diff --git a/data/unk_80009410.data.s b/data/unk_80009410.data.s deleted file mode 100644 index 175b179a58..0000000000 --- a/data/unk_80009410.data.s +++ /dev/null @@ -1,27 +0,0 @@ -.include "macro.inc" - -/* assembler directives */ -.set noat /* allow manual use of $at */ -.set noreorder /* don't insert nops after branches */ -.set gp=64 /* allow use of 64-bit general purpose registers */ - -.section .data - -.balign 16 - -/* Unused */ -glabel D_80009410 - .word osStopThread - .word __osSetHWIntrRoutine -#if PLATFORM_N64 - .word osEPiWriteIo - .word osEPiReadIo -#endif - .word __osSetFpcCsr - .word __osGetFpcCsr - .word __osGetHWIntrRoutine - .word __osSetHWIntrRoutine - .word osViGetNextFramebuffer -#if !PLATFORM_N64 - .word bcmp -#endif diff --git a/include/gfx.h b/include/gfx.h index edc6217a3d..2c3d2b0a87 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -5,6 +5,7 @@ #include "ultra64/gbi.h" #include "sched.h" #include "thga.h" +#include "versions.h" // Texture memory size, 4 KiB #define TMEM_SIZE 0x1000 @@ -46,8 +47,10 @@ typedef struct GraphicsContext { /* 0x02E8 */ s32 fbIdx; /* 0x02EC */ void (*callback)(struct GraphicsContext*, void*); /* 0x02F0 */ void* callbackParam; +#if OOT_VERSION >= PAL_1_0 /* 0x02F4 */ f32 xScale; /* 0x02F8 */ f32 yScale; +#endif /* 0x02FC */ char unk_2FC[0x04]; } GraphicsContext; // size = 0x300 diff --git a/include/sched.h b/include/sched.h index e170817015..2d20e7ec09 100644 --- a/include/sched.h +++ b/include/sched.h @@ -3,6 +3,7 @@ #include "ultra64.h" #include "irqmgr.h" +#include "versions.h" #define OS_SC_NEEDS_RDP 0x0001 // Task uses the RDP #define OS_SC_NEEDS_RSP 0x0002 // Task uses the RSP @@ -27,8 +28,10 @@ typedef struct CfbInfo { /* 0x10 */ u8 unk_10; // set to 0, never read /* 0x11 */ s8 updateRate; // how many VIs should elapse before next swap /* 0x12 */ s8 updateTimer; // counts down (in VIs) from updateRate to 0, swaps the framebuffer at 0 +#if OOT_VERSION >= PAL_1_0 /* 0x14 */ f32 xScale; /* 0x18 */ f32 yScale; +#endif } CfbInfo; // size = 0x1C typedef struct OSScTask { diff --git a/spec b/spec index 6ea4769395..74d2cfe2a2 100644 --- a/spec +++ b/spec @@ -15,9 +15,11 @@ beginseg name "boot" address 0x80000460 include "$(BUILD_DIR)/src/boot/boot_main.o" - include "$(BUILD_DIR)/data/unk_80009410.data.o" include "$(BUILD_DIR)/src/boot/idle.o" +#if OOT_VERSION >= PAL_1_0 include "$(BUILD_DIR)/src/boot/viconfig.o" +#endif + include "$(BUILD_DIR)/src/boot/carthandle.o" include "$(BUILD_DIR)/src/boot/z_std_dma.o" include "$(BUILD_DIR)/src/boot/yaz0.o" include "$(BUILD_DIR)/src/boot/z_locale.o" @@ -41,8 +43,10 @@ beginseg include "$(BUILD_DIR)/src/libultra/io/piacs.o" include "$(BUILD_DIR)/src/libultra/os/sendmesg.o" include "$(BUILD_DIR)/src/libultra/os/stopthread.o" +#if OOT_VERSION >= PAL_1_0 include "$(BUILD_DIR)/src/libultra/io/viextendvstart.o" include "$(BUILD_DIR)/src/libultra/io/vimodepallan1.o" +#endif include "$(BUILD_DIR)/src/libultra/os/recvmesg.o" #if !PLATFORM_N64 include "$(BUILD_DIR)/src/libultra/os/initialize.o" @@ -92,7 +96,9 @@ beginseg include "$(BUILD_DIR)/src/libultra/os/setthreadpri.o" include "$(BUILD_DIR)/src/libultra/os/getthreadpri.o" include "$(BUILD_DIR)/src/libultra/io/epirawread.o" +#if OOT_VERSION >= PAL_1_0 include "$(BUILD_DIR)/src/libultra/io/viswapbuf.o" +#endif include "$(BUILD_DIR)/src/libultra/io/epirawdma.o" #if !PLATFORM_N64 include "$(BUILD_DIR)/src/libultra/libc/bcmp.o" @@ -113,11 +119,16 @@ beginseg #if OOT_PAL_N64 include "$(BUILD_DIR)/src/libultra/io/vimodentsclan1.o" include "$(BUILD_DIR)/src/libultra/io/vimodempallan1.o" +#endif +#if OOT_VERSION < PAL_1_0 + include "$(BUILD_DIR)/src/libultra/io/vimodepallan1.o" #endif include "$(BUILD_DIR)/src/libultra/io/viswapcontext.o" include "$(BUILD_DIR)/src/libultra/io/pigetcmdq.o" include "$(BUILD_DIR)/src/libultra/io/epiread.o" +#if OOT_VERSION >= PAL_1_0 include "$(BUILD_DIR)/src/libultra/io/visetspecial.o" +#endif include "$(BUILD_DIR)/src/libultra/io/cartrominit.o" #if OOT_PAL_N64 || OOT_DEBUG include "$(BUILD_DIR)/src/libultra/io/vimodefpallan1.o" @@ -143,8 +154,10 @@ beginseg include "$(BUILD_DIR)/src/libultra/io/vimgr.o" include "$(BUILD_DIR)/src/libultra/io/vigetcurrcontext.o" include "$(BUILD_DIR)/src/libultra/os/startthread.o" +#if OOT_VERSION >= PAL_1_0 include "$(BUILD_DIR)/src/libultra/io/visetyscale.o" include "$(BUILD_DIR)/src/libultra/io/visetxscale.o" +#endif include "$(BUILD_DIR)/src/libultra/os/sethwintrroutine.o" include "$(BUILD_DIR)/src/libultra/os/gethwintrroutine.o" #if !PLATFORM_N64 @@ -452,6 +465,15 @@ beginseg number 7 endseg +#if OOT_NTSC && OOT_VERSION < NTSC_1_2 +beginseg + name "jpn_message_data_static" + romalign 0x1000 + include "$(BUILD_DIR)/assets/text/jpn_message_data_static.o" + number 8 +endseg +#endif + beginseg name "message_texture_static" romalign 0x1000 @@ -466,7 +488,7 @@ beginseg number 10 endseg -#if OOT_NTSC +#if OOT_NTSC && OOT_VERSION >= NTSC_1_2 beginseg name "jpn_message_data_static" romalign 0x1000 @@ -807,6 +829,9 @@ beginseg include "$(BUILD_DIR)/src/libultra/libc/string.o" #endif include "$(BUILD_DIR)/src/libultra/io/sp.o" +#if OOT_VERSION < PAL_1_0 + include "$(BUILD_DIR)/src/libultra/io/viswapbuf.o" +#endif #if !PLATFORM_N64 include "$(BUILD_DIR)/src/libultra/mgu/mtxident.o" #endif @@ -828,6 +853,9 @@ beginseg include "$(BUILD_DIR)/src/libultra/gu/ortho.o" include "$(BUILD_DIR)/src/libultra/gu/cosf.o" include "$(BUILD_DIR)/src/libultra/gu/libm_vals.o" +#if OOT_VERSION < PAL_1_0 + include "$(BUILD_DIR)/src/libultra/io/visetspecial.o" +#endif include "$(BUILD_DIR)/src/libultra/gu/coss.o" #if PLATFORM_N64 include "$(BUILD_DIR)/src/libultra/os/settime.o" @@ -851,7 +879,7 @@ beginseg include "$(BUILD_DIR)/src/libultra/mgu/translate.o" #endif include "$(BUILD_DIR)/src/libultra/io/contramwrite.o" -#if !OOT_PAL_N64 && !OOT_DEBUG +#if OOT_VERSION == NTSC_1_2 || (PLATFORM_GC && !OOT_DEBUG) include "$(BUILD_DIR)/src/libultra/io/vimodefpallan1.o" #endif #if !OOT_DEBUG @@ -886,6 +914,9 @@ beginseg include "$(BUILD_DIR)/src/libultra/mgu/mtxf2l.o" #endif include "$(BUILD_DIR)/src/libultra/libc/llcvt.o" +#if OOT_VERSION < PAL_1_0 + include "$(BUILD_DIR)/src/libultra/io/visetyscale.o" +#endif include "$(BUILD_DIR)/src/libultra/io/vigetcurrframebuf.o" include "$(BUILD_DIR)/src/libultra/io/spsetpc.o" include "$(BUILD_DIR)/src/libc/sqrt.o" diff --git a/src/boot/carthandle.c b/src/boot/carthandle.c new file mode 100644 index 0000000000..16d3160b55 --- /dev/null +++ b/src/boot/carthandle.c @@ -0,0 +1,3 @@ +#include "ultra64.h" + +OSPiHandle* gCartHandle = NULL; diff --git a/src/boot/idle.c b/src/boot/idle.c index eca094e640..7128309e00 100644 --- a/src/boot/idle.c +++ b/src/boot/idle.c @@ -6,19 +6,33 @@ #pragma increment_block_number "gc-eu:64 gc-eu-mq:64 gc-jp:64 gc-jp-ce:64 gc-jp-mq:64 gc-us:64 gc-us-mq:64 ntsc-1.2:64" OSThread sMainThread; +#if OOT_VERSION < PAL_1_0 +STACK(sMainStack, 0x800); +#else STACK(sMainStack, 0x900); +#endif StackEntry sMainStackInfo; OSMesg sPiMgrCmdBuff[50]; OSMesgQueue gPiMgrCmdQueue; OSViMode gViConfigMode; -u8 gViConfigModeType; -s8 D_80009430 = 1; -vu8 gViConfigBlack = true; -u8 gViConfigAdditionalScanLines = 0; -u32 gViConfigFeatures = OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF; -f32 gViConfigXScale = 1.0; -f32 gViConfigYScale = 1.0; +#if OOT_VERSION < PAL_1_0 +u8 gViConfigModeType = OS_VI_NTSC_LPN1; +#else +u8 gViConfigModeType; +#endif + +// Unused +void* D_80009410[] = { + osStopThread, __osSetHWIntrRoutine, +#if PLATFORM_N64 + osEPiWriteIo, osEPiReadIo, +#endif + __osSetFpcCsr, __osGetFpcCsr, __osGetHWIntrRoutine, __osSetHWIntrRoutine, osViGetNextFramebuffer, +#if !PLATFORM_N64 + bcmp, +#endif +}; void Main_ThreadEntry(void* arg) { OSTime time; @@ -60,9 +74,11 @@ void Idle_ThreadEntry(void* arg) { osCreateViManager(OS_PRIORITY_VIMGR); +#if OOT_VERSION >= PAL_1_0 gViConfigFeatures = OS_VI_GAMMA_OFF | OS_VI_DITHER_FILTER_ON; gViConfigXScale = 1.0f; gViConfigYScale = 1.0f; +#endif #if OOT_DEBUG // Allow both 60 Hz and 50 Hz @@ -110,11 +126,17 @@ void Idle_ThreadEntry(void* arg) { } #endif +#if OOT_VERSION < PAL_1_0 + osViSetMode(&gViConfigMode); + osViBlack(true); +#else D_80009430 = 1; osViSetMode(&gViConfigMode); ViConfig_UpdateVi(true); osViBlack(true); osViSwapBuffer((void*)0x803DA80); //! @bug Invalid vram address (probably intended to be 0x803DA800) +#endif + osCreatePiManager(OS_PRIORITY_PIMGR, &gPiMgrCmdQueue, sPiMgrCmdBuff, ARRAY_COUNT(sPiMgrCmdBuff)); StackCheck_Init(&sMainStackInfo, sMainStack, STACK_TOP(sMainStack), 0, 0x400, "main"); osCreateThread(&sMainThread, THREAD_ID_MAIN, Main_ThreadEntry, arg, STACK_TOP(sMainStack), THREAD_PRI_MAIN_INIT); diff --git a/src/boot/viconfig.c b/src/boot/viconfig.c index 4ac95122c7..ae50922e63 100644 --- a/src/boot/viconfig.c +++ b/src/boot/viconfig.c @@ -1,8 +1,12 @@ #include "global.h" #include "terminal.h" -// this should probably go elsewhere but right now viconfig.o is the only object between idle and z_std_dma -OSPiHandle* gCartHandle = NULL; +s8 D_80009430 = 1; +vu8 gViConfigBlack = true; +u8 gViConfigAdditionalScanLines = 0; +u32 gViConfigFeatures = OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF; +f32 gViConfigXScale = 1.0; +f32 gViConfigYScale = 1.0; void ViConfig_UpdateVi(u32 black) { if (black) { diff --git a/src/boot/z_locale.c b/src/boot/z_locale.c index 2ff79fb013..6d60af64b4 100644 --- a/src/boot/z_locale.c +++ b/src/boot/z_locale.c @@ -1,6 +1,7 @@ #include "global.h" #include "region.h" #include "terminal.h" +#include "versions.h" s32 gCurrentRegion = 0; @@ -29,9 +30,11 @@ void Locale_Init(void) { case 'E': // "NTSC-U (North America)" gCurrentRegion = REGION_US; break; +#if OOT_VERSION >= PAL_1_0 case 'P': // "PAL (Europe)" gCurrentRegion = REGION_EU; break; +#endif default: PRINTF(VT_COL(RED, WHITE)); PRINTF(T("z_locale_init: 日本用かアメリカ用か判別できません\n", diff --git a/src/code/game.c b/src/code/game.c index 45362fb586..2b665e0d8d 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -2,6 +2,7 @@ #include "fault.h" #include "libc64/os_malloc.h" #include "terminal.h" +#include "versions.h" #if PLATFORM_N64 #include "n64dd.h" #endif @@ -281,6 +282,14 @@ void GameState_Update(GameState* gameState) { func_800C4344(gameState); +#if OOT_VERSION < PAL_1_0 + if (R_VI_MODE_EDIT_STATE != VI_MODE_EDIT_STATE_INACTIVE) { + ViMode_Update(&sViMode, &gameState->input[0]); + gfxCtx->viMode = &sViMode.customViMode; + gfxCtx->viFeatures = sViMode.viFeatures; + } +#endif + #if OOT_DEBUG if (SREG(63) == 1u) { if (R_VI_MODE_EDIT_STATE < VI_MODE_EDIT_STATE_INACTIVE) { diff --git a/src/code/graph.c b/src/code/graph.c index 5aadf9cc80..2ecd87dd12 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -2,6 +2,7 @@ #include "fault.h" #include "terminal.h" #include "ucode_disas.h" +#include "versions.h" #define GFXPOOL_HEAD_MAGIC 0x1234 #define GFXPOOL_TAIL_MAGIC 0x5678 @@ -140,10 +141,17 @@ void Graph_Init(GraphicsContext* gfxCtx) { gfxCtx->gfxPoolIdx = 0; gfxCtx->fbIdx = 0; gfxCtx->viMode = NULL; + +#if OOT_VERSION < PAL_1_0 + gfxCtx->viFeatures = 0; +#else gfxCtx->viFeatures = gViConfigFeatures; gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; +#endif + osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff)); + #if OOT_DEBUG func_800D31F0(); Fault_AddClient(&sGraphFaultClient, Graph_FaultClient, NULL, NULL); @@ -272,8 +280,10 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx) { cfb->viMode = gfxCtx->viMode; cfb->viFeatures = gfxCtx->viFeatures; +#if OOT_VERSION >= PAL_1_0 cfb->xScale = gfxCtx->xScale; cfb->yScale = gfxCtx->yScale; +#endif cfb->unk_10 = 0; cfb->updateRate = R_UPDATE_RATE; diff --git a/src/code/sched.c b/src/code/sched.c index 77860aa511..3374da65e6 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -41,6 +41,7 @@ */ #include "global.h" #include "fault.h" +#include "versions.h" #define RSP_DONE_MSG 667 #define RDP_DONE_MSG 668 @@ -53,7 +54,7 @@ OSTime sRSPAudioTimeStart; OSTime sRSPOtherTimeStart; OSTime sRDPTimeStart; -#if OOT_DEBUG +#if OOT_VERSION < PAL_1_0 || OOT_DEBUG vs32 sSchedDebugPrintfEnabled = false; #define SCHED_DEBUG_PRINTF \ @@ -115,10 +116,29 @@ void Sched_SwapFrameBufferImpl(CfbInfo* cfbInfo) { #endif } +#if OOT_VERSION < PAL_1_0 + if (cfbInfo->viMode != NULL) { + osViSetMode(cfbInfo->viMode); + osViSetSpecialFeatures(cfbInfo->viFeatures); + } + if (1) {} + if (1) {} + if (1) {} + if (1) {} + if (1) {} +#endif + cfbInfo->unk_10 = 0; } void Sched_SwapFrameBuffer(Scheduler* sc, CfbInfo* cfbInfo) { +#if OOT_VERSION < PAL_1_0 + Sched_SwapFrameBufferImpl(cfbInfo); + if (sc->isFirstSwap) { + osViBlack(false); + sc->isFirstSwap = false; + } +#else if (sc->isFirstSwap) { sc->isFirstSwap = false; @@ -127,6 +147,7 @@ void Sched_SwapFrameBuffer(Scheduler* sc, CfbInfo* cfbInfo) { } } Sched_SwapFrameBufferImpl(cfbInfo); +#endif } void Sched_HandlePreNMI(Scheduler* sc) { @@ -162,7 +183,12 @@ void Sched_HandlePreNMI(Scheduler* sc) { void Sched_HandleNMI(Scheduler* sc) { // black the screen and reset the VI y scale just in time for NMI reset +#if OOT_VERSION < PAL_1_0 + osViSetYScale(1.0f); + osViBlack(true); +#else ViConfig_UpdateVi(true); +#endif } /** @@ -424,6 +450,13 @@ void Sched_RunTask(Scheduler* sc, OSScTask* spTask, OSScTask* dpTask) { // If the task also uses the RDP, set current running RDP task if (spTask == dpTask && sc->curRDPTask == NULL) { +#if OOT_VERSION < PAL_1_0 + // Unknown SCHED_DEBUG_PRINTF calls + if (sSchedDebugPrintfEnabled) {} + if (sSchedDebugPrintfEnabled) {} + if (sSchedDebugPrintfEnabled) {} +#endif + sc->curRDPTask = dpTask; sRDPTimeStart = sRSPGfxTimeStart; } @@ -467,7 +500,9 @@ void Sched_HandleNotification(Scheduler* sc) { void Sched_HandleRetrace(Scheduler* sc) { SCHED_DEBUG_PRINTF("%08d:scHandleRetrace %08x\n", (u32)OS_CYCLES_TO_USEC(osGetTime()), osViGetCurrentFramebuffer()); +#if OOT_VERSION >= PAL_1_0 ViConfig_UpdateBlack(); +#endif sc->retraceCount++; // Retrace handlers run after VI context swap. The last swap buffer may now be the current buffer. @@ -649,6 +684,12 @@ void Sched_Init(Scheduler* sc, void* stack, OSPri priority, u8 viModeType, UNK_T // Create message queues for receiving interrupt events and tasks osCreateMesgQueue(&sc->interruptQueue, sc->interruptMsgBuf, ARRAY_COUNT(sc->interruptMsgBuf)); osCreateMesgQueue(&sc->cmdQueue, sc->cmdMsgBuf, ARRAY_COUNT(sc->cmdMsgBuf)); + +#if OOT_VERSION < PAL_1_0 + osViBlack(true); + osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF); +#endif + osSetEventMesg(OS_EVENT_SP, &sc->interruptQueue, (OSMesg)RSP_DONE_MSG); osSetEventMesg(OS_EVENT_DP, &sc->interruptQueue, (OSMesg)RDP_DONE_MSG); IrqMgr_AddClient(irqMgr, &sc->irqClient, &sc->interruptQueue); diff --git a/src/code/z_prenmi.c b/src/code/z_prenmi.c index 29ea097d68..e1bb151453 100644 --- a/src/code/z_prenmi.c +++ b/src/code/z_prenmi.c @@ -1,5 +1,6 @@ #include "global.h" #include "terminal.h" +#include "versions.h" void func_80092320(PreNMIState* this) { this->state.running = false; @@ -17,7 +18,12 @@ void PreNMI_Update(PreNMIState* this) { } if (this->timer == 0) { +#if OOT_VERSION < PAL_1_0 + osViSetYScale(1.0f); + osViBlack(true); +#else ViConfig_UpdateVi(true); +#endif func_80092320(this); return; }