I am trying to make a game board minesweeper 9x9 board in
I am trying to make a game board ( minesweeper ) 9x9 board in intel assembly language using Irvine32 Please help having a lot of issues
Solution
mapSize equ 9
mineCount equ 9
mapData equ heapPtr + 80 ; generated mine map memory offset
org 100h ; dos .com file program start
inc ax
int 10h ; set 40x25
int 33h ; show mouse cursor
;init game map in heap
mov ah,7 ; set text color
mov di,mapData - 80
mov cl,40 ; assume CH = null on entry
rep stosw ; line of null (for map clipping)
mov cl,mapSize
@: 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 @B
mov cl,40
rep stosw ; line of null at end of data
;generate mines
mov di,mapData
mov cl,mineCount
@: 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 @B
;setup video segment
push 0B800h
pop es
;draw board to screen
xor di,di
mov ax,7FEh ; color + ascii char
mov cl,mapSize
@: push cx
mov cl,mapSize
rep stosw
pop cx
add di,80-(mapSize*2) ; next line down
loop @B
inputLoop:
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 @F
winLoose: ; win or loose brings us here
xor ax,ax
int 16h
ret ; END OF GAME
; win game test.... if unclicked spaces == mineCount then you win
@: xor si,si
mov cx,mapSize*40
wincheck:
lods word [es:si] ; lodsw [es:si] (bytecode: db 26h,0ADh)
cmp al,0FEh ; still covered?
jne @F
inc dx ; count unclicked spots
@: loop wincheck
cmp dl,mineCount ; all mines accounted for?
je winLoose
jmp inputLoop
;do horizontal row of three (above or below a mine)
packMineCount: ; save some bytes
push cx
mov cl,3
@: call mineCounter
inc bx
inc bx
loop @B
pop cx
ret
;incriment 1 of the 8 spaces around mine (assuming no other mine in it)
mineCounter:
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 @F
mov dx,830h
@: sub dx,0FEFFh
mov [di+bx],dx ; and store
mineCountDone:
ret
;4-way flood fill (not full 8 way)
stackFill:
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 @F ; if map char != empty space then ret
lodsw ; si+=2
call stackFill ; x+1
add si,78
call stackFill ; y+1
sub si,160
call stackFill ; y-1
add si,78
call stackFill ; x-1
lodsw ; si+=2
@: ret
heapPtr: ; start of game map memory heap
;END OF PROGRAM



