@@ -32,7 +32,7 @@ cpu 686
32
32
%define VgaChar(color , ascii) (((color) << 8 ) | (ascii))
33
33
34
34
%assign Color.Veiled 0x77
35
- %assign Color.Unveiled 0x87
35
+ %assign Color.Unveiled 0xf0
36
36
%assign Color.Cursor 0x00
37
37
%assign Color.GameWinText 0x20
38
38
%assign Color.GameOverText 0xc0
@@ -176,8 +176,7 @@ GameLoop:
176
176
177
177
ClearCell:
178
178
mov ax , [ di ]
179
- mov dl , Color.Unveiled
180
- mov [ di + 1 ], dl
179
+ call UnveilCell
181
180
.CmpEmpty:
182
181
cmp al , '0'
183
182
jne .CmpMine
@@ -218,6 +217,20 @@ GetTextBufIndex:
218
217
pop cx
219
218
ret
220
219
220
+ ;; Unveil a cell so it is visible on the screen
221
+ ;;
222
+ ;; Parameters:
223
+ ;; * di - cell pointer in text buffer
224
+ ;; * al - cell ASCII value
225
+ ;; Returns:
226
+ ;; * dl - written VGA color code
227
+ UnveilCell:
228
+ ; Use xor magic to make the cells colored
229
+ mov dl , al
230
+ xor dl , '0' ^ Color.Unveiled
231
+ mov [ di + 1 ], dl
232
+ ret
233
+
221
234
;; Flood fill empty cells
222
235
;;
223
236
;; Parameters:
@@ -240,22 +253,22 @@ Flood:
240
253
jae . Ret
241
254
242
255
; Base case: we visited this cell already
243
- cmp al , '. '
256
+ cmp al , ' '
244
257
je . Ret
245
258
246
259
; Base case: this is a bomb
247
260
cmp al , '*'
248
261
je . Ret
249
262
250
263
; Body: unveil cell
251
- mov byte [ di + 1 ], Color.Unveiled
264
+ call UnveilCell
252
265
253
266
; Base case: nonempty cell
254
267
cmp al , '0'
255
268
jne . Ret
256
269
257
- ; Body: mark cell
258
- mov byte [ di ], '. '
270
+ ; Body: mark cell as visited and empty
271
+ mov byte [ di ], ' '
259
272
260
273
; Recursive case: flood adjacent cells
261
274
0 commit comments