1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-26 04:48:05 +11:00

forth: make "(parsed)" support negative literals

This limitation was becoming annoying...
This commit is contained in:
Virgil Dupras 2020-03-26 14:47:17 -04:00
parent 40eda1d933
commit cb3e6469b8
2 changed files with 17 additions and 2 deletions

View File

@ -296,6 +296,8 @@ strskip:
parseDecimal: parseDecimal:
; First char is special: it has to succeed. ; First char is special: it has to succeed.
ld a, (hl) ld a, (hl)
cp '-'
jr z, .negative
; Parse the decimal char at A and extract it's 0-9 numerical value. Put the ; Parse the decimal char at A and extract it's 0-9 numerical value. Put the
; result in A. ; result in A.
; On success, the carry flag is reset. On error, it is set. ; On success, the carry flag is reset. On error, it is set.
@ -349,6 +351,19 @@ parseDecimal:
cp a ; ensure Z cp a ; ensure Z
ret ret
.negative:
inc hl
call parseDecimal
ret nz
push hl ; --> lvl 1
or a ; clear carry
ld hl, 0
sbc hl, de
ex de, hl
pop hl ; <-- lvl 1
xor a ; set Z
ret
; *** Support routines *** ; *** Support routines ***
; Find the entry corresponding to word where (HL) points to and sets DE to ; Find the entry corresponding to word where (HL) points to and sets DE to
; point to that entry. ; point to that entry.

View File

@ -130,7 +130,7 @@ CODE *
DE INCss, DE INCss,
( noinc ) ( noinc )
A DECr, A DECr,
0 12 - JRNZe, ( loop ) -12 JRNZe, ( loop )
HL PUSHqq, HL PUSHqq,
;CODE ;CODE
@ -154,7 +154,7 @@ CODE /MOD
DE ADDHLss, DE ADDHLss,
C DECr, C DECr,
( skip ) ( skip )
0 12 - DJNZe, ( loop ) -12 DJNZe, ( loop )
B A LDrr, B A LDrr,
HL PUSHqq, HL PUSHqq,
BC PUSHqq, BC PUSHqq,