From cb3e6469b825d64dbb5f82363ef12565808b305c Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 26 Mar 2020 14:47:17 -0400 Subject: [PATCH] forth: make "(parsed)" support negative literals This limitation was becoming annoying... --- forth/forth.asm | 15 +++++++++++++++ forth/z80c.fs | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/forth/forth.asm b/forth/forth.asm index 742804f..ae2381a 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -296,6 +296,8 @@ strskip: parseDecimal: ; First char is special: it has to succeed. ld a, (hl) + cp '-' + jr z, .negative ; Parse the decimal char at A and extract it's 0-9 numerical value. Put the ; result in A. ; On success, the carry flag is reset. On error, it is set. @@ -349,6 +351,19 @@ parseDecimal: cp a ; ensure Z 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 *** ; Find the entry corresponding to word where (HL) points to and sets DE to ; point to that entry. diff --git a/forth/z80c.fs b/forth/z80c.fs index fbe7ac5..183d848 100644 --- a/forth/z80c.fs +++ b/forth/z80c.fs @@ -130,7 +130,7 @@ CODE * DE INCss, ( noinc ) A DECr, - 0 12 - JRNZe, ( loop ) + -12 JRNZe, ( loop ) HL PUSHqq, ;CODE @@ -154,7 +154,7 @@ CODE /MOD DE ADDHLss, C DECr, ( skip ) - 0 12 - DJNZe, ( loop ) + -12 DJNZe, ( loop ) B A LDrr, HL PUSHqq, BC PUSHqq,