-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.tras
1529 lines (1393 loc) · 24.7 KB
/
game.tras
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
CONST proc_type, 0
CONST proc_chain, 1
CONST proc_pid, 2
CONST proc_name, 3
CONST proc_xy, 4
CONST proc_hp, 5
CONST proc_drunk, 6
CONST proc_attack, 7
CONST proc_speed, 8
CONST proc_move, 9
CONST proc_inv, 10
CONST proc_pgt_ptr, 11
CONST proc_pgt_reg, 12
CONST proc_pc, 13
CONST proc_psw, 14
CONST proc_regs, 15
CONST proc_iterator, 23
CONST proc_size, 24
CONST item_type, 0
CONST item_chain, 1
CONST item_count, 2
CONST item_size, 3
CONST pdesc_name, 0
CONST pdesc_type, 1
CONST pdesc_hp, 2
CONST pdesc_drunk, 3
CONST pdesc_attack, 4
CONST pdesc_speed, 5
CONST pdesc_item, 6
CONST type_mcguffin, -5
CONST type_empty, -4
CONST type_vodka, -3
CONST type_redbull, -2
CONST type_walizka, -1
CONST type_pc, 1
CONST type_valis, 2
CONST type_blue, 3
CONST type_white, 4
CONST type_drunk, 5
CONST type_cyber, 6
CONST notify_bump, -3
CONST notify_croak, -2
CONST notify_attack, -1
CONST notify_square, 1
CONST notify_give, 2
CONST notify_use, 3
CONST num_pids, 27
CONST vector_pf_x, -12
CONST vector_pf_w, -9
CONST vector_pf_r, -6
CONST vector_df, -3
vector_reset:
J reset_handler
BYTE 0
vector_syscall:
J syscall_handler
BYTE 0
vector_priverr:
J priverr_handler
BYTE 0
vector_illegal:
J illegal_handler
BYTE 0
vector_div0:
J div0_handler
reset_handler:
MOV @1, "Initializing operating system..."
MOV @2, -1
HVC 1
# Write out remaining handlers.
MOV @1, #---000000
ST @1, [vector_pf_x]
ST @1, [vector_pf_w]
ST @1, [vector_pf_r]
ST @1, [vector_df]
MOV @1, pf_x_handler
ST @1, [vector_pf_x+1]
MOV @1, pf_w_handler
ST @1, [vector_pf_w+1]
MOV @1, pf_r_handler
ST @1, [vector_pf_r+1]
MOV @1, df_handler
ST @1, [vector_df+1]
# Initialize page allocator.
MOV @1, data_end-1
SHR @1, 6
ST @1, [last_pg]
MOV @1, data_end
ST @1, [heap_end]
# Initialize kernel page tables.
MOV @1, @0
MOV @2, rodata_start
SHR @2, 6
init_pgt_code_loop:
SHL @3, @1, 3
XOR @3, #00000000-
ST @3, [kernel_pgt + @1]
ADD @1, 1
CMP @1, @2
JNZ init_pgt_code_loop
MOV @2, data_start
SHR @2, 6
init_pgt_rodata_loop:
SHL @3, @1, 3
XOR @3, #000000-00
ST @3, [kernel_pgt + @1]
ADD @1, 1
CMP @1, @2
JNZ init_pgt_rodata_loop
LD @2, [last_pg]
ADD @2, 1
init_pgt_data_loop:
SHL @3, @1, 3
XOR @3, #000000--0
ST @3, [kernel_pgt + @1]
ADD @1, 1
CMP @1, @2
JNZ init_pgt_data_loop
# Stack page.
MOV @1, #00000---0
ST @1, [kernel_pgt - 1]
# Initialize stack pointer.
MOV @-4, #000------
# Enable paging.
MOV @1, kernel_pgt
SHR @1, 3
R2S @PGTN, @1
MOV @1, #---000000
R2S @PSW, @1
# Start user programs.
MOV @1, "Starting user programs..."
MOV @2, -1
HVC 1
MOV @1, desc_pc
J @-1, spawn_process
MOV @1, desc_valis
J @-1, spawn_process
MOV @-2, 9
blue_spawn_loop:
MOV @1, desc_blue
J @-1, spawn_process
SUB @-2, 1
JNZ blue_spawn_loop
MOV @-2, 3
white_spawn_loop:
MOV @1, desc_white
J @-1, spawn_process
SUB @-2, 1
JNZ white_spawn_loop
MOV @-2, 3
drunk_spawn_loop:
MOV @1, desc_drunk
J @-1, spawn_process
SUB @-2, 1
JNZ drunk_spawn_loop
MOV @1, desc_cyber
J @-1, spawn_process
# Initialize board.
MOV @1, "Initializing board..."
MOV @2, -1
HVC 1
MOV @-3, @0
init_process_place_loop:
LD @1, [processes + @-3]
CMP @1, @0
JZ init_process_place_cont
init_process_place_retry:
RNG @2
AND @2, #00+++++++
LD @3, [board + @2]
CMP @3, @0
JG init_process_place_retry
J @-1, place_process
init_process_place_cont:
ADD @-3, 1
CMP @-3, num_pids
JNZ init_process_place_loop
# Start the game.
MOV @1, "Entering game loop..."
MOV @2, -1
HVC 1
MOV @-3, @0
loop:
LD @-2, [processes + @-3]
ADD @-3, 1
CMP @-3, num_pids
JNZ loop_no_wrap
MOV @-3, @0
loop_no_wrap:
CMP @-2, @0
JZ loop
# Add move points.
LD @1, [@-2 + proc_move]
LD @2, [@-2 + proc_speed]
ADD @1, 1
ST @1, [@-2 + proc_move]
CMP @1, @2
JNZ loop
ST @0, [@-2 + proc_move]
# Action time.
ST @0, [@-2 + proc_regs + 4]
MOV @1, @-2
J @-1, run_user
LD @1, [@-2 + proc_regs + 4]
AND @1, #0000000++
LD @1, [action_jtable + @1]
J @1
action_move:
LD @1, [@-2 + proc_regs + 5]
CMP @1, @0
JZ loop
J @-1, drunk_confusion
LD @2, [@-2 + proc_xy]
AND @3, @2, #00000++++
AND @4, @1, #00000000+
ADD @3, @4
AND @0, @3, #+++++0000
JNZ move_bump_wall
SHR @4, @2, 4
SHR @1, 1
AND @1, #00000000+
ADD @4, @1
AND @0, @4, #++++++000
JNZ move_bump_wall
SHL @4, 4
XOR @3, @4
LD @4, [board + @3]
CMP @4, @0
JZ move_ok
LD @1, [@4 + proc_type]
CMP @1, 0
JG move_bump_other
move_ok:
SUB @-4, 1
ST @3, [@-4]
LD @1, [@-2 + proc_chain]
ST @0, [@-2 + proc_chain]
ST @1, [board + @2]
J @-1, clear_square
LD @2, [@-4]
ADD @-4, 1
MOV @1, @-2
J @-1, place_process
J loop
move_bump_wall:
MOV @1, notify_bump
LD @2, [@-2 + proc_pid]
MOV @3, @0
MOV @4, @0
J @-1, broadcast
J loop
move_bump_other:
MOV @1, notify_bump
LD @2, [@-2 + proc_pid]
LD @3, [@4 + proc_pid]
MOV @4, @0
J @-1, broadcast
J loop
action_attack:
LD @1, [@-2 + proc_regs + 5]
CMP @1, @0
JZ loop
J @-1, drunk_confusion
LD @2, [@-2 + proc_xy]
AND @3, @2, #00000++++
AND @4, @1, #00000000+
ADD @3, @4
AND @0, @3, #+++++0000
JNZ move_bump_wall
SHR @4, @2, 4
SHR @1, 1
AND @1, #00000000+
ADD @4, @1
AND @0, @4, #++++++000
JNZ move_bump_wall
SHL @4, 4
XOR @3, @4
LD @4, [board + @3]
CMP @4, @0
JZ attack_air
LD @1, [@4 + proc_type]
CMP @1, 0
JLE attack_air
# Actual attack.
RNG @1
CMP @1, 0
JGE attack_rnd_pos
NEG @1, @1
attack_rnd_pos:
LD @2, [@-2 + proc_attack]
MOD @1, @2
ADD @1, @2
ADD @1, 1
LD @2, [@4 + proc_hp]
SUB @2, @1
JLE attack_croak
ST @2, [@4 + proc_hp]
MOV @1, notify_attack
LD @3, [@4 + proc_pid]
MOV @4, @2
LD @2, [@-2 + proc_pid]
J @-1, broadcast
J loop
attack_croak:
MOV @1, notify_croak
LD @2, [@-2 + proc_pid]
LD @3, [@4 + proc_pid]
MOV @-2, @4
J @-1, broadcast
LD @1, [@-2 + proc_type]
CMP @1, type_pc
JZ die
# Dump inventory.
LD @1, [@-2 + proc_inv]
LD @2, [@-2 + proc_xy]
ADD @2, @2, board
J @-1, chain_splice
# Clear from board.
LD @2, [@-2 + proc_xy]
LD @1, [@-2 + proc_chain]
ST @1, [board + @2]
J @-1, clear_square
LD @1, [@-2 + proc_pid]
ST @0, [processes + @1]
J loop
die:
MOV @1, 0
HVC 0
attack_air:
MOV @1, notify_attack
LD @2, [@-2 + proc_pid]
MOV @3, @0
MOV @4, @0
J @-1, broadcast
J loop
action_pick:
ADD @1, @-2, proc_chain
LD @2, [@-2 + proc_regs + 5]
LD @3, [@-2 + proc_regs + 6]
J @-1, chain_get
CMP @1, 0
JZ loop
ADD @1, @-2, proc_inv
LD @2, [@-2 + proc_regs + 5]
LD @3, [@-2 + proc_regs + 6]
J @-1, chain_put
J loop
action_drop:
ADD @1, @-2, proc_inv
LD @2, [@-2 + proc_regs + 5]
LD @3, [@-2 + proc_regs + 6]
J @-1, chain_get
CMP @1, 0
JZ loop
ADD @1, @-2, proc_chain
LD @2, [@-2 + proc_regs + 5]
LD @3, [@-2 + proc_regs + 6]
J @-1, chain_put
J loop
action_use:
ADD @1, @-2, proc_inv
LD @2, [@-2 + proc_regs + 5]
MOV @3, 1
CMP @2, type_walizka
JZ use_ok
CMP @2, type_vodka
JZ use_ok
CMP @2, type_redbull
JZ use_ok
MOV @1, "Not a usable item."
MOV @2, 2
HVC 1
J loop
use_ok:
J @-1, chain_get
CMP @1, 0
JZ loop
LD @2, [@-2 + proc_regs + 5]
CMP @2, type_walizka
JZ use_walizka
CMP @2, type_vodka
JZ use_vodka
LD @2, [@-2 + proc_hp]
ADD @2, 100
ST @2, [@-2 + proc_hp]
J use_notify
use_walizka:
LD @2, [@-2 + proc_drunk]
ADD @2, 3
ST @2, [@-2 + proc_drunk]
J use_notify
use_vodka:
LD @2, [@-2 + proc_drunk]
ADD @2, 1
ST @2, [@-2 + proc_drunk]
use_notify:
MOV @1, notify_use
ST @1, [@-2 + proc_regs + 4]
LD @1, [@-2 + proc_hp]
ST @1, [@-2 + proc_regs + 6]
LD @1, [@-2 + proc_drunk]
ST @1, [@-2 + proc_regs + 7]
MOV @1, @-2
J @-1, run_user
J loop
action_give:
LD @1, [@-2 + proc_regs + 5]
CMP @1, @0
JZ loop
J @-1, drunk_confusion
LD @2, [@-2 + proc_xy]
AND @3, @2, #00000++++
AND @4, @1, #00000000+
ADD @3, @4
AND @0, @3, #+++++0000
JNZ move_bump_wall
SHR @4, @2, 4
SHR @1, 1
AND @1, #00000000+
ADD @4, @1
AND @0, @4, #++++++000
JNZ move_bump_wall
SHL @4, 4
XOR @3, @4
LD @4, [board + @3]
CMP @4, @0
JZ loop
LD @1, [@4 + proc_type]
CMP @1, 0
JLE loop
# Actual give code.
SUB @-4, 1
ST @4, [@-4]
ADD @1, @-2, proc_inv
LD @2, [@-2 + proc_regs + 6]
LD @3, [@-2 + proc_regs + 7]
J @-1, chain_get
LD @4, [@-4]
ADD @-4, 1
CMP @1, 0
JZ loop
SUB @-4, 1
ST @4, [@-4]
ADD @1, @4, proc_inv
LD @2, [@-2 + proc_regs + 6]
LD @3, [@-2 + proc_regs + 7]
J @-1, chain_put
LD @4, [@-4]
ADD @-4, 1
# Notify.
MOV @1, notify_give
ST @1, [@4 + proc_regs + 4]
LD @1, [@-2 + proc_pid]
ST @1, [@4 + proc_regs + 5]
LD @1, [@-2 + proc_regs + 6]
ST @1, [@4 + proc_regs + 6]
LD @1, [@-2 + proc_regs + 7]
ST @1, [@4 + proc_regs + 7]
MOV @1, @4
J @-1, run_user
J loop
action_unknown:
MOV @1, "Unknown action "
J @-1, log_str
LD @1, [@-2 + proc_regs + 4]
J @-1, log_raw
MOV @1, 1
J @-1, log_finish
J loop
drunk_confusion:
LD @2, [@-2 + proc_drunk]
RNG @3
AND @3, 1
ADD @3, 1
CMP @3, @2
JGE @-1
RNG @2
AND @2, #0000000++
JZ @-1
MOV @1, @2
J @-1
place_process:
ST @2, [@1 + proc_xy]
LD @3, [board + @2]
ST @3, [@1 + proc_chain]
ST @1, [board + @2]
LD @3, [@1 + proc_type]
LD @4, [@1 + proc_pid]
MOV @1, notify_square
J broadcast
clear_square:
MOV @1, notify_square
MOV @3, @0
MOV @4, @0
LD @3, [board + @2]
CMP @3, 0
JZ broadcast
LD @3, [@3 + proc_type]
J broadcast
# in: @1 ptr to chain, @2 type, @3 count
# out: @1 1 success, 0 fail
chain_get:
LD @4, [@1]
CMP @4, 0
JZ chain_get_not_found
LD @4, [@4 + item_type]
CMP @4, @2
JZ chain_get_found
LD @1, [@1]
ADD @1, item_chain
J chain_get
chain_get_found:
LD @4, [@1]
LD @2, [@4 + item_count]
SUB @2, @3
JL chain_get_too_few
JZ chain_get_remove
ST @2, [@4 + item_count]
MOV @1, 1
J @-1
chain_get_remove:
LD @2, [@4 + item_chain]
ST @2, [@1]
MOV @1, 1
J @-1
chain_get_not_found:
SUB @-4, 2
ST @-1, [@-4 + 0]
ST @2, [@-4 + 1]
MOV @1, "Item type "
J @-1, log_str
LD @1, [@-4 + 1]
J @-1, log_int
MOV @1, " not found on chain"
J @-1, log_str
MOV @1, 2
J @-1, log_finish
LD @-1, [@-4 + 0]
ADD @-4, 2
MOV @1, 0
J @-1
chain_get_too_few:
SUB @-4, 4
ST @-1, [@-4 + 0]
LD @2, [@4 + item_type]
ST @2, [@-4 + 1]
LD @2, [@4 + item_count]
ST @2, [@-4 + 2]
ST @3, [@-4 + 3]
MOV @1, "Not enough of item type "
J @-1, log_str
LD @1, [@-4 + 1]
J @-1, log_int
MOV @1, ": have "
J @-1, log_str
LD @1, [@-4 + 2]
J @-1, log_int
MOV @1, ", requested "
J @-1, log_str
LD @1, [@-4 + 3]
J @-1, log_int
MOV @1, 2
J @-1, log_finish
LD @-1, [@-4 + 0]
ADD @-4, 4
MOV @1, 0
J @-1
# in: @1 ptr to chain, @2 type, @3 count
chain_put:
LD @4, [@1]
CMP @4, 0
JZ chain_put_end
LD @4, [@4 + item_type]
CMP @4, @2
JZ chain_put_found
LD @1, [@1]
ADD @1, item_chain
J chain_put
chain_put_found:
LD @4, [@1]
LD @2, [@4 + item_count]
ADD @2, @3
ST @2, [@4 + item_count]
J @-1
chain_put_end:
SUB @-4, 4
ST @-1, [@-4 + 0]
ST @1, [@-4 + 1]
ST @2, [@-4 + 2]
ST @3, [@-4 + 3]
MOV @1, item_size
J @-1, malloc
LD @4, [@-4 + 1]
LD @2, [@-4 + 2]
LD @3, [@-4 + 3]
ST @1, [@4]
ST @2, [@1 + item_type]
ST @3, [@1 + item_count]
ST @0, [@1 + item_chain]
LD @-1, [@-4 + 0]
ADD @-4, 4
J @-1
# in: @1 src chain, @2 ptr to dst chain
chain_splice:
SUB @-4, 3
ST @-1, [@-4 + 0]
ST @1, [@-4 + 1]
ST @2, [@-4 + 2]
chain_splice_loop:
LD @1, [@-4 + 1]
CMP @1, 0
JZ chain_splice_end
LD @4, [@1 + item_chain]
ST @4, [@-4 + 1]
LD @2, [@1 + item_type]
LD @3, [@1 + item_count]
LD @1, [@-4 + 2]
J @-1, chain_put
J chain_splice_loop
chain_splice_end:
LD @-1, [@-4 + 0]
ADD @-4, 3
J @-1
broadcast:
SUB @-4, 6
ST @-1, [@-4 + 0]
ST @-2, [@-4 + 1]
ST @1, [@-4 + 2]
ST @2, [@-4 + 3]
ST @3, [@-4 + 4]
ST @4, [@-4 + 5]
MOV @-2, @0
broadcast_loop:
LD @1, [processes + @-2]
CMP @1, @0
JZ broadcast_cont
LD @2, [@-4 + 2]
ST @2, [@1 + proc_regs + 4]
LD @2, [@-4 + 3]
ST @2, [@1 + proc_regs + 5]
LD @2, [@-4 + 4]
ST @2, [@1 + proc_regs + 6]
LD @2, [@-4 + 5]
ST @2, [@1 + proc_regs + 7]
J @-1, run_user
broadcast_cont:
ADD @-2, 1
CMP @-2, num_pids
JNZ broadcast_loop
LD @-1, [@-4 + 0]
LD @-2, [@-4 + 1]
ADD @-4, 6
J @-1
syscall_handler:
R2S @SCRP, @1
MOV @1, #---000+00
R2S @PSW, @1
S2R @1, @SCRZ
ST @-4, [@1 + proc_regs + 0]
ST @-3, [@1 + proc_regs + 1]
ST @-2, [@1 + proc_regs + 2]
ST @-1, [@1 + proc_regs + 3]
ST @2, [@1 + proc_regs + 5]
ST @3, [@1 + proc_regs + 6]
ST @4, [@1 + proc_regs + 7]
S2R @-4, @SCRN
S2R @2, @SCRP
ST @2, [@1 + proc_regs + 4]
S2R @2, @EPSW
ST @2, [@1 + proc_psw]
S2R @2, @EPC
ADD @2, 1
ST @2, [@1 + proc_pc]
SETF @TL, 0
S2R @2, @EDATA
AND @2, #0000000++
LD @2, [syscall_jtable + @2]
J @2
syscall_yield:
R2S @SCRZ, @0
LD @-3, [@-4 + 0]
LD @-2, [@-4 + 1]
LD @-1, [@-4 + 2]
ADD @-4, 3
J @-1
run_user:
SUB @-4, 3
ST @-3, [@-4 + 0]
ST @-2, [@-4 + 1]
ST @-1, [@-4 + 2]
R2S @SCRZ, @1
R2S @SCRN, @-4
syscall_exit:
S2R @1, @SCRZ
LD @2, [@1 + proc_pgt_reg]
R2S @PGTP, @2
LD @2, [@1 + proc_pc]
R2S @EPC, @2
LD @2, [@1 + proc_psw]
R2S @EPSW, @2
LD @2, [@1 + proc_regs + 4]
R2S @SCRP, @2
LD @-4, [@1 + proc_regs + 0]
LD @-3, [@1 + proc_regs + 1]
LD @-2, [@1 + proc_regs + 2]
LD @-1, [@1 + proc_regs + 3]
LD @2, [@1 + proc_regs + 5]
LD @3, [@1 + proc_regs + 6]
LD @4, [@1 + proc_regs + 7]
S2R @1, @SCRP
ERET
syscall_iterate_floor:
LD @2, [@1 + proc_chain]
ST @2, [@1 + proc_iterator]
J syscall_exit
syscall_iterate_inv:
LD @2, [@1 + proc_inv]
ST @2, [@1 + proc_iterator]
J syscall_exit
syscall_iterate_next:
LD @2, [@1 + proc_iterator]
CMP @2, 0
JZ iterate_done
LD @3, [@2 + item_type]
ST @3, [@1 + proc_regs + 4]
LD @3, [@2 + item_count]
ST @3, [@1 + proc_regs + 5]
LD @3, [@2 + item_chain]
ST @3, [@1 + proc_iterator]
J syscall_exit
iterate_done:
ST @0, [@1 + proc_regs + 4]
ST @0, [@1 + proc_regs + 5]
J syscall_exit
syscall_look:
LD @2, [@1 + proc_regs + 4]
AND @2, #00+++++++
LD @4, [board + @2]
MOV @2, @0
MOV @3, @0
CMP @4, @0
JZ syscall_look_done
LD @2, [@4 + proc_type]
CMP @2, @0
JL syscall_look_done
LD @3, [@4 + proc_pid]
syscall_look_done:
ST @2, [@1 + proc_regs + 4]
ST @3, [@1 + proc_regs + 5]
J syscall_exit
syscall_log:
LD @2, [@1 + proc_regs + 4]
MOV @3, usr_log_buf
SETF @RM, 1
SETF @RP, 1
syscall_log_loop:
LD @4, [@2++]
ST @4, [@3++]
CMP @4, @0
JZ syscall_log_loop_end
CMP @3, usr_log_buf + 242
JNZ syscall_log_loop
syscall_log_loop_end:
ST @0, [@3++]
SETF @RP, -1
SETF @RM, 0
S2R @1, @SCRZ
LD @1, [@1 + proc_name]
J @-1, log_str
MOV @1, "/"
J @-1, log_str
S2R @1, @SCRZ
LD @1, [@1 + proc_pid]
J @-1, log_int
MOV @1, ": "
J @-1, log_str
MOV @1, usr_log_buf
J @-1, log_str
S2R @1, @SCRZ
LD @1, [@1 + proc_regs + 5]
J @-1, log_finish
J syscall_exit
syscall_pidinfo:
LD @2, [@1 + proc_regs + 4]
CMP @2, @0
JL syscall_pidinfo_error
CMP @2, num_pids
JGE syscall_pidinfo_error
LD @2, [processes + @2]
CMP @2, @0
JZ syscall_pidinfo_error
LD @3, [@2 + proc_xy]
ST @3, [@1 + proc_regs + 4]
LD @3, [@2 + proc_type]
ST @3, [@1 + proc_regs + 5]
J syscall_exit
syscall_pidinfo_error:
ST @0, [@1 + proc_regs + 4]
ST @0, [@1 + proc_regs + 5]
ST @0, [@1 + proc_regs + 6]
J syscall_exit
syscall_quit:
S2R @1, @SCRZ
LD @1, [@1 + proc_regs + 4]
HVC 0
syscall_flag:
LD @2, [@1 + proc_type]
MOV @1, "flag1.txt"
CMP @2, type_pc
JZ do_flag
MOV @1, "flag2.txt"
CMP @2, type_valis
JNZ flag_nope
do_flag:
HVC 4
CMP @1, @0
JL flag_fail
S2R @4, @SCRZ
MOV @2, @1
MOV @3, 0
LD @1, [@4 + proc_regs + 4]
ST @2, [@4 + proc_regs + 4]
SETF @WP, 1
SETF @WM, 1
HVC 3
SETF @WP, -1
SETF @WM, 0
CMP @1, 0
JL flag_fail
J syscall_exit
flag_fail:
MOV @1, "Flag read failed!"
MOV @2, 2
HVC 1
flag_nope:
S2R @1, @SCRZ
ST @0, [@1 + proc_regs + 4]
J syscall_exit
syscall_unknown:
MOV @1, "Unknown syscall "
J @-1, log_str
S2R @1, @EDATA
J @-1, log_raw
MOV @1, 1
J @-1, log_finish
J syscall_exit
df_handler:
ST @-4, [exc_regs]
ST @-3, [exc_regs+1]
ST @-2, [exc_regs+2]
ST @-1, [exc_regs+3]
ST @1, [exc_regs+4]
ST @2, [exc_regs+5]
ST @3, [exc_regs+6]
ST @4, [exc_regs+7]
J @-1, log_clear
MOV @1, "DOUBLE FAULT "
J @-1, log_str
S2R @1, @EDATA
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
exc_common:
S2R @1, @SCRZ
CMP @1, @0
JZ exc_no_process
MOV @1, "PROCESS: "
J @-1, log_str
S2R @1, @SCRZ
LD @1, [@1 + proc_name]
J @-1, log_str
MOV @1, "/"
J @-1, log_str
S2R @1, @SCRZ
LD @1, [@1 + proc_pid]
J @-1, log_int
MOV @1, 2
J @-1, log_finish
exc_no_process:
MOV @1, "PC = "
J @-1, log_str
S2R @1, @EPC
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "PSW = "
J @-1, log_str
S2R @1, @EPSW
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "R-4 = "
J @-1, log_str
LD @1, [exc_regs]
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "R-3 = "
J @-1, log_str
LD @1, [exc_regs+1]
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "R-2 = "
J @-1, log_str
LD @1, [exc_regs+2]
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "R-1 = "
J @-1, log_str
LD @1, [exc_regs+3]
J @-1, log_raw
MOV @1, 2
J @-1, log_finish
MOV @1, "R1 = "
J @-1, log_str
LD @1, [exc_regs+4]
J @-1, log_raw
MOV @1, 2