[Decompilation] [th01] Point items: Collection and drop callbacks

Part of P0159, funded by Yanga.
This commit is contained in:
nmlgc 2021-09-22 12:55:12 +02:00
parent e9950e2399
commit ef5225448c
3 changed files with 46 additions and 108 deletions

View File

@ -7,6 +7,7 @@ extern "C" {
#include "th01/resident.hpp"
#include "th01/v_colors.hpp"
#include "th01/math/clamp.hpp"
#include "th01/math/digit.hpp"
#include "th01/hardware/egc.h"
#include "th01/hardware/graph.h"
#include "th01/main/playfld.hpp"
@ -18,6 +19,7 @@ extern "C" {
#include "th01/main/player/player.hpp"
#include "th01/sprites/main_ptn.h"
}
#include "th01/core/str_val.hpp"
#include "th01/main/hud/hud.hpp"
#include "th01/main/shape.hpp"
#include "th01/main/stage/item.hpp"
@ -30,12 +32,14 @@ static const pixel_t ITEM_W = PTN_W;
static const pixel_t ITEM_H = PTN_H;
static const unsigned int POINT_CAP = 65530;
static const unsigned int POINT_CAP_DIGITS = digit_count(POINT_CAP);
// Assumes that [BOMB_COLLECT_1] and [BOMB_COLLECT_CAP] have the same length
// in bytes!
static const pixel_t BOMB_COLLECT_1_W = shiftjis_w(BOMB_COLLECT_1);
static const pixel_t BOMB_COLLECT_2_W = shiftjis_w(BOMB_COLLECT_2);
static const pixel_t POINT_COLLECT_W = (POINT_CAP_DIGITS * GLYPH_HALF_W);
// TODO: Remove, once data can be emitted here
#undef BOMB_COLLECT_1
@ -131,6 +135,10 @@ typedef void drop_func_t(void);
item.top = clamp_max_2_ge(item.top, (PLAYFIELD_BOTTOM - ITEM_H)); \
}
inline screen_x_t point_collect_left(item_t* slots, const int i) {
return clamp_max_2(slots[i].left, (PLAYFIELD_RIGHT - POINT_COLLECT_W));
}
inline screen_x_t bomb_collect_2_left(item_t* slots, const int i) {
// Line 2 is centered relative to line 1.
enum {
@ -373,3 +381,30 @@ void items_point_reset(void)
items_point[i].flag = IF_FREE;
}
}
void point_drop(void)
{
resident->point_value = 0;
}
void point_collect_update_and_render(int slot)
{
#define item items_point[slot]
#define left point_collect_left(items_point, slot)
char str[POINT_CAP_DIGITS + 1];
egc_copy_rect_1_to_0_16_word_w(left, item.top, POINT_COLLECT_W, GLYPH_H);
item.top += item.velocity_y;
item.flag_state.collect_time--;
if(item.flag_state.collect_time == 0) {
item.flag = IF_FREE;
return;
}
str_right_aligned_from_uint16(str, resident->point_value, POINT_CAP_DIGITS);
graph_putsa_fx(left, item.top, V_WHITE, str);
#undef left
#undef item
}

7
th01/math/digit.hpp Normal file
View File

@ -0,0 +1,7 @@
#define digit_count(num) ( \
(num >= 10000) ? 5 : \
(num >= 1000) ? 4 : \
(num >= 100) ? 3 : \
(num >= 10) ? 2 \
: 1 \
)

View File

@ -6051,6 +6051,8 @@ main_24_TEXT segment byte public 'CODE' use16
extern @point_hittest$qi:proc
extern @items_point_render$qv:proc
extern @items_point_reset$qv:proc
extern @point_drop$qv:proc
extern @point_collect_update_and_render$qi:proc
main_24_TEXT ends
main_24__TEXT segment byte public 'CODE' use16
@ -6060,112 +6062,6 @@ main_24__TEXT segment byte public 'CODE' use16
IF_FREE = 0
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_18456 proc far
push bp
mov bp, sp
les bx, _resident
mov es:[bx+reiidenconfig_t.p_value], 0
pop bp
retf
sub_18456 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_18465 proc far
@@str = byte ptr -6
@@slot = word ptr 6
enter 6, 0
push si
mov si, [bp+@@slot]
push (16 shl 16) or 48
mov bx, si
imul bx, size item_t
push _items_point.ITEM_top[bx]
mov bx, si
imul bx, size item_t
cmp _items_point.ITEM_left[bx], (PLAYFIELD_RIGHT - (5 * GLYPH_HALF_W))
jle short loc_1848E
mov ax, (PLAYFIELD_RIGHT - (5 * GLYPH_HALF_W))
jmp short loc_18497
; ---------------------------------------------------------------------------
loc_1848E:
mov bx, si
imul bx, size item_t
mov ax, _items_point.ITEM_left[bx]
loc_18497:
push ax
call _egc_copy_rect_1_to_0_16
add sp, 8
mov bx, si
imul bx, size item_t
mov ax, _items_point.ITEM_velocity_y[bx]
mov bx, si
imul bx, size item_t
add _items_point.ITEM_top[bx], ax
mov bx, si
imul bx, size item_t
dec _items_point.ITEM_collect_time[bx]
mov bx, si
imul bx, size item_t
cmp _items_point.ITEM_collect_time[bx], 0
jnz short loc_184D3
mov bx, si
imul bx, size item_t
mov _items_point.ITEM_flag[bx], IF_FREE
jmp short loc_1851B
; ---------------------------------------------------------------------------
loc_184D3:
push ss
lea ax, [bp+@@str]
push ax
les bx, _resident
push es:[bx+reiidenconfig_t.p_value]
push 5
call @str_right_aligned_from_uint16$qncuiui
push ss
lea ax, [bp+@@str]
push ax
push 7
mov bx, si
imul bx, size item_t
push _items_point.ITEM_top[bx]
mov bx, si
imul bx, size item_t
cmp _items_point.ITEM_left[bx], (PLAYFIELD_RIGHT - (5 * GLYPH_HALF_W))
jle short loc_18509
mov ax, (PLAYFIELD_RIGHT - (5 * GLYPH_HALF_W))
jmp short loc_18512
; ---------------------------------------------------------------------------
loc_18509:
mov bx, si
imul bx, size item_t
mov ax, _items_point.ITEM_left[bx]
loc_18512:
push ax
call _graph_putsa_fx
add sp, 0Ah
loc_1851B:
pop si
leave
retf
sub_18465 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
@ -6184,9 +6080,9 @@ loc_18526:
cmp _items_point.ITEM_flag[bx], IF_FREE
jz short loc_18580
push seg main_24
push offset sub_18456
push offset @point_drop$qv
push seg main_24
push offset sub_18465
push offset @point_collect_update_and_render$qi
push PTN_ITEM_POINT
push ds
mov ax, si