add clang-format and format.py and cleanup util.c

This commit is contained in:
RevoSucks 2023-09-02 15:54:26 -04:00
parent 168ed2e763
commit 1670cbcd8d
63 changed files with 1133 additions and 1183 deletions

View File

@ -178,7 +178,9 @@ def main():
files = args.files
extra_files = []
else:
files = glob.glob("src/**/*.c", recursive=True)
# Ignore libultra files. They cause too many formatter issues so we just wont format libultra for now and only
# format the game specific files. We can format libleo however.
files = [file for file in glob.glob("src/**/*.c", recursive=True) if not file.startswith('src/libultra/')]
extra_files = glob.glob("assets/**/*.xml", recursive=True)
format_files(files, extra_files, nb_jobs)

View File

@ -191,7 +191,7 @@ extern float sinf(float angle);
extern float cosf(float angle);
extern signed short sins (unsigned short angle);
extern signed short coss (unsigned short angle);
extern float sqrtf(float value);
extern float sqrtf(float f);
/*
* Dump routines for low-level display lists

View File

@ -245,8 +245,8 @@ extern u32 LeoDriveExist(void);
/* Synchronous functions */
extern s32 LeoClearQueue(void);
extern s32 LeoByteToLBA(s32 startLBA, u32 nbytes, s32 *lbas);
extern s32 LeoLBAToByte(s32 startLBA, u32 nLBAs, s32 *bytes);
extern s32 LeoByteToLBA(s32 startlba, u32 nbytes, s32* lba);
extern s32 LeoLBAToByte(s32 startlba, u32 nlbas, s32* bytes);
extern s32 LeoReadCapacity(LEOCapacity *cap, s32 dir);
extern s32 LeoInquiry(LEOVersion *ver);
extern s32 LeoTestUnitReady(LEOStatus *status);

View File

@ -40,8 +40,8 @@
/*-----------------------------------*/
/* LEO FUNCTION DEFINITIONS */
/*-----------------------------------*/
extern void leoInitialize(OSPri PRI_WRK, OSPri PRI_INT, OSMesg *command_que_buf, u32 cmd_buff_size);
extern void leoCommand(void *CDB);
extern void leoInitialize(OSPri compri, OSPri intpri, OSMesg* command_que_buf, u32 cmd_buff_size);
extern void leoCommand(void* cmd_blk_addr);
extern void LeoReset(void);
extern s32 LeoResetClear(void);

View File

@ -187,7 +187,7 @@ typedef u32 OSYieldResult;
/*
* break this up into two steps for debugging.
*/
extern void osSpTaskLoad(OSTask *tp);
extern void osSpTaskLoad(OSTask* intp);
extern void osSpTaskStartGo(OSTask *tp);
extern void osSpTaskYield(void);

View File

@ -1,6 +1,6 @@
#ifndef _XSTDIO_H
#define _XSTDIO_H
#include <ultratypes.h>
#include "ultratypes.h"
#include <stdlib.h>
#include <stdarg.h>

View File

@ -9,12 +9,6 @@ extern s32 func_8005A990(OSPiHandle *);
// bcopy.s
extern void _bcopy(void *, void *, u32);
// 3A80.c
extern uintptr_t convert_addr_to_virt_addr(uintptr_t addr);
extern void func_80002F58(void);
extern void *func_80002FDC(s32);
extern void func_80003004(void *);
// 3FB0.s
extern void func_80003B30(void *, s32, s32, s32); // types unknown

View File

@ -147,9 +147,9 @@ typedef struct
extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *);
u16 __osSumcalc(u8 *ptr, int length);
s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum);
s32 __osIdCheckSum(u16* ptr, u16* checkSum, u16* idSum);
s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid);
s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp);
s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check);
s32 __osGetId(OSPfs *pfs);
s32 __osCheckId(OSPfs *pfs);
s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank);

View File

@ -3,6 +3,12 @@
#include "ultra64.h"
// thread pris
#define THREAD_PRI_IDLE_INIT 100
// thread IDs
#define THREAD_ID_IDLE 1
#define POOL_END_4MB 0x80400000
#define POOL_END_6MB 0x80600000

View File

@ -38,7 +38,7 @@ segments:
- [0x28E0, c, memmap]
- [0x2EC0, c, memory_main] # handles the main global pool
- [0x3640, c, memory] # memory_pool
- [0x3A80, c]
- [0x3A80, c, util]
- [0x3FB0, asm] # PRES-JPEG decoder
- [0x5580, asm] # there's a split here according to PAL
- [0x60A0, asm] #
@ -325,7 +325,7 @@ segments:
- [0x68020, bin] # rest of rom part 1
# .data is somewhere in here
- [0x69790, .data, 3A80]
- [0x69790, .data, util]
- [0x697A0, bin, rom_data_697A0]
- [0x6A1B0, .data, crash_screen]
- [0x6A3B0, .data, profiler]
@ -354,7 +354,7 @@ segments:
# Start of .rodata
- [0x7BAC0, .rodata, rsp]
- [0x7BB10, rodata, rom_rodata_7BB10]
- [0x7BB20, .rodata, 3A80]
- [0x7BB20, .rodata, util]
- [0x7BB50, rodata, rom_rodata_7BB50]
- [0x7BBE0, .rodata, crash_screen]
- [0x7BFA0, .rodata, profiler]

View File

