diff --git a/src/pi-pico/cpu-pi-pico.py b/src/pi-pico/cpu-pi-pico.py index 13dc4cf..ac3b280 100644 --- a/src/pi-pico/cpu-pi-pico.py +++ b/src/pi-pico/cpu-pi-pico.py @@ -53,8 +53,6 @@ class CPU: def load_memory(self, bytes): self.memory = bytes + bytearray(256 - len(bytes)) - print(type(self.memory)) - print('mem 254', self.memory[254]) # print(self.memory) def start(self): @@ -63,18 +61,16 @@ class CPU: def step(self): if self.IP >= 255: # TODO CHECK self.IP = 0 - print("IP:", self.IP) + print("IP:", toHex(self.IP)) self.instruction['opcode'] = self.memory[self.IP] self.IP = self.IP+1 self.instruction['operand'] = self.memory[self.IP] self.IP = self.IP+1 - print(self.memory[self.IP -1], self.memory[self.IP-2]) - print(self.instruction) self.nums2mnems[self.instruction['opcode']](self, self.instruction['operand']) - print("instr:", self.instruction['opcode'], self.instruction['operand']) + print("instr:", toHex(self.instruction['opcode']), toHex(self.instruction['operand'])) print("mnem:", self.nums2mnems[self.instruction['opcode']]) - print("acc:", self.acc) + print("acc:", self.acc, "N:", self.flags['N']) print("running:", self.running) print() # self.print_screen() @@ -89,9 +85,15 @@ class CPU: def lda_lit(self, operand): self.acc = operand - + self.flags['Z'] = True if self.acc == 0 else False + self.flags['Eq'] = True if self.acc == operand else False + self.flags['N'] = True if self.acc > 127 else False + def lda_mem(self, operand): self.acc = self.memory[operand] + self.flags['Z'] = True if self.acc == 0 else False + self.flags['Eq'] = True if self.acc == operand else False + self.flags['N'] = True if self.acc > 127 else False def sta_lit(self, operand): self.memory[operand] = self.acc @@ -147,10 +149,12 @@ class CPU: self.IP = operand def jmp_mem(self, operand): - self.IP = memory[operand] + self.IP = self.memory[operand] - def ske(self, operand): - if self.flags['Eq']: + def ske(self, operand): # FIXME +# if self.flags['Eq']: +# self.IP += 2 + if self.acc == operand: self.IP += 2 def skz(self, operand): @@ -330,14 +334,20 @@ class Monitor: cpu = CPU() monitor = Monitor(cpu) -preamble = '00' * 64 -prog = preamble + '02 01 13 f0 12 f0 04 02 03 f0 12 f0 05 41 08 00 06 40 00 00' # STRIPES +# preamble = '00 ' * 64 +# prog = preamble + '02 01 13 f0 12 f0 04 02 03 f0 12 f0 05 41 08 00 06 40 00 00' # STRIPES +# offset = 64 +# prog = preamble + '02 01 13 f0 12 f0 04 02 03 f0 05 08 09 00 04 09 03 f0 07 41 06' + toHex(offset) + '00 00' #prog = '00' -program_bytes = bytearray.fromhex(prog.replace(" ", "")) +# program_bytes = bytearray.fromhex(prog.replace(" ", "")) # Add jmp at addr 254: #program_with_jump = program_bytes + bytearray(254 - len(program_bytes)) + bytearray.fromhex('0600') # jump to addr 00 -program_with_jump = program_bytes + bytearray(254 - len(program_bytes)) + bytearray.fromhex('0640') # jump to addr 0x40 (dec 64) -cpu.load_memory(program_with_jump) +# program_with_jump = program_bytes + bytearray(254 - len(program_bytes)) + bytearray.fromhex('0640') # jump to addr 0x40 (dec 64) + +with open('test-multiply2.bin', 'rb') as file: + program_bytes = bytearray(file.read()) + +cpu.load_memory(program_bytes) monitor.run() \ No newline at end of file