Skip to content

Commit

Permalink
[Decompilation] [th01] Boss entities: .BOS slot freeing function
Browse files Browse the repository at this point in the history
Still no need for the classic `if(ptr) { delete[] ptr; ptr = NULL }`
macro, since the `ptr` is unconditionally set to NULL here…

Part of P0120, funded by Yanga.
  • Loading branch information
nmlgc committed Sep 28, 2020
1 parent d48e553 commit 9738ba9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 149 deletions.
16 changes: 16 additions & 0 deletions th01/formats/bos.hpp
Expand Up @@ -52,6 +52,22 @@ struct bos_t {
image.planes.G = new dots16_t[plane_size / 2]; \
image.planes.E = new dots16_t[plane_size / 2];

// Always setting the pointer to NULL, for a change...
#define bos_image_ptr_free(ptr) \
if(ptr) { \
delete[] ptr; \
} \
ptr = NULL;

#define bos_free(slot_ptr) \
for(int image = 0; image < BOS_IMAGES_PER_SLOT; image++) { \
bos_image_ptr_free(slot_ptr.image[image].alpha); \
bos_image_ptr_free(slot_ptr.image[image].planes.B); \
bos_image_ptr_free(slot_ptr.image[image].planes.R); \
bos_image_ptr_free(slot_ptr.image[image].planes.G); \
bos_image_ptr_free(slot_ptr.image[image].planes.E); \
}

/// All functions that operate on this format are implemented redundantly for
/// both CBossEntity and CBossAnim, with their own respective entity arrays.
/// ---------------------------------------------------------------------
16 changes: 12 additions & 4 deletions th01/main/boss/entity_a.cpp
Expand Up @@ -51,10 +51,7 @@ int CBossEntity::load(const char fn[PF_FN_LEN], int slot)

bos_header_load(this, plane_size, fn);
if(!bos_header_only) {
/* TODO: Replace with the decompiled call
* bos_entity_free(slot);
* once that function is part of this translation unit */
__asm { push slot; nop; push cs; call near ptr bos_entity_free; pop cx; }
bos_entity_free(slot);
for(int i = 0; bos_image_count > i; i++) {
#define image bos_entity_images[slot].image[i]
bos_image_new(image, plane_size);
Expand Down Expand Up @@ -594,6 +591,17 @@ bool16 CBossEntity::hittest_orb(void) const
}
return false;
}

void bos_entity_free(int slot)
{
for(int image = 0; image < BOS_IMAGES_PER_SLOT; image++) {
bos_image_ptr_free(bos_entity_images[slot].image[image].alpha);
bos_image_ptr_free(bos_entity_images[slot].image[image].planes.B);
bos_image_ptr_free(bos_entity_images[slot].image[image].planes.R);
bos_image_ptr_free(bos_entity_images[slot].image[image].planes.G);
bos_image_ptr_free(bos_entity_images[slot].image[image].planes.E);
}
}
/// --------

/// Non-entity animations
Expand Down
146 changes: 1 addition & 145 deletions th01_reiiden.asm
Expand Up @@ -8884,158 +8884,14 @@ main_21_TEXT segment byte public 'CODE' use16
extern @CBossEntity@move_lock_unput_and_put_8$qiiii:proc
extern @CBossEntity@move_lock_and_put_8$qiiii:proc
extern @CBossEntity@hittest_orb$xqv:proc
extern _bos_entity_free:proc
main_21_TEXT ends

main_21__TEXT segment byte public 'CODE' use16
assume cs:main_21
;org 4
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing

; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
public _bos_entity_free
_bos_entity_free proc far

@@slot = word ptr 6

push bp
mov bp, sp
push si
push di
mov di, [bp+@@slot]
xor si, si
jmp loc_16B4B
; ---------------------------------------------------------------------------

loc_169D8:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov ax, word ptr (_bos_entity_images[bx].BOS_alpha+0)
or ax, word ptr (_bos_entity_images[bx].BOS_alpha+2)
jz short loc_16A09
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
call @$bdla$qnv c, large _bos_entity_images[bx].BOS_alpha

loc_16A09:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov word ptr (_bos_entity_images[bx].BOS_alpha+2), 0
mov word ptr (_bos_entity_images[bx].BOS_alpha+0), 0
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov ax, word ptr (_bos_entity_images[bx].BOS_B+0)
or ax, word ptr (_bos_entity_images[bx].BOS_B+2)
jz short loc_16A53
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
call @$bdla$qnv c, large _bos_entity_images[bx].BOS_B

loc_16A53:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov word ptr (_bos_entity_images[bx].BOS_B+2), 0
mov word ptr (_bos_entity_images[bx].BOS_B+0), 0
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov ax, word ptr (_bos_entity_images[bx].BOS_R+0)
or ax, word ptr (_bos_entity_images[bx].BOS_R+2)
jz short loc_16A9D
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
call @$bdla$qnv c, large _bos_entity_images[bx].BOS_R

loc_16A9D:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov word ptr (_bos_entity_images[bx].BOS_R+2), 0
mov word ptr (_bos_entity_images[bx].BOS_R+0), 0
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov ax, word ptr (_bos_entity_images[bx].BOS_G+0)
or ax, word ptr (_bos_entity_images[bx].BOS_G+2)
jz short loc_16AE7
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
call @$bdla$qnv c, large _bos_entity_images[bx].BOS_G

loc_16AE7:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov word ptr (_bos_entity_images[bx].BOS_G+2), 0
mov word ptr (_bos_entity_images[bx].BOS_G+0), 0
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov ax, word ptr (_bos_entity_images[bx].BOS_E+0)
or ax, word ptr (_bos_entity_images[bx].BOS_E+2)
jz short loc_16B31
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
call @$bdla$qnv c, large _bos_entity_images[bx].BOS_E

loc_16B31:
mov bx, di
imul bx, size bos_t
mov ax, si
imul ax, size bos_image_t
add bx, ax
mov word ptr (_bos_entity_images[bx].BOS_E+2), 0
mov word ptr (_bos_entity_images[bx].BOS_E+0), 0
inc si

loc_16B4B:
cmp si, 8
jl loc_169D8
pop di
pop si
pop bp
retf
_bos_entity_free endp


; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
Expand Down

0 comments on commit 9738ba9

Please sign in to comment.