aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_emu/peripherals.py
diff options
context:
space:
mode:
Diffstat (limited to 'atk16_emu/peripherals.py')
-rw-r--r--atk16_emu/peripherals.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/atk16_emu/peripherals.py b/atk16_emu/peripherals.py
index c11bb55..0038a33 100644
--- a/atk16_emu/peripherals.py
+++ b/atk16_emu/peripherals.py
@@ -1,7 +1,32 @@
import pygame
import sys
+import random
from .memory import RAM, ROM
+class Peripherals:
+ def __init__(self):
+ pygame.init()
+ self.graphics = Graphics()
+ self.keyboard = Keyboard()
+
+ def step(self):
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ sys.exit(0)
+ elif event.type == pygame.KEYDOWN:
+ print(f"key pressed: {event.key}")
+ self.keyboard.latest_pressed = event.key
+
+ self.graphics.step()
+
+class DummyPeripherals:
+ def __init__(self):
+ self.graphics = DummyGraphics()
+ self.keyboard = DummyKeyboard()
+
+ def step(self):
+ pass
+
class TPU:
def __init__(self):
self.surface = pygame.Surface((320, 240))
@@ -29,7 +54,6 @@ class TPU:
for cx in range(2 ** 3):
sx = (tx << 3) + cx
sy = (ty << 3) + cy
- #print("cy", cy, "ty", ty, "cx", cx, "tx", tx, "text_addr", text_addr, "char_s", char_s, "char_addr", char_addr)
pixel_value_bit = (char_d >> cx) & 1
self.surface.set_at((sx, sy), (255 * pixel_value_bit, 255 * pixel_value_bit, 255))
@@ -40,7 +64,6 @@ class TPU:
class Graphics:
def __init__(self):
- pygame.init()
pygame.display.init()
surface_scale = 4
@@ -60,10 +83,6 @@ class Graphics:
def step(self):
if self.active_picture_unit:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit(0)
-
self.active_picture_unit.frame()
self.screen.blit(pygame.transform.scale(self.tpu.surface, self.screen.get_size()), (0, 0))
@@ -89,3 +108,22 @@ class DummyGraphics:
def step(self):
pass
+
+ def write(self, addr: int, char: int):
+ pass
+
+class Keyboard:
+ def __init__(self):
+ # mimic electronic behaviour my assigning a random value at start
+ self.latest_pressed: int = random.randrange(0, 2 ** 16)
+
+ def read(self) -> int:
+ return self.latest_pressed
+
+class DummyKeyboard:
+ def __init__(self):
+ pass
+
+ def read(self) -> int:
+ print("warning: reading from dummy keyboard")
+ return 0xFFFF