mirror of
https://github.com/jtauber/applepy.git
synced 2025-02-16 17:30:27 +00:00
Merge pull request #7 from ghewgill/flash
add flash attribute to text mode
This commit is contained in:
commit
2b1680a6a7
21
applepy.py
21
applepy.py
@ -6,6 +6,7 @@
|
||||
import numpy
|
||||
import pygame
|
||||
import colorsys
|
||||
import time
|
||||
|
||||
def signed(x):
|
||||
if x > 0x7F:
|
||||
@ -105,6 +106,9 @@ class Display:
|
||||
self.screen = pygame.display.set_mode((560, 384))
|
||||
pygame.display.set_caption("ApplePy")
|
||||
self.mix = False
|
||||
self.flash_time = time.time()
|
||||
self.flash_on = False
|
||||
self.flash_chars = [[0] * 0x400] * 2
|
||||
|
||||
self.chargen = []
|
||||
for c in self.characters:
|
||||
@ -163,6 +167,7 @@ class Display:
|
||||
|
||||
if start_text <= address <= start_text + 0x3FF:
|
||||
base = address - start_text
|
||||
self.flash_chars[self.page - 1][base] = value
|
||||
hi, lo = divmod(base, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = hi + 8 * row_group
|
||||
@ -173,7 +178,12 @@ class Display:
|
||||
if self.text or not self.mix or not row < 20:
|
||||
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)))
|
||||
else:
|
||||
@ -238,6 +248,14 @@ class Display:
|
||||
|
||||
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:
|
||||
|
||||
@ -811,6 +829,7 @@ class CPU:
|
||||
|
||||
update_cycle += 1
|
||||
if update_cycle >= 1024:
|
||||
self.memory.display.flash()
|
||||
pygame.display.flip()
|
||||
self.memory.update(self.cycles)
|
||||
update_cycle = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user