feat: add cpu state view

This commit is contained in:
shokre 2021-09-18 22:51:03 +02:00
parent 81672e4962
commit 8dfc561b8b
3 changed files with 50 additions and 2 deletions

17
orao.py
View file

@ -8,6 +8,9 @@ from orao.video import mem_listener as video_mem_listener, terminal
from orao.timer import mem_listener as timer_mem_listener from orao.timer import mem_listener as timer_mem_listener
from orao.chargen import chargen_init, chargen_draw_str from orao.chargen import chargen_init, chargen_draw_str
# views
from orao.views.cpu_state import CPUState
MEM_LOAD_PRG = None MEM_LOAD_PRG = None
if len(sys.argv) == 2: if len(sys.argv) == 2:
@ -34,6 +37,9 @@ cpu.store_mem_listeners.append(timer_mem_listener)
chargen_init(cpu.memory[0xE000:]) chargen_init(cpu.memory[0xE000:])
# views
view_cpu_state = CPUState()
# status lines # status lines
status_line = pygame.Surface((64 * 8, 3*8), depth=24) status_line = pygame.Surface((64 * 8, 3*8), depth=24)
status_line.fill((0, 0, 0)) status_line.fill((0, 0, 0))
@ -52,14 +58,21 @@ for i in range(0, MAX_LABELS):
def render_frame(): def render_frame():
store_mem_view(cpu.memory) store_mem_view(cpu.memory)
view_cpu_state.render(cpu)
screen.fill((0, 0, 0)) screen.fill((0, 0, 0))
screen.blit(pygame.transform.smoothscale(terminal, (512, 512)), [0, 0]) screen.blit(pygame.transform.smoothscale(terminal, (512, 512)), [0, 0])
chargen_draw_str(status_line, 0, 8, 'Speed: {0:.2f} MHz'.format(ratio)) chargen_draw_str(status_line, 0, 8, 'Speed: {0:.2f} MHz'.format(ratio))
screen.blit(status_line, [0, 512+1]) screen.blit(status_line, [0, 512+1])
lsx = 512 + 1
lsy = 0
_, lsy = view_cpu_state.blit(screen, [lsx, lsy], scale=1.8)
lsy += 1
w, h = micro_mem_view_dims w, h = micro_mem_view_dims
screen.blit(mem_map_labels, [512+1, 0]) screen.blit(mem_map_labels, [lsx, lsy])
screen.blit(pygame.transform.scale(micro_mem_view, (w * 3, h * 3)), [512 + 1 + 8 + 8 + 1 + 1, 0]) screen.blit(pygame.transform.scale(micro_mem_view, (w * 3, h * 3)), [lsx + 8 + 8 + 1 + 1, lsy])
# finish rendering
pygame.display.flip() pygame.display.flip()
while running: while running:

0
orao/views/__init__.py Normal file
View file

35
orao/views/cpu_state.py Normal file
View file

@ -0,0 +1,35 @@
import pygame
from ..chargen import chargen_draw_str
class CPUState:
surf = None
def __init__(self):
self.surf = pygame.Surface((8 * 8, 6 * 8), depth=24)
self.width = self.surf.get_width()
self.height = self.surf.get_height()
self.surf.fill((0, 0, 0))
def scale(self, f):
return pygame.transform.smoothscale(self.surf, (int(self.width * f), int(self.height * f)))
def render(self, cpu):
lc = (0xff, 0xcc, 0x00)
chargen_draw_str(self.surf, 0, 0*8, 'A X Y', color=lc)
chargen_draw_str(self.surf, 0, 1*8, '%02X %02X %02X' % (cpu.a, cpu.x, cpu.y))
chargen_draw_str(self.surf, 0, 2*8, 'PC:', color=lc)
chargen_draw_str(self.surf, 0, 3*8, 'SP:', color=lc)
chargen_draw_str(self.surf, 4*8, 2*8, '%04X' % cpu.pc)
chargen_draw_str(self.surf, 4*8, 3*8, '%04X' % cpu.sp)
chargen_draw_str(self.surf, 0, 4*8, "NVssDIZC", color=lc)
chargen_draw_str(self.surf, 0, 5*8, "{0:b}".format(cpu.flags))
def blit(self, screen, pos, scale=1):
if scale == 1:
screen.blit(self.surf, pos)
return (pos[0], pos[1] + self.height)
else:
screen.blit(self.scale(scale), pos)
return (pos[0], pos[1] + int(self.height*scale))