Passing parameters and references in 16bit TASM
Posted on 2004-10-23
I'm presently converting a simple 16bit TASM video mode 13h program to use the stack instead of globals and register passing to functions. I'm learning from a MASM book which may be the reason for some confusion on my behalf.
At present I have the following three functions in a file that is assembled separately and then linked with my main file:
BackBuffer db 64000 dup(?)
_SaveVideoMode PROC near
ARG VideoMode:PTR BYTE
mov ah,0Fh ; function 0Fh - get current mode
int 10h ; Bios video service call
mov BYTE PTR [VideoMode],al ; save current mode
_ResetVideoMode PROC near
; Resets the prior video mode (as stored in VideoMode) ; Originally a global
mov al,VideoMode ; set video mode 3, text
xor ah,ah ; clear ah - set mode
int 10h ; call bios service
_DrawPixel proc near
LOCAL DT:BYTE ; UNUSED AT PRESENT, WILL BE USED
; Plot Color at (X,Y)
mov di, OFFSET BackBuffer
The pertinent sections of main:
VideoMode db ?
;... in main proc
Call _SaveVideoMode C, offset VideoMode
; Set up timer etc
Call _DrawPixel C, 160, 100, RED_INDEX ; Draw red pixel in center of screen
Call _FlipBuffer C ; Show the change...
Call _ResetVideoMode C,VideoMode
Now, I've used all of these functions successfully with globals and register passing, so I'm relatively sure that the logic is sound. However, it is evident from the results that none of the parameters passed are as expected...
What exactly am I doing wrong?
Thanks in advance for any help.
I've found in using the functions that if I use:
Call _DrawPixel C, ax, bx, RED_INDEX
It works fine, though with:
Call _DrawPixel C, WORD 170, WORD 110, RED_INDEX
it does not work as expected...
Isn't specifying an arg as a word the same as using a word register in the argument list?
Also, I seem to be getting functional behavior from the set/reset function when I set it as a word instead of a ptr byte in the argument list. (And I can't get it to pass as a byte at all, I'm getting the feeling that working with words works better...)
I'm still unsure as to what is wrong with the DrawPixel when I include the local variable (which I will need).