diff --git a/emul/forth/z80c.bin b/emul/forth/z80c.bin index b57f1b0..5bd02a5 100644 Binary files a/emul/forth/z80c.bin and b/emul/forth/z80c.bin differ diff --git a/forth/forth.asm b/forth/forth.asm index 1a45941..865ec23 100644 --- a/forth/forth.asm +++ b/forth/forth.asm @@ -1405,28 +1405,10 @@ SWAP: push hl jp next -; ( a b c d -- c d a b ) - .db "2SWAP" - .fill 2 - .dw $-SWAP - .db 0 -SWAP2: - .dw nativeWord - pop de ; D - pop hl ; C - pop bc ; B - call chkPS - - ex (sp), hl ; A in HL - push de ; D - push hl ; A - push bc ; B - jp next - ; ( a -- a a ) .db "DUP" .fill 4 - .dw $-SWAP2 + .dw $-SWAP .db 0 DUP: .dw nativeWord @@ -1436,26 +1418,10 @@ DUP: push hl jp next -; ( a b -- a b a b ) - .db "2DUP" - .fill 3 - .dw $-DUP - .db 0 -DUP2: - .dw nativeWord - pop hl ; B - pop de ; A - call chkPS - push de - push hl - push de - push hl - jp next - ; ( a b -- a b a ) .db "OVER" .fill 3 - .dw $-DUP2 + .dw $-DUP .db 0 OVER: .dw nativeWord @@ -1467,29 +1433,9 @@ OVER: push de jp next -; ( a b c d -- a b c d a b ) - .db "2OVER" - .fill 2 - .dw $-OVER - .db 0 -OVER2: - .dw nativeWord - pop hl ; D - pop de ; C - pop bc ; B - pop iy ; A - call chkPS - push iy ; A - push bc ; B - push de ; C - push hl ; D - push iy ; A - push bc ; B - jp next - .db ">R" .fill 5 - .dw $-OVER2 + .dw $-OVER .db 0 P2R: .dw nativeWord diff --git a/forth/z80a.fs b/forth/z80a.fs index 1f9cabc..331e86d 100644 --- a/forth/z80a.fs +++ b/forth/z80a.fs @@ -22,6 +22,11 @@ 3 CONSTANT AF 3 CONSTANT SP +( As a general rule, IX and IY are equivalent to spitting an + extra 0xdd / 0xfd and then spit the equivalent of HL ) +: IX 0xdd A, HL ; +: IY 0xfd A, HL ; + ( -- ) : OP1 CREATE C, DOES> C@ A, ; 0xc9 OP1 RET, diff --git a/forth/z80c.fs b/forth/z80c.fs index 4e2f89e..1e8c078 100644 --- a/forth/z80c.fs +++ b/forth/z80c.fs @@ -30,4 +30,44 @@ CODE ROT BC PUSHqq, ( A ) ;CODE +( a b -- a b a b ) +CODE 2DUP + HL POPqq, ( B ) + DE POPqq, ( A ) + ROUTINE P CALLnn, + DE PUSHqq, ( A ) + HL PUSHqq, ( B ) + DE PUSHqq, ( A ) + HL PUSHqq, ( B ) +;CODE + +( a b c d -- a b c d a b ) + +CODE 2OVER + HL POPqq, ( D ) + DE POPqq, ( C ) + BC POPqq, ( B ) + IY POPqq, ( A ) + ROUTINE P CALLnn, + IY PUSHqq, ( A ) + BC PUSHqq, ( B ) + DE PUSHqq, ( C ) + HL PUSHqq, ( D ) + IY PUSHqq, ( A ) + BC PUSHqq, ( B ) +;CODE + +( a b c d -- c d a b ) + +CODE 2SWAP + HL POPqq, ( D ) + DE POPqq, ( C ) + BC POPqq, ( B ) + IY POPqq, ( A ) + ROUTINE P CALLnn, + DE PUSHqq, ( C ) + HL PUSHqq, ( D ) + IY PUSHqq, ( A ) + BC PUSHqq, ( B ) +;CODE