-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLine.asm
240 lines (192 loc) · 7.9 KB
/
CLine.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
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createLine
dopush dx,cx,ax,bx
;enter - when game starts, when player restarts game (also dies), when player hits up key on line 5 from bottom. cell, row = array index.
;exit - creates new line in array to be printed to game.
;randomizer 1-4 if new road will appear
mov [shrSize], 14 ; 1-4
call randomizer ;taking time for randomizer
cmp ax, 2
jne contRoad
contGrass:
call incCell ;updating array index to next cell.
mov [roadCount], 0 ;הכבישים כבר לא ברצף
;moving to array 0 so algorithm will know that line is NOT road
mov dx, 0
mov [di], dx
call rowNext ;adding to index to skip to next line
jmp quitLine ;jumping to end of procedure.
contRoad:
call checkMaxRoad
cmp bx, 1
je contGrass
inc [roadCount] ;if new road than roadCount is incrimented
call incCell ;updating array index to next cell.
;moving to array 0 so algorithm will know that line IS road
mov dx,1
mov [di], dx
;calling the speed+timer cells creator.
call createSpeed
;calling the direction of road creator.
call createDirection
;calling the number of cars cell creator.
call createCarN
;calling the cars pos cells creator.
call createCarPosCol
call rowNext ;adding to index to skip to next line
quitLine:
dopop bx,ax,cx,dx
ret
endp createLine
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createSpeed
;enter - cell, row = array index.
;exit - creates speed and timer cells in array.
;randomizer to choose speed of road.
mov [shrSize], 12 ;getting the 3 siginficent bits (0 - f) to be on the lowest bits.
call randomizer ;randomizer procedure.
add ax, 1 ;ax = 1-8
;counting for difficulty.
cmp ax, [minSpeed] ; if number < minimum than => number = minimum.
jbe contSpeed
mov ax, [minSpeed] ;ax = minimum.
contSpeed:
mov ah,al ;moving speed to higher register ( xh => x0xh )
xor al,al ;zeroing al ( x0xh => x00h)
call incCell ;updating array index to next cell.
mov [di], ax ;speed cell = speed.
;creating timer cell
call incCell ;updating array index to next cell.
mov [di], ax ;timer cell = speed.
ret
endp createSpeed
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createDirection
;enter - cell, row = array index.
;exit - creates direction of road cell. 0 = right, 1 = left.
; randomizer to decide direction of road.
mov [shrSize], 15 ;getting siginifcant bit to be on the lowest bit.
call randomizer ;randomizer procedure.
mov dx, 0 ;road = right.
cmp al,1 ;comparing rand number with 1
je RoadLeft ;if random bit is 1 than:
mov dx, 1 ; road = left.
RoadLeft:
call incCell ;updating array index to next cell.
mov [di],dx ; direction of road cell = dx.
ret
endp createDirection
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createCarN
;enter - cell, row = array index.
;exit - creates number of cars cell. 1-4 cars.
; randomizer to decide number of cars in road.
mov [shrSize], 14 ; getting the 2 siginficent bits (0-3) to be on the lowest bits.
call randomizer ;randomizer procedure
call incCell ;updating array index to next cell.
inc ax ; ax = 1-4.
;counting for difficulty.
cmp ax, [minCars] ; if number < minimum than => number = minimum.
jae contCarNumber
mov ax, [minCars] ;ax = minimum.
contCarNumber:
mov [di], ax
;moving to cx number of cars for CarPosCol creator procedure.
sub ax,1 ;decreacing cx because first car is outside loop.
mov cx, ax ;cx = ax.
ret
endp createCarN
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createCarPosCol
;enter - cell, row = array index. cx = number of cars (-1 because first car is outside loop.
;exit - creates car position and color cells.
; randomizer to determine position of car.
mov [shrSize], 8 ; siginficent register to lower register.
call randomizer ;randomizer procedure
call incCell ;updating array index to next cell.
mov [di],ax ;moving to position cell 0-ffh (0-255)
mov [lastpos], ax ; saving part of first position.
mov [shrSize], 10 ;6 siginifcent bits to lower bits. (0 - 3f)
call randomizer ;randomizer procedure
add [di], ax ;adding to position cell 0-3fh ( 0-63) = first part + second part = 0-318
add [lastpos], ax ;saving second part of position.
call createCarColor ;קורא לפעולה שמגרילה צבע
cmp cx,0 ;if cx = 0 than:
jz endRoad ; יוצא מהפעולה
cmp cx,1 ;if cx != 1 than:
jne contpos1 ; jumps to next check
;randomizer to determine position of car.
mov [shrSize], 9 ; 0 - 127
call movPosToArr ;קורא לפעולה ששומרת את המיקום של המכונית
call createCarColor ;קורא לפעולה שמגרילה צבע
jmp endRoad ;יוצא מהפעולה
contpos1:
cmp cx,2 ;if cx != 2 than:
jne contpos2 ; jumps to 4 car loop.
;randomizer to determine position of car.
loopPos1:
mov [shrSize], 9 ;0 - 63
call movPosToArr ;קורא לפעולה ששומרת את המיקום של המכונית
call createCarColor ;קורא לפעולה שמגרילה צבע
loop loopPos1 ;car position loop
jmp endRoad ;יוצא מהפעולה
;randomizer to determine position of car.
contpos2:
mov [shrSize] , 10 ; 0-63
call movPosToArr ;קורא לפעולה ששומרת את המיקום של המכונית
call createCarColor ;קורא לפעולה שמגרילה צבע
loop contpos2 ;car position loop
endRoad:
ret
endp createCarPosCol
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc movPosToArr
;enter- מקבל ב lastpos את המיקום האחרון
;exit- מגריל מיקום חדש ושם אותו במערך ובlastpos
call randomizer
add ax,25 ;מוסיף 25 כדי שהמכוניות לא יגעו אחד בשני
;add to last position
add ax, [lastpos] ;מוסיף מיקום קודם למיקום החדש
cmp ax, 320 ;בודק כדי שהמיקום לא יגלוש שורה
jnae inRange2
sub ax, 320 ; אם כן אז מוריד 320
inRange2:
call incCell
mov [di], ax ;מעביר את המיקום החדש למיקום שלו במערך
mov [lastpos], ax
ret
endp movPosToArr
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc createCarColor
;enter- אין
;exit- מגריל מס' שישמש כצבע של המכונית ושם אותו במערך.
mov [shrSize], 13 ;0-7
call randomizer
mov dx, [randNum]
add dx, 0f7h ;f7h-feh
call incCell
mov [di], dx
ret
endp createCarColor
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
proc checkMaxRoad
;enter- אין
;exit- בודק אם היו 4 כבישים ברצף אם כן אז מעביר ל bx = 1
xor bx, bx ;מאפס את האוגר שמשמש כבוליאני
cmp [roadCount], 4 ;מקסימום 4 כבישים ברצף.
jne contNotMax
mov [roadCount], 0 ;אם כן אז מאפס את המשתנה
mov bx, 1 ; אוגר בוליאני שווה אמת
contNotMax:
ret
endp checkMaxRoad
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''