udis/1802.py

316 lines
11 KiB
Python

#########################################################################
#
# Processor specific code
# CPU = "1802"
# Description = "RCA 1802 COSMAC 8-bit microprocessor."
# DataWidth = 8 # 8-bit data
# AddressWidth = 16 # 16-bit addresses
#
# See:
# https://en.wikipedia.org/wiki/RCA_1802
# https://www.atarimagazines.com/computeii/issue3/page52.php
# http://www.massmind.org/techref/1802/index.htm
# https://www.bgmicro.com/pdf/elf%20manual.pdf
# Maximum length of an instruction (for formatting purposes)
maxLength = 3
# Leadin bytes for multibyte instructions
leadInBytes = []
# Addressing mode table
# List of addressing modes and corresponding format strings for operands.
addressModeTable = {
"one" : "",
"two" : "${0:02X}",
"three" : "${0:02X}{1:02X}",
}
# 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, "idl", "one" ],
0x01 : [ 1, "ld 1", "one" ],
0x02 : [ 1, "ld 2", "one" ],
0x03 : [ 1, "ld 3", "one" ],
0x04 : [ 1, "ld 4", "one" ],
0x05 : [ 1, "ld 5", "one" ],
0x06 : [ 1, "ld 6", "one" ],
0x07 : [ 1, "ld 7", "one" ],
0x08 : [ 1, "ld 8", "one" ],
0x09 : [ 1, "ld 9", "one" ],
0x0a : [ 1, "ld 10", "one" ],
0x0b : [ 1, "ld 11", "one" ],
0x0c : [ 1, "ld 12", "one" ],
0x0d : [ 1, "ld 13", "one" ],
0x0e : [ 1, "ld 14", "one" ],
0x0f : [ 1, "ld 15", "one" ],
0x10 : [ 1, "inc 0", "one" ],
0x11 : [ 1, "inc 1", "one" ],
0x12 : [ 1, "inc 2", "one" ],
0x13 : [ 1, "inc 3", "one" ],
0x14 : [ 1, "inc 4", "one" ],
0x15 : [ 1, "inc 5", "one" ],
0x16 : [ 1, "inc 6", "one" ],
0x17 : [ 1, "inc 7", "one" ],
0x18 : [ 1, "inc 8", "one" ],
0x19 : [ 1, "inc 9", "one" ],
0x1a : [ 1, "inc 10", "one" ],
0x1b : [ 1, "inc 11", "one" ],
0x1c : [ 1, "inc 12", "one" ],
0x1d : [ 1, "inc 13", "one" ],
0x1e : [ 1, "inc 14", "one" ],
0x1f : [ 1, "inc 15", "one" ],
0x20 : [ 1, "dec 0", "one" ],
0x21 : [ 1, "dec 1", "one" ],
0x22 : [ 1, "dec 2", "one" ],
0x23 : [ 1, "dec 3", "one" ],
0x24 : [ 1, "dec 4", "one" ],
0x25 : [ 1, "dec 5", "one" ],
0x26 : [ 1, "dec 6", "one" ],
0x27 : [ 1, "dec 7", "one" ],
0x28 : [ 1, "dec 8", "one" ],
0x29 : [ 1, "dec 9", "one" ],
0x2a : [ 1, "dec 10", "one" ],
0x2b : [ 1, "dec 11", "one" ],
0x2c : [ 1, "dec 12", "one" ],
0x2d : [ 1, "dec 13", "one" ],
0x2e : [ 1, "dec 14", "one" ],
0x2f : [ 1, "dec 15", "one" ],
0x30 : [ 2, "br", "two" ],
0x31 : [ 2, "bq", "two" ],
0x32 : [ 2, "bz", "two" ],
0x33 : [ 2, "bdf", "two" ],
0x34 : [ 2, "b1", "two" ],
0x35 : [ 2, "b2", "two" ],
0x36 : [ 2, "b3", "two" ],
0x37 : [ 2, "b4", "two" ],
0x38 : [ 2, "nbr", "two" ],
#0x38: [ 2, "skp", "two" ], Alternate mnemonic for above
0x39 : [ 2, "bnq", "two" ],
0x3a : [ 2, "bnz", "two" ],
0x3b : [ 2, "bnf", "two" ],
0x3c : [ 2, "bn1", "two" ],
0x3d : [ 2, "bn2", "two" ],
0x3e : [ 2, "bn3", "two" ],
0x3f : [ 2, "bn4", "two" ],
0x40 : [ 1, "lda 0", "one" ],
0x41 : [ 1, "lda 1", "one" ],
0x42 : [ 1, "lda 2", "one" ],
0x43 : [ 1, "lda 3", "one" ],
0x44 : [ 1, "lda 4", "one" ],
0x45 : [ 1, "lda 5", "one" ],
0x46 : [ 1, "lda 6", "one" ],
0x47 : [ 1, "lda 7", "one" ],
0x48 : [ 1, "lda 8", "one" ],
0x49 : [ 1, "lda 9", "one" ],
0x4a : [ 1, "lda 10", "one" ],
0x4b : [ 1, "lda 11", "one" ],
0x4c : [ 1, "lda 12", "one" ],
0x4d : [ 1, "lda 13", "one" ],
0x4e : [ 1, "lda 14", "one" ],
0x4f : [ 1, "lda 15", "one" ],
0x50 : [ 1, "str 0", "one" ],
0x51 : [ 1, "str 1", "one" ],
0x52 : [ 1, "str 2", "one" ],
0x53 : [ 1, "str 3", "one" ],
0x54 : [ 1, "str 4", "one" ],
0x55 : [ 1, "str 5", "one" ],
0x56 : [ 1, "str 6", "one" ],
0x57 : [ 1, "str 7", "one" ],
0x58 : [ 1, "str 8", "one" ],
0x59 : [ 1, "str 9", "one" ],
0x5a : [ 1, "str 10", "one" ],
0x5b : [ 1, "str 11", "one" ],
0x5c : [ 1, "str 12", "one" ],
0x5d : [ 1, "str 13", "one" ],
0x5e : [ 1, "str 14", "one" ],
0x5f : [ 1, "str 15", "one" ],
0x60 : [ 1, "irx", "one" ],
0x61 : [ 1, "out 1", "one" ],
0x62 : [ 1, "out 2", "one" ],
0x63 : [ 1, "out 3", "one" ],
0x64 : [ 2, "out 4", "two" ],
0x65 : [ 1, "out 5", "one" ],
0x66 : [ 1, "out 6", "one" ],
0x67 : [ 1, "out 7", "one" ],
0x69 : [ 1, "inp 1", "one" ],
0x6a : [ 1, "inp 2", "one" ],
0x6b : [ 1, "inp 3", "one" ],
0x6c : [ 1, "inp 4", "one" ],
0x6d : [ 1, "inp 5", "one" ],
0x6e : [ 1, "inp 6", "one" ],
0x6f : [ 1, "inp 7", "one" ],
0x70 : [ 1, "ret", "one" ],
0x71 : [ 1, "dis", "one" ],
0x72 : [ 1, "ldxa", "one" ],
0x73 : [ 1, "stxd", "one" ],
0x74 : [ 1, "adc", "one" ],
0x75 : [ 1, "sdb", "one" ],
0x76 : [ 1, "rshr", "one" ],
0x77 : [ 1, "smb", "one" ],
0x78 : [ 1, "sav", "one" ],
0x79 : [ 1, "mark", "one" ],
0x7a : [ 1, "req", "one" ],
0x7b : [ 1, "seq", "one" ],
0x7c : [ 1, "adci", "one" ],
0x7d : [ 1, "sdbi", "one" ],
0x7e : [ 1, "rshl", "one" ],
0x7f : [ 1, "smbi", "one" ],
0x80 : [ 1, "glo 0", "one" ],
0x81 : [ 1, "glo 1", "one" ],
0x82 : [ 1, "glo 2", "one" ],
0x83 : [ 1, "glo 3", "one" ],
0x84 : [ 1, "glo 4", "one" ],
0x85 : [ 1, "glo 5", "one" ],
0x86 : [ 1, "glo 6", "one" ],
0x87 : [ 1, "glo 7", "one" ],
0x88 : [ 1, "glo 8", "one" ],
0x89 : [ 1, "glo 9", "one" ],
0x8a : [ 1, "glo 10", "one" ],
0x8b : [ 1, "glo 11", "one" ],
0x8c : [ 1, "glo 12", "one" ],
0x8d : [ 1, "glo 13", "one" ],
0x8e : [ 1, "glo 14", "one" ],
0x8f : [ 1, "glo 15", "one" ],
0x90 : [ 1, "ghi 0", "one" ],
0x91 : [ 1, "ghi 1", "one" ],
0x92 : [ 1, "ghi 2", "one" ],
0x93 : [ 1, "ghi 3", "one" ],
0x94 : [ 1, "ghi 4", "one" ],
0x95 : [ 1, "ghi 5", "one" ],
0x96 : [ 1, "ghi 6", "one" ],
0x97 : [ 1, "ghi 7", "one" ],
0x98 : [ 1, "ghi 8", "one" ],
0x99 : [ 1, "ghi 9", "one" ],
0x9a : [ 1, "ghi 10", "one" ],
0x9b : [ 1, "ghi 11", "one" ],
0x9c : [ 1, "ghi 12", "one" ],
0x9d : [ 1, "ghi 13", "one" ],
0x9e : [ 1, "ghi 14", "one" ],
0x9f : [ 1, "ghi 15", "one" ],
0xa0 : [ 1, "plo 0", "one" ],
0xa1 : [ 1, "plo 1", "one" ],
0xa2 : [ 1, "plo 2", "one" ],
0xa3 : [ 1, "plo 3", "one" ],
0xa4 : [ 1, "plo 4", "one" ],
0xa5 : [ 1, "plo 5", "one" ],
0xa6 : [ 1, "plo 6", "one" ],
0xa7 : [ 1, "plo 7", "one" ],
0xa8 : [ 1, "plo 8", "one" ],
0xa9 : [ 1, "plo 9", "one" ],
0xaa : [ 1, "plo 10", "one" ],
0xab : [ 1, "plo 11", "one" ],
0xac : [ 1, "plo 12", "one" ],
0xad : [ 1, "plo 13", "one" ],
0xae : [ 1, "plo 14", "one" ],
0xaf : [ 1, "plo 15", "one" ],
0xb0 : [ 1, "phi 0", "one" ],
0xb1 : [ 1, "phi 1", "one" ],
0xb2 : [ 1, "phi 2", "one" ],
0xb3 : [ 1, "phi 3", "one" ],
0xb4 : [ 1, "phi 4", "one" ],
0xb5 : [ 1, "phi 5", "one" ],
0xb6 : [ 1, "phi 6", "one" ],
0xb7 : [ 1, "phi 7", "one" ],
0xb8 : [ 1, "phi 8", "one" ],
0xb9 : [ 1, "phi 9", "one" ],
0xba : [ 1, "phi 10", "one" ],
0xbb : [ 1, "phi 11", "one" ],
0xbc : [ 1, "phi 12", "one" ],
0xbd : [ 1, "phi 13", "one" ],
0xbe : [ 1, "phi 14", "one" ],
0xbf : [ 1, "phi 15", "one" ],
0xc0 : [ 3, "lbr", "three" ],
0xc1 : [ 3, "lbq", "three" ],
0xc2 : [ 3, "lbz", "three" ],
0xc3 : [ 3, "lbdf", "three" ],
0xc4 : [ 1, "nop", "one" ],
0xc5 : [ 3, "lsnq", "three" ],
0xc6 : [ 3, "lsnz", "three" ],
0xc7 : [ 3, "lsnf", "three" ],
0xc8 : [ 3, "lskp", "three" ],
0xc9 : [ 3, "lbnq", "three" ],
0xca : [ 3, "lbnz", "three" ],
0xcb : [ 3, "lbnf", "three" ],
0xcc : [ 3, "lsie", "three" ],
0xcd : [ 3, "lsq", "three" ],
0xce : [ 3, "lsz", "three" ],
0xcf : [ 3, "lsdf", "three" ],
0xd0 : [ 1, "sep 0", "one" ],
0xd1 : [ 1, "sep 1", "one" ],
0xd2 : [ 1, "sep 2", "one" ],
0xd3 : [ 1, "sep 3", "one" ],
0xd4 : [ 1, "sep 4", "one" ],
0xd5 : [ 1, "sep 5", "one" ],
0xd6 : [ 1, "sep 6", "one" ],
0xd7 : [ 1, "sep 7", "one" ],
0xd8 : [ 1, "sep 8", "one" ],
0xd9 : [ 1, "sep 9", "one" ],
0xda : [ 1, "sep 10", "one" ],
0xdb : [ 1, "sep 11", "one" ],
0xdc : [ 1, "sep 12", "one" ],
0xdd : [ 1, "sep 13", "one" ],
0xde : [ 1, "sep 14", "one" ],
0xdf : [ 1, "sep 15", "one" ],
0xe0 : [ 1, "sex 0", "one" ],
0xe1 : [ 1, "sex 1", "one" ],
0xe2 : [ 1, "sex 2", "one" ],
0xe3 : [ 1, "sex 3", "one" ],
0xe4 : [ 1, "sex 4", "one" ],
0xe5 : [ 1, "sex 5", "one" ],
0xe6 : [ 1, "sex 6", "one" ],
0xe7 : [ 1, "sex 7", "one" ],
0xe8 : [ 1, "sex 8", "one" ],
0xe9 : [ 1, "sex 9", "one" ],
0xea : [ 1, "sex 10", "one" ],
0xeb : [ 1, "sex 11", "one" ],
0xec : [ 1, "sex 12", "one" ],
0xed : [ 1, "sex 13", "one" ],
0xee : [ 1, "sex 14", "one" ],
0xef : [ 1, "sex 15", "one" ],
0xf0 : [ 1, "ldx", "one" ],
0xf1 : [ 1, "or", "one" ],
0xf2 : [ 1, "and", "one" ],
0xf3 : [ 1, "xor", "one" ],
0xf4 : [ 1, "add", "one" ],
0xf5 : [ 1, "sd", "one" ],
0xf6 : [ 1, "shr", "one" ],
0xf7 : [ 1, "sm", "one" ],
0xf8 : [ 2, "ldi", "two" ],
0xf9 : [ 2, "ori", "two" ],
0xfa : [ 2, "ani", "two" ],
0xfb : [ 2, "xri", "two" ],
0xfc : [ 2, "adi", "two" ],
0xfd : [ 2, "sdi", "two" ],
0xfe : [ 2, "shl", "two" ],
0xff : [ 2, "smi", "two" ],
}
# End of processor specific code
##########################################################################