-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer1.asm
24084 lines (21274 loc) · 510 KB
/
player1.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
.MODEL SMALL
.STACK 128
.DATA
;--------------------------------- data for InGame ---------------------------------
WINDOW_WIDTH equ 320
WINDOW_HEIGHT equ 200
FRAMES_DELAY equ 41 ;24 fps
current_time db ? ;used in delay function
initial_time db ? ;used in delay function
ball_center_x dw 0
ball_center_y dw 0
ball_radius dw 5
ball_radius_square dw ? ;will be calculated in main
ball_velocity_x dw 1 ;-5
ball_velocity_y dw 2 ;2
ball_color_random db 0Fh
right_margin dw 10
top_margin dw 10
bottom_margin dw 10
left_margin dw 10
border_width dw 1
racket_margin dw 30
racket_start_x dw ? ;will set to window_width - racket_margin - racket_width later
racket_start_y dw 180
racket_width dw 25
racket_height dw 5
racket_move_velocity dw 10
shootcenter_x dw ?
shootcenter_y dw ?
chk db ?
dummy1 dw ?
dummy2 dw ?
dummy3 DB 0
;--------------------------------- data for InGame ---------------------------------
;SI -> registers , DI -> Indices
;these vriables are for the first page
;1 -> 15 (2 operands) , 16 -> 23 (1 operand) , 24 -> 25 (no operands) : important for command index
;note for the commandListNames : we can access the string of the command chosen by the following equation : command index * 4 + offset commandListNames
;note for the OperandListNames : we can access the string of the command chosen by the following equation : command index * 2 + offset OperandListNames
chooseMessage DB 'choose$'
yesOrNoMessage DB 'is there is a bracket$'
enterANumber DB ',enter a number : $'
enterNameMessage DB 'Please Enter Your Name : $'
enterPointsMessage DB 'Initial Points : $'
pressEnterMessage DB 'Press Enter To Continue : $'
sendMessageEnter DB 'Press Enter to execute this command : $'
enterForbiddenMsg DB 'Forbidden Character : $'
commandList DB '01) ADD,02) ADC,03) SUB,04) SBB,05) RCR,06) RCL,07) MOV,08) XOR,09) AND,10) OR,11) SHR,12) SHL,13) SAR,14) ROL,15) ROR,16) PUSH,17) POP,18) INC,19) DEC,20) IMUL,21) IDIV,22) MUL,23) DIV,24) NOP,25) CLC$'
isBracketList DB '1) yes,2) No$'
firstOperandList DB '01) AX,02) BX,03) CX,04) DX,05) SI,06) DI,07) SP,08) BP,09) AH,10) AL,11) BH,12) BL,13) CH,14) CL,15) DH,16) DL$'
secondOperandList DB '01) AX,02) BX,03) CX,04) DX,05) SI,06) DI,07) SP,08) BP,09) AH,10) AL,11) BH,12) BL,13) CH,14) CL,15) DH,16) DL,17) enter a number$'
powerUpsList1 DB '1) Executing a command on your own processor,(consumes 5 points),2) Executing a command on your processor and your,opponent processor at the same time,(consumes 3 points),3) Changing the forbidden character only once,(consumes 8 points),$'
powerUpsList2 DB '4) Making one of the data lines stuck at zero or,at one for a single instruction,(consumes 2 points),5) Clearing all registers at once.,(Consumes 30 points and could be used only once)$'
instructionList DB 'use left and right arrow to edit your command,use up and down arrows to scroll pages,use f2 to in game chatting,use f3 to out game chatting,press f4 to exit chatting$'
addressListHeaders DB ' 0 1 2 3 4 5 6 7 8 9 A B C D E F$'
noticationsTitle DB 'notifications ',1,'$'
powerUpsInfo DB 'Power Up info : $'
registersList DB ' AX BX CX DX SI DI SP BP $'
commandListNames DB 'ADD ','ADC ','SUB ','SBB ','RCR ','RCL ','MOV ','XOR ','AND ','OR ','SHR ','SHL ','SAR ','ROL ','ROR ','PUSH','POP ','INC ','DEC ','IMUL','IDIV','MUL ','DIV ','NOP ','CLC '
OperandListNames DB 'AX','BX','CX','DX','SI','DI','SP','BP','AH','AL','BH','BL','CH','CL','DH','DL'
enterGameLevelMsg DB 'enter game Level : $'
gameLevelMsg DB 'game Level : $'
ForbiddebCharMsg DB 'Forbidden Char is : $'
flagsList DB 'CF : ,PF : ,AF : ,ZF : ,SF : ,OF : $'
WinnerMessage DB 'the winner is : $'
loserMessage DB 'the loser is : $'
EnterNewForbidden DB ' ,New Forbidden Char : $'
TargetMessage DB 'Target:$'
enterRegisterVal DB 'AX : ,BX : ,CX : ,DX : ,SI : ,DI : ,SP : ,BP : , $'
extraPowerUp DB '6) Change target Value$'
enterNewTargerMsg DB ',new Target : $'
inGameChatReqMsg DB 'the other player wants to InGame chat with you, press 1 to accept$'
outGameChatReqMsg DB 'the other player wants to outGame chat with you, press 1 to accept$'
personTurnIndex DB 1 ; if 0 then its my turn on my device , if 1 then its opponent turn on his device (used in communication)
isThereAChatting DB 0
;for chat type
;0 : inGameChatting
;1 : outGameChatting
chatType DB 0
;for messageing
messageToBeSend DB 200 DUP('$')
messageRecieved DB 200 DUP('$')
messageToBeSendRow DB 22
messageToBeSendCol DB 51
messageRecievedRow DB 0
messageRecievedCOL DB 51
;variables to be used later in execution
commandIndex DB ?
isFirstOpBracket DB ?
firstOperandIndex DB ?
isSecondOpBracket DB ?
secondOperandIndex DB ?
numberEntered DW 0H
commandEntered DB 15 DUP('$')
pointsAddress DW ?
addressesAddress DW ?
registersAddress DW ?
forbiddentCharAdd DW ?
flagAddress DW ?
gameLevel DB 5
personTurn DB 0 ; if personTurn = 0 then you , if personTurn = 1 then opponent
isGameEnded DB 0 ; if 1 then stop executing and end game
loserNameAddress DW ?
winnerNameAddress DW ?
addedValueToSIDest DW ?
addedValueToSISource DW ?
targetValue DW 105EH
tempNewTarget DW 0
;Variables for level 2
TargetPerson DB 1 ;if 1 then execute on me , if 2 then execute at oponent
;for navigation index
;1 : left arrow
;2 : right arrow
;3 : up arrow
;4 : down arrow
;5 : f2
;6 : f3
;7 : ENTER
;8 : f4
isANavigateButton DB 0H
navigationIndex DB 0H
dummyVariable DB 0H
powerUpIndex DB 0
;variables to be used in other things
navigate DB 1H
PageNumber DB 0H
cursorY DB 0H
cursorX DB 0H
isFirstTime DB 1H
InitialPoints DB 0
tempForbChar DB 0
regisetAdd DW ?
NUMtoBeDisplayed DB 4 DUP('$')
;YOUR VARIABLES
yourAddressesList DB 16 DUP(0)
yourFlags DW 0
youchangedForbiddenKey DB 0 ;IF 1 then you cannot change opponent key again
youMadeRegWithZero DB 0 ;If 1 then you canot use this power up again
youchangedTargetValue DB 0 ;If 1 then you canot use this power up again
;yourRegistersValues[0] = AX
;yourRegistersValues[1] = BX
;yourRegistersValues[2] = CX
;yourRegistersValues[3] = DX
;yourRegistersValues[4] = SI
;yourRegistersValues[5] = DI
;yourRegistersValues[6] = SP
;yourRegistersValues[7] = BP
yourRegistersValues DW 8 DUP(0)
yourPoints DB 0
yourName DB 10 DUP('$')
yourForbiddenChar DB 1 DUP('$')
;OPPONENT VARIABLES
opponentAddressesList DB 16 DUP(0)
opponentFlags DW 0
opponentchangedForbiddenKey DB 0 ;IF 1 then opponent cannot change opponent key again
opponentMadeRegWithZero DB 0 ;If 1 then opponent canot use this power up again
opponentchangedTargetValue DB 0
;opponentRegistersValues[0] = AX
;opponentRegistersValues[1] = BX
;opponentRegistersValues[2] = CX
;opponentRegistersValues[3] = DX
;opponentRegistersValues[4] = SI
;opponentRegistersValues[5] = DI
;opponentRegistersValues[6] = SP
;opponentRegistersValues[7] = BP
opponentRegistersValues DW 8 DUP(0)
opponentPoints DB 0
opponentName DB 10 DUP('$')
opponentForbiddenChar DB 1 DUP('$')
.CODE
;this segemnt is for for inGame game
;=========================================================================
;---------------------
DRAW_SHOOT PROC
;call SET_GRAPHIC_MODE
mov dx, shootcenter_y ;
sub dx, 1 ;Initial row for drawing the ball
draw_sh_loop1:
mov cx, shootcenter_x ;
sub cx, 1 ;initial column for drawing the ball
draw_sh_loop2:
call CHECK_INSIDE_SHOOT
cmp bx, 0000h
je pass_this_pixel
mov al, ball_color_random ;color (random)
mov ah, 0ch ;code for drawing pixel
int 10h ;interupt
pass_this_pixel:
inc cx ;go to next column
mov ax, shootcenter_x ;checking if code reached end of column
add ax, 1
cmp cx, ax
jne draw_sh_loop2
inc dx ;go to next row
mov ax, shootcenter_y ;checking if code reached end of row
add ax, 1
cmp dx, ax
jne draw_sh_loop1
RET
DRAW_SHOOT ENDP
DRAW_BALL PROC
;call SET_GRAPHIC_MODE
mov dx, ball_center_y ;
sub dx, ball_radius ;Initial row for drawing the ball
draw_ball_loop1:
mov cx, ball_center_x ;
sub cx, ball_radius ;initial column for drawing the ball
draw_ball_loop2:
call CHECK_INSIDE_BALL
cmp bx, 0000h
je pass_this_pixel_SH
mov al, ball_color_random ;color (random)
mov ah, 0ch ;code for drawing pixel
int 10h ;interupt
pass_this_pixel_SH:
inc cx ;go to next column
mov ax, ball_center_x ;checking if code reached end of column
add ax, ball_radius
cmp cx, ax
jne draw_ball_loop2
inc dx ;go to next row
mov ax, ball_center_y ;checking if code reached end of row
add ax, ball_radius
cmp dx, ax
jne draw_ball_loop1
RET
DRAW_BALL ENDP
;---------------------
GET_RANDOM_COLOR PROC
push cx
push dx
mov ah, 2ch
int 21h ;get current time miliseconds in al
mov al, dl
mov ah, 0
mov cl, 15
div cl ;we have our random number inside ah (modulus)
inc ah ;to avoid black color for ball!
mov ball_color_random, ah
pop dx
pop cx
RET
GET_RANDOM_COLOR ENDP
;---------------------
CHECK_INSIDE_BALL PROC ;checks if coordinate inside cx and dx is inside the ball's circle. bx=1 for yes, bx=0 for no
push cx
push dx ;keep row and column inside stack
cmp cx, ball_center_x ;check if current point is left or right of center
jge cx_is_positive
mov ax, ball_center_x
sub ax, cx
xchg ax, cx ;now center_x - current_x is in cx
jmp delta_x_is_calculated
cx_is_positive:
sub cx, ball_center_x ;now current_x - center_x is in cx
jmp delta_x_is_calculated
delta_x_is_calculated:
mov al, cl
mul cl ;delta_x^2 inside ax
push ax ;push ax to stack
cmp dx, ball_center_y ;check if current point is up or down of center
jge dx_is_positive
mov ax, ball_center_y
sub ax, dx
xchg ax, dx ;now center_y - current_y is in cx
jmp delta_y_is_calculated
dx_is_positive:
sub dx, ball_center_y ;now current_y - center_y is in cx
jmp delta_y_is_calculated
delta_y_is_calculated:
mov al, dl
mul dl ;delta_y^2 is inside ax
push ax ;push ax to stack
calculate_distance_squared:
pop bx
pop ax
add bx, ax ;calculate delta_x^2 + delta_y^2
cmp bx, ball_radius_square
jle point_is_inside_circle
jg point_is_outside_circle
point_is_inside_circle:
mov bx, 1
jmp check_inside_ball_exit
point_is_outside_circle:
mov bx, 0
jmp check_inside_ball_exit
check_inside_ball_exit:
pop dx
pop cx
RET
CHECK_INSIDE_BALL ENDP
;---------------------
CHECK_INSIDE_SHOOT PROC ;checks if coordinate inside cx and dx is inside the ball's circle. bx=1 for yes, bx=0 for no
push cx
push dx ;keep row and column inside stack
cmp cx, shootcenter_x ;check if current point is left or right of center
jge cx_is_positiveSH
mov ax, shootcenter_x
sub ax, cx
xchg ax, cx ;now center_x - current_x is in cx
jmp delta_x_is_calculatedSH
cx_is_positiveSH:
sub cx, shootcenter_x ;now current_x - center_x is in cx
jmp delta_x_is_calculatedSH
delta_x_is_calculatedSH:
mov al, cl
mul cl ;delta_x^2 inside ax
push ax ;push ax to stack
cmp dx, shootcenter_y ;check if current point is up or down of center
jge dx_is_positiveSH
mov ax, shootcenter_y
sub ax, dx
xchg ax, dx ;now center_y - current_y is in cx
jmp delta_y_is_calculatedSH
dx_is_positiveSH:
sub dx, shootcenter_y ;now current_y - center_y is in cx
jmp delta_y_is_calculatedSH
delta_y_is_calculatedSH:
mov al, dl
mul dl ;delta_y^2 is inside ax
push ax ;push ax to stack
calculate_distance_squaredSH:
pop bx
pop ax
add bx, ax ;calculate delta_x^2 + delta_y^2
cmp bx, ball_radius_square
jle point_is_inside_circleSH
jg point_is_outside_circleSH
point_is_inside_circleSH:
mov bx, 1
jmp check_inside_ball_exitSH
point_is_outside_circleSH:
mov bx, 0
jmp check_inside_ball_exitSH
check_inside_ball_exitSH:
pop dx
pop cx
RET
CHECK_INSIDE_SHOOT ENDP
;---------------------
MOVE_BALL PROC
mov ax, ball_velocity_x
add ball_center_x, ax
mov ax, ball_velocity_y
add ball_center_y, ax
RET
MOVE_BALL ENDP
;--------------------
MOVE_SHOOT PROC
mov ax, 0
sub shootcenter_x, ax
mov ax, 6
sub shootcenter_y, ax
RET
MOVE_SHOOT ENDP
;---------------------
CHECK_KEYBOARD_EVENTS PROC
mov si,0
mov ah, 01h
int 16h
jnz lg ;jz
jmp racket_movement_end
lg:
mov ah, 00h
int 16h
cmp ah,4bh
je racket_move_up
cmp ah, 4dh
je racket_move_down
cmp al,32
je lbl
cmp al, 'q'
jne L_g
mov dummy3,1
jmp end_Subprogram
L_g:
racket_move_up:
mov ax, racket_move_velocity
sub racket_start_x, ax
mov ax, right_margin
cmp racket_start_x, ax
jl dum1
jmp racket_movement_end
dum1:
mov ax, right_margin
mov racket_start_x, ax
jmp racket_movement_end
racket_move_down:
mov ax, racket_move_velocity
add racket_start_x, ax
mov ax, WINDOW_WIDTH
sub ax, left_margin
sub ax, racket_height
cmp racket_start_x, ax
jle racket_movement_end
mov ax, WINDOW_WIDTH
sub ax, left_margin
sub ax, racket_height
mov racket_start_x, ax
jmp racket_movement_end
lbl:
whil :
cmp shootcenter_y,0
je chfirst
;here check collosion with shot or not
mov ax,ball_center_x
cmp ax,shootcenter_x
je xeqx
jmp loklok
xeqx:
mov ax,ball_center_y
cmp ax,shootcenter_y
jne loklok
inc opponentPoints
jmp racket_movement_end
;----------------
loklok: CALL CLEAR_SHOOT
CALL CLEAR_RACKET
CALL CLEAR_BALL
CALL MOVE_SHOOT
CALL MOVE_BALL
CALL CHECK_BALL_COLLISION
CALL DRAW_SHOOT
CALL DRAW_RACKET
CALL DRAW_BALL
CALL DELAY
JMP whil
chfirst:
mov ax,racket_start_x
mov bx, racket_start_y
mov shootcenter_x,ax
mov shootcenter_y,bx
CALL CLEAR_BALL
CALL CLEAR_SHOOT
racket_movement_end:
mov ax,racket_start_x
mov bx, racket_start_y
; add ax,5
;
; add bx,10
mov shootcenter_x,ax
mov shootcenter_y,bx
CALL CLEAR_BALL
CALL CLEAR_SHOOT
end_Subprogram:
RET
CHECK_KEYBOARD_EVENTS ENDP
;---------------------
CHECK_BALL_COLLISION PROC
call CHECK_BALL_RIGHT_COLLISION
call CHECK_BALL_LEFT_COLLISION
call CHECK_BALL_TOP_COLLISION
call CHECK_BALL_BOTTOM_COLLISION
RET
CHECK_BALL_COLLISION ENDP
;---------------------
CHECK_BALL_LEFT_COLLISION PROC
mov bx, ball_center_x
sub bx, ball_radius
cmp bx, left_margin ;did the ball touch the left border?
jle left_collided
jg left_collision_end
left_collided:
mov ax, left_margin
mov ball_center_x, ax
mov ax, ball_radius
add ball_center_x, ax ;putting ball on the left border (in case it passed it)
call GET_RANDOM_COLOR
not ball_velocity_x
add ball_velocity_x, 1 ;multiplied the x velocity by -1, so the direction of it changes.
left_collision_end:
RET
CHECK_BALL_LEFT_COLLISION ENDP
;----------------------------------
CHECK_BALL_RIGHT_COLLISION PROC
mov bx, ball_center_x
add bx, ball_radius
mov ax ,WINDOW_WIDTH
sub ax, bx
cmp ax, right_margin ;did the ball touch the left border?
jle rihgt_collided
jg right_collision_end
rihgt_collided:
mov ax,right_margin
sub ball_center_x,ax
call GET_RANDOM_COLOR
not ball_velocity_x
add ball_velocity_x, 1 ;multiplied the x velocity by -1, so the direction of it changes.
right_collision_end:
RET
CHECK_BALL_RIGHT_COLLISION ENDP
;---------------------*------------
CHECK_BALL_TOP_COLLISION PROC
mov bx, ball_center_y
sub bx, ball_radius
cmp bx, top_margin ;did the ball touch the top border?
jle top_collided
jg top_collision_end
top_collided:
mov ax, top_margin
mov ball_center_y, ax
mov ax, ball_radius
add ball_center_y, ax ;putting ball on the top border (in case it passed it)
call GET_RANDOM_COLOR
not ball_velocity_y
add ball_velocity_y, 1 ;multiplied the y velocity by -1, so the direction of it changes.
top_collision_end:
RET
CHECK_BALL_TOP_COLLISION ENDP
;---------------------
CHECK_BALL_BOTTOM_COLLISION PROC
mov bx, ball_center_y
add bx, ball_radius
mov cx, WINDOW_HEIGHT
sub cx, bottom_margin
cmp bx, cx ;did the ball touch the bottom border?
jge bottom_collided
jl bottom_collision_end
bottom_collided:
mov ax, WINDOW_HEIGHT
sub ax, bottom_margin
mov ball_center_y, ax
mov ax, ball_radius
sub ball_center_y, ax ;putting ball on the bottom border (in case it passed it)
call GET_RANDOM_COLOR
not ball_velocity_y
add ball_velocity_y, 1 ;multiplied the y velocity by -1, so the direction of it changes.
bottom_collision_end:
RET
CHECK_BALL_BOTTOM_COLLISION ENDP
;--------------------
DELAY PROC
mov ah, 86h
mov cx, 0h
mov dx, 0a028h ;wait for 41 miliseconds (for 24 fps)
int 15h
RET
DELAY ENDP
;------------------
CLEAR_BALL PROC ;same as draw ball, with black color
mov dx, ball_center_y
sub dx, ball_radius ;Initial row for drawing the ball
clear_ball_loop1:
mov cx, ball_center_x
sub cx, ball_radius
clear_ball_loop2:
mov ah, 0ch ;code for drawing pixel
mov al, 00h ;color (black)
int 10h ;interupt
inc cx ;go to next column
mov ax, ball_center_x ;checking if code reached end of column
add ax, ball_radius
cmp cx, ax
jnz clear_ball_loop2
inc dx ;go to next tow
mov ax, ball_center_y ;checking if code reached end of row
add ax, ball_radius
cmp dx, ax
jnz clear_ball_loop1
RET
CLEAR_BALL ENDP
;---------------------
CLEAR_SHOOT PROC ;same as draw ball, with black color
mov dx, shootcenter_y ;
sub dx, ball_radius ;Initial row for drawing the ball
clear_ball_loop1SH:
mov cx, shootcenter_x ;
sub cx, ball_radius ;initial column for drawing the ball
clear_ball_loop2SH:
mov ah, 0ch ;code for drawing pixel
mov al, 00h ;color (black)
int 10h ;interupt
inc cx ;go to next column
mov ax, shootcenter_x ;checking if code reached end of column
add ax, ball_radius
cmp cx, ax
jnz clear_ball_loop2SH
inc dx ;go to next tow
mov ax, shootcenter_y ;checking if code reached end of row
add ax, ball_radius
cmp dx, ax
jnz clear_ball_loop1SH
RET
CLEAR_SHOOT ENDP
;---------------------
CLEAR_RACKET PROC
mov dx, racket_start_y ;initial row for drawing the racket
clear_racket_loop1:
mov cx, racket_start_x ;initial column for drawing the ball
clear_racket_loop2:
mov ah, 0ch
mov al, 00h
int 10h
inc cx
mov ax, racket_start_x
add ax, racket_width
cmp cx, ax
jnz clear_racket_loop2
inc dx
mov ax, racket_start_y
add ax, racket_height
cmp dx, ax
jnz clear_racket_loop1
RET
CLEAR_RACKET ENDP
;---------------------
DRAW_RACKET PROC
mov dx, racket_start_y
draw_racket_loop1:
mov cx, racket_start_x
draw_racket_loop2:
mov ah, 0ch
mov al, 25h
int 10h
inc cx
mov ax, racket_start_x
add ax, racket_width
cmp cx, ax
jnz draw_racket_loop2
inc dx
mov ax, racket_start_y
add ax, racket_height
cmp dx, ax
jnz draw_racket_loop1
RET
DRAW_RACKET ENDP
;---------------------
CLEAR_SCREEN PROC
mov ah, 06H ;scroll up
mov al, 00h ;clear entire window
mov bh, 00h ;color
mov cx, 0000 ;start row, column
mov dx, 184fh ;end row, column
int 10h
RET
CLEAR_SCREEN ENDP
;---------------------
SET_GRAPHIC_MODE PROC
mov ah, 00h ;setting video mode
mov al, 13h ;320x200 256 colors
int 10h ;call interruption
mov ax, 1003h
mov bl, 00h
mov bh, 00h
int 10h ;disable blinking for background
RET
SET_GRAPHIC_MODE ENDP
;---------------------
InitGame PROC
mov ax, ball_radius
mul ball_radius
mov ball_radius_square, ax ;initializing ball_radius_square
mov ax, WINDOW_WIDTH
sub ax, racket_margin
sub ax, racket_width
mov racket_start_x, 150
;----------------
mov ax, racket_start_x
mov bx,racket_start_y
mov shootcenter_x,ax
mov shootcenter_y,bx
;-----------------
CALL SET_GRAPHIC_MODE
move_ball_loop:
call CLEAR_BALL
call MOVE_BALL
call CLEAR_RACKET
call CHECK_KEYBOARD_EVENTS
cmp dummy3,1
je end_program
call CHECK_BALL_COLLISION
call DRAW_RACKET
call DRAW_BALL
call DELAY
jmp move_ball_loop
end_program:
mov dummy3,0
RET
InitGame ENDP
;=========================================================================
;==================================MACRO===================================
;this is a macro to change foreground and background color of a screen
changeForBackColor MACRO forColor,BackColor
MOV AH,06H
;use BH as register to put the 2 values sticked together
MOV BH,BackColor
MOV CL,4
SHL BH,CL
OR BH,forColor
XOR AL, AL ; Clear entire screen => same as MOV al,0
XOR CX, CX ; Upper left corner CH=row, CL=column => same as MOV cx, 0
MOV DX, 184FH ; lower right corner DH=row, DL=column
INT 10H
ENDM
;==========================================================================
;==================================MACRO===================================
;this is a macro to display a byte
displayByteByConvertingItToAscii MACRO num,forColor,BackColor
LOCAL BEGINTOPRINTTHENEXTNUM,MULTIPLYBWITHFACTOR,EXITMULTIPLYINGBBYAFACTOR
;the idea of this function is that it takes a nuumber like 232 , it divides it first by 100 then it pints 2
;then the remainder is 32 , it takes this remainder and divides it by 10 then it prints 3
;then the remainder is 2 , t takes this remainder and divide it by 1 and then it prints 2
MOV DL,3
MOV DH,num
BEGINTOPRINTTHENEXTNUM:
;calculate the vale of divisor
MOV BH,DL
SUB BH,01H
MOV AL,1
MOV CL,10
MULTIPLYBWITHFACTOR:
CMP BH,0H
JE EXITMULTIPLYINGBBYAFACTOR
MUL CL
DEC BH
JMP MULTIPLYBWITHFACTOR
EXITMULTIPLYINGBBYAFACTOR:
MOV BL,AL
;calculate the result of division
MOV AL,DH
MOV AH,0H
DIV BL ;AL = AX/BL , AH = AX%BL
MOV DH,AH
ADD AL,'0'
;print the number on the screen
MOV AH,09H
MOV BH,0H
MOV BL,BackColor
MOV CL,4
SHL BL,CL
OR BL,forColor
MOV CX,1H
INT 10H
PUSH DX
;get the cursor position and adjust it
MOV BH,0H
MOV AH,03H ;DH : row ,DL : column
INT 10H
;then increment the column number and set the new cursor position to it
INC DL
MOV AH,02H
INT 10H
POP DX
;repeat
DEC DL
JNZ BEGINTOPRINTTHENEXTNUM
ENDM
;==========================================================================
;==================================MACRO===================================
;this is a macro to display a word
displayWordByConvertingItToAscii MACRO num,forColor,BackColor
;the idea of this function is that it takes a nuumber like 232 , it divides it first by 100 then it pints 2
;then the remainder is 32 , it takes this remainder and divides it by 10 then it prints 3
;then the remainder is 2 , t takes this remainder and divide it by 1 and then it prints 2
LOCALS @@ ;this will define any lable with prefix @@ to be a local variable
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV DX,num
MOV BL,5
@@BEGINTOPRINTTHENEXTNUM:
;calculate the vale of divisor
MOV AH,0H
MOV BH,BL
SUB BH,01H
MOV AL,1
MOV CX,10
@@MULTIPLYBWITHFACTOR:
CMP BH,0H
JE @@EXITMULTIPLYINGBBYAFACTOR
PUSH DX
MUL CX
POP DX
DEC BH
JMP @@MULTIPLYBWITHFACTOR
@@EXITMULTIPLYINGBBYAFACTOR:
PUSH BX
MOV BX,AX
;calculate the result of division
MOV AX,DX
MOV DX,0
DIV BX ;AX = (DX AX)/BX , DX = (DX AX)%BX
ADD AL,'0'
;print the number on the screen
MOV AH,09H
MOV BH,0H
MOV BL,BackColor
MOV CL,4
SHL BL,CL
OR BL,forColor
MOV CX,1H
INT 10H
PUSH DX
;get the cursor position and adjust it
MOV BH,0H
MOV AH,03H ;DH : row ,DL : column
INT 10H
;then increment the column number and set the new cursor position to it
INC DL
MOV AH,02H
INT 10H
POP DX
POP BX
;repeat
DEC BL
JNZ @@BEGINTOPRINTTHENEXTNUM
POP DX
POP CX
POP BX
POP AX
ENDM
;==========================================================================
;==================================MACRO===================================
;this is a macro to display a word => this is a special micro
displaySourceNumberByConvertingItToAscii MACRO num,forColor,BackColor