udis/z80.py

632 lines
17 KiB
Python
Raw Normal View History

2015-06-24 02:59:44 +00:00
##########################################################################
#
# Processor specific code
# CPU = "Z80"
# Description = "Zilog 8-bit microprocessor."
# DataWidth = 8 # 8-bit data
# AddressWidth = 16 # 16-bit addresses
# Maximum length of an instruction (for formatting purposes)
maxLength = 3
# Leadin bytes for multibyte instructions
2015-06-25 02:41:15 +00:00
leadInBytes = [0xcb, 0xdd, 0xfd]
2015-06-24 02:59:44 +00:00
# Addressing mode table
# List of addressing modes and corresponding format strings for operands.
addressModeTable = {
"implied" : "",
2015-06-25 02:41:15 +00:00
"a" : "a",
"b" : "b",
"c" : "c",
"d" : "d",
"e" : "e",
"h" : "h",
"l" : "l",
"sp" : "sp",
"bc" : "bc",
"de" : "de",
"hl" : "hl",
"af,af" : "af,af",
"hl,bc" : "hl,bc",
"hl,de" : "hl,bc",
"hl,hl" : "hl,hl",
"hl,sp" : "hl,sp",
"bc,nn" : "bc,${1:02X}{0:02X}",
"de,nn" : "de,${1:02X}{0:02X}",
"hl,nn" : "hl,${1:02X}{0:02X}",
"sp,nn" : "sp,${1:02X}{0:02X}",
"indnn,hl" : "(${1:02X}{0:02X}),hl",
"indhl,n" : "(hl),(${0:02X})",
"a,indnn" : "a,(${1:02X}{0:02X})",
"indnn,a" : "(${1:02X}{0:02X}),a",
"hl,indnn" : "hl,(${1:02X}{0:02X})",
"indbc,a" : "(bc),a",
"indde,a" : "(de),a",
"indhl" : "(hl)",
"a,indde" : "a,(de)",
"a,indbc" : "a,(bc)",
"n" : "${0:02X}",
"a,n" : "a,${0:02X}",
"b,n" : "b,${0:02X}",
"c,n" : "b,${0:02X}",
"d,n" : "d,${0:02X}",
"e,n" : "e,${0:02X}",
"h,n" : "h,${0:02X}",
"l,n" : "l,${0:02X}",
"nz,n" : "nz,${0:04X}",
"z,n" : "z,${0:04X}",
"nc,n" : "nc,${0:04X}",
"c,n" : "c,${0:04X}",
2015-06-24 02:59:44 +00:00
}
# Op Code Table
# Key is numeric opcode (possibly multiple bytes)
# Value is a list:
# # bytes
# mnemonic
# addressing mode
# flags (e.g. pcr)
opcodeTable = {
0x00 : [ 1, "nop", "implied" ],
2015-06-25 02:41:15 +00:00
0x01 : [ 3, "ld", "bc,nn" ],
0x02 : [ 1, "ld", "indbc,a" ],
0x03 : [ 1, "inc", "bc" ],
0x04 : [ 1, "inc", "b" ],
0x05 : [ 1, "dec", "b" ],
0x06 : [ 2, "ld", "b,n" ],
2015-06-24 02:59:44 +00:00
0x07 : [ 1, "rlca", "implied" ],
2015-06-25 02:41:15 +00:00
0x08 : [ 1, "ex", "af,af" ],
0x09 : [ 1, "add", "hl,bc" ],
0x0a : [ 1, "ld", "a,indbc" ],
0x0b : [ 1, "dec", "bc" ],
0x0c : [ 1, "inc", "c" ],
0x0d : [ 1, "dec", "c" ],
0x0e : [ 2, "ld", "c,n" ],
2015-06-24 02:59:44 +00:00
0x0f : [ 1, "rrca", "implied" ],
2015-06-25 02:41:15 +00:00
0x10 : [ 2, "djnz", "n", pcr ],
0x11 : [ 3, "ld", "de,nn" ],
0x12 : [ 1, "ld", "indde,a" ],
0x13 : [ 1, "inc", "de" ],
0x14 : [ 1, "inc", "d" ],
0x15 : [ 1, "dec", "d" ],
0x16 : [ 2, "ld", "d,n" ],
2015-06-24 02:59:44 +00:00
0x17 : [ 1, "rla", "implied" ],
2015-06-25 02:41:15 +00:00
0x18 : [ 2, "jr", "n", pcr ],
0x19 : [ 1, "add", "hl,de" ],
0x1a : [ 1, "ld", "a,indde" ],
0x1b : [ 1, "dec", "de" ],
0x1c : [ 1, "inc", "e" ],
0x1d : [ 1, "dec", "e" ],
0x1e : [ 2, "ld", "e,n" ],
2015-06-24 02:59:44 +00:00
0x1f : [ 1, "rra", "implied" ],
2015-06-25 02:41:15 +00:00
0x20 : [ 2, "jr", "nz,n" ],
0x21 : [ 3, "ld", "hl,nn" ],
0x22 : [ 3, "ld", "indnn,hl" ],
0x23 : [ 1, "inc", "hl" ],
0x24 : [ 1, "inc", "h" ],
0x25 : [ 1, "dec", "h" ],
0x26 : [ 2, "ld", "h,n" ],
0x27 : [ 1, "daa", "implied" ],
0x28 : [ 2, "jr", "z,n", pcr ],
0x29 : [ 1, "add", "hl,hl" ],
0x2a : [ 3, "ld", "hl,indnn" ],
0x2b : [ 1, "dec", "hl" ],
0x2c : [ 1, "inc", "l" ],
0x2d : [ 1, "dec", "l" ],
0x2e : [ 2, "ld", "l,n" ],
0x2f : [ 1, "cpl", "implied" ],
0x30 : [ 2, "jr", "nc,n", pcr ],
0x31 : [ 3, "ld", "sp,nn" ],
0x32 : [ 3, "ld", "indnn,a" ],
0x33 : [ 1, "inc", "sp" ],
0x34 : [ 1, "inc", "indhl" ],
0x35 : [ 1, "dec", "indhl" ],
0x36 : [ 2, "ld", "indhl,n" ],
0x37 : [ 1, "scf", "implied" ],
0x38 : [ 2, "jr", "c,n", pcr ],
0x39 : [ 1, "add", "hl,sp" ],
0x3a : [ 3, "ld", "a,indnn" ],
0x3b : [ 1, "dec", "sp" ],
0x3c : [ 1, "inc", "a" ],
0x3d : [ 1, "dec", "a" ],
0x3e : [ 2, "ld", "a,n" ],
0x3f : [ 1, "ccf", "implied" ],
2015-06-24 02:59:44 +00:00
# [ "ld b,b", 1 ], # 40
# [ "ld b,c", 1 ], # 41
# [ "ld b,d", 1 ], # 42
# [ "ld b,e", 1 ], # 43
# [ "ld b,h", 1 ], # 44
# [ "ld b,l", 1 ], # 45
# [ "ld b,(hl)", 1 ], # 46
# [ "ld b,a", 1 ], # 47
# [ "ld c,b", 1 ], # 48
# [ "ld c,c", 1 ], # 49
# [ "ld c,d", 1 ], # 4A
# [ "ld c,e", 1 ], # 4B
# [ "ld c,h", 1 ], # 4C
# [ "ld c,l", 1 ], # 4D
# [ "ld c,(hl)", 1 ], # 4E
# [ "ld c,a", 1 ], # 4F
#
# [ "ld d,b", 1 ], # 50
# [ "ld d,c", 1 ], # 51
# [ "ld d,d", 1 ], # 52
# [ "ld d,e", 1 ], # 53
# [ "ld d,h", 1 ], # 54
# [ "ld d,l", 1 ], # 55
# [ "ld d,(hl)", 1 ], # 56
# [ "ld d,a", 1 ], # 57
# [ "ld e,b", 1 ], # 58
# [ "ld e,c", 1 ], # 59
# [ "ld e,d", 1 ], # 5A
# [ "ld e,e", 1 ], # 5B
# [ "ld e,h", 1 ], # 5C
# [ "ld e,l", 1 ], # 5D
# [ "ld e,(hl)", 1 ], # 5E
# [ "ld e,a", 1 ], # 5F
#
# [ "ld h,b", 1 ], # 60
# [ "ld h,c", 1 ], # 61
# [ "ld h,d", 1 ], # 62
# [ "ld h,e", 1 ], # 63
# [ "ld h,h", 1 ], # 64
# [ "ld h,l", 1 ], # 65
# [ "ld h,(hl)", 1 ], # 66
# [ "ld h,a", 1 ], # 67
# [ "ld l,b", 1 ], # 68
# [ "ld l,c", 1 ], # 69
# [ "ld l,d", 1 ], # 6A
# [ "ld l,e", 1 ], # 6B
# [ "ld l,h", 1 ], # 6C
# [ "ld l,l", 1 ], # 6D
# [ "ld l,(hl)", 1 ], # 6E
# [ "ld l,a", 1 ], # 6F
#
# [ "ld (hl),b", 1 ], # 70
# [ "ld (hl),c", 1 ], # 71
# [ "ld (hl),d", 1 ], # 72
# [ "ld (hl),e", 1 ], # 73
# [ "ld (hl),h", 1 ], # 74
# [ "ld (hl),l", 1 ], # 75
# [ "halt", 1 ], # 76
# [ "ld (hl),a", 1 ], # 77
# [ "ld a,b", 1 ], # 78
# [ "ld a,c", 1 ], # 79
# [ "ld a,d", 1 ], # 7A
# [ "ld a,e", 1 ], # 7B
# [ "ld a,h", 1 ], # 7C
# [ "ld a,l", 1 ], # 7D
# [ "ld a,(hl)", 1 ], # 7E
# [ "ld a,a", 1 ], # 7F
#
# [ "add a,b", 1 ], # 80
# [ "add a,c", 1 ], # 81
# [ "add a,d", 1 ], # 82
# [ "add a,ee", 1 ], # 83
# [ "add a,h", 1 ], # 84
# [ "add a,l", 1 ], # 85
# [ "add a,(hl)", 1 ], # 86
# [ "add a,a", 1 ], # 87
# [ "adc a,b", 1 ], # 88
# [ "adc a,c", 1 ], # 89
# [ "adc a,d", 1 ], # 8A
# [ "adc a,e", 1 ], # 8B
# [ "adc a,h", 1 ], # 8C
# [ "adc a,l", 1 ], # 8D
# [ "adc a,(hl)", 1 ], # 8E
# [ "adc a,a", 1 ], # 8F
#
# [ "sub b", 1 ], # 90
# [ "sub c", 1 ], # 91
# [ "sub d", 1 ], # 92
# [ "sub e", 1 ], # 93
# [ "sub h", 1 ], # 94
# [ "sub l", 1 ], # 95
# [ "sub (hl)", 1 ], # 96
# [ "sub a", 1 ], # 97
# [ "sbc a,b", 1 ], # 98
# [ "sbc a,c", 1 ], # 99
# [ "sbc a,d", 1 ], # 9A
# [ "sbc a,e", 1 ], # 9B
# [ "sbc a,h", 1 ], # 9C
# [ "sbc a,l", 1 ], # 9D
# [ "sbc a,(hl)", 1 ], # 9E
# [ "sbc a,a", 1 ], # 9F
#
# [ "and b", 1 ], # A0
# [ "and c", 1 ], # A1
# [ "and d", 1 ], # A2
# [ "and e", 1 ], # A3
# [ "and h", 1 ], # A4
# [ "and l", 1 ], # A5
# [ "and (hl)", 1 ], # A6
# [ "and a", 1 ], # A7
# [ "xor b", 1 ], # A8
# [ "xor c", 1 ], # A9
# [ "xor d", 1 ], # AA
# [ "xor e", 1 ], # AB
# [ "xor h", 1 ], # AC
# [ "xor l", 1 ], # AD
# [ "xor (hl)", 1 ], # AE
# [ "xor a", 1 ], # AF
#
# [ "or b", 1 ], # B0
# [ "or c", 1 ], # B1
# [ "or d", 1 ], # B2
# [ "or e", 1 ], # B3
# [ "or h", 1 ], # B4
# [ "or l", 1 ], # B5
# [ "or (hl)", 1 ], # B6
# [ "or a", 1 ], # B7
# [ "cp b", 1 ], # B8
# [ "cp c", 1 ], # B9
# [ "cp d", 1 ], # BA
# [ "cp e", 1 ], # BB
# [ "cp h", 1 ], # BC
# [ "cp l", 1 ], # BD
# [ "cp (hl)", 1 ], # BE
# [ "cp a", 1 ], # BF
#
# [ "ret nz", 1 ], # C0
# [ "pop bc", 1 ], # C1
# [ "jp nz,", 3 ], # C2
# [ "jp ", 3 ], # C3
# [ "call nz,", 3 ], # C4
# [ "push bc", 1 ], # C5
# [ "ada a,", 2 ], # C6
# [ "rst 00", 1 ], # C7
# [ "ret z", 1 ], # C8
# [ "ret", 1 ], # C9
# [ "jp z,", 3 ], # CA
# [ "prefix", 2 ], # CB
# [ "call z,", 3 ], # CC
# [ "call ", 3 ], # CD
# [ "adc a,", 2 ], # CE
# [ "rst 08", 1 ], # CF
#
# [ "ret nc", 1 ], # D0
# [ "pop de", 1 ], # D1
# [ "jp nc,", 3 ], # D2
# [ "out (", 2 ], # D3 then append "),a"
# [ "call nc,", 3 ], # D4
# [ "push de", 1 ], # D5
# [ "sub ", 2 ], # D6
# [ "rst 10", 1 ], # D7
# [ "ret c", 1 ], # D8
# [ "exx", 1 ], # D9
# [ "jp c,", 3 ], # DA
# [ "in a,(", 2 ], # DB then append ")"
# [ "call c,", 3 ], # DC
# [ "prefix", 2 ], # DD
# [ "sbc a,", 2 ], # DE
# [ "rst 18", 1 ], # DF
#
# [ "ret po", 1 ], # E0
# [ "pop hl", 1 ], # E1
# [ "jp po,", 3 ], # E2
# [ "ex (sp),hl", 1 ],# E3
# [ "call po,", 3 ], # E4
# [ "push hl", 1 ], # E5
# [ "and ", 2 ], # E6
# [ "rst 20", 1 ], # E7
# [ "ret pe", 1 ], # E8
# [ "jp (hl)", 1 ], # E9
# [ "jp pe,", 3 ], # EA
# [ "ex de,hl", 1 ], # EB
# [ "call pe,", 3 ], # EC
# [ "prefix", 2 ], # ED
# [ "xor ", 2 ], # EE
# [ "rst 28", 1 ], # EF
#
# [ "ret p", 1 ], # F0
# [ "pop af", 1 ], # F1
# [ "jp p,", 3 ], # F2
# [ "di", 1 ], # F3
# [ "call p,", 3 ], # F4
# [ "push af", 1 ], # F5
# [ "or ", 2 ], # F6
# [ "rst 30", 1 ], # F7
# [ "ret m", 1 ], # F8
# [ "ld sp,phl", 1 ], # F9
# [ "jp m,", 3 ], # FA
# [ "ei", 1 ], # FB
# [ "call m,", 3 ], # FC
# [ "prefix", 2 ], # FD
# [ "cp ", 2 ], # FE
# [ "rst 38", 1 ], # FF
#
2015-06-25 02:41:15 +00:00
# Multibyte instructions
0xcb00 : [ 2, "rlc", "b" ],
2015-06-24 02:59:44 +00:00
}
# End of processor specific code
##########################################################################
## Lookup table for multibyte instructions starting with 0xCB
#lookupTableCB = [
# [ "rlc b", 2 ], # 00
# [ "rlc c", 2 ], # 01
# [ "rlc d", 2 ], # 02
# [ "rlc e", 2 ], # 03
# [ "rlc h", 2 ], # 04
# [ "rlc l", 2 ], # 05
# [ "rlc (hl)", 2 ], # 06
# [ "rlc a", 2 ], # 07
# [ "rrc b", 2 ], # 08
# [ "rrc c", 2 ], # 09
# [ "rrc d", 2 ], # 0A
# [ "rrc e", 2 ], # 0B
# [ "rrc h", 2 ], # 0C
# [ "rrc l", 2 ], # 0D
# [ "rrc (hl)", 2 ], # 0E
# [ "rrc a", 2 ], # 0F
#
# [ "rl b", 2 ], # 10
# [ "rl c", 2 ], # 11
# [ "rl d", 2 ], # 12
# [ "rl e", 2 ], # 13
# [ "rl h", 2 ], # 14
# [ "rl l", 2 ], # 15
# [ "rl (hl)", 2 ], # 16
# [ "rl a", 2 ], # 17
# [ "rr b", 2 ], # 18
# [ "rr c", 2 ], # 19
# [ "rr d", 2 ], # 1A
# [ "rr e", 2 ], # 1B
# [ "rr h", 2 ], # 1C
# [ "rr l", 2 ], # 1D
# [ "rr (hl)", 2 ], # 1E
# [ "rr e", 2 ], # 1F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # 2F
#
# [ "", 2 ], # 20
# [ "", 2 ], # 21
# [ "", 2 ], # 22
# [ "", 2 ], # 23
# [ "", 2 ], # 24
# [ "", 2 ], # 25
# [ "", 2 ], # 26
# [ "", 2 ], # 27
# [ "", 2 ], # 28
# [ "", 2 ], # 29
# [ "", 2 ], # 2A
# [ "", 2 ], # 2B
# [ "", 2 ], # 2C
# [ "", 2 ], # 2D
# [ "", 2 ], # 2E
# [ "", 2 ], # FF
#]
#