feat: add timer

This commit is contained in:
shokre 2021-09-16 16:08:09 +02:00
parent 8b1cd8c99b
commit 32795a402c
2 changed files with 13 additions and 0 deletions

View file

@ -5,6 +5,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
from orao.timer import mem_listener as timer_mem_listener
MEM_LOAD_PRG = None
@ -27,6 +28,7 @@ background = pygame.image.load("pozadina.png").convert_alpha()
cpu = CPU(bytearray([0xFF]*0xC000) + bytearray(open('ORAO13.ROM', 'rb').read()))
cpu.channel = pygame.mixer.Channel(0)
cpu.store_mem_listeners.append(video_mem_listener)
cpu.store_mem_listeners.append(timer_mem_listener)
while running:
before, previous_loop_cycles = datetime.datetime.now(), cpu.cycles

11
orao/timer.py Normal file
View file

@ -0,0 +1,11 @@
timer = {}
def mem_listener(addr, val, cpu):
if addr >= 0xa000 and addr <= 0xa0ff:
timer_ix = addr & 0xff
if timer_ix in timer:
print('timer(%s):duration %d cy' % (timer_ix, cpu.cycles - timer[timer_ix] - 4))
del timer[timer_ix]
else:
timer[timer_ix] = cpu.cycles