mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:18:07 +11:00
zasm: can now assemble zasm/parse.asm!
This commit is contained in:
parent
2ce6b61964
commit
fd11941867
@ -6,7 +6,7 @@ parseDecimalDigit:
|
|||||||
; First, let's see if we have an easy 0-9 case
|
; First, let's see if we have an easy 0-9 case
|
||||||
cp '0'
|
cp '0'
|
||||||
ret c ; if < '0', we have a problem
|
ret c ; if < '0', we have a problem
|
||||||
sub a, '0' ; our value now is valid if it's < 10
|
sub '0' ; our value now is valid if it's < 10
|
||||||
cp 10 ; on success, C is set, which is the opposite
|
cp 10 ; on success, C is set, which is the opposite
|
||||||
; of what we want
|
; of what we want
|
||||||
ccf ; invert C flag
|
ccf ; invert C flag
|
||||||
@ -22,30 +22,27 @@ parseDecimal:
|
|||||||
ld ix, 0
|
ld ix, 0
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp 0
|
or a
|
||||||
jr z, .end ; success!
|
jr z, .end ; success!
|
||||||
call parseDecimalDigit
|
call parseDecimalDigit
|
||||||
jr c, .error
|
jr c, .error
|
||||||
|
|
||||||
; Now, let's add A to IX. First, multiply by 10.
|
; Now, let's add A to IX. First, multiply by 10.
|
||||||
ld d, ixh ; we need a copy of the initial copy for later
|
push ix \ pop de
|
||||||
ld e, ixl
|
|
||||||
add ix, ix ; x2
|
add ix, ix ; x2
|
||||||
|
jr c, .error
|
||||||
add ix, ix ; x4
|
add ix, ix ; x4
|
||||||
|
jr c, .error
|
||||||
add ix, ix ; x8
|
add ix, ix ; x8
|
||||||
|
jr c, .error
|
||||||
add ix, de ; x9
|
add ix, de ; x9
|
||||||
|
jr c, .error
|
||||||
add ix, de ; x10
|
add ix, de ; x10
|
||||||
add a, ixl
|
jr c, .error
|
||||||
jr nc, .nocarry
|
ld d, 0
|
||||||
inc ixh
|
ld e, a
|
||||||
.nocarry:
|
add ix, de
|
||||||
ld ixl, a
|
jr c, .error
|
||||||
|
|
||||||
; We didn't bother checking for the C flag at each step because we
|
|
||||||
; check for overflow afterwards. If ixh < d, we overflowed
|
|
||||||
ld a, ixh
|
|
||||||
cp d
|
|
||||||
jr c, .error ; carry is set? overflow
|
|
||||||
|
|
||||||
inc hl
|
inc hl
|
||||||
jr .loop
|
jr .loop
|
||||||
@ -65,8 +62,8 @@ parseHexadecimal:
|
|||||||
call hasHexPrefix
|
call hasHexPrefix
|
||||||
ret nz
|
ret nz
|
||||||
push hl
|
push hl
|
||||||
xor a
|
push de
|
||||||
ld ixh, a
|
ld d, 0
|
||||||
inc hl ; get rid of "0x"
|
inc hl ; get rid of "0x"
|
||||||
inc hl
|
inc hl
|
||||||
call strlen
|
call strlen
|
||||||
@ -82,23 +79,25 @@ parseHexadecimal:
|
|||||||
call parseHexPair
|
call parseHexPair
|
||||||
jr c, .error
|
jr c, .error
|
||||||
inc hl ; now HL is on first char of next pair
|
inc hl ; now HL is on first char of next pair
|
||||||
ld ixh, a
|
ld d, a
|
||||||
jr .single
|
jr .single
|
||||||
.doubleShort:
|
.doubleShort:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
call parseHex
|
call parseHex
|
||||||
jr c, .error
|
jr c, .error
|
||||||
inc hl ; now HL is on first char of next pair
|
inc hl ; now HL is on first char of next pair
|
||||||
ld ixh, a
|
ld d, a
|
||||||
.single:
|
.single:
|
||||||
call parseHexPair
|
call parseHexPair
|
||||||
jr c, .error
|
jr c, .error
|
||||||
ld ixl, a
|
ld e, a
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
jr .end
|
jr .end
|
||||||
.error:
|
.error:
|
||||||
call unsetZ
|
call unsetZ
|
||||||
.end:
|
.end:
|
||||||
|
push de \ pop ix
|
||||||
|
pop de
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -114,17 +113,17 @@ hasHexPrefix:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse string at (HL) as a binary value (0b010101) and return value in IXL.
|
; Parse string at (HL) as a binary value (0b010101) and return value in IX.
|
||||||
; Clears IXH.
|
; High IX byte is always clear.
|
||||||
; Sets Z on success.
|
; Sets Z on success.
|
||||||
parseBinaryLiteral:
|
parseBinaryLiteral:
|
||||||
call hasBinPrefix
|
call hasBinPrefix
|
||||||
ret nz
|
ret nz
|
||||||
push bc
|
push bc
|
||||||
push hl
|
push hl
|
||||||
xor a
|
push de
|
||||||
ld ixh, a
|
ld d, 0
|
||||||
inc hl ; get rid of "0x"
|
inc hl ; get rid of "0b"
|
||||||
inc hl
|
inc hl
|
||||||
call strlen
|
call strlen
|
||||||
or a
|
or a
|
||||||
@ -148,12 +147,14 @@ parseBinaryLiteral:
|
|||||||
inc c
|
inc c
|
||||||
.nobit:
|
.nobit:
|
||||||
djnz .loop
|
djnz .loop
|
||||||
ld ixl, c
|
ld e, c
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
jr .end
|
jr .end
|
||||||
.error:
|
.error:
|
||||||
call unsetZ
|
call unsetZ
|
||||||
.end:
|
.end:
|
||||||
|
push de \ pop ix
|
||||||
|
pop de
|
||||||
pop hl
|
pop hl
|
||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
@ -171,7 +172,7 @@ hasBinPrefix:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse string at (HL) and, if it is a char literal, sets Z and return
|
; Parse string at (HL) and, if it is a char literal, sets Z and return
|
||||||
; corresponding value in IXL. Clears IXH.
|
; corresponding value in IX. High IX byte is always clear.
|
||||||
;
|
;
|
||||||
; A valid char literal starts with ', ends with ' and has one character in the
|
; A valid char literal starts with ', ends with ' and has one character in the
|
||||||
; middle. No escape sequence are accepted, but ''' will return the apostrophe
|
; middle. No escape sequence are accepted, but ''' will return the apostrophe
|
||||||
@ -182,6 +183,7 @@ parseCharLiteral:
|
|||||||
ret nz
|
ret nz
|
||||||
|
|
||||||
push hl
|
push hl
|
||||||
|
push de
|
||||||
inc hl
|
inc hl
|
||||||
inc hl
|
inc hl
|
||||||
cp (hl)
|
cp (hl)
|
||||||
@ -191,13 +193,15 @@ parseCharLiteral:
|
|||||||
or a ; cp 0
|
or a ; cp 0
|
||||||
jr nz, .end ; string has to end there
|
jr nz, .end ; string has to end there
|
||||||
; Valid char, good
|
; Valid char, good
|
||||||
ld ixh, a ; A is zero, take advantage of that
|
ld d, a ; A is zero, take advantage of that
|
||||||
dec hl
|
dec hl
|
||||||
dec hl
|
dec hl
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
ld ixl, a
|
ld e, a
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
.end:
|
.end:
|
||||||
|
push de \ pop ix
|
||||||
|
pop de
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -233,8 +237,7 @@ parseNumberOrSymbol:
|
|||||||
push de
|
push de
|
||||||
call symGetVal
|
call symGetVal
|
||||||
; value in DE. We need it in IX
|
; value in DE. We need it in IX
|
||||||
ld ixh, d
|
push de \ pop ix
|
||||||
ld ixl, e
|
|
||||||
pop de
|
pop de
|
||||||
cp a ; ensure Z
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "zasm/io.asm"
|
#include "zasm/io.asm"
|
||||||
.equ SYM_RAMSTART IO_RAMEND
|
.equ SYM_RAMSTART IO_RAMEND
|
||||||
#include "zasm/symbol.asm"
|
#include "zasm/symbol.asm"
|
||||||
|
#include "zasm/parse.asm"
|
||||||
|
|
||||||
zasmIsFirstPass:
|
zasmIsFirstPass:
|
||||||
nop
|
nop
|
||||||
|
Loading…
Reference in New Issue
Block a user