-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid.inc
1686 lines (1342 loc) · 29.8 KB
/
grid.inc
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
DrawPath_ proc
mov cx,Path_Length
mov bx,0
drawTrack:
mov ax,PathX[bx]
mov x,ax
mov ax,PathY[bx]
mov y,ax
mov ax, Path_Tile[bx]
cmp ax,0
jnz dp_skip1
call drawSquare
jmp dp_skip0
dp_skip1:
cmp ax,1
jnz dp_skip2
call drawSquareLeftRight
jmp dp_skip0
dp_skip2:
cmp ax,2
jnz dp_skip3
call drawSquareLeftDown
jmp dp_skip0
dp_skip3:
cmp ax,3
jnz dp_skip4
call drawSquareRightDown
jmp dp_skip0
dp_skip4:
cmp ax,4
jnz dp_skip5
call drawSquareDownLeft
jmp dp_skip0
dp_skip5:
cmp ax,5
jnz dp_skip0
call drawSquareDownRight
dp_skip0:
inc bx
inc bx
loop drawTrack
ret
DrawPath_ endp
Generate proc
;generatePath:
;initialize
call genRand
mov ax,RandNum
mov y,ax
mov x,0
; the currIndex should keep up with values of x & y
mov cx,y
indexLoop:
add currIndex,GRID_WIDTH
loop indexLoop
generatePath:
;main subroutine
cmp x, GRID_WIDTH
jge exit_
call checkCurrentDirections
call chooseDirection
cmp x,GRID_WIDTH
jge continue_generatePath
call updateMap
continue_generatePath:
cmp currDirection,1 ;DOWN
jnz generatePath
inc x
inc currIndex
jmp generatePath
exit_:
mov ax,Path_Length
mov Path_Length_dec,ax
dec Path_Length_dec
dec Path_Length_dec
mov Path_Length_aux,ax
add Path_Length_aux,ax
mov Path_Length_aux_2,ax
add Path_Length_aux_2,ax
add Path_Length_aux_2,ax
add Path_Length_aux_2,ax
ret
Generate endp
genRand PROC ;;CHANGES AX CX
PUSH AX CX
mov cx,60000
loop1:
loop loop1
;mov cx,60000
;loop2:
;loop loop2
;
;mov cx,60000
;loop3:
;loop loop3
;
mov AH, 2Ch
int 21h
mov AH,0
mov AL,dl
DIV Threshold
mov al,AH
mov ah,0
MOV RandNum,Ax
POP CX AX
RET
genRand ENDP
writeProbingIndex proc
mov ax,currIndex
mov probingIndex,ax
; ----- x - probe -----
cmp x_probe,0
jz skip_x_probe
;either 1 or -1
cmp x_probe,1
jnz neg_x_probe
; + 1
add probingIndex,1
jmp skip_x_probe
neg_x_probe:
; - 1
sub probingIndex,1
skip_x_probe:
; ----- y - probe -----
cmp y_probe,0
jz skip_y_probe
;either 1 or -1
cmp y_probe,1
jnz neg_y_probe
; + 1 * GRID_WIDTH
add probingIndex, GRID_WIDTH
jmp skip_y_probe
neg_y_probe:
; - 1 * GRID_WIDTH
sub probingIndex, GRID_WIDTH
skip_y_probe:
;now probingIndex is ready
mov si,offset visited
add si,probingIndex
add si,probingIndex
cmp [si],1
jz writeProbing_true
;writeProbing_false
mov ax,0
ret
writeProbing_true:
mov ax,1
ret
writeProbingIndex endp
changeDirection proc
mov Threshold,3
call genRand
;block 1
cmp RandNum,0
jnz continue_block1_cd
cmp currDirection,2 ;LEFT
jnz continue_block1_cd
cmp y,1
jle continue_block1_cd
jmp block1_cd_if
continue_block1_cd:
cmp RandNum,0
jnz block2_cd
cmp currDirection,3 ;RIGHT
jnz block2_cd
cmp y,GRID_HEIGHT -2
jge block2_cd
block1_cd_if:
cmp x,1
jl block2_cd
;set scalars
mov x_probe,-1
mov y_probe,0
call writeProbingIndex
cmp ax,0
jnz block2_cd
mov x_probe,-1
mov y_probe,-1
call writeProbingIndex
cmp ax,0
jnz block2_cd
mov x_probe,-1
mov y_probe,1
call writeProbingIndex
cmp ax,0
jnz block2_cd
call goUp
ret
block2_cd:
cmp currDirection,2 ;LEFT
jnz block2_cd_else
mov tile_no, 2;leftdown unchanged
call updateMap
jmp block3_cd
block2_cd_else:
cmp currDirection,3 ;RIGHT
jnz block3_cd
mov tile_no, 5 ;rightdown to downright
call updateMap
block3_cd:
cmp currDirection,2 ;LEFT
jnz or_block3_cd
jmp block3_cd_if
or_block3_cd:
cmp currDirection,3 ;RIGHT
jnz block4_cd
block3_cd_if:
inc x
inc currIndex
mov currDirection,0 ;DOWN to leftright
mov tile_no, 0 ;downpath
ret
block4_cd:
; OR if block
cmp continueLeft,1
jz block4_cd_if1
cmp continueRight,1
jz block4_cd_if1
cmp y,1
jle bridge_else1out
cmp y,GRID_HEIGHT - 2
jge bridge_else1out
block4_cd_if1:
cmp continueLeft,1
jz block4_cd_if2
cmp RandNum,1
jnz block4_cd_else_if1
cmp continueRight,0
jnz block4_cd_else_if1
block4_cd_if2:
; set probes
mov x_probe,0
mov y_probe,-1
call writeProbingIndex
cmp ax,0
jnz bridge_block5_cd ; i believe this is where control flow heads
cmp continueLeft,1
jnz block4_cd_else_if2
;char?
mov continueLeft,0
mov tile_no, 5 ;rightdown to downright
mov currDirection,2 ;LEFT
jmp block5_cd
;bridging
bridge_else1out: jmp block4_cd_else1out
bridge_block5_cd: jmp block5_cd
block4_cd_else_if2:
;char?
mov tile_no, 4;downleft unchanged
mov currDirection,2 ;LEFT
jmp block5_cd
block4_cd_else_if1:
;set probes
mov x_probe,0
mov y_probe,1
call writeProbingIndex
cmp ax,0
jnz block5_cd
cmp continueRight,1
jnz block4_cd_else_if1_else
mov continueRight,0
;char?
mov tile_no, 2 ;leftdown unchanged
mov currDirection,3 ;RIGHT
jmp block5_cd
block4_cd_else_if1_else:
mov tile_no, 3 ;downright to rightdown
mov currDirection,3 ;RIGHT
;char?
jmp block5_cd
block4_cd_else1out:
cmp y,1
jle block4_cd_else2out
;char?
mov tile_no, 4 ;downleft
mov currDirection,2 ;LEFT
jmp block5_cd
block4_cd_else2out:
cmp y,GRID_HEIGHT - 2
jge block5_cd
;char?
mov tile_no, 3 ;downright to rightdown
mov currDirection,3 ;RIGHT
block5_cd:
cmp currDirection,2 ;LEFT
jnz block5_cd_else
call goLeft
ret
block5_cd_else:
cmp currDirection,3 ;RIGHT
jnz exit_cd
call goRight
ret
exit_cd:
ret
changeDirection endp
checkCurrentDirections PROC
; block #1
; if AND block
cmp currDirection,2 ;LEFT
jnz continue_block2_ccd
cmp y,1
jl continue_block2_ccd
; setting probing scalars
mov x_probe,0
mov y_probe,-1
call writeProbingIndex ;result in ax
cmp ax,0
jnz continue_block2_ccd
dec y
sub currIndex,GRID_WIDTH ; index should keep up
ret
continue_block2_ccd:
cmp currDirection,3 ;RIGHT
jnz continue_block3_ccd
cmp y,GRID_HEIGHT - 1
jge continue_block3_ccd
; setting probing scalars
mov x_probe,0
mov y_probe,1
call writeProbingIndex ;result in ax
cmp ax,0
jnz continue_block3_ccd
INC y
add currIndex,GRID_WIDTH ; index should keep up
ret
continue_block3_ccd:
cmp currDirection,0 ;UP
jnz continue_block4_ccd
cmp x,1
jl continue_block4_ccd
; setting probing scalars
mov x_probe,-1
mov y_probe,0
call writeProbingIndex
cmp ax,0
jnz continue_block4_ccd
; INSIDE OF BLOCK 3
cmp continueLeft,1
jnz continue_block3_continue_ccd
; set probes
mov x_probe,-1
mov y_probe,-1
call writeProbingIndex
cmp ax,0
jnz continue_block3_continue_ccd
jmp ccd_block3_if
continue_block3_continue_ccd:
cmp continueRight,1
jnz continue_block3_else
; set probes
mov x_probe,-1
mov y_probe,1
call writeProbingIndex
cmp ax,0
jnz continue_block3_else
ccd_block3_if:
dec x
dec currIndex
ret
continue_block3_else:
mov forceDirectionChange,1
ret
continue_block4_ccd:
cmp currDirection,1 ;DOWN
jz exit_ccd
mov forceDirectionChange,1
ret
exit_ccd:
ret
checkCurrentDirections ENDP
drawSquare proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS
sub dx,CELL_H
mov cx,[START_COLUMN]
mov al,border_color
DRAW_BORDER11:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER11
sub dx,CELL_H
mov cx,bx
DRAW_BORDER12:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER12
POP CX BX DI
RET
drawSquare endp
drawSquareLeftRight proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS2:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS2
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS2
sub dx,CELL_H
mov cx,[START_COLUMN]
mov al,border_color
DRAW_BORDER21:
int 10h
inc cx
cmp cx,bx
jne DRAW_BORDER21
add dx,CELL_H
mov cx,[START_COLUMN]
DRAW_BORDER22:
int 10h
inc cx
cmp cx,bx
jne DRAW_BORDER22
POP CX BX DI
RET
drawSquareLeftRight endp
drawSquareLeftDown proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS3:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS3
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS3
sub dx,CELL_H
mov cx,[START_COLUMN]
mov al,border_color
DRAW_BORDER31:
int 10h
inc cx
cmp cx,bx
jne DRAW_BORDER31
;add dx,CELL_H
mov cx,[START_COLUMN]
DRAW_BORDER32:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER32
POP CX BX DI
RET
drawSquareLeftDown endp
drawSquareRightDown proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS4:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS4
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS4
sub dx,CELL_H
mov cx,[START_COLUMN]
mov al,border_color
DRAW_BORDER41:
int 10h
inc cx
cmp cx,bx
jne DRAW_BORDER41
;add dx,CELL_H
;mov cx,[START_COLUMN]
DRAW_BORDER42:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER42
POP CX BX DI
RET
drawSquareRightDown endp
drawSquareDownLeft proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS5:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS5
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS5
sub dx,CELL_H
mov cx,bx
mov al,border_color
DRAW_BORDER51:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER51
;add dx,CELL_H
;mov cx,[START_COLUMN]
DRAW_BORDER52:
int 10h
dec cx
cmp cx,[START_COLUMN]
jne DRAW_BORDER52
POP CX BX DI
RET
drawSquareDownLeft endp
drawSquareDownRight proc
PUSH DI BX CX
mov ax , x;
mov bx,CELL_W
mov dx,0
mul bx
mov cx,ax
mov [START_COLUMN],CX
mov ax, y;
mov bx,CELL_H
mov dx,0
mul bx
mov dx,ax
MOV BX,CX
ADD BX,CELL_W
MOV DI,DX
ADD DI,CELL_H
MOV AX,DS
MOV ES,AX
MOV AH,0CH
; inc color
DRAW_PIXELS6:
MOV AL,color
INT 10H
INC CX
CMP CX,BX
JNE DRAW_PIXELS6
MOV CX,[START_COLUMN]
INC DX
CMP DX,DI
JNE DRAW_PIXELS6
sub dx,CELL_H
mov cx,[START_COLUMN]
mov al,border_color
DRAW_BORDER61:
int 10h
inc dx
cmp dx,di
jne DRAW_BORDER61
;add dx,CELL_H
;mov cx,[START_COLUMN]
DRAW_BORDER62:
int 10h
inc cx
cmp cx,bx
jne DRAW_BORDER62
POP CX BX DI
RET
drawSquareDownRight endp
; Updates visited at currIndex in grid
updateVisited proc
mov si,offset visited
add si,currIndex
add si,currIndex
mov [si],1
mov bx,Path_Length
ADD bx,Path_Length
mov ax,x
mov PathX[bx],ax
mov ax,y
mov PathY[bx],ax
mov ax,tile_no
mov Path_Tile[bx],ax
inc Path_Length
ret
updateVisited endp
chooseDirection proc
; if AND block
cmp currCount,2 ;if less than
jge chooseDirection_else
cmp forceDirectionChange,0
jnz chooseDirection_else
inc currCount
ret
chooseDirection_else:
mov Threshold,2
call genRand
; if OR block
cmp RandNum,1 ;chance to change
jz chooseDirection_innerBlock
cmp forceDirectionChange,1
jz chooseDirection_innerBlock
cmp currCount,2
jge chooseDirection_innerBlock
jmp chooseDirection_skipInnerBlock
chooseDirection_innerBlock:
mov currCount,0
mov forceDirectionChange,0
call changeDirection
chooseDirection_skipInnerBlock:
inc currCount
ret
chooseDirection endp
goUp proc
cmp currDirection,2 ;LEFT
jnz goUp_else
mov tile_no, 3 ;downright to rightdown
call updateMap
mov continueLeft,1 ;true
jmp continue_goUp
;else
goUp_else:
mov tile_no, 4 ;downleft unchanged
call updateMap
mov continueRight,1 ;true
continue_goUp:
mov currDirection,0 ;UP
dec x
dec currIndex
mov tile_no, 1 ;downpath to leftright
ret
goUp endp
goLeft proc
call updateMap
dec y
sub currIndex,GRID_WIDTH
mov tile_no, 0 ;leftright to downpath
ret
goLeft endp
goRight proc
call updateMap
inc y
add currIndex,GRID_WIDTH
mov tile_no, 0 ;leftright to downpath
RET
goRight endp
updateMap proc
call updateVisited
;call drawSquare
ret
updateMap endp
RecievePowerUp PROC
PUSHA
Ragain:
call CHECKRECIEVE
cmp RecieveFlag,1
JNE Ragain
mov al,DataIn
MOV RandomNumberForPowerUp,AL
; CALL RandPowerUp
POPA
RET
RecievePowerUp ENDP
genPowerUps PROC
PUSH AX
PUSH Bx
PUSH DX
PUSH DI
PUSH CX
MOV CX,Path_Length
; SUB CX,1
MOV AX,CX
MOV BL,4
DIV BL
MOV CL,al
MOV CH,0
MOV DI,offset PathX
ADD DI,2
MOV BX,offset PathY
ADD BX,2
LoopOnPath:
MOV AX,CELL_W
MUL [DI]