-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGolf.asm
1113 lines (963 loc) · 21.6 KB
/
Golf.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
; Assembly Project - Mini Golf.
.386 ; .386 in order to use far jumps
IDEAL
MODEL small
STACK 100h
DATASEG
; gravity equ 0100111001110b - f64 (headache)
Clock equ es:6Ch
subPixel equ 0
maxVelocity equ 22
minVelocity equ 1
frictionFactor equ 2
filename_start db 'start.bmp',0 ; picture
filename_rules db 'rules.bmp',0
filename_back_menu db 'backMenu.bmp',0
filename_game db 'game.bmp',0
filehandle dw 0
Header db 54 dup (0)
Palette db 256*4 dup (0)
ScrLine db 320 dup (0) ; picture
endMsg db 'Thank you for playing the game',13,10,'$'
ErrorMsg db 'Error in loading', 13, 10 ,'$'
strokes db 'Strokes: '
nameGame db 'Mini Golf'
range dw 0
released dw 0
; music
note dw 1750h
; music
pointX dw 0
pointY dw 0
virX dw 0
virY dw 0
color dw 15
holeX dw 300
holeY dw 100
colorHole dw 8
;line db "Physics$"
msgFix db "Click the left button for execution$"
;Draw ball offsets
xOffsets dw 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 1, 2
yOffsets dw 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3
;Draw ball offsets
;Draw hole offsets
;xHoleOffsets dw 1,2,3,4,5,6, 0,1,2,3,4,5,6,7 ,0,1,2,3,4,5,6,7 ,0,1,2,3,4,5,6,7 ,0,1,2,3,4,5,6,7 ,0,1,2,3,4,5,6,7 ,0,1,2,3,4,5,6,7 ,1,2,3,4,5,6
;yHoleOffsets dw 0,0,0,0,0,0, 1,1,1,1,1,1,1,1 ,2,2,2,2,2,2,2,2 ,3,3,3,3,3,3,3,3 ,4,4,4,4,4,4,4,4 ,5,5,5,5,5,5,5,5 ,6,6,6,6,6,6,6,6 ,7,7,7,7,7,7
;Draw hole offsets
twoWord dw 2
; boolean variable
mouseDown db 0
hitWall db 0
hitWallGeneral db 0
; boolean variable
velocity dw 0
velX dw 0
velY dw 0
newVelX dw 0
newVelY dw 0
;IN: nothing
;OUT: prints 'Mini Golf'
macro strShowName
;y
mov bp, seg nameGame
mov es, bp
mov bp, offset nameGame
mov al, 0
mov bh, 2h
mov bl, 15
mov cx, 9
mov dh, 23
mov dl, 30
mov ah, 13h
int 10h
endm
;IN: nothing
;OUT: prints 'Strokes'
macro strShowStrokes
;a
mov bp, seg strokes
mov es, bp
mov bp, offset strokes
mov al, 0
mov bh, 2h
mov bl, 15
mov cx, 9
mov dh, 23
mov dl, 1
mov ah, 13h
int 10h
endm
;IN: nothing
;OUT: updates the strokes number
macro strChange
;i
mov dl, 10
mov dh, 23
mov bh, 0
mov ah, 02h
int 10h
mov dl, ' '
mov bl, 0
mov bh, 0
mov ah, 02h
;clearing the last digit
mov cx, 9
loopForClear:
int 10h
loop loopForClear
;clearing the last digit
mov dl, 10
mov dh, 23
mov bh, 0
mov ah, 02h
int 10h
mov ax,[released]
call printNum
endm
CODESEG
proc printNum
;r
;initialize count
mov cx,0
mov dx,0
label1:
; if ax is zero
cmp ax,0
je print1
;initialize bx to 10
mov bx,10
; extract the last digit
div bx
;push it in the stack
push dx
;increment the count
inc cx
;set dx to 0
xor dx,dx
jmp label1
print1:
;check if count
;is greater than zero
cmp cx,0
je exitProc
;pop the top of stack
pop dx
;add 48 so that it
;represents the ASCII
;value of digits
add dx,48
;interrupt to print a
;character
mov ah,02h
int 21h
;decrease the count
dec cx
jmp print1
exitProc:
ret
endp printNum
; -------------GUI functions-------------
proc releaseNote
;m
; open speaker
in al, 61h
or al, 00000011b
out 61h, al
; send control word to change frequency
mov al, 0B6h
out 43h, al
; play frequency 131Hz
mov ax, [note]
out 42h, al ; Sending lower byte
mov al, ah
out 42h, al ; Sending upper byte
call delay_ball
in al, 61h
and al, 11111100b
out 61h, al
endp releaseNote
proc CloseFileBMP ;proc to close the bmp file before printing another one
;a
mov ah, 3Eh
mov bx, [filehandle]
int 21h
ret
endp CloseFileBMP
proc OpenFile_start
;o
; Open file
mov ah, 3Dh
xor al, al
mov dx, offset filename_start
int 21h
jc openerror
mov [filehandle], ax
ret
openerror:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
ret
endp OpenFile_start
proc OpenFile_rules
;z
; Open file
mov ah, 3Dh
xor al, al
mov dx, offset filename_rules
int 21h
jc openerror_rules
mov [filehandle], ax
ret
openerror_rules:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
ret
endp OpenFile_rules
proc OpenFile_back_menu
; Open file
mov ah, 3Dh
xor al, al
mov dx, offset filename_back_menu
int 21h
jc openerror_back_menu
mov [filehandle], ax
ret
openerror_back_menu:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
ret
endp OpenFile_back_menu
proc OpenFile_game
; Open file
mov ah, 3Dh
xor al, al
mov dx, offset filename_game
int 21h
jc openerror_game
mov [filehandle], ax
ret
openerror_game:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
ret
endp OpenFile_game
proc ReadHeader
; Read BMP file header, 54 bytes
mov ah,3fh
mov bx, [filehandle]
mov cx,54
mov dx,offset Header
int 21h
ret
endp ReadHeader
proc ReadPalette
; Read BMP file color palette, 256 colors * 4 bytes (400h)
mov ah,3fh
mov cx,400h
mov dx,offset Palette
int 21h
ret
endp ReadPalette
proc CopyPal
; Copy the colors palette to the video memory
; The number of the first color should be sent to port 3C8h
; The palette is sent to port 3C9h
mov si,offset Palette
mov cx,256
mov dx,3C8h
mov al,0
; Copy starting color to port 3C8h
out dx,al
; Copy palette itself to port 3C9h
inc dx
PalLoop:
; Note: Colors in a BMP file are saved as BGR values rather than RGB
mov al,[si + 2] ; Get red value
shr al,2 ; Max. is 255, but video palette maximal
; value is 63. Therefore dividing by 4
out dx,al ; Send it
mov al,[si+1] ; Get green value
shr al,2
out dx,al ; Send it
mov al,[si] ; Get blue value
shr al,2
out dx,al ; Send it
add si,4 ; Point to next color
; (There is a null chr. after every color.)
loop PalLoop
ret
endp CopyPal
proc CopyBitmap
; BMP graphics are saved upside-down .
; Read the graphic line by line (200 lines in VGA format),
; displaying the lines from bottom to top.
mov ax, 0A000h
mov es, ax
mov cx,200
PrintBMPLoop :
push cx
; di = cx*320, point to the correct screen line
mov di,cx
shl cx,6
shl di,8
add di,cx
; Read one line
mov ah,3fh
mov cx,320
mov dx,offset ScrLine
int 21h
; Copy one line into video memory
cld ; Clear direction flag, for movsb
mov cx,320
mov si,offset ScrLine
rep movsb ; Copy line to the screen
;rep movsb is same as the following code :
;mov es:di, ds:si
;inc si
;inc di
;dec cx
;loop until cx=0
pop cx
loop PrintBMPLoop
ret
endp CopyBitmap
proc msg_holding_point
mov dx, offset msgFix
mov ah, 9h
int 21h
ret
endp msg_holding_point
proc textMode
mov ah, 0h ; text mode
mov al,2h
int 10h
ret
endp textMode
proc graphicsMode
mov ax,13h ; graphics mode
int 10h
ret
endp graphicsMode
proc game_screen
call OpenFile_game
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
call CloseFileBMP
ret
endp game_screen
proc start_screen ; printing the menu
call OpenFile_start
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
call CloseFileBMP
ret
endp start_screen
proc rules_screen ; printing the rules
call OpenFile_rules
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
call CloseFileBMP
ret
endp rules_screen
proc back_menu_screen ; printing the game screen
call OpenFile_back_menu
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
call CloseFileBMP
ret
endp back_menu_screen
; -------------GUI functions-------------
; -------------object functions-------------
proc checkBall
cmp [mouseDown], 0
jne nextFrame
cmp [pointY],43
jle checkUpperBound
jmp nextFrame
checkUpperBound:
cmp [pointY],31
jge checkOther
jmp nextFrame
checkOther:
cmp [pointX],286
jge checkRightBound
jmp nextFrame
checkRightBound:
cmp [pointX],300
jge nextFrame
;call game_screen
call delay_ball
jmp backMenu
endp checkBall
proc clearingRec
mov bx,170
push [color]
outerLoop:
inc bx
mov cx, 320
rec:
mov dx, bx
mov [color], 0
push cx
push dx
push [color]
call drawPixel
dec cx
cmp cx, 0
jge rec
cmp bx,180
jle outerLoop
pop [color]
ret
endp clearingRec
proc drawPixel
pop bp
pop ax ;color
pop dx ;Y position
pop cx ;X position
mov bh, 0h
mov ah,0ch
int 10h
push bp
ret
endp drawPixel
proc drawball
mov bl,0
drawBallLoop:
;push bx
xor ah, ah ; reseting ah
mov al, bl ; keeping the counters value
mul [twoWord] ; ax * 2, 2 is the size of every element of the list
add ax, offset xOffsets ; adding the base address of the array
push bx ; pushing bx in order to keep the value of bl
mov bx, ax ; moving the address of the x-offset to bx
mov ax, [word ptr bx] ; saving the x-offset to ax because you can only use word prt on bx
pop bx ; getting the counters value back
push bx
mov bx,[pointX]
shr bx,subPixel
add ax,bx
pop bx
;add ax, [pointX] ; adding the base x-value to the x-offset
push ax ; pushing as a parameter the final x-value
; same thing for the y
xor ah, ah
mov al, bl
mul [twoWord]
add ax, offset yOffsets
push bx
mov bx, ax
mov ax, [word ptr bx]
pop bx
push bx
mov bx,[pointY]
shr bx,subPixel
add ax,bx
pop bx
;add ax, [pointY]
push ax
;same thing for the y
push [color] ; pushing as a parameter the color
call drawPixel ; drawing the pixel
inc bx
cmp bl,12
jnz drawBallLoop ; looping 12 times for the ball
ret
endp drawball
proc deleteBall
push [color]
mov [word ptr color], 2
call drawBall
pop [color]
ret
endp deleteBall
; -------------object functions-------------
; -------------mouse functions-------------
proc mouseInitialization
push ax
mov ax,0h
int 33h
pop ax
ret
endp mouseInitialization
proc showMouse
push ax
mov ax,01
int 33h
pop ax
ret
endp showMouse
proc hideMouse
push ax
mov ax,02h
int 33h
pop ax
ret
endp hideMouse
; -------------mouse functions-------------
; -------------math & physics functions-------------
;generates a random number between 0 - range
proc generateRandom
pop bp
pop [word ptr range]
randLoop:
;getting the random
mov ax, 40h
mov es, ax
mov ax, [Clock] ; get the timer counter
mov ah, [byte cs:si] ; read one bye from memory
xor al, ah ; xor the memory and counter
and ax,11111111b ; limit the result
inc si ; si += 1, in order it to be more randomised
xor ah,ah
cmp ax,[range] ; if the number is not in the range, keep randomising until we get a random number
ja randLoop
push ax
push bp
ret
endp generateRandom
proc delay_ball
mov ax, 40h
mov es, ax
mov ax, [Clock]
FirstTick:
cmp ax, [Clock]
je FirstTick
mov cx, 1 ; 1x0.055sec = ~1.65
DelayLoop:
mov ax, [Clock]
Tick:
cmp ax, [Clock]
je Tick
loop DelayLoop
ret
endp delay_ball
proc pow2
pop bp
pop ax ; value for squaring
push dx
imul ax
and ax, 0111111111111111b
pop dx ;keeping dx clear
push ax ; squared value
push bp
ret
endp pow2
proc sqrt
pop bp
pop bx ;v^2 - the velocity squared
mov dx,0 ;check variable
sqrtLoop:
push bp
push bx
push dx
call pow2
pop ax
pop bx
pop bp
cmp ax,bx
jl incNum
jg takePreviousNum
;returning the number
push dx
push bp
ret
;returning the number
incNum:
inc dx
jmp sqrtLoop
takePreviousNum:
dec dx
push dx
push bp
ret
jmp sqrtLoop
push bp
ret
endp sqrt
proc vectorMultiplication
pop bp
;when called - push [N_Y]
; push [N_X]
; push [V1_Y]
; push [V1_X]
pop ax ; V1_X
pop bx ; V1_Y
pop cx ; N_X
pop dx ; N_Y
push dx
imul cx ; ax * bx --> can be interpreted as V1_X * V2_X
pop dx
mov cx,ax
mov ax,bx
imul dx; ax * dx --> can be interpreted as V1_Y * V2_Y
add ax,cx
push ax
push bp
ret
endp vectorMultiplication
;proc taylorSin
;pop [angle]
;ret
;endp taylorSin
;proc calc_cos
;ret
;endp calc_cos
; -------------math & physics functions-------------
proc initializeGame
menu:
call textMode
call graphicsMode
call start_screen
;keyboard input
mov ah,1h
int 21h
cmp al,70h; if user pressed 'p' then start the game
je startGame
cmp al,72h; if user pressed 'r' then move to the rules page, r ascii is 72
je rules
cmp al,65h; if user pressed 'e' then close the game
je exit; in order to close the game, we need to move to text mode
jmp menu
startGame:
call textMode
call graphicsMode
call game_screen
call mouseInitialization
call showMouse
mov [released], 0
;randomising the balls position every round
mov [range],170
push [range]
call generateRandom
pop ax
mov [pointY],ax
xor ax,ax
mov [range],320
push [range]
call generateRandom
pop ax
mov [pointX],ax
strShowStrokes
strShowName
;randomising the balls position every round
gameLoop:
push ax
call deleteBall
mov ax, 3h ; getting the status of the mouse
int 33h ; ^
shr bx,1 ; shifting bx one bit so we can use the carry flag
jc checkIfMouseDown ; jump if the left button is down
;shr bx,1
;jc printMsg
jmp mouseNotDown ; jump if the left button is not down
checkIfMouseDown:
cmp [mouseDown],1
jz mouseHold
;this code will run at the first frame of the click
push bx
mov bx,[pointY]
mov [virY],bx
mov bx,[pointX]
mov [virX],bx
pop bx
call drawBall
mouseHold:
mov [mouseDown], 1 ; mouseDown = True
mov [word ptr color],15
;dragCheck:
;mov bh,0h
;mov ah, 0Dh
;int 10h
;cmp al,3
;jne dragCheck
shr cx,1 ; cx /= 2, to fit screen
mov [pointX],cx
mov [pointY],dx
call drawball
;dragging
jmp afterMouseCheck ; after the mouse click
mouseNotDown:
cmp [mouseDown], 1 ; checking if the mouse if pressed (mouseDown == True)
jnz afterLeftClickReleasedCheck ; mouseDown != 1, we change the balls position, left click was released this frame
; we move the ball if the user dragged the ball
; velocityY = pointY - mouseY
mov bx, [virY]
sub bx, [pointY]
mov [velY],bx
mov bx,[virY]
mov [pointY],bx
; velocityX = pointX - mouseX
mov bx, [virX]
sub bx, [pointX]
mov [velX],bx
mov bx,[virX]
mov [pointX],bx
;calc velocity
push [word ptr velX]
call pow2
pop bx
push [word ptr velY]
call pow2
pop ax
add ax,bx
push ax
call sqrt
;calc velocity
pop ax ; ax keeps the velocity of the ball : |v| = sqrt(Vx^2 + Vy^2)
mov [velocity], ax
cmp ax, maxVelocity
jle afterLeftClickReleasedCheck
;set velocity for normal physics
mov bx,maxVelocity
mov ax, [velX]
imul bx
idiv [velocity]
mov [velX],ax
mov ax, [velY]
imul bx
idiv [velocity]
mov [velY],ax
inc [released]
strChange
call hideMouse
call releaseNote
afterLeftClickReleasedCheck:
mov [mouseDown], 0
mov [word ptr color],15
afterMouseCheck: ; if the mouse was clicked we move the ball, for the first time.
; move ball
call deleteBall
push [word ptr velX]
call pow2
pop bx ;taking ax as bx
push [word ptr velY]
call pow2
pop ax
add ax,bx
push ax
call sqrt
pop ax ; getting the velocity
cmp ax,frictionFactor
jle stopBall
mov [velocity] , ax
sub ax, frictionFactor
push ax ; keeping the old velocity for the x calc
imul [word ptr velX]
idiv [word ptr velocity]
mov [velX], ax
pop ax
imul [word ptr velY]
idiv [word ptr velocity]
mov [velY], ax
jmp moveBall
stopBall:
mov [velX],0
mov [velY],0
call showMouse
moveBall:
; wall check
mov [word ptr hitWallGeneral] ,0
cmp [pointY],165
jge reflectPositionOnLowerWall
notReflectPositionOnLowerWall:
cmp [pointY], 5
jle reflectPositionOnUpperWall
notReflectPositionOnUpperWall:
cmp [pointX], 315
jge reflectPositionOnRightWall
notReflectPositionOnRightWall:
cmp [pointX],5
jle reflectPositionOnLeftWall
afterHit:
mov bx,[word ptr hitWallGeneral]
mov [word ptr hitWall] ,bx
mov bx, [velX]
add bx, [pointX]
mov [pointX], bx
mov bx, [velY]
add bx, [pointY]
mov [pointY], bx
; checking if the ball is inside the hole
call checkBall
; checking if thee ball is inside the hole
reflectPositionOnLowerWall:
mov [word ptr hitWallGeneral], 1
cmp [word ptr hitWall], 1
je notReflectPositionOnLowerWall
;the length of the normal vector of W1 - 20
push 20 ; N_Y
push 0 ; N_X
push [word ptr velY]
push [word ptr velX]
;pushing the components of two vectors
call vectorMultiplication
pop ax
shl ax,1
;newVelY
push [word ptr velY]
mov bx,20
imul bx
mov bx,ax
push 20
call pow2
pop ax
xchg bx,ax; switchs betweem the registers
idiv bx
sub [velY],ax
mov bx,[velY]
mov [newVelY],bx
;getting the reflection Y value
mov bx, [pointX]
add bx, [VelX]
mov [pointX], bx
mov bx, [pointY]
add bx, [newVelY]
mov [pointY], bx
jmp afterHit
reflectPositionOnUpperWall:
mov [word ptr hitWallGeneral], 1
cmp [word ptr hitWall], 1
je notReflectPositionOnUpperWall
push 20 ; N_Y
push 0 ; N_X
push [word ptr velY]
push [word ptr velX]
;pushing the components of two vectors
call vectorMultiplication
pop ax
shl ax,1
;newVelY
;push [word ptr velY]
mov bx,20
imul bx
mov bx,ax
push 20
call pow2
pop ax
xchg bx,ax; switchs betweem the registers
idiv bx
sub [velY],ax
mov bx,[velY]
mov [newVelY],bx
mov bx, [pointX]
add bx, [VelX]
mov [pointX], bx
mov bx, [pointY]
add bx, [newVelY]
mov [pointY], bx
jmp afterHit
reflectPositionOnRightWall:
mov [word ptr hitWallGeneral], 1