move reg control vars to ewram, merge with unused vblank

This commit is contained in:
DizzyEggg
2024-12-14 23:15:43 +01:00
parent b9fbe33d89
commit 40ceb381ed
10 changed files with 6457 additions and 6482 deletions

File diff suppressed because it is too large Load Diff

6201
data/data_80B9BB8_2.s Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,6 @@
#ifndef GUARD_MAIN_H
#define GUARD_MAIN_H
typedef void (*IntrCallback)(void);
void AgbMain(void);
extern IntrCallback gIntrCallbacks[6];
void AckInterrupt(u16);
bool8 EnableInterrupts(void);
bool8 DisableInterrupts(void);
#endif // GUARD_MAIN_H
#endif // GUARD_MAIN_H

View File

@@ -1,7 +1,13 @@
#ifndef GUARD_CODE_800B5F0_H
#define GUARD_CODE_800B5F0_H
#include "main.h"
typedef void (*IntrCallback)(void);
extern IntrCallback gIntrCallbacks[6];
void AckInterrupt(u16);
bool8 EnableInterrupts(void);
bool8 DisableInterrupts(void);
// size: 0x8
typedef struct unkStruct_202D648
@@ -16,9 +22,12 @@ extern s16 gUnknown_203B0AA;
extern s16 gUnknown_203B0AC;
extern s16 gUnknown_203B0AE;
void sub_800B540(void);
void InitIntrTable(const IntrCallback *interrupt_table);
IntrCallback SetInterruptCallback(u32 index, IntrCallback new_callback);
void nullsub_17(void);
void xxx_update_bg_sound_input(void);
void sub_800BA5C(void);
#endif // GUARD_CODE_800B5F0_H
#endif // GUARD_CODE_800B5F0_H

View File

