2020-03-25 04:46:05 +11:00
|
|
|
( Core words in z80. This requires a full Forth interpreter
|
|
|
|
to run, but is also necessary for core.fs. This means that
|
|
|
|
it needs to be compiled from a prior bootstrapped binary.
|
|
|
|
|
|
|
|
This stage is tricky due to the fact that references in
|
|
|
|
Forth are all absolute, except for prev word refs. This
|
|
|
|
means that there are severe limitations to the kind of code
|
|
|
|
you can put here.
|
|
|
|
|
|
|
|
You shouldn't define any word with reference to other words.
|
|
|
|
This means no regular definition. You can, however, execute
|
|
|
|
any word from our high level Forth, as long as it doesn't
|
|
|
|
spit word references.
|
|
|
|
|
|
|
|
ROUTINE stuff is fine. It's not supposed to change.
|
|
|
|
|
|
|
|
These restrictions are temporary, I'll figure something out
|
|
|
|
so that we can end up fully bootstrap Forth from within
|
|
|
|
itself.
|
2020-03-27 03:05:48 +11:00
|
|
|
|
|
|
|
Oh, also: KEY and EMIT are not defined here. There're
|
|
|
|
expected to be defined in platform-specific code.
|
2020-03-25 04:46:05 +11:00
|
|
|
)
|
|
|
|
|
|
|
|
( a b c -- b c a )
|
|
|
|
CODE ROT
|
|
|
|
HL POPqq, ( C )
|
|
|
|
DE POPqq, ( B )
|
|
|
|
BC POPqq, ( A )
|
2020-03-26 12:49:09 +11:00
|
|
|
chkPS,
|
2020-03-25 04:46:05 +11:00
|
|
|
DE PUSHqq, ( B )
|
|
|
|
HL PUSHqq, ( C )
|
|
|
|
BC PUSHqq, ( A )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-25 05:44:10 +11:00
|
|
|
( a b -- a b a b )
|
|
|
|
CODE 2DUP
|
|
|
|
HL POPqq, ( B )
|
|
|
|
DE POPqq, ( A )
|
2020-03-25 14:02:06 +11:00
|
|
|
chkPS,
|
2020-03-25 05:44:10 +11:00
|
|
|
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 )
|
2020-03-25 14:02:06 +11:00
|
|
|
chkPS,
|
2020-03-25 05:44:10 +11:00
|
|
|
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 )
|
2020-03-25 14:02:06 +11:00
|
|
|
chkPS,
|
2020-03-25 05:44:10 +11:00
|
|
|
DE PUSHqq, ( C )
|
|
|
|
HL PUSHqq, ( D )
|
|
|
|
IY PUSHqq, ( A )
|
|
|
|
BC PUSHqq, ( B )
|
|
|
|
;CODE
|
2020-03-25 04:46:05 +11:00
|
|
|
|
2020-03-25 13:09:52 +11:00
|
|
|
CODE AND
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
A E LDrr,
|
|
|
|
L ANDr,
|
|
|
|
L A LDrr,
|
|
|
|
A D LDrr,
|
|
|
|
H ANDr,
|
|
|
|
H A LDrr,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
2020-03-26 08:07:15 +11:00
|
|
|
|
2020-03-26 08:18:29 +11:00
|
|
|
CODE OR
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
A E LDrr,
|
|
|
|
L ORr,
|
|
|
|
L A LDrr,
|
|
|
|
A D LDrr,
|
|
|
|
H ORr,
|
|
|
|
H A LDrr,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-26 08:24:46 +11:00
|
|
|
CODE XOR
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
A E LDrr,
|
|
|
|
L XORr,
|
|
|
|
L A LDrr,
|
|
|
|
A D LDrr,
|
|
|
|
H XORr,
|
|
|
|
H A LDrr,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-27 05:36:14 +11:00
|
|
|
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
|
|
|
|
|
2020-03-26 13:51:23 +11:00
|
|
|
( Borrowed from http://wikiti.brandonw.net/ )
|
|
|
|
( Divides AC by DE and places the quotient in AC and the
|
|
|
|
remainder in HL )
|
|
|
|
CODE /MOD
|
|
|
|
DE POPqq,
|
|
|
|
BC POPqq,
|
|
|
|
chkPS,
|
|
|
|
A B LDrr,
|
|
|
|
B 16 LDrn,
|
|
|
|
HL 0 LDddnn,
|
|
|
|
( loop )
|
|
|
|
SCF,
|
|
|
|
C RLr,
|
|
|
|
RLA,
|
|
|
|
HL ADCHLss,
|
|
|
|
DE SBCHLss,
|
|
|
|
4 JRNCe, ( skip )
|
|
|
|
DE ADDHLss,
|
|
|
|
C DECr,
|
|
|
|
( skip )
|
|
|
|
0 12 - DJNZe, ( loop )
|
|
|
|
B A LDrr,
|
|
|
|
HL PUSHqq,
|
|
|
|
BC PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-26 08:52:51 +11:00
|
|
|
CODE C!
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
E LD(HL)r,
|
|
|
|
;CODE
|
|
|
|
|
|
|
|
CODE C@
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
L LDr(HL),
|
|
|
|
H 0 LDrn,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-26 08:07:15 +11:00
|
|
|
CODE PC!
|
|
|
|
BC POPqq,
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
L OUT(C)r,
|
|
|
|
;CODE
|
2020-03-26 08:13:10 +11:00
|
|
|
|
|
|
|
CODE PC@
|
|
|
|
BC POPqq,
|
|
|
|
chkPS,
|
|
|
|
H 0 LDrn,
|
|
|
|
L INr(C),
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
2020-03-27 05:11:22 +11:00
|
|
|
|
|
|
|
CODE I
|
|
|
|
L 0 IX+ LDrIXY,
|
|
|
|
H 1 IX+ LDrIXY,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
|
|
|
CODE I'
|
|
|
|
L 2 IX- LDrIXY,
|
|
|
|
H 1 IX- LDrIXY,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
|
|
|
CODE J
|
|
|
|
L 4 IX- LDrIXY,
|
|
|
|
H 3 IX- LDrIXY,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|