mirror of
https://github.com/jtauber/applepy.git
synced 2025-01-14 16:32:47 +00:00
improved hires colour, fixed non-ASCII key crash, fixed to work with later pygame/numpy
This commit is contained in:
parent
e9c9581857
commit
0d41f951b9
2
LICENSE
2
LICENSE
@ -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
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
14
applepy.py
14
applepy.py
@ -234,20 +234,24 @@ class Display:
|
|||||||
if xx % 2:
|
if xx % 2:
|
||||||
pixels[x][y] = (0, 0, 0)
|
pixels[x][y] = (0, 0, 0)
|
||||||
# orange
|
# 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)
|
pixels[x + 1][y] = (255, 192, 0) if c else (0, 0, 0)
|
||||||
else:
|
else:
|
||||||
# blue
|
# blue
|
||||||
pixels[x][y] = (0, 192, 255) if c else (0, 0, 0)
|
pixels[x][y] = (0, 192, 255) if c else (0, 0, 0)
|
||||||
pixels[x + 1][y] = (0, 0, 0)
|
pixels[x + 1][y] = (0, 0, 0)
|
||||||
|
pixels[x + 1][y] = (0, 192, 255) if c else (0, 0, 0) # @@@
|
||||||
else:
|
else:
|
||||||
if xx % 2:
|
if xx % 2:
|
||||||
pixels[x][y] = (0, 0, 0)
|
pixels[x][y] = (0, 0, 0)
|
||||||
# green
|
# 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)
|
pixels[x + 1][y] = (0, 255, 0) if c else (0, 0, 0)
|
||||||
else:
|
else:
|
||||||
# violet
|
# violet
|
||||||
pixels[x][y] = (255, 0, 255) if c else (0, 0, 0)
|
pixels[x][y] = (255, 0, 255) if c else (0, 0, 0)
|
||||||
pixels[x + 1][y] = (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][y + 1] = (0, 0, 0)
|
||||||
pixels[x + 1][y + 1] = (0, 0, 0)
|
pixels[x + 1][y + 1] = (0, 0, 0)
|
||||||
@ -269,15 +273,15 @@ class Speaker:
|
|||||||
CHECK_INTERVAL = 1000
|
CHECK_INTERVAL = 1000
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pygame.mixer.pre_init(44100, -16, 1)
|
pygame.mixer.pre_init(11025, -16, 1)
|
||||||
pygame.init()
|
pygame.init()
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def toggle(self, cycle):
|
def toggle(self, cycle):
|
||||||
if self.last_toggle is not None:
|
if self.last_toggle is not None:
|
||||||
l = (cycle - self.last_toggle) / Speaker.CPU_CYCLES_PER_SAMPLE
|
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([0, 26000] if self.polarity else [0, -2600])
|
||||||
self.buffer.extend((l - 2) * [0.5] if self.polarity else [-0.5])
|
self.buffer.extend((l - 2) * [16384] if self.polarity else [-16384])
|
||||||
self.polarity = not self.polarity
|
self.polarity = not self.polarity
|
||||||
self.last_toggle = cycle
|
self.last_toggle = cycle
|
||||||
|
|
||||||
@ -287,7 +291,7 @@ class Speaker:
|
|||||||
self.polarity = False
|
self.polarity = False
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
sample_array = numpy.array(self.buffer)
|
sample_array = numpy.int16(self.buffer)
|
||||||
sound = pygame.sndarray.make_sound(sample_array)
|
sound = pygame.sndarray.make_sound(sample_array)
|
||||||
sound.play()
|
sound.play()
|
||||||
self.reset()
|
self.reset()
|
||||||
@ -419,7 +423,7 @@ class Apple2:
|
|||||||
if key:
|
if key:
|
||||||
if key == 0x7F:
|
if key == 0x7F:
|
||||||
key = 0x08
|
key = 0x08
|
||||||
self.softswitches.kbd = 0x80 + key
|
self.softswitches.kbd = 0x80 + (key & 0x7F)
|
||||||
|
|
||||||
update_cycle += 1
|
update_cycle += 1
|
||||||
if update_cycle >= 1024:
|
if update_cycle >= 1024:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user