@ -7,7 +7,7 @@ extern s32 D_80078580;
extern void* D_80078584;
void func_80042920(void *arg0, s32 arg1) {
void func_80042920(void* arg0, s32 arg1) {
if (D_80078580 == 0) {
D_80078580 = arg0;
if (D_80078584 == NULL) {

View File

@ -24,12 +24,12 @@ struct UnkArray4* func_800495F8();
extern struct UnkArray4* D_80078584; // who did this? fix later
void func_8004EBF0(struct UnkStruct8004EBF0* arg0, f32 arg1) {
struct UnkArray4 *temp_v0;
struct UnkArray4* temp_v0;
if (arg0->unk8 != NULL) {
temp_v0 = func_800495F8();
if (temp_v0 != NULL) {
temp_v0->unk4 = (s32) (D_80078584->unk1C + arg0->unk8->unk88);
temp_v0->unk4 = (s32)(D_80078584->unk1C + arg0->unk8->unk88);
temp_v0->unk8 = 7;
temp_v0->unkC = arg1;
temp_v0->unk0 = 0;

View File

@ -7,10 +7,10 @@ extern u8 D_800A82B0[32];
extern OSMesgQueue gSIEventMesgQueue;
s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force);
s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer);
s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force);
s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer);
extern s32 osPfsIsPlug(OSMesgQueue *, u8 *);
extern s32 osPfsIsPlug(OSMesgQueue*, u8*);
extern u8 D_800A82CF;
@ -30,35 +30,34 @@ s32 func_8000B4C4(void) {
u8 sp2F; // sp2F
if (D_800697E0 == 0) {
u8 *buffer;
u8* buffer;
osPfsIsPlug(&gSIEventMesgQueue, &sp2F);
if(sp2F & 8) {
if (sp2F & 8) {
Cont_BlockEepromQueue();
for(buffer = D_800A82B0, i = 0; i < 32; i++) {
for (buffer = D_800A82B0, i = 0; i < 32; i++) {
buffer[i] = 0xFE;
}
if((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2)
&& (__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) {
if ((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2) &&
(__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) {
Cont_NoBlockEepromQueue();
return 0;
}
if((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0) && (D_800A82CF == 0xFE)) {
if ((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0) && (D_800A82CF == 0xFE)) {
Cont_NoBlockEepromQueue();
return 0;
}
for(buffer = D_800A82B0, i = 0; i < 32; i+=4) {
buffer[i+0] = 0x85;
buffer[i+1] = 0x85;
buffer[i+2] = 0x85;
buffer[i+3] = 0x85;
for (buffer = D_800A82B0, i = 0; i < 32; i += 4) {
buffer[i + 0] = 0x85;
buffer[i + 1] = 0x85;
buffer[i + 2] = 0x85;
buffer[i + 3] = 0x85;
}
if((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2)
&& (__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) {
if ((__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) == 2) &&
(__osContRamWrite(&gSIEventMesgQueue, 3, 0x400, buffer, 0) != 0)) {
Cont_NoBlockEepromQueue();
return 0;
}
if((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0)
&& (D_800A82CF == 0x85)) {
if ((__osContRamRead(&gSIEventMesgQueue, 3, 0x400, buffer) == 0) && (D_800A82CF == 0x85)) {
Cont_NoBlockEepromQueue();
D_800697E0 = 1;
return 1;
@ -78,7 +77,7 @@ u8 func_8000B6B4(void) {
}
void func_8000B6FC(u8 arg0) {
u8 *buffer = D_800A82B0;
u8* buffer = D_800A82B0;
Cont_BlockEepromQueue();
__osContRamRead(&gSIEventMesgQueue, 3, 0x600, buffer);
if (D_800A82CF == 8) {

View File

@ -29,7 +29,7 @@ void func_800373D8(void);
void func_8004FD44(void);
void func_8004B1CC();
void func_8004B9C4();
void func_80037340(void *);
void func_80037340(void*);
void func_8004FCD8(s32);
void func_8003D4A0(s32);
void func_8004AF24(s32);
@ -37,19 +37,15 @@ void func_8004FD64(s32);
void func_8004AE90(s32, s32);
void func_8000D1C0(void) {
}
void func_8000D1C8(void) {
}
void func_8000D1D0(void) {
}
void func_8000D1D8(void) {
}
void func_8000D1E0(void) {
@ -82,7 +78,7 @@ void func_8000D278(void) {
s32 func_8000D2B4(s32 arg0) {
s32 retvar = 0;
if (arg0 != 0) {
func_8004FCD8(2);
}
@ -111,7 +107,7 @@ void func_8000D380(void) {
D_800A83A0 = 1;
}
void func_8000D3A8(void *unused) {
void func_8000D3A8(void* unused) {
__osSetFpcCsr(0x01000C01);
func_80004CC0(&D_800A8480, 1, 1);
func_80005328(&D_800A8480);
@ -120,14 +116,14 @@ void func_8000D3A8(void *unused) {
D_800A8478 = 0;
osCreateMesgQueue(&D_800A83A8[0].queue, &D_800A83A8[0].mesg, 1);
osCreateMesgQueue(&D_800A83A8[1].queue, &D_800A83A8[1].mesg, 1);
osSendMesg(&D_800A83A8[0].queue, (void* )0x444F4E45, 0);
osSendMesg(&D_800A83A8[1].queue, (void* )0x444F4E45, 0);
osSendMesg(&D_800A83A8[0].queue, (void*)0x444F4E45, 0);
osSendMesg(&D_800A83A8[1].queue, (void*)0x444F4E45, 0);
func_800373D8();
func_8004AF24(0);
func_8004AE90(3, 4);
// thread loop
while(1) {
while (1) {
func_80004CF4(&D_800A8480);
profiler_log_thread4_time();
if ((D_800A83A0 != 0) && (D_800A62E0.unkA38 < 0x15)) {

View File

@ -4,6 +4,7 @@
#include "fragments.h"
#include "memory.h"
#include "dp_intro.h"
#include "util.h"
struct UnkInputStruct8000D738 {
s32 unk0;
@ -25,8 +26,8 @@ struct UnkStruct800AA664 {
char padding1B0[0x2030];
};
extern struct UnkStruct800AA660 *D_800AA660;
extern struct UnkStruct800AA664 *D_800AA664;
extern struct UnkStruct800AA660* D_800AA660;
extern struct UnkStruct800AA664* D_800AA664;
extern char D_800AA668;
extern u8 D_81200000[];
@ -40,20 +41,20 @@ void func_81206D9C(void);
void func_81206E64(void);
void func_81206F38(void);
void func_80005370(struct UnkStruct800AA660 *);
void func_80004454(u32, void *, void *);
void func_80005370(struct UnkStruct800AA660*);
void func_80004454(u32, void*, void*);
char func_8000B318(char);
s32 func_800044F4(void *, void *, s32, s32);
s32 func_800044F4(void*, void*, s32, s32);
s32 func_8000484C(s32, s32);
void func_8000D5C0(void* unused) {
void (*func)(void *) = convert_addr_to_virt_addr(&func_81206F38);
void (*func)(void*) = Util_ConvertAddrToVirtAddr(&func_81206F38);
__osSetFpcCsr(0x01000C01);
func_80004CC0(D_800AA664, 0, 1);
func_80005328(D_800AA664);
while(1) {
while (1) {
func_80004CF4(D_800AA664);
if (D_800A62E0.unkA38 >= 0x15) {
continue;
@ -62,9 +63,9 @@ void func_8000D5C0(void* unused) {
}
}
void func_8000D678(void *unused) {
void (*func1)(void *func) = convert_addr_to_virt_addr(&func_81206D9C);
void (*func2)(void *func) = convert_addr_to_virt_addr(&func_81206E64);
void func_8000D678(void* unused) {
void (*func1)(void* func) = Util_ConvertAddrToVirtAddr(&func_81206D9C);
void (*func2)(void* func) = Util_ConvertAddrToVirtAddr(&func_81206E64);
__osSetFpcCsr(0x01000C01);
func_80004CC0(D_800AA660, 0, 1);
@ -72,7 +73,7 @@ void func_8000D678(void *unused) {
func1(D_800AA660);
osStartThread(D_800AA664);
while(1) {
while (1) {
func_80004CF4(D_800AA660);
if (D_800A62E0.unkA38 >= 0x15) {
continue;
@ -87,14 +88,15 @@ void func_8000D738(struct UnkInputStruct8000D738* arg0) {
main_pool_push_state('GBEM');
D_800AA660 = (void*)main_pool_alloc_node_no_func(0x2210, 0);
D_800AA664 = (void*)main_pool_alloc_node_no_func(0x21E0, 0);
func_80004454(((u32) ((u32) &fragment1_TEXT_START & 0x0FF00000) >> 0x14) - 0x10, &fragment1_ROM_START, &fragment1_ROM_END);
func_80004454(((u32)((u32)&fragment1_TEXT_START & 0x0FF00000) >> 0x14) - 0x10, &fragment1_ROM_START,
&fragment1_ROM_END);
temp_v0 = func_800044F4(&D_3BA190, &D_3CB130, 1, 1);
D_800AA660->unk21FC = func_8000484C(temp_v0, 0);
D_800AA660->unk2200 = func_8000484C(temp_v0, 1);
D_800AA660->unk2204 = *arg0;
osCreateMesgQueue(&D_800AA660->queue, &D_800AA660->mesg, 1);
osCreateThread(&D_800AA664->thread, 10, func_8000D5C0, NULL, (u32)D_800AA664 + 0x21E0, 0x11);
osCreateThread(&D_800AA660->thread, 8, func_8000D678, NULL, (u32)D_800AA660 + 0x21E0, 0xF);
osCreateThread(&D_800AA664->thread, 10, func_8000D5C0, NULL, (u32)D_800AA664 + 0x21E0, 0x11);
osCreateThread(&D_800AA660->thread, 8, func_8000D678, NULL, (u32)D_800AA660 + 0x21E0, 0xF);
D_800AA668 = func_8000B318(0);
osStartThread(&D_800AA660->thread);
}

View File

@ -23,17 +23,17 @@ void Cont_InitControllers(void) {
int i;
// clear each gControllers member.
for(i = 0; i < MAXCONTROLLERS; i++) {
for (i = 0; i < MAXCONTROLLERS; i++) {
bzero((void*)&gControllers[i], sizeof(struct Controller));
}
// Initialize each connected controller.
for(i = 0; i < MAXCONTROLLERS; i++) {
for (i = 0; i < MAXCONTROLLERS; i++) {
// If the bit is set in this bitfield for each iteration, it means
// the controller is connected. Set the ID and pointers respectively.
if(gControllerBits & (1 << i)) {
gControllers[i].contId = (i+1); // indexed by 1. (cont 1, cont 2, etc)
gControllers[i].statusData = &gControllerStatuses[i];
if (gControllerBits & (1 << i)) {
gControllers[i].contId = (i + 1); // indexed by 1. (cont 1, cont 2, etc)
gControllers[i].statusData = &gControllerStatuses[i];
gControllers[i].controllerData = &gControllerPads[i];
}
}
@ -43,7 +43,7 @@ void Cont_InitControllers(void) {
* Take the updated controller struct and calculate
* the new x, y, and distance floats.
*/
void Cont_AdjustAnalogStick(struct Controller *controller) {
void Cont_AdjustAnalogStick(struct Controller* controller) {
// reset the controller's x and y floats.
controller->stickX = 0.0f;
controller->stickY = 0.0f;
@ -66,8 +66,7 @@ void Cont_AdjustAnalogStick(struct Controller *controller) {
}
// calculate f32 magnitude from the center by vector length.
controller->stickMag =
sqrtf(controller->stickX * controller->stickX + controller->stickY * controller->stickY);
controller->stickMag = sqrtf(controller->stickX * controller->stickX + controller->stickY * controller->stickY);
// magnitude cannot exceed 64.0f: if it does, modify the values appropriately to
// flatten the values down to the allowed maximum value.
@ -77,7 +76,6 @@ void Cont_AdjustAnalogStick(struct Controller *controller) {
controller->stickMag = 64;
}
if (controller->stickMag > 0.0f) {
controller->unkE = func_8000A360(-controller->stickY, controller->stickX);
}
@ -97,23 +95,22 @@ void Cont_StartReadInputs(void) {
*/
void Cont_ReadInputs(void) {
s32 i;
struct Controller *controller = &gControllers[0];
struct Controller* controller = &gControllers[0];
osRecvMesg(&gSIEventMesgQueue, NULL, OS_MESG_BLOCK);
osContGetReadData(&gControllerPads[0]);
Cont_NoBlockEepromQueue();
for(i = 0; i < 4; i++, controller++) {
for (i = 0; i < 4; i++, controller++) {
// if the contId is not 0, it means the controller is initialized.
if(controller->contId != 0) {
if (controller->contId != 0) {
controller->rawStickX = controller->controllerData->stick_x;
controller->rawStickY = controller->controllerData->stick_y;
controller->buttonPressed = controller->controllerData->button
& (controller->controllerData->button ^ controller->buttonDown);
controller->unkA = controller->buttonDown
& (controller->controllerData->button ^ controller->buttonDown);
controller->buttonPressed =
controller->controllerData->button & (controller->controllerData->button ^ controller->buttonDown);
controller->unkA = controller->buttonDown & (controller->controllerData->button ^ controller->buttonDown);
controller->buttonDown = controller->controllerData->button;
Cont_AdjustAnalogStick(controller);
} else {
controller->buttonPressed = 0;
@ -156,7 +153,7 @@ s32 Cont_AttemptReadEeprom(u8* buffer, u32 size, s32 inaddr) {
// specified by http://n64devkit.square7.ch/n64man/os/osEepromLongRead.htm.
// Force the value to be a multiple of 8 to adhere to the restrictions.
s32 address = ALIGN8(inaddr);
i --;
i--;
// once the result is 0 (success), exit from the loop since the write was successful.
result = osEepromLongRead(&gSIEventMesgQueue, count, buffer, address);
} while (i > 0 && result);
@ -182,7 +179,7 @@ s32 Cont_AttemptWriteEeprom(u8* buffer, u32 size, s32 inaddr) {
// specified by http://n64devkit.square7.ch/n64man/os/osEepromLongRead.htm.
// Force the value to be a multiple of 8 to adhere to the restrictions.
s32 address = ALIGN8(inaddr);
i --;
i--;
// once the result is 0 (success), exit from the loop since the write was successful.
result = osEepromLongWrite(&gSIEventMesgQueue, count, buffer, address);
} while (i > 0 && result);

View File

@ -7,28 +7,27 @@
#include "memmap.h"
#include "controller.h"
extern void *D_80068BA0[];
extern void* D_80068BA0[];
CrashScreen gCrashScreen;
u8 gCrashScreenCharToGlyph[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42,
-1, 39, 44, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42, -1, 39, 44, -1, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
};
u32 gCrashScreenFont[] = {
0x70871C30, 0x8988A250, 0x88808290, 0x88831C90, 0x888402F8, 0x88882210, 0x71CF9C10, 0xF9CF9C70, 0x8228A288,
0xF200A288, 0x0BC11C78, 0x0A222208, 0x8A222288, 0x71C21C70, 0x23C738F8, 0x5228A480, 0x8A282280, 0x8BC822F0,
0xFA282280, 0x8A28A480, 0x8BC738F8, 0xF9C89C08, 0x82288808, 0x82088808, 0xF2EF8808, 0x82288888, 0x82288888,
0x81C89C70, 0x8A08A270, 0x920DA288, 0xA20AB288, 0xC20AAA88, 0xA208A688, 0x9208A288, 0x8BE8A270, 0xF1CF1CF8,
0x8A28A220, 0x8A28A020, 0xF22F1C20, 0x82AA0220, 0x82492220, 0x81A89C20, 0x8A28A288, 0x8A28A288, 0x8A289488,
0x8A2A8850, 0x894A9420, 0x894AA220, 0x70852220, 0xF8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400,
0x80020800, 0xF8011000, 0x70800000, 0x88822200, 0x08820400, 0x108F8800, 0x20821000, 0x00022200, 0x20800020,
0x00000000,
0x70871C30, 0x8988A250, 0x88808290, 0x88831C90, 0x888402F8, 0x88882210, 0x71CF9C10, 0xF9CF9C70,
0x8228A288, 0xF200A288, 0x0BC11C78, 0x0A222208, 0x8A222288, 0x71C21C70, 0x23C738F8, 0x5228A480,
0x8A282280, 0x8BC822F0, 0xFA282280, 0x8A28A480, 0x8BC738F8, 0xF9C89C08, 0x82288808, 0x82088808,
0xF2EF8808, 0x82288888, 0x82288888, 0x81C89C70, 0x8A08A270, 0x920DA288, 0xA20AB288, 0xC20AAA88,
0xA208A688, 0x9208A288, 0x8BE8A270, 0xF1CF1CF8, 0x8A28A220, 0x8A28A020, 0xF22F1C20, 0x82AA0220,
0x82492220, 0x81A89C20, 0x8A28A288, 0x8A28A288, 0x8A289488, 0x8A2A8850, 0x894A9420, 0x894AA220,
0x70852220, 0xF8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400, 0x80020800, 0xF8011000,
0x70800000, 0x88822200, 0x08820400, 0x108F8800, 0x20821000, 0x00022200, 0x20800020, 0x00000000,
};
const char* gFaultCauses[18] = {
@ -53,43 +52,27 @@ const char* gFaultCauses[18] = {
};
const char* gFPCSRFaultCauses[6] = {
"Unimplemented operation",
"Invalid operation",
"Division by zero",
"Overflow",
"Underflow",
"Inexact operation",
"Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", "Inexact operation",
};
/*
* To unlock the screen for viewing, press these buttons in sequence
* on controller 1 once the game crashes.
*/
u16 gCrashScreenUnlockInputs[] = {
U_JPAD,
D_JPAD,
L_JPAD,
R_JPAD,
U_CBUTTONS,
D_CBUTTONS,
L_CBUTTONS,
R_CBUTTONS,
B_BUTTON,
A_BUTTON
};
u16 gCrashScreenUnlockInputs[] = { U_JPAD, D_JPAD, L_JPAD, R_JPAD, U_CBUTTONS,
D_CBUTTONS, L_CBUTTONS, R_CBUTTONS, B_BUTTON, A_BUTTON };
void crash_screen_sleep(s32 ms) {
u64 cycles = OS_USEC_TO_CYCLES(ms * 1000LL); // why not just do OS_NSEC_TO_CYCLES and not multiply by 1000LL?
osSetTime(0);
while (osGetTime() < cycles) {
}
while (osGetTime() < cycles) {}
}
void crash_screen_wait_for_button_combo(void) {
s32 breakloop = FALSE;
s32 i = 0;
do {
Cont_StartReadInputs();
Cont_ReadInputs();
@ -174,12 +157,12 @@ void crash_screen_draw_glyph(s32 x, s32 y, s32 glyph) {
}
}
char *crash_screen_copy_to_buf(char *buffer, const char *data, size_t size) {
return (char *) memcpy(buffer, data, size) + size;
char* crash_screen_copy_to_buf(char* buffer, const char* data, size_t size) {
return (char*)memcpy(buffer, data, size) + size;
}
void crash_screen_printf(s32 x, s32 y, const char *fmt, ...) {
signed char *ptr;
void crash_screen_printf(s32 x, s32 y, const char* fmt, ...) {
signed char* ptr;
u32 glyph;
s32 size;
signed char buf[0x100];
@ -187,7 +170,7 @@ void crash_screen_printf(s32 x, s32 y, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
size = _Printf(crash_screen_copy_to_buf, (char *)buf, fmt, args);
size = _Printf(crash_screen_copy_to_buf, (char*)buf, fmt, args);
if (size > 0) {
ptr = buf;
@ -210,14 +193,14 @@ void crash_screen_printf(s32 x, s32 y, const char *fmt, ...) {
va_end(args);
}
void crash_screen_print_fpr(s32 x, s32 y, s32 regNum, void *addr) {
void crash_screen_print_fpr(s32 x, s32 y, s32 regNum, void* addr) {
u32 bits;
s32 exponent;
bits = *(u32 *) addr;
bits = *(u32*)addr;
exponent = ((bits & 0x7f800000U) >> 0x17) - 0x7f;
if ((exponent >= -0x7e && exponent <= 0x7f) || bits == 0) {
crash_screen_printf(x, y, "F%02d:%+.3e", regNum, *(f32 *) addr);
crash_screen_printf(x, y, "F%02d:%+.3e", regNum, *(f32*)addr);
} else {
crash_screen_printf(x, y, "F%02d:---------", regNum);
}
@ -299,20 +282,20 @@ void crash_screen_draw(OSThread* faultedThread) {
crash_screen_print_fpr(30, 220, 30, &ctx->fp30.f.f_even);
ret = Memmap_GetLoadedFragmentVaddr(ctx->pc);
if(ret != 0) {
crash_screen_printf(120, 220, "F-PC:%08XH", ret-0x20);
if (ret != 0) {
crash_screen_printf(120, 220, "F-PC:%08XH", ret - 0x20);
}
ret = Memmap_GetLoadedFragmentVaddr((u32)ctx->ra);
if(ret != 0) {
crash_screen_printf(210, 220, "F-RA:%08XH", ret-0x20);
if (ret != 0) {
crash_screen_printf(210, 220, "F-RA:%08XH", ret - 0x20);
}
crash_screen_sleep(500);
// all of these null terminators needed to pad the rodata section for this file
// can potentially fix this problem in another way?
crash_screen_printf(210, 140, "MM:%08XH", *(u32 *)(uintptr_t)ctx->pc);
crash_screen_printf(210, 140, "MM:%08XH", *(u32*)(uintptr_t)ctx->pc);
}
OSThread* crash_screen_get_faulted_thread(void) {
@ -345,7 +328,7 @@ void crash_screen_thread_entry(UNUSED void* unused) {
crash_screen_wait_for_button_combo();
crash_screen_draw(faultedThread);
while(TRUE){}
while (TRUE) {}
}
void crash_screen_set_draw_info(u16* frameBufPtr, u16 width, u16 height) {
@ -373,7 +356,7 @@ void crash_screen_printf_with_bg(s16 x, s16 y, const char* fmt, ...) {
va_start(args, fmt);
size = _Printf(crash_screen_copy_to_buf, (char *)buf, fmt, args);
size = _Printf(crash_screen_copy_to_buf, (char*)buf, fmt, args);
if (size > 0) {
crash_screen_draw_rect(x - 6, y - 6, (size + 2) * 6, 19);
@ -394,4 +377,3 @@ void crash_screen_printf_with_bg(s16 x, s16 y, const char* fmt, ...) {
va_end(args);
}

View File

@ -25,7 +25,7 @@ void crash_screen_draw_glyph(s32 x, s32 y, s32 glyph);
char *crash_screen_copy_to_buf(char *buffer, const char *data, size_t size);
void crash_screen_printf(s32 x, s32 y, const char *fmt, ...);
void crash_screen_print_fpr(s32 x, s32 y, s32 regNum, void *addr);
void crash_screen_print_fpcsr(u32 value);
void crash_screen_print_fpcsr(u32 fpcsr);
void crash_screen_draw(OSThread* faultedThread);
OSThread* crash_screen_get_faulted_thread(void);
void crash_screen_thread_entry(void* unused);

View File

@ -6,10 +6,10 @@
extern u32 D_800818E0;
extern s16 D_80083C1C;
s32 func_80000E80(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
s32 func_80000E80(s32 arg0, void* arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
if (arg0 == 0) {
temp_v0->unk0 = 0xF0;
@ -25,25 +25,25 @@ s32 func_80000E80(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5)
return temp_v0 == NULL;
}
s32 func_80000F0C(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4) {
s32 func_80000F0C(s32 arg0, void* arg1, s32 arg2, s32 arg3, s32 arg4) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 0xF4;
temp_v0->unk1C = (uintptr_t)arg1;
temp_v0->unk24 = arg2;
temp_v0->unk20 = (void *)(uintptr_t)arg0;
temp_v0->unk20 = (void*)(uintptr_t)arg0;
temp_v0->unk28 = arg3;
func_80000E2C(temp_v0, arg4);
}
return temp_v0 == NULL;
}
s32 func_80000F80(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
s32 func_80000F80(s32 arg0, void* arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
if (arg0 == 0) {
temp_v0->unk0 = 0xF2;
@ -59,10 +59,10 @@ s32 func_80000F80(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5)
return temp_v0 == NULL;
}
s32 func_8000100C(s32 arg0, void *arg1, s16 arg2, s32 arg3, s32 arg4) {
s32 func_8000100C(s32 arg0, void* arg1, s16 arg2, s32 arg3, s32 arg4) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
if (arg0 == 0) {
temp_v0->unk0 = 0xF5;
@ -78,10 +78,10 @@ s32 func_8000100C(s32 arg0, void *arg1, s16 arg2, s32 arg3, s32 arg4) {
return temp_v0 == NULL;
}
s32 func_80001098(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
s32 func_80001098(s32 arg0, void* arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
if (arg0 == 0) {
temp_v0->unk0 = 5;
@ -100,7 +100,7 @@ s32 func_80001098(s32 arg0, void *arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5)
s32 func_80001124(s32 arg0, s32 arg1) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 0xC;
temp_v0->unk20 = &D_800818E0;
@ -113,7 +113,7 @@ s32 func_80001124(s32 arg0, s32 arg1) {
s32 func_80001184(s32 arg0, s32 arg1, s32 arg2) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 7;
temp_v0->unk1C = arg0;
@ -124,9 +124,9 @@ s32 func_80001184(s32 arg0, s32 arg1, s32 arg2) {
}
s32 func_800011E4(s32 arg0, s32 arg1) {
struct UnkStruct80000E80 * temp_v0;
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 8;
temp_v0->unk1C = 0;
@ -139,7 +139,7 @@ s32 func_800011E4(s32 arg0, s32 arg1) {
s32 func_8000123C(s32 arg0, s32 arg1) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 8;
temp_v0->unk1C = 4;
@ -149,10 +149,10 @@ s32 func_8000123C(s32 arg0, s32 arg1) {
return temp_v0 == NULL;
}
s32 func_80001298(void *arg0, s32 arg1, s32 arg2) {
s32 func_80001298(void* arg0, s32 arg1, s32 arg2) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 0xE;
temp_v0->unk20 = arg0;
@ -166,10 +166,10 @@ s16 func_800012F8(void) {
return D_80083C1C;
}
s32 func_80001304(void *arg0, s32 arg1, s32 arg2) {
s32 func_80001304(void* arg0, s32 arg1, s32 arg2) {
struct UnkStruct80000E80* temp_v0;
temp_v0 = func_80002FDC(0x2C);
temp_v0 = Util_Malloc(0x2C);
if (temp_v0 != NULL) {
temp_v0->unk0 = 0xD;
temp_v0->unk20 = arg0;

View File

@ -28,11 +28,11 @@ struct UnkStruct80083CA0_2 {
OSThread thread;
char filler1B0[0x18];
s32 unk1C8;
u8 filler1CC[0x9E0-0x1CC];
struct UnkArray4 *unk9E0;
char filler9E4[0xA2C-0x9E4];
u8 filler1CC[0x9E0 - 0x1CC];
struct UnkArray4* unk9E0;
char filler9E4[0xA2C - 0x9E4];
s32 unkA2C;
char fillerA30[0xA88-0xA30];
char fillerA30[0xA88 - 0xA30];
u16 unkA88;
u8 unkA8A;
u8 unkA8B;
@ -82,7 +82,7 @@ extern s32 osTvType;
extern char D_80068B74[];
extern f32 D_8007AF10;
extern OSViMode D_800796E0[]; // osViModeTable
extern OSViMode D_800796E0[]; // osViModeTable
extern void func_8000183C(void*);
@ -97,7 +97,7 @@ extern OSMesg D_80084688;
extern s32 D_80084758;
// .bss?
extern u64 D_80084760[0x100/sizeof(u64)];
extern u64 D_80084760[0x100 / sizeof(u64)];
// function prototypes
void func_80001AD4(u16 arg0);
@ -106,23 +106,23 @@ void func_80001C1C(struct UnkArray4* arg0, u8 arg1, u8 arg2, u8 arg3, u8 arg4, s
void func_80001380(struct UnkStruct80001380* arg0) {
arg0->task.t.type = 1;
arg0->task.t.flags = 0;
arg0->task.t.ucode_boot = D_80084760;
arg0->task.t.ucode_boot_size = 0x100;
arg0->task.t.ucode = F3DEX2_bin;
arg0->task.t.ucode_data = F3DEX2_data_bin;
arg0->task.t.ucode_size = 0x1000;
arg0->task.t.ucode_data_size = 0x800;
arg0->task.t.dram_stack = (void *)ALIGN16((uintptr_t)D_80084860);
arg0->task.t.dram_stack_size = 0x400;
arg0->task.t.yield_data_ptr = (void *)ALIGN16((uintptr_t)D_80084C68);
arg0->task.t.yield_data_size = 0xC00;
arg0->task.t.output_buff = (D_80085870);
arg0->task.t.output_buff_size = (D_80085870 + (0x20000/sizeof(u64)));
arg0->task.t.ucode_boot = D_80084760;
arg0->task.t.ucode_boot_size = 0x100;
arg0->task.t.ucode = F3DEX2_bin;
arg0->task.t.ucode_data = F3DEX2_data_bin;
arg0->task.t.ucode_size = 0x1000;
arg0->task.t.ucode_data_size = 0x800;
arg0->task.t.dram_stack = (void*)ALIGN16((uintptr_t)D_80084860);
arg0->task.t.dram_stack_size = 0x400;
arg0->task.t.yield_data_ptr = (void*)ALIGN16((uintptr_t)D_80084C68);
arg0->task.t.yield_data_size = 0xC00;
arg0->task.t.output_buff = (D_80085870);
arg0->task.t.output_buff_size = (D_80085870 + (0x20000 / sizeof(u64)));
osCreateMesgQueue(&arg0->queue, &arg0->mesg, 1);
}
void func_80001444(struct UnkStruct80001380* arg0, struct UnkArray4* arg1, s32 arg2) {
arg0->task.t.data_ptr = (void *)(uintptr_t)arg1->unk4;
arg0->task.t.data_ptr = (void*)(uintptr_t)arg1->unk4;
arg0->task.t.data_size = arg1->unk8;
func_800053B4(arg0, arg2);
}
@ -135,7 +135,7 @@ void func_80001474(s8 arg0, s8 arg1) {
} else {
var_v0 = (arg0 * 2) + arg1 + 4;
}
osViSetMode(&D_800796E0[(s32)D_80068B74[var_v0]]);
osViSetSpecialFeatures(0x40U);
osViSetSpecialFeatures(2U);
@ -172,7 +172,8 @@ void func_800015A8(void) {
if (D_80083CA0.unkAA0 != 0) {
func_800049AC(&D_800846C0);
}
if ((D_80083CA0.unkA90 != 0) && (D_80083CA0.unkAB8 != D_80083CA0.unkA98) && (D_80083CA0.unkAAF != D_80083CA0.unkA8F)) {
if ((D_80083CA0.unkA90 != 0) && (D_80083CA0.unkAB8 != D_80083CA0.unkA98) &&
(D_80083CA0.unkAAF != D_80083CA0.unkA8F)) {
func_80001444(&D_800846C0, &D_8008472C, 1);
sp20 = 1;
}
@ -188,22 +189,22 @@ void func_800015A8(void) {
} while (D_80083CA0.unk1C8 > 0);
}
if (D_80083CA0.unkAA8 != NULL) {
osViSwapBuffer((void *)(uintptr_t)D_80083CA0.unkAA8->unk8);
osViSwapBuffer((void*)(uintptr_t)D_80083CA0.unkAA8->unk8);
osViRepeatLine(0);
if ((D_80083CA0.unkA9D != D_80083CA0.unkAAD) || (D_80083CA0.unkA9E != D_80083CA0.unkAAE)) {
func_80001474((s8) D_80083CA0.unkA9D, (s8) D_80083CA0.unkA9E);
func_80001474((s8)D_80083CA0.unkA9D, (s8)D_80083CA0.unkA9E);
}
if (D_80068B70 != 0) {
osViBlack(1U);
} else {
osViBlack(0U);
}
crash_screen_set_draw_info((void *)(uintptr_t)D_80083CA0.unkAA8->unk8, *(u16 *)&D_80083CA0.unkAA8->unk4, 0x10);
crash_screen_set_draw_info((void*)(uintptr_t)D_80083CA0.unkAA8->unk8, *(u16*)&D_80083CA0.unkAA8->unk4, 0x10);
} else {
osViRepeatLine(1);
osViSwapBuffer((void *)(uintptr_t)D_80083CA0.unk9E0->unk8);
osViSwapBuffer((void*)(uintptr_t)D_80083CA0.unk9E0->unk8);
if ((D_80083CA0.unkA9D != D_80083CA0.unkAAD) || (D_80083CA0.unkA9E != D_80083CA0.unkAAE)) {
func_80001474((s8) D_80083CA0.unkA9D, (s8) D_80083CA0.unkA9E);
func_80001474((s8)D_80083CA0.unkA9D, (s8)D_80083CA0.unkA9E);
}
}
if ((sp20 == 0) && (D_80083CA0.unkA90 != 0)) {
@ -225,14 +226,14 @@ void func_800017E4(void) {
func_80004CF4(&D_80083CA0);
}
void func_8000183C(UNUSED void *arg) {
void func_8000183C(UNUSED void* arg) {
__osSetFpcCsr(0x01000C01);
func_80001C1C(&D_8008474C, 0, 1, 2, 0xFF, 0, 0, 0);
func_80001C1C(&D_8008473C, 0, 1, 2, 0xFF, 0, 0, 0);
func_80004CC0(&D_80083CA0.thread, 0, 4);
func_80005328(&D_80083CA0);
func_80001380(&D_800846C0);
while(1) {
while (1) {
void* sp4C;
if (D_800A62E0.unkA38 > 0) {
func_800017E4();
@ -246,7 +247,7 @@ void func_8000183C(UNUSED void *arg) {
profiler_log_thread5_time(UNK_EVENT_2);
func_8000152C(sp4C);
func_800015A8();
osSendMesg(&D_800846A4, (void* )0x444F4E45, 0);
osSendMesg(&D_800846A4, (void*)0x444F4E45, 0);
}
}
@ -255,7 +256,9 @@ void func_800019C8(void) {
if ((temp_v0 != 1) && (temp_v0 != 2)) {
osViBlack(1U);
while(1);
while (1) {
;
}
}
osCreateThread(&D_80083CA0.thread, 5, func_8000183C, NULL, &D_80084680, 0x28);
osStartThread(&D_80083CA0.thread);
@ -270,26 +273,27 @@ void func_800019C8(void) {
void func_80001AD4(u16 arg0) {
s32 i = 0x280;
u16 *arr = (void *)(uintptr_t)D_80083CA0.unk9E0->unk8;
u16* arr = (void*)(uintptr_t)D_80083CA0.unk9E0->unk8;
while(i --> 0) {
while (i-- > 0) {
*(arr)++ = arg0;
}
osWritebackDCache((void *)(uintptr_t)D_80083CA0.unk9E0->unk8, 0x500);
osWritebackDCache((void*)(uintptr_t)D_80083CA0.unk9E0->unk8, 0x500);
}
u16 func_80001B2C(void) {
// YIKES. What is this typing?!?
u16 *ptr = (u16*)(uintptr_t)((u32 *)(uintptr_t)D_80084680[0])[2];
u16* ptr = (u16*)(uintptr_t)((u32*)(uintptr_t)D_80084680[0])[2];
return *ptr;
}
s32 func_80001B40(void) {
s32 result = 0;
if (osViGetCurrentFramebuffer() == ((void **)(uintptr_t)D_80084680[0])[2])
if (osViGetCurrentFramebuffer() == ((void**)(uintptr_t)D_80084680[0])[2]) {
result = 1;
}
return result;
}
@ -303,9 +307,9 @@ void func_80001BA8(void* arg0) {
}
void func_80001BD4(s32 arg0) {
while(arg0 --> 0) {
while (arg0-- > 0) {
func_80001BA8(0);
func_80001B7C();
func_80001B7C();
}
}

View File

@ -30,11 +30,8 @@ s32 func_8000A630(s32 arg0, void* arg1) {
s32 sp20 = 0;
UNUSED u8 padding[8];
if ((func_8000AF40(arg0, arg1, 0, 0x20) == 0)
&& (func_8000AEBC(arg0, (uintptr_t)&sp24, 0, 0x20) == 0)
&& (bcmp(&sp24, arg1, 0x20) == 0)
&& (osGbpakGetStatus(&D_800A8100[arg0], &sp47) == 0))
{
if ((func_8000AF40(arg0, arg1, 0, 0x20) == 0) && (func_8000AEBC(arg0, (uintptr_t)&sp24, 0, 0x20) == 0) &&
(bcmp(&sp24, arg1, 0x20) == 0) && (osGbpakGetStatus(&D_800A8100[arg0], &sp47) == 0)) {
sp20 = ((sp47 & 4) != 0) == 0;
}
return sp20;
@ -47,25 +44,25 @@ s32 func_8000A6D8(s32 arg0, u8* arg1) {
if (arg1 == NULL) {
arg1 = sp34;
}
HAL_Memset((char *)arg1, 0x55, 0x20);
HAL_Memset((char*)arg1, 0x55, 0x20);
if (func_8000A630(arg0, arg1) != 0) {
HAL_Memset((char *)arg1, 0xAA, 0x20);
HAL_Memset((char*)arg1, 0xAA, 0x20);
if (func_8000A630(arg0, arg1) != 0) {
s32 i;
for (i = 0; i < ARRAY_COUNT(sp34); i++) {
arg1[i] = osGetCount();
}
}
var_s0 = func_8000A630(arg0, arg1);
}
}
return var_s0;
}
s32 func_8000A798(s32 arg0, u8 *arg1, u8 *arg2) {
s32 func_8000A798(s32 arg0, u8* arg1, u8* arg2) {
u8 status;
OSGbpakId gbpakId;
s32 sp28 = 0;
if (arg1 != NULL) {
*arg1 = D_800A82A0[arg0];
}
@ -104,7 +101,7 @@ s32 func_8000A888(s32 arg0, u8 arg1) {
void func_8000A924(void) {
s32 i;
for(i = 0; i < 4; i++) {
for (i = 0; i < 4; i++) {
if (D_800A82A4 & (1 << i)) {
osGbpakPower(&D_800A8100[i], 0);
D_800A82A0[i] = 0;
@ -119,16 +116,16 @@ s32 func_8000A9D0(OSGbpakId* header) {
// is the cartridge non-Japanese?
if (header->country_code == 1) {
// Which supported POKeMON version is this?
if (HAL_Strcmp((char *)header->game_title, "POKEMON RED") == 0) {
if (HAL_Strcmp((char*)header->game_title, "POKEMON RED") == 0) {
return 1;
}
if (HAL_Strcmp((char *)header->game_title, "POKEMON GREEN") == 0) {
if (HAL_Strcmp((char*)header->game_title, "POKEMON GREEN") == 0) {
return 1;
}
if (HAL_Strcmp((char *)header->game_title, "POKEMON BLUE") == 0) {
if (HAL_Strcmp((char*)header->game_title, "POKEMON BLUE") == 0) {
return 1;
}
if (HAL_Strcmp((char *)header->game_title, "POKEMON YELLOW") == 0) {
if (HAL_Strcmp((char*)header->game_title, "POKEMON YELLOW") == 0) {
return 1;
}
}
@ -148,7 +145,7 @@ s32 func_8000AA7C(void) {
D_800A82A8 = 0;
osPfsIsPlug(&gSIEventMesgQueue, &D_800A82A6);
for(i = 0; i < 4; i++) {
for (i = 0; i < 4; i++) {
if ((D_800A82A6 & (1 << i)) && ((i != 3) || (func_8000B4C4() == 0))) {
if (osGbpakInit(&gSIEventMesgQueue, &D_800A8100[i], i) == 0) {
D_800A82A4 |= (1 << i);
@ -191,11 +188,9 @@ s32 func_8000AC7C(s32 arg0) {
// check the error code returned (if applicable) by the osGbpakGetStatus
// call.
if ((ret == PFS_ERR_NOPACK)
|| (ret == PFS_ERR_DEVICE)
|| (ret == PFS_ERR_CONTRFAIL)) {
if ((ret == PFS_ERR_NOPACK) || (ret == PFS_ERR_DEVICE) || (ret == PFS_ERR_CONTRFAIL)) {
func_8002B274(arg0, 1);
}
}
return !((status & OS_GBPAK_GBCART_ON) != 0);
}
@ -203,9 +198,7 @@ s32 func_8000ACF4(s32 arg0) {
u8 status;
s32 ret = osGbpakGetStatus(&D_800A8100[arg0], &status);
if ((ret == PFS_ERR_NOPACK)
|| (ret == PFS_ERR_DEVICE)
|| (ret == PFS_ERR_CONTRFAIL)) {
if ((ret == PFS_ERR_NOPACK) || (ret == PFS_ERR_DEVICE) || (ret == PFS_ERR_CONTRFAIL)) {
func_8002B274(arg0, 1);
}
return ((status & OS_GBPAK_GBCART_ON) != 0);
@ -217,15 +210,14 @@ s32 func_8000AD68(s32 arg0) {
OSGbpakId sp28;
D_800A82A0[arg0] = 0;
if ((osGbpakInit(&gSIEventMesgQueue, &D_800A8100[arg0], arg0) == 0)
&& (osGbpakReadId(&D_800A8100[arg0], &sp28, &status) == 0)
&& (status & OS_GBPAK_RSTB_STATUS)
&& (osGbpakCheckConnector(&D_800A8100[arg0], &status) == 0)) {
if ((osGbpakInit(&gSIEventMesgQueue, &D_800A8100[arg0], arg0) == 0) &&
(osGbpakReadId(&D_800A8100[arg0], &sp28, &status) == 0) && (status & OS_GBPAK_RSTB_STATUS) &&
(osGbpakCheckConnector(&D_800A8100[arg0], &status) == 0)) {
func_8000D970(&D_800A8100[arg0]);
D_800A82A0[arg0] = 1;
}
return D_800A82A0[arg0] == 1;
}
@ -235,9 +227,8 @@ s32 func_8000AE28(s32 arg0, void* arg1) {
s32 sp18;
sp18 = 0;
if ((func_8000AEBC(arg0, (uintptr_t)&sp1C, 0, 0x20) == 0) && (bcmp(&sp1C, arg1, 0x20) == 0)
&& (osGbpakGetStatus(&D_800A8100[arg0], &status) == 0)
&& !(status & OS_GBPAK_RSTB_DETECTION)) {
if ((func_8000AEBC(arg0, (uintptr_t)&sp1C, 0, 0x20) == 0) && (bcmp(&sp1C, arg1, 0x20) == 0) &&
(osGbpakGetStatus(&D_800A8100[arg0], &status) == 0) && !(status & OS_GBPAK_RSTB_DETECTION)) {
sp18 = 1;
}
return sp18;
@ -263,7 +254,7 @@ s32 func_8000AF40(s32 arg0, void* arg1, u16 arg2, u16 arg3) {
return var_v1;
}
s32 func_8000AFC4(s32 arg0, u8 *arg1, u16 arg2, u16 arg3) {
s32 func_8000AFC4(s32 arg0, u8* arg1, u16 arg2, u16 arg3) {
s32 var_v1;
var_v1 = 1;
@ -273,7 +264,7 @@ s32 func_8000AFC4(s32 arg0, u8 *arg1, u16 arg2, u16 arg3) {
return var_v1;
}
s32 func_8000B048(s32 arg0, u8 *arg1, u16 arg2, u16 arg3) {
s32 func_8000B048(s32 arg0, u8* arg1, u16 arg2, u16 arg3) {
s32 var_v1;
var_v1 = 1;
@ -288,21 +279,21 @@ int func_8000B0CC(s32 arg0, s32 arg1) {
int i;
int ret;
for(i = 0; i < 0x20; i++) {
for (i = 0; i < 0x20; i++) {
sp28[i] = 0;
}
ret = func_8000B048(arg0, sp28, 0x5000U, 0x20U);
if (ret) {
return ret;
}
for(i = 0; i < 0x20; i++) {
for (i = 0; i < 0x20; i++) {
sp28[i] = (arg1 / 32);
}
ret = func_8000B048(arg0, sp28, 0x4000U, 0x20U);
if (ret) {
return ret;
}
for(i = 0; i < 0x20; i++) {
for (i = 0; i < 0x20; i++) {
sp28[i] = (arg1 % 32);
}
return func_8000B048(arg0, sp28, 0x2000U, 0x20U);
@ -312,7 +303,7 @@ s32 func_8000B1C4(s32 arg0, u8* arg1, s32 arg2, s32 arg3) {
s32 ret = 1;
u32 temp_s1 = (arg2 & ~0x1F);
u32 temp_s4 = ((arg2 + arg3) + 0x1F) & ~0x1F;
s32 temp_s1_2;
s32 temp_v0_4;
u32 temp_v0_5;

View File

@ -2,29 +2,27 @@
#include <string.h>
#include "hal_libc.h"
/*
/**
* Strcpy implementation; copy the strings terminated by 0. Return the original dest
* pointer.
*/
char* HAL_Strcpy(char* dest, char* src) {
char *newDest = dest;
while ((*(newDest++) = *(src++)) != '\0') {
}
char* newDest = dest;
while ((*(newDest++) = *(src++)) != '\0') {}
return dest;
}
/*
/**
* Alternate strcpy implementation; return the post-increment altered dest pointer.
*/
char* HAL_Strcpy2(char *dest, char* src) {
char* HAL_Strcpy2(char* dest, char* src) {
UNUSED size_t c = strlen(dest); // this is completely pointless. the strlen func called
// doesnt alter the pointer.
while ((*(dest++) = *(src++)) != '\0') {
}
while ((*(dest++) = *(src++)) != '\0') {}
return dest;
}
/*
/**
* Strcmp implementation. Compare two strings, terminated by 0. Return a 0 if success, return
* a positive value if the 2nd string is "greater" than the 1st, and vice versa.
*/
@ -45,10 +43,10 @@ size_t HAL_Strcmp(char* dest, char* src) {
// depending on where the mismatch occured, this subtraction operation
// will result in the correctly expected sign for whichever string is
// "greater".
return c1-c2;
return c1 - c2;
}
/*
/**
* Memset implementation. Given a value, set each byte in the given pointer to
* this value for every byte across a given specified size. Return the original
* pointer used.
@ -57,7 +55,7 @@ char* HAL_Memset(char* dest, s32 c, u32 nsize) {
char* newDest = dest;
// While the size is not 0, keep decrementing.
while( nsize --> 0 ) {
while (nsize-- > 0) {
*newDest++ = c;
}
return dest;

View File

@ -30,7 +30,7 @@ s32 LeoByteToLBA(s32 startlba, u32 nbytes, s32* lba) {
}
reslba++;
startlba++;
if ((nbytes != 0) && ((u32) startlba >= NUM_LBAS+0x18)) {
if ((nbytes != 0) && ((u32)startlba >= NUM_LBAS + 0x18)) {
return LEO_ERROR_LBA_OUT_OF_RANGE;
}
flag = 0;

View File

@ -4,78 +4,80 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
s32 LeoCJCreateLeoManager(OSPri comPri, OSPri intPri, OSMesg *cmdBuf, s32 cmdMsgCnt) {
OSPiHandle* driveRomHandle;
OSPiHandle* leoDiskHandle;
UNUSED volatile LEOCmdInquiry cmdBlockInq;
UNUSED volatile LEOCmd cmdBlockID;
LEODiskID thisID;
u32 stat;
u32 data;
s32 LeoCJCreateLeoManager(OSPri comPri, OSPri intPri, OSMesg* cmdBuf, s32 cmdMsgCnt) {
OSPiHandle* driveRomHandle;
OSPiHandle* leoDiskHandle;
UNUSED volatile LEOCmdInquiry cmdBlockInq;
UNUSED volatile LEOCmd cmdBlockID;
LEODiskID thisID;
u32 stat;
u32 data;
if (__leoActive) {
return LEO_ERROR_GOOD;
}
if (!LeoDriveExist()) {
return LEO_ERROR_DEVICE_COMMUNICATION_FAILURE;
}
leoDiskHandle = osLeoDiskInit();
driveRomHandle = osDriveRomInit();
__leoActive = 1;
__osSetHWIntrRoutine(1, __osLeoInterrupt, leoDiskStack);
leoInitialize(comPri, intPri, cmdBuf, cmdMsgCnt);
if (osResetType == 1) {
__leoSetReset();
}
cmdBlockInq.header.command = 2;
cmdBlockInq.header.reserve1 = 0;
cmdBlockInq.header.control = 0;
cmdBlockInq.header.reserve3 = 0;
leoCommand((void*)&cmdBlockInq);
{
volatile s32 dummy = (u32) &cmdBlockInq & 0xFFFFFF;
while (dummy > 0) {
dummy -= ((u32)__leoSetReset & 0xFFFFFF) | 0x403DF4;
if (__leoActive) {
return LEO_ERROR_GOOD;
}
}
while (cmdBlockInq.header.status == 8);
if (!LeoDriveExist()) {
return LEO_ERROR_DEVICE_COMMUNICATION_FAILURE;
}
if (cmdBlockInq.header.status != 0) {
return cmdBlockInq.header.sense;
}
leoDiskHandle = osLeoDiskInit();
driveRomHandle = osDriveRomInit();
__leoActive = 1;
__leoVersion.driver = cmdBlockInq.version;
__leoVersion.drive = 6;
__leoVersion.deviceType = cmdBlockInq.dev_type;
__leoVersion.ndevices = cmdBlockInq.dev_num;
__osSetHWIntrRoutine(1, __osLeoInterrupt, leoDiskStack);
leoInitialize(comPri, intPri, cmdBuf, cmdMsgCnt);
stat = __leoVersion.driver & 0xF;
if (stat == 4) {
LEO_country_code = 0;
} else if ((stat == 3) || (stat == 1)) {
volatile u32 dummy;
if (osResetType == 1) {
__leoSetReset();
}
osEPiReadIo(driveRomHandle, 0x9FF00, &data);
data = ((data & 0xFF000000) >> 0x18);
dummy = 0x3ED98F23;
if (data != 0xC3) {
cmdBlockInq.header.command = 2;
cmdBlockInq.header.reserve1 = 0;
cmdBlockInq.header.control = 0;
cmdBlockInq.header.reserve3 = 0;
leoCommand((void*)&cmdBlockInq);
{
volatile s32 dummy = (u32)&cmdBlockInq & 0xFFFFFF;
while (dummy > 0) {
dummy -= ((u32)__leoSetReset & 0xFFFFFF) | 0x403DF4;
}
}
while (cmdBlockInq.header.status == 8) {
;
}
if (cmdBlockInq.header.status != 0) {
return cmdBlockInq.header.sense;
}
__leoVersion.driver = cmdBlockInq.version;
__leoVersion.drive = 6;
__leoVersion.deviceType = cmdBlockInq.dev_type;
__leoVersion.ndevices = cmdBlockInq.dev_num;
stat = __leoVersion.driver & 0xF;
if (stat == 4) {
LEO_country_code = 0;
} else if ((stat == 3) || (stat == 1)) {
volatile u32 dummy;
osEPiReadIo(driveRomHandle, 0x9FF00, &data);
data = ((data & 0xFF000000) >> 0x18);
dummy = 0x3ED98F23;
if (data != 0xC3) {
while (1) {}
}
dummy *= data;
dummy -= (u32)&cmdBlockInq;
LEO_country_code = 0xE848D316;
} else {
while (1) {}
}
dummy *= data;
dummy -= (u32)&cmdBlockInq;
LEO_country_code = 0xE848D316;
} else {
while (1) {}
}
return LEO_ERROR_GOOD;
return LEO_ERROR_GOOD;
}

View File

@ -18,7 +18,7 @@ OSPiHandle* osDriveRomInit(void) {
__osPiRelAccess();
return &__DriveRomHandle;
}
first = 0;
__DriveRomHandle.type = DEVICE_TYPE_BULK;
__DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1);
@ -28,37 +28,36 @@ OSPiHandle* osDriveRomInit(void) {
while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) {}
//Keep the previous PI settings as we go to into the safest settings to read the PI info from DDROM.
// Keep the previous PI settings as we go to into the safest settings to read the PI info from DDROM.
latency = HW_REG(PI_BSD_DOM1_LAT_REG, u32);
pageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32);
release = HW_REG(PI_BSD_DOM1_RLS_REG, u32);
pulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32);
//Set the safest PI settings
// Set the safest PI settings
HW_REG(PI_BSD_DOM1_LAT_REG, u32) = 0xff;
HW_REG(PI_BSD_DOM1_PGS_REG, u32) = 0;
HW_REG(PI_BSD_DOM1_RLS_REG, u32) = 3;
HW_REG(PI_BSD_DOM1_PWD_REG, u32) = 0xff;
//Read the PI settings from DDROM and put it in __DriveRomHandle
// Read the PI settings from DDROM and put it in __DriveRomHandle
value = HW_REG(__DriveRomHandle.baseAddress, u32);
__DriveRomHandle.latency = value & 0xFF;
__DriveRomHandle.pageSize = (value >> 0x10) & 0xF;
__DriveRomHandle.relDuration = (value >> 0x14) & 0xF;
__DriveRomHandle.pulse = (value >> 8) & 0xFF;
//Put back the previous PI settings
// Put back the previous PI settings
HW_REG(PI_BSD_DOM1_LAT_REG, u32) = latency;
HW_REG(PI_BSD_DOM1_PGS_REG, u32) = pageSize;
HW_REG(PI_BSD_DOM1_RLS_REG, u32) = release;
HW_REG(PI_BSD_DOM1_PWD_REG, u32) = pulse;
saveMask = __osDisableInt();
__DriveRomHandle.next = __osPiTable;
__osPiTable = &__DriveRomHandle;
__osRestoreInt(saveMask);
__osPiRelAccess();
return &__DriveRomHandle;
}

View File

@ -26,7 +26,7 @@ s32 LeoLBAToByte(s32 startlba, u32 nlbas, s32* bytes) {
resbytes += byte_p_blk;
nlbas -= 1;
startlba += 1;
if ((nlbas > 0) && ((u32)startlba >= NUM_LBAS+0x18)) {
if ((nlbas > 0) && ((u32)startlba >= NUM_LBAS + 0x18)) {
return LEO_ERROR_LBA_OUT_OF_RANGE;
}
flag = 0;

View File

@ -7,29 +7,9 @@
// Firmware revision of libleo library.
const char LEOfirmware_rev[] = "B014A26";
const u8 LEOBYTE_TBL1[9] = {
0xE8,
0xD8,
0xD0,
0xC0,
0xB0,
0xA0,
0x90,
0x80,
0x70
};
const u8 LEOBYTE_TBL1[9] = { 0xE8, 0xD8, 0xD0, 0xC0, 0xB0, 0xA0, 0x90, 0x80, 0x70 };
const u16 LEOBYTE_TBL2[9] = {
0x4D08,
0x47B8,
0x4510,
0x3FC0,
0x3A70,
0x3520,
0x2FD0,
0x2A80,
0x2530
};
const u16 LEOBYTE_TBL2[9] = { 0x4D08, 0x47B8, 0x4510, 0x3FC0, 0x3A70, 0x3520, 0x2FD0, 0x2A80, 0x2530 };
const u16 LEOVZONE_TBL[][0x10] = {
{ 0x0124, 0x0248, 0x035A, 0x047E, 0x05A2, 0x06B4, 0x07C6, 0x08D8, 0x09EA, 0x0AB6, 0x0B82, 0x0C94, 0x0DA6, 0x0EB8,
@ -48,24 +28,8 @@ const u16 LEOVZONE_TBL[][0x10] = {
0x0FB8, 0x10DC },
};
const u16 LEOZONE_SCYL_TBL[16] = {
0x0000,
0x009E,
0x013C,
0x01D1,
0x0266,
0x02FB,
0x0390,
0x0425,
0x0091,
0x012F,
0x01C4,
0x0259,
0x02EE,
0x0383,
0x0418,
0x048A
};
const u16 LEOZONE_SCYL_TBL[16] = { 0x0000, 0x009E, 0x013C, 0x01D1, 0x0266, 0x02FB, 0x0390, 0x0425,
0x0091, 0x012F, 0x01C4, 0x0259, 0x02EE, 0x0383, 0x0418, 0x048A };
const u8 LEOVZONE_PZONEHD_TBL[][0x10] = {
{ 0x00, 0x01, 0x02, 0x09, 0x08, 0x03, 0x04, 0x05, 0x06, 0x07, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A },
@ -79,22 +43,6 @@ const u8 LEOVZONE_PZONEHD_TBL[][0x10] = {
const u16 LEOZONE_OUTERCYL_TBL[8] = { 0x0000, 0x009E, 0x013C, 0x01D1, 0x0266, 0x02FB, 0x0390, 0x0425 };
const u16 LEORAM_START_LBA[7] = {
0x05A2,
0x07C6,
0x09EA,
0x0C0E,
0x0E32,
0x1010,
0x10DC
};
const u16 LEORAM_START_LBA[7] = { 0x05A2, 0x07C6, 0x09EA, 0x0C0E, 0x0E32, 0x1010, 0x10DC };
const s32 LEORAM_BYTE[7] = {
0x024A9DC0,
0x01C226C0,
0x01450F00,
0x00D35680,
0x006CFD40,
0x001DA240,
0x00000000
};
const s32 LEORAM_BYTE[7] = { 0x024A9DC0, 0x01C226C0, 0x01450F00, 0x00D35680, 0x006CFD40, 0x001DA240, 0x00000000 };

View File

@ -2,111 +2,71 @@
#include "libleo/internal.h"
const u8 ganlog[512] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1D, 0x3A, 0x74,
0xE8, 0xCD, 0x87, 0x13, 0x26, 0x4C, 0x98, 0x2D, 0x5A, 0xB4, 0x75,
0xEA, 0xC9, 0x8F, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x9D,
0x27, 0x4E, 0x9C, 0x25, 0x4A, 0x94, 0x35, 0x6A, 0xD4, 0xB5, 0x77,
0xEE, 0xC1, 0x9F, 0x23, 0x46, 0x8C, 0x05, 0x0A, 0x14, 0x28, 0x50,
0xA0, 0x5D, 0xBA, 0x69, 0xD2, 0xB9, 0x6F, 0xDE, 0xA1, 0x5F, 0xBE,
0x61, 0xC2, 0x99, 0x2F, 0x5E, 0xBC, 0x65, 0xCA, 0x89, 0x0F, 0x1E,
0x3C, 0x78, 0xF0, 0xFD, 0xE7, 0xD3, 0xBB, 0x6B, 0xD6, 0xB1, 0x7F,
0xFE, 0xE1, 0xDF, 0xA3, 0x5B, 0xB6, 0x71, 0xE2, 0xD9, 0xAF, 0x43,
0x86, 0x11, 0x22, 0x44, 0x88, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xBD,
0x67, 0xCE, 0x81, 0x1F, 0x3E, 0x7C, 0xF8, 0xED, 0xC7, 0x93, 0x3B,
0x76, 0xEC, 0xC5, 0x97, 0x33, 0x66, 0xCC, 0x85, 0x17, 0x2E, 0x5C,
0xB8, 0x6D, 0xDA, 0xA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 0xB2, 0xDC, 0xFC, 0xBE, 0x61, 0xF2, 0x56, 0xD3, 0xAB, 0x14, 0x2A,
0x5D, 0x9E, 0x84, 0x3C, 0x39, 0x53, 0x47, 0x6D, 0x41, 0xA2, 0x1F, 0x2D, 0x43, 0xD8, 0xB7, 0x7B, 0xA4, 0x76, 0xC4,
0x17, 0x49, 0xEC, 0x7F, 0x0C, 0x6F, 0xF6, 0x6C, 0xA1, 0x3B, 0x52, 0x29, 0x9D, 0x55, 0xAA, 0xFB, 0x60, 0x86, 0xB1,
0xBB, 0xCC, 0x3E, 0x5A, 0xCB, 0x59, 0x5F, 0xB0, 0x9C, 0xA9, 0xA0, 0x51, 0x0B, 0xF5, 0x16, 0xEB, 0x7A, 0x75, 0x2C,
0xD7, 0x4F, 0xAE, 0xD5, 0xE9, 0xE6, 0xE7, 0xAD, 0xE8, 0x74, 0xD6, 0xF4, 0xEA, 0xA8, 0x50, 0x58, 0xAF, 0xFF
};
//.bss
extern block_param_form LEOc2_param;
//extern
// extern
extern u8 LEO_TempBuffer[0xE8];
extern u8 LEOC2_Syndrome[2][0xE8*4];
extern u8 LEOC2_Syndrome[2][0xE8 * 4];
s32 leoC2_Correction(void) {
switch (LEOc2_param.err_num) {
@ -142,7 +102,7 @@ void leoC2_single_ecc(void) {
do {
*(--pointer) ^= *(p_s -= 4);
} while(--byte != 0);
} while (--byte != 0);
}
}
@ -162,7 +122,7 @@ void leoC2_double_ecc(void) {
m = 0x58 - LEOc2_param.err_pos[1];
d = ganlog[k] ^ ganlog[m];
d = glog[leoAlpha_div(1, d)];
byte = LEOc2_param.bytes;
byte = LEOc2_param.bytes;
if (LEOc2_param.err_pos[1] < 0x55) {
goto c2_2_2;
@ -177,10 +137,10 @@ c2_2_2:
c2_2_1:
pointer1 = &LEOc2_param.pntr[(LEOc2_param.err_pos[0] + 1) * byte];
p_s = LEOc2_param.c2buff_e;
do {
p_s -= 4;
s0 = p_s[0];
s0 = p_s[0];
if (s0 != 0) {
a = ganlog[m + glog[s0]] ^ p_s[1];
} else {
@ -253,11 +213,17 @@ void leoC2_3_ecc(void) {
o = glog[o];
p = glog[p];
byte = LEOc2_param.bytes;
if (LEOc2_param.err_pos[2] < 0x55) goto c2_3_3;
if (LEOc2_param.err_pos[2] < 0x55) {
goto c2_3_3;
}
pointer3 = &LEO_TempBuffer[sizeof(LEO_TempBuffer)];
if (LEOc2_param.err_pos[1] < 0x55) goto c2_3_2;
if (LEOc2_param.err_pos[1] < 0x55) {
goto c2_3_2;
}
pointer2 = &LEO_TempBuffer[sizeof(LEO_TempBuffer)];
if (LEOc2_param.err_pos[0] < 0x55) goto c2_3_1;
if (LEOc2_param.err_pos[0] < 0x55) {
goto c2_3_1;
}
return;
c2_3_3:
pointer3 = &LEOc2_param.pntr[(LEOc2_param.err_pos[2] + 1) * byte];
@ -266,7 +232,7 @@ c2_3_2:
c2_3_1:
pointer1 = &LEOc2_param.pntr[(LEOc2_param.err_pos[0] + 1) * byte];
p_s = LEOc2_param.c2buff_e;
do {
p_s -= 4;
s0 = p_s[0];
@ -417,16 +383,24 @@ void leoC2_4_ecc(void) {
r = glog[r];
byte = LEOc2_param.bytes;
if (LEOc2_param.err_pos[3] < 0x55) goto c2_4_4;
if (LEOc2_param.err_pos[3] < 0x55) {
goto c2_4_4;
}
pointer4 = &LEO_TempBuffer[sizeof(LEO_TempBuffer)];
if (LEOc2_param.err_pos[2] < 0x55) goto c2_4_3;
if (LEOc2_param.err_pos[2] < 0x55) {
goto c2_4_3;
}
pointer3 = &LEO_TempBuffer[sizeof(LEO_TempBuffer)];
if (LEOc2_param.err_pos[1] < 0x55) goto c2_4_2;
if (LEOc2_param.err_pos[1] < 0x55) {
goto c2_4_2;
}
pointer2 = &LEO_TempBuffer[sizeof(LEO_TempBuffer)];
if (LEOc2_param.err_pos[0] < 0x55) goto c2_4_1;
if (LEOc2_param.err_pos[0] < 0x55) {
goto c2_4_1;
}
return;
c2_4_4:
pointer4 = &LEOc2_param.pntr[(LEOc2_param.err_pos[3] + 1) * byte];
c2_4_3:
@ -477,10 +451,18 @@ c2_4_1:
pointer2--;
pointer3--;
pointer4--;
if (R0) *pointer1 ^= R0;
if (R1) *pointer2 ^= R1;
if (R2) *pointer3 ^= R2;
if (R3) *pointer4 ^= R3;
if (R0) {
*pointer1 ^= R0;
}
if (R1) {
*pointer2 ^= R1;
}
if (R2) {
*pointer3 ^= R2;
}
if (R3) {
*pointer4 ^= R3;
}
} while (--byte != 0);
}

View File

@ -5,14 +5,14 @@
extern u16 LEOrw_flags;
// D_8007DA40
const u8 leo_sys_form_lbas[] = {0, 1, 8, 9, 0, 0, 0, 0}; // EXTRA 0 IS A HACK
const u8 leo_sys_form_lbas[] = { 0, 1, 8, 9, 0, 0, 0, 0 }; // EXTRA 0 IS A HACK
#pragma GLOBAL_ASM("asm/nonmatchings/libleo/leocmdex/leomain.s")
/*const LEOCmdRead leo_sys_read_cmd =
{
{LEO_COMMAND_READ,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00000000},
12,1,0,0
{LEO_COMMAND_READ,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00000000},
12,1,0,0
};*/
extern LEOCmdRead leo_sys_read_cmd;
@ -22,7 +22,7 @@ u8 leoRead_system_area(void) {
LEOCmd* prev_cmd;
u32 retry_cntr;
s32 read_mode;
prev_cmd = LEOcur_command;
LEOcur_command = (LEOCmd*)&temp_cmd;
read_mode = 0;
@ -30,34 +30,34 @@ u8 leoRead_system_area(void) {
while (1) {
LEOdisk_type = 0;
//For lba_to_phys to avoid dealing with alternative tracks on the disk
// For lba_to_phys to avoid dealing with alternative tracks on the disk
LEO_sys_data.param.defect_num[0] = 0;
LEOrw_flags = 0x3000;
temp_cmd = leo_sys_read_cmd;
temp_cmd.buff_ptr = &LEO_sys_data;
if (read_mode == 0) {
//read System LBA 12 (+0, this is an offset value for leoRead_common)
//see leo_sys_read_cmd premade struct
// read System LBA 12 (+0, this is an offset value for leoRead_common)
// see leo_sys_read_cmd premade struct
leoRead_common(0);
switch (temp_cmd.header.sense) {
case LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION:
do {
//if expecting a retail disk, LBA 12 is expected to do a read error, if not then freeze
} while (LEO_country_code != 0);
retry_cntr = 0;
read_mode--;
continue;
case LEO_SENSE_UNRECOVERED_READ_ERROR:
do {
//if expecting a development disk, LBA 12 is expected to read correctly, if not then freeze
} while (LEO_country_code == 0);
retry_cntr = 0;
read_mode--;
continue;
case LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION:
do {
// if expecting a retail disk, LBA 12 is expected to do a read error, if not then freeze
} while (LEO_country_code != 0);
retry_cntr = 0;
read_mode--;
continue;
case LEO_SENSE_UNRECOVERED_READ_ERROR:
do {
// if expecting a development disk, LBA 12 is expected to read correctly, if not then freeze
} while (LEO_country_code == 0);
retry_cntr = 0;
read_mode--;
continue;
}
} else {
//read System LBA 0,1,8,9 (or 2,3,10,11 for dev)
// read System LBA 0,1,8,9 (or 2,3,10,11 for dev)
temp_cmd.lba = leo_sys_form_lbas[retry_cntr & 3];
if (LEO_country_code == 0) {
temp_cmd.lba += 2;
@ -65,7 +65,7 @@ u8 leoRead_system_area(void) {
leoRead_common(0);
if (temp_cmd.header.status == LEO_STATUS_GOOD) {
do {
//if disk country and set country code in libleo mismatch, then freeze
// if disk country and set country code in libleo mismatch, then freeze
} while (LEO_sys_data.param.country != LEO_country_code);
break;
}
@ -78,8 +78,9 @@ u8 leoRead_system_area(void) {
break;
}
if ((retry_cntr & 7) == 0) {
//Recalibrate drive every 8th tries
if ((temp_cmd.header.sense = leoSend_asic_cmd_w(ASIC_RECAL, 0)) == LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) {
// Recalibrate drive every 8th tries
if ((temp_cmd.header.sense = leoSend_asic_cmd_w(ASIC_RECAL, 0)) ==
LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION) {
continue;
}
goto system_retry;

View File

@ -35,8 +35,7 @@ void leoInitialize(OSPri compri, OSPri intpri, OSMesg* command_que_buf, u32 cmd_
osCreateMesgQueue(&LEOpost_que, LEOpost_que_buf, ARRAY_COUNT(LEOpost_que_buf));
osCreateThread(&LEOcommandThread, 1, leomain, NULL, LEOcommandThreadStack, compri);
osStartThread(&LEOcommandThread);
osCreateThread(&LEOinterruptThread, 1, leointerrupt, NULL,
LEOinterruptThreadStack, intpri);
osCreateThread(&LEOinterruptThread, 1, leointerrupt, NULL, LEOinterruptThreadStack, intpri);
osStartThread(&LEOinterruptThread);
osSetEventMesg(OS_EVENT_CART, &LEOevent_que, (OSMesg)0x30000);
osSendMesg(&LEOblock_que, NULL, 0);

View File

@ -2,7 +2,7 @@
#include "libleo/internal.h"
extern vu16 LEOrw_flags;
extern u8 LEOC2_Syndrome[2][0xE8*4];
extern u8 LEOC2_Syndrome[2][0xE8 * 4];
extern block_param_form LEOc2_param;
u32 read_write_track();
@ -62,11 +62,11 @@ u32 read_write_track(void) {
u16 bnum;
u8* temp;
u32 c2datasize;
block_param.bytes = LEOtgt_param.sec_bytes;
block_param.blkbytes = LEOtgt_param.blk_bytes;
if (LEOrw_flags & 0x2000) {
//Sector Mode
// Sector Mode
block_param.blkbytes = block_param.bytes;
}
block_param.pntr = LEOwrite_pointer;
@ -83,22 +83,23 @@ u32 read_write_track(void) {
LEOPiInfo->transferInfo.block[0].dramAddr = block_param.pntr;
LEOPiInfo->transferInfo.block[0].C2Addr = &LEOC2_Syndrome[0];
if (LEOrw_flags & 0x2000) {
//Sector Mode
// Sector Mode
LEOtgt_param.rdwr_blocks = 1;
LEOPiInfo->transferInfo.transferMode = 3;
} else if (LEOtgt_param.rdwr_blocks == 2) {
LEOPiInfo->transferInfo.transferMode = 2;
LEOPiInfo->transferInfo.block[1] = LEOPiInfo->transferInfo.block[0];
LEOPiInfo->transferInfo.block[1].C2Addr = &LEOC2_Syndrome[1];
LEOPiInfo->transferInfo.block[1].dramAddr = ((u8*)LEOPiInfo->transferInfo.block[1].dramAddr + block_param.blkbytes);
LEOPiInfo->transferInfo.block[1].dramAddr =
((u8*)LEOPiInfo->transferInfo.block[1].dramAddr + block_param.blkbytes);
}
message = leoChk_mecha_int();
if (message == 0) {
if (LEOrw_flags & 0x8000) {
//Write Mode
// Write Mode
leoSet_mseq(1);
} else {
//Read Mode
// Read Mode
leoSet_mseq(0);
}
leosetup_BM();
@ -146,7 +147,7 @@ u32 read_write_track(void) {
goto track_end;
}
}
if (block == 0) {
temp = LEOC2_Syndrome[0];
} else {
@ -163,11 +164,12 @@ u32 read_write_track(void) {
osRecvMesg(&LEOc2ctrl_que, NULL, 1);
LEOrw_flags |= 0x4000;
LEOc2_param = block_param;
osSendMesg(&LEOcontrol_que, (void* )0x80000, 1);
osSendMesg(&LEOcontrol_que, (void*)0x80000, 1);
}
} else {
if (LEOtgt_param.rdwr_blocks == 1) {
if ((*(u32*)&LEOC2_Syndrome[block][0x00] | *(u32*)&LEOC2_Syndrome[block][0x04] | *(u32*)&LEOC2_Syndrome[block][0x08] | *(u32*)&LEOC2_Syndrome[block][0x0C]) != 0) {
if ((*(u32*)&LEOC2_Syndrome[block][0x00] | *(u32*)&LEOC2_Syndrome[block][0x04] |
*(u32*)&LEOC2_Syndrome[block][0x08] | *(u32*)&LEOC2_Syndrome[block][0x0C]) != 0) {
message = 0x17;
goto track_end;
}
@ -181,11 +183,11 @@ u32 read_write_track(void) {
}
return 0;
}
track_end:
track_end:
if (message == 0x16) {
message = leochk_err_reg();
}
do_retry:
do_retry:
if (leoChk_err_retry(message) || (LEOrw_flags & 0x1000) || retry_cntr++ == 0x40) {
break;
}

View File

@ -4,12 +4,12 @@
#include "PR/os_system.h"
extern OSThread* __osRunQueue;
extern OSThread *__osPopThread(OSThread **);
extern void __osEnqueueThread(OSThread **, OSThread *);
extern OSThread* __osPopThread(OSThread**);
extern void __osEnqueueThread(OSThread**, OSThread*);
extern OSIntMask __osGlobalIntMask;
void __osLeoAbnormalResume(void);
void __osLeoResume(void);
extern s32 osEPiRawStartDma(OSPiHandle *, s32, u32, void *, u32);
extern s32 osEPiRawStartDma(OSPiHandle*, s32, u32, void*, u32);
s32 __osLeoInterrupt(void) {
u32 stat = 0;

View File

@ -2,217 +2,217 @@
#include "libleo/internal.h"
extern u32 asic_cur_status; // static?
extern u32 unit_atten; // static?
extern u32 unit_atten; // static?
extern s32 currentCommand;
s32 osEPiWriteIo(OSPiHandle *, u32 , u32 );
s32 osEPiWriteIo(OSPiHandle*, u32, u32);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
u8 leoAnalize_asic_status(void) {
u32 curr_stat;
u32 curr_stat;
osEPiReadIo(LEOPiInfo, LEO_STATUS, &asic_cur_status);
osEPiReadIo(LEOPiInfo, LEO_STATUS, &asic_cur_status);
if ((curr_stat = asic_cur_status ^ 0x1000000) & 0x1C3FFFF) {
if (curr_stat & 0x1C1FFFF) {
LEOdrive_flag = 0;
if ((curr_stat = asic_cur_status ^ 0x1000000) & 0x1C3FFFF) {
if (curr_stat & 0x1C1FFFF) {
LEOdrive_flag = 0;
}
if (curr_stat & LEO_STATUS_PRESENCE_MASK) {
return 41;
}
if ((curr_stat & 0xC00000) == LEO_STATUS_BUSY_STATE) {
return LEO_SENSE_COMMAND_PHASE_ERROR;
}
if (curr_stat & LEO_STATUS_RESET_STATE) {
unit_atten |= 2;
return LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED;
}
if (curr_stat & LEO_STATUS_DISK_PRESENT) {
return LEO_SENSE_EJECTED_ILLEGALLY_RESUME;
}
if (curr_stat & LEO_STATUS_DISK_CHANGE) {
unit_atten |= 1;
return LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED;
}
if (curr_stat & LEO_STATUS_MECHANIC_ERROR) {
return LEO_SENSE_NO_SEEK_COMPLETE;
}
}
if (curr_stat & LEO_STATUS_PRESENCE_MASK) {
return 41;
}
if ((curr_stat & 0xC00000) == LEO_STATUS_BUSY_STATE) {
return LEO_SENSE_COMMAND_PHASE_ERROR;
}
if (curr_stat & LEO_STATUS_RESET_STATE) {
unit_atten |= 2;
return LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED;
}
if (curr_stat & LEO_STATUS_DISK_PRESENT) {
return LEO_SENSE_EJECTED_ILLEGALLY_RESUME;
}
if (curr_stat & LEO_STATUS_DISK_CHANGE) {
unit_atten |= 1;
return LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED;
}
if (curr_stat & LEO_STATUS_MECHANIC_ERROR) {
return LEO_SENSE_NO_SEEK_COMPLETE;
}
}
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
u8 leoChk_asic_ready(u32 asic_cmd) {
u32 sense_code = leoAnalize_asic_status();
u32 sense_code = leoAnalize_asic_status();
switch (sense_code) {
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
if (asic_cmd == ASIC_CLR_CHGFLG) {
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED:
if (!(asic_cur_status & LEO_STATUS_BUSY_STATE)) {
if (asic_cmd == ASIC_CLR_RSTFLG) {
switch (sense_code) {
case LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED:
if (asic_cmd == ASIC_CLR_CHGFLG) {
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
case LEO_SENSE_POWERONRESET_DEVICERESET_OCCURED:
if (!(asic_cur_status & LEO_STATUS_BUSY_STATE)) {
if (asic_cmd == ASIC_CLR_RSTFLG) {
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
if (leoRecv_event_mesg(0) != 0) {
return LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_CMD, ASIC_CLR_RSTFLG);
if (leoRecv_event_mesg(1) != 0) {
return LEO_SENSE_WAITING_NMI;
}
}
default:
break;
case LEO_SENSE_EJECTED_ILLEGALLY_RESUME:
if (asic_cmd & ASIC_NEED_DISK_IN) {
break;
}
case LEO_SENSE_NO_SEEK_COMPLETE:
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
if (leoRecv_event_mesg(0) != 0) {
return LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_CMD, ASIC_CLR_RSTFLG);
if (leoRecv_event_mesg(1) != 0) {
return LEO_SENSE_WAITING_NMI;
}
}
default:
break;
case LEO_SENSE_EJECTED_ILLEGALLY_RESUME:
if (asic_cmd & ASIC_NEED_DISK_IN) {
break;
}
case LEO_SENSE_NO_SEEK_COMPLETE:
return LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
}
return sense_code;
}
return sense_code;
}
u8 leoChk_done_status(u32 asic_cmd) {
u32 asic_data;
u32 code = leoAnalize_asic_status();
u32 asic_data;
u32 code = leoAnalize_asic_status();
switch (code) {
case 43:
case 47:
if (!(asic_cur_status & 0x800000)) {
if (leoRecv_event_mesg(0) != 0) {
return 37;
}
switch (code) {
case 43:
case 47:
if (!(asic_cur_status & 0x800000)) {
if (leoRecv_event_mesg(0) != 0) {
return 37;
}
osEPiWriteIo(LEOPiInfo, 0x5000508, 0x90000);
if (leoRecv_event_mesg(1) != 0) {
return 37;
}
}
break;
osEPiWriteIo(LEOPiInfo, 0x5000508, 0x90000);
if (leoRecv_event_mesg(1) != 0) {
return 37;
}
}
break;
case 49:
if (asic_cmd & 1) {
break;
}
return 0;
case 49:
if (asic_cmd & 1) {
break;
}
return 0;
case 21:
osEPiWriteIo(LEOPiInfo, 0x5000500, 0);
if (leoRecv_event_mesg(0) != 0) {
return 37;
}
case 21:
osEPiWriteIo(LEOPiInfo, 0x5000500, 0);
if (leoRecv_event_mesg(0) != 0) {
return 37;
}
osEPiWriteIo(LEOPiInfo, 0x5000508, 0xC0000);
if (leoRecv_event_mesg(1) != 0) {
return 37;
}
osEPiWriteIo(LEOPiInfo, 0x5000508, 0xC0000);
if (leoRecv_event_mesg(1) != 0) {
return 37;
}
osEPiReadIo(LEOPiInfo, 0x5000500, &asic_data);
code = leoChk_asic_ready(0xC0000);
if (code != 0) {
return code;
}
osEPiReadIo(LEOPiInfo, 0x5000500, &asic_data);
code = leoChk_asic_ready(0xC0000);
if (code != 0) {
return code;
}
if (asic_data & 0x10000) {
return 2;
}
if (asic_data & 0x20000) {
return 24;
}
if (asic_data & 0x40000) {
return 1;
}
if (asic_data & 0x80000) {
return 21;
}
if (asic_data & 0x200000) {
return 11;
}
return 41;
if (asic_data & 0x10000) {
return 2;
}
if (asic_data & 0x20000) {
return 24;
}
if (asic_data & 0x40000) {
return 1;
}
if (asic_data & 0x80000) {
return 21;
}
if (asic_data & 0x200000) {
return 11;
}
return 41;
default:
break;
}
return code;
default:
break;
}
return code;
}
u8 leoSend_asic_cmd_i(u32 asic_cmd, u32 asic_data) {
u8 status = leoChk_asic_ready(asic_cmd);
u8 status = leoChk_asic_ready(asic_cmd);
if (status != 0) {
return LEOcur_command->header.sense = status;
}
osEPiWriteIo(LEOPiInfo, LEO_DATA, asic_data);
if (leoRecv_event_mesg(0) != 0) {
return LEOcur_command->header.sense = LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_STATUS, asic_cmd);
return 0;
if (status != 0) {
return LEOcur_command->header.sense = status;
}
osEPiWriteIo(LEOPiInfo, LEO_DATA, asic_data);
if (leoRecv_event_mesg(0) != 0) {
return LEOcur_command->header.sense = LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_STATUS, asic_cmd);
return 0;
}
u8 leoWait_mecha_cmd_done(u32 asic_cmd) {
u32 done_stat;
u32 done_stat;
if (leoRecv_event_mesg(1)) {
return LEO_SENSE_WAITING_NMI;
}
done_stat = leoChk_done_status(asic_cmd);
if (done_stat != 0) {
return done_stat;
}
return 0;
if (leoRecv_event_mesg(1)) {
return LEO_SENSE_WAITING_NMI;
}
done_stat = leoChk_done_status(asic_cmd);
if (done_stat != 0) {
return done_stat;
}
return 0;
}
u8 leoSend_asic_cmd_w(u32 asic_cmd, u32 asic_data) {
u32 wstatus = leoSend_asic_cmd_i(asic_cmd, asic_data);
u32 wstatus = leoSend_asic_cmd_i(asic_cmd, asic_data);
if (wstatus != 0) {
return wstatus;
}
return leoWait_mecha_cmd_done(asic_cmd);
if (wstatus != 0) {
return wstatus;
}
return leoWait_mecha_cmd_done(asic_cmd);
}
u8 leoSend_asic_cmd_w_nochkDiskChange(u32 asic_cmd, u32 asic_data) {
u8 status;
u32 done_stat;
u8 status;
u32 done_stat;
status = leoChk_asic_ready(asic_cmd);
if ((status != LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED) && (status != 0)) {
return LEOcur_command->header.sense = status;
}
status = leoChk_asic_ready(asic_cmd);
if ((status != LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED) && (status != 0)) {
return LEOcur_command->header.sense = status;
}
osEPiWriteIo(LEOPiInfo, LEO_DATA, asic_data);
if (leoRecv_event_mesg(0) != 0) {
return LEOcur_command->header.sense = LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_DATA, asic_data);
if (leoRecv_event_mesg(0) != 0) {
return LEOcur_command->header.sense = LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_STATUS, asic_cmd);
if (leoRecv_event_mesg(1) != 0) {
return LEO_SENSE_WAITING_NMI;
}
osEPiWriteIo(LEOPiInfo, LEO_STATUS, asic_cmd);
if (leoRecv_event_mesg(1) != 0) {
return LEO_SENSE_WAITING_NMI;
}
done_stat = leoChk_done_status(asic_cmd);
if ((done_stat != LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED) && (done_stat != 0)) {
return done_stat;
}
return 0;
done_stat = leoChk_done_status(asic_cmd);
if ((done_stat != LEO_SENSE_MEDIUM_MAY_HAVE_CHANGED) && (done_stat != 0)) {
return done_stat;
}
return 0;
}
u8 leoDetect_index_w(void) {
return leoSend_asic_cmd_w(ASIC_INDEX_LOCK_RETRY, 0);
return leoSend_asic_cmd_w(ASIC_INDEX_LOCK_RETRY, 0);
}
u8 leoRecal_i(void) {
return leoSend_asic_cmd_i(ASIC_RECAL, 0);
return leoSend_asic_cmd_i(ASIC_RECAL, 0);
}
u8 leoRecal_w(void) {
return leoSend_asic_cmd_w(ASIC_RECAL, 0);
return leoSend_asic_cmd_w(ASIC_RECAL, 0);
}
u8 leoSeek_i(u16 rwmode) {
@ -225,25 +225,25 @@ u8 leoSeek_i(u16 rwmode) {
}
u8 leoSeek_w(void) {
u8 sksense = leoSeek_i(0);
u8 sksense = leoSeek_i(0);
if (sksense != 0) {
return sksense;
}
if (sksense != 0) {
return sksense;
}
return leoWait_mecha_cmd_done(ASIC_RD_SEEK);
return leoWait_mecha_cmd_done(ASIC_RD_SEEK);
}
s32 leoRecv_event_mesg(s32 control) {
u32 done_mesg;
u32 done_mesg;
if (osRecvMesg(&LEOevent_que, (OSMesg*)&done_mesg, control) == 0) {
if (done_mesg == ASIC_SOFT_RESET_CODE) {
leoDrive_reset();
return 0xFF;
if (osRecvMesg(&LEOevent_que, (OSMesg*)&done_mesg, control) == 0) {
if (done_mesg == ASIC_SOFT_RESET_CODE) {
leoDrive_reset();
return 0xFF;
}
}
}
return 0;
return 0;
}
u32 leoChk_err_retry(u32 sense) {
@ -295,35 +295,35 @@ u8 leoChk_cur_drvmode(void) {
}
void leoDrive_reset() {
osEPiWriteIo(LEOPiInfo, LEO_HARD_RESET, ASIC_HARD_RESET_CODE);
osEPiWriteIo(LEOPiInfo, LEO_HARD_RESET, ASIC_HARD_RESET_CODE);
}
u32 leoChkUnit_atten(void) {
return unit_atten;
return unit_atten;
}
u32 leoRetUnit_atten(void) {
if (unit_atten & 2) {
return 43;
}
if (unit_atten & 1) {
return 47;
}
return 0;
if (unit_atten & 2) {
return 43;
}
if (unit_atten & 1) {
return 47;
}
return 0;
}
void leoClrUA_RESET(void) {
unit_atten &= ~2;
unit_atten &= ~2;
}
void leoClrUA_MEDIUM_CHANGED(void) {
unit_atten &= ~1;
unit_atten &= ~1;
}
void leoSetUA_MEDIUM_CHANGED(void) {
unit_atten |= 1;
unit_atten |= 1;
}
void leoInitUnit_atten(void) {
unit_atten = 1;
unit_atten = 1;
}

View File

@ -20,38 +20,38 @@ void leoReadDiskId(void) {
u8* temp_pointer;
u32 cntr;
//Keep Disk ID Command and replace
// Keep Disk ID Command and replace
temp_pointer = (u8*)LEOcur_command;
//Read Disk ID to Temp Buffer
// Read Disk ID to Temp Buffer
LEOcur_command = (LEOCmd*)&dummy_cmd;
for (cntr = 0; cntr < (sizeof(leo_disk_id_lba)); cntr++) {
LEOrw_flags = 0x2000;
dummy_cmd = read_id_cmd;
dummy_cmd.lba = leo_disk_id_lba[cntr];
leoRead_common(0);
if (dummy_cmd.header.sense != LEO_SENSE_UNRECOVERED_READ_ERROR) break;
if (dummy_cmd.header.sense != LEO_SENSE_UNRECOVERED_READ_ERROR) {
break;
}
}
//Put back the old ReadDiskID command
// Put back the old ReadDiskID command
LEOcur_command = (LEOCmd*)temp_pointer;
//Copy Disk ID to buffer pointed by ReadDiskID command
// Copy Disk ID to buffer pointed by ReadDiskID command
temp_pointer = (u8*)LEOcur_command->data.readdiskid.buffer_pointer;
for (cntr = 0; cntr < (sizeof(LEODiskID)); cntr += sizeof(u32))
{
*(u32 *)temp_pointer = *((u32 *)&LEO_TempBuffer[cntr]);
temp_pointer += sizeof(u32);
for (cntr = 0; cntr < (sizeof(LEODiskID)); cntr += sizeof(u32)) {
*(u32*)temp_pointer = *((u32*)&LEO_TempBuffer[cntr]);
temp_pointer += sizeof(u32);
}
//Copy status and sense
// Copy status and sense
LEOcur_command->header.sense = dummy_cmd.header.sense;
LEOcur_command->header.status = dummy_cmd.header.status;
if (LEOcur_command->header.status == LEO_STATUS_GOOD) {
leoClrUA_MEDIUM_CHANGED();
} else {
leoSetUA_MEDIUM_CHANGED();
}
}

View File

@ -19,7 +19,7 @@ void leoRead_common(u32 offset) {
tg_lba += offset;
if ((tg_lba + tg_blocks) > 0x10DC) { // Unclear what this number represents
invalid_lba:
invalid_lba:
LEOcur_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
@ -58,7 +58,6 @@ void leoRead_common(u32 offset) {
LEOcur_command->header.sense = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
LEOcur_command->header.status = LEO_STATUS_GOOD;
return;
}
}
}

View File

@ -20,7 +20,7 @@ void leoRezero(void) {
break;
}
} while (retry_cntr--);
LEOcur_command->header.sense = sense_code;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
}

View File

@ -6,9 +6,9 @@ void leoSeek(void) {
u8 retry_cntr = 20;
if (LEOcur_command->data.seek.lba > LEO_LBA_MAX) {
LEOcur_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
LEOcur_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
leoLba_to_phys(LEOcur_command->data.seek.lba + 0x18);

View File

@ -2,7 +2,7 @@
#include "libleo/internal.h"
void leoTest_unit_rdy(void) {
((LEOCmdTestUnitReady*)LEOcur_command)->test = leoChk_cur_drvmode();
LEOcur_command->header.sense = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
LEOcur_command->header.status = LEO_STATUS_GOOD;
((LEOCmdTestUnitReady*)LEOcur_command)->test = leoChk_cur_drvmode();
LEOcur_command->header.sense = LEO_SENSE_NO_ADDITIONAL_SENSE_INFOMATION;
LEOcur_command->header.status = LEO_STATUS_GOOD;
}

View File

@ -1,12 +1,12 @@
#include <ultra64.h>
#include "libleo/internal.h"
static const u8 ymdupper[6] = {99,12,31,23,59,59};
static const u8 dayupper[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
static const u8 ymdupper[6] = { 99, 12, 31, 23, 59, 59 };
static const u8 dayupper[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void leoReadTimer(void) {
UNUSED u8* rdparam;
UNUSED u8 data[4];
UNUSED u8* rdparam;
UNUSED u8 data[4];
__LOCTime time;
u8 sense_code = __locReadTimer(&time);
LEOcur_command->data.time.yearlo = time.year;
@ -20,7 +20,7 @@ void leoReadTimer(void) {
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
if ((u8) LEOcur_command->data.time.yearlo >= 0x96U) {
if ((u8)LEOcur_command->data.time.yearlo >= 0x96U) {
LEOcur_command->data.time.yearhi = 0x19;
} else {
LEOcur_command->data.time.yearhi = 0x20;
@ -38,39 +38,39 @@ void leoSetTimer(void) {
u8 result;
__LOCTime time;
//Verify values (if they're correct BCD or within limits)
// Verify values (if they're correct BCD or within limits)
for (ymd = 0; ymd < 6; ymd++) {
temp = *p_tmp;
//Verify right nybble (only right nybble for some reason)
// Verify right nybble (only right nybble for some reason)
if ((temp & 0xF) > 9) {
//nybble is above 0x9 therefore the BCD value is invalid
// nybble is above 0x9 therefore the BCD value is invalid
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
//Convert BCD value to binary value
// Convert BCD value to binary value
temp = temp - ((temp >> 4) * 6);
switch (ymd) {
case 2:
//Day value check
// Day value check
if ((dayupper[month] < temp) && ((temp != 0x1D) || (year & 3))) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
case 1:
//Month value cannot be 0
// Month value cannot be 0
if (temp == 0) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
default:
//Verify max value of each time info
// Verify max value of each time info
if (ymdupper[ymd] < temp) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
@ -83,37 +83,34 @@ void leoSetTimer(void) {
p_tmp++;
}
//Every value has been ymd good, now set the values in hardware
// Every value has been ymd good, now set the values in hardware
//Prepare the time info to use
// Prepare the time info to use
time.year = LEOcur_command->data.time.yearlo;
time.month = LEOcur_command->data.time.month;
time.day = LEOcur_command->data.time.day;
time.hour = LEOcur_command->data.time.hour;
time.minute = LEOcur_command->data.time.minute;
time.second = LEOcur_command->data.time.second;
//Set the new time
// Set the new time
result = __locSetTimer(&time);
if (result != 0) {
LEOcur_command->header.sense = result;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
//Get the time
// Get the time
result = __locReadTimer(&time);
if (result != 0) {
LEOcur_command->header.sense = result;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
//Check if the time is set correctly
if ((time.year != LEOcur_command->data.time.yearlo)
|| (time.month != LEOcur_command->data.time.month)
|| (time.day != LEOcur_command->data.time.day)
|| (time.hour != LEOcur_command->data.time.hour)
|| (time.minute != LEOcur_command->data.time.minute)
|| (time.second != LEOcur_command->data.time.second)) {
// Check if the time is set correctly
if ((time.year != LEOcur_command->data.time.yearlo) || (time.month != LEOcur_command->data.time.month) ||
(time.day != LEOcur_command->data.time.day) || (time.hour != LEOcur_command->data.time.hour) ||
(time.minute != LEOcur_command->data.time.minute) || (time.second != LEOcur_command->data.time.second)) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
@ -121,7 +118,6 @@ void leoSetTimer(void) {
LEOcur_command->header.status = LEO_STATUS_GOOD;
}
u8 __locReadTimer(__LOCTime* time) {
u32 data;
u8 sense_code;
@ -131,27 +127,27 @@ u8 __locReadTimer(__LOCTime* time) {
return sense_code;
}
osEPiReadIo(LEOPiInfo, LEO_DATA, &data);
time->minute = (u8) ((u32) (data & 0xFF000000) >> 0x18);
time->second = (s8) ((u32) (data & 0xFF0000) >> 0x10);
time->minute = (u8)((u32)(data & 0xFF000000) >> 0x18);
time->second = (s8)((u32)(data & 0xFF0000) >> 0x10);
sense_code = leoSend_asic_cmd_w_nochkDiskChange(ASIC_READ_TIMER_DATE, 0U);
if (sense_code != 0) {
time->minute = (u8) (time->minute & 0xFF7F);
time->minute = (u8)(time->minute & 0xFF7F);
return sense_code;
}
osEPiReadIo(LEOPiInfo, LEO_DATA, &data);
time->day = (s8) ((u32) (data & 0xFF000000) >> 0x18);
time->hour = (s8) ((u32) (data & 0xFF0000) >> 0x10);
time->day = (s8)((u32)(data & 0xFF000000) >> 0x18);
time->hour = (s8)((u32)(data & 0xFF0000) >> 0x10);
sense_code = leoSend_asic_cmd_w_nochkDiskChange(ASIC_READ_TIMER_YEAR, 0U);
if (sense_code != 0) {
time->minute = (u8) (time->minute & 0xFF7F);
time->minute = (u8)(time->minute & 0xFF7F);
return sense_code;
}
osEPiReadIo(LEOPiInfo, LEO_DATA, &data);
sense_code = time->minute;
time->year = (s8) ((u32) (data & 0xFF000000) >> 0x18);
time->month = (s8) ((u32) (data & 0xFF0000) >> 0x10);
time->year = (s8)((u32)(data & 0xFF000000) >> 0x18);
time->month = (s8)((u32)(data & 0xFF0000) >> 0x10);
if (sense_code & 0x80) {
time->minute = (u8) (sense_code & 0xFF7F);
time->minute = (u8)(sense_code & 0xFF7F);
return 5;
}
return 0;
@ -171,7 +167,11 @@ u8 __locSetTimer(__LOCTime* time) {
minuteSecond = (time->minute << 0x18) + (time->second << 0x10);
temp_v0 = leoSend_asic_cmd_w_nochkDiskChange(ASIC_SET_TIMER_YEAR, yearMonth);
result = temp_v0;
if ((temp_v0 != 0) || (temp_v0_2 = leoSend_asic_cmd_w_nochkDiskChange(ASIC_SET_TIMER_DATE, dayHour), result = temp_v0_2, (temp_v0_2 != 0)) || (temp_v0_3 = leoSend_asic_cmd_w_nochkDiskChange(ASIC_SET_TIMER_MINUTE, minuteSecond), result = temp_v0_3, (temp_v0_3 != 0))) {
if ((temp_v0 != 0) ||
(temp_v0_2 = leoSend_asic_cmd_w_nochkDiskChange(ASIC_SET_TIMER_DATE, dayHour), result = temp_v0_2,
(temp_v0_2 != 0)) ||
(temp_v0_3 = leoSend_asic_cmd_w_nochkDiskChange(ASIC_SET_TIMER_MINUTE, minuteSecond), result = temp_v0_3,
(temp_v0_3 != 0))) {
return result;
}
return 0;

View File

@ -11,7 +11,6 @@ void leoTranslate(void) {
u8 flag; // boolean
if (LEOcur_command->data.readwrite.lba >= NUM_LBAS) {
LEOcur_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
@ -28,8 +27,9 @@ void leoTranslate(void) {
if (flag || (LEOVZONE_TBL[LEOdisk_type][vzone] == lba)) {
vzone = leoLba_to_vzone(lba);
zone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
if (zone >= 8)
if (zone >= 8) {
zone -= 7;
}
byte_p_blk = LEOBYTE_TBL2[zone];
}
if (calc_bytes < byte_p_blk) {
@ -55,8 +55,9 @@ void leoTranslate(void) {
if (flag || (LEOVZONE_TBL[LEOdisk_type][vzone] == lba)) {
vzone = leoLba_to_vzone(lba);
zone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
if (zone >= 8)
if (zone >= 8) {
zone -= 7;
}
byte_p_blk = LEOBYTE_TBL2[zone];
}
calc_bytes += byte_p_blk;

View File

@ -8,69 +8,71 @@ u16 leoLba_to_phys(u32 lba) {
u16 defect_offset;
u16 defect_amount;
//A cylinder track is made of two blocks, so we may be able to only read one of it if the next block is on the next cylinder
// A cylinder track is made of two blocks, so we may be able to only read one of it if the next block is on the next
// cylinder
LEOtgt_param.rdwr_blocks = 2 - (lba & 1);
//Blocks are interleaved between cylinders
// Blocks are interleaved between cylinders
if (((lba & 3) != 0) && ((lba & 3) != 3)) {
LEOtgt_param.start_block = 1;
} else {
LEOtgt_param.start_block = 0;
}
//Get Virtual & Physical Disk Zones from LBA
// Get Virtual & Physical Disk Zones from LBA
vzone = leoLba_to_vzone(lba);
pzone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
//Set Parameter Disk Head & Zone
// Set Parameter Disk Head & Zone
LEOtgt_param.head = 0;
LEOtgt_param.zone = pzone;
if (LEOtgt_param.zone > 7)
{
if (LEOtgt_param.zone > 7) {
LEOtgt_param.zone -= 7;
LEOtgt_param.head = 1;
}
//Get the start cylinder from current zone
// Get the start cylinder from current zone
pzone_cylinder_start = LEOZONE_SCYL_TBL[pzone];
{
//Get Virtual Zone LBA start, if Zone 0, it's LBA 0
// Get Virtual Zone LBA start, if Zone 0, it's LBA 0
u16 vzone_lba_start = (vzone != 0) ? LEOVZONE_TBL[LEOdisk_type][vzone - 1] : 0;
//Get Cylinder relative of the current Zone
// Get Cylinder relative of the current Zone
u16 zone_cylinder = ((lba - vzone_lba_start) >> 1);
//Calculate Physical Cylinder
// Calculate Physical Cylinder
if (LEOtgt_param.head != 0) {
LEOtgt_param.cylinder = pzone_cylinder_start - zone_cylinder;
pzone_cylinder_start = LEOZONE_OUTERCYL_TBL[LEOtgt_param.zone - 1];
} else {
LEOtgt_param.cylinder = pzone_cylinder_start + zone_cylinder;
}
}
}
{
u32 pzone_prev = pzone - 1;
//Get the relative offset to defect tracks for the current zone (if Zone 0, then it's 0)
// Get the relative offset to defect tracks for the current zone (if Zone 0, then it's 0)
defect_offset = (pzone != 0) ? LEO_sys_data.param.defect_num[pzone_prev] : 0;
//Get amount of defect tracks for the current zone
// Get amount of defect tracks for the current zone
defect_amount = LEO_sys_data.param.defect_num[pzone] - defect_offset;
}
//Skip defective cylinders
// Skip defective cylinders
while (defect_amount != 0) {
u16 defect_cylinder = (pzone_cylinder_start + LEO_sys_data.param.defect_data[defect_offset]);
if (LEOtgt_param.cylinder < defect_cylinder) break;
if (LEOtgt_param.cylinder < defect_cylinder) {
break;
}
LEOtgt_param.cylinder++;
defect_offset++;
defect_amount--;
}
//Set sector and block size info
// Set sector and block size info
LEOtgt_param.sec_bytes = LEOBYTE_TBL1[LEOtgt_param.zone];
LEOtgt_param.blk_bytes = LEOBYTE_TBL2[LEOtgt_param.zone];
//For development disks
// For development disks
if ((LEO_country_code == 0) && (lba < 0xC)) {
LEOtgt_param.sec_bytes = 0xC0;
LEOtgt_param.blk_bytes = 0x3FC0;
@ -79,7 +81,6 @@ u16 leoLba_to_phys(u32 lba) {
return 0;
}
u16 leoLba_to_vzone(u32 lba) {
u16 i;
const u16* ptr = LEOVZONE_TBL[LEOdisk_type];

View File

@ -18,7 +18,7 @@ void leoWrite(void) {
start_lba += 0x18;
if ((start_lba >= 0x10DC) || (start_lba + xfer_blk > 0x10DC)) {
invalid_lba:
invalid_lba:
LEOcur_command->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;

View File

@ -1,19 +1,19 @@
#include <ultra64.h>
#include "libleo/internal.h"
s32 LeoReadDiskID(LEOCmd *cmdBlock, LEODiskID *vaddr, OSMesgQueue *mq) {
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_READ_DISK_ID;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
cmdBlock->data.readdiskid.buffer_pointer = vaddr;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
s32 LeoReadDiskID(LEOCmd* cmdBlock, LEODiskID* vaddr, OSMesgQueue* mq) {
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_READ_DISK_ID;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
cmdBlock->data.readdiskid.buffer_pointer = vaddr;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
}

View File

@ -2,17 +2,17 @@
#include "libleo/internal.h"
s32 LeoReadRTC(LEOCmd* cmdBlock, OSMesgQueue* mq) {
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_READ_TIMER;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_READ_TIMER;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
}

View File

@ -2,25 +2,25 @@
#include "libleo/internal.h"
s32 LeoReadWrite(LEOCmd* cmdBlock, s32 direction, u32 LBA, void* vAddr, u32 nLBAs, OSMesgQueue* mq) {
if (!__leoActive) {
return -1;
}
if (direction == OS_READ) {
cmdBlock->header.command = LEO_COMMAND_READ;
} else {
cmdBlock->header.command = LEO_COMMAND_WRITE;
}
cmdBlock->header.reserve1 = 0;
if (mq != NULL) {
cmdBlock->header.control = LEO_CONTROL_POST;
} else {
cmdBlock->header.control = 0;
}
cmdBlock->header.reserve3 = 0;
cmdBlock->header.post = mq;
cmdBlock->data.readwrite.lba = LBA;
cmdBlock->data.readwrite.xfer_blks = nLBAs;
cmdBlock->data.readwrite.buff_ptr = vAddr;
leoCommand(cmdBlock);
return 0;
if (!__leoActive) {
return -1;
}
if (direction == OS_READ) {
cmdBlock->header.command = LEO_COMMAND_READ;
} else {
cmdBlock->header.command = LEO_COMMAND_WRITE;
}
cmdBlock->header.reserve1 = 0;
if (mq != NULL) {
cmdBlock->header.control = LEO_CONTROL_POST;
} else {
cmdBlock->header.control = 0;
}
cmdBlock->header.reserve3 = 0;
cmdBlock->header.post = mq;
cmdBlock->data.readwrite.lba = LBA;
cmdBlock->data.readwrite.xfer_blks = nLBAs;
cmdBlock->data.readwrite.buff_ptr = vAddr;
leoCommand(cmdBlock);
return 0;
}

View File

@ -2,18 +2,18 @@
#include "libleo/internal.h"
s32 LeoSeek(LEOCmd* cmdBlock, u32 lba, OSMesgQueue* mq) {
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_SEEK;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
cmdBlock->data.readwrite.lba = lba;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
if (!__leoActive) {
return -1;
}
cmdBlock->header.command = LEO_COMMAND_SEEK;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
cmdBlock->data.readwrite.lba = lba;
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
}

View File

@ -2,39 +2,38 @@
#include "libleo/internal.h"
s32 LeoSetRTC(LEOCmd* cmdBlock, LEODiskTime* RTCdata, OSMesgQueue* mq) {
if (!__leoActive) {
return -1;
}
if (leoVerifyRTC(RTCdata->yearhi, RTCdata->yearlo) != 0) {
osSendMesg(mq, (void *)LEO_SENSE_ILLEGAL_TIMER_VALUE, 1);
if (!__leoActive) {
return -1;
}
if (leoVerifyRTC(RTCdata->yearhi, RTCdata->yearlo) != 0) {
osSendMesg(mq, (void*)LEO_SENSE_ILLEGAL_TIMER_VALUE, 1);
return 0;
}
cmdBlock->header.command = LEO_COMMAND_SET_TIMER;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
_bcopy(RTCdata, &cmdBlock->data.time, 8);
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
}
cmdBlock->header.command = LEO_COMMAND_SET_TIMER;
cmdBlock->header.reserve1 = 0;
cmdBlock->header.control = 0;
cmdBlock->header.reserve3 = 0;
_bcopy(RTCdata, &cmdBlock->data.time, 8);
if (mq != NULL) {
cmdBlock->header.control |= LEO_CONTROL_POST;
cmdBlock->header.post = mq;
}
leoCommand(cmdBlock);
return 0;
}
/*
* The "year" is expressed in 4 digits with the high 2 digits being yearhi and low 2 digits being yearlo. 2023 = 0x20, 0x23
* The "hour" member uses the 24-hour clock.
* Return 0 if year is between ranges from 1996 to 2095
* The "year" is expressed in 4 digits with the high 2 digits being yearhi and low 2 digits being yearlo. 2023 = 0x20,
* 0x23 The "hour" member uses the 24-hour clock. Return 0 if year is between ranges from 1996 to 2095
*/
s32 leoVerifyRTC(u8 yearhi, u8 yearlo) {
u32 year;
if (((yearlo & 0xF) >= 0xA) || ((yearlo & 0xF0) >= 0x91) || ((yearhi & 0xF) >= 0xA) || ((yearhi & 0xF0) >= 0x91)) {
return 1;
}
year = (((yearhi - ((yearhi >> 4) * 6)) * 0x64) + yearlo) - ((yearlo >> 4) * 6);
if ((year < 0x7CCU) || (year >= 0x830U)) {
return 1;
}
return 0;
u32 year;
if (((yearlo & 0xF) >= 0xA) || ((yearlo & 0xF0) >= 0x91) || ((yearhi & 0xF) >= 0xA) || ((yearhi & 0xF0) >= 0x91)) {
return 1;
}
year = (((yearhi - ((yearhi >> 4) * 6)) * 0x64) + yearlo) - ((yearlo >> 4) * 6);
if ((year < 0x7CCU) || (year >= 0x830U)) {
return 1;
}
return 0;
}

View File

@ -9,18 +9,18 @@ s32 LeoSpdlMotor(LEOCmd* cmdBlock, u8 mode, OSMesgQueue* mq) {
cmdBlock->header.reserve1 = 0;
switch (mode) {
case LEO_MOTOR_ACTIVE:
cmdBlock->header.control = LEO_CONTROL_START;
break;
case LEO_MOTOR_STANDBY:
cmdBlock->header.control = LEO_CONTROL_STBY;
break;
case LEO_MOTOR_SLEEP:
cmdBlock->header.control = 0;
break;
case LEO_MOTOR_BRAKE:
cmdBlock->header.control = LEO_CONTROL_BRAKE;
break;
case LEO_MOTOR_ACTIVE:
cmdBlock->header.control = LEO_CONTROL_START;
break;
case LEO_MOTOR_STANDBY:
cmdBlock->header.control = LEO_CONTROL_STBY;
break;
case LEO_MOTOR_SLEEP:
cmdBlock->header.control = 0;
break;
case LEO_MOTOR_BRAKE:
cmdBlock->header.control = LEO_CONTROL_BRAKE;
break;
}
cmdBlock->header.reserve3 = 0;

View File

@ -2,22 +2,22 @@
#include "libleo/internal.h"
s32 LeoTestUnitReady(u8* status) {
volatile LEOCmdTestUnitReady cmdBlock;
volatile LEOCmdTestUnitReady cmdBlock;
if (!__leoActive) {
return -1;
}
if (HW_REG(PI_STATUS_REG, u32) & 1) {
return LEO_STATUS_BUSY;
}
cmdBlock.header.command = 3;
cmdBlock.header.reserve1 = 0;
cmdBlock.header.control = 0;
cmdBlock.header.reserve3 = 0;
leoCommand((void *)&cmdBlock);
if (!__leoActive) {
return -1;
}
if (HW_REG(PI_STATUS_REG, u32) & 1) {
return LEO_STATUS_BUSY;
}
cmdBlock.header.command = 3;
cmdBlock.header.reserve1 = 0;
cmdBlock.header.control = 0;
cmdBlock.header.reserve3 = 0;
leoCommand((void*)&cmdBlock);
while (cmdBlock.header.status == LEO_STATUS_BUSY) {}
while (cmdBlock.header.status == LEO_STATUS_BUSY) {}
*status = cmdBlock.test;
return cmdBlock.header.sense;
}
*status = cmdBlock.test;
return cmdBlock.header.sense;
}

View File

@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never

View File

@ -1,5 +1,4 @@
#include <ultra64.h>
#include "common.h"
#include "dp_intro.h"
#include "crash_screen.h"
@ -8,7 +7,7 @@
extern void func_8002B330(); // thread 6 function
// entry .bss
u8 D_8007ED80[0xF180-0xED80]; // unknown, start of .bss
u8 D_8007ED80[0xF180 - 0xED80]; // unknown, start of .bss
OSThread gIdleThread;
u8 unk_8007F330[0x400];
OSThread pThreads;
@ -20,7 +19,7 @@ u8 D_800818F8[0x8];
/**
* Initialize hardware, start main thread, then idle.
*/
void thread1_idle(UNUSED void *arg0) {
void Idle_ThreadEntry(UNUSED void* unused) {
osCreateViManager(OS_PRIORITY_VIMGR);
func_80001474(0, 1);
osViBlack(TRUE);
@ -35,14 +34,20 @@ void thread1_idle(UNUSED void *arg0) {
osSetThreadPri(NULL, 0);
// Halt
while(TRUE);
while (TRUE) {
;
}
}
void main_func(void) {
/**
* C entrypoint from the boot/entry code. Starts the libultra OS library and
* creates the idle thread which bootstraps the rest of the game.
*/
void Main(void) {
osInitialize();
osCartRomInit();
set_watch_lohi(0);
func_80002F58();
osCreateThread(&gIdleThread, 1, &thread1_idle, 0, &pThreads, 100);
Util_InitMainPools();
osCreateThread(&gIdleThread, THREAD_ID_IDLE, &Idle_ThreadEntry, NULL, &pThreads, THREAD_PRI_IDLE_INIT);
osStartThread(&gIdleThread);
}

View File

@ -6,7 +6,7 @@
*/
void Memmap_SetSegmentMap(u32 id, uintptr_t vaddr, size_t size) {
gSegments[id].vaddr = vaddr;
gSegments[id].size = size;
gSegments[id].size = size;
}
/*
@ -27,7 +27,7 @@ uintptr_t Memmap_GetSegmentBaseVaddr(u32 id) {
*/
uintptr_t Memmap_GetSegmentVaddr(u32 mask) {
if ((mask >> 0x1C) == 0) {
u32 id = (mask & 0x0F000000) >> 0x18;
u32 id = (mask & 0x0F000000) >> 0x18;
u32 value = (mask & 0x00FFFFFF) >> 0x00;
if (gSegments[id].vaddr != NULL) {
mask = gSegments[id].vaddr + value;
@ -55,19 +55,19 @@ u32 Memmap_GetSegmentVaddrMask(u32 i, uintptr_t addr) {
*/
void Memmap_ClearSegmentMemmap(u32 id) {
gSegments[id].vaddr = NULL;
gSegments[id].size = 0;
gSegments[id].size = 0;
}
/*
* Initialize the 16 segments with the segment memmap virtual addresses for the
* display list head.
* display list head.
*/
void Memmap_SetSegments(Gfx** gfxDl) {
u32 i;
Gfx* gfx = *gfxDl;
for(i = 0; i < 16; i++) {
gSPSegment(gfx++, i, osVirtualToPhysical((void *)gSegments[i].vaddr));
for (i = 0; i < 16; i++) {
gSPSegment(gfx++, i, osVirtualToPhysical((void*)gSegments[i].vaddr));
}
*gfxDl = gfx;
}
@ -77,28 +77,28 @@ void Memmap_SetSegments(Gfx** gfxDl) {
*/
void Memmap_RelocateFragment(u32 id, struct Fragment* fragment) {
u32 isLoNeg;
u32 *luiRefs[32];
u32* luiRefs[32];
u32 luiVals[32];
u32 *luiInstRef;
u32 *relocDataP;
u32* luiInstRef;
u32* relocDataP;
u32 relocSize;
struct RelocTable* relocInfo;
UNUSED u32 relocOffset;
u32 reloc;
u32 temp_v0_5;
u32 i;
u32 *regValP;
u32* regValP;
UNUSED s32 pad;
relocOffset = fragment->relocOffset;
relocSize = fragment->sizeInRam - fragment->relocOffset;
relocInfo = (struct RelocTable *)((uintptr_t)fragment->relocOffset + (uintptr_t)fragment);
relocInfo = (struct RelocTable*)((uintptr_t)fragment->relocOffset + (uintptr_t)fragment);
osInvalICache(fragment, fragment->sizeInRam);
osInvalDCache(fragment, fragment->sizeInRam);
Memmap_SetFragmentMap(id, (uintptr_t)fragment, fragment->sizeInRam);
for(i = 0; i < relocInfo->nRelocations; i++) {
for (i = 0; i < relocInfo->nRelocations; i++) {
reloc = relocInfo->relocations[i];
relocDataP = (u32*)((reloc & 0xFFFFFF) + (uintptr_t)fragment);
@ -112,7 +112,9 @@ void Memmap_RelocateFragment(u32 id, struct Fragment* fragment) {
// Handles 26-bit address relocation, used for jumps and jals.
// Extract the address from the target field of the J-type MIPS instruction.
// Relocate the address and update the instruction.
*relocDataP = (((u32) (Memmap_GetFragmentVaddr(((*relocDataP * 4) & 0x0FFFFFFC) + 0x80000000) & 0x0FFFFFFF) >> 2) | (*relocDataP & 0xFC000000));
*relocDataP =
(((u32)(Memmap_GetFragmentVaddr(((*relocDataP * 4) & 0x0FFFFFFC) + 0x80000000) & 0x0FFFFFFF) >> 2) |
(*relocDataP & 0xFC000000));
break;
case R_MIPS_HI16:
// Handles relocation for a hi/lo pair, part 1.
@ -132,13 +134,13 @@ void Memmap_RelocateFragment(u32 id, struct Fragment* fragment) {
temp_v0_5 = Memmap_GetFragmentVaddr((*regValP << 0x10) + (s16)*relocDataP);
isLoNeg = (temp_v0_5 & 0x8000) ? 1 : 0;
*luiInstRef = (u32) ((*luiInstRef & 0xFFFF0000) | ((temp_v0_5 >> 16) + isLoNeg));
*relocDataP = (u32) ((*relocDataP & 0xFFFF0000) | (temp_v0_5 & 0xFFFF));
*luiInstRef = (u32)((*luiInstRef & 0xFFFF0000) | ((temp_v0_5 >> 16) + isLoNeg));
*relocDataP = (u32)((*relocDataP & 0xFFFF0000) | (temp_v0_5 & 0xFFFF));
break;
}
}
if (relocSize != 0) {
bzero((void *)((uintptr_t)fragment->relocOffset + (uintptr_t)fragment), relocSize);
bzero((void*)((uintptr_t)fragment->relocOffset + (uintptr_t)fragment), relocSize);
}
osWritebackDCache(fragment, fragment->sizeInRam);
}
@ -170,7 +172,7 @@ uintptr_t Memmap_GetFragmentBaseVaddr(u32 id) {
*/
uintptr_t Memmap_GetFragmentVaddr(u32 mask) {
if ((mask >= 0x81000000U) && (mask < 0x90000000U)) {
u32 id = ((mask & 0x0FF00000) >> 0x14) - 0x10;
u32 id = ((mask & 0x0FF00000) >> 0x14) - 0x10;
u32 value = ((mask & 0x000FFFFF));
if (gFragments[id].vaddr != NULL) {
mask = gFragments[id].vaddr + value;
@ -209,7 +211,7 @@ uintptr_t Memmap_GetLoadedFragmentVaddr(uintptr_t addr) {
struct MemoryMap* fraglist = gFragments;
int i, UNUSED j;
for(i = 0, fraglist = gFragments; i < 0xF0; i++, fraglist++) {
for (i = 0, fraglist = gFragments; i < 0xF0; i++, fraglist++) {
if (addr >= fraglist->vaddr) {
size_t diff = addr - fraglist->vaddr;
if (diff < fraglist->size) {

View File

@ -9,9 +9,9 @@
* order for allocation/freeing.
* Return NULL if there is not enough space in the main pool.
*/
struct MemoryPool *mem_pool_try_init(u32 size, s32 side) {
struct MainPoolBlock *block;
struct MemoryPool *ret;
struct MemoryPool* mem_pool_try_init(u32 size, s32 side) {
struct MainPoolBlock* block;
struct MemoryPool* ret;
size = ALIGN4(size);
block = main_pool_alloc_node_no_func(size, side);
@ -28,13 +28,14 @@ struct MemoryPool *mem_pool_try_init(u32 size, s32 side) {
// TODO: This function is strange, it cant be using MemoryPool, as it allocates
// more variables than the MemoryPool struct, and it doesnt line up. Whats going
// on with these structs?
struct MainPool* mem_pool_init(struct MainPool *pool, s32 size) {
s32 aligned_size = ALIGN4(size - 3) - 0x28; // whats the deal with 0x28? this size doesnt match any known pool struct.
void *listHeadL = &pool->listHeadL;
struct MainPool* mem_pool_init(struct MainPool* pool, s32 size) {
s32 aligned_size =
ALIGN4(size - 3) - 0x28; // whats the deal with 0x28? this size doesnt match any known pool struct.
void* listHeadL = &pool->listHeadL;
pool->available = aligned_size;
pool->start = listHeadL;
pool->end = listHeadL;
pool->start = listHeadL;
pool->end = listHeadL;
pool->listHeadL = NULL;
pool->listHeadR = aligned_size;
osCreateMesgQueue(&pool->queue, &pool->msgs[0], 1);
@ -45,26 +46,26 @@ struct MainPool* mem_pool_init(struct MainPool *pool, s32 size) {
/**
* Allocate from a memory pool. Return NULL if there is not enough space.
*/
void *mem_pool_alloc(struct MainPool *node, s32 size) {
struct MemoryBlock *freeBlock;
void *addr;
void* mem_pool_alloc(struct MainPool* node, s32 size) {
struct MemoryBlock* freeBlock;
void* addr;
osRecvMesg(&node->queue, 0, 1);
addr = NULL;
size = ALIGN4(size) + sizeof(struct MemoryBlock);
freeBlock = (struct MemoryBlock *)&node->end;
freeBlock = (struct MemoryBlock*)&node->end;
while (freeBlock->next != NULL) {
if (freeBlock->next->size >= size) {
addr = (u8*)freeBlock->next + sizeof(struct MemoryBlock); //get data after header
addr = (u8*)freeBlock->next + sizeof(struct MemoryBlock); // get data after header
if (freeBlock->next->size - size <= sizeof(struct MemoryBlock)) {
freeBlock->next = freeBlock->next->next;
} else {
struct MemoryBlock *newBlock = (struct MemoryBlock *)((u8 *)freeBlock->next + size);
newBlock->size = freeBlock->next->size - size; //set size
struct MemoryBlock* newBlock = (struct MemoryBlock*)((u8*)freeBlock->next + size);
newBlock->size = freeBlock->next->size - size; // set size
newBlock->next = freeBlock->next->next;
freeBlock->next->size = size; //set size
freeBlock->next->size = size; // set size
freeBlock->next = newBlock;
}
break;
@ -81,27 +82,24 @@ void *mem_pool_alloc(struct MainPool *node, s32 size) {
void mem_pool_free(struct MemoryPool* pool, void* addr) {
struct MemoryBlock* block;
struct MemoryBlock* freeList;
if (addr != NULL) {
if (addr != NULL) {
osRecvMesg(&pool->queue, NULL, 1);
block = (struct MemoryBlock*)((u8*)addr - sizeof(struct MemoryBlock));
freeList = pool->freeList.next;
if (pool->freeList.next == NULL) {
pool->freeList.next = block;
block->next = NULL;
}
else if (block < pool->freeList.next) {
} else if (block < pool->freeList.next) {
if ((u32)pool->freeList.next == ((u32)block + (u32)block->size)) {
block->size += ((u32) freeList->size);
block->size += ((u32)freeList->size);
block->next = freeList->next;
pool->freeList.next = block;
}
else {
} else {
block->next = pool->freeList.next;
pool->freeList.next = block;
}
}
else {
} else {
while (freeList->next != NULL) {
if (freeList < block && block < freeList->next) {
break;
@ -111,8 +109,7 @@ void mem_pool_free(struct MemoryPool* pool, void* addr) {
if (((u32)freeList + (u32)freeList->size) == (u32)block) {
freeList->size += block->size;
block = freeList;
}
else {
} else {
block->next = freeList->next;
freeList->next = block;
}
@ -125,9 +122,9 @@ void mem_pool_free(struct MemoryPool* pool, void* addr) {
}
}
void *func_80002D10(u32 size, s32 side) {
void* func_80002D10(u32 size, s32 side) {
struct MainPoolBlock* block;
void *ptr = NULL;
void* ptr = NULL;
size = ALIGN4(size);
ptr = 0;
@ -151,7 +148,7 @@ void* func_80002DA4(struct MainPoolState* block, s32 size) {
block->listHeadL = 0;
block->freeSpace = ((size & ~3) - 0x10); // this doesnt match an ALIGN4 macro or whatnot
block->listHeadR = temp_v1;
block->prev = temp_v1;
block->prev = temp_v1;
return block;
}
@ -171,7 +168,7 @@ s32 func_80002DCC(struct MainPoolState* state, s32 arg1, s32 arg2) {
temp_a3 = (s32)state->listHeadL + temp_a2;
if ((s32)state->freeSpace >= temp_a3) {
ret = var_v0;
state->prev = (s32) ((s32)state->prev + temp_a2);
state->prev = (s32)((s32)state->prev + temp_a2);
state->listHeadL = temp_a3;
}
}

View File

@ -9,9 +9,9 @@ static struct MainPool sMemPool;
* that grow inward from the left and right. It therefore only supports
* freeing the object that was most recently allocated from a side.
*/
void main_pool_init(void *start, void *end) {
sMemPool.start = (void *)(ALIGN16((uintptr_t)start) + 16);
sMemPool.end = (void *)(ALIGN16((uintptr_t)end - 15) - 16);
void main_pool_init(void* start, void* end) {
sMemPool.start = (void*)(ALIGN16((uintptr_t)start) + 16);
sMemPool.end = (void*)(ALIGN16((uintptr_t)end - 15) - 16);
sMemPool.available = (uintptr_t)sMemPool.end - (uintptr_t)sMemPool.start;
sMemPool.mainState = NULL;
@ -19,13 +19,13 @@ void main_pool_init(void *start, void *end) {
sMemPool.listHeadL->prev = NULL;
sMemPool.listHeadL->next = NULL;
sMemPool.listHeadL->func = NULL;
sMemPool.listHeadL->arg = 0;
sMemPool.listHeadL->arg = 0;
sMemPool.listHeadR = sMemPool.end;
sMemPool.listHeadR->prev = NULL;
sMemPool.listHeadR->next = NULL;
sMemPool.listHeadL->func = NULL;
sMemPool.listHeadL->arg = 0;
sMemPool.listHeadL->arg = 0;
osCreateMesgQueue(&sMemPool.queue, sMemPool.msgs, ARRAY_COUNT(sMemPool.msgs));
osSendMesg(&sMemPool.queue, NULL, OS_MESG_NOBLOCK);
@ -36,15 +36,15 @@ void main_pool_init(void *start, void *end) {
* specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT).
* If there is not enough space, return NULL.
*/
void *main_pool_alloc(u32 size, u32 side) {
struct MainPoolBlock *newListHead;
void *addr = NULL;
void* main_pool_alloc(u32 size, u32 side) {
struct MainPoolBlock* newListHead;
void* addr = NULL;
size = ALIGN16(size) + sizeof(struct MainPoolBlock);
if (size != 0 && sMemPool.available >= size) {
if (side == MEMORY_POOL_LEFT) {
sMemPool.available -= size;
newListHead = (void *)((uintptr_t)sMemPool.listHeadL + size);
newListHead = (void*)((uintptr_t)sMemPool.listHeadL + size);
sMemPool.listHeadL->next = newListHead;
newListHead->prev = sMemPool.listHeadL;
newListHead->next = NULL;
@ -54,7 +54,7 @@ void *main_pool_alloc(u32 size, u32 side) {
sMemPool.listHeadL = newListHead;
} else if (side == MEMORY_POOL_RIGHT) {
sMemPool.available -= size;
newListHead = (void *)((uintptr_t)sMemPool.listHeadR - size);
newListHead = (void*)((uintptr_t)sMemPool.listHeadR - size);
sMemPool.listHeadR->prev = newListHead;
newListHead->next = sMemPool.listHeadR;
newListHead->prev = NULL;
@ -73,22 +73,20 @@ void *main_pool_alloc(u32 size, u32 side) {
* newer blocks are freed as well.
* Return the amount of free space left in the pool.
*/
u32 main_pool_free(void *addr, u32 runBlockFunc) {
struct MainPoolBlock *block = (struct MainPoolBlock *)((u8 *)addr - sizeof(struct MainPoolBlock));
struct MainPoolBlock *oldListHead = (struct MainPoolBlock *)((u8 *)addr - sizeof(struct MainPoolBlock));
u32 main_pool_free(void* addr, u32 runBlockFunc) {
struct MainPoolBlock* block = (struct MainPoolBlock*)((u8*)addr - sizeof(struct MainPoolBlock));
struct MainPoolBlock* oldListHead = (struct MainPoolBlock*)((u8*)addr - sizeof(struct MainPoolBlock));
if (oldListHead < sMemPool.listHeadL) {
do {
block = (sMemPool.listHeadL = sMemPool.listHeadL->prev);
if (runBlockFunc) {
// TODO: Fakematch
void (*func)(struct MainPoolBlock *, u32) = block->func;
void (*func)(struct MainPoolBlock*, u32) = block->func;
if (func != 0) {
block->func(block + 1, block->arg);
block->func(block + 1, block->arg);
// TODO: fake here too
if ((!(&sMemPool)) && (!(&sMemPool)))
{
}
if ((!(&sMemPool)) && (!(&sMemPool))) {}
}
}
sMemPool.available += ((uintptr_t)sMemPool.listHeadL->next - (uintptr_t)sMemPool.listHeadL);
@ -99,7 +97,7 @@ u32 main_pool_free(void *addr, u32 runBlockFunc) {
if (oldListHead >= block && oldListHead >= block) {
do {
if (runBlockFunc) {
void (*func)(struct MainPoolBlock *, u32) = block->func;
void (*func)(struct MainPoolBlock*, u32) = block->func;
if (func != NULL) {
func(block + 1, block->arg);
block = sMemPool.listHeadR;
@ -120,8 +118,8 @@ u32 main_pool_free(void *addr, u32 runBlockFunc) {
* Manually allocate and initialize a block given a size and side and its
* function+arguments.
*/
void *main_pool_alloc_node(u32 size, s32 side, s32 arg, void *func) {
struct MainPoolBlock *node;
void* main_pool_alloc_node(u32 size, s32 side, s32 arg, void* func) {
struct MainPoolBlock* node;
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
node = main_pool_alloc(size, side);
@ -129,15 +127,15 @@ void *main_pool_alloc_node(u32 size, s32 side, s32 arg, void *func) {
main_pool_set_func(node, arg, func);
}
osSendMesg(&sMemPool.queue, NULL, OS_MESG_NOBLOCK);
return node;
}
/**
* Same as above but no function/argument is set.
*/
void *main_pool_alloc_node_no_func(u32 size, s32 side) {
struct MainPoolBlock *node;
void* main_pool_alloc_node_no_func(u32 size, s32 side) {
struct MainPoolBlock* node;
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
node = main_pool_alloc(size, side);
@ -150,7 +148,7 @@ void *main_pool_alloc_node_no_func(u32 size, s32 side) {
* Tries to free a block of memory that was allocated from the pool. Return
* the new available amount of the pool.
*/
u32 main_pool_try_free(struct MainPoolBlock *addr) {
u32 main_pool_try_free(struct MainPoolBlock* addr) {
if (addr != NULL) {
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
main_pool_free(addr, 1);
@ -166,9 +164,9 @@ u32 main_pool_try_free(struct MainPoolBlock *addr) {
* block from the left side.
* The block does not move.
*/
void *main_pool_realloc(void *addr, size_t size) {
struct MainPoolBlock *prior = (struct MainPoolBlock *)((u8 *)addr - sizeof(struct MainPoolBlock));
void *newaddr = NULL;
void* main_pool_realloc(void* addr, size_t size) {
struct MainPoolBlock* prior = (struct MainPoolBlock*)((u8*)addr - sizeof(struct MainPoolBlock));
void* newaddr = NULL;
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
@ -177,7 +175,7 @@ void *main_pool_realloc(void *addr, size_t size) {
size = ALIGN16(size);
if (diff >= size || sMemPool.available >= (size - diff)) {
s32 arg = prior->arg;
void *func = prior->func;
void* func = prior->func;
main_pool_free(addr, 0);
newaddr = main_pool_alloc(size, MEMORY_POOL_LEFT);
main_pool_set_func(newaddr, arg, func);
@ -205,9 +203,9 @@ u32 main_pool_get_available(void) {
* in the pool.
*/
u32 main_pool_push_state(u32 arg) {
struct MainPoolState *state;
struct MainPoolBlock *listHeadL;
struct MainPoolBlock *listHeadR;
struct MainPoolState* state;
struct MainPoolBlock* listHeadL;
struct MainPoolBlock* listHeadR;
uintptr_t available;
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
@ -221,15 +219,15 @@ u32 main_pool_push_state(u32 arg) {
if (state != NULL) {
/**
* Why is this line here? What this line is doing is backing the pointer up to the
* previous block before this one. in the block alloc function, addr is determined
* previous block before this one. in the block alloc function, addr is determined
* by the head plus the size of the block struct, meaning it is returning the
* pointer to the head.
*/
((struct MainPoolBlock *)((u8*)state-sizeof(struct MainPoolBlock)))->arg = arg;
((struct MainPoolBlock*)((u8*)state - sizeof(struct MainPoolBlock)))->arg = arg;
// now that the previous block's argument is set, set the newly allocated state's
// fields.
state->prev = sMemPool.mainState;
state->prev = sMemPool.mainState;
state->freeSpace = available;
state->listHeadL = listHeadL;
state->listHeadR = listHeadR;
@ -246,11 +244,11 @@ u32 main_pool_push_state(u32 arg) {
* amount of free space left in the pool.
*/
u32 main_pool_pop_state(u32 arg) {
struct MainPoolState *node;
struct MainPoolBlock *argptr;
void *listHeadL;
void *listHeadR;
struct MainPoolState *state;
struct MainPoolState* node;
struct MainPoolBlock* argptr;
void* listHeadL;
void* listHeadR;
struct MainPoolState* state;
argptr = (u32)arg;
osRecvMesg(&sMemPool.queue, NULL, OS_MESG_BLOCK);
@ -263,20 +261,20 @@ u32 main_pool_pop_state(u32 arg) {
sMemPool.mainState = node->prev;
// was the argument passed in 0?
if (argptr == 0) {
break;
if (argptr == 0) {
break;
}
// odd reuse of the variable, but what this is doing is backing the ptr up to the
// pool block. Thus, to check the arg variable on the pool block located before the state,
// pool block. Thus, to check the arg variable on the pool block located before the state,
// we will need to cast the next if check.
node = (void*)((u8*)node - sizeof(struct MainPoolState));
if ((uintptr_t)argptr == (uintptr_t)((struct MainPoolBlock *)node)->arg) {
if ((uintptr_t)argptr == (uintptr_t)((struct MainPoolBlock*)node)->arg) {
// we found the block with the matching string! break.
break;
break;
}
} while(sMemPool.mainState != NULL);
} while (sMemPool.mainState != NULL);
argptr = sMemPool.listHeadR;
while ((uintptr_t)listHeadR > (uintptr_t)argptr) {
@ -306,20 +304,20 @@ u32 main_pool_pop_state(u32 arg) {
* Without this being called, its hard to tell the correct context of this
* function.
*/
void *main_pool_search(uintptr_t addr, s32 *argPtr) {
struct MainPoolBlock *node;
struct MainPoolBlock *otherNode;
void* main_pool_search(uintptr_t addr, s32* argPtr) {
struct MainPoolBlock* node;
struct MainPoolBlock* otherNode;
node = sMemPool.listHeadL->prev;
while (node != NULL) {
int isAddrLater = (addr >= ((uintptr_t) ((u8*)node + sizeof(struct MainPoolBlock))));
int isAddrLater = (addr >= ((uintptr_t)((u8*)node + sizeof(struct MainPoolBlock))));
otherNode = node->next;
// seems to be checking for an addr within a block region? Since this function
// is unused, we wont be able to check for the intended context of what could
// call this function.
if (isAddrLater && addr < ((uintptr_t)otherNode & 0xFFFFFFFF)) {
if (argPtr != NULL) {
*argPtr = node->arg;
*argPtr = node->arg;
}
// return the pointer to its block contents.
return (void*)((u8*)(node) + sizeof(struct MainPoolBlock));
@ -331,12 +329,12 @@ void *main_pool_search(uintptr_t addr, s32 *argPtr) {
node = sMemPool.listHeadR;
otherNode = node->next;
while (otherNode != NULL) {
int isAddrLater = (addr >= ((uintptr_t) ((u8*)node + sizeof(struct MainPoolBlock))));
struct MainPoolBlock *new_var = otherNode; // bit of a fakematch to force the move reload.
int isAddrLater = (addr >= ((uintptr_t)((u8*)node + sizeof(struct MainPoolBlock))));
struct MainPoolBlock* new_var = otherNode; // bit of a fakematch to force the move reload.
// same as above.
if (isAddrLater && (addr < ((uintptr_t)new_var & 0xFFFFFFFF))) {
if (argPtr != NULL) {
*argPtr = node->arg;
*argPtr = node->arg;
}
// return the pointer to its block contents.
return (void*)((u8*)(node) + sizeof(struct MainPoolBlock));
@ -350,8 +348,8 @@ void *main_pool_search(uintptr_t addr, s32 *argPtr) {
/**
* Set the block function and its argument(s) for a given block.
*/
void main_pool_set_func(void *block, s32 arg, void *func) {
struct MainPoolBlock *node = (void*)((uintptr_t)block - sizeof(struct MainPoolBlock));
void main_pool_set_func(void* block, s32 arg, void* func) {
struct MainPoolBlock* node = (void*)((uintptr_t)block - sizeof(struct MainPoolBlock));
node->func = func;
node->arg = arg;
}
@ -359,8 +357,8 @@ void main_pool_set_func(void *block, s32 arg, void *func) {
/**
* Get the distance offset from the block's state listHeadL pointer to the current block.
*/
size_t main_pool_get_block_dist(struct MainPoolBlock *block) {
struct MainPoolState *state = ((u8*)block - sizeof(struct MainPoolBlock));
size_t main_pool_get_block_dist(struct MainPoolBlock* block) {
struct MainPoolState* state = ((u8*)block - sizeof(struct MainPoolBlock));
return (size_t)((uintptr_t)state->listHeadL - (uintptr_t)block);
}
@ -368,6 +366,6 @@ size_t main_pool_get_block_dist(struct MainPoolBlock *block) {
/**
* Return the pointer to the static memory pool area.
*/
struct MainPool *main_pool_get_pool(void) {
struct MainPool* main_pool_get_pool(void) {
return &sMemPool;
}

View File

@ -2,7 +2,7 @@
#include "profiler.h"
extern OSTime D_800A6CE8;
extern Gfx *gDisplayListHead;
extern Gfx* gDisplayListHead;
struct Profiler gProfiler;
@ -14,7 +14,7 @@ struct Profiler gProfiler;
*
* TODO: Is there any way to derive this value correctly?
*/
#define UNK_FPS_60_APPROX_VALUE 770296
#define UNK_FPS_60_APPROX_VALUE 770296
// log the current osTime to the appropriate idx for current thread5 processes.
void profiler_log_thread5_time(enum ProfilerGameEvent eventID) {
@ -38,10 +38,10 @@ void profiler_log_thread5_time(enum ProfilerGameEvent eventID) {
// log the audio system before and after osTimes in pairs to the soundTimes array.
void profiler_log_thread4_time(void) {
struct ProfilerFrameData *profiler = &gProfiler.profiler_data[gProfiler.frameIdx1];
struct ProfilerFrameData* profiler = &gProfiler.profiler_data[gProfiler.frameIdx1];
if(profiler->numSoundTimes < ARRAY_COUNT(profiler->soundTimes)) {
profiler->soundTimes[profiler->numSoundTimes++] = osGetTime();
if (profiler->numSoundTimes < ARRAY_COUNT(profiler->soundTimes)) {
profiler->soundTimes[profiler->numSoundTimes++] = osGetTime();
}
}
@ -60,7 +60,7 @@ void profiler_log_gfx_time(enum ProfilerGfxEvent eventID) {
// log the times between vblank started and ended.
void profiler_log_vblank_time(void) {
struct ProfilerFrameData *profiler = &gProfiler.profiler_data[gProfiler.frameIdx2];
struct ProfilerFrameData* profiler = &gProfiler.profiler_data[gProfiler.frameIdx2];
if (profiler->numVblankTimes < ARRAY_COUNT(profiler->vblankTimes)) {
profiler->vblankTimes[profiler->numVblankTimes++] = osGetTime();
@ -104,7 +104,7 @@ void draw_profiler_bar_cpu(OSTime clockBase, OSTime clockStart, OSTime clockEnd,
// convert the cycles to microseconds, but multiply by 3 before converting them
// to nanoseconds. So why not just use OS_CYCLES_TO_NSEC?
rectX1 = ((OS_CYCLES_TO_USEC(durationStart)) * 3ULL / 1000ULL) + 30;
rectX2 = ((OS_CYCLES_TO_USEC(durationEnd)) * 3ULL / 1000ULL) + 30;
rectX2 = ((OS_CYCLES_TO_USEC(durationEnd)) * 3ULL / 1000ULL) + 30;
if (rectX1 > 225) {
rectX1 = 225;
@ -131,23 +131,23 @@ void draw_profiler_bar_cpu_keep_max(OSTime start, OSTime end, s16 posY, s16* las
// set the duration, and floor to 0 if the result is below 0.
if ((duration = end - start) < 0) {
duration = 0;
duration = 0;
}
// like earlier, multiply by 3 and convert to nsec by dividing by 1000.
// why not just use OS_CYCLES_TO_NSEC?
lrx = (OS_CYCLES_TO_USEC(duration) * 3ULL / 1000ULL) + 30;
if(lrx > 225) {
lrx = 225;
if (lrx > 225) {
lrx = 225;
}
// Keep the maximum lrx seen in the last 16 calls. If a new max is seen, reset
// the counter to start over and set the new observed maximum.
if(++*reset_ctr > 15 || *last_max < lrx) {
if (++*reset_ctr > 15 || *last_max < lrx) {
*reset_ctr = 0;
*last_max = lrx;
}
// now that we have a max, build the coordinates to make the rect.
lrx = *last_max;
ulx = lrx - 4;
@ -162,10 +162,10 @@ void draw_profiler_bar_cpu_keep_max(OSTime start, OSTime end, s16 posY, s16* las
void draw_reference_profiler_bars(void) {
// Draws the reference "max" bars underneath the real thing.
draw_profiler_rect(30, 79, 220, GPACK_RGBA5551(40, 80, 255, 1)); // Blue
draw_profiler_rect(79, 128, 220, GPACK_RGBA5551(255, 255, 40, 1)); // Yellow
draw_profiler_rect(128, 177, 220, GPACK_RGBA5551(255, 120, 40, 1)); // Orange
draw_profiler_rect(177, 226, 220, GPACK_RGBA5551(255, 40, 40, 1)); // Red
draw_profiler_rect(30, 79, 220, GPACK_RGBA5551(40, 80, 255, 1)); // Blue
draw_profiler_rect(79, 128, 220, GPACK_RGBA5551(255, 255, 40, 1)); // Yellow
draw_profiler_rect(128, 177, 220, GPACK_RGBA5551(255, 120, 40, 1)); // Orange
draw_profiler_rect(177, 226, 220, GPACK_RGBA5551(255, 40, 40, 1)); // Red
}
/*
@ -174,22 +174,24 @@ void draw_reference_profiler_bars(void) {
*/
void draw_profiler_mode_1(void) {
s32 i;
struct ProfilerFrameData *profiler;
struct ProfilerFrameData *profiler_2;
struct ProfilerFrameData* profiler;
struct ProfilerFrameData* profiler_2;
OSTime clockBase;
// set profiler pointers. first pointer is for game+sound profiler and 2nd is for gfx and vblank.
profiler = &gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
profiler = &gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
profiler_2 = &gProfiler.profiler_data[(gProfiler.frameIdx2 == 0) ? 2 : gProfiler.frameIdx2 - 1];
// calculate the clockBase.
clockBase = profiler->gameTimes[0] - UNK_FPS_60_APPROX_VALUE;
// (yellow)
draw_profiler_bar_cpu(clockBase, profiler->gameTimes[0], profiler->gameTimes[1], 212, GPACK_RGBA5551(255, 255, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler->gameTimes[0], profiler->gameTimes[1], 212,
GPACK_RGBA5551(255, 255, 40, 1));
// (orange)
draw_profiler_bar_cpu(clockBase, profiler->gameTimes[1], profiler->gameTimes[2], 212, GPACK_RGBA5551(255, 120, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler->gameTimes[1], profiler->gameTimes[2], 212,
GPACK_RGBA5551(255, 120, 40, 1));
// we need to get the amount of finished numSoundTimes pairs, so get rid of the odd bit to get the
// limit of finished pairs.
@ -197,22 +199,26 @@ void draw_profiler_mode_1(void) {
// draw the sound update times. (red)
for (i = 0; i < profiler->numSoundTimes; i += 2) {
draw_profiler_bar_cpu(clockBase, profiler->soundTimes[i], profiler->soundTimes[i + 1], 212, GPACK_RGBA5551(255, 40, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler->soundTimes[i], profiler->soundTimes[i + 1], 212,
GPACK_RGBA5551(255, 40, 40, 1));
}
//! RSP and RDP run in parallel, so while they are not absolutely guaranteed to return in order,
// it is theoretically possible they might not. In all cases, the RDP should finish later than RSP.
// Thus, this is not really a bug in practice, but should still be noted that the C doesn't check
// this.
draw_profiler_bar_cpu(clockBase, profiler_2->gfxTimes[0], profiler_2->gfxTimes[1], 216, GPACK_RGBA5551(255, 255, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler_2->gfxTimes[1], profiler_2->gfxTimes[2], 216, GPACK_RGBA5551(255, 120, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler_2->gfxTimes[0], profiler_2->gfxTimes[1], 216,
GPACK_RGBA5551(255, 255, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler_2->gfxTimes[1], profiler_2->gfxTimes[2], 216,
GPACK_RGBA5551(255, 120, 40, 1));
// like earlier, toss the odd bit.
profiler_2->numVblankTimes &= 0xFFFE;
// render the vblank time pairs. (red)
for (i = 0; i < profiler_2->numVblankTimes; i += 2) {
draw_profiler_bar_cpu(clockBase, profiler_2->vblankTimes[i], profiler_2->vblankTimes[i + 1], 216, GPACK_RGBA5551(255, 40, 40, 1));
draw_profiler_bar_cpu(clockBase, profiler_2->vblankTimes[i], profiler_2->vblankTimes[i + 1], 216,
GPACK_RGBA5551(255, 40, 40, 1));
}
draw_reference_profiler_bars();
@ -223,21 +229,23 @@ void draw_profiler_mode_1(void) {
* easier to see which processes take the longest.
*/
void draw_profiler_mode_0(void) {
s32 i; // set profiler pointers. first pointer is for game+sound profiler and 2nd is for gfx and vblank.
struct ProfilerFrameData *profiler = &gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
OSTime clockStart = profiler->gameTimes[0] <= profiler->soundTimes[0] ? profiler->gameTimes[0]
: profiler->soundTimes[0];
s32 i; // set profiler pointers. first pointer is for game+sound profiler and 2nd is for gfx and vblank.
struct ProfilerFrameData* profiler =
&gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
OSTime clockStart =
profiler->gameTimes[0] <= profiler->soundTimes[0] ? profiler->gameTimes[0] : profiler->soundTimes[0];
OSTime gameDuration = profiler->gameTimes[1] - clockStart;
OSTime renderDuration = profiler->gameTimes[2] - profiler->gameTimes[1];
OSTime taskStart = 0;
struct ProfilerFrameData *profiler_2 = &gProfiler.profiler_data[(gProfiler.frameIdx2 == 0) ? 2 : gProfiler.frameIdx2 - 1];
struct ProfilerFrameData* profiler_2 =
&gProfiler.profiler_data[(gProfiler.frameIdx2 == 0) ? 2 : gProfiler.frameIdx2 - 1];
OSTime rspDuration = profiler_2->gfxTimes[1] - profiler_2->gfxTimes[0];
OSTime rdpDuration = profiler_2->gfxTimes[2] - profiler_2->gfxTimes[0];
OSTime vblank = 0;
static s16 sRenderLastMax = 0;
static s16 sRenderLastMax = 0;
static s16 sRenderResetCtr = 0;
static s16 sRDPLastMax = 0;
static s16 sRDPResetCtr = 0;
static s16 sRDPLastMax = 0;
static s16 sRDPResetCtr = 0;
// like above functions, toss the odd bit.
profiler->numSoundTimes &= 0xFFFE;
@ -270,13 +278,11 @@ void draw_profiler_mode_0(void) {
// draw game execution duration. (yellow)
clockStart += taskStart;
draw_profiler_bar_cpu(0, clockStart, clockStart + gameDuration, 212,
GPACK_RGBA5551(255, 255, 40, 1));
draw_profiler_bar_cpu(0, clockStart, clockStart + gameDuration, 212, GPACK_RGBA5551(255, 255, 40, 1));
// draw render duration. (orange)
clockStart += gameDuration;
draw_profiler_bar_cpu(0, clockStart, clockStart + renderDuration, 212,
GPACK_RGBA5551(255, 120, 40, 1));
draw_profiler_bar_cpu(0, clockStart, clockStart + renderDuration, 212, GPACK_RGBA5551(255, 120, 40, 1));
draw_profiler_bar_cpu_keep_max(0, clockStart + renderDuration, 212, &sRenderLastMax, &sRenderResetCtr);
@ -305,14 +311,14 @@ void draw_profiler(s32 profiler_mode) {
gDPSetCycleType(gDisplayListHead++, G_CYC_FILL);
gDPSetRenderMode(gDisplayListHead++, G_RM_NOOP, G_RM_NOOP2);
ulx = 30;
uly = 211;
ulx = 30;
uly = 211;
ulx_off = 196;
uly_off = 9;
if (func_80007A58() != 0) {
ulx <<= 1;
uly <<= 1;
ulx <<= 1;
uly <<= 1;
ulx_off <<= 1;
uly_off <<= 1;
}
@ -334,12 +340,16 @@ void draw_profiler(s32 profiler_mode) {
* used to measure for undesired lag (values above 1.0) when printed to the screen.
*/
void print_profiler_metrics(void) {
struct ProfilerFrameData *profiler = &gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
struct ProfilerFrameData *profiler_2 = &gProfiler.profiler_data[(gProfiler.frameIdx2 == 0) ? 2 : gProfiler.frameIdx2 - 1];
struct ProfilerFrameData* profiler =
&gProfiler.profiler_data[(gProfiler.frameIdx1 == 0) ? 2 : gProfiler.frameIdx1 - 1];
struct ProfilerFrameData* profiler_2 =
&gProfiler.profiler_data[(gProfiler.frameIdx2 == 0) ? 2 : gProfiler.frameIdx2 - 1];
s32 pad[3]; // i dont understand. but ok.
HAL_Printf(240, 210, "CPU:%5.3f", ((profiler->gameTimes[2] - profiler->gameTimes[0])) * (1/(float)UNK_FPS_60_APPROX_VALUE));
HAL_Printf(240, 220, "RCP:%5.3f", ((profiler_2->gfxTimes[2] - profiler_2->gfxTimes[0])) * (1/(float)UNK_FPS_60_APPROX_VALUE));
HAL_Printf(240, 210, "CPU:%5.3f",
((profiler->gameTimes[2] - profiler->gameTimes[0])) * (1 / (float)UNK_FPS_60_APPROX_VALUE));
HAL_Printf(240, 220, "RCP:%5.3f",
((profiler_2->gfxTimes[2] - profiler_2->gfxTimes[0])) * (1 / (float)UNK_FPS_60_APPROX_VALUE));
}
// reset the profiler data to uninitialized 0s.
@ -355,7 +365,7 @@ u32 set_get_time_diff(enum SetGetTimeDiff state) {
u32 ret = 0;
static OSTime sBackupTime = 0ULL;
switch(state) {
switch (state) {
case SET_TIME:
sBackupTime = osGetTime();
ret = 0;

140
src/rsp.c
View File

@ -3,11 +3,11 @@
#include "rsp.h"
// All from n64 programming manual section 27.2
#define SRAM_START_ADDR 0x08000000
#define SRAM_SIZE 0x8000
#define SRAM_latency 0x5
#define SRAM_pulse 0x0c
#define SRAM_pageSize 0xd
#define SRAM_START_ADDR 0x08000000
#define SRAM_SIZE 0x8000
#define SRAM_latency 0x5
#define SRAM_pulse 0x0c
#define SRAM_pageSize 0xd
#define SRAM_relDuration 0x2
OSThread gRspThread;
@ -40,7 +40,7 @@ OSPiHandle* func_80000628(void) {
static OSPiHandle sramHandle;
void* baseAddr = OS_PHYSICAL_TO_K1(SRAM_START_ADDR);
if (baseAddr != (void *)(uintptr_t)sramHandle.baseAddress) {
if (baseAddr != (void*)(uintptr_t)sramHandle.baseAddress) {
sramHandle.type = DEVICE_TYPE_SRAM;
sramHandle.baseAddress = (uintptr_t)baseAddr;
sramHandle.latency = SRAM_latency;
@ -58,7 +58,7 @@ OSPiHandle* func_80000628(void) {
s32 func_800006C4(struct UnkStruct800006C4_2* arg0) {
OSIoMesg msg;
OSPiHandle *handle = func_80000628();
OSPiHandle* handle = func_80000628();
msg.hdr.pri = 0;
msg.hdr.retQueue = &D_80083BD0.queue2;
@ -74,7 +74,7 @@ s32 func_800006C4(struct UnkStruct800006C4_2* arg0) {
s32 func_8000074C(struct UnkStruct800006C4_2* arg0) {
OSIoMesg msg;
OSPiHandle *handle = func_80000628();
OSPiHandle* handle = func_80000628();
msg.hdr.pri = 0;
msg.hdr.retQueue = &D_80083BD0.queue2;
@ -90,7 +90,7 @@ s32 func_8000074C(struct UnkStruct800006C4_2* arg0) {
s32 func_800007D4(struct UnkStruct800006C4_2* arg0, s32 arg1) {
OSIoMesg msg;
OSPiHandle *handle;
OSPiHandle* handle;
if (arg1 == 0) {
handle = osCartRomInit();
@ -112,7 +112,7 @@ s32 func_800007D4(struct UnkStruct800006C4_2* arg0, s32 arg1) {
s32 func_8000087C(struct UnkStruct800006C4_2* arg0) {
OSIoMesg msg;
OSPiHandle *handle;
OSPiHandle* handle;
handle = osCartRomInit();
@ -155,33 +155,33 @@ void* func_800009C8(void) {
return msg;
}
void *func_800009F8(struct UnkStruct800006C4_2* arg0) {
void* func_800009F8(struct UnkStruct800006C4_2* arg0) {
LeoReadWrite(arg0, 0, arg0->unk1C, arg0->vaddr, arg0->size, &D_80083BD0.queue2);
return func_800009C8();
}
void *func_80000A3C(struct UnkStruct800006C4_2* arg0) {
void* func_80000A3C(struct UnkStruct800006C4_2* arg0) {
LeoReadWrite(arg0, 1, arg0->unk1C, arg0->vaddr, arg0->size, &D_80083BD0.queue2);
return func_800009C8();
}
void *func_80000A80(struct UnkStruct80000A80* arg0) {
void* func_80000A80(struct UnkStruct80000A80* arg0) {
LeoReadDiskID(&arg0->cmd, arg0->addr, &D_80083BD0.queue2);
return func_800009C8();
}
void *func_80000AB0(struct UnkStruct80000A80* arg0) {
void* func_80000AB0(struct UnkStruct80000A80* arg0) {
LeoSeek(&arg0->cmd, arg0->lba, &D_80083BD0.queue2);
return func_800009C8();
}
void *func_80000AE0(struct UnkStruct80000A80* arg0) {
void* func_80000AE0(struct UnkStruct80000A80* arg0) {
LeoSpdlMotor(&arg0->cmd, arg0->mode, &D_80083BD0.queue2);
return func_800009C8();
}
void *func_80000B10(struct UnkStruct80000A80* arg0) {
void *temp_v0;
void* func_80000B10(struct UnkStruct80000A80* arg0) {
void* temp_v0;
LeoReadRTC(&arg0->cmd, &D_80083BD0.queue2);
temp_v0 = func_800009C8();
@ -191,79 +191,79 @@ void *func_80000B10(struct UnkStruct80000A80* arg0) {
return temp_v0;
}
void *func_80000B74(struct UnkStruct80000A80* arg0) {
void* func_80000B74(struct UnkStruct80000A80* arg0) {
LeoSetRTC(&arg0->cmd, arg0->addr, &D_80083BD0.queue2);
return func_800009C8();
}
void thread20_rsp(UNUSED void *arg) {
void thread20_rsp(UNUSED void* arg) {
struct UnkStruct800006C4_2* sp2C;
OSMesg var_v0;
func_800005C0();
func_8000C8F8();
while(1) {
while (1) {
osRecvMesg(&D_80083BD0.queue1, (void*)&sp2C, OS_MESG_BLOCK);
switch (sp2C->unk0) {
case 0xF0:
var_v0 = (OSMesg)INT2VOID(func_800007D4(sp2C, 0));
break;
case 0xF1:
var_v0 = (OSMesg)INT2VOID(func_800007D4(sp2C, 1));
break;
case 0xF2:
var_v0 = (OSMesg)INT2VOID(func_800006C4(sp2C));
break;
case 0xF3:
var_v0 = (OSMesg)INT2VOID(func_8000074C(sp2C));
break;
case 0xF4:
var_v0 = (OSMesg)INT2VOID(func_8000087C(sp2C));
break;
case 0xF5:
var_v0 = (OSMesg)INT2VOID(func_80000904(sp2C));
break;
case 0xF6:
var_v0 = (OSMesg)INT2VOID(func_80000974(sp2C));
break;
case 0x5:
var_v0 = (OSMesg)func_800009F8(sp2C);
break;
case 0x6:
var_v0 = (OSMesg)func_80000A3C(sp2C);
break;
case 0xC:
/*
* TODO: These castings imply the 2 struct defs are the same struct, but
* there is very tenuous aliasing going on due to s16 and u8 overlap where
* there should be word loads. What is going on here?
*/
var_v0 = (OSMesg)func_80000A80((struct UnkStruct80000A80 *)sp2C);
break;
case 0x7:
var_v0 = (OSMesg)func_80000AB0((struct UnkStruct80000A80 *)sp2C);
break;
case 0x8:
var_v0 = (OSMesg)func_80000AE0((struct UnkStruct80000A80 *)sp2C);
break;
case 0xD:
var_v0 = (OSMesg)func_80000B10((struct UnkStruct80000A80 *)sp2C);
break;
case 0xE:
var_v0 = (OSMesg)func_80000B74((struct UnkStruct80000A80 *)sp2C);
break;
case 0xF0:
var_v0 = (OSMesg)INT2VOID(func_800007D4(sp2C, 0));
break;
case 0xF1:
var_v0 = (OSMesg)INT2VOID(func_800007D4(sp2C, 1));
break;
case 0xF2:
var_v0 = (OSMesg)INT2VOID(func_800006C4(sp2C));
break;
case 0xF3:
var_v0 = (OSMesg)INT2VOID(func_8000074C(sp2C));
break;
case 0xF4:
var_v0 = (OSMesg)INT2VOID(func_8000087C(sp2C));
break;
case 0xF5:
var_v0 = (OSMesg)INT2VOID(func_80000904(sp2C));
break;
case 0xF6:
var_v0 = (OSMesg)INT2VOID(func_80000974(sp2C));
break;
case 0x5:
var_v0 = (OSMesg)func_800009F8(sp2C);
break;
case 0x6:
var_v0 = (OSMesg)func_80000A3C(sp2C);
break;
case 0xC:
/*
* TODO: These castings imply the 2 struct defs are the same struct, but
* there is very tenuous aliasing going on due to s16 and u8 overlap where
* there should be word loads. What is going on here?
*/
var_v0 = (OSMesg)func_80000A80((struct UnkStruct80000A80*)sp2C);
break;
case 0x7:
var_v0 = (OSMesg)func_80000AB0((struct UnkStruct80000A80*)sp2C);
break;
case 0x8:
var_v0 = (OSMesg)func_80000AE0((struct UnkStruct80000A80*)sp2C);
break;
case 0xD:
var_v0 = (OSMesg)func_80000B10((struct UnkStruct80000A80*)sp2C);
break;
case 0xE:
var_v0 = (OSMesg)func_80000B74((struct UnkStruct80000A80*)sp2C);
break;
}
if ((OSMesgQueue *)INT2VOID(sp2C->unk28) != NULL) {
if ((OSMesgQueue*)INT2VOID(sp2C->unk28) != NULL) {
osSendMesg(INT2VOID(sp2C->unk28), var_v0, 0);
}
func_80003004(sp2C);
Util_Free(sp2C);
}
}
void rsp_init(void) {
osCreateMesgQueue(&D_80083BD0.queue2, &D_80083BCC, 1);
osCreateMesgQueue(&D_80083BD0.queue1, &D_80083B8C, 16);
osCreatePiManager(0x96, (void *)&D_80083BD0.unk4, (OSMesg)&gRspThreadStack[0x1C], 0x20);
osCreatePiManager(0x96, (void*)&D_80083BD0.unk4, (OSMesg)&gRspThreadStack[0x1C], 0x20);
osCreateThread(&gRspThread, 20, thread20_rsp, NULL, gRspThreadStack, 90);
osStartThread(&gRspThread);
}

View File

@ -2,4 +2,4 @@
#include <macros.h>
// used for padding. Splat cant auto gen these I guess
UNUSED static u8 unk_bss[0x800A6070-0x80083CA0];
UNUSED static u8 unk_bss[0x800A6070 - 0x80083CA0];

View File

@ -1,4 +1,4 @@
#include <ultra64.h>
#include <macros.h>
UNUSED static u8 unk_bss[0x80103880-0x800A8100];
UNUSED static u8 unk_bss[0x80103880 - 0x800A8100];

View File

@ -2,4 +2,4 @@
#include <macros.h>
// used for padding. Splat cant auto gen these I guess
UNUSED static u8 unk_bss[0x800A74C0-0x800A7420];
UNUSED static u8 unk_bss[0x800A74C0 - 0x800A7420];

View File

@ -2,4 +2,4 @@
#include <macros.h>
// used for padding. Splat cant auto gen these I guess
UNUSED static u8 unk_bss[0x800A7320-0x800A60B0];
UNUSED static u8 unk_bss[0x800A7320 - 0x800A60B0];

View File

@ -1,6 +1,7 @@
#include <ultra64.h>
#include "memmap.h"
#include "memory.h"
#include "util.h"
/**
* Based on the context of this variable's usage, it appears to be intended to
@ -19,7 +20,7 @@ s32 func_80007A58(void);
/**
* Convert any valid address to its virtual (KSEG0) counterpart.
*/
uintptr_t convert_addr_to_virt_addr(uintptr_t addr) {
uintptr_t Util_ConvertAddrToVirtAddr(uintptr_t addr) {
uintptr_t retaddr = NULL; // any invalid cases are treated as NULL return.
// convert physical (in installed memory range) to virtual.
@ -43,14 +44,17 @@ uintptr_t convert_addr_to_virt_addr(uintptr_t addr) {
/**
* Copy memory from one address to the other.
*/
void HAL_Memcpy(u32* dest, u32* src, int size) {
void Util_Memcpy(u32* dest, u32* src, int size) {
while (size-- > 0) {
*(dest++) = *(src++);
}
}
// init_main_pools ?
void func_80002F58(void) {
/**
* Initialize the global memory pools and set the main pool after the
* global pool.
*/
void Util_InitMainPools(void) {
/**
* wat? mem sizes are only ever 0x400000 or 0x800000. This check makes no sense
* in normal contexts. However, since osGetMemSize checks each MB at a time, if
@ -68,17 +72,25 @@ void func_80002F58(void) {
gMainPool = mem_pool_try_init(0x10000, 0);
}
// main_malloc ?
void* func_80002FDC(s32 size) {
/**
* Allocate memory from the main pool.
*/
void* Util_Malloc(s32 size) {
return mem_pool_alloc(gMainPool, size);
}
// main_free ?
void func_80003004(void* arg0) {
mem_pool_free(gMainPool, arg0);
/**
* Free a pointer being used in the main pool.
*/
void Util_Free(void* ptr) {
mem_pool_free(gMainPool, ptr);
}
void HAL_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
/**
* Draws a profiler rectangle with given coordinates. Solely used by the next function
* which facilitates the tacked on memory profiler.
*/
void Util_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
s32 uly = 15;
s32 lry = 17;
Gfx* gfx = *dlist;
@ -97,9 +109,11 @@ void HAL_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
}
/**
* Render the memory profiler bar and print the MEM display.
* Render the memory profiler bar and print the MEM display. For some reason, this
* is not within profiler.c itself but added in this "util" file. This seems to be
* tacked onto the profiler by HAL instead of EAD.
*/
void profiler_draw_mem_display(Gfx** dlist) {
void Util_DrawMemProfiler(Gfx** dlist) {
struct MainPool* pool = main_pool_get_pool(); // get pool pointer
/**
* Get the available memory offset by gExpansionRAMStart variable. This variable is weird; it
@ -122,10 +136,10 @@ void profiler_draw_mem_display(Gfx** dlist) {
s32 endX = ((u32)(K0_TO_PHYS(pool->end) - gExpansionRAMStart) >> 15) + baseX;
// draw the rects.
HAL_DrawRect(dlist, baseX, startX, GPACK_RGBA5551(248, 120, 40, 1)); // orange
HAL_DrawRect(dlist, startX, headLX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
HAL_DrawRect(dlist, headLX, headRX, GPACK_RGBA5551(40, 80, 248, 1)); // blue
HAL_DrawRect(dlist, headRX, endX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
Util_DrawRect(dlist, baseX, startX, GPACK_RGBA5551(248, 120, 40, 1)); // orange
Util_DrawRect(dlist, startX, headLX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
Util_DrawRect(dlist, headLX, headRX, GPACK_RGBA5551(40, 80, 248, 1)); // blue
Util_DrawRect(dlist, headRX, endX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
// how many bytes and kilobytes are available?
HAL_Printf(baseX, 20, "MEM: +%XH (+%dK)", available, available / 1024);
@ -139,10 +153,10 @@ void profiler_draw_mem_display(Gfx** dlist) {
// draw the rects. if we are negative in the memory, we are using red for the backwards
// allocations to indicate too much memory is being used.
HAL_DrawRect(dlist, baseX, startX, GPACK_RGBA5551(248, 120, 40, 1)); // orange
HAL_DrawRect(dlist, startX, headRX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
HAL_DrawRect(dlist, headRX, headLX, GPACK_RGBA5551(248, 40, 40, 1)); // red
HAL_DrawRect(dlist, headLX, endX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
Util_DrawRect(dlist, baseX, startX, GPACK_RGBA5551(248, 120, 40, 1)); // orange
Util_DrawRect(dlist, startX, headRX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
Util_DrawRect(dlist, headRX, headLX, GPACK_RGBA5551(248, 40, 40, 1)); // red
Util_DrawRect(dlist, headLX, endX, GPACK_RGBA5551(248, 248, 40, 1)); // yellow
// how many bytes and kilobytes are available?
HAL_Printf(baseX, 20, "MEM: -%XH (-%dK)", -available, -available / 1024);
@ -152,7 +166,7 @@ void profiler_draw_mem_display(Gfx** dlist) {
/**
* Clear memory address area.
*/
void HAL_Memclear(u64* dest, u32 size) {
void Util_Memclear(u64* dest, u32 size) {
while (size-- > 0) {
*(dest++) = -1;
}
@ -164,8 +178,7 @@ void HAL_Memclear(u64* dest, u32 size) {
* the code for such a test is not present in this ROM, so we can only guess this function's
* intended usage.
*/
// check_stub_mem_area ?
s32 func_80003348(u64* ptr) {
s32 Util_CheckStubMemArea(u64* ptr) {
s32 ret = 0;
while (*(ptr++) == 0x8040000080400000) {

16
src/util.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _UTIL_H_
#define _UTIL_H_
extern u32 gExpansionRAMStart;
uintptr_t Util_ConvertAddrToVirtAddr(uintptr_t addr);
void Util_Memcpy(u32* dest, u32* src, int size);
void Util_InitMainPools(void);
void* Util_Malloc(s32 size);
void Util_Free(void* ptr);
void Util_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color);
void Util_DrawMemProfiler(Gfx** dlist);
void Util_Memclear(u64* dest, u32 size);
s32 Util_CheckStubMemArea(u64* ptr); // unused
#endif // _UTIL_H_

View File

@ -208,7 +208,7 @@ __LeoBootGame2 = 0x8000B9EC;
__LeoBootGame3 = 0x8000BD10;
leomain = 0x80051EC0;
lldiv = 0x80064B10;
main_func = 0x80000530;
Main = 0x80000530;
memcpy = 0x8005E250;
osAiGetLength = 0x80063700;
osAiSetFrequency = 0x80062270;
@ -564,10 +564,10 @@ print_profiler_metrics = 0x8000A0FC;
clear_profiler_data = 0x8000A21C;
draw_profiler_bar_cpu_keep_max = 0x80009630;
Yay0_Decompress = 0x8000B7F0;
convert_addr_to_virt_addr = 0x80002E80;
HAL_Memcpy = 0x80002F28;
HAL_DrawRect = 0x8000302C;
HAL_Memclear = 0x8000330C;
Util_ConvertAddrToVirtAddr = 0x80002E80;
Util_Memcpy = 0x80002F28;
Util_DrawRect = 0x8000302C;
Util_Memclear = 0x8000330C;
UnkHeapThing = 0x80104BC0;
gMemPool = 0x800A6070;
main_pool_alloc = 0x80002380;
@ -589,4 +589,7 @@ gMainPool = 0x800A60B0;
mem_pool_try_init = 0x80002A40;
mem_pool_init = 0x80002A88;
mem_pool_alloc = 0x80002AF8;
mem_pool_free = 0x80002BD0;
mem_pool_free = 0x80002BD0;
Util_DrawMemProfiler = 0x8000310C;
Util_Malloc = 0x80002FDC;
Util_Free = 0x80003004;