-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadventureland.a18
2648 lines (2576 loc) · 94.4 KB
/
adventureland.a18
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
;
; Copyright (C) 1980 by Scott Adams, All Rights Reserved.
; Copyright (C) 1993 by Morten Løhre, All Rights Reserved.
; Copyright (C) 2019 by Richard Goedeken, All Rights Reselved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
incl "bios.inc"
incl "kernel.inc"
;
bs equ 8
cr equ 13
lf equ 10
esc equ 27
del equ 7fh
;
#if not O_CREAT
O_CREAT equ 00000001b
#endif
#if not O_TRUNC
O_TRUNC equ 00000010b
#endif
;
; ************************************************************
; This block generates the Execution header for a stand-alone
; program. It begins 6 bytes before the program start.
; ************************************************************
;
org 02000h-6 ; Header starts at 01ffah
dw 2000h
dw endrom-2000h
dw 2000h
;
br GameStart
; **************************************************
; Build date format:
; 80h+month, day, four digit year
; **************************************************
; 80h month offset indicates extended
; build information, with build number and text.
; **************************************************
;
;
date
build: dw 5 ; build number
db '@Copyleft 2021 Wayne Hortensius',0
;__________________________________________________________________________________________________
; Print a 2-digit number
; IN: D = number to print, RF = pointer to start of string
; OUT: N/A
; TRASHED: D, R7
Print2Digit
phi R7 ; save number to print
ldi 0
plo R7
ghi R7
P2D_Tens
smi 10
bl P2D_TensDone
inc R7
br P2D_Tens
P2D_TensDone
adi 10 ; D is now number of singles
phi R7
glo R7
LSNZ ; if there are no tens,
ldi ' '-'0' ; use space as filler char.
adi '0'
str RF ; store the tens digit
inc RF
ldi '0'
plo R7
ghi R7
P2D_Ones
smi 1
bl P2D_OnesDone
inc R7
br P2D_Ones
P2D_OnesDone
glo R7
str RF
dec RF
retn
;__________________________________________________________________________________________________
; Clear screen
; IN: N/A
; OUT: N/A
; TRASHED: RF
ClearScreen
load rf,ClsMsg
call O_MSG
retn
;__________________________________________________________________________________________________
; Generate a psuedo-random byte
; IN: N/A
; OUT: D=psuedo-random number
; TRASHED: R7
GenRandom
load r7,Rand_VarX
sex R7
ldn R7 ; D = VarX
adi 1
str R7
inc R7
lda R7 ; D = VarA
inc R7
XOR ; D = VarA XOR VarC
dec R7
dec R7
dec R7
XOR ; D = VarA XOR VarC XOR VarX
inc R7
str R7 ; VarA = D
inc R7
ADD
stxd
SHR
XOR
inc R7
inc R7
ADD
str R7
;;; sex r2
retn
;__________________________________________________________________________________________________
; Restore internal variables to starting state
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, R9
GameReset
load r8,Array_I2 ; start by initializing item locations
load r9,Array_IA
ldi IL
plo R7
GRLoop1
lda R8
str R9
inc R9
dec R7
glo R7
bnz GRLoop1
inc R9
inc R9
ldi 0
str R9 ; Loadflag = 0
inc R9
str R9 ; Endflag = 0
inc R9
str R9 ; Darkflag = 0
ldi AR
inc R9
str R9 ; Room = AR
ldi LI
inc R9
str R9 ; lamp_oil = LT
ldi 0
inc R9
str R9
inc R9
str R9 ; state_flags = 0
retn
;__________________________________________________________________________________________________
; Main program starting point
Exit
load rf,saveStack ; restore Elf/OS's stack
lda rf
phi r2
ldn rf
plo r2
retn ; return to Elf/OS
GameStart
load rf,saveStack ; save Elf/OS's stack
ghi r2
str rf
inc rf
glo r2
str rf
load r2,localStack ; use our own stack
load rf,splash
call O_MSG
call O_READKEY ; wait for key press
call ClearScreen
; beginning of main() function
; Print welcome message
load rf,StartingMsg
call O_MSG
; start of main loop
MainLoad
; reset all game state
call GameReset
; load game if possible
call Do_LoadGame
; clear screen
call ClearScreen
; look()
call Do_Look
; NV[0] = 0
load r9,Array_NV
ldi 0
str R9
; turn()
call Do_Turn
MainGetInput
; get_input()
call Do_GetInput
; if command parsing failed, try again
bnz MainGetInput
; turn()
call Do_Turn
; reload R9 to point to Endflag
load r9,Endflag
ldn R9
lbnz Exit ; quit if endflag != 0
dec R9
ldn R9
lbnz MainLoad ; loop back and re-load if loadflag != 0
; deal with lamp oil
load ra,Array_IA+9
ldn RA
smi 0FFH
lbnz MainNoLamp
load r9,LampOil
ldn R9
smi 1
str R9 ; lamp_oil--
lbdf LampNotEmpty
load rf,LampEmptyMsg ; print Lamp is Empty message
call O_MSG
ldi 0
str RA ; IA[9] = 0
br MainNoLamp
LampNotEmpty
smi 25 ; is our oil level < 25?
bdf MainNoLamp
load rf,LampLow1Msg ; print Lamp is low message
call O_MSG
load rf,PrintNumber
ldn R9 ; D = lamp_oil
call Print2Digit
load rf,PrintNumber
call O_MSG
load rf,LampLow2Msg
call O_MSG
MainNoLamp
; NV[0] = 0
load r9,Array_NV
ldi 0
str R9
; turn()
call Do_Turn
MainLoopTail
; reload R9 to point to Endflag
load r9,Endflag
ldn R9
lbnz Exit ; if endflag != 0, quit
dec R9
ldn R9
lbnz MainLoad ; if loadflag != 0, loop back and re-load
lbr MainGetInput ; otherwise, get next command
;__________________________________________________________________________________________________
; Adventure get_action_variable() function
; IN: RD=pAcVar
; OUT: D=value
; TRASHED: N/A
Sub_GetActionVariable
inc RD ; ###
inc RD
GAV_Loop1
inc RD
ldn RD
bz GAV_FoundVar
inc RD
br GAV_Loop1
GAV_FoundVar
dec RD
ldn RD
retn
;__________________________________________________________________________________________________
; Adventure get_input() function
; IN: N/A
; OUT: D = return value (1 if failed, 0 if command OK)
; TRASHED: R7, R8, R9, RA, RB, RC, RD, RF
Do_GetInput
; print input prompt
load rf,InputPromptMsg
call O_MSG
; now we are in the gets() function. set up loop variables
ldi 0
plo RA ; RA.0 is character counter; only 79 are allowed
load r9,Array_TPS ; R9 is pointer to input line
GILoop1
; wait for key press
ghi re
ani 0feh
phi re
call O_READKEY
phi rf
ghi re
ori 001h
phi re
; handle backspace
ghi RF
smi 8
bz GIBackspace
ghi RF
smi 07FH
bnz GILoop1N1
GIBackspace
glo RA ; if line length is 0
bz GILoop1 ; then just go back for another input character
ldi bs ; otherwise, erase last character
call O_TYPE
ldi ' ' ; ' '
call O_TYPE
ldi bs ; '\b'
call O_TYPE
dec RA ; decrement character count
dec R9 ; decrement input line pointer
br GILoop1 ; and then go back for another input character
GILoop1N1
; handle enter or return
ghi RF
smi lf
LBZ GIEnter
ghi RF
smi cr
bnz GILoop1N2
GIEnter
ldi cr
call O_TYPE
ldi lf
call O_TYPE
br GIgetsDone
GILoop1N2
; ensure that input character is valid
ghi RF
smi ' '
bz GICharOk
ghi RF
smi 'A'
bl GIJumpLoop1
ghi RF
smi 'Z'+1
bl GICharOk
ghi RF
smi 'a'
bl GIJumpLoop1
ghi RF
smi 'z'+1
bl GICharOk
GIJumpLoop1
LBR GILoop1
GICharOk
ghi RF
str R9 ; add input character to our string
inc R9
inc RA ; increment string length counter
call O_TYPE ; echo character to serial output
glo RA ; how long is the input line?
smi 79
bl GIJumpLoop1 ; if < 79 characters, go get another
GIgetsDone
ldi 0 ; null-terminate input string
str R9
load r9,Array_TPS
; now we are back in the get_input() function.
; If the line is empty, go prompt for another command
ldn R9
LBZ Do_GetInput
; otherwise, start parsing. begin by skipping any leading spaces
GIParseLoop1
lda R9
bz GIParseLoop1Done
smi ' '
bz GIParseLoop1
GIParseLoop1Done
dec R9
; store pointer to first word in RA
glo R9
plo RA
ghi R9
phi RA
; convert entire string to uppercase
GIParseLoop2
lda R9
lbz GIParseLoop2Done
smi 'a'
lbnf GIParseLoop2 ; BL
adi 'A'
dec R9
str R9
inc R9
lbr GIParseLoop2
GIParseLoop2Done
; reload pointer to start of first word, and find the end (the next space)
glo RA
plo R9
ghi RA
phi R9
GIParseLoop3
lda R9
bz GIParseLoop3Done
smi ' '
bnz GIParseLoop3
GIParseLoop3Done
; if we found a space, NULL-terminate the first word
dec R9
ldn R9
lbz GIParseLoop4
ldi 0
str R9
inc R9
; skip any additional spaces in between words
GIParseLoop4
lda R9
smi ' '
lbz GIParseLoop4
dec R9
; store pointer to second word in RB
glo R9
plo RB
ghi R9
phi RB
; find matches for both words
load rc,Array_NV ; RC = pointer to NV[2]
load rd,Array_NVS ; RD = pointer to NVS[2][NL][4], NL=60
ldi 0
phi RF ; RF.1 = i, for (i = 0; i < 2; i++)
glo RA ; load pointer to first word in R9
plo R9
ghi RA
phi R9
GIParseLoop5
ldi 0
str RC ; NV[i] = 0
ldn R9
bz GIParseLoop5Tail
ldi 0
plo RF ; RF.0 = j, for (j = 0; j < NL; j++)
GIParseLoop5_1
glo RD
plo R8
ghi RD
phi R8 ; R8 = s = NVS[i][j]
ldn R8
smi '*' ; if first character of word is '*'
bnz GIParseLoop5_1Next1
inc R8 ; then skip it
GIParseLoop5_1Next1
; comparestring()
sex r8
lda R9 ; Load 1st character in input word
bz GIParseLoop5_1WordEnd
SM ; compare to 1st character in table word
bnz GIParseLoop5_1NoMatch
inc R8
lda R9 ; Load 2nd character in input word
bz GIParseLoop5_1WordEnd
SM ; compare to 2nd character in table word
bnz GIParseLoop5_1NoMatch
inc R8
lda R9 ; Load 3rd character in input word
bz GIParseLoop5_1WordEnd
SM
bnz GIParseLoop5_1NoMatch
SKP ; fall through to GIParseLoop5_1Match
GIParseLoop5_1WordEnd
ldn R8
bnz GIParseLoop5_1NoMatch
GIParseLoop5_1Match
glo RF
str RC ; NV[i] = j
glo RD
plo R8
ghi RD
phi R8 ; R8 = NVS[i][j]
GIParseLoop5_1_1 ; while (NVS[i][NV[i]][0] == '*') NV[i]--;
ldn R8
smi '*'
bnz GIParseLoop5Tail
ldn RC
smi 1
str RC ; NV[i]--
dec R8
dec R8
dec R8
dec R8
br GIParseLoop5_1_1
GIParseLoop5_1NoMatch
sex R2
inc RD
inc RD
inc RD
inc RD ; move word table pointer to next word
ghi RF ; test i variable
bnz GIParseLoop5_1Next2
glo RA ; reload pointer to first word in R9
plo R9
ghi RA
phi R9
br GIParseLoop5_1Next3
GIParseLoop5_1Next2
glo RB ; reload pointer to second word in R9
plo R9
ghi RB
phi R9
GIParseLoop5_1Next3
inc RF
glo RF
smi NL ; NL = 60
BNF GIParseLoop5_1 ; go check the next word in the table
GIParseLoop5Tail
inc RC ; point to next element in NV array
glo RB ; load pointer to second word in R9
plo R9
ghi RB
phi R9
load rd,Array_NVS+(NL*4) ; RD = pointer to second half of NVS[2][NL][4], NL=60
ghi RF
adi 1 ; i++
phi RF
smi 2
BNF GIParseLoop5 ; branch if less
; validate first word (verb)
dec RC
dec RC
lda RC
lbnz GIParseVerbOk
load rf,InputError1Msg
call O_MSG ; print "I don't know how to "
glo RA
plo RF
ghi RA
phi RF
call O_MSG ; print first word
load rf,InputError2Msg
call O_MSG ; print '!\r\n'
ldi 1
retn ; return 1
GIParseVerbOk
; validate second word (noun)
ldn RB ; D is word[0][0]
lbz GIParseAllGood
ldn RC ; D is NV[1]
lbnz GIParseAllGood
load rf,InputError3Msg
call O_MSG ; print "I don't know what a "
glo RB
plo RF
ghi RB
phi RF
call O_MSG ; print second word
load rf,InputError4Msg
call O_MSG ; print " is!\n"
ldi 1
retn ; return 1
GIParseAllGood
ldi 0
retn ; return 0
;__________________________________________________________________________________________________
; LoadGame function to restore game state from disk file
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, RC, RD, RF
Do_LoadGame
load rf,LoadQestion
call O_MSG ; print "Load saved game (Y or N)?"
call Do_YesNo ; D = 0 if No, 1 if Yes
lbnz LGNext1
retn ; return
LGNext1
load rf,SavePath
load rd,SaveFiledes ; savefile descriptor
ldi 0 ; (nocreate, no truncate, no append) flags
plo r7
call O_OPEN ; attempt to open file
lbnf LoadOpened ; DF=0, file was opened
LoadFailed:
load rf,LoadFailedMsg
call O_MSG
call O_READKEY ; wait for key press
retn
;
LoadOpened:
load rc,SaveLength
load rf,SaveStart
load rd,SaveFiledes
call O_READ ; read the save file
lbnf CloseLoadFile ; DF=0, read OK
call LoadFailed ; erad failed
CloseLoadFile:
load rf,SaveFiledes
call O_CLOSE ; close the image file
retn
;__________________________________________________________________________________________________
; Adventure look() function
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, R9, RA, RB, RC, RF
Do_Look
load r9,Darkflag
lda R9 ; D == is_dark
bz LKNotDark
sex R9 ; R9 is pointing to 'room'
load ra,Array_IA+9
ldn RA
SHL
BDF LKNotDark
SHR
SM
bz LKNotDark
; it's dark. print a message and return
load rf,Look1Msg
call O_MSG
retn
LKNotDark
ldn R9
SHL ; D = room * 2
adi LOW Table_RSS
plo RA
ldi HIGH Table_RSS
ADCI 0
phi RA
lda RA
phi RB
lda RA
plo RB ; RB = RSS[room]
lda RB
smi '*'
bz LKPrintRoom1
dec RB
load rf,Look2Msg ; print "I'm in a " prefix
call O_MSG
LKPrintRoom1
glo RB
plo Rf
ghi RB
phi Rf
call O_MSG ; print the room description
ldi 0
plo RB ; RB.0 is item counter 'i' for loop
phi RB ; RB.1 is flag which specifies whether item list prefix has been printed
load ra,Array_IA ; RA is pointer to start of IA[]
LKLoop1
sex R9 ; R9 is pointing to 'room'
lda RA
SM
lbnz LKLoop1Tail
; we have found an item in this room. start by printing the item list header if necessary
ghi RB
bnz LKLoop1Next1
ldi 1
phi RB
load rf,Look3Msg
call O_MSG ; print: "Visible Items Here:"
LKLoop1Next1
; print item description
glo RB ; D = item number (i)
SHL
adi LOW Table_IAS
plo R8
ldi HIGH Table_IAS
adci 0
phi R8
lda R8
phi RC
lda R8
plo RC ; RC = pointer to item description
ldi ' '
call O_TYPE
ldi ' '
call O_TYPE
ldi ' '
call O_TYPE
LKLoop1_1
ldn RC
bz LKLoop1_1Tail
smi '/'
bz LKLoop1_1Tail
lda RC
call O_TYPE
br LKLoop1_1
LKLoop1_1Tail
ldi cr
call O_TYPE
ldi lf
call O_TYPE
LKLoop1Tail
inc RB
glo RB
smi IL
LBNF LKLoop1
; now print room exits
sex R9
ldn R9 ; D = room
ADD
ADD
SHL ; D = room * 6
adi LOW Array_RM
plo R9
ldi HIGH Array_RM
adci 0
phi R9 ; R9 is pointer to RM[room][0]
ldi 0
plo RB ; RB.0 is direction counter 'i' for loop
phi RB ; RB.1 is flag which specifies whether exit list header has been printed
LKLoop2
lda R9
LBZ LKLoop2Tail
; we have found an exit from this room. start by printing the exit list header if necessary
ghi RB
lbnz LKLoop2Next1
ldi 1
phi RB
load rf,Look4Msg
call O_MSG
LKLoop2Next1
glo RB
SHL
SHL
SHL
adi LOW Array_DIR
plo RF
ldi HIGH Array_DIR
adci 0
phi RF
call O_MSG ; print direction
ldi ' '
call O_TYPE
LKLoop2Tail
inc RB
glo RB
smi 6
lbnf LKLoop2 ; BL
ldi cr
call O_TYPE
ldi lf
call O_TYPE
ldi lf
call O_TYPE
retn
;__________________________________________________________________________________________________
; Adventure turn() function
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, R9, RA, RB, RF
Do_Turn
ldi 0
plo R9 ; R9.0 = i ((is_dark) && (IA[9] != room) && (IA[9] != -1))
phi R9 ; R9.1 = go_direction
load r7,Array_NV
lda R7 ; D = NV[0]
smi 1
bnz TUNoGo
ldn R7
bnz TUHaveNoun
load rf,Turn1Msg
call O_MSG ; print "Where do you want me to go? Give me a direction too.\n"
retn ; return
TUHaveNoun
smi 007H
LBDF TUNoDirection ; BGE
ldn R7
phi R9 ; go_direction = NV[1]
br TUHaveDirection
TUNoGo
dec R7
ldn R7 ; D = NV[0]
smi 54
LBNF TUNoDirection ; BL
smi 6
LBDF TUNoDirection ; BGE
adi 7
phi R9 ; go_direction = NV[0] - 53
TUHaveDirection
load ra,Darkflag
lda RA ; D == is_dark
sex RA ; RA is pointing to 'room'
bz TUNotDark
load rb,Array_IA+9 ; RB is pointer to IA[9]
ldn RB
SHL
BDF TUNotDark
SHR
SM
bz TUNotDark
; it's dark. print a message
inc R9 ; i = 1
load rf,Turn2Msg
call O_MSG ; print: "Warning: it's dangerous to move in the dark!\n"
sex RA
TUNotDark
ghi R9
str R2 ; put go_direction on top of stack
LDX ; D = room
ADD
ADD
SHL ; D = room * 6
sex R2
ADD ; D = room * 6 + go_direction
adi LOW (Array_RM-1)
plo RB
ldi HIGH (Array_RM-1)
adci 0
phi RB ; RB is pointer to RM[room][go_direction-1]
ldn RB
phi R9 ; R9.1 = j
lbnz TUExitNotBlocked
glo R9
bnz TUBlockedAndDark
load rf,Turn3Msg
call O_MSG ; print: "I can't go in that direction.\n"
retn ; return
TUBlockedAndDark
load rf,Turn4Msg
call O_MSG ; print: "I fell down and broke my neck.\n"
ldi RL-1
phi R9 ; j = RL-1
dec RA
ldi 0
str RA ; is_dark = false
inc RA
br TUSetRoom
TUExitNotBlocked
call ClearScreen
TUSetRoom
ghi R9
str RA ; room = j
call Do_Look ; look()
retn ; return
TUNoDirection
ldi 0
phi R9 ; R9.1 = command_found = false
plo R9
inc R9 ; R9.0 = command_allowed = true
load ra,Array_C ; RA = C[cmd]
TULoop1
load r7,Array_NV
ldn RA
plo R8 ; R8.0 = i = C[cmd][0]
bz TULoop1Next1
ldn R7
lbz TULoop1Done ; if (NV[0] == 0 && i != 0) break;
glo R8
TULoop1Next1
sex R7
SM
lbnz TULoop1Tail
inc RA
ldn RA
dec RA
plo R8 ; R8.0 = i = C[cmd][1]
lbz TULoop1CheckCommand
inc R7
SM ; D = i - NV[1]
dec R7
lbz TULoop1CheckCommand
ldn R7 ; D = NV[0]
lbnz TULoop1Tail
TULoop1GetChances ; get random number between 1 and 100
call GenRandom ; R7 is trashed
SHR
smi 100
lbdf TULoop1GetChances ;;E BGE
adi 101
str R2
glo R8 ; D = i
SM
lbnf TULoop1Tail ; BL
TULoop1CheckCommand
ldi 1
phi R9 ; R9.1 = command_found = true
call Do_CheckLogics
plo R9 ; R9.0 = command_allowed = check_logics(cmd)
lbz TULoop1Tail
glo RA ; pre-increment C[cmd] pointer to use as an end-of-loop marker
plo RD ; and store original value in RD###
adi 010H
plo RA
plo RB
ghi RA
phi RD ; RD is pAcVar###
adci 0
phi RA
phi RB
dec RB
dec RB
dec RB
dec RB ; RB is C[cmd][y]
TULoop1_1
ldn RB ; D = ac
bz TULoop1_1SkipAction
call Do_Action
bnz TULoop1_1Done ; if (failed) break;
TULoop1_1SkipAction
load r7,Loadflag
lda R7
bnz TULoop1Done ; if (loadflag) break twice
ldn R7
bnz TULoop1Done ; if (endflag) break twice
TULoo1_1Tail
inc RB ; y++
glo RB
str R2
glo RA
SM
lbnz TULoop1_1 ; loop if C[cmd][y] != C[cmd+1][0]
TULoop1_1Done
load r7,Array_NV ; R7 = NV
ldn R7
bnz TULoop1Done ; if (NV[0] != 0) break;
br TULoop1Tail2 ; skip C[cmd] pointer advancement because we already did it
TULoop1Tail
glo RA
adi 010H
plo RA
ghi RA
adci 000H
phi RA ; RA = C[cmd+1]
TULoop1Tail2
ldn RA
smi 0FFH
lbnz TULoop1
TULoop1Done
load r7,Array_NV
ldn R7 ; D = NV[0]
smi 10
bz TUCarryDrop
ldn R7
smi 18
bnz TUNotCarryDrop
TUCarryDrop
glo R9 ; D = command_allowed
bz TURunCarryDrop
ghi R9 ; D = command_found
bnz TUNotCarryDrop
TURunCarryDrop ; if (!command_found || !command_allowed)
call Do_CarryDrop ; carry_drop()
retn ; return
TUNotCarryDrop
ldn R7 ; D = NV[0]
bz TUDone
ghi R9 ; D = command_found
bnz TUCommandWasFound
load rf,Turn5Msg
br TUPrintAndReturn ; print: "I don't understand your command."
TUCommandWasFound
glo R9 ; D = command_allowed
bnz TUDone