mirror of
https://github.com/pret/pmd-sky.git
synced 2026-09-26 12:17:30 -05:00
Replace the Window placeholder with its real layout
struct Window was landed two commits ago as mostly filler: the fields those
functions happened to touch, and padding to reach the 0xE0 stride GetWindow
indexes by. This replaces it with the full 0xE0 layout, supplied by the project
maintainer, together with the four types it is built from -- WindowTemplate,
WindowBlock, WindowTile and CursorParams, plus Point.
Four things the layout has to satisfy, and does:
sizeof is 0xE0, the stride GetWindow multiplies by.
is_active is an s8 at 0xB6, which is where DeleteWindow does ldrnesb.
WindowTemplate.width is at 0x06, where the previous partial struct, inherited
from overlay_31_02382820.h, already had width.
x, y, width and height at 0x04 through 0x07 account for GetWindowRectangle
exactly: it writes y*8, y*8 + height*8, x*8 and x*8 + width*8, so its output
is top, bottom, left, right. That function is rewritten against the named
fields rather than shifting anonymous bytes.
Three choices worth noting for review. The struct keeps its tag, so both
struct Window and Window resolve and no existing use changes. GetWindowContents
still returns void * rather than the u32 the field is typed as, because all 22
of its callers assign the result to a pointer; the cast is a no-op and avoids 22
integer-to-pointer conversions. And width moving inside the template means
overlay_31_02382820.c reads window2->template.width, the one source change the
layout forces.
The field names here are the maintainer's, not derived in this commit. The
offsets and widths are checkable against the asm; the names are not, and should
be read as supplied rather than proven.
No comments are added to any pmd-sky file.
Authored by Claude (Opus 5) under human direction, from a struct definition
supplied by the maintainer. Confirmed by a matching build with
overlay_31_02382820.o rebuilt: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,19 +20,91 @@ typedef struct {
|
||||
|
||||
#include "util.h"
|
||||
|
||||
struct Window {
|
||||
u8 PAD[4];
|
||||
u8 field_0x4;
|
||||
u8 field_0x5;
|
||||
u8 width;
|
||||
u8 field_0x7;
|
||||
u8 field_0x8;
|
||||
u8 field_0x9[3];
|
||||
void *field_0xC;
|
||||
u8 field_0x10[0xD0];
|
||||
};
|
||||
typedef struct {
|
||||
s32 x;
|
||||
s32 y;
|
||||
} Point;
|
||||
|
||||
extern struct Window WINDOW_LIST[];
|
||||
typedef struct {
|
||||
u32 state;
|
||||
u8 is_dirty;
|
||||
u8 padding_05[3];
|
||||
Point base_pos;
|
||||
Point alt_pos;
|
||||
u8 unk18;
|
||||
u8 unk19;
|
||||
u16 padding_1A;
|
||||
Point extra_pos;
|
||||
} CursorParams;
|
||||
|
||||
typedef struct {
|
||||
u32 unk00;
|
||||
u8 x;
|
||||
u8 y;
|
||||
u8 width;
|
||||
u8 height;
|
||||
volatile u8 bg_id;
|
||||
s8 unk09;
|
||||
u16 unk0A;
|
||||
u32 unk0C;
|
||||
} WindowTemplate;
|
||||
|
||||
typedef struct {
|
||||
u16 unk00;
|
||||
u16 unk02;
|
||||
u16 unk04;
|
||||
u16 unk06;
|
||||
u8 padding_08[0x0C];
|
||||
u16 unk14;
|
||||
u16 unk16;
|
||||
u16 unk18;
|
||||
u16 unk1A;
|
||||
u16 unk1C;
|
||||
u16 padding_1E;
|
||||
u32 unk20;
|
||||
u32 unk24;
|
||||
u16 padding_28;
|
||||
u16 unk2A;
|
||||
u8 unk2C;
|
||||
u8 unk2D;
|
||||
u8 unk2E;
|
||||
u8 unk2F;
|
||||
u8 padding_30[0x0C];
|
||||
u8 unk3C;
|
||||
u8 padding_3D;
|
||||
u8 unk3E;
|
||||
u8 padding_3F;
|
||||
} WindowBlock;
|
||||
|
||||
typedef struct {
|
||||
u8 pixels[8][8];
|
||||
} WindowTile;
|
||||
|
||||
typedef struct Window {
|
||||
WindowTemplate template;
|
||||
s8 id;
|
||||
u8 unk11;
|
||||
u16 base_tile;
|
||||
WindowTile *pixel_buffer;
|
||||
u8 *vram_base;
|
||||
u32 transfer_length;
|
||||
u32 row_stride;
|
||||
WindowTile *active_transfer_src;
|
||||
u8 *active_vram_dest;
|
||||
u32 active_transfer_len;
|
||||
u16 unk30;
|
||||
u16 unk32;
|
||||
WindowBlock render_elem_1;
|
||||
WindowBlock render_elem_2;
|
||||
u8 unkB4;
|
||||
s8 next_window_id;
|
||||
s8 is_active;
|
||||
u8 unkB7;
|
||||
u32 unkB8;
|
||||
CursorParams cursor_params;
|
||||
} Window;
|
||||
|
||||
extern Window WINDOW_LIST[20];
|
||||
|
||||
struct Window *GetWindow(s32 window_id);
|
||||
void *GetWindowContents(s32 window_id);
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
void GetWindowRectangle(s32 window_id, struct unk_02028284* out)
|
||||
{
|
||||
struct Window *w = &WINDOW_LIST[window_id];
|
||||
s32 top = w->field_0x5 << 3;
|
||||
WindowTemplate *tmpl = &WINDOW_LIST[window_id].template;
|
||||
s32 top = tmpl->y << 3;
|
||||
s32 left;
|
||||
|
||||
out->field_0x0 = top;
|
||||
out->field_0x4 = top + (w->field_0x7 << 3);
|
||||
left = w->field_0x4 << 3;
|
||||
out->field_0x4 = top + (tmpl->height << 3);
|
||||
left = tmpl->x << 3;
|
||||
out->field_0x8 = left;
|
||||
out->field_0xC = left + (w->width << 3);
|
||||
out->field_0xC = left + (tmpl->width << 3);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
void* GetWindowContents(s32 window_id)
|
||||
{
|
||||
struct Window *w = &WINDOW_LIST[window_id];
|
||||
WindowTemplate *tmpl = &WINDOW_LIST[window_id].template;
|
||||
|
||||
return w->field_0xC;
|
||||
return (void *)tmpl->unk0C;
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ void DungeonMenuSwitch(s32 window_id)
|
||||
PreprocessString(str_buff, 0x400, DUNGEON_MENU_SWITCH_STR1, 0, &str_values);
|
||||
struct Window* window2 = GetWindow(window_id);
|
||||
s32 text_width = sub_020265A8(str_buff);
|
||||
s32 x_offset = (window2->width * 8 - text_width) / 2;
|
||||
s32 x_offset = (window2->template.width * 8 - text_width) / 2;
|
||||
DrawTextInWindow(window_id, x_offset, 2, str_buff);
|
||||
UpdateWindow(window_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user