This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spacewar.mac
2057 lines (1906 loc) · 31.2 KB
/
spacewar.mac
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/macro fio-dec system, june 1963
szm=sza sma-szf
spq=szm i
clc=cma+cla-opr
define senseswitch A
repeat 3, A=A+A
szs A
term
define init A,B
law B
dap A
term
define index A,B,C
idx A
sas B
jmp C
term
define listen
cla+cli+clf 1-opr-opr
szf i 1
jmp .-1
tyi
term
define swap
rcl 9s
rcl 9s
term
define load A,B
lio (B
dio A
term
define setup A,B
law i B
dac A
term
define count A,B
isp A
jmp B
term
define move A,B
lio A
dio B
term
define clear A,B
init .+2, A
dzm
index .-1, (dzm B+1, .-1
term
/spacewar 3.1 24 sep 62 p1. 1
3/
jmp sbf / ignore seq. break
jmp a40
jmp a1 / use test word for control, note iot 11 00
/ interesting and often changed constants
/symb loc usual value (all instructions are executed,
/ and may be replaced by jda or jsp)
tno,
6,
law i 41 / number of torps + 1
tvl,
7,
sar 4s / torpedo velocity
rlt,
10,
law i 20 / torpedo reload time
tlf,
11,
law i 140 / torpedo life
foo,
12,
-20000 / fuel supply
maa,
13,
10 / spaceship angular acceleration
sac,
14,
sar 4s / spaceship acceleration
str,
15,
1 / star capture radius
me1,
16,
6000 / collision "radius"
me2,
17,
3000 / above/2
ddd,
20,
777777 / 0 to save space for ddt
the,
21,
sar 9s / amount of torpedo space warpage
mhs,
22,
law i 10 / number of hyperspace shots
hd1,
23,
law i 40 / time in hyperspace before breakout
hd2,
24,
law i 100 / time in hyperspace breakout
hd3,
25,
law i 200 / time to recharge hyperfield generator
hr1,
26,
scl 9s / scale on hyperspatial displacement
hr2,
27,
scl 4s / scale on hyperspatially induced velocity
hur,
30,
40000 / hyperspatial uncertancy
ran,
31,
0 / random number
/ place to build a private control word routine.
/ it should leave the control word in the io as follows.
/ high order 4 bits, rotate ccw, rotate cw, (both mean hyperspace)
/ fire rocket, and fire torpedo. low order 4 bits, same for
/ other ship. routine is entered by jsp cwg.
40/
cwr,
jmp mg1 / normally iot 11 control
. 20/ / space
////
/ routine to flush sequence breaks, if they occur.
sbf,
tyi
lio 2
lac 0
lsm
jmp i 1
define xincr X,Y,INS
lac Y
INS ~ssn
dac Y
lac X
INS ~scn
dac X
term
define yincr X,Y,INS
lac Y
INS ~scn
dac Y
lac X
-INS+add+sub ~ssn
dac X
term
////
define dispatch
add (a+r
dap . 1
jmp .
a,
term
define dispt A,Y,B
repeat 6, B=B+B
lio Y
dpy-A+B
term
define scale A,B,C
lac A
sar B
dac C
term
define diff V,S,QF
add i V
dac i V
xct QF
add i S
dac i S
term
define random
lac ran
rar 1s
xor (355760
add (355670
dac ran
term
define ranct S,X,C
random
S
X
sma
cma
dac C
term
////
/sine-cosine subroutine. adams associates
/calling sequence= number in ac, jda jda sin or jdacos.
/argument is between q+2 pi, with binary point to right of bit 3.
/anser has binary point to right of bit 0. time = 2.35 ms.
define mult Z
jda mpy
lac Z
term
cos,
0
dap csx
lac (62210
add cos
dac sin
jmp .+4
sin,
0
dap csx
lac sin
spa
si1,
add (311040
sub (62210
sma
jmp si2
add (62210
si3,
ral 2s
mult (242763
dac sin
mult sin
dac cos
mult (756103
add (121312
mult cos
add (532511
mult cos
add (144417
mult sin
scl 3s
dac cos
xor sin
sma
jmp csx-1
lac (377777
lio sin
spi
cma
jmp csx
lac cos
csx,
jmp .
si2,
cma
add (62210
sma
jmp si3
add (62210
spa
jmp .+3
sub (62210
jmp si3
sub (62210
jmp si1
////
/bbn multiply subroutine
/call.. lac one factor, jdy mpy or imp, lac other factor.
imp,
0 /returns low 17 bits and sign in ac
dap im1
im1,
xct
jda mpy
lac imp
idx im1
rir 1s
rcr 9s
rcr 9s
jmp i im1
mp2,
0
mpy,
0 /return 34 bits and 2 signs
dap mp1
lac mpy
spa
cma
rcr 9s
rcr 9s
mp1,
xct
spa
cma
dac mp2
cla
repeat 21, mus mp2
dac mp2
xct mp1
xor mpy
sma
jmp mp3
lac mp2
cma
rcr 9s
rcr 9s
cma
rcr 9s
rcr 9s
dac mp2
mp3,
idx mp1
lac mp2
jmp i mp1
////
/integer square root
/input in ac, binary point to right of bit 17, jda sqt
/answer in ac with binary point between 8 and 9
/largest input number = 177777
sqt,
0
dap sqx
law i 23
dac sq1
dzm sq2
lio sqt
dzm sqt
sq3,
isp sq1
jmp .+3
lac sq2
sqx,
jmp .
lac sq2
sal 1s
dac sq2
lac sqt
rcl 2s
sza i
jmp sq3
dac sqt
lac sq2
sal 1s
add (1
sub sqt
sma+sza-skip
jmp sq3
spa
cma
dac sqt
idx sq2
jmp sq3
sq1,
0
sq2,
0
////
/bbn divide subroutine
/calling sequence.. lac hi-dividend, lio lo-dividend, jda dvd, lac divisor.
/returns quot in ac, rem in io.
idv,
0 /integer divide, dividend in ac.
dap dv1
lac idv
scr 9s
scr 8s
dac dvd
jmp dv1
dvd,
0
dap dv1
dv1,
xct
spa
cma
dac idv
lac dvd
sma
jmp dv2
cma
rcr 9s
rcr 9s
cma
rcr 9s
rcr 9s
dv2,
sub idv
sma
jmp dve
repeat 22, dis idv
add idv
dio idv
cli
rcr 1s
lio dvd
spi
cma
dac dvd
xct dv1
xor dvd
rcr 9s
rcr 9s
idx dv1
dve,
idx dv1
lac idv
spi
cma
lio dvd
jmp i dv1
////
/outline compiler
/ac=where to compile to, call oc
/ot=address of outline table
define plinst A
lac A
dac i oc
idx oc
terminate
define comtab A, B
plinst A
jsp ocs
lac B
jmp oce
terminate
ocs,
dap ocz /puts in swap
dio i oc
idx oc
dio i oc
idx oc
ocz,
jmp .
oc,
0
dap ocx
lac i ocx
dap ocg
plinst (stf 5
dap ocm
idx ocx
ock,
plinst (lac ~sx1
plinst (lio ~sy1
clf 6
ocj,
setup ~occ,6
ocg,
lio .
och,
cla
rcl 3s
dio ~oci
lio (rcl 9s
dispatch
opr
jmp oc1
oco,
jmp oc2
ocq,
jmp oc3
ocp,
jmp oc4
ocr,
jmp oc5
jmp oc6
////
plinst (szf 5 //code
add (4
dap ocn
plinst ocn
plinst (dac ~sx1
plinst (dio ~sy1
plinst (jmp sq6
plinst (clf 5
plinst (lac ~scm
plinst (cma
plinst (dac ~scm
plinst (lac ~ssm
plinst (cma
plinst (dac ~ssm
plinst (lac ~csm
plinst (lio ~ssd
plinst (dac ~ssd
plinst (dio ~csm
plinst (lac ~ssc
plinst (lio ~csn
plinst (dac ~csn
plinst (dio ~ssc
plinst ocm
ocx,
jmp .
ocm,
jmp .
ocn,
jmp .
oc1,
plinst (add ~ssn
jsp ocs
lac (sub ~scn
oce,
dac i oc
idx oc
jsp ocs
plinst (ioh
lac (dpy-4000
ocd,
dac i oc
idx oc
lio ~oci
count ~occ, och
idx ocg
jmp ocj
oc2,
comtab (add ~scm, (add ~ssm
oc3,
comtab (add ~ssc, (sub ~csm
oc4,
comtab (sub ~scm, (sub ~ssm
oc5,
comtab (add ~csn, (sub ~ssd
oc6,
szf 6
jmp oc9
stf 6
plinst (dac ~ssa
lac (dio ~ssi
jmp ocd
oc9,
clf 6
plinst (lac ~ssa
lac (lio ~ssi
jmp ocd
////
/ display a star
define starp
add ~bx
swap
add ~by
swap
ioh
dpy-4000
terminate
/star
blp,
dap blx
szs 60
jmp blx
random
rar 9s
and (add 340
spa
xor (377777
dac ~bx
lac ran
ral 4s
and (add 340
spa
xor (377777
dac ~by
jsp bpt
ioh
blx,
jmp .
bpt,
dap bpx
random
sar 9s
sar 5s
spa
cma
sal 3s
add (bds
dap bjm
cla cli clf 6-opr-opr
dpy-4000
bjm,
jmp .
bds,
repeat 20, starp
szf 6
bpx,
jmp .
stf 6
cma
swap
cma
swap
jmp bjm
////
/background display . 3/13/62, prs.
define dislis J, Q, B
repeat 6, B=B+B
clf 5
lac flo+r
dap fpo+r
fs,
dap fin+r
dap fyn+r
idx fyn+r
fin,
lac /lac x
sub fpr /right margin
sma
jmp fgr+r
add (2000
frr,
spq
fou,
jmp fuu+r
fie,
sub (1000
sal 8s
fyn,
lio /lio y
dpy-i+B
stf 5
fid,
idx fyn+r
sad (lio Q+2
jmp flp+r
sad fpo+r
jmp fx+r
dap fin+r
idx fyn+r
jmp fin+r
fgr,
add (2000 -20000
jmp frr+r
fuu,
szf 5
fx,
jmp flo+r+1 /return
idx flo+r
idx flo+r
sas (Q+2
jmp fid+r
law J
dac flo+r
jmp fid+r
flp,
lac (lio J
sad fpo+r
jmp fx+r
dap fin+r
law J+1
dap fyn+r
jmp fin+r
fpo,
lio
flo,
J
terminate
////
define background
jsp bck
termin
bck,
dap bcx
szs 40
jmp bcx
isp bcc
bcx,
jmp .
law i 2
dac bcc
dislis 1j,1q,3
dislis 2j,2q,2
dislis 3j,3q,1
dislis 4j,4q,0
isp bkc
jmp bcx
law i 20
dac bkc
law i 1
add fpr
spa
add (20000
dac fpr
jmp bcx
bcc,
0
bkc,
0
fpr,
10000
////
/spacewar 3.1 24 sep 62 pt. 2
/main control for spaceships
nob=30 /total number of colliding objects
ml0,
load ~mtc, -4000 /delay for loop
init ml1, mtb /loc of calc routines
add (nob
dap mx1 /x
nx1=mtb nob
add (nob
dap my1 /y
ny1=nx1 nob
add (nob
dap ma1 / count for length of explosion or torp
na1=ny1 nob
add (nob
dap mb1 / count of instructions taken by calc routine
nb1=na1 nob
add (nob
dac ~mdx / dx
ndx=nb1 nob
add (nob
dac ~mdy / dy
ndy=ndx nob
add (nob
dap mom /angular velocity
nom=ndy nob
add (2
dap mth / angle
nth=nom 2
add (2
dac ~mfu /fuel
nfu=nth 2
add (2
dac ~mtr / no torps remaining
ntr=nfu 2
add (2
dap mot / outline of spaceship
not=ntr 2
add (2
dap mco / old control word
nco=not 2
add (2
dac ~mh1
nh1=nco 2
add (2
dac ~mh2
nh2=nh1 2
add (2
dac ~mh3
nh3=nh2 2
add (2
dac ~mh4
nh4=nh3 2
nnn=nh4 2
////
law ss1
xor mtb
sza
jmp mdn
law ss2
xor mtb 1
sza
jmp mdn
law 1 / test if both ships out of torps
add ntr
spa
jmp md1
law 1
add ntr 1
spa i
jmp mdn
md1,
xct tlf / restart delay is 2x torpedo life
sal 1s
dac ~ntd
jmp ml1
mdn,
count ~ntd,ml1
stf 1
stf 2
law ss1
xor mtb
sza
clf 1
sza i
idx ~1sc
law ss2
xor mtb 1
sza
clf 2
sza i
idx ~2sc
clf 2
jmp a
////
a1,
law mg2 / test word control
dac ~cwg
jmp a
a40,
law cwr / here from start at 4
dac ~cwg
jmp a6
a,
lac ~gct
sma
jmp a5
count ~gct, a5
lac ~1sc
sas ~2sc
jmp a4
law i 1
dac ~gct
a5,
lat
and (40
sza i
jmp a2
a4,
lac ~1sc
lio ~2sc
hlt
lat
and (40
sza
jmp a2
dzm ~1sc
dzm ~2sc
a6,
lat
rar 6s
and (37
sza
cma
dac ~gct
a2,
clear mtb, nnn-1 / clear out all tables
law ss1
dac mtb
law ss2
dac mtb 1
lac (200000
dac nx1
dac ny1
cma
dac nx1 1
dac ny1 1
lac (144420
dac nth
////
law nnn / start of outline problem
dac not
lio ddd
spi i
jmp a3
jda oc
ot1
a3,
dac not 1
jda oc
ot2
xct tno
dac ntr
dac ntr 1
lac foo
dac nfu
dac nfu 1
law 2000
dac nb1
dac nb1 1
xct mhs
dac nh2
dac nh2 1
jmp ml0
/ control word get routines
mg1,
dap mg3
cli
iot 11
mg3,
jmp .
mg2,
dap mg4
lat
swap
mg4,
jmp .
////
ml1,
lac . / 1st control word
sza i / zero if not active
jmp mq1 / not active
swap
idx ~moc
spi
jmp mq4
law 1
add ml1
dap ml2
law 1
add mx1
dap mx2
law 1
add my1
dap my2
law 1
add ma1
dap ma2
law 1
add mb1
dap mb2
mot,
lac .
dap sp5
ml2,
lac . / 2nd control word
spq / can it collide?
jmp mq2 / no
mx1,
lac . / calc if collision
mx2,
sub . / delta x
spa / take abs value