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

zasm: add support for RLC r and RRC r

This commit is contained in:
Virgil Dupras 2019-05-18 19:59:31 -04:00
parent 29f0bcbe23
commit 2ce6b61964
2 changed files with 41 additions and 30 deletions

View File

@ -2,7 +2,7 @@
; Number of rows in the argspec table ; Number of rows in the argspec table
ARGSPEC_TBL_CNT .equ 31 ARGSPEC_TBL_CNT .equ 31
; Number of rows in the primary instructions table ; Number of rows in the primary instructions table
INSTR_TBL_CNT .equ 148 INSTR_TBL_CNT .equ 150
; 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 6 INSTR_TBL_ROWSIZE .equ 6
; Instruction IDs They correspond to the index of the table in instrNames ; Instruction IDs They correspond to the index of the table in instrNames
@ -53,14 +53,16 @@ I_RETI .equ 0x2b
I_RETN .equ 0x2c I_RETN .equ 0x2c
I_RL .equ 0x2d I_RL .equ 0x2d
I_RLA .equ 0x2e I_RLA .equ 0x2e
I_RLCA .equ 0x2f I_RLC .equ 0x2f
I_RR .equ 0x30 I_RLCA .equ 0x30
I_RRA .equ 0x31 I_RR .equ 0x31
I_RRCA .equ 0x32 I_RRA .equ 0x32
I_SBC .equ 0x33 I_RRC .equ 0x33
I_SCF .equ 0x34 I_RRCA .equ 0x34
I_SUB .equ 0x35 I_SBC .equ 0x35
I_XOR .equ 0x36 I_SCF .equ 0x36
I_SUB .equ 0x37
I_XOR .equ 0x38
; Checks whether A is 'N' or 'M' ; Checks whether A is 'N' or 'M'
checkNOrM: checkNOrM:
@ -585,12 +587,24 @@ getUpcode:
ld de, instrUpcode ; from this point, DE points to "where we are" ld de, instrUpcode ; from this point, DE points to "where we are"
; in terms of upcode writing. ; in terms of upcode writing.
inc de ; make DE point to where we should write next. inc de ; make DE point to where we should write next.
ld c, 1 ; C holds our upcode count
; Now, let's determine if we have one or two upcode. As a general rule,
; we simply have to check if (ix+5) == 0, which means one upcode.
; However, some two-upcodes instructions have a 0 (ix+5) because they
; expect group OR-ing into it and all other bits are zero. See "RLC r".
; To handle those cases, we *also* check for Bit 6 in (ix+3).
ld a, (ix+5) ; second upcode ld a, (ix+5) ; second upcode
cp 0 ; do we have a second upcode? or a ; do we have a second upcode?
jr z, .onlyOneUpcode jr nz, .twoUpcodes
bit 6, (ix+3)
jr z, .onlyOneUpcode ; not set: single upcode
.twoUpcodes:
; we have two upcodes ; we have two upcodes
ld (de), a ld (de), a
inc de inc de
inc c
.onlyOneUpcode: .onlyOneUpcode:
; now, let's see if we're dealing with a group here ; now, let's see if we're dealing with a group here
ld a, (ix+1) ; first argspec ld a, (ix+1) ; first argspec
@ -653,8 +667,7 @@ getUpcode:
call checknmxy call checknmxy
jr z, .withByte jr z, .withByte
; nope, no number, alright, we're finished here ; nope, no number, alright, we're finished here
ld c, 1 jr .end
jr .computeBytesWritten
.withByte: .withByte:
inc hl inc hl
; HL points to our number (LSB), with (HL+1) being our MSB which should ; HL points to our number (LSB), with (HL+1) being our MSB which should
@ -669,9 +682,9 @@ getUpcode:
; First, check whether we're on first pass. If we are, skip processing ; First, check whether we're on first pass. If we are, skip processing
; below because not having real symbol value makes relative address ; below because not having real symbol value makes relative address
; verification falsely fail. ; verification falsely fail.
ld c, 2 ; this is a two bytes instruction inc c ; one extra byte is written
call zasmIsFirstPass call zasmIsFirstPass
jr z, .computeBytesWritten jr z, .end
; We're on second pass ; We're on second pass
push de ; Don't let go of this, that's our dest push de ; Don't let go of this, that's our dest
@ -698,7 +711,7 @@ getUpcode:
or a ; cp 0 or a ; cp 0
jr nz, .numberTruncated ; if A is anything but zero, we're out jr nz, .numberTruncated ; if A is anything but zero, we're out
; of bounds. ; of bounds.
jr .computeBytesWritten jr .end
.absoluteValue: .absoluteValue:
; verify that the MSB in argument is zero ; verify that the MSB in argument is zero
@ -707,26 +720,20 @@ getUpcode:
dec hl ; HL now points to LSB dec hl ; HL now points to LSB
or a ; cp 0 or a ; cp 0
jr nz, .numberTruncated jr nz, .numberTruncated
push bc
ldi ldi
ld c, 2 pop bc
jr .computeBytesWritten inc c
jr .end
.withWord: .withWord:
inc hl ; HL now points to LSB inc hl ; HL now points to LSB
; Clear to proceed. HL already points to our number ; Clear to proceed. HL already points to our number
push bc
ldi ; LSB written, we point to MSB now ldi ; LSB written, we point to MSB now
ldi ; MSB written ldi ; MSB written
ld c, 3 pop bc
jr .computeBytesWritten inc c ; two extra bytes are written
.computeBytesWritten:
; At this point, everything that we needed to write in instrUpcode is
; written an C is 1 if we have no extra byte, 2 if we have an extra
; byte and 3 if we have an extra word. What we need to do here is check
; if ix+5 is non-zero and increase C if it is.
ld a, (ix+5)
cp 0
jr z, .end ; no second upcode? nothing to do.
; We have 2 base upcodes
inc c inc c
jr .end jr .end
.numberTruncated: .numberTruncated:
@ -945,9 +952,11 @@ instrNames:
.db "RETN" .db "RETN"
.db "RL", 0, 0 .db "RL", 0, 0
.db "RLA", 0 .db "RLA", 0
.db "RLC", 0
.db "RLCA" .db "RLCA"
.db "RR", 0, 0 .db "RR", 0, 0
.db "RRA", 0 .db "RRA", 0
.db "RRC", 0
.db "RRCA" .db "RRCA"
.db "SBC", 0 .db "SBC", 0
.db "SCF", 0 .db "SCF", 0
@ -1114,9 +1123,11 @@ instrTBl:
.db I_RETN,0, 0, 0, 0xed, 0x45 ; RETN .db I_RETN,0, 0, 0, 0xed, 0x45 ; RETN
.db I_RL, 0xb, 0,0x40, 0xcb, 0b00010000 ; RL r .db I_RL, 0xb, 0,0x40, 0xcb, 0b00010000 ; RL r
.db I_RLA, 0, 0, 0, 0x17 , 0 ; RLA .db I_RLA, 0, 0, 0, 0x17 , 0 ; RLA
.db I_RLC, 0xb, 0,0x40, 0xcb, 0b00000000 ; RLC r
.db I_RLCA,0, 0, 0, 0x07 , 0 ; RLCA .db I_RLCA,0, 0, 0, 0x07 , 0 ; RLCA
.db I_RR, 0xb, 0,0x40, 0xcb, 0b00011000 ; RR r .db I_RR, 0xb, 0,0x40, 0xcb, 0b00011000 ; RR r
.db I_RRA, 0, 0, 0, 0x1f , 0 ; RRA .db I_RRA, 0, 0, 0, 0x1f , 0 ; RRA
.db I_RRC, 0xb, 0,0x40, 0xcb, 0b00001000 ; RRC r
.db I_RRCA,0, 0, 0, 0x0f , 0 ; RRCA .db I_RRCA,0, 0, 0, 0x0f , 0 ; RRCA
.db I_SBC, 'A', 'l', 0, 0x9e , 0 ; SBC A, (HL) .db I_SBC, 'A', 'l', 0, 0x9e , 0 ; SBC A, (HL)
.db I_SBC, 'A', 0xb, 0, 0b10011000 , 0 ; SBC A, r .db I_SBC, 'A', 0xb, 0, 0b10011000 , 0 ; SBC A, r
@ -1138,4 +1149,3 @@ curArg2:
instrUpcode: instrUpcode:
.db 0, 0, 0, 0 .db 0, 0, 0, 0

View File

@ -23,3 +23,4 @@ label2: .dw 0x42
ld b, baz-3 ld b, baz-3
rl d rl d
rr e rr e
rlc c