Implement rest of 1802 CPU.

This commit is contained in:
Jeff Tranter 2020-06-11 18:54:50 -04:00
parent 716da8c5d8
commit 4adcf46f29

247
1802.py
View File

@ -11,6 +11,7 @@
# 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
@ -52,39 +53,39 @@ opcodeTable = {
0x0e : [ 1, "ld 14", "one" ],
0x0f : [ 1, "ld 15", "one" ],
0x10 : [ 1, "inc", "one" ],
0x11 : [ 1, "inc", "one" ],
0x12 : [ 1, "inc", "one" ],
0x13 : [ 1, "inc", "one" ],
0x14 : [ 1, "inc", "one" ],
0x15 : [ 1, "inc", "one" ],
0x16 : [ 1, "inc", "one" ],
0x17 : [ 1, "inc", "one" ],
0x18 : [ 1, "inc", "one" ],
0x19 : [ 1, "inc", "one" ],
0x1a : [ 1, "inc", "one" ],
0x1b : [ 1, "inc", "one" ],
0x1c : [ 1, "inc", "one" ],
0x1d : [ 1, "inc", "one" ],
0x1e : [ 1, "inc", "one" ],
0x1f : [ 1, "inc", "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", "one" ],
0x21 : [ 1, "dec", "one" ],
0x22 : [ 1, "dec", "one" ],
0x23 : [ 1, "dec", "one" ],
0x24 : [ 1, "dec", "one" ],
0x25 : [ 1, "dec", "one" ],
0x26 : [ 1, "dec", "one" ],
0x27 : [ 1, "dec", "one" ],
0x28 : [ 1, "dec", "one" ],
0x29 : [ 1, "dec", "one" ],
0x2a : [ 1, "dec", "one" ],
0x2b : [ 1, "dec", "one" ],
0x2c : [ 1, "dec", "one" ],
0x2d : [ 1, "dec", "one" ],
0x2e : [ 1, "dec", "one" ],
0x2f : [ 1, "dec", "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" ],
@ -104,48 +105,48 @@ opcodeTable = {
0x3e : [ 2, "bn3", "two" ],
0x3f : [ 2, "bn4", "two" ],
0x40 : [ 1, "lda", "one" ],
0x41 : [ 1, "lda", "one" ],
0x42 : [ 1, "lda", "one" ],
0x43 : [ 1, "lda", "one" ],
0x44 : [ 1, "lda", "one" ],
0x45 : [ 1, "lda", "one" ],
0x46 : [ 1, "lda", "one" ],
0x47 : [ 1, "lda", "one" ],
0x48 : [ 1, "lda", "one" ],
0x49 : [ 1, "lda", "one" ],
0x4a : [ 1, "lda", "one" ],
0x4b : [ 1, "lda", "one" ],
0x4c : [ 1, "lda", "one" ],
0x4d : [ 1, "lda", "one" ],
0x4e : [ 1, "lda", "one" ],
0x4f : [ 1, "lda", "one" ],
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", "one" ],
0x51 : [ 1, "str", "one" ],
0x52 : [ 1, "str", "one" ],
0x53 : [ 1, "str", "one" ],
0x54 : [ 1, "str", "one" ],
0x55 : [ 1, "str", "one" ],
0x56 : [ 1, "str", "one" ],
0x57 : [ 1, "str", "one" ],
0x58 : [ 1, "str", "one" ],
0x59 : [ 1, "str", "one" ],
0x5a : [ 1, "str", "one" ],
0x5b : [ 1, "str", "one" ],
0x5c : [ 1, "str", "one" ],
0x5d : [ 1, "str", "one" ],
0x5e : [ 1, "str", "one" ],
0x5f : [ 1, "str", "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" ],
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" ],
@ -172,22 +173,22 @@ opcodeTable = {
0x7e : [ 1, "rshl", "one" ],
0x7f : [ 1, "smbi", "one" ],
0x80 : [ 1, "glo", "one" ],
0x81 : [ 1, "glo", "one" ],
0x82 : [ 1, "glo", "one" ],
0x83 : [ 1, "glo", "one" ],
0x84 : [ 1, "glo", "one" ],
0x85 : [ 1, "glo", "one" ],
0x86 : [ 1, "glo", "one" ],
0x87 : [ 1, "glo", "one" ],
0x88 : [ 1, "glo", "one" ],
0x89 : [ 1, "glo", "one" ],
0x8a : [ 1, "glo", "one" ],
0x8b : [ 1, "glo", "one" ],
0x8c : [ 1, "glo", "one" ],
0x8d : [ 1, "glo", "one" ],
0x8e : [ 1, "glo", "one" ],
0x8f : [ 1, "glo", "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" ],
@ -241,38 +242,38 @@ opcodeTable = {
0xbf : [ 1, "phi 15", "one" ],
0xc0 : [ 3, "lbr", "three" ],
0xc1 : [ 3, "lbq", "one" ],
0xc2 : [ 3, "lbz", "one" ],
0xc3 : [ 3, "lbdf", "one" ],
0xc1 : [ 3, "lbq", "three" ],
0xc2 : [ 3, "lbz", "three" ],
0xc3 : [ 3, "lbdf", "three" ],
0xc4 : [ 1, "nop", "one" ],
0xc5 : [ 3, "lsnq", "one" ],
0xc6 : [ 3, "lsnz", "one" ],
0xc7 : [ 3, "lsnf", "one" ],
0xc8 : [ 3, "lskp", "one" ],
0xc9 : [ 3, "lbnq", "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", "one" ],
0xcd : [ 3, "lsq", "one" ],
0xce : [ 3, "lsz", "one" ],
0xcf : [ 3, "lsdf", "one" ],
0xcc : [ 3, "lsie", "three" ],
0xcd : [ 3, "lsq", "three" ],
0xce : [ 3, "lsz", "three" ],
0xcf : [ 3, "lsdf", "three" ],
0xd0 : [ 1, "sep", "one" ],
0xd1 : [ 1, "sep", "one" ],
0xd2 : [ 1, "sep", "one" ],
0xd3 : [ 1, "sep", "one" ],
0xd4 : [ 1, "sep", "one" ],
0xd5 : [ 1, "sep", "one" ],
0xd6 : [ 1, "sep", "one" ],
0xd7 : [ 1, "sep", "one" ],
0xd8 : [ 1, "sep", "one" ],
0xd9 : [ 1, "sep", "one" ],
0xda : [ 1, "sep", "one" ],
0xdb : [ 1, "sep", "one" ],
0xdc : [ 1, "sep", "one" ],
0xdd : [ 1, "sep", "one" ],
0xde : [ 1, "sep", "one" ],
0xdf : [ 1, "sep", "one" ],
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" ],
@ -292,7 +293,7 @@ opcodeTable = {
0xef : [ 1, "sex 15", "one" ],
0xf0 : [ 1, "ldx", "one" ],
0xf1 : [ 1, "oe", "one" ],
0xf1 : [ 1, "or", "one" ],
0xf2 : [ 1, "and", "one" ],
0xf3 : [ 1, "xor", "one" ],
0xf4 : [ 1, "add", "one" ],
@ -300,13 +301,13 @@ opcodeTable = {
0xf6 : [ 1, "shr", "one" ],
0xf7 : [ 1, "sm", "one" ],
0xf8 : [ 2, "ldi", "two" ],
0xf9 : [ 1, "ori", "one" ],
0xfa : [ 1, "ani", "one" ],
0xfb : [ 1, "xri", "one" ],
0xfc : [ 1, "adi", "one" ],
0xfd : [ 1, "sdi", "one" ],
0xfe : [ 1, "shl", "one" ],
0xff : [ 1, "smi", "one" ],
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" ],
}