summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/berry_fix_program.c531
-rw-r--r--src/bg.c189
-rw-r--r--src/multiboot.c2
-rw-r--r--src/text.c6
-rw-r--r--src/window.c2
5 files changed, 626 insertions, 104 deletions
diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c
new file mode 100644
index 000000000..f04308ae8
--- /dev/null
+++ b/src/berry_fix_program.c
@@ -0,0 +1,531 @@
+
+// Includes
+#include "global.h"
+#include "gpu_regs.h"
+#include "multiboot.h"
+#include "malloc.h"
+#include "bg.h"
+#include "main.h"
+#include "sprite.h"
+#include "task.h"
+#include "unknown_task.h"
+#include "window.h"
+#include "menu.h"
+#include "m4a.h"
+
+// Static type declarations
+
+typedef struct {
+ u8 state;
+ u8 unk1;
+ u16 unk2;
+ struct MultiBootParam mb;
+} berryfix_t;
+
+// Static RAM declarations
+
+static berryfix_t *berry_fix_mb_manager;
+
+// Static ROM declarations
+
+static void berry_fix_main(void);
+static void berry_fix_gpu_set(void);
+static int berry_fix_text_update(int);
+static void berry_fix_text_print(int);
+static void berry_fix_bg_hide(void);
+
+// .rodata
+
+static const u8 gUnknown_08617E78[] = _("Berry Program Update");
+static const u8 gUnknown_08617E8D[] = _("Ruby/Sapphire");
+static const u8 gUnknown_08617E9B[] = _("Emerald");
+
+static const u8 Unknown_08617EA3[] = _("The Berry Program on your POKéMON\nRuby/Sapphire Game Pak will be updated.\n{COLOR RED}{SHADOW LIGHT_RED}Press the A Button.");
+static const u8 Unknown_08617F07[] = _("Please ensure the connection of your\nGame Boy Advance system matches this.\n{COLOR RED}{SHADOW LIGHT_RED}YES: Press the A Button.\nNO: Turn off the power and try again.");
+static const u8 Unknown_08617F97[] = _("Please turn on the power of POKéMON\nRuby/Sapphire while holding START and\nSELECT simultaneously. Then, ensure\nthe picture above appears.");
+static const u8 Unknown_08618020[] = _("Transmitting. Please wait.\n{COLOR RED}{SHADOW LIGHT_RED}Please do not turn off the power or\nunplug the Game Boy Advance Game\nLink Cable.");
+static const u8 Unknown_08618092[] = _("Please follow the instructions on your\nPOKéMON Ruby/Sapphire screen.");
+static const u8 Unknown_086180D7[] = _("Transmission failure.\n{COLOR RED}{SHADOW LIGHT_RED}Please try again.");
+
+static const struct BgTemplate gUnknown_08618108[] = {
+ {
+ 0, 0, 30, 0, 0, 0
+ }, {
+ 1, 1, 31, 0, 0, 1
+ }
+};
+
+static const struct WindowTemplate gUnknown_08618110[] = {
+ {0, 2, 4, 26, 2, 15, 0x001},
+ {0, 1, 11, 28, 8, 15, 0x035},
+ {0, 0, 8, 30, 2, 15, 0x115},
+ {0, 8, 0, 14, 2, 15, 0x151},
+ {-1}
+};
+
+static const u16 gUnknown_08618138[] = {
+ 0x7fff, 0x7fff, 0x318c, 0x675a,
+ 0x043c, 0x3aff, 0x0664, 0x4bd2,
+ 0x6546, 0x7b14, 0x7fff, 0x318c,
+ 0x675a, 0x0000, 0x0000, 0x0000
+};
+
+static const u8 gUnknown_08618158[] = {10, 11, 12};
+static const u8 gUnknown_0861815B[] = { 0, 10, 13};
+
+static const u8 *const gUnknown_08618160[] = {
+ Unknown_08617F07,
+ Unknown_08617F97,
+ Unknown_08618020,
+ Unknown_08618092,
+ Unknown_086180D7,
+ Unknown_08617EA3
+};
+
+extern const u8 gUnknown_08DD87C0[];
+extern const u8 gUnknown_08DD8EE0[];
+extern const u8 gUnknown_08DD8780[];
+extern const u8 gUnknown_08DD90E0[];
+extern const u8 gUnknown_08DD9718[];
+extern const u8 gUnknown_08DD9080[];
+extern const u8 gUnknown_08DD98B4[];
+extern const u8 gUnknown_08DD9E58[];
+extern const u8 gUnknown_08DD9874[];
+extern const u8 gUnknown_08DDA02C[];
+extern const u8 gUnknown_08DDA63C[];
+extern const u8 gUnknown_08DD9FEC[];
+extern const u8 gUnknown_08DDA840[];
+extern const u8 gUnknown_08DDAE40[];
+extern const u8 gUnknown_08DDA800[];
+extern const u8 gUnknown_08DDB020[];
+extern const u8 gUnknown_08DDB2C4[];
+extern const u8 gUnknown_08DDAFE0[];
+
+static const u8 *const gUnknown_08618178[][3] = {
+ {
+ gUnknown_08DD87C0,
+ gUnknown_08DD8EE0,
+ gUnknown_08DD8780
+ }, {
+ gUnknown_08DD90E0,
+ gUnknown_08DD9718,
+ gUnknown_08DD9080
+ }, {
+ gUnknown_08DD98B4,
+ gUnknown_08DD9E58,
+ gUnknown_08DD9874
+ }, {
+ gUnknown_08DDA02C,
+ gUnknown_08DDA63C,
+ gUnknown_08DD9FEC
+ }, {
+ gUnknown_08DDA840,
+ gUnknown_08DDAE40,
+ gUnknown_08DDA800
+ }, {
+ gUnknown_08DDB020,
+ gUnknown_08DDB2C4,
+ gUnknown_08DDAFE0
+ },
+};
+
+extern const u8 gUnknown_089A6550[0xC0];
+extern const u8 gMultiBootProgram_BerryGlitchFix_Start[0x3b34];
+extern const u8 gMultiBootProgram_BerryGlitchFix_End[];
+
+// .text
+
+void InitBerryFixProgram(void)
+{
+ DisableInterrupts(0xFFFF);
+ EnableInterrupts(0x0001);
+ m4aSoundVSyncOff();
+ SetVBlankCallback(NULL);
+ ResetSpriteData();
+ ResetTasks();
+ remove_some_task();
+ SetGpuReg(REG_OFFSET_DISPCNT, 0x0000);
+ berry_fix_mb_manager = AllocZeroed(0x50);
+ berry_fix_mb_manager->state = 0;
+ berry_fix_mb_manager->unk1 = 6;
+ SetMainCallback2(berry_fix_main);
+}
+
+static void berry_fix_main(void)
+{
+ switch (berry_fix_mb_manager->state)
+ {
+ case 0:
+ berry_fix_gpu_set();
+ berry_fix_mb_manager->state = 1;
+ break;
+ case 1:
+ if (berry_fix_text_update(5) == 5 && (gMain.newKeys & A_BUTTON))
+ {
+ berry_fix_mb_manager->state = 2;
+ }
+ break;
+ case 2:
+ if (berry_fix_text_update(0) == 0 && (gMain.newKeys & A_BUTTON))
+ {
+ berry_fix_mb_manager->state = 3;
+ }
+ break;
+ case 3:
+ if (berry_fix_text_update(1) == 1)
+ {
+ berry_fix_mb_manager->mb.masterp = gUnknown_089A6550;
+ berry_fix_mb_manager->mb.server_type = 0;
+ MultiBootInit(&berry_fix_mb_manager->mb);
+ berry_fix_mb_manager->unk2 = 0;
+ berry_fix_mb_manager->state = 4;
+ }
+ break;
+ case 4:
+ MultiBootMain(&berry_fix_mb_manager->mb);
+ if (berry_fix_mb_manager->mb.probe_count != 0 || (!(berry_fix_mb_manager->mb.response_bit & 2) || !(berry_fix_mb_manager->mb.client_bit & 2)))
+ {
+ berry_fix_mb_manager->unk2 = 0;
+ }
+ else if (++ berry_fix_mb_manager->unk2 > 180)
+ {
+ MultiBootStartMaster(&berry_fix_mb_manager->mb, gMultiBootProgram_BerryGlitchFix_Start, (u32)(gMultiBootProgram_BerryGlitchFix_End - gMultiBootProgram_BerryGlitchFix_Start), 4, 1);
+ berry_fix_mb_manager->state = 5;
+ }
+ break;
+ case 5:
+ if (berry_fix_text_update(2) == 2) {
+ MultiBootMain(&berry_fix_mb_manager->mb);
+ if (MultiBootCheckComplete(&berry_fix_mb_manager->mb)) {
+ berry_fix_mb_manager->state = 6;
+ }
+ else if (!(berry_fix_mb_manager->mb.client_bit & 2)) {
+ berry_fix_mb_manager->state = 7;
+ }
+ }
+ break;
+ case 6:
+ if (berry_fix_text_update(3) == 3 && gMain.newKeys & A_BUTTON)
+ {
+ DoSoftReset();
+ }
+ break;
+ case 7:
+ if (berry_fix_text_update(4) == 4 && gMain.newKeys & A_BUTTON)
+ {
+ berry_fix_mb_manager->state = 1;
+ }
+ break;
+ }
+}
+
+#ifdef NONMATCHING
+static void berry_fix_gpu_set(void)
+{
+ s32 width;
+
+ SetGpuReg(REG_OFFSET_BG0CNT, 0x0000);
+ SetGpuReg(REG_OFFSET_BG1CNT, 0x0000);
+ SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000);
+ SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000);
+ SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000);
+ SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000);
+ SetGpuReg(REG_OFFSET_BLDCNT, 0x0000);
+
+ DmaFill32(3, 0, VRAM, VRAM_SIZE);
+ DmaFill32(3, 0, OAM, OAM_SIZE);
+ DmaFill32(3, 0, PLTT, PLTT_SIZE);
+ ResetBgsAndClearDma3BusyFlags(0);
+
+ InitBgsFromTemplates(0, gUnknown_08618108, ARRAY_COUNT(gUnknown_08618108));
+ ChangeBgX(0, 0, 0);
+ ChangeBgY(0, 0, 0);
+ ChangeBgX(1, 0, 0);
+ ChangeBgY(1, 0, 0);
+ InitWindows(gUnknown_08618110);
+ DeactivateAllTextPrinters();
+
+ DmaCopy32(3, gUnknown_08618138, BG_PLTT + 0x1E0, 0x20);
+ SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP);
+ FillWindowPixelBuffer(2, 0);
+ FillWindowPixelBuffer(3, 0);
+ FillWindowPixelBuffer(0, 0xAA);
+
+// This block is a meme among memes
+ width = (0x78 - GetStringWidth(0, gUnknown_08617E9B, 0)) / 2;
+ box_print(2, 0, width, 3, gUnknown_0861815B, -1, gUnknown_08617E9B);
+ width = (s32)(0x78 - GetStringWidth(0, gUnknown_08617E9B, 0)) / 2 + 0x78;
+ box_print(2, 0, width, 3, gUnknown_0861815B, -1, gUnknown_08617E8D);
+ width = (0x70 - GetStringWidth(0, gUnknown_08617E8D, 0)) / 2;
+ box_print(3, 0, width, 0, gUnknown_0861815B, -1, gUnknown_08617E8D);
+ width = (0xd0 - GetStringWidth(1, gUnknown_08617E78, 0)) / 2;
+ box_print(0, 1, width, 2, gUnknown_08618158, -1, gUnknown_08617E78);
+
+ CopyWindowToVram(2, 2);
+ CopyWindowToVram(3, 2);
+ CopyWindowToVram(0, 2);
+}
+
+#else
+__attribute__((naked)) static void berry_fix_gpu_set(void)
+{
+ asm(".syntax unified\n"
+ "\tpush {r4-r6,lr}\n"
+ "\tmov r6, r8\n"
+ "\tpush {r6}\n"
+ "\tsub sp, 0x10\n"
+ "\tmovs r0, 0x8\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0xA\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x10\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x12\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x14\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x16\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x50\n"
+ "\tmovs r1, 0\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r1, 0\n"
+ "\tstr r1, [sp, 0xC]\n"
+ "\tldr r4, =0x040000d4\n"
+ "\tadd r0, sp, 0xC\n"
+ "\tstr r0, [r4]\n"
+ "\tmovs r0, 0xC0\n"
+ "\tlsls r0, 19\n"
+ "\tstr r0, [r4, 0x4]\n"
+ "\tldr r0, =0x85006000\n"
+ "\tstr r0, [r4, 0x8]\n"
+ "\tldr r0, [r4, 0x8]\n"
+ "\tstr r1, [sp, 0xC]\n"
+ "\tadd r0, sp, 0xC\n"
+ "\tstr r0, [r4]\n"
+ "\tmovs r0, 0xE0\n"
+ "\tlsls r0, 19\n"
+ "\tstr r0, [r4, 0x4]\n"
+ "\tldr r2, =0x85000100\n"
+ "\tstr r2, [r4, 0x8]\n"
+ "\tldr r0, [r4, 0x8]\n"
+ "\tstr r1, [sp, 0xC]\n"
+ "\tadd r0, sp, 0xC\n"
+ "\tstr r0, [r4]\n"
+ "\tmovs r0, 0xA0\n"
+ "\tlsls r0, 19\n"
+ "\tstr r0, [r4, 0x4]\n"
+ "\tstr r2, [r4, 0x8]\n"
+ "\tldr r0, [r4, 0x8]\n"
+ "\tmovs r0, 0\n"
+ "\tbl ResetBgsAndClearDma3BusyFlags\n"
+ "\tldr r1, =gUnknown_08618108\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r2, 0x2\n"
+ "\tbl InitBgsFromTemplates\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl ChangeBgX\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl ChangeBgY\n"
+ "\tmovs r0, 0x1\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl ChangeBgX\n"
+ "\tmovs r0, 0x1\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl ChangeBgY\n"
+ "\tldr r0, =gUnknown_08618110\n"
+ "\tbl InitWindows\n"
+ "\tbl DeactivateAllTextPrinters\n"
+ "\tldr r0, =gUnknown_08618138\n"
+ "\tstr r0, [r4]\n"
+ "\tldr r0, =0x050001e0\n"
+ "\tstr r0, [r4, 0x4]\n"
+ "\tldr r0, =0x84000008\n"
+ "\tstr r0, [r4, 0x8]\n"
+ "\tldr r0, [r4, 0x8]\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0x40\n"
+ "\tbl SetGpuReg\n"
+ "\tmovs r0, 0x2\n"
+ "\tmovs r1, 0\n"
+ "\tbl FillWindowPixelBuffer\n"
+ "\tmovs r0, 0x3\n"
+ "\tmovs r1, 0\n"
+ "\tbl FillWindowPixelBuffer\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0xAA\n"
+ "\tbl FillWindowPixelBuffer\n"
+ "\tldr r5, =gUnknown_08617E9B\n"
+ "\tmovs r0, 0\n"
+ "\tadds r1, r5, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl GetStringWidth\n"
+ "\tadds r1, r0, 0\n"
+ "\tmovs r4, 0x78\n"
+ "\tsubs r0, r4, r1\n"
+ "\tlsrs r1, r0, 31\n"
+ "\tadds r0, r1\n"
+ "\tasrs r0, 1\n"
+ "\tlsls r2, r0, 24\n"
+ "\tlsrs r2, 24\n"
+ "\tldr r6, =gUnknown_0861815B\n"
+ "\tstr r6, [sp]\n"
+ "\tmovs r0, 0x1\n"
+ "\tnegs r0, r0\n"
+ "\tmov r8, r0\n"
+ "\tstr r0, [sp, 0x4]\n"
+ "\tstr r5, [sp, 0x8]\n"
+ "\tmovs r0, 0x2\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r3, 0x3\n"
+ "\tbl box_print\n"
+ "\tldr r5, =gUnknown_08617E8D\n"
+ "\tmovs r0, 0\n"
+ "\tadds r1, r5, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl GetStringWidth\n"
+ "\tadds r1, r0, 0\n"
+ "\tsubs r4, r1\n"
+ "\tlsrs r0, r4, 31\n"
+ "\tadds r4, r0\n"
+ "\tasrs r4, 1\n"
+ "\tadds r0, r4, 0\n"
+ "\tadds r0, 0x78\n"
+ "\tlsls r2, r0, 24\n"
+ "\tlsrs r2, 24\n"
+ "\tstr r6, [sp]\n"
+ "\tmov r0, r8\n"
+ "\tstr r0, [sp, 0x4]\n"
+ "\tstr r5, [sp, 0x8]\n"
+ "\tmovs r0, 0x2\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r3, 0x3\n"
+ "\tbl box_print\n"
+ "\tmovs r0, 0\n"
+ "\tadds r1, r5, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl GetStringWidth\n"
+ "\tadds r1, r0, 0\n"
+ "\tmovs r0, 0x70\n"
+ "\tsubs r0, r1\n"
+ "\tlsrs r1, r0, 31\n"
+ "\tadds r0, r1\n"
+ "\tasrs r0, 1\n"
+ "\tlsls r2, r0, 24\n"
+ "\tlsrs r2, 24\n"
+ "\tstr r6, [sp]\n"
+ "\tmov r0, r8\n"
+ "\tstr r0, [sp, 0x4]\n"
+ "\tstr r5, [sp, 0x8]\n"
+ "\tmovs r0, 0x3\n"
+ "\tmovs r1, 0\n"
+ "\tmovs r3, 0\n"
+ "\tbl box_print\n"
+ "\tldr r4, =gUnknown_08617E78\n"
+ "\tmovs r0, 0x1\n"
+ "\tadds r1, r4, 0\n"
+ "\tmovs r2, 0\n"
+ "\tbl GetStringWidth\n"
+ "\tadds r1, r0, 0\n"
+ "\tmovs r0, 0xD0\n"
+ "\tsubs r0, r1\n"
+ "\tlsrs r1, r0, 31\n"
+ "\tadds r0, r1\n"
+ "\tasrs r0, 1\n"
+ "\tlsls r2, r0, 24\n"
+ "\tlsrs r2, 24\n"
+ "\tldr r0, =gUnknown_08618158\n"
+ "\tstr r0, [sp]\n"
+ "\tmov r0, r8\n"
+ "\tstr r0, [sp, 0x4]\n"
+ "\tstr r4, [sp, 0x8]\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0x1\n"
+ "\tmovs r3, 0x2\n"
+ "\tbl box_print\n"
+ "\tmovs r0, 0x2\n"
+ "\tmovs r1, 0x2\n"
+ "\tbl CopyWindowToVram\n"
+ "\tmovs r0, 0x3\n"
+ "\tmovs r1, 0x2\n"
+ "\tbl CopyWindowToVram\n"
+ "\tmovs r0, 0\n"
+ "\tmovs r1, 0x2\n"
+ "\tbl CopyWindowToVram\n"
+ "\tadd sp, 0x10\n"
+ "\tpop {r3}\n"
+ "\tmov r8, r3\n"
+ "\tpop {r4-r6}\n"
+ "\tpop {r0}\n"
+ "\tbx r0\n"
+ "\t.pool\n"
+ ".syntax divided");
+}
+#endif
+
+static int berry_fix_text_update(int checkval)
+{
+ if (berry_fix_mb_manager->unk1 == checkval)
+ {
+ return checkval;
+ }
+ if (berry_fix_mb_manager->unk1 == 6)
+ {
+ berry_fix_text_print(checkval);
+ berry_fix_mb_manager->unk1 = checkval;
+ }
+ else
+ {
+ berry_fix_bg_hide();
+ berry_fix_mb_manager->unk1 = 6;
+ }
+ return berry_fix_mb_manager->unk1;
+}
+
+static void berry_fix_text_print(int scene)
+{
+ FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32);
+ FillWindowPixelBuffer(1, 0xAA);
+ box_print(1, 1, 0, 0, gUnknown_08618158, -1, gUnknown_08618160[scene]);
+ PutWindowTilemap(1);
+ CopyWindowToVram(1, 2);
+ switch (scene)
+ {
+ case 0:
+ case 2:
+ case 3:
+ case 4:
+ PutWindowTilemap(2);
+ break;
+ case 1:
+ PutWindowTilemap(3);
+ break;
+ case 5:
+ PutWindowTilemap(0);
+ break;
+ }
+ CopyBgTilemapBufferToVram(0);
+ LZ77UnCompVram(gUnknown_08618178[scene][0], (void *)BG_CHAR_ADDR(1));
+ LZ77UnCompVram(gUnknown_08618178[scene][1], (void *)BG_SCREEN_ADDR(31));
+ CpuCopy32(gUnknown_08618178[scene][2], (void *)BG_PLTT, 0x100);
+ ShowBg(0);
+ ShowBg(1);
+}
+
+static void berry_fix_bg_hide()
+{
+ HideBg(0);
+ HideBg(1);
+}
diff --git a/src/bg.c b/src/bg.c
index 8979eaecd..390a99d50 100644
--- a/src/bg.c
+++ b/src/bg.c
@@ -1,5 +1,6 @@
#include "global.h"
#include "dma3.h"
+#include "bg.h"
#define DISPCNT_ALL_BG_AND_MODE_BITS 0x0F07
@@ -22,33 +23,23 @@ struct BgControl {
u16 priority:2;
u16 mosaic:1;
u16 wraparound:1;
-
+
u16 charBaseIndex:2;
u16 mapBaseIndex:5;
u16 paletteMode:1;
-
+
u8 unknown_2;
u8 unknown_3;
} configs[4];
-
- u16 bgVisibilityAndMode;
-};
-struct BgTemplate {
- u32 bg:2;
- u32 charBaseIndex:2;
- u32 mapBaseIndex:5;
- u32 screenSize:2;
- u32 paletteMode:1;
- u32 priority:2;
- u32 baseTile:10;
+ u16 bgVisibilityAndMode;
};
struct BgConfig2 {
u32 baseTile:10;
u32 basePalette:4;
u32 unk_3:18;
-
+
void* tilemap;
u32 bg_x;
u32 bg_y;
@@ -103,7 +94,7 @@ void ResetBgControlStructs(void)
struct BgConfig* bgConfigs = &gGpuBgConfigs.configs[0];
struct BgConfig zeroedConfig = gZeroedBgControlStruct;
int i;
-
+
for (i = 0; i < 4; i++)
{
bgConfigs[i] = zeroedConfig;
@@ -126,40 +117,40 @@ void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenS
{
gGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3;
}
-
+
if (mapBaseIndex != 0xFF)
{
gGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F;
}
-
+
if (screenSize != 0xFF)
{
gGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3;
}
-
+
if (paletteMode != 0xFF)
{
gGpuBgConfigs.configs[bg].paletteMode = paletteMode;
}
-
+
if (priority != 0xFF)
{
gGpuBgConfigs.configs[bg].priority = priority & 0x3;
}
-
+
if (mosaic != 0xFF)
{
gGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1;
}
-
+
if (wraparound != 0xFF)
{
gGpuBgConfigs.configs[bg].wraparound = wraparound;
}
-
+
gGpuBgConfigs.configs[bg].unknown_2 = 0;
gGpuBgConfigs.configs[bg].unknown_3 = 0;
-
+
gGpuBgConfigs.configs[bg].visible = 1;
}
}
@@ -188,7 +179,7 @@ u16 GetBgControlAttribute(u8 bg, u8 attributeId)
return gGpuBgConfigs.configs[bg].wraparound;
}
}
-
+
return 0xFF;
}
@@ -196,7 +187,7 @@ u8 LoadBgVram(u8 bg, void *src, u16 size, u16 destOffset, u8 mode)
{
u16 offset;
s8 cursor;
-
+
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
{
switch (mode)
@@ -211,11 +202,11 @@ u8 LoadBgVram(u8 bg, void *src, u16 size, u16 destOffset, u8 mode)
cursor = -1;
goto end;
}
-
+
offset = destOffset + offset;
-
+
cursor = RequestDma3Copy(src, (void*)(offset + BG_VRAM), size, 0);
-
+
if (cursor == -1)
{
return -1;
@@ -225,7 +216,7 @@ u8 LoadBgVram(u8 bg, void *src, u16 size, u16 destOffset, u8 mode)
{
return -1;
}
-
+
end:
return cursor;
}
@@ -242,9 +233,9 @@ void ShowBgInternal(u8 bg)
(gGpuBgConfigs.configs[bg].mapBaseIndex << 8) |
(gGpuBgConfigs.configs[bg].wraparound << 13) |
(gGpuBgConfigs.configs[bg].screenSize << 14);
-
+
SetGpuReg((bg << 1) + 0x8, value);
-
+
gGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8);
gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
}
@@ -273,7 +264,7 @@ void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX,
{
struct BgAffineSrcData src;
struct BgAffineDstData dest;
-
+
switch (gGpuBgConfigs.bgVisibilityAndMode & 0x7)
{
case 1:
@@ -288,7 +279,7 @@ void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX,
default:
return;
}
-
+
src.texX = srcCenterX;
src.texY = srcCenterY;
src.scrX = dispCenterX;
@@ -296,7 +287,7 @@ void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX,
src.sx = scaleX;
src.sy = scaleY;
src.alpha = rotationAngle;
-
+
BgAffineSet(&src, &dest, 1);
SetGpuReg(REG_OFFSET_BG2PA, dest.pa);
@@ -326,20 +317,20 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
{
int i;
ResetBgs();
-
+
for (i = 0; i < 4; i++)
{
gDmaBusyBitfield[i] = 0;
}
-
+
gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
}
-void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplates)
+void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates)
{
int i;
u8 bg;
-
+
SetBgModeInternal(bgMode);
ResetBgControlStructs();
@@ -355,11 +346,11 @@ void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplat
templates[i].priority,
0,
0);
-
+
gGpuBgConfigs2[bg].baseTile = templates[i].baseTile;
gGpuBgConfigs2[bg].basePalette = 0;
gGpuBgConfigs2[bg].unk_3 = 0;
-
+
gGpuBgConfigs2[bg].tilemap = NULL;
gGpuBgConfigs2[bg].bg_x = 0;
gGpuBgConfigs2[bg].bg_y = 0;
@@ -367,10 +358,10 @@ void InitBgsFromTemplates(u8 bgMode, struct BgTemplate *templates, u8 numTemplat
}
}
-void InitBgFromTemplate(struct BgTemplate *template)
+void InitBgFromTemplate(const struct BgTemplate *template)
{
u8 bg = template->bg;
-
+
if (bg < 4)
{
SetBgControlAttributes(bg,
@@ -381,11 +372,11 @@ void InitBgFromTemplate(struct BgTemplate *template)
template->priority,
0,
0);
-
+
gGpuBgConfigs2[bg].baseTile = template->baseTile;
gGpuBgConfigs2[bg].basePalette = 0;
gGpuBgConfigs2[bg].unk_3 = 0;
-
+
gGpuBgConfigs2[bg].tilemap = NULL;
gGpuBgConfigs2[bg].bg_x = 0;
gGpuBgConfigs2[bg].bg_y = 0;
@@ -401,7 +392,7 @@ u16 LoadBgTiles(u8 bg, void* src, u16 size, u16 destOffset)
{
u16 tileOffset;
u8 cursor;
-
+
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE) == 0)
{
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x20;
@@ -410,37 +401,37 @@ u16 LoadBgTiles(u8 bg, void* src, u16 size, u16 destOffset)
{
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x40;
}
-
+
cursor = LoadBgVram(bg, src, size, tileOffset, DISPCNT_MODE_1);
-
+
if (cursor == 0xFF)
{
return -1;
}
-
+
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
-
+
if (gUnneededFireRedVariable == 1)
{
DummiedOutFireRedLeafGreenTileAllocFunc(bg, tileOffset / 0x20, size / 0x20, 1);
}
-
+
return cursor;
}
u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset)
{
u8 cursor;
-
+
cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2);
-
+
if (cursor == 0xFF)
{
return -1;
}
-
+
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
-
+
return cursor;
}
@@ -448,12 +439,12 @@ u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset)
{
u16 paletteOffset;
s8 cursor;
-
+
if (IsInvalidBg32(bg) == FALSE)
{
paletteOffset = (gGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2);
cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0);
-
+
if (cursor == -1)
{
return -1;
@@ -475,14 +466,14 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
u8 mod;
u8 div;
s8 reqSpace;
-
+
int i;
-
+
for (i = 0; i < 0x80; i++)
{
div = i / 0x20;
mod = i % 0x20;
-
+
if ((gDmaBusyBitfield[div] & (1 << mod)) != FALSE)
{
reqSpace = CheckForSpaceForDma3Request(i);
@@ -490,7 +481,7 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
{
return TRUE;
}
-
+
gDmaBusyBitfield[div] &= ~(1 << mod);
}
}
@@ -634,12 +625,12 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
u8 mode;
u16 temp1;
u16 temp2;
-
+
if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
{
return -1;
}
-
+
switch (op)
{
case 0:
@@ -653,9 +644,9 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
gGpuBgConfigs2[bg].bg_x -= value;
break;
}
-
+
mode = GetBgMode();
-
+
switch (bg)
{
case 0:
@@ -695,7 +686,7 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
}
break;
}
-
+
return gGpuBgConfigs2[bg].bg_x;
}
@@ -713,12 +704,12 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
u8 mode;
u16 temp1;
u16 temp2;
-
+
if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
{
return -1;
}
-
+
switch (op)
{
case 0:
@@ -732,9 +723,9 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
gGpuBgConfigs2[bg].bg_y -= value;
break;
}
-
+
mode = GetBgMode();
-
+
switch (bg)
{
case 0:
@@ -774,7 +765,7 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
}
break;
}
-
+
return gGpuBgConfigs2[bg].bg_y;
}
@@ -783,12 +774,12 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
u8 mode;
u16 temp1;
u16 temp2;
-
+
if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
{
return -1;
}
-
+
switch (op)
{
case 0:
@@ -802,9 +793,9 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
gGpuBgConfigs2[bg].bg_y -= value;
break;
}
-
+
mode = GetBgMode();
-
+
switch (bg)
{
case 0:
@@ -820,7 +811,7 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
{
temp1 = gGpuBgConfigs2[2].bg_y >> 0x8;
SetGpuReg_ForcedBlank(REG_OFFSET_BG2VOFS, temp1);
-
+
}
else
{
@@ -845,7 +836,7 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
}
break;
}
-
+
return gGpuBgConfigs2[bg].bg_y;
}
@@ -868,13 +859,13 @@ u8 Unused_AdjustBgMosaic(u8 a1, u8 a2)
u16 result;
s16 test1;
s16 test2;
-
+
result = GetGpuReg(REG_OFFSET_MOSAIC);
-
+
test1 = result & 0xF;
test2 = (result >> 4) & 0xF;
result &= 0xFF00;
-
+
switch (a2)
{
case 0:
@@ -929,12 +920,12 @@ u8 Unused_AdjustBgMosaic(u8 a1, u8 a2)
}
break;
}
-
+
result |= ((test2 << 0x4) & 0xF0);
result |= (test1 & 0xF);
-
+
SetGpuReg(REG_OFFSET_MOSAIC, result);
-
+
return result;
}
@@ -981,7 +972,7 @@ void CopyToBgTilemapBuffer(u8 bg, void *src, u16 mode, u16 destOffset)
void CopyBgTilemapBufferToVram(u8 bg)
{
u16 sizeToLoad;
-
+
if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE)
{
switch (GetBgType(bg))
@@ -1006,7 +997,7 @@ void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u
u16 destX16;
u16 destY16;
u16 mode;
-
+
if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE)
{
switch (GetBgType(bg))
@@ -1047,11 +1038,11 @@ void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWid
u16 attribute;
u16 mode;
u16 mode2;
-
+
void* srcCopy;
u16 destX16;
u16 destY16;
-
+
if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE)
{
attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE);
@@ -1336,7 +1327,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
u16 x16;
u16 y16;
u16 mode;
-
+
if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE)
{
switch (GetBgType(bg))
@@ -1375,10 +1366,10 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
u16 mode2;
u16 attribute;
u16 mode3;
-
+
u16 x16;
u16 y16;
-
+
if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE)
{
attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE);
@@ -1414,9 +1405,9 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
u16 GetBgMetricTextMode(u8 bg, u8 whichMetric)
{
u8 attribute;
-
+
attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE);
-
+
switch (whichMetric)
{
case 0:
@@ -1462,9 +1453,9 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric)
u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric)
{
u8 attribute;
-
+
attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE);
-
+
switch (whichMetric)
{
case 0:
@@ -1491,7 +1482,7 @@ u32 GetTileMapIndexFromCoords(s32 x, s32 y, s32 screenSize, u32 screenWidth, u32
{
x = x & (screenWidth - 1);
y = y & (screenHeight - 1);
-
+
switch (screenSize)
{
case 0:
@@ -1526,7 +1517,7 @@ void CopyTileMapEntry(u16 *src, u16 *dest, s32 palette1, u32 tileOffset, u32 pal
test = ((*dest & 0xFC00) + (palette2 << 12)) | ((*src + tileOffset) & 0x3FF);
break;
}
-
+
*dest = test;
}
#else
@@ -1586,10 +1577,10 @@ _08002B3C:\n\
u32 GetBgType(u8 bg)
{
u8 mode;
-
+
mode = GetBgMode();
-
-
+
+
switch (bg)
{
case 0:
@@ -1621,7 +1612,7 @@ u32 GetBgType(u8 bg)
}
break;
}
-
+
return 0xFFFF;
}
diff --git a/src/multiboot.c b/src/multiboot.c
index 80291ff46..7fd6df2d0 100644
--- a/src/multiboot.c
+++ b/src/multiboot.c
@@ -316,7 +316,7 @@ void MultiBootStartProbe(struct MultiBootParam *mp)
mp->probe_count = 1;
}
-void MultiBootStartMaster(struct MultiBootParam *mp, u8 *srcp, int length, u8 palette_color, s8 palette_speed)
+void MultiBootStartMaster(struct MultiBootParam *mp, const u8 *srcp, int length, u8 palette_color, s8 palette_speed)
{
int i = 0;
diff --git a/src/text.c b/src/text.c
index cad8326e3..aa4e201c0 100644
--- a/src/text.c
+++ b/src/text.c
@@ -2779,7 +2779,7 @@ _08005D6E:\n\
bx r1");
}
-u32 GetStringWidthFixedWidthFont(u8 *str, u8 fontId, u8 letterSpacing)
+u32 GetStringWidthFixedWidthFont(const u8 *str, u8 fontId, u8 letterSpacing)
{
int i;
u8 width;
@@ -2788,7 +2788,7 @@ u32 GetStringWidthFixedWidthFont(u8 *str, u8 fontId, u8 letterSpacing)
u8 line;
int strPos;
u8 lineWidths[8];
- u8 *strLocal;
+ const u8 *strLocal;
for (i = 0; i < 8; i++)
{
@@ -2883,7 +2883,7 @@ u32 (*GetFontWidthFunc(u8 glyphId))(u16, bool32)
return 0;
}
-s32 GetStringWidth(u8 fontId, u8 *str, s16 letterSpacing)
+u32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing)
{
bool8 isJapanese;
int minGlyphWidth;
diff --git a/src/window.c b/src/window.c
index 574b13aa0..164031bee 100644
--- a/src/window.c
+++ b/src/window.c
@@ -35,7 +35,7 @@ static void nullsub_8(void)
}
-bool16 InitWindows(struct WindowTemplate *templates)
+bool16 InitWindows(const struct WindowTemplate *templates)
{
int i;
void *bgTilemapBuffer;