2020-03-24 13:46:05 -04: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.
|
|
|
|
|
|
|
|
These restrictions are temporary, I'll figure something out
|
|
|
|
so that we can end up fully bootstrap Forth from within
|
|
|
|
itself.
|
2020-03-26 12:05:48 -04:00
|
|
|
|
|
|
|
Oh, also: KEY and EMIT are not defined here. There're
|
|
|
|
expected to be defined in platform-specific code.
|
2020-04-02 11:39:40 -04:00
|
|
|
|
|
|
|
This unit expects the same conf as boot.fs.
|
2020-03-24 13:46:05 -04:00
|
|
|
)
|
|
|
|
|
2020-04-02 11:29:23 -04:00
|
|
|
( dummy entry for dict hook )
|
|
|
|
(entry) _
|
|
|
|
H@ 256 /MOD 2 PC! 2 PC!
|
|
|
|
|
2020-03-24 13:46:05 -04:00
|
|
|
( a b c -- b c a )
|
|
|
|
CODE ROT
|
|
|
|
HL POPqq, ( C )
|
|
|
|
DE POPqq, ( B )
|
|
|
|
BC POPqq, ( A )
|
2020-03-25 21:49:09 -04:00
|
|
|
chkPS,
|
2020-03-24 13:46:05 -04:00
|
|
|
DE PUSHqq, ( B )
|
|
|
|
HL PUSHqq, ( C )
|
|
|
|
BC PUSHqq, ( A )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 08:02:20 -04:00
|
|
|
( a -- a a )
|
|
|
|
CODE DUP
|
|
|
|
HL POPqq, ( A )
|
|
|
|
chkPS,
|
|
|
|
HL PUSHqq, ( A )
|
|
|
|
HL PUSHqq, ( A )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 13:57:06 -04:00
|
|
|
( a -- )
|
|
|
|
CODE DROP
|
|
|
|
HL POPqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 08:06:11 -04:00
|
|
|
( a b -- b a )
|
|
|
|
CODE SWAP
|
|
|
|
HL POPqq, ( B )
|
|
|
|
DE POPqq, ( A )
|
|
|
|
chkPS,
|
|
|
|
HL PUSHqq, ( B )
|
|
|
|
DE PUSHqq, ( A )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 07:58:16 -04:00
|
|
|
( a b -- a b a )
|
|
|
|
CODE OVER
|
|
|
|
HL POPqq, ( B )
|
|
|
|
DE POPqq, ( A )
|
|
|
|
chkPS,
|
|
|
|
DE PUSHqq, ( A )
|
|
|
|
HL PUSHqq, ( B )
|
|
|
|
DE PUSHqq, ( A )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-24 14:44:10 -04:00
|
|
|
( a b -- a b a b )
|
|
|
|
CODE 2DUP
|
|
|
|
HL POPqq, ( B )
|
|
|
|
DE POPqq, ( A )
|
2020-03-24 23:02:06 -04:00
|
|
|
chkPS,
|
2020-03-24 14:44:10 -04:00
|
|
|
DE PUSHqq, ( A )
|
|
|
|
HL PUSHqq, ( B )
|
|
|
|
DE PUSHqq, ( A )
|
|
|
|
HL PUSHqq, ( B )
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 13:54:46 -04:00
|
|
|
( a b -- )
|
|
|
|
CODE 2DROP
|
|
|
|
HL POPqq,
|
|
|
|
HL POPqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-24 14:44:10 -04:00
|
|
|
( 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-24 23:02:06 -04:00
|
|
|
chkPS,
|
2020-03-24 14:44:10 -04: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-24 23:02:06 -04:00
|
|
|
chkPS,
|
2020-03-24 14:44:10 -04:00
|
|
|
DE PUSHqq, ( C )
|
|
|
|
HL PUSHqq, ( D )
|
|
|
|
IY PUSHqq, ( A )
|
|
|
|
BC PUSHqq, ( B )
|
|
|
|
;CODE
|
2020-03-24 13:46:05 -04:00
|
|
|
|
2020-03-24 22:09:52 -04: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-25 17:07:15 -04:00
|
|
|
|
2020-03-25 17:18:29 -04: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-25 17:24:46 -04: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-30 17:26:51 -04:00
|
|
|
CODE NOT
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
A L LDrr,
|
|
|
|
H ORr,
|
|
|
|
HL 0 LDddnn,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNZ, L1 FWR ( skip )
|
2020-03-30 17:26:51 -04:00
|
|
|
( false, make 1 )
|
|
|
|
HL INCss,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 FSET ( skip )
|
2020-03-30 17:26:51 -04:00
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-28 15:33:14 -04:00
|
|
|
CODE +
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
DE ADDHLss,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-27 11:36:58 -04:00
|
|
|
CODE -
|
|
|
|
DE POPqq,
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
A ORr,
|
|
|
|
DE SBCHLss,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-26 14:36:14 -04: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,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNC, 4 A, ( noinc )
|
2020-03-26 14:36:14 -04:00
|
|
|
BC ADDHLss,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNC, 1 A, ( noinc )
|
2020-03-26 14:36:14 -04:00
|
|
|
DE INCss,
|
|
|
|
( noinc )
|
|
|
|
A DECr,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNZ, -14 A, ( loop )
|
2020-03-26 14:36:14 -04:00
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-25 22:51:23 -04: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,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 BSET ( loop )
|
2020-03-25 22:51:23 -04:00
|
|
|
SCF,
|
|
|
|
C RLr,
|
|
|
|
RLA,
|
|
|
|
HL ADCHLss,
|
|
|
|
DE SBCHLss,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNC, L2 FWR ( skip )
|
2020-03-25 22:51:23 -04:00
|
|
|
DE ADDHLss,
|
|
|
|
C DECr,
|
2020-03-31 09:23:00 -04:00
|
|
|
L2 FSET ( skip )
|
|
|
|
DJNZ, L1 BWR ( loop )
|
2020-03-25 22:51:23 -04:00
|
|
|
B A LDrr,
|
|
|
|
HL PUSHqq,
|
|
|
|
BC PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 14:09:39 -04:00
|
|
|
CODE !
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
(HL) E LDrr,
|
|
|
|
HL INCss,
|
|
|
|
(HL) D LDrr,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 14:05:07 -04:00
|
|
|
CODE @
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
E (HL) LDrr,
|
|
|
|
HL INCss,
|
|
|
|
D (HL) LDrr,
|
|
|
|
EXDEHL,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-25 17:52:51 -04:00
|
|
|
CODE C!
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
2020-03-27 18:38:42 -04:00
|
|
|
(HL) E LDrr,
|
2020-03-25 17:52:51 -04:00
|
|
|
;CODE
|
|
|
|
|
|
|
|
CODE C@
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
2020-03-27 18:38:42 -04:00
|
|
|
L (HL) LDrr,
|
2020-03-25 17:52:51 -04:00
|
|
|
H 0 LDrn,
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-25 17:07:15 -04:00
|
|
|
CODE PC!
|
|
|
|
BC POPqq,
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
L OUT(C)r,
|
|
|
|
;CODE
|
2020-03-25 17:13:10 -04:00
|
|
|
|
|
|
|
CODE PC@
|
|
|
|
BC POPqq,
|
|
|
|
chkPS,
|
|
|
|
H 0 LDrn,
|
|
|
|
L INr(C),
|
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
2020-03-26 14:11:22 -04: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
|
2020-03-27 11:27:40 -04:00
|
|
|
|
|
|
|
CODE >R
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
2020-03-30 17:05:00 -04:00
|
|
|
( 17 == pushRS )
|
|
|
|
17 CALLnn,
|
2020-03-27 11:27:40 -04:00
|
|
|
;CODE
|
|
|
|
|
|
|
|
CODE R>
|
2020-03-30 17:05:00 -04:00
|
|
|
( 20 == popRS )
|
|
|
|
20 CALLnn,
|
2020-03-27 11:27:40 -04:00
|
|
|
HL PUSHqq,
|
|
|
|
;CODE
|
2020-03-27 21:36:05 -04:00
|
|
|
|
|
|
|
CODE IMMEDIATE
|
|
|
|
CURRENT LDHL(nn),
|
|
|
|
HL DECss,
|
|
|
|
7 (HL) SETbr,
|
|
|
|
;CODE
|
2020-03-27 21:58:24 -04:00
|
|
|
|
|
|
|
CODE IMMED?
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
HL DECss,
|
|
|
|
DE 0 LDddnn,
|
|
|
|
7 (HL) BITbr,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRZ, L1 FWR ( notset )
|
2020-03-27 21:58:24 -04:00
|
|
|
DE INCss,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 FSET ( notset )
|
2020-03-27 21:58:24 -04:00
|
|
|
DE PUSHqq,
|
|
|
|
;CODE
|
2020-03-28 10:11:52 -04:00
|
|
|
|
2020-03-28 10:14:27 -04:00
|
|
|
CODE BYE
|
|
|
|
HALT,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-28 10:11:52 -04:00
|
|
|
CODE (resSP)
|
2020-04-02 11:39:40 -04:00
|
|
|
( INITIAL_SP == RAM+0 )
|
|
|
|
SP RAMSTART LDdd(nn),
|
2020-03-28 10:11:52 -04:00
|
|
|
;CODE
|
2020-03-28 15:14:15 -04:00
|
|
|
|
2020-03-30 08:25:22 -04:00
|
|
|
CODE (resRS)
|
2020-04-02 11:39:40 -04:00
|
|
|
IX RS_ADDR LDddnn,
|
2020-03-30 08:25:22 -04:00
|
|
|
;CODE
|
|
|
|
|
2020-03-28 15:14:15 -04:00
|
|
|
CODE SCMP
|
|
|
|
DE POPqq,
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 BSET ( loop )
|
2020-03-31 08:02:40 -04:00
|
|
|
LDA(DE),
|
|
|
|
(HL) CPr,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNZ, L2 FWR ( not equal? break early to "end".
|
|
|
|
NZ is set. )
|
2020-03-31 08:02:40 -04:00
|
|
|
A ORr, ( if our char is null, stop )
|
|
|
|
HL INCss,
|
|
|
|
DE INCss,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNZ, L1 BWR ( loop )
|
|
|
|
L2 FSET ( end )
|
2020-03-30 17:05:00 -04:00
|
|
|
( 40 == flagsToBC )
|
|
|
|
40 CALLnn,
|
2020-03-28 15:14:15 -04:00
|
|
|
BC PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-28 15:18:25 -04:00
|
|
|
CODE CMP
|
|
|
|
HL POPqq,
|
|
|
|
DE POPqq,
|
|
|
|
chkPS,
|
|
|
|
A ORr, ( clear carry )
|
|
|
|
DE SBCHLss,
|
2020-03-30 17:05:00 -04:00
|
|
|
( 40 == flagsToBC )
|
|
|
|
40 CALLnn,
|
2020-03-28 15:18:25 -04:00
|
|
|
BC PUSHqq,
|
|
|
|
;CODE
|
|
|
|
|
2020-03-30 17:36:15 -04:00
|
|
|
CODE (find)
|
|
|
|
HL POPqq,
|
2020-03-30 17:59:30 -04:00
|
|
|
chkPS,
|
2020-03-30 17:36:15 -04:00
|
|
|
( 3 == find )
|
|
|
|
3 CALLnn,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRZ, L1 FWR ( found )
|
2020-03-30 17:36:15 -04:00
|
|
|
( not found )
|
|
|
|
HL PUSHqq,
|
|
|
|
DE 0 LDddnn,
|
|
|
|
DE PUSHqq,
|
|
|
|
JPNEXT,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 FSET ( found )
|
2020-03-30 17:36:15 -04:00
|
|
|
DE PUSHqq,
|
|
|
|
DE 1 LDddnn,
|
|
|
|
DE PUSHqq,
|
|
|
|
;CODE
|
2020-03-30 17:59:30 -04:00
|
|
|
|
|
|
|
CODE SCPY
|
|
|
|
HL POPqq,
|
|
|
|
chkPS,
|
|
|
|
DE HERE LDdd(nn),
|
|
|
|
B 0 LDrn,
|
2020-03-31 09:23:00 -04:00
|
|
|
L1 BSET ( loop )
|
2020-03-30 17:59:30 -04:00
|
|
|
A (HL) LDrr,
|
|
|
|
LD(DE)A,
|
|
|
|
HL INCss,
|
|
|
|
DE INCss,
|
|
|
|
B INCr,
|
|
|
|
A ORr,
|
2020-03-31 09:23:00 -04:00
|
|
|
JRNZ, L1 BWR ( loop )
|
2020-03-30 17:59:30 -04:00
|
|
|
DE A LD(dd)r
|
|
|
|
HERE DE LD(nn)dd,
|
|
|
|
;CODE
|