2022-03-06 22:16:48 +00:00
|
|
|
public @BB_LOAD$QNXC
|
|
|
|
@bb_load$qnxc proc near
|
2019-02-28 22:30:34 +00:00
|
|
|
push si
|
|
|
|
call hmem_allocbyte pascal, BB_SIZE
|
|
|
|
mov _bb_load_seg, ax
|
[Maintenance] Reimplement TASM's ARG directive for `MOV BX, SP` functions
`cPtrSize` is simply the wrong constant for calculating parameter
offsets on the stack, because it corresponds to the memory model's
default distance, not the function's distance. Luckily, ARG has a
RETURNS clause, and if you declare all parameters in there, ARG won't
emit that pesky and unnecessary `ENTER 0, 0` instruction. Big discovery
right there!
Sadly, ARG is unusable for ZUN's silly functions that keep the base
pointer in BX. TASM declares the resulting equates as `[BP+offset]`,
and it's apparently impossible to only get `offset` out of such an
equate later.
So, rather than staying with numbers, let's reimplement ARG for these
functions instead. This way, we can even abstract away the stack clear
size for the `RET` instructions.
It's a bit rough around the edges though, forcing you to explicitly
specify the function distance, and to pass the parameters in reverse
order compared to the C declaration (thankfully, all of these use the
PASCAL calling convention). It also doesn't work with more complex
types yet. But certainly better than numbers.
Part of P0134, funded by [Anonymous].
2021-02-10 11:51:14 +00:00
|
|
|
|
|
|
|
arg_bx near, @fn:dword
|
|
|
|
|
2019-02-28 22:30:34 +00:00
|
|
|
mov si, ds
|
|
|
|
mov ax, 3D00h
|
[Maintenance] Reimplement TASM's ARG directive for `MOV BX, SP` functions
`cPtrSize` is simply the wrong constant for calculating parameter
offsets on the stack, because it corresponds to the memory model's
default distance, not the function's distance. Luckily, ARG has a
RETURNS clause, and if you declare all parameters in there, ARG won't
emit that pesky and unnecessary `ENTER 0, 0` instruction. Big discovery
right there!
Sadly, ARG is unusable for ZUN's silly functions that keep the base
pointer in BX. TASM declares the resulting equates as `[BP+offset]`,
and it's apparently impossible to only get `offset` out of such an
equate later.
So, rather than staying with numbers, let's reimplement ARG for these
functions instead. This way, we can even abstract away the stack clear
size for the `RET` instructions.
It's a bit rough around the edges though, forcing you to explicitly
specify the function distance, and to pass the parameters in reverse
order compared to the C declaration (thankfully, all of these use the
PASCAL calling convention). It also doesn't work with more complex
types yet. But certainly better than numbers.
Part of P0134, funded by [Anonymous].
2021-02-10 11:51:14 +00:00
|
|
|
lds dx, @fn+2
|
2019-02-28 22:30:34 +00:00
|
|
|
int 21h ; DOS - 2+ - OPEN DISK FILE WITH HANDLE
|
|
|
|
; DS:DX -> ASCIZ filename
|
|
|
|
; AL = access mode
|
|
|
|
; 0 - read
|
|
|
|
mov bx, ax
|
|
|
|
mov ds, si
|
|
|
|
mov ds, _bb_load_seg
|
|
|
|
mov cx, BB_SIZE
|
|
|
|
xor dx, dx
|
|
|
|
mov ah, 3Fh
|
|
|
|
int 21h ; DOS - 2+ - READ FROM FILE WITH HANDLE
|
|
|
|
; BX = file handle, CX = number of bytes to read
|
|
|
|
; DS:DX -> buffer
|
|
|
|
mov ah, 3Eh
|
|
|
|
int 21h ; DOS - 2+ - CLOSE A FILE WITH HANDLE
|
|
|
|
; BX = file handle
|
|
|
|
mov ds, si
|
|
|
|
pop si
|
|
|
|
mov ax, _bb_load_seg
|
[Maintenance] Reimplement TASM's ARG directive for `MOV BX, SP` functions
`cPtrSize` is simply the wrong constant for calculating parameter
offsets on the stack, because it corresponds to the memory model's
default distance, not the function's distance. Luckily, ARG has a
RETURNS clause, and if you declare all parameters in there, ARG won't
emit that pesky and unnecessary `ENTER 0, 0` instruction. Big discovery
right there!
Sadly, ARG is unusable for ZUN's silly functions that keep the base
pointer in BX. TASM declares the resulting equates as `[BP+offset]`,
and it's apparently impossible to only get `offset` out of such an
equate later.
So, rather than staying with numbers, let's reimplement ARG for these
functions instead. This way, we can even abstract away the stack clear
size for the `RET` instructions.
It's a bit rough around the edges though, forcing you to explicitly
specify the function distance, and to pass the parameters in reverse
order compared to the C declaration (thankfully, all of these use the
PASCAL calling convention). It also doesn't work with more complex
types yet. But certainly better than numbers.
Part of P0134, funded by [Anonymous].
2021-02-10 11:51:14 +00:00
|
|
|
ret_bx
|
2022-03-06 22:16:48 +00:00
|
|
|
@bb_load$qnxc endp
|
2019-02-28 22:30:34 +00:00
|
|
|
nop
|