From 31f0d68ca2e7c9d52f31efa4628d8fefca0caeed Mon Sep 17 00:00:00 2001 From: Hyenadae Date: Wed, 13 May 2020 07:57:25 -0400 Subject: [PATCH 01/16] Removed majority of TARGET_N64 logic from code --- bin/segment2.c | 26 +----- include/PR/gbi.h | 22 ----- include/PR/ultratypes.h | 9 +- include/config.h | 9 +- include/gfx_dimensions.h | 8 -- include/macros.h | 11 --- include/make_const_nonconst.h | 7 -- include/platform_info.h | 5 -- include/segment_symbols.h | 10 --- levels/menu/script.c | 7 +- lib/src/guMtxF2L.c | 49 +---------- src/audio/external.c | 110 +------------------------ src/audio/heap.c | 7 +- src/audio/internal.h | 3 - src/audio/port_eu.c | 101 ----------------------- src/audio/synthesis.c | 3 - src/buffers/buffers.h | 5 +- src/engine/level_script.c | 15 ++-- src/engine/surface_load.c | 3 - src/engine/surface_load.h | 4 +- src/game/display.h | 2 +- src/game/game_init.c | 67 +++------------ src/game/game_init.h | 4 +- src/game/geo_misc.c | 5 +- src/game/geo_misc.h | 6 -- src/game/ingame_menu.c | 29 ++----- src/game/macro_special_objects.c | 3 +- src/game/macro_special_objects.h | 2 - src/game/memory.c | 136 +------------------------------ src/game/memory.h | 8 -- src/game/print.c | 26 ------ src/game/rendering_graph_node.c | 6 -- src/game/screen_transition.c | 13 +-- src/game/skybox.c | 2 - src/goddard/renderer.c | 106 +----------------------- src/goddard/skin.c | 26 ++---- 36 files changed, 58 insertions(+), 797 deletions(-) diff --git a/bin/segment2.c b/bin/segment2.c index d4199d9c..d7e807fd 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -2499,41 +2499,23 @@ static const Lights1 segment2_lights_unused = gdSPDefLights1( // 0x02014470 - 0x020144B0 static const Mtx matrix_identity = { -#ifdef TARGET_N64 - {{0x00010000, 0x00000000, - 0x00000001, 0x00000000}, - {0x00000000, 0x00010000, - 0x00000000, 0x00000001}, - {0x00000000, 0x00000000, - 0x00000000, 0x00000000}, - {0x00000000, 0x00000000, - 0x00000000, 0x00000000}} -#else + {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}} -#endif + }; // 0x020144B0 - 0x020144F0 static const Mtx matrix_fullscreen = { -#if TARGET_N64 - {{0x00000000, 0x00000000, - 0x00000000, 0x00000000}, - {0x00000000, 0xffff0000, - 0xffffffff, 0xffff0001}, - {((65536 * 2 / SCREEN_WIDTH) << 16) | 0, 0x00000000, - (0 << 16) | (65536 * 2 / SCREEN_HEIGHT), 0x00000000}, - {0x00000000, 0x00000000, - 0x00000000, 0x00000000}} -#else + {{2.0f / SCREEN_WIDTH, 0.0f, 0.0f, 0.0f}, {0.0f, 2.0f / SCREEN_HEIGHT, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f, 0.0f}, {-1.0f, -1.0f, -1.0f, 1.0f}} -#endif + }; diff --git a/include/PR/gbi.h b/include/PR/gbi.h index 4a7a5de0..0f63e04f 100644 --- a/include/PR/gbi.h +++ b/include/PR/gbi.h @@ -1109,11 +1109,7 @@ * Vertex (set up for use with colors) */ typedef struct { -#ifdef TARGET_N64 - short ob[3]; /* x, y, z */ -#else float ob[3]; /* x, y, z */ -#endif unsigned short flag; short tc[2]; /* texture coord */ unsigned char cn[4]; /* color & alpha */ @@ -1123,11 +1119,7 @@ typedef struct { * Vertex (set up for use with normals) */ typedef struct { -#ifdef TARGET_N64 - short ob[3]; /* x, y, z */ -#else float ob[3]; /* x, y, z */ -#endif unsigned short flag; short tc[2]; /* texture coord */ signed char n[3]; /* normal */ @@ -1176,23 +1168,9 @@ typedef struct { unsigned char v[3]; } Tri; -#ifdef TARGET_N64 -/* - * 4x4 matrix, fixed point s15.16 format. - * First 8 words are integer portion of the 4x4 matrix - * Last 8 words are the fraction portion of the 4x4 matrix - */ -typedef s32 Mtx_t[4][4]; - -typedef union { - Mtx_t m; - long long int force_structure_alignment; -} Mtx; -#else typedef struct { float m[4][4]; } Mtx; -#endif /* * Viewport diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8a00490a..e2a3e771 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -29,16 +29,9 @@ typedef volatile s64 vs64; typedef float f32; typedef double f64; -#ifdef TARGET_N64 -typedef u32 size_t; -typedef s32 ssize_t; -typedef u32 uintptr_t; -typedef s32 intptr_t; -typedef s32 ptrdiff_t; -#else #include #include typedef ptrdiff_t ssize_t; -#endif + #endif diff --git a/include/config.h b/include/config.h index df5cc54e..db50b1cc 100644 --- a/include/config.h +++ b/include/config.h @@ -1,4 +1,5 @@ #ifndef CONFIG_H + #define CONFIG_H /** @@ -28,15 +29,11 @@ #define SCREEN_HEIGHT 240 // Border Height Define for NTSC Versions -#ifdef TARGET_N64 -#ifndef VERSION_EU -#define BORDER_HEIGHT 8 -#else + #define BORDER_HEIGHT 1 -#endif + #else // What's the point of having a border? #define BORDER_HEIGHT 0 -#endif #endif diff --git a/include/gfx_dimensions.h b/include/gfx_dimensions.h index dfc0394d..cae20701 100644 --- a/include/gfx_dimensions.h +++ b/include/gfx_dimensions.h @@ -1,7 +1,6 @@ #ifndef GFX_DIMENSIONS_H #define GFX_DIMENSIONS_H -#ifndef TARGET_N64 #include #include "pc/gfx/gfx_pc.h" #define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * gfx_current_dimensions.aspect_ratio + (v)) @@ -9,12 +8,5 @@ #define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v)) #define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v)) #define GFX_DIMENSIONS_ASPECT_RATIO (gfx_current_dimensions.aspect_ratio) -#else -#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (v) -#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH - (v)) -#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) (v) -#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH - (v)) -#define GFX_DIMENSIONS_ASPECT_RATIO (4.0f / 3.0f) -#endif #endif diff --git a/include/macros.h b/include/macros.h index 8d6182c9..bcace7fb 100644 --- a/include/macros.h +++ b/include/macros.h @@ -46,20 +46,9 @@ #define ALIGNED16 #endif -#ifdef TARGET_N64 -// convert a virtual address to physical. -#define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF) - -// convert a physical address to virtual. -#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) | 0x80000000) - -// another way of converting virtual to physical -#define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U) -#else // no conversion for pc port other than cast #define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr)) #define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr)) #define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr)) -#endif #endif diff --git a/include/make_const_nonconst.h b/include/make_const_nonconst.h index 6336ec34..249f73ae 100644 --- a/include/make_const_nonconst.h +++ b/include/make_const_nonconst.h @@ -1,11 +1,4 @@ #ifndef MAKE_CONST_NONCONST_H #define MAKE_CONST_NONCONST_H -#ifdef TARGET_N64 -// IDO sometimes puts const variables in .rodata and sometimes in .data, which breaks ordering. -// This makes sure all variables are put into the same section (.data). We need to do this for -// both IDO and gcc for TARGET_N64. -#define const -#endif - #endif diff --git a/include/platform_info.h b/include/platform_info.h index ee35d4f0..2197833a 100644 --- a/include/platform_info.h +++ b/include/platform_info.h @@ -1,14 +1,9 @@ #ifndef PLATFORM_INFO_H #define PLATFORM_INFO_H -#ifdef TARGET_N64 -#define IS_64_BIT 0 -#define IS_BIG_ENDIAN 1 -#else #include #define IS_64_BIT (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFU) #define IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -#endif #define DOUBLE_SIZE_ON_64_BIT(size) ((size) * (sizeof(void *) / 4)) diff --git a/include/segment_symbols.h b/include/segment_symbols.h index 77adc158..26d65cde 100644 --- a/include/segment_symbols.h +++ b/include/segment_symbols.h @@ -1,15 +1,9 @@ #ifndef SEGMENT_SYMBOLS_H #define SEGMENT_SYMBOLS_H -#ifdef TARGET_N64 -#define DECLARE_SEGMENT(name) \ - extern u8 _##name##SegmentRomStart[]; \ - extern u8 _##name##SegmentRomEnd[]; -#else #define DECLARE_SEGMENT(name) \ static u8 _##name##SegmentRomStart[1]; \ static u8 _##name##SegmentRomEnd[1]; -#endif #define DECLARE_ACTOR_SEGMENT(name) \ DECLARE_SEGMENT(name##_mio0) \ @@ -43,11 +37,7 @@ DECLARE_ACTOR_SEGMENT(group17) DECLARE_SEGMENT(behavior) DECLARE_SEGMENT(scripts) DECLARE_SEGMENT(goddard) -#ifdef TARGET_N64 -extern u8 _goddardSegmentStart[]; -#else static u8 _goddardSegmentStart[1]; -#endif DECLARE_LEVEL_SEGMENT(menu) DECLARE_LEVEL_SEGMENT(intro) diff --git a/levels/menu/script.c b/levels/menu/script.c index 5a9d3e44..4e955c12 100644 --- a/levels/menu/script.c +++ b/levels/menu/script.c @@ -72,19 +72,16 @@ const LevelScript level_main_menu_entry_2[] = { /*25*/ FREE_LEVEL_POOL(), /*26*/ LOAD_AREA(/*area*/ 2), -#ifndef TARGET_N64 + // sVisibleStars is set to 0 during FIXED_LOAD above on N64, but not on PC-port. // lvl_init_act_selector_values_and_stars must be called here otherwise the // previous value is retained and causes incorrect drawing during the 16 transition // frames. CALL(/*arg*/ 0, /*func*/ lvl_init_act_selector_values_and_stars), -#endif + /*27*/ TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF), /*29*/ SLEEP(/*frames*/ 16), /*30*/ SET_MENU_MUSIC(/*seq*/ 0x000D), -#ifdef TARGET_N64 - /*31*/ CALL(/*arg*/ 0, /*func*/ lvl_init_act_selector_values_and_stars), -#endif /*33*/ CALL_LOOP(/*arg*/ 0, /*func*/ lvl_update_obj_and_load_act_button_actions), /*35*/ GET_OR_SET(/*op*/ OP_SET, /*var*/ VAR_CURR_ACT_NUM), /*36*/ STOP_MUSIC(/*fadeOutTime*/ 0x00BE), diff --git a/lib/src/guMtxF2L.c b/lib/src/guMtxF2L.c index e08528ec..9cd7359c 100644 --- a/lib/src/guMtxF2L.c +++ b/lib/src/guMtxF2L.c @@ -1,49 +1,9 @@ #include "libultra_internal.h" -#ifndef TARGET_N64 #include -#endif -#ifdef TARGET_N64 -void guMtxF2L(float mf[4][4], Mtx *m) { - int r, c; - s32 tmp1; - s32 tmp2; - s32 *m1 = &m->m[0][0]; - s32 *m2 = &m->m[2][0]; - for (r = 0; r < 4; r++) { - for (c = 0; c < 2; c++) { - tmp1 = mf[r][2 * c] * 65536.0f; - tmp2 = mf[r][2 * c + 1] * 65536.0f; - *m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff); - *m2++ = ((tmp1 << 0x10) & 0xffff0000) | (tmp2 & 0xffff); - } - } -} -void guMtxL2F(float mf[4][4], Mtx *m) { - int r, c; - u32 tmp1; - u32 tmp2; - u32 *m1; - u32 *m2; - s32 stmp1, stmp2; - m1 = (u32 *) &m->m[0][0]; - m2 = (u32 *) &m->m[2][0]; - for (r = 0; r < 4; r++) { - for (c = 0; c < 2; c++) { - tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff); - tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff); - stmp1 = *(s32 *) &tmp1; - stmp2 = *(s32 *) &tmp2; - mf[r][c * 2 + 0] = stmp1 / 65536.0f; - mf[r][c * 2 + 1] = stmp2 / 65536.0f; - } - } -} -#else void guMtxF2L(float mf[4][4], Mtx *m) { memcpy(m, mf, sizeof(Mtx)); } -#endif void guMtxIdentF(float mf[4][4]) { int r, c; @@ -58,11 +18,8 @@ void guMtxIdentF(float mf[4][4]) { } } void guMtxIdent(Mtx *m) { -#ifdef TARGET_N64 - float mf[4][4]; - guMtxIdentF(mf); - guMtxF2L(mf, m); -#else + guMtxIdentF(m->m); -#endif + } + diff --git a/src/audio/external.c b/src/audio/external.c index 32431a53..a059c0b5 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -738,6 +738,7 @@ void func_8031D838(s32 player, FadeT fadeInTime, u8 targetVolume) { } seqPlayer->fadeVelocity = (((f32)(FLOAT_CAST(targetVolume) / EU_FLOAT(127.0)) - seqPlayer->fadeVolume) / (f32) fadeInTime); + #ifdef VERSION_EU seqPlayer->state = 0; #else @@ -764,117 +765,15 @@ void func_eu_802e9bec(s32 player, s32 channel, s32 arg2) { } #else - -#ifdef TARGET_N64 -struct SPTask *create_next_audio_frame_task(void) { - u32 samplesRemainingInAI; - s32 writtenCmds; - s32 index; - OSTask_t *task; - s32 oldDmaCount; - s32 flags; - - gAudioFrameCount++; - if (gAudioLoadLock != AUDIO_LOCK_NOT_LOADING) { - stubbed_printf("DAC:Lost 1 Frame.\n"); - return NULL; - } - - gAudioTaskIndex ^= 1; - gCurrAiBufferIndex++; - gCurrAiBufferIndex %= NUMAIBUFFERS; - index = (gCurrAiBufferIndex - 2 + NUMAIBUFFERS) % NUMAIBUFFERS; - samplesRemainingInAI = osAiGetLength() / 4; - - // Audio is triple buffered; the audio interface reads from two buffers - // while the third is being written by the RSP. More precisely, the - // lifecycle is: - // - this function computes an audio command list - // - wait for vblank - // - the command list is sent to the RSP (we could have sent it to the - // RSP before the vblank, but that gives the RSP less time to finish) - // - wait for vblank - // - the RSP is now expected to be finished, and we can send its output - // on to the AI - // Here we thus send to the AI the sound that was generated two frames ago. - if (gAiBufferLengths[index] != 0) { - osAiSetNextBuffer(gAiBuffers[index], gAiBufferLengths[index] * 4); - } - - oldDmaCount = gCurrAudioFrameDmaCount; - // There has to be some sort of no-op if here, but it's not exactly clear - // how it should look... It's also very unclear why gCurrAudioFrameDmaQueue - // isn't read from here, despite gCurrAudioFrameDmaCount being reset. - if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE) { - stubbed_printf("DMA: Request queue over.( %d )\n", oldDmaCount); - } - gCurrAudioFrameDmaCount = 0; - - gAudioTask = &gAudioTasks[gAudioTaskIndex]; - gAudioCmd = gAudioCmdBuffers[gAudioTaskIndex]; - - index = gCurrAiBufferIndex; - gCurrAiBuffer = gAiBuffers[index]; - gAiBufferLengths[index] = ((gSamplesPerFrameTarget - samplesRemainingInAI + - EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE; - if (gAiBufferLengths[index] < gMinAiBufferLength) { - gAiBufferLengths[index] = gMinAiBufferLength; - } - if (gAiBufferLengths[index] > gSamplesPerFrameTarget + SAMPLES_TO_OVERPRODUCE) { - gAiBufferLengths[index] = gSamplesPerFrameTarget + SAMPLES_TO_OVERPRODUCE; - } - - if (sGameLoopTicked != 0) { - update_game_sound(); - sGameLoopTicked = 0; - } - - // For the function to match we have to preserve some arbitrary variable - // across this function call. - flags = 0; - gAudioCmd = synthesis_execute(gAudioCmd, &writtenCmds, gCurrAiBuffer, gAiBufferLengths[index]); - gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount); - - index = gAudioTaskIndex; - gAudioTask->msgqueue = NULL; - gAudioTask->msg = NULL; - - task = &gAudioTask->task.t; - task->type = M_AUDTASK; - task->flags = flags; - task->ucode_boot = rspF3DBootStart; - task->ucode_boot_size = (u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart; - task->ucode = rspAspMainStart; - task->ucode_size = 0x800; // (this size is ignored) - task->ucode_data = rspAspMainDataStart; - task->ucode_data_size = (rspAspMainDataEnd - rspAspMainDataStart) * sizeof(u64); - task->dram_stack = NULL; - task->dram_stack_size = 0; - task->output_buff = NULL; - task->output_buff_size = NULL; - task->data_ptr = gAudioCmdBuffers[index]; - task->data_size = writtenCmds * sizeof(u64); - - // The audio task never yields, so having a yield buffer is pointless. - // This wastefulness was fixed in US. -#ifdef VERSION_JP - task->yield_data_ptr = (u64 *) gAudioSPTaskYieldBuffer; - task->yield_data_size = OS_YIELD_AUDIO_SIZE; -#else - task->yield_data_ptr = NULL; - task->yield_data_size = 0; +// Stubbed N64-US/JP audio code +// continue; #endif - decrease_sample_dma_ttls(); - return gAudioTask; -} -#endif -#endif -#ifndef TARGET_N64 struct SPTask *create_next_audio_frame_task(void) { return NULL; } + void create_next_audio_buffer(s16 *samples, u32 num_samples) { gAudioFrameCount++; if (sGameLoopTicked != 0) { @@ -886,7 +785,6 @@ void create_next_audio_buffer(s16 *samples, u32 num_samples) { gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount); decrease_sample_dma_ttls(); } -#endif void play_sound(s32 soundBits, f32 *pos) { sSoundRequests[sSoundRequestCount].soundBits = soundBits; diff --git a/src/audio/heap.c b/src/audio/heap.c index 32b8103c..d1d69417 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -651,12 +651,7 @@ s32 audio_shut_down_and_reset_step(void) { */ void wait_for_audio_frames(s32 frames) { gAudioFrameCount = 0; -#ifdef TARGET_N64 - // Sound thread will update gAudioFrameCount - while (gAudioFrameCount < frames) { - // spin - } -#endif + } #endif diff --git a/src/audio/internal.h b/src/audio/internal.h index f681afae..fa44c8be 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -507,9 +507,6 @@ struct Note /* U/J, EU */ /*0xA4, 0x00*/ struct AudioListItem listItem; /* 0x10*/ struct NoteSynthesisState synthesisState; -#ifdef TARGET_N64 - u8 pad0[12]; -#endif /*0x04, 0x30*/ u8 priority; /* 0x31*/ u8 waveId; /* 0x32*/ u8 sampleCountIndex; diff --git a/src/audio/port_eu.c b/src/audio/port_eu.c index f90fc2bf..b0d0650e 100644 --- a/src/audio/port_eu.c +++ b/src/audio/port_eu.c @@ -34,107 +34,6 @@ void decrease_sample_dma_ttls(void); s32 audio_shut_down_and_reset_step(void); void func_802ad7ec(u32); -#ifdef TARGET_N64 -struct SPTask *create_next_audio_frame_task(void) { - u32 samplesRemainingInAI; - s32 writtenCmds; - s32 index; - OSTask_t *task; - s32 flags; - u16 *currAiBuffer; - s32 oldDmaCount; - OSMesg sp30; - OSMesg sp2C; - - gAudioFrameCount++; - if (gAudioFrameCount % gAudioBufferParameters.presetUnk4 != 0) { - stubbed_printf("DAC:Lost 1 Frame.\n"); - return NULL; - } - - osSendMesg(OSMesgQueues[0], (OSMesg) gAudioFrameCount, 0); - - gAudioTaskIndex ^= 1; - gCurrAiBufferIndex++; - gCurrAiBufferIndex %= NUMAIBUFFERS; - index = (gCurrAiBufferIndex - 2 + NUMAIBUFFERS) % NUMAIBUFFERS; - samplesRemainingInAI = osAiGetLength() / 4; - - if (gAiBufferLengths[index] != 0) { - osAiSetNextBuffer(gAiBuffers[index], gAiBufferLengths[index] * 4); - } - - oldDmaCount = gCurrAudioFrameDmaCount; - if (oldDmaCount > AUDIO_FRAME_DMA_QUEUE_SIZE) { - stubbed_printf("DMA: Request queue over.( %d )\n", oldDmaCount); - } - gCurrAudioFrameDmaCount = 0; - - decrease_sample_dma_ttls(); - if (osRecvMesg(OSMesgQueues[2], &sp30, 0) != -1) { - gAudioResetPresetIdToLoad = (u8) (s32) sp30; - gAudioResetStatus = 5; - } - - if (gAudioResetStatus != 0) { - if (audio_shut_down_and_reset_step() == 0) { - if (gAudioResetStatus == 0) { - osSendMesg(OSMesgQueues[3], (OSMesg) (s32) gAudioResetPresetIdToLoad, OS_MESG_NOBLOCK); - } - return NULL; - } - } - - gAudioTask = &gAudioTasks[gAudioTaskIndex]; - gAudioCmd = gAudioCmdBuffers[gAudioTaskIndex]; - index = gCurrAiBufferIndex; - currAiBuffer = gAiBuffers[index]; - - gAiBufferLengths[index] = ((gAudioBufferParameters.samplesPerFrameTarget - samplesRemainingInAI + - EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE; - if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength) { - gAiBufferLengths[index] = gAudioBufferParameters.minAiBufferLength; - } - if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength) { - gAiBufferLengths[index] = gAudioBufferParameters.maxAiBufferLength; - } - - if (osRecvMesg(OSMesgQueues[1], &sp2C, OS_MESG_NOBLOCK) != -1) { - func_802ad7ec((u32) sp2C); - } - - flags = 0; - gAudioCmd = synthesis_execute(gAudioCmd, &writtenCmds, currAiBuffer, gAiBufferLengths[index]); - gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount); - gAudioRandom = gAudioRandom + writtenCmds / 8; - - index = gAudioTaskIndex; - gAudioTask->msgqueue = NULL; - gAudioTask->msg = NULL; - - task = &gAudioTask->task.t; - task->type = M_AUDTASK; - task->flags = flags; -#if TARGET_N64 - task->ucode_boot = rspF3DBootStart; - task->ucode_boot_size = (u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart; - task->ucode = rspAspMainStart; - task->ucode_data = rspAspMainDataStart; - task->ucode_size = 0x800; // (this size is ignored) - task->ucode_data_size = (rspAspMainDataEnd - rspAspMainDataStart) * sizeof(u64); -#endif - task->dram_stack = NULL; - task->dram_stack_size = 0; - task->output_buff = NULL; - task->output_buff_size = NULL; - task->data_ptr = gAudioCmdBuffers[index]; - task->data_size = writtenCmds * sizeof(u64); - task->yield_data_ptr = NULL; - task->yield_data_size = 0; - return gAudioTask; -} -#endif - void eu_process_audio_cmd(struct EuAudioCmd *cmd) { s32 i; diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index 370728ba..b332c9f0 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -8,10 +8,7 @@ #include "seqplayer.h" #include "external.h" - -#ifndef TARGET_N64 #include "../pc/mixer.h" -#endif #define DMEM_ADDR_TEMP 0x0 #define DMEM_ADDR_UNCOMPRESSED_NOTE 0x180 diff --git a/src/buffers/buffers.h b/src/buffers/buffers.h index aa834618..3d8b6c64 100644 --- a/src/buffers/buffers.h +++ b/src/buffers/buffers.h @@ -27,11 +27,8 @@ extern struct SaveBuffer gSaveBuffer; extern u8 gGfxSPTaskStack[]; -#ifdef TARGET_N64 -#define GFX_NUM_POOLS 2 -#else #define GFX_NUM_POOLS 1 -#endif + extern struct GfxPool gGfxPools[GFX_NUM_POOLS]; #endif diff --git a/src/engine/level_script.c b/src/engine/level_script.c index d0534038..64e4d46e 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -1,7 +1,6 @@ #include -#ifndef TARGET_N64 #include -#endif + #include "sm64.h" #include "audio/external.h" @@ -605,9 +604,7 @@ static void level_cmd_set_gamma(void) { static void level_cmd_set_terrain_data(void) { if (sCurrAreaIndex != -1) { -#ifdef TARGET_N64 - gAreas[sCurrAreaIndex].terrainData = segmented_to_virtual(CMD_GET(void *, 4)); -#else + Collision *data; u32 size; @@ -615,7 +612,7 @@ static void level_cmd_set_terrain_data(void) { size = get_area_terrain_size(data) * sizeof(Collision); gAreas[sCurrAreaIndex].terrainData = alloc_only_pool_alloc(sLevelPool, size); memcpy(gAreas[sCurrAreaIndex].terrainData, data, size); -#endif + } sCurrentCmd = CMD_NEXT; } @@ -629,9 +626,7 @@ static void level_cmd_set_rooms(void) { static void level_cmd_set_macro_objects(void) { if (sCurrAreaIndex != -1) { -#ifdef TARGET_N64 - gAreas[sCurrAreaIndex].macroObjects = segmented_to_virtual(CMD_GET(void *, 4)); -#else + MacroObject *data = segmented_to_virtual(CMD_GET(void *, 4)); s32 len = 0; while (data[len++] != 0x001E) { @@ -639,7 +634,7 @@ static void level_cmd_set_macro_objects(void) { } gAreas[sCurrAreaIndex].macroObjects = alloc_only_pool_alloc(sLevelPool, len * sizeof(MacroObject)); memcpy(gAreas[sCurrAreaIndex].macroObjects, data, len * sizeof(MacroObject)); -#endif + } sCurrentCmd = CMD_NEXT; } diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index 363f9afb..da354352 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -533,7 +533,6 @@ void alloc_surface_pools(void) { reset_red_coins_collected(); } -#ifndef TARGET_N64 /** * Get the size of the terrain data, to get the correct size when copying later. */ @@ -581,8 +580,6 @@ u32 get_area_terrain_size(s16 *data) { return data - startPos; } -#endif - /** * Process the level file, loading in vertices, surfaces, some objects, and environmental diff --git a/src/engine/surface_load.h b/src/engine/surface_load.h index 943317c9..b8637be4 100644 --- a/src/engine/surface_load.h +++ b/src/engine/surface_load.h @@ -28,9 +28,9 @@ extern struct Surface *sSurfacePool; extern s16 sSurfacePoolSize; void alloc_surface_pools(void); -#ifndef TARGET_N64 + u32 get_area_terrain_size(s16 *data); -#endif + void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects); void clear_dynamic_surfaces(void); void load_object_collision_model(void); diff --git a/src/game/display.h b/src/game/display.h index 0c427111..877c4f0b 100644 --- a/src/game/display.h +++ b/src/game/display.h @@ -3,7 +3,7 @@ #include "types.h" -#define GFX_POOL_SIZE 6400 +#define GFX_POOL_SIZE 64000 extern u16 frameBufferIndex; extern u32 gGlobalTimer; diff --git a/src/game/game_init.c b/src/game/game_init.c index 939383a2..8834fc8b 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -217,13 +217,7 @@ void create_task_structure(void) { gGfxSPTask->msgqueue = &D_80339CB8; gGfxSPTask->msg = (OSMesg) 2; gGfxSPTask->task.t.type = M_GFXTASK; -#if TARGET_N64 - gGfxSPTask->task.t.ucode_boot = rspF3DBootStart; - gGfxSPTask->task.t.ucode_boot_size = ((u8 *) rspF3DBootEnd - (u8 *) rspF3DBootStart); - gGfxSPTask->task.t.flags = 0; - gGfxSPTask->task.t.ucode = rspF3DStart; - gGfxSPTask->task.t.ucode_data = rspF3DDataStart; -#endif + gGfxSPTask->task.t.ucode_size = SP_UCODE_SIZE; // (this size is ignored) gGfxSPTask->task.t.ucode_data_size = SP_UCODE_DATA_SIZE; gGfxSPTask->task.t.dram_stack = (u64 *) gGfxSPTaskStack; @@ -267,33 +261,9 @@ void end_master_display_list(void) { create_task_structure(); } -void draw_reset_bars(void) { - s32 sp24; - s32 sp20; - s32 fbNum; - u64 *sp18; - - if (gResetTimer != 0 && D_8032C648 < 15) { - if (sCurrFBNum == 0) { - fbNum = 2; - } else { - fbNum = sCurrFBNum - 1; - } - - sp18 = (u64 *) PHYSICAL_TO_VIRTUAL(gPhysicalFrameBuffers[fbNum]); - sp18 += D_8032C648++ * (SCREEN_WIDTH / 4); - - for (sp24 = 0; sp24 < ((SCREEN_HEIGHT / 16) + 1); sp24++) { - // Must be on one line to match -O2 - for (sp20 = 0; sp20 < (SCREEN_WIDTH / 4); sp20++) *sp18++ = 0; - sp18 += ((SCREEN_WIDTH / 4) * 14); - } - } - - osWritebackDCacheAll(); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); -} +//void draw_reset_bars(void) { // TARGET_64 only +// Stubbed. Only N64 target uses this +// } void rendering_init(void) { gGfxPool = &gGfxPools[0]; @@ -626,16 +596,12 @@ void setup_game_memory(void) { load_segment_decompress(2, _segment2_mio0SegmentRomStart, _segment2_mio0SegmentRomEnd); } -#ifndef TARGET_N64 + static struct LevelCommand *levelCommandAddr; -#endif // main game loop thread. runs forever as long as the game // continues. void thread5_game_loop(UNUSED void *arg) { -#ifdef TARGET_N64 - struct LevelCommand *levelCommandAddr; -#endif setup_game_memory(); #ifdef VERSION_SH @@ -655,32 +621,21 @@ void thread5_game_loop(UNUSED void *arg) { play_music(SEQ_PLAYER_SFX, SEQUENCE_ARGS(0, SEQ_SOUND_PLAYER), 0); set_sound_mode(save_file_get_sound_mode()); -#ifdef TARGET_N64 - func_80247ED8(); - rendering_init(); - - while (1) { -#else gGlobalTimer++; } void game_loop_one_iteration(void) { -#endif // if the reset timer is active, run the process to reset the game. - if (gResetTimer) { + //if (gResetTimer) { +// draw_reset_bars(); (N64 target only?) +//} -#ifdef TARGET_N64 - draw_reset_bars(); - continue; -#else - return; -#endif - } profiler_log_thread5_time(THREAD5_START); // if any controllers are plugged in, start read the data for when // read_controller_inputs is called later. if (gControllerBits) { + #ifdef VERSION_SH block_until_rumble_pak_free(); #endif @@ -699,7 +654,5 @@ void game_loop_one_iteration(void) { // amount of free space remaining. print_text_fmt_int(180, 20, "BUF %d", gGfxPoolEnd - (u8 *) gDisplayListHead); } -#ifdef TARGET_N64 - } -#endif +// } was here for ifdef targ 64 } diff --git a/src/game/game_init.h b/src/game/game_init.h index 68db7426..10dd2f86 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -51,7 +51,7 @@ extern struct MarioAnimation gDemo; extern u8 gMarioAnims[]; extern u8 gDemoInputs[]; -#define GFX_POOL_SIZE 6400 +#define GFX_POOL_SIZE 64000 struct GfxPool { Gfx buffer[GFX_POOL_SIZE]; @@ -71,7 +71,7 @@ extern void clear_viewport(Vp *, s32); void make_viewport_clip_rect(Vp *viewport); extern void init_render_image(void); extern void end_master_display_list(void); -extern void draw_reset_bars(void); +//extern void draw_reset_bars(void); Target_64 only. Not used extern void rendering_init(void); extern void config_gfx_pool(void); extern void display_and_vsync(void); diff --git a/src/game/geo_misc.c b/src/game/geo_misc.c index af0cfa6f..afd5e289 100644 --- a/src/game/geo_misc.c +++ b/src/game/geo_misc.c @@ -46,11 +46,8 @@ s8 gFlyingCarpetState; * * Texture coordinates are s10.5 fixed-point, which means you should left-shift the actual coordinates by 5. */ -#ifdef TARGET_N64 -void make_vertex(Vtx *vtx, s32 n, s16 x, s16 y, s16 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a) { -#else void make_vertex(Vtx *vtx, s32 n, f32 x, f32 y, f32 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a) { -#endif + vtx[n].v.ob[0] = x; vtx[n].v.ob[1] = y; vtx[n].v.ob[2] = z; diff --git a/src/game/geo_misc.h b/src/game/geo_misc.h index 5646568d..fde7095e 100644 --- a/src/game/geo_misc.h +++ b/src/game/geo_misc.h @@ -12,15 +12,9 @@ enum FlyingCarpetState extern s8 gFlyingCarpetState; -#ifdef TARGET_N64 -extern void make_vertex( - Vtx *vtx, s32 n, s16 x, s16 y, s16 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a -); -#else extern void make_vertex( Vtx *vtx, s32 n, f32 x, f32 y, f32 z, s16 tx, s16 ty, u8 r, u8 g, u8 b, u8 a ); -#endif extern s16 round_float(f32); extern Gfx *geo_exec_inside_castle_light(s32 callContext, struct GraphNode *node, f32 mtx[4][4]); extern Gfx *geo_exec_flying_carpet_timer_update(s32 callContext, struct GraphNode *node, diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index bfcbf42b..f1336559 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -131,14 +131,7 @@ void create_dl_identity_matrix(void) { return; } -#ifdef TARGET_N64 - matrix->m[0][0] = 0x00010000; matrix->m[1][0] = 0x00000000; matrix->m[2][0] = 0x00000000; matrix->m[3][0] = 0x00000000; - matrix->m[0][1] = 0x00000000; matrix->m[1][1] = 0x00010000; matrix->m[2][1] = 0x00000000; matrix->m[3][1] = 0x00000000; - matrix->m[0][2] = 0x00000001; matrix->m[1][2] = 0x00000000; matrix->m[2][2] = 0x00000000; matrix->m[3][2] = 0x00000000; - matrix->m[0][3] = 0x00000000; matrix->m[1][3] = 0x00000001; matrix->m[2][3] = 0x00000000; matrix->m[3][3] = 0x00000000; -#else guMtxIdent(matrix); -#endif gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); @@ -1802,25 +1795,18 @@ void render_dialog_entries(void) { render_dialog_box_type(dialog, dialog->linesPerBox); gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, -#ifdef TARGET_N64 - ensure_nonnegative(dialog->leftOffset), -#else + 0, -#endif ensure_nonnegative(DIAG_VAL2 - dialog->width), #ifdef VERSION_EU -#ifdef TARGET_N64 - ensure_nonnegative(dialog->leftOffset + DIAG_VAL3 / gDialogBoxScale), -#else + SCREEN_WIDTH, -#endif + ensure_nonnegative((240 - dialog->width) + ((dialog->linesPerBox * 80) / DIAG_VAL4) / gDialogBoxScale)); #else -#ifdef TARGET_N64 - ensure_nonnegative(DIAG_VAL3 + dialog->leftOffset), -#else + SCREEN_WIDTH, -#endif + ensure_nonnegative(240 + ((dialog->linesPerBox * 80) / DIAG_VAL4) - dialog->width)); #endif #if defined(VERSION_JP) || defined(VERSION_SH) @@ -2133,12 +2119,9 @@ void shade_screen(void) { // This is a bit weird. It reuses the dialog text box (width 130, height -80), // so scale to at least fit the screen. -#ifdef TARGET_N64 - create_dl_scale_matrix(MENU_MTX_NOPUSH, 2.6f, 3.4f, 1.0f); -#else + create_dl_scale_matrix(MENU_MTX_NOPUSH, GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f); -#endif gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 110); gSPDisplayList(gDisplayListHead++, dl_draw_text_bg_box); diff --git a/src/game/macro_special_objects.c b/src/game/macro_special_objects.c index 63c63d3b..d9318971 100644 --- a/src/game/macro_special_objects.c +++ b/src/game/macro_special_objects.c @@ -328,7 +328,7 @@ void spawn_special_objects(s16 areaIndex, s16 **specialObjList) { } } -#ifndef TARGET_N64 +// PC Port, so always use below u32 get_special_objects_size(s16 *data) { s16 *startPos = data; s32 numOfSpecialObjects; @@ -372,4 +372,3 @@ u32 get_special_objects_size(s16 *data) { return data - startPos; } -#endif diff --git a/src/game/macro_special_objects.h b/src/game/macro_special_objects.h index 33fee18c..37851cc9 100644 --- a/src/game/macro_special_objects.h +++ b/src/game/macro_special_objects.h @@ -16,8 +16,6 @@ extern void spawn_macro_abs_special(u32 model, const BehaviorScript *behavior, s extern void spawn_macro_objects(s16 areaIndex, s16 * macroObjList); extern void spawn_macro_objects_hardcoded(s16 areaIndex, s16 * macroObjList); extern void spawn_special_objects(s16 areaIndex, s16 ** specialObjList); -#ifndef TARGET_N64 extern u32 get_special_objects_size(s16 *data); -#endif #endif /* MACRO_SPECIAL_OBJECTS_H */ diff --git a/src/game/memory.c b/src/game/memory.c index da4107fc..14c332cc 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -1,7 +1,5 @@ #include -#ifndef TARGET_N64 #include -#endif #include "sm64.h" @@ -78,27 +76,6 @@ void *get_segment_base_addr(s32 segment) { return (void *) (sSegmentTable[segment] | 0x80000000); } -#ifdef TARGET_N64 -void *segmented_to_virtual(const void *addr) { - size_t segment = (uintptr_t) addr >> 24; - size_t offset = (uintptr_t) addr & 0x00FFFFFF; - - return (void *) ((sSegmentTable[segment] + offset) | 0x80000000); -} - -void *virtual_to_segmented(u32 segment, const void *addr) { - size_t offset = ((uintptr_t) addr & 0x1FFFFFFF) - sSegmentTable[segment]; - - return (void *) ((segment << 24) + offset); -} - -void move_segment_table_to_dmem(void) { - s32 i; - - for (i = 0; i < 16; i++) - gSPSegment(gDisplayListHead++, i, sSegmentTable[i]); -} -#else void *segmented_to_virtual(const void *addr) { return (void *) addr; } @@ -109,7 +86,7 @@ void *virtual_to_segmented(u32 segment, const void *addr) { void move_segment_table_to_dmem(void) { } -#endif + /** * Initialize the main memory pool. This pool is conceptually a pair of stacks @@ -248,22 +225,8 @@ u32 main_pool_pop_state(void) { */ static void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) { u32 size = ALIGN16(srcEnd - srcStart); -#ifdef TARGET_N64 - osInvalDCache(dest, size); - while (size != 0) { - u32 copySize = (size >= 0x1000) ? 0x1000 : size; - osPiStartDma(&gDmaIoMesg, OS_MESG_PRI_NORMAL, OS_READ, (uintptr_t) srcStart, dest, copySize, - &gDmaMesgQueue); - osRecvMesg(&gDmaMesgQueue, &D_80339BEC, OS_MESG_BLOCK); - - dest += copySize; - srcStart += copySize; - size -= copySize; - } -#else memcpy(dest, srcStart, srcEnd - srcStart); -#endif } /** @@ -281,103 +244,6 @@ static void *dynamic_dma_read(u8 *srcStart, u8 *srcEnd, u32 side) { return dest; } -#ifdef TARGET_N64 -/** - * Load data from ROM into a newly allocated block, and set the segment base - * address to this block. - */ -void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side) { - void *addr = dynamic_dma_read(srcStart, srcEnd, side); - - if (addr != NULL) { - set_segment_base_addr(segment, addr); - } - return addr; -} - -/* - * Allocate a block of memory starting at destAddr and ending at the righthand - * end of the memory pool. Then copy srcStart through srcEnd from ROM to this - * block. - * If this block is not large enough to hold the ROM data, or that portion - * of the pool is already allocated, return NULL. - */ -void *load_to_fixed_pool_addr(u8 *destAddr, u8 *srcStart, u8 *srcEnd) { - void *dest = NULL; - u32 srcSize = ALIGN16(srcEnd - srcStart); - u32 destSize = ALIGN16((u8 *) sPoolListHeadR - destAddr); - - if (srcSize <= destSize) { - dest = main_pool_alloc(destSize, MEMORY_POOL_RIGHT); - if (dest != NULL) { - bzero(dest, destSize); - osWritebackDCacheAll(); - dma_read(dest, srcStart, srcEnd); - osInvalICache(dest, destSize); - osInvalDCache(dest, destSize); - } - } else { - } - return dest; -} - -/** - * Decompress the block of ROM data from srcStart to srcEnd and return a - * pointer to an allocated buffer holding the decompressed data. Set the - * base address of segment to this address. - */ -void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) { - void *dest = NULL; - - u32 compSize = ALIGN16(srcEnd - srcStart); - u8 *compressed = main_pool_alloc(compSize, MEMORY_POOL_RIGHT); - - // Decompressed size from mio0 header - u32 *size = (u32 *) (compressed + 4); - - if (compressed != NULL) { - dma_read(compressed, srcStart, srcEnd); - dest = main_pool_alloc(*size, MEMORY_POOL_LEFT); - if (dest != NULL) { - decompress(compressed, dest); - set_segment_base_addr(segment, dest); - main_pool_free(compressed); - } else { - } - } else { - } - return dest; -} - -void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd) { - UNUSED void *dest = NULL; - u32 compSize = ALIGN16(srcEnd - srcStart); - u8 *compressed = main_pool_alloc(compSize, MEMORY_POOL_RIGHT); - UNUSED u32 *pUncSize = (u32 *) (compressed + 4); - - if (compressed != NULL) { - dma_read(compressed, srcStart, srcEnd); - decompress(compressed, gDecompressionHeap); - set_segment_base_addr(segment, gDecompressionHeap); - main_pool_free(compressed); - } else { - } - return gDecompressionHeap; -} - -void load_engine_code_segment(void) { - void *startAddr = (void *) SEG_ENGINE; - u32 totalSize = SEG_FRAMEBUFFERS - SEG_ENGINE; - UNUSED u32 alignedSize = ALIGN16(_engineSegmentRomEnd - _engineSegmentRomStart); - - bzero(startAddr, totalSize); - osWritebackDCacheAll(); - dma_read(startAddr, _engineSegmentRomStart, _engineSegmentRomEnd); - osInvalICache(startAddr, totalSize); - osInvalDCache(startAddr, totalSize); -} -#endif - /** * Allocate an allocation-only pool from the main pool. This pool doesn't * support freeing allocated memory. diff --git a/src/game/memory.h b/src/game/memory.h index b392728e..0639ccef 100644 --- a/src/game/memory.h +++ b/src/game/memory.h @@ -37,19 +37,11 @@ u32 main_pool_available(void); u32 main_pool_push_state(void); u32 main_pool_pop_state(void); -#ifdef TARGET_N64 -void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side); -void *load_to_fixed_pool_addr(u8 *destAddr, u8 *srcStart, u8 *srcEnd); -void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd); -void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd); -void load_engine_code_segment(void); -#else #define load_segment(...) #define load_to_fixed_pool_addr(...) #define load_segment_decompress(...) #define load_segment_decompress_heap(...) #define load_engine_code_segment(...) -#endif struct AllocOnlyPool *alloc_only_pool_init(u32 size, u32 side); void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size); diff --git a/src/game/print.c b/src/game/print.c index 42395b5f..56ab66d3 100644 --- a/src/game/print.c +++ b/src/game/print.c @@ -366,29 +366,6 @@ void add_glyph_texture(s8 glyphIndex) { gSPDisplayList(gDisplayListHead++, dl_hud_img_load_tex_block); } -#ifdef TARGET_N64 -/** - * Clips textrect into the boundaries defined. - */ -void clip_to_bounds(s32 *x, s32 *y) { - if (*x < TEXRECT_MIN_X) { - *x = TEXRECT_MIN_X; - } - - if (*x > TEXRECT_MAX_X) { - *x = TEXRECT_MAX_X; - } - - if (*y < TEXRECT_MIN_Y) { - *y = TEXRECT_MIN_Y; - } - - if (*y > TEXRECT_MAX_Y) { - *y = TEXRECT_MAX_Y; - } -} -#endif - /** * Renders the glyph that's set at the given position. */ @@ -398,9 +375,6 @@ void render_textrect(s32 x, s32 y, s32 pos) { s32 rectX; s32 rectY; -#ifdef TARGET_N64 - clip_to_bounds(&rectBaseX, &rectBaseY); -#endif rectX = rectBaseX; rectY = rectBaseY; gSPTextureRectangle(gDisplayListHead++, rectX << 2, rectY << 2, (rectX + 15) << 2, diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 93a9a8a3..d83616d5 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -506,11 +506,7 @@ static void geo_process_background(struct GraphNodeBackground *node) { if (list != 0) { geo_append_display_list((void *) VIRTUAL_TO_PHYSICAL(list), node->fnNode.node.flags >> 8); } else if (gCurGraphNodeMasterList != NULL) { -#ifdef TARGET_N64 - Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 7); -#else Gfx *gfxStart = alloc_display_list(sizeof(Gfx) * 8); -#endif Gfx *gfx = gfxStart; gDPPipeSync(gfx++); @@ -757,9 +753,7 @@ static int obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { // the amount of units between the center of the screen and the horizontal edge // given the distance from the object to the camera. -#ifndef TARGET_N64 hScreenEdge *= GFX_DIMENSIONS_ASPECT_RATIO; -#endif if (geo != NULL && geo->type == GRAPH_NODE_TYPE_CULLING_RADIUS) { cullingRadius = diff --git a/src/game/screen_transition.c b/src/game/screen_transition.c index b0c14776..c009abea 100644 --- a/src/game/screen_transition.c +++ b/src/game/screen_transition.c @@ -241,13 +241,10 @@ int render_screen_transition(s8 fadeTimer, s8 transType, u8 transTime, struct Wa } Gfx *render_cannon_circle_base(void) { -#ifdef TARGET_N64 - Vtx *verts = alloc_display_list(4 * sizeof(*verts)); - Gfx *dlist = alloc_display_list(16 * sizeof(*dlist)); -#else + Vtx *verts = alloc_display_list(8 * sizeof(*verts)); Gfx *dlist = alloc_display_list(20 * sizeof(*dlist)); -#endif + Gfx *g = dlist; if (verts != NULL && dlist != NULL) { @@ -256,12 +253,10 @@ Gfx *render_cannon_circle_base(void) { make_vertex(verts, 2, SCREEN_WIDTH, SCREEN_HEIGHT, -1, 1152, 192, 0, 0, 0, 255); make_vertex(verts, 3, 0, SCREEN_HEIGHT, -1, -1152, 192, 0, 0, 0, 255); -#ifndef TARGET_N64 make_vertex(verts, 4, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 0, -1, 0, 0, 0, 0, 0, 255); make_vertex(verts, 5, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), 0, -1, 0, 0, 0, 0, 0, 255); make_vertex(verts, 6, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, 0, 0, 0, 255); make_vertex(verts, 7, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, 0, 0, 0, 255); -#endif gSPDisplayList(g++, dl_proj_mtx_fullscreen); gDPSetCombineMode(g++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); @@ -272,12 +267,12 @@ Gfx *render_cannon_circle_base(void) { gSPVertex(g++, VIRTUAL_TO_PHYSICAL(verts), 4, 0); gSPDisplayList(g++, dl_draw_quad_verts_0123); gSPTexture(g++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF); -#ifndef TARGET_N64 + gDPSetCombineMode(g++, G_CC_SHADE, G_CC_SHADE); gSPVertex(g++, VIRTUAL_TO_PHYSICAL(verts + 4), 4, 4); gSP2Triangles(g++, 4, 0, 3, 0, 4, 3, 7, 0); gSP2Triangles(g++, 1, 5, 6, 0, 1, 6, 2, 0); -#endif + gSPDisplayList(g++, dl_screen_transition_end); gSPEndDisplayList(g); } else { diff --git a/src/game/skybox.c b/src/game/skybox.c index 76f93201..d1f49908 100644 --- a/src/game/skybox.c +++ b/src/game/skybox.c @@ -242,7 +242,6 @@ void *create_skybox_ortho_matrix(s8 player) { f32 top = sSkyBoxInfo[player].scaledY; Mtx *mtx = alloc_display_list(sizeof(*mtx)); -#ifndef TARGET_N64 f32 half_width = (4.0f / 3.0f) / GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_WIDTH / 2; f32 center = (sSkyBoxInfo[player].scaledX + SCREEN_WIDTH / 2); if (half_width < SCREEN_WIDTH / 2) { @@ -250,7 +249,6 @@ void *create_skybox_ortho_matrix(s8 player) { left = center - half_width; right = center + half_width; } -#endif if (mtx != NULL) { guOrtho(mtx, left, right, bottom, top, 0.0f, 3.0f, 1.0f); diff --git a/src/goddard/renderer.c b/src/goddard/renderer.c index b5b7fafb..6264bb66 100644 --- a/src/goddard/renderer.c +++ b/src/goddard/renderer.c @@ -27,15 +27,9 @@ #define MAX_GD_DLS 1000 #define OS_MESG_SI_COMPLETE 0x33333333 -#ifdef TARGET_N64 -#define GD_VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) &0x0FFFFFFF) -#define GD_LOWER_24(addr) ((uintptr_t)(addr) &0x00FFFFFF) -#define GD_LOWER_29(addr) (((uintptr_t)(addr)) & 0x1FFFFFFF) -#else #define GD_VIRTUAL_TO_PHYSICAL(addr) (addr) #define GD_LOWER_24(addr) ((uintptr_t)(addr)) #define GD_LOWER_29(addr) (((uintptr_t)(addr))) -#endif #define MTX_INTPART_PACK(w1, w2) (((w1) &0xFFFF0000) | (((w2) >> 16) & 0xFFFF)) #define MTX_FRACPART_PACK(w1, w2) ((((w1) << 16) & 0xFFFF0000) | ((w2) &0xFFFF)) @@ -1691,27 +1685,9 @@ u32 Unknown8019EC88(Gfx *dl, UNUSED s32 arg1) { /* 24D4C4 -> 24D63C; orig name: func_8019ECF4 */ void mat4_to_mtx(const Mat4f *src, Mtx *dst) { -#ifdef TARGET_N64 - s32 i; // 14 - s32 j; // 10 - s32 w1; - s32 w2; - s32 *mtxInt = (s32 *) dst->m[0]; // s32 part - s32 *mtxFrc = (s32 *) dst->m[2]; // frac part - for (i = 0; i < 4; i++) { - for (j = 0; j < 2; j++) { - w1 = (s32)((*src)[i][j * 2] * 65536.0f); - w2 = (s32)((*src)[i][j * 2 + 1] * 65536.0f); - *mtxInt = MTX_INTPART_PACK(w1, w2); - mtxInt++; - *mtxFrc = MTX_FRACPART_PACK(w1, w2); - mtxFrc++; - } - } -#else guMtxF2L(src, dst); -#endif + } /* 24D63C -> 24D6E4; orig name: func_8019EE6C */ @@ -3632,89 +3608,9 @@ void Unknown801A6E30(UNUSED u32 a0) { void Unknown801A6E44(UNUSED u32 a0) { } -#ifdef TARGET_N64 -/* 255628 -> 255704; orig name: func_801A6E58 */ -void gd_block_dma(u32 devAddr, void *vAddr, s32 size) { - s32 transfer; // 2c - - do { - if ((transfer = size) > 0x1000) { - transfer = 0x1000; - } - - osPiStartDma(&D_801BE980, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, transfer, &sGdDMAQueue); - osRecvMesg(&sGdDMAQueue, &D_801BE97C, OS_MESG_BLOCK); - devAddr += transfer; - vAddr = (void *) ((uintptr_t) vAddr + transfer); - size -= 0x1000; - } while (size > 0); -} - -/* 255704 -> 255988 */ -struct GdObj *load_dynlist(struct DynList *dynlist) { - u32 segSize; // 4c - u8 *allocSegSpace; // 48 - void *allocPtr; // 44 - uintptr_t dynlistSegStart; // 40 - uintptr_t dynlistSegEnd; // 3c - s32 i; // 38 - s32 sp34; // tlbPage - struct GdObj *loadedList; // 30 - - i = -1; - - while (sDynLists[++i].list != NULL) { - if (sDynLists[i].list == dynlist) { - break; - } - } - - if (sDynLists[i].list == NULL) { - fatal_printf("load_dynlist() ptr not found in any banks"); - } - - switch (sDynLists[i].flag) { - case STD_LIST_BANK: - dynlistSegStart = (uintptr_t) _gd_dynlistsSegmentRomStart; - dynlistSegEnd = (uintptr_t) _gd_dynlistsSegmentRomEnd; - break; - default: - fatal_printf("load_dynlist() unkown bank"); - } - - segSize = dynlistSegEnd - dynlistSegStart; - allocSegSpace = gd_malloc_temp(segSize + 0x10000); - - if ((allocPtr = (void *) allocSegSpace) == NULL) { - fatal_printf("Not enough DRAM for DATA segment \n"); - } - - allocSegSpace = (u8 *) (((uintptr_t) allocSegSpace + 0x10000) & 0xFFFF0000); - gd_block_dma(dynlistSegStart, (void *) allocSegSpace, segSize); - osUnmapTLBAll(); - - sp34 = (segSize / 0x10000) / 2 + 1; //? has to be written this way - if (sp34 >= 31) { - fatal_printf("load_dynlist() too many TLBs"); - } - - for (i = 0; i < sp34; i++) { - osMapTLB(i, OS_PM_64K, (void *) (uintptr_t) (0x04000000 + (i * 2 * 0x10000)), - GD_LOWER_24(((uintptr_t) allocSegSpace) + (i * 2 * 0x10000)), - GD_LOWER_24(((uintptr_t) allocSegSpace) + (i * 2 * 0x10000) + 0x10000), -1); - } - - loadedList = proc_dynlist(dynlist); - gd_free(allocPtr); - osUnmapTLBAll(); - - return loadedList; -} -#else struct GdObj *load_dynlist(struct DynList *dynlist) { return proc_dynlist(dynlist); } -#endif /* 255988 -> 25599C */ void stub_801A71B8(UNUSED u32 a0) { diff --git a/src/goddard/skin.c b/src/goddard/skin.c index 5223c246..59779177 100644 --- a/src/goddard/skin.c +++ b/src/goddard/skin.c @@ -303,9 +303,7 @@ void convert_gd_verts_to_Vn(struct ObjGroup *grp) { u8 nx, ny, nz; // 24, 25, 26 UNUSED u32 pad20; register struct VtxLink *vtxlink; // a1 -#ifdef TARGET_N64 - register s16 *vnPos; // a2 -#endif + register s16 x; // a3 register s16 y; // t0 register s16 z; // t1 @@ -325,18 +323,12 @@ void convert_gd_verts_to_Vn(struct ObjGroup *grp) { nz = (u8)(vtx->normal.z * 255.0f); for (vtxlink = vtx->gbiVerts; vtxlink != NULL; vtxlink = vtxlink->prev) { -#ifdef TARGET_N64 - vnPos = vtxlink->data->n.ob; - vn = vtxlink->data; - *vnPos++ = x; - *vnPos++ = y; - *vnPos++ = z; -#else + vn = vtxlink->data; vn->n.ob[0] = x; vn->n.ob[1] = y; vn->n.ob[2] = z; -#endif + vn->n.n[0] = nx; vn->n.n[1] = ny; vn->n.n[2] = nz; @@ -348,9 +340,7 @@ void convert_gd_verts_to_Vn(struct ObjGroup *grp) { void convert_gd_verts_to_Vtx(struct ObjGroup *grp) { UNUSED u32 pad24[6]; register struct VtxLink *vtxlink; // a1 -#ifdef TARGET_N64 - register s16 *vtxcoords; // a2 -#endif + register s16 x; // a3 register s16 y; // t0 register s16 z; // t1 @@ -366,16 +356,10 @@ void convert_gd_verts_to_Vtx(struct ObjGroup *grp) { z = (s16) vtx->pos.z; for (vtxlink = vtx->gbiVerts; vtxlink != NULL; vtxlink = vtxlink->prev) { -#ifdef TARGET_N64 - vtxcoords = vtxlink->data->v.ob; - vtxcoords[0] = x; - vtxcoords[1] = y; - vtxcoords[2] = z; -#else + vtxlink->data->v.ob[0] = x; vtxlink->data->v.ob[1] = y; vtxlink->data->v.ob[2] = z; -#endif } } } From 829c1f29a8a7b5626a343ba26bcd499e51b56c94 Mon Sep 17 00:00:00 2001 From: Hyenadae Date: Thu, 14 May 2020 05:18:12 -0400 Subject: [PATCH 02/16] Fixed more border-related code and fixes to N64 build removal --- Makefile | 38 ++++++++++++++++++-------------------- include/config.h | 9 ++------- include/gfx_dimensions.h | 4 ++-- src/game/game_init.c | 8 +++++--- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index d4bd2846..b3bafd9a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ + # Makefile to rebuild SM64 split image ### Default target ### @@ -23,7 +24,7 @@ TARGET_N64 = 0 # Build and optimize for Raspberry Pi(s) TARGET_RPI ?= 0 # Compiler to use (ido or gcc) -COMPILER ?= ido +# COMPILER ?= ido // Old Default # Disable better camera by default BETTERCAMERA ?= 0 @@ -224,10 +225,6 @@ GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists MIPSISET := -mips2 MIPSBIT := -32 -ifeq ($(COMPILER),gcc) - MIPSISET := -mips3 -endif - ifeq ($(VERSION),eu) OPT_FLAGS := -O2 else @@ -246,9 +243,8 @@ ifeq ($(TARGET_WEB),1) endif # Use a default opt flag for gcc, then override if RPi -ifeq ($(COMPILER),gcc) -OPT_FLAGS := -O2 # Breaks sound on x86? -endif + +# OPT_FLAGS := -O2 # "Whole-compile optimization flag" Breaks sound on x86. ifeq ($(TARGET_RPI),1) machine = $(shell sh -c 'uname -m 2>/dev/null || echo unknown') @@ -424,14 +420,15 @@ else LD := $(CC) endif -CPP := cpp -P -OBJDUMP := objdump -OBJCOPY := objcopy +CPP := $(CROSS)cpp -P +OBJDUMP := $(CROSS)objdump +OBJCOPY := $(CROSS)objcopy PYTHON := python3 +SDLCONFIG := $(CROSS)sdl2-config ifeq ($(WINDOWS_BUILD),1) -CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(CROSS)sdl2-config --cflags` -CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(CROSS)sdl2-config --cflags` +CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` +CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` else ifeq ($(TARGET_WEB),1) CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2 @@ -439,8 +436,8 @@ CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fn # Linux / Other builds below else -CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(CROSS)sdl2-config --cflags` -CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(CROSS)sdl2-config --cflags` +CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` +CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` endif # Check for better camera option @@ -456,14 +453,17 @@ LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY=20MB -g4 --source-map-base ht else ifeq ($(WINDOWS_BUILD),1) -LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread -lglew32 `$(CROSS)sdl2-config --static-libs` -lm -lglu32 -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -lopengl32 -no-pie -static +LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread -lglew32 `$(SDLCONFIG) --static-libs` -lm -lglu32 -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -lopengl32 -no-pie -static +ifeq ($(WINDOWS_CONSOLE),1) +LDFLAGS += -mconsole +endif else # Linux / Other builds below ifeq ($(TARGET_RPI),1) -LDFLAGS := $(OPT_FLAGS) -lm -lGLESv2 `$(CROSS)sdl2-config --libs` -no-pie +LDFLAGS := $(OPT_FLAGS) -lm -lGLESv2 `$(SDLCONFIG) --libs` -no-pie else -LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(CROSS)sdl2-config --libs` -no-pie -lpthread +LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm -lGL `$(SDLCONFIG) --libs` -no-pie -lpthread endif endif endif #Added for Pi ifeq @@ -676,7 +676,6 @@ $(BUILD_DIR)/assets/mario_anim_data.c: $(wildcard assets/anims/*.inc.c) $(BUILD_DIR)/assets/demo_data.c: assets/demo_data.json $(wildcard assets/demos/*.bin) $(PYTHON) tools/demo_data_converter.py assets/demo_data.json $(VERSION_CFLAGS) > $@ -ifeq ($(COMPILER),ido) # Source code $(BUILD_DIR)/levels/%/leveldata.o: OPT_FLAGS := -g $(BUILD_DIR)/actors/%.o: OPT_FLAGS := -g @@ -718,7 +717,6 @@ $(BUILD_DIR)/src/audio/%.acpp: src/audio/%.c $(BUILD_DIR)/src/audio/%.copt: $(BUILD_DIR)/src/audio/%.acpp $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/copt -signed -I=$< -CMP=$@ -cp=i -scalaroptimize=1 endif -endif # Rebuild files with 'GLOBAL_ASM' if the NON_MATCHING flag changes. diff --git a/include/config.h b/include/config.h index db50b1cc..23a317e8 100644 --- a/include/config.h +++ b/include/config.h @@ -28,12 +28,7 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -// Border Height Define for NTSC Versions - -#define BORDER_HEIGHT 1 - -#else -// What's the point of having a border? -#define BORDER_HEIGHT 0 +// What's the point of having a border if we're not an N64? +#define BORDER_HEIGHT 0 // Never use a border as not-N64 #endif diff --git a/include/gfx_dimensions.h b/include/gfx_dimensions.h index cae20701..f3a5ee23 100644 --- a/include/gfx_dimensions.h +++ b/include/gfx_dimensions.h @@ -5,8 +5,8 @@ #include "pc/gfx/gfx_pc.h" #define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * gfx_current_dimensions.aspect_ratio + (v)) #define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH / 2 + SCREEN_HEIGHT / 2 * gfx_current_dimensions.aspect_ratio - (v)) -#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v)) -#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v)) +#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) ((int)floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v))) +#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ((int)ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v))) #define GFX_DIMENSIONS_ASPECT_RATIO (gfx_current_dimensions.aspect_ratio) #endif diff --git a/src/game/game_init.c b/src/game/game_init.c index 8834fc8b..ffcf7a18 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -3,6 +3,7 @@ #include "sm64.h" #include "audio/external.h" #include "buffers/buffers.h" +#include "gfx_dimensions.h" #include "buffers/gfx_output_buffer.h" #include "buffers/framebuffers.h" #include "buffers/zbuffer.h" @@ -152,8 +153,9 @@ void clear_frame_buffer(s32 a) { gDPSetCycleType(gDisplayListHead++, G_CYC_FILL); gDPSetFillColor(gDisplayListHead++, a); - gDPFillRectangle(gDisplayListHead++, 0, BORDER_HEIGHT, SCREEN_WIDTH - 1, - SCREEN_HEIGHT - 1 - BORDER_HEIGHT); + + // Ratio-correct borderfill + gDPFillRectangle(gDisplayListHead++, GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(0), BORDER_HEIGHT, GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(0) - 1, SCREEN_HEIGHT - BORDER_HEIGHT - 1); gDPPipeSync(gDisplayListHead++); @@ -495,7 +497,7 @@ void read_controller_inputs(void) { controller->stickMag = 0; } } - + } #else for (i = 0; i < 2; i++) { From 1a3034898cda792c65e628da38bcd902003f8d30 Mon Sep 17 00:00:00 2001 From: Heaven Volkoff Date: Sat, 16 May 2020 04:48:11 -0300 Subject: [PATCH 03/16] Consider second color column of Light_t when calculating vertex colors --- src/pc/gfx/gfx_pc.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d674a4d6..8d03cffa 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -569,10 +569,16 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti calculate_normal_dir(&lookat_y, rsp.current_lookat_coeffs[1]); rsp.lights_changed = false; } - - int r = rsp.current_lights[rsp.current_num_lights - 1].col[0]; - int g = rsp.current_lights[rsp.current_num_lights - 1].col[1]; - int b = rsp.current_lights[rsp.current_num_lights - 1].col[2]; + + // Inspired by: + // https://github.com/gonetz/GLideN64/commit/c8cbafff71a81bee5112aaafe6e21d6648ff8125#diff-69d8715ec7f9fd627ec4f5516edd003dL484 + const bool useFirstColor = (dest_index & 1) == 0; + const unsigned char* col = useFirstColor + ? rsp.current_lights[rsp.current_num_lights - 1].col + : rsp.current_lights[rsp.current_num_lights - 1].colc; + int r = col[0]; + int g = col[1]; + int b = col[2]; for (int i = 0; i < rsp.current_num_lights - 1; i++) { float intensity = 0; @@ -581,9 +587,14 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti intensity += vn->n[2] * rsp.current_lights_coeffs[i][2]; intensity /= 127.0f; if (intensity > 0.0f) { - r += intensity * rsp.current_lights[i].col[0]; - g += intensity * rsp.current_lights[i].col[1]; - b += intensity * rsp.current_lights[i].col[2]; + // Inspired by: + // https://github.com/gonetz/GLideN64/commit/c8cbafff71a81bee5112aaafe6e21d6648ff8125#diff-69d8715ec7f9fd627ec4f5516edd003dL492 + col = useFirstColor + ? rsp.current_lights[i].col + : rsp.current_lights[i].colc; + r += intensity * col[0]; + g += intensity * col[1]; + b += intensity * col[2]; } } From f4a3757145a508fa9338562b6524f488b0a0c492 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 16:16:44 -0300 Subject: [PATCH 04/16] Further fixes to MXE compilation Adds on the work of PR #130. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91049539..a0dd34c5 100644 --- a/Makefile +++ b/Makefile @@ -423,7 +423,13 @@ else endif ifeq ($(WINDOWS_BUILD),1) - LD := $(CXX) + ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL + LD := $(CC) + else ifeq ($(CROSS),x86_64-w64-mingw32.static-) + LD := $(CC) + else + LD := $(CXX) + endif else LD := $(CC) endif From 9e8290773b29a2cf515f65b2f4997d0e79d57bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sat, 16 May 2020 16:23:23 -0300 Subject: [PATCH 05/16] Shutdown subsystems on exit Porting from testing, originally by @fgsfdsfgs --- src/pc/audio/audio_api.h | 1 + src/pc/audio/audio_null.c | 8 ++++++-- src/pc/audio/audio_sdl.c | 14 +++++++++++++- src/pc/controller/controller_api.h | 4 ++++ src/pc/controller/controller_entry_point.c | 7 +++++++ src/pc/controller/controller_keyboard.c | 4 ++++ src/pc/controller/controller_recorded_tas.c | 8 ++++++++ src/pc/controller/controller_sdl.c | 12 ++++++++++++ src/pc/gfx/gfx_opengl.c | 6 +++++- src/pc/gfx/gfx_pc.c | 11 +++++++++++ src/pc/gfx/gfx_pc.h | 1 + src/pc/gfx/gfx_rendering_api.h | 1 + src/pc/gfx/gfx_sdl2.c | 13 ++++++++++++- src/pc/gfx/gfx_window_manager_api.h | 1 + src/pc/pc_main.c | 20 +++++++++++++++----- 15 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/pc/audio/audio_api.h b/src/pc/audio/audio_api.h index 26794dd6..b40130e0 100644 --- a/src/pc/audio/audio_api.h +++ b/src/pc/audio/audio_api.h @@ -10,6 +10,7 @@ struct AudioAPI { int (*buffered)(void); int (*get_desired_buffered)(void); void (*play)(const uint8_t *buf, size_t len); + void (*shutdown)(void); }; #endif diff --git a/src/pc/audio/audio_null.c b/src/pc/audio/audio_null.c index 8a244e4b..4d0dd923 100644 --- a/src/pc/audio/audio_null.c +++ b/src/pc/audio/audio_null.c @@ -15,9 +15,13 @@ static int audio_null_get_desired_buffered(void) { static void audio_null_play(const uint8_t *buf, size_t len) { } +static void audio_null_shutdown(void) { +} + struct AudioAPI audio_null = { audio_null_init, audio_null_buffered, audio_null_get_desired_buffered, - audio_null_play -}; + audio_null_play, + audio_null_shutdown +}; \ No newline at end of file diff --git a/src/pc/audio/audio_sdl.c b/src/pc/audio/audio_sdl.c index 2f13ccde..beb5a1e6 100644 --- a/src/pc/audio/audio_sdl.c +++ b/src/pc/audio/audio_sdl.c @@ -40,9 +40,21 @@ static void audio_sdl_play(const uint8_t *buf, size_t len) { } } +static void audio_sdl_shutdown(void) +{ + if (SDL_WasInit(SDL_INIT_AUDIO)) { + if (dev != 0) { + SDL_CloseAudioDevice(dev); + dev = 0; + } + SDL_QuitSubSystem(SDL_INIT_AUDIO); + } +} + struct AudioAPI audio_sdl = { audio_sdl_init, audio_sdl_buffered, audio_sdl_get_desired_buffered, - audio_sdl_play + audio_sdl_play, + audio_sdl_shutdown }; \ No newline at end of file diff --git a/src/pc/controller/controller_api.h b/src/pc/controller/controller_api.h index fdd6e503..2f9c1d16 100644 --- a/src/pc/controller/controller_api.h +++ b/src/pc/controller/controller_api.h @@ -13,10 +13,14 @@ struct ControllerAPI { void (*read)(OSContPad *pad); // read controller and update N64 pad values u32 (*rawkey)(void); // returns last pressed virtual key or VK_INVALID if none void (*reconfig)(void); // (optional) call when bindings have changed + void (*shutdown)(void); // (optional) call in osContReset }; // used for binding keys u32 controller_get_raw_key(void); void controller_reconfigure(void); +// calls the shutdown() function of all controller subsystems +void controller_shutdown(void); + #endif diff --git a/src/pc/controller/controller_entry_point.c b/src/pc/controller/controller_entry_point.c index 536b0798..90c10c1d 100644 --- a/src/pc/controller/controller_entry_point.c +++ b/src/pc/controller/controller_entry_point.c @@ -65,6 +65,13 @@ u32 controller_get_raw_key(void) { return VK_INVALID; } +void controller_shutdown(void) { + for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) { + if (controller_implementations[i]->shutdown) + controller_implementations[i]->shutdown(); + } +} + void controller_reconfigure(void) { for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) { if (controller_implementations[i]->reconfig) diff --git a/src/pc/controller/controller_keyboard.c b/src/pc/controller/controller_keyboard.c index c9421a24..9fb4b635 100644 --- a/src/pc/controller/controller_keyboard.c +++ b/src/pc/controller/controller_keyboard.c @@ -107,10 +107,14 @@ static u32 keyboard_rawkey(void) { return ret; } +static void keyboard_shutdown(void) { +} + struct ControllerAPI controller_keyboard = { VK_BASE_KEYBOARD, keyboard_init, keyboard_read, keyboard_rawkey, keyboard_bindkeys, + keyboard_shutdown }; diff --git a/src/pc/controller/controller_recorded_tas.c b/src/pc/controller/controller_recorded_tas.c index f05c0558..2fcd5b54 100644 --- a/src/pc/controller/controller_recorded_tas.c +++ b/src/pc/controller/controller_recorded_tas.c @@ -23,6 +23,13 @@ static void tas_read(OSContPad *pad) { } } +static void tas_shutdown(void) { + if (fp != NULL) { + fclose(fp); + fp = NULL; + } +} + static u32 tas_rawkey(void) { return VK_INVALID; } @@ -33,4 +40,5 @@ struct ControllerAPI controller_recorded_tas = { tas_read, tas_rawkey, NULL, // no rebinding + tas_shutdown }; diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 171a31f4..62aa2acf 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -204,10 +204,22 @@ static u32 controller_sdl_rawkey(void) { return VK_INVALID; } +static void controller_sdl_shutdown(void) { + if (SDL_WasInit(SDL_INIT_GAMECONTROLLER)) { + if (sdl_cntrl) { + SDL_GameControllerClose(sdl_cntrl); + sdl_cntrl = NULL; + } + SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER); + } + init_ok = false; +} + struct ControllerAPI controller_sdl = { VK_BASE_SDL_GAMEPAD, controller_sdl_init, controller_sdl_read, controller_sdl_rawkey, controller_sdl_bind, + controller_sdl_shutdown }; diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c index b7067e91..b283b7e2 100644 --- a/src/pc/gfx/gfx_opengl.c +++ b/src/pc/gfx/gfx_opengl.c @@ -481,6 +481,9 @@ static void gfx_opengl_start_frame(void) { glEnable(GL_SCISSOR_TEST); } +static void gfx_opengl_shutdown(void) { +} + struct GfxRenderingAPI gfx_opengl_api = { gfx_opengl_z_is_from_0_to_1, gfx_opengl_unload_shader, @@ -500,5 +503,6 @@ struct GfxRenderingAPI gfx_opengl_api = { gfx_opengl_set_use_alpha, gfx_opengl_draw_triangles, gfx_opengl_init, - gfx_opengl_start_frame + gfx_opengl_start_frame, + gfx_opengl_shutdown }; diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 7052ad60..67c45ecb 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -1547,3 +1547,14 @@ void gfx_end_frame(void) { gfx_wapi->swap_buffers_end(); } } + +void gfx_shutdown(void) { + if (gfx_rapi) { + if (gfx_rapi->shutdown) gfx_rapi->shutdown(); + gfx_rapi = NULL; + } + if (gfx_wapi) { + if (gfx_wapi->shutdown) gfx_wapi->shutdown(); + gfx_wapi = NULL; + } +} \ No newline at end of file diff --git a/src/pc/gfx/gfx_pc.h b/src/pc/gfx/gfx_pc.h index 6903597c..8d62e2b7 100644 --- a/src/pc/gfx/gfx_pc.h +++ b/src/pc/gfx/gfx_pc.h @@ -15,5 +15,6 @@ void gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi); void gfx_start_frame(void); void gfx_run(Gfx *commands); void gfx_end_frame(void); +void gfx_shutdown(void); #endif diff --git a/src/pc/gfx/gfx_rendering_api.h b/src/pc/gfx/gfx_rendering_api.h index 58d79435..75aedef9 100644 --- a/src/pc/gfx/gfx_rendering_api.h +++ b/src/pc/gfx/gfx_rendering_api.h @@ -27,6 +27,7 @@ struct GfxRenderingAPI { void (*draw_triangles)(float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris); void (*init)(void); void (*start_frame)(void); + void (*shutdown)(void); }; #endif diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index e7018476..57ff486d 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -24,6 +24,7 @@ #include "src/pc/controller/controller_keyboard.h" static SDL_Window *wnd; +static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; static bool cur_fullscreen; @@ -235,6 +236,15 @@ static double gfx_sdl_get_time(void) { return 0.0; } + +static void gfx_sdl_shutdown(void) { + if (SDL_WasInit(0)) { + if (ctx) { SDL_GL_DeleteContext(ctx); ctx = NULL; } + if (wnd) { SDL_DestroyWindow(wnd); wnd = NULL; } + SDL_Quit(); + } +} + struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init, gfx_sdl_main_loop, @@ -243,5 +253,6 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_start_frame, gfx_sdl_swap_buffers_begin, gfx_sdl_swap_buffers_end, - gfx_sdl_get_time + gfx_sdl_get_time, + gfx_sdl_shutdown }; diff --git a/src/pc/gfx/gfx_window_manager_api.h b/src/pc/gfx/gfx_window_manager_api.h index 9c68cd10..45826711 100644 --- a/src/pc/gfx/gfx_window_manager_api.h +++ b/src/pc/gfx/gfx_window_manager_api.h @@ -13,6 +13,7 @@ struct GfxWindowManagerAPI { void (*swap_buffers_begin)(void); void (*swap_buffers_end)(void); double (*get_time)(void); // For debug + void (*shutdown)(void); }; #endif diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 52d8339b..93774fe2 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -84,6 +84,20 @@ void produce_one_frame(void) { gfx_end_frame(); } +void audio_shutdown(void) { + if (audio_api) { + if (audio_api->shutdown) audio_api->shutdown(); + audio_api = NULL; + } +} + +void game_shutdown(void) { + configfile_save(CONFIG_FILE); + controller_shutdown(); + audio_shutdown(); + gfx_shutdown(); +} + #ifdef TARGET_WEB static void em_main_loop(void) { } @@ -117,17 +131,13 @@ static void on_anim_frame(double time) { } #endif -static void save_config(void) { - configfile_save(CONFIG_FILE); -} - void main_func(void) { static u64 pool[0x165000/8 / 4 * sizeof(void *)]; main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0])); gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); configfile_load(CONFIG_FILE); - atexit(save_config); + atexit(game_shutdown); #ifdef TARGET_WEB emscripten_set_main_loop(em_main_loop, 0, 0); From f6642e9a9d32836cc52071ba12e953c4023018c5 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sat, 16 May 2020 22:39:37 +0300 Subject: [PATCH 06/16] tabs begone --- src/pc/gfx/gfx_pc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 67d8e1ec..3b11a46c 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -575,7 +575,7 @@ static void gfx_sp_vertex(size_t n_vertices, size_t dest_index, const Vtx *verti // Inspired by: // https://github.com/gonetz/GLideN64/commit/c8cbafff71a81bee5112aaafe6e21d6648ff8125#diff-69d8715ec7f9fd627ec4f5516edd003dL484 const bool useFirstColor = (dest_index & 1) == 0; - const unsigned char* col = useFirstColor + const unsigned char* col = useFirstColor ? rsp.current_lights[rsp.current_num_lights - 1].col : rsp.current_lights[rsp.current_num_lights - 1].colc; int r = col[0]; From 3d7bdc300cd5c818ee7c677d4ef9718ddfe0402d Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 17:12:56 -0300 Subject: [PATCH 07/16] Add NO_BZERO for MXE --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index a0dd34c5..ece07b95 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ TARGET_N64 = 0 # Build and optimize for Raspberry Pi(s) TARGET_RPI ?= 0 +# No BZERO (for building under MXE) +NO_BZERO ?= 0 # Compiler to use (ido or gcc) COMPILER ?= ido @@ -461,6 +463,12 @@ endif # Check for enhancement options +# Check for no bzero option +ifeq ($(NO_BZERO),1) +CC_CHECK += -DNO_BZERO +CFLAGS += -DNO_BZERO +endif + # Check for Puppycam option ifeq ($(BETTERCAMERA),1) CC_CHECK += -DBETTERCAMERA From e42e1587b24c7042de03cf00a715f6fcbd4a8fb4 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 17:14:10 -0300 Subject: [PATCH 08/16] MXE fix for os_libc.h --- include/PR/os_libc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h index 94111c0b..13ec2124 100644 --- a/include/PR/os_libc.h +++ b/include/PR/os_libc.h @@ -4,7 +4,13 @@ #include "ultratypes.h" // Old deprecated functions from strings.h, replaced by memcpy/memset. +#ifdef NO_BZERO +#include +#define bzero(buf, size) memset(buf, 0, size) +#define bcopy(src, dst, size) memcpy(dst, src, size) +#else extern void bcopy(const void *, void *, size_t); extern void bzero(void *, size_t); +#endif #endif /* !_OS_LIBC_H_ */ From 8736776545859a9dd6bb33fd4022d1bc598c8dbb Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 17:20:33 -0300 Subject: [PATCH 09/16] Another fix to MXE --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index ece07b95..5903e52f 100644 --- a/Makefile +++ b/Makefile @@ -450,6 +450,12 @@ SDLCONFIG := $(CROSS)sdl2-config ifeq ($(WINDOWS_BUILD),1) CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` + ifeq ($(CROSS),i686-w64-mingw32.static-) + ifeq ($(CROSS),x86_64-w64-mingw32.static-) + CC_CHECK += D_NOBZERO + CFLAGS += D_NOBZERO + endif + endif else ifeq ($(TARGET_WEB),1) CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2 From 385e396feb6d6afd4d71d096ddb9378425206402 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 17:21:59 -0300 Subject: [PATCH 10/16] fix the MXE fix for os_libc.h --- include/PR/os_libc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h index 13ec2124..4c2fc3e1 100644 --- a/include/PR/os_libc.h +++ b/include/PR/os_libc.h @@ -6,8 +6,8 @@ // Old deprecated functions from strings.h, replaced by memcpy/memset. #ifdef NO_BZERO #include -#define bzero(buf, size) memset(buf, 0, size) -#define bcopy(src, dst, size) memcpy(dst, src, size) +#define bzero(buf, size) memset((buf), 0, (size)) +#define bcopy(src, dst, size) memcpy((dst), (src), (size)) #else extern void bcopy(const void *, void *, size_t); extern void bzero(void *, size_t); From 69ff11e459e237998725b0bda05754908eb0503e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sat, 16 May 2020 17:57:40 -0300 Subject: [PATCH 11/16] Add support for saves of both endiannesses. Porting from testing. Originally by @fgsfdsfgs. --- src/game/save_file.c | 119 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 111 insertions(+), 8 deletions(-) diff --git a/src/game/save_file.c b/src/game/save_file.c index 6803fb69..b5112eb5 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -15,6 +15,12 @@ #define MENU_DATA_MAGIC 0x4849 #define SAVE_FILE_MAGIC 0x4441 +#define BSWAP16(x) \ + ( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) ) +#define BSWAP32(x) \ + ( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \ + (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) ) + STATIC_ASSERT(sizeof(struct SaveBuffer) == EEPROM_SIZE, "eeprom buffer size must match"); extern struct SaveBuffer gSaveBuffer; @@ -50,6 +56,38 @@ static void stub_save_file_1(void) { UNUSED s32 pad; } +/** + * Byteswap all multibyte fields in a SaveBlockSignature. + */ +static inline void bswap_signature(struct SaveBlockSignature *data) { + data->magic = BSWAP16(data->magic); + data->chksum = BSWAP16(data->chksum); // valid as long as the checksum is a literal sum +} + +/** + * Byteswap all multibyte fields in a MainMenuSaveData. + */ +static inline void bswap_menudata(struct MainMenuSaveData *data) { + for (int i = 0; i < NUM_SAVE_FILES; ++i) + data->coinScoreAges[i] = BSWAP32(data->coinScoreAges[i]); + data->soundMode = BSWAP16(data->soundMode); +#ifdef VERSION_EU + data->language = BSWAP16(data->language); +#endif + bswap_signature(&data->signature); +} + +/** + * Byteswap all multibyte fields in a SaveFile. + */ +static inline void bswap_savefile(struct SaveFile *data) { + data->capPos[0] = BSWAP16(data->capPos[0]); + data->capPos[1] = BSWAP16(data->capPos[1]); + data->capPos[2] = BSWAP16(data->capPos[2]); + data->flags = BSWAP32(data->flags); + bswap_signature(&data->signature); +} + /** * Read from EEPROM to a given address. * The EEPROM address is computed using the offset of the destination address from gSaveBuffer. @@ -80,16 +118,16 @@ static s32 read_eeprom_data(void *buffer, s32 size) { /** * Write data to EEPROM. - * The EEPROM address is computed using the offset of the source address from gSaveBuffer. + * The EEPROM address was originally computed using the offset of the source address from gSaveBuffer. * Try at most 4 times, and return 0 on success. On failure, return the status returned from * osEepromLongWrite. Unlike read_eeprom_data, return 1 if EEPROM isn't loaded. */ -static s32 write_eeprom_data(void *buffer, s32 size) { +static s32 write_eeprom_data(void *buffer, s32 size, const uintptr_t baseofs) { s32 status = 1; if (gEepromProbe != 0) { s32 triesLeft = 4; - u32 offset = (u32)((u8 *) buffer - (u8 *) &gSaveBuffer) >> 3; + u32 offset = (u32)baseofs >> 3; do { #ifdef VERSION_SH @@ -106,6 +144,41 @@ static s32 write_eeprom_data(void *buffer, s32 size) { return status; } +/** + * Wrappers that byteswap the data on LE platforms before writing it to 'EEPROM' + */ + +static inline s32 write_eeprom_savefile(const u32 file, const u32 slot, const u32 num) { + // calculate the EEPROM address using the file number and slot + const uintptr_t ofs = (u8*)&gSaveBuffer.files[file][slot] - (u8*)&gSaveBuffer; + +#if IS_BIG_ENDIAN + return write_eeprom_data(&gSaveBuffer.files[file][slot], num * sizeof(struct SaveFile), ofs); +#else + // byteswap the data and then write it + struct SaveFile sf[num]; + bcopy(&gSaveBuffer.files[file][slot], sf, num * sizeof(sf[0])); + for (u32 i = 0; i < num; ++i) bswap_savefile(&sf[i]); + return write_eeprom_data(&sf, sizeof(sf), ofs); +#endif +} + +static inline s32 write_eeprom_menudata(const u32 slot, const u32 num) { + // calculate the EEPROM address using the slot + const uintptr_t ofs = (u8*)&gSaveBuffer.menuData[slot] - (u8*)&gSaveBuffer; + +#if IS_BIG_ENDIAN + return write_eeprom_data(&gSaveBuffer.menuData[slot], num * sizeof(struct MainMenuSaveData), ofs); +#else + // byteswap the data and then write it + struct MainMenuSaveData md[num]; + bcopy(&gSaveBuffer.menuData[slot], md, num * sizeof(md[0])); + for (u32 i = 0; i < num; ++i) bswap_menudata(&md[i]); + return write_eeprom_data(&md, sizeof(md), ofs); +#endif +} + + /** * Sum the bytes in data to data + size - 2. The last two bytes are ignored * because that is where the checksum is stored. @@ -157,7 +230,7 @@ static void restore_main_menu_data(s32 srcSlot) { bcopy(&gSaveBuffer.menuData[srcSlot], &gSaveBuffer.menuData[destSlot], sizeof(gSaveBuffer.menuData[destSlot])); // Write destination data to EEPROM - write_eeprom_data(&gSaveBuffer.menuData[destSlot], sizeof(gSaveBuffer.menuData[destSlot])); + write_eeprom_menudata(destSlot, 1); } static void save_main_menu_data(void) { @@ -169,7 +242,7 @@ static void save_main_menu_data(void) { bcopy(&gSaveBuffer.menuData[0], &gSaveBuffer.menuData[1], sizeof(gSaveBuffer.menuData[1])); // Write to EEPROM - write_eeprom_data(gSaveBuffer.menuData, sizeof(gSaveBuffer.menuData)); + write_eeprom_menudata(0, 2); gMainMenuDataModified = FALSE; } @@ -245,8 +318,35 @@ static void restore_save_file_data(s32 fileIndex, s32 srcSlot) { sizeof(gSaveBuffer.files[fileIndex][destSlot])); // Write destination data to EEPROM - write_eeprom_data(&gSaveBuffer.files[fileIndex][destSlot], - sizeof(gSaveBuffer.files[fileIndex][destSlot])); + write_eeprom_savefile(fileIndex, destSlot, 1); +} + +/** + * Check if the 'EEPROM' save has different endianness (e.g. it's from an actual N64). + */ +static u8 save_file_need_bswap(const struct SaveBuffer *buf) { + // check all signatures just in case + for (int i = 0; i < 2; ++i) { + if (buf->menuData[i].signature.magic == BSWAP16(MENU_DATA_MAGIC)) + return TRUE; + for (int j = 0; j < NUM_SAVE_FILES; ++j) { + if (buf->files[j][i].signature.magic == BSWAP16(SAVE_FILE_MAGIC)) + return TRUE; + } + } + return FALSE; +} + +/** + * Byteswap all multibyte fields in a SaveBuffer. + */ +static void save_file_bswap(struct SaveBuffer *buf) { + bswap_menudata(buf->menuData + 0); + bswap_menudata(buf->menuData + 1); + for (int i = 0; i < NUM_SAVE_FILES; ++i) { + bswap_savefile(buf->files[i] + 0); + bswap_savefile(buf->files[i] + 1); + } } void save_file_do_save(s32 fileIndex) { @@ -260,7 +360,7 @@ void save_file_do_save(s32 fileIndex) { sizeof(gSaveBuffer.files[fileIndex][1])); // Write to EEPROM - write_eeprom_data(gSaveBuffer.files[fileIndex], sizeof(gSaveBuffer.files[fileIndex])); + write_eeprom_savefile(fileIndex, 0, 2); gSaveFileModified = FALSE; } @@ -298,6 +398,9 @@ void save_file_load_all(void) { bzero(&gSaveBuffer, sizeof(gSaveBuffer)); read_eeprom_data(&gSaveBuffer, sizeof(gSaveBuffer)); + if (save_file_need_bswap(&gSaveBuffer)) + save_file_bswap(&gSaveBuffer); + // Verify the main menu data and create a backup copy if only one of the slots is valid. validSlots = verify_save_block_signature(&gSaveBuffer.menuData[0], sizeof(gSaveBuffer.menuData[0]), MENU_DATA_MAGIC); validSlots |= verify_save_block_signature(&gSaveBuffer.menuData[1], sizeof(gSaveBuffer.menuData[1]),MENU_DATA_MAGIC) << 1; From 7bf7b34c57f8b1ca06d2d54e3deff59fb38da26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sat, 16 May 2020 18:07:14 -0300 Subject: [PATCH 12/16] Add a `--configfile` CLI option Usage: `--configfile yahoo.ini` will load up a file named yahoo.ini as the configuration file. --- src/game/options_menu.c | 3 ++- src/pc/cliopts.c | 16 ++++++++++++++++ src/pc/configfile.h | 2 -- src/pc/pc_main.c | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 37bce584..59dfc23e 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -16,6 +16,7 @@ #include "game/game_init.h" #include "game/ingame_menu.h" #include "game/options_menu.h" +#include "pc/cliopts.h" #include "pc/configfile.h" #include "pc/controller/controller_api.h" @@ -424,7 +425,7 @@ void optmenu_toggle(void) { newcam_init_settings(); // load bettercam settings from config vars #endif controller_reconfigure(); // rebind using new config values - configfile_save(CONFIG_FILE); + configfile_save(gCLIOpts.ConfigFile); } } diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 602de098..0baf9fdd 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,5 +1,6 @@ #include "cliopts.h" #include +#include struct PCCLIOptions gCLIOpts; @@ -8,6 +9,8 @@ void parse_cli_opts(int argc, char* argv[]) // Initialize options with false values. gCLIOpts.SkipIntro = 0; gCLIOpts.FullScreen = 0; + gCLIOpts.ConfigFile = malloc(31); + strncpy(gCLIOpts.ConfigFile, "sm64config.txt", strlen("sm64config.txt")); // Scan arguments for options if (argc > 1) @@ -20,6 +23,19 @@ void parse_cli_opts(int argc, char* argv[]) if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen gCLIOpts.FullScreen = 1; + + if (strncmp(argv[i], "--configfile", strlen("--configfile")) == 0) + { + if (i+1 < argc) + { + if (strlen(argv[i]) > 30) { + fprintf(stderr, "Configuration file supplied has a name too long.\n"); + } else { + memset(gCLIOpts.ConfigFile, 0, 30); + strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1])); + } + } + } } } } \ No newline at end of file diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 8dc69e27..49b48b93 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -3,8 +3,6 @@ #include -#define CONFIG_FILE "sm64config.txt" - #define MAX_BINDS 3 #define MAX_VOLUME 127 #define VOLUME_SHIFT 7 diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 93774fe2..f0c0a08b 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -92,7 +92,7 @@ void audio_shutdown(void) { } void game_shutdown(void) { - configfile_save(CONFIG_FILE); + configfile_save(gCLIOpts.ConfigFile);; controller_shutdown(); audio_shutdown(); gfx_shutdown(); @@ -136,7 +136,7 @@ void main_func(void) { main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0])); gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); - configfile_load(CONFIG_FILE); + configfile_load(gCLIOpts.ConfigFile); atexit(game_shutdown); #ifdef TARGET_WEB From e67a5443b70ecf597843572ab3a1680e54ed9437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sat, 16 May 2020 18:14:43 -0300 Subject: [PATCH 13/16] Fixed some stuff --- src/pc/cliopts.c | 1 + src/pc/cliopts.h | 1 + src/pc/pc_main.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 0baf9fdd..1e3b29c8 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,6 +1,7 @@ #include "cliopts.h" #include #include +#include struct PCCLIOptions gCLIOpts; diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index b4a0b613..1844c44c 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -4,6 +4,7 @@ struct PCCLIOptions { u8 SkipIntro; u8 FullScreen; + char * ConfigFile; }; extern struct PCCLIOptions gCLIOpts; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index f0c0a08b..c198f210 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -20,6 +20,7 @@ #include "cliopts.h" #include "configfile.h" +#include "controller/controller_api.h" OSMesg D_80339BEC; OSMesgQueue gSIEventMesgQueue; From 9fd43118cb6129521956741a3d5f01cb00e701bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= <36349314+vrmiguel@users.noreply.github.com> Date: Sat, 16 May 2020 18:37:08 -0300 Subject: [PATCH 14/16] Added nightly notice. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b1cc3121..c9fabe58 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ OpenGL adaptation of [n64decomp/sm64](https://github.com/n64decomp/sm64). Feel free to report bugs and contribute, but remember, there must be **no upload of any copyrighted asset**. Run `./extract_assets.py --clean && make clean` or `make distclean` to remove ROM-originated content. This port has been made possible mostly thanks to [Emill](https://github.com/Emill) and his [n64-fast32-engine](https://github.com/Emill/n64-fast3d-engine/) renderer. + +Please contribute **first** to the [nightly branch](https://github.com/sm64pc/sm64pc/tree/nightly/). New functionality will be merged to master once they're considered to be well-tested. + *Read this in other languages: [Español](README_es_ES.md) [简体中文](README_zh_CN.md).* ## Features From 0402ad463b84fe5049bd491c9a8ff951342755c7 Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 19:18:50 -0300 Subject: [PATCH 15/16] fixed MXE once and for all thanks to @fgsfdsfgs, this is the final thing needed for MXE support --- include/PR/os_libc.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h index 4c2fc3e1..e7567516 100644 --- a/include/PR/os_libc.h +++ b/include/PR/os_libc.h @@ -3,14 +3,28 @@ #include "ultratypes.h" -// Old deprecated functions from strings.h, replaced by memcpy/memset. -#ifdef NO_BZERO +// old bstring functions that aren't present on some platforms + +#if defined(__APPLE__) + +// macOS libc has them +#include + +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) + +// there's no way that shit's defined, use memcpy/memset #include -#define bzero(buf, size) memset((buf), 0, (size)) -#define bcopy(src, dst, size) memcpy((dst), (src), (size)) +#undef bzero +#undef bcopy +#define bzero(buf, len) memset((buf), 0, (len)) +#define bcopy(src, dst, len) memcpy((dst), (src), (len)) + #else + +// hope for the best extern void bcopy(const void *, void *, size_t); extern void bzero(void *, size_t); + #endif #endif /* !_OS_LIBC_H_ */ From 5c9e3c60a7b14ccc387ea1e7bcdb98585ba8446e Mon Sep 17 00:00:00 2001 From: "Colton G. Rushton" Date: Sat, 16 May 2020 19:20:45 -0300 Subject: [PATCH 16/16] strip out now-needless NOBZERO flag --- Makefile | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Makefile b/Makefile index 5903e52f..a0dd34c5 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,6 @@ TARGET_N64 = 0 # Build and optimize for Raspberry Pi(s) TARGET_RPI ?= 0 -# No BZERO (for building under MXE) -NO_BZERO ?= 0 # Compiler to use (ido or gcc) COMPILER ?= ido @@ -450,12 +448,6 @@ SDLCONFIG := $(CROSS)sdl2-config ifeq ($(WINDOWS_BUILD),1) CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) `$(SDLCONFIG) --cflags` CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv `$(SDLCONFIG) --cflags` - ifeq ($(CROSS),i686-w64-mingw32.static-) - ifeq ($(CROSS),x86_64-w64-mingw32.static-) - CC_CHECK += D_NOBZERO - CFLAGS += D_NOBZERO - endif - endif else ifeq ($(TARGET_WEB),1) CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2 @@ -469,12 +461,6 @@ endif # Check for enhancement options -# Check for no bzero option -ifeq ($(NO_BZERO),1) -CC_CHECK += -DNO_BZERO -CFLAGS += -DNO_BZERO -endif - # Check for Puppycam option ifeq ($(BETTERCAMERA),1) CC_CHECK += -DBETTERCAMERA