-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.asm
1270 lines (1178 loc) · 23.4 KB
/
game.asm
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 valis, 1
CONST redford, 2
CONST redbull, 3
CONST rum, 4
CONST gin, 5
CONST tequila, 6
CONST jagermeister, 7
CONST baileys, 8
CONST coca_cola, 9
CONST tonic, 10
CONST orange, 11
CONST grenadine, 12
CONST milk, 13
CONST pigwowka, 14
CONST invsz, 15
CONST dir_s, 1
CONST dir_n, 2
CONST dir_e, 4
CONST dir_w, 8
DATA cache_cur, 1
DATA cache_dir, 1
DATA valis_state, 1
DATA redford_state, 1
DATA pos, 2
DATA hp, 2
DATA monster_hp, 2
DATA cheater, 1
DATA lfsr, 3
DATA dig, 4
DATA inv, invsz
DATA board, 64
CONST drunk, inv
start:
CALL init
main_loop:
CALL cache
CALL menu
CALL main_cmd
B main_loop
menu:
CALL print_space_desc
LPTR "SELECT AN OPTION:\r\n\r\n"
CALL print_str
CALL menu_dirs
CALL menu_space_cmds
CALL menu_misc
LPTR "\r\nYOUR CHOICE: "
CALL print_str
RET
menu_dirs:
AND dir_s, [cache_dir]
BZ menu_dirs_no_s
LPTR "- GO (S)OUTH\r\n"
CALL print_str
menu_dirs_no_s:
AND dir_n, [cache_dir]
BZ menu_dirs_no_n
LPTR "- GO (N)ORTH\r\n"
CALL print_str
menu_dirs_no_n:
AND dir_e, [cache_dir]
BZ menu_dirs_no_e
LPTR "- GO (E)AST\r\n"
CALL print_str
menu_dirs_no_e:
AND dir_w, [cache_dir]
BZ menu_dirs_no_w
LPTR "- GO (W)EST\r\n"
CALL print_str
menu_dirs_no_w:
RET
menu_space_cmds:
ADD 0, [cache_cur]
BZ menu_space_cmds_no_fight
SUB redford, [cache_cur]
BC menu_space_cmds_no_talk
LPTR "- (T)ALK TO "
CALL print_str
CALL print_the_monster
CALL print_nl
menu_space_cmds_no_talk:
SUB valis, [cache_cur]
BZ menu_space_cmds_no_fight
LPTR "- (F)IGHT "
CALL print_str
CALL print_the_monster
CALL print_nl
menu_space_cmds_no_fight:
RET
menu_misc:
LPTR "- (D)RINK\r\n"
CALL print_str
LPTR "- SHOW (I)NVENTORY\r\n"
CALL print_str
RET
cache:
MOV R0, [pos]
MOV R1, [pos+1]
ADD R0, LO board
ADC R1, MID board
MOV [cache_cur], DATA
MOV [cache_dir], 0
MOV R0, [pos]
AND R0, 7
BZ cache_no_w
OR [cache_dir], dir_w
cache_no_w:
SUB 7, R0
BZ cache_no_e
OR [cache_dir], dir_e
cache_no_e:
MOV R0, [pos]
MOV R1, [pos+1]
SHR R1, R1
RCR R0, R0
SHR R1, R1
RCR R0, R0
SHR R1, R1
RCR R0, R0
AND R0, 7
BZ cache_no_s
OR [cache_dir], dir_s
cache_no_s:
SUB 7, R0
BZ cache_no_n
OR [cache_dir], dir_n
cache_no_n:
RET
main_cmd:
GETC R0
PUTC R0
MOV R1, 0
MOV R2, 0
SHL R0, R0
RCL R1, R1
SHL R0, R0
RCL R1, R1
ADD R0, LO jtab_main_cmd
ADC R1, MID jtab_main_cmd
ADC R2, HI jtab_main_cmd
PUSH R2
PUSH R1
PUSH R0
RET
jtab_main_cmd:
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_east
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_inventory
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_fight
JMP main_cmd_drink
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_south
JMP main_cmd_talk
JMP main_cmd_west
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_invalid
JMP main_cmd_north
JMP main_cmd_invalid
main_cmd_invalid:
LPTR "\r\n\r\nINVALID OPTION.\r\n\r\n"
CALL print_str
RET
main_cmd_south:
AND dir_s, [cache_dir]
BZ main_cmd_move_err
SUB [pos], 8
SBB [pos+1], 0
LPTR "\r\n\r\nYOU MOVE TO THE SOUTH.\r\n\r\n"
CALL print_str
RET
main_cmd_north:
AND dir_n, [cache_dir]
BZ main_cmd_move_err
ADD [pos], 8
ADC [pos+1], 0
LPTR "\r\n\r\nYOU MOVE TO THE NORTH.\r\n\r\n"
CALL print_str
RET
main_cmd_east:
AND dir_e, [cache_dir]
BZ main_cmd_move_err
ADD [pos], 1
LPTR "\r\n\r\nYOU MOVE TO THE EAST.\r\n\r\n"
CALL print_str
RET
main_cmd_west:
AND dir_w, [cache_dir]
BZ main_cmd_move_err
SUB [pos], 1
LPTR "\r\n\r\nYOU MOVE TO THE WEST.\r\n\r\n"
CALL print_str
RET
main_cmd_move_err:
LPTR "\r\n\r\nYOU CANNOT MOVE IN THAT DIRECTION.\r\n\r\n"
CALL print_str
RET
main_cmd_inventory:
LPTR "\r\n\r\nYOUR INVENTORY:\r\n\r\n"
CALL print_str
MOV R0, 1
inv_loop:
PUSH R0
MOV R1, 0
ADD R0, inv
ADC R1, 0
ADD 0, DATA
BZ inv_skip
PUSH DATA
LPTR "- "
CALL print_str
POP R0
POP R3
PUSH R3
PUSH R0
LPTR stab_item
CALL print_from_tab
LPTR " ("
CALL print_str
POP R0
MOV R1, 0
CALL print_num
LPTR ")\r\n"
CALL print_str
inv_skip:
POP R0
ADD R0, 1
SUB invsz, R0
BNZ inv_loop
LPTR "\r\n"
CALL print_str
CALL print_health
ADD 0, [drunk]
BZ inv_no_drunk
SUB 2, [drunk]
BC inv_very_drunk
LPTR "YOU ARE DRUNK.\r\n"
CALL print_str
B inv_no_drunk
inv_very_drunk:
LPTR "YOU ARE VERY DRUNK.\r\n"
CALL print_str
inv_no_drunk:
LPTR "\r\n"
CALL print_str
RET
main_cmd_drink:
LPTR "\r\n\r\nCHOOSE AN ITEM TO DRINK:\r\n\r\n"
CALL print_str
ADD 0, [inv+valis]
BZ drink_no_valis
LPTR "- WALIZKA (V)ALISA\r\n"
CALL print_str
drink_no_valis:
ADD 0, [inv+redbull]
BZ drink_no_redbull
LPTR "- CAN OF (R)EDBULL\r\n"
CALL print_str
drink_no_redbull:
ADD 0, [inv+rum]
BZ drink_no_rum
LPTR "- BOTTLE OF R(U)M\r\n"
CALL print_str
drink_no_rum:
ADD 0, [inv+gin]
BZ drink_no_gin
LPTR "- BOTTLE OF (G)IN\r\n"
CALL print_str
drink_no_gin:
ADD 0, [inv+tequila]
BZ drink_no_tequila
LPTR "- BOTTLE OF (T)EQUILA\r\n"
CALL print_str
drink_no_tequila:
ADD 0, [inv+jagermeister]
BZ drink_no_jager
LPTR "- BOTTLE OF (J)AGERMEISTER\r\n"
CALL print_str
drink_no_jager:
ADD 0, [inv+baileys]
BZ drink_no_baileys
LPTR "- BOTTLE OF (B)AILEYS\r\n"
CALL print_str
drink_no_baileys:
ADD 0, [inv+coca_cola]
BZ drink_no_cola
LPTR "- BOTTLE OF (C)OCA-COLA\r\n"
CALL print_str
drink_no_cola:
ADD 0, [inv+tonic]
BZ drink_no_tonic
LPTR "- BOTTLE OF TO(N)IC\r\n"
CALL print_str
drink_no_tonic:
ADD 0, [inv+orange]
BZ drink_no_orange
LPTR "- CARTON OF (O)RANGE JUICE\r\n"
CALL print_str
drink_no_orange:
ADD 0, [inv+grenadine]
BZ drink_no_grenadine
LPTR "- GRENADINE (S)YRUP\r\n"
CALL print_str
drink_no_grenadine:
ADD 0, [inv+milk]
BZ drink_no_milk
LPTR "- CARTON OF (M)ILK\r\n"
CALL print_str
drink_no_milk:
LPTR "\r\nYOUR CHOICE: "
CALL print_str
GETC R0
PUTC R0
CALL print_nl
CALL print_nl
MOV R1, 0
MOV R2, 0
SHL R0, R0
RCL R1, R1
SHL R0, R0
RCL R1, R1
ADD R0, LO jtab_drink
ADC R1, MID jtab_drink
ADC R2, HI jtab_drink
PUSH R2
PUSH R1
PUSH R0
RET
jtab_drink:
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_rum
JMP drink_invalid
JMP drink_orange
JMP drink_invalid
JMP drink_jagermeister
JMP drink_gin
JMP drink_invalid
JMP drink_baileys
JMP drink_coca_cola
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_invalid
JMP drink_grenadine
JMP drink_tequila
JMP drink_invalid
JMP drink_valis
JMP drink_invalid
JMP drink_invalid
JMP drink_milk
JMP drink_invalid
JMP drink_redbull
JMP drink_invalid
JMP drink_tonic
JMP drink_invalid
drink_invalid:
LPTR "INVALID CHOICE.\r\n\r\n"
CALL print_str
RET
drink_rum:
ADD 0, [inv+rum]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF RUM.\r\n"
CALL print_str
SUB [inv+rum], 1
JMP drink_alcohol
drink_tequila:
ADD 0, [inv+tequila]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF TEQUILA.\r\n"
CALL print_str
SUB [inv+tequila], 1
JMP drink_alcohol
drink_gin:
ADD 0, [inv+gin]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF GIN.\r\n"
CALL print_str
SUB [inv+gin], 1
JMP drink_alcohol
drink_jagermeister:
ADD 0, [inv+jagermeister]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF JAEGERMEISTER.\r\n"
CALL print_str
SUB [inv+jagermeister], 1
JMP drink_alcohol
drink_baileys:
ADD 0, [inv+baileys]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF BAILEYS.\r\n"
CALL print_str
SUB [inv+baileys], 1
JMP drink_alcohol
drink_alcohol:
ADD 0, [drunk]
BNZ drink_more
LPTR "YOU GET DRUNK.\r\n\r\n"
CALL print_str
B drink_end
drink_more:
LPTR "YOU GET EVEN MORE DRUNK.\r\n\r\n"
CALL print_str
drink_end:
ADD [drunk], 1
RET
drink_orange:
ADD 0, [inv+orange]
BZ drink_invalid
LPTR "YOU DRINK A CARTON OF ORANGE JUICE.\r\n\r\n"
CALL print_str
SUB [inv+orange], 1
RET
drink_milk:
ADD 0, [inv+milk]
BZ drink_invalid
LPTR "YOU DRINK A CARTON OF MILK.\r\n\r\n"
CALL print_str
SUB [inv+milk], 1
RET
drink_tonic:
ADD 0, [inv+tonic]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF TONIC.\r\n\r\n"
CALL print_str
SUB [inv+tonic], 1
RET
drink_coca_cola:
ADD 0, [inv+coca_cola]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF COCA-COLA.\r\n\r\n"
CALL print_str
SUB [inv+coca_cola], 1
RET
drink_grenadine:
ADD 0, [inv+grenadine]
BZ drink_invalid
LPTR "YOU DRINK A BOTTLE OF GRENADINE SYRUP. EW.\r\n\r\n"
CALL print_str
SUB [inv+grenadine], 1
RET
drink_valis:
ADD 0, [inv+valis]
BZ drink_invalid
LPTR "YOU DRINK EVERYTHING FOUND INSIDE WALIZKA VALISA. YOU DIE OF ALCOHOL POISONING...\r\n"
CALL print_str
LOSE
drink_redbull:
ADD 0, [inv+redbull]
BZ drink_invalid
LPTR "YOU DRINK A CAN OF REDBULL. YOU FEEL MUCH BETTER.\r\n\r\n"
CALL print_str
SUB [inv+redbull], 1
ADD [hp], LO 100
ADC [hp+1], MID 100
RET
fight_nothing:
LPTR "\r\n\r\nTHERE IS NOTHING HERE TO FIGHT.\r\n\r\n"
CALL print_str
RET
main_cmd_fight:
ADD 0, [cache_cur]
BZ fight_nothing
LPTR "\r\n\r\nYOU ATTACK "
CALL print_str
CALL print_the_monster
SUB pigwowka, [cache_cur]
BZ fight_pigwowka
LPTR ".\r\n\r\n"
CALL print_str
MOV [monster_hp], LO 100
MOV [monster_hp+1], MID 100
fight_loop:
LPTR "SELECT AN OPTION:\r\n\r\n"
LPTR "- (A)TTACK\r\n"
CALL print_str
LPTR "- USE (S)HIELD\r\n"
CALL print_str
LPTR "- (C)HEAT\r\n"
CALL print_str
LPTR "\r\nYOUR CHOICE: "
CALL print_str
GETC R0
PUTC R0
SUB 1, R0
BZ fight_attack
SUB 0x0d, R0
BZ fight_cheat
SUB 0x14, R0
BZ fight_shield
LPTR "\r\n\r\nINVALID OPTION.\r\n\r\n"
CALL print_str
B fight_loop
fight_pigwowka:
LPTR ". HE SEEMS TO BE TOO DRUNK TO EVEN NOTICE.\r\n"
CALL print_str
B fight_item
fight_cheat:
MOV [hp], LO 1000
MOV [hp+1], MID 1000
MOV [cheater], 1
LPTR "\r\n\r\nCURRENT HEALTH: 1000%.\r\n\r\n"
CALL print_str
B fight_loop
fight_attack:
CALL rnd
SUB 0x10, R0
BA fight_you_hit
LPTR "\r\n\r\nYOU ATTACK "
CALL print_str
CALL print_the_monster
LPTR ", BUT MISS.\r\n"
CALL print_str
B fight_monster_attack
fight_you_hit:
ADD R0, 1
SUB [monster_hp], R0
SBB [monster_hp+1], 0
BC fight_you_kill
MOV R0, [monster_hp]
OR R0, [monster_hp+1]
BZ fight_you_kill
LPTR "\r\n\r\nYOU HIT "
CALL print_str
CALL print_the_monster
LPTR ".\r\n"
CALL print_str
LPTR "ENEMY HEALTH: "
CALL print_str
MOV R0, [monster_hp]
MOV R1, [monster_hp+1]
CALL print_num
LPTR "%\r\n"
CALL print_str
fight_monster_attack:
CALL rnd
SUB 0x10, R0
BA fight_monster_hit
CALL print_the_monster
LPTR " ATTACKS YOU, BUT MISSES.\r\n\r\n"
CALL print_str
B fight_loop
fight_monster_hit:
ADD R0, 1
SUB [hp], R0
SBB [hp+1], 0
BC fight_you_die
MOV R0, [hp]
OR R0, [hp+1]
BZ fight_you_die
CALL print_the_monster
LPTR " HITS YOU.\r\n"
CALL print_str
CALL print_health
LPTR "\r\n"
CALL print_str
B fight_loop
fight_you_die:
CALL print_the_monster
LPTR " HITS YOU. YOU DIE...\r\n"
CALL print_str
LOSE
fight_shield:
LPTR "\r\n\r\n"
CALL print_str
CALL print_the_monster
CALL rnd
SUB 0x10, R0
BA fight_shield_hit
LPTR " ATTACKS YOU, BUT MISSES.\r\n\r\n"
CALL print_str
B fight_loop
fight_shield_hit:
LPTR " ATTACKS YOU, BUT BOUNCES OFF YOUR SHIELD.\r\n\r\n"
CALL print_str
B fight_loop
fight_you_kill:
LPTR "\r\n\r\nYOU KILL "
CALL print_str
CALL print_the_monster
LPTR ".\r\n"
CALL print_str
SUB valis, [cache_cur]
BNZ fight_no_valis
LPTR "YOU IDIOT. NOW NOBODY KNOWS THE FLAG.\r\n"
CALL print_str
fight_no_valis:
SUB redford, [cache_cur]
BNZ fight_item
SUB 2, [redford_state]
BNZ fight_item
CALL print_nl
B fight_end
fight_item:
MOV R0, LO inv
MOV R1, MID inv
ADD R0, [cache_cur]
ADC R1, 0
ADD DATA, 1
LPTR "YOU ACQUIRE AN ITEM: "
CALL print_str
LPTR stab_item
MOV R3, [cache_cur]
CALL print_from_tab
LPTR ".\r\n\r\n"
CALL print_str
fight_end:
MOV R0, [pos]
MOV R1, [pos+1]
ADD R0, LO board
ADC R1, MID board
MOV DATA, 0
RET
main_cmd_talk:
SUB valis, [cache_cur]
BZ talk_valis
SUB redford, [cache_cur]
BZ talk_redford
LPTR "\r\n\r\nYOU TALK TO YOURSELF. YOU'RE NOT VERY INTERESTING.\r\n\r\n"
CALL print_str
RET
talk_redford:
LPTR "\r\n\r\nYOU APPROACH REDFORD.\r\n\r\n"
CALL print_str
MOV R0, [redford_state]
SHL R0, R0
RCL R1, 0
SHL R0, R0
RCL R1, R1
MOV R2, 0
ADD R0, LO jtab_talk_redford
ADC R1, MID jtab_talk_redford
ADC R2, HI jtab_talk_redford
PUSH R2
PUSH R1
PUSH R0
RET
talk_valis:
LPTR "\r\n\r\nYOU ENTER THE TAVERN AND APPROACH VALIS.\r\n\r\n"
CALL print_str
MOV R0, [valis_state]
SHL R0, R0
RCL R1, 0
SHL R0, R0
RCL R1, R1
MOV R2, 0
ADD R0, LO jtab_talk_valis
ADC R1, MID jtab_talk_valis
ADC R2, HI jtab_talk_valis
PUSH R2
PUSH R1
PUSH R0
RET
jtab_talk_valis:
JMP valis_redbull
JMP valis_powerstrip
JMP valis_redbull
JMP valis_redbull
JMP valis_gin_tonic
JMP valis_redbull
JMP valis_jagermeister
JMP valis_redbull
JMP valis_redbull
JMP valis_tequila_sunrise
JMP valis_redbull
JMP valis_cuba_libre
JMP valis_redbull
JMP valis_win
valis_redbull:
LPTR "- HEY, I WAS WONDERING IF YOU COULD HELP ME FIND THE FLAG?\r\n"
CALL print_str
LPTR "- THE FLAG? MAYBE, BUT FIRST, I NEED A REDBULL.\r\n"
CALL print_str
ADD 0, [inv+redbull]
BZ valis_no_redbull
SUB [inv+redbull], 1
ADD [valis_state], 1
LPTR "\r\nYOU GIVE VALIS A REDBULL. VALIS DRINKS IT IN ONE GO.\r\n\r\n"
CALL print_str
RET
valis_no_redbull:
LPTR "- I... I DON'T HAVE A REDBULL.\r\n"
CALL print_str
LPTR "- WELL THEN, MAKE YOURSELF USEFUL AND FIND ONE.\r\n"
CALL print_str
CALL print_nl
RET
valis_powerstrip:
ADD 0, [inv+redford]
BZ valis_no_powerstrip
LPTR "YOU GIVE VALIS A POWER STRIP. VALIS CONNECTS HIS LAPTOP.\r\n"
CALL print_str
CALL print_nl
SUB [inv+redford], 1
ADD [valis_state], 1
RET
valis_no_powerstrip:
LPTR "- SO, CAN I GET THE FLAG NOW?\r\n"
CALL print_str
LPTR "- FLAG? I CANNOT GIVE YOU ANY FLAGS WITHOUT POWER FOR MY LAPTOP. GO FIND REDFORD AND GET A POWER STRIP FROM HIM.\r\n"
CALL print_str
CALL print_nl
MOV [redford_state], 1
RET
valis_gin_tonic:
LPTR "- HEY, I WAS WONDERING IF YOU COULD HELP ME FIND THE FLAG?\r\n"
CALL print_str
LPTR "- THE FLAG? MAYBE, BUT FIRST, I NEED A GIN AND TONIC.\r\n"
CALL print_str
ADD 0, [inv+gin]
BZ valis_no_gin_tonic
ADD 0, [inv+tonic]
BZ valis_no_gin_tonic
SUB [inv+gin], 1
SUB [inv+tonic], 1
ADD [valis_state], 1
LPTR "\r\nYOU GIVE VALIS A GIN AND TONIC. VALIS DRINKS IT IN ONE GO.\r\n\r\n"
CALL print_str
RET
valis_no_gin_tonic:
LPTR "- I... I DON'T HAVE THE INGREDIENTS FOR GIN AND TONIC.\r\n"
CALL print_str
LPTR "- WELL THEN, MAKE YOURSELF USEFUL AND FIND THEM.\r\n"
CALL print_str
CALL print_nl
RET
valis_tequila_sunrise:
LPTR "- HEY, I WAS WONDERING IF YOU COULD HELP ME FIND THE FLAG?\r\n"
CALL print_str
LPTR "- THE FLAG? MAYBE, BUT FIRST, I NEED A TEQUILA SUNRISE.\r\n"
CALL print_str
ADD 0, [inv+tequila]
BZ valis_no_tequila_sunrise
ADD 0, [inv+orange]
BZ valis_no_tequila_sunrise
ADD 0, [inv+grenadine]
BZ valis_no_tequila_sunrise
SUB [inv+tequila], 1
SUB [inv+orange], 1
SUB [inv+grenadine], 1
ADD [valis_state], 1
LPTR "\r\nYOU GIVE VALIS A TEQUILA SUNRISE. VALIS DRINKS IT IN ONE GO.\r\n\r\n"
CALL print_str
RET
valis_no_tequila_sunrise:
LPTR "- I... I DON'T HAVE THE INGREDIENTS FOR TEQUILA SUNRISE.\r\n"
CALL print_str
LPTR "- WELL THEN, MAKE YOURSELF USEFUL AND FIND THEM.\r\n"
CALL print_str
CALL print_nl
RET
valis_jagermeister:
LPTR "- HEY, I WAS WONDERING IF YOU COULD HELP ME FIND THE FLAG?\r\n"
CALL print_str
LPTR "- THE FLAG? MAYBE, BUT FIRST, I NEED A JAEGERMEISTER WITH REDBULL.\r\n"
CALL print_str
ADD 0, [inv+jagermeister]
BZ valis_no_jagermeister
ADD 0, [inv+redbull]
BZ valis_no_jagermeister
SUB [inv+jagermeister], 1
SUB [inv+redbull], 1
ADD [valis_state], 1
LPTR "\r\nYOU GIVE VALIS A JAEGERMEISTER WITH REDBULL. VALIS DRINKS IT IN ONE GO.\r\n\r\n"
CALL print_str
RET
valis_no_jagermeister:
LPTR "- I... I DON'T HAVE THE INGREDIENTS FOR JAEGERMEISTER WITH REDBULL.\r\n"
CALL print_str
LPTR "- WELL THEN, MAKE YOURSELF USEFUL AND FIND THEM.\r\n"
CALL print_str
CALL print_nl
RET
valis_cuba_libre:
LPTR "- HEY, I WAS WONDERING IF YOU COULD HELP ME FIND THE FLAG?\r\n"
CALL print_str
LPTR "- THE FLAG? MAYBE, BUT FIRST, I NEED A CUBA LIBRE.\r\n"
CALL print_str
ADD 0, [inv+rum]
BZ valis_no_cuba_libre
ADD 0, [inv+coca_cola]
BZ valis_no_cuba_libre
SUB [inv+rum], 1
SUB [inv+coca_cola], 1
ADD [valis_state], 1
LPTR "\r\nYOU GIVE VALIS A CUBA LIBRE. VALIS DRINKS IT IN ONE GO.\r\n\r\n"
CALL print_str
RET
valis_no_cuba_libre:
LPTR "- I... I DON'T HAVE THE INGREDIENTS FOR CUBA LIBRE.\r\n"
CALL print_str
LPTR "- WELL THEN, MAKE YOURSELF USEFUL AND FIND THEM.\r\n"
CALL print_str
CALL print_nl
RET
valis_win:
LPTR "- FLA... THE FLAG... I'VE DONE EVERYTHING... PLEASE...\r\n"
CALL print_str
ADD 0, [cheater]
BNZ valis_cheater
CALL print_str
LPTR "- EH. FINE. HERE IT IS: "
CALL print_str
WIN
CALL print_nl
CALL print_nl
RET
valis_cheater:
LPTR "- YES. BUT YOU CHEATED. YOU WILL NEVER GET THE FLAG NOW.\r\n\r\n"
CALL print_str
RET
jtab_talk_redford:
JMP redford_hi
JMP redford_powerstrip
JMP redford_hi
redford_hi:
LPTR "- HI. HOW'S IT GOING?\r\n\r\n"
CALL print_str
LPTR "REDFORD RANTS ABOUT UNTESTED CTF TASKS.\r\n"
CALL print_str
CALL print_nl
RET
redford_powerstrip:
LPTR "- HI. DO YOU HAVE A POWERSTRIP?\r\n"
CALL print_str
LPTR "- SURE.\r\n"
CALL print_str
LPTR "- OK, CAN I GET IT? VALIS REALLY NEEDS IT.\r\n"
CALL print_str
LPTR "- ONLY IF I GET SOMETHING IN RETURN. BAILEYS WITH MILK WOULD BE GOOD.\r\n"
CALL print_str
ADD 0, [inv+baileys]
BZ redford_no_baileys
ADD 0, [inv+milk]
BZ redford_no_baileys
CALL print_nl
LPTR "YOU MIX REDFORD A BAILEYS WITH MILK. REDFORD HAPPILY GIVES YOU HIS POWER STRIP.\r\n"
CALL print_str
SUB [inv+baileys], 1
SUB [inv+milk], 1
ADD [inv+redford], 1
MOV [redford_state], 2
redford_no_baileys:
CALL print_nl
RET
rnd:
MOV R0, [lfsr]
CALL lfsr_rot
CALL lfsr_rot
CALL lfsr_rot
CALL lfsr_rot
CALL lfsr_rot
RET
lfsr_rot:
MOV R1, [lfsr]
MOV R2, [lfsr+1]
MOV R3, [lfsr+2]
AND R1, 0x11
AND R2, 0xc
AND R3, 0x1d
XOR R1, R2
XOR R1, R3
SHR R2, R1
XOR R1, R2
SHR R2, R2
XOR R1, R2
SHR R2, R2
XOR R1, R2
SHR R2, R2
XOR R1, R2
SHR R1, R1
RCR [lfsr+2], [lfsr+2]
RCR [lfsr+1], [lfsr+1]
RCR [lfsr+0], [lfsr+0]
RET
init:
MOV [pos], 0
MOV [cheater], 0
MOV [valis_state], 0
MOV [redford_state], 0
MOV [hp], LO 100
MOV [hp+1], MID 100
MOV [drunk], 0
init_rnd:
RND [lfsr]
RND [lfsr+1]
RND [lfsr+2]
MOV R0, [lfsr]
OR R0, [lfsr+1]
OR R0, [lfsr+2]
BZ init_rnd
MOV R0, LO inv
MOV R1, MID inv
MOV R2, invsz
init_inv_loop:
MOV DATA, 0
ADD R0, 1
ADC R1, 0
SUB R2, 1
BNZ init_inv_loop
MOV R0, LO board
MOV R1, MID board
MOV R2, 0
MOV R3, 2