-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpong.asm
1712 lines (1544 loc) · 81.1 KB
/
pong.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
; Trying to disp score
.model small
.stack 64
.data
; ========== CHAT MODULE VARIABLES ==========
TRANS_MESSAGE DB '-This is the transmitter PC-', '$'
TRANS_MSG db 15, ?, 15 dup('$')
;PREPARE_FOR_SENDING DB 'SENDING: "', 0AH, 0DH, '$'
DONE_SENDING DB 0AH, 0DH, '$'
CURSER_ROW DB 1
CURSER_COL DB 1
END_CHAT_MESSAGE_PART1 DB '-To end chatting with $'
LENGTH_END_CHAT_MESSAGE EQU 22
END_CHAT_MESSAGE_PART2 DB 'Press F3$'
;DASHED_LINE db '--------------------------------------------------------------------------------','$'
; TO RECEIVE
CURSER_ROW_REC DB 16
CURSER_COL_REC DB 1
RECEIVE_MSG db 15, ?, 15 dup('$'), 0AH, 0DH,'$'
PREPARE_RECEIVE_MSG db 'PLAYER: ', '$'
PREPARE_SEND_MSG db 'PLAYER: ', '$'
REASSIGN_VAR db 24h
; ========== VARS TO CONTROLL COLLESION ==========
WINDOW_WIDTH dw 280h ; 320 Pixels 640
WINDOW_HEIGHT dw 165h ; 120 Pixels 480 => old value 180 <=
WINDOW_BOUNDS DW 6h ; to check collesion early
; ========== Status bar variables ==========
STATUS_BAR_START_ROW_UPPER_PART db 22 ; the start of the status bar => Score part
STATUS_BAR_START_ROW_LOWER_PART db 28 ; the start of the status bar => end game part
STATUS_BAR_START_ROW_MIDDLE_PART db 25 ; the start of the status bar => in-game chat part
LEFT_PLAYER_INGAME_MESSAGE DB 35, ?, 35 dup('$')
RIGHT_PLAYER_INGAME_MESSAGE DB 35, ?, 35 dup('$')
FLAG_lEFT_PLAYER_MESSAGE DB 00H ; To check if a string was entered before
FLAG_RIGHT_PLAYER_MESSAGE DB 00H
TO_CONCATINATE_STRINGS DB ' : $'
SWITCH_BETWEEN_PLAYERS DB 'To switch the chat with the other player Press enter then F5, ESC => end chat','$'
; ========== VARS TO CONTROL MOVEMENT ==========
OLD_TIME DB 0 ; old time
BALL_ORIGINAL_X DW 140h ; X-position of the point of the center
BALL_ORIGINAL_Y DW 0c0h ; Y-position of the point of the center
; ========== VARS TO DROW BALL ==========
BALL_X DW 140h ; "BALL" X position (cloumn)
BALL_Y DW 0c0h ; "BALL" y position (row - line)
BALL_SIZE DW 8h ; SIze of the ball 4-x 4-y
BALL_VELOCITY_X_ARR DW 05h,04h,03h,04h,02h,05h,03h ; velocity values in x direction for level 1
BALL_VELOCITY_X_ARR_2 DW 07h,03h,05h,04h,06h,02h,06h ; velocity values in x direction for level 2
BALL_VELOCITY_X DW 05h ; current ball velocity in x direction
BALL_VELOCITY_Y_ARR DW 02h,04h,05h,03h,05h,03h,04h ; velocity values in y direction for level 1
BALL_VELOCITY_Y_ARR_2 DW 02h,06h,05h,06h,03h,07h,04h ; velocity values in y direction for level 2
BALL_VELOCITY_Y DW 02h ; current ball velocity in y direction
BALL_VELOCITY_CURRENT DW 0 ; index of the current velocity to loop the arrays
BALL_VELOCITY_TOT DB 0
; ========== VARS TO DROW LEFT_PADDELS ==========
PADDLE_LEFT_X dw 0Ah ; "LEFT-PADDLE" X position (cloumn)
PADDLE_LEFT_Y DW 0Ah ; "LEFT-PADDLE" y position (row - line)
; ========== VARS TO DROW RIGHT_PADDELS ==========
PADDLE_RIGHT_X dw 624 ; "RIGHT-PADDLE" X position (cloumn)
PADDLE_RIGHT_Y DW 0Ah ; "RIGHT-PADDLE" y position (row - line)
; ========== PADDELS SIZE ==========
PADDLE_WIDTH dw 05h ; PADDLE Width (how many columns)
PADDLE_HEIGHT dw 3Fh ; PADDLE Height (how many rows)
PADDLE_ELONGATED_HEIGHT DW 6FH
PADDLE_LEFT_HEIGHT dw 3Fh
PADDLE_RIGHT_HEIGHT dw 3Fh
; ========== PADDEL VELOCITY ==========
PADDLE_VELOCITY dw 07h ; Paddel Vertical Velocity
; ========== VARS USED in GAVE_OVER Page ==========
msg db 'GAME OVER'
STR_LENGTH EQU 15
; ========== SCORE VARS ==========
OPEN_PRACIKT db ' ('
LEFT_PLAYER_SCORE db 30h ; First digit of the score of the player at the left
CONCATINATE db ':' ; used to display the score
RIGHT_PLAYER_SCORE db 30h ; First digit of the score of the player at the right
SCORE_LENGTH EQU 3 ; used to display the score
CLOSE_PRACIKT db ')'
MSG_TO_DISPLAY_SCORE__IN_GAME_MODE db "'s Score: ", '$'
; ========== LEVEL number ==========
SCORE_LIMIT db 35h
LEVEL db 00h
; ========== Player user name ==========
WLCOME_MSG_PLAYER1 db 'Please Enter your Name:', 10, 9, 9, 9, 9, '$'
WLCOME_MSG_PLAYER2 db 'Please Enter your Name:', 10, 9, 9, 9, 9, '$'
MY_USER_NAME_PLAYER1 db 15, ?, 15 dup('$'), '$'
MY_USER_NAME_PLAYER2 db 15, ?, 15 dup('$'), '$'
WLCOME_MSG_LENGTH EQU 28
LAST_MSG db 'Please Press any key to continue', '$'
ERROR_NAME_MSG db 10, 9, 'Your name should start with a letter, Please enter it again: ','$'
DASHED_LINE db '--------------------------------------------------------------------------------','$'
; ========== Transition between level One and Two ==========
trans_msg_level db 'LEVEL "2"'
trans_msg_LENGTH EQU 9
; ========== Main Screen variables ==========
start_chatting_msg db '*To Start chatting press F1','$'
start_PongGame_msg db '*To Start Pong game press F2','$'
end_game_msg db '*To end the program press ESC','$'
start_row db 9 ; row position of main menu message
start_column db 25 ; row position of main menu message
end_game_msg_part1 db '-To end the game with ', '$'
end_game_msg_part2 db 'Press F4', '$'
dummy_variable_to_count_strings_length db 0h
; ===========Elongation Card Variables=========
Is_Two db 2h
NEW_PADDLE_HEIGHT db 2fh
LEFT_PADDLE_FLAG_HEIGHT db 0h
RIGHT_PADDLE_FLAG_HEIGHT db 0h
ELONGATION_ONCE_LEFT DB 00H
ELONGATION_ONCE_RIGHT DB 00H
; ===================freeze card variables================
Is_Three db 3h
Right_Freeze_Flag db 0h
Left_Freeze_Flag db 0h
Froze_Once_Left db 00H
Froze_Once_Right db 00H
; ==================DOUBLE CARD VARIABLES==================
COLLISION_COUNTER DB 00H
.code
main proc
mov ax,@data
mov ds, ax
call USER_NAME_PLAYER1
call USER_NAME_PLAYER2
START_GAME:
mov LEFT_PLAYER_SCORE, 30h
mov RIGHT_PLAYER_SCORE, 30h
call MAIN_MENU
CHECK_AGAIN_ON_KEYPRESSED:
mov ah,00h ; get keypress from user
int 16h
cmp ah, 03Bh ; Check if F1 was pressed (Scan code of F1 = 3B )
JZ CHATTING_MODE
cmp ah, 03Ch ; Check if F2 was pressed (Scan code of F2 = 3C )
JZ GAME_MODE
cmp ah, 01h ; Check if ESC was pressed (Scan code of ESC = 01 )
JZ EXIT2
; else none of the keys corresponds to a valid command (take a keypress again)
jmp CHECK_AGAIN_ON_KEYPRESSED
EXIT2:
mov ah, 04ch
int 21h
CHATTING_MODE:
call CHAT_MODE
jmp START_GAME
GAME_MODE:
call CLEAR_SCREEN
CHECK_TIME:
; get system time, more information @"http://spike.scu.edu.au/~barry/interrupts.html#ah2c"
mov ah, 2Ch ; get the system time
int 21h ; Return: CH = hour CL = minute DH = second DL = 1/100 seconds
cmp dl, OLD_TIME ; compare old time with the one just returned from the system
JE CHECK_TIME ; if (the same) THEN { check Time again;} ELSE { continue;}
mov OLD_TIME, dl ; OLD_TIME := store current time
; clear screen to draw next frame
call CLEAR_SCREEN ; we create the Illosion of movement by "Clear - move - draw - clear ...."
call STATUS_BAR
mov ah,01h ; get keypress from user to check if user pressed F4
int 16h
cmp ah, 03Eh ; Check if F4 was pressed (Scan code of F4 = 01 )
JE START_GAME
call MOV_BALL ; move the ball
call DRAW_BALL ; draw the ball
CAll CHECK_ELONGATE_CARD ;call the Elongate card
CAll CHECK_FREZE_CARD ;call the freeze card
call MOVE_PADDLES ; move paddles
call DRAW_PADDLES ; draw paddles
call DRAW_SCORE ; draw score
; if reached the limit score of level one
mov al, SCORE_LIMIT
cmp LEFT_PLAYER_SCORE, al
JE NEXT_LEVEL
mov al, SCORE_LIMIT
cmp RIGHT_PLAYER_SCORE, al
JE NEXT_LEVEL
jmp CHECK_TIME ; loop again
NEXT_LEVEL:
cmp LEVEL, 01h
JE GAME_OVER_ALERT
;transferring x values for velocity from the array specified for level 2
mov cx,7 ; the number of possible values for velocity
mov di,offset BALL_VELOCITY_X_ARR ; the old array to change valuues
mov si,offset BALL_VELOCITY_X_ARR_2 ; the array to copy values from
REP MOVSW ; trasferring vlues
;transferring y values for velocity from the array specified for level 2
mov cx,7 ; the number of possible values for velocity
mov di,offset BALL_VELOCITY_Y_ARR ; the old array to change valuues
mov si,offset BALL_VELOCITY_Y_ARR_2 ; the array to copy values from
REP MOVSW ; trasferring vlues
mov LEVEL, 01h ; previous value was 0
mov SCORE_LIMIT, 39h ; 39 = '9', previous value was 35h = '5'
call CLEAR_SCREEN
call TRANSITION
jmp CHECK_TIME
GAME_OVER_ALERT:
call CLEAR_SCREEN
call GAME_OVER
; Enters Infinte Loop
jmp $
; return to operating system
EXIT:
mov ah,04ch ; "INT 21h, ah=04Ch" return to the operating system
int 21h ; Excute according to the above configurations "ah" > return to the operating system
main endp
;========================================================================== USER NAME PROCEDURE ==========================================================================
;=============== Player 1 ===============
USER_NAME_PLAYER1 PROC NEAR
mov ah, 0h ; set video mode
mov al, 03h ; configure video mode settings
int 10h
;Set cursor position to row 9 and column 25 and print welcome message
mov ah, 02h ; int 10h on ah = 02h => Set cursor position
mov dh, start_row ; row 9
mov dl, start_column ; column 25
int 10h
mov ah , 09h
mov dx, offset WLCOME_MSG_PLAYER1
int 21h
; Wait user input and validate it => should start with a letter
; should exist between 41h 'A' - 5Ah 'Z' or between 61h 'a' - 7Ah 'z'
TAKE_INPUT_AGAIN:
mov ah, 0Ah ; get input from user
mov dx, offset MY_USER_NAME_PLAYER1
int 21h
mov ah, MY_USER_NAME_PLAYER1[2] ; move first character to ah to check on it
cmp ah, 40h ; if character greater than 'A' => check if it is less than 'Z'
JG CHECK_LESS_CAPITAL_Z ; else => check if it is between 'a' and 'z'
CHECK_SMALL_CHARACTERS:
cmp ah, 60h ; if character greater than 'a' => check if it is less than 'z'
JG CHECK_LESS_SMALL_Z ; else => invalid character, take input again
mov ah , 09h
mov dx, offset ERROR_NAME_MSG ; print error message and loop again
int 21h
jmp TAKE_INPUT_AGAIN
CHECK_LESS_CAPITAL_Z:
mov ah, MY_USER_NAME_PLAYER1[2]
cmp ah, 5Bh
JL CONTINUE ; if character less than 'Z' => valid character and continue the program
jmp CHECK_SMALL_CHARACTERS ; else => it could be lower case character => check them
CHECK_LESS_SMALL_Z:
mov ah, MY_USER_NAME_PLAYER1[2]
cmp ah, 7Bh
JL CONTINUE ; if character less than 'Z' => valid character and continue the program
mov ah , 09h ; else => print error message and loop again
mov dx, offset ERROR_NAME_MSG
int 21h
jmp TAKE_INPUT_AGAIN
CONTINUE:
;Set cursor position to row 9 and column 25 and print this message 'Press any key to continue'
mov ah,03h ; get cursor current position
int 10h
mov ah, 02h ; int 10h on ah = 02h => Set cursor position
add dh, 1 ; row 13
mov dl, start_column ; column 25
int 10h
mov ah , 09h
mov dx, offset LAST_MSG
int 21h
;Read any key to continue
mov ah, 00H
int 16h
ret
USER_NAME_PLAYER1 ENDP
;=============== Player 2 ===============
USER_NAME_PLAYER2 PROC NEAR
mov ah, 0h ; set video mode
mov al, 03h ; configure video mode settings
int 10h
;Set cursor position to row 9 and column 25 and print welcome message
mov ah, 02h ; int 10h on ah = 02h => Set cursor position
mov dh, start_row ; row 9
mov dl, start_column ; column 25
int 10h
mov ah , 09h
mov dx, offset WLCOME_MSG_PLAYER2
int 21h
; Wait user input and validate it => should start with a letter
; should exist between 41h 'A' - 5Ah 'Z' or between 61h 'a' - 7Ah 'z'
TAKE_INPUT_AGAIN_P2:
mov ah, 0Ah ; get input from user
mov dx, offset MY_USER_NAME_PLAYER2
int 21h
mov ah, MY_USER_NAME_PLAYER2[2] ; move first character to ah to check on it
cmp ah, 40h ; if character greater than 'A' => check if it is less than 'Z'
JG CHECK_LESS_CAPITAL_Z_P2 ; else => check if it is between 'a' and 'z'
CHECK_SMALL_CHARACTERS_P2:
cmp ah, 60h ; if character greater than 'a' => check if it is less than 'z'
JG CHECK_LESS_SMALL_Z_P2 ; else => invalid character, take input again
mov ah , 09h
mov dx, offset ERROR_NAME_MSG ; print error message and loop again
int 21h
jmp TAKE_INPUT_AGAIN_P2
CHECK_LESS_CAPITAL_Z_P2:
mov ah, MY_USER_NAME_PLAYER2[2]
cmp ah, 5Bh
JL CONTINUE_P2 ; if character less than 'Z' => valid character and continue the program
jmp CHECK_SMALL_CHARACTERS_P2 ; else => it could be lower case character => check them
CHECK_LESS_SMALL_Z_P2:
mov ah, MY_USER_NAME_PLAYER2[2]
cmp ah, 7Bh
JL CONTINUE_P2 ; if character less than 'Z' => valid character and continue the program
mov ah , 09h ; else => print error message and loop again
mov dx, offset ERROR_NAME_MSG
int 21h
jmp TAKE_INPUT_AGAIN_P2
CONTINUE_P2:
;Set cursor position to row 9 and column 25 and print this message 'Press any key to continue'
mov ah,03h ; get cursor current position
int 10h
mov ah, 02h ; int 10h on ah = 02h => Set cursor position
add dh, 1 ; row 13
mov dl, start_column ; column 25
int 10h
mov ah , 09h
mov dx, offset LAST_MSG
int 21h
;Read any key to continue
mov ah, 00H
int 16h
ret
USER_NAME_PLAYER2 ENDP
;========================================================================== MOVE BALL PROCEDURE ==========================================================================
; this procedure handels all the logic behind setting the ball's position
MOV_BALL PROC NEAR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "Horizantal Movement" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ax, BALL_VELOCITY_X ; how mush shall the ball move in the x-direction
add BALL_X, ax ; x-position(ball) = x-position(ball) + Velocity(X) "Horizantal"
; Check if their is collesions with the right boundries
mov ax, WINDOW_BOUNDS ; left boundry
cmp BALL_X, ax ; compares the x-position(ball) ~ left boundry
JL RESET_POSITION_LEFT ; IF (less) {THEN Collesion with left Boundry;} ELSE {continue;}
; Check if their is collesions with the left boundrie
mov ax, WINDOW_WIDTH ; Window width
sub ax, BALL_SIZE ; size of the ball
sub ax, WINDOW_BOUNDS ; right boundry
CMP BALL_X, ax ; compare x-position(ball) ~ [Window width - size of the ball - right boundry]
JG RESET_POSITION_RIGHT ; IF (Greater) {THEN Collesion with right Boundry;} ELSE {continue;}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "Vertical Movement" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ax, BALL_VELOCITY_Y ; how mush shall the ball move in the Y-direction
add BALL_Y, ax ; Y-position(ball) = Y-position(ball)+ Velocity(Y) "Vertical"
; Check if their is collesions with the upper boundries
mov ax, WINDOW_BOUNDS ; Upper boundry
cmp BALL_Y, ax ; compares the y-position(ball) ~ Upper boundry
JL far ptr NEG_VELOCITY_Y_TEMP_TRANS ; IF (less) {THEN Collesion with Upper Boundry;} ELSE {continue;}
; Check if their is collesions with the lower boundries
mov ax, WINDOW_HEIGHT ; Window height
sub ax, BALL_SIZE ; size of the ball
sub ax, WINDOW_BOUNDS ; lower boundry
cmp BALL_Y, ax ; compare Y-position(ball) ~ [Window height - size of the ball - lower boundry]
JG far ptr NEG_VELOCITY_Y_TEMP_TRANS ; IF (Greater) {THEN Collesion with lower Boundry;} ELSE {continue;}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
jmp NEXT
NEG_VELOCITY_Y_TEMP_TRANS:
JMP NEG_VELOCITY_Y_TEMP
; return if After setting the ball to center point as a result for hetting any of the left of right boundry
RESET_POSITION_LEFT:
cmp COLLISION_COUNTER,0Ah
JL NORMAL_POINTS_RIGHT
ADD RIGHT_PLAYER_SCORE,2
MOV COLLISION_COUNTER,00H
JMP DOUBLE_POINTS_RIGHT
NORMAL_POINTS_RIGHT:
add RIGHT_PLAYER_SCORE, 1
DOUBLE_POINTS_RIGHT:
; added for freeze card
mov Left_Freeze_Flag,00H
; end of freeze card
; added for Elongation card
MOV AX ,PADDLE_HEIGHT
MOV PADDLE_LEFT_HEIGHT,AX
; finish addinf for elongation card
ADD BALL_VELOCITY_CURRENT,2 ; to get the index of the next velocity(2 as it is an array of words)
INC BALL_VELOCITY_TOT
cmp BALL_VELOCITY_CURRENT,12h ; the last index in our array
JLE CHANGING_VELOCITY ;when we are in the appropriate range
mov BALL_VELOCITY_CURRENT,0h ;if we got away of the array we start again from 0 index
call RESET_BALL_POSITION
ret
RESET_POSITION_RIGHT:
cmp COLLISION_COUNTER,0ah
JL NORMAL_POINTS_LEFT
ADD LEFT_PLAYER_SCORE,2
MOV COLLISION_COUNTER,00H
JMP DOUBLE_POINTS_LEFT
NORMAL_POINTS_LEFT:
add LEFT_PLAYER_SCORE, 1
DOUBLE_POINTS_LEFT:
; added for freeze card right
mov Right_Freeze_Flag ,00H
; end of freeze card right
; added for elongation card
MOV AX ,PADDLE_HEIGHT
MOV PADDLE_RIGHT_HEIGHT,AX
; finish add for elongation
ADD BALL_VELOCITY_CURRENT,2 ; to get the index of the next velocity(2 as it is an array of words)
INC BALL_VELOCITY_TOT
cmp BALL_VELOCITY_CURRENT,12h ; the last index in our array
JLE CHANGING_VELOCITY ;when we are in the appropriate range
mov BALL_VELOCITY_CURRENT,0h ;if we got away of the array we start again from 0 index
jmp CHANGING_VELOCITY
NEG_VELOCITY_Y_TEMP: jmp NEG_VELOCITY_Y
CHANGING_VELOCITY:
lea bx,BALL_VELOCITY_X_ARR ; gettig the offset of the x array
add bx,BALL_VELOCITY_CURRENT ; getting the value in the current index
mov ax,[bx] ; getting the value in ax in order to move it to another place in memory
mov BALL_VELOCITY_X,ax ; refreshing the value of x velocity
lea bx,BALL_VELOCITY_Y_ARR ; gettig the offset of the y array
add bx,BALL_VELOCITY_CURRENT ; getting the value in the current index
mov ax,[bx] ; getting the value in ax in order to move it to another place in memory
mov BALL_VELOCITY_X,ax
mov al,BALL_VELOCITY_TOT
mov BALL_VELOCITY_Y,ax ; refreshing the value of y velocity
mov al,BALL_VELOCITY_TOT
mov bl,04
div bl
cmp ah,0
JE AFTER_CHANGING_VELOCITY
cmp ah,1
JE NegateX
cmp ah,2
JE NegateXY
cmp ah,3
JE NegateY
NegateX:neg BALL_VELOCITY_X
JMP AFTER_CHANGING_VELOCITY
NegateY:neg BALL_VELOCITY_Y
JMP AFTER_CHANGING_VELOCITY
NegateXY:neg BALL_VELOCITY_X
neg BALL_VELOCITY_Y
AFTER_CHANGING_VELOCITY: call RESET_BALL_POSITION
ret
;RESET_POSITION:
call RESET_BALL_POSITION
ret
; return if After reversing the velocity of the ball due to hetting any of the Upper of lower boundry
NEG_VELOCITY_Y:
NEG BALL_VELOCITY_Y
ret
NEXT:
; CHECK COLLISION, morre information @"https://www.azurefromthetrenches.com/introductory-guide-to-aabb-tree-collision-detection/"
; check ball collision with the right paddle
; CONDITION: "maxx1 > minx2" && "minx1 < maxx2" && "maxy1 > miny1" && "miny1 < maxy2"
; PROJECTION OF THE ABOVE CONDITION USING OUR VARIABLES:
; "maxx1=(BALL_X + BALL_Size)" > "minx2=PADDLE_RIGHT_X"
; &&
; "minx1=BALL_X" < "maxx2=(PADDLE_RIGHT_X + PADDLE_WIDTH)"
; &&
; "maxy1=(BALL_Y + BALL_SIZE)" > "miny1=PADDLE_RIGHT_Y"
; &&
; "miny1=BALL_Y" < "maxy2=(PADDLE_RIGHT_Y + PADDLE_HEIGHT)"
; [1]: (BALL_X + BALL_Size) > PADDLE_RIGHT_X
mov ax, BALL_X
add ax, BALL_SIZE ; (BALL_X + BALL_Size)
cmp ax, PADDLE_RIGHT_X ; [1]: compares the (BALL_X + BALL_Size) ~ PADDLE_RIGHT_X
JNG CHECK_COLLISION_LEFT_PADDLE ; IF (Greater) THEN {Collesion with right paddle;} ELSE {Check if their exist a collision with left paddle;}
; [2]: BALL_X < (PADDLE_RIGHT_X + PADDLE_WIDTH)
mov ax, PADDLE_RIGHT_X
add ax, PADDLE_WIDTH ; (PADDLE_RIGHT_X + PADDLE_WIDTH)
cmp BALL_X, ax ; [2]: compares the BALL_X ~ (PADDLE_RIGHT_X + PADDLE_WIDTH)
JNL CHECK_COLLISION_LEFT_PADDLE ; IF (LESS) THEN {Collesion with right paddle;} ELSE {Check if their exist a collision with left paddle;}
; [3]: (BALL_Y + BALL_SIZE) > PADDLE_RIGHT_Y
mov ax, BALL_Y
add ax, BALL_SIZE ; (BALL_Y + BALL_SIZE)
cmp ax, PADDLE_RIGHT_Y ; [3]: compares the (BALL_Y + BALL_SIZE) ~ PADDLE_RIGHT_Y
JNG CHECK_COLLISION_LEFT_PADDLE ; IF (Greater) THEN {Collesion with right paddle;} ELSE {Check if their exist a collision with left paddle;}
; [4]: BALL_Y < (PADDLE_RIGHT_Y + PADDLE_HEIGHT)
mov ax, PADDLE_RIGHT_Y
add ax, PADDLE_RIGHT_HEIGHT ; (PADDLE_RIGHT_Y + PADDLE_HEIGHT)
cmp BALL_Y, ax ; [4]: compares the BALL_Y ~ (PADDLE_RIGHT_Y + PADDLE_HEIGHT)
JNL CHECK_COLLISION_LEFT_PADDLE ; IF (LESS) THEN {Collesion with right paddle;} ELSE {Check if their exist a collision with left paddle;}
; THERE IS A COLLISION O_o with the right PADDLE
add COLLISION_COUNTER,1h ; Counts the coolison with paddles
NEG BALL_VELOCITY_X ; reverse the X-Velosity(Ball)
ret
CHECK_COLLISION_LEFT_PADDLE:
; check ball collision with the left paddle
; [1]: (BALL_X + BALL_Size) > PADDLE_LEFT_X
; &&
; [2]: BALL_X < (PADDLE_LEFT_X + PADDLE_WIDTH)
; &&
; [3]: (BALL_Y + BALL_SIZE) > PADDLE_LEFT_Y
; &&
; [4]: BALL_Y < (PADDLE_LEFT_Y + PADDLE_HEIGHT)
; [1]: (BALL_X + BALL_Size) > PADDLE_LEFT_X
mov ax, BALL_X
add ax, BALL_SIZE ; (BALL_X + BALL_Size)
cmp ax, PADDLE_LEFT_X ; [1]: compares the (BALL_X + BALL_Size) ~ PADDLE_LEFT_X
JNG OUT_PROC ; IF (Greater) THEN {Collesion with left paddle;} ELSE {EXIT;}
; [2]: BALL_X < (PADDLE_LEFT_X + PADDLE_WIDTH)
mov ax, PADDLE_LEFT_X
add ax, PADDLE_WIDTH ; (PADDLE_LEFT_X + PADDLE_WIDTH)
cmp BALL_X, ax ; [2]: compares the BALL_X ~ (PADDLE_RIGHT_X + PADDLE_WIDTH)
JNL OUT_PROC ; IF (LESS) THEN {Collesion with left paddle;} ELSE {EXIT;}
; [3]: (BALL_Y + BALL_SIZE) > PADDLE_LEFT_Y
mov ax, BALL_Y
add ax, BALL_SIZE ; (BALL_Y + BALL_SIZE)
cmp ax, PADDLE_LEFT_Y ; [3]: compares the (BALL_Y + BALL_SIZE) ~ PADDLE_LEFT_Y
JNG OUT_PROC ; IF (Greater) THEN {Collesion with left paddle;} ELSE ELSE {EXIT;}
; [4]: BALL_Y < (PADDLE_LEFT_Y + PADDLE_HEIGHT)
mov ax, PADDLE_LEFT_Y
add ax, PADDLE_LEFT_HEIGHT ; (PADDLE_LEFT_Y + PADDLE_HEIGHT)
cmp BALL_Y, ax ; [4]: compares the BALL_Y ~ (PADDLE_LEFT_Y + PADDLE_HEIGHT)
JNL OUT_PROC ; IF (LESS) THEN {Collesion with left paddle;} ELSE ELSE {EXIT;}
; THERE IS A COLLISION O_o with the left PADDLE
add COLLISION_COUNTER,1h ; Counts the coolison with paddles
NEG BALL_VELOCITY_X ; reverse the X-Velosity(Ball)
ret
OUT_PROC:
; return if every thing is okay while setting the positions
ret
MOV_BALL ENDP
;========================================================================== DRAW SCORE PROCEDURE ==========================================================================
DRAW_SCORE PROC NEAR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Draw Left Player Score ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov si, @data ;moves to si the location in memory of the data segment
mov es, si ;moves to es the location in memory of the data segment
mov ah, 13h ;service to print string in graphic mode
mov al, 0 ;sub-service 0 all the characters will be in the same color(bl) and cursor position is not updated after the string is written
mov bh, 0 ;page number=always zero
mov bl, 0Ah ;color of the text (white foreground 1111 and black background 0000 )
mov cx, SCORE_LENGTH ;length of string
mov dl, 38 ;Column 0 > 40
mov dh, 2 ;Row 0 > 25
mov bp, offset LEFT_PLAYER_SCORE ;mov bp the offset of the string
int 10h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret
DRAW_SCORE ENDP
;========================================================================== MOVE PADDLES PROCEDURE ==========================================================================
; this procedure handels all the logic behind setting the paddles' positions
MOVE_PADDLES PROC NEAR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "LEFT PADDLE MOVEMENT" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Check if a key is pressed - DON't WAIT
mov ah, 01h ; Get Keyboard Status
int 16h ; Excute according to the above configurations "ah" - DON'T WAIT
JZ CHECK_RIGHT_PADDLE_MOVEMENT ; ZF = 0 if a key pressed >>> 1: check if a player is trying to move the right paddle
;;;;;;;;;;;;;;;;;; WHICH KEY WAS PRESSED ;;;;;;;;;;;;;;;;;
; to check which key was pressed
mov ah, 00h ; read the char > al
int 16h ; Excute according to the above configurations "ah"
; check for the freezing state of the leftplayer
cmp Left_Freeze_Flag,1H
JE CHECK_RIGHT_PADDLE_MOVEMENT
; check if 'w', 'W' was pressed
CMP al, 77h ; 'w' = 77h
je MOVE_LEFT_PADDLE_UP ; move the left paddle up
CMP al, 57h ; 'W' = 57h
je MOVE_LEFT_PADDLE_UP ; move the left paddle up
; check if 's', 'S' was pressed
CMP al, 73h ; 's' = 73h
je MOVE_LEFT_PADDLE_DOWN ; move the left paddle down
CMP al, 53h ; 'S' = 53h
je MOVE_LEFT_PADDLE_DOWN ; move the left paddle down
; Nothing of the expecting keys THEN {Check if they are related to the right paddel;}
JMP CHECK_RIGHT_PADDLE_MOVEMENT
;;;;;;;;;;;;;;;; END: WHICH KEY WAS PRESSED ;;;;;;;;;;;;;;;
; Move left paddle "up"
MOVE_LEFT_PADDLE_UP:
mov ax, PADDLE_VELOCITY ; how mush shall the paddle move in the Y-direction
sub PADDLE_LEFT_Y, ax ; mov paddle
mov ax, WINDOW_BOUNDS ; upper boundry
cmp PADDLE_LEFT_Y, ax ; compares the y-position(paddel) ~ upper boundry
JL FIX_LEFT_PADDLE_TOP_POSITION ; IF(LESS) THEN {Fix the position of the left paddle;} ELSE {continue;}
JMP CHECK_RIGHT_PADDLE_MOVEMENT ; check if a player is trying to move the right paddle
; correct the paddle position if it exceded the upper boundry
FIX_LEFT_PADDLE_TOP_POSITION:
mov ax, WINDOW_BOUNDS ; upper boundry
mov PADDLE_LEFT_Y, ax ; sets the Y-position(paddle) := upper boundry
jmp CHECK_RIGHT_PADDLE_MOVEMENT ; check if a player is trying to move the right paddle
; Move left paddle "down"
MOVE_LEFT_PADDLE_DOWN:
mov ax, PADDLE_VELOCITY ; how mush shall the paddle move in the Y-direction
add PADDLE_LEFT_Y, ax ; mov paddle
; check if the left paddle y is correct
mov ax, WINDOW_HEIGHT ; Window height "the height of the screen"
sub ax, WINDOW_BOUNDS ; the lower boundry
sub ax, PADDLE_LEFT_HEIGHT ; the height of the paddle
cmp PADDLE_LEFT_Y, ax ; compare Y-position(paddle) ~ [Window height - lower boundry - height of the paddle]
JG FIX_PADDLE_LEFT_BOTTOM_POSITION ; IF (Greater) {Fix the position of the right paddle;} ELSE {continue;}
JMP CHECK_RIGHT_PADDLE_MOVEMENT ; check if a player is trying to move the right paddle
; correct the paddle position if it exceded the lower boundry
FIX_PADDLE_LEFT_BOTTOM_POSITION: ; FIX: ELONGATION WITHOUT PRESSING KEYS
mov PADDLE_LEFT_Y, ax ; sets the Y-position(paddle) := [Window height - lower boundry - height of the paddle]
jmp CHECK_RIGHT_PADDLE_MOVEMENT ; check if a player is trying to move the right paddle
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "END: LEFT PADDLE MOVEMENT" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "RIGHT PADDLE MOVEMENT" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; check if a player is trying to move the right paddle
CHECK_RIGHT_PADDLE_MOVEMENT:
;;;;;;;;;;;;;;;;;; WHICH KEY WAS PRESSED ;;;;;;;;;;;;;;;;;
; check for the freezing state of the leftplayer
cmp Right_Freeze_Flag,1H
JE EXIT_PROC
; check if up_arrow key was pressed
CMP ah, 72 ; 72 is the scan code of the up arrow key
je MOVE_RIGHT_PADDLE_UP ; move the right paddle up
; check if down_arrow was pressed
CMP ah, 80 ; 80 is the scan code of the down arrow key
je MOVE_RIGHT_PADDLE_DOWN ; move the right paddle down
; Nothing of the expecting keys THEN {EXIT;}
JMP EXIT_PROC
;;;;;;;;;;;;;;;; END: WHICH KEY WAS PRESSED ;;;;;;;;;;;;;;;
; Move right paddle "up"
MOVE_RIGHT_PADDLE_UP:
mov ax, PADDLE_VELOCITY ; how mush shall the paddle move in the Y-direction
sub PADDLE_RIGHT_Y, ax ; mov paddle
mov ax, WINDOW_BOUNDS ; upper boundry
cmp PADDLE_RIGHT_Y, ax ; compares the y-position(paddel) ~ upper boundry
JL FIX_PADDLE_RIGHT_TOP_POSITION ; IF(LESS) THEN {Fix the position of the right paddle;} ELSE {continue;}
JMP EXIT_PROC ; Everything went smoothly THEN {DONE, EXIT;}
; correct the paddle position if it exceded the upper boundry
FIX_PADDLE_RIGHT_TOP_POSITION:
mov ax, WINDOW_BOUNDS ; upper boundry
mov PADDLE_RIGHT_Y, ax ; sets the Y-position(paddle) := upper boundry
jmp EXIT_PROC ; Everything went smoothly THEN {DONE, EXIT;}
; Move right paddle "down"
MOVE_RIGHT_PADDLE_DOWN:
mov ax, PADDLE_VELOCITY ; how mush shall the paddle move in the Y-direction
add PADDLE_RIGHT_Y, ax ; mov paddle
mov ax, WINDOW_HEIGHT ; Window height "the height of the screen"
sub ax, WINDOW_BOUNDS ; the lower boundry
sub ax, PADDLE_RIGHT_HEIGHT ; the height of the paddle
cmp PADDLE_RIGHT_Y, ax ; compare Y-position(paddle) ~ [Window height - lower boundry - height of the paddle]
JG FIX_PADDLE_RIGHT_BOTTOM_POSITION ; IF (Greater) {Fix the position of the right paddle;} ELSE {continue;}
JMP EXIT_PROC ; Everything went smoothly THEN {DONE, EXIT;}
; correct the paddle position if it exceded the lower boundry
FIX_PADDLE_RIGHT_BOTTOM_POSITION:
mov PADDLE_RIGHT_Y, ax ; sets the Y-position(paddle) := [Window height - lower boundry - height of the paddle]
jmp EXIT_PROC ; Everything went smoothly THEN {DONE, EXIT;}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "END: Right PADDLE MOVEMENT" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EXIT_PROC:
ret
MOVE_PADDLES ENDP
;======================================================================= RESET BALL POSITION PROCEDURE =======================================================================
; this ptocedure recet the ball to the center of the screen
RESET_BALL_POSITION PROC NEAR
mov ax, BALL_ORIGINAL_X ; the X-position(center)
mov BALL_X, ax ; X-position(ball)
mov ax, BALL_ORIGINAL_Y ; Y-position(center)
mov BALL_Y, ax ; Y-position(ball)
ret
RESET_BALL_POSITION ENDP
;========================================================================== DRAW BALL PROCEDURE ==========================================================================
; This procedure handels all the logic behind drawing the ball
DRAW_BALL PROC NEAR
mov cx, BALL_X ; set the initial X-position(ball) (Column)
mov dx, BALL_Y ; set the initial Y-position(ball) (raws - lines)
; Start drawing
DRAW_BALL_HORIZANTAL:
; Configure the screen to the draw pexil mode
mov ah, 0Ch ; draw pixil mode
mov al, 0Eh ; white color (ball)
mov bh, 00h ; set page number
int 10h ; Excute according to the above configurations "ah, al, bh"
INC CX ; cx:"x-position" = cx:"x-position" + 1
; AX := cx - X-position(ball)
mov ax, cx ; the new X-position(ball)
sub ax, BALL_X ; AX := new X-position(ball) - previous X-position(ball)
; Check IF (AX >= BALL_SIZE) THEN {Draw the next "line || raw";} ELSE {continue;}
cmp ax, BALL_SIZE ; AX := Size(Ball)
JNG DRAW_BALL_HORIZANTAL ; continue drawing the current "line || row"
; "NEW HORIZANTAL line"
mov cx, BALL_X ; set cx to initial X-position(ball) (Column)
inc dx ; go to the next line
; AX := DC - Y-position(ball)
mov ax, dx ; the new Y-position(ball)
sub ax, BALL_Y ; AX := new Y-position(ball) - previous Y-position(ball)
; Check IF (AX >= BALL_SIZE) THEN {EXIT;} ELSE {continue;}
cmp ax, BALL_SIZE ; AX := Size(Ball)
JNG DRAW_BALL_HORIZANTAL ; continue drawing the current "line || row"
; EXIT
ret
DRAW_BALL ENDP
;========================================================================== DRAW PADDLES PROCEDURE ==========================================================================
; This procedure handels all the logic behind drawing the paddles
DRAW_PADDLES PROC NEAR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "Drawing The left paddle" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov cx, PADDLE_LEFT_X ; set the initial X-position(LEFT_paddle) (Column)
mov dx, PADDLE_LEFT_Y ; set the initial Y-position(LEFT_paddle) (raws - lines)
DRAW_PADDLE_LEFT_HORIZANTAL:
; Configure the screen to the draw pexil mode
mov ah, 0Ch ; draw pixil mode
mov al, RIGHT_PLAYER_SCORE
cmp LEFT_PLAYER_SCORE, al
JG GREEN_LEFT
JL RED_LEFT
mov al, 0Fh ; white color (paddle)
jmp WHIET_LEFT
GREEN_LEFT:
mov al, 0Ah ; green color
jmp WHIET_LEFT
RED_LEFT:
mov al, 04h ; RED color
jmp WHIET_LEFT
WHIET_LEFT:
mov bh, 00h ; set page number
int 10h ; Excute according to the above configurations "ah, al, bh"
INC CX ; cx:"x-position" = cx:"x-position" + 1
; AX := cx - X-position(paddle)
mov ax, cx ; the new X-position(paddle)
sub ax, PADDLE_LEFT_X ; AX := new X-position(paddle) - previous X-position(paddle)
; Check IF (AX >= Paddle Width) THEN {Draw the next "line || raw";} ELSE {continue;}
cmp ax, PADDLE_WIDTH ; AX := Width(paddle)
JNG DRAW_PADDLE_LEFT_HORIZANTAL ; continue drawing the current "line || row"
; "NEW HORIZANTAL line"
mov cx, PADDLE_LEFT_X ; set cx to initial X-position(paddle) (Column)
inc dx ; go to the next line
; AX := DC - Y-position(paddle)
mov ax, dx ; the new Y-position(paddle)
sub ax, PADDLE_LEFT_Y ; AX := new Y-position(paddle) - previous Y-position(paddle)
; Check IF (AX >= Paddle Height) THEN {Draw The Right Paddle;} ELSE {continue;}
cmp ax, PADDLE_LEFT_HEIGHT ; AX := Height(paddle)
JNG DRAW_PADDLE_LEFT_HORIZANTAL ; continue drawing the current "line || row"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "END: Drawing The left paddle" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "Drawing The right paddle" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov cx, PADDLE_RIGHT_X ; set the initial X-position(RIGHT_paddle) (Column)
mov dx, PADDLE_RIGHT_Y ; set the initial Y-position(RIGHT_paddle) (raws - lines)
DRAW_PADDLE_RIGHT_HORIZANTAL:
; Configure the screen to the draw pexil mode
mov ah, 0Ch ; draw pixil mode
mov al, LEFT_PLAYER_SCORE
cmp RIGHT_PLAYER_SCORE, al
JG GREEN_RIGHT
JL RED_RIGHT
mov al, 0Fh ; white color (paddle)
jmp WHIET_RIGHT
GREEN_RIGHT:
mov al, 0Ah ; green color
jmp WHIET_RIGHT
RED_RIGHT:
mov al, 04h ; RED color
jmp WHIET_RIGHT
WHIET_RIGHT:
mov bh, 00h ; set page number
int 10h ; Excute according to the above configurations "ah, al, bh"
INC CX ; cx:"x-position" = cx:"x-position" + 1
; AX := cx - X-position(paddle)
mov ax, cx ; the new X-position(paddle)
sub ax, PADDLE_RIGHT_X ; AX := new X-position(paddle) - previous X-position(paddle)
; Check IF (AX >= Paddle Width) THEN {Draw the next "line || raw";} ELSE {continue;}
cmp ax, PADDLE_WIDTH ; AX := Width(paddle)
JNG DRAW_PADDLE_RIGHT_HORIZANTAL ; continue drawing the current "line || row"
; "NEW HORIZANTAL line"
mov cx, PADDLE_RIGHT_X ; set cx to initial X-position(paddle) (Column)
inc dx ; go to the next line
; AX := DC - Y-position(paddle)
mov ax, dx ; the new Y-position(paddle)
sub ax, PADDLE_RIGHT_Y ; AX := new Y-position(paddle) - previous Y-position(paddle)
; Check IF (AX >= Paddle Height) THEN {EXIT;} ELSE {continue;}
cmp ax, PADDLE_RIGHT_HEIGHT ; AX := Height(paddle)
JNG DRAW_PADDLE_RIGHT_HORIZANTAL ; continue drawing the current "line || row"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; "END: Drawing The right paddle" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ret
DRAW_PADDLES ENDP
;========================================================================== CLEAR SCREEN PROCEDURE ==========================================================================
; This procedure helps in creating the Illosion of movement by clearing the screen
CLEAR_SCREEN PROC NEAR
; set video mode, more information @"https://stanislavs.org/helppc/int_10-0.html"
mov ah, 00h ; set video mode
mov al, 12h ; configure video mode settings
int 10h ; Excute according to the above configurations "ah, al"
; set backgroud, more information @"https://stanislavs.org/helppc/int_10-b.html"
mov ah, 0bh ; Set color palette
mov bh, 00h ; palette color ID - to set background and border color
mov bl, 00h ; black color
int 10h ; Excute according to the above configurations "ah, al, bh"
ret
CLEAR_SCREEN ENDP
;========================================================================= STATUS BAR PROCEDURE =========================================================================
STATUS_BAR PROC NEAR
;Set cursor position to row 22 and column 0 and print a dashed line
mov ah, 02h
mov dh, STATUS_BAR_START_ROW_UPPER_PART ; row 22
mov dl, 0 ; column 0
int 10h
mov ah, 09h ; print dashed line
mov dx, offset DASHED_LINE
int 21h
; ========== Player 1 score ==========
;Set cursor position to row 23 and column 0 and print the score of the players
mov ah, 02h
mov al, STATUS_BAR_START_ROW_UPPER_PART
add al, 1
mov dh, al ; row 23
mov dl, 0 ; column 0
int 10h
mov ah, 09h ; print player's user name
mov dx, offset MY_USER_NAME_PLAYER1[2]
int 21h
;Count the length of the left player username to set the cursor position after it
mov SI, offset MY_USER_NAME_PLAYER1[2] ; move memory location of user name player to SI
mov ch, 0h ; prepare counter
STRING1_NOT_ENDED:
cmp byte PTR [SI], 24h ; compare current character with $ (end of string)
JE DONE_COUNTING1 ; if equal => exit the loop
INC ch ; increment counter
INC SI ; increment SI (to ge tnext memory location)
jmp STRING1_NOT_ENDED ; continue looping
DONE_COUNTING1:
;add ch, 30h
sub ch, 1h
mov ah, 02h ; Set cursor position
mov dh, al ; row 23
mov dl, ch ; column after the name's length
int 10h
mov ah, 09h ; print this message => 's score:
mov dx, offset MSG_TO_DISPLAY_SCORE__IN_GAME_MODE
int 21h
; display score of left player
mov ah, 02h ; print player's score
mov dl, LEFT_PLAYER_SCORE ; character t be printed
int 21h
; ========== player 2 score ==========
;Count the length of the left player username to set the cursor position after it
mov SI, offset MY_USER_NAME_PLAYER2[2] ; move memory location of user name player to SI
mov ch, 0h ; prepare counter
STRING4_NOT_ENDED:
cmp byte PTR [SI], 24h ; compare current character with $ (end of string)
JE DONE_COUNTING4 ; if equal => exit the loop
INC ch ; increment counter
INC SI ; increment SI (to ge tnext memory location)
jmp STRING4_NOT_ENDED ; continue looping
DONE_COUNTING4:
mov dummy_variable_to_count_strings_length, ch ; store counter in a dummy variable
;Count the length of "'s score: " message to set the cursor position after it
mov SI, offset MSG_TO_DISPLAY_SCORE__IN_GAME_MODE ; move memory location of user name player to SI
mov ch, 0h ; prepare counter
STRING5_NOT_ENDED:
cmp byte PTR [SI], 24h ; compare current character with $ (end of string)
JE DONE_COUNTING5 ; if equal => exit the loop
INC ch ; increment counter
INC SI ; increment SI (to ge tnext memory location)
jmp STRING5_NOT_ENDED ; continue looping
DONE_COUNTING5:
add ch, dummy_variable_to_count_strings_length
add ch, 2 ; to leave space for the score
;Set cursor position to row 23 and column 0 and print the score of the players
mov ah, 02h
mov al, STATUS_BAR_START_ROW_UPPER_PART
add al, 1
mov cl, 80 ; number of columns
sub cl, ch ; To get the starting column (Print the score from the right)
mov dh, al ; row 23
mov dl, cl ; calculated column number
int 10h
mov ah, 09h ; print player's user name
mov dx, offset MY_USER_NAME_PLAYER2[2]
int 21h
mov ah, 02h ; Set cursor position
mov dh, al ; row 23
add cl, dummy_variable_to_count_strings_length
mov dl, cl ; column after the name's length
int 10h
mov ah, 09h ; print this message => 's score:
mov dx, offset MSG_TO_DISPLAY_SCORE__IN_GAME_MODE
int 21h
; display score of right player
mov ah, 02h ; print player's score
mov dl, RIGHT_PLAYER_SCORE ; character t be printed
int 21h
;Set cursor position to row 24 and column 0 and print a dashed line
mov ah, 02h
mov al, STATUS_BAR_START_ROW_UPPER_PART
add al, 2
mov dh, al ; row 17
mov dl, 0 ; column 0
int 10h
mov ah, 09h ; print dashed line
mov dx, offset DASHED_LINE
int 21h
; ===================== In game chat =====================
mov ah,01h ; Check keyboard buffer has keypressed or not
int 16h ; ZF = 1 => keystroke not available, ZF = 0 => keystroke available
; Check if player inserted a string
cmp al,50h
JE PRINT_DASHED_LINE_FIRST ; CHECK if P was pressed
cmp al,70h
JE PRINT_DASHED_LINE_FIRST ; CHECK if p was pressed
JMP EXIT_IN_CHAT_GAME ; P not pressed => skip in game chat part
PRINT_DASHED_LINE_FIRST:
; Consume the character in keyboard buffer
mov ah,07h
int 21h
;Set cursor position to row 28 and column 0 and print a dashed line
mov ah, 02h
mov dh, STATUS_BAR_START_ROW_LOWER_PART ; row 28
mov dl, 0 ; column 0
int 10h
mov ah, 09h ; print dashed line
mov dx, offset DASHED_LINE
int 21h
;Print end game message
mov ah, 09h ; print this message => To end the game with
mov dx, offset SWITCH_BETWEEN_PLAYERS
int 21h
; draw paddles and ball to stop the game
IN_GAME_CHAT_LEFT_PLAYER:
call DRAW_PADDLES
call DRAW_BALL
call DRAW_SCORE
; This piece of code is just to clear the row for multiple usage (print a character multiple times in black color)
mov ah, 02h
mov dh, STATUS_BAR_START_ROW_MIDDLE_PART ; row 25
mov dl, 0 ; column 0
int 10h
mov ah, 09h
mov al, 'A'
mov bl, 00H
mov cx, 40
int 10h