cj68_opcodes.html
001| '''OP CODE DEFINITION LIST.
001|
001| Fields: byte-value, name, length, implemented/tested, payload descr, operation descr.
001|
001| Overview:
001| PGM 0x00 (10) 05-0e
001| CMP/JMP 0x10 (2) 16, 17
001| JUMP[A|V] 0x20 (0)
001| JUMP[T|R] 0x30 (0)
001| CALL/STAK 0x40 (0)
001| LOAD 0x50 (3) 5c-5e
001| SAVE 0x60 (4) 6c-6e
001| IO 0x70 (3) 74, 7e, 7f
001| COPY 0x80 (11) 82, 83, 87-8f
001| MATH1/SHIFT 0x90 (0)
001| MATH2 0xa0 (0)
001| LOGIC 0xb0 (4) b3, b7, bb, bf
001| - 0xc0 (16) c0-cf
001| - 0xd0 (16) d0-df
001| SYSTEM 0xe0 (0)
001| INTS 0xf0 (0)
001|
001| Notes:
001| reg - value in register
001| [reg] - value register points to
001| a0.a1.a2.a3 - value IS a0.a1.a2.a3
001| [a0.a1.a2.a3] - value IN a0.a1.a2.a3
001| [[a0.a1.a2.a3]] - value a0.a1.a2.a3 points to
001| b0.b1.b2.b3 - value is literal bytes
001| num - a byte value
001| number - a word value
001|
001| I=immediate, A=address, V=vector, T=table, VT=vector-table, TV=table-vector,
001| R=register, RV=register-vector, RT=register-table, RVT=register-vector-table
001|
001| Jump instructions: NEG=LT, ELT, Z=EQ, NZ=NE, EGT, POS=GT, OV
001|
001| LOADSI and SAVEDI handle word values; they assume valid SI or DI, which they increment by 4.
001| LOADB and SAVEB handle byte values; they assume valid SI or DI, which they increment by 1.
001|
001| MUL* and DIV* instructions require an even-numbered register and use
001| the next next register (numerically) for result. MUL puts high word
001| in second register, DIV puts the remainder in it.
001|
001| Functions:
001| list_opcodes (sout, space) - list op codes to screen or file
001| do_opcodes_check (**kwargs) - check cj68 methods against opcodes
001| do_opcodes_list (**kwargs) - list the op codes to text file
001| do_opcodes_webpage (**kwargs) - generate an op codes HTML page
001|
001| '''
002|
003| from sys import stdin, stdout, stderr
004| from os import path
005| from logger import logger
006| from goodies import KWARG
007| from files import SPC,EOL,linefile
008| from webpage import WebPage
009|
010| BasePath = r'C:\CJS\prj\Python\app\sims\cj68'
011| DocsPath = path.join(BasePath, 'doc')
012| Log = logger('cj68opc')
013|
014| OpCodes:tuple[tuple] = (
015| (0x00, 'NOP' ,1,2, '' , 'No operation.' ),
016| (0x01, 'PGM' ,3,2, 'id ver' , 'Program header.' ),
017| (0x02, 'DAT' ,0,2, 'len b1...blen' , 'Instream program data.' ),
018| (0x03, 'TAG' ,0,2, 'b1...blen' , 'Tag marker.' ),
019| (0x04, 'EOT' ,1,2, '' , 'End of text marker.' ),
020|
021| (0x0f, 'RANDOM' ,2,2, 'reg' , 'Put a random integer in reg.' ),
022|
023| (0x10, 'TEST' ,2,2, 'reg' , 'Test reg value to set flags.' ),
024| (0x11, 'CMPI' ,6,2, 'reg number' , 'Compare reg to n0,n1,n2,n3; set flags.' ),
025| (0x12, 'CMPA' ,6,2, 'reg address' , 'Compare reg to [a0,a1,a2,a3];set flags.' ),
026| (0x13, 'CMPV' ,6,2, 'reg address' , 'Compare reg to [[a0,a1,a2,a3]]; set flags.' ),
027| (0x14, 'CMPT' ,7,2, 'reg1 reg2 address' , 'Compare reg1 to [a0,a1,a2,a3+reg2];set flags.'),
028| (0x15, 'CMPR' ,3,2, 'reg1 reg2' , 'Compare reg1 to reg2; set flags.' ),
029|
030| (0x18, 'JMP' ,2,2, 'num' , 'Relative jump (by num).' ),
031| (0x19, 'JMPZ' ,2,2, 'num' , 'Relative jump (by num) if ZF.' ),
032| (0x19, 'JMPEQ' ,2,2, 'num' , 'Relative jump (by num) if ZF.' ),
033| (0x1a, 'JMPNZ' ,2,2, 'num' , 'Relative jump (by num) if not ZF.' ),
034| (0x1a, 'JMPNE' ,2,2, 'num' , 'Relative jump (by num) if not ZF.' ),
035| (0x1b, 'JMPELT' ,2,2, 'num' , 'Relative jump (by num) if NEG or ZF.' ),
036| (0x1c, 'JMPNEG' ,2,2, 'num' , 'Relative jump (by num) if NEG.' ),
037| (0x1c, 'JMPLT' ,2,2, 'num' , 'Relative jump (by num) if NEG.' ),
038| (0x1d, 'JMPPOS' ,2,2, 'num' , 'Relative jump (by num) if not (NEG or ZF).' ),
039| (0x1d, 'JMPGT' ,2,2, 'num' , 'Relative jump (by num) if not (NEG or ZF).' ),
040| (0x1e, 'JMPEGT' ,2,2, 'num' , 'Relative jump (by num) if ZF and not NEG.' ),
041| (0x1f, 'JMPOV' ,2,2, 'num' , 'Relative jump (by num) if OVF.' ),
042|
043| (0x20, 'JUMP' ,5,2, 'address' , 'Jump to a0.a1.a2.a3.' ),
044| (0x21, 'JZ' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if ZF.' ),
045| (0x21, 'JEQ' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if ZF.' ),
046| (0x22, 'JNZ' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if not ZF.' ),
047| (0x22, 'JNE' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if not ZF.' ),
048| (0x23, 'JELT' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if NEG or ZF.' ),
049| (0x24, 'JNEG' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if NEG.' ),
050| (0x24, 'JLT' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if NEG.' ),
051| (0x25, 'JPOS' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if not (NEG or ZF).' ),
052| (0x25, 'JGT' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if not (NEG or ZF).' ),
053| (0x26, 'JEGT' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if ZF and not NEG .' ),
054| (0x27, 'JOV' ,5,2, 'address' , 'Jump to a0.a1.a2.a3 if OVF.' ),
055|
056| (0x28, 'JVEC' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3].' ),
057| (0x29, 'JZV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if ZF.' ),
058| (0x29, 'JEQV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if ZF.' ),
059| (0x2a, 'JNZV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if not ZF.' ),
060| (0x2a, 'JNEV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if not ZF.' ),
061| (0x2b, 'JELTV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if NEG or ZF.' ),
062| (0x2c, 'JNEGV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if NEG.' ),
063| (0x2c, 'JLTV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if NEG.' ),
064| (0x2d, 'JPOSV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if not (NEG or ZF).' ),
065| (0x2d, 'JGTV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if not (NEG or ZF).' ),
066| (0x2e, 'JEGTV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if ZF and not NEG.' ),
067| (0x2f, 'JOVV' ,5,2, 'address' , 'Jump to [a0.a1.a2.a3] if OVF.' ),
068|
069| (0x30, 'JREG' ,2,2, 'reg' , 'Jump to [reg].' ),
070| (0x31, 'JZR' ,2,2, 'reg' , 'Jump to [reg] if ZF.' ),
071| (0x31, 'JEQR' ,2,2, 'reg' , 'Jump to [reg] if ZF.' ),
072| (0x32, 'JNZR' ,2,2, 'reg' , 'Jump to [reg] if not ZF.' ),
073| (0x32, 'JNER' ,2,2, 'reg' , 'Jump to [reg] if not ZF.' ),
074| (0x33, 'JELTR' ,2,2, 'reg' , 'Jump to [reg] if NEG or ZF.' ),
075| (0x34, 'JNEGR' ,2,2, 'reg' , 'Jump to [reg] if NEG.' ),
076| (0x34, 'JLTR' ,2,2, 'reg' , 'Jump to [reg] if NEG.' ),
077| (0x35, 'JPOSR' ,2,2, 'reg' , 'Jump to [reg] if not (NEG or ZF).' ),
078| (0x35, 'JGTR' ,2,2, 'reg' , 'Jump to [reg] if not (NEG or ZF).' ),
079| (0x36, 'JEGTR' ,2,2, 'reg' , 'Jump to [reg] if ZF and not NEG.' ),
080| (0x37, 'JOVR' ,2,2, 'reg' , 'Jump to [reg] if OVF.' ),
081|
082| (0x38, 'JTAB' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2].' ),
083| (0x39, 'JZT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if ZF.' ),
084| (0x39, 'JEQT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if ZF.' ),
085| (0x3a, 'JNZT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if not ZF.' ),
086| (0x3a, 'JNET' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if not ZF.' ),
087| (0x3b, 'JELTT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if NEG or ZF.' ),
088| (0x3c, 'JNEGT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if NEG.' ),
089| (0x3c, 'JLTT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if NEG.' ),
090| (0x3d, 'JPOST' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if not (NEG or ZF).' ),
091| (0x3d, 'JGTT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if not (NEG or ZF).' ),
092| (0x3e, 'JEGTT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if ZF and not NEG.' ),
093| (0x3f, 'JOVT' ,3,2, 'reg1 reg2' , 'Jump to [reg1+reg2] if OVF.' ),
094|
095| (0x40, 'CALL' ,5,2, 'address' , 'Call a0.a1.a2.a3.' ),
096| (0x41, 'CVEC' ,5,2, 'address' , 'Call [a0.a1.a2.a3].' ),
097| (0x42, 'CREG' ,2,2, 'reg' , 'Call reg.' ),
098| (0x43, 'CTAB' ,3,2, 'reg1 reg2' , 'Call [reg1] offset by reg2.' ),
099| (0x44, 'RET' ,1,2, '' , 'Return from a subroutine.' ),
100| (0x45, 'RETINT' ,1,2, '' , 'Return from an interrupt.' ),
101| (0x46, 'SPBPI' ,2,2, 'num' , 'Copy SP+num to BP.' ),
102| (0x47, 'SPBPR' ,2,2, 'reg' , 'Copy SP+reg to BP.' ),
103| (0x48, 'PUSH' ,2,2, 'reg' , 'Push all registers to stack.' ),
104| (0x49, 'POP' ,2,2, 'reg' , 'Pop all registers from stack.' ),
105| (0x4a, 'PUSHSUB' ,1,2, '' , 'Push BP, SI, DI to stack.' ),
106| (0x4b, 'POPSUB' ,1,2, '' , 'Pop BP, SI, DI from stack.' ),
107| (0x4c, 'PUSHALL' ,1,2, '' , 'Push all registers to stack.' ),
108| (0x4d, 'POPALL' ,1,2, '' , 'Pop all registers from stack.' ),
109| (0x4e, 'SETBPR' ,2,2, 'reg' , 'Load BP with reg.' ),
110| (0x4f, 'SETBPI' ,5,2, 'number' , 'Load BP with n0,n1,n2,n3.' ),
111|
112| (0x50, 'LOADA' ,6,2, 'reg address' , 'Load reg with [a0.a1.a2.a3].' ),
113| (0x51, 'LOADV' ,6,2, 'reg address' , 'Load reg with [[a0.a1.a2.a3]].' ),
114| (0x52, 'LOADT' ,7,2, 'reg1 reg2 address' , 'Load reg1 with [a0.a1.a2.a3+reg2].' ),
115| (0x53, 'LOADVT' ,7,2, 'reg1 reg2 address' , 'Load reg1 with [[a0.a1.a2.a3]+reg2].' ),
116| (0x54, 'LOADTV' ,7,2, 'reg1 reg2 address' , 'Load reg1 with [[a0.a1.a2.a3+reg2]].' ),
117| (0x55, 'LOADR' ,3,2, 'reg1 reg2' , 'Load reg1 with [reg2].' ),
118| (0x56, 'LOADRV' ,3,2, 'reg1 reg2' , 'Load reg1 with [[reg2]].' ),
119| (0x57, 'LOADRT' ,4,2, 'reg1 reg2 reg3' , 'Load reg1 with [reg2+reg3].' ),
120| (0x58, 'LOADB' ,3,2, 'reg1 reg2' , 'Load reg1 with byte [reg2].' ),
121| (0x59, 'LOADBT' ,4,2, 'reg1 reg2 reg3' , 'Load reg1 with byte [re2+reg3].' ),
122| (0x5a, 'LOADW' ,2,2, 'reg' , 'Load reg with [SI] (incr SI).' ),
123| (0x5b, 'LOADSF' ,3,2, 'reg num' , 'Load reg with [BP+num].' ),
124| (0x5f, 'LOADI' ,6,2, 'reg number' , 'Load reg with n0.n1.n2.n3.' ),
125|
126| (0x60, 'SAVEA' ,6,2, 'reg address' , 'Save reg to [a0.a1.a2.a3].' ),
127| (0x61, 'SAVEV' ,6,2, 'reg address' , 'Save reg to [[a0.a1.a2.a3]].' ),
128| (0x62, 'SAVET' ,7,2, 'reg1 reg2 address' , 'Save reg1 to [a0.a1.a2.a3+reg2].' ),
129| (0x63, 'SAVEVT' ,7,2, 'reg1 reg2 address' , 'Save reg1 to [[a0.a1.a2.a3]+reg2].' ),
130| (0x64, 'SAVETV' ,7,2, 'reg1 reg2 address' , 'Save reg1 to [[a0.a1.a2.a3+reg2]].' ),
131| (0x65, 'SAVER' ,3,2, 'reg1 reg2' , 'Save reg1 to [reg2].' ),
132| (0x66, 'SAVERV' ,3,2, 'reg1 reg2' , 'Save reg1 to [[reg2]].' ),
133| (0x67, 'SAVERT' ,4,2, 'reg1 reg2 reg3' , 'Save reg1 to [reg2+reg3].' ),
134| (0x68, 'SAVEB' ,3,2, 'reg1 reg2' , 'Save reg1 byte to [reg2].' ),
135| (0x69, 'SAVEBT' ,4,2, 'reg1 reg2 reg3' , 'Save reg1 byte to [reg2+reg3].' ),
136| (0x6a, 'SAVEW' ,2,2, 'reg' , 'Save reg to [DI] (incr DI).' ),
137| (0x6b, 'SAVESF' ,3,2, 'reg num' , 'Save reg to [BP+num].' ),
138| (0x6f, 'DUPE' ,3,2, 'reg1 reg2' , 'Copy reg2 to reg1.' ),
139|
140| (0x70, 'GETB' ,3,2, 'chn reg' , 'Get byte from chnl to reg.' ),
141| (0x71, 'GETA' ,7,2, 'chn num address' , 'Get num bytes from chn to a0.a1.a2.a3.' ),
142| (0x72, 'GETV' ,7,2, 'chn num address' , 'Get num bytes from chn to [a0.a1.a2.a3].' ),
143| (0x73, 'GETR' ,4,2, 'chn num reg' , 'Get num bytes from chn to [reg].' ),
144|
145| (0x75, 'CHNRTR' ,2,2, 'chn' , 'Channel Ready-to-Read flag sets ZERO flag.' ),
146| (0x76, 'CHNRTW' ,2,2, 'chn' , 'Channel Ready-to-Write flag sets ZERO flag.' ),
147| (0x77, 'CHNSTAT' ,3,2, 'chn reg' , 'Load channel status into reg.' ),
148|
149| (0x78, 'PUTB' ,3,2, 'chn reg' , 'Put byte from reg to chn.' ),
150| (0x79, 'PUTA' ,7,2, 'chn num address' , 'Put num bytes from a0.a1.a2.a3 to chn.' ),
151| (0x7a, 'PUTV' ,7,2, 'chn num address' , 'Put num bytes from [a0.a1.a2.a3] to chn.' ),
152| (0x7b, 'PUTR' ,4,2, 'chn num reg' , 'Put byte from [reg] to chn.' ),
153| (0x7c, 'PUTI' ,3,2, 'chn num' , 'Put immediate byte to chn.' ),
154| (0x7d, 'PUTM' ,0,2, 'chn len b1...blen' , 'Put bytes b1 ... blen to chn.' ),
155|
156| (0x80, 'COPY' ,2,2, 'reg' , 'Copy reg bytes from [SI] to [DI].' ),
157| (0x81, 'FILL' ,3,2, 'reg1 reg2' , 'Fill reg1 bytes at [DI] with reg2.' ),
158|
159| (0x84, 'MEMAND' ,3,2, 'reg1 reg2' , 'AND reg1 bytes at [DI] with reg2.' ),
160| (0x85, 'MEMOR' ,3,2, 'reg1 reg2' , 'OR reg1 bytes at [DI] with reg2.' ),
161| (0x86, 'MEMXOR' ,3,2, 'reg1 reg2' , 'XOR reg1 bytes at [DI] with reg2.' ),
162|
163| (0x90, 'NEG' ,2,2, 'reg' , 'Set reg to its negative value.' ),
164| (0x91, 'ABS' ,2,2, 'reg' , 'Set reg to its absolute value.' ),
165| (0x92, 'INV' ,2,2, 'reg' , 'Set reg to its bitwise invert.' ),
166| (0x93, 'REV' ,2,2, 'reg' , 'Set reg to its bitwise reverse.' ),
167|
168| (0x94, 'INCR' ,2,2, 'reg' , 'Increment reg.' ),
169| (0x95, 'DECR' ,2,2, 'reg' , 'Decrement reg.' ),
170| (0x96, 'INCRW' ,2,2, 'reg' , 'Increment reg by 4 (one word).' ),
171| (0x97, 'DECRW' ,2,2, 'reg' , 'Decrement reg by 4 (one word).' ),
172|
173| (0x98, 'ISHL' ,3,2, 'reg num' , 'Shift left reg1 by num.' ),
174| (0x99, 'ISHR' ,3,2, 'reg num' , 'Shift right reg1 by num.' ),
175| (0x9a, 'IROL' ,3,2, 'reg num' , 'Rotate left reg1 by num.' ),
176| (0x9b, 'IROR' ,3,2, 'reg num' , 'Rotate right reg1 by num.' ),
177|
178| (0x9c, 'RSHL' ,3,2, 'reg1 reg2' , 'Shift left reg1 by reg2.' ),
179| (0x9d, 'RSHR' ,3,2, 'reg1 reg2' , 'Shift right reg1 by reg2.' ),
180| (0x9e, 'RROL' ,3,2, 'reg1 reg2' , 'Rotate left reg1 by reg2.' ),
181| (0x9f, 'RROR' ,3,2, 'reg1 reg2' , 'Rotate right reg1 by reg2.' ),
182|
183| (0xa0, 'IADD' ,6,2, 'reg number' , 'Add n0.n1.n2.n3 to reg.' ),
184| (0xa1, 'ISUB' ,6,2, 'reg number' , 'Subtract n0.n1.n2.n3 from reg.' ),
185| (0xa2, 'IMUL' ,6,2, 'reg number' , 'Multiply reg by n0.n1.n2.n3.' ),
186| (0xa3, 'IDIV' ,6,2, 'reg number' , 'Divide reg by n0.n1.n2.n3.' ),
187|
188| (0xa4, 'AADD' ,6,2, 'reg address' , 'Add [a0.a1.a2.a3] to reg.' ),
189| (0xa5, 'ASUB' ,6,2, 'reg address' , 'Subtract [a0.a1.a2.a3] from reg.' ),
190| (0xa6, 'AMUL' ,6,2, 'reg address' , 'Multiply reg by [a0.a1.a2.a3].' ),
191| (0xa7, 'ADIV' ,6,2, 'reg address' , 'Divide reg by [a0.a1.a2.a3].' ),
192|
193| (0xa8, 'VADD' ,6,2, 'reg address' , 'Add [[a0.a1.a2.a3]] to reg.' ),
194| (0xa9, 'VSUB' ,6,2, 'reg address' , 'Subtract [[a0.a1.a2.a3]] from reg.' ),
195| (0xaa, 'VMUL' ,6,2, 'reg address' , 'Multiply reg by [[a0.a1.a2.a3]].' ),
196| (0xab, 'VDIV' ,6,2, 'reg address' , 'Divide reg by [[a0.a1.a2.a3]].' ),
197|
198| (0xac, 'RADD' ,3,2, 'reg1 reg2' , 'Add reg2 to reg1.' ),
199| (0xad, 'RSUB' ,3,2, 'reg1 reg2' , 'Subtract reg2 from reg1.' ),
200| (0xae, 'RMUL' ,3,2, 'reg1 reg2' , 'Multiply reg1 by reg2.' ),
201| (0xaf, 'RDIV' ,3,2, 'reg1 reg2' , 'Divide reg1 by reg2.' ),
202|
203| (0xb0, 'IAND' ,6,2, 'reg number' , 'AND reg1 with n0.n1.n2.n3.' ),
204| (0xb1, 'IOR' ,6,2, 'reg number' , 'OR reg1 with n0.n1.n2.n3.' ),
205| (0xb2, 'IXOR' ,6,2, 'reg number' , 'XOR reg1 with n0.n1.n2.n3.' ),
206|
207| (0xb4, 'AAND' ,6,2, 'reg address' , 'AND reg1 with [a0.a1.a2.a3].' ),
208| (0xb5, 'AOR' ,6,2, 'reg address' , 'OR reg1 with [a0.a1.a2.a3].' ),
209| (0xb6, 'AXOR' ,6,2, 'reg address' , 'XOR reg1 with [a0.a1.a2.a3].' ),
210|
211| (0xb8, 'VAND' ,6,2, 'reg address' , 'AND reg1 with [[a0.a1.a2.a3]].' ),
212| (0xb9, 'VOR' ,6,2, 'reg address' , 'OR reg1 with [[a0.a1.a2.a3]].' ),
213| (0xba, 'VXOR' ,6,2, 'reg address' , 'XOR reg1 with [[a0.a1.a2.a3]].' ),
214|
215| (0xbc, 'RAND' ,3,2, 'reg1 reg2' , 'AND reg1 with reg2.' ),
216| (0xbd, 'ROR' ,3,2, 'reg1 reg2' , 'OR reg1 with reg2.' ),
217| (0xbe, 'RXOR' ,3,2, 'reg1 reg2' , 'XOR reg1 with reg2.' ),
218|
219| (0xe0, 'SETFLGS' ,1,2, '' , 'Set all math flags (Z, OF, NEG).' ),
220| (0xe1, 'CLRFLGS' ,1,2, '' , 'Clear all math flags.' ),
221| (0xe2, 'GETFLGS' ,2,2, 'reg' , 'Load all flags into reg.' ),
222| (0xe3, 'GETIP' ,2,2, 'reg' , 'Load instruction pointer into reg.' ),
223| (0xe4, 'GETSP' ,2,2, 'reg' , 'Load stack pointer into reg.' ),
224| (0xe5, 'GETBP' ,2,2, 'reg' , 'Load stack pointer into reg.' ),
225| (0xe6, 'GETSI' ,2,2, 'reg' , 'Load stack pointer into reg.' ),
226| (0xe7, 'GETDI' ,2,2, 'reg' , 'Load stack pointer into reg.' ),
227|
228| (0xe8, 'SETSI' ,5,2, 'address' , 'Set SI to a0,a1,a2,a3.' ),
229| (0xe9, 'SETDI' ,5,2, 'address' , 'Set DI to a0,a1,a2,a3.' ),
230| (0xea, 'REGSI' ,2,2, 'reg' , 'Copy reg to SI.' ),
231| (0xeb, 'REGDI' ,2,2, 'reg' , 'Copy reg to DI.' ),
232| (0xec, 'SETVECI' ,6,2, 'int number' , 'Set user interrupt #int with n0.n1.n2.n3.' ),
233| (0xed, 'SETVECT' ,7,2, 'int reg address' , 'Set user interrupt #int with [address+reg].' ),
234| (0xee, 'SETVECR' ,3,2, 'int reg' , 'Set user interrupt #int with reg.' ),
235| (0xef, 'DEBUG' ,1,1, '' , 'Call debugger [#fffffff4].' ),
236|
237| (0xf0, 'INT' ,2,2, 'int' , 'Interrupt int [0-63].' ),
238| (0xf1, 'INT1' ,1,2, '' , 'User interrupt 1 (system interrupt 56).' ),
239| (0xf2, 'INT2' ,1,2, '' , 'User interrupt 2 (system interrupt 57).' ),
240| (0xf3, 'INT3' ,1,2, '' , 'User interrupt 3 (system interrupt 58).' ),
241| (0xf4, 'INT4' ,1,2, '' , 'User interrupt 4 (system interrupt 59).' ),
242| (0xf5, 'INT5' ,1,2, '' , 'User interrupt 5 (system interrupt 60).' ),
243| (0xf6, 'INT6' ,1,2, '' , 'User interrupt 6 (system interrupt 61).' ),
244| (0xf7, 'INT7' ,1,2, '' , 'User interrupt 7 (system interrupt 62).' ),
245| (0xf8, 'INT8' ,1,2, '' , 'User interrupt 8 (system interrupt 63).' ),
246|
247| (0xf9, 'NMI' ,1,1, '' , 'Non-maskable interrupt [#fffffff0].' ),
248| (0xfa, 'HOLD' ,1,1, '' , 'Stop operation; requires NMI to continue.' ),
249| (0xfb, 'WAIT' ,1,1, '' , 'Stop operation; any interrupt continues.' ),
250| (0xfc, 'PAUSE' ,1,1, '' , 'Stop operation; allows others to run.' ),
251| (0xfd, 'RESTART' ,1,1, '' , 'Jump to RESTART address [#fffffff8].' ),
252| (0xfe, 'REBOOT' ,1,1, '' , 'Jump to REBOOT address [#fffffffc].' ),
253| (0xff, 'HALT' ,1,1, '' , 'Stop the CPU; exit operation.' ),
254| )
255|
256|
257| '''Operands Dictionary. Index by operand string for operand length.'''
258| Operands:dict = {
259| 'reg':1, 'reg1':1, 'reg2':1, 'reg3':1,
260| 'num':1, 'num1':1, 'num2':1,
261| 'chn':1, 'int':1, 'len':1,
262| 'id':1, 'ver':1,
263| 'address':4, 'number':4,
264| 'b1...blen':0
265| }
266|
267|
268| '''OpIndex Dictionary. Index by OpCode Name for OpCode List Index.'''
269| OpIndex:dict = {rcd[1]:rx for rx,rcd in enumerate(OpCodes)}
270|
271| '''OpValue Dictionary. Index by OpCode Name for OpCode Value.'''
272| OpValue:dict = {rcd[1]:rcd[0] for rcd in OpCodes}
273|
274| '''OpLabel Dictionary. Index by OpCode Value for OpCode Name.'''
275| OpLabel:dict = {rcd[0]:rcd[1] for rcd in OpCodes}
276|
277|
278| '''OpCode Function (lambda). Takes OpCode Name. Returns OpCode Value.'''
279| OpCode = lambda name:OpValue[name]
280|
281|
282|
283| def list_opcodes (sout=None, space=8):
284| '''List the OpCodes table to a stream (screen or file).'''
285| fout = stdout if sout is None else sout
286|
287| space_next = space
288| for ix,rcd in enumerate(OpCodes):
289| if space_next <= rcd[0]:
290| while space_next <= rcd[0]:
291| space_next += space
292| print(file=fout)
293|
294| impl = '- ' if rcd[3] else '# '
295| print(f'{impl}{ix+1:3d}: 0x{rcd[0]:02x} {rcd[1]:<8s} {rcd[4]:<25s} {rcd[5]}', file=fout)
296| print(file=fout)
297|
298|
299| def do_opcodes_check (cls, **kwargs):
300| '''CMND: Check cj68 class for opcode methods .'''
301| fpath = KWARG('fpath', DocsPath, str, kwargs)
302| fname = KWARG('fname', 'cj68-op-codes.out', str, kwargs)
303| Log.info('opcodes-check-methods:: %s' % str(list(kwargs.keys())))
304| Log.debug(f'{fpath=}')
305| Log.debug(f'{fname=}')
306| Log.info()
307|
308|
309| for rcd in OpCodes:
310| method = f'op_{rcd[1]}'
311| Log.debug(f'Looking for class method: {method}')
312| try:
313| Log.info(cls.__dict__[method])
314| except:
315| Log.warn('Method Not Found!')
316| Log.info()
317|
318|
319| for method in sorted(cls.__dict__):
320| Log.trace(f'Class method: {method}')
321| if not method.startswith('op_'):
322| continue
323| opname = method[3:].upper()
324| Log.debug(f'Looking for OpCode definition: {opname}')
325| if opname in OpIndex:
326| ix = OpIndex[opname]
327| Log.info(OpCodes[ix])
328| else:
329| Log.warn('Opcode Not Found!')
330| Log.info()
331|
332| Log.info()
333| return 'Done'
334|
335|
336| def do_opcodes_list (**kwargs):
337| '''CMND: List OpCodes to screen/file.'''
338| fpath = KWARG('fpath', DocsPath, str, kwargs)
339| fname = KWARG('fname', 'cj68-op-codes.list', str, kwargs)
340| space = KWARG('space', 8, int, kwargs)
341| Log.info('opcodes-list:: %s' % str(list(kwargs.keys())))
342| Log.debug(f'{fpath=}')
343| Log.debug(f'{fname=}')
344| Log.debug(f'{space=}')
345| Log.info()
346|
347| if fname:
348|
349| fn = path.join(fpath,fname) if fpath else fname
350| fp = open(fn, mode='w')
351| try:
352| list_opcodes(sout=fp, space=space)
353| except:
354| raise
355| finally:
356| fp.close()
357| print(f'wrote: {fn}')
358| Log.info(f'wrote: {fn}')
359| else:
360|
361| list_opcodes(space=space)
362|
363| Log.info()
364| return 'Done'
365|
366|
367| CSS = '''
367| body {
367| background-color: #f7f9fc;
367| color: #000000;
367| font-family: "Verdana", "Arial", "Helvetica", sans-serif;
367| font-size: 10px;
367| font-weight: normal;
367| font-style: normal;
367| line-height: 1.33;
367| text-decoration: none;
367| text-align: left;
367| vertical-align: top;
367| padding: 0;
367| border: 0;
367| margin: 0;
367| }
367| h1, h2, h3, h4, h5, h6 {
367| font-family: "Tahoma", "Verdana", "Arial", "Helvetica", sans-serif;
367| font-weight: bold;
367| font-style: normal;
367| line-height: 1.0;
367| text-decoration: none;
367| text-align: left;
367| vertical-align: bottom;
367| padding: 0;
367| border: 0;
367| margin: 0;
367| }
367| h1 {
367| color: #000000;
367| font-size: 12px;
367| font-weight: normal;
367| font-style: italic;
367| text-align: right;
367| }
367| h2 {
367| color: #000000;
367| font-size: 15px;
367| text-align: right;
367| }
367| h3 {
367| color: #603018;
367| font-size: 14px;
367| text-align: left;
367| margin-bottom: 9px;
367| }
367| h4 {
367| color: #804020;
367| font-size: 14px;
367| padding: 9px 9px 18px 9px;
367| border: 1px solid black;
367| margin-top: 20px;
367| margin-bottom: 0;
367| }
367| #PageHead {
367| background-color: #e0e7ef;
367| font-size: medium;
367| padding: 6px 20px 8px 6px;
367| border-bottom: 2px solid black;
367| margin: 0;
367| }
367| #PageBody {
367| padding: 6px 24px 18px 12px;
367| margin: 0;
367| }
367| #PageFoot {
367| background-color: #c0c7cf;
367| color: #808080;
367| font-family: sans-serif;
367| font-size: 9px;
367| font-weight: normal;
367| font-style: normal;
367| line-height: 1.0;
367| text-align: center;
367| padding: 4px 12px 8px 12px;
367| border-top: 1px solid black;
367| margin: 0;
367| }
367| #PageFoot .Lt {
367| float: left;
367| text-align: left;
367| }
367| #PageFoot .Rt {
367| float: right;
367| text-align: right;
367| }
367| #PageBody table {
367| background-color: transparent;
367| font-size: 17px;
367| border-spacing: 3px 0;
367| padding: 1px 2px 3px 2px;
367| border: 2px solid #000000;
367| margin: 15px 5px;
367| }
367| #PageBody table thead th {
367| background-color: #000000;
367| color: #ffffff;
367| font-weight: normal;
367| font-style: italic;
367| text-align: left;
367| padding: 4px 3px 8px 3px;
367| }
367| #PageBody table tbody th {
367| text-align: left;
367| padding: 2px 9px 3px 9px;
367| }
367| #PageBody table tbody td {
367| white-space: nowrap;
367| text-align: left;
367| padding: 2px 9px 3px 9px;
367| }
367| #PageBody table tbody .Bold {
367| font-weight: bold;
367| }
367| #PageBody table tbody .Number {
367| font-family: monospace;
367| font-size: 19px;
367| text-align: right;
367| }
367|
367| '''
368|
369| def do_opcodes_webpage (**kwargs):
370| '''CMND: Create an HTML webpage from OpCodes.'''
371| fpath = KWARG('fpath', DocsPath, str, kwargs)
372| fname = KWARG('fname', 'cj68-op-codes.text', str, kwargs)
373| hpath = KWARG('hpath', DocsPath, str, kwargs)
374| hname = KWARG('hname', 'cj68-op-codes.html', str, kwargs)
375| space = KWARG('space', 8, int, kwargs)
376| Log.info('opcodes-webpage:: %s' % str(list(kwargs.keys())))
377| Log.debug(f'{fpath=}')
378| Log.debug(f'{fname=}')
379| Log.debug(f'{hpath=}')
380| Log.debug(f'{hname=}')
381| Log.info()
382| descfile = path.join(fpath, fname) if fpath else fname
383| htmlfile = path.join(hpath, hname) if hpath else hname
384|
385| fdesc = linefile(descfile)
386| if fdesc:
387| fdesc.load()
388|
389|
390| props = dict(
391| h1='CJSonnack',
392| h2='Python Apps',
393| h3='CJ68: OpCodes',
394| css=[], csstxt=CSS
395| )
396| pg = WebPage('CJ68', **props)
397| pg.add()
398| pg.add('<table>')
399| pg.add('<thead>')
400| pg.add('<tr>')
401| pg.add('<th style="text-align:center;">idx</th>')
402| pg.add('<th style="text-align:center;">code</th>')
403| pg.add('<th>name</th>')
404| pg.add('<th style="text-align:center;">len</th>')
405| pg.add('<th>operands</th>')
406| pg.add('<th>descrip</th>')
407| pg.add('<th style="text-align:center;">rem</th>')
408| pg.add('</tr>')
409| pg.add('</thead>')
410| pg.add('<tbody>')
411|
412| space_next = space
413| for ix,rcd in enumerate(OpCodes):
414| if space_next <= rcd[0]:
415| while space_next <= rcd[0]:
416| space_next += space
417| pg.add('<tr>')
418| pg.add('<td colspan="7" style="height:10px;"></td>')
419| pg.add('</tr>')
420|
421| pg.add('<tr>')
422| pg.add(f'<td class="Number">{ix+1:3d}</td>')
423| pg.add(f'<td class="Number Bold">0x{rcd[0]:02X}</td>')
424| pg.add(f'<th>{rcd[1]}</th>')
425| pg.add(f'<td class="Bold">{rcd[2]}</td>')
426| pg.add(f'<td>{rcd[4]}</td>')
427| pg.add(f'<td>{rcd[5]}</td>')
428| pg.add(f'<td>{"#?."[rcd[3]]}</td>')
429| pg.add('</tr>')
430| pg.add()
431|
432| pg.add('</tbody>')
433| pg.add('</table>')
434| pg.add()
435| pg.add('<p>len: total length, 0=variable length</p>')
436| pg.add('<p>rem: #=not implemented, ?=not tested, .=done!</p>')
437| pg.add()
438| pg.save(htmlfile, log=Log)
439|
440| Log.info()
441| return 'Done'
442|
443|
444|
445| '''eof'''
446|