improved hires colour, fixed non-ASCII key crash, fixed to work with later pygame/numpy

This commit is contained in:
James Tauber 2013-03-08 06:56:52 -05:00
parent e9c9581857
commit 0d41f951b9
2 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2001-2012 James Tauber and contributors
# Copyright (c) 2001-2013 James Tauber and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal

View File

@ -234,20 +234,24 @@ class Display:
if xx % 2:
pixels[x][y] = (0, 0, 0)
# orange
pixels[x][y] = (255, 192, 0) if c else (0, 0, 0) # @@@
pixels[x + 1][y] = (255, 192, 0) if c else (0, 0, 0)
else:
# blue
pixels[x][y] = (0, 192, 255) if c else (0, 0, 0)
pixels[x + 1][y] = (0, 0, 0)
pixels[x + 1][y] = (0, 192, 255) if c else (0, 0, 0) # @@@
else:
if xx % 2:
pixels[x][y] = (0, 0, 0)
# green
pixels[x][y] = (0, 255, 0) if c else (0, 0, 0) # @@@
pixels[x + 1][y] = (0, 255, 0) if c else (0, 0, 0)
else:
# violet
pixels[x][y] = (255, 0, 255) if c else (0, 0, 0)
pixels[x + 1][y] = (0, 0, 0)
pixels[x + 1][y] = (255, 0, 255) if c else (0, 0, 0) # @@@
pixels[x][y + 1] = (0, 0, 0)
pixels[x + 1][y + 1] = (0, 0, 0)
@ -269,15 +273,15 @@ class Speaker:
CHECK_INTERVAL = 1000
def __init__(self):
pygame.mixer.pre_init(44100, -16, 1)
pygame.mixer.pre_init(11025, -16, 1)
pygame.init()
self.reset()
def toggle(self, cycle):
if self.last_toggle is not None:
l = (cycle - self.last_toggle) / Speaker.CPU_CYCLES_PER_SAMPLE
self.buffer.extend([0, 0.8] if self.polarity else [0, -0.8])
self.buffer.extend((l - 2) * [0.5] if self.polarity else [-0.5])
self.buffer.extend([0, 26000] if self.polarity else [0, -2600])
self.buffer.extend((l - 2) * [16384] if self.polarity else [-16384])
self.polarity = not self.polarity
self.last_toggle = cycle
@ -287,7 +291,7 @@ class Speaker:
self.polarity = False
def play(self):
sample_array = numpy.array(self.buffer)
sample_array = numpy.int16(self.buffer)
sound = pygame.sndarray.make_sound(sample_array)
sound.play()
self.reset()
@ -419,7 +423,7 @@ class Apple2:
if key:
if key == 0x7F:
key = 0x08
self.softswitches.kbd = 0x80 + key
self.softswitches.kbd = 0x80 + (key & 0x7F)
update_cycle += 1
if update_cycle >= 1024: