Johann 'Myrkraverk' Oskarsson
2019-10-26 22:43:42 UTC
Dear c.o.m.programmer and c.l.a.x86,
[Note: crossposted to c.o.m.p and c.l.a.x]
I am working my way through this 16bit assembly tutorial,
https://github.com/adamsmasher/sokobanDOS/tree/master/lesson2
except that I'm using the OpenWatcom assembler, wasm.
As far as I know, I've translated the nasm syntax to wasm correctly;
which is incidentally pretty similar to masm. And from reading the
code, I'm fairly certait *it should work* but doesn't. When I run it in
DOSBox-X, it doesn't quit when I press escape.
What am I missing here? I apologize for the lengthy code, it's the
complete tutorial lesson 2.
I'm compiling it like so,
wasm dostut2.asm
wlink sys dos com file dostut2.obj
and then running it in DOSBox-X. I'm fairly certain the problem is with
my code, and not in DOSBox-X.
Thank you.
;; file dostut2.asm
.286 ; we don't use bits 16 in wasm
.model tiny
.code
org 100h ; dos loads here
main proc
call installkb
call initvideo
gameloop:
call waitframe
cmp byte ptr [quit], 1
jne gameloop
call restorevideo
call restorekb
;; exit
mov ah, 4ch
mov al, 00h
int 21h
main endp
quit: db 0
include video.asm
include kb.asm
end
;; end of file: dostut2.asm
;;-----------------------------------------------------------------
;; file: video.asm
waitframe proc
push dx
;; port 0x3da contains vga status
mov dx, 03dah
waitretrace:
in al, dx ; read from port 0x03da into al
;; bit 3 will be on if we're in retrace
test al, 08h ; are we in retrace?
jnz waitretrace
endrefresh:
in al, dx
test al, 0x08 ; are we in refresh?
jz endrefresh
pop dx
ret
waitframe endp
initvideo proc
;; set mode to 0x13
mov ax, 13h
int 10h
ret
initvideo endp
restorevideo proc
;; return to text mode 0x03
mov ax, 03h
int 10h
ret
restorevideo endp
;; end of file: video.asm
;;-----------------------------------------------------------------
;; file: kb.asm
oldkbhandler: dw 0
oldkbseg: dw 0
installkb proc
push es
push bx
push dx
;; backup old kb interrupt
mov ax, 3509h
int 21h
mov [oldkbhandler], bx
mov [oldkbseg], es
;; install new kb interrupt
mov ah, 23h
mov dx, kbhandler
int 21h
pop dx
pop bx
pop es
ret
installkb endp
restorekb proc
push dx
push ds
mov ax, 2509h
mov dx, [oldkbhandler]
mov ds, [oldkbseg]
int 21h
pop ds
pop dx
ret
restorekb endp
kbhandler proc
push ax
in al, 60h ; get key event
cmp al, 01h ; esc pressed?
jne done ; if this is .done then wasm silently
mov byte ptr [quit], al ; doesn't create the object file.
done: mov al, 20h ; ack
out 20h, al ; send ack
pop ax
iret
kbhandler endp
;; end of file: kb.asm
[Note: crossposted to c.o.m.p and c.l.a.x]
I am working my way through this 16bit assembly tutorial,
https://github.com/adamsmasher/sokobanDOS/tree/master/lesson2
except that I'm using the OpenWatcom assembler, wasm.
As far as I know, I've translated the nasm syntax to wasm correctly;
which is incidentally pretty similar to masm. And from reading the
code, I'm fairly certait *it should work* but doesn't. When I run it in
DOSBox-X, it doesn't quit when I press escape.
What am I missing here? I apologize for the lengthy code, it's the
complete tutorial lesson 2.
I'm compiling it like so,
wasm dostut2.asm
wlink sys dos com file dostut2.obj
and then running it in DOSBox-X. I'm fairly certain the problem is with
my code, and not in DOSBox-X.
Thank you.
;; file dostut2.asm
.286 ; we don't use bits 16 in wasm
.model tiny
.code
org 100h ; dos loads here
main proc
call installkb
call initvideo
gameloop:
call waitframe
cmp byte ptr [quit], 1
jne gameloop
call restorevideo
call restorekb
;; exit
mov ah, 4ch
mov al, 00h
int 21h
main endp
quit: db 0
include video.asm
include kb.asm
end
;; end of file: dostut2.asm
;;-----------------------------------------------------------------
;; file: video.asm
waitframe proc
push dx
;; port 0x3da contains vga status
mov dx, 03dah
waitretrace:
in al, dx ; read from port 0x03da into al
;; bit 3 will be on if we're in retrace
test al, 08h ; are we in retrace?
jnz waitretrace
endrefresh:
in al, dx
test al, 0x08 ; are we in refresh?
jz endrefresh
pop dx
ret
waitframe endp
initvideo proc
;; set mode to 0x13
mov ax, 13h
int 10h
ret
initvideo endp
restorevideo proc
;; return to text mode 0x03
mov ax, 03h
int 10h
ret
restorevideo endp
;; end of file: video.asm
;;-----------------------------------------------------------------
;; file: kb.asm
oldkbhandler: dw 0
oldkbseg: dw 0
installkb proc
push es
push bx
push dx
;; backup old kb interrupt
mov ax, 3509h
int 21h
mov [oldkbhandler], bx
mov [oldkbseg], es
;; install new kb interrupt
mov ah, 23h
mov dx, kbhandler
int 21h
pop dx
pop bx
pop es
ret
installkb endp
restorekb proc
push dx
push ds
mov ax, 2509h
mov dx, [oldkbhandler]
mov ds, [oldkbseg]
int 21h
pop ds
pop dx
ret
restorekb endp
kbhandler proc
push ax
in al, 60h ; get key event
cmp al, 01h ; esc pressed?
jne done ; if this is .done then wasm silently
mov byte ptr [quit], al ; doesn't create the object file.
done: mov al, 20h ; ack
out 20h, al ; send ack
pop ax
iret
kbhandler endp
;; end of file: kb.asm
--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk