mirror of
https://github.com/jtauber/applepy.git
synced 2024-12-29 00:30:44 +00:00
Merge branch 'master' into disk
Conflicts: applepy.py
This commit is contained in:
commit
82477edb20
19
LICENSE
Normal file
19
LICENSE
Normal file
@ -0,0 +1,19 @@
|
||||
# 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
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
@ -32,4 +32,17 @@ The only I/O supported is the keyboard and screen but 40-column text, LORES
|
||||
and HIRES graphics are all supported.
|
||||
|
||||
ApplePy currently requires Pygame (although there is a minimal applepy_curses.py
|
||||
that uses curses to display text mode only).
|
||||
that uses curses to display text mode only) and numpy (just for an array for
|
||||
speaker sounds)
|
||||
|
||||
Here's how I set up the dependencies (on Mac OS X 10.8):
|
||||
|
||||
pip install numpy
|
||||
brew install sdl sdl_image sdl_mixer sdl_ttf portmidi hg
|
||||
pip install hg+http://bitbucket.org/pygame/pygame
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This code is made available under an MIT License. See LICENSE.
|
17
applepy.py
Normal file → Executable file
17
applepy.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# ApplePy - an Apple ][ emulator in Python
|
||||
# James Tauber / http://jtauber.com/
|
||||
# originally written 2001, updated 2011
|
||||
@ -232,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)
|
||||
@ -267,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
|
||||
|
||||
@ -285,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()
|
||||
@ -532,7 +538,8 @@ class Apple2:
|
||||
if key:
|
||||
if key == 0x7F:
|
||||
key = 0x08
|
||||
self.io.kbd = 0x80 + key
|
||||
|
||||
self.io.kbd = 0x80 + (key & 0x7F)
|
||||
|
||||
update_cycle += 1
|
||||
if update_cycle >= 1024:
|
||||
|
Loading…
Reference in New Issue
Block a user