-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadventureland.lst
7101 lines (7012 loc) · 282 KB
/
adventureland.lst
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"
; *******************************************************************
; *** This software is copyright 2006 by Michael H Riley ***
; *** You have permission to use, modify, copy, and distribute ***
; *** this software so long as this copyright notice is retained. ***
; *** This software may not be used in commercial applications ***
; *** without express written permission from the author. ***
; *******************************************************************
; f_getdev bit values
b_devIDE equ 00000001b ; IDE
b_devFLPY equ 00000010b ; floppy
b_devBBSER equ 00000100b ; Bit-banged serial
b_devUART equ 00001000b ; UART
b_devRTC equ 00010000b ; RTC
b_devNVR equ 00100000b ; NVRAM
b_devNBREAD equ 00000001b ; NBREAD supported
#ifndef _IS_BIOS
; Define address for standard BIOS vectors
BIOS equ 0ff00h
; Define address for extended BIOS vectors
EBIOS equ 0f800h
scall equ r4 ; register for SCALL
sret equ r5 ; register for SRET
f_boot equ (BIOS+00h) ; boot from ide device
f_type equ (BIOS+03h) ; type 1 character to console
f_read equ (BIOS+06h) ; read 1 character from console
f_msg equ (BIOS+09h) ; type asciiz string to console
f_typex equ (BIOS+0ch) ; depricated, just returns now
f_input equ (BIOS+0fh) ; read asciiz from console
f_strcmp equ (BIOS+12h) ; compare 2 strings
f_ltrim equ (BIOS+15h) ; trim leading spaces
f_strcpy equ (BIOS+18h) ; copy an asciiz string
f_memcpy equ (BIOS+1bh) ; copy memory
f_wrtsec equ (BIOS+1eh) ; write floppy sector (depricated)
f_rdsec equ (BIOS+21h) ; read floppy sector (depricated)
f_seek0 equ (BIOS+24h) ; floppy seek to track 0 (depricated)
f_seek equ (BIOS+27h) ; floopy track seek (depricated)
f_drive equ (BIOS+2ah) ; select floppy drive (depricated)
f_setbd equ (BIOS+2dh) ; set console baud rate
f_mul16 equ (BIOS+30h) ; 16-bit multiply
f_div16 equ (BIOS+33h) ; 16-bit division
f_idereset equ (BIOS+36h) ; reset ide device
f_idewrite equ (BIOS+39h) ; write ide sector
f_ideread equ (BIOS+3ch) ; read ide sector
f_initcall equ (BIOS+3fh) ; initialize R4 and R5
f_bootide equ (BIOS+42h) ; boot from ide device
f_hexin equ (BIOS+45h) ; convert ascii number to hex
f_hexout2 equ (BIOS+48h) ; convert hex to 2-digit ascii
f_hexout4 equ (BIOS+4bh) ; convert hex to 4-digit ascii
f_tty equ (BIOS+4eh) ; type character to console
f_mover equ (BIOS+51h) ; program relocator
f_minimon equ (BIOS+54h) ; mini monitor
f_freemem equ (BIOS+57h) ; determine memory size
f_isnum equ (BIOS+5ah) ; determine if D is numeric
f_atoi equ (BIOS+5dh) ; convert ascii to integer
f_uintout equ (BIOS+60h) ; convert unsigned integer to ascii
f_intout equ (BIOS+63h) ; convert signed integer to ascii
f_inmsg equ (BIOS+66h) ; type in-line message
f_inputl equ (BIOS+69h) ; read limited line from console
f_brktest equ (BIOS+6ch) ; check for serial break
f_findtkn equ (BIOS+6fh) ; find token in a token table
f_isalpha equ (BIOS+72h) ; determine if D is alphabetic
f_ishex equ (BIOS+75h) ; determine if D is hexadecimal
f_isalnum equ (BIOS+78h) ; determine if D is alpha or numeric
f_idnum equ (BIOS+7bh) ; determine type of ascii number
f_isterm equ (BIOS+7eh) ; determine if D is a termination char
f_getdev equ (BIOS+81h) ; get supported devices
f_nbread equ (BIOS+84); ; read 1 char from console (non blocking)
f_version equ (BIOS+0f9h) ; 3 bytes holding bios version number
; "Extended" BIOS vectors
f_bread equ (EBIOS+00h) ; read from onboard serial port
f_btype equ (EBIOS+03h) ; write to onboard serial port
f_btest equ (EBIOS+06h) ; test onboard serial port
f_utype equ (EBIOS+09h) ; write to disk board UART
f_uread equ (EBIOS+0ch) ; read from disk board UART
f_utest equ (EBIOS+0fh) ; test disk board UART
f_usetbd equ (EBIOS+12h) ; set disk board UART baud rate and format
f_gettod equ (EBIOS+15h) ; read time of day clock
f_settod equ (EBIOS+18h) ; set time of day clock
f_rdnvr equ (EBIOS+1bh) ; read non volatile RAM
f_wrnvr equ (EBIOS+1eh) ; write non volatile RAM
f_idesize equ (EBIOS+21h) ; return size of attached IDE drive(s)
f_ideid equ (EBIOS+24h) ; return device data for IDE drive(s)
f_tmtoas equ (EBIOS+2ah) ; time to ASCII string
f_dttoas equ (EBIOS+27h) ; date to ASCII string
f_rtctest equ (EBIOS+2dh) ; test size and presence of RTC/NVR
f_astodt equ (EBIOS+30h) ; convert ASCII string to date
f_astotm equ (EBIOS+33h) ; convert ASCII string to time
f_nvrcchk equ (EBIOS+36h) ; compute NVR checksum
#endif
incl "kernel.inc"
O_CREAT equ 00000001b
O_TRUNC equ 00000010b
O_APPND equ 00000100b
;
errexists equ 1
errnoffnd equ 2
errinvdir equ 3
errisdir equ 4
errdirnotempty equ 5
errnotexec equ 6
;
ff_dir equ 00000001b
ff_exec equ 00000010b
ff_write equ 00000100b
ff_hide equ 00001000b
ff_archive equ 00010000b
#ifndef _IS_KERNEL
O_CLDBOOT: equ 0300h ; jump to cold boot routine
O_WRMBOOT: equ 0303h ; jump to warm boot routine
O_OPEN: equ 0306h ; open a file
O_READ: equ 0309h ; read from file
O_WRITE: equ 030ch ; write to file
O_SEEK: equ 030fh ; seek to file position
O_CLOSE: equ 0312h ; close file
O_OPENDIR: equ 0315h ; open dir as a file
O_DELETE: equ 0318h ; delete a file
O_RENAME: equ 031bh ; rename a file
O_EXEC: equ 031eh ; execute an external program
O_MKDIR: equ 0321h ; make directory
O_CHDIR: equ 0324h ; change directory
O_RMDIR: equ 0327h ; remove directory
O_RDLUMP: equ 032Ah ; read LAT entry
O_WRLUMP: equ 032Dh ; write LAT entry
O_TYPE: equ 0330h ; passthrough for console output
O_MSG: equ 0333h ; passthrough for console output
O_READKEY: equ 0336h ; passthrough for console input
O_INPUT: equ 0339h ; passthrough for console input
O_PRTSTAT: equ 033ch ; printer status
O_PRINT: equ 033fh ; output to printer
O_EXECBIN: equ 0342h ; execute from default directory
O_SETDEF: equ 0345h ; set/get default directory
O_KINIT: equ 0348h ; reserved - do not use!!!
O_INMSG: equ 034bh ; passthrough for console output
O_GETDEV: equ 034eh ; passthrough to f_getdef
O_GETTOD: equ 0351h ; passthrough to f_gettod
O_SETTOD: equ 0354h ; passthrough to f_settod
O_INPUTL: equ 0357h ; passthrough to f_inputl
O_BOOT: equ 035ah ; passthrough to f_boot
O_TTY: equ 035dh
O_SETBD: equ 0360h ; passthrough to f_setbd
O_INITCALL: equ 0363h ; passthrough to f_initcall
O_BRKTEST: equ 0366h ; passthrough to f_brktest
O_DEVCTRL: equ 0369h ; Hook for device control drivers
O_ALLOC: equ 036ch ; passthrough to alloc
O_DEALLOC: equ 036fh ; passthrough to dealloc
O_TERMCTRL: equ 0372h ; Hook for terminal control drivers
O_MEMCTRL: equ 0375h ; Hook for memory control drivers
;
I_SERVE: equ 03f6h ; address of interrupt chain head
;
V_IVEC: equ 03fdh ; interrupt head
V_DVEC: equ 036ah ; device head
K_VER: equ 0400h ; kernel version number
K_BUILD: equ 0403h ; kernel build number
K_BMONTH: equ 0405h ; kernel build month
K_BDAY: equ 0406h ; kernel build day
K_BYEAR: equ 0407h ; kernel build month
K_HIMEM: equ 0442h ; high memory pointer
K_LOWMEM: equ 0465h ; lowest memory heap can use
K_RETVAL: equ 0467h ; D on program exit
K_HEAP: equ 0468h ; heap pointer
K_CLKFREQ: equ 0470h ; system clock frequency
K_MONTH: equ 0475h ; date/time
K_DAY: equ 0476h
K_YEAR: equ 0477h
K_HOUR: equ 0478h
K_MINUTE: equ 0479h
K_SECOND: equ 047ah
K_SECDEN: equ 047bh
K_SECNUM: equ 047dh
;
D_IDERESET equ 0444h ; jump to bios ide reset
D_IDEREAD equ 0447h ; jump to bios ide read
D_IDEWRITE equ 044ah ; jump to bios ide write
D_REAPHEAP equ 044dh ; passthrough to heapreaper
D_PROGEND equ 0450h
#endif
;
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
1ffa 20 00 dw 2000h
1ffc 53 d2 dw endrom-2000h
1ffe 20 00 dw 2000h
;
2000 30 b0 br GameStart
; **************************************************
; Build date format:
; 80h+month, day, four digit year
; **************************************************
; 80h month offset indicates extended
; build information, with build number and text.
; **************************************************
;
;
2002 88 07 07 e5 date
2006 00 05 build: dw 5 ; build number
2008 40 43 6f 70 db '@Copyleft 2021 Wayne Hortensius',0
200c 79 6c 65 66
2010 74 20 32 30
2014 32 31 20 57
2018 61 79 6e 65
201c 20 48 6f 72
2020 74 65 6e 73
2024 69 75 73 00
;__________________________________________________________________________________________________
; Print a 2-digit number
; IN: D = number to print, RF = pointer to start of string
; OUT: N/A
; TRASHED: D, R7
Print2Digit
2028 b7 phi R7 ; save number to print
2029 f8 00 ldi 0
202b a7 plo R7
202c 97 ghi R7
P2D_Tens
202d ff 0a smi 10
202f 3b 34 bl P2D_TensDone
2031 17 inc R7
2032 30 2d br P2D_Tens
P2D_TensDone
2034 fc 0a adi 10 ; D is now number of singles
2036 b7 phi R7
2037 87 glo R7
2038 c6 LSNZ ; if there are no tens,
2039 f8 f0 ldi ' '-'0' ; use space as filler char.
203b fc 30 adi '0'
203d 5f str RF ; store the tens digit
203e 1f inc RF
203f f8 30 ldi '0'
2041 a7 plo R7
2042 97 ghi R7
P2D_Ones
2043 ff 01 smi 1
2045 3b 4a bl P2D_OnesDone
2047 17 inc R7
2048 30 43 br P2D_Ones
P2D_OnesDone
204a 87 glo R7
204b 5f str RF
204c 2f dec RF
204d d5 retn
;__________________________________________________________________________________________________
; Clear screen
; IN: N/A
; OUT: N/A
; TRASHED: RF
ClearScreen
204e f8 2b bf f8 load rf,ClsMsg
2052 bf af
2054 d4 03 33 call O_MSG
2057 d5 retn
;__________________________________________________________________________________________________
; Generate a psuedo-random byte
; IN: N/A
; OUT: D=psuedo-random number
; TRASHED: R7
GenRandom
2058 f8 73 b7 f8 load r7,Rand_VarX
205c 73 a7
205e e7 sex R7
205f 07 ldn R7 ; D = VarX
2060 fc 01 adi 1
2062 57 str R7
2063 17 inc R7
2064 47 lda R7 ; D = VarA
2065 17 inc R7
2066 f3 XOR ; D = VarA XOR VarC
2067 27 dec R7
2068 27 dec R7
2069 27 dec R7
206a f3 XOR ; D = VarA XOR VarC XOR VarX
206b 17 inc R7
206c 57 str R7 ; VarA = D
206d 17 inc R7
206e f4 ADD
206f 73 stxd
2070 f6 SHR
2071 f3 XOR
2072 17 inc R7
2073 17 inc R7
2074 f4 ADD
2075 57 str R7
;;; sex r2
2076 d5 retn
;__________________________________________________________________________________________________
; Restore internal variables to starting state
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, R9
GameReset
2077 f8 63 b8 f8 load r8,Array_I2 ; start by initializing item locations
207b d7 a8
207d f8 73 b9 f8 load r9,Array_IA
2081 2d a9
2083 f8 3d ldi IL
2085 a7 plo R7
GRLoop1
2086 48 lda R8
2087 59 str R9
2088 19 inc R9
2089 27 dec R7
208a 87 glo R7
208b 3a 86 bnz GRLoop1
208d 19 inc R9
208e 19 inc R9
208f f8 00 ldi 0
2091 59 str R9 ; Loadflag = 0
2092 19 inc R9
2093 59 str R9 ; Endflag = 0
2094 19 inc R9
2095 59 str R9 ; Darkflag = 0
2096 f8 0b ldi AR
2098 19 inc R9
2099 59 str R9 ; Room = AR
209a f8 7d ldi LI
209c 19 inc R9
209d 59 str R9 ; lamp_oil = LT
209e f8 00 ldi 0
20a0 19 inc R9
20a1 59 str R9
20a2 19 inc R9
20a3 59 str R9 ; state_flags = 0
20a4 d5 retn
;__________________________________________________________________________________________________
; Main program starting point
Exit
20a5 f8 73 bf f8 load rf,saveStack ; restore Elf/OS's stack
20a9 bb af
20ab 4f lda rf
20ac b2 phi r2
20ad 0f ldn rf
20ae a2 plo r2
20af d5 retn ; return to Elf/OS
GameStart
20b0 f8 73 bf f8 load rf,saveStack ; save Elf/OS's stack
20b4 bb af
20b6 92 ghi r2
20b7 5f str rf
20b8 1f inc rf
20b9 82 glo r2
20ba 5f str rf
20bb f8 73 b2 f8 load r2,localStack ; use our own stack
20bf ba a2
20c1 f8 64 bf f8 load rf,splash
20c5 14 af
20c7 d4 03 33 call O_MSG
20ca d4 03 36 call O_READKEY ; wait for key press
20cd d4 20 4e call ClearScreen
; beginning of main() function
; Print welcome message
20d0 f8 2b bf f8 load rf,StartingMsg
20d4 ce af
20d6 d4 03 33 call O_MSG
; start of main loop
MainLoad
; reset all game state
20d9 d4 20 77 call GameReset
; load game if possible
20dc d4 23 10 call Do_LoadGame
; clear screen
20df d4 20 4e call ClearScreen
; look()
20e2 d4 23 67 call Do_Look
; NV[0] = 0
20e5 f8 73 b9 f8 load r9,Array_NV
20e9 6a a9
20eb f8 00 ldi 0
20ed 59 str R9
; turn()
20ee d4 24 57 call Do_Turn
MainGetInput
; get_input()
20f1 d4 21 82 call Do_GetInput
; if command parsing failed, try again
20f4 3a f1 bnz MainGetInput
; turn()
20f6 d4 24 57 call Do_Turn
; reload R9 to point to Endflag
20f9 f8 73 b9 f8 load r9,Endflag
20fd 6d a9
20ff 09 ldn R9
2100 ca 20 a5 lbnz Exit ; quit if endflag != 0
2103 29 dec R9
2104 09 ldn R9
2105 ca 20 d9 lbnz MainLoad ; loop back and re-load if loadflag != 0
; deal with lamp oil
2108 f8 73 ba f8 load ra,Array_IA+9
210c 36 aa
210e 0a ldn RA
210f ff ff smi 0FFH
2111 ca 21 58 lbnz MainNoLamp
2114 f8 73 b9 f8 load r9,LampOil
2118 70 a9
211a 09 ldn R9
211b ff 01 smi 1
211d 59 str R9 ; lamp_oil--
211e c3 21 2f lbdf LampNotEmpty
2121 f8 2c bf f8 load rf,LampEmptyMsg ; print Lamp is Empty message
2125 c5 af
2127 d4 03 33 call O_MSG
212a f8 00 ldi 0
212c 5a str RA ; IA[9] = 0
212d 30 58 br MainNoLamp
LampNotEmpty
212f ff 19 smi 25 ; is our oil level < 25?
2131 33 58 bdf MainNoLamp
2133 f8 2c bf f8 load rf,LampLow1Msg ; print Lamp is low message
2137 ee af
2139 d4 03 33 call O_MSG
213c f8 73 bf f8 load rf,PrintNumber
2140 77 af
2142 09 ldn R9 ; D = lamp_oil
2143 d4 20 28 call Print2Digit
2146 f8 73 bf f8 load rf,PrintNumber
214a 77 af
214c d4 03 33 call O_MSG
214f f8 2d bf f8 load rf,LampLow2Msg
2153 15 af
2155 d4 03 33 call O_MSG
MainNoLamp
; NV[0] = 0
2158 f8 73 b9 f8 load r9,Array_NV
215c 6a a9
215e f8 00 ldi 0
2160 59 str R9
; turn()
2161 d4 24 57 call Do_Turn
MainLoopTail
; reload R9 to point to Endflag
2164 f8 73 b9 f8 load r9,Endflag
2168 6d a9
216a 09 ldn R9
216b ca 20 a5 lbnz Exit ; if endflag != 0, quit
216e 29 dec R9
216f 09 ldn R9
2170 ca 20 d9 lbnz MainLoad ; if loadflag != 0, loop back and re-load
2173 c0 20 f1 lbr MainGetInput ; otherwise, get next command
;__________________________________________________________________________________________________
; Adventure get_action_variable() function
; IN: RD=pAcVar
; OUT: D=value
; TRASHED: N/A
Sub_GetActionVariable
2176 1d inc RD ; ###
2177 1d inc RD
GAV_Loop1
2178 1d inc RD
2179 0d ldn RD
217a 32 7f bz GAV_FoundVar
217c 1d inc RD
217d 30 78 br GAV_Loop1
GAV_FoundVar
217f 2d dec RD
2180 0d ldn RD
2181 d5 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
2182 f8 2d bf f8 load rf,InputPromptMsg
2186 23 af
2188 d4 03 33 call O_MSG
; now we are in the gets() function. set up loop variables
218b f8 00 ldi 0
218d aa plo RA ; RA.0 is character counter; only 79 are allowed
218e f8 72 b9 f8 load r9,Array_TPS ; R9 is pointer to input line
2192 dd a9
GILoop1
; wait for key press
2194 9e ghi re
2195 fa fe ani 0feh
2197 be phi re
2198 d4 03 36 call O_READKEY
219b bf phi rf
219c 9e ghi re
219d f9 01 ori 001h
219f be phi re
; handle backspace
21a0 9f ghi RF
21a1 ff 08 smi 8
21a3 32 aa bz GIBackspace
21a5 9f ghi RF
21a6 ff 7f smi 07FH
21a8 3a c0 bnz GILoop1N1
GIBackspace
21aa 8a glo RA ; if line length is 0
21ab 32 94 bz GILoop1 ; then just go back for another input character
21ad f8 08 ldi bs ; otherwise, erase last character
21af d4 03 30 call O_TYPE
21b2 f8 20 ldi ' ' ; ' '
21b4 d4 03 30 call O_TYPE
21b7 f8 08 ldi bs ; '\b'
21b9 d4 03 30 call O_TYPE
21bc 2a dec RA ; decrement character count
21bd 29 dec R9 ; decrement input line pointer
21be 30 94 br GILoop1 ; and then go back for another input character
GILoop1N1
; handle enter or return
21c0 9f ghi RF
21c1 ff 0a smi lf
21c3 c2 21 cb LBZ GIEnter
21c6 9f ghi RF
21c7 ff 0d smi cr
21c9 3a d7 bnz GILoop1N2
GIEnter
21cb f8 0d ldi cr
21cd d4 03 30 call O_TYPE
21d0 f8 0a ldi lf
21d2 d4 03 30 call O_TYPE
21d5 30 ff br GIgetsDone
GILoop1N2
; ensure that input character is valid
21d7 9f ghi RF
21d8 ff 20 smi ' '
21da 32 f3 bz GICharOk
21dc 9f ghi RF
21dd ff 41 smi 'A'
21df 3b f0 bl GIJumpLoop1
21e1 9f ghi RF
21e2 ff 5b smi 'Z'+1
21e4 3b f3 bl GICharOk
21e6 9f ghi RF
21e7 ff 61 smi 'a'
21e9 3b f0 bl GIJumpLoop1
21eb 9f ghi RF
21ec ff 7b smi 'z'+1
21ee 3b f3 bl GICharOk
GIJumpLoop1
21f0 c0 21 94 LBR GILoop1
GICharOk
21f3 9f ghi RF
21f4 59 str R9 ; add input character to our string
21f5 19 inc R9
21f6 1a inc RA ; increment string length counter
21f7 d4 03 30 call O_TYPE ; echo character to serial output
21fa 8a glo RA ; how long is the input line?
21fb ff 4f smi 79
21fd 3b f0 bl GIJumpLoop1 ; if < 79 characters, go get another
GIgetsDone
21ff f8 00 ldi 0 ; null-terminate input string
2201 59 str R9
2202 f8 72 b9 f8 load r9,Array_TPS
2206 dd a9
; now we are back in the get_input() function.
; If the line is empty, go prompt for another command
2208 09 ldn R9
2209 c2 21 82 LBZ Do_GetInput
; otherwise, start parsing. begin by skipping any leading spaces
GIParseLoop1
220c 49 lda R9
220d 32 13 bz GIParseLoop1Done
220f ff 20 smi ' '
2211 32 0c bz GIParseLoop1
GIParseLoop1Done
2213 29 dec R9
; store pointer to first word in RA
2214 89 glo R9
2215 aa plo RA
2216 99 ghi R9
2217 ba phi RA
; convert entire string to uppercase
GIParseLoop2
2218 49 lda R9
2219 c2 22 29 lbz GIParseLoop2Done
221c ff 61 smi 'a'
221e cb 22 18 lbnf GIParseLoop2 ; BL
2221 fc 41 adi 'A'
2223 29 dec R9
2224 59 str R9
2225 19 inc R9
2226 c0 22 18 lbr GIParseLoop2
GIParseLoop2Done
; reload pointer to start of first word, and find the end (the next space)
2229 8a glo RA
222a a9 plo R9
222b 9a ghi RA
222c b9 phi R9
GIParseLoop3
222d 49 lda R9
222e 32 34 bz GIParseLoop3Done
2230 ff 20 smi ' '
2232 3a 2d bnz GIParseLoop3
GIParseLoop3Done
; if we found a space, NULL-terminate the first word
2234 29 dec R9
2235 09 ldn R9
2236 c2 22 3d lbz GIParseLoop4
2239 f8 00 ldi 0
223b 59 str R9
223c 19 inc R9
; skip any additional spaces in between words
GIParseLoop4
223d 49 lda R9
223e ff 20 smi ' '
2240 c2 22 3d lbz GIParseLoop4
2243 29 dec R9
; store pointer to second word in RB
2244 89 glo R9
2245 ab plo RB
2246 99 ghi R9
2247 bb phi RB
; find matches for both words
2248 f8 73 bc f8 load rc,Array_NV ; RC = pointer to NV[2]
224c 6a ac
224e f8 3a bd f8 load rd,Array_NVS ; RD = pointer to NVS[2][NL][4], NL=60
2252 e3 ad
2254 f8 00 ldi 0
2256 bf phi RF ; RF.1 = i, for (i = 0; i < 2; i++)
2257 8a glo RA ; load pointer to first word in R9
2258 a9 plo R9
2259 9a ghi RA
225a b9 phi R9
GIParseLoop5
225b f8 00 ldi 0
225d 5c str RC ; NV[i] = 0
225e 09 ldn R9
225f 32 b4 bz GIParseLoop5Tail
2261 f8 00 ldi 0
2263 af plo RF ; RF.0 = j, for (j = 0; j < NL; j++)
GIParseLoop5_1
2264 8d glo RD
2265 a8 plo R8
2266 9d ghi RD
2267 b8 phi R8 ; R8 = s = NVS[i][j]
2268 08 ldn R8
2269 ff 2a smi '*' ; if first character of word is '*'
226b 3a 6e bnz GIParseLoop5_1Next1
226d 18 inc R8 ; then skip it
GIParseLoop5_1Next1
; comparestring()
226e e8 sex r8
226f 49 lda R9 ; Load 1st character in input word
2270 32 84 bz GIParseLoop5_1WordEnd
2272 f7 SM ; compare to 1st character in table word
2273 3a 9c bnz GIParseLoop5_1NoMatch
2275 18 inc R8
2276 49 lda R9 ; Load 2nd character in input word
2277 32 84 bz GIParseLoop5_1WordEnd
2279 f7 SM ; compare to 2nd character in table word
227a 3a 9c bnz GIParseLoop5_1NoMatch
227c 18 inc R8
227d 49 lda R9 ; Load 3rd character in input word
227e 32 84 bz GIParseLoop5_1WordEnd
2280 f7 SM
2281 3a 9c bnz GIParseLoop5_1NoMatch
2283 38 SKP ; fall through to GIParseLoop5_1Match
GIParseLoop5_1WordEnd
2284 08 ldn R8
2285 3a 9c bnz GIParseLoop5_1NoMatch
GIParseLoop5_1Match
2287 8f glo RF
2288 5c str RC ; NV[i] = j
2289 8d glo RD
228a a8 plo R8
228b 9d ghi RD
228c b8 phi R8 ; R8 = NVS[i][j]
GIParseLoop5_1_1 ; while (NVS[i][NV[i]][0] == '*') NV[i]--;
228d 08 ldn R8
228e ff 2a smi '*'
2290 3a b4 bnz GIParseLoop5Tail
2292 0c ldn RC
2293 ff 01 smi 1
2295 5c str RC ; NV[i]--
2296 28 dec R8
2297 28 dec R8
2298 28 dec R8
2299 28 dec R8
229a 30 8d br GIParseLoop5_1_1
GIParseLoop5_1NoMatch
229c e2 sex R2
229d 1d inc RD
229e 1d inc RD
229f 1d inc RD
22a0 1d inc RD ; move word table pointer to next word
22a1 9f ghi RF ; test i variable
22a2 3a aa bnz GIParseLoop5_1Next2
22a4 8a glo RA ; reload pointer to first word in R9
22a5 a9 plo R9
22a6 9a ghi RA
22a7 b9 phi R9
22a8 30 ae br GIParseLoop5_1Next3
GIParseLoop5_1Next2
22aa 8b glo RB ; reload pointer to second word in R9
22ab a9 plo R9
22ac 9b ghi RB
22ad b9 phi R9
GIParseLoop5_1Next3
22ae 1f inc RF
22af 8f glo RF
22b0 ff 3c smi NL ; NL = 60
22b2 3b 64 BNF GIParseLoop5_1 ; go check the next word in the table
GIParseLoop5Tail
22b4 1c inc RC ; point to next element in NV array
22b5 8b glo RB ; load pointer to second word in R9
22b6 a9 plo R9
22b7 9b ghi RB
22b8 b9 phi R9
22b9 f8 3b bd f8 load rd,Array_NVS+(NL*4) ; RD = pointer to second half of NVS[2][NL][4], NL=60
22bd d3 ad
22bf 9f ghi RF
22c0 fc 01 adi 1 ; i++
22c2 bf phi RF
22c3 ff 02 smi 2
22c5 3b 5b BNF GIParseLoop5 ; branch if less
; validate first word (verb)
22c7 2c dec RC
22c8 2c dec RC
22c9 4c lda RC
22ca ca 22 e9 lbnz GIParseVerbOk
22cd f8 2d bf f8 load rf,InputError1Msg
22d1 43 af
22d3 d4 03 33 call O_MSG ; print "I don't know how to "
22d6 8a glo RA
22d7 af plo RF
22d8 9a ghi RA
22d9 bf phi RF
22da d4 03 33 call O_MSG ; print first word
22dd f8 2d bf f8 load rf,InputError2Msg
22e1 5c af
22e3 d4 03 33 call O_MSG ; print '!\r\n'
22e6 f8 01 ldi 1
22e8 d5 retn ; return 1
GIParseVerbOk
; validate second word (noun)
22e9 0b ldn RB ; D is word[0][0]
22ea c2 23 0d lbz GIParseAllGood
22ed 0c ldn RC ; D is NV[1]
22ee ca 23 0d lbnz GIParseAllGood
22f1 f8 2d bf f8 load rf,InputError3Msg
22f5 64 af
22f7 d4 03 33 call O_MSG ; print "I don't know what a "
22fa 8b glo RB
22fb af plo RF
22fc 9b ghi RB
22fd bf phi RF
22fe d4 03 33 call O_MSG ; print second word
2301 f8 2d bf f8 load rf,InputError4Msg
2305 7d af
2307 d4 03 33 call O_MSG ; print " is!\n"
230a f8 01 ldi 1
230c d5 retn ; return 1
GIParseAllGood
230d f8 00 ldi 0
230f d5 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
2310 f8 2c bf f8 load rf,LoadQestion
2314 49 af
2316 d4 03 33 call O_MSG ; print "Load saved game (Y or N)?"
2319 d4 2a ee call Do_YesNo ; D = 0 if No, 1 if Yes
231c ca 23 20 lbnz LGNext1
231f d5 retn ; return
LGNext1
2320 f8 72 bf f8 load rf,SavePath
2324 cc af
2326 f8 73 bd f8 load rd,SaveFiledes ; savefile descriptor
232a bd ad
232c f8 00 ldi 0 ; (nocreate, no truncate, no append) flags
232e a7 plo r7
232f d4 03 06 call O_OPEN ; attempt to open file
2332 cb 23 42 lbnf LoadOpened ; DF=0, file was opened
LoadFailed:
2335 f8 2c bf f8 load rf,LoadFailedMsg
2339 6f af
233b d4 03 33 call O_MSG
233e d4 03 36 call O_READKEY ; wait for key press
2341 d5 retn
;
LoadOpened:
2342 f8 00 bc f8 load rc,SaveLength
2346 46 ac
2348 f8 73 bf f8 load rf,SaveStart
234c 2d af
234e f8 73 bd f8 load rd,SaveFiledes
2352 bd ad
2354 d4 03 09 call O_READ ; read the save file
2357 cb 23 5d lbnf CloseLoadFile ; DF=0, read OK
235a d4 23 35 call LoadFailed ; erad failed
CloseLoadFile:
235d f8 73 bf f8 load rf,SaveFiledes
2361 bd af
2363 d4 03 12 call O_CLOSE ; close the image file
2366 d5 retn
;__________________________________________________________________________________________________
; Adventure look() function
; IN: N/A
; OUT: N/A
; TRASHED: R7, R8, R9, RA, RB, RC, RF
Do_Look
2367 f8 73 b9 f8 load r9,Darkflag
236b 6e a9
236d 49 lda R9 ; D == is_dark
236e 32 89 bz LKNotDark
2370 e9 sex R9 ; R9 is pointing to 'room'
2371 f8 73 ba f8 load ra,Array_IA+9
2375 36 aa
2377 0a ldn RA
2378 fe SHL
2379 33 89 BDF LKNotDark
237b f6 SHR
237c f7 SM
237d 32 89 bz LKNotDark
; it's dark. print a message and return
237f f8 2d bf f8 load rf,Look1Msg
2383 88 af
2385 d4 03 33 call O_MSG
2388 d5 retn
LKNotDark
2389 09 ldn R9
238a fe SHL ; D = room * 2
238b fc bc adi LOW Table_RSS
238d aa plo RA
238e f8 3d ldi HIGH Table_RSS
2390 7c 00 ADCI 0
2392 ba phi RA
2393 4a lda RA
2394 bb phi RB
2395 4a lda RA
2396 ab plo RB ; RB = RSS[room]
2397 4b lda RB
2398 ff 2a smi '*'
239a 32 a6 bz LKPrintRoom1
239c 2b dec RB
239d f8 2d bf f8 load rf,Look2Msg ; print "I'm in a " prefix
23a1 b2 af
23a3 d4 03 33 call O_MSG
LKPrintRoom1
23a6 8b glo RB
23a7 af plo Rf
23a8 9b ghi RB
23a9 bf phi Rf
23aa d4 03 33 call O_MSG ; print the room description
23ad f8 00 ldi 0
23af ab plo RB ; RB.0 is item counter 'i' for loop
23b0 bb phi RB ; RB.1 is flag which specifies whether item list prefix has been printed
23b1 f8 73 ba f8 load ra,Array_IA ; RA is pointer to start of IA[]
23b5 2d aa
LKLoop1
23b7 e9 sex R9 ; R9 is pointing to 'room'
23b8 4a lda RA
23b9 f7 SM
23ba ca 24 00 lbnz LKLoop1Tail
; we have found an item in this room. start by printing the item list header if necessary
23bd 9b ghi RB
23be 3a cc bnz LKLoop1Next1
23c0 f8 01 ldi 1
23c2 bb phi RB
23c3 f8 2d bf f8 load rf,Look3Msg
23c7 bc af
23c9 d4 03 33 call O_MSG ; print: "Visible Items Here:"
LKLoop1Next1
; print item description
23cc 8b glo RB ; D = item number (i)
23cd fe SHL
23ce fc 1a adi LOW Table_IAS
23d0 a8 plo R8
23d1 f8 5c ldi HIGH Table_IAS
23d3 7c 00 adci 0
23d5 b8 phi R8
23d6 48 lda R8
23d7 bc phi RC
23d8 48 lda R8
23d9 ac plo RC ; RC = pointer to item description
23da f8 20 ldi ' '
23dc d4 03 30 call O_TYPE
23df f8 20 ldi ' '
23e1 d4 03 30 call O_TYPE
23e4 f8 20 ldi ' '
23e6 d4 03 30 call O_TYPE
LKLoop1_1
23e9 0c ldn RC
23ea 32 f6 bz LKLoop1_1Tail
23ec ff 2f smi '/'
23ee 32 f6 bz LKLoop1_1Tail
23f0 4c lda RC
23f1 d4 03 30 call O_TYPE
23f4 30 e9 br LKLoop1_1
LKLoop1_1Tail
23f6 f8 0d ldi cr
23f8 d4 03 30 call O_TYPE
23fb f8 0a ldi lf
23fd d4 03 30 call O_TYPE
LKLoop1Tail
2400 1b inc RB
2401 8b glo RB
2402 ff 3d smi IL
2404 cb 23 b7 LBNF LKLoop1
; now print room exits
2407 e9 sex R9
2408 09 ldn R9 ; D = room
2409 f4 ADD
240a f4 ADD
240b fe SHL ; D = room * 6
240c fc f0 adi LOW Array_RM
240e a9 plo R9
240f f8 3c ldi HIGH Array_RM
2411 7c 00 adci 0
2413 b9 phi R9 ; R9 is pointer to RM[room][0]
2414 f8 00 ldi 0
2416 ab plo RB ; RB.0 is direction counter 'i' for loop
2417 bb phi RB ; RB.1 is flag which specifies whether exit list header has been printed
LKLoop2
2418 49 lda R9
2419 c2 24 40 LBZ LKLoop2Tail