-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrickBreakerGame.asm
1017 lines (903 loc) · 13.6 KB
/
BrickBreakerGame.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
start_game: db 0
oldisr: dd 0
colume: dw 0
row: dw 0
incC: db 0
incR: db 0
previous: dw 0
tickcount: db 0
left_edge: dw 3524
right_edge dw 3652
right_: dw 0
left_: dw 0
pre_stack_pos: dw 3580
second: dw 0
clock: db 0
bonus: dw 0
bricks_start_location: dw 810 , 828 , 846 , 864 , 882 , 900 , 918 , 936 , 1290 , 1308 , 1326 , 1344 , 1362, 1380, 1398 , 1416 , 1770 , 1788 , 1806 , 1824 , 1842 , 1860 , 1878 , 1896
bricks_end_location: dw 822 , 840 , 858 , 876 , 894 , 912 , 930 , 948 , 1302 , 1320 , 1338 , 1356 , 1374 , 1392 , 1414 , 1428 , 1782 , 1800 , 1818 , 1836 ,1854 , 1872 , 1890 , 1908
score: dw 0
total_bricks: dw 16
calculated_location: dw 0
left_limit dw 0
right_limit dw 0
mid dw 0
left_or_right: db 0
preBall:dw 0
live: db 2
end_of_game: dw 0
StayOnStacker: db 0
counter: dw 0
solid: db 0
solid1: db 0
Lose_str: db 'YOU_LOSE'
Score_str: db 'SCORE'
Lives_str: db 'LIVES'
welcome_str: db 'BRICK BREAKER'
play_str: db 'PRESS ENTER TO PLAY GAME'
total_score_str: db 'YOUR TOTAL SCORES :'
exit_str: db 'PRESS E TO EXIT'
quit_str: db 'PRESS ENTER+Q TO QUIT GAME'
restart_str: db 'PRESS ENTER+R TO RESTART YOUR GAME'
main_menu:
push ax
call clrscr
mov ax , 1010
push ax
mov ax ,welcome_str
push ax
mov ax , 13
push ax
call printstr
mov ax , 1330
push ax
mov ax , play_str
push ax
mov ax , 24
push ax
call printstr
mov ax , 1650
push ax
mov ax , exit_str
push ax
mov ax , 15
push ax
call printstr
pop ax
ret
printnum:
push bp
mov bp, sp
push es
push ax
push bx
push cx
push dx
push di
mov ax, 0xb800
mov es, ax
mov ax, [bp+4]
mov bx, 10
mov cx, 0
nextdigit: mov dx, 0
div bx
add dl, 0x30
push dx
inc cx
cmp ax, 0
jnz nextdigit
mov di, [bp+6]
nextpos: pop dx
mov dh, 0x07
mov [es:di], dx
add di, 2
loop nextpos
pop di
pop dx
pop cx
pop bx
pop ax
pop es
pop bp
ret 4
callmee:
mov ax , 1990
push ax
mov ax , Lose_str
push ax
mov ax , 8
push ax
call printstr
jmp callmee
pop ax
ret
printstr:
push bp
mov bp, sp
push es
push ax
push cx
push si
push di
mov ax, 0xb800
mov es, ax
mov di, [bp+8]
mov si, [bp+6]
mov cx, [bp+4]
mov ah, 0x07
nextchar:
mov al, [si]
mov [es:di], ax
add di, 2
add si, 1
loop nextchar
pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 6
time_str: db 'TIME '
printStrings:
push ax
mov ax , 280
push ax
mov ax , Lives_str
push ax
mov ax , 5
push ax
call printstr
mov ax , 162
push ax
mov ax , Score_str
push ax
mov ax , 5
push ax
call printstr
mov ax , 220
push ax
mov ax , time_str
push ax
mov ax , 5
push ax
call printstr
pop ax
ret
clrscr:
push es
push ax
push cx
push di
mov ax, 0xb800
mov es, ax
xor di, di
mov ax, 0x0720
mov cx, 2000
cld
rep stosw
pop di
pop cx
pop ax
pop es
ret
border:
push ax
push es
push di
mov ax,0xb800
mov es,ax
mov ah,0x90
mov al,0x20
mov di,482
l1:
mov word[es:di],ax
add di,2
cmp di,636
jne l1
cmp byte[cs:solid],1
jne nnp
mov ah,0x40
jmp npp
nnp:
mov ah,0x90
npp:
mov di,3682
l2:
mov word[es:di],ax
add di,2
cmp di,3836
jne l2
mov ah,0x60
mov al,0x20
mov di,482
l3:
mov word[es:di],ax
add di,160
cmp di,3842
jne l3
mov di,636
l4:
mov word[es:di],ax
add di,160
cmp di,3996
jne l4
pop di
pop es
pop ax
ret
brick_remove:
push es
push ax
push dx
push cx
push si
push bx
mov ax,0xb800
mov es,ax
mov cx , 24
mov si , 0
mov dx , [cs:calculated_location]
check:
mov ax , word[cs:bricks_start_location + si]
mov bx , word[cs:bricks_end_location + si]
add si , 2
cmp dx , ax
jae checknext
loop check
jmp end_ofFunc
checknext:
cmp dx , bx
jbe remove
loop check
jmp end_ofFunc
remove:
sub si , 2
mov di , word[cs:bricks_start_location + si]
mov cx , 6
mov ax , 0x0720
rep stosw
add word[cs:score] , 2
dec word[cs:total_bricks]
mov ax , 174
push ax
push word[cs:score]
call printnum
end_ofFunc:
pop bx
pop si
pop cx
pop dx
pop ax
pop es
ret
bricks:
push es
push cx
push bx
push si
push di
mov ax, 0xb800
mov es, ax
mov di, 810
mov si , 0
mov bx , 0
cld
brickline1:
cmp di , 936
ja brickline2
mov ah , 0xf0
mov al , 0x20
mov cx , 6
rep stosw
mov cx , 3
mov ax, 0x0720
rep stosw
add si , 2
jmp brickline1
brickline2:
mov di , 1290
brickline2_print:
cmp di, 1416
ja brickline3
mov ah , 0xa0
mov al , 0x20
mov cx , 6
rep stosw
mov cx , 3
mov ax, 0x0720
rep stosw
add si , 2
jmp brickline2_print
brickline3:
mov di, 1770
brickline2_print3:
cmp di, 1896
ja endn
mov ah , 0xf0
mov al , 0x20
mov cx , 6
rep stosw
mov cx , 3
mov ax, 0x0720
rep stosw
add si , 2
jmp brickline2_print3
endn:
mov di,846
mov cx,6
mov al,0x20
mov ah,0xf0
rep stosw
pop di
pop si
pop bx
pop cx
pop es
ret
clearStacker:
push bp
mov bp , sp
push es
push ax
push di
push cx
mov ax , 0xb800
mov es , ax
mov ax , 0x0720
mov cx , 13
mov di , [bp+4]
rep stosw
mov di,[cs:preBall]
mov word[es:di],ax
pop cx
pop di
pop ax
pop es
pop bp
ret 2
printStacker:
push bp
mov bp , sp
push es
push ax
push di
push cx
mov ax , 0xb800
mov es , ax
mov al , 0x20
mov ah , 0xb0
mov cx , 13
mov di , [bp+4]
mov word[cs:left_limit] , di
rep stosw
sub di , 2
mov word[cs:right_limit] , di
mov ax , word[cs:right_limit]
sub ax,12
mov word[cs:mid] , ax
sub ax,160
mov di,ax
shr ax,1
sub ax,1680
mov cx,ax
cmp byte[cs:StayOnStacker],1
jne endi
mov al,'O'
mov ah,0x07
mov word[es:di],ax
mov [cs:preBall],di
mov word[cs:row],21
mov word[cs:colume],cx
mov word[cs:previous],di
endi:
pop cx
pop di
pop ax
pop es
pop bp
ret 2
stacker:
push ax
push di
cmp word[cs:right_] , 1
je movRight
cmp word[cs:left_] , 1
je movLeft
movRight:
mov ax, word[cs:pre_stack_pos]
add ax , 8
cmp ax , word[cs:right_edge]
ja exit1
mov di, word[cs:pre_stack_pos]
push di
call clearStacker
push ax
call printStacker
mov word[cs:pre_stack_pos] , ax
jmp exit1
movLeft:
mov ax, word[cs:pre_stack_pos]
sub ax , 8
cmp ax , word[cs:left_edge]
jb exit1
mov di, word[cs:pre_stack_pos]
push di
call clearStacker
push ax
call printStacker
mov word[cs:pre_stack_pos] , ax
jmp exit1
exit1:
pop di
pop ax
ret
calculate_position:
push bp
mov bp , sp
push ax
mov al , 80
mul byte[bp+4]
add ax , [bp+6]
shl ax ,1
mov word[cs:calculated_location] , ax
pop ax
pop bp
ret 4
nextposition:
push ax
push bx
push cx
mov al,[cs:incC]
mov ah,[cs:incR]
mov bx,[cs:colume]
mov cx,[cs:row]
cmp word[cs:colume],3
jne nextcond4
mov al,1
jmp rowCheck3
nextcond4:
cmp word[cs:colume],77
jne rowCheck3
mov al,0
rowCheck3:
cmp word[cs:row],4
jne nextcond5
mov ah,1
jmp printingLocation1
nextcond5:
cmp word[cs:row],22
jne printingLocation1
mov ah,0
printingLocation1:
cmp al,1
jne nextcond6
add bx,1
jmp rowCheck4
nextcond6:
sub bx,1
rowCheck4:
cmp ah,1
jne nextcond7
add cx,1
jmp calculatelocation1
nextcond7:
sub cx,1
calculatelocation1:
push bx
push cx
call calculate_position
pop cx
pop bx
pop ax
ret
left_right:
push ax
mov ax , word[cs:calculated_location]
cmp ax , [cs:mid]
ja check_right
cmp ax , [cs:left_limit]
jb endit
mov byte[cs:left_or_right] , 0
jmp endit
check_right:
cmp ax , [cs:right_limit]
ja endit
mov byte[cs:left_or_right] , 1
jmp endit
endit:
pop ax
ret
ball:
push es
push ax
push bx
push cx
push di
mov ax,0xb800
mov es,ax
mov di,[cs:previous]
mov word[es:di],0x0720
call nextposition
mov di,[cs:calculated_location]
mov ax,word[es:di]
cmp ah,0x07
je R
cmp ah,0xb0
je n
call brick_remove
jmp n1
n:
call left_right
cmp byte[cs:left_or_right],1
jne n3
mov byte[cs:incC],1
jmp n1
n3:
mov byte[cs:incC],0
n1:
cmp byte[cs:incR],1
jne r1
mov byte[cs:incR],0
jmp R
r1:
cmp byte[cs:incR],0
jne R
mov byte[cs:incR],1
R:
cmp word[cs:colume],3
jne nextcond
mov byte[cs:incC],1
jmp rowCheck
nextcond:
cmp word[cs:colume],77
jne rowCheck
mov byte[cs:incC],0
rowCheck:
cmp word[cs:row],4
jne nextcond1
mov byte[cs:incR],1
jmp printingLocation
nextcond1:
cmp byte[cs:solid],0
jne solid12
cmp word[cs:row],22
jne printingLocation
mov byte[cs:StayOnStacker],1
mov ax,word[cs:mid]
sub ax,160
mov di,ax
shr ax,1
sub ax,1680
mov cx,ax
mov al,'O'
mov ah,0x07
mov word[es:di],ax
mov [cs:preBall],di
mov word[cs:row],21
mov word[cs:colume],cx
mov word[cs:previous],di
sub byte[cs:live],1
cmp byte[cs:live],0
jne endii
jmp endii
solid12:
cmp word[cs:row],23
jne printingLocation
mov byte[incR],0
printingLocation:
cmp byte[cs:incC],1
jne nextcond2
add word[cs:colume],1
jmp rowCheck1
nextcond2:
sub word[cs:colume],1
rowCheck1:
cmp byte[cs:incR],1
jne nextcond3
add word[cs:row],1
jmp calculatelocation
nextcond3:
sub word[cs:row],1
calculatelocation:
mov ax,word[cs:row]
mov bx,80
mul bx
add ax,word[cs:colume]
shl ax,1
mov di,ax
mov word[cs:previous],ax
mov ah,0x07
mov al,'O'
mov word[es:di],ax
endii:
pop di
pop cx
pop bx
pop ax
pop es
ret
call_instruction_menu: db 0
kbisr:
push ax
push es
mov word[cs:right_] , 0
mov word[cs:left_] , 0
mov ax, 0xb800
mov es, ax
in al, 0x60
cmp byte[start_game] , 0
jne main_game
cmp al , 0x1c
jne cmp_instruction
mov byte[start_game] , 1
jmp exit
cmp_instruction:
cmp al , 0x17
jne exit
cmp byte[start_game] , 1
jne exit
main_game:
cmp al, 0x4b
jne nextcmp
mov word[cs:left_] , 1
call stacker
jmp exit
nextcmp:
cmp al, 0x4d
jne nextcmp2
mov word[cs:right_] , 1
call stacker
jmp exit
nextcmp2:
cmp al, 0xad
jne nextcmp3
jmp exit
nextcmp3:
cmp al, 0xab
jne nextcmp4
jmp exit
nextcmp4:
cmp al,0x39
jne nextcmp5
mov byte[cs:StayOnStacker],0
jmp exit
nextcmp5:
cmp al,0xb9
jne exitcmp
jmp exit
exitcmp:
cmp al,0x12
jne quitcmp
mov byte[cs:end_game] , 1
jmp exit
quitcmp:
cmp al , 0x10
jne restartcmp
mov byte[cs:quit] , 1
jmp exit
restartcmp:
cmp al , 0x13
jne nomatch
mov byte[cs:restart] , 1
jmp exit
nomatch:
pop es
pop ax
jmp far [cs:oldisr]
exit:
mov al, 0x20
out 0x20, al
pop es
pop ax
iret
timer:
cmp byte[cs:start_game],1
jne pp
inc byte[cs:clock]
cmp byte[cs:clock],18
jne ppp
add word[cs:second],1
mov byte[cs:clock],0
ppp:
cmp byte[cs:solid],1
jne po
inc byte[cs:solid1]
cmp byte[cs:solid1],180
jne po
mov byte[cs:solid],0
po:
inc word[cs:bonus]
cmp word[cs:bonus],2160
jnbe pk
cmp word[cs:total_bricks],0
jne pk
add word[cs:score],50
pk:
push ax
mov ax , 230
push ax
mov ax , word[cs:second]
push ax
call printnum
pop ax
pp:
cmp byte[cs:StayOnStacker],0
jne endof
cmp byte[cs:start_game] , 1
jne endof
inc byte[cs:tickcount]
cmp byte[cs:tickcount], 2
jne endof
call ball
call border
mov byte[cs:tickcount],0
endof:
mov al, 0x20
out 0x20, al
iret
print_lives:
push ax
push es
mov ax , 0xb800
mov es , ax
mov cx , 3
mov ax , 0x0720
mov di , 292
rep stosw
mov cl , byte[cs:live]
mov ch , 0
mov ah , 0x07
mov al , '*'
mov di , 292
rep stosw
pop es
pop ax
ret
oldtmr: dd 0
end_game: db 0
start:
xor ax, ax
mov es, ax
mov ax, [es:9*4]
mov [oldisr], ax
mov ax, [es:9*4+2]
mov [oldisr+2], ax
mov ax, [es:8*4]
mov [oldtmr], ax
mov ax, [es:8*4+2]
mov [oldtmr+2], ax
cli
mov word [es:9*4], kbisr
mov [es:9*4+2], cs
mov word [es:8*4],timer
mov [es:8*4+2],cs
sti
call main_menu
menu_loop:
cmp byte[start_game] , 0
je menu_loop
cmp byte[end_game] , 1
je endgame
start_game_here:
mov byte[restart] , 0
mov byte[quit] , 0
call clrscr
call printStrings
call print_lives
mov ax , 174
push ax
push word[score]
call printnum
call bricks
mov byte[StayOnStacker],1
call stacker
game_inner_loop:
cmp word[total_bricks] , 0
je endgame
cmp byte[end_game] , 1
je endgame
cmp byte[live] , 0
je endgame
jmp game_inner_loop
instruction:
again_ins:
cmp byte[start_game] , 1
je start_game_here
jne again_ins
endgame:
mov byte[start_game] , 0
call last_menu
call clrscr
cmp byte[restart] , 1
je start_game_here
mov ax , [oldisr]
mov bx , [oldisr+2]
mov cx , [oldtmr]
mov dx , [oldtmr+2]
cli
mov [es:9*4] , ax
mov [es:9*4+2], bx
mov [es:8*4] , cx
mov [es:8*4+2], dx
sti
mov ax , 0x4c00
int 0x21
restart: db 0
quit: db 0
variable: dw 0
last_menu:
push ax
call clrscr
cmp byte[live] , 1
jne check_win
mov ax , 1990
push ax
mov ax , Lose_str
push ax
mov ax , 8
push ax
call printstr
check_win:
cmp word[total_bricks] , 0
jne no_results
mov ax , 1990
push ax
mov ax , Lose_str
push ax
mov ax , 8
push ax
call printstr
no_results:
call last_menu_display
what_nxt:
cmp byte[cs:restart] , 1
je do_restart
cmp byte[cs:quit] , 1
je go_quit
jmp what_nxt
go_quit:
pop ax
ret
do_restart:
pop ax
mov word[second] , 0
mov byte[clock] , 0
mov byte[start_game] , 1
mov word[total_bricks] , 24
mov byte[live] , 3
mov word[score] , 0
mov byte[end_game] , 0
mov word[bonus] , 0
ret
last_menu_display:
push ax
mov ax , 1010
push ax
mov ax ,total_score_str
push ax
mov ax , 17
push ax
call printstr
mov ax , 1052
push ax
push word[score]
call printnum
mov ax , 1330
push ax