Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 3 additions & 88 deletions chao_garden/asm/code.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,99 +4,14 @@
.syntax unified
.arm

thumb_func_start sub_0200019c
sub_0200019c: @ 0x0200019c
push {r4, lr}
ldr r0, _020001E0 @ =IntrMain
ldr r4, _020001E4 @ =0x03000000
ldr r2, _020001E8 @ =0x04000020
adds r1, r4, #0
bl CpuSet
ldr r0, _020001EC @ =0x03007FFC
str r4, [r0]
ldr r1, _020001F0 @ =gIntrTable
ldr r2, _020001F4 @ =sub_02000244
adds r0, r1, #0
adds r0, #0xc
_020001B6:
str r2, [r0]
subs r0, #4
cmp r0, r1
bge _020001B6
ldr r2, _020001F8 @ =0x04000200
movs r0, #1
strh r0, [r2]
ldr r0, _020001FC @ =0x080000B2
ldrb r0, [r0]
cmp r0, #0x96
bne _02000204
ldrh r0, [r2]
movs r3, #0x80
lsls r3, r3, #6
adds r1, r3, #0
orrs r0, r1
strh r0, [r2]
ldr r0, _02000200 @ =gUnknown_03003B70
strh r1, [r0]
b _0200020A
.align 2, 0
_020001E0: .4byte IntrMain
_020001E4: .4byte 0x03000000
_020001E8: .4byte 0x04000020
_020001EC: .4byte 0x03007FFC
_020001F0: .4byte gIntrTable
_020001F4: .4byte sub_02000244
_020001F8: .4byte 0x04000200
_020001FC: .4byte 0x080000B2
_02000200: .4byte gUnknown_03003B70
_02000204:
ldr r1, _0200021C @ =gUnknown_03003B70
movs r0, #0
strh r0, [r1]
_0200020A:
ldr r1, _02000220 @ =0x04000004
movs r0, #8
strh r0, [r1]
ldr r1, _02000224 @ =0x04000208
movs r0, #1
strh r0, [r1]
pop {r4}
pop {r0}
bx r0
.align 2, 0
_0200021C: .4byte gUnknown_03003B70
_02000220: .4byte 0x04000004
_02000224: .4byte 0x04000208

