refactored update_text and update_lores into a single method

This commit is contained in:
James Tauber 2011-08-13 07:06:11 -04:00
parent 9e92bbba97
commit 38736cf243

View File

@ -129,79 +129,59 @@ class Display:
self.high_res = True self.high_res = True
def update(self, address, value): def update(self, address, value):
if self.page == 1 and 0x400 <= address <= 0x7FF: if self.page == 1:
if self.text: start = 0x400
self.update_text(address - 0x400, value, False) elif self.page == 2:
elif self.mix: start = 0x800
self.update_lores(address - 0x400, value, True) else:
self.update_text(address - 0x400, value, True)
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)
def update_text(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 return
if start <= address <= start + 0x3FF:
base = address - start
hi, lo = divmod(base, 0x80)
row_group, column = divmod(lo, 0x28)
row = hi + 8 * row_group
# skip if writing to row group 3 if row_group == 3:
if row_group == 3: return
return
mode, ch = divmod(value, 0x40)
if mode == 0: # inverse
on = (0, 0, 0)
off = (0, 200, 0)
elif mode == 1: # flash
on = (0, 0, 0)
off = (0, 200, 0)
else: # normal
on = (0, 200, 0)
off = (0, 0, 0)
pixels = pygame.PixelArray(self.screen) pixels = pygame.PixelArray(self.screen)
for line in range(8):
b = self.characters[ch][line] << 1 if self.text or not self.mix or not row < 20:
for i in range(7): mode, ch = divmod(value, 0x40)
x = 2 * (column * 7 + (5 - i))
y = 2 * (row * 8 + line) if mode == 0: # inverse
bit = (b >> i) % 2 on = (0, 0, 0)
pixels[x][y] = on if bit else off off = (0, 200, 0)
pixels[x + 1][y] = on if bit else off elif mode == 1: # flash
del pixels on = (0, 0, 0)
off = (0, 200, 0)
def update_lores(self, base, value, mixed): else: # normal
hi, lo = divmod(base, 0x80) on = (0, 200, 0)
row_group, column = divmod(lo, 0x28) off = (0, 0, 0)
row = hi + 8 * row_group
for line in range(8):
if mixed and row >= 20: b = self.characters[ch][line] << 1
return for i in range(7):
x = 2 * (column * 7 + (5 - i))
lower, upper = divmod(value, 0x10) y = 2 * (row * 8 + line)
bit = (b >> i) % 2
pixels = pygame.PixelArray(self.screen) pixels[x][y] = on if bit else off
for dx in range(14): pixels[x + 1][y] = on if bit else off
for dy in range(8): else:
x = column * 14 + dx lower, upper = divmod(value, 0x10)
y = row * 16 + dy
pixels[x][y] = self.lores_colours[upper] for dx in range(14):
for dy in range(8, 16): for dy in range(8):
x = column * 14 + dx x = column * 14 + dx
y = row * 16 + dy y = row * 16 + dy
pixels[x][y] = self.lores_colours[lower] pixels[x][y] = self.lores_colours[upper]
del pixels for dy in range(8, 16):
x = column * 14 + dx
y = row * 16 + dy
pixels[x][y] = self.lores_colours[lower]
del pixels
class RAM: class RAM: