NOW we finally draw something correctly...

This commit is contained in:
José Carlos Cuevas 2020-06-07 14:10:33 +02:00
parent 5cf5824b14
commit 7392932305

123
mine.asm
View file

@ -1,6 +1,9 @@
format MZ ;Specify the
org 100h ;specify .COM file
format MZ ;Specify the .EXE format
entry MainSeg:start
org 0100h
stack $3000
;org 100h ;specify origin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -12,13 +15,65 @@ LINES = 8
;Code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment MainSeg
use16
start:
; mov al,13h ;AX=0000 at program start
; int 10h ;init mode 13h
; push word 0A000h ;Requires 80186 or higher to PUSH IMMED
; pop es ;ES now points to mode 13h screen segment
; push word 00000h ;
; pop si
mov al,13h ;AX=0000 at program start
int 10h ;init mode 13h
push word 0A000h ;Requires 80186 or higher to PUSH IMMED
pop es ;ES now points to mode 13h screen segment
mov ax, DataSeg
mov ds, ax ;DS now points to our data segment
; Test draw a box
mov cx, 00h ;Y is 0
mov ax, 00h ;X is 0
mov bx, covercell
call drawbox ;Draw a box with this data
jmp mainloop
;This is thought to pick up from the registers the address of what we need to draw
;Draw it, and return. The params are:
;- AX -> X position
;- CX -> Y position
;- BX -> base memory address of the bitmap
drawbox:
push ax ;Save the X value for later
mov ax, cx ;Prepare for multiplications
mov cl, 8
mul cl ;This routine maintains the 8x8 positions
mov cx, 320 ;
mul cl ;And now we count whole lines for the address
mov cx, ax ;Retrieve the line into CX
pop ax ;Retrieve the X value into AX register
mov dl, 8
mul dl ;We multiply the X value too for the 8x8
add cx, ax ;Now we've put in AX the pointer value
mov si, cx ;Set SI to the correct address we'll draw
mov cx, 00
mov ax, 00
mov dx, 00
drawloop:
mov al, byte [ds:bx] ;Current address in BX
mov byte [es:si], al ;Put the pixel into RAM
inc bx
inc cx
inc dx
cmp dx, 08h ;Sort of modulo
je jumplinedraw ;Time to increment SI in a more complex way
inc si
continuecomp:
cmp cx, 040h ;Compare CX to hex 64 (8x8)
jne drawloop ;Continue
ret ;Return
jumplinedraw:
mov dx, 00h
add si, 313 ;Jump a whole line
jmp continuecomp ;Continue the routine
mainloop:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -27,23 +82,23 @@ mainloop:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Check for user wanting to leave by pressing ESC
in al,60h ;read whatever is at keyboard port; looking for ESC which is #1
cmp al,48h
je upkey
cmp al,4bh
je leftkey
cmp al,4dh
je rightkey
cmp al,50h
je downkey
cmp al,39h
je space
cmp al,38h
je lalt
mov dword [lastkeypressed], 0h ;Reset the current key as it is not one we are checking
dec al ;if ESC, AL now 0
jnz mainloop ;fall through if 0, jump otherwise
;Check for user input or wanting to leave by pressing ESC
in al,60h ;read whatever is at keyboard port; looking for ESC which is #1
; cmp al,48h
; je upkey
; cmp al,4bh
; je leftkey
; cmp al,4dh
; je rightkey
; cmp al,50h
; je downkey
; cmp al,39h
; je space
; cmp al,38h
; je lalt
; mov word [lastkeypressed], 0h ;Reset the current key as it is not one we are checking
dec al ;if ESC, AL now 0
jnz mainloop ;fall through if 0, jump otherwise
exit:
mov al,03 ;AX=0000 due to mainloop exit condition
@ -110,4 +165,22 @@ lalt:
;Data segment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment DataSeg
use16
lastkeypressed: db 0
;Game map. First 8 bytes are for the cell status
;the last 8 bytes are for the cell contents.
;
;Cell status: 0 covered, 1 uncovered, 2 flagged
;Cell content: 0 empty, 1-8 number, 9 mine
map: dw COLUMNS * LINES dup ?
covercell: db 0fh, 0fh, 0fh, 0fh, 0fh, 0fh, 0fh, 0fh
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 0fh, 17h, 17h, 17h, 17h, 17h, 17h, 14h
db 14h, 14h, 14h, 14h, 14h, 14h, 14h, 14h