Improve keypad monitor entry
This commit is contained in:
parent
d5ded67b79
commit
f21e57cafe
63
src/cpu.py
63
src/cpu.py
|
|
@ -27,6 +27,22 @@ km = keypad.KeyMatrix(
|
||||||
column_pins = (board.P4, board.P6, board.P8, board.P9) )
|
column_pins = (board.P4, board.P6, board.P8, board.P9) )
|
||||||
|
|
||||||
|
|
||||||
|
class TwoDigitHexInput:
|
||||||
|
def __init__(self):
|
||||||
|
self.digits = [0x0, 0x0]
|
||||||
|
self.currentDigit = 0
|
||||||
|
self.value = 0
|
||||||
|
|
||||||
|
def input(self, d):
|
||||||
|
self.digits[self.currentDigit] = d
|
||||||
|
self.value = (self.digits[0] * 16) + self.digits[1]
|
||||||
|
print("INPUT", self.digits)
|
||||||
|
self.currentDigit = 0 if self.currentDigit else 1
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.__init__()
|
||||||
|
print(self.digits)
|
||||||
|
|
||||||
|
|
||||||
class CPU:
|
class CPU:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -37,10 +53,8 @@ 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" # These are strings because it makes shifting digits in easier
|
self.monitorAddressInput = TwoDigitHexInput()
|
||||||
self.monitorDataInput = "00"
|
self.monitorDataInput = TwoDigitHexInput()
|
||||||
self.monitorAddressDisplay = "00"
|
|
||||||
self.monitorDataDisplay = "00"
|
|
||||||
|
|
||||||
|
|
||||||
def load_memory(self, bytes):
|
def load_memory(self, bytes):
|
||||||
|
|
@ -68,7 +82,7 @@ class CPU:
|
||||||
displayGroup = displayio.Group()
|
displayGroup = displayio.Group()
|
||||||
board.DISPLAY.root_group = displayGroup
|
board.DISPLAY.root_group = displayGroup
|
||||||
|
|
||||||
text = self.monitorAddressDisplay + " " + self.monitorDataDisplay
|
text = "IP " + str(self.IP) + "DATA " + str(self.memory[self.IP]) + "ACC " + str(self.acc)
|
||||||
text_area = label.Label(terminalio.FONT, text=text)
|
text_area = label.Label(terminalio.FONT, text=text)
|
||||||
text_area.x = 10
|
text_area.x = 10
|
||||||
text_area.y = 100
|
text_area.y = 100
|
||||||
|
|
@ -99,29 +113,28 @@ class CPU:
|
||||||
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("\nENTERING", self.monitorMode, "MODE")
|
print("\nENTERING", self.monitorMode, "MODE")
|
||||||
|
self.monitorDataInput.currentDigit = 0
|
||||||
|
self.monitorAddressInput.currentDigit = 0
|
||||||
time.sleep(0.5) # lazy debounce
|
time.sleep(0.5) # lazy debounce
|
||||||
if btnr.value == False:
|
if btnr.value == False:
|
||||||
print("\nSINGLE STEP FROM MONITOR ADDR")
|
print("\nSINGLE STEP FROM MONITOR ADDR")
|
||||||
self.IP = int(self.monitorAddressInput, 16)
|
# self.IP = self.monitorAddressInput.value
|
||||||
self.step()
|
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 = new_digit_0x[2:3]
|
|
||||||
if self.monitorMode == 'addressEntry':
|
if self.monitorMode == 'addressEntry':
|
||||||
cat = self.monitorAddressInput + new_digit
|
self.monitorAddressInput.input(keypad_event.key_number)
|
||||||
self.monitorAddressInput = cat[1:3]
|
self.IP = self.monitorAddressInput.value
|
||||||
print("MA", self.monitorAddressInput)
|
print("MA", self.IP)
|
||||||
else:
|
else:
|
||||||
cat = self.monitorDataInput + new_digit
|
self.monitorDataInput.input(keypad_event.key_number)
|
||||||
self.monitorDataInput = cat[1:3] # TODO this variable might not be necessary, huh?
|
self.memory[self.IP] = self.monitorDataInput.value
|
||||||
self.memory[int(self.monitorAddressInput, 16)] = int(self.monitorDataInput, 16)
|
print("MD", self.monitorDataInput.value)
|
||||||
print("MD", self.monitorDataInput)
|
if self.monitorDataInput.currentDigit == 0: # that was the second keypress, so go to the next addresss
|
||||||
print("Acc", self.acc, "Addr", self.monitorAddressInput, "Data", self.memory[int(self.monitorAddressInput, 16)])
|
self.IP = (self.IP + 1) % 256
|
||||||
|
print("ADVANCING")
|
||||||
|
print("Acc", self.acc, "IP", self.IP, "Data", self.memory[self.IP], "\n")
|
||||||
|
|
||||||
# TODO: update data with keypad
|
|
||||||
# then, automatically go to next address (?)
|
|
||||||
|
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
if self.IP >= 256:
|
if self.IP >= 256:
|
||||||
|
|
@ -148,11 +161,12 @@ class CPU:
|
||||||
t = time.time()
|
t = time.time()
|
||||||
while (time.time() - t) < 30:
|
while (time.time() - t) < 30:
|
||||||
self.read_keys()
|
self.read_keys()
|
||||||
#self.print_monitor()
|
# self.print_monitor()
|
||||||
#if self.running:
|
# if self.running:
|
||||||
# self.step()
|
# self.step()
|
||||||
# time.time.sleep(0.5)
|
# time.sleep(0.5)
|
||||||
print("timeout")
|
print("timeout")
|
||||||
|
print(self.memory)
|
||||||
|
|
||||||
def hlt(self, operand):
|
def hlt(self, operand):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
@ -275,7 +289,8 @@ class CPU:
|
||||||
|
|
||||||
cpu = CPU()
|
cpu = CPU()
|
||||||
|
|
||||||
prog = '04 FF 04 01 14 01 00 00'
|
#prog = '04 FF 04 01 14 01 00 00'
|
||||||
|
prog = '00'
|
||||||
program_bytes = bytearray.fromhex(prog.replace(" ", ""))
|
program_bytes = bytearray.fromhex(prog.replace(" ", ""))
|
||||||
# Add jmp at addr 254:
|
# Add jmp at addr 254:
|
||||||
program_with_jump = program_bytes + bytearray(254 - len(program_bytes)) + bytearray.fromhex('0600')
|
program_with_jump = program_bytes + bytearray(254 - len(program_bytes)) + bytearray.fromhex('0600')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue