├── .gitignore
├── LICENSE.md
├── README.md
├── altera
├── ZMachine.bdf
├── ZMachine.qpf
├── ZMachine.qsf
├── ZMachine.qws
├── ZMachine.v
├── altpll0.bsf
├── altpll0.ppf
├── altpll0.qip
├── altpll0.v
├── altpll0_bb.v
├── boss.bsf
├── main.bsf
└── zmachine.sdc
├── benchmark
├── benchmark.inf
└── benchmark.txt
├── bios
├── bios.inf
├── combinedata.c
├── compressicon.c
├── encoding.txt
├── icons.h
├── makefont.c
├── touchscreeninfo.txt
├── zfont2.h
└── zfont2.xcf
├── emscripten
├── zops.data
├── zops.html
├── zops.html.mem
└── zops.js
├── gates.txt
├── instructions.md
├── utils
├── 16bitcolor.c
├── gradient.h
├── makegradient.c
├── screen.c
├── touchgenerator.c
└── zops.c
└── z3.vl
/.gitignore:
--------------------------------------------------------------------------------
1 | *.z3
2 | *.dat
3 | *.out
4 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Charles Cole
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | * Redistributions in binary form must reproduce the above copyright notice,
11 | this list of conditions and the following disclaimer in the documentation
12 | and/or other materials provided with the distribution.
13 |
14 | * Neither the name of Z3 nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Z3
2 | ==
3 |
4 | A Verilog implementation of the Infocom Z-Machine V3.
5 |
6 | Back in the very early 80s Infocom, the purveyor of very fine text based video games, when faced with the problems of porting their games to the plethora of home computers available back in the day invented a virtual machine optimised for running interactive fiction. Then interpreters were written for all the popular computers of the day so they could all run the same code.
7 |
8 | This virtual machine was never meant to be implemented in hardware although now thanks to cheap FPGAs it can be! The Z-Machine CPU is written in Verilog and included here. So using a Cyclone II EP2C5 FPGA (~$10), a TFT LCD Arduino Shield (~$3), 512Kb 8-bit flash (~$2), 128Kb 8-bit SRAM (~$2) and a ADC ($2) you too could have a functioning Z-Machine system.
9 |
10 | Check out the following YouTube video to see it in action...
11 |
12 | [](http://www.youtube.com/watch?v=HuQZq6DQQDY)
13 |
14 | The spec the Z3 follows is...
15 | http://inform-fiction.org/zmachine/standards/z1point0/index.html. Specifically version 3, the so called "Standard" games. These were released between 1982 and 1987 and covers most Infocom games.
16 |
17 | Z3 passes the "CZECH - Comprehensive Z-machine Emulation CHecker" by Amir Karger. And is known to run Zork I, Hitchhiker's Guide to the Galaxy, Planetfall and Curses (by Graham Nelson).
18 |
19 | To provide some input/output a terminal is implemented in a BIOS (in Z-machine code) which exists in the ROM above 120Kb. The IO related opcodes (like @print) vector into the BIOS which provides the terminal. A small number of extra op codes were added so the BIOS could interface with an LCD touchscreen.
20 |
21 | Save/Restore isn't currently supported (as my hardware hasn't any storage) and is the only notable omission.
22 |
23 | To compare the performance of the Z-Machine to other machines from around the same time. I ported the Dhrystone benchmark (and others) to Inform (a language for writing Z-Machine code). Using this benchmark the Z3 at 10MHz is around 0.93 DMIPS which is comparable to the performance of an Atari ST running native code.
24 |
25 | The BIOS contains two easter eggs. By typing "invade" a fairly complete Space Invaders clone will start. Also "mandelbrot" draws a mandelbrot fractal.
26 |
27 | For (very brief) instructions to build, check instructions.txt.
28 |
29 | *Nb. To save time while developing the BIOS I modified my existing Z-machine interpreter to support the Z3's extra opcodes, memory layout and peripherals so I could interate without having to remove and reflash the ROM. Thanks to Emscripten this Z3 emulator can now be [run in a any modern browser](http://charcole.github.io/Z3/emscripten/zops.html).*
30 |
31 | *Disclaimer: This is my first Verilog project so might not be written all that well*
32 |
--------------------------------------------------------------------------------
/altera/ZMachine.bdf:
--------------------------------------------------------------------------------
1 | /*
2 | WARNING: Do NOT edit the input and output ports in this file in a text
3 | editor if you plan to continue editing the block that represents it in
4 | the Block Editor! File corruption is VERY likely to occur.
5 | */
6 | /*
7 | Copyright (C) 1991-2013 Altera Corporation
8 | Your use of Altera Corporation's design tools, logic functions
9 | and other software and tools, and its AMPP partner logic
10 | functions, and any output files from any of the foregoing
11 | (including device programming or simulation files), and any
12 | associated documentation or information are expressly subject
13 | to the terms and conditions of the Altera Program License
14 | Subscription Agreement, Altera MegaCore Function License
15 | Agreement, or other applicable license agreement, including,
16 | without limitation, that your use is for the sole purpose of
17 | programming logic devices manufactured by Altera and sold by
18 | Altera or its authorized distributors. Please refer to the
19 | applicable agreement for further details.
20 | */
21 | (header "graphic" (version "1.4"))
22 | (pin
23 | (input)
24 | (rect -368 256 -200 272)
25 | (text "INPUT" (rect 125 0 154 10)(font "Arial" (font_size 6)))
26 | (text "osc_clk" (rect 5 0 43 11)(font "Arial" ))
27 | (pt 168 8)
28 | (drawing
29 | (line (pt 84 12)(pt 109 12))
30 | (line (pt 84 4)(pt 109 4))
31 | (line (pt 113 8)(pt 168 8))
32 | (line (pt 84 12)(pt 84 4))
33 | (line (pt 109 4)(pt 113 8))
34 | (line (pt 109 12)(pt 113 8))
35 | )
36 | (text "VCC" (rect 128 7 149 17)(font "Arial" (font_size 6)))
37 | (annotation_block (location)(rect -424 272 -368 288))
38 | )
39 | (pin
40 | (input)
41 | (rect 152 304 320 320)
42 | (text "INPUT" (rect 125 0 154 10)(font "Arial" (font_size 6)))
43 | (text "adcDout" (rect 5 0 47 11)(font "Arial" ))
44 | (pt 168 8)
45 | (drawing
46 | (line (pt 84 12)(pt 109 12))
47 | (line (pt 84 4)(pt 109 4))
48 | (line (pt 113 8)(pt 168 8))
49 | (line (pt 84 12)(pt 84 4))
50 | (line (pt 109 4)(pt 113 8))
51 | (line (pt 109 12)(pt 113 8))
52 | )
53 | (text "VCC" (rect 128 7 149 17)(font "Arial" (font_size 6)))
54 | (annotation_block (location)(rect 96 320 152 336))
55 | )
56 | (pin
57 | (input)
58 | (rect 152 320 320 336)
59 | (text "INPUT" (rect 125 0 154 10)(font "Arial" (font_size 6)))
60 | (text "reset" (rect 5 0 31 11)(font "Arial" ))
61 | (pt 168 8)
62 | (drawing
63 | (line (pt 84 12)(pt 109 12))
64 | (line (pt 84 4)(pt 109 4))
65 | (line (pt 113 8)(pt 168 8))
66 | (line (pt 84 12)(pt 84 4))
67 | (line (pt 109 4)(pt 113 8))
68 | (line (pt 109 12)(pt 113 8))
69 | )
70 | (text "VCC" (rect 128 7 149 17)(font "Arial" (font_size 6)))
71 | )
72 | (pin
73 | (output)
74 | (rect 560 304 736 320)
75 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
76 | (text "address[16..0]" (rect 90 0 160 11)(font "Arial" ))
77 | (pt 0 8)
78 | (drawing
79 | (line (pt 0 8)(pt 52 8))
80 | (line (pt 52 4)(pt 78 4))
81 | (line (pt 52 12)(pt 78 12))
82 | (line (pt 52 12)(pt 52 4))
83 | (line (pt 78 4)(pt 82 8))
84 | (line (pt 82 8)(pt 78 12))
85 | (line (pt 78 12)(pt 82 8))
86 | )
87 | (annotation_block (location)(rect 736 320 784 336))
88 | )
89 | (pin
90 | (output)
91 | (rect 560 320 736 336)
92 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
93 | (text "WE" (rect 90 0 110 11)(font "Arial" ))
94 | (pt 0 8)
95 | (drawing
96 | (line (pt 0 8)(pt 52 8))
97 | (line (pt 52 4)(pt 78 4))
98 | (line (pt 52 12)(pt 78 12))
99 | (line (pt 52 12)(pt 52 4))
100 | (line (pt 78 4)(pt 82 8))
101 | (line (pt 82 8)(pt 78 12))
102 | (line (pt 78 12)(pt 82 8))
103 | )
104 | (annotation_block (location)(rect 736 336 792 352))
105 | )
106 | (pin
107 | (output)
108 | (rect 560 368 736 384)
109 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
110 | (text "ramCS" (rect 90 0 125 11)(font "Arial" ))
111 | (pt 0 8)
112 | (drawing
113 | (line (pt 0 8)(pt 52 8))
114 | (line (pt 52 4)(pt 78 4))
115 | (line (pt 52 12)(pt 78 12))
116 | (line (pt 52 12)(pt 52 4))
117 | (line (pt 78 4)(pt 82 8))
118 | (line (pt 82 8)(pt 78 12))
119 | (line (pt 78 12)(pt 82 8))
120 | )
121 | (annotation_block (location)(rect 736 384 792 400))
122 | )
123 | (pin
124 | (output)
125 | (rect 560 352 736 368)
126 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
127 | (text "romCS" (rect 90 0 125 11)(font "Arial" ))
128 | (pt 0 8)
129 | (drawing
130 | (line (pt 0 8)(pt 52 8))
131 | (line (pt 52 4)(pt 78 4))
132 | (line (pt 52 12)(pt 78 12))
133 | (line (pt 52 12)(pt 52 4))
134 | (line (pt 78 4)(pt 82 8))
135 | (line (pt 82 8)(pt 78 12))
136 | (line (pt 78 12)(pt 82 8))
137 | )
138 | (annotation_block (location)(rect 736 368 792 384))
139 | )
140 | (pin
141 | (output)
142 | (rect 560 336 736 352)
143 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
144 | (text "PE" (rect 90 0 106 11)(font "Arial" ))
145 | (pt 0 8)
146 | (drawing
147 | (line (pt 0 8)(pt 52 8))
148 | (line (pt 52 4)(pt 78 4))
149 | (line (pt 52 12)(pt 78 12))
150 | (line (pt 52 12)(pt 52 4))
151 | (line (pt 78 4)(pt 82 8))
152 | (line (pt 82 8)(pt 78 12))
153 | (line (pt 78 12)(pt 82 8))
154 | )
155 | (annotation_block (location)(rect 736 352 792 368))
156 | )
157 | (pin
158 | (output)
159 | (rect 560 384 736 400)
160 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
161 | (text "led0" (rect 90 0 112 11)(font "Arial" ))
162 | (pt 0 8)
163 | (drawing
164 | (line (pt 0 8)(pt 52 8))
165 | (line (pt 52 4)(pt 78 4))
166 | (line (pt 52 12)(pt 78 12))
167 | (line (pt 52 12)(pt 52 4))
168 | (line (pt 78 4)(pt 82 8))
169 | (line (pt 82 8)(pt 78 12))
170 | (line (pt 78 12)(pt 82 8))
171 | )
172 | (annotation_block (location)(rect 736 400 784 416))
173 | )
174 | (pin
175 | (output)
176 | (rect 560 400 736 416)
177 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
178 | (text "led1" (rect 90 0 112 11)(font "Arial" ))
179 | (pt 0 8)
180 | (drawing
181 | (line (pt 0 8)(pt 52 8))
182 | (line (pt 52 4)(pt 78 4))
183 | (line (pt 52 12)(pt 78 12))
184 | (line (pt 52 12)(pt 52 4))
185 | (line (pt 78 4)(pt 82 8))
186 | (line (pt 82 8)(pt 78 12))
187 | (line (pt 78 12)(pt 82 8))
188 | )
189 | (annotation_block (location)(rect 736 416 784 432))
190 | )
191 | (pin
192 | (output)
193 | (rect 560 416 736 432)
194 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
195 | (text "led2" (rect 90 0 112 11)(font "Arial" ))
196 | (pt 0 8)
197 | (drawing
198 | (line (pt 0 8)(pt 52 8))
199 | (line (pt 52 4)(pt 78 4))
200 | (line (pt 52 12)(pt 78 12))
201 | (line (pt 52 12)(pt 52 4))
202 | (line (pt 78 4)(pt 82 8))
203 | (line (pt 82 8)(pt 78 12))
204 | (line (pt 78 12)(pt 82 8))
205 | )
206 | (annotation_block (location)(rect 736 432 784 448))
207 | )
208 | (pin
209 | (output)
210 | (rect 560 512 736 528)
211 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
212 | (text "A18" (rect 90 0 111 11)(font "Arial" ))
213 | (pt 0 8)
214 | (drawing
215 | (line (pt 0 8)(pt 52 8))
216 | (line (pt 52 4)(pt 78 4))
217 | (line (pt 52 12)(pt 78 12))
218 | (line (pt 52 12)(pt 52 4))
219 | (line (pt 78 4)(pt 82 8))
220 | (line (pt 82 8)(pt 78 12))
221 | (line (pt 78 12)(pt 82 8))
222 | )
223 | (annotation_block (location)(rect 736 528 792 544))
224 | )
225 | (pin
226 | (output)
227 | (rect 560 496 736 512)
228 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
229 | (text "A17" (rect 90 0 111 11)(font "Arial" ))
230 | (pt 0 8)
231 | (drawing
232 | (line (pt 0 8)(pt 52 8))
233 | (line (pt 52 4)(pt 78 4))
234 | (line (pt 52 12)(pt 78 12))
235 | (line (pt 52 12)(pt 52 4))
236 | (line (pt 78 4)(pt 82 8))
237 | (line (pt 82 8)(pt 78 12))
238 | (line (pt 78 12)(pt 82 8))
239 | )
240 | (annotation_block (location)(rect 736 512 792 528))
241 | )
242 | (pin
243 | (output)
244 | (rect 296 120 472 136)
245 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
246 | (text "romOE" (rect 90 0 126 11)(font "Arial" ))
247 | (pt 0 8)
248 | (drawing
249 | (line (pt 0 8)(pt 52 8))
250 | (line (pt 52 4)(pt 78 4))
251 | (line (pt 52 12)(pt 78 12))
252 | (line (pt 52 12)(pt 52 4))
253 | (line (pt 78 4)(pt 82 8))
254 | (line (pt 82 8)(pt 78 12))
255 | (line (pt 78 12)(pt 82 8))
256 | )
257 | (annotation_block (location)(rect 472 136 528 152))
258 | )
259 | (pin
260 | (output)
261 | (rect 296 56 472 72)
262 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
263 | (text "ramCE2" (rect 90 0 132 11)(font "Arial" ))
264 | (pt 0 8)
265 | (drawing
266 | (line (pt 0 8)(pt 52 8))
267 | (line (pt 52 4)(pt 78 4))
268 | (line (pt 52 12)(pt 78 12))
269 | (line (pt 52 12)(pt 52 4))
270 | (line (pt 78 4)(pt 82 8))
271 | (line (pt 82 8)(pt 78 12))
272 | (line (pt 78 12)(pt 82 8))
273 | )
274 | (annotation_block (location)(rect 472 72 528 88))
275 | )
276 | (pin
277 | (output)
278 | (rect 296 88 472 104)
279 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
280 | (text "ramOE" (rect 90 0 126 11)(font "Arial" ))
281 | (pt 0 8)
282 | (drawing
283 | (line (pt 0 8)(pt 52 8))
284 | (line (pt 52 4)(pt 78 4))
285 | (line (pt 52 12)(pt 78 12))
286 | (line (pt 52 12)(pt 52 4))
287 | (line (pt 78 4)(pt 82 8))
288 | (line (pt 82 8)(pt 78 12))
289 | (line (pt 78 12)(pt 82 8))
290 | )
291 | (annotation_block (location)(rect 472 104 528 120))
292 | )
293 | (pin
294 | (output)
295 | (rect 560 432 736 448)
296 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
297 | (text "lcdCS" (rect 90 0 120 11)(font "Arial" ))
298 | (pt 0 8)
299 | (drawing
300 | (line (pt 0 8)(pt 52 8))
301 | (line (pt 52 4)(pt 78 4))
302 | (line (pt 52 12)(pt 78 12))
303 | (line (pt 52 12)(pt 52 4))
304 | (line (pt 78 4)(pt 82 8))
305 | (line (pt 82 8)(pt 78 12))
306 | (line (pt 78 12)(pt 82 8))
307 | )
308 | (annotation_block (location)(rect 736 448 792 464))
309 | )
310 | (pin
311 | (output)
312 | (rect 560 448 736 464)
313 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
314 | (text "lcdRS" (rect 90 0 120 11)(font "Arial" ))
315 | (pt 0 8)
316 | (drawing
317 | (line (pt 0 8)(pt 52 8))
318 | (line (pt 52 4)(pt 78 4))
319 | (line (pt 52 12)(pt 78 12))
320 | (line (pt 52 12)(pt 52 4))
321 | (line (pt 78 4)(pt 82 8))
322 | (line (pt 82 8)(pt 78 12))
323 | (line (pt 78 12)(pt 82 8))
324 | )
325 | (annotation_block (location)(rect 736 464 792 480))
326 | )
327 | (pin
328 | (output)
329 | (rect 560 464 736 480)
330 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
331 | (text "lcdReset" (rect 90 0 134 11)(font "Arial" ))
332 | (pt 0 8)
333 | (drawing
334 | (line (pt 0 8)(pt 52 8))
335 | (line (pt 52 4)(pt 78 4))
336 | (line (pt 52 12)(pt 78 12))
337 | (line (pt 52 12)(pt 52 4))
338 | (line (pt 78 4)(pt 82 8))
339 | (line (pt 82 8)(pt 78 12))
340 | (line (pt 78 12)(pt 82 8))
341 | )
342 | (annotation_block (location)(rect 736 480 792 496))
343 | )
344 | (pin
345 | (output)
346 | (rect 296 32 472 48)
347 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
348 | (text "lcdRD" (rect 90 0 121 11)(font "Arial" ))
349 | (pt 0 8)
350 | (drawing
351 | (line (pt 0 8)(pt 52 8))
352 | (line (pt 52 4)(pt 78 4))
353 | (line (pt 52 12)(pt 78 12))
354 | (line (pt 52 12)(pt 52 4))
355 | (line (pt 78 4)(pt 82 8))
356 | (line (pt 82 8)(pt 78 12))
357 | (line (pt 78 12)(pt 82 8))
358 | )
359 | (annotation_block (location)(rect 472 48 528 64))
360 | )
361 | (pin
362 | (output)
363 | (rect 560 480 736 496)
364 | (text "OUTPUT" (rect 1 0 41 10)(font "Arial" (font_size 6)))
365 | (text "nadcCS" (rect 90 0 131 11)(font "Arial" ))
366 | (pt 0 8)
367 | (drawing
368 | (line (pt 0 8)(pt 52 8))
369 | (line (pt 52 4)(pt 78 4))
370 | (line (pt 52 12)(pt 78 12))
371 | (line (pt 52 12)(pt 52 4))
372 | (line (pt 78 4)(pt 82 8))
373 | (line (pt 82 8)(pt 78 12))
374 | (line (pt 78 12)(pt 82 8))
375 | )
376 | (annotation_block (location)(rect 736 496 792 512))
377 | )
378 | (pin
379 | (bidir)
380 | (rect 560 288 736 304)
381 | (text "BIDIR" (rect 1 0 28 10)(font "Arial" (font_size 6)))
382 | (text "data[7..0]" (rect 90 0 136 11)(font "Arial" ))
383 | (pt 0 8)
384 | (drawing
385 | (line (pt 56 4)(pt 78 4))
386 | (line (pt 0 8)(pt 52 8))
387 | (line (pt 56 12)(pt 78 12))
388 | (line (pt 78 4)(pt 82 8))
389 | (line (pt 78 12)(pt 82 8))
390 | (line (pt 56 4)(pt 52 8))
391 | (line (pt 52 8)(pt 56 12))
392 | )
393 | (text "VCC" (rect 4 7 25 17)(font "Arial" (font_size 6)))
394 | (annotation_block (location)(rect 736 304 792 320))
395 | )
396 | (symbol
397 | (rect 264 200 296 232)
398 | (text "GND" (rect 8 16 30 26)(font "Arial" (font_size 6)))
399 | (text "inst1" (rect 3 21 27 32)(font "Arial" )(invisible))
400 | (port
401 | (pt 16 0)
402 | (output)
403 | (text "1" (rect 18 0 26 11)(font "Courier New" (bold))(invisible))
404 | (text "1" (rect 18 0 26 11)(font "Courier New" (bold))(invisible))
405 | (line (pt 16 8)(pt 16 0))
406 | )
407 | (drawing
408 | (line (pt 8 8)(pt 16 16))
409 | (line (pt 16 16)(pt 24 8))
410 | (line (pt 8 8)(pt 24 8))
411 | )
412 | )
413 | (symbol
414 | (rect 264 16 296 32)
415 | (text "VCC" (rect 7 0 28 10)(font "Arial" (font_size 6)))
416 | (text "ramCE2_1" (rect 3 5 57 16)(font "Arial" )(invisible))
417 | (port
418 | (pt 16 16)
419 | (output)
420 | (text "1" (rect 19 7 27 18)(font "Courier New" (bold))(invisible))
421 | (text "1" (rect 19 7 27 18)(font "Courier New" (bold))(invisible))
422 | (line (pt 16 16)(pt 16 8))
423 | )
424 | (drawing
425 | (line (pt 8 8)(pt 24 8))
426 | )
427 | )
428 | (symbol
429 | (rect -184 200 72 352)
430 | (text "altpll0" (rect 111 0 153 16)(font "Arial" (font_size 10)))
431 | (text "inst2" (rect 8 137 32 148)(font "Arial" ))
432 | (port
433 | (pt 0 64)
434 | (input)
435 | (text "inclk0" (rect 0 0 34 13)(font "Arial" (font_size 8)))
436 | (text "inclk0" (rect 4 51 38 64)(font "Arial" (font_size 8)))
437 | (line (pt 0 64)(pt 40 64))
438 | )
439 | (port
440 | (pt 256 64)
441 | (output)
442 | (text "c0" (rect 0 0 15 13)(font "Arial" (font_size 8)))
443 | (text "c0" (rect 241 51 256 64)(font "Arial" (font_size 8)))
444 | )
445 | (port
446 | (pt 256 80)
447 | (output)
448 | (text "locked" (rect 0 0 37 13)(font "Arial" (font_size 8)))
449 | (text "locked" (rect 221 67 258 80)(font "Arial" (font_size 8)))
450 | )
451 | (drawing
452 | (text "Cyclone II" (rect 203 138 252 149)(font "Arial" ))
453 | (text "inclk0 frequency: 50.000 MHz" (rect 50 60 196 71)(font "Arial" ))
454 | (text "Operation Mode: Normal" (rect 50 72 172 83)(font "Arial" ))
455 | (text "Clk " (rect 51 91 71 102)(font "Arial" ))
456 | (text "Ratio" (rect 71 91 98 102)(font "Arial" ))
457 | (text "Ph (dg)" (rect 97 91 134 102)(font "Arial" ))
458 | (text "DC (%)" (rect 132 91 169 102)(font "Arial" ))
459 | (text "c0" (rect 54 104 66 115)(font "Arial" ))
460 | (text "1/5" (rect 76 104 92 115)(font "Arial" ))
461 | (text "0.00" (rect 103 104 126 115)(font "Arial" ))
462 | (text "50.00" (rect 136 104 165 115)(font "Arial" ))
463 | (line (pt 0 0)(pt 257 0))
464 | (line (pt 257 0)(pt 257 153))
465 | (line (pt 0 153)(pt 257 153))
466 | (line (pt 0 0)(pt 0 153))
467 | (line (pt 48 89)(pt 164 89))
468 | (line (pt 48 101)(pt 164 101))
469 | (line (pt 48 114)(pt 164 114))
470 | (line (pt 48 89)(pt 48 114))
471 | (line (pt 68 89)(pt 68 114)(line_width 3))
472 | (line (pt 94 89)(pt 94 114)(line_width 3))
473 | (line (pt 129 89)(pt 129 114)(line_width 3))
474 | (line (pt 163 89)(pt 163 114))
475 | (line (pt 40 48)(pt 207 48))
476 | (line (pt 207 48)(pt 207 135))
477 | (line (pt 40 135)(pt 207 135))
478 | (line (pt 40 48)(pt 40 135))
479 | (line (pt 255 64)(pt 207 64))
480 | (line (pt 255 80)(pt 207 80))
481 | )
482 | )
483 | (symbol
484 | (rect 96 248 160 296)
485 | (text "AND2" (rect 1 0 29 10)(font "Arial" (font_size 6)))
486 | (text "inst3" (rect 3 37 27 48)(font "Arial" ))
487 | (port
488 | (pt 0 16)
489 | (input)
490 | (text "IN1" (rect 2 7 23 18)(font "Courier New" (bold))(invisible))
491 | (text "IN1" (rect 2 7 23 18)(font "Courier New" (bold))(invisible))
492 | (line (pt 0 16)(pt 14 16))
493 | )
494 | (port
495 | (pt 0 32)
496 | (input)
497 | (text "IN2" (rect 2 23 23 34)(font "Courier New" (bold))(invisible))
498 | (text "IN2" (rect 2 23 23 34)(font "Courier New" (bold))(invisible))
499 | (line (pt 0 32)(pt 14 32))
500 | )
501 | (port
502 | (pt 64 24)
503 | (output)
504 | (text "OUT" (rect 48 15 69 26)(font "Courier New" (bold))(invisible))
505 | (text "OUT" (rect 48 15 69 26)(font "Courier New" (bold))(invisible))
506 | (line (pt 42 24)(pt 64 24))
507 | )
508 | (drawing
509 | (line (pt 14 12)(pt 30 12))
510 | (line (pt 14 37)(pt 31 37))
511 | (line (pt 14 12)(pt 14 37))
512 | (arc (pt 31 37)(pt 30 12)(rect 18 12 43 37))
513 | )
514 | )
515 | (symbol
516 | (rect 336 264 536 568)
517 | (text "boss" (rect 5 0 29 11)(font "Arial" ))
518 | (text "inst" (rect 8 288 26 299)(font "Arial" ))
519 | (port
520 | (pt 0 32)
521 | (input)
522 | (text "clk" (rect 0 0 15 11)(font "Arial" ))
523 | (text "clk" (rect 21 27 36 38)(font "Arial" ))
524 | (line (pt 0 32)(pt 16 32))
525 | )
526 | (port
527 | (pt 0 48)
528 | (input)
529 | (text "adcDout" (rect 0 0 42 11)(font "Arial" ))
530 | (text "adcDout" (rect 21 43 63 54)(font "Arial" ))
531 | (line (pt 0 48)(pt 16 48))
532 | )
533 | (port
534 | (pt 0 64)
535 | (input)
536 | (text "reset" (rect 0 0 25 11)(font "Arial" ))
537 | (text "reset" (rect 21 59 46 70)(font "Arial" ))
538 | (line (pt 0 64)(pt 16 64))
539 | )
540 | (port
541 | (pt 200 48)
542 | (output)
543 | (text "waddress[16..0]" (rect 0 0 77 11)(font "Arial" ))
544 | (text "waddress[16..0]" (rect 114 43 179 54)(font "Arial" ))
545 | (line (pt 200 48)(pt 184 48)(line_width 3))
546 | )
547 | (port
548 | (pt 200 64)
549 | (output)
550 | (text "we" (rect 0 0 15 11)(font "Arial" ))
551 | (text "we" (rect 167 59 179 70)(font "Arial" ))
552 | (line (pt 200 64)(pt 184 64))
553 | )
554 | (port
555 | (pt 200 80)
556 | (output)
557 | (text "pe" (rect 0 0 14 11)(font "Arial" ))
558 | (text "pe" (rect 168 75 179 86)(font "Arial" ))
559 | (line (pt 200 80)(pt 184 80))
560 | )
561 | (port
562 | (pt 200 96)
563 | (output)
564 | (text "romCS" (rect 0 0 35 11)(font "Arial" ))
565 | (text "romCS" (rect 150 91 179 102)(font "Arial" ))
566 | (line (pt 200 96)(pt 184 96))
567 | )
568 | (port
569 | (pt 200 112)
570 | (output)
571 | (text "ramCS" (rect 0 0 35 11)(font "Arial" ))
572 | (text "ramCS" (rect 150 107 179 118)(font "Arial" ))
573 | (line (pt 200 112)(pt 184 112))
574 | )
575 | (port
576 | (pt 200 128)
577 | (output)
578 | (text "led0" (rect 0 0 22 11)(font "Arial" ))
579 | (text "led0" (rect 161 123 179 134)(font "Arial" ))
580 | (line (pt 200 128)(pt 184 128))
581 | )
582 | (port
583 | (pt 200 144)
584 | (output)
585 | (text "led1" (rect 0 0 22 11)(font "Arial" ))
586 | (text "led1" (rect 161 139 179 150)(font "Arial" ))
587 | (line (pt 200 144)(pt 184 144))
588 | )
589 | (port
590 | (pt 200 160)
591 | (output)
592 | (text "led2" (rect 0 0 22 11)(font "Arial" ))
593 | (text "led2" (rect 161 155 179 166)(font "Arial" ))
594 | (line (pt 200 160)(pt 184 160))
595 | )
596 | (port
597 | (pt 200 176)
598 | (output)
599 | (text "lcdCS" (rect 0 0 30 11)(font "Arial" ))
600 | (text "lcdCS" (rect 154 171 179 182)(font "Arial" ))
601 | (line (pt 200 176)(pt 184 176))
602 | )
603 | (port
604 | (pt 200 192)
605 | (output)
606 | (text "lcdRS" (rect 0 0 30 11)(font "Arial" ))
607 | (text "lcdRS" (rect 154 187 179 198)(font "Arial" ))
608 | (line (pt 200 192)(pt 184 192))
609 | )
610 | (port
611 | (pt 200 208)
612 | (output)
613 | (text "lcdReset" (rect 0 0 44 11)(font "Arial" ))
614 | (text "lcdReset" (rect 142 203 179 214)(font "Arial" ))
615 | (line (pt 200 208)(pt 184 208))
616 | )
617 | (port
618 | (pt 200 224)
619 | (output)
620 | (text "nadcCS" (rect 0 0 41 11)(font "Arial" ))
621 | (text "nadcCS" (rect 145 219 179 230)(font "Arial" ))
622 | (line (pt 200 224)(pt 184 224))
623 | )
624 | (port
625 | (pt 200 240)
626 | (output)
627 | (text "a17" (rect 0 0 20 11)(font "Arial" ))
628 | (text "a17" (rect 163 235 179 246)(font "Arial" ))
629 | (line (pt 200 240)(pt 184 240))
630 | )
631 | (port
632 | (pt 200 256)
633 | (output)
634 | (text "a18" (rect 0 0 20 11)(font "Arial" ))
635 | (text "a18" (rect 163 251 179 262)(font "Arial" ))
636 | (line (pt 200 256)(pt 184 256))
637 | )
638 | (port
639 | (pt 200 32)
640 | (bidir)
641 | (text "data[7..0]" (rect 0 0 46 11)(font "Arial" ))
642 | (text "data[7..0]" (rect 143 27 189 38)(font "Arial" ))
643 | (line (pt 200 32)(pt 184 32)(line_width 3))
644 | )
645 | (drawing
646 | (rectangle (rect 16 16 184 288))
647 | )
648 | )
649 | (connector
650 | (pt 296 128)
651 | (pt 280 128)
652 | )
653 | (connector
654 | (pt 280 96)
655 | (pt 280 128)
656 | )
657 | (connector
658 | (pt 280 96)
659 | (pt 296 96)
660 | )
661 | (connector
662 | (pt 296 64)
663 | (pt 280 64)
664 | )
665 | (connector
666 | (pt 296 40)
667 | (pt 280 40)
668 | )
669 | (connector
670 | (pt 280 32)
671 | (pt 280 40)
672 | )
673 | (connector
674 | (pt 280 40)
675 | (pt 280 64)
676 | )
677 | (connector
678 | (pt 560 296)
679 | (pt 536 296)
680 | (bus)
681 | )
682 | (connector
683 | (pt 320 312)
684 | (pt 336 312)
685 | )
686 | (connector
687 | (pt 560 312)
688 | (pt 536 312)
689 | (bus)
690 | )
691 | (connector
692 | (pt 560 328)
693 | (pt 536 328)
694 | )
695 | (connector
696 | (pt 560 344)
697 | (pt 536 344)
698 | )
699 | (connector
700 | (pt 560 360)
701 | (pt 536 360)
702 | )
703 | (connector
704 | (pt 560 376)
705 | (pt 536 376)
706 | )
707 | (connector
708 | (pt 560 392)
709 | (pt 536 392)
710 | )
711 | (connector
712 | (pt 560 408)
713 | (pt 536 408)
714 | )
715 | (connector
716 | (pt 560 424)
717 | (pt 536 424)
718 | )
719 | (connector
720 | (pt 560 440)
721 | (pt 536 440)
722 | )
723 | (connector
724 | (pt 560 456)
725 | (pt 536 456)
726 | )
727 | (connector
728 | (pt 560 472)
729 | (pt 536 472)
730 | )
731 | (connector
732 | (pt 560 488)
733 | (pt 536 488)
734 | )
735 | (connector
736 | (pt 536 504)
737 | (pt 560 504)
738 | )
739 | (connector
740 | (pt 280 128)
741 | (pt 280 200)
742 | )
743 | (connector
744 | (pt 536 520)
745 | (pt 560 520)
746 | )
747 | (connector
748 | (pt -200 264)
749 | (pt -184 264)
750 | )
751 | (connector
752 | (pt 72 264)
753 | (pt 96 264)
754 | )
755 | (connector
756 | (pt 72 280)
757 | (pt 96 280)
758 | )
759 | (connector
760 | (pt 160 272)
761 | (pt 248 272)
762 | )
763 | (connector
764 | (pt 248 272)
765 | (pt 248 296)
766 | )
767 | (connector
768 | (pt 336 296)
769 | (pt 248 296)
770 | )
771 | (connector
772 | (pt 336 328)
773 | (pt 320 328)
774 | )
775 | (junction (pt 280 128))
776 | (junction (pt 280 40))
777 |
--------------------------------------------------------------------------------
/altera/ZMachine.qpf:
--------------------------------------------------------------------------------
1 | # -------------------------------------------------------------------------- #
2 | #
3 | # Copyright (C) 1991-2013 Altera Corporation
4 | # Your use of Altera Corporation's design tools, logic functions
5 | # and other software and tools, and its AMPP partner logic
6 | # functions, and any output files from any of the foregoing
7 | # (including device programming or simulation files), and any
8 | # associated documentation or information are expressly subject
9 | # to the terms and conditions of the Altera Program License
10 | # Subscription Agreement, Altera MegaCore Function License
11 | # Agreement, or other applicable license agreement, including,
12 | # without limitation, that your use is for the sole purpose of
13 | # programming logic devices manufactured by Altera and sold by
14 | # Altera or its authorized distributors. Please refer to the
15 | # applicable agreement for further details.
16 | #
17 | # -------------------------------------------------------------------------- #
18 | #
19 | # Quartus II 64-Bit
20 | # Version 13.0.1 Build 232 06/12/2013 Service Pack 1 SJ Web Edition
21 | # Date created = 21:16:13 September 09, 2014
22 | #
23 | # -------------------------------------------------------------------------- #
24 |
25 | QUARTUS_VERSION = "13.0"
26 | DATE = "21:16:13 September 09, 2014"
27 |
28 | # Revisions
29 |
30 | PROJECT_REVISION = "ZMachine"
31 |
--------------------------------------------------------------------------------
/altera/ZMachine.qsf:
--------------------------------------------------------------------------------
1 | # -------------------------------------------------------------------------- #
2 | #
3 | # Copyright (C) 1991-2013 Altera Corporation
4 | # Your use of Altera Corporation's design tools, logic functions
5 | # and other software and tools, and its AMPP partner logic
6 | # functions, and any output files from any of the foregoing
7 | # (including device programming or simulation files), and any
8 | # associated documentation or information are expressly subject
9 | # to the terms and conditions of the Altera Program License
10 | # Subscription Agreement, Altera MegaCore Function License
11 | # Agreement, or other applicable license agreement, including,
12 | # without limitation, that your use is for the sole purpose of
13 | # programming logic devices manufactured by Altera and sold by
14 | # Altera or its authorized distributors. Please refer to the
15 | # applicable agreement for further details.
16 | #
17 | # -------------------------------------------------------------------------- #
18 | #
19 | # Quartus II 64-Bit
20 | # Version 13.0.1 Build 232 06/12/2013 Service Pack 1 SJ Web Edition
21 | # Date created = 21:16:13 September 09, 2014
22 | #
23 | # -------------------------------------------------------------------------- #
24 | #
25 | # Notes:
26 | #
27 | # 1) The default values for assignments are stored in the file:
28 | # ZMachine_assignment_defaults.qdf
29 | # If this file doesn't exist, see file:
30 | # assignment_defaults.qdf
31 | #
32 | # 2) Altera recommends that you do not modify this file. This
33 | # file is updated automatically by the Quartus II software
34 | # and any changes you make may be lost or overwritten.
35 | #
36 | # -------------------------------------------------------------------------- #
37 |
38 |
39 | set_global_assignment -name FAMILY "Cyclone II"
40 | set_global_assignment -name DEVICE EP2C5T144C8
41 | set_global_assignment -name TOP_LEVEL_ENTITY ZMachine
42 | set_global_assignment -name ORIGINAL_QUARTUS_VERSION "13.0 SP1"
43 | set_global_assignment -name PROJECT_CREATION_TIME_DATE "21:16:13 SEPTEMBER 09, 2014"
44 | set_global_assignment -name LAST_QUARTUS_VERSION "13.0 SP1"
45 | set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
46 | set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
47 | set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
48 | set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 1
49 | set_global_assignment -name EDA_SIMULATION_TOOL "ModelSim-Altera (Verilog)"
50 | set_global_assignment -name EDA_OUTPUT_DATA_FORMAT "VERILOG HDL" -section_id eda_simulation
51 | set_global_assignment -name VERILOG_FILE ZMachine.v
52 | set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
53 | set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
54 | set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
55 | set_global_assignment -name BDF_FILE ZMachine.bdf
56 | set_global_assignment -name STRATIX_DEVICE_IO_STANDARD "3.3-V LVTTL"
57 | set_location_assignment PIN_142 -to address[16]
58 | set_location_assignment PIN_141 -to address[15]
59 | set_location_assignment PIN_48 -to address[14]
60 | set_location_assignment PIN_53 -to address[13]
61 | set_location_assignment PIN_139 -to address[12]
62 | set_location_assignment PIN_58 -to address[11]
63 | set_location_assignment PIN_60 -to address[10]
64 | set_location_assignment PIN_57 -to address[9]
65 | set_location_assignment PIN_55 -to address[8]
66 | set_location_assignment PIN_137 -to address[7]
67 | set_location_assignment PIN_136 -to address[6]
68 | set_location_assignment PIN_135 -to address[5]
69 | set_location_assignment PIN_134 -to address[4]
70 | set_location_assignment PIN_133 -to address[3]
71 | set_location_assignment PIN_132 -to address[2]
72 | set_location_assignment PIN_129 -to address[1]
73 | set_location_assignment PIN_126 -to address[0]
74 | set_location_assignment PIN_64 -to data[7]
75 | set_location_assignment PIN_65 -to data[6]
76 | set_location_assignment PIN_67 -to data[5]
77 | set_location_assignment PIN_69 -to data[4]
78 | set_location_assignment PIN_70 -to data[3]
79 | set_location_assignment PIN_121 -to data[2]
80 | set_location_assignment PIN_122 -to data[1]
81 | set_location_assignment PIN_125 -to data[0]
82 | set_location_assignment PIN_17 -to osc_clk
83 | set_location_assignment PIN_52 -to WE
84 | set_global_assignment -name PHYSICAL_SYNTHESIS_COMBO_LOGIC_FOR_AREA OFF
85 | set_global_assignment -name PHYSICAL_SYNTHESIS_MAP_LOGIC_TO_MEMORY_FOR_AREA OFF
86 | set_global_assignment -name PHYSICAL_SYNTHESIS_EFFORT NORMAL
87 | set_global_assignment -name POWER_PRESET_COOLING_SOLUTION "23 MM HEAT SINK WITH 200 LFPM AIRFLOW"
88 | set_global_assignment -name POWER_BOARD_THERMAL_MODEL "NONE (CONSERVATIVE)"
89 | set_location_assignment PIN_43 -to PE
90 | set_location_assignment PIN_63 -to ramCS
91 | set_location_assignment PIN_120 -to romCS
92 | set_global_assignment -name SDC_FILE zmachine.sdc
93 | set_global_assignment -name CYCLONEII_OPTIMIZATION_TECHNIQUE AREA
94 | set_global_assignment -name SMART_RECOMPILE ON
95 | set_global_assignment -name ADV_NETLIST_OPT_SYNTH_WYSIWYG_REMAP ON
96 | set_global_assignment -name AUTO_SHIFT_REGISTER_RECOGNITION ALWAYS
97 | set_location_assignment PIN_3 -to led0
98 | set_location_assignment PIN_7 -to led1
99 | set_location_assignment PIN_9 -to led2
100 | set_location_assignment PIN_143 -to A18
101 | set_location_assignment PIN_118 -to A17
102 | set_location_assignment PIN_119 -to romOE
103 | set_location_assignment PIN_51 -to ramCE2
104 | set_location_assignment PIN_59 -to ramOE
105 | set_location_assignment PIN_41 -to lcdCS
106 | set_location_assignment PIN_40 -to lcdReset
107 | set_location_assignment PIN_42 -to lcdRS
108 | set_location_assignment PIN_44 -to lcdRD
109 | set_location_assignment PIN_45 -to nadcCS
110 | set_location_assignment PIN_47 -to adcDout
111 | set_instance_assignment -name WEAK_PULL_UP_RESISTOR ON -to adcDout
112 | set_global_assignment -name QIP_FILE altpll0.qip
113 | set_location_assignment PIN_144 -to reset
114 | set_instance_assignment -name WEAK_PULL_UP_RESISTOR ON -to reset
115 | set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
--------------------------------------------------------------------------------
/altera/ZMachine.qws:
--------------------------------------------------------------------------------
1 | @( l a s t _ w o r k s p a c e
--------------------------------------------------------------------------------
/altera/altpll0.bsf:
--------------------------------------------------------------------------------
1 | /*
2 | WARNING: Do NOT edit the input and output ports in this file in a text
3 | editor if you plan to continue editing the block that represents it in
4 | the Block Editor! File corruption is VERY likely to occur.
5 | */
6 | /*
7 | Copyright (C) 1991-2013 Altera Corporation
8 | Your use of Altera Corporation's design tools, logic functions
9 | and other software and tools, and its AMPP partner logic
10 | functions, and any output files from any of the foregoing
11 | (including device programming or simulation files), and any
12 | associated documentation or information are expressly subject
13 | to the terms and conditions of the Altera Program License
14 | Subscription Agreement, Altera MegaCore Function License
15 | Agreement, or other applicable license agreement, including,
16 | without limitation, that your use is for the sole purpose of
17 | programming logic devices manufactured by Altera and sold by
18 | Altera or its authorized distributors. Please refer to the
19 | applicable agreement for further details.
20 | */
21 | (header "symbol" (version "1.2"))
22 | (symbol
23 | (rect 0 0 256 152)
24 | (text "altpll0" (rect 111 0 153 16)(font "Arial" (font_size 10)))
25 | (text "inst" (rect 8 137 26 148)(font "Arial" ))
26 | (port
27 | (pt 0 64)
28 | (input)
29 | (text "inclk0" (rect 0 0 34 13)(font "Arial" (font_size 8)))
30 | (text "inclk0" (rect 4 51 31 63)(font "Arial" (font_size 8)))
31 | (line (pt 0 64)(pt 40 64))
32 | )
33 | (port
34 | (pt 256 64)
35 | (output)
36 | (text "c0" (rect 0 0 15 13)(font "Arial" (font_size 8)))
37 | (text "c0" (rect 241 51 253 63)(font "Arial" (font_size 8)))
38 | )
39 | (port
40 | (pt 256 80)
41 | (output)
42 | (text "locked" (rect 0 0 37 13)(font "Arial" (font_size 8)))
43 | (text "locked" (rect 221 67 252 79)(font "Arial" (font_size 8)))
44 | )
45 | (drawing
46 | (text "Cyclone II" (rect 203 138 449 286)(font "Arial" ))
47 | (text "inclk0 frequency: 50.000 MHz" (rect 50 60 226 130)(font "Arial" ))
48 | (text "Operation Mode: Normal" (rect 50 72 203 154)(font "Arial" ))
49 | (text "Clk " (rect 51 91 117 192)(font "Arial" ))
50 | (text "Ratio" (rect 71 91 165 192)(font "Arial" ))
51 | (text "Ph (dg)" (rect 97 91 225 192)(font "Arial" ))
52 | (text "DC (%)" (rect 132 91 296 192)(font "Arial" ))
53 | (text "c0" (rect 54 104 119 218)(font "Arial" ))
54 | (text "1/5" (rect 76 104 166 218)(font "Arial" ))
55 | (text "0.00" (rect 103 104 225 218)(font "Arial" ))
56 | (text "50.00" (rect 136 104 296 218)(font "Arial" ))
57 | (line (pt 0 0)(pt 257 0))
58 | (line (pt 257 0)(pt 257 153))
59 | (line (pt 0 153)(pt 257 153))
60 | (line (pt 0 0)(pt 0 153))
61 | (line (pt 48 89)(pt 164 89))
62 | (line (pt 48 101)(pt 164 101))
63 | (line (pt 48 114)(pt 164 114))
64 | (line (pt 48 89)(pt 48 114))
65 | (line (pt 68 89)(pt 68 114)(line_width 3))
66 | (line (pt 94 89)(pt 94 114)(line_width 3))
67 | (line (pt 129 89)(pt 129 114)(line_width 3))
68 | (line (pt 163 89)(pt 163 114))
69 | (line (pt 40 48)(pt 207 48))
70 | (line (pt 207 48)(pt 207 135))
71 | (line (pt 40 135)(pt 207 135))
72 | (line (pt 40 48)(pt 40 135))
73 | (line (pt 255 64)(pt 207 64))
74 | (line (pt 255 80)(pt 207 80))
75 | )
76 | )
77 |
--------------------------------------------------------------------------------
/altera/altpll0.ppf:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/altera/altpll0.qip:
--------------------------------------------------------------------------------
1 | set_global_assignment -name IP_TOOL_NAME "ALTPLL"
2 | set_global_assignment -name IP_TOOL_VERSION "13.0"
3 | set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "altpll0.v"]
4 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "altpll0.bsf"]
5 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "altpll0_bb.v"]
6 | set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "altpll0.ppf"]
7 |
--------------------------------------------------------------------------------
/altera/altpll0.v:
--------------------------------------------------------------------------------
1 | // megafunction wizard: %ALTPLL%
2 | // GENERATION: STANDARD
3 | // VERSION: WM1.0
4 | // MODULE: altpll
5 |
6 | // ============================================================
7 | // File Name: altpll0.v
8 | // Megafunction Name(s):
9 | // altpll
10 | //
11 | // Simulation Library Files(s):
12 | // altera_mf
13 | // ============================================================
14 | // ************************************************************
15 | // THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
16 | //
17 | // 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
18 | // ************************************************************
19 |
20 |
21 | //Copyright (C) 1991-2013 Altera Corporation
22 | //Your use of Altera Corporation's design tools, logic functions
23 | //and other software and tools, and its AMPP partner logic
24 | //functions, and any output files from any of the foregoing
25 | //(including device programming or simulation files), and any
26 | //associated documentation or information are expressly subject
27 | //to the terms and conditions of the Altera Program License
28 | //Subscription Agreement, Altera MegaCore Function License
29 | //Agreement, or other applicable license agreement, including,
30 | //without limitation, that your use is for the sole purpose of
31 | //programming logic devices manufactured by Altera and sold by
32 | //Altera or its authorized distributors. Please refer to the
33 | //applicable agreement for further details.
34 |
35 |
36 | // synopsys translate_off
37 | `timescale 1 ps / 1 ps
38 | // synopsys translate_on
39 | module altpll0 (
40 | inclk0,
41 | c0,
42 | locked);
43 |
44 | input inclk0;
45 | output c0;
46 | output locked;
47 |
48 | wire [5:0] sub_wire0;
49 | wire sub_wire2;
50 | wire [0:0] sub_wire5 = 1'h0;
51 | wire [0:0] sub_wire1 = sub_wire0[0:0];
52 | wire c0 = sub_wire1;
53 | wire locked = sub_wire2;
54 | wire sub_wire3 = inclk0;
55 | wire [1:0] sub_wire4 = {sub_wire5, sub_wire3};
56 |
57 | altpll altpll_component (
58 | .inclk (sub_wire4),
59 | .clk (sub_wire0),
60 | .locked (sub_wire2),
61 | .activeclock (),
62 | .areset (1'b0),
63 | .clkbad (),
64 | .clkena ({6{1'b1}}),
65 | .clkloss (),
66 | .clkswitch (1'b0),
67 | .configupdate (1'b0),
68 | .enable0 (),
69 | .enable1 (),
70 | .extclk (),
71 | .extclkena ({4{1'b1}}),
72 | .fbin (1'b1),
73 | .fbmimicbidir (),
74 | .fbout (),
75 | .fref (),
76 | .icdrclk (),
77 | .pfdena (1'b1),
78 | .phasecounterselect ({4{1'b1}}),
79 | .phasedone (),
80 | .phasestep (1'b1),
81 | .phaseupdown (1'b1),
82 | .pllena (1'b1),
83 | .scanaclr (1'b0),
84 | .scanclk (1'b0),
85 | .scanclkena (1'b1),
86 | .scandata (1'b0),
87 | .scandataout (),
88 | .scandone (),
89 | .scanread (1'b0),
90 | .scanwrite (1'b0),
91 | .sclkout0 (),
92 | .sclkout1 (),
93 | .vcooverrange (),
94 | .vcounderrange ());
95 | defparam
96 | altpll_component.clk0_divide_by = 5,
97 | altpll_component.clk0_duty_cycle = 50,
98 | altpll_component.clk0_multiply_by = 1,
99 | altpll_component.clk0_phase_shift = "0",
100 | altpll_component.compensate_clock = "CLK0",
101 | altpll_component.gate_lock_counter = 1048575,
102 | altpll_component.gate_lock_signal = "YES",
103 | altpll_component.inclk0_input_frequency = 20000,
104 | altpll_component.intended_device_family = "Cyclone II",
105 | altpll_component.invalid_lock_multiplier = 5,
106 | altpll_component.lpm_hint = "CBX_MODULE_PREFIX=altpll0",
107 | altpll_component.lpm_type = "altpll",
108 | altpll_component.operation_mode = "NORMAL",
109 | altpll_component.port_activeclock = "PORT_UNUSED",
110 | altpll_component.port_areset = "PORT_UNUSED",
111 | altpll_component.port_clkbad0 = "PORT_UNUSED",
112 | altpll_component.port_clkbad1 = "PORT_UNUSED",
113 | altpll_component.port_clkloss = "PORT_UNUSED",
114 | altpll_component.port_clkswitch = "PORT_UNUSED",
115 | altpll_component.port_configupdate = "PORT_UNUSED",
116 | altpll_component.port_fbin = "PORT_UNUSED",
117 | altpll_component.port_inclk0 = "PORT_USED",
118 | altpll_component.port_inclk1 = "PORT_UNUSED",
119 | altpll_component.port_locked = "PORT_USED",
120 | altpll_component.port_pfdena = "PORT_UNUSED",
121 | altpll_component.port_phasecounterselect = "PORT_UNUSED",
122 | altpll_component.port_phasedone = "PORT_UNUSED",
123 | altpll_component.port_phasestep = "PORT_UNUSED",
124 | altpll_component.port_phaseupdown = "PORT_UNUSED",
125 | altpll_component.port_pllena = "PORT_UNUSED",
126 | altpll_component.port_scanaclr = "PORT_UNUSED",
127 | altpll_component.port_scanclk = "PORT_UNUSED",
128 | altpll_component.port_scanclkena = "PORT_UNUSED",
129 | altpll_component.port_scandata = "PORT_UNUSED",
130 | altpll_component.port_scandataout = "PORT_UNUSED",
131 | altpll_component.port_scandone = "PORT_UNUSED",
132 | altpll_component.port_scanread = "PORT_UNUSED",
133 | altpll_component.port_scanwrite = "PORT_UNUSED",
134 | altpll_component.port_clk0 = "PORT_USED",
135 | altpll_component.port_clk1 = "PORT_UNUSED",
136 | altpll_component.port_clk2 = "PORT_UNUSED",
137 | altpll_component.port_clk3 = "PORT_UNUSED",
138 | altpll_component.port_clk4 = "PORT_UNUSED",
139 | altpll_component.port_clk5 = "PORT_UNUSED",
140 | altpll_component.port_clkena0 = "PORT_UNUSED",
141 | altpll_component.port_clkena1 = "PORT_UNUSED",
142 | altpll_component.port_clkena2 = "PORT_UNUSED",
143 | altpll_component.port_clkena3 = "PORT_UNUSED",
144 | altpll_component.port_clkena4 = "PORT_UNUSED",
145 | altpll_component.port_clkena5 = "PORT_UNUSED",
146 | altpll_component.port_extclk0 = "PORT_UNUSED",
147 | altpll_component.port_extclk1 = "PORT_UNUSED",
148 | altpll_component.port_extclk2 = "PORT_UNUSED",
149 | altpll_component.port_extclk3 = "PORT_UNUSED",
150 | altpll_component.valid_lock_multiplier = 1;
151 |
152 |
153 | endmodule
154 |
155 | // ============================================================
156 | // CNX file retrieval info
157 | // ============================================================
158 | // Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING "0"
159 | // Retrieval info: PRIVATE: BANDWIDTH STRING "1.000"
160 | // Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING "0"
161 | // Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING "MHz"
162 | // Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING "Low"
163 | // Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING "1"
164 | // Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING "0"
165 | // Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING "0"
166 | // Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING "0"
167 | // Retrieval info: PRIVATE: CLKLOSS_CHECK STRING "0"
168 | // Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING "1"
169 | // Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING "0"
170 | // Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING "0"
171 | // Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING "0"
172 | // Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING "c0"
173 | // Retrieval info: PRIVATE: CUR_FBIN_CLK STRING "c0"
174 | // Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
175 | // Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "1"
176 | // Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
177 | // Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "10.000000"
178 | // Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
179 | // Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
180 | // Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
181 | // Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING "1"
182 | // Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING "1"
183 | // Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC "1048575"
184 | // Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING "1"
185 | // Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING "50.000"
186 | // Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING "MHz"
187 | // Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING "100.000"
188 | // Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING "1"
189 | // Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING "1"
190 | // Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING "MHz"
191 | // Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone II"
192 | // Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING "1"
193 | // Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING "1"
194 | // Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING "1"
195 | // Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING "Not Available"
196 | // Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
197 | // Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
198 | // Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
199 | // Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
200 | // Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "1"
201 | // Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
202 | // Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "10.00000000"
203 | // Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "1"
204 | // Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
205 | // Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "0"
206 | // Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
207 | // Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
208 | // Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
209 | // Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
210 | // Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
211 | // Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "0"
212 | // Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
213 | // Retrieval info: PRIVATE: PLL_ENA_CHECK STRING "0"
214 | // Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC "0"
215 | // Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC "0"
216 | // Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING "0"
217 | // Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC "0"
218 | // Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING "0"
219 | // Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC "0"
220 | // Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING "inclk0"
221 | // Retrieval info: PRIVATE: RECONFIG_FILE STRING "altpll0.mif"
222 | // Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING "0"
223 | // Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING "0"
224 | // Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING "0"
225 | // Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING "0"
226 | // Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING "0"
227 | // Retrieval info: PRIVATE: SPREAD_FREQ STRING "50.000"
228 | // Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING "KHz"
229 | // Retrieval info: PRIVATE: SPREAD_PERCENT STRING "0.500"
230 | // Retrieval info: PRIVATE: SPREAD_USE STRING "0"
231 | // Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
232 | // Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
233 | // Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
234 | // Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
235 | // Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
236 | // Retrieval info: PRIVATE: USE_CLK0 STRING "1"
237 | // Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
238 | // Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
239 | // Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
240 | // Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
241 | // Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "5"
242 | // Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
243 | // Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "1"
244 | // Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
245 | // Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
246 | // Retrieval info: CONSTANT: GATE_LOCK_COUNTER NUMERIC "1048575"
247 | // Retrieval info: CONSTANT: GATE_LOCK_SIGNAL STRING "YES"
248 | // Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "20000"
249 | // Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone II"
250 | // Retrieval info: CONSTANT: INVALID_LOCK_MULTIPLIER NUMERIC "5"
251 | // Retrieval info: CONSTANT: LPM_TYPE STRING "altpll"
252 | // Retrieval info: CONSTANT: OPERATION_MODE STRING "NORMAL"
253 | // Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING "PORT_UNUSED"
254 | // Retrieval info: CONSTANT: PORT_ARESET STRING "PORT_UNUSED"
255 | // Retrieval info: CONSTANT: PORT_CLKBAD0 STRING "PORT_UNUSED"
256 | // Retrieval info: CONSTANT: PORT_CLKBAD1 STRING "PORT_UNUSED"
257 | // Retrieval info: CONSTANT: PORT_CLKLOSS STRING "PORT_UNUSED"
258 | // Retrieval info: CONSTANT: PORT_CLKSWITCH STRING "PORT_UNUSED"
259 | // Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING "PORT_UNUSED"
260 | // Retrieval info: CONSTANT: PORT_FBIN STRING "PORT_UNUSED"
261 | // Retrieval info: CONSTANT: PORT_INCLK0 STRING "PORT_USED"
262 | // Retrieval info: CONSTANT: PORT_INCLK1 STRING "PORT_UNUSED"
263 | // Retrieval info: CONSTANT: PORT_LOCKED STRING "PORT_USED"
264 | // Retrieval info: CONSTANT: PORT_PFDENA STRING "PORT_UNUSED"
265 | // Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING "PORT_UNUSED"
266 | // Retrieval info: CONSTANT: PORT_PHASEDONE STRING "PORT_UNUSED"
267 | // Retrieval info: CONSTANT: PORT_PHASESTEP STRING "PORT_UNUSED"
268 | // Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING "PORT_UNUSED"
269 | // Retrieval info: CONSTANT: PORT_PLLENA STRING "PORT_UNUSED"
270 | // Retrieval info: CONSTANT: PORT_SCANACLR STRING "PORT_UNUSED"
271 | // Retrieval info: CONSTANT: PORT_SCANCLK STRING "PORT_UNUSED"
272 | // Retrieval info: CONSTANT: PORT_SCANCLKENA STRING "PORT_UNUSED"
273 | // Retrieval info: CONSTANT: PORT_SCANDATA STRING "PORT_UNUSED"
274 | // Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING "PORT_UNUSED"
275 | // Retrieval info: CONSTANT: PORT_SCANDONE STRING "PORT_UNUSED"
276 | // Retrieval info: CONSTANT: PORT_SCANREAD STRING "PORT_UNUSED"
277 | // Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
278 | // Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
279 | // Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_UNUSED"
280 | // Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_UNUSED"
281 | // Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
282 | // Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
283 | // Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
284 | // Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
285 | // Retrieval info: CONSTANT: PORT_clkena1 STRING "PORT_UNUSED"
286 | // Retrieval info: CONSTANT: PORT_clkena2 STRING "PORT_UNUSED"
287 | // Retrieval info: CONSTANT: PORT_clkena3 STRING "PORT_UNUSED"
288 | // Retrieval info: CONSTANT: PORT_clkena4 STRING "PORT_UNUSED"
289 | // Retrieval info: CONSTANT: PORT_clkena5 STRING "PORT_UNUSED"
290 | // Retrieval info: CONSTANT: PORT_extclk0 STRING "PORT_UNUSED"
291 | // Retrieval info: CONSTANT: PORT_extclk1 STRING "PORT_UNUSED"
292 | // Retrieval info: CONSTANT: PORT_extclk2 STRING "PORT_UNUSED"
293 | // Retrieval info: CONSTANT: PORT_extclk3 STRING "PORT_UNUSED"
294 | // Retrieval info: CONSTANT: VALID_LOCK_MULTIPLIER NUMERIC "1"
295 | // Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT_CLK_EXT VCC "@clk[5..0]"
296 | // Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT_CLK_EXT VCC "@extclk[3..0]"
297 | // Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
298 | // Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
299 | // Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND "locked"
300 | // Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
301 | // Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
302 | // Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
303 | // Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
304 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.v TRUE
305 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.ppf TRUE
306 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.inc FALSE
307 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.cmp FALSE
308 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.bsf TRUE
309 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0_inst.v FALSE
310 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0_bb.v TRUE
311 | // Retrieval info: LIB_FILE: altera_mf
312 | // Retrieval info: CBX_MODULE_PREFIX: ON
313 |
--------------------------------------------------------------------------------
/altera/altpll0_bb.v:
--------------------------------------------------------------------------------
1 | // megafunction wizard: %ALTPLL%VBB%
2 | // GENERATION: STANDARD
3 | // VERSION: WM1.0
4 | // MODULE: altpll
5 |
6 | // ============================================================
7 | // File Name: altpll0.v
8 | // Megafunction Name(s):
9 | // altpll
10 | //
11 | // Simulation Library Files(s):
12 | // altera_mf
13 | // ============================================================
14 | // ************************************************************
15 | // THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
16 | //
17 | // 13.0.1 Build 232 06/12/2013 SP 1 SJ Web Edition
18 | // ************************************************************
19 |
20 | //Copyright (C) 1991-2013 Altera Corporation
21 | //Your use of Altera Corporation's design tools, logic functions
22 | //and other software and tools, and its AMPP partner logic
23 | //functions, and any output files from any of the foregoing
24 | //(including device programming or simulation files), and any
25 | //associated documentation or information are expressly subject
26 | //to the terms and conditions of the Altera Program License
27 | //Subscription Agreement, Altera MegaCore Function License
28 | //Agreement, or other applicable license agreement, including,
29 | //without limitation, that your use is for the sole purpose of
30 | //programming logic devices manufactured by Altera and sold by
31 | //Altera or its authorized distributors. Please refer to the
32 | //applicable agreement for further details.
33 |
34 | module altpll0 (
35 | inclk0,
36 | c0,
37 | locked);
38 |
39 | input inclk0;
40 | output c0;
41 | output locked;
42 |
43 | endmodule
44 |
45 | // ============================================================
46 | // CNX file retrieval info
47 | // ============================================================
48 | // Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING "0"
49 | // Retrieval info: PRIVATE: BANDWIDTH STRING "1.000"
50 | // Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING "0"
51 | // Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING "MHz"
52 | // Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING "Low"
53 | // Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING "1"
54 | // Retrieval info: PRIVATE: BANDWIDTH_USE_CUSTOM STRING "0"
55 | // Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING "0"
56 | // Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING "0"
57 | // Retrieval info: PRIVATE: CLKLOSS_CHECK STRING "0"
58 | // Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING "1"
59 | // Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING "0"
60 | // Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING "0"
61 | // Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING "0"
62 | // Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING "c0"
63 | // Retrieval info: PRIVATE: CUR_FBIN_CLK STRING "c0"
64 | // Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
65 | // Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "1"
66 | // Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
67 | // Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "10.000000"
68 | // Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
69 | // Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
70 | // Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
71 | // Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING "1"
72 | // Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING "1"
73 | // Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC "1048575"
74 | // Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING "1"
75 | // Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING "50.000"
76 | // Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING "MHz"
77 | // Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING "100.000"
78 | // Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING "1"
79 | // Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING "1"
80 | // Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING "MHz"
81 | // Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone II"
82 | // Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING "1"
83 | // Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING "1"
84 | // Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING "1"
85 | // Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING "Not Available"
86 | // Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
87 | // Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
88 | // Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
89 | // Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
90 | // Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "1"
91 | // Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
92 | // Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "10.00000000"
93 | // Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "1"
94 | // Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
95 | // Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "0"
96 | // Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
97 | // Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
98 | // Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
99 | // Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
100 | // Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
101 | // Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "0"
102 | // Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
103 | // Retrieval info: PRIVATE: PLL_ENA_CHECK STRING "0"
104 | // Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC "0"
105 | // Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC "0"
106 | // Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING "0"
107 | // Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC "0"
108 | // Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING "0"
109 | // Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC "0"
110 | // Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING "inclk0"
111 | // Retrieval info: PRIVATE: RECONFIG_FILE STRING "altpll0.mif"
112 | // Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING "0"
113 | // Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING "0"
114 | // Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING "0"
115 | // Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING "0"
116 | // Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING "0"
117 | // Retrieval info: PRIVATE: SPREAD_FREQ STRING "50.000"
118 | // Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING "KHz"
119 | // Retrieval info: PRIVATE: SPREAD_PERCENT STRING "0.500"
120 | // Retrieval info: PRIVATE: SPREAD_USE STRING "0"
121 | // Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
122 | // Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
123 | // Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
124 | // Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
125 | // Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
126 | // Retrieval info: PRIVATE: USE_CLK0 STRING "1"
127 | // Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
128 | // Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
129 | // Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
130 | // Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
131 | // Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "5"
132 | // Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
133 | // Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "1"
134 | // Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
135 | // Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
136 | // Retrieval info: CONSTANT: GATE_LOCK_COUNTER NUMERIC "1048575"
137 | // Retrieval info: CONSTANT: GATE_LOCK_SIGNAL STRING "YES"
138 | // Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "20000"
139 | // Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone II"
140 | // Retrieval info: CONSTANT: INVALID_LOCK_MULTIPLIER NUMERIC "5"
141 | // Retrieval info: CONSTANT: LPM_TYPE STRING "altpll"
142 | // Retrieval info: CONSTANT: OPERATION_MODE STRING "NORMAL"
143 | // Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING "PORT_UNUSED"
144 | // Retrieval info: CONSTANT: PORT_ARESET STRING "PORT_UNUSED"
145 | // Retrieval info: CONSTANT: PORT_CLKBAD0 STRING "PORT_UNUSED"
146 | // Retrieval info: CONSTANT: PORT_CLKBAD1 STRING "PORT_UNUSED"
147 | // Retrieval info: CONSTANT: PORT_CLKLOSS STRING "PORT_UNUSED"
148 | // Retrieval info: CONSTANT: PORT_CLKSWITCH STRING "PORT_UNUSED"
149 | // Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING "PORT_UNUSED"
150 | // Retrieval info: CONSTANT: PORT_FBIN STRING "PORT_UNUSED"
151 | // Retrieval info: CONSTANT: PORT_INCLK0 STRING "PORT_USED"
152 | // Retrieval info: CONSTANT: PORT_INCLK1 STRING "PORT_UNUSED"
153 | // Retrieval info: CONSTANT: PORT_LOCKED STRING "PORT_USED"
154 | // Retrieval info: CONSTANT: PORT_PFDENA STRING "PORT_UNUSED"
155 | // Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING "PORT_UNUSED"
156 | // Retrieval info: CONSTANT: PORT_PHASEDONE STRING "PORT_UNUSED"
157 | // Retrieval info: CONSTANT: PORT_PHASESTEP STRING "PORT_UNUSED"
158 | // Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING "PORT_UNUSED"
159 | // Retrieval info: CONSTANT: PORT_PLLENA STRING "PORT_UNUSED"
160 | // Retrieval info: CONSTANT: PORT_SCANACLR STRING "PORT_UNUSED"
161 | // Retrieval info: CONSTANT: PORT_SCANCLK STRING "PORT_UNUSED"
162 | // Retrieval info: CONSTANT: PORT_SCANCLKENA STRING "PORT_UNUSED"
163 | // Retrieval info: CONSTANT: PORT_SCANDATA STRING "PORT_UNUSED"
164 | // Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING "PORT_UNUSED"
165 | // Retrieval info: CONSTANT: PORT_SCANDONE STRING "PORT_UNUSED"
166 | // Retrieval info: CONSTANT: PORT_SCANREAD STRING "PORT_UNUSED"
167 | // Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
168 | // Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
169 | // Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_UNUSED"
170 | // Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_UNUSED"
171 | // Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
172 | // Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
173 | // Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
174 | // Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
175 | // Retrieval info: CONSTANT: PORT_clkena1 STRING "PORT_UNUSED"
176 | // Retrieval info: CONSTANT: PORT_clkena2 STRING "PORT_UNUSED"
177 | // Retrieval info: CONSTANT: PORT_clkena3 STRING "PORT_UNUSED"
178 | // Retrieval info: CONSTANT: PORT_clkena4 STRING "PORT_UNUSED"
179 | // Retrieval info: CONSTANT: PORT_clkena5 STRING "PORT_UNUSED"
180 | // Retrieval info: CONSTANT: PORT_extclk0 STRING "PORT_UNUSED"
181 | // Retrieval info: CONSTANT: PORT_extclk1 STRING "PORT_UNUSED"
182 | // Retrieval info: CONSTANT: PORT_extclk2 STRING "PORT_UNUSED"
183 | // Retrieval info: CONSTANT: PORT_extclk3 STRING "PORT_UNUSED"
184 | // Retrieval info: CONSTANT: VALID_LOCK_MULTIPLIER NUMERIC "1"
185 | // Retrieval info: USED_PORT: @clk 0 0 6 0 OUTPUT_CLK_EXT VCC "@clk[5..0]"
186 | // Retrieval info: USED_PORT: @extclk 0 0 4 0 OUTPUT_CLK_EXT VCC "@extclk[3..0]"
187 | // Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
188 | // Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
189 | // Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND "locked"
190 | // Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
191 | // Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
192 | // Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
193 | // Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
194 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.v TRUE
195 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.ppf TRUE
196 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.inc FALSE
197 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.cmp FALSE
198 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0.bsf TRUE
199 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0_inst.v FALSE
200 | // Retrieval info: GEN_FILE: TYPE_NORMAL altpll0_bb.v TRUE
201 | // Retrieval info: LIB_FILE: altera_mf
202 | // Retrieval info: CBX_MODULE_PREFIX: ON
203 |
--------------------------------------------------------------------------------
/altera/boss.bsf:
--------------------------------------------------------------------------------
1 | /*
2 | WARNING: Do NOT edit the input and output ports in this file in a text
3 | editor if you plan to continue editing the block that represents it in
4 | the Block Editor! File corruption is VERY likely to occur.
5 | */
6 | /*
7 | Copyright (C) 1991-2013 Altera Corporation
8 | Your use of Altera Corporation's design tools, logic functions
9 | and other software and tools, and its AMPP partner logic
10 | functions, and any output files from any of the foregoing
11 | (including device programming or simulation files), and any
12 | associated documentation or information are expressly subject
13 | to the terms and conditions of the Altera Program License
14 | Subscription Agreement, Altera MegaCore Function License
15 | Agreement, or other applicable license agreement, including,
16 | without limitation, that your use is for the sole purpose of
17 | programming logic devices manufactured by Altera and sold by
18 | Altera or its authorized distributors. Please refer to the
19 | applicable agreement for further details.
20 | */
21 | (header "symbol" (version "1.1"))
22 | (symbol
23 | (rect 16 16 216 320)
24 | (text "boss" (rect 5 0 23 12)(font "Arial" ))
25 | (text "inst" (rect 8 288 20 300)(font "Arial" ))
26 | (port
27 | (pt 0 32)
28 | (input)
29 | (text "clk" (rect 0 0 10 12)(font "Arial" ))
30 | (text "clk" (rect 21 27 31 39)(font "Arial" ))
31 | (line (pt 0 32)(pt 16 32)(line_width 1))
32 | )
33 | (port
34 | (pt 0 48)
35 | (input)
36 | (text "adcDout" (rect 0 0 33 12)(font "Arial" ))
37 | (text "adcDout" (rect 21 43 54 55)(font "Arial" ))
38 | (line (pt 0 48)(pt 16 48)(line_width 1))
39 | )
40 | (port
41 | (pt 0 64)
42 | (input)
43 | (text "reset" (rect 0 0 20 12)(font "Arial" ))
44 | (text "reset" (rect 21 59 41 71)(font "Arial" ))
45 | (line (pt 0 64)(pt 16 64)(line_width 1))
46 | )
47 | (port
48 | (pt 200 48)
49 | (output)
50 | (text "waddress[16..0]" (rect 0 0 61 12)(font "Arial" ))
51 | (text "waddress[16..0]" (rect 118 43 179 55)(font "Arial" ))
52 | (line (pt 200 48)(pt 184 48)(line_width 3))
53 | )
54 | (port
55 | (pt 200 64)
56 | (output)
57 | (text "we" (rect 0 0 10 12)(font "Arial" ))
58 | (text "we" (rect 169 59 179 71)(font "Arial" ))
59 | (line (pt 200 64)(pt 184 64)(line_width 1))
60 | )
61 | (port
62 | (pt 200 80)
63 | (output)
64 | (text "pe" (rect 0 0 9 12)(font "Arial" ))
65 | (text "pe" (rect 170 75 179 87)(font "Arial" ))
66 | (line (pt 200 80)(pt 184 80)(line_width 1))
67 | )
68 | (port
69 | (pt 200 96)
70 | (output)
71 | (text "romCS" (rect 0 0 29 12)(font "Arial" ))
72 | (text "romCS" (rect 150 91 179 103)(font "Arial" ))
73 | (line (pt 200 96)(pt 184 96)(line_width 1))
74 | )
75 | (port
76 | (pt 200 112)
77 | (output)
78 | (text "ramCS" (rect 0 0 29 12)(font "Arial" ))
79 | (text "ramCS" (rect 150 107 179 119)(font "Arial" ))
80 | (line (pt 200 112)(pt 184 112)(line_width 1))
81 | )
82 | (port
83 | (pt 200 128)
84 | (output)
85 | (text "led0" (rect 0 0 15 12)(font "Arial" ))
86 | (text "led0" (rect 164 123 179 135)(font "Arial" ))
87 | (line (pt 200 128)(pt 184 128)(line_width 1))
88 | )
89 | (port
90 | (pt 200 144)
91 | (output)
92 | (text "led1" (rect 0 0 14 12)(font "Arial" ))
93 | (text "led1" (rect 165 139 179 151)(font "Arial" ))
94 | (line (pt 200 144)(pt 184 144)(line_width 1))
95 | )
96 | (port
97 | (pt 200 160)
98 | (output)
99 | (text "led2" (rect 0 0 15 12)(font "Arial" ))
100 | (text "led2" (rect 164 155 179 167)(font "Arial" ))
101 | (line (pt 200 160)(pt 184 160)(line_width 1))
102 | )
103 | (port
104 | (pt 200 176)
105 | (output)
106 | (text "lcdCS" (rect 0 0 23 12)(font "Arial" ))
107 | (text "lcdCS" (rect 156 171 179 183)(font "Arial" ))
108 | (line (pt 200 176)(pt 184 176)(line_width 1))
109 | )
110 | (port
111 | (pt 200 192)
112 | (output)
113 | (text "lcdRS" (rect 0 0 24 12)(font "Arial" ))
114 | (text "lcdRS" (rect 155 187 179 199)(font "Arial" ))
115 | (line (pt 200 192)(pt 184 192)(line_width 1))
116 | )
117 | (port
118 | (pt 200 208)
119 | (output)
120 | (text "lcdReset" (rect 0 0 35 12)(font "Arial" ))
121 | (text "lcdReset" (rect 144 203 179 215)(font "Arial" ))
122 | (line (pt 200 208)(pt 184 208)(line_width 1))
123 | )
124 | (port
125 | (pt 200 224)
126 | (output)
127 | (text "nadcCS" (rect 0 0 31 12)(font "Arial" ))
128 | (text "nadcCS" (rect 148 219 179 231)(font "Arial" ))
129 | (line (pt 200 224)(pt 184 224)(line_width 1))
130 | )
131 | (port
132 | (pt 200 240)
133 | (output)
134 | (text "a17" (rect 0 0 12 12)(font "Arial" ))
135 | (text "a17" (rect 167 235 179 247)(font "Arial" ))
136 | (line (pt 200 240)(pt 184 240)(line_width 1))
137 | )
138 | (port
139 | (pt 200 256)
140 | (output)
141 | (text "a18" (rect 0 0 12 12)(font "Arial" ))
142 | (text "a18" (rect 167 251 179 263)(font "Arial" ))
143 | (line (pt 200 256)(pt 184 256)(line_width 1))
144 | )
145 | (port
146 | (pt 200 32)
147 | (bidir)
148 | (text "data[7..0]" (rect 0 0 36 12)(font "Arial" ))
149 | (text "data[7..0]" (rect 143 27 179 39)(font "Arial" ))
150 | (line (pt 200 32)(pt 184 32)(line_width 3))
151 | )
152 | (drawing
153 | (rectangle (rect 16 16 184 288)(line_width 1))
154 | )
155 | )
156 |
--------------------------------------------------------------------------------
/altera/main.bsf:
--------------------------------------------------------------------------------
1 | /*
2 | WARNING: Do NOT edit the input and output ports in this file in a text
3 | editor if you plan to continue editing the block that represents it in
4 | the Block Editor! File corruption is VERY likely to occur.
5 | */
6 | /*
7 | Copyright (C) 1991-2013 Altera Corporation
8 | Your use of Altera Corporation's design tools, logic functions
9 | and other software and tools, and its AMPP partner logic
10 | functions, and any output files from any of the foregoing
11 | (including device programming or simulation files), and any
12 | associated documentation or information are expressly subject
13 | to the terms and conditions of the Altera Program License
14 | Subscription Agreement, Altera MegaCore Function License
15 | Agreement, or other applicable license agreement, including,
16 | without limitation, that your use is for the sole purpose of
17 | programming logic devices manufactured by Altera and sold by
18 | Altera or its authorized distributors. Please refer to the
19 | applicable agreement for further details.
20 | */
21 | (header "symbol" (version "1.1"))
22 | (symbol
23 | (rect 16 16 64 64)
24 | (text "main" (rect 5 0 23 12)(font "Arial" ))
25 | (text "inst" (rect 8 32 20 44)(font "Arial" ))
26 | (drawing
27 | (rectangle (rect 16 16 32 32)(line_width 1))
28 | )
29 | )
30 |
--------------------------------------------------------------------------------
/altera/zmachine.sdc:
--------------------------------------------------------------------------------
1 | create_clock -period 20.000 -name osc_clk osc_clk
2 | derive_pll_clocks
3 | derive_clock_uncertainty
--------------------------------------------------------------------------------
/benchmark/benchmark.inf:
--------------------------------------------------------------------------------
1 | [Ackermann
2 | m n;
3 | if (m==0)
4 | return n+1;
5 | else if (n==0)
6 | return Ackermann(m-1,1);
7 | else
8 | return Ackermann(m-1,Ackermann(m,n-1));
9 | ];
10 |
11 | [AckermannBench
12 | result i;
13 | @print "Ackermann Benchmark^";
14 | @print "Start^";
15 | @show_status;
16 | result=Ackermann(3,6);
17 | @print "End^";
18 | @show_status;
19 | @print "Result=";
20 | @print_num result;
21 | @new_line;
22 | @print "Start10^";
23 | @show_status;
24 | result=Ackermann(3,6);
25 | result=Ackermann(3,6);
26 | result=Ackermann(3,6);
27 | result=Ackermann(3,6);
28 | result=Ackermann(3,6);
29 | result=Ackermann(3,6);
30 | result=Ackermann(3,6);
31 | result=Ackermann(3,6);
32 | result=Ackermann(3,6);
33 | @print "End^^";
34 | @show_status;
35 | ];
36 |
37 | Constant SIZE=8192;
38 |
39 | Array flags -> SIZE+1;
40 |
41 | [Sieve
42 | iter count i prime k;
43 | @print "Sieve of Eratosthenes Benchmark^";
44 | @print "Start10^";
45 | @show_status;
46 | for (iter = 1: iter <= 10: iter++)
47 | {
48 | count = 0;
49 | for (i = 0: i <= SIZE: i++)
50 | i->flags = 1;
51 |
52 | for (i = 0: i <= SIZE: i++)
53 | {
54 | if (i->flags)
55 | {
56 | prime = i + i + 3;
57 | k = i + prime;
58 |
59 | while (k <= SIZE)
60 | {
61 | k->flags = 0;
62 | k = k + prime;
63 | }
64 |
65 | count++;
66 | }
67 | }
68 | }
69 | @print "End^";
70 | @show_status;
71 | @print "Count=";
72 | @print_num count;
73 | @new_line;
74 | @print "Start100^";
75 | @show_status;
76 | for (iter = 1: iter <= 100: iter++)
77 | {
78 | count = 0;
79 | for (i = 0: i <= SIZE: i++)
80 | i->flags = 1;
81 |
82 | for (i = 0: i <= SIZE: i++)
83 | {
84 | if (i->flags)
85 | {
86 | prime = i + i + 3;
87 | k = i + prime;
88 |
89 | while (k <= SIZE)
90 | {
91 | k->flags = 0;
92 | k = k + prime;
93 | }
94 |
95 | count++;
96 | }
97 | }
98 | }
99 | @print "End^^";
100 | @show_status;
101 | ];
102 |
103 | [Mandelbrot
104 | x y xtemp ytemp x0 y0 x00 y00 i;
105 | @print "Start Mandelbrot 16-bit^";
106 | @show_status;
107 | y0=60;
108 | do
109 | {
110 | x0=-120;
111 | y00=y0*40;
112 | do
113 | {
114 | xtemp=0;
115 | ytemp=0;
116 | x=0;
117 | y=0;
118 | i=0;
119 | x00=x0*20;
120 | do
121 | {
122 | xtemp=xtemp-ytemp+y00;
123 | y=(x*y+x00)/32;
124 | if (y>=2*64 || y<=-2*64)
125 | {
126 | i++;
127 | break;
128 | }
129 | x=xtemp/64;
130 | if (x>=2*64 || x<=-2*64)
131 | {
132 | i++;
133 | break;
134 | }
135 | xtemp=x*x;
136 | ytemp=y*y;
137 | i++;
138 | } until ( xtemp + ytemp >= 64*64*4 || i>=32);
139 | i=1-->(i+MandelbrotPalette);
140 | x0++;
141 | } until (x0>=120);
142 | y0--;
143 | } until (y0==60-230);
144 | @print "End Mandelbrot 16-bit^^";
145 | @show_status;
146 | ];
147 |
148 | [ Mul32
149 | r a b
150 | x1 x2 y1 y2 mul;
151 | mul=1;
152 | a=(a-->0)*16+(a->2)/16;
153 | if (a<0)
154 | {
155 | mul=-mul;
156 | a=-a;
157 | }
158 | y1=a/256;
159 | x1=a&$ff;
160 | b=(b-->0)*16+(b->2)/16;
161 | if (b<0)
162 | {
163 | mul=-mul;
164 | b=-b;
165 | }
166 | y2=b/256;
167 | x2=b&$ff;
168 | r-->0=0;
169 | r-->1=x1*x2;
170 | r++;
171 | r-->0=r-->0+x1*y2+x2*y1;
172 | r--;
173 | r-->0=mul*(r-->0+y1*y2);
174 | ];
175 |
176 | [ Add32
177 | r a b;
178 | r-->0=0;
179 | r-->1=(a-->1)&$ff+(b-->1)&$ff;
180 | r++;
181 | a++;
182 | b++;
183 | r-->0=r-->0+(a-->0)&$ff+(b-->0)&$ff;
184 | r--;
185 | a--;
186 | b--;
187 | r-->0=r-->0+a-->0+b-->0;
188 | ];
189 |
190 | [ Neg32
191 | r a;
192 | r-->1=~a-->1+1;
193 | r-->0=~a-->0;
194 | if (r-->1==0)
195 | r-->0=r-->0+1;
196 | ];
197 |
198 | [ Mov32
199 | r a;
200 | r-->1=a-->1;
201 | r-->0=a-->0;
202 | ];
203 |
204 | [ Dob32
205 | r;
206 | r-->0=2*r-->0;
207 | if (r-->1<0)
208 | r-->0=r-->0+1;
209 | r-->1=2*r-->1;
210 | ];
211 |
212 | [MandelbrotPalette;
213 | ];
214 |
215 | [Mandelbrot32
216 | x y xtemp ytemp x0 y0 x00 y00 i t;
217 | @print "Start Mandelbrot 32-bit^";
218 | @show_status;
219 | y0=60;
220 |
221 | xtemp=0;
222 | ytemp=4;
223 | y=8;
224 | x=12;
225 | t=16;
226 | x00=20;
227 | y00=24;
228 |
229 | do
230 | {
231 | x0=-120;
232 | y00-->0=y0*40/16;
233 | y00-->1=0;
234 | do
235 | {
236 | xtemp-->0=0;
237 | xtemp-->1=0;
238 | ytemp-->0=0;
239 | ytemp-->1=0;
240 | y-->0=0;
241 | y-->1=0;
242 | x-->0=0;
243 | x-->1=0;
244 | x00-->0=x0*40/16;
245 | x00-->1=0;
246 |
247 | i=0;
248 | do
249 | {
250 | Neg32(ytemp, ytemp);
251 | Add32(t, xtemp, ytemp);
252 | Neg32(ytemp, ytemp);
253 | Add32(xtemp, t, y00);
254 | Mul32(t, x, y);
255 | Dob32(t);
256 | Add32(y, t, x00);
257 | Mov32(x,xtemp);
258 | Mul32(xtemp,x,x);
259 | Mul32(ytemp,y,y);
260 | i++;
261 | if (y-->0>=$200 || y-->0<=-$200)
262 | break;
263 | if (x-->0>=$200 || x-->0<=-$200)
264 | break;
265 | Add32(t,xtemp,ytemp);
266 | } until ( t-->0 >= $400 || i>=32);
267 | i=1-->(i+MandelbrotPalette);
268 | x0++;
269 | } until (x0>=120);
270 | y0--;
271 | } until (y0==60-230);
272 | @print "End Mandelbrot 32-bit^^";
273 | @show_status;
274 | ];
275 |
276 | Constant Number_Of_Runs = 10000;
277 |
278 | Constant Ident_1 = 0;
279 | Constant Ident_2 = 1;
280 | Constant Ident_3 = 2;
281 | Constant Ident_4 = 3;
282 | Constant Ident_5 = 4;
283 |
284 | Constant Ptr_Comp=0;
285 | Constant Discr=1;
286 | Constant Enum_Comp=2;
287 | Constant Int_Comp=3;
288 | Constant Str_Comp=8;
289 | Constant E_Comp_2=2;
290 | Constant Str_2_Comp=6;
291 | Constant Ch_1_Comp=4;
292 | Constant Ch_2_Comp=5;
293 | Constant RecSize=Str_Comp+31;
294 |
295 | Array String1-> 'D' 'H' 'R' 'Y' 'S' 'T' 'O' 'N' 'E' ' ' 'P' 'R' 'O' 'G' 'R' 'A' 'M' ',' ' ' '1' ''' 'S' 'T' ' ' 'S' 'T' 'R' 'I' 'N' 'G' 0;
296 | Array String2-> 'D' 'H' 'R' 'Y' 'S' 'T' 'O' 'N' 'E' ' ' 'P' 'R' 'O' 'G' 'R' 'A' 'M' ',' ' ' '2' ''' 'N' 'D' ' ' 'S' 'T' 'R' 'I' 'N' 'G' 0;
297 | Array String3-> 'D' 'H' 'R' 'Y' 'S' 'T' 'O' 'N' 'E' ' ' 'P' 'R' 'O' 'G' 'R' 'A' 'M' ',' ' ' '3' ''' 'R' 'D' ' ' 'S' 'T' 'R' 'I' 'N' 'G' 0;
298 | Array SomeString->'D' 'H' 'R' 'Y' 'S' 'T' 'O' 'N' 'E' ' ' 'P' 'R' 'O' 'G' 'R' 'A' 'M' ',' ' ' 'S' 'O' 'M' 'E' ' ' 'S' 'T' 'R' 'I' 'N' 'G' 0;
299 | Array Str_1_Loc_Space->31;
300 | Array Str_2_Loc_Space->31;
301 | Array Arr_1_Glob-->50;
302 | Array Arr_2_Glob-->2500;
303 | Array Ptr_Glob->RecSize;
304 | Array Next_Ptr_Glob->RecSize;
305 | Global Int_Glob;
306 | Global Bool_Glob;
307 | Global Ch_1_Glob;
308 | Global Ch_2_Glob;
309 |
310 | [strcmp
311 | a b c1 c2 i;
312 | while (1)
313 | {
314 | c1=i->a;
315 | c2=i->b;
316 | if (c1~=c2 || c1*c2==0)
317 | return c1-c2;
318 | i++;
319 | }
320 | ];
321 |
322 | [strcpy
323 | a b i;
324 | while (b->i)
325 | {
326 | a->i=b->i;
327 | i++;
328 | }
329 | a->i=0;
330 | ];
331 |
332 | [memcpy
333 | a b i;
334 | while (i)
335 | {
336 | i--;
337 | a->i=b->i;
338 | }
339 | ];
340 |
341 | [PrintString
342 | a i;
343 | while (a->0)
344 | {
345 | i=a->0;
346 | @print_char i;
347 | a++;
348 | }
349 | ];
350 |
351 | [Func_1
352 | Ch_1_Par_Val Ch_2_Par_Val
353 | Ch_1_Loc Ch_2_Loc;
354 |
355 | Ch_1_Loc = Ch_1_Par_Val;
356 | Ch_2_Loc = Ch_1_Loc;
357 | if (Ch_2_Loc ~= Ch_2_Par_Val)
358 | return (Ident_1);
359 | else
360 | {
361 | Ch_1_Glob = Ch_1_Loc;
362 | return (Ident_2);
363 | }
364 | ];
365 |
366 | [Func_2
367 | Str_1_Par_Ref Str_2_Par_Ref
368 | Int_Loc Ch_Loc;
369 |
370 | Int_Loc = 2;
371 | while (Int_Loc <= 2)
372 | {
373 | if (Func_1 (Str_1_Par_Ref->Int_Loc,
374 | Str_2_Par_Ref->(Int_Loc+1)) == Ident_1)
375 | {
376 | Ch_Loc = 'A';
377 | Int_Loc ++;
378 | }
379 | }
380 | if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
381 | Int_Loc = 7;
382 | if (Ch_Loc == 'R')
383 | return 1;
384 | else
385 | {
386 | if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
387 | {
388 | Int_Loc = Int_Loc + 7;
389 | Int_Glob = Int_Loc;
390 | return 1;
391 | }
392 | else
393 | return 0;
394 | }
395 | ];
396 |
397 | [Func_3
398 | Enum_Par_Val
399 | Enum_Loc;
400 |
401 | Enum_Loc = Enum_Par_Val;
402 | if (Enum_Loc == Ident_3)
403 | return 1;
404 | else
405 | return 0;
406 | ];
407 |
408 | [Proc_1
409 | Ptr_Val_Par
410 | Next_Record;
411 | Next_Record = Ptr_Val_Par-->Ptr_Comp;
412 | memcpy(Ptr_Val_Par-->Ptr_Comp, Ptr_Glob, RecSize);
413 | Ptr_Val_Par-->Int_Comp = 5;
414 | Next_Record-->Int_Comp
415 | = Ptr_Val_Par-->Int_Comp;
416 | Next_Record-->Ptr_Comp = Ptr_Val_Par-->Ptr_Comp;
417 | Proc_3 (Next_Record+2*Ptr_Comp);
418 | if (Next_Record-->Discr == Ident_1)
419 | {
420 | Next_Record-->Int_Comp = 6;
421 | Next_Record-->Enum_Comp=Proc_6 (Ptr_Val_Par-->Enum_Comp);
422 | Next_Record-->Ptr_Comp = Ptr_Glob-->Ptr_Comp;
423 | Next_Record-->Int_Comp=Proc_7 (Next_Record-->Int_Comp, 10);
424 | }
425 | else
426 | memcpy(Ptr_Val_Par, Ptr_Val_Par-->Ptr_Comp, RecSize);
427 | ];
428 |
429 | [Proc_2
430 | Int_Par_Ref
431 | Int_Loc Enum_Loc;
432 |
433 | Int_Loc = Int_Par_Ref + 10;
434 | do
435 | if (Ch_1_Glob == 'A')
436 | {
437 | Int_Loc --;
438 | Int_Par_Ref = Int_Loc - Int_Glob;
439 | Enum_Loc = Ident_1;
440 | }
441 | until (Enum_Loc == Ident_1);
442 | return Int_Par_Ref;
443 | ];
444 |
445 | [Proc_3
446 | Ptr_Ref_Par;
447 | if (Ptr_Glob)
448 | {
449 | Ptr_Ref_Par-->0 = Ptr_Glob-->Ptr_Comp;
450 | }
451 | Ptr_Glob-->Int_Comp=Proc_7(10, Int_Glob);
452 | ];
453 |
454 | [Proc_4
455 | Bool_Loc;
456 | Bool_Loc = Ch_1_Glob == 'A';
457 | Bool_Glob = Bool_Loc | Bool_Glob;
458 | Ch_2_Glob = 'B';
459 | ];
460 |
461 | [Proc_5;
462 | Ch_1_Glob = 'A';
463 | Bool_Glob = 0;
464 | ];
465 |
466 | [Proc_6
467 | Enum_Val_Par
468 | Enum_Ref_Par;
469 |
470 | Enum_Ref_Par = Enum_Val_Par;
471 | if (~~Func_3 (Enum_Val_Par))
472 | Enum_Ref_Par = Ident_4;
473 | switch (Enum_Val_Par)
474 | {
475 | Ident_1:
476 | Enum_Ref_Par = Ident_1;
477 | break;
478 | Ident_2:
479 | if (Int_Glob > 100) Enum_Ref_Par = Ident_1;
480 | else Enum_Ref_Par = Ident_4;
481 | break;
482 | Ident_3:
483 | Enum_Ref_Par = Ident_2;
484 | break;
485 | Ident_4:
486 | break;
487 | Ident_5:
488 | Enum_Ref_Par = Ident_3;
489 | break;
490 | }
491 | return Enum_Ref_Par;
492 | ];
493 |
494 | [Proc_7
495 | Int_1_Par_Val Int_2_Par_Val
496 | Int_Loc;
497 |
498 | Int_Loc = Int_1_Par_Val + 2;
499 | return Int_2_Par_Val + Int_Loc;
500 | ];
501 |
502 | [Proc_8
503 | Arr_1_Par_Ref Int_1_Par_Val Int_2_Par_Val ! Should take Arr_2_Global as argument but limited to 3 args
504 | Int_Index Int_Loc;
505 |
506 | Int_Loc = Int_1_Par_Val + 5;
507 | Arr_1_Par_Ref-->Int_Loc = Int_2_Par_Val;
508 | Arr_1_Par_Ref-->(Int_Loc+1) = Arr_1_Par_Ref-->Int_Loc;
509 | Arr_1_Par_Ref-->(Int_Loc+30) = Int_Loc;
510 | for (Int_Index = Int_Loc: Int_Index <= Int_Loc+1: Int_Index++)
511 | Arr_2_Glob-->(50*Int_Loc+Int_Index) = Int_Loc;
512 | Arr_2_Glob-->(50*Int_Loc+Int_Loc-1) = Arr_2_Glob-->(50*Int_Loc+Int_Loc-1)+1;
513 | Arr_2_Glob-->(50*(Int_Loc+20)+Int_Loc) = Arr_1_Par_Ref-->Int_Loc;
514 | Int_Glob = 5;
515 | ];
516 |
517 | [Dhrystone
518 | Run_Index Int_1_Loc Int_2_Loc Int_3_Loc Enum_Loc Ch_Index Str_1_Loc Str_2_Loc temp;
519 |
520 | Str_1_Loc=Str_1_Loc_Space;
521 | Str_2_Loc=Str_2_Loc_Space;
522 | strcpy(Str_1_Loc, String1);
523 |
524 | Ptr_Glob-->Ptr_Comp = Next_Ptr_Glob;
525 | Ptr_Glob-->Discr = Ident_1;
526 | Ptr_Glob-->Enum_Comp = Ident_3;
527 | Ptr_Glob-->Int_Comp = 40;
528 | strcpy(Ptr_Glob+Str_Comp, SomeString);
529 | Arr_2_Glob-->(8*50+7) = 10;
530 |
531 | @print "Start Dhrystone x10000^";
532 | @show_status;
533 |
534 | for (Run_Index = 1: Run_Index <= Number_Of_Runs: Run_Index++)
535 | {
536 | Proc_5();
537 | Proc_4();
538 | Int_1_Loc = 2;
539 | Int_2_Loc = 3;
540 | strcpy (Str_2_Loc, String2);
541 | Enum_Loc = Ident_2;
542 | Bool_Glob = ~~Func_2 (Str_1_Loc, Str_2_Loc);
543 | while (Int_1_Loc < Int_2_Loc)
544 | {
545 | Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
546 | Int_3_Loc = Proc_7 (Int_1_Loc, Int_2_Loc);
547 | Int_1_Loc ++;
548 | }
549 | Proc_8 (Arr_1_Glob, Int_1_Loc, Int_3_Loc);
550 | Proc_1 (Ptr_Glob);
551 | for (Ch_Index = 'A': Ch_Index <= Ch_2_Glob: Ch_Index++)
552 | {
553 | if (Enum_Loc == Func_1 (Ch_Index, 'C'))
554 | {
555 | Enum_Loc=Proc_6 (Ident_1);
556 | strcpy (Str_2_Loc, String3);
557 | Int_2_Loc = Run_Index;
558 | Int_Glob = Run_Index;
559 | }
560 | }
561 | Int_2_Loc = Int_2_Loc * Int_1_Loc;
562 | Int_1_Loc = Int_2_Loc / Int_3_Loc;
563 | Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
564 | Int_1_Loc = Proc_2 (Int_1_Loc);
565 | }
566 | @print "End Dhrystone^^";
567 | @show_status;
568 |
569 | @print "Int_Glob: ";
570 | @print_num Int_Glob;
571 | @print " should be 5^";
572 | @print "Bool_Glob: ";
573 | @print_num Bool_Glob;
574 | @print " should be 1^";
575 | @print "Ch_1_Glob: '";
576 | @print_char Ch_1_Glob;
577 | @print "' should be 'A'^";
578 | @print "Ch_2_Glob: '";
579 | @print_char Ch_2_Glob;
580 | @print "' should be 'B'^";
581 | @print "Arr_1_Glob[8]: ";
582 | temp=Arr_1_Glob-->8;
583 | @print_num temp;
584 | @print " should be 7^";
585 | @print "Arr_2_Glob[8][7]: ";
586 | temp=Arr_2_Glob-->(8*50+7);
587 | @print_num temp;
588 | @print " should be Number_Of_Runs+10^";
589 |
590 | @print "Ptr_Glob->^";
591 | @print " Ptr_Comp: ";
592 | temp=Ptr_Glob-->Ptr_Comp;
593 | @print_num temp;
594 | @new_line;
595 | @print " Discr: ";
596 | temp=Ptr_Glob-->Discr;
597 | @print_num temp;
598 | @print " should be 0^";
599 | @print " Enum_Comp: ";
600 | temp=Ptr_Glob-->Enum_Comp;
601 | @print_num temp;
602 | @print " should be 2^";
603 | @print " Int_Comp: ";
604 | temp=Ptr_Glob-->Int_Comp;
605 | @print_num temp;
606 | @print " should be 17^";
607 | @print " Str_Comp: ";
608 | temp=Ptr_Glob+Str_Comp;
609 | PrintString(temp);
610 | @print " should be DHRYSTONE PROGRAM, SOME STRING^";
611 |
612 | @print "Next_Ptr_Glob->^";
613 | @print " Ptr_Comp: ";
614 | temp=Next_Ptr_Glob-->Ptr_Comp;
615 | @print_num temp;
616 | @print " should be same as above^";
617 | @print " Discr: ";
618 | temp=Next_Ptr_Glob-->Discr;
619 | @print_num temp;
620 | @print " should be 0^";
621 | @print " Enum_Comp: ";
622 | temp=Next_Ptr_Glob-->Enum_Comp;
623 | @print_num temp;
624 | @print " should be 1^";
625 | @print " Int_Comp: ";
626 | temp=Next_Ptr_Glob-->Int_Comp;
627 | @print_num temp;
628 | @print " should be 18^";
629 | @print " Str_Comp: ";
630 | temp=Next_Ptr_Glob+Str_Comp;
631 | PrintString(temp);
632 | @print " should be DHRYSTONE PROGRAM, SOME STRING^";
633 |
634 | @print "Int_1_Loc: ";
635 | @print_num Int_1_Loc;
636 | @print " should be 5^";
637 | @print "Int_2_Loc: ";
638 | @print_num Int_2_Loc;
639 | @print " should be 13^";
640 | @print "Int_3_Loc: ";
641 | @print_num Int_3_Loc;
642 | @print " should be 7^";
643 | @print "Enum_Loc: ";
644 | @print_num Enum_Loc;
645 | @print " should be 1^";
646 | @print "Str_1_Loc: ";
647 | PrintString(Str_1_Loc);
648 | @print " should be DHRYSTONE PROGRAM, 1'ST STRING^";
649 | @print "Str_2_Loc: ";
650 | PrintString(Str_2_Loc);
651 | @print " should be DHRYSTONE PROGRAM, 2'ND STRING^^";
652 | @show_status;
653 | ];
654 |
655 | [Main
656 | t;
657 | AckermannBench();
658 | Sieve();
659 | Dhrystone();
660 | Mandelbrot();
661 | Mandelbrot32();
662 | ];
663 |
--------------------------------------------------------------------------------
/benchmark/benchmark.txt:
--------------------------------------------------------------------------------
1 | 1.83 -> 11.57 = 9.74s x10 Ackermann => 0.97s for Ackermann
2 | 12.64 -> 22.88 = 10.24s x100 Sieve => 1.02s for x10 Sieve
3 | 6.33 -> 12.44 = 6.11s x10000 Dhrystone => 1636 Dhrystones per second
4 | or 0.93 DMIPS or 0.093 DMIP/MHz
5 |
6 | Core i7 2.7GHz Early 2011 13-inch MacBook Pro
7 | zops 14.25s for x500000 => 35087 => 19.97 DMIPS
8 | Zoom 6.75s for x500000 => 74074 => 42.15 DMIPS
9 | Frotz 6.15s for x500000 => 81300 => 46.27 DMIPS or 0.017 DMIP/MHz
10 |
11 |
12 | 10x Sieve (Lower is better)
13 |
14 | Acorn Archimedes 8Mz ARM2 + Acorn C 0.5
15 | IBM AT (6Mhz) 286 C Compiler 0.7
16 | ** 10MHz Z3 Inform 6 ** 1.0
17 | VAX 11/780 1.4
18 | 10Mhz 8086 + Lattice 3.6
19 | IBM PC (5Mhz) Assembly 4.0
20 | 8Mhz 68000 DR C Compiler 6.0
21 | Apple II Assembly 13.9
22 |
23 |
24 | Ackermann(3,6) (Lower is better)
25 |
26 | ** 10MHz Z3 Inform 6 ** 1.0
27 | 10MHz ERC (Sparc V7) C 1.1
28 | RISC I 7.6MHz 3.2
29 | VAX 11/780 5MHz 5.1
30 | Z8002 6MHz 9.0
31 |
32 |
33 | DMIPS (Higher is better)
34 |
35 | Commodore 64 1MHz 0.02
36 | Apple IIe 1MHz 0.02
37 | Apple Macintosh 8MHz 0.4
38 | Atari ST 8MHz 0.6
39 | ** 10MHz Z3 Inform 6 ** 0.9
40 | IBM PC/AT 286 8MHz 1.3
41 | Compaq 386 16MHz 1.7
42 | ARM2 8MHz 2.6
43 | Acorn RiscPC ARM 610 30 MHz 18.4
44 | Frotz (Early 2011 13-MacBook i7 2.7GHz) 46.2
45 | Early 2011 MacBook Pro i7 2.7GHz O0 5405. or 2.00 DMIPs/MHz
46 | Early 2011 MacBook Pro i7 2.7GHz O3 14121. or 5.23 DMIPs/MHz
47 |
--------------------------------------------------------------------------------
/bios/bios.inf:
--------------------------------------------------------------------------------
1 | Constant Border = 4;
2 | Constant ScrWidth = 240-Border+1;
3 | Constant ScrHeight = 320;
4 | Constant BufferHeight = 630;
5 | Constant LineStride = 30;
6 | Constant LineStrideW = 15;
7 | Constant TextHeight = 10;
8 | Constant KeyboardStartLine = 240;
9 | Constant KeyboardTextSpacing = 20;
10 | Constant KeyboardSepSpacing = 5;
11 | Constant StatusHeight = 10;
12 | ! S c o r e : 0 M o v e s : 0
13 | Constant ScoreXOffset = (240-Border-(4+5+4+3+4+2+4)-(3+6+4+4+4+4+2+4));
14 |
15 | Constant DictionaryOff = 8;
16 |
17 | Constant cAbbrev = 0;
18 | Constant cEncodO = 2;
19 | Constant cEncodB = 4;
20 | Constant cScrenX = 8;
21 | Constant cScrenY = 10;
22 | Constant cFontO = 12;
23 | Constant cFontB = 14;
24 | Constant cBitMpW = 16;
25 | Constant cScroll = 18;
26 | Constant cTextO = 20;
27 | Constant cTextB = 22;
28 | Constant cTextSep = 24;
29 | Constant cScrollStart = 26;
30 | Constant cLastScroll = 28;
31 | Constant MaxTextSize = $400;
32 |
33 | Constant contextW = $D800; ! $1B000
34 |
35 | ! Code should start at $1E580
36 | ! Font + Encoding data is directly before
37 | ! Game must be smaller than $1E000 (120Kb) to fit in BIOS
38 |
39 | ! BitMap buffer is at the top of the high RAM (18.75Kb)
40 | ! Scratch buffer is below the bitmap and is 1Kb
41 | ! Context structure is just below that
42 | ! Bottom of high RAM are the stacks growing up
43 |
44 | [Main;
45 | ! Used as a table to pick out addresses of functions
46 | SysInit();
47 | SysPrint();
48 | SysPrintChar();
49 | SysPrintNum();
50 | SysRead();
51 | SysShowStatus();
52 | SysQuit();
53 | SysException();
54 | ];
55 |
56 | [DecodeText
57 | inputO inputW !inputs
58 | outputO outputB encodingO encodingB alpha charWord c char charOut; !temps
59 |
60 | outputO=cTextO==>contextW;
61 | outputB=cTextB==>contextW;
62 | encodingO=cEncodO==>contextW;
63 | encodingB=cEncodB==>contextW;
64 | do
65 | {
66 | charWord = inputO-->inputW;
67 | for (c=0: c<3: c++)
68 | {
69 | if (c==0) char=(charWord&$7c00)/1024;
70 | else if (c==1) char=(charWord&$3e0)/32;
71 | else char=charWord&31;
72 |
73 | charOut=-1;
74 | if (alpha<=2 && char<=5)
75 | {
76 | if (char==0)
77 | {
78 | charOut=' ';
79 | alpha=0;
80 | }
81 | else
82 | {
83 | if (char>=4)
84 | alpha=char-3;
85 | else
86 | alpha=char+2;
87 | }
88 | }
89 | else if (char==6 && alpha==2)
90 | {
91 | alpha=6;
92 | }
93 | else
94 | {
95 | if (alpha<=2)
96 | {
97 | charOut=encodingO->(encodingB+26*alpha+char-6);
98 | alpha=0;
99 | }
100 | else if (alpha<=5)
101 | {
102 | cTextB==>contextW=outputB;
103 | outputB=DecodeText(0, (cAbbrev==>contextW)-->(32*(alpha-3)+char));
104 | outputB=cTextB==>contextW;
105 | alpha=0;
106 | }
107 | else if (alpha==6)
108 | {
109 | alpha=32+char*32;
110 | }
111 | else
112 | {
113 | charOut=(alpha-32)|char;
114 | alpha=0;
115 | }
116 | }
117 | if (charOut>=0)
118 | {
119 | outputO=>outputB=charOut;
120 | outputB++;
121 | }
122 | }
123 | inputW++;
124 | }
125 | until (charWord<0);
126 | outputO=>outputB=0;
127 |
128 | cTextB==>contextW=outputB;
129 | ];
130 |
131 | [TextToConsole
132 | textO textB
133 | fontO fontB bitmapW char ptr a b w x y checkWrap firstLine;
134 |
135 | x=cScrenX==>contextW;
136 | y=cScrenY==>contextW;
137 | fontO=cFontO==>contextW;
138 | fontB=cFontB==>contextW;
139 | bitmapW=cBitMpW==>contextW;
140 | char=textO=>textB;
141 | if (x~=Border)
142 | checkWrap=1;
143 | firstLine=1;
144 | while (char)
145 | {
146 | if (char<=32)
147 | {
148 | checkWrap=1;
149 | }
150 | else if (checkWrap)
151 | {
152 | w=x;
153 | ptr=textB;
154 | while (textO=>ptr>32)
155 | {
156 | w=w+(fontO->(fontB+(textO=>ptr)*TextHeight));
157 | ptr++;
158 | }
159 | if (w>ScrWidth)
160 | {
161 | x=ScrWidth+1;
162 | }
163 | checkWrap=0;
164 | }
165 | ptr=fontB+char*TextHeight;
166 | w=fontO->ptr;
167 | if (x+w>ScrWidth || char==10)
168 | {
169 | y=y+TextHeight;
170 | if (y>BufferHeight-TextHeight)
171 | y=0;
172 | if (y>(KeyboardStartLine-StatusHeight)-TextHeight || cScrollStart==>contextW)
173 | {
174 | cScrollStart==>contextW=1;
175 | a=cScroll==>contextW;
176 | a=a+TextHeight;
177 | if (a>=BufferHeight)
178 | a=0;
179 | if (a==cLastScroll==>contextW)
180 | {
181 | cScrenY==>contextW=y;
182 | b=UpdateScreen();
183 | b=GetKey();
184 | }
185 | cScroll==>contextW=a;
186 | }
187 | a=y*LineStride;
188 | b=LineStride*5;
189 | while (b)
190 | {
191 | a==>bitmapW=0;
192 | a=a+2;
193 | b--;
194 | }
195 | x=Border;
196 | firstLine=0;
197 | }
198 | if (x~=Border || char>32 || firstLine)
199 | {
200 | if (cTextSep==>contextW==0 || char==124)
201 | {
202 | a=7-(x&7);
203 | b=2;
204 | while (a)
205 | {
206 | b=b*2;
207 | a--;
208 | }
209 | a=x/8+y*LineStride;
210 | for (char=0: char<9: char++)
211 | {
212 | ptr++;
213 | a==>bitmapW=(a==>bitmapW)|((fontO->ptr)*b);
214 | a=a+LineStride;
215 | }
216 | }
217 | x=x+w;
218 | }
219 | textB++;
220 | char=textO=>textB;
221 | }
222 | cScrenX==>contextW=x;
223 | cScrenY==>contextW=y;
224 | ];
225 |
226 | [UpdateScreen
227 | ptr size sizeW bitmapW scroll; !temps
228 | bitmapW=cBitMpW==>contextW;
229 | scroll=cScroll==>contextW;
230 | cLastScroll==>contextW=cScrenY==>contextW;
231 | @write_reg 32 0;
232 | @write_reg 33 0;
233 | @blit1 0 LineStride $49c2 $49c2;
234 | @write_reg 32 0;
235 | @write_reg 33 1;
236 | ptr=bitmapW+(LineStrideW*BufferHeight);
237 | sizeW=LineStride*(StatusHeight-1);
238 | @blit1 ptr sizeW $49c2 $ff14;
239 | @write_reg 32 0;
240 | @write_reg 33 StatusHeight;
241 | ptr=bitmapW+(LineStrideW*scroll);
242 | sizeW=LineStride*(KeyboardStartLine-StatusHeight);
243 | if (scroll > BufferHeight - (KeyboardStartLine-StatusHeight))
244 | {
245 | size=BufferHeight-scroll;
246 | sizeW=LineStride*size;
247 | @blit1 ptr sizeW $ff14 $49c2;
248 | ptr=bitmapW;
249 | size=size+StatusHeight;
250 | @write_reg 32 0;
251 | @write_reg 33 size;
252 | sizeW=LineStride*(KeyboardStartLine-size);
253 | }
254 | @blit1 ptr sizeW $ff14 $49c2;
255 | ];
256 |
257 | [InitScreenRegs;
258 | @write_reg $0000 $0000; ! Setting primes the screen for data
259 | @write_reg $0001 $0100;
260 | @write_reg $0002 $0700;
261 | @write_reg $0003 $1030;
262 | @write_reg $0008 $0302;
263 | @write_reg $0009 $0000;
264 | @write_reg $000A $0008;
265 | @write_reg $0010 $0790;
266 | @write_reg $0011 $0005;
267 | @write_reg $0012 $0000;
268 | @write_reg $0013 $0000;
269 | @write_reg $0010 $12B0;
270 | @write_reg $0011 $0007;
271 | @write_reg $0012 $008C;
272 | @write_reg $0013 $1700;
273 | @write_reg $0029 $0022;
274 | @write_reg $0030 $0000;
275 | @write_reg $0031 $0505;
276 | @write_reg $0032 $0205;
277 | @write_reg $0035 $0206;
278 | @write_reg $0036 $0408;
279 | @write_reg $0037 $0000;
280 | @write_reg $0038 $0504;
281 | @write_reg $0039 $0206;
282 | @write_reg $003C $0206;
283 | @write_reg $003D $0408;
284 | @write_reg $0050 $0000;
285 | @write_reg $0051 $00EF;
286 | @write_reg $0052 $0000;
287 | @write_reg $0053 $013F;
288 | @write_reg $0060 $A700;
289 | @write_reg $0061 $0001;
290 | @write_reg $0090 $0033;
291 | @write_reg $0081 $0000;
292 | @write_reg $0082 $0000;
293 | @write_reg $0083 $013F;
294 | ];
295 |
296 | [InitContext;
297 | cAbbrev==>contextW=$18-->0;
298 | cEncodO==>contextW=$FFFF; !1E500
299 | cEncodB==>contextW=$E501;
300 | cScrenX==>contextW=Border;
301 | !cScrenY==>contextW=0;
302 | cFontO ==>contextW=$FFFF; ! $1E000
303 | cFontB ==>contextW=$E001;
304 | cBitMpW==>contextW=-(BufferHeight+StatusHeight)*LineStrideW;
305 | !cScroll==>contextW=0;
306 | cTextO==>contextW=cBitMpW==>contextW;
307 | cTextB==>contextW=cBitMpW==>contextW-MaxTextSize;
308 | !cTextSep==>contextW=0;
309 | !cScrollStart==>contextW=0;
310 | !cLastScroll==>contextW=0;
311 | ];
312 |
313 | [SysPrint
314 | printO printW;
315 | printW=DecodeText(printO&1, printW);
316 | if (printO&2) ! Doing print_ret so need to add a newline
317 | {
318 | printO=cTextO==>contextW;
319 | printW=cTextB==>contextW;
320 | printO=>printW=10;
321 | printW++;
322 | printO=>printW=0;
323 | }
324 | cTextB==>contextW=(cBitMpW==>contextW-MaxTextSize); ! reset buffer as Decode modifies it
325 | printW=TextToConsole(cTextO==>contextW, cTextB==>contextW);
326 | rtrue;
327 | ];
328 |
329 | [SysPrintChar
330 | char
331 | textO textB;
332 | textO=cTextO==>contextW;
333 | textB=cTextB==>contextW;
334 | textO=>textB=char;
335 | textB++;
336 | textO=>textB=0;
337 | char=TextToConsole(textO, textB-1);
338 | rtrue;
339 | ];
340 |
341 | [SysPrintNum
342 | num
343 | digit writeStarted demon temp;
344 | demon=10000;
345 | if (num<0)
346 | {
347 | temp=SysPrintChar('-');
348 | demon=-demon;
349 | }
350 | while (1)
351 | {
352 | digit=num/demon;
353 | if (digit<0) ! Not sure why I need to do this but fixes -32678
354 | digit=-digit;
355 | if (digit>0 || writeStarted || demon==1 || demon==-1)
356 | {
357 | temp=SysPrintChar('0'+digit);
358 | writeStarted=1;
359 | if (demon==1 || demon==-1)
360 | break;
361 | }
362 | num=num-digit*demon;
363 | demon=demon/10;
364 | }
365 | rtrue;
366 | ];
367 |
368 | [DrawKeyboard
369 | size ptr line i;
370 | ! Use print system to make keyboard bitmaps then blit to screen
371 | for (: i<2: i++)
372 | {
373 | cTextSep==>contextW=i;
374 | @print " q | w | e | r | t | y | u | i | o | p^";
375 | @print " a | s | d | f | g | h | j | k | l^";
376 | @print " z | x | c | v | b | n | m | ,^";
377 | @print " Delete | Space | Enter^";
378 | }
379 | cTextSep==>contextW=0;
380 | @write_reg 32 0;
381 | size=LineStride*TextHeight;
382 | ptr=cBitMpW==>contextW;
383 | i=ptr+4*TextHeight*LineStrideW;
384 | line=KeyboardStartLine+1+KeyboardSepSpacing;
385 | while (ptrcontextW;
415 | i=ptr+LineStrideW*TextHeight*8;
416 | while (ptrptr=0;
419 | ptr++;
420 | }
421 | cScrenY==>contextW=0;
422 | ];
423 |
424 | [GameSelect
425 | palette
426 | imageO imageP c col count p x y winW winWMax;
427 |
428 | c=320;
429 | @write_reg 32 0;
430 | @write_reg 33 0;
431 | while (c)
432 | {
433 | p=240;
434 | while (p)
435 | {
436 | col=0;
437 | if ((c+p)&7 && (c-p)&7)
438 | col=((0-->(palette+c))*(0-->(palette+(p+40))))&$7E0;
439 | p--;
440 | @write_reg 34 col;
441 | }
442 | c--;
443 | y++;
444 | }
445 | palette=palette+320;
446 |
447 | imageP=(palette+128)*2+1;
448 | imageO=$FFFF;
449 | p=4;
450 | while (p)
451 | {
452 | winW=127;
453 | winWMax=226;
454 | if (p&1)
455 | {
456 | winW=13;
457 | winWMax=112;
458 | }
459 | y=167;
460 | if (p&2)
461 | {
462 | y=33;
463 | }
464 | @write_reg $0050 winW;
465 | @write_reg $0051 winWMax;
466 | @write_reg 32 winW;
467 | @write_reg 33 y;
468 | count=100*120;
469 | while (count>0)
470 | {
471 | c=imageO->imageP;
472 | col=0-->(palette+(c&$7F));
473 | imageP++;
474 | if (c&$80)
475 | {
476 | c=imageO->imageP;
477 | imageP++;
478 | count=count-c;
479 | while (c)
480 | {
481 | @write_reg 34 col;
482 | c--;
483 | }
484 | }
485 | else
486 | {
487 | @write_reg 34 col;
488 | count--;
489 | }
490 | }
491 | p--;
492 | }
493 | @write_reg $0050 $0000;
494 | @write_reg $0051 $00EF;
495 | @write_reg $0007 $0133; ! Turn on the screen
496 |
497 | do !wait for touch
498 | {
499 | @get_touch $93 -> x;
500 | if (x<1000)
501 | y--;
502 | else
503 | y=10;
504 | } until (y==0);
505 | @get_touch $95 -> x; ! x
506 | @get_touch $1A -> y; ! y
507 | p=0;
508 | if (x>510)
509 | p++;
510 | if (y>508)
511 | p=p+2;
512 |
513 | if (p>0)
514 | @switch_bank p;
515 | ];
516 |
517 | [MandelbrotPalette;
518 | @db 0;
519 | @db $f800; @db $fb80; @db $f800; @db $fc00;
520 | @db $f800; @db $fc00; @db $f800; @db $fc00;
521 | @db $ff80; @db $df80; @db $bf80; @db $9f80;
522 | @db $7f80; @db $5f80; @db $3f80; @db $1f80;
523 | @db $1f81; @db $1f85; @db $1f89; @db $1f8d;
524 | @db $1f91; @db $1f96; @db $1f9a; @db $1f9e;
525 | @db $1d9f; @db $191f; @db $151f; @db $111f;
526 | @db $0d1f; @db $091f; @db $049f; @db $009f;
527 | ];
528 |
529 | [Mandelbrot
530 | x y xtemp ytemp x0 y0 x00 y00 i;
531 | @write_reg 32 0;
532 | @write_reg 33 StatusHeight;
533 | y0=60;
534 | do
535 | {
536 | x0=-120;
537 | y00=y0*40;
538 | do
539 | {
540 | xtemp=0;
541 | ytemp=0;
542 | y=0;
543 | i=0;
544 | x00=x0*20;
545 | do
546 | {
547 | i++;
548 | xtemp=xtemp-ytemp+y00;
549 | y=(x*y+x00)/32;
550 | if (y>=2*64 || y<=-2*64)
551 | break;
552 | x=xtemp/64;
553 | if (x>=2*64 || x<=-2*64)
554 | break;
555 | xtemp=x*x;
556 | ytemp=y*y;
557 | } until ( xtemp + ytemp >= 64*64*4 || i>=32);
558 | i=1-->(i+MandelbrotPalette);
559 | @write_reg 34 i;
560 | x0++;
561 | } until (x0>=120);
562 | y0--;
563 | } until (y0==60-(KeyboardStartLine-StatusHeight));
564 | @write_reg $0007 $0133; ! Turn on the screen
565 | x=GetKey();
566 | ];
567 |
568 | [SpaceInvadersSpriteData;
569 | !squid1 Offset:0
570 | @db 8*(8|16);
571 | @db 8*(4|8|16|32);
572 | @db 8*(2|4|8|16|32|64);
573 | @db 8*(1|2|8|16|64|128);
574 | @db 8*(1|2|4|8|16|32|64|128);
575 | @db 8*(4|32);
576 | @db 8*(2|8|16|64);
577 | @db 8*(1|4|32|128);
578 | !ant1 Offset:16
579 | @db 4*(4|256);
580 | @db 4*(8|128);
581 | @db 4*(4|8|16|32|64|128|256);
582 | @db 4*(2|4|16|32|64|256|512);
583 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024);
584 | @db 4*(1|4|8|16|32|64|128|256|1024);
585 | @db 4*(1|4|256|1024);
586 | @db 4*(8|16|64|128);
587 | !bug1 Offset:32
588 | @db 4*(16|32|64|128);
589 | @db 4*(2|4|8|16|32|64|128|256|512|1024);
590 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024|2048);
591 | @db 4*(1|2|4|32|64|512|1024|2048);
592 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024|2048);
593 | @db 4*(4|8|16|128|256|512);
594 | @db 4*(2|4|32|64|512|1024);
595 | @db 4*(4|8|256|512);
596 | !squid2 Offset:48
597 | @db 8*(8|16);
598 | @db 8*(4|8|16|32);
599 | @db 8*(2|4|8|16|32|64);
600 | @db 8*(1|2|8|16|64|128);
601 | @db 8*(1|2|4|8|16|32|64|128);
602 | @db 8*(2|8|16|64);
603 | @db 8*(1|128);
604 | @db 8*(2|64);
605 | !ant2 Offset:64
606 | @db 4*(4|256);
607 | @db 4*(1|8|128|1024);
608 | @db 4*(1|4|8|16|32|64|128|256|1024);
609 | @db 4*(1|2|4|16|32|64|256|512|1024);
610 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024);
611 | @db 4*(2|4|8|16|32|64|128|256|512);
612 | @db 4*(4|256);
613 | @db 4*(2|512);
614 | !bug2 Offset:80
615 | @db 4*(16|32|64|128);
616 | @db 4*(2|4|8|16|32|64|128|256|512|1024);
617 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024|2048);
618 | @db 4*(1|2|4|32|64|512|1024|2048);
619 | @db 4*(1|2|4|8|16|32|64|128|256|512|1024|2048);
620 | @db 4*(8|16|128|256);
621 | @db 4*(4|8|32|64|256|512);
622 | @db 4*(1|2|1024|2048);
623 | !ship Offset:96
624 | @db 2*(64);
625 | @db 2*(32|64|128);
626 | @db 2*(32|64|128);
627 | @db 2*(2|4|8|16|32|64|128|256|512|1024|2048);
628 | @db 2*(1|2|4|8|16|32|64|128|256|512|1024|2048|4096);
629 | @db 2*(1|2|4|8|16|32|64|128|256|512|1024|2048|4096);
630 | @db 2*(1|2|4|8|16|32|64|128|256|512|1024|2048|4096);
631 | @db 2*(1|2|4|8|16|32|64|128|256|512|1024|2048|4096);
632 | !explosion Offset:112
633 | @db 4*(16|256);
634 | @db 4*(2|32|128|2048);
635 | @db 4*(4|1024);
636 | @db 4*(8|512);
637 | @db 4*(1|2|2048); !|4096); Should really but messes with clear
638 | @db 4*(8|512);
639 | @db 4*(4|32|128|1024);
640 | @db 4*(2|16|256|2048);
641 | !ufo Offset:128
642 | @db $03c0;
643 | @db $0ff0;
644 | @db $3ffc;
645 | @db $6db6;
646 | @db $ffff;
647 | @db $3bdc;
648 | @db $1008;
649 | !base Offset:142
650 | @db $0FFF; @db $C000;
651 | @db $1FFF; @db $E000;
652 | @db $3FFF; @db $F000;
653 | @db $7FFF; @db $F800;
654 | @db $FFFF; @db $FC00;
655 | @db $FFFF; @db $FC00;
656 | @db $FFFF; @db $FC00;
657 | @db $FFFF; @db $FC00;
658 | @db $FFFF; @db $FC00;
659 | @db $FFFF; @db $FC00;
660 | @db $FFFF; @db $FC00;
661 | @db $FFFF; @db $FC00;
662 | @db $FE03; @db $FC00;
663 | @db $FC01; @db $FC00;
664 | @db $F800; @db $FC00;
665 | @db $F800; @db $FC00;
666 | ];
667 |
668 | [SpaceInvaders
669 | sprites x y i k s xd u c sx t p l ud j;
670 |
671 | !copy sprite data
672 | sprites=contextW-MaxTextSize/2;
673 | i=SpaceInvadersSpriteData;
674 | k=i+71;
675 | c=sprites;
676 | while (ic=1-->i;
679 | i++;
680 | c++;
681 | }
682 | !copy 4x bases as will get destroyed
683 | c=sprites+135;
684 | k=i+32;
685 | t=4;
686 | while (t)
687 | {
688 | i=SpaceInvadersSpriteData+71;
689 | while (ic=1-->i;
692 | i++;
693 | c++;
694 | }
695 | t--;
696 | }
697 |
698 | s=sprites;
699 | k=s+5;
700 | t=26;
701 | c=234;
702 | while (ss=0; !dying
705 | 200==>s=8; !startX
706 | 210==>s=t; !startY
707 | 220==>s=$7ff; !alive
708 | c==>sprites=0; !bullet direction
709 | s++;
710 | t=t+16;
711 | c=c+6;
712 | }
713 | 184==>sprites=0; ! dead timer
714 | 186==>sprites=0; ! ufo dead timer
715 | 188==>sprites=255; ! ufo position
716 |
717 | @write_reg $0050 0;
718 | @write_reg $0051 $EF;
719 | @write_reg 32 0;
720 | @write_reg 33 StatusHeight;
721 | @blit1 0 6900 0 0;
722 | xd=2;
723 | sx=115;
724 | l=3;
725 | ud=1;
726 | while (1)
727 | {
728 | if (random(50)==1 && ~~184==>sprites)
729 | {
730 | x=random(11)-1;
731 | k=x;
732 | t=1;
733 | while (k)
734 | {
735 | t=t*2;
736 | k--;
737 | }
738 | s=228;
739 | y=0;
740 | for (k=0: k<5: k++)
741 | {
742 | if (s==>sprites&t)
743 | {
744 | x=(s-20)==>sprites+16*x;
745 | y=(s-10)==>sprites+6;
746 | break;
747 | }
748 | s=s-2;
749 | }
750 | if (y)
751 | {
752 | for (k=0: k<4: k++)
753 | {
754 | s=236+6*k;
755 | if (~~(s+4)==>sprites)
756 | {
757 | s==>sprites=x+8;
758 | (s+2)==>sprites=y;
759 | (s+4)==>sprites=1;
760 | break;
761 | }
762 | }
763 | }
764 | }
765 |
766 | x=188==>sprites;
767 | if (x<240-16)
768 | {
769 | i=2;
770 | while (i)
771 | {
772 | @write_reg $0050 x;
773 | @write_reg 32 x;
774 | y=x+15;
775 | @write_reg $0051 y;
776 | @write_reg 33 16;
777 | i--;
778 | if (i)
779 | {
780 | @blit1 0 14 0 0;
781 | x++;
782 | 188==>sprites=x;
783 | if (x>=240-16)
784 | break;
785 | }
786 | else
787 | {
788 | s=sprites+64;
789 | x=186==>sprites;
790 | k=$f800;
791 | if (x)
792 | {
793 | s=sprites+56;
794 | x--;
795 | 186==>sprites=x;
796 | if (~~x)
797 | {
798 | 188==>sprites=255;
799 | k=0;
800 | }
801 | }
802 | @blit1 s 14 0 k;
803 | }
804 | }
805 | }
806 | else if (random(2000)==1)
807 | {
808 | 188==>sprites=0;
809 | }
810 |
811 | ud--;
812 | if (ud<=0)
813 | {
814 | k=0;
815 | do
816 | {
817 | u--;
818 | if (u<0)
819 | u=4;
820 | x=220==>(sprites+u);
821 | k++;
822 | } until (x || k>5);
823 | if (~~x)
824 | {
825 | break; ! all enemies dead
826 | }
827 | if (x&$007)
828 | ud++;
829 | if (x&$038)
830 | ud++;
831 | if (x&$1C0)
832 | ud++;
833 | if (x&$600)
834 | ud++;
835 | k=5;
836 | while (k)
837 | {
838 | k--;
839 | t=220==>(sprites+k);
840 | if (t)
841 | j=k;
842 | x=x|t;
843 | }
844 | k=x;
845 | c=8;
846 | while (~~(x&1))
847 | {
848 | c=c-16;
849 | x=x/2;
850 | }
851 | t=54;
852 | while (~~(k&$400))
853 | {
854 | k=k*2;
855 | t=t+16;
856 | }
857 | x=200==>(sprites+u)+xd;
858 | if (x>t || x(sprites+u);
861 | @write_reg $0050 0;
862 | @write_reg $0051 $EF;
863 | @write_reg 32 0;
864 | @write_reg 33 y;
865 | @blit1 0 240 0 0;
866 | 210==>(sprites+u)=y+10;
867 | if (u==j)
868 | xd=-xd;
869 | if (y>202) !touched the ship row
870 | {
871 | if (~~184==>sprites)
872 | {
873 | 184==>sprites=150;
874 | }
875 | l=0;
876 | }
877 | }
878 | 200==>(sprites+u)=x;
879 | }
880 | s=sprites+135;
881 | for (k=0: k<4: k++)
882 | {
883 | x=35+k*50;
884 | @write_reg $50 x;
885 | @write_reg 32 x;
886 | x=x+31;
887 | @write_reg $51 x;
888 | @write_reg 33 195;
889 | @blit1 s 64 0 $7E0;
890 | s=s+32;
891 | }
892 | for (k=0: k<5: k++)
893 | {
894 | x=200==>(sprites+k);
895 | y=210==>(sprites+k);
896 | p=220==>(sprites+k);
897 | c=y/8;
898 | c=(31-c)*32*64+c+1;
899 | s=sprites;
900 | if (x&2)
901 | s=s+24;
902 | if (k>=3)
903 | s=s+16;
904 | else if (k>=1)
905 | s=s+8;
906 | t=1;
907 | for (i=0: i<11: i++)
908 | {
909 | @write_reg $0050 x;
910 | @write_reg 32 x;
911 | @write_reg 33 y;
912 | x=x+15;
913 | @write_reg $0051 x;
914 | x++;
915 | if (p&t)
916 | {
917 | j=190==>(sprites+k);
918 | if (j&t)
919 | {
920 | if (j&$8000)
921 | {
922 | @blit1 s 16 0 0;
923 | p=p&~t;
924 | }
925 | else
926 | {
927 | j=sprites+56;
928 | @blit1 j 16 0 c;
929 | }
930 | }
931 | else
932 | {
933 | @blit1 s 16 0 c;
934 | }
935 | }
936 | t=t*2;
937 | }
938 | 220==>(sprites+k)=p;
939 | p=190==>(sprites+k);
940 | if (p)
941 | {
942 | if (p&$8000)
943 | p=0;
944 | else
945 | p=p+$1000;
946 | 190==>(sprites+k)=p;
947 | }
948 | }
949 | s=230;
950 | for (j=-3: j<5: j++)
951 | {
952 | k=j;
953 | if (k<0)
954 | k=0;
955 | x=(s+4)==>sprites;
956 | if (x)
957 | {
958 | y=(s+2)==>sprites;
959 | i=s==>sprites;
960 | @write_reg 32 i;
961 | @write_reg $50 i;
962 | @write_reg $51 i;
963 | @write_reg 33 y;
964 | @write_reg 34 0;
965 | @write_reg 34 0;
966 | if (x>0)
967 | {
968 | @write_reg 34 0;
969 | @write_reg 34 0;
970 | }
971 | if (k) !not player bullet
972 | {
973 | if (234==>sprites)
974 | {
975 | t=232==>sprites;
976 | if (y<=t && y+4>=t)
977 | {
978 | t=230==>sprites;
979 | if (i<=t+2 && i>=t-2)
980 | {
981 | ! two bullets hit
982 | 234==>sprites=0;
983 | (s+4)==>sprites=0;
984 | ! erase player bullet
985 | @write_reg 32 t;
986 | @write_reg $50 t;
987 | @write_reg $51 t;
988 | t=232==>sprites;
989 | @write_reg 33 t;
990 | @write_reg 34 0;
991 | @write_reg 34 0;
992 | }
993 | }
994 | }
995 | }
996 | y=y+x;
997 | (s+2)==>sprites=y;
998 | if (x<0)
999 | {
1000 | for (i=0: i<5: i++)
1001 | {
1002 | t=210==>(sprites+i);
1003 | if (y>=t && ysprites-200==>(sprites+i);
1006 | if (t>=0 && t<11*16)
1007 | {
1008 | p=1;
1009 | c=0;
1010 | while (t>16)
1011 | {
1012 | p=p*2;
1013 | t=t-16;
1014 | c=c+16;
1015 | }
1016 | if (t>2 && t<14)
1017 | {
1018 | if (220==>(sprites+i)&p)
1019 | {
1020 | 190==>(sprites+i)=190==>(sprites+i)|p;
1021 | (s+4)==>sprites=0;
1022 | p=200==>(sprites+i)+c;
1023 | t=210==>(sprites+i);
1024 | break;
1025 | }
1026 | }
1027 | }
1028 | }
1029 | }
1030 | }
1031 | if (y>=195 && y<195+16)
1032 | {
1033 | t=s==>sprites-35;
1034 | if (t>=0 && t<4*50)
1035 | {
1036 | i=t/50;
1037 | t=t-i*50;
1038 | if (t<22)
1039 | {
1040 | k=(270-1)+(64*i)+(4*(y-195));
1041 | t=t+7;
1042 | while (t>=12)
1043 | {
1044 | t=t-8;
1045 | k=k++;
1046 | }
1047 | p=1;
1048 | t=15-t;
1049 | while (t)
1050 | {
1051 | t--;
1052 | p=p*2;
1053 | }
1054 | t=k==>sprites;
1055 | if (t&p)
1056 | {
1057 | p=p/8;
1058 | k==>sprites=t&~(p*(1|2|4|8|16));
1059 | if (y<195+15)
1060 | (k+4)==>sprites=(k+4)==>sprites&~(p*(2|4|8));
1061 | if (y<195+14)
1062 | (k+8)==>sprites=(k+8)==>sprites&~(p*(1|4|16));
1063 | if (y>195)
1064 | (k-4)==>sprites=(k-4)==>sprites&~(p*(2|4|8));
1065 | if (y>196)
1066 | (k-8)==>sprites=(k-8)==>sprites&~(p*(1|4|16));
1067 | (s+4)==>sprites=0;
1068 | }
1069 | }
1070 | }
1071 | }
1072 | i=s==>sprites;
1073 | if (x>0 && i>sx+1 && i=220 && y<217+8)
1074 | {
1075 | (s+4)==>sprites=0;
1076 | if (~~184==>sprites)
1077 | {
1078 | 184==>sprites=150;
1079 | l--;
1080 | }
1081 | }
1082 | ;
1083 | if (x<0 && y>=16 && y<=16+7 && i>=188==>sprites && i<188==>sprites+16)
1084 | {
1085 | (s+4)==>sprites=0;
1086 | 186==>sprites=8;
1087 | }
1088 | if (y>=217+8 || y<=StatusHeight)
1089 | (s+4)==>sprites=0;
1090 | if ((s+4)==>sprites)
1091 | {
1092 | @write_reg 33 y;
1093 | @write_reg 34 $7E0;
1094 | @write_reg 34 $7E0;
1095 | if (x>0)
1096 | {
1097 | @write_reg 34 $7E0;
1098 | @write_reg 34 $7E0;
1099 | }
1100 | }
1101 | }
1102 | if (j>=0)
1103 | s=s+6;
1104 | }
1105 | if (~~184==>sprites)
1106 | {
1107 | @get_touch $93 -> x;
1108 | if (x<1000)
1109 | {
1110 | @get_touch $1A -> y; ! y
1111 | if (y<720)
1112 | {
1113 | @get_touch $95 -> x; ! x
1114 | x=x-90;
1115 | x=x*2;
1116 | x=x/7;
1117 | x=x-7;
1118 | if (x>sx)
1119 | sx++;
1120 | else
1121 | sx--;
1122 | }
1123 | else if (234==>sprites==0)
1124 | {
1125 | 230==>sprites=sx+8;
1126 | 232==>sprites=217;
1127 | 234==>sprites=-1;
1128 | }
1129 | }
1130 | }
1131 | @write_reg $0050 sx;
1132 | @write_reg 32 sx;
1133 | x=sx+15;
1134 | @write_reg $0051 x;
1135 | @write_reg 33 218;
1136 | s=sprites+96/2;
1137 | k=$7e0;
1138 | if (184==>sprites)
1139 | {
1140 | if (184==>sprites>130)
1141 | s=sprites+56;
1142 | else
1143 | k=0;
1144 | 184==>sprites=184==>sprites-1;
1145 | }
1146 | else if (l<=0)
1147 | {
1148 | break;
1149 | }
1150 | @blit1 s 16 0 k;
1151 |
1152 | s=sprites+96/2;
1153 | for (k=0: k<3: k++)
1154 | {
1155 | x=10+16*k;
1156 | @write_reg $0050 x;
1157 | @write_reg 32 x;
1158 | x=x+15;
1159 | @write_reg $0051 x;
1160 | @write_reg 33 230;
1161 | if (k0)
1177 | @print "You win!^^";
1178 | else
1179 | @print "Bad luck.^^";
1180 | ];
1181 |
1182 | [SysInit
1183 | temp;
1184 | temp=InitContext();
1185 | temp=InitScreenRegs();
1186 | if (~~($FFFF->$E580))
1187 | temp=GameSelect($B400);
1188 | temp=DrawKeyboard();
1189 | @new_line;
1190 | ! Set flags
1191 | 0->1=(0->1&$8f)|$40; ! Status line availible, Screen splitting not availible + variable pitch font
1192 | 0->10=0->10&$fe; ! Transcripting off
1193 | ];
1194 |
1195 | [FindInDictionary
1196 | text parse
1197 | encodingO encodingB textO textB count limit i a c;
1198 |
1199 | encodingO=cEncodO==>contextW;
1200 | textO=cTextO==>contextW;
1201 | textB=cTextB==>contextW;
1202 | limit=textB+6;
1203 |
1204 | i=6;
1205 | while (i)
1206 | {
1207 | i--;
1208 | textO=>(textB+i)=5;
1209 | }
1210 |
1211 | count=parse->2;
1212 | text=text+parse->3;
1213 |
1214 | while (count && textB0;
1217 | text++;
1218 | count--;
1219 | if (c==32)
1220 | {
1221 | textO=>textB=0;
1222 | textB++;
1223 | }
1224 | else
1225 | {
1226 | i=0;
1227 | a=3;
1228 | encodingB=cEncodB==>contextW;
1229 | while (c~=encodingO->encodingB)
1230 | {
1231 | encodingB++;
1232 | i++;
1233 | if (i==26)
1234 | {
1235 | if (a==5)
1236 | break;
1237 | a++;
1238 | i=0;
1239 | }
1240 | }
1241 | if (a>3)
1242 | {
1243 | textO=>textB=a;
1244 | textB++;
1245 | }
1246 | if (i==26)
1247 | {
1248 | textO=>textB=6;
1249 | textB++;
1250 | textO=>textB=(c/32)&$1F;
1251 | textB++;
1252 | textO=>textB=c&$1F;
1253 | textB++;
1254 | }
1255 | else
1256 | {
1257 | textO=>textB=6+i;
1258 | textB++;
1259 | }
1260 | }
1261 | }
1262 |
1263 | textB=cTextB==>contextW;
1264 | a=textO=>(textB )*1024+textO=>(textB+1)*32+textO=>(textB+2);
1265 | c=textO=>(textB+3)*1024+textO=>(textB+4)*32+textO=>(textB+5);
1266 | c=c|$8000;
1267 |
1268 | i=DictionaryOff-->0;
1269 | parse-->0=0;
1270 | i=i+i->0+1;
1271 | limit=i->0;
1272 | i++;
1273 | count=i-->0;
1274 | i=i+2;
1275 | while (count)
1276 | {
1277 | if (i-->0==a && i-->1==c)
1278 | {
1279 | parse-->0=i;
1280 | break;
1281 | }
1282 | i=i+limit;
1283 | count--;
1284 | }
1285 | ];
1286 |
1287 | [UpdateStatus
1288 | x y scoreX;
1289 |
1290 | x=cBitMpW==>contextW+BufferHeight*LineStrideW;
1291 | y=StatusHeight*LineStrideW;
1292 | while (y)
1293 | {
1294 | 0==>x=0;
1295 | x++;
1296 | y--;
1297 | }
1298 |
1299 | x=cScrenX==>contextW;
1300 | y=cScrenY==>contextW;
1301 | cScrenX==>contextW=Border;
1302 | cScrenY==>contextW=BufferHeight;
1303 | @print_obj sys__glob0;
1304 | scoreX=ScoreXOffset;
1305 | if (sys__glob1>=1000)
1306 | scoreX=scoreX-12;
1307 | else if (sys__glob1>=100)
1308 | scoreX=scoreX-8;
1309 | else if (sys__glob1>=10)
1310 | scoreX=scoreX-4;
1311 | if (sys__glob2>=1000)
1312 | scoreX=scoreX-12;
1313 | else if (sys__glob2>=100)
1314 | scoreX=scoreX-8;
1315 | else if (sys__glob2>=10)
1316 | scoreX=scoreX-4;
1317 | cScrenX==>contextW=scoreX;
1318 | print "Score:";
1319 | @print_num sys__glob1;
1320 | print " Moves:";
1321 | @print_num sys__glob2;
1322 | cScrenX==>contextW=x;
1323 | cScrenY==>contextW=y;
1324 | ];
1325 |
1326 | [GetKey
1327 | x y
1328 | startY scrollStart scrollLimit scroll;
1329 |
1330 | startY=1024;
1331 | scrollLimit=cScroll==>contextW;
1332 | while (1)
1333 | {
1334 | scrollStart=scroll;
1335 | do !wait for not-touch
1336 | {
1337 | if (startY~=1024)
1338 | {
1339 | @get_touch $1A -> y; ! y
1340 | scroll=scrollStart+(startY-y)/3;
1341 | if (scroll>0)
1342 | {
1343 | scroll=0;
1344 | }
1345 | else if (scroll<-BufferHeight+KeyboardStartLine-StatusHeight)
1346 | {
1347 | scroll=-BufferHeight+KeyboardStartLine-StatusHeight;
1348 | }
1349 | cScroll==>contextW=((scrollLimit+scroll+BufferHeight+BufferHeight)%BufferHeight);
1350 | x=UpdateScreen();
1351 | }
1352 | @get_touch $93 -> x;
1353 | } until (x>=1000);
1354 | y=10;
1355 | do !wait for touch
1356 | {
1357 | @get_touch $93 -> x;
1358 | if (x<1000)
1359 | y--;
1360 | else
1361 | y=10;
1362 | } until (y==0);
1363 | startY=1024;
1364 | @get_touch $95 -> x; ! x
1365 | @get_touch $1A -> y; ! y
1366 | if (y>=870)
1367 | {
1368 | if (x<=374) ! delete
1369 | return 0;
1370 | if (x<=649)
1371 | return ' ';
1372 | return 10;
1373 | }
1374 | else if (y>=820)
1375 | {
1376 | if (x<=256)
1377 | return 'z';
1378 | if (x<=340)
1379 | return 'x';
1380 | if (x<=423)
1381 | return 'c';
1382 | if (x<=506)
1383 | return 'v';
1384 | if (x<=590)
1385 | return 'b';
1386 | if (x<=673)
1387 | return 'n';
1388 | if (x<=753)
1389 | return 'm';
1390 | return ',';
1391 | }
1392 | else if (y>=770)
1393 | {
1394 | if (x<=215)
1395 | return 'a';
1396 | if (x<=298)
1397 | return 's';
1398 | if (x<=381)
1399 | return 'd';
1400 | if (x<=465)
1401 | return 'f';
1402 | if (x<=548)
1403 | return 'g';
1404 | if (x<=631)
1405 | return 'h';
1406 | if (x<=711)
1407 | return 'j';
1408 | if (x<=794)
1409 | return 'k';
1410 | return 'l';
1411 | }
1412 | else if (y>=720)
1413 | {
1414 | if (x<=173)
1415 | return 'q';
1416 | if (x<=253)
1417 | return 'w';
1418 | if (x<=336)
1419 | return 'e';
1420 | if (x<=416)
1421 | return 'r';
1422 | if (x<=499)
1423 | return 't';
1424 | if (x<=583)
1425 | return 'y';
1426 | if (x<=666)
1427 | return 'u';
1428 | if (x<=753)
1429 | return 'i';
1430 | if (x<=836)
1431 | return 'o';
1432 | return 'p';
1433 | }
1434 | else
1435 | {
1436 | startY=y;
1437 | }
1438 | }
1439 | ];
1440 |
1441 | [EraseConsole
1442 | sx sy
1443 | i ptr endptr bitmapW mask;
1444 |
1445 | bitmapW=cBitMpW==>contextW;
1446 |
1447 | i=sx;
1448 | mask=1;
1449 | while (sx&15)
1450 | {
1451 | mask=mask*2;
1452 | sx++;
1453 | }
1454 | mask=~(mask-1);
1455 | sx=i/16;
1456 |
1457 | while (sy<=cScrenY==>contextW)
1458 | {
1459 | for (i=0: i<10: i++)
1460 | {
1461 | ptr=(sy+i)*LineStride+sx+sx;
1462 | endptr=(sy+i+1)*LineStride;
1463 | ptr==>bitmapW=ptr==>bitmapW&mask;
1464 | ptr=ptr+2;
1465 | while (ptrbitmapW=0;
1468 | ptr=ptr+2;
1469 | }
1470 | }
1471 | sx=0;
1472 | sy=sy+10;
1473 | mask=0;
1474 | }
1475 | ];
1476 |
1477 | [SysRead
1478 | parse text
1479 | count i c sep dict readingWord parse0 temp;
1480 |
1481 | temp=UpdateStatus();
1482 | temp=UpdateScreen();
1483 | @write_reg $0007 $0133; ! Turn on the screen
1484 |
1485 | c=cScrenX==>contextW;
1486 | sep=cScrenY==>contextW;
1487 | dict=cScroll==>contextW;
1488 |
1489 | do
1490 | {
1491 | i++;
1492 | text->i=GetKey();
1493 | if (text->i==0)
1494 | {
1495 | if (i>=2)
1496 | i=i-2;
1497 | else
1498 | i--;
1499 | }
1500 | temp=EraseConsole(c,sep);
1501 | cScrenX==>contextW=c;
1502 | cScrenY==>contextW=sep;
1503 | cScroll==>contextW=dict;
1504 | text->(i+1)=0;
1505 | temp=TextToConsole(1, text);
1506 | temp=UpdateScreen();
1507 | } until (i && text->i==10);
1508 | text->i=0;
1509 | text->0=(i-1);
1510 |
1511 | i=0;
1512 | if (text->0==10)
1513 | {
1514 | if (text->1=='m' && text->2=='a' && text->3=='n' && text->4=='d' && text->5=='e'
1515 | && text->6=='l' && text->7=='b' && text->8=='r' && text->9=='o' && text->10=='t')
1516 | {
1517 | parse0=Mandelbrot();
1518 | i=1;
1519 | }
1520 | }
1521 | else if (text->0==6)
1522 | {
1523 | if (text->1=='i' && text->2=='n' && text->3=='v' && text->4=='a' && text->5=='d' && text->6=='e')
1524 | {
1525 | parse0=SpaceInvaders();
1526 | i=1;
1527 | }
1528 | }
1529 | if (i)
1530 | {
1531 | text->0=4;
1532 | text->1='w';
1533 | text->2='a';
1534 | text->3='i';
1535 | text->4='t';
1536 | text->5=0;
1537 | }
1538 |
1539 | parse0=parse;
1540 | parse++;
1541 | parse++;
1542 |
1543 | parse0->1=0;
1544 | count=text->0;
1545 | i=1;
1546 | while (count)
1547 | {
1548 | c=text->i;
1549 | if (c==32)
1550 | {
1551 | sep=-1;
1552 | }
1553 | else
1554 | {
1555 | dict=DictionaryOff-->0;
1556 | sep=dict->0;
1557 | while (sep)
1558 | {
1559 | if (c==dict->sep)
1560 | break;
1561 | sep--;
1562 | }
1563 | }
1564 | if (readingWord)
1565 | {
1566 | if (sep)
1567 | {
1568 | parse0->1=parse0->1+1;
1569 | parse->2=i-parse->3;
1570 | temp=FindInDictionary(text, parse);
1571 | parse=parse+4;
1572 | readingWord=0;
1573 | if (sep>0)
1574 | {
1575 | parse->3=i;
1576 | readingWord=1;
1577 | }
1578 | }
1579 | }
1580 | else if (sep>=0)
1581 | {
1582 | parse->3=i;
1583 | readingWord=1;
1584 | }
1585 | count--;
1586 | i++;
1587 | }
1588 | if (readingWord)
1589 | {
1590 | parse0->1=parse0->1+1;
1591 | parse->2=i-parse->3;
1592 | temp=FindInDictionary(text, parse);
1593 | }
1594 | ];
1595 |
1596 | [SysShowStatus
1597 | temp;
1598 | temp=UpdateStatus();
1599 | temp=UpdateScreen();
1600 | ];
1601 |
1602 | [PressKeyToReboot
1603 | temp;
1604 | @print "Press any key to reboot]";
1605 | temp=UpdateScreen();
1606 | temp=GetKey();
1607 | @switch_bank 0;
1608 | ];
1609 |
1610 | [SysQuit
1611 | temp;
1612 | @print "^[Quit. ";
1613 | temp=PressKeyToReboot();
1614 | ];
1615 |
1616 | [SysException
1617 | pc oper0 oper1;
1618 | @print "^[Exception PC/2=";
1619 | @print_num pc;
1620 | @print " OP0=";
1621 | @print_num oper0;
1622 | @print " OP1=";
1623 | @print_num oper1;
1624 | @print "]^[";
1625 | pc=PressKeyToReboot();
1626 | ];
1627 |
--------------------------------------------------------------------------------
/bios/combinedata.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | unsigned char data[512*1024]={0};
4 |
5 | #define CALLBACK_BASE 0x1E58B
6 | #define INIT_CALLBACK CALLBACK_BASE+0
7 | #define PRINT_CALLBACK CALLBACK_BASE+5
8 | #define PRINTCHAR_CALLBACK CALLBACK_BASE+10
9 | #define PRINTNUM_CALLBACK CALLBACK_BASE+15
10 | #define READ_CALLBACK CALLBACK_BASE+20
11 |
12 | char* roms[4]={
13 | "Zork1.z3",
14 | "hhgg.z3",
15 | "curses.z3",
16 | "Planetfa.z3"
17 | };
18 |
19 | int main()
20 | {
21 | FILE *f;
22 | int i;
23 | for (i=0; i<4; i++)
24 | {
25 | f=fopen(roms[i], "rb");
26 | fread(&data[0x20000*i], 1, 0x20000, f);
27 | fclose(f);
28 | if (i==0)
29 | {
30 | f=fopen("icons.dat", "rb");
31 | fread(&data[0x20000*i+0x16800], 1, 30*1024, f);
32 | fclose(f);
33 | }
34 | f=fopen("zfont.dat", "rb");
35 | fread(&data[0x20000*i+0x1E000], 1, 0x500, f);
36 | fclose(f);
37 | f=fopen("encoding.txt", "rb");
38 | fread(&data[0x20000*i+0x1E500], 1, 0x80, f);
39 | fclose(f);
40 | data[0x20000*i+0x1E57F]=i;
41 | f=fopen("bios.z3", "rb");
42 | fseek(f, 0x1E580, SEEK_SET);
43 | fread(&data[0x20000*i+0x1E580], 1, 0x20000-0x1E580, f);
44 | fclose(f);
45 | }
46 |
47 | f=fopen("rom.z3","wb");
48 | fwrite(data, 1, sizeof(data), f);
49 | fclose(f);
50 |
51 | printf("Done\n");
52 | }
53 |
--------------------------------------------------------------------------------
/bios/compressicon.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "icons.h"
5 |
6 | #define MIN(a,b) ((a)<(b)?(a):(b))
7 |
8 | int main(int argc, char **argv)
9 | {
10 | char *data=malloc(sizeof(header_data));
11 | char *p=data;
12 | FILE *f;
13 | int i=0;
14 | while (i<320)
15 | {
16 | *(p++)=0;
17 | *(p++)=(45.0f*sinf((3.14f/2.0f)*(160.0f-fabsf(160.0f-i))/160.0f));
18 | i++;
19 | }
20 | i=0;
21 | while (i<128)
22 | {
23 | unsigned char r=header_data_cmap[i][0];
24 | unsigned char g=header_data_cmap[i][1];
25 | unsigned char b=header_data_cmap[i][2];
26 | *(p++)=(r&0xF8)|(g>>5);
27 | *(p++)=((g<<3)&0xE0)|(b>>3);
28 | i++;
29 | }
30 | i=0;
31 | while (i
2 | #include "zfont2.h"
3 |
4 | unsigned char data[128][10];
5 |
6 | void calculateKeyboard(char *output, char *line1, int s)
7 | {
8 | int x=0;
9 | int g=0;
10 | int h=s/2;
11 | int sections=1;
12 | char *sep=strchr(line1,'|');
13 | while (sep)
14 | {
15 | sections+=2;
16 | sep=strchr(sep+1,'|');
17 | }
18 | g=120-sections*h+h;
19 | while (*line1)
20 | {
21 | int w=0;
22 | sep=line1;
23 | if (*sep=='|')
24 | w=data['|'][0];
25 | else
26 | {
27 | while (*sep!='|' && *sep!='\0')
28 | {
29 | w+=data[*sep][0];
30 | sep++;
31 | }
32 | }
33 | while (x+w/2 Stack needs moving into memory. On chip?
10 | 4257 (92%) - Removed Routines
11 | 2451 (53%) - Removed Routines + new ops
12 | 2451 (53%) - Removed Routines + new ops
13 | 2529 (45%) - + 0Ops
14 | 4266 (93%) - + 2Ops
15 | 3653 (79%) - + 2Ops (-LoadB/LoadW)
16 | 2785 (60%) - + 2Ops (-IncChk)
17 |
18 | 6476 (141%) - Enough ops to get to first input read
19 | 266 - No DoOp logic (probably everything compiled out)
20 | 1644 (36%) - + 0Ops
21 | 3023 (66%) - + 1Ops
22 | 4183 (91%) - + VarOps
23 | 6669 (145%) - Back to full with fixed MOD instruction
24 | 6597 (143%) - + Simple DoBranch instructions moved to state
25 | 5460 (118%) - + Reduce number stack from 32->4 (FIXME!)
26 | 4991 (108%) - + Remove MOD (not used)
27 | 4626 (100%) - + Remove DIV (could do less efficiently?)
28 |
29 | 3271 (71%) - Removed localRegs + stack from internal state (and -MOD) + StoreRegister now a state
30 | 3657 - Removed memStack (+MOD)
31 | 3332 (72%) - Removed memStack (-MOD) : Erm... why bigger?
32 | 3222 (70%) - Reduce phase to 4 bits
33 | 3202 (69%) - Remove temp2
34 |
35 | 4034 (88%) - Printing system + All ops but (MOD/remove_obj/insert_obj)
36 | 4503 (98%) - All ops except MOD
37 |
38 | 5373 (117%) - Reset + full printing system (except print_num)
39 | 5125 (111%) - Print state collapse
40 | 5053 (110%) - Removed some duplicate driving
41 | 4906 (106%) - Multicycle divide (and implements MOD)
42 | 4910 (107%) - + Working random
43 | 5081 (110%) - + Implemented print_num
44 | 4538 (98%) - Without print/sread
45 |
46 | 5012 (109%) - Full (with tweak)
47 | 1022 (22%) - - All ops
48 | 1711 (37%) - + 0Ops (~700)
49 | 2945 (64%) - + 1Ops (~1200)
50 | 4048 (88%) - + VarOps (~1100)
51 | 5012 (109%) - + 2Ops (~1000)
52 | 4651 (101%) - Full - 0Ops (~400)
53 | 4202 (91%) - Full - 1Ops (~800)
54 | 4048 (88%) - Full - 2Ops (~1000)
55 | 4177 (91%) - Full - VarOps (~800)
56 |
57 | 4741 (103%) - Full - Call (~250)
58 | 4867 (106%) - Full - Call - AvoidReadFunction
59 | 4974 (108%) - Full - StoreW/StoreB (~40)
60 | 4931 (107%) - Full - PutProp (~80)
61 | 4831 (105%) - Full - printchar/num (~180)
62 | 4853 (105%) - Full - printnum (~140)
63 | 4938 (107%) - Full - Random (~75)
64 | 4937 (107%) - Full - Push/Pull (~75)
65 |
66 | 4755 (103%) - Full (Modified call/read function states. Very suspicious!)
67 | 4591 (100%) - Full - Load (~160)
68 | 4569 (99%) - Full - RemoveObj (~190)
69 | 4648 (101%) - Full (RemoveObj calls insert obj)
70 | 4586 (100%) - Full (fussed Pull) <- Yay!
71 |
72 | 4353 (94%) - Print/PrintChar/PrintNum BIOS
73 | 4522 (98%) - Blit and writeReg ops
74 | 4533 (98%) - + Added extra output pins (Tested and works!)
75 | 4408 (96%) - Added default cases
76 | 4475 (97%) - + Blit colour setting
77 |
78 | 4463 (97%) - Passes Czech and Planetfall test
79 | 4401 (96%) - Blit as arguments
80 | 4406 (96%) - New relocatable BIOS
81 |
82 | 4545 (99%) - Touch screen reading (maybe buggy)
83 | 4548 (99%) - Reset switch (and working touch screen)
84 | 4495 (98%) - Removed wasted cycle when fetching ops
85 | 4550 (99%) - Removed wasted cycle when storing results on some ops
86 | 4580 (99%) - Added last stored variable cache
87 | 4555 (99%) - 1 cycle @dynamic, faster function calls + stream draw
88 |
--------------------------------------------------------------------------------
/instructions.md:
--------------------------------------------------------------------------------
1 | INSTRUCTIONS
2 | ============
3 |
4 | ## BUILDING THE BIOS
5 |
6 |
7 | ### TO BUILD PATCHED INFORM 6
8 | ```
9 | Clone the git repository of...
10 | https://github.com/charcole/Inform6.git
11 |
12 | git checkout inform6b
13 | clang -O3 *.c -o inform6b.out
14 | ```
15 |
16 | ### ASSEMBLE THE ROM
17 |
18 | Obtain 4 Z machine V3 games that are less than 120Kb. Update the roms array in
19 | combinedata.c to reference the games you are using. The first game in the
20 | array must be around 90Kb (like Zork I) as the icons are stored in this space.
21 |
22 | ```
23 | cd bios
24 | clang makefont.c -o makefont.out && ./makefont.out
25 | clang -O3 compressicon.c -o compressicon.out && ./compressicon.out
26 | clang -O3 combinedata.c -o combinedata.out && ./combinedata.out
27 | inform6b.out -v3 -t -l -y bios.inf
28 | ```
29 |
30 | To alter font, load zfont2.xcf in the GIMP. Alter the image as needed. Bottom
31 | row is for specifying how wide each character should be. Save image as
32 | zfont2.h. Recompile and run makefont.out.
33 |
34 | To alter icons, create an image 100x480 in the GIMP. Make indexed using 128
35 | colour palette. Save as icons.h. Recompile and run compressicon then
36 | combinedata. The compression ratio achieved must be better than around 60% to
37 | fit after Zork I.
38 |
39 |
40 | ## SIMULATING
41 |
42 | I used: Icarus-0.8.1-2005Sep12
43 |
44 | Make sure you'll built the BIOS and it's in the same directory you are going
45 | to run the Verilog simulation in.
46 |
47 | ```
48 | iverilog z3.vl && ./a.out
49 | ```
50 |
51 | If you want to run passed first request for input then touch.txt can be
52 | generated using TouchGenerator in the utilities. Using this a script can be
53 | provided which can be typed automatically during the simulation.
54 |
55 | To check screen output Screen (in utilties) can be run on the output from
56 | a.out. You may have to remove this section from the z3.vl...
57 |
58 | ```
59 | if (b.operNum==`OP_VAR && b.op==`OPVAR_BLIT1 && b.phase==0 && b.state==`STATE_DO_OP) begin
60 | b.operand[1]=1;
61 | end
62 | ```
63 |
64 | Another way of checking output is to look at ram.dat. At the end it contains
65 | the scroll back buffer from the BIOS decoded and can be viewed in a text
66 | editor.
67 |
68 |
69 | ## RUNNING ON HARDWARE
70 |
71 | ### THE HARDWARE
72 |
73 | A "EP2C5 Cyclone II Mini Board" AKA "CycloneII EP2C5T144 Learning Board".
74 | These contain an EP2C5T144 which is an Cyclone II FPGA with around 4600 LEs.
75 | They are very reasonably priced on eBay (~$10).
76 |
77 | '2.4" TFT LCD Shield' by http://mcufriend.com was used as a screen. Again very
78 | cheap off eBay (~$3). It's a colour screen with resistive touch screen.
79 |
80 | | RS Part No. | Part No. | Description | Price |
81 | |---------------|-----------------------|-----------------------------------------------|-------|
82 | | 7118029 | A29L040-70F | Parallel FLASH 4MB, 512Kx8, 3V, DIP32 | £1.24 |
83 | | 7444542 | AS6C1008-55PCN | SRAM,1M,128Kx8,55ns,3V,Low Power,DIP32 | £1.65 |
84 | | 6696064 | MCP3008-I/P | A/D Converter 10Bit 8-ch 2.7V SPI PDIP16 | £1.53 |
85 |
86 |
87 | ### TO PROGRAM THE FPGA
88 |
89 | Obtain Altera Quantus II 13.0sp1. I believe this was the last version to
90 | support Cyclone II. Open project altera/ZMachine.qpf and hit compile.
91 | Nb. ZMachine.v is identical to z3.vl.
92 |
93 |
94 | ### TO PROGRAM THE ROM
95 |
96 | Using a Minipro TL866CS
97 | ```
98 | minipro -w rom.z3 -p "A29L040 @DIP32"
99 | ```
100 |
101 | ## OPTIONAL EXTRAS
102 |
103 | ### TO BUILD THE BENCHMARK
104 |
105 | ```
106 | inform6.out -v3 -t -l -y benchmark.inf \$MAX_STATIC_DATA=20000
107 | ```
108 |
109 | Nb. This is the unpatched version of Inform 6.
110 |
111 | You can include this in as one of the games in combinedata.c.
112 |
113 |
114 | ### TO BUILD UTILITIES
115 |
116 | * Z-Ops:
117 | High level emulator. Useful for working on the BIOS.
118 |
119 | ```
120 | clang -framework SDL2 -F/Users/charlie/Library/Frameworks
121 | -I/Users/charlie/Library/Frameworks/SDL2.framework/Headers -I../../lib -O3 -g zops.c ../../lib/cclib64.a -o zops.out
122 | ```
123 |
124 | * 16BitColor:
125 | Takes hex colours and turns them into 16 bit needed by screen
126 | eg. ./16bitcolor.out 0xffe1a2
127 | ```
128 | clang 16bitcolor.c -o 16bitcolor.out
129 | ```
130 |
131 | * TouchGenerator:
132 | Takes script2.txt and generates a list of simulated touch data
133 | to type out the script. Used to automatically test the simulation.
134 |
135 | ```
136 | clang touchgenerator.c -o touchgenerator.out
137 | ```
138 |
139 | * MakeGradient:
140 | Makes gradient for Mandelbrot generator easter egg. Image is
141 | from gradient.h saved from the GIMP as a header in indexed mode. Output needs
142 | pasting into bios.inf.
143 |
144 | ```
145 | clang -O3 makegradient.c -o makegradient.out && ./makegradient.out
146 | ```
147 |
148 | * Screen:
149 | Takes the output from the simulator and draws the resultant screen
150 | output. Outdated now, use zops instead.
151 |
152 | ```
153 | clang -framework SDL2 -F/Users/charlie/Library/Frameworks -I/Users/charlie/Library/Frameworks/SDL2.framework/Headers screen.c -o screen.out
154 | ```
155 |
--------------------------------------------------------------------------------
/utils/16bitcolor.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | unsigned short ToU16(unsigned long a)
4 | {
5 | unsigned short out=(a>>8)&0xF800;
6 | out|=(a>>5)&0x07E0;
7 | out|=(a>>3)&0x001F;
8 | return out;
9 | }
10 |
11 | int main(int argc, char **argv)
12 | {
13 | int c;
14 | if (argc!=2)
15 | {
16 | printf("Usage: 16bitcolor hexcolor\n");
17 | return 1;
18 | }
19 | sscanf(argv[1], "%x", &c);
20 | printf("0x%06x->0x%04x\n", c, ToU16(c));
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/utils/gradient.h:
--------------------------------------------------------------------------------
1 | /* GIMP header image file format (INDEXED): /Users/charlie/code/verilog/Z2/gradient.h */
2 |
3 | static unsigned int width = 32;
4 | static unsigned int height = 1;
5 |
6 | /* Call this macro repeatedly. After each use, the pixel data can be extracted */
7 |
8 | #define HEADER_PIXEL(data,pixel) {\
9 | pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \
10 | pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \
11 | pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \
12 | data ++; }
13 |
14 | static char header_data_cmap[256][3] = {
15 | { 0, 7,255},
16 | { 0, 39,255},
17 | {255, 0, 0},
18 | { 0, 72,255},
19 | {255, 30, 0},
20 | { 0,105,255},
21 | {255, 64, 0},
22 | { 0,137,255},
23 | {255, 96, 0},
24 | { 0,170,255},
25 | {255,129, 0},
26 | { 0,203,255},
27 | {255,162, 0},
28 | { 0,255, 12},
29 | { 0,255, 45},
30 | { 20,255, 0},
31 | { 0,236,255},
32 | { 0,255, 78},
33 | { 0,255,111},
34 | { 0,255,143},
35 | {255,195, 0},
36 | { 54,255, 0},
37 | { 0,255,176},
38 | { 0,255,209},
39 | { 0,255,242},
40 | { 86,255, 0},
41 | {119,255, 0},
42 | {152,255, 0},
43 | {255,227, 0},
44 | {185,255, 0},
45 | {217,255, 0},
46 | {250,255, 0},
47 | {255,255,255},
48 | {255,255,255},
49 | {255,255,255},
50 | {255,255,255},
51 | {255,255,255},
52 | {255,255,255},
53 | {255,255,255},
54 | {255,255,255},
55 | {255,255,255},
56 | {255,255,255},
57 | {255,255,255},
58 | {255,255,255},
59 | {255,255,255},
60 | {255,255,255},
61 | {255,255,255},
62 | {255,255,255},
63 | {255,255,255},
64 | {255,255,255},
65 | {255,255,255},
66 | {255,255,255},
67 | {255,255,255},
68 | {255,255,255},
69 | {255,255,255},
70 | {255,255,255},
71 | {255,255,255},
72 | {255,255,255},
73 | {255,255,255},
74 | {255,255,255},
75 | {255,255,255},
76 | {255,255,255},
77 | {255,255,255},
78 | {255,255,255},
79 | {255,255,255},
80 | {255,255,255},
81 | {255,255,255},
82 | {255,255,255},
83 | {255,255,255},
84 | {255,255,255},
85 | {255,255,255},
86 | {255,255,255},
87 | {255,255,255},
88 | {255,255,255},
89 | {255,255,255},
90 | {255,255,255},
91 | {255,255,255},
92 | {255,255,255},
93 | {255,255,255},
94 | {255,255,255},
95 | {255,255,255},
96 | {255,255,255},
97 | {255,255,255},
98 | {255,255,255},
99 | {255,255,255},
100 | {255,255,255},
101 | {255,255,255},
102 | {255,255,255},
103 | {255,255,255},
104 | {255,255,255},
105 | {255,255,255},
106 | {255,255,255},
107 | {255,255,255},
108 | {255,255,255},
109 | {255,255,255},
110 | {255,255,255},
111 | {255,255,255},
112 | {255,255,255},
113 | {255,255,255},
114 | {255,255,255},
115 | {255,255,255},
116 | {255,255,255},
117 | {255,255,255},
118 | {255,255,255},
119 | {255,255,255},
120 | {255,255,255},
121 | {255,255,255},
122 | {255,255,255},
123 | {255,255,255},
124 | {255,255,255},
125 | {255,255,255},
126 | {255,255,255},
127 | {255,255,255},
128 | {255,255,255},
129 | {255,255,255},
130 | {255,255,255},
131 | {255,255,255},
132 | {255,255,255},
133 | {255,255,255},
134 | {255,255,255},
135 | {255,255,255},
136 | {255,255,255},
137 | {255,255,255},
138 | {255,255,255},
139 | {255,255,255},
140 | {255,255,255},
141 | {255,255,255},
142 | {255,255,255},
143 | {255,255,255},
144 | {255,255,255},
145 | {255,255,255},
146 | {255,255,255},
147 | {255,255,255},
148 | {255,255,255},
149 | {255,255,255},
150 | {255,255,255},
151 | {255,255,255},
152 | {255,255,255},
153 | {255,255,255},
154 | {255,255,255},
155 | {255,255,255},
156 | {255,255,255},
157 | {255,255,255},
158 | {255,255,255},
159 | {255,255,255},
160 | {255,255,255},
161 | {255,255,255},
162 | {255,255,255},
163 | {255,255,255},
164 | {255,255,255},
165 | {255,255,255},
166 | {255,255,255},
167 | {255,255,255},
168 | {255,255,255},
169 | {255,255,255},
170 | {255,255,255},
171 | {255,255,255},
172 | {255,255,255},
173 | {255,255,255},
174 | {255,255,255},
175 | {255,255,255},
176 | {255,255,255},
177 | {255,255,255},
178 | {255,255,255},
179 | {255,255,255},
180 | {255,255,255},
181 | {255,255,255},
182 | {255,255,255},
183 | {255,255,255},
184 | {255,255,255},
185 | {255,255,255},
186 | {255,255,255},
187 | {255,255,255},
188 | {255,255,255},
189 | {255,255,255},
190 | {255,255,255},
191 | {255,255,255},
192 | {255,255,255},
193 | {255,255,255},
194 | {255,255,255},
195 | {255,255,255},
196 | {255,255,255},
197 | {255,255,255},
198 | {255,255,255},
199 | {255,255,255},
200 | {255,255,255},
201 | {255,255,255},
202 | {255,255,255},
203 | {255,255,255},
204 | {255,255,255},
205 | {255,255,255},
206 | {255,255,255},
207 | {255,255,255},
208 | {255,255,255},
209 | {255,255,255},
210 | {255,255,255},
211 | {255,255,255},
212 | {255,255,255},
213 | {255,255,255},
214 | {255,255,255},
215 | {255,255,255},
216 | {255,255,255},
217 | {255,255,255},
218 | {255,255,255},
219 | {255,255,255},
220 | {255,255,255},
221 | {255,255,255},
222 | {255,255,255},
223 | {255,255,255},
224 | {255,255,255},
225 | {255,255,255},
226 | {255,255,255},
227 | {255,255,255},
228 | {255,255,255},
229 | {255,255,255},
230 | {255,255,255},
231 | {255,255,255},
232 | {255,255,255},
233 | {255,255,255},
234 | {255,255,255},
235 | {255,255,255},
236 | {255,255,255},
237 | {255,255,255},
238 | {255,255,255},
239 | {255,255,255},
240 | {255,255,255},
241 | {255,255,255},
242 | {255,255,255},
243 | {255,255,255},
244 | {255,255,255},
245 | {255,255,255},
246 | {255,255,255},
247 | {255,255,255},
248 | {255,255,255},
249 | {255,255,255},
250 | {255,255,255},
251 | {255,255,255},
252 | {255,255,255},
253 | {255,255,255},
254 | {255,255,255},
255 | {255,255,255},
256 | {255,255,255},
257 | {255,255,255},
258 | {255,255,255},
259 | {255,255,255},
260 | {255,255,255},
261 | {255,255,255},
262 | {255,255,255},
263 | {255,255,255},
264 | {255,255,255},
265 | {255,255,255},
266 | {255,255,255},
267 | {255,255,255},
268 | {255,255,255},
269 | {255,255,255},
270 | {255,255,255}
271 | };
272 | static char header_data[] = {
273 | 2,4,6,8,10,12,20,28,31,30,29,27,26,25,21,15,
274 | 13,14,17,18,19,22,23,24,16,11,9,7,5,3,1,0
275 | };
276 |
--------------------------------------------------------------------------------
/utils/makegradient.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "gradient.h"
3 |
4 | int main(int argc, char **argv)
5 | {
6 | int i=0;
7 | while (i<32)
8 | {
9 | unsigned char r=header_data_cmap[header_data[i]][0];
10 | unsigned char g=header_data_cmap[header_data[i]][1];
11 | unsigned char b=header_data_cmap[header_data[i]][2];
12 | printf("@db $%04x;", ((r&0xF8)<<8)|((g&0xFC)<<5)|(b>>3));
13 | if ((i&3)==3)
14 | printf("\n");
15 | else
16 | printf(" ");
17 | i++;
18 | }
19 | return 0;
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/utils/screen.c:
--------------------------------------------------------------------------------
1 | #include "SDL.h"
2 | #include
3 |
4 | unsigned short myPixels[320*240];
5 |
6 | int hex2num(char c)
7 | {
8 | if (c>='0' && c<='9')
9 | return c-'0';
10 | if (c>='a' && c<='f')
11 | return c-'a'+10;
12 | if (c>='A' && c<='F')
13 | return c-'A'+10;
14 | printf("Bad hex:%c\n", c);
15 | return 0;
16 | }
17 |
18 | int main(int argc, char* argv[])
19 | {
20 | FILE *f;
21 | SDL_Window *window;
22 | SDL_Renderer *ren;
23 | SDL_Texture *tex;
24 | unsigned short curReg=0;
25 | unsigned short curData=0;
26 | int curRecv=0;
27 | int curX=0;
28 | int curY=0;
29 | int curIdx=0;
30 | if (argc!=2)
31 | {
32 | printf("Usage: screen.out simulation.log\n");
33 | return 1;
34 | }
35 | f=fopen(argv[1],"r");
36 | if (!f)
37 | {
38 | printf("Couldn't open %s\n", argv[1]);
39 | return 1;
40 | }
41 | while (1)
42 | {
43 | char line[1024];
44 | char *start;
45 | if (!fgets(line, sizeof(line)-1, f))
46 | {
47 | break;
48 | }
49 | start=strchr(line, 'P');
50 | if (start && start[1]=='E' && start[2]==':')
51 | {
52 | int lcdWR=start[3]-'0';
53 | int lcdCS=start[4]-'0';
54 | int lcdReset=start[6]-'0';
55 | if (lcdCS==0 && lcdReset==1 && lcdWR==0)
56 | {
57 | int lcdRS=start[5]-'0';
58 | char *data=strchr(start, 'D');
59 | unsigned char d;
60 | if (data && data[1]==':')
61 | {
62 | d=(hex2num(data[2])<<4)|hex2num(data[3]);
63 | }
64 | if (lcdRS==0)
65 | {
66 | if (curRecv>=2)
67 | curRecv=0;
68 | curRecv++;
69 | curReg<<=8;
70 | curReg|=d;
71 | }
72 | else
73 | {
74 | curRecv++;
75 | curData<<=8;
76 | curData|=d;
77 | if (curRecv>=4 && !(curRecv&1))
78 | {
79 | if (curReg==0x22)
80 | {
81 | myPixels[curIdx%(320*240)]=curData;
82 | curIdx++;
83 | }
84 | else if (curReg==0x20)
85 | {
86 | curX=curData;
87 | curIdx=curY*240+curX;
88 | }
89 | else if (curReg==0x21)
90 | {
91 | curY=curData;
92 | curIdx=curY*240+curX;
93 | }
94 | }
95 | }
96 | }
97 | }
98 | }
99 | SDL_Init(SDL_INIT_VIDEO);
100 | window = SDL_CreateWindow("TFTLCD",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,240,320,SDL_WINDOW_SHOWN);
101 | if (window == NULL)
102 | {
103 | printf("Could not create window: %s\n", SDL_GetError());
104 | return 1;
105 | }
106 | ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
107 | if (ren == NULL)
108 | {
109 | printf("Could not create renderer: %s\n", SDL_GetError());
110 | return 1;
111 | }
112 | tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, 240, 320);
113 | if (tex == NULL)
114 | {
115 | printf("Could not create texture: %s\n", SDL_GetError());
116 | return 1;
117 | }
118 | SDL_UpdateTexture(tex, NULL, myPixels, 240*sizeof(myPixels[0]));
119 | SDL_RenderClear(ren);
120 | SDL_RenderCopy(ren, tex, NULL, NULL);
121 | SDL_RenderPresent(ren);
122 | SDL_Delay(10000);
123 | SDL_DestroyTexture(tex);
124 | SDL_DestroyRenderer(ren);
125 | SDL_DestroyWindow(window);
126 | SDL_Quit();
127 | return 0;
128 | }
129 |
--------------------------------------------------------------------------------
/utils/touchgenerator.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int touch[][3]={
5 | { 'z', 200, 850 },
6 | { 'x', 300, 850 },
7 | { 'c', 400, 850 },
8 | { 'v', 450, 850 },
9 | { 'b', 550, 850 },
10 | { 'n', 640, 850 },
11 | { 'm', 720, 850 },
12 | { ',', 800, 850 },
13 | { 'a', 150, 800 },
14 | { 's', 250, 800 },
15 | { 'd', 320, 800 },
16 | { 'f', 410, 800 },
17 | { 'g', 500, 800 },
18 | { 'h', 600, 800 },
19 | { 'j', 700, 800 },
20 | { 'k', 780, 800 },
21 | { 'l', 850, 800 },
22 | { 'q', 150, 750 },
23 | { 'w', 200, 750 },
24 | { 'e', 300, 750 },
25 | { 'r', 400, 750 },
26 | { 't', 450, 750 },
27 | { 'y', 550, 750 },
28 | { 'u', 650, 750 },
29 | { 'i', 700, 750 },
30 | { 'o', 800, 750 },
31 | { 'p', 900, 750 },
32 | { ' ', 500, 900 },
33 | { 'Z', 200, 850 },
34 | { 'X', 300, 850 },
35 | { 'C', 400, 850 },
36 | { 'V', 450, 850 },
37 | { 'B', 550, 850 },
38 | { 'N', 640, 850 },
39 | { 'M', 720, 850 },
40 | { 'A', 150, 800 },
41 | { 'S', 250, 800 },
42 | { 'D', 320, 800 },
43 | { 'F', 410, 800 },
44 | { 'G', 500, 800 },
45 | { 'H', 600, 800 },
46 | { 'J', 700, 800 },
47 | { 'K', 780, 800 },
48 | { 'L', 850, 800 },
49 | { 'Q', 150, 750 },
50 | { 'W', 200, 750 },
51 | { 'E', 300, 750 },
52 | { 'R', 400, 750 },
53 | { 'T', 450, 750 },
54 | { 'Y', 550, 750 },
55 | { 'U', 650, 750 },
56 | { 'I', 700, 750 },
57 | { 'O', 800, 750 },
58 | { 'P', 900, 750 },
59 | { '\n',800, 900 }
60 | };
61 |
62 | int main(int argc, char **argv)
63 | {
64 | FILE *f=fopen("script2.txt", "r");
65 | while (!feof(f))
66 | {
67 | char line[1024];
68 | fgets(line, sizeof(line), f);
69 | int c=0;
70 | while (line[c])
71 | {
72 | int x,y;
73 | int z=1023;
74 | int i;
75 | for (i=0; i
7 | #include "SDL.h"
8 |
9 | #ifdef __EMSCRIPTEN__
10 | #include
11 | #endif
12 |
13 | #define MAX_TOKEN_LEN 256
14 | #define USE_BIOS 1
15 |
16 | u16 randomseed=1;
17 |
18 | enum
19 | {
20 | SrcImmediate,
21 | SrcVariable
22 | };
23 |
24 | enum
25 | {
26 | Form0OP,
27 | Form1OP,
28 | Form2OP,
29 | FormVAR
30 | };
31 |
32 | static int zeroOpStoreInstructions[]={};
33 | static int oneOpStoreInstructions[]={0x01,0x02,0x03,0x04,0x08,0x0E,0x0F};
34 | static int twoOpStoreInstructions[]={0x08,0x09,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
35 | static int varOpStoreInstructions[]={0x00,0x07,0x0C,0x16,0x17,0x18,0x1E};
36 |
37 | static int zeroOpBranchInstructions[]={0x05,0x06,0x0D};
38 | static int oneOpBranchInstructions[]={0x00,0x01,0x02};
39 | static int twoOpBranchInstructions[]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x0A};
40 | static int varOpBranchInstructions[]={0x17};
41 |
42 | static char alphabetLookup[3][27]={
43 | { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' },
44 | { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' },
45 | { ' ', '\n','0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ',', '!', '?', '_', '#', '\'','"', '/', '\\','-', ':', '(', ')' },
46 | };
47 |
48 | typedef struct ZOperand_s
49 | {
50 | int value;
51 | int src;
52 | } ZOperand;
53 |
54 | typedef struct ZBranch_s
55 | {
56 | int offset;
57 | int negate;
58 | } ZBranch;
59 |
60 | typedef struct ZInstruction_s
61 | {
62 | int op;
63 | int form;
64 | int store;
65 | int numOps;
66 | ZBranch branch;
67 | ZOperand operands[4];
68 | } ZInstruction;
69 |
70 | typedef struct ZCallStack_s
71 | {
72 | int returnAddr;
73 | int returnStore;
74 | int locals[16];
75 | int depth;
76 | } ZCallStack;
77 |
78 | typedef struct ZObject_s
79 | {
80 | int addr;
81 | int propTable;
82 | } ZObject;
83 |
84 | typedef struct ZProperty_s
85 | {
86 | int addr;
87 | int size;
88 | int bDefault;
89 | } ZProperty;
90 |
91 | typedef struct ZToken_s
92 | {
93 | char token[MAX_TOKEN_LEN];
94 | int offset;
95 | } ZToken;
96 |
97 | typedef struct ZDictEntry_s
98 | {
99 | int coded[4];
100 | int current;
101 | } ZDictEntry;
102 |
103 | typedef char byte;
104 |
105 | static ZInstruction m_ins;
106 | static int m_pc;
107 | static int m_globalVariables;
108 | static int m_abbrevTable;
109 | static int m_objectTable;
110 | static int m_dictionaryTable;
111 | static int m_memSize;
112 | static int m_memOffset;
113 | static byte *rom;
114 | static byte *memory;
115 | static byte *biosRAM;
116 | static u16 *screen;
117 | static int m_numberstack[1024];
118 | static stack m_stack;
119 | static ZCallStack m_callstackcontents[1024];
120 | static stack m_callStack;
121 |
122 | int forceDynamic=0;
123 | int curIdx=0;
124 | int curX=0;
125 | int curY=0;
126 | int winXMin=0;
127 | int winXMax=240-1;
128 | int winYMin=0;
129 | int winYMax=320-1;
130 | SDL_Window *window;
131 | SDL_Renderer *ren;
132 | SDL_Texture *tex;
133 | SDL_Surface *surface;
134 | int mouseDown=0;
135 | int mouseX=0;
136 | int mouseY=0;
137 |
138 | byte ReadMem(int addr)
139 | {
140 | return memory[addr+m_memOffset];
141 | }
142 |
143 | void WriteMem(int addr, byte val)
144 | {
145 | memory[addr+m_memOffset]=val;
146 | }
147 |
148 | byte ReadMemDyn(int addr)
149 | {
150 | if (addr>=0x10000 && forceDynamic)
151 | return biosRAM[addr-0x10000];
152 | return memory[addr+m_memOffset];
153 | }
154 |
155 | void displayState();
156 |
157 | void WriteMemDyn(int addr, byte val)
158 | {
159 | if (addr>=0x10000)
160 | {
161 | if (1)//forceDynamic)
162 | biosRAM[addr-0x10000]=val;
163 | else
164 | {
165 | printf("Bad write:%x (PC:%x)\n", addr, m_pc);
166 | displayState();
167 | }
168 | }
169 | else
170 | {
171 | memory[addr+m_memOffset]=val;
172 | }
173 | }
174 |
175 | int makeS16(int msb, int lsb)
176 | {
177 | int ret=(msb<<8)+lsb;
178 | if ((ret&0x8000)!=0)
179 | {
180 | ret+=-0x10000;
181 | }
182 | return ret;
183 | }
184 |
185 | int makeU16(int msb, int lsb)
186 | {
187 | return (msb<<8)+lsb;
188 | }
189 |
190 | int readBytePC()
191 | {
192 | return ReadMem(m_pc++)&0xFF;
193 | }
194 |
195 | int readS16PC()
196 | {
197 | int msb=readBytePC();
198 | int lsb=readBytePC();
199 | return makeS16(msb, lsb);
200 | }
201 |
202 | int readVariable(int var)
203 | {
204 | if (var==0)
205 | {
206 | return *(int*)stackPop(&m_stack);
207 | }
208 | if (var<16)
209 | {
210 | return ((ZCallStack*)stackPeek(&m_callStack))->locals[var-1];
211 | }
212 | int off=2*(var-16);
213 | off+=m_globalVariables;
214 | return makeS16(ReadMem(off)&0xFF, ReadMem(off+1)&0xFF);
215 | }
216 |
217 | void setVariable(int var, int value)
218 | {
219 | value&=0xFFFF;
220 | if ((value&0x8000)!=0)
221 | {
222 | value+=-0x10000;
223 | }
224 | if (var==0)
225 | {
226 | *(int*)stackPush(&m_stack)=value;
227 | return;
228 | }
229 | if (var<16)
230 | {
231 | ((ZCallStack*)stackPeek(&m_callStack))->locals[var-1]=value;
232 | return;
233 | }
234 | int off=2*(var-16);
235 | off+=m_globalVariables;
236 | WriteMem(off+0,(byte)((value&0xFF00)>>8));
237 | WriteMem(off+1,(byte)((value&0x00FF)>>0));
238 | }
239 |
240 | void setVariableIndirect(int var, int value)
241 | {
242 | if (var==0)
243 | {
244 | stackPop(&m_stack);
245 | }
246 | setVariable(var, value);
247 | }
248 |
249 | int readVariableIndirect(int var)
250 | {
251 | int ret=readVariable(var);
252 | if (var==0)
253 | {
254 | setVariable(var, ret);
255 | }
256 | return ret;
257 | }
258 |
259 | ZObject getObject(int id)
260 | {
261 | ZObject ret;
262 | ret.addr=m_objectTable+2*31+9*(id-1);
263 | ret.propTable=makeU16(ReadMem(ret.addr+7)&0xFF, ReadMem(ret.addr+8)&0xFF);
264 | return ret;
265 | }
266 |
267 | ZProperty getProperty(ZObject obj, int id)
268 | {
269 | ZProperty ret;
270 | int address=obj.propTable;
271 | int textLen=ReadMem(address++)&0xFF;
272 | address+=textLen*2;
273 | while (ReadMem(address)!=0)
274 | {
275 | int sizeId=ReadMem(address++)&0xFF;
276 | int size=1+(sizeId>>5);
277 | int propId=sizeId&31;
278 | if (propId==id)
279 | {
280 | ret.addr=address;
281 | ret.size=size;
282 | ret.bDefault=FALSE;
283 | return ret;
284 | }
285 | address+=size;
286 | }
287 | ret.addr=(m_objectTable+(id-1)*2)&0xFFFF;
288 | ret.size=2;
289 | ret.bDefault=TRUE;
290 | return ret;
291 | }
292 |
293 | void returnRoutine(int value)
294 | {
295 | ZCallStack *cs=stackPop(&m_callStack);
296 | while (cs->depthreturnStore>=0)
301 | {
302 | setVariable(cs->returnStore, value);
303 | }
304 | m_pc=cs->returnAddr;
305 | if (cs->returnStore==-2)
306 | {
307 | returnRoutine(1);
308 | }
309 | }
310 |
311 | void doBranch(int cond, ZBranch branch)
312 | {
313 | if (branch.negate)
314 | {
315 | cond=!cond;
316 | }
317 | if (cond)
318 | {
319 | if (branch.offset==0)
320 | returnRoutine(0);
321 | else if (branch.offset==1)
322 | returnRoutine(1);
323 | else
324 | m_pc+=branch.offset-2;
325 | }
326 | }
327 |
328 | void readOperand(int operandType)
329 | {
330 | if (operandType==3) //omitted
331 | {
332 | return;
333 | }
334 | ZOperand *operand = &m_ins.operands[m_ins.numOps++];
335 | switch (operandType)
336 | {
337 | case 0: // long constant
338 | operand->value = readS16PC();
339 | operand->src = SrcImmediate;
340 | break;
341 | case 1: // small constant
342 | operand->value = readBytePC();
343 | operand->src = SrcImmediate;
344 | break;
345 | case 2: // variable
346 | operand->value = readVariable(readBytePC());
347 | operand->src = SrcVariable;
348 | break;
349 | }
350 | }
351 |
352 | void readShortForm(int opcode)
353 | {
354 | int operand=(opcode>>4)&3;
355 | int op=opcode&15;
356 | m_ins.op=op;
357 | if (operand==3)
358 | m_ins.form=Form0OP;
359 | else
360 | m_ins.form=Form1OP;
361 | readOperand(operand);
362 | }
363 |
364 | void readLongForm(int opcode)
365 | {
366 | int op=opcode&31;
367 | m_ins.op=op;
368 | m_ins.form=Form2OP;
369 | readOperand(((opcode&(1<<6))!=0)?2:1);
370 | readOperand(((opcode&(1<<5))!=0)?2:1);
371 | }
372 |
373 | void readVariableForm(int opcode)
374 | {
375 | int op=opcode&31;
376 | int operandTypes=readBytePC();
377 | int i;
378 | m_ins.op=op;
379 | if ((opcode&0xF0)>=0xE0)
380 | m_ins.form=FormVAR;
381 | else
382 | m_ins.form=Form2OP;
383 | for (i=3; i>=0; i--)
384 | {
385 | readOperand((operandTypes>>(2*i))&3);
386 | }
387 | }
388 |
389 | int readStoreInstruction(int *match, int length, int op)
390 | {
391 | int i;
392 | for (i=0; i>2;
524 | characters[1]=((pair1&3)<<3) + ((pair2&0xE0)>>5);
525 | characters[2]=pair2&0x1F;
526 | for (i=0; i<3; i++)
527 | {
528 | if (longNext>0)
529 | {
530 | longChar<<=5;
531 | longChar&=0x3FF;
532 | longChar|=characters[i];
533 | longNext--;
534 | if (longNext==0)
535 | {
536 | printf("%c", (char)longChar);
537 | }
538 | }
539 | else if (!abbrNext)
540 | {
541 | if (characters[i]==6 && alphabet==2)
542 | {
543 | longNext=2;
544 | }
545 | else if (characters[i]>=6)
546 | {
547 | characters[i]-=6;
548 | printf("%c", alphabetLookup[alphabet][characters[i]]);
549 | alphabet=0;
550 | }
551 | else if (characters[i]==4)
552 | {
553 | alphabet=1;
554 | }
555 | else if (characters[i]==5)
556 | {
557 | alphabet=2;
558 | }
559 | else if (characters[i]==0)
560 | {
561 | printf(" ");
562 | }
563 | else
564 | {
565 | abbrChar=characters[i];
566 | abbrNext=TRUE;
567 | }
568 | }
569 | else
570 | {
571 | int idx=32*(abbrChar-1)+characters[i];
572 | int abbrevTable=m_abbrevTable+2*idx;
573 | int abbrevAddress=makeU16(ReadMem(abbrevTable)&0xFF, ReadMem(abbrevTable+1)&0xFF);
574 | printText(2*abbrevAddress);
575 | abbrNext=FALSE;
576 | }
577 | }
578 | }
579 | return address;
580 | }
581 |
582 | void removeObject(int childId)
583 | {
584 | ZObject child=getObject(childId);
585 | int parentId=ReadMem(child.addr+4)&0xFF;
586 | if (parentId!=0)
587 | {
588 | ZObject parent=getObject(parentId);
589 | if ((ReadMem(parent.addr+6)&0xFF)==childId)
590 | {
591 | WriteMem(parent.addr+6,ReadMem(child.addr+5)); // parent.child=child.sibling
592 | }
593 | else
594 | {
595 | int siblingId=ReadMem(parent.addr+6)&0xFF;
596 | while (siblingId!=0)
597 | {
598 | ZObject sibling=getObject(siblingId);
599 | int nextSiblingId=ReadMem(sibling.addr+5)&0xFF;
600 | if (nextSiblingId==childId)
601 | {
602 | WriteMem(sibling.addr+5,ReadMem(child.addr+5)); // sibling.sibling=child.sibling
603 | break;
604 | }
605 | siblingId=nextSiblingId;
606 | }
607 | if (siblingId==0)
608 | {
609 | illegalInstruction();
610 | }
611 | }
612 | WriteMem(child.addr+4,0);
613 | WriteMem(child.addr+5,0);
614 | }
615 | }
616 |
617 | void addChild(int parentId, int childId)
618 | {
619 | ZObject child=getObject(childId);
620 | ZObject parent=getObject(parentId);
621 | WriteMem(child.addr+5,ReadMem(parent.addr+6)); // child.sibling=parent.child
622 | WriteMem(child.addr+4,(byte)parentId); // child.parent=parent
623 | WriteMem(parent.addr+6,(byte)childId); // parent.child=child
624 | }
625 |
626 | void zDictInit(ZDictEntry *entry)
627 | {
628 | entry->current=0;
629 | entry->coded[0]=0;
630 | entry->coded[1]=0;
631 | entry->coded[2]=0x80;
632 | entry->coded[3]=0;
633 | }
634 |
635 | void zDictAddCharacter(ZDictEntry *entry, int code)
636 | {
637 | code&=31;
638 | switch (entry->current)
639 | {
640 | case 0: entry->coded[0]|=code<<2; break;
641 | case 1: entry->coded[0]|=code>>3; entry->coded[1]|=(code<<5)&0xFF; break;
642 | case 2: entry->coded[1]|=code; break;
643 | case 3: entry->coded[2]|=code<<2; break;
644 | case 4: entry->coded[2]|=code>>3; entry->coded[3]|=(code<<5)&0xFF; break;
645 | case 5: entry->coded[3]|=code; break;
646 | }
647 | entry->current++;
648 | }
649 |
650 | ZDictEntry encodeToken(char* token)
651 | {
652 | ZDictEntry ret;
653 | int tokenLen=strlen(token);
654 | int t;
655 | zDictInit(&ret);
656 | for (t=0; t>5);
680 | zDictAddCharacter(&ret, curChar&31);
681 | }
682 | else
683 | {
684 | if (alphabet>0)
685 | {
686 | int shift=alphabet+3;
687 | zDictAddCharacter(&ret, shift);
688 | }
689 | zDictAddCharacter(&ret, code+6);
690 | }
691 | }
692 | for (t=0; t<6; t++) // pad
693 | {
694 | zDictAddCharacter(&ret, 5);
695 | }
696 | return ret;
697 | }
698 |
699 | int getDictionaryAddress(char* token, int dictionary)
700 | {
701 | int entryLength = ReadMem(dictionary++)&0xFF;
702 | int numEntries = makeU16(ReadMem(dictionary+0)&0xFF, ReadMem(dictionary+1)&0xFF);
703 | ZDictEntry zde = encodeToken(token);
704 | int i;
705 | dictionary+=2;
706 | for (i=0; i>8)&0xFF));
782 | WriteMem(parseBuffer++,(byte)((outAddress>>0)&0xFF));
783 | WriteMem(parseBuffer++,(byte)strlen(tokens[i].token));
784 | WriteMem(parseBuffer++,(byte)(tokens[i].offset+1));
785 | }
786 |
787 | return MIN(maxEntries, numTokens);
788 | }
789 |
790 | void restart()
791 | {
792 | memcpy(memory, rom, m_memSize);
793 | memset(biosRAM, 0, 0x10000);
794 | ASSERT(ReadMem(0)==3);
795 | m_globalVariables=makeU16(ReadMem(0xC)&0xFF, ReadMem(0xD)&0xFF);
796 | m_abbrevTable=makeU16(ReadMem(0x18)&0xFF, ReadMem(0x19)&0xFF);
797 | m_objectTable=makeU16(ReadMem(0xA)&0xFF, ReadMem(0xB)&0xFF);
798 | m_dictionaryTable=makeU16(ReadMem(0x8)&0xFF, ReadMem(0x9)&0xFF);
799 | m_pc=makeU16(ReadMem(6)&0xFF, ReadMem(7)&0xFF);
800 | //WriteMem(1,ReadMem(1)|(1<<4)); // status line not available
801 | //WriteMem(1,ReadMem(1)&~(1<<5)); // screen splitting available
802 | //WriteMem(1,ReadMem(1)&~(1<<6)); // variable pitch font
803 | //WriteMem(0x10,ReadMem(0x10)|(1<<0)); // transcripting
804 | //WriteMem(0x10,ReadMem(0x10)|(1<<1)); // fixed font
805 | stackInit(&m_stack, m_numberstack, sizeof(m_numberstack[0]), ARRAY_SIZEOF(m_numberstack));
806 | stackInit(&m_callStack, m_callstackcontents, sizeof(m_callstackcontents[0]), ARRAY_SIZEOF(m_callstackcontents));
807 | #if USE_BIOS
808 | callBIOS(0,FALSE);
809 | #endif
810 | }
811 |
812 | void process0OPInstruction()
813 | {
814 | switch (m_ins.op)
815 | {
816 | case 0: //rtrue
817 | returnRoutine(1);
818 | break;
819 | case 1: //rfalse
820 | returnRoutine(0);
821 | break;
822 | case 2: //print
823 | {
824 | #if !USE_BIOS
825 | m_pc=printText(m_pc);
826 | #else
827 | int origAddr=m_pc;
828 | while (!(ReadMem(m_pc)&0x80))
829 | {
830 | m_pc+=2;
831 | }
832 | m_pc+=2;
833 | m_ins.operands[1].value=origAddr&1;
834 | m_ins.operands[2].value=origAddr>>1;
835 | m_ins.numOps=3;
836 | callBIOS(1,FALSE);
837 | #endif
838 | break;
839 | }
840 | case 3: //print_ret
841 | {
842 | #if !USE_BIOS
843 | m_pc=printText(m_pc);
844 | printf("\n");
845 | returnRoutine(1);
846 | #else
847 | int origAddr=m_pc;
848 | while (!(ReadMem(m_pc)&0x80))
849 | {
850 | m_pc+=2;
851 | }
852 | m_pc+=2;
853 | m_ins.operands[1].value=(origAddr&1)|2;
854 | m_ins.operands[2].value=origAddr>>1;
855 | m_ins.numOps=3;
856 | callBIOS(1,TRUE);
857 | #endif
858 | break;
859 | }
860 | case 4: //nop
861 | break;
862 | case 5: //save
863 | doBranch(FALSE, m_ins.branch);
864 | break;
865 | case 6: //restore
866 | doBranch(FALSE, m_ins.branch);
867 | break;
868 | case 7: //restart
869 | restart();
870 | break;
871 | case 8: //ret_popped
872 | returnRoutine(*(int*)stackPop(&m_stack));
873 | break;
874 | case 9: //pop
875 | stackPop(&m_stack);
876 | break;
877 | case 0xA: //quit
878 | #if !USE_BIOS
879 | haltInstruction();
880 | #else
881 | callBIOS(6,FALSE);
882 | #endif
883 | break;
884 | case 0xB: //new_line
885 | #if !USE_BIOS
886 | printf("\n");
887 | #else
888 | m_ins.operands[1].value='\n';
889 | m_ins.numOps=2;
890 | callBIOS(2,FALSE);
891 | #endif
892 | break;
893 | case 0xC: //show_status
894 | #if !USE_BIOS
895 | haltInstruction();
896 | #else
897 | callBIOS(5,FALSE);
898 | #endif
899 | break;
900 | case 0xD: //verify
901 | doBranch(TRUE, m_ins.branch);
902 | break;
903 | case 0xE: //extended
904 | illegalInstruction();
905 | break;
906 | case 0xF: //piracy
907 | // doBranch(TRUE, m_ins.branch);
908 | forceDynamic=1;
909 | break;
910 | }
911 | }
912 |
913 | void process1OPInstruction()
914 | {
915 | switch (m_ins.op)
916 | {
917 | case 0: //jz
918 | doBranch(m_ins.operands[0].value==0, m_ins.branch);
919 | break;
920 | case 1: //get_sibling
921 | {
922 | ZObject child=getObject(m_ins.operands[0].value);
923 | int siblingId=ReadMem(child.addr+5)&0xFF;
924 | setVariable(m_ins.store, siblingId);
925 | doBranch(siblingId!=0, m_ins.branch);
926 | break;
927 | }
928 | case 2: //get_child
929 | {
930 | ZObject child=getObject(m_ins.operands[0].value);
931 | int childId=ReadMem(child.addr+6)&0xFF;
932 | setVariable(m_ins.store, childId);
933 | doBranch(childId!=0, m_ins.branch);
934 | break;
935 | }
936 | case 3: //get_parent_object
937 | {
938 | ZObject child=getObject(m_ins.operands[0].value);
939 | setVariable(m_ins.store, ReadMem(child.addr+4)&0xFF);
940 | break;
941 | }
942 | case 4: //get_prop_len
943 | {
944 | int propAddress=(m_ins.operands[0].value&0xFFFF)-1;
945 | int sizeId=ReadMem(propAddress)&0xFF;
946 | int size=(sizeId>>5)+1;
947 | setVariable(m_ins.store, size);
948 | break;
949 | }
950 | case 5: //inc
951 | {
952 | int value=readVariable(m_ins.operands[0].value);
953 | setVariable(m_ins.operands[0].value, value+1);
954 | break;
955 | }
956 | case 6: //dec
957 | {
958 | int value=readVariable(m_ins.operands[0].value);
959 | setVariable(m_ins.operands[0].value, value-1);
960 | break;
961 | }
962 | case 7: //print_addr
963 | #if !USE_BIOS
964 | printText(m_ins.operands[0].value);
965 | #else
966 | m_ins.operands[1].value=m_ins.operands[0].value&1;
967 | m_ins.operands[2].value=m_ins.operands[0].value>>1;
968 | m_ins.numOps=3;
969 | callBIOS(1,FALSE);
970 | #endif
971 | break;
972 | case 8: //call_1s
973 | m_memOffset=(m_ins.operands[0].value&3)*0x20000;
974 | restart();
975 | break;
976 | case 9: //remove_obj
977 | {
978 | removeObject(m_ins.operands[0].value);
979 | break;
980 | }
981 | case 0xA: //print_obj
982 | {
983 | #if !USE_BIOS
984 | ZObject obj=getObject(m_ins.operands[0].value);
985 | printText(obj.propTable+1);
986 | #else
987 | ZObject obj=getObject(m_ins.operands[0].value);
988 | m_ins.operands[1].value=(obj.propTable+1)&1;
989 | m_ins.operands[2].value=(obj.propTable+1)>>1;
990 | m_ins.numOps=3;
991 | callBIOS(1,FALSE);
992 | #endif
993 | break;
994 | }
995 | case 0xB: //ret
996 | returnRoutine(m_ins.operands[0].value);
997 | break;
998 | case 0xC: //jump
999 | m_pc+=m_ins.operands[0].value-2;
1000 | break;
1001 | case 0xD: //print_paddr
1002 | #if !USE_BIOS
1003 | printText(2*(m_ins.operands[0].value&0xFFFF));
1004 | #else
1005 | m_ins.operands[1].value=0;
1006 | m_ins.operands[2].value=m_ins.operands[0].value;
1007 | m_ins.numOps=3;
1008 | callBIOS(1,FALSE);
1009 | #endif
1010 | break;
1011 | case 0xE: //load
1012 | setVariable(m_ins.store, readVariableIndirect(m_ins.operands[0].value));
1013 | break;
1014 | case 0xF: //not
1015 | setVariable(m_ins.store, ~m_ins.operands[0].value);
1016 | break;
1017 | }
1018 | }
1019 |
1020 | void process2OPInstruction()
1021 | {
1022 | switch (m_ins.op)
1023 | {
1024 | case 0:
1025 | illegalInstruction();
1026 | break;
1027 | case 1: //je
1028 | {
1029 | int takeBranch=FALSE;
1030 | int test=m_ins.operands[0].value;
1031 | int i;
1032 | for (i=1; im_ins.operands[1].value, m_ins.branch);
1048 | break;
1049 | case 4: //dec_chk
1050 | {
1051 | int value=readVariable(m_ins.operands[0].value);
1052 | value--;
1053 | setVariable(m_ins.operands[0].value, value);
1054 | doBranch(valuem_ins.operands[1].value, m_ins.branch);
1063 | break;
1064 | }
1065 | case 6: //jin
1066 | {
1067 | ZObject child=getObject(m_ins.operands[0].value);
1068 | doBranch((ReadMem(child.addr+4)&0xFF)==m_ins.operands[1].value, m_ins.branch);
1069 | break;
1070 | }
1071 | case 7: //test
1072 | {
1073 | int flags=m_ins.operands[1].value;
1074 | doBranch((m_ins.operands[0].value&flags)==flags, m_ins.branch);
1075 | break;
1076 | }
1077 | case 8: //or
1078 | setVariable(m_ins.store, m_ins.operands[0].value|m_ins.operands[1].value);
1079 | break;
1080 | case 9: //and
1081 | setVariable(m_ins.store, m_ins.operands[0].value&m_ins.operands[1].value);
1082 | break;
1083 | case 0xA: //test_attr
1084 | {
1085 | ZObject obj=getObject(m_ins.operands[0].value);
1086 | int attr=m_ins.operands[1].value;
1087 | int offset=attr/8;
1088 | int bit=0x80>>(attr%8);
1089 | doBranch((ReadMem(obj.addr+offset)&bit)==bit, m_ins.branch);
1090 | break;
1091 | }
1092 | case 0xB: //set_attr
1093 | {
1094 | ZObject obj=getObject(m_ins.operands[0].value);
1095 | int attr=m_ins.operands[1].value;
1096 | int offset=attr/8;
1097 | int bit=0x80>>(attr%8);
1098 | WriteMem(obj.addr+offset,ReadMem(obj.addr+offset)|bit);
1099 | break;
1100 | }
1101 | case 0xC: //clear_attr
1102 | {
1103 | ZObject obj=getObject(m_ins.operands[0].value);
1104 | int attr=m_ins.operands[1].value;
1105 | int offset=attr/8;
1106 | int bit=0x80>>(attr%8);
1107 | WriteMem(obj.addr+offset,ReadMem(obj.addr+offset)&~bit);
1108 | break;
1109 | }
1110 | case 0xD: //store
1111 | setVariableIndirect(m_ins.operands[0].value, m_ins.operands[1].value);
1112 | break;
1113 | case 0xE: //insert_obj
1114 | {
1115 | removeObject(m_ins.operands[0].value);
1116 | addChild(m_ins.operands[1].value, m_ins.operands[0].value);
1117 | break;
1118 | }
1119 | case 0xF: //loadw
1120 | {
1121 | int address=((m_ins.operands[0].value&0xFFFF)+2*(m_ins.operands[1].value&0xFFFF));
1122 | setVariable(m_ins.store, makeS16(ReadMemDyn(address)&0xFF, ReadMemDyn(address+1)&0xFF));
1123 | forceDynamic=0;
1124 | break;
1125 | }
1126 | case 0x10: //loadb
1127 | {
1128 | int address=((m_ins.operands[0].value&0xFFFF)+(m_ins.operands[1].value&0xFFFF));
1129 | setVariable(m_ins.store, ReadMemDyn(address)&0xFF);
1130 | forceDynamic=0;
1131 | break;
1132 | }
1133 | case 0x11: //get_prop
1134 | {
1135 | ZObject obj=getObject(m_ins.operands[0].value);
1136 | ZProperty prop=getProperty(obj, m_ins.operands[1].value);
1137 | if (prop.size==1)
1138 | {
1139 | setVariable(m_ins.store, ReadMem(prop.addr)&0xFF);
1140 | }
1141 | else if (prop.size==2)
1142 | {
1143 | setVariable(m_ins.store, makeS16(ReadMem(prop.addr)&0xFF, ReadMem(prop.addr+1)&0xFF));
1144 | }
1145 | else
1146 | {
1147 | illegalInstruction();
1148 | }
1149 | break;
1150 | }
1151 | case 0x12: //get_prop_addr
1152 | {
1153 | ZObject obj=getObject(m_ins.operands[0].value);
1154 | ZProperty prop=getProperty(obj, m_ins.operands[1].value);
1155 | if (prop.bDefault)
1156 | setVariable(m_ins.store, 0);
1157 | else
1158 | setVariable(m_ins.store, prop.addr);
1159 | break;
1160 | }
1161 | case 0x13: //get_next_prop
1162 | {
1163 | ZObject obj=getObject(m_ins.operands[0].value);
1164 | if (m_ins.operands[1].value==0)
1165 | {
1166 | int address=obj.propTable;
1167 | int textLen=ReadMem(address++)&0xFF;
1168 | address+=textLen*2;
1169 | int nextSizeId=ReadMem(address)&0xFF;
1170 | setVariable(m_ins.store, nextSizeId&31);
1171 | }
1172 | else
1173 | {
1174 | ZProperty prop=getProperty(obj, m_ins.operands[1].value);
1175 | if (prop.bDefault)
1176 | {
1177 | illegalInstruction();
1178 | }
1179 | else
1180 | {
1181 | int nextSizeId=ReadMem(prop.addr+prop.size)&0xFF;
1182 | setVariable(m_ins.store, nextSizeId&31);
1183 | }
1184 | }
1185 | break;
1186 | }
1187 | case 0x14: //add
1188 | setVariable(m_ins.store, m_ins.operands[0].value+m_ins.operands[1].value);
1189 | break;
1190 | case 0x15: //sub
1191 | setVariable(m_ins.store, m_ins.operands[0].value-m_ins.operands[1].value);
1192 | break;
1193 | case 0x16: //mul
1194 | setVariable(m_ins.store, m_ins.operands[0].value*m_ins.operands[1].value);
1195 | break;
1196 | case 0x17: //div
1197 | setVariable(m_ins.store, m_ins.operands[0].value/m_ins.operands[1].value);
1198 | break;
1199 | case 0x18: //mod
1200 | setVariable(m_ins.store, m_ins.operands[0].value%m_ins.operands[1].value);
1201 | break;
1202 | case 0x19: //call_2s
1203 | illegalInstruction();
1204 | break;
1205 | case 0x1A: //call_2n
1206 | illegalInstruction();
1207 | break;
1208 | case 0x1B: //set_colour
1209 | illegalInstruction();
1210 | break;
1211 | case 0x1C: //throw
1212 | illegalInstruction();
1213 | break;
1214 | case 0x1D:
1215 | illegalInstruction();
1216 | break;
1217 | case 0x1E:
1218 | //printf("WriteReg: %04x %04x\n", m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF);
1219 | if (m_ins.operands[0].value==0x22)
1220 | {
1221 | screen[curIdx%(320*240)]=m_ins.operands[1].value;
1222 | curIdx++;
1223 | curX++;
1224 | if (curX>winXMax)
1225 | {
1226 | curX=winXMin;
1227 | curY++;
1228 | if (curY>winYMax)
1229 | {
1230 | curY=winYMin;
1231 | }
1232 | curIdx=curY*240+curX;
1233 | }
1234 | }
1235 | else if (m_ins.operands[0].value==0x20)
1236 | {
1237 | curX=m_ins.operands[1].value;
1238 | curIdx=curY*240+curX;
1239 | }
1240 | else if (m_ins.operands[0].value==0x21)
1241 | {
1242 | curY=m_ins.operands[1].value;
1243 | curIdx=curY*240+curX;
1244 | }
1245 | else if (m_ins.operands[0].value==0x50)
1246 | {
1247 | winXMin=m_ins.operands[1].value;
1248 | }
1249 | else if (m_ins.operands[0].value==0x51)
1250 | {
1251 | winXMax=m_ins.operands[1].value;
1252 | }
1253 | else if (m_ins.operands[0].value==0x52)
1254 | {
1255 | winYMin=m_ins.operands[1].value;
1256 | }
1257 | else if (m_ins.operands[0].value==0x53)
1258 | {
1259 | winYMax=m_ins.operands[1].value;
1260 | }
1261 | else if (m_ins.operands[0].value==7)
1262 | {
1263 | #ifndef __EMSCRIPTEN__
1264 | SDL_UpdateTexture(tex, NULL, screen, 240*sizeof(screen[0]));
1265 | SDL_RenderClear(ren);
1266 | SDL_RenderCopy(ren, tex, NULL, NULL);
1267 | SDL_RenderPresent(ren);
1268 | SDL_Delay(1);
1269 | #endif
1270 | }
1271 | break;
1272 | case 0x1F:
1273 | illegalInstruction();
1274 | break;
1275 | }
1276 | }
1277 |
1278 | void processVARInstruction()
1279 | {
1280 | switch (m_ins.op)
1281 | {
1282 | case 0: // call
1283 | callRoutine(2*(m_ins.operands[0].value&0xFFFF), m_ins.store, TRUE);
1284 | break;
1285 | case 1: //storew
1286 | {
1287 | int address=((m_ins.operands[0].value&0xFFFF)+2*(m_ins.operands[1].value&0xFFFF));
1288 | int value=m_ins.operands[2].value;
1289 | WriteMemDyn(address,(byte)((value>>8)&0xFF));
1290 | WriteMemDyn(address+1,(byte)(value&0xFF));
1291 | forceDynamic=0;
1292 | break;
1293 | }
1294 | case 2: //storeb
1295 | {
1296 | int address=((m_ins.operands[0].value&0xFFFF)+(m_ins.operands[1].value&0xFFFF));
1297 | int value=m_ins.operands[2].value;
1298 | WriteMemDyn(address,(byte)(value&0xFF));
1299 | forceDynamic=0;
1300 | break;
1301 | }
1302 | case 3: //put_prop
1303 | {
1304 | ZObject obj=getObject(m_ins.operands[0].value);
1305 | ZProperty prop=getProperty(obj, m_ins.operands[1].value);
1306 | if (!prop.bDefault)
1307 | {
1308 | if (prop.size==1)
1309 | {
1310 | WriteMem(prop.addr,(byte)(m_ins.operands[2].value&0xFF));
1311 | }
1312 | else if (prop.size==2)
1313 | {
1314 | WriteMem(prop.addr+0,(byte)((m_ins.operands[2].value>>8)&0xFF));
1315 | WriteMem(prop.addr+1,(byte)(m_ins.operands[2].value&0xFF));
1316 | }
1317 | }
1318 | else
1319 | {
1320 | illegalInstruction();
1321 | }
1322 | break;
1323 | }
1324 | case 4: //sread
1325 | {
1326 | #if !USE_BIOS
1327 | static char input[4096];
1328 | int bufferAddr=m_ins.operands[0].value;
1329 | int parseAddr=m_ins.operands[1].value;
1330 | int maxLength=ReadMem(bufferAddr++)&0xFF;
1331 | int maxParse=ReadMem(parseAddr++)&0xFF;
1332 | int realInLen=0;
1333 | int inLen;
1334 | int i;
1335 | fgets(input, sizeof(input), stdin);
1336 | inLen=strlen(input);
1337 | for (i=0; i0)
1378 | {
1379 | randomseed=randomseed^(randomseed<<13);
1380 | randomseed=randomseed^(randomseed>>9);
1381 | randomseed=randomseed^(randomseed<<7);
1382 | ret=((randomseed&0x7FFF)%(maxValue))+1;
1383 | }
1384 | else if (maxValue<0)
1385 | {
1386 | randomseed=maxValue;
1387 | }
1388 | setVariable(m_ins.store, ret);
1389 | break;
1390 | }
1391 | case 8: //push
1392 | setVariable(0, m_ins.operands[0].value);
1393 | break;
1394 | case 9: //pull
1395 | setVariableIndirect(m_ins.operands[0].value, readVariable(0));
1396 | break;
1397 | case 0xA: //split_window
1398 | haltInstruction();
1399 | break;
1400 | case 0xB: //set_window
1401 | haltInstruction();
1402 | break;
1403 | case 0xC: //call_vs2
1404 | illegalInstruction();
1405 | break;
1406 | case 0xD: //erase_window
1407 | illegalInstruction();
1408 | break;
1409 | case 0xE: //erase_line
1410 | illegalInstruction();
1411 | break;
1412 | case 0xF: //set_cursor
1413 | illegalInstruction();
1414 | break;
1415 | case 0x10: //get_cursor
1416 | illegalInstruction();
1417 | break;
1418 | case 0x11: //set_text_style
1419 | illegalInstruction();
1420 | break;
1421 | case 0x12: //buffer_mode
1422 | illegalInstruction();
1423 | break;
1424 | case 0x13: //output_stream
1425 | haltInstruction();
1426 | break;
1427 | case 0x14: //input_stream
1428 | haltInstruction();
1429 | break;
1430 | case 0x15: //sound_effect
1431 | haltInstruction();
1432 | break;
1433 | case 0x16: //read_char
1434 | illegalInstruction();
1435 | break;
1436 | case 0x17: //scan_table
1437 | illegalInstruction();
1438 | break;
1439 | case 0x18: //not
1440 | illegalInstruction();
1441 | break;
1442 | case 0x19: //call_vn
1443 | illegalInstruction();
1444 | break;
1445 | case 0x1A: //call_vn2
1446 | illegalInstruction();
1447 | break;
1448 | case 0x1B: //tokenise
1449 | illegalInstruction();
1450 | break;
1451 | case 0x1C: //encode_text
1452 | illegalInstruction();
1453 | break;
1454 | case 0x1D: //copy_table
1455 | illegalInstruction();
1456 | break;
1457 | case 0x1E: //print_table
1458 | {
1459 | // printf("GetTouch: %04x\n", m_ins.operands[0].value);
1460 | SDL_Event e;
1461 | while (SDL_PollEvent(&e))
1462 | {
1463 | if (e.type == SDL_QUIT)
1464 | exit(1);
1465 | else if (e.type == SDL_MOUSEBUTTONDOWN)
1466 | mouseDown=1;
1467 | else if (e.type == SDL_MOUSEBUTTONUP)
1468 | mouseDown=0;
1469 | else if (e.type == SDL_MOUSEMOTION)
1470 | {
1471 | SDL_MouseMotionEvent *mm=(SDL_MouseMotionEvent*)&e;
1472 | mouseX=mm->x;
1473 | mouseY=mm->y;
1474 | }
1475 | }
1476 | if (m_ins.operands[0].value==0x93) // touching?
1477 | setVariable(m_ins.store, mouseDown?0:1024);
1478 | else if (m_ins.operands[0].value==0x95) // X
1479 | {
1480 | float m=(840.0f-170.0f)/(216.0f-23.0f);
1481 | float c=840.0f-216.0f*m;
1482 | float v=mouseX*m+c;
1483 | setVariable(m_ins.store, (int)MIN(MAX(v,0),1023));
1484 | }
1485 | else if (m_ins.operands[0].value==0x1A) // Y
1486 | {
1487 | float m=(870.0f-720.0f)/(302.0f-243.0f);
1488 | float c=870.0f-302.0f*m;
1489 | float v=mouseY*m+c;
1490 | setVariable(m_ins.store, (int)MIN(MAX(v,0),1023));
1491 | }
1492 | else
1493 | setVariable(m_ins.store, 0);
1494 | break;
1495 | }
1496 | case 0x1F: //check_arg_count
1497 | {
1498 | int i;
1499 | //printf("Blit: %04x %04x %04x %04x\n", m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF, m_ins.operands[2].value&0xFFFF, m_ins.operands[3].value&0xFFFF);
1500 | forceDynamic=1;
1501 | for (i=0; i<(m_ins.operands[1].value&0xFFFF); i++)
1502 | {
1503 | byte data=ReadMemDyn(2*(m_ins.operands[0].value&0xFFFF)+i);
1504 | screen[curIdx%(320*240)]=(data&0x80)?m_ins.operands[3].value:m_ins.operands[2].value;
1505 | curIdx++;
1506 | screen[curIdx%(320*240)]=(data&0x40)?m_ins.operands[3].value:m_ins.operands[2].value;
1507 | curIdx++;
1508 | screen[curIdx%(320*240)]=(data&0x20)?m_ins.operands[3].value:m_ins.operands[2].value;
1509 | curIdx++;
1510 | screen[curIdx%(320*240)]=(data&0x10)?m_ins.operands[3].value:m_ins.operands[2].value;
1511 | curIdx++;
1512 | screen[curIdx%(320*240)]=(data&0x08)?m_ins.operands[3].value:m_ins.operands[2].value;
1513 | curIdx++;
1514 | screen[curIdx%(320*240)]=(data&0x04)?m_ins.operands[3].value:m_ins.operands[2].value;
1515 | curIdx++;
1516 | screen[curIdx%(320*240)]=(data&0x02)?m_ins.operands[3].value:m_ins.operands[2].value;
1517 | curIdx++;
1518 | screen[curIdx%(320*240)]=(data&0x01)?m_ins.operands[3].value:m_ins.operands[2].value;
1519 | curIdx++;
1520 | curX+=8;
1521 | if (curX>winXMax)
1522 | {
1523 | curX=winXMin;
1524 | curY++;
1525 | if (curY>winYMax)
1526 | {
1527 | curY=winYMin;
1528 | }
1529 | curIdx=curY*240+curX;
1530 | }
1531 | }
1532 | #ifndef __EMSCRIPTEN__
1533 | SDL_UpdateTexture(tex, NULL, screen, 240*sizeof(screen[0]));
1534 | SDL_RenderClear(ren);
1535 | SDL_RenderCopy(ren, tex, NULL, NULL);
1536 | SDL_RenderPresent(ren);
1537 | SDL_Delay(1);
1538 | #endif
1539 | forceDynamic=0;
1540 | break;
1541 | }
1542 | }
1543 | }
1544 |
1545 | void executeInstruction()
1546 | {
1547 | m_ins.numOps=0;
1548 | //printf("\nPC:%05x ", m_pc);
1549 | int opcode=readBytePC();
1550 | if ((opcode&0xC0)==0xC0)
1551 | {
1552 | readVariableForm(opcode);
1553 | }
1554 | else if ((opcode&0xC0)==0x80)
1555 | {
1556 | readShortForm(opcode);
1557 | }
1558 | else
1559 | {
1560 | readLongForm(opcode);
1561 | }
1562 | switch (m_ins.form)
1563 | {
1564 | case Form0OP:
1565 | //printf("Doing op0:%2d\n", m_ins.op);
1566 | m_ins.store=readStoreInstruction(zeroOpStoreInstructions,ARRAY_SIZEOF(zeroOpStoreInstructions),m_ins.op);
1567 | m_ins.branch=readBranchInstruction(zeroOpBranchInstructions,ARRAY_SIZEOF(zeroOpBranchInstructions),m_ins.op);
1568 | //dumpCurrentInstruction();
1569 | process0OPInstruction();
1570 | break;
1571 | case Form1OP:
1572 | //printf("Doing op1:%2d Operands:%04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF);
1573 | m_ins.store=readStoreInstruction(oneOpStoreInstructions,ARRAY_SIZEOF(oneOpStoreInstructions),m_ins.op);
1574 | m_ins.branch=readBranchInstruction(oneOpBranchInstructions,ARRAY_SIZEOF(oneOpBranchInstructions),m_ins.op);
1575 | //dumpCurrentInstruction();
1576 | process1OPInstruction();
1577 | break;
1578 | case Form2OP:
1579 | //printf("Doing op2:%2d Operands:%04x %04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF);
1580 | m_ins.store=readStoreInstruction(twoOpStoreInstructions,ARRAY_SIZEOF(twoOpStoreInstructions),m_ins.op);
1581 | m_ins.branch=readBranchInstruction(twoOpBranchInstructions,ARRAY_SIZEOF(twoOpBranchInstructions),m_ins.op);
1582 | //dumpCurrentInstruction();
1583 | process2OPInstruction();
1584 | break;
1585 | case FormVAR:
1586 | //if (m_ins.numOps==4)
1587 | // printf("Doing opvar:%2d Operands:%04x %04x %04x %04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF, m_ins.operands[2].value&0xFFFF, m_ins.operands[3].value&0xFFFF);
1588 | //else if (m_ins.numOps==3)
1589 | // printf("Doing opvar:%2d Operands:%04x %04x %04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF, m_ins.operands[2].value&0xFFFF);
1590 | //else if (m_ins.numOps==2)
1591 | // printf("Doing opvar:%2d Operands:%04x %04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF, m_ins.operands[1].value&0xFFFF);
1592 | //else if (m_ins.numOps==1)
1593 | // printf("Doing opvar:%2d Operands:%04x\n", m_ins.op, m_ins.operands[0].value&0xFFFF);
1594 | //else
1595 | // printf("Doing opvar:%2d Operands:\n", m_ins.op);
1596 | m_ins.store=readStoreInstruction(varOpStoreInstructions,ARRAY_SIZEOF(varOpStoreInstructions),m_ins.op);
1597 | m_ins.branch=readBranchInstruction(varOpBranchInstructions,ARRAY_SIZEOF(varOpBranchInstructions),m_ins.op);
1598 | //dumpCurrentInstruction();
1599 | processVARInstruction();
1600 | break;
1601 | }
1602 | }
1603 |
1604 | #ifdef __EMSCRIPTEN__
1605 | void executeInstruction30()
1606 | {
1607 | for (int i=0; i<50000; i++)
1608 | {
1609 | executeInstruction();
1610 | }
1611 | if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface);
1612 | for (int i = 0; i < 320; i++)
1613 | {
1614 | for (int j = 0; j < 240; j++)
1615 | {
1616 | u16 c=screen[i*240+j];
1617 | u8 r=(c>>8)&0xF8;
1618 | u8 g=(c>>3)&0xFC;
1619 | u8 b=(c<<3)&0xF8;
1620 | *((Uint32*)surface->pixels + i * 240 + j) = SDL_MapRGBA(surface->format, r, g, b, 255);
1621 | }
1622 | }
1623 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
1624 | SDL_Flip(surface);
1625 | }
1626 | #endif
1627 |
1628 | int main(int argc, char **argv)
1629 | {
1630 | TFile fh;
1631 | #ifdef __EMSCRIPTEN__
1632 | if (fileOpen(&fh, "rom.z3", TRUE))
1633 | #else
1634 | if (argc!=2)
1635 | {
1636 | printf("Usage: zops game.z3\n");
1637 | }
1638 | else if (fileOpen(&fh, argv[1], TRUE))
1639 | #endif
1640 | {
1641 | m_memSize=fileSize(&fh);
1642 |
1643 | SDL_Init(SDL_INIT_VIDEO);
1644 | #ifdef __EMSCRIPTEN__
1645 | surface = SDL_SetVideoMode(240, 320, 32, SDL_SWSURFACE);
1646 | #else
1647 | window = SDL_CreateWindow("TFTLCD",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,240,320,SDL_WINDOW_SHOWN);
1648 | if (window == NULL)
1649 | {
1650 | printf("Could not create window: %s\n", SDL_GetError());
1651 | return 1;
1652 | }
1653 | ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
1654 | if (ren == NULL)
1655 | {
1656 | printf("Could not create renderer: %s\n", SDL_GetError());
1657 | return 1;
1658 | }
1659 | tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, 240, 320);
1660 | if (tex == NULL)
1661 | {
1662 | printf("Could not create texture: %s\n", SDL_GetError());
1663 | return 1;
1664 | }
1665 | #endif
1666 |
1667 | rom=memAlloc(m_memSize);
1668 | memory=memAlloc(m_memSize);
1669 | biosRAM=memAlloc(0x10000);
1670 | screen=memAlloc(320*240*sizeof(u16));
1671 | fileReadData(&fh, rom, m_memSize);
1672 | fileClose(&fh);
1673 | restart();
1674 | #ifdef __EMSCRIPTEN__
1675 | emscripten_set_main_loop(executeInstruction30, 30, 0);
1676 | #else
1677 | while (1)
1678 | {
1679 | executeInstruction();
1680 | }
1681 | SDL_DestroyTexture(tex);
1682 | SDL_DestroyRenderer(ren);
1683 | SDL_DestroyWindow(window);
1684 | SDL_Quit();
1685 | #endif
1686 | return 0;
1687 | }
1688 | return 1;
1689 | }
1690 |
--------------------------------------------------------------------------------