X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fz80%2Ftables.py;h=ec77dae34926a582bbe23cd044e688f82adfb5ff;hb=bcd4e47e8cc688d2a04c6fbfde1e0a354405f769;hp=b0d9e5213728feb4426059a005d0b5ffcb7784bb;hpb=26abbf3762e19d89ab578905aaba24e8764d1696;p=libsigrokdecode.git diff --git a/decoders/z80/tables.py b/decoders/z80/tables.py index b0d9e52..ec77dae 100644 --- a/decoders/z80/tables.py +++ b/decoders/z80/tables.py @@ -24,28 +24,30 @@ Instruction tuple: (d, i, ro, wo, rep, format string) used for the displacement and the immediate operand, respectively. An operand consisting of more than one byte is assembled in little endian order. - The format string should refer to the {d} and {i} operands by name. - Displacements are interpreted as signed integers, whereas immediate - operands are always read as unsigned. The tables for instructions - operating on the IX/IY index registers additionally use {r} in the - format string as a placeholder for the register name. The placeholders ro and wo are the number of bytes the instruction is expected to read or write, respectively. These counts are used for both memory and I/O access, but not for immediate operands. A negative value indicates that the operand byte order is big endian rather than the usual little endian. The placeholder rep is a boolean used to mark repeating instructions. + The format string should refer to the {d} and {i} operands by name. + Displacements are interpreted as signed integers, whereas immediate + operands are always read as unsigned. The tables for instructions + operating on the IX/IY index registers additionally use {r} in the + format string as a placeholder for the register name. + Relative jump instructions may specify {j} instead of {d} to output + the displacement relative to the start of the instruction. ''' # Instructions without a prefix main_instructions = { 0x00: (0, 0, 0, 0, False, 'NOP'), - 0x01: (0, 2, 0, 0, False, 'LD BC,{i:04X}h'), + 0x01: (0, 2, 0, 0, False, 'LD BC,{i:04H}h'), 0x02: (0, 0, 0, 1, False, 'LD (BC),A'), 0x03: (0, 0, 0, 0, False, 'INC BC'), 0x04: (0, 0, 0, 0, False, 'INC B'), 0x05: (0, 0, 0, 0, False, 'DEC B'), - 0x06: (0, 1, 0, 0, False, 'LD B,{i:02X}h'), + 0x06: (0, 1, 0, 0, False, 'LD B,{i:02H}h'), 0x07: (0, 0, 0, 0, False, 'RLCA'), 0x08: (0, 0, 0, 0, False, 'EX AF,AF\''), 0x09: (0, 0, 0, 0, False, 'ADD HL,BC'), @@ -53,58 +55,58 @@ main_instructions = { 0x0B: (0, 0, 0, 0, False, 'DEC BC'), 0x0C: (0, 0, 0, 0, False, 'INC C'), 0x0D: (0, 0, 0, 0, False, 'DEC C'), - 0x0E: (0, 1, 0, 0, False, 'LD C,{i:02X}h'), + 0x0E: (0, 1, 0, 0, False, 'LD C,{i:02H}h'), 0x0F: (0, 0, 0, 0, False, 'RRCA'), - 0x10: (1, 0, 0, 0, False, 'DJNZ {d:+d}'), - 0x11: (0, 2, 0, 0, False, 'LD DE,{i:04X}h'), + 0x10: (1, 0, 0, 0, False, 'DJNZ ${j:+d}'), + 0x11: (0, 2, 0, 0, False, 'LD DE,{i:04H}h'), 0x12: (0, 0, 0, 1, False, 'LD (DE),A'), 0x13: (0, 0, 0, 0, False, 'INC DE'), 0x14: (0, 0, 0, 0, False, 'INC D'), 0x15: (0, 0, 0, 0, False, 'DEC D'), - 0x16: (0, 1, 0, 0, False, 'LD D,{i:02X}h'), + 0x16: (0, 1, 0, 0, False, 'LD D,{i:02H}h'), 0x17: (0, 0, 0, 0, False, 'RLA'), - 0x18: (1, 0, 0, 0, False, 'JR {d:+d}'), + 0x18: (1, 0, 0, 0, False, 'JR ${j:+d}'), 0x19: (0, 0, 0, 0, False, 'ADD HL,DE'), 0x1A: (0, 0, 1, 0, False, 'LD A,(DE)'), 0x1B: (0, 0, 0, 0, False, 'DEC DE'), 0x1C: (0, 0, 0, 0, False, 'INC E'), 0x1D: (0, 0, 0, 0, False, 'DEC E'), - 0x1E: (0, 1, 0, 0, False, 'LD E,{i:02X}h'), + 0x1E: (0, 1, 0, 0, False, 'LD E,{i:02H}h'), 0x1F: (0, 0, 0, 0, False, 'RRA'), - 0x20: (1, 0, 0, 0, False, 'JR NZ,{d:+d}'), - 0x21: (0, 2, 0, 0, False, 'LD HL,{i:04X}h'), - 0x22: (0, 2, 0, 2, False, 'LD ({i:04X}h),HL'), + 0x20: (1, 0, 0, 0, False, 'JR NZ,${j:+d}'), + 0x21: (0, 2, 0, 0, False, 'LD HL,{i:04H}h'), + 0x22: (0, 2, 0, 2, False, 'LD ({i:04H}h),HL'), 0x23: (0, 0, 0, 0, False, 'INC HL'), 0x24: (0, 0, 0, 0, False, 'INC H'), 0x25: (0, 0, 0, 0, False, 'DEC H'), - 0x26: (0, 1, 0, 0, False, 'LD H,{i:02X}h'), + 0x26: (0, 1, 0, 0, False, 'LD H,{i:02H}h'), 0x27: (0, 0, 0, 0, False, 'DAA'), - 0x28: (1, 0, 0, 0, False, 'JR Z,{d:+d}'), + 0x28: (1, 0, 0, 0, False, 'JR Z,${j:+d}'), 0x29: (0, 0, 0, 0, False, 'ADD HL,HL'), - 0x2A: (0, 2, 2, 0, False, 'LD HL,({i:04X}h)'), + 0x2A: (0, 2, 2, 0, False, 'LD HL,({i:04H}h)'), 0x2B: (0, 0, 0, 0, False, 'DEC HL'), 0x2C: (0, 0, 0, 0, False, 'INC L'), 0x2D: (0, 0, 0, 0, False, 'DEC L'), - 0x2E: (0, 1, 0, 0, False, 'LD L,{i:02X}h'), + 0x2E: (0, 1, 0, 0, False, 'LD L,{i:02H}h'), 0x2F: (0, 0, 0, 0, False, 'CPL'), - 0x30: (1, 0, 0, 0, False, 'JR NC,{d:+d}'), - 0x31: (0, 2, 0, 0, False, 'LD SP,{i:04X}h'), - 0x32: (0, 2, 0, 1, False, 'LD ({i:04X}h),A'), + 0x30: (1, 0, 0, 0, False, 'JR NC,${j:+d}'), + 0x31: (0, 2, 0, 0, False, 'LD SP,{i:04H}h'), + 0x32: (0, 2, 0, 1, False, 'LD ({i:04H}h),A'), 0x33: (0, 0, 0, 0, False, 'INC SP'), 0x34: (0, 0, 1, 1, False, 'INC (HL)'), 0x35: (0, 0, 1, 1, False, 'DEC (HL)'), - 0x36: (0, 1, 0, 1, False, 'LD (HL),{i:02X}h'), + 0x36: (0, 1, 0, 1, False, 'LD (HL),{i:02H}h'), 0x37: (0, 0, 0, 0, False, 'SCF'), - 0x38: (1, 0, 0, 0, False, 'JR C,{d:+d}'), + 0x38: (1, 0, 0, 0, False, 'JR C,${j:+d}'), 0x39: (0, 0, 0, 0, False, 'ADD HL,SP'), - 0x3A: (0, 2, 1, 0, False, 'LD A,({i:04X}h)'), + 0x3A: (0, 2, 1, 0, False, 'LD A,({i:04H}h)'), 0x3B: (0, 0, 0, 0, False, 'DEC SP'), 0x3C: (0, 0, 0, 0, False, 'INC A'), 0x3D: (0, 0, 0, 0, False, 'DEC A'), - 0x3E: (0, 1, 0, 0, False, 'LD A,{i:02X}h'), + 0x3E: (0, 1, 0, 0, False, 'LD A,{i:02H}h'), 0x3F: (0, 0, 0, 0, False, 'CCF'), 0x40: (0, 0, 0, 0, False, 'LD B,B'), @@ -245,70 +247,70 @@ main_instructions = { 0xC0: (0, 0, 2, 0, False, 'RET NZ'), 0xC1: (0, 0, 2, 0, False, 'POP BC'), - 0xC2: (0, 2, 0, 0, False, 'JP NZ,{i:04X}h'), - 0xC3: (0, 2, 0, 0, False, 'JP {i:04X}h'), - 0xC4: (0, 2, 0,-2, False, 'CALL NZ,{i:04X}h'), + 0xC2: (0, 2, 0, 0, False, 'JP NZ,{i:04H}h'), + 0xC3: (0, 2, 0, 0, False, 'JP {i:04H}h'), + 0xC4: (0, 2, 0,-2, False, 'CALL NZ,{i:04H}h'), 0xC5: (0, 0, 0,-2, False, 'PUSH BC'), - 0xC6: (0, 1, 0, 0, False, 'ADD A,{i:02X}h'), + 0xC6: (0, 1, 0, 0, False, 'ADD A,{i:02H}h'), 0xC7: (0, 0, 0,-2, False, 'RST 00h'), 0xC8: (0, 0, 2, 0, False, 'RET Z'), 0xC9: (0, 0, 2, 0, False, 'RET'), - 0xCA: (0, 2, 0, 0, False, 'JP Z,{i:04X}h'), + 0xCA: (0, 2, 0, 0, False, 'JP Z,{i:04H}h'), - 0xCC: (0, 2, 0,-2, False, 'CALL Z,{i:04X}h'), - 0xCD: (0, 2, 0,-2, False, 'CALL {i:04X}h'), - 0xCE: (0, 1, 0, 0, False, 'ADC A,{i:02X}h'), + 0xCC: (0, 2, 0,-2, False, 'CALL Z,{i:04H}h'), + 0xCD: (0, 2, 0,-2, False, 'CALL {i:04H}h'), + 0xCE: (0, 1, 0, 0, False, 'ADC A,{i:02H}h'), 0xCF: (0, 0, 0,-2, False, 'RST 08h'), 0xD0: (0, 0, 2, 0, False, 'RET NC'), 0xD1: (0, 0, 2, 0, False, 'POP DE'), - 0xD2: (0, 2, 0, 0, False, 'JP NC,{i:04X}h'), - 0xD3: (0, 1, 0, 1, False, 'OUT ({i:02X}h),A'), - 0xD4: (0, 2, 0,-2, False, 'CALL NC,{i:04X}h'), + 0xD2: (0, 2, 0, 0, False, 'JP NC,{i:04H}h'), + 0xD3: (0, 1, 0, 1, False, 'OUT ({i:02H}h),A'), + 0xD4: (0, 2, 0,-2, False, 'CALL NC,{i:04H}h'), 0xD5: (0, 0, 0,-2, False, 'PUSH DE'), - 0xD6: (0, 1, 0, 0, False, 'SUB {i:02X}h'), + 0xD6: (0, 1, 0, 0, False, 'SUB {i:02H}h'), 0xD7: (0, 0, 0,-2, False, 'RST 10h'), 0xD8: (0, 0, 2, 0, False, 'RET C'), 0xD9: (0, 0, 0, 0, False, 'EXX'), - 0xDA: (0, 2, 0, 0, False, 'JP C,{i:04X}h'), - 0xDB: (0, 1, 1, 0, False, 'IN A,({i:02X}h)'), - 0xDC: (0, 2, 0,-2, False, 'CALL C,{i:04X}h'), + 0xDA: (0, 2, 0, 0, False, 'JP C,{i:04H}h'), + 0xDB: (0, 1, 1, 0, False, 'IN A,({i:02H}h)'), + 0xDC: (0, 2, 0,-2, False, 'CALL C,{i:04H}h'), - 0xDE: (0, 1, 0, 0, False, 'SBC A,{i:02X}h'), + 0xDE: (0, 1, 0, 0, False, 'SBC A,{i:02H}h'), 0xDF: (0, 0, 0,-2, False, 'RST 18h'), 0xE0: (0, 0, 2, 0, False, 'RET PO'), 0xE1: (0, 0, 2, 0, False, 'POP HL'), - 0xE2: (0, 2, 0, 0, False, 'JP PO,{i:04X}h'), + 0xE2: (0, 2, 0, 0, False, 'JP PO,{i:04H}h'), 0xE3: (0, 0, 2, 2, False, 'EX (SP),HL'), - 0xE4: (0, 2, 0,-2, False, 'CALL PO,{i:04X}h'), + 0xE4: (0, 2, 0,-2, False, 'CALL PO,{i:04H}h'), 0xE5: (0, 0, 0,-2, False, 'PUSH HL'), - 0xE6: (0, 1, 0, 0, False, 'AND {i:02X}h'), + 0xE6: (0, 1, 0, 0, False, 'AND {i:02H}h'), 0xE7: (0, 0, 0,-2, False, 'RST 20h'), 0xE8: (0, 0, 2, 0, False, 'RET PE'), 0xE9: (0, 0, 0, 0, False, 'JP (HL)'), - 0xEA: (0, 2, 0, 0, False, 'JP PE,{i:04X}h'), + 0xEA: (0, 2, 0, 0, False, 'JP PE,{i:04H}h'), 0xEB: (0, 0, 0, 0, False, 'EX DE,HL'), - 0xEC: (0, 2, 0,-2, False, 'CALL PE,{i:04X}h'), + 0xEC: (0, 2, 0,-2, False, 'CALL PE,{i:04H}h'), - 0xEE: (0, 1, 0, 0, False, 'XOR {i:02X}h'), + 0xEE: (0, 1, 0, 0, False, 'XOR {i:02H}h'), 0xEF: (0, 0, 0,-2, False, 'RST 28h'), 0xF0: (0, 0, 2, 0, False, 'RET P'), 0xF1: (0, 0, 2, 0, False, 'POP AF'), - 0xF2: (0, 2, 0, 0, False, 'JP P,{i:04X}h'), + 0xF2: (0, 2, 0, 0, False, 'JP P,{i:04H}h'), 0xF3: (0, 0, 0, 0, False, 'DI'), - 0xF4: (0, 2, 0,-2, False, 'CALL P,{i:04X}h'), + 0xF4: (0, 2, 0,-2, False, 'CALL P,{i:04H}h'), 0xF5: (0, 0, 0,-2, False, 'PUSH AF'), - 0xF6: (0, 1, 0, 0, False, 'OR {i:02X}h'), + 0xF6: (0, 1, 0, 0, False, 'OR {i:02H}h'), 0xF7: (0, 0, 0,-2, False, 'RST 30h'), 0xF8: (0, 0, 2, 0, False, 'RET M'), 0xF9: (0, 0, 0, 0, False, 'LD SP,HL'), - 0xFA: (0, 2, 0, 0, False, 'JP M,{i:04X}h'), + 0xFA: (0, 2, 0, 0, False, 'JP M,{i:04H}h'), 0xFB: (0, 0, 0, 0, False, 'EI'), - 0xFC: (0, 2, 0,-2, False, 'CALL M,{i:04X}h'), + 0xFC: (0, 2, 0,-2, False, 'CALL M,{i:04H}h'), - 0xFE: (0, 1, 0, 0, False, 'CP {i:02X}h'), + 0xFE: (0, 1, 0, 0, False, 'CP {i:02H}h'), 0xFF: (0, 0, 0,-2, False, 'RST 38h') } @@ -317,7 +319,7 @@ extended_instructions = { 0x40: (0, 0, 1, 0, False, 'IN B,(C)'), 0x41: (0, 0, 0, 1, False, 'OUT (C),B'), 0x42: (0, 0, 0, 0, False, 'SBC HL,BC'), - 0x43: (0, 2, 0, 2, False, 'LD ({i:04X}h),BC'), + 0x43: (0, 2, 0, 2, False, 'LD ({i:04H}h),BC'), 0x44: (0, 0, 0, 0, False, 'NEG'), 0x45: (0, 0, 2, 0, False, 'RETN'), 0x46: (0, 0, 0, 0, False, 'IM 0'), @@ -325,7 +327,7 @@ extended_instructions = { 0x48: (0, 0, 1, 0, False, 'IN C,(C)'), 0x49: (0, 0, 0, 1, False, 'OUT (C),C'), 0x4A: (0, 0, 0, 0, False, 'ADC HL,BC'), - 0x4B: (0, 2, 2, 0, False, 'LD BC,({i:04X}h)'), + 0x4B: (0, 2, 2, 0, False, 'LD BC,({i:04H}h)'), 0x4C: (0, 0, 0, 0, False, 'NEG'), 0x4D: (0, 0, 2, 0, False, 'RETI'), 0x4E: (0, 0, 0, 0, False, 'IM 0/1'), @@ -334,7 +336,7 @@ extended_instructions = { 0x50: (0, 0, 1, 0, False, 'IN D,(C)'), 0x51: (0, 0, 0, 1, False, 'OUT (C),D'), 0x52: (0, 0, 0, 0, False, 'SBC HL,DE'), - 0x53: (0, 2, 0, 2, False, 'LD ({i:04X}h),DE'), + 0x53: (0, 2, 0, 2, False, 'LD ({i:04H}h),DE'), 0x54: (0, 0, 0, 0, False, 'NEG'), 0x55: (0, 0, 2, 0, False, 'RETN'), 0x56: (0, 0, 0, 0, False, 'IM 1'), @@ -342,7 +344,7 @@ extended_instructions = { 0x58: (0, 0, 1, 0, False, 'IN E,(C)'), 0x59: (0, 0, 0, 1, False, 'OUT (C),E'), 0x5A: (0, 0, 0, 0, False, 'ADC HL,DE'), - 0x5B: (0, 2, 2, 0, False, 'LD DE,({i:04X}h)'), + 0x5B: (0, 2, 2, 0, False, 'LD DE,({i:04H}h)'), 0x5C: (0, 0, 0, 0, False, 'NEG'), 0x5D: (0, 0, 2, 0, False, 'RETN'), 0x5E: (0, 0, 0, 0, False, 'IM 2'), @@ -351,7 +353,7 @@ extended_instructions = { 0x60: (0, 0, 1, 0, False, 'IN H,(C)'), 0x61: (0, 0, 0, 1, False, 'OUT (C),H'), 0x62: (0, 0, 0, 0, False, 'SBC HL,HL'), - 0x63: (0, 2, 0, 2, False, 'LD ({i:04X}h),HL'), + 0x63: (0, 2, 0, 2, False, 'LD ({i:04H}h),HL'), 0x64: (0, 0, 0, 0, False, 'NEG'), 0x65: (0, 0, 2, 0, False, 'RETN'), 0x66: (0, 0, 0, 0, False, 'IM 0'), @@ -359,7 +361,7 @@ extended_instructions = { 0x68: (0, 0, 1, 0, False, 'IN L,(C)'), 0x69: (0, 0, 0, 1, False, 'OUT (C),L'), 0x6A: (0, 0, 0, 0, False, 'ADC HL,HL'), - 0x6B: (0, 2, 2, 0, False, 'LD HL,({i:04X}h)'), + 0x6B: (0, 2, 2, 0, False, 'LD HL,({i:04H}h)'), 0x6C: (0, 0, 0, 0, False, 'NEG'), 0x6D: (0, 0, 2, 0, False, 'RETN'), 0x6E: (0, 0, 0, 0, False, 'IM 0/1'), @@ -368,7 +370,7 @@ extended_instructions = { 0x70: (0, 0, 1, 0, False, 'IN (C)'), 0x71: (0, 0, 0, 1, False, 'OUT (C),0'), 0x72: (0, 0, 0, 0, False, 'SBC HL,SP'), - 0x73: (0, 2, 0, 2, False, 'LD ({i:04X}h),SP'), + 0x73: (0, 2, 0, 2, False, 'LD ({i:04H}h),SP'), 0x74: (0, 0, 0, 0, False, 'NEG'), 0x75: (0, 0, 2, 0, False, 'RETN'), 0x76: (0, 0, 0, 0, False, 'IM 1'), @@ -376,7 +378,7 @@ extended_instructions = { 0x78: (0, 0, 1, 0, False, 'IN A,(C)'), 0x79: (0, 0, 0, 1, False, 'OUT (C),A'), 0x7A: (0, 0, 0, 0, False, 'ADC HL,SP'), - 0x7B: (0, 2, 2, 0, False, 'LD SP,({i:04X}h)'), + 0x7B: (0, 2, 2, 0, False, 'LD SP,({i:04H}h)'), 0x7C: (0, 0, 0, 0, False, 'NEG'), 0x7D: (0, 0, 2, 0, False, 'RETN'), 0x7E: (0, 0, 0, 0, False, 'IM 2'), @@ -683,23 +685,23 @@ index_instructions = { 0x19: (0, 0, 0, 0, False, 'ADD {r},DE'), - 0x21: (0, 2, 0, 0, False, 'LD {r},{i:04X}h'), - 0x22: (0, 2, 0, 2, False, 'LD ({i:04X}h),{r}'), + 0x21: (0, 2, 0, 0, False, 'LD {r},{i:04H}h'), + 0x22: (0, 2, 0, 2, False, 'LD ({i:04H}h),{r}'), 0x23: (0, 0, 0, 0, False, 'INC {r}'), 0x24: (0, 0, 0, 0, False, 'INC {r}h'), 0x25: (0, 0, 0, 0, False, 'DEC {r}h'), - 0x26: (0, 1, 0, 0, False, 'LD {r}h,{i:02X}h'), + 0x26: (0, 1, 0, 0, False, 'LD {r}h,{i:02H}h'), 0x29: (0, 0, 0, 0, False, 'ADD {r},{r}'), - 0x2A: (0, 2, 2, 0, False, 'LD {r},({i:04X}h)'), + 0x2A: (0, 2, 2, 0, False, 'LD {r},({i:04H}h)'), 0x2B: (0, 0, 0, 0, False, 'DEC {r}'), 0x2C: (0, 0, 0, 0, False, 'INC {r}l'), 0x2D: (0, 0, 0, 0, False, 'DEC {r}l'), - 0x2E: (0, 1, 0, 0, False, 'LD {r}l,{i:02X}h'), + 0x2E: (0, 1, 0, 0, False, 'LD {r}l,{i:02H}h'), 0x34: (1, 0, 1, 1, False, 'INC ({r}{d:+d})'), 0x35: (1, 0, 1, 1, False, 'DEC ({r}{d:+d})'), - 0x36: (1, 1, 0, 1, False, 'LD ({r}{d:+d}),{i:02X}h'), + 0x36: (1, 1, 0, 1, False, 'LD ({r}{d:+d}),{i:02H}h'), 0x39: (0, 0, 0, 0, False, 'ADD {r},SP'),