port input_recorder from sa2; match some ram symbols

Co-authored-by: Oliver Bell <freshollie@gmail.com>
This commit is contained in:
Zhengwen Jiang 2022-05-12 20:03:41 -05:00 committed by Egor Ananyin
parent 36dd0e3b09
commit f93cd68329
10 changed files with 119 additions and 195 deletions

View File

@ -5,136 +5,6 @@
.text
thumb_func_start sub_0815819C
sub_0815819C: @ 0x0815819C
ldr r1, _081581A4 @ =gInputRecorder
movs r0, #0
str r0, [r1, #4]
bx lr
.align 2, 0
_081581A4: .4byte gInputRecorder
thumb_func_start sub_081581A8
sub_081581A8: @ 0x081581A8
ldr r1, _081581B0 @ =gInputRecorder
movs r0, #0
str r0, [r1]
bx lr
.align 2, 0
_081581B0: .4byte gInputRecorder
thumb_func_start sub_081581B4
sub_081581B4: @ 0x081581B4
push {r4, r5, r6, lr}
sub sp, #4
ldr r6, _081581F4 @ =gInputRecorder
movs r5, #0
strb r5, [r6, #8]
ldr r4, _081581F8 @ =gUnk_03006CBC
movs r0, #0x80
lsls r0, r0, #5
bl EwramMalloc
adds r1, r0, #0
str r1, [r4]
ldr r0, _081581FC @ =gInputPlaybackBuffer
ldr r0, [r0]
bl LZ77UnCompWram
ldr r0, _08158200 @ =nullsub_146
movs r2, #0x80
lsls r2, r2, #6
ldr r1, _08158204 @ =sub_0815826C
str r1, [sp]
movs r1, #0
movs r3, #0
bl TaskCreate
str r5, [r6, #4]
str r5, [r6]
add sp, #4
pop {r4, r5, r6}
pop {r0}
bx r0
.align 2, 0
_081581F4: .4byte gInputRecorder
_081581F8: .4byte gUnk_03006CBC
_081581FC: .4byte gInputPlaybackBuffer
_08158200: .4byte nullsub_146
_08158204: .4byte sub_0815826C
thumb_func_start sub_08158208
sub_08158208: @ 0x08158208
push {lr}
ldr r3, _08158218 @ =gInputRecorder
ldr r2, [r3]
ldr r0, _0815821C @ =0x000007FF
cmp r2, r0
ble _08158220
movs r0, #0
b _0815822E
.align 2, 0
_08158218: .4byte gInputRecorder
_0815821C: .4byte 0x000007FF
_08158220:
ldr r0, _08158234 @ =gUnk_03006CBC
ldr r1, [r0]
lsls r0, r2, #1
adds r0, r0, r1
ldrh r0, [r0]
adds r1, r2, #1
str r1, [r3]
_0815822E:
pop {r1}
bx r1
.align 2, 0
_08158234: .4byte gUnk_03006CBC
thumb_func_start sub_08158238
sub_08158238: @ 0x08158238
push {r4, lr}
lsls r0, r0, #0x10
lsrs r3, r0, #0x10
ldr r4, _0815825C @ =gInputRecorder
ldr r2, [r4, #4]
ldr r0, _08158260 @ =0x000007FF
cmp r2, r0
bgt _08158256
ldr r0, _08158264 @ =gUnk_03006CBC
ldr r1, [r0]
lsls r0, r2, #1
adds r0, r0, r1
strh r3, [r0]
adds r0, r2, #1
str r0, [r4, #4]
_08158256:
pop {r4}
pop {r0}
bx r0
.align 2, 0
_0815825C: .4byte gInputRecorder
_08158260: .4byte 0x000007FF
_08158264: .4byte gUnk_03006CBC
thumb_func_start nullsub_146
nullsub_146: @ 0x08158268
bx lr
.align 2, 0
thumb_func_start sub_0815826C
sub_0815826C: @ 0x0815826C
push {lr}
ldr r0, _08158284 @ =gUnk_03006CBC
ldr r0, [r0]
bl EwramFree
ldr r1, _08158288 @ =gInputRecorder
movs r0, #0
strb r0, [r1, #8]
str r0, [r1, #4]
str r0, [r1]
pop {r0}
bx r0
.align 2, 0
_08158284: .4byte gUnk_03006CBC
_08158288: .4byte gInputRecorder
thumb_func_start sub_0815828C
sub_0815828C: @ 0x0815828C
push {r4, r5, r6, r7, lr}

View File

@ -302,19 +302,18 @@ struct Song
extern const struct MusicPlayer gMPlayTable[];
extern const struct Song gSongTable[];
extern u8 gMPlayMemAccArea[];
#define MAX_POKEMON_CRIES 2
extern u8 gMPlayMemAccArea[0x10];
extern char SoundMainRAM[];
extern void *gMPlayJumpTable[];
typedef void (*MPlayFunc)();
extern MPlayFunc gMPlayJumpTable[36];
extern struct MusicPlayerInfo gUnk_030016A0;
typedef void (*XcmdFunc)(struct MusicPlayerInfo *, struct MusicPlayerTrack *);
extern const XcmdFunc gXcmdTable[];
extern struct CgbChannel gCgbChans[];
extern struct CgbChannel gCgbChans[4];
extern const u8 gCgb3Vol[];
extern const u8 gScaleTable[];
@ -354,7 +353,7 @@ void CgbSound(void);
void CgbOscOff(u8);
u32 MidiKeyToCgbFreq(u8, u8, u8);
void nullsub_141(void);
void MPlayJumpTableCopy(void **mplayJumpTable);
void MPlayJumpTableCopy(MPlayFunc *);
void SampleFreqSet(u32 freq);
void m4aSoundVSyncOn(void);
void m4aSoundVSyncOff(void);

24
include/input_recorder.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef GUARD_INPUT_RECORDER_H
#define GUARD_INPUT_RECORDER_H
#include "global.h"
#define RECORDER_DISABLED 0
#define RECORDER_RECORD 1
#define RECORDER_PLAYBACK 2
struct InputRecorder {
s32 playbackHead;
s32 recordHead;
u8 mode;
};
extern struct InputRecorder gInputRecorder;
void InputRecorderResetRecordHead(void);
void InputRecorderResetPlaybackHead(void);
void InputRecorderLoadTape(void);
u16 InputRecorderRead(void);
void InputRecorderWrite(u16);
#endif

View File

@ -62,16 +62,6 @@ union Unk_030060A0 {
u8 parts[4];
};
#define RECORDER_DISABLED 0
#define RECORDER_RECORD 1
#define RECORDER_PLAYBACK 2
struct InputRecorder {
u32 playbackHead;
u32 recordHead;
u8 mode;
};
struct MultiSioData_0_0 {
u8 unk0;
u8 unk1;
@ -175,10 +165,9 @@ extern u8 gUnk_030068B0;
extern u16 gUnk_030068B4;
extern s16 gUnk_030068B8;
extern FuncType_030068C0 gUnk_030068C0[8];
extern const u32 *gInputPlaybackBuffer; // used for demo in sonic advance 2, but doesn't seem to be used here
extern const u32 *gInputPlaybackData;
extern u8 gUnk_030068D4;
extern struct InputRecorder gInputRecorder;
extern IntrFunc gIntrTable[];
extern u32 gIntrMainBuf[0x80];
@ -187,8 +176,6 @@ extern IntrFunc const gIntrTableTemplate[];
extern void GameLoop(void);
extern void UpdateScreenDma(void);
extern void GameInit(void);
extern u16 sub_08158208(void);
extern void sub_08158238(u16);
extern void WaitForInput(void);
extern void GetInput(void);
extern void UpdateScreenCpuSet(void);

View File

@ -112,17 +112,13 @@ SECTIONS {
. = 0x0000000C; gUnk_0300000C = .;
. = 0x00000010; gUnk_03000010 = .;
. = 0x00000014; src/multi_boot.o(.bss);
. = ALIGN(16);
. = 0x00000020; gUnk_03000020 = .;
. = ALIGN(16); gUnk_03000020 = .;
. = 0x0000002C; gUnk_0300002C = .;
. = 0x00000030; gUnk_03000030 = .;
. = 0x00000034; gUnk_03000034 = .;
. += 4; . = ALIGN(4);
*libgcc.a:dp-bit.o(.bss);
. = ALIGN(4);
*libgcc.a:fp-bit.o(.bss);
. = ALIGN(4);
. = 0x00000060; SoundMainRAM_Buffer = .;
. = 0x00000038; *libgcc.a:dp-bit.o(.bss);
. = ALIGN(4); *libgcc.a:fp-bit.o(.bss);
. = ALIGN(4); src/m4a.o(.bss*);
. = 0x00000470; gTimer3IntrBkp = .;
. = 0x00000478; gMultiBootDataRecv = .;
. = 0x00000480; gUnk_03000480 = .;
@ -137,22 +133,8 @@ SECTIONS {
. = 0x00000530; gUnk_03000530 = .;
. = 0x00000554; gUnk_03000554 = .;
. = 0x00000558; gUnk_03000558 = .;
. = 0x00000560; gSoundInfo = .;
. = 0x00001510; gMPlayJumpTable = .;
. = 0x00001514; gUnk_03001514 = .;
. = 0x00001598; gUnk_03001598 = .;
. = 0x0000159C; gUnk_0300159C = .;
. = 0x000015A0; gCgbChans = .;
. = 0x000016A0; gUnk_030016A0 = .;
. = 0x000016E0; gUnk_030016E0 = .;
. = 0x00001720; gUnk_03001720 = .;
. = 0x00001760; gMPlayMemAccArea = .;
. = 0x00001770; gUnk_03001770 = .;
. = 0x000017B0; gIntrTable = .;
. = 0x00000560; src/m4a.o(common_data);
. = ALIGN(16); gIntrTable = .;
. = 0x000017F0; gIntrMainBuf = .;
. = 0x000019F0; gUnk_030019F0 = .;
. = 0x000023F0; gUnk_030023F0 = .;
@ -253,16 +235,14 @@ SECTIONS {
. = 0x000068B4; gUnk_030068B4 = .;
. = 0x000068B8; gUnk_030068B8 = .;
. = 0x000068C0; gUnk_030068C0 = .;
. = 0x000068D0; gInputPlaybackBuffer = .;
. = 0x000068D0; gInputPlaybackData = .;
. = 0x000068D4; gUnk_030068D4 = .;
. = 0x000068D8; gRngVal = .;
. = 0x000068E0; gMultiSioIntrFuncBuf = .;
. = 0x00006A60; gMultiSioArea = .;
. = 0x00006C50; gMultiSioRecvFuncBuf = .;
. = 0x00006C90; gSio32MultiLoadArea = .;
. = 0x00006CB0; gInputRecorder = .;
. = 0x00006CBC; gUnk_03006CBC = .;
. = 0x00006CC0; gUnk_03006CC0 = .;
. = 0x000068E0; src/multi_sio.o(common_data);
. = ALIGN(4); src/sio32_multi_load.o(common_data);
. = ALIGN(16); src/input_recorder.o(common_data);
. = ALIGN(4); src/input_recorder.o(.bss);
. = ALIGN(4); gUnk_03006CC0 = .;
. = 0x00006CC4; gUnk_03006CC4 = .;
. = 0x00007F00; gUnk_03007F00 = .;
. = 0x00008000;
@ -416,7 +396,8 @@ SECTIONS {
src/multi_sio.o(.text);
src/multi_boot.o(.text);
src/sio32_multi_load.o(.text);
asm/code_0815819C.o(.text);
src/input_recorder.o(.text);
asm/code_0815828C.o(.text);
asm/multi_sio_asm.o(.text);
src/malloc_ewram.o(.text);
src/agb_sram.o(.text);

55
src/input_recorder.c Normal file
View File

@ -0,0 +1,55 @@
#include "input_recorder.h"
#include "task.h"
#include "malloc_ewram.h"
#include "main.h"
#define TAPE_LENGTH 0x800
/* The module was simply never used in the game. Used in Sonic Advance 2. */
static void Task_InputRecorder(void);
static void InputRecorderEject(struct Task *);
static u16 *sTapeBuffer;
struct InputRecorder gInputRecorder __attribute__((section("common_data"))) = {};
void InputRecorderResetRecordHead(void) {
gInputRecorder.recordHead = 0;
}
void InputRecorderResetPlaybackHead(void) {
gInputRecorder.playbackHead = 0;
}
void InputRecorderLoadTape(void) {
gInputRecorder.mode = RECORDER_DISABLED;
sTapeBuffer = EwramMalloc(TAPE_LENGTH * sizeof(u16));
// Load the playback tape into the recorder
LZ77UnCompWram(gInputPlaybackData, sTapeBuffer);
TaskCreate(Task_InputRecorder, 0, 0x2000, 0, InputRecorderEject); // Only emit the callback functions. No space needed
gInputRecorder.recordHead = 0;
gInputRecorder.playbackHead = 0;
}
u16 InputRecorderRead(void) {
if (gInputRecorder.playbackHead < TAPE_LENGTH)
return sTapeBuffer[gInputRecorder.playbackHead++];
return 0;
}
void InputRecorderWrite(u16 input) {
if (gInputRecorder.recordHead < TAPE_LENGTH) {
sTapeBuffer[gInputRecorder.recordHead++] = input;
}
}
static void Task_InputRecorder(void) {
// Potentially generate input ??
}
static void InputRecorderEject(struct Task *unused __attribute__((unused))) {
EwramFree(sTapeBuffer);
gInputRecorder.mode = RECORDER_DISABLED;
gInputRecorder.recordHead = 0;
gInputRecorder.playbackHead = 0;
}

View File

@ -1,8 +1,16 @@
#include "gba/m4a.h"
extern ALIGNED(4) char SoundMainRAM_Buffer[0x400];
char SoundMainRAM_Buffer[0x400] __attribute__((section(".bss.code"), aligned(4))) = {};
struct SoundInfo gSoundInfo __attribute__((section("common_data"))) = {};
MPlayFunc gMPlayJumpTable[36] __attribute__((section("common_data"))) = {};
struct CgbChannel gCgbChans[4] __attribute__((section("common_data"))) = {};
struct MusicPlayerInfo gUnk_030016A0 __attribute__((section("common_data"))) = {};
struct MusicPlayerInfo gUnk_030016E0 __attribute__((section("common_data"))) = {};
struct MusicPlayerInfo gUnk_03001720 __attribute__((section("common_data"))) = {};
u8 gMPlayMemAccArea[0x10] __attribute__((section("common_data"))) = {};
struct MusicPlayerInfo gUnk_03001770 __attribute__((section("common_data"))) = {};
extern struct SoundInfo gSoundInfo;
u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust)
{

View File

@ -8,6 +8,7 @@
#include "multi_sio.h"
#include "multi_08030C94.h"
#include "malloc_ewram.h"
#include "input_recorder.h"
#define GetBit(x, y) ((x) >> (y) & 1)
@ -148,7 +149,7 @@ void GameInit(void) {
gInputRecorder.mode = RECORDER_DISABLED;
gUnk_03002480 = 0;
gInputPlaybackBuffer = NULL;
gInputPlaybackData = NULL;
gFrameCount = 0;
for (i = 0; i < 15; i++) {
@ -535,10 +536,10 @@ void GetInput(void) {
gUnk_03002480 = gInput;
if (gInputRecorder.mode == RECORDER_RECORD) {
sub_08158238(gInput);
InputRecorderWrite(gInput);
}
else if (gInputRecorder.mode == RECORDER_PLAYBACK) {
gInput = sub_08158208();
gInput = InputRecorderRead();
}
gPressedKeys = (gInput ^ gPrevInput) & gInput;

View File

@ -2,12 +2,12 @@
static const u8 sMultiSioLibVer[] = "MultiSio4Sio32Load020820";
// COMMON
// struct MultiSioArea gMultiSioArea; // Multi-play Communication Work Area
#ifdef MULTI_SIO_DI_FUNC_FAST
// u32 gMultiSioRecvFuncBuf[0x40 / 4]; // Receive Data/Check Buffer Change Routine RAM Execution Buffer
// u32 gMultiSioIntrFuncBuf[0x180 / 4]; // Interrupt Routine RAM Execution Buffer
u32 gMultiSioIntrFuncBuf[0x180 / 4] __attribute__((section("common_data"))) = {}; // Interrupt Routine RAM Execution Buffer
#endif
struct MultiSioArea gMultiSioArea __attribute__((section("common_data"))) = {}; // Multi-play Communication Work Area
#ifdef MULTI_SIO_DI_FUNC_FAST
u32 gMultiSioRecvFuncBuf[0x40 / 4] __attribute__((aligned(16), section("common_data"))) = {}; // Receive Data/Check Buffer Change Routine RAM Execution Buffer
#endif
/*------------------------------------------------------------------*/

View File

@ -2,8 +2,7 @@
static const u8 sMultiSioLibVer[] = "Sio32MultiLoad010214";
// COMMON
// struct Sio32MultiLoadArea gSio32MultiLoadArea; // 32bit serial communication multi-load work area
struct Sio32MultiLoadArea gSio32MultiLoadArea __attribute__((section("common_data"))) = {}; // 32bit serial communication multi-load work area
/*------------------------------------------------------------------*/
/* 32bit serial communication multi-load main */