1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-26 17:58:05 +11:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Virgil Dupras
0b8c8c9ca0 recipes/trs80: still wip... 2020-04-28 10:12:16 -04:00
Virgil Dupras
61b2e02351 xcomp: remove XOFF and use ORG and BIN( instead 2020-04-28 09:37:00 -04:00
Virgil Dupras
838548843e boot: apply BIN( to stray stable ABI references
With cross compiling and IMMEDIATE words, things get icky with stable
ABI references. For the same reason that EXIT, (br) and (br?) need to
stay at stable offsets, these word references will not have BIN(
properly applied at Inner core xcomp.

The solution for now is to adjust during EXECUTE, which is ugly and
inefficient, but I don't see a better solution right now.
2020-04-28 08:52:47 -04:00
Virgil Dupras
4501313410 Add [IF] .. [THEN]
Will be useful as kinds of "#ifdef"s during xcomp.
2020-04-28 08:28:59 -04:00
Virgil Dupras
f97df4614e recipes/trs80: wip 2020-04-28 07:51:41 -04:00
20 changed files with 96 additions and 69 deletions

View File

@ -7,10 +7,10 @@ context, branching doesn't work.
f IF A ELSE B THEN: if f is true, execute A, if false, execute
B. ELSE is optional.
[IF] .. [THEN]: Meta-IF. Works outside definitions. No [ELSE].
BEGIN .. f UNTIL: if f is false, branch to BEGIN.
BEGIN .. AGAIN: Always branch to BEGIN.
x y DO .. LOOP: LOOP increments y. if y != x, branch to DO.
x CASE y OF A ENDOF z OF B ENDOF C ENDCASE: If x == y, execute
A, if x == z, execute B. Otherwise, execute C. x is dropped
in case of an OF match, *but it is kept if it reaches C*. You
have to consume it to avoid PSP leak. (cont.)
(cont.)

11
blk/043
View File

@ -1,4 +1,8 @@
(cont.)
x CASE y OF A ENDOF z OF B ENDOF C ENDCASE: If x == y, execute
A, if x == z, execute B. Otherwise, execute C. x is dropped
in case of an OF match, *but it is kept if it reaches C*. You
have to consume it to avoid PSP leak.
(br) -- Branches by the number specified in the 2
following bytes. Can be negative.
(?br) f -- Branch if f is false.
@ -9,8 +13,3 @@
ABORT -- Resets PS and RS and returns to interpreter.
ABORT" x" -- *I* Compiles a ." followed by a ABORT.
EXECUTE a -- Execute wordref at addr a
INTERPRET -- Get a line from stdin, compile it in tmp memory,
then execute the compiled contents.
LEAVE -- In a DO..LOOP, exit at the next LOOP call.
QUIT -- Return to interpreter prompt immediately
EXIT! -- Exit current INTERPRET loop.

5
blk/044 Normal file
View File

@ -0,0 +1,5 @@
INTERPRET -- Get a line from stdin, compile it in tmp memory,
then execute the compiled contents.
LEAVE -- In a DO..LOOP, exit at the next LOOP call.
QUIT -- Return to interpreter prompt immediately
EXIT! -- Exit current INTERPRET loop.

8
blk/160 Normal file
View File

@ -0,0 +1,8 @@
TRS-80 Drivers
Drivers for the TRS-80 keyboard, video and floppy. At the
moment, they are thin layer over the drivers provided by
TRSDOS' SVC.
Load the Z80 words with "162 LOAD" and the high level part
with "164 LOAD".

13
blk/162 Normal file
View File

@ -0,0 +1,13 @@
CODE KEY
A 0x01 LDrn, ( @KEY )
0x28 RSTn,
L A LDrr, H 0 LDrn,
HL PUSHqq,
;CODE
CODE EMIT
BC POPqq, ( c == @DSP arg )
chkPS,
A 0x02 LDrn, ( @DSP )
0x28 RSTn,
;CODE

View File

@ -3,7 +3,7 @@ OUT [nA, (C)r] IN [An, r(C)]
SET [br] RES [br] BIT [br]
RL [r] RLC [r] SLA [r] RLA RLCA
RR [r] RRC [r] SRL [r] RRA RRCA
CALL [nn] DJNZ
CALL [nn] RST [n] DJNZ
JP [nn, (HL), (IX), (IY)]
JR [, Z, NZ, C, NC]

View File

@ -1,16 +1,14 @@
( dd nn -- )
: LDdd(nn),
: LDdd(nn), ( dd nn -- )
0xed A,
SWAP <<4 0x4b OR A,
A,,
;
( nn dd -- )
: LD(nn)dd,
: LD(nn)dd, ( nn dd -- )
0xed A,
<<4 0x43 OR A,
A,,
;
: RSTn, 0xc7 OR A, ;
: JP(IX), IX DROP JP(HL), ;
: JP(IY), IY DROP JP(HL), ;

View File

@ -6,3 +6,4 @@
: PUSHZ, BC 0 LDddnn, IFZ, BC INCss, THEN, BC PUSHqq, ;
: HLZ, A H LDrr, L ORr, ;
: DEZ, A D LDrr, E ORr, ;
: LDDE(HL), E (HL) LDrr, HL INCss, D (HL) LDrr, ;

10
blk/260
View File

@ -2,7 +2,10 @@ Cross compilation program
This programs allows cross compilation of boot binary and
icore. Run "262 LOAD" right before your cross compilation and
then set XCURRENT to CURRENT and XCOFF to H@.
then set XCURRENT to CURRENT.
This unit depends on a properly initialized z80a with ORG and
BIN( set. That is how we determine compilation offsets.
This redefines defining words to achieve cross compilation.
The goal is two-fold:
@ -10,7 +13,4 @@ The goal is two-fold:
1. Add an offset to all word references in definitions.
2. Don't shadow important words we need right now.
Words overrides like ":", "IMMEDIATE" and "CODE" are not
automatically shadowed to allow the harmless inclusion of
this unit. This shadowing has to take place in your xcomp
configuration. (cont.)
(cont.)

View File

@ -1,6 +1,9 @@
(cont.)
See example in /emul/forth/xcomp.fs
Words overrides like ":", "IMMEDIATE" and "CODE" are not
automatically shadowed to allow the harmless inclusion of
this unit. This shadowing has to take place in your xcomp
configuration.
See example in /emul/xcomp.fs
Why limit ourselves to icore? Oh, I've tried cross-compiling
the whole shebang. I tried. And failed. Too dynamic.

View File

@ -1,5 +1,4 @@
VARIABLE XCURRENT
VARIABLE XOFF
: XCON XCURRENT CURRENT* ! ;
: XCOFF 0x02 RAM+ CURRENT* ! ;

View File

@ -4,7 +4,7 @@
XCURRENT @ SWAP ( xcur w ) _find ( a f )
IF ( a )
DUP IMMED? IF ABORT THEN
DUP XOFF @ > IF XOFF @ - THEN ,
DUP ORG @ > IF ORG @ - BIN( @ + THEN ,
ELSE ( w )
0x02 RAM+ @ SWAP ( cur w ) _find ( a f )
IF DUP IMMED? NOT IF ABORT THEN EXECUTE

11
blk/301
View File

@ -1,7 +1,10 @@
L3 BSET
PC ORG @ 0x34 + ! ( execute )
( DE points to wordref )
EXDEHL,
L3 BSET PC ORG @ 0x34 + ! ( execute )
EXDEHL, ( HL now points to wordref )
( We don't apply BIN( reliably on stable ABI stuff, we
might need to adjust addr. Ugly, but well... )
BIN( @ [IF]
A XORr, H ORr, IFZ, H BIN( @ 256 / LDrn,
[THEN]
E (HL) LDrr,
D BIN( @ 256 / LDrn,
EXDEHL,

10
blk/302
View File

@ -1,16 +1,12 @@
L1 BSET
PC ORG @ 0x0f + ! ( compiledWord )
L1 BSET PC ORG @ 0x0f + ! ( compiledWord )
( 1. Push current IP to RS
2. Set new IP to the second atom of the list
3. Execute the first atom of the list. )
IY PUSHqq, HL POPqq, ( <-- IP )
0x11 BCALL, ( 11 == pushRS )
EXDEHL, ( HL points to PFA )
( While we increase, dereference into DE for execute call
later. )
E (HL) LDrr,
HL INCss,
D (HL) LDrr,
( While we inc, dereference into DE for execute call later. )
LDDE(HL),
HL INCss,
HL PUSHqq, IY POPqq, ( --> IP )
JR, L3 BWR ( execute-B301 )

View File

@ -6,3 +6,7 @@
H@ 2- ( push a. -2 for allot offset )
; IMMEDIATE
: [IF]
IF EXIT THEN
LIT< [THEN] BEGIN DUP WORD S= UNTIL DROP ;
: [THEN] ;

Binary file not shown.

View File

@ -10,12 +10,11 @@
CURRENT @ XCURRENT !
H@ 256 /MOD 2 PC! 2 PC!
H@ XOFF !
282 LOAD ( boot.z80 )
393 LOAD ( icore )
(entry) _
( Update LATEST )
H@ XOFF @ - XOFF @ 8 + !
PC ORG @ 8 + !
," CURRENT @ HERE ! "
," : EMIT 0 PC! ; "
," : KEY 0 PC@ ; "

View File

@ -16,14 +16,13 @@ RAMSTART 0x70 + CONSTANT ACIA_MEM
CURRENT @ XCURRENT !
H@ 256 /MOD 2 PC! 2 PC!
H@ XOFF !
282 LOAD ( boot.z80 )
352 LOAD ( acia.z80 )
372 LOAD ( sdc.z80 )
393 LOAD ( icore )
(entry) _
( Update LATEST )
H@ XOFF @ - XOFF @ 8 + !
PC ORG @ 8 + !
422 441 XPACKR ( core cmp )
446 452 XPACKR ( parse )
358 360 XPACKR ( acia.fs )

View File

@ -1,30 +1,8 @@
SHELLAPPS = zasm ed
APPTARGETS = ${SHELLAPPS:%=cfsin/%}
CFSTARGETS = $(APPTARGETS) cfsin/user.h
TARGET = os.bin
BASEDIR = ../..
ZASM = $(BASEDIR)/emul/zasm/zasm
KERNEL = $(BASEDIR)/kernel
APPS = $(BASEDIR)/apps
CFSPACK = $(BASEDIR)/tools/cfspack/cfspack
TARGET = stage1.bin
EDIR = ../../emul
STAGE2 = $(EDIR)/stage2
.PHONY: all
all: $(TARGET) floppy.cfs
$(TARGET): glue.asm
$(ZASM) $(KERNEL) $(APPS) < glue.asm > $@
$(CFSPACK):
make -C $(BASEDIR)/tools/cfspack
floppy.cfs: $(CFSTARGETS) $(CFSPACK)
$(CFSPACK) cfsin > $@
$(APPTARGETS):
$(ZASM) $(KERNEL) $(APPS) user.h < $(APPS)/${@:cfsin/%=%}/glue.asm > $@
cfsin/user.h: user.h
cp user.h $@
.PHONY: clean
clean:
rm -f $(CFSTARGETS) floppy.cfs $(TARGET)
all: $(TARGET)
$(TARGET): xcomp.fs $(STAGE2)
cat xcomp.fs | $(STAGE2) > $@

22
recipes/trs80/xcomp.fs Normal file
View File

@ -0,0 +1,22 @@
0x6000 CONSTANT RAMSTART
0xf000 CONSTANT RS_ADDR
212 LOAD ( z80 assembler )
262 LOAD ( xcomp )
: CODE XCODE ;
: IMMEDIATE XIMM ;
: (entry) (xentry) ;
: : [ ' X: , ] ;
CURRENT @ XCURRENT !
H@ 256 /MOD 2 PC! 2 PC!
0x3000 BIN( !
282 LOAD ( boot.z80 )
162 LOAD ( trs80.z80 )
393 LOAD ( icore )
(entry) _
( Update LATEST )
PC ORG @ 8 + !
422 463 XPACKR ( core cmp print parse readln fmt )
," : _ RDLN$ (ok) ; _ "
H@ 256 /MOD 2 PC! 2 PC!