mirror of
https://github.com/jtauber/applepy.git
synced 2024-11-22 19:30:54 +00:00
refactored update_text and update_lores into a single method
This commit is contained in:
parent
9e92bbba97
commit
38736cf243
44
applepy.py
44
applepy.py
@ -129,35 +129,25 @@ class Display:
|
||||
self.high_res = True
|
||||
|
||||
def update(self, address, value):
|
||||
if self.page == 1 and 0x400 <= address <= 0x7FF:
|
||||
if self.text:
|
||||
self.update_text(address - 0x400, value, False)
|
||||
elif self.mix:
|
||||
self.update_lores(address - 0x400, value, True)
|
||||
self.update_text(address - 0x400, value, True)
|
||||
if self.page == 1:
|
||||
start = 0x400
|
||||
elif self.page == 2:
|
||||
start = 0x800
|
||||
else:
|
||||
self.update_lores(address - 0x400, value, False)
|
||||
if self.page == 2 and 0x800 <= address <= 0xBFF:
|
||||
if self.text:
|
||||
self.update_text(address - 0x800, value, False)
|
||||
elif self.mix:
|
||||
self.update_lores(address - 0x400, value, True)
|
||||
self.update_text(address - 0x400, value, True)
|
||||
else:
|
||||
self.update_lores(address - 0x800, value, False)
|
||||
return
|
||||
|
||||
def update_text(self, base, value, mixed):
|
||||
if start <= address <= start + 0x3FF:
|
||||
base = address - start
|
||||
hi, lo = divmod(base, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = hi + 8 * row_group
|
||||
|
||||
if mixed and row < 20:
|
||||
return
|
||||
|
||||
# skip if writing to row group 3
|
||||
if row_group == 3:
|
||||
return
|
||||
|
||||
pixels = pygame.PixelArray(self.screen)
|
||||
|
||||
if self.text or not self.mix or not row < 20:
|
||||
mode, ch = divmod(value, 0x40)
|
||||
|
||||
if mode == 0: # inverse
|
||||
@ -170,7 +160,6 @@ class Display:
|
||||
on = (0, 200, 0)
|
||||
off = (0, 0, 0)
|
||||
|
||||
pixels = pygame.PixelArray(self.screen)
|
||||
for line in range(8):
|
||||
b = self.characters[ch][line] << 1
|
||||
for i in range(7):
|
||||
@ -179,19 +168,9 @@ class Display:
|
||||
bit = (b >> i) % 2
|
||||
pixels[x][y] = on if bit else off
|
||||
pixels[x + 1][y] = on if bit else off
|
||||
del pixels
|
||||
|
||||
def update_lores(self, base, value, mixed):
|
||||
hi, lo = divmod(base, 0x80)
|
||||
row_group, column = divmod(lo, 0x28)
|
||||
row = hi + 8 * row_group
|
||||
|
||||
if mixed and row >= 20:
|
||||
return
|
||||
|
||||
else:
|
||||
lower, upper = divmod(value, 0x10)
|
||||
|
||||
pixels = pygame.PixelArray(self.screen)
|
||||
for dx in range(14):
|
||||
for dy in range(8):
|
||||
x = column * 14 + dx
|
||||
@ -201,6 +180,7 @@ class Display:
|
||||
x = column * 14 + dx
|
||||
y = row * 16 + dy
|
||||
pixels[x][y] = self.lores_colours[lower]
|
||||
|
||||
del pixels
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user