@@ -69,7 +69,6 @@ SECTIONS {
src/file_system.o(.text);
src/decompress.o(.text);
src/main.o(.text);
src/unused_vblank.o(.text);
src/reg_control.o(.text);
src/music.o(.text);
src/code_800C9CC.o(.text);
@@ -424,6 +423,9 @@ SECTIONS {
src/file_system.o(.rodata);
src/decompress.o(.rodata);
data/data_80B9BB8.o(.rodata);
src/main.o(.rodata);
src/reg_control.o(.rodata);
data/data_80B9BB8_2.o(.rodata);
src/debug.o(.rodata);
src/save.o(.rodata);
src/save_read.o(.rodata);

View File

@@ -1,4 +1,5 @@
#include "global.h"
#include "globaldata.h"
#include "bg_control.h"
#include "bg_palette_buffer.h"
#include "code_8004AA0.h"
@@ -16,10 +17,6 @@
#include "sprite.h"
#include "text.h"
EWRAM_DATA u8 IntrMain_Buffer[0x120] = {0};
EWRAM_DATA IntrCallback gIntrTable[6] = {0};
EWRAM_DATA IntrCallback gIntrCallbacks[6] = {0};
extern u8 ewram_start[];
extern u8 ewramClearEnd[];
extern u8 ewramClearEnd2[]; // Force a second storage in the asm
@@ -30,31 +27,20 @@ extern u8 unk_code[];
extern u8 unk_code_ram[];
extern u8 unk_code_ram_end[];
EWRAM_DATA_2 u8 gInterruptsEnabled = {0};
// data_8270000.s
extern const u8 gUnknown_8270000[];
// data_80B9BB8.s
extern const u8 gUnknown_80B9BF1[];
extern const IntrCallback gInitialIntrTable[6];
UNUSED static const char sStringRomUserData[] = "PKD ROM USER DATA 000000";
// code_2.c
extern void GameLoop(void);
extern void InitGraphics(void);
// code_800D090.c
extern void Hang(void);
extern void sub_800D6AC(void);
extern void sub_800D7D0(void);
void InitIntrTable(const IntrCallback *interrupt_table);
IntrCallback SetInterruptCallback(u32 index, IntrCallback new_callback);
void sub_800B540(void);
void AgbMain(void)
{
u8 value[4];
u8 seed[6];
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;
@@ -96,8 +82,12 @@ void AgbMain(void)
sub_800CDA8(1);
sub_800B540();
InitFlash();
memcpy(seed, gUnknown_80B9BF1, 6);
{
u8 seed[] = {0x36, 0x27, 0x46, 0x01, 0xB9, 0x48};
SeedRng(seed);
}
InitSprites();
nullsub_9();
nullsub_6();
@@ -113,107 +103,3 @@ void AgbMain(void)
GameLoop();
Hang();
}
void sub_800B540(void)
{
s32 i;
for (i = 0; i < 6; i++)
gIntrCallbacks[i] = NULL;
nullsub_17();
InitMusic(); // initialize music and stop DMAs
while (REG_VCOUNT < 160){}
REG_IE ^= INTR_FLAG_TIMER3 | INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT; // 0x45
*(u8*)&REG_DISPCNT |= DISPCNT_FORCED_BLANK;
InitIntrTable(gInitialIntrTable); // set up intrrupt vector/table
REG_TM3CNT = (TIMER_64CLK | TIMER_INTR_ENABLE | TIMER_ENABLE) << 16;
REG_IE |= INTR_FLAG_GAMEPAK | INTR_FLAG_TIMER3 | INTR_FLAG_VCOUNT | INTR_FLAG_VBLANK; // 0x2045
REG_DISPSTAT = DISPSTAT_VCOUNT_INTR | DISPSTAT_VBLANK_INTR;
gUnknown_203B0AE = -1;
gUnknown_203B0AC = 0;
sub_800D6AC(); // Some other IO REG update func
sub_800D7D0(); // Some other IO REG update func
gInterruptsEnabled = 1;
EnableInterrupts();
while(REG_VCOUNT < 160){}
}
bool8 EnableInterrupts(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (REG_IME & 1)
return FALSE;
REG_IME = 1;
return TRUE;
}
bool8 DisableInterrupts(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (!(REG_IME & 1))
return FALSE;
REG_IME = 0;
return TRUE;
}
bool8 sub_800B650(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (REG_IME & 1)
return FALSE;
return TRUE;
}
void AckInterrupt(u16 flag)
{
if (!gInterruptsEnabled)
return;
REG_IME = 0;
INTR_CHECK |= flag;
REG_IME = 1;
}
void InitIntrTable(const IntrCallback *interrupt_table)
{
CpuCopy32(interrupt_table, gIntrTable, sizeof(gIntrTable)); // 0x18 = 0x6 * 4 (0x4F00 is 32 bits)
CpuCopy32(IntrMain, IntrMain_Buffer, sizeof(IntrMain_Buffer)); // 0x120 = 0x48 * 4 (0x4F00 is 32 bits)
INTR_VECTOR = IntrMain_Buffer;
}
IntrCallback *GetInterruptHandler(u32 index)
{
return &gIntrTable[index];
}
IntrCallback SetInterruptCallback(u32 index, IntrCallback new_callback)
{
IntrCallback old_callback;
u32 interrupt_var;
interrupt_var = DisableInterrupts();
old_callback = gIntrCallbacks[index];
gIntrCallbacks[index] = new_callback;
if (interrupt_var)
EnableInterrupts();
return old_callback;
}

View File

@@ -1,7 +1,7 @@
#include "global.h"
#include "constants/bg_music.h"
#include "m4a.h"
#include "main.h"
#include "reg_control.h"
#include "music.h"
static EWRAM_DATA u16 sBGMusicPlayerstate = {0};

View File

@@ -1,14 +1,22 @@
#include "global.h"
#include "globaldata.h"
#include "bg_control.h"
#include "debug.h"
#include "input.h"
#include "music.h"
#include "reg_control.h"
#include "sprite.h"
#include "crt0.h"
extern void (gUnknown_202DBB8)(void);
EWRAM_DATA u8 IntrMain_Buffer[0x120] = {0};
EWRAM_DATA IntrCallback gIntrTable[6] = {0};
EWRAM_DATA IntrCallback gIntrCallbacks[6] = {0};
EWRAM_DATA unkStruct_202D648 gUnknown_202D608[8] = {0};
EWRAM_DATA unkStruct_202D648 gUnknown_202D648[8] = {0};
EWRAM_DATA_2 u8 gInterruptsEnabled = {0};
EWRAM_DATA_2 bool8 gUnknown_203B099 = {0};
EWRAM_DATA_2 bool8 gUnknown_203B09A = {0};
EWRAM_DATA_2 bool8 gUnknown_203B09B = {0};
@@ -22,7 +30,227 @@ EWRAM_DATA_2 s16 gUnknown_203B0AE = {0};
EWRAM_DATA_2 s16 gUnknown_203B0B0 = {0}; // Written to but never read
EWRAM_DATA_2 s16 gUnknown_203B0B2 = {0}; // Written to but never read
// code_800D090.c
extern void sub_800D6AC(void);
extern void sub_800D7D0(void);
static void UpdateBGControlRegisters(void);
void VBlankIntr(void);
void VCountIntr(void);
void UnusedIntrFunc(void);
void Timer3Intr(void);
static const IntrCallback sInitialIntrTable[6] =
{
&gUnknown_202DBB8,
VBlankIntr,
VCountIntr,
UnusedIntrFunc,
Timer3Intr,
UnusedIntrFunc,
};
void sub_800B540(void)
{
s32 i;
for (i = 0; i < 6; i++)
gIntrCallbacks[i] = NULL;
nullsub_17();
InitMusic(); // initialize music and stop DMAs
while (REG_VCOUNT < 160){}
REG_IE ^= INTR_FLAG_TIMER3 | INTR_FLAG_VBLANK | INTR_FLAG_VCOUNT; // 0x45
*(u8*)&REG_DISPCNT |= DISPCNT_FORCED_BLANK;
InitIntrTable(sInitialIntrTable); // set up intrrupt vector/table
REG_TM3CNT = (TIMER_64CLK | TIMER_INTR_ENABLE | TIMER_ENABLE) << 16;
REG_IE |= INTR_FLAG_GAMEPAK | INTR_FLAG_TIMER3 | INTR_FLAG_VCOUNT | INTR_FLAG_VBLANK; // 0x2045
REG_DISPSTAT = DISPSTAT_VCOUNT_INTR | DISPSTAT_VBLANK_INTR;
gUnknown_203B0AE = -1;
gUnknown_203B0AC = 0;
sub_800D6AC(); // Some other IO REG update func
sub_800D7D0(); // Some other IO REG update func
gInterruptsEnabled = 1;
EnableInterrupts();
while(REG_VCOUNT < 160){}
}
bool8 EnableInterrupts(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (REG_IME & 1)
return FALSE;
REG_IME = 1;
return TRUE;
}
bool8 DisableInterrupts(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (!(REG_IME & 1))
return FALSE;
REG_IME = 0;
return TRUE;
}
bool8 sub_800B650(void)
{
if (!gInterruptsEnabled)
return FALSE;
if (REG_IME & 1)
return FALSE;
return TRUE;
}
void AckInterrupt(u16 flag)
{
if (!gInterruptsEnabled)
return;
REG_IME = 0;
INTR_CHECK |= flag;
REG_IME = 1;
}
void InitIntrTable(const IntrCallback *interrupt_table)
{
CpuCopy32(interrupt_table, gIntrTable, sizeof(gIntrTable)); // 0x18 = 0x6 * 4 (0x4F00 is 32 bits)
CpuCopy32(IntrMain, IntrMain_Buffer, sizeof(IntrMain_Buffer)); // 0x120 = 0x48 * 4 (0x4F00 is 32 bits)
INTR_VECTOR = IntrMain_Buffer;
}
IntrCallback *GetInterruptHandler(u32 index)
{
return &gIntrTable[index];
}
IntrCallback SetInterruptCallback(u32 index, IntrCallback new_callback)
{
IntrCallback old_callback;
u32 interrupt_var;
interrupt_var = DisableInterrupts();
old_callback = gIntrCallbacks[index];
gIntrCallbacks[index] = new_callback;
if (interrupt_var)
EnableInterrupts();
return old_callback;
}
// Unused?
s32 sub_800B720(s16 a0, IntrCallback a1)
{
s32 r2;
unkStruct_202D648 *r3;
s32 r4;
bool8 sp4;
s32 spC;
bool32 sp10;
spC = a0;
sp4 = DisableInterrupts();
do {
sp10 = FALSE;
r4 = 0;
r3 = gUnknown_202D608;
if (r4 >= gUnknown_203B0AA)
continue;
if (r3->unk0 == gUnknown_203B0A8) {
gUnknown_203B0A8 = (gUnknown_203B0A8 + 1) & 0x7fff;
sp10 = TRUE;
continue;
}
label:
do {
r4++;
r3++;
if (r4 >= gUnknown_203B0AA)
continue;
if (r3->unk0 == gUnknown_203B0A8) {
gUnknown_203B0A8 = (gUnknown_203B0A8 + 1) & 0x7fff;
sp10 = TRUE;
}
else
goto label;
} while (0);
} while (sp10);
for (r4 = 0, r3 = gUnknown_202D608; r4 < gUnknown_203B0AA; r4++, r3++) {
if (r3->unk2 > spC)
break;
}
for (r2 = gUnknown_203B0AA - 1, r3 = &gUnknown_202D608[r2]; r2 >= r4; r2--, r3--)
r3[1] = r3[0];
gUnknown_203B0AA++;
gUnknown_202D608[r4].unk0 = gUnknown_203B0A8;
#ifdef NONMATCHING
gUnknown_202D608[r4].unk2 = spC;
#else
gUnknown_202D608[r4].unk2 = ((u32)spC << 0x10 >> 0x10); // fake and may overflow. Unspecified behavior
#endif
gUnknown_202D608[r4].unk4 = a1;
if (sp4)
EnableInterrupts();
return gUnknown_203B0A8;
}
// Unused?
void sub_800B850(s16 a0)
{
s32 r2;
unkStruct_202D648 *r4;
bool8 r5;
s32 r6;
r6 = a0;
r5 = DisableInterrupts();
r2 = 0;
r4 = &gUnknown_202D608[r2];
r4++; r4--;
for (; r2 < gUnknown_203B0AA; r2++, r4++) {
if (r4->unk0 != r6)
continue;
gUnknown_203B0AA--;
for (; r2 < gUnknown_203B0AA; r2++, r4++)
r4[0] = r4[1];
if (!r5)
return;
EnableInterrupts();
return;
}
if (r5)
EnableInterrupts();
}
void UnusedIntrFunc(void)
{
}
void VBlankIntr(void)
{
@@ -52,7 +280,7 @@ void VBlankIntr(void)
void VCountIntr(void)
{
s32 sVar2 = (s16) REG_VCOUNT;
s32 sVar2 = (vs16) REG_VCOUNT;
if (gUnknown_203B0AE < 0) {
if (gIntrCallbacks[2] != 0) {

View File

@@ -1,102 +0,0 @@
#include "global.h"
#include "reg_control.h"
extern unkStruct_202D648 gUnknown_202D608[8];
// Unused?
s32 sub_800B720(s16 a0, IntrCallback a1)
{
s32 r2;
unkStruct_202D648 *r3;
s32 r4;
bool8 sp4;
s32 spC;
bool32 sp10;
spC = a0;
sp4 = DisableInterrupts();
do {
sp10 = FALSE;
r4 = 0;
r3 = gUnknown_202D608;
if (r4 >= gUnknown_203B0AA)
continue;
if (r3->unk0 == gUnknown_203B0A8) {
gUnknown_203B0A8 = (gUnknown_203B0A8 + 1) & 0x7fff;
sp10 = TRUE;
continue;
}
label:
do {
r4++;
r3++;
if (r4 >= gUnknown_203B0AA)
continue;
if (r3->unk0 == gUnknown_203B0A8) {
gUnknown_203B0A8 = (gUnknown_203B0A8 + 1) & 0x7fff;
sp10 = TRUE;
}
else
goto label;
} while (0);
} while (sp10);
for (r4 = 0, r3 = gUnknown_202D608; r4 < gUnknown_203B0AA; r4++, r3++) {
if (r3->unk2 > spC)
break;
}
for (r2 = gUnknown_203B0AA - 1, r3 = &gUnknown_202D608[r2]; r2 >= r4; r2--, r3--)
r3[1] = r3[0];
gUnknown_203B0AA++;
gUnknown_202D608[r4].unk0 = gUnknown_203B0A8;
#ifdef NONMATCHING
gUnknown_202D608[r4].unk2 = spC;
#else
gUnknown_202D608[r4].unk2 = ((u32)spC << 0x10 >> 0x10); // fake and may overflow. Unspecified behavior
#endif
gUnknown_202D608[r4].unk4 = a1;
if (sp4)
EnableInterrupts();
return gUnknown_203B0A8;
}
// Unused?
void sub_800B850(s16 a0)
{
s32 r2;
unkStruct_202D648 *r4;
bool8 r5;
s32 r6;
r6 = a0;
r5 = DisableInterrupts();
r2 = 0;
r4 = &gUnknown_202D608[r2];
r4++; r4--;
for (; r2 < gUnknown_203B0AA; r2++, r4++) {
if (r4->unk0 != r6)
continue;
gUnknown_203B0AA--;
for (; r2 < gUnknown_203B0AA; r2++, r4++)
r4[0] = r4[1];
if (!r5)
return;
EnableInterrupts();
return;
}
if (r5)
EnableInterrupts();
}
void UnusedIntrFunc(void)
{
}

View File

@@ -42,33 +42,7 @@ gUnknown_203B090: /* 203B090 (InitGraphics) */
.include "src/file_system.o"
.include "src/main.o"
/* reg_control */
gUnknown_203B099: /* 203B099 (VBlankIntr - xxx_update_bg_sound_input) */
.space 0x1
gUnknown_203B09A: /* 203B09A (sub_800BA5C - xxx_update_bg_sound_input) */
.space 0x1
gUnknown_203B09B: /* 203B09B */
.space 0x1
gUnknown_203B09C: /* 203B09C */
.space 0x4
gUnknown_203B0A0: /* 203B0A0 */
.space 0x4
gUnknown_203B0A4: /* 203B0A4 */
.space 0x4
gUnknown_203B0A8: /* 203B0A8 */
.space 0x2
gUnknown_203B0AA: /* 203B0AA */
.space 0x2
gUnknown_203B0AC: /* 203B0AC */
.space 0x2
gUnknown_203B0AE: /* 203B0AE */
.space 0x2
gUnknown_203B0B0: /* 203B0B0 */
.space 0x2
gUnknown_203B0B2: /* 203B0B2 */
.space 0x2
.include "src/reg_control.o"
.include "src/flash.o"
.space 0x3