Get basic keypad entry working

This commit is contained in:
n loewen 2025-03-08 11:18:33 +00:00
parent fd4ca3e8c8
commit d5ded67b79
1 changed files with 17 additions and 5 deletions

View File

@ -18,10 +18,16 @@ btnb = DigitalInOut(board.BTNB)
btnb.direction = Direction.INPUT
btnb.pull = Pull.UP # down doesn't work
btnr = DigitalInOut(board.RIGHT)
btnr.direction = Direction.INPUT
btnr.pull = Pull.UP # down doesn't work
km = keypad.KeyMatrix(
row_pins = (board.P0, board.P1, board.P2, board.P3),
column_pins = (board.P4, board.P6, board.P8, board.P9) )
class CPU:
def __init__(self):
self.running = False
@ -31,7 +37,7 @@ class CPU:
self.instruction = { 'opcode': False, 'operand': False }
self.memory = False
self.monitorMode = 'addressEntry' # dataEntry
self.monitorAddressInput = "00"
self.monitorAddressInput = "00" # These are strings because it makes shifting digits in easier
self.monitorDataInput = "00"
self.monitorAddressDisplay = "00"
self.monitorDataDisplay = "00"
@ -88,11 +94,16 @@ class CPU:
else: # halted
if btna.value == False:
self.running = True
print("STARTING")
print("\nSTARTING")
time.sleep(0.5) # lazy debounce
if btnb.value == False:
self.monitorMode = 'addressEntry' if self.monitorMode != 'addressEntry' else 'dataEntry'
print(self.monitorMode)
print("\nENTERING", self.monitorMode, "MODE")
time.sleep(0.5) # lazy debounce
if btnr.value == False:
print("\nSINGLE STEP FROM MONITOR ADDR")
self.IP = int(self.monitorAddressInput, 16)
self.step()
time.sleep(0.5) # lazy debounce
if keypad_event and keypad_event.released:
new_digit_0x = hex(keypad_event.key_number)
@ -103,9 +114,10 @@ class CPU:
print("MA", self.monitorAddressInput)
else:
cat = self.monitorDataInput + new_digit
self.monitorDataInput = cat[1:3]
self.monitorDataInput = cat[1:3] # TODO this variable might not be necessary, huh?
self.memory[int(self.monitorAddressInput, 16)] = int(self.monitorDataInput, 16)
print("MD", self.monitorDataInput)
print("Acc", self.acc, "Addr", self.monitorAddressInput, "Data", self.memory[int(self.monitorAddressInput)])
print("Acc", self.acc, "Addr", self.monitorAddressInput, "Data", self.memory[int(self.monitorAddressInput, 16)])
# TODO: update data with keypad
# then, automatically go to next address (?)