Move InitGraphics from text

This commit is contained in:
DizzyEggg 2025-03-14 14:22:46 +01:00
parent 1f4c406866
commit 883d338b99
5 changed files with 71 additions and 111 deletions

View File

@ -1,31 +1,5 @@
.section .rodata
@ text.s
.string "pksdir0\0"
.align 2,0
.global gUnknown_80B88B0
gUnknown_80B88B0: @ 80B88B0
.string "font\0"
.align 2,0
.global gUnknown_80B88B8
gUnknown_80B88B8: @ 80B88B8
.string "fontsp\0"
.align 2,0
.global gUnknown_80B88C0
gUnknown_80B88C0: @ 80B88C0
.string "fontsppa\0"
.align 2,0
.global gUnknown_80B88CC
gUnknown_80B88CC: @ 80B88CC
.string "fontpal\0"
.align 2,0
@ code_8009804.s
@ ?
.string "pksdir0\0"

View File

@ -409,6 +409,7 @@ SECTIONS {
data/data1.o(.rodata);
src/random.o(.rodata);
src/text.o(.rodata);
src/code_8009804.o(.rodata);
data/data2.o(.rodata);
src/math.o(.rodata);
src/file_system.o(.rodata);

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "globaldata.h"
#include "bg_palette_buffer.h"
#include "code_8009804.h"
#include "cpu.h"
@ -6,7 +7,6 @@
#include "text.h"
#include "code_800558C.h"
extern const u8 gUnknown_80B88CC[];
extern const struct FileArchive gSystemFileArchive; // 8300500
EWRAM_DATA RGB gFontPalette[128] = {0};
@ -15,13 +15,77 @@ EWRAM_DATA static s32 gUnknown_202D23C = 0;
EWRAM_DATA static struct unkStruct_202D240 gUnknown_202D240[8] = {0};
EWRAM_DATA u32 gUnknown_202D2A0 = 0;
struct FontData
{
s32 size;
u8 dataArray[0];
};
// Only written to.
EWRAM_INIT static bool8 gUnknown_203B090 = FALSE;
#define OAM_DUMMY 0xA000A0 // y set to 160 - DISPLAY_HEIGHT
void InitGraphics(void)
{
s32 i;
OpenedFile *file;
u32 *dest;
const RGB *rgbColors;
struct FontData *font;
#ifdef NONMATCHING
const FileArchive *sysFileArchieve;
#else
register const FileArchive *sysFileArchieve asm("r4");
#endif // NONMATCHING
gUnknown_203B090 = TRUE;
dest = (u32 *)VRAM;
for (i = 0; i < VRAM_SIZE / sizeof(*dest); i++) {
*dest++ = 0;
}
dest = (u32 *)PLTT;
for (i = 0; i < PLTT_SIZE / sizeof(*dest); i++) {
*dest++ = 0;
}
dest = (u32 *)OAM;
for (i = 0; i < OAM_SIZE / sizeof(*dest); i++) {
*dest++ = OAM_DUMMY;
}
sysFileArchieve = &gSystemFileArchive;
file = OpenFileAndGetFileDataPtr("font", sysFileArchieve);
font = (struct FontData *)(file->data);
i = font->size;
CpuCopy((u32 *)(VRAM + 0x4f00), font->dataArray, i * 32);
CloseFile(file);
file = OpenFileAndGetFileDataPtr("fontsp", sysFileArchieve);
font = (struct FontData *)(file->data);
i = font->size;
CpuCopy((u32 *)(VRAM + 0x17e00), font->dataArray, i * 32);
CloseFile(file);
InitFontPalette();
file = OpenFileAndGetFileDataPtr("fontsppa", sysFileArchieve);
rgbColors = (RGB *)file->data;
for (i = 0; i < 16; rgbColors++, i++) {
SetBGPaletteBufferColorArray(0x1F0 + i, rgbColors);
}
CloseFile(file);
TransferBGPaletteBuffer();
}
void InitFontPalette(void)
{
OpenedFile *fontpalFile;
s32 i;
RGB *ptr;
fontpalFile = OpenFileAndGetFileDataPtr(gUnknown_80B88CC, &gSystemFileArchive); // fontpal
fontpalFile = OpenFileAndGetFileDataPtr("fontpal", &gSystemFileArchive);
CpuCopy(gFontPalette, fontpalFile->data, sizeof(gFontPalette));
if (sub_80063B0() == 1)
@ -65,8 +129,8 @@ void vram_related_8009804(void)
*dest++ = 0;
dest = (u32 *)OAM;
for (i = 0; i < OAM_SIZE / 4; i++)
*dest++ = 0xA000A0; // TODO: Macro or explanation
for (i = 0; i < OAM_SIZE / sizeof(*dest); i++)
*dest++ = OAM_DUMMY;
}
void sub_80098A0(void)

View File

@ -15,11 +15,6 @@ struct CharMapStruct
struct unkChar *unk4;
};
// data2.s
extern const char gUnknown_80B88B0[]; // "font"
extern const char gUnknown_80B88B8[]; // "fontsp"
extern const char gUnknown_80B88C0[]; // "fontsppa"
// system_sbin.s
extern const struct FileArchive gSystemFileArchive;
@ -58,9 +53,6 @@ EWRAM_INIT void (*ScrollUpWindowFunc)(s32 windowId) = ScrollUpWindow;
EWRAM_INIT void (*gIwramTextFunc3)(s32 a0) = sub_82729A4;
EWRAM_INIT void (*gIwramTextFunc4)(s32 a0) = sub_8272A78;
// This variable is only used in InitGraphics function, which may or may not belong to text.c
EWRAM_INIT u8 gUnknown_203B090 = 0;
static void ShowWindowsInternal(const WindowTemplates *a0, bool8 a1, bool8 a2, DungeonPos *a3);
static void AddWindow(Window *windows, u32 *vram, u32 *a2, u16 *a3, u32 windowId, const WindowTemplate *winTemplate, bool8 a6, s32 firstBlockId, DungeonPos *positionModifier, u8 a9);
static void sub_800677C(Window *a0, s32 a1, u16 *a2, u8 a3);
@ -3273,78 +3265,6 @@ static s32 InterpretColorChar(u8 a0)
return 7;
}
struct FontData {
u32 size;
u8 dataArray[136 * 32];
};
struct FontSpData {
u32 size;
u8 dataArray[16 * 32];
};
void InitGraphics(void)
{
u32 count;
OpenedFile *file;
u32 *dest;
struct FontData *font;
struct FontSpData *fontSp;
#ifdef NONMATCHING
RGB *data;
u32 size;
const struct FileArchive *arc;
#else
register RGB *data asm("r4");
register u32 size asm("r5");
register const struct FileArchive *arc asm("r4");
#endif
gUnknown_203B090 = 1;
dest = (u32 *)VRAM;
for(count = 0; count < 0x6000; count++)
{
*dest++ = 0;
}
dest = (u32 *)PLTT;
for(count = 0; count < 0x100; count++)
{
*dest++ = 0;
}
dest = (u32 *)OAM;
for(count = 0; count < 0x100; count++)
{
*dest++ = 0x00a000a0;
}
arc = &gSystemFileArchive;
file = OpenFileAndGetFileDataPtr(gUnknown_80B88B0, arc);
font = (struct FontData *)(file->data);
size = font->size;
CpuCopy((u32 *)0x06004f00, font->dataArray, size * 32);
CloseFile(file);
file = OpenFileAndGetFileDataPtr(gUnknown_80B88B8, arc);
fontSp = (struct FontSpData *)(file->data);
size = fontSp->size;
CpuCopy((u32 *)0x06017e00, fontSp->dataArray, size * 32);
CloseFile(file);
InitFontPalette();
file = OpenFileAndGetFileDataPtr(gUnknown_80B88C0, arc);
data = (RGB *)file->data;
for(count = 0; (s32)count < 0x10; data++, count++)
{
SetBGPaletteBufferColorArray(0x1F0 + count, data);
}
CloseFile(file);
TransferBGPaletteBuffer();
}
// These functions run from IWRAM for improved performance.
IWRAM_INIT void ScrollDownWindow(s32 windowId)
{

View File

@ -6,6 +6,7 @@
.include "src/code_800558C.o"
.include "src/random.o"
.include "src/text.o"
.include "src/code_8009804.o"
.include "src/file_system.o"
.include "src/main.o"
.include "src/reg_control.o"