-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.asm
1658 lines (1195 loc) · 32.6 KB
/
game.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
IDEAL
MODEL small
STACK 100h
MACRO PUSH_REGISTERS
push ax bx cx dx di si
ENDM
MACRO POP_REGISTERS
pop si di dx cx bx ax
ENDM
START_SCREEN equ 'Start.bmp'
MAIN_SCREEN equ 'Main.bmp'
HELP_SCREEN equ 'Help.bmp'
BIRD equ 'Bird.bmp'
BIRD_UP equ 'BirdUp.bmp'
ERASE_SCREEN equ 'Erase.bmp'
SCORE_TABLE equ 'Scores.txt'
BMP_WIDTH = 320
GAME_OVER equ 'GO.bmp'
PLAYER_SIZE = 15
PLAYER_AUTO_PIXEL_MOVEMENT = 2
PLAYER_MANUAL_PIXEL_MOVEMENT = 30
STARTING_PLAYER_Y_POSITION = 20
PLAYER_COLUMN = 30
FALSE = 0
TRUE = 1
POLE_WAIT_INTERVAL = 0
POLE_BOUNDARY = 0
POLE_COLOR = 2 ; Goes by graphic mode colors
POLE_WIDTH = 20
POLE_PIXEL_MOVEMENT = 2
FIRST_POLE_STARTING_POSITION = 100
FIRST_POLE_SPACE_STARTING_POSITION = 10
SECOND_POLE_STARTING_POSITION = 200
SECOND_POLE_SPACE_STARTING_POSITION = 10
THIRD_POLE_STARTING_POSITION = 300
THIRD_POLE_SPACE_STARTING_POSITION = 10
MINIMUM_SPACE_HEIGHT = 70
MAXIMUM_SPACE_HEIGHT = 90
BACKGROUND_COLOR = 9
GAME_OVER_RECTANGLE_COLOR = 0
GAME_OVER_COLUMN = 60
GAME_OVER_ROW = 60
GAME_OVER_WIDTH = 192
GAME_OVER_HEIGHT = 32
GAME_OVER_RECTANGLE_HEIGHT_CONSTANT = 50
GAME_OVER_RECTANGLE_CONSTANT = 10 ; works on x axis and y axis
DATASEG
MainName db MAIN_SCREEN , 0
HelpName db HELP_SCREEN , 0
StartName db START_SCREEN , 0
BirdName db BIRD, 0
BirdUpName db BIRD_UP, 0
EraseScreenName db ERASE_SCREEN, 0
ScoresName db SCORE_TABLE, 0
GameOverName db GAME_OVER, 0
FileHandle dw ?
Header db 54 dup(0)
Palette db 400h dup (0)
BmpLeft dw ?
BmpTop dw ?
BmpColSize dw ?
BmpRowSize dw ?
ErrorFile db 0
BmpFileErrorMsg db 'Error At Opening Bmp File ',MAIN_SCREEN, 0dh, 0ah,'$'
ScrLine db BMP_WIDTH dup (0) ; One Color line read buffer
PlayerYPosition db STARTING_PLAYER_Y_POSITION ; Starting player position
FirstPoleXPosition dw FIRST_POLE_STARTING_POSITION
FirstPoleStartSpaceRow dw FIRST_POLE_SPACE_STARTING_POSITION ; start of space
FirstPoleEndSpaceRow dw FIRST_POLE_SPACE_STARTING_POSITION + MAXIMUM_SPACE_HEIGHT ; end of space
SecondPoleXPosition dw SECOND_POLE_STARTING_POSITION
SecondPoleStartSpaceRow dw SECOND_POLE_SPACE_STARTING_POSITION ; start of space
SecondPoleEndSpaceRow dw SECOND_POLE_SPACE_STARTING_POSITION + MAXIMUM_SPACE_HEIGHT ; end of space
ThirdPoleXPosition dw THIRD_POLE_STARTING_POSITION
ThirdPoleStartSpaceRow dw THIRD_POLE_SPACE_STARTING_POSITION ; start of space
ThirdPoleEndSpaceRow dw THIRD_POLE_SPACE_STARTING_POSITION + MAXIMUM_SPACE_HEIGHT ; end of space
CurrentScore db 0
RndCurrentPos dw start
IsInFirstPoleZone db FALSE
IsInSecondPoleZone db FALSE
IsInThirdPoleZone db FALSE
ScoreMessage db " Final Score Is: ", '$'
FinalMessage db 0dh, 0ah, " Press any key to continue...$"
CODESEG
start:
mov ax,@data
mov ds,ax
call MainScreen
exit:
mov ax,4C00h
int 21h
proc InitializeValues
mov [FirstPoleXPosition], FIRST_POLE_STARTING_POSITION
mov [FirstPoleStartSpaceRow], FIRST_POLE_SPACE_STARTING_POSITION
mov [FirstPoleEndSpaceRow], FIRST_POLE_SPACE_STARTING_POSITION
add [FirstPoleEndSpaceRow], MAXIMUM_SPACE_HEIGHT
mov [SecondPoleXPosition], SECOND_POLE_STARTING_POSITION
mov [SecondPoleStartSpaceRow], SECOND_POLE_SPACE_STARTING_POSITION
mov [SecondPoleEndSpaceRow], SECOND_POLE_SPACE_STARTING_POSITION
add [SecondPoleEndSpaceRow], MAXIMUM_SPACE_HEIGHT
mov [ThirdPoleXPosition], THIRD_POLE_STARTING_POSITION
mov [ThirdPoleStartSpaceRow], THIRD_POLE_SPACE_STARTING_POSITION
mov [ThirdPoleEndSpaceRow], THIRD_POLE_SPACE_STARTING_POSITION
add [ThirdPoleEndSpaceRow], MAXIMUM_SPACE_HEIGHT
mov [PlayerYPosition], STARTING_PLAYER_Y_POSITION
mov [CurrentScore], 0
mov [IsInFirstPoleZone], FALSE
mov [IsInSecondPoleZone], FALSE
mov [IsInThirdPoleZone], FALSE
ret
endp InitializeValues
;==============================
; Description:
; this procedure initializes mainScreen, and waits for mouse input. When mouse is clicked,
; it checks whether or not to switch screens.
;==============================
proc MainScreen
call SetGraphic
call InitializeValues
mov ax, 1
int 33h
mov ah, 2
mov bh, 2
mov dl, 0
mov dh, 0
int 10h
mov [BmpLeft],0
mov [BmpTop],0
mov [BmpColSize], 320
mov [BmpRowSize] ,200
mov dx, offset MainName
call OpenShowBmp
ClickWaitWithDelay:
mov cx,1000
@@Wait:
loop @@Wait
WaitTillPressOnPoint:
mov dx, offset MainName
call OpenShowBmp
mov ax,5h
mov bx,0
int 33h
cmp bx,00h
jne ClickWaitWithDelay ; mouse wasn't pressed
shr cx, 1 ; 640 / 2 = 320
jmp Clicked
GoToHelp:
jmp HelpScreen
GoToGame:
jmp Game
; if (horizontal position > 135 && < 184 && vertical position > 162 && < 177) -> go to help
Clicked:
push 135
push 184
push 162
push 177
call isInBoundary
;IS_IN_BOUNDARY 135, 184, 162, 177
jc GoToHelp
push 135
push 184
push 129
push 142
call isInBoundary
;IS_IN_BOUNDARY 135, 184, 129, 142
jc GoToGame
jmp ClickWaitWithDelay
ret
endp MainScreen
;==============================
; Description:
; this procedure initializes helpScreen, and waits for mouse input. When mouse is clicked,
; it checks whether or not to switch screens.
;==============================
proc HelpScreen
mov dx, offset HelpName
call OpenShowBmp
@@@ClickWaitWithDelay:
mov cx,1000
@@@Wait:
loop @@@Wait
@@@WaitTillPressOnPoint:
mov dx, offset HelpName
call OpenShowBmp
mov ax,5h
mov bx,0
int 33h
cmp bx,00h
jne @@@ClickWaitWithDelay ; mouse wasn't pressed
shr cx, 1
jmp MouseHasBeenClicked
@@GoToGame:
jmp Game
@@GoToMain:
jmp MainScreen
MouseHasBeenClicked:
push 248
push 292
push 140
push 147
call isInBoundary
jc @@GoToGame
push 250
push 290
push 155
push 166
call isInBoundary
jc @@GoToMain
jmp @@@ClickWaitWithDelay
ret
endp HelpScreen
;==============================
; Description:
; This procedure draws the screen. Goes by background color.
;==============================
proc DrawScreen
mov [BmpLeft],0
mov [BmpTop],0
mov [BmpColSize], 320
mov [BmpRowSize] ,200
mov dx, offset EraseScreenName
call OpenShowBmp
ret
endp DrawScreen
;==============================
; Description:
; Manages the whole game.
; Steps:
; Before mainLoop:
; Draw the screen
; InitializePlayer
; InitializePoles
; MainLoop:
; HandleScore
; HandlePlayerMovement
; HandleIllegalPlayerPosition
; HandlePlayerCollision
; HandlePoles
; This loop runs until HandleIllegalPlayerPosition or HandlePlayerCollision returns true. In This case, the loop exits
; After MainLoop:
; Goto DeathScreen
;
;==============================
proc Game
; initialize:
mov ax, 2h ; hide cursor
int 33h
call DrawScreen
call InitializePlayer
call InitializePoles
mov ah, 00h ; clear buffer
int 16h
mov cx, POLE_WAIT_INTERVAL ; this will be wait untill poles are erased and put on screen
MainLoop:
push cx
call HandleScore
call HandlePlayerMovement ; handles player movement
xor dx,dx ; RESET DX
; call HandleTimer
call HandleIllegalPlayerPosition ; position > 200 or position < 0
cmp dx, TRUE
je EndGame
call HandlePlayerCollision
cmp dx, TRUE
je EndGame
pop cx
cmp cx, 0
je HandlePolesAllowed
dec cx
jmp HandlePolesForbidden
HandlePolesAllowed:
call HandlePoles
mov cx, POLE_WAIT_INTERVAL
HandlePolesForbidden:
jmp MainLoop
EndGame:
pop cx
jmp DeathScreen
ret
endp Game
;==============================
; Description:
; This procedure checks whether or not a given pole is in the pole zone.
; if it is, the variable is made true.
;==============================
proc IsInPoleZone
push bp
mov bp, sp
POLE_ADDRESS equ [bp+6]
IS_IN_POLE_ZONE equ [bp+4]
mov bx, POLE_ADDRESS
mov ax, [bx] ; pole position in ax
cmp ax, PLAYER_COLUMN
jl InPoleZone
jmp NotInPoleZone
InPoleZone:
mov bx, IS_IN_POLE_ZONE
mov ax, TRUE
mov [bx], ax
NotInPoleZone:
pop bp
ret 4
endp IsInPoleZone
;==============================
; Description:
; This procedure uses isInPoleZone to decide whether or not to increment the score by 1.
;==============================
proc HandleScoreIncrementation
push bp
mov bp, sp
POLE_ADDRESS equ [bp+6]
IS_IN_POLE_ZONE equ [bp+4]
mov bx, IS_IN_POLE_ZONE
mov ax, [bx]
cmp ax, TRUE
jne EndScoreIncrementation
FinalCheck:
mov bx, POLE_ADDRESS ; bx = pole address
mov ax, [bx]
add ax, POLE_WIDTH ; ax = polePosition + width = end of the pole
mov bx, PLAYER_COLUMN ; where the player is positioned on the x axis
cmp bx, ax ; if where the player is positioned > end of pole -> IncrementScore
ja IncrementScore
jmp EndScoreIncrementation
IncrementScore:
inc [CurrentScore]
mov bx, IS_IN_POLE_ZONE
mov ax, FALSE ; Move false after player has passed the pole zone.
mov [bx], ax
EndScoreIncrementation:
pop bp
ret 4
endp HandleScoreIncrementation
proc HandleScore
PUSH_REGISTERS
push offset FirstPoleXPosition
push offset IsInFirstPoleZone
call IsInPoleZone
push offset SecondPoleXPosition
push offset IsInSecondPoleZone
call IsInPoleZone
push offset ThirdPoleXPosition
push offset IsInThirdPoleZone
call IsInPoleZone
; handle score inc
push offset FirstPoleXPosition
push offset IsInFirstPoleZone
call HandleScoreIncrementation
push offset SecondPoleXPosition
push offset IsInSecondPoleZone
call HandleScoreIncrementation
push offset ThirdPoleXPosition
push offset IsInThirdPoleZone
call HandleScoreIncrementation
POP_REGISTERS
ret
endp HandleScore
proc DrawEndGameRectangle
mov cx, GAME_OVER_COLUMN
sub cx, GAME_OVER_RECTANGLE_CONSTANT
mov dx, GAME_OVER_ROW
sub dx, GAME_OVER_RECTANGLE_CONSTANT
mov al, GAME_OVER_RECTANGLE_COLOR
xor di,di
add di, GAME_OVER_RECTANGLE_CONSTANT
add di, GAME_OVER_WIDTH
add di, GAME_OVER_RECTANGLE_CONSTANT
xor si, si
add si, GAME_OVER_RECTANGLE_CONSTANT
add si, GAME_OVER_HEIGHT
add si, GAME_OVER_RECTANGLE_HEIGHT_CONSTANT
call Rect
ret
endp DrawEndGameRectangle
proc DeathScreen
call DeathScreenDelay
call TextMode
call PrintScore
call PrintFinalMessage
ClearBuffer:
mov ah, 0h
int 16h
mov ah, 1h
int 16h
jnz ClearBuffer
mov ah, 0h
int 16h
call MainScreen
ret
endp DeathScreen
proc PrintScore
mov ah, 09h
mov dx, offset ScoreMessage
int 21h
xor ah,ah
mov al, [CurrentScore]
shr al, 2 ; div by 4
call ShowAxDecimal
ret
endp PrintScore
proc PrintFinalMessage
mov ah, 09h
mov dx, offset FinalMessage
int 21h
ret
endp PrintFinalMessage
proc DeathScreenDelay
mov ah, 86h
mov cx, 01Eh
mov dx, 8480h
int 15h
ret
endp DeathScreenDelay
;==============================
; Description:
; Goes over a square perimeter around the player and checks whether a given pixel color is detected.
;==============================
proc ScanPlayerPerimeterForGivenColor
push bp
mov bp, sp
GIVEN_COLOR equ [bp+4]
; DX = row
; CX = column
mov dl, [PlayerYPosition]
; start at x position PLAYER_COLUMN + PLAYER_SIZE. every iteration, increment counter by one to scan next player pixel.
mov cx, PLAYER_SIZE
@@LoopCollisionYAxis:
push cx
mov cx, PLAYER_COLUMN
inc cx
add cx, PLAYER_SIZE
inc dl
mov ah, 0Dh
int 10h
cmp al, GIVEN_COLOR
je SetDXRegister
pop cx
loop @@LoopCollisionYAxis
mov cx, PLAYER_SIZE
dec cx
mov si, 0
; Start at x position player column, and y position = player y position.
; Every iteration increase si by 1 and add to cx, move into dl player y position.
; This gives us the current place on the axis which we want to check for given color. if detected, jump out
LoopCollisionTopXAxis:
push cx
mov cx, PLAYER_COLUMN
add cx, si
mov dl, [PlayerYPosition]
dec dl
xor dh, dh
mov ah, 0Dh
int 10h
cmp al, GIVEN_COLOR
je SetDXRegister
sub cx, si ; if this didnt happen, cx instead of adding one more every iteration, would add si.
inc si
pop cx
loop LoopCollisionTopXAxis
mov cx, PLAYER_SIZE
dec cx
mov si, 0
; Start at x position player column, and y position = player y position.
; Every iteration increase si by 1 and add to cx, move into dl the player size + position.
; This gives us the current place on the axis which we want to check for given color. if detected, jump out
LoopCollisionBottomXAxis:
push cx
mov cx, PLAYER_COLUMN
add cx, si
mov dl, [PlayerYPosition]
add dl, PLAYER_SIZE
xor dh,dh
mov ah, 0Dh
int 10h
cmp al, GIVEN_COLOR
je SetDXRegister
sub cx, si ; if this didnt happen, cx instead of adding one more every iteration, would add si.
inc si
pop cx
loop LoopCollisionBottomXAxis
jmp endScanPlayerPerimeterForGivenColor
SetDXRegister:
mov dx, TRUE
pop cx
endScanPlayerPerimeterForGivenColor:
pop bp
ret 2
endp ScanPlayerPerimeterForGivenColor
;==============================
; Description:
; Pushes the pole color and uses ScanPlayerPerimeterForGivenColor.
;==============================
proc HandlePlayerCollision
push POLE_COLOR
call ScanPlayerPerimeterForGivenColor
ret
endp HandlePlayerCollision
;==============================
; Description:
; Initializes ALL player poles, by pushing the start and ending of the pole spaces, and moving the position into cx. this procedure uses InitializePole
;==============================
proc InitializePoles
mov cx, [FirstPoleXPosition]
push [FirstPoleStartSpaceRow]
push [FirstPoleEndSpaceRow]
call InitializePole
mov cx, [SecondPoleXPosition]
push [SecondPoleStartSpaceRow]
push [SecondPoleEndSpaceRow]
call InitializePole
mov cx, [ThirdPoleXPosition]
push [ThirdPoleStartSpaceRow]
push [ThirdPoleEndSpaceRow]
call InitializePole
ret
endp InitializePoles
; make mask acording to bh size
; output Si = mask put 1 in all bh range
; example if bh 4 or 5 or 6 or 7 si will be 7
; if Bh 64 till 127 si will be 127
Proc MakeMask
push bx
mov si,1
@@again:
shr bh,1
cmp bh,0
jz @@EndProc
shl si,1 ; add 1 to si at right
inc si
jmp @@again
@@EndProc:
pop bx
ret
endp MakeMask
; Description : get RND between any bl and bh includs (max 0 -255)
; Input : 1. Bl = min (from 0) , BH , Max (till 255)
; 2. RndCurrentPos a word variable, help to get good rnd number
; Declre it at DATASEG : RndCurrentPos dw ,0
; 3. EndOfCsLbl: is label at the end of the program one line above END start
; Output: Al - rnd num from bl to bh (example 50 - 150)
; More Info:
; Bl must be less than Bh
; in order to get good random value again and agin the Code segment size should be
; at least the number of times the procedure called at the same second ...
; for example - if you call to this proc 50 times at the same second -
; Make sure the cs size is 50 bytes or more
; (if not, make it to be more)
proc RandomByCs
push es
push si
push di
mov ax, 40h
mov es, ax
sub bh,bl ; we will make rnd number between 0 to the delta between bl and bh
; Now bh holds only the delta
cmp bh,0
jz @@ExitP
mov di, [word RndCurrentPos]
call MakeMask ; will put in si the right mask according the delta (bh) (example for 28 will put 31)
RandLoop: ; generate random number
mov ax, [es:06ch] ; read timer counter
mov ah, [byte cs:di] ; read one byte from memory (from semi random byte at cs)
xor al, ah ; xor memory and counter
; Now inc di in order to get a different number next time
inc di
cmp di,(EndOfCsLbl - start - 1)
jb @@Continue
mov di, offset start
@@Continue:
mov [word RndCurrentPos], di
and ax, si ; filter result between 0 and si (the mask)
cmp al,bh ;do again if above the delta
ja RandLoop
add al,bl ; add the lower limit to the rnd num
@@ExitP:
pop di
pop si
pop es
ret
endp RandomByCs
;==============================
; Description:
; The procedure starts with getting the pole position, the pole start space and end space from the stack.
; It checks if the pole has gone past its boundary, if it has, change the position to the max.
; when changing position, this procedure randomizes pole space start position, and space height
;==============================
proc ChangePolePositionToMax
push bp
mov bp, sp
POLE_ADDRESS equ [bp+8]
POLE_START_SPACE equ [bp+6]
POLE_END_SPACE equ [bp+4]
mov bx, POLE_ADDRESS
mov ax, [bx]
cmp ax, POLE_BOUNDARY
jle ChangePoleToMax
jmp EndPoleChangePosition
ChangePoleToMax:
mov cx, [bx] ; cx = pole position
mov bx, POLE_START_SPACE
push [bx] ; push start of pole space
mov bx, POLE_END_SPACE
push [bx] ; push end of pole space
call EndPole ; completely erase the pole
call HandlePoleInconsistency ; handles leftover green pixels.
mov ax, 320 ; screen width
sub ax, POLE_PIXEL_MOVEMENT
mov bx, POLE_ADDRESS
mov [bx], ax
; pole position = (320 - POLE_PIXEL_MOVEMENT)
mov bl, MINIMUM_SPACE_HEIGHT
mov bh, MAXIMUM_SPACE_HEIGHT
call RandomByCs ; randomize pole space height
; AL = random number between al and ah
push ax ; save random space
xor ah,ah ; AH = 0
mov bl, 0 ; minimum start position
mov cx, 200 ; graphic height
sub cx, ax ; subtract the graphic height by the space height so if for example the height = 40, the maximum start position needs to be 200 - 40, so there wont be too many pixels drawn.
mov bh, cl ; move the upper limit of the start position into bh
call RandomByCs ; randomize the starting position between (0 and GRAPHIC_HEIGHT - SPACE_HEIGHT )
pop cx ; random space height into cx
push ax ; random space start position
push POLE_START_SPACE ; the address of the pole start space
push POLE_END_SPACE ; the address of the pole end space
push cx ; the random space height
call ModifyPoleParameters
EndPoleChangePosition:
pop bp
ret 6
endp ChangePolePositionToMax
proc ModifyPoleParameters
push bp
mov bp, sp
RANDOM_SPACE_POSITION equ [bp+10]
START_SPACE equ [bp+8]
END_SPACE equ [bp+6]
RANDOM_HEIGHT equ [bp+4]
mov ax, RANDOM_SPACE_POSITION
mov bx, START_SPACE
mov [bx], ax ; START_SPACE = RANDOM_SPACE_POSITION
mov ax, RANDOM_SPACE_POSITION
add ax, RANDOM_HEIGHT ; AX = RANDOM_SPACE_POSITION + RANDOM_HEIGHT = The end of the sspace
mov bx, END_SPACE
mov [bx], ax
pop bp
ret 8
endp ModifyPoleParameters
;==============================
; Description:
; Handles if position < POLE_BOUNDARY. uses ChangePolePositionToMax
;==============================
proc HandleIllegalPolePositions
push offset FirstPoleXPosition
push offset FirstPoleStartSpaceRow
push offset FirstPoleEndSpaceRow
call ChangePolePositionToMax
push offset SecondPoleXPosition
push offset SecondPoleStartSpaceRow
push offset SecondPoleEndSpaceRow
call ChangePolePositionToMax
push offset ThirdPoleXPosition
push offset ThirdPoleStartSpaceRow
push offset ThirdPoleEndSpaceRow
call ChangePolePositionToMax
ret
endp HandleIllegalPolePositions
;==============================
; Description:
; Handles everything related to poles.
;
;==============================
proc HandlePoles
xor cx,cx
call ErasePoles
sub [FirstPoleXPosition], POLE_PIXEL_MOVEMENT
sub [SecondPoleXPosition], POLE_PIXEL_MOVEMENT ; pole positions = polePositions - POLE_PIXEL_MOVEMENT
sub [ThirdPoleXPosition], POLE_PIXEL_MOVEMENT
; Draw Each pole
mov cx, [FirstPoleXPosition]
push [FirstPoleStartSpaceRow]
push [FirstPoleEndSpaceRow]
call DrawPole
mov cx, [SecondPoleXPosition]
push [SecondPoleStartSpaceRow]
push [SecondPoleEndSpaceRow]
call DrawPole
mov cx, [ThirdPoleXPosition]
push [ThirdPoleStartSpaceRow]
push [ThirdPoleEndSpaceRow]
call DrawPole
call HandleIllegalPolePositions
ret
endp HandlePoles
proc ErasePoles
mov cx, [FirstPoleXPosition]
push [FirstPoleStartSpaceRow]
push [FirstPoleEndSpaceRow]
call ErasePole
mov cx, [SecondPoleXPosition]
push [SecondPoleStartSpaceRow]
push [SecondPoleEndSpaceRow]
call ErasePole
mov cx, [ThirdPoleXPosition]
push [ThirdPoleStartSpaceRow]
push [ThirdPoleEndSpaceRow]
call ErasePole
ret
endp ErasePoles
;==============================
; Description:
; Handles if position < 0 or position > 200. answer in dx
;==============================
proc HandleIllegalPlayerPosition
xor ax,ax
jmp CheckForForbiddenPositon
SetDX:
mov dx, TRUE
jmp EndHandleIllegalPlayerPosition
CheckForForbiddenPositon:
mov al, [PlayerYPosition]
mov dl, 200
sub dl, PLAYER_SIZE