From 40eda1d9339fbfa9da2ae9313089303f8c7cbe37 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 26 Mar 2020 14:36:14 -0400 Subject: [PATCH] forth: Forth-ify "*" --- emul/forth/z80c.bin | Bin 367 -> 401 bytes forth/forth.asm | 28 +--------------------------- forth/z80c.fs | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index f8a2b42e9256f24d613ab1402e5c78e6f8739e5a..f9c283090158d34da3e8f2a376d11a35121bd48c 100644 GIT binary patch delta 49 zcmV-10M7sK0+9odq$es8009>O(ZS6f03iSXJ`gF(6U!1X1PL$!6FngE<--~PFHKKG HB9W=aUJVY% delta 15 XcmbQp{GMsT5>|a*e;3h-r;h;uEZhbK diff --git a/forth/forth.asm b/forth/forth.asm index 31f53dc..742804f 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -1340,35 +1340,9 @@ MINUS: push hl jp next -; ( a b -- c ) A * B - .db "*" - .dw $-MINUS - .db 1 -MULT: - .dw nativeWord - pop de - pop bc - call chkPS - ; DE * BC -> DE (high) and HL (low) - ld hl, 0 - ld a, 0x10 -.loop: - add hl, hl - rl e - rl d - jr nc, .noinc - add hl, bc - jr nc, .noinc - inc de -.noinc: - dec a - jr nz, .loop - push hl - jp next - ; ( a1 a2 -- b ) .db "SCMP" - .dw $-MULT + .dw $-MINUS .db 4 SCMP: .dw nativeWord diff --git a/forth/z80c.fs b/forth/z80c.fs index 1ed407a..fbe7ac5 100644 --- a/forth/z80c.fs +++ b/forth/z80c.fs @@ -113,6 +113,27 @@ CODE XOR HL PUSHqq, ;CODE +CODE * + DE POPqq, + BC POPqq, + chkPS, + ( DE * BC -> DE (high) and HL (low) ) + HL 0 LDddnn, + A 0x10 LDrn, +( loop ) + HL ADDHLss, + E RLr, + D RLr, + 6 JRNCe, ( noinc ) + BC ADDHLss, + 3 JRNCe, ( noinc ) + DE INCss, +( noinc ) + A DECr, + 0 12 - JRNZe, ( loop ) + HL PUSHqq, +;CODE + ( Borrowed from http://wikiti.brandonw.net/ ) ( Divides AC by DE and places the quotient in AC and the remainder in HL )