summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2026-03-26 07:59:39 -0300
committerGitHub <noreply@github.com>2026-03-26 07:59:39 -0300
commita9da608e187f0f6874ee15491347751751fcedeb (patch)
tree3c6a69aad3623d66afd2ab6e46b2a693a2529b2d
parent02eafced87237be63b32ddc187ea85faf92afe00 (diff)
[n64-jp-1.1] CIC6105.c matched (#1843)
* match CIC6105.c * Renames and fixes * Fix bss * format * Review * Version check inequalities
-rw-r--r--Makefile2
-rw-r--r--include/CIC6105.h6
-rw-r--r--include/PR/mbi.h1
-rw-r--r--include/PR/ucode.h3
-rw-r--r--include/regs.h1
-rw-r--r--src/boot/CIC6105.c86
-rw-r--r--src/code/audio_thread_manager.c4
-rw-r--r--src/code/graph.c2
-rw-r--r--src/code/osFlash.c2
-rw-r--r--src/code/sys_math3d.c2
-rw-r--r--src/code/z_jpeg.c14
-rw-r--r--tools/disasm/n64-jp-1.1/functions.txt4
-rw-r--r--tools/disasm/n64-jp-1.1/variables.txt7
-rw-r--r--tools/disasm/n64-us/variables.txt2
14 files changed, 117 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 308e83928..1ec2277c6 100644
--- a/Makefile
+++ b/Makefile
@@ -467,7 +467,7 @@ $(BUILD_DIR)/src/code/jpegdecoder.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/code/jpegutils.o: CC := $(CC_OLD)
$(BUILD_DIR)/src/code/jpegutils.o: OPTFLAGS := -O2
-$(BUILD_DIR)/src/code/osFlash.o: CC := $(CC_OLD)
+$(BUILD_DIR)/src/code/osFlash.o: CC := ./tools/buildtools/preprocess.sh -v $(VERSION) -i $(ICONV) -- $(CC_OLD)
$(BUILD_DIR)/src/code/osFlash.o: OPTFLAGS := -g
$(BUILD_DIR)/src/code/osFlash.o: MIPS_VERSION := -mips1
diff --git a/include/CIC6105.h b/include/CIC6105.h
index 09a363a4d..60c55cbc7 100644
--- a/include/CIC6105.h
+++ b/include/CIC6105.h
@@ -3,6 +3,8 @@
#include "ultra64.h"
+#include "versions.h"
+
// IPL3 puts values in those addresses as part of the anti-piracy checks
#define CIC_ADDRESS_1 0x002FB1F4
#define CIC_ADDRESS_2 0x002FE1C0
@@ -15,6 +17,10 @@ void CIC6105_AddRomInfoFaultPage(void);
void CIC6105_Destroy(void);
void CIC6105_Init(void);
+#if MM_VERSION <= N64_JP_1_1
+void CIC6105_ScheduleCICTask(void);
+#endif
+
extern s32 gCICAddr1Val;
extern s32 gCICAddr2Val;
diff --git a/include/PR/mbi.h b/include/PR/mbi.h
index acfe89084..011107f2a 100644
--- a/include/PR/mbi.h
+++ b/include/PR/mbi.h
@@ -80,6 +80,7 @@
#define M_AUDTASK 2
#define M_VIDTASK 3
#define M_NJPEGTASK 4
+#define M_CICTASK 4
#define M_HVQTASK 6
#define M_HVQMTASK 7
diff --git a/include/PR/ucode.h b/include/PR/ucode.h
index 848983ebe..bb0c1d1b4 100644
--- a/include/PR/ucode.h
+++ b/include/PR/ucode.h
@@ -13,6 +13,9 @@
extern u64 rspbootTextStart[];
extern u64 rspbootTextEnd[];
+extern u64 cic6105TextStart[];
+extern u64 cic6105TextEnd[];
+
extern u64 aspMainTextStart[];
extern u64 aspMainTextEnd[];
extern u64 aspMainDataStart[];
diff --git a/include/regs.h b/include/regs.h
index 7bd88d784..d45064640 100644
--- a/include/regs.h
+++ b/include/regs.h
@@ -68,6 +68,7 @@ extern RegEditor* gRegEditor;
#define R_RUN_SPEED_LIMIT REG(45)
#define R_ENABLE_ARENA_DBG SREG(0) // Same as OoT
+#define R_AUDIOMGR_DEBUG_LEVEL SREG(20)
#define R_ROOM_IMAGE_NODRAW_FLAGS SREG(25)
#define R_UPDATE_RATE SREG(30)
#define R_VI_MODE_EDIT_STATE SREG(48)
diff --git a/src/boot/CIC6105.c b/src/boot/CIC6105.c
index 73ce74dd5..abafe999f 100644
--- a/src/boot/CIC6105.c
+++ b/src/boot/CIC6105.c
@@ -2,23 +2,56 @@
#include "build.h"
#include "fault.h"
+#include "macros.h"
+#include "regs.h"
+#include "scheduler.h"
-#pragma increment_block_number "n64-us:200"
+#pragma increment_block_number "n64-us:188"
s32 gCICAddr1Val;
s32 gCICAddr2Val;
FaultClient sRomInfoFaultClient;
+#if MM_VERSION < N64_US
+s32 gCICValue1;
+s32 gCICValue2;
+
+s32 CIC6105_ILoveYou(void);
+#endif
void CIC6105_Noop1(void) {
+#if MM_VERSION < N64_US
+ R_AUDIOMGR_DEBUG_LEVEL = 1;
+#endif
}
void CIC6105_Noop2(void) {
+#if MM_VERSION < N64_US
+ R_AUDIOMGR_DEBUG_LEVEL = 0;
+#endif
}
void CIC6105_PrintRomInfo(void) {
+#if MM_VERSION >= N64_US
FaultDrawer_DrawText(80, 200, "SP_STATUS %08x", IO_READ(SP_STATUS_REG));
FaultDrawer_DrawText(40, 184, "ROM_F [Creator:%s]", gBuildCreator);
FaultDrawer_DrawText(56, 192, "[Date:%s]", gBuildDate);
+#else
+ u32 status = IO_READ(SP_STATUS_REG);
+
+ FaultDrawer_SetCursor(48, 200);
+ if (status & SP_STATUS_SIG7) {
+ FaultDrawer_Printf("OCARINA %08x %08x", gCICValue1, gCICValue2);
+ } else {
+ FaultDrawer_Printf("LEGEND %08x %08x", gCICValue1, gCICValue2);
+ }
+ FaultDrawer_SetCursor(40, 184);
+ FaultDrawer_Printf("ROM_F");
+ FaultDrawer_Printf(" [Creator:%s]", gBuildCreator);
+ FaultDrawer_SetCursor(56, 192);
+ FaultDrawer_Printf("[Date:%s]", gBuildDate);
+ FaultDrawer_SetCursor(96, 32);
+ FaultDrawer_Printf("I LOVE YOU %08x", CIC6105_ILoveYou());
+#endif
}
void CIC6105_AddRomInfoFaultPage(void) {
@@ -29,6 +62,57 @@ void CIC6105_Destroy(void) {
Fault_RemoveClient(&sRomInfoFaultClient);
}
+#if MM_VERSION < N64_US
+void CIC6105_ScheduleCICTask(void) {
+ // TODO: do something with the hardcoded sizes
+ static OSTask D_80097AA0_unknown = {
+ M_CICTASK, // type
+ 0, // flags
+ rspbootTextStart, // ucode_boot
+ 0x000003E8, // ucode_boot_size
+ cic6105TextStart, // ucode
+ 0x00000020, // ucode_size
+ (u64*)gBuildCreator, // ucode_data
+ 0x00000008, // ucode_data_size
+ NULL, // dram_stack
+ 0x00000000, // dram_stack_size
+ NULL, // output_buff
+ NULL, // output_buff_size
+ NULL, // data_ptr
+ 0x00000000, // data_size
+ NULL, // yield_data_ptr
+ 0x00000000, // yield_data_size
+ };
+
+ OSScTask task;
+ OSMesgQueue queue;
+ OSMesg msg[1];
+
+ osCreateMesgQueue(&queue, msg, ARRAY_COUNT(msg));
+
+ task.next = NULL;
+ task.flags = OS_SC_NEEDS_RSP;
+ task.msgQ = &queue;
+ task.msg = (OSMesg)0;
+ task.framebuffer = NULL;
+ task.list = D_80097AA0_unknown;
+ osSendMesg(&gScheduler.cmdQueue, &task, OS_MESG_BLOCK);
+
+ Sched_SendNotifyMsg(&gScheduler);
+ osRecvMesg(&queue, NULL, OS_MESG_BLOCK);
+
+ gCICValue1 = IO_READ(SP_DMEM_START + 0xFF4);
+ gCICValue2 = IO_READ(SP_DMEM_START + 0xFFC);
+ CIC6105_ILoveYou();
+
+ (void)"flag:%08x data:%08x\n";
+}
+
+s32 CIC6105_ILoveYou(void) {
+ return 0;
+}
+#endif
+
void CIC6105_Init(void) {
gCICAddr1Val = IO_READ(CIC_ADDRESS_1);
gCICAddr2Val = IO_READ(CIC_ADDRESS_2);
diff --git a/src/code/audio_thread_manager.c b/src/code/audio_thread_manager.c
index d6661b700..25aa6c11f 100644
--- a/src/code/audio_thread_manager.c
+++ b/src/code/audio_thread_manager.c
@@ -16,7 +16,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
OSTimer timer;
s32 msg;
- if (SREG(20) > 0) {
+ if (R_AUDIOMGR_DEBUG_LEVEL > 0) {
audioMgr->rspTask = NULL;
}
@@ -37,7 +37,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
Sched_SendNotifyMsg(audioMgr->sched);
}
- if (SREG(20) >= 2) {
+ if (R_AUDIOMGR_DEBUG_LEVEL >= 2) {
rspTask = NULL;
} else {
rspTask = AudioThread_Update();
diff --git a/src/code/graph.c b/src/code/graph.c
index f823f995a..d25ec751f 100644
--- a/src/code/graph.c
+++ b/src/code/graph.c
@@ -236,7 +236,7 @@ retry:
void Graph_UpdateGame(GameState* gameState) {
GameState_GetInput(gameState);
GameState_IncrementFrameCount(gameState);
- if (SREG(20) < 3) {
+ if (R_AUDIOMGR_DEBUG_LEVEL < 3) {
Audio_Update();
}
}
diff --git a/src/code/osFlash.c b/src/code/osFlash.c
index 17162c53c..bdc59e8f2 100644
--- a/src/code/osFlash.c
+++ b/src/code/osFlash.c
@@ -3,6 +3,8 @@
#include "alignment.h"
#include "macros.h"
+#pragma increment_block_number "n64-us:188"
+
u32 __osFlashID[4] ALIGNED(8);
OSIoMesg __osFlashMsg ALIGNED(8);
OSMesgQueue __osFlashMessageQ ALIGNED(8);
diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c
index 039f58829..a0fb5fbd6 100644
--- a/src/code/sys_math3d.c
+++ b/src/code/sys_math3d.c
@@ -6,7 +6,7 @@
#include "macros.h"
-#pragma increment_block_number "n64-us:124"
+#pragma increment_block_number "n64-us:122"
// The bss index at this point should be 184
diff --git a/src/code/z_jpeg.c b/src/code/z_jpeg.c
index 377080e7d..91a9900af 100644
--- a/src/code/z_jpeg.c
+++ b/src/code/z_jpeg.c
@@ -25,7 +25,7 @@ extern u64 njpgdspMainDataStart[];
* Configures and schedules a JPEG decoder task and waits for it to finish.
*/
void Jpeg_ScheduleDecoderTask(JpegContext* jpegCtx) {
- static OSTask_t sJpegTask = {
+ static OSTask sJpegTask = {
M_NJPEGTASK, // type
0, // flags
NULL, // ucode_boot
@@ -54,18 +54,18 @@ void Jpeg_ScheduleDecoderTask(JpegContext* jpegCtx) {
workBuf->taskData.qTableUPtr = &workBuf->qTableU;
workBuf->taskData.qTableVPtr = &workBuf->qTableV;
- sJpegTask.flags = 0;
- sJpegTask.ucode_boot = SysUcode_GetUCodeBoot();
- sJpegTask.ucode_boot_size = SysUcode_GetUCodeBootSize();
- sJpegTask.yield_data_ptr = (u64*)&workBuf->yieldData;
- sJpegTask.data_ptr = (u64*)&workBuf->taskData;
+ sJpegTask.t.flags = 0;
+ sJpegTask.t.ucode_boot = SysUcode_GetUCodeBoot();
+ sJpegTask.t.ucode_boot_size = SysUcode_GetUCodeBootSize();
+ sJpegTask.t.yield_data_ptr = (u64*)&workBuf->yieldData;
+ sJpegTask.t.data_ptr = (u64*)&workBuf->taskData;
jpegCtx->scTask.next = NULL;
jpegCtx->scTask.flags = OS_SC_NEEDS_RSP;
jpegCtx->scTask.msgQ = &jpegCtx->mq;
jpegCtx->scTask.msg = NULL;
jpegCtx->scTask.framebuffer = NULL;
- jpegCtx->scTask.list.t = sJpegTask;
+ jpegCtx->scTask.list = sJpegTask;
osSendMesg(&gScheduler.cmdQueue, (OSMesg*)&jpegCtx->scTask, OS_MESG_BLOCK);
Sched_SendNotifyMsg(&gScheduler); // osScKickEntryMsg
diff --git a/tools/disasm/n64-jp-1.1/functions.txt b/tools/disasm/n64-jp-1.1/functions.txt
index 242a19b91..72f4412cb 100644
--- a/tools/disasm/n64-jp-1.1/functions.txt
+++ b/tools/disasm/n64-jp-1.1/functions.txt
@@ -42,8 +42,8 @@ CIC6105_Noop2 = 0x80081828; // type:func size:0x14
CIC6105_PrintRomInfo = 0x8008183C; // type:func size:0xEC
CIC6105_AddRomInfoFaultPage = 0x80081928; // type:func size:0x34
CIC6105_Destroy = 0x8008195C; // type:func size:0x24
-func_80081980_unknown = 0x80081980; // type:func size:0xD4
-func_80081A54_unknown = 0x80081A54; // type:func size:0xC
+CIC6105_ScheduleCICTask = 0x80081980; // type:func size:0xD4
+CIC6105_ILoveYou = 0x80081A54; // type:func size:0xC
CIC6105_Init = 0x80081A60; // type:func size:0x30
osSyncPrintfUnused = 0x80081A90; // type:func size:0x1C
osSyncPrintf = 0x80081AAC; // type:func size:0x1C
diff --git a/tools/disasm/n64-jp-1.1/variables.txt b/tools/disasm/n64-jp-1.1/variables.txt
index 7ae8402e4..d2600f527 100644
--- a/tools/disasm/n64-jp-1.1/variables.txt
+++ b/tools/disasm/n64-jp-1.1/variables.txt
@@ -385,7 +385,9 @@ sYaz0CurSize = 0x8009D968; // size:0x4
sYaz0MaxPtr = 0x8009D96C; // size:0x4
gCICAddr1Val = 0x8009D970; // size:0x4
gCICAddr2Val = 0x8009D974; // size:0x4
-sRomInfoFaultClient = 0x8009D978; // size:0x18
+sRomInfoFaultClient = 0x8009D978; // size:0x10
+gCICValue1 = 0x8009D988; // size:0x4
+gCICValue2 = 0x8009D98C; // size:0x4
sFaultInstance = 0x8009D990; // size:0x4
sFaultTimeTotal = 0x8009D994; // type:f32 size:0x4
sFaultCustomOptions = 0x8009D998; // size:0x4
@@ -4319,8 +4321,7 @@ B_801F85C4_unknown = 0x801F85C4;
B_801F85C8_unknown = 0x801F85C8;
B_801F85D8_unknown = 0x801F85D8;
B_801F85DC_unknown = 0x801F85DC;
-B_801F85E0_unknown = 0x801F85E0;
-B_801F86F8_unknown = 0x801F86F8;
+gScheduler = 0x801F85E0; // size:0x338 type:Scheduler
B_801F8918_unknown = 0x801F8918;
B_801F8920_unknown = 0x801F8920;
B_801F8938_unknown = 0x801F8938;
diff --git a/tools/disasm/n64-us/variables.txt b/tools/disasm/n64-us/variables.txt
index 35d6b2d68..7b232ef42 100644
--- a/tools/disasm/n64-us/variables.txt
+++ b/tools/disasm/n64-us/variables.txt
@@ -110,7 +110,7 @@ sYaz0MaxPtr = 0x8009BE1C; // size:0x4
gYaz0DecompressDstEnd = 0x8009BE20; // size:0x4
gCICAddr1Val = 0x8009BE30; // size:0x4
gCICAddr2Val = 0x8009BE34; // size:0x4
-sRomInfoFaultClient = 0x8009BE38; // size:0x18
+sRomInfoFaultClient = 0x8009BE38; // size:0x10
sFaultInstance = 0x8009BE50; // size:0x4
sFaultTimeTotal = 0x8009BE54; // size:0x4
sFaultCustomOptions = 0x8009BE58; // size:0x4