From d158d186e2bf0e5f13b7c90e2bc9412af4f1e22e Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 11 Jun 2020 19:15:43 +0200 Subject: [PATCH] [Decompilation] [th01] Player shots: Reset function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why the sloppyness of unblitting a whole 16×16 rectangle *if you have a dedicated function to precisely unblit a .PTN sprite using its alpha mask*??? Oh well, it's not the regular function called in the main loop, so who cares…? Part of P0098, funded by Yanga. --- th01/main/player/shots.cpp | 23 ++++++++++++ th01/main/player/shots.hpp | 1 + th01/main_38.cpp | 1 + th01_reiiden.asm | 76 +++----------------------------------- 4 files changed, 31 insertions(+), 70 deletions(-) diff --git a/th01/main/player/shots.cpp b/th01/main/player/shots.cpp index 68994118..5c98e7a1 100644 --- a/th01/main/player/shots.cpp +++ b/th01/main/player/shots.cpp @@ -1,7 +1,15 @@ #include "th01/snd/mdrv2.h" +#include "th01/formats/ptn.hpp" +#include "th01/hardware/egc.h" #include "th01/main/playfld.hpp" #include "th01/main/player/shots.hpp" +static const int SHOT_W = PTN_QUARTER_W; +static const int SHOT_H = PTN_QUARTER_H; + +#define sloppy_unput(i) \ + egc_copy_rect_1_to_0(left[i], top[i], SHOT_W, SHOT_H); + void CShots::add(int new_left, int new_top) { if(new_left < PLAYFIELD_LEFT || new_left > (PLAYFIELD_RIGHT - 1)) { @@ -22,3 +30,18 @@ void CShots::add(int new_left, int new_top) return; } } + +void CShots::unput_and_reset_all(void) +{ + for(int i = 0; i < SHOT_COUNT; i++) { + if(moving[i]) { + sloppy_unput(i); + moving[i] = false; + } else if(decay_frame[i]) { + sloppy_unput(i); + decay_frame[i] = false; + } + } +} + +#undef sloppy_unput diff --git a/th01/main/player/shots.hpp b/th01/main/player/shots.hpp index 253fa98e..756a5106 100644 --- a/th01/main/player/shots.hpp +++ b/th01/main/player/shots.hpp @@ -10,6 +10,7 @@ struct CShots { unsigned char decay_frame[SHOT_COUNT]; void add(int new_left, int new_top); + void unput_and_reset_all(void); }; extern CShots Shots; diff --git a/th01/main_38.cpp b/th01/main_38.cpp index 5ed74ecd..e4045431 100644 --- a/th01/main_38.cpp +++ b/th01/main_38.cpp @@ -8,6 +8,7 @@ extern "C" { #include "platform.h" #include "pc98.h" +#include "planar.h" #include "th01/main/player/shots.cpp" } diff --git a/th01_reiiden.asm b/th01_reiiden.asm index 966f7ef2..493644fa 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -3501,7 +3501,7 @@ loc_D7E4: push offset unk_37635 call sub_30DEE add sp, 4 - call CShots_2FCAD c, offset _Shots, ds + call @CShots@unput_and_reset_all$qv c, offset _Shots, ds mov word ptr [bp+s1+2], ds mov word ptr [bp+s1], 1250h mov byte_34ADF, 0 @@ -4408,7 +4408,7 @@ loc_E224: loc_E244: inc si call sub_CE5C - call CShots_2FCAD c, offset _Shots, ds + call @CShots@unput_and_reset_all$qv c, offset _Shots, ds push ds push offset unk_37635 call sub_30DEE @@ -7567,7 +7567,7 @@ arg_0 = word ptr 6 enter 6, 0 push si push di - call CShots_2FCAD c, offset _Shots, ds + call @CShots@unput_and_reset_all$qv c, offset _Shots, ds push ds push offset unk_37635 call sub_30DEE @@ -18563,7 +18563,7 @@ loc_1AE85: push ax call _egc_copy_rect_1_to_0 add sp, 8 - call CShots_2FCAD c, offset _Shots, ds + call @CShots@unput_and_reset_all$qv c, offset _Shots, ds push ds push offset unk_37635 call sub_30E54 @@ -49271,7 +49271,7 @@ loc_2C835: jnz loc_2CAA8 mov word_3A6CA, 0 mov word_3B433, 18Fh - call CShots_2FCAD c, offset _Shots, ds + call @CShots@unput_and_reset_all$qv c, offset _Shots, ds push ds push offset unk_37635 call sub_30DEE @@ -54631,71 +54631,7 @@ main_38__TEXT segment byte public 'CODE' use16 assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing extern @CShots@add$qii:proc - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -CShots_2FCAD proc far - -@@CShots = dword ptr 6 - - push bp - mov bp, sp - push si - xor si, si - jmp short loc_2FD20 -; --------------------------------------------------------------------------- - -loc_2FCB5: - les bx, [bp+@@CShots] - add bx, si - cmp es:[bx+CShots.SHOT_moving], 0 - jz short loc_2FCEB - push (16 shl 16) or 16 - mov ax, si - add ax, ax - mov bx, word ptr [bp+@@CShots] - add bx, ax - push es:[bx+CShots.SHOT_top] - push es:[bx+CShots.SHOT_left] - call _egc_copy_rect_1_to_0 - add sp, 8 - les bx, [bp+@@CShots] - add bx, si - mov es:[bx+CShots.SHOT_moving], 0 - jmp short loc_2FD1F -; --------------------------------------------------------------------------- - -loc_2FCEB: - les bx, [bp+@@CShots] - add bx, si - cmp es:[bx+CShots.SHOT_decay_frame], 0 - jz short loc_2FD1F - push (16 shl 16) or 16 - mov ax, si - add ax, ax - mov bx, word ptr [bp+@@CShots] - add bx, ax - push es:[bx+CShots.SHOT_top] - push es:[bx+CShots.SHOT_left] - call _egc_copy_rect_1_to_0 - add sp, 8 - les bx, [bp+@@CShots] - add bx, si - mov es:[bx+CShots.SHOT_decay_frame], 0 - -loc_2FD1F: - inc si - -loc_2FD20: - cmp si, SHOT_COUNT - jl short loc_2FCB5 - pop si - pop bp - retf -CShots_2FCAD endp - + extern @CShots@unput_and_reset_all$qv:proc ; =============== S U B R O U T I N E =======================================