253 byte PC minesweeper game (complete source code) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


253 byte PC minesweeper game (complete source code)

m34tb34tm34tb34t Posts: 25Member
@: push cx
mov cl,mapSize ; square maps only
mov al,20h ; empty space marked with space (bar)
rep stosw
mov al,0
mov cl,40-mapSize ; rest of screen is null
rep stosw
pop cx
loop @: in ax,40h
mov bx,mapSize*40 ; size of map buffer in bytes (including nulls)
xor dx,dx ; clear DX for DIV
div bx
mov bx,dx ; spot == rand()%total_spots
shl bx,1 ; force even (word align) address
mov dx,[di+bx] ; load map spot
cmp dl,20h
jne @B ; only write in empty space (20h)
mov byte [di+bx],'*'
;place numbers on map around mines giving hints
sub bx,82
call packMineCount ; NW, N, NE
add bx,154
call packMineCount ; SW, S, SE
sub bx,82
call mineCounter ; E
sub bx,4
call mineCounter ; W
loop @: push cx
mov cl,mapSize
rep stosw
pop cx
add di,80-(mapSize*2) ; next line down
loop @B
mov ax,3 ; read mouse info
int 33h
shr cx,2 ; horz. 0-80 -> 320/4 = 40 chars (80 bytes)
shr dx,3 ; vert. 0-24 -> 200/8 = 25 chars high
and bx,bx ; test buttons
jz inputLoop
;calc mouse click address
mov ax,80
mul dx ; mul doubles as xor dx,dx later on
add ax,cx ; 80*y + x
mov si,ax ; si = video and map data offset
;click action
call stackFill
lods word [es:si] ; (lodsw [es:si]) bytecode: db 26h, 0ADh
cmp al,'*'
jne @: xor si,si
mov cx,mapSize*40
lods word [es:si] ; lodsw [es:si] (bytecode: db 26h,0ADh)
cmp al,0FEh ; still covered?
jne @: call mineCounter
inc bx
inc bx
loop @B
pop cx

;incriment 1 of the 8 spaces around mine (assuming no other mine in it)
mov dx,[di+bx]
and dl,dl ; game board clipping
jz @F
cmp dl,'*' ; dont change value of mines
je mineCountDone
cmp dl,20h
jne @: sub dx,0FEFFh
mov [di+bx],dx ; and store

;4-way flood fill (not full 8 way)
mov ax,[es:si] ; load scr char
cmp al,0FEh ; don't fill if already revealed/flagged
jne @F
mov ax,[si+mapData] ; load map char
mov [es:si],ax ; copy to screen
cmp al,20h ; stop fill if close to a mine
jne @: ret

heapPtr: ; start of game map memory heap


Sign In or Register to comment.