From 4672f226bb3e378748e020af6cdacf40c33911a8 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 30 May 2021 15:43:12 +0200 Subject: [PATCH] [Decompilation] [th05] Shinki: Background particle rendering We really wouldn't have wanted to start writing inline ASM in the middle of a conditional expression just to get that janky `CMP AX, 0` instead of TCC's sensible `OR AX, AX` optimization. Part of P0146, funded by -Tom- and Ember2528. --- th05/formats/super.h | 2 +- th05/main/boss/render.cpp | 57 ++++++++++++++++++++++ th05_main.asm | 99 ++------------------------------------- 3 files changed, 63 insertions(+), 95 deletions(-) diff --git a/th05/formats/super.h b/th05/formats/super.h index 1f10b632..76eec34d 100644 --- a/th05/formats/super.h +++ b/th05/formats/super.h @@ -6,4 +6,4 @@ _AX = top; \ _CX = left; \ z_super_roll_put_16x16_mono_raw(patnum); -void z_pascal near z_super_roll_put_16x16_mono_raw(int patnum); +void pascal near z_super_roll_put_16x16_mono_raw(int patnum); diff --git a/th05/main/boss/render.cpp b/th05/main/boss/render.cpp index 63d9a8d9..b27563ba 100644 --- a/th05/main/boss/render.cpp +++ b/th05/main/boss/render.cpp @@ -5,6 +5,7 @@ #include "platform.h" #include "pc98.h" +#include "decomp.hpp" #include "master.hpp" #include "th01/math/area.hpp" #include "th01/math/subpixel.hpp" @@ -13,6 +14,8 @@ #include "th04/math/randring.h" #include "th04/main/drawp.hpp" #include "th04/main/playfld.hpp" +#include "th05/sprites/main_pat.h" +#include "th05/formats/super.h" #include "th05/main/boss/boss.hpp" /// Structures @@ -58,6 +61,60 @@ static const int PARTICLES_UNINITIALIZED = (-1 & 0xFF); extern unsigned char shinki_bg_linesets_zoomed_out; extern int shinki_bg_type_a_particles_alive; +void near shinki_bg_particles_render(void) +{ + _ES = SEG_PLANE_B; + boss_particle_t near *particle = boss_particles; + int patnum; + screen_x_t left_; + int i = 0; + while(i < BOSS_PARTICLE_COUNT) { + if(particle->pos.x.v != Subpixel::None()) { + particle->pos.x.v += particle->velocity.x.v; + particle->pos.y.v += particle->velocity.y.v; + if(particle->patnum == 0) { + patnum = (particle->age / 8); + if(patnum >= PARTICLE_CELS) { + patnum = (PARTICLE_CELS - 1); + } + patnum += PAT_PARTICLE; + } else { + patnum = particle->patnum; + } + + #define left static_cast(_CX) + #define top static_cast(_AX) + + // Lol, is this only not directly assigned to _CX because ZUN was + // scared that the _AX assignment might overwrite _CX? + left_ = ( + particle->pos.x.to_pixel() + PLAYFIELD_LEFT - (PARTICLE_W / 2) + ); + top = ( + particle->pos.y.to_pixel() + PLAYFIELD_TOP - (PARTICLE_H / 2) + ); + left = left_; + if(!( + (left > (PLAYFIELD_LEFT - PARTICLE_W)) && + (left < PLAYFIELD_RIGHT) && + (top > keep_0(PLAYFIELD_TOP - PARTICLE_H)) && + (top < PLAYFIELD_BOTTOM) + )) { + particle->pos = particle->origin; + particle->age = 0; + } else { + z_super_roll_put_16x16_mono(left, top, patnum); + particle->age++; + } + + #undef top + #undef left + } + i++; + particle++; + } +} + void near shinki_bg_type_a_update_part1(void) { boss_particle_t near *particle; diff --git a/th05_main.asm b/th05_main.asm index e7261e45..f313b28e 100644 --- a/th05_main.asm +++ b/th05_main.asm @@ -3532,96 +3532,7 @@ loc_D322: retn yumeko_bg_render endp - -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_D327 proc near - -@@i = word ptr -4 -@@left = word ptr -2 - - enter 4, 0 - push si - push di - mov ax, GRAM_400 - mov es, ax - mov si, offset _boss_particles - mov [bp+@@i], 0 - jmp short loc_D3BA -; --------------------------------------------------------------------------- - -loc_D33C: - cmp [si+boss_particle_t.BP_pos.x], SUBPIXEL_NONE - jz short loc_D3B4 - mov ax, [si+boss_particle_t.BP_velocity.x] - add [si+boss_particle_t.BP_pos.x], ax - mov ax, [si+boss_particle_t.BP_velocity.y] - add [si+boss_particle_t.BP_pos.y], ax - cmp [si+boss_particle_t.BP_patnum], 0 - jnz short loc_D36C - mov ax, [si+boss_particle_t.BP_age] - mov bx, 8 - cwd - idiv bx - mov di, ax - cmp di, PARTICLE_CELS - jl short loc_D366 - mov di, (PARTICLE_CELS - 1) - -loc_D366: - add di, PAT_PARTICLE - jmp short loc_D373 -; --------------------------------------------------------------------------- - -loc_D36C: - mov al, [si+boss_particle_t.BP_patnum] - mov ah, 0 - mov di, ax - -loc_D373: - mov ax, [si+boss_particle_t.BP_pos.x] - sar ax, 4 - add ax, (PLAYFIELD_LEFT - (PARTICLE_W / 2)) - mov [bp+@@left], ax - mov ax, [si+boss_particle_t.BP_pos.y] - sar ax, 4 - add ax, (PLAYFIELD_TOP - (PARTICLE_H / 2)) - mov cx, [bp+@@left] - cmp cx, (PLAYFIELD_LEFT - PARTICLE_W) - jle short loc_D39F - cmp cx, PLAYFIELD_RIGHT - jge short loc_D39F - cmp ax, (PLAYFIELD_TOP - PARTICLE_H) - jle short loc_D39F - cmp ax, PLAYFIELD_BOTTOM - jl short loc_D3AD - -loc_D39F: - mov eax, dword ptr [si+boss_particle_t.BP_origin] - mov dword ptr [si+boss_particle_t.BP_pos], eax - mov [si+boss_particle_t.BP_age], 0 - jmp short loc_D3B4 -; --------------------------------------------------------------------------- - -loc_D3AD: - call z_super_roll_put_16x16_mono_raw pascal, di - inc [si+boss_particle_t.BP_age] - -loc_D3B4: - inc [bp+@@i] - add si, size boss_particle_t - -loc_D3BA: - cmp [bp+@@i], BOSS_PARTICLE_COUNT - jl loc_D33C - pop di - pop si - leave - retn -sub_D327 endp - + _shinki_bg_particles_render procdesc c near _shinki_bg_type_a_update_part1 procdesc c near GRCG_LINESET_LINE_PUT procdesc pascal near \ set:near ptr, i:word @@ -3677,7 +3588,7 @@ loc_D630: call _grcg_setmode_rmw_seg1 mov ah, GC_BRG call _grcg_setcolor_direct_seg1_raw - call sub_D327 + call _shinki_bg_particles_render call grcg_lineset_line_put pascal, offset lineset0, 18 call grcg_lineset_line_put pascal, offset lineset0, 12 call grcg_lineset_line_put pascal, offset lineset1, 18 @@ -3921,7 +3832,7 @@ loc_D82E: call _grcg_setmode_rmw_seg1 mov ah, GC_BRG call _grcg_setcolor_direct_seg1_raw - call sub_D327 + call _shinki_bg_particles_render call grcg_lineset_line_put pascal, offset lineset0, 18 call grcg_lineset_line_put pascal, offset lineset0, 12 call grcg_lineset_line_put pascal, offset lineset1, 18 @@ -4130,7 +4041,7 @@ loc_D9C6: call _grcg_setmode_rmw_seg1 mov ah, GC_BRG call _grcg_setcolor_direct_seg1_raw - call sub_D327 + call _shinki_bg_particles_render call grcg_lineset_line_put pascal, offset lineset0, 18 call grcg_lineset_line_put pascal, offset lineset0, 12 call grcg_lineset_line_put pascal, offset lineset1, 18 @@ -4291,7 +4202,7 @@ loc_DB0A: call sub_E950 call sub_DA25 call grcg_setcolor pascal, (GC_RMW shl 16) + 6 - call sub_D327 + call _shinki_bg_particles_render GRCG_OFF_CLOBBERING dx leave retn