diff --git a/orao.py b/orao.py index c11521a..7e7da88 100755 --- a/orao.py +++ b/orao.py @@ -4,6 +4,7 @@ import pygame, numpy, sys, datetime, wave, time from orao.cpu import CPU from orao.keyboard import listener as orao_kbd_listener +from orao.video import mem_listener as video_mem_listener, terminal MEM_LOAD_PRG = None @@ -21,13 +22,11 @@ pygame.time.set_timer(pygame.USEREVENT + 1, 40) # setup surfaces screen = pygame.display.set_mode((800, 900)) background = pygame.image.load("pozadina.png").convert_alpha() -terminal = pygame.Surface((256, 256), pygame.SRCALPHA, depth=32) -terminal.fill((255, 255, 255)) # create CPU cpu = CPU(bytearray([0xFF]*0xC000) + bytearray(open('ORAO13.ROM', 'rb').read())) -cpu.alphaarray = pygame.surfarray.pixels_alpha(terminal) cpu.channel = pygame.mixer.Channel(0) +cpu.store_mem_listeners.append(video_mem_listener) while running: before, previous_loop_cycles = datetime.datetime.now(), cpu.cycles diff --git a/orao/cpu.py b/orao/cpu.py index f44341c..3bb05bb 100755 --- a/orao/cpu.py +++ b/orao/cpu.py @@ -5,6 +5,7 @@ import wave class CPU(object): CARRY, ZERO, INTERRUPT, DECIMAL, BREAK, UNUSED, OVERFLOW, NEGATIVE = [2**i for i in range(8)] alphaarray = None + store_mem_listeners = [] def __init__(self, memory): s, self.tape_out, self.filename, self.samples = self, None, None, 0 @@ -98,14 +99,12 @@ class CPU(object): return if addr == 0x8800: self.speaker() # Zvucnik - if 0x6000 <= addr <= 0x7FFF: # Video RAM - if self.alphaarray is not None: - y, x = divmod((addr - 0x6000) * 8, 256) - for i in range(8): - self.alphaarray[x+i, y] = 255 if (val>>i) & 1 else 0 # Transparency mask self.memory[addr] = val & 0xFF + for listener in self.store_mem_listeners: + listener(addr, val) + def stack_push(self, value): self.store_byte(256 + self.sp, value & 0xFF) self.sp = (self.sp - 1) & 0xFF diff --git a/orao/video.py b/orao/video.py new file mode 100644 index 0000000..f7126ad --- /dev/null +++ b/orao/video.py @@ -0,0 +1,11 @@ +import pygame + +terminal = pygame.Surface((256, 256), pygame.SRCALPHA, depth=32) +terminal.fill((255, 255, 255)) +alphaarray = pygame.surfarray.pixels_alpha(terminal) + +def mem_listener(addr, val): + if 0x6000 <= addr <= 0x7FFF: # Video RAM + y, x = divmod((addr - 0x6000) * 8, 256) + for i in range(8): + alphaarray[x + i, y] = 255 if (val >> i) & 1 else 0 # Transparency mask