diff --git a/CMakeLists.txt b/CMakeLists.txt index b38aa786e..112b59a22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,9 @@ if(WIN32) elseif(APPLE) # OSX set(TARGET_OS "osx") +elseif(NINTENDO_SWITCH) + # Switch + set(TARGET_OS "nswitch") elseif(UNIX) # Generic *nix; assume Linux set(TARGET_OS "linux") @@ -149,6 +152,11 @@ include_directories("${CMAKE_SOURCE_DIR}/port/include") include_directories("${CMAKE_BINARY_DIR}/port/include") include_directories("${CMAKE_SOURCE_DIR}/port/src/imgui") +# Set Release optimization to -Og until I fix the -O2 issues +if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) + add_compile_options(-Og) +endif() + # Common CFLAGS add_compile_options( -fno-inline-functions @@ -185,19 +193,31 @@ set(LIBS ) # SDL2 find_package(SDL2 REQUIRED) +if(NINTENDO_SWITCH) + if(NOT SDL2_LIBRARY OR NOT SDL2_INCLUDE_DIR) + # sometimes FindSDL2 just wants us to suffer and does not set these + set(SDL2_LIBRARY "SDL2") + set(SDL2_INCLUDE_DIR "${DEVKITPRO}/portlibs/switch/include/SDL2") + endif() +endif() include_directories(SYSTEM "${SDL2_INCLUDE_DIR}") list(APPEND LIBS "${SDL2_LIBRARY}") # ZLib find_package(ZLIB REQUIRED) +if(ZLIB_INCLUDE_DIR) + include_directories(SYSTEM "${ZLIB_INCLUDE_DIR}") +endif() list(APPEND LIBS "${ZLIB_LIBRARY}") # GL if(NOT GL_LIBRARY) if(WIN32) - set(GL_LIBRARY "opengl32") + set(GL_LIBRARY opengl32) + elseif(NINTENDO_SWITCH) + set(GL_LIBRARY EGL glapi drm_nouveau) else() - set(GL_LIBRARY "GL") + set(GL_LIBRARY GL) endif() endif() list(APPEND LIBS "${GL_LIBRARY}") @@ -206,6 +226,8 @@ list(APPEND LIBS "${GL_LIBRARY}") if(NOT EXTRA_LIBRARIES) if(WIN32) set(EXTRA_LIBRARIES dbghelp -static-libstdc++) + elseif(NINTENDO_SWITCH) + set(EXTRA_LIBRARIES stdc++ pthread) else() set(EXTRA_LIBRARIES stdc++ m dl) endif() @@ -297,10 +319,21 @@ add_custom_target(pd_headers ALL DEPENDS ${JSON_HEADERS}) # Game target +set(BIN_NAME "pd${BIN_REGION}.${TARGET_ARCH}") add_executable(pd ${SRC}) add_dependencies(pd pd_headers) target_link_libraries(pd ${LIBS}) -set_target_properties(pd PROPERTIES OUTPUT_NAME "pd${BIN_REGION}.${TARGET_ARCH}") +set_target_properties(pd PROPERTIES OUTPUT_NAME "${BIN_NAME}") if(WIN32) set_target_properties(pd PROPERTIES WIN32_EXECUTABLE TRUE) endif() + +# Additional commands for specific platforms. + +if(NINTENDO_SWITCH) + add_custom_command(TARGET pd POST_BUILD + COMMAND nacptool --create "Perfect Dark" "fgsfds and contributors" "${VERSION_ROMID}/${VERSION_BRANCH}/${VERSION_HASH}" "${BIN_NAME}.nacp" + COMMAND aarch64-none-elf-strip -o ${CMAKE_BINARY_DIR}/${BIN_NAME}.stripped.elf ${CMAKE_BINARY_DIR}/${BIN_NAME}.elf + COMMAND elf2nro ${CMAKE_BINARY_DIR}/${BIN_NAME}.stripped.elf ${CMAKE_BINARY_DIR}/${BIN_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/dist/nswitch/icon.jpg --nacp=${BIN_NAME}.nacp + ) +endif() diff --git a/README.md b/README.md index 8e508b465..6cc20f684 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ Controls can be rebound in `pd.ini`. Default control scheme is as follows: 5. Run `cmake -G"Unix Makefiles" -Bbuild .`. * Add ` -DROMID=pal-final` or ` -DROMID=jpn-final` at the end of the command if you want to build a PAL or JPN executable respectively.\ 6. Run `cmake --build build -j4 -- -O`. -6. The resulting executable will be at `build/pd.x86_64.exe` (or at `build/pd.i686.exe` if building for i686). -7. If you don't know where you downloaded the source to, you can run `explorer .` to open the current directory. +7. The resulting executable will be at `build/pd.x86_64.exe` (or at `build/pd.i686.exe` if building for i686). +8. If you don't know where you downloaded the source to, you can run `explorer .` to open the current directory. ### Linux @@ -125,7 +125,32 @@ Controls can be rebound in `pd.ini`. Default control scheme is as follows: * Add ` -DROMID=pal-final` or ` -DROMID=jpn-final` at the end of the command if you want to build a PAL or JPN executable respectively. * Add ` -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32` at the end of the command if you want to crosscompile from x86_64 to x86. 4. Run `cmake --build build -j4`. -4. The resulting executable will be at `build/pd.` (for example `build/pd.x86_64`). +5. The resulting executable will be at `build/pd.` (for example `build/pd.x86_64`). + +### Nintendo Switch + +1. Set up the [devkitA64 environment](https://devkitpro.org/wiki/Getting_Started). + * On Windows you can do it under MSYS2 or WSL, usually MSYS2 is recommended. + * If using MSYS2, make sure to use the **MSYS2** shell, **not** MINGW32 or MINGW64. +2. Install host dependencies: + * On MSYS2: execute command `pacman -Syuu && pacman -S git make cmake python3` + * On Linux: use your package manager as normal to install the above dependencies. +3. Install Switch toolchain and dependencies: + * Execute commands: + ``` + dkp-pacman -Syuu + dkp-pacman -S devkitA64 libnx switch-zlib switch-sdl2 switch-cmake dkp-toolchain-vars + ``` + * If in MSYS2 or `dkp-pacman` doesn't work, replace it with just `pacman`. +4. Ensure devkitA64 environment variables are set: + * Execute command: `source /opt/devkitpro/switchvars.sh` + * If your `$DEVKITPRO` path is different, substitute that instead or set the variables manually. +5. Configure: + * Execute command: `aarch64-none-elf-cmake -G"Unix Makefiles" -Bbuild .` + * Add ` -DROMID=pal-final` or ` -DROMID=jpn-final` at the end of the command if you want to build a PAL or JPN executable respectively. +6. Build: + * Execute command: `make -C build -j4` +7. The resulting executable will be at `build/pd.arm64.nro`. ### Notes diff --git a/dist/nswitch/gamecontrollerdb.txt b/dist/nswitch/gamecontrollerdb.txt new file mode 100644 index 000000000..7dcba6b02 --- /dev/null +++ b/dist/nswitch/gamecontrollerdb.txt @@ -0,0 +1,2 @@ +# Switch (SDL_GetPlatform is not changed in switch-sdl2) +000038f853776974636820436f6e7400,Switch Controller,a:b0,b:b1,back:b11,dpdown:b15,dpleft:b12,dpright:b14,dpup:b13,leftshoulder:b6,leftstick:b4,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b5,righttrigger:b9,rightx:a2,righty:a3,start:b10,x:b2,y:b3,platform:Unknown (see SDL_platform.h), diff --git a/dist/nswitch/icon.jpg b/dist/nswitch/icon.jpg new file mode 100644 index 000000000..2adc6f6c8 Binary files /dev/null and b/dist/nswitch/icon.jpg differ diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index df813796e..571e03f05 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -1637,34 +1637,27 @@ static void gfx_sp_extra_geometry_mode(uint32_t clear, uint32_t set) { } static void gfx_adjust_viewport_or_scissor(XYWidthHeight* area, bool preserve_aspect = false) { - if (!fbActive) { - area->width *= RATIO_X; - area->x *= RATIO_X; - area->height *= RATIO_Y; - area->y = SCREEN_HEIGHT - area->y; - area->y *= RATIO_Y; - if (preserve_aspect) { - // preserve native aspect ratio - const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio; - const float midx = gfx_current_dimensions.width * 0.5f; - area->x = midx + (area->x - midx) * ratio; - area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f; - area->width *= ratio; - } + // HACK: assume all target framebuffers have the same aspect + area->width *= RATIO_X; + area->x *= RATIO_X; + area->height *= RATIO_Y; + area->y = SCREEN_HEIGHT - area->y; + area->y *= RATIO_Y; + if (preserve_aspect) { + // preserve native aspect ratio + const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio; + const float midx = gfx_current_dimensions.width * 0.5f; + area->x = midx + (area->x - midx) * ratio; + area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f; + area->width *= ratio; + } - if (!game_renders_to_framebuffer || - (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && - gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) { - area->x += gfx_current_game_window_viewport.x; - area->y += gfx_current_window_dimensions.height - - (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height); - } - } else { - area->width *= RATIO_Y; - area->height *= RATIO_Y; - area->x *= RATIO_Y; - area->y = active_fb->second.orig_height - area->y; - area->y *= RATIO_Y; + if (!game_renders_to_framebuffer || + (gfx_msaa_level > 1 && gfx_current_dimensions.width == gfx_current_game_window_viewport.width && + gfx_current_dimensions.height == gfx_current_game_window_viewport.height)) { + area->x += gfx_current_game_window_viewport.x; + area->y += gfx_current_window_dimensions.height - + (gfx_current_game_window_viewport.y + gfx_current_game_window_viewport.height); } } @@ -2726,6 +2719,7 @@ extern "C" void gfx_resize_framebuffer(int fb, uint32_t width, uint32_t height, extern "C" void gfx_set_framebuffer(int fb, float noise_scale) { gfx_rapi->start_draw_to_framebuffer(fb, noise_scale); gfx_rapi->clear_framebuffer(true, true); + active_fb = framebuffers.find(fb); } extern "C" void gfx_copy_framebuffer(int fb_dst, int fb_src, int left, int top, int use_back) { @@ -2750,4 +2744,5 @@ extern "C" void gfx_copy_framebuffer(int fb_dst, int fb_src, int left, int top, extern "C" void gfx_reset_framebuffer(void) { gfx_rapi->start_draw_to_framebuffer(0, (float)gfx_current_dimensions.height / SCREEN_HEIGHT); + active_fb = framebuffers.end(); } diff --git a/port/fast3d/glad/glad.c b/port/fast3d/glad/glad.c index 08d76207d..2c4624e31 100644 --- a/port/fast3d/glad/glad.c +++ b/port/fast3d/glad/glad.c @@ -1,6 +1,6 @@ /* - OpenGL loader generated by glad 0.1.36 on Thu Oct 5 16:07:54 2023. + OpenGL loader generated by glad 0.1.36 on Wed Nov 13 09:35:45 2024. Language/Generator: C/C++ Specification: gl @@ -17,15 +17,15 @@ GL_EXT_gpu_shader4, GL_KHR_debug, GL_NV_depth_clamp - Loader: True + Loader: False Local files: True Omit khrplatform: False Reproducible: False Commandline: - --profile="compatibility" --api="gl=3.2" --generator="c" --spec="gl" --local-files --extensions="GL_ARB_depth_clamp,GL_ARB_framebuffer_object,GL_ARB_texture_mirror_clamp_to_edge,GL_ARB_vertex_array_object,GL_EXT_framebuffer_blit,GL_EXT_framebuffer_multisample,GL_EXT_framebuffer_object,GL_EXT_gpu_shader4,GL_KHR_debug,GL_NV_depth_clamp" + --profile="compatibility" --api="gl=3.2" --generator="c" --spec="gl" --no-loader --local-files --extensions="GL_ARB_depth_clamp,GL_ARB_framebuffer_object,GL_ARB_texture_mirror_clamp_to_edge,GL_ARB_vertex_array_object,GL_EXT_framebuffer_blit,GL_EXT_framebuffer_multisample,GL_EXT_framebuffer_object,GL_EXT_gpu_shader4,GL_KHR_debug,GL_NV_depth_clamp" Online: - https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&loader=on&api=gl%3D3.2&extensions=GL_ARB_depth_clamp&extensions=GL_ARB_framebuffer_object&extensions=GL_ARB_texture_mirror_clamp_to_edge&extensions=GL_ARB_vertex_array_object&extensions=GL_EXT_framebuffer_blit&extensions=GL_EXT_framebuffer_multisample&extensions=GL_EXT_framebuffer_object&extensions=GL_EXT_gpu_shader4&extensions=GL_KHR_debug&extensions=GL_NV_depth_clamp + https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&api=gl%3D3.2&extensions=GL_ARB_depth_clamp&extensions=GL_ARB_framebuffer_object&extensions=GL_ARB_texture_mirror_clamp_to_edge&extensions=GL_ARB_vertex_array_object&extensions=GL_EXT_framebuffer_blit&extensions=GL_EXT_framebuffer_multisample&extensions=GL_EXT_framebuffer_object&extensions=GL_EXT_gpu_shader4&extensions=GL_KHR_debug&extensions=GL_NV_depth_clamp */ #include @@ -33,138 +33,6 @@ #include #include "glad.h" -static void* get_proc(const char *namez); - -#if defined(_WIN32) || defined(__CYGWIN__) -#ifndef _WINDOWS_ -#undef APIENTRY -#endif -#include -static HMODULE libGL; - -typedef void* (APIENTRYP PFNWGLGETPROCADDRESSPROC_PRIVATE)(const char*); -static PFNWGLGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; - -#ifdef _MSC_VER -#ifdef __has_include - #if __has_include() - #define HAVE_WINAPIFAMILY 1 - #endif -#elif _MSC_VER >= 1700 && !_USING_V110_SDK71_ - #define HAVE_WINAPIFAMILY 1 -#endif -#endif - -#ifdef HAVE_WINAPIFAMILY - #include - #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) - #define IS_UWP 1 - #endif -#endif - -static -int open_gl(void) { -#ifndef IS_UWP - libGL = LoadLibraryW(L"opengl32.dll"); - if(libGL != NULL) { - void (* tmp)(void); - tmp = (void(*)(void)) GetProcAddress(libGL, "wglGetProcAddress"); - gladGetProcAddressPtr = (PFNWGLGETPROCADDRESSPROC_PRIVATE) tmp; - return gladGetProcAddressPtr != NULL; - } -#endif - - return 0; -} - -static -void close_gl(void) { - if(libGL != NULL) { - FreeLibrary((HMODULE) libGL); - libGL = NULL; - } -} -#else -#include -static void* libGL; - -#if !defined(__APPLE__) && !defined(__HAIKU__) -typedef void* (APIENTRYP PFNGLXGETPROCADDRESSPROC_PRIVATE)(const char*); -static PFNGLXGETPROCADDRESSPROC_PRIVATE gladGetProcAddressPtr; -#endif - -static -int open_gl(void) { -#ifdef __APPLE__ - static const char *NAMES[] = { - "../Frameworks/OpenGL.framework/OpenGL", - "/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/OpenGL", - "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL" - }; -#else - static const char *NAMES[] = {"libGL.so.1", "libGL.so"}; -#endif - - unsigned int index = 0; - for(index = 0; index < (sizeof(NAMES) / sizeof(NAMES[0])); index++) { - libGL = dlopen(NAMES[index], RTLD_NOW | RTLD_GLOBAL); - - if(libGL != NULL) { -#if defined(__APPLE__) || defined(__HAIKU__) - return 1; -#else - gladGetProcAddressPtr = (PFNGLXGETPROCADDRESSPROC_PRIVATE)dlsym(libGL, - "glXGetProcAddressARB"); - return gladGetProcAddressPtr != NULL; -#endif - } - } - - return 0; -} - -static -void close_gl(void) { - if(libGL != NULL) { - dlclose(libGL); - libGL = NULL; - } -} -#endif - -static -void* get_proc(const char *namez) { - void* result = NULL; - if(libGL == NULL) return NULL; - -#if !defined(__APPLE__) && !defined(__HAIKU__) - if(gladGetProcAddressPtr != NULL) { - result = gladGetProcAddressPtr(namez); - } -#endif - if(result == NULL) { -#if defined(_WIN32) || defined(__CYGWIN__) - result = (void*)GetProcAddress((HMODULE) libGL, namez); -#else - result = dlsym(libGL, namez); -#endif - } - - return result; -} - -int gladLoadGL(void) { - int status = 0; - - if(open_gl()) { - status = gladLoadGLLoader(&get_proc); - close_gl(); - } - - return status; -} - struct gladGLversionStruct GLVersion = { 0, 0 }; #if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0) @@ -185,7 +53,7 @@ static int get_exts(void) { exts = (const char *)glGetString(GL_EXTENSIONS); #ifdef _GLAD_IS_SOME_NEW_VERSION } else { - unsigned int index; + int index; num_exts_i = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts_i); @@ -197,7 +65,7 @@ static int get_exts(void) { return 0; } - for(index = 0; index < (unsigned)num_exts_i; index++) { + for(index = 0; index < num_exts_i; index++) { const char *gl_str_tmp = (const char*)glGetStringi(GL_EXTENSIONS, index); size_t len = strlen(gl_str_tmp); diff --git a/port/fast3d/glad/glad.h b/port/fast3d/glad/glad.h index e096abac2..e0b55c5c2 100644 --- a/port/fast3d/glad/glad.h +++ b/port/fast3d/glad/glad.h @@ -1,6 +1,6 @@ /* - OpenGL loader generated by glad 0.1.36 on Thu Oct 5 16:07:54 2023. + OpenGL loader generated by glad 0.1.36 on Wed Nov 13 09:35:45 2024. Language/Generator: C/C++ Specification: gl @@ -17,15 +17,15 @@ GL_EXT_gpu_shader4, GL_KHR_debug, GL_NV_depth_clamp - Loader: True + Loader: False Local files: True Omit khrplatform: False Reproducible: False Commandline: - --profile="compatibility" --api="gl=3.2" --generator="c" --spec="gl" --local-files --extensions="GL_ARB_depth_clamp,GL_ARB_framebuffer_object,GL_ARB_texture_mirror_clamp_to_edge,GL_ARB_vertex_array_object,GL_EXT_framebuffer_blit,GL_EXT_framebuffer_multisample,GL_EXT_framebuffer_object,GL_EXT_gpu_shader4,GL_KHR_debug,GL_NV_depth_clamp" + --profile="compatibility" --api="gl=3.2" --generator="c" --spec="gl" --no-loader --local-files --extensions="GL_ARB_depth_clamp,GL_ARB_framebuffer_object,GL_ARB_texture_mirror_clamp_to_edge,GL_ARB_vertex_array_object,GL_EXT_framebuffer_blit,GL_EXT_framebuffer_multisample,GL_EXT_framebuffer_object,GL_EXT_gpu_shader4,GL_KHR_debug,GL_NV_depth_clamp" Online: - https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&loader=on&api=gl%3D3.2&extensions=GL_ARB_depth_clamp&extensions=GL_ARB_framebuffer_object&extensions=GL_ARB_texture_mirror_clamp_to_edge&extensions=GL_ARB_vertex_array_object&extensions=GL_EXT_framebuffer_blit&extensions=GL_EXT_framebuffer_multisample&extensions=GL_EXT_framebuffer_object&extensions=GL_EXT_gpu_shader4&extensions=GL_KHR_debug&extensions=GL_NV_depth_clamp + https://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&api=gl%3D3.2&extensions=GL_ARB_depth_clamp&extensions=GL_ARB_framebuffer_object&extensions=GL_ARB_texture_mirror_clamp_to_edge&extensions=GL_ARB_vertex_array_object&extensions=GL_EXT_framebuffer_blit&extensions=GL_EXT_framebuffer_multisample&extensions=GL_EXT_framebuffer_object&extensions=GL_EXT_gpu_shader4&extensions=GL_KHR_debug&extensions=GL_NV_depth_clamp */ @@ -90,9 +90,6 @@ typedef void* (* GLADloadproc)(const char *name); #endif GLAPI struct gladGLversionStruct GLVersion; - -GLAPI int gladLoadGL(void); - GLAPI int gladLoadGLLoader(GLADloadproc); #include "khrplatform.h" diff --git a/port/include/fs.h b/port/include/fs.h index 24858460d..bfb21b3ec 100644 --- a/port/include/fs.h +++ b/port/include/fs.h @@ -19,7 +19,7 @@ s32 fsFileSize(const char *name); FILE *fsFileOpenWrite(const char *name); FILE *fsFileOpenRead(const char *name); -void fsFileClose(FILE *f); +void fsFileFree(FILE *f); const char *fsGetModDir(void); diff --git a/port/src/config.c b/port/src/config.c index b37c2e955..6be6f0d9f 100644 --- a/port/src/config.c +++ b/port/src/config.c @@ -228,7 +228,7 @@ s32 configSave(const char *fname) configSaveEntry(cfg, f); } - fsFileClose(f); + fsFileFree(f); return 1; } @@ -282,7 +282,7 @@ s32 configLoad(const char *fname) } } - fsFileClose(f); + fsFileFree(f); return 1; } diff --git a/port/src/fs.c b/port/src/fs.c index bb863af09..cbcec8782 100644 --- a/port/src/fs.c +++ b/port/src/fs.c @@ -276,7 +276,7 @@ FILE *fsFileOpenRead(const char *name) return fopen(fsFullPath(name), "rb"); } -void fsFileClose(FILE *f) +void fsFileFree(FILE *f) { fclose(f); } diff --git a/port/src/libultra.c b/port/src/libultra.c index 708f97bd5..465a1e62c 100644 --- a/port/src/libultra.c +++ b/port/src/libultra.c @@ -277,7 +277,7 @@ static inline void osEeepromLoad(const char *fname) FILE *fp = fsFileOpenRead(fname); if (fp) { fread(eeprom, 1, EEPROM_SIZE, fp); - fsFileClose(fp); + fsFileFree(fp); } else { sysLogPrintf(LOG_NOTE, "could not read EEPROM from `%s`: %s", fsFullPath(fname), strerror(errno)); } @@ -289,7 +289,7 @@ static inline void osEeepromSave(const char *fname) FILE* fp = fsFileOpenWrite(fname); if (fp) { fwrite(eeprom, 1, EEPROM_SIZE, fp); - fsFileClose(fp); + fsFileFree(fp); } else { sysLogPrintf(LOG_ERROR, "could not save EEPROM to `%s`: %s", fsFullPath(fname), strerror(errno)); } diff --git a/port/src/preprocess/filebg.c b/port/src/preprocess/filebg.c index 55f173364..6ff407310 100644 --- a/port/src/preprocess/filebg.c +++ b/port/src/preprocess/filebg.c @@ -266,7 +266,7 @@ static u32 convertRoomGfxData(u8 *dst, u8 *src, u32 infsize, u32 src_ofs) intptr_t endpos = (uintptr_t)dst_header->vertices - src_ofs; uintptr_t curpos_src = sizeof(struct n64_roomgfxdata); - uintptr_t curpos_dst = sizeof(struct roomgfxdata); + uintptr_t curpos_dst = sizeof(struct roomgfxdata) - sizeof(struct roomblock); // compensate for the [1] // roomblocks int ncoords = 0; diff --git a/port/src/preprocess/filemodel.c b/port/src/preprocess/filemodel.c index c2ff8c100..189c7faae 100644 --- a/port/src/preprocess/filemodel.c +++ b/port/src/preprocess/filemodel.c @@ -76,6 +76,8 @@ static const struct alignconfig alignConfigs[] = { static struct marker contentMarkers[1024]; static int numContentMarkers; +// TODO: get rid of the host_ structs here when I figure out why the ones from types.h won't work + struct n64_modeldef { u32 ptr_rootnode; u32 ptr_skel; @@ -88,6 +90,18 @@ struct n64_modeldef { u32 ptr_texconfigs; }; +struct host_modeldef { + uintptr_t ptr_rootnode; + uintptr_t ptr_skel; + uintptr_t ptr_parts; + s16 numparts; + s16 nummatrices; + u32 scale; + u16 rwdatalen; + u16 numtexconfigs; + uintptr_t ptr_texconfigs; +}; + struct n64_modelnode { u16 type; u32 ptr_rodata; @@ -97,7 +111,30 @@ struct n64_modelnode { u32 ptr_child; }; -struct n64_modelrodata_gundl { +struct host_modelnode { + u16 type; + uintptr_t ptr_rodata; + uintptr_t ptr_parent; + uintptr_t ptr_next; + uintptr_t ptr_prev; + uintptr_t ptr_child; +}; + +struct generic_rodata_chrinfo { + u16 animpart; + s16 mtxindex; + u32 unk04; + u16 rwdataindex; +}; + +struct generic_rodata_position { + u32 pos[3]; + u16 part; + s16 mtxindexes[3]; + u32 drawdist; +}; + +struct n64_rodata_gundl { u32 ptr_opagdl; u32 ptr_xlugdl; u32 ptr_baseaddr; @@ -106,34 +143,75 @@ struct n64_modelrodata_gundl { s16 unk12; }; -struct n64_modelrodata_distance { - f32 near; - f32 far; +struct host_rodata_gundl { + uintptr_t ptr_opagdl; + uintptr_t ptr_xlugdl; + uintptr_t ptr_baseaddr; + uintptr_t ptr_vertices; + s16 numvertices; + s16 unk12; +}; + +struct n64_rodata_distance { + u32 near; + u32 far; u32 ptr_target; u16 rwdataindex; }; -struct n64_modelrodata_reorder { - f32 unk00; - f32 unk04; - f32 unk08; - f32 unk0c[3]; +struct host_rodata_distance { + u32 near; + u32 far; + uintptr_t ptr_target; + u16 rwdataindex; +}; + +struct n64_rodata_reorder { + u32 unk00; + u32 unk04; + u32 unk08; + u32 unk0c[3]; u32 ptr_node_unk18; u32 ptr_node_unk1c; s16 side; u16 rwdataindex; }; -struct n64_modelrodata_chrgunfire { - struct coord pos; - struct coord dim; +struct host_rodata_reorder { + u32 unk00; + u32 unk04; + u32 unk08; + u32 unk0c[3]; + uintptr_t ptr_node_unk18; + uintptr_t ptr_node_unk1c; + s16 side; + u16 rwdataindex; +}; + +struct generic_rodata_bbox { + s32 hitpart; + u32 bbox[6]; +}; + +struct n64_rodata_chrgunfire { + u32 pos[3]; + u32 dim[3]; u32 ptr_texture; - f32 unk1c; + u32 unk1c; u16 rwdataindex; u32 ptr_baseaddr; }; -struct n64_modelrodata_type11 { +struct host_rodata_chrgunfire { + u32 pos[3]; + u32 dim[3]; + uintptr_t ptr_texture; + u32 unk1c; + u16 rwdataindex; + uintptr_t ptr_baseaddr; +}; + +struct n64_rodata_type11 { u32 unk00; u32 unk04; u32 unk08; @@ -144,19 +222,52 @@ struct n64_modelrodata_type11 { u32 extra2; }; -struct n64_modelrodata_toggle { +struct host_rodata_type11 { + u32 unk00; + u32 unk04; + u32 unk08; + u32 unk0c; + u32 unk10; + u32 unk14; + u32 extra1; + u32 extra2; +}; + +struct n64_rodata_toggle { u32 ptr_target; u16 rwdataindex; }; -struct n64_modelrodata_stargunfire { +struct host_rodata_toggle { + uintptr_t ptr_target; + u16 rwdataindex; +}; + +struct generic_rodata_positionheld { + u32 pos[3]; + s16 mtxindex; + u32 unk10; +}; + +struct n64_rodata_stargunfire { u32 unk00; u32 ptr_vertices; u32 ptr_gdl; u32 ptr_baseaddr; }; -struct n64_modelrodata_dl { +struct host_rodata_stargunfire { + u32 unk00; + uintptr_t ptr_vertices; + uintptr_t ptr_gdl; + uintptr_t ptr_baseaddr; +}; + +struct generic_rodata_headspot { + u16 rwdataindex; +}; + +struct n64_rodata_dl { u32 ptr_opagdl; u32 ptr_xlugdl; u32 ptr_colours; @@ -167,6 +278,22 @@ struct n64_modelrodata_dl { u16 numcolours; }; +struct host_rodata_dl { + uintptr_t ptr_opagdl; + uintptr_t ptr_xlugdl; + uintptr_t ptr_colours; + uintptr_t ptr_vertices; // colours follow this array + s16 numvertices; + s16 mcount; + u16 rwdataindex; + u16 numcolours; +}; + +struct generic_rodata_type19 { + u32 numvertices; + u32 vertices[3]; +}; + struct n64_textureconfig { u32 ptr; u8 width; @@ -179,6 +306,18 @@ struct n64_textureconfig { u8 unk0b; }; +struct host_textureconfig { + uintptr_t ptr; + u8 width; + u8 height; + u8 level; + u8 format; + u8 depth; + u8 s; + u8 t; + u8 unk0b; +}; + static inline uintptr_t minPtr(uintptr_t a, uintptr_t b) { return (a && (a < b || !b)) ? a : b; } @@ -263,87 +402,109 @@ static void populateMarkers(u8 *src) switch (marker->type) { case CT_MODELDEF: - struct n64_modeldef *src_modeldef = src_thing; - int num_texconfigs = PD_BE16(src_modeldef->numtexconfigs); - u32 texconfigpos = PD_BE32(src_modeldef->ptr_texconfigs); - setMarker(PD_BE32(src_modeldef->ptr_rootnode), CT_NODE, marker->src_offset); - setMarker(PD_BE32(src_modeldef->ptr_parts), CT_PARTS, marker->src_offset); + { + struct n64_modeldef *src_modeldef = src_thing; + int num_texconfigs = PD_BE16(src_modeldef->numtexconfigs); + u32 texconfigpos = PD_BE32(src_modeldef->ptr_texconfigs); + setMarker(PD_BE32(src_modeldef->ptr_rootnode), CT_NODE, marker->src_offset); + setMarker(PD_BE32(src_modeldef->ptr_parts), CT_PARTS, marker->src_offset); - for (int i = 0; i < num_texconfigs; i++) { - setMarker(texconfigpos + sizeof(struct n64_textureconfig) * i, CT_TEXCONFIG, marker->src_offset); + for (int i = 0; i < num_texconfigs; i++) { + setMarker(texconfigpos + sizeof(struct n64_textureconfig) * i, CT_TEXCONFIG, marker->src_offset); + } + break; } - break; case CT_NODE: - struct n64_modelnode *src_node = src_thing; - u32 node_type = PD_BE16(src_node->type) & 0xff; - setMarker(PD_BE32(src_node->ptr_rodata), nodeTypeToContentType[node_type], marker->src_offset); - setMarker(PD_BE32(src_node->ptr_parent), CT_NODE, marker->src_offset); - setMarker(PD_BE32(src_node->ptr_next), CT_NODE, marker->src_offset); - setMarker(PD_BE32(src_node->ptr_prev), CT_NODE, marker->src_offset); - setMarker(PD_BE32(src_node->ptr_child), CT_NODE, marker->src_offset); - break; + { + struct n64_modelnode *src_node = src_thing; + u32 node_type = PD_BE16(src_node->type) & 0xff; + setMarker(PD_BE32(src_node->ptr_rodata), nodeTypeToContentType[node_type], marker->src_offset); + setMarker(PD_BE32(src_node->ptr_parent), CT_NODE, marker->src_offset); + setMarker(PD_BE32(src_node->ptr_next), CT_NODE, marker->src_offset); + setMarker(PD_BE32(src_node->ptr_prev), CT_NODE, marker->src_offset); + setMarker(PD_BE32(src_node->ptr_child), CT_NODE, marker->src_offset); + break; + } case CT_TEXCONFIG: - struct n64_textureconfig *src_texconfig = src_thing; - if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) { - setMarker(PD_BE32(src_texconfig->ptr), CT_TEXDATA, marker->src_offset); + { + struct n64_textureconfig *src_texconfig = src_thing; + if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) { + setMarker(PD_BE32(src_texconfig->ptr), CT_TEXDATA, marker->src_offset); + } + break; } - break; case CT_PARTS: - struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; - u32 *src_parts = (u32 *) src_thing; - int num_parts = PD_BE16(src_modeldef2->numparts); + { + struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; + u32 *src_parts = (u32 *) src_thing; + int num_parts = PD_BE16(src_modeldef2->numparts); - for (int i = 0; i < num_parts; i++) { - setMarker(PD_BE32(src_parts[i]), CT_NODE, marker->src_offset); + for (int i = 0; i < num_parts; i++) { + setMarker(PD_BE32(src_parts[i]), CT_NODE, marker->src_offset); + } + break; } - break; case CT_RODATA_CHRINFO: break; case CT_RODATA_POSITION: break; case CT_RODATA_GUNDL: - struct n64_modelrodata_gundl *src_gundl = src_thing; - setMarker(PD_BE32(src_gundl->ptr_opagdl), CT_GDL, marker->src_offset); - setMarker(PD_BE32(src_gundl->ptr_xlugdl), CT_GDL, marker->src_offset); - setMarker(PD_BE32(src_gundl->ptr_vertices), CT_VTXCOL, marker->src_offset); - break; + { + struct n64_rodata_gundl *src_gundl = src_thing; + setMarker(PD_BE32(src_gundl->ptr_opagdl), CT_GDL, marker->src_offset); + setMarker(PD_BE32(src_gundl->ptr_xlugdl), CT_GDL, marker->src_offset); + setMarker(PD_BE32(src_gundl->ptr_vertices), CT_VTXCOL, marker->src_offset); + break; + } case CT_RODATA_DISTANCE: - struct n64_modelrodata_distance *src_dist = src_thing; - setMarker(PD_BE32(src_dist->ptr_target), CT_NODE, marker->src_offset); - break; + { + struct n64_rodata_distance *src_dist = src_thing; + setMarker(PD_BE32(src_dist->ptr_target), CT_NODE, marker->src_offset); + break; + } case CT_RODATA_REORDER: - struct n64_modelrodata_reorder *src_reorder = src_thing; - setMarker(PD_BE32(src_reorder->ptr_node_unk18), CT_NODE, marker->src_offset); - setMarker(PD_BE32(src_reorder->ptr_node_unk1c), CT_NODE, marker->src_offset); - break; + { + struct n64_rodata_reorder *src_reorder = src_thing; + setMarker(PD_BE32(src_reorder->ptr_node_unk18), CT_NODE, marker->src_offset); + setMarker(PD_BE32(src_reorder->ptr_node_unk1c), CT_NODE, marker->src_offset); + break; + } case CT_RODATA_CHRGUNFIRE: - struct n64_modelrodata_chrgunfire *src_chrgunfire = src_thing; - setMarker(PD_BE32(src_chrgunfire->ptr_texture), CT_TEXCONFIG, marker->src_offset); - break; + { + struct n64_rodata_chrgunfire *src_chrgunfire = src_thing; + setMarker(PD_BE32(src_chrgunfire->ptr_texture), CT_TEXCONFIG, marker->src_offset); + break; + } case CT_RODATA_TOGGLE: - struct n64_modelrodata_toggle *src_toggle = src_thing; - setMarker(PD_BE32(src_toggle->ptr_target), CT_NODE, marker->src_offset); - break; + { + struct n64_rodata_toggle *src_toggle = src_thing; + setMarker(PD_BE32(src_toggle->ptr_target), CT_NODE, marker->src_offset); + break; + } case CT_RODATA_STARGUNFIRE: - struct n64_modelrodata_stargunfire *src_stargunfire = src_thing; - colstart = PD_BE32(src_stargunfire->unk00)*4*(sizeof(s16) * 6); - u32 vtxstart = PD_BE32(src_stargunfire->ptr_vertices); - u32 vtxend = vtxstart + colstart; - colstart = ALIGN8(vtxstart + colstart); - setMarker(vtxstart, CT_VTXCOL4, marker->src_offset); - if (vtxend != colstart) { - setMarker(vtxend, CT_SKIP, marker->src_offset); + { + struct n64_rodata_stargunfire *src_stargunfire = src_thing; + colstart = PD_BE32(src_stargunfire->unk00)*4*(sizeof(s16) * 6); + u32 vtxstart = PD_BE32(src_stargunfire->ptr_vertices); + u32 vtxend = vtxstart + colstart; + colstart = ALIGN8(vtxstart + colstart); + setMarker(vtxstart, CT_VTXCOL4, marker->src_offset); + if (vtxend != colstart) { + setMarker(vtxend, CT_SKIP, marker->src_offset); + } + setMarker(colstart, CT_VTXCOL, marker->src_offset); + setMarker(PD_BE32(src_stargunfire->ptr_gdl), CT_GDL, marker->src_offset); + break; } - setMarker(colstart, CT_VTXCOL, marker->src_offset); - setMarker(PD_BE32(src_stargunfire->ptr_gdl), CT_GDL, marker->src_offset); - break; case CT_RODATA_DL: - struct n64_modelrodata_dl *src_dl = src_thing; - setMarker(PD_BE32(src_dl->ptr_opagdl), CT_GDL, marker->src_offset); - setMarker(PD_BE32(src_dl->ptr_xlugdl), CT_GDL, marker->src_offset); - setMarker(PD_BE32(src_dl->ptr_colours), CT_VTXCOL, marker->src_offset); - setMarker(PD_BE32(src_dl->ptr_vertices), CT_VTXCOL, marker->src_offset); - break; + { + struct n64_rodata_dl *src_dl = src_thing; + setMarker(PD_BE32(src_dl->ptr_opagdl), CT_GDL, marker->src_offset); + setMarker(PD_BE32(src_dl->ptr_xlugdl), CT_GDL, marker->src_offset); + setMarker(PD_BE32(src_dl->ptr_colours), CT_VTXCOL, marker->src_offset); + setMarker(PD_BE32(src_dl->ptr_vertices), CT_VTXCOL, marker->src_offset); + break; + } case CT_TEXDATA: case CT_VTXCOL: case CT_GDL: @@ -352,7 +513,6 @@ static void populateMarkers(u8 *src) case CT_RODATA_POSITIONHELD: case CT_RODATA_HEADSPOT: case CT_RODATA_19: - break; default: break; } @@ -397,231 +557,280 @@ static u32 convertContent(u8 *dst, u8 *src, u32 src_file_len) switch (marker->type) { case CT_MODELDEF: - struct n64_modeldef *src_modeldef = src_thing; - struct modeldef *dst_modeldef = dst_thing; - dst_modeldef->skel = (void *)(uintptr_t)PD_BE32(src_modeldef->ptr_skel); - dst_modeldef->numparts = PD_BE16(src_modeldef->numparts); - dst_modeldef->nummatrices = PD_BE16(src_modeldef->nummatrices); - dst_modeldef->scale = PD_BE32(src_modeldef->scale); - dst_modeldef->rwdatalen = PD_BE16(src_modeldef->rwdatalen); - dst_modeldef->numtexconfigs = PD_BE16(src_modeldef->numtexconfigs); - dstpos += sizeof(*dst_modeldef); - break; + { + struct n64_modeldef *src_modeldef = src_thing; + struct host_modeldef *dst_modeldef = dst_thing; + dst_modeldef->ptr_skel = PD_BE32(src_modeldef->ptr_skel); + dst_modeldef->numparts = PD_BE16(src_modeldef->numparts); + dst_modeldef->nummatrices = PD_BE16(src_modeldef->nummatrices); + dst_modeldef->scale = PD_BE32(src_modeldef->scale); + dst_modeldef->rwdatalen = PD_BE16(src_modeldef->rwdatalen); + dst_modeldef->numtexconfigs = PD_BE16(src_modeldef->numtexconfigs); + dstpos += sizeof(*dst_modeldef); + break; + } case CT_NODE: - struct n64_modelnode *src_node = src_thing; - struct modelnode *dst_node = dst_thing; - dst_node->type = PD_BE16(src_node->type); - dstpos += sizeof(*dst_node); - break; + { + struct n64_modelnode *src_node = src_thing; + struct host_modelnode *dst_node = dst_thing; + dst_node->type = PD_BE16(src_node->type); + dstpos += sizeof(*dst_node); + break; + } case CT_TEXCONFIG: - struct n64_textureconfig *src_texconfig = src_thing; - struct textureconfig *dst_texconfig = dst_thing; + { + struct n64_textureconfig *src_texconfig = src_thing; + struct host_textureconfig *dst_texconfig = dst_thing; - while (src_len >= sizeof(*src_texconfig)) { - if ((PD_BE32(src_texconfig->ptr) & 0xff000000) != 0x05000000) { - dst_texconfig->textureptr = (void *)(uintptr_t)PD_BE32(src_texconfig->ptr); + while (src_len >= sizeof(*src_texconfig)) { + if ((PD_BE32(src_texconfig->ptr) & 0xff000000) != 0x05000000) { + dst_texconfig->ptr = PD_BE32(src_texconfig->ptr); + } + + dst_texconfig->width = src_texconfig->width; + dst_texconfig->height = src_texconfig->height; + dst_texconfig->level = src_texconfig->level; + dst_texconfig->format = src_texconfig->format; + dst_texconfig->depth = src_texconfig->depth; + dst_texconfig->s = src_texconfig->s; + dst_texconfig->t = src_texconfig->t; + dst_texconfig->unk0b = src_texconfig->unk0b; + + dstpos += sizeof(*dst_texconfig); + src_len -= sizeof(*src_texconfig); + src_texconfig++; + dst_texconfig++; } - - dst_texconfig->width = src_texconfig->width; - dst_texconfig->height = src_texconfig->height; - dst_texconfig->level = src_texconfig->level; - dst_texconfig->format = src_texconfig->format; - dst_texconfig->depth = src_texconfig->depth; - dst_texconfig->s = src_texconfig->s; - dst_texconfig->t = src_texconfig->t; - dst_texconfig->unk0b = src_texconfig->unk0b; - - dstpos += sizeof(*dst_texconfig); - src_len -= sizeof(*src_texconfig); - src_texconfig++; - dst_texconfig++; + break; } - break; case CT_TEXDATA: - memcpy(dst_thing, src_thing, src_len); - dstpos += src_len; - break; + { + memcpy(dst_thing, src_thing, src_len); + dstpos += src_len; + break; + } case CT_PARTS: - struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; - u32 *src_parts = (u32 *) src_thing; - uintptr_t *dst_parts = (uintptr_t *) dst_thing; - int num_parts = PD_BE16(src_modeldef2->numparts); - u16 *src_nums = (u16 *) &src_parts[num_parts]; - u16 *dst_nums = (u16 *) &dst_parts[num_parts]; + { + struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; + u32 *src_parts = (u32 *) src_thing; + uintptr_t *dst_parts = (uintptr_t *) dst_thing; + int num_parts = PD_BE16(src_modeldef2->numparts); + u16 *src_nums = (u16 *) &src_parts[num_parts]; + u16 *dst_nums = (u16 *) &dst_parts[num_parts]; - for (int i = 0; i < num_parts; i++) { - dst_nums[i] = PD_BE16(src_nums[i]); + for (int i = 0; i < num_parts; i++) { + dst_nums[i] = PD_BE16(src_nums[i]); + } + dstpos += num_parts * sizeof(uintptr_t) + num_parts * sizeof(u16); + if (num_parts) { + dstpos = ALIGN8(dstpos); + } + break; } - dstpos += num_parts * sizeof(uintptr_t) + num_parts * sizeof(u16); - if (num_parts) { - dstpos = ALIGN8(dstpos); - } - break; case CT_VTXCOL: case CT_VTXCOL4: - memcpy(dst_thing, src_thing, src_len); - dstpos += src_len; - break; + { + memcpy(dst_thing, src_thing, src_len); + dstpos += src_len; + break; + } case CT_GDL: - struct marker *parent = findMarker(marker->parent_src_offset); - u32 src_vtx; - u32 dst_vtx; + { + struct marker *parent = findMarker(marker->parent_src_offset); + u32 src_vtx; + u32 dst_vtx; - if (parent->type == CT_RODATA_GUNDL) { - struct n64_modelrodata_gundl *src_rodata = (struct n64_modelrodata_gundl *) &src[parent->src_offset]; - struct modelrodata_gundl *dst_rodata = (struct modelrodata_gundl *) &dst[parent->dst_offset]; - src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; - dst_vtx = ((uintptr_t)dst_rodata->vertices) & 0x00ffffff; - } else if (parent->type == CT_RODATA_STARGUNFIRE) { - struct n64_modelrodata_stargunfire *src_rodata = (struct n64_modelrodata_stargunfire *) &src[parent->src_offset]; - struct modelrodata_stargunfire *dst_rodata = (struct modelrodata_stargunfire *) &dst[parent->dst_offset]; - src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; - dst_vtx = ((uintptr_t)dst_rodata->vertices) & 0x00ffffff; - } else if (parent->type == CT_RODATA_DL) { - struct n64_modelrodata_dl *src_rodata = (struct n64_modelrodata_dl *) &src[parent->src_offset]; - struct modelrodata_dl *dst_rodata = (struct modelrodata_dl *) &dst[parent->dst_offset]; - src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; - dst_vtx = ((uintptr_t)dst_rodata->vertices) & 0x00ffffff; + if (parent->type == CT_RODATA_GUNDL) { + struct n64_rodata_gundl *src_rodata = (struct n64_rodata_gundl *) &src[parent->src_offset]; + struct host_rodata_gundl *dst_rodata = (struct host_rodata_gundl *) &dst[parent->dst_offset]; + src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; + dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff; + } else if (parent->type == CT_RODATA_STARGUNFIRE) { + struct n64_rodata_stargunfire *src_rodata = (struct n64_rodata_stargunfire *) &src[parent->src_offset]; + struct host_rodata_stargunfire *dst_rodata = (struct host_rodata_stargunfire *) &dst[parent->dst_offset]; + src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; + dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff; + } else if (parent->type == CT_RODATA_DL) { + struct n64_rodata_dl *src_rodata = (struct n64_rodata_dl *) &src[parent->src_offset]; + struct host_rodata_dl *dst_rodata = (struct host_rodata_dl *) &dst[parent->dst_offset]; + src_vtx = PD_BE32(src_rodata->ptr_vertices) & 0x00ffffff; + dst_vtx = (dst_rodata->ptr_vertices) & 0x00ffffff; + } + + dstpos = gbiConvertGdl(dst, dstpos, src, marker->src_offset, 0); + break; } - - dstpos = gbiConvertGdl(dst, dstpos, src, marker->src_offset, 0); - break; case CT_RODATA_CHRINFO: - struct modelrodata_chrinfo *src_chrinfo = src_thing; - struct modelrodata_chrinfo *dst_chrinfo = dst_thing; - dst_chrinfo->animpart = PD_BE16(src_chrinfo->animpart); - dst_chrinfo->mtxindex = PD_BE16(src_chrinfo->mtxindex); - dst_chrinfo->unk04 = PD_BE32(src_chrinfo->unk04); - dst_chrinfo->rwdataindex = PD_BE16(src_chrinfo->rwdataindex); - dstpos += sizeof(*dst_chrinfo); - break; + { + struct generic_rodata_chrinfo *src_chrinfo = src_thing; + struct generic_rodata_chrinfo *dst_chrinfo = dst_thing; + dst_chrinfo->animpart = PD_BE16(src_chrinfo->animpart); + dst_chrinfo->mtxindex = PD_BE16(src_chrinfo->mtxindex); + dst_chrinfo->unk04 = PD_BE32(src_chrinfo->unk04); + dst_chrinfo->rwdataindex = PD_BE16(src_chrinfo->rwdataindex); + dstpos += sizeof(*dst_chrinfo); + break; + } case CT_RODATA_POSITION: - struct modelrodata_position *src_position = src_thing; - struct modelrodata_position *dst_position = dst_thing; - dst_position->pos = PD_SWAPPED_VAL(src_position->pos); - dst_position->part = PD_BE16(src_position->part); - dst_position->mtxindexes[0] = PD_BE16(src_position->mtxindexes[0]); - dst_position->mtxindexes[1] = PD_BE16(src_position->mtxindexes[1]); - dst_position->mtxindexes[2] = PD_BE16(src_position->mtxindexes[2]); - dst_position->drawdist = PD_SWAPPED_VAL(src_position->drawdist); - dstpos += sizeof(*dst_position); - break; + { + struct generic_rodata_position *src_position = src_thing; + struct generic_rodata_position *dst_position = dst_thing; + dst_position->pos[0] = PD_BE32(src_position->pos[0]); + dst_position->pos[1] = PD_BE32(src_position->pos[1]); + dst_position->pos[2] = PD_BE32(src_position->pos[2]); + dst_position->part = PD_BE16(src_position->part); + dst_position->mtxindexes[0] = PD_BE16(src_position->mtxindexes[0]); + dst_position->mtxindexes[1] = PD_BE16(src_position->mtxindexes[1]); + dst_position->mtxindexes[2] = PD_BE16(src_position->mtxindexes[2]); + dst_position->drawdist = PD_BE32(src_position->drawdist); + dstpos += sizeof(*dst_position); + break; + } case CT_RODATA_GUNDL: - struct n64_modelrodata_gundl *src_gundl = src_thing; - struct modelrodata_gundl *dst_gundl = dst_thing; - dst_gundl->vertices = NULL; - dst_gundl->numvertices = PD_BE16(src_gundl->numvertices); - dst_gundl->unk12 = PD_BE16(src_gundl->unk12); - dstpos += sizeof(*dst_gundl); - break; + { + struct n64_rodata_gundl *src_gundl = src_thing; + struct host_rodata_gundl *dst_gundl = dst_thing; + dst_gundl->ptr_vertices = 0; + dst_gundl->numvertices = PD_BE16(src_gundl->numvertices); + dst_gundl->unk12 = PD_BE16(src_gundl->unk12); + dstpos += sizeof(*dst_gundl); + break; + } case CT_RODATA_DISTANCE: - struct n64_modelrodata_distance *src_dist = src_thing; - struct modelrodata_distance *dst_dist = dst_thing; - dst_dist->near = PD_SWAPPED_VAL(src_dist->near); - dst_dist->far = PD_SWAPPED_VAL(src_dist->far); - dst_dist->rwdataindex = PD_BE16(src_dist->rwdataindex); - dstpos += sizeof(*dst_dist); - break; + { + struct n64_rodata_distance *src_dist = src_thing; + struct host_rodata_distance *dst_dist = dst_thing; + dst_dist->near = PD_BE32(src_dist->near); + dst_dist->far = PD_BE32(src_dist->far); + dst_dist->rwdataindex = PD_BE16(src_dist->rwdataindex); + dstpos += sizeof(*dst_dist); + break; + } case CT_RODATA_REORDER: - struct n64_modelrodata_reorder *src_reorder = src_thing; - struct modelrodata_reorder *dst_reorder = dst_thing; - dst_reorder->unk00 = PD_SWAPPED_VAL(src_reorder->unk00); - dst_reorder->unk04 = PD_SWAPPED_VAL(src_reorder->unk04); - dst_reorder->unk08 = PD_SWAPPED_VAL(src_reorder->unk08); - dst_reorder->unk0c[0] = PD_SWAPPED_VAL(src_reorder->unk0c[0]); - dst_reorder->unk0c[1] = PD_SWAPPED_VAL(src_reorder->unk0c[1]); - dst_reorder->unk0c[2] = PD_SWAPPED_VAL(src_reorder->unk0c[2]); - dst_reorder->side = PD_BE16(src_reorder->side); - dst_reorder->rwdataindex = PD_BE16(src_reorder->rwdataindex); - dstpos += sizeof(*dst_reorder); - break; + { + struct n64_rodata_reorder *src_reorder = src_thing; + struct host_rodata_reorder *dst_reorder = dst_thing; + dst_reorder->unk00 = PD_BE32(src_reorder->unk00); + dst_reorder->unk04 = PD_BE32(src_reorder->unk04); + dst_reorder->unk08 = PD_BE32(src_reorder->unk08); + dst_reorder->unk0c[0] = PD_BE32(src_reorder->unk0c[0]); + dst_reorder->unk0c[1] = PD_BE32(src_reorder->unk0c[1]); + dst_reorder->unk0c[2] = PD_BE32(src_reorder->unk0c[2]); + dst_reorder->side = PD_BE16(src_reorder->side); + dst_reorder->rwdataindex = PD_BE16(src_reorder->rwdataindex); + dstpos += sizeof(*dst_reorder); + break; + } case CT_RODATA_BBOX: - struct modelrodata_bbox *src_bbox = src_thing; - struct modelrodata_bbox *dst_bbox = dst_thing; - dst_bbox->hitpart = PD_BE32(src_bbox->hitpart); - dst_bbox->xmin = PD_SWAPPED_VAL(src_bbox->xmin); - dst_bbox->xmax = PD_SWAPPED_VAL(src_bbox->xmax); - dst_bbox->ymin = PD_SWAPPED_VAL(src_bbox->ymin); - dst_bbox->ymax = PD_SWAPPED_VAL(src_bbox->ymax); - dst_bbox->zmin = PD_SWAPPED_VAL(src_bbox->zmin); - dst_bbox->zmax = PD_SWAPPED_VAL(src_bbox->zmax); - dstpos += sizeof(*dst_bbox); - break; + { + struct generic_rodata_bbox *src_bbox = src_thing; + struct generic_rodata_bbox *dst_bbox = dst_thing; + dst_bbox->hitpart = PD_BE32(src_bbox->hitpart); + dst_bbox->bbox[0] = PD_BE32(src_bbox->bbox[0]); + dst_bbox->bbox[1] = PD_BE32(src_bbox->bbox[1]); + dst_bbox->bbox[2] = PD_BE32(src_bbox->bbox[2]); + dst_bbox->bbox[3] = PD_BE32(src_bbox->bbox[3]); + dst_bbox->bbox[4] = PD_BE32(src_bbox->bbox[4]); + dst_bbox->bbox[5] = PD_BE32(src_bbox->bbox[5]); + dstpos += sizeof(*dst_bbox); + break; + } case CT_RODATA_CHRGUNFIRE: - struct n64_modelrodata_chrgunfire *src_chrgunfire = src_thing; - struct modelrodata_chrgunfire *dst_chrgunfire = dst_thing; - dst_chrgunfire->pos = PD_SWAPPED_VAL(src_chrgunfire->pos); - dst_chrgunfire->dim = PD_SWAPPED_VAL(src_chrgunfire->dim); - dst_chrgunfire->unk1c = PD_SWAPPED_VAL(src_chrgunfire->unk1c); - dst_chrgunfire->rwdataindex = PD_BE16(src_chrgunfire->rwdataindex); - dst_chrgunfire->baseaddr = NULL; - dstpos += sizeof(*dst_chrgunfire); - break; + { + struct n64_rodata_chrgunfire *src_chrgunfire = src_thing; + struct host_rodata_chrgunfire *dst_chrgunfire = dst_thing; + dst_chrgunfire->pos[0] = PD_BE32(src_chrgunfire->pos[0]); + dst_chrgunfire->pos[1] = PD_BE32(src_chrgunfire->pos[1]); + dst_chrgunfire->pos[2] = PD_BE32(src_chrgunfire->pos[2]); + dst_chrgunfire->dim[0] = PD_BE32(src_chrgunfire->dim[0]); + dst_chrgunfire->dim[1] = PD_BE32(src_chrgunfire->dim[1]); + dst_chrgunfire->dim[2] = PD_BE32(src_chrgunfire->dim[2]); + dst_chrgunfire->unk1c = PD_BE32(src_chrgunfire->unk1c); + dst_chrgunfire->rwdataindex = PD_BE16(src_chrgunfire->rwdataindex); + dst_chrgunfire->ptr_baseaddr = 0; + dstpos += sizeof(*dst_chrgunfire); + break; + } case CT_RODATA_11: - struct n64_modelrodata_type11 *src_type11 = src_thing; - struct modelrodata_type11 *dst_type11 = dst_thing; - dst_type11->unk00 = PD_BE32(src_type11->unk00); - dst_type11->unk04 = PD_BE32(src_type11->unk04); - dst_type11->unk08 = PD_BE32(src_type11->unk08); - dst_type11->unk0c = PD_BE32(src_type11->unk0c); - dst_type11->unk10 = PD_BE32(src_type11->unk10); - dst_type11->unk14 = NULL; - dst_type11->unk18 = PD_BE32(src_type11->extra1); - dst_type11->unk1c = PD_BE32(src_type11->extra2); - dstpos += sizeof(*dst_type11); - break; + { + struct n64_rodata_type11 *src_type11 = src_thing; + struct host_rodata_type11 *dst_type11 = dst_thing; + dst_type11->unk00 = PD_BE32(src_type11->unk00); + dst_type11->unk04 = PD_BE32(src_type11->unk04); + dst_type11->unk08 = PD_BE32(src_type11->unk08); + dst_type11->unk0c = PD_BE32(src_type11->unk0c); + dst_type11->unk10 = PD_BE32(src_type11->unk10); + dst_type11->extra1 = PD_BE32(src_type11->extra1); + dst_type11->extra2 = PD_BE32(src_type11->extra2); + dstpos += sizeof(*dst_type11); + break; + } case CT_RODATA_TOGGLE: - struct n64_modelrodata_toggle *src_toggle = src_thing; - struct modelrodata_toggle *dst_toggle = dst_thing; - dst_toggle->rwdataindex = PD_BE16(src_toggle->rwdataindex); - dstpos += sizeof(*dst_toggle); - break; + { + struct n64_rodata_toggle *src_toggle = src_thing; + struct host_rodata_toggle *dst_toggle = dst_thing; + dst_toggle->rwdataindex = PD_BE16(src_toggle->rwdataindex); + dstpos += sizeof(*dst_toggle); + break; + } case CT_RODATA_POSITIONHELD: - struct modelrodata_positionheld *src_posheld = src_thing; - struct modelrodata_positionheld *dst_posheld = dst_thing; - dst_posheld->pos = PD_SWAPPED_VAL(src_posheld->pos); - dst_posheld->mtxindex = PD_BE16(src_posheld->mtxindex); - dst_posheld->unk10 = PD_BE32(src_posheld->unk10); - dstpos += sizeof(*dst_posheld); - break; + { + struct generic_rodata_positionheld *src_posheld = src_thing; + struct generic_rodata_positionheld *dst_posheld = dst_thing; + dst_posheld->pos[0] = PD_BE32(src_posheld->pos[0]); + dst_posheld->pos[1] = PD_BE32(src_posheld->pos[1]); + dst_posheld->pos[2] = PD_BE32(src_posheld->pos[2]); + dst_posheld->mtxindex = PD_BE16(src_posheld->mtxindex); + dst_posheld->unk10 = PD_BE32(src_posheld->unk10); + dstpos += sizeof(*dst_posheld); + break; + } case CT_RODATA_STARGUNFIRE: - struct n64_modelrodata_stargunfire *src_stargunfire = src_thing; - struct modelrodata_stargunfire *dst_stargunfire = dst_thing; - dst_stargunfire->unk00 = PD_BE32(src_stargunfire->unk00); - dstpos += sizeof(*dst_stargunfire); - break; + { + struct n64_rodata_stargunfire *src_stargunfire = src_thing; + struct host_rodata_stargunfire *dst_stargunfire = dst_thing; + dst_stargunfire->unk00 = PD_BE32(src_stargunfire->unk00); + dstpos += sizeof(*dst_stargunfire); + break; + } case CT_RODATA_HEADSPOT: - struct modelrodata_headspot *src_headspot = src_thing; - struct modelrodata_headspot *dst_headspot = dst_thing; - dst_headspot->rwdataindex = PD_BE16(src_headspot->rwdataindex); - dstpos += sizeof(*dst_headspot); - break; + { + struct generic_rodata_headspot *src_headspot = src_thing; + struct generic_rodata_headspot *dst_headspot = dst_thing; + dst_headspot->rwdataindex = PD_BE16(src_headspot->rwdataindex); + dstpos += sizeof(*dst_headspot); + break; + } case CT_RODATA_DL: - struct n64_modelrodata_dl *src_dl = src_thing; - struct modelrodata_dl *dst_dl = dst_thing; - dst_dl->numvertices = PD_BE16(src_dl->numvertices); - dst_dl->mcount = PD_BE16(src_dl->mcount); - dst_dl->rwdataindex = PD_BE16(src_dl->rwdataindex); - dst_dl->numcolours = PD_BE16(src_dl->numcolours); - dstpos += sizeof(*dst_dl); - break; + { + struct n64_rodata_dl *src_dl = src_thing; + struct host_rodata_dl *dst_dl = dst_thing; + dst_dl->numvertices = PD_BE16(src_dl->numvertices); + dst_dl->mcount = PD_BE16(src_dl->mcount); + dst_dl->rwdataindex = PD_BE16(src_dl->rwdataindex); + dst_dl->numcolours = PD_BE16(src_dl->numcolours); + dstpos += sizeof(*dst_dl); + break; + } case CT_RODATA_19: - struct modelrodata_type19 *src_type19 = src_thing; - struct modelrodata_type19 *dst_type19 = dst_thing; - u32 *src_vertices = src_thing + sizeof(u32); - u32 *dst_vertices = dst_thing + sizeof(u32); - int num_vertices = PD_BE32(src_type19->numvertices); + { + struct generic_rodata_type19 *src_type19 = src_thing; + struct generic_rodata_type19 *dst_type19 = dst_thing; + u32 *src_vertices = src_thing + sizeof(u32); + u32 *dst_vertices = dst_thing + sizeof(u32); + int num_vertices = PD_BE32(src_type19->numvertices); - dst_type19->numvertices = (num_vertices); - dstpos += sizeof(u32); + dst_type19->numvertices = (num_vertices); + dstpos += sizeof(u32); - for (int i = 0; i < num_vertices; i++) { - dst_vertices[i * 3 + 0] = PD_BE32(src_vertices[i * 3 + 0]); - dst_vertices[i * 3 + 1] = PD_BE32(src_vertices[i * 3 + 1]); - dst_vertices[i * 3 + 2] = PD_BE32(src_vertices[i * 3 + 2]); - dstpos += sizeof(u32) * 3; + for (int i = 0; i < num_vertices; i++) { + dst_vertices[i * 3 + 0] = PD_BE32(src_vertices[i * 3 + 0]); + dst_vertices[i * 3 + 1] = PD_BE32(src_vertices[i * 3 + 1]); + dst_vertices[i * 3 + 2] = PD_BE32(src_vertices[i * 3 + 2]); + dstpos += sizeof(u32) * 3; + } + break; } - break; case CT_SKIP: break; } @@ -655,125 +864,146 @@ static u8 *relinkPointers(u8 *dst, u8 *src) switch (marker->type) { case CT_MODELDEF: - struct n64_modeldef *src_modeldef = src_thing; - struct modeldef *dst_modeldef = dst_thing; - dst_modeldef->rootnode = (void *)(uintptr_t)resolvePointer(PD_BE32(src_modeldef->ptr_rootnode)); - dst_modeldef->parts = (void *)(uintptr_t)resolvePointer(PD_BE32(src_modeldef->ptr_parts)); - dst_modeldef->texconfigs = (void *)(uintptr_t)resolvePointer(PD_BE32(src_modeldef->ptr_texconfigs)); - break; + { + struct n64_modeldef *src_modeldef = src_thing; + struct host_modeldef *dst_modeldef = dst_thing; + dst_modeldef->ptr_rootnode = (resolvePointer(PD_BE32(src_modeldef->ptr_rootnode))); + dst_modeldef->ptr_parts = (resolvePointer(PD_BE32(src_modeldef->ptr_parts))); + dst_modeldef->ptr_texconfigs = (resolvePointer(PD_BE32(src_modeldef->ptr_texconfigs))); + break; + } case CT_NODE: - struct n64_modelnode *src_node = src_thing; - struct modelnode *dst_node = dst_thing; - dst_node->rodata = (void *)(uintptr_t)resolvePointer(PD_BE32(src_node->ptr_rodata)); - dst_node->parent = (void *)(uintptr_t)resolvePointer(PD_BE32(src_node->ptr_parent)); - dst_node->next = (void *)(uintptr_t)resolvePointer(PD_BE32(src_node->ptr_next)); - dst_node->prev = (void *)(uintptr_t)resolvePointer(PD_BE32(src_node->ptr_prev)); - dst_node->child = (void *)(uintptr_t)resolvePointer(PD_BE32(src_node->ptr_child)); + { + struct n64_modelnode *src_node = src_thing; + struct host_modelnode *dst_node = dst_thing; + dst_node->ptr_rodata = (resolvePointer(PD_BE32(src_node->ptr_rodata))); + dst_node->ptr_parent = (resolvePointer(PD_BE32(src_node->ptr_parent))); + dst_node->ptr_next = (resolvePointer(PD_BE32(src_node->ptr_next))); + dst_node->ptr_prev = (resolvePointer(PD_BE32(src_node->ptr_prev))); + dst_node->ptr_child = (resolvePointer(PD_BE32(src_node->ptr_child))); - lowestptr = (uintptr_t)dst_node->rodata; - break; + lowestptr = dst_node->ptr_rodata; + break; + } case CT_TEXCONFIG: - struct n64_textureconfig *src_texconfig = src_thing; - struct textureconfig *dst_texconfig = dst_thing; - if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) { - dst_texconfig->textureptr = (void *)(uintptr_t)resolvePointer(PD_BE32(src_texconfig->ptr)); - gbiAddTexAddr(PD_BE32(src_texconfig->ptr), (uintptr_t)dst_texconfig->textureptr); + { + struct n64_textureconfig *src_texconfig = src_thing; + struct host_textureconfig *dst_texconfig = dst_thing; + if ((PD_BE32(src_texconfig->ptr) & 0xff000000) == 0x05000000) { + dst_texconfig->ptr = (resolvePointer(PD_BE32(src_texconfig->ptr))); + gbiAddTexAddr(PD_BE32(src_texconfig->ptr), dst_texconfig->ptr); + } + break; } - break; case CT_PARTS: - struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; - u32 *src_parts = (u32 *) src_thing; - uintptr_t *dst_parts = (uintptr_t *) dst_thing; - int num_parts = PD_BE16(src_modeldef2->numparts); + { + struct n64_modeldef *src_modeldef2 = (struct n64_modeldef *) src; + u32 *src_parts = (u32 *) src_thing; + uintptr_t *dst_parts = (uintptr_t *) dst_thing; + int num_parts = PD_BE16(src_modeldef2->numparts); - for (int i = 0; i < num_parts; i++) { - dst_parts[i] = (resolvePointer(PD_BE32(src_parts[i]))); + for (int i = 0; i < num_parts; i++) { + dst_parts[i] = (resolvePointer(PD_BE32(src_parts[i]))); + } + break; } - break; case CT_RODATA_CHRINFO: - break; case CT_RODATA_POSITION: break; case CT_RODATA_GUNDL: - struct n64_modelrodata_gundl *src_gundl = src_thing; - struct modelrodata_gundl *dst_gundl = dst_thing; - dst_gundl->opagdl = (void *)(uintptr_t)resolvePointer(PD_BE32(src_gundl->ptr_opagdl)); - dst_gundl->xlugdl = (void *)(uintptr_t)resolvePointer(PD_BE32(src_gundl->ptr_xlugdl)); - dst_gundl->vertices = (void *)(uintptr_t)resolvePointer(PD_BE32(src_gundl->ptr_vertices)); - - gbiConvertVtx(dst, ((uintptr_t)dst_gundl->vertices) & 0x00ffffff, dst_gundl->numvertices); + { + struct n64_rodata_gundl *src_gundl = src_thing; + struct host_rodata_gundl *dst_gundl = dst_thing; + dst_gundl->ptr_opagdl = (resolvePointer(PD_BE32(src_gundl->ptr_opagdl))); + dst_gundl->ptr_xlugdl = (resolvePointer(PD_BE32(src_gundl->ptr_xlugdl))); + dst_gundl->ptr_vertices = (resolvePointer(PD_BE32(src_gundl->ptr_vertices))); + + gbiConvertVtx(dst, dst_gundl->ptr_vertices & 0x00ffffff, dst_gundl->numvertices); - gbiSetVtx(PD_BE32(src_gundl->ptr_vertices), (uintptr_t)dst_gundl->vertices); - gbiSetSegment(0x04, (uintptr_t)dst_gundl->vertices); + gbiSetVtx(PD_BE32(src_gundl->ptr_vertices), dst_gundl->ptr_vertices); + gbiSetSegment(0x04, dst_gundl->ptr_vertices); - gbiGdlRewriteAddrs(dst, (uintptr_t)dst_gundl->opagdl); - gbiGdlRewriteAddrs(dst, (uintptr_t)dst_gundl->xlugdl); + gbiGdlRewriteAddrs(dst, dst_gundl->ptr_opagdl); + gbiGdlRewriteAddrs(dst, dst_gundl->ptr_xlugdl); - if (dst_gundl->opagdl) dst_gundl->opagdl = SEGADDR(dst_gundl->opagdl); - if (dst_gundl->xlugdl) dst_gundl->xlugdl = SEGADDR(dst_gundl->xlugdl); + if (dst_gundl->ptr_opagdl) dst_gundl->ptr_opagdl |= 1; + if (dst_gundl->ptr_xlugdl) dst_gundl->ptr_xlugdl |= 1; - lowestptr = minPtr3((uintptr_t)dst_gundl->opagdl, (uintptr_t)dst_gundl->xlugdl, (uintptr_t)dst_gundl->vertices); - break; + lowestptr = minPtr3(dst_gundl->ptr_opagdl, dst_gundl->ptr_xlugdl, dst_gundl->ptr_vertices); + break; + } case CT_RODATA_DISTANCE: - struct n64_modelrodata_distance *src_dist = src_thing; - struct modelrodata_distance *dst_dist = dst_thing; - dst_dist->target = (void *)(uintptr_t)resolvePointer(PD_BE32(src_dist->ptr_target)); - break; + { + struct n64_rodata_distance *src_dist = src_thing; + struct host_rodata_distance *dst_dist = dst_thing; + dst_dist->ptr_target = (resolvePointer(PD_BE32(src_dist->ptr_target))); + break; + } case CT_RODATA_REORDER: - struct n64_modelrodata_reorder *src_reorder = src_thing; - struct modelrodata_reorder *dst_reorder = dst_thing; - dst_reorder->unk18 = (void *)(uintptr_t)resolvePointer(PD_BE32(src_reorder->ptr_node_unk18)); - dst_reorder->unk1c = (void *)(uintptr_t)resolvePointer(PD_BE32(src_reorder->ptr_node_unk1c)); - break; + { + struct n64_rodata_reorder *src_reorder = src_thing; + struct host_rodata_reorder *dst_reorder = dst_thing; + dst_reorder->ptr_node_unk18 = (resolvePointer(PD_BE32(src_reorder->ptr_node_unk18))); + dst_reorder->ptr_node_unk1c = (resolvePointer(PD_BE32(src_reorder->ptr_node_unk1c))); + break; + } case CT_RODATA_CHRGUNFIRE: - struct n64_modelrodata_chrgunfire *src_chrgunfire = src_thing; - struct modelrodata_chrgunfire *dst_chrgunfire = dst_thing; - dst_chrgunfire->texture = (void *)(uintptr_t)resolvePointer(PD_BE32(src_chrgunfire->ptr_texture)); - if ((PD_BE32((u32)(uintptr_t)dst_chrgunfire->texture) & 0xff000000) == 0x05000000) { - gbiAddTexAddr(PD_BE32((u32)(uintptr_t)dst_chrgunfire->texture), (uintptr_t)dst_chrgunfire->texture); + { + struct n64_rodata_chrgunfire *src_chrgunfire = src_thing; + struct host_rodata_chrgunfire *dst_chrgunfire = dst_thing; + dst_chrgunfire->ptr_texture = (resolvePointer(PD_BE32(src_chrgunfire->ptr_texture))); + if ((PD_BE32(dst_chrgunfire->ptr_texture) & 0xff000000) == 0x05000000) { + gbiAddTexAddr(PD_BE32(dst_chrgunfire->ptr_texture), dst_chrgunfire->ptr_texture); + } + break; } - break; case CT_RODATA_TOGGLE: - struct n64_modelrodata_toggle *src_toggle = src_thing; - struct modelrodata_toggle *dst_toggle = dst_thing; - dst_toggle->target = (void *)(uintptr_t)resolvePointer(PD_BE32(src_toggle->ptr_target)); - break; + { + struct n64_rodata_toggle *src_toggle = src_thing; + struct host_rodata_toggle *dst_toggle = dst_thing; + dst_toggle->ptr_target = (resolvePointer(PD_BE32(src_toggle->ptr_target))); + break; + } case CT_RODATA_STARGUNFIRE: - struct n64_modelrodata_stargunfire *src_stargunfire = src_thing; - struct modelrodata_stargunfire *dst_stargunfire = dst_thing; - dst_stargunfire->vertices = (void *)(uintptr_t)resolvePointer(PD_BE32(src_stargunfire->ptr_vertices)); - dst_stargunfire->gdl = (void *)(uintptr_t)resolvePointer(PD_BE32(src_stargunfire->ptr_gdl)); + { + struct n64_rodata_stargunfire *src_stargunfire = src_thing; + struct host_rodata_stargunfire *dst_stargunfire = dst_thing; + dst_stargunfire->ptr_vertices = (resolvePointer(PD_BE32(src_stargunfire->ptr_vertices))); + dst_stargunfire->ptr_gdl = (resolvePointer(PD_BE32(src_stargunfire->ptr_gdl))); - gbiConvertVtx(dst, ((uintptr_t)dst_stargunfire->vertices) & 0x00ffffff, dst_stargunfire->unk00*4); + gbiConvertVtx(dst, dst_stargunfire->ptr_vertices & 0x00ffffff, dst_stargunfire->unk00*4); - gbiSetVtx(PD_BE32(src_stargunfire->ptr_vertices), (uintptr_t)dst_stargunfire->vertices); - gbiSetSegment(0x04, (uintptr_t)dst_stargunfire->vertices); - gbiGdlRewriteAddrs(dst, (uintptr_t)dst_stargunfire->gdl); - if (dst_stargunfire->gdl) dst_stargunfire->gdl = SEGADDR(dst_stargunfire->gdl); + gbiSetVtx(PD_BE32(src_stargunfire->ptr_vertices), dst_stargunfire->ptr_vertices); + gbiSetSegment(0x04, dst_stargunfire->ptr_vertices); + gbiGdlRewriteAddrs(dst, dst_stargunfire->ptr_gdl); + if (dst_stargunfire->ptr_gdl) dst_stargunfire->ptr_gdl |= 1; - lowestptr = minPtr((uintptr_t)dst_stargunfire->gdl, (uintptr_t)dst_stargunfire->vertices); - break; + lowestptr = minPtr(dst_stargunfire->ptr_gdl, dst_stargunfire->ptr_vertices); + break; + } case CT_RODATA_DL: - struct n64_modelrodata_dl *src_dl = src_thing; - struct modelrodata_dl *dst_dl = dst_thing; - dst_dl->opagdl = (void *)(uintptr_t)resolvePointer(PD_BE32(src_dl->ptr_opagdl)); - dst_dl->xlugdl = (void *)(uintptr_t)resolvePointer(PD_BE32(src_dl->ptr_xlugdl)); - dst_dl->colours = (void *)(uintptr_t)resolvePointer(PD_BE32(src_dl->ptr_colours)); - dst_dl->vertices = (void *)(uintptr_t)resolvePointer(PD_BE32(src_dl->ptr_vertices)); - - gbiConvertVtx(dst, ((uintptr_t)dst_dl->vertices) & 0x00ffffff, dst_dl->numvertices); + { + struct n64_rodata_dl *src_dl = src_thing; + struct host_rodata_dl *dst_dl = dst_thing; + dst_dl->ptr_opagdl = (resolvePointer(PD_BE32(src_dl->ptr_opagdl))); + dst_dl->ptr_xlugdl = (resolvePointer(PD_BE32(src_dl->ptr_xlugdl))); + dst_dl->ptr_colours = (resolvePointer(PD_BE32(src_dl->ptr_colours))); + dst_dl->ptr_vertices = (resolvePointer(PD_BE32(src_dl->ptr_vertices))); + + gbiConvertVtx(dst, dst_dl->ptr_vertices & 0x00ffffff, dst_dl->numvertices); - gbiSetVtx(PD_BE32(src_dl->ptr_vertices), (uintptr_t)dst_dl->vertices); - gbiSetSegment(0x04, (uintptr_t)dst_dl->vertices); - gbiGdlRewriteAddrs(dst, (uintptr_t)dst_dl->opagdl); - gbiGdlRewriteAddrs(dst, (uintptr_t)dst_dl->xlugdl); - - if (dst_dl->opagdl) dst_dl->opagdl = SEGADDR(dst_dl->opagdl); - if (dst_dl->xlugdl) dst_dl->xlugdl = SEGADDR(dst_dl->xlugdl); + gbiSetVtx(PD_BE32(src_dl->ptr_vertices), dst_dl->ptr_vertices); + gbiSetSegment(0x04, dst_dl->ptr_vertices); + gbiGdlRewriteAddrs(dst, dst_dl->ptr_opagdl); + gbiGdlRewriteAddrs(dst, dst_dl->ptr_xlugdl); + + if (dst_dl->ptr_opagdl) dst_dl->ptr_opagdl |= 1; + if (dst_dl->ptr_xlugdl) dst_dl->ptr_xlugdl |= 1; - lowestptr = minPtr3((uintptr_t)dst_dl->opagdl, (uintptr_t)dst_dl->xlugdl, (uintptr_t)dst_dl->colours); - lowestptr = minPtr(lowestptr, (uintptr_t)dst_dl->vertices); - break; + lowestptr = minPtr3(dst_dl->ptr_opagdl, dst_dl->ptr_xlugdl, dst_dl->ptr_colours); + lowestptr = minPtr(lowestptr, dst_dl->ptr_vertices); + break; + } case CT_TEXDATA: case CT_VTXCOL: case CT_VTXCOL4: diff --git a/port/src/preprocess/filepads.c b/port/src/preprocess/filepads.c index 1ba7e59d2..84dafe405 100644 --- a/port/src/preprocess/filepads.c +++ b/port/src/preprocess/filepads.c @@ -235,7 +235,6 @@ static u32 convertCover(u8 *dst, u32 dstpos, u8 *src, u32 srcpos, int num_covers host_covers[i].pos = PD_SWAPPED_VAL(n64_covers[i].pos); host_covers[i].look = PD_SWAPPED_VAL(n64_covers[i].look); host_covers[i].flags = PD_BE16(n64_covers[i].flags); - host_covers[i].unk1a = PD_BE16(n64_covers[i].unk1a); } dstpos += num_covers * sizeof(struct coverdefinition); diff --git a/port/src/preprocess/filesetup.c b/port/src/preprocess/filesetup.c index 5e5ab9cc9..3d764cdf7 100644 --- a/port/src/preprocess/filesetup.c +++ b/port/src/preprocess/filesetup.c @@ -1003,7 +1003,7 @@ static u32 convertProps(u8* dst, u8* src) static uintptr_t convertIntro(u8 *dst, u8 *src) { - u8 cmd_size[] = { + static const u8 cmd_size[] = { 3, // INTROCMD_SPAWN 4, // INTROCMD_WEAPON 4, // INTROCMD_AMMO diff --git a/port/src/video.c b/port/src/video.c index 63be72f54..52eafc228 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -12,16 +12,28 @@ #include "../fast3d/gfx_sdl.h" #include "../fast3d/gfx_opengl.h" +#ifdef PLATFORM_NSWITCH +#define DEFAULT_VID_WIDTH 1280 +#define DEFAULT_VID_HEIGHT 720 +#define DEFAULT_VID_FULLSCREEN true +#define DEFAULT_VID_FULLSCREEN_EXCLUSIVE true +#else +#define DEFAULT_VID_WIDTH 640 +#define DEFAULT_VID_HEIGHT 480 +#define DEFAULT_VID_FULLSCREEN false +#define DEFAULT_VID_FULLSCREEN_EXCLUSIVE false +#endif + static struct GfxWindowManagerAPI *wmAPI; static struct GfxRenderingAPI *renderingAPI; static bool initDone = false; -static s32 vidWidth = 640; -static s32 vidHeight = 480; +static s32 vidWidth = DEFAULT_VID_WIDTH; +static s32 vidHeight = DEFAULT_VID_HEIGHT; static s32 vidFramebuffers = true; -static s32 vidFullscreen = false; -static s32 vidFullscreenExclusive = false; +static s32 vidFullscreen = DEFAULT_VID_FULLSCREEN; +static s32 vidFullscreenExclusive = DEFAULT_VID_FULLSCREEN_EXCLUSIVE; static s32 vidMaximize = false; static s32 vidAllowHiDpi = false; static s32 vidVsync = 1; diff --git a/src/game/bondmove.c b/src/game/bondmove.c index ede1b11d0..400cfa00c 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -907,7 +907,9 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i aimoffhist[i] = !aimonhist[i]; } - g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1]; + if (numsamples > 0) { + g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1]; + } } if (!lvIsPaused()) { @@ -1238,7 +1240,9 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i aimoffhist[i] = !aimonhist[i]; } - g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1]; + if (numsamples > 0) { + g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1]; + } } if (!lvIsPaused()) { diff --git a/src/game/invitems.c b/src/game/invitems.c index e7ccc6e43..89c7b0ed4 100644 --- a/src/game/invitems.c +++ b/src/game/invitems.c @@ -2848,7 +2848,7 @@ struct weapon invitem_rocketlauncher = { L_GUN_027, // name L_GUN_149, // manufacturer L_GUN_175, // description - WEAPONFLAG_AICANUSE | WEAPONFLAG_DUALFLIP | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_AIMTRACK, + WEAPONFLAG_AICANUSE | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_AIMTRACK, }; struct guncmd invanim_slayer_shoot[] = { @@ -3083,7 +3083,7 @@ struct weapon invitem_devastator = { L_GUN_028, // name L_GUN_149, // manufacturer L_GUN_176, // description - WEAPONFLAG_AICANUSE | WEAPONFLAG_DUALFLIP | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS, + WEAPONFLAG_AICANUSE | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS, }; struct weaponfunc invfunc_mine_threatdetector = { @@ -3476,7 +3476,7 @@ struct weapon invitem_grenade = { L_GUN_036, // name L_GUN_000, // manufacturer L_GUN_183, // description - WEAPONFLAG_THROWABLE | WEAPONFLAG_00000004 | WEAPONFLAG_ONEHANDED | WEAPONFLAG_AICANUSE | WEAPONFLAG_DUALFLIP | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00000400 | WEAPONFLAG_00002000 | WEAPONFLAG_00008000 | WEAPONFLAG_HASHANDS, + WEAPONFLAG_THROWABLE | WEAPONFLAG_00000004 | WEAPONFLAG_ONEHANDED | WEAPONFLAG_AICANUSE | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00000400 | WEAPONFLAG_00002000 | WEAPONFLAG_00008000 | WEAPONFLAG_HASHANDS, }; struct weaponfunc_throw invfunc_nbomb_throw = { @@ -3537,7 +3537,7 @@ struct weapon invitem_nbomb = { L_GUN_037, // name L_GUN_000, // manufacturer L_GUN_184, // description - WEAPONFLAG_THROWABLE | WEAPONFLAG_00000004 | WEAPONFLAG_ONEHANDED | WEAPONFLAG_AICANUSE | WEAPONFLAG_DUALFLIP | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00000400 | WEAPONFLAG_00002000 | WEAPONFLAG_00008000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_DETERMINER_S_AN | WEAPONFLAG_DETERMINER_F_AN, + WEAPONFLAG_THROWABLE | WEAPONFLAG_00000004 | WEAPONFLAG_ONEHANDED | WEAPONFLAG_AICANUSE | WEAPONFLAG_00000040 | WEAPONFLAG_TRACKTIMEUSED | WEAPONFLAG_00000400 | WEAPONFLAG_00002000 | WEAPONFLAG_00008000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_DETERMINER_S_AN | WEAPONFLAG_DETERMINER_F_AN, }; struct gunviscmd gunviscmds_farsight[] = { @@ -6131,7 +6131,7 @@ struct weapon invitem_rocketlauncher_34 = { L_GUN_027, // name L_GUN_000, // manufacturer L_GUN_000, // description - WEAPONFLAG_AICANUSE | WEAPONFLAG_DUALFLIP | WEAPONFLAG_00000040 | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_AIMTRACK, + WEAPONFLAG_AICANUSE | WEAPONFLAG_00000040 | WEAPONFLAG_00002000 | WEAPONFLAG_00004000 | WEAPONFLAG_HASHANDS | WEAPONFLAG_AIMTRACK, }; struct guncmd invanim_tester_shoot[] = { diff --git a/src/game/menugfx.c b/src/game/menugfx.c index 273e2c6f1..11b9f9a58 100644 --- a/src/game/menugfx.c +++ b/src/game/menugfx.c @@ -19,6 +19,7 @@ #include "types.h" #ifndef PLATFORM_N64 #include "video.h" +#include "game/bondview.h" #endif #define NUM_SUCCESS_PARTICLES 280 @@ -30,7 +31,9 @@ #define PXTOBYTES(val) ((val) * 2) #ifndef PLATFORM_N64 -s32 g_MenuBlurFb = 0; +static s32 g_MenuBlurFb = -1; +static s32 g_MenuScreenFb = -1; +static bool g_MenuBlurDone = false; #endif /** @@ -122,11 +125,14 @@ void menugfxCreateBlur(void) g_ScaleX = 1; #else - if (g_MenuBlurFb == 0) { + if (g_MenuBlurFb < 0) { g_MenuBlurFb = videoCreateFramebuffer(BLURIMG_WIDTH, BLURIMG_HEIGHT, true, false); + g_MenuScreenFb = videoCreateFramebuffer(0, 0, false, true); } // copy full viewport and downscale to 40x30 videoCopyFramebuffer(g_MenuBlurFb, 0, -1, -1); + // we'll generate a blurred version later + g_MenuBlurDone = false; #endif } @@ -144,6 +150,22 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) return menugfxRenderGradient(gdl, 0, 0, viGetWidth(), viGetHeight(), 0xff, 0xff, 0xff); } +#ifndef PLATFORM_N64 + width = viGetWidth(); + height = viGetHeight(); + if (g_MenuBlurFb >= 0 && !g_MenuBlurDone) { + // blit the small blur texture onto a screen-sized framebuffer while blurring it + g_MenuBlurDone = true; + gdl = bviewPrepareStaticRgba16(gdl, 0xffffffff, 0xff); + gDPSetTextureFilter(gdl++, G_TF_BLUR_EXT); + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, g_MenuBlurFb); + gDPSetFramebufferTargetEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, g_MenuScreenFb); + gSPImageRectangleEXT(gdl++, 0, 0, 0, 0, width << 2, height << 2, BLURIMG_WIDTH, BLURIMG_HEIGHT, 0, BLURIMG_WIDTH, BLURIMG_HEIGHT); + gDPSetFramebufferTargetEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, 0); + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, 0); + } +#endif + colours = gfxAllocateColours(1); vertices = gfxAllocateVertices(4); @@ -155,8 +177,8 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); #ifndef PLATFORM_N64 - // let gDPLoadTextureBlock above set the size, then overwrite the texture selection with our fb texture - gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, BLURIMG_WIDTH, g_MenuBlurFb); + // LoadTextureBlock will set up the sizes, but we'll use the framebuffer instead of g_BlurBuffer + gDPSetFramebufferTextureEXT(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, g_MenuScreenFb); #endif gDPPipeSync(gdl++); @@ -164,14 +186,7 @@ Gfx *menugfxRenderBgBlur(Gfx *gdl, u32 colour, s16 arg2, s16 arg3) gDPSetAlphaCompare(gdl++, G_AC_NONE); gDPSetCombineMode(gdl++, G_CC_MODULATEI, G_CC_MODULATEI); gSPClearGeometryMode(gdl++, G_CULL_BOTH); - -#ifdef PLATFORM_N64 gDPSetTextureFilter(gdl++, G_TF_BILERP); -#else - // enable blur filter for the texture - gDPSetTextureFilter(gdl++, G_TF_BLUR_EXT); -#endif - gDPSetRenderMode(gdl++, G_RM_XLU_SURF, G_RM_XLU_SURF2); #if VERSION >= VERSION_JPN_FINAL diff --git a/src/game/sight.c b/src/game/sight.c index cc55ffc59..78359c4ef 100644 --- a/src/game/sight.c +++ b/src/game/sight.c @@ -312,7 +312,7 @@ void sightTick(bool sighton) if (g_Vars.currentplayer->lookingatprop.prop != g_Vars.currentplayer->trackedprops[0].prop) { struct sndstate *handle; - handle = snd00010718(&handle, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, true); + handle = snd00010718(NULL, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, true); trackedprop = &g_Vars.currentplayer->trackedprops[0]; @@ -338,7 +338,7 @@ void sightTick(bool sighton) if (index >= 0) { struct sndstate *handle; - handle = snd00010718(&handle, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, 1); + handle = snd00010718(NULL, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, 1); trackedprop = &g_Vars.currentplayer->trackedprops[index]; @@ -361,7 +361,7 @@ void sightTick(bool sighton) if (index >= 0) { struct sndstate *handle; - handle = snd00010718(&handle, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, 1); + handle = snd00010718(NULL, 0, AL_VOL_FULL, AL_PAN_CENTER, SFX_0007, 1, 1, -1, 1); trackedprop = &g_Vars.currentplayer->trackedprops[index]; diff --git a/src/include/platform.h b/src/include/platform.h index 949ff31a6..176fd83db 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -4,6 +4,9 @@ // detect OS #if defined(_WIN32) #define PLATFORM_WIN32 1 +#elif defined(__SWITCH__) + #define PLATFORM_POSIX 1 + #define PLATFORM_NSWITCH 1 #elif defined(__linux__) #define PLATFORM_POSIX 1 #define PLATFORM_LINUX 1 diff --git a/src/include/types.h b/src/include/types.h index 2936c93f9..da5d058b4 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -538,8 +538,6 @@ struct modelrodata_type11 { // type 0x11 u32 unk0c; u32 unk10; void *unk14; - u32 unk18; - u32 unk1c; }; struct modelrodata_toggle { // type 0x12 @@ -550,7 +548,6 @@ struct modelrodata_toggle { // type 0x12 struct modelrodata_positionheld { // type 0x15 struct coord pos; s16 mtxindex; - s32 unk10; }; struct modelrodata_stargunfire { // type 0x16 @@ -2847,7 +2844,6 @@ struct coverdefinition { struct coord pos; struct coord look; u16 flags; - u16 unk1a; }; struct cover {