-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel16d.dasm
156 lines (135 loc) · 5.23 KB
/
camel16d.dasm
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
; LISTING 3.
;
; ===============================================
; CamelForth for the Mojang DCPU-16 (http://0x10c.com)
; Copyright (c) 2012 Helge Horch
; CamelForth for the Zilog Z80
; Copyright (c) 1994,1995 Bradford J. Rodriguez
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
; Commercial inquiries should be directed to the author at
; 115 First St., #105, Collingwood, Ontario L9Y 4W3 Canada
; or via email to bj@camelforth.com
;
; ===============================================
; CAMEL16D.S: CPU and Model Dependencies
; Source code is for the ASM assembler.
; Forth words are documented as follows:
;* NAME stack -- stack description
; Word names in upper case are from the ANS
; Forth Core word set. Names in lower case are
; "internal" implementation words & extensions.
;
; Direct-Threaded Forth model for Mojang DCPU-16
; cell size is 16 bits (1 word)
; char size is 16 bits (1 word)
; address unit is 16 bits (1 word)
; ===============================================
; ALIGNMENT AND PORTABILITY OPERATORS ===========
; Many of these are synonyms for other words,
; and so are defined as CODE words.
;C ALIGN -- align HERE
head ALIGN,"ALIGN",docode
next
;C ALIGNED addr -- a-addr align given addr
head ALIGNED,"ALIGNED",docode
next
;Z CELL -- n size of one cell
head CELL,"CELL",docon
dw 1
;C CELL+ a-addr1 -- a-addr2 add cell size
; 1+ ;
head CELLPLUS,"CELL+",docode
add b,1
next
;C CELLS n1 -- n2 cells->adrs units
head CELLS,"CELLS",docode
next
;C CHAR+ c-addr1 -- c-addr2 add char size
head CHARPLUS,"CHAR+",docode
add b,1
next
;C CHARS n1 -- n2 chars->adrs units
head CHARS,"CHARS",docode
next
;C >BODY xt -- a-addr adrs of param field
; 2 + ; DCPU-16 (2 word JSR)
head TOBODY,">BODY",docode
add b,2
next
;X COMPILE, xt -- append execution token
; I called this word ,XT before I discovered that
; it is defined in the ANSI standard as COMPILE,.
; On a DTC Forth this simply appends xt (like , )
; but on an STC Forth this must append 'CALL xt'.
head COMMAXT,'COMPILE,',docode
set pc,COMMA
;Z !CF adrs cfa -- set code action of a word
; 7C20 OVER ! store 'JSR adrs' instr
; 1+ ! ; DCPU-16 VERSION
; Depending on the implementation this could
; append CALL adrs or JUMP adrs.
head STORECF,"!CF",docolon
DAT LIT,0x7c20,OVER,STORE
DAT ONEPLUS,STORE,EXIT
;Z ,CF adrs -- append a code field
; HERE !CF 2 ALLOT ; DCPU-16 VERSION (2 words)
head COMMACF,',CF',docolon
DAT HERE,STORECF,LIT,2,ALLOT,EXIT
;Z !COLON -- change code field to docolon
; -2 ALLOT docolon-adrs ,CF ;
; This should be used immediately after CREATE.
; This is made a distinct word, because on an STC
; Forth, colon definitions have no code field.
head STORCOLON,'!COLON',docolon
DAT LIT,-2,ALLOT
DAT LIT,docolon,COMMACF,EXIT
;Z ,EXIT -- append hi-level EXIT action
; ['] EXIT ,XT ;
; This is made a distinct word, because on an STC
; Forth, it appends a RET instruction, not an xt.
head CEXIT,',EXIT',docolon
DAT LIT,EXIT,COMMAXT,EXIT
; CONTROL STRUCTURES ============================
; These words allow Forth control structure words
; to be defined portably.
;Z ,BRANCH xt -- append a branch instruction
; xt is the branch operator to use, e.g. qbranch
; or (loop). It does NOT append the destination
; address. On the Z80 this is equivalent to ,XT.
head COMMABRANCH,',BRANCH',docode
set pc,COMMA
;Z ,DEST dest -- append a branch address
; This appends the given destination address to
; the branch instruction. On the Z80 this is ','
; ...other CPUs may use relative addressing.
head COMMADEST,',DEST',docode
set pc,COMMA
;Z !DEST dest adrs -- change a branch dest'n
; Changes the destination address found at 'adrs'
; to the given 'dest'. On the Z80 this is '!'
; ...other CPUs may need relative addressing.
head STOREDEST,'!DEST',docode
set pc,STORE
; HEADER STRUCTURE ==============================
; The structure of the Forth dictionary headers
; (name, link, immediate flag, and "smudge" bit)
; does not necessarily differ across CPUs. This
; structure is not easily factored into distinct
; "portable" words; instead, it is implicit in
; the definitions of FIND and CREATE, and also in
; NFA>LFA, NFA>CFA, IMMED?, IMMEDIATE, HIDE, and
; REVEAL. These words must be (substantially)
; rewritten if either the header structure or its
; inherent assumptions are changed.