2019-12-27 21:28:54 +00:00
|
|
|
scoredat_func macro nam:req
|
|
|
|
public nam
|
|
|
|
nam proc near
|
|
|
|
if GAME eq 5
|
[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
|
2019-12-27 21:28:54 +00:00
|
|
|
push si
|
|
|
|
mov bx, offset _hi
|
|
|
|
else
|
[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, @hi:word
|
2019-12-27 21:28:54 +00:00
|
|
|
push si
|
[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
|
|
|
mov bx, @hi
|
2019-12-27 21:28:54 +00:00
|
|
|
endif
|
|
|
|
mov si, bx
|
|
|
|
|
|
|
|
endfunc macro
|
|
|
|
pop si
|
[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
|
|
|
|
nam endp
|
|
|
|
if GAME eq 4
|
2019-12-27 21:28:54 +00:00
|
|
|
; TODO: Turn into unconditional EVEN once this is a separate
|
|
|
|
; translation unit
|
|
|
|
even
|
|
|
|
endif
|
|
|
|
endm
|
|
|
|
endm
|
|
|
|
|
|
|
|
scoredat_func SCOREDAT_DECODE
|
|
|
|
mov cx, size scoredat_t - 1
|
|
|
|
|
|
|
|
if GAME eq 5
|
|
|
|
mov dx, word ptr [bx+scoredat_section_t.key1]
|
|
|
|
add bx, scoredat_section_t.score
|
|
|
|
|
|
|
|
@@decode:
|
|
|
|
mov al, [bx+1]
|
|
|
|
ror al, 3
|
|
|
|
xor al, dh
|
|
|
|
add al, dl
|
|
|
|
add [bx], al
|
|
|
|
inc bx
|
|
|
|
loop @@decode
|
|
|
|
add [bx], dl
|
|
|
|
mov cx, size scoredat_t
|
|
|
|
xor bx, bx
|
|
|
|
else
|
|
|
|
mov ah, [bx+scoredat_section_t.key2]
|
|
|
|
add bx, scoredat_section_t.score
|
|
|
|
|
|
|
|
@@decode:
|
|
|
|
mov al, [bx+1]
|
|
|
|
ror al, 3
|
|
|
|
xor al, ah
|
|
|
|
add al, [si+scoredat_section_t.key1]
|
|
|
|
add [bx], al
|
|
|
|
inc bx
|
|
|
|
loop @@decode
|
|
|
|
mov al, [si+scoredat_section_t.key1]
|
|
|
|
add [bx], al
|
|
|
|
xor bx, bx
|
|
|
|
mov cx, size scoredat_t
|
|
|
|
endif
|
|
|
|
|
|
|
|
xor dx, dx
|
|
|
|
mov ax, [si+scoredat_section_t.sum]
|
|
|
|
add si, scoredat_section_t.score
|
|
|
|
|
|
|
|
@@sum:
|
|
|
|
mov bl, [si]
|
|
|
|
add dx, bx
|
|
|
|
inc si
|
|
|
|
loop @@sum
|
|
|
|
sub ax, dx
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
|
|
|
|
scoredat_func SCOREDAT_ENCODE
|
|
|
|
xor dx, dx
|
|
|
|
xor ax, ax
|
|
|
|
add bx, scoredat_section_t.score
|
|
|
|
mov cx, size scoredat_t
|
|
|
|
|
|
|
|
@@sum:
|
|
|
|
mov dl, [bx]
|
|
|
|
add ax, dx
|
|
|
|
inc bx
|
|
|
|
loop @@sum
|
|
|
|
mov [si+scoredat_section_t.sum], ax
|
|
|
|
call IRand
|
|
|
|
mov word ptr [si+scoredat_section_t.key1], ax
|
|
|
|
xor dx, dx
|
|
|
|
add si, size scoredat_section_t - 1
|
|
|
|
mov cx, size scoredat_t
|
|
|
|
|
|
|
|
@@encode:
|
|
|
|
add dl, al
|
|
|
|
sub [si], dl
|
|
|
|
mov dl, [si]
|
|
|
|
ror dl, 3
|
|
|
|
xor dl, ah
|
|
|
|
dec si
|
|
|
|
loop @@encode
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
purge scoredat_func
|