1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-02-14 19:14:50 +00:00

[iQue] Match remaining libultra/os files (#2414)

* Match remaining libultra/os files

* Align box id macros

* Fix bss, format

* Fix BSS

* Clarify some comments

* More bug comment

* Comment

* Fix BSS
This commit is contained in:
Tharo 2025-01-10 23:54:02 +00:00 committed by GitHub
parent 1549f34e8e
commit b19b06a531
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 197 additions and 61 deletions

View file

@ -214,7 +214,7 @@ else ifeq ($(PLATFORM),GC)
LIBULTRA_VERSION := L
LIBULTRA_PATCH := 0
else ifeq ($(PLATFORM),IQUE)
CPP_DEFINES += -DPLATFORM_N64=0 -DPLATFORM_GC=0 -DPLATFORM_IQUE=1 -DBBPLAYER
CPP_DEFINES += -DPLATFORM_N64=0 -DPLATFORM_GC=0 -DPLATFORM_IQUE=1
LIBULTRA_VERSION := L
LIBULTRA_PATCH := 0
else
@ -702,8 +702,12 @@ else
$(BUILD_DIR)/src/libultra/gu/%.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/io/%.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/libc/%.o: OPTFLAGS := -O2
ifeq ($(PLATFORM),IQUE)
$(BUILD_DIR)/src/libultra/os/%.o: OPTFLAGS := -O0
else
$(BUILD_DIR)/src/libultra/os/%.o: OPTFLAGS := -O1
endif
endif
$(BUILD_DIR)/src/libleo/%.o: CC := $(CC_OLD)
$(BUILD_DIR)/src/libleo/%.o: OPTFLAGS := -O2

View file

@ -190,4 +190,76 @@
*/
#define PI_NAND_CTRL_REG (PI_BASE_REG + 0x48)
/**
* [31:16] Box ID
* [31:30] Hardware Revision? (osInitialize checks this and sets __osBbIsBb to 2 if != 0)
* [29:27] ?? (not seen)
* [26:25] ?? (system clock speed identifier?)
* [24:22] ?? (bootrom, checked against MI_10_REG and copied there if mismatch)
* [21:16] ?? (not seen)
* [ 7: 4] GPIO direction control
* [7] RTC Data output enable
* [6] RTC Clock output enable
* [5] Error LED output enable
* [4] Power Control output enable
* [ 3: 0] GPIO in/out value
* [3] RTC Data output value (0=low, 1=high)
* [2] RTC Clock output value (0=low, 1=high)
* [1] Error LED (0=on, 1=off)
* [0] Power Control (0=off, 1=on)
*/
#define PI_GPIO_REG (PI_BASE_REG + 0x60)
/* Box ID */
#define PI_GPIO_GET_BOXID(reg) ((reg) >> 16)
#define PI_GPIO_IS_HW_V2(reg) ((reg) & (3 << 30))
/* GPIO: Input/Output enables */
#define PI_GPIO_I_PWR ((0 << 0) << 4)
#define PI_GPIO_O_PWR ((1 << 0) << 4)
#define PI_GPIO_I_LED ((0 << 1) << 4)
#define PI_GPIO_O_LED ((1 << 1) << 4)
#define PI_GPIO_I_RTC_CLK ((0 << 2) << 4)
#define PI_GPIO_O_RTC_CLK ((1 << 2) << 4)
#define PI_GPIO_I_RTC_DAT ((0 << 3) << 4)
#define PI_GPIO_O_RTC_DAT ((1 << 3) << 4)
/* GPIO: Output controls */
/* Power */
#define PI_GPIO_PWR_OFF (0 << 0)
#define PI_GPIO_PWR_ON (1 << 0)
/* LED */
#define PI_GPIO_LED_ON (0 << 1)
#define PI_GPIO_LED_OFF (1 << 1)
/* RTC */
#define PI_GPIO_RTC_CLK_LO (0 << 2)
#define PI_GPIO_RTC_CLK_HI (1 << 2)
#define PI_GPIO_RTC_DAT_LO (0 << 3)
#define PI_GPIO_RTC_DAT_HI (1 << 3)
/* GPIO: Input getters */
#define PI_GPIO_GET_PWR(reg) (((reg) >> 0) & 1)
#define PI_GPIO_GET_LED(reg) (((reg) >> 1) & 1)
#define PI_GPIO_GET_RTC_CLK(reg) (((reg) >> 2) & 1)
#define PI_GPIO_GET_RTC_DAT(reg) (((reg) >> 3) & 1)
/**
* [31] ?
*/
#define PI_64_REG (PI_BASE_REG + 0x64)
/******************************************************************************
* Additional Serial Interface (SI) Registers
*/
/**
* ?
*/
#define SI_0C_REG (SI_BASE_REG + 0x0C)
/**
* ?
*/
#define SI_1C_REG (SI_BASE_REG + 0x1C)
#endif

View file

@ -9,15 +9,23 @@ extern Mtx D_01000000;
extern void* osRomBase;
extern s32 osTvType;
extern u32 osRomType;
extern u32 osVersion;
extern s32 osResetType;
extern s32 osCicId;
extern u32 osMemSize;
extern u8 osAppNMIBuffer[0x40];
extern u32 __osBbIsBb;
extern u32 __osBbHackFlags;
extern u32 __osBbPakAddress[4];
extern u32 __osBbEepromSize;
extern u32 __osBbPakSize;
extern u32 __osBbFlashSize;
extern u32 __osBbEepromAddress;
extern u32 __osBbPakAddress[4];
extern u32 __osBbFlashAddress;
extern u32 __osBbSramSize;
extern u32 __osBbSramAddress;
extern u32 __osBbHackFlags;
extern s8 D_80009430;
extern vu8 gViConfigBlack;

View file

@ -28,7 +28,7 @@
#endif
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.2:78 pal-1.0:76 pal-1.1:76"
"ntsc-1.2:70 pal-1.0:68 pal-1.1:68"
StackEntry sDmaMgrStackInfo;
OSMesgQueue sDmaMgrMsgQueue;

View file

@ -40,8 +40,8 @@
* DPad-Up may be pressed to enable sending fault pages over osSyncPrintf as well as displaying them on-screen.
* DPad-Down disables sending fault pages over osSyncPrintf.
*/
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-eu-mq-dbg:160 gc-jp:176 gc-jp-ce:176 gc-jp-mq:176 gc-us:176" \
"gc-us-mq:176"
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-eu-mq-dbg:160 gc-jp:160 gc-jp-ce:160 gc-jp-mq:160 gc-us:160" \
"gc-us-mq:160"
#include "global.h"
#include "alloca.h"

View file

@ -23,8 +23,8 @@ extern struct IrqMgr gIrqMgr;
#include "n64dd.h"
#endif
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-jp:160 gc-jp-ce:160 gc-jp-mq:160 gc-us:160 gc-us-mq:160" \
"ntsc-1.0:138 ntsc-1.1:138 ntsc-1.2:138 pal-1.0:136 pal-1.1:136"
#pragma increment_block_number "gc-eu:144 gc-eu-mq:144 gc-jp:144 gc-jp-ce:144 gc-jp-mq:144 gc-us:144 gc-us-mq:144" \
"ntsc-1.0:130 ntsc-1.1:130 ntsc-1.2:130 pal-1.0:128 pal-1.1:128"
extern u8 _buffersSegmentEnd[];

View file

@ -2,7 +2,7 @@
#include "terminal.h"
#include "line_numbers.h"
#pragma increment_block_number "ntsc-1.0:120 ntsc-1.1:120 ntsc-1.2:120"
#pragma increment_block_number "ntsc-1.0:112 ntsc-1.1:112 ntsc-1.2:112"
u16 DynaSSNodeList_GetNextNodeIdx(DynaSSNodeList* nodeList);
void BgCheck_GetStaticLookupIndicesFromPos(CollisionContext* colCtx, Vec3f* pos, Vec3i* sector);

View file

@ -4,7 +4,7 @@
#include "terminal.h"
#include "overlays/actors/ovl_En_Horse/z_en_horse.h"
#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.0:128 ntsc-1.1:128 ntsc-1.2:128 pal-1.0:128 pal-1.1:128"
s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags);
@ -3639,7 +3639,7 @@ s32 Camera_KeepOn3(Camera* camera) {
}
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.0:141 ntsc-1.1:141 ntsc-1.2:141 pal-1.0:139 pal-1.1:139"
"ntsc-1.0:133 ntsc-1.1:133 ntsc-1.2:133 pal-1.0:131 pal-1.1:131"
s32 Camera_KeepOn4(Camera* camera) {
static Vec3f D_8015BD50;

View file

@ -3,7 +3,7 @@
#include "versions.h"
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.0:192 ntsc-1.1:192 ntsc-1.2:192 pal-1.0:192 pal-1.1:192"
"ntsc-1.0:176 ntsc-1.1:176 ntsc-1.2:176 pal-1.0:160 pal-1.1:160"
ALIGNED(16) SaveContext gSaveContext;
u32 D_8015FA88;

View file

@ -1,4 +1,4 @@
#pragma increment_block_number "gc-eu:224 gc-eu-mq:224 gc-jp:224 gc-jp-ce:224 gc-jp-mq:224 gc-us:224 gc-us-mq:224" \
#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:224 gc-jp-ce:224 gc-jp-mq:224 gc-us:224 gc-us-mq:224" \
"ntsc-1.0:224 ntsc-1.1:224 ntsc-1.2:224 pal-1.0:224 pal-1.1:224"
#include "global.h"

View file

@ -1,5 +1,5 @@
#pragma increment_block_number "gc-eu:228 gc-eu-mq:228 gc-jp:212 gc-jp-ce:212 gc-jp-mq:212 gc-us:212 gc-us-mq:212" \
"ntsc-1.0:224 ntsc-1.1:224 ntsc-1.2:224 pal-1.0:236 pal-1.1:236"
#pragma increment_block_number "gc-eu:220 gc-eu-mq:220 gc-jp:212 gc-jp-ce:212 gc-jp-mq:212 gc-us:212 gc-us-mq:212" \
"ntsc-1.0:224 ntsc-1.1:224 ntsc-1.2:224 pal-1.0:228 pal-1.1:228"
#include "global.h"
#include "ultra64.h"

View file

@ -8,7 +8,7 @@
#endif
#pragma increment_block_number "gc-eu:0 gc-eu-mq:0 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.0:96 ntsc-1.1:96 ntsc-1.2:96 pal-1.0:128 pal-1.1:128"
"ntsc-1.0:80 ntsc-1.1:80 ntsc-1.2:80 pal-1.0:128 pal-1.1:128"
#if !PLATFORM_GC
#define OCARINA_BUTTON_A_PRIM_1_R 80

View file

@ -3,6 +3,7 @@
#define STEP 0x100000
u32 osGetMemSize(void) {
#ifndef BBPLAYER
vu32* ptr;
u32 size = 0x400000;
u32 data0;
@ -28,4 +29,7 @@ u32 osGetMemSize(void) {
}
return size;
#else
return osMemSize;
#endif
}

View file

@ -11,5 +11,5 @@ OSTime osGetTime(void) {
t = __osCurrentTime;
__osRestoreInt(prevInt);
return base + t;
return t + base;
}

View file

@ -1,4 +1,5 @@
#include "global.h"
#include "ultra64/bcp.h"
typedef struct __osExceptionVector {
u32 inst1; // lui $k0, %hi(__osException)
@ -59,13 +60,50 @@ void OSINITIALIZE_FUNC(void) {
__osSetWatchLo(0x04900000);
#endif
while (__osSiRawReadIo((void*)(PIF_RAM_END - 3), &pifdata)) {
;
#ifdef BBPLAYER
{
u32 x, y;
// Check for iQue Player hardware by enabling and disabling FLASH and IDE interrupts and checking if the
// register gives the correct response.
IO_WRITE(MI_EX_INTR_MASK_REG, MI_EX_INTR_MASK_SET_FLASH | MI_EX_INTR_MASK_SET_IDE);
x = IO_READ(MI_EX_INTR_MASK_REG);
IO_WRITE(MI_EX_INTR_MASK_REG, MI_EX_INTR_MASK_CLR_FLASH | MI_EX_INTR_MASK_CLR_IDE);
y = IO_READ(MI_EX_INTR_MASK_REG);
__osBbIsBb =
((x & (MI_EX_INTR_MASK_FLASH | MI_EX_INTR_MASK_IDE)) == (MI_EX_INTR_MASK_FLASH | MI_EX_INTR_MASK_IDE)) &&
((y & (MI_EX_INTR_MASK_FLASH | MI_EX_INTR_MASK_IDE)) == 0);
}
while (__osSiRawWriteIo((void*)(PIF_RAM_END - 3), pifdata | 8)) {
;
//! @bug Most games do not have permission to use GPIO, so they often cannot correctly tell if they are running on
//! HW V1 or V2.
if (__osBbIsBb && PI_GPIO_IS_HW_V2(IO_READ(PI_GPIO_REG))) {
__osBbIsBb = 2;
}
if (__osBbIsBb) {
// Set IPL boot parameters
osTvType = OS_TV_NTSC;
osRomType = 0;
osResetType = 0;
osVersion = 1;
osMemSize = 0x400000;
}
if (!__osBbIsBb) {
// The PIF doesn't exist on iQue, no need to enable NMI from PIF
#endif
while (__osSiRawReadIo((void*)(PIF_RAM_END - 3), &pifdata)) {
;
}
while (__osSiRawWriteIo((void*)(PIF_RAM_END - 3), pifdata | 8)) {
;
}
#ifdef BBPLAYER
}
#endif
*(__osExceptionVector*)UT_VEC = __osExceptionPreamble; // TLB miss
*(__osExceptionVector*)XUT_VEC = __osExceptionPreamble; // XTLB miss
*(__osExceptionVector*)ECC_VEC = __osExceptionPreamble; // cache errors
@ -102,6 +140,31 @@ void OSINITIALIZE_FUNC(void) {
}
#endif
#ifdef BBPLAYER
if (!__osBbIsBb) {
// In a real iQue Player environment (that is, real hardware + app launched from the system menu)
// these are set on app launch by the system menu based on the contents of the game's associated
// ticket. Set some dummy values if not running on iQue Player hardware.
__osBbEepromSize = 0x200;
__osBbPakSize = 0x8000;
__osBbFlashSize = 0x20000;
__osBbEepromAddress = 0x80400000 - 0x200;
__osBbPakAddress[0] = 0x80400000 - 0x8200;
__osBbPakAddress[1] = 0;
__osBbPakAddress[2] = 0;
__osBbPakAddress[3] = 0;
__osBbFlashAddress = 0x80400000 - 0x20000;
__osBbSramSize = __osBbFlashSize;
__osBbSramAddress = __osBbFlashAddress;
}
if (__osBbIsBb) {
IO_WRITE(PI_64_REG, IO_READ(PI_64_REG) & ~0x80000000);
IO_WRITE(MI_EX_INTR_MASK_REG, MI_EX_INTR_MASK_SET_IDE);
IO_WRITE(SI_0C_REG, 0);
IO_WRITE(SI_1C_REG, (IO_READ(SI_1C_REG) & ~0x7F000000) | 0x2F400000);
}
#endif
IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON);
IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1);
IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1);

View file

@ -7,9 +7,10 @@ s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag) {
if (flag == OS_MESG_NOBLOCK) {
__osRestoreInt(prevInt);
return -1;
} else {
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->mtqueue);
}
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->mtqueue);
}
if (msg != NULL) {

View file

@ -12,20 +12,14 @@ s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* m
timer->next = NULL;
timer->prev = NULL;
timer->interval = interval;
if (countdown != 0) {
timer->value = countdown;
} else {
timer->value = interval;
}
timer->value = (countdown != 0) ? countdown : interval;
timer->mq = mq;
timer->msg = msg;
#if LIBULTRA_VERSION >= LIBULTRA_VERSION_K
prevInt = __osDisableInt();
if (__osTimerList->next != __osTimerList) {
if (1) {}
if (__osTimerList->next == __osTimerList) {
} else {
next = __osTimerList->next;
count = osGetCount();
value = count - __osTimerCounter;

View file

@ -2,13 +2,7 @@
void osStopThread(OSThread* thread) {
register u32 prevInt = __osDisableInt();
register u32 state;
if (thread == NULL) {
state = OS_STATE_RUNNING;
} else {
state = thread->state;
}
register u16 state = (thread == NULL) ? OS_STATE_RUNNING : thread->state;
switch (state) {
case OS_STATE_RUNNING:

View file

@ -6,16 +6,16 @@ OSThread* __osActiveQueue = (OSThread*)&__osThreadTail;
OSThread* __osRunningThread = NULL;
OSThread* __osFaultedThread = NULL;
void __osDequeueThread(OSThread** queue, OSThread* thread) {
register OSThread** a2 = queue;
register OSThread* a3 = *a2;
void __osDequeueThread(register OSThread** queue, register OSThread* thread) {
register OSThread* pred = (OSThread*)queue;
register OSThread* succ = pred->next;
while (a3 != NULL) {
if (a3 == thread) {
*a2 = thread->next;
while (succ != NULL) {
if (succ == thread) {
pred->next = thread->next;
return;
}
a2 = &a3->next;
a3 = *a2;
pred = succ;
succ = pred->next;
}
}

View file

@ -11,10 +11,8 @@ void __osTimerServicesInit(void) {
__osCurrentTime = 0;
__osBaseCounter = 0;
__osViIntrCount = 0;
__osTimerList->prev = __osTimerList;
__osTimerList->next = __osTimerList->prev;
__osTimerList->value = 0;
__osTimerList->interval = __osTimerList->value;
__osTimerList->next = __osTimerList->prev = __osTimerList;
__osTimerList->interval = __osTimerList->value = 0;
__osTimerList->mq = NULL;
__osTimerList->msg = NULL;
}
@ -28,7 +26,7 @@ void __osTimerInterrupt(void) {
return;
}
while (true) {
for (;;) {
timer = __osTimerList->next;
if (timer == __osTimerList) {
__osSetCompare(0);
@ -72,7 +70,7 @@ void __osSetTimerIntr(OSTime time) {
prevInt = __osDisableInt();
__osTimerCounter = osGetCount();
newTime = time + __osTimerCounter;
newTime = __osTimerCounter + time;
__osSetCompare((u32)newTime);
__osRestoreInt(prevInt);
}

View file

@ -3,11 +3,9 @@
u32 osVirtualToPhysical(void* vaddr) {
if (IS_KSEG0(vaddr)) {
return K0_TO_PHYS(vaddr);
}
if (IS_KSEG1(vaddr)) {
} else if (IS_KSEG1(vaddr)) {
return K1_TO_PHYS(vaddr);
} else {
return __osProbeTLB(vaddr);
}
return __osProbeTLB(vaddr);
}

View file

@ -338,14 +338,14 @@ static s32 D_80858AA0;
// TODO: There's probably a way to match BSS ordering with less padding by spreading the variables out and moving
// data around. It would be easier if we had more options for controlling BSS ordering in debug.
#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \
#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.0:192 ntsc-1.1:192 ntsc-1.2:192 pal-1.0:192 pal-1.1:192"
static s32 sSavedCurrentMask;
static Vec3f sInteractWallCheckResult;
static Input* sControlInput;
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-jp:160 gc-jp-ce:160 gc-jp-mq:160 gc-us:160 gc-us-mq:160" \
#pragma increment_block_number "gc-eu:160 gc-eu-mq:160 gc-jp:192 gc-jp-ce:192 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \
"ntsc-1.0:128 ntsc-1.1:128 ntsc-1.2:128 pal-1.0:128 pal-1.1:128"
// .data

View file

@ -16,7 +16,7 @@
#include "terminal.h"
#include "versions.h"
#pragma increment_block_number "ntsc-1.0:128 ntsc-1.1:128 ntsc-1.2:128 pal-1.0:128 pal-1.1:128"
#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 ntsc-1.0:128 ntsc-1.1:128 ntsc-1.2:128 pal-1.0:128 pal-1.1:128"
#if !PLATFORM_GC
#define KALEIDO_PROMPT_CURSOR_R 100