Skip to content

Commit 329a6c5

Browse files
committed
Add cell digit coloring
1 parent 9c33533 commit 329a6c5

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

mine.asm

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cpu 686
3232
%define VgaChar(color, ascii) (((color) << 8) | (ascii))
3333

3434
%assign Color.Veiled 0x77
35-
%assign Color.Unveiled 0x87
35+
%assign Color.Unveiled 0xf0
3636
%assign Color.Cursor 0x00
3737
%assign Color.GameWinText 0x20
3838
%assign Color.GameOverText 0xc0
@@ -176,8 +176,7 @@ GameLoop:
176176

177177
ClearCell:
178178
mov ax, [di]
179-
mov dl, Color.Unveiled
180-
mov [di + 1], dl
179+
call UnveilCell
181180
.CmpEmpty:
182181
cmp al, '0'
183182
jne .CmpMine
@@ -218,6 +217,20 @@ GetTextBufIndex:
218217
pop cx
219218
ret
220219

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+
221234
;; Flood fill empty cells
222235
;;
223236
;; Parameters:
@@ -240,22 +253,22 @@ Flood:
240253
jae .Ret
241254

242255
; Base case: we visited this cell already
243-
cmp al, '.'
256+
cmp al, ' '
244257
je .Ret
245258

246259
; Base case: this is a bomb
247260
cmp al, '*'
248261
je .Ret
249262

250263
; Body: unveil cell
251-
mov byte [di + 1], Color.Unveiled
264+
call UnveilCell
252265

253266
; Base case: nonempty cell
254267
cmp al, '0'
255268
jne .Ret
256269

257-
; Body: mark cell
258-
mov byte [di], '.'
270+
; Body: mark cell as visited and empty
271+
mov byte [di], ' '
259272

260273
; Recursive case: flood adjacent cells
261274

0 commit comments

Comments
 (0)