Skip to content

Commit

Permalink
[embed] DCPU-16 working with the new split main.ft
Browse files Browse the repository at this point in the history
  • Loading branch information
bshepherdson committed Nov 6, 2024
1 parent 5c45b7d commit b86523f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 83 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ VICE_C64_FLAGS ?= -nativemonitor \

# DCPU cinematic universe - DCPU-16, Risque-16, Mocha 86k
forth-dcpu16.bin: host/*.ft dcpu16/*.ft shared/*.ft
$(FORTH) dcpu16/main.ft dcpu16/disks.ft dcpu16/tail.ft \
-e 'S" forth-dcpu16.bin" dump bye'
$(FORTH) dcpu16/main.ft -e 'bye'

dcpu16: forth-dcpu16.bin
run-dcpu16: forth-dcpu16.bin
$(EMULATOR) -disk $(DCPU_DISK) forth-dcpu16.bin

forth-rq16.bin: host/*.ft rq16/*.ft shared/*.ft dcpu16/*
forth-rq16.bin: host/*.ft rq16/*.ft shared/*.ft dcpu16/*.ft
$(FORTH) rq16/main.ft dcpu16/disks.ft rq16/tail.ft \
-e 'S" forth-rq16.bin" dump bye'

Expand Down
4 changes: 1 addition & 3 deletions dcpu16/tail.ft → dcpu16/finalize.ft
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ host definitions
host latest var_latest tcode!
host data-there @ var_dp tcode!

\ The assembled image must be emitted with
\ S" filename" dump
\ but that's handled with -e in the Makefile
host tcforth-output dump-forth
81 changes: 6 additions & 75 deletions dcpu16/main.ft
Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
\ Entry point for metacompiling the portable kernel to DCPU-16.
\ Most of the heavy lifting is done in other files, this is just orchestrating.
\ Unified entry point for building the interactive Forth system on DCPU-16.

REQUIRE ../host/vocabularies.ft

host definitions

\ Metacompiler configuration =================================================
host REQUIRE ../host/configuration.ft \ Default interactive is fine.

interactive-forth!
16 config char-bits !
1 config cell-width !
1 config instr-width !

config little-endian? OFF

\ XXX: Playing with separate spaces.
\ separate-spaces!
\ config data-space-blank? ON

\ Target spaces ==============================================================
REQUIRE ../host/spaces.ft

' <be16@> IS <tc@*>
' <be16!> IS <tc!*>

$0 code-there ORG!
\ $4000 name-there ORG! $8000 name-there space>offset !
\ $6000 data-there ORG!


REQUIRE assembler.ft \ DCPU-16 assembler


host REQUIRE ../host/helpers.ft
host REQUIRE model.ft \ Add the DCPU-16 model words
host REQUIRE ../host/dictionary.ft
host REQUIRE ../host/mirrors.ft

?stack-clear

\ Now we have what we need to metacompile the CODE definitions at the heart of
\ the new kernel.
host REQUIRE kernel.ft

\ Overwrite the jump target of the entry code to be main.
\ The instruction is at $0000 and its target argument at $0001.
main 1 tcode!

\ The main part of the metacompiler
?stack-clear
host REQUIRE ../host/metacompiler.ft

\ Now an interleaved dance of shared and target-specific metacompiled code.
host REQUIRE ../shared/basics.ft
host REQUIRE branches.ft \ Target-specific branching helpers.
host REQUIRE ../shared/control-structures.ft
host REQUIRE ../shared/exceptions.ft
host REQUIRE model-target.ft
host REQUIRE ../shared/input.ft
host REQUIRE ../shared/core2.ft
host REQUIRE ../shared/refill.ft
host REQUIRE lib.ft \ Division etc. helpers
host REQUIRE hardware.ft \ Hardware handling
host REQUIRE screen.ft
host REQUIRE ../shared/output.ft
host REQUIRE ../shared/error-messages.ft
host REQUIRE intro.ft \ DCPU-16/Risque-16 HW init; intro msg
host REQUIRE ../shared/init.ft \ Shared init code.

\ NB: You should always include tail.ft as the last stage of your build.
\ It actually emits the assembled image.

\ Known-missing words ========================================================
\ Core: ENVIRONMENT? WORD
REQUIRE preamble.ft
host REQUIRE spaces.ft
host REQUIRE system.ft
host REQUIRE disks.ft
host REQUIRE finalize.ft
32 changes: 32 additions & 0 deletions dcpu16/preamble.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
\ Entry point for metacompiling the portable kernel to DCPU-16.
\ Most of the heavy lifting is done in other files, this is just orchestrating.

REQUIRE ../host/vocabularies.ft
REQUIRE ../host/helpers.ft

native definitions
[undefined] machine [IF]
DEFER machine
:noname S" dcpu16" ; IS machine
[THEN]

native DEFER tcforth-output
:noname ( -- c-addr u )
pad S" forth-" cat machine cat S" .bin" cat
pad tuck - ; IS tcforth-output

host definitions

\ Metacompiler configuration =================================================
host REQUIRE ../host/configuration.ft \ Default interactive is fine.

interactive-forth!
16 config char-bits !
1 config cell-width !
1 config instr-width !

config little-endian? OFF

\ XXX: Playing with separate spaces.
\ separate-spaces!
\ config data-space-blank? ON
8 changes: 8 additions & 0 deletions dcpu16/spaces.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\ Target spaces ==============================================================
REQUIRE ../host/spaces.ft

\ Address units are 16-bit values stored on the host as 2 bytes, big-endian.
' <be16@> IS <tc@*>
' <be16!> IS <tc!*>

$0 code-there ORG!
43 changes: 43 additions & 0 deletions dcpu16/system.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
REQUIRE assembler.ft \ DCPU-16 assembler

host REQUIRE ../host/helpers.ft
host REQUIRE model.ft \ Add the DCPU-16 model words
host REQUIRE ../host/dictionary.ft
host REQUIRE ../host/mirrors.ft

?stack-clear

\ Now we have what we need to metacompile the CODE definitions at the heart of
\ the new kernel.
host REQUIRE kernel.ft

\ Overwrite the jump target of the entry code to be main.
\ The instruction is at $0000 and the jump target is at $0001.
main 1 tcode!

\ The main part of the metacompiler
?stack-clear
host REQUIRE ../host/metacompiler.ft

\ Now an interleaved dance of shared and target-specific metacompiled code.
host REQUIRE ../shared/basics.ft
host REQUIRE branches.ft \ Target-specific branching helpers.
host REQUIRE ../shared/control-structures.ft
host REQUIRE ../shared/exceptions.ft
host REQUIRE model-target.ft
host REQUIRE ../shared/input.ft
host REQUIRE ../shared/core2.ft
host REQUIRE ../shared/refill.ft
host REQUIRE lib.ft \ Division etc. helpers
host REQUIRE hardware.ft \ Hardware handling
host REQUIRE screen.ft
host REQUIRE ../shared/output.ft
host REQUIRE ../shared/error-messages.ft
host REQUIRE intro.ft \ DCPU-16/Risque-16 HW init; intro msg
host REQUIRE ../shared/init.ft \ Shared init code.

\ NB: You should always include tail.ft as the last stage of your build.
\ It actually emits the assembled image.

\ Known-missing words ========================================================
\ Core: ENVIRONMENT? WORD
4 changes: 3 additions & 1 deletion host/helpers.ft
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
host definitions
native definitions

\ Converts the name text to upper-case.
: >upper ( ch -- ch' ) dup 'a' 'z' 1+ within IF 'a' 'A' - - THEN ;

: ?stack-clear ( -- ) depth IF ." Stack not clear: " .s cr abort THEN ;

: cat ( dst src u -- dst' )
rot swap 2dup + >R move R> ;
2 changes: 1 addition & 1 deletion host/spaces.ft
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ DEFER <tc!*> ( tchar c-addr -- )
\ ." spaces order: "
\ all-spaces @ BEGIN ?dup WHILE dup space>org @ hex. space>next @ REPEAT cr ;

: dump ( c-addr u -- )
: dump-forth ( c-addr u -- )
cr cr ." Assembling to " 2dup type cr
\ .spaces

Expand Down

0 comments on commit b86523f

Please sign in to comment.