kosarev / z80

Fast and flexible Z80/i8080 emulator with C++ and Python APIs
MIT License
63 stars 10 forks source link

Emulator exception on 'ix' instruction #57

Closed mortenjc closed 1 month ago

mortenjc commented 1 month ago

Hey

I am running some old z80 code (from the late 70's). While simulating keyboard input I managed to cause an exception in the emulator. It looks like the 'ix' instruction is the culprit.

As far as I can tell, the instruction DD BE 0F is valid.

Please let me know if I can assist in debugging this.

Cheers Morten

--- output from my wrapper

loading program: Emulator exception (ix) loaded 3 bytes from list at address 2000h ########### HEXDUMP 0x2000 - 0xffff #################################### icount 0 2000 DD BE 0F FF FF FF FF FF FF FF FF FF FF FF FF FF ................ .... ########### HEXDUMP END ################################################# Traceback (most recent call last): File "/Users/mortenchristensen/projects/mjcgit/Q1/src/emulator.py", line 86, in main(args) File "/Users/mortenchristensen/projects/mjcgit/Q1/src/emulator.py", line 40, in main inst_str, bytes, bytes_str = C.getinst() ^^^^^^^^^^^ File "/Users/mortenchristensen/projects/mjcgit/Q1/src/cpu.py", line 40, in getinst instr = self.b.build_instr(self.m.pc, bytes(self.m.memory[self.m.pc:self.m.pc + Cpu.MAX_INSTR_SIZE])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/z80-1.0b2-py3.11-macosx-12-x86_64.egg/z80/_disasm.py", line 291, in build_instr op = self.build_op(addr, op_text) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/z80-1.0b2-py3.11-macosx-12-x86_64.egg/z80/_disasm.py", line 229, in build_op return At(self.build_op(addr, text[1:-1])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/z80-1.0b2-py3.11-macosx-12-x86_64.egg/z80/_disasm.py", line 243, in __build_op op = self.OPS[text[:2]]


KeyError: 'ix'
mortenjc commented 1 month ago

This seems to be an issue with _disasm.py - I pursued this a little further. Could it be that we just need to change

    'hl': HL,
    'i': IReg,
    'iy': IY,
    'Pbc': BC,

to add the missing 'ix' ?

    'hl': HL,
    'i': IReg,
    'ix': IX,
    'iy': IY,
    'Pbc': BC, 
kosarev commented 1 month ago

to add the missing 'ix' ?

Yes, fixed in 897454f6cda1729fafb8cb8d7f02f1d38fcfee29. I only used the disassembler on a few very specific (though large) binaries, so It's very possible that the tables still miss some operands. Thanks for catching and investigating!

mortenjc commented 1 month ago

works for me