From b1ec7fce284b6bdf37b91fc40e96d218186c4dba Mon Sep 17 00:00:00 2001 From: nmlgc Date: Mon, 27 Dec 2021 22:31:23 +0100 Subject: [PATCH] [Decompilation] [th01] Sariel: Spawn ray rendering So if Sariel's version of this function is worse than Konngara's, can we conclude that Sariel's code was written first? (Edit, after having decompiled more of the fight: Sariel's functions are predominantly `near` in contrast to Konngara's 100% `far` ones, which is just as much of an indicator for the opposite.) Part of P0174, funded by Ember2528. --- th01/main/boss/b20j.cpp | 33 ++++----------- th01/main/boss/b20m.cpp | 22 ++++++++++ th01/main/spawnray.hpp | 29 +++++++++++++ th01_reiiden.asm | 93 ++++++++++------------------------------- 4 files changed, 81 insertions(+), 96 deletions(-) create mode 100644 th01/main/spawnray.hpp diff --git a/th01/main/boss/b20j.cpp b/th01/main/boss/b20j.cpp index 26713c98..80c345c4 100644 --- a/th01/main/boss/b20j.cpp +++ b/th01/main/boss/b20j.cpp @@ -30,6 +30,7 @@ extern "C" { #include "th01/formats/stagedat.hpp" #include "th01/sprites/pellet.h" #include "th01/sprites/shape8x8.hpp" +#include "th01/main/spawnray.hpp" #include "th01/main/vars.hpp" #include "th01/main/boss/entity_a.hpp" #include "th01/main/stage/palette.hpp" @@ -291,7 +292,8 @@ template struct Snakes { #define select_for_rank konngara_select_for_rank #include "th01/main/select_r.cpp" -void pellet_spawnray_unput_and_put( +// Almost identical to Sariel's version. This one is better. +static void spawnray_unput_and_put( screen_x_t origin_x, vram_y_t origin_y, screen_x_t target_x, vram_y_t target_y, int col @@ -299,27 +301,10 @@ void pellet_spawnray_unput_and_put( { static screen_x_t target_prev_x = -PIXEL_NONE; static vram_y_t target_prev_y = -PIXEL_NONE; - if(col == 99) { - target_prev_x = -PIXEL_NONE; - target_prev_y = -PIXEL_NONE; - // Umm, shouldn't we unblit in this case? - return; - } - if( - (target_prev_x != -PIXEL_NONE) && (target_prev_y != -PIXEL_NONE) && - (target_prev_x >= 0) && (target_prev_x < RES_X) && - (target_prev_y >= 0) && (target_prev_y < RES_Y) - ) { - graph_r_line_unput(origin_x, origin_y, target_prev_x, target_prev_y); - } - if( - (target_x >= 0) && (target_x < RES_X) && - (target_y >= 0) && (target_y < RES_Y) - ) { - graph_r_line(origin_x, origin_y, target_x, target_y, col); - } - target_prev_x = target_x; - target_prev_y = target_y; + spawnray_unput_and_put_func( + target_prev_x, target_prev_y, + origin_x, origin_y, target_x, target_y, col, false + ); } // Siddhaṃ seed syllables @@ -1032,9 +1017,7 @@ void pattern_four_homing_snakes(void) inline void swordray_unput_put_and_move( screen_x_t& end_x, screen_x_t& end_y, screen_x_t delta_x, screen_y_t delta_y ) { - pellet_spawnray_unput_and_put( - SWORD_CENTER_X, SWORD_CENTER_Y, end_x, end_y, 6 - ); + spawnray_unput_and_put(SWORD_CENTER_X, SWORD_CENTER_Y, end_x, end_y, 6); // Gimme those original instructions! if(delta_x < 0) { end_x -= -delta_x; } else { end_x += delta_x; } if(delta_y < 0) { end_y -= -delta_y; } else { end_y += delta_y; } diff --git a/th01/main/boss/b20m.cpp b/th01/main/boss/b20m.cpp index fcaba637..b9d8572d 100644 --- a/th01/main/boss/b20m.cpp +++ b/th01/main/boss/b20m.cpp @@ -23,6 +23,7 @@ extern "C" { #include "th01/formats/ptn.hpp" #include "th01/formats/stagedat.hpp" #include "th01/sprites/pellet.h" +#include "th01/main/spawnray.hpp" #include "th01/main/vars.hpp" #include "th01/main/boss/entity_a.hpp" } @@ -226,3 +227,24 @@ void sariel_free(void) sariel_grc_free(); ptn_free(PTN_SLOT_BG_ENT); } + +// Almost identical to Konngara's version. This one is worse. +void pascal near spawnray_unput_and_put( + screen_x_t origin_x, vram_y_t origin_y, + screen_x_t target_x, vram_y_t target_y, + int col +) +{ + #define target_prev_x spawnray_target_prev_x + #define target_prev_y spawnray_target_prev_y + + extern screen_x_t target_prev_x; + extern vram_y_t target_prev_y; + spawnray_unput_and_put_func( + target_prev_x, target_prev_y, + origin_x, origin_y, target_x, target_y, col, true + ); + + #undef target_prev_x + #undef target_prev_y +} diff --git a/th01/main/spawnray.hpp b/th01/main/spawnray.hpp new file mode 100644 index 00000000..5ed9d1fa --- /dev/null +++ b/th01/main/spawnray.hpp @@ -0,0 +1,29 @@ +#define spawnray_unput_and_put_func( \ + target_prev_x, target_prev_y, \ + origin_x, origin_y, target_x, target_y, col, unblit_always \ +) { \ + if(col == 99) { \ + target_prev_x = -PIXEL_NONE; \ + target_prev_y = -PIXEL_NONE; \ + /* Umm, shouldn't we unblit in this case? */ \ + goto spawnray_ret; \ + } \ + if( \ + (unblit_always || \ + (target_prev_x != -PIXEL_NONE) && (target_prev_y != -PIXEL_NONE) \ + ) && \ + (target_prev_x >= 0) && (target_prev_x < RES_X) && \ + (target_prev_y >= 0) && (target_prev_y < RES_Y) \ + ) { \ + graph_r_line_unput(origin_x, origin_y, target_prev_x, target_prev_y); \ + } \ + if( \ + (target_x >= 0) && (target_x < RES_X) && \ + (target_y >= 0) && (target_y < RES_Y) \ + ) { \ + graph_r_line(origin_x, origin_y, target_x, target_y, col); \ + } \ + target_prev_x = target_x; \ + target_prev_y = target_y; \ +spawnray_ret: \ +} diff --git a/th01_reiiden.asm b/th01_reiiden.asm index b98dbdeb..5c77a560 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -22432,6 +22432,8 @@ main_36_TEXT segment byte public 'CODE' use16 @wand_bg_snap$qv procdesc near @wand_bg_put$qv procdesc near extern @sariel_free$qv:proc + @SPAWNRAY_UNPUT_AND_PUT$QIIIII procdesc pascal near \ + origin:Point, target_x:word, target_y:word, col:word main_36_TEXT ends main_36__TEXT segment byte public 'CODE' use16 @@ -22445,65 +22447,6 @@ sariel_shield equ sariel_dress equ sariel_wand equ -; =============== S U B R O U T I N E ======================================= - -; Attributes: bp-based frame - -sub_28948 proc near - -@@col = word ptr 4 -@@bottom = word ptr 6 -@@right = word ptr 8 -@@top = word ptr 0Ah -@@left = word ptr 0Ch - - push bp - mov bp, sp - push si - push di - mov si, [bp+@@right] - mov di, [bp+@@bottom] - cmp [bp+@@col], 99 - jnz short loc_28967 - mov point_35DBB.x, 999 - mov point_35DBB.y, 999 - jmp short loc_289CA -; --------------------------------------------------------------------------- - -loc_28967: - cmp point_35DBB.x, 0 - jl short loc_2899B - cmp point_35DBB.x, RES_X - jge short loc_2899B - cmp point_35DBB.y, 0 - jl short loc_2899B - cmp point_35DBB.y, RES_Y - jge short loc_2899B - call _graph_r_line_unput c, [bp+@@left], [bp+@@top], point_35DBB.x, point_35DBB.y - -loc_2899B: - or si, si - jl short loc_289C2 - cmp si, RES_X - jge short loc_289C2 - or di, di - jl short loc_289C2 - cmp di, RES_Y - jge short loc_289C2 - call _graph_r_line c, [bp+@@left], [bp+@@top], si, di, [bp+@@col] - -loc_289C2: - mov point_35DBB.x, si - mov point_35DBB.y, di - -loc_289CA: - pop di - pop si - pop bp - retn 0Ah -sub_28948 endp - - ; =============== S U B R O U T I N E ======================================= ; Attributes: bp-based frame @@ -25550,7 +25493,10 @@ sub_2A69B proc near mov bp, sp cmp _boss_phase_frame, 5 jge short loc_2A6B0 - call sub_28948 pascal, large 0, large 0, 99 + push large 0 + push large 0 + push 99 + call @spawnray_unput_and_put$qiiiii loc_2A6B0: cmp _boss_phase_frame, 50 @@ -25661,7 +25607,7 @@ loc_2A85B: jge short loc_2A886 loc_2A863: - call sub_28948 pascal, ((RES_X / 2) shl 16) or 120, point_3B037.x, point_3B037.y, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 120, point_3B037.x, point_3B037.y, 7 mov ax, x_3B03D add point_3B037.x, ax mov ax, y_3B03B @@ -25789,7 +25735,10 @@ sub_2A949 proc near push di cmp _boss_phase_frame, 5 jge short loc_2A960 - call sub_28948 pascal, large 0, large 0, 99 + push large 0 + push large 0 + push 99 + call @spawnray_unput_and_put$qiiiii loc_2A960: cmp _boss_phase_frame, 150 @@ -25830,7 +25779,7 @@ loc_2A99E: sar eax, 8 add ax, 160 mov di, ax - call sub_28948 pascal, ((RES_X / 2) shl 16) or 160, si, ax, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 160, si, ax, 7 mov al, byte_3B042 add angle_3B041, al inc byte_3B042 @@ -25848,7 +25797,7 @@ loc_2AA13: jnz short loc_2AA36 mov si, 999 mov di, 999 - call sub_28948 pascal, ((RES_X / 2) shl 16) or 160, si, di, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 160, si, di, 7 mov angle_3B041, 0 jmp loc_2ABD8 ; --------------------------------------------------------------------------- @@ -26052,7 +26001,7 @@ loc_2AC27: push ax ; left call _grc_put_8 add sp, 0Ah - call sub_28948 pascal, ((RES_X / 2) shl 16) or 120, point_3B043.x, point_3B043.y, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 120, point_3B043.x, point_3B043.y, 7 loc_2AC8A: mov ax, _boss_phase_frame @@ -26088,7 +26037,7 @@ loc_2AC8A: push ax push point_3B043.y push 7 - call sub_28948 + call @spawnray_unput_and_put$qiiiii cmp grc_image_3B04B, 5 jge short loc_2ACFB mov ax, grc_image_3B04B @@ -26430,7 +26379,7 @@ loc_2B01A: push ax ; left call _grc_put_8 add sp, 12h - call sub_28948 pascal, ((RES_X / 2) shl 16) or 120, x_3B04D, y_3B04F, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 120, x_3B04D, y_3B04F, 7 loc_2B07B: mov ax, _boss_phase_frame @@ -26465,7 +26414,7 @@ loc_2B07B: push ax push y_3B04F push 7 - call sub_28948 + call @spawnray_unput_and_put$qiiiii cmp grc_image_3B051, 5 jge short loc_2B0E9 mov ax, grc_image_3B051 @@ -27243,7 +27192,7 @@ loc_2B883: push ax push point_3B330.x call _egc_copy_rect_1_to_0_16 - call sub_28948 pascal, ((RES_X / 2) shl 16) or 185, point_3B330.x, point_3B330.y, 7 + call @spawnray_unput_and_put$qiiiii pascal, ((RES_X / 2) shl 16) or 185, point_3B330.x, point_3B330.y, 7 push 7 ; col push grc_image_3B334 ; image push GRC_SLOT_BOSS_1 ; slot @@ -27278,7 +27227,7 @@ loc_2B8E3: push ax push point_3B330.y push 7 - call sub_28948 + call @spawnray_unput_and_put$qiiiii push 7 ; col push grc_image_3B334 ; image push GRC_SLOT_BOSS_1 ; slot @@ -29911,7 +29860,9 @@ _BG_IMAGES label dword dd aBoss6_a2_grp ; "BOSS6_A2.GRP" dd aBoss6_a3_grp ; "BOSS6_A3.GRP" dd aBoss6_a4_grp ; "BOSS6_A4.GRP" -point_35DBB Point <999, 999> +public _spawnray_target_prev_x, _spawnray_target_prev_y +_spawnray_target_prev_x dw 999 +_spawnray_target_prev_y dw 999 dd 0 dd 0 dd 0