mirror of
https://github.com/hsoft/collapseos.git
synced 2025-04-04 13:38:39 +11:00
Fixed more errors, clearer choice of constants
This commit is contained in:
parent
ab4fca334d
commit
edbd775642
@ -9,28 +9,23 @@
|
||||
; On success, the carry flag is reset. On error, it is set.
|
||||
; Also, zero flag set if '0'
|
||||
; parseDecimalDigit has been replaced with the following code inline:
|
||||
; add a, 0xc6 ; Maps '0'-'9' onto 0xf6-0xff
|
||||
; sub 0xf6 ; Anything but 0xf6-0xff carries
|
||||
; Maps 0xf6-0xff onto 0-9
|
||||
; add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
||||
; sub 0xff-9 ; maps to 0-9 and carries if not a digit
|
||||
|
||||
; Parse string at (HL) as a decimal value and return value in IX under the
|
||||
; same conditions as parseLiteral.
|
||||
; Sets Z on success, unset on error.
|
||||
|
||||
; 61 bytes
|
||||
; 107 cycles overhead + up to 73 cycles if length >= 5
|
||||
; 136 cycles in loop
|
||||
; first digit is skipped in overhead
|
||||
parseDecimal:
|
||||
push hl
|
||||
|
||||
ld a, (hl)
|
||||
add a, 0xc6 ; converts '0'-'9' to 0-9
|
||||
sub 0xf6 ; carries if out of range
|
||||
add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
||||
sub 0xff-9 ; maps to 0-9 and carries if not a digit
|
||||
exx ; preserve bc, hl, de
|
||||
ld h, 0
|
||||
ld l, a ; load first digit in without multiplying
|
||||
ld b, 4 ; Carries can only occur for decimals >=5 in length
|
||||
ld b, 3 ; Carries can only occur for decimals >=5 in length
|
||||
jr c, .error
|
||||
|
||||
.loop:
|
||||
@ -39,8 +34,8 @@ parseDecimal:
|
||||
ld a, (hl)
|
||||
exx
|
||||
|
||||
add a, 0xc6 ; converts '0'-'9' to 0-9
|
||||
sub 0xf6 ; carries if out of range
|
||||
add a, 0xff-'9' ; maps '0'-'9' onto 0xf6-0xff
|
||||
sub 0xff-9 ; maps to 0-9 and carries if not a digit
|
||||
jr c, .error
|
||||
|
||||
add hl, hl ; x2
|
||||
@ -68,7 +63,7 @@ parseDecimal:
|
||||
inc hl
|
||||
ld a, (hl)
|
||||
exx
|
||||
add a, 0xd0
|
||||
add a, 0xd0 ; the next line expects a null to be mapped to 0xd0
|
||||
.error:
|
||||
sub 0xd0 ; if a is null, set Z
|
||||
; a is checked for null before any errors
|
||||
|
Loading…
Reference in New Issue
Block a user