thumb_func_start sub_02000228
sub_02000228: @ 0x02000228
push {lr}
adds r1, r0, #0
cmp r1, #0
bne _02000232
ldr r1, _0200023C @ =sub_02000244
_02000232:
ldr r0, _02000240 @ =gIntrTable
str r1, [r0, #4]
pop {r0}
bx r0
.align 2, 0
_0200023C: .4byte sub_02000244
_02000240: .4byte gIntrTable

thumb_func_start sub_02000244
sub_02000244: @ 0x02000244
bx lr
.align 2, 0

thumb_func_start sub_02000248
sub_02000248: @ 0x02000248
push {r4, r5, r6, r7, lr}
mov r7, sb
mov r6, r8
push {r6, r7}
bl IdentifyFlash
ldr r1, _020002A8 @ =gUnknown_03003B68
ldr r1, _020002A8 @ =gIntrTable+2*4
movs r0, #2
bl SetFlashTimerIntr
movs r6, #0
Expand Down Expand Up @@ -136,7 +51,7 @@ _0200026C:
ldr r6, [r4, #4]
b _020002C8
.align 2, 0
_020002A8: .4byte gUnknown_03003B68
_020002A8: .4byte gIntrTable+2*4
_020002AC: .4byte gUnknown_03003B80
_020002B0: .4byte 0x00001965
_020002B4: .4byte 0x00000858
Expand Down Expand Up @@ -2965,7 +2880,7 @@ sub_020018a0: @ 0x020018a0
push {lr}
bl m4aSoundInit
ldr r0, _020018B0 @ =sub_020018B4
bl sub_02000228
bl SetVBlankIntr
pop {r0}
bx r0
.align 2, 0
Expand Down
1 change: 1 addition & 0 deletions chao_garden/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define GUARD_FUNCTIONS_H

void IntrMain(void);
void IntrDummy(void);

#endif // GUARD_FUNCTIONS_H
2 changes: 2 additions & 0 deletions chao_garden/include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@

#define SYSTEM_CLOCK (16 * 1024 * 1024) // System Clock

#define ROM_BASE 0x08000000

#endif // GUARD_GBA_DEFINES
5 changes: 5 additions & 0 deletions chao_garden/include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@
// with for the calculation
#define GBA_FRAMES_PER_SECOND 60

// TODO: Find better place for this
typedef void (*HBlankFunc)(u8 vcount);
typedef void (*IntrFunc)(void);
typedef u32 (*SpriteUpdateFunc)(void);

#endif // GUARD_GLOBAL_H
1 change: 1 addition & 0 deletions chao_garden/ldscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SECTIONS {
build/mb_chao_garden/asm/rom_header.o(.text);
build/mb_chao_garden/asm/crt0.o(.text);
build/mb_chao_garden/src/main.o(.text);
build/mb_chao_garden/src/init.o(.text);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw can be init.c but it's likely this was just part of main.c? Are these called from any other location?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only assuming based on the interrupt stuff being setup as part of main.c in the base rom

Copy link
Copy Markdown
Collaborator Author

@JaceCear JaceCear Nov 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently sub_0200019c gets only called by main, but sub_02000228 is referenced by code.s!

Can push sub_0200019c to main if you prefer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably part of main.c for now

build/mb_chao_garden/asm/code.o(.text);
build/mb_chao_garden/asm/m4a0.o(.text);
build/mb_chao_garden/src/m4a.o(.text);
Expand Down
22 changes: 22 additions & 0 deletions chao_garden/src/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "global.h"
#include "agb_flash.h"
#include "m4a.h"

extern IntrFunc gIntrTable[4];

// TCG = Tiny Chao Garden
struct TCG_SaveSectorHeader {
u32 security, version;
};

struct TCG_SaveSectorData {
struct TCG_SaveSectorHeader header;

u8 padding_8[0x850];
}; /* size:0x858 according to sub_02000248 */

// TCG = Tiny Chao Garden
#define TCG_FIRST_SAVE_SECTOR 10
#define TCG_SAVE_SECTOR_COUNT 6

extern struct TCG_SaveSectorData gUnknown_03003B80;
50 changes: 50 additions & 0 deletions chao_garden/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ struct UNK_03003330 {
u8 unk10;
};

#define GBA_ROM_HEADER_FIXED_VALUE_ADDR ((vu8 *)(ROM_BASE + 0xB2))
#define FIXED_HEADER_VALUE 0x96

extern u8 IntrMain_RAM[0x80];
extern IntrFunc gIntrTable[4];
extern u16 gUnknown_03003B70;

extern struct GameConfig gUnknown_02000008;
extern struct UNK_03003330 gUnknown_03003330;

Expand Down Expand Up @@ -84,3 +91,46 @@ void AgbMain()
gUnknown_03003330.unkE = 1;
}
}

void sub_0200019c(void)
{
IntrFunc *base, *table, dummy;

// Init IntrMain_RAM
CpuCopy32(IntrMain, IntrMain_RAM, sizeof(IntrMain_RAM));
INTR_VECTOR = IntrMain_RAM;

// Init IntrTable
base = gIntrTable;
dummy = &IntrDummy;
table = &base[3];
do {
*table = dummy;
} while ((s32)--table >= (s32)base);

REG_IE = INTR_FLAG_VBLANK;

if (*GBA_ROM_HEADER_FIXED_VALUE_ADDR == FIXED_HEADER_VALUE) {
REG_IE |= INTR_FLAG_GAMEPAK;
gUnknown_03003B70 = INTR_FLAG_GAMEPAK;
} else {
gUnknown_03003B70 = 0;
}

REG_DISPSTAT = DISPSTAT_VBLANK_INTR;
REG_IME = INTR_FLAG_VBLANK;
}

void SetVBlankIntr(IntrFunc func)
{
IntrFunc toInsert;

if (func == NULL)
toInsert = &IntrDummy;
else
toInsert = func;

gIntrTable[1] = toInsert;
}

void IntrDummy(void) { }
3 changes: 1 addition & 2 deletions chao_garden/sym_iwram.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
. = 0x00000000; gUnknown_03000000 = .;
. = 0x00000000; IntrMain_RAM = .;
. = 0x00000080; gUnknown_03000080 = .;
. = 0x00000084; gUnknown_03000084 = .;
. = 0x00000088; gUnknown_03000088 = .;
Expand Down Expand Up @@ -161,7 +161,6 @@
. = 0x00003330; gUnknown_03003330 = .;
. = 0x00003350; gUnknown_03003350 = .;
. = 0x00003B60; gIntrTable = .;
. = 0x00003B68; gUnknown_03003B68 = .;
. = 0x00003B70; gUnknown_03003B70 = .;
. = 0x00003B80; gUnknown_03003B80 = .;
. = 0x00003B88; gUnknown_03003B88 = .;
Expand Down