-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlastjob.asm
executable file
·2070 lines (2068 loc) · 55.7 KB
/
lastjob.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
; --------------------------------------------------------------------------
; BILL'S LAST JOB
; --------------------------------------------------------------------------
; Written by Tal Safran
; E-Mail: safran \\AT\\ nyu //D0T// edu
; NYU ID: N19420196
; V22.0201 - Computer Systems Organization
; Fall 2008, New York University
; Professor Nathan Hull
; --------------------------------------------------------------------------
JMP MAIN
; Game speed! Very important!
SPEED DB 50 ; Any value between 1-99
D_LOOP EQU 1400 ; Delay loop (Higher value = slower)
; DOS Settings
DOSC_C DB ? ; Original column of DOS cursor
; Sound Settings
SOUND DB 0 ; Sound? (0 - OFF, else - ON)
; For saved games
PLAYER DB 9 DUP (' ') ; Maximum 8 chars. Spaces will be trimmed later
; Last space used as EOF
FNAME DB 15 DUP (0) ; Complete file name for saved
FHANDLE DW ? ; File handle for writing/reading files
; File data: <Current level>, <Sound ON/OFF), <Delay>, <Attempts for levs 1-9)
FDATA DB 1, 0FFH, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 12 bytes total
; Menu settings
MENU_COL EQU 48 ; Column for menu cursor
MENU_ROW DB 12 ; Row variable for menu cursor
MENU_INST EQU 12 ; Row location for INSTRUCTIONS
MENU_STRT EQU 14 ; Row location for START GAME
MENU_LOAD EQU 16 ; Row location for LOAD GAME
MENU_EXIT EQU 18 ; Row location for EXIT
; Definition of Colors
C_DOS EQU 07H ; Grey on black
C_WALL EQU 44H ; Wall color (Red)
C_BUG EQU 02H ; BUG color (Green on black)
C_BRN EQU 0CH ; Brain color (Light red on black)
C_STATUS EQU 4FH ; Status bar (White on red)
C_RNG EQU 4EH ; Range (yellow on red)
C_INTRO1 EQU 0FH ; White on black
C_INTRO2 EQU 0EH ; Yellow on black
; Positions of game burders
BORD_R EQU 77 ; Right border
BORD_L EQU 8 ; Left border
BORD_B EQU 23 ; Bottom border
BORD_T EQU 1 ; Top border
; Positions of BUG Zone borders
ZONEB_R EQU 7 ; Right border
ZONEB_L EQU 4 ; Left border
ZONEB_T EQU 3 ; Top border
ZONEB_B EQU 18 ; Bottom border
; Position of BUG
HIDEB DB 0 ; 0 - draw BUG; 1 - hide BUG
BUG_R DB ? ; Row position of BUG
BUG_C DB ? ; Column position of BUG
; Number of attempts
ATT DB ? ; Number of shots attempted
; Brain character, position, direction, and range left
BRAIN EQU 0ECH ; Brain character
BRN_R DB ? ; Brain row position
BRN_C DB ? ; Brain column position
BRN_HDIR DB ? ; Horizontal direction: 0=;left, FF=right
BRN_VDIR DB ? ; Vertical direction: 0=up, FF=down
RNG_MAX DB ? ; Maximum brain distance for current level
RNG_BRN DB ? ; Distance traveled by brain
RNG_LFT DB ? ; Distance left
RNG_DEC DB ? ; Traces number of decrements for RANGE label
; Directions (for movement of BUG)
D_TUR DB 0 ; Turret: 0 - up; else - down
D_UP EQU 48H ; UP key
D_DOWN EQU 50H ; DOWN key
D_LEFT EQU 4BH ; LEFT key
D_RIGHT EQU 4DH ; RIGHT key
; --------------------------------------------------------------------------
; MAIN Program
; --------------------------------------------------------------------------
MAIN: CALL INTRO ; Load introduction
CALL MENU ; Load menu
; Return everything and exit
MOV BL, C_DOS ; Set DOS colors
CALL CLS ; Blank the screen
MOV DL, DOSC_C ; Reset to original cursor column
MOV DH, 0 ; First line
CALL SETCUR
;
INT 20H
; --------------------------------------------------------------------------
; CALL INTRO Displays the introduction
;
; (No input required)
; --------------------------------------------------------------------------
INTRO PROC
; Paint screen black
MOV BL, 0 ; Black background
CALL CLS
; Paint opening screen
LEA SI, S_SKIP ; "Press any key to continue..."
MOV DH, 22 ; Row
MOV DL, 60 ; Column
MOV BL, C_INTRO2 ; Color scheme
CALL PRINTSTR
MOV EFF, 0FFH ; Turn on 'typing' effect
LEA SI, S_INTRO ; Load opening text
MOV DH, 5 ; Row
MOV DL, 10 ; Column
MOV BL, C_INTRO1 ; Color scheme
CALL PRINTSTR
MOV EFF, 0 ; Turn off 'typing' effect
MOV AH, 0 ; Wait for user to press key
INT 16H
;
RET
INTRO ENDP
; --------------------------------------------------------------------------
; CALL MENU Displays the menu
;
; (No input required)
; --------------------------------------------------------------------------
MENU PROC
PUSH AX ; Save registers
PUSH BX
; Clear the screen
MENU1: MOV BL, 0 ; Black
CALL CLS
; Initialize PLAYER string
MOV DI, 0 ; Initialize offset
INITP: MOV PLAYER[DI], ' ' ; Put all spaces in player name
INC DI
CMP DI, 9 ; ... in first 8 characters
JB INITP
; Initialize FNAME string with all 0's
MOV DI, 0
INITF: MOV FNAME[0], 0 ; Put all zeros in file name
INC DI
CMP DI, 15 ; at last char?
JB INITF
; Paint the logo
LEA SI, S_LOGO ; Load logo
MOV DH, 2 ; Row
MOV DL, 5 ; Column
MOV BL, C_INTRO2 ; Color scheme
CALL PRINTSTR
; Paint Menu items
LEA SI, S_MENU ; Load menu string
MOV DH, 12 ; Row
MOV DL, 50 ; Column
MOV BL, C_INTRO1 ; Color scheme
CALL PRINTSTR
; Print brain 'cursor'
MOV DH, MENU_ROW ; Row
MOV DL, MENU_COL ; Column
MOV CX, 1 ; 1 char at a time
MOV BL, C_BRN ; Color scheme
MOV AL, BRAIN ; Character
CALL PAINT
; Wait for user to do something
GETACT: MOV AH, 0 ; Read a key
INT 16H
MOV AL, MENU_ROW ; Save cursor location
CMP AH, D_UP ; Pressed UP?
JE M_UP
CMP AH, D_DOWN ; Pressed DOWN?
JE M_DOWN
CMP AH, 1CH ; Pressed ENTER?
JE DOACT
JMP GETACT ; Otherwise, get new key
; Help a brotha jump!
MENU2: JMP MENU1
; Move cursor up
M_UP: CMP AL, MENU_INST ; At top row?
JE GETACT ; ... if yes, neglect
MOV DH, MENU_ROW ; Row
MOV DL, MENU_COL ; Column
MOV CX, 1 ; 1 char
MOV BL, C_BRN ; Color scheme
MOV AL, ' ' ; SPACE temporarily hides cursor
CALL PAINT
SUB MENU_ROW, 2 ; Go 2 rows down
MOV DH, MENU_ROW ; Set new row
MOV AL, BRAIN ; Set BRAIN character
CALL PAINT
JMP GETACT ; Get new key
; Move cursor down
M_DOWN: CMP AL, MENU_EXIT ; At bottom row?
JE GETACT ; ... if yes, neglect
MOV DH, MENU_ROW ; Row
MOV DL, MENU_COL ; Column
MOV CX, 1 ; 1 char
MOV BL, C_BRN ; Color scheme
MOV AL, ' ' ; SPACE temporarily hides cursor
CALL PAINT
ADD MENU_ROW, 2 ; Go 2 rows up
MOV DH, MENU_ROW ; Set new row
MOV AL, BRAIN ; Set BRAIN character
CALL PAINT
JMP GETACT ; Get new key
; User pressed ENTER. Do the action
DOACT: CMP AL, MENU_EXIT ; Is EXIT highlighted?
JE XMENU1
CMP AL, MENU_STRT ; Is START GAME highlighted?
JE STARTG
CMP AL, MENU_LOAD ; Is LOAD GAME highlighted?
JE LOADG1
CMP AL, MENU_INST ; Is INSTRUCTIONS highlighted?
JE LOADINST
JMP MENU2 ; Otherwise, go back to menu
;
STARTG: LEA SI, S_ENTERN ; Load string
MOV DH, 20 ; Row
MOV DL, 6 ; Column
MOV BL, C_INTRO1 ; Color scheme
CALL PRINTSTR
ADD DL, 12 ; Place cursor after text
; Get user's name (8 character max)
MOV DI, 0 ; Offset for PLAYER string
GETCH: CALL SETCUR ; Show the cursor
MOV AH, 0 ; Get character
INT 16H
CMP AH, 1CH ; Pressed ENTER?
JNE SAVECHAR ; ... if not, store char
CMP DI, 0 ; ENTER only char pressed?
JE MENU3 ; ... if so, go back to menu
JMP CRFILE ; ... otherwise, create file
SAVECHAR:MOV PLAYER [DI], AL ; Save character
MOV CX, 1 ; Echo whatever was typed
CALL PAINT
INC DL ; Move over one column
INC DI ; Increment string offset
CMP DI, 8 ; 8 character maximum
JB GETCH ; ... keep going if below g
JMP CRFILE ; ... otherwise, create the file
; Help a brotha jump!
MENU3: JMP MENU2
XMENU1: JMP XMENU
LOADG1: JMP LOADG
;
; Load instruction screen
LOADINST: CALL INSTRUCT
JMP MENU2 ; Then go back
;
; Create saved game file
CRFILE: MOV DI, 0 ; Initialize offset
CRFNAME: MOV AL, PLAYER[DI] ; Get character
CMP AL, ' ' ; At end of name?
JE APPEND ; ... if so, add extention
MOV FNAME[DI], AL ; ... otherwise, keep getting chars
INC DI
JMP CRFNAME
; Now, add .DAT extension to filename
APPEND: MOV FNAME[DI], '.'
INC DI ; Next char
MOV FNAME[DI], 'D'
INC DI ; Next char
MOV FNAME[DI], 'A'
INC DI ; Next char
MOV FNAME[DI], 'T'
; Create file
MOV AH, 3CH ; Create file
MOV CX, 0 ; No special attributes
LEA DX, FNAME ; Load file name
INT 21H
JNC NOERR1
; If error, print error message
MOV DH, 22 ; Row
MOV DL, 6 ; Column
MOV BL, C_INTRO2 ; Color scheme
LEA SI, S_ERR1 ; Load string
CALL PRINTSTR
MOV AH, 0 ; Wait for user to press a key
INT 16H
MENU4: JMP MENU3 ; Go back
NOERR1: MOV FHANDLE, AX ; Save handle
; Save initial data
MOV AH, 40H ; Write to file
MOV BX, FHANDLE ; Load handle
MOV CX, 12 ; Write all 12 bytes in FDATA
LEA DX, FDATA ; Load FDATA string
INT 21H
; Close file
CALL CLOSEFILE ; Close the file
CALL INITFDATA ; Initialize FDATA
JMP STARTGAME ; Start the game
;
; // Done creating saved game file //
;
; Load a Game
LOADG: LEA SI, S_ENTERN ; Load string
MOV DH, 20 ; Row
MOV DL, 6 ; Column
MOV BL, C_INTRO1 ; Color scheme
CALL PRINTSTR
ADD DL, 12 ; Place cursor after text
; Get user's name (8 character max)
MOV DI, 0 ; Offset for PLAYER string
GETCH1: CALL SETCUR ; Show the cursor
MOV AH, 0 ; Get character
INT 16H
CMP AH, 1CH ; Pressed ENTER?
JNE SAVECHAR1 ; ... if not, store char
CMP DI, 0 ; ENTER only char pressed?
JE MENU4 ; ... if so, go back to menu
JMP OPFILE ; ... otherwise, create file
SAVECHAR1: MOV PLAYER [DI], AL ; Save character
MOV CX, 1 ; Echo whatever was typed
CALL PAINT
INC DL ; Move over one column
INC DI ; Increment string offset
CMP DI, 8 ; 8 character maximum
JB GETCH1
OPFILE: MOV DI, 0 ; Initialize offset
OPFNAME: MOV AL, PLAYER[DI] ; Get character
CMP AL, ' ' ; At end of name?
JE APPEND1 ; ... if so, add extention
MOV FNAME[DI], AL ; ... otherwise, keep getting chars
INC DI ; Next character
JMP OPFNAME ; Get more characters
; Now, add .DAT extension to filename
APPEND1: MOV FNAME[DI], '.'
INC DI ; Next char
MOV FNAME[DI], 'D'
INC DI ; Next char
MOV FNAME[DI], 'A'
INC DI ; Next char
MOV FNAME[DI], 'T'
; Open the file
MOV AH, 3DH ; Open file
MOV AL, 0 ; Open for reading
LEA DX, FNAME ; Load filename string
INT 21H
JC ERR2 ; Carry flag set if ERROR
MOV FHANDLE, AX ; Otherwise, save handle
; Read from the file
MOV AH, 3FH ; Read from file
MOV BX, FHANDLE ; Load handle
MOV CX, 12 ; Read all 12 bytes
LEA DX, FDATA ; Store them in FDATA (will overwrite)
INT 21H
JC ERR2 ; Error sets carry flag
JMP STARTGAME ; Otherwise, start the game!
; If error, print error message
ERR2: MOV DH, 22 ; Row
MOV DL, 6 ; Column
MOV BL, C_INTRO2 ; Color scheme
LEA SI, S_ERR2 ; Print error message
CALL PRINTSTR
MOV AH, 0 ; Wait for user to hit a key
INT 16H
JMP MENU4 ; Go back to menu
; Load level 1 and start
STARTGAME: CALL INIT ; Initialize game board
CALL PLAYBUG ; Start playing
MOV MENU_ROW, 12 ; Reset menu cursor at top
JMP MENU3 ; Go back to menu
;
XMENU: POP BX ; Return registers
POP AX
RET
MENU ENDP
; --------------------------------------------------------------------------
; CALL INSTRUCT Displays the game instructions.
; --------------------------------------------------------------------------
INSTRUCT PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
;
; First, clear the screen
MOV BL, C_INTRO1 ; Color: White on black
CALL CLS
; Now, print borders for instructions
; Start with top borders
MOV AL, 0C9H ; Top left border
MOV CX, 1 ; 1 character
MOV DH, 3 ; Row
MOV DL, 14 ; Column
CALL PAINT
MOV AL, 0CDH ; Top border characcter
MOV CX, 50 ; 50 characters
INC DL ; Move one column over
CALL PAINT
MOV AL, 0BBH ; Top right border character
MOV CX, 1 ; 1 character
ADD DL, 50 ;Move 50 columns over (after painting 50 chars)
CALL PAINT
; Now, print side borders
MOV AX, 0BAH ; Side border character
BORLP: MOV DL, 14 ; Start from left side (col 14)
INC DH ; New row
CMP DH, 20 ; At last row?
JAE PRMID ; ... if so, print middle border
CALL PAINT
MOV DL, 65 ; Now paint right side (col 65)
CALL PAINT
JMP BORLP ; Keep going
; Print middle border
PRMID: MOV AL, 0CDH ; Middle border character
MOV CX, 50 ; 50 chars
MOV DH, 14 ; Row 14
MOV DL, 15 ; Column 15
CALL PAINT
; Print bottom border
MOV AL, 0C8H ; Bottom-left border
MOV CX, 1 ; 1 character
MOV DH, 20 ; Row
MOV DL, 14 ; Column
CALL PAINT
MOV AL, 0CDH ; Bottom border characcter
MOV CX, 50 ; 50 characters
INC DL ; Move one column over
CALL PAINT
MOV AL, 0BCH ; Bottom-right border character
MOV CX, 1 ; 1 character
ADD DL, 50 ; Move 50 columns over
CALL PAINT
; Print "press any key to continue"
MOV DH, 22 ; Row
MOV DL, 50 ; Column
MOV BL, C_INTRO2 ; Color scheme
LEA SI, S_OUTRO7 ; Load string
CALL PRINTSTR
; \\ First set of instructions
; Begin with drawing the GOAL
MOV AL, '>' ; GOAL character
MOV DH, 5 ; Row
MOV DL, 38 ; Column
MOV BL, 22H ; Top part of GOAL
MOV CX, 3 ; Width 3
CALL PAINT
INC DH ; Mov down a row
I1LP: MOV BL, 0EEH ; Color scheme for '>' (blinking)
MOV CX, 2 ; 2 characters
CALL PAINT
MOV BL, 22H ; Now, paint right edge (Green)
MOV CX, 1 ; 1 character
ADD DL, 2 ; Move over 2 columns
CALL PAINT
SUB DL, 2 ; Now, move back 2 columns
INC DH ; Move down a row
CMP DH, 12 ; Done drawing?
JB I1LP
MOV BL, 22H ; Bottom part
MOV CX, 3 ; Width 3
CALL PAINT
; Now, draw the text
MOV DH, 16 ; Row
MOV DL, 22 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST1 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
CALL CLRBOXES ; Clear the box area
; \\ Second set of instructions
; Draw the BUG first
MOV AL, 'X' ; BUG character
MOV BL, C_BUG ; Color: Green on black
MOV CX, 3 ; 3 characters
MOV DH, 7 ; Row
MOV DL, 38 ; Column
CALL PAINT
INC DH ; Draw next row
CALL PAINT
INC DH ; Draw next row
CALL PAINT
INC DH ; Draw next row
CALL PAINT
SUB DH, 2 ; Draw turret (on 2nd row)
ADD DL, 3 ; Adjust column
MOV AL, '/' ; Turret character
MOV CX, 1 ; 1 char
CALL PAINT
; Now, draw the text
MOV DH, 16 ; Row
MOV DL, 20 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST2 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
; \\ Third set of instructions
; Add BRAIN to sketch
MOV AL, BRAIN ; Brain character
MOV BL, C_BRN ; Color scheme
MOV CX, 1 ; 1 character
MOV DH, 6 ; Row
MOV DL, 44 ; Column
CALL PAINT
; Now, draw the text
MOV DH, 16 ; Row
MOV DL, 20 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST3 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
CALL CLRBOXES ; Clear the box area
; \\ Fourth set of instructions
; Print RANGE label
MOV BL, C_STATUS ; Color scheme
MOV DH, 8 ; Row
MOV DL, 34 ; Column
LEA SI, S_RANGE ; Load string
CALL PRINTSTR
MOV AL, 04H ; SPADES character
MOV BL, C_RNG ; Color scheme
MOV CX, 5 ; 5 characters
ADD DL, 7 ; Column offset
CALL PAINT
; Now, draw the text
MOV DH, 16 ; Rw
MOV DL, 17 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST4 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
CALL CLRBOXES ; Clear box area
; \\ Fifth set of instructions
; Print SOUND label
MOV BL, C_STATUS ; Color scheme
MOV DH, 8 ; Row
MOV DL, 34 ; Column
LEA SI, S_SOUND ; Load string
CALL PRINTSTR
ADD DL, 7 ; Column offset
LEA SI, S_OFF ; Load string
CALL PRINTSTR
; Now, draw the text
MOV DH, 16 ; Row
MOV DL, 17 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST5 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
CALL CLRBOXES ; Clear the box area
; \\ Sixth set of instructions
; Print DELAY label
MOV BL, C_STATUS ; Color scheme
MOV DH, 8 ; Row
MOV DL, 34 ; Column
LEA SI, S_DELAY ; Load string
CALL PRINTSTR
ADD DL, 7 ; Column offset
MOV BX, 50 ; Will print DELAY: 50
CALL PRINTNUM
; Now, draw the text
MOV DH, 16 ; Row
MOV DL, 17 ; Column
MOV BL, C_INTRO1 ; Color scheme
LEA SI, S_INST6 ; Load string
CALL PRINTSTR
; Wait for a key to be pressed
MOV AH, 0 ; Wait for key
INT 16H
;
POP DX ; Return registers
POP CX
POP BX
POP AX
RET
INSTRUCT ENDP
; --------------------------------------------------------------------------
; CALL CLRBOXES Routine used to clear boxes in INSTRUCTIONS screen
; --------------------------------------------------------------------------
CLRBOXES PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
;
MOV AL, ' ' ; Print spaces
MOV BL, C_INTRO1 ; Color scheme (black)
MOV CX, 50 ; 50 chars at a time
;
MOV DH, 4 ; Row
MOV DL, 15 ; Column
; Move through all the necessary rows
CLRLP: CALL PAINT
INC DH ; Next row
CMP DH, 20 ; At last row?
JE XCLR
CMP DH, 14 ; At row 14? If so, skip (has a border drawn)
JNE CLRLP
INC DH ; ... skip
JMP CLRLP
;
XCLR: POP DX ; Return registers
POP CX
POP BX
POP AX
RET
CLRBOXES ENDP
; --------------------------------------------------------------------------
; CALL INITFDATA Initializes values in FDATA
; 1, 0FFH, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0
; --------------------------------------------------------------------------
INITFDATA PROC
;
MOV FDATA[0], 1 ; Default values
MOV FDATA[1], 0FFH
MOV FDATA[2], 50
MOV FDATA[3], 0
MOV FDATA[4], 0
MOV FDATA[5], 0
MOV FDATA[6], 0
MOV FDATA[7], 0
MOV FDATA[8], 0
MOV FDATA[9], 0
MOV FDATA[10], 0
MOV FDATA[11], 0
;
RET
INITFDATA ENDP
; --------------------------------------------------------------------------
; CALL SAVEFILE Saves game data into file pointed by FHANDLE
; This procedure will close the file automatically.
; INPUT:
; FHANDLE Game handle
; OUTPUT:
; FERR
; --------------------------------------------------------------------------
SAVEFILE PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
; Create file
MOV AH, 3CH ; Create file
MOV CX, 0 ; No special attributes
LEA DX, FNAME ; Load file name
INT 21H
; Load all the data into FDATA
MOV AL, CURLEV ; Load current level
MOV FDATA[0], AL ; Save current level
MOV AL, SOUND ; Load sound setting
MOV FDATA[1], AL ; Save sound setting
MOV AL, SPEED ; Load delay setting
MOV FDATA[2], AL ; Save delay setting
; Log attempts
MOV AX, 2 ; First level begins at position 3
ADD AL, CURLEV ; Level number will give correct offset
MOV DI, AX ; e.g. Level 4 attempts are at FDATA[6]
MOV AL, ATT
MOV FDATA[DI], AL ; Save attempts
; Write the data to file
MOV AH, 40H ; Write to file
MOV BX, FHANDLE ; Load handle
MOV CX, 12 ; Write all 12 bytes in FDATA
LEA DX, FDATA ; Load data address
INT 21H
; Close the file
CALL CLOSEFILE
;
POP DX ; Return registers
POP CX
POP BX
POP AX
RET
SAVEFILE ENDP
; --------------------------------------------------------------------------
; CALL LOADFILE Loads a game into FDATA
;
; FNAME File name
; --------------------------------------------------------------------------
LOADFILE PROC
PUSH AX ; Save registers
PUSH BX
; Open the file
MOV AH, 3DH ; Open file
MOV AL, 0 ; Open for reading
LEA DX, FNAME ; Load filename
INT 21H
MOV FHANDLE, AX ; Save handle
; Read from the file
MOV AH, 3FH ; Read from file
MOV BX, FHANDLE ; Load handle
MOV CX, 12 ; Read all 12 bytes
LEA DX, FDATA ; Load FDATA address
INT 21H
;
POP BX ; Return registers
POP AX
RET
LOADFILE ENDP
; --------------------------------------------------------------------------
; CALL CLOSEFILE Opens a game and saves handle in FHANDLE
;
; FHANDLE File name
; --------------------------------------------------------------------------
CLOSEFILE PROC
PUSH AX ; Save registers
PUSH BX
;
MOV AH, 3EH ; Close file
MOV BX, FHANDLE ; Load handle
INT 21H
;
POP BX ; Return registers
POP AX
RET
CLOSEFILE ENDP
; --------------------------------------------------------------------------
; CALL INIT Initializes screen for gameplay
;
; (No input required)
; --------------------------------------------------------------------------
INIT PROC
; Store level memory locations
LEA SI, LVL1
MOV LEVS[0], SI ; Level 1
LEA SI, LVL2
MOV LEVS[2], SI ; Level 2
LEA SI, LVL3
MOV LEVS[4], SI ; Level 3
LEA SI, LVL4
MOV LEVS[6], SI ; Level 4
LEA SI, LVL5
MOV LEVS[8], SI ; Level 5
LEA SI, LVL6
MOV LEVS[10], SI ; Level 6
LEA SI, LVL7
MOV LEVS[12], SI ; Level 7
LEA SI, LVL8
MOV LEVS[14], SI ; Level 8
LEA SI, LVL9
MOV LEVS[16], SI ; Level 9
; Load FDATA
MOV AL, FDATA[0] ; Get level number
MOV CURLEV, AL
MOV AL, FDATA[1] ; Get sound preference
MOV SOUND, AL
MOV AL, FDATA[2] ; Get delay setting
MOV SPEED, AL
MOV AX, 2 ; Now, go to current level
ADD AL, CURLEV ; ... will be FDATA[2 + CURLEV]
MOV DI, AX
MOV AL, FDATA[DI] ; Load attempts for level
MOV ATT, AL
; Did we beat the game? Show end screen
CMP CURLEV, 10
JE ENDGAME1
; Remember DOS cursor position and clear screen
MOV AH, 3 ; Read cursor pos
MOV BH, 0 ; Video page 0
INT 10H
MOV DOSC_C, DL ; Load DOS colors
MOV BL, C_DOS ; Color scheme
CALL CLS ; Clear the screen
CALL HIDEBUG ; Hide the BUG
; Paint top and bottom game borders
MOV AL, 'W' ; 'W' character
MOV DX, 0 ; Start from (0,0)
MOV CX, 80 ; 80 characters
MOV BL, C_WALL ; Color scheme
CALL PAINT
MOV DH, 24 ; Row 24
CALL PAINT
; Paint left and right game borders
MOV DH, 1 ; Begin with row 1
MOV CX, 2 ; 2 characters
PTSIDES: MOV DL, 0 ; Left side
CALL PAINT
MOV DL, 78 ; Right side
CALL PAINT
ADD DH, 1 ; New row
CMP DH, 25 ; Last column
JB PTSIDES
; Paint borders of BUG zone
MOV BL, 1111B ; Set color to white
MOV AL, 0CDH ; Top border character
MOV CX, 5 ; 5 characters
MOV DH, 1 ; Row
MOV DL, 2 ; Column
CALL PAINT
MOV AL, 0BBH ; Top-right corner character
MOV CX, 1 ; 1 character
MOV DL, 7 ; Colun
CALL PAINT
JMP SIDEB
; Help a brotha jump!
ENDGAME1: JMP ENDGAME
;
SIDEB: INC DH ; Go down, row by row
MOV AL, 0BAH ; Right border character
CALL PAINT
CMP DH, 21 ; Row
JBE SIDEB
MOV AL, 0BCH ; Bottom-right border character
INC DH ; Next row
CALL PAINT
MOV AL, 0CDH ; Bottom border character
MOV CX, 5 ; 5 characters
MOV DL, 2 ; Column
CALL PAINT
; Paint Delay label
MOV DH, 0 ; Row
MOV DL, 68 ; Column
LEA SI, S_DELAY ; Load string
MOV BL, C_STATUS ; Color scheme
CALL PRINTSTR
; Print the Delay
MOV DL, 74 ; Column
MOV BL, SPEED ; Load speed
CALL PRINTNUM
; Print Sound label
MOV DL, 3 ; Column
MOV BL, C_STATUS ; Color scheme
LEA SI, S_SOUND ; Load string
CALL PRINTSTR
; Print Sound ON/OFF
MOV DL, 10 ; Column
CMP SOUND, 0 ; Sound ON or OFF?
JE PR_OFF
LEA SI, S_ON ; Load string
CALL PRINTSTR
JMP PRLEV
PR_OFF: LEA SI, S_OFF ; Load string
CALL PRINTSTR
; Print Level label
PRLEV: MOV DH, 24
MOV DL, 31
LEA SI, S_LEVEL ; Load string
MOV BL, C_STATUS
CALL PRINTSTR
; Load Level
LEA SI, LVL1 ; Load level
CALL LOADLEV
; Print Attempts label
MOV DL, 3 ; Column
MOV BL, C_STATUS ; Color scheme
LEA SI, S_ATT ; Load string
CALL PRINTSTR
; Print range label
MOV DL, 65 ; Column
LEA SI, S_RANGE ; Load string
MOV BL, C_STATUS ; Color scheme
CALL PRINTSTR
; Print distance left
CALL PRINTRNG
; Initially place the BUG
MOV BUG_R, 5 ; Initial row
MOV BUG_C, 3 ; Initial column
CALL DRAWBUG ; Draw the bug
CALL HIDECUR ; Get rid of cursor
;
RET
INIT ENDP
; --------------------------------------------------------------------------
; CALL CLS Clears the screen
; --------------------------------------------------------------------------
CLS PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
;
MOV AL, ' ' ; Fill screen with black
MOV CX, 80*25 ; Entire screen
MOV DX, 0 ; Starting from (0,0)
CALL PAINT
;
POP DX ; Return registers
POP CX
POP BX
POP AX
RET
CLS ENDP
; --------------------------------------------------------------------------
; CALL PAINT Paints characters onto screen
;
; AL Character to print
; BL Color
; CX Number of characters to print
; DH, DL Row, column of first character
; --------------------------------------------------------------------------
PAINT PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
;
CMP CX, 0 ; If no characters, exit
JE XPAINT
CALL SETCUR ; Set cursor position
MOV BH, 0 ; Video page 0
MOV AH, 9 ; Write character
INT 10H
CALL HIDECUR
;
XPAINT: POP DX ; Return registers
POP CX
POP BX
POP AX
RET
PAINT ENDP
; --------------------------------------------------------------------------
; CALL SETCUR Sets the cursor position
;
; DH, DL Row, column of cursor
; --------------------------------------------------------------------------
SETCUR PROC
PUSH AX ; Save registers
PUSH BX
PUSH DX
;
MOV BH, 0 ; Video page 0
MOV AH, 2 ; Set cursor
INT 10H
;
POP DX ; Return registers
POP BX
POP AX
RET
SETCUR ENDP
; --------------------------------------------------------------------------
; CALL HIDECUR Hides the cursor
; --------------------------------------------------------------------------
HIDECUR PROC
PUSH AX ; Save registers
PUSH CX
PUSH DX
;
MOV DH, 25 ; Put cursor out of sight
MOV DL, 0
CALL SETCUR
;
POP DX ; Return registers
POP CX
POP AX
RET
HIDECUR ENDP
; --------------------------------------------------------------------------
; CALL HIDEBUG Temporarily hides the bug
; --------------------------------------------------------------------------
HIDEBUG PROC
MOV HIDEB, 1 ; Set HIDE to YES
CALL DRAWBUG ; and draw the bug
RET
HIDEBUG ENDP
; --------------------------------------------------------------------------
; CALL DRAWBUG Draws the bug
;
; HIDEB If set to 1, will hide the BUG instead of drawing it
; --------------------------------------------------------------------------
DRAWBUG PROC
PUSH AX ; Save registers
PUSH BX
PUSH CX
PUSH DX
;
MOV DH, BUG_R ; Set position
MOV DL, BUG_C
MOV BL, C_BUG ; Set color scheme
;
CMP HIDEB, 1 ; Hide or draw?
JNZ DRAW1 ; ... draw the bug
MOV AL, ' ' ; ... draw a blank
MOV BL, 0 ; Video page 0
JMP DRAW2
DRAW1: MOV AL, 'X' ; Character
MOV BL, C_BUG ; Color
DRAW2: MOV CX, 3 ; Number of Chars
CALL PAINT ; First row of BUG
INC DH
CALL PAINT ; Second Row
INC DH
CALL PAINT ; Third Row
INC DH
CALL PAINT ; Fourth Row
; Draw Turret
MOV DH, BUG_R ; Get BUG row
MOV DL, BUG_C ; Get BUG column
MOV CX, 1 ; 1 character
ADD DL, 3 ; Row
;
MOV AL, ' ' ; Space hides
CMP D_TUR, 0 ; UP or DOWN?
JNE DRAW4
;
CMP HIDEB, 1 ; Are we hiding?
JE DRAW3 ; If so, keep the space
MOV AL, '/' ; Sets turret UP
DRAW3: ADD DH, 1 ; Next row
CALL PAINT
JMP XDRAW
DRAW4: CMP HIDEB, 1
JE DRAW5
MOV AL, '\' ; Sets turret DOWN
DRAW5: ADD DH, 2 ; Row
CALL PAINT
;
XDRAW: MOV HIDEB, 0 ; HIDE set to no