1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:08:05 +11:00

zasm: add a bunch of instructions

This commit is contained in:
Virgil Dupras 2019-04-21 13:58:13 -04:00
parent e9e2f30fc5
commit 93eb262083
2 changed files with 80 additions and 3 deletions

View File

@ -14,6 +14,7 @@ argspecTbl = {
'A': "A", 'A': "A",
'B': "B", 'B': "B",
'C': "C", 'C': "C",
'k': "(C)",
'D': "D", 'D': "D",
'E': "E", 'E': "E",
'H': "H", 'H': "H",
@ -129,6 +130,8 @@ def main():
if n == 'BIT': if n == 'BIT':
# we only want to keep 1, 2, 4 # we only want to keep 1, 2, 4
args1 = args1[:3] args1 = args1[:3]
if n == 'IM':
args1 = [0, 1, 2]
if args1: if args1:
for arg1 in args1: for arg1 in args1:
args2 = genargs(a2) args2 = genargs(a2)

View File

@ -2,9 +2,9 @@
; *** Consts *** ; *** Consts ***
; Number of rows in the argspec table ; Number of rows in the argspec table
ARGSPEC_TBL_CNT .equ 28 ARGSPEC_TBL_CNT .equ 29
; Number of rows in the primary instructions table ; Number of rows in the primary instructions table
INSTR_TBL_CNT .equ 108 INSTR_TBL_CNT .equ 114
; size in bytes of each row in the primary instructions table ; size in bytes of each row in the primary instructions table
INSTR_TBL_ROWSIZE .equ 9 INSTR_TBL_ROWSIZE .equ 9
@ -538,9 +538,9 @@ handleBITR:
ld a, (curArg2) ld a, (curArg2)
ld h, 0xb ld h, 0xb
call findInGroup call findInGroup
ret nz ; error
push af ; push group value push af ; push group value
; write first upcode ; write first upcode
ret nz ; error
ld a, 0xcb ; first upcode ld a, 0xcb ; first upcode
ld (curUpcode), a ld (curUpcode), a
; get bit value ; get bit value
@ -557,6 +557,73 @@ handleBITR:
ld c, 2 ld c, 2
ret ret
handleIM:
ld a, (curArg1+1)
cp 0
jr z, .im0
cp 1
jr z, .im1
cp 2
jr z, .im2
; error
ld c, 0
ret
.im0:
ld a, 0x46
jr .proceed
.im1:
ld a, 0x56
jr .proceed
.im2:
ld a, 0x5e
.proceed:
ld (curUpcode+1), a
ld a, 0xed
ld (curUpcode), a
ld c, 2
ret
handleLDIXn:
ld a, 0xdd
jr handleLDIXYn
handleLDIYn:
ld a, 0xfd
handleLDIXYn:
ld (curUpcode), a
ld a, 0x36 ; second upcode
ld (curUpcode+1), a
ld a, (curArg1+1) ; IXY displacement
ld (curUpcode+2), a
ld a, (curArg2+1) ; N
ld (curUpcode+3), a
ld c, 4
ret
.error:
xor c
ret
handleLDIXr:
ld a, 0xdd
jr handleLDIXYr
handleLDIYr:
ld a, 0xfd
handleLDIXYr:
ld (curUpcode), a
; get group value
ld a, (curArg2)
ld h, 0xb
call findInGroup
ret nz ; error
or 0b01110000 ; second upcode
ld (curUpcode+1), a
ld a, (curArg1+1) ; IXY displacement
ld (curUpcode+2), a
ld c, 3
ret
.error:
xor c
ret
; Compute the upcode for argspec row at (DE) and arguments in curArg{1,2} and ; Compute the upcode for argspec row at (DE) and arguments in curArg{1,2} and
; writes the resulting upcode in curUpcode. A is the number if bytes written ; writes the resulting upcode in curUpcode. A is the number if bytes written
; to curUpcode (can be zero if something went wrong). ; to curUpcode (can be zero if something went wrong).
@ -791,6 +858,7 @@ argspecTbl:
.db 'A', "A", 0, 0, 0 .db 'A', "A", 0, 0, 0
.db 'B', "B", 0, 0, 0 .db 'B', "B", 0, 0, 0
.db 'C', "C", 0, 0, 0 .db 'C', "C", 0, 0, 0
.db 'k', "(C)", 0
.db 'D', "D", 0, 0, 0 .db 'D', "D", 0, 0, 0
.db 'E', "E", 0, 0, 0 .db 'E', "E", 0, 0, 0
.db 'H', "H", 0, 0, 0 .db 'H', "H", 0, 0, 0
@ -918,7 +986,9 @@ instrTBl:
.db "EX",0,0, 'd', 'h', 0, 0xeb , 0 ; EX DE, HL .db "EX",0,0, 'd', 'h', 0, 0xeb , 0 ; EX DE, HL
.db "EXX", 0, 0, 0, 0, 0xd9 , 0 ; EXX .db "EXX", 0, 0, 0, 0, 0xd9 , 0 ; EXX
.db "HALT", 0, 0, 0, 0x76 , 0 ; HALT .db "HALT", 0, 0, 0, 0x76 , 0 ; HALT
.db "IM",0,0,'n', 0,0x20 \ .dw handleIM ; IM {0,1,2}
.db "IN",0,0, 'A', 'm', 0, 0xdb , 0 ; IN A, (n) .db "IN",0,0, 'A', 'm', 0, 0xdb , 0 ; IN A, (n)
.db "IN",0,0,0xb,'k',0x43, 0xed, 0b01000000 ; IN r, (C)
.db "INC", 0, 'l', 0, 0, 0x34 , 0 ; INC (HL) .db "INC", 0, 'l', 0, 0, 0x34 , 0 ; INC (HL)
.db "INC", 0, 'X', 0, 0, 0xdd , 0x23 ; INC IX .db "INC", 0, 'X', 0, 0, 0xdd , 0x23 ; INC IX
.db "INC", 0, 'x', 0, 0, 0xdd , 0x34 ; INC (IX+d) .db "INC", 0, 'x', 0, 0, 0xdd , 0x34 ; INC (IX+d)
@ -954,6 +1024,10 @@ instrTBl:
.db "LD",0,0, 'A', 'M', 0, 0x3a , 0 ; LD A, (NN) .db "LD",0,0, 'A', 'M', 0, 0x3a , 0 ; LD A, (NN)
.db "LD",0,0, 'M', 'h', 0, 0x22 , 0 ; LD (NN), HL .db "LD",0,0, 'M', 'h', 0, 0x22 , 0 ; LD (NN), HL
.db "LD",0,0, 'h', 'M', 0, 0x2a , 0 ; LD HL, (NN) .db "LD",0,0, 'h', 'M', 0, 0x2a , 0 ; LD HL, (NN)
.db "LD",0,0, 'x','n',0x20 \ .dw handleLDIXn ; LD (IX+d), n
.db "LD",0,0, 'y','n',0x20 \ .dw handleLDIYn ; LD (IY+d), n
.db "LD",0,0, 'x',0xb,0x20 \ .dw handleLDIXr ; LD (IX+d), r
.db "LD",0,0, 'y',0xb,0x20 \ .dw handleLDIYr ; LD (IY+d), r
.db "NOP", 0, 0, 0, 0, 0x00 , 0 ; NOP .db "NOP", 0, 0, 0, 0, 0x00 , 0 ; NOP
.db "OR",0,0, 'l', 0, 0, 0xb6 , 0 ; OR (HL) .db "OR",0,0, 'l', 0, 0, 0xb6 , 0 ; OR (HL)
.db "OR",0,0, 0xb, 0, 0, 0b10110000 , 0 ; OR r .db "OR",0,0, 0xb, 0, 0, 0b10110000 , 0 ; OR r