Get basic keypad entry working
This commit is contained in:
parent
fd4ca3e8c8
commit
d5ded67b79
22
src/cpu.py
22
src/cpu.py
|
|
@ -18,10 +18,16 @@ btnb = DigitalInOut(board.BTNB)
|
||||||
btnb.direction = Direction.INPUT
|
btnb.direction = Direction.INPUT
|
||||||
btnb.pull = Pull.UP # down doesn't work
|
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(
|
km = keypad.KeyMatrix(
|
||||||
row_pins = (board.P0, board.P1, board.P2, board.P3),
|
row_pins = (board.P0, board.P1, board.P2, board.P3),
|
||||||
column_pins = (board.P4, board.P6, board.P8, board.P9) )
|
column_pins = (board.P4, board.P6, board.P8, board.P9) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CPU:
|
class CPU:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
@ -31,7 +37,7 @@ class CPU:
|
||||||
self.instruction = { 'opcode': False, 'operand': False }
|
self.instruction = { 'opcode': False, 'operand': False }
|
||||||
self.memory = False
|
self.memory = False
|
||||||
self.monitorMode = 'addressEntry' # dataEntry
|
self.monitorMode = 'addressEntry' # dataEntry
|
||||||
self.monitorAddressInput = "00"
|
self.monitorAddressInput = "00" # These are strings because it makes shifting digits in easier
|
||||||
self.monitorDataInput = "00"
|
self.monitorDataInput = "00"
|
||||||
self.monitorAddressDisplay = "00"
|
self.monitorAddressDisplay = "00"
|
||||||
self.monitorDataDisplay = "00"
|
self.monitorDataDisplay = "00"
|
||||||
|
|
@ -88,11 +94,16 @@ class CPU:
|
||||||
else: # halted
|
else: # halted
|
||||||
if btna.value == False:
|
if btna.value == False:
|
||||||
self.running = True
|
self.running = True
|
||||||
print("STARTING")
|
print("\nSTARTING")
|
||||||
time.sleep(0.5) # lazy debounce
|
time.sleep(0.5) # lazy debounce
|
||||||
if btnb.value == False:
|
if btnb.value == False:
|
||||||
self.monitorMode = 'addressEntry' if self.monitorMode != 'addressEntry' else 'dataEntry'
|
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
|
time.sleep(0.5) # lazy debounce
|
||||||
if keypad_event and keypad_event.released:
|
if keypad_event and keypad_event.released:
|
||||||
new_digit_0x = hex(keypad_event.key_number)
|
new_digit_0x = hex(keypad_event.key_number)
|
||||||
|
|
@ -103,9 +114,10 @@ class CPU:
|
||||||
print("MA", self.monitorAddressInput)
|
print("MA", self.monitorAddressInput)
|
||||||
else:
|
else:
|
||||||
cat = self.monitorDataInput + new_digit
|
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("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
|
# TODO: update data with keypad
|
||||||
# then, automatically go to next address (?)
|
# then, automatically go to next address (?)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue