-
Notifications
You must be signed in to change notification settings - Fork 0
/
Space Shooter.asm
1978 lines (1592 loc) · 24 KB
/
Space Shooter.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
[org 0x0100]
jmp start
bg: db 0x70
gname: db 'CATCH IT',0
gnameclr: db 0x07 ;
gnamecorstrt: dw 1,34
gnamecor: dw 4,34
block1: dw 0x0720 ;29b2
block1cor: dw 2,4
mclr: db 0xC0
m: db 'Game Instructions',0
m1: db 'Press <- to move left or -> to move right',0
m2: db '- RED object: 15 points',0
m3: db '- BLUE object: 10 points',0
m4: db '- GREEN object: 5 points',0
m5: db '- Avoid hitting bomb',0
m6: db '- You have total 120 seconds',0
m7: db 'Press ENTER to start',0
;end var
block1corend: dw 7,18
mclrend: db 0x7B
mend: db 'GAME OVER',0
m1end: db 'Your Score: ',0
m2end: db 'Red Object (15 pts): ',0
m3end: db 'Blue Object (10 pts): ',0
m4end: db 'Green Object (5 pts): ',0
m5end: db 'You CATCHED: ',0
goclr: db 0xF0
;----game scrren var-----------
scoreline: db 'Score::',0
scorelinecor: dw 4,62
score: dw 0 ;block1corx+1
robj: dw 0
bobj: dw 0
gobj: dw 0
scorecor: dw 4,69
timeline: db 'Time:',0
timelinecor: dw 4,7
time: dw 120 ;block1corx+1
timecor: dw 4,12
timeisr: dd 0 ;for saving
countfortime: dw 0
bucketcoor: dw 20,40
int9isr: dd 0
endofgame: dd 0
counterforscroll: dw 0
counterforobjgen: dw 0
counterfornewobj: dw 0
;*******FUNCTIONS********
strlen: push bp
mov bp,sp
;push ax ;result return in ax
push bx
push cx
push dx
push si
push di
mov ax,0
les di,[bp+4]
xor al,al
mov cx,0xffff
cld
repne scasb
mov ax,0xffff
sub ax,cx
dec ax ;decrement extra sapce for 0
pop di
pop si
pop dx
pop cx
pop bx
;pop ax
pop bp
ret 4
locgen: push bp
mov bp,sp
;push ax ;result return in ax
push bx
push cx
push dx
push si
push di
mov ax,0;just a precaution
mov al,80
mul byte [bp+6];x
add ax,[bp+4];y
shl ax,1
pop di
pop si
pop dx
pop cx
pop bx
;pop ax
pop bp
ret 4
;------------------------START SCREEN--------------
startprint:
push bp
mov bp,sp
push es
push ax
push bx
push cx
push dx
push si
push di
;setting bg
mov ax,0xb800
mov es,ax
mov cx,2000
mov ah,[bg]
mov al,0x20
mov di,0
cld
rep stosw ;background set
;print 1st line
push ds
mov si,gname
push si
call strlen
mov cx,ax ;len in cx
push word [gnamecorstrt];x
push word [gnamecorstrt+2];y
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,[gnameclr]
mov si,gname
nameloopstart: lodsb
stosw
loop nameloopstart
;border start line
push word [block1cor];x
push word [block1cor+2];y
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ax,[block1]
mov cx,72
rep stosw
;;;;;;;;;;small border print
mov si,17
mov dx,[block1cor]
bbprintstart:
add dx,1
push dx
push word [block1cor+2];y
call locgen
mov di,ax ;loc in di
mov cx,2
mov ax,[block1]
rep stosw
push dx
mov bx,74
push bx
call locgen
mov di,ax
mov cx,2
mov ax,[block1]
rep stosw
dec si
jnz bbprintstart
;border endline
add dx,1
push dx
push word [block1cor+2];y
call locgen
mov di,ax ;loc in di
mov cx,72
mov ax,[block1]
rep stosw
;line 0
push ds
mov si,m
push si
call strlen
mov cx,ax ;len in cx
mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 30
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x07
mov si,m
mloop: lodsb
stosw
loop mloop
;;;;;;;;;;;
;line 1
push ds
mov si,m1
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 18
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0xF0
mov si,m1
m1loop: lodsb
stosw
loop m1loop
;;;;;;;;;;
;line 2
push ds
mov si,m2
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 10
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x74
mov si,m2
m2loop: lodsb
stosw
loop m2loop
;;;;;;;;;;;;
;line 3
push ds
mov si,m3
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 10
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x79
mov si,m3
m3loop: lodsb
stosw
loop m3loop
;;;;;;;;;;;;
;line 4
push ds
mov si,m4
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 10
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x72
mov si,m4
m4loop: lodsb
stosw
loop m4loop
;;;;;;;;;;;;
;line 5
push ds
mov si,m5
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 10
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,[bg]
mov si,m5
m5loop: lodsb
stosw
loop m5loop
;;;;;;;;;;
;line 6
push ds
mov si,m6
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 10
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,[bg]
mov si,m6
m6loop: lodsb
stosw
loop m6loop
;;;;;;;;;;
;line 7
push ds
mov si,m7
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1cor]
add dx,2
push dx
;mov bx,10
push 30
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x87
mov si,m7
m7loop: lodsb
stosw
loop m7loop
;;;;;;;;;;
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop es
pop bp
ret
;--------------------------------------------------
;-------------END SCREEN---------------------------------
endprint:
push bp
mov bp,sp
push es
push ax
push bx
push cx
push dx
push si
push di
;setting bg
mov ax,0xb800
mov es,ax
mov cx,2000
mov ah,[bg]
mov al,0x20
mov di,0
cld
rep stosw ;background set
;====================================
;print 1st line
push ds
mov si,gname
push si
call strlen
mov cx,ax ;len in cx
push word [gnamecor];x
push word [gnamecor+2];y
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x07
mov si,gname
nameloopend:
lodsb
stosw
loop nameloopend
;====================================
;border start line
push word [block1corend];x
push word [block1corend+2];y
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ax,[block1]
mov cx,40
rep stosw
;====================================
;small border print
mov si,14
mov dx,[block1corend]
;====================================
bbprintend:
add dx,1
push dx
push word [block1corend+2];y
call locgen
mov di,ax ;loc in di
mov cx,2
mov ax,[block1]
rep stosw
push dx
mov bx,56
push bx
call locgen
mov di,ax
mov cx,2
mov ax,[block1]
rep stosw
dec si
jnz bbprintend
;====================================
;border endline
add dx,1
push dx
push word [block1corend+2];y
call locgen
mov di,ax ;loc in di
mov cx,40
mov ax,[block1]
rep stosw
;====================================
;line GameOver
push ds
mov si,mend
push si
call strlen
mov cx,ax ;len in cx
mov dx,[block1corend]
add dx,2
push dx
;mov bx,10
push 33
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,[goclr]
mov si,mend
mendloop:
lodsb
stosw
loop mendloop
;====================================
;line Score
push ds
mov si,m1end
push si
call strlen
mov cx,ax ;len in cx
;mov dx,[block1corend]
add dx,2
push dx
;mov bx,10
push 30
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,[bg]
mov si,m1end
m1endloop:
lodsb
stosw
loop m1endloop
;====================================
;High Score Variable
mov ax,[score]
mov bx,10
mov dx,0
mov cx,0
nextdigitend:
mov dx,0
div bx
add dl, 0x30
push dx
inc cx
cmp ax,0
jnz nextdigitend
nextposend:
pop dx
mov dh,[bg]
mov [es:di],dx
add di,2
loop nextposend
;====================================
;You Catched
push ds
mov si,m5end
push si
call strlen
mov cx,ax ;len in cx
mov dx,[block1corend]
add dx,6
push dx
;mov bx,10
push 31
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x07
mov si,m5end
m5endloop:
lodsb
stosw
loop m5endloop
;====================================
;====================================
;RED
push ds
mov si,m2end
push si
call strlen
mov cx,ax ;len in cx
add dx,2
push dx
;mov bx,10
push 26
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x74
mov si,m2end
m2endloop:
lodsb
stosw
loop m2endloop
;====================================
;RED obj
mov ax,[robj]
mov bx,10
mov dx,0
mov cx,0
nextdigitend1:
mov dx,0
div bx
add dl, 0x30
push dx
inc cx
cmp ax,0
jnz nextdigitend1
nextposend1:
pop dx
mov dh,0x74
mov [es:di],dx
add di,2
loop nextposend1
;====================================
;====================================
;Blue
push ds
mov si,m3end
push si
call strlen
mov cx,ax ;len in cx
mov dx,[block1corend]
add dx,10
push dx
;mov bx,10
push 26
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x79
mov si,m3end
m3endloop:
lodsb
stosw
loop m3endloop
;====================================
;Blue obj
mov ax,[bobj]
mov bx,10
mov dx,0
mov cx,0
nextdigitend2:
mov dx,0
div bx
add dl, 0x30
push dx
inc cx
cmp ax,0
jnz nextdigitend2
nextposend2:
pop dx
mov dh,0x79
mov [es:di],dx
add di,2
loop nextposend2
;====================================
;Green
push ds
mov si,m4end
push si
call strlen
mov cx,ax ;len in cx
mov dx,[block1corend]
add dx,12
push dx
;mov bx,10
push 26
call locgen
mov di,ax ;loc in di
mov ax,0xb800
mov es,ax
mov ah,0x72
mov si,m4end
m4endloop:
lodsb
stosw
loop m4endloop
;====================================
;Blue obj
mov ax,[gobj]
mov bx,10
mov dx,0
mov cx,0
nextdigitend3:
mov dx,0
div bx
add dl, 0x30
push dx
inc cx
cmp ax,0
jnz nextdigitend3
nextposend3:
pop dx
mov dh,0x72
mov [es:di],dx
add di,2
loop nextposend3
;====================================
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop es
pop bp
ret
;====================================
;--------------------------------------------------
;-------------GAME---------------------------------
point5obj: push bp
mov bp,sp
sub sp,2
push es
push ax
push bx
push cx
push dx
push si
push di
mov ax,0xb800
mov es,ax
push word [bp+6] ;x
push word [bp+4] ;y
call locgen
mov [bp-2],ax ;di
mov di,ax
mov cx,3
mov ah,0x72
mov al,'*'
rep stosw
mov di,[bp-2]
add di,160 ;move 1 line
mov [es:di],ax
add di,4
mov [es:di],ax
mov di,[bp-2]
add di,320 ;move 2 line
mov cx,2
mov ah,0x7A
rep stosw
;add di,2
mov [es:di],ax
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop es
mov sp,bp
pop bp
ret 4 ;x y coor
;;;;;;;;;;;;;;;;10obj;;;;;;;;;;;;;;;;;
point10obj: push bp
mov bp,sp
sub sp,2
push es
push ax
push bx
push cx
push dx
push si
push di
mov ax,0xb800
mov es,ax
push word [bp+6] ;x
push word [bp+4] ;y
call locgen
mov [bp-2],ax ;di
mov di,ax
mov cx,3
mov ah,0x71
mov al,'*'
rep stosw
mov di,[bp-2]
add di,160 ;move 1 line
mov [es:di],ax
add di,4
mov [es:di],ax
mov di,[bp-2]
add di,320 ;move 2 line
mov cx,2
mov ah,0x79
rep stosw
;add di,2
mov [es:di],ax
pop di
pop si
pop dx
pop cx
pop bx
pop ax
pop es
mov sp,bp
pop bp
ret 4 ;x y coor
;;;;;;;;;;point15obj;;;;;;;;;;;;;;;
point15obj: push bp
mov bp,sp
sub sp,2
push es
push ax
push bx
push cx
push dx
push si
push di
mov ax,0xb800
mov es,ax
push word [bp+6] ;x
push word [bp+4] ;y
call locgen
mov [bp-2],ax ;di
mov di,ax
mov cx,3
mov ah,0x74
mov al,'*'
rep stosw
mov di,[bp-2]
add di,160 ;move 1 line
mov [es:di],ax
add di,4
mov [es:di],ax
mov di,[bp-2]
add di,320 ;move 2 line
mov cx,2
mov ah,0x7C
rep stosw
;add di,2
mov [es:di],ax