1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-28 00:48:06 +11:00
collapseos/forth/z80c.fs

366 lines
5.5 KiB
Forth
Raw Normal View History

( 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
2020-04-12 03:16:04 +10:00
you can put here. Those limitations are the same as those
described in icore.fs.
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.
This unit expects the same conf as boot.fs.
)
( a b c -- b c a )
CODE ROT
HL POPqq, ( C )
DE POPqq, ( B )
BC POPqq, ( A )
chkPS,
DE PUSHqq, ( B )
HL PUSHqq, ( C )
BC PUSHqq, ( A )
;CODE
2020-03-30 23:02:20 +11:00
( a -- a a )
CODE DUP
HL POPqq, ( A )
chkPS,
HL PUSHqq, ( A )
HL PUSHqq, ( A )
;CODE
2020-03-31 04:57:06 +11:00
( a -- )
CODE DROP
HL POPqq,
;CODE
2020-03-30 23:06:11 +11:00
( a b -- b a )
CODE SWAP
HL POPqq, ( B )
DE POPqq, ( A )
chkPS,
HL PUSHqq, ( B )
DE PUSHqq, ( A )
;CODE
2020-03-30 22:58:16 +11: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
( a b -- a b a b )
CODE 2DUP
HL POPqq, ( B )
DE POPqq, ( A )
2020-03-25 14:02:06 +11:00
chkPS,
DE PUSHqq, ( A )
HL PUSHqq, ( B )
DE PUSHqq, ( A )
HL PUSHqq, ( B )
;CODE
2020-03-31 04:54:46 +11:00
( a b -- )
CODE 2DROP
HL POPqq,
HL POPqq,
;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,
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,
DE PUSHqq, ( C )
HL PUSHqq, ( D )
IY PUSHqq, ( A )
BC PUSHqq, ( B )
;CODE
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-31 08:26:51 +11:00
CODE NOT
HL POPqq,
chkPS,
A L LDrr,
H ORr,
HL 0 LDddnn,
IFNZ, ( skip )
( false, make 1 )
HL INCss,
THEN, ( skip )
2020-03-31 08:26:51 +11:00
HL PUSHqq,
;CODE
2020-03-29 06:33:14 +11:00
CODE +
HL POPqq,
DE POPqq,
chkPS,
DE ADDHLss,
HL PUSHqq,
;CODE
2020-03-28 02:36:58 +11:00
CODE -
DE POPqq,
HL POPqq,
chkPS,
2020-04-14 09:31:23 +10:00
DE SUBHLss,
2020-03-28 02:36:58 +11:00
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,
JRNC, 4 A, ( noinc )
2020-03-27 05:36:14 +11:00
BC ADDHLss,
JRNC, 1 A, ( noinc )
2020-03-27 05:36:14 +11:00
DE INCss,
( noinc )
A DECr,
JRNZ, -14 A, ( loop )
2020-03-27 05:36:14 +11:00
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,
BEGIN, ( loop )
SCF,
C RLr,
RLA,
HL ADCHLss,
DE SBCHLss,
IFNC, ( skip )
DE ADDHLss,
C DECr,
THEN, ( skip )
DJNZ, AGAIN, ( loop )
2020-03-26 13:51:23 +11:00
B A LDrr,
HL PUSHqq,
BC PUSHqq,
;CODE
CODE !
2020-03-31 05:09:39 +11:00
HL POPqq,
DE POPqq,
chkPS,
(HL) E LDrr,
HL INCss,
(HL) D LDrr,
;CODE
CODE @
2020-03-31 05:05:07 +11:00
HL POPqq,
chkPS,
E (HL) LDrr,
HL INCss,
D (HL) LDrr,
2020-04-08 07:32:04 +10:00
DE PUSHqq,
2020-03-31 05:05:07 +11:00
;CODE
CODE C!
2020-03-26 08:52:51 +11:00
HL POPqq,
DE POPqq,
chkPS,
2020-03-28 09:38:42 +11:00
(HL) E LDrr,
2020-03-26 08:52:51 +11:00
;CODE
CODE C@
2020-03-26 08:52:51 +11:00
HL POPqq,
chkPS,
2020-03-28 09:38:42 +11:00
L (HL) LDrr,
2020-03-26 08:52:51 +11:00
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
2020-03-28 02:27:40 +11:00
CODE >R
HL POPqq,
chkPS,
( 17 == pushRS )
17 CALLnn,
2020-03-28 02:27:40 +11:00
;CODE
CODE R>
( 20 == popRS )
20 CALLnn,
2020-03-28 02:27:40 +11:00
HL PUSHqq,
;CODE
2020-03-28 12:36:05 +11:00
2020-03-29 01:14:27 +11:00
CODE BYE
HALT,
;CODE
2020-03-29 01:11:52 +11:00
CODE (resSP)
( INITIAL_SP == RAM+0 )
SP RAMSTART LDdd(nn),
2020-03-29 01:11:52 +11:00
;CODE
2020-03-29 06:14:15 +11:00
2020-03-30 23:25:22 +11:00
CODE (resRS)
IX RS_ADDR LDddnn,
2020-03-30 23:25:22 +11:00
;CODE
2020-03-29 06:14:15 +11:00
CODE SCMP
DE POPqq,
HL POPqq,
chkPS,
BEGIN, ( loop )
LDA(DE),
(HL) CPr,
JRNZ, L1 FWR ( not equal? break early to "end".
NZ is set. )
A ORr, ( if our char is null, stop )
HL INCss,
DE INCss,
JRNZ, AGAIN, ( loop )
L1 FSET ( end )
( 40 == flagsToBC )
40 CALLnn,
2020-03-29 06:14:15 +11:00
BC PUSHqq,
;CODE
CODE CMP
HL POPqq,
DE POPqq,
chkPS,
2020-04-14 09:31:23 +10:00
DE SUBHLss,
( 40 == flagsToBC )
40 CALLnn,
BC PUSHqq,
;CODE
( cur w -- a f )
CODE _find
HL POPqq, ( w )
DE POPqq, ( cur )
2020-03-31 08:59:30 +11:00
chkPS,
2020-03-31 08:36:15 +11:00
( 3 == find )
3 CALLnn,
IFZ, ( found )
( not found )
HL PUSHqq,
DE 0 LDddnn,
DE PUSHqq,
JPNEXT,
THEN, ( found )
2020-03-31 08:36:15 +11:00
DE PUSHqq,
DE 1 LDddnn,
DE PUSHqq,
;CODE
2020-03-31 08:59:30 +11:00
2020-04-03 14:21:53 +11:00
CODE (im1)
IM1,
EI,
;CODE