-
Notifications
You must be signed in to change notification settings - Fork 24
/
gbforth.fs
108 lines (82 loc) · 2.08 KB
/
gbforth.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! /usr/bin/env gforth
\ -*- forth -*-
require ./src/vocabulary.fs
also gbforth definitions
also gbforth
require ./src/cli.fs
require ./src/rom.fs
require ./src/sym.fs
require ./src/asm.fs
require ./src/cartridge.fs
require ./src/runtime.fs
require ./src/compiler/cross.fs
also gb-assembler-impl
' romc, IS emit
' rom-offset IS offset
' romc! IS emit-to
previous
output-file to-symbol-file set-sym-file
s" ; Generated by gbforth " sym-write sym-cr sym-cr
: also-path-if-set ( addr u -- )
dup 0 > if
fpath also-path
else
2drop
then ;
fpath clear-path
gbforth-path also-path-if-set
fpath path+ .
fpath path+ ~+
require ./src/user.fs
( We want to load the input file sealed in the GBFORTH-USER
( vocabulary. The problem is that we do not want to populate this
vocabulary with auxiliary words to load the input-file.
Instead, we put all the words in this colon-definition to resolve
the word into addresses before we seal and load the game.
)
: assert-empty-stack
depth 0<> abort" Stack is not empty" ;
: assert-memory-fits
rom-unused 0< abort" ROM is full"
ram-unused 0< abort" WRAM is full" ;
: write-game
fix-header-complement
fix-global-checksum
output-file dump-rom ;
: %. swap 100 * swap / 1 .r ;
:noname
assert-empty-stack
gbforth-user definitions
seal also
--no-kernel invert if
s" ./lib/core.fs" required
then
--no-header invert if
ROM
s" ./lib/header.fs" included
RAM
then
input-file included
--no-kernel invert if
s" ./src/prelude.fs" included
then
assert-empty-stack
assert-memory-fits
write-game
--verbose if
CR CR
." \ " rom-offset 5 .r ." bytes written to " output-file type CR
." \ " rom-unused 5 .r ." bytes left, used "
rom-here rom-size %. ." % of ROM" CR CR
." \ " ram-here DP0 - 5 .r ." bytes allotted in memory" CR
." \ " ram-unused 5 .r ." bytes left, used "
ram-here DP0 - ram-size %. ." % of WRAM" CR
then
--debug if
also forth
also gbforth
else
bye
then
; execute
( Do not write any code after this! )