make VBlankIntr() match

This commit is contained in:
YamaArashi 2017-02-17 10:52:03 -08:00
parent afd45e9dd4
commit a60e850a86
3 changed files with 21 additions and 129 deletions

View File

@ -1,3 +1,4 @@
.include "constants/gba_constants.inc"
.include "asm/macros.inc"
.syntax unified
@ -87,10 +88,10 @@ RegisterRamReset: @ 82E70A8
thumb_func_start SoftReset
@ void SoftReset()
SoftReset: @ 82E70AC
ldr r3, =0x04000208
ldr r3, =REG_IME
movs r2, 0
strb r2, [r3]
ldr r1, =gUnknown_03007F00
ldr r1, =0x3007F00
mov sp, r1
swi 0x1
swi 0

View File

@ -16,10 +16,9 @@ extern u8 gHeap[];
extern struct SaveBlock2 gUnknown_02024A54;
extern char *gUnknown_03005D94;
extern char gUnknown_02029808[];
extern u16 gIntrCheck;
extern u32 gBattleTypeFlags;
extern u8 gUnknown_03002748;
//extern u32 gUnknown_0203CF5C;
extern u32 *gUnknown_0203CF5C;
void Timer3Intr(void);
bool8 HandleLinkConnection(void);
@ -157,17 +156,10 @@ static void UpdateLinkAndCallCallbacks(void)
CallCallbacks();
}
struct gUnknown_0203CF5C_Struct
{
u32 value;
};
extern struct gUnknown_0203CF5C_Struct gUnknown_0203CF5C;
static void InitMainCallbacks(void)
{
gMain.vblankCounter1 = 0;
gUnknown_0203CF5C.value = 0;
gUnknown_0203CF5C = NULL;
gMain.vblankCounter2 = 0;
gMain.callback1 = NULL;
SetMainCallback2(c2_copyright_1);
@ -220,7 +212,7 @@ void InitKeys(void)
{
gKeyRepeatContinueDelay = 5;
gKeyRepeatStartDelay = 40;
gMain.heldKeys = 0;
gMain.newKeys = 0;
gMain.newAndRepeatedKeys = 0;
@ -288,7 +280,7 @@ void InitIntrHandlers(void)
SetSerialCallback(NULL);
REG_IME = 1;
EnableInterrupts(0x1);
}
@ -321,25 +313,23 @@ void SetSerialCallback(IntrCallback callback)
extern void CopyBufferedValuesToGpuRegs(void);
extern void ProcessDma3Requests(void);
#ifdef NONMATCHING
static void VBlankIntr(void)
{
if (gLinkVSyncDisabled != FALSE)
LinkVSync();
else if(gUnknown_03002748 == FALSE)
else if (gUnknown_03002748 == FALSE)
sub_800B9B8();
gMain.vblankCounter1++; // in the original asm, gMain is put into r0 for this addition and then preserved in r4 after it. the compiler wants to skip that and put it in either r4 or r1.
gMain.vblankCounter1++;
if (gUnknown_0203CF5C && *gUnknown_0203CF5C < 0xFFFFFFFF)
(*gUnknown_0203CF5C)++;
if(gUnknown_0203CF5C.value > 0)
if(gUnknown_0203CF5C.value < 0xFFFFFFFF)
gUnknown_0203CF5C.value++;
if (gMain.vblankCallback)
gMain.vblankCallback();
gMain.vblankCounter2++;
CopyBufferedValuesToGpuRegs();
ProcessDma3Requests();
@ -348,101 +338,14 @@ static void VBlankIntr(void)
m4aSoundMain();
sub_8033648();
if(!gMain.inBattle || (gBattleTypeFlags & 0x013F0102) == 0)
if (!gMain.inBattle || (gBattleTypeFlags & 0x013F0102) == 0)
Random();
sub_800E174();
gIntrCheck |= INTR_FLAG_VBLANK;
INTR_CHECK |= INTR_FLAG_VBLANK;
gMain.intrCheck |= INTR_FLAG_VBLANK;
}
#else
__attribute__((naked))
static void VBlankIntr(void)
{
asm(".syntax unified\n\
push {r4,lr}\n\
ldr r0, =gLinkVSyncDisabled\n\
ldrb r0, [r0]\n\
cmp r0, 0\n\
beq _0800074C\n\
bl LinkVSync\n\
b _08000758\n\
.pool\n\
_0800074C:\n\
ldr r0, =gUnknown_03002748\n\
ldrb r0, [r0]\n\
cmp r0, 0\n\
bne _08000758\n\
bl sub_800B9B8\n\
_08000758:\n\
ldr r0, =gMain\n\
ldr r1, [r0, 0x20]\n\
adds r1, 0x1\n\
str r1, [r0, 0x20]\n\
ldr r1, =gUnknown_0203CF5C\n\
ldr r1, [r1]\n\
adds r4, r0, 0\n\
cmp r1, 0\n\
beq _08000778\n\
ldr r2, [r1]\n\
movs r0, 0x2\n\
negs r0, r0\n\
cmp r2, r0\n\
bhi _08000778\n\
adds r0, r2, 0x1\n\
str r0, [r1]\n\
_08000778:\n\
ldr r0, [r4, 0xC]\n\
cmp r0, 0\n\
beq _08000782\n\
bl _call_via_r0\n\
_08000782:\n\
ldr r0, [r4, 0x24]\n\
adds r0, 0x1\n\
str r0, [r4, 0x24]\n\
bl CopyBufferedValuesToGpuRegs\n\
bl ProcessDma3Requests\n\
ldr r1, =gPcmDmaCounter\n\
ldr r0, =gSoundInfo\n\
ldrb r0, [r0, 0x4]\n\
strb r0, [r1]\n\
bl m4aSoundMain\n\
bl sub_8033648\n\
ldr r1, =0x00000439\n\
adds r0, r4, r1\n\
ldrb r1, [r0]\n\
movs r0, 0x2\n\
ands r0, r1\n\
cmp r0, 0\n\
beq _080007BA\n\
ldr r0, =gBattleTypeFlags\n\
ldr r0, [r0]\n\
ldr r1, =0x013f0102\n\
ands r0, r1\n\
cmp r0, 0\n\
bne _080007BE\n\
_080007BA:\n\
bl Random\n\
_080007BE:\n\
bl sub_800E174\n\
ldr r2, =gIntrCheck\n\
ldrh r0, [r2]\n\
movs r1, 0x1\n\
orrs r0, r1\n\
strh r0, [r2]\n\
ldr r0, =gMain\n\
ldrh r2, [r0, 0x1C]\n\
ldrh r3, [r0, 0x1C]\n\
orrs r1, r2\n\
strh r1, [r0, 0x1C]\n\
pop {r4}\n\
pop {r0}\n\
bx r0\n\
.pool\n\
.syntax divided");
}
#endif
void StartFlashMemoryTimer(void)
{
@ -464,7 +367,7 @@ static void VCountIntr(void)
gMain.vcountCallback();
m4aSoundVSync();
gIntrCheck |= INTR_FLAG_VCOUNT;
INTR_CHECK |= INTR_FLAG_VCOUNT;
gMain.intrCheck |= INTR_FLAG_VCOUNT;
}
@ -473,7 +376,7 @@ static void SerialIntr(void)
if (gMain.serialCallback)
gMain.serialCallback();
gIntrCheck |= INTR_FLAG_SERIAL;
INTR_CHECK |= INTR_FLAG_SERIAL;
gMain.intrCheck |= INTR_FLAG_SERIAL;
}
@ -483,19 +386,19 @@ static void IntrDummy(void)
static void WaitForVBlank(void)
{
gMain.intrCheck &= ~INTR_FLAG_VBLANK;
while(!(gMain.intrCheck & 0x1))
;
}
void sub_80008DC(u32 var)
void sub_80008DC(u32 *var)
{
gUnknown_0203CF5C.value = var;
gUnknown_0203CF5C = var;
}
void sub_80008E8(void)
{
gUnknown_0203CF5C.value = 0;
gUnknown_0203CF5C = NULL;
}
void DoSoftReset(void)

View File

@ -518,15 +518,3 @@ gUnknown_03007898: @ 3007898
gUnknown_030078A0: @ 30078A0
.space 0x660
gUnknown_03007F00: @ 3007F00
.space 0xF0
gUnknown_03007FF0: @ 3007FF0
.space 0x8
gIntrCheck: @ 3007FF8
.space 0x4
gUnknown_03007FFC: @ 3007FFC
.space 0x4