From ea0997ab389a2128de0f7b5b3d2e37cf6651e5e5 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 30 Sep 2021 22:21:47 +0200 Subject: [PATCH] [Decompilation] [th01] Pellet speed modification Category: Function comment spells out entire function code because its effects are impossible to summarize Part of P0160, funded by Yanga. --- th01/main/bullet/pellet.cpp | 4 +- th01/main/bullet/pellet_s.cpp | 21 +++++++++ th01/main/bullet/pellet_s.hpp | 19 ++++++++ th01/main_012.cpp | 6 +++ th01/resident.hpp | 13 +++++- th01_reiiden.asm | 85 ++++------------------------------- 6 files changed, 69 insertions(+), 79 deletions(-) create mode 100644 th01/main/bullet/pellet_s.cpp create mode 100644 th01/main/bullet/pellet_s.hpp diff --git a/th01/main/bullet/pellet.cpp b/th01/main/bullet/pellet.cpp index 9343f2cc..80d81ac3 100644 --- a/th01/main/bullet/pellet.cpp +++ b/th01/main/bullet/pellet.cpp @@ -178,7 +178,9 @@ inline subpixel_t base_speed_for_rank(void) #define speed_set(speed) \ speed += base_speed_for_rank(); \ - speed += ((resident->pellet_speed * speed) / to_sp(2.5f)); \ + /* Note that ((subpixel * pellet_speed_t) / pellet_speed_t) still gives a + /* correct subpixel result. */ \ + speed += ((resident->pellet_speed * speed) / PELLET_SPEED_MULTIPLIER); \ if(speed < to_sp(1.0f)) { \ speed = to_sp(1.0f); \ } diff --git a/th01/main/bullet/pellet_s.cpp b/th01/main/bullet/pellet_s.cpp new file mode 100644 index 00000000..f4a53d7e --- /dev/null +++ b/th01/main/bullet/pellet_s.cpp @@ -0,0 +1,21 @@ +#include "th01/main/bullet/pellet_s.hpp" + +void pellet_speed_lower(pellet_speed_t max, pellet_speed_t negative_delta) +{ + if(resident->pellet_speed > max) { + resident->pellet_speed = max; + } else { + resident->pellet_speed += negative_delta; + } + if(resident->pellet_speed < PELLET_SPEED_LOWER_MIN) { + resident->pellet_speed = PELLET_SPEED_LOWER_MIN; + } +} + +void pellet_speed_raise(pellet_speed_t delta) +{ + resident->pellet_speed += delta; + if(resident->pellet_speed > PELLET_SPEED_RAISE_MAX) { + resident->pellet_speed = PELLET_SPEED_RAISE_MAX; + } +} diff --git a/th01/main/bullet/pellet_s.hpp b/th01/main/bullet/pellet_s.hpp new file mode 100644 index 00000000..3b142b77 --- /dev/null +++ b/th01/main/bullet/pellet_s.hpp @@ -0,0 +1,19 @@ +#define PELLET_SPEED_LOWER_MIN to_pellet_speed(-0.375f) +#define PELLET_SPEED_RAISE_MAX to_pellet_speed(0.5f) + +// Clamps the resident speed of newly fired pellets to the given maximum value +// if it's higher, then raises (sic) it by [negative_delta], down to a minimum +// of [PELLET_SPEED_LOWER_MIN]. +void pellet_speed_lower(pellet_speed_t max, pellet_speed_t negative_delta); + +inline void pellet_speed_lower(float max, float negative_delta) { + pellet_speed_lower(to_pellet_speed(max), to_pellet_speed(negative_delta)); +} + +// Raises the resident speed of newly fired pellets by [delta], up to a +// maximum of [PELLET_SPEED_RAISE_MAX]. +void pellet_speed_raise(pellet_speed_t delta); + +inline void pellet_speed_raise(float delta) { + pellet_speed_raise(to_pellet_speed(delta)); +} diff --git a/th01/main_012.cpp b/th01/main_012.cpp index ece2a4d1..694a2c1b 100644 --- a/th01/main_012.cpp +++ b/th01/main_012.cpp @@ -2,3 +2,9 @@ * ----- * 3rd part of code segment #1 of TH01's REIIDEN.EXE */ + +#include "platform.h" +#include "th01/common.h" +#include "th01/resident.hpp" + +#include "th01/main/bullet/pellet_s.cpp" diff --git a/th01/resident.hpp b/th01/resident.hpp index 29f9d57f..39070e51 100644 --- a/th01/resident.hpp +++ b/th01/resident.hpp @@ -9,6 +9,17 @@ typedef enum { MODE_DEBUG = 3 } mode_t; +// Much like subpixels, pellet speeds are stored pre-multiplied by 40 to allow +// an effective resolution of 0.025 pixels to be losslessly stored in an +// integer. This pre-multiplication is reverted by the pellet spawning +// functions. +typedef int pellet_speed_t; + +static const pellet_speed_t PELLET_SPEED_MULTIPLIER = 40; + +#define to_pellet_speed(pixel_v) \ + static_cast(pixel_v * PELLET_SPEED_MULTIPLIER) + #define RES_ID "ReiidenConfig" typedef struct { char id[sizeof(RES_ID)]; @@ -23,7 +34,7 @@ typedef struct { char snd_need_init; char unused_2; char mode; - int pellet_speed; + pellet_speed_t pellet_speed; long rand; long score; long continues_total; diff --git a/th01_reiiden.asm b/th01_reiiden.asm index aab413fe..cbf562eb 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -1276,65 +1276,8 @@ sub_C942 endp main_012_TEXT ends main_013_TEXT segment byte public 'CODE' use16 - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_CBBE proc far - -arg_0 = word ptr 6 -arg_2 = word ptr 8 - - push bp - mov bp, sp - mov dx, [bp+arg_0] - les bx, _resident - cmp es:[bx+reiidenconfig_t.bullet_speed], dx - jle short loc_CBD4 - mov es:[bx+reiidenconfig_t.bullet_speed], dx - jmp short loc_CBDF -; --------------------------------------------------------------------------- - -loc_CBD4: - les bx, _resident - mov ax, [bp+arg_2] - add es:[bx+reiidenconfig_t.bullet_speed], ax - -loc_CBDF: - les bx, _resident - cmp es:[bx+reiidenconfig_t.bullet_speed], -15 - jge short loc_CBF0 - mov es:[bx+reiidenconfig_t.bullet_speed], -15 - -loc_CBF0: - pop bp - retf -sub_CBBE endp - - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_CBF2 proc far - -arg_0 = word ptr 6 - - push bp - mov bp, sp - les bx, _resident - mov ax, [bp+arg_0] - add es:[bx+reiidenconfig_t.bullet_speed], ax - cmp es:[bx+reiidenconfig_t.bullet_speed], 20 - jle short loc_CC0D - mov es:[bx+reiidenconfig_t.bullet_speed], 20 - -loc_CC0D: - pop bp - retf -sub_CBF2 endp - + extern @pellet_speed_lower$qii:proc + extern @pellet_speed_raise$qi:proc ; =============== S U B R O U T I N E ======================================= @@ -1390,9 +1333,7 @@ loc_CD2E: mov al, es:[bx+reiidenconfig_t.start_lives_extra] add al, 2 mov es:[bx+reiidenconfig_t.rem_lives], al - push 0FFFBFFFEh - call sub_CBBE - add sp, 4 + call @pellet_speed_lower$qii c, large (-2 and 0FFFFh) or (-5 shl 16) loc_CD52: call _input_sense stdcall, 0 @@ -1717,8 +1658,7 @@ sub_D02F proc far push 0Fh call _mdrv2_se_play pop cx - push 1 - call sub_CBF2 + call @pellet_speed_raise$qi stdcall, 1 pop cx loc_D076: @@ -3059,8 +2999,7 @@ loc_DC64: div ebx cmp edx, 0 jnz short loc_DC9D - push 1 - call sub_CBF2 + call @pellet_speed_raise$qi stdcall, 1 pop cx loc_DC9D: @@ -6368,8 +6307,7 @@ sub_1938A proc far call sub_192D6 cmp _stage_timer, 0 jnz short loc_193B8 - push 2 - call sub_CBF2 + call @pellet_speed_raise$qi stdcall, 2 pop cx nopcall @harryup_animate$qv pop bp @@ -6581,8 +6519,7 @@ loc_19FB0: jz short loc_19FDB mov byte_35B46, 2 mov _input_bomb, 0 - push 1 - call sub_CBF2 + call @pellet_speed_raise$qi stdcall, 1 jmp loc_1AC29 ; --------------------------------------------------------------------------- @@ -8450,13 +8387,7 @@ loc_1B01F: loc_1B028: call sub_193BA - -loc_1B02D: - push 0FFFE0000h - -loc_1B033: - call sub_CBBE - add sp, 4 + call @pellet_speed_lower$qii c, large 0 or (-2 shl 16) pop di pop si leave