From 9738ba921a8069e8543453e51300c220d96fc598 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Wed, 23 Sep 2020 21:48:48 +0200 Subject: [PATCH] [Decompilation] [th01] Boss entities: .BOS slot freeing function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- th01/formats/bos.hpp | 16 ++++ th01/main/boss/entity_a.cpp | 16 +++- th01_reiiden.asm | 146 +----------------------------------- 3 files changed, 29 insertions(+), 149 deletions(-) diff --git a/th01/formats/bos.hpp b/th01/formats/bos.hpp index 4343462b..f27b46d3 100644 --- a/th01/formats/bos.hpp +++ b/th01/formats/bos.hpp @@ -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. /// --------------------------------------------------------------------- diff --git a/th01/main/boss/entity_a.cpp b/th01/main/boss/entity_a.cpp index c58328a3..d39c1bfb 100644 --- a/th01/main/boss/entity_a.cpp +++ b/th01/main/boss/entity_a.cpp @@ -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); @@ -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 diff --git a/th01_reiiden.asm b/th01_reiiden.asm index 037fa894..cac7ce8d 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -8884,6 +8884,7 @@ 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 @@ -8891,151 +8892,6 @@ main_21__TEXT segment byte public 'CODE' use16 ;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