refactor: move screen rendering to separate file, add store_mem_listeners
This commit is contained in:
parent
076e1803a2
commit
d0f6126307
3 changed files with 17 additions and 8 deletions
5
orao.py
5
orao.py
|
@ -4,6 +4,7 @@
|
||||||
import pygame, numpy, sys, datetime, wave, time
|
import pygame, numpy, sys, datetime, wave, time
|
||||||
from orao.cpu import CPU
|
from orao.cpu import CPU
|
||||||
from orao.keyboard import listener as orao_kbd_listener
|
from orao.keyboard import listener as orao_kbd_listener
|
||||||
|
from orao.video import mem_listener as video_mem_listener, terminal
|
||||||
|
|
||||||
MEM_LOAD_PRG = None
|
MEM_LOAD_PRG = None
|
||||||
|
|
||||||
|
@ -21,13 +22,11 @@ pygame.time.set_timer(pygame.USEREVENT + 1, 40)
|
||||||
# setup surfaces
|
# setup surfaces
|
||||||
screen = pygame.display.set_mode((800, 900))
|
screen = pygame.display.set_mode((800, 900))
|
||||||
background = pygame.image.load("pozadina.png").convert_alpha()
|
background = pygame.image.load("pozadina.png").convert_alpha()
|
||||||
terminal = pygame.Surface((256, 256), pygame.SRCALPHA, depth=32)
|
|
||||||
terminal.fill((255, 255, 255))
|
|
||||||
|
|
||||||
# create CPU
|
# create CPU
|
||||||
cpu = CPU(bytearray([0xFF]*0xC000) + bytearray(open('ORAO13.ROM', 'rb').read()))
|
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.channel = pygame.mixer.Channel(0)
|
||||||
|
cpu.store_mem_listeners.append(video_mem_listener)
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
before, previous_loop_cycles = datetime.datetime.now(), cpu.cycles
|
before, previous_loop_cycles = datetime.datetime.now(), cpu.cycles
|
||||||
|
|
|
@ -5,6 +5,7 @@ import wave
|
||||||
class CPU(object):
|
class CPU(object):
|
||||||
CARRY, ZERO, INTERRUPT, DECIMAL, BREAK, UNUSED, OVERFLOW, NEGATIVE = [2**i for i in range(8)]
|
CARRY, ZERO, INTERRUPT, DECIMAL, BREAK, UNUSED, OVERFLOW, NEGATIVE = [2**i for i in range(8)]
|
||||||
alphaarray = None
|
alphaarray = None
|
||||||
|
store_mem_listeners = []
|
||||||
|
|
||||||
def __init__(self, memory):
|
def __init__(self, memory):
|
||||||
s, self.tape_out, self.filename, self.samples = self, None, None, 0
|
s, self.tape_out, self.filename, self.samples = self, None, None, 0
|
||||||
|
@ -98,14 +99,12 @@ class CPU(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if addr == 0x8800: self.speaker() # Zvucnik
|
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
|
self.memory[addr] = val & 0xFF
|
||||||
|
|
||||||
|
for listener in self.store_mem_listeners:
|
||||||
|
listener(addr, val)
|
||||||
|
|
||||||
def stack_push(self, value):
|
def stack_push(self, value):
|
||||||
self.store_byte(256 + self.sp, value & 0xFF)
|
self.store_byte(256 + self.sp, value & 0xFF)
|
||||||
self.sp = (self.sp - 1) & 0xFF
|
self.sp = (self.sp - 1) & 0xFF
|
||||||
|
|
11
orao/video.py
Normal file
11
orao/video.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue