decomp bmlib-hblank

This commit is contained in:
MokhaLeee 2024-07-08 19:03:03 +08:00
parent a42422f453
commit e2c7128dbd
10 changed files with 235 additions and 401 deletions

View File

@ -697,6 +697,13 @@ void MapFloodCore(void)
case 4:
goto break_internal_loop;
case 5:
MapFloodCoreStep(3, 0, -1);
MapFloodCoreStep(2, 0, 1);
MapFloodCoreStep(0, -1, 0);
MapFloodCoreStep(1, 1, 0);
break;
}
gMovMapFillState.dst->connexion = 4;

View File

@ -1,378 +0,0 @@
.INCLUDE "macro.inc"
.SYNTAX UNIFIED
THUMB_FUNC_START sub_8014CA4
sub_8014CA4: @ 0x08014CA4
push {r4, r5, r6, lr}
adds r4, r0, #0
adds r0, r1, #0
adds r5, r2, #0
adds r6, r3, #0
lsls r4, r4, #0xc
adds r1, r4, #0
bl DivArm
adds r1, r5, #0
adds r2, r6, #0
bl sub_800A42C
pop {r4, r5, r6}
pop {r1}
bx r1
THUMB_FUNC_END sub_8014CA4
THUMB_FUNC_START sub_8014CC4
sub_8014CC4: @ 0x08014CC4
push {r4, r5, r6, lr}
ldr r0, _08014D24 @ 0x04000006
ldrh r0, [r0]
adds r0, #1
lsls r0, r0, #0x10
lsrs r4, r0, #0x10
cmp r4, #0xe4
bne _08014CD6
movs r4, #0
_08014CD6:
cmp r4, #0x9f
bhi _08014D38
ldr r5, _08014D28 @ gUnknown_03004990
ldr r2, [r5]
ldr r1, _08014D2C @ 0x0000079D
adds r0, r2, r1
ldrb r0, [r0]
lsls r0, r0, #0x18
asrs r0, r0, #0x18
cmp r0, #0
beq _08014D9E
ldr r3, _08014D30 @ 0x0000079C
adds r0, r2, r3
ldrb r1, [r0]
lsls r0, r1, #4
subs r0, r0, r1
lsls r0, r0, #6
adds r0, r2, r0
movs r3, #0
adds r6, r5, #0
ldr r5, _08014D34 @ 0x0000078C
lsls r1, r4, #1
adds r2, r0, r1
movs r4, #0xa0
lsls r4, r4, #1
_08014D08:
ldr r0, [r6]
lsls r1, r3, #2
adds r0, r0, r5
adds r0, r0, r1
ldr r1, [r0]
cmp r1, #0
beq _08014D1A
ldrh r0, [r2]
strh r0, [r1]
_08014D1A:
adds r2, r2, r4
adds r3, #1
cmp r3, #2
ble _08014D08
b _08014D9E
.align 2, 0
_08014D24: .4byte 0x04000006
_08014D28: .4byte gUnknown_03004990
_08014D2C: .4byte 0x0000079D
_08014D30: .4byte 0x0000079C
_08014D34: .4byte 0x0000078C
_08014D38:
cmp r4, #0xa0
bne _08014D9E
ldr r4, _08014D84 @ gUnknown_03004990
ldr r1, [r4]
ldr r2, _08014D88 @ 0x0000079E
adds r0, r1, r2
movs r2, #0
ldrsb r2, [r0, r2]
cmp r2, #0
beq _08014D98
ldr r3, _08014D8C @ 0x0000079D
adds r1, r1, r3
movs r0, #1
strb r0, [r1]
ldr r0, [r4]
ldr r2, _08014D90 @ 0x0000079B
adds r1, r0, r2
ldrb r1, [r1]
subs r3, #1
adds r0, r0, r3
strb r1, [r0]
movs r3, #0
adds r6, r4, #0
ldr r5, _08014D94 @ 0x0000078C
movs r4, #0xf0
lsls r4, r4, #3
_08014D6C:
ldr r0, [r6]
lsls r2, r3, #2
adds r1, r0, r5
adds r1, r1, r2
adds r0, r0, r4
adds r0, r0, r2
ldr r0, [r0]
str r0, [r1]
adds r3, #1
cmp r3, #2
ble _08014D6C
b _08014D9E
.align 2, 0
_08014D84: .4byte gUnknown_03004990
_08014D88: .4byte 0x0000079E
_08014D8C: .4byte 0x0000079D
_08014D90: .4byte 0x0000079B
_08014D94: .4byte 0x0000078C
_08014D98:
ldr r3, _08014DA4 @ 0x0000079D
adds r0, r1, r3
strb r2, [r0]
_08014D9E:
pop {r4, r5, r6}
pop {r0}
bx r0
.align 2, 0
_08014DA4: .4byte 0x0000079D
THUMB_FUNC_END sub_8014CC4
THUMB_FUNC_START sub_8014DA8
sub_8014DA8: @ 0x08014DA8
push {r4, r5, r6, r7, lr}
mov r7, r9
mov r6, r8
push {r6, r7}
ldr r1, _08014E24 @ gUnknown_03004990
str r0, [r1]
movs r3, #0
adds r6, r1, #0
adds r5, r6, #0
movs r0, #0xf3
lsls r0, r0, #3
mov r8, r0
movs r4, #0
ldr r1, _08014E28 @ 0x0000078C
mov ip, r1
movs r2, #0xf0
lsls r2, r2, #3
mov r9, r2
_08014DCC:
ldr r0, [r5]
add r0, r8
adds r0, r0, r3
strb r4, [r0]
ldr r0, [r5]
lsls r2, r3, #2
mov r7, ip
adds r1, r0, r7
adds r1, r1, r2
add r0, r9
adds r0, r0, r2
str r4, [r0]
str r4, [r1]
adds r3, #1
cmp r3, #2
ble _08014DCC
ldr r0, [r6]
ldr r1, _08014E2C @ 0x0000079B
adds r2, r0, r1
movs r1, #0
strb r1, [r2]
ldr r2, _08014E30 @ 0x0000079C
adds r0, r0, r2
strb r1, [r0]
ldr r0, [r6]
ldr r7, _08014E34 @ 0x0000079D
adds r0, r0, r7
strb r1, [r0]
ldr r0, [r6]
adds r2, #2
adds r0, r0, r2
strb r1, [r0]
movs r0, #0
bl SetPrimaryHBlankHandler
ldr r0, _08014E38 @ sub_8014CC4
bl SetPrimaryHBlankHandler
pop {r3, r4}
mov r8, r3
mov r9, r4
pop {r4, r5, r6, r7}
pop {r0}
bx r0
.align 2, 0
_08014E24: .4byte gUnknown_03004990
_08014E28: .4byte 0x0000078C
_08014E2C: .4byte 0x0000079B
_08014E30: .4byte 0x0000079C
_08014E34: .4byte 0x0000079D
_08014E38: .4byte sub_8014CC4
THUMB_FUNC_END sub_8014DA8
THUMB_FUNC_START sub_8014E3C
sub_8014E3C: @ 0x08014E3C
push {r4, r5, lr}
sub sp, #4
movs r0, #0
bl SetPrimaryHBlankHandler
mov r0, sp
movs r5, #0
strh r5, [r0]
ldr r4, _08014E68 @ gUnknown_03004990
ldr r1, [r4]
ldr r2, _08014E6C @ 0x010003C0
bl CpuSet
ldr r0, [r4]
ldr r1, _08014E70 @ 0x0000079E
adds r0, r0, r1
strb r5, [r0]
add sp, #4
pop {r4, r5}
pop {r0}
bx r0
.align 2, 0
_08014E68: .4byte gUnknown_03004990
_08014E6C: .4byte 0x010003C0
_08014E70: .4byte 0x0000079E
THUMB_FUNC_END sub_8014E3C
THUMB_FUNC_START sub_8014E74
sub_8014E74: @ 0x08014E74
push {r4, lr}
adds r3, r0, #0
ldr r0, _08014EA0 @ gUnknown_03004990
ldr r0, [r0]
ldr r4, _08014EA4 @ 0x0000079B
adds r2, r0, r4
ldrb r2, [r2]
adds r2, r2, r1
movs r1, #1
ands r2, r1
lsls r1, r2, #4
subs r1, r1, r2
lsls r1, r1, #6
adds r0, r0, r1
lsls r1, r3, #2
adds r1, r1, r3
lsls r1, r1, #6
adds r0, r0, r1
pop {r4}
pop {r1}
bx r1
.align 2, 0
_08014EA0: .4byte gUnknown_03004990
_08014EA4: .4byte 0x0000079B
THUMB_FUNC_END sub_8014E74
THUMB_FUNC_START sub_8014EA8
sub_8014EA8: @ 0x08014EA8
ldr r0, _08014EBC @ gUnknown_03004990
ldr r1, [r0]
ldr r0, _08014EC0 @ 0x0000079B
adds r1, r1, r0
ldrb r0, [r1]
movs r2, #1
eors r0, r2
strb r0, [r1]
bx lr
.align 2, 0
_08014EBC: .4byte gUnknown_03004990
_08014EC0: .4byte 0x0000079B
THUMB_FUNC_END sub_8014EA8
THUMB_FUNC_START sub_8014EC4
sub_8014EC4: @ 0x08014EC4
ldr r2, _08014ED8 @ gUnknown_03004990
ldr r2, [r2]
lsls r0, r0, #2
movs r3, #0xf0
lsls r3, r3, #3
adds r2, r2, r3
adds r2, r2, r0
str r1, [r2]
bx lr
.align 2, 0
_08014ED8: .4byte gUnknown_03004990
THUMB_FUNC_END sub_8014EC4
THUMB_FUNC_START sub_8014EDC
sub_8014EDC: @ 0x08014EDC
ldr r1, _08014EF0 @ gUnknown_03004990
ldr r1, [r1]
lsls r0, r0, #2
movs r2, #0xf0
lsls r2, r2, #3
adds r1, r1, r2
adds r1, r1, r0
movs r0, #0
str r0, [r1]
bx lr
.align 2, 0
_08014EF0: .4byte gUnknown_03004990
THUMB_FUNC_END sub_8014EDC
THUMB_FUNC_START sub_8014EF4
sub_8014EF4: @ 0x08014EF4
ldr r1, _08014F0C @ gUnknown_03004990
ldr r1, [r1]
movs r2, #0xf3
lsls r2, r2, #3
adds r1, r1, r2
adds r1, r1, r0
ldrb r2, [r1]
movs r0, #3
ands r0, r2
strb r0, [r1]
bx lr
.align 2, 0
_08014F0C: .4byte gUnknown_03004990
THUMB_FUNC_END sub_8014EF4
THUMB_FUNC_START sub_8014F10
sub_8014F10: @ 0x08014F10
ldr r1, _08014F2C @ gUnknown_03004990
ldr r2, [r1]
movs r1, #0xf3
lsls r1, r1, #3
adds r2, r2, r1
adds r2, r2, r0
ldrb r1, [r2]
movs r0, #3
ands r0, r1
movs r1, #1
orrs r0, r1
strb r0, [r2]
bx lr
.align 2, 0
_08014F2C: .4byte gUnknown_03004990
THUMB_FUNC_END sub_8014F10
THUMB_FUNC_START sub_8014F30
sub_8014F30: @ 0x08014F30
ldr r1, _08014F4C @ gUnknown_03004990
ldr r2, [r1]
movs r1, #0xf3
lsls r1, r1, #3
adds r2, r2, r1
adds r2, r2, r0
ldrb r1, [r2]
movs r0, #3
ands r0, r1
movs r1, #2
orrs r0, r1
strb r0, [r2]
bx lr
.align 2, 0
_08014F4C: .4byte gUnknown_03004990
THUMB_FUNC_END sub_8014F30

View File

@ -269,12 +269,26 @@ void sub_8014BE0(int palid);
void MemCpy(const void * src, void * dst, int size);
void PutDrawTextCentered(struct Text * text, int x, int y, char const * str, int width);
int sub_8014CA4(int, int, int, int);
// ??? sub_8014CC4(???);
void sub_8014DA8(void*);
struct Unknown03004990 {
/* 000 */ u16 buf[3 * 320];
/* 780 */ u16 * src[3];
/* 78C */ u16 * dst[3];
/* 798 */ u8 unk_798[3];
/* 79B */ u8 unk_79B;
/* 79C */ u8 unk_79C;
/* 79D */ bool unk_79D;
/* 79E */ bool unk_79E;
};
extern struct Unknown03004990 * gUnknown_03004990;
void HBlank_8014CC4(void);
void sub_8014DA8(struct Unknown03004990 * buf);
void sub_8014E3C(void);
// ??? sub_8014E74(???);
// ??? sub_8014EA8(???);
void sub_8014EC4(int, int);
u16 * sub_8014E74(int, int);
void sub_8014EA8(void);
void sub_8014EC4(int index,void * pr_offset);
// ??? sub_8014EDC(???);
void sub_8014EF4(int);
// ??? sub_8014F10(???);

View File

@ -27,7 +27,7 @@
// helper macros
#define EWRAM_ENTRY ((u8 *)__ewram_start)
#define EWRAM_ENTRY ((void *)__ewram_start)
#define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0]))

View File

@ -328,13 +328,6 @@ extern struct Unknown020007E0 gUnknown_020007E0[];
extern struct Font gSaveMenuSubBoxFont;
extern struct Text gSaveMenuSubBoxText;
struct Unknown03004990 {
/* 000 */ u8 unk[0x79E - 0x000];
/* 79E */ u8 unk_79E;
};
extern struct Unknown03004990* gUnknown_03004990;
extern u16 Sprite_08A20570[];
extern u16 Sprite_08A20578[];
extern u16 Sprite_08A20580[];

View File

@ -17,7 +17,7 @@ struct Struct02003BE8
/* 10 */ int * unk_10;
};
// ??? sub_800A42C(???);
int sub_800A42C(int a, int b, int c);
// ??? sub_800A4E8(???);
// ??? sub_800A518(???);
// ??? sub_800A680(???);

View File

@ -315,7 +315,7 @@ SECTIONS
src/eventfx-earthquake.o(.text);
src/eventfx-stoneshatter.o(.text);
src/bmlib.o(.text);
asm/bmlib-hblank.o(.text);
src/bmlib-hblank.o(.text);
src/bmlib-math.o(.text);
src/bm.o(.text);
src/bmitem.o(.text);

200
src/bmlib-hblank.c Normal file
View File

@ -0,0 +1,200 @@
#include "global.h"
#include "bmlib.h"
#include "spline.h"
#include "hardware.h"
int sub_8014CA4(int timer, int speed, int a, int b)
{
return sub_800A42C(DivArm(speed, timer * 0x1000), a, b);
}
void HBlank_8014CC4(void)
{
int bg;
u16 vcount = REG_VCOUNT + 1;
if (vcount == 228)
vcount = 0;
if (vcount < DISPLAY_HEIGHT)
{
if (gUnknown_03004990->unk_79D)
{
u16 * src = gUnknown_03004990->buf + gUnknown_03004990->unk_79C * 480;
for (bg = 0; bg < 3; bg++)
{
if (gUnknown_03004990->dst[bg])
{
*gUnknown_03004990->dst[bg] = vcount[src + 160 * bg]; // ¿
}
}
}
}
else if (vcount == DISPLAY_HEIGHT)
{
if (gUnknown_03004990->unk_79E)
{
gUnknown_03004990->unk_79D = true;
gUnknown_03004990->unk_79C = gUnknown_03004990->unk_79B;
for (bg = 0; bg < 3; bg++)
{
gUnknown_03004990->dst[bg] = gUnknown_03004990->src[bg];
}
}
else
{
gUnknown_03004990->unk_79D = false;
}
}
}
#if NONMATCHING
void sub_8014DA8(struct Unknown03004990 * buf)
{
int bg;
gUnknown_03004990 = buf;
for (bg = 0; bg < 3; bg++)
{
gUnknown_03004990->unk_798[bg] = 0;
gUnknown_03004990->dst[bg] = NULL;
gUnknown_03004990->src[bg] = NULL;
}
gUnknown_03004990->unk_79B = 0;
gUnknown_03004990->unk_79C = 0;
gUnknown_03004990->unk_79D = false;
gUnknown_03004990->unk_79E = false;
SetPrimaryHBlankHandler(NULL);
SetPrimaryHBlankHandler(HBlank_8014CC4);
}
#else
/* https://decomp.me/scratch/isCOG */
NAKEDFUNC
void sub_8014DA8(struct Unknown03004990 * buf)
{
asm("\
.syntax unified\n\
push {r4, r5, r6, r7, lr}\n\
mov r7, r9\n\
mov r6, r8\n\
push {r6, r7}\n\
ldr r1, _08014E24 @ gUnknown_03004990\n\
str r0, [r1]\n\
movs r3, #0\n\
adds r6, r1, #0\n\
adds r5, r6, #0\n\
movs r0, #0xf3\n\
lsls r0, r0, #3\n\
mov r8, r0\n\
movs r4, #0\n\
ldr r1, _08014E28 @ 0x0000078C\n\
mov ip, r1\n\
movs r2, #0xf0\n\
lsls r2, r2, #3\n\
mov r9, r2\n\
_08014DCC:\n\
ldr r0, [r5]\n\
add r0, r8\n\
adds r0, r0, r3\n\
strb r4, [r0]\n\
ldr r0, [r5]\n\
lsls r2, r3, #2\n\
mov r7, ip\n\
adds r1, r0, r7\n\
adds r1, r1, r2\n\
add r0, r9\n\
adds r0, r0, r2\n\
str r4, [r0]\n\
str r4, [r1]\n\
adds r3, #1\n\
cmp r3, #2\n\
ble _08014DCC\n\
ldr r0, [r6]\n\
ldr r1, _08014E2C @ 0x0000079B\n\
adds r2, r0, r1\n\
movs r1, #0\n\
strb r1, [r2]\n\
ldr r2, _08014E30 @ 0x0000079C\n\
adds r0, r0, r2\n\
strb r1, [r0]\n\
ldr r0, [r6]\n\
ldr r7, _08014E34 @ 0x0000079D\n\
adds r0, r0, r7\n\
strb r1, [r0]\n\
ldr r0, [r6]\n\
adds r2, #2\n\
adds r0, r0, r2\n\
strb r1, [r0]\n\
movs r0, #0\n\
bl SetPrimaryHBlankHandler\n\
ldr r0, _08014E38 @ HBlank_8014CC4\n\
bl SetPrimaryHBlankHandler\n\
pop {r3, r4}\n\
mov r8, r3\n\
mov r9, r4\n\
pop {r4, r5, r6, r7}\n\
pop {r0}\n\
bx r0\n\
.align 2, 0\n\
_08014E24: .4byte gUnknown_03004990\n\
_08014E28: .4byte 0x0000078C\n\
_08014E2C: .4byte 0x0000079B\n\
_08014E30: .4byte 0x0000079C\n\
_08014E34: .4byte 0x0000079D\n\
_08014E38: .4byte HBlank_8014CC4\n\
.syntax divided\n\
");
}
#endif
void sub_8014E3C(void)
{
SetPrimaryHBlankHandler(NULL);
CpuFill16(0, gUnknown_03004990->buf, sizeof(gUnknown_03004990->buf));
gUnknown_03004990->unk_79E = 0;
}
u16 * sub_8014E74(int bg, int flip)
{
int frame = (gUnknown_03004990->unk_79B + flip) & 1;
u16 * tm = gUnknown_03004990->buf + frame * 480;
return tm + bg * 160;
}
void sub_8014EA8(void)
{
gUnknown_03004990->unk_79B ^= 1;
}
void sub_8014EC4(int index, void * pr_offset)
{
gUnknown_03004990->src[index] = pr_offset;
}
void sub_8014EDC(int index)
{
gUnknown_03004990->src[index] = NULL;
}
void sub_8014EF4(int index)
{
gUnknown_03004990->unk_798[index] &= 3;
}
void sub_8014F10(int index)
{
gUnknown_03004990->unk_798[index] = (gUnknown_03004990->unk_798[index] & 3) | 1;
}
void sub_8014F30(int index)
{
gUnknown_03004990->unk_798[index] = (gUnknown_03004990->unk_798[index] & 3) | 2;
}

View File

@ -5,6 +5,7 @@
#include "hardware.h"
#include "proc.h"
#include "bm.h"
#include "spline.h"
#include "m4a.h"
#include "soundwrapper.h"
#include "fontgrp.h"

View File

@ -289,9 +289,6 @@ void sub_80AA7EC(struct SaveDrawProc * proc)
return;
}
u16 * sub_8014E74(int, int);
void sub_8014EA8(void);
//! FE8U = 0x080AA9D8
void sub_80AA9D8(struct SaveDrawProc * proc)
{
@ -365,12 +362,12 @@ void SaveDraw_Init(struct SaveDrawProc * proc)
proc->unk_40 = 0;
proc->unk_3e = 0;
sub_8014DA8(__ewram_start);
sub_8014EC4(0, REG_ADDR_BG2HOFS);
sub_8014DA8(EWRAM_ENTRY);
sub_8014EC4(0, (void *)REG_ADDR_BG2HOFS);
sub_8014EF4(0);
sub_80AA9D8(proc);
gUnknown_03004990->unk_79E = 1;
gUnknown_03004990->unk_79E = true;
sub_80AB548();
@ -935,11 +932,11 @@ void sub_80AB720(struct SaveDrawProc * proc)
proc->unk_40 = 0;
proc->unk_3e = 0;
sub_8014EC4(0, REG_ADDR_BG2HOFS);
sub_8014EC4(0, (void *)REG_ADDR_BG2HOFS);
sub_8014EF4(0);
sub_80AA9D8(proc);
gUnknown_03004990->unk_79E = 1;
gUnknown_03004990->unk_79E = true;
return;
}