DRA DebugCaptureScreen, DebugCaptureVideo (#330)

Matches the two orphan functions `DebugCaptureScreen` and
`DebugCaptureVideo`. I also fully imported the `.rodata` into `42398.c`
and I am proud to say the file is now fully decompiled! I also renamed
two other functions that are used by the two I decompiled. They are now
all fully documented. Note the unused `u8 bmp[0x100];` in
`DebugCaptureVideo`, probably a copy&pasta left-over. The function does
not match without it.

I am waiting for https://github.com/mkst/maspsx/pull/6 and
https://github.com/mkst/maspsx/pull/7 to be merged as currently maspsx
breaks the two functions.
This commit is contained in:
Luciano Ciccariello 2023-07-19 21:15:59 +01:00 committed by GitHub
parent 8ce7e2735a
commit 45857ff533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 230 additions and 34 deletions

View File

@ -39,11 +39,11 @@ segments:
- [0x8258, data]
- [0x8900, data]
- [0xCEB0, data]
- [0xD670, rodata] # not rodata but data
- [0x2217C, rodata]
- [0x227B0, rodata]
- [0xD670, data]
- [0x2217C, data]
- [0x227B0, data]
- [0x3B3B0, rodata]
- [0x3B430, .rodata, 42398]
- [0x3B3B4, .rodata, 42398]
- [0x3B530, .rodata, play]
- [0x3B560, .rodata, gameover]
- [0x3B720, .rodata, 46358]

View File

@ -32,9 +32,9 @@ g_MemcardSavePath = 0x800DBE6C;
D_800DC4C0 = 0x800DC434;
D_800DC4C4 = 0x800DC438;
func_800E2398 = 0x800E22B4;
func_800E2438 = 0x800E2354;
func_800E249C = 0x800E23B8;
func_800E2824 = 0x800E2740;
DebugInputWait = 0x800E2354;
DebugCaptureScreen = 0x800E23B8;
DebugCaptureVideo = 0x800E2740;
func_800E2B00 = 0x800E2A1C;
func_800E2E98 = 0x800E2DB4;
nullsub_8 = 0x800E2E50;

View File

@ -872,6 +872,10 @@ jpt_80133990 = 0x800E2074;
jpt_80133C10 = 0x800E208C;
jpt_80135058 = 0x800E20B4;
jpt_801353DC = 0x800E2354;
DebugShowWaitInfo = 0x800E2398;
DebugInputWait = 0x800E2438;
DebugCaptureScreen = 0x800E249C;
DebugCaptureVideo = 0x800E2824;
nullsub_8 = 0x800E2F34;
PrintGpuInfo = 0x800E2F3C;
PrintHBlankInfo = 0x800E31C0;
@ -1022,7 +1026,10 @@ IncrementRingBufferPos = 0x80135C00;
nullsub_10 = 0x801362A4;
g_DebugPalIdx = 0x801362C0;
g_CurrentOT = 0x801362CC;
g_DebugIsRecordingVideo = 0x801362D8;
g_GpuMaxUsage = 0x801362DC;
g_DebugWaitInfoTimer = 0x80136300;
g_DebugRecordVideoFid = 0x80136304;
g_softResetTimer = 0x80136408;
g_PadsRepeatTimer = 0x80137460;
g_DecSrcPtr = 0x80137578;

View File

@ -30,4 +30,7 @@ D_8015523C = 0x8015523C;
D_80155240 = 0x80155240;
UpdateEntityRichter = 0x80157BFC;
SetPlayerStep = 0x8015C908;
DebugShowWaitInfo = 0x8015E380;
DebugInputWait = 0x8015E420;
func_8017328C = 0x8017328C;
g_DebugWaitInfoTimer = 0x80174F7C;

View File

@ -634,7 +634,7 @@ g_api_func_800FF110 = 0x8003C88C;
g_api_func_800FD664 = 0x8003C890;
g_api_func_800FD5BC = 0x8003C894;
g_api_LearnSpell = 0x8003C898;
g_api_func_800E2438 = 0x8003C89C;
g_api_DebugInputWait = 0x8003C89C;
g_api_unused12C = 0x8003C8A0;
g_api_unused130 = 0x8003C8A4;
g_api_unused134 = 0x8003C8A8;

View File

@ -952,7 +952,7 @@ typedef struct {
/* 8003C890 */ s32 (*func_800FD664)(s32 arg0);
/* 8003C894 */ s32 (*func_800FD5BC)(Unkstruct_800FD5BC* arg0);
/* 8003C898 */ void (*LearnSpell)(s32 spellId);
/* 8003C89C */ void (*func_800E2438)(const char* str);
/* 8003C89C */ void (*DebugInputWait)(const char* str);
/* 8003C8A0 */ void* unused12C;
/* 8003C8A4 */ void* unused130;
/* 8003C8A8 */ void* unused134;

View File

@ -10,7 +10,6 @@
#define DISP_UNK2_H DISP_ALL_H
#define PAD_RESETCOMBO ((PAD_START) | (PAD_SELECT))
void func_800E2398(const char* str);
s32 LoadVabData(void);
void func_800E385C(u32*);
void UpdateGame(void);
@ -33,13 +32,23 @@ void SoundInit(void);
void func_801353A0(void);
s32 func_80136010(void);
extern const char* aO;
const char aO[] = "\no\n";
const char D_800DB3B8[] = "sim:c:\\bin\\dra000.bmp";
const char D_800DB3D0[] = "cre err:%s\n";
const char D_800DB3DC[] = "wr err\n";
const char D_800DB3E4[] = "clo err\n";
const char D_800DB3F0[] = "sim:c:\\bin\\dra000.mov";
const char D_800DB408[] = "pale";
const char D_800DB410[] = "reverse";
const char D_800DB418[] = "light";
const char D_800DB420[] = "dark";
const char D_800DB428[] = "normal";
void func_800E2398(const char* str) {
void DebugShowWaitInfo(const char* msg) {
g_CurrentBuffer = g_CurrentBuffer->next;
FntPrint(str);
if (D_80136300++ & 4) {
FntPrint(&aO); // TODO: rodata split
FntPrint(msg);
if (g_DebugWaitInfoTimer++ & 4) {
FntPrint(&aO); // TODO: inline
}
DrawSync(0);
VSync(0);
@ -48,16 +57,193 @@ void func_800E2398(const char* str) {
FntFlush(-1);
}
void func_800E2438(const char* str) {
void DebugInputWait(const char* msg) {
while (PadRead(0))
func_800E2398(str);
DebugShowWaitInfo(msg);
while (!PadRead(0))
func_800E2398(str);
DebugShowWaitInfo(msg);
}
INCLUDE_ASM("asm/us/dra/nonmatchings/42398", func_800E249C);
void DebugCaptureScreen(void) {
const int BmpHeaderLen = 0x36;
const int MaxScreenshotCount = 1000;
const int BytesPerPixel = 3;
char fileName[0x100];
u8 bmp[0x100];
s8 buffer[0x30];
s32 fid;
s32 width;
s32 height;
u32 fileSize;
s32 bufferPos;
s8* dst;
u16* src;
s32 i;
s32 j;
INCLUDE_ASM("asm/us/dra/nonmatchings/42398", func_800E2824);
if (!(g_pads[1].tapped & PAD_SELECT && g_pads[1].pressed & PAD_UP)) {
return;
}
StoreImage(&g_CurrentBuffer->disp.disp, (u32*)0x80200000);
DrawSync(0);
for (i = 0; i < MaxScreenshotCount; i++) {
__builtin_memcpy(fileName, D_800DB3B8, sizeof(D_800DB3B8));
fileName[14] += i / 100;
fileName[15] += i / 10 - i / 100 * 10;
fileName[16] += i % 10;
fid = open(fileName, O_RDONLY);
if (fid < 0) {
break;
}
close(fid);
}
fid = open(fileName, O_CREAT);
if (fid < 0) {
FntPrint(D_800DB3D0, &fileName);
return;
}
width = g_CurrentBuffer->disp.disp.w;
height = g_CurrentBuffer->disp.disp.h;
for (i = 0; i < BmpHeaderLen; i++) {
bmp[i] = 0;
}
fileSize = BmpHeaderLen + width * height * BytesPerPixel;
bmp[0x00] = 'B'; // Bitmap signature
bmp[0x01] = 'M'; // for Windows OS
bmp[0x02] = fileSize; // total file size of
bmp[0x03] = fileSize >> 8; // the bitmap file
bmp[0x04] = fileSize >> 16; // in little endian
bmp[0x05] = fileSize >> 24; //
bmp[0x0A] = BmpHeaderLen; // Data offset
bmp[0x0E] = 40; // header size
bmp[0x1A] = 1; // number of color planes
bmp[0x1C] = BytesPerPixel * 8; // bits per pixel
bmp[0x12] = width;
bmp[0x13] = width / 256;
bmp[0x16] = height;
bmp[0x17] = height / 256;
if (write(fid, &bmp, BmpHeaderLen) < 0) {
FntPrint(D_800DB3DC);
return;
}
bufferPos = 0;
dst = buffer;
src = 0x80200000;
for (i = height - 1; i >= 0; i--) {
u16* start = buffer;
for (j = 0; j < width; j++) {
u16 pixelColor = src[j + i * width];
*dst++ = (pixelColor >> 7) & 0xF8; // B
*dst++ = (pixelColor >> 2) & 0xF8; // G
*dst++ = (pixelColor & 0x1F) << 3; // R
if (++bufferPos == 0x10) {
if (write(fid, start, bufferPos * BytesPerPixel) < 0) {
FntPrint(D_800DB3DC);
return;
}
bufferPos = 0;
dst = start;
}
}
}
if (bufferPos != 0) {
if (write(fid, &buffer, bufferPos * BytesPerPixel) < 0) {
FntPrint(D_800DB3DC);
return;
}
}
if (close(fid) < 0) {
FntPrint(D_800DB3E4);
return;
}
DebugInputWait(fileName);
}
void DebugCaptureVideo(void) {
const int MaxVideoFramesCount = 1000;
char fileName[0x100];
u8 bmp[0x100];
u16 buffer[0x10];
s32 fid;
s32 bufferPos;
s32 i;
s32 j;
u16* start;
u16* src;
u16* dst;
for (i = 0; i < 4; i++) {
if (g_Settings.buttonConfig[i] != 3 - i) {
return;
}
}
if (g_DebugIsRecordingVideo == false) {
if (!(g_pads[0].tapped & PAD_TRIANGLE)) {
return;
}
for (i = 0; i < MaxVideoFramesCount; i++) {
__builtin_memcpy(fileName, D_800DB3F0, sizeof(D_800DB3F0));
fileName[14] += i / 100;
fileName[15] += i / 10 - i / 100 * 10;
fileName[16] += i % 10;
g_DebugRecordVideoFid = open(fileName, O_RDONLY);
if (g_DebugRecordVideoFid < 0) {
break;
}
close(g_DebugRecordVideoFid);
}
g_DebugRecordVideoFid = open(fileName, O_CREAT);
if (g_DebugRecordVideoFid < 0) {
FntPrint(D_800DB3D0, fileName);
return;
}
g_DebugIsRecordingVideo = true;
} else if (g_pads[0].tapped & PAD_TRIANGLE) {
g_DebugIsRecordingVideo = false;
if (close(g_DebugRecordVideoFid) < 0) {
FntPrint(D_800DB3E4);
}
return;
}
StoreImage(&g_CurrentBuffer->disp.disp, (u_long*)0x80200000);
DrawSync(0);
src = 0x80200000;
i = 0;
bufferPos = 0;
dst = buffer;
start = buffer;
for (; i < 0x40; i++) {
for (j = 0; j < 0x40; j++) {
*dst++ = src[0x6060 + i * 0x100 + j];
if (++bufferPos == 0x10) {
if (write(g_DebugRecordVideoFid, start, bufferPos * 2) < 0) {
FntPrint(D_800DB3DC);
return;
}
bufferPos = 0;
dst = start;
}
}
}
if (bufferPos != 0) {
if (write(g_DebugRecordVideoFid, buffer, bufferPos * 2) < 0) {
FntPrint(D_800DB3DC);
return;
}
}
}
void func_800E2B00(void) {
DR_MODE* drMode;
@ -457,7 +643,7 @@ loop_5:
g_DebugPalIdx = 0;
D_801362C4 = 0;
D_801362C8 = 0;
D_801362D8 = 0;
g_DebugIsRecordingVideo = false;
g_DemoMode = Demo_None;
D_8003C704 = 0;
D_800973EC = 0;

View File

@ -239,7 +239,7 @@ void DemoSaveFile(void) {
}
__builtin_memcpy(buf, " OK", sizeof(" OK"));
func_800E2438(buf);
DebugInputWait(buf);
}
void DemoInit(s32 arg0) {

View File

@ -418,10 +418,11 @@ extern s32 D_801362C8;
extern u32* g_CurrentOT;
extern s32 D_801362D0[];
extern s32 D_801362D4;
extern s32 D_801362D8;
extern s32 g_DebugIsRecordingVideo;
extern GpuUsage g_GpuMaxUsage;
extern s32 g_softResetTimer;
extern s32 D_80136300;
extern s32 g_DebugWaitInfoTimer;
extern s32 g_DebugRecordVideoFid;
extern s16 D_80136308[];
extern s32 D_8013640C;
extern s32 D_80136410;

View File

@ -1,10 +1,9 @@
#include "ric.h"
// same as func_800E2398
void func_8015E380(const char* str) {
void DebugShowWaitInfo(const char* msg) {
g_CurrentBuffer = g_CurrentBuffer->next;
FntPrint(str);
if (D_80174F7C++ & 4) {
FntPrint(msg);
if (g_DebugWaitInfoTimer++ & 4) {
FntPrint("\no\n");
}
DrawSync(0);
@ -14,11 +13,11 @@ void func_8015E380(const char* str) {
FntFlush(-1);
}
void func_8015E420(s32 arg0) {
void DebugInputWait(const char* msg) {
while (PadRead(0))
func_8015E380(arg0);
DebugShowWaitInfo(msg);
while (PadRead(0) == 0)
func_8015E380(arg0);
DebugShowWaitInfo(msg);
}
INCLUDE_ASM("asm/us/ric/nonmatchings/22380", func_8015E484);

View File

@ -28,7 +28,7 @@ extern void func_8015CE7C(void);
extern void func_8015CF08(void);
extern void func_8015D020(void);
extern bool func_8015DBB0(s32);
extern void func_8015E380(const char* str);
extern void DebugShowWaitInfo(const char* str);
extern void func_8015F9F0(Entity* entity);
extern void func_8015FAB8(Entity*);
extern s32 func_8015FDB0(POLY_GT4* poly, s16 posX, s16 posY);
@ -98,7 +98,7 @@ extern AnimationFrame* D_80155EA8;
extern s8 D_80156904;
extern s32 D_80174F74;
extern s32 D_80174F78;
extern s32 D_80174F7C;
extern s32 g_DebugWaitInfoTimer;
extern u8 D_80174FAC;
extern u8 D_80174FB0;
extern u8 D_80174FB4;

@ -1 +1 @@
Subproject commit 4c06a8b9149b55944c33cf049c61e4988d5b81b4
Subproject commit 661027375aa3850784dbb032fb825f7526398e9c