commit
51acc8e156
30
applepy.py
30
applepy.py
|
@ -7,6 +7,8 @@ import numpy
|
||||||
import pygame
|
import pygame
|
||||||
import colorsys
|
import colorsys
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def signed(x):
|
def signed(x):
|
||||||
if x > 0x7F:
|
if x > 0x7F:
|
||||||
|
@ -106,6 +108,9 @@ class Display:
|
||||||
self.screen = pygame.display.set_mode((560, 384))
|
self.screen = pygame.display.set_mode((560, 384))
|
||||||
pygame.display.set_caption("ApplePy")
|
pygame.display.set_caption("ApplePy")
|
||||||
self.mix = False
|
self.mix = False
|
||||||
|
self.flash_time = time.time()
|
||||||
|
self.flash_on = False
|
||||||
|
self.flash_chars = [[0] * 0x400] * 2
|
||||||
|
|
||||||
self.chargen = []
|
self.chargen = []
|
||||||
for c in self.characters:
|
for c in self.characters:
|
||||||
|
@ -164,6 +169,7 @@ class Display:
|
||||||
|
|
||||||
if start_text <= address <= start_text + 0x3FF:
|
if start_text <= address <= start_text + 0x3FF:
|
||||||
base = address - start_text
|
base = address - start_text
|
||||||
|
self.flash_chars[self.page - 1][base] = value
|
||||||
hi, lo = divmod(base, 0x80)
|
hi, lo = divmod(base, 0x80)
|
||||||
row_group, column = divmod(lo, 0x28)
|
row_group, column = divmod(lo, 0x28)
|
||||||
row = hi + 8 * row_group
|
row = hi + 8 * row_group
|
||||||
|
@ -174,7 +180,12 @@ class Display:
|
||||||
if self.text or not self.mix or not row < 20:
|
if self.text or not self.mix or not row < 20:
|
||||||
mode, ch = divmod(value, 0x40)
|
mode, ch = divmod(value, 0x40)
|
||||||
|
|
||||||
inv = mode in (0, 1)
|
if mode == 0:
|
||||||
|
inv = True
|
||||||
|
elif mode == 1:
|
||||||
|
inv = self.flash_on
|
||||||
|
else:
|
||||||
|
inv = False
|
||||||
|
|
||||||
self.screen.blit(self.chargen[ch][self.colour][inv], (2 * (column * 7), 2 * (row * 8)))
|
self.screen.blit(self.chargen[ch][self.colour][inv], (2 * (column * 7), 2 * (row * 8)))
|
||||||
else:
|
else:
|
||||||
|
@ -239,6 +250,14 @@ class Display:
|
||||||
|
|
||||||
del pixels
|
del pixels
|
||||||
|
|
||||||
|
def flash(self):
|
||||||
|
if time.time() - self.flash_time >= 0.5:
|
||||||
|
self.flash_on = not self.flash_on
|
||||||
|
for offset, char in enumerate(self.flash_chars[self.page - 1]):
|
||||||
|
if (char & 0xC0) == 0x40:
|
||||||
|
self.update(0x400 + offset, char)
|
||||||
|
self.flash_time = time.time()
|
||||||
|
|
||||||
|
|
||||||
class Speaker:
|
class Speaker:
|
||||||
|
|
||||||
|
@ -806,14 +825,19 @@ class CPU:
|
||||||
quit = True
|
quit = True
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.unicode:
|
key = ord(event.unicode) if event.unicode else 0
|
||||||
key = ord(event.unicode)
|
if event.key == pygame.K_LEFT:
|
||||||
|
key = 0x08
|
||||||
|
if event.key == pygame.K_RIGHT:
|
||||||
|
key = 0x15
|
||||||
|
if key:
|
||||||
if key == 0x7F:
|
if key == 0x7F:
|
||||||
key = 0x08
|
key = 0x08
|
||||||
self.memory.softswitches.kbd = 0x80 + key
|
self.memory.softswitches.kbd = 0x80 + key
|
||||||
|
|
||||||
update_cycle += 1
|
update_cycle += 1
|
||||||
if update_cycle >= 1024:
|
if update_cycle >= 1024:
|
||||||
|
self.memory.display.flash()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
self.memory.update(self.cycles)
|
self.memory.update(self.cycles)
|
||||||
update_cycle = 0
|
update_cycle = 0
|
||||||
|
|
Loading…
Reference in New Issue