-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfocal69MEGA_TOPSEQ_EEPROM.ino
654 lines (611 loc) · 30.5 KB
/
focal69MEGA_TOPSEQ_EEPROM.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
// INTERRUPT NOW FAKED EVERY 256 OPS, WAY MORE RESPONSIVE
#define MEMSIZE 3952
#define SRL Serial3
// EEPROM SIZE: 4096 bytes = 2048 words
// Cannot dump all memory - would need 8192, have 4096.
// Use half - maybe we can store up to THREE files later on.
// So far, we shall save only the code-populated userspace
// locations in FOCAL-69, given by LOCATIONS, and according
// to the manual (3200-5377)OCT = (1664-2815)DEC or
// 1660 to 2820 to remember it easier.
#define Word unsigned int
#include <EEPROM.h>
const int STARTING_EEPROM_ADDRESS = 0;
Word pc;
// As of this writing, this whole thing is a quick-and-dirty port of this amazing 256-LOC
// PDP-8 / 4K emulator: https://git.jeelabs.org/jcw/embello/src/branch/master/explore/1638-pdp8
// It was written for PC, and I ported it to Arduino - it definitely runs on DUE.
// Beware that the Arduino IDE builtin Serial monitor will not work (will not terminate lines
// correctly), so use some actual terminal emulator - I am using picocom. - To do all this,
// I ran jcw's original program, with the modification that I let it dump its memory right
// after it loaded FOCAL 69. Then, I removed all loading routines and simply placed the
// dump below into the mem-array, to let the machine have FOCAL 69 in memory a priori.
// I have not tested it, but it should be possible, if you program anything, to replace
// this dump with a new FOCAL 69 dump, containing your program. Hence, I modified the
// cleanup-function so that it simply presents such a dump once you press Ctrl-\ - enjoy!
// For instance, you can try this: FOR X=-10,1,10;TYPE X,!
// - Nino, 21st May 2020
Word mem[] = {
1464,2819,2819,1411,4,11,64,3328,1632,2404,63,1680,38,1050,
0,2404,0,4045,1287,2403,0,2403,0,1632,2040,2413,4094,0,0,
2815,0,0,1048,0,0,6,0,0,0,6,0,3459,1028,3540,4080,0,0,0,
2413,832,0,1470,1462,2048,141,798,5,141,140,135,131,223,
138,141,1,4032,174,4033,3968,4080,127,15,191,4094,3903,176,
3936,3922,3955,4093,4091,4087,63,128,2048,1048,1133,3021,
3072,3200,1632,1670,1632,1679,1039,1287,337,885,319,348,
364,1212,1346,716,465,1333,1133,1301,194,1186,1264,267,847,
859,1053,484,448,1074,1494,0,0,0,0,0,0,0,1505,3976,2942,
607,1554,3585,1600,1558,662,1547,661,2409,602,1544,1586,
602,1559,2410,2407,59,316,2406,2703,170,1680,2406,2406,602,
1551,1552,2405,541,1547,2416,2417,2802,2745,1046,2412,596,
565,4000,2422,560,1544,1586,567,1800,2416,3848,2405,2406,
566,590,4000,2736,2421,2414,2687,2400,393,786,3880,2687,
1554,530,3585,2714,165,2416,566,586,4008,2770,1566,2553,
551,250,550,4000,2422,551,2415,3588,1591,2417,2405,2417,
2784,2794,556,3654,556,3588,567,1591,2405,2417,2422,2794,
556,567,1591,2405,2417,2784,3848,2422,3648,567,68,4000,
3600,567,70,3888,2422,4000,763,3600,3588,1589,3010,2944,
4064,1024,1036,1032,624,610,875,739,1493,1493,1493,1493,
1493,3840,1493,1493,1493,1392,3654,3590,3590,2955,2412,530,
2402,2403,15,2403,53,565,4040,2739,2413,3584,531,1545,777,
2419,2422,2400,390,2404,53,786,3880,2745,3585,1560,565,4064,
2736,792,2419,2745,792,1591,2709,2413,2422,2400,392,2404,
53,2404,15,779,1554,3006,393,403,1593,3616,2248,569,1803,
3616,2248,3007,347,523,1547,523,3681,537,3992,2422,3016,
2428,977,1593,3616,2248,721,3585,1803,3616,2248,2873,988,
3744,988,1545,1244,591,2248,591,1593,777,1803,1081,2789,
591,2248,3036,315,3744,1004,1260,1545,591,1593,779,1801,
1081,2803,3052,1504,138,143,151,573,607,1493,565,392,396,
3898,2412,2413,2422,531,1554,2405,566,590,4008,2913,2408,
766,2696,566,61,2402,2405,2408,766,3848,2707,779,2407,507,
119,2422,2412,1046,2413,2743,567,4000,2411,2405,2409,566,
590,4000,2724,787,3880,2745,3585,1560,565,4032,792,2419,
2747,792,1591,2719,531,2731,1558,2913,565,4072,2745,2409,
2740,915,2416,2408,1015,3008,566,1216,642,4008,2767,2417,
3008,3848,3008,1216,1216,3008,1139,977,1546,778,3912,2784,
3617,566,4000,2772,977,3616,522,1580,3848,1233,1233,3776,
3025,289,68,3617,1593,567,68,569,4008,1252,3044,2982,542,
4000,2804,2405,3054,2410,2407,3582,1794,3054,541,392,396,
211,198,201,196,199,195,193,212,204,197,215,205,209,210,
138,2420,2463,1035,2464,585,1562,549,3912,1050,4072,1050,
3848,3063,2407,767,3833,2405,2712,2405,2709,897,1063,2400,
771,2416,566,733,3872,2422,536,2402,2400,906,779,1560,2311,
3352,0,2407,767,3711,2422,536,2402,2400,906,2407,767,3708,
2422,2403,1048,2400,906,2403,1048,2403,15,2400,392,2404,
15,2404,1048,2404,3896,779,1560,2311,280,987,3352,1365,0,
549,4064,2913,536,2402,2403,3896,2753,3907,3924,2403,1285,
2753,2347,2402,566,734,4000,2422,2400,906,2347,3123,3712,
779,3119,3848,2347,3712,2910,545,545,523,272,387,396,642,
643,3907,1156,413,686,127,883,3313,3744,1582,1558,2407,761,
126,1070,2710,2400,771,566,2402,685,2409,1054,3585,2393,
779,1590,2690,2400,907,2392,2691,1046,2405,2407,771,507,
2409,2715,2405,2412,567,1578,2692,575,2355,3616,575,2409,
2405,2692,186,2412,2413,2422,560,1544,1586,567,1800,520,
1559,2356,1600,1046,2405,2409,2407,62,697,2406,2747,560,
3585,1544,1586,2410,2407,57,697,2406,2758,146,3880,566,
3617,1593,972,1228,1546,778,3912,2784,569,4000,2772,522,
972,1593,825,1593,2873,1228,3776,3020,2347,3584,3325,3290,
2790,3314,1574,3073,2910,0,3110,3094,3105,2799,3712,3052,
699,696,1504,706,697,177,714,165,162,161,163,164,160,172,
187,141,2420,162,141,2422,1586,2406,2405,2408,1015,2710,
566,82,561,1585,2405,2408,1015,2710,2705,2418,2719,561,
1582,2480,779,1585,2479,2347,1743,560,1560,536,3617,537,
4072,2737,792,3617,561,4008,2757,536,568,2721,1063,897,537,
517,3681,523,3984,2422,537,568,1561,561,1816,1048,719,1816,
1048,2311,351,3352,0,2913,536,1545,777,3617,719,4000,2732,
1048,1048,2913,175,566,588,4000,3023,2405,2768,3920,3911,
0,1024,0,232,566,589,4000,1243,566,726,1580,556,4040,3035,
566,727,4072,1243,3035,2311,728,2280,3288,0,1752,1572,2910,
607,1554,779,1593,2873,673,666,681,678,1578,683,683,392,396,
525,556,2402,557,2402,558,2402,641,2402,2405,1581,2420,2711,
2778,2787,2400,775,2420,2724,138,255,2422,607,1560,585,556,
3880,2727,3585,4008,2771,556,593,4040,2803,2418,3848,2422,
556,1556,532,593,4032,1556,532,3617,557,4040,2760,557,3658,
3594,729,1724,557,4000,2404,36,2311,280,3413,0,597,1560,
532,557,4008,2913,779,1581,2733,2418,3848,2805,557,2402,
536,1744,2403,2044,532,1581,2405,2420,2803,2778,2787,2704,
280,2403,36,597,1560,1566,2393,2404,36,2706,1582,2405,2408,
1015,2796,558,3652,566,2787,2418,2422,2177,779,2407,1140,
3207,2418,2422,2177,1035,2910,160,171,173,175,170,222,168,
219,188,169,221,190,172,187,141,189,2403,1285,2404,36,665,
4040,2345,2311,3584,3224,0,597,1560,2215,2967,914,1,1024,0,
0,3,933,556,593,4032,2973,556,592,4064,1181,2973,527,779,
1581,668,779,3617,556,4000,2422,2405,2983,183,3074,2413,
2994,1046,2405,566,590,4000,2743,527,3616,531,1583,603,3617,
531,4008,2687,3584,787,1813,603,1593,825,3880,2775,1562,
531,3681,538,3992,559,538,1849,538,2761,3616,531,1545,559,
3616,531,1546,559,560,1584,520,3616,522,1562,520,559,1544,
778,1801,1050,2792,2739,144,2356,1590,2408,915,3053,2409,
3053,1371,1448,1438,1397,1432,1359,1402,1428,1429,1452,
1405,1474,1433,1399,216,2420,2719,2706,2699,566,586,3872,
2422,605,1584,1883,560,1561,2687,2412,560,1544,2421,1043,
565,4032,787,2419,2703,787,1591,2709,560,1561,2913,1077,
603,1557,603,1555,531,1545,567,3681,777,3880,2742,3992,
2743,531,1557,787,3872,2726,3848,1186,531,3585,1551,1552,
2978,177,2264,4040,518,751,566,3880,2766,573,1590,534,576,
4008,2409,3004,2264,3616,2750,534,4000,2774,576,4008,3585,
1600,2749,584,2757,1228,1040,2789,529,82,1590,566,579,4008,
2763,566,750,3032,783,1553,3616,1552,529,3658,3594,3594,
2780,4064,4001,184,3584,789,1840,560,1813,561,3872,1800,
520,3585,1584,560,1561,3056,683,396,3202,495,495,3240,1,
1024,0,0,0,0,4086,0,3097,2701,3102,70,3880,2701,595,2956,
0,567,2415,82,2210,578,2409,567,2210,750,1590,2409,2965,0,
70,1562,587,1563,2730,1051,1562,538,651,3904,2728,3712,539,
2409,538,587,2409,2978,138,3880,566,590,3880,2750,575,2355,
2997,575,2355,574,2748,178,584,3617,566,3880,746,577,3880,
3053,747,1593,569,236,750,3872,748,4008,2778,569,82,3872,
2269,3584,3010,594,2269,2772,1368,1074,2799,561,1800,1585,
523,3681,517,520,3984,3037,2422,32,255,96,1540,4000,2415,
1585,3616,1586,3037,0,0,0,0,0,0,0,0,0,0,0,0,0,2048,3965,
1664,3592,1665,3105,2709,3106,1550,949,3880,2709,3108,1550,
1973,693,3585,71,691,1717,3097,2726,3102,70,3880,2726,595,
1714,690,642,4008,2784,540,4000,2422,690,1564,3081,2730,
3082,1567,3236,3137,3584,641,3652,640,3073,2816,141,1616,
1617,1617,1135,540,3944,2743,1726,1564,702,2998,1341,1718,
3073,948,4000,2753,3074,526,4000,2764,694,3110,1550,2771,
694,1972,692,3585,71,691,1716,3073,3006,1750,0,3744,726,
1591,3073,526,4000,2779,3074,2786,595,1591,1038,581,1583,
3616,691,1544,3584,1800,1071,2793,1564,691,1717,691,1716,
3616,3110,577,2409,2411,1042,786,3880,2815,1591,577,2409,
2409,2411,575,2409,598,1642,2687,562,4000,2700,520,3617,
535,4032,2977,681,2409,520,1593,3584,1074,2722,825,82,579,
4000,2719,3616,1586,3616,520,1544,825,65,1585,2977,1368,
825,65,518,4000,2712,1849,2713,220,560,1560,537,3617,536,
4008,2913,792,1742,717,1551,1552,2405,2409,2405,2409,2405,
2409,1048,792,2508,2405,2409,1048,2311,280,0,2392,575,2409,
568,585,536,2731,1314,1613,0,2601,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,3502,3312,2065,4045,4045,3519,895,2994,3436,3502,
3312,2870,2995,3135,895,2600,1576,617,3057,3113,2665,2668,
2175,895,2687,895,895,895,895,4045,4045,0,0,0,0,0,0,1679,
0,237,399,193,812,3193,3513,4045,1685,271,1248,637,3504,
4045,1699,276,608,2569,2929,2674,2998,3436,3246,3509,2866,
2994,3455,832,1709,281,1248,1576,617,3928,2569,2929,2687,
832,1716,311,1248,637,621,3199,832,1722,316,480,3246,3248,
4045,1752,321,1248,1576,3177,3944,1194,3184,3120,3120,2667,
2579,2737,3120,3120,2667,2580,2737,3120,3113,2792,1386,3184,
3113,2792,1450,3184,2667,1535,832,1766,341,83,736,2185,950,
1570,2834,2835,2836,2837,2838,2839,4045,1779,389,608,2578,
2675,2993,3116,3502,3125,2867,2993,3135,832,1785,394,1248,
893,3135,832,1798,399,608,2578,2675,2994,3116,3310,3248,
2867,2996,3135,832,1804,404,1248,893,3199,832,1810,409,
1248,1213,2898,4045,1816,414,1248,957,1215,832,1822,419,
480,3438,3125,4045,1835,424,608,2579,2675,2996,3436,3310,
3381,2867,2998,3455,832,1841,429,1248,893,3263,832,1847,
434,1248,1277,2899,4045,1853,439,1248,957,1279,832,1859,
444,480,3438,3125,4045,1872,449,608,2580,2675,2999,3116,
3310,3568,2868,2992,3455,832,1878,454,1248,893,3327,832,
1884,459,1248,1341,2900,4045,1890,464,1248,957,1343,832,
1896,469,480,3438,3125,4045,1909,517,608,2581,2676,2993,
3116,3374,3184,2868,2995,3135,832,1915,522,1248,893,3391,
832,1921,527,1248,1405,2901,4045,1927,532,1248,957,1407,
832,1933,537,480,3438,3125,4045,1946,542,608,2582,2676,
2995,3436,3374,3317,2868,2997,3455,832,1952,547,1248,893,
3455,832,1958,552,1248,1469,2902,4045,1964,557,1248,957,
1471,832,1970,562,480,3438,3125,4045,1983,567,608,2583,
2676,2998,3116,3374,3504,2866,2993,3455,832,1989,572,1248,
893,3519,832,1995,577,1248,1533,2903,4045,2001,582,1248,
957,1535,832,2014,587,608,2574,2677,2992,3436,3246,3189,
2869,2992,3455,832,2020,645,1248,637,3199,832,2034,650,608,
2569,2934,3113,3438,3189,2869,2995,3692,3438,3321,4045,
2056,655,608,2574,2886,596,1192,1576,617,3057,3120,3120,
3113,2677,2995,3564,3438,3248,2869,2995,3583,832,2073,660,
608,2566,596,1192,1576,617,2665,3438,3249,2869,2995,3564,
3438,3249,4045,2089,661,1312,2417,2088,393,1298,2600,1576,
617,3057,3120,3120,3113,2665,4045,2117,662,1312,2417,2088,
393,1298,2600,1576,617,3057,3120,3120,2665,2920,3184,2694,
596,1192,2584,2569,2671,3184,3120,3120,2665,2665,4045,2144,
663,1312,2417,2088,393,1298,2600,1576,617,3057,3120,3113,
2669,2609,3114,393,1298,2600,1576,617,3057,3120,3120,2665,
2665,4045,2170,664,1312,2417,2088,393,1298,2600,1576,617,
3057,3120,2665,2920,3184,2694,596,1192,2584,2569,2671,3184,
3120,2665,2665,4045,2195,665,1312,2417,2088,393,1298,2600,
1576,617,3057,3113,2669,2609,3114,393,1298,2600,1576,617,
3057,3120,2665,2665,4045,2218,666,1312,2417,2088,393,1298,
2584,2569,2665,2920,3184,2694,596,1192,2584,2569,2671,3184,
2665,2665,2849,4045,2225,677,1248,637,619,3199,832,2231,678,
480,3438,3184,4045,2237,679,1248,957,3135,832,2251,680,608,
2573,2929,2677,2996,3436,3310,3376,2869,2996,3455,832,2265,
685,608,2573,2930,2677,2997,3116,3310,3509,2869,2997,3135,
832,2279,690,608,2573,2931,2677,2997,3436,3374,3125,2869,
2997,3455,832,2293,695,608,2573,2932,2677,2998,3116,3374,
3312,2869,2998,3135,832,2307,700,608,2573,2933,2677,2998,
3436,3374,3445,2869,2998,3455,832,2313,705,480,3246,3189,
4045,2319,773,1248,637,3199,832,2331,774,1312,2422,2992,
3104,620,2234,2220,1576,617,4045,2341,775,1312,2422,2992,
3104,1576,619,3177,4045,2351,776,1312,2422,2992,3104,1576,
619,3241,4045,2361,777,1312,2422,2992,3104,1576,619,3305,
4045,2371,778,1312,2422,2992,3104,1576,619,3369,4045,2382,
779,1312,2422,2992,3104,1576,619,3433,2849,4045,2389,782,
1248,637,619,3519,832,2403,783,608,2569,2934,3113,3502,3253,
2870,2995,3116,3502,3312,4045,2409,793,480,3502,3126,4045,
0,798,1151,832,1493,368,2447,1542,1457,1028,3282,1452,7,2,
2050,2354,2401,1585,2400,799,1048,792,3065,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,549,4040,2516,1563,2311,2251,3517,0,2347,
1749,2311,3584,3518,445,1470,3517,2493,3518,712,3286,197,
1750,1469,703,3286,194,2494,726,3286,445,1750,2257,718,0,
725,548,1572,1051,2910,2311,3517,206,1981,0,2910,2770,2774,
4,1274,770,4092,1135,2671,10,2860,227,7,1398,2785,1,1477,
1309,1,1024,0,2,1024,0,2675,0,0,0,0,0,2311,445,2493,3518,
2300,761,2494,758,3286,243,2494,752,2494,749,2493,1750,0,
3052,2580,0,1311,931,4095,1732,2332,4091,1734,2860,0,1311,
934,0,1303,1235,4093,1815,3626,0,549,4040,2291,1563,2311,
3485,1439,0,549,4040,2705,2311,415,1949,3485,0,3744,1778,
2963,2522,1266,2972,2311,3485,414,1437,0,2972,2754,2770,
2766,2510,549,3880,2422,4040,2345,2311,3566,1439,0,549,
3880,2910,4032,2740,2311,415,2030,3566,0,3744,1563,517,
1572,3616,1006,1573,1574,1575,3585,2030,2311,2287,3485,
494,1439,3566,2283,744,2542,741,2542,738,2542,735,2542,
732,2542,729,2542,726,2542,925,0,2972,0,2047,4066,4095,
2048,2112,4095,1359,199,4094,2123,3721,4094,1373,1729,4093,
2534,505,4092,1182,2244,4089,2404,989,2518,0,1419,2316,0,
0,2345,3744,3059,0,0,0,0,0,0,0,0,0,2311,3282,206,1234,0,
549,4064,2701,549,4032,2910,2345,3616,1563,2311,1734,3286,
0,2347,2311,3584,3282,214,1234,2246,3282,1226,0,549,4040,
2725,2311,3282,0,539,3616,1563,2311,210,1230,0,549,4040,
2737,2311,202,1234,3282,0,2311,210,1742,3282,2258,3286,218,
2262,734,2262,738,2262,742,2262,718,2258,0,1051,2910,2345,
2910,3,1608,2030,1693,2,1608,2030,1693,1,1608,2030,1693,0,
0,0,0,0,0,0,0,4084,1281,3597,546,4089,2868,2892,3176,4093,
1305,2801,2526,0,2773,268,1655,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1756,554,2415,82,1562,538,3617,3880,
726,1757,554,3880,2721,82,1755,733,731,3912,2712,3744,538,
1755,3616,539,3904,3712,538,3912,2739,726,3904,3712,727,
1593,985,569,1758,569,3617,1593,725,1502,990,728,4040,2741,
2014,1081,2769,1502,1051,3712,554,4008,2798,733,539,3936,
2797,731,3904,3712,3617,539,3617,1562,539,538,4008,2787,
538,3585,4040,581,2270,1050,2755,578,2409,2755,3616,734,
1758,2730,5,4090,7,4086,3176,3180,0,0,0,0,2522,1245,3038,
2944,3616,539,1563,1244,2795,3616,1756,2763,780,2763,3712,
2522,578,2409,1152,780,2270,1244,2802,3616,1756,2803,3807,
549,1576,549,4040,2345,3065,202,1574,1572,1573,1575,1740,
1576,566,692,3880,2704,585,4000,2705,3616,1576,2486,566,
693,4008,2704,2199,2944,2966,566,690,4008,2967,2417,2967,
2727,556,1739,2231,1228,4000,2422,2486,2712,566,586,4040,
2967,566,691,4064,2967,566,82,2720,3899,3878,3925,3936,494,
2978,551,1571,550,1570,549,1569,1738,2253,2253,2267,2253,
715,1571,1570,1569,2267,714,2999,0,6,1,3011,551,3652,1575,
550,3588,1574,549,3588,1573,714,3588,1738,3021,3016,3776,
551,547,1575,3588,550,546,1574,3588,549,545,1573,3588,714,
1738,3035,3402,3776,545,3912,3664,3592,1569,546,3592,1570,
547,3592,1571,1056,3052,3052,0,0,0,0,0,733,2409,549,4032,
732,734,2409,2539,1563,548,3912,2711,3872,737,4072,2716,
2311,2532,0,3585,539,2697,2311,2538,0,3616,2709,2021,2022,
744,1548,548,3680,1772,739,1572,2391,1260,2725,998,3880,
2744,738,4040,2740,3585,1804,1060,738,1051,3584,998,1051,
3584,3848,2535,1804,1060,2744,744,1548,739,2537,2944,731,
2409,539,3912,3617,1573,539,4032,585,734,2409,549,1060,735,
3904,2765,736,1573,3616,548,3872,2284,549,2522,2944,1314,
197,4083,189,173,3996,100,4092,4086,4089,3261,3019,3018,
2999,3895,2816,3257,2937,0,587,2409,3052,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,992,4000,2502,566,588,4008,2690,2498,566,
589,4000,2705,2502,1989,2499,965,3617,1563,712,1572,2500,
2503,2311,3352,0,566,705,4000,2726,2502,2498,2500,551,539,
1563,2311,280,0,539,3880,2944,4032,2737,2311,2237,3352,0,
3585,2742,2311,2233,3352,0,3616,539,1563,2726,4,1280,0,0,
4093,1638,1639,1640,3899,2944,2967,3707,3020,494,3805,35,
0,0,0,0,0,0,0,0,0,581,1763,543,4032,2804,1050,2772,1251,
2772,2275,523,766,3984,3042,1035,2913,138,0,765,3616,1789,
3680,1567,765,3872,3084,4000,767,598,1642,3043,2275,3059,
393,3616,1567,3086,70,3880,2770,595,1590,3025,0,2415,2148,
958,3776,1575,1571,896,3880,2944,1714,690,83,4008,2702,
580,128,1568,582,178,544,1568,691,178,4008,2713,800,1568,
1152,3616,544,1549,690,3654,3590,71,3880,2743,692,1714,946,
3880,2741,1714,708,1548,591,1583,781,1804,1071,2733,2994,
3457,256,3451,707,2747,707,1549,3616,544,1548,591,1583,
780,1805,1071,2750,2689,35,31,2549,2552,2689,2554,2553,
2555,2551,2689,549,4000,2773,1572,1573,1574,1575,2689,
2403,36,2403,32,2404,36,2347,3912,2786,3616,1714,1571,
549,4000,2422,2403,1285,2404,36,2404,3896,2800,2403,3896,
2404,32,2550,1202,2795,2689,2550,2689,3691,3588,3805,3475,
3052,3567,3035,3398,3397,3655,3443,3405,0,3403,4036,3776,
551,3617,1575,550,3616,3864,3649,1574,549,3616,3864,3649,
1573,2947,3400,549,3880,550,4008,2761,545,3880,546,3880,
547,4008,2963,544,3617,548,3880,2747,1667,643,3904,3617,
1746,722,734,4040,2749,643,4032,2741,2287,1234,2737,2747,
3616,544,1568,2515,1234,2744,1171,2963,544,4032,2756,548,
4032,2963,2758,548,4032,643,4064,2963,544,1572,545,1573,
546,1574,547,1575,2963,4036,3052,3420,2537,548,4072,2795,
3585,1571,744,1568,2195,23,1063,2788,1062,3848,1061,1575,
2538,550,3028,23,2937,3707,1572,1573,1574,2788,3401,3776,
549,3912,3600,3592,1573,550,3592,1574,551,3592,1575,1060,
3055,3055,223,255,138,253,4095,3444,3585,544,2260,4040,
2283,1729,1728,1727,1726,549,2025,545,2538,2,546,2538,3,
550,2025,545,2538,3,546,2538,4,2739,1724,547,2025,549,2538,
4,550,2538,5,551,2025,545,2538,4,546,2538,5,547,2538,6,705,
1573,704,1574,703,1575,2241,1575,2948,0,0,0,1280,2787,3642,
1064,2345,2535,1063,3009,545,4008,2422,544,3617,3585,2260,
4032,2283,2536,2241,3027,3329,3592,548,1572,596,37,545,
4032,3616,1576,549,3880,3046,4040,2345,545,3880,3046,3028,
3408,3805,3761,3758,3712,3398,3776,547,3617,1571,546,3616,
3864,3649,1570,545,3616,3864,3649,1569,3051,3825,552,4040,
2345,3067,3613,3880,2944,1708,1707,687,1709,3648,684,3592,
1708,683,3856,2704,3648,686,3592,1707,1197,2696,684,3592,
1709,896,3617,682,1708,685,3648,940,1964,1196,3588,683,940,
1964,3856,2944,1196,1452,2944,2726,3650,995,3648,1280,3185,
4084,4073,0,1664,1708,688,1709,3848,2391,3648,546,550,1710,
3588,549,545,3856,2756,1573,686,1574,3712,684,3588,1708,640,
3588,1664,1197,2743,684,1574,640,1573,2993,3588,1757,1197,
2743,733,1573,640,1574,684,1575,2993,3222,2557,2294,549,
3880,551,3880,550,4008,2803,549,3652,4040,2800,2391,3680,
548,1572,2791,2558,2294,3037,1572,3037,3567,3826,549,3912,
3617,4040,2549,3062,2937,3707,0,2311,3260,0,549,4040,2422,
548,3912,3600,3592,1720,3864,1208,3584,695,1721,1722,1723,
701,3880,702,4008,2741,2311,188,1720,696,0,3744,548,1572,
548,3617,696,4000,2737,549,3617,697,4000,2737,550,3617,698,
3904,3617,3585,4032,2910,2311,3256,0,2711,1572,2910,1549,2,
1024,0,0,0,0,0,3907,0,0,0,603,2263,560,2263,537,2263,541,
2263,2766,2405,2409,566,590,4000,2764,526,4000,2770,3074,
2884,0,1562,538,3590,3590,2280,2415,3588,2280,3594,3592,
2280,2280,3712,575,2409,3031,0,238,587,2409,538,3048,7,0
};
Word mask(Word w) { return w & 07777; }
Word lmask(Word w) { return w & 017777; }
Word opAddr (int ir) {
Word a = ir & 0177;
if (ir & 0200)
a |= (pc - 1) & 07600;
if (ir & 0400) {
if ((a & 07770) == 010)
mem[a] = mask(mem[a] + 1);
a = mem[a];
}
return a;
}
// This I simply turned into a memory dump, so if anything was
// programmed in FOCAL, it should be retained here and could be
// pasted later on at the top. - Nino
void cleanup () {
SRL.println();
SRL.println();
int cntr;
int decer = 0;
for (cntr = 0; cntr < MEMSIZE; cntr++) {
SRL.print(static_cast<int>(mem[cntr]));
SRL.print(", ");
delay(300);
decer++;
if (decer == 12) {
SRL.print("\r\n");
decer = 0;
}
}
SRL.println();
SRL.println();
}
void writeArrayIntoEEPROM(int address, Word numbers[])
{
// 1660 to 2820
int addressIndex = address;
for (int i = 1660; i < 2820; i++)
{
EEPROM.write(addressIndex, numbers[i] >> 8);
EEPROM.write(addressIndex + 1, numbers[i] & 0xFF);
addressIndex += 2;
}
}
void readArrayFromEEPROM(int address, Word numbers[])
{
// 1660 to 2820
int addressIndex = address;
for (int i = 1660; i < 2820; i++)
{
numbers[i] = (EEPROM.read(addressIndex) << 8) + EEPROM.read(addressIndex + 1);
addressIndex += 2;
}
}
void setup() {
// start serial port at 300 bps
// SRL.begin(300, SERIAL_7E2);
SRL.begin(300, SERIAL_8N1);
int greeting = 1;
if (greeting == 1) {
greeting = 0;
SRL.print(F("\r\n WELCOME TO THE TOPSEQ SYSTEM IN FOCAL-69 ON AN ARDUINO PDP-8.\r\n"));
delay(990);
SRL.print(F(" THIS COMPUTER HAS BEEN SET TO RUN THE TOPSEQ SEMANTIC NETWORK.\r\n"));
delay(990);
SRL.print(F(" TOPSEQ IS SHORT FOR TOPIC SEQUENCER INDICATING THE NATURE OF\r\n"));
delay(990);
SRL.print(F(" THE SYSTEM. EACH INPUT CONSISTS OF EXACTLY SIX ONE-DIGIT\r\n"));
delay(990);
SRL.print(F(" POSITIVE OR NEGATIVE DECIMAL NUMBERS 1-9, E.G:\r\n"));
delay(990);
SRL.print(F(" 1,2,3,4,5,6 RETURN. NOTE THAT 0 IS NOT USED AND MEANS NO TOPIC.\r\n"));
delay(990);
SRL.print(F(" THIS SETS A NEW SENTENCE INTO THE KNOWLEDGE BASE, AT ONCE\r\n"));
delay(990);
SRL.print(F(" FORGETTING THE OLDEST ONE. EACH NUMBER REPRESENTS A POSSIBLE\r\n"));
delay(990);
SRL.print(F(" TOPIC. THE TOPIC OF THE SENTENCE IS ALWAYS THE FIRST NUMBER\r\n"));
delay(990);
SRL.print(F(" GIVEN IN THE SENTENCE. IT CAN BE SEARCHED BY NOTING IT AS\r\n"));
delay(990);
SRL.print(F(" NEGATIVE DURING INPUT, AS 1,-2,-1,2,3,4 SEARCHES FOR SENTENCES\r\n"));
delay(990);
SRL.print(F(" BEGINNING WITH 2 AND 1 AND WILL INDEED FIND 1,2,3,4,5,6 AS IT\r\n"));
delay(990);
SRL.print(F(" BEGINS WITH 1. AT THE SAME TIME, THE SYSTEM WILL ALSO LEARN\r\n"));
delay(990);
SRL.print(F(" 1,2,1,2,3,4, I.E. ALL TOPICS ARE STORED AS POSITIVE NUMBERS.\r\n"));
delay(990);
SRL.print(F(" IF YOU WISH TO ONLY SEARCH FOR A TERM, TRY E.G.\r\n"));
delay(990);
SRL.print(F(" -1,0,0,0,0,0 RETURN. IF A TOPIC OF INTEREST HAS BEEN\r\n"));
delay(990);
SRL.print(F(" SPECIFIED BY MINUS, A REPLY WILL BE MADE. OTHERWISE, THE\r\n"));
delay(990);
SRL.print(F(" SYSTEM WILL ONLY LEARN THE SENTENCE. THE KNOWLEDGE CONSISTS.\r\n"));
delay(990);
SRL.print(F(" OUT OF 60 SENTENCES. IF ANY SENTENCE IS INPUT THAT BEGINS WITH\r\n"));
delay(990);
SRL.print(F(" ZERO, THE INTERACTION TERMINATES AND THE KNOWLEDGE BASE IS\r\n"));
delay(990);
SRL.print(F(" PRINTED OUT. YOU ARE THEN RETURNED TO FOCAL-69. ERASE ALL\r\n"));
delay(990);
SRL.print(F(" IN FOCAL REMOVES THE AI UNTIL RESTART. TYPE GO TO COMMENCE.\r\n"));
delay(990);
SRL.print(F(" ~ DUMPS, { SAVES AND } GETS MEMORY: PRESS THE KEY, THEN ENTER.\r\n"));
}
pc = 0200;
Word sr = 0;
Word ac = 0, mq = 0;
int iena = 0;
for (;;) {
iena >>= 1; // implements delayed enabling, relies on sign extension
static char counter; // HACK: every 256 ops, we fake an interrupt
if ((iena & 1) && ++counter == 0) {
mem[0] = pc;
pc = 1;
iena = 0;
}
int ir = mem[pc];
pc = mask(pc + 1);
switch ((ir >> 9) & 07) {
case 0: // AND
ac &= mem[opAddr(ir)] | 010000;
break;
case 1: // TAD
ac = lmask(ac + mem[opAddr(ir)]);
break;
case 2: { // ISZ
Word t = opAddr(ir);
mem[t] = mask(mem[t] + 1);
if (mem[t] == 0)
pc = mask(pc + 1);
break;
}
case 3: // DCA
mem[opAddr(ir)] = mask(ac);
ac &= 010000;
break;
case 4: { // JMS
Word t = opAddr(ir);
mem[t] = pc;
pc = mask(t + 1);
break;
}
case 5: // JMP
pc = opAddr(ir);
break;
case 6: // IOT
switch ((ir >> 3) & 077) {
case 00:
switch (ir) {
case 06001: iena = ~1; break; // delays one cycle
case 06002: iena = 0; break;
default: { // SRL.print("IOT "); SRL.print(ir, OCT); SRL.print(" AC="); SRL.println(ac, OCT);
}
}
break;
case 03: // keyboard
if ((ir & 01) && SRL.available()) {
pc = mask(pc + 1);}
if (ir & 04) { // read byte
int b = SRL.read();
if ((b > 96) && (b < 123)) {b = b - 32;} // turn letters to CAPITALS
if (b == '~') { // cleanup on ctrl-backslash: (b == 0x1C)
SRL.print(F("\r\nQUIT\r\n"));
cleanup();
// return 4;
if (ir & 01) // skip if ready
pc = mask(pc + 1);
if (ir & 04) { // send byte
SRL.write(ac & 0177); // strip off parity
// fflush(stdout);
}
if (ir & 02) // clear flag
ac &= 010000;
}
if (b == '{') {
b = ' ';
SRL.print(F("\r\nSAVING MEMORY...\r\n"));
writeArrayIntoEEPROM(STARTING_EEPROM_ADDRESS, mem);
// for (int iii = 0; iii < MEMSIZE - 16; iii = iii + 1) { client.print(mem[iii]); client.print(","); }
SRL.print(F("\r\nMEMORY SAVED.\r\n")); delay(250);
}
if (b == '}') {
b = ' ';
SRL.print(F("\r\nLOADING MEMORY...\r\n"));
readArrayFromEEPROM(STARTING_EEPROM_ADDRESS, mem);
// for (int iii = 0; iii < MEMSIZE - 16; iii = iii + 1) { client.print(mem[iii]); client.print(","); }
SRL.print(F("\r\nMEMORY LOADED.\r\n")); delay(250);
}
ac = (ac & 010000) | b;
}
break;
case 04: // teleprinter
if (ir & 01) // skip if ready
pc = mask(pc + 1);
if (ir & 04) { // send byte
SRL.write(ac & 0177); // strip off parity
delay(60); if ((ac & 0177) == '\n') { delay(440); }
// fflush(stdout);
}
if (ir & 02) // clear flag
ac &= 010000;
break;
default:
{ // SRL.print("IOT "); SRL.print(ir, OCT); SRL.print(" AC="); SRL.println(ac, OCT);
}
break;
}
break;
case 7: // OPR
if ((ir & 0400) == 0) { // group 1
if (ir & 0200) // CLA
ac &= 010000;
if (ir & 0100) // CLL
ac &= 07777;
if (ir & 040) // CMA
ac ^= 07777;
if (ir & 020) // CML
ac ^= 010000;
if (ir & 01) // IAC
ac = lmask(ac + 1);
switch (ir & 016) {
case 012: // RTR
ac = lmask((ac >> 1) | (ac << 12)); // fall through
case 010: // RAR
ac = lmask((ac >> 1) | (ac << 12));
break;
case 06: // RTL
ac = lmask((ac >> 12) | (ac << 1)); // fall through
case 04: // RAL
ac = lmask((ac >> 12) | (ac << 1));
break;
case 02: // BSW
ac = (ac & 010000) | ((ac >> 6) & 077)
| ((ac << 6) & 07700);
break;
}
} else if ((ir & 01) == 0) { // group 2
// SMA, SPA, SZA, SNA, SNL, SZL
int s = ((ir & 0100) && (ac & 04000)) ||
((ir & 040) && (ac & 07777) == 0) ||
((ir & 020) && (ac & 010000) != 0) ? 0 : 010;
if (s == (ir & 010))
pc = mask(pc + 1);
if (ir & 0200) // CLA
ac &= 010000;
if (ir & 04) // OSR
ac |= sr;
if (ir & 02) { // HLT
SRL.print(F("\r\nHALT ")); SRL.println(mask(ac), OCT);
// return 0;
}
} else { // group 3
Word t = mq;
if (ir & 0200) // CLA
ac &= 010000;
if (ir & 020) { // MQL
mq = ac & 07777;
ac &= 010000;
}
if (ir & 0100)
ac |= t;
}
break;
}
}
}
void loop() {}