blob: d5548aa68ee81465354445079f60ad023e699474 [file] [log] [blame]
swissChili94f1e762022-01-29 21:55:45 -08001\documentclass[letterpaper,11pt,twocolumn]{article}
2\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}\usepackage[T1]{fontenc}
3\usepackage[utf8]{inputenc}
4\usepackage{lmodern}
5\usepackage{amsmath}
6\usepackage{amsfonts}
7\usepackage{amssymb}
8\usepackage{amsthm}
9\usepackage{graphicx}
10\usepackage{color}
11\usepackage{xcolor}
12\usepackage{url}
13\usepackage{textcomp}
14\usepackage{listings}
15\usepackage{glossaries}
16\usepackage{parskip}
17\usepackage{imakeidx}
18\usepackage{hyperref}
19
20\makeindex
21
22\title{DOS Forth Manual}
23\author{}
24\date{}
25
26\newcommand{\defword}[3]{\textbf{#1}\index{#1}\label{word:#1} #2 (#3)\quad}
27\newcommand{\then}{\text{-- }}
28\newenvironment{expl}{$\triangleright$}{}
29\newcommand{\wordref}[1]{\textbf{#1} \ref{word:#1}}
30
31\begin{document}
32
33\maketitle
34\tableofcontents
35
36\section{Words}
37
38\subsection{Stack manipulation}
39
40\defword{swap}{}{a b \then b a}
41
42\defword{dup}{}{a \then a a}
43
44\defword{drop}{}{a \then}
45
46\defword{nip}{}{a b \then b}
47
48\defword{2dup}{}{a b \then a b a b}
49
50\subsection{Logic and arithmetic}
51
52\defword{+}{}{a b \then a+b}
53
54\defword{-}{}{a b \then a-b}
55
56\defword{*}{}{a b \then a$\times$b}
57
58\defword{/mod}{}{a b \then rem quot}
59\begin{expl}
60 Rem is the remainder, quot is the quotient of a/b.
61\end{expl}
62
63\defword{and}{}{a b \then a\&b}
64\begin{expl}
65 Bitwise and.
66\end{expl}
67
68\defword{xor}{}{a b \then a\^b}
69\begin{expl}
70 Bitwise exclusive or.
71\end{expl}
72
73\subsection{Input and output}
74
75\defword{key}{}{ \then char}
76\begin{expl}
77 Char is the next ASCII character from the input.
78\end{expl}
79
80\defword{word}{}{ \then address length}
81\begin{expl}
82 Reads the next whitespace-terminated word from the input. Address is the address of the first byte, length is the length in bytes. The maximum length is 32 bytes.
83
84 Word uses a buffer which is reused every call. If you want the parsed string to persist after the next call you must copy it to your own buffer.
85\end{expl}
86
87\defword{number}{}{address length \then number unparsed}
88\begin{expl}
89 Parses the specified string as a base-10 number. Number is the parsed number as a cell, unparsed is the number of unparsed bytes, e.g. 0 if everything was parsed.
90\end{expl}
91
92\defword{.}{}{num \then}
93\begin{expl}
94 Writes number as a base-10 digit to the output.
95\end{expl}
96
97\defword{emit}{}{char \then}
98\begin{expl}
99 Writes the byte char to the output literally.
100\end{expl}
101
102\defword{cr}{}{ \then }
103\begin{expl}
104 Writes a carriate return followed by a newline to the output.
105\end{expl}
106
107\defword{space}{}{ \then }
108\begin{expl}
109 Writes an ASCII space to the output.
110\end{expl}
111
112\defword{type}{}{address length \then}
113\begin{expl}
114 Write the string of bytes starting at address of the specified length to the output. See also \wordref{word}.
115\end{expl}
116
117\defword{open-file-named}{}{flags address length \then handle}
118\begin{expl}
119 Opens the file specified by the string address and length with the given flags. \textit{TODO: document flags}. Handle is 0 if the file could not be opened.
120\end{expl}
121
122\defword{open-file}{name}{flags \then handle}
123\begin{expl}
124 Same as \wordref{open-file-named} but reads the name from the input at runtime.
125\end{expl}
126
127\defword{close-file}{}{handle \then}
128\begin{expl}
129 Closes the file specified by handle.
130\end{expl}
131
132\defword{f,}{}{cell handle \then}
133\begin{expl}
134 Writes cell (2 bytes) to the given file.
135\end{expl}
136
137\defword{fc,}{}{char handle \then}
138\begin{expl}
139 Writes the byte char to the given file.
140\end{expl}
141
142\defword{fwrite-range}{}{start-address end-address handle \then}
143\begin{expl}
144 Writes the memory range starting at start-address up to but not including end-address to the given file.
145\end{expl}
146
147\subsection{Dictionary}
148
149\defword{find}{}{address length \then entry}
150\begin{expl}
151 Finds the dictionary entry with the name string specified by address and length in the dictionary. Entry is the address of the first byte of the dictionary entry. See also \wordref{>cfa}, \wordref{>dfa}. Entry is zero if a suitable entry cannot be found.
152\end{expl}
153
154\defword{@}{}{address \then value}
155\begin{expl}
156 Gets the cell starting at address from memory.
157\end{expl}
158
159\defword{!}{}{value address \then}
160\begin{expl}
161 Sets the cell at address to value.
162\end{expl}
163
164\defword{c@}{}{address \then char}
165\begin{expl}
166 Gets the byte at address from memory.
167\end{expl}
168
169\defword{c!}{}{char address \then}
170\begin{expl}
171 Sets the byte at address to char.
172\end{expl}
173
174\defword{>cfa}{}{entry \then cfa}
175\begin{expl}
176 Gets the code field address for the given dictionary entry.
177\end{expl}
178
179\defword{>dfa}{}{entry \then cfa}
180\begin{expl}
181 Gets the data field address for the given dictionary entry.
182\end{expl}
183
184\defword{cmove}{}{from to length \then}
185\begin{expl}
186 Copy the string of bytes length long starting at from to to.
187\end{expl}
188
189\defword{round-even}{}{number \then even}
190\begin{expl}
191 Rounds number up until it is even. If it is already even returns it as is.
192\end{expl}
193
194\defword{cmove,}{}{from length \then}
195\begin{expl}
196 Moves the string of bytes length long starting at from to the top of the dictionary and offsets the here pointer.
197\end{expl}
198
199\defword{create}{name}{ \then}
200\begin{expl}
201 Creates a dictionary entry. Name is read from the input at runtime.
202\end{expl}
203
204\defword{,}{}{value \then}
205\begin{expl}
206 Writes the cell value to the top of the stack, adding 2 to the here pointer.
207\end{expl}
208
209\defword{c,}{}{char \then}
210\begin{expl}
211 Writes the byte char to the top of the stack, adding 1 to the here pointer.
212\end{expl}
213
214\defword{[}{}{ \then}
215\begin{expl}
216 Switches to interpret mode.
217\end{expl}
218
219\defword{]}{}{ \then}
220\begin{expl}
221 Immediately switches to compile mode.
222\end{expl}
223
224\defword{immediate}{}{ \then}
225\begin{expl}
226 Immediately toggles if the most recently defined dictionary word is immediate.
227\end{expl}
228
229\defword{hidden}{}{ \then}
230\begin{expl}
231 Toggles if the most recently defined dictionary word is hidden.
232\end{expl}
233
234\defword{hide}{name}{ \then}
235\begin{expl}
236 Reads a word from the input at runtime, looks it up in the dictionary, and toggles if it is hidden.
237\end{expl}
238
239\defword{tick}{name}{ \then cfa}
240\begin{expl}
241 Reads a word from the input at runtime, looks it up in the dictionary, and returns its code field address.
242\end{expl}
243
244\defword{word-type}{}{entry \then type}
245\begin{expl}
246 Returns the type of the word starting at entry. 0 if immediate, 1 if normal.
247\end{expl}
248
249\defword{interpret}{name}{ \then ?}
250\begin{expl}
251 Reads a word from the input at runtime and interprets it.
252\end{expl}
253
254\defword{quit}{}{ \then ?}
255\begin{expl}
256 Runs \wordref{interpret} repeatedly.
257\end{expl}
258
259\defword{:}{name}{ \then }
260\begin{expl}
261 Begins defining a word with the specified name. Switches to compiling state.
262\end{expl}
263
264\defword{;}{}{ \then }
265\begin{expl}
266 Finishes defining a word. Switches back to interpreting state.
267\end{expl}
268
269\defword{entry->name}{}{entry \then address length}
270\begin{expl}
271 Finds the name of the dictionary entry starting at entry.
272\end{expl}
273
274\defword{words}{}{ \then }
275\begin{expl}
276 Writes a list of the currently defined non-hidden words to the output.
277\end{expl}
278
279\defword{.s}{}{ \then }
280\begin{expl}
281 Displays the current content of the stack from bottom to top.
282\end{expl}
283
284\subsection{Images and executables}
285
286\defword{dump-image}{name}{ \then }
287\begin{expl}
288 Dumps the current Forth image in .COM format to the file with the specified name. This saves the entire contents of the dictionary, but not the stack.
289\end{expl}
290
291\section{License}
292
293Copyright \copyright{} 2022 \href{https://swisschili.sh}{swissChili}. This document is released under the terms of the \href{https://www.gnu.org/licenses/fdl-1.3.html}{GNU Free Documentation License}.
294
295\printindex
296\end{document}