-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemblematics.html
More file actions
434 lines (371 loc) · 16.9 KB
/
emblematics.html
File metadata and controls
434 lines (371 loc) · 16.9 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-W11-4 02:12 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Emblematics</title>
<meta name="author" content="Inanna" />
<meta name="description" content="A game" />
<meta name="generator" content="Org Mode" />
<link href="/site.css" rel="stylesheet" type="text/css" /><link href="images/website-icon.png" rel="icon" />
</head>
<body>
<div id="preamble" class="status">
<div><a href="/index.html"><img alt="An abstract logo representing a series of three assembly line stamping machines with the words CONS, DEV, and embalzoned in white on each machine." id="site-logo" src="/images/website-logo.png" /></a></div>
</div>
<div id="content" class="content">
<h1 class="title">Emblematics
<br />
<span class="subtitle">A simple ARG based around computation.</span>
</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org1658d08">Introduction</a></li>
<li><a href="#org3b52427">ATTENTION, SPOILERS AHEAD</a></li>
<li><a href="#org6f50658">Machine Language and Architecture</a>
<ul>
<li><a href="#org4f94d8e">Registers</a></li>
<li><a href="#org103eb68">Memory Tags</a></li>
<li><a href="#org329da97">Instruction Set Architecture</a>
<ul>
<li><a href="#org78492be">Processing Instructions</a></li>
<li><a href="#org1427680">Microcode</a></li>
<li><a href="#org16f80a0">definstruction macro</a></li>
<li><a href="#orgb517efb">SYMBOL</a></li>
<li><a href="#org93431f7">VHEAD</a></li>
<li><a href="#orge9de901">CONS</a></li>
</ul>
</li>
<li><a href="#org2333647">Memory</a></li>
<li><a href="#org3badb42">Process Isolation</a></li>
<li><a href="#orgab37722">Virtual Pages</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org1658d08" class="outline-2">
<h2 id="org1658d08">Introduction</h2>
<div class="outline-text-2" id="text-org1658d08">
<p>
Emblematics is a simple ARG based around a fictional LISP machine that is connected to the web. The game is implemented in Clojurescript and lives exclusively in the browser. This is the source code for it, and contains all the text in the game (so far). I might break it into multiple files eventually, and should that happen this will contain the core functionality of the game.
</p>
<p>
If you want to contribute to the game, please contact me on twitter <a href="https://twitter.com/cons_dev">@cons<sub>dev</sub></a>. I am willing to accept code or scripts as well.
</p>
</div>
</div>
<div id="outline-container-org3b52427" class="outline-2">
<h2 id="org3b52427">ATTENTION, SPOILERS AHEAD</h2>
<div class="outline-text-2" id="text-org3b52427">
<p>
This file is the source code of the game, therefore spoilers are ahead. You have been warned.
</p>
</div>
</div>
<div id="outline-container-org6f50658" class="outline-2">
<h2 id="org6f50658">Machine Language and Architecture</h2>
<div class="outline-text-2" id="text-org6f50658">
<p>
To implement the game I also implement a simple lisp machine. Sources used as inspiration include <a href="https://www.cs.utah.edu/~mflatt/past-courses/cs6510/public_html/lispm.pdf">this slideshow</a> on lisp machine architectures and <a href="https://core.ac.uk/download/pdf/225209295.pdf">this paper</a>, and of course the <a href="https://en.wikipedia.org/wiki/SECD_machine">SECD machine</a>. Overall the machine is
</p>
<p>
The emblematics operation system runs on a specialized hardware architecture using tagged bytes to ensure that.
</p>
<p>
This adds a type system to the assembly language as well as several other features to
</p>
</div>
<div id="outline-container-org4f94d8e" class="outline-3">
<h3 id="org4f94d8e">Registers</h3>
<div class="outline-text-3" id="text-org4f94d8e">
<p>
There are a number of registers
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Binary</th>
<th scope="col" class="org-left">Mnemonic</th>
<th scope="col" class="org-left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"> </td>
<td class="org-left">S</td>
<td class="org-left">Stack register, references head of list treated as stack in memory.</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">T</td>
<td class="org-left">Symbol table register, points to symbol table.</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">C</td>
<td class="org-left">References CONS cell whose CAR should be executed.</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">E</td>
<td class="org-left">Argument list register</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">D</td>
<td class="org-left">Dump register, points to previous values of E register</td>
</tr>
</tbody>
</table>
<pre class="example">
</pre>
</div>
</div>
<div id="outline-container-org103eb68" class="outline-3">
<h3 id="org103eb68">Memory Tags</h3>
<div class="outline-text-3" id="text-org103eb68">
<p>
All memory within Emblematics is tagged with a four bit code indicating the type of the object. Following that is a single byte containing
</p>
<table id="org4c9e5a5" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-right">Binary</th>
<th scope="col" class="org-left">Name</th>
<th scope="col" class="org-left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-right">0x43</td>
<td class="org-left">CONS</td>
<td class="org-left">cons cell (contains both CDR and CAR address)</td>
</tr>
<tr>
<td class="org-right">0x56</td>
<td class="org-left">VHEAD</td>
<td class="org-left">head of a vector, CAR contains vector size, CDR vector contents</td>
</tr>
<tr>
<td class="org-right">0x42</td>
<td class="org-left">BLTIN</td>
<td class="org-left">builtin function, basically an instruction</td>
</tr>
<tr>
<td class="org-right">0x53</td>
<td class="org-left">SYMBOL</td>
<td class="org-left">reference to SYMTAB</td>
</tr>
<tr>
<td class="org-right">0x57</td>
<td class="org-left">CHAR</td>
<td class="org-left">character in the Emblematics encoding</td>
</tr>
<tr>
<td class="org-right">0x5A</td>
<td class="org-left">INTEGER</td>
<td class="org-left">32 bit number</td>
</tr>
<tr>
<td class="org-right">0x52</td>
<td class="org-left">REAL</td>
<td class="org-left">floating point number</td>
</tr>
</tbody>
</table>
<p>
We also write
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span>println datatypes<span style="color: #494949;">)</span>
</pre>
</div>
<p>
A few little functions are defined to extract the memory cells and tags as well.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">get-tag</span> <span style="color: #bbb;">[</span>mem-cell<span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span>bit-shift-right mem-cell 36<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">get-refs</span> <span style="color: #bbb;">[</span>mem-cell<span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> <span style="color: #494949;">(</span>reduce #<span style="color: #bbb;">(</span>bit-clear <span style="font-style: italic;">%1</span> <span style="font-style: italic;">%2</span><span style="color: #bbb;">)</span> mem-cell <span style="color: #bbb;">(</span>range 36 40<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>bit-shift-right 35<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org329da97" class="outline-3">
<h3 id="org329da97">Instruction Set Architecture</h3>
<div class="outline-text-3" id="text-org329da97">
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Binary</th>
<th scope="col" class="org-left">Mnemonic</th>
<th scope="col" class="org-left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"> </td>
<td class="org-left">NOP</td>
<td class="org-left">No operation</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">PSH</td>
<td class="org-left">Push onto stack</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">POP</td>
<td class="org-left">Pop from the stack</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">APL</td>
<td class="org-left">Apply the first argument on the stack to the arglist pointed to by the second argument.</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left">RMV</td>
<td class="org-left">Remove top cell</td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left"> </td>
<td class="org-left"> </td>
</tr>
<tr>
<td class="org-left"> </td>
<td class="org-left"> </td>
<td class="org-left"> </td>
</tr>
</tbody>
</table>
</div>
<div id="outline-container-org78492be" class="outline-4">
<h4 id="org78492be">Processing Instructions</h4>
<div class="outline-text-4" id="text-org78492be">
<p>
To interpret instructions they are stored in a table with the binary representation of the instruction being the address of the function storing the instruction. Therefore to access the NOP instruction you simply access it at.
</p>
<p>
All instructions are offset by 0x42.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def</span> <span style="font-style: italic;">itable</span> <span style="color: #bbb;">(</span>make-array clojure.lang.Fn 256<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org1427680" class="outline-4">
<h4 id="org1427680">Microcode</h4>
<div class="outline-text-4" id="text-org1427680">
<p>
To define the various instructions some more atomic instructions are defined.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">stack-pop</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">stack-push</span><span style="color: #494949;">)</span>
<span style="color: #a4a4a4; font-style: italic;">;; </span><span style="color: #a4a4a4; font-style: italic;">apply a function to the arguments provided.</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defn</span> <span style="font-weight: bold; font-style: italic;">stack-apply</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org16f80a0" class="outline-4">
<h4 id="org16f80a0">definstruction macro</h4>
<div class="outline-text-4" id="text-org16f80a0">
<p>
To make the definition of instructions easy (and allow for more easily named values) I define a simple macro that registers an instruction with the instruction table and pushes and pops values from the stack automatically.
</p>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defmacro</span> <span style="font-weight: bold; font-style: italic;">definstruction</span> <span style="color: #bbb;">[</span>name bin-repr & body<span style="color: #bbb;">]</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #494949;">[</span>args <span style="color: #bbb;">(</span>first body<span style="color: #bbb;">)</span><span style="color: #494949;">]</span>
`<span style="color: #494949;">(</span>aset itable ~bin-repr
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">fn</span> ~name <span style="color: #494949;">[</span>mem<span style="color: #494949;">]</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> ~<span style="color: #bbb;">(</span>vec <span style="color: #494949;">(</span>mapcat <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">fn</span> <span style="color: #494949;">[</span>arg<span style="color: #494949;">]</span>
<span style="color: #494949;">[</span>arg <span style="color: #bbb;">(</span>stack-pop mem<span style="color: #bbb;">)</span><span style="color: #494949;">]</span><span style="color: #bbb;">)</span>
args<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
~@body<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">definstruction</span> <span style="font-weight: bold; font-style: italic;">nop</span> 0x0 <span style="color: #bbb;">[]</span> 0<span style="color: #494949;">)</span>
</pre>
</div>
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">definstruction</span> <span style="font-weight: bold; font-style: italic;">psh</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">definstruction</span> <span style="font-weight: bold; font-style: italic;">pop</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">definstruction</span> <span style="font-weight: bold; font-style: italic;">apl</span><span style="color: #494949;">)</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">definstruction</span> <span style="font-weight: bold; font-style: italic;">rmv</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb517efb" class="outline-4">
<h4 id="orgb517efb">SYMBOL</h4>
<div class="outline-text-4" id="text-orgb517efb">
<div class="org-src-container">
<pre class="src src-clojure"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def</span> <span style="font-style: italic;">SYMBOL</span> 0x01<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org93431f7" class="outline-4">
<h4 id="org93431f7">VHEAD</h4>
</div>
<div id="outline-container-orge9de901" class="outline-4">
<h4 id="orge9de901">CONS</h4>
<div class="outline-text-4" id="text-orge9de901">
<div class="org-src-container">
<pre class="src src-clojure">
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org2333647" class="outline-3">
<h3 id="org2333647">Memory</h3>
<div class="outline-text-3" id="text-org2333647">
<p>
Memory is addressed with.
</p>
</div>
</div>
<div id="outline-container-org3badb42" class="outline-3">
<h3 id="org3badb42">Process Isolation</h3>
<div class="outline-text-3" id="text-org3badb42">
<p>
Process are not isolated in Emblematics in the usual sense. Rather the system relies upon the properties of the LISP machine processor and language to ensure process isolation. Vectors cannot be addressed out of bounds,
</p>
</div>
</div>
<div id="outline-container-orgab37722" class="outline-3">
<h3 id="orgab37722">Virtual Pages</h3>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="date">Last Modified: 2022-W02-1 17:30</p><p class="creator">Generated Using: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 27.2 (<a href="https://orgmode.org">Org</a> mode 9.4.6)</p><p class="license">Except where otherwise noted content on <a href="https://cons.dev">cons.dev</a> is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/" rel="license">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p>
</div>
</body>
</html>