2020-11-14 16:24:04 +00:00
|
|
|
.386
|
2021-03-29 17:16:49 +00:00
|
|
|
.model use16 large SHARED_
|
2020-11-14 16:24:04 +00:00
|
|
|
locals
|
|
|
|
|
[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
|
|
|
include th03/arg_bx.inc
|
2020-11-14 16:24:04 +00:00
|
|
|
include th03/formats/cdg.inc
|
|
|
|
|
|
|
|
extrn FILE_ROPEN:proc
|
|
|
|
extrn FILE_READ:proc
|
|
|
|
extrn FILE_SEEK:proc
|
|
|
|
extrn FILE_CLOSE:proc
|
|
|
|
extrn HMEM_ALLOCBYTE:proc
|
|
|
|
extrn HMEM_FREE:proc
|
|
|
|
extrn _cdg_slots:cdg_t:CDG_SLOT_COUNT
|
2021-01-05 18:16:19 +00:00
|
|
|
extrn _cdg_noalpha:byte
|
2020-11-14 16:24:04 +00:00
|
|
|
extrn cdg_images_to_load:byte
|
|
|
|
|
|
|
|
g_SHARED group SHARED, SHARED_
|
|
|
|
SHARED segment word public 'CODE' use16
|
|
|
|
SHARED ends
|
|
|
|
|
|
|
|
SHARED_ segment word public 'CODE' use16
|
|
|
|
assume cs:g_SHARED
|
|
|
|
|
2019-09-15 16:23:33 +00:00
|
|
|
public CDG_LOAD_SINGLE_NOALPHA
|
|
|
|
public CDG_LOAD_SINGLE
|
2017-01-19 20:14:22 +00:00
|
|
|
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_load_single_noalpha label proc
|
2021-01-05 18:16:19 +00:00
|
|
|
mov _cdg_noalpha, 1
|
2017-01-19 20:14:22 +00:00
|
|
|
align 2
|
|
|
|
|
2019-09-15 14:22:36 +00:00
|
|
|
cdg_load_single proc far
|
2017-01-19 20:14:22 +00:00
|
|
|
|
|
|
|
@@n = word ptr 6
|
|
|
|
@@fn = dword ptr 8
|
|
|
|
@@slot = word ptr 12
|
|
|
|
|
|
|
|
push bp
|
|
|
|
mov bp, sp
|
|
|
|
push si
|
|
|
|
push di
|
|
|
|
mov di, [bp+@@slot]
|
|
|
|
push di
|
2020-11-14 16:24:04 +00:00
|
|
|
nop ; This was definitely compiled from C...
|
|
|
|
call cdg_free
|
|
|
|
shl di, 4 ; *= size cdg_t
|
2017-01-19 20:14:22 +00:00
|
|
|
add di, offset _cdg_slots
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_ropen pascal, large [bp+@@fn]
|
|
|
|
call file_read pascal, ds, di, size cdg_t
|
2020-09-05 14:09:18 +00:00
|
|
|
mov ax, [di+cdg_t.CDG_plane_size]
|
2017-01-19 20:14:22 +00:00
|
|
|
mov dx, ax
|
2020-09-05 14:09:18 +00:00
|
|
|
cmp [di+cdg_t.plane_layout], CDG_COLORS
|
2017-01-19 20:14:22 +00:00
|
|
|
jz short @@read
|
|
|
|
shl ax, 2
|
2020-09-05 14:09:18 +00:00
|
|
|
cmp [di+cdg_t.plane_layout], CDG_ALPHA
|
2017-01-19 20:14:22 +00:00
|
|
|
jz short @@read
|
|
|
|
add ax, dx
|
|
|
|
|
|
|
|
@@read:
|
|
|
|
mul [bp+@@n]
|
|
|
|
movzx eax, ax
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_seek pascal, eax, 1
|
2019-09-15 14:22:36 +00:00
|
|
|
call cdg_read_single
|
2017-01-19 20:14:22 +00:00
|
|
|
call file_close
|
2021-01-05 18:16:19 +00:00
|
|
|
mov _cdg_noalpha, 0
|
2017-01-19 20:14:22 +00:00
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
pop bp
|
|
|
|
retf 8
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_load_single endp
|
2017-01-19 20:14:22 +00:00
|
|
|
align 2
|
|
|
|
|
|
|
|
; Reads a single CDG image from the master.lib file, which previously has been
|
|
|
|
; positioned at the beginning of the image data, into the slot in DI.
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_read_single proc near
|
2020-09-05 14:09:18 +00:00
|
|
|
mov al, [di+cdg_t.plane_layout]
|
|
|
|
or al, al ; AL == CDG_COLORS?
|
2017-01-19 20:14:22 +00:00
|
|
|
jz short @@colors
|
2020-09-05 14:09:18 +00:00
|
|
|
cmp al, CDG_ALPHA
|
2017-01-19 20:14:22 +00:00
|
|
|
jz short @@alpha
|
2021-01-05 18:16:19 +00:00
|
|
|
cmp _cdg_noalpha, 0
|
2017-01-19 20:14:22 +00:00
|
|
|
jnz short @@skip_alpha
|
|
|
|
|
|
|
|
@@alpha:
|
2020-11-14 16:24:04 +00:00
|
|
|
call hmem_allocbyte pascal, [di+cdg_t.CDG_plane_size]
|
2020-09-05 14:09:18 +00:00
|
|
|
mov [di+cdg_t.seg_alpha], ax
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_read pascal, ax, 0, [di+cdg_t.CDG_plane_size]
|
2017-01-19 20:14:22 +00:00
|
|
|
jmp short @@colors
|
|
|
|
|
|
|
|
@@skip_alpha:
|
2020-09-05 14:09:18 +00:00
|
|
|
movzx eax, [di+cdg_t.CDG_plane_size]
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_seek pascal, eax, 1
|
2017-01-19 20:14:22 +00:00
|
|
|
|
|
|
|
@@colors:
|
2020-09-05 14:09:18 +00:00
|
|
|
cmp [di+cdg_t.plane_layout], CDG_ALPHA
|
2017-01-19 20:14:22 +00:00
|
|
|
jz short @@ret
|
2020-09-05 14:09:18 +00:00
|
|
|
mov ax, [di+cdg_t.CDG_plane_size]
|
2017-01-19 20:14:22 +00:00
|
|
|
shl ax, 2
|
2020-11-14 16:24:04 +00:00
|
|
|
call hmem_allocbyte pascal, ax
|
2020-09-05 14:09:18 +00:00
|
|
|
mov [di+cdg_t.seg_colors], ax
|
2017-01-19 20:14:22 +00:00
|
|
|
push ax
|
|
|
|
push 0
|
2020-09-05 14:09:18 +00:00
|
|
|
mov ax, [di+cdg_t.CDG_plane_size]
|
2017-01-19 20:14:22 +00:00
|
|
|
shl ax, 2
|
|
|
|
push ax
|
|
|
|
call file_read
|
|
|
|
|
|
|
|
@@ret:
|
|
|
|
retn
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_read_single endp
|
2017-01-19 20:14:22 +00:00
|
|
|
|
|
|
|
|
2019-09-15 16:23:33 +00:00
|
|
|
public CDG_LOAD_ALL_NOALPHA
|
|
|
|
public CDG_LOAD_ALL
|
2017-01-19 20:14:22 +00:00
|
|
|
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_load_all_noalpha label proc
|
2021-01-05 18:16:19 +00:00
|
|
|
mov _cdg_noalpha, 1
|
2017-01-19 20:14:22 +00:00
|
|
|
align 2
|
|
|
|
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_load_all proc far
|
2017-01-19 20:14:22 +00:00
|
|
|
|
|
|
|
@@fn = dword ptr 6
|
|
|
|
@@slot_first = word ptr 10
|
|
|
|
|
|
|
|
push bp
|
|
|
|
mov bp, sp
|
|
|
|
push si
|
|
|
|
push di
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_ropen pascal, large [bp+@@fn]
|
2021-03-27 13:22:50 +00:00
|
|
|
cdg_slot_offset di, [bp+@@slot_first]
|
2020-11-14 16:24:04 +00:00
|
|
|
call file_read pascal, ds, di, size cdg_t
|
2017-01-19 20:14:22 +00:00
|
|
|
mov si, di
|
|
|
|
mov bp, [bp+@@slot_first]
|
2020-09-05 14:09:18 +00:00
|
|
|
mov al, cdg_t.image_count[si]
|
2017-01-19 20:14:22 +00:00
|
|
|
mov cdg_images_to_load, al
|
|
|
|
push ds
|
|
|
|
pop es
|
|
|
|
|
|
|
|
@@loop:
|
2020-11-14 16:24:04 +00:00
|
|
|
call cdg_free pascal, bp
|
|
|
|
mov cx, (cdg_t.seg_alpha / dword)
|
2017-01-19 20:14:22 +00:00
|
|
|
rep movsd
|
2020-09-05 14:09:18 +00:00
|
|
|
sub si, cdg_t.seg_alpha
|
|
|
|
sub di, cdg_t.seg_alpha
|
2019-09-15 14:22:36 +00:00
|
|
|
call cdg_read_single
|
2017-01-19 20:14:22 +00:00
|
|
|
inc bp
|
2020-09-05 14:09:18 +00:00
|
|
|
add di, size cdg_t
|
2017-01-19 20:14:22 +00:00
|
|
|
dec cdg_images_to_load
|
|
|
|
jnz short @@loop
|
|
|
|
call file_close
|
2021-01-05 18:16:19 +00:00
|
|
|
mov _cdg_noalpha, 0
|
2017-01-19 20:14:22 +00:00
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
pop bp
|
|
|
|
retf 6
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_load_all endp
|
2017-01-19 20:14:22 +00:00
|
|
|
|
|
|
|
|
2019-09-15 16:23:33 +00:00
|
|
|
public CDG_FREE
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_free proc far
|
[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 far, @slot:word
|
2020-11-14 16:24:04 +00:00
|
|
|
|
2017-01-19 20:14:22 +00:00
|
|
|
push di
|
[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 di, @slot
|
2020-11-14 16:24:04 +00:00
|
|
|
shl di, 4 ; *= size cdg_t
|
2020-09-05 14:09:18 +00:00
|
|
|
add di, offset _cdg_slots.seg_alpha
|
2017-01-19 20:14:22 +00:00
|
|
|
cmp word ptr [di], 0
|
|
|
|
jz short @@colors
|
2020-11-14 16:24:04 +00:00
|
|
|
call hmem_free pascal, word ptr [di]
|
2017-01-19 20:14:22 +00:00
|
|
|
mov word ptr [di], 0
|
|
|
|
|
|
|
|
@@colors:
|
2020-11-14 16:24:04 +00:00
|
|
|
add di, word ; = seg_colors
|
2017-01-19 20:14:22 +00:00
|
|
|
cmp word ptr [di], 0
|
|
|
|
jz short @@ret
|
2020-11-14 16:24:04 +00:00
|
|
|
call hmem_free pascal, word ptr [di]
|
2017-01-19 20:14:22 +00:00
|
|
|
mov word ptr [di], 0
|
|
|
|
|
|
|
|
@@ret:
|
|
|
|
pop di
|
[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
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_free endp
|
2017-01-19 20:14:22 +00:00
|
|
|
align 2
|
|
|
|
|
|
|
|
|
2020-09-05 15:52:09 +00:00
|
|
|
public CDG_FREE_ALL
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_free_all proc far
|
2017-01-19 20:14:22 +00:00
|
|
|
push si
|
|
|
|
mov si, CDG_SLOT_COUNT - 1
|
|
|
|
|
|
|
|
@@loop:
|
2019-09-15 14:22:36 +00:00
|
|
|
call cdg_free pascal, si
|
2017-01-19 20:14:22 +00:00
|
|
|
dec si
|
|
|
|
jge short @@loop
|
|
|
|
pop si
|
|
|
|
retf
|
2020-11-14 16:24:04 +00:00
|
|
|
cdg_free_all endp
|
|
|
|
SHARED_ ends
|
|
|
|
|
|
|
|
end
|