-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtari Breakout COAL Project.asm
1327 lines (1061 loc) · 31.7 KB
/
Atari Breakout COAL Project.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
;for myRand
fab: dw 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765 ;20 in total
fabIndex: dw 0 ;which fabonaicii number to send next
underlineW1: db '/\/\/\/\/\/\/\/\/\/\/\/\/' , 0
w1: db 'WELCOME TO ATARI BREAKOUT', 0 ;welcome screen messages
w2: db '-> Use arrow keys to move the bar',0
w3: db '-> You must not let the ball fall or you loose a life',0
w4: db '-> You have five lives',0
w5: db '-> You must break all blocks in the game to win',0
w6: db 'Press any key to play',0
w7: db 'Press escape to exit',0
border: db '*',0
e1: db 'THANKYOU FOR PLAYING ATARI BREAKOUT',0 ;exit screen messages
;left most x cordinate of the bar
barPos: dw 30 ;bar length is 20 words
;ball data
;bools to determine if to add or substract 1 from the x and y cordinates to calculate next position
boolX: db 0 ;0=+1 1=-1
boolY: db 1
;ball cordinates
ballX: dw 40 ;col
ballY: dw 22 ;row
;to store old keyboard old isr
oldisr: dd 0
score: dw 0
scoreText: db 'SCORE: ',0
lives: db '5'
livesText: db 'LIVES: ',0
quit: db 'YOU QUIT!',0
lost: db 'GAME OVER YOU LOSE!',0
win: db 'WELL PLAYED YOU WIN!',0
;total number of bricks in the game to comapre with to see if player has won
totalBricks: dw 0
myName: db 'DEVELOPED BY EEMAAN',0
;----------------------------------------------------------------------------------
;function to clear the screen by printing black spaces
clrscr:
push es
push ax
push di
mov ax, 0xb800
mov es, ax ; point es to video base
mov di, 0 ; point di to top left column
nextloc: mov word [es:di], 0x0720 ; clear next char on screen
add di, 2 ; move to next screen location
cmp di, 4000 ; has the whole screen cleared
jne nextloc ; if no clear next position
pop di
pop ax
pop es
ret
;---------------------------------------------------------------------------------
;function to calculate random number with system time and send back in dx
rand:
;mov dx,8
push ax
push bx
push cx
push es
push bp
push di
push si
mov bx,dx ; saving prev dx
randloop: MOV AH, 00h ; interrupts to get system time
INT 1Ah ; CX:DX now hold number of clock ticks since midnight
mov ax, dx
xor dx, dx
mov cx, 9
div cx ; here dx contains the remainder of the division - from 0 to 9
add dx, 10 ;range: 10 to 15
cmp dx,bx ; comaring new dx with old that is stored in bx
je randloop ; find rand again if same so consective blocks have different lengths
pop si
pop di
pop bp
pop es
pop cx
pop bx
pop ax
ret
;--------------------------------------------------------------------------------
;function to make cx even if its odd
makeCXeven:
push bx
mov bx,cx ;saving value of cx
shr cx,1
jnc evenCX
add bx,1 ;making value of cx even if was odd
evenCX: mov cx,bx ;restoring value of cx
pop bx
ret
;---------------------------------------------------------------------------------
;before every brick a rand must be called so add 1 to brick count then call rand
countAndRand:
add word[totalBricks],1
call rand
ret
;---------------------------------------------------------------------------------
;function that recives row number and color of blocks and prints them in diffreent sizes in the whole row
print_blocks:
push bp
mov bp,sp
push ax
;push dx
push cx
push es
push di
push bx
mov ax, 0xb800
mov es, ax
mov al, 80 ; load al with columns per row
mul byte [bp+6] ; 80 x r
shl ax, 1 ; byte no ((80xr)x2)
mov di, ax ; point di to row start
mov bx,ax
add bx,160 ;indicates end of row
mov ah,byte[bp+4] ;loads attribute in ah
mov al,0x20 ;space ascii
mov cx,di ; cx to start of row
call countAndRand
add cx,dx ;this controls length of 1st rectangle
call makeCXeven
nextchar: mov word [es:di], ax
here: add di, 2
cmp di,bx ;bx has end of row
jae goback ;stop printing and return if end of row is reached
cmp di,cx
jna nextchar
call countAndRand
add cx,dx ;this controls length of next rectangle
call makeCXeven
mov ah, 0x00 ;attributes of black space (diffrent from other black spaces so that ball can bounce back from here)
mov word [es:di], ax ; print black space
mov ah,[bp+4] ;restoring coloured atribute to print next block
jmp here
goback: pop bx
pop di
pop es
pop cx
;pop dx ;dx is not saved and restored in this subroutine because we need the value of dx in next calls
pop ax
pop bp
ret 4
;------------------------------------------------------------------------------------
;function that recives x y cordinates of ball and prints ball there
print_ball:
push ax
push es
push di
mov ax, 0xb800
mov es, ax
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, word[ballX] ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
mov ah, 0x0F ;white
mov al, 'o' ;o ascii
mov word [es:di], ax
pop di
pop es
pop ax
ret
;------------------------------------------------------------------------------------
;function that recives x cordinate of left side of bar and prints bar of length 20 in 23rd row
print_bar:
push ax
push es
push di
push cx
mov ax,0xb800
mov es,ax
mov al, 80
mov cl, 23 ;row
mul cl
add ax, word[barPos] ;column
shl ax,1
mov di,ax
mov ah, 0x18 ;blue
mov al, 0x20 ;space
mov cx,20
l1: cmp cx,11 ;differnt color to indicate middle
je changeBar
cmp cx,10
je changeBar
barChanged: mov word [es:di], ax
add di, 2
mov ah,0x18 ;restore old attribute if changed
loop l1
pop cx
pop di
pop es
pop ax
ret
changeBar: mov ah,0xB0
jmp barChanged
;------------------------------------------------------------------------------------
;loop to create a delay in the execution
delay:
push cx
mov cx, 0xffff
delayloop1: loop delayloop1
mov cx, 0xffff
delayloop2: loop delayloop2
mov cx, 0xffff
delayloop3: loop delayloop3
pop cx
ret
;------------------------------------------------------------------------------------
;function to print a string by reciving attributes text and cordinates
printStr:
push bp
mov bp, sp
push es
push ax
push cx
push si
push di
push ds
pop es ; es = ds
mov di, [bp+4] ; point di to string... es:di -->"Hello World"
mov cx, 0xffff ; load maximum number in cx
xor al, al ; load a zero in al
repne scasb ; find zero in the string
mov ax, 0xffff ; load maximum number in ax
sub ax, cx ; find change in cx
dec ax ; exclude null from length ; ffff - cx - 1 = 11 (strlen)
jz exit ; no printing if string is empty
mov cx, ax ; load string length in cx
mov ax, 0xb800
mov es, ax ; point es to video base
mov al, 80 ; load al with columns per row
mul byte [bp+8] ; multiply with y position
add ax, [bp+10] ; add x position
shl ax, 1 ; turn into byte offset
mov di,ax ; point di to required location
mov si, [bp+4] ; point si to string
mov ah, [bp+6] ; load attribute in ah
cld ; auto increment mode
.nextchar: lodsb ; load next char in al
stosw ; print char/attribute pair
loop .nextchar ; repeat for the whole string
exit: pop di
pop si
pop cx
pop ax
pop es
pop bp
ret 8
;------------------------------------------------------------------------------------
;function that prints all the messages on the welcome prompt screen
welcome:
push ax
push cx
push bx
call clrscr
mov cx,79
mov bx,1
topborder: push bx ; push column
mov ax, 0
push ax ; push row
mov ax, 0x8F ; white on black blinking
push ax ; push attribute
mov ax, border
push ax ; push address of message
call printStr
add bx,1
loop topborder
mov cx,79
mov bx,1
bottomborder:
push bx ; push column
mov ax, 24
push ax ; push row
mov ax, 0x8F ; white on black blinking
push ax ; push attribute
mov ax, border
push ax ; push address of message
call printStr
add bx,1
loop bottomborder
mov ax, 27
push ax ; push column
mov ax, 3
push ax ; push row
mov ax, 4 ; red on black
push ax ; push attribute
mov ax, w1
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 27
push ax ; push column
mov ax, 4
push ax ; push row
mov ax, 0x89 ; blue on black blinking
push ax ; push attribute
mov ax, underlineW1
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 3
push ax ; push column
mov ax, 9
push ax ; push row
mov ax, 13 ; magenta
push ax ; push attribute
mov ax, w2
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 3
push ax ; push column
mov ax, 10
push ax ; push row
mov ax, 13 ; magenta
push ax ; push attribute
mov ax, w3
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 3
push ax ; push column
mov ax, 11
push ax ; push row
mov ax, 13 ; magenta
push ax ; push attribute
mov ax, w4
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 3
push ax ; push column
mov ax, 12
push ax ; push row
mov ax, 13 ; magenta
push ax ; push attribute
mov ax, w5
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 29
push ax ; push column
mov ax, 17
push ax ; push row
mov ax, 14 ; yellow
push ax ; push attribute
mov ax, w6
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 29
push ax ; push column
mov ax, 18
push ax ; push row
mov ax, 14 ; yellow
push ax ; push attribute
mov ax, w7
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 60
push ax ; push column
mov ax, 22
push ax ; push row
mov ax, 11 ; cyan
push ax ; push attribute
mov ax, myName
push ax ; push address of message
call printStr ; call the printstr subroutine
pop bx
pop cx
pop ax
ret
;------------------------------------------------------------------------------------
;function to print thankyou message and exit
clrExit: call clrscr
exitGame:
mov ax, 22
push ax ; push column
mov ax, 14
push ax ; push row
mov ax, 14 ; yellow
push ax ; push attribute
mov ax, e1
push ax ; push address of message
call printStr ; call the printstr subroutine
mov ax, 60
push ax ; push column
mov ax, 21
push ax ; push row
mov ax, 11 ; cyan
push ax ; push attribute
mov ax, myName
push ax ; push address of message
call printStr ; call the printstr subroutine
mov sp,0xfffe
mov ax, 0x4c00 ; terminate program
int 0x21
;------------------------------------------------------------------------------------
;function to print message of loosing game
lostExit:
call clrscr
call printLives
call printScore
mov ax, 30
push ax ; push column
mov ax, 10
push ax ; push row
mov ax, 12 ; red
push ax ; push attribute
mov ax, lost
push ax ; push address of message
call printStr ; call the printstr subroutine
jmp unhookexit
;------------------------------------------------------------------------------------
;function to print massage of winning game
winExit:
call clrscr
call printLives
call printScore
mov ax, 30
push ax ; push column
mov ax, 10
push ax ; push row
mov ax, 12 ; red
push ax ; push attribute
mov ax, win
push ax ; push address of message
call printStr ; call the printstr subroutine
jmp unhookexit
;------------------------------------------------------------------------------------
;function to print message of quitting is esc is pressed after game has been started
quitExit:
call clrscr
call printLives
call printScore
mov ax, 35
push ax ; push column
mov ax, 10
push ax ; push row
mov ax, 12 ; red
push ax ; push attribute
mov ax, quit
push ax ; push address of message
call printStr ; call the printstr subroutine
jmp unhookexit
;------------------------------------------------------------------------------------
;function to unhook the keyboard inturrpt
unHook:
push ax
push bx
push es
xor ax,ax
mov es,ax
mov ax, [oldisr] ; read old offset in ax
mov bx, [oldisr+2] ; read old segment in bx
cli ; disable interrupts
mov [es:9*4], ax ; restore old offset from ax
mov [es:9*4+2], bx ; restore old segment from bx
sti ; enable interrupts
pop es
pop bx
pop ax
ret
;------------------------------------------------------------------------------------
;function to call unhooking function and then exit function
unhookexit:
call unHook
jmp exitGame
;------------------------------------------------------------------------------------
;function to print the start of the game by calling functions of ball, bar, bricks, score and lives printing
startGame:
call clrscr
call printLives
call printScore
push dx
push 2 ;row [bp+6]
push 0x48 ;color attribute
call print_blocks
push 4 ;row
push 0x68
call print_blocks
push 6 ;row
push 0x58
call print_blocks
push 8 ;row
push 0xA8
call print_blocks
pop dx
call print_ball
call print_bar
ret
;------------------------------------------------------------------------------------
;function to erase the brick from screen that was hit
;cordinates are not current but next
;remove brick and make the spaces on its side normal so ball can move into them
clrBrick:
push ax
push es
push di
push bx
push cx
mov ax, 0xb800
mov es, ax
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, word[ballX] ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
cmp word[es:di],0x0020
jne oneBrick
add word[score],1 ;center of two bricks was hit so add extra score
call brickSound
call delay
oneBrick: call brickSound
call delay
mov ax, 0x0720 ;normal attribute of clear screen
mov word [es:di], ax ;delete word that was hit
mov bx,word[ballX] ;move postion that was hit to bx
checkLeft: sub bx,1 ;checking left
cmp bx,0 ;checking for screen left edge
jb checkRight
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, bx ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
mov ax, 0x0720 ;normal attribute of clear screen
cmp word [es:di], 0x0020 ;check if brick side
je delRight
cmp word[es:di],0x0720 ;check if brick has ended
je checkRight
mov word [es:di],ax ;if not end then still the brick that was hit so delete
jmp checkLeft
delRight: mov word[es:di],ax ;was brick side so clear and then strat checking right
checkRight: ;left side of brick deleted now delete right
mov bx,word[ballX] ;load the point that was hit in bx again
rightLoop: add bx,1 ;go right
cmp bx,79 ;check screen right edge
ja blockDeled
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, bx ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
mov ax, 0x0720 ;normal attribute of clear screen
cmp word [es:di], 0x0020 ;check if brick side
je delRet
cmp word[es:di],0x0720 ;check if brick has ended
je blockDeled
mov word [es:di],ax ;if not end then we're still inside brick that was hit so delete word
jmp rightLoop
delRet: mov word[es:di],ax ;edge of brick is reached so clear it and return
blockDeled: pop cx ;block completely deleted so return
pop bx
pop di
pop es
pop ax
ret
;------------------------------------------------------------------------------------
;function of erasing the bar on the screen so a new one can be printed later
clrBar:
push ax
push es
push di
push cx
mov ax,0xb800
mov es,ax
mov al, 80
mov cl, 23 ;row
mul cl
add ax, word[barPos] ;column
shl ax,1
mov di,ax
mov ah, 0x07 ;black
mov al, 0x20 ;space
mov cx,20
.l1: mov word [es:di], ax
add di, 2
loop .l1
pop cx
pop di
pop es
pop ax
ret
;------------------------------------------------------------------------------------
;function that is hooked with keyboard inturrput that according to key codes moves the bar or exits
moveBar:
push ax
in al, 0x60
cmp al,0x01 ;esc
je quitExit
cmp al, 0x4D
je rightarrow
cmp al, 0x4B
je leftarrow
jmp nomatch
rightarrow:
cmp word[barPos],60
je nomatch
cmp word[ballY],23
je nomatch
call clrBar
add word[barPos],1
call print_bar
jmp nomatch
leftarrow:
cmp word[barPos],0
je nomatch
cmp word[ballY],23
je nomatch
call clrBar
sub word[barPos],1
call print_bar
jmp nomatch
nomatch:
pop ax
jmp far [cs:oldisr] ; call the original ISR
ret
;------------------------------------------------------------------------------------
;function to calculate the next coordinates of ball
nextXY:
cmp byte[boolX],0
je addX
sub word[ballX],1
jmp changeY
addX: add word[ballX],1
changeY: cmp byte[boolY],0
je addY
sub word[ballY],1
jmp changedXY
addY: add word[ballY],1
changedXY: ret
;------------------------------------------------------------------------------------
;prev coordinates of ball
prevXY:
cmp byte[boolX],0
je subX
add word[ballX],1
jmp ChangeY
subX: sub word[ballX],1
ChangeY: cmp byte[boolY],0
je subY
add word[ballY],1
jmp ChangedXY
subY: sub word[ballY],1
ChangedXY: ret
;------------------------------------------------------------------------------------
;function that tells wetaher the next cordinates calculated are inside are bounds and ball can move onto them
;set ax to 1 if ball can move at coordinates else 0
canmove:
push es
push di
mov ax, 0xb800
mov es, ax ; point es to video base
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, word[ballX] ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
mov ah, 0x07 ;black
mov al, 0x20 ;space
cmp word [es:di], ax ; is next ball position black space
je yes ; then ball can move there
mov ax,0 ;ax=0 ball cannot move
pop di
pop es
ret
yes: mov ax,1
pop di
pop es
ret
;------------------------------------------------------------------------------------
;function to erase the ball so it can be reprinted at next position
clrBall:
push ax
push es
push di
mov ax, 0xb800
mov es, ax
mov ax, 80 ; load al with columns per row
mul word [ballY] ; 80 x r
add ax, word[ballX] ; ((80xr)+c)
shl ax, 1 ; byte no (((80xr)+c)x2)
mov di, ax
mov ah, 0x07 ;black
mov al, 0x20 ;space
mov word [es:di], ax
pop di
pop es
pop ax
ret
;------------------------------------------------------------------------------------
;function with infinite loop that keeps moving the ball around the screen by calling appropriate functions
moveBall:
cmp word[ballX],79
je rightHit
cmp word[ballX],0
je leftHit
cmp word[ballY],23
je bottomHit
cmp word[ballY],1 ;row 0 is for scores and lives
je topHit
goToNext2:
cmp word[ballY],1 ;checking here again
je topHit
goToNext3:
call nextXY ; get next postion of ball
call canmove ; check if ball can move to this next position
cmp ax,0
je barHit ;cant move there because coloured block that is either brick or bar
call prevXY ;get curreent position of ball back
goToNext:
call delay
call delay
call clrBall ; erase ball from there
call nextXY ; get next postion of ball
call print_ball ; print ball at new postion
jmp moveBall
topHit: call topBounce
call hitSound
jmp goToNext3
barHit:
cmp word[ballY],23 ; check if hit was at brick or bar
jne brickHit ; bar is at 23Y so if next pos is not at 23Y then it was brick hit
call hitSound
call prevXY ;get current ball postion
call barBounce
cmp ax,1 ;was mid hit called
je moveBall ;ball has already been moved so go to top
jmp goToNext ;normal procedure after direction change
brickHit:
call clrBrick
call prevXY ; get curr position of ball
call topBounce
add word[score],1
call printScore
mov ax,word[totalBricks]
cmp word[score],ax
je winExit
jmp goToNext2
rightHit: call hitSound
call rightBounce
jmp goToNext2 ;ball can have only one type of hit so dont check for other types just move the ball
leftHit: call hitSound
call leftBounce
jmp goToNext2
bottomHit:
call bottomBounce
sub byte[lives],1
call printLives
call lifeSound
cmp byte[lives],'0'
je lostExit
call delay
call delay
call delay
call delay
call delay
call delay
jmp goToNext
;-----------------------------------------------------------------------------------
;bounce functions change direction of movement according to place of bounce
;these functions chnage the values in boolX and boolY
;-----------------------------------------------------------------------------------
;mid of bar= pos+9 and bar pos+10
;left of bar= <pos+9
;right of bar= >pos+10
;move 1 to ax if bounce was mid bounce and 0 if not
barBounce:
mov ax,word[barPos]
add ax,9 ;pos+9
cmp word[ballX],ax
je midHit
add ax,1 ;pos+10
cmp word[ballX],ax
je midHit
cmp word[ballX],ax ;>pos+10
ja barRight
jmp barLeft
midHit: ;movememt here is in 90 degree angle
sub word[ballY],1 ;move up by one row and repeat until either brick or top is reached
cmp word[ballY],1 ;check if top edge is reached
je end2
call canmove ;check if there is no block
cmp ax,0
je end1
add word[ballY],1 ;go to where ball is currently
call delay
call delay
call clrBall ;delete ball
sub word[ballY],1 ;move up by one row
call print_ball ;print new ball
jmp midHit
barRight: mov byte[boolX],0 ;go right
mov byte[boolY],1 ;go up
mov ax,0
ret
barLeft: mov byte[boolX],1 ;go left
mov byte[boolY],1 ;go up
mov ax,0
ret