diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..c7b900f06 --- /dev/null +++ b/.clang-format @@ -0,0 +1,23 @@ +IndentWidth: 4 +Language: Cpp +UseTab: Never +ColumnLimit: 120 +PointerAlignment: Left +BreakBeforeBraces: Attach +SpaceAfterCStyleCast: false +Cpp11BracedListStyle: false +IndentCaseLabels: true +BinPackArguments: true +BinPackParameters: true +AlignAfterOpenBracket: Align +AlignOperands: true +BreakBeforeTernaryOperators: true +BreakBeforeBinaryOperators: None +AllowShortBlocksOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AlignEscapedNewlines: Left +AlignTrailingComments: true +SortIncludes: false diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..caf62ab7f --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,9 @@ +Checks: '-*,readability-braces-around-statements,readability-inconsistent-declaration-parameter-name' +WarningsAsErrors: '' +HeaderFilterRegex: '(src|include)\/.*\.h$' +FormatStyle: 'file' +CheckOptions: + # Require argument names to match exactly (instead of allowing a name to be a prefix/suffix of another) + # Note: 'true' is expected by clang-tidy 12+ but '1' is used for compatibility with older versions + - key: readability-inconsistent-declaration-parameter-name.Strict + value: 1 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..dfe077042 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..6dc77dbb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +*.otr +.vscode +*.swp +logs +*.nix +shipofharkinian.json +.envrc +imgui.ini + +mm/libultraship/extern/Debug/ImGui.lib + +mm/libultraship/extern/Debug/StrHash64.lib + +mm/libultraship/extern/Debug/tinyxml2.lib + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.lib.recipe + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CL.command.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CL.read.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CL.write.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CustomBuild.command.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CustomBuild.read.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/CustomBuild.write.1.tlog + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/ImGui.lastbuildstate + +mm/libultraship/extern/ImGui.dir/Debug/ImGui.tlog/Lib-link.read.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CL.command.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CL.read.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CL.write.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CustomBuild.command.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CustomBuild.read.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/CustomBuild.write.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/Lib-link.read.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/Lib-link.write.1.tlog + +mm/libultraship/extern/StrHash64.dir/Debug/StrHash64.tlog/Lib.command.1.tlog +/buildmm +/Debug/libultraship.lib +/Debug +/build* +/Release +.vs/* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..5bea84c42 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "libultraship"] + path = libultraship + url = git@github.com:louist103/libultraship.git +[submodule "OTRExporter"] + path = OTRExporter + url = git@github.com:louist103/OTRExporter.git +[submodule "ZAPDTR"] + path = ZAPDTR + url = git@github.com:louist103/ZAPDTR.git diff --git a/CMake/Default.cmake b/CMake/Default.cmake new file mode 100644 index 000000000..70bfa9038 --- /dev/null +++ b/CMake/Default.cmake @@ -0,0 +1,65 @@ +################################################################################ +# Command for variable_watch. This command issues error message, if a variable +# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens +# variable_watch( property_reader_guard) +################################################################################ +function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK) + if("${PROPERTY_READER_GUARD_DISABLED}") + return() + endif() + + if("${ACCESS}" STREQUAL "MODIFIED_ACCESS") + message(FATAL_ERROR + " Variable ${VARIABLE} is not supposed to be changed.\n" + " It is used only for reading target property ${VARIABLE}.\n" + " Use\n" + " set_target_properties(\"\" PROPERTIES \"${VARIABLE}\" \"\")\n" + " or\n" + " set_target_properties(\"\" PROPERTIES \"${VARIABLE}_\" \"\")\n" + " instead.\n") + endif() +endfunction() + +################################################################################ +# Create variable with generator expression that expands to value of +# target property _. If property is empty or not set then property +# is used instead. Variable has watcher property_reader_guard that +# doesn't allow to edit it. +# create_property_reader() +# Input: +# name - Name of watched property and output variable +################################################################################ +function(create_property_reader NAME) + set(PROPERTY_READER_GUARD_DISABLED TRUE) + set(CONFIG_VALUE "$>>>") + set(IS_CONFIG_VALUE_EMPTY "$") + set(GENERAL_VALUE "$>") + set("${NAME}" "$" PARENT_SCOPE) + variable_watch("${NAME}" property_reader_guard) +endfunction() + +################################################################################ +# Set property $_${PROPS_CONFIG_U} of ${PROPS_TARGET} to +# set_config_specific_property( ) +# Input: +# name - Prefix of property name +# value - New value +################################################################################ +function(set_config_specific_property NAME VALUE) + set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}") +endfunction() + +################################################################################ + +create_property_reader("TARGET_NAME") +create_property_reader("OUTPUT_DIRECTORY") + +set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}") +set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}") + +set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") +set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") +set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") \ No newline at end of file diff --git a/CMake/DefaultCXX.cmake b/CMake/DefaultCXX.cmake new file mode 100644 index 000000000..7b052b9cc --- /dev/null +++ b/CMake/DefaultCXX.cmake @@ -0,0 +1,12 @@ +include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake") + +set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}") + +if(MSVC) + create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING") + create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT") + + set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc") + set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi") +endif() \ No newline at end of file diff --git a/CMake/Packaging-2.cmake b/CMake/Packaging-2.cmake new file mode 100644 index 000000000..3525ae1e4 --- /dev/null +++ b/CMake/Packaging-2.cmake @@ -0,0 +1,30 @@ +set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY 0) +set(CPACK_COMPONENTS_ALL "ship" "extractor" "appimage") + +if (NOT CPACK_GENERATOR STREQUAL "External") + list(REMOVE_ITEM CPACK_COMPONENTS_ALL "appimage") +endif() + +if (CPACK_GENERATOR MATCHES "DEB|RPM") +# https://unix.stackexchange.com/a/11552/254512 +set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/ship/bin")#/${CMAKE_PROJECT_VERSION}") +set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY 0) +elseif (CPACK_GENERATOR MATCHES "ZIP") +set(CPACK_PACKAGING_INSTALL_PREFIX "") +endif() + +if (CPACK_GENERATOR MATCHES "External") +set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +SET(CPACK_MONOLITHIC_INSTALL 1) +set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/bin") +endif() + +if (CPACK_GENERATOR MATCHES "Bundle") + set(CPACK_BUNDLE_NAME "soh") + set(CPACK_BUNDLE_PLIST "macosx/Info.plist") + set(CPACK_BUNDLE_ICON "macosx/soh.icns") + set(CPACK_BUNDLE_STARTUP_COMMAND "../soh/macosx/soh-macos.sh") + set(CPACK_BUNDLE_APPLE_CERT_APP "-") +endif() + diff --git a/CMake/Packaging.cmake b/CMake/Packaging.cmake new file mode 100644 index 000000000..907f8da76 --- /dev/null +++ b/CMake/Packaging.cmake @@ -0,0 +1,90 @@ +# these are cache variables, so they could be overwritten with -D, + +set(CPACK_PACKAGE_NAME "${PROJECT_NAME}" + CACHE STRING "The resulting package name" +) + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple C++ application" + CACHE STRING "Package description for the package metadata" +) +set(CPACK_PACKAGE_VENDOR "Some Company") + +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +SET(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/_packages") + +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + +set(CPACK_PACKAGE_CONTACT "YOUR@E-MAIL.net") +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "YOUR NAME") + +#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") + +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +set(CPACK_SYSTEM_NAME ${LSB_RELEASE_CODENAME_SHORT}) +# package name for deb +# if set, then instead of some-application-0.9.2-Linux.deb +# you'll get some-application_0.9.2_amd64.deb (note the underscores too) +#set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) +execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) +set( CPACK_DEBIAN_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}-${ARCHITECTURE}.deb ) +# if you want every group to have its own package, +# although the same happens if this is not sent (so it defaults to ONE_PER_GROUP) +# and CPACK_DEB_COMPONENT_INSTALL is set to YES +set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)#ONE_PER_GROUP) +# without this you won't be able to pack only specified component +set(CPACK_DEB_COMPONENT_INSTALL YES) + +set(CPACK_EXTERNAL_ENABLE_STAGING YES) +set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${PROJECT_BINARY_DIR}/appimage-generate.cmake") + +file(GENERATE + OUTPUT "${PROJECT_BINARY_DIR}/appimage-generate.cmake" + CONTENT [[ +include(CMakePrintHelpers) +cmake_print_variables(CPACK_TEMPORARY_DIRECTORY) +cmake_print_variables(CPACK_TOPLEVEL_DIRECTORY) +cmake_print_variables(CPACK_PACKAGE_DIRECTORY) +cmake_print_variables(CPACK_PACKAGE_FILE_NAME) + +find_program(LINUXDEPLOY_EXECUTABLE + NAMES linuxdeploy linuxdeploy-x86_64.AppImage + PATHS ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy) + +if (NOT LINUXDEPLOY_EXECUTABLE) + message(STATUS "Downloading linuxdeploy") + set(LINUXDEPLOY_EXECUTABLE ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy/linuxdeploy) + file(DOWNLOAD + https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage + ${LINUXDEPLOY_EXECUTABLE} + INACTIVITY_TIMEOUT 10 + LOG ${CPACK_PACKAGE_DIRECTORY}/linuxdeploy/download.log + STATUS LINUXDEPLOY_DOWNLOAD) + execute_process(COMMAND chmod +x ${LINUXDEPLOY_EXECUTABLE} COMMAND_ECHO STDOUT) +endif() + +execute_process( + COMMAND + ${CMAKE_COMMAND} -E env + OUTPUT=${CPACK_PACKAGE_FILE_NAME}.appimage + VERSION=$,${CPACK_PACKAGE_VERSION},0.1.0> + ${LINUXDEPLOY_EXECUTABLE} + --appimage-extract-and-run + --appdir=${CPACK_TEMPORARY_DIRECTORY} + --executable=$ + $<$>:--desktop-file=$> + $<$>:--icon-file=$> + --output=appimage + # --verbosity=2 +) +]]) + +endif() + +include(CPack) + diff --git a/CMake/Utils.cmake b/CMake/Utils.cmake new file mode 100644 index 000000000..c691eefc6 --- /dev/null +++ b/CMake/Utils.cmake @@ -0,0 +1,248 @@ +# utils file for projects came from visual studio solution with cmake-converter. + +################################################################################ +# Wrap each token of the command with condition +################################################################################ +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) +macro(prepare_commands) + unset(TOKEN_ROLE) + unset(COMMANDS) + foreach(TOKEN ${ARG_COMMANDS}) + if("${TOKEN}" STREQUAL "COMMAND") + set(TOKEN_ROLE "KEYWORD") + elseif("${TOKEN_ROLE}" STREQUAL "KEYWORD") + set(TOKEN_ROLE "CONDITION") + elseif("${TOKEN_ROLE}" STREQUAL "CONDITION") + set(TOKEN_ROLE "COMMAND") + elseif("${TOKEN_ROLE}" STREQUAL "COMMAND") + set(TOKEN_ROLE "ARG") + endif() + + if("${TOKEN_ROLE}" STREQUAL "KEYWORD") + list(APPEND COMMANDS "${TOKEN}") + elseif("${TOKEN_ROLE}" STREQUAL "CONDITION") + set(CONDITION ${TOKEN}) + elseif("${TOKEN_ROLE}" STREQUAL "COMMAND") + list(APPEND COMMANDS "$<$:${DUMMY}>$<${CONDITION}:${TOKEN}>") + elseif("${TOKEN_ROLE}" STREQUAL "ARG") + list(APPEND COMMANDS "$<${CONDITION}:${TOKEN}>") + endif() + endforeach() +endmacro() +cmake_policy(POP) + +################################################################################ +# Transform all the tokens to absolute paths +################################################################################ +macro(prepare_output) + unset(OUTPUT) + foreach(TOKEN ${ARG_OUTPUT}) + if(IS_ABSOLUTE ${TOKEN}) + list(APPEND OUTPUT "${TOKEN}") + else() + list(APPEND OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${TOKEN}") + endif() + endforeach() +endmacro() + +################################################################################ +# Parse add_custom_command_if args. +# +# Input: +# PRE_BUILD - Pre build event option +# PRE_LINK - Pre link event option +# POST_BUILD - Post build event option +# TARGET - Target +# OUTPUT - List of output files +# DEPENDS - List of files on which the command depends +# COMMANDS - List of commands(COMMAND condition1 commannd1 args1 COMMAND +# condition2 commannd2 args2 ...) +# Output: +# OUTPUT - Output files +# DEPENDS - Files on which the command depends +# COMMENT - Comment +# PRE_BUILD - TRUE/FALSE +# PRE_LINK - TRUE/FALSE +# POST_BUILD - TRUE/FALSE +# TARGET - Target name +# COMMANDS - Prepared commands(every token is wrapped in CONDITION) +# NAME - Unique name for custom target +# STEP - PRE_BUILD/PRE_LINK/POST_BUILD +################################################################################ +function(add_custom_command_if_parse_arguments) + cmake_parse_arguments("ARG" "PRE_BUILD;PRE_LINK;POST_BUILD" "TARGET;COMMENT" "DEPENDS;OUTPUT;COMMANDS" ${ARGN}) + + if(WIN32) + set(DUMMY "cd.") + elseif(UNIX) + set(DUMMY "true") + endif() + + prepare_commands() + prepare_output() + + set(DEPENDS "${ARG_DEPENDS}") + set(COMMENT "${ARG_COMMENT}") + set(PRE_BUILD "${ARG_PRE_BUILD}") + set(PRE_LINK "${ARG_PRE_LINK}") + set(POST_BUILD "${ARG_POST_BUILD}") + set(TARGET "${ARG_TARGET}") + if(PRE_BUILD) + set(STEP "PRE_BUILD") + elseif(PRE_LINK) + set(STEP "PRE_LINK") + elseif(POST_BUILD) + set(STEP "POST_BUILD") + endif() + set(NAME "${TARGET}_${STEP}") + + set(OUTPUT "${OUTPUT}" PARENT_SCOPE) + set(DEPENDS "${DEPENDS}" PARENT_SCOPE) + set(COMMENT "${COMMENT}" PARENT_SCOPE) + set(PRE_BUILD "${PRE_BUILD}" PARENT_SCOPE) + set(PRE_LINK "${PRE_LINK}" PARENT_SCOPE) + set(POST_BUILD "${POST_BUILD}" PARENT_SCOPE) + set(TARGET "${TARGET}" PARENT_SCOPE) + set(COMMANDS "${COMMANDS}" PARENT_SCOPE) + set(STEP "${STEP}" PARENT_SCOPE) + set(NAME "${NAME}" PARENT_SCOPE) +endfunction() + +################################################################################ +# Add conditional custom command +# +# Generating Files +# The first signature is for adding a custom command to produce an output: +# add_custom_command_if( +# +# +# +# [COMMAND condition command2 [args2...]] +# [DEPENDS [depends...]] +# [COMMENT comment] +# +# Build Events +# add_custom_command_if( +# +# +# +# [COMMAND condition command2 [args2...]] +# [COMMENT comment] +# +# Input: +# output - Output files the command is expected to produce +# condition - Generator expression for wrapping the command +# command - Command-line(s) to execute at build time. +# args - Command`s args +# depends - Files on which the command depends +# comment - Display the given message before the commands are executed at +# build time. +# PRE_BUILD - Run before any other rules are executed within the target +# PRE_LINK - Run after sources have been compiled but before linking the +# binary +# POST_BUILD - Run after all other rules within the target have been +# executed +################################################################################ +function(add_custom_command_if) + add_custom_command_if_parse_arguments(${ARGN}) + + if(OUTPUT AND TARGET) + message(FATAL_ERROR "Wrong syntax. A TARGET and OUTPUT can not both be specified.") + endif() + + if(OUTPUT) + add_custom_command(OUTPUT ${OUTPUT} + ${COMMANDS} + DEPENDS ${DEPENDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + elseif(TARGET) + if(PRE_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio") + add_custom_target( + ${NAME} + ${COMMANDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + add_dependencies(${TARGET} ${NAME}) + else() + add_custom_command( + TARGET ${TARGET} + ${STEP} + ${COMMANDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + endif() + else() + message(FATAL_ERROR "Wrong syntax. A TARGET or OUTPUT must be specified.") + endif() +endfunction() + +################################################################################ +# Use props file for a target and configs +# use_props( ) +# Inside there are following variables: +# PROPS_TARGET - +# PROPS_CONFIG - One of +# PROPS_CONFIG_U - Uppercase PROPS_CONFIG +# Input: +# target - Target to apply props file +# configs - Build configurations to apply props file +# props_file - CMake script +################################################################################ +macro(use_props TARGET CONFIGS PROPS_FILE) + set(PROPS_TARGET "${TARGET}") + foreach(PROPS_CONFIG ${CONFIGS}) + string(TOUPPER "${PROPS_CONFIG}" PROPS_CONFIG_U) + + get_filename_component(ABSOLUTE_PROPS_FILE "${PROPS_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") + if(EXISTS "${ABSOLUTE_PROPS_FILE}") + include("${ABSOLUTE_PROPS_FILE}") + else() + message(WARNING "Corresponding cmake file from props \"${ABSOLUTE_PROPS_FILE}\" doesn't exist") + endif() + endforeach() +endmacro() + +################################################################################ +# Add compile options to source file +# source_file_compile_options( [compile_options...]) +# Input: +# source_file - Source file +# compile_options - Options to add to COMPILE_FLAGS property +################################################################################ +function(source_file_compile_options SOURCE_FILE) + if("${ARGC}" LESS_EQUAL "1") + return() + endif() + + get_source_file_property(COMPILE_OPTIONS "${SOURCE_FILE}" COMPILE_OPTIONS) + + if(COMPILE_OPTIONS) + list(APPEND COMPILE_OPTIONS ${ARGN}) + else() + set(COMPILE_OPTIONS "${ARGN}") + endif() + + set_source_files_properties("${SOURCE_FILE}" PROPERTIES COMPILE_OPTIONS "${COMPILE_OPTIONS}") +endfunction() + +################################################################################ +# Default properties of visual studio projects +################################################################################ +set(DEFAULT_CXX_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultCXX.cmake") + +function(get_linux_lsb_release_information) + find_program(LSB_RELEASE_EXEC lsb_release) + if(NOT LSB_RELEASE_EXEC) + message(FATAL_ERROR "Could not detect lsb_release executable, can not gather required information") + endif() + + execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --id OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --release OUTPUT_VARIABLE LSB_RELEASE_VERSION_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${LSB_RELEASE_EXEC}" --short --codename OUTPUT_VARIABLE LSB_RELEASE_CODENAME_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + + set(LSB_RELEASE_ID_SHORT "${LSB_RELEASE_ID_SHORT}" PARENT_SCOPE) + set(LSB_RELEASE_VERSION_SHORT "${LSB_RELEASE_VERSION_SHORT}" PARENT_SCOPE) + set(LSB_RELEASE_CODENAME_SHORT "${LSB_RELEASE_CODENAME_SHORT}" PARENT_SCOPE) +endfunction() diff --git a/CMake/automate-vcpkg.cmake b/CMake/automate-vcpkg.cmake new file mode 100644 index 000000000..409194959 --- /dev/null +++ b/CMake/automate-vcpkg.cmake @@ -0,0 +1,191 @@ +#------------------------------------------------------------------------------------------------------------ +# +# Automate-VCPKG by Andre Taulien +# =============================== +# +# Project Repository: https://github.com/REGoth-project/Automate-VCPKG +# License ..........: MIT, see end of file. +# +# Based on: https://github.com/sutambe/cpptruths/blob/vcpkg_cmake_blog/cpp0x/vcpkg_test/CMakeLists.txt +# +# +# While [Vcpkg](https://github.com/microsoft/vcpkg) on it's own is awesome, it does add +# a little bit of complexity to getting a project to build. Even more if the one trying +# to compile your application is not too fond of the commandline. Additionally, CMake +# commands tend to get rather long with the toolchain path. +# +# To keep things simple for new users who just want to get the project to build, this +# script offers a solution. +# +# Lets assume your main `CMakelists.txt` looks something like this: +# +# cmake_minimum_required (VERSION 3.12.0) +# project (MyProject) +# +# add_executable(MyExecutable main.c) +# +# To integrate Vcpkg into that `CMakelists.txt`, simple put the following lines before the +# call to `project(MyProject)`: +# +# include(cmake/automate-vcpkg.cmake) +# +# vcpkg_bootstrap() +# vcpkg_install_packages(libsquish physfs) +# +# The call to `vcpkg_bootstrap()` will clone the official Vcpkg repository and bootstrap it. +# If it detected an existing environment variable defining a valid `VCPKG_ROOT`, it will +# update the existing installation of Vcpkg. +# +# Arguments to `vcpkg_install_packages()` are the packages you want to install using Vcpkg. +# +# If you want to keep the possibility for users to chose their own copy of Vcpkg, you can +# simply not run the code snippet mentioned above, something like this will work: +# +# option(SKIP_AUTOMATE_VCPKG "When ON, you will need to built the packages +# required by MyProject on your own or supply your own vcpkg toolchain.") +# +# if (NOT SKIP_AUTOMATE_VCPKG) +# include(cmake/automate-vcpkg.cmake) +# +# vcpkg_bootstrap() +# vcpkg_install_packages(libsquish physfs) +# endif() +# +# Then, the user has to supply the packages on their own, be it through Vcpkg or manually +# specifying their locations. +#------------------------------------------------------------------------------------------------------------ + +cmake_minimum_required (VERSION 3.12) + +if(WIN32) + set(VCPKG_FALLBACK_ROOT ${CMAKE_CURRENT_BINARY_DIR}/vcpkg CACHE STRING "vcpkg configuration directory to use if vcpkg was not installed on the system before") +else() + set(VCPKG_FALLBACK_ROOT ${CMAKE_CURRENT_BINARY_DIR}/.vcpkg CACHE STRING "vcpkg configuration directory to use if vcpkg was not installed on the system before") +endif() + +# On Windows, Vcpkg defaults to x86, even on x64 systems. If we're +# doing a 64-bit build, we need to fix that. +if (WIN32) + + # Since the compiler checks haven't run yet, we need to figure + # out the value of CMAKE_SIZEOF_VOID_P ourselfs + + include(CheckTypeSize) + enable_language(C) + check_type_size("void*" SIZEOF_VOID_P BUILTIN_TYPES_ONLY) + + if (SIZEOF_VOID_P EQUAL 8) + message(STATUS "Using Vcpkg triplet 'x64-windows'") + + set(VCPKG_TRIPLET x64-windows) + endif() +endif() + +if(NOT DEFINED VCPKG_ROOT) + if(NOT DEFINED ENV{VCPKG_ROOT}) + set(VCPKG_ROOT ${VCPKG_FALLBACK_ROOT}) + else() + set(VCPKG_ROOT $ENV{VCPKG_ROOT}) + endif() +endif() + +# Installs a new copy of Vcpkg or updates an existing one +macro(vcpkg_bootstrap) + _install_or_update_vcpkg() + + # Find out whether the user supplied their own VCPKG toolchain file + if(NOT DEFINED ${CMAKE_TOOLCHAIN_FILE}) + # We know this wasn't set before so we need point the toolchain file to the newly found VCPKG_ROOT + set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE STRING "") + + # Just setting vcpkg.cmake as toolchain file does not seem to actually pull in the code + include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) + + set(AUTOMATE_VCPKG_USE_SYSTEM_VCPKG OFF) + else() + # VCPKG_ROOT has been defined by the toolchain file already + set(AUTOMATE_VCPKG_USE_SYSTEM_VCPKG ON) + endif() + + message(STATUS "Automate VCPKG status:") + message(STATUS " VCPKG_ROOT.....: ${VCPKG_ROOT}") + message(STATUS " VCPKG_EXEC.....: ${VCPKG_EXEC}") + message(STATUS " VCPKG_BOOTSTRAP: ${VCPKG_BOOTSTRAP}") +endmacro() + +macro(_install_or_update_vcpkg) + if(NOT EXISTS ${VCPKG_ROOT}) + message(STATUS "Cloning vcpkg in ${VCPKG_ROOT}") + execute_process(COMMAND git clone https://github.com/Microsoft/vcpkg.git ${VCPKG_ROOT} --depth 1) + + # If a reproducible build is desired (and potentially old libraries are # ok), uncomment the + # following line and pin the vcpkg repository to a specific githash. + # execute_process(COMMAND git checkout 745a0aea597771a580d0b0f4886ea1e3a94dbca6 WORKING_DIRECTORY ${VCPKG_ROOT}) + else() + # The following command has no effect if the vcpkg repository is in a detached head state. + message(STATUS "Auto-updating vcpkg in ${VCPKG_ROOT}") + execute_process(COMMAND git pull WORKING_DIRECTORY ${VCPKG_ROOT}) + endif() + + if(NOT EXISTS ${VCPKG_ROOT}/README.md) + message(FATAL_ERROR "***** FATAL ERROR: Could not clone vcpkg *****") + endif() + + if(WIN32) + set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg.exe) + set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.bat) + else() + set(VCPKG_EXEC ${VCPKG_ROOT}/vcpkg) + set(VCPKG_BOOTSTRAP ${VCPKG_ROOT}/bootstrap-vcpkg.sh) + endif() + + if(NOT EXISTS ${VCPKG_EXEC}) + message("Bootstrapping vcpkg in ${VCPKG_ROOT}") + execute_process(COMMAND ${VCPKG_BOOTSTRAP} WORKING_DIRECTORY ${VCPKG_ROOT}) + endif() + + if(NOT EXISTS ${VCPKG_EXEC}) + message(FATAL_ERROR "***** FATAL ERROR: Could not bootstrap vcpkg *****") + endif() + +endmacro() + +# Installs the list of packages given as parameters using Vcpkg +macro(vcpkg_install_packages) + + # Need the given list to be space-separated + #string (REPLACE ";" " " PACKAGES_LIST_STR "${ARGN}") + + message(STATUS "Installing/Updating the following vcpkg-packages: ${PACKAGES_LIST_STR}") + + if (VCPKG_TRIPLET) + set(ENV{VCPKG_DEFAULT_TRIPLET} "${VCPKG_TRIPLET}") + endif() + + execute_process( + COMMAND ${VCPKG_EXEC} install ${ARGN} + WORKING_DIRECTORY ${VCPKG_ROOT} + ) +endmacro() + +# MIT License +# +# Copyright (c) 2019 REGoth-project +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..1d41f0b2a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,225 @@ +cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR) + +set(CMAKE_SYSTEM_VERSION 10.0 CACHE STRING "" FORCE) +set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use") + +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version") + +project(2s2h VERSION 0.0.1 LANGUAGES C CXX) +set(PROJECT_BUILD_NAME "PRE ALPHA" CACHE STRING "") +set(PROJECT_TEAM "github.com/harbourmasters" CACHE STRING "") + +set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT mm) +add_compile_options($<$:/MP>) +add_compile_options($<$:/utf-8>) + +if (CMAKE_SYSTEM_NAME MATCHES "Windows|Linux") + if(NOT DEFINED BUILD_CROWD_CONTROL) + set(BUILD_CROWD_CONTROL OFF) + endif() +endif() + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +include(CMake/automate-vcpkg.cmake) + +set(VCPKG_TRIPLET x86-windows-static) +set(VCPKG_TARGET_TRIPLET x86-windows-static) + +vcpkg_bootstrap() +vcpkg_install_packages(zlib bzip2 libpng sdl2 sdl2-net glew glfw3) +endif() + +################################################################################ +# Set target arch type if empty. Visual studio solution generator provides it. +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(NOT CMAKE_VS_PLATFORM_NAME) + set(CMAKE_VS_PLATFORM_NAME "x64") + endif() + message("${CMAKE_VS_PLATFORM_NAME} architecture in use") + + if(NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64" + OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")) + message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!") + endif() +endif() + +################################################################################ +# Global configuration types +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") +set(CMAKE_C_FLAGS_DEBUG "-g -ffast-math -DDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-g -ffast-math -DDEBUG") +set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG") +else() +set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-fuse-ld=lld") +set(CMAKE_C_FLAGS_DEBUG "-g") +set(CMAKE_LINKER_FLAGS_DEBUG "-fuse-ld=lld") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") +set(CMAKE_OBJCXX_FLAGS_RELEASE "-O2 -DNDEBUG") +endif() + +if(NOT CMAKE_BUILD_TYPE ) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) +endif() + +################################################################################ +# Common utils +################################################################################ +include(CMake/Utils.cmake) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + get_linux_lsb_release_information() + message(STATUS "Linux ${LSB_RELEASE_ID_SHORT} ${LSB_RELEASE_VERSION_SHORT} ${LSB_RELEASE_CODENAME_SHORT}") +else() + message(STATUS ${CMAKE_SYSTEM_NAME}) +endif() + +################################################################################ +# Additional Global Settings(add specific info there) +################################################################################ +include(CMake/GlobalSettingsInclude.cmake OPTIONAL) + +################################################################################ +# Use solution folders feature +################################################################################ +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +################################################################################ +# Sub-projects +################################################################################ +add_subdirectory(libultraship ${CMAKE_BINARY_DIR}/libultraship) +add_subdirectory(ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD) +add_subdirectory(OTRExporter) +add_subdirectory(mm) + +set_property(TARGET mm PROPERTY APPIMAGE_DESKTOP_FILE_TERMINAL YES) +set_property(TARGET mm PROPERTY APPIMAGE_DESKTOP_FILE "${CMAKE_SOURCE_DIR}/scripts/linux/appimage/soh.desktop") +set_property(TARGET mm PROPERTY APPIMAGE_ICON_FILE "${CMAKE_BINARY_DIR}/sohIcon.png") + +#if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +#install(PROGRAMS "${CMAKE_SOURCE_DIR}/scripts/linux/appimage/soh.sh" DESTINATION . COMPONENT appimage) +#install(FILES "${CMAKE_SOURCE_DIR}/soh.otr" DESTINATION . COMPONENT ship) +#install(TARGETS ZAPD DESTINATION ./assets/extractor COMPONENT extractor) +#install(DIRECTORY "${CMAKE_SOURCE_DIR}/soh/assets/extractor/" DESTINATION ./assets/extractor COMPONENT extractor) +#install(DIRECTORY "${CMAKE_SOURCE_DIR}/soh/assets/xml/" DESTINATION ./assets/extractor/xmls COMPONENT extractor) +#install(DIRECTORY "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/filelists/" DESTINATION ./assets/extractor/filelists COMPONENT extractor) +#install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ActorList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT extractor) +#install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ObjectList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT extractor) +#install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/SymbolMap_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT extractor) +#endif() + +if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") +install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/extractor/" DESTINATION ./assets/extractor COMPONENT 2s2h) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/xml/" DESTINATION ./assets/extractor/xmls COMPONENT 2s2h) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/filelists/" DESTINATION ./assets/extractor/filelists COMPONENT 2s2h) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ActorList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT 2s2h) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ObjectList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT 2s2h) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/SymbolMap_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols COMPONENT 2s2h) +endif() + +find_package(Python3 COMPONENTS Interpreter) + +# Target to generate OTRs +add_custom_target( + ExtractAssets + # CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions + COMMAND ${CMAKE_COMMAND} -E $,remove,rm> -f oot.otr oot-mq.otr soh.otr + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$" --non-interactive + COMMAND ${CMAKE_COMMAND} -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DTARGET_DIR="$" -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter + COMMENT "Running asset extraction..." + DEPENDS ZAPD + BYPRODUCTS mm.otr ${CMAKE_SOURCE_DIR}/mm.otr ${CMAKE_SOURCE_DIR}/soh.otr +) + +# Target to generate headers +add_custom_target( + ExtractAssetHeaders + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$" --non-interactive --gen-headers + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter + COMMENT "Generating asset headers..." + DEPENDS ZAPD +) + +# Target to generate only soh.otr +add_custom_target( + GenerateSohOtr + # CMake versions prior to 3.17 do not have the rm command, use remove instead for older versions + COMMAND ${CMAKE_COMMAND} -E $,remove,rm> -f soh.otr + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter/extract_assets.py -z "$" --norom + COMMAND ${CMAKE_COMMAND} -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DTARGET_DIR="$" -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DBINARY_DIR=${CMAKE_BINARY_DIR} -DONLYSOHOTR=On -P ${CMAKE_CURRENT_SOURCE_DIR}/copy-existing-otrs.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/OTRExporter + COMMENT "Generating soh.otr..." + DEPENDS ZAPD +) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + find_package(ImageMagick COMPONENTS convert) + if (ImageMagick_FOUND) + execute_process ( + COMMAND ${ImageMagick_convert_EXECUTABLE} mm/macosx/sohIcon.png -resize 512x512 ${CMAKE_BINARY_DIR}/sohIcon.png + OUTPUT_VARIABLE outVar + ) + endif() +endif() + +#if(CMAKE_SYSTEM_NAME MATCHES "Darwin") +#add_custom_target(CreateOSXIcons +# COMMAND mkdir -p ${CMAKE_BINARY_DIR}/macosx/soh.iconset +# COMMAND sips -z 16 16 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_16x16.png +# COMMAND sips -z 32 32 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_16x16@2x.png +# COMMAND sips -z 32 32 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_32x32.png +# COMMAND sips -z 64 64 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_32x32@2x.png +# COMMAND sips -z 128 128 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_128x128.png +# COMMAND sips -z 256 256 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_128x128@2x.png +# COMMAND sips -z 256 256 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_256x256.png +# COMMAND sips -z 512 512 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_256x256@2x.png +# COMMAND sips -z 512 512 soh/macosx/sohIcon.png --out ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_512x512.png +# COMMAND cp soh/macosx/sohIcon.png ${CMAKE_BINARY_DIR}/macosx/soh.iconset/icon_512x512@2x.png +# COMMAND iconutil -c icns -o ${CMAKE_BINARY_DIR}/macosx/soh.icns ${CMAKE_BINARY_DIR}/macosx/soh.iconset +# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +# COMMENT "Creating OSX icons ..." +# ) +#add_dependencies(soh CreateOSXIcons) + +install(TARGETS ZAPD DESTINATION ${CMAKE_BINARY_DIR}/assets/extractor) + +set(PROGRAM_PERMISSIONS_EXECUTE OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ) + +install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/extractor/" DESTINATION ./assets/extractor) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/mm/assets/xml/" DESTINATION ./assets/extractor/xmls) +install(DIRECTORY "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/filelists/" DESTINATION ./assets/extractor/filelists) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ActorList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ObjectList_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols) +install(FILES "${CMAKE_SOURCE_DIR}/OTRExporter/CFG/SymbolMap_OoTMqDbg.txt" DESTINATION ./assets/extractor/symbols) + +install(DIRECTORY ${CMAKE_BINARY_DIR}/assets + DESTINATION . + PATTERN ZAPD.out + PERMISSIONS ${PROGRAM_PERMISSIONS_EXECUTE} + ) + +#install(CODE " +# include(BundleUtilities) +# fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/soh-macos\" \"\" \"${dirs}\") +# ") + +#endif() + +#if(CMAKE_SYSTEM_NAME MATCHES "Windows|NintendoSwitch|CafeOS") +#install(FILES ${CMAKE_SOURCE_DIR}/README.md DESTINATION . COMPONENT 2s2h RENAME readme.txt ) +#endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(CPACK_GENERATOR "External") +elseif(CMAKE_SYSTEM_NAME MATCHES "Windows|NintendoSwitch|CafeOS") + set(CPACK_GENERATOR "ZIP") +elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CPACK_GENERATOR "Bundle") +endif() + +#set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/CMake/Packaging-2.cmake) +#include(CMake/Packaging.cmake) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..806cae1f6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM ubuntu:latest + +ARG MY_XAUTH_COOKIE + +ENV LANG C.UTF-8 +ARG DEBIAN_FRONTEND=noninteractive + +RUN dpkg --add-architecture i386 +RUN apt-get update + +RUN apt-get install -y \ + binutils:i386 \ + gcc-12:i386 \ + g++-12:i386 && \ + ln -sf /usr/bin/python3.10 /usr/bin/python3 && \ + ln -s /usr/bin/gcc-12 /usr/bin/gcc && \ + ln -s /usr/bin/gcc-12 /usr/bin/cc && \ + ln -s /usr/bin/g++-12 /usr/bin/g++ && \ + ln -s /usr/bin/g++-12 /usr/bin/c++ + +RUN apt-get install -y \ + libsdl2-dev:i386 \ + zlib1g-dev:i386 \ + libbz2-dev:i386 \ + libpng-dev:i386 \ + libboost-dev:i386 \ + libgles2-mesa-dev + +RUN apt-get install -y \ + make \ + cmake \ + git \ + gdb \ + lld \ + python3.10 \ + ninja-build \ + lsb-release \ + clang-format + +RUN git clone https://github.com/Perlmint/glew-cmake.git && \ + cmake -B glew-cmake/builddir -S glew-cmake -GNinja && \ + cmake --build glew-cmake/builddir && \ + cmake --install glew-cmake/builddir --prefix /usr && \ + mv /usr/lib/libglew-shared.so /usr/lib/libglew.so + +RUN git clone https://github.com/libsdl-org/SDL_net.git -b SDL2 && \ + cmake -B SDL_net/build -S SDL_net -DCMAKE_BUILD_TYPE=Release && \ + cmake --build SDL_net/build --config Release --parallel && \ + cmake --install SDL_net/build --config Release + + +RUN touch /root/.Xauthority && \ + xauth add $MY_XAUTH_COOKIE + + +RUN mkdir /2ship +WORKDIR /2ship diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..0e259d42c --- /dev/null +++ b/LICENSE @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/OTRExporter b/OTRExporter new file mode 160000 index 000000000..6212ebc44 --- /dev/null +++ b/OTRExporter @@ -0,0 +1 @@ +Subproject commit 6212ebc4407107340a76b3ab052f94170a42a3a6 diff --git a/ZAPDTR b/ZAPDTR new file mode 160000 index 000000000..01615a6c4 --- /dev/null +++ b/ZAPDTR @@ -0,0 +1 @@ +Subproject commit 01615a6c4c6f8e95149fd52ab85b1ae970167bc3 diff --git a/libultraship b/libultraship new file mode 160000 index 000000000..1dd5f43ff --- /dev/null +++ b/libultraship @@ -0,0 +1 @@ +Subproject commit 1dd5f43ffcf4d3d9d322da2408aca76bd41b0bb2 diff --git a/mm/.gitignore b/mm/.gitignore index 8c5705f18..dc0447c84 100644 --- a/mm/.gitignore +++ b/mm/.gitignore @@ -7,7 +7,6 @@ __pycache__/ .vscode/ .vs/ .idea/ -CMakeLists.txt cmake-build-debug venv/ tags @@ -55,3 +54,4 @@ docs/doxygen/ .python-version .make_options .*env +*.otr \ No newline at end of file diff --git a/mm/2s2h/BenPort.cpp b/mm/2s2h/BenPort.cpp new file mode 100644 index 000000000..efc63589f --- /dev/null +++ b/mm/2s2h/BenPort.cpp @@ -0,0 +1,1340 @@ +#include "BenPort.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "z64animation.h" +#include "z64bgcheck.h" +#include +#ifdef _WIN32 +#include +#else +#include +#endif +#include +#include +#define DRMP3_IMPLEMENTATION +#include +#define DRWAV_IMPLEMENTATION +#include +#include +#include "variables.h" +#include "z64.h" +#include "macros.h" +#include + +#include +#include + +#ifdef __APPLE__ +#include +#else +#include +#endif +#include "Extractor/Extract.h" +// OTRTODO +//#include + + +#ifdef ENABLE_CROWD_CONTROL +#include "Enhancements/crowd-control/CrowdControl.h" +CrowdControl* CrowdControl::Instance; +#endif + +#include +#include + +// Resource Types/Factories +#include "2s2h/resource/type/Animation.h" +#include "2s2h/resource/type/AudioSample.h" +#include "2s2h/resource/type/AudioSequence.h" +#include "2s2h/resource/type/AudioSoundFont.h" +#include "2s2h/resource/type/CollisionHeader.h" +#include "2s2h/resource/type/Cutscene.h" +#include "2s2h/resource/type/Path.h" +#include "2s2h/resource/type/PlayerAnimation.h" +#include "2s2h/resource/type/Scene.h" +#include "2s2h/resource/type/Skeleton.h" +#include "2s2h/resource/type/SkeletonLimb.h" +#include "2s2h/resource/type/Text.h" +#include "2s2h/resource/importer/AnimationFactory.h" +#include "2s2h/resource/importer/AudioSampleFactory.h" +#include "2s2h/resource/importer/AudioSequenceFactory.h" +#include "2s2h/resource/importer/AudioSoundFontFactory.h" +#include "2s2h/resource/importer/CollisionHeaderFactory.h" +#include "2s2h/resource/importer/CutsceneFactory.h" +#include "2s2h/resource/importer/PathFactory.h" +#include "2s2h/resource/importer/PlayerAnimationFactory.h" +#include "2s2h/resource/importer/SceneFactory.h" +#include "2s2h/resource/importer/SkeletonFactory.h" +#include "2s2h/resource/importer/SkeletonLimbFactory.h" +#include "2s2h/resource/importer/TextFactory.h" +#include "2s2h/resource/importer/TextMMFactory.h" +#include "2s2h/resource/importer/BackgroundFactory.h" +#include "2s2h/resource/importer/TextureAnimationFactory.h" + +OTRGlobals* OTRGlobals::Instance; + +extern "C" char** cameraStrings; +std::vector> cameraStdStrings; + +Color_RGB8 kokiriColor = { 0x1E, 0x69, 0x1B }; +Color_RGB8 goronColor = { 0x64, 0x14, 0x00 }; +Color_RGB8 zoraColor = { 0x00, 0xEC, 0x64 }; + + +OTRGlobals::OTRGlobals() { + std::vector OTRFiles; + //std::string mqPath = LUS::Context::LocateFileAcrossAppDirs("oot-mq.otr", appShortName); + //if (std::filesystem::exists(mqPath)) { + // OTRFiles.push_back(mqPath); + //} + std::string ootPath = LUS::Context::LocateFileAcrossAppDirs("mm.otr", appShortName); + if (std::filesystem::exists(ootPath)) { + OTRFiles.push_back(ootPath); + } + std::string sohOtrPath = LUS::Context::GetPathRelativeToAppBundle("soh.otr"); + if (std::filesystem::exists(sohOtrPath)) { + OTRFiles.push_back(sohOtrPath); + } + std::string patchesPath = LUS::Context::LocateFileAcrossAppDirs("mods", appShortName); + if (patchesPath.length() > 0 && std::filesystem::exists(patchesPath)) { + if (std::filesystem::is_directory(patchesPath)) { + for (const auto& p : std::filesystem::recursive_directory_iterator(patchesPath)) { + if (StringHelper::IEquals(p.path().extension().string(), ".otr")) { + OTRFiles.push_back(p.path().generic_string()); + } + } + } + } + std::unordered_set ValidHashes = { OOT_PAL_MQ, OOT_NTSC_JP_MQ, OOT_NTSC_US_MQ, OOT_PAL_GC_MQ_DBG, + OOT_NTSC_US_10, OOT_NTSC_US_11, OOT_NTSC_US_12, OOT_PAL_10, + OOT_PAL_11, OOT_NTSC_JP_GC_CE, OOT_NTSC_JP_GC, OOT_NTSC_US_GC, + OOT_PAL_GC, OOT_PAL_GC_DBG1, OOT_PAL_GC_DBG2 }; + // tell LUS to reserve 3 SoH specific threads (Game, Audio, Save) + context = LUS::Context::CreateInstance("2 Ship 2 Harkinian", appShortName, "shipofharkinian.json", OTRFiles, {}, 3); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_Animation, "Animation", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_PlayerAnimation, "PlayerAnimation", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_Room, "Room", std::make_shared()); // Is room scene? maybe? + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_CollisionHeader, "CollisionHeader", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_Skeleton, "Skeleton", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_SkeletonLimb, "SkeletonLimb", std::make_shared()); + // TODO should we use a custom command for this? + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Path, "Path", + std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_Cutscene, "Cutscene", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_Text, "Text", + std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(LUS::ResourceType::SOH_TextMM, "TextMM", + std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_AudioSample, "AudioSample", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_AudioSoundFont, "AudioSoundFont", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_AudioSequence, "AudioSequence", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::SOH_Background, "Background", std::make_shared()); + context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + LUS::ResourceType::TSH_TexAnim, "TextureAnimation", std::make_shared()); + + //gSaveStateMgr = std::make_shared(); + //gRandomizer = std::make_shared(); + hasMasterQuest = hasOriginal = false; + + // Move the camera strings from read only memory onto the heap (writable memory) + // This is in OTRGlobals right now because this is a place that will only ever be run once at the beginning of + // startup. We should probably find some code in db_camera that does initialization and only run once, and then + // dealloc on deinitialization. + //cameraStrings = (char**)malloc(sizeof(constCameraStrings)); + //for (int32_t i = 0; i < sizeof(constCameraStrings) / sizeof(char*); i++) { + // // OTRTODO: never deallocated... + // auto dup = strdup(constCameraStrings[i]); + // cameraStrings[i] = dup; + //} + + auto versions = context->GetResourceManager()->GetArchive()->GetGameVersions(); + #if 0 + for (uint32_t version : versions) { + if (!ValidHashes.contains(version)) { +#if defined(__SWITCH__) + SPDLOG_ERROR("Invalid OTR File!"); +#elif defined(__WIIU__) + LUS::WiiU::ThrowInvalidOTR(); +#else + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Invalid OTR File", + "Attempted to load an invalid OTR file. Try regenerating.", nullptr); + SPDLOG_ERROR("Invalid OTR File!"); +#endif + exit(1); + } + switch (version) { + case OOT_PAL_MQ: + case OOT_NTSC_JP_MQ: + case OOT_NTSC_US_MQ: + case OOT_PAL_GC_MQ_DBG: + hasMasterQuest = true; + break; + case OOT_NTSC_US_10: + case OOT_NTSC_US_11: + case OOT_NTSC_US_12: + case OOT_PAL_10: + case OOT_PAL_11: + case OOT_NTSC_JP_GC_CE: + case OOT_NTSC_JP_GC: + case OOT_NTSC_US_GC: + case OOT_PAL_GC: + case OOT_PAL_GC_DBG1: + case OOT_PAL_GC_DBG2: + hasOriginal = true; + break; + default: + break; + } + } + #endif +} + +OTRGlobals::~OTRGlobals() { +} + +bool OTRGlobals::HasMasterQuest() { + return hasMasterQuest; +} + +bool OTRGlobals::HasOriginal() { + return hasOriginal; +} + +uint32_t OTRGlobals::GetInterpolationFPS() { + if (LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() == LUS::WindowBackend::DX11) { + return CVarGetInteger("gInterpolationFPS", 20); + } + + if (CVarGetInteger("gMatchRefreshRate", 0)) { + return LUS::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(); + } + + return std::min(LUS::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(), + CVarGetInteger("gInterpolationFPS", 20)); +} + +struct ExtensionEntry { + std::string path; + std::string ext; +}; + +extern uintptr_t clearMtx; +extern "C" Mtx gMtxClear; +extern "C" MtxF gMtxFClear; +extern "C" void OTRMessage_Init(); +extern "C" void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); +extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len); +extern "C" int AudioPlayer_Buffered(void); +extern "C" int AudioPlayer_GetDesiredBuffered(void); +extern "C" void ResourceMgr_LoadDirectory(const char* resName); +std::unordered_map ExtensionCache; + +extern "C" void OTRExtScanner() { + auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles("*").get(); + + for (auto& rPath : lst) { + std::vector raw = StringHelper::Split(rPath, "."); + std::string ext = raw[raw.size() - 1]; + std::string nPath = rPath.substr(0, rPath.size() - (ext.size() + 1)); + replace(nPath.begin(), nPath.end(), '\\', '/'); + + ExtensionCache[nPath] = { rPath, ext }; + } +} + +extern "C" void InitOTR() { +#if not defined(__SWITCH__) && not defined(__WIIU__) + if (!std::filesystem::exists(LUS::Context::LocateFileAcrossAppDirs("mm.otr", appShortName))) { + std::string installPath = LUS::Context::GetAppBundlePath(); + if (!std::filesystem::exists(installPath + "/assets/extractor")) { + Extractor::ShowErrorBox( + "Extractor assets not found", + "No OTR files found. Missing assets/extractor folder needed to generate OTR file. Exiting..."); + exit(1); + } + + bool generatedOtrIsMQ = false; + if (Extractor::ShowYesNoBox("No OTR Files", "No OTR files found. Generate one now?") == IDYES) { + Extractor extract; + if (!extract.Run()) { + Extractor::ShowErrorBox("Error", "An error occured, no OTR file was generated. Exiting..."); + exit(1); + } + extract.CallZapd(installPath, LUS::Context::GetAppDirectoryPath(appShortName)); + generatedOtrIsMQ = extract.IsMasterQuest(); + } else { + exit(1); + } + } +#endif + +#ifdef __SWITCH__ + LUS::Switch::Init(LUS::PreInitPhase); +#elif defined(__WIIU__) + LUS::WiiU::Init("soh"); +#endif + + OTRGlobals::Instance = new OTRGlobals(); + SohGui::SetupGuiElements(); + + clearMtx = (uintptr_t)&gMtxClear; + //OTRMessage_Init(); + //OTRExtScanner(); + time_t now = time(NULL); + tm* tm_now = localtime(&now); + if (tm_now->tm_mon == 11 && tm_now->tm_mday >= 24 && tm_now->tm_mday <= 25) { + CVarRegisterInteger("gLetItSnow", 1); + } else { + CVarClear("gLetItSnow"); + } + + srand(now); +#ifdef ENABLE_CROWD_CONTROL + CrowdControl::Instance = new CrowdControl(); + CrowdControl::Instance->Init(); + if (CVarGetInteger("gCrowdControl", 0)) { + CrowdControl::Instance->Enable(); + } else { + CrowdControl::Instance->Disable(); + } +#endif + + std::shared_ptr conf = OTRGlobals::Instance->context->GetConfig(); + +} + +extern "C" void SaveManager_ThreadPoolWait() { + //SaveManager::Instance->ThreadPoolWait(); +} + +extern "C" void DeinitOTR() { + SaveManager_ThreadPoolWait(); +#ifdef ENABLE_CROWD_CONTROL + CrowdControl::Instance->Disable(); + CrowdControl::Instance->Shutdown(); +#endif + + // Destroying gui here because we have shared ptrs to LUS objects which output to SPDLOG which is destroyed before + // these shared ptrs. + //SohGui::Destroy(); + + OTRGlobals::Instance->context = nullptr; +} + +#ifdef _WIN32 +extern "C" uint64_t GetFrequency() { + LARGE_INTEGER nFreq; + + QueryPerformanceFrequency(&nFreq); + + return nFreq.QuadPart; +} + +extern "C" uint64_t GetPerfCounter() { + LARGE_INTEGER ticks; + QueryPerformanceCounter(&ticks); + + return ticks.QuadPart; +} +#else +extern "C" uint64_t GetFrequency() { + return 1000; // sec -> ms +} + +extern "C" uint64_t GetPerfCounter() { + struct timespec monotime; + clock_gettime(CLOCK_MONOTONIC, &monotime); + + uint64_t remainingMs = (monotime.tv_nsec / 1000000); + + // in milliseconds + return monotime.tv_sec * 1000 + remainingMs; +} +#endif + +extern "C" uint64_t GetUnixTimestamp() { + auto time = std::chrono::system_clock::now(); + auto since_epoch = time.time_since_epoch(); + auto millis = std::chrono::duration_cast(since_epoch); + long now = millis.count(); + return now; +} + +// C->C++ Bridge +extern "C" void Graph_ProcessFrame(void (*run_one_game_iter)(void)) { + OTRGlobals::Instance->context->GetWindow()->MainLoop(run_one_game_iter); +} + +extern bool ShouldClearTextureCacheAtEndOfFrame; + +extern "C" void Graph_StartFrame() { +#ifndef __WIIU__ + using LUS::KbScancode; + int32_t dwScancode = OTRGlobals::Instance->context->GetWindow()->GetLastScancode(); + OTRGlobals::Instance->context->GetWindow()->SetLastScancode(-1); + + switch (dwScancode) { + #if 0 + case KbScancode::LUS_KB_F5: { + if (CVarGetInteger("gSaveStatesEnabled", 0) == 0) { + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->TextDrawNotification( + 6.0f, true, "Save states not enabled. Check Cheats Menu."); + return; + } + const unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); + const SaveStateReturn stateReturn = + OTRGlobals::Instance->gSaveStateMgr->AddRequest({ slot, RequestType::SAVE }); + + switch (stateReturn) { + case SaveStateReturn::SUCCESS: + SPDLOG_INFO("[SOH] Saved state to slot {}", slot); + break; + case SaveStateReturn::FAIL_WRONG_GAMESTATE: + SPDLOG_ERROR("[SOH] Can not save a state outside of \"GamePlay\""); + break; + [[unlikely]] default : break; + } + break; + } + case KbScancode::LUS_KB_F6: { + if (CVarGetInteger("gSaveStatesEnabled", 0) == 0) { + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->TextDrawNotification( + 6.0f, true, "Save states not enabled. Check Cheats Menu."); + return; + } + unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); + slot++; + if (slot > 5) { + slot = 0; + } + OTRGlobals::Instance->gSaveStateMgr->SetCurrentSlot(slot); + SPDLOG_INFO("Set SaveState slot to {}.", slot); + break; + } + case KbScancode::LUS_KB_F7: { + if (CVarGetInteger("gSaveStatesEnabled", 0) == 0) { + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->TextDrawNotification( + 6.0f, true, "Save states not enabled. Check Cheats Menu."); + return; + } + const unsigned int slot = OTRGlobals::Instance->gSaveStateMgr->GetCurrentSlot(); + const SaveStateReturn stateReturn = + OTRGlobals::Instance->gSaveStateMgr->AddRequest({ slot, RequestType::LOAD }); + + switch (stateReturn) { + case SaveStateReturn::SUCCESS: + SPDLOG_INFO("[SOH] Loaded state from slot {}", slot); + break; + case SaveStateReturn::FAIL_INVALID_SLOT: + SPDLOG_ERROR("[SOH] Invalid State Slot Number {}", slot); + break; + case SaveStateReturn::FAIL_STATE_EMPTY: + SPDLOG_ERROR("[SOH] State Slot {} is empty", slot); + break; + case SaveStateReturn::FAIL_WRONG_GAMESTATE: + SPDLOG_ERROR("[SOH] Can not load a state outside of \"GamePlay\""); + break; + [[unlikely]] default : break; + } + + break; + } +#endif +#if defined(_WIN32) || defined(__APPLE__) + case KbScancode::LUS_KB_F9: { + // Toggle TTS + CVarSetInteger("gA11yTTS", !CVarGetInteger("gA11yTTS", 0)); + break; + } +#endif + case KbScancode::LUS_KB_TAB: { + // Toggle HD Assets + CVarSetInteger("gAltAssets", !CVarGetInteger("gAltAssets", 0)); + //ShouldClearTextureCacheAtEndOfFrame = true; + break; + } + } +#endif + OTRGlobals::Instance->context->GetWindow()->StartFrame(); +} + +void RunCommands(Gfx* Commands, const std::vector>& mtx_replacements) { + //for (const auto& m : mtx_replacements) { + gfx_run(Commands, {}); + gfx_end_frame(); + // } +} + +// C->C++ Bridge +extern "C" void Graph_ProcessGfxCommands(Gfx* commands) { + { + //std::unique_lock Lock(audio.mutex); + //audio.processing = true; + } + + //audio.cv_to_thread.notify_one(); + std::vector> mtx_replacements; + int target_fps = 20; + //OTRGlobals::Instance->GetInterpolationFPS(); + static int last_fps; + static int last_update_rate; + static int time; + int fps = target_fps; + int original_fps = 60 / R_UPDATE_RATE; + + if (target_fps == 20 || original_fps > target_fps) { + fps = original_fps; + } + + if (last_fps != fps || last_update_rate != R_UPDATE_RATE) { + time = 0; + } + + // time_base = fps * original_fps (one second) + // int next_original_frame = fps; + + //while (time + original_fps <= next_original_frame) { + // time += original_fps; + // if (time != next_original_frame) { + // mtx_replacements.push_back(FrameInterpolation_Interpolate((float)time / next_original_frame)); + // } else { + // mtx_replacements.emplace_back(); + // } + //} + + //time -= fps; + + OTRGlobals::Instance->context->GetWindow()->SetTargetFps(original_fps); + // OTRGlobals::Instance->context->GetWindow()->SetTargetFps(20); + //OTRGlobals::Instance->context->GetWindow()->SetTargetFps(60); + + //int threshold = CVarGetInteger("gExtraLatencyThreshold", 80); + //OTRGlobals::Instance->context->GetWindow()->SetMaximumFrameLatency(threshold > 0 && target_fps >= threshold ? 2 + //: 1); + + RunCommands(commands, mtx_replacements); + + //last_fps = fps; + //last_update_rate = R_UPDATE_RATE; + + //{ + // std::unique_lock Lock(audio.mutex); + // while (audio.processing) { + // audio.cv_from_thread.wait(Lock); + // } + //} + // + //if (ShouldClearTextureCacheAtEndOfFrame) { + // gfx_texture_cache_clear(); + // LUS::SkeletonPatcher::UpdateSkeletons(); + // ShouldClearTextureCacheAtEndOfFrame = false; + //} + + // OTRTODO: FIGURE OUT END FRAME POINT + /* if (OTRGlobals::Instance->context->lastScancode != -1) + OTRGlobals::Instance->context->lastScancode = -1;*/ +} + +float divisor_num = 0.0f; + +extern "C" void OTRGetPixelDepthPrepare(float x, float y) { + OTRGlobals::Instance->context->GetWindow()->GetPixelDepthPrepare(x, y); +} + +extern "C" uint16_t OTRGetPixelDepth(float x, float y) { + return OTRGlobals::Instance->context->GetWindow()->GetPixelDepth(x, y); +} + +extern "C" uint32_t ResourceMgr_GetNumGameVersions() { + return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions().size(); +} + +extern "C" uint32_t ResourceMgr_GetGameVersion(int index) { + return LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index]; +} + +extern "C" uint32_t ResourceMgr_GetGamePlatform(int index) { + uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index]; + + switch (version) { + case OOT_NTSC_US_10: + case OOT_NTSC_US_11: + case OOT_NTSC_US_12: + case OOT_PAL_10: + case OOT_PAL_11: + return GAME_PLATFORM_N64; + case OOT_NTSC_JP_GC: + case OOT_NTSC_US_GC: + case OOT_PAL_GC: + case OOT_NTSC_JP_MQ: + case OOT_NTSC_US_MQ: + case OOT_PAL_MQ: + case OOT_PAL_GC_DBG1: + case OOT_PAL_GC_DBG2: + case OOT_PAL_GC_MQ_DBG: + return GAME_PLATFORM_GC; + } +} + +extern "C" uint32_t ResourceMgr_GetGameRegion(int index) { + uint32_t version = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->GetGameVersions()[index]; + + switch (version) { + case OOT_NTSC_US_10: + case OOT_NTSC_US_11: + case OOT_NTSC_US_12: + case OOT_NTSC_JP_GC: + case OOT_NTSC_US_GC: + case OOT_NTSC_JP_MQ: + case OOT_NTSC_US_MQ: + return GAME_REGION_NTSC; + case OOT_PAL_10: + case OOT_PAL_11: + case OOT_PAL_GC: + case OOT_PAL_MQ: + case OOT_PAL_GC_DBG1: + case OOT_PAL_GC_DBG2: + case OOT_PAL_GC_MQ_DBG: + return GAME_REGION_PAL; + } +} + +uint32_t IsSceneMasterQuest(s16 sceneNum) { + return false; + uint32_t value = 0; + //uint8_t mqMode = CVarGetInteger("gBetterDebugWarpScreenMQMode", WARP_MODE_OVERRIDE_OFF); + //if (mqMode == WARP_MODE_OVERRIDE_MQ_AS_VANILLA) { + // return 1; + //} else if (mqMode == WARP_MODE_OVERRIDE_VANILLA_AS_MQ) { + // return 0; + //} else { + // if (OTRGlobals::Instance->HasMasterQuest()) { + // if (!OTRGlobals::Instance->HasOriginal()) { + // value = 1; + // } else if (IS_MASTER_QUEST) { + // value = 1; + // } else { + // value = 0; + // if (IS_RANDO && !OTRGlobals::Instance->gRandomizer->masterQuestDungeons.empty() && + // OTRGlobals::Instance->gRandomizer->masterQuestDungeons.contains(sceneNum)) { + // value = 1; + // } + // } + // } + //} + return value; +} + +uint32_t IsGameMasterQuest() { + return false; + //return gPlayState != NULL ? IsSceneMasterQuest(gPlayState->sceneNum) : 0; +} + +extern "C" uint32_t ResourceMgr_GameHasMasterQuest() { + return OTRGlobals::Instance->HasMasterQuest(); +} + +extern "C" uint32_t ResourceMgr_GameHasOriginal() { + return OTRGlobals::Instance->HasOriginal(); +} + +extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum) { + return IsSceneMasterQuest(sceneNum); +} + +extern "C" uint32_t ResourceMgr_IsGameMasterQuest() { + return IsGameMasterQuest(); +} + +extern "C" void ResourceMgr_LoadDirectory(const char* resName) { + LUS::Context::GetInstance()->GetResourceManager()->LoadDirectory(resName); +} +extern "C" void ResourceMgr_DirtyDirectory(const char* resName) { + LUS::Context::GetInstance()->GetResourceManager()->DirtyDirectory(resName); +} + +// OTRTODO: There is probably a more elegant way to go about this... +// Kenix: This is definitely leaking memory when it's called. +extern "C" char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize) { + auto lst = LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles(searchMask); + char** result = (char**)malloc(lst->size() * sizeof(char*)); + + for (size_t i = 0; i < lst->size(); i++) { + char* str = (char*)malloc(lst.get()[0][i].size() + 1); + memcpy(str, lst.get()[0][i].data(), lst.get()[0][i].size()); + str[lst.get()[0][i].size()] = '\0'; + result[i] = str; + } + *resultSize = lst->size(); + + return result; +} + +extern "C" uint8_t ResourceMgr_FileExists(const char* filePath) { + std::string path = filePath; + if (path.substr(0, 7) == "__OTR__") { + path = path.substr(7); + } + + return ExtensionCache.contains(path); +} + +extern "C" void ResourceMgr_LoadFile(const char* resName) { + LUS::Context::GetInstance()->GetResourceManager()->LoadResource(resName); +} + +std::shared_ptr GetResourceByNameHandlingMQ(const char* path) { + std::string Path = path; + if (ResourceMgr_IsGameMasterQuest()) { + size_t pos = 0; + if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) { + Path.replace(pos, 7, "/mq/"); + } + } + return LUS::Context::GetInstance()->GetResourceManager()->LoadResource(Path.c_str()); +} + +extern "C" char* GetResourceDataByNameHandlingMQ(const char* path) { + auto res = GetResourceByNameHandlingMQ(path); + + if (res == nullptr) { + return nullptr; + } + + return (char*)res->GetRawPointer(); +} + +extern "C" char* ResourceMgr_LoadFileFromDisk(const char* filePath) { + FILE* file = fopen(filePath, "r"); + fseek(file, 0, SEEK_END); + int fSize = ftell(file); + fseek(file, 0, SEEK_SET); + + char* data = (char*)malloc(fSize); + fread(data, 1, fSize, file); + + fclose(file); + + return data; +} + +extern "C" uint8_t ResourceMgr_ResourceIsBackground(char* texPath) { + auto res = GetResourceByNameHandlingMQ(texPath); + return res->GetInitData()->Type == LUS::ResourceType::SOH_Background; +} + +extern "C" char* ResourceMgr_LoadJPEG(char* data, size_t dataSize) { + static char* finalBuffer = 0; + + if (finalBuffer == 0) + finalBuffer = (char*)malloc(dataSize); + + int w; + int h; + int comp; + + unsigned char* pixels = + stbi_load_from_memory((const unsigned char*)data, 320 * 240 * 2, &w, &h, &comp, STBI_rgb_alpha); + // unsigned char* pixels = stbi_load_from_memory((const unsigned char*)data, 480 * 240 * 2, &w, &h, &comp, + // STBI_rgb_alpha); + int idx = 0; + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + uint16_t* bufferTest = (uint16_t*)finalBuffer; + int pixelIdx = ((y * w) + x) * 4; + + uint8_t r = pixels[pixelIdx + 0] / 8; + uint8_t g = pixels[pixelIdx + 1] / 8; + uint8_t b = pixels[pixelIdx + 2] / 8; + + uint8_t alphaBit = pixels[pixelIdx + 3] != 0; + + uint16_t data = (r << 11) + (g << 6) + (b << 1) + alphaBit; + + finalBuffer[idx++] = (data & 0xFF00) >> 8; + finalBuffer[idx++] = (data & 0x00FF); + } + } + + return (char*)finalBuffer; +} + +extern "C" uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); + +extern "C" uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); + +extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) { + auto res = GetResourceByNameHandlingMQ(filePath); + + if (res->GetInitData()->Type == LUS::ResourceType::DisplayList) + return (char*)&((std::static_pointer_cast(res))->Instructions[0]); + else if (res->GetInitData()->Type == LUS::ResourceType::Array) + return (char*)(std::static_pointer_cast(res))->Vertices.data(); + else { + return (char*)GetResourceDataByNameHandlingMQ(filePath); + } +} + +extern "C" char* ResourceMgr_LoadIfDListByName(const char* filePath) { + auto res = GetResourceByNameHandlingMQ(filePath); + + if (res->GetInitData()->Type == LUS::ResourceType::DisplayList) + return (char*)&((std::static_pointer_cast(res))->Instructions[0]); + + return nullptr; +} + +//extern "C" Sprite* GetSeedTexture(uint8_t index) { +// return OTRGlobals::Instance->gRandomizer->GetSeedTexture(index); +//} + +extern "C" char* ResourceMgr_LoadPlayerAnimByName(const char* animPath) { + auto anim = std::static_pointer_cast(GetResourceByNameHandlingMQ(animPath)); + + return (char*)&anim->limbRotData[0]; +} + +extern "C" void ResourceMgr_PushCurrentDirectory(char* path) { + gfx_push_current_dir(path); +} + +extern "C" Gfx* ResourceMgr_LoadGfxByName(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + return (Gfx*)&res->Instructions[0]; +} + +typedef struct { + int index; + Gfx instruction; +} GfxPatch; + +std::unordered_map> originalGfx; + +// Attention! This is primarily for cosmetics & bug fixes. For things like mods and model replacement you should be +// using OTRs instead (When that is available). Index can be found using the commented out section below. +extern "C" void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction) { + auto res = std::static_pointer_cast( + LUS::Context::GetInstance()->GetResourceManager()->LoadResource(path)); + + // Leaving this here for people attempting to find the correct Dlist index to patch + /*if (strcmp("__OTR__objects/object_gi_longsword/gGiBiggoronSwordDL", path) == 0) { + for (int i = 0; i < res->instructions.size(); i++) { + Gfx* gfx = (Gfx*)&res->instructions[i]; + // Log all commands + // SPDLOG_INFO("index:{} command:{}", i, gfx->words.w0 >> 24); + // Log only SetPrimColors + if (gfx->words.w0 >> 24 == 250) { + SPDLOG_INFO("index:{} r:{} g:{} b:{} a:{}", i, _SHIFTR(gfx->words.w1, 24, 8), _SHIFTR(gfx->words.w1, 16, + 8), _SHIFTR(gfx->words.w1, 8, 8), _SHIFTR(gfx->words.w1, 0, 8)); + } + } + }*/ + + // Index refers to individual gfx words, which are half the size on 32-bit + // if (sizeof(uintptr_t) < 8) { + // index /= 2; + // } + + Gfx* gfx = (Gfx*)&res->Instructions[index]; + + if (!originalGfx.contains(path) || !originalGfx[path].contains(patchName)) { + originalGfx[path][patchName] = { index, *gfx }; + } + + *gfx = instruction; +} + +extern "C" void ResourceMgr_PatchGfxCopyCommandByName(const char* path, const char* patchName, int destinationIndex, + int sourceIndex) { + auto res = std::static_pointer_cast( + LUS::Context::GetInstance()->GetResourceManager()->LoadResource(path)); + + Gfx* destinationGfx = (Gfx*)&res->Instructions[destinationIndex]; + Gfx sourceGfx = res->Instructions[sourceIndex]; + + if (!originalGfx.contains(path) || !originalGfx[path].contains(patchName)) { + originalGfx[path][patchName] = { destinationIndex, *destinationGfx }; + } + + *destinationGfx = sourceGfx; +} + +extern "C" void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName) { + if (originalGfx.contains(path) && originalGfx[path].contains(patchName)) { + auto res = std::static_pointer_cast( + LUS::Context::GetInstance()->GetResourceManager()->LoadResource(path)); + + Gfx* gfx = (Gfx*)&res->Instructions[originalGfx[path][patchName].index]; + *gfx = originalGfx[path][patchName].instruction; + + originalGfx[path].erase(patchName); + } +} + +extern "C" char* ResourceMgr_LoadVtxArrayByName(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + + return (char*)res->Vertices.data(); +} + +extern "C" size_t ResourceMgr_GetVtxArraySizeByName(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + + return res->Vertices.size(); + // } +} + +extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + + return (char*)res->Scalars.data(); +} + +extern "C" size_t ResourceMgr_GetArraySizeByName(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + + return res->Scalars.size(); + // } +} +extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + + // if (res->CachedGameAsset != nullptr) + // return (char*)res->CachedGameAsset; + // else + // { + Vec3s* data = (Vec3s*)malloc(sizeof(Vec3s) * res->Scalars.size()); + + for (size_t i = 0; i < res->Scalars.size(); i += 3) { + data[(i / 3)].x = res->Scalars[i + 0].s16; + data[(i / 3)].y = res->Scalars[i + 1].s16; + data[(i / 3)].z = res->Scalars[i + 2].s16; + } + + // res->CachedGameAsset = data; + + return (char*)data; + // } +} + +extern "C" AnimatedMaterial* ResourceMgr_LoadAnimatedMatByName(const char* path) { + return (AnimatedMaterial*)ResourceGetDataByName(path); +} + +extern "C" CollisionHeader* ResourceMgr_LoadColByName(const char* path) { + return (CollisionHeader*)ResourceGetDataByName(path); +} + +extern "C" Vtx* ResourceMgr_LoadVtxByName(char* path) { + return (Vtx*)ResourceGetDataByName(path); +} + +//extern "C" SequenceData ResourceMgr_LoadSeqByName(const char* path) { +// SequenceData* sequence = (SequenceData*)ResourceGetDataByName(path); +// return *sequence; +//} +// +//std::map cachedCustomSFs; +#if 0 +extern "C" SoundFontSample* ReadCustomSample(const char* path) { + return nullptr; + /* + if (!ExtensionCache.contains(path)) + return nullptr; + + ExtensionEntry entry = ExtensionCache[path]; + + auto sampleRaw = LUS::Context::GetInstance()->GetResourceManager()->LoadFile(entry.path); + uint32_t* strem = (uint32_t*)sampleRaw->Buffer.get(); + uint8_t* strem2 = (uint8_t*)strem; + + SoundFontSample* sampleC = new SoundFontSample; + + if (entry.ext == "wav") { + drwav_uint32 channels; + drwav_uint32 sampleRate; + drwav_uint64 totalPcm; + drmp3_int16* pcmData = + drwav_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &channels, &sampleRate, + &totalPcm, NULL); sampleC->size = totalPcm; sampleC->sampleAddr = (uint8_t*)pcmData; sampleC->codec = CODEC_S16; + + sampleC->loop = new AdpcmLoop; + sampleC->loop->start = 0; + sampleC->loop->end = sampleC->size - 1; + sampleC->loop->count = 0; + sampleC->sampleRateMagicValue = 'RIFF'; + sampleC->sampleRate = sampleRate; + + cachedCustomSFs[path] = sampleC; + return sampleC; + } else if (entry.ext == "mp3") { + drmp3_config mp3Info; + drmp3_uint64 totalPcm; + drmp3_int16* pcmData = + drmp3_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &mp3Info, &totalPcm, NULL); + + sampleC->size = totalPcm * mp3Info.channels * sizeof(short); + sampleC->sampleAddr = (uint8_t*)pcmData; + sampleC->codec = CODEC_S16; + + sampleC->loop = new AdpcmLoop; + sampleC->loop->start = 0; + sampleC->loop->end = sampleC->size; + sampleC->loop->count = 0; + sampleC->sampleRateMagicValue = 'RIFF'; + sampleC->sampleRate = mp3Info.sampleRate; + + cachedCustomSFs[path] = sampleC; + return sampleC; + } + + return nullptr; + */ +} + +extern "C" SoundFontSample* ResourceMgr_LoadAudioSample(const char* path) { + return (SoundFontSample*)ResourceGetDataByName(path); +} + +extern "C" SoundFont* ResourceMgr_LoadAudioSoundFont(const char* path) { + return (SoundFont*)ResourceGetDataByName(path); +} +#endif +extern "C" int ResourceMgr_OTRSigCheck(char* imgData) { + uintptr_t i = (uintptr_t)(imgData); + + // if (i == 0xD9000000 || i == 0xE7000000 || (i & 1) == 1) + if ((i & 1) == 1) + return 0; + + // if ((i & 0xFF000000) != 0xAB000000 && (i & 0xFF000000) != 0xCD000000 && i != 0) { + if (i != 0) { + if (imgData[0] == '_' && imgData[1] == '_' && imgData[2] == 'O' && imgData[3] == 'T' && imgData[4] == 'R' && + imgData[5] == '_' && imgData[6] == '_') + return 1; + } + + return 0; +} + +extern "C" AnimationHeaderCommon* ResourceMgr_LoadAnimByName(const char* path) { + return (AnimationHeaderCommon*)ResourceGetDataByName(path); +} + +extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path, SkelAnime* skelAnime) { + std::string pathStr = std::string(path); + static const std::string sOtr = "__OTR__"; + + if (pathStr.starts_with(sOtr)) { + pathStr = pathStr.substr(sOtr.length()); + } + + bool isAlt = CVarGetInteger("gAltAssets", 0); + + if (isAlt) { + pathStr = LUS::IResource::gAltAssetPrefix + pathStr; + } + + SkeletonHeader* skelHeader = (SkeletonHeader*)ResourceGetDataByName(pathStr.c_str()); + + // If there isn't an alternate model, load the regular one + if (isAlt && skelHeader == NULL) { + skelHeader = (SkeletonHeader*)ResourceGetDataByName(path); + } + + // This function is only called when a skeleton is initialized. + // Therefore we can take this oppurtunity to take note of the Skeleton that is created... + if (skelAnime != nullptr) { + auto stringPath = std::string(path); + //LUS::SkeletonPatcher::RegisterSkeleton(stringPath, skelAnime); + } + + return skelHeader; +} + +extern "C" void ResourceMgr_UnregisterSkeleton(SkelAnime* skelAnime) { + if (skelAnime != nullptr) + LUS::SkeletonPatcher::UnregisterSkeleton(skelAnime); +} + +extern "C" void ResourceMgr_ClearSkeletons(SkelAnime* skelAnime) { + if (skelAnime != nullptr) + LUS::SkeletonPatcher::ClearSkeletons(); +} + +extern "C" s32* ResourceMgr_LoadCSByName(const char* path) { + return (s32*)GetResourceDataByNameHandlingMQ(path); +} + +std::filesystem::path GetSaveFile(std::shared_ptr Conf) { + const std::string fileName = + Conf->GetString("Game.SaveName", LUS::Context::GetPathRelativeToAppDirectory("oot_save.sav")); + std::filesystem::path saveFile = std::filesystem::absolute(fileName); + + if (!exists(saveFile.parent_path())) { + create_directories(saveFile.parent_path()); + } + + return saveFile; +} + +std::filesystem::path GetSaveFile() { + const std::shared_ptr pConf = OTRGlobals::Instance->context->GetConfig(); + + return GetSaveFile(pConf); +} + +void OTRGlobals::CheckSaveFile(size_t sramSize) const { + const std::shared_ptr pConf = Instance->context->GetConfig(); + + std::filesystem::path savePath = GetSaveFile(pConf); + std::fstream saveFile(savePath, std::fstream::in | std::fstream::out | std::fstream::binary); + if (saveFile.fail()) { + saveFile.open(savePath, std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::app); + for (int i = 0; i < sramSize; ++i) { + saveFile.write("\0", 1); + } + } + saveFile.close(); +} + +//extern "C" void Ctx_ReadSaveFile(uintptr_t addr, void* dramAddr, size_t size) { +// SaveManager::ReadSaveFile(GetSaveFile(), addr, dramAddr, size); +//} + +//extern "C" void Ctx_WriteSaveFile(uintptr_t addr, void* dramAddr, size_t size) { +// SaveManager::WriteSaveFile(GetSaveFile(), addr, dramAddr, size); +//} + +std::wstring StringToU16(const std::string& s) { + std::vector result; + size_t i = 0; + while (i < s.size()) { + unsigned long uni; + size_t nbytes; + bool error = false; + unsigned char c = s[i++]; + if (c < 0x80) { // ascii + uni = c; + nbytes = 0; + } else if (c <= 0xBF) { // assuming kata/hiragana delimiter + nbytes = 0; + uni = '\1'; + } else if (c <= 0xDF) { + uni = c & 0x1F; + nbytes = 1; + } else if (c <= 0xEF) { + uni = c & 0x0F; + nbytes = 2; + } else if (c <= 0xF7) { + uni = c & 0x07; + nbytes = 3; + } + for (size_t j = 0; j < nbytes; ++j) { + unsigned char c = s[i++]; + uni <<= 6; + uni += c & 0x3F; + } + if (uni != '\1') + result.push_back(uni); + } + std::wstring utf16; + for (size_t i = 0; i < result.size(); ++i) { + unsigned long uni = result[i]; + if (uni <= 0xFFFF) { + utf16 += (wchar_t)uni; + } else { + uni -= 0x10000; + utf16 += (wchar_t)((uni >> 10) + 0xD800); + utf16 += (wchar_t)((uni & 0x3FF) + 0xDC00); + } + } + return utf16; +} + +int CopyStringToCharBuffer(const std::string& inputStr, char* buffer, const int maxBufferSize) { + if (!inputStr.empty()) { + // Prevent potential horrible overflow due to implicit conversion of maxBufferSize to an unsigned. Prevents + // negatives. + memset(buffer, 0, std::max(0, maxBufferSize)); + // Gaurentee that this value will be greater than 0, regardless of passed variables. + const int copiedCharLen = std::min(std::max(0, maxBufferSize - 1), inputStr.length()); + memcpy(buffer, inputStr.c_str(), copiedCharLen); + return copiedCharLen; + } + + return 0; +} + +extern "C" void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)) { + const std::vector hira1 = { + u'を', u'ぁ', u'ぃ', u'ぅ', u'ぇ', u'ぉ', u'ゃ', u'ゅ', u'ょ', u'っ', u'-', u'あ', u'い', + u'う', u'え', u'お', u'か', u'き', u'く', u'け', u'こ', u'さ', u'し', u'す', u'せ', u'そ', + }; + + const std::vector hira2 = { + u'た', u'ち', u'つ', u'て', u'と', u'な', u'に', u'ぬ', u'ね', u'の', u'は', u'ひ', u'ふ', u'へ', u'ほ', u'ま', + u'み', u'む', u'め', u'も', u'や', u'ゆ', u'よ', u'ら', u'り', u'る', u'れ', u'ろ', u'わ', u'ん', u'゛', u'゜', + }; + + std::wstring wstr = StringToU16(str); + + for (const auto& c : wstr) { + unsigned char convt = ' '; + if (c < 0x80) { + printImpl(printer, c); + } else if (c >= u'。' && c <= u'゚') { // katakana + printImpl(printer, c - 0xFEC0); + } else { + auto it = std::find(hira1.begin(), hira1.end(), c); + if (it != hira1.end()) { // hiragana block 1 + printImpl(printer, 0x88 + std::distance(hira1.begin(), it)); + } + + auto it2 = std::find(hira2.begin(), hira2.end(), c); + if (it2 != hira2.end()) { // hiragana block 2 + printImpl(printer, 0xe0 + std::distance(hira2.begin(), it2)); + } + } + } +} + +extern "C" uint32_t OTRGetCurrentWidth() { + return OTRGlobals::Instance->context->GetWindow()->GetWidth(); +} + +extern "C" uint32_t OTRGetCurrentHeight() { + return OTRGlobals::Instance->context->GetWindow()->GetHeight(); +} + +Color_RGB8 GetColorForControllerLED() { + #if 0 + auto brightness = CVarGetFloat("gLedBrightness", 1.0f) / 1.0f; + Color_RGB8 color = { 0, 0, 0 }; + if (brightness > 0.0f) { + LEDColorSource source = + static_cast(CVarGetInteger("gLedColorSource", LED_SOURCE_TUNIC_ORIGINAL)); + bool criticalOverride = CVarGetInteger("gLedCriticalOverride", 1); + if (gPlayState && (source == LED_SOURCE_TUNIC_ORIGINAL || source == LED_SOURCE_TUNIC_COSMETICS)) { + switch (CUR_EQUIP_VALUE(EQUIP_TUNIC) - 1) { + case PLAYER_TUNIC_KOKIRI: + color = source == LED_SOURCE_TUNIC_COSMETICS + ? CVarGetColor24("gCosmetics.Link_KokiriTunic.Value", kokiriColor) + : kokiriColor; + break; + case PLAYER_TUNIC_GORON: + color = source == LED_SOURCE_TUNIC_COSMETICS + ? CVarGetColor24("gCosmetics.Link_GoronTunic.Value", goronColor) + : goronColor; + break; + case PLAYER_TUNIC_ZORA: + color = source == LED_SOURCE_TUNIC_COSMETICS + ? CVarGetColor24("gCosmetics.Link_ZoraTunic.Value", zoraColor) + : zoraColor; + break; + } + } + if (source == LED_SOURCE_CUSTOM) { + color = CVarGetColor24("gLedPort1Color", { 255, 255, 255 }); + } + if (criticalOverride || source == LED_SOURCE_HEALTH) { + if (HealthMeter_IsCritical()) { + color = { 0xFF, 0, 0 }; + } else if (source == LED_SOURCE_HEALTH) { + if (gSaveContext.health / gSaveContext.healthCapacity <= 0.4f) { + color = { 0xFF, 0xFF, 0 }; + } else { + color = { 0, 0xFF, 0 }; + } + } + } + color.r = color.r * brightness; + color.g = color.g * brightness; + color.b = color.b * brightness; + } + #endif + return { 0, 0, 0 }; +} + +extern "C" void OTRControllerCallback(uint8_t rumble) { + auto physicalDevice = LUS::Context::GetInstance()->GetControlDeck()->GetDeviceFromPortIndex(0); + + if (physicalDevice->CanSetLed()) { + // We call this every tick, SDL accounts for this use and prevents driver spam + // https://github.com/libsdl-org/SDL/blob/f17058b562c8a1090c0c996b42982721ace90903/src/joystick/SDL_joystick.c#L1114-L1144 + physicalDevice->SetLedColor(0, GetColorForControllerLED()); + } + + physicalDevice->SetRumble(0, rumble); +} + +extern "C" float OTRGetAspectRatio() { + return gfx_current_dimensions.aspect_ratio; +} + +extern "C" float OTRGetDimensionFromLeftEdge(float v) { + return (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * OTRGetAspectRatio() + (v)); +} + +extern "C" float OTRGetDimensionFromRightEdge(float v) { + return (SCREEN_WIDTH / 2 + SCREEN_HEIGHT / 2 * OTRGetAspectRatio() - (SCREEN_WIDTH - v)); +} + +f32 floorf(f32 x); +f32 ceilf(f32 x); + +extern "C" int16_t OTRGetRectDimensionFromLeftEdge(float v) { + return ((int)floorf(OTRGetDimensionFromLeftEdge(v))); +} + +extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) { + return ((int)ceilf(OTRGetDimensionFromRightEdge(v))); +} + +extern "C" int AudioPlayer_Buffered(void) { + return AudioPlayerBuffered(); +} + +extern "C" int AudioPlayer_GetDesiredBuffered(void) { + return AudioPlayerGetDesiredBuffered(); +} + +extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) { + AudioPlayerPlayFrame(buf, len); +} + +extern "C" int Controller_ShouldRumble(size_t slot) { + auto controlDeck = LUS::Context::GetInstance()->GetControlDeck(); + + if (slot < controlDeck->GetNumConnectedPorts()) { + auto physicalDevice = controlDeck->GetDeviceFromPortIndex(slot); + + if (physicalDevice->GetProfile(slot)->UseRumble && physicalDevice->CanRumble()) { + return 1; + } + } + + return 0; +} diff --git a/mm/2s2h/BenPort.h b/mm/2s2h/BenPort.h new file mode 100644 index 000000000..fbdd93bcf --- /dev/null +++ b/mm/2s2h/BenPort.h @@ -0,0 +1,137 @@ +#ifndef OTR_GLOBALS_H +#define OTR_GLOBALS_H + +#pragma once + + +#define GAME_REGION_NTSC 0 +#define GAME_REGION_PAL 1 + +#define GAME_PLATFORM_N64 0 +#define GAME_PLATFORM_GC 1 + +#ifdef __cplusplus +#include + +#include + +const std::string customMessageTableID = "BaseGameOverrides"; +const std::string appShortName = "soh"; + +class OTRGlobals { + public: + static OTRGlobals* Instance; + + std::shared_ptr context; + + OTRGlobals(); + ~OTRGlobals(); + + bool HasMasterQuest(); + bool HasOriginal(); + uint32_t GetInterpolationFPS(); + std::shared_ptr> ListFiles(std::string path); + + private: + void CheckSaveFile(size_t sramSize) const; + bool hasMasterQuest; + bool hasOriginal; +}; + +uint32_t IsGameMasterQuest(); +#endif + +#ifndef __cplusplus +void InitOTR(void); +void DeinitOTR(void); +void VanillaItemTable_Init(); +void OTRAudio_Init(); +void OTRMessage_Init(); +void InitAudio(); +void Graph_StartFrame(); +void Graph_ProcessGfxCommands(Gfx* commands); +void Graph_ProcessFrame(void (*run_one_game_iter)(void)); +void OTRLogString(const char* src); +void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)); +void OTRGetPixelDepthPrepare(float x, float y); +uint16_t OTRGetPixelDepth(float x, float y); +int32_t OTRGetLastScancode(); +uint32_t ResourceMgr_IsGameMasterQuest(); +uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum); +uint32_t ResourceMgr_GameHasMasterQuest(); +uint32_t ResourceMgr_GameHasOriginal(); +uint32_t ResourceMgr_GetNumGameVersions(); +uint32_t ResourceMgr_GetGameVersion(int index); +uint32_t ResourceMgr_GetGamePlatform(int index); +uint32_t ResourceMgr_GetGameRegion(int index); +void ResourceMgr_LoadDirectory(const char* resName); +char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize); +uint8_t ResourceMgr_FileExists(const char* resName); +char* GetResourceDataByNameHandlingMQ(const char* path); +void ResourceMgr_LoadFile(const char* resName); +char* ResourceMgr_LoadFileFromDisk(const char* filePath); +uint8_t ResourceMgr_ResourceIsBackground(char* texPath); +char* ResourceMgr_LoadJPEG(char* data, size_t dataSize); +uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); +uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); +CollisionHeader* ResourceMgr_LoadColByName(const char* path); +AnimatedMaterial* ResourceMgr_LoadAnimatedMatByName(const char* path); +char* ResourceMgr_LoadTexOrDListByName(const char* filePath); +char* ResourceMgr_LoadPlayerAnimByName(const char* animPath); +AnimationHeaderCommon* ResourceMgr_LoadAnimByName(const char* path); +char* ResourceMgr_GetNameByCRC(uint64_t crc, char* alloc); +Gfx* ResourceMgr_LoadGfxByCRC(uint64_t crc); +Gfx* ResourceMgr_LoadGfxByName(const char* path); +void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction); +void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName); +char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path); +char* ResourceMgr_LoadArrayByName(const char* path); +size_t ResourceMgr_GetArraySizeByName(const char* path); +Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc); +char* ResourceMgr_LoadVtxArrayByName(const char* path); +size_t ResourceMgr_GetVtxArraySizeByName(const char* path); +Vtx* ResourceMgr_LoadVtxByName(char* path); + +void Ctx_ReadSaveFile(uintptr_t addr, void* dramAddr, size_t size); +void Ctx_WriteSaveFile(uintptr_t addr, void* dramAddr, size_t size); + +uint64_t GetPerfCounter(); +struct SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path, SkelAnime* skelAnime); +void ResourceMgr_UnregisterSkeleton(SkelAnime* skelAnime); +void ResourceMgr_ClearSkeletons(); +s32* ResourceMgr_LoadCSByName(const char* path); +int ResourceMgr_OTRSigCheck(char* imgData); +uint64_t osGetTime(void); +uint32_t osGetCount(void); +uint32_t OTRGetCurrentWidth(void); +uint32_t OTRGetCurrentHeight(void); +float OTRGetAspectRatio(void); +float OTRGetDimensionFromLeftEdge(float v); +float OTRGetDimensionFromRightEdge(float v); +int16_t OTRGetRectDimensionFromLeftEdge(float v); +int16_t OTRGetRectDimensionFromRightEdge(float v); +int AudioPlayer_Buffered(void); +int AudioPlayer_GetDesiredBuffered(void); +void AudioPlayer_Play(const uint8_t* buf, uint32_t len); +void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); +int Controller_ShouldRumble(size_t slot); +void Controller_BlockGameInput(); +void Controller_UnblockGameInput(); +void Overlay_DisplayText(float duration, const char* text); +void Overlay_DisplayText_Seconds(int seconds, const char* text); + +void Gfx_RegisterBlendedTexture(const char* name, u8* mask, u8* replacement); +void CheckTracker_OnMessageClose(); + +int32_t GetGIID(uint32_t itemID); +#endif + +#ifdef __cplusplus +extern "C" { +#endif +uint64_t GetUnixTimestamp(); +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/mm/2s2h/Extractor/EndianCvt.o b/mm/2s2h/Extractor/EndianCvt.o new file mode 100644 index 000000000..23c9daa88 Binary files /dev/null and b/mm/2s2h/Extractor/EndianCvt.o differ diff --git a/mm/2s2h/Extractor/Extract.cpp b/mm/2s2h/Extractor/Extract.cpp new file mode 100644 index 000000000..ae3e325fb --- /dev/null +++ b/mm/2s2h/Extractor/Extract.cpp @@ -0,0 +1,603 @@ +#ifdef _WIN32 +#include +#include +#include +#pragma comment(lib, "Shlwapi.lib") +#endif +#include "Extract.h" +#include "portable-file-dialogs.h" +#include + +#ifdef unix +#include +#include +#include +#include +#endif + +#ifdef _MSC_VER +#define BSWAP32 _byteswap_ulong +#define BSWAP16 _byteswap_ushort +#elif __has_include() +#include +#define BSWAP32 bswap_32 +#define BSWAP16 bswap_16 +#else +#define BSWAP16(value) ((((value)&0xff) << 8) | ((value) >> 8)) + +#define BSWAP32(value) \ + (((uint32_t)BSWAP16((uint16_t)((value)&0xffff)) << 16) | (uint32_t)BSWAP16((uint16_t)((value) >> 16))) +#endif + +#if defined(_MSC_VER) +#define UNREACHABLE __assume(0) +#elif __llvm__ +#define UNREACHABLE __builtin_assume(0) +#else +#define UNREACHABLE __builtin_unreachable(); +#endif + +#include + +#include + +#include +#include +#include +#include +#include +#include + +extern "C" uint32_t CRC32C(unsigned char* data, size_t dataSize); + +static constexpr uint32_t OOT_PAL_GC = 0x09465AC3; +static constexpr uint32_t OOT_PAL_MQ = 0x1D4136F3; +static constexpr uint32_t OOT_PAL_GC_DBG1 = 0x871E1C92; // 03-21-2002 build +static constexpr uint32_t OOT_PAL_GC_DBG2 = 0x87121EFE; // 03-13-2002 build +static constexpr uint32_t OOT_PAL_GC_MQ_DBG = 0x917D18F6; +static constexpr uint32_t OOT_PAL_10 = 0xB044B569; +static constexpr uint32_t OOT_PAL_11 = 0xB2055FBD; +static constexpr uint32_t MM_US_10 = 0x5354631C; + +static const std::unordered_map verMap = { + { MM_US_10, "U.S 1.0" }, + //{ OOT_PAL_GC, "PAL Gamecube" }, + //{ OOT_PAL_MQ, "PAL MQ" }, + //{ OOT_PAL_GC_DBG1, "PAL Debug 1" }, + //{ OOT_PAL_GC_DBG2, "PAL Debug 2" }, + //{ OOT_PAL_GC_MQ_DBG, "PAL MQ Debug" }, + //{ OOT_PAL_10, "PAL N64 1.0" }, + //{ OOT_PAL_11, "PAL N64 1.1" }, +}; + +// TODO only check the first 54MB of the rom. +static constexpr std::array goodCrcs = { + + //0xfa8c0555, // MQ DBG 64MB (Original overdump) + //0x8652ac4c, // MQ DBG 64MB + //0x5B8A1EB7, // MQ DBG 64MB (Empty overdump) + //0x1f731ffe, // MQ DBG 54MB + //0x044b3982, // NMQ DBG 54MB + //0xEB15D7B9, // NMQ DBG 64MB + //0xDA8E61BF, // GC PAL + //0x7A2FAE68, // GC MQ PAL + //0xFD9913B1, // N64 PAL 1.0 + //0xE033FBBA, // N64 PAL 1.1 +}; + +enum class ButtonId : int { + YES, + NO, + FIND, +}; + + +void Extractor::ShowErrorBox(const char* title, const char* text) { +#ifdef _WIN32 + MessageBoxA(nullptr, text, title, MB_OK | MB_ICONERROR); +#else + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, text, nullptr); +#endif +} + +void Extractor::ShowSizeErrorBox() const { + std::unique_ptr boxBuffer = std::make_unique(mCurrentRomPath.size() + 100); + snprintf(boxBuffer.get(), mCurrentRomPath.size() + 100, + "The rom file %s was not a valid size. Was %zu MB, expecting 32, 54, or 64MB.", mCurrentRomPath.c_str(), + mCurRomSize / MB_BASE); + ShowErrorBox("Invalid Rom Size", boxBuffer.get()); +} + +void Extractor::ShowCrcErrorBox() const { + ShowErrorBox("Rom CRC invalid", "Rom CRC did not match the list of known good roms. Please find another."); +} + +int Extractor::ShowRomPickBox(uint32_t verCrc) const { + std::unique_ptr boxBuffer = std::make_unique(mCurrentRomPath.size() + 100); + SDL_MessageBoxData boxData = { 0 }; + SDL_MessageBoxButtonData buttons[3] = { { 0 } }; + int ret; + + buttons[0].buttonid = 0; + buttons[0].text = "Yes"; + buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; + buttons[1].buttonid = 1; + buttons[1].text = "No"; + buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; + buttons[2].buttonid = 2; + buttons[2].text = "Find ROM"; + boxData.numbuttons = 3; + boxData.flags = SDL_MESSAGEBOX_INFORMATION; + boxData.message = boxBuffer.get(); + boxData.title = "Rom Detected"; + boxData.window = nullptr; + + boxData.buttons = buttons; + snprintf(boxBuffer.get(), mCurrentRomPath.size() + 100, + "Rom detected: %s, Header CRC32: %8X. It appears to be: %s. Use this rom?", mCurrentRomPath.c_str(), + verCrc, verMap.at(verCrc)); + + SDL_ShowMessageBox(&boxData, &ret); + return ret; +} + +int Extractor::ShowYesNoBox(const char* title, const char* box) { + int ret; +#ifdef _WIN32 + ret = MessageBoxA(nullptr, box, title, MB_YESNO | MB_ICONQUESTION); +#else + SDL_MessageBoxData boxData = { 0 }; + SDL_MessageBoxButtonData buttons[2] = { { 0 } }; + + buttons[0].buttonid = IDYES; + buttons[0].text = "Yes"; + buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT; + buttons[1].buttonid = IDNO; + buttons[1].text = "No"; + buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT; + boxData.numbuttons = 2; + boxData.flags = SDL_MESSAGEBOX_INFORMATION; + boxData.message = box; + boxData.title = title; + boxData.buttons = buttons; + SDL_ShowMessageBox(&boxData, &ret); +#endif + return ret; +} + +void Extractor::SetRomInfo(const std::string& path) { + mCurrentRomPath = path; + mCurRomSize = GetCurRomSize(); +} + +void Extractor::FilterRoms(std::vector& roms, RomSearchMode searchMode) { + std::ifstream inFile; + std::vector::iterator it = roms.begin(); + + while (it != roms.end()) { + std::string rom = *it; + SetRomInfo(rom); + + // Skip. We will handle rom size errors later on after filtering + if (!ValidateRomSize()) { + it++; + continue; + } + + inFile.open(rom, std::ios::in | std::ios::binary); + inFile.read((char*)mRomData.get(), mCurRomSize); + inFile.clear(); + inFile.close(); + + BitConverter::RomToBigEndian(mRomData.get(), mCurRomSize); + + // Rom doesn't claim to be valid + // Game type doesn't match search mode + if (!verMap.contains(GetRomVerCrc()) || + (searchMode == RomSearchMode::Vanilla && IsMasterQuest()) || + (searchMode == RomSearchMode::MQ && !IsMasterQuest())) { + it = roms.erase(it); + continue; + } + + it++; + } +} + +void Extractor::GetRoms(std::vector& roms) { +#ifdef _WIN32 + WIN32_FIND_DATAA ffd; + HANDLE h = FindFirstFileA(".\\*", &ffd); + + do { + if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + char* ext = PathFindExtensionA(ffd.cFileName); + + // Check for any standard N64 rom file extensions. + if ((strcmp(ext, ".z64") == 0) || (strcmp(ext, ".n64") == 0) || (strcmp(ext, ".v64") == 0)) + roms.push_back(ffd.cFileName); + } + } while (FindNextFileA(h, &ffd) != 0); + // if (h != nullptr) { + // CloseHandle(h); + //} +#elif unix + // Open the directory of the app. + DIR* d = opendir("."); + struct dirent* dir; + + if (d != NULL) { + // Go through each file in the directory + while ((dir = readdir(d)) != NULL) { + struct stat path; + + // Check if current entry is not folder + stat(dir->d_name, &path); + if (S_ISREG(path.st_mode)) { + + // Get the position of the extension character. + char* ext = strrchr(dir->d_name, '.'); + if (ext != NULL && (strcmp(ext, ".z64") == 0 || strcmp(ext, ".n64") == 0 || + strcmp(ext, ".v64") == 0)) { + roms.push_back(dir->d_name); + } + } + } + } + closedir(d); +#else + for (const auto& file : std::filesystem::directory_iterator("./")) { + if (file.is_directory()) + continue; + if ((file.path().extension() == ".n64") || (file.path().extension() == ".z64") || + (file.path().extension() == ".v64")) { + roms.push_back((file.path())); + } + } +#endif +} + +bool Extractor::GetRomPathFromBox() { +#ifdef _WIN32 + OPENFILENAMEA box = { 0 }; + char nameBuffer[512]; + nameBuffer[0] = 0; + + box.lStructSize = sizeof(box); + box.lpstrFile = nameBuffer; + box.nMaxFile = sizeof(nameBuffer) / sizeof(nameBuffer[0]); + box.lpstrTitle = "Open Rom"; + box.Flags = OFN_NOCHANGEDIR | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; + box.lpstrFilter = "N64 Roms\0*.z64;*.v64;*.n64\0\0"; + if (!GetOpenFileNameA(&box)) { + DWORD err = CommDlgExtendedError(); + // GetOpenFileName will return 0 but no error is set if the user just closes the box. + if (err != 0) { + const char* errStr = nullptr; + switch (err) { + case FNERR_BUFFERTOOSMALL: + errStr = "Path buffer too small. Move file closer to root of your drive"; + break; + case FNERR_INVALIDFILENAME: + errStr = "File name for rom provided is invalid."; + break; + case FNERR_SUBCLASSFAILURE: + errStr = "Failed to open a filebox because there is not enough RAM to do so."; + break; + } + MessageBoxA(nullptr, "Box Error", errStr, MB_OK | MB_ICONERROR); + return false; + } + } + // The box was closed without something being selected. + if (nameBuffer[0] == 0) { + return false; + } + mCurrentRomPath = nameBuffer; + #else + auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64 *.n64 *.v64" }).result(); + + if (selection.empty()) { + return false; + } + + mCurrentRomPath = selection[0]; + #endif + mCurRomSize = GetCurRomSize(); + return true; +} + +uint32_t Extractor::GetRomVerCrc() const { + return BSWAP32(((uint32_t*)mRomData.get())[4]); +} + +size_t Extractor::GetCurRomSize() const { + return std::filesystem::file_size(mCurrentRomPath); +} + +bool Extractor::ValidateAndFixRom() { + // The MQ debug rom sometimes has the header patched to look like a US rom. Change it back + if (GetRomVerCrc() == OOT_PAL_GC_MQ_DBG) { + mRomData[0x3E] = 'P'; + } + + const uint32_t actualCrc = CRC32C(mRomData.get(), mCurRomSize); + + for (const uint32_t crc : goodCrcs) { + if (actualCrc == crc) { + return true; + } + } + return false; +} + +bool Extractor::ValidateRomSize() const { + if (mCurRomSize != MB32 && mCurRomSize != MB54 && mCurRomSize != MB64) { + return false; + } + return true; +} + +bool Extractor::ValidateRom(bool skipCrcTextBox) { + if (!ValidateRomSize()) { + ShowSizeErrorBox(); + return false; + } + if (!ValidateAndFixRom()) { + if (!skipCrcTextBox) { + ShowCrcErrorBox(); + } + return false; + } + return true; +} + +bool Extractor::ManuallySearchForRom() { + std::ifstream inFile; + + if (!GetRomPathFromBox()) { + ShowErrorBox("No rom selected", "No Rom selected. Exiting"); + return false; + } + + inFile.open(mCurrentRomPath, std::ios::in | std::ios::binary); + + if (!inFile.is_open()) { + return false; // TODO Handle error + } + + inFile.read((char*)mRomData.get(), mCurRomSize); + inFile.close(); + BitConverter::RomToBigEndian(mRomData.get(), mCurRomSize); + + if (!ValidateRom()) { + return false; + } + + return true; +} + +bool Extractor::ManuallySearchForRomMatchingType(RomSearchMode searchMode) { + if (!ManuallySearchForRom()) { + return false; + } + + char msgBuf[150]; + snprintf(msgBuf, 150, "The selected rom does not match the expected game type\nExpected type: %s.\n\nDo you want to search again?", + searchMode == RomSearchMode::MQ ? "Master Quest" : "Vanilla"); + + while ((searchMode == RomSearchMode::Vanilla && IsMasterQuest()) || + (searchMode == RomSearchMode::MQ && !IsMasterQuest())) { + int ret = ShowYesNoBox("Wrong Game Type", msgBuf); + switch (ret) { + case IDYES: + if (!ManuallySearchForRom()) { + return false; + } + continue; + case IDNO: + return false; + default: + UNREACHABLE; + break; + } + } + + return true; +} + +bool Extractor::Run(RomSearchMode searchMode) { + std::vector roms; + std::ifstream inFile; + + GetRoms(roms); + FilterRoms(roms, searchMode); + + if (roms.empty()) { + int ret = ShowYesNoBox("No roms found", "No roms found. Look for one?"); + + switch (ret) { + case IDYES: + if (!ManuallySearchForRomMatchingType(searchMode)) { + return false; + } + break; + case IDNO: + ShowErrorBox("No rom selected", "No rom selected. Exiting"); + return false; + default: + UNREACHABLE; + break; + } + } + + for (const auto& rom : roms) { + SetRomInfo(rom); + + if (!ValidateRomSize()) { + ShowSizeErrorBox(); + continue; + } + + inFile.open(rom, std::ios::in | std::ios::binary); + inFile.read((char*)mRomData.get(), mCurRomSize); + inFile.clear(); + inFile.close(); + BitConverter::RomToBigEndian(mRomData.get(), mCurRomSize); + + int option = ShowRomPickBox(GetRomVerCrc()); + + if (option == (int)ButtonId::YES) { + if (!ValidateRom(true)) { + if (rom == roms.back()) { + ShowCrcErrorBox(); + } else { + ShowErrorBox("Rom CRC invalid", + "Rom CRC did not match the list of known good roms. Trying the next one..."); + } + continue; + } + break; + } else if (option == (int)ButtonId::FIND) { + if (!ManuallySearchForRomMatchingType(searchMode)) { + return false; + } + break; + } else if (option == (int)ButtonId::NO) { + if (rom == roms.back()) { + ShowErrorBox("No rom provided", "No rom provided. Exiting"); + return false; + } + continue; + } + break; + } + return true; +} + +bool Extractor::IsMasterQuest() const { + switch (GetRomVerCrc()) { + case OOT_PAL_MQ: + case OOT_PAL_GC_MQ_DBG: + return true; + case OOT_PAL_10: + case OOT_PAL_11: + case OOT_PAL_GC: + case OOT_PAL_GC_DBG1: + return false; + default: + UNREACHABLE; + } +} + +const char* Extractor::GetZapdVerStr() const { + switch (GetRomVerCrc()) { + case OOT_PAL_GC: + return "GC_NMQ_PAL_F"; + case OOT_PAL_MQ: + return "GC_MQ_PAL_F"; + case OOT_PAL_GC_DBG1: + return "GC_NMQ_D"; + case OOT_PAL_GC_MQ_DBG: + return "GC_MQ_D"; + case OOT_PAL_10: + return "N64_PAL_10"; + case OOT_PAL_11: + return "N64_PAL_11"; + default: + // We should never be in a state where this path happens. + UNREACHABLE; + break; + } +} + +std::string Extractor::Mkdtemp() { + std::string temp_dir = std::filesystem::temp_directory_path().string(); + + // create 6 random alphanumeric characters + static const char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dist(0, sizeof(charset) - 1); + + char randchr[7]; + for (int i = 0; i < 6; i++) { + randchr[i] = charset[dist(gen)]; + } + randchr[6] = '\0'; + + std::string tmppath = temp_dir + "/extractor-" + randchr; + std::filesystem::create_directory(tmppath); + return tmppath; +} + +extern "C" int zapd_main(int argc, char** argv); + +bool Extractor::CallZapd(std::string installPath, std::string exportdir) { + constexpr int argc = 16; + char xmlPath[1024]; + char confPath[1024]; + std::array argv; + const char* version = GetZapdVerStr(); + const char* otrFile = IsMasterQuest() ? "oot-mq.otr" : "oot.otr"; + + std::string romPath = std::filesystem::absolute(mCurrentRomPath).string(); + installPath = std::filesystem::absolute(installPath).string(); + exportdir = std::filesystem::absolute(exportdir).string(); + // Work this out in the temporary folder + std::string tempdir = Mkdtemp(); + std::string curdir = std::filesystem::current_path().string(); +#ifdef _WIN32 + std::filesystem::copy(installPath + "/assets", tempdir + "/assets", + std::filesystem::copy_options::recursive | std::filesystem::copy_options::update_existing); +#else + std::filesystem::create_symlink(installPath + "/assets", tempdir + "/assets"); +#endif + + std::filesystem::current_path(tempdir); + + snprintf(xmlPath, 1024, "assets/extractor/xmls/%s", version); + snprintf(confPath, 1024, "assets/extractor/Config_%s.xml", version); + + argv[0] = "ZAPD"; + argv[1] = "ed"; + argv[2] = "-i"; + argv[3] = xmlPath; + argv[4] = "-b"; + argv[5] = romPath.c_str(); + argv[6] = "-fl"; + argv[7] = "assets/extractor/filelists"; + argv[8] = "-gsf"; + argv[9] = "1"; + argv[10] = "-rconf"; + argv[11] = confPath; + argv[12] = "-se"; + argv[13] = "OTR"; + argv[14] = "--otrfile"; + argv[15] = otrFile; + +#ifdef _WIN32 + // Grab a handle to the command window. + HWND cmdWindow = GetConsoleWindow(); + + // Normally the command window is hidden. We want the window to be shown here so the user can see the progess of the extraction. + ShowWindow(cmdWindow, SW_SHOW); + SetWindowPos(cmdWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); +#endif + + zapd_main(argc, (char**)argv.data()); + +#ifdef _WIN32 + // Hide the command window again. + ShowWindow(cmdWindow, SW_HIDE); +#endif + + std::filesystem::copy(otrFile, exportdir + "/" + otrFile, std::filesystem::copy_options::overwrite_existing); + + // Go back to where this game was executed from + std::filesystem::current_path(curdir); + std::filesystem::remove_all(tempdir); + + return 0; +} + diff --git a/mm/2s2h/Extractor/Extract.h b/mm/2s2h/Extractor/Extract.h new file mode 100644 index 000000000..6c9b4a078 --- /dev/null +++ b/mm/2s2h/Extractor/Extract.h @@ -0,0 +1,64 @@ +#ifndef EXTRACT_H +#define EXTRACT_H + +#include +#include +#include +#include + +// Values come from windows.h +#ifndef IDYES +#define IDYES 6 +#endif +#ifndef IDNO +#define IDNO 7 +#endif + +static constexpr size_t MB_BASE = 1024 * 1024; +static constexpr size_t MB32 = 32 * MB_BASE; +static constexpr size_t MB54 = 54 * MB_BASE; +static constexpr size_t MB64 = 64 * MB_BASE; + +enum class RomSearchMode { + Both = 0, + Vanilla = 1, + MQ = 2, +}; + +class Extractor { + std::unique_ptr mRomData = std::make_unique(MB64); + std::string mCurrentRomPath; + size_t mCurRomSize = 0; + + bool GetRomPathFromBox(); + + uint32_t GetRomVerCrc() const; + size_t GetCurRomSize() const; + bool ValidateAndFixRom(); + bool ValidateRomSize() const; + + bool ValidateRom(bool skipCrcBox = false); + const char* GetZapdVerStr() const; + + void SetRomInfo(const std::string& path); + + void FilterRoms(std::vector& roms, RomSearchMode searchMode); + void GetRoms(std::vector& roms); + void ShowSizeErrorBox() const; + void ShowCrcErrorBox() const; + int ShowRomPickBox(uint32_t verCrc) const; + bool ManuallySearchForRom(); + bool ManuallySearchForRomMatchingType(RomSearchMode searchMode); + + public: + //TODO create some kind of abstraction for message boxes. + static int ShowYesNoBox(const char* title, const char* text); + static void ShowErrorBox(const char* title, const char* text); + bool IsMasterQuest() const; + + bool Run(RomSearchMode searchMode = RomSearchMode::Both); + bool CallZapd(std::string installPath, std::string exportdir); + const char* GetZapdStr(); + std::string Mkdtemp(); +}; +#endif diff --git a/mm/2s2h/Extractor/FastCrc32C.c b/mm/2s2h/Extractor/FastCrc32C.c new file mode 100644 index 000000000..d88b04beb --- /dev/null +++ b/mm/2s2h/Extractor/FastCrc32C.c @@ -0,0 +1,144 @@ +#include +#include + +// Force the compiler to assume we have support for the CRC32 intrinsic. We will check for our selves later. +// Clang will define both __llvm__ and __GNUC__ but GCC will only define __GNUC__. So we need to check for __llvm__ first. +#if ((defined(__llvm__) && (defined(__x86_64__) || defined(__i386__)))) +#pragma clang attribute push(__attribute__((target("crc32"))), apply_to = function) +#elif ((defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)))) +// GCC Only lets you enable all of sse4.2 so we will for just this file and reset it at the end. +#pragma GCC push_options +#pragma GCC target("sse4.2") +#endif + +// Include headers for the CRC32 intrinsic and cpuid instruction on windows. No need to do any other checks because it assumes the target will support CRC32 +#ifdef _WIN32 +#include +#include +// Same as above but these platforms use slightly different headers +#elif ((defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)))) +#include +#include +#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) +// Nothing cause its a compiler builtin +#else +#define NO_CRC_INTRIN +#endif + +#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32) +#define INTRIN_CRC32_64(crc, value) __asm__("crc32cx %w[c], %w[c], %x[v]" : [c] "+r"(crc) : [v] "r"(value)) +#define INTRIN_CRC32_32(crc, value) __asm__("crc32cw %w[c], %w[c], %w[v]" : [c] "+r"(crc) : [v] "r"(value)) +#define INTRIN_CRC32_16(crc, value) __asm__("crc32ch %w[c], %w[c], %w[v]" : [c] "+r"(crc) : [v] "r"(value)) +#define INTRIN_CRC32_8(crc, value) __asm__("crc32cb %w[c], %w[c], %w[v]" : [c] "+r"(crc) : [v] "r"(value)) +#elif defined(__GNUC__) || defined(_MSC_VER) +#define INTRIN_CRC32_64(crc, data) crc = _mm_crc32_u64(crc, data) +#define INTRIN_CRC32_32(crc, data) crc = _mm_crc32_u32(crc, data) +#define INTRIN_CRC32_16(crc, data) crc = _mm_crc32_u16(crc, data) +#define INTRIN_CRC32_8(crc, data) crc = _mm_crc32_u8(crc, data) +#endif + +static const uint32_t crc32Table[256] = { + 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, + 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L, 0x105EC76FL, 0xE235446CL, + 0xF165B798L, 0x030E349BL, 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, 0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, + 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL, 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, + 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L, 0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL, + 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, 0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, + 0x1642AE59L, 0xE4292D5AL, 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, + 0x6EF07595L, 0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L, + 0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L, 0x5125DAD3L, + 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, 0xDBFC821CL, 0x2997011FL, + 0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L, 0x61C69362L, 0x93AD1061L, 0x80FDE395L, + 0x72966096L, 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, 0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, + 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L, 0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, 0xB602C312L, + 0x44694011L, 0x5739B3E5L, 0xA55230E6L, 0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL, 0xCEB018DEL, + 0xDDE0EB2AL, 0x2F8B6829L, 0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, + 0x563C5F93L, 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, + 0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL, 0x1871A4D8L, + 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L, 0xA24BB5A6L, 0x502036A5L, + 0x4370C551L, 0xB11B4652L, 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, 0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, + 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L, 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, + 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, 0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, + 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL, 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, + 0xE52CC12CL, 0x1747422FL, 0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, + 0x9D9E1AE0L, 0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L, + 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, 0xE330A81AL, + 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L, 0x69E9F0D5L, 0x9B8273D6L, + 0x88D28022L, 0x7AB90321L, 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL, 0xF36E6F75L, 0x0105EC76L, 0x12551F82L, + 0xE03E9C81L, 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, 0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, + 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L +}; +// On platforms that we know will never support a crc32 instruction (such as the WiiU) we will skip compiling this function in. +#ifndef NO_CRC_INTRIN + +static uint32_t CRC32IntrinImpl(unsigned char* data, size_t dataSize) { + uint32_t ret = 0xFFFFFFFF; + int64_t sizeSigned = dataSize; +// Only 64bit platforms support doing a CRC32 operation on a 64bit value +#if defined(_M_X64) || defined(__x86_64__) || defined(__aarch64__) + while ((sizeSigned -= sizeof(uint64_t)) >= 0) { + INTRIN_CRC32_64(ret, *(uint64_t*)data); + data += sizeof(uint64_t); + } + + if (sizeSigned & sizeof(uint32_t)) { + INTRIN_CRC32_32(ret, *(uint32_t*)data); + + data += sizeof(uint32_t); + } +// On 32 bit we can only do 32bit operations +#elif defined(_M_IX86) || defined(__i386__) + while ((sizeSigned -= sizeof(uint32_t)) >= 0) { + INTRIN_CRC32_32(ret, *(uint32_t*)data); + data += sizeof(uint32_t); + } +#endif + if (sizeSigned & sizeof(uint16_t)) { + INTRIN_CRC32_16(ret, *(uint16_t*)data); + data += sizeof(uint16_t); + } + + if (sizeSigned & sizeof(uint8_t)) { + INTRIN_CRC32_8(ret, *data); + } + + return ~ret; +} +#endif + +static uint32_t CRC32TableImpl(unsigned char* data, size_t dataSize) { + const uint8_t* p = data; + uint32_t crc = 0xFFFFFFFF; + + while (dataSize--) + crc = crc32Table[(crc ^ *p++) & 0xff] ^ (crc >> 8); + + return ~crc; +} + +uint32_t CRC32C(unsigned char* data, size_t dataSize) { +#ifndef NO_CRC_INTRIN + // Test to make sure the CPU supports the CRC32 intrinsic + unsigned int cpuidData[4]; +#ifdef _WIN32 + __cpuid(cpuidData, 1); +#elif __APPLE__ || (defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)) +// Every Mac that supports SoH should support this instruction. Also check for ARM64 at the same time + return CRC32IntrinImpl(data, dataSize); +#else + __get_cpuid(1, &cpuidData[0], &cpuidData[1], &cpuidData[2], &cpuidData[3]); +#endif + + if (cpuidData[2] & (1 << 20)) { // bit_SSE4_2 + return CRC32IntrinImpl(data, dataSize); + } +#endif // NO_CRC_INTRIN + return CRC32TableImpl(data, dataSize); +} + +#if ((defined(__llvm__) && (defined(__x86_64__) || defined(__i386__)))) +#pragma clang attribute pop +#elif ((defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)))) +#pragma GCC pop_options +#else +#endif diff --git a/mm/2s2h/Extractor/portable-file-dialogs.h b/mm/2s2h/Extractor/portable-file-dialogs.h new file mode 100644 index 000000000..1fc79a291 --- /dev/null +++ b/mm/2s2h/Extractor/portable-file-dialogs.h @@ -0,0 +1,1887 @@ +// +// Portable File Dialogs +// +// Copyright © 2018–2022 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +#if _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN 1 +#endif +#include +#include +#include +#include // IFileDialog +#include +#include +#include // std::async +#include // GetUserProfileDirectory() + +#elif __EMSCRIPTEN__ +#include + +#else +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 2 // for popen() +#endif +#ifdef __APPLE__ +# ifndef _DARWIN_C_SOURCE +# define _DARWIN_C_SOURCE +# endif +#endif +#include // popen() +#include // std::getenv() +#include // fcntl() +#include // read(), pipe(), dup2(), getuid() +#include // ::kill, std::signal +#include // stat() +#include // waitpid() +#include // getpwnam() +#endif + +#include // std::string +#include // std::shared_ptr +#include // std::ostream +#include // std::map +#include // std::set +#include // std::regex +#include // std::mutex, std::this_thread +#include // std::chrono + +// Versions of mingw64 g++ up to 9.3.0 do not have a complete IFileDialog +#ifndef PFD_HAS_IFILEDIALOG +# define PFD_HAS_IFILEDIALOG 1 +# if (defined __MINGW64__ || defined __MINGW32__) && defined __GXX_ABI_VERSION +# if __GXX_ABI_VERSION <= 1013 +# undef PFD_HAS_IFILEDIALOG +# define PFD_HAS_IFILEDIALOG 0 +# endif +# endif +#endif + +namespace pfd +{ + +enum class button +{ + cancel = -1, + ok, + yes, + no, + abort, + retry, + ignore, +}; + +enum class choice +{ + ok = 0, + ok_cancel, + yes_no, + yes_no_cancel, + retry_cancel, + abort_retry_ignore, +}; + +enum class icon +{ + info = 0, + warning, + error, + question, +}; + +// Additional option flags for various dialog constructors +enum class opt : uint8_t +{ + none = 0, + // For file open, allow multiselect. + multiselect = 0x1, + // For file save, force overwrite and disable the confirmation dialog. + force_overwrite = 0x2, + // For folder select, force path to be the provided argument instead + // of the last opened directory, which is the Microsoft-recommended, + // user-friendly behaviour. + force_path = 0x4, +}; + +inline opt operator |(opt a, opt b) { return opt(uint8_t(a) | uint8_t(b)); } +inline bool operator &(opt a, opt b) { return bool(uint8_t(a) & uint8_t(b)); } + +// The settings class, only exposing to the user a way to set verbose mode +// and to force a rescan of installed desktop helpers (zenity, kdialog…). +class settings +{ +public: + static bool available(); + + static void verbose(bool value); + static void rescan(); + +protected: + explicit settings(bool resync = false); + + bool check_program(std::string const &program); + + inline bool is_osascript() const; + inline bool is_zenity() const; + inline bool is_kdialog() const; + + enum class flag + { + is_scanned = 0, + is_verbose, + + has_zenity, + has_matedialog, + has_qarma, + has_kdialog, + is_vista, + + max_flag, + }; + + // Static array of flags for internal state + bool const &flags(flag in_flag) const; + + // Non-const getter for the static array of flags + bool &flags(flag in_flag); +}; + +// Internal classes, not to be used by client applications +namespace internal +{ + +// Process wait timeout, in milliseconds +static int const default_wait_timeout = 20; + +class executor +{ + friend class dialog; + +public: + // High level function to get the result of a command + std::string result(int *exit_code = nullptr); + + // High level function to abort + bool kill(); + +#if _WIN32 + void start_func(std::function const &fun); + static BOOL CALLBACK enum_windows_callback(HWND hwnd, LPARAM lParam); +#elif __EMSCRIPTEN__ + void start(int exit_code); +#else + void start_process(std::vector const &command); +#endif + + ~executor(); + +protected: + bool ready(int timeout = default_wait_timeout); + void stop(); + +private: + bool m_running = false; + std::string m_stdout; + int m_exit_code = -1; +#if _WIN32 + std::future m_future; + std::set m_windows; + std::condition_variable m_cond; + std::mutex m_mutex; + DWORD m_tid; +#elif __EMSCRIPTEN__ || __NX__ + // FIXME: do something +#else + pid_t m_pid = 0; + int m_fd = -1; +#endif +}; + +class platform +{ +protected: +#if _WIN32 + // Helper class around LoadLibraryA() and GetProcAddress() with some safety + class dll + { + public: + dll(std::string const &name); + ~dll(); + + template class proc + { + public: + proc(dll const &lib, std::string const &sym) + : m_proc(reinterpret_cast((void *)::GetProcAddress(lib.handle, sym.c_str()))) + {} + + operator bool() const { return m_proc != nullptr; } + operator T *() const { return m_proc; } + + private: + T *m_proc; + }; + + private: + HMODULE handle; + }; + + // Helper class around CoInitialize() and CoUnInitialize() + class ole32_dll : public dll + { + public: + ole32_dll(); + ~ole32_dll(); + bool is_initialized(); + + private: + HRESULT m_state; + }; + + // Helper class around CreateActCtx() and ActivateActCtx() + class new_style_context + { + public: + new_style_context(); + ~new_style_context(); + + private: + HANDLE create(); + ULONG_PTR m_cookie = 0; + }; +#endif +}; + +class dialog : protected settings, protected platform +{ +public: + bool ready(int timeout = default_wait_timeout) const; + bool kill() const; + +protected: + explicit dialog(); + + std::vector desktop_helper() const; + static std::string buttons_to_name(choice _choice); + static std::string get_icon_name(icon _icon); + + std::string powershell_quote(std::string const &str) const; + std::string osascript_quote(std::string const &str) const; + std::string shell_quote(std::string const &str) const; + + // Keep handle to executing command + std::shared_ptr m_async; +}; + +class file_dialog : public dialog +{ +protected: + enum type + { + open, + save, + folder, + }; + + file_dialog(type in_type, + std::string const &title, + std::string const &default_path = "", + std::vector const &filters = {}, + opt options = opt::none); + +protected: + std::string string_result(); + std::vector vector_result(); + +#if _WIN32 + static int CALLBACK bffcallback(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData); +#if PFD_HAS_IFILEDIALOG + std::string select_folder_vista(IFileDialog *ifd, bool force_path); +#endif + + std::wstring m_wtitle; + std::wstring m_wdefault_path; + + std::vector m_vector_result; +#endif +}; + +} // namespace internal + +// +// The path class provides some platform-specific path constants +// + +class path : protected internal::platform +{ +public: + static std::string home(); + static std::string separator(); +}; + +// +// The notify widget +// + +class notify : public internal::dialog +{ +public: + notify(std::string const &title, + std::string const &message, + icon _icon = icon::info); +}; + +// +// The message widget +// + +class message : public internal::dialog +{ +public: + message(std::string const &title, + std::string const &text, + choice _choice = choice::ok_cancel, + icon _icon = icon::info); + + button result(); + +private: + // Some extra logic to map the exit code to button number + std::map m_mappings; +}; + +// +// The open_file, save_file, and open_folder widgets +// + +class open_file : public internal::file_dialog +{ +public: + open_file(std::string const &title, + std::string const &default_path = "", + std::vector const &filters = { "All Files", "*" }, + opt options = opt::none); + +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(deprecated) + // Backwards compatibility + [[deprecated("Use pfd::opt::multiselect instead of allow_multiselect")]] +#endif +#endif + open_file(std::string const &title, + std::string const &default_path, + std::vector const &filters, + bool allow_multiselect); + + std::vector result(); +}; + +class save_file : public internal::file_dialog +{ +public: + save_file(std::string const &title, + std::string const &default_path = "", + std::vector const &filters = { "All Files", "*" }, + opt options = opt::none); + +#if defined(__has_cpp_attribute) +#if __has_cpp_attribute(deprecated) + // Backwards compatibility + [[deprecated("Use pfd::opt::force_overwrite instead of confirm_overwrite")]] +#endif +#endif + save_file(std::string const &title, + std::string const &default_path, + std::vector const &filters, + bool confirm_overwrite); + + std::string result(); +}; + +class select_folder : public internal::file_dialog +{ +public: + select_folder(std::string const &title, + std::string const &default_path = "", + opt options = opt::none); + + std::string result(); +}; + +// +// Below this are all the method implementations. You may choose to define the +// macro PFD_SKIP_IMPLEMENTATION everywhere before including this header except +// in one place. This may reduce compilation times. +// + +#if !defined PFD_SKIP_IMPLEMENTATION + +// internal free functions implementations + +namespace internal +{ + +#if _WIN32 +static inline std::wstring str2wstr(std::string const &str) +{ + int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), nullptr, 0); + std::wstring ret(len, '\0'); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), (LPWSTR)ret.data(), (int)ret.size()); + return ret; +} + +static inline std::string wstr2str(std::wstring const &str) +{ + int len = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)str.size(), nullptr, 0, nullptr, nullptr); + std::string ret(len, '\0'); + WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)str.size(), (LPSTR)ret.data(), (int)ret.size(), nullptr, nullptr); + return ret; +} + +static inline bool is_vista() +{ + OSVERSIONINFOEXW osvi; + memset(&osvi, 0, sizeof(osvi)); + DWORDLONG const mask = VerSetConditionMask( + VerSetConditionMask( + VerSetConditionMask( + 0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL), + VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + osvi.dwOSVersionInfoSize = sizeof(osvi); + osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_VISTA); + osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_VISTA); + osvi.wServicePackMajor = 0; + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, mask) != FALSE; +} +#endif + +// This is necessary until C++20 which will have std::string::ends_with() etc. + +static inline bool ends_with(std::string const &str, std::string const &suffix) +{ + return suffix.size() <= str.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +static inline bool starts_with(std::string const &str, std::string const &prefix) +{ + return prefix.size() <= str.size() && + str.compare(0, prefix.size(), prefix) == 0; +} + +// This is necessary until C++17 which will have std::filesystem::is_directory + +static inline bool is_directory(std::string const &path) +{ +#if _WIN32 + auto attr = GetFileAttributesA(path.c_str()); + return attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY); +#elif __EMSCRIPTEN__ + // TODO + return false; +#else + struct stat s; + return stat(path.c_str(), &s) == 0 && S_ISDIR(s.st_mode); +#endif +} + +// This is necessary because getenv is not thread-safe + +static inline std::string getenv(std::string const &str) +{ +#if _MSC_VER + char *buf = nullptr; + size_t size = 0; + if (_dupenv_s(&buf, &size, str.c_str()) == 0 && buf) + { + std::string ret(buf); + free(buf); + return ret; + } + return ""; +#else + auto buf = std::getenv(str.c_str()); + return buf ? buf : ""; +#endif +} + +} // namespace internal + +// settings implementation + +inline settings::settings(bool resync) +{ + flags(flag::is_scanned) &= !resync; + + if (flags(flag::is_scanned)) + return; + + auto pfd_verbose = internal::getenv("PFD_VERBOSE"); + auto match_no = std::regex("(|0|no|false)", std::regex_constants::icase); + if (!std::regex_match(pfd_verbose, match_no)) + flags(flag::is_verbose) = true; + +#if _WIN32 + flags(flag::is_vista) = internal::is_vista(); +#elif !__APPLE__ + flags(flag::has_zenity) = check_program("zenity"); + flags(flag::has_matedialog) = check_program("matedialog"); + flags(flag::has_qarma) = check_program("qarma"); + flags(flag::has_kdialog) = check_program("kdialog"); + + // If multiple helpers are available, try to default to the best one + if (flags(flag::has_zenity) && flags(flag::has_kdialog)) + { + auto desktop_name = internal::getenv("XDG_SESSION_DESKTOP"); + if (desktop_name == std::string("gnome")) + flags(flag::has_kdialog) = false; + else if (desktop_name == std::string("KDE")) + flags(flag::has_zenity) = false; + } +#endif + + flags(flag::is_scanned) = true; +} + +inline bool settings::available() +{ +#if _WIN32 + return true; +#elif __APPLE__ + return true; +#elif __EMSCRIPTEN__ + // FIXME: Return true after implementation is complete. + return false; +#else + settings tmp; + return tmp.flags(flag::has_zenity) || + tmp.flags(flag::has_matedialog) || + tmp.flags(flag::has_qarma) || + tmp.flags(flag::has_kdialog); +#endif +} + +inline void settings::verbose(bool value) +{ + settings().flags(flag::is_verbose) = value; +} + +inline void settings::rescan() +{ + settings(/* resync = */ true); +} + +// Check whether a program is present using “which”. +inline bool settings::check_program(std::string const &program) +{ +#if _WIN32 + (void)program; + return false; +#elif __EMSCRIPTEN__ + (void)program; + return false; +#else + int exit_code = -1; + internal::executor async; + async.start_process({"/bin/sh", "-c", "which " + program}); + async.result(&exit_code); + return exit_code == 0; +#endif +} + +inline bool settings::is_osascript() const +{ +#if __APPLE__ + return true; +#else + return false; +#endif +} + +inline bool settings::is_zenity() const +{ + return flags(flag::has_zenity) || + flags(flag::has_matedialog) || + flags(flag::has_qarma); +} + +inline bool settings::is_kdialog() const +{ + return flags(flag::has_kdialog); +} + +inline bool const &settings::flags(flag in_flag) const +{ + static bool flags[size_t(flag::max_flag)]; + return flags[size_t(in_flag)]; +} + +inline bool &settings::flags(flag in_flag) +{ + return const_cast(static_cast(this)->flags(in_flag)); +} + +// path implementation +inline std::string path::home() +{ +#if _WIN32 + // First try the USERPROFILE environment variable + auto user_profile = internal::getenv("USERPROFILE"); + if (user_profile.size() > 0) + return user_profile; + // Otherwise, try GetUserProfileDirectory() + HANDLE token = nullptr; + DWORD len = MAX_PATH; + char buf[MAX_PATH] = { '\0' }; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) + { + dll userenv("userenv.dll"); + dll::proc get_user_profile_directory(userenv, "GetUserProfileDirectoryA"); + get_user_profile_directory(token, buf, &len); + CloseHandle(token); + if (*buf) + return buf; + } +#elif __EMSCRIPTEN__ + return "/"; +#else + // First try the HOME environment variable + auto home = internal::getenv("HOME"); + if (home.size() > 0) + return home; + // Otherwise, try getpwuid_r() + size_t len = 4096; +#if defined(_SC_GETPW_R_SIZE_MAX) + auto size_max = sysconf(_SC_GETPW_R_SIZE_MAX); + if (size_max != -1) + len = size_t(size_max); +#endif + std::vector buf(len); + struct passwd pwd, *result; + if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) + return result->pw_dir; +#endif + return "/"; +} + +inline std::string path::separator() +{ +#if _WIN32 + return "\\"; +#else + return "/"; +#endif +} + +// executor implementation + +inline std::string internal::executor::result(int *exit_code /* = nullptr */) +{ + stop(); + if (exit_code) + *exit_code = m_exit_code; + return m_stdout; +} + +inline bool internal::executor::kill() +{ +#if _WIN32 + if (m_future.valid()) + { + // Close all windows that weren’t open when we started the future + auto previous_windows = m_windows; + EnumWindows(&enum_windows_callback, (LPARAM)this); + for (auto hwnd : m_windows) + if (previous_windows.find(hwnd) == previous_windows.end()) + { + SendMessage(hwnd, WM_CLOSE, 0, 0); + // Also send IDNO in case of a Yes/No or Abort/Retry/Ignore messagebox + SendMessage(hwnd, WM_COMMAND, IDNO, 0); + } + } +#elif __EMSCRIPTEN__ || __NX__ + // FIXME: do something + return false; // cannot kill +#else + ::kill(m_pid, SIGKILL); +#endif + stop(); + return true; +} + +#if _WIN32 +inline BOOL CALLBACK internal::executor::enum_windows_callback(HWND hwnd, LPARAM lParam) +{ + auto that = (executor *)lParam; + + DWORD pid; + auto tid = GetWindowThreadProcessId(hwnd, &pid); + if (tid == that->m_tid) + that->m_windows.insert(hwnd); + return TRUE; +} +#endif + +#if _WIN32 +inline void internal::executor::start_func(std::function const &fun) +{ + stop(); + + auto trampoline = [fun, this]() + { + // Save our thread id so that the caller can cancel us + m_tid = GetCurrentThreadId(); + EnumWindows(&enum_windows_callback, (LPARAM)this); + m_cond.notify_all(); + return fun(&m_exit_code); + }; + + std::unique_lock lock(m_mutex); + m_future = std::async(std::launch::async, trampoline); + m_cond.wait(lock); + m_running = true; +} + +#elif __EMSCRIPTEN__ +inline void internal::executor::start(int exit_code) +{ + m_exit_code = exit_code; +} + +#else +inline void internal::executor::start_process(std::vector const &command) +{ + stop(); + m_stdout.clear(); + m_exit_code = -1; + + int in[2], out[2]; + if (pipe(in) != 0 || pipe(out) != 0) + return; + + m_pid = fork(); + if (m_pid < 0) + return; + + close(in[m_pid ? 0 : 1]); + close(out[m_pid ? 1 : 0]); + + if (m_pid == 0) + { + dup2(in[0], STDIN_FILENO); + dup2(out[1], STDOUT_FILENO); + + // Ignore stderr so that it doesn’t pollute the console (e.g. GTK+ errors from zenity) + int fd = open("/dev/null", O_WRONLY); + dup2(fd, STDERR_FILENO); + close(fd); + + std::vector args; + std::transform(command.cbegin(), command.cend(), std::back_inserter(args), + [](std::string const &s) { return const_cast(s.c_str()); }); + args.push_back(nullptr); // null-terminate argv[] + + execvp(args[0], args.data()); + exit(1); + } + + close(in[1]); + m_fd = out[0]; + auto flags = fcntl(m_fd, F_GETFL); + fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); + + m_running = true; +} +#endif + +inline internal::executor::~executor() +{ + stop(); +} + +inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) +{ + if (!m_running) + return true; + +#if _WIN32 + if (m_future.valid()) + { + auto status = m_future.wait_for(std::chrono::milliseconds(timeout)); + if (status != std::future_status::ready) + { + // On Windows, we need to run the message pump. If the async + // thread uses a Windows API dialog, it may be attached to the + // main thread and waiting for messages that only we can dispatch. + MSG msg; + while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return false; + } + + m_stdout = m_future.get(); + } +#elif __EMSCRIPTEN__ || __NX__ + // FIXME: do something + (void)timeout; +#else + char buf[BUFSIZ]; + ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore + if (received > 0) + { + m_stdout += std::string(buf, received); + return false; + } + + // Reap child process if it is dead. It is possible that the system has already reaped it + // (this happens when the calling application handles or ignores SIG_CHLD) and results in + // waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for + // a little while. + int status; + pid_t child = waitpid(m_pid, &status, WNOHANG); + if (child != m_pid && (child >= 0 || errno != ECHILD)) + { + // FIXME: this happens almost always at first iteration + std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); + return false; + } + + close(m_fd); + m_exit_code = WEXITSTATUS(status); +#endif + + m_running = false; + return true; +} + +inline void internal::executor::stop() +{ + // Loop until the user closes the dialog + while (!ready()) + ; +} + +// dll implementation + +#if _WIN32 +inline internal::platform::dll::dll(std::string const &name) + : handle(::LoadLibraryA(name.c_str())) +{} + +inline internal::platform::dll::~dll() +{ + if (handle) + ::FreeLibrary(handle); +} +#endif // _WIN32 + +// ole32_dll implementation + +#if _WIN32 +inline internal::platform::ole32_dll::ole32_dll() + : dll("ole32.dll") +{ + // Use COINIT_MULTITHREADED because COINIT_APARTMENTTHREADED causes crashes. + // See https://github.com/samhocevar/portable-file-dialogs/issues/51 + auto coinit = proc(*this, "CoInitializeEx"); + m_state = coinit(nullptr, COINIT_MULTITHREADED); +} + +inline internal::platform::ole32_dll::~ole32_dll() +{ + if (is_initialized()) + proc(*this, "CoUninitialize")(); +} + +inline bool internal::platform::ole32_dll::is_initialized() +{ + return m_state == S_OK || m_state == S_FALSE; +} +#endif + +// new_style_context implementation + +#if _WIN32 +inline internal::platform::new_style_context::new_style_context() +{ + // Only create one activation context for the whole app lifetime. + static HANDLE hctx = create(); + + if (hctx != INVALID_HANDLE_VALUE) + ActivateActCtx(hctx, &m_cookie); +} + +inline internal::platform::new_style_context::~new_style_context() +{ + DeactivateActCtx(0, m_cookie); +} + +inline HANDLE internal::platform::new_style_context::create() +{ + // This “hack” seems to be necessary for this code to work on windows XP. + // Without it, dialogs do not show and close immediately. GetError() + // returns 0 so I don’t know what causes this. I was not able to reproduce + // this behavior on Windows 7 and 10 but just in case, let it be here for + // those versions too. + // This hack is not required if other dialogs are used (they load comdlg32 + // automatically), only if message boxes are used. + dll comdlg32("comdlg32.dll"); + + // Using approach as shown here: https://stackoverflow.com/a/10444161 + UINT len = ::GetSystemDirectoryA(nullptr, 0); + std::string sys_dir(len, '\0'); + ::GetSystemDirectoryA(&sys_dir[0], len); + + ACTCTXA act_ctx = + { + // Do not set flag ACTCTX_FLAG_SET_PROCESS_DEFAULT, since it causes a + // crash with error “default context is already set”. + sizeof(act_ctx), + ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID, + "shell32.dll", 0, 0, sys_dir.c_str(), (LPCSTR)124, nullptr, 0, + }; + + return ::CreateActCtxA(&act_ctx); +} +#endif // _WIN32 + +// dialog implementation + +inline bool internal::dialog::ready(int timeout /* = default_wait_timeout */) const +{ + return m_async->ready(timeout); +} + +inline bool internal::dialog::kill() const +{ + return m_async->kill(); +} + +inline internal::dialog::dialog() + : m_async(std::make_shared()) +{ +} + +inline std::vector internal::dialog::desktop_helper() const +{ +#if __APPLE__ + return { "osascript" }; +#else + return { flags(flag::has_zenity) ? "zenity" + : flags(flag::has_matedialog) ? "matedialog" + : flags(flag::has_qarma) ? "qarma" + : flags(flag::has_kdialog) ? "kdialog" + : "echo" }; +#endif +} + +inline std::string internal::dialog::buttons_to_name(choice _choice) +{ + switch (_choice) + { + case choice::ok_cancel: return "okcancel"; + case choice::yes_no: return "yesno"; + case choice::yes_no_cancel: return "yesnocancel"; + case choice::retry_cancel: return "retrycancel"; + case choice::abort_retry_ignore: return "abortretryignore"; + /* case choice::ok: */ default: return "ok"; + } +} + +inline std::string internal::dialog::get_icon_name(icon _icon) +{ + switch (_icon) + { + case icon::warning: return "warning"; + case icon::error: return "error"; + case icon::question: return "question"; + // Zenity wants "information" but WinForms wants "info" + /* case icon::info: */ default: +#if _WIN32 + return "info"; +#else + return "information"; +#endif + } +} + +// This is only used for debugging purposes +inline std::ostream& operator <<(std::ostream &s, std::vector const &v) +{ + int not_first = 0; + for (auto &e : v) + s << (not_first++ ? " " : "") << e; + return s; +} + +// Properly quote a string for Powershell: replace ' or " with '' or "" +// FIXME: we should probably get rid of newlines! +// FIXME: the \" sequence seems unsafe, too! +// XXX: this is no longer used but I would like to keep it around just in case +inline std::string internal::dialog::powershell_quote(std::string const &str) const +{ + return "'" + std::regex_replace(str, std::regex("['\"]"), "$&$&") + "'"; +} + +// Properly quote a string for osascript: replace \ or " with \\ or \" +// XXX: this also used to replace ' with \' when popen was used, but it would be +// smarter to do shell_quote(osascript_quote(...)) if this is needed again. +inline std::string internal::dialog::osascript_quote(std::string const &str) const +{ + return "\"" + std::regex_replace(str, std::regex("[\\\\\"]"), "\\$&") + "\""; +} + +// Properly quote a string for the shell: just replace ' with '\'' +// XXX: this is no longer used but I would like to keep it around just in case +inline std::string internal::dialog::shell_quote(std::string const &str) const +{ + return "'" + std::regex_replace(str, std::regex("'"), "'\\''") + "'"; +} + +// file_dialog implementation + +inline internal::file_dialog::file_dialog(type in_type, + std::string const &title, + std::string const &default_path /* = "" */, + std::vector const &filters /* = {} */, + opt options /* = opt::none */) +{ +#if _WIN32 + std::string filter_list; + std::regex whitespace(" *"); + for (size_t i = 0; i + 1 < filters.size(); i += 2) + { + filter_list += filters[i] + '\0'; + filter_list += std::regex_replace(filters[i + 1], whitespace, ";") + '\0'; + } + filter_list += '\0'; + + m_async->start_func([this, in_type, title, default_path, filter_list, + options](int *exit_code) -> std::string + { + (void)exit_code; + m_wtitle = internal::str2wstr(title); + m_wdefault_path = internal::str2wstr(default_path); + auto wfilter_list = internal::str2wstr(filter_list); + + // Initialise COM. This is required for the new folder selection window, + // (see https://github.com/samhocevar/portable-file-dialogs/pull/21) + // and to avoid random crashes with GetOpenFileNameW() (see + // https://github.com/samhocevar/portable-file-dialogs/issues/51) + ole32_dll ole32; + + // Folder selection uses a different method + if (in_type == type::folder) + { +#if PFD_HAS_IFILEDIALOG + if (flags(flag::is_vista)) + { + // On Vista and higher we should be able to use IFileDialog for folder selection + IFileDialog *ifd; + HRESULT hr = dll::proc(ole32, "CoCreateInstance") + (CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ifd)); + + // In case CoCreateInstance fails (which it should not), try legacy approach + if (SUCCEEDED(hr)) + return select_folder_vista(ifd, options & opt::force_path); + } +#endif + + BROWSEINFOW bi; + memset(&bi, 0, sizeof(bi)); + + bi.lpfn = &bffcallback; + bi.lParam = (LPARAM)this; + + if (flags(flag::is_vista)) + { + if (ole32.is_initialized()) + bi.ulFlags |= BIF_NEWDIALOGSTYLE; + bi.ulFlags |= BIF_EDITBOX; + bi.ulFlags |= BIF_STATUSTEXT; + } + + auto *list = SHBrowseForFolderW(&bi); + std::string ret; + if (list) + { + auto buffer = new wchar_t[MAX_PATH]; + SHGetPathFromIDListW(list, buffer); + dll::proc(ole32, "CoTaskMemFree")(list); + ret = internal::wstr2str(buffer); + delete[] buffer; + } + return ret; + } + + OPENFILENAMEW ofn; + memset(&ofn, 0, sizeof(ofn)); + ofn.lStructSize = sizeof(OPENFILENAMEW); + ofn.hwndOwner = GetActiveWindow(); + + ofn.lpstrFilter = wfilter_list.c_str(); + + auto woutput = std::wstring(MAX_PATH * 256, L'\0'); + ofn.lpstrFile = (LPWSTR)woutput.data(); + ofn.nMaxFile = (DWORD)woutput.size(); + if (!m_wdefault_path.empty()) + { + // If a directory was provided, use it as the initial directory. If + // a valid path was provided, use it as the initial file. Otherwise, + // let the Windows API decide. + auto path_attr = GetFileAttributesW(m_wdefault_path.c_str()); + if (path_attr != INVALID_FILE_ATTRIBUTES && (path_attr & FILE_ATTRIBUTE_DIRECTORY)) + ofn.lpstrInitialDir = m_wdefault_path.c_str(); + else if (m_wdefault_path.size() <= woutput.size()) + //second argument is size of buffer, not length of string + StringCchCopyW(ofn.lpstrFile, MAX_PATH*256+1, m_wdefault_path.c_str()); + else + { + ofn.lpstrFileTitle = (LPWSTR)m_wdefault_path.data(); + ofn.nMaxFileTitle = (DWORD)m_wdefault_path.size(); + } + } + ofn.lpstrTitle = m_wtitle.c_str(); + ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER; + + dll comdlg32("comdlg32.dll"); + + // Apply new visual style (required for windows XP) + new_style_context ctx; + + if (in_type == type::save) + { + if (!(options & opt::force_overwrite)) + ofn.Flags |= OFN_OVERWRITEPROMPT; + + dll::proc get_save_file_name(comdlg32, "GetSaveFileNameW"); + if (get_save_file_name(&ofn) == 0) + return ""; + return internal::wstr2str(woutput.c_str()); + } + else + { + if (options & opt::multiselect) + ofn.Flags |= OFN_ALLOWMULTISELECT; + ofn.Flags |= OFN_PATHMUSTEXIST; + + dll::proc get_open_file_name(comdlg32, "GetOpenFileNameW"); + if (get_open_file_name(&ofn) == 0) + return ""; + } + + std::string prefix; + for (wchar_t const *p = woutput.c_str(); *p; ) + { + auto filename = internal::wstr2str(p); + p += wcslen(p); + // In multiselect mode, we advance p one wchar further and + // check for another filename. If there is one and the + // prefix is empty, it means we just read the prefix. + if ((options & opt::multiselect) && *++p && prefix.empty()) + { + prefix = filename + "/"; + continue; + } + + m_vector_result.push_back(prefix + filename); + } + + return ""; + }); +#elif __EMSCRIPTEN__ + // FIXME: do something + (void)in_type; + (void)title; + (void)default_path; + (void)filters; + (void)options; +#else + auto command = desktop_helper(); + + if (is_osascript()) + { + std::string script = "set ret to choose"; + switch (in_type) + { + case type::save: + script += " file name"; + break; + case type::open: default: + script += " file"; + if (options & opt::multiselect) + script += " with multiple selections allowed"; + break; + case type::folder: + script += " folder"; + break; + } + + if (default_path.size()) + { + if (in_type == type::folder || is_directory(default_path)) + script += " default location "; + else + script += " default name "; + script += osascript_quote(default_path); + } + + script += " with prompt " + osascript_quote(title); + + if (in_type == type::open) + { + // Concatenate all user-provided filter patterns + std::string patterns; + for (size_t i = 0; i < filters.size() / 2; ++i) + patterns += " " + filters[2 * i + 1]; + + // Split the pattern list to check whether "*" is in there; if it + // is, we have to disable filters because there is no mechanism in + // OS X for the user to override the filter. + std::regex sep("\\s+"); + std::string filter_list; + bool has_filter = true; + std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1); + std::sregex_token_iterator end; + for ( ; iter != end; ++iter) + { + auto pat = iter->str(); + if (pat == "*" || pat == "*.*") + has_filter = false; + else if (internal::starts_with(pat, "*.")) + filter_list += "," + osascript_quote(pat.substr(2, pat.size() - 2)); + } + + if (has_filter && filter_list.size() > 0) + { + // There is a weird AppleScript bug where file extensions of length != 3 are + // ignored, e.g. type{"txt"} works, but type{"json"} does not. Fortunately if + // the whole list starts with a 3-character extension, everything works again. + // We use "///" for such an extension because we are sure it cannot appear in + // an actual filename. + script += " of type {\"///\"" + filter_list + "}"; + } + } + + if (in_type == type::open && (options & opt::multiselect)) + { + script += "\nset s to \"\""; + script += "\nrepeat with i in ret"; + script += "\n set s to s & (POSIX path of i) & \"\\n\""; + script += "\nend repeat"; + script += "\ncopy s to stdout"; + } + else + { + script += "\nPOSIX path of ret"; + } + + command.push_back("-e"); + command.push_back(script); + } + else if (is_zenity()) + { + command.push_back("--file-selection"); + + // If the default path is a directory, make sure it ends with "/" otherwise zenity will + // open the file dialog in the parent directory. + auto filename_arg = "--filename=" + default_path; + if (in_type != type::folder && !ends_with(default_path, "/") && internal::is_directory(default_path)) + filename_arg += "/"; + command.push_back(filename_arg); + + command.push_back("--title"); + command.push_back(title); + command.push_back("--separator=\n"); + + for (size_t i = 0; i < filters.size() / 2; ++i) + { + command.push_back("--file-filter"); + command.push_back(filters[2 * i] + "|" + filters[2 * i + 1]); + } + + if (in_type == type::save) + command.push_back("--save"); + if (in_type == type::folder) + command.push_back("--directory"); + if (!(options & opt::force_overwrite)) + command.push_back("--confirm-overwrite"); + if (options & opt::multiselect) + command.push_back("--multiple"); + } + else if (is_kdialog()) + { + switch (in_type) + { + case type::save: command.push_back("--getsavefilename"); break; + case type::open: command.push_back("--getopenfilename"); break; + case type::folder: command.push_back("--getexistingdirectory"); break; + } + if (options & opt::multiselect) + { + command.push_back("--multiple"); + command.push_back("--separate-output"); + } + + command.push_back(default_path); + + std::string filter; + for (size_t i = 0; i < filters.size() / 2; ++i) + filter += (i == 0 ? "" : " | ") + filters[2 * i] + "(" + filters[2 * i + 1] + ")"; + command.push_back(filter); + + command.push_back("--title"); + command.push_back(title); + } + + if (flags(flag::is_verbose)) + std::cerr << "pfd: " << command << std::endl; + + m_async->start_process(command); +#endif +} + +inline std::string internal::file_dialog::string_result() +{ +#if _WIN32 + return m_async->result(); +#else + auto ret = m_async->result(); + // Strip potential trailing newline (zenity). Also strip trailing slash + // added by osascript for consistency with other backends. + while (!ret.empty() && (ret.back() == '\n' || ret.back() == '/')) + ret.pop_back(); + return ret; +#endif +} + +inline std::vector internal::file_dialog::vector_result() +{ +#if _WIN32 + m_async->result(); + return m_vector_result; +#else + std::vector ret; + auto result = m_async->result(); + for (;;) + { + // Split result along newline characters + auto i = result.find('\n'); + if (i == 0 || i == std::string::npos) + break; + ret.push_back(result.substr(0, i)); + result = result.substr(i + 1, result.size()); + } + return ret; +#endif +} + +#if _WIN32 +// Use a static function to pass as BFFCALLBACK for legacy folder select +inline int CALLBACK internal::file_dialog::bffcallback(HWND hwnd, UINT uMsg, + LPARAM, LPARAM pData) +{ + auto inst = (file_dialog *)pData; + switch (uMsg) + { + case BFFM_INITIALIZED: + SendMessage(hwnd, BFFM_SETSELECTIONW, TRUE, (LPARAM)inst->m_wdefault_path.c_str()); + break; + } + return 0; +} + +#if PFD_HAS_IFILEDIALOG +inline std::string internal::file_dialog::select_folder_vista(IFileDialog *ifd, bool force_path) +{ + std::string result; + + IShellItem *folder; + + // Load library at runtime so app doesn't link it at load time (which will fail on windows XP) + dll shell32("shell32.dll"); + dll::proc + create_item(shell32, "SHCreateItemFromParsingName"); + + if (!create_item) + return ""; + + auto hr = create_item(m_wdefault_path.c_str(), + nullptr, + IID_PPV_ARGS(&folder)); + + // Set default folder if found. This only sets the default folder. If + // Windows has any info about the most recently selected folder, it + // will display it instead. Generally, calling SetFolder() to set the + // current directory “is not a good or expected user experience and + // should therefore be avoided”: + // https://docs.microsoft.com/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifiledialog-setfolder + if (SUCCEEDED(hr)) + { + if (force_path) + ifd->SetFolder(folder); + else + ifd->SetDefaultFolder(folder); + folder->Release(); + } + + // Set the dialog title and option to select folders + ifd->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM); + ifd->SetTitle(m_wtitle.c_str()); + + hr = ifd->Show(GetActiveWindow()); + if (SUCCEEDED(hr)) + { + IShellItem* item; + hr = ifd->GetResult(&item); + if (SUCCEEDED(hr)) + { + wchar_t* wname = nullptr; + // This is unlikely to fail because we use FOS_FORCEFILESYSTEM, but try + // to output a debug message just in case. + if (SUCCEEDED(item->GetDisplayName(SIGDN_FILESYSPATH, &wname))) + { + result = internal::wstr2str(std::wstring(wname)); + dll::proc(ole32_dll(), "CoTaskMemFree")(wname); + } + else + { + if (SUCCEEDED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &wname))) + { + auto name = internal::wstr2str(std::wstring(wname)); + dll::proc(ole32_dll(), "CoTaskMemFree")(wname); + std::cerr << "pfd: failed to get path for " << name << std::endl; + } + else + std::cerr << "pfd: item of unknown type selected" << std::endl; + } + + item->Release(); + } + } + + ifd->Release(); + + return result; +} +#endif +#endif + +// notify implementation + +inline notify::notify(std::string const &title, + std::string const &message, + icon _icon /* = icon::info */) +{ + if (_icon == icon::question) // Not supported by notifications + _icon = icon::info; + +#if _WIN32 + // Use a static shared pointer for notify_icon so that we can delete + // it whenever we need to display a new one, and we can also wait + // until the program has finished running. + struct notify_icon_data : public NOTIFYICONDATAW + { + ~notify_icon_data() { Shell_NotifyIconW(NIM_DELETE, this); } + }; + + static std::shared_ptr nid; + + // Release the previous notification icon, if any, and allocate a new + // one. Note that std::make_shared() does value initialization, so there + // is no need to memset the structure. + nid = nullptr; + nid = std::make_shared(); + + // For XP support + nid->cbSize = NOTIFYICONDATAW_V2_SIZE; + nid->hWnd = nullptr; + nid->uID = 0; + + // Flag Description: + // - NIF_ICON The hIcon member is valid. + // - NIF_MESSAGE The uCallbackMessage member is valid. + // - NIF_TIP The szTip member is valid. + // - NIF_STATE The dwState and dwStateMask members are valid. + // - NIF_INFO Use a balloon ToolTip instead of a standard ToolTip. The szInfo, uTimeout, szInfoTitle, and dwInfoFlags members are valid. + // - NIF_GUID Reserved. + nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO; + + // Flag Description + // - NIIF_ERROR An error icon. + // - NIIF_INFO An information icon. + // - NIIF_NONE No icon. + // - NIIF_WARNING A warning icon. + // - NIIF_ICON_MASK Version 6.0. Reserved. + // - NIIF_NOSOUND Version 6.0. Do not play the associated sound. Applies only to balloon ToolTips + switch (_icon) + { + case icon::warning: nid->dwInfoFlags = NIIF_WARNING; break; + case icon::error: nid->dwInfoFlags = NIIF_ERROR; break; + /* case icon::info: */ default: nid->dwInfoFlags = NIIF_INFO; break; + } + + ENUMRESNAMEPROC icon_enum_callback = [](HMODULE, LPCTSTR, LPTSTR lpName, LONG_PTR lParam) -> BOOL + { + ((NOTIFYICONDATAW *)lParam)->hIcon = ::LoadIcon(GetModuleHandle(nullptr), lpName); + return false; + }; + + nid->hIcon = ::LoadIcon(nullptr, IDI_APPLICATION); + ::EnumResourceNames(nullptr, RT_GROUP_ICON, icon_enum_callback, (LONG_PTR)nid.get()); + + nid->uTimeout = 5000; + + StringCchCopyW(nid->szInfoTitle, ARRAYSIZE(nid->szInfoTitle), internal::str2wstr(title).c_str()); + StringCchCopyW(nid->szInfo, ARRAYSIZE(nid->szInfo), internal::str2wstr(message).c_str()); + + // Display the new icon + Shell_NotifyIconW(NIM_ADD, nid.get()); +#elif __EMSCRIPTEN__ + // FIXME: do something + (void)title; + (void)message; +#else + auto command = desktop_helper(); + + if (is_osascript()) + { + command.push_back("-e"); + command.push_back("display notification " + osascript_quote(message) + + " with title " + osascript_quote(title)); + } + else if (is_zenity()) + { + command.push_back("--notification"); + command.push_back("--window-icon"); + command.push_back(get_icon_name(_icon)); + command.push_back("--text"); + command.push_back(title + "\n" + message); + } + else if (is_kdialog()) + { + command.push_back("--icon"); + command.push_back(get_icon_name(_icon)); + command.push_back("--title"); + command.push_back(title); + command.push_back("--passivepopup"); + command.push_back(message); + command.push_back("5"); + } + + if (flags(flag::is_verbose)) + std::cerr << "pfd: " << command << std::endl; + + m_async->start_process(command); +#endif +} + +// message implementation + +inline message::message(std::string const &title, + std::string const &text, + choice _choice /* = choice::ok_cancel */, + icon _icon /* = icon::info */) +{ +#if _WIN32 + // Use MB_SYSTEMMODAL rather than MB_TOPMOST to ensure the message window is brought + // to front. See https://github.com/samhocevar/portable-file-dialogs/issues/52 + UINT style = MB_SYSTEMMODAL; + switch (_icon) + { + case icon::warning: style |= MB_ICONWARNING; break; + case icon::error: style |= MB_ICONERROR; break; + case icon::question: style |= MB_ICONQUESTION; break; + /* case icon::info: */ default: style |= MB_ICONINFORMATION; break; + } + + switch (_choice) + { + case choice::ok_cancel: style |= MB_OKCANCEL; break; + case choice::yes_no: style |= MB_YESNO; break; + case choice::yes_no_cancel: style |= MB_YESNOCANCEL; break; + case choice::retry_cancel: style |= MB_RETRYCANCEL; break; + case choice::abort_retry_ignore: style |= MB_ABORTRETRYIGNORE; break; + /* case choice::ok: */ default: style |= MB_OK; break; + } + + m_mappings[IDCANCEL] = button::cancel; + m_mappings[IDOK] = button::ok; + m_mappings[IDYES] = button::yes; + m_mappings[IDNO] = button::no; + m_mappings[IDABORT] = button::abort; + m_mappings[IDRETRY] = button::retry; + m_mappings[IDIGNORE] = button::ignore; + + m_async->start_func([text, title, style](int* exit_code) -> std::string + { + auto wtext = internal::str2wstr(text); + auto wtitle = internal::str2wstr(title); + // Apply new visual style (required for all Windows versions) + new_style_context ctx; + *exit_code = MessageBoxW(GetActiveWindow(), wtext.c_str(), wtitle.c_str(), style); + return ""; + }); + +#elif __EMSCRIPTEN__ + std::string full_message; + switch (_icon) + { + case icon::warning: full_message = "⚠️"; break; + case icon::error: full_message = "⛔"; break; + case icon::question: full_message = "❓"; break; + /* case icon::info: */ default: full_message = "ℹ"; break; + } + + full_message += ' ' + title + "\n\n" + text; + + // This does not really start an async task; it just passes the + // EM_ASM_INT return value to a fake start() function. + m_async->start(EM_ASM_INT( + { + if ($1) + return window.confirm(UTF8ToString($0)) ? 0 : -1; + alert(UTF8ToString($0)); + return 0; + }, full_message.c_str(), _choice == choice::ok_cancel)); +#else + auto command = desktop_helper(); + + if (is_osascript()) + { + std::string script = "display dialog " + osascript_quote(text) + + " with title " + osascript_quote(title); + auto if_cancel = button::cancel; + switch (_choice) + { + case choice::ok_cancel: + script += "buttons {\"OK\", \"Cancel\"}" + " default button \"OK\"" + " cancel button \"Cancel\""; + break; + case choice::yes_no: + script += "buttons {\"Yes\", \"No\"}" + " default button \"Yes\"" + " cancel button \"No\""; + if_cancel = button::no; + break; + case choice::yes_no_cancel: + script += "buttons {\"Yes\", \"No\", \"Cancel\"}" + " default button \"Yes\"" + " cancel button \"Cancel\""; + break; + case choice::retry_cancel: + script += "buttons {\"Retry\", \"Cancel\"}" + " default button \"Retry\"" + " cancel button \"Cancel\""; + break; + case choice::abort_retry_ignore: + script += "buttons {\"Abort\", \"Retry\", \"Ignore\"}" + " default button \"Abort\"" + " cancel button \"Retry\""; + if_cancel = button::retry; + break; + case choice::ok: default: + script += "buttons {\"OK\"}" + " default button \"OK\"" + " cancel button \"OK\""; + if_cancel = button::ok; + break; + } + m_mappings[1] = if_cancel; + m_mappings[256] = if_cancel; // XXX: I think this was never correct + script += " with icon "; + switch (_icon) + { + #define PFD_OSX_ICON(n) "alias ((path to library folder from system domain) as text " \ + "& \"CoreServices:CoreTypes.bundle:Contents:Resources:" n ".icns\")" + case icon::info: default: script += PFD_OSX_ICON("ToolBarInfo"); break; + case icon::warning: script += "caution"; break; + case icon::error: script += "stop"; break; + case icon::question: script += PFD_OSX_ICON("GenericQuestionMarkIcon"); break; + #undef PFD_OSX_ICON + } + + command.push_back("-e"); + command.push_back(script); + } + else if (is_zenity()) + { + switch (_choice) + { + case choice::ok_cancel: + command.insert(command.end(), { "--question", "--cancel-label=Cancel", "--ok-label=OK" }); break; + case choice::yes_no: + // Do not use standard --question because it causes “No” to return -1, + // which is inconsistent with the “Yes/No/Cancel” mode below. + command.insert(command.end(), { "--question", "--switch", "--extra-button=No", "--extra-button=Yes" }); break; + case choice::yes_no_cancel: + command.insert(command.end(), { "--question", "--switch", "--extra-button=Cancel", "--extra-button=No", "--extra-button=Yes" }); break; + case choice::retry_cancel: + command.insert(command.end(), { "--question", "--switch", "--extra-button=Cancel", "--extra-button=Retry" }); break; + case choice::abort_retry_ignore: + command.insert(command.end(), { "--question", "--switch", "--extra-button=Ignore", "--extra-button=Abort", "--extra-button=Retry" }); break; + case choice::ok: + default: + switch (_icon) + { + case icon::error: command.push_back("--error"); break; + case icon::warning: command.push_back("--warning"); break; + default: command.push_back("--info"); break; + } + } + + command.insert(command.end(), { "--title", title, + "--width=300", "--height=0", // sensible defaults + "--no-markup", // do not interpret text as Pango markup + "--text", text, + "--icon-name=dialog-" + get_icon_name(_icon) }); + } + else if (is_kdialog()) + { + if (_choice == choice::ok) + { + switch (_icon) + { + case icon::error: command.push_back("--error"); break; + case icon::warning: command.push_back("--sorry"); break; + default: command.push_back("--msgbox"); break; + } + } + else + { + std::string flag = "--"; + if (_icon == icon::warning || _icon == icon::error) + flag += "warning"; + flag += "yesno"; + if (_choice == choice::yes_no_cancel) + flag += "cancel"; + command.push_back(flag); + if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) + { + m_mappings[0] = button::yes; + m_mappings[256] = button::no; + } + } + + command.push_back(text); + command.push_back("--title"); + command.push_back(title); + + // Must be after the above part + if (_choice == choice::ok_cancel) + command.insert(command.end(), { "--yes-label", "OK", "--no-label", "Cancel" }); + } + + if (flags(flag::is_verbose)) + std::cerr << "pfd: " << command << std::endl; + + m_async->start_process(command); +#endif +} + +inline button message::result() +{ + int exit_code; + auto ret = m_async->result(&exit_code); + // osascript will say "button returned:Cancel\n" + // and others will just say "Cancel\n" + if (internal::ends_with(ret, "Cancel\n")) + return button::cancel; + if (internal::ends_with(ret, "OK\n")) + return button::ok; + if (internal::ends_with(ret, "Yes\n")) + return button::yes; + if (internal::ends_with(ret, "No\n")) + return button::no; + if (internal::ends_with(ret, "Abort\n")) + return button::abort; + if (internal::ends_with(ret, "Retry\n")) + return button::retry; + if (internal::ends_with(ret, "Ignore\n")) + return button::ignore; + if (m_mappings.count(exit_code) != 0) + return m_mappings[exit_code]; + return exit_code == 0 ? button::ok : button::cancel; +} + +// open_file implementation + +inline open_file::open_file(std::string const &title, + std::string const &default_path /* = "" */, + std::vector const &filters /* = { "All Files", "*" } */, + opt options /* = opt::none */) + : file_dialog(type::open, title, default_path, filters, options) +{ +} + +inline open_file::open_file(std::string const &title, + std::string const &default_path, + std::vector const &filters, + bool allow_multiselect) + : open_file(title, default_path, filters, + (allow_multiselect ? opt::multiselect : opt::none)) +{ +} + +inline std::vector open_file::result() +{ + return vector_result(); +} + +// save_file implementation + +inline save_file::save_file(std::string const &title, + std::string const &default_path /* = "" */, + std::vector const &filters /* = { "All Files", "*" } */, + opt options /* = opt::none */) + : file_dialog(type::save, title, default_path, filters, options) +{ +} + +inline save_file::save_file(std::string const &title, + std::string const &default_path, + std::vector const &filters, + bool confirm_overwrite) + : save_file(title, default_path, filters, + (confirm_overwrite ? opt::none : opt::force_overwrite)) +{ +} + +inline std::string save_file::result() +{ + return string_result(); +} + +// select_folder implementation + +inline select_folder::select_folder(std::string const &title, + std::string const &default_path /* = "" */, + opt options /* = opt::none */) + : file_dialog(type::folder, title, default_path, {}, options) +{ +} + +inline std::string select_folder::result() +{ + return string_result(); +} + +#endif // PFD_SKIP_IMPLEMENTATION + +} // namespace pfd diff --git a/mm/2s2h/SohGui.cpp b/mm/2s2h/SohGui.cpp new file mode 100644 index 000000000..6771ff921 --- /dev/null +++ b/mm/2s2h/SohGui.cpp @@ -0,0 +1,216 @@ +// +// SohGui.cpp +// soh +// +// Created by David Chavez on 24.08.22. +// + +#include "SohGui.hpp" + +#include +#include +#define IMGUI_DEFINE_MATH_OPERATORS +#include +#include +#include + +#ifdef __APPLE__ +#include "graphic/Fast3D/gfx_metal.h" +#endif + +#ifdef __SWITCH__ +#include +#endif + +//#include "UIWidgets.hpp" +#include "include/global.h" +#include "include/z64audio.h" +//#include "soh/SaveManager.h" +//#include "OTRGlobals.h" +//#include "soh/Enhancements/presets.h" +//#include "2s2h/resource/type/Skeleton.h" +#include "libultraship/libultraship.h" + +//#ifdef ENABLE_CROWD_CONTROL +//#include "Enhancements/crowd-control/CrowdControl.h" +//#endif + +//#include "Enhancements/game-interactor/GameInteractor.h" +//#include "Enhancements/cosmetics/authenticGfxPatches.h" + +bool ShouldClearTextureCacheAtEndOfFrame = false; +bool isBetaQuestEnabled = false; + +extern "C" { + void enableBetaQuest() { isBetaQuestEnabled = true; } + void disableBetaQuest() { isBetaQuestEnabled = false; } +} + + +namespace SohGui { + + // MARK: - Properties + + static const char* chestSizeAndTextureMatchesContentsOptions[4] = { "Disabled", "Both", "Texture Only", "Size Only" }; + static const char* bunnyHoodOptions[3] = { "Disabled", "Faster Run & Longer Jump", "Faster Run" }; + static const char* allPowers[9] = { + "Vanilla (1x)", + "Double (2x)", + "Quadruple (4x)", + "Octuple (8x)", + "Foolish (16x)", + "Ridiculous (32x)", + "Merciless (64x)", + "Pure Torture (128x)", + "OHKO (256x)" }; + static const char* subPowers[8] = { allPowers[0], allPowers[1], allPowers[2], allPowers[3], allPowers[4], allPowers[5], allPowers[6], allPowers[7] }; + static const char* subSubPowers[7] = { allPowers[0], allPowers[1], allPowers[2], allPowers[3], allPowers[4], allPowers[5], allPowers[6] }; + static const char* zFightingOptions[3] = { "Disabled", "Consistent Vanish", "No Vanish" }; + static const char* autosaveLabels[6] = { "Off", "New Location + Major Item", "New Location + Any Item", "New Location", "Major Item", "Any Item" }; + static const char* FastFileSelect[5] = { "File N.1", "File N.2", "File N.3", "Zelda Map Select (require OoT Debug Mode)", "File select" }; + static const char* bonkDamageValues[8] = { + "No Damage", + "0.25 Heart", + "0.5 Heart", + "1 Heart", + "2 Hearts", + "4 Hearts", + "8 Hearts", + "OHKO" + }; + + static const inline std::vector> audioBackends = { +#ifdef _WIN32 + { "wasapi", "Windows Audio Session API" }, +#endif +#if defined(__linux) + { "pulse", "PulseAudio" }, +#endif + { "sdl", "SDL Audio" } + }; + + + // MARK: - Helpers + + std::string GetWindowButtonText(const char* text, bool menuOpen) { + char buttonText[100] = ""; + if (menuOpen) { + strcat(buttonText, ICON_FA_CHEVRON_RIGHT " "); + } + strcat(buttonText, text); + if (!menuOpen) { strcat(buttonText, " "); } + return buttonText; + } + + + // MARK: - Delegates + + std::shared_ptr mSohMenuBar; + + std::shared_ptr mConsoleWindow; + std::shared_ptr mStatsWindow; + std::shared_ptr mInputEditorWindow; + std::shared_ptr mGfxDebuggerWindow; + + //std::shared_ptr mAudioEditorWindow; + //std::shared_ptr mGameControlEditorWindow; + //std::shared_ptr mCosmeticsEditorWindow; + //std::shared_ptr mActorViewerWindow; + //std::shared_ptr mColViewerWindow; + //std::shared_ptr mSaveEditorWindow; + //std::shared_ptr mDLViewerWindow; + //std::shared_ptr mGameplayStatsWindow; + //std::shared_ptr mCheckTrackerSettingsWindow; + //std::shared_ptr mCheckTrackerWindow; + //std::shared_ptr mEntranceTrackerWindow; + //std::shared_ptr mItemTrackerSettingsWindow; + //std::shared_ptr mItemTrackerWindow; + //std::shared_ptr mRandomizerSettingsWindow; + + void SetupGuiElements() { + auto gui = LUS::Context::GetInstance()->GetWindow()->GetGui(); + + mSohMenuBar = std::make_shared("gOpenMenuBar", CVarGetInteger("gOpenMenuBar", 0)); + gui->SetMenuBar(std::reinterpret_pointer_cast(mSohMenuBar)); + + if (gui->GetMenuBar() && !gui->GetMenuBar()->IsVisible()) { +#if defined(__SWITCH__) || defined(__WIIU__) + gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press - to access enhancements menu"); +#else + gui->GetGameOverlay()->TextDrawNotification(30.0f, true, "Press F1 to access enhancements menu"); +#endif + } + + mStatsWindow = gui->GetGuiWindow("Stats"); + if (mStatsWindow == nullptr) { + SPDLOG_ERROR("Could not find stats window"); + } + + mConsoleWindow = gui->GetGuiWindow("Console"); + if (mConsoleWindow == nullptr) { + SPDLOG_ERROR("Could not find console window"); + } + + mInputEditorWindow = gui->GetGuiWindow("Input Editor"); + if (mInputEditorWindow == nullptr) { + SPDLOG_ERROR("Could not find input editor window"); + } + + mGfxDebuggerWindow = gui->GetGuiWindow("GfxDebuggerWindow"); + if (mGfxDebuggerWindow == nullptr) { + SPDLOG_ERROR("Could not find input GfxDebuggerWindow"); + } + + /* + mAudioEditorWindow = std::make_shared("gAudioEditor.WindowOpen", "Audio Editor"); + gui->AddGuiWindow(mAudioEditorWindow); + mGameControlEditorWindow = std::make_shared("gGameControlEditorEnabled", "Game Control Editor"); + gui->AddGuiWindow(mGameControlEditorWindow); + mCosmeticsEditorWindow = std::make_shared("gCosmeticsEditorEnabled", "Cosmetics Editor"); + gui->AddGuiWindow(mCosmeticsEditorWindow); + mActorViewerWindow = std::make_shared("gActorViewerEnabled", "Actor Viewer"); + gui->AddGuiWindow(mActorViewerWindow); + mColViewerWindow = std::make_shared("gCollisionViewerEnabled", "Collision Viewer"); + gui->AddGuiWindow(mColViewerWindow); + mSaveEditorWindow = std::make_shared("gSaveEditorEnabled", "Save Editor"); + gui->AddGuiWindow(mSaveEditorWindow); + mDLViewerWindow = std::make_shared("gDLViewerEnabled", "Display List Viewer"); + gui->AddGuiWindow(mDLViewerWindow); + mGameplayStatsWindow = std::make_shared("gGameplayStatsEnabled", "Gameplay Stats"); + gui->AddGuiWindow(mGameplayStatsWindow); + mCheckTrackerWindow = std::make_shared("gCheckTrackerEnabled", "Check Tracker"); + gui->AddGuiWindow(mCheckTrackerWindow); + mCheckTrackerSettingsWindow = std::make_shared("gCheckTrackerSettingsEnabled", "Check Tracker Settings"); + gui->AddGuiWindow(mCheckTrackerSettingsWindow); + mEntranceTrackerWindow = std::make_shared("gEntranceTrackerEnabled","Entrance Tracker"); + gui->AddGuiWindow(mEntranceTrackerWindow); + mItemTrackerWindow = std::make_shared("gItemTrackerEnabled", "Item Tracker"); + gui->AddGuiWindow(mItemTrackerWindow); + mItemTrackerSettingsWindow = std::make_shared("gItemTrackerSettingsEnabled", "Item Tracker Settings"); + gui->AddGuiWindow(mItemTrackerSettingsWindow); + mRandomizerSettingsWindow = std::make_shared("gRandomizerSettingsEnabled", "Randomizer Settings"); + gui->AddGuiWindow(mRandomizerSettingsWindow); + */ + } + + void Destroy() { + //mRandomizerSettingsWindow = nullptr; + //mItemTrackerWindow = nullptr; + //mItemTrackerSettingsWindow = nullptr; + //mEntranceTrackerWindow = nullptr; + //mCheckTrackerWindow = nullptr; + //mCheckTrackerSettingsWindow = nullptr; + //mGameplayStatsWindow = nullptr; + //mDLViewerWindow = nullptr; + //mSaveEditorWindow = nullptr; + //mColViewerWindow = nullptr; + //mActorViewerWindow = nullptr; + //mCosmeticsEditorWindow = nullptr; + //mGameControlEditorWindow = nullptr; + //mAudioEditorWindow = nullptr; + //mInputEditorWindow = nullptr; + mStatsWindow = nullptr; + mConsoleWindow = nullptr; + mSohMenuBar = nullptr; + } +} diff --git a/mm/2s2h/SohGui.hpp b/mm/2s2h/SohGui.hpp new file mode 100644 index 000000000..8e5fc9447 --- /dev/null +++ b/mm/2s2h/SohGui.hpp @@ -0,0 +1,42 @@ +// +// SohGui.hpp +// soh +// +// Created by David Chavez on 24.08.22. +// + +#ifndef SohGui_hpp +#define SohGui_hpp + +#include +#include "SohMenuBar.h" +//#include "Enhancements/audio/AudioEditor.h" +//#include "Enhancements/controls/GameControlEditor.h" +//#include "Enhancements/cosmetics/CosmeticsEditor.h" +//#include "Enhancements/debugger/actorViewer.h" +//#include "Enhancements/debugger/colViewer.h" +//#include "Enhancements/debugger/debugSaveEditor.h" +//#include "Enhancements/debugger/dlViewer.h" +//#include "Enhancements/gameplaystatswindow.h" +//#include "Enhancements/randomizer/randomizer_check_tracker.h" +//#include "Enhancements/randomizer/randomizer_entrance_tracker.h" +//#include "Enhancements/randomizer/randomizer_item_tracker.h" +//#include "Enhancements/randomizer/randomizer_settings_window.h" + +#ifdef __cplusplus +extern "C" { +#endif + void enableBetaQuest(); + void disableBetaQuest(); +#ifdef __cplusplus +} +#endif + +namespace SohGui { + void SetupHooks(); + void SetupGuiElements(); + void Draw(); + void Destroy(); +} + +#endif /* SohGui_hpp */ diff --git a/mm/2s2h/SohMenuBar.cpp b/mm/2s2h/SohMenuBar.cpp new file mode 100644 index 000000000..cbc502839 --- /dev/null +++ b/mm/2s2h/SohMenuBar.cpp @@ -0,0 +1,574 @@ +#include "SohMenuBar.h" +#include "ImGui/imgui.h" +#include "public/bridge/consolevariablebridge.h" +#include +#include "UIWidgets.hpp" +//#include "include/z64audio.h" +//#include "OTRGlobals.h" +#include "z64.h" +//#include "Enhancements/game-interactor/GameInteractor.h" +//#include "soh/Enhancements/presets.h" +//#include "soh/Enhancements/mods.h" +//#include "Enhancements/cosmetics/authenticGfxPatches.h" +#ifdef ENABLE_CROWD_CONTROL +#include "Enhancements/crowd-control/CrowdControl.h" +#endif + + +//#include "Enhancements/audio/AudioEditor.h" +//#include "Enhancements/controls/GameControlEditor.h" +//#include "Enhancements/cosmetics/CosmeticsEditor.h" +//#include "Enhancements/debugger/actorViewer.h" +//#include "Enhancements/debugger/colViewer.h" +//#include "Enhancements/debugger/debugSaveEditor.h" +//#include "Enhancements/debugger/dlViewer.h" +//#include "Enhancements/gameplaystatswindow.h" +//#include "Enhancements/randomizer/randomizer_check_tracker.h" +//#include "Enhancements/randomizer/randomizer_entrance_tracker.h" +//#include "Enhancements/randomizer/randomizer_item_tracker.h" +//#include "Enhancements/randomizer/randomizer_settings_window.h" + +extern bool ShouldClearTextureCacheAtEndOfFrame; +extern bool isBetaQuestEnabled; + +extern "C" PlayState* gPlayState; + +enum SeqPlayers { + /* 0 */ SEQ_BGM_MAIN, + /* 1 */ SEQ_FANFARE, + /* 2 */ SEQ_SFX, + /* 3 */ SEQ_BGM_SUB, + /* 4 */ SEQ_MAX +}; + +std::string GetWindowButtonText(const char* text, bool menuOpen) { + char buttonText[100] = ""; + if (menuOpen) { + strcat(buttonText, ICON_FA_CHEVRON_RIGHT " "); + } + strcat(buttonText, text); + if (!menuOpen) { strcat(buttonText, " "); } + return buttonText; +} + + static const char* filters[3] = { +#ifdef __WIIU__ + "", +#else + "Three-Point", +#endif + "Linear", "None" + }; + + static const char* chestStyleMatchesContentsOptions[4] = { "Disabled", "Both", "Texture Only", "Size Only" }; + static const char* bunnyHoodOptions[3] = { "Disabled", "Faster Run & Longer Jump", "Faster Run" }; + static const char* mirroredWorldModes[9] = { + "Disabled", "Always", "Random", "Random (Seeded)", "Dungeons", + "Dungeons (Vanilla)", "Dungeons (MQ)", "Dungeons Random", "Dungeons Random (Seeded)", + }; + static const char* enemyRandomizerModes[3] = { "Disabled", "Random", "Random (Seeded)" }; + static const char* allPowers[9] = { + "Vanilla (1x)", + "Double (2x)", + "Quadruple (4x)", + "Octuple (8x)", + "Foolish (16x)", + "Ridiculous (32x)", + "Merciless (64x)", + "Pure Torture (128x)", + "OHKO (256x)" }; + static const char* subPowers[8] = { allPowers[0], allPowers[1], allPowers[2], allPowers[3], allPowers[4], allPowers[5], allPowers[6], allPowers[7] }; + static const char* subSubPowers[7] = { allPowers[0], allPowers[1], allPowers[2], allPowers[3], allPowers[4], allPowers[5], allPowers[6] }; + static const char* zFightingOptions[3] = { "Disabled", "Consistent Vanish", "No Vanish" }; + static const char* autosaveLabels[6] = { "Off", "New Location + Major Item", "New Location + Any Item", "New Location", "Major Item", "Any Item" }; + static const char* DebugSaveFileModes[3] = { "Off", "Vanilla", "Maxed" }; + static const char* FastFileSelect[5] = { "File N.1", "File N.2", "File N.3", "Zelda Map Select (require OoT Debug Mode)", "File select" }; + static const char* DekuStickCheat[3] = { "Normal", "Unbreakable", "Unbreakable + Always on Fire" }; + static const char* bonkDamageValues[8] = { + "No Damage", + "0.25 Heart", + "0.5 Heart", + "1 Heart", + "2 Hearts", + "4 Hearts", + "8 Hearts", + "OHKO" + }; + static const char* timeTravelOptions[3] = { "Disabled", "Ocarina of Time", "Any Ocarina" }; + +extern "C" SaveContext gSaveContext; + +namespace SohGui { + +void DrawMenuBarIcon() { + static bool gameIconLoaded = false; + if (!gameIconLoaded) { + LUS::Context::GetInstance()->GetWindow()->GetGui()->LoadTexture("Game_Icon", "textures/icons/gIcon.png"); + gameIconLoaded = true; + } + + if (LUS::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName("Game_Icon")) { +#ifdef __SWITCH__ + ImVec2 iconSize = ImVec2(20.0f, 20.0f); + float posScale = 1.0f; +#elif defined(__WIIU__) + ImVec2 iconSize = ImVec2(16.0f * 2, 16.0f * 2); + float posScale = 2.0f; +#else + ImVec2 iconSize = ImVec2(16.0f, 16.0f); + float posScale = 1.0f; +#endif + ImGui::SetCursorPos(ImVec2(5, 2.5f) * posScale); + ImGui::Image(LUS::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName("Game_Icon"), iconSize); + ImGui::SameLine(); + ImGui::SetCursorPos(ImVec2(25, 0) * posScale); + } +} + +void DrawShipMenu() { + if (ImGui::BeginMenu("Ship")) { + if (ImGui::MenuItem("Hide Menu Bar", +#if !defined(__SWITCH__) && !defined(__WIIU__) + "F1" +#else + "[-]" +#endif + )) { + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetMenuBar()->ToggleVisibility(); + } + UIWidgets::Spacer(0); +#if !defined(__SWITCH__) && !defined(__WIIU__) + if (ImGui::MenuItem("Toggle Fullscreen", "F11")) { + LUS::Context::GetInstance()->GetWindow()->ToggleFullscreen(); + } + UIWidgets::Spacer(0); +#endif + if (ImGui::MenuItem("Reset", +#ifdef __APPLE__ + "Command-R" +#elif !defined(__SWITCH__) && !defined(__WIIU__) + "Ctrl+R" +#else + "" +#endif + )) { + std::reinterpret_pointer_cast( + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")) + ->Dispatch("reset"); + } +#if !defined(__SWITCH__) && !defined(__WIIU__) + UIWidgets::Spacer(0); + if (ImGui::MenuItem("Open App Files Folder")) { + std::string filesPath = LUS::Context::GetInstance()->GetAppDirectoryPath(); + SDL_OpenURL(std::string("file:///" + std::filesystem::absolute(filesPath).string()).c_str()); + } + UIWidgets::Spacer(0); + + if (ImGui::MenuItem("Quit")) { + LUS::Context::GetInstance()->GetWindow()->Close(); + } +#endif + ImGui::EndMenu(); + } +} + +extern std::shared_ptr mInputEditorWindow; +// extern std::shared_ptr mGameControlEditorWindow; + +void DrawSettingsMenu() { + if (ImGui::BeginMenu("Settings")) { + if (ImGui::BeginMenu("Audio")) { + UIWidgets::PaddedEnhancementSliderFloat("Master Volume: %d %%", "##Master_Vol", "gGameMasterVolume", 0.0f, + 1.0f, "", 1.0f, true, true, false, true); + if (UIWidgets::PaddedEnhancementSliderFloat("Main Music Volume: %d %%", "##Main_Music_Vol", + "gMainMusicVolume", 0.0f, 1.0f, "", 1.0f, true, true, false, + true)) { + // Audio_SetGameVolume(SEQ_BGM_MAIN, CVarGetFloat("gMainMusicVolume", 1.0f)); + } + if (UIWidgets::PaddedEnhancementSliderFloat("Sub Music Volume: %d %%", "##Sub_Music_Vol", "gSubMusicVolume", + 0.0f, 1.0f, "", 1.0f, true, true, false, true)) { + // Audio_SetGameVolume(SEQ_BGM_SUB, CVarGetFloat("gSubMusicVolume", 1.0f)); + } + if (UIWidgets::PaddedEnhancementSliderFloat("Sound Effects Volume: %d %%", "##Sound_Effect_Vol", + "gSFXMusicVolume", 0.0f, 1.0f, "", 1.0f, true, true, false, + true)) { + // Audio_SetGameVolume(SEQ_SFX, CVarGetFloat("gSFXMusicVolume", 1.0f)); + } + if (UIWidgets::PaddedEnhancementSliderFloat("Fanfare Volume: %d %%", "##Fanfare_Vol", "gFanfareVolume", + 0.0f, 1.0f, "", 1.0f, true, true, false, true)) { + // Audio_SetGameVolume(SEQ_FANFARE, CVarGetFloat("gFanfareVolume", 1.0f)); + } + + static std::unordered_map audioBackendNames = { + { LUS::AudioBackend::WASAPI, "Windows Audio Session API" }, + { LUS::AudioBackend::PULSE, "PulseAudio" }, + { LUS::AudioBackend::SDL, "SDL" }, + }; + + ImGui::Text("Audio API (Needs reload)"); + auto currentAudioBackend = LUS::Context::GetInstance()->GetAudio()->GetAudioBackend(); + + if (LUS::Context::GetInstance()->GetAudio()->GetAvailableAudioBackends()->size() <= 1) { + UIWidgets::DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + if (ImGui::BeginCombo("##AApi", audioBackendNames[currentAudioBackend])) { + for (uint8_t i = 0; i < LUS::Context::GetInstance()->GetAudio()->GetAvailableAudioBackends()->size(); + i++) { + auto backend = LUS::Context::GetInstance()->GetAudio()->GetAvailableAudioBackends()->data()[i]; + if (ImGui::Selectable(audioBackendNames[backend], backend == currentAudioBackend)) { + LUS::Context::GetInstance()->GetAudio()->SetAudioBackend(backend); + } + } + ImGui::EndCombo(); + } + if (LUS::Context::GetInstance()->GetAudio()->GetAvailableAudioBackends()->size() <= 1) { + UIWidgets::ReEnableComponent(""); + } + + ImGui::EndMenu(); + } + + UIWidgets::Spacer(0); + + if (ImGui::BeginMenu("Controller")) { + //ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 6.0f)); + //ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.0f)); + //ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); + //ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.22f, 0.38f, 0.56f, 1.0f)); + if (mInputEditorWindow) { + if (ImGui::Button( + GetWindowButtonText("Controller Mapping", CVarGetInteger("gControllerConfigurationEnabled", 0)) + .c_str(), + ImVec2(-1.0f, 0.0f))) { + mInputEditorWindow->ToggleVisibility(); + } + } + // if (mGameControlEditorWindow) { + // if (ImGui::Button(GetWindowButtonText("Additional Controller Options", + // CVarGetInteger("gGameControlEditorEnabled", 0)).c_str(), ImVec2(-1.0f, 0.0f))) { + // mGameControlEditorWindow->ToggleVisibility(); + //} + + ImGui::EndMenu(); + + } + UIWidgets::PaddedSeparator(); + //ImGui::PopStyleColor(1); + //ImGui::PopStyleVar(3); +#ifndef __SWITCH__ + UIWidgets::EnhancementCheckbox("Menubar Controller Navigation", "gControlNav"); + UIWidgets::Tooltip("Allows controller navigation of the SOH menu bar (Settings, Enhancements,...)\nCAUTION: " + "This will disable game inputs while the menubar is visible.\n\nD-pad to move between " + "items, A to select, and X to grab focus on the menu bar"); +#endif + UIWidgets::PaddedEnhancementCheckbox("Show Inputs", "gInputEnabled", true, false); + UIWidgets::Tooltip("Shows currently pressed inputs on the bottom right of the screen"); + UIWidgets::PaddedEnhancementSliderFloat("Input Scale: %.1f", "##Input", "gInputScale", 1.0f, 3.0f, "", 1.0f, + false, true, true, false); + UIWidgets::Tooltip("Sets the on screen size of the displayed inputs from the Show Inputs setting"); + UIWidgets::PaddedEnhancementSliderInt("Simulated Input Lag: %d frames", "##SimulatedInputLag", + "gSimulatedInputLag", 0, 6, "", 0, true, true, false); + UIWidgets::Tooltip("Buffers your inputs to be executed a specified amount of frames later"); + + ImGui::EndMenu(); + } + + UIWidgets::Spacer(0); + + if (ImGui::BeginMenu("Graphics")) { +#ifndef __APPLE__ + if (UIWidgets::EnhancementSliderFloat("Internal Resolution: %d %%", "##IMul", "gInternalResolution", 0.5f, 2.0f, + "", 1.0f, true)) { + LUS::Context::GetInstance()->GetWindow()->SetResolutionMultiplier(CVarGetFloat("gInternalResolution", 1)); + }; + UIWidgets::Tooltip("Multiplies your output resolution by the value inputted, as a more intensive but effective " + "form of anti-aliasing"); +#endif +#ifndef __WIIU__ + if (UIWidgets::PaddedEnhancementSliderInt("MSAA: %d", "##IMSAA", "gMSAAValue", 1, 8, "", 1, true, true, + false)) { + LUS::Context::GetInstance()->GetWindow()->SetMsaaLevel(CVarGetInteger("gMSAAValue", 1)); + }; + UIWidgets::Tooltip("Activates multi-sample anti-aliasing when above 1x up to 8x for 8 samples for every pixel"); +#endif + + { // FPS Slider + const int minFps = 20; + static int maxFps; + if (LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() == LUS::WindowBackend::DX11) { + maxFps = 360; + } else { + maxFps = LUS::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(); + } + // int currentFps = fmax(fmin(OTRGlobals::Instance->GetInterpolationFPS(), maxFps), minFps); + int currentFps = 20; + bool matchingRefreshRate = + CVarGetInteger("gMatchRefreshRate", 0) && + LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() != LUS::WindowBackend::DX11; + UIWidgets::PaddedEnhancementSliderInt((currentFps == 20) ? "FPS: Original (20)" : "FPS: %d", + "##FPSInterpolation", "gInterpolationFPS", minFps, maxFps, "", 20, + true, true, false, matchingRefreshRate); + if (LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() == LUS::WindowBackend::DX11) { + UIWidgets::Tooltip( + "Uses Matrix Interpolation to create extra frames, resulting in smoother graphics. This is purely " + "visual and does not impact game logic, execution of glitches etc.\n\n" + "A higher target FPS than your monitor's refresh rate will waste resources, and might give a worse " + "result."); + } else { + UIWidgets::Tooltip( + "Uses Matrix Interpolation to create extra frames, resulting in smoother graphics. This is purely " + "visual and does not impact game logic, execution of glitches etc."); + } + } // END FPS Slider + + if (LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() == LUS::WindowBackend::DX11) { + UIWidgets::Spacer(0); + if (ImGui::Button("Match Refresh Rate")) { + int hz = LUS::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate(); + if (hz >= 20 && hz <= 360) { + CVarSetInteger("gInterpolationFPS", hz); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + } + } + } else { + UIWidgets::PaddedEnhancementCheckbox("Match Refresh Rate", "gMatchRefreshRate", true, false); + } + UIWidgets::Tooltip("Matches interpolation value to the current game's window refresh rate"); + + if (LUS::Context::GetInstance()->GetWindow()->GetWindowBackend() == LUS::WindowBackend::DX11) { + UIWidgets::PaddedEnhancementSliderInt( + CVarGetInteger("gExtraLatencyThreshold", 80) == 0 ? "Jitter fix: Off" : "Jitter fix: >= %d FPS", + "##ExtraLatencyThreshold", "gExtraLatencyThreshold", 0, 360, "", 80, true, true, false); + UIWidgets::Tooltip("When Interpolation FPS setting is at least this threshold, add one frame of input lag " + "(e.g. 16.6 ms for 60 FPS) in order to avoid jitter. This setting allows the CPU to " + "work on one frame while GPU works on the previous frame.\nThis setting should be used " + "when your computer is too slow to do CPU + GPU work in time."); + } + + UIWidgets::PaddedSeparator(true, true, 3.0f, 3.0f); + + static std::unordered_map windowBackendNames = { + { LUS::WindowBackend::DX11, "DirectX" }, + { LUS::WindowBackend::SDL_OPENGL, "OpenGL" }, + { LUS::WindowBackend::SDL_METAL, "Metal" }, + { LUS::WindowBackend::GX2, "GX2" } + }; + + ImGui::Text("Renderer API (Needs reload)"); + LUS::WindowBackend runningWindowBackend = LUS::Context::GetInstance()->GetWindow()->GetWindowBackend(); + LUS::WindowBackend configWindowBackend; + int configWindowBackendId = LUS::Context::GetInstance()->GetConfig()->GetInt("Window.Backend.Id", -1); + if (configWindowBackendId != -1 && + configWindowBackendId < static_cast(LUS::WindowBackend::BACKEND_COUNT)) { + configWindowBackend = static_cast(configWindowBackendId); + } else { + configWindowBackend = runningWindowBackend; + } + + if (LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) { + UIWidgets::DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + if (ImGui::BeginCombo("##RApi", windowBackendNames[configWindowBackend])) { + for (size_t i = 0; i < LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size(); + i++) { + auto backend = LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->data()[i]; + if (ImGui::Selectable(windowBackendNames[backend], backend == configWindowBackend)) { + LUS::Context::GetInstance()->GetConfig()->SetInt("Window.Backend.Id", static_cast(backend)); + LUS::Context::GetInstance()->GetConfig()->SetString("Window.Backend.Name", + windowBackendNames[backend]); + LUS::Context::GetInstance()->GetConfig()->Save(); + } + } + ImGui::EndCombo(); + } + if (LUS::Context::GetInstance()->GetWindow()->GetAvailableWindowBackends()->size() <= 1) { + UIWidgets::ReEnableComponent(""); + } + + if (LUS::Context::GetInstance()->GetWindow()->CanDisableVerticalSync()) { + UIWidgets::PaddedEnhancementCheckbox("Enable Vsync", "gVsyncEnabled", true, false); + } + + if (LUS::Context::GetInstance()->GetWindow()->SupportsWindowedFullscreen()) { + UIWidgets::PaddedEnhancementCheckbox("Windowed fullscreen", "gSdlWindowedFullscreen", true, false); + } + + if (LUS::Context::GetInstance()->GetWindow()->GetGui()->SupportsViewports()) { + UIWidgets::PaddedEnhancementCheckbox("Allow multi-windows", "gEnableMultiViewports", true, false, false, "", + UIWidgets::CheckboxGraphics::Cross, true); + UIWidgets::Tooltip("Allows windows to be able to be dragged off of the main game window. Requires a reload " + "to take effect."); + } + + // If more filters are added to LUS, make sure to add them to the filters list here + ImGui::Text("Texture Filter (Needs reload)"); + + UIWidgets::EnhancementCombobox("gTextureFilter", filters, FILTER_THREE_POINT); + + UIWidgets::Spacer(0); + + LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGameOverlay()->DrawSettings(); + + ImGui::EndMenu(); + } + + UIWidgets::Spacer(0); + + if (ImGui::BeginMenu("Languages")) { + UIWidgets::PaddedEnhancementCheckbox("Translate Title Screen", "gTitleScreenTranslation"); + if (UIWidgets::EnhancementRadioButton("English", "gLanguages", LANGUAGE_ENG)) { + // GameInteractor::Instance->ExecuteHooks(); + } + if (UIWidgets::EnhancementRadioButton("German", "gLanguages", LANGUAGE_GER)) { + // GameInteractor::Instance->ExecuteHooks(); + } + // if (UIWidgets::EnhancementRadioButton("French", "gLanguages", LANGUAGE_FRA)) { + // GameInteractor::Instance->ExecuteHooks(); + //} + ImGui::EndMenu(); + } + + UIWidgets::Spacer(0); + + if (ImGui::BeginMenu("Accessibility")) { +#if defined(_WIN32) || defined(__APPLE__) + UIWidgets::PaddedEnhancementCheckbox("Text to Speech", "gA11yTTS"); + UIWidgets::Tooltip("Enables text to speech for in game dialog"); +#endif + UIWidgets::PaddedEnhancementCheckbox("Disable Idle Camera Re-Centering", "gA11yDisableIdleCam"); + UIWidgets::Tooltip("Disables the automatic re-centering of the camera when idle."); + + ImGui::EndMenu(); + } + + //ImGui::EndMenu(); +} + +extern std::shared_ptr mStatsWindow; +extern std::shared_ptr mConsoleWindow; +extern std::shared_ptr mGfxDebuggerWindow; +// extern std::shared_ptr mSaveEditorWindow; +// extern std::shared_ptr mColViewerWindow; +// extern std::shared_ptr mActorViewerWindow; +// extern std::shared_ptr mDLViewerWindow; + +void DrawDeveloperToolsMenu() { + if (ImGui::BeginMenu("Developer Tools")) { + UIWidgets::EnhancementCheckbox("OoT Debug Mode", "gDebugEnabled"); + UIWidgets::Tooltip("Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad " + "Right, and open the debug menu with L on the pause screen"); + if (CVarGetInteger("gDebugEnabled", 0)) { + ImGui::Text("Debug Save File Mode:"); + UIWidgets::EnhancementCombobox("gDebugSaveFileMode", DebugSaveFileModes, 1); + UIWidgets::Tooltip("Changes the behaviour of debug file select creation (creating a save file on slot 1 " + "with debug mode on)\n" + "- Off: The debug save file will be a normal savefile\n" + "- Vanilla: The debug save file will be the debug save file from the original game\n" + "- Maxed: The debug save file will be a save file with all of the items & upgrades"); + } + UIWidgets::PaddedEnhancementCheckbox("OoT Skulltula Debug", "gSkulltulaDebugEnabled", true, false); + UIWidgets::Tooltip("Enables Skulltula Debug, when moving the cursor in the menu above various map icons (boss " + "key, compass, map screen locations, etc) will set the GS bits in that area.\nUSE WITH " + "CAUTION AS IT DOES NOT UPDATE THE GS COUNT."); + UIWidgets::PaddedEnhancementCheckbox("Fast File Select", "gSkipLogoTitle", true, false); + UIWidgets::Tooltip( + "Load the game to the selected menu or file\n\"Zelda Map Select\" require debug mode else you will " + "fallback to File choose menu\nUsing a file number that don't have save will create a save file only if " + "you toggle on \"Create a new save if none ?\" else it will bring you to the File choose menu"); + if (CVarGetInteger("gSkipLogoTitle", 0)) { + ImGui::Text("Loading:"); + UIWidgets::EnhancementCombobox("gSaveFileID", FastFileSelect, 0); + }; + UIWidgets::PaddedEnhancementCheckbox("Better Debug Warp Screen", "gBetterDebugWarpScreen", true, false); + UIWidgets::Tooltip("Optimized debug warp screen, with the added ability to chose entrances and time of day"); + UIWidgets::PaddedEnhancementCheckbox("Debug Warp Screen Translation", "gDebugWarpScreenTranslation", true, + false, false, "", UIWidgets::CheckboxGraphics::Cross, true); + UIWidgets::Tooltip("Translate the Debug Warp Screen based on the game language"); + UIWidgets::PaddedSeparator(); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(12.0f, 6.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0f); + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.22f, 0.38f, 0.56f, 1.0f)); + if (mStatsWindow) { + if (ImGui::Button(GetWindowButtonText("Stats", CVarGetInteger("gStatsEnabled", 0)).c_str(), + ImVec2(-1.0f, 0.0f))) { + mStatsWindow->ToggleVisibility(); + } + UIWidgets::Tooltip("Shows the stats window, with your FPS and frametimes, and the OS you're playing on"); + } + UIWidgets::Spacer(0); + if (mConsoleWindow) { + if (ImGui::Button(GetWindowButtonText("Console", CVarGetInteger("gConsoleEnabled", 0)).c_str(), + ImVec2(-1.0f, 0.0f))) { + mConsoleWindow->ToggleVisibility(); + } + UIWidgets::Tooltip( + "Enables the console window, allowing you to input commands, type help for some examples"); + } + UIWidgets::Spacer(0); + if (mGfxDebuggerWindow) { + if (ImGui::Button(GetWindowButtonText("Gfx Debugger", CVarGetInteger("gGfxDebuggerEnabled", 0)).c_str(), + ImVec2(-1.0f, 0.0f))) { + mGfxDebuggerWindow->ToggleVisibility(); + } + UIWidgets::Tooltip( + "Enables the Gfx Debugger window, allowing you to input commands, type help for some examples"); + } + UIWidgets::Spacer(0); + + // if (mSaveEditorWindow) { + // if (ImGui::Button(GetWindowButtonText("Save Editor", CVarGetInteger("gSaveEditorEnabled", 0)).c_str(), + // ImVec2(-1.0f, 0.0f))) { + // //mSaveEditorWindow->ToggleVisibility(); + // } + // } + // UIWidgets::Spacer(0); + // if (mColViewerWindow) { + // if (ImGui::Button(GetWindowButtonText("Collision Viewer", CVarGetInteger("gCollisionViewerEnabled", + // 0)).c_str(), ImVec2(-1.0f, 0.0f))) { + // //mColViewerWindow->ToggleVisibility(); + // } + // } + // UIWidgets::Spacer(0); + // if (mActorViewerWindow) { + // if (ImGui::Button(GetWindowButtonText("Actor Viewer", CVarGetInteger("gActorViewerEnabled", 0)).c_str(), + // ImVec2(-1.0f, 0.0f))) { + // //mActorViewerWindow->ToggleVisibility(); + // } + // } + // UIWidgets::Spacer(0); + // if (mDLViewerWindow) { + // if (ImGui::Button(GetWindowButtonText("Display List Viewer", CVarGetInteger("gDLViewerEnabled", + // 0)).c_str(), ImVec2(-1.0f, 0.0f))) { + // //mDLViewerWindow->ToggleVisibility(); + // } + // } + + ImGui::PopStyleVar(3); + ImGui::PopStyleColor(1); + + ImGui::EndMenu(); + } +} + +void SohMenuBar::DrawElement() { + if (ImGui::BeginMenuBar()) { + static ImVec2 sWindowPadding(8.0f, 8.0f); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, sWindowPadding); + + ImGui::SetCursorPosY(0.0f); + DrawSettingsMenu(); + + ImGui::SetCursorPosY(0.0f); + + DrawDeveloperToolsMenu(); + + ImGui::SetCursorPosY(0.0f); + + ImGui::PopStyleVar(1); + ImGui::EndMenuBar(); + } +} +} + // namespace SohGui \ No newline at end of file diff --git a/mm/2s2h/SohMenuBar.h b/mm/2s2h/SohMenuBar.h new file mode 100644 index 000000000..ecfb2764e --- /dev/null +++ b/mm/2s2h/SohMenuBar.h @@ -0,0 +1,16 @@ +#pragma once + +//#include +#include "window/gui/GuiMenuBar.h" +#include "window/gui/GuiElement.h" + +namespace SohGui { +class SohMenuBar : public LUS::GuiMenuBar { + public: + using LUS::GuiMenuBar::GuiMenuBar; + protected: + void DrawElement() override; + void InitElement() override {}; + void UpdateElement() override {}; +}; +} // namespace SohGui \ No newline at end of file diff --git a/mm/2s2h/UIWidgets.cpp b/mm/2s2h/UIWidgets.cpp new file mode 100644 index 000000000..3086f32ad --- /dev/null +++ b/mm/2s2h/UIWidgets.cpp @@ -0,0 +1,716 @@ +// +// UIWidgets.cpp +// soh +// +// Created by David Chavez on 25.08.22. +// + +#include "UIWidgets.hpp" + +#define IMGUI_DEFINE_MATH_OPERATORS +#include +#include + +#include +//#include "soh/Enhancements/cosmetics/CosmeticsEditor.h" + +namespace UIWidgets { + + // MARK: - Layout Helper + + // Automatically adds newlines to break up text longer than a specified number of characters + // Manually included newlines will still be respected and reset the line length + // If line is midword when it hits the limit, text should break at the last encountered space + char* WrappedText(const char* text, unsigned int charactersPerLine) { + std::string newText(text); + const size_t tipLength = newText.length(); + int lastSpace = -1; + int currentLineLength = 0; + for (unsigned int currentCharacter = 0; currentCharacter < tipLength; currentCharacter++) { + if (newText[currentCharacter] == '\n') { + currentLineLength = 0; + lastSpace = -1; + continue; + } else if (newText[currentCharacter] == ' ') { + lastSpace = currentCharacter; + } + + if ((currentLineLength >= charactersPerLine) && (lastSpace >= 0)) { + newText[lastSpace] = '\n'; + currentLineLength = currentCharacter - lastSpace - 1; + lastSpace = -1; + } + currentLineLength++; + } + + return strdup(newText.c_str()); + } + + char* WrappedText(const std::string& text, unsigned int charactersPerLine) { + return WrappedText(text.c_str(), charactersPerLine); + } + + void SetLastItemHoverText(const std::string& text) { + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("%s", WrappedText(text, 60)); + ImGui::EndTooltip(); + } + } + + void SetLastItemHoverText(const char* text) { + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("%s", WrappedText(text, 60)); + ImGui::EndTooltip(); + } + } + + // Adds a "?" next to the previous ImGui item with a custom tooltip + void InsertHelpHoverText(const std::string& text) { + ImGui::SameLine(); + ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?"); + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("%s", WrappedText(text, 60)); + ImGui::EndTooltip(); + } + } + + void InsertHelpHoverText(const char* text) { + ImGui::SameLine(); + ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "?"); + if (ImGui::IsItemHovered()) { + ImGui::BeginTooltip(); + ImGui::Text("%s", WrappedText(text, 60)); + ImGui::EndTooltip(); + } + } + + + // MARK: - UI Elements + + void Tooltip(const char* text) { + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("%s", WrappedText(text)); + } + } + + void Spacer(float height) { + ImGui::Dummy(ImVec2(0.0f, height)); + } + + void PaddedSeparator(bool padTop, bool padBottom, float extraVerticalTopPadding, float extraVerticalBottomPadding) { + if (padTop) { + Spacer(extraVerticalTopPadding); + } + ImGui::Separator(); + if (padBottom) { + Spacer(extraVerticalBottomPadding); + } + } + + void RenderCross(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz) { + float thickness = ImMax(sz / 5.0f, 1.0f); + sz -= thickness * 0.5f; + pos += ImVec2(thickness * 0.25f, thickness * 0.25f); + + draw_list->PathLineTo(ImVec2(pos.x, pos.y)); + draw_list->PathLineTo(ImVec2(pos.x + sz, pos.y + sz)); + draw_list->PathStroke(col, 0, thickness); + + draw_list->PathLineTo(ImVec2(pos.x + sz, pos.y)); + draw_list->PathLineTo(ImVec2(pos.x, pos.y + sz)); + draw_list->PathStroke(col, 0, thickness); + } + + bool CustomCheckbox(const char* label, bool* v, bool disabled, CheckboxGraphics disabledGraphic) { + ImGuiWindow* window = ImGui::GetCurrentWindow(); + if (window->SkipItems) { + return false; + } + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); + + const float square_sz = ImGui::GetFrameHeight(); + const ImVec2 pos = window->DC.CursorPos; + const ImRect total_bb(pos, pos + ImVec2(square_sz + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), label_size.y + style.FramePadding.y * 2.0f)); + ImGui::ItemSize(total_bb, style.FramePadding.y); + if (!ImGui::ItemAdd(total_bb, id)) { + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0)); + return false; + } + + bool hovered, held; + bool pressed = ImGui::ButtonBehavior(total_bb, id, &hovered, &held); + if (pressed) { + *v = !(*v); + ImGui::MarkItemEdited(id); + } + + const ImRect check_bb(pos, pos + ImVec2(square_sz, square_sz)); + ImGui::RenderNavHighlight(total_bb, id); + ImGui::RenderFrame(check_bb.Min, check_bb.Max, ImGui::GetColorU32((held && hovered) ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg), true, style.FrameRounding); + ImU32 check_col = ImGui::GetColorU32(ImGuiCol_CheckMark); + ImU32 cross_col = ImGui::GetColorU32(ImVec4(0.50f, 0.50f, 0.50f, 1.00f)); + bool mixed_value = (g.LastItemData.InFlags & ImGuiItemFlags_MixedValue) != 0; + if (mixed_value) { + // Undocumented tristate/mixed/indeterminate checkbox (#2644) + // This may seem awkwardly designed because the aim is to make ImGuiItemFlags_MixedValue supported by all widgets (not just checkbox) + ImVec2 pad(ImMax(1.0f, IM_FLOOR(square_sz / 3.6f)), ImMax(1.0f, IM_FLOOR(square_sz / 3.6f))); + window->DrawList->AddRectFilled(check_bb.Min + pad, check_bb.Max - pad, check_col, style.FrameRounding); + } else if ((!disabled && *v) || (disabled && disabledGraphic == CheckboxGraphics::Checkmark)) { + const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); + ImGui::RenderCheckMark(window->DrawList, check_bb.Min + ImVec2(pad, pad), check_col, square_sz - pad * 2.0f); + } else if (disabled && disabledGraphic == CheckboxGraphics::Cross) { + const float pad = ImMax(1.0f, IM_FLOOR(square_sz / 6.0f)); + RenderCross(window->DrawList, check_bb.Min + ImVec2(pad, pad), cross_col, square_sz - pad * 2.0f); + } + + ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y); + if (g.LogEnabled) { + ImGui::LogRenderedText(&label_pos, mixed_value ? "[~]" : *v ? "[x]" : "[ ]"); + } + if (label_size.x > 0.0f) { + ImGui::RenderText(label_pos, label); + } + + IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0)); + return pressed; + } + + void ReEnableComponent(const char* disabledTooltipText) { + // End of disable region of previous component + ImGui::PopStyleVar(1); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && strcmp(disabledTooltipText, "") != 0) { + ImGui::SetTooltip("%s", disabledTooltipText); + } + ImGui::PopItemFlag(); + } + + void DisableComponent(const float alpha) { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha); + } + + bool EnhancementCheckbox(const char* text, const char* cvarName, bool disabled, const char* disabledTooltipText, CheckboxGraphics disabledGraphic, bool defaultValue) { + bool changed = false; + if (disabled) { + DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + + bool val = (bool)CVarGetInteger(cvarName, defaultValue); + if (CustomCheckbox(text, &val, disabled, disabledGraphic)) { + CVarSetInteger(cvarName, val); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + changed = true; + } + + if (disabled) { + ReEnableComponent(disabledTooltipText); + } + return changed; + } + + bool PaddedEnhancementCheckbox(const char* text, const char* cvarName, bool padTop, bool padBottom, bool disabled, const char* disabledTooltipText, CheckboxGraphics disabledGraphic, bool defaultValue) { + ImGui::BeginGroup(); + if (padTop) Spacer(0); + + bool changed = EnhancementCheckbox(text, cvarName, disabled, disabledTooltipText, disabledGraphic, defaultValue); + + if (padBottom) Spacer(0); + ImGui::EndGroup(); + return changed; + } + + bool EnhancementCombobox(const char* cvarName, std::span comboArray, uint8_t defaultIndex, bool disabled, const char* disabledTooltipText, uint8_t disabledValue) { + bool changed = false; + if (defaultIndex <= 0) { + defaultIndex = 0; + } + + if (disabled) { + DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + + uint8_t selected = CVarGetInteger(cvarName, defaultIndex); + std::string comboName = std::string("##") + std::string(cvarName); + if (ImGui::BeginCombo(comboName.c_str(), comboArray[selected])) { + for (uint8_t i = 0; i < comboArray.size(); i++) { + if (strlen(comboArray[i]) > 0) { + if (ImGui::Selectable(comboArray[i], i == selected)) { + CVarSetInteger(cvarName, i); + selected = i; + changed = true; + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + } + } + } + ImGui::EndCombo(); + } + + if (disabled) { + ReEnableComponent(disabledTooltipText); + + if (disabledValue >= 0 && selected != disabledValue) { + CVarSetInteger(cvarName, disabledValue); + changed = true; + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + } + } + + return changed; + } + + bool LabeledRightAlignedEnhancementCombobox(const char* label, const char* cvarName, std::span comboArray, uint8_t defaultIndex, bool disabled, const char* disabledTooltipText, uint8_t disabledValue) { + ImGui::Text("%s", label); + s32 currentValue = CVarGetInteger(cvarName, defaultIndex); + +#ifdef __WIIU__ + ImGui::SameLine(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize(comboArray[currentValue]).x + 40.0f)); + ImGui::PushItemWidth(ImGui::CalcTextSize(comboArray[currentValue]).x + 60.0f); +#else + ImGui::SameLine(ImGui::GetContentRegionAvail().x - (ImGui::CalcTextSize(comboArray[currentValue]).x + 20.0f)); + ImGui::PushItemWidth(ImGui::CalcTextSize(comboArray[currentValue]).x + 30.0f); +#endif + + bool changed = EnhancementCombobox(cvarName, comboArray, defaultIndex, disabled, disabledTooltipText, disabledValue); + + ImGui::PopItemWidth(); + return changed; + } + + void PaddedText(const char* text, bool padTop, bool padBottom) { + if (padTop) Spacer(0); + + ImGui::Text("%s", text); + + if (padBottom) Spacer(0); + } + + bool EnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue, bool PlusMinusButton, bool disabled, const char* disabledTooltipText) { + bool changed = false; + int val = CVarGetInteger(cvarName, defaultValue); + + if (disabled) { + DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + + ImGui::Text(text, val); + Spacer(0); + + ImGui::BeginGroup(); + if (PlusMinusButton) { + std::string MinusBTNName = " - ##" + std::string(cvarName); + if (ImGui::Button(MinusBTNName.c_str())) { + val--; + changed = true; + } + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + } + + ImGui::PushItemWidth(std::min((ImGui::GetContentRegionAvail().x - (PlusMinusButton ? sliderButtonWidth : 0.0f)), maxSliderWidth)); + if (ImGui::SliderInt(id, &val, min, max, format, ImGuiSliderFlags_AlwaysClamp)) + { + changed = true; + } + ImGui::PopItemWidth(); + + if (PlusMinusButton) { + std::string PlusBTNName = " + ##" + std::string(cvarName); + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + if (ImGui::Button(PlusBTNName.c_str())) { + val++; + changed = true; + } + } + ImGui::EndGroup(); + + if (disabled) { + ReEnableComponent(disabledTooltipText); + } + + if (val < min) { + val = min; + changed = true; + } + + if (val > max) { + val = max; + changed = true; + } + + if (changed) { + CVarSetInteger(cvarName, val); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + } + + return changed; + } + + bool EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton, bool disabled, const char* disabledTooltipText) { + bool changed = false; + float val = CVarGetFloat(cvarName, defaultValue); + + if (disabled) { + DisableComponent(ImGui::GetStyle().Alpha * 0.5f); + } + + if (!isPercentage) { + ImGui::Text(text, val); + } else { + ImGui::Text(text, static_cast(100 * val)); + } + Spacer(0); + + ImGui::BeginGroup(); + if (PlusMinusButton) { + std::string MinusBTNName = " - ##" + std::string(cvarName); + if (ImGui::Button(MinusBTNName.c_str())) { + if (isPercentage) { + val -= 0.01f; + } else { + val -= 0.1f; + } + changed = true; + } + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + } + + ImGui::PushItemWidth(std::min((ImGui::GetContentRegionAvail().x - (PlusMinusButton ? sliderButtonWidth : 0.0f)), maxSliderWidth)); + if (ImGui::SliderFloat(id, &val, min, max, format, ImGuiSliderFlags_AlwaysClamp)) { + if (isPercentage) { + val = roundf(val * 100) / 100; + } + changed = true; + } + ImGui::PopItemWidth(); + + if (PlusMinusButton) { + std::string PlusBTNName = " + ##" + std::string(cvarName); + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + if (ImGui::Button(PlusBTNName.c_str())) { + if (isPercentage) { + val += 0.01f; + } else { + val += 0.1f; + } + changed = true; + } + } + ImGui::EndGroup(); + + if (disabled) { + ReEnableComponent(disabledTooltipText); + } + + if (val < min) { + val = min; + changed = true; + } + + if (val > max) { + val = max; + changed = true; + } + + if (changed) { + CVarSetFloat(cvarName, val); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + } + + return changed; + } + + bool PaddedEnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue, bool PlusMinusButton, bool padTop, bool padBottom, bool disabled, const char* disabledTooltipText) { + bool changed = false; + ImGui::BeginGroup(); + if (padTop) Spacer(0); + + changed = EnhancementSliderInt(text, id, cvarName, min, max, format, defaultValue, PlusMinusButton, disabled, disabledTooltipText); + + if (padBottom) Spacer(0); + ImGui::EndGroup(); + return changed; + } + + bool PaddedEnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton, bool padTop, bool padBottom, bool disabled, const char* disabledTooltipText) { + bool changed = false; + ImGui::BeginGroup(); + if (padTop) Spacer(0); + + changed = EnhancementSliderFloat(text, id, cvarName, min, max, format, defaultValue, isPercentage, PlusMinusButton, disabled, disabledTooltipText); + + if (padBottom) Spacer(0); + ImGui::EndGroup(); + return changed; + } + + bool EnhancementRadioButton(const char* text, const char* cvarName, int id) { + /*Usage : + EnhancementRadioButton("My Visible Name","gMyCVarName", MyID); + First arg is the visible name of the Radio button + Second is the cvar name where MyID will be saved. + Note: the CVar name should be the same to each Buddies. + Example : + EnhancementRadioButton("English", "gLanguages", LANGUAGE_ENG); + EnhancementRadioButton("German", "gLanguages", LANGUAGE_GER); + EnhancementRadioButton("French", "gLanguages", LANGUAGE_FRA); + */ + std::string make_invisible = "##" + std::string(text) + std::string(cvarName); + + bool ret = false; + int val = CVarGetInteger(cvarName, 0); + if (ImGui::RadioButton(make_invisible.c_str(), id == val)) { + CVarSetInteger(cvarName, id); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + ret = true; + } + ImGui::SameLine(); + ImGui::Text("%s", text); + + return ret; + } + + bool DrawResetColorButton(const char* cvarName, ImVec4* colors, ImVec4 defaultcolors, bool has_alpha) { + bool changed = false; + std::string Cvar_RBM = std::string(cvarName) + "RBM"; + std::string MakeInvisible = "Reset##" + std::string(cvarName) + "Reset"; + if (ImGui::Button(MakeInvisible.c_str())) { + colors->x = defaultcolors.x; + colors->y = defaultcolors.y; + colors->z = defaultcolors.z; + colors->w = has_alpha ? defaultcolors.w : 255.0f; + + Color_RGBA8 colorsRGBA; + colorsRGBA.r = defaultcolors.x; + colorsRGBA.g = defaultcolors.y; + colorsRGBA.b = defaultcolors.z; + colorsRGBA.a = has_alpha ? defaultcolors.w : 255.0f; + + CVarSetColor(cvarName, colorsRGBA); + CVarSetInteger(Cvar_RBM.c_str(), 0); //On click disable rainbow mode. + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + changed = true; + } + Tooltip("Revert colors to the game's original colors (GameCube version)\nOverwrites previously chosen color"); + return changed; + } + + bool DrawRandomizeColorButton(const char* cvarName, ImVec4* colors) { + return false; + } + + void DrawLockColorCheckbox(const char* cvarName) { + std::string Cvar_Lock = std::string(cvarName) + "Lock"; + s32 lock = CVarGetInteger(Cvar_Lock.c_str(), 0); + std::string FullName = "Lock##" + Cvar_Lock; + EnhancementCheckbox(FullName.c_str(), Cvar_Lock.c_str()); + Tooltip("Prevents this color from being changed upon selecting \"Randomize all\""); + } + + void RainbowColor(const char* cvarName, ImVec4* colors) { + std::string Cvar_RBM = std::string(cvarName) + "RBM"; + std::string MakeInvisible = "Rainbow##" + std::string(cvarName) + "Rainbow"; + + EnhancementCheckbox(MakeInvisible.c_str(), Cvar_RBM.c_str()); + Tooltip("Cycles through colors on a timer\nOverwrites previously chosen color"); + } + + void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha) { + Color_RGBA8 defaultColors; + defaultColors.r = default_colors.x; + defaultColors.g = default_colors.y; + defaultColors.b = default_colors.z; + defaultColors.a = default_colors.w; + + Color_RGBA8 cvarColor = CVarGetColor(cvarname, defaultColors); + + ColorArray.x = cvarColor.r / 255.0; + ColorArray.y = cvarColor.g / 255.0; + ColorArray.z = cvarColor.b / 255.0; + ColorArray.w = cvarColor.a / 255.0; + } + + bool EnhancementColor(const char* text, const char* cvarName, ImVec4 ColorRGBA, ImVec4 default_colors, bool allow_rainbow, bool has_alpha, bool TitleSameLine) { + bool changed = false; + LoadPickersColors(ColorRGBA, cvarName, default_colors, has_alpha); + + ImGuiColorEditFlags flags = ImGuiColorEditFlags_None; + + if (!TitleSameLine) { + ImGui::Text("%s", text); + flags = ImGuiColorEditFlags_NoLabel; + } + + ImGui::PushID(cvarName); + + if (!has_alpha) { + if (ImGui::ColorEdit3(text, (float*)&ColorRGBA, flags)) + { + Color_RGBA8 colors; + colors.r = ColorRGBA.x * 255.0; + colors.g = ColorRGBA.y * 255.0; + colors.b = ColorRGBA.z * 255.0; + colors.a = 255.0; + + CVarSetColor(cvarName, colors); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + changed = true; + } + } + else + { + flags |= ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreview; + if (ImGui::ColorEdit4(text, (float*)&ColorRGBA, flags)) + { + Color_RGBA8 colors; + colors.r = ColorRGBA.x * 255.0; + colors.g = ColorRGBA.y * 255.0; + colors.b = ColorRGBA.z * 255.0; + colors.a = ColorRGBA.w * 255.0; + + CVarSetColor(cvarName, colors); + LUS::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick(); + changed = true; + } + } + + ImGui::PopID(); + + //ImGui::SameLine(); // Removing that one to gain some width spacing on the HUD editor + ImGui::PushItemWidth(-FLT_MIN); + if (DrawResetColorButton(cvarName, &ColorRGBA, default_colors, has_alpha)) { + changed = true; + } + ImGui::SameLine(); + if (DrawRandomizeColorButton(cvarName, &ColorRGBA)) { + changed = true; + } + if (allow_rainbow) { + if (ImGui::GetContentRegionAvail().x > 185) { + ImGui::SameLine(); + } + RainbowColor(cvarName, &ColorRGBA); + } + DrawLockColorCheckbox(cvarName); + ImGui::NewLine(); + ImGui::PopItemWidth(); + + return changed; + } + + void DrawFlagArray32(const std::string& name, uint32_t& flags) { + ImGui::PushID(name.c_str()); + for (int32_t flagIndex = 0; flagIndex < 32; flagIndex++) { + if ((flagIndex % 8) != 0) { + ImGui::SameLine(); + } + ImGui::PushID(flagIndex); + uint32_t bitMask = 1 << flagIndex; + bool flag = (flags & bitMask) != 0; + if (ImGui::Checkbox("##check", &flag)) { + if (flag) { + flags |= bitMask; + } else { + flags &= ~bitMask; + } + } + ImGui::PopID(); + } + ImGui::PopID(); + } + + void DrawFlagArray16(const std::string& name, uint16_t& flags) { + ImGui::PushID(name.c_str()); + for (int16_t flagIndex = 0; flagIndex < 16; flagIndex++) { + if ((flagIndex % 8) != 0) { + ImGui::SameLine(); + } + ImGui::PushID(flagIndex); + uint16_t bitMask = 1 << flagIndex; + bool flag = (flags & bitMask) != 0; + if (ImGui::Checkbox("##check", &flag)) { + if (flag) { + flags |= bitMask; + } else { + flags &= ~bitMask; + } + } + ImGui::PopID(); + } + ImGui::PopID(); + } + + void DrawFlagArray8(const std::string& name, uint8_t& flags) { + ImGui::PushID(name.c_str()); + for (int8_t flagIndex = 0; flagIndex < 8; flagIndex++) { + if ((flagIndex % 8) != 0) { + ImGui::SameLine(); + } + ImGui::PushID(flagIndex); + uint8_t bitMask = 1 << flagIndex; + bool flag = (flags & bitMask) != 0; + if (ImGui::Checkbox("##check", &flag)) { + if (flag) { + flags |= bitMask; + } else { + flags &= ~bitMask; + } + } + ImGui::PopID(); + } + ImGui::PopID(); + } + + bool StateButtonEx(const char* str_id, const char* label, ImVec2 size, ImGuiButtonFlags flags) { + ImGuiContext& g = *GImGui; + ImGuiWindow* window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + const ImGuiStyle& style = g.Style; + const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); + + const ImGuiID id = window->GetID(str_id); + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + const float default_size = ImGui::GetFrameHeight(); + ImGui::ItemSize(size, (size.y >= default_size) ? g.Style.FramePadding.y : -1.0f); + if (!ImGui::ItemAdd(bb, id)) + return false; + + if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat) + flags |= ImGuiButtonFlags_Repeat; + + bool hovered, held; + bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags); + + // Render + const ImU32 bg_col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive + : hovered ? ImGuiCol_ButtonHovered + : ImGuiCol_Button); + //const ImU32 text_col = ImGui::GetColorU32(ImGuiCol_Text); + ImGui::RenderNavHighlight(bb, id); + ImGui::RenderFrame(bb.Min, bb.Max, bg_col, true, g.Style.FrameRounding); + ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, {0.55f, 0.45f}, &bb); + /*ImGui::RenderArrow(window->DrawList, + bb.Min + + ImVec2(ImMax(0.0f, (size.x - g.FontSize) * 0.5f), ImMax(0.0f, (size.y - g.FontSize) * 0.5f)), + text_col, dir);*/ + + IMGUI_TEST_ENGINE_ITEM_INFO(id, str_id, g.LastItemData.StatusFlags); + return pressed; + } + + bool StateButton(const char* str_id, const char* label) { + float sz = ImGui::GetFrameHeight(); + return StateButtonEx(str_id, label, ImVec2(sz, sz), ImGuiButtonFlags_None); + } +} diff --git a/mm/2s2h/UIWidgets.hpp b/mm/2s2h/UIWidgets.hpp new file mode 100644 index 000000000..b18487977 --- /dev/null +++ b/mm/2s2h/UIWidgets.hpp @@ -0,0 +1,101 @@ +// +// UIWidgets.hpp +// soh +// +// Created by David Chavez on 25.08.22. +// + +#ifndef UIWidgets_hpp +#define UIWidgets_hpp + +#include +#include +#include +#include +#include + +namespace UIWidgets { + + struct TextFilters { + static int FilterNumbers(ImGuiInputTextCallbackData* data) { + if (data->EventChar < 256 && strchr("1234567890", (char)data->EventChar)) { + return 0; + } + return 1; + } + + static int FilterAlphaNum(ImGuiInputTextCallbackData* data) { + const char* alphanum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ0123456789"; + if (data->EventChar < 256 && strchr(alphanum, (char)data->EventChar)) { + return 0; + } + return 1; + } + + }; + + // MARK: - Enums + + enum class CheckboxGraphics { + Cross, + Checkmark, + None + }; + constexpr float maxSliderWidth = 260.0f; +#ifdef __SWITCH__ + constexpr float sliderButtonWidth = 42.0f; +#elif defined(__WIIU__) + constexpr float sliderButtonWidth = 60.0f; +#else + constexpr float sliderButtonWidth = 30.0f; +#endif + + char* WrappedText(const char* text, unsigned int charactersPerLine = 60); + char* WrappedText(const std::string& text, unsigned int charactersPerLine); + + void SetLastItemHoverText(const std::string& text); + void SetLastItemHoverText(const char* text); + + void InsertHelpHoverText(const std::string& text); + void InsertHelpHoverText(const char* text); + + void Tooltip(const char* text); + void Spacer(float height); + void PaddedSeparator(bool padTop = true, bool padBottom = true, float extraVerticalTopPadding = 0.0f, float extraVerticalBottomPadding = 0.0f); + + void RenderCross(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); + bool CustomCheckbox(const char* label, bool* v, bool disabled, CheckboxGraphics disabledGraphic); + + void ReEnableComponent(const char* disabledTooltipText); + void DisableComponent(const float alpha); + + bool EnhancementCheckbox(const char* text, const char* cvarName, bool disabled = false, const char* disabledTooltipText = "", CheckboxGraphics disabledGraphic = CheckboxGraphics::Cross, bool defaultValue = false); + bool PaddedEnhancementCheckbox(const char* text, const char* cvarName, bool padTop = true, bool padBottom = true, bool disabled = false, const char* disabledTooltipText = "", CheckboxGraphics disabledGraphic = CheckboxGraphics::Cross, bool defaultValue = false); + + bool EnhancementCombobox(const char* cvarName, std::span comboArray, uint8_t defaultIndex, bool disabled = false, const char* disabledTooltipText = "", uint8_t disabledValue = -1); + bool LabeledRightAlignedEnhancementCombobox(const char* label, const char* cvarName, std::span comboArray, uint8_t defaultIndex, bool disabled = false, const char* disabledTooltipText = "", uint8_t disabledValue = -1); + + void PaddedText(const char* text, bool padTop = true, bool padBottom = true); + + bool EnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue = 0, bool PlusMinusButton = true, bool disabled = false, const char* disabledTooltipText = ""); + bool PaddedEnhancementSliderInt(const char* text, const char* id, const char* cvarName, int min, int max, const char* format, int defaultValue = 0, bool PlusMinusButton = true, bool padTop = true, bool padBottom = true, bool disabled = false, const char* disabledTooltipText = ""); + bool EnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton = true, bool disabled = false, const char* disabledTooltipText = ""); + bool PaddedEnhancementSliderFloat(const char* text, const char* id, const char* cvarName, float min, float max, const char* format, float defaultValue, bool isPercentage, bool PlusMinusButton = true, bool padTop = true, bool padBottom = true, bool disabled = false, const char* disabledTooltipText = ""); + + bool EnhancementRadioButton(const char* text, const char* cvarName, int id); + + bool DrawResetColorButton(const char* cvarName, ImVec4* colors, ImVec4 defaultcolors, bool has_alpha); + bool DrawRandomizeColorButton(const char* cvarName, ImVec4* colors); + void DrawLockColorCheckbox(const char* cvarName); + void RainbowColor(const char* cvarName, ImVec4* colors); + + void LoadPickersColors(ImVec4& ColorArray, const char* cvarname, const ImVec4& default_colors, bool has_alpha); + bool EnhancementColor(const char* text, const char* cvarName, ImVec4 ColorRGBA, ImVec4 default_colors, bool allow_rainbow = true, bool has_alpha = false, bool TitleSameLine = false); + + void DrawFlagArray32(const std::string& name, uint32_t& flags); + void DrawFlagArray16(const std::string& name, uint16_t& flags); + void DrawFlagArray8(const std::string& name, uint8_t& flags); + bool StateButton(const char* str_id, const char* label); +} + +#endif /* UIWidgets_hpp */ diff --git a/mm/2s2h/gu_pc.c b/mm/2s2h/gu_pc.c new file mode 100644 index 000000000..be1954a5d --- /dev/null +++ b/mm/2s2h/gu_pc.c @@ -0,0 +1,88 @@ +#include +#include "z64.h" + +void guMtxF2L(float mf[4][4], Mtx* m) { + unsigned 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) { + unsigned 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; + } + } +} + +void guMtxIdentF(f32 mf[4][4]) { + unsigned int r, c; + for (r = 0; r < 4; r++) { + for (c = 0; c < 4; c++) { + if (r == c) { + mf[r][c] = 1.0f; + } else { + mf[r][c] = 0.0f; + } + } + } +} + +void guMtxIdent(Mtx* m) { + guMtxIdentF(m->m); +} + +void guTranslateF(float m[4][4], float x, float y, float z) { + guMtxIdentF(m); + m[3][0] = x; + m[3][1] = y; + m[3][2] = z; +} +void guTranslate(Mtx* m, float x, float y, float z) { + float mf[4][4]; + guTranslateF(mf, x, y, z); + guMtxF2L(mf, m); +} + +void guScaleF(float mf[4][4], float x, float y, float z) { + guMtxIdentF(mf); + mf[0][0] = x; + mf[1][1] = y; + mf[2][2] = z; + mf[3][3] = 1.0; +} +void guScale(Mtx* m, float x, float y, float z) { + float mf[4][4]; + guScaleF(mf, x, y, z); + guMtxF2L(mf, m); +} + +void guNormalize(f32* x, f32* y, f32* z) { + f32 tmp = 1.0f / sqrtf(*x * *x + *y * *y + *z * *z); + *x = *x * tmp; + *y = *y * tmp; + *z = *z * tmp; +} diff --git a/mm/2s2h/resource/importer/AnimationFactory.cpp b/mm/2s2h/resource/importer/AnimationFactory.cpp new file mode 100644 index 000000000..c177c8ea9 --- /dev/null +++ b/mm/2s2h/resource/importer/AnimationFactory.cpp @@ -0,0 +1,108 @@ +#include "2s2h/resource/importer/AnimationFactory.h" +#include "2s2h/resource/type/Animation.h" +#include "2s2h/resource/importer/PlayerAnimationFactory.h" +#include +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +AnimationFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Animation with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::AnimationFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { + std::shared_ptr animation = std::static_pointer_cast(resource); + + ResourceVersionFactory::ParseFileBinary(reader, animation); + + AnimationType animType = (AnimationType)reader->ReadUInt32(); + animation->type = animType; + + if (animType == AnimationType::Normal) { + // Set frame count + animation->animationData.animationHeader.common.frameCount = reader->ReadInt16(); + + // Populate frame data + uint32_t rotValuesCnt = reader->ReadUInt32(); + animation->rotationValues.reserve(rotValuesCnt); + for (uint32_t i = 0; i < rotValuesCnt; i++) { + animation->rotationValues.push_back(reader->ReadUInt16()); + } + animation->animationData.animationHeader.frameData = (int16_t*)animation->rotationValues.data(); + + // Populate joint indices + uint32_t rotIndCnt = reader->ReadUInt32(); + animation->rotationIndices.reserve(rotIndCnt); + for (size_t i = 0; i < rotIndCnt; i++) { + uint16_t x = reader->ReadUInt16(); + uint16_t y = reader->ReadUInt16(); + uint16_t z = reader->ReadUInt16(); + animation->rotationIndices.push_back(RotationIndex(x, y, z)); + } + animation->animationData.animationHeader.jointIndices = (JointIndex*)animation->rotationIndices.data(); + + // Set static index max + animation->animationData.animationHeader.staticIndexMax = reader->ReadInt16(); + } else if (animType == AnimationType::Curve) { + // Read frame count (unused in this animation type) + reader->ReadInt16(); + + // Set refIndex + uint32_t refArrCnt = reader->ReadUInt32(); + animation->refIndexArr.reserve(refArrCnt); + for (uint32_t i = 0; i < refArrCnt; i++) { + animation->refIndexArr.push_back(reader->ReadUByte()); + } + animation->animationData.transformUpdateIndex.refIndex = animation->refIndexArr.data(); + + // Populate transform data + uint32_t transformDataCnt = reader->ReadUInt32(); + animation->transformDataArr.reserve(transformDataCnt); + for (uint32_t i = 0; i < transformDataCnt; i++) { + TransformData data; + data.unk_00 = reader->ReadUInt16(); + data.unk_02 = reader->ReadInt16(); + data.unk_04 = reader->ReadInt16(); + data.unk_06 = reader->ReadInt16(); + data.unk_08 = reader->ReadFloat(); + + animation->transformDataArr.push_back(data); + } + animation->animationData.transformUpdateIndex.transformData = animation->transformDataArr.data(); + + // Populate copy values + uint32_t copyValuesCnt = reader->ReadUInt32(); + animation->copyValuesArr.reserve(copyValuesCnt); + for (uint32_t i = 0; i < copyValuesCnt; i++) { + animation->copyValuesArr.push_back(reader->ReadInt16()); + } + animation->animationData.transformUpdateIndex.copyValues = animation->copyValuesArr.data(); + } else if (animType == AnimationType::Link) { + // Read the frame count + animation->animationData.linkAnimationHeader.common.frameCount = reader->ReadInt16(); + + // Read the segment pointer (always 32 bit, doesn't adjust for system pointer size) + std::string path = reader->ReadString(); + + animation->animationData.linkAnimationHeader.segment = ResourceGetDataByName(path.c_str()); + } else if (animType == AnimationType::Legacy) { + SPDLOG_DEBUG("BEYTAH ANIMATION?!"); + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/AnimationFactory.h b/mm/2s2h/resource/importer/AnimationFactory.h new file mode 100644 index 000000000..dee2026f9 --- /dev/null +++ b/mm/2s2h/resource/importer/AnimationFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class AnimationFactory : public ResourceFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class AnimationFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/AudioSampleFactory.cpp b/mm/2s2h/resource/importer/AudioSampleFactory.cpp new file mode 100644 index 000000000..73c5af484 --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSampleFactory.cpp @@ -0,0 +1,141 @@ +#include "2s2h/resource/importer/AudioSampleFactory.h" +#include "2s2h/resource/type/AudioSample.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +AudioSampleFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 2: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load AudioSample with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::AudioSampleFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr audioSample = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, audioSample); + + audioSample->sample.codec = reader->ReadUByte(); + audioSample->sample.medium = reader->ReadUByte(); + audioSample->sample.unk_bit26 = reader->ReadUByte(); + audioSample->sample.unk_bit25 = reader->ReadUByte(); + audioSample->sample.size = reader->ReadUInt32(); + + audioSample->audioSampleData.reserve(audioSample->sample.size); + for (uint32_t i = 0; i < audioSample->sample.size; i++) { + audioSample->audioSampleData.push_back(reader->ReadUByte()); + } + audioSample->sample.sampleAddr = audioSample->audioSampleData.data(); + + audioSample->loop.start = reader->ReadUInt32(); + audioSample->loop.end = reader->ReadUInt32(); + audioSample->loop.count = reader->ReadUInt32(); + + audioSample->loopStateCount = reader->ReadUInt32(); + for (int i = 0; i < 16; i++) { + audioSample->loop.state[i] = 0; + } + for (uint32_t i = 0; i < audioSample->loopStateCount; i++) { + audioSample->loop.state[i] = reader->ReadInt16(); + } + audioSample->sample.loop = &audioSample->loop; + + audioSample->book.order = reader->ReadInt32(); + audioSample->book.npredictors = reader->ReadInt32(); + audioSample->bookDataCount = reader->ReadUInt32(); + + audioSample->bookData.reserve(audioSample->bookDataCount); + for (uint32_t i = 0; i < audioSample->bookDataCount; i++) { + audioSample->bookData.push_back(reader->ReadInt16()); + } + audioSample->book.book = audioSample->bookData.data(); + audioSample->sample.book = &audioSample->book; +} +} // namespace LUS + + +/* +in ResourceMgr_LoadAudioSample we used to have +-------------- + if (cachedCustomSFs.find(path) != cachedCustomSFs.end()) + return cachedCustomSFs[path]; + + SoundFontSample* cSample = ReadCustomSample(path); + + if (cSample != nullptr) + return cSample; +-------------- +before the rest of the standard sample reading, this is the ReadCustomSample code we used to have + +extern "C" SoundFontSample* ReadCustomSample(const char* path) { + + if (!ExtensionCache.contains(path)) + return nullptr; + + ExtensionEntry entry = ExtensionCache[path]; + + auto sampleRaw = LUS::Context::GetInstance()->GetResourceManager()->LoadFile(entry.path); + uint32_t* strem = (uint32_t*)sampleRaw->Buffer.get(); + uint8_t* strem2 = (uint8_t*)strem; + + SoundFontSample* sampleC = new SoundFontSample; + + if (entry.ext == "wav") { + drwav_uint32 channels; + drwav_uint32 sampleRate; + drwav_uint64 totalPcm; + drmp3_int16* pcmData = + drwav_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &channels, &sampleRate, &totalPcm, NULL); + sampleC->size = totalPcm; + sampleC->sampleAddr = (uint8_t*)pcmData; + sampleC->codec = CODEC_S16; + + sampleC->loop = new AdpcmLoop; + sampleC->loop->start = 0; + sampleC->loop->end = sampleC->size - 1; + sampleC->loop->count = 0; + sampleC->sampleRateMagicValue = 'RIFF'; + sampleC->sampleRate = sampleRate; + + cachedCustomSFs[path] = sampleC; + return sampleC; + } else if (entry.ext == "mp3") { + drmp3_config mp3Info; + drmp3_uint64 totalPcm; + drmp3_int16* pcmData = + drmp3_open_memory_and_read_pcm_frames_s16(strem2, sampleRaw->BufferSize, &mp3Info, &totalPcm, NULL); + + sampleC->size = totalPcm * mp3Info.channels * sizeof(short); + sampleC->sampleAddr = (uint8_t*)pcmData; + sampleC->codec = CODEC_S16; + + sampleC->loop = new AdpcmLoop; + sampleC->loop->start = 0; + sampleC->loop->end = sampleC->size; + sampleC->loop->count = 0; + sampleC->sampleRateMagicValue = 'RIFF'; + sampleC->sampleRate = mp3Info.sampleRate; + + cachedCustomSFs[path] = sampleC; + return sampleC; + } + + return nullptr; +} + +*/ diff --git a/mm/2s2h/resource/importer/AudioSampleFactory.h b/mm/2s2h/resource/importer/AudioSampleFactory.h new file mode 100644 index 000000000..6e9ddc17c --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSampleFactory.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class AudioSampleFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class AudioSampleFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/AudioSequenceFactory.cpp b/mm/2s2h/resource/importer/AudioSequenceFactory.cpp new file mode 100644 index 000000000..20c5df8a3 --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSequenceFactory.cpp @@ -0,0 +1,52 @@ +#include "2s2h/resource/importer/AudioSequenceFactory.h" +#include "2s2h/resource/type/AudioSequence.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +AudioSequenceFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 2: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load AudioSequence with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::AudioSequenceFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr audioSequence = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, audioSequence); + + audioSequence->sequence.seqDataSize = reader->ReadInt32(); + audioSequence->sequenceData.reserve(audioSequence->sequence.seqDataSize); + for (uint32_t i = 0; i < audioSequence->sequence.seqDataSize; i++) { + audioSequence->sequenceData.push_back(reader->ReadChar()); + } + audioSequence->sequence.seqData = audioSequence->sequenceData.data(); + + audioSequence->sequence.seqNumber = reader->ReadUByte(); + audioSequence->sequence.medium = reader->ReadUByte(); + audioSequence->sequence.cachePolicy = reader->ReadUByte(); + + audioSequence->sequence.numFonts = reader->ReadUInt32(); + for (uint32_t i = 0; i < 16; i++) { + audioSequence->sequence.fonts[i] = 0; + } + for (uint32_t i = 0; i < audioSequence->sequence.numFonts; i++) { + audioSequence->sequence.fonts[i] = reader->ReadUByte(); + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/AudioSequenceFactory.h b/mm/2s2h/resource/importer/AudioSequenceFactory.h new file mode 100644 index 000000000..12b3809aa --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSequenceFactory.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class AudioSequenceFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class AudioSequenceFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/AudioSoundFontFactory.cpp b/mm/2s2h/resource/importer/AudioSoundFontFactory.cpp new file mode 100644 index 000000000..4ccb7edad --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSoundFontFactory.cpp @@ -0,0 +1,190 @@ +#include "2s2h/resource/importer/AudioSoundFontFactory.h" +#include "2s2h/resource/type/AudioSoundFont.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultraship.h" + +namespace LUS { +std::shared_ptr +AudioSoundFontFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 2: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load AudioSoundFont with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::AudioSoundFontFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr audioSoundFont = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, audioSoundFont); + + audioSoundFont->soundFont.fntIndex = reader->ReadInt32(); + audioSoundFont->medium = reader->ReadInt8(); + audioSoundFont->cachePolicy = reader->ReadInt8(); + + audioSoundFont->data1 = reader->ReadUInt16(); + audioSoundFont->soundFont.sampleBankId1 = audioSoundFont->data1 >> 8; + audioSoundFont->soundFont.sampleBankId2 = audioSoundFont->data1 & 0xFF; + + audioSoundFont->data2 = reader->ReadUInt16(); + audioSoundFont->data3 = reader->ReadUInt16(); + + uint32_t drumCount = reader->ReadUInt32(); + audioSoundFont->soundFont.numDrums = drumCount; + + uint32_t instrumentCount = reader->ReadUInt32(); + audioSoundFont->soundFont.numInstruments = instrumentCount; + + uint32_t soundEffectCount = reader->ReadUInt32(); + audioSoundFont->soundFont.numSfx = soundEffectCount; + + // 🥁 DRUMS 🥁 + audioSoundFont->drums.reserve(audioSoundFont->soundFont.numDrums); + audioSoundFont->drumAddresses.reserve(audioSoundFont->soundFont.numDrums); + for (uint32_t i = 0; i < audioSoundFont->soundFont.numDrums; i++) { + Drum drum; + drum.releaseRate = reader->ReadUByte(); + drum.pan = reader->ReadUByte(); + drum.loaded = reader->ReadUByte(); + drum.loaded = 0; // this was always getting set to zero in ResourceMgr_LoadAudioSoundFont + + uint32_t envelopeCount = reader->ReadUInt32(); + audioSoundFont->drumEnvelopeCounts.push_back(envelopeCount); + std::vector drumEnvelopes; + drumEnvelopes.reserve(audioSoundFont->drumEnvelopeCounts[i]); + for (uint32_t j = 0; j < audioSoundFont->drumEnvelopeCounts.back(); j++) { + AdsrEnvelope env; + + int16_t delay = reader->ReadInt16(); + int16_t arg = reader->ReadInt16(); + + env.delay = BE16SWAP(delay); + env.arg = BE16SWAP(arg); + + drumEnvelopes.push_back(env); + } + audioSoundFont->drumEnvelopeArrays.push_back(drumEnvelopes); + drum.envelope = audioSoundFont->drumEnvelopeArrays.back().data(); + + bool hasSample = reader->ReadInt8(); + std::string sampleFileName = reader->ReadString(); + drum.sound.tuning = reader->ReadFloat(); + + if (sampleFileName.empty()) { + drum.sound.sample = nullptr; + } else { + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str()); + drum.sound.sample = static_cast(res ? res->GetRawPointer() : nullptr); + } + + audioSoundFont->drums.push_back(drum); + audioSoundFont->drumAddresses.push_back(&audioSoundFont->drums.back()); + } + audioSoundFont->soundFont.drums = audioSoundFont->drumAddresses.data(); + + // 🎺🎻🎷🎸🎹 INSTRUMENTS 🎹🎸🎷🎻🎺 + audioSoundFont->instruments.reserve(audioSoundFont->soundFont.numInstruments); + for (uint32_t i = 0; i < audioSoundFont->soundFont.numInstruments; i++) { + Instrument instrument; + + uint8_t isValidEntry = reader->ReadUByte(); + instrument.loaded = reader->ReadUByte(); + instrument.loaded = 0; // this was always getting set to zero in ResourceMgr_LoadAudioSoundFont + + instrument.normalRangeLo = reader->ReadUByte(); + instrument.normalRangeHi = reader->ReadUByte(); + instrument.releaseRate = reader->ReadUByte(); + + uint32_t envelopeCount = reader->ReadInt32(); + audioSoundFont->instrumentEnvelopeCounts.push_back(envelopeCount); + std::vector instrumentEnvelopes; + for (uint32_t j = 0; j < audioSoundFont->instrumentEnvelopeCounts.back(); j++) { + AdsrEnvelope env; + + int16_t delay = reader->ReadInt16(); + int16_t arg = reader->ReadInt16(); + + env.delay = BE16SWAP(delay); + env.arg = BE16SWAP(arg); + + instrumentEnvelopes.push_back(env); + } + audioSoundFont->instrumentEnvelopeArrays.push_back(instrumentEnvelopes); + instrument.envelope = audioSoundFont->instrumentEnvelopeArrays.back().data(); + + bool hasLowNoteSoundFontEntry = reader->ReadInt8(); + if (hasLowNoteSoundFontEntry) { + bool hasSampleRef = reader->ReadInt8(); + std::string sampleFileName = reader->ReadString(); + instrument.lowNotesSound.tuning = reader->ReadFloat(); + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str()); + instrument.lowNotesSound.sample = static_cast(res ? res->GetRawPointer() : nullptr); + } else { + instrument.lowNotesSound.sample = nullptr; + instrument.lowNotesSound.tuning = 0; + } + + bool hasNormalNoteSoundFontEntry = reader->ReadInt8(); + if (hasNormalNoteSoundFontEntry) { + bool hasSampleRef = reader->ReadInt8(); + std::string sampleFileName = reader->ReadString(); + instrument.normalNotesSound.tuning = reader->ReadFloat(); + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str()); + instrument.normalNotesSound.sample = static_cast(res ? res->GetRawPointer() : nullptr); + } else { + instrument.normalNotesSound.sample = nullptr; + instrument.normalNotesSound.tuning = 0; + } + + bool hasHighNoteSoundFontEntry = reader->ReadInt8(); + if (hasHighNoteSoundFontEntry) { + bool hasSampleRef = reader->ReadInt8(); + std::string sampleFileName = reader->ReadString(); + instrument.highNotesSound.tuning = reader->ReadFloat(); + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str()); + instrument.highNotesSound.sample = static_cast(res ? res->GetRawPointer() : nullptr); + } else { + instrument.highNotesSound.sample = nullptr; + instrument.highNotesSound.tuning = 0; + } + + + audioSoundFont->instruments.push_back(instrument); + audioSoundFont->instrumentAddresses.push_back(isValidEntry ? + &audioSoundFont->instruments.back() : + nullptr); + } + audioSoundFont->soundFont.instruments = audioSoundFont->instrumentAddresses.data(); + + // 🔊 SOUND EFFECTS 🔊 + audioSoundFont->soundEffects.reserve(audioSoundFont->soundFont.numSfx); + for (uint32_t i = 0; i < audioSoundFont->soundFont.numSfx; i++) { + SoundFontSound soundEffect; + + bool hasSFEntry = reader->ReadInt8(); + if (hasSFEntry) { + bool hasSampleRef = reader->ReadInt8(); + std::string sampleFileName = reader->ReadString(); + soundEffect.tuning = reader->ReadFloat(); + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(sampleFileName.c_str()); + soundEffect.sample = static_cast(res ? res->GetRawPointer() : nullptr); + } + + audioSoundFont->soundEffects.push_back(soundEffect); + } + audioSoundFont->soundFont.soundEffects = audioSoundFont->soundEffects.data(); +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/AudioSoundFontFactory.h b/mm/2s2h/resource/importer/AudioSoundFontFactory.h new file mode 100644 index 000000000..7dd5bc0d5 --- /dev/null +++ b/mm/2s2h/resource/importer/AudioSoundFontFactory.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class AudioSoundFontFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class AudioSoundFontFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/BackgroundFactory.cpp b/mm/2s2h/resource/importer/BackgroundFactory.cpp new file mode 100644 index 000000000..6acc7737c --- /dev/null +++ b/mm/2s2h/resource/importer/BackgroundFactory.cpp @@ -0,0 +1,39 @@ +#include "2s2h/resource/importer/BackgroundFactory.h" +#include "2s2h/resource/type/Background.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +BackgroundFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Background with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void BackgroundFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { + std::shared_ptr background = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, background); + + uint32_t dataSize = reader->ReadUInt32(); + + background->Data.reserve(dataSize); + + for (uint32_t i = 0; i < dataSize; i++) { + background->Data.push_back(reader->ReadUByte()); + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/BackgroundFactory.h b/mm/2s2h/resource/importer/BackgroundFactory.h new file mode 100644 index 000000000..9767fdf8b --- /dev/null +++ b/mm/2s2h/resource/importer/BackgroundFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "resource/Resource.h" +#include "resource/ResourceFactory.h" + +namespace LUS { +class BackgroundFactory : public ResourceFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class BackgroundFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/CollisionHeaderFactory.cpp b/mm/2s2h/resource/importer/CollisionHeaderFactory.cpp new file mode 100644 index 000000000..4b5b45f0d --- /dev/null +++ b/mm/2s2h/resource/importer/CollisionHeaderFactory.cpp @@ -0,0 +1,142 @@ +#include "2s2h/resource/importer/CollisionHeaderFactory.h" +#include "2s2h/resource/type/CollisionHeader.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +CollisionHeaderFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Collision Header with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::CollisionHeaderFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr collisionHeader = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, collisionHeader); + + collisionHeader->collisionHeaderData.minBounds.x = reader->ReadInt16(); + collisionHeader->collisionHeaderData.minBounds.y = reader->ReadInt16(); + collisionHeader->collisionHeaderData.minBounds.z = reader->ReadInt16(); + + collisionHeader->collisionHeaderData.maxBounds.x = reader->ReadInt16(); + collisionHeader->collisionHeaderData.maxBounds.y = reader->ReadInt16(); + collisionHeader->collisionHeaderData.maxBounds.z = reader->ReadInt16(); + + collisionHeader->collisionHeaderData.numVertices = reader->ReadInt32(); + collisionHeader->vertices.reserve(collisionHeader->collisionHeaderData.numVertices); + for (int32_t i = 0; i < collisionHeader->collisionHeaderData.numVertices; i++) { + Vec3s vtx; + vtx.x = reader->ReadInt16(); + vtx.y = reader->ReadInt16(); + vtx.z = reader->ReadInt16(); + collisionHeader->vertices.push_back(vtx); + } + collisionHeader->collisionHeaderData.vtxList = collisionHeader->vertices.data(); + + collisionHeader->collisionHeaderData.numPolygons = reader->ReadUInt32(); + collisionHeader->polygons.reserve(collisionHeader->collisionHeaderData.numPolygons); + for (uint32_t i = 0; i < collisionHeader->collisionHeaderData.numPolygons; i++) { + CollisionPoly polygon; + + polygon.type = reader->ReadUInt16(); + + polygon.flags_vIA = reader->ReadUInt16(); + polygon.flags_vIB = reader->ReadUInt16(); + polygon.vIC = reader->ReadUInt16(); + + polygon.normal.x = reader->ReadUInt16(); + polygon.normal.y = reader->ReadUInt16(); + polygon.normal.z = reader->ReadUInt16(); + + polygon.dist = reader->ReadUInt16(); + + collisionHeader->polygons.push_back(polygon); + + } + collisionHeader->collisionHeaderData.polyList = collisionHeader->polygons.data(); + + collisionHeader->surfaceTypesCount = reader->ReadUInt32(); + collisionHeader->surfaceTypes.reserve(collisionHeader->surfaceTypesCount); + for (uint32_t i = 0; i < collisionHeader->surfaceTypesCount; i++) { + SurfaceType surfaceType; + + surfaceType.data[1] = reader->ReadUInt32(); + surfaceType.data[0] = reader->ReadUInt32(); + + collisionHeader->surfaceTypes.push_back(surfaceType); + } + collisionHeader->collisionHeaderData.surfaceTypeList = collisionHeader->surfaceTypes.data(); + + collisionHeader->camDataCount = reader->ReadUInt32(); + collisionHeader->camData.reserve(collisionHeader->camDataCount); + collisionHeader->camPosDataIndices.reserve(collisionHeader->camDataCount); + for (uint32_t i = 0; i < collisionHeader->camDataCount; i++) { + CamData camDataEntry; + camDataEntry.cameraSType = reader->ReadUInt16(); + camDataEntry.numCameras = reader->ReadInt16(); + collisionHeader->camData.push_back(camDataEntry); + + int32_t camPosDataIdx = reader->ReadInt32(); + collisionHeader->camPosDataIndices.push_back(camPosDataIdx); + } + + collisionHeader->camPosCount = reader->ReadInt32(); + collisionHeader->camPosData.reserve(collisionHeader->camPosCount); + for (int32_t i = 0; i < collisionHeader->camPosCount; i++) { + Vec3s pos; + pos.x = reader->ReadInt16(); + pos.y = reader->ReadInt16(); + pos.z = reader->ReadInt16(); + collisionHeader->camPosData.push_back(pos); + } + + Vec3s zero; + zero.x = 0; + zero.y = 0; + zero.z = 0; + collisionHeader->camPosDataZero = zero; + + for (size_t i = 0; i < collisionHeader->camDataCount; i++) { + int32_t idx = collisionHeader->camPosDataIndices[i]; + + if (collisionHeader->camPosCount > 0) { + collisionHeader->camData[i].camPosData = &collisionHeader->camPosData[idx]; + } else { + collisionHeader->camData[i].camPosData = &collisionHeader->camPosDataZero; + } + } + collisionHeader->collisionHeaderData.cameraDataList = collisionHeader->camData.data(); + collisionHeader->collisionHeaderData.cameraDataListLen = collisionHeader->camDataCount; + + collisionHeader->collisionHeaderData.numWaterBoxes = reader->ReadInt32(); + collisionHeader->waterBoxes.reserve(collisionHeader->collisionHeaderData.numWaterBoxes); + for (int32_t i = 0; i < collisionHeader->collisionHeaderData.numWaterBoxes; i++) { + WaterBox waterBox; + waterBox.xMin = reader->ReadInt16(); + waterBox.ySurface = reader->ReadInt16(); + waterBox.zMin = reader->ReadInt16(); + waterBox.xLength = reader->ReadInt16(); + waterBox.zLength = reader->ReadInt16(); + waterBox.properties = reader->ReadInt32(); + + collisionHeader->waterBoxes.push_back(waterBox); + } + collisionHeader->collisionHeaderData.waterBoxes = collisionHeader->waterBoxes.data(); +} +} diff --git a/mm/2s2h/resource/importer/CollisionHeaderFactory.h b/mm/2s2h/resource/importer/CollisionHeaderFactory.h new file mode 100644 index 000000000..09d6ba4c5 --- /dev/null +++ b/mm/2s2h/resource/importer/CollisionHeaderFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class CollisionHeaderFactory : public ResourceFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class CollisionHeaderFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/CutsceneFactory.cpp b/mm/2s2h/resource/importer/CutsceneFactory.cpp new file mode 100644 index 000000000..12498cf92 --- /dev/null +++ b/mm/2s2h/resource/importer/CutsceneFactory.cpp @@ -0,0 +1,917 @@ +#include "2s2h/resource/importer/CutsceneFactory.h" +#include "2s2h/resource/type/Cutscene.h" +#include "spdlog/spdlog.h" +// TODO headers +// extern "C" { +//#include "z64cutscene.h" +//} +typedef enum { + /* 0x00A */ CS_CMD_TEXT = 10, + /* 0x05A */ CS_CMD_CAMERA_SPLINE = 90, + /* 0x064 */ CS_CMD_ACTOR_CUE_100 = 100, + /* 0x065 */ CS_CMD_ACTOR_CUE_101, + /* 0x066 */ CS_CMD_ACTOR_CUE_102, + /* 0x067 */ CS_CMD_ACTOR_CUE_103, + /* 0x068 */ CS_CMD_ACTOR_CUE_104, + /* 0x069 */ CS_CMD_ACTOR_CUE_105, + /* 0x06A */ CS_CMD_ACTOR_CUE_106, + /* 0x06B */ CS_CMD_ACTOR_CUE_107, + /* 0x06C */ CS_CMD_ACTOR_CUE_108, + /* 0x06D */ CS_CMD_ACTOR_CUE_109, + /* 0x06E */ CS_CMD_ACTOR_CUE_110, + /* 0x06F */ CS_CMD_ACTOR_CUE_111, + /* 0x070 */ CS_CMD_ACTOR_CUE_112, + /* 0x071 */ CS_CMD_ACTOR_CUE_113, + /* 0x072 */ CS_CMD_ACTOR_CUE_114, + /* 0x073 */ CS_CMD_ACTOR_CUE_115, + /* 0x074 */ CS_CMD_ACTOR_CUE_116, + /* 0x075 */ CS_CMD_ACTOR_CUE_117, + /* 0x076 */ CS_CMD_ACTOR_CUE_118, + /* 0x077 */ CS_CMD_ACTOR_CUE_119, + /* 0x078 */ CS_CMD_ACTOR_CUE_120, + /* 0x079 */ CS_CMD_ACTOR_CUE_121, + /* 0x07A */ CS_CMD_ACTOR_CUE_122, + /* 0x07B */ CS_CMD_ACTOR_CUE_123, + /* 0x07C */ CS_CMD_ACTOR_CUE_124, + /* 0x07D */ CS_CMD_ACTOR_CUE_125, + /* 0x07E */ CS_CMD_ACTOR_CUE_126, + /* 0x07F */ CS_CMD_ACTOR_CUE_127, + /* 0x080 */ CS_CMD_ACTOR_CUE_128, + /* 0x081 */ CS_CMD_ACTOR_CUE_129, + /* 0x082 */ CS_CMD_ACTOR_CUE_130, + /* 0x083 */ CS_CMD_ACTOR_CUE_131, + /* 0x084 */ CS_CMD_ACTOR_CUE_132, + /* 0x085 */ CS_CMD_ACTOR_CUE_133, + /* 0x086 */ CS_CMD_ACTOR_CUE_134, + /* 0x087 */ CS_CMD_ACTOR_CUE_135, + /* 0x088 */ CS_CMD_ACTOR_CUE_136, + /* 0x089 */ CS_CMD_ACTOR_CUE_137, + /* 0x08A */ CS_CMD_ACTOR_CUE_138, + /* 0x08B */ CS_CMD_ACTOR_CUE_139, + /* 0x08C */ CS_CMD_ACTOR_CUE_140, + /* 0x08D */ CS_CMD_ACTOR_CUE_141, + /* 0x08E */ CS_CMD_ACTOR_CUE_142, + /* 0x08F */ CS_CMD_ACTOR_CUE_143, + /* 0x090 */ CS_CMD_ACTOR_CUE_144, + /* 0x091 */ CS_CMD_ACTOR_CUE_145, + /* 0x092 */ CS_CMD_ACTOR_CUE_146, + /* 0x093 */ CS_CMD_ACTOR_CUE_147, + /* 0x094 */ CS_CMD_ACTOR_CUE_148, + /* 0x095 */ CS_CMD_ACTOR_CUE_149, + /* 0x096 */ CS_CMD_MISC, + /* 0x097 */ CS_CMD_LIGHT_SETTING, + /* 0x098 */ CS_CMD_TRANSITION, + /* 0x099 */ CS_CMD_MOTION_BLUR, + /* 0x09A */ CS_CMD_GIVE_TATL, + /* 0x09B */ CS_CMD_TRANSITION_GENERAL, + /* 0x09C */ CS_CMD_FADE_OUT_SEQ, + /* 0x09D */ CS_CMD_TIME, + /* 0x0C8 */ CS_CMD_PLAYER_CUE = 200, + /* 0x0C9 */ CS_CMD_ACTOR_CUE_201, + /* 0x0FA */ CS_CMD_UNK_DATA_FA = 0xFA, + /* 0x0FE */ CS_CMD_UNK_DATA_FE = 0xFE, + /* 0x0FF */ CS_CMD_UNK_DATA_FF, + /* 0x100 */ CS_CMD_UNK_DATA_100, + /* 0x101 */ CS_CMD_UNK_DATA_101, + /* 0x102 */ CS_CMD_UNK_DATA_102, + /* 0x103 */ CS_CMD_UNK_DATA_103, + /* 0x104 */ CS_CMD_UNK_DATA_104, + /* 0x105 */ CS_CMD_UNK_DATA_105, + /* 0x108 */ CS_CMD_UNK_DATA_108 = 0x108, + /* 0x109 */ CS_CMD_UNK_DATA_109, + /* 0x12C */ CS_CMD_START_SEQ = 300, + /* 0x12D */ CS_CMD_STOP_SEQ, + /* 0x12E */ CS_CMD_START_AMBIENCE, + /* 0x12F */ CS_CMD_FADE_OUT_AMBIENCE, + /* 0x130 */ CS_CMD_SFX_REVERB_INDEX_2, + /* 0x131 */ CS_CMD_SFX_REVERB_INDEX_1, + /* 0x132 */ CS_CMD_MODIFY_SEQ, + /* 0x15E */ CS_CMD_DESTINATION = 350, + /* 0x15F */ CS_CMD_CHOOSE_CREDITS_SCENES, + /* 0x190 */ CS_CMD_RUMBLE = 400, + /* 0x1C2 */ CS_CMD_ACTOR_CUE_450 = 450, + /* 0x1C3 */ CS_CMD_ACTOR_CUE_451, + /* 0x1C4 */ CS_CMD_ACTOR_CUE_452, + /* 0x1C5 */ CS_CMD_ACTOR_CUE_453, + /* 0x1C6 */ CS_CMD_ACTOR_CUE_454, + /* 0x1C7 */ CS_CMD_ACTOR_CUE_455, + /* 0x1C8 */ CS_CMD_ACTOR_CUE_456, + /* 0x1C9 */ CS_CMD_ACTOR_CUE_457, + /* 0x1CA */ CS_CMD_ACTOR_CUE_458, + /* 0x1CB */ CS_CMD_ACTOR_CUE_459, + /* 0x1CC */ CS_CMD_ACTOR_CUE_460, + /* 0x1CD */ CS_CMD_ACTOR_CUE_461, + /* 0x1CE */ CS_CMD_ACTOR_CUE_462, + /* 0x1CF */ CS_CMD_ACTOR_CUE_463, + /* 0x1D0 */ CS_CMD_ACTOR_CUE_464, + /* 0x1D1 */ CS_CMD_ACTOR_CUE_465, + /* 0x1D2 */ CS_CMD_ACTOR_CUE_466, + /* 0x1D3 */ CS_CMD_ACTOR_CUE_467, + /* 0x1D4 */ CS_CMD_ACTOR_CUE_468, + /* 0x1D5 */ CS_CMD_ACTOR_CUE_469, + /* 0x1D6 */ CS_CMD_ACTOR_CUE_470, + /* 0x1D7 */ CS_CMD_ACTOR_CUE_471, + /* 0x1D8 */ CS_CMD_ACTOR_CUE_472, + /* 0x1D9 */ CS_CMD_ACTOR_CUE_473, + /* 0x1DA */ CS_CMD_ACTOR_CUE_474, + /* 0x1DB */ CS_CMD_ACTOR_CUE_475, + /* 0x1DC */ CS_CMD_ACTOR_CUE_476, + /* 0x1DD */ CS_CMD_ACTOR_CUE_477, + /* 0x1DE */ CS_CMD_ACTOR_CUE_478, + /* 0x1DF */ CS_CMD_ACTOR_CUE_479, + /* 0x1E0 */ CS_CMD_ACTOR_CUE_480, + /* 0x1E1 */ CS_CMD_ACTOR_CUE_481, + /* 0x1E2 */ CS_CMD_ACTOR_CUE_482, + /* 0x1E3 */ CS_CMD_ACTOR_CUE_483, + /* 0x1E4 */ CS_CMD_ACTOR_CUE_484, + /* 0x1E5 */ CS_CMD_ACTOR_CUE_485, + /* 0x1E6 */ CS_CMD_ACTOR_CUE_486, + /* 0x1E7 */ CS_CMD_ACTOR_CUE_487, + /* 0x1E8 */ CS_CMD_ACTOR_CUE_488, + /* 0x1E9 */ CS_CMD_ACTOR_CUE_489, + /* 0x1EA */ CS_CMD_ACTOR_CUE_490, + /* 0x1EB */ CS_CMD_ACTOR_CUE_491, + /* 0x1EC */ CS_CMD_ACTOR_CUE_492, + /* 0x1ED */ CS_CMD_ACTOR_CUE_493, + /* 0x1EE */ CS_CMD_ACTOR_CUE_494, + /* 0x1EF */ CS_CMD_ACTOR_CUE_495, + /* 0x1F0 */ CS_CMD_ACTOR_CUE_496, + /* 0x1F1 */ CS_CMD_ACTOR_CUE_497, + /* 0x1F2 */ CS_CMD_ACTOR_CUE_498, + /* 0x1F3 */ CS_CMD_ACTOR_CUE_499, + /* 0x1F4 */ CS_CMD_ACTOR_CUE_500, + /* 0x1F5 */ CS_CMD_ACTOR_CUE_501, + /* 0x1F6 */ CS_CMD_ACTOR_CUE_502, + /* 0x1F7 */ CS_CMD_ACTOR_CUE_503, + /* 0x1F8 */ CS_CMD_ACTOR_CUE_504, + /* 0x1F9 */ CS_CMD_ACTOR_CUE_SOTCS, // Song of Time Cutscenes (Double SoT, Three-Day Reset SoT) + /* 0x1FA */ CS_CMD_ACTOR_CUE_506, + /* 0x1FB */ CS_CMD_ACTOR_CUE_507, + /* 0x1FC */ CS_CMD_ACTOR_CUE_508, + /* 0x1FD */ CS_CMD_ACTOR_CUE_509, + /* 0x1FE */ CS_CMD_ACTOR_CUE_510, + /* 0x1FF */ CS_CMD_ACTOR_CUE_511, + /* 0x200 */ CS_CMD_ACTOR_CUE_512, + /* 0x201 */ CS_CMD_ACTOR_CUE_513, + /* 0x202 */ CS_CMD_ACTOR_CUE_514, + /* 0x203 */ CS_CMD_ACTOR_CUE_515, + /* 0x204 */ CS_CMD_ACTOR_CUE_516, + /* 0x205 */ CS_CMD_ACTOR_CUE_517, + /* 0x206 */ CS_CMD_ACTOR_CUE_518, + /* 0x207 */ CS_CMD_ACTOR_CUE_519, + /* 0x208 */ CS_CMD_ACTOR_CUE_520, + /* 0x209 */ CS_CMD_ACTOR_CUE_521, + /* 0x20A */ CS_CMD_ACTOR_CUE_522, + /* 0x20B */ CS_CMD_ACTOR_CUE_523, + /* 0x20C */ CS_CMD_ACTOR_CUE_524, + /* 0x20D */ CS_CMD_ACTOR_CUE_525, + /* 0x20E */ CS_CMD_ACTOR_CUE_526, + /* 0x20F */ CS_CMD_ACTOR_CUE_527, + /* 0x210 */ CS_CMD_ACTOR_CUE_528, + /* 0x211 */ CS_CMD_ACTOR_CUE_529, + /* 0x212 */ CS_CMD_ACTOR_CUE_530, + /* 0x213 */ CS_CMD_ACTOR_CUE_531, + /* 0x214 */ CS_CMD_ACTOR_CUE_532, + /* 0x215 */ CS_CMD_ACTOR_CUE_533, + /* 0x216 */ CS_CMD_ACTOR_CUE_534, + /* 0x217 */ CS_CMD_ACTOR_CUE_535, + /* 0x218 */ CS_CMD_ACTOR_CUE_536, + /* 0x219 */ CS_CMD_ACTOR_CUE_537, + /* 0x21A */ CS_CMD_ACTOR_CUE_538, + /* 0x21B */ CS_CMD_ACTOR_CUE_539, + /* 0x21C */ CS_CMD_ACTOR_CUE_540, + /* 0x21D */ CS_CMD_ACTOR_CUE_541, + /* 0x21E */ CS_CMD_ACTOR_CUE_542, + /* 0x21F */ CS_CMD_ACTOR_CUE_543, + /* 0x220 */ CS_CMD_ACTOR_CUE_544, + /* 0x221 */ CS_CMD_ACTOR_CUE_545, + /* 0x222 */ CS_CMD_ACTOR_CUE_546, + /* 0x223 */ CS_CMD_ACTOR_CUE_547, + /* 0x224 */ CS_CMD_ACTOR_CUE_548, + /* 0x225 */ CS_CMD_ACTOR_CUE_549, + /* 0x226 */ CS_CMD_ACTOR_CUE_550, + /* 0x227 */ CS_CMD_ACTOR_CUE_551, + /* 0x228 */ CS_CMD_ACTOR_CUE_552, + /* 0x229 */ CS_CMD_ACTOR_CUE_553, + /* 0x22A */ CS_CMD_ACTOR_CUE_554, + /* 0x22B */ CS_CMD_ACTOR_CUE_555, + /* 0x22C */ CS_CMD_ACTOR_CUE_556, + /* 0x22D */ CS_CMD_ACTOR_CUE_557, + /* 0x22E */ CS_CMD_ACTOR_CUE_558, + /* 0x22F */ CS_CMD_ACTOR_CUE_559, + /* 0x230 */ CS_CMD_ACTOR_CUE_560, + /* 0x231 */ CS_CMD_ACTOR_CUE_561, + /* 0x232 */ CS_CMD_ACTOR_CUE_562, + /* 0x233 */ CS_CMD_ACTOR_CUE_563, + /* 0x234 */ CS_CMD_ACTOR_CUE_564, + /* 0x235 */ CS_CMD_ACTOR_CUE_565, + /* 0x236 */ CS_CMD_ACTOR_CUE_566, + /* 0x237 */ CS_CMD_ACTOR_CUE_567, + /* 0x238 */ CS_CMD_ACTOR_CUE_568, + /* 0x239 */ CS_CMD_ACTOR_CUE_569, + /* 0x23A */ CS_CMD_ACTOR_CUE_570, + /* 0x23B */ CS_CMD_ACTOR_CUE_571, + /* 0x23C */ CS_CMD_ACTOR_CUE_572, + /* 0x23D */ CS_CMD_ACTOR_CUE_573, + /* 0x23E */ CS_CMD_ACTOR_CUE_574, + /* 0x23F */ CS_CMD_ACTOR_CUE_575, + /* 0x240 */ CS_CMD_ACTOR_CUE_576, + /* 0x241 */ CS_CMD_ACTOR_CUE_577, + /* 0x242 */ CS_CMD_ACTOR_CUE_578, + /* 0x243 */ CS_CMD_ACTOR_CUE_579, + /* 0x244 */ CS_CMD_ACTOR_CUE_580, + /* 0x245 */ CS_CMD_ACTOR_CUE_581, + /* 0x246 */ CS_CMD_ACTOR_CUE_582, + /* 0x247 */ CS_CMD_ACTOR_CUE_583, + /* 0x248 */ CS_CMD_ACTOR_CUE_584, + /* 0x249 */ CS_CMD_ACTOR_CUE_585, + /* 0x24A */ CS_CMD_ACTOR_CUE_586, + /* 0x24B */ CS_CMD_ACTOR_CUE_587, + /* 0x24C */ CS_CMD_ACTOR_CUE_588, + /* 0x24D */ CS_CMD_ACTOR_CUE_589, + /* 0x24E */ CS_CMD_ACTOR_CUE_590, + /* 0x24F */ CS_CMD_ACTOR_CUE_591, + /* 0x250 */ CS_CMD_ACTOR_CUE_592, + /* 0x251 */ CS_CMD_ACTOR_CUE_593, + /* 0x252 */ CS_CMD_ACTOR_CUE_594, + /* 0x253 */ CS_CMD_ACTOR_CUE_595, + /* 0x254 */ CS_CMD_ACTOR_CUE_596, + /* 0x255 */ CS_CMD_ACTOR_CUE_597, + /* 0x256 */ CS_CMD_ACTOR_CUE_598, + /* 0x257 */ CS_CMD_ACTOR_CUE_599, + /* -2 */ CS_CMD_ACTOR_CUE_POST_PROCESS = 0xFFFFFFFE, + /* -1 */ CS_CAM_STOP // OoT Remnant +} CutsceneCmd; + +namespace LUS { +std::shared_ptr CutsceneFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Cutscene with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +static inline uint32_t read_CMD_BBBB(std::shared_ptr reader) { + uint32_t v; + reader->Read((char*)&v, sizeof(uint32_t)); + + return v; +} + +static inline uint32_t read_CMD_BBH(std::shared_ptr reader) { + uint32_t v; + reader->Read((char*)&v, sizeof(uint32_t)); + + // swap the half word to match endianness + if (reader->GetEndianness() != LUS::Endianness::Native) { + uint8_t* b = (uint8_t*)&v; + uint8_t tmp = b[2]; + b[2] = b[3]; + b[3] = tmp; + } + + return v; +} + +static inline uint32_t read_CMD_HBB(std::shared_ptr reader) { + uint32_t v; + reader->Read((char*)&v, sizeof(uint32_t)); + + // swap the half word to match endianness + if (reader->GetEndianness() != LUS::Endianness::Native) { + uint8_t* b = (uint8_t*)&v; + uint8_t tmp = b[0]; + b[0] = b[1]; + b[1] = tmp; + } + + return v; +} + +static inline uint32_t read_CMD_HH(std::shared_ptr reader) { + uint32_t v; + reader->Read((char*)&v, sizeof(uint32_t)); + + // swap the half words to match endianness + if (reader->GetEndianness() != LUS::Endianness::Native) { + uint8_t* b = (uint8_t*)&v; + uint8_t tmp = b[0]; + b[0] = b[1]; + b[1] = tmp; + tmp = b[2]; + b[2] = b[3]; + b[3] = tmp; + } + + return v; +} + +void LUS::CutsceneFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr cutscene = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, cutscene); + + uint32_t numEntries = reader->ReadUInt32(); + cutscene->commands.reserve(numEntries); + + cutscene->numCommands = reader->ReadUInt32(); + cutscene->commands.push_back(cutscene->numCommands); + + cutscene->endFrame = reader->ReadUInt32(); + cutscene->commands.push_back(cutscene->endFrame); + + // BENTODO detect the game + ParseFileBinaryMM(reader, cutscene); +} + +void LUS::CutsceneFactoryV0::ParseFileBinaryOoT(std::shared_ptr reader, + std::shared_ptr cutscene) { + while (true) { + uint32_t commandId = reader->ReadUInt32(); + cutscene->commands.push_back(commandId); + + switch (commandId) { + case (uint32_t)CutsceneCommands::SetCameraPos: { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + while (true) { + uint32_t val = read_CMD_BBH(reader); + int8_t continueFlag = ((int8_t*)&val)[0]; + + cutscene->commands.push_back(val); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + if (continueFlag == -1) { + break; + } + } + } break; + case (uint32_t)CutsceneCommands::SetCameraFocus: { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + while (true) { + uint32_t val = read_CMD_BBH(reader); + int8_t continueFlag = ((int8_t*)&val)[0]; + + cutscene->commands.push_back(val); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + if (continueFlag == -1) { + break; + } + } + break; + } + case (uint32_t)CutsceneCommands::SpecialAction: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::SetLighting: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::SetCameraPosLink: { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + while (true) { + uint32_t val = read_CMD_BBH(reader); + int8_t continueFlag = ((int8_t*)&val)[0]; + + cutscene->commands.push_back(val); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + if (continueFlag == -1) { + break; + } + } + break; + } + case (uint32_t)CutsceneCommands::SetCameraFocusLink: { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + while (true) { + uint32_t val = read_CMD_BBH(reader); + int8_t continueFlag = ((int8_t*)&val)[0]; + + cutscene->commands.push_back(val); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + + if (continueFlag == -1) { + break; + } + } + break; + } + case (uint32_t)CutsceneCommands::Cmd09: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HBB(reader)); + cutscene->commands.push_back(read_CMD_BBH(reader)); + } + break; + } + case 0x15: + case (uint32_t)CutsceneCommands::Unknown: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + } break; + case (uint32_t)CutsceneCommands::Textbox: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case (uint32_t)CutsceneCommands::SetActorAction0: + case (uint32_t)CutsceneCommands::SetActorAction1: + case 17: + case 18: + case 23: + case 34: + case 39: + case 46: + case 76: + case 85: + case 93: + case 105: + case 107: + case 110: + case 119: + case 123: + case 138: + case 139: + case 144: + case (uint32_t)CutsceneCommands::SetActorAction2: + case 16: + case 24: + case 35: + case 40: + case 48: + case 64: + case 68: + case 70: + case 78: + case 80: + case 94: + case 116: + case 118: + case 120: + case 125: + case 131: + case 141: + case (uint32_t)CutsceneCommands::SetActorAction3: + case 36: + case 41: + case 50: + case 67: + case 69: + case 72: + case 74: + case 81: + case 106: + case 117: + case 121: + case 126: + case 132: + case (uint32_t)CutsceneCommands::SetActorAction4: + case 37: + case 42: + case 51: + case 53: + case 63: + case 65: + case 66: + case 75: + case 82: + case 108: + case 127: + case 133: + case (uint32_t)CutsceneCommands::SetActorAction5: + case 38: + case 43: + case 47: + case 54: + case 79: + case 83: + case 128: + case 135: + case (uint32_t)CutsceneCommands::SetActorAction6: + case 55: + case 77: + case 84: + case 90: + case 129: + case 136: + case (uint32_t)CutsceneCommands::SetActorAction7: + case 52: + case 57: + case 58: + case 88: + case 115: + case 130: + case 137: + case (uint32_t)CutsceneCommands::SetActorAction8: + case 60: + case 89: + case 111: + case 114: + case 134: + case 142: + case (uint32_t)CutsceneCommands::SetActorAction9: + case (uint32_t)CutsceneCommands::SetActorAction10: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + + break; + } + case (uint32_t)CutsceneCommands::SetSceneTransFX: { + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + break; + } + case (uint32_t)CutsceneCommands::PlayBGM: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::StopBGM: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::FadeBGM: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::SetTime: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HBB(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case (uint32_t)CutsceneCommands::Terminator: { + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + break; + } + case 0xFFFFFFFF: // CS_END + { + cutscene->commands.push_back(reader->ReadUInt32()); + return; + } + default: + SPDLOG_TRACE("CutsceneV0: Unknown command {}\n", commandId); + // error? + break; + } + } +} + +void LUS::CutsceneFactoryV0::ParseFileBinaryMM(std::shared_ptr reader, + std::shared_ptr cutscene) { + while (true) { + uint32_t command = reader->ReadUInt32(); + cutscene->commands.push_back(command); + + if (((command >= CS_CMD_ACTOR_CUE_100) && (command <= CS_CMD_ACTOR_CUE_149)) || + (command == CS_CMD_ACTOR_CUE_201) || + ((command >= CS_CMD_ACTOR_CUE_450) && (command <= CS_CMD_ACTOR_CUE_599))) { + goto actorCue; + } + + switch (command) { + case CS_CMD_TEXT: { + uint32_t size = reader->ReadUInt32(); + // uint8_t type = reader->ReadInt8(); + cutscene->commands.push_back(size); + // BENTODO do we need to read the type? + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_CAMERA_SPLINE: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < (size / 4); i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_MISC: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_LIGHT_SETTING: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_BBH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_TRANSITION: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_MOTION_BLUR: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_GIVE_TATL: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_START_SEQ: + case CS_CMD_STOP_SEQ: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_BBH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_SFX_REVERB_INDEX_2: + case CS_CMD_SFX_REVERB_INDEX_1: + case CS_CMD_MODIFY_SEQ: + + case CS_CMD_START_AMBIENCE: + case CS_CMD_FADE_OUT_AMBIENCE: + case CS_CMD_DESTINATION: + case CS_CMD_CHOOSE_CREDITS_SCENES: + + case CS_CMD_UNK_DATA_FA: + case CS_CMD_UNK_DATA_FE: + case CS_CMD_UNK_DATA_FF: + case CS_CMD_UNK_DATA_100: + case CS_CMD_UNK_DATA_101: + case CS_CMD_UNK_DATA_102: + case CS_CMD_UNK_DATA_103: + case CS_CMD_UNK_DATA_104: + case CS_CMD_UNK_DATA_105: + case CS_CMD_UNK_DATA_108: + case CS_CMD_UNK_DATA_109: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_BBH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_TRANSITION_GENERAL: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HBB(reader)); + cutscene->commands.push_back(read_CMD_BBBB(reader)); + } + break; + } + case CS_CMD_FADE_OUT_SEQ: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + } + break; + } + case CS_CMD_TIME: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HBB(reader)); + } + break; + } + case CS_CMD_PLAYER_CUE: { + actorCue: + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + cutscene->commands.push_back(reader->ReadUInt32()); + } + break; + } + case CS_CMD_RUMBLE: { + uint32_t size = reader->ReadUInt32(); + cutscene->commands.push_back(size); + + for (uint32_t i = 0; i < size; i++) { + cutscene->commands.push_back(read_CMD_HH(reader)); + cutscene->commands.push_back(read_CMD_HBB(reader)); + cutscene->commands.push_back(read_CMD_BBBB(reader)); + } + break; + } + case 0xFFFFFFFF: { + cutscene->commands.push_back(reader->ReadUInt32()); + return; + } + default: + SPDLOG_TRACE("CutsceneV0: Unknown command {}\n", command); + // error? + break; + } + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/CutsceneFactory.h b/mm/2s2h/resource/importer/CutsceneFactory.h new file mode 100644 index 000000000..729041ce3 --- /dev/null +++ b/mm/2s2h/resource/importer/CutsceneFactory.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + + +namespace LUS { +class Cutscene; +class CutsceneFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class CutsceneFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + + private: + void ParseFileBinaryOoT(std::shared_ptr reader,std::shared_ptr cutscene); + void ParseFileBinaryMM(std::shared_ptr reader, std::shared_ptr cutscene); +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/PathFactory.cpp b/mm/2s2h/resource/importer/PathFactory.cpp new file mode 100644 index 000000000..07e5b6e7b --- /dev/null +++ b/mm/2s2h/resource/importer/PathFactory.cpp @@ -0,0 +1,113 @@ +#include "2s2h/resource/importer/PathFactory.h" +#include "2s2h/resource/type/Path.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +PathFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Path with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::PathFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr path = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, path); + + path->numPaths = reader->ReadUInt32(); + path->paths.reserve(path->numPaths); + for (uint32_t k = 0; k < path->numPaths; k++) { + std::vector points; + uint32_t pointCount = reader->ReadUInt32(); + points.reserve(pointCount); + for (uint32_t i = 0; i < pointCount; i++) { + Vec3s point; + point.x = reader->ReadInt16(); + point.y = reader->ReadInt16(); + point.z = reader->ReadInt16(); + + points.push_back(point); + } + + PathData pathDataEntry; + pathDataEntry.count = pointCount; + + path->paths.push_back(points); + pathDataEntry.points = path->paths.back().data(); + + path->pathData.push_back(pathDataEntry); + } +} + +std::shared_ptr PathFactoryMM::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Path with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::PathFactoryMMV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { + std::shared_ptr path = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, path); + + path->numPaths = reader->ReadUInt32(); + path->paths.reserve(path->numPaths); + for (uint32_t k = 0; k < path->numPaths; k++) { + std::vector points; + uint32_t pointCount = reader->ReadUInt32(); + + uint8_t additionalPathIndex = reader->ReadUByte(); + int16_t customValue = reader->ReadInt16(); + + for (uint32_t i = 0; i < pointCount; i++) { + Vec3s point; + point.x = reader->ReadInt16(); + point.y = reader->ReadInt16(); + point.z = reader->ReadInt16(); + + points.push_back(point); + } + + PathDataMM pathDataEntry; + pathDataEntry.count = pointCount; + pathDataEntry.additionalPathIndex = additionalPathIndex; + pathDataEntry.customValue = customValue; + + path->paths.push_back(points); + pathDataEntry.points = path->paths.back().data(); + + path->pathData.push_back(pathDataEntry); + } +} + + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/PathFactory.h b/mm/2s2h/resource/importer/PathFactory.h new file mode 100644 index 000000000..08f9e26cf --- /dev/null +++ b/mm/2s2h/resource/importer/PathFactory.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class PathFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class PathFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +class PathFactoryMM : public ResourceFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class PathFactoryMMV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/PlayerAnimationFactory.cpp b/mm/2s2h/resource/importer/PlayerAnimationFactory.cpp new file mode 100644 index 000000000..7e6aba360 --- /dev/null +++ b/mm/2s2h/resource/importer/PlayerAnimationFactory.cpp @@ -0,0 +1,41 @@ +#include "2s2h/resource/importer/PlayerAnimationFactory.h" +#include "2s2h/resource/type/PlayerAnimation.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +PlayerAnimationFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load PlayerAnimation with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::PlayerAnimationFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr playerAnimation = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, playerAnimation); + + uint32_t numEntries = reader->ReadUInt32(); + playerAnimation->limbRotData.reserve(numEntries); + + for (uint32_t i = 0; i < numEntries; i++) { + playerAnimation->limbRotData.push_back(reader->ReadInt16()); + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/PlayerAnimationFactory.h b/mm/2s2h/resource/importer/PlayerAnimationFactory.h new file mode 100644 index 000000000..b4981f7c6 --- /dev/null +++ b/mm/2s2h/resource/importer/PlayerAnimationFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class PlayerAnimationFactory : public ResourceFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class PlayerAnimationFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/SceneFactory.cpp b/mm/2s2h/resource/importer/SceneFactory.cpp new file mode 100644 index 000000000..67320daa8 --- /dev/null +++ b/mm/2s2h/resource/importer/SceneFactory.cpp @@ -0,0 +1,140 @@ +#include "spdlog/spdlog.h" +#include "2s2h/resource/importer/SceneFactory.h" +#include "2s2h/resource/type/Scene.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" +#include "2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetWindSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetExitListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.h" +#include "2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h" +#include "2s2h/resource/importer/scenecommand/SetCsCameraFactory.h" +#include "2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetRoomListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.h" +#include "2s2h/resource/importer/scenecommand/SetEntranceListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetObjectListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetStartPositionListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetActorListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.h" +#include "2s2h/resource/importer/scenecommand/EndMarkerFactory.h" +#include "2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.h" +#include "2s2h/resource/importer/scenecommand/SetPathwaysFactory.h" +#include "2s2h/resource/importer/scenecommand/SetCutscenesFactory.h" +#include "2s2h/resource/importer/scenecommand/SetLightListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetMeshFactory.h" +#include "2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetMinimapListFactory.h" +#include "2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.h" +#include "2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.h" + +namespace LUS { + +std::shared_ptr +SceneFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + if (SceneFactory::sceneCommandFactories.empty()) { + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetLightingSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetWind] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetExitList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetTimeSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSkyboxModifier] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetEchoSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSoundSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSkyboxSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetRoomBehavior] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCsCamera] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCameraSettings] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetRoomList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCollisionHeader] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetEntranceList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSpecialObjects] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetObjectList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetStartPositionList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetActorList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetTransitionActorList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::EndMarker] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetAlternateHeaders] = std::make_shared(); + // TODO should we use a different custom scene command like cutscenes? + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetPathways] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCutscenes] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetLightList] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetMesh] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCutscenesMM] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetAnimatedMaterialList] = + std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetMinimapList] = + std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetMinimapChests] = + std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetActorCutsceneList] = + std::make_shared(); + } + + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Scene with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void SceneFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr scene = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, scene); + + ParseSceneCommands(scene, reader); +} + +void SceneFactoryV0::ParseSceneCommands(std::shared_ptr scene, std::shared_ptr reader) { + uint32_t commandCount = reader->ReadUInt32(); + scene->commands.reserve(commandCount); + + for (uint32_t i = 0; i < commandCount; i++) { + scene->commands.push_back(ParseSceneCommand(scene, reader, i)); + } +} + +std::shared_ptr SceneFactoryV0::ParseSceneCommand(std::shared_ptr scene, + std::shared_ptr reader, uint32_t index) { + SceneCommandID cmdID = (SceneCommandID)reader->ReadInt32(); + + reader->Seek(-sizeof(int32_t), SeekOffsetType::Current); + + std::shared_ptr result = nullptr; + std::shared_ptr commandFactory = SceneFactory::sceneCommandFactories[cmdID]; + + if (commandFactory != nullptr) { + auto initData = std::make_shared(); + initData->Id = scene->GetInitData()->Id; + initData->Type = ResourceType::SOH_SceneCommand; + initData->Path = scene->GetInitData()->Path + "/SceneCommand" + std::to_string(index); + initData->ResourceVersion = scene->GetInitData()->ResourceVersion; + result = std::static_pointer_cast(commandFactory->ReadResource(initData, reader)); + // Cache the resource? + } + + if (result == nullptr) { + SPDLOG_ERROR("Failed to load scene command of type {} in scene {}", (uint32_t)cmdID, scene->GetInitData()->Path); + } + + return result; +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/SceneFactory.h b/mm/2s2h/resource/importer/SceneFactory.h new file mode 100644 index 000000000..40887983d --- /dev/null +++ b/mm/2s2h/resource/importer/SceneFactory.h @@ -0,0 +1,29 @@ +#pragma once + +#include "2s2h/resource/type/Scene.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class SceneFactory : public ResourceFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + + // Doing something very similar to what we do on the ResourceLoader. + // Eventually, scene commands should be moved up to the ResourceLoader as well. + // They can not right now because the exporter does not give them a proper resource type enum value, + // and the exporter does not export the commands with a proper OTR header. + static inline std::unordered_map> sceneCommandFactories; +}; + +class SceneFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + void ParseSceneCommands(std::shared_ptr scene, std::shared_ptr reader); +protected: + std::shared_ptr ParseSceneCommand(std::shared_ptr scene, std::shared_ptr reader, uint32_t index); +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/SkeletonFactory.cpp b/mm/2s2h/resource/importer/SkeletonFactory.cpp new file mode 100644 index 000000000..aa4c814bd --- /dev/null +++ b/mm/2s2h/resource/importer/SkeletonFactory.cpp @@ -0,0 +1,158 @@ +#include "2s2h/resource/importer/SkeletonFactory.h" +#include "2s2h/resource/type/Skeleton.h" +#include +#include + +namespace LUS { +std::shared_ptr +SkeletonFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Skeleton with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +std::shared_ptr +SkeletonFactory::ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Skeleton with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileXML(reader, resource); + + return resource; +} + +void SkeletonFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr skeleton = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, skeleton); + + skeleton->type = (SkeletonType)reader->ReadInt8(); + skeleton->limbType = (LimbType)reader->ReadInt8(); + skeleton->limbCount = reader->ReadUInt32(); + skeleton->dListCount = reader->ReadUInt32(); + skeleton->limbTableType = (LimbType)reader->ReadInt8(); + skeleton->limbTableCount = reader->ReadUInt32(); + + skeleton->limbTable.reserve(skeleton->limbTableCount); + for (uint32_t i = 0; i < skeleton->limbTableCount; i++) { + std::string limbPath = reader->ReadString(); + + skeleton->limbTable.push_back(limbPath); + } + + if (skeleton->type == LUS::SkeletonType::Curve) { + skeleton->skeletonData.skelCurveLimbList.limbCount = skeleton->limbCount; + skeleton->curveLimbArray.reserve(skeleton->skeletonData.skelCurveLimbList.limbCount); + } else if (skeleton->type == LUS::SkeletonType::Flex) { + skeleton->skeletonData.flexSkeletonHeader.dListCount = skeleton->dListCount; + } + + if (skeleton->type == LUS::SkeletonType::Normal) { + skeleton->skeletonData.skeletonHeader.limbCount = skeleton->limbCount; + skeleton->standardLimbArray.reserve(skeleton->skeletonData.skeletonHeader.limbCount); + } else if (skeleton->type == LUS::SkeletonType::Flex) { + skeleton->skeletonData.flexSkeletonHeader.sh.limbCount = skeleton->limbCount; + skeleton->standardLimbArray.reserve(skeleton->skeletonData.flexSkeletonHeader.sh.limbCount); + } + + for (size_t i = 0; i < skeleton->limbTable.size(); i++) { + std::string limbStr = skeleton->limbTable[i]; + auto limb = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(limbStr.c_str()); + skeleton->skeletonHeaderSegments.push_back(limb ? limb->GetRawPointer() : nullptr); + } + + if (skeleton->type == LUS::SkeletonType::Normal) { + skeleton->skeletonData.skeletonHeader.segment = (void**)skeleton->skeletonHeaderSegments.data(); + } else if (skeleton->type == LUS::SkeletonType::Flex) { + skeleton->skeletonData.flexSkeletonHeader.sh.segment = (void**)skeleton->skeletonHeaderSegments.data(); + } else if (skeleton->type == LUS::SkeletonType::Curve) { + skeleton->skeletonData.skelCurveLimbList.limbs = (SkelCurveLimb**)skeleton->skeletonHeaderSegments.data(); + } else { + SPDLOG_ERROR("unknown skeleton type {}", (uint32_t)skeleton->type); + } + + skeleton->skeletonData.skeletonHeader.skeletonType = (uint8_t)skeleton->type; +} +void SkeletonFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) +{ + std::shared_ptr skel = std::static_pointer_cast(resource); + + std::string skeletonType = reader->Attribute("Type"); + // std::string skeletonLimbType = reader->Attribute("LimbType"); + int numLimbs = reader->IntAttribute("LimbCount"); + int numDLs = reader->IntAttribute("DisplayListCount"); + + if (skeletonType == "Flex") { + skel->type = SkeletonType::Flex; + } else if (skeletonType == "Curve") { + skel->type = SkeletonType::Curve; + } else if (skeletonType == "Normal") { + skel->type = SkeletonType::Normal; + } + + skel->type = SkeletonType::Flex; + skel->limbType = LimbType::LOD; + + // if (skeletonLimbType == "Standard") + // skel->limbType = LimbType::Standard; + // else if (skeletonLimbType == "LOD") + // skel->limbType = LimbType::LOD; + // else if (skeletonLimbType == "Curve") + // skel->limbType = LimbType::Curve; + // else if (skeletonLimbType == "Skin") + // skel->limbType = LimbType::Skin; + // else if (skeletonLimbType == "Legacy") + // Sskel->limbType = LimbType::Legacy; + + auto child = reader->FirstChildElement(); + + skel->limbCount = numLimbs; + skel->dListCount = numDLs; + + while (child != nullptr) { + std::string childName = child->Name(); + + if (childName == "SkeletonLimb") { + std::string limbName = child->Attribute("Path"); + skel->limbTable.push_back(limbName); + + auto limb = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(limbName.c_str()); + skel->skeletonHeaderSegments.push_back(limb ? limb->GetRawPointer() : nullptr); + } + + child = child->NextSiblingElement(); + } + + skel->skeletonData.flexSkeletonHeader.sh.limbCount = skel->limbCount; + skel->skeletonData.flexSkeletonHeader.sh.segment = (void**)skel->skeletonHeaderSegments.data(); + skel->skeletonData.flexSkeletonHeader.dListCount = skel->dListCount; + skel->skeletonData.skeletonHeader.skeletonType = (uint8_t)skel->type; +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/SkeletonFactory.h b/mm/2s2h/resource/importer/SkeletonFactory.h new file mode 100644 index 000000000..d64449393 --- /dev/null +++ b/mm/2s2h/resource/importer/SkeletonFactory.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class SkeletonFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + std::shared_ptr + ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) override; +}; + +class SkeletonFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; +}; +}; // namespace LUS + diff --git a/mm/2s2h/resource/importer/SkeletonLimbFactory.cpp b/mm/2s2h/resource/importer/SkeletonLimbFactory.cpp new file mode 100644 index 000000000..ad2fec085 --- /dev/null +++ b/mm/2s2h/resource/importer/SkeletonLimbFactory.cpp @@ -0,0 +1,271 @@ +#include "2s2h/resource/importer/SkeletonLimbFactory.h" +#include "2s2h/resource/type/SkeletonLimb.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultraship.h" + +namespace LUS { +std::shared_ptr +SkeletonLimbFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Skeleton Limb with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +std::shared_ptr +SkeletonLimbFactory::ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Skeleton Limb with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileXML(reader, resource); + + return resource; +} + +void LUS::SkeletonLimbFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr skeletonLimb = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, skeletonLimb); + + skeletonLimb->limbType = (LimbType)reader->ReadInt8(); + skeletonLimb->skinSegmentType = (ZLimbSkinType)reader->ReadInt8(); + skeletonLimb->skinDList = reader->ReadString(); + + skeletonLimb->skinVtxCnt = reader->ReadUInt16(); + + skeletonLimb->skinLimbModifCount = reader->ReadUInt32(); + skeletonLimb->skinLimbModifArray.reserve(skeletonLimb->skinLimbModifCount); + skeletonLimb->skinLimbModifVertexArrays.reserve(skeletonLimb->skinLimbModifCount); + skeletonLimb->skinLimbModifTransformationArrays.reserve(skeletonLimb->skinLimbModifCount); + for (size_t i = 0; i < skeletonLimb->skinLimbModifCount; i++) { + SkinLimbModif skinLimbModif; + skinLimbModif.unk_4 = reader->ReadUInt16(); + skeletonLimb->skinLimbModifArray.push_back(skinLimbModif); + + std::vector skinVertexArray; + int32_t skinVertexCount = reader->ReadInt32(); + skinVertexArray.reserve(skinVertexCount); + for (int32_t k = 0; k < skinVertexCount; k++) { + SkinVertex skinVertex; + + skinVertex.index = reader->ReadInt16(); + skinVertex.s = reader->ReadInt16(); + skinVertex.t = reader->ReadInt16(); + skinVertex.normX = reader->ReadInt8(); + skinVertex.normY = reader->ReadInt8(); + skinVertex.normZ = reader->ReadInt8(); + skinVertex.alpha = reader->ReadUByte(); + + skinVertexArray.push_back(skinVertex); + } + skeletonLimb->skinLimbModifVertexArrays.push_back(skinVertexArray); + + std::vector skinTransformationArray; + int32_t skinTransformationCount = reader->ReadInt32(); + skinTransformationArray.reserve(skinTransformationCount); + for (int32_t k = 0; k < skinTransformationCount; k++) { + SkinTransformation skinTransformation; + + skinTransformation.limbIndex = reader->ReadUByte(); + skinTransformation.x = reader->ReadInt16(); + skinTransformation.y = reader->ReadInt16(); + skinTransformation.z = reader->ReadInt16(); + skinTransformation.scale = reader->ReadUByte(); + + skinTransformationArray.push_back(skinTransformation); + } + skeletonLimb->skinLimbModifTransformationArrays.push_back(skinTransformationArray); + } + + skeletonLimb->skinDList2 = reader->ReadString(); + + skeletonLimb->legTransX = reader->ReadFloat(); + skeletonLimb->legTransY = reader->ReadFloat(); + skeletonLimb->legTransZ = reader->ReadFloat(); + + skeletonLimb->rotX = reader->ReadUInt16(); + skeletonLimb->rotY = reader->ReadUInt16(); + skeletonLimb->rotZ = reader->ReadUInt16(); + + skeletonLimb->childPtr = reader->ReadString(); + skeletonLimb->siblingPtr = reader->ReadString(); + skeletonLimb->dListPtr = reader->ReadString(); + skeletonLimb->dList2Ptr = reader->ReadString(); + + skeletonLimb->transX = reader->ReadInt16(); + skeletonLimb->transY = reader->ReadInt16(); + skeletonLimb->transZ = reader->ReadInt16(); + + skeletonLimb->childIndex = reader->ReadUByte(); + skeletonLimb->siblingIndex = reader->ReadUByte(); + + if (skeletonLimb->limbType == LUS::LimbType::LOD) { + skeletonLimb->limbData.lodLimb.jointPos.x = skeletonLimb->transX; + skeletonLimb->limbData.lodLimb.jointPos.y = skeletonLimb->transY; + skeletonLimb->limbData.lodLimb.jointPos.z = skeletonLimb->transZ; + skeletonLimb->limbData.lodLimb.child = skeletonLimb->childIndex; + skeletonLimb->limbData.lodLimb.sibling = skeletonLimb->siblingIndex; + + if (skeletonLimb->dListPtr != "") { + auto dList = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->dListPtr.c_str()); + skeletonLimb->limbData.lodLimb.dLists[0] = (Gfx*)(dList ? dList->GetRawPointer() : nullptr); + } else { + skeletonLimb->limbData.lodLimb.dLists[0] = nullptr; + } + + if (skeletonLimb->dList2Ptr != "") { + auto dList = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->dList2Ptr.c_str()); + skeletonLimb->limbData.lodLimb.dLists[1] = (Gfx*)(dList ? dList->GetRawPointer() : nullptr); + } else { + skeletonLimb->limbData.lodLimb.dLists[1] = nullptr; + } + } else if (skeletonLimb->limbType == LUS::LimbType::Standard) { + skeletonLimb->limbData.standardLimb.jointPos.x = skeletonLimb->transX; + skeletonLimb->limbData.standardLimb.jointPos.y = skeletonLimb->transY; + skeletonLimb->limbData.standardLimb.jointPos.z = skeletonLimb->transZ; + skeletonLimb->limbData.standardLimb.child = skeletonLimb->childIndex; + skeletonLimb->limbData.standardLimb.sibling = skeletonLimb->siblingIndex; + skeletonLimb->limbData.standardLimb.dList = nullptr; + + if (!skeletonLimb->dListPtr.empty()) { + const auto dList = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->dListPtr.c_str()); + skeletonLimb->limbData.standardLimb.dList = (Gfx*)(dList ? dList->GetRawPointer() : nullptr); + } + } else if (skeletonLimb->limbType == LUS::LimbType::Curve) { + skeletonLimb->limbData.skelCurveLimb.firstChildIdx = skeletonLimb->childIndex; + skeletonLimb->limbData.skelCurveLimb.nextLimbIdx = skeletonLimb->siblingIndex; + skeletonLimb->limbData.skelCurveLimb.dList[0] = nullptr; + skeletonLimb->limbData.skelCurveLimb.dList[1] = nullptr; + + if (!skeletonLimb->dListPtr.empty()) { + const auto dList = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->dListPtr.c_str()); + skeletonLimb->limbData.skelCurveLimb.dList[0] = (Gfx*)(dList ? dList->GetRawPointer() : nullptr); + } + + if (!skeletonLimb->dList2Ptr.empty()) { + const auto dList = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->dList2Ptr.c_str()); + skeletonLimb->limbData.skelCurveLimb.dList[1] = (Gfx*)(dList ? dList->GetRawPointer() : nullptr); + } + } else if (skeletonLimb->limbType == LUS::LimbType::Skin) { + skeletonLimb->limbData.skinLimb.jointPos.x = skeletonLimb->transX; + skeletonLimb->limbData.skinLimb.jointPos.y = skeletonLimb->transY; + skeletonLimb->limbData.skinLimb.jointPos.z = skeletonLimb->transZ; + skeletonLimb->limbData.skinLimb.child = skeletonLimb->childIndex; + skeletonLimb->limbData.skinLimb.sibling = skeletonLimb->siblingIndex; + + if (skeletonLimb->skinSegmentType == LUS::ZLimbSkinType::SkinType_DList) { + skeletonLimb->limbData.skinLimb.segmentType = static_cast(skeletonLimb->skinSegmentType); + } else if (skeletonLimb->skinSegmentType == LUS::ZLimbSkinType::SkinType_4) { + skeletonLimb->limbData.skinLimb.segmentType = 4; + } else if (skeletonLimb->skinSegmentType == LUS::ZLimbSkinType::SkinType_5) { + skeletonLimb->limbData.skinLimb.segmentType = 5; + } else { + skeletonLimb->limbData.skinLimb.segmentType = 0; + } + + if (skeletonLimb->skinSegmentType == LUS::ZLimbSkinType::SkinType_DList) { + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->skinDList.c_str()); + skeletonLimb->limbData.skinLimb.segment = res ? res->GetRawPointer() : nullptr; + } else if (skeletonLimb->skinSegmentType == LUS::ZLimbSkinType::SkinType_4) { + skeletonLimb->skinAnimLimbData.totalVtxCount = skeletonLimb->skinVtxCnt; + skeletonLimb->skinAnimLimbData.limbModifCount = skeletonLimb->skinLimbModifCount; + skeletonLimb->skinAnimLimbData.limbModifications = skeletonLimb->skinLimbModifArray.data(); + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(skeletonLimb->skinDList2.c_str()); + skeletonLimb->skinAnimLimbData.dlist = (Gfx*)(res ? res->GetRawPointer() : nullptr); + + for (size_t i = 0; i < skeletonLimb->skinLimbModifArray.size(); i++) { + skeletonLimb->skinAnimLimbData.limbModifications[i].vtxCount = skeletonLimb->skinLimbModifVertexArrays[i].size(); + skeletonLimb->skinAnimLimbData.limbModifications[i].skinVertices = skeletonLimb->skinLimbModifVertexArrays[i].data(); + + skeletonLimb->skinAnimLimbData.limbModifications[i].transformCount = skeletonLimb->skinLimbModifTransformationArrays[i].size(); + skeletonLimb->skinAnimLimbData.limbModifications[i].limbTransformations = skeletonLimb->skinLimbModifTransformationArrays[i].data(); + + skeletonLimb->skinAnimLimbData.limbModifications[i].unk_4 = skeletonLimb->skinLimbModifArray[i].unk_4; + } + + skeletonLimb->limbData.skinLimb.segment = &skeletonLimb->skinAnimLimbData; + } + } +} +void SkeletonLimbFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) +{ + std::shared_ptr skelLimb = std::static_pointer_cast(resource); + + std::string limbType = reader->Attribute("Type"); + + // OTRTODO + skelLimb->limbType = LimbType::LOD; + + // skelLimb->legTransX = reader->FloatAttribute("LegTransX"); + // skelLimb->legTransY = reader->FloatAttribute("LegTransY"); + // skelLimb->legTransZ = reader->FloatAttribute("LegTransZ"); + skelLimb->rotX = reader->IntAttribute("RotX"); + skelLimb->rotY = reader->IntAttribute("RotY"); + skelLimb->rotZ = reader->IntAttribute("RotZ"); + + // skelLimb->transX = reader->IntAttribute("TransX"); + // skelLimb->transY = reader->IntAttribute("TransY"); + // skelLimb->transZ = reader->IntAttribute("TransZ"); + + skelLimb->transX = (int)reader->FloatAttribute("LegTransX"); + skelLimb->transY = (int)reader->FloatAttribute("LegTransY"); + skelLimb->transZ = (int)reader->FloatAttribute("LegTransZ"); + + skelLimb->childIndex = reader->IntAttribute("ChildIndex"); + skelLimb->siblingIndex = reader->IntAttribute("SiblingIndex"); + + // skelLimb->childPtr = reader->Attribute("ChildLimb"); + // skelLimb->siblingPtr = reader->Attribute("SiblingLimb"); + skelLimb->dListPtr = reader->Attribute("DisplayList1"); + + if (std::string(reader->Attribute("DisplayList1")) == "gEmptyDL") { + skelLimb->dListPtr = ""; + } + + auto& limbData = skelLimb->limbData; + + limbData.lodLimb.jointPos.x = skelLimb->transX; + limbData.lodLimb.jointPos.y = skelLimb->transY; + limbData.lodLimb.jointPos.z = skelLimb->transZ; + + if (skelLimb->dListPtr != "") { + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess((const char*)skelLimb->dListPtr.c_str()); + limbData.lodLimb.dLists[0] = (Gfx*)(res ? res->GetRawPointer() : nullptr); + } else { + limbData.lodLimb.dLists[0] = nullptr; + } + + limbData.lodLimb.dLists[1] = nullptr; + + limbData.lodLimb.child = skelLimb->childIndex; + limbData.lodLimb.sibling = skelLimb->siblingIndex; + + // skelLimb->dList2Ptr = reader->Attribute("DisplayList2"); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/SkeletonLimbFactory.h b/mm/2s2h/resource/importer/SkeletonLimbFactory.h new file mode 100644 index 000000000..8480a0126 --- /dev/null +++ b/mm/2s2h/resource/importer/SkeletonLimbFactory.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class SkeletonLimbFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + std::shared_ptr + ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) override; +}; + +class SkeletonLimbFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; +}; +}; // namespace LUS + diff --git a/mm/2s2h/resource/importer/TextFactory.cpp b/mm/2s2h/resource/importer/TextFactory.cpp new file mode 100644 index 000000000..7d7ffb4f3 --- /dev/null +++ b/mm/2s2h/resource/importer/TextFactory.cpp @@ -0,0 +1,93 @@ +#include "2s2h/resource/importer/TextFactory.h" +#include "2s2h/resource/type/Text.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +TextFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + default: + // VERSION NOT SUPPORTED + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Text with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +std::shared_ptr +TextFactory::ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Text with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileXML(reader, resource); + + return resource; +} + +void LUS::TextFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr text = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, text); + + uint32_t msgCount = reader->ReadUInt32(); + text->messages.reserve(msgCount); + + for (uint32_t i = 0; i < msgCount; i++) { + MessageEntry entry; + entry.id = reader->ReadUInt16(); + entry.textboxType = reader->ReadUByte(); + entry.textboxYPos = reader->ReadUByte(); + entry.msg = reader->ReadString(); + + text->messages.push_back(entry); + } +} +void TextFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) { + std::shared_ptr txt = std::static_pointer_cast(resource); + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + + if (childName == "TextEntry") { + MessageEntry entry; + entry.id = child->IntAttribute("ID"); + entry.textboxType = child->IntAttribute("TextboxType"); + entry.textboxYPos = child->IntAttribute("TextboxYPos"); + entry.msg = child->Attribute("Message"); + entry.msg += "\x2"; + + txt->messages.push_back(entry); + int bp = 0; + } + + child = child->NextSiblingElement(); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/TextFactory.h b/mm/2s2h/resource/importer/TextFactory.h new file mode 100644 index 000000000..7a6ae2841 --- /dev/null +++ b/mm/2s2h/resource/importer/TextFactory.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class TextFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + std::shared_ptr + ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) override; +}; + +class TextFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; +}; +}; // namespace LUS + diff --git a/mm/2s2h/resource/importer/TextMMFactory.cpp b/mm/2s2h/resource/importer/TextMMFactory.cpp new file mode 100644 index 000000000..3c2892001 --- /dev/null +++ b/mm/2s2h/resource/importer/TextMMFactory.cpp @@ -0,0 +1,100 @@ +#include "2s2h/resource/importer/TextMMFactory.h" +#include "2s2h/resource/type/TextMM.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +TextMMFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + default: + // VERSION NOT SUPPORTED + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Text with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +std::shared_ptr TextMMFactory::ReadResourceXML(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Text with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileXML(reader, resource); + + return resource; +} + +void LUS::TextMMFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { + std::shared_ptr text = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, text); + + uint32_t msgCount = reader->ReadUInt32(); + text->messages.reserve(msgCount); + + for (uint32_t i = 0; i < msgCount; i++) { + MessageEntryMM entry; + entry.id = reader->ReadUInt16(); + entry.textboxType = reader->ReadUByte(); + entry.textboxYPos = reader->ReadUByte(); + entry.icon = reader->ReadUByte(); + entry.nextMessageID = reader->ReadUInt16(); + entry.firstItemCost = reader->ReadUInt16(); + entry.secondItemCost = reader->ReadUInt16(); + entry.msg = reader->ReadString(); + + text->messages.push_back(entry); + } +} +void TextMMFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) { + std::shared_ptr txt = std::static_pointer_cast(resource); + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + + if (childName == "TextEntry") { + MessageEntryMM entry; + entry.id = child->IntAttribute("ID"); + entry.textboxType = child->IntAttribute("TextboxType"); + entry.textboxYPos = child->IntAttribute("TextboxYPos"); + + // BENTODO: MM Unique Fields + + + entry.msg = child->Attribute("Message"); + entry.msg += "\x2"; + + txt->messages.push_back(entry); + int bp = 0; + } + + child = child->NextSiblingElement(); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/TextMMFactory.h b/mm/2s2h/resource/importer/TextMMFactory.h new file mode 100644 index 000000000..0322a3762 --- /dev/null +++ b/mm/2s2h/resource/importer/TextMMFactory.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class TextMMFactory : public ResourceFactory +{ + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + std::shared_ptr + ReadResourceXML(std::shared_ptr initData, tinyxml2::XMLElement *reader) override; +}; + +class TextMMFactoryV0 : public ResourceVersionFactory +{ + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; +}; +}; // namespace LUS + diff --git a/mm/2s2h/resource/importer/TextureAnimationFactory.cpp b/mm/2s2h/resource/importer/TextureAnimationFactory.cpp new file mode 100644 index 000000000..cc33beecf --- /dev/null +++ b/mm/2s2h/resource/importer/TextureAnimationFactory.cpp @@ -0,0 +1,124 @@ +#include "2s2h/resource/importer/TextureAnimationFactory.h" +#include "2s2h/resource/type/TextureAnimation.h" +#include +#include "spdlog/spdlog.h" + +namespace LUS { + +std::shared_ptr TextureAnimationFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load Texture Animation with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::TextureAnimationFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr tAnim = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, tAnim); + + size_t numEntries = reader->ReadUInt32(); + + for (size_t i = 0; i < numEntries; i++) { + AnimatedMaterial anim; + anim.segment = reader->ReadInt8(); + anim.type = reader->ReadInt8(); + + switch ((TextureAnimationParamsType)anim.type) { + case TextureAnimationParamsType::SingleScroll: { + auto* e = new AnimatedMatTexScrollParams; + e->xStep = reader->ReadInt8(); + e->yStep = reader->ReadInt8(); + e->width = reader->ReadUByte(); + e->height = reader->ReadUByte(); + anim.params = e; + break; + } + case TextureAnimationParamsType::DualScroll: { + auto* e = new AnimatedMatTexScrollParams[2]; + e[0].xStep = reader->ReadInt8(); + e[0].yStep = reader->ReadInt8(); + e[0].width = reader->ReadUByte(); + e[0].height = reader->ReadUByte(); + e[1].xStep = reader->ReadInt8(); + e[1].yStep = reader->ReadInt8(); + e[1].width = reader->ReadUByte(); + e[1].height = reader->ReadUByte(); + anim.params = e; + break; + } + case TextureAnimationParamsType::ColorChange: + case TextureAnimationParamsType::ColorChangeLERP: + case TextureAnimationParamsType::ColorChangeLagrange: { + auto* e = new AnimatedMatColorParams; + e->keyFrameLength = reader->ReadUInt16(); + e->keyFrameCount = reader->ReadUInt16(); + + size_t frames = reader->ReadUInt32(); + + e->keyFrames = new uint16_t[frames]; + for (size_t i = 0; i < frames; i++) { + e->keyFrames[i] = reader->ReadUInt16(); + } + size_t primColorSize = reader->ReadUInt32(); + e->primColors = new F3DPrimColor[primColorSize]; + + for (size_t i = 0; i < primColorSize; i++) { + e->primColors[i].r = reader->ReadUByte(); + e->primColors[i].g = reader->ReadUByte(); + e->primColors[i].b = reader->ReadUByte(); + e->primColors[i].a = reader->ReadUByte(); + e->primColors[i].lodFrac = reader->ReadUByte(); + } + + size_t envColorSize = reader->ReadUInt16(); + e->envColors = new F3DEnvColor[envColorSize]; + for (size_t i = 0; i < envColorSize; i++) { + e->envColors[i].r = reader->ReadUByte(); + e->envColors[i].g = reader->ReadUByte(); + e->envColors[i].b = reader->ReadUByte(); + e->envColors[i].a = reader->ReadUByte(); + } + anim.params = e; + break; + } + case TextureAnimationParamsType::TextureCycle: { + auto* e = new AnimatedMatTexCycleParams; + + e->keyFrameLength = reader->ReadUInt16(); + e->textureList = new void*[e->keyFrameLength]; + e->textureIndexList = new uint8_t[e->keyFrameLength]; + + for (size_t i = 0; i < e->keyFrameLength; i++) { + e->textureList[i] = ResourceGetDataByName(reader->ReadString().c_str()); + } + for (size_t i = 0; i < e->keyFrameLength; i++) { + e->textureIndexList[i] = reader->ReadUByte(); + } + anim.params = e; + break; + } + case TextureAnimationParamsType::Empty: { + anim.params = nullptr; + break; + } + } + tAnim->anims.emplace_back(anim); + } +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/TextureAnimationFactory.h b/mm/2s2h/resource/importer/TextureAnimationFactory.h new file mode 100644 index 000000000..1bc52e246 --- /dev/null +++ b/mm/2s2h/resource/importer/TextureAnimationFactory.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactory.h" + +namespace LUS { +class TextureAnimationFactory : public ResourceFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; + +}; + +class TextureAnimationFactoryV0 : public ResourceVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.cpp b/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.cpp new file mode 100644 index 000000000..61dba4ca3 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.cpp @@ -0,0 +1,38 @@ +#include "2s2h/resource/importer/scenecommand/EndMarkerFactory.h" +#include "2s2h/resource/type/scenecommand/EndMarker.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +EndMarkerFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load EndMarker with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::EndMarkerFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr endMarker = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, endMarker); + + ReadCommandId(endMarker, reader); + + // This has no data. +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.h b/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.h new file mode 100644 index 000000000..a2580c077 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/EndMarkerFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class EndMarkerFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class EndMarkerFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.cpp new file mode 100644 index 000000000..a2ed3c829 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.cpp @@ -0,0 +1,10 @@ +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" +#include "spdlog/spdlog.h" + +namespace LUS { +void SceneCommandVersionFactory::ReadCommandId(std::shared_ptr command, std::shared_ptr reader) { + command->cmdId = (SceneCommandID)reader->ReadInt32(); +} +} + \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.h b/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.h new file mode 100644 index 000000000..b1449fad4 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SceneCommandFactory.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include "Resource.h" +#include "ResourceFactory.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" + +namespace LUS { +class SceneCommandFactory : public ResourceFactory {}; + +class SceneCommandVersionFactory : public ResourceVersionFactory { +protected: + void ReadCommandId(std::shared_ptr command, std::shared_ptr reader); +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.cpp new file mode 100644 index 000000000..4ad852fb1 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.cpp @@ -0,0 +1,55 @@ +#include "2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.h" +#include "2s2h/resource/type/scenecommand/SetActorCutsceneList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetActorCutsceneListFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetActorList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + + +void SetActorCutsceneListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setActorCsList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setActorCsList); + + ReadCommandId(setActorCsList, reader); + + setActorCsList->numEntries = reader->ReadUInt32(); + setActorCsList->entries.reserve(setActorCsList->numEntries); + + for (uint32_t i = 0; i < setActorCsList->numEntries; i++) { + CutsceneEntry e; + e.priority = reader->ReadInt16(); + e.length = reader->ReadInt16(); + e.csCamId = reader->ReadInt16(); + e.scriptIndex = reader->ReadInt16(); + e.additionalCsId = reader->ReadInt16(); + e.endSfx = reader->ReadUByte(); + e.customValue = reader->ReadUByte(); + e.hudVisibility = reader->ReadInt16(); + e.endCam = reader->ReadUByte(); + e.letterboxSize = reader->ReadUByte(); + setActorCsList->entries.emplace_back(e); + } + +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.h new file mode 100644 index 000000000..23314c129 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetActorCutsceneListFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetActorCutsceneListFactory : public SceneCommandFactory { + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetActorCutsceneListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + +}; + +} diff --git a/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.cpp new file mode 100644 index 000000000..32aa3db5f --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.cpp @@ -0,0 +1,53 @@ +#include "2s2h/resource/importer/scenecommand/SetActorListFactory.h" +#include "2s2h/resource/type/scenecommand/SetActorList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetActorListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetActorList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetActorListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setActorList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setActorList); + + ReadCommandId(setActorList, reader); + + setActorList->numActors = reader->ReadUInt32(); + setActorList->actorList.reserve(setActorList->numActors); + for (uint32_t i = 0; i < setActorList->numActors; i++) { + ActorEntry entry; + + entry.id = reader->ReadUInt16(); + entry.pos.x = reader->ReadInt16(); + entry.pos.y = reader->ReadInt16(); + entry.pos.z = reader->ReadInt16(); + entry.rot.x = reader->ReadInt16(); + entry.rot.y = reader->ReadInt16(); + entry.rot.z = reader->ReadInt16(); + entry.params = reader->ReadUInt16(); + + setActorList->actorList.push_back(entry); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.h new file mode 100644 index 000000000..5958ac576 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetActorListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetActorListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetActorListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp new file mode 100644 index 000000000..d68d65c34 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp @@ -0,0 +1,49 @@ +#include "2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.h" +#include "2s2h/resource/type/scenecommand/SetAlternateHeaders.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultraship.h" + +namespace LUS { +std::shared_ptr SetAlternateHeadersFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetAlternateHeaders with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetAlternateHeadersFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setAlternateHeaders = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setAlternateHeaders); + + ReadCommandId(setAlternateHeaders, reader); + + setAlternateHeaders->numHeaders = reader->ReadUInt32(); + setAlternateHeaders->headers.reserve(setAlternateHeaders->numHeaders); + for (uint32_t i = 0; i < setAlternateHeaders->numHeaders; i++) { + auto headerName = reader->ReadString(); + if (!headerName.empty()) { + setAlternateHeaders->headers.push_back(std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(headerName.c_str()))); + } else { + setAlternateHeaders->headers.push_back(nullptr); + } + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.h b/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.h new file mode 100644 index 000000000..efa96f68f --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetAlternateHeadersFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetAlternateHeadersFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetAlternateHeadersFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.cpp new file mode 100644 index 000000000..e6e9865ec --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.cpp @@ -0,0 +1,41 @@ +#include "2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.h" +#include "2s2h/resource/type/scenecommand/SetAnimatedMaterialList.h" +#include "2s2h/resource/type/TextureAnimation.h" +#include "spdlog/spdlog.h" +#include + +namespace LUS { + +std::shared_ptr LUS::SetAnimatedMaterialListFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetAnimatedMaterialList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetAnimatedMaterialListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setAnimatedMat = + std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setAnimatedMat); + + ReadCommandId(setAnimatedMat, reader); + AnimatedMaterialData* res = (AnimatedMaterialData*)ResourceGetDataByName(reader->ReadString().c_str()); + setAnimatedMat->mat = res; +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.h new file mode 100644 index 000000000..22e3fff69 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetAnimatedMaterialListFactory.h @@ -0,0 +1,17 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetAnimatedMaterialListFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetAnimatedMaterialListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +} diff --git a/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp new file mode 100644 index 000000000..caa46cefd --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp @@ -0,0 +1,39 @@ +#include "2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetCameraSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetCameraSettingsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetCameraSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetCameraSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setCameraSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setCameraSettings); + + ReadCommandId(setCameraSettings, reader); + // BENTODO in MM this scene command is only used as a signal to have the scene system mark an area as visted. We should make a new command factory for this but this is fine for now. + //setCameraSettings->settings.cameraMovement = reader->ReadInt8(); + //setCameraSettings->settings.worldMapArea = reader->ReadInt32(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.h new file mode 100644 index 000000000..e17150807 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetCameraSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetCameraSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp new file mode 100644 index 000000000..4badbb055 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp @@ -0,0 +1,39 @@ +#include "2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.h" +#include "2s2h/resource/type/scenecommand/SetCollisionHeader.h" +#include "libultraship/libultraship.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetCollisionHeaderFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetCollisionHeader with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetCollisionHeaderFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setCollisionHeader = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setCollisionHeader); + + ReadCommandId(setCollisionHeader, reader); + + setCollisionHeader->fileName = reader->ReadString(); + setCollisionHeader->collisionHeader = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCollisionHeader->fileName.c_str())); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.h b/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.h new file mode 100644 index 000000000..76655015d --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCollisionHeaderFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetCollisionHeaderFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetCollisionHeaderFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp new file mode 100644 index 000000000..445f64cb6 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp @@ -0,0 +1,55 @@ +#include "2s2h/resource/importer/scenecommand/SetCsCameraFactory.h" +#include "2s2h/resource/type/scenecommand/SetCsCamera.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetCsCameraFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetCsCamera with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetCsCameraFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setCsCamera = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setCsCamera); + + ReadCommandId(setCsCamera, reader); + + size_t camSize = reader->ReadUInt32(); + + for (size_t i = 0; i < camSize; i++) { + ActorCsCamInfoData data; + data.setting = reader->ReadUInt16(); + data.count = reader->ReadUInt16(); + if (data.count == 0) { + data.actorCsCamFuncData = nullptr; + continue; + } + data.actorCsCamFuncData = new z64Vec3s[data.count]; + for (size_t j = 0; j < data.count; j++) { + data.actorCsCamFuncData[j].x = reader->ReadInt16(); + data.actorCsCamFuncData[j].y = reader->ReadInt16(); + data.actorCsCamFuncData[j].z = reader->ReadInt16(); + } + setCsCamera->csCamera.emplace_back(data); + } + +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.h b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.h new file mode 100644 index 000000000..4be361364 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetCsCameraFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetCsCameraFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.cpp new file mode 100644 index 000000000..ce429d8c1 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.cpp @@ -0,0 +1,81 @@ +#include "2s2h/resource/importer/scenecommand/SetCutscenesFactory.h" +#include "2s2h/resource/type/scenecommand/SetCutscenes.h" +#include +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetCutscenesFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetCutscenes with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetCutscenesFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setCutscenes = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setCutscenes); + + ReadCommandId(setCutscenes, reader); + + setCutscenes->fileName = reader->ReadString(); + setCutscenes->cutscene = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCutscenes->fileName.c_str())); +} + +std::shared_ptr SetCutsceneFactoryMM::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetCutscenes with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetCutscenesFactoryMMV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setCutscenes = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setCutscenes); + + ReadCommandId(setCutscenes, reader); + + size_t numCs = reader->ReadUByte(); + + for (size_t i = 0; i < numCs; i++) { + CutsceneScriptEntry entry; + std::string path = reader->ReadString(); + entry.exit = reader->ReadUInt16(); + entry.entrance = reader->ReadUByte(); + entry.flag = reader->ReadUByte(); + entry.data = ResourceGetDataByName(path.c_str()); + setCutscenes->entries.emplace_back(entry); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.h b/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.h new file mode 100644 index 000000000..905eab39a --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetCutscenesFactory.h @@ -0,0 +1,28 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetCutscenesFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetCutscenesFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +class SetCutsceneFactoryMM : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetCutscenesFactoryMMV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.cpp new file mode 100644 index 000000000..c9bdfef54 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.cpp @@ -0,0 +1,38 @@ +#include "2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetEchoSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetEchoSettingsFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetEchoSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetEchoSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setEchoSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setEchoSettings); + + ReadCommandId(setEchoSettings, reader); + + setEchoSettings->settings.echo = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.h new file mode 100644 index 000000000..20673aa57 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetEchoSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetEchoSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetEchoSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.cpp new file mode 100644 index 000000000..34a50248a --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.cpp @@ -0,0 +1,46 @@ +#include "2s2h/resource/importer/scenecommand/SetEntranceListFactory.h" +#include "2s2h/resource/type/scenecommand/SetEntranceList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetEntranceListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetEntranceListList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetEntranceListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setEntranceList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setEntranceList); + + ReadCommandId(setEntranceList, reader); + + setEntranceList->numEntrances = reader->ReadUInt32(); + setEntranceList->entrances.reserve(setEntranceList->numEntrances); + for (uint32_t i = 0; i < setEntranceList->numEntrances; i++) { + EntranceEntry entranceEntry; + + entranceEntry.spawn = reader->ReadInt8(); + entranceEntry.room = reader->ReadInt8(); + + setEntranceList->entrances.push_back(entranceEntry); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.h new file mode 100644 index 000000000..2bb1186ba --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetEntranceListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetEntranceListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetEntranceListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.cpp new file mode 100644 index 000000000..4c5ddcb88 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.cpp @@ -0,0 +1,41 @@ +#include "2s2h/resource/importer/scenecommand/SetExitListFactory.h" +#include "2s2h/resource/type/scenecommand/SetExitList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetExitListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared( initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetExitList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetExitListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setExitList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setExitList); + + ReadCommandId(setExitList, reader); + + setExitList->numExits = reader->ReadUInt32(); + setExitList->exits.reserve(setExitList->numExits); + for (uint32_t i = 0; i < setExitList->numExits; i++) { + setExitList->exits.push_back(reader->ReadUInt16()); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.h new file mode 100644 index 000000000..e04ab4ba0 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetExitListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetExitListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetExitListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.cpp new file mode 100644 index 000000000..ab83635bf --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.cpp @@ -0,0 +1,58 @@ +#include "2s2h/resource/importer/scenecommand/SetLightListFactory.h" +#include "2s2h/resource/type/scenecommand/SetLightList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetLightListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetLightList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetLightListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setLightList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setLightList); + + ReadCommandId(setLightList, reader); + + setLightList->numLights = reader->ReadUInt32(); + setLightList->lightList.reserve(setLightList->numLights); + for (uint32_t i = 0; i < setLightList->numLights; i++) { + LightInfo light; + + light.type = reader->ReadUByte(); + + light.params.point.x = reader->ReadInt16(); + light.params.point.y = reader->ReadInt16(); + light.params.point.z = reader->ReadInt16(); + + light.params.point.color[0] = reader->ReadUByte(); // r + light.params.point.color[1] = reader->ReadUByte(); // g + light.params.point.color[2] = reader->ReadUByte(); // b + + light.params.point.drawGlow = reader->ReadUByte(); + light.params.point.radius = reader->ReadInt16(); + + setLightList->lightList.push_back(light); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.h new file mode 100644 index 000000000..c099b82c5 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetLightListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetLightListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetLightListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.cpp new file mode 100644 index 000000000..c13aeffec --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.cpp @@ -0,0 +1,70 @@ +#include "2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetLightingSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetLightingSettingsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetLightingSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetLightingSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setLightingSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setLightingSettings); + + ReadCommandId(setLightingSettings, reader); + + uint32_t count = reader->ReadInt32(); + setLightingSettings->settings.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + EnvLightSettings lightSettings; + lightSettings.ambientColor[0] = reader->ReadInt8(); + lightSettings.ambientColor[1] = reader->ReadInt8(); + lightSettings.ambientColor[2] = reader->ReadInt8(); + + lightSettings.light1Dir[0] = reader->ReadInt8(); + lightSettings.light1Dir[1] = reader->ReadInt8(); + lightSettings.light1Dir[2] = reader->ReadInt8(); + + lightSettings.light1Color[0] = reader->ReadInt8(); + lightSettings.light1Color[1] = reader->ReadInt8(); + lightSettings.light1Color[2] = reader->ReadInt8(); + + lightSettings.light2Dir[0] = reader->ReadInt8(); + lightSettings.light2Dir[1] = reader->ReadInt8(); + lightSettings.light2Dir[2] = reader->ReadInt8(); + + lightSettings.light2Color[0] = reader->ReadInt8(); + lightSettings.light2Color[1] = reader->ReadInt8(); + lightSettings.light2Color[2] = reader->ReadInt8(); + + lightSettings.fogColor[0] = reader->ReadInt8(); + lightSettings.fogColor[1] = reader->ReadInt8(); + lightSettings.fogColor[2] = reader->ReadInt8(); + + lightSettings.fogNear = reader->ReadInt16(); + lightSettings.fogFar = reader->ReadUInt16(); + setLightingSettings->settings.push_back(lightSettings); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.h new file mode 100644 index 000000000..b25f85a97 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetLightingSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetLightingSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetLightingSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.cpp new file mode 100644 index 000000000..dcb3f4c10 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.cpp @@ -0,0 +1,169 @@ +#include "2s2h/resource/importer/scenecommand/SetMeshFactory.h" +#include "2s2h/resource/type/scenecommand/SetMesh.h" +#include "spdlog/spdlog.h" +#include "libultraship/libultraship.h" + +namespace LUS { +std::shared_ptr +SetMeshFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetMesh with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetMeshFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setMesh = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setMesh); + + ReadCommandId(setMesh, reader); + + setMesh->data = reader->ReadInt8(); + + setMesh->meshHeader.base.type = reader->ReadInt8(); + int32_t polyNum = 1; + + if (setMesh->meshHeader.base.type != 1) { + polyNum = reader->ReadInt8(); + if (setMesh->meshHeader.base.type == 0) { + setMesh->meshHeader.polygon0.num = polyNum; + } else if (setMesh->meshHeader.base.type == 2) { + setMesh->meshHeader.polygon2.num = polyNum; + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } + } + + if (setMesh->meshHeader.base.type == 2) { + setMesh->dlists2.reserve(polyNum); + } else { + setMesh->dlists.reserve(setMesh->meshHeader.polygon0.num); + } + + for (int32_t i = 0; i < polyNum; i++) { + if (setMesh->meshHeader.base.type == 0) { + PolygonDlist dlist; + + int32_t polyType = reader->ReadInt8(); // Unused + std::string meshOpa = reader->ReadString(); + std::string meshXlu = reader->ReadString(); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->dlists.push_back(dlist); + } else if (setMesh->meshHeader.base.type == 1) { + PolygonDlist pType; + + setMesh->meshHeader.polygon1.format = reader->ReadUByte(); + std::string imgOpa = reader->ReadString(); + std::string imgXlu = reader->ReadString(); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgXlu.c_str()); + pType.opa = imgOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + pType.xlu = imgXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + int32_t bgImageCount = reader->ReadUInt32(); + setMesh->images.reserve(bgImageCount); + + for (int32_t i = 0; i < bgImageCount; i++) { + BgImage image; + image.unk_00 = reader->ReadUInt16(); + image.id = reader->ReadUByte(); + std::string imagePath = "__OTR__" + reader->ReadString(); + setMesh->imagePaths.push_back(imagePath); + image.source = (void*)setMesh->imagePaths.back().c_str(); + image.unk_0C = reader->ReadUInt32(); + image.tlut = reader->ReadUInt32(); + image.width = reader->ReadUInt16(); + image.height = reader->ReadUInt16(); + image.fmt = reader->ReadUByte(); + image.siz = reader->ReadUByte(); + image.mode0 = reader->ReadUInt16(); + image.tlutCount = reader->ReadUInt16(); + + if (setMesh->meshHeader.polygon1.format == 1) { + setMesh->meshHeader.polygon1.single.source = image.source; + setMesh->meshHeader.polygon1.single.unk_0C = image.unk_0C; + setMesh->meshHeader.polygon1.single.tlut = (void*)image.tlut; // OTRTODO: type of bgimage.tlut should be uintptr_t + setMesh->meshHeader.polygon1.single.width = image.width; + setMesh->meshHeader.polygon1.single.height = image.height; + setMesh->meshHeader.polygon1.single.fmt = image.fmt; + setMesh->meshHeader.polygon1.single.siz = image.siz; + setMesh->meshHeader.polygon1.single.mode0 = image.mode0; + setMesh->meshHeader.polygon1.single.tlutCount = image.tlutCount; + } else { + setMesh->images.push_back(image); + } + } + + if (setMesh->meshHeader.polygon1.format != 1) { + setMesh->meshHeader.polygon1.multi.count = bgImageCount; + } + + int32_t polyType = reader->ReadInt8(); // Unused?? + + std::string meshOpa = reader->ReadString(); + std::string meshXlu = reader->ReadString(); + + opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + pType.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + pType.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->dlists.push_back(pType); + } else if (setMesh->meshHeader.base.type == 2) { + PolygonDlist2 dlist; + + int32_t polyType = reader->ReadInt8(); // Unused + dlist.pos.x = reader->ReadInt16(); + dlist.pos.y = reader->ReadInt16(); + dlist.pos.z = reader->ReadInt16(); + dlist.unk_06 = reader->ReadInt16(); + + std::string meshOpa = reader->ReadString(); + std::string meshXlu = reader->ReadString(); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->dlists2.push_back(dlist); + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } + } + + if (setMesh->meshHeader.base.type == 2) { + setMesh->meshHeader.polygon2.start = setMesh->dlists2.data(); + } else if (setMesh->meshHeader.base.type == 0) { + setMesh->meshHeader.polygon0.start = setMesh->dlists.data(); + } else if (setMesh->meshHeader.base.type == 1) { + setMesh->meshHeader.polygon1.multi.list = setMesh->images.data(); + setMesh->meshHeader.polygon1.dlist = (Gfx*)setMesh->dlists.data(); + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.h b/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.h new file mode 100644 index 000000000..3ae72fdbc --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMeshFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetMeshFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetMeshFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.cpp new file mode 100644 index 000000000..dae215ab1 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.cpp @@ -0,0 +1,50 @@ +#include "2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.h" +#include "2s2h/resource/type/scenecommand/SetMinimapChests.h" +#include "spdlog/spdlog.h" + +namespace LUS { + +std::shared_ptr SetMinimapChestsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetMinimapChestsFactory with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void SetMinimapChestsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr chests = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, chests); + + ReadCommandId(chests, reader); + + size_t size = reader->ReadUInt32(); + + chests->chests.reserve(size); + + for (size_t i = 0; i < size; i++) { + MinimapChestData d; + d.unk_0 = reader->ReadUInt16(); + d.unk_2 = reader->ReadUInt16(); + d.unk_4 = reader->ReadUInt16(); + d.unk_6 = reader->ReadUInt16(); + d.unk_8 = reader->ReadUInt16(); + chests->chests.emplace_back(d); + } +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.h new file mode 100644 index 000000000..941405c40 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMinimapChestsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetMinimapChestsFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetMinimapChestsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +} \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.cpp new file mode 100644 index 000000000..43eb4b496 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.cpp @@ -0,0 +1,50 @@ +#include "2s2h/resource/importer/scenecommand/SetMinimapListFactory.h" +#include "2s2h/resource/type/scenecommand/SetMinimapList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetMinimapListFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetMinimapListFactory with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} +void SetMinimapListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr mapList = std::static_pointer_cast(resource); + + ResourceVersionFactory::ParseFileBinary(reader, mapList); + + ReadCommandId(mapList, reader); + + size_t size = reader->ReadUInt32(); + + mapList->list.scale = reader->ReadUInt16(); + mapList->entries.reserve(size); + + for (size_t i = 0; i < size; i++) { + MinimapEntryData data; + data.mapId = reader->ReadUInt16(); + data.unk2 = reader->ReadUInt16(); + data.unk4 = reader->ReadUInt16(); + data.unk6 = reader->ReadUInt16(); + data.unk8 = reader->ReadUInt16(); + mapList->entries.emplace_back(data); + } + mapList->list.entry = mapList->entries.data(); +} +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.h new file mode 100644 index 000000000..d8a5fd643 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetMinimapListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetMinimapListFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetMinimapListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.cpp new file mode 100644 index 000000000..274407c00 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.cpp @@ -0,0 +1,42 @@ +#include "2s2h/resource/importer/scenecommand/SetObjectListFactory.h" +#include "2s2h/resource/type/scenecommand/SetObjectList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetObjectListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetObjectList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetObjectListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setObjectList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setObjectList); + + ReadCommandId(setObjectList, reader); + + setObjectList->numObjects = reader->ReadUInt32(); + setObjectList->objects.reserve(setObjectList->numObjects); + for (uint32_t i = 0; i < setObjectList->numObjects; i++) { + setObjectList->objects.push_back(reader->ReadUInt16()); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.h new file mode 100644 index 000000000..b977576d3 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetObjectListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetObjectListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetObjectListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.cpp new file mode 100644 index 000000000..a361a0915 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.cpp @@ -0,0 +1,82 @@ +#include "2s2h/resource/importer/scenecommand/SetPathwaysFactory.h" +#include "2s2h/resource/type/scenecommand/SetPathways.h" +#include "spdlog/spdlog.h" +#include + +namespace LUS { +std::shared_ptr +SetPathwaysFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetPathways with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetPathwaysFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setPathways = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setPathways); + + ReadCommandId(setPathways, reader); + + setPathways->numPaths = reader->ReadUInt32(); + setPathways->paths.reserve(setPathways->numPaths); + for (uint32_t i = 0; i < setPathways->numPaths; i++) { + std::string pathFileName = reader->ReadString(); + auto path = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str())); + setPathways->paths.push_back(path->GetPointer()); + } +} + +std::shared_ptr SetPathwaysMMFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetPathwaysMM with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetPathwaysMMFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setPathways = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setPathways); + + ReadCommandId(setPathways, reader); + + setPathways->numPaths = reader->ReadUInt32(); + setPathways->paths.reserve(setPathways->numPaths); + for (uint32_t i = 0; i < setPathways->numPaths; i++) { + std::string pathFileName = reader->ReadString(); + auto path = std::static_pointer_cast( + LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str())); + setPathways->paths.push_back(path->GetPointer()); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.h b/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.h new file mode 100644 index 000000000..544ef02dc --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetPathwaysFactory.h @@ -0,0 +1,28 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetPathwaysFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetPathwaysFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +class SetPathwaysMMFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetPathwaysMMFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp new file mode 100644 index 000000000..e2c5df85f --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp @@ -0,0 +1,78 @@ +#include "2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h" +#include "2s2h/resource/type/scenecommand/SetRoomBehavior.h" +#include "spdlog/spdlog.h" + +namespace LUS { +// OOT +#if 0 +std::shared_ptr +SetRoomBehaviorFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetRoomBehavior with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetRoomBehaviorFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setRoomBehavior = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setRoomBehavior); + + ReadCommandId(setRoomBehavior, reader); + + setRoomBehavior->roomBehavior.gameplayFlags = reader->ReadInt8(); + setRoomBehavior->roomBehavior.gameplayFlags2 = reader->ReadInt32(); +} +#endif +// MM + +std::shared_ptr SetRoomBehaviorMMFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetRoomBehavior with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void SetRoomBehaviorMMFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setRoomBehavior = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setRoomBehavior); + + ReadCommandId(setRoomBehavior, reader); + + setRoomBehavior->roomBehavior.gameplayFlags = reader->ReadInt8(); + setRoomBehavior->roomBehavior.currRoomUnk2 = reader->ReadInt8(); + setRoomBehavior->roomBehavior.currRoomUnk5 = reader->ReadInt8(); + setRoomBehavior->roomBehavior.msgCtxUnk = reader->ReadInt8(); + setRoomBehavior->roomBehavior.enablePointLights = reader->ReadInt8(); + setRoomBehavior->roomBehavior.kankyoContextUnkE2 = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h new file mode 100644 index 000000000..a449a1c8f --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h @@ -0,0 +1,28 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetRoomBehaviorFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetRoomBehaviorFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +class SetRoomBehaviorMMFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetRoomBehaviorMMFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.cpp new file mode 100644 index 000000000..ac4040afa --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.cpp @@ -0,0 +1,50 @@ +#include "2s2h/resource/importer/scenecommand/SetRoomListFactory.h" +#include "2s2h/resource/type/scenecommand/SetRoomList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetRoomListFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetRoomList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetRoomListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setRoomList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setRoomList); + + ReadCommandId(setRoomList, reader); + + setRoomList->numRooms = reader->ReadInt32(); + setRoomList->rooms.reserve(setRoomList->numRooms); + for (uint32_t i = 0; i < setRoomList->numRooms; i++) { + RomFile room; + + setRoomList->fileNames.push_back(reader->ReadString()); + + room.fileName = (char*)setRoomList->fileNames.back().c_str(); + room.vromStart = reader->ReadInt32(); + room.vromEnd = reader->ReadInt32(); + + setRoomList->rooms.push_back(room); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.h new file mode 100644 index 000000000..eeb099aa8 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetRoomListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetRoomListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp new file mode 100644 index 000000000..c2670e0fd --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp @@ -0,0 +1,38 @@ +#include "2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.h" +#include "2s2h/resource/type/scenecommand/SetSkyboxModifier.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetSkyboxModifierFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetSkyboxModifier with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetSkyboxModifierFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setSkyboxModifier = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setSkyboxModifier); + + ReadCommandId(setSkyboxModifier, reader); + + setSkyboxModifier->modifier.skyboxDisabled = reader->ReadInt8(); + setSkyboxModifier->modifier.sunMoonDisabled = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.h b/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.h new file mode 100644 index 000000000..3880751fe --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSkyboxModifierFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetSkyboxModifierFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetSkyboxModifierFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp new file mode 100644 index 000000000..8ac3b91a4 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp @@ -0,0 +1,40 @@ +#include "2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetSkyboxSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetSkyboxSettingsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetSkyboxSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void SetSkyboxSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setSkyboxSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setSkyboxSettings); + + ReadCommandId(setSkyboxSettings, reader); + + setSkyboxSettings->settings.unk = reader->ReadInt8(); + setSkyboxSettings->settings.skyboxId = reader->ReadInt8(); + setSkyboxSettings->settings.weather = reader->ReadInt8(); + setSkyboxSettings->settings.indoors = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.h new file mode 100644 index 000000000..c75c86673 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSkyboxSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetSkyboxSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetSkyboxSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.cpp new file mode 100644 index 000000000..98ee97f03 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.cpp @@ -0,0 +1,39 @@ +#include "2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetSoundSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetSoundSettingsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetSoundSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetSoundSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setSoundSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setSoundSettings); + + ReadCommandId(setSoundSettings, reader); + + setSoundSettings->settings.reverb = reader->ReadInt8(); + setSoundSettings->settings.natureAmbienceId = reader->ReadInt8(); + setSoundSettings->settings.seqId = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.h new file mode 100644 index 000000000..235c617a2 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSoundSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetSoundSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetSoundSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp new file mode 100644 index 000000000..35fc6614e --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp @@ -0,0 +1,38 @@ +#include "2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.h" +#include "2s2h/resource/type/scenecommand/SetSpecialObjects.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetSpecialObjectsFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr){ + SPDLOG_ERROR("Failed to load SetSpecialObjects with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetSpecialObjectsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setSpecialObjects = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setSpecialObjects); + + ReadCommandId(setSpecialObjects, reader); + + setSpecialObjects->specialObjects.elfMessage = reader->ReadInt8(); + setSpecialObjects->specialObjects.globalObject = reader->ReadInt16(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.h new file mode 100644 index 000000000..b62180a45 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetSpecialObjectsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetSpecialObjectsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetSpecialObjectsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.cpp new file mode 100644 index 000000000..9d95a01ce --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.cpp @@ -0,0 +1,55 @@ +#include "2s2h/resource/importer/scenecommand/SetStartPositionListFactory.h" +#include "2s2h/resource/type/scenecommand/SetStartPositionList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetStartPositionListFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) + { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) + { + SPDLOG_ERROR("Failed to load SetStartPositionList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetStartPositionListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) +{ + std::shared_ptr setStartPositionList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setStartPositionList); + + ReadCommandId(setStartPositionList, reader); + + setStartPositionList->numStartPositions = reader->ReadUInt32(); + setStartPositionList->startPositions.reserve(setStartPositionList->numStartPositions); + for (uint32_t i = 0; i < setStartPositionList->numStartPositions; i++) { + ActorEntry entry; + + entry.id = reader->ReadUInt16(); + entry.pos.x = reader->ReadInt16(); + entry.pos.y = reader->ReadInt16(); + entry.pos.z = reader->ReadInt16(); + entry.rot.x = reader->ReadInt16(); + entry.rot.y = reader->ReadInt16(); + entry.rot.z = reader->ReadInt16(); + entry.params = reader->ReadUInt16(); + + setStartPositionList->startPositions.push_back(entry); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.h new file mode 100644 index 000000000..b029f3a1e --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetStartPositionListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetStartPositionListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetStartPositionListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.cpp new file mode 100644 index 000000000..e3f2d77e5 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.cpp @@ -0,0 +1,39 @@ +#include "2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetTimeSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetTimeSettingsFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetTimeSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetTimeSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setTimeSettings = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setTimeSettings); + + ReadCommandId(setTimeSettings, reader); + + setTimeSettings->settings.hour = reader->ReadInt8(); + setTimeSettings->settings.minute = reader->ReadInt8(); + setTimeSettings->settings.timeIncrement = reader->ReadInt8(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.h new file mode 100644 index 000000000..1482c2892 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetTimeSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetTimeSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetTimeSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.cpp new file mode 100644 index 000000000..611897fbe --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.cpp @@ -0,0 +1,54 @@ +#include "2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.h" +#include "2s2h/resource/type/scenecommand/SetTransitionActorList.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr SetTransitionActorListFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetTransitionActorList with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetTransitionActorListFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setTransitionActorList = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setTransitionActorList); + + ReadCommandId(setTransitionActorList, reader); + + setTransitionActorList->numTransitionActors = reader->ReadUInt32(); + setTransitionActorList->transitionActorList.reserve(setTransitionActorList->numTransitionActors); + for (uint32_t i = 0; i < setTransitionActorList->numTransitionActors; i++) { + TransitionActorEntry entry; + + entry.sides[0].room = reader->ReadUByte(); + entry.sides[0].effects = reader->ReadUByte(); + entry.sides[1].room = reader->ReadUByte(); + entry.sides[1].effects = reader->ReadUByte(); + entry.id = reader->ReadInt16(); + entry.pos.x = reader->ReadInt16(); + entry.pos.y = reader->ReadInt16(); + entry.pos.z = reader->ReadInt16(); + entry.rotY = reader->ReadInt16(); + entry.params = reader->ReadUInt16(); + + setTransitionActorList->transitionActorList.push_back(entry); + } +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.h b/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.h new file mode 100644 index 000000000..d300fdf3c --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetTransitionActorListFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetTransitionActorListFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetTransitionActorListFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.cpp new file mode 100644 index 000000000..74b3e78ab --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.cpp @@ -0,0 +1,40 @@ +#include "2s2h/resource/importer/scenecommand/SetWindSettingsFactory.h" +#include "2s2h/resource/type/scenecommand/SetWindSettings.h" +#include "spdlog/spdlog.h" + +namespace LUS { +std::shared_ptr +SetWindSettingsFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetWindSettings with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void LUS::SetWindSettingsFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setWind = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setWind); + + ReadCommandId(setWind, reader); + + setWind->settings.windWest = reader->ReadInt8(); + setWind->settings.windVertical = reader->ReadInt8(); + setWind->settings.windSouth = reader->ReadInt8(); + setWind->settings.windSpeed = reader->ReadUByte(); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.h b/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.h new file mode 100644 index 000000000..b4fb4d615 --- /dev/null +++ b/mm/2s2h/resource/importer/scenecommand/SetWindSettingsFactory.h @@ -0,0 +1,16 @@ +#pragma once + +#include "2s2h/resource/importer/scenecommand/SceneCommandFactory.h" + +namespace LUS { +class SetWindSettingsFactory : public SceneCommandFactory { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; +}; + +class SetWindSettingsFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/Animation.cpp b/mm/2s2h/resource/type/Animation.cpp new file mode 100644 index 000000000..46327c732 --- /dev/null +++ b/mm/2s2h/resource/type/Animation.cpp @@ -0,0 +1,21 @@ +#include "Animation.h" + +namespace LUS { +AnimationData* Animation::GetPointer() { + return &animationData; +} + +size_t Animation::GetPointerSize() { + switch(type) { + case AnimationType::Normal: + return sizeof(animationData.animationHeader); + case AnimationType::Link: + return sizeof(animationData.linkAnimationHeader); + case AnimationType::Curve: + return sizeof(animationData.transformUpdateIndex); + case AnimationType::Legacy: + default: + return 0; + } +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/Animation.h b/mm/2s2h/resource/type/Animation.h new file mode 100644 index 000000000..3d6b810bf --- /dev/null +++ b/mm/2s2h/resource/type/Animation.h @@ -0,0 +1,87 @@ +#pragma once + +#include "Resource.h" +#include + +namespace LUS { + enum class AnimationType { + Normal = 0, + Link = 1, + Curve = 2, + Legacy = 3, + }; + + struct RotationIndex { + uint16_t x, y, z; + + RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) { + } + }; + + typedef struct { + /* 0x0000 */ u16 unk_00; // appears to be flags + /* 0x0002 */ s16 unk_02; + /* 0x0004 */ s16 unk_04; + /* 0x0006 */ s16 unk_06; + /* 0x0008 */ f32 unk_08; + } TransformData; // size = 0xC + + typedef struct { + /* 0x0000 */ u8* refIndex; + /* 0x0004 */ TransformData* transformData; + /* 0x0008 */ s16* copyValues; + /* 0x000C */ s16 unk_0C; + /* 0x000E */ s16 unk_0E; + } TransformUpdateIndex; // size = 0x10 + + typedef struct { + /* 0x00 */ s16 frameCount; + } AnimationHeaderCommon; + + // Index into the frame data table. + typedef struct { + /* 0x00 */ u16 x; + /* 0x02 */ u16 y; + /* 0x04 */ u16 z; + } JointIndex; // size = 0x06 + + typedef struct { + /* 0x00 */ AnimationHeaderCommon common; + /* 0x04 */ s16* frameData; // "tbl" + /* 0x08 */ JointIndex* jointIndices; // "ref_tbl" + /* 0x0C */ u16 staticIndexMax; + } AnimationHeader; // size = 0x10 + + typedef struct { + /* 0x00 */ AnimationHeaderCommon common; + /* 0x04 */ void* segment; + } LinkAnimationHeader; // size = 0x8 + + union AnimationData { + AnimationHeader animationHeader; + LinkAnimationHeader linkAnimationHeader; + TransformUpdateIndex transformUpdateIndex; + }; + + class Animation : public Resource { + public: + using Resource::Resource; + + Animation() : Resource(std::shared_ptr()) {} + + AnimationData* GetPointer(); + size_t GetPointerSize(); + + AnimationType type; + AnimationData animationData; + + // NORMAL + std::vector rotationValues; + std::vector rotationIndices; + + // CURVE + std::vector refIndexArr; + std::vector transformDataArr; + std::vector copyValuesArr; + }; +}; // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/AudioSample.cpp b/mm/2s2h/resource/type/AudioSample.cpp new file mode 100644 index 000000000..951aae6c1 --- /dev/null +++ b/mm/2s2h/resource/type/AudioSample.cpp @@ -0,0 +1,11 @@ +#include "AudioSample.h" + +namespace LUS { +Sample* AudioSample::GetPointer() { + return &sample; +} + +size_t AudioSample::GetPointerSize() { + return sizeof(Sample); +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/AudioSample.h b/mm/2s2h/resource/type/AudioSample.h new file mode 100644 index 000000000..eda8aa456 --- /dev/null +++ b/mm/2s2h/resource/type/AudioSample.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include + +namespace LUS { + typedef struct { + /* 0x00 */ uintptr_t start; + /* 0x04 */ uintptr_t end; + /* 0x08 */ u32 count; + /* 0x0C */ char unk_0C[0x4]; + /* 0x10 */ s16 state[16]; // only exists if count != 0. 8-byte aligned + } AdpcmLoop; // size = 0x30 (or 0x10) + + typedef struct { + /* 0x00 */ s32 order; + /* 0x04 */ s32 npredictors; + /* 0x08 */ s16* book; // size 8 * order * npredictors. 8-byte aligned + } AdpcmBook; // s + + typedef struct { + union { + struct { + /* 0x00 */ u32 codec : 4; + /* 0x00 */ u32 medium : 2; + /* 0x00 */ u32 unk_bit26 : 1; + /* 0x00 */ u32 unk_bit25 : 1; // this has been named isRelocated in zret + /* 0x01 */ u32 size : 24; + }; + u32 asU32; + }; + + /* 0x04 */ u8* sampleAddr; + /* 0x08 */ AdpcmLoop* loop; + /* 0x0C */ AdpcmBook* book; + u32 sampleRateMagicValue; // For wav samples only... + s32 sampleRate; // For wav samples only... + } Sample; // size = 0x10 + + class AudioSample : public Resource { + public: + using Resource::Resource; + + AudioSample() : Resource(std::shared_ptr()) {} + + Sample* GetPointer(); + size_t GetPointerSize(); + + Sample sample; + std::vector audioSampleData; + + AdpcmLoop loop; + uint32_t loopStateCount; + + AdpcmBook book; + uint32_t bookDataCount; + std::vector bookData; + }; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/AudioSequence.cpp b/mm/2s2h/resource/type/AudioSequence.cpp new file mode 100644 index 000000000..c09514a67 --- /dev/null +++ b/mm/2s2h/resource/type/AudioSequence.cpp @@ -0,0 +1,12 @@ +#include "AudioSequence.h" + +namespace LUS { + +Sequence* AudioSequence::GetPointer() { + return &sequence; +} + +size_t AudioSequence::GetPointerSize() { + return sizeof(Sequence); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/AudioSequence.h b/mm/2s2h/resource/type/AudioSequence.h new file mode 100644 index 000000000..2b2bb8be9 --- /dev/null +++ b/mm/2s2h/resource/type/AudioSequence.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include + +namespace LUS { + +typedef struct { + char* seqData; + int32_t seqDataSize; + uint16_t seqNumber; + uint8_t medium; + uint8_t cachePolicy; + int32_t numFonts; + uint8_t fonts[16]; +} Sequence; + +class AudioSequence : public Resource { +public: + using Resource::Resource; + + AudioSequence() : Resource(std::shared_ptr()) {} + + Sequence* GetPointer(); + size_t GetPointerSize(); + + Sequence sequence; + std::vector sequenceData; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/AudioSoundFont.cpp b/mm/2s2h/resource/type/AudioSoundFont.cpp new file mode 100644 index 000000000..43ac40abf --- /dev/null +++ b/mm/2s2h/resource/type/AudioSoundFont.cpp @@ -0,0 +1,11 @@ +#include "AudioSoundFont.h" + +namespace LUS { +SoundFont* AudioSoundFont::GetPointer() { + return &soundFont; +} + +size_t AudioSoundFont::GetPointerSize() { + return sizeof(SoundFont); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/AudioSoundFont.h b/mm/2s2h/resource/type/AudioSoundFont.h new file mode 100644 index 000000000..99b18b401 --- /dev/null +++ b/mm/2s2h/resource/type/AudioSoundFont.h @@ -0,0 +1,84 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include "2s2h/resource/type/AudioSample.h" +#include + +namespace LUS { + +typedef struct { + /* 0x0 */ s16 delay; + /* 0x2 */ s16 arg; +} AdsrEnvelope; // size = 0x4 + +typedef struct { + /* 0x00 */ Sample* sample; + /* 0x04 */ union { + u32 tuningAsU32; + f32 tuning;// frequency scale factor + }; +} SoundFontSound; // size = 0x8 + +typedef struct { + /* 0x00 */ u8 loaded; + /* 0x01 */ u8 normalRangeLo; + /* 0x02 */ u8 normalRangeHi; + /* 0x03 */ u8 releaseRate; + /* 0x04 */ AdsrEnvelope* envelope; + /* 0x08 */ SoundFontSound lowNotesSound; + /* 0x10 */ SoundFontSound normalNotesSound; + /* 0x18 */ SoundFontSound highNotesSound; +} Instrument; // size = 0x20 + +typedef struct { + /* 0x00 */ u8 releaseRate; + /* 0x01 */ u8 pan; + /* 0x02 */ u8 loaded; + /* 0x04 */ SoundFontSound sound; + /* 0x14 */ AdsrEnvelope* envelope; +} Drum; // size = 0x14 + +typedef struct { + /* 0x00 */ u8 numInstruments; + /* 0x01 */ u8 numDrums; + /* 0x02 */ u8 sampleBankId1; + /* 0x03 */ u8 sampleBankId2; + /* 0x04 */ u16 numSfx; + /* 0x08 */ Instrument** instruments; + /* 0x0C */ Drum** drums; + /* 0x10 */ SoundFontSound* soundEffects; + s32 fntIndex; +} SoundFont; // size = 0x14 + +class AudioSoundFont : public Resource { +public: + using Resource::Resource; + + AudioSoundFont() : Resource(std::shared_ptr()) {} + + SoundFont* GetPointer(); + size_t GetPointerSize(); + + int8_t medium; + int8_t cachePolicy; + uint16_t data1; + uint16_t data2; + uint16_t data3; + + std::vector drums; + std::vector drumAddresses; + std::vector drumEnvelopeCounts; + std::vector> drumEnvelopeArrays; + + std::vector instruments; + std::vector instrumentAddresses; + std::vector instrumentEnvelopeCounts; + std::vector> instrumentEnvelopeArrays; + + std::vector soundEffects; + + SoundFont soundFont; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/Background.cpp b/mm/2s2h/resource/type/Background.cpp new file mode 100644 index 000000000..bc1047b5c --- /dev/null +++ b/mm/2s2h/resource/type/Background.cpp @@ -0,0 +1,11 @@ +#include "Background.h" + +namespace LUS { +uint8_t* Background::GetPointer() { + return Data.data(); +} + +size_t Background::GetPointerSize() { + return Data.size() * sizeof(uint8_t); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/Background.h b/mm/2s2h/resource/type/Background.h new file mode 100644 index 000000000..7f22658e0 --- /dev/null +++ b/mm/2s2h/resource/type/Background.h @@ -0,0 +1,17 @@ +#pragma once + +#include "resource/Resource.h" + +namespace LUS { +class Background : public Resource { + public: + using Resource::Resource; + + Background() : Resource(std::shared_ptr()) {} + + uint8_t* GetPointer(); + size_t GetPointerSize(); + + std::vector Data; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/CollisionHeader.cpp b/mm/2s2h/resource/type/CollisionHeader.cpp new file mode 100644 index 000000000..5625d2b59 --- /dev/null +++ b/mm/2s2h/resource/type/CollisionHeader.cpp @@ -0,0 +1,11 @@ +#include "CollisionHeader.h" + +namespace LUS { +CollisionHeaderData* CollisionHeader::GetPointer() { + return &collisionHeaderData; +} + +size_t CollisionHeader::GetPointerSize() { + return sizeof(collisionHeaderData); +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/CollisionHeader.h b/mm/2s2h/resource/type/CollisionHeader.h new file mode 100644 index 000000000..e401aa7f5 --- /dev/null +++ b/mm/2s2h/resource/type/CollisionHeader.h @@ -0,0 +1,98 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include +#include "z64math.h" + +namespace LUS { + +typedef struct { + /* 0x00 */ u16 type; + union { + u16 vtxData[3]; + struct { + /* 0x02 */ u16 flags_vIA; // 0xE000 is poly exclusion flags (xpFlags), 0x1FFF is vtxId + /* 0x04 */ u16 flags_vIB; // 0xE000 is flags, 0x1FFF is vtxId + // 0x2000 = poly IsConveyor surface + /* 0x06 */ u16 vIC; + }; + }; + /* 0x08 */ Vec3s normal; // Unit normal vector + // Value ranges from -0x7FFF to 0x7FFF, representing -1.0 to 1.0; 0x8000 is invalid + + /* 0x0E */ s16 dist; // Plane distance from origin along the normal +} CollisionPoly; // size = 0x10 + +typedef struct { + /* 0x00 */ s16 xMin; + /* 0x02 */ s16 ySurface; + /* 0x04 */ s16 zMin; + /* 0x06 */ s16 xLength; + /* 0x08 */ s16 zLength; + /* 0x0C */ u32 properties; + + // 0x0008_0000 = ? + // 0x0007_E000 = Room Index, 0x3F = all rooms + // 0x0000_1F00 = Lighting Settings Index + // 0x0000_00FF = CamData index +} WaterBox; // size = 0x10 + +typedef struct { + /* 0x00 */ u16 cameraSType; + /* 0x02 */ s16 numCameras; + /* 0x04 */ Vec3s* camPosData; +} CamData; + +typedef struct { + u32 data[2]; + + // Type 1 + // 0x0800_0000 = wall damage +} SurfaceType; + + +typedef struct { + /* 0x00 */ Vec3s minBounds; // minimum coordinates of poly bounding box + /* 0x06 */ Vec3s maxBounds; // maximum coordinates of poly bounding box + /* 0x0C */ u16 numVertices; + /* 0x10 */ Vec3s* vtxList; + /* 0x14 */ u16 numPolygons; + /* 0x18 */ CollisionPoly* polyList; + /* 0x1C */ SurfaceType* surfaceTypeList; + /* 0x20 */ CamData* cameraDataList; + /* 0x24 */ u16 numWaterBoxes; + /* 0x28 */ WaterBox* waterBoxes; + size_t cameraDataListLen; // OTRTODO: Added to allow for bounds checking the cameraDataList. +} CollisionHeaderData; // original name: BGDataInfo + +class CollisionHeader : public Resource { +public: + using Resource::Resource; + + CollisionHeader() : Resource(std::shared_ptr()) {} + + CollisionHeaderData* GetPointer(); + size_t GetPointerSize(); + + CollisionHeaderData collisionHeaderData; + + std::vector vertices; + + std::vector polygons; + + uint32_t surfaceTypesCount; + std::vector surfaceTypes; + + uint32_t camDataCount; + std::vector camData; + std::vector camPosDataIndices; + + int32_t camPosCount; + Vec3s camPosDataZero; + std::vector camPosData; + + std::vector waterBoxes; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/Cutscene.cpp b/mm/2s2h/resource/type/Cutscene.cpp new file mode 100644 index 000000000..c7e98062a --- /dev/null +++ b/mm/2s2h/resource/type/Cutscene.cpp @@ -0,0 +1,12 @@ +#include "Cutscene.h" +#include + +namespace LUS { +uint32_t* Cutscene::GetPointer() { + return commands.data(); +} + +size_t Cutscene::GetPointerSize() { + return commands.size() * sizeof(uint32_t); +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/Cutscene.h b/mm/2s2h/resource/type/Cutscene.h new file mode 100644 index 000000000..5bd268e61 --- /dev/null +++ b/mm/2s2h/resource/type/Cutscene.h @@ -0,0 +1,71 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include "Vec2f.h" +#include "Vec3f.h" +#include "Color3b.h" + +namespace LUS { + +enum class CutsceneCommands { + Cmd00 = 0x0000, + SetCameraPos = 0x0001, + SetCameraFocus = 0x0002, + SpecialAction = 0x0003, + SetLighting = 0x0004, + SetCameraPosLink = 0x0005, + SetCameraFocusLink = 0x0006, + Cmd07 = 0x0007, + Cmd08 = 0x0008, + Cmd09 = 0x0009, + Unknown = 0x001A, + Textbox = 0x0013, + SetActorAction0 = 0x000A, + SetActorAction1 = 0x000F, + SetActorAction2 = 0x000E, + SetActorAction3 = 0x0019, + SetActorAction4 = 0x001D, + SetActorAction5 = 0x001E, + SetActorAction6 = 0x002C, + SetActorAction7 = 0x001F, + SetActorAction8 = 0x0031, + SetActorAction9 = 0x003E, + SetActorAction10 = 0x008F, + SetSceneTransFX = 0x002D, + Nop = 0x000B, + PlayBGM = 0x0056, + StopBGM = 0x0057, + FadeBGM = 0x007C, + SetTime = 0x008C, + Terminator = 0x03E8, + End = 0xFFFF, + Error = 0xFEAF, +}; + +class Cutscene : public Resource { + public: + using Resource::Resource; + + Cutscene() : Resource(std::shared_ptr()) {} + + uint32_t* GetPointer(); + size_t GetPointerSize(); + + uint32_t numCommands; + uint32_t endFrame; + std::vector commands; +}; +} // namespace LUS + + +///////////// + +// class CutsceneCommand { +// public: +// uint32_t commandID; +// uint32_t commandIndex; + +// CutsceneCommand(){}; +// }; diff --git a/mm/2s2h/resource/type/Path.cpp b/mm/2s2h/resource/type/Path.cpp new file mode 100644 index 000000000..8ca2ac78d --- /dev/null +++ b/mm/2s2h/resource/type/Path.cpp @@ -0,0 +1,19 @@ +#include "Path.h" + +namespace LUS { +PathData* Path::GetPointer() { + return pathData.data(); +} + +size_t Path::GetPointerSize() { + return pathData.size() * sizeof(PathData); +} + +PathDataMM* PathMM::GetPointer() { + return pathData.data(); +} +size_t PathMM::GetPointerSize() { + return pathData.size() * sizeof(PathData); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/type/Path.h b/mm/2s2h/resource/type/Path.h new file mode 100644 index 000000000..045764cc8 --- /dev/null +++ b/mm/2s2h/resource/type/Path.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include +#include "z64math.h" + +namespace LUS { + +typedef struct { + /* 0x00 */ u8 count; // number of points in the path + /* 0x04 */ Vec3s* points; // Segment Address to the array of points +} PathData; // size = 0x8 + +typedef struct { + /* 0x0 */ u8 count; // Number of points in the path + /* 0x1 */ u8 additionalPathIndex; + /* 0x2 */ s16 customValue; // Path specific to help distinguish different paths + /* 0x4 */ Vec3s* points; // Segment Address to the array of points +} PathDataMM; // size = 0x8 + +class Path : public Resource { +public: + using Resource::Resource; + + Path() : Resource(std::shared_ptr()) {} + + PathData* GetPointer(); + size_t GetPointerSize(); + + uint32_t numPaths; + std::vector pathData; + std::vector> paths; +}; + +class PathMM : public Resource { + public: + using Resource::Resource; + + PathMM() : Resource(std::shared_ptr()) { + } + + PathDataMM* GetPointer(); + size_t GetPointerSize(); + + uint32_t numPaths; + std::vector pathData; + std::vector> paths; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/type/PlayerAnimation.cpp b/mm/2s2h/resource/type/PlayerAnimation.cpp new file mode 100644 index 000000000..55925f49c --- /dev/null +++ b/mm/2s2h/resource/type/PlayerAnimation.cpp @@ -0,0 +1,12 @@ +#include "PlayerAnimation.h" +#include + +namespace LUS { +int16_t* PlayerAnimation::GetPointer() { + return limbRotData.data(); +} + +size_t PlayerAnimation::GetPointerSize() { + return limbRotData.size() * sizeof(int16_t); +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/PlayerAnimation.h b/mm/2s2h/resource/type/PlayerAnimation.h new file mode 100644 index 000000000..4eb51b139 --- /dev/null +++ b/mm/2s2h/resource/type/PlayerAnimation.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include "Vec2f.h" +#include "Vec3f.h" +#include "Color3b.h" + +namespace LUS { + +class PlayerAnimation : public Resource { + public: + using Resource::Resource; + + PlayerAnimation() : Resource(std::shared_ptr()) {} + + int16_t* GetPointer(); + size_t GetPointerSize(); + + std::vector limbRotData; +}; +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/Scene.cpp b/mm/2s2h/resource/type/Scene.cpp new file mode 100644 index 000000000..bfe219e54 --- /dev/null +++ b/mm/2s2h/resource/type/Scene.cpp @@ -0,0 +1,12 @@ +#include "Scene.h" + +namespace LUS { +void* Scene::GetPointer() { + // Scene is a special type that requries C++ processing. As such, we return nothing. + return nullptr; +} + +size_t Scene::GetPointerSize() { + return 0; +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/Scene.h b/mm/2s2h/resource/type/Scene.h new file mode 100644 index 000000000..f726da359 --- /dev/null +++ b/mm/2s2h/resource/type/Scene.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "scenecommand/SceneCommand.h" +#include + +namespace LUS { + +class Scene : public Resource { +public: + using Resource::Resource; + + Scene() : Resource(std::shared_ptr()) {} + + void* GetPointer(); + size_t GetPointerSize(); + + std::vector> commands; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/Skeleton.cpp b/mm/2s2h/resource/type/Skeleton.cpp new file mode 100644 index 000000000..7b9003bab --- /dev/null +++ b/mm/2s2h/resource/type/Skeleton.cpp @@ -0,0 +1,82 @@ +#include "resource/ResourceManager.h" +#include "Skeleton.h" +#include "2s2h/BenPort.h" +#include "libultraship/libultraship.h" + +namespace LUS { +SkeletonData* Skeleton::GetPointer() { + return &skeletonData; +} + +size_t Skeleton::GetPointerSize() { + switch(type) { + case SkeletonType::Normal: + return sizeof(skeletonData.skeletonHeader); + case SkeletonType::Flex: + return sizeof(skeletonData.flexSkeletonHeader); + case SkeletonType::Curve: + return sizeof(skeletonData.skelCurveLimbList); + default: + return 0; + } +} + +std::vector SkeletonPatcher::skeletons; + + +void SkeletonPatcher::RegisterSkeleton(std::string& path, SkelAnime* skelAnime) { + SkeletonPatchInfo info; + + info.skelAnime = skelAnime; + + static const std::string sOtr = "__OTR__"; + + if (path.starts_with(sOtr)) { + path = path.substr(sOtr.length()); + } + + // Determine if we're using an alternate skeleton + if (path.starts_with(LUS::IResource::gAltAssetPrefix)) { + info.vanillaSkeletonPath = path.substr(LUS::IResource::gAltAssetPrefix.length(), + path.size() - LUS::IResource::gAltAssetPrefix.length()); + } else { + info.vanillaSkeletonPath = path; + } + + skeletons.push_back(info); +} + +void SkeletonPatcher::UnregisterSkeleton(SkelAnime* skelAnime) { + + // TODO: Should probably just use a dictionary here... + for (int i = 0; i < skeletons.size(); i++) + { + auto skel = skeletons[i]; + + if (skel.skelAnime == skelAnime) { + skeletons.erase(skeletons.begin() + i); + break; + } + } +} +void SkeletonPatcher::ClearSkeletons() +{ + skeletons.clear(); +} + +void SkeletonPatcher::UpdateSkeletons() { + bool isHD = CVarGetInteger("gAltAssets", 0); + for (auto skel : skeletons) { + Skeleton* newSkel = + (Skeleton*)LUS::Context::GetInstance()->GetResourceManager() + ->LoadResource((isHD ? LUS::IResource::gAltAssetPrefix : "") + skel.vanillaSkeletonPath, true) + .get(); + + if (newSkel != nullptr) { + skel.skelAnime->skeleton = newSkel->skeletonData.skeletonHeader.segment; + uintptr_t skelPtr = (uintptr_t)newSkel->GetPointer(); + memcpy(&skel.skelAnime->skeleton, &skelPtr, sizeof(uintptr_t)); // Dumb thing that needs to be done because cast is not cooperating + } + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/Skeleton.h b/mm/2s2h/resource/type/Skeleton.h new file mode 100644 index 000000000..490614a44 --- /dev/null +++ b/mm/2s2h/resource/type/Skeleton.h @@ -0,0 +1,94 @@ +#pragma once + +#include +#include "Resource.h" +#include "SkeletonLimb.h" +#include + +namespace LUS { + +enum class SkeletonType { + Normal, + Flex, + Curve, +}; + +// typedef struct { +// /* 0x00 */ Vec3s jointPos; // Root is position in model space, children are relative to parent +// /* 0x06 */ u8 child; +// /* 0x07 */ u8 sibling; +// /* 0x08 */ Gfx* dList; +// } StandardLimb; // size = 0xC + +// Model has limbs with only rigid meshes +typedef struct { + /* 0x00 */ void** segment; + /* 0x04 */ uint8_t limbCount; + uint8_t skeletonType; +} SkeletonHeader; // size = 0x8 + +// Model has limbs with flexible meshes +typedef struct { + /* 0x00 */ SkeletonHeader sh; + /* 0x08 */ uint8_t dListCount; +} FlexSkeletonHeader; // size = 0xC + +// typedef struct { +// /* 0x0000 */ u8 firstChildIdx; +// /* 0x0001 */ u8 nextLimbIdx; +// /* 0x0004 */ Gfx* dList[2]; +// } SkelCurveLimb; // size = 0xC + +typedef struct { + /* 0x0000 */ SkelCurveLimb** limbs; + /* 0x0004 */ uint8_t limbCount; +} SkelCurveLimbList; // size = 0x8 + +union SkeletonData { + SkeletonHeader skeletonHeader; + FlexSkeletonHeader flexSkeletonHeader; + SkelCurveLimbList skelCurveLimbList; +}; + +class Skeleton : public Resource { + public: + using Resource::Resource; + + Skeleton() : Resource(std::shared_ptr()) {} + + SkeletonData* GetPointer(); + size_t GetPointerSize(); + + SkeletonType type; + SkeletonData skeletonData; + + LimbType limbType; + int limbCount; + int dListCount; + LimbType limbTableType; + int limbTableCount; + std::vector standardLimbArray; + std::vector curveLimbArray; + std::vector limbTable; + std::vector skeletonHeaderSegments; +}; + +// TODO: CLEAN THIS UP LATER +struct SkeletonPatchInfo +{ + SkelAnime* skelAnime; + std::string vanillaSkeletonPath; +}; + +class SkeletonPatcher { + public: + static void RegisterSkeleton(std::string& path, SkelAnime* skelAnime); + static void UnregisterSkeleton(SkelAnime* skelAnime); + static void ClearSkeletons(); + static void UpdateSkeletons(); + + static std::vector skeletons; +}; + + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/SkeletonLimb.cpp b/mm/2s2h/resource/type/SkeletonLimb.cpp new file mode 100644 index 000000000..8e5a8ef6d --- /dev/null +++ b/mm/2s2h/resource/type/SkeletonLimb.cpp @@ -0,0 +1,24 @@ +#include "SkeletonLimb.h" + +namespace LUS { +SkeletonLimbData* SkeletonLimb::GetPointer() { + return &limbData; +} + +size_t SkeletonLimb::GetPointerSize() { + switch(limbType) { + case LimbType::Standard: + return sizeof(limbData.standardLimb); + case LimbType::LOD: + return sizeof(limbData.lodLimb); + case LimbType::Skin: + return sizeof(limbData.skinLimb); + case LimbType::Curve: + return sizeof(limbData.skelCurveLimb); + case LimbType::Invalid: + case LimbType::Legacy: + default: + return 0; + } +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/SkeletonLimb.h b/mm/2s2h/resource/type/SkeletonLimb.h new file mode 100644 index 000000000..2110b3484 --- /dev/null +++ b/mm/2s2h/resource/type/SkeletonLimb.h @@ -0,0 +1,134 @@ +#pragma once + +#include "Resource.h" +#include "libultraship/libultra.h" +#include "z64math.h" + +namespace LUS { +enum class LimbType { + Invalid, + Standard, + LOD, + Skin, + Curve, + Legacy, +}; + +enum class ZLimbSkinType +{ + SkinType_0, // Segment = 0 + SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28 + SkinType_5 = 5, // Segment = 0 + SkinType_DList = 11, // Segment = DList address +}; + +/** + * Holds a compact version of a vertex used in the Skin system + * It is used to initialise the Vtx used by an animated limb + */ +typedef struct { + /* 0x00 */ u16 index; + /* 0x02 */ s16 s; // s and t are texture coordinates (also known as u and v) + /* 0x04 */ s16 t; + /* 0x06 */ s8 normX; + /* 0x07 */ s8 normY; + /* 0x08 */ s8 normZ; + /* 0x09 */ u8 alpha; +} SkinVertex; // size = 0xA + +/** + * Describes a position displacement and a scale to be applied to a limb at index `limbIndex` + */ +typedef struct { + /* 0x00 */ u8 limbIndex; + /* 0x02 */ s16 x; + /* 0x04 */ s16 y; + /* 0x06 */ s16 z; + /* 0x08 */ u8 scale; +} SkinTransformation; // size = 0xA + +typedef struct { + /* 0x00 */ u16 vtxCount; // number of vertices in this modif entry + /* 0x02 */ u16 transformCount; + /* 0x04 */ u16 unk_4; // index of limbTransformations? + /* 0x08 */ SkinVertex* skinVertices; + /* 0x0C */ SkinTransformation* limbTransformations; +} SkinLimbModif; // size = 0x10 + +typedef struct { + /* 0x00 */ Vec3s jointPos; // Root is position in model space, children are relative to parent + /* 0x06 */ u8 child; + /* 0x07 */ u8 sibling; + /* 0x08 */ Gfx* dLists[2]; // Near and far +} LodLimb; // size = 0x10 + +typedef struct { + /* 0x00 */ Vec3s jointPos; // Root is position in model space, children are relative to parent + /* 0x06 */ u8 child; + /* 0x07 */ u8 sibling; + /* 0x08 */ Gfx* dList; +} StandardLimb; // size = 0xC + +typedef struct { + /* 0x0000 */ u8 firstChildIdx; + /* 0x0001 */ u8 nextLimbIdx; + /* 0x0004 */ Gfx* dList[2]; +} SkelCurveLimb; // size = 0xC + +typedef struct { + /* 0x00 */ Vec3s jointPos; // Root is position in model space, children are relative to parent + /* 0x06 */ u8 child; + /* 0x07 */ u8 sibling; + /* 0x08 */ s32 segmentType; // Type of data contained in segment + /* 0x0C */ void* segment; // Gfx* if segmentType is SKIN_LIMB_TYPE_NORMAL, SkinAnimatedLimbData* if segmentType is SKIN_LIMB_TYPE_ANIMATED, NULL otherwise +} SkinLimb; // size = 0x10 + +typedef struct { + /* 0x00 */ u16 totalVtxCount; // total vertex count for all modif entries + /* 0x02 */ u16 limbModifCount; + /* 0x04 */ SkinLimbModif* limbModifications; + /* 0x08 */ Gfx* dlist; +} SkinAnimatedLimbData; // size = 0xC + +union SkeletonLimbData { + LodLimb lodLimb; + StandardLimb standardLimb; + SkelCurveLimb skelCurveLimb; + SkinLimb skinLimb; +}; + +class SkeletonLimb : public Resource { +public: + using Resource::Resource; + + SkeletonLimb() : Resource(std::shared_ptr()) {} + + SkeletonLimbData* GetPointer(); + size_t GetPointerSize(); + + LimbType limbType; + SkeletonLimbData limbData; + + ZLimbSkinType skinSegmentType; + uint16_t skinVtxCnt; + SkinAnimatedLimbData skinAnimLimbData; + + std::string skinDataDList; + std::string skinDList; + std::string skinDList2; + + float legTransX, legTransY, legTransZ; // Vec3f + uint16_t rotX, rotY, rotZ; // Vec3s + + std::string childPtr, siblingPtr, dListPtr, dList2Ptr; + + int16_t transX, transY, transZ; + uint8_t childIndex, siblingIndex; + + uint32_t skinLimbModifCount; + std::vector skinLimbModifArray; + + std::vector> skinLimbModifVertexArrays; + std::vector> skinLimbModifTransformationArrays; +}; +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/Text.cpp b/mm/2s2h/resource/type/Text.cpp new file mode 100644 index 000000000..eee289f8a --- /dev/null +++ b/mm/2s2h/resource/type/Text.cpp @@ -0,0 +1,11 @@ +#include "Text.h" + +namespace LUS { +MessageEntry* Text::GetPointer() { + return messages.data(); +} + +size_t Text::GetPointerSize() { + return messages.size() * sizeof(MessageEntry); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/Text.h b/mm/2s2h/resource/type/Text.h new file mode 100644 index 000000000..db0cb36a0 --- /dev/null +++ b/mm/2s2h/resource/type/Text.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include + +namespace LUS { +// TODO: we've moved away from using classes for this stuff +class MessageEntry +{ +public: + uint16_t id; + uint8_t textboxType; + uint8_t textboxYPos; + std::string msg; +}; + +class Text : public Resource { +public: + using Resource::Resource; + + Text() : Resource(std::shared_ptr()) {} + + MessageEntry* GetPointer(); + size_t GetPointerSize(); + + std::vector messages; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/TextMM.cpp b/mm/2s2h/resource/type/TextMM.cpp new file mode 100644 index 000000000..b4acc8d18 --- /dev/null +++ b/mm/2s2h/resource/type/TextMM.cpp @@ -0,0 +1,11 @@ +#include "TextMM.h" + +namespace LUS { +MessageEntryMM* TextMM::GetPointer() { + return messages.data(); +} + +size_t TextMM::GetPointerSize() { + return messages.size() * sizeof(MessageEntryMM); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/TextMM.h b/mm/2s2h/resource/type/TextMM.h new file mode 100644 index 000000000..7a6e2d1ab --- /dev/null +++ b/mm/2s2h/resource/type/TextMM.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include "Resource.h" +#include + +namespace LUS { +// TODO: we've moved away from using classes for this stuff + +class MessageEntryMM { + public: + uint16_t id; + uint8_t textboxType; + uint8_t textboxYPos; + uint8_t icon; + uint16_t nextMessageID; + uint16_t firstItemCost; + uint16_t secondItemCost; + uint32_t segmentId; + uint32_t msgOffset; + std::string msg; +}; + +class TextMM : public Resource { +public: + using Resource::Resource; + + TextMM() : Resource(std::shared_ptr()) { + } + + MessageEntryMM* GetPointer(); + size_t GetPointerSize(); + + std::vector messages; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/TextureAnimation.cpp b/mm/2s2h/resource/type/TextureAnimation.cpp new file mode 100644 index 000000000..0d49d0e5b --- /dev/null +++ b/mm/2s2h/resource/type/TextureAnimation.cpp @@ -0,0 +1,36 @@ +#include "TextureAnimation.h" + +namespace LUS { +TextureAnimation::~TextureAnimation() { + for (auto& a : anims) { + switch ((TextureAnimationParamsType)a.type) { + case TextureAnimationParamsType::SingleScroll: + delete a.params; + break; + case TextureAnimationParamsType::DualScroll: + delete[] a.params; + break; + case TextureAnimationParamsType::ColorChange: + case TextureAnimationParamsType::ColorChangeLERP: + case TextureAnimationParamsType::ColorChangeLagrange: + delete[] ((AnimatedMatColorParams*)a.params)->keyFrames; + delete[] ((AnimatedMatColorParams*)a.params)->primColors; + delete[] ((AnimatedMatColorParams*)a.params)->envColors; + delete a.params; + break; + case TextureAnimationParamsType::TextureCycle: + // BENTODO free the textures + delete[] ((AnimatedMatTexCycleParams*)a.params)->textureIndexList; + delete[] ((AnimatedMatTexCycleParams*)a.params)->textureList; + delete a.params; + break; + } + } +} +AnimatedMaterial* TextureAnimation::GetPointer() { + return anims.data(); +} +size_t TextureAnimation::GetPointerSize() { + return anims.size() * sizeof(AnimatedMaterial); +} +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/TextureAnimation.h b/mm/2s2h/resource/type/TextureAnimation.h new file mode 100644 index 000000000..5538547c6 --- /dev/null +++ b/mm/2s2h/resource/type/TextureAnimation.h @@ -0,0 +1,104 @@ +#pragma once +#include "Resource.h" + +namespace LUS { +enum class TextureAnimationParamsType { + /* 0 */ SingleScroll, + /* 1 */ DualScroll, + /* 2 */ ColorChange, + /* 3 */ ColorChangeLERP, + /* 4 */ ColorChangeLagrange, + /* 5 */ TextureCycle, + /* 6 */ Empty // An empty TextureAnimation has the form 00 00 00 06 00000000 +}; + +class ZTextureAnimationParams { + public: + TextureAnimationParamsType type; +}; + +struct TextureScrollingParamsEntry { + int8_t xStep; + int8_t yStep; + uint8_t width; + uint8_t height; +}; + +class TextureScrollingParams : public ZTextureAnimationParams { + public: + int count; // 1 for Single, 2 for Dual + TextureScrollingParamsEntry rows[2]; // Too small to make a vector worth it +}; + +struct F3DPrimColor { + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + uint8_t lodFrac; +}; + +struct F3DEnvColor { + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +class TextureColorChangingParams : public ZTextureAnimationParams { + public: + uint16_t animLength; // size of list for type 2 + uint16_t colorListCount; + std::vector primColorList; + std::vector envColorList; + std::vector frameDataList; +}; + +class TextureCyclingParams : public ZTextureAnimationParams { + public: + uint16_t cycleLength; + std::vector textureList; + std::vector textureIndexList; +}; + +typedef struct { + /* 0x0 */ uint16_t keyFrameLength; + /* 0x2 */ uint16_t keyFrameCount; + /* 0x4 */ F3DPrimColor* primColors; + /* 0x8 */ F3DEnvColor* envColors; + /* 0xC */ uint16_t* keyFrames; +} AnimatedMatColorParams; // size = 0x10 + +typedef struct { + /* 0x0 */ int8_t xStep; + /* 0x1 */ int8_t yStep; + /* 0x2 */ uint8_t width; + /* 0x3 */ uint8_t height; +} AnimatedMatTexScrollParams; // size = 0x4 + +typedef struct { + /* 0x0 */ uint16_t keyFrameLength; + /* 0x4 */ void** textureList; + /* 0x8 */ uint8_t* textureIndexList; +} AnimatedMatTexCycleParams; // size = 0xC + +typedef struct { + /* 0x0 */ int8_t segment; + /* 0x2 */ int16_t type; + /* 0x4 */ void* params; +} AnimatedMaterial; // size = 0x8 + +class TextureAnimation : public Resource { + public: + using Resource::Resource; + ~TextureAnimation(); + + TextureAnimation() : Resource(std::shared_ptr()) { + } + + AnimatedMaterial* GetPointer(); + size_t GetPointerSize(); + + std::vector anims; +}; +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/EndMarker.cpp b/mm/2s2h/resource/type/scenecommand/EndMarker.cpp new file mode 100644 index 000000000..9d12c1518 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/EndMarker.cpp @@ -0,0 +1,11 @@ +#include "EndMarker.h" + +namespace LUS { +Marker* EndMarker::GetPointer() { + return &endMarker; +} + +size_t EndMarker::GetPointerSize() { + return sizeof(Marker); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/EndMarker.h b/mm/2s2h/resource/type/scenecommand/EndMarker.h new file mode 100644 index 000000000..9f981f1f9 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/EndMarker.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + +} Marker; + +class EndMarker : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + Marker* GetPointer(); + size_t GetPointerSize(); + + Marker endMarker; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/RomFile.h b/mm/2s2h/resource/type/scenecommand/RomFile.h new file mode 100644 index 000000000..ebdc3dc3b --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/RomFile.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace LUS { + typedef struct { + /* 0x00 */ uintptr_t vromStart; + /* 0x04 */ uintptr_t vromEnd; + char* fileName; + } RomFile; // size = 0x8 +} \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SceneCommand.h b/mm/2s2h/resource/type/scenecommand/SceneCommand.h new file mode 100644 index 000000000..ea99e066e --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SceneCommand.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include + +namespace LUS { + +enum class SceneCommandID : uint8_t { + SetStartPositionList = 0x00, + SetActorList = 0x01, + SetCsCamera = 0x02, + SetCollisionHeader = 0x03, + SetRoomList = 0x04, + SetWind = 0x05, + SetEntranceList = 0x06, + SetSpecialObjects = 0x07, + SetRoomBehavior = 0x08, + Unused09 = 0x09, + SetMesh = 0x0A, + SetObjectList = 0x0B, + SetLightList = 0x0C, + SetPathways = 0x0D, + SetTransitionActorList = 0x0E, + SetLightingSettings = 0x0F, + SetTimeSettings = 0x10, + SetSkyboxSettings = 0x11, + SetSkyboxModifier = 0x12, + SetExitList = 0x13, + EndMarker = 0x14, + SetSoundSettings = 0x15, + SetEchoSettings = 0x16, + SetCutscenes = 0x17, + SetAlternateHeaders = 0x18, + SetCameraSettings = 0x19, + + // MM Commands + SetWorldMapVisited = 0x19, + SetAnimatedMaterialList = 0x1A, + SetActorCutsceneList = 0x1B, + SetMinimapList = 0x1C, + Unused1D = 0x1D, + SetMinimapChests = 0x1E, + SetCutscenesMM = 0x1F, // This opcode is not in the original game. Its a special command for OTRs. + + Error = 0xFF +}; + +class ISceneCommand : public IResource { +public: + using IResource::IResource; + ISceneCommand() : IResource(std::shared_ptr()) {} + SceneCommandID cmdId; +}; + +template class SceneCommand : public ISceneCommand { + public: + using ISceneCommand::ISceneCommand; + virtual T* GetPointer() = 0; + void* GetRawPointer() override { + return static_cast(GetPointer()); + } +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.cpp b/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.cpp new file mode 100644 index 000000000..79d5253ac --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.cpp @@ -0,0 +1,13 @@ +#include "SetActorCutsceneList.h" +#include "2s2h/resource/type/scenecommand/SetActorCutsceneList.h" + +namespace LUS { +CutsceneEntry* SetActorCutsceneList::GetPointer() { + return entries.data(); +} + +size_t SetActorCutsceneList::GetPointerSize() { + return entries.size() * sizeof(CutsceneEntry); +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.h b/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.h new file mode 100644 index 000000000..5b93d1a5b --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetActorCutsceneList.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Resource.h" +#include "SceneCommand.h" + +namespace LUS { +typedef struct CutsceneEntry { + int16_t priority; + int16_t length; + int16_t csCamId; + int16_t scriptIndex; + int16_t additionalCsId; + uint8_t endSfx; + uint8_t customValue; + int16_t hudVisibility; + uint8_t endCam; + uint8_t letterboxSize; +} CutsceneEntry; + +class SetActorCutsceneList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + CutsceneEntry* GetPointer(); + size_t GetPointerSize(); + + uint32_t numEntries; + std::vector entries; +}; + +} \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SetActorList.cpp b/mm/2s2h/resource/type/scenecommand/SetActorList.cpp new file mode 100644 index 000000000..d37ebb148 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetActorList.cpp @@ -0,0 +1,11 @@ +#include "SetActorList.h" + +namespace LUS { +ActorEntry* SetActorList::GetPointer() { + return actorList.data(); +} + +size_t SetActorList::GetPointerSize() { + return actorList.size() * sizeof(ActorEntry); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetActorList.h b/mm/2s2h/resource/type/scenecommand/SetActorList.h new file mode 100644 index 000000000..117175d7d --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetActorList.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +// #include +#include "z64math.h" + +namespace LUS { +typedef struct { + /* 0x00 */ s16 id; + /* 0x02 */ Vec3s pos; + /* 0x08 */ Vec3s rot; + /* 0x0E */ s16 params; +} ActorEntry; // size = 0x10 + +class SetActorList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + ActorEntry* GetPointer(); + size_t GetPointerSize(); + + uint32_t numActors; + std::vector actorList; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.cpp b/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.cpp new file mode 100644 index 000000000..15b3c97d4 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.cpp @@ -0,0 +1,12 @@ +#include "SetAlternateHeaders.h" + +namespace LUS { +void* SetAlternateHeaders::GetPointer() { + // Like Scene, SetAlternateHeader is a special type that is only acted upon in C++. + return nullptr; +} + +size_t SetAlternateHeaders::GetPointerSize() { + return 0; +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.h b/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.h new file mode 100644 index 000000000..ebc571e3d --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetAlternateHeaders.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include "2s2h/resource/type/Scene.h" +#include "RomFile.h" +#include + + +namespace LUS { + +class SetAlternateHeaders : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + void* GetPointer(); + size_t GetPointerSize(); + + uint32_t numHeaders; + std::vector> headers; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.cpp b/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.cpp new file mode 100644 index 000000000..ef3adc543 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.cpp @@ -0,0 +1,13 @@ +#include "SetAnimatedMaterialList.h" + +namespace LUS { + +AnimatedMaterialData* LUS::SetAnimatedMaterialList::GetPointer() { + return mat; +} + +size_t LUS::SetAnimatedMaterialList::GetPointerSize() { + return sizeof(AnimatedMaterialData); +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.h b/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.h new file mode 100644 index 000000000..02a8c7c38 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetAnimatedMaterialList.h @@ -0,0 +1,23 @@ +#pragma once + +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + /* 0x0 */ int8_t segment; + /* 0x2 */ int16_t type; + /* 0x4 */ void* params; +} AnimatedMaterialData; // size = 0x8 + +class SetAnimatedMaterialList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + AnimatedMaterialData* GetPointer(); + size_t GetPointerSize(); + + AnimatedMaterialData* mat; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCameraSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetCameraSettings.cpp new file mode 100644 index 000000000..e1d2967e7 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCameraSettings.cpp @@ -0,0 +1,11 @@ +#include "SetCameraSettings.h" + +namespace LUS { +CameraSettings* SetCameraSettings::GetPointer() { + return &settings; +} + +size_t SetCameraSettings::GetPointerSize() { + return sizeof(CameraSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCameraSettings.h b/mm/2s2h/resource/type/scenecommand/SetCameraSettings.h new file mode 100644 index 000000000..adbde2e02 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCameraSettings.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + int8_t cameraMovement; + int32_t worldMapArea; +} CameraSettings; + +class SetCameraSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + CameraSettings* GetPointer(); + size_t GetPointerSize(); + + CameraSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.cpp b/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.cpp new file mode 100644 index 000000000..db8cdcb32 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.cpp @@ -0,0 +1,17 @@ +#include "SetCollisionHeader.h" + +namespace LUS { +CollisionHeaderData* SetCollisionHeader::GetPointer() { + if (collisionHeader == nullptr) { + return nullptr; + } + return collisionHeader->GetPointer(); +} + +size_t SetCollisionHeader::GetPointerSize() { + if (collisionHeader == nullptr) { + return 0; + } + return collisionHeader->GetPointerSize(); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.h b/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.h new file mode 100644 index 000000000..c615eedad --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCollisionHeader.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" +#include "2s2h/resource/type/CollisionHeader.h" +// #include + +namespace LUS { +class SetCollisionHeader : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + CollisionHeaderData* GetPointer(); + size_t GetPointerSize(); + + std::string fileName; + + std::shared_ptr collisionHeader; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp b/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp new file mode 100644 index 000000000..59af0c0fe --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp @@ -0,0 +1,18 @@ +#include "SetCsCamera.h" + +namespace LUS { +SetCsCamera::~SetCsCamera() { + for (auto c : csCamera) { + if (c.actorCsCamFuncData != nullptr) { + delete[] c.actorCsCamFuncData; + } + } +} +ActorCsCamInfoData* SetCsCamera::GetPointer() { + return csCamera.data(); +} + +size_t SetCsCamera::GetPointerSize() { + return sizeof(ActorCsCamInfoData); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCsCamera.h b/mm/2s2h/resource/type/scenecommand/SetCsCamera.h new file mode 100644 index 000000000..fa5d9a500 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCsCamera.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + +} CsCamera; + +typedef struct { + /* 0x0 */ s16 x; + /* 0x2 */ s16 y; + /* 0x4 */ s16 z; +} z64Vec3s; // size = 0x6 + +typedef struct { + /* 0x0 */ s16 setting; // camera setting described by CameraSettingType enum + /* 0x2 */ s16 count; + /* 0x4 */ z64Vec3s* actorCsCamFuncData; // s16 data grouped in threes +} ActorCsCamInfoData; // size = 0x8 + +class SetCsCamera : public SceneCommand { + public: + using SceneCommand::SceneCommand; + ~SetCsCamera(); + + ActorCsCamInfoData* GetPointer(); + size_t GetPointerSize(); + + std::vector csCamera; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCutscenes.cpp b/mm/2s2h/resource/type/scenecommand/SetCutscenes.cpp new file mode 100644 index 000000000..01c88751b --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCutscenes.cpp @@ -0,0 +1,35 @@ +#include "SetCutscenes.h" + +namespace LUS { +uint32_t* SetCutscenes::GetPointer() { + if (cutscene == nullptr) { + return nullptr; + } + return cutscene->GetPointer(); +} + +size_t SetCutscenes::GetPointerSize() { + if (cutscene == nullptr) { + return 0; + } + return cutscene->GetPointerSize(); +} + +CutsceneScriptEntry* SetCutscenesMM::GetPointer() { + // return nullptr; // BENTODO + if (entries.size() == 0) { + return nullptr; + } + return entries.data(); +} + +size_t SetCutscenesMM::GetPointerSize() { + //return 0; + // BENTODO + if (entries.size() == 0) { + return 0; + } + return entries.size() * sizeof(CutsceneScriptEntry); +} + +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCutscenes.h b/mm/2s2h/resource/type/scenecommand/SetCutscenes.h new file mode 100644 index 000000000..900201522 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetCutscenes.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "2s2h/resource/type/scenecommand/SceneCommand.h" +#include "2s2h/resource/type/Cutscene.h" +// #include + +namespace LUS { +class SetCutscenes : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + uint32_t* GetPointer(); + size_t GetPointerSize(); + + std::string fileName; + std::shared_ptr cutscene; +}; + +class CutsceneScriptEntry { + public: + void* data; + uint16_t exit; + uint8_t entrance; + uint8_t flag; +}; + + +class SetCutscenesMM : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + CutsceneScriptEntry* GetPointer(); + size_t GetPointerSize(); + + std::vector entries; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetEchoSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetEchoSettings.cpp new file mode 100644 index 000000000..47cfa85ad --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetEchoSettings.cpp @@ -0,0 +1,11 @@ +#include "SetEchoSettings.h" + +namespace LUS { +EchoSettings* SetEchoSettings::GetPointer() { + return &settings; +} + +size_t SetEchoSettings::GetPointerSize() { + return sizeof(EchoSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetEchoSettings.h b/mm/2s2h/resource/type/scenecommand/SetEchoSettings.h new file mode 100644 index 000000000..ea2f664d4 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetEchoSettings.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + int8_t echo; +} EchoSettings; + +class SetEchoSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + EchoSettings* GetPointer(); + size_t GetPointerSize(); + + EchoSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetEntranceList.cpp b/mm/2s2h/resource/type/scenecommand/SetEntranceList.cpp new file mode 100644 index 000000000..d33ac189b --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetEntranceList.cpp @@ -0,0 +1,11 @@ +#include "SetEntranceList.h" + +namespace LUS { +EntranceEntry* SetEntranceList::GetPointer() { + return entrances.data(); +} + +size_t SetEntranceList::GetPointerSize() { + return entrances.size() * sizeof(EntranceEntry); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetEntranceList.h b/mm/2s2h/resource/type/scenecommand/SetEntranceList.h new file mode 100644 index 000000000..d31dda78c --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetEntranceList.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + /* 0x00 */ u8 spawn; + /* 0x01 */ u8 room; +} EntranceEntry; + +class SetEntranceList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + EntranceEntry* GetPointer(); + size_t GetPointerSize(); + + uint32_t numEntrances; + + std::vector entrances; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetExitList.cpp b/mm/2s2h/resource/type/scenecommand/SetExitList.cpp new file mode 100644 index 000000000..99966cdb4 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetExitList.cpp @@ -0,0 +1,11 @@ +#include "SetExitList.h" + +namespace LUS { +uint16_t* SetExitList::GetPointer() { + return exits.data(); +} + +size_t SetExitList::GetPointerSize() { + return exits.size() * sizeof(int16_t); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetExitList.h b/mm/2s2h/resource/type/scenecommand/SetExitList.h new file mode 100644 index 000000000..c6f0b3f42 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetExitList.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +class SetExitList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + uint16_t* GetPointer(); + size_t GetPointerSize(); + + uint32_t numExits; + + std::vector exits; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetLightList.cpp b/mm/2s2h/resource/type/scenecommand/SetLightList.cpp new file mode 100644 index 000000000..c59f75c20 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetLightList.cpp @@ -0,0 +1,11 @@ +#include "SetLightList.h" + +namespace LUS { +LightInfo* SetLightList::GetPointer() { + return lightList.data(); +} + +size_t SetLightList::GetPointerSize() { + return lightList.size() * sizeof(LightInfo); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetLightList.h b/mm/2s2h/resource/type/scenecommand/SetLightList.h new file mode 100644 index 000000000..bbc5aad3d --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetLightList.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + /* 0x0 */ s16 x; + /* 0x2 */ s16 y; + /* 0x4 */ s16 z; + /* 0x6 */ u8 color[3]; + /* 0x9 */ u8 drawGlow; + /* 0xA */ s16 radius; +} LightPoint; // size = 0xC + +typedef struct { + /* 0x0 */ s8 x; + /* 0x1 */ s8 y; + /* 0x2 */ s8 z; + /* 0x3 */ u8 color[3]; +} LightDirectional; // size = 0x6 + +typedef union { + LightPoint point; + LightDirectional dir; +} LightParams; // size = 0xC + +typedef struct { + /* 0x0 */ u8 type; + /* 0x2 */ LightParams params; +} LightInfo; // size = 0xE + +class SetLightList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + LightInfo* GetPointer(); + size_t GetPointerSize(); + + uint32_t numLights; + std::vector lightList; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetLightingSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetLightingSettings.cpp new file mode 100644 index 000000000..69127f19c --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetLightingSettings.cpp @@ -0,0 +1,11 @@ +#include "SetLightingSettings.h" + +namespace LUS { +EnvLightSettings* SetLightingSettings::GetPointer() { + return settings.data(); +} + +size_t SetLightingSettings::GetPointerSize() { + return settings.size() * sizeof(EnvLightSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetLightingSettings.h b/mm/2s2h/resource/type/scenecommand/SetLightingSettings.h new file mode 100644 index 000000000..ca894fec3 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetLightingSettings.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + /* 0x00 */ u8 ambientColor[3]; + /* 0x03 */ s8 light1Dir[3]; + /* 0x06 */ u8 light1Color[3]; + /* 0x09 */ s8 light2Dir[3]; + /* 0x0C */ u8 light2Color[3]; + /* 0x0F */ u8 fogColor[3]; + /* 0x12 */ s16 fogNear; + /* 0x14 */ s16 fogFar; +} EnvLightSettings; // size = 0x16 + +class SetLightingSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + EnvLightSettings* GetPointer(); + size_t GetPointerSize(); + + std::vector settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetMesh.cpp b/mm/2s2h/resource/type/scenecommand/SetMesh.cpp new file mode 100644 index 000000000..5ecd2cbfa --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMesh.cpp @@ -0,0 +1,11 @@ +#include "SetMesh.h" + +namespace LUS { +MeshHeader* SetMesh::GetPointer() { + return &meshHeader; +} + +size_t SetMesh::GetPointerSize() { + return sizeof(MeshHeader); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetMesh.h b/mm/2s2h/resource/type/scenecommand/SetMesh.h new file mode 100644 index 000000000..a3a6c9731 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMesh.h @@ -0,0 +1,103 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include "libultraship/libultra.h" +#include "z64math.h" + +namespace LUS { +typedef struct { + /* 0x00 */ u8 type; +} PolygonBase; + +typedef struct { + /* 0x00 */ PolygonBase base; + /* 0x01 */ u8 num; // number of dlist entries + /* 0x04 */ void* start; + /* 0x08 */ void* end; +} PolygonType0; // size = 0xC + +typedef struct { + /* 0x00 */ u16 unk_00; + /* 0x02 */ u8 id; + /* 0x04 */ void* source; + /* 0x08 */ u32 unk_0C; + /* 0x0C */ u32 tlut; + /* 0x10 */ u16 width; + /* 0x12 */ u16 height; + /* 0x14 */ u8 fmt; + /* 0x15 */ u8 siz; + /* 0x16 */ u16 mode0; + /* 0x18 */ u16 tlutCount; +} BgImage; // size = 0x1C + +typedef struct { + /* 0x00 */ PolygonBase base; + /* 0x01 */ u8 format; // 1 = single, 2 = multi + /* 0x04 */ Gfx* dlist; + union { + struct { + /* 0x08 */ void* source; + /* 0x0C */ u32 unk_0C; + /* 0x10 */ void* tlut; + /* 0x14 */ u16 width; + /* 0x16 */ u16 height; + /* 0x18 */ u8 fmt; + /* 0x19 */ u8 siz; + /* 0x1A */ u16 mode0; + /* 0x1C */ u16 tlutCount; + } single; + struct { + /* 0x08 */ u8 count; + /* 0x0C */ BgImage* list; + } multi; + }; +} PolygonType1; + +typedef struct { + /* 0x00 */ PolygonBase base; + /* 0x01 */ u8 num; // number of dlist entries + /* 0x04 */ void* start; + /* 0x08 */ void* end; +} PolygonType2; // size = 0xC + +typedef union { + PolygonBase base; + PolygonType0 polygon0; + PolygonType1 polygon1; + PolygonType2 polygon2; +} MeshHeader; // "Ground Shape" + +typedef struct { + /* 0x00 */ Vec3s pos; + /* 0x06 */ s16 unk_06; + /* 0x08 */ Gfx* opa; + /* 0x0C */ Gfx* xlu; +} PolygonDlist2; // size = 0x8 + +typedef struct { + /* 0x00 */ Gfx* opa; + /* 0x04 */ Gfx* xlu; +} PolygonDlist; // size = 0x8 + +class SetMesh : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + MeshHeader* GetPointer(); + size_t GetPointerSize(); + + uint32_t numPoly; + uint8_t data; + uint8_t meshHeaderType; + + std::vector dlists; + std::vector dlists2; + std::vector imagePaths; + std::vector images; + MeshHeader meshHeader; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetMinimapChests.cpp b/mm/2s2h/resource/type/scenecommand/SetMinimapChests.cpp new file mode 100644 index 000000000..dde6da61d --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMinimapChests.cpp @@ -0,0 +1,13 @@ +#include "SetMinimapChests.h" + +namespace LUS { + +MinimapChestData* SetMinimapChests::GetPointer() { + return chests.data(); +} + +size_t SetMinimapChests::GetPointerSize() { + return sizeof(MinimapChestData); +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SetMinimapChests.h b/mm/2s2h/resource/type/scenecommand/SetMinimapChests.h new file mode 100644 index 000000000..2877d4dc7 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMinimapChests.h @@ -0,0 +1,23 @@ +#pragma once +#include "Resource.h" +#include "SceneCommand.h" + +namespace LUS { +typedef struct { + int16_t unk_0; + int16_t unk_2; + int16_t unk_4; + int16_t unk_6; + int16_t unk_8; +} MinimapChestData; + +class SetMinimapChests : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + MinimapChestData* GetPointer(); + size_t GetPointerSize(); + std::vector chests; +}; + +} diff --git a/mm/2s2h/resource/type/scenecommand/SetMinimapList.cpp b/mm/2s2h/resource/type/scenecommand/SetMinimapList.cpp new file mode 100644 index 000000000..e97a6eee0 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMinimapList.cpp @@ -0,0 +1,13 @@ +#include "SetMinimapList.h" + +namespace LUS { + +MinimapListData* LUS::SetMinimapList::GetPointer() { + return &list; +} + +size_t LUS::SetMinimapList::GetPointerSize() { + return sizeof(list); +} + +} // namespace LUS \ No newline at end of file diff --git a/mm/2s2h/resource/type/scenecommand/SetMinimapList.h b/mm/2s2h/resource/type/scenecommand/SetMinimapList.h new file mode 100644 index 000000000..ecebbc323 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetMinimapList.h @@ -0,0 +1,33 @@ +#pragma once + +#include "Resource.h" +#include "SceneCommand.h" +#include + + +namespace LUS { +typedef struct { + /* 0x00 */ u16 mapId; + /* 0x02 */ s16 unk2; + /* 0x04 */ s16 unk4; + /* 0x06 */ s16 unk6; + /* 0x08 */ u16 unk8; // flags; 1 = mirror x? 2 = mirror y? +} MinimapEntryData; // size = 0xA + +typedef struct { + /* 0x00 */ MinimapEntryData* entry; + /* 0x04 */ s16 scale; +} MinimapListData; // size = 0x8 + + +class SetMinimapList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + MinimapListData* GetPointer(); + size_t GetPointerSize(); + + MinimapListData list; + std::vector entries; +}; + +} diff --git a/mm/2s2h/resource/type/scenecommand/SetObjectList.cpp b/mm/2s2h/resource/type/scenecommand/SetObjectList.cpp new file mode 100644 index 000000000..921166675 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetObjectList.cpp @@ -0,0 +1,11 @@ +#include "SetObjectList.h" + +namespace LUS { +int16_t* SetObjectList::GetPointer() { + return objects.data(); +} + +size_t SetObjectList::GetPointerSize() { + return objects.size() * sizeof(int16_t); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetObjectList.h b/mm/2s2h/resource/type/scenecommand/SetObjectList.h new file mode 100644 index 000000000..c6f786636 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetObjectList.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +class SetObjectList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + int16_t* GetPointer(); + size_t GetPointerSize(); + + uint32_t numObjects; + std::vector objects; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetPathways.cpp b/mm/2s2h/resource/type/scenecommand/SetPathways.cpp new file mode 100644 index 000000000..046543a5b --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetPathways.cpp @@ -0,0 +1,18 @@ +#include "SetPathways.h" + +namespace LUS { +PathData** SetPathways::GetPointer() { + return paths.data(); +} + +size_t SetPathways::GetPointerSize() { + return paths.size() * sizeof(PathData*); +} + +PathDataMM** SetPathwaysMM::GetPointer() { + return paths.data(); +} +size_t SetPathwaysMM::GetPointerSize() { + return paths.size() * sizeof(PathData*); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetPathways.h b/mm/2s2h/resource/type/scenecommand/SetPathways.h new file mode 100644 index 000000000..e72cdcb29 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetPathways.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +// #include +#include "2s2h/resource/type/Path.h" + +namespace LUS { + +class SetPathways : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + PathData** GetPointer(); + size_t GetPointerSize(); + + uint32_t numPaths; + std::vector paths; +}; + +class SetPathwaysMM : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + PathDataMM** GetPointer(); + size_t GetPointerSize(); + + uint32_t numPaths; + std::vector paths; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp new file mode 100644 index 000000000..a56562449 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp @@ -0,0 +1,17 @@ +#include "SetRoomBehavior.h" + +namespace LUS { +RoomBehavior* SetRoomBehavior::GetPointer() { + return &roomBehavior; +} + +size_t SetRoomBehavior::GetPointerSize() { + return sizeof(RoomBehavior); +} +RoomBehaviorMM* SetRoomBehaviorMM::GetPointer() { + return &roomBehavior; +} +size_t SetRoomBehaviorMM::GetPointerSize() { + return sizeof(RoomBehaviorMM); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h new file mode 100644 index 000000000..6889a2aee --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + int8_t gameplayFlags; + int32_t gameplayFlags2; +} RoomBehavior; + +typedef struct { + int8_t gameplayFlags; + int8_t currRoomUnk2; + int8_t currRoomUnk5; + int8_t msgCtxUnk; + int8_t enablePointLights; + int8_t kankyoContextUnkE2; +} RoomBehaviorMM; + +class SetRoomBehavior : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + RoomBehavior* GetPointer(); + size_t GetPointerSize(); + + RoomBehavior roomBehavior; +}; + + +class SetRoomBehaviorMM : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + RoomBehaviorMM* GetPointer(); + size_t GetPointerSize(); + + RoomBehaviorMM roomBehavior; +}; + +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomList.cpp b/mm/2s2h/resource/type/scenecommand/SetRoomList.cpp new file mode 100644 index 000000000..cf8c1d61a --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetRoomList.cpp @@ -0,0 +1,11 @@ +#include "SetRoomList.h" + +namespace LUS { +RomFile* SetRoomList::GetPointer() { + return rooms.data(); +} + +size_t SetRoomList::GetPointerSize() { + return rooms.size() * sizeof(RomFile); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomList.h b/mm/2s2h/resource/type/scenecommand/SetRoomList.h new file mode 100644 index 000000000..9bd0e07bc --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetRoomList.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include "RomFile.h" +#include +#include + +namespace LUS { +// typedef struct { +// /* 0x00 */ uintptr_t vromStart; +// /* 0x04 */ uintptr_t vromEnd; +// char* fileName; +// } RomFile; // size = 0x8 + +class SetRoomList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + RomFile* GetPointer(); + size_t GetPointerSize(); + + uint32_t numRooms; + + std::vector fileNames; + std::vector rooms; + ~SetRoomList() { + SPDLOG_TRACE("ROOM LIST DTOR"); + } +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.cpp b/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.cpp new file mode 100644 index 000000000..9926ec01a --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.cpp @@ -0,0 +1,11 @@ +#include "SetSkyboxModifier.h" + +namespace LUS { +SkyboxModifier* SetSkyboxModifier::GetPointer() { + return &modifier; +} + +size_t SetSkyboxModifier::GetPointerSize() { + return sizeof(SkyboxModifier); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.h b/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.h new file mode 100644 index 000000000..6a54879e6 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSkyboxModifier.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + uint8_t skyboxDisabled; + uint8_t sunMoonDisabled; +} SkyboxModifier; + +class SetSkyboxModifier : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + SkyboxModifier* GetPointer(); + size_t GetPointerSize(); + + SkyboxModifier modifier; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.cpp new file mode 100644 index 000000000..7f12d4fa3 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.cpp @@ -0,0 +1,11 @@ +#include "SetSkyboxSettings.h" + +namespace LUS { +SkyboxSettings* SetSkyboxSettings::GetPointer() { + return &settings; +} + +size_t SetSkyboxSettings::GetPointerSize() { + return sizeof(SetSkyboxSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.h b/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.h new file mode 100644 index 000000000..a2a9593b0 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSkyboxSettings.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + uint8_t unk; + uint8_t skyboxId; + uint8_t weather; + uint8_t indoors; +} SkyboxSettings; + +class SetSkyboxSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + SkyboxSettings* GetPointer(); + size_t GetPointerSize(); + + SkyboxSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSoundSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetSoundSettings.cpp new file mode 100644 index 000000000..f6f1941d1 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSoundSettings.cpp @@ -0,0 +1,11 @@ +#include "SetSoundSettings.h" + +namespace LUS { +SoundSettings* SetSoundSettings::GetPointer() { + return &settings; +} + +size_t SetSoundSettings::GetPointerSize() { + return sizeof(SoundSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSoundSettings.h b/mm/2s2h/resource/type/scenecommand/SetSoundSettings.h new file mode 100644 index 000000000..c4ee4668d --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSoundSettings.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + uint8_t seqId; + uint8_t natureAmbienceId; + uint8_t reverb; +} SoundSettings; + +class SetSoundSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + SoundSettings* GetPointer(); + size_t GetPointerSize(); + + SoundSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.cpp b/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.cpp new file mode 100644 index 000000000..3887107da --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.cpp @@ -0,0 +1,11 @@ +#include "SetSpecialObjects.h" + +namespace LUS { +SpecialObjects* SetSpecialObjects::GetPointer() { + return &specialObjects; +} + +size_t SetSpecialObjects::GetPointerSize() { + return sizeof(SpecialObjects); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.h b/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.h new file mode 100644 index 000000000..78cfcd425 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetSpecialObjects.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + int8_t elfMessage; + int16_t globalObject; +} SpecialObjects; + +class SetSpecialObjects : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + SpecialObjects* GetPointer(); + size_t GetPointerSize(); + + SpecialObjects specialObjects; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetStartPositionList.cpp b/mm/2s2h/resource/type/scenecommand/SetStartPositionList.cpp new file mode 100644 index 000000000..89fb40049 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetStartPositionList.cpp @@ -0,0 +1,11 @@ +#include "SetStartPositionList.h" + +namespace LUS { +ActorEntry* SetStartPositionList::GetPointer() { + return startPositions.data(); +} + +size_t SetStartPositionList::GetPointerSize() { + return startPositions.size() * sizeof(ActorEntry); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetStartPositionList.h b/mm/2s2h/resource/type/scenecommand/SetStartPositionList.h new file mode 100644 index 000000000..cc939aca0 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetStartPositionList.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include "2s2h/resource/type/scenecommand/SetActorList.h" +// #include + +namespace LUS { +// typedef struct { +// /* 0x00 */ s16 id; +// /* 0x02 */ Vec3s pos; +// /* 0x08 */ Vec3s rot; +// /* 0x0E */ s16 params; +// } ActorEntry; // size = 0x10 + +class SetStartPositionList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + ActorEntry* GetPointer(); + size_t GetPointerSize(); + + uint32_t numStartPositions; + std::vector startPositions; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetTimeSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetTimeSettings.cpp new file mode 100644 index 000000000..9a10fb022 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetTimeSettings.cpp @@ -0,0 +1,11 @@ +#include "SetTimeSettings.h" + +namespace LUS { +TimeSettings* SetTimeSettings::GetPointer() { + return &settings; +} + +size_t SetTimeSettings::GetPointerSize() { + return sizeof(TimeSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetTimeSettings.h b/mm/2s2h/resource/type/scenecommand/SetTimeSettings.h new file mode 100644 index 000000000..637398652 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetTimeSettings.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + uint8_t hour; + uint8_t minute; + uint8_t timeIncrement; +} TimeSettings; + +class SetTimeSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + TimeSettings* GetPointer(); + size_t GetPointerSize(); + + TimeSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.cpp b/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.cpp new file mode 100644 index 000000000..86387e682 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.cpp @@ -0,0 +1,11 @@ +#include "SetTransitionActorList.h" + +namespace LUS { +TransitionActorEntry* SetTransitionActorList::GetPointer() { + return transitionActorList.data(); +} + +size_t SetTransitionActorList::GetPointerSize() { + return transitionActorList.size() * sizeof(TransitionActorEntry); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.h b/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.h new file mode 100644 index 000000000..bb6fc2ac6 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetTransitionActorList.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +// #include +#include "z64math.h" + +namespace LUS { +typedef struct { + struct { + s8 room; // Room to switch to + s8 effects; // How the camera reacts during the transition + } /* 0x00 */ sides[2]; // 0 = front, 1 = back + /* 0x04 */ s16 id; + /* 0x06 */ Vec3s pos; + /* 0x0C */ s16 rotY; + /* 0x0E */ s16 params; +} TransitionActorEntry; // size = 0x10 + +class SetTransitionActorList : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + TransitionActorEntry* GetPointer(); + size_t GetPointerSize(); + + uint32_t numTransitionActors; + std::vector transitionActorList; +}; +}; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetWindSettings.cpp b/mm/2s2h/resource/type/scenecommand/SetWindSettings.cpp new file mode 100644 index 000000000..3aa9ce7a6 --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetWindSettings.cpp @@ -0,0 +1,11 @@ +#include "SetWindSettings.h" + +namespace LUS { +WindSettings* SetWindSettings::GetPointer() { + return &settings; +} + +size_t SetWindSettings::GetPointerSize() { + return sizeof(WindSettings); +} +} // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetWindSettings.h b/mm/2s2h/resource/type/scenecommand/SetWindSettings.h new file mode 100644 index 000000000..e79b445ae --- /dev/null +++ b/mm/2s2h/resource/type/scenecommand/SetWindSettings.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include "Resource.h" +#include "SceneCommand.h" +#include + +namespace LUS { +typedef struct { + int8_t windWest; + int8_t windVertical; + int8_t windSouth; + uint8_t windSpeed; +} WindSettings; + +class SetWindSettings : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + WindSettings* GetPointer(); + size_t GetPointerSize(); + + WindSettings settings; +}; +}; // namespace LUS diff --git a/mm/2s2h/z_message_OTR.cpp b/mm/2s2h/z_message_OTR.cpp new file mode 100644 index 000000000..808d9b794 --- /dev/null +++ b/mm/2s2h/z_message_OTR.cpp @@ -0,0 +1,87 @@ +#include "BenPort.h" +#include +#include "2s2h/resource/type/Scene.h" +#include +#include "global.h" +#include "vt.h" +#include "2s2h/resource/type/TextMM.h" +#include +#include + +// BENTODO: This needs to be cleaned up. It can probably be implemented better. +struct MessageStruct +{ + uint8_t textboxType; + uint8_t textboxYPos; + uint8_t icon; + uint16_t nextMessageID; + uint16_t firstItemCost; + uint16_t secondItemCost; + uint16_t alwaysFFFF; +}; + +//extern "C" MessageTableEntry* sNesMessageEntryTablePtr; +//extern "C" MessageTableEntry* sStaffMessageEntryTablePtr; + +MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) { + auto file = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(filePath)); + + if (file == nullptr) + return nullptr; + + // Allocate room for an additional message + // OTRTODO: Should not be malloc'ing here. It's fine for now since we check elsewhere that the message table is + // already null. + MessageTableEntry* table = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * (file->messages.size() + 1)); + + for (size_t i = 0; i < file->messages.size(); i++) { + table[i].textId = file->messages[i].id; + table[i].typePos = (file->messages[i].textboxType << 4) | file->messages[i].textboxYPos; + table[i].segment = (const char*)malloc(file->messages[i].msg.size() + 11); + + MessageStruct* msgStruct = (MessageStruct*)table[i].segment; + msgStruct->textboxType = file->messages[i].textboxType; + msgStruct->textboxYPos = file->messages[i].textboxYPos; + msgStruct->icon = file->messages[i].icon; + msgStruct->nextMessageID = file->messages[i].nextMessageID; + msgStruct->firstItemCost = file->messages[i].firstItemCost; + msgStruct->secondItemCost = file->messages[i].secondItemCost; + msgStruct->alwaysFFFF = 0xFFFF; + + memcpy((void*)(&table[i].segment[11]), file->messages[i].msg.c_str(), file->messages[i].msg.size()); + + //table[i].segment = file->messages[i].msg.c_str(); + table[i].msgSize = file->messages[i].msg.size() + 11; + + //if (isNES && file->messages[i].id == 0xFFFC) + //_message_0xFFFC_nes = (char*)file->messages[i].msg.c_str(); + } + + return table; +} + +extern "C" void OTRMessage_Init(PlayState* play) { + // OTRTODO: Added a lot of null checks here so that we don't malloc the table multiple times causing a memory leak. + // We really ought to fix the implementation such that we aren't malloc'ing new tables. + // Once we fix the implementation, remove these NULL checks. + //if (play->msgCtx.messageEntryTableNes == NULL) { + play->msgCtx.messageEntryTableNes = OTRMessage_LoadTable("text/message_data_static/message_data_static", true); + play->msgCtx.messageEntryTable = play->msgCtx.messageEntryTableNes; + //} + + //if (play->msgCtx.messageTableStaff == NULL) { + auto file2 = + std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResource( + "text/staff_message_data_static/staff_message_data_static")); + // OTRTODO: Should not be malloc'ing here. It's fine for now since we check that the message table is already null. + play->msgCtx.messageTableStaff = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size()); + + for (size_t i = 0; i < file2->messages.size(); i++) { + play->msgCtx.messageTableStaff[i].textId = file2->messages[i].id; + play->msgCtx.messageTableStaff[i].typePos = + (file2->messages[i].textboxType << 4) | file2->messages[i].textboxYPos; + play->msgCtx.messageTableStaff[i].segment = file2->messages[i].msg.c_str(); + play->msgCtx.messageTableStaff[i].msgSize = file2->messages[i].msg.size(); + } + //} +} diff --git a/mm/2s2h/z_play_2SH.cpp b/mm/2s2h/z_play_2SH.cpp new file mode 100644 index 000000000..5679a15cc --- /dev/null +++ b/mm/2s2h/z_play_2SH.cpp @@ -0,0 +1,80 @@ +#include "BenPort.h" +#include +#include "2s2h/resource/type/Scene.h" +#include +#include +extern "C" { +#include "global.h" +#include "vt.h" +#include +} +LUS::IResource* OTRPlay_LoadFile(PlayState* play, const char* fileName) { + auto res = LUS::Context::GetInstance()->GetResourceManager()->LoadResource(fileName); + return res.get(); +} + +s32 OTRScene_ExecuteCommands(PlayState* play, LUS::Scene* scene); + +extern "C" void OTRPlay_InitScene(PlayState* play, s32 spawn) { + play->curSpawn = spawn; + play->linkActorEntry = NULL; + play->actorCsCamList = NULL; + play->setupEntranceList = NULL; + play->setupExitList = NULL; + play->naviQuestHints = NULL; + play->setupPathList = NULL; + play->sceneMaterialAnims = NULL; + play->roomCtx.unk74 = NULL; + play->numSetupActors = 0; + Object_InitContext(&play->state, &play->objectCtx); + LightContext_Init(play, &play->lightCtx); + Scene_ResetTransitionActorList(&play->state, &play->transitionActors); + Room_Init(play, &play->roomCtx); + gSaveContext.worldMapArea = 0; + OTRScene_ExecuteCommands(play, (LUS::Scene*)play->sceneSegment); + Play_InitEnvironment(play, play->skyboxId); +} + +extern "C" void OTRPlay_SpawnScene(PlayState* play, s32 sceneId, s32 spawn) { + s32 pad; + SceneTableEntry* scene = &gSceneTable[sceneId]; + + scene->unk_D = 0; + play->loadedScene = scene; + play->sceneId = sceneId; + play->sceneConfig = scene->drawConfig; + std::string scenePath = StringHelper::Sprintf("scenes/nonmq/%s/%s", scene->segment.fileName, scene->segment.fileName); + play->sceneSegment = OTRPlay_LoadFile(play, scenePath.c_str()); + scene->unk_D = 0; + gSegments[2] = (uintptr_t)play->sceneSegment; + OTRPlay_InitScene(play, spawn); + Room_AllocateAndLoad(play, &play->roomCtx); +} + +extern "C" s32 OTRfunc_800973FC(PlayState* play, RoomContext* roomCtx) { + if (roomCtx->status == 1) { + // if (!osRecvMesg(&roomCtx->loadQueue, NULL, OS_MESG_NOBLOCK)) { + if (1) { + roomCtx->status = 0; + roomCtx->curRoom.segment = roomCtx->activeRoomVram; + gSegments[3] = (uintptr_t)roomCtx->activeRoomVram; + + OTRScene_ExecuteCommands(play, (LUS::Scene*)roomCtx->curRoom.segment); + func_80123140(play, GET_PLAYER(play)); + Actor_SpawnTransitionActors(play, &play->actorCtx); + if (((play->sceneId != SCENE_IKANA) || (roomCtx->curRoom.num != 1)) && (play->sceneId != SCENE_IKNINSIDE)) { + play->envCtx.lightSettingOverride = LIGHT_SETTING_OVERRIDE_NONE; + play->envCtx.lightBlendOverride = LIGHT_BLEND_OVERRIDE_NONE; + } + func_800FEAB0(); + if (Environment_GetStormState(play) == STORM_STATE_OFF) { + Environment_StopStormNatureAmbience(play); + } + return 1; + } + + return 0; + } + + return 1; +} \ No newline at end of file diff --git a/mm/2s2h/z_scene_2SH.cpp b/mm/2s2h/z_scene_2SH.cpp new file mode 100644 index 000000000..586d9d6b4 --- /dev/null +++ b/mm/2s2h/z_scene_2SH.cpp @@ -0,0 +1,450 @@ +#include "BenPort.h" +extern "C" { +#include "z64.h" +#include "vt.h" +#include "global.h" +} +#include +#include +#include +#include +#include +#include +#include "2s2h/resource/type/Scene.h" +#include "2s2h/resource/type/CollisionHeader.h" +#include "2s2h/resource/type/Cutscene.h" +#include "2s2h/resource/type/Path.h" +#include "2s2h/resource/type/Text.h" +#include "2s2h/resource/type/scenecommand/SetCameraSettings.h" +#include "2s2h/resource/type/scenecommand/SetCutscenes.h" +#include "2s2h/resource/type/scenecommand/SetStartPositionList.h" +#include "2s2h/resource/type/scenecommand/SetActorList.h" +#include "2s2h/resource/type/scenecommand/SetCollisionHeader.h" +#include "2s2h/resource/type/scenecommand/SetRoomList.h" +#include "2s2h/resource/type/scenecommand/SetEntranceList.h" +#include "2s2h/resource/type/scenecommand/SetSpecialObjects.h" +#include "2s2h/resource/type/scenecommand/SetRoomBehavior.h" +#include "2s2h/resource/type/scenecommand/SetMesh.h" +#include "2s2h/resource/type/scenecommand/SetObjectList.h" +#include "2s2h/resource/type/scenecommand/SetLightList.h" +#include "2s2h/resource/type/scenecommand/SetPathways.h" +#include "2s2h/resource/type/scenecommand/SetTransitionActorList.h" +#include "2s2h/resource/type/scenecommand/SetSkyboxSettings.h" +#include "2s2h/resource/type/scenecommand/SetSkyboxModifier.h" +#include "2s2h/resource/type/scenecommand/SetTimeSettings.h" +#include "2s2h/resource/type/scenecommand/SetWindSettings.h" +#include "2s2h/resource/type/scenecommand/SetSoundSettings.h" +#include "2s2h/resource/type/scenecommand/SetEchoSettings.h" +#include "2s2h/resource/type/scenecommand/SetAlternateHeaders.h" +#include "2s2h/resource/type/scenecommand/SetActorCutsceneList.h" +#include "2s2h/resource/type/scenecommand/SetAnimatedMaterialList.h" +#include "2s2h/resource/type/scenecommand/SetMinimapList.h" +#include "2s2h/resource/type/scenecommand/SetMinimapChests.h" +#include "2s2h/resource/type/scenecommand/SetCsCamera.h" + +s32 OTRScene_ExecuteCommands(PlayState* play, LUS::Scene* scene); + + +void Scene_CommandSpawnList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetStartPositionList* list = (LUS::SetStartPositionList*)cmd; + ActorEntry* entries = (ActorEntry*)(list->GetRawPointer()); + s32 loadedCount; + s16 playerObjectId; + void* objectPtr; + + play->linkActorEntry = &entries[play->setupEntranceList[play->curSpawn].spawn]; + + if ((PLAYER_GET_INITMODE(play->linkActorEntry) == PLAYER_INITMODE_TELESCOPE) || + ((gSaveContext.respawnFlag == 2) && + (gSaveContext.respawn[RESPAWN_MODE_RETURN].playerParams == PLAYER_PARAMS(0xFF, PLAYER_INITMODE_TELESCOPE)))) { + // Skull Kid Object + Object_SpawnPersistent(&play->objectCtx, OBJECT_STK); + return; + } + + loadedCount = Object_SpawnPersistent(&play->objectCtx, OBJECT_LINK_CHILD); + objectPtr = play->objectCtx.slots[play->objectCtx.numEntries].segment; + play->objectCtx.numEntries = loadedCount; + play->objectCtx.numPersistentEntries = loadedCount; + playerObjectId = gPlayerFormObjectIds[GET_PLAYER_FORM]; + gActorOverlayTable[0].initInfo->objectId = playerObjectId; + Object_SpawnPersistent(&play->objectCtx, playerObjectId); + + play->objectCtx.slots[play->objectCtx.numEntries].segment = objectPtr; +} + +void Scene_CommandActorList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetActorList* list = (LUS::SetActorList*)cmd; + + play->numSetupActors = list->numActors; + play->actorCtx.halfDaysBit = 0; + play->setupActorList = (ActorEntry*)list->GetRawPointer(); +} + +void Scene_CommandActorCutsceneCamList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetCsCamera* cams = (LUS::SetCsCamera*)cmd; + + play->actorCsCamList = (ActorCsCamInfo*)cams->GetPointer(); +} + +void Scene_CommandCollisionHeader(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetCollisionHeader* colHeader = (LUS::SetCollisionHeader*)cmd; + BgCheck_Allocate(&play->colCtx, play, (CollisionHeader*)colHeader->GetRawPointer()); +} + +void Scene_CommandRoomList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetRoomList* list = (LUS::SetRoomList*)cmd; + play->numRooms = list->numRooms; + play->roomList = (RomFile*)list->GetPointer(); +} + +void Scene_CommandWindSettings(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetWindSettings* settings = (LUS::SetWindSettings*)cmd; + + play->envCtx.windDirection.x = settings->settings.windWest; + play->envCtx.windDirection.y = settings->settings.windVertical; + play->envCtx.windDirection.z = settings->settings.windSouth; + play->envCtx.windSpeed = settings->settings.windSpeed; +} + +void Scene_CommandEntranceList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetEntranceList* list = (LUS::SetEntranceList*)cmd; + + play->setupEntranceList = (EntranceEntry*)list->GetRawPointer(); +} + +void Scene_CommandSpecialFiles(PlayState* play, LUS::ISceneCommand* cmd) { + printf("Un-implemented command %02X\n", cmd->cmdId); + // Unused according to z_scene.c +} + +void Scene_CommandRoomBehavior(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetRoomBehaviorMM* behavior = (LUS::SetRoomBehaviorMM*)cmd; + + play->roomCtx.curRoom.behaviorType1 = behavior->roomBehavior.gameplayFlags; + play->roomCtx.curRoom.behaviorType2 = behavior->roomBehavior.currRoomUnk2; + play->roomCtx.curRoom.lensMode = behavior->roomBehavior.currRoomUnk5; + play->msgCtx.unk12044 = behavior->roomBehavior.msgCtxUnk; + play->roomCtx.curRoom.enablePosLights = behavior->roomBehavior.enablePointLights; + play->envCtx.stormState = behavior->roomBehavior.kankyoContextUnkE2; + //play->roomCtx.curRoom.behaviorType1 = behavior->roomBehavior.gameplayFlags; + //play->roomCtx.curRoom.behaviorType2 = behavior->roomBehavior.gameplayFlags2 & 0xFF; + //play->roomCtx.curRoom.lensMode = (behavior->roomBehavior.gameplayFlags2 >> 8) & 1; + //play->msgCtx.unk12044 = (behavior->roomBehavior.gameplayFlags2 >> 0xA) & 1; + //play->roomCtx.curRoom.enablePosLights = (behavior->roomBehavior.gameplayFlags2 >> 0xB) & 1; + //play->envCtx.stormState = (behavior->roomBehavior.gameplayFlags2 >> 0xC) & 1; +} + +void Scene_Command09(PlayState* play, LUS::ISceneCommand* cmd) { + // Empty in z_scene.c +} + +void Scene_CommandMesh(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetMesh* mesh = (LUS::SetMesh*)cmd; + + play->roomCtx.curRoom.roomShape = (RoomShape*)mesh->GetRawPointer(); +} + +void Scene_CommandObjectList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetObjectList* objList = (LUS::SetObjectList*)cmd; + + s16* entry = (s16*)objList->GetRawPointer(); + + for (unsigned int i = 0; i < objList->objects.size(); i++) { + bool alreadyIncluded = true; + + for (unsigned int j = 0; j < play->objectCtx.numEntries; j++) { + if (play->objectCtx.slots[j].id == objList->objects[i]) { + alreadyIncluded = true; + break; + } + } + + if (!alreadyIncluded) { + play->objectCtx.slots[play->objectCtx.numEntries++].id = objList->objects[i]; + Actor_KillAllWithMissingObject(play, &play->actorCtx); + } + } +} + +void Scene_CommandLightList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetLightList* lightList = (LUS::SetLightList*)cmd; + + for (unsigned int i = 0; i < lightList->numLights; i++) { + LightContext_InsertLight(play, &play->lightCtx, (LightInfo*)&lightList->lightList[i]); + } +} + +void Scene_CommandPathList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetPathwaysMM* paths = (LUS::SetPathwaysMM*)cmd; + + play->setupPathList = (Path*)paths->GetPointer()[0]; +} + +void Scene_CommandTransiActorList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetTransitionActorList* list = (LUS::SetTransitionActorList*)cmd; + + play->transitionActors.count = list->numTransitionActors; + play->transitionActors.list = (TransitionActorEntry*)list->GetRawPointer(); +} + +void Scene_CommandEnvLightSettings(PlayState* play, LUS::ISceneCommand* cmd) { + play->envCtx.lightSettingsList = (EnvLightSettings*)cmd->GetRawPointer(); +} + +void Scene_CommandTimeSettings(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetTimeSettings* settings = (LUS::SetTimeSettings*)cmd; + + if ((settings->settings.hour != 0xFF) && (settings->settings.minute != 0xFF)) { + gSaveContext.skyboxTime = gSaveContext.save.time = CLOCK_TIME_ALT2_F(settings->settings.hour, settings->settings.minute); + } + + if (settings->settings.timeIncrement != 0xFF) { + play->envCtx.sceneTimeSpeed = settings->settings.timeIncrement; + } else { + play->envCtx.sceneTimeSpeed = 0; + } + + // Increase time speed during first cycle + if ((gSaveContext.save.saveInfo.inventory.items[SLOT_OCARINA] == ITEM_NONE) && (play->envCtx.sceneTimeSpeed != 0)) { + play->envCtx.sceneTimeSpeed = 5; + } + + if (gSaveContext.sunsSongState == SUNSSONG_INACTIVE) { + R_TIME_SPEED = play->envCtx.sceneTimeSpeed; + } + + play->envCtx.sunPos.x = -(Math_SinS(((void)0, gSaveContext.save.time) - CLOCK_TIME(12, 0)) * 120.0f) * 25.0f; + play->envCtx.sunPos.y = (Math_CosS(((void)0, gSaveContext.save.time) - CLOCK_TIME(12, 0)) * 120.0f) * 25.0f; + play->envCtx.sunPos.z = (Math_CosS(((void)0, gSaveContext.save.time) - CLOCK_TIME(12, 0)) * 20.0f) * 25.0f; + + if ((play->envCtx.sceneTimeSpeed == 0) && (gSaveContext.save.cutsceneIndex < 0xFFF0)) { + gSaveContext.skyboxTime = gSaveContext.save.time; + + if ((gSaveContext.skyboxTime >= CLOCK_TIME(4, 0)) && (gSaveContext.skyboxTime < CLOCK_TIME(6, 30))) { + gSaveContext.skyboxTime = CLOCK_TIME(5, 0); + } else if ((gSaveContext.skyboxTime >= CLOCK_TIME(6, 30)) && (gSaveContext.skyboxTime < CLOCK_TIME(8, 0))) { + gSaveContext.skyboxTime = CLOCK_TIME(8, 0); + } else if ((gSaveContext.skyboxTime >= CLOCK_TIME(16, 0)) && (gSaveContext.skyboxTime < CLOCK_TIME(17, 0))) { + gSaveContext.skyboxTime = CLOCK_TIME(17, 0); + } else if ((gSaveContext.skyboxTime >= CLOCK_TIME(18, 0)) && (gSaveContext.skyboxTime < CLOCK_TIME(19, 0))) { + gSaveContext.skyboxTime = CLOCK_TIME(19, 0); + } + } +} + +void Scene_CommandSkyboxSettings(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetSkyboxSettings* settings = (LUS::SetSkyboxSettings*)cmd; + + play->skyboxId = settings->settings.skyboxId & 3; + // BENTODO z_scene.c reads from skyboxSettings.skyboxConfig not weather + // Settings uses names from OOT + play->envCtx.skyboxConfig = play->envCtx.changeSkyboxNextConfig = settings->settings.weather; + play->envCtx.lightMode = settings->settings.indoors; + //Scene_LoadAreaTextures(play, settings->settings.) +} + +void Scene_CommandSkyboxDisables(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetSkyboxModifier* mod = (LUS::SetSkyboxModifier*)cmd; + + play->envCtx.skyboxDisabled = mod->modifier.skyboxDisabled; + play->envCtx.sunDisabled = mod->modifier.sunMoonDisabled; +} + +void Scene_CommandExitList(PlayState* play, LUS::ISceneCommand* cmd) { + play->setupExitList = (u16*)cmd->GetRawPointer(); +} + +void Scene_CommandSoundSettings(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetSoundSettings* settings = (LUS::SetSoundSettings*)cmd; + + play->sequenceCtx.seqId = settings->settings.seqId; + play->sequenceCtx.ambienceId = settings->settings.natureAmbienceId; + + if(gSaveContext.seqId == (u8)NA_BGM_DISABLED || AudioSeq_GetActiveSeqId(SEQ_PLAYER_BGM_MAIN) == NA_BGM_FINAL_HOURS) { + Audio_SetSpec(settings->settings.reverb); // BENTODO Verify if this should be reverb + } + } + +void Scene_CommandEchoSetting(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetEchoSettings* echo = (LUS::SetEchoSettings*)cmd; + play->roomCtx.curRoom.echo = echo->settings.echo; +} + +void Scene_CommandCutsceneScriptList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetCutscenesMM* cs = (LUS::SetCutscenesMM*)cmd; + play->csCtx.scriptListCount = cs->entries.size(); + // BENTODO do this the right way with get pointer + play->csCtx.scriptList = (CutsceneScriptEntry*)cs->entries.data(); + +} + +void Scene_CommandAltHeaderList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetAlternateHeaders* headers = (LUS::SetAlternateHeaders*)cmd; + + if (gSaveContext.sceneLayer != 0) { + LUS::Scene* desiredHeader = + std::static_pointer_cast(headers->headers[gSaveContext.sceneLayer - 1]).get(); + + if (desiredHeader != nullptr) { + OTRScene_ExecuteCommands(play, desiredHeader); + // z_scene does (cmd + 1)->base.code = 0x14; + } + } +} + +void Scene_CommandSetRegionVisitedFlag(PlayState* play, LUS::ISceneCommand* cmd) { + s16 j = 0; + s16 i = 0; + + while (true) { + if (gSceneIdsPerRegion[i][j] == 0xFFFF) { + i++; + j = 0; + + if (i == REGION_MAX) { + break; + } + } + + if (play->sceneId == gSceneIdsPerRegion[i][j]) { + break; + } + + j++; + } + + if (i < REGION_MAX) { + gSaveContext.save.saveInfo.regionsVisited = + (gBitFlags[i] | gSaveContext.save.saveInfo.regionsVisited) | gSaveContext.save.saveInfo.regionsVisited; + } +} + +void Scene_CommandAnimatedMaterials(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetAnimatedMaterialList* list = (LUS::SetAnimatedMaterialList*)cmd; + play->sceneMaterialAnims = (AnimatedMaterial*)list->mat; +} + +void Scene_CommandCutsceneList(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetActorCutsceneList* list = (LUS::SetActorCutsceneList*)cmd; + + CutsceneManager_Init(play, (ActorCutscene*)list->GetPointer(), list->numEntries); +} + +void Scene_CommandMiniMap(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetMinimapList* list = (LUS::SetMinimapList*)cmd; + + MapDisp_Init(play); + + MapDisp_InitMapData(play, list->GetPointer()); +} + +void Scene_Command1D(PlayState* play, LUS::ISceneCommand* cmd) { + +} + +void Scene_CommandMiniMapCompassInfo(PlayState* play, LUS::ISceneCommand* cmd) { + LUS::SetMinimapChests* chests = (LUS::SetMinimapChests*)cmd; + + MapDisp_InitChestData(play, chests->chests.size(), chests->GetPointer()); +} + +void (*sSceneCmdHandlersOTR[SCENE_CMD_MAX])(PlayState*, LUS::ISceneCommand*) = { + Scene_CommandSpawnList, // SCENE_CMD_ID_SPAWN_LIST + Scene_CommandActorList, // SCENE_CMD_ID_ACTOR_LIST + Scene_CommandActorCutsceneCamList, // SCENE_CMD_ID_ACTOR_CUTSCENE_CAM_LIST + Scene_CommandCollisionHeader, // SCENE_CMD_ID_COL_HEADER + Scene_CommandRoomList, // SCENE_CMD_ID_ROOM_LIST + Scene_CommandWindSettings, // SCENE_CMD_ID_WIND_SETTINGS + Scene_CommandEntranceList, // SCENE_CMD_ID_ENTRANCE_LIST + Scene_CommandSpecialFiles, // SCENE_CMD_ID_SPECIAL_FILES + Scene_CommandRoomBehavior, // SCENE_CMD_ID_ROOM_BEHAVIOR + Scene_Command09, // SCENE_CMD_ID_UNK_09 + Scene_CommandMesh, // SCENE_CMD_ID_ROOM_SHAPE + Scene_CommandObjectList, // SCENE_CMD_ID_OBJECT_LIST + Scene_CommandLightList, // SCENE_CMD_ID_LIGHT_LIST + Scene_CommandPathList, // SCENE_CMD_ID_PATH_LIST + Scene_CommandTransiActorList, // SCENE_CMD_ID_TRANSI_ACTOR_LIST + Scene_CommandEnvLightSettings, // SCENE_CMD_ID_ENV_LIGHT_SETTINGS + Scene_CommandTimeSettings, // SCENE_CMD_ID_TIME_SETTINGS + Scene_CommandSkyboxSettings, // SCENE_CMD_ID_SKYBOX_SETTINGS + Scene_CommandSkyboxDisables, // SCENE_CMD_ID_SKYBOX_DISABLES + Scene_CommandExitList, // SCENE_CMD_ID_EXIT_LIST + NULL, // SCENE_CMD_ID_END + Scene_CommandSoundSettings, // SCENE_CMD_ID_SOUND_SETTINGS + Scene_CommandEchoSetting, // SCENE_CMD_ID_ECHO_SETTINGS + Scene_CommandCutsceneScriptList, // SCENE_CMD_ID_CUTSCENE_SCRIPT_LIST + Scene_CommandAltHeaderList, // SCENE_CMD_ID_ALTERNATE_HEADER_LIST + Scene_CommandSetRegionVisitedFlag, // SCENE_CMD_ID_SET_REGION_VISITED + Scene_CommandAnimatedMaterials, // SCENE_CMD_ID_ANIMATED_MATERIAL_LIST + Scene_CommandCutsceneList, // SCENE_CMD_ID_ACTOR_CUTSCENE_LIST + Scene_CommandMiniMap, // SCENE_CMD_ID_MINIMAP_INFO + Scene_Command1D, // SCENE_CMD_ID_UNUSED_1D + Scene_CommandMiniMapCompassInfo, // SCENE_CMD_ID_MINIMAP_COMPASS_ICON_INFO +}; + +s32 OTRScene_ExecuteCommands(PlayState* play, LUS::Scene* scene) { + LUS::SceneCommandID cmdCode; + + for (int i = 0; i < scene->commands.size(); i++) { + auto sceneCmd = scene->commands[i]; + + if (sceneCmd == nullptr) // UH OH + continue; + + cmdCode = sceneCmd->cmdId; + // osSyncPrintf("*** Scene_Word = { code=%d, data1=%02x, data2=%04x } ***\n", cmdCode, sceneCmd->base.data1, sceneCmd->base.data2); + //SPDLOG_TRACE("CMD {:X}", cmdCode); + if ((int)cmdCode == SCENE_CMD_ID_END) { + break; + } else if (cmdCode == LUS::SceneCommandID::SetCutscenesMM) + cmdCode = LUS::SceneCommandID::SetCutscenes; + + //if ((int)cmdCode <= 0x19) + sSceneCmdHandlersOTR[(int)cmdCode](play, sceneCmd.get()); + + + // sceneCmd++; + } + return 0; +} + + +std::shared_ptr GetResourceByNameHandlingMQ(const char* path); + +extern "C" s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomNum) { + + u32 size; + + if (roomCtx->status == 0) { + roomCtx->prevRoom = roomCtx->curRoom; + roomCtx->curRoom.num = roomNum; + roomCtx->curRoom.segment = NULL; + roomCtx->status = 1; + + //assert(roomNum < play->numRooms); + + if (roomNum >= play->numRooms) + return 0; // UH OH + + size = play->roomList[roomNum].vromEnd - play->roomList[roomNum].vromStart; + //roomCtx->activeRoomVram = + // (void*)((uintptr_t)roomCtx->roomMemPages[roomCtx->activeMemPage] - ((size + 8) * roomCtx->activeMemPage + 7)); + + // DmaMgr_SendRequest2(&roomCtx->dmaRequest, roomCtx->unk_34, play->roomList[roomNum].vromStart, size, 0, + //&roomCtx->loadQueue, NULL, __FILE__, __LINE__); + printf("File Name %s\n", play->roomList[roomNum].fileName); + auto roomData = + std::static_pointer_cast(GetResourceByNameHandlingMQ(play->roomList[roomNum].fileName)); + roomCtx->status = 1; + roomCtx->activeRoomVram = roomData.get(); + + roomCtx->activeMemPage ^= 1; + + //SPDLOG_INFO("Room Init - curRoom.num: {0:#x}", roomCtx->curRoom.num); + + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/mm/CMake/Default.cmake b/mm/CMake/Default.cmake new file mode 100644 index 000000000..70bfa9038 --- /dev/null +++ b/mm/CMake/Default.cmake @@ -0,0 +1,65 @@ +################################################################################ +# Command for variable_watch. This command issues error message, if a variable +# is changed. If variable PROPERTY_READER_GUARD_DISABLED is TRUE nothing happens +# variable_watch( property_reader_guard) +################################################################################ +function(property_reader_guard VARIABLE ACCESS VALUE CURRENT_LIST_FILE STACK) + if("${PROPERTY_READER_GUARD_DISABLED}") + return() + endif() + + if("${ACCESS}" STREQUAL "MODIFIED_ACCESS") + message(FATAL_ERROR + " Variable ${VARIABLE} is not supposed to be changed.\n" + " It is used only for reading target property ${VARIABLE}.\n" + " Use\n" + " set_target_properties(\"\" PROPERTIES \"${VARIABLE}\" \"\")\n" + " or\n" + " set_target_properties(\"\" PROPERTIES \"${VARIABLE}_\" \"\")\n" + " instead.\n") + endif() +endfunction() + +################################################################################ +# Create variable with generator expression that expands to value of +# target property _. If property is empty or not set then property +# is used instead. Variable has watcher property_reader_guard that +# doesn't allow to edit it. +# create_property_reader() +# Input: +# name - Name of watched property and output variable +################################################################################ +function(create_property_reader NAME) + set(PROPERTY_READER_GUARD_DISABLED TRUE) + set(CONFIG_VALUE "$>>>") + set(IS_CONFIG_VALUE_EMPTY "$") + set(GENERAL_VALUE "$>") + set("${NAME}" "$" PARENT_SCOPE) + variable_watch("${NAME}" property_reader_guard) +endfunction() + +################################################################################ +# Set property $_${PROPS_CONFIG_U} of ${PROPS_TARGET} to +# set_config_specific_property( ) +# Input: +# name - Prefix of property name +# value - New value +################################################################################ +function(set_config_specific_property NAME VALUE) + set_target_properties("${PROPS_TARGET}" PROPERTIES "${NAME}_${PROPS_CONFIG_U}" "${VALUE}") +endfunction() + +################################################################################ + +create_property_reader("TARGET_NAME") +create_property_reader("OUTPUT_DIRECTORY") + +set_config_specific_property("TARGET_NAME" "${PROPS_TARGET}") +set_config_specific_property("OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("ARCHIVE_OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("LIBRARY_OUTPUT_NAME" "${TARGET_NAME}") +set_config_specific_property("RUNTIME_OUTPUT_NAME" "${TARGET_NAME}") + +set_config_specific_property("ARCHIVE_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") +set_config_specific_property("LIBRARY_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") +set_config_specific_property("RUNTIME_OUTPUT_DIRECTORY" "${OUTPUT_DIRECTORY}") \ No newline at end of file diff --git a/mm/CMake/DefaultCXX.cmake b/mm/CMake/DefaultCXX.cmake new file mode 100644 index 000000000..7b052b9cc --- /dev/null +++ b/mm/CMake/DefaultCXX.cmake @@ -0,0 +1,12 @@ +include("${CMAKE_CURRENT_LIST_DIR}/Default.cmake") + +set_config_specific_property("OUTPUT_DIRECTORY" "${CMAKE_SOURCE_DIR}$<$>:/${CMAKE_VS_PLATFORM_NAME}>/${PROPS_CONFIG}") + +if(MSVC) + create_property_reader("DEFAULT_CXX_EXCEPTION_HANDLING") + create_property_reader("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT") + + set_target_properties("${PROPS_TARGET}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set_config_specific_property("DEFAULT_CXX_EXCEPTION_HANDLING" "/EHsc") + set_config_specific_property("DEFAULT_CXX_DEBUG_INFORMATION_FORMAT" "/Zi") +endif() \ No newline at end of file diff --git a/mm/CMake/Linux32bit-toolchain.cmake b/mm/CMake/Linux32bit-toolchain.cmake new file mode 100644 index 000000000..824f63263 --- /dev/null +++ b/mm/CMake/Linux32bit-toolchain.cmake @@ -0,0 +1,15 @@ +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER gcc) +set(CMAKE_C_FLAGS "-m32") +set(CMAKE_CXX_COMPILER g++) +set(CMAKE_CXX_FLAGS -m32) + +# here is the target environment located +#set(CMAKE_FIND_ROOT_PATH /lib/i386-linux-gnu ) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) diff --git a/mm/CMake/Utils.cmake b/mm/CMake/Utils.cmake new file mode 100644 index 000000000..5bce7d488 --- /dev/null +++ b/mm/CMake/Utils.cmake @@ -0,0 +1,233 @@ +# utils file for projects came from visual studio solution with cmake-converter. + +################################################################################ +# Wrap each token of the command with condition +################################################################################ +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) +macro(prepare_commands) + unset(TOKEN_ROLE) + unset(COMMANDS) + foreach(TOKEN ${ARG_COMMANDS}) + if("${TOKEN}" STREQUAL "COMMAND") + set(TOKEN_ROLE "KEYWORD") + elseif("${TOKEN_ROLE}" STREQUAL "KEYWORD") + set(TOKEN_ROLE "CONDITION") + elseif("${TOKEN_ROLE}" STREQUAL "CONDITION") + set(TOKEN_ROLE "COMMAND") + elseif("${TOKEN_ROLE}" STREQUAL "COMMAND") + set(TOKEN_ROLE "ARG") + endif() + + if("${TOKEN_ROLE}" STREQUAL "KEYWORD") + list(APPEND COMMANDS "${TOKEN}") + elseif("${TOKEN_ROLE}" STREQUAL "CONDITION") + set(CONDITION ${TOKEN}) + elseif("${TOKEN_ROLE}" STREQUAL "COMMAND") + list(APPEND COMMANDS "$<$:${DUMMY}>$<${CONDITION}:${TOKEN}>") + elseif("${TOKEN_ROLE}" STREQUAL "ARG") + list(APPEND COMMANDS "$<${CONDITION}:${TOKEN}>") + endif() + endforeach() +endmacro() +cmake_policy(POP) + +################################################################################ +# Transform all the tokens to absolute paths +################################################################################ +macro(prepare_output) + unset(OUTPUT) + foreach(TOKEN ${ARG_OUTPUT}) + if(IS_ABSOLUTE ${TOKEN}) + list(APPEND OUTPUT "${TOKEN}") + else() + list(APPEND OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${TOKEN}") + endif() + endforeach() +endmacro() + +################################################################################ +# Parse add_custom_command_if args. +# +# Input: +# PRE_BUILD - Pre build event option +# PRE_LINK - Pre link event option +# POST_BUILD - Post build event option +# TARGET - Target +# OUTPUT - List of output files +# DEPENDS - List of files on which the command depends +# COMMANDS - List of commands(COMMAND condition1 commannd1 args1 COMMAND +# condition2 commannd2 args2 ...) +# Output: +# OUTPUT - Output files +# DEPENDS - Files on which the command depends +# COMMENT - Comment +# PRE_BUILD - TRUE/FALSE +# PRE_LINK - TRUE/FALSE +# POST_BUILD - TRUE/FALSE +# TARGET - Target name +# COMMANDS - Prepared commands(every token is wrapped in CONDITION) +# NAME - Unique name for custom target +# STEP - PRE_BUILD/PRE_LINK/POST_BUILD +################################################################################ +function(add_custom_command_if_parse_arguments) + cmake_parse_arguments("ARG" "PRE_BUILD;PRE_LINK;POST_BUILD" "TARGET;COMMENT" "DEPENDS;OUTPUT;COMMANDS" ${ARGN}) + + if(WIN32) + set(DUMMY "cd.") + elseif(UNIX) + set(DUMMY "true") + endif() + + prepare_commands() + prepare_output() + + set(DEPENDS "${ARG_DEPENDS}") + set(COMMENT "${ARG_COMMENT}") + set(PRE_BUILD "${ARG_PRE_BUILD}") + set(PRE_LINK "${ARG_PRE_LINK}") + set(POST_BUILD "${ARG_POST_BUILD}") + set(TARGET "${ARG_TARGET}") + if(PRE_BUILD) + set(STEP "PRE_BUILD") + elseif(PRE_LINK) + set(STEP "PRE_LINK") + elseif(POST_BUILD) + set(STEP "POST_BUILD") + endif() + set(NAME "${TARGET}_${STEP}") + + set(OUTPUT "${OUTPUT}" PARENT_SCOPE) + set(DEPENDS "${DEPENDS}" PARENT_SCOPE) + set(COMMENT "${COMMENT}" PARENT_SCOPE) + set(PRE_BUILD "${PRE_BUILD}" PARENT_SCOPE) + set(PRE_LINK "${PRE_LINK}" PARENT_SCOPE) + set(POST_BUILD "${POST_BUILD}" PARENT_SCOPE) + set(TARGET "${TARGET}" PARENT_SCOPE) + set(COMMANDS "${COMMANDS}" PARENT_SCOPE) + set(STEP "${STEP}" PARENT_SCOPE) + set(NAME "${NAME}" PARENT_SCOPE) +endfunction() + +################################################################################ +# Add conditional custom command +# +# Generating Files +# The first signature is for adding a custom command to produce an output: +# add_custom_command_if( +# +# +# +# [COMMAND condition command2 [args2...]] +# [DEPENDS [depends...]] +# [COMMENT comment] +# +# Build Events +# add_custom_command_if( +# +# +# +# [COMMAND condition command2 [args2...]] +# [COMMENT comment] +# +# Input: +# output - Output files the command is expected to produce +# condition - Generator expression for wrapping the command +# command - Command-line(s) to execute at build time. +# args - Command`s args +# depends - Files on which the command depends +# comment - Display the given message before the commands are executed at +# build time. +# PRE_BUILD - Run before any other rules are executed within the target +# PRE_LINK - Run after sources have been compiled but before linking the +# binary +# POST_BUILD - Run after all other rules within the target have been +# executed +################################################################################ +function(add_custom_command_if) + add_custom_command_if_parse_arguments(${ARGN}) + + if(OUTPUT AND TARGET) + message(FATAL_ERROR "Wrong syntax. A TARGET and OUTPUT can not both be specified.") + endif() + + if(OUTPUT) + add_custom_command(OUTPUT ${OUTPUT} + ${COMMANDS} + DEPENDS ${DEPENDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + elseif(TARGET) + if(PRE_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio") + add_custom_target( + ${NAME} + ${COMMANDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + add_dependencies(${TARGET} ${NAME}) + else() + add_custom_command( + TARGET ${TARGET} + ${STEP} + ${COMMANDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT ${COMMENT}) + endif() + else() + message(FATAL_ERROR "Wrong syntax. A TARGET or OUTPUT must be specified.") + endif() +endfunction() + +################################################################################ +# Use props file for a target and configs +# use_props( ) +# Inside there are following variables: +# PROPS_TARGET - +# PROPS_CONFIG - One of +# PROPS_CONFIG_U - Uppercase PROPS_CONFIG +# Input: +# target - Target to apply props file +# configs - Build configurations to apply props file +# props_file - CMake script +################################################################################ +macro(use_props TARGET CONFIGS PROPS_FILE) + set(PROPS_TARGET "${TARGET}") + foreach(PROPS_CONFIG ${CONFIGS}) + string(TOUPPER "${PROPS_CONFIG}" PROPS_CONFIG_U) + + get_filename_component(ABSOLUTE_PROPS_FILE "${PROPS_FILE}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") + if(EXISTS "${ABSOLUTE_PROPS_FILE}") + include("${ABSOLUTE_PROPS_FILE}") + else() + message(WARNING "Corresponding cmake file from props \"${ABSOLUTE_PROPS_FILE}\" doesn't exist") + endif() + endforeach() +endmacro() + +################################################################################ +# Add compile options to source file +# source_file_compile_options( [compile_options...]) +# Input: +# source_file - Source file +# compile_options - Options to add to COMPILE_FLAGS property +################################################################################ +function(source_file_compile_options SOURCE_FILE) + if("${ARGC}" LESS_EQUAL "1") + return() + endif() + + get_source_file_property(COMPILE_OPTIONS "${SOURCE_FILE}" COMPILE_OPTIONS) + + if(COMPILE_OPTIONS) + list(APPEND COMPILE_OPTIONS ${ARGN}) + else() + set(COMPILE_OPTIONS "${ARGN}") + endif() + + set_source_files_properties("${SOURCE_FILE}" PROPERTIES COMPILE_OPTIONS "${COMPILE_OPTIONS}") +endfunction() + +################################################################################ +# Default properties of visual studio projects +################################################################################ +set(DEFAULT_CXX_PROPS "${CMAKE_CURRENT_LIST_DIR}/DefaultCXX.cmake") diff --git a/mm/CMakeLists.txt b/mm/CMakeLists.txt new file mode 100644 index 000000000..192ef0cab --- /dev/null +++ b/mm/CMakeLists.txt @@ -0,0 +1,824 @@ +cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR) + +set(CMAKE_SYSTEM_VERSION 10.0 CACHE STRING "" FORCE) + +project(mm LANGUAGES C CXX) +set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use") + +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + enable_language(OBJCXX) + set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-arc") + set(CMAKE_OBJCXX_FLAGS "${CMAKE_OBJCXX_FLAGS} -fobjc-arc") +endif() + +set (BUILD_UTILS OFF CACHE STRING "no utilities") +set (BUILD_SHARED_LIBS OFF CACHE STRING "install/link shared instead of static libs") + +################################################################################ +# Set target arch type if empty. Visual studio solution generator provides it. +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if(NOT CMAKE_VS_PLATFORM_NAME) + set(CMAKE_VS_PLATFORM_NAME "x64") + endif() + message("${CMAKE_VS_PLATFORM_NAME} architecture in use") + + if(NOT ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64" + OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")) + message(FATAL_ERROR "${CMAKE_VS_PLATFORM_NAME} arch is not supported!") + endif() +endif() + +################################################################################ +# Global configuration types +################################################################################ +set(CMAKE_CONFIGURATION_TYPES + "Debug" + "Release" + CACHE STRING "" FORCE +) + +################################################################################ +# Global compiler options +################################################################################ +if(MSVC) + # remove default flags provided with CMake for MSVC + set(CMAKE_C_FLAGS "") + set(CMAKE_C_FLAGS_DEBUG "") + set(CMAKE_C_FLAGS_RELEASE "") + set(CMAKE_CXX_FLAGS "") + set(CMAKE_CXX_FLAGS_DEBUG "") + set(CMAKE_CXX_FLAGS_RELEASE "") +endif() + +################################################################################ +# Global linker options +################################################################################ +if(MSVC) + # remove default flags provided with CMake for MSVC + set(CMAKE_EXE_LINKER_FLAGS "") + set(CMAKE_MODULE_LINKER_FLAGS "") + set(CMAKE_SHARED_LINKER_FLAGS "") + set(CMAKE_STATIC_LINKER_FLAGS "") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS}") +endif() + +################################################################################ +# Common utils +################################################################################ +include(CMake/Utils.cmake) + +################################################################################ +# Additional Global Settings(add specific info there) +################################################################################ +include(CMake/GlobalSettingsInclude.cmake OPTIONAL) + +################################################################################ +# Use solution folders feature +################################################################################ +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +################################################################################ +# Sub-projects +################################################################################ +if (NOT TARGET libultraship) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libultraship ${CMAKE_BINARY_DIR}/libultraship) +endif() + +if (NOT TARGET ZAPDUtils) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPDUtils ${CMAKE_BINARY_DIR}/ZAPDUtils) +endif() + +if (NOT TARGET ZAPDLib) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD) +endif() + +set(PROJECT_NAME mm) + +################################################################################ +# Sources +################################################################################ +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/boot/build.c.in ${CMAKE_BINARY_DIR}/build.c @ONLY) +#configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/boot/properties.h.in ${CMAKE_CURRENT_SOURCE_DIR}/properties.h @ONLY) + +#set(Header_Files "resource.h") +source_group("headers" FILES ${Header_Files}) + +# include {{{ +file(GLOB Header_Files__include "include/*.h" "include/*.inc") +list(APPEND Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/libc/stdarg.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/bgm.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/math_n64.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/stdbool_n64.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/stddef_n64.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/stdlib_n64.h) +list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/include/ultra64.h) +source_group("include" FILES ${Header_Files__include}) +# }}} + +# m (root) +file(GLOB soh__ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "2s2h/*.c" "2s2h/*.cpp" "2s2h/*.h") +source_group("2s2h" FILES ${soh__}) + +file(GLOB_RECURSE libultra_headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "include/PR/*.h" +) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set_source_files_properties(2s2h/BenPort.cpp PROPERTIES COMPILE_FLAGS "/utf-8") +endif() + +# soh/config {{{ +#file(GLOB_RECURSE soh__config RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} +# "soh/config/*.h" +# "soh/config/*.cpp" +#) +# }}} + +# soh/enhancements {{{ +#file(GLOB_RECURSE soh__Enhancements RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} +# "soh/Enhancements/*.c" +# "soh/Enhancements/*.cpp" +# "soh/Enhancements/*.h" +# "soh/Enhancements/*.hpp" +# "soh/Enhancements/*_extern.inc" +# "soh/Enhancements/*.mm" +#) + +#list(REMOVE_ITEM soh__Enhancements "soh/Enhancements/gamecommand.h") +#list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/gfx.*") + +# handle crowd control removals +#list(REMOVE_ITEM soh__Enhancements "soh/Enhancements/crowd-control/soh.cs") +#list(REMOVE_ITEM soh__Enhancements "soh/Enhancements/crowd-control/soh.ccpak") +#if (!BUILD_CROWD_CONTROL) +# list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/crowd-control/*") +#endif() + +# handle speechsynthesizer removals +#if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +# list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/Darwin*") +#elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") +# list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/SAPI*") +#else() +# list(FILTER soh__Enhancements EXCLUDE REGEX "soh/Enhancements/speechsynthesizer/(Darwin|SAPI).*") +#endif() + +#source_group("soh\\Enhancements" REGULAR_EXPRESSION "soh/Enhancements/*") +#source_group("soh\\Enhancements\\audio" REGULAR_EXPRESSION "soh/Enhancements/audio/*") +#source_group("soh\\Enhancements\\controls" REGULAR_EXPRESSION "soh/Enhancements/controls/*") +#source_group("soh\\Enhancements\\cosmetics" REGULAR_EXPRESSION "soh/Enhancements/cosmetics/*") +#source_group("soh\\Enhancements\\crowd-control" REGULAR_EXPRESSION "soh/Enhancements/crowd-control/*") +#source_group("soh\\Enhancements\\custom-message" REGULAR_EXPRESSION "soh/Enhancements/custom-message/*") +#source_group("soh\\Enhancements\\debugger" REGULAR_EXPRESSION "soh/Enhancements/debugger/*") +#source_group("soh\\Enhancements\\game-interactor" REGULAR_EXPRESSION "soh/Enhancements/game-interactor/*") +#source_group("soh\\Enhancements\\item-tables" REGULAR_EXPRESSION "soh/Enhancements/item-tables/*") +#source_group("soh\\Enhancements\\randomizer" REGULAR_EXPRESSION "soh/Enhancements/randomizer/*") +#source_group("soh\\Enhancements\\randomizer\\3drando" REGULAR_EXPRESSION "soh/Enhancements/randomizer/3drando/*") +#source_group("soh\\Enhancements\\randomizer\\3drando\\hint_list" REGULAR_EXPRESSION "soh/Enhancements/randomizer/3drando/hint_list/*") +#source_group("soh\\Enhancements\\randomizer\\3drando\\location_access" REGULAR_EXPRESSION "soh/Enhancements/randomizer/3drando/location_access/*") +#source_group("soh\\Enhancements\\speechsynthesizer" REGULAR_EXPRESSION "soh/Enhancements/speechsynthesizer/*") +#source_group("soh\\Enhancements\\tts" REGULAR_EXPRESSION "soh/Enhancements/tts/*") + +#if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +# set_source_files_properties(soh/Enhancements/tts/tts.cpp PROPERTIES COMPILE_FLAGS "/utf-8") +#endif() +# }}} + +if(NOT CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") + # 2s2h/Extractor {{{ + file(GLOB_RECURSE soh__Extractor RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "2s2h/Extractor/*.c" + "2s2h/Extractor/*.cpp" + "2s2h/Extractor/*.h" + "2s2h/Extractor/*.hpp" + ) + # }}} +else() + file(GLOB_RECURSE soh__Extractor RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "2s2h/Extractor/*.h" + "2s2h/Extractor/*.hpp" + ) +# }}} +endif() + +# 2s2h/resource {{{ +file(GLOB_RECURSE soh__Resource RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "2s2h/resource/*.cpp" "2s2h/resource/*.h") + +source_group("2s2h\\resource\\type" REGULAR_EXPRESSION "2s2h/resource/type/*") +source_group("2s2h\\resource\\type\\scenecommand" REGULAR_EXPRESSION "2s2h/resource/type/scenecommand/*") +source_group("2s2h\\resource\\importer" REGULAR_EXPRESSION "2s2h/resource/importer/*") +source_group("2s2h\\resource\\importer\\scenecommand" REGULAR_EXPRESSION "2s2h/resource/importer/scenecommand/*") +# }}} + +# src (decomp) {{{ +file(GLOB_RECURSE src__ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.c" "src/*.h") + +list(APPEND src__ ${CMAKE_BINARY_DIR}/build.c) +#list(APPEND src__ ${CMAKE_CURRENT_SOURCE_DIR}/properties.h) +#list(APPEND src__ ${CMAKE_CURRENT_SOURCE_DIR}/Resource.rc) +list(FILTER src__ EXCLUDE REGEX "src/dmadata/*") +list(FILTER src__ EXCLUDE REGEX "src/elf_message/*") +list(FILTER src__ EXCLUDE REGEX "src/libultra/io/*") +list(FILTER src__ EXCLUDE REGEX "src/libultra/libc/*") +list(FILTER src__ EXCLUDE REGEX "src/libultra/os/*") +list(FILTER src__ EXCLUDE REGEX "src/libultra/rmon/*") +list(FILTER src__ EXCLUDE REGEX "src/libultra/*") +#list(APPEND src__ "src/libultra/libc/sprintf.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/cosf.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/lookat.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/lookathil.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/perspective.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/position.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/sinf.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/sinf.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/sqrtf.c") +#list(REMOVE_ITEM src__ "src/libultra/gu/us2dex.c") + +source_group("src" REGULAR_EXPRESSION "src/*") +source_group("src\\build" FILES ${CMAKE_BINARY_DIR}/build.c) +source_group("src\\boot" REGULAR_EXPRESSION "src/boot/*") +source_group("src\\buffers" REGULAR_EXPRESSION "src/buffers/*") +source_group("src\\code" REGULAR_EXPRESSION "src/code/*") +#source_group("src\\libultra" REGULAR_EXPRESSION "src/libultra/*") +source_group("src\\overlays\\actors" REGULAR_EXPRESSION "src/overlays/actors/*") +source_group("src\\overlays\\effects" REGULAR_EXPRESSION "src/overlays/effects/*") +source_group("src\\overlays\\fbdemos" REGULAR_EXPRESSION "src/overlays/fbdemos/*") +source_group("src\\overlays\\gamestates" REGULAR_EXPRESSION "src/overlays/gamestates/*") +source_group("src\\overlays\\misc" REGULAR_EXPRESSION "src/overlays/misc/*") +# }}} + +set(ALL_FILES + ${Header_Files} + ${Header_Files__include} + ${soh__} + ${libultra_headers} +# ${soh__config} +# ${soh__Enhancements} + ${soh__Extractor} + ${soh__Resource} + ${src__} +) + +################################################################################ +# Target +################################################################################ +add_executable(${PROJECT_NAME} ${ALL_FILES}) + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +use_props(${PROJECT_NAME} "${CMAKE_CONFIGURATION_TYPES}" "${DEFAULT_CXX_PROPS}") +endif() + +set(ROOT_NAMESPACE 2s2h) + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + set_target_properties(${PROJECT_NAME} PROPERTIES + VS_GLOBAL_KEYWORD "Win32Proj" + ) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + set_target_properties(${PROJECT_NAME} PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE" + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + set_target_properties(${PROJECT_NAME} PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_RELEASE "TRUE" + ) + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set_target_properties(${PROJECT_NAME} PROPERTIES + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES + OUTPUT_NAME "2s2h-macos" + ) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME "2s2h.elf" + ) +endif() +################################################################################ +# MSVC runtime library +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + get_property(MSVC_RUNTIME_LIBRARY_DEFAULT TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + string(CONCAT "MSVC_RUNTIME_LIBRARY_STR" + $<$: + MultiThreadedDebug + > + $<$: + MultiThreaded + > + $<$,$>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}> + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + string(CONCAT "MSVC_RUNTIME_LIBRARY_STR" + $<$: + MultiThreadedDebug + > + $<$: + MultiThreaded + > + $<$,$>>:${MSVC_RUNTIME_LIBRARY_DEFAULT}> + ) + endif() + set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY_STR}) +endif() +################################################################################ +# Find/download Boost +################################################################################ +include(FetchContent) +FetchContent_Declare( + Boost + URL https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz + URL_HASH SHA256=205666dea9f6a7cfed87c7a6dfbeb52a2c1b9de55712c9c1a87735d7181452b6 + SOURCE_SUBDIR "null" # Set to a nonexistent directory so boost is not built (we don't need to build it) + DOWNLOAD_EXTRACT_TIMESTAMP false # supress timestamp warning, not needed since the url wont change +) + +set(Boost_NO_BOOST_CMAKE false) +set(BOOST_INCLUDEDIR ${FETCHCONTENT_BASE_DIR}/boost-src) # Location where FetchContent stores the source +message("Searching for Boost installation") +find_package(Boost) + +if (NOT ${Boost_FOUND}) + message("Boost not found. Downloading now...") + FetchContent_MakeAvailable(Boost) + message("Boost downloaded to " ${FETCHCONTENT_BASE_DIR}/boost-src) + set(BOOST-INCLUDE ${FETCHCONTENT_BASE_DIR}/boost-src) +else() + message("Boost found in " ${Boost_INCLUDE_DIRS}) + set(BOOST-INCLUDE ${Boost_INCLUDE_DIRS}) +endif() +################################################################################ +# Compile definitions +################################################################################ +find_package(SDL2) +set(SDL2-INCLUDE ${SDL2_INCLUDE_DIRS}) + +if (BUILD_CROWD_CONTROL) + find_package(SDL2_net) + set(SDL2-NET-INCLUDE ${SDL_NET_INCLUDE_DIRS}) +endif() + +target_include_directories(${PROJECT_NAME} PRIVATE assets + ${CMAKE_CURRENT_SOURCE_DIR}/include/ + ${CMAKE_CURRENT_SOURCE_DIR}/include/PR + ${CMAKE_CURRENT_SOURCE_DIR}/src/ + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/include + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/log + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/debug + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/menu + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/utils + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/utils/binarytools + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/config + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/resource + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/resource/type + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/resource/factory + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/audio + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/window + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/window/gui + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/config + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/public + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/public/libultra + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/public/bridge + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/extern + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/extern/tinyxml2 + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/libultraship/Lib/ + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/libultraship/Lib/libjpeg/include/ + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/libultraship/Lib/spdlog/include/ + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/graphic/Fast3D/U64/PR + ${CMAKE_CURRENT_SOURCE_DIR}/../libultraship/src/graphic + ${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPDUtils + ${CMAKE_CURRENT_SOURCE_DIR}/../ZAPDTR/ZAPD/resource/type + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/2s2h/ + ${SDL2-INCLUDE} + ${SDL2-NET-INCLUDE} + ${BOOST-INCLUDE} + ${CMAKE_CURRENT_SOURCE_DIR}/assets/ + . +) + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_DX11;" + ">" + "$<$:" + "NDEBUG" + ">" + "$<$:ENABLE_CROWD_CONTROL>" + "INCLUDE_GAME_PRINTF;" + "ENABLE_CROWD_CONTROL;" + "UNICODE;" + "_UNICODE" + STORMLIB_NO_AUTO_LINK + "_CRT_SECURE_NO_WARNINGS;" + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "NOINCLUDE_GAME_PRINTF;" + "_DEBUG;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_OPENGL" + ">" + "$<$:" + "NDEBUG;" + ">" + "INCLUDE_GAME_PRINTF;" + "NON_EQUIVALENT;" + "NON_MATCHING;" + "WIN32;" + "UNICODE;" + "_UNICODE" + STORMLIB_NO_AUTO_LINK + ) + endif() +elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG" + ">" + "$<$:" + "NDEBUG" + ">" + "SPDLOG_ACTIVE_LEVEL=3;" + "SPDLOG_NO_THREAD_ID;" + "SPDLOG_NO_TLS;" + "STBI_NO_THREAD_LOCALS;" + ) +elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG" + ">" + "$<$:" + "NDEBUG" + ">" + "$<$:ENABLE_CROWD_CONTROL>" + "SPDLOG_ACTIVE_LEVEL=0;" + "_CONSOLE;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_OPENGL;" + "UNICODE;" + "_UNICODE" + "NON_MATCHING;" + "NON_EQUIVALENT;" + ) +endif() +################################################################################ +# Compile and link options +################################################################################ +if(MSVC) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_compile_options(${PROJECT_NAME} PRIVATE + $<$: + /w; + /Od + > + $<$: + /Oi; + /Gy; + /W3 + > + /sdl-; + /permissive-; + /MP; + ${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT}; + ${DEFAULT_CXX_EXCEPTION_HANDLING} + ) + target_compile_options(${PROJECT_NAME} PRIVATE $<$:/ZI;>) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_compile_options(${PROJECT_NAME} PRIVATE + $<$: + /RTCs + /w + /Od + > + $<$: + /O2; + /Oi; + /Gy + > + /permissive-; + /MP; + /sdl-; + /w; + ${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT}; + ${DEFAULT_CXX_EXCEPTION_HANDLING} + ) + endif() + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_link_options(${PROJECT_NAME} PRIVATE + $<$: + /INCREMENTAL + > + $<$: + /OPT:REF; + /OPT:ICF; + /INCREMENTAL:NO; + /FORCE:MULTIPLE + > + /MANIFEST:NO; + /DEBUG; + /SUBSYSTEM:WINDOWS + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_link_options(${PROJECT_NAME} PRIVATE + $<$: + /STACK:8777216 + > + $<$: + /OPT:REF; + /OPT:ICF; + /INCREMENTAL:NO; + /FORCE:MULTIPLE + > + /MANIFEST:NO; + /DEBUG; + /SUBSYSTEM:WINDOWS + ) + endif() +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-return-type + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + #-Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$: + -Wno-c++11-narrowing + -Wno-deprecated-enum-enum-conversion + > + -pthread + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + ) + elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-return-type + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$: + -Wno-c++11-narrowing + -Wno-deprecated-enum-enum-conversion + > + -pthread + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + ) + elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + target_compile_options(${PROJECT_NAME} PRIVATE + -O2 + + # disable some warnings to not clutter output + -Wno-multichar + -Wno-return-type + -Wno-narrowing + -Wno-switch-outside-range + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + -Wno-discarded-array-qualifiers + -Wno-discarded-qualifiers + -Wno-int-conversion + -Wno-builtin-declaration-mismatch + -Wno-switch-unreachable + -Wno-stringop-overflow + > + ) + else() + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(CPU_OPTION -msse2 -mfpmath=sse) + endif() + + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + #-Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$:-Wno-deprecated-enum-enum-conversion> + -pthread + ${CPU_OPTION} + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + -Wl,-export-dynamic + ) + endif() +endif() +################################################################################ +# Pre build events +################################################################################ +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_custom_command_if( + TARGET ${PROJECT_NAME} + PRE_BUILD + COMMANDS + COMMAND $ copy /b $build.c +,, + ) +endif() + +if(NOT CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") + add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMENT "Copying asset xmls..." + #COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/mm/assets/extractor $/assets/extractor + #COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/mm/assets/xml $/assets/extractor/xmls + #COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/OTRExporter/CFG/filelists $/assets/extractor/filelists + #COMMAND ${CMAKE_COMMAND} -E make_directory $/assets/extractor/symbols + #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ActorList_MM.txt $/assets/extractor/symbols + #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/OTRExporter/CFG/ObjectList_MM.txt $/assets/extractor/symbols + #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/OTRExporter/CFG/SymbolMap_MM.txt $/assets/extractor/symbols + ) +endif() +################################################################################ +# Dependencies +################################################################################ +add_dependencies(${PROJECT_NAME} + ZAPDUtils + libultraship +) +if(NOT CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") +add_dependencies(${PROJECT_NAME} + ZAPDLib +) +endif() + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + find_package(glfw3 REQUIRED) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + "glu32;" + "SDL2::SDL2;" + "SDL2::SDL2main;" + "$<$:SDL2_net::SDL2_net-static>" + "glfw;" + "winmm;" + "imm32;" + "version;" + "setupapi" + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + "glu32;" + "SDL2::SDL2;" + "SDL2::SDL2main;" + "glfw;" + "winmm;" + "imm32;" + "version;" + "setupapi" + ) + endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + find_package(SDL2) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + SDL2::SDL2 + -lglad + Threads::Threads + ) +elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + find_package(SDL2 REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + SDL2::SDL2-static + + "$<$:-Wl,--wrap=abort>" + ) + target_include_directories(${PROJECT_NAME} PRIVATE + ${DEVKITPRO}/portlibs/wiiu/include/ + ) +else() + find_package(SDL2) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + set(ADDITIONAL_LIBRARY_DEPENDENCIES + "libultraship;" + "ZAPDUtils;" + "ZAPDLib;" + SDL2::SDL2 + "$<$:SDL2_net::SDL2_net>" + ${CMAKE_DL_LIBS} + Threads::Threads + ) +endif() + +if(NOT CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") +INSTALL(TARGETS mm DESTINATION . COMPONENT 2s2h) +endif() + +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") +INSTALL(FILES $ DESTINATION ./debug COMPONENT 2s2h) +INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/soh.otr DESTINATION . COMPONENT 2s2h) +endif() + +find_program(CURL NAMES curl DOC "Path to the curl program. Used to download files.") +execute_process(COMMAND ${CURL} -sSfL https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt -o ${CMAKE_BINARY_DIR}/gamecontrollerdb.txt OUTPUT_VARIABLE RESULT) + +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/macosx/Info.plist.in ${CMAKE_BINARY_DIR}/macosx/Info.plist @ONLY) +INSTALL(FILES ${CMAKE_BINARY_DIR}/gamecontrollerdb.txt DESTINATION ../MacOS COMPONENT 2s2h) +INSTALL(FILES ${CMAKE_BINARY_DIR}/mm/soh.otr DESTINATION ../Resources COMPONENT 2s2h) +elseif(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "NintendoSwitch|CafeOS") +INSTALL(FILES ${CMAKE_BINARY_DIR}/gamecontrollerdb.txt DESTINATION . COMPONENT 2s2h) +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch|CafeOS") + if (NOT TARGET pathconf) + add_library(pathconf OBJECT platform/pathconf.c) + endif() + target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}" $ ) +else() + target_link_libraries(${PROJECT_NAME} PRIVATE "${ADDITIONAL_LIBRARY_DEPENDENCIES}") +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "NintendoSwitch") + +nx_generate_nacp(2s2h.nacp + NAME "2s2h of Harkinian" + AUTHOR "${PROJECT_TEAM}" + VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" +) + +nx_create_nro(2s2h + NACP 2s2h.nacp + ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.jpg +) + +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/2s2h.nro DESTINATION . COMPONENT 2s2h) + +elseif(CMAKE_SYSTEM_NAME MATCHES "CafeOS") + +wut_create_rpx(${PROJECT_NAME}) + +wut_create_wuhb(${PROJECT_NAME} + NAME "Two Ship Two Harkinian" + SHORTNAME "2S2H" + AUTHOR "${PROJECT_TEAM}" + ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.jpg +) + +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/2s2h.rpx ${CMAKE_CURRENT_BINARY_DIR}/2s2h.wuhb DESTINATION . COMPONENT 2s2h) + +endif() diff --git a/mm/assets/xml/archives/icon_item_24_static.xml b/mm/assets/xml/archives/icon_item_24_static.xml index 2997b546b..6bf637534 100644 --- a/mm/assets/xml/archives/icon_item_24_static.xml +++ b/mm/assets/xml/archives/icon_item_24_static.xml @@ -1,5 +1,5 @@ - + diff --git a/mm/assets/xml/archives/icon_item_static.xml b/mm/assets/xml/archives/icon_item_static.xml index 3480d704a..52cf6a3a9 100644 --- a/mm/assets/xml/archives/icon_item_static.xml +++ b/mm/assets/xml/archives/icon_item_static.xml @@ -1,5 +1,5 @@ - + diff --git a/mm/assets/xml/archives/item_name_static.xml b/mm/assets/xml/archives/item_name_static.xml index da0b903a0..b9ff2a5ee 100644 --- a/mm/assets/xml/archives/item_name_static.xml +++ b/mm/assets/xml/archives/item_name_static.xml @@ -1,6 +1,6 @@ - + diff --git a/mm/assets/xml/archives/map_grand_static.xml b/mm/assets/xml/archives/map_grand_static.xml index 05e5893c1..94e51b350 100644 --- a/mm/assets/xml/archives/map_grand_static.xml +++ b/mm/assets/xml/archives/map_grand_static.xml @@ -1,102 +1,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mm/assets/xml/archives/map_i_static.xml b/mm/assets/xml/archives/map_i_static.xml index fce2cc437..15e1a4348 100644 --- a/mm/assets/xml/archives/map_i_static.xml +++ b/mm/assets/xml/archives/map_i_static.xml @@ -1,62 +1,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mm/assets/xml/archives/map_name_static.xml b/mm/assets/xml/archives/map_name_static.xml index fe392eb03..d672cdc39 100644 --- a/mm/assets/xml/archives/map_name_static.xml +++ b/mm/assets/xml/archives/map_name_static.xml @@ -1,6 +1,6 @@ - + diff --git a/mm/assets/xml/archives/schedule_dma_static.xml b/mm/assets/xml/archives/schedule_dma_static.xml index c71bdb413..42f75f6d9 100644 --- a/mm/assets/xml/archives/schedule_dma_static.xml +++ b/mm/assets/xml/archives/schedule_dma_static.xml @@ -1,5 +1,5 @@ - + diff --git a/mm/assets/xml/interface/icon_item_vtx_static.xml b/mm/assets/xml/interface/icon_item_vtx_static.xml index 37ccb0063..2c7bfe219 100644 --- a/mm/assets/xml/interface/icon_item_vtx_static.xml +++ b/mm/assets/xml/interface/icon_item_vtx_static.xml @@ -1,4 +1,5 @@ + diff --git a/mm/assets/xml/interface/parameter_static.xml b/mm/assets/xml/interface/parameter_static.xml index a2ab9e0c5..2cbcb8124 100644 --- a/mm/assets/xml/interface/parameter_static.xml +++ b/mm/assets/xml/interface/parameter_static.xml @@ -22,14 +22,14 @@ - + - + @@ -44,7 +44,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -74,10 +74,10 @@ - + - + @@ -114,7 +114,7 @@ - + diff --git a/mm/assets/xml/objects/gameplay_keep.xml b/mm/assets/xml/objects/gameplay_keep.xml index 785fa3e1d..cf35b95a8 100644 --- a/mm/assets/xml/objects/gameplay_keep.xml +++ b/mm/assets/xml/objects/gameplay_keep.xml @@ -1433,8 +1433,7 @@ - - + diff --git a/mm/assets/xml/text/message_data_static.xml b/mm/assets/xml/text/message_data_static.xml new file mode 100644 index 000000000..dfbb98c74 --- /dev/null +++ b/mm/assets/xml/text/message_data_static.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mm/build.c b/mm/build.c new file mode 100644 index 000000000..e69de29bb diff --git a/mm/include/PR/abi.h b/mm/include/PR/abi.h index 7d3113022..c53118347 100644 --- a/mm/include/PR/abi.h +++ b/mm/include/PR/abi.h @@ -1,6 +1,7 @@ #ifndef PR_ABI_H #define PR_ABI_H - +#include +#if 0 /* Audio commands: */ /* #define A_SPNOOP 0 @@ -21,30 +22,30 @@ #define A_SETLOOP 15 */ -#define A_SPNOOP 0 -#define A_ADPCM 1 -#define A_CLEARBUFF 2 -#define A_UNK3 3 -#define A_ADDMIXER 4 -#define A_RESAMPLE 5 -#define A_RESAMPLE_ZOH 6 -#define A_FILTER 7 -#define A_SETBUFF 8 -#define A_DUPLICATE 9 -#define A_DMEMMOVE 10 -#define A_LOADADPCM 11 -#define A_MIXER 12 -#define A_INTERLEAVE 13 -#define A_HILOGAIN 14 -#define A_SETLOOP 15 -#define A_INTERL 17 -#define A_ENVSETUP1 18 -#define A_ENVMIXER 19 -#define A_LOADBUFF 20 -#define A_SAVEBUFF 21 -#define A_ENVSETUP2 22 -#define A_S8DEC 23 -#define A_UNK19 25 +#define A_SPNOOP 0 +#define A_ADPCM 1 +#define A_CLEARBUFF 2 +#define A_UNK3 3 +#define A_ADDMIXER 4 +#define A_RESAMPLE 5 +#define A_RESAMPLE_ZOH 6 +#define A_FILTER 7 +#define A_SETBUFF 8 +#define A_DUPLICATE 9 +#define A_DMEMMOVE 10 +#define A_LOADADPCM 11 +#define A_MIXER 12 +#define A_INTERLEAVE 13 +#define A_HILOGAIN 14 +#define A_SETLOOP 15 +#define A_INTERL 17 +#define A_ENVSETUP1 18 +#define A_ENVMIXER 19 +#define A_LOADBUFF 20 +#define A_SAVEBUFF 21 +#define A_ENVSETUP2 22 +#define A_S8DEC 23 +#define A_UNK19 25 #define ACMD_SIZE 32 /* @@ -281,56 +282,53 @@ typedef short ENVMIX_STATE[40]; * Macros to assemble the audio command list */ -#define aADPCMdec(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (unsigned int)(s); \ -} +#define aADPCMdec(pkt, f, s) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (unsigned int)(s); \ + } -#define aPoleFilter(pkt, f, g, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} +#define aPoleFilter(pkt, f, g, s) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(g, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ + } -#define aHiLoGain(pkt, gain, count, dmem, a4) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_HILOGAIN, 24, 8) | \ - _SHIFTL(gain, 16, 8) | _SHIFTL(count, 0, 16)); \ - _a->words.w1 = _SHIFTL(dmem, 16, 16) | _SHIFTL(a4, 0, 16); \ -} +#define aHiLoGain(pkt, gain, count, dmem, a4) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_HILOGAIN, 24, 8) | _SHIFTL(gain, 16, 8) | _SHIFTL(count, 0, 16)); \ + _a->words.w1 = _SHIFTL(dmem, 16, 16) | _SHIFTL(a4, 0, 16); \ + } -#define aUnkCmd3(pkt, a1, a2, a3) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_UNK3, 24, 8) | _SHIFTL(a3, 0, 16); \ - _a->words.w1 = _SHIFTL(a1, 16, 16) | _SHIFTL(a2, 0, 16); \ -} +#define aUnkCmd3(pkt, a1, a2, a3) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_UNK3, 24, 8) | _SHIFTL(a3, 0, 16); \ + _a->words.w1 = _SHIFTL(a1, 16, 16) | _SHIFTL(a2, 0, 16); \ + } -#define aUnkCmd19(pkt, a1, a2, a3, a4) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_UNK19, 24, 8) | _SHIFTL(a1, 16, 8) | \ - _SHIFTL(a2, 0, 16)); \ - _a->words.w1 = _SHIFTL(a3, 16, 16) | _SHIFTL(a4, 0, 16); \ -} +#define aUnkCmd19(pkt, a1, a2, a3, a4) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_UNK19, 24, 8) | _SHIFTL(a1, 16, 8) | _SHIFTL(a2, 0, 16)); \ + _a->words.w1 = _SHIFTL(a3, 16, 16) | _SHIFTL(a4, 0, 16); \ + } -#define aS8Dec(pkt, a1, a2) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_S8DEC, 24, 8) | _SHIFTL(a1, 16, 8); \ - _a->words.w1 = (unsigned int)(a2); \ -} +#define aS8Dec(pkt, a1, a2) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_S8DEC, 24, 8) | _SHIFTL(a1, 16, 8); \ + _a->words.w1 = (unsigned int)(a2); \ + } /* * Clears DMEM by writing zeros. @@ -347,34 +345,30 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(size); \ } -#define aEnvMixer(pkt, dmemi, count, swapLR, x0, x1, x2, x3, m, bits) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (bits | _SHIFTL(dmemi >> 4, 16, 8) | \ - _SHIFTL(count, 8, 8) | _SHIFTL(swapLR, 4, 1) | \ - _SHIFTL(x0, 3, 1) | _SHIFTL(x1, 2, 1) | \ - _SHIFTL(x2, 1, 1) | _SHIFTL(x3, 0, 1)); \ - _a->words.w1 = (unsigned int)(m); \ -} +#define aEnvMixer(pkt, dmemi, count, swapLR, x0, x1, x2, x3, m, bits) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (bits | _SHIFTL(dmemi >> 4, 16, 8) | _SHIFTL(count, 8, 8) | _SHIFTL(swapLR, 4, 1) | \ + _SHIFTL(x0, 3, 1) | _SHIFTL(x1, 2, 1) | _SHIFTL(x2, 1, 1) | _SHIFTL(x3, 0, 1)); \ + _a->words.w1 = (unsigned int)(m); \ + } -#define aInterleave(pkt, o, l, r, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_INTERLEAVE, 24, 8) | \ - _SHIFTL(c >> 4, 16, 8) | _SHIFTL(o, 0, 16)); \ - _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ -} +#define aInterleave(pkt, o, l, r, c) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_INTERLEAVE, 24, 8) | _SHIFTL(c >> 4, 16, 8) | _SHIFTL(o, 0, 16)); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ + } -#define aInterl(pkt, dmemi, dmemo, count) \ -{ \ - Acmd *_a = (Acmd*)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_INTERL, 24, 8) | \ - _SHIFTL(count, 0, 16)); \ - _a->words.w1 = _SHIFTL(dmemi, 16, 16) | _SHIFTL(dmemo, 0, 16); \ -} +#define aInterl(pkt, dmemi, dmemo, count) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_INTERL, 24, 8) | _SHIFTL(count, 0, 16)); \ + _a->words.w1 = _SHIFTL(dmemi, 16, 16) | _SHIFTL(dmemo, 0, 16); \ + } /* * Loads a buffer to DMEM from any physical source address, KSEG0, or KSEG1 @@ -392,32 +386,29 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(addrSrc); \ } -#define aMix(pkt, f, g, i, o) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ -} +#define aMix(pkt, f, g, i, o) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ + } -#define aPan(pkt, f, d, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(d, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} +#define aPan(pkt, f, d, s) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(d, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ + } -#define aResample(pkt, f, p, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | \ - _SHIFTL(f, 16, 8) | _SHIFTL(p, 0, 16)); \ - _a->words.w1 = (unsigned int)(s); \ -} +#define aResample(pkt, f, p, s) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(p, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ + } /* * Stores a buffer from DMEM to any physical source address, KSEG0, or KSEG1 @@ -435,93 +426,85 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(addrDest); \ } -#define aSegment(pkt, s, b) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ - _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ -} +#define aSegment(pkt, s, b) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ + _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ + } -#define aSetBuffer(pkt, f, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(i, 0, 16)); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} +#define aSetBuffer(pkt, f, i, o, c) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(i, 0, 16)); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ + } -#define aSetVolume(pkt, f, v, t, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = _SHIFTL(r, 0, 16) | _SHIFTL(t, 16, 16); \ -} +#define aSetVolume(pkt, f, v, t, r) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | _SHIFTL(v, 0, 16)); \ + _a->words.w1 = _SHIFTL(r, 0, 16) | _SHIFTL(t, 16, 16); \ + } -#define aSetVolume32(pkt, f, v, tr) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = (unsigned int)(tr); \ -} +#define aSetVolume32(pkt, f, v, tr) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | _SHIFTL(v, 0, 16)); \ + _a->words.w1 = (unsigned int)(tr); \ + } -#define aSetLoop(pkt, a) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ - _a->words.w1 = (unsigned int)(a); \ -} +#define aSetLoop(pkt, a) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ + _a->words.w1 = (unsigned int)(a); \ + } -#define aDMEMMove(pkt, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} +#define aDMEMMove(pkt, i, o, c) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ + } #define aLoadADPCM(pkt, c, d) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ + { \ + Acmd* _a = (Acmd*)pkt; \ \ _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ _a->words.w1 = (unsigned int)d; \ -} + } +#define aEnvSetup1(pkt, a, b, c, d) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ENVSETUP1, 24, 8) | _SHIFTL(a, 16, 8) | _SHIFTL(b, 0, 16)); \ + _a->words.w1 = _SHIFTL(c, 16, 16) | _SHIFTL(d, 0, 16); \ + } +#define aEnvSetup2(pkt, volLeft, volRight) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); \ + _a->words.w1 = _SHIFTL(volLeft, 16, 16) | _SHIFTL(volRight, 0, 16); \ + } -#define aEnvSetup1(pkt, a, b, c, d) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_ENVSETUP1, 24, 8) | \ - _SHIFTL(a, 16, 8) | _SHIFTL(b, 0, 16)); \ - _a->words.w1 = _SHIFTL(c, 16, 16) | _SHIFTL(d, 0, 16); \ -} - -#define aEnvSetup2(pkt, volLeft, volRight) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); \ - _a->words.w1 = _SHIFTL(volLeft, 16, 16) | \ - _SHIFTL(volRight, 0, 16); \ -} - -#define aFilter(pkt, f, countOrBuf, addr) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_FILTER, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(countOrBuf, 0, 16); \ - _a->words.w1 = (unsigned int)(addr); \ -} +#define aFilter(pkt, f, countOrBuf, addr) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_FILTER, 24, 8) | _SHIFTL(f, 16, 8) | _SHIFTL(countOrBuf, 0, 16); \ + _a->words.w1 = (unsigned int)(addr); \ + } /* * Duplicates 128 bytes of data a specified number of times. @@ -539,22 +522,22 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = _SHIFTL(dmemDest, 16, 16) | _SHIFTL(0x80, 0, 16); \ } -#define aAddMixer(pkt, count, dmemi, dmemo, a4) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_ADDMIXER, 24, 8) | \ - _SHIFTL(count >> 4, 16, 8) | _SHIFTL(a4, 0, 16)); \ - _a->words.w1 = _SHIFTL(dmemi, 16, 16) | _SHIFTL(dmemo, 0, 16); \ -} +#define aAddMixer(pkt, count, dmemi, dmemo, a4) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_ADDMIXER, 24, 8) | _SHIFTL(count >> 4, 16, 8) | _SHIFTL(a4, 0, 16)); \ + _a->words.w1 = _SHIFTL(dmemi, 16, 16) | _SHIFTL(dmemo, 0, 16); \ + } -#define aResampleZoh(pkt, pitch, pitchAccu) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_RESAMPLE_ZOH, 24, 8) | \ - _SHIFTL(pitch, 0, 16)); \ - _a->words.w1 = _SHIFTL(pitchAccu, 0, 16); \ -} +#define aResampleZoh(pkt, pitch, pitchAccu) \ + { \ + Acmd* _a = (Acmd*)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE_ZOH, 24, 8) | _SHIFTL(pitch, 0, 16)); \ + _a->words.w1 = _SHIFTL(pitchAccu, 0, 16); \ + } #endif /* ULTRA64_ABI_H */ + +#endif diff --git a/mm/include/PR/controller.h b/mm/include/PR/controller.h index 367912452..50bea2088 100644 --- a/mm/include/PR/controller.h +++ b/mm/include/PR/controller.h @@ -1,6 +1,7 @@ #ifndef PR_CONTROLLER_H #define PR_CONTROLLER_H - +#include +#if 0 #include "ultratypes.h" #include "os_cont.h" #include "os_pfs.h" @@ -12,7 +13,7 @@ #define BLOCKSIZE 32 #define PFS_ONE_PAGE 8 -#define PFS_PAGE_SIZE (BLOCKSIZE*PFS_ONE_PAGE) +#define PFS_PAGE_SIZE (BLOCKSIZE * PFS_ONE_PAGE) #define CONT_CMD_REQUEST_STATUS 0 #define CONT_CMD_READ_BUTTON 1 @@ -38,57 +39,57 @@ #define CONT_CMD_WRITE_EEPROM_RX 1 #define CONT_CMD_RESET_RX 3 -#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ -#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ -#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ -#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ -#define CONT_ERR_NOT_READY 12 -#define CONT_ERR_VOICE_MEMORY 13 -#define CONT_ERR_VOICE_WORD 14 -#define CONT_ERR_VOICE_NO_RESPONSE 15 +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 // Joybus commands #define CONT_CMD_REQUEST_STATUS 0 -#define CONT_CMD_READ_BUTTON 1 -#define CONT_CMD_READ_PAK 2 -#define CONT_CMD_WRITE_PAK 3 -#define CONT_CMD_READ_EEPROM 4 -#define CONT_CMD_WRITE_EEPROM 5 -#define CONT_CMD_READ36_VOICE 9 -#define CONT_CMD_WRITE20_VOICE 10 -#define CONT_CMD_READ2_VOICE 11 -#define CONT_CMD_WRITE4_VOICE 12 -#define CONT_CMD_SWRITE_VOICE 13 -#define CONT_CMD_CHANNEL_RESET 0xFD -#define CONT_CMD_RESET 0xFF +#define CONT_CMD_READ_BUTTON 1 +#define CONT_CMD_READ_PAK 2 +#define CONT_CMD_WRITE_PAK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_READ36_VOICE 9 +#define CONT_CMD_WRITE20_VOICE 10 +#define CONT_CMD_READ2_VOICE 11 +#define CONT_CMD_WRITE4_VOICE 12 +#define CONT_CMD_SWRITE_VOICE 13 +#define CONT_CMD_CHANNEL_RESET 0xFD +#define CONT_CMD_RESET 0xFF // Bytes transmitted for each joybus command #define CONT_CMD_REQUEST_STATUS_TX 1 -#define CONT_CMD_READ_BUTTON_TX 1 -#define CONT_CMD_READ_PAK_TX 3 -#define CONT_CMD_WRITE_PAK_TX 35 -#define CONT_CMD_READ_EEPROM_TX 2 -#define CONT_CMD_WRITE_EEPROM_TX 10 -#define CONT_CMD_READ36_VOICE_TX 3 -#define CONT_CMD_WRITE20_VOICE_TX 23 -#define CONT_CMD_READ2_VOICE_TX 3 -#define CONT_CMD_WRITE4_VOICE_TX 7 -#define CONT_CMD_SWRITE_VOICE_TX 3 -#define CONT_CMD_RESET_TX 1 +#define CONT_CMD_READ_BUTTON_TX 1 +#define CONT_CMD_READ_PAK_TX 3 +#define CONT_CMD_WRITE_PAK_TX 35 +#define CONT_CMD_READ_EEPROM_TX 2 +#define CONT_CMD_WRITE_EEPROM_TX 10 +#define CONT_CMD_READ36_VOICE_TX 3 +#define CONT_CMD_WRITE20_VOICE_TX 23 +#define CONT_CMD_READ2_VOICE_TX 3 +#define CONT_CMD_WRITE4_VOICE_TX 7 +#define CONT_CMD_SWRITE_VOICE_TX 3 +#define CONT_CMD_RESET_TX 1 // Bytes received for each joybus command #define CONT_CMD_REQUEST_STATUS_RX 3 -#define CONT_CMD_READ_BUTTON_RX 4 -#define CONT_CMD_READ_PAK_RX 33 -#define CONT_CMD_WRITE_PAK_RX 1 -#define CONT_CMD_READ_EEPROM_RX 8 -#define CONT_CMD_WRITE_EEPROM_RX 1 -#define CONT_CMD_READ36_VOICE_RX 37 -#define CONT_CMD_WRITE20_VOICE_RX 1 -#define CONT_CMD_READ2_VOICE_RX 3 -#define CONT_CMD_WRITE4_VOICE_RX 1 -#define CONT_CMD_SWRITE_VOICE_RX 1 -#define CONT_CMD_RESET_RX 3 +#define CONT_CMD_READ_BUTTON_RX 4 +#define CONT_CMD_READ_PAK_RX 33 +#define CONT_CMD_WRITE_PAK_RX 1 +#define CONT_CMD_READ_EEPROM_RX 8 +#define CONT_CMD_WRITE_EEPROM_RX 1 +#define CONT_CMD_READ36_VOICE_RX 37 +#define CONT_CMD_WRITE20_VOICE_RX 1 +#define CONT_CMD_READ2_VOICE_RX 3 +#define CONT_CMD_WRITE4_VOICE_RX 1 +#define CONT_CMD_SWRITE_VOICE_RX 1 +#define CONT_CMD_RESET_RX 3 #define CONT_CMD_NOP 0xFF #define CONT_CMD_END 0xFE // Indicates end of a command @@ -106,23 +107,23 @@ #define PFS_ERR_NOPACK 1 // Accessory detection -#define CONT_ADDR_DETECT 0x8000 +#define CONT_ADDR_DETECT 0x8000 // Rumble -#define CONT_ADDR_RUMBLE 0xC000 +#define CONT_ADDR_RUMBLE 0xC000 // Controller Pak // Transfer Pak -#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different -#define CONT_ADDR_GB_BANK 0xA000 +#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different +#define CONT_ADDR_GB_BANK 0xA000 #define CONT_ADDR_GB_STATUS 0xB000 // Addresses sent to controller accessories are in blocks, not bytes #define CONT_BLOCKS(x) ((x) / BLOCKSIZE) // Block addresses of the above -#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT) -#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE) -#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER) -#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK) +#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT) +#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE) +#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER) +#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK) #define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS) @@ -142,6 +143,8 @@ typedef struct { /* 0x7 */ s8 stick_y; } __OSContReadFormat; + +// Original name: __OSContRequesFormat typedef struct { /* 0x00 */ u8 align; /* 0x01 */ u8 txsize; @@ -151,7 +154,7 @@ typedef struct { /* 0x05 */ u8 typel; /* 0x06 */ u8 status; /* 0x07 */ u8 align1; -} __OSContRequesFormat; // size = 0x8 +} __OSContRequestHeader; // size = 0x8 typedef struct { /* 0x00 */ u8 txsize; @@ -203,5 +206,5 @@ extern u8 __osMaxControllers; extern OSMesgQueue __osEepromTimerQ; extern OSMesg __osEepromTimerMsg[]; extern OSPifRam __osPfsPifRam; - +#endif #endif diff --git a/mm/include/PR/gbi.h b/mm/include/PR/gbi.h index c6fcdc1e2..262ac95e8 100644 --- a/mm/include/PR/gbi.h +++ b/mm/include/PR/gbi.h @@ -1,129 +1,212 @@ #include "mbi.h" +#include +#if 0 +#ifndef ULTRA64_GBI_H +#define ULTRA64_GBI_H +#include + +#ifdef _MSC_VER +#ifndef u8 +#define u8 uint8_t +#endif + +#ifndef u16 +#define u16 uint16_t +#endif + +#ifndef u32 +#define u32 uint32_t +#endif + +#ifndef u64 +#define u64 uint64_t +#endif + +#ifndef s8 +#define s8 int8_t +#endif + +#ifndef s16 +#define s16 int16_t +#endif + +#ifndef s32 +#define s32 int32_t +#endif + +#ifndef s64 +#define s64 int64_t +#endif +#endif + +#define qs1616(e) ((s32)((e)*0x00010000)) + +#define IPART(x) ((qs1616(x) >> 16) & 0xFFFF) +#define FPART(x) (qs1616(x) & 0xFFFF) + +#define gdSPDefMtx(xx, yx, zx, wx, xy, yy, zy, wy, xz, yz, zz, wz, xw, yw, zw, ww) \ + { \ + { \ + (IPART(xx) << 0x10) | IPART(xy), (IPART(xz) << 0x10) | IPART(xw), (IPART(yx) << 0x10) | IPART(yy), \ + (IPART(yz) << 0x10) | IPART(yw), (IPART(zx) << 0x10) | IPART(zy), (IPART(zz) << 0x10) | IPART(zw), \ + (IPART(wx) << 0x10) | IPART(wy), (IPART(wz) << 0x10) | IPART(ww), (FPART(xx) << 0x10) | FPART(xy), \ + (FPART(xz) << 0x10) | FPART(xw), (FPART(yx) << 0x10) | FPART(yy), (FPART(yz) << 0x10) | FPART(yw), \ + (FPART(zx) << 0x10) | FPART(zy), (FPART(zz) << 0x10) | FPART(zw), (FPART(wx) << 0x10) | FPART(wy), \ + (FPART(wz) << 0x10) | FPART(ww), \ + } \ + } -#ifndef PR_GBI_H -#define PR_GBI_H -#include "ultratypes.h" /* To enable Fast3DEX grucode support, define F3DEX_GBI. */ /* Types */ /* Private macro to wrap other macros in do {...} while (0) */ -#define _DW(macro) do {macro} while (0) + +#define _DW(macro) \ + do { \ + macro \ + } while (0) #define F3DEX_GBI_2 -#ifdef F3DEX_GBI_2 -# ifndef F3DEX_GBI -# define F3DEX_GBI -# endif -#define G_NOOP 0x00 -#define G_RDPHALF_2 0xF1 -#define G_SETOTHERMODE_H 0xE3 -#define G_SETOTHERMODE_L 0xE2 -#define G_RDPHALF_1 0xE1 -#define G_SPNOOP 0xE0 -#define G_ENDDL 0xDF -#define G_DL 0xDE -#define G_LOAD_UCODE 0xDD -#define G_MOVEMEM 0xDC -#define G_MOVEWORD 0xDB -#define G_MTX 0xDA -#define G_GEOMETRYMODE 0xD9 -#define G_POPMTX 0xD8 -#define G_TEXTURE 0xD7 -#define G_DMA_IO 0xD6 -#define G_SPECIAL_1 0xD5 -#define G_SPECIAL_2 0xD4 -#define G_SPECIAL_3 0xD3 +#ifdef F3DEX_GBI_2 +#ifndef F3DEX_GBI +#define F3DEX_GBI +#endif +#define G_NOOP 0x00 +#define G_RDPHALF_2 0xf1 +#define G_SETOTHERMODE_H 0xe3 +#define G_SETOTHERMODE_L 0xe2 +#define G_RDPHALF_1 0xe1 +#define G_SPNOOP 0xe0 +#define G_ENDDL 0xdf +#define G_DL 0xde +#define G_LOAD_UCODE 0xdd +#define G_MOVEMEM 0xdc +#define G_MOVEWORD 0xdb +#define G_MTX 0xda +#define G_GEOMETRYMODE 0xd9 +#define G_POPMTX 0xd8 +#define G_TEXTURE 0xd7 +#define G_DMA_IO 0xd6 +#define G_SPECIAL_1 0xd5 +#define G_SPECIAL_2 0xd4 +#define G_SPECIAL_3 0xd3 -#define G_VTX 0x01 -#define G_MODIFYVTX 0x02 -#define G_CULLDL 0x03 -#define G_BRANCH_Z 0x04 -#define G_TRI1 0x05 -#define G_TRI2 0x06 -#define G_QUAD 0x07 -#define G_LINE3D 0x08 -#else /* F3DEX_GBI_2 */ +#define G_VTX 0x01 +#define G_MODIFYVTX 0x02 +#define G_CULLDL 0x03 +#define G_BRANCH_Z 0x04 +#define G_TRI1 0x05 +#define G_TRI2 0x06 +#define G_QUAD 0x07 +#define G_LINE3D 0x08 +#else /* F3DEX_GBI_2 */ /* DMA commands: */ -#define G_SPNOOP 0 /* handle 0 gracefully */ -#define G_MTX 1 -#define G_RESERVED0 2 /* not implemeted */ -#define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ -#define G_VTX 4 -#define G_RESERVED1 5 /* not implemeted */ -#define G_DL 6 -#define G_RESERVED2 7 /* not implemeted */ -#define G_RESERVED3 8 /* not implemeted */ -#define G_SPRITE2D_BASE 9 /* sprite command */ +#define G_SPNOOP 0 /* handle 0 gracefully */ +#define G_MTX 1 +#define G_RESERVED0 2 /* not implemeted */ +#define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ +#define G_VTX 4 +#define G_RESERVED1 5 /* not implemeted */ +#define G_DL 6 +#define G_RESERVED2 7 /* not implemeted */ +#define G_RESERVED3 8 /* not implemeted */ +#define G_SPRITE2D_BASE 9 /* sprite command */ /* IMMEDIATE commands: */ -#define G_IMMFIRST -65 -#define G_TRI1 (G_IMMFIRST-0) -#define G_CULLDL (G_IMMFIRST-1) -#define G_POPMTX (G_IMMFIRST-2) -#define G_MOVEWORD (G_IMMFIRST-3) -#define G_TEXTURE (G_IMMFIRST-4) -#define G_SETOTHERMODE_H (G_IMMFIRST-5) -#define G_SETOTHERMODE_L (G_IMMFIRST-6) -#define G_ENDDL (G_IMMFIRST-7) -#define G_SETGEOMETRYMODE (G_IMMFIRST-8) -#define G_CLEARGEOMETRYMODE (G_IMMFIRST-9) -#define G_LINE3D (G_IMMFIRST-10) -#define G_RDPHALF_1 (G_IMMFIRST-11) -#define G_RDPHALF_2 (G_IMMFIRST-12) -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_MODIFYVTX (G_IMMFIRST-13) -# define G_TRI2 (G_IMMFIRST-14) -# define G_BRANCH_Z (G_IMMFIRST-15) -# define G_LOAD_UCODE (G_IMMFIRST-16) +#define G_IMMFIRST -65 +#define G_TRI1 (G_IMMFIRST - 0) +#define G_CULLDL (G_IMMFIRST - 1) +#define G_POPMTX (G_IMMFIRST - 2) +#define G_MOVEWORD (G_IMMFIRST - 3) +#define G_TEXTURE (G_IMMFIRST - 4) +#define G_SETOTHERMODE_H (G_IMMFIRST - 5) +#define G_SETOTHERMODE_L (G_IMMFIRST - 6) +#define G_ENDDL (G_IMMFIRST - 7) +#define G_SETGEOMETRYMODE (G_IMMFIRST - 8) +#define G_CLEARGEOMETRYMODE (G_IMMFIRST - 9) +#define G_LINE3D (G_IMMFIRST - 10) +#define G_RDPHALF_1 (G_IMMFIRST - 11) +#define G_RDPHALF_2 (G_IMMFIRST - 12) +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) +#define G_MODIFYVTX (G_IMMFIRST - 13) +#define G_TRI2 (G_IMMFIRST - 14) +#define G_BRANCH_Z (G_IMMFIRST - 15) +#define G_LOAD_UCODE (G_IMMFIRST - 16) #else -# define G_RDPHALF_CONT (G_IMMFIRST-13) +#define G_RDPHALF_CONT (G_IMMFIRST - 13) #endif /* We are overloading 2 of the immediate commands to keep the byte alignment of dmem the same */ -#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST-1) -#define G_SPRITE2D_DRAW (G_IMMFIRST-2) +#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST - 1) +#define G_SPRITE2D_DRAW (G_IMMFIRST - 2) /* RDP commands: */ -#define G_NOOP 0xC0 /* 0 */ +#define G_NOOP 0xc0 /* 0 */ -#endif /* F3DEX_GBI_2 */ +#endif /* F3DEX_GBI_2 */ /* RDP commands: */ -#define G_SETCIMG 0xFF /* -1 */ -#define G_SETZIMG 0xFE /* -2 */ -#define G_SETTIMG 0xFD /* -3 */ -#define G_SETCOMBINE 0xFC /* -4 */ -#define G_SETENVCOLOR 0xFB /* -5 */ -#define G_SETPRIMCOLOR 0xFA /* -6 */ -#define G_SETBLENDCOLOR 0xF9 /* -7 */ -#define G_SETFOGCOLOR 0xF8 /* -8 */ -#define G_SETFILLCOLOR 0xF7 /* -9 */ -#define G_FILLRECT 0xF6 /* -10 */ -#define G_SETTILE 0xF5 /* -11 */ -#define G_LOADTILE 0xF4 /* -12 */ -#define G_LOADBLOCK 0xF3 /* -13 */ -#define G_SETTILESIZE 0xF2 /* -14 */ -#define G_LOADTLUT 0xF0 /* -16 */ -#define G_RDPSETOTHERMODE 0xEF /* -17 */ -#define G_SETPRIMDEPTH 0xEE /* -18 */ -#define G_SETSCISSOR 0xED /* -19 */ -#define G_SETCONVERT 0xEC /* -20 */ -#define G_SETKEYR 0xEB /* -21 */ -#define G_SETKEYGB 0xEA /* -22 */ -#define G_RDPFULLSYNC 0xE9 /* -23 */ -#define G_RDPTILESYNC 0xE8 /* -24 */ -#define G_RDPPIPESYNC 0xE7 /* -25 */ -#define G_RDPLOADSYNC 0xE6 /* -26 */ -#define G_TEXRECTFLIP 0xE5 /* -27 */ -#define G_TEXRECT 0xE4 /* -28 */ +#define G_SETCIMG 0xff /* -1 */ +#define G_SETZIMG 0xfe /* -2 */ +#define G_SETTIMG 0xfd /* -3 */ +#define G_SETCOMBINE 0xfc /* -4 */ +#define G_SETENVCOLOR 0xfb /* -5 */ +#define G_SETPRIMCOLOR 0xfa /* -6 */ +#define G_SETBLENDCOLOR 0xf9 /* -7 */ +#define G_SETFOGCOLOR 0xf8 /* -8 */ +#define G_SETFILLCOLOR 0xf7 /* -9 */ +#define G_FILLRECT 0xf6 /* -10 */ +#define G_SETTILE 0xf5 /* -11 */ +#define G_LOADTILE 0xf4 /* -12 */ +#define G_LOADBLOCK 0xf3 /* -13 */ +#define G_SETTILESIZE 0xf2 /* -14 */ +#define G_LOADTLUT 0xf0 /* -16 */ +#define G_RDPSETOTHERMODE 0xef /* -17 */ +#define G_SETPRIMDEPTH 0xee /* -18 */ +#define G_SETSCISSOR 0xed /* -19 */ +#define G_SETCONVERT 0xec /* -20 */ +#define G_SETKEYR 0xeb /* -21 */ +#define G_SETKEYGB 0xea /* -22 */ +#define G_RDPFULLSYNC 0xe9 /* -23 */ +#define G_RDPTILESYNC 0xe8 /* -24 */ +#define G_RDPPIPESYNC 0xe7 /* -25 */ +#define G_RDPLOADSYNC 0xe6 /* -26 */ +#define G_TEXRECTFLIP 0xe5 /* -27 */ +#define G_TEXRECT 0xe4 /* -28 */ +// CUSTOM OTR COMMANDS +#define G_SETTIMG_OTR_HASH 0x20 +#define G_SETFB 0x21 +#define G_RESETFB 0x22 +#define G_SETTIMG_FB 0x23 +#define G_VTX_OTR_FILEPATH 0x24 +#define G_SETTIMG_OTR_FILEPATH 0x25 +#define G_TRI1_OTR 0x26 +#define G_DL_OTR_FILEPATH 0x27 +#define G_PUSHCD 0x28 +#define G_MTX_OTR2 0x29 +#define G_DL_OTR_HASH 0x31 +#define G_VTX_OTR_HASH 0x32 +#define G_MARKER 0x33 +#define G_INVALTEXCACHE 0x34 +#define G_BRANCH_Z_OTR 0x35 +#define G_MTX_OTR 0x36 +#define G_TEXRECT_WIDE 0x37 +#define G_FILLWIDERECT 0x38 + +/* GFX Effects */ + +// RDP Cmd +#define G_SETGRAYSCALE 0x39 +#define G_EXTRAGEOMETRYMODE 0x3a +#define G_SETINTENSITY 0x40 /* * The following commands are the "generated" RDP commands; the user @@ -133,14 +216,14 @@ * These id's are -56, -52, -54, -50, -55, -51, -53, -49, ... * edge, shade, texture, zbuff bits: estz */ -#define G_TRI_FILL 0xC8 /* fill triangle: 11001000 */ -#define G_TRI_SHADE 0xCC /* shade triangle: 11001100 */ -#define G_TRI_TXTR 0xCA /* texture triangle: 11001010 */ -#define G_TRI_SHADE_TXTR 0xCE /* shade, texture triangle: 11001110 */ -#define G_TRI_FILL_ZBUFF 0xC9 /* fill, zbuff triangle: 11001001 */ -#define G_TRI_SHADE_ZBUFF 0xCD /* shade, zbuff triangle: 11001101 */ -#define G_TRI_TXTR_ZBUFF 0xCB /* texture, zbuff triangle: 11001011 */ -#define G_TRI_SHADE_TXTR_ZBUFF 0xCF /* shade, txtr, zbuff trngl: 11001111 */ +#define G_TRI_FILL 0xc8 /* fill triangle: 11001000 */ +#define G_TRI_SHADE 0xcc /* shade triangle: 11001100 */ +#define G_TRI_TXTR 0xca /* texture triangle: 11001010 */ +#define G_TRI_SHADE_TXTR 0xce /* shade, texture triangle: 11001110 */ +#define G_TRI_FILL_ZBUFF 0xc9 /* fill, zbuff triangle: 11001001 */ +#define G_TRI_SHADE_ZBUFF 0xcd /* shade, zbuff triangle: 11001101 */ +#define G_TRI_TXTR_ZBUFF 0xcb /* texture, zbuff triangle: 11001011 */ +#define G_TRI_SHADE_TXTR_ZBUFF 0xcf /* shade, txtr, zbuff trngl: 11001111 */ /* * A TRI_FILL triangle is just the edges. You need to set the DP @@ -156,10 +239,10 @@ */ /* masks to build RDP triangle commands: */ -#define G_RDP_TRI_FILL_MASK 0x08 -#define G_RDP_TRI_SHADE_MASK 0x04 -#define G_RDP_TRI_TXTR_MASK 0x02 -#define G_RDP_TRI_ZBUFF_MASK 0x01 +#define G_RDP_TRI_FILL_MASK 0x08 +#define G_RDP_TRI_SHADE_MASK 0x04 +#define G_RDP_TRI_TXTR_MASK 0x02 +#define G_RDP_TRI_ZBUFF_MASK 0x01 /* * HACK: @@ -174,31 +257,30 @@ * * THIS WILL BE REMOVED FOR HARDWARE VERSION 2.0! */ -#define BOWTIE_VAL 0 - +#define BOWTIE_VAL 0 /* gets added to RDP command, in order to test for addres fixup: */ -#define G_RDP_ADDR_FIXUP 3 /* |RDP cmds| <= this, do addr fixup */ +#define G_RDP_ADDR_FIXUP 3 /* |RDP cmds| <= this, do addr fixup */ #ifdef _LANGUAGE_ASSEMBLY -#define G_RDP_TEXRECT_CHECK ((-1*G_TEXRECTFLIP)& 0xFF) +#define G_RDP_TEXRECT_CHECK ((-1 * G_TEXRECTFLIP) & 0xff) #endif /* macros for command parsing: */ -#define GDMACMD(x) (x) -#define GIMMCMD(x) (G_IMMFIRST-(x)) -#define GRDPCMD(x) (0xFF-(x)) +#define GDMACMD(x) (x) +#define GIMMCMD(x) (G_IMMFIRST - (x)) +#define GRDPCMD(x) (0xff - (x)) -#define G_DMACMDSIZ 128 -#define G_IMMCMDSIZ 64 -#define G_RDPCMDSIZ 64 +#define G_DMACMDSIZ 128 +#define G_IMMCMDSIZ 64 +#define G_RDPCMDSIZ 64 /* * Coordinate shift values, number of bits of fraction */ -#define G_TEXTURE_IMAGE_FRAC 2 -#define G_TEXTURE_SCALE_FRAC 16 -#define G_SCALE_FRAC 8 -#define G_ROTATE_FRAC 16 +#define G_TEXTURE_IMAGE_FRAC 2 +#define G_TEXTURE_SCALE_FRAC 16 +#define G_SCALE_FRAC 8 +#define G_ROTATE_FRAC 16 /* * Parameters to graphics commands @@ -213,32 +295,33 @@ * Note : this number is NOT the viewport z-scale constant. * See the comment next to G_MAXZ for more info. */ -#define G_MAXFBZ 0x3FFF /* 3b exp, 11b mantissa */ +#define G_MAXFBZ 0x3fff /* 3b exp, 11b mantissa */ + +#define GPACK_RGBA5551(r, g, b, a) ((((r) << 8) & 0xf800) | (((g) << 3) & 0x7c0) | (((b) >> 2) & 0x3e) | ((a)&0x1)) +#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz)) + +#define G_MAXFBZ 0x3FFF /* 3b exp, 11b mantissa */ -#define GPACK_RGBA5551(r, g, b, a) ((((r)<<8) & 0xF800) | \ - (((g)<<3) & 0x7C0) | \ - (((b)>>2) & 0x3E) | ((a) & 0x1)) #define GPACK_IA16(i, a) (((i) << 8) | (a)) -#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz)) /* * G_MTX: parameter flags */ -#ifdef F3DEX_GBI_2 -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x04 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x01 -#else /* F3DEX_GBI_2 */ -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x01 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x04 -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define G_MTX_MODELVIEW 0x00 /* matrix types */ +#define G_MTX_PROJECTION 0x04 +#define G_MTX_MUL 0x00 /* concat or load */ +#define G_MTX_LOAD 0x02 +#define G_MTX_NOPUSH 0x00 /* push or not */ +#define G_MTX_PUSH 0x01 +#else /* F3DEX_GBI_2 */ +#define G_MTX_MODELVIEW 0x00 /* matrix types */ +#define G_MTX_PROJECTION 0x01 +#define G_MTX_MUL 0x00 /* concat or load */ +#define G_MTX_LOAD 0x02 +#define G_MTX_NOPUSH 0x00 /* push or not */ +#define G_MTX_PUSH 0x04 +#endif /* F3DEX_GBI_2 */ /* * flags for G_SETGEOMETRYMODE @@ -265,104 +348,109 @@ * See the man page for gSP1Triangle(). * */ -#define G_ZBUFFER 0x00000001 -#define G_SHADE 0x00000004 /* enable Gouraud interp */ -/* rest of low byte reserved for setup ucode */ -#ifdef F3DEX_GBI_2 -# define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ -# define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ -# define G_CULL_FRONT 0x00000200 -# define G_CULL_BACK 0x00000400 -# define G_CULL_BOTH 0x00000600 /* To make code cleaner */ +#define G_ZBUFFER 0x00000001 +#define G_SHADE 0x00000004 /* enable Gouraud interp */ + /* rest of low byte reserved for setup ucode */ +#ifdef F3DEX_GBI_2 +#define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ +#define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ +#define G_CULL_FRONT 0x00000200 +#define G_CULL_BACK 0x00000400 +#define G_CULL_BOTH 0x00000600 /* To make code cleaner */ #else -# define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ -# define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ -# define G_CULL_FRONT 0x00001000 -# define G_CULL_BACK 0x00002000 -# define G_CULL_BOTH 0x00003000 /* To make code cleaner */ +#define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ +#define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ +#define G_CULL_FRONT 0x00001000 +#define G_CULL_BACK 0x00002000 +#define G_CULL_BOTH 0x00003000 /* To make code cleaner */ #endif -#define G_FOG 0x00010000 -#define G_LIGHTING 0x00020000 -#define G_TEXTURE_GEN 0x00040000 -#define G_TEXTURE_GEN_LINEAR 0x00080000 -#define G_LOD 0x00100000 /* NOT IMPLEMENTED */ -#define G_LIGHTING_POSITIONAL 0x00400000 -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_CLIPPING 0x00800000 +#define G_FOG 0x00010000 +#define G_LIGHTING 0x00020000 +#define G_TEXTURE_GEN 0x00040000 +#define G_TEXTURE_GEN_LINEAR 0x00080000 +#define G_LOD 0x00100000 /* NOT IMPLEMENTED */ +#define G_LIGHTING_POSITIONAL 0x00400000 +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) +#define G_CLIPPING 0x00800000 #else -# define G_CLIPPING 0x00000000 +#define G_CLIPPING 0x00000000 #endif #ifdef _LANGUAGE_ASSEMBLY -#define G_FOG_H (G_FOG/0x10000) -#define G_LIGHTING_H (G_LIGHTING/0x10000) -#define G_TEXTURE_GEN_H (G_TEXTURE_GEN/0x10000) -#define G_TEXTURE_GEN_LINEAR_H (G_TEXTURE_GEN_LINEAR/0x10000) -#define G_LOD_H (G_LOD/0x10000) /* NOT IMPLEMENTED */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define G_CLIPPING_H (G_CLIPPING/0x10000) +#define G_FOG_H (G_FOG / 0x10000) +#define G_LIGHTING_H (G_LIGHTING / 0x10000) +#define G_TEXTURE_GEN_H (G_TEXTURE_GEN / 0x10000) +#define G_TEXTURE_GEN_LINEAR_H (G_TEXTURE_GEN_LINEAR / 0x10000) +#define G_LOD_H (G_LOD / 0x10000) /* NOT IMPLEMENTED */ +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) +#define G_CLIPPING_H (G_CLIPPING / 0x10000) #endif #endif +/* + * G_EXTRAGEOMETRY flags: set extra custom geometry modes + */ +#define G_EX_INVERT_CULLING 0x00000001 + /* Need these defined for Sprite Microcode */ #ifdef _LANGUAGE_ASSEMBLY -#define G_TX_LOADTILE 7 -#define G_TX_RENDERTILE 0 +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 -#define G_TX_NOMIRROR 0 -#define G_TX_WRAP 0 -#define G_TX_MIRROR 0x1 -#define G_TX_CLAMP 0x2 -#define G_TX_NOMASK 0 -#define G_TX_NOLOD 0 +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 #endif /* * G_SETIMG fmt: set image formats */ -#define G_IM_FMT_RGBA 0 -#define G_IM_FMT_YUV 1 -#define G_IM_FMT_CI 2 -#define G_IM_FMT_IA 3 -#define G_IM_FMT_I 4 +#define G_IM_FMT_RGBA 0 +#define G_IM_FMT_YUV 1 +#define G_IM_FMT_CI 2 +#define G_IM_FMT_IA 3 +#define G_IM_FMT_I 4 /* * G_SETIMG siz: set image pixel size */ -#define G_IM_SIZ_4b 0 -#define G_IM_SIZ_8b 1 -#define G_IM_SIZ_16b 2 -#define G_IM_SIZ_32b 3 -#define G_IM_SIZ_DD 5 +#define G_IM_SIZ_4b 0 +#define G_IM_SIZ_8b 1 +#define G_IM_SIZ_16b 2 +#define G_IM_SIZ_32b 3 +#define G_IM_SIZ_DD 5 -#define G_IM_SIZ_4b_BYTES 0 -#define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES -#define G_IM_SIZ_4b_LINE_BYTES G_IM_SIZ_4b_BYTES +#define G_IM_SIZ_4b_BYTES 0 +#define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES +#define G_IM_SIZ_4b_LINE_BYTES G_IM_SIZ_4b_BYTES -#define G_IM_SIZ_8b_BYTES 1 -#define G_IM_SIZ_8b_TILE_BYTES G_IM_SIZ_8b_BYTES -#define G_IM_SIZ_8b_LINE_BYTES G_IM_SIZ_8b_BYTES +#define G_IM_SIZ_8b_BYTES 1 +#define G_IM_SIZ_8b_TILE_BYTES G_IM_SIZ_8b_BYTES +#define G_IM_SIZ_8b_LINE_BYTES G_IM_SIZ_8b_BYTES -#define G_IM_SIZ_16b_BYTES 2 -#define G_IM_SIZ_16b_TILE_BYTES G_IM_SIZ_16b_BYTES -#define G_IM_SIZ_16b_LINE_BYTES G_IM_SIZ_16b_BYTES +#define G_IM_SIZ_16b_BYTES 2 +#define G_IM_SIZ_16b_TILE_BYTES G_IM_SIZ_16b_BYTES +#define G_IM_SIZ_16b_LINE_BYTES G_IM_SIZ_16b_BYTES -#define G_IM_SIZ_32b_BYTES 4 -#define G_IM_SIZ_32b_TILE_BYTES 2 -#define G_IM_SIZ_32b_LINE_BYTES 2 +#define G_IM_SIZ_32b_BYTES 4 +#define G_IM_SIZ_32b_TILE_BYTES 2 +#define G_IM_SIZ_32b_LINE_BYTES 2 -#define G_IM_SIZ_4b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_8b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_16b_LOAD_BLOCK G_IM_SIZ_16b -#define G_IM_SIZ_32b_LOAD_BLOCK G_IM_SIZ_32b +#define G_IM_SIZ_4b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_8b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_16b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_32b_LOAD_BLOCK G_IM_SIZ_32b -#define G_IM_SIZ_4b_SHIFT 2 -#define G_IM_SIZ_8b_SHIFT 1 +#define G_IM_SIZ_4b_SHIFT 2 +#define G_IM_SIZ_8b_SHIFT 1 #define G_IM_SIZ_16b_SHIFT 0 #define G_IM_SIZ_32b_SHIFT 0 -#define G_IM_SIZ_4b_INCR 3 -#define G_IM_SIZ_8b_INCR 1 +#define G_IM_SIZ_4b_INCR 3 +#define G_IM_SIZ_8b_INCR 1 #define G_IM_SIZ_16b_INCR 0 #define G_IM_SIZ_32b_INCR 0 @@ -370,590 +458,534 @@ * G_SETCOMBINE: color combine modes */ /* Color combiner constants: */ -#define G_CCMUX_COMBINED 0 -#define G_CCMUX_TEXEL0 1 -#define G_CCMUX_TEXEL1 2 -#define G_CCMUX_PRIMITIVE 3 -#define G_CCMUX_SHADE 4 -#define G_CCMUX_ENVIRONMENT 5 -#define G_CCMUX_CENTER 6 -#define G_CCMUX_SCALE 6 -#define G_CCMUX_COMBINED_ALPHA 7 -#define G_CCMUX_TEXEL0_ALPHA 8 -#define G_CCMUX_TEXEL1_ALPHA 9 -#define G_CCMUX_PRIMITIVE_ALPHA 10 -#define G_CCMUX_SHADE_ALPHA 11 -#define G_CCMUX_ENV_ALPHA 12 -#define G_CCMUX_LOD_FRACTION 13 -#define G_CCMUX_PRIM_LOD_FRAC 14 -#define G_CCMUX_NOISE 7 -#define G_CCMUX_K4 7 -#define G_CCMUX_K5 15 -#define G_CCMUX_1 6 -#define G_CCMUX_0 31 +#define G_CCMUX_COMBINED 0 +#define G_CCMUX_TEXEL0 1 +#define G_CCMUX_TEXEL1 2 +#define G_CCMUX_PRIMITIVE 3 +#define G_CCMUX_SHADE 4 +#define G_CCMUX_ENVIRONMENT 5 +#define G_CCMUX_CENTER 6 +#define G_CCMUX_SCALE 6 +#define G_CCMUX_COMBINED_ALPHA 7 +#define G_CCMUX_TEXEL0_ALPHA 8 +#define G_CCMUX_TEXEL1_ALPHA 9 +#define G_CCMUX_PRIMITIVE_ALPHA 10 +#define G_CCMUX_SHADE_ALPHA 11 +#define G_CCMUX_ENV_ALPHA 12 +#define G_CCMUX_LOD_FRACTION 13 +#define G_CCMUX_PRIM_LOD_FRAC 14 +#define G_CCMUX_NOISE 7 +#define G_CCMUX_K4 7 +#define G_CCMUX_K5 15 +#define G_CCMUX_1 6 +#define G_CCMUX_0 31 /* Alpha combiner constants: */ -#define G_ACMUX_COMBINED 0 -#define G_ACMUX_TEXEL0 1 -#define G_ACMUX_TEXEL1 2 -#define G_ACMUX_PRIMITIVE 3 -#define G_ACMUX_SHADE 4 -#define G_ACMUX_ENVIRONMENT 5 -#define G_ACMUX_LOD_FRACTION 0 -#define G_ACMUX_PRIM_LOD_FRAC 6 -#define G_ACMUX_1 6 -#define G_ACMUX_0 7 +#define G_ACMUX_COMBINED 0 +#define G_ACMUX_TEXEL0 1 +#define G_ACMUX_TEXEL1 2 +#define G_ACMUX_PRIMITIVE 3 +#define G_ACMUX_SHADE 4 +#define G_ACMUX_ENVIRONMENT 5 +#define G_ACMUX_LOD_FRACTION 0 +#define G_ACMUX_PRIM_LOD_FRAC 6 +#define G_ACMUX_1 6 +#define G_ACMUX_0 7 /* typical CC cycle 1 modes */ -#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE -#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE -#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 -#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 -#define G_CC_MODULATERGB G_CC_MODULATEI -#define G_CC_MODULATERGBA G_CC_MODULATEIA -#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA -#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 -#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 -#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM -#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM -#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM -#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE -#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 -#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_ADDRGB 1, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_ADDRGBDECALA 1, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE -#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 +#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE +#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE +#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 +#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB G_CC_MODULATEI +#define G_CC_MODULATERGBA G_CC_MODULATEIA +#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA +#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 +#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM +#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM +#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM +#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE +#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 +#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_ADDRGB 1, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_ADDRGBDECALA 1, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE +#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 /* oddball modes */ -#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 -#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 -#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 +#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 +#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE /* used for 1-cycle sparse mip-maps, primitive color has color of lowest LOD */ -#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 +#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 /* typical CC cycle 1 modes, usually followed by other cycle 2 modes */ -#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 +#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 /* * One-cycle color convert operation */ -#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE +#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE /* * NOTE: YUV2RGB expects TF step1 color conversion to occur in 2nd clock. * Therefore, CC looks for step1 results in TEXEL1 */ -#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 +#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 /* typical CC cycle 2 modes */ -#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED -#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 -#define G_CC_MODULATERGB2 G_CC_MODULATEI2 -#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 -#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 -#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 -#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 -#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE +#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED +#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 +#define G_CC_MODULATERGB2 G_CC_MODULATEI2 +#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 +#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 +#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 +#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 +#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE /* * ? -#define G_CC_DECALRGBA2 COMBINED, SHADE, COMBINED_ALPHA, SHADE, 0, 0, 0, SHADE +#define G_CC_DECALRGBA2 COMBINED, SHADE, COMBINED_ALPHA, SHADE, 0, 0, 0, SHADE */ -#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 -#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 -#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE -#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED -#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 -#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED +#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 +#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 +#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE +#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED +#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED /* * G_SETOTHERMODE_L sft: shift count */ -#define G_MDSFT_ALPHACOMPARE 0 -#define G_MDSFT_ZSRCSEL 2 -#define G_MDSFT_RENDERMODE 3 -#define G_MDSFT_BLENDER 16 +#define G_MDSFT_ALPHACOMPARE 0 +#define G_MDSFT_ZSRCSEL 2 +#define G_MDSFT_RENDERMODE 3 +#define G_MDSFT_BLENDER 16 /* * G_SETOTHERMODE_H sft: shift count */ -#define G_MDSFT_BLENDMASK 0 /* unsupported */ -#define G_MDSFT_ALPHADITHER 4 -#define G_MDSFT_RGBDITHER 6 +#define G_MDSFT_BLENDMASK 0 /* unsupported */ +#define G_MDSFT_ALPHADITHER 4 +#define G_MDSFT_RGBDITHER 6 -#define G_MDSFT_COMBKEY 8 -#define G_MDSFT_TEXTCONV 9 -#define G_MDSFT_TEXTFILT 12 -#define G_MDSFT_TEXTLUT 14 -#define G_MDSFT_TEXTLOD 16 -#define G_MDSFT_TEXTDETAIL 17 -#define G_MDSFT_TEXTPERSP 19 -#define G_MDSFT_CYCLETYPE 20 -#define G_MDSFT_COLORDITHER 22 /* unsupported in HW 2.0 */ -#define G_MDSFT_PIPELINE 23 +#define G_MDSFT_COMBKEY 8 +#define G_MDSFT_TEXTCONV 9 +#define G_MDSFT_TEXTFILT 12 +#define G_MDSFT_TEXTLUT 14 +#define G_MDSFT_TEXTLOD 16 +#define G_MDSFT_TEXTDETAIL 17 +#define G_MDSFT_TEXTPERSP 19 +#define G_MDSFT_CYCLETYPE 20 +#define G_MDSFT_COLORDITHER 22 /* unsupported in HW 2.0 */ +#define G_MDSFT_PIPELINE 23 /* G_SETOTHERMODE_H gPipelineMode */ -#define G_PM_1PRIMITIVE (1 << G_MDSFT_PIPELINE) -#define G_PM_NPRIMITIVE (0 << G_MDSFT_PIPELINE) +#define G_PM_1PRIMITIVE (1 << G_MDSFT_PIPELINE) +#define G_PM_NPRIMITIVE (0 << G_MDSFT_PIPELINE) /* G_SETOTHERMODE_H gSetCycleType */ -#define G_CYC_1CYCLE (0 << G_MDSFT_CYCLETYPE) -#define G_CYC_2CYCLE (1 << G_MDSFT_CYCLETYPE) -#define G_CYC_COPY (2 << G_MDSFT_CYCLETYPE) -#define G_CYC_FILL (3 << G_MDSFT_CYCLETYPE) +#define G_CYC_1CYCLE (0 << G_MDSFT_CYCLETYPE) +#define G_CYC_2CYCLE (1 << G_MDSFT_CYCLETYPE) +#define G_CYC_COPY (2 << G_MDSFT_CYCLETYPE) +#define G_CYC_FILL (3 << G_MDSFT_CYCLETYPE) /* G_SETOTHERMODE_H gSetTexturePersp */ -#define G_TP_NONE (0 << G_MDSFT_TEXTPERSP) -#define G_TP_PERSP (1 << G_MDSFT_TEXTPERSP) +#define G_TP_NONE (0 << G_MDSFT_TEXTPERSP) +#define G_TP_PERSP (1 << G_MDSFT_TEXTPERSP) /* G_SETOTHERMODE_H gSetTextureDetail */ -#define G_TD_CLAMP (0 << G_MDSFT_TEXTDETAIL) -#define G_TD_SHARPEN (1 << G_MDSFT_TEXTDETAIL) -#define G_TD_DETAIL (2 << G_MDSFT_TEXTDETAIL) +#define G_TD_CLAMP (0 << G_MDSFT_TEXTDETAIL) +#define G_TD_SHARPEN (1 << G_MDSFT_TEXTDETAIL) +#define G_TD_DETAIL (2 << G_MDSFT_TEXTDETAIL) /* G_SETOTHERMODE_H gSetTextureLOD */ -#define G_TL_TILE (0 << G_MDSFT_TEXTLOD) -#define G_TL_LOD (1 << G_MDSFT_TEXTLOD) +#define G_TL_TILE (0 << G_MDSFT_TEXTLOD) +#define G_TL_LOD (1 << G_MDSFT_TEXTLOD) /* G_SETOTHERMODE_H gSetTextureLUT */ -#define G_TT_NONE (0 << G_MDSFT_TEXTLUT) -#define G_TT_RGBA16 (2 << G_MDSFT_TEXTLUT) -#define G_TT_IA16 (3 << G_MDSFT_TEXTLUT) +#define G_TT_NONE (0 << G_MDSFT_TEXTLUT) +#define G_TT_RGBA16 (2 << G_MDSFT_TEXTLUT) +#define G_TT_IA16 (3 << G_MDSFT_TEXTLUT) /* G_SETOTHERMODE_H gSetTextureFilter */ -#define G_TF_POINT (0 << G_MDSFT_TEXTFILT) -#define G_TF_AVERAGE (3 << G_MDSFT_TEXTFILT) -#define G_TF_BILERP (2 << G_MDSFT_TEXTFILT) +#define G_TF_POINT (0 << G_MDSFT_TEXTFILT) +#define G_TF_AVERAGE (3 << G_MDSFT_TEXTFILT) +#define G_TF_BILERP (2 << G_MDSFT_TEXTFILT) /* G_SETOTHERMODE_H gSetTextureConvert */ -#define G_TC_CONV (0 << G_MDSFT_TEXTCONV) -#define G_TC_FILTCONV (5 << G_MDSFT_TEXTCONV) -#define G_TC_FILT (6 << G_MDSFT_TEXTCONV) +#define G_TC_CONV (0 << G_MDSFT_TEXTCONV) +#define G_TC_FILTCONV (5 << G_MDSFT_TEXTCONV) +#define G_TC_FILT (6 << G_MDSFT_TEXTCONV) /* G_SETOTHERMODE_H gSetCombineKey */ -#define G_CK_NONE (0 << G_MDSFT_COMBKEY) -#define G_CK_KEY (1 << G_MDSFT_COMBKEY) +#define G_CK_NONE (0 << G_MDSFT_COMBKEY) +#define G_CK_KEY (1 << G_MDSFT_COMBKEY) /* G_SETOTHERMODE_H gSetColorDither */ -#define G_CD_MAGICSQ (0 << G_MDSFT_RGBDITHER) -#define G_CD_BAYER (1 << G_MDSFT_RGBDITHER) -#define G_CD_NOISE (2 << G_MDSFT_RGBDITHER) +#define G_CD_MAGICSQ (0 << G_MDSFT_RGBDITHER) +#define G_CD_BAYER (1 << G_MDSFT_RGBDITHER) +#define G_CD_NOISE (2 << G_MDSFT_RGBDITHER) #ifndef _HW_VERSION_1 -#define G_CD_DISABLE (3 << G_MDSFT_RGBDITHER) -#define G_CD_ENABLE G_CD_NOISE /* HW 1.0 compatibility mode */ +#define G_CD_DISABLE (3 << G_MDSFT_RGBDITHER) +#define G_CD_ENABLE G_CD_NOISE /* HW 1.0 compatibility mode */ #else -#define G_CD_ENABLE (1 << G_MDSFT_COLORDITHER) -#define G_CD_DISABLE (0 << G_MDSFT_COLORDITHER) +#define G_CD_ENABLE (1 << G_MDSFT_COLORDITHER) +#define G_CD_DISABLE (0 << G_MDSFT_COLORDITHER) #endif /* G_SETOTHERMODE_H gSetAlphaDither */ -#define G_AD_PATTERN (0 << G_MDSFT_ALPHADITHER) -#define G_AD_NOTPATTERN (1 << G_MDSFT_ALPHADITHER) -#define G_AD_NOISE (2 << G_MDSFT_ALPHADITHER) -#define G_AD_DISABLE (3 << G_MDSFT_ALPHADITHER) +#define G_AD_PATTERN (0 << G_MDSFT_ALPHADITHER) +#define G_AD_NOTPATTERN (1 << G_MDSFT_ALPHADITHER) +#define G_AD_NOISE (2 << G_MDSFT_ALPHADITHER) +#define G_AD_DISABLE (3 << G_MDSFT_ALPHADITHER) /* G_SETOTHERMODE_L gSetAlphaCompare */ -#define G_AC_NONE (0 << G_MDSFT_ALPHACOMPARE) -#define G_AC_THRESHOLD (1 << G_MDSFT_ALPHACOMPARE) -#define G_AC_DITHER (3 << G_MDSFT_ALPHACOMPARE) +#define G_AC_NONE (0 << G_MDSFT_ALPHACOMPARE) +#define G_AC_THRESHOLD (1 << G_MDSFT_ALPHACOMPARE) +#define G_AC_DITHER (3 << G_MDSFT_ALPHACOMPARE) /* G_SETOTHERMODE_L gSetDepthSource */ -#define G_ZS_PIXEL (0 << G_MDSFT_ZSRCSEL) -#define G_ZS_PRIM (1 << G_MDSFT_ZSRCSEL) +#define G_ZS_PIXEL (0 << G_MDSFT_ZSRCSEL) +#define G_ZS_PRIM (1 << G_MDSFT_ZSRCSEL) /* G_SETOTHERMODE_L gSetRenderMode */ -#define AA_EN 0x8 -#define Z_CMP 0x10 -#define Z_UPD 0x20 -#define IM_RD 0x40 -#define CLR_ON_CVG 0x80 -#define CVG_DST_CLAMP 0 -#define CVG_DST_WRAP 0x100 -#define CVG_DST_FULL 0x200 -#define CVG_DST_SAVE 0x300 -#define ZMODE_OPA 0 -#define ZMODE_INTER 0x400 -#define ZMODE_XLU 0x800 -#define ZMODE_DEC 0xC00 -#define CVG_X_ALPHA 0x1000 -#define ALPHA_CVG_SEL 0x2000 -#define FORCE_BL 0x4000 -#define TEX_EDGE 0x0000 /* used to be 0x8000 */ +#define AA_EN 0x8 +#define Z_CMP 0x10 +#define Z_UPD 0x20 +#define IM_RD 0x40 +#define CLR_ON_CVG 0x80 +#define CVG_DST_CLAMP 0 +#define CVG_DST_WRAP 0x100 +#define CVG_DST_FULL 0x200 +#define CVG_DST_SAVE 0x300 +#define ZMODE_OPA 0 +#define ZMODE_INTER 0x400 +#define ZMODE_XLU 0x800 +#define ZMODE_DEC 0xc00 +#define CVG_X_ALPHA 0x1000 +#define ALPHA_CVG_SEL 0x2000 +#define FORCE_BL 0x4000 +#define TEX_EDGE 0x0000 /* used to be 0x8000 */ -#define G_BL_CLR_IN 0 -#define G_BL_CLR_MEM 1 -#define G_BL_CLR_BL 2 -#define G_BL_CLR_FOG 3 -#define G_BL_1MA 0 -#define G_BL_A_MEM 1 -#define G_BL_A_IN 0 -#define G_BL_A_FOG 1 -#define G_BL_A_SHADE 2 -#define G_BL_1 2 -#define G_BL_0 3 +#define G_BL_CLR_IN 0 +#define G_BL_CLR_MEM 1 +#define G_BL_CLR_BL 2 +#define G_BL_CLR_FOG 3 +#define G_BL_1MA 0 +#define G_BL_A_MEM 1 +#define G_BL_A_IN 0 +#define G_BL_A_FOG 1 +#define G_BL_A_SHADE 2 +#define G_BL_1 2 +#define G_BL_0 3 -#define GBL_c1(m1a, m1b, m2a, m2b) \ - (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 -#define GBL_c2(m1a, m1b, m2a, m2b) \ - (m1a) << 28 | (m1b) << 24 | (m2a) << 20 | (m2b) << 16 +#define GBL_c1(m1a, m1b, m2a, m2b) (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 +#define GBL_c2(m1a, m1b, m2a, m2b) (m1a) << 28 | (m1b) << 24 | (m2a) << 20 | (m2b) << 16 -#define RM_AA_ZB_OPA_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_RA_ZB_OPA_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_RA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_XLU_SURF(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_XLU_SURF(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_OPA_DECAL(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ALPHA_CVG_SEL | \ - ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ALPHA_CVG_SEL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_RA_ZB_OPA_DECAL(clk) \ - AA_EN | Z_CMP | CVG_DST_WRAP | ALPHA_CVG_SEL | \ - ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_RA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | CVG_DST_WRAP | ALPHA_CVG_SEL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_XLU_DECAL(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_XLU_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_OPA_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ALPHA_CVG_SEL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_RA_ZB_OPA_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ - ALPHA_CVG_SEL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_RA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_XLU_INTER(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ - FORCE_BL | ZMODE_INTER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_XLU_INTER(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_XLU_LINE(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_XLU_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_DEC_LINE(clk) \ - AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_DEC_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_TEX_EDGE(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_TEX_EDGE(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_TEX_INTER(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_INTER | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_TEX_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_INTER | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_SUB_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_ZB_SUB_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_ZB_PCL_SURF(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_PCL_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_OPA_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_OPA_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_TEX_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_TEX_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_ZB_SUB_TERR(clk) \ - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_ZB_SUB_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_OPA_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_OPA_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_RA_OPA_SURF(clk) \ + AA_EN | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_RA_OPA_SURF(clk) \ - AA_EN | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_XLU_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_XLU_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | \ - ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_XLU_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_XLU_LINE(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_DEC_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_DEC_LINE(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | CVG_X_ALPHA | \ - ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_TEX_EDGE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_TEX_EDGE(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_SUB_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_AA_SUB_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_AA_PCL_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | G_AC_DITHER | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_PCL_SURF(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_OPA_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_OPA_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_TEX_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_TEX_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_AA_SUB_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_AA_SUB_TERR(clk) \ - AA_EN | IM_RD | CVG_DST_FULL | \ - ZMODE_OPA | ALPHA_CVG_SEL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_ZB_OPA_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_ZB_XLU_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_ZB_OPA_SURF(clk) \ - Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \ - ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_ZB_OPA_DECAL(clk) \ + Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) -#define RM_ZB_XLU_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_ZB_XLU_DECAL(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_ZB_OPA_DECAL(clk) \ - Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) +#define RM_ZB_CLD_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_ZB_XLU_DECAL(clk) \ - Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_ZB_OVL_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_ZB_CLD_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_ZB_PCL_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | G_AC_DITHER | GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) -#define RM_ZB_OVL_SURF(clk) \ - Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_OPA_SURF(clk) CVG_DST_CLAMP | FORCE_BL | ZMODE_OPA | GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) -#define RM_ZB_PCL_SURF(clk) \ - Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ - G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define RM_XLU_SURF(clk) \ + IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_OPA | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_TEX_EDGE(clk) \ + CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | TEX_EDGE | AA_EN | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) -#define RM_OPA_SURF(clk) \ - CVG_DST_CLAMP | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define RM_CLD_SURF(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define RM_XLU_SURF(clk) \ - IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_PCL_SURF(clk) \ + CVG_DST_FULL | FORCE_BL | ZMODE_OPA | G_AC_DITHER | GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) -#define RM_TEX_EDGE(clk) \ - CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL |\ - ZMODE_OPA | TEX_EDGE | AA_EN | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define RM_ADD(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | GBL_c##clk(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) -#define RM_CLD_SURF(clk) \ - IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) +#define RM_NOOP(clk) GBL_c##clk(0, 0, 0, 0) -#define RM_PCL_SURF(clk) \ - CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ - G_AC_DITHER | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) - -#define RM_ADD(clk) \ - IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) - -#define RM_NOOP(clk) \ - GBL_c##clk(0, 0, 0, 0) - -#define RM_VISCVG(clk) \ - IM_RD | FORCE_BL | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) +#define RM_VISCVG(clk) IM_RD | FORCE_BL | GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) /* for rendering to an 8-bit framebuffer */ -#define RM_OPA_CI(clk) \ - CVG_DST_CLAMP | ZMODE_OPA | \ - GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define RM_OPA_CI(clk) CVG_DST_CLAMP | ZMODE_OPA | GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define G_RM_AA_ZB_OPA_SURF RM_AA_ZB_OPA_SURF(1) +#define G_RM_AA_ZB_OPA_SURF2 RM_AA_ZB_OPA_SURF(2) +#define G_RM_AA_ZB_XLU_SURF RM_AA_ZB_XLU_SURF(1) +#define G_RM_AA_ZB_XLU_SURF2 RM_AA_ZB_XLU_SURF(2) +#define G_RM_AA_ZB_OPA_DECAL RM_AA_ZB_OPA_DECAL(1) +#define G_RM_AA_ZB_OPA_DECAL2 RM_AA_ZB_OPA_DECAL(2) +#define G_RM_AA_ZB_XLU_DECAL RM_AA_ZB_XLU_DECAL(1) +#define G_RM_AA_ZB_XLU_DECAL2 RM_AA_ZB_XLU_DECAL(2) +#define G_RM_AA_ZB_OPA_INTER RM_AA_ZB_OPA_INTER(1) +#define G_RM_AA_ZB_OPA_INTER2 RM_AA_ZB_OPA_INTER(2) +#define G_RM_AA_ZB_XLU_INTER RM_AA_ZB_XLU_INTER(1) +#define G_RM_AA_ZB_XLU_INTER2 RM_AA_ZB_XLU_INTER(2) +#define G_RM_AA_ZB_XLU_LINE RM_AA_ZB_XLU_LINE(1) +#define G_RM_AA_ZB_XLU_LINE2 RM_AA_ZB_XLU_LINE(2) +#define G_RM_AA_ZB_DEC_LINE RM_AA_ZB_DEC_LINE(1) +#define G_RM_AA_ZB_DEC_LINE2 RM_AA_ZB_DEC_LINE(2) +#define G_RM_AA_ZB_TEX_EDGE RM_AA_ZB_TEX_EDGE(1) +#define G_RM_AA_ZB_TEX_EDGE2 RM_AA_ZB_TEX_EDGE(2) +#define G_RM_AA_ZB_TEX_INTER RM_AA_ZB_TEX_INTER(1) +#define G_RM_AA_ZB_TEX_INTER2 RM_AA_ZB_TEX_INTER(2) +#define G_RM_AA_ZB_SUB_SURF RM_AA_ZB_SUB_SURF(1) +#define G_RM_AA_ZB_SUB_SURF2 RM_AA_ZB_SUB_SURF(2) +#define G_RM_AA_ZB_PCL_SURF RM_AA_ZB_PCL_SURF(1) +#define G_RM_AA_ZB_PCL_SURF2 RM_AA_ZB_PCL_SURF(2) +#define G_RM_AA_ZB_OPA_TERR RM_AA_ZB_OPA_TERR(1) +#define G_RM_AA_ZB_OPA_TERR2 RM_AA_ZB_OPA_TERR(2) +#define G_RM_AA_ZB_TEX_TERR RM_AA_ZB_TEX_TERR(1) +#define G_RM_AA_ZB_TEX_TERR2 RM_AA_ZB_TEX_TERR(2) +#define G_RM_AA_ZB_SUB_TERR RM_AA_ZB_SUB_TERR(1) +#define G_RM_AA_ZB_SUB_TERR2 RM_AA_ZB_SUB_TERR(2) +#define G_RM_RA_ZB_OPA_SURF RM_RA_ZB_OPA_SURF(1) +#define G_RM_RA_ZB_OPA_SURF2 RM_RA_ZB_OPA_SURF(2) +#define G_RM_RA_ZB_OPA_DECAL RM_RA_ZB_OPA_DECAL(1) +#define G_RM_RA_ZB_OPA_DECAL2 RM_RA_ZB_OPA_DECAL(2) +#define G_RM_RA_ZB_OPA_INTER RM_RA_ZB_OPA_INTER(1) +#define G_RM_RA_ZB_OPA_INTER2 RM_RA_ZB_OPA_INTER(2) -#define G_RM_AA_ZB_OPA_SURF RM_AA_ZB_OPA_SURF(1) -#define G_RM_AA_ZB_OPA_SURF2 RM_AA_ZB_OPA_SURF(2) -#define G_RM_AA_ZB_XLU_SURF RM_AA_ZB_XLU_SURF(1) -#define G_RM_AA_ZB_XLU_SURF2 RM_AA_ZB_XLU_SURF(2) -#define G_RM_AA_ZB_OPA_DECAL RM_AA_ZB_OPA_DECAL(1) -#define G_RM_AA_ZB_OPA_DECAL2 RM_AA_ZB_OPA_DECAL(2) -#define G_RM_AA_ZB_XLU_DECAL RM_AA_ZB_XLU_DECAL(1) -#define G_RM_AA_ZB_XLU_DECAL2 RM_AA_ZB_XLU_DECAL(2) -#define G_RM_AA_ZB_OPA_INTER RM_AA_ZB_OPA_INTER(1) -#define G_RM_AA_ZB_OPA_INTER2 RM_AA_ZB_OPA_INTER(2) -#define G_RM_AA_ZB_XLU_INTER RM_AA_ZB_XLU_INTER(1) -#define G_RM_AA_ZB_XLU_INTER2 RM_AA_ZB_XLU_INTER(2) -#define G_RM_AA_ZB_XLU_LINE RM_AA_ZB_XLU_LINE(1) -#define G_RM_AA_ZB_XLU_LINE2 RM_AA_ZB_XLU_LINE(2) -#define G_RM_AA_ZB_DEC_LINE RM_AA_ZB_DEC_LINE(1) -#define G_RM_AA_ZB_DEC_LINE2 RM_AA_ZB_DEC_LINE(2) -#define G_RM_AA_ZB_TEX_EDGE RM_AA_ZB_TEX_EDGE(1) -#define G_RM_AA_ZB_TEX_EDGE2 RM_AA_ZB_TEX_EDGE(2) -#define G_RM_AA_ZB_TEX_INTER RM_AA_ZB_TEX_INTER(1) -#define G_RM_AA_ZB_TEX_INTER2 RM_AA_ZB_TEX_INTER(2) -#define G_RM_AA_ZB_SUB_SURF RM_AA_ZB_SUB_SURF(1) -#define G_RM_AA_ZB_SUB_SURF2 RM_AA_ZB_SUB_SURF(2) -#define G_RM_AA_ZB_PCL_SURF RM_AA_ZB_PCL_SURF(1) -#define G_RM_AA_ZB_PCL_SURF2 RM_AA_ZB_PCL_SURF(2) -#define G_RM_AA_ZB_OPA_TERR RM_AA_ZB_OPA_TERR(1) -#define G_RM_AA_ZB_OPA_TERR2 RM_AA_ZB_OPA_TERR(2) -#define G_RM_AA_ZB_TEX_TERR RM_AA_ZB_TEX_TERR(1) -#define G_RM_AA_ZB_TEX_TERR2 RM_AA_ZB_TEX_TERR(2) -#define G_RM_AA_ZB_SUB_TERR RM_AA_ZB_SUB_TERR(1) -#define G_RM_AA_ZB_SUB_TERR2 RM_AA_ZB_SUB_TERR(2) +#define G_RM_AA_OPA_SURF RM_AA_OPA_SURF(1) +#define G_RM_AA_OPA_SURF2 RM_AA_OPA_SURF(2) +#define G_RM_AA_XLU_SURF RM_AA_XLU_SURF(1) +#define G_RM_AA_XLU_SURF2 RM_AA_XLU_SURF(2) +#define G_RM_AA_XLU_LINE RM_AA_XLU_LINE(1) +#define G_RM_AA_XLU_LINE2 RM_AA_XLU_LINE(2) +#define G_RM_AA_DEC_LINE RM_AA_DEC_LINE(1) +#define G_RM_AA_DEC_LINE2 RM_AA_DEC_LINE(2) +#define G_RM_AA_TEX_EDGE RM_AA_TEX_EDGE(1) +#define G_RM_AA_TEX_EDGE2 RM_AA_TEX_EDGE(2) +#define G_RM_AA_SUB_SURF RM_AA_SUB_SURF(1) +#define G_RM_AA_SUB_SURF2 RM_AA_SUB_SURF(2) +#define G_RM_AA_PCL_SURF RM_AA_PCL_SURF(1) +#define G_RM_AA_PCL_SURF2 RM_AA_PCL_SURF(2) +#define G_RM_AA_OPA_TERR RM_AA_OPA_TERR(1) +#define G_RM_AA_OPA_TERR2 RM_AA_OPA_TERR(2) +#define G_RM_AA_TEX_TERR RM_AA_TEX_TERR(1) +#define G_RM_AA_TEX_TERR2 RM_AA_TEX_TERR(2) +#define G_RM_AA_SUB_TERR RM_AA_SUB_TERR(1) +#define G_RM_AA_SUB_TERR2 RM_AA_SUB_TERR(2) -#define G_RM_RA_ZB_OPA_SURF RM_RA_ZB_OPA_SURF(1) -#define G_RM_RA_ZB_OPA_SURF2 RM_RA_ZB_OPA_SURF(2) -#define G_RM_RA_ZB_OPA_DECAL RM_RA_ZB_OPA_DECAL(1) -#define G_RM_RA_ZB_OPA_DECAL2 RM_RA_ZB_OPA_DECAL(2) -#define G_RM_RA_ZB_OPA_INTER RM_RA_ZB_OPA_INTER(1) -#define G_RM_RA_ZB_OPA_INTER2 RM_RA_ZB_OPA_INTER(2) +#define G_RM_RA_OPA_SURF RM_RA_OPA_SURF(1) +#define G_RM_RA_OPA_SURF2 RM_RA_OPA_SURF(2) -#define G_RM_AA_OPA_SURF RM_AA_OPA_SURF(1) -#define G_RM_AA_OPA_SURF2 RM_AA_OPA_SURF(2) -#define G_RM_AA_XLU_SURF RM_AA_XLU_SURF(1) -#define G_RM_AA_XLU_SURF2 RM_AA_XLU_SURF(2) -#define G_RM_AA_XLU_LINE RM_AA_XLU_LINE(1) -#define G_RM_AA_XLU_LINE2 RM_AA_XLU_LINE(2) -#define G_RM_AA_DEC_LINE RM_AA_DEC_LINE(1) -#define G_RM_AA_DEC_LINE2 RM_AA_DEC_LINE(2) -#define G_RM_AA_TEX_EDGE RM_AA_TEX_EDGE(1) -#define G_RM_AA_TEX_EDGE2 RM_AA_TEX_EDGE(2) -#define G_RM_AA_SUB_SURF RM_AA_SUB_SURF(1) -#define G_RM_AA_SUB_SURF2 RM_AA_SUB_SURF(2) -#define G_RM_AA_PCL_SURF RM_AA_PCL_SURF(1) -#define G_RM_AA_PCL_SURF2 RM_AA_PCL_SURF(2) -#define G_RM_AA_OPA_TERR RM_AA_OPA_TERR(1) -#define G_RM_AA_OPA_TERR2 RM_AA_OPA_TERR(2) -#define G_RM_AA_TEX_TERR RM_AA_TEX_TERR(1) -#define G_RM_AA_TEX_TERR2 RM_AA_TEX_TERR(2) -#define G_RM_AA_SUB_TERR RM_AA_SUB_TERR(1) -#define G_RM_AA_SUB_TERR2 RM_AA_SUB_TERR(2) +#define G_RM_ZB_OPA_SURF RM_ZB_OPA_SURF(1) +#define G_RM_ZB_OPA_SURF2 RM_ZB_OPA_SURF(2) +#define G_RM_ZB_XLU_SURF RM_ZB_XLU_SURF(1) +#define G_RM_ZB_XLU_SURF2 RM_ZB_XLU_SURF(2) +#define G_RM_ZB_OPA_DECAL RM_ZB_OPA_DECAL(1) +#define G_RM_ZB_OPA_DECAL2 RM_ZB_OPA_DECAL(2) +#define G_RM_ZB_XLU_DECAL RM_ZB_XLU_DECAL(1) +#define G_RM_ZB_XLU_DECAL2 RM_ZB_XLU_DECAL(2) +#define G_RM_ZB_CLD_SURF RM_ZB_CLD_SURF(1) +#define G_RM_ZB_CLD_SURF2 RM_ZB_CLD_SURF(2) +#define G_RM_ZB_OVL_SURF RM_ZB_OVL_SURF(1) +#define G_RM_ZB_OVL_SURF2 RM_ZB_OVL_SURF(2) +#define G_RM_ZB_PCL_SURF RM_ZB_PCL_SURF(1) +#define G_RM_ZB_PCL_SURF2 RM_ZB_PCL_SURF(2) -#define G_RM_RA_OPA_SURF RM_RA_OPA_SURF(1) -#define G_RM_RA_OPA_SURF2 RM_RA_OPA_SURF(2) +#define G_RM_OPA_SURF RM_OPA_SURF(1) +#define G_RM_OPA_SURF2 RM_OPA_SURF(2) +#define G_RM_XLU_SURF RM_XLU_SURF(1) +#define G_RM_XLU_SURF2 RM_XLU_SURF(2) +#define G_RM_CLD_SURF RM_CLD_SURF(1) +#define G_RM_CLD_SURF2 RM_CLD_SURF(2) +#define G_RM_TEX_EDGE RM_TEX_EDGE(1) +#define G_RM_TEX_EDGE2 RM_TEX_EDGE(2) +#define G_RM_PCL_SURF RM_PCL_SURF(1) +#define G_RM_PCL_SURF2 RM_PCL_SURF(2) +#define G_RM_ADD RM_ADD(1) +#define G_RM_ADD2 RM_ADD(2) +#define G_RM_NOOP RM_NOOP(1) +#define G_RM_NOOP2 RM_NOOP(2) +#define G_RM_VISCVG RM_VISCVG(1) +#define G_RM_VISCVG2 RM_VISCVG(2) +#define G_RM_OPA_CI RM_OPA_CI(1) +#define G_RM_OPA_CI2 RM_OPA_CI(2) -#define G_RM_ZB_OPA_SURF RM_ZB_OPA_SURF(1) -#define G_RM_ZB_OPA_SURF2 RM_ZB_OPA_SURF(2) -#define G_RM_ZB_XLU_SURF RM_ZB_XLU_SURF(1) -#define G_RM_ZB_XLU_SURF2 RM_ZB_XLU_SURF(2) -#define G_RM_ZB_OPA_DECAL RM_ZB_OPA_DECAL(1) -#define G_RM_ZB_OPA_DECAL2 RM_ZB_OPA_DECAL(2) -#define G_RM_ZB_XLU_DECAL RM_ZB_XLU_DECAL(1) -#define G_RM_ZB_XLU_DECAL2 RM_ZB_XLU_DECAL(2) -#define G_RM_ZB_CLD_SURF RM_ZB_CLD_SURF(1) -#define G_RM_ZB_CLD_SURF2 RM_ZB_CLD_SURF(2) -#define G_RM_ZB_OVL_SURF RM_ZB_OVL_SURF(1) -#define G_RM_ZB_OVL_SURF2 RM_ZB_OVL_SURF(2) -#define G_RM_ZB_PCL_SURF RM_ZB_PCL_SURF(1) -#define G_RM_ZB_PCL_SURF2 RM_ZB_PCL_SURF(2) - -#define G_RM_OPA_SURF RM_OPA_SURF(1) -#define G_RM_OPA_SURF2 RM_OPA_SURF(2) -#define G_RM_XLU_SURF RM_XLU_SURF(1) -#define G_RM_XLU_SURF2 RM_XLU_SURF(2) -#define G_RM_CLD_SURF RM_CLD_SURF(1) -#define G_RM_CLD_SURF2 RM_CLD_SURF(2) -#define G_RM_TEX_EDGE RM_TEX_EDGE(1) -#define G_RM_TEX_EDGE2 RM_TEX_EDGE(2) -#define G_RM_PCL_SURF RM_PCL_SURF(1) -#define G_RM_PCL_SURF2 RM_PCL_SURF(2) -#define G_RM_ADD RM_ADD(1) -#define G_RM_ADD2 RM_ADD(2) -#define G_RM_NOOP RM_NOOP(1) -#define G_RM_NOOP2 RM_NOOP(2) -#define G_RM_VISCVG RM_VISCVG(1) -#define G_RM_VISCVG2 RM_VISCVG(2) -#define G_RM_OPA_CI RM_OPA_CI(1) -#define G_RM_OPA_CI2 RM_OPA_CI(2) - - -#define G_RM_FOG_SHADE_A GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) -#define G_RM_FOG_PRIM_A GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) -#define G_RM_PASS GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) +#define G_RM_FOG_SHADE_A GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) +#define G_RM_FOG_PRIM_A GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) +#define G_RM_PASS GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) /* * G_SETCONVERT: K0-5 */ -#define G_CV_K0 175 -#define G_CV_K1 -43 -#define G_CV_K2 -89 -#define G_CV_K3 222 -#define G_CV_K4 114 -#define G_CV_K5 42 +#define G_CV_K0 175 +#define G_CV_K1 -43 +#define G_CV_K2 -89 +#define G_CV_K3 222 +#define G_CV_K4 114 +#define G_CV_K5 42 /* * G_SETSCISSOR: interlace mode */ -#define G_SC_NON_INTERLACE 0 -#define G_SC_ODD_INTERLACE 3 -#define G_SC_EVEN_INTERLACE 2 +#define G_SC_NON_INTERLACE 0 +#define G_SC_ODD_INTERLACE 3 +#define G_SC_EVEN_INTERLACE 2 /* flags to inhibit pushing of the display list (on branch) */ -#define G_DL_PUSH 0x00 -#define G_DL_NOPUSH 0x01 +#define G_DL_PUSH 0x00 +#define G_DL_NOPUSH 0x01 + +#if defined(_MSC_VER) || defined(__GNUC__) +#define _LANGUAGE_C +#endif /* * BEGIN C-specific section: (typedef's) @@ -997,27 +1029,27 @@ * Vertex (set up for use with colors) */ typedef struct { - short ob[3]; /* x, y, z */ - unsigned short flag; - short tc[2]; /* texture coord */ - unsigned char cn[4]; /* color & alpha */ + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + unsigned char cn[4]; /* color & alpha */ } Vtx_t; /* * Vertex (set up for use with normals) */ typedef struct { - short ob[3]; /* x, y, z */ - unsigned short flag; - short tc[2]; /* texture coord */ - signed char n[3]; /* normal */ - unsigned char a; /* alpha */ + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + signed char n[3]; /* normal */ + unsigned char a; /* alpha */ } Vtx_tn; typedef union { - Vtx_t v; /* Use this one for colors */ - Vtx_tn n; /* Use this one for normals */ - long long int force_structure_alignment; + Vtx_t v; /* Use this one for colors */ + Vtx_tn n; /* Use this one for normals */ + long long int force_structure_alignment; } Vtx; /* @@ -1025,47 +1057,37 @@ typedef union { */ typedef struct { - void *SourceImagePointer; - void *TlutPointer; - short Stride; - short SubImageWidth; - short SubImageHeight; - char SourceImageType; - char SourceImageBitSize; - short SourceImageOffsetS; - short SourceImageOffsetT; - /* 20 bytes for above */ + void* SourceImagePointer; + void* TlutPointer; + short Stride; + short SubImageWidth; + short SubImageHeight; + char SourceImageType; + char SourceImageBitSize; + short SourceImageOffsetS; + short SourceImageOffsetT; + /* 20 bytes for above */ - /* padding to bring structure size to 64 bit allignment */ - char dummy[4]; + /* padding to bring structure size to 64 bit allignment */ + char dummy[4]; } uSprite_t; typedef union { - uSprite_t s; + uSprite_t s; - /* Need to make sure this is 64 bit aligned */ - long long int force_structure_allignment[3]; + /* Need to make sure this is 64 bit aligned */ + long long int force_structure_allignment[3]; } uSprite; /* * Triangle face */ typedef struct { - unsigned char flag; - unsigned char v[3]; + unsigned char flag; + unsigned char v[3]; } Tri; -typedef long int Mtx_t[4][4]; -typedef union { - Mtx_t m; - struct { - u16 intPart[4][4]; - u16 fracPart[4][4]; - }; - long long int force_structure_alignment; -} Mtx; // size = 0x40 - /* * Viewport */ @@ -1087,7 +1109,7 @@ typedef union { * but we don't have the ucode to do that... * */ -#define G_MAXZ 0x03FF /* 10 bits of integer screen-Z precision */ +#define G_MAXZ 0x03ff /* 10 bits of integer screen-Z precision */ /* * The viewport structure elements have 2 bits of fraction, necessary @@ -1097,18 +1119,18 @@ typedef union { * Accounting for these fractional bits, using the default projection * and viewing matrices, the viewport structure is initialized thusly: * - * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0, - * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0, + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0, + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0, */ typedef struct { - short vscale[4]; /* scale, 2 bits fraction */ - short vtrans[4]; /* translate, 2 bits fraction */ - /* both the above arrays are padded to 64-bit boundary */ + short vscale[4]; /* scale, 2 bits fraction */ + short vtrans[4]; /* translate, 2 bits fraction */ + /* both the above arrays are padded to 64-bit boundary */ } Vp_t; typedef union { - Vp_t vp; - long long int force_structure_alignment; + Vp_t vp; + long long int force_structure_alignment; } Vp; /* @@ -1119,42 +1141,42 @@ typedef union { * which to store a 1-4 word DMA. * */ -#ifdef F3DEX_GBI_2 +#ifdef F3DEX_GBI_2 /* 0,4 are reserved by G_MTX */ -# define G_MV_MMTX 2 -# define G_MV_PMTX 6 -# define G_MV_VIEWPORT 8 -# define G_MV_LIGHT 10 -# define G_MV_POINT 12 -# define G_MV_MATRIX 14 /* NOTE: this is in moveword table */ -# define G_MVO_LOOKATX (0*24) -# define G_MVO_LOOKATY (1*24) -# define G_MVO_L0 (2*24) -# define G_MVO_L1 (3*24) -# define G_MVO_L2 (4*24) -# define G_MVO_L3 (5*24) -# define G_MVO_L4 (6*24) -# define G_MVO_L5 (7*24) -# define G_MVO_L6 (8*24) -# define G_MVO_L7 (9*24) -#else /* F3DEX_GBI_2 */ -# define G_MV_VIEWPORT 0x80 -# define G_MV_LOOKATY 0x82 -# define G_MV_LOOKATX 0x84 -# define G_MV_L0 0x86 -# define G_MV_L1 0x88 -# define G_MV_L2 0x8A -# define G_MV_L3 0x8C -# define G_MV_L4 0x8E -# define G_MV_L5 0x90 -# define G_MV_L6 0x92 -# define G_MV_L7 0x94 -# define G_MV_TXTATT 0x96 -# define G_MV_MATRIX_1 0x9E /* NOTE: this is in moveword table */ -# define G_MV_MATRIX_2 0x98 -# define G_MV_MATRIX_3 0x9A -# define G_MV_MATRIX_4 0x9C -#endif /* F3DEX_GBI_2 */ +#define G_MV_MMTX 2 +#define G_MV_PMTX 6 +#define G_MV_VIEWPORT 8 +#define G_MV_LIGHT 10 +#define G_MV_POINT 12 +#define G_MV_MATRIX 14 /* NOTE: this is in moveword table */ +#define G_MVO_LOOKATX (0 * 24) +#define G_MVO_LOOKATY (1 * 24) +#define G_MVO_L0 (2 * 24) +#define G_MVO_L1 (3 * 24) +#define G_MVO_L2 (4 * 24) +#define G_MVO_L3 (5 * 24) +#define G_MVO_L4 (6 * 24) +#define G_MVO_L5 (7 * 24) +#define G_MVO_L6 (8 * 24) +#define G_MVO_L7 (9 * 24) +#else /* F3DEX_GBI_2 */ +#define G_MV_VIEWPORT 0x80 +#define G_MV_LOOKATY 0x82 +#define G_MV_LOOKATX 0x84 +#define G_MV_L0 0x86 +#define G_MV_L1 0x88 +#define G_MV_L2 0x8a +#define G_MV_L3 0x8c +#define G_MV_L4 0x8e +#define G_MV_L5 0x90 +#define G_MV_L6 0x92 +#define G_MV_L7 0x94 +#define G_MV_TXTATT 0x96 +#define G_MV_MATRIX_1 0x9e /* NOTE: this is in moveword table */ +#define G_MV_MATRIX_2 0x98 +#define G_MV_MATRIX_3 0x9a +#define G_MV_MATRIX_4 0x9c +#endif /* F3DEX_GBI_2 */ /* * MOVEWORD indices @@ -1164,97 +1186,97 @@ typedef union { * an immediate word will be stored. * */ -#define G_MW_MATRIX 0x00 /* NOTE: also used by movemem */ -#define G_MW_NUMLIGHT 0x02 -#define G_MW_CLIP 0x04 -#define G_MW_SEGMENT 0x06 -#define G_MW_FOG 0x08 -#define G_MW_LIGHTCOL 0x0A -#ifdef F3DEX_GBI_2 -# define G_MW_FORCEMTX 0x0C -#else /* F3DEX_GBI_2 */ -# define G_MW_POINTS 0x0C -#endif /* F3DEX_GBI_2 */ -#define G_MW_PERSPNORM 0x0E +#define G_MW_MATRIX 0x00 /* NOTE: also used by movemem */ +#define G_MW_NUMLIGHT 0x02 +#define G_MW_CLIP 0x04 +#define G_MW_SEGMENT 0x06 +#define G_MW_FOG 0x08 +#define G_MW_LIGHTCOL 0x0a +#ifdef F3DEX_GBI_2 +#define G_MW_FORCEMTX 0x0c +#else /* F3DEX_GBI_2 */ +#define G_MW_POINTS 0x0c +#endif /* F3DEX_GBI_2 */ +#define G_MW_PERSPNORM 0x0e /* * These are offsets from the address in the dmem table */ -#define G_MWO_NUMLIGHT 0x00 -#define G_MWO_CLIP_RNX 0x04 -#define G_MWO_CLIP_RNY 0x0C -#define G_MWO_CLIP_RPX 0x14 -#define G_MWO_CLIP_RPY 0x1C -#define G_MWO_SEGMENT_0 0x00 -#define G_MWO_SEGMENT_1 0x01 -#define G_MWO_SEGMENT_2 0x02 -#define G_MWO_SEGMENT_3 0x03 -#define G_MWO_SEGMENT_4 0x04 -#define G_MWO_SEGMENT_5 0x05 -#define G_MWO_SEGMENT_6 0x06 -#define G_MWO_SEGMENT_7 0x07 -#define G_MWO_SEGMENT_8 0x08 -#define G_MWO_SEGMENT_9 0x09 -#define G_MWO_SEGMENT_A 0x0A -#define G_MWO_SEGMENT_B 0x0B -#define G_MWO_SEGMENT_C 0x0C -#define G_MWO_SEGMENT_D 0x0D -#define G_MWO_SEGMENT_E 0x0E -#define G_MWO_SEGMENT_F 0x0F -#define G_MWO_FOG 0x00 -#define G_MWO_aLIGHT_1 0x00 -#define G_MWO_bLIGHT_1 0x04 -#ifdef F3DEX_GBI_2 -#define G_MWO_aLIGHT_2 0x18 -#define G_MWO_bLIGHT_2 0x1C -#define G_MWO_aLIGHT_3 0x30 -#define G_MWO_bLIGHT_3 0x34 -#define G_MWO_aLIGHT_4 0x48 -#define G_MWO_bLIGHT_4 0x4C -#define G_MWO_aLIGHT_5 0x60 -#define G_MWO_bLIGHT_5 0x64 -#define G_MWO_aLIGHT_6 0x78 -#define G_MWO_bLIGHT_6 0x7C -#define G_MWO_aLIGHT_7 0x90 -#define G_MWO_bLIGHT_7 0x94 -#define G_MWO_aLIGHT_8 0xA8 -#define G_MWO_bLIGHT_8 0xAC +#define G_MWO_NUMLIGHT 0x00 +#define G_MWO_CLIP_RNX 0x04 +#define G_MWO_CLIP_RNY 0x0c +#define G_MWO_CLIP_RPX 0x14 +#define G_MWO_CLIP_RPY 0x1c +#define G_MWO_SEGMENT_0 0x00 +#define G_MWO_SEGMENT_1 0x01 +#define G_MWO_SEGMENT_2 0x02 +#define G_MWO_SEGMENT_3 0x03 +#define G_MWO_SEGMENT_4 0x04 +#define G_MWO_SEGMENT_5 0x05 +#define G_MWO_SEGMENT_6 0x06 +#define G_MWO_SEGMENT_7 0x07 +#define G_MWO_SEGMENT_8 0x08 +#define G_MWO_SEGMENT_9 0x09 +#define G_MWO_SEGMENT_A 0x0a +#define G_MWO_SEGMENT_B 0x0b +#define G_MWO_SEGMENT_C 0x0c +#define G_MWO_SEGMENT_D 0x0d +#define G_MWO_SEGMENT_E 0x0e +#define G_MWO_SEGMENT_F 0x0f +#define G_MWO_FOG 0x00 +#define G_MWO_aLIGHT_1 0x00 +#define G_MWO_bLIGHT_1 0x04 +#ifdef F3DEX_GBI_2 +#define G_MWO_aLIGHT_2 0x18 +#define G_MWO_bLIGHT_2 0x1c +#define G_MWO_aLIGHT_3 0x30 +#define G_MWO_bLIGHT_3 0x34 +#define G_MWO_aLIGHT_4 0x48 +#define G_MWO_bLIGHT_4 0x4c +#define G_MWO_aLIGHT_5 0x60 +#define G_MWO_bLIGHT_5 0x64 +#define G_MWO_aLIGHT_6 0x78 +#define G_MWO_bLIGHT_6 0x7c +#define G_MWO_aLIGHT_7 0x90 +#define G_MWO_bLIGHT_7 0x94 +#define G_MWO_aLIGHT_8 0xa8 +#define G_MWO_bLIGHT_8 0xac #else -#define G_MWO_aLIGHT_2 0x20 -#define G_MWO_bLIGHT_2 0x24 -#define G_MWO_aLIGHT_3 0x40 -#define G_MWO_bLIGHT_3 0x44 -#define G_MWO_aLIGHT_4 0x60 -#define G_MWO_bLIGHT_4 0x64 -#define G_MWO_aLIGHT_5 0x80 -#define G_MWO_bLIGHT_5 0x84 -#define G_MWO_aLIGHT_6 0xA0 -#define G_MWO_bLIGHT_6 0xA4 -#define G_MWO_aLIGHT_7 0xC0 -#define G_MWO_bLIGHT_7 0xC4 -#define G_MWO_aLIGHT_8 0xE0 -#define G_MWO_bLIGHT_8 0xE4 +#define G_MWO_aLIGHT_2 0x20 +#define G_MWO_bLIGHT_2 0x24 +#define G_MWO_aLIGHT_3 0x40 +#define G_MWO_bLIGHT_3 0x44 +#define G_MWO_aLIGHT_4 0x60 +#define G_MWO_bLIGHT_4 0x64 +#define G_MWO_aLIGHT_5 0x80 +#define G_MWO_bLIGHT_5 0x84 +#define G_MWO_aLIGHT_6 0xa0 +#define G_MWO_bLIGHT_6 0xa4 +#define G_MWO_aLIGHT_7 0xc0 +#define G_MWO_bLIGHT_7 0xc4 +#define G_MWO_aLIGHT_8 0xe0 +#define G_MWO_bLIGHT_8 0xe4 #endif -#define G_MWO_MATRIX_XX_XY_I 0x00 -#define G_MWO_MATRIX_XZ_XW_I 0x04 -#define G_MWO_MATRIX_YX_YY_I 0x08 -#define G_MWO_MATRIX_YZ_YW_I 0x0C -#define G_MWO_MATRIX_ZX_ZY_I 0x10 -#define G_MWO_MATRIX_ZZ_ZW_I 0x14 -#define G_MWO_MATRIX_WX_WY_I 0x18 -#define G_MWO_MATRIX_WZ_WW_I 0x1C -#define G_MWO_MATRIX_XX_XY_F 0x20 -#define G_MWO_MATRIX_XZ_XW_F 0x24 -#define G_MWO_MATRIX_YX_YY_F 0x28 -#define G_MWO_MATRIX_YZ_YW_F 0x2C -#define G_MWO_MATRIX_ZX_ZY_F 0x30 -#define G_MWO_MATRIX_ZZ_ZW_F 0x34 -#define G_MWO_MATRIX_WX_WY_F 0x38 -#define G_MWO_MATRIX_WZ_WW_F 0x3C -#define G_MWO_POINT_RGBA 0x10 -#define G_MWO_POINT_ST 0x14 -#define G_MWO_POINT_XYSCREEN 0x18 -#define G_MWO_POINT_ZSCREEN 0x1C +#define G_MWO_MATRIX_XX_XY_I 0x00 +#define G_MWO_MATRIX_XZ_XW_I 0x04 +#define G_MWO_MATRIX_YX_YY_I 0x08 +#define G_MWO_MATRIX_YZ_YW_I 0x0c +#define G_MWO_MATRIX_ZX_ZY_I 0x10 +#define G_MWO_MATRIX_ZZ_ZW_I 0x14 +#define G_MWO_MATRIX_WX_WY_I 0x18 +#define G_MWO_MATRIX_WZ_WW_I 0x1c +#define G_MWO_MATRIX_XX_XY_F 0x20 +#define G_MWO_MATRIX_XZ_XW_F 0x24 +#define G_MWO_MATRIX_YX_YY_F 0x28 +#define G_MWO_MATRIX_YZ_YW_F 0x2c +#define G_MWO_MATRIX_ZX_ZY_F 0x30 +#define G_MWO_MATRIX_ZZ_ZW_F 0x34 +#define G_MWO_MATRIX_WX_WY_F 0x38 +#define G_MWO_MATRIX_WZ_WW_F 0x3c +#define G_MWO_POINT_RGBA 0x10 +#define G_MWO_POINT_ST 0x14 +#define G_MWO_POINT_XYSCREEN 0x18 +#define G_MWO_POINT_ZSCREEN 0x1c /* * Light structure. @@ -1267,12 +1289,12 @@ typedef union { */ typedef struct { - unsigned char col[3]; /* diffuse light value (rgba) */ - char pad1; - unsigned char colc[3]; /* copy of diffuse light value (rgba) */ - char pad2; - signed char dir[3]; /* direction of light (normalized) */ - char pad3; + unsigned char col[3]; /* diffuse light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of diffuse light value (rgba) */ + char pad2; + signed char dir[3]; /* direction of light (normalized) */ + char pad3; } Light_t; // Added in MM @@ -1286,555 +1308,325 @@ typedef struct { } PointLight_t; typedef struct { - unsigned char col[3]; /* ambient light value (rgba) */ - char pad1; - unsigned char colc[3]; /* copy of ambient light value (rgba) */ - char pad2; + unsigned char col[3]; /* ambient light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of ambient light value (rgba) */ + char pad2; } Ambient_t; typedef struct { - int x1,y1,x2,y2; /* texture offsets for highlight 1/2 */ + int x1, y1, x2, y2; /* texture offsets for highlight 1/2 */ } Hilite_t; typedef union { - Light_t l; - PointLight_t p; - long long int force_structure_alignment[2]; + Light_t l; + PointLight_t p; + long long int force_structure_alignment[2]; } Light; typedef union { - Ambient_t l; - long long int force_structure_alignment[1]; + Ambient_t l; + long long int force_structure_alignment[1]; } Ambient; typedef struct { - Ambient a; - Light l[7]; + Ambient a; + Light l[7]; } Lightsn; typedef struct { - Ambient a; - Light l[1]; + Ambient a; + Light l[1]; } Lights0; typedef struct { - Ambient a; - Light l[1]; + Ambient a; + Light l[1]; } Lights1; typedef struct { - Ambient a; - Light l[2]; + Ambient a; + Light l[2]; } Lights2; typedef struct { - Ambient a; - Light l[3]; + Ambient a; + Light l[3]; } Lights3; typedef struct { - Ambient a; - Light l[4]; + Ambient a; + Light l[4]; } Lights4; typedef struct { - Ambient a; - Light l[5]; + Ambient a; + Light l[5]; } Lights5; typedef struct { - Ambient a; - Light l[6]; + Ambient a; + Light l[6]; } Lights6; typedef struct { - Ambient a; - Light l[7]; + Ambient a; + Light l[7]; } Lights7; typedef struct { - Light l[2]; + Light l[2]; } LookAt; typedef union { - Hilite_t h; - long int force_structure_alignment[4]; + Hilite_t h; + long int force_structure_alignment[4]; } Hilite; -#define gdSPDefLights0(ar,ag,ab) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { 0, 0, 0 }, 0, \ - { 0, 0, 0 }, 0, \ - { 0, 0, 0 }, 0 \ - }} \ - } \ - } +#define gdSPDefLights0(ar, ag, ab) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { \ + { { 0, 0, 0 }, 0, { 0, 0, 0 }, 0, { 0, 0, 0 }, 0 } \ + } \ + } \ + } +#define gdSPDefLights1(ar, ag, ab, r1, g1, b1, x1, y1, z1) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { \ + { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } \ + } \ + } \ + } +#define gdSPDefLights2(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, { \ + { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } \ + } \ + } \ + } +#define gdSPDefLights3(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2, r3, g3, b3, x3, y3, z3) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, \ + { { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } }, { \ + { { r3, g3, b3 }, 0, { r3, g3, b3 }, 0, { x3, y3, z3 }, 0 } \ + } \ + } \ + } +#define gdSPDefLights4(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2, r3, g3, b3, x3, y3, z3, r4, g4, b4, \ + x4, y4, z4) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, \ + { { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } }, \ + { { { r3, g3, b3 }, 0, { r3, g3, b3 }, 0, { x3, y3, z3 }, 0 } }, { \ + { { r4, g4, b4 }, 0, { r4, g4, b4 }, 0, { x4, y4, z4 }, 0 } \ + } \ + } \ + } +#define gdSPDefLights5(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2, r3, g3, b3, x3, y3, z3, r4, g4, b4, \ + x4, y4, z4, r5, g5, b5, x5, y5, z5) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, \ + { { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } }, \ + { { { r3, g3, b3 }, 0, { r3, g3, b3 }, 0, { x3, y3, z3 }, 0 } }, \ + { { { r4, g4, b4 }, 0, { r4, g4, b4 }, 0, { x4, y4, z4 }, 0 } }, { \ + { { r5, g5, b5 }, 0, { r5, g5, b5 }, 0, { x5, y5, z5 }, 0 } \ + } \ + } \ + } -#define gdSPDefLights1(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }} \ - } \ - } +#define gdSPDefLights6(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2, r3, g3, b3, x3, y3, z3, r4, g4, b4, \ + x4, y4, z4, r5, g5, b5, x5, y5, z5, r6, g6, b6, x6, y6, z6) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, \ + { { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } }, \ + { { { r3, g3, b3 }, 0, { r3, g3, b3 }, 0, { x3, y3, z3 }, 0 } }, \ + { { { r4, g4, b4 }, 0, { r4, g4, b4 }, 0, { x4, y4, z4 }, 0 } }, \ + { { { r5, g5, b5 }, 0, { r5, g5, b5 }, 0, { x5, y5, z5 }, 0 } }, { \ + { { r6, g6, b6 }, 0, { r6, g6, b6 }, 0, { x6, y6, z6 }, 0 } \ + } \ + } \ + } -#define gdSPDefLights2(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }} \ - } \ - } +#define gdSPDefLights7(ar, ag, ab, r1, g1, b1, x1, y1, z1, r2, g2, b2, x2, y2, z2, r3, g3, b3, x3, y3, z3, r4, g4, b4, \ + x4, y4, z4, r5, g5, b5, x5, y5, z5, r6, g6, b6, x6, y6, z6, r7, g7, b7, x7, y7, z7) \ + { \ + { { { ar, ag, ab }, 0, { ar, ag, ab }, 0 } }, { \ + { { { r1, g1, b1 }, 0, { r1, g1, b1 }, 0, { x1, y1, z1 }, 0 } }, \ + { { { r2, g2, b2 }, 0, { r2, g2, b2 }, 0, { x2, y2, z2 }, 0 } }, \ + { { { r3, g3, b3 }, 0, { r3, g3, b3 }, 0, { x3, y3, z3 }, 0 } }, \ + { { { r4, g4, b4 }, 0, { r4, g4, b4 }, 0, { x4, y4, z4 }, 0 } }, \ + { { { r5, g5, b5 }, 0, { r5, g5, b5 }, 0, { x5, y5, z5 }, 0 } }, \ + { { { r6, g6, b6 }, 0, { r6, g6, b6 }, 0, { x6, y6, z6 }, 0 } }, { \ + { { r7, g7, b7 }, 0, { r7, g7, b7 }, 0, { x7, y7, z7 }, 0 } \ + } \ + } \ + } -#define gdSPDefLights3(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2, \ - r3,g3,b3, \ - x3,y3,z3) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }}, \ - {{ \ - { r3, g3, b3 }, 0, \ - { r3, g3, b3 }, 0, \ - { x3, y3, z3 }, 0 \ - }} \ - } \ - } - -#define gdSPDefLights4(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2, \ - r3,g3,b3, \ - x3,y3,z3, \ - r4,g4,b4, \ - x4,y4,z4) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }}, \ - {{ \ - { r3, g3, b3 }, 0, \ - { r3, g3, b3 }, 0, \ - { x3, y3, z3 }, 0 \ - }}, \ - {{ \ - { r4, g4, b4 }, 0, \ - { r4, g4, b4 }, 0, \ - { x4, y4, z4 }, 0 \ - }} \ - } \ - } - -#define gdSPDefLights5(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2, \ - r3,g3,b3, \ - x3,y3,z3, \ - r4,g4,b4, \ - x4,y4,z4, \ - r5,g5,b5, \ - x5,y5,z5) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }}, \ - {{ \ - { r3, g3, b3 }, 0, \ - { r3, g3, b3 }, 0, \ - { x3, y3, z3 }, 0 \ - }}, \ - {{ \ - { r4, g4, b4 }, 0, \ - { r4, g4, b4 }, 0, \ - { x4, y4, z4 }, 0 \ - }}, \ - {{ \ - { r5, g5, b5 }, 0, \ - { r5, g5, b5 }, 0, \ - { x5, y5, z5 }, 0 \ - }} \ - } \ - } - -#define gdSPDefLights6(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2, \ - r3,g3,b3, \ - x3,y3,z3, \ - r4,g4,b4, \ - x4,y4,z4, \ - r5,g5,b5, \ - x5,y5,z5, \ - r6,g6,b6, \ - x6,y6,z6) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }}, \ - {{ \ - { r3, g3, b3 }, 0, \ - { r3, g3, b3 }, 0, \ - { x3, y3, z3 }, 0 \ - }}, \ - {{ \ - { r4, g4, b4 }, 0, \ - { r4, g4, b4 }, 0, \ - { x4, y4, z4 }, 0 \ - }}, \ - {{ \ - { r5, g5, b5 }, 0, \ - { r5, g5, b5 }, 0, \ - { x5, y5, z5 }, 0 \ - }}, \ - {{ \ - { r6, g6, b6 }, 0, \ - { r6, g6, b6 }, 0, \ - { x6, y6, z6 }, 0 \ - }} \ - } \ - } - -#define gdSPDefLights7(ar,ag,ab, \ - r1,g1,b1, \ - x1,y1,z1, \ - r2,g2,b2, \ - x2,y2,z2, \ - r3,g3,b3, \ - x3,y3,z3, \ - r4,g4,b4, \ - x4,y4,z4, \ - r5,g5,b5, \ - x5,y5,z5, \ - r6,g6,b6, \ - x6,y6,z6, \ - r7,g7,b7, \ - x7,y7,z7) \ - { \ - {{ \ - { ar, ag, ab }, 0, \ - { ar, ag, ab }, 0 \ - }}, \ - { \ - {{ \ - { r1, g1, b1 }, 0, \ - { r1, g1, b1 }, 0, \ - { x1, y1, z1 }, 0 \ - }}, \ - {{ \ - { r2, g2, b2 }, 0, \ - { r2, g2, b2 }, 0, \ - { x2, y2, z2 }, 0 \ - }}, \ - {{ \ - { r3, g3, b3 }, 0, \ - { r3, g3, b3 }, 0, \ - { x3, y3, z3 }, 0 \ - }}, \ - {{ \ - { r4, g4, b4 }, 0, \ - { r4, g4, b4 }, 0, \ - { x4, y4, z4 }, 0 \ - }}, \ - {{ \ - { r5, g5, b5 }, 0, \ - { r5, g5, b5 }, 0, \ - { x5, y5, z5 }, 0 \ - }}, \ - {{ \ - { r6, g6, b6 }, 0, \ - { r6, g6, b6 }, 0, \ - { x6, y6, z6 }, 0 \ - }}, \ - {{ \ - { r7, g7, b7 }, 0, \ - { r7, g7, b7 }, 0, \ - { x7, y7, z7 }, 0 \ - }} \ - } \ - } - -#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \ - {{ \ - {{ \ - { 0, 0, 0 }, 0, \ - { 0, 0, 0 }, 0, \ - { rightx, righty, rightz }, 0 \ - }}, \ - {{ \ - { 0, 0x80, 0 }, 0, \ - { 0, 0x80, 0 }, 0, \ - { upx, upy, upz }, 0 \ - }} \ - }} - -#define qs1616(e) ((s32)((e) * 0x00010000)) - -#define IPART(x) ((qs1616(x) >> 16) & 0xFFFF) -#define FPART(x) (qs1616(x) & 0xFFFF) - -#define gdSPDefMtx( \ - xx, yx, zx, wx, \ - xy, yy, zy, wy, \ - xz, yz, zz, wz, \ - xw, yw, zw, ww) \ - {{ \ - (IPART(xx) << 0x10) | IPART(xy), \ - (IPART(xz) << 0x10) | IPART(xw), \ - (IPART(yx) << 0x10) | IPART(yy), \ - (IPART(yz) << 0x10) | IPART(yw), \ - (IPART(zx) << 0x10) | IPART(zy), \ - (IPART(zz) << 0x10) | IPART(zw), \ - (IPART(wx) << 0x10) | IPART(wy), \ - (IPART(wz) << 0x10) | IPART(ww), \ - (FPART(xx) << 0x10) | FPART(xy), \ - (FPART(xz) << 0x10) | FPART(xw), \ - (FPART(yx) << 0x10) | FPART(yy), \ - (FPART(yz) << 0x10) | FPART(yw), \ - (FPART(zx) << 0x10) | FPART(zy), \ - (FPART(zz) << 0x10) | FPART(zw), \ - (FPART(wx) << 0x10) | FPART(wy), \ - (FPART(wz) << 0x10) | FPART(ww), \ - }} +#define gdSPDefLookAt(rightx, righty, rightz, upx, upy, upz) \ + { \ + { \ + { { { 0, 0, 0 }, 0, { 0, 0, 0 }, 0, { rightx, righty, rightz }, 0 } }, { \ + { { 0, 0x80, 0 }, 0, { 0, 0x80, 0 }, 0, { upx, upy, upz }, 0 } \ + } \ + } \ + } /* * Graphics DMA Packet */ typedef struct { - int cmd:8; - unsigned int par:8; - unsigned int len:16; - unsigned int addr; + int cmd : 8; + unsigned int par : 8; + unsigned int len : 16; + unsigned int addr; } Gdma; /* * Graphics Immediate Mode Packet types */ typedef struct { - int cmd:8; - int pad:24; - Tri tri; + int cmd : 8; + int pad : 24; + Tri tri; } Gtri; typedef struct { - int cmd:8; - int pad1:24; - int pad2:24; - unsigned char param:8; + int cmd : 8; + int pad1 : 24; + int pad2 : 24; + unsigned char param : 8; } Gpopmtx; /* * typedef struct { - * int cmd:8; - * int pad0:24; - * int pad1:4; - * int number:4; - * int base:24; + * int cmd:8; + * int pad0:24; + * int pad1:4; + * int number:4; + * int base:24; * } Gsegment; */ typedef struct { - int cmd:8; - int pad0:8; - int mw_index:8; - int number:8; - int pad1:8; - int base:24; + int cmd : 8; + int pad0 : 8; + int mw_index : 8; + int number : 8; + int pad1 : 8; + int base : 24; } Gsegment; typedef struct { - int cmd:8; - int pad0:8; - int sft:8; - int len:8; - unsigned int data:32; + int cmd : 8; + int pad0 : 8; + int sft : 8; + int len : 8; + unsigned int data : 32; } GsetothermodeL; typedef struct { - int cmd:8; - int pad0:8; - int sft:8; - int len:8; - unsigned int data:32; + int cmd : 8; + int pad0 : 8; + int sft : 8; + int len : 8; + unsigned int data : 32; } GsetothermodeH; typedef struct { - unsigned char cmd; - unsigned char lodscale; - unsigned char tile; - unsigned char on; - unsigned short s; - unsigned short t; + unsigned char cmd; + unsigned char lodscale; + unsigned char tile; + unsigned char on; + unsigned short s; + unsigned short t; } Gtexture; typedef struct { - int cmd:8; - int pad:24; - Tri line; + int cmd : 8; + int pad : 24; + Tri line; } Gline3D; typedef struct { - int cmd:8; - int pad1:24; - short int pad2; - short int scale; + int cmd : 8; + int pad1 : 24; + short int pad2; + short int scale; } Gperspnorm; - /* * RDP Packet types */ typedef struct { - int cmd:8; - unsigned int fmt:3; - unsigned int siz:2; - unsigned int pad:7; - unsigned int wd:12; /* really only 10 bits, extra */ - unsigned int dram; /* to account for 1024 */ + int cmd : 8; + unsigned int fmt : 3; + unsigned int siz : 2; + unsigned int pad : 7; + unsigned int wd : 12; /* really only 10 bits, extra */ + unsigned int dram; /* to account for 1024 */ } Gsetimg; typedef struct { - int cmd:8; - unsigned int muxs0:24; - unsigned int muxs1:32; + int cmd : 8; + unsigned int muxs0 : 24; + unsigned int muxs1 : 32; } Gsetcombine; typedef struct { - int cmd:8; - unsigned char pad; - unsigned char prim_min_level; - unsigned char prim_level; - unsigned long color; + int cmd : 8; + unsigned char pad; + unsigned char prim_min_level; + unsigned char prim_level; + unsigned long color; } Gsetcolor; typedef struct { - int cmd:8; - int x0:10; - int x0frac:2; - int y0:10; - int y0frac:2; - unsigned int pad:8; - int x1:10; - int x1frac:2; - int y1:10; - int y1frac:2; + int cmd : 8; + int x0 : 10; + int x0frac : 2; + int y0 : 10; + int y0frac : 2; + unsigned int pad : 8; + int x1 : 10; + int x1frac : 2; + int y1 : 10; + int y1frac : 2; } Gfillrect; typedef struct { - int cmd:8; - unsigned int fmt:3; - unsigned int siz:2; - unsigned int pad0:1; - unsigned int line:9; - unsigned int tmem:9; - unsigned int pad1:5; - unsigned int tile:3; - unsigned int palette:4; - unsigned int ct:1; - unsigned int mt:1; - unsigned int maskt:4; - unsigned int shiftt:4; - unsigned int cs:1; - unsigned int ms:1; - unsigned int masks:4; - unsigned int shifts:4; + int cmd : 8; + unsigned int fmt : 3; + unsigned int siz : 2; + unsigned int pad0 : 1; + unsigned int line : 9; + unsigned int tmem : 9; + unsigned int pad1 : 5; + unsigned int tile : 3; + unsigned int palette : 4; + unsigned int ct : 1; + unsigned int mt : 1; + unsigned int maskt : 4; + unsigned int shiftt : 4; + unsigned int cs : 1; + unsigned int ms : 1; + unsigned int masks : 4; + unsigned int shifts : 4; } Gsettile; typedef struct { - int cmd:8; - unsigned int sl:12; - unsigned int tl:12; - int pad:5; - unsigned int tile:3; - unsigned int sh:12; - unsigned int th:12; + int cmd : 8; + unsigned int sl : 12; + unsigned int tl : 12; + int pad : 5; + unsigned int tile : 3; + unsigned int sh : 12; + unsigned int th : 12; } Gloadtile; typedef Gloadtile Gloadblock; @@ -1844,21 +1636,21 @@ typedef Gloadtile Gsettilesize; typedef Gloadtile Gloadtlut; typedef struct { - unsigned int cmd:8; /* command */ - unsigned int xl:12; /* X coordinate of upper left */ - unsigned int yl:12; /* Y coordinate of upper left */ - unsigned int pad1:5; /* Padding */ - unsigned int tile:3; /* Tile descriptor index */ - unsigned int xh:12; /* X coordinate of lower right */ - unsigned int yh:12; /* Y coordinate of lower right */ - unsigned int s:16; /* S texture coord at top left */ - unsigned int t:16; /* T texture coord at top left */ - unsigned int dsdx:16;/* Change in S per change in X */ - unsigned int dtdy:16;/* Change in T per change in Y */ + unsigned int cmd : 8; /* command */ + unsigned int xl : 12; /* X coordinate of upper left */ + unsigned int yl : 12; /* Y coordinate of upper left */ + unsigned int pad1 : 5; /* Padding */ + unsigned int tile : 3; /* Tile descriptor index */ + unsigned int xh : 12; /* X coordinate of lower right */ + unsigned int yh : 12; /* Y coordinate of lower right */ + unsigned int s : 16; /* S texture coord at top left */ + unsigned int t : 16; /* T texture coord at top left */ + unsigned int dsdx : 16; /* Change in S per change in X */ + unsigned int dtdy : 16; /* Change in T per change in Y */ } Gtexrect; -#define MakeTexRect(xh,yh,flip,tile,xl,yl,s,t,dsdx,dtdy) \ - G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy +#define MakeTexRect(xh, yh, flip, tile, xl, yl, s, t, dsdx, dtdy) \ + G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy /* * Textured rectangles are 128 bits not 64 bits @@ -1874,34 +1666,43 @@ typedef struct { * Generic Gfx Packet */ typedef struct { - unsigned int w0; - unsigned int w1; + uintptr_t w0; + uintptr_t w1; + + // unsigned long long w0; + // unsigned long long w1; } Gwords; +#ifdef __cplusplus +static_assert(sizeof(Gwords) == 2 * sizeof(void*), "Display list size is bad"); +#endif + /* * This union is the fundamental type of the display list. * It is, by law, exactly 64 bits in size. */ typedef union { - Gwords words; - Gdma dma; - Gtri tri; - Gline3D line; - Gpopmtx popmtx; - Gsegment segment; - GsetothermodeH setothermodeH; - GsetothermodeL setothermodeL; - Gtexture texture; - Gperspnorm perspnorm; - Gsetimg setimg; - Gsetcombine setcombine; - Gsetcolor setcolor; - Gfillrect fillrect; /* use for setscissor also */ - Gsettile settile; - Gloadtile loadtile; /* use for loadblock also, th is dxt */ - Gsettilesize settilesize; - Gloadtlut loadtlut; - long long int force_structure_alignment; + Gwords words; +#if !defined(F3D_OLD) && IS_BIG_ENDIAN && !IS_64_BIT + Gdma dma; + Gtri tri; + Gline3D line; + Gpopmtx popmtx; + Gsegment segment; + GsetothermodeH setothermodeH; + GsetothermodeL setothermodeL; + Gtexture texture; + Gperspnorm perspnorm; + Gsetimg setimg; + Gsetcombine setcombine; + Gsetcolor setcolor; + Gfillrect fillrect; /* use for setscissor also */ + Gsettile settile; + Gloadtile loadtile; /* use for loadblock also, th is dxt */ + Gsettilesize settilesize; + Gloadtlut loadtlut; +#endif + long long int force_structure_alignment; } Gfx; /* @@ -1911,63 +1712,53 @@ typedef union { /* * DMA macros */ -#define gDma0p(pkt, c, s, l) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ - _g->words.w1 = (unsigned int)(s); \ -} +#define gDma0p(pkt, c, s, l) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ + _g->words.w1 = (uintptr_t)(s); \ + }) -#define gsDma0p(c, s, l) \ -{ \ - _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (unsigned int)(s) \ -} +#define gsDma0p(c, s, l) \ + { _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (uintptr_t)(s) } -#define gDma1p(pkt, c, s, l, p) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ - _SHIFTL((l), 0, 16)); \ - _g->words.w1 = (unsigned int)(s); \ -}) +#define gDma1p(pkt, c, s, l, p) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | _SHIFTL((l), 0, 16)); \ + _g->words.w1 = (uintptr_t)(s); \ + }) -#define gsDma1p(c, s, l, p) \ -{ \ - (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ - _SHIFTL((l), 0, 16)), \ - (unsigned int)(s) \ -} +#define gsDma1p(c, s, l, p) \ + { (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | _SHIFTL((l), 0, 16)), (uintptr_t)(s) } -#define gDma2p(pkt, c, adrs, len, idx, ofs) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ - _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)); \ - _g->words.w1 = (unsigned int)(adrs); \ -}) -#define gsDma2p(c, adrs, len, idx, ofs) \ -{ \ - (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ - _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)), \ - (unsigned int)(adrs) \ -} +#define gDma2p(pkt, c, adrs, len, idx, ofs) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = \ + (_SHIFTL((c), 24, 8) | _SHIFTL(((len)-1) / 8, 19, 5) | _SHIFTL((ofs) / 8, 8, 8) | _SHIFTL((idx), 0, 8)); \ + _g->words.w1 = (uintptr_t)(adrs); \ + }) +#define gsDma2p(c, adrs, len, idx, ofs) \ + { \ + (_SHIFTL((c), 24, 8) | _SHIFTL(((len)-1) / 8, 19, 5) | _SHIFTL((ofs) / 8, 8, 8) | _SHIFTL((idx), 0, 8)), \ + (uintptr_t)(adrs) \ + } -#define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) -#define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) +#define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) +#define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) -#ifdef F3DEX_GBI_2 -# define gSPMatrix(pkt, m, p) \ - gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) -# define gsSPMatrix(m, p) \ - gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) -#else /* F3DEX_GBI_2 */ -# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) -# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define gSPMatrix(pkt, m, p) gDma2p((pkt), G_MTX, (m), sizeof(Mtx), (p) ^ G_MTX_PUSH, 0) +#define gsSPMatrix(m, p) gsDma2p(G_MTX, (m), sizeof(Mtx), (p) ^ G_MTX_PUSH, 0) +#else /* F3DEX_GBI_2 */ +#define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) +#define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) +#endif /* F3DEX_GBI_2 */ -#if defined(F3DEX_GBI_2) +#if defined(F3DEX_GBI_2) /* * F3DEX_GBI_2: G_VTX GBI format was changed. * @@ -1977,19 +1768,16 @@ _DW({ \ * | |seg| address | * +-+---+-----------------------------+ */ -# define gSPVertex(pkt, v, n, v0) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = \ - _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ - _g->words.w1 = (unsigned int)(v); \ -}) -# define gsSPVertex(v, n, v0) \ -{ \ - (_SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7)), \ - (unsigned int)(v) \ -} -#elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +#define __gSPVertex(pkt, v, n, v0) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_VTX, 24, 8) | _SHIFTL((n), 12, 8) | _SHIFTL((v0) + (n), 1, 7); \ + _g->words.w1 = (uintptr_t)(v); \ + }) +#define gsSPVertex(v, n, v0) \ + { (_SHIFTL(G_VTX, 24, 8) | _SHIFTL((n), 12, 8) | _SHIFTL((v0) + (n), 1, 7)), (uintptr_t)(v) } + +#elif (defined(F3DEX_GBI) || defined(F3DLP_GBI)) /* * F3DEX_GBI: G_VTX GBI format was changed to support 64 vertice. * @@ -1999,230 +1787,185 @@ _DW({ \ * | |seg| address | * +-+---+-----------------------------+ */ -# define gSPVertex(pkt, v, n, v0) \ - gDma1p((pkt),G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) -# define gsSPVertex(v, n, v0) \ - gsDma1p(G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +#define gSPVertex(pkt, v, n, v0) gDma1p((pkt), G_VTX, (v), ((n) << 10) | (sizeof(Vtx) * (n)-1), (v0)*2) +#define gsSPVertex(v, n, v0) gsDma1p(G_VTX, (v), ((n) << 10) | (sizeof(Vtx) * (n)-1), (v0)*2) #else -# define gSPVertex(pkt, v, n, v0) \ - gDma1p(pkt, G_VTX, v, sizeof(Vtx)*(n),((n)-1)<<4|(v0)) -# define gsSPVertex(v, n, v0) \ - gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0)) +#define gSPVertex(pkt, v, n, v0) gDma1p(pkt, G_VTX, v, sizeof(Vtx) * (n), ((n)-1) << 4 | (v0)) +#define gsSPVertex(v, n, v0) gsDma1p(G_VTX, v, sizeof(Vtx) * (n), ((n)-1) << 4 | (v0)) #endif +#ifdef F3DEX_GBI_2 +#define gSPViewport(pkt, v) gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +#define gsSPViewport(v) gsDma2p(G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +#else /* F3DEX_GBI_2 */ +#define gSPViewport(pkt, v) gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +#define gsSPViewport(v) gsDma1p(G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +#endif /* F3DEX_GBI_2 */ -#ifdef F3DEX_GBI_2 -# define gSPViewport(pkt, v) \ - gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) -# define gsSPViewport(v) \ - gsDma2p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) -#else /* F3DEX_GBI_2 */ -# define gSPViewport(pkt,v) \ - gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) -# define gsSPViewport(v) \ - gsDma1p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) -#endif /* F3DEX_GBI_2 */ +#define gsSPPushCD(pkt, dl) gDma1p(pkt, G_PUSHCD, dl, 0, G_DL_PUSH) +#define __gSPDisplayList(pkt, dl) gDma1p(pkt, G_DL, dl, 0, G_DL_PUSH) +#define gsSPDisplayList(dl) gsDma1p(G_DL, dl, 0, G_DL_PUSH) +#define gsSPDisplayListOTRHash(dl) gsDma1p(G_DL_OTR_HASH, dl, 0, G_DL_PUSH) +#define gsSPDisplayListOTRFilePath(dl) gsDma1p(G_DL_OTR_FILEPATH, dl, 0, G_DL_PUSH) -#define gSPDisplayList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_PUSH) -#define gsSPDisplayList( dl) gsDma1p( G_DL,dl,0,G_DL_PUSH) +#define gSPBranchList(pkt, dl) gDma1p(pkt, G_DL, dl, 0, G_DL_NOPUSH) +#define gsSPBranchList(dl) gsDma1p(G_DL, dl, 0, G_DL_NOPUSH) +#define gsSPBranchListOTRHash(dl) gsDma1p(G_DL_OTR_HASH, dl, 0, G_DL_NOPUSH) +#define gsSPBranchListOTRFilePath(dl) gsDma1p(G_DL_OTR_FILEPATH, dl, 0, G_DL_NOPUSH) -#define gSPBranchList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_NOPUSH) -#define gsSPBranchList( dl) gsDma1p( G_DL,dl,0,G_DL_NOPUSH) - -#define gSPSprite2DBase(pkt, s) gDma1p(pkt, G_SPRITE2D_BASE, s, sizeof(uSprite), 0) -#define gsSPSprite2DBase(s) gsDma1p(G_SPRITE2D_BASE, s, sizeof(uSprite), 0) +#define gSPSprite2DBase(pkt, s) gDma1p(pkt, G_SPRITE2D_BASE, s, sizeof(uSprite), 0) +#define gsSPSprite2DBase(s) gsDma1p(G_SPRITE2D_BASE, s, sizeof(uSprite), 0) /* * RSP short command (no DMA required) macros */ -#define gImmp0(pkt, c) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ -} +#define gImmp0(pkt, c) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + }) -#define gsImmp0(c) \ -{ \ - _SHIFTL((c), 24, 8) \ -} +#define gsImmp0(c) \ + { _SHIFTL((c), 24, 8) } -#define gImmp1(pkt, c, p0) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = (unsigned int)(p0); \ -}) +#define gImmp1(pkt, c, p0) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (uintptr_t)(p0); \ + }) -#define gsImmp1(c, p0) \ -{ \ - _SHIFTL((c), 24, 8), (unsigned int)(p0) \ -} +#define gsImmp1(c, p0) \ + { _SHIFTL((c), 24, 8), (uintptr_t)(p0) } -#define gImmp2(pkt, c, p0, p1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8); \ -} +#define gImmp2(pkt, c, p0, p1) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8); \ + }) -#define gsImmp2(c, p0, p1) \ -{ \ - _SHIFTL((c), 24, 8), _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8)\ -} +#define gsImmp2(c, p0, p1) \ + { _SHIFTL((c), 24, 8), _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) } -#define gImmp3(pkt, c, p0, p1, p2) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | \ - _SHIFTL((p2), 0, 8)); \ -} +#define gImmp3(pkt, c, p0, p1, p2) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8)); \ + }) -#define gsImmp3(c, p0, p1, p2) \ -{ \ - _SHIFTL((c), 24, 8), (_SHIFTL((p0), 16, 16) | \ - _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8))\ -} +#define gsImmp3(c, p0, p1, p2) \ + { _SHIFTL((c), 24, 8), (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8)) } -#define gImmp21(pkt, c, p0, p1, dat) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | \ - _SHIFTL((p1), 0, 8)); \ - _g->words.w1 = (unsigned int) (dat); \ -}) +#define gImmp21(pkt, c, p0, p1, dat) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8)); \ + _g->words.w1 = (uintptr_t)(dat); \ + }) -#define gsImmp21(c, p0, p1, dat) \ -{ \ - _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8),\ - (unsigned int) (dat) \ -} +#define gsImmp21(c, p0, p1, dat) \ + { _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8), (uintptr_t)(dat) } -#ifdef F3DEX_GBI_2 -#define gMoveWd(pkt, index, offset, data) \ - gDma1p((pkt), G_MOVEWORD, data, offset, index) -#define gsMoveWd( index, offset, data) \ - gsDma1p( G_MOVEWORD, data, offset, index) -#else /* F3DEX_GBI_2 */ -#define gMoveWd(pkt, index, offset, data) \ - gImmp21((pkt), G_MOVEWORD, offset, index, data) -#define gsMoveWd( index, offset, data) \ - gsImmp21( G_MOVEWORD, offset, index, data) -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define gMoveWd(pkt, index, offset, data) gDma1p((pkt), G_MOVEWORD, data, offset, index) +#define gsMoveWd(index, offset, data) gsDma1p(G_MOVEWORD, data, offset, index) +#else /* F3DEX_GBI_2 */ +#define gMoveWd(pkt, index, offset, data) gImmp21((pkt), G_MOVEWORD, offset, index, data) +#define gsMoveWd(index, offset, data) gsImmp21(G_MOVEWORD, offset, index, data) +#endif /* F3DEX_GBI_2 */ /* Sprite immediate macros, there is also a sprite dma macro above */ -#define gSPSprite2DScaleFlip(pkt, sx, sy, fx, fy) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ - _SHIFTL((fx), 8, 8) | \ - _SHIFTL((fy), 0, 8)); \ - _g->words.w1 = (_SHIFTL((sx), 16, 16) | \ - _SHIFTL((sy), 0, 16)); \ -} +#define gSPSprite2DScaleFlip(pkt, sx, sy, fx, fy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | _SHIFTL((fx), 8, 8) | _SHIFTL((fy), 0, 8)); \ + _g->words.w1 = (_SHIFTL((sx), 16, 16) | _SHIFTL((sy), 0, 16)); \ + }) -#define gsSPSprite2DScaleFlip(sx, sy, fx, fy) \ -{ \ - (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ - _SHIFTL((fx), 8, 8) | \ - _SHIFTL((fy), 0, 8)), \ - (_SHIFTL((sx), 16, 16) | \ - _SHIFTL((sy), 0, 16)) \ -} +#define gsSPSprite2DScaleFlip(sx, sy, fx, fy) \ + { \ + (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | _SHIFTL((fx), 8, 8) | _SHIFTL((fy), 0, 8)), \ + (_SHIFTL((sx), 16, 16) | _SHIFTL((sy), 0, 16)) \ + } -#define gSPSprite2DDraw(pkt, px, py) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)); \ - _g->words.w1 = (_SHIFTL((px), 16, 16) | \ - _SHIFTL((py), 0, 16)); \ -} - -#define gsSPSprite2DDraw(px, py) \ -{ \ - (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)), \ - (_SHIFTL((px), 16, 16) | \ - _SHIFTL((py), 0, 16)) \ -} +#define gSPSprite2DDraw(pkt, px, py) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)); \ + _g->words.w1 = (_SHIFTL((px), 16, 16) | _SHIFTL((py), 0, 16)); \ + }) +#define gsSPSprite2DDraw(px, py) \ + { (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)), (_SHIFTL((px), 16, 16) | _SHIFTL((py), 0, 16)) } /* * Note: the SP1Triangle() and line macros multiply the vertex indices * by 10, this is an optimization for the microcode. */ -#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) -# define __gsSP1Triangle_w1(v0, v1, v2) \ - (_SHIFTL((v0)*2,16,8)|_SHIFTL((v1)*2,8,8)|_SHIFTL((v2)*2,0,8)) -# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v0): \ - __gsSP1Triangle_w1(v2, v0, v1)) -# define __gsSPLine3D_w1(v0, v1, wd) \ - (_SHIFTL((v0)*2,16,8)|_SHIFT((v1)*2,8,8)|_SHIFT((wd),0,8)) -# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ - (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd): \ - __gsSPLine3D_w1(v1, v0, wd)) -# define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ - __gsSP1Triangle_w1(v3, v0, v1)) -# define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ - __gsSP1Triangle_w1(v3, v1, v2)) +#if (defined(F3DLP_GBI) || defined(F3DEX_GBI)) +#define __gsSP1Triangle_w1(v0, v1, v2) (_SHIFTL((v0)*2, 16, 8) | _SHIFTL((v1)*2, 8, 8) | _SHIFTL((v2)*2, 0, 8)) +#define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2) \ + : ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v0) \ + : __gsSP1Triangle_w1(v2, v0, v1)) +#define __gsSPLine3D_w1(v0, v1, wd) (_SHIFTL((v0)*2, 16, 8) | _SHIFT((v1)*2, 8, 8) | _SHIFT((wd), 0, 8)) +#define __gsSPLine3D_w1f(v0, v1, wd, flag) (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd) : __gsSPLine3D_w1(v1, v0, wd)) +#define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2) \ + : ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3) \ + : ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0) \ + : __gsSP1Triangle_w1(v3, v0, v1)) +#define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3) \ + : ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0) \ + : ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1) \ + : __gsSP1Triangle_w1(v3, v1, v2)) #else -# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ - (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ - _SHIFTL((v1)*10, 8,8)|_SHIFTL((v2)*10, 0,8)) -# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ - (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ - _SHIFTL((v1)*10, 8,8)|_SHIFTL((wd), 0,8)) +#define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (_SHIFTL((flag), 24, 8) | _SHIFTL((v0)*10, 16, 8) | _SHIFTL((v1)*10, 8, 8) | _SHIFTL((v2)*10, 0, 8)) +#define __gsSPLine3D_w1f(v0, v1, wd, flag) \ + (_SHIFTL((flag), 24, 8) | _SHIFTL((v0)*10, 16, 8) | _SHIFTL((v1)*10, 8, 8) | _SHIFTL((wd), 0, 8)) #endif -#ifdef F3DEX_GBI_2 +#ifdef F3DEX_GBI_2 /*** *** 1 Triangle ***/ -#define gSP1Triangle(pkt, v0, v1, v2, flag) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_TRI1, 24, 8)| \ - __gsSP1Triangle_w1f(v0, v1, v2, flag); \ - _g->words.w1 = 0; \ -}) -#define gsSP1Triangle(v0, v1, v2, flag) \ -{ \ - _SHIFTL(G_TRI1, 24, 8)|__gsSP1Triangle_w1f(v0, v1, v2, flag), \ - 0 \ -} +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8) | __gsSP1Triangle_w1f(v0, v1, v2, flag); \ + _g->words.w1 = 0; \ + }) +#define gsSP1Triangle(v0, v1, v2, flag) \ + { _SHIFTL(G_TRI1, 24, 8) | __gsSP1Triangle_w1f(v0, v1, v2, flag), 0 } + +#define gsSP1TriangleOTR(v0, v1, v2, flag) \ + { _SHIFTL(G_TRI1_OTR, 24, 8) | __gsSP1Triangle_w1f(v0, v1, v2, flag), 0 } /*** *** Line ***/ -#define gSPLine3D(pkt, v0, v1, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ - __gsSPLine3D_w1f(v0, v1, 0, flag); \ - _g->words.w1 = 0; \ -} -#define gsSPLine3D(v0, v1, flag) \ -{ \ - _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, 0, flag), \ - 0 \ -} +#define gSPLine3D(pkt, v0, v1, flag) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8) | __gsSPLine3D_w1f(v0, v1, 0, flag); \ + _g->words.w1 = 0; \ + }) +#define gsSPLine3D(v0, v1, flag) \ + { _SHIFTL(G_LINE3D, 24, 8) | __gsSPLine3D_w1f(v0, v1, 0, flag), 0 } /*** *** LineW @@ -2233,71 +1976,59 @@ _DW({ \ * half-pixel units, so a width of 1 translates to (.5 + 1.5) or * a 2.0 pixels wide line. */ -#define gSPLineW3D(pkt, v0, v1, wd, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ - __gsSPLine3D_w1f(v0, v1, wd, flag); \ - _g->words.w1 = 0; \ -} -#define gsSPLineW3D(v0, v1, wd, flag) \ -{ \ - _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, wd, flag), \ - 0 \ -} +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8) | __gsSPLine3D_w1f(v0, v1, wd, flag); \ + _g->words.w1 = 0; \ + }) +#define gsSPLineW3D(v0, v1, wd, flag) \ + { _SHIFTL(G_LINE3D, 24, 8) | __gsSPLine3D_w1f(v0, v1, wd, flag), 0 } /*** *** 1 Quadrangle ***/ -#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ - _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ -}) +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8) | __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ + }) -#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ -{ \ - (_SHIFTL(G_QUAD, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ - __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ -} -#else /* F3DEX_GBI_2 */ +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ + { \ + (_SHIFTL(G_QUAD, 24, 8) | __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + } +#else /* F3DEX_GBI_2 */ /*** *** 1 Triangle ***/ -#define gSP1Triangle(pkt, v0, v1, v2, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ - _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ -} -#define gsSP1Triangle(v0, v1, v2, flag) \ -{ \ - _SHIFTL(G_TRI1, 24, 8), \ - __gsSP1Triangle_w1f(v0, v1, v2, flag) \ -} +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ + _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ + } +#define gsSP1Triangle(v0, v1, v2, flag) \ + { _SHIFTL(G_TRI1, 24, 8), __gsSP1Triangle_w1f(v0, v1, v2, flag) } /*** *** Line ***/ -#define gSPLine3D(pkt, v0, v1, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ - _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ -} -#define gsSPLine3D(v0, v1, flag) \ -{ \ - _SHIFTL(G_LINE3D, 24, 8), \ - __gsSPLine3D_w1f(v0, v1, 0, flag) \ -} +#define gSPLine3D(pkt, v0, v1, flag) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ + } +#define gsSPLine3D(v0, v1, flag) \ + { _SHIFTL(G_LINE3D, 24, 8), __gsSPLine3D_w1f(v0, v1, 0, flag) } /*** *** LineW @@ -2308,130 +2039,108 @@ _DW({ \ * half-pixel units, so a width of 1 translates to (.5 + 1.5) or * a 2.0 pixels wide line. */ -#define gSPLineW3D(pkt, v0, v1, wd, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ - _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ -} -#define gsSPLineW3D(v0, v1, wd, flag) \ -{ \ - _SHIFTL(G_LINE3D, 24, 8), \ - __gsSPLine3D_w1f(v0, v1, wd, flag) \ -} +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ + } +#define gsSPLineW3D(v0, v1, wd, flag) \ + { _SHIFTL(G_LINE3D, 24, 8), __gsSPLine3D_w1f(v0, v1, wd, flag) } /*** *** 1 Quadrangle ***/ -#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ - _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ -} +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8) | __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ + } -#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ -{ \ - (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ - __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ -} -#endif /* F3DEX_GBI_2 */ +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ + { \ + (_SHIFTL(G_TRI2, 24, 8) | __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + } +#endif /* F3DEX_GBI_2 */ -#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) +#if (defined(F3DLP_GBI) || defined(F3DEX_GBI)) /*** *** 2 Triangles ***/ -#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Triangle_w1f(v00, v01, v02, flag0)); \ - _g->words.w1 = __gsSP1Triangle_w1f(v10, v11, v12, flag1); \ -}) +#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8) | __gsSP1Triangle_w1f(v00, v01, v02, flag0)); \ + _g->words.w1 = __gsSP1Triangle_w1f(v10, v11, v12, flag1); \ + }) -#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ -{ \ - (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Triangle_w1f(v00, v01, v02, flag0)), \ - __gsSP1Triangle_w1f(v10, v11, v12, flag1) \ -} +#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ + { (_SHIFTL(G_TRI2, 24, 8) | __gsSP1Triangle_w1f(v00, v01, v02, flag0)), __gsSP1Triangle_w1f(v10, v11, v12, flag1) } -#endif /* F3DEX_GBI/F3DLP_GBI */ +#endif /* F3DEX_GBI/F3DLP_GBI */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -#define gSPCullDisplayList(pkt,vstart,vend) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ - _SHIFTL((vstart)*2, 0, 16); \ - _g->words.w1 = _SHIFTL((vend)*2, 0, 16); \ -} +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) +#define gSPCullDisplayList(pkt, vstart, vend) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16); \ + _g->words.w1 = _SHIFTL((vend)*2, 0, 16); \ + }) -#define gsSPCullDisplayList(vstart,vend) \ -{ \ - _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16), \ - _SHIFTL((vend)*2, 0, 16) \ -} +#define gsSPCullDisplayList(vstart, vend) \ + { _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16), _SHIFTL((vend)*2, 0, 16) } #else -#define gSPCullDisplayList(pkt,vstart,vend) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ - ((0x0FF& (vstart))*40); \ - _g->words.w1 = (unsigned int)((0x0F & ((vend)+1))*40); \ -} +#define gSPCullDisplayList(pkt, vstart, vend) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | ((0x0f & (vstart)) * 40); \ + _g->words.w1 = (unsigned int)((0x0f & ((vend) + 1)) * 40); \ + } -#define gsSPCullDisplayList(vstart,vend) \ -{ \ - _SHIFTL(G_CULLDL, 24, 8) | ((0x0F & (vstart))*40), \ - ((0x0F & ((vend)+1))*40) \ -} +#define gsSPCullDisplayList(vstart, vend) \ + { _SHIFTL(G_CULLDL, 24, 8) | ((0x0f & (vstart)) * 40), ((0x0f & ((vend) + 1)) * 40) } #endif -#define gSPSegment(pkt, segment, base) \ - gMoveWd(pkt, G_MW_SEGMENT, (segment)*4, base) -#define gsSPSegment(segment, base) \ - gsMoveWd( G_MW_SEGMENT, (segment)*4, base) +#define __gSPSegment(pkt, segment, base) gMoveWd(pkt, G_MW_SEGMENT, (segment)*4, base) +#define gsSPSegment(segment, base) gsMoveWd(G_MW_SEGMENT, (segment)*4, base) /* * Clipping Macros */ -#define FR_NEG_FRUSTRATIO_1 0x00000001 -#define FR_POS_FRUSTRATIO_1 0x0000FFFF -#define FR_NEG_FRUSTRATIO_2 0x00000002 -#define FR_POS_FRUSTRATIO_2 0x0000FFFE -#define FR_NEG_FRUSTRATIO_3 0x00000003 -#define FR_POS_FRUSTRATIO_3 0x0000FFFD -#define FR_NEG_FRUSTRATIO_4 0x00000004 -#define FR_POS_FRUSTRATIO_4 0x0000FFFC -#define FR_NEG_FRUSTRATIO_5 0x00000005 -#define FR_POS_FRUSTRATIO_5 0x0000FFFB -#define FR_NEG_FRUSTRATIO_6 0x00000006 -#define FR_POS_FRUSTRATIO_6 0x0000FFFA +#define FR_NEG_FRUSTRATIO_1 0x00000001 +#define FR_POS_FRUSTRATIO_1 0x0000ffff +#define FR_NEG_FRUSTRATIO_2 0x00000002 +#define FR_POS_FRUSTRATIO_2 0x0000fffe +#define FR_NEG_FRUSTRATIO_3 0x00000003 +#define FR_POS_FRUSTRATIO_3 0x0000fffd +#define FR_NEG_FRUSTRATIO_4 0x00000004 +#define FR_POS_FRUSTRATIO_4 0x0000fffc +#define FR_NEG_FRUSTRATIO_5 0x00000005 +#define FR_POS_FRUSTRATIO_5 0x0000fffb +#define FR_NEG_FRUSTRATIO_6 0x00000006 +#define FR_POS_FRUSTRATIO_6 0x0000fffa /* * r should be one of: FRUSTRATIO_1, FRUSTRATIO_2, FRUSTRATIO_3, ... FRUSTRATIO_6 */ -#define gSPClipRatio(pkt, r) \ -{ \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r); \ - gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r); \ -} +#define gSPClipRatio(pkt, r) \ + _DW({ \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r); \ + }) -#define gsSPClipRatio(r) \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r), \ - gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r) +#define gsSPClipRatio(r) \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r), gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r), gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r) /* * Insert values into Matrix @@ -2440,16 +2149,12 @@ _DW({ \ * num = new element (32 bit value replacing 2 int or 2 frac matrix * componants */ -#ifdef F3DEX_GBI_2 -#define gSPInsertMatrix(pkt, where, num) \ - ERROR!! gSPInsertMatrix is no longer supported. -#define gsSPInsertMatrix(where, num) \ - ERROR!! gsSPInsertMatrix is no longer supported. +#ifdef F3DEX_GBI_2 +#define gSPInsertMatrix(pkt, where, num) ERROR !!gSPInsertMatrix is no longer supported. +#define gsSPInsertMatrix(where, num) ERROR !!gsSPInsertMatrix is no longer supported. #else -#define gSPInsertMatrix(pkt, where, num) \ - gMoveWd(pkt, G_MW_MATRIX, where, num) -#define gsSPInsertMatrix(where, num) \ - gsMoveWd(G_MW_MATRIX, where, num) +#define gSPInsertMatrix(pkt, where, num) gMoveWd(pkt, G_MW_MATRIX, where, num) +#define gsSPInsertMatrix(where, num) gsMoveWd(G_MW_MATRIX, where, num) #endif /* @@ -2457,29 +2162,28 @@ _DW({ \ * * mptr = pointer to matrix */ -#ifdef F3DEX_GBI_2 -#define gSPForceMatrix(pkt, mptr) \ -{ gDma2p((pkt),G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0); \ - gMoveWd((pkt), G_MW_FORCEMTX,0,0x00010000); \ -} -#define gsSPForceMatrix(mptr) \ - gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \ - gsMoveWd(G_MW_FORCEMTX,0,0x00010000) +#ifdef F3DEX_GBI_2 +#define gSPForceMatrix(pkt, mptr) \ + _DW({ \ + gDma2p((pkt), G_MOVEMEM, (mptr), sizeof(Mtx), G_MV_MATRIX, 0); \ + gMoveWd((pkt), G_MW_FORCEMTX, 0, 0x00010000); \ + }) +#define gsSPForceMatrix(mptr) \ + gsDma2p(G_MOVEMEM, (mptr), sizeof(Mtx), G_MV_MATRIX, 0), gsMoveWd(G_MW_FORCEMTX, 0, 0x00010000) -#else /* F3DEX_GBI_2 */ -#define gSPForceMatrix(pkt, mptr) \ -{ \ - gDma1p(pkt, G_MOVEMEM, mptr, 16, G_MV_MATRIX_1); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3); \ - gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4); \ -} -#define gsSPForceMatrix(mptr) \ - gsDma1p( G_MOVEMEM, mptr, 16, G_MV_MATRIX_1), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3), \ - gsDma1p( G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4) -#endif /* F3DEX_GBI_2 */ +#else /* F3DEX_GBI_2 */ +#define gSPForceMatrix(pkt, mptr) \ + { \ + gDma1p(pkt, G_MOVEMEM, mptr, 16, G_MV_MATRIX_1); \ + gDma1p(pkt, G_MOVEMEM, (char*)(mptr) + 16, 16, G_MV_MATRIX_2); \ + gDma1p(pkt, G_MOVEMEM, (char*)(mptr) + 32, 16, G_MV_MATRIX_3); \ + gDma1p(pkt, G_MOVEMEM, (char*)(mptr) + 48, 16, G_MV_MATRIX_4); \ + } +#define gsSPForceMatrix(mptr) \ + gsDma1p(G_MOVEMEM, mptr, 16, G_MV_MATRIX_1), gsDma1p(G_MOVEMEM, (char*)(mptr) + 16, 16, G_MV_MATRIX_2), \ + gsDma1p(G_MOVEMEM, (char*)(mptr) + 32, 16, G_MV_MATRIX_3), \ + gsDma1p(G_MOVEMEM, (char*)(mptr) + 48, 16, G_MV_MATRIX_4) +#endif /* F3DEX_GBI_2 */ /* * Insert values into Points @@ -2488,32 +2192,25 @@ _DW({ \ * where = which element of point to modify (byte offset into point) * num = new value (32 bit) */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define gSPModifyVertex(pkt, vtx, where, val) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_MODIFYVTX,24,8)| \ - _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16)); \ - _g->words.w1 = (unsigned int)(val); \ -} -# define gsSPModifyVertex(vtx, where, val) \ -{ \ - _SHIFTL(G_MODIFYVTX,24,8)| \ - _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16), \ - (unsigned int)(val) \ -} +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) +#define gSPModifyVertex(pkt, vtx, where, val) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = (_SHIFTL(G_MODIFYVTX, 24, 8) | _SHIFTL((where), 16, 8) | _SHIFTL((vtx)*2, 0, 16)); \ + _g->words.w1 = (unsigned int)(val); \ + }) +#define gsSPModifyVertex(vtx, where, val) \ + { _SHIFTL(G_MODIFYVTX, 24, 8) | _SHIFTL((where), 16, 8) | _SHIFTL((vtx)*2, 0, 16), (unsigned int)(val) } #else -# define gSPModifyVertex(pkt, vtx, where, val) \ - gMoveWd(pkt, G_MW_POINTS, (vtx)*40+(where), val) -# define gsSPModifyVertex(vtx, where, val) \ - gsMoveWd(G_MW_POINTS, (vtx)*40+(where), val) +#define gSPModifyVertex(pkt, vtx, where, val) gMoveWd(pkt, G_MW_POINTS, (vtx)*40 + (where), val) +#define gsSPModifyVertex(vtx, where, val) gsMoveWd(G_MW_POINTS, (vtx)*40 + (where), val) #endif -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI)) /* * gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval). * - * dl = DL branch to + * dl = DL branch to * vtx = Vertex * zval = Screen depth * near = Near plane @@ -2521,65 +2218,67 @@ _DW({ \ * flag = G_BZ_PERSP or G_BZ_ORTHO */ -#define G_BZ_PERSP 0 -#define G_BZ_ORTHO 1 +#define G_BZ_PERSP 0 +#define G_BZ_ORTHO 1 -#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ -(((unsigned int)FTOFIX32(((flag) == G_BZ_PERSP ? \ - (1.0f-(float)(near)/(float)(zval)) / \ - (1.0f-(float)(near)/(float)(far )) : \ - ((float)(zval) - (float)(near)) / \ - ((float)(far ) - (float)(near))))) * \ - (((int)((zmax) - (zmin)))&~1) + (int)FTOFIX32(zmin)) +#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ + (((unsigned int)FTOFIX32(((flag) == G_BZ_PERSP \ + ? (1.0f - (float)(near) / (float)(zval)) / (1.0f - (float)(near) / (float)(far)) \ + : ((float)(zval) - (float)(near)) / ((float)(far) - (float)(near))))) * \ + (((int)((zmax) - (zmin))) & ~1) + \ + (int)FTOFIX32(zmin)) -#define G_DEPTOZS(zval, near, far, flag) \ - G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) +#define G_DEPTOZS(zval, near, far, flag) G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) -#define gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, zmin, zmax) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(dl); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ - _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ - _g->words.w1 = G_DEPTOZSrg(zval, near, far, flag, zmin, zmax); \ -} +#define gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, zmin, zmax) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ + _g->words.w1 = (uintptr_t)(dl); \ + _g = (Gfx*)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z, 24, 8) | _SHIFTL((vtx)*5, 12, 12) | _SHIFTL((vtx)*2, 0, 12)); \ + _g->words.w1 = G_DEPTOZSrg(zval, near, far, flag, zmin, zmax); \ + }) -#define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ -{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(dl), }, \ -{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ - G_DEPTOZSrg(zval, near, far, flag, zmin, zmax), } +#define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ + { \ + _SHIFTL(G_RDPHALF_1, 24, 8), \ + (uintptr_t)(dl), \ + }, \ + { \ + _SHIFTL(G_BRANCH_Z, 24, 8) | _SHIFTL((vtx)*5, 12, 12) | _SHIFTL((vtx)*2, 0, 12), \ + G_DEPTOZSrg(zval, near, far, flag, zmin, zmax), \ + } -#define gSPBranchLessZ(pkt, dl, vtx, zval, near, far, flag) \ - gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, 0, G_MAXZ) -#define gsSPBranchLessZ(dl, vtx, zval, near, far, flag) \ - gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, 0, G_MAXZ) +#define gSPBranchLessZ(pkt, dl, vtx, zval, near, far, flag) \ + gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, 0, G_MAXZ) +#define gsSPBranchLessZ(dl, vtx, zval, near, far, flag) gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, 0, G_MAXZ) /* * gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval). * - * dl = DL branch to + * dl = DL branch to * vtx = Vertex * zval = Raw value of screen depth */ -#define gSPBranchLessZraw(pkt, dl, vtx, zval) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(dl); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ - _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ - _g->words.w1 = (unsigned int)(zval); \ -} +#define gSPBranchLessZraw(pkt, dl, vtx, zval) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ + _g->words.w1 = (uintptr_t)(dl); \ + _g = (Gfx*)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z, 24, 8) | _SHIFTL((vtx)*5, 12, 12) | _SHIFTL((vtx)*2, 0, 12)); \ + _g->words.w1 = (uintptr_t)(zval); \ + }) -#define gsSPBranchLessZraw(dl, vtx, zval) \ -{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(dl), }, \ -{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ - (unsigned int)(zval), } +#define gsSPBranchLessZraw(dl, vtx, zval) \ + { \ + _SHIFTL(G_RDPHALF_1, 24, 8), \ + (uintptr_t)(dl), \ + }, \ + { \ + _SHIFTL(G_BRANCH_Z, 24, 8) | _SHIFTL((vtx)*5, 12, 12) | _SHIFTL((vtx)*2, 0, 12), (uintptr_t)(zval), \ + } /* * gSPLoadUcode RSP loads specified ucode. @@ -2587,96 +2286,90 @@ _DW({ \ * uc_start = ucode text section start * uc_dstart = ucode data section start */ -#define gSPLoadUcodeEx(pkt, uc_start, uc_dstart, uc_dsize) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (unsigned int)(uc_dstart); \ - _g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(G_LOAD_UCODE,24,8)| \ - _SHIFTL((int)(uc_dsize)-1,0,16)); \ - _g->words.w1 = (unsigned int)(uc_start); \ -}) +#define gSPLoadUcodeEx(pkt, uc_start, uc_dstart, uc_dsize) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ + _g->words.w1 = (uintptr_t)(uc_dstart); \ + _g = (Gfx*)(pkt); \ + _g->words.w0 = (_SHIFTL(G_LOAD_UCODE, 24, 8) | _SHIFTL((int)(uc_dsize)-1, 0, 16)); \ + _g->words.w1 = (uintptr_t)(uc_start); \ + }) -#define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ -{ _SHIFTL(G_RDPHALF_1,24,8), \ - (unsigned int)(uc_dstart), }, \ -{ _SHIFTL(G_LOAD_UCODE,24,8)| \ - _SHIFTL((int)(uc_dsize)-1,0,16), \ - (unsigned int)(uc_start), } +#define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ + { \ + _SHIFTL(G_RDPHALF_1, 24, 8), \ + (uintptr_t)(uc_dstart), \ + }, \ + { \ + _SHIFTL(G_LOAD_UCODE, 24, 8) | _SHIFTL((int)(uc_dsize)-1, 0, 16), (uintptr_t)(uc_start), \ + } -#define gSPLoadUcode(pkt, uc_start, uc_dstart) \ - gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) -#define gsSPLoadUcode(uc_start, uc_dstart) \ - gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) +#define gSPLoadUcode(pkt, uc_start, uc_dstart) gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) +#define gsSPLoadUcode(uc_start, uc_dstart) gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) -#define gSPLoadUcodeL(pkt, ucode) \ - gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&ucode##TextStart), \ - OS_K0_TO_PHYSICAL(&ucode##DataStart)) -#define gsSPLoadUcodeL(ucode) \ - gsSPLoadUcode(OS_K0_TO_PHYSICAL(&ucode##TextStart), \ - OS_K0_TO_PHYSICAL(&ucode##DataStart)) +#define gSPLoadUcodeL(pkt, ucode) \ + gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart)) +#define gsSPLoadUcodeL(ucode) \ + gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), OS_K0_TO_PHYSICAL(&##ucode##DataStart)) #endif -#ifdef F3DEX_GBI_2 +#ifdef F3DEX_GBI_2 /* * gSPDma_io DMA to/from DMEM/IMEM for DEBUG. */ -#define gSPDma_io(pkt, flag, dmem, dram, size) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ - _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12); \ - _g->words.w1 = (unsigned int)(dram); \ -} +#define gSPDma_io(pkt, flag, dmem, dram, size) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_DMA_IO, 24, 8) | _SHIFTL((flag), 23, 1) | _SHIFTL((dmem) / 8, 13, 10) | \ + _SHIFTL((size)-1, 0, 12); \ + _g->words.w1 = (uintptr_t)(dram); \ + }) -#define gsSPDma_io(flag, dmem, dram, size) \ -{ \ - _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ - _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12), \ - (unsigned int)(dram) \ -} +#define gsSPDma_io(flag, dmem, dram, size) \ + { \ + _SHIFTL(G_DMA_IO, 24, 8) | _SHIFTL((flag), 23, 1) | _SHIFTL((dmem) / 8, 13, 10) | _SHIFTL((size)-1, 0, 12), \ + (uintptr_t)(dram) \ + } -#define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) -#define gsSPDmaRead(dmem,dram,size) gsSPDma_io(0,(dmem),(dram),(size)) -#define gSPDmaWrite(pkt,dmem,dram,size) gSPDma_io((pkt),1,(dmem),(dram),(size)) -#define gsSPDmaWrite(dmem,dram,size) gsSPDma_io(1,(dmem),(dram),(size)) +#define gSPDmaRead(pkt, dmem, dram, size) gSPDma_io((pkt), 0, (dmem), (dram), (size)) +#define gsSPDmaRead(dmem, dram, size) gsSPDma_io(0, (dmem), (dram), (size)) +#define gSPDmaWrite(pkt, dmem, dram, size) gSPDma_io((pkt), 1, (dmem), (dram), (size)) +#define gsSPDmaWrite(dmem, dram, size) gsSPDma_io(1, (dmem), (dram), (size)) #endif /* * Lighting Macros */ -#ifdef F3DEX_GBI_2 -# define NUML(n) ((n)*24) +#ifdef F3DEX_GBI_2 +#define NUML(n) ((n)*24) #else -# define NUML(n) (((n)+1)*32 + 0x80000000) +#define NUML(n) (((n) + 1) * 32 + 0x80000000) #endif -#define NUMLIGHTS_0 1 -#define NUMLIGHTS_1 1 -#define NUMLIGHTS_2 2 -#define NUMLIGHTS_3 3 -#define NUMLIGHTS_4 4 -#define NUMLIGHTS_5 5 -#define NUMLIGHTS_6 6 -#define NUMLIGHTS_7 7 +#define NUMLIGHTS_0 1 +#define NUMLIGHTS_1 1 +#define NUMLIGHTS_2 2 +#define NUMLIGHTS_3 3 +#define NUMLIGHTS_4 4 +#define NUMLIGHTS_5 5 +#define NUMLIGHTS_6 6 +#define NUMLIGHTS_7 7 /* * n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7 * NOTE: in addition to the number of directional lights specified, * there is always 1 ambient light */ -#define gSPNumLights(pkt, n) \ - gMoveWd(pkt, G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) -#define gsSPNumLights(n) \ - gsMoveWd( G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) +#define gSPNumLights(pkt, n) gMoveWd(pkt, G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) +#define gsSPNumLights(n) gsMoveWd(G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) -#define LIGHT_1 1 -#define LIGHT_2 2 -#define LIGHT_3 3 -#define LIGHT_4 4 -#define LIGHT_5 5 -#define LIGHT_6 6 -#define LIGHT_7 7 -#define LIGHT_8 8 +#define LIGHT_1 1 +#define LIGHT_2 2 +#define LIGHT_3 3 +#define LIGHT_4 4 +#define LIGHT_5 5 +#define LIGHT_6 6 +#define LIGHT_7 7 +#define LIGHT_8 8 /* * l should point to a Light struct * n should be one of: LIGHT_1, LIGHT_2, ..., LIGHT_8 @@ -2685,212 +2378,163 @@ _DW({ \ * LIGHT_1 through LIGHT_3 will be the directional lights and light * LIGHT_4 will be the ambient light. */ -#ifdef F3DEX_GBI_2 -# define gSPLight(pkt, l, n) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) -# define gsSPLight(l, n) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) -#else /* F3DEX_GBI_2 */ -# define gSPLight(pkt, l, n) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) -# define gsSPLight(l, n) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define gSPLight(pkt, l, n) gDma2p((pkt), G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, (n)*24 + 24) +#define gsSPLight(l, n) gsDma2p(G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, (n)*24 + 24) +#else /* F3DEX_GBI_2 */ +#define gSPLight(pkt, l, n) gDma1p(pkt, G_MOVEMEM, l, sizeof(Light), ((n)-1) * 2 + G_MV_L0) +#define gsSPLight(l, n) gsDma1p(G_MOVEMEM, l, sizeof(Light), ((n)-1) * 2 + G_MV_L0) +#endif /* F3DEX_GBI_2 */ /* * gSPLightColor changes color of light without recalculating light direction * col is a 32 bit word with r,g,b,a (alpha is ignored) * n should be one of LIGHT_1, LIGHT_2, ..., LIGHT_8 */ -#define gSPLightColor(pkt, n, col) \ -{ \ - gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_a##n, col); \ - gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_b##n, col); \ -} -#define gsSPLightColor(n, col) \ - gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), \ - gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) +#define gSPLightColor(pkt, n, col) \ + _DW({ \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_a##n, col); \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_b##n, col); \ + }) +#define gsSPLightColor(n, col) gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) /* These macros use a structure "name" which is init'd with the gdSPDefLights macros*/ -#define gSPSetLights0(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_0); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.a,2); \ -} -#define gsSPSetLights0(name) \ - gsSPNumLights(NUMLIGHTS_0), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.a,2) +#define gSPSetLights0(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_0); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.a, 2); \ + }) +#define gsSPSetLights0(name) gsSPNumLights(NUMLIGHTS_0), gsSPLight(&name.l[0], 1), gsSPLight(&name.a, 2) -#define gSPSetLights1(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_1); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.a,2); \ -} -#define gsSPSetLights1(name) \ - gsSPNumLights(NUMLIGHTS_1), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.a,2) +#define gSPSetLights1(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_1); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.a, 2); \ + }) +#define gsSPSetLights1(name) gsSPNumLights(NUMLIGHTS_1), gsSPLight(&name.l[0], 1), gsSPLight(&name.a, 2) -#define gSPSetLights2(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_2); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.a,3); \ -} -#define gsSPSetLights2(name) \ - gsSPNumLights(NUMLIGHTS_2), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.a,3) +#define gSPSetLights2(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_2); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.a, 3); \ + }) +#define gsSPSetLights2(name) \ + gsSPNumLights(NUMLIGHTS_2), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.a, 3) -#define gSPSetLights3(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_3); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.a,4); \ -} -#define gsSPSetLights3(name) \ - gsSPNumLights(NUMLIGHTS_3), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.a,4) +#define gSPSetLights3(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_3); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.l[2], 3); \ + gSPLight(pkt, &name.a, 4); \ + }) +#define gsSPSetLights3(name) \ + gsSPNumLights(NUMLIGHTS_3), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.l[2], 3), \ + gsSPLight(&name.a, 4) -#define gSPSetLights4(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_4); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.a,5); \ -} -#define gsSPSetLights4(name) \ - gsSPNumLights(NUMLIGHTS_4), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.a,5) +#define gSPSetLights4(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_4); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.l[2], 3); \ + gSPLight(pkt, &name.l[3], 4); \ + gSPLight(pkt, &name.a, 5); \ + }) +#define gsSPSetLights4(name) \ + gsSPNumLights(NUMLIGHTS_4), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.l[2], 3), \ + gsSPLight(&name.l[3], 4), gsSPLight(&name.a, 5) -#define gSPSetLights5(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_5); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.a,6); \ -} +#define gSPSetLights5(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_5); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.l[2], 3); \ + gSPLight(pkt, &name.l[3], 4); \ + gSPLight(pkt, &name.l[4], 5); \ + gSPLight(pkt, &name.a, 6); \ + }) -#define gsSPSetLights5(name) \ - gsSPNumLights(NUMLIGHTS_5), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.a,6) +#define gsSPSetLights5(name) \ + gsSPNumLights(NUMLIGHTS_5), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.l[2], 3), \ + gsSPLight(&name.l[3], 4), gsSPLight(&name.l[4], 5), gsSPLight(&name.a, 6) -#define gSPSetLights6(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_6); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.l[5],6); \ - gSPLight(pkt,&name.a,7); \ -} +#define gSPSetLights6(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_6); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.l[2], 3); \ + gSPLight(pkt, &name.l[3], 4); \ + gSPLight(pkt, &name.l[4], 5); \ + gSPLight(pkt, &name.l[5], 6); \ + gSPLight(pkt, &name.a, 7); \ + }) -#define gsSPSetLights6(name) \ - gsSPNumLights(NUMLIGHTS_6), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.l[5],6), \ - gsSPLight(&name.a,7) +#define gsSPSetLights6(name) \ + gsSPNumLights(NUMLIGHTS_6), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.l[2], 3), \ + gsSPLight(&name.l[3], 4), gsSPLight(&name.l[4], 5), gsSPLight(&name.l[5], 6), gsSPLight(&name.a, 7) -#define gSPSetLights7(pkt,name) \ -{ \ - gSPNumLights(pkt,NUMLIGHTS_7); \ - gSPLight(pkt,&name.l[0],1); \ - gSPLight(pkt,&name.l[1],2); \ - gSPLight(pkt,&name.l[2],3); \ - gSPLight(pkt,&name.l[3],4); \ - gSPLight(pkt,&name.l[4],5); \ - gSPLight(pkt,&name.l[5],6); \ - gSPLight(pkt,&name.l[6],7); \ - gSPLight(pkt,&name.a,8); \ -} +#define gSPSetLights7(pkt, name) \ + _DW({ \ + gSPNumLights(pkt, NUMLIGHTS_7); \ + gSPLight(pkt, &name.l[0], 1); \ + gSPLight(pkt, &name.l[1], 2); \ + gSPLight(pkt, &name.l[2], 3); \ + gSPLight(pkt, &name.l[3], 4); \ + gSPLight(pkt, &name.l[4], 5); \ + gSPLight(pkt, &name.l[5], 6); \ + gSPLight(pkt, &name.l[6], 7); \ + gSPLight(pkt, &name.a, 8); \ + }) -#define gsSPSetLights7(name) \ - gsSPNumLights(NUMLIGHTS_7), \ - gsSPLight(&name.l[0],1), \ - gsSPLight(&name.l[1],2), \ - gsSPLight(&name.l[2],3), \ - gsSPLight(&name.l[3],4), \ - gsSPLight(&name.l[4],5), \ - gsSPLight(&name.l[5],6), \ - gsSPLight(&name.l[6],7), \ - gsSPLight(&name.a,8) +#define gsSPSetLights7(name) \ + gsSPNumLights(NUMLIGHTS_7), gsSPLight(&name.l[0], 1), gsSPLight(&name.l[1], 2), gsSPLight(&name.l[2], 3), \ + gsSPLight(&name.l[3], 4), gsSPLight(&name.l[4], 5), gsSPLight(&name.l[5], 6), gsSPLight(&name.l[6], 7), \ + gsSPLight(&name.a, 8) /* * Reflection/Hiliting Macros */ -#ifdef F3DEX_GBI_2 -# define gSPLookAtX(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) -# define gsSPLookAtX(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) -# define gSPLookAtY(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) -# define gsSPLookAtY(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) -#else /* F3DEX_GBI_2 */ -# define gSPLookAtX(pkt, l) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) -# define gsSPLookAtX(l) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) -# define gSPLookAtY(pkt, l) \ - gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) -# define gsSPLookAtY(l) \ - gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define gSPLookAtX(pkt, l) gDma2p((pkt), G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATX) +#define gsSPLookAtX(l) gsDma2p(G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATX) +#define gSPLookAtY(pkt, l) gDma2p((pkt), G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATY) +#define gsSPLookAtY(l) gsDma2p(G_MOVEMEM, (l), sizeof(Light), G_MV_LIGHT, G_MVO_LOOKATY) +#else /* F3DEX_GBI_2 */ +#define gSPLookAtX(pkt, l) gDma1p(pkt, G_MOVEMEM, l, sizeof(Light), G_MV_LOOKATX) +#define gsSPLookAtX(l) gsDma1p(G_MOVEMEM, l, sizeof(Light), G_MV_LOOKATX) +#define gSPLookAtY(pkt, l) gDma1p(pkt, G_MOVEMEM, l, sizeof(Light), G_MV_LOOKATY) +#define gsSPLookAtY(l) gsDma1p(G_MOVEMEM, l, sizeof(Light), G_MV_LOOKATY) +#endif /* F3DEX_GBI_2 */ -#define gSPLookAt(pkt, la) \ -_DW({ \ - gSPLookAtX(pkt,la); \ - gSPLookAtY(pkt,(char *)(la)+16); \ -}) -#define gsSPLookAt(la) \ - gsSPLookAtX(la), \ - gsSPLookAtY((char *)(la)+16) +#define gSPLookAt(pkt, la) \ + _DW({ \ + gSPLookAtX(pkt, la); \ + gSPLookAtY(pkt, (char*)(la) + 16); \ + }) +#define gsSPLookAt(la) gsSPLookAtX(la), gsSPLookAtY((char*)(la) + 16) -#define gDPSetHilite1Tile(pkt, tile, hilite, width, height) \ - gDPSetTileSize(pkt, tile, (hilite)->h.x1 & 0xFFF, (hilite)->h.y1 & 0xFFF, \ - ((((width)-1)*4)+(hilite)->h.x1) & 0xFFF, ((((height)-1)*4)+(hilite)->h.y1) & 0xFFF) -#define gsDPSetHilite1Tile(tile, hilite, width, height) \ - gsDPSetTileSize(tile, (hilite)->h.x1 & 0xFFF, (hilite)->h.y1 & 0xFFF, \ - ((((width)-1)*4)+(hilite)->h.x1) & 0xFFF, ((((height)-1)*4)+(hilite)->h.y1) & 0xFFF) +#define gDPSetHilite1Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x1 & 0xfff, (hilite)->h.y1 & 0xfff, \ + ((((width)-1) * 4) + (hilite)->h.x1) & 0xfff, ((((height)-1) * 4) + (hilite)->h.y1) & 0xfff) +#define gsDPSetHilite1Tile(tile, hilite, width, height) \ + gsDPSetTileSize(tile, (hilite)->h.x1 & 0xfff, (hilite)->h.y1 & 0xfff, \ + ((((width)-1) * 4) + (hilite)->h.x1) & 0xfff, ((((height)-1) * 4) + (hilite)->h.y1) & 0xfff) -#define gDPSetHilite2Tile(pkt, tile, hilite, width, height) \ - gDPSetTileSize(pkt, tile, (hilite)->h.x2 & 0xFFF, (hilite)->h.y2 & 0xFFF, \ - ((((width)-1)*4)+(hilite)->h.x2) & 0xFFF, ((((height)-1)*4)+(hilite)->h.y2) & 0xFFF) -#define gsDPSetHilite2Tile(tile, hilite, width, height) \ - gsDPSetTileSize(tile, (hilite)->h.x2 & 0xFFF, (hilite)->h.y2 & 0xFFF, \ - ((((width)-1)*4)+(hilite)->h.x2) & 0xFFF, ((((height)-1)*4)+(hilite)->h.y2) & 0xFFF) +#define gDPSetHilite2Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x2 & 0xfff, (hilite)->h.y2 & 0xfff, \ + ((((width)-1) * 4) + (hilite)->h.x2) & 0xfff, ((((height)-1) * 4) + (hilite)->h.y2) & 0xfff) +#define gsDPSetHilite2Tile(tile, hilite, width, height) \ + gsDPSetTileSize(tile, (hilite)->h.x2 & 0xfff, (hilite)->h.y2 & 0xfff, \ + ((((width)-1) * 4) + (hilite)->h.x2) & 0xfff, ((((height)-1) * 4) + (hilite)->h.y2) & 0xfff) /* * FOG macros @@ -2905,486 +2549,461 @@ _DW({ \ * max is where fog is thickest (usually 1000) * */ -#define gSPFogFactor(pkt, fm, fo) \ - gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) +#define gSPFogFactor(pkt, fm, fo) gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, (_SHIFTL(fm, 16, 16) | _SHIFTL(fo, 0, 16))) -#define gsSPFogFactor(fm, fo) \ - gsMoveWd(G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) +#define gsSPFogFactor(fm, fo) gsMoveWd(G_MW_FOG, G_MWO_FOG, (_SHIFTL(fm, 16, 16) | _SHIFTL(fo, 0, 16))) -#define gSPFogPosition(pkt, min, max) \ - gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL((128000/((max)-(min))),16,16) | \ - _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) +#define gSPFogPosition(pkt, min, max) \ + gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000 / ((max) - (min))), 16, 16) | _SHIFTL(((500 - (min)) * 256 / ((max) - (min))), 0, 16))) -#define gsSPFogPosition(min, max) \ - gsMoveWd(G_MW_FOG, G_MWO_FOG, \ - (_SHIFTL((128000/((max)-(min))),16,16) | \ - _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) +#define gsSPFogPosition(min, max) \ + gsMoveWd(G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000 / ((max) - (min))), 16, 16) | _SHIFTL(((500 - (min)) * 256 / ((max) - (min))), 0, 16))) -#ifdef F3DEX_GBI_2 +#ifdef F3DEX_GBI_2 /* * Macros to turn texture on/off */ -# define gSPTexture(pkt, s, t, level, tile, on) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ - _SHIFTL(BOWTIE_VAL,16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ - _SHIFTL((on),1,7)); \ - _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ -}) -# define gsSPTexture(s, t, level, tile, on) \ -{ \ - (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL(BOWTIE_VAL,16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ - (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ -} +#define gSPTexture(pkt, s, t, level, tile, on) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(BOWTIE_VAL, 16, 8) | _SHIFTL((level), 11, 3) | \ + _SHIFTL((tile), 8, 3) | _SHIFTL((on), 1, 7)); \ + _g->words.w1 = (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)); \ + }) +#define gsSPTexture(s, t, level, tile, on) \ + { \ + (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(BOWTIE_VAL, 16, 8) | _SHIFTL((level), 11, 3) | _SHIFTL((tile), 8, 3) | \ + _SHIFTL((on), 1, 7)), \ + (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)) \ + } /* * Different version of SPTexture macro, has an additional parameter * which is currently reserved in the microcode. */ -# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ - _SHIFTL((xparam),16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ - _SHIFTL((on),1,7)); \ - _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ -} -# define gsSPTextureL(s, t, level, xparam, tile, on) \ -{ \ - (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL((xparam),16,8) | \ - _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ - (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ -} +#define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL((xparam), 16, 8) | _SHIFTL((level), 11, 3) | \ + _SHIFTL((tile), 8, 3) | _SHIFTL((on), 1, 7)); \ + _g->words.w1 = (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)); \ + }) +#define gsSPTextureL(s, t, level, xparam, tile, on) \ + { \ + (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL((xparam), 16, 8) | _SHIFTL((level), 11, 3) | _SHIFTL((tile), 8, 3) | \ + _SHIFTL((on), 1, 7)), \ + (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)) \ + } #else /* * Macros to turn texture on/off */ -# define gSPTexture(pkt, s, t, level, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)|\ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ - _SHIFTL((on),0,8)); \ - _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ -} -# define gsSPTexture(s, t, level, tile, on) \ -{ \ - (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ - (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ -} +#define gSPTexture(pkt, s, t, level, tile, on) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(BOWTIE_VAL, 16, 8) | _SHIFTL((level), 11, 3) | \ + _SHIFTL((tile), 8, 3) | _SHIFTL((on), 0, 8)); \ + _g->words.w1 = (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)); \ + } +#define gsSPTexture(s, t, level, tile, on) \ + { \ + (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(BOWTIE_VAL, 16, 8) | _SHIFTL((level), 11, 3) | _SHIFTL((tile), 8, 3) | \ + _SHIFTL((on), 0, 8)), \ + (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)) \ + } /* * Different version of SPTexture macro, has an additional parameter * which is currently reserved in the microcode. */ -# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ - _SHIFTL((on),0,8)); \ - _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ -} -# define gsSPTextureL(s, t, level, xparam, tile, on) \ -{ \ - (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ - _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ - (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ -} +#define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL((xparam), 16, 8) | _SHIFTL((level), 11, 3) | \ + _SHIFTL((tile), 8, 3) | _SHIFTL((on), 0, 8)); \ + _g->words.w1 = (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)); \ + } +#define gsSPTextureL(s, t, level, xparam, tile, on) \ + { \ + (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL((xparam), 16, 8) | _SHIFTL((level), 11, 3) | _SHIFTL((tile), 8, 3) | \ + _SHIFTL((on), 0, 8)), \ + (_SHIFTL((s), 16, 16) | _SHIFTL((t), 0, 16)) \ + } #endif -#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) -#define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) +#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) +#define gsSPPerspNormalize(s) gsMoveWd(G_MW_PERSPNORM, 0, (s)) -#ifdef F3DEX_GBI_2 -# define gSPPopMatrixN(pkt, n, num) gDma2p((pkt),G_POPMTX,(num)*64,64,2,0) -# define gsSPPopMatrixN(n, num) gsDma2p( G_POPMTX,(num)*64,64,2,0) -# define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) -# define gsSPPopMatrix(n) gsSPPopMatrixN( (n), 1) -#else /* F3DEX_GBI_2 */ -# define gSPPopMatrix(pkt, n) gImmp1(pkt, G_POPMTX, n) -# define gsSPPopMatrix(n) gsImmp1( G_POPMTX, n) -#endif /* F3DEX_GBI_2 */ +#ifdef F3DEX_GBI_2 +#define gSPPopMatrixN(pkt, n, num) gDma2p((pkt), G_POPMTX, (num)*64, 64, 2, 0) +#define gsSPPopMatrixN(n, num) gsDma2p(G_POPMTX, (num)*64, 64, 2, 0) +#define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) +#define gsSPPopMatrix(n) gsSPPopMatrixN((n), 1) +#else /* F3DEX_GBI_2 */ +#define gSPPopMatrix(pkt, n) gImmp1(pkt, G_POPMTX, n) +#define gsSPPopMatrix(n) gsImmp1(G_POPMTX, n) +#endif /* F3DEX_GBI_2 */ -#define gSPEndDisplayList(pkt) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_ENDDL, 24, 8); \ - _g->words.w1 = 0; \ -}) +#define gSPEndDisplayList(pkt) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_ENDDL, 24, 8); \ + _g->words.w1 = 0; \ + }) -#define gsSPEndDisplayList() \ -{ \ - _SHIFTL(G_ENDDL, 24, 8), 0 \ -} +#define gsSPEndDisplayList() \ + { _SHIFTL(G_ENDDL, 24, 8), 0 } -#ifdef F3DEX_GBI_2 +#define __gSPInvalidateTexCache(pkt, addr) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_INVALTEXCACHE, 24, 8); \ + _g->words.w1 = addr; \ + }) + +#define gsSPInvalidateTexCache() \ + { _SHIFTL(G_INVALTEXCACHE, 24, 8), 0 } + +#define gsSPSetFB(pkt, fb) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETFB, 24, 8); \ + _g->words.w1 = fb; \ + } + +#define gsSPResetFB(pkt) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RESETFB, 24, 8); \ + _g->words.w1 = 0; \ + } + +#define gSPGrayscale(pkt, state) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETGRAYSCALE, 24, 8); \ + _g->words.w1 = state; \ + } + +#define gsSPGrayscale(state) \ + { (_SHIFTL(G_SETGRAYSCALE, 24, 8)), (state) } + +#define gSPExtraGeometryMode(pkt, c, s) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_EXTRAGEOMETRYMODE, 24, 8) | _SHIFTL(~(u32)(c), 0, 24); \ + _g->words.w1 = (u32)(s); \ + }) + +#define gSPSetExtraGeometryMode(pkt, word) gSPExtraGeometryMode((pkt), 0, word) +#define gSPClearExtraGeometryMode(pkt, word) gSPExtraGeometryMode((pkt), word, 0) + +#ifdef F3DEX_GBI_2 /* - * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. + * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. * - * gSPClearGeometryMode(pkt,c) - * gSPSetGeometryMode(pkt,s) + * gSPClearGeometryMode(pkt,c) + * gSPSetGeometryMode(pkt,s) * - * gSPLoadGeometryMode(pkt, word) sets GeometryMode directly. + * gSPLoadGeometryMode(pkt, word) sets GeometryMode directly. */ -#define gSPGeometryMode(pkt, c, s) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = _SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24);\ - _g->words.w1 = (u32)(s); \ -}) +#define gSPGeometryMode(pkt, c, s) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = _SHIFTL(G_GEOMETRYMODE, 24, 8) | _SHIFTL(~(u32)(c), 0, 24); \ + _g->words.w1 = (u32)(s); \ + }) -#define gsSPGeometryMode(c, s) \ -{ \ - (_SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24)),(u32)(s) \ -} -#define gSPSetGeometryMode(pkt, word) gSPGeometryMode((pkt),0,(word)) -#define gsSPSetGeometryMode(word) gsSPGeometryMode(0,(word)) -#define gSPClearGeometryMode(pkt, word) gSPGeometryMode((pkt),(word),0) -#define gsSPClearGeometryMode(word) gsSPGeometryMode((word),0) -#define gSPLoadGeometryMode(pkt, word) gSPGeometryMode((pkt),-1,(word)) -#define gsSPLoadGeometryMode(word) gsSPGeometryMode(-1,(word)) +#define gsSPGeometryMode(c, s) \ + { (_SHIFTL(G_GEOMETRYMODE, 24, 8) | _SHIFTL(~(u32)(c), 0, 24)), (u32)(s) } +#define gSPSetGeometryMode(pkt, word) gSPGeometryMode((pkt), 0, (word)) +#define gsSPSetGeometryMode(word) gsSPGeometryMode(0, (word)) +#define gSPClearGeometryMode(pkt, word) gSPGeometryMode((pkt), (word), 0) +#define gsSPClearGeometryMode(word) gsSPGeometryMode((word), 0) +#define gSPLoadGeometryMode(pkt, word) gSPGeometryMode((pkt), -1, (word)) +#define gsSPLoadGeometryMode(word) gsSPGeometryMode(-1, (word)) -#else /* F3DEX_GBI_2 */ -#define gSPSetGeometryMode(pkt, word) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETGEOMETRYMODE, 24, 8); \ - _g->words.w1 = (unsigned int)(word); \ -} +#else /* F3DEX_GBI_2 */ +#define gSPSetGeometryMode(pkt, word) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ + } -#define gsSPSetGeometryMode(word) \ -{ \ - _SHIFTL(G_SETGEOMETRYMODE, 24, 8), (unsigned int)(word) \ -} +#define gsSPSetGeometryMode(word) \ + { _SHIFTL(G_SETGEOMETRYMODE, 24, 8), (unsigned int)(word) } -#define gSPClearGeometryMode(pkt, word) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8); \ - _g->words.w1 = (unsigned int)(word); \ -} +#define gSPClearGeometryMode(pkt, word) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ + } -#define gsSPClearGeometryMode(word) \ -{ \ - _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8), (unsigned int)(word) \ -} -#endif /* F3DEX_GBI_2 */ +#define gsSPClearGeometryMode(word) \ + { _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8), (unsigned int)(word) } +#endif /* F3DEX_GBI_2 */ -#ifdef F3DEX_GBI_2 -#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)| \ - _SHIFTL((len)-1,0,8)); \ - _g->words.w1 = (unsigned int)(data); \ -}) +#ifdef F3DEX_GBI_2 +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(32 - (sft) - (len), 8, 8) | _SHIFTL((len)-1, 0, 8)); \ + _g->words.w1 = (unsigned int)(data); \ + }) -#define gsSPSetOtherMode(cmd, sft, len, data) \ -{ \ - _SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)|_SHIFTL((len)-1,0,8), \ - (unsigned int)(data) \ -} +#define gsSPSetOtherMode(cmd, sft, len, data) \ + { _SHIFTL(cmd, 24, 8) | _SHIFTL(32 - (sft) - (len), 8, 8) | _SHIFTL((len)-1, 0, 8), (unsigned int)(data) } #else -#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | \ - _SHIFTL(len, 0, 8)); \ - _g->words.w1 = (unsigned int)(data); \ -} +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ + { \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8)); \ + _g->words.w1 = (unsigned int)(data); \ + } -#define gsSPSetOtherMode(cmd, sft, len, data) \ -{ \ - _SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8), \ - (unsigned int)(data) \ -} +#define gsSPSetOtherMode(cmd, sft, len, data) \ + { _SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8), (unsigned int)(data) } #endif /* * RDP setothermode register commands - register shadowed in RSP */ -#define gDPPipelineMode(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) -#define gsDPPipelineMode(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) +#define gDPPipelineMode(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) +#define gsDPPipelineMode(mode) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) -#define gDPSetCycleType(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) -#define gsDPSetCycleType(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) +#define gDPSetCycleType(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) +#define gsDPSetCycleType(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) -#define gDPSetTexturePersp(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) -#define gsDPSetTexturePersp(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) +#define gDPSetTexturePersp(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) +#define gsDPSetTexturePersp(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) -#define gDPSetTextureDetail(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) -#define gsDPSetTextureDetail(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) +#define gDPSetTextureDetail(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) +#define gsDPSetTextureDetail(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) -#define gDPSetTextureLOD(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) -#define gsDPSetTextureLOD(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) +#define gDPSetTextureLOD(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) +#define gsDPSetTextureLOD(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) -#define gDPSetTextureLUT(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) -#define gsDPSetTextureLUT(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) +#define gDPSetTextureLUT(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) +#define gsDPSetTextureLUT(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) -#define gDPSetTextureFilter(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) -#define gsDPSetTextureFilter(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) +#define gDPSetTextureFilter(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) +#define gsDPSetTextureFilter(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) -#define gDPSetTextureConvert(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) -#define gsDPSetTextureConvert(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) +#define gDPSetTextureConvert(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) +#define gsDPSetTextureConvert(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) -#define gDPSetCombineKey(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) -#define gsDPSetCombineKey(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) +#define gDPSetCombineKey(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) +#define gsDPSetCombineKey(type) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) #ifndef _HW_VERSION_1 -#define gDPSetColorDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) -#define gsDPSetColorDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#define gDPSetColorDither(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#define gsDPSetColorDither(mode) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) #else -#define gDPSetColorDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) -#define gsDPSetColorDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#define gDPSetColorDither(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#define gsDPSetColorDither(mode) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) #endif #ifndef _HW_VERSION_1 -#define gDPSetAlphaDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) -#define gsDPSetAlphaDither(mode) \ - gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#define gDPSetAlphaDither(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#define gsDPSetAlphaDither(mode) gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) #endif - #define gDPSetDither(pkt, mode) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 4, mode) +#define gDPSetDither(pkt, mode) gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 4, mode) /* 'blendmask' is not supported anymore. * The bits are reserved for future use. * Fri May 26 13:45:55 PDT 1995 */ -#define gDPSetBlendMask(pkt, mask) gDPNoOp(pkt) -#define gsDPSetBlendMask(mask) gsDPNoOp() +#define gDPSetBlendMask(pkt, mask) gDPNoOp(pkt) +#define gsDPSetBlendMask(mask) gsDPNoOp() -#define gDPSetAlphaCompare(pkt, type) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) -#define gsDPSetAlphaCompare(type) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) +#define gDPSetAlphaCompare(pkt, type) gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) +#define gsDPSetAlphaCompare(type) gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) -#define gDPSetDepthSource(pkt, src) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) -#define gsDPSetDepthSource(src) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) +#define gDPSetDepthSource(pkt, src) gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) +#define gsDPSetDepthSource(src) gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) -#define gDPSetRenderMode(pkt, c0, c1) \ - gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ - (c0) | (c1)) -#define gsDPSetRenderMode(c0, c1) \ - gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ - (c0) | (c1)) +#define gDPSetRenderMode(pkt, c0, c1) gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, (c0) | (c1)) +#define gsDPSetRenderMode(c0, c1) gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, (c0) | (c1)) -#define gSetImage(pkt, cmd, fmt, siz, width, i) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12); \ - _g->words.w1 = (unsigned int)(i); \ -}) +#define gSetImage(pkt, cmd, fmt, siz, width, i) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12); \ + _g->words.w1 = (uintptr_t)(i); \ + }) -#define gsSetImage(cmd, fmt, siz, width, i) \ -{ \ - _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), \ - (unsigned int)(i) \ -} - -#define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) -#define gsDPSetColorImage(f, s, w, i) gsSetImage(G_SETCIMG, f, s, w, i) +#define gsSetImage(cmd, fmt, siz, width, i) \ + { _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), (uintptr_t)(i) } +#define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) +#define gsDPSetColorImage(f, s, w, i) gsSetImage(G_SETCIMG, f, s, w, i) /* use these for new code */ -#define gDPSetDepthImage(pkt, i) gSetImage(pkt, G_SETZIMG, 0, 0, 1, i) -#define gsDPSetDepthImage(i) gsSetImage(G_SETZIMG, 0, 0, 1, i) +#define gDPSetDepthImage(pkt, i) gSetImage(pkt, G_SETZIMG, 0, 0, 1, i) +#define gsDPSetDepthImage(i) gsSetImage(G_SETZIMG, 0, 0, 1, i) /* kept for compatibility */ -#define gDPSetMaskImage(pkt, i) gDPSetDepthImage(pkt, i) -#define gsDPSetMaskImage(i) gsDPSetDepthImage(i) +#define gDPSetMaskImage(pkt, i) gDPSetDepthImage(pkt, i) +#define gsDPSetMaskImage(i) gsDPSetDepthImage(i) -#define gDPSetTextureImage(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG, f, s, w, i) -#define gsDPSetTextureImage(f, s, w, i) gsSetImage(G_SETTIMG, f, s, w, i) +#define __gDPSetTextureImage(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG, f, s, w, i) +#define gsDPSetTextureImage(f, s, w, i) gsSetImage(G_SETTIMG, f, s, w, i) +#define __gDPSetTextureImageFB(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG_FB, f, s, w, i) /* * RDP macros */ -#define gDPSetCombine(pkt, muxs0, muxs1) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24);\ - _g->words.w1 = (unsigned int)(muxs1); \ -} +#define gDPSetCombine(pkt, muxs0, muxs1) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24); \ + _g->words.w1 = (unsigned int)(muxs1); \ + }) -#define gsDPSetCombine(muxs0, muxs1) \ -{ \ - _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24), \ - (unsigned int)(muxs1) \ -} +#define gsDPSetCombine(muxs0, muxs1) \ + { _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24), (unsigned int)(muxs1) } -#define GCCc0w0(saRGB0, mRGB0, saA0, mA0) \ - (_SHIFTL((saRGB0), 20, 4) | _SHIFTL((mRGB0), 15, 5) | \ - _SHIFTL((saA0), 12, 3) | _SHIFTL((mA0), 9, 3)) +#define GCCc0w0(saRGB0, mRGB0, saA0, mA0) \ + (_SHIFTL((saRGB0), 20, 4) | _SHIFTL((mRGB0), 15, 5) | _SHIFTL((saA0), 12, 3) | _SHIFTL((mA0), 9, 3)) -#define GCCc1w0(saRGB1, mRGB1) \ - (_SHIFTL((saRGB1), 5, 4) | _SHIFTL((mRGB1), 0, 5)) +#define GCCc1w0(saRGB1, mRGB1) (_SHIFTL((saRGB1), 5, 4) | _SHIFTL((mRGB1), 0, 5)) -#define GCCc0w1(sbRGB0, aRGB0, sbA0, aA0) \ - (_SHIFTL((sbRGB0), 28, 4) | _SHIFTL((aRGB0), 15, 3) | \ - _SHIFTL((sbA0), 12, 3) | _SHIFTL((aA0), 9, 3)) +#define GCCc0w1(sbRGB0, aRGB0, sbA0, aA0) \ + (_SHIFTL((sbRGB0), 28, 4) | _SHIFTL((aRGB0), 15, 3) | _SHIFTL((sbA0), 12, 3) | _SHIFTL((aA0), 9, 3)) -#define GCCc1w1(sbRGB1, saA1, mA1, aRGB1, sbA1, aA1) \ - (_SHIFTL((sbRGB1), 24, 4) | _SHIFTL((saA1), 21, 3) | \ - _SHIFTL((mA1), 18, 3) | _SHIFTL((aRGB1), 6, 3) | \ - _SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3)) +#define GCCc1w1(sbRGB1, saA1, mA1, aRGB1, sbA1, aA1) \ + (_SHIFTL((sbRGB1), 24, 4) | _SHIFTL((saA1), 21, 3) | _SHIFTL((mA1), 18, 3) | _SHIFTL((aRGB1), 6, 3) | \ + _SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3)) -#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ - a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | \ - _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ - G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ - GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ - 0, 24); \ - _g->words.w1 = (unsigned int)(GCCc0w1(G_CCMUX_##b0, \ - G_CCMUX_##d0, \ - G_ACMUX_##Ab0, \ - G_ACMUX_##Ad0) | \ - GCCc1w1(G_CCMUX_##b1, \ - G_ACMUX_##Aa1, \ - G_ACMUX_##Ac1, \ - G_CCMUX_##d1, \ - G_ACMUX_##Ab1, \ - G_ACMUX_##Ad1)); \ -}) +#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = \ + _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ + 0, 24); \ + _g->words.w1 = (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, G_ACMUX_##Ac1, G_CCMUX_##d1, G_ACMUX_##Ab1, \ + G_ACMUX_##Ad1)); \ + }) -#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ - a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ -{ \ - _SHIFTL(G_SETCOMBINE, 24, 8) | \ - _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ - G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ - GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), 0, 24), \ - (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, \ - G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ - GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, \ - G_ACMUX_##Ac1, G_CCMUX_##d1, \ - G_ACMUX_##Ab1, G_ACMUX_##Ad1)) \ -} +#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ + { \ + _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ + 0, 24), \ + (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, G_ACMUX_##Ac1, G_CCMUX_##d1, G_ACMUX_##Ab1, \ + G_ACMUX_##Ad1)) \ + } + +#define gsDPSetCombineLERP_NoMacros(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ + { \ + _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(GCCc0w0(a0, c0, Aa0, Ac0) | GCCc1w0(a1, c1), 0, 24), \ + (unsigned int)(GCCc0w1(b0, d0, Ab0, Ad0) | GCCc1w1(b1, Aa1, Ac1, d1, Ab1, Ad1)) \ + } /* * SetCombineMode macros are NOT redunant. It allow the C preprocessor * to substitute single parameter which includes commas in the token and * rescan for higher parameter count macro substitution. * - * eg. gsDPSetCombineMode(G_CC_MODULATE, G_CC_MODULATE) turns into - * gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0, - * TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0) + * eg. gsDPSetCombineMode(G_CC_MODULATE, G_CC_MODULATE) turns into + * gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0, + * TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0) */ -#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) -#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) +/* +#if _MSC_VER +#define gDPSetCombineMode(pkt, a, b) gDPNoParam(pkt, G_NOOP) +#else +#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) +//#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, ##a, b) +#endif +*/ -#define gDPSetColor(pkt, c, d) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(c, 24, 8); \ - _g->words.w1 = (unsigned int)(d); \ -}) +#if defined(_MSC_VER) +#define CALL_2(A, B) A B +#define CALL_3(A, B, C) A B C -#define gsDPSetColor(c, d) \ -{ \ - _SHIFTL(c, 24, 8), (unsigned int)(d) \ -} +#define gDPSetCombineMode(pkt, a, b) CALL_2(gDPSetCombineLERP, (pkt, a, b)) +#define gsDPSetCombineMode(a, b) CALL_2(gsDPSetCombineLERP, (a, b)) +#else +#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) +#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) +#endif -#define DPRGBColor(pkt, cmd, r, g, b, a) \ - gDPSetColor(pkt, cmd, \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) -#define sDPRGBColor(cmd, r, g, b, a) \ - gsDPSetColor(cmd, \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) +#if defined(_MSC_VER) || defined(__GNUC__) +#define CALL_2(A, B) A B +#define CALL_3(A, B, C) A B C -#define gDPSetEnvColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETENVCOLOR, r,g,b,a) -#define gsDPSetEnvColor(r, g, b, a) \ - sDPRGBColor(G_SETENVCOLOR, r,g,b,a) -#define gDPSetBlendColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETBLENDCOLOR, r,g,b,a) -#define gsDPSetBlendColor(r, g, b, a) \ - sDPRGBColor(G_SETBLENDCOLOR, r,g,b,a) -#define gDPSetFogColor(pkt, r, g, b, a) \ - DPRGBColor(pkt, G_SETFOGCOLOR, r,g,b,a) -#define gsDPSetFogColor(r, g, b, a) \ - sDPRGBColor(G_SETFOGCOLOR, r,g,b,a) -#define gDPSetFillColor(pkt, d) \ - gDPSetColor(pkt, G_SETFILLCOLOR, (d)) -#define gsDPSetFillColor(d) \ - gsDPSetColor(G_SETFILLCOLOR, (d)) +// #define gsDPSetCombineMode(a, b) CALL_2(gsDPSetCombineLERP, (a, b)) +// #define gsDPSetCombineMode(a, b) _SHIFTL(0, 24, 8), 0 +#else +#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) +#endif -#define gDPSetPrimDepth(pkt, z, dz) \ - gDPSetColor(pkt, G_SETPRIMDEPTH, \ - _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) -#define gsDPSetPrimDepth(z, dz) \ - gsDPSetColor(G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | \ - _SHIFTL(dz, 0, 16)) +#define gDPSetColor(pkt, c, d) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8); \ + _g->words.w1 = (unsigned int)(d); \ + }) -#define gDPSetPrimColor(pkt, m, l, r, g, b, a) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ - _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ - _g->words.w1 = (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ - _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)); \ -}) +#define gsDPSetColor(c, d) \ + { _SHIFTL(c, 24, 8), (unsigned int)(d) } -#define gsDPSetPrimColor(m, l, r, g, b, a) \ -{ \ - (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | \ - _SHIFTL(l, 0, 8)), \ - (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | \ - _SHIFTL(a, 0, 8)) \ -} +#define DPRGBColor(pkt, cmd, r, g, b, a) \ + gDPSetColor(pkt, cmd, (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) +#define sDPRGBColor(cmd, r, g, b, a) \ + gsDPSetColor(cmd, (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) + +#define gDPSetGrayscaleColor(pkt, r, g, b, lerp) DPRGBColor(pkt, G_SETINTENSITY, r, g, b, lerp) +#define gsDPSetGrayscaleColor(r, g, b, a) sDPRGBColor(G_SETINTENSITY, r, g, b, a) +#define gDPSetEnvColor(pkt, r, g, b, a) DPRGBColor(pkt, G_SETENVCOLOR, r, g, b, a) +#define gsDPSetEnvColor(r, g, b, a) sDPRGBColor(G_SETENVCOLOR, r, g, b, a) +#define gDPSetBlendColor(pkt, r, g, b, a) DPRGBColor(pkt, G_SETBLENDCOLOR, r, g, b, a) +#define gsDPSetBlendColor(r, g, b, a) sDPRGBColor(G_SETBLENDCOLOR, r, g, b, a) +#define gDPSetFogColor(pkt, r, g, b, a) DPRGBColor(pkt, G_SETFOGCOLOR, r, g, b, a) +#define gsDPSetFogColor(r, g, b, a) sDPRGBColor(G_SETFOGCOLOR, r, g, b, a) +#define gDPSetFillColor(pkt, d) gDPSetColor(pkt, G_SETFILLCOLOR, (d)) +#define gsDPSetFillColor(d) gsDPSetColor(G_SETFILLCOLOR, (d)) +#define gDPSetPrimDepth(pkt, z, dz) gDPSetColor(pkt, G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) +#define gsDPSetPrimDepth(z, dz) gsDPSetColor(G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) + +#define gDPSetPrimColor(pkt, m, l, r, g, b, a) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ + _g->words.w1 = (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)); \ + }) + +#define gsDPSetPrimColor(m, l, r, g, b, a) \ + { \ + (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)), \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)) \ + } /* * gDPSetOtherMode (This is for expert user.) @@ -3393,40 +3012,37 @@ _DW({ \ * Do not use this command in the same DL with another g*SPSetOtherMode DLs. * * [Usage] - * gDPSetOtherMode(pkt, modeA, modeB) + * gDPSetOtherMode(pkt, modeA, modeB) * * 'modeA' is described all parameters of GroupA GBI command. * 'modeB' is also described all parameters of GroupB GBI command. * - * GroupA: - * gDPPipelineMode, gDPSetCycleType, gSPSetTexturePersp, - * gDPSetTextureDetail, gDPSetTextureLOD, gDPSetTextureLUT, - * gDPSetTextureFilter, gDPSetTextureConvert, gDPSetCombineKey, - * gDPSetColorDither, gDPSetAlphaDither + * GroupA: + * gDPPipelineMode, gDPSetCycleType, gSPSetTexturePersp, + * gDPSetTextureDetail, gDPSetTextureLOD, gDPSetTextureLUT, + * gDPSetTextureFilter, gDPSetTextureConvert, gDPSetCombineKey, + * gDPSetColorDither, gDPSetAlphaDither * - * GroupB: - * gDPSetAlphaCompare, gDPSetDepthSource, gDPSetRenderMode + * GroupB: + * gDPSetAlphaCompare, gDPSetDepthSource, gDPSetRenderMode * - * Use 'OR' operation to get modeA and modeB. + * Use 'OR' operation to get modeA and modeB. * - * modeA = G_PM_* | G_CYC_* | G_TP_* | G_TD_* | G_TL_* | G_TT_* | G_TF_* - * G_TC_* | G_CK_* | G_CD_* | G_AD_*; + * modeA = G_PM_* | G_CYC_* | G_TP_* | G_TD_* | G_TL_* | G_TT_* | G_TF_* + * G_TC_* | G_CK_* | G_CD_* | G_AD_*; * - * modeB = G_AC_* | G_ZS_* | G_RM_* | G_RM_*2; + * modeB = G_AC_* | G_ZS_* | G_RM_* | G_RM_*2; */ -#define gDPSetOtherMode(pkt, mode0, mode1) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24);\ - _g->words.w1 = (unsigned int)(mode1); \ -}) +#define gDPSetOtherMode(pkt, mode0, mode1) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(mode0, 0, 24); \ + _g->words.w1 = (unsigned int)(mode1); \ + }) -#define gsDPSetOtherMode(mode0, mode1) \ -{ \ - _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24), \ - (unsigned int)(mode1) \ -} +#define gsDPSetOtherMode(mode0, mode1) \ + { _SHIFTL(G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(mode0, 0, 24), (unsigned int)(mode1) } /* * Texturing macros @@ -3434,23 +3050,22 @@ _DW({ \ /* These are also defined defined above for Sprite Microcode */ -#define G_TX_LOADTILE 7 -#define G_TX_RENDERTILE 0 - -#define G_TX_NOMIRROR 0 -#define G_TX_WRAP 0 -#define G_TX_MIRROR 0x1 -#define G_TX_CLAMP 0x2 -#define G_TX_NOMASK 0 -#define G_TX_NOLOD 0 +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 #ifndef MAX -#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif #ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif /* * Dxt is the inverse of the number of 64-bit words in a line of @@ -3460,7 +3075,7 @@ _DW({ \ * this. The 4b macros are a special case since 4-bit textures * are loaded as 8-bit textures. Dxt is fixed point 1.11. RJM */ -#define G_TX_DXT_FRAC 11 +#define G_TX_DXT_FRAC 11 /* * For RCP 2.0, the maximum number of texels that can be loaded @@ -3472,71 +3087,51 @@ _DW({ \ * the g*DPLoadBlock macros directly, you will need to handle this * tile manipulation yourself. RJM. */ -#ifdef _HW_VERSION_1 -#define G_TX_LDBLK_MAX_TXL 4095 -#else -#define G_TX_LDBLK_MAX_TXL 2047 -#endif /* _HW_VERSION_1 */ -#define TXL2WORDS(txls, b_txl) MAX(1, ((txls)*(b_txl)/8)) -#define CALC_DXT(width, b_txl) \ - (((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / \ - TXL2WORDS(width, b_txl)) +#define G_TX_LDBLK_MAX_TXL 4095 -#define TXL2WORDS_4b(txls) MAX(1, ((txls)/16)) -#define CALC_DXT_4b(width) \ - (((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / \ - TXL2WORDS_4b(width)) +#define TXL2WORDS(txls, b_txl) MAX(1, ((txls) * (b_txl) / 8)) +#define CALC_DXT(width, b_txl) (((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / TXL2WORDS(width, b_txl)) -#define gDPLoadTileGeneric(pkt, c, tile, uls, ult, lrs, lrt) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | \ - _SHIFTL(ult, 0, 12); \ - _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | \ - _SHIFTL(lrt, 0, 12); \ -}) +#define TXL2WORDS_4b(txls) MAX(1, ((txls) / 16)) +#define CALC_DXT_4b(width) (((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / TXL2WORDS_4b(width)) -#define gsDPLoadTileGeneric(c, tile, uls, ult, lrs, lrt) \ -{ \ - _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12), \ - _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12)\ -} +#define gDPLoadTileGeneric(pkt, c, tile, uls, ult, lrs, lrt) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12); \ + }) -#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) \ - gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt) -#define gsDPSetTileSize(t, uls, ult, lrs, lrt) \ - gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt) -#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) \ - gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt) -#define gsDPLoadTile(t, uls, ult, lrs, lrt) \ - gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt) +#define gsDPLoadTileGeneric(c, tile, uls, ult, lrs, lrt) \ + { \ + _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12), \ + _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12) \ + } -#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, \ - maskt, shiftt, cms, masks, shifts) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) |\ - _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ - _SHIFTL(tmem, 0, 9); \ - _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ - _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ - _SHIFTL(shiftt, 10, 4) |_SHIFTL(cms, 8, 2) | \ - _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4); \ -}) +#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gsDPSetTileSize(t, uls, ult, lrs, lrt) gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt) +#define gsDPLoadTile(t, uls, ult, lrs, lrt) gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt) -#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, \ - maskt, shiftt, cms, masks, shifts) \ -{ \ - (_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | \ - _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | _SHIFTL(tmem, 0, 9)),\ - (_SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ - _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ - _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | \ - _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4)) \ -} +#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, maskt, shiftt, cms, masks, shifts) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ + _SHIFTL(tmem, 0, 9); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4); \ + }) + +#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, maskt, shiftt, cms, masks, shifts) \ + { \ + (_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ + _SHIFTL(tmem, 0, 9)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4)) \ + } /* * For RCP 2.0, the maximum number of texels that can be loaded @@ -3548,319 +3143,231 @@ _DW({ \ * the g*DPLoadBlock macros directly, you will need to handle this * tile manipulation yourself. RJM. */ -#define gDPLoadBlock(pkt, tile, uls, ult, lrs, dxt) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_LOADBLOCK, 24, 8) | \ - _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | \ - _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) |\ - _SHIFTL(dxt, 0, 12)); \ -}) +#define gDPLoadBlock(pkt, tile, uls, ult, lrs, dxt) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL((MIN(lrs, G_TX_LDBLK_MAX_TXL)), 12, 12) | _SHIFTL(dxt, 0, 12)); \ + }) -#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ -{ \ - (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | \ - _SHIFTL(ult, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | \ - _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) | \ - _SHIFTL(dxt, 0, 12)) \ -} +#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ + { \ + (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL((MIN(lrs, G_TX_LDBLK_MAX_TXL)), 12, 12) | _SHIFTL(dxt, 0, 12)) \ + } -#define gDPLoadTLUTCmd(pkt, tile, count) \ -_DW({ \ - Gfx *_g = (Gfx *)pkt; \ - \ - _g->words.w0 = _SHIFTL(G_LOADTLUT, 24, 8); \ - _g->words.w1 = _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10);\ -}) +#define gDPLoadTLUTCmd(pkt, tile, count) \ + _DW({ \ + Gfx* _g = (Gfx*)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_LOADTLUT, 24, 8); \ + _g->words.w1 = _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10); \ + }) -#define gsDPLoadTLUTCmd(tile, count) \ -{ \ - _SHIFTL(G_LOADTLUT, 24, 8), \ - _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10) \ -} +#define gsDPLoadTLUTCmd(tile, count) \ + { _SHIFTL(G_LOADTLUT, 24, 8), _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10) } -#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -_DW({ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -}) +#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) -#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * 1)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*1) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* Load fix rww 27jun95 */ /* The S at the end means odd lines are already word Swapped */ -#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, 0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * Allow tmem address and render tile to be specified. * The S at the end means odd lines are already word Swapped */ -#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * siz##_LINE_BYTES)+7)>>3, tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, \ + shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, 0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) - -#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, \ - (((width) * 1)+7)>>3, 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, 0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*1) + 7) >> 3, 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * allows tmem address to be specified */ -#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0, cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, G_TX_RENDERTILE, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, tmem, G_TX_RENDERTILE, pal, cmt, maskt, \ + shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * allows tmem address and render tile to be specified */ -#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, rtile, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, \ + shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * allows tmem address and render tile to be specified */ -#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ - gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ - tmem, rtile, pal, cmt, \ - maskt, shiftt, cms, masks, shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, \ + shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width)*siz##_LINE_BYTES) + 7) >> 3, tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) -#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* Here is the static form of the pre-swapped texture block loading */ /* See gDPLoadTextureBlockS() for reference. Basically, just don't calculate DxT, use 0 */ -#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0 , \ - cmt, maskt,shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, 0), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * Allow tmem address to be specified */ -#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - +#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), tmem, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * Allow tmem address and render_tile to be specified */ -#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - +#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, \ + shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPSetTileSize(rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * Allow tmem address and render_tile to be specified, useful when loading * mutilple tiles at a time. */ -#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, \ - height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ - 0 , cmt, maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ - CALC_DXT(width, siz##_BYTES)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, \ - ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPSetTileSize(rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * Allows tmem and render tile to be specified. Useful when loading @@ -3871,269 +3378,183 @@ _DW({ \ * calculate DxT, use 0 */ -#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ - gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0 , \ - cmt, maskt,shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ - (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), tmem,\ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + siz##_INCR) >> siz##_SHIFT) - 1, 0), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width)*siz##_LINE_BYTES) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPSetTileSize(rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -_DW({ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -}) +#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* Load fix rww 27jun95 */ /* The S at the end means odd lines are already word Swapped */ -#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, 0 ); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, 0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * 4-bit load block. Useful when loading multiple tiles */ -#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height,\ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * 4-bit load block. Allows tmem and render tile to be specified. Useful when * loading multiple tiles. The S means odd lines are already word swapped. */ -#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, 0 ); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, 0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) +#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) -#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ - cmt, maskt, shiftt, cms, masks, shifts); \ - gDPLoadSync(pkt); \ - gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ - (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ -} +#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) -#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - -#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, 0), gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * 4-bit load block. Allows tmem address and render tile to be specified. * Useful when loading multiple tiles. */ -#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - +#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * 4-bit load block. Allows tmem address and render tile to be specified. * Useful when loading multiple tiles. S means odd lines are already swapped. */ -#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) - +#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, 0), gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, ((height)-1) << G_TEXTURE_IMAGE_FRAC) /* * Allows tmem address to be specified */ -#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, \ - pal, cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ - gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ - maskt, shiftt, cms, masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ - CALC_DXT_4b(width)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ - ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ - ((height)-1) << G_TEXTURE_IMAGE_FRAC) +#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width) * (height) + 3) >> 2) - 1, CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width) >> 1) + 7) >> 3), tmem, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) #ifndef _HW_VERSION_1 -#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ -_DW({ \ - gDPSetTextureImage(pkt, fmt, siz, width, timg); \ - gDPSetTile(pkt, fmt, siz, \ - (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, \ - (uls)<> 3), 0, G_TX_LOADTILE, 0, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile(pkt, G_TX_LOADTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + }) #else /******** WORKAROUND hw 1 load tile bug ********/ -#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ - \ -_DW({ \ - int _loadtile_i, _loadtile_nw; Gfx *_loadtile_temp = pkt; \ - guDPLoadTextureTile(_loadtile_temp, timg, fmt, siz, \ - width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt); \ - _loadtile_nw = guGetDPLoadTextureTileSz(ult, lrt) - 1; \ - for(_loadtile_i = 0; _loadtile_i < _loadtile_nw; _loadtile_i++) \ - pkt; \ -}) +#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, uls, ult, lrs, lrt, pal, cms, cmt, masks, maskt, \ + shifts, shiftt) \ + \ + { \ + int _loadtile_i, _loadtile_nw; \ + Gfx* _loadtile_temp = pkt; \ + guDPLoadTextureTile(_loadtile_temp, timg, fmt, siz, width, height, uls, ult, lrs, lrt, pal, cms, cmt, masks, \ + maskt, shifts, shiftt); \ + _loadtile_nw = guGetDPLoadTextureTileSz(ult, lrt) - 1; \ + for (_loadtile_i = 0; _loadtile_i < _loadtile_nw; _loadtile_i++) \ + pkt; \ + } #endif /* HW_VERSION_1 */ @@ -4141,199 +3562,125 @@ _DW({ \ * Load texture tile. Allows tmem address and render tile to be specified. * Useful for loading multiple tiles. */ -#define gDPLoadMultiTile(pkt, timg, tmem, rtile, fmt, siz, width, height,\ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ -_DW({ \ - gDPSetTextureImage(pkt, fmt, siz, width, timg); \ - gDPSetTile(pkt, fmt, siz, \ - (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), tmem, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, \ - (uls)<> 3), tmem, G_TX_LOADTILE, 0, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile(pkt, G_TX_LOADTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), tmem, rtile, pal, cmt, maskt, \ + shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + }) - -#define gsDPLoadTextureTile(timg, fmt, siz, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz, width, timg), \ - gsDPSetTile(fmt, siz, \ - (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks,\ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, \ - (uls)<> 3), 0, G_TX_LOADTILE, 0, cmt, maskt, \ + shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile(G_TX_LOADTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, (((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC) /* * Load texture tile. Allows tmem address and render tile to be specified. * Useful for loading multiple tiles. */ -#define gsDPLoadMultiTile(timg, tmem, rtile, fmt, siz, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, siz, width, timg), \ - gsDPSetTile(fmt, siz, \ - (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), \ - tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<>3), \ - tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, \ - (uls)<> 3), tmem, G_TX_LOADTILE, 0, cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile(G_TX_LOADTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, (((((lrs) - (uls) + 1) * siz##_LINE_BYTES) + 7) >> 3), tmem, rtile, pal, cmt, maskt, \ + shiftt, cms, masks, shifts), \ + gsDPSetTileSize(rtile, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC) -#define gDPLoadTextureTile_4b(pkt, timg, fmt, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ -{ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_8b, ((width)>>1), timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ - masks, shifts); \ - gDPSetTileSize(pkt, G_TX_RENDERTILE, \ - (uls)<> 1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), 0, G_TX_LOADTILE, 0, cmt, maskt, \ + shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile(pkt, G_TX_LOADTILE, (uls) << (G_TEXTURE_IMAGE_FRAC - 1), (ult) << (G_TEXTURE_IMAGE_FRAC), \ + (lrs) << (G_TEXTURE_IMAGE_FRAC - 1), (lrt) << (G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + }) /* * Load texture tile. Allows tmem address and render tile to be specified. * Useful for loading multiple tiles. */ -#define gDPLoadMultiTile_4b(pkt, timg, tmem, rtile, fmt, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ -_DW({ \ - gDPSetTextureImage(pkt, fmt, G_IM_SIZ_8b, ((width)>>1), timg); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPLoadSync(pkt); \ - gDPLoadTile( pkt, G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ - gDPPipeSync(pkt); \ - gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ - (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ - rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts); \ - gDPSetTileSize(pkt, rtile, \ - (uls)<> 1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), tmem, G_TX_LOADTILE, 0, cmt, maskt, \ + shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile(pkt, G_TX_LOADTILE, (uls) << (G_TEXTURE_IMAGE_FRAC - 1), (ult) << (G_TEXTURE_IMAGE_FRAC), \ + (lrs) << (G_TEXTURE_IMAGE_FRAC - 1), (lrt) << (G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, \ + shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC); \ + }) -#define gsDPLoadTextureTile_4b(timg, fmt, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_8b, ((width)>>1), timg), \ - gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ - G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(G_TX_RENDERTILE, \ - (uls)<> 1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), 0, G_TX_LOADTILE, 0, cmt, maskt, \ + shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile(G_TX_LOADTILE, (uls) << (G_TEXTURE_IMAGE_FRAC - 1), (ult) << (G_TEXTURE_IMAGE_FRAC), \ + (lrs) << (G_TEXTURE_IMAGE_FRAC - 1), (lrt) << (G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), 0, G_TX_RENDERTILE, pal, cmt, maskt, \ + shiftt, cms, masks, shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC) /* * Load texture tile. Allows tmem address and render tile to be specified. * Useful for loading multiple tiles. */ -#define gsDPLoadMultiTile_4b(timg, tmem, rtile, fmt, width, height, \ - uls, ult, lrs, lrt, pal, \ - cms, cmt, masks, maskt, shifts, shiftt) \ - \ - gsDPSetTextureImage(fmt, G_IM_SIZ_8b, ((width)>>1), timg), \ - gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ - tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ - masks, shifts), \ - gsDPLoadSync(), \ - gsDPLoadTile( G_TX_LOADTILE, \ - (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (ult)<<(G_TEXTURE_IMAGE_FRAC), \ - (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ - (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ - gsDPPipeSync(), \ - gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ - tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ - shifts), \ - gsDPSetTileSize(rtile, \ - (uls)<> 1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), tmem, G_TX_LOADTILE, 0, cmt, maskt, \ + shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile(G_TX_LOADTILE, (uls) << (G_TEXTURE_IMAGE_FRAC - 1), (ult) << (G_TEXTURE_IMAGE_FRAC), \ + (lrs) << (G_TEXTURE_IMAGE_FRAC - 1), (lrt) << (G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs) - (uls) + 1) >> 1) + 7) >> 3), tmem, rtile, pal, cmt, maskt, shiftt, \ + cms, masks, shifts), \ + gsDPSetTileSize(rtile, (uls) << G_TEXTURE_IMAGE_FRAC, (ult) << G_TEXTURE_IMAGE_FRAC, \ + (lrs) << G_TEXTURE_IMAGE_FRAC, (lrt) << G_TEXTURE_IMAGE_FRAC) /* * Load a 16-entry palette (for 4-bit CI textures) @@ -4341,51 +3688,43 @@ _DW({ \ */ #ifndef _HW_VERSION_1 -#define gDPLoadTLUT_pal16(pkt, pal, dram) \ -{ \ - gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ - gDPTileSync(pkt); \ - gDPSetTile(pkt, 0, 0, 0, (256+(((pal)&0xF)*16)), \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0); \ - gDPLoadSync(pkt); \ - gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, 15); \ - gDPPipeSync(pkt); \ -} +#define gDPLoadTLUT_pal16(pkt, pal, dram) \ + _DW({ \ + gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, 0, 0, 0, (256 + (((pal)&0xf) * 16)), G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0); \ + gDPLoadSync(pkt); \ + gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, 15); \ + gDPPipeSync(pkt); \ + }) #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gDPLoadTLUT_pal16(pkt, pal, dram) \ - \ - _gDPLoadTextureBlock(pkt, dram, (256+(((pal)&0xF)*16)), \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*16, 1, \ - pal, 0, 0, 0, 0, 0, 0) +#define gDPLoadTLUT_pal16(pkt, pal, dram) \ + \ + _gDPLoadTextureBlock(pkt, dram, (256 + (((pal)&0xf) * 16)), G_IM_FMT_RGBA, G_IM_SIZ_16b, 4 * 16, 1, pal, 0, 0, 0, \ + 0, 0, 0) #endif /* _HW_VERSION_1 */ - /* * Load a 16-entry palette (for 4-bit CI textures) * Assumes a 16 entry tlut is being loaded, palette # is 0-15 */ #ifndef _HW_VERSION_1 -#define gsDPLoadTLUT_pal16(pal, dram) \ - \ - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), \ - gsDPTileSync(), \ - gsDPSetTile(0, 0, 0, (256+(((pal)&0xF)*16)), \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0), \ - gsDPLoadSync(), \ - gsDPLoadTLUTCmd(G_TX_LOADTILE, 15), \ - gsDPPipeSync() +#define gsDPLoadTLUT_pal16(pal, dram) \ + \ + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), gsDPTileSync(), \ + gsDPSetTile(0, 0, 0, (256 + (((pal)&0xf) * 16)), G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0), gsDPLoadSync(), \ + gsDPLoadTLUTCmd(G_TX_LOADTILE, 15), gsDPPipeSync() #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gsDPLoadTLUT_pal16(pal, dram) \ - \ - _gsDPLoadTextureBlock(dram, (256+(((pal)&0xF)*16)), \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*16, 1, \ - pal, 0, 0, 0, 0, 0, 0) +#define gsDPLoadTLUT_pal16(pal, dram) \ + \ + _gsDPLoadTextureBlock(dram, (256 + (((pal)&0xf) * 16)), G_IM_FMT_RGBA, G_IM_SIZ_16b, 4 * 16, 1, pal, 0, 0, 0, 0, \ + 0, 0) #endif /* _HW_VERSION_1 */ @@ -4395,403 +3734,372 @@ _DW({ \ */ #ifndef _HW_VERSION_1 -#define gDPLoadTLUT_pal256(pkt, dram) \ -{ \ - gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ - gDPTileSync(pkt); \ - gDPSetTile(pkt, 0, 0, 0, 256, \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0); \ - gDPLoadSync(pkt); \ - gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, 255); \ - gDPPipeSync(pkt); \ -} +#define gDPLoadTLUT_pal256(pkt, dram) \ + _DW({ \ + gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, 0, 0, 0, 256, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0); \ + gDPLoadSync(pkt); \ + gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, 255); \ + gDPPipeSync(pkt); \ + }) + +#define gDPLoadTLUT_pal128(pkt, pal, dram) \ + _DW({ \ + gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, 0, 0, 0, 256 + ((pal)&1) * 128, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0); \ + gDPLoadSync(pkt); \ + gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, 127); \ + gDPPipeSync(pkt); \ + }) #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gDPLoadTLUT_pal256(pkt, dram) \ - \ - _gDPLoadTextureBlock(pkt, dram, 256, \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*256, 1, \ - 0, 0, 0, 0, 0, 0, 0) - +#define gDPLoadTLUT_pal256(pkt, dram) \ + \ + _gDPLoadTextureBlock(pkt, dram, 256, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4 * 256, 1, 0, 0, 0, 0, 0, 0, 0) #endif /* _HW_VERSION_1 */ - #ifndef _HW_VERSION_1 -#define gsDPLoadTLUT_pal256(dram) \ - \ - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), \ - gsDPTileSync(), \ - gsDPSetTile(0, 0, 0, 256, \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0), \ - gsDPLoadSync(), \ - gsDPLoadTLUTCmd(G_TX_LOADTILE, 255), \ - gsDPPipeSync() +#define gsDPLoadTLUT_pal256(dram) \ + \ + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), gsDPTileSync(), \ + gsDPSetTile(0, 0, 0, 256, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0), gsDPLoadSync(), \ + gsDPLoadTLUTCmd(G_TX_LOADTILE, 255), gsDPPipeSync() #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gsDPLoadTLUT_pal256(dram) \ - \ - _gsDPLoadTextureBlock(dram, 256, \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*256, 1, \ - 0, 0, 0, 0, 0, 0, 0) +#define gsDPLoadTLUT_pal256(dram) \ + \ + _gsDPLoadTextureBlock(dram, 256, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4 * 256, 1, 0, 0, 0, 0, 0, 0, 0) #endif /* _HW_VERSION_1 */ - #ifndef _HW_VERSION_1 -#define gDPLoadTLUT(pkt, count, tmemaddr, dram) \ -_DW({ \ - gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ - gDPTileSync(pkt); \ - gDPSetTile(pkt, 0, 0, 0, tmemaddr, \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0); \ - gDPLoadSync(pkt); \ - gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, ((count)-1)); \ - gDPPipeSync(pkt); \ -}) +#define gDPLoadTLUT(pkt, count, tmemaddr, dram) \ + _DW({ \ + gDPSetTextureImage(pkt, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram); \ + gDPTileSync(pkt); \ + gDPSetTile(pkt, 0, 0, 0, tmemaddr, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0); \ + gDPLoadSync(pkt); \ + gDPLoadTLUTCmd(pkt, G_TX_LOADTILE, ((count)-1)); \ + gDPPipeSync(pkt); \ + }) #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gDPLoadTLUT(pkt, count, tmemaddr, dram) \ - \ - _gDPLoadTextureBlock(pkt, dram, tmemaddr, \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, count, \ - 0, 0, 0, 0, 0, 0, 0) +#define gDPLoadTLUT(pkt, count, tmemaddr, dram) \ + \ + _gDPLoadTextureBlock(pkt, dram, tmemaddr, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, count, 0, 0, 0, 0, 0, 0, 0) #endif /* _HW_VERSION_1 */ - #ifndef _HW_VERSION_1 -#define gsDPLoadTLUT(count, tmemaddr, dram) \ - \ - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), \ - gsDPTileSync(), \ - gsDPSetTile(0, 0, 0, tmemaddr, \ - G_TX_LOADTILE, 0 , 0, 0, 0, 0, 0, 0), \ - gsDPLoadSync(), \ - gsDPLoadTLUTCmd(G_TX_LOADTILE, ((count)-1)), \ - gsDPPipeSync() +#define gsDPLoadTLUT(count, tmemaddr, dram) \ + \ + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dram), gsDPTileSync(), \ + gsDPSetTile(0, 0, 0, tmemaddr, G_TX_LOADTILE, 0, 0, 0, 0, 0, 0, 0), gsDPLoadSync(), \ + gsDPLoadTLUTCmd(G_TX_LOADTILE, ((count)-1)), gsDPPipeSync() #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ -#define gsDPLoadTLUT(count, tmemaddr, dram) \ - \ - _gsDPLoadTextureBlock(dram, tmemaddr, \ - G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, count, \ - 0, 0, 0, 0, 0, 0, 0) +#define gsDPLoadTLUT(count, tmemaddr, dram) \ + \ + _gsDPLoadTextureBlock(dram, tmemaddr, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, count, 0, 0, 0, 0, 0, 0, 0) #endif /* _HW_VERSION_1 */ -#define gDPSetScissor(pkt, mode, ulx, uly, lrx, lry) \ -_DW({ \ - Gfx *_g = (Gfx *)pkt; \ - \ - _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(uly)*4.0F), 0, 12); \ - _g->words.w1 = _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(lry)*4.0F), 0, 12); \ -}) +#define gDPSetScissor(pkt, mode, ulx, uly, lrx, lry) \ + _DW({ \ + Gfx* _g = (Gfx*)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12); \ + }) +#define gDPSetScissorFrac(pkt, mode, ulx, uly, lrx, lry) \ + _DW({ \ + Gfx* _g = (Gfx*)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | _SHIFTL((int)((ulx)), 12, 12) | _SHIFTL((int)((uly)), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | _SHIFTL((int)((lrx)), 12, 12) | _SHIFTL((int)((lry)), 0, 12); \ + }) -#define gDPSetScissorFrac(pkt, mode, ulx, uly, lrx, lry) \ -_DW({ \ - Gfx *_g = (Gfx *)pkt; \ - \ - _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((ulx)), 12, 12) | \ - _SHIFTL((int)((uly)), 0, 12); \ - _g->words.w1 = _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((lrx)), 12, 12) | \ - _SHIFTL((int)((lry)), 0, 12); \ -}) +#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ + { \ + _SHIFTL(G_SETSCISSOR, 24, 8) | _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12), \ + _SHIFTL(mode, 24, 2) | _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12) \ + } -#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ -{ \ - _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(uly)*4.0F), 0, 12), \ - _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ - _SHIFTL((int)((float)(lry)*4.0F), 0, 12) \ -} +#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ + { \ + _SHIFTL(G_SETSCISSOR, 24, 8) | _SHIFTL((int)((ulx)), 12, 12) | _SHIFTL((int)((uly)), 0, 12), \ + _SHIFTL(mode, 24, 2) | _SHIFTL((int)(lrx), 12, 12) | _SHIFTL((int)(lry), 0, 12) \ + } -#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ -{ \ - _SHIFTL(G_SETSCISSOR, 24, 8) | \ - _SHIFTL((int)((ulx)), 12, 12) | \ - _SHIFTL((int)((uly)), 0, 12), \ - _SHIFTL(mode, 24, 2) | \ - _SHIFTL((int)(lrx), 12, 12) | \ - _SHIFTL((int)(lry), 0, 12) \ -} +#define gDPFillWideRectangle(pkt, ulx, uly, lrx, lry) \ + { \ + Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt); \ + _g0->words.w0 = _SHIFTL(G_FILLWIDERECT, 24, 8) | _SHIFTL((lrx), 2, 22); \ + _g0->words.w1 = _SHIFTL((lry), 2, 22); \ + _g1->words.w0 = _SHIFTL((ulx), 2, 22); \ + _g1->words.w1 = _SHIFTL((uly), 2, 22); \ + } /* Fraction never used in fill */ -#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ - _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10));\ - _g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10));\ -}) +#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10)); \ + _g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)); \ + }) -#define gsDPFillRectangle(ulx, uly, lrx, lry) \ -{ \ - (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | \ - _SHIFTL((lry), 2, 10)), \ - (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \ -} +#define gsDPFillRectangle(ulx, uly, lrx, lry) \ + { \ + (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10)), \ + (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \ + } /* like gDPFillRectangle but accepts negative arguments */ -#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ - _SHIFTL(MAX((lrx),0), 14, 10) | \ - _SHIFTL(MAX((lry),0), 2, 10)); \ - _g->words.w1 = (_SHIFTL(MAX((ulx),0), 14, 10) | \ - _SHIFTL(MAX((uly),0), 2, 10)); \ -} +#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL(MAX((lrx), 0), 14, 10) | _SHIFTL(MAX((lry), 0), 2, 10)); \ + _g->words.w1 = (_SHIFTL(MAX((ulx), 0), 14, 10) | _SHIFTL(MAX((uly), 0), 2, 10)); \ + }) -#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETCONVERT, 24, 8) | \ - _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | \ - _SHIFTR(k2, 5, 4)); \ - _g->words.w1 = (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | \ - _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)); \ -} +#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETCONVERT, 24, 8) | _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTR(k2, 5, 4)); \ + _g->words.w1 = (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)); \ + }) -#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ -{ \ - (_SHIFTL(G_SETCONVERT, 24, 8) | \ - _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTL(k2, 5, 4)), \ - (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | \ - _SHIFTL(k5, 0, 9)) \ -} +#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ + { \ + (_SHIFTL(G_SETCONVERT, 24, 8) | _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTL(k2, 5, 4)), \ + (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)) \ + } -#define gDPSetKeyR(pkt, cR, sR, wR) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(G_SETKEYR, 24, 8); \ - _g->words.w1 = (_SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | \ - _SHIFTL(sR, 0, 8)); \ -} +#define gDPSetKeyR(pkt, cR, sR, wR) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETKEYR, 24, 8); \ + _g->words.w1 = (_SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8)); \ + }) -#define gsDPSetKeyR(cR, sR, wR) \ -{ \ - _SHIFTL(G_SETKEYR, 24, 8), \ - _SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8) \ -} +#define gsDPSetKeyR(cR, sR, wR) \ + { _SHIFTL(G_SETKEYR, 24, 8), _SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8) } -#define gDPSetKeyGB(pkt, cG, sG, wG, cB, sB, wB) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETKEYGB, 24, 8) | \ - _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)); \ - _g->words.w1 = (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | \ - _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)); \ -} +#define gDPSetKeyGB(pkt, cG, sG, wG, cB, sB, wB) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)); \ + _g->words.w1 = (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)); \ + }) -#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ -{ \ - (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | \ - _SHIFTL(wB, 0, 12)), \ - (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | \ - _SHIFTL(sB, 0, 8)) \ -} +#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ + { \ + (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)), \ + (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)) \ + } -#define gDPNoParam(pkt, cmd) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8); \ - _g->words.w1 = 0; \ -}) +#define gDPNoParam(pkt, cmd) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = 0; \ + }) -#define gsDPNoParam(cmd) \ -{ \ - _SHIFTL(cmd, 24, 8), 0 \ -} +#define gsDPNoParam(cmd) \ + { _SHIFTL(cmd, 24, 8), 0 } -#define gDPParam(pkt, cmd, param) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = _SHIFTL(cmd, 24, 8); \ - _g->words.w1 = (param); \ -} +#define gDPParam(pkt, cmd, param) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = (param); \ + }) -#define gsDPParam(cmd, param) \ -{ \ - _SHIFTL(cmd, 24, 8), (param) \ -} +#define gsDPParam(cmd, param) \ + { _SHIFTL(cmd, 24, 8), (param) } /* Notice that textured rectangles are 128-bit commands, therefore * gsDPTextureRectangle() should not be used in display lists * under normal circumstances (use gsSPTextureRectangle()). * That is also why there is no gDPTextureRectangle() macros. */ -#define gsDPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{ \ - (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ -}, \ -{ \ - _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ - _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ -} +#define gsDPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + { \ + (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ + }, \ + { \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ + } -#define gDPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - if (pkt); \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - _g ++; \ - _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ - _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ -} +#define gDPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + if (pkt) \ + ; \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)); \ + _g++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ + }) -#define gsDPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{ \ - (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ -}, \ -{ \ - _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ - _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ -} +#define gsDPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + { \ + (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ + }, \ + { \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ + } -#define gDPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - if (pkt); \ - _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - _g ++; \ - _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ - _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ -} +#define gDPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + if (pkt) \ + ; \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)); \ + _g++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ + }) -#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ - (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)),\ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ - gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ - gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) +#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ + gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) -#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)));\ -}) +#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ + }) + +#define gSPWideTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + { \ + Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt), *_g2 = (Gfx*)(pkt); \ + \ + _g0->words.w0 = _SHIFTL(G_TEXRECT_WIDE, 24, 8) | _SHIFTL((xh), 0, 24); \ + _g0->words.w1 = _SHIFTL((yh), 0, 24); \ + _g1->words.w0 = (_SHIFTL(tile, 24, 3) | _SHIFTL((xl), 0, 24)); \ + _g1->words.w1 = _SHIFTL((yl), 0, 24); \ + _g2->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g2->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ + } + +#define gsSPWideTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + { { \ + (_SHIFTL(G_TEXRECT_WIDE, 24, 8) | _SHIFTL((xh), 0, 24)), \ + _SHIFTL((yh), 0, 24), \ + } }, \ + { { \ + (_SHIFTL((tile), 24, 3) | _SHIFTL((xl), 0, 24)), \ + _SHIFTL((yl), 0, 24), \ + } }, \ + { \ + { _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) } \ + } /* like gSPTextureRectangle but accepts negative position arguments */ -#define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | \ - _SHIFTL(MAX((s16)(xh),0), 12, 12) | \ - _SHIFTL(MAX((s16)(yh),0), 0, 12)); \ - _g->words.w1 = (_SHIFTL((tile), 24, 3) | \ - _SHIFTL(MAX((s16)(xl),0), 12, 12) | \ - _SHIFTL(MAX((s16)(yl),0), 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, \ - (_SHIFTL(((s) - \ - (((s16)(xl) < 0) ? \ - (((s16)(dsdx) < 0) ? \ - (MAX((((s16)(xl)*(s16)(dsdx))>>7),0)) : \ - (MIN((((s16)(xl)*(s16)(dsdx))>>7),0))) : 0)), \ - 16, 16) | \ - _SHIFTL(((t) - \ - (((yl) < 0) ? \ - (((s16)(dtdy) < 0) ? \ - (MAX((((s16)(yl)*(s16)(dtdy))>>7),0)) : \ - (MIN((((s16)(yl)*(s16)(dtdy))>>7),0))) : 0)), \ - 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL((dsdx), 16, 16) | \ - _SHIFTL((dtdy), 0, 16))); \ -}) +#define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = \ + (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(MAX((s16)(xh), 0), 12, 12) | _SHIFTL(MAX((s16)(yh), 0), 0, 12)); \ + _g->words.w1 = \ + (_SHIFTL((tile), 24, 3) | _SHIFTL(MAX((s16)(xl), 0), 12, 12) | _SHIFTL(MAX((s16)(yl), 0), 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, \ + (_SHIFTL(((s) - (((s16)(xl) < 0) ? (((s16)(dsdx) < 0) ? (MAX((((s16)(xl) * (s16)(dsdx)) >> 7), 0)) \ + : (MIN((((s16)(xl) * (s16)(dsdx)) >> 7), 0))) \ + : 0)), \ + 16, 16) | \ + _SHIFTL(((t) - (((yl) < 0) ? (((s16)(dtdy) < 0) ? (MAX((((s16)(yl) * (s16)(dtdy)) >> 7), 0)) \ + : (MIN((((s16)(yl) * (s16)(dtdy)) >> 7), 0))) \ + : 0)), \ + 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL((dsdx), 16, 16) | _SHIFTL((dtdy), 0, 16))); \ + }) -#define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ - (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ - _SHIFTL(yh, 0, 12)), \ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ - gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ - gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) +#define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)), \ + gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) -#define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) |\ - _SHIFTL(yh, 0, 12)); \ - _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ - _SHIFTL(yl, 0, 12)); \ - gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ - gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ -} +#define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ + }) -#define gsDPWord(wordhi, wordlo) \ - gsImmp1(G_RDPHALF_1, (unsigned int)(wordhi)), \ - gsImmp1(G_RDPHALF_2, (unsigned int)(wordlo)) +#define gsDPWord(wordhi, wordlo) \ + gsImmp1(G_RDPHALF_1, (unsigned int)(wordhi)), gsImmp1(G_RDPHALF_2, (unsigned int)(wordlo)) -#define gDPWord(pkt, wordhi, wordlo) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - gImmp1(pkt, G_RDPHALF_1, (unsigned int)(wordhi)); \ - gImmp1(pkt, G_RDPHALF_2, (unsigned int)(wordlo)); \ -} +#define gDPWord(pkt, wordhi, wordlo) \ + _DW({ \ + Gfx* _g = (Gfx*)(pkt); \ + \ + gImmp1(pkt, G_RDPHALF_1, (unsigned int)(wordhi)); \ + gImmp1(pkt, G_RDPHALF_2, (unsigned int)(wordlo)); \ + }) -#define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) -#define gsDPFullSync() gsDPNoParam(G_RDPFULLSYNC) -#define gDPTileSync(pkt) gDPNoParam(pkt, G_RDPTILESYNC) -#define gsDPTileSync() gsDPNoParam(G_RDPTILESYNC) -#define gDPPipeSync(pkt) gDPNoParam(pkt, G_RDPPIPESYNC) -#define gsDPPipeSync() gsDPNoParam(G_RDPPIPESYNC) -#define gDPLoadSync(pkt) gDPNoParam(pkt, G_RDPLOADSYNC) -#define gsDPLoadSync() gsDPNoParam(G_RDPLOADSYNC) -#define gDPNoOp(pkt) gDPNoParam(pkt, G_NOOP) -#define gsDPNoOp() gsDPNoParam(G_NOOP) -#define gDPNoOpTag(pkt, tag) gDPParam(pkt, G_NOOP, tag) -#define gsDPNoOpTag(tag) gsDPParam(G_NOOP, tag) +#define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) +#define gsDPFullSync() gsDPNoParam(G_RDPFULLSYNC) +#define gDPTileSync(pkt) gDPNoParam(pkt, G_RDPTILESYNC) +#define gsDPTileSync() gsDPNoParam(G_RDPTILESYNC) +#define gDPPipeSync(pkt) gDPNoParam(pkt, G_RDPPIPESYNC) +#define gsDPPipeSync() gsDPNoParam(G_RDPPIPESYNC) +#define gDPLoadSync(pkt) gDPNoParam(pkt, G_RDPLOADSYNC) +#define gsDPLoadSync() gsDPNoParam(G_RDPLOADSYNC) +#define gDPNoOp(pkt) gDPNoParam(pkt, G_NOOP) +#define gsDPNoOp() gsDPNoParam(G_NOOP) +#define gDPNoOpTag(pkt, tag) gDPParam(pkt, G_NOOP, tag) +#define gsDPNoOpTag(tag) gsDPParam(G_NOOP, tag) -#define gDPNoOpHere(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 1) -#define gDPNoOpString(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 2) -#define gDPNoOpWord(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 3) -#define gDPNoOpFloat(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 4) -#define gDPNoOpQuiet(pkt) gDma1p(pkt, G_NOOP, 0, 0, 5) -#define gDPNoOpVerbose(pkt, n) gDma1p(pkt, G_NOOP, 0, n, 5) -#define gDPNoOpCallBack(pkt, callback, arg) gDma1p(pkt, G_NOOP, callback, arg, 6) -#define gDPNoOpOpenDisp(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 7) -#define gDPNoOpCloseDisp(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 8) -#define gDPNoOpTag3(pkt, type, data, n) gDma1p(pkt, G_NOOP, data, n, type) +#define gDPNoOpHere(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 1) +#define gDPNoOpString(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 2) +#define gDPNoOpWord(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 3) +#define gDPNoOpFloat(pkt, data, n) gDma1p(pkt, G_NOOP, data, n, 4) +#define gDPNoOpQuiet(pkt) gDma1p(pkt, G_NOOP, 0, 0, 5) +#define gDPNoOpVerbose(pkt, n) gDma1p(pkt, G_NOOP, 0, n, 5) +#define gDPNoOpCallBack(pkt, callback, arg) gDma1p(pkt, G_NOOP, callback, arg, 6) +#define gDPNoOpOpenDisp(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 7) +#define gDPNoOpCloseDisp(pkt, file, line) gDma1p(pkt, G_NOOP, file, line, 8) +#define gDPNoOpTag3(pkt, type, data, n) gDma1p(pkt, G_NOOP, data, n, type) #endif #endif +#endif diff --git a/mm/include/PR/gs2dex.h b/mm/include/PR/gs2dex.h index 55ef95238..644b554a4 100644 --- a/mm/include/PR/gs2dex.h +++ b/mm/include/PR/gs2dex.h @@ -1,8 +1,10 @@ -#ifndef PR_GS2DEX_H -#define PR_GS2DEX_H +#ifndef PR_GS2DEX_H +#define PR_GS2DEX_H #include "ultratypes.h" +#include +#if 0 #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif @@ -10,9 +12,9 @@ extern "C" { /*===========================================================================* * Macro *===========================================================================*/ -#define GS_CALC_DXT(line) (((1<< G_TX_DXT_FRAC)-1)/(line)+1) -#define GS_PIX2TMEM(pix, siz) ((pix)>>(4-(siz))) -#define GS_PIX2DXT(pix, siz) GS_CALC_DXT(GS_PIX2TMEM((pix), (siz))) +#define GS_CALC_DXT(line) (((1 << G_TX_DXT_FRAC) - 1) / (line) + 1) +#define GS_PIX2TMEM(pix, siz) ((pix) >> (4 - (siz))) +#define GS_PIX2DXT(pix, siz) GS_CALC_DXT(GS_PIX2TMEM((pix), (siz))) /*===========================================================================* * Data structures for S2DEX microcode @@ -21,11 +23,11 @@ extern "C" { /*---------------------------------------------------------------------------* * Background *---------------------------------------------------------------------------*/ -#define G_BGLT_LOADBLOCK 0x0033 -#define G_BGLT_LOADTILE 0xFFF4 +#define G_BGLT_LOADBLOCK 0x0033 +#define G_BGLT_LOADTILE 0xFFF4 -#define G_BG_FLAG_FLIPS 0x01 -#define G_BG_FLAG_FLIPT 0x10 +#define G_BG_FLAG_FLIPS 0x01 +#define G_BG_FLAG_FLIPT 0x10 /* Non scalable background plane */ typedef struct { @@ -102,8 +104,8 @@ typedef union { /*---------------------------------------------------------------------------* * 2D Objects *---------------------------------------------------------------------------*/ -#define G_OBJ_FLAG_FLIPS 1<<0 /* inversion to S-direction */ -#define G_OBJ_FLAG_FLIPT 1<<4 /* nversion to T-direction */ +#define G_OBJ_FLAG_FLIPS 1 << 0 /* inversion to S-direction */ +#define G_OBJ_FLAG_FLIPT 1 << 4 /* nversion to T-direction */ typedef struct { s16 objX; /* s10.2 OBJ x-coordinate of upper-left end */ @@ -156,12 +158,12 @@ typedef union { /*---------------------------------------------------------------------------* * Loading into TMEM *---------------------------------------------------------------------------*/ -#define G_OBJLT_TXTRBLOCK 0x00001033 -#define G_OBJLT_TXTRTILE 0x00FC1034 -#define G_OBJLT_TLUT 0x00000030 +#define G_OBJLT_TXTRBLOCK 0x00001033 +#define G_OBJLT_TXTRTILE 0x00FC1034 +#define G_OBJLT_TLUT 0x00000030 -#define GS_TB_TSIZE(pix,siz) (GS_PIX2TMEM((pix),(siz))-1) -#define GS_TB_TLINE(pix,siz) (GS_CALC_DXT(GS_PIX2TMEM((pix),(siz)))) +#define GS_TB_TSIZE(pix, siz) (GS_PIX2TMEM((pix), (siz)) - 1) +#define GS_TB_TLINE(pix, siz) (GS_CALC_DXT(GS_PIX2TMEM((pix), (siz)))) typedef struct { u32 type; /* G_OBJLT_TXTRBLOCK divided into types */ @@ -174,8 +176,8 @@ typedef struct { u32 mask; /* STATE mask */ } uObjTxtrBlock_t; /* 24 bytes */ -#define GS_TT_TWIDTH(pix,siz) ((GS_PIX2TMEM((pix), (siz))<<2)-1) -#define GS_TT_THEIGHT(pix,siz) (((pix)<<2)-1) +#define GS_TT_TWIDTH(pix, siz) ((GS_PIX2TMEM((pix), (siz)) << 2) - 1) +#define GS_TT_THEIGHT(pix, siz) (((pix) << 2) - 1) typedef struct { u32 type; /* G_OBJLT_TXTRTILE divided into types */ @@ -188,8 +190,8 @@ typedef struct { u32 mask; /* STATE mask */ } uObjTxtrTile_t; /* 24 bytes */ -#define GS_PAL_HEAD(head) ((head)+256) -#define GS_PAL_NUM(num) ((num)-1) +#define GS_PAL_HEAD(head) ((head) + 256) +#define GS_PAL_NUM(num) ((num)-1) typedef struct { u32 type; /* G_OBJLT_TLUT divided into types */ @@ -221,134 +223,139 @@ typedef struct { * GBI Commands for S2DEX microcode *===========================================================================*/ /* GBI Header */ -#ifdef F3DEX_GBI_2 -#define G_OBJ_RECTANGLE_R 0xDA -#define G_OBJ_MOVEMEM 0xDC -#define G_RDPHALF_0 0xE4 -#define G_OBJ_RECTANGLE 0x01 -#define G_OBJ_SPRITE 0x02 -#define G_SELECT_DL 0x04 -#define G_OBJ_LOADTXTR 0x05 -#define G_OBJ_LDTX_SPRITE 0x06 -#define G_OBJ_LDTX_RECT 0x07 -#define G_OBJ_LDTX_RECT_R 0x08 -#define G_BG_1CYC 0x09 -#define G_BG_COPY 0x0A -#define G_OBJ_RENDERMODE 0x0B +#ifdef F3DEX_GBI_2 +#define G_OBJ_RECTANGLE_R 0xDA +#define G_OBJ_MOVEMEM 0xDC +#define G_RDPHALF_0 0xE4 +#define G_OBJ_RECTANGLE 0x01 +#define G_OBJ_SPRITE 0x02 +#define G_SELECT_DL 0x04 +#define G_OBJ_LOADTXTR 0x05 +#define G_OBJ_LDTX_SPRITE 0x06 +#define G_OBJ_LDTX_RECT 0x07 +#define G_OBJ_LDTX_RECT_R 0x08 +#define G_BG_1CYC 0x09 +#define G_BG_COPY 0x0A +#define G_OBJ_RENDERMODE 0x0B #else -#define G_BG_1CYC 0x01 -#define G_BG_COPY 0x02 -#define G_OBJ_RECTANGLE 0x03 -#define G_OBJ_SPRITE 0x04 -#define G_OBJ_MOVEMEM 0x05 -#define G_SELECT_DL 0xB0 -#define G_OBJ_RENDERMODE 0xB1 -#define G_OBJ_RECTANGLE_R 0xB2 -#define G_OBJ_LOADTXTR 0xC1 -#define G_OBJ_LDTX_SPRITE 0xC2 -#define G_OBJ_LDTX_RECT 0xC3 -#define G_OBJ_LDTX_RECT_R 0xC4 -#define G_RDPHALF_0 0xE4 +#define G_BG_1CYC 0x01 +#define G_BG_COPY 0x02 +#define G_OBJ_RECTANGLE 0x03 +#define G_OBJ_SPRITE 0x04 +#define G_OBJ_MOVEMEM 0x05 +#define G_SELECT_DL 0xB0 +#define G_OBJ_RENDERMODE 0xB1 +#define G_OBJ_RECTANGLE_R 0xB2 +#define G_OBJ_LOADTXTR 0xC1 +#define G_OBJ_LDTX_SPRITE 0xC2 +#define G_OBJ_LDTX_RECT 0xC3 +#define G_OBJ_LDTX_RECT_R 0xC4 +#define G_RDPHALF_0 0xE4 #endif /*---------------------------------------------------------------------------* * Background wrapped screen *---------------------------------------------------------------------------*/ -#define gSPBgRectangle(pkt, m, mptr) gDma0p((pkt),(m),(mptr),0) -#define gsSPBgRectangle(m, mptr) gsDma0p( (m),(mptr),0) -#define gSPBgRectCopy(pkt, mptr) gSPBgRectangle((pkt), G_BG_COPY, (mptr)) -#define gsSPBgRectCopy(mptr) gsSPBgRectangle( G_BG_COPY, (mptr)) -#define gSPBgRect1Cyc(pkt, mptr) gSPBgRectangle((pkt), G_BG_1CYC, (mptr)) -#define gsSPBgRect1Cyc(mptr) gsSPBgRectangle( G_BG_1CYC, (mptr)) +#define gSPBgRectangle(pkt, m, mptr) gDma0p((pkt), (m), (mptr), 0) +#define gsSPBgRectangle(m, mptr) gsDma0p((m), (mptr), 0) +#define gSPBgRectCopy(pkt, mptr) gSPBgRectangle((pkt), G_BG_COPY, (mptr)) +#define gsSPBgRectCopy(mptr) gsSPBgRectangle(G_BG_COPY, (mptr)) +#define gSPBgRect1Cyc(pkt, mptr) gSPBgRectangle((pkt), G_BG_1CYC, (mptr)) +#define gsSPBgRect1Cyc(mptr) gsSPBgRectangle(G_BG_1CYC, (mptr)) /*---------------------------------------------------------------------------* * 2D Objects *---------------------------------------------------------------------------*/ -#define gSPObjSprite(pkt, mptr) gDma0p((pkt),G_OBJ_SPRITE, (mptr),0) -#define gsSPObjSprite(mptr) gsDma0p( G_OBJ_SPRITE, (mptr),0) -#define gSPObjRectangle(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE, (mptr),0) -#define gsSPObjRectangle(mptr) gsDma0p( G_OBJ_RECTANGLE, (mptr),0) -#define gSPObjRectangleR(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE_R,(mptr),0) -#define gsSPObjRectangleR(mptr) gsDma0p( G_OBJ_RECTANGLE_R,(mptr),0) +#define gSPObjSprite(pkt, mptr) gDma0p((pkt), G_OBJ_SPRITE, (mptr), 0) +#define gsSPObjSprite(mptr) gsDma0p(G_OBJ_SPRITE, (mptr), 0) +#define gSPObjRectangle(pkt, mptr) gDma0p((pkt), G_OBJ_RECTANGLE, (mptr), 0) +#define gsSPObjRectangle(mptr) gsDma0p(G_OBJ_RECTANGLE, (mptr), 0) +#define gSPObjRectangleR(pkt, mptr) gDma0p((pkt), G_OBJ_RECTANGLE_R, (mptr), 0) +#define gsSPObjRectangleR(mptr) gsDma0p(G_OBJ_RECTANGLE_R, (mptr), 0) /*---------------------------------------------------------------------------* * 2D Matrix *---------------------------------------------------------------------------*/ -#define gSPObjMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),0,23) -#define gsSPObjMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),0,23) -#define gSPObjSubMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),2, 7) -#define gsSPObjSubMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),2, 7) +#define gSPObjMatrix(pkt, mptr) gDma1p((pkt), G_OBJ_MOVEMEM, (mptr), 0, 23) +#define gsSPObjMatrix(mptr) gsDma1p(G_OBJ_MOVEMEM, (mptr), 0, 23) +#define gSPObjSubMatrix(pkt, mptr) gDma1p((pkt), G_OBJ_MOVEMEM, (mptr), 2, 7) +#define gsSPObjSubMatrix(mptr) gsDma1p(G_OBJ_MOVEMEM, (mptr), 2, 7) /*---------------------------------------------------------------------------* * Loading into TMEM *---------------------------------------------------------------------------*/ -#define gSPObjLoadTxtr(pkt, tptr) gDma0p((pkt),G_OBJ_LOADTXTR, (tptr),23) -#define gsSPObjLoadTxtr(tptr) gsDma0p( G_OBJ_LOADTXTR, (tptr),23) -#define gSPObjLoadTxSprite(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_SPRITE,(tptr),47) -#define gsSPObjLoadTxSprite(tptr) gsDma0p( G_OBJ_LDTX_SPRITE,(tptr),47) -#define gSPObjLoadTxRect(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT, (tptr),47) -#define gsSPObjLoadTxRect(tptr) gsDma0p( G_OBJ_LDTX_RECT, (tptr),47) -#define gSPObjLoadTxRectR(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT_R,(tptr),47) -#define gsSPObjLoadTxRectR(tptr) gsDma0p( G_OBJ_LDTX_RECT_R,(tptr),47) +#define gSPObjLoadTxtr(pkt, tptr) gDma0p((pkt), G_OBJ_LOADTXTR, (tptr), 23) +#define gsSPObjLoadTxtr(tptr) gsDma0p(G_OBJ_LOADTXTR, (tptr), 23) +#define gSPObjLoadTxSprite(pkt, tptr) gDma0p((pkt), G_OBJ_LDTX_SPRITE, (tptr), 47) +#define gsSPObjLoadTxSprite(tptr) gsDma0p(G_OBJ_LDTX_SPRITE, (tptr), 47) +#define gSPObjLoadTxRect(pkt, tptr) gDma0p((pkt), G_OBJ_LDTX_RECT, (tptr), 47) +#define gsSPObjLoadTxRect(tptr) gsDma0p(G_OBJ_LDTX_RECT, (tptr), 47) +#define gSPObjLoadTxRectR(pkt, tptr) gDma0p((pkt), G_OBJ_LDTX_RECT_R, (tptr), 47) +#define gsSPObjLoadTxRectR(tptr) gsDma0p(G_OBJ_LDTX_RECT_R, (tptr), 47) /*---------------------------------------------------------------------------* * Select Display List *---------------------------------------------------------------------------*/ -#define gSPSelectDL(pkt, mptr, sid, flag, mask) \ -{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xFFFF, (sid)); \ - gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } -#define gsSPSelectDL(mptr, sid, flag, mask) \ -{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xFFFF, (sid)); \ - gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } -#define gSPSelectBranchDL(pkt, mptr, sid, flag, mask) \ -{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xFFFF, (sid)); \ - gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } -#define gsSPSelectBranchDL(mptr, sid, flag, mask) \ -{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xFFFF, (sid)); \ - gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } +#define gSPSelectDL(pkt, mptr, sid, flag, mask) \ + { \ + gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr)&0xFFFF, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); \ + } +#define gsSPSelectDL(mptr, sid, flag, mask) \ + { \ + gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr)&0xFFFF, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); \ + } +#define gSPSelectBranchDL(pkt, mptr, sid, flag, mask) \ + { \ + gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr)&0xFFFF, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); \ + } +#define gsSPSelectBranchDL(mptr, sid, flag, mask) \ + { \ + gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr)&0xFFFF, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); \ + } /*---------------------------------------------------------------------------* * Set general status *---------------------------------------------------------------------------*/ -#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG */ +#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG */ -#define gSPSetStatus(pkt, sid, val) \ - gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) -#define gsSPSetStatus(sid, val) \ - gsMoveWd( G_MW_GENSTAT, (sid), (val)) +#define gSPSetStatus(pkt, sid, val) gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) +#define gsSPSetStatus(sid, val) gsMoveWd(G_MW_GENSTAT, (sid), (val)) /*---------------------------------------------------------------------------* * Set Object Render Mode *---------------------------------------------------------------------------*/ -#define G_OBJRM_NOTXCLAMP 0x01 -#define G_OBJRM_XLU 0x02 /* Ignored */ -#define G_OBJRM_ANTIALIAS 0x04 /* Ignored */ -#define G_OBJRM_BILERP 0x08 -#define G_OBJRM_SHRINKSIZE_1 0x10 -#define G_OBJRM_SHRINKSIZE_2 0x20 -#define G_OBJRM_WIDEN 0x40 +#define G_OBJRM_NOTXCLAMP 0x01 +#define G_OBJRM_XLU 0x02 /* Ignored */ +#define G_OBJRM_ANTIALIAS 0x04 /* Ignored */ +#define G_OBJRM_BILERP 0x08 +#define G_OBJRM_SHRINKSIZE_1 0x10 +#define G_OBJRM_SHRINKSIZE_2 0x20 +#define G_OBJRM_WIDEN 0x40 -#define gSPObjRenderMode(pkt, mode) gImmp1((pkt),G_OBJ_RENDERMODE,(mode)) -#define gsSPObjRenderMode(mode) gsImmp1( G_OBJ_RENDERMODE,(mode)) +#define gSPObjRenderMode(pkt, mode) gImmp1((pkt), G_OBJ_RENDERMODE, (mode)) +#define gsSPObjRenderMode(mode) gsImmp1(G_OBJ_RENDERMODE, (mode)) /*===========================================================================* * Render Mode Macro *===========================================================================*/ -#define RM_RA_SPRITE(clk) \ - AA_EN | CVG_DST_CLAMP | \ - CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ +#define RM_RA_SPRITE(clk) \ + AA_EN | CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) -#define G_RM_SPRITE G_RM_OPA_SURF -#define G_RM_SPRITE2 G_RM_OPA_SURF2 -#define G_RM_RA_SPRITE RM_RA_SPRITE(1) -#define G_RM_RA_SPRITE2 RM_RA_SPRITE(2) -#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR -#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 -#define G_RM_XLU_SPRITE G_RM_XLU_SURF -#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 -#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF -#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 +#define G_RM_SPRITE G_RM_OPA_SURF +#define G_RM_SPRITE2 G_RM_OPA_SURF2 +#define G_RM_RA_SPRITE RM_RA_SPRITE(1) +#define G_RM_RA_SPRITE2 RM_RA_SPRITE(2) +#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR +#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 +#define G_RM_XLU_SPRITE G_RM_XLU_SURF +#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 +#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF +#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 /*===========================================================================* * External functions @@ -363,9 +370,9 @@ extern u64 gspS2DEX2_xbusTextStart[], gspS2DEX2_xbusTextEnd[]; extern u64 gspS2DEX2_xbusDataStart[], gspS2DEX2_xbusDataEnd[]; extern void guS2DInitBg(uObjBg *); -#ifdef F3DEX_GBI_2 -# define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ -# define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ +#ifdef F3DEX_GBI_2 +#define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ +#define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8); extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *); #else @@ -377,5 +384,5 @@ extern void guS2DInitBg(uObjBg *); } #endif #endif /* GS2DEX_H */ - +#endif /*======== End of gs2dex.h ========*/ diff --git a/mm/include/PR/os_cont.h b/mm/include/PR/os_cont.h index 6a63b8901..5c0a1d562 100644 --- a/mm/include/PR/os_cont.h +++ b/mm/include/PR/os_cont.h @@ -1,6 +1,7 @@ #ifndef PR_OS_CONT_H #define PR_OS_CONT_H - +#include +#if 0 #include "ultratypes.h" #include "os_message.h" @@ -8,65 +9,65 @@ typedef struct { /* 0x0 */ u16 type; /* 0x2 */ u8 status; - /* 0x3 */ u8 errno; + /* 0x3 */ u8 err_no; } OSContStatus; // size = 0x4 typedef struct { /* 0x0 */ u16 button; /* 0x2 */ s8 stick_x; /* 0x3 */ s8 stick_y; - /* 0x4 */ u8 errno; + /* 0x4 */ u8 err_no; } OSContPad; // size = 0x6 -#define MAXCONTROLLERS 4 +#define MAXCONTROLLERS 4 /* controller errors */ -#define CONT_NO_RESPONSE_ERROR 0x8 -#define CONT_OVERRUN_ERROR 0x4 +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 /* Controller type */ -#define CONT_ABSOLUTE 0x0001 -#define CONT_RELATIVE 0x0002 -#define CONT_JOYPORT 0x0004 -#define CONT_EEPROM 0x8000 -#define CONT_EEP16K 0x4000 -#define CONT_TYPE_MASK 0x1F07 -#define CONT_TYPE_NORMAL 0x0005 -#define CONT_TYPE_MOUSE 0x0002 -#define CONT_TYPE_VOICE 0x0100 +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1F07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 /* Controller status */ -#define CONT_CARD_ON 0x01 -#define CONT_CARD_PULL 0x02 -#define CONT_ADDR_CRC_ER 0x04 -#define CONT_EEPROM_BUSY 0x80 +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 // TODO: use real libultra button defines instead of this /* Buttons */ -#define BTN_CRIGHT 0x0001 -#define BTN_CLEFT 0x0002 -#define BTN_CDOWN 0x0004 -#define BTN_CUP 0x0008 -#define BTN_R 0x0010 -#define BTN_L 0x0020 -#define BTN_RESET 0x0080 -#define BTN_DRIGHT 0x0100 -#define BTN_DLEFT 0x0200 -#define BTN_DDOWN 0x0400 -#define BTN_DUP 0x0800 -#define BTN_START 0x1000 -#define BTN_Z 0x2000 -#define BTN_B 0x4000 -#define BTN_A 0x8000 +#define BTN_CRIGHT 0x0001 +#define BTN_CLEFT 0x0002 +#define BTN_CDOWN 0x0004 +#define BTN_CUP 0x0008 +#define BTN_R 0x0010 +#define BTN_L 0x0020 +#define BTN_RESET 0x0080 +#define BTN_DRIGHT 0x0100 +#define BTN_DLEFT 0x0200 +#define BTN_DDOWN 0x0400 +#define BTN_DUP 0x0800 +#define BTN_START 0x1000 +#define BTN_Z 0x2000 +#define BTN_B 0x4000 +#define BTN_A 0x8000 -#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ -#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ -#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ -#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ -#define CONT_ERR_NOT_READY 12 -#define CONT_ERR_VOICE_MEMORY 13 -#define CONT_ERR_VOICE_WORD 14 -#define CONT_ERR_VOICE_NO_RESPONSE 15 +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data); @@ -75,5 +76,6 @@ s32 osContStartReadData(OSMesgQueue* mq); s32 osContSetCh(u8 ch); void osContGetQuery(OSContStatus* data); void osContGetReadData(OSContPad* data); +#endif #endif diff --git a/mm/include/PR/os_convert.h b/mm/include/PR/os_convert.h index 468d77f9a..76a984fbd 100644 --- a/mm/include/PR/os_convert.h +++ b/mm/include/PR/os_convert.h @@ -12,7 +12,7 @@ #define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) #define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) -#define OS_K0_TO_PHYSICAL(x) (u32)(((char*)(x)-0x80000000)) +#define OS_K0_TO_PHYSICAL(x) (x) #define OS_K1_TO_PHYSICAL(x) (u32)(((char*)(x)-0xA0000000)) #define OS_PHYSICAL_TO_K0(x) (void*)(((u32)(x)+0x80000000)) diff --git a/mm/include/PR/os_exception.h b/mm/include/PR/os_exception.h index 7140c9663..37fcbd915 100644 --- a/mm/include/PR/os_exception.h +++ b/mm/include/PR/os_exception.h @@ -35,15 +35,15 @@ typedef u32 OSHWIntr; #define RCP_IMASKSHIFT 16 -OSIntMask osGetIntMask(void); -OSIntMask osSetIntMask(OSIntMask im); +//OSIntMask osGetIntMask(void); +//OSIntMask osSetIntMask(OSIntMask im); // Internal -void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd); -void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd); -void __osSetGlobalIntMask(OSHWIntr mask); -void __osResetGlobalIntMask(OSHWIntr mask); +//void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void* stackEnd); +//void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**handler)(void), void** stackEnd); +//void __osSetGlobalIntMask(OSHWIntr mask); +//void __osResetGlobalIntMask(OSHWIntr mask); #endif diff --git a/mm/include/PR/os_internal.h b/mm/include/PR/os_internal.h index f2c5bfa17..516f80cdc 100644 --- a/mm/include/PR/os_internal.h +++ b/mm/include/PR/os_internal.h @@ -1,14 +1,28 @@ #ifndef PR_OS_INTERNAL_H #define PR_OS_INTERNAL_H +#include + +#if 0 #include "ultratypes.h" #include "os_message.h" #include "os_pi.h" #include "os_internal_rsp.h" typedef struct __osHwInt { - /* 0x00 */ s32 (*handler)(void); - /* 0x04 */ void* stackEnd; + /* 0x00 */ OSMesgQueue* queue; + /* 0x04 */ OSMesg msg; } __osHwInt; // size = 0x08 +typedef struct { + /* 0x00 */ u32 initialized; + /* 0x04 */ OSThread* mgrThread; + /* 0x08 */ OSMesgQueue* cmdQueue; + /* 0x0C */ OSMesgQueue* eventQueue; + /* 0x10 */ OSMesgQueue* accessQueue; + /* 0x14 */ s32 (*piDmaCallback)(s32, uintptr_t, void*, size_t); + /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, uintptr_t, void*, size_t); +} OSMgrArgs; // size = 0x1C + #endif +#endif \ No newline at end of file diff --git a/mm/include/PR/os_libc.h b/mm/include/PR/os_libc.h index 755f24692..61751d6a1 100644 --- a/mm/include/PR/os_libc.h +++ b/mm/include/PR/os_libc.h @@ -2,14 +2,16 @@ #define PR_OS_LIBC_H #include "libc/stdarg.h" +#include - +#ifndef __GNUC__ void bcopy(void* __src, void* __dest, int __n); int bcmp(void* __s1, void* __s2, int __n); void bzero(void* begin, int length); -s32 vsprintf(char* dst, char* fmt, va_list args); +// s32 vsprintf(char* dst, char* fmt, va_list args); int sprintf(char* dst, const char* fmt, ...); void osSyncPrintf(const char* fmt, ...); - #endif + +#endif \ No newline at end of file diff --git a/mm/include/PR/os_message.h b/mm/include/PR/os_message.h index bb577f57b..c41cb1702 100644 --- a/mm/include/PR/os_message.h +++ b/mm/include/PR/os_message.h @@ -3,6 +3,10 @@ #include "os_thread.h" +#include + +#if 0 + typedef void* OSMesg; typedef u32 OSEvent; @@ -15,40 +19,41 @@ typedef struct OSMesgQueue { /* 0x14 */ OSMesg* msg; } OSMesgQueue; // size = 0x18 -#define OS_NUM_EVENTS 15 +#define OS_NUM_EVENTS 15 -#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ -#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ -#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ -#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ -#define OS_EVENT_SP 4 /* SP task done interrupt */ -#define OS_EVENT_SI 5 /* SI (controller) interrupt */ -#define OS_EVENT_AI 6 /* AI interrupt */ -#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ -#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ -#define OS_EVENT_DP 9 /* DP full sync interrupt */ -#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ -#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ -#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ -#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ -#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ +#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ +#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ +#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ +#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ +#define OS_EVENT_SP 4 /* SP task done interrupt */ +#define OS_EVENT_SI 5 /* SI (controller) interrupt */ +#define OS_EVENT_AI 6 /* AI interrupt */ +#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ +#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ +#define OS_EVENT_DP 9 /* DP full sync interrupt */ +#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ +#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ +#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ +#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ +#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ -#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ -#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ -#define OS_EVENT_RDB_DATA_DONE 17 /* read of host io data complete */ -#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ -#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ -#define OS_EVENT_RDB_DBG_DONE 20 -#define OS_EVENT_RDB_FLUSH_PROF 21 -#define OS_EVENT_RDB_ACK_PROF 22 +#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ +#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ +#define OS_EVENT_RDB_DATA_DONE 17 /* read of host io data complete */ +#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ +#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ +#define OS_EVENT_RDB_DBG_DONE 20 +#define OS_EVENT_RDB_FLUSH_PROF 21 +#define OS_EVENT_RDB_ACK_PROF 22 -#define OS_MESG_NOBLOCK 0 -#define OS_MESG_BLOCK 1 +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 -#define MQ_GET_COUNT(mq) ((mq)->validCount) +#endif +#define MQ_GET_COUNT(mq) ((mq)->validCount) #define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) -#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count); s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags); @@ -57,5 +62,4 @@ s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags); void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg m); - -#endif +#endif \ No newline at end of file diff --git a/mm/include/PR/os_pfs.h b/mm/include/PR/os_pfs.h index 4ce1acd52..d17df8179 100644 --- a/mm/include/PR/os_pfs.h +++ b/mm/include/PR/os_pfs.h @@ -1,73 +1,76 @@ #ifndef PR_OS_PFS_H #define PR_OS_PFS_H +#include +#if 0 + #include "os.h" /* File System size */ -#define OS_PFS_VERSION 0x0200 -#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) -#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) +#define OS_PFS_VERSION 0x0200 +#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) +#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) #define PFS_INODE_SIZE_PER_PAGE 128 -#define PFS_FILE_NAME_LEN 16 -#define PFS_FILE_EXT_LEN 4 -#define BLOCKSIZE 32 -#define PFS_ONE_PAGE 8 -#define PFS_MAX_BANKS 62 +#define PFS_FILE_NAME_LEN 16 +#define PFS_FILE_EXT_LEN 4 +#define BLOCKSIZE 32 +#define PFS_ONE_PAGE 8 +#define PFS_MAX_BANKS 62 /* File System flag */ -#define PFS_READ 0 -#define PFS_WRITE 1 -#define PFS_CREATE 2 +#define PFS_READ 0 +#define PFS_WRITE 1 +#define PFS_CREATE 2 /* File System status */ -#define PFS_INITIALIZED 0x1 -#define PFS_CORRUPTED 0x2 -#define PFS_ID_BROKEN 0x4 -#define PFS_MOTOR_INITIALIZED 0x8 -#define PFS_GBPAK_INITIALIZED 0x10 +#define PFS_INITIALIZED 0x1 +#define PFS_CORRUPTED 0x2 +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 /* Definition for page usage */ -#define PFS_EOF 1 -#define PFS_PAGE_NOT_EXIST 2 -#define PFS_PAGE_NOT_USED 3 +#define PFS_EOF 1 +#define PFS_PAGE_NOT_EXIST 2 +#define PFS_PAGE_NOT_USED 3 /* File System error number */ -#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ -#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ -#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ -#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR -#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ -#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ -#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ -#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ -#define PFS_ERR_EXIST 9 /* file exists*/ -#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ -#define PFS_ERR_DEVICE 11 /* wrong device type*/ -#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ -#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ +#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ +#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ +#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ +#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR +#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ +#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ +#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ +#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ +#define PFS_ERR_EXIST 9 /* file exists*/ +#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ +#define PFS_ERR_DEVICE 11 /* wrong device type*/ +#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ +#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ /* Definition for bank */ -#define PFS_ID_BANK_256K 0 -#define PFS_ID_BANK_1M 4 -#define PFS_BANKS_256K 1 +#define PFS_ID_BANK_256K 0 +#define PFS_ID_BANK_1M 4 +#define PFS_BANKS_256K 1 -#define PFS_WRITTEN 2 -#define DEF_DIR_PAGES 2 +#define PFS_WRITTEN 2 +#define DEF_DIR_PAGES 2 -#define PFS_ID_0AREA 1 -#define PFS_ID_1AREA 3 -#define PFS_ID_2AREA 4 -#define PFS_ID_3AREA 6 -#define PFS_LABEL_AREA 7 -#define PFS_ID_PAGE PFS_ONE_PAGE * 0 +#define PFS_ID_0AREA 1 +#define PFS_ID_1AREA 3 +#define PFS_ID_2AREA 4 +#define PFS_ID_3AREA 6 +#define PFS_LABEL_AREA 7 +#define PFS_ID_PAGE PFS_ONE_PAGE * 0 -#define PFS_BANK_LAPPED_BY 8 /* => u8 */ +#define PFS_BANK_LAPPED_BY 8 /* => u8 */ #define PFS_SECTOR_PER_BANK 32 -#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) -#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) +#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) +#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE / PFS_SECTOR_PER_BANK) typedef struct { /* 0x00 */ s32 status; @@ -145,5 +148,5 @@ s32 osPfsFileState(OSPfs* pfs, s32 fileNo, OSPfsState* state); s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern); s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes); - +#endif #endif diff --git a/mm/include/PR/os_pi.h b/mm/include/PR/os_pi.h index 7959ac7b3..788b44f92 100644 --- a/mm/include/PR/os_pi.h +++ b/mm/include/PR/os_pi.h @@ -1,6 +1,9 @@ #ifndef PR_OS_PI_H #define PR_OS_PI_H +#include + +#if 0 #include "ultratypes.h" #include "os_message.h" #include "libc/stddef.h" @@ -70,37 +73,36 @@ typedef struct OSDevMgr { /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, uintptr_t, void*, size_t); } OSDevMgr; // size = 0x1C - - -#define OS_READ 0 -#define OS_WRITE 1 +#define OS_READ 0 +#define OS_WRITE 1 /* * I/O message types */ -#define OS_MESG_TYPE_BASE 10 -#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0) -#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1) -#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2) -#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3) -#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4) -#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5) -#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6) +#define OS_MESG_TYPE_BASE 10 +#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE + 0) +#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE + 1) +#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE + 2) +#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE + 3) +#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE + 4) +#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE + 5) +#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE + 6) /* * I/O message priority */ -#define OS_MESG_PRI_NORMAL 0 -#define OS_MESG_PRI_HIGH 1 +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 /* * PI/EPI */ -#define PI_DOMAIN1 0 -#define PI_DOMAIN2 1 +#define PI_DOMAIN1 0 +#define PI_DOMAIN2 1 extern OSPiHandle* __osPiTable; +#endif void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt); OSPiHandle* osCartRomInit(void); @@ -109,5 +111,4 @@ s32 osEPiWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data); s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data); s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction); s32 osEPiLinkHandle(OSPiHandle* handle); - #endif diff --git a/mm/include/PR/sched.h b/mm/include/PR/os_sched.h similarity index 100% rename from mm/include/PR/sched.h rename to mm/include/PR/os_sched.h diff --git a/mm/include/PR/os_system.h b/mm/include/PR/os_system.h index b55ca11a1..dc3c90df9 100644 --- a/mm/include/PR/os_system.h +++ b/mm/include/PR/os_system.h @@ -6,15 +6,14 @@ /* * Values for osTvType */ -#define OS_TV_PAL 0 -#define OS_TV_NTSC 1 -#define OS_TV_MPAL 2 +#define OS_TV_PAL 0 +#define OS_TV_NTSC 1 +#define OS_TV_MPAL 2 /* * Size of buffer the retains contents after NMI */ -#define OS_APP_NMI_BUFSIZE 64 - +#define OS_APP_NMI_BUFSIZE 64 extern s32 osTvType; extern s32 osRomType; @@ -23,7 +22,7 @@ extern s32 osResetType; extern s32 osCicId; extern s32 osVersion; extern u32 osMemSize; -extern s32 osAppNMIBuffer[]; +extern s32 osAppNMIBuffer[8]; extern u64 osClockRate; @@ -34,4 +33,4 @@ extern u32 __OSGlobalIntMask; u32 osGetMemSize(void); s32 osAfterPreNMI(void); -#endif +#endif \ No newline at end of file diff --git a/mm/include/PR/os_thread.h b/mm/include/PR/os_thread.h index b88520087..2746e47e6 100644 --- a/mm/include/PR/os_thread.h +++ b/mm/include/PR/os_thread.h @@ -2,9 +2,10 @@ #define PR_OS_THREAD_H #include "ultratypes.h" - -#define OS_FLAG_CPU_BREAK 1 -#define OS_FLAG_FAULT 2 +#include +#if 0 +#define OS_FLAG_CPU_BREAK 1 +#define OS_FLAG_FAULT 2 typedef s32 OSPri; typedef s32 OSId; @@ -47,28 +48,27 @@ typedef struct OSThread { /* 0x20 */ __OSThreadContext context; } OSThread; // size = 0x1B0 -#define OS_STATE_STOPPED (1 << 0) -#define OS_STATE_RUNNABLE (1 << 1) -#define OS_STATE_RUNNING (1 << 2) -#define OS_STATE_WAITING (1 << 3) +#define OS_STATE_STOPPED (1 << 0) +#define OS_STATE_RUNNABLE (1 << 1) +#define OS_STATE_RUNNING (1 << 2) +#define OS_STATE_WAITING (1 << 3) - -#define OS_PRIORITY_IDLE 0 -#define OS_PRIORITY_MAIN 10 -#define OS_PRIORITY_GRAPH 11 -#define OS_PRIORITY_AUDIOMGR 12 -#define OS_PRIORITY_PADMGR 14 -#define OS_PRIORITY_SCHED 15 -#define OS_PRIORITY_DMAMGR 16 -#define OS_PRIORITY_IRQMGR 17 -#define OS_PRIORITY_PIMGR 150 -#define OS_PRIORITY_FAULTCLIENT 126 -#define OS_PRIORITY_FAULT 127 -#define OS_PRIORITY_APPMAX 127 -#define OS_PRIORITY_RMONSPIN 200 -#define OS_PRIORITY_RMON 250 -#define OS_PRIORITY_VIMGR 254 -#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_IDLE 0 +#define OS_PRIORITY_MAIN 10 +#define OS_PRIORITY_GRAPH 11 +#define OS_PRIORITY_AUDIOMGR 12 +#define OS_PRIORITY_PADMGR 14 +#define OS_PRIORITY_SCHED 15 +#define OS_PRIORITY_DMAMGR 16 +#define OS_PRIORITY_IRQMGR 17 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_FAULTCLIENT 126 +#define OS_PRIORITY_FAULT 127 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_MAX 255 #define OS_PRIORITY_THREADTAIL -1 @@ -84,5 +84,5 @@ OSPri osGetThreadPri(OSThread* t); // internal OSThread* __osGetActiveQueue(void); - +#endif #endif diff --git a/mm/include/PR/os_time.h b/mm/include/PR/os_time.h index d0da9b8a9..89575c06a 100644 --- a/mm/include/PR/os_time.h +++ b/mm/include/PR/os_time.h @@ -4,7 +4,9 @@ #include "ultratypes.h" #include "os_message.h" +#include +#if 0 typedef u64 OSTime; typedef struct OSTimer_s { @@ -18,8 +20,8 @@ typedef struct OSTimer_s { OSTime osGetTime(void); void osSetTime(OSTime ticks); -s32 osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg); +s32 osSetTimer(OSTimer* t, OSTime value, OSTime interval, OSMesgQueue* mq, OSMesg msg); s32 osStopTimer(OSTimer* t); - #endif +#endif \ No newline at end of file diff --git a/mm/include/PR/os_vi.h b/mm/include/PR/os_vi.h index 041622916..46b0f3ca2 100644 --- a/mm/include/PR/os_vi.h +++ b/mm/include/PR/os_vi.h @@ -1,30 +1,32 @@ #ifndef PR_OS_VI_H #define PR_OS_VI_H +#include +#if 0 #include "PR/ultratypes.h" #include "PR/os_message.h" /* Special Features */ -#define OS_VI_GAMMA_ON (1 << 0) -#define OS_VI_GAMMA_OFF (1 << 1) -#define OS_VI_GAMMA_DITHER_ON (1 << 2) -#define OS_VI_GAMMA_DITHER_OFF (1 << 3) -#define OS_VI_DIVOT_ON (1 << 4) -#define OS_VI_DIVOT_OFF (1 << 5) -#define OS_VI_DITHER_FILTER_ON (1 << 6) +#define OS_VI_GAMMA_ON (1 << 0) +#define OS_VI_GAMMA_OFF (1 << 1) +#define OS_VI_GAMMA_DITHER_ON (1 << 2) +#define OS_VI_GAMMA_DITHER_OFF (1 << 3) +#define OS_VI_DIVOT_ON (1 << 4) +#define OS_VI_DIVOT_OFF (1 << 5) +#define OS_VI_DITHER_FILTER_ON (1 << 6) #define OS_VI_DITHER_FILTER_OFF (1 << 7) -#define OS_VI_GAMMA 0x08 -#define OS_VI_GAMMA_DITHER 0x04 -#define OS_VI_DIVOT 0x10 +#define OS_VI_GAMMA 0x08 +#define OS_VI_GAMMA_DITHER 0x04 +#define OS_VI_DIVOT 0x10 #define OS_VI_DITHER_FILTER 0x10000 -#define OS_VI_UNK1 0x1 -#define OS_VI_UNK2 0x2 -#define OS_VI_UNK40 0x40 -#define OS_VI_UNK100 0x100 -#define OS_VI_UNK200 0x200 -#define OS_VI_UNK1000 0x1000 -#define OS_VI_UNK2000 0x2000 +#define OS_VI_UNK1 0x1 +#define OS_VI_UNK2 0x2 +#define OS_VI_UNK40 0x40 +#define OS_VI_UNK100 0x100 +#define OS_VI_UNK200 0x200 +#define OS_VI_UNK1000 0x1000 +#define OS_VI_UNK2000 0x2000 typedef struct { /* 0x00 */ u32 ctrl; @@ -52,75 +54,68 @@ typedef struct { /* 0x24 */ OSViFieldRegs fldRegs[2]; } OSViMode; // size = 0x4C +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 -#define OS_VI_NTSC_LPN1 0 /* NTSC */ -#define OS_VI_NTSC_LPF1 1 -#define OS_VI_NTSC_LAN1 2 -#define OS_VI_NTSC_LAF1 3 -#define OS_VI_NTSC_LPN2 4 -#define OS_VI_NTSC_LPF2 5 -#define OS_VI_NTSC_LAN2 6 -#define OS_VI_NTSC_LAF2 7 -#define OS_VI_NTSC_HPN1 8 -#define OS_VI_NTSC_HPF1 9 -#define OS_VI_NTSC_HAN1 10 -#define OS_VI_NTSC_HAF1 11 -#define OS_VI_NTSC_HPN2 12 -#define OS_VI_NTSC_HPF2 13 +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 -#define OS_VI_PAL_LPN1 14 /* PAL */ -#define OS_VI_PAL_LPF1 15 -#define OS_VI_PAL_LAN1 16 -#define OS_VI_PAL_LAF1 17 -#define OS_VI_PAL_LPN2 18 -#define OS_VI_PAL_LPF2 19 -#define OS_VI_PAL_LAN2 20 -#define OS_VI_PAL_LAF2 21 -#define OS_VI_PAL_HPN1 22 -#define OS_VI_PAL_HPF1 23 -#define OS_VI_PAL_HAN1 24 -#define OS_VI_PAL_HAF1 25 -#define OS_VI_PAL_HPN2 26 -#define OS_VI_PAL_HPF2 27 +#define OS_VI_MPAL_LPN1 28 /* MPAL */ +#define OS_VI_MPAL_LPF1 29 +#define OS_VI_MPAL_LAN1 30 +#define OS_VI_MPAL_LAF1 31 +#define OS_VI_MPAL_LPN2 32 +#define OS_VI_MPAL_LPF2 33 +#define OS_VI_MPAL_LAN2 34 +#define OS_VI_MPAL_LAF2 35 +#define OS_VI_MPAL_HPN1 36 +#define OS_VI_MPAL_HPF1 37 +#define OS_VI_MPAL_HAN1 38 +#define OS_VI_MPAL_HAF1 39 +#define OS_VI_MPAL_HPN2 40 +#define OS_VI_MPAL_HPF2 41 -#define OS_VI_MPAL_LPN1 28 /* MPAL */ -#define OS_VI_MPAL_LPF1 29 -#define OS_VI_MPAL_LAN1 30 -#define OS_VI_MPAL_LAF1 31 -#define OS_VI_MPAL_LPN2 32 -#define OS_VI_MPAL_LPF2 33 -#define OS_VI_MPAL_LAN2 34 -#define OS_VI_MPAL_LAF2 35 -#define OS_VI_MPAL_HPN1 36 -#define OS_VI_MPAL_HPF1 37 -#define OS_VI_MPAL_HAN1 38 -#define OS_VI_MPAL_HAF1 39 -#define OS_VI_MPAL_HPN2 40 -#define OS_VI_MPAL_HPF2 41 +#define OS_VI_FPAL_LPN1 42 /* FPAL */ +#define OS_VI_FPAL_LPF1 43 +#define OS_VI_FPAL_LAN1 44 +#define OS_VI_FPAL_LAF1 45 +#define OS_VI_FPAL_LPN2 46 +#define OS_VI_FPAL_LPF2 47 +#define OS_VI_FPAL_LAN2 48 +#define OS_VI_FPAL_LAF2 49 +#define OS_VI_FPAL_HPN1 50 +#define OS_VI_FPAL_HPF1 51 +#define OS_VI_FPAL_HAN1 52 +#define OS_VI_FPAL_HAF1 53 +#define OS_VI_FPAL_HPN2 54 +#define OS_VI_FPAL_HPF2 55 -#define OS_VI_FPAL_LPN1 42 /* FPAL */ -#define OS_VI_FPAL_LPF1 43 -#define OS_VI_FPAL_LAN1 44 -#define OS_VI_FPAL_LAF1 45 -#define OS_VI_FPAL_LPN2 46 -#define OS_VI_FPAL_LPF2 47 -#define OS_VI_FPAL_LAN2 48 -#define OS_VI_FPAL_LAF2 49 -#define OS_VI_FPAL_HPN1 50 -#define OS_VI_FPAL_HPF1 51 -#define OS_VI_FPAL_HAN1 52 -#define OS_VI_FPAL_HAF1 53 -#define OS_VI_FPAL_HPN2 54 -#define OS_VI_FPAL_HPF2 55 +#define OS_VI_UNK28 28 -#define OS_VI_UNK28 28 - -extern OSViMode osViModeNtscHpf1; -extern OSViMode osViModePalLan1; -extern OSViMode osViModeNtscHpn1; -extern OSViMode osViModeNtscLan1; -extern OSViMode osViModeMpalLan1; -extern OSViMode osViModeFpalLan1; extern OSViMode osViModeNtscHpf1; extern OSViMode osViModePalLan1; @@ -133,12 +128,12 @@ void* osViGetCurrentFramebuffer(void); void* osViGetNextFramebuffer(void); void osViSetXScale(f32 value); void osViSetYScale(f32 value); -void osViExtendVStart(u32 value); +void osViExtendVStart(u32 a0); void osViSetSpecialFeatures(u32 func); void osViSetMode(OSViMode* modep); void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount); void osViSwapBuffer(void* frameBufPtr); void osViBlack(u8 active); void osCreateViManager(OSPri pri); - +#endif #endif diff --git a/mm/include/PR/osint.h b/mm/include/PR/osint.h index f472a35f5..a14cee522 100644 --- a/mm/include/PR/osint.h +++ b/mm/include/PR/osint.h @@ -1,6 +1,10 @@ #ifndef PR_OSINT_H #define PR_OSINT_H +#include + +#if 0 + #include "ultratypes.h" #include "os_message.h" #include "os.h" @@ -51,3 +55,4 @@ extern u32 __osViIntrCount; extern u32 __osTimerCounter; #endif +#endif \ No newline at end of file diff --git a/mm/include/PR/piint.h b/mm/include/PR/piint.h index 8517f9d63..96dde86c7 100644 --- a/mm/include/PR/piint.h +++ b/mm/include/PR/piint.h @@ -1,85 +1,14 @@ #ifndef PR_PIINT_H #define PR_PIINT_H +#include + +#if 0 + #include "ultratypes.h" #include "os_pi.h" #include "libc/stdint.h" -#define LEO_BASE_REG 0x05000000 - -#define LEO_CMD (LEO_BASE_REG + 0x508) -#define LEO_STATUS (LEO_BASE_REG + 0x508) - -#define LEO_BM_CTL (LEO_BASE_REG + 0x510) -#define LEO_BM_STATUS (LEO_BASE_REG + 0x510) - -#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518) -#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518) - -#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) // C2 Sector Buffer -#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) // Data Sector Buffer -#define LEO_DATA (LEO_BASE_REG + 0x500) // Data -#define LEO_MISC_REG (LEO_BASE_REG + 0x504) // Misc Register -#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) // Current Track -#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) // Sector Error Status -#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) // Current Sector -#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) // Hard Reset -#define LEO_C1_S0 (LEO_BASE_REG + 0x524) // C1 -#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) // Sector Size (in bytes) -#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) // C1 -#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) // Sectors per Block, Full Size -#define LEO_C1_S4 (LEO_BASE_REG + 0x534) // C1 -#define LEO_C1_S6 (LEO_BASE_REG + 0x538) // C1 -#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) // Current Address? -#define LEO_ID_REG (LEO_BASE_REG + 0x540) // ID -#define LEO_TEST_REG (LEO_BASE_REG + 0x544) // Test Read -#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) // Test Write -#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) // Microsequencer RAM - -#define LEO_STATUS_PRESENCE_MASK 0xFFFF - -#define LEO_STATUS_DATA_REQUEST 0x40000000 -#define LEO_STATUS_C2_TRANSFER 0x10000000 -#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000 -#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000 -#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000 -#define LEO_STATUS_DISK_PRESENT 0x01000000 -#define LEO_STATUS_BUSY_STATE 0x00800000 -#define LEO_STATUS_RESET_STATE 0x00400000 -#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000 -#define LEO_STATUS_HEAD_RETRACTED 0x00080000 -#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000 -#define LEO_STATUS_MECHANIC_ERROR 0x00020000 -#define LEO_STATUS_DISK_CHANGE 0x00010000 - -#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED) -#define LEO_STATUS_MODE_ACTIVE 0 - -#define LEO_CUR_TK_INDEX_LOCK 0x60000000 - -#define LEO_BM_STATUS_RUNNING 0x80000000 // Running -#define LEO_BM_STATUS_ERROR 0x04000000 // Error -#define LEO_BM_STATUS_MICRO 0x02000000 // Micro Status? -#define LEO_BM_STATUS_BLOCK 0x01000000 // Block Transfer -#define LEO_BM_STATUS_C1CORRECTION 0x00800000 // C1 Correction -#define LEO_BM_STATUS_C1DOUBLE 0x00400000 // C1 Double -#define LEO_BM_STATUS_C1SINGLE 0x00200000 // C1 Single -#define LEO_BM_STATUS_C1ERROR 0x00010000 // C1 Error - -#define LEO_BM_CTL_START 0x80000000 // Start Buffer Manager -#define LEO_BM_CTL_MODE 0x40000000 // Buffer Manager Mode -#define LEO_BM_CTL_IMASK 0x20000000 // BM Interrupt Mask -#define LEO_BM_CTL_RESET 0x10000000 // Buffer Manager Reset -#define LEO_BM_CTL_DISABLE_OR 0x08000000 // Disable OR Check? -#define LEO_BM_CTL_DISABLE_C1 0x04000000 // Disable C1 Correction -#define LEO_BM_CTL_BLOCK 0x02000000 // Block Transfer -#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 // Mechanic Interrupt Reset - -#define LEO_BM_CTL_CONTROL_MASK 0xFF000000 -#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000 -#define LEO_BM_CTL_SECTOR_SHIFT 16 extern OSDevMgr __osPiDevMgr; extern OSPiHandle* __osCurrentHandle[]; @@ -99,5 +28,5 @@ s32 __osEPiRawWriteIo(OSPiHandle* handle, uintptr_t devAddr, u32 data); s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data); s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, uintptr_t cartAddr, void* dramAddr, size_t size); OSMesgQueue* osPiGetCmdQueue(void); - #endif +#endif \ No newline at end of file diff --git a/mm/include/PR/sptask.h b/mm/include/PR/sptask.h index 3ec4bf1bf..b3a1594a9 100644 --- a/mm/include/PR/sptask.h +++ b/mm/include/PR/sptask.h @@ -1,80 +1,84 @@ #ifndef PR_SPTASK_H #define PR_SPTASK_H +#include + +#if 0 + #include "PR/ultratypes.h" #include "libc/stddef.h" /* Task Types */ -#define M_NULTASK 0 -#define M_GFXTASK 1 -#define M_AUDTASK 2 -#define M_VIDTASK 3 +#define M_NULTASK 0 +#define M_GFXTASK 1 +#define M_AUDTASK 2 +#define M_VIDTASK 3 #define M_NJPEGTASK 4 -#define M_HVQTASK 6 -#define M_HVQMTASK 7 +#define M_HVQTASK 6 +#define M_HVQMTASK 7 /* Task Flags */ #define M_TASK_FLAG0 (1 << 0) #define M_TASK_FLAG1 (1 << 1) /* Task Flag Fields */ -#define OS_TASK_YIELDED (1 << 0) -#define OS_TASK_DP_WAIT (1 << 1) +#define OS_TASK_YIELDED (1 << 0) +#define OS_TASK_DP_WAIT (1 << 1) #define OS_TASK_LOADABLE (1 << 2) -#define OS_TASK_SP_ONLY (1 << 3) -#define OS_TASK_USR0 (1 << 4) -#define OS_TASK_USR1 (1 << 5) -#define OS_TASK_USR2 (1 << 6) -#define OS_TASK_USR3 (1 << 7) +#define OS_TASK_SP_ONLY (1 << 3) +#define OS_TASK_USR0 (1 << 4) +#define OS_TASK_USR1 (1 << 5) +#define OS_TASK_USR2 (1 << 6) +#define OS_TASK_USR3 (1 << 7) -#define OS_YIELD_DATA_SIZE 0xC00 +#define OS_YIELD_DATA_SIZE 0xC00 #define OS_YIELD_AUDIO_SIZE 0x400 /* SpStatus */ /* Write */ -#define SPSTATUS_CLEAR_HALT (1 << 0) -#define SPSTATUS_SET_HALT (1 << 1) -#define SPSTATUS_CLEAR_BROKE (1 << 2) -#define SPSTATUS_CLEAR_INTR (1 << 3) -#define SPSTATUS_SET_INTR (1 << 4) -#define SPSTATUS_CLEAR_SSTEP (1 << 5) -#define SPSTATUS_SET_SSTEP (1 << 6) -#define SPSTATUS_CLEAR_INTR_ON_BREAK (1 << 7) -#define SPSTATUS_SET_INTR_ON_BREAK (1 << 8) -#define SPSTATUS_CLEAR_SIGNAL0 (1 << 9) -#define SPSTATUS_SET_SIGNAL0 (1 << 10) -#define SPSTATUS_CLEAR_SIGNAL1 (1 << 11) -#define SPSTATUS_SET_SIGNAL1 (1 << 12) -#define SPSTATUS_CLEAR_SIGNAL2 (1 << 13) -#define SPSTATUS_SET_SIGNAL2 (1 << 14) -#define SPSTATUS_CLEAR_SIGNAL3 (1 << 15) -#define SPSTATUS_SET_SIGNAL3 (1 << 16) -#define SPSTATUS_CLEAR_SIGNAL4 (1 << 17) -#define SPSTATUS_SET_SIGNAL4 (1 << 18) -#define SPSTATUS_CLEAR_SIGNAL5 (1 << 19) -#define SPSTATUS_SET_SIGNAL5 (1 << 20) -#define SPSTATUS_CLEAR_SIGNAL6 (1 << 21) -#define SPSTATUS_SET_SIGNAL6 (1 << 23) -#define SPSTATUS_CLEAR_SIGNAL7 (1 << 24) -#define SPSTATUS_SET_SIGNAL7 (1 << 25) +#define SPSTATUS_CLEAR_HALT (1 << 0) +#define SPSTATUS_SET_HALT (1 << 1) +#define SPSTATUS_CLEAR_BROKE (1 << 2) +#define SPSTATUS_CLEAR_INTR (1 << 3) +#define SPSTATUS_SET_INTR (1 << 4) +#define SPSTATUS_CLEAR_SSTEP (1 << 5) +#define SPSTATUS_SET_SSTEP (1 << 6) +#define SPSTATUS_CLEAR_INTR_ON_BREAK (1 << 7) +#define SPSTATUS_SET_INTR_ON_BREAK (1 << 8) +#define SPSTATUS_CLEAR_SIGNAL0 (1 << 9) +#define SPSTATUS_SET_SIGNAL0 (1 << 10) +#define SPSTATUS_CLEAR_SIGNAL1 (1 << 11) +#define SPSTATUS_SET_SIGNAL1 (1 << 12) +#define SPSTATUS_CLEAR_SIGNAL2 (1 << 13) +#define SPSTATUS_SET_SIGNAL2 (1 << 14) +#define SPSTATUS_CLEAR_SIGNAL3 (1 << 15) +#define SPSTATUS_SET_SIGNAL3 (1 << 16) +#define SPSTATUS_CLEAR_SIGNAL4 (1 << 17) +#define SPSTATUS_SET_SIGNAL4 (1 << 18) +#define SPSTATUS_CLEAR_SIGNAL5 (1 << 19) +#define SPSTATUS_SET_SIGNAL5 (1 << 20) +#define SPSTATUS_CLEAR_SIGNAL6 (1 << 21) +#define SPSTATUS_SET_SIGNAL6 (1 << 23) +#define SPSTATUS_CLEAR_SIGNAL7 (1 << 24) +#define SPSTATUS_SET_SIGNAL7 (1 << 25) /* Read */ -#define SPSTATUS_HALT (1 << 0) -#define SPSTATUS_BROKE (1 << 1) -#define SPSTATUS_DMA_BUSY (1 << 2) -#define SPSTATUS_DMA_FULL (1 << 3) -#define SPSTATUS_IO_FULL (1 << 4) -#define SPSTATUS_SINGLE_STEP (1 << 5) -#define SPSTATUS_INTERRUPT_ON_BREAK (1 << 6) -#define SPSTATUS_SIGNAL0_SET (1 << 7) -#define SPSTATUS_SIGNAL1_SET (1 << 8) -#define SPSTATUS_SIGNAL2_SET (1 << 9) -#define SPSTATUS_SIGNAL3_SET (1 << 10) -#define SPSTATUS_SIGNAL4_SET (1 << 11) -#define SPSTATUS_SIGNAL5_SET (1 << 12) -#define SPSTATUS_SIGNAL6_SET (1 << 13) -#define SPSTATUS_SIGNAL7_SET (1 << 14) +#define SPSTATUS_HALT (1 << 0) +#define SPSTATUS_BROKE (1 << 1) +#define SPSTATUS_DMA_BUSY (1 << 2) +#define SPSTATUS_DMA_FULL (1 << 3) +#define SPSTATUS_IO_FULL (1 << 4) +#define SPSTATUS_SINGLE_STEP (1 << 5) +#define SPSTATUS_INTERRUPT_ON_BREAK (1 << 6) +#define SPSTATUS_SIGNAL0_SET (1 << 7) +#define SPSTATUS_SIGNAL1_SET (1 << 8) +#define SPSTATUS_SIGNAL2_SET (1 << 9) +#define SPSTATUS_SIGNAL3_SET (1 << 10) +#define SPSTATUS_SIGNAL4_SET (1 << 11) +#define SPSTATUS_SIGNAL5_SET (1 << 12) +#define SPSTATUS_SIGNAL6_SET (1 << 13) +#define SPSTATUS_SIGNAL7_SET (1 << 14) typedef struct { /* 0x00 */ u32 type; @@ -114,5 +118,5 @@ void osSpTaskStartGo(OSTask* tp); void osSpTaskYield(void); OSYieldResult osSpTaskYielded(OSTask* task); - +#endif #endif diff --git a/mm/include/PR/ultratypes.h b/mm/include/PR/ultratypes.h index 76afdf6a0..e50f3f797 100644 --- a/mm/include/PR/ultratypes.h +++ b/mm/include/PR/ultratypes.h @@ -1,6 +1,9 @@ #ifndef PR_ULTRATYPES_H #define PR_ULTRATYPES_H +#include + +#if 0 typedef signed char s8; typedef unsigned char u8; typedef signed short int s16; @@ -27,8 +30,8 @@ typedef u32 size_t; #ifndef NULL #define NULL (void*)0 #endif - +#endif // TODO: move this somewhere else typedef void* TexturePtr; -#endif +#endif \ No newline at end of file diff --git a/mm/include/PR/viint.h b/mm/include/PR/viint.h index bc9ce2335..51f0ad1c1 100644 --- a/mm/include/PR/viint.h +++ b/mm/include/PR/viint.h @@ -1,38 +1,42 @@ #ifndef PR_VIINT_H #define PR_VIINT_H +#include + +#if 0 #include "ultratypes.h" #define OS_TV_TYPE_PAL 0 #define OS_TV_TYPE_NTSC 1 #define OS_TV_TYPE_MPAL 2 -#define VI_STATE_MODE_UPDATED (1 << 0) +#define VI_STATE_MODE_UPDATED (1 << 0) #define VI_STATE_XSCALE_UPDATED (1 << 1) #define VI_STATE_YSCALE_UPDATED (1 << 2) -#define VI_STATE_CTRL_UPDATED (1 << 3) // related to control regs changing +#define VI_STATE_CTRL_UPDATED (1 << 3) // related to control regs changing #define VI_STATE_BUFFER_UPDATED (1 << 4) // swap buffer -#define VI_STATE_BLACK (1 << 5) // probably related to a black screen -#define VI_STATE_REPEATLINE (1 << 6) // repeat line? -#define VI_STATE_FADE (1 << 7) // fade +#define VI_STATE_BLACK (1 << 5) // probably related to a black screen +#define VI_STATE_REPEATLINE (1 << 6) // repeat line? +#define VI_STATE_FADE (1 << 7) // fade #define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ #define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ #define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ -#define VI_SCALE_MASK 0xFFF -#define VI_2_10_FPART_MASK 0x3FF -#define VI_SUBPIXEL_SH 0x10 +#define VI_SCALE_MASK 0xFFF +#define VI_2_10_FPART_MASK 0x3FF +#define VI_SUBPIXEL_SH 0x10 // For use in initializing OSViMode structures -#define BURST(hsync_width, color_width, vsync_width, color_start) \ - (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20)) +#define BURST(hsync_width, color_width, vsync_width, color_start) \ + (((u32)(hsync_width)&0xFF) | (((u32)(color_width)&0xFF) << 8) | (((u32)(vsync_width)&0xF) << 16) | \ + (((u32)(color_start)&0xFFFF) << 20)) #define WIDTH(v) (v) #define VSYNC(v) (v) -#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF)) -#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF)) -#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF)) +#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration)&0xFFFF)) +#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower)&0xFFFF)) +#define START(start, end) (((u32)(start) << 16) | ((u32)(end)&0xFFFF)) #define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1)) @@ -71,5 +75,5 @@ extern __OSViContext* __osViNext; extern u32 __additional_scanline; __OSViContext* __osViGetCurrentContext(void); void __osViInit(void); - +#endif #endif diff --git a/mm/include/PR/xstdio.h b/mm/include/PR/xstdio.h index 9850d88f8..391cbca6f 100644 --- a/mm/include/PR/xstdio.h +++ b/mm/include/PR/xstdio.h @@ -1,6 +1,7 @@ #ifndef PR_XSTDIO_H #define PR_XSTDIO_H - +#include +#if 0 #include "ultratypes.h" #include "libc/stdarg.h" @@ -36,3 +37,4 @@ void _Litob(_Pft* args, u8 type); void _Ldtob(_Pft* args, u8 type); #endif +#endif \ No newline at end of file diff --git a/mm/include/align_asset_macro.h b/mm/include/align_asset_macro.h new file mode 100644 index 000000000..0cadd09c5 --- /dev/null +++ b/mm/include/align_asset_macro.h @@ -0,0 +1,10 @@ +#ifndef ALIGN_ASSET_MACRO_H +#define ALIGN_ASSET_MACRO_H + +#if defined(_WIN32) + #define ALIGN_ASSET(x) __declspec(align(x)) +#else + #define ALIGN_ASSET(x) __attribute__((aligned (x))) +#endif + +#endif \ No newline at end of file diff --git a/mm/include/buffers.h b/mm/include/buffers.h index 72615a717..d560315be 100644 --- a/mm/include/buffers.h +++ b/mm/include/buffers.h @@ -9,8 +9,8 @@ extern u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE]; extern STACK(gGfxSPTaskStack, 0x400); extern GfxPool gGfxPools[2]; -extern u8 gAudioHeap[0x138000]; -extern u8 gSystemHeap[]; +extern u8* gAudioHeap; +extern u8* gSystemHeap; extern u8 gPictoPhotoI8[PICTO_PHOTO_SIZE]; extern u8 D_80784600[0x56200]; diff --git a/mm/include/color.h b/mm/include/color.h index 7c0cd7d9f..e0fe470de 100644 --- a/mm/include/color.h +++ b/mm/include/color.h @@ -1,11 +1,11 @@ -#ifndef COLOR_H -#define COLOR_H +#ifndef _COLOR_H_ +#define _COLOR_H_ #include "PR/ultratypes.h" - +#include // For checking the alpha bit in an RGBA16 pixel #define RGBA16_PIXEL_OPAQUE 1 - +#if 0 typedef struct { /* 0x0 */ u8 r; /* 0x1 */ u8 g; @@ -19,11 +19,7 @@ typedef struct { /* 0x3 */ u8 a; } Color_RGBA8; // size = 0x4 -typedef struct { - /* 0x0 */ s16 r; - /* 0x2 */ s16 g; - /* 0x4 */ s16 b; -} Color_RGB16; // size = 0x6 + // only use when necessary for alignment purposes typedef union { @@ -33,10 +29,6 @@ typedef union { u32 rgba; } Color_RGBA8_u32; -typedef struct { - f32 r, g, b, a; -} Color_RGBAf; - typedef struct { u32 r, g, b, a; } Color_RGBAu32; @@ -51,6 +43,23 @@ typedef union { u16 rgba; } Color_RGBA16; + +typedef struct { + f32 r, g, b, a; +} Color_RGBAf; + +#endif + +typedef struct { + /* 0x0 */ s16 r; + /* 0x2 */ s16 g; + /* 0x4 */ s16 b; +} Color_RGB16; // size = 0x6 + +typedef struct { + u32 r, g, b, a; +} Color_RGBAu32; + typedef union { struct { u32 r : 5; @@ -61,7 +70,7 @@ typedef union { u16 rgba; } Color_RGBA16_2; -typedef union{ +typedef union { struct { u32 r : 3; u32 g : 3; @@ -70,8 +79,7 @@ typedef union{ }; u16 rgba; } Color_RGBA14; - -#define RGBA8(r, g, b, a) ((((r) & 0xFF) << 24) | (((g) & 0xFF) << 16) | (((b) & 0xFF) << 8) | (((a) & 0xFF) << 0)) +#define RGBA8(r, g, b, a) ((((r)&0xFF) << 24) | (((g)&0xFF) << 16) | (((b)&0xFF) << 8) | (((a)&0xFF) << 0)) #define RGBA16_GET_R(pixel) (((pixel) >> 11) & 0x1F) #define RGBA16_GET_G(pixel) (((pixel) >> 6) & 0x1F) diff --git a/mm/include/command_macros_base.h b/mm/include/command_macros_base.h index 4a866c29e..a52ee1667 100644 --- a/mm/include/command_macros_base.h +++ b/mm/include/command_macros_base.h @@ -16,11 +16,7 @@ #define CMD_W(a) (a) -#ifdef __GNUC__ -#define CMD_F(a) .f = (a) -#else #define CMD_F(a) (a) -#endif #define CMD_PTR(a) (uintptr_t)(a) diff --git a/mm/include/fixed_point.h b/mm/include/fixed_point.h index bb7e96494..58c3e68ba 100644 --- a/mm/include/fixed_point.h +++ b/mm/include/fixed_point.h @@ -26,9 +26,11 @@ f64 nearbyint(f64 x); s32 lnearbyintf(f32 x); s32 lnearbyint(f64 x); +#ifndef __GNUC__ f32 roundf(f32 x); f64 round(f64 x); s32 lroundf(f32 x); s32 lround(f64 x); - #endif + +#endif \ No newline at end of file diff --git a/mm/include/functions.h b/mm/include/functions.h index 59a28dc75..8238a7d7e 100644 --- a/mm/include/functions.h +++ b/mm/include/functions.h @@ -1,6 +1,11 @@ #ifndef FUNCTIONS_H #define FUNCTIONS_H +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif + #include "z64.h" void bootproc(void); @@ -14,7 +19,7 @@ s32 DmaMgr_FindDmaIndex(uintptr_t vrom); const char* func_800809F4(uintptr_t param_1); void DmaMgr_ProcessMsg(DmaRequest* req); void DmaMgr_ThreadEntry(void* arg); -s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromStart, size_t size, UNK_TYPE4 unused, OSMesgQueue* queue, void* msg); +s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromStart, size_t size, UNK_TYPE4 unused, OSMesgQueue* queue, OSMesg msg); s32 DmaMgr_SendRequest0(void* vramStart, uintptr_t vromStart, size_t size); void DmaMgr_Start(void); void DmaMgr_Stop(void); @@ -607,12 +612,6 @@ s32 func_80105294(void); s16 func_80105318(void); // void func_80105328(void); // void func_8010534C(void); -void func_8010549C(PlayState* play, void* segmentAddress); -void func_8010565C(PlayState* play, u8 num, void* segmentAddress); -void func_80105818(PlayState* play, u32 uParm2, TransitionActorEntry* puParm3); -void func_80105A40(PlayState* play); -void func_80105B34(PlayState* play); -void func_80105C40(s16 arg0); // void func_80105FE0(void); // void func_80106408(void); // void func_80106450(void); @@ -1327,4 +1326,9 @@ void AudioSeq_ResetActiveSequencesAndVolume(void); void Regs_InitData(PlayState* play); +#ifdef __cplusplus +} +#undef this +#endif + #endif diff --git a/mm/include/gfx.h b/mm/include/gfx.h index 87f949d8b..eabf8f439 100644 --- a/mm/include/gfx.h +++ b/mm/include/gfx.h @@ -2,7 +2,7 @@ #define GFX_H #include "ultra64.h" -#include "PR/sched.h" +#include "PR/os_sched.h" #include "thga.h" #include "alignment.h" #include "unk.h" @@ -110,12 +110,12 @@ typedef struct GfxPool { /* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC /* 0x00008 */ GfxMasterList master; /* 0x00308 */ Gfx polyXluBuffer[0x800]; - /* 0x04308 */ Gfx overlayBuffer[0x400]; + /* 0x04308 */ Gfx overlayBuffer[0x800]; // 0x400 -> 0x800 to avoid thga crashes /* 0x06308 */ Gfx workBuffer[0x40]; /* 0x06508 */ Gfx debugBuffer[0x40]; /* 0x06708 */ Gfx polyOpaBuffer[0x3380]; /* 0x20308 */ u16 tailMagic; // GFXPOOL_TAIL_MAGIC -} GfxPool; // size = 0x20310 +} GfxPool; // size = 0x20310 typedef struct GraphicsContext { /* 0x000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" @@ -228,13 +228,24 @@ Gfx* Gfx_BranchTexScroll(Gfx** gfxp, u32 x, u32 y, s32 width, s32 height); void func_8012CB04(Gfx** gfxp, u32 x, u32 y); Gfx* func_8012CB28(GraphicsContext* gfxCtx, u32 x, u32 y); Gfx* Gfx_TexScroll(GraphicsContext* gfxCtx, u32 x, u32 y, s32 width, s32 height); -Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, u32 y2, s32 width2, s32 height2); -Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); +Gfx* Gfx_TwoTexScroll(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, u32 x2, + u32 y2, s32 width2, s32 height2); +Gfx* Gfx_TwoTexScrollEnvColor(GraphicsContext* gfxCtx, s32 tile1, u32 x1, u32 y1, s32 width1, s32 height1, s32 tile2, + u32 x2, u32 y2, s32 width2, s32 height2, s32 r, s32 g, s32 b, s32 a); Gfx* Gfx_EnvColor(GraphicsContext* gfxCtx, s32 r, s32 g, s32 b, s32 a); Gfx* Gfx_PrimColor(GraphicsContext* gfxCtx, s32 lodfrac, s32 r, s32 g, s32 b, s32 a); void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g, u8 b); void func_8012D374(GraphicsContext* gfxCtx, u8 r, u8 g, u8 b); void func_8012D40C(f32* param_1, f32* param_2, s16* param_3); +void gSPSegment(void* value, int segNum, uintptr_t target); +void gSPSegmentLoadRes(void* value, int segNum, uintptr_t target); +void gDPSetTextureImage(Gfx* pkt, u32 format, u32 size, u32 width, uintptr_t i); +void gDPSetTextureImageFB(Gfx* pkt, u32 format, u32 size, u32 width, int fb); +void gSPDisplayList(Gfx* pkt, Gfx* dl); +void gSPDisplayListOffset(Gfx* pkt, Gfx* dl, int offset); +void gSPVertex(Gfx* pkt, uintptr_t v, int n, int v0); +void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr); + extern Gfx gSetupDLs[SETUPDL_MAX][6]; extern Gfx gEmptyDL[]; @@ -247,14 +258,19 @@ extern Gfx gEmptyDL[]; // __gfxCtx shouldn't be used directly. // Use the DISP macros defined above when writing to display buffers. -#define OPEN_DISPS(gfxCtx) \ - { \ - GraphicsContext* __gfxCtx = gfxCtx; \ - s32 __dispPad +#define OPEN_DISPS(gfxCtx) \ + { \ + GraphicsContext* __gfxCtx = gfxCtx; \ + gDPNoOpOpenDisp(gfxCtx->polyOpa.p++, __FILE__, __LINE__); \ + gDPNoOpOpenDisp(gfxCtx->polyXlu.p++, __FILE__, __LINE__); \ + gDPNoOpOpenDisp(gfxCtx->overlay.p++, __FILE__, __LINE__); -#define CLOSE_DISPS(gfxCtx) \ - (void)0; \ - } \ +#define CLOSE_DISPS(gfxCtx) \ + (void)0; \ + gDPNoOpCloseDisp(gfxCtx->polyOpa.p++, __FILE__, __LINE__); \ + gDPNoOpCloseDisp(gfxCtx->polyXlu.p++, __FILE__, __LINE__); \ + gDPNoOpCloseDisp(gfxCtx->overlay.p++, __FILE__, __LINE__); \ + } \ (void)0 #define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size)))) diff --git a/mm/include/irqmgr.h b/mm/include/irqmgr.h index a19169dc7..76dae3004 100644 --- a/mm/include/irqmgr.h +++ b/mm/include/irqmgr.h @@ -2,7 +2,7 @@ #define IRQMGR_H #include "ultra64.h" -#include "PR/sched.h" +#include "PR/os_sched.h" typedef struct IrqMgrClient { /* 0x0 */ struct IrqMgrClient* next; diff --git a/mm/include/libc/math.h b/mm/include/libc/math.h index 3f5ed3a20..57ea1d81e 100644 --- a/mm/include/libc/math.h +++ b/mm/include/libc/math.h @@ -1,16 +1,16 @@ #ifndef LIBC_MATH_H #define LIBC_MATH_H -#include "PR/ultratypes.h" - #define M_PI 3.14159265358979323846f #define M_SQRT2 1.41421356237309504880f -#define M_SQRT3 1.7320508075688772935274463415059f -#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */ +#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */ #define FLT_MAX 340282346638528859811704183484516925440.0f #define SHT_MAX 32767.0f #define SHT_MINV (1.0f / SHT_MAX) +#ifdef __GNUC__ +#include +#else float fabsf(float f); #pragma intrinsic(fabsf) #ifdef __GNUC__ @@ -21,3 +21,5 @@ double sqrt(double d); #pragma intrinsic(sqrt) #endif + +#endif diff --git a/mm/include/libc/stddef.h b/mm/include/libc/stddef.h index d75339614..277d914c3 100644 --- a/mm/include/libc/stddef.h +++ b/mm/include/libc/stddef.h @@ -2,7 +2,8 @@ #define LIBC_STDDEF_H #include "PR/ultratypes.h" - +#include +#if 0 typedef s32 ptrdiff_t; #ifdef __GNUC__ @@ -10,5 +11,5 @@ typedef s32 ptrdiff_t; #else #define offsetof(structure, member) ((size_t)&(((structure*)0)->member)) #endif - +#endif #endif /* STDDEF_H */ diff --git a/mm/include/libc/stdlib.h b/mm/include/libc/stdlib.h index ec15b4f6c..fe5d84276 100644 --- a/mm/include/libc/stdlib.h +++ b/mm/include/libc/stdlib.h @@ -2,7 +2,7 @@ #define LIBC_STDLIB_H #include "libc/stddef.h" - +#if 0 typedef struct { /* 0x0 */ int quot; /* 0x4 */ int rem; @@ -24,5 +24,5 @@ typedef long wchar_t; ldiv_t ldiv(long numer, long denom); lldiv_t lldiv(long long numer, long long denom); - +#endif #endif /* STDLIB_H */ diff --git a/mm/include/libc/string.h b/mm/include/libc/string.h index 9c6a1cb08..2332cd5f6 100644 --- a/mm/include/libc/string.h +++ b/mm/include/libc/string.h @@ -3,10 +3,10 @@ #include "libc/stddef.h" - +#ifdef __sgi const char* strchr(const char* s, int c); size_t strlen(const char* s); void* memcpy(void* s1, const void* s2, size_t n); - +#endif #endif diff --git a/mm/include/listalloc.h b/mm/include/listalloc.h index e4ca07f07..9a6f473b2 100644 --- a/mm/include/listalloc.h +++ b/mm/include/listalloc.h @@ -1,6 +1,11 @@ #ifndef LISTALLOC_H #define LISTALLOC_H +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif + #include "ultra64.h" typedef struct ListAlloc { @@ -13,4 +18,9 @@ void* ListAlloc_Alloc(ListAlloc* this, size_t size); void ListAlloc_Free(ListAlloc* this, void* data); void ListAlloc_FreeAll(ListAlloc* this); +#ifdef __cplusplus +} +#undef this #endif + +#endif \ No newline at end of file diff --git a/mm/include/macros.h b/mm/include/macros.h index f6fa1bb6e..d0fe3cbde 100644 --- a/mm/include/macros.h +++ b/mm/include/macros.h @@ -25,8 +25,8 @@ #define RDRAM_CACHED KSEG0 -#define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) + RDRAM_CACHED) -#define SEGMENTED_TO_K0(addr) (void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr)) +#define PHYSICAL_TO_VIRTUAL(addr) (addr) //((uintptr_t)(addr) + RDRAM_CACHED) +#define SEGMENTED_TO_K0(addr) (addr) //(void*)((gSegments[SEGMENT_NUMBER(addr)] + K0BASE) + SEGMENT_OFFSET(addr)) #define GET_ACTIVE_CAM(play) ((play)->cameraPtrs[(play)->activeCamId]) diff --git a/mm/include/message_data_static.h b/mm/include/message_data_static.h index d139c4621..bda17b6fa 100644 --- a/mm/include/message_data_static.h +++ b/mm/include/message_data_static.h @@ -7,6 +7,7 @@ typedef struct MessageTableEntry { /* 0x0 */ u16 textId; /* 0x2 */ u8 typePos; /* 0x4 */ const char* segment; + u32 msgSize; } MessageTableEntry; // size = 0x8; #endif diff --git a/mm/include/scheduler.h b/mm/include/scheduler.h index 1aeae07ec..7a9715a5b 100644 --- a/mm/include/scheduler.h +++ b/mm/include/scheduler.h @@ -2,7 +2,7 @@ #define SCHEDULER_H #include "PR/ultratypes.h" -#include "PR/sched.h" +#include "PR/os_sched.h" #include "PR/os_vi.h" #include "PR/sptask.h" #include "irqmgr.h" diff --git a/mm/include/segment_symbols.h b/mm/include/segment_symbols.h index 4d5824138..19ead8081 100644 --- a/mm/include/segment_symbols.h +++ b/mm/include/segment_symbols.h @@ -4,38 +4,47 @@ #include "libc/stddef.h" #include "PR/ultratypes.h" -#define DECLARE_SEGMENT(name) \ - extern u8 _##name##SegmentStart[]; \ - extern u8 _##name##SegmentEnd[]; +#define DECLARE_SEGMENT(name) \ + // extern u8 _##name##SegmentStart[]; \ +// extern u8 _##name##SegmentEnd[]; -#define DECLARE_ROM_SEGMENT(name) \ - extern u8 _##name##SegmentRomStart[]; \ - extern u8 _##name##SegmentRomEnd[]; - -#define DECLARE_BSS_SEGMENT(name) \ - extern u8 _##name##SegmentBssStart[]; \ - extern u8 _##name##SegmentBssEnd[]; +#define DECLARE_ROM_SEGMENT(name) \ + // extern u8 _##name##SegmentRomStart[]; \ +// extern u8 _##name##SegmentRomEnd[]; +#define DECLARE_BSS_SEGMENT(name) \ +// extern u8 _##name##SegmentBssStart[]; \ +// extern u8 _##name##SegmentBssEnd[]; \ +// #define DECLARE_OVERLAY_SEGMENT(name) \ DECLARE_SEGMENT(ovl_##name) \ DECLARE_ROM_SEGMENT(ovl_##name) -#define SEGMENT_START(segment) (_ ## segment ## SegmentStart) -#define SEGMENT_END(segment) (_ ## segment ## SegmentEnd) -#define SEGMENT_SIZE(segment) ((uintptr_t)SEGMENT_END(segment) - (uintptr_t)SEGMENT_START(segment)) +#define SEGMENT_START(segment) 0 +//(_ ## segment ## SegmentStart) -#define SEGMENT_ROM_START(segment) ((uintptr_t) _ ## segment ## SegmentRomStart) -#define SEGMENT_ROM_START_OFFSET(segment, offset) ((uintptr_t) (( _ ## segment ## SegmentRomStart ) + (offset))) -#define SEGMENT_ROM_END(segment) ((uintptr_t) _ ## segment ## SegmentRomEnd) -#define SEGMENT_ROM_SIZE(segment) (SEGMENT_ROM_END(segment) - SEGMENT_ROM_START(segment)) -#define SEGMENT_ROM_SIZE_ALT(segment) ((size_t)( _ ## segment ## SegmentRomEnd - _ ## segment ## SegmentRomStart )) +#define SEGMENT_END(segment) 0 +//(_ ## segment ## SegmentEnd) -#define SEGMENT_BSS_START(segment) (_ ## segment ## SegmentBssStart) -#define SEGMENT_BSS_END(segment) (_ ## segment ## SegmentBssEnd) -#define SEGMENT_BSS_SIZE(segment) ((uintptr_t)SEGMENT_BSS_END(segment) - (uintptr_t)SEGMENT_BSS_START(segment)) +#define SEGMENT_SIZE(segment) (uintptr_t) NULL +//((uintptr_t)SEGMENT_END(segment) - (uintptr_t)SEGMENT_START(segment)) + +#define SEGMENT_ROM_START(segment) NULL +//(_ ## segment ## SegmentRomStart) +#define SEGMENT_ROM_END(segment) NULL +//(_ ## segment ## SegmentRomEnd) +#define SEGMENT_ROM_SIZE(segment) NULL +//((uintptr_t)SEGMENT_ROM_END(segment) - (uintptr_t)SEGMENT_ROM_START(segment)) + +#define SEGMENT_BSS_START(segment) 0 +//(_ ## segment ## SegmentBssStart) +#define SEGMENT_BSS_END(segment) 0 +//(_ ## segment ## SegmentBssEnd) +#define SEGMENT_BSS_SIZE(segment) 0 +//((uintptr_t)SEGMENT_BSS_END(segment) - (uintptr_t)SEGMENT_BSS_START(segment)) #define ROM_FILE(name) \ - { (uintptr_t)SEGMENT_ROM_START(name), (uintptr_t)SEGMENT_ROM_END(name) } + { (uintptr_t) SEGMENT_ROM_START(name), (uintptr_t)SEGMENT_ROM_END(name) } #define ROM_FILE_UNSET \ { 0 } diff --git a/mm/include/z64.h b/mm/include/z64.h index 17f22d183..5547f2aa9 100644 --- a/mm/include/z64.h +++ b/mm/include/z64.h @@ -1,6 +1,9 @@ #ifndef Z64_H #define Z64_H - +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif #include "libc/math.h" #include "libc/stdarg.h" #include "libc/stdbool.h" @@ -69,6 +72,8 @@ #include "z64keyframe.h" #include "regs.h" +#define AUDIO_HEAP_SIZE 0x1380000 +#define SYSTEM_HEAP_SIZE (1024 * 1024 * 32) typedef struct PauseContext { /* 0x000 */ View view; @@ -292,4 +297,17 @@ typedef enum { /* 3 */ PICTO_PHOTO_STATE_READY } PictoPhotoState; +#define ROM_FILE(name) \ + { 0, 0, #name } + +#define ROM_FILE_EMPTY \ + { 0, 0, "" } + +#define ROM_FILE_UNSET \ + { 0 } + +#ifdef __cplusplus +} +#undef this +#endif #endif diff --git a/mm/include/z64bgcheck.h b/mm/include/z64bgcheck.h index 2df706cb2..888ffbc47 100644 --- a/mm/include/z64bgcheck.h +++ b/mm/include/z64bgcheck.h @@ -1,9 +1,17 @@ #ifndef Z64BGCHECK_H #define Z64BGCHECK_H +#ifdef __cplusplus +#ifndef this +#define this thisx +#endif +extern "C" { +#endif +#include "z64actor.h" + struct PlayState; -struct Actor; -struct DynaPolyActor; +//struct Actor; +//struct DynaPolyActor; #define SS_NULL 0xFFFF @@ -592,4 +600,10 @@ s32 func_800CA6F0(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z s32 func_800CA9D0(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox); s32 func_800CAA14(CollisionPoly* polyA, CollisionPoly* polyB, Vec3f* pointA, Vec3f* pointB, Vec3f* closestPoint); +#ifdef __cplusplus +} +#undef this +#endif + + #endif diff --git a/mm/include/z64bombers_notebook.h b/mm/include/z64bombers_notebook.h index 5b89aaf70..06438b62a 100644 --- a/mm/include/z64bombers_notebook.h +++ b/mm/include/z64bombers_notebook.h @@ -1,6 +1,11 @@ #ifndef Z64BOMBERS_NOTEBOOK_H #define Z64BOMBERS_NOTEBOOK_H +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif + #include "ultra64.h" #include "z64dma.h" @@ -8,7 +13,7 @@ struct PlayState; #define DEFINE_PERSON(enum, _photo, _description, _metEnum, _metMessage, _metFlag) enum, typedef enum BombersNotebookPerson { - #include "tables/bombers_notebook/person_table.h" +#include "tables/bombers_notebook/person_table.h" /* 0x14 */ BOMBERS_NOTEBOOK_PERSON_MAX } BombersNotebookPerson; @@ -23,8 +28,8 @@ typedef enum BombersNotebookLoadState { #define DEFINE_PERSON(_enum, _photo, _description, metEnum, _metMessage, _metFlag) metEnum, #define DEFINE_EVENT(enum, _icon, _colorFlag, _description, _completedMessage, _completedFlag) enum, typedef enum BombersNotebookEvent { - #include "tables/bombers_notebook/person_table.h" - #include "tables/bombers_notebook/event_table.h" +#include "tables/bombers_notebook/person_table.h" +#include "tables/bombers_notebook/event_table.h" /* 0x37 */ BOMBERS_NOTEBOOK_EVENT_MAX } BombersNotebookEvent; @@ -56,4 +61,9 @@ void BombersNotebook_Update(struct PlayState* play, BombersNotebook* this, Input void BombersNotebook_Init(BombersNotebook* this); void BombersNotebook_Destroy(BombersNotebook* this); +#ifdef __cplusplus +} +#undef this +#endif + #endif diff --git a/mm/include/z64interface.h b/mm/include/z64interface.h index d768254e2..401ab72af 100644 --- a/mm/include/z64interface.h +++ b/mm/include/z64interface.h @@ -126,12 +126,29 @@ typedef enum { /* 1 */ STORY_TYPE_GIANTS_LEAVING } StoryType; +typedef enum { + /* 0 */ A_BUTTON_ACTION, + /* 1 */ B_BUTTON_ACTION, + /* 2 */ START_BUTTON_ACTION, + /* 3 */ CLOCK_TIMER +} ActionBtn; + +typedef enum { + /* 0 */ ACTION_MAIN, + /* 1 */ ACTION_SUB +} ActionType; + +typedef struct { + char* mainTex; + char* subTex; +} ActionLabel; + typedef struct { /* 0x000 */ View view; /* 0x168 */ Vtx* actionVtx; /* 0x16C */ Vtx* beatingHeartVtx; /* 0x170 */ u8* parameterSegment; - /* 0x174 */ u8* doActionSegment; + /* 0x174 */ ActionLabel* doActionSegment; /* 0x178 */ u8* iconItemSegment; /* 0x17C */ u8* mapSegment; /* 0x180 */ u8* unk_180; // unused segment? @@ -255,7 +272,7 @@ void Inventory_UpdateItem(struct PlayState* play, s16 slot, s16 item); void Interface_SetAButtonDoAction(struct PlayState* play, u16 aButtonDoAction); void Interface_SetBButtonDoAction(struct PlayState* play, s16 bButtonDoAction); void Interface_SetTatlCall(struct PlayState* play, u16 tatlCallState); -void Interface_LoadBButtonDoActionLabel(struct PlayState* play, s16 bButtonDoAction); +void Interface_LoadButtonDoActionLabel(struct PlayState* play, s16 doAction, s16 button, s16 state); s32 Health_ChangeBy(struct PlayState* play, s16 healthChange); void Health_GiveHearts(s16 hearts); void Rupees_ChangeBy(s16 rupeeChange); diff --git a/mm/include/z64jpeg.h b/mm/include/z64jpeg.h index 181140386..e08d85d49 100644 --- a/mm/include/z64jpeg.h +++ b/mm/include/z64jpeg.h @@ -3,7 +3,7 @@ #include "PR/ultratypes.h" #include "PR/os_message.h" -#include "PR/sched.h" +#include "PR/os_sched.h" typedef struct { /* 0x00 */ u16 table[8*8]; diff --git a/mm/include/z64math.h b/mm/include/z64math.h index 2c457d8bf..a5cb74a5a 100644 --- a/mm/include/z64math.h +++ b/mm/include/z64math.h @@ -2,7 +2,7 @@ #define Z64MATH_H #include "PR/ultratypes.h" - +#include #define VEC_SET(V,X,Y,Z) V.x=X;V.y=Y;V.z=Z typedef struct { @@ -119,6 +119,7 @@ typedef enum { /* 2 */ OLIB_DIFF // Sub `a` and `b` to dest } OlibVec3fDiff; +#if 0 typedef float MtxF_t[4][4]; typedef union { MtxF_t mf; @@ -129,7 +130,7 @@ typedef union { xw, yw, zw, ww; }; } MtxF; // size = 0x40 - +#endif #define LERPIMP(v0, v1, t) ((v0) + (((v1) - (v0)) * (t))) #define LERPIMP_ALT(v0, v1, t) (((v1) - (v0)) * (t) + (v0)) #define S16_LERP(v0, v1, t) ((s16)(((v1) - (v0)) * (t)) + (v0)) diff --git a/mm/include/z64player.h b/mm/include/z64player.h index 32b673fe4..4b7810b1a 100644 --- a/mm/include/z64player.h +++ b/mm/include/z64player.h @@ -1,6 +1,11 @@ #ifndef Z64PLAYER_H #define Z64PLAYER_H +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif + #include "alignment.h" #include "PR/os.h" #include "z64actor.h" @@ -1304,5 +1309,9 @@ typedef struct Player { /* 0xD6B */ u8 unk_D6B; /* 0xD6C */ Vec3f unk_D6C; // previous body part 0 position } Player; // size = 0xD78 +#ifdef __cplusplus +} +#undef this +#endif #endif diff --git a/mm/include/z64prerender.h b/mm/include/z64prerender.h index 813f6827a..344b11b76 100644 --- a/mm/include/z64prerender.h +++ b/mm/include/z64prerender.h @@ -1,6 +1,10 @@ #ifndef Z64_PRERENDER_H #define Z64_PRERENDER_H +#ifdef __cplusplus +extern "C" { +#endif + #include "ultra64.h" #include "listalloc.h" #include "unk.h" @@ -40,34 +44,39 @@ typedef struct PreRender { /* 0x44 */ ListAlloc alloc; /* 0x4C */ u8 unk_4C; /* 0x4D */ u8 filterState; // See `PrerenderFilterState` -} PreRender; // size = 0x50 +} PreRender; // size = 0x50 - -void PreRender_SetValuesSave(PreRender* this, u32 width, u32 height, void* fbuf, void* zbuf, void* cvg); -void PreRender_Init(PreRender* this); -void PreRender_SetValues(PreRender* this, u32 width, u32 height, void* fbuf, void* zbuf); -void PreRender_Destroy(PreRender* this); -void PreRender_CopyImage(PreRender* this, Gfx** gfxp, void* img, void* imgDst, u32 useThresholdAlphaCompare); -void PreRender_RestoreBuffer(PreRender* this, Gfx** gfxp, void* buf, void* bufSave); -void func_8016FF90(PreRender* this, Gfx** gfxp, void* buf, void* bufSave, s32 envR, s32 envG, s32 envB, s32 envA); -void func_80170200(PreRender* this, Gfx** gfxp, void* buf, void* bufSave); -void PreRender_CoverageRgba16ToI8(PreRender* this, Gfx** gfxp, void* img, void* cvgDst); -void PreRender_SaveZBuffer(PreRender* this, Gfx** gfxp); -void PreRender_SaveFramebuffer(PreRender* this, Gfx** gfxp); -void PreRender_FetchFbufCoverage(PreRender* this, Gfx** gfxp); -void PreRender_DrawCoverage(PreRender* this, Gfx** gfxp); -void PreRender_RestoreZBuffer(PreRender* this, Gfx** gfxp); -void func_80170798(PreRender* this, Gfx** gfxp); -void func_80170AE0(PreRender* this, Gfx** gfxp, s32 alpha); -void PreRender_RestoreFramebuffer(PreRender* this, Gfx** gfxp); -void PreRender_AntiAliasFilterPixel(PreRender* this, s32 x, s32 y); -void PreRender_AntiAliasFilter(PreRender* this); +void PreRender_SetValuesSave(PreRender* thisx, u32 width, u32 height, void* fbuf, void* zbuf, void* cvg); +void PreRender_Init(PreRender* thisx); +void PreRender_SetValues(PreRender* thisx, u32 width, u32 height, void* fbuf, void* zbuf); +void PreRender_Destroy(PreRender* thisx); +void PreRender_CopyImage(PreRender* thisx, Gfx** gfxp, void* img, void* imgDst, u32 useThresholdAlphaCompare); +void PreRender_RestoreBuffer(PreRender* thisx, Gfx** gfxp, void* buf, void* bufSave); +void func_8016FF90(PreRender* thisx, Gfx** gfxp, void* buf, void* bufSave, s32 envR, s32 envG, s32 envB, s32 envA); +void func_80170200(PreRender* thisx, Gfx** gfxp, void* buf, void* bufSave); +void PreRender_CoverageRgba16ToI8(PreRender* thisx, Gfx** gfxp, void* img, void* cvgDst); +void PreRender_SaveZBuffer(PreRender* thisx, Gfx** gfxp); +void PreRender_SaveFramebuffer(PreRender* thisx, Gfx** gfxp); +void PreRender_FetchFbufCoverage(PreRender* thisx, Gfx** gfxp); +void PreRender_DrawCoverage(PreRender* thisx, Gfx** gfxp); +void PreRender_RestoreZBuffer(PreRender* thisx, Gfx** gfxp); +void func_80170798(PreRender* thisx, Gfx** gfxp); +void func_80170AE0(PreRender* thisx, Gfx** gfxp, s32 alpha); +void PreRender_RestoreFramebuffer(PreRender* thisx, Gfx** gfxp); +void PreRender_AntiAliasFilterPixel(PreRender* thisx, s32 x, s32 y); +void PreRender_AntiAliasFilter(PreRender* thisx); u32 PreRender_Get5bMedian9(u8* px1, u8* px2, u8* px3); -void PreRender_DivotFilter(PreRender* this); -void PreRender_ApplyFilters(PreRender* this); -void PreRender_ApplyFiltersSlowlyInit(PreRender* this); -void PreRender_ApplyFiltersSlowlyDestroy(PreRender* this); -void func_801720C4(PreRender* this); -void Prerender_DrawBackground2D(Gfx** gfxp, void* timg, void* tlut, u16 width, u16 height, u8 fmt, u8 siz, u16 tt, u16 tlutCount, f32 x, f32 y, f32 xScale, f32 yScale, u32 flags); +void PreRender_DivotFilter(PreRender* thisx); +void PreRender_ApplyFilters(PreRender* thisx); +void PreRender_ApplyFiltersSlowlyInit(PreRender* thisx); +void PreRender_ApplyFiltersSlowlyDestroy(PreRender* thisx); +void func_801720C4(PreRender* thisx); +void Prerender_DrawBackground2D(Gfx** gfxp, void* timg, void* tlut, u16 width, u16 height, u8 fmt, u8 siz, u16 tt, + u16 tlutCount, f32 x, f32 y, f32 xScale, f32 yScale, u32 flags); + +#ifdef __cplusplus +} +#undef thisx +#endif #endif diff --git a/mm/include/z64scene.h b/mm/include/z64scene.h index 6562d3261..3fac5d349 100644 --- a/mm/include/z64scene.h +++ b/mm/include/z64scene.h @@ -17,6 +17,7 @@ struct PlayState; typedef struct { /* 0x0 */ uintptr_t vromStart; /* 0x4 */ uintptr_t vromEnd; + char* fileName; } RomFile; // size = 0x8 #define ROOM_DRAW_OPA (1 << 0) diff --git a/mm/include/z64skybox.h b/mm/include/z64skybox.h index 0a981d23e..30dd9ead2 100644 --- a/mm/include/z64skybox.h +++ b/mm/include/z64skybox.h @@ -23,7 +23,7 @@ typedef enum SkyboxId { typedef struct SkyboxContext { /* 0x000 */ View view; - /* 0x168 */ void* staticSegments[4]; + /* 0x168 */ void* staticSegments[2][5]; /* 0x178 */ void* paletteStaticSegment; /* 0x17C */ Gfx (*dListBuf)[150]; /* 0x180 */ Gfx* roomDL; @@ -41,6 +41,33 @@ typedef struct SkyboxContext { /* 0x225 */ Color_RGB8 env; } SkyboxContext; // size = 0x228 +typedef struct { + char** file; + char* palette; +} SkyboxFiles; + +#if 0 +typedef struct SkyboxContext { + /* 0x000 */ View view; + /* 0x168 */ void* staticSegments[4]; + /* 0x178 */ void* paletteStaticSegment; + /* 0x17C */ Gfx (*dListBuf)[150]; + /* 0x180 */ Gfx* roomDL; + /* 0x184 */ Vtx* roomVtx; + /* 0x188 */ DmaRequest unk188; + /* 0x1A8 */ DmaRequest unk1A8; + /* 0x1C8 */ DmaRequest unk1C8; + /* 0x1E8 */ OSMesgQueue loadQueue; + /* 0x200 */ OSMesg loadMsg; + /* 0x204 */ s16 skyboxShouldDraw; + /* 0x208 */ Vec3f rot; + /* 0x214 */ Vec3f eye; + /* 0x220 */ s16 angle; + /* 0x222 */ Color_RGB8 prim; + /* 0x225 */ Color_RGB8 env; +} SkyboxContext; // size = 0x228 +#endif + typedef struct struct_801C5F44 { /* 0x00 */ s32 unk0; /* 0x04 */ s32 unk4; @@ -49,14 +76,16 @@ typedef struct struct_801C5F44 { /* 0x10 */ s32 unk10; } struct_801C5F44; // size = 0x14 -s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, s32 arg8); +s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, + s32 arg8); void func_80143148(SkyboxContext* skyboxCtx, s32 arg1); void Skybox_Setup(struct GameState* gameState, SkyboxContext* skyboxCtx, s16 skyboxId); void func_80143324(struct PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId); void Skybox_Init(struct GameState* gameState, SkyboxContext* skyboxCtx, s16 skyboxId); Mtx* Skybox_UpdateMatrix(SkyboxContext* skyboxCtx, f32 x, f32 y, f32 z); void Skybox_SetColors(SkyboxContext* skyboxCtx, u8 primR, u8 primG, u8 primB, u8 envR, u8 envG, u8 envB); -void Skybox_Draw(SkyboxContext* skyboxCtx, struct GraphicsContext* gfxCtx, s16 skyboxId, s16 blend, f32 x, f32 y, f32 z); +void Skybox_Draw(SkyboxContext* skyboxCtx, struct GraphicsContext* gfxCtx, s16 skyboxId, s16 blend, f32 x, f32 y, + f32 z); void Skybox_Update(SkyboxContext* skyboxCtx); #endif diff --git a/mm/include/z64visfbuf.h b/mm/include/z64visfbuf.h index 00961b7da..a9d04bb9e 100644 --- a/mm/include/z64visfbuf.h +++ b/mm/include/z64visfbuf.h @@ -1,6 +1,11 @@ #ifndef Z64_VISFBUF_H #define Z64_VISFBUF_H +#ifdef __cplusplus +extern "C" { +#define this thisx +#endif + #include "ultra64.h" #include "color.h" #include "PR/gs2dex.h" @@ -27,12 +32,19 @@ typedef struct VisFbuf { void VisFbuf_Init(VisFbuf* this); void VisFbuf_Destroy(VisFbuf* this); void VisFbuf_DrawBgToColorImage(Gfx** gfxP, uObjBg* bg, void* img, s32 width, s32 height, VisFbufBgMode cycleMode); -void VisFbuf_SetBg(Gfx** gfxP, void* source, void* img, s32 width, s32 height, f32 x, f32 y, f32 scaleX, f32 scaleY, VisFbufBgMode cycleMode); +void VisFbuf_SetBg(Gfx** gfxP, void* source, void* img, s32 width, s32 height, f32 x, f32 y, f32 scaleX, f32 scaleY, + VisFbufBgMode cycleMode); void VisFbuf_SetBgSimple(Gfx** gfxP, void* source, void* img, s32 width, s32 height, VisFbufBgMode cycleMode); -void VisFbuf_SetBgGeneral(Gfx** gfxP, void* source, void* img, s32 width, s32 height, f32 x, f32 y, f32 scaleX, f32 scaleY, VisFbufBgMode cycleMode); +void VisFbuf_SetBgGeneral(Gfx** gfxP, void* source, void* img, s32 width, s32 height, f32 x, f32 y, f32 scaleX, + f32 scaleY, VisFbufBgMode cycleMode); void VisFbuf_ApplyEffects(VisFbuf* this, Gfx** gfxP, void* source, void* img, s32 width, s32 height); void VisFbuf_DrawGeneral(VisFbuf* this, Gfx** gfxP, void* source, void* img, s32 width, s32 height); void VisFbuf_DrawInterpolate(VisFbuf* this, Gfx** gfxP, void* img, s32 width, s32 height); void VisFbuf_Draw(VisFbuf* this, Gfx** gfxP, void* img); +#ifdef __cplusplus +} +#undef this +#endif + #endif diff --git a/mm/src/audio/lib/load.c b/mm/src/audio/lib/load.c index d4e23a86a..95b0e5698 100644 --- a/mm/src/audio/lib/load.c +++ b/mm/src/audio/lib/load.c @@ -32,7 +32,7 @@ typedef struct { void AudioLoad_DiscardFont(s32 fontId); s32 AudioLoad_SyncInitSeqPlayerInternal(s32 playerIndex, s32 seqId, s32 arg2); u8* AudioLoad_SyncLoadSeq(s32 seqId); -uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad); +u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad); SoundFontData* AudioLoad_SyncLoadFont(u32 fontId); void* AudioLoad_SyncLoad(s32 tableType, u32 id, s32* didAllocate); u32 AudioLoad_GetRealTableIndex(s32 tableType, u32 id); @@ -91,7 +91,7 @@ s8* sScriptLoadDonePointers[0x10]; s32 sAudioLoadPad1[2]; // file padding s32 D_801FD1E0; -DmaHandler sDmaHandler = osEPiStartDma; +DmaHandler sDmaHandler; //= osEPiStartDma; void* sUnusedHandler = NULL; s32 gAudioCtxInitalized = false; @@ -414,7 +414,7 @@ void AudioLoad_SyncLoadSeqParts(s32 seqId, s32 arg1, s32 arg2, OSMesgQueue* arg3 AudioLoad_SyncLoadSeq(seqId); } if (arg2 != 0) { - osSendMesg(arg3, (OSMesg)(arg2 << 0x18), OS_MESG_NOBLOCK); + osSendMesg(arg3, OS_MESG_32(arg2 << 0x18), OS_MESG_NOBLOCK); } } } @@ -431,10 +431,10 @@ s32 AudioLoad_SyncLoadSample(Sample* sample, s32 fontId) { } if (sample->medium == MEDIUM_UNK) { - AudioLoad_SyncDmaUnkMedium((uintptr_t)sample->sampleAddr, sampleAddr, sample->size, + AudioLoad_SyncDmaUnkMedium(sample->sampleAddr, sampleAddr, sample->size, gAudioCtx.sampleBankTable->unkMediumParam); } else { - AudioLoad_SyncDma((uintptr_t)sample->sampleAddr, sampleAddr, sample->size, sample->medium); + AudioLoad_SyncDma(sample->sampleAddr, sampleAddr, sample->size, sample->medium); } sample->medium = MEDIUM_RAM; sample->sampleAddr = sampleAddr; @@ -471,7 +471,7 @@ s32 AudioLoad_SyncLoadInstrument(s32 fontId, s32 instId, s32 drumId) { void AudioLoad_AsyncLoad(s32 tableType, s32 id, s32 nChunks, s32 retData, OSMesgQueue* retQueue) { if (AudioLoad_AsyncLoadInner(tableType, id, nChunks, retData, retQueue) == NULL) { - osSendMesg(retQueue, (OSMesg)0xFFFFFFFF, OS_MESG_NOBLOCK); + osSendMesg(retQueue, OS_MESG_32(0xFFFFFFFF), OS_MESG_NOBLOCK); } } @@ -632,11 +632,11 @@ u8* AudioLoad_SyncLoadSeq(s32 seqId) { return AudioLoad_SyncLoad(SEQUENCE_TABLE, seqId, &didAllocate); } -uintptr_t AudioLoad_GetSampleBank(u32 sampleBankId, u32* outMedium) { +u32 AudioLoad_GetSampleBank(u32 sampleBankId, u32* outMedium) { return AudioLoad_TrySyncLoadSampleBank(sampleBankId, outMedium, true); } -uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad) { +u32 AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 noLoad) { void* addr; AudioTable* sampleBankTable; u32 realTableId = AudioLoad_GetRealTableIndex(SAMPLE_TABLE, sampleBankId); @@ -651,7 +651,7 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 } *outMedium = MEDIUM_RAM; - return (uintptr_t)addr; + return addr; } cachePolicy = sampleBankTable->entries[sampleBankId].cachePolicy; @@ -664,7 +664,7 @@ uintptr_t AudioLoad_TrySyncLoadSampleBank(u32 sampleBankId, u32* outMedium, s32 addr = AudioLoad_SyncLoad(SAMPLE_TABLE, sampleBankId, &noLoad); if (addr != NULL) { *outMedium = MEDIUM_RAM; - return (uintptr_t)addr; + return addr; } *outMedium = sampleBankTable->entries[sampleBankId].medium; @@ -785,7 +785,7 @@ void* AudioLoad_SyncLoad(s32 tableType, u32 id, s32* didAllocate) { size -= 0x10; } - bcopy((void*)romAddr, ramAddr, size); + bcopy(romAddr, ramAddr, size); } else if (medium2 == mediumUnk) { AudioLoad_SyncDmaUnkMedium(romAddr, ramAddr, size, (s16)table->unkMediumParam); } else { @@ -867,7 +867,7 @@ AudioTable* AudioLoad_GetLoadTable(s32 tableType) { * @param sampleBankReloc information on the sampleBank containing raw audio samples */ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, SampleBankRelocInfo* sampleBankReloc) { - void* soundOffset; + uintptr_t soundOffset; uintptr_t soundListOffset; Instrument* inst; Drum* drum; @@ -876,7 +876,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample s32 numDrums = gAudioCtx.soundFontList[fontId].numDrums; s32 numInstruments = gAudioCtx.soundFontList[fontId].numInstruments; s32 numSfx = gAudioCtx.soundFontList[fontId].numSfx; - uintptr_t* fontData = (uintptr_t*)fontDataStartAddr; + u32* fontData = (u32*)fontDataStartAddr; // Relocate an offset (relative to the start of the font data) to a pointer (a ram address) #define RELOC_TO_RAM(x) (void*)((uintptr_t)(x) + (uintptr_t)(fontDataStartAddr)) @@ -889,7 +889,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample // If the soundFont has drums if ((soundListOffset != 0) && (numDrums != 0)) { - fontData[0] = (uintptr_t)RELOC_TO_RAM(soundListOffset); + fontData[0] = RELOC_TO_RAM(soundListOffset); // Loop through the drum offsets for (i = 0; i < numDrums; i++) { @@ -897,7 +897,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample soundOffset = ((Drum**)fontData[0])[i]; // Some drum data entries are empty, represented by an offset of 0 in the list of drum offsets - if (soundOffset == NULL) { + if (soundOffset == 0) { continue; } soundOffset = RELOC_TO_RAM(soundOffset); @@ -925,7 +925,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample // If the soundFont has sound effects if ((soundListOffset != 0) && (numSfx != 0)) { - fontData[1] = (uintptr_t)RELOC_TO_RAM(soundListOffset); + fontData[1] = RELOC_TO_RAM(soundListOffset); // Loop through the sound effects for (i = 0; i < numSfx; i++) { @@ -955,7 +955,7 @@ void AudioLoad_RelocateFont(s32 fontId, SoundFontData* fontDataStartAddr, Sample for (i = 2; i <= 2 + numInstruments - 1; i++) { // Some instrument data entries are empty, represented by an offset of 0 in the list of instrument offsets if (fontData[i] != 0) { - fontData[i] = (uintptr_t)RELOC_TO_RAM(fontData[i]); + fontData[i] = RELOC_TO_RAM(fontData[i]); inst = (Instrument*)fontData[i]; // The instrument may be in the list multiple times and already relocated @@ -1097,7 +1097,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData, ramAddr = AudioLoad_SearchCaches(tableType, realId); if (ramAddr != NULL) { loadStatus = LOAD_STATUS_COMPLETE; - osSendMesg(retQueue, (OSMesg)MK_ASYNC_MSG(retData, 0, 0, LOAD_STATUS_NOT_LOADED), OS_MESG_NOBLOCK); + osSendMesg(retQueue, OS_MESG_32(MK_ASYNC_MSG(retData, 0, 0, LOAD_STATUS_NOT_LOADED)), OS_MESG_NOBLOCK); } else { table = AudioLoad_GetLoadTable(tableType); size = table->entries[realId].size; @@ -1263,8 +1263,8 @@ void AudioLoad_Init(void* heap, size_t heapSize) { gAudioCtx.curAiBufferIndex = 0; gAudioCtx.soundMode = SOUNDMODE_STEREO; gAudioCtx.curTask = NULL; - gAudioCtx.rspTask[0].task.t.dataSize = 0; - gAudioCtx.rspTask[1].task.t.dataSize = 0; + gAudioCtx.rspTask[0].task.t.data_size = 0; + gAudioCtx.rspTask[1].task.t.data_size = 0; osCreateMesgQueue(&gAudioCtx.syncDmaQueue, &gAudioCtx.syncDmaMesg, 1); osCreateMesgQueue(&gAudioCtx.curAudioFrameDmaQueue, gAudioCtx.currAudioFrameDmaMesgBuf, @@ -1330,7 +1330,7 @@ void AudioLoad_Init(void* heap, size_t heapSize) { AudioHeap_InitPool(&gAudioCtx.permanentPool, addr, gAudioHeapInitSizes.permanentPoolSize); gAudioCtxInitalized = true; - osSendMesg(gAudioCtx.taskStartQueueP, (void*)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); + osSendMesg(gAudioCtx.taskStartQueueP, OS_MESG_32(gAudioCtx.totalTaskCount), OS_MESG_NOBLOCK); } void AudioLoad_InitSlowLoads(void) { @@ -1376,7 +1376,7 @@ s32 AudioLoad_SlowLoadSample(s32 fontId, s32 instId, s8* isDone) { slowLoad->status = LOAD_STATUS_START; slowLoad->bytesRemaining = ALIGN16(sample->size); slowLoad->ramAddr = slowLoad->curRamAddr; - slowLoad->curDevAddr = (uintptr_t)sample->sampleAddr; + slowLoad->curDevAddr = sample->sampleAddr; slowLoad->medium = sample->medium; slowLoad->seqOrFontId = fontId; slowLoad->instId = instId; @@ -1464,7 +1464,7 @@ void AudioLoad_ProcessSlowLoads(s32 resetStatus) { if (slowLoad->medium == MEDIUM_UNK) { size_t size = slowLoad->bytesRemaining; - AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, (uintptr_t)slowLoad->curRamAddr, size, + AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, slowLoad->curRamAddr, size, slowLoad->unkMediumParam); } else { AudioLoad_DmaSlowCopy(slowLoad, slowLoad->bytesRemaining); @@ -1472,7 +1472,7 @@ void AudioLoad_ProcessSlowLoads(s32 resetStatus) { slowLoad->bytesRemaining = 0; } else { if (slowLoad->medium == MEDIUM_UNK) { - AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, (uintptr_t)slowLoad->curRamAddr, 0x400, + AudioLoad_DmaSlowCopyUnkMedium(slowLoad->curDevAddr, slowLoad->curRamAddr, 0x400, slowLoad->unkMediumParam); } else { AudioLoad_DmaSlowCopy(slowLoad, 0x400); @@ -1550,7 +1550,7 @@ AudioAsyncLoad* AudioLoad_StartAsyncLoadUnkMedium(s32 unkMediumParam, uintptr_t return NULL; } - osSendMesg(&gAudioCtx.asyncLoadUnkMediumQueue, asyncLoad, OS_MESG_NOBLOCK); + osSendMesg(&gAudioCtx.asyncLoadUnkMediumQueue, OS_MESG_PTR(asyncLoad), OS_MESG_NOBLOCK); asyncLoad->unkMediumParam = unkMediumParam; return asyncLoad; } @@ -1671,10 +1671,10 @@ void AudioLoad_FinishAsyncLoad(AudioAsyncLoad* asyncLoad) { break; } - doneMsg = (OSMesg)asyncLoad->retMsg; + // doneMsg = asyncLoad->retMsg; if (1) {} asyncLoad->status = LOAD_STATUS_WAITING; - osSendMesg(asyncLoad->retQueue, doneMsg, OS_MESG_NOBLOCK); + // osSendMesg(asyncLoad->retQueue, doneMsg, OS_MESG_NOBLOCK); } void AudioLoad_ProcessAsyncLoad(AudioAsyncLoad* asyncLoad, s32 resetStatus) { @@ -1743,8 +1743,8 @@ void AudioLoad_AsyncDmaRamUnloaded(AudioAsyncLoad* asyncLoad, size_t size) { size = ALIGN16(size); Audio_InvalDCache(asyncLoad->curRamAddr, size); osCreateMesgQueue(&asyncLoad->msgQueue, &asyncLoad->msg, 1); - bcopy((void*)asyncLoad->curDevAddr, asyncLoad->curRamAddr, size); - osSendMesg(&asyncLoad->msgQueue, NULL, OS_MESG_NOBLOCK); + bcopy(asyncLoad->curDevAddr, asyncLoad->curRamAddr, size); + osSendMesg(&asyncLoad->msgQueue, OS_MESG_PTR(NULL), OS_MESG_NOBLOCK); } void AudioLoad_AsyncDmaUnkMedium(uintptr_t devAddr, void* ramAddr, size_t size, s16 arg3) { diff --git a/mm/src/audio/lib/thread.c b/mm/src/audio/lib/thread.c index e1acb1583..632906b8a 100644 --- a/mm/src/audio/lib/thread.c +++ b/mm/src/audio/lib/thread.c @@ -20,6 +20,8 @@ AudioTask* AudioThread_Update(void) { } AudioTask* AudioThread_UpdateImpl(void) { + // BENTODO + #if 0 static AudioTask* sWaitingAudioTask = NULL; u32 numSamplesRemainingInAi; s32 numAbiCmds; @@ -47,7 +49,7 @@ AudioTask* AudioThread_UpdateImpl(void) { return NULL; } - osSendMesg(gAudioCtx.taskStartQueueP, (OSMesg)gAudioCtx.totalTaskCount, OS_MESG_NOBLOCK); + osSendMesg(gAudioCtx.taskStartQueueP, OS_MESG_32(gAudioCtx.totalTaskCount), OS_MESG_NOBLOCK); gAudioCtx.rspTaskIndex ^= 1; gAudioCtx.curAiBufferIndex++; gAudioCtx.curAiBufferIndex %= 3; @@ -96,7 +98,7 @@ AudioTask* AudioThread_UpdateImpl(void) { if (gAudioCtx.resetStatus != 0) { if (AudioHeap_ResetStep() == 0) { if (gAudioCtx.resetStatus == 0) { - osSendMesg(gAudioCtx.audioResetQueueP, (OSMesg)(uintptr_t)gAudioCtx.specId, OS_MESG_NOBLOCK); + osSendMesg(gAudioCtx.audioResetQueueP, OS_MESG_8(gAudioCtx.specId), OS_MESG_NOBLOCK); } sWaitingAudioTask = NULL; @@ -168,21 +170,21 @@ AudioTask* AudioThread_UpdateImpl(void) { task = &gAudioCtx.curTask->task.t; task->type = M_AUDTASK; task->flags = 0; - task->ucodeBoot = aspMainTextStart; - task->ucodeBootSize = SP_UCODE_SIZE; - task->ucodeDataSize = ((aspMainDataEnd - aspMainDataStart) * sizeof(u64)) - 1; + task->ucode_boot = aspMainTextStart; + task->ucode_boot_size = SP_UCODE_SIZE; + task->ucode_data_size = ((aspMainDataEnd - aspMainDataStart) * sizeof(u64)) - 1; task->ucode = aspMainTextStart; - task->ucodeData = aspMainDataStart; - task->ucodeSize = SP_UCODE_SIZE; - task->dramStack = (u64*)D_801D6200; - task->dramStackSize = 0; - task->outputBuff = NULL; - task->outputBuffSize = NULL; + task->ucode_data = aspMainDataStart; + task->ucode_size = SP_UCODE_SIZE; + task->dram_stack = (u64*)D_801D6200; + task->dram_stack_size = 0; + task->output_buff = NULL; + task->output_buff_size = NULL; if (1) {} - task->dataPtr = (u64*)gAudioCtx.abiCmdBufs[index]; - task->dataSize = numAbiCmds * sizeof(Acmd); - task->yieldDataPtr = NULL; - task->yieldDataSize = 0; + task->data_ptr = (u64*)gAudioCtx.abiCmdBufs[index]; + task->data_size = numAbiCmds * sizeof(Acmd); + task->yield_data_ptr = NULL; + task->yield_data_size = 0; if (gAudioCtx.numAbiCmdsMax < numAbiCmds) { gAudioCtx.numAbiCmdsMax = numAbiCmds; @@ -194,6 +196,7 @@ AudioTask* AudioThread_UpdateImpl(void) { sWaitingAudioTask = gAudioCtx.curTask; return NULL; } + #endif } void AudioThread_ProcessGlobalCmd(AudioCmd* cmd) { @@ -430,7 +433,7 @@ s32 AudioThread_ScheduleProcessCmds(void) { } ret = osSendMesg(gAudioCtx.threadCmdProcQueueP, - (void*)(((gAudioCtx.threadCmdReadPos & 0xFF) << 8) | (gAudioCtx.threadCmdWritePos & 0xFF)), + OS_MESG_PTR(((gAudioCtx.threadCmdReadPos & 0xFF) << 8) | (gAudioCtx.threadCmdWritePos & 0xFF)), OS_MESG_NOBLOCK); if (ret != -1) { gAudioCtx.threadCmdReadPos = gAudioCtx.threadCmdWritePos; diff --git a/mm/src/audio/sfx.c b/mm/src/audio/sfx.c index f66747999..79d10804b 100644 --- a/mm/src/audio/sfx.c +++ b/mm/src/audio/sfx.c @@ -741,6 +741,8 @@ void AudioSfx_StopByPosAndBank(u8 bankId, Vec3f* pos) { } void AudioSfx_StopByPos(Vec3f* pos) { +// BENTODO: infinite loop +#if 0 u8 bankId; SfxBankEntry entryToRemove; @@ -750,6 +752,7 @@ void AudioSfx_StopByPos(Vec3f* pos) { entryToRemove.posX = &pos->x; AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_POS, &entryToRemove); +#endif } void AudioSfx_StopByPosAndId(Vec3f* pos, u16 sfxId) { @@ -814,6 +817,8 @@ void AudioSfx_StopByTokenAndId(u8 token, u16 sfxId) { } void AudioSfx_StopById(u32 sfxId) { + // BENTODO: infinite loop +#if 0 SfxBankEntry* entry; u8 entryIndex = gSfxBanks[SFX_BANK(sfxId)][0].next; u8 prevEntryIndex = 0; @@ -837,6 +842,7 @@ void AudioSfx_StopById(u32 sfxId) { entryToRemove.sfxId = sfxId; AudioSfx_RemoveMatchingRequests(SFX_RM_REQ_BY_ID, &entryToRemove); +#endif } void AudioSfx_ProcessRequests(void) { diff --git a/mm/src/audio/voice_external.c b/mm/src/audio/voice_external.c index 00d5f24a0..95eca9cde 100644 --- a/mm/src/audio/voice_external.c +++ b/mm/src/audio/voice_external.c @@ -36,6 +36,7 @@ void func_801A4EB0(void) { } void func_801A4EB8(void) { + #if 0 u8* new_var; OSMesgQueue* serialEventQueue; s32 index; @@ -65,10 +66,12 @@ void func_801A4EB8(void) { func_801A53E8(800, 2, VOICE_WARN_TOO_SMALL, 500, 2000); D_801D8E3C = 1; } + #endif } // Used externally in code_8019AF00 void func_801A4FD8(void) { +#if 0 s32 errorCode; OSMesgQueue* serialEventQueue; @@ -88,6 +91,7 @@ void func_801A4FD8(void) { func_801A5080(VOICE_WORD_ID_HIYA); func_801A5080(VOICE_WORD_ID_CHEESE); } + #endif } void func_801A5080(u16 wordId) { diff --git a/mm/src/audio/voice_internal.c b/mm/src/audio/voice_internal.c index c5df0c652..1efd76153 100644 --- a/mm/src/audio/voice_internal.c +++ b/mm/src/audio/voice_internal.c @@ -58,6 +58,8 @@ s32 func_801A51F0(s32 errorCode) { } s32 func_801A5228(OSVoiceDictionary* dict) { + return 0; + #if 0 OSMesgQueue* serialEventQueue; s32 errorCode; u8 numWords; @@ -95,9 +97,12 @@ s32 func_801A5228(OSVoiceDictionary* dict) { } return errorCode; + #endif } OSVoiceData* func_801A5390(void) { + return NULL; +#if 0 OSVoiceData* voiceData; OSMesgQueue* serialEventQueue; @@ -109,6 +114,7 @@ OSVoiceData* func_801A5390(void) { PadMgr_VoiceReleaseSerialEventQueue(serialEventQueue); return voiceData; + #endif } // Unused @@ -127,6 +133,7 @@ void func_801A53E8(u16 distance, u16 answerNum, u16 warning, u16 voiceLevel, u16 // Unused // Could have a return? or be void return? s32 func_801A541C(s32 analog, s32 digital) { + #if 0 s32 errorCode; OSMesgQueue* serialEventQueue; @@ -139,10 +146,13 @@ s32 func_801A541C(s32 analog, s32 digital) { func_801A51F0(errorCode); } } + #endif } // Unused s32 func_801A5488(u8* word) { + return 0; +#if 0 s32 errorCode; OSMesgQueue* serialEventQueue; @@ -151,6 +161,7 @@ s32 func_801A5488(u8* word) { PadMgr_VoiceReleaseSerialEventQueue(serialEventQueue); return errorCode; + #endif } u8* func_801A54C4(void) { @@ -158,6 +169,8 @@ u8* func_801A54C4(void) { } s32 func_801A54D0(u16 wordId) { + return 0; +#if 0 s32 errorCode; u8 phi_t0 = true; u8 numWords; @@ -198,9 +211,12 @@ s32 func_801A54D0(u16 wordId) { } return errorCode; + #endif } s32 func_801A5680(u16 wordId) { + return 0; + #if 0 s32 errorCode; u8 phi_a3 = true; u8 numWords; @@ -241,9 +257,12 @@ s32 func_801A5680(u16 wordId) { } return errorCode; + #endif } s32 func_801A5808(void) { + return 0; + #if 0 s32 errorCode = 0; s32 ret; OSMesgQueue* serialEventQueue; @@ -312,6 +331,7 @@ s32 func_801A5808(void) { ret = func_801A51F0(errorCode); return ret; + #endif } // Unused diff --git a/mm/src/boot/O2/__osMalloc.c b/mm/src/boot/O2/__osMalloc.c index 71a5a5ba3..085f6286c 100644 --- a/mm/src/boot/O2/__osMalloc.c +++ b/mm/src/boot/O2/__osMalloc.c @@ -26,11 +26,11 @@ void ArenaImpl_LockInit(Arena* arena) { } void ArenaImpl_Lock(Arena* arena) { - osSendMesg(&arena->lock, NULL, OS_MESG_BLOCK); + //osSendMesg(&arena->lock, NULL, OS_MESG_BLOCK); } void ArenaImpl_Unlock(Arena* arena) { - osRecvMesg(&arena->lock, NULL, OS_MESG_BLOCK); + //osRecvMesg(&arena->lock, NULL, OS_MESG_BLOCK); } ArenaNode* ArenaImpl_GetLastBlock(Arena* arena) { diff --git a/mm/src/boot/O2/debug.c b/mm/src/boot/O2/debug.c index 3933b585e..b146000d2 100644 --- a/mm/src/boot/O2/debug.c +++ b/mm/src/boot/O2/debug.c @@ -2,7 +2,7 @@ #include "fault.h" void _dbg_hungup(const char* file, int lineNum) { - osGetThreadId(NULL); + //osGetThreadId(NULL); Fault_AddHungupAndCrash(file, lineNum); } diff --git a/mm/src/boot/O2/fmodf.c b/mm/src/boot/O2/fmodf.c index 2f8aa74bf..b83b635f3 100644 --- a/mm/src/boot/O2/fmodf.c +++ b/mm/src/boot/O2/fmodf.c @@ -1,5 +1,5 @@ #include "global.h" - +#if 0 f32 fmodf(f32 dividend, f32 divisor) { s32 quotient; @@ -10,3 +10,4 @@ f32 fmodf(f32 dividend, f32 divisor) { return dividend - quotient * divisor; } +#endif \ No newline at end of file diff --git a/mm/src/boot/O2/gfxprint.c b/mm/src/boot/O2/gfxprint.c index b52675829..c123bb0eb 100644 --- a/mm/src/boot/O2/gfxprint.c +++ b/mm/src/boot/O2/gfxprint.c @@ -7,11 +7,131 @@ #define GFXP_FLAG_ENLARGE (1 << 6) #define GFXP_FLAG_OPEN (1 << 7) -//! TODO: Need to extract -extern u16 sGfxPrintFontTLUT[64]; -extern u16 sGfxPrintRainbowTLUT[16]; -extern u8 sGfxPrintRainbowData[8]; -extern u8 sGfxPrintFontData[2048]; +static u16 sGfxPrintFontTLUT[64] = { + 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, + 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, + 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +static u16 sGfxPrintRainbowTLUT[16] = { + 0xF801, 0xFBC1, 0xFFC1, 0x07C1, 0x0421, 0x003F, 0x803F, 0xF83F, + 0xF801, 0xFBC1, 0xFFC1, 0x07C1, 0x0421, 0x003F, 0x803F, 0xF83F, +}; + +static u8 sGfxPrintRainbowData[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; + +static u8 sGfxPrintFontData[(16 * 256) / 2] = { + 0x00, 0xDF, 0xFD, 0x00, 0x0A, 0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D, 0xC0, 0x01, 0x12, 0x2D, + 0xD0, 0x06, 0x71, 0x99, 0x00, 0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56, 0x29, 0x90, 0x05, 0x58, + 0x97, 0x60, 0x0D, 0xD2, 0x29, 0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02, 0x6E, 0xF7, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xBF, 0xFB, 0x00, 0x0E, 0xFF, 0xFF, 0xC0, 0x0B, 0xF0, 0x0F, 0xB0, + 0x0F, 0xF0, 0x03, 0x30, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x02, 0x20, 0x0C, 0xFB, 0xBF, 0x60, 0x0F, 0xFC, 0xCE, + 0x20, 0x0D, 0xD4, 0x4F, 0xF0, 0x0F, 0xF0, 0x02, 0x20, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x03, 0x30, 0x0C, 0xFB, + 0xBF, 0x40, 0x0E, 0xF7, 0x77, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0xFD, 0x00, 0x0A, + 0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D, 0xC0, 0x01, 0x12, 0x2D, 0xD0, 0x06, 0x71, 0x99, 0x00, + 0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56, 0x29, 0x90, 0x05, 0x58, 0x97, 0x60, 0x0D, 0xD2, 0x29, + 0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02, 0x6E, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0xBF, 0xFB, 0x00, 0x00, 0x0D, 0xE0, 0x00, 0x0B, 0xF0, 0x0F, 0xB0, 0x00, 0x5D, 0xE6, 0x00, 0x0F, + 0xF0, 0x0F, 0xF0, 0x05, 0x5C, 0xC6, 0x60, 0x0C, 0xFB, 0xBF, 0x60, 0x77, 0x3F, 0xF3, 0x77, 0x0D, 0xD4, 0x4F, 0xF0, + 0xBB, 0x3F, 0xF3, 0xBB, 0x0F, 0xF0, 0x0F, 0xF0, 0x09, 0x9C, 0xCA, 0xA0, 0x0C, 0xFB, 0xBF, 0x40, 0x00, 0x9D, 0xEA, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0xE0, 0x00, 0x04, 0xC2, 0x2C, 0x40, 0x02, 0x8D, 0x50, 0x20, 0x0C, 0xCA, + 0xAC, 0xC0, 0x21, 0xF9, 0x17, 0x10, 0x04, 0xC2, 0x2C, 0x40, 0x12, 0x49, 0x34, 0x00, 0x00, 0x82, 0x08, 0x00, 0x01, + 0x97, 0x51, 0x10, 0x08, 0x8A, 0x88, 0x80, 0x04, 0x61, 0x52, 0x41, 0x00, 0x80, 0x08, 0x00, 0x43, 0x11, 0x75, 0x30, + 0x00, 0xA2, 0x08, 0x00, 0x60, 0x05, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x40, 0x00, 0x22, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x0F, 0xB0, 0x00, 0x00, 0x00, 0x08, 0x80, 0x04, 0x0D, 0xA4, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x08, 0xCD, 0xE8, 0x80, 0x02, 0x2A, 0xA2, 0x20, 0x08, 0xCD, 0xE8, 0x80, 0x02, 0xAA, 0x22, 0x20, 0x04, + 0x0D, 0xA4, 0x00, 0x0C, 0xD1, 0x00, 0x00, 0x00, 0x0F, 0xB0, 0x00, 0x8C, 0x51, 0x00, 0x00, 0x00, 0x22, 0x11, 0x00, + 0x81, 0x10, 0x00, 0x00, 0x00, 0xDF, 0xFD, 0x00, 0x0A, 0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D, + 0xC0, 0x01, 0x12, 0x2D, 0xD0, 0x06, 0x71, 0x99, 0x00, 0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56, + 0x29, 0x90, 0x05, 0x58, 0x97, 0x60, 0x0D, 0xD2, 0x29, 0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02, + 0x6E, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x00, 0x04, 0x48, 0x99, 0x80, + 0x03, 0x3C, 0xC3, 0x30, 0x00, 0xCD, 0x10, 0x88, 0x03, 0x3C, 0xC3, 0x30, 0x02, 0xBF, 0x62, 0xA8, 0x00, 0x33, 0x33, + 0x20, 0x01, 0x10, 0x4C, 0x80, 0x01, 0x10, 0x03, 0x30, 0x00, 0x15, 0xC8, 0x00, 0x03, 0x3C, 0xC3, 0x30, 0x02, 0x67, + 0x32, 0x20, 0x00, 0x3F, 0xF3, 0x00, 0x04, 0x40, 0x99, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, + 0xDF, 0xFD, 0x10, 0x07, 0xFF, 0xFF, 0x60, 0x1C, 0xE0, 0x0E, 0xC1, 0x0F, 0xF0, 0x09, 0x90, 0x1E, 0xE1, 0x16, 0x61, + 0x0F, 0xF0, 0x01, 0x10, 0x1E, 0xF4, 0x56, 0x21, 0x0F, 0xF6, 0x67, 0x10, 0x1E, 0xF2, 0x36, 0x61, 0x0F, 0xF0, 0x89, + 0x90, 0x1E, 0xF1, 0x0F, 0xE1, 0x0F, 0xF0, 0x09, 0x90, 0x16, 0xEC, 0xCE, 0x21, 0x07, 0xFB, 0xBB, 0x20, 0x01, 0x11, + 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x09, 0xB6, 0x6F, 0xD0, 0x27, 0xD8, 0x8E, 0x60, 0x09, 0x92, 0xED, 0x10, 0x2F, + 0xF0, 0x2E, 0xE0, 0x09, 0x9A, 0xE5, 0x10, 0x2F, 0xF6, 0x2E, 0xE0, 0x09, 0x9B, 0x75, 0x10, 0x2F, 0xD6, 0x4E, 0xE0, + 0x0D, 0xDA, 0xE5, 0x10, 0x2F, 0xD0, 0x4E, 0xE0, 0x0D, 0xD2, 0xED, 0x10, 0x2F, 0xD0, 0x0E, 0xE0, 0x09, 0xF6, 0x6F, + 0x90, 0x27, 0xD9, 0x9F, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x8F, 0x71, + 0x1F, 0xF0, 0x2F, 0xD0, 0x0F, 0xF0, 0x8F, 0x71, 0x1F, 0xF0, 0x2F, 0xD0, 0x07, 0x70, 0x8E, 0x61, 0x1E, 0xE0, 0x27, + 0xDD, 0xDF, 0x60, 0x8E, 0x69, 0x1E, 0xE0, 0x27, 0x76, 0x4A, 0xA0, 0x8E, 0xE9, 0x9E, 0xE0, 0x2F, 0xD0, 0x6E, 0x80, + 0x8A, 0xE7, 0xFE, 0xA0, 0x07, 0xFA, 0x8E, 0x60, 0x88, 0x27, 0x7A, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x7C, 0xCF, 0xF0, 0x13, 0x26, 0x60, 0x11, 0x07, 0x7C, 0xCF, 0xF0, 0x03, 0x76, 0x65, 0x10, 0x02, 0x39, + 0xD7, 0x20, 0x04, 0x53, 0x35, 0x40, 0x00, 0x2F, 0xF2, 0x00, 0x01, 0x13, 0x31, 0x10, 0x00, 0x5F, 0xB1, 0x00, 0x00, + 0x03, 0x30, 0x00, 0x05, 0x5E, 0xE5, 0x50, 0x01, 0x13, 0x31, 0x10, 0x05, 0x5E, 0xED, 0xD0, 0x02, 0x23, 0x30, 0x00, + 0x00, 0x08, 0x88, 0x80, 0x8A, 0xAB, 0xB8, 0x88, 0x00, 0x00, 0x11, 0x00, 0x00, 0x04, 0x45, 0x10, 0x04, 0x62, 0x33, + 0x20, 0x00, 0x44, 0x01, 0x10, 0x04, 0xC8, 0x9A, 0xA0, 0x00, 0xEE, 0xAB, 0x10, 0x0C, 0xE6, 0x67, 0x20, 0x0E, 0xF5, + 0x5F, 0xB0, 0x0E, 0xE0, 0x06, 0x60, 0x0B, 0xF6, 0x2B, 0x90, 0x0E, 0xE0, 0x06, 0x60, 0x03, 0xFC, 0x89, 0x90, 0x04, + 0xEE, 0xEE, 0xA0, 0x00, 0x77, 0x3B, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x88, 0x88, 0x00, 0x09, 0x90, 0x00, 0x00, + 0x00, 0x11, 0x10, 0x00, 0x09, 0x92, 0x24, 0x40, 0x00, 0x01, 0x10, 0x00, 0x09, 0x90, 0x88, 0x00, 0x26, 0xEF, 0xDE, + 0x20, 0x09, 0x9B, 0xB5, 0x40, 0x2E, 0xC3, 0x3C, 0xE2, 0x0D, 0x9A, 0x25, 0x50, 0x2E, 0xC3, 0x3C, 0xE2, 0x0D, 0xDA, + 0xA5, 0x50, 0x2E, 0xC3, 0x3C, 0xE2, 0x09, 0xD6, 0xED, 0x10, 0x26, 0xCB, 0xBC, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, + 0x05, 0xFB, 0xFF, 0xE0, 0x8E, 0x61, 0x16, 0xE8, 0x0F, 0xF4, 0x03, 0x30, 0x8F, 0x71, 0x17, 0xF8, 0x07, 0xFC, 0x8B, + 0x30, 0x8E, 0x69, 0x96, 0xE8, 0x05, 0x73, 0x3B, 0xA0, 0x8A, 0x6D, 0xD6, 0xA8, 0x0D, 0xD8, 0x8A, 0x20, 0x08, 0xA7, + 0x79, 0xB2, 0x01, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8A, 0x01, 0x10, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x80, 0xA1, 0x10, 0x00, 0x07, 0x74, 0x4F, 0x70, 0x80, 0xA9, 0x90, 0x00, 0x02, 0x31, 0xDF, 0x20, + 0x84, 0xE6, 0x00, 0x04, 0x00, 0x27, 0xDA, 0x20, 0xC8, 0xAA, 0x4C, 0x40, 0x00, 0x57, 0x3B, 0x20, 0x00, 0xA1, 0x18, + 0x00, 0x05, 0x54, 0x6F, 0x50, 0x00, 0xA9, 0x98, 0x00, 0x02, 0x22, 0x20, 0x80, 0x02, 0x00, 0x18, 0x88, 0x00, 0x04, + 0x44, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40, 0x0C, 0x44, 0x44, 0x00, 0x00, 0x04, 0x40, 0x00, 0x88, + 0xC0, 0x00, 0x00, 0x00, 0x0C, 0xC0, 0x00, 0x0C, 0x46, 0xA4, 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x08, 0x8E, 0xE0, 0x00, + 0x02, 0x08, 0x80, 0x00, 0x80, 0xD0, 0x88, 0x00, 0x28, 0xA8, 0x80, 0x00, 0x88, 0xCD, 0x4C, 0x40, 0x0A, 0x88, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xE0, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x88, 0x00, 0x80, 0x01, 0x06, 0x10, 0x00, 0x56, 0xE7, 0x50, 0x80, 0x02, 0x1F, 0xF1, 0x00, 0x38, + 0x8C, 0xB8, 0x00, 0x0B, 0xF6, 0x0B, 0x00, 0x94, 0xC0, 0x28, 0x00, 0x06, 0x07, 0x6A, 0x00, 0xCB, 0xA6, 0xC8, 0x00, + 0x00, 0x47, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x80, 0x00, 0x00, 0x39, 0x14, + 0x20, 0x02, 0x22, 0x24, 0x00, 0x08, 0xAE, 0xA8, 0x60, 0x04, 0x28, 0x99, 0x70, 0x07, 0x75, 0xD1, 0x04, 0x0F, 0xB3, + 0x33, 0xD0, 0x00, 0xAE, 0xBE, 0xA4, 0x25, 0x15, 0x20, 0xA0, 0x02, 0x61, 0x0C, 0x02, 0x20, 0x42, 0x08, 0x20, 0x2C, + 0x30, 0x14, 0x02, 0x02, 0x28, 0x82, 0x00, 0x03, 0xAC, 0xC1, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x12, 0x00, 0x08, 0x00, 0x28, 0x00, 0x0A, 0xCF, 0xEE, 0x20, 0x0B, 0x62, 0x2E, 0x20, 0x02, 0x10, 0x82, + 0x40, 0x01, 0x44, 0xE4, 0x40, 0x03, 0x00, 0x0E, 0x00, 0x8D, 0xEA, 0xAC, 0x00, 0x02, 0x10, 0x0A, 0x00, 0x01, 0xE0, + 0x24, 0x00, 0x0C, 0x21, 0x02, 0x00, 0x09, 0x42, 0x21, 0x00, 0x00, 0xCC, 0xF4, 0x40, 0x02, 0xBF, 0xD4, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x0C, 0xCC, 0xC4, 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x00, 0x02, 0xA0, + 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x04, 0xCE, 0x64, 0x40, 0x02, 0x08, 0x80, 0x00, 0x00, 0x90, 0x00, 0x40, 0x28, 0xA8, + 0x80, 0x00, 0x08, 0x01, 0x04, 0x00, 0x0A, 0x88, 0x80, 0x00, 0x04, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x54, 0x44, 0x00, + 0xEE, 0xFE, 0xE0, 0x00, 0x09, 0x3B, 0x3F, 0x00, 0x21, 0xD8, 0x20, 0x00, 0x00, 0x54, 0x4F, 0x00, 0x18, 0x58, 0x20, + 0x00, 0x00, 0x01, 0x86, 0x00, 0xC6, 0x7E, 0x40, 0x00, 0x00, 0xEF, 0x66, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0xC0, 0x20, 0x00, 0xAA, 0xAA, 0xEA, 0x20, 0xEF, 0xFF, 0xFF, 0x00, 0x80, + 0x44, 0x19, 0x30, 0x00, 0x49, 0x24, 0x00, 0xC5, 0x35, 0x1B, 0x10, 0x00, 0x4B, 0x24, 0x00, 0x01, 0x35, 0xA0, 0x00, + 0x8C, 0xA9, 0xAC, 0x80, 0x00, 0x2C, 0x00, 0x00, 0x04, 0x21, 0xA4, 0x00, 0x2A, 0x84, 0x00, 0x00, 0x73, 0x11, 0xF1, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x11, 0x19, 0x00, 0x00, 0x40, 0x00, 0x00, 0x8F, 0xEE, + 0xEF, 0xE0, 0x0B, 0x76, 0x66, 0xD0, 0x1A, 0x00, 0x0B, 0x40, 0x4C, 0x40, 0x02, 0xD0, 0x28, 0x00, 0x1A, 0x40, 0x01, + 0xD0, 0x2C, 0x10, 0x00, 0x00, 0x38, 0x40, 0x00, 0x40, 0x28, 0x10, 0x00, 0x01, 0xA0, 0x40, 0x00, 0x42, 0x83, 0x00, + 0x05, 0xFE, 0x44, 0x40, 0x03, 0xFD, 0x54, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x99, 0x9B, + 0x00, 0x00, 0x10, 0x20, 0x00, 0x07, 0x26, 0x21, 0x40, 0x2A, 0xFE, 0xEE, 0xA0, 0x8D, 0x8C, 0xA9, 0xC0, 0x00, 0x10, + 0x20, 0x80, 0x32, 0x33, 0xB3, 0x60, 0x00, 0x19, 0x28, 0x00, 0x00, 0x00, 0xA1, 0x40, 0x00, 0x10, 0xB1, 0x00, 0x00, + 0x08, 0x34, 0x00, 0x00, 0x1A, 0x08, 0x00, 0x05, 0xF7, 0x40, 0x00, 0x8E, 0xF4, 0x44, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x02, 0x80, 0x00, 0x04, 0x00, 0x00, 0x1D, 0x11, 0xDB, 0x00, 0xDD, 0xFD, 0xDD, + 0xD0, 0x0C, 0x88, 0x07, 0x00, 0x02, 0x06, 0x00, 0x90, 0x48, 0x00, 0x34, 0x00, 0x2C, 0x04, 0x2C, 0x10, 0x48, 0x11, + 0x21, 0x40, 0x04, 0x84, 0x83, 0x40, 0x59, 0x03, 0x00, 0x50, 0x40, 0x0C, 0x10, 0x60, 0x42, 0xA9, 0x88, 0xC0, 0x40, + 0x15, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x40, 0x08, 0x98, 0x88, 0x80, + 0x08, 0xF9, 0x98, 0xC0, 0x06, 0x77, 0x75, 0x50, 0x02, 0x0C, 0x05, 0x00, 0x19, 0x98, 0xA8, 0xD0, 0x0B, 0x99, 0xCA, + 0x80, 0x04, 0x54, 0x65, 0xC0, 0x20, 0x08, 0x50, 0x20, 0x00, 0x10, 0x20, 0xC0, 0x31, 0x1C, 0x04, 0x20, 0x00, 0x01, + 0x28, 0x40, 0x26, 0x63, 0xBB, 0xE0, 0x26, 0xEF, 0xE6, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x01, 0x00, 0xC8, 0xC0, 0x00, 0x00, 0x0F, 0x8A, 0x89, 0x80, 0xC3, 0xF3, 0x11, 0x30, 0x0F, 0x02, 0x01, 0x80, + 0xC9, 0xC0, 0x00, 0x30, 0x0F, 0x02, 0x05, 0xA0, 0x00, 0x00, 0x00, 0x30, 0x0E, 0x02, 0x05, 0xA0, 0x00, 0x00, 0x00, + 0x30, 0x0E, 0x02, 0x52, 0x80, 0x00, 0x00, 0x03, 0x00, 0x2C, 0xDF, 0xA8, 0x80, 0x02, 0x33, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x88, 0x00, 0x01, 0x02, 0x80, 0x00, 0x03, 0xFF, 0xF7, 0x00, 0x0F, + 0x26, 0xE4, 0x72, 0xCC, 0x38, 0x00, 0x40, 0x0C, 0x38, 0x99, 0x00, 0x03, 0x0A, 0x31, 0x50, 0x0C, 0xB1, 0x82, 0x80, + 0x03, 0x28, 0x06, 0x00, 0x87, 0x88, 0x2A, 0xA0, 0x01, 0x05, 0xC2, 0x00, 0x85, 0x82, 0xC2, 0x80, 0x10, 0x00, 0x39, + 0x10, 0x08, 0x51, 0xBF, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x48, 0x9D, + 0xCC, 0x40, 0xC9, 0xE6, 0x7F, 0x40, 0x40, 0x00, 0x94, 0x00, 0x5B, 0x21, 0x0C, 0xB0, 0x48, 0xAE, 0xCC, 0x40, 0xE1, + 0x30, 0x0C, 0x30, 0x43, 0x01, 0xA4, 0x00, 0xE1, 0x24, 0x5D, 0x30, 0x78, 0x8C, 0xD6, 0x10, 0xF1, 0x60, 0x94, 0x70, + 0xD0, 0x40, 0x9C, 0x70, 0x0B, 0x8C, 0x53, 0x00, 0x0C, 0x9D, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x39, 0x50, 0x00, 0x00, 0x88, 0xF0, 0x00, 0x2E, 0xAF, 0xC6, 0x00, 0x03, 0x01, 0x77, 0x60, 0x04, 0xF0, + 0x41, 0x60, 0x03, 0x92, 0xF8, 0x12, 0x0F, 0xBD, 0x91, 0x40, 0x1B, 0x28, 0x60, 0x92, 0x70, 0xF4, 0x01, 0xF0, 0x0A, + 0xD4, 0x65, 0x82, 0x53, 0xE0, 0x01, 0xE0, 0x04, 0x10, 0x68, 0x60, 0x04, 0x2A, 0xBE, 0x00, 0x00, 0x4F, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3A, 0xEE, 0x00, 0xC8, 0xC0, 0x00, 0x00, 0x0D, 0x84, 0xA5, + 0x00, 0xC1, 0xC2, 0x11, 0x00, 0x45, 0x0E, 0x27, 0x00, 0xD9, 0xC3, 0x00, 0x10, 0x07, 0xF8, 0x8D, 0x20, 0x01, 0x30, + 0x00, 0x10, 0xAC, 0x02, 0x25, 0xA0, 0x01, 0x22, 0x00, 0x10, 0x44, 0x20, 0x16, 0xA0, 0x13, 0x02, 0x00, 0x30, 0x04, + 0x1B, 0xAA, 0x40, 0x21, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; void GfxPrint_Setup(GfxPrint* this) { s32 width = 16; @@ -36,10 +156,11 @@ void GfxPrint_Setup(GfxPrint* this) { gDPSetColor(this->dList++, G_SETPRIMCOLOR, this->color.rgba); - gDPLoadMultiTile_4b(this->dList++, sGfxPrintRainbowData, 0, 1, G_IM_FMT_CI, 2, 8, 0, 0, 1, 7, 4, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 1, 3, G_TX_NOLOD, G_TX_NOLOD); + // BENTODO: CRASH + // gDPLoadMultiTile_4b(this->dList++, sGfxPrintRainbowData, 0, 1, G_IM_FMT_CI, 2, 8, 0, 0, 1, 7, 4, + // G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 1, 3, G_TX_NOLOD, G_TX_NOLOD); - gDPLoadTLUT(this->dList++, 16, 320, sGfxPrintRainbowTLUT); + // gDPLoadTLUT(this->dList++, 16, 320, sGfxPrintRainbowTLUT); for (i = 1; i < 4; i++) { gDPSetTile(this->dList++, G_IM_FMT_CI, G_IM_SIZ_4b, 1, 0, i * 2 + 1, 4, G_TX_NOMIRROR | G_TX_WRAP, 3, @@ -80,7 +201,8 @@ void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c) { this->flags &= ~GFXP_FLAG_UPDATE; gDPPipeSync(this->dList++); - if (this->flags & GFXP_FLAG_RAINBOW) { + // BENTODO: CRASH HERE + if (this->flags & GFXP_FLAG_RAINBOW && false) { gDPSetTextureLUT(this->dList++, G_TT_RGBA16); gDPSetCycleType(this->dList++, G_CYC_2CYCLE); gDPSetRenderMode(this->dList++, G_RM_PASS, G_RM_XLU_SURF2); @@ -143,12 +265,14 @@ void GfxPrint_PrintChar(GfxPrint* this, u8 c) { this->flags &= ~GFXP_FLAG_HIRAGANA; break; case GFXP_RAINBOW_ON_CHAR: - this->flags |= GFXP_FLAG_RAINBOW; - this->flags |= GFXP_FLAG_UPDATE; + // BENTODO: CRASH + // this->flags |= GFXP_FLAG_RAINBOW; + // this->flags |= GFXP_FLAG_UPDATE; break; case GFXP_RAINBOW_OFF_CHAR: - this->flags &= ~GFXP_FLAG_RAINBOW; - this->flags |= GFXP_FLAG_UPDATE; + // BENTODO: CRASH + // this->flags &= ~GFXP_FLAG_RAINBOW; + // this->flags |= GFXP_FLAG_UPDATE; break; case GFXP_UNUSED_CHAR: default: diff --git a/mm/src/boot/O2/loadfragment2.c b/mm/src/boot/O2/loadfragment2.c index 02b3ab218..86c459f9c 100644 --- a/mm/src/boot/O2/loadfragment2.c +++ b/mm/src/boot/O2/loadfragment2.c @@ -132,6 +132,8 @@ void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlReloc } size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* ramStart, void* ramEnd, void* allocatedRamAddr) { + return 0; + #if 0 uintptr_t vramStart = (uintptr_t)ramStart; uintptr_t vramEnd = (uintptr_t)ramEnd; s32 size = vromEnd - vromStart; @@ -164,6 +166,7 @@ size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* ramStart, void if (gOverlayLogSeverity >= 3) {} return size; + #endif } void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd) { diff --git a/mm/src/boot/O2/padsetup.c b/mm/src/boot/O2/padsetup.c index 9cef6f196..8a20456f6 100644 --- a/mm/src/boot/O2/padsetup.c +++ b/mm/src/boot/O2/padsetup.c @@ -19,7 +19,7 @@ s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status) { *outMask = 0; for (i = 0; i < MAXCONTROLLERS; i++) { - switch (status[i].errno) { + switch (status[i].err_no) { case 0: if (status[i].type == CONT_TYPE_NORMAL) { *outMask |= 1 << i; diff --git a/mm/src/boot/O2/padutils.c b/mm/src/boot/O2/padutils.c index 1c6bbe868..b56c01a24 100644 --- a/mm/src/boot/O2/padutils.c +++ b/mm/src/boot/O2/padutils.c @@ -1,4 +1,5 @@ #include "padutils.h" +#include void PadUtils_Init(Input* input) { bzero(input, sizeof(Input)); diff --git a/mm/src/boot/O2/printutils.c b/mm/src/boot/O2/printutils.c index 3fb8cf367..82e16f4dd 100644 --- a/mm/src/boot/O2/printutils.c +++ b/mm/src/boot/O2/printutils.c @@ -1,4 +1,12 @@ #include "global.h" +#include "stdio.h" + +s32 _Printf(PrintCallback a, void* arg, const char* fmt, va_list ap) { + unsigned char buffer[4096]; + + vsnprintf(buffer, sizeof(buffer), fmt, ap); + a(arg, buffer, strlen(buffer)); +} s32 PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args) { return _Printf(*pfn, pfn, fmt, args); @@ -14,4 +22,4 @@ s32 PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...) { va_end(args); return ret; -} +} \ No newline at end of file diff --git a/mm/src/boot/O2/rcp_utils.c b/mm/src/boot/O2/rcp_utils.c index f587fad21..4c16efb86 100644 --- a/mm/src/boot/O2/rcp_utils.c +++ b/mm/src/boot/O2/rcp_utils.c @@ -1,23 +1,23 @@ #include "ultra64.h" void RcpUtils_PrintRegisterStatus(void) { - u32 spStatus = __osSpGetStatus(); - u32 dpStatus = osDpGetStatus(); - - if (spStatus) { - // stubbed debug prints - } - - if (dpStatus) { - // stubbed debug prints - } + //u32 spStatus = __osSpGetStatus(); + //u32 dpStatus = osDpGetStatus(); + // + //if (spStatus) { + // // stubbed debug prints + //} + // + //if (dpStatus) { + // // stubbed debug prints + //} } void RcpUtils_Reset(void) { - RcpUtils_PrintRegisterStatus(); - // Flush the RDP pipeline and freeze clock counter - osDpSetStatus(DPC_SET_FREEZE | DPC_SET_FLUSH); - // Halt the RSP, disable interrupt on break and set "task done" signal - __osSpSetStatus(SP_SET_HALT | SP_SET_TASKDONE | SP_CLR_INTR_BREAK); - RcpUtils_PrintRegisterStatus(); + //RcpUtils_PrintRegisterStatus(); + //// Flush the RDP pipeline and freeze clock counter + //osDpSetStatus(DPC_SET_FREEZE | DPC_SET_FLUSH); + //// Halt the RSP, disable interrupt on break and set "task done" signal + //__osSpSetStatus(SP_SET_HALT | SP_SET_TASKDONE | SP_CLR_INTR_BREAK); + //RcpUtils_PrintRegisterStatus(); } diff --git a/mm/src/boot/O2/sleep.c b/mm/src/boot/O2/sleep.c index a35abc5b2..baa2d3d83 100644 --- a/mm/src/boot/O2/sleep.c +++ b/mm/src/boot/O2/sleep.c @@ -1,27 +1,27 @@ #include "global.h" void Sleep_Cycles(u64 time) { - OSMesgQueue mq; - OSMesg msg[1]; - OSTimer timer; + //OSMesgQueue mq; + //OSMesg msg[1]; + //OSTimer timer; - osCreateMesgQueue(&mq, msg, ARRAY_COUNT(msg)); - osSetTimer(&timer, time, 0, &mq, NULL); - osRecvMesg(&mq, NULL, OS_MESG_BLOCK); + //osCreateMesgQueue(&mq, msg, ARRAY_COUNT(msg)); + //osSetTimer(&timer, time, 0, &mq, NULL); + //osRecvMesg(&mq, NULL, OS_MESG_BLOCK); } void Sleep_Nsec(u32 nsec) { - Sleep_Cycles(OS_NSEC_TO_CYCLES(nsec)); + //Sleep_Cycles(OS_NSEC_TO_CYCLES(nsec)); } void Sleep_Usec(u32 usec) { - Sleep_Cycles(OS_USEC_TO_CYCLES(usec)); + //Sleep_Cycles(OS_USEC_TO_CYCLES(usec)); } void Sleep_Msec(u32 ms) { - Sleep_Cycles((ms * OS_CPU_COUNTER) / 1000ULL); + //Sleep_Cycles((ms * OS_CPU_COUNTER) / 1000ULL); } void Sleep_Sec(u32 sec) { - Sleep_Cycles(sec * OS_CPU_COUNTER); + //Sleep_Cycles(sec * OS_CPU_COUNTER); } diff --git a/mm/src/boot/O2/sprintf.c b/mm/src/boot/O2/sprintf.c index 773b982ff..bcb2a4384 100644 --- a/mm/src/boot/O2/sprintf.c +++ b/mm/src/boot/O2/sprintf.c @@ -1,7 +1,9 @@ #include "ultra64.h" #include "libc/stdlib.h" #include "libc/string.h" +#include +#if 0 void* proutSprintf(void* dst, const char* fmt, size_t size) { return (void*)((uintptr_t)memcpy(dst, fmt, size) + size); } @@ -28,3 +30,4 @@ int sprintf(char* dst, const char* fmt, ...) { return ans; } +#endif diff --git a/mm/src/boot/boot_main.c b/mm/src/boot/boot_main.c index 0f95871ea..a47eea560 100644 --- a/mm/src/boot/boot_main.c +++ b/mm/src/boot/boot_main.c @@ -1,3 +1,4 @@ +#if 0 #include "prevent_bss_reordering.h" #include "carthandle.h" #include "idle.h" @@ -23,3 +24,4 @@ void bootproc(void) { osCreateThread(&sIdleThread, Z_THREAD_ID_IDLE, Idle_ThreadEntry, NULL, STACK_TOP(sIdleStack), Z_PRIORITY_IDLE); osStartThread(&sIdleThread); } +#endif \ No newline at end of file diff --git a/mm/src/boot/build.c.in b/mm/src/boot/build.c.in new file mode 100644 index 000000000..e69de29bb diff --git a/mm/src/boot/fault.c b/mm/src/boot/fault.c index 0ee4faed7..2244a8ce1 100644 --- a/mm/src/boot/fault.c +++ b/mm/src/boot/fault.c @@ -51,7 +51,7 @@ #include "main.h" #include "macros.h" #include "global.h" - +#if 0 FaultMgr* sFaultInstance; f32 sFaultTimeTotal; // read but not set anywhere @@ -80,11 +80,12 @@ const char* sCpuExceptions[] = { const char* sFpuExceptions[] = { "Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", "Inexact operation", }; - +#endif +#include void Fault_SleepImpl(u32 duration) { - OSTime value = (duration * OS_CPU_COUNTER) / 1000ULL; + //OSTime value = (duration * OS_CPU_COUNTER) / 1000ULL; - Sleep_Cycles(value); + //Sleep_Cycles(value); } /** @@ -94,6 +95,7 @@ void Fault_SleepImpl(u32 duration) { * Arguments are passed on to the callback through `arg0` and `arg1`. */ void Fault_AddClient(FaultClient* client, FaultClientCallback callback, void* arg0, void* arg1) { + #if 0 OSIntMask mask; u32 alreadyExists = false; @@ -124,12 +126,14 @@ end: if (alreadyExists) { osSyncPrintf(VT_COL(RED, WHITE) "fault_AddClient: %08x は既にリスト中にある\n" VT_RST, client); } + #endif } /** * Removes a fault client so that the page is no longer displayed if a crash occurs. */ void Fault_RemoveClient(FaultClient* client) { + #if 0 FaultClient* iter = sFaultInstance->clients; FaultClient* lastIter = NULL; OSIntMask mask; @@ -161,6 +165,7 @@ void Fault_RemoveClient(FaultClient* client) { if (listIsEmpty) { osSyncPrintf(VT_COL(RED, WHITE) "fault_RemoveClient: %08x リスト不整合です\n" VT_RST, client); } + #endif } /** @@ -174,6 +179,7 @@ void Fault_RemoveClient(FaultClient* client) { * The callback may return 0 if it could not convert the address */ void Fault_AddAddrConvClient(FaultAddrConvClient* client, FaultAddrConvClientCallback callback, void* arg) { + #if 0 OSIntMask mask; s32 alreadyExists = false; @@ -202,9 +208,11 @@ end: if (alreadyExists) { osSyncPrintf(VT_COL(RED, WHITE) "fault_AddressConverterAddClient: %08x は既にリスト中にある\n" VT_RST, client); } + #endif } void Fault_RemoveAddrConvClient(FaultAddrConvClient* client) { + #if 0 FaultAddrConvClient* iter = sFaultInstance->addrConvClients; FaultAddrConvClient* lastIter = NULL; OSIntMask mask; @@ -237,6 +245,7 @@ void Fault_RemoveAddrConvClient(FaultAddrConvClient* client) { osSyncPrintf(VT_COL(RED, WHITE) "fault_AddressConverterRemoveClient: %08x は既にリスト中にある\n" VT_RST, client); } + #endif } /** @@ -244,6 +253,7 @@ void Fault_RemoveAddrConvClient(FaultAddrConvClient* client) { * address converter clients */ uintptr_t Fault_ConvertAddress(uintptr_t addr) { + #if 0 uintptr_t ret; FaultAddrConvClient* iter = sFaultInstance->addrConvClients; @@ -258,18 +268,19 @@ uintptr_t Fault_ConvertAddress(uintptr_t addr) { } return 0; + #endif } void Fault_Sleep(u32 msec) { - Fault_SleepImpl(msec); + //Fault_SleepImpl(msec); } void Fault_PadCallback(Input* input) { - PadMgr_GetInput2(input, false); + //PadMgr_GetInput2(input, false); } void Fault_UpdatePadImpl(void) { - sFaultInstance->padCallback(sFaultInstance->inputs); + //sFaultInstance->padCallback(sFaultInstance->inputs); } /** @@ -282,6 +293,7 @@ void Fault_UpdatePadImpl(void) { * DPad-Left continues and returns false */ u32 Fault_WaitForInputImpl(void) { + #if 0 Input* input = &sFaultInstance->inputs[0]; s32 count = 600; u32 pressedBtn; @@ -318,35 +330,37 @@ u32 Fault_WaitForInputImpl(void) { } } } + #endif } void Fault_WaitForInput(void) { - Fault_WaitForInputImpl(); + //Fault_WaitForInputImpl(); } void Fault_DrawRec(s32 x, s32 y, s32 w, s32 h, u16 color) { - FaultDrawer_DrawRecImpl(x, y, x + w - 1, y + h - 1, color); + //FaultDrawer_DrawRecImpl(x, y, x + w - 1, y + h - 1, color); } void Fault_FillScreenBlack(void) { - FaultDrawer_SetForeColor(GPACK_RGBA5551(255, 255, 255, 1)); - FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 1)); - FaultDrawer_FillScreen(); - FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 0)); + //FaultDrawer_SetForeColor(GPACK_RGBA5551(255, 255, 255, 1)); + //FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 1)); + //FaultDrawer_FillScreen(); + //FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 0)); } void Fault_FillScreenRed(void) { - FaultDrawer_SetForeColor(GPACK_RGBA5551(255, 255, 255, 1)); - FaultDrawer_SetBackColor(GPACK_RGBA5551(240, 0, 0, 1)); - FaultDrawer_FillScreen(); - FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 0)); + //FaultDrawer_SetForeColor(GPACK_RGBA5551(255, 255, 255, 1)); + //FaultDrawer_SetBackColor(GPACK_RGBA5551(240, 0, 0, 1)); + //FaultDrawer_FillScreen(); + //FaultDrawer_SetBackColor(GPACK_RGBA5551(0, 0, 0, 0)); } void Fault_DrawCornerRec(u16 color) { - Fault_DrawRec(22, 16, 8, 1, color); + //Fault_DrawRec(22, 16, 8, 1, color); } void Fault_PrintFReg(s32 index, f32* value) { + #if 0 u32 raw = *(u32*)value; s32 v0 = ((raw & 0x7F800000) >> 0x17) - 0x7F; @@ -356,9 +370,11 @@ void Fault_PrintFReg(s32 index, f32* value) { // Print subnormal floats as their IEEE-754 hex representation FaultDrawer_Printf("F%02d: %08x(16) ", index, raw); } + #endif } void Fault_LogFReg(s32 idx, f32* value) { + #if 0 u32 raw = *(u32*)value; s32 v0 = ((raw & 0x7F800000) >> 0x17) - 0x7F; @@ -367,9 +383,11 @@ void Fault_LogFReg(s32 idx, f32* value) { } else { osSyncPrintf("F%02d: %08x(16) ", idx, *(u32*)value); } + #endif } void Fault_PrintFPCR(u32 value) { + #if 0 s32 i; u32 flag = 0x20000; @@ -385,9 +403,11 @@ void Fault_PrintFPCR(u32 value) { flag >>= 1; } FaultDrawer_Printf("\n"); + #endif } void Fault_LogFPCSR(u32 value) { + #if 0 s32 i; u32 flag = 0x20000; @@ -399,9 +419,11 @@ void Fault_LogFPCSR(u32 value) { } flag >>= 1; } + #endif } void Fault_PrintThreadContext(OSThread* thread) { + #if 0 __OSThreadContext* threadCtx; s16 causeStrIdx = _SHIFTR((u32)thread->context.cause, 2, 5); @@ -464,9 +486,11 @@ void Fault_PrintThreadContext(OSThread* thread) { if (sFaultTimeTotal != 0.0f) { FaultDrawer_DrawText(160, 216, "%5.2f sec\n", sFaultTimeTotal); } + #endif } void osSyncPrintfThreadContext(OSThread* thread) { + #if 0 __OSThreadContext* threadCtx; s16 causeStrIdx = _SHIFTR((u32)thread->context.cause, 2, 5); @@ -519,6 +543,7 @@ void osSyncPrintfThreadContext(OSThread* thread) { Fault_LogFReg(28, &threadCtx->fp28.f.f_even); Fault_LogFReg(30, &threadCtx->fp30.f.f_even); osSyncPrintf("\n"); + #endif } /** @@ -526,6 +551,7 @@ void osSyncPrintfThreadContext(OSThread* thread) { * the CPU break or Fault flag set. */ OSThread* Fault_FindFaultedThread(void) { + #if 0 OSThread* iter = __osGetActiveQueue(); while (iter->priority != OS_PRIORITY_THREADTAIL) { @@ -537,8 +563,10 @@ OSThread* Fault_FindFaultedThread(void) { } return NULL; + #endif } void Fault_Wait5Seconds(void) { + #if 0 s32 pad; OSTime start = osGetTime(); @@ -547,6 +575,7 @@ void Fault_Wait5Seconds(void) { } while ((osGetTime() - start) <= OS_SEC_TO_CYCLES(5)); sFaultInstance->autoScroll = true; + #endif } /** @@ -555,6 +584,7 @@ void Fault_Wait5Seconds(void) { * (DPad-Left & L & R & C-Right) & Start */ void Fault_WaitForButtonCombo(void) { + #if 0 Input* input = &sFaultInstance->inputs[0]; FaultDrawer_SetForeColor(GPACK_RGBA5551(255, 255, 255, 1)); @@ -566,9 +596,11 @@ void Fault_WaitForButtonCombo(void) { Fault_UpdatePadImpl(); } while (!CHECK_BTN_ALL(input->press.button, BTN_RESET)); } while (!CHECK_BTN_ALL(input->cur.button, BTN_DLEFT | BTN_L | BTN_R | BTN_CRIGHT)); + #endif } void Fault_DrawMemDumpContents(const char* title, uintptr_t addr, u32 param_3) { + #if 0 uintptr_t alignedAddr = addr; u32* writeAddr; s32 y; @@ -605,6 +637,7 @@ void Fault_DrawMemDumpContents(const char* title, uintptr_t addr, u32 param_3) { } FaultDrawer_SetCharPad(0, 0); + #endif } /** @@ -624,6 +657,7 @@ void Fault_DrawMemDumpContents(const char* title, uintptr_t addr, u32 param_3) { * @param cRightJump Unused parameter, pressing C-Right jumps to this address */ void Fault_DrawMemDump(uintptr_t pc, uintptr_t sp, uintptr_t cLeftJump, uintptr_t cRightJump) { + #if 0 s32 scrollCountdown; s32 off; Input* input = &sFaultInstance->inputs[0]; @@ -704,6 +738,7 @@ void Fault_DrawMemDump(uintptr_t pc, uintptr_t sp, uintptr_t cLeftJump, uintptr_ // Resume auto-scroll and move to next page sFaultInstance->autoScroll = true; + #endif } /** @@ -742,6 +777,7 @@ void Fault_DrawMemDump(uintptr_t pc, uintptr_t sp, uintptr_t cLeftJump, uintptr_ * and the backtrace may continue as normal. */ void Fault_WalkStack(uintptr_t* spPtr, uintptr_t* pcPtr, uintptr_t* raPtr) { + #if 0 uintptr_t sp = *spPtr; uintptr_t pc = *pcPtr; uintptr_t ra = *raPtr; @@ -804,12 +840,14 @@ done: *spPtr = sp; *pcPtr = pc; *raPtr = ra; + #endif } /** * Draws the stack trace page contents for the specified thread */ void Fault_DrawStackTrace(OSThread* thread, u32 flags) { + #if 0 s32 line; uintptr_t sp = thread->context.sp; uintptr_t ra = thread->context.ra; @@ -836,9 +874,11 @@ void Fault_DrawStackTrace(OSThread* thread, u32 flags) { Fault_WalkStack(&sp, &pc, &ra); } + #endif } void Fault_LogStackTrace(OSThread* thread, u32 flags) { + #if 0 s32 line; uintptr_t sp = thread->context.sp; uintptr_t ra = thread->context.ra; @@ -864,9 +904,11 @@ void Fault_LogStackTrace(OSThread* thread, u32 flags) { Fault_WalkStack(&sp, &pc, &ra); } + #endif } void Fault_ResumeThread(OSThread* thread) { + #if 0 thread->context.cause = 0; thread->context.fpcsr = 0; thread->context.pc += sizeof(u32); @@ -874,9 +916,11 @@ void Fault_ResumeThread(OSThread* thread) { osWritebackDCache((void*)thread->context.pc, 4); osInvalICache((void*)thread->context.pc, 4); osStartThread(thread); + #endif } void Fault_DisplayFrameBuffer(void) { + #if 0 void* fb; osViSetYScale(1.0f); @@ -895,6 +939,7 @@ void Fault_DisplayFrameBuffer(void) { osViSwapBuffer(fb); FaultDrawer_SetDrawerFrameBuffer(fb, SCREEN_WIDTH, SCREEN_HEIGHT); + #endif } /** @@ -902,6 +947,7 @@ void Fault_DisplayFrameBuffer(void) { * on the crash screen. */ void Fault_ProcessClients(void) { + #if 0 FaultClient* client = sFaultInstance->clients; s32 idx = 0; @@ -918,9 +964,11 @@ void Fault_ProcessClients(void) { } client = client->next; } + #endif } void Fault_SetOptionsFromController3(void) { + #if 0 static u32 faultCustomOptions; Input* input3 = &sFaultInstance->inputs[3]; u32 pad; @@ -953,18 +1001,20 @@ void Fault_SetOptionsFromController3(void) { FaultDrawer_DrawText(0x20, 0xD8, "GRAPH PC %08x RA %08x SP %08x", pc, ra, sp); } } + #endif } void Fault_UpdatePad(void) { - Fault_UpdatePadImpl(); - Fault_SetOptionsFromController3(); + //Fault_UpdatePadImpl(); + //Fault_SetOptionsFromController3(); } -#define FAULT_MSG_CPU_BREAK ((OSMesg)1) -#define FAULT_MSG_FAULT ((OSMesg)2) -#define FAULT_MSG_UNK ((OSMesg)3) +//#define FAULT_MSG_CPU_BREAK ((OSMesg)1) +//#define FAULT_MSG_FAULT ((OSMesg)2) +//#define FAULT_MSG_UNK ((OSMesg)3) void Fault_ThreadEntry(void* arg) { + #if 0 OSMesg msg; u32 pad; OSThread* faultedThread; @@ -1063,18 +1113,20 @@ void Fault_ThreadEntry(void* arg) { Fault_ResumeThread(faultedThread); } + #endif } void Fault_SetFrameBuffer(void* fb, u16 w, u16 h) { - sFaultInstance->fb = fb; - FaultDrawer_SetDrawerFrameBuffer(fb, w, h); + //sFaultInstance->fb = fb; + //FaultDrawer_SetDrawerFrameBuffer(fb, w, h); } -STACK(sFaultStack, 0x600); -StackEntry sFaultStackInfo; -FaultMgr gFaultMgr; +//STACK(sFaultStack, 0x600); +//StackEntry sFaultStackInfo; +//FaultMgr gFaultMgr; void Fault_Init(void) { + #if 0 sFaultInstance = &gFaultMgr; bzero(sFaultInstance, sizeof(FaultMgr)); FaultDrawer_Init(); @@ -1092,6 +1144,7 @@ void Fault_Init(void) { osCreateThread(&sFaultInstance->thread, Z_THREAD_ID_FAULT, Fault_ThreadEntry, NULL, STACK_TOP(sFaultStack), Z_PRIORITY_FAULT); osStartThread(&sFaultInstance->thread); + #endif } /** @@ -1099,12 +1152,14 @@ void Fault_Init(void) { * specified in arguments to `Fault_AddHungupAndCrashImpl`. */ void Fault_HangupFaultClient(const char* exp1, const char* exp2) { + #if 0 osSyncPrintf("HungUp on Thread %d\n", osGetThreadId(NULL)); osSyncPrintf("%s\n", exp1 != NULL ? exp1 : "(NULL)"); osSyncPrintf("%s\n", exp2 != NULL ? exp2 : "(NULL)"); FaultDrawer_Printf("HungUp on Thread %d\n", osGetThreadId(NULL)); FaultDrawer_Printf("%s\n", exp1 != NULL ? exp1 : "(NULL)"); FaultDrawer_Printf("%s\n", exp2 != NULL ? exp2 : "(NULL)"); + #endif } /** @@ -1113,11 +1168,12 @@ void Fault_HangupFaultClient(const char* exp1, const char* exp2) { * or both may be NULL. */ void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2) { - FaultClient client; - s32 pad; - - Fault_AddClient(&client, (void*)Fault_HangupFaultClient, (void*)exp1, (void*)exp2); - *(u32*)0x11111111 = 0; // trigger an exception via unaligned memory access + assert(0); + //FaultClient client; + //s32 pad; + // + //Fault_AddClient(&client, (void*)Fault_HangupFaultClient, (void*)exp1, (void*)exp2); + //*(u32*)0x11111111 = 0; // trigger an exception via unaligned memory access } /** diff --git a/mm/src/boot/fault_drawer.c b/mm/src/boot/fault_drawer.c index 6031ccaa6..ed653a09d 100644 --- a/mm/src/boot/fault_drawer.c +++ b/mm/src/boot/fault_drawer.c @@ -32,7 +32,7 @@ typedef struct { /* 0x35 */ u8 osSyncPrintfEnabled; /* 0x38 */ FaultDrawerCallback inputCallback; } FaultDrawer; // size = 0x3C - +#if 0 extern const u32 sFaultDrawerFont[]; FaultDrawer sFaultDrawer; @@ -76,15 +76,16 @@ FaultDrawer sFaultDrawerDefault = { false, // osSyncPrintfEnabled NULL, // inputCallback }; - +#endif //! TODO: Needs to be extracted -#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/sFaultDrawerFont.s") +//#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/sFaultDrawerFont.s") void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) { - sFaultDrawerInstance->osSyncPrintfEnabled = enabled; + //sFaultDrawerInstance->osSyncPrintfEnabled = enabled; } void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color) { + #if 0 u16* frameBuffer; s32 x; s32 y; @@ -112,9 +113,11 @@ void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 col osWritebackDCacheAll(); } + #endif } void FaultDrawer_DrawChar(char c) { + #if 0 s32 x; s32 y; u32 data; @@ -144,9 +147,12 @@ void FaultDrawer_DrawChar(char c) { dataPtr += 2; } } + #endif } s32 FaultDrawer_ColorToPrintColor(u16 color) { + return 0; +#if 0 s32 i; for (i = 0; i < ARRAY_COUNT(sFaultDrawerInstance->printColors); i++) { @@ -155,9 +161,11 @@ s32 FaultDrawer_ColorToPrintColor(u16 color) { } } return -1; + #endif } void FaultDrawer_UpdatePrintColor(void) { + #if 0 s32 index; if (sFaultDrawerInstance->osSyncPrintfEnabled) { @@ -173,49 +181,51 @@ void FaultDrawer_UpdatePrintColor(void) { osSyncPrintf(VT_SGR("4%d"), index); } } + #endif } void FaultDrawer_SetForeColor(u16 color) { - sFaultDrawerInstance->foreColor = color; - FaultDrawer_UpdatePrintColor(); + //sFaultDrawerInstance->foreColor = color; + //FaultDrawer_UpdatePrintColor(); } void FaultDrawer_SetBackColor(u16 color) { - sFaultDrawerInstance->backColor = color; - FaultDrawer_UpdatePrintColor(); + //sFaultDrawerInstance->backColor = color; + //FaultDrawer_UpdatePrintColor(); } void FaultDrawer_SetFontColor(u16 color) { - FaultDrawer_SetForeColor(color | 1); // force alpha to be set + //FaultDrawer_SetForeColor(color | 1); // force alpha to be set } void FaultDrawer_SetCharPad(s8 padW, s8 padH) { - sFaultDrawerInstance->charWPad = padW; - sFaultDrawerInstance->charHPad = padH; + //sFaultDrawerInstance->charWPad = padW; + //sFaultDrawerInstance->charHPad = padH; } void FaultDrawer_SetCursor(s32 x, s32 y) { - if (sFaultDrawerInstance->osSyncPrintfEnabled) { - osSyncPrintf( - VT_CUP("%d", "%d"), - (y - sFaultDrawerInstance->yStart) / (sFaultDrawerInstance->charH + sFaultDrawerInstance->charHPad), - (x - sFaultDrawerInstance->xStart) / (sFaultDrawerInstance->charW + sFaultDrawerInstance->charWPad)); - } - sFaultDrawerInstance->cursorX = x; - sFaultDrawerInstance->cursorY = y; + //if (sFaultDrawerInstance->osSyncPrintfEnabled) { + // osSyncPrintf( + // VT_CUP("%d", "%d"), + // (y - sFaultDrawerInstance->yStart) / (sFaultDrawerInstance->charH + sFaultDrawerInstance->charHPad), + // (x - sFaultDrawerInstance->xStart) / (sFaultDrawerInstance->charW + sFaultDrawerInstance->charWPad)); + //} + //sFaultDrawerInstance->cursorX = x; + //sFaultDrawerInstance->cursorY = y; } void FaultDrawer_FillScreen() { - if (sFaultDrawerInstance->osSyncPrintfEnabled) { - osSyncPrintf(VT_CLS); - } - - FaultDrawer_DrawRecImpl(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart, sFaultDrawerInstance->xEnd, - sFaultDrawerInstance->yEnd, sFaultDrawerInstance->backColor | 1); - FaultDrawer_SetCursor(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart); + //if (sFaultDrawerInstance->osSyncPrintfEnabled) { + // osSyncPrintf(VT_CLS); + //} + // + //FaultDrawer_DrawRecImpl(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart, sFaultDrawerInstance->xEnd, + // sFaultDrawerInstance->yEnd, sFaultDrawerInstance->backColor | 1); + //FaultDrawer_SetCursor(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart); } void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) { + #if 0 for (; count != 0; count--, str++) { if (sFaultDrawerInstance->escCode) { sFaultDrawerInstance->escCode = false; @@ -260,17 +270,19 @@ void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) { } osWritebackDCacheAll(); - - return arg; + #endif + return NULL; } -const char D_80099080[] = "(null)"; +//const char D_80099080[] = "(null)"; s32 FaultDrawer_VPrintf(const char* fmt, va_list ap) { - return _Printf(FaultDrawer_FormatStringFunc, sFaultDrawerInstance, fmt, ap); + //return _Printf(FaultDrawer_FormatStringFunc, sFaultDrawerInstance, fmt, ap); } s32 FaultDrawer_Printf(const char* fmt, ...) { + return 0; +#if 0 s32 ret; va_list args; @@ -281,30 +293,31 @@ s32 FaultDrawer_Printf(const char* fmt, ...) { va_end(args); return ret; + #endif } void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - - FaultDrawer_SetCursor(x, y); - FaultDrawer_VPrintf(fmt, args); - - va_end(args); + //va_list args; + //va_start(args, fmt); + // + //FaultDrawer_SetCursor(x, y); + //FaultDrawer_VPrintf(fmt, args); + // + //va_end(args); } void FaultDrawer_SetDrawerFrameBuffer(void* frameBuffer, u16 w, u16 h) { - sFaultDrawerInstance->frameBuffer = frameBuffer; - sFaultDrawerInstance->w = w; - sFaultDrawerInstance->h = h; + //sFaultDrawerInstance->frameBuffer = frameBuffer; + //sFaultDrawerInstance->w = w; + //sFaultDrawerInstance->h = h; } void FaultDrawer_SetInputCallback(FaultDrawerCallback callback) { - sFaultDrawerInstance->inputCallback = callback; + //sFaultDrawerInstance->inputCallback = callback; } void FaultDrawer_Init() { - sFaultDrawerInstance = &sFaultDrawer; - bcopy(&sFaultDrawerDefault, sFaultDrawerInstance, sizeof(FaultDrawer)); - sFaultDrawerInstance->frameBuffer = (u16*)(PHYS_TO_K0(osMemSize) - SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(u16)); + //sFaultDrawerInstance = &sFaultDrawer; + //bcopy(&sFaultDrawerDefault, sFaultDrawerInstance, sizeof(FaultDrawer)); + //sFaultDrawerInstance->frameBuffer = (u16*)(PHYS_TO_K0(osMemSize) - SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(u16)); } diff --git a/mm/src/boot/idle.c b/mm/src/boot/idle.c index 08f6d6ec7..7899885f0 100644 --- a/mm/src/boot/idle.c +++ b/mm/src/boot/idle.c @@ -29,35 +29,36 @@ f32 gViConfigXScale = 1.0f; f32 gViConfigYScale = 1.0f; void Main_ClearMemory(void* begin, void* end) { - if (begin < end) { - bzero(begin, (uintptr_t)end - (uintptr_t)begin); - } + //if (begin < end) { + // bzero(begin, (uintptr_t)end - (uintptr_t)begin); + //} } void Main_InitFramebuffer(u32* framebuffer, size_t numBytes, u32 value) { - for (; numBytes > 0; numBytes -= sizeof(u32)) { - *framebuffer++ = value; - } + //for (; numBytes > 0; numBytes -= sizeof(u32)) { + // *framebuffer++ = value; + //} } void Main_InitScreen(void) { - Main_InitFramebuffer((u32*)gFramebuffer1, sizeof(gFramebuffer1), - (GPACK_RGBA5551(0, 0, 0, 1) << 16) | GPACK_RGBA5551(0, 0, 0, 1)); - ViConfig_UpdateVi(false); - osViSwapBuffer(gFramebuffer1); - osViBlack(false); + //Main_InitFramebuffer((u32*)gFramebuffer1, sizeof(gFramebuffer1), + // (GPACK_RGBA5551(0, 0, 0, 1) << 16) | GPACK_RGBA5551(0, 0, 0, 1)); + //ViConfig_UpdateVi(false); + //osViSwapBuffer(gFramebuffer1); + //osViBlack(false); } void Main_InitMemory(void) { - void* memStart = (void*)0x80000400; - void* memEnd = OS_PHYSICAL_TO_K0(osMemSize); - - Main_ClearMemory(memStart, gFramebuffer1); - Main_ClearMemory(D_80025D00, bootproc); - Main_ClearMemory(gGfxSPTaskYieldBuffer, memEnd); + //void* memStart = (void*)0x80000400; + //void* memEnd = OS_PHYSICAL_TO_K0(osMemSize); + // + //Main_ClearMemory(memStart, gFramebuffer1); + //Main_ClearMemory(D_80025D00, bootproc); + //Main_ClearMemory(gGfxSPTaskYieldBuffer, memEnd); } void Main_Init(void) { + #if 0 DmaRequest dmaReq; OSMesgQueue mq; OSMesg msg[1]; @@ -77,18 +78,22 @@ void Main_Init(void) { gDmaMgrDmaBuffSize = prevSize; Main_ClearMemory(SEGMENT_BSS_START(code), SEGMENT_BSS_END(code)); + #endif } void Main_ThreadEntry(void* arg) { + #if 0 StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, STACK_TOP(sIrqMgrStack), 0, 0x100, "irqmgr"); IrqMgr_Init(&gIrqMgr, STACK_TOP(sIrqMgrStack), Z_PRIORITY_IRQMGR, 1); DmaMgr_Start(); Main_Init(); Main(arg); DmaMgr_Stop(); + #endif } void Idle_InitVideo(void) { + #if 0 osCreateViManager(OS_PRIORITY_VIMGR); gViConfigFeatures = OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF; @@ -114,15 +119,16 @@ void Idle_InitVideo(void) { } D_80096B20 = 1; + #endif } void Idle_ThreadEntry(void* arg) { - Idle_InitVideo(); - osCreatePiManager(OS_PRIORITY_PIMGR, &gPiMgrCmdQueue, sPiMgrCmdBuff, ARRAY_COUNT(sPiMgrCmdBuff)); - StackCheck_Init(&sMainStackInfo, sMainStack, STACK_TOP(sMainStack), 0, 0x400, "main"); - osCreateThread(&sMainThread, Z_THREAD_ID_MAIN, Main_ThreadEntry, arg, STACK_TOP(sMainStack), Z_PRIORITY_MAIN); - osStartThread(&sMainThread); - osSetThreadPri(NULL, OS_PRIORITY_IDLE); + //Idle_InitVideo(); + //osCreatePiManager(OS_PRIORITY_PIMGR, &gPiMgrCmdQueue, sPiMgrCmdBuff, ARRAY_COUNT(sPiMgrCmdBuff)); + //StackCheck_Init(&sMainStackInfo, sMainStack, STACK_TOP(sMainStack), 0, 0x400, "main"); + //osCreateThread(&sMainThread, Z_THREAD_ID_MAIN, Main_ThreadEntry, arg, STACK_TOP(sMainStack), Z_PRIORITY_MAIN); + //osStartThread(&sMainThread); + //osSetThreadPri(NULL, OS_PRIORITY_IDLE); - for (;;) {} + //for (;;) {} } diff --git a/mm/src/boot/irqmgr.c b/mm/src/boot/irqmgr.c index 172eabec8..4cdcd398d 100644 --- a/mm/src/boot/irqmgr.c +++ b/mm/src/boot/irqmgr.c @@ -8,6 +8,7 @@ volatile OSTime gIrqMgrRetraceTime = 0; s32 sIrqMgrRetraceCount = 0; void IrqMgr_AddClient(IrqMgr* irqmgr, IrqMgrClient* client, OSMesgQueue* msgQueue) { + #if 0 u32 saveMask; saveMask = osSetIntMask(1); @@ -24,9 +25,11 @@ void IrqMgr_AddClient(IrqMgr* irqmgr, IrqMgrClient* client, OSMesgQueue* msgQueu if (irqmgr->prenmiStage > 1) { osSendMesg(client->queue, &irqmgr->nmiMsg.type, OS_MESG_NOBLOCK); } + #endif } void IrqMgr_RemoveClient(IrqMgr* irqmgr, IrqMgrClient* remove) { + #if 0 IrqMgrClient* iter; IrqMgrClient* last; u32 saveMask; @@ -50,18 +53,22 @@ void IrqMgr_RemoveClient(IrqMgr* irqmgr, IrqMgrClient* remove) { } osSetIntMask(saveMask); + #endif } void IrqMgr_SendMesgForClient(IrqMgr* irqmgr, OSMesg msg) { + #if 0 IrqMgrClient* iter = irqmgr->callbacks; while (iter != NULL) { osSendMesg(iter->queue, msg, OS_MESG_NOBLOCK); iter = iter->next; } + #endif } void IrqMgr_JamMesgForClient(IrqMgr* irqmgr, OSMesg msg) { + #if 0 IrqMgrClient* iter = irqmgr->callbacks; while (iter != NULL) { @@ -70,9 +77,11 @@ void IrqMgr_JamMesgForClient(IrqMgr* irqmgr, OSMesg msg) { } iter = iter->next; } + #endif } void IrqMgr_HandlePreNMI(IrqMgr* irqmgr) { + #if 0 gIrqMgrResetStatus = 1; irqmgr->prenmiStage = 1; @@ -82,13 +91,15 @@ void IrqMgr_HandlePreNMI(IrqMgr* irqmgr) { osSetTimer(&irqmgr->prenmiTimer, OS_USEC_TO_CYCLES(450000), 0, &irqmgr->irqQueue, (OSMesg)0x29F); IrqMgr_JamMesgForClient(irqmgr, &irqmgr->prenmiMsg.type); + #endif } void IrqMgr_CheckStack(void) { - StackCheck_Check(NULL); + //StackCheck_Check(NULL); } void IrqMgr_HandlePRENMI450(IrqMgr* irqmgr) { + #if 0 gIrqMgrResetStatus = 2; irqmgr->prenmiStage = 2; @@ -96,19 +107,21 @@ void IrqMgr_HandlePRENMI450(IrqMgr* irqmgr) { osSetTimer(&irqmgr->prenmiTimer, OS_USEC_TO_CYCLES(30000), 0, &irqmgr->irqQueue, (OSMesg)0x2A0); IrqMgr_SendMesgForClient(irqmgr, &irqmgr->nmiMsg.type); + #endif } void IrqMgr_HandlePRENMI480(IrqMgr* irqmgr) { // Wait .52 seconds. After this we will have waited an entire second - osSetTimer(&irqmgr->prenmiTimer, OS_USEC_TO_CYCLES(520000), 0, &irqmgr->irqQueue, (OSMesg)0x2A1); + //osSetTimer(&irqmgr->prenmiTimer, OS_USEC_TO_CYCLES(520000), 0, &irqmgr->irqQueue, (OSMesg)0x2A1); - osAfterPreNMI(); + //osAfterPreNMI(); } void IrqMgr_HandlePRENMI500(IrqMgr* irqmgr) { - IrqMgr_CheckStack(); + //IrqMgr_CheckStack(); } void IrqMgr_HandleRetrace(IrqMgr* irqmgr) { + #if 0 if (gIrqMgrRetraceTime == 0) { if (irqmgr->lastFrameTime == 0) { irqmgr->lastFrameTime = osGetTime(); @@ -119,9 +132,11 @@ void IrqMgr_HandleRetrace(IrqMgr* irqmgr) { sIrqMgrRetraceCount += 1; IrqMgr_SendMesgForClient(irqmgr, irqmgr); + #endif } void IrqMgr_ThreadEntry(IrqMgr* irqmgr) { + #if 0 u32 interrupt; u32 stop; @@ -151,9 +166,11 @@ void IrqMgr_ThreadEntry(IrqMgr* irqmgr) { break; } } + #endif } void IrqMgr_Init(IrqMgr* irqmgr, void* stack, OSPri pri, u8 retraceCount) { + #if 0 irqmgr->callbacks = NULL; irqmgr->verticalRetraceMesg.type = 1; irqmgr->prenmiMsg.type = 4; @@ -167,4 +184,5 @@ void IrqMgr_Init(IrqMgr* irqmgr, void* stack, OSPri pri, u8 retraceCount) { osCreateThread(&irqmgr->thread, Z_THREAD_ID_IRQMGR, IrqMgr_ThreadEntry, irqmgr, stack, pri); osStartThread(&irqmgr->thread); + #endif } diff --git a/mm/src/boot/viconfig.c b/mm/src/boot/viconfig.c index 1b9f1135c..cfb17fe32 100644 --- a/mm/src/boot/viconfig.c +++ b/mm/src/boot/viconfig.c @@ -1,7 +1,15 @@ #include "libc/stdbool.h" #include "idle.h" +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeFpalLan1; + void ViConfig_UpdateVi(u32 black) { + #if 0 if (black) { switch (osTvType) { case OS_TV_MPAL: @@ -46,6 +54,7 @@ void ViConfig_UpdateVi(u32 black) { } gViConfigUseBlack = black; + #endif } void ViConfig_UpdateBlack(void) { diff --git a/mm/src/boot/z_std_dma.c b/mm/src/boot/z_std_dma.c index d5ba90513..208d6ed52 100644 --- a/mm/src/boot/z_std_dma.c +++ b/mm/src/boot/z_std_dma.c @@ -8,14 +8,15 @@ size_t gDmaMgrDmaBuffSize = 0x2000; -StackEntry sDmaMgrStackInfo; -u16 sNumDmaEntries; -OSMesgQueue sDmaMgrMsgQueue; -OSMesg sDmaMgrMsgs[32]; -OSThread sDmaMgrThread; -STACK(sDmaMgrStack, 0x500); +//StackEntry sDmaMgrStackInfo; +//u16 sNumDmaEntries; +//OSMesgQueue sDmaMgrMsgQueue; +//OSMesg sDmaMgrMsgs[32]; +//OSThread sDmaMgrThread; +//STACK(sDmaMgrStack, 0x500); s32 DmaMgr_DmaRomToRam(uintptr_t rom, void* ram, size_t size) { + #if 0 OSIoMesg ioMsg; OSMesgQueue queue; OSMesg msg[1]; @@ -59,13 +60,16 @@ s32 DmaMgr_DmaRomToRam(uintptr_t rom, void* ram, size_t size) { END: return ret; + #endif + return 0; } s32 DmaMgr_DmaHandler(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { - return osEPiStartDma(pihandle, mb, direction); + //return osEPiStartDma(pihandle, mb, direction); } DmaEntry* DmaMgr_FindDmaEntry(uintptr_t vrom) { + #if 0 DmaEntry* curr; for (curr = dmadata; curr->vromEnd != 0; curr++) { @@ -80,9 +84,11 @@ DmaEntry* DmaMgr_FindDmaEntry(uintptr_t vrom) { } return NULL; + #endif } u32 DmaMgr_TranslateVromToRom(uintptr_t vrom) { + #if 0 DmaEntry* entry = DmaMgr_FindDmaEntry(vrom); if (entry != NULL) { @@ -98,9 +104,11 @@ u32 DmaMgr_TranslateVromToRom(uintptr_t vrom) { } return -1; + #endif } s32 DmaMgr_FindDmaIndex(uintptr_t vrom) { + #if 0 DmaEntry* entry = DmaMgr_FindDmaEntry(vrom); if (entry != NULL) { @@ -108,6 +116,7 @@ s32 DmaMgr_FindDmaIndex(uintptr_t vrom) { } return -1; + #endif } const char* func_800809F4(u32 a0) { @@ -115,6 +124,7 @@ const char* func_800809F4(u32 a0) { } void DmaMgr_ProcessMsg(DmaRequest* req) { + #if 0 uintptr_t vrom; void* ram; size_t size; @@ -156,30 +166,34 @@ void DmaMgr_ProcessMsg(DmaRequest* req) { } else { Fault_AddHungupAndCrash("../z_std_dma.c", 558); } + #endif } void DmaMgr_ThreadEntry(void* a0) { + #if 0 OSMesg msg; DmaRequest* req; while (1) { osRecvMesg(&sDmaMgrMsgQueue, &msg, OS_MESG_BLOCK); - if (msg == NULL) { + if (msg.ptr == NULL) { break; } - req = (DmaRequest*)msg; + req = (DmaRequest*)msg.ptr; DmaMgr_ProcessMsg(req); if (req->notifyQueue) { osSendMesg(req->notifyQueue, req->notifyMsg, OS_MESG_NOBLOCK); } } + #endif } s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromStart, size_t size, UNK_TYPE4 unused, OSMesgQueue* queue, OSMesg msg) { + #if 0 if (gIrqMgrResetStatus >= 2) { return -2; } @@ -191,12 +205,13 @@ s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromS request->notifyQueue = queue; request->notifyMsg = msg; - osSendMesg(&sDmaMgrMsgQueue, request, OS_MESG_BLOCK); - + osSendMesg(&sDmaMgrMsgQueue, OS_MESG_PTR(request), OS_MESG_BLOCK); + #endif return 0; } s32 DmaMgr_SendRequest0(void* vramStart, uintptr_t vromStart, size_t size) { + #if 0 DmaRequest req; OSMesgQueue queue; OSMesg msg[1]; @@ -204,18 +219,19 @@ s32 DmaMgr_SendRequest0(void* vramStart, uintptr_t vromStart, size_t size) { osCreateMesgQueue(&queue, msg, ARRAY_COUNT(msg)); - ret = DmaMgr_SendRequestImpl(&req, vramStart, vromStart, size, 0, &queue, NULL); + ret = DmaMgr_SendRequestImpl(&req, vramStart, vromStart, size, 0, &queue, OS_MESG_PTR(NULL)); if (ret == -1) { return ret; } else { osRecvMesg(&queue, NULL, OS_MESG_BLOCK); } - + #endif return 0; } void DmaMgr_Start(void) { + #if 0 DmaMgr_DmaRomToRam(SEGMENT_ROM_START(dmadata), dmadata, SEGMENT_ROM_SIZE(dmadata)); { @@ -236,8 +252,9 @@ void DmaMgr_Start(void) { Z_PRIORITY_DMAMGR); osStartThread(&sDmaMgrThread); + #endif } void DmaMgr_Stop(void) { - osSendMesg(&sDmaMgrMsgQueue, NULL, OS_MESG_BLOCK); + //osSendMesg(&sDmaMgrMsgQueue, OS_MESG_PTR(NULL), OS_MESG_BLOCK); } diff --git a/mm/src/buffers/heaps.c b/mm/src/buffers/heaps.c index 477eca03e..6a7cba7a8 100644 --- a/mm/src/buffers/heaps.c +++ b/mm/src/buffers/heaps.c @@ -1,5 +1,26 @@ #include "buffers.h" +#include +#include -u8 gAudioHeap[0x138000]; -u8 gSystemHeap[UNK_SIZE]; +u8* gAudioHeap; + +u8* gSystemHeap; + +void Heaps_Alloc(void) { +#ifdef _MSC_VER + gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 0x10); + gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 0x10); +#elif defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) + if (posix_memalign((void**)&gAudioHeap, 0x10, AUDIO_HEAP_SIZE) != 0) + gAudioHeap = NULL; + if (posix_memalign((void**)&gSystemHeap, 0x10, SYSTEM_HEAP_SIZE) != 0) + gSystemHeap = NULL; +#else + gAudioHeap = (u8*)memalign(0x10, AUDIO_HEAP_SIZE); + gSystemHeap = (u8*)memalign(0x10, SYSTEM_HEAP_SIZE); +#endif + + assert(gAudioHeap != NULL); + assert(gSystemHeap != NULL); +} \ No newline at end of file diff --git a/mm/src/code/PreRender.c b/mm/src/code/PreRender.c index e33fbd30e..8a862f6a9 100644 --- a/mm/src/code/PreRender.c +++ b/mm/src/code/PreRender.c @@ -16,6 +16,7 @@ #include "slowly.h" #include "stack.h" #include "stackcheck.h" +#include /** * Assigns the "save" values in PreRender @@ -125,6 +126,8 @@ void func_80170200(PreRender* this, Gfx** gfxp, void* buf, void* bufSave) { * @param cvgDst Buffer to store coverage into */ void PreRender_CoverageRgba16ToI8(PreRender* this, Gfx** gfxp, void* img, void* cvgDst) { + // BENTODO: + return; Gfx* gfx = *gfxp; s32 rowsRemaining; s32 curRow; @@ -598,7 +601,7 @@ u32 PreRender_Get5bMedian9(u8* px1, u8* px2, u8* px3) { void PreRender_DivotFilter(PreRender* this) { u32 width = this->width; u32 height = this->height; - u8* buffer = alloca(width * 10); + u8* buffer = malloc(width * 10); u8* redRow[3]; u8* greenRow[3]; u8* blueRow[3]; @@ -684,6 +687,7 @@ void PreRender_DivotFilter(PreRender* this) { greenRow[1] = greenRow[2]; blueRow[1] = blueRow[2]; } + free(buffer); } /** diff --git a/mm/src/code/TwoHeadGfxArena.c b/mm/src/code/TwoHeadGfxArena.c index d40512efd..3811bbd12 100644 --- a/mm/src/code/TwoHeadGfxArena.c +++ b/mm/src/code/TwoHeadGfxArena.c @@ -93,7 +93,7 @@ Mtx* THGA_AllocMtx(TwoHeadGfxArena* thga) { /** * Allocates `num` vertices to the tail end of the Two Head Gfx Arena. */ -Vtx* THGA_AllocVtxArray(TwoHeadGfxArena* thga, u32 num) { +Vtx* THGA_AllocVtxArray(TwoHeadGfxArena* thga, size_t num) { return THGA_AllocTail(thga, num * sizeof(Vtx)); } diff --git a/mm/src/code/audio_thread_manager.c b/mm/src/code/audio_thread_manager.c index 12941eb2d..ea035510a 100644 --- a/mm/src/code/audio_thread_manager.c +++ b/mm/src/code/audio_thread_manager.c @@ -5,11 +5,12 @@ void AudioMgr_NotifyTaskDone(AudioMgr* audioMgr) { AudioTask* task = audioMgr->rspTask; if (audioMgr->rspTask->taskQueue != NULL) { - osSendMesg(task->taskQueue, NULL, OS_MESG_BLOCK); + osSendMesg(task->taskQueue, OS_MESG_PTR(NULL), OS_MESG_BLOCK); } } - +// BENTODO void AudioMgr_HandleRetrace(AudioMgr* audioMgr) { + #if 0 static s32 sRetryCount = 10; AudioTask* rspTask; s32 timerMsgVal = 666; @@ -32,8 +33,8 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) { audioMgr->audioTask.list = audioMgr->rspTask->task; audioMgr->audioTask.msgQ = &audioMgr->cmdQueue; - audioMgr->audioTask.msg = NULL; - osSendMesg(&audioMgr->sched->cmdQ, &audioMgr->audioTask, OS_MESG_BLOCK); + audioMgr->audioTask.msg.ptr = NULL; + osSendMesg(&audioMgr->sched->cmdQ, OS_MESG_PTR(&audioMgr->audioTask), OS_MESG_BLOCK); Sched_SendEntryMsg(audioMgr->sched); } @@ -45,7 +46,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) { if (audioMgr->rspTask != NULL) { while (true) { - osSetTimer(&timer, OS_USEC_TO_CYCLES(32000), 0, &audioMgr->cmdQueue, (OSMesg)timerMsgVal); + osSetTimer(&timer, OS_USEC_TO_CYCLES(32000), 0, &audioMgr->cmdQueue, OS_MESG_32(timerMsgVal)); osRecvMesg(&audioMgr->cmdQueue, (OSMesg*)&msg, OS_MESG_BLOCK); osStopTimer(&timer); if (msg == timerMsgVal) { @@ -67,6 +68,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) { } audioMgr->rspTask = rspTask; + #endif } void AudioMgr_HandlePreNMI(AudioMgr* audioMgr) { @@ -82,7 +84,7 @@ void AudioMgr_ThreadEntry(void* arg) { Audio_Init(); AudioLoad_SetDmaHandler(DmaMgr_DmaHandler); Audio_InitSound(); - osSendMesg(&audioMgr->lockQueue, NULL, OS_MESG_BLOCK); + osSendMesg(&audioMgr->lockQueue, OS_MESG_PTR(NULL), OS_MESG_BLOCK); IrqMgr_AddClient(audioMgr->irqMgr, &irqClient, &audioMgr->interruptQueue); exit = false; diff --git a/mm/src/code/code_8010C1B0.c b/mm/src/code/code_8010C1B0.c index 2c1fd410f..12a94df3a 100644 --- a/mm/src/code/code_8010C1B0.c +++ b/mm/src/code/code_8010C1B0.c @@ -9,12 +9,12 @@ void MsgEvent_SendNullTask(void) { task.next = NULL; task.flags = OS_SC_RCP_MASK; task.msgQ = &queue; - task.msg = NULL; + task.msg.ptr = NULL; task.framebuffer = NULL; task.list.t.type = M_NULTASK; osCreateMesgQueue(task.msgQ, &msg, 1); - osSendMesg(&gSchedContext.cmdQ, &task, OS_MESG_BLOCK); + osSendMesg(&gSchedContext.cmdQ, OS_MESG_PTR(&task), OS_MESG_BLOCK); Sched_SendEntryMsg(&gSchedContext); osRecvMesg(&queue, NULL, OS_MESG_BLOCK); } diff --git a/mm/src/code/game.c b/mm/src/code/game.c index 237783319..a3f0ba824 100644 --- a/mm/src/code/game.c +++ b/mm/src/code/game.c @@ -228,12 +228,13 @@ void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* g SpeedMeter_Init(&sGameSpeedMeter); Rumble_Init(); - osSendMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK); + osSendMesg(&gameState->gfxCtx->queue, OS_MESG_PTR(NULL), OS_MESG_BLOCK); } void GameState_Destroy(GameState* gameState) { - AudioMgr_StopAllSfxExceptSystem(); - Audio_Update(); + // BENTODO + //AudioMgr_StopAllSfxExceptSystem(); + //Audio_Update(); osRecvMesg(&gameState->gfxCtx->queue, NULL, OS_MESG_BLOCK); if (gameState->destroy != NULL) { diff --git a/mm/src/code/graph.c b/mm/src/code/graph.c index 6568a258d..219df9897 100644 --- a/mm/src/code/graph.c +++ b/mm/src/code/graph.c @@ -1,7 +1,9 @@ +#include "prevent_bss_reordering.h" #include "z64.h" #include "regs.h" #include "functions.h" #include "fault.h" +#include "gfxdebuggerbridge.h" // Variables are put before most headers as a hacky way to bypass bss reordering FaultAddrConvClient sGraphFaultAddrConvClient; @@ -24,6 +26,10 @@ OSTime sGraphPrevUpdateEndTime; #include "overlays/gamestates/ovl_title/z_title.h" #include "z_title_setup.h" +void Graph_StartFrame(); +void Graph_ProcessGfxCommands(Gfx* commands); +void Graph_ProcessFrame(void (*run_one_game_iter)(void)); + void Graph_FaultClient(void) { FaultDrawer_DrawText(30, 100, "ShowFrameBuffer PAGE 0/1"); osViSwapBuffer(SysCfb_GetFramebuffer(0)); @@ -43,7 +49,7 @@ void Graph_SetNextGfxPool(GraphicsContext* gfxCtx) { GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx % 2]; gGfxMasterDL = &pool->master; - gSegments[0x0E] = (uintptr_t)gGfxMasterDL; + gSegments[0x0E] = gGfxMasterDL; pool->headMagic = GFXPOOL_HEAD_MAGIC; pool->tailMagic = GFXPOOL_TAIL_MAGIC; @@ -61,7 +67,7 @@ void Graph_SetNextGfxPool(GraphicsContext* gfxCtx) { gfxCtx->debugBuffer = pool->debugBuffer; gfxCtx->curFrameBuffer = SysCfb_GetFramebuffer(gfxCtx->framebufferIndex % 2); - gSegments[0x0F] = (uintptr_t)gfxCtx->curFrameBuffer; + gSegments[0x0F] = gfxCtx->curFrameBuffer; gfxCtx->zbuffer = SysCfb_GetZBuffer(); @@ -122,13 +128,13 @@ void Graph_Init(GraphicsContext* gfxCtx) { gfxCtx->xScale = gViConfigXScale; gfxCtx->yScale = gViConfigYScale; osCreateMesgQueue(&gfxCtx->queue, gfxCtx->msgBuff, ARRAY_COUNT(gfxCtx->msgBuff)); - Fault_AddClient(&sGraphFaultClient, (void*)Graph_FaultClient, NULL, NULL); - Fault_AddAddrConvClient(&sGraphFaultAddrConvClient, Graph_FaultAddrConv, NULL); + // Fault_AddClient(&sGraphFaultClient, (void*)Graph_FaultClient, NULL, NULL); + // Fault_AddAddrConvClient(&sGraphFaultAddrConvClient, Graph_FaultAddrConv, NULL); } void Graph_Destroy(GraphicsContext* gfxCtx) { - Fault_RemoveClient(&sGraphFaultClient); - Fault_RemoveAddrConvClient(&sGraphFaultAddrConvClient); + // Fault_RemoveClient(&sGraphFaultClient); + // Fault_RemoveAddrConvClient(&sGraphFaultAddrConvClient); } /** @@ -146,10 +152,10 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx, GameState* gameState) { CfbInfo* cfb; retry: - osSetTimer(&timer, OS_USEC_TO_CYCLES(3 * 1000 * 1000), 0, &gfxCtx->queue, (OSMesg)666); - osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK); - osStopTimer(&timer); - +// osSetTimer(&timer, OS_USEC_TO_CYCLES(3 * 1000 * 1000), 0, &gfxCtx->queue, (OSMesg)666); +// osRecvMesg(&gfxCtx->queue, &msg, OS_MESG_BLOCK); +// osStopTimer(&timer); +#if 0 if (msg == (OSMesg)666) { osSyncPrintf("GRAPH SP TIMEOUT\n"); if (retryCount >= 0) { @@ -159,10 +165,10 @@ retry: } else { // graph.c: No more! die! osSyncPrintf("graph.c:もうダメ!死ぬ!\n"); - Fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!"); + //Fault_AddHungupAndCrashImpl("RCP is HUNG UP!!", "Oh! MY GOD!!"); } } - +#endif gfxCtx->masterList = gGfxMasterDL; if (gfxCtx->callback != NULL) { gfxCtx->callback(gfxCtx, gfxCtx->callbackArg); @@ -170,20 +176,23 @@ retry: task->type = M_GFXTASK; task->flags = OS_SC_DRAM_DLIST; - task->ucodeBoot = SysUcode_GetUCodeBoot(); - task->ucodeBootSize = SysUcode_GetUCodeBootSize(); + task->ucode_boot = SysUcode_GetUCodeBoot(); + task->ucode_boot_size = SysUcode_GetUCodeBootSize(); task->ucode = SysUcode_GetUCode(); - task->ucodeData = SysUcode_GetUCodeData(); - task->ucodeSize = SP_UCODE_SIZE; - task->ucodeDataSize = SP_UCODE_DATA_SIZE; - task->dramStack = (u64*)gGfxSPTaskStack; - task->dramStackSize = sizeof(gGfxSPTaskStack); - task->outputBuff = gGfxSPTaskOutputBufferPtr; - task->outputBuffSize = (void*)gGfxSPTaskOutputBufferEnd; - task->dataPtr = (u64*)gGfxMasterDL; - task->dataSize = 0; - task->yieldDataPtr = (u64*)gGfxSPTaskYieldBuffer; - task->yieldDataSize = sizeof(gGfxSPTaskYieldBuffer); + task->ucode_data = SysUcode_GetUCodeData(); + task->ucode_size = SP_UCODE_SIZE; + task->ucode_data_size = SP_UCODE_DATA_SIZE; + task->dram_stack = (u64*)gGfxSPTaskStack; + task->dram_stack_size = sizeof(gGfxSPTaskStack); + task->output_buff = gGfxSPTaskOutputBufferPtr; + task->output_buff_size = gGfxSPTaskOutputBufferEnd; + task->data_ptr = (u64*)gGfxMasterDL; + OPEN_DISPS(gfxCtx); + task->data_size = (uintptr_t)WORK_DISP - (uintptr_t)gfxCtx->workBuffer; + CLOSE_DISPS(gfxCtx); + + task->yield_data_ptr = (u64*)gGfxSPTaskYieldBuffer; + task->yield_data_size = sizeof(gGfxSPTaskYieldBuffer); scTask->next = NULL; scTask->flags = OS_SC_RCP_MASK | OS_SC_SWAPBUFFER | OS_SC_LAST_TASK; @@ -195,7 +204,7 @@ retry: } scTask->msgQ = &gfxCtx->queue; - scTask->msg = NULL; + scTask->msg.ptr = NULL; { s32 pad; } @@ -224,16 +233,17 @@ retry: } gfxCtx->schedMsgQ = &gSchedContext.cmdQ; - osSendMesg(&gSchedContext.cmdQ, scTask, OS_MESG_BLOCK); + osSendMesg(&gSchedContext.cmdQ, OS_MESG_PTR(scTask), OS_MESG_BLOCK); Sched_SendEntryMsg(&gSchedContext); } void Graph_UpdateGame(GameState* gameState) { GameState_GetInput(gameState); GameState_IncrementFrameCount(gameState); - if (SREG(20) < 3) { - Audio_Update(); - } + // BENTODO + // if (SREG(20) < 3) { + // Audio_Update(); + //} } /** @@ -242,6 +252,10 @@ void Graph_UpdateGame(GameState* gameState) { */ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) { u32 problem; + if (GfxDebuggerIsDebugging()) { + Graph_ProcessGfxCommands(&gGfxMasterDL->taskStart[0]); + return; + } gameState->unk_A3 = 0; Graph_SetNextGfxPool(gfxCtx); @@ -261,12 +275,19 @@ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) { { Gfx* gfx = gGfxMasterDL->taskStart; - gSPSegment(gfx++, 0x0E, gGfxMasterDL); - gSPDisplayList(gfx++, &D_0E000000.disps[3]); - gSPDisplayList(gfx++, &D_0E000000.disps[0]); - gSPDisplayList(gfx++, &D_0E000000.disps[1]); - gSPDisplayList(gfx++, &D_0E000000.disps[2]); - gSPDisplayList(gfx++, &D_0E000000.debugDisp[0]); + gSPSegment(gfx++, 0x0E, gGfxMasterDL->taskStart); + //__gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.disps[3] - (uintptr_t)&D_0E000000) + 1); + //__gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.disps[0] - (uintptr_t)&D_0E000000) + 1); + //__gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.disps[1] - (uintptr_t)&D_0E000000) + 1); + //__gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.disps[2] - (uintptr_t)&D_0E000000) + 1); + //__gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.debugDisp[0] - (uintptr_t)&D_0E000000) + 1); + gSPDisplayList(gfx++, gfxCtx->work.start); + + gSPDisplayList(gfx++, gGfxPools[gfxCtx->gfxPoolIdx % 2].workBuffer); + gSPDisplayList(gfx++, gGfxPools[gfxCtx->gfxPoolIdx % 2].polyOpaBuffer); + gSPDisplayList(gfx++, gGfxPools[gfxCtx->gfxPoolIdx % 2].polyXluBuffer); + gSPDisplayList(gfx++, gGfxPools[gfxCtx->gfxPoolIdx % 2].overlayBuffer); + gSPDisplayList(gfx++, gGfxPools[gfxCtx->gfxPoolIdx % 2].debugBuffer); gDPPipeSync(gfx++); gDPFullSync(gfx++); @@ -279,10 +300,10 @@ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) { GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx % 2]; if (pool->headMagic != GFXPOOL_HEAD_MAGIC) { - Fault_AddHungupAndCrash("../graph.c", 1054); + // Fault_AddHungupAndCrash("../graph.c", 1054); } if (pool->tailMagic != GFXPOOL_TAIL_MAGIC) { - Fault_AddHungupAndCrash("../graph.c", 1066); + // Fault_AddHungupAndCrash("../graph.c", 1066); } } @@ -306,6 +327,11 @@ void Graph_ExecuteAndDraw(GraphicsContext* gfxCtx, GameState* gameState) { Graph_TaskSet00(gfxCtx, gameState); gfxCtx->gfxPoolIdx++; gfxCtx->framebufferIndex++; + + if (GfxDebuggerIsDebuggingRequested()) { + GfxDebuggerDebugDisplayList(&gGfxMasterDL->taskStart[0]); + } + Graph_ProcessGfxCommands(&gGfxMasterDL->taskStart[0]); } { @@ -332,7 +358,15 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { Graph_ExecuteAndDraw(gfxCtx, gameState); } -void Graph_ThreadEntry(void* arg) { +static struct RunFrameContext { + GraphicsContext gfxCtx; + GameState* gameState; + GameStateOverlay* nextOvl; + GameStateOverlay* ovl; + int state; +} runFrameContext; + +void RunFrame() { GraphicsContext gfxCtx; GameStateOverlay* nextOvl = &gGameStateOverlayTable[0]; GameStateOverlay* ovl; @@ -340,47 +374,56 @@ void Graph_ThreadEntry(void* arg) { u32 size; s32 pad[2]; - gZBufferLoRes = SystemArena_Malloc(sizeof(*gZBufferLoRes) + sizeof(*gWorkBufferLoRes) + 64 - 1); - gZBufferLoRes = (void*)ALIGN64((u32)gZBufferLoRes); + switch (runFrameContext.state) { + case 0: + break; + case 1: + goto nextFrame; + } - gWorkBufferLoRes = (void*)((u8*)gZBufferLoRes + sizeof(*gZBufferLoRes)); + runFrameContext.nextOvl = &gGameStateOverlayTable[0]; - gGfxSPTaskOutputBufferHiRes = gGfxSPTaskOutputBufferLoRes = - SystemArena_Malloc(sizeof(*gGfxSPTaskOutputBufferLoRes)); + Graph_Init(&runFrameContext.gfxCtx); + while (runFrameContext.nextOvl) { + runFrameContext.ovl = runFrameContext.nextOvl; + Overlay_LoadGameState(runFrameContext.ovl); - gGfxSPTaskOutputBufferEndLoRes = (u8*)gGfxSPTaskOutputBufferLoRes + sizeof(*gGfxSPTaskOutputBufferLoRes); - gGfxSPTaskOutputBufferEndHiRes = (u8*)gGfxSPTaskOutputBufferHiRes + sizeof(*gGfxSPTaskOutputBufferHiRes); + size = runFrameContext.ovl->instanceSize; + osSyncPrintf("クラスサイズ=%dバイト\n", size); // "Class size = %d bytes" - SysCfb_Init(); - Fault_SetFrameBuffer(gWorkBuffer, SCREEN_WIDTH, SCREEN_HEIGHT); - Graph_Init(&gfxCtx); + runFrameContext.gameState = SystemArena_Malloc(size); - while (nextOvl) { - ovl = nextOvl; + bzero(runFrameContext.gameState, size); // fix + GameState_Init(runFrameContext.gameState, runFrameContext.ovl->init, &runFrameContext.gfxCtx); - Overlay_LoadGameState(ovl); + uint64_t freq = GetFrequency(); - size = ovl->instanceSize; + while (GameState_IsRunning(runFrameContext.gameState)) { - func_800809F4(ovl->vromStart); + Graph_StartFrame(); - gameState = SystemArena_Malloc(size); + PadMgr_ThreadEntry(&gPadMgr); - bzero(gameState, size); - GameState_Init(gameState, ovl->init, &gfxCtx); + Graph_Update(&runFrameContext.gfxCtx, runFrameContext.gameState); + // ticksB = GetPerfCounter(); - while (GameState_IsRunning(gameState)) { - Graph_Update(&gfxCtx, gameState); + // Graph_ProcessGfxCommands(runFrameContext.gfxCtx.workBuffer); + // Graph_ProcessGfxCommands(gGfxMasterDL->taskStart); + // uint64_t diff = (ticksB - ticksA) / (freq / 1000); + // printf("Frame simulated in %ims\n", diff); + runFrameContext.state = 1; + return; + nextFrame:; } - nextOvl = Graph_GetNextGameState(gameState); - - if (size) {} - - GameState_Destroy(gameState); - SystemArena_Free(gameState); - - Overlay_FreeGameState(ovl); + runFrameContext.nextOvl = Graph_GetNextGameState(runFrameContext.gameState); + GameState_Destroy(runFrameContext.gameState); + // System (runFrameContext.gameState); + Overlay_FreeGameState(runFrameContext.ovl); } - Graph_Destroy(&gfxCtx); + Graph_Destroy(&runFrameContext.gfxCtx); +} + +void Graph_ThreadEntry(void* arg0) { + Graph_ProcessFrame(RunFrame); } diff --git a/mm/src/code/main.c b/mm/src/code/main.c index 14ee841ce..e9d9be56a 100644 --- a/mm/src/code/main.c +++ b/mm/src/code/main.c @@ -11,7 +11,7 @@ // Variables are put before most headers as a hacky way to bypass bss reordering OSMesgQueue sSerialEventQueue; OSMesg sSerialMsgBuf[1]; -u32 gSegments[NUM_SEGMENTS]; +uintptr_t gSegments[NUM_SEGMENTS]; SchedContext gSchedContext; IrqMgrClient sIrqClient; OSMesgQueue sIrqMgrMsgQueue; @@ -39,11 +39,19 @@ s32 gScreenWidth = SCREEN_WIDTH; s32 gScreenHeight = SCREEN_HEIGHT; size_t gSystemHeapSize = 0; -void Main(void* arg) { +void InitOTR(); + +#ifdef __GNUC__ +#define SDL_main main +#endif + +void SDL_main(int argc, char** argv /* void* arg*/) { intptr_t fb; intptr_t sysHeap; s32 exit; s16* msg; + InitOTR(); + Heaps_Alloc(); gScreenWidth = SCREEN_WIDTH; gScreenHeight = SCREEN_HEIGHT; @@ -52,21 +60,22 @@ void Main(void* arg) { Fault_Init(); Check_RegionIsSupported(); Check_ExpansionPak(); - - sysHeap = (intptr_t)gSystemHeap; - fb = 0x80780000; - gSystemHeapSize = fb - sysHeap; - SystemHeap_Init((void*)sysHeap, gSystemHeapSize); + sysHeap = gSystemHeap; + // fb = 0x80780000; + // gSystemHeapSize = fb - sysHeap; + SystemHeap_Init(sysHeap, SYSTEM_HEAP_SIZE); Regs_Init(); R_ENABLE_ARENA_DBG = 0; osCreateMesgQueue(&sSerialEventQueue, sSerialMsgBuf, ARRAY_COUNT(sSerialMsgBuf)); - osSetEventMesg(OS_EVENT_SI, &sSerialEventQueue, NULL); + osSetEventMesg(OS_EVENT_SI, &sSerialEventQueue, OS_MESG_PTR(NULL)); osCreateMesgQueue(&sIrqMgrMsgQueue, sIrqMgrMsgBuf, ARRAY_COUNT(sIrqMgrMsgBuf)); + PadMgr_Init(&sSerialEventQueue, &gIrqMgr, Z_THREAD_ID_PADMGR, Z_PRIORITY_PADMGR, STACK_TOP(sPadMgrStack)); +#if 0 StackCheck_Init(&sSchedStackInfo, sSchedStack, STACK_TOP(sSchedStack), 0, 0x100, "sched"); Sched_Init(&gSchedContext, STACK_TOP(sSchedStack), Z_PRIORITY_SCHED, gViConfigModeType, 1, &gIrqMgr); @@ -79,13 +88,14 @@ void Main(void* arg) { &gIrqMgr); StackCheck_Init(&sPadMgrStackInfo, sPadMgrStack, STACK_TOP(sPadMgrStack), 0, 0x100, "padmgr"); - PadMgr_Init(&sSerialEventQueue, &gIrqMgr, Z_THREAD_ID_PADMGR, Z_PRIORITY_PADMGR, STACK_TOP(sPadMgrStack)); AudioMgr_Unlock(&sAudioMgr); - StackCheck_Init(&sGraphStackInfo, sGraphStack, STACK_TOP(sGraphStack), 0, 0x100, "graph"); - osCreateThread(&gGraphThread, Z_THREAD_ID_GRAPH, Graph_ThreadEntry, arg, STACK_TOP(sGraphStack), Z_PRIORITY_GRAPH); + osCreateThread(&gGraphThread, Z_THREAD_ID_GRAPH, Graph_ThreadEntry, NULL, STACK_TOP(sGraphStack), Z_PRIORITY_GRAPH); osStartThread(&gGraphThread); +#endif + + Graph_ThreadEntry(0); exit = false; diff --git a/mm/src/code/object_table.c b/mm/src/code/object_table.c index 87c4069fe..6d28be247 100644 --- a/mm/src/code/object_table.c +++ b/mm/src/code/object_table.c @@ -11,9 +11,13 @@ s16 gPlayerFormObjectIds[PLAYER_FORM_MAX] = { ObjectId gObjectTableSize = OBJECT_ID_MAX; // Object Table definition -#define DEFINE_OBJECT(name, _enumValue) { SEGMENT_ROM_START(name), SEGMENT_ROM_END(name) }, -#define DEFINE_OBJECT_UNSET(_enumValue) { 0, 0 }, -#define DEFINE_OBJECT_SIZE_ZERO(name, _enumValue) { SEGMENT_ROM_START(name), SEGMENT_ROM_START(name) }, +#define DEFINE_OBJECT(name, _1) { 0, 0, #name}, +#define DEFINE_OBJECT_NULL(name, _1) ROM_FILE(name), +#define DEFINE_OBJECT_UNSET(_0) { 0, 0, "" }, +#define DEFINE_OBJECT_SIZE_ZERO(name, x) DEFINE_OBJECT_UNSET(aa) +//#define DEFINE_OBJECT(name, _enumValue) { SEGMENT_ROM_START(name), SEGMENT_ROM_END(name) }, +//#define DEFINE_OBJECT_UNSET(_enumValue) { 0, 0 }, +//#define DEFINE_OBJECT_SIZE_ZERO(name, _enumValue) { SEGMENT_ROM_START(name), SEGMENT_ROM_START(name) }, RomFile gObjectTable[] = { #include "tables/object_table.h" diff --git a/mm/src/code/padmgr.c b/mm/src/code/padmgr.c index 056103dde..09e29eaf5 100644 --- a/mm/src/code/padmgr.c +++ b/mm/src/code/padmgr.c @@ -35,9 +35,8 @@ #include "PR/controller.h" #include "PR/os_motor.h" #include "fault.h" -#include "z64voice.h" -extern FaultMgr gFaultMgr; +//extern FaultMgr gFaultMgr; #define PADMGR_RETRACE_MSG (1 << 0) #define PADMGR_PRE_NMI_MSG (1 << 1) @@ -172,7 +171,7 @@ OSMesgQueue* PadMgr_VoiceAcquireSerialEventQueue(void) { * @see PadMgr_AcquireSerialEventQueue */ void PadMgr_ReleaseSerialEventQueue(OSMesgQueue* serialEventQueue) { - osSendMesg(&sPadMgrInstance->serialLockQueue, (OSMesg)serialEventQueue, OS_MESG_BLOCK); + // osSendMesg(&sPadMgrInstance->serialLockQueue, (OSMesg)serialEventQueue, OS_MESG_BLOCK); } /** @@ -181,7 +180,7 @@ void PadMgr_ReleaseSerialEventQueue(OSMesgQueue* serialEventQueue) { * @see PadMgr_VoiceAcquireSerialEventQueue */ void PadMgr_VoiceReleaseSerialEventQueue(OSMesgQueue* serialEventQueue) { - osSendMesg(&sPadMgrInstance->serialLockQueue, (OSMesg)serialEventQueue, OS_MESG_BLOCK); + // osSendMesg(&sPadMgrInstance->serialLockQueue, (OSMesg)serialEventQueue, OS_MESG_BLOCK); } /** @@ -191,7 +190,7 @@ void PadMgr_VoiceReleaseSerialEventQueue(OSMesgQueue* serialEventQueue) { * @see PadMgr_UnlockPadData */ void PadMgr_LockPadData(void) { - osRecvMesg(&sPadMgrInstance->lockQueue, NULL, OS_MESG_BLOCK); + // osRecvMesg(&sPadMgrInstance->lockQueue, NULL, OS_MESG_BLOCK); } /** @@ -201,7 +200,7 @@ void PadMgr_LockPadData(void) { * @see PadMgr_LockPadData */ void PadMgr_UnlockPadData(void) { - osSendMesg(&sPadMgrInstance->lockQueue, NULL, OS_MESG_BLOCK); + // osSendMesg(&sPadMgrInstance->lockQueue, NULL, OS_MESG_BLOCK); } /** @@ -275,7 +274,7 @@ void PadMgr_UpdateRumble(void) { // No controller pak } else { // Unrecognized return code - Fault_AddHungupAndCrash("../padmgr.c", 594); + // Fault_AddHungupAndCrash("../padmgr.c", 594); } } } @@ -354,18 +353,19 @@ void PadMgr_AdjustInput(Input* input) { s8 curX = input->cur.stick_x; s8 curY = input->cur.stick_y; - if (CHECK_BTN_ANY(input->press.button, BTN_RESET) || (input->press.stick_x == 0)) { - input->press.stick_x = 61; - input->press.errno = -61; - input->press.stick_y = 63; - input->rel.errno = -63; - } + // BENTODO + // if (CHECK_BTN_ANY(input->press.button, BTN_RESET) || (input->press.stick_x == 0)) { + // input->press.stick_x = 61; + // input->press.err_no = -61; + // input->press.stick_y = 63; + // input->rel.err_no = -63; + //} pressX = input->press.stick_x; - pressX2 = (s8)input->press.errno; + pressX2 = (s8)input->press.err_no; pressY = input->press.stick_y; - pressY2 = (s8)input->rel.errno; + pressY2 = (s8)input->rel.err_no; - if (CHECK_BTN_ANY(input->cur.button, BTN_RESET)) { + /* if (CHECK_BTN_ANY(input->cur.button, BTN_RESET)) { minus = curX - 7; plus = curX + 7; @@ -377,7 +377,7 @@ void PadMgr_AdjustInput(Input* input) { } else if (plus < 0) { if (pressX2 > plus + 3) { pressX2 = plus + 3; - input->press.errno = plus + 3; + input->press.err_no = plus + 3; } } @@ -392,10 +392,10 @@ void PadMgr_AdjustInput(Input* input) { } else if (plus < 0) { if (pressY2 > plus + 3) { pressY2 = plus + 3; - input->rel.errno = plus + 3; + input->rel.err_no = plus + 3; } } - } + }*/ minus = curX - 7; plus = curX + 7; @@ -449,7 +449,7 @@ void PadMgr_UpdateInputs(void) { input->prev = input->cur; isStandardController = sPadMgrInstance->ctrlrType[i] == PADMGR_CONT_NORMAL; if (isStandardController) { - switch (pad->errno) { + switch (pad->err_no) { case 0: // No error, copy inputs input->cur = *pad; @@ -465,7 +465,7 @@ void PadMgr_UpdateInputs(void) { input->cur.button = 0; input->cur.stick_x = 0; input->cur.stick_y = 0; - input->cur.errno = pad->errno; + input->cur.err_no = pad->err_no; if (sPadMgrInstance->ctrlrType[i] != PADMGR_CONT_NONE) { // If we get no response, consider the controller disconnected sPadMgrInstance->ctrlrType[i] = PADMGR_CONT_NONE; @@ -476,14 +476,14 @@ void PadMgr_UpdateInputs(void) { default: // Unknown error response - Fault_AddHungupAndCrash("../padmgr.c", 1098); + // Fault_AddHungupAndCrash("../padmgr.c", 1098); break; } } else { input->cur.button = 0; input->cur.stick_x = 0; input->cur.stick_y = 0; - input->cur.errno = pad->errno; + input->cur.err_no = pad->err_no; } // If opposed directions on the D-Pad are pressed at the same time, mask both out @@ -511,6 +511,7 @@ void PadMgr_UpdateInputs(void) { * a VRU other than on the first VI retrace. */ void PadMgr_InitVoice(void) { +#if 0 s32 i; OSMesgQueue* serialEventQueue; s32 ret; @@ -536,6 +537,7 @@ void PadMgr_InitVoice(void) { if (sVoiceInitStatus == VOICE_INIT_TRY) { sVoiceInitStatus = VOICE_INIT_FAILED; } +#endif } /** @@ -544,12 +546,15 @@ void PadMgr_InitVoice(void) { void PadMgr_UpdateConnections(void) { s32 ctrlrMask = 0; s32 i; - char msg[50]; + char msg[2048]; for (i = 0; i < MAXCONTROLLERS; i++) { - if (sPadMgrInstance->padStatus[i].errno == 0) { + goto TriggerKenix; + if (sPadMgrInstance->padStatus[i].err_no == 0) { switch (sPadMgrInstance->padStatus[i].type & CONT_TYPE_MASK) { case CONT_TYPE_NORMAL: + // BENTODO: :goron: + TriggerKenix: // Standard N64 Controller ctrlrMask |= (1 << i); if (sPadMgrInstance->ctrlrType[i] == PADMGR_CONT_NONE) { @@ -604,7 +609,7 @@ void PadMgr_HandleRetrace(void) { } // Wait for controller data - osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK); + // osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK); osContGetReadData(sPadMgrInstance->pads); // Clear all but controller 1 @@ -617,7 +622,7 @@ void PadMgr_HandleRetrace(void) { // Query controller statuses osContStartQuery(serialEventQueue); - osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK); + // osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK); osContGetQuery(sPadMgrInstance->padStatus); // Lock serial message queue @@ -646,7 +651,7 @@ void PadMgr_HandleRetrace(void) { } // Rumble Pak - if (gFaultMgr.msgId != 0) { + if (/*gFaultMgr.msgId != 0*/ 0) { // If fault is active, no rumble PadMgr_RumbleStop(); } else if (sPadMgrInstance->rumbleOffTimer > 0) { @@ -734,6 +739,7 @@ void PadMgr_GetInput2(Input* inputs, s32 gameRequest) { } void PadMgr_ThreadEntry() { +#if 1 s16* interruptMsg = NULL; s32 actionBits; s32 exit; @@ -745,6 +751,7 @@ void PadMgr_ThreadEntry() { actionBits = 0; exit = false; + /* while (!exit) { // Process all messages currently in the queue, instead of only a single mssage. // Deduplicates the same message. @@ -764,23 +771,27 @@ void PadMgr_ThreadEntry() { break; } } while (!MQ_IS_EMPTY(&sPadMgrInstance->interruptQueue)); + */ - // Act on received messages - while (actionBits != 0) { - if (actionBits & PADMGR_NMI_MSG) { - actionBits &= ~PADMGR_NMI_MSG; - exit = true; - } else if (actionBits & PADMGR_PRE_NMI_MSG) { - actionBits &= ~PADMGR_PRE_NMI_MSG; - PadMgr_HandlePreNMI(); - } else if (actionBits & PADMGR_RETRACE_MSG) { - actionBits &= ~PADMGR_RETRACE_MSG; - PadMgr_HandleRetrace(); - } + PadMgr_HandleRetrace(); + + // Act on received messages + while (actionBits != 0) { + if (actionBits & PADMGR_NMI_MSG) { + actionBits &= ~PADMGR_NMI_MSG; + exit = true; + } else if (actionBits & PADMGR_PRE_NMI_MSG) { + actionBits &= ~PADMGR_PRE_NMI_MSG; + PadMgr_HandlePreNMI(); + } else if (actionBits & PADMGR_RETRACE_MSG) { + actionBits &= ~PADMGR_RETRACE_MSG; + PadMgr_HandleRetrace(); } } +//} - IrqMgr_RemoveClient(sPadMgrInstance->irqMgr, &sPadMgrInstance->irqClient); +// IrqMgr_RemoveClient(sPadMgrInstance->irqMgr, &sPadMgrInstance->irqClient); +#endif } void PadMgr_Init(OSMesgQueue* siEvtQ, IrqMgr* irqMgr, OSId threadId, OSPri pri, void* stack) { @@ -797,6 +808,6 @@ void PadMgr_Init(OSMesgQueue* siEvtQ, IrqMgr* irqMgr, OSId threadId, OSPri pri, osContSetCh(sPadMgrInstance->nControllers); PadMgr_ReleaseSerialEventQueue(siEvtQ); - osCreateThread(&sPadMgrInstance->thread, threadId, PadMgr_ThreadEntry, sPadMgrInstance, stack, pri); - osStartThread(&sPadMgrInstance->thread); + // osCreateThread(&sPadMgrInstance->thread, threadId, PadMgr_ThreadEntry, sPadMgrInstance, stack, pri); + // osStartThread(&sPadMgrInstance->thread); } diff --git a/mm/src/code/sched.c b/mm/src/code/sched.c index c7fb5a495..d2e798161 100644 --- a/mm/src/code/sched.c +++ b/mm/src/code/sched.c @@ -97,7 +97,7 @@ void Sched_HandleAudioCancel(SchedContext* sched) { } send_mesg: - osSendMesg(&sched->interruptQ, (OSMesg)RSP_DONE_MSG, OS_MESG_NOBLOCK); + osSendMesg(&sched->interruptQ, OS_MESG_32(RSP_DONE_MSG), OS_MESG_NOBLOCK); return; } @@ -131,6 +131,7 @@ void Sched_HandleAudioCancel(SchedContext* sched) { * an RDP_DONE_MSG back to itself. */ void Sched_HandleGfxCancel(SchedContext* sched) { + #if 0 s32 i; // GRAPH SP Cancel @@ -160,7 +161,7 @@ void Sched_HandleGfxCancel(SchedContext* sched) { } send_mesg: - osSendMesg(&sched->interruptQ, (OSMesg)RSP_DONE_MSG, OS_MESG_NOBLOCK); + osSendMesg(&sched->interruptQ, OS_MESG_PTR(RSP_DONE_MSG), OS_MESG_NOBLOCK); goto halt_rdp; } @@ -192,6 +193,7 @@ halt_rdp: osSendMesg(&sched->interruptQ, (OSMesg)RDP_DONE_MSG, OS_MESG_NOBLOCK); } } + #endif } /** @@ -348,8 +350,8 @@ void Sched_RunTask(SchedContext* sched, OSScTask* spTask, OSScTask* dpTask) { if (spTask->list.t.type == M_AUDTASK) { // Set global pointers to audio task data for use in audio processing - gAudioSPDataPtr = spTask->list.t.dataPtr; - gAudioSPDataSize = spTask->list.t.dataSize; + gAudioSPDataPtr = spTask->list.t.data_ptr; + gAudioSPDataSize = spTask->list.t.data_size; } // Begin task execution @@ -366,6 +368,7 @@ void Sched_RunTask(SchedContext* sched, OSScTask* spTask, OSScTask* dpTask) { * Enqueues any tasks that have been sent to the scheduler down the command queue. */ void Sched_HandleEntry(SchedContext* sched) { + #if 0 OSScTask* spTask = NULL; OSScTask* dpTask = NULL; OSMesg msg = NULL; @@ -385,6 +388,7 @@ void Sched_HandleEntry(SchedContext* sched) { if (Sched_Schedule(sched, &spTask, &dpTask, state) != state) { Sched_RunTask(sched, spTask, dpTask); } + #endif } void Sched_HandleRetrace(SchedContext* sched) { @@ -505,7 +509,7 @@ void Sched_HandleRDPDone(SchedContext* sched) { * been sent down the command queue. */ void Sched_SendEntryMsg(SchedContext* sched) { - osSendMesg(&sched->interruptQ, (OSMesg)ENTRY_MSG, OS_MESG_BLOCK); + osSendMesg(&sched->interruptQ, OS_MESG_32(ENTRY_MSG), OS_MESG_BLOCK); } /** @@ -513,7 +517,7 @@ void Sched_SendEntryMsg(SchedContext* sched) { * to stop the last dispatched audio task. */ void Sched_SendAudioCancelMsg(SchedContext* sched) { - osSendMesg(&sched->interruptQ, (OSMesg)RDP_AUDIO_CANCEL_MSG, OS_MESG_BLOCK); + osSendMesg(&sched->interruptQ, OS_MESG_32(RDP_AUDIO_CANCEL_MSG), OS_MESG_BLOCK); } /** @@ -521,7 +525,7 @@ void Sched_SendAudioCancelMsg(SchedContext* sched) { * to stop the last dispatched gfx task. */ void Sched_SendGfxCancelMsg(SchedContext* sched) { - osSendMesg(&sched->interruptQ, (OSMesg)RSP_GFX_CANCEL_MSG, OS_MESG_BLOCK); + osSendMesg(&sched->interruptQ, OS_MESG_32(RSP_GFX_CANCEL_MSG), OS_MESG_BLOCK); } /** @@ -541,7 +545,7 @@ void Sched_FaultClient(void* param1, void* param2) { spTask = sched->curRSPTask; if (spTask != NULL) { FaultDrawer_Printf("RSPTask %08x %08x %02x %02x\n%01x %08x %08x\n", spTask, spTask->next, spTask->state, - spTask->flags, spTask->list.t.type, spTask->list.t.dataPtr, spTask->list.t.dataSize); + spTask->flags, spTask->list.t.type, spTask->list.t.data_ptr, spTask->list.t.data_size); } dpTask = sched->curRDPTask; @@ -556,14 +560,14 @@ void Sched_FaultClient(void* param1, void* param2) { * threads or the OS. */ void Sched_ThreadEntry(void* arg) { - s32 msg = 0; + OSMesg msg = OS_MESG_PTR(NULL);; SchedContext* sched = (SchedContext*)arg; while (true) { - osRecvMesg(&sched->interruptQ, (OSMesg*)&msg, OS_MESG_BLOCK); + osRecvMesg(&sched->interruptQ, &msg, OS_MESG_BLOCK); // Check if it's a message from another thread or the OS - switch (msg) { + switch ((s32)msg.data32) { case RDP_AUDIO_CANCEL_MSG: Sched_HandleAudioCancel(sched); continue; @@ -584,9 +588,8 @@ void Sched_ThreadEntry(void* arg) { Sched_HandleRDPDone(sched); continue; } - // Check if it's a message from the IrqMgr - switch (((OSScMsg*)msg)->type) { + switch (((OSScMsg*)msg.data32)->type) { case OS_SC_RETRACE_MSG: Sched_HandleRetrace(sched); continue; @@ -614,8 +617,8 @@ void Sched_Init(SchedContext* sched, void* stack, OSPri pri, u8 viModeType, UNK_ osCreateMesgQueue(&sched->interruptQ, sched->intBuf, ARRAY_COUNT(sched->intBuf)); osCreateMesgQueue(&sched->cmdQ, sched->cmdMsgBuf, ARRAY_COUNT(sched->cmdMsgBuf)); - osSetEventMesg(OS_EVENT_SP, &sched->interruptQ, (OSMesg)RSP_DONE_MSG); - osSetEventMesg(OS_EVENT_DP, &sched->interruptQ, (OSMesg)RDP_DONE_MSG); + osSetEventMesg(OS_EVENT_SP, &sched->interruptQ, OS_MESG_32(RSP_DONE_MSG)); + osSetEventMesg(OS_EVENT_DP, &sched->interruptQ, OS_MESG_32(RDP_DONE_MSG)); IrqMgr_AddClient(irqMgr, &sched->irqClient, &sched->interruptQ); Fault_AddClient(&sSchedFaultClient, Sched_FaultClient, sched, NULL); osCreateThread(&sched->thread, Z_THREAD_ID_SCHED, Sched_ThreadEntry, sched, stack, pri); diff --git a/mm/src/code/stubs.c b/mm/src/code/stubs.c new file mode 100644 index 000000000..19c2d7a2c --- /dev/null +++ b/mm/src/code/stubs.c @@ -0,0 +1,1107 @@ +#include +#include +#include "z64.h" +#include +//#include + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 +#define SCREEN_WIDTH_HIRES 640 +#define SCREEN_HEIGHT_HIRES 480 + +#define HIRES_BUFFER_WIDTH 576 +#define HIRES_BUFFER_HEIGHT 454 + +s32 osResetType; + +// AudioContext gAudioContext; +// unk_D_8016E750 D_8016E750[4]; +u8 gLetterTLUT[4][32]; +u8 gFontFF[999]; +DmaEntry dmadata[1568]; +// u8 D_80133418; +u16 gAudioSEFlagSwapSource[64]; +u16 gAudioSEFlagSwapTarget[64]; +u8 gAudioSEFlagSwapMode[64]; + +s32 osAppNMIBuffer[8]; + +f32 qNaN0x10000 = 0x7F810000; + +u16 gFramebuffer1[SCREEN_HEIGHT][SCREEN_WIDTH]; // at 0x80000500 +u16 gFramebuffer0[SCREEN_HEIGHT][SCREEN_WIDTH]; + +u16 gFramebufferHiRes0[HIRES_BUFFER_WIDTH][HIRES_BUFFER_HEIGHT]; +u16 gFramebufferHiRes1[HIRES_BUFFER_WIDTH][HIRES_BUFFER_HEIGHT]; + +ActiveSequence gActiveSeqs[5]; +AudioContext gAudioCtx; +s32 D_801FD120; + +u8 gSoundFontTable[5]; +u8 gSequenceFontTable[5]; +u8 gSequenceTable[5]; +u8 gSampleBankTable[5]; + +AudioCustomUpdateFunction gAudioCustomUpdateFunction; +AudioCustomSeqFunction gAudioCustomSeqFunction; +AudioCustomReverbFunction gAudioCustomReverbFunction; +AudioCustomSynthFunction gAudioCustomSynthFunction; + +u64 aspMainTextStart[100]; +u64 aspMainDataStart[100]; +u64 aspMainDataEnd[100]; + +u8 sNumSeqRequests[5]; +u32 sAudioSeqCmds[0xB0]; +ActiveSequence gActiveSeqs[5]; +u8 sResetAudioHeapTimer; +u16 sResetAudioHeapFadeReverbVolume; +u16 sResetAudioHeapFadeReverbVolumeStep; + +u8 D_801D6200[0x400]; +SeqRequest sSeqRequests[5][5]; + +u8 D_80025D00[100]; + +GfxMasterList D_0E000000; +Mtx D_01000000; +u16 D_0F000000[SCREEN_WIDTH * SCREEN_HEIGHT]; + +u64 gspS2DEX_fifoTextStart[1], gspS2DEX_fifoTextEnd[1]; +u64 gspS2DEX_fifoDataStart[1], gspS2DEX_fifoDataEnd[1]; +u64 gspS2DEX_fifo_dTextStart[1], gspS2DEX_fifo_dTextEnd[1]; +u64 gspS2DEX_fifo_dDataStart[1], gspS2DEX_fifo_dDataEnd[1]; +u64 gspS2DEX2_fifoTextStart[1], gspS2DEX2_fifoTextEnd[1]; +u64 gspS2DEX2_fifoDataStart[1], gspS2DEX2_fifoDataEnd[1]; +u64 gspS2DEX2_xbusTextStart[1], gspS2DEX2_xbusTextEnd[1]; +u64 gspS2DEX2_xbusDataStart[1], gspS2DEX2_xbusDataEnd[1]; +u64 gspF3DZEX2_NoN_PosLight_fifoTextStart[1]; +u64 gspF3DZEX2_NoN_PosLight_fifoTextEnd[1]; +u64 gspF3DZEX2_NoN_PosLight_fifoDataStart[1]; +u64 gspF3DZEX2_NoN_PosLight_fifoDataEnd[1]; + +Vec3f gZeroVec3f; +Vec3s gZeroVec3s; + +u64 rspbootTextStart[1]; +u64 rspbootTextEnd[1]; + +u64 njpgdspMainTextStart[1]; +u64 njpgdspMainDataStart[1]; + +Mtx gMtxClear; + +TexturePtr gCircleTex[] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000001, 0x23344555, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00124567, 0x89AABBCC, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x4679ABDE, + 0xEFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00002478, 0xACEFFFFF, 0xFFFFFFFF, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01468BDE, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x57ACEFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000258, 0xBDFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x000258BE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x0148BEFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x36ADFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x00000015, 0x8CFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x0000037A, 0xEFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000, 0x000048CF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x00000000, 0x00000000, 0x00000000, 0x00159DFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, + 0x00000000, 0x00000000, 0x026AEFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, + 0x00000000, 0x27BFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000003, + 0x7BFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000037, 0xCFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x0000037C, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x000027CF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00027BFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x00000000, 0x00000000, 0x0016BFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x00000000, 0x00000000, 0x005AFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, + 0x00000000, 0x049EFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, + 0x38DFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000001, 0x7CFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000005, 0xAFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000038, 0xEFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x0000016C, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x000004AF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x00000000, 0x000027DF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x00000000, 0x00005BFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, + 0x00028EFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x0005BFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x0028EFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x005BFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x017DFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x04AFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x06CFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x00000000, 0x28EFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x00000000, 0x4AFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000001, + 0x7DFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000002, 0x8EFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000004, 0xAFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000006, 0xCFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000017, 0xEFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000029, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x0000004A, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x0000005B, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x0000006D, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000017E, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000028E, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0000039F, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000003AF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000004AF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x000004BF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0x000005BF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0x000005CF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0x000005CF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + }; + +u8 gPlayerFormItemRestrictions[PLAYER_FORM_MAX][114] /*= { + {0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x01,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x01,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x01,0x01}, +{0x01,0x00,0x00,0x00}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x01,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x01,0x01,0x00}, +{0x00,0x00,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x01,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x01}, +{0x00,0x00,0x00,0x01}, +{0x01,0x00,0x00,0x00}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x00,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x01,0x01,0x01}, +{0x01,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00}, +}*/; + +u8 gPictoPhotoI8[PICTO_PHOTO_SIZE]; +u8 D_80784600[0x56200]; + +OSPiHandle* __osPiTable; +OSPiHandle* __osCurrentHandle[5]; +void* osRomBase; + +__osHwInt __osHwIntTable[1]; + +OSIntMask osSetIntMask(OSIntMask a) { + return 0; +} + +s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel) { +} + +s32 osSetRumble(OSPfs* pfs, u32 vibrate) { + return 0; +} + +void osWritebackDCache(void* vaddr, s32 nbytes) { +} + +void osInvalICache(void* vaddr, size_t nbytes) { +} + +u32 __osGetFpcCsr() { + return 0; +} + +u32 __osSetFpcCsr(u32 a0) { + return 0; +} + +OSIntMask __osDisableInt(void) { +} + +void __osRestoreInt(OSIntMask a0) { +} + +OSPiHandle* osCartRomInit(void) { + return NULL; +} + +u32 osMemSize = 1024 * 1024 * 1024; + +void Audio_osInvalDCache(void* buf, s32 size) { +} + +void Audio_osWritebackDCache(void* mem, s32 size) { +} + +void osInvalDCache(void* vaddr, size_t nbytes) { +} + +void osWritebackDCacheAll(void) { +} + +void Audio_SetBGM(u32 bgmId) { +} + +OSPiHandle* osDriveRomInit() { +} + +void osSetUpMempakWrite(s32 channel, OSPifRam* buf) { +} + +void osUnmapTLBAll(void) { + +} + +#ifndef __GNUC__ +void bzero(void* src, int length) { + memset(src, 0, length); +} + +void bcopy(void* __src, void* __dest, int __n) { + memcpy(__dest, __src, __n); +} +int bcmp(void* __s1, void* __s2, int __n) { + return memcmp(__s1, __s2, __n); +} +#endif +int ResourceMgr_OTRSigCheck(char* imgData); +char* ResourceMgr_LoadTexOrDListByName(char* data); + +void gSPSegment(void* value, int segNum, uintptr_t target) { + char* imgData = (char*)target; + + int res = ResourceMgr_OTRSigCheck(imgData); + + // OTRTODO: Disabled for now to fix an issue with HD Textures. + // With HD textures, we need to pass the path to F3D, not the raw texture data. + // Otherwise the needed metadata is not available for proper rendering... + // This should *not* cause any crashes, but some testing may be needed... + // UPDATE: To maintain compatability it will still do the old behavior if the resource is a display list. + // That should not affect HD textures. + if (res) { + uintptr_t desiredTarget = (uintptr_t)ResourceMgr_LoadIfDListByName(imgData); + + if (desiredTarget != NULL) + target = desiredTarget; + } + + __gSPSegment(value, segNum, target); +} + +void gSPSegmentLoadRes(void* value, int segNum, uintptr_t target) { + char* imgData = (char*)target; + + int res = ResourceMgr_OTRSigCheck(imgData); + + if (res) { + target = (uintptr_t)ResourceMgr_LoadTexOrDListByName(imgData); + } + + __gSPSegment(value, segNum, target); +} + +void gDPSetTextureImage(Gfx* pkt, u32 format, u32 size, u32 width, uintptr_t i) { + __gDPSetTextureImage(pkt, format, size, width, i); +} + +void gDPSetTextureImageFB(Gfx* pkt, u32 format, u32 size, u32 width, int fb) { + __gDPSetTextureImageFB(pkt, format, size, width, fb); +} + +void gSPDisplayList(Gfx* pkt, Gfx* dl) { + char* imgData = (char*)dl; + + if (ResourceMgr_OTRSigCheck(imgData) == 1) { + + // ResourceMgr_PushCurrentDirectory(imgData); + // gsSPPushCD(pkt++, imgData); + dl = ResourceMgr_LoadGfxByName(imgData); + } + + __gSPDisplayList(pkt, dl); +} + +void gSPDisplayListOffset(Gfx* pkt, Gfx* dl, int offset) { + char* imgData = (char*)dl; + + if (ResourceMgr_OTRSigCheck(imgData) == 1) + dl = ResourceMgr_LoadGfxByName(imgData); + + __gSPDisplayList(pkt, dl + offset); +} + +void gSPVertex(Gfx* pkt, uintptr_t v, int n, int v0) { + if (ResourceMgr_OTRSigCheck((char*)v) == 1) + v = (uintptr_t)ResourceMgr_LoadVtxByName((char*)v); + + __gSPVertex(pkt, v, n, v0); +} + +void gSPInvalidateTexCache(Gfx* pkt, uintptr_t texAddr) { + char* imgData = (char*)texAddr; + + if (texAddr != 0 && ResourceMgr_OTRSigCheck(imgData)) { + // Temporary solution to the mq/nonmq issue, this will be + // handled better with LUS 1.0 + texAddr = (uintptr_t)ResourceMgr_LoadTexOrDListByName(imgData); + } + + __gSPInvalidateTexCache(pkt, texAddr); +} +void func_801A1290(void) { + +} + +void func_801A1904(void) { + +} + +void func_801A1E0C(void) { + +} + +void func_801A2090(void) { + +} + +void func_801A312C(void) { + +} + +void func_801A3AC0(void) { + +} + +void func_801A1FB4(u8 playerIndex, Vec3f* pos, u16 seqId, f32 maxDist) { + +} + +void func_801A3A7C(s32 arg0) { + +} + +void func_801A3CD8(s8 param_1) { + +} +void func_801A3CF4(s8 arg0) { +} +void func_801A3D98(s8 audioSetting) { +} +void func_801A3E38(u8 arg0) { +} +void func_801A3EC0(u8 arg0) { +} +void func_801A4058(UNK_TYPE arg0) { +} +void func_801A41C8(s32 arg0) { +} +void func_801A41F8(UNK_TYPE arg0) { +} +void func_801A3000(u16 seqId, u8 ioData) { +} +u16 func_801A5100(void) { +} +void __osDispatchThread(void) { +} + +u32 __osGetCause(void) { +} +void __osSetCause(u32 p) { +} +u32 __osGetCompare(void) { +} +void __osSetCompare(u32 value) { +} +u32 __osGetConfig(void) { +} +void __osSetConfig(u32 p) { +} +u32 __osGetSR(void) { +} +void __osSetSR(u32 value) { +} + +u32 __osGetWatchLo(void) { +} +void __osSetWatchLo(u32 value) { +} + +void __osEnqueueAndYield(OSThread** param_1) { +} +void __osEnqueueThread(OSThread** param_1, OSThread* param_2) { +} +OSThread* __osPopThread(OSThread** param_1) { +} +void osMapTLBRdb(void) { +} +u32 __osProbeTLB(void* param_1) { +} +void func_801A31EC(u16 seqId, s8 arg1, u8 arg2) { +} +s32 osAiSetFrequency(u32 frequency) { +} +s32 osContStartQuery(OSMesgQueue* mq) { +} +void osCreateThread(void* a, u32 b, void* c, void* d) { +} +void osGetThreadPri(void* a) { +} +void osContGetQuery(OSContStatus* data) { +} +void osStartThread(OSThread* thread) { +} +void osViSwapBuffer(void* vaddr) { +} +void osViSetMode(OSViMode* mode) { +} +void osViSetSpecialFeatures(u32 func) { +} +void __osInitialize_common(void) { +} +void __osInitialize_autodetect(void) { +} +void __osExceptionPreamble() { +} +void __osCleanupThread(void) { +} +void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg msg) { +} +void osDestroyThread(OSThread* thread) { +} +s32 __osMotorAccess(OSPfs* pfs, u32 vibrate) { +} +s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel) { + return 0; +} +s32 osContSetCh(u8 ch) { +} +void osViSetYScale(f32 scale) { +} +void osViSetXScale(f32 value) { +} +void osSpTaskYield(void) { +} +u32* osViGetCurrentFramebuffer(void) { +} +OSPiHandle* osFlashInit(void) { +} +void osFlashReadId(u32* t, u32* v) { +} +s32 osFlashSectorErase(u32 page) { +} +s32 osFlashWriteBuffer(OSIoMesg* mb, s32 priority, void* dramAddr, OSMesgQueue* mq) { +} +s32 osFlashWriteArray(u32 pageNum) { +} +s32 osFlashReadArray(OSIoMesg* mb, s32 priority, u32 pageNum, void* dramAddr, u32 pageCount, OSMesgQueue* mq) { +} +void osFlashChange(u32 flashNum) { +} +void osFlashAllEraseThrough(void) { +} +void osFlashSectorEraseThrough(u32 pageNum) { +} +s32 osFlashCheckEraseEnd(void) { +} +void osSetThreadPri(OSThread* thread, OSPri p) { +} +void guS2DInitBg(uObjBg* bg) { + u32 size; + s32 tmem = (bg->b.imageFmt == G_IM_FMT_CI) ? 0x100 : 0x200; + u16 shift = (6 - bg->b.imageSiz); + + if (bg->b.imageLoad == G_BGLT_LOADBLOCK) { + bg->b.tmemW = bg->b.imageW >> shift; + bg->b.tmemH = (tmem / bg->b.tmemW) * 4; + bg->b.tmemSizeW = bg->b.tmemW * 2; + bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemLoadSH = (bg->b.tmemSize >> 1) - 1; + bg->b.tmemLoadTH = (0x7FF / bg->b.tmemW) + 1; + } else { // G_BGLT_LOADTILE + bg->b.tmemW = (bg->b.frameW >> shift) + 3; + bg->b.tmemH = (tmem / bg->b.tmemW) * 4; + bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; + + size = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemSize = (size >> 16); + bg->b.tmemLoadSH = (size >> 0) & 0xFFFF; + bg->b.tmemLoadTH = bg->b.tmemH - 1; + } +} +void* osViGetNextFramebuffer() { +} +OSYieldResult osSpTaskYielded(OSTask* task) { +} +void osViBlack(u8 active) { +} +static s16 sintable[0x400] = { + 0x0000, 0x0032, 0x0064, 0x0096, 0x00C9, 0x00FB, 0x012D, 0x0160, 0x0192, 0x01C4, 0x01F7, 0x0229, 0x025B, 0x028E, + 0x02C0, 0x02F2, 0x0324, 0x0357, 0x0389, 0x03BB, 0x03EE, 0x0420, 0x0452, 0x0484, 0x04B7, 0x04E9, 0x051B, 0x054E, + 0x0580, 0x05B2, 0x05E4, 0x0617, 0x0649, 0x067B, 0x06AD, 0x06E0, 0x0712, 0x0744, 0x0776, 0x07A9, 0x07DB, 0x080D, + 0x083F, 0x0871, 0x08A4, 0x08D6, 0x0908, 0x093A, 0x096C, 0x099F, 0x09D1, 0x0A03, 0x0A35, 0x0A67, 0x0A99, 0x0ACB, + 0x0AFE, 0x0B30, 0x0B62, 0x0B94, 0x0BC6, 0x0BF8, 0x0C2A, 0x0C5C, 0x0C8E, 0x0CC0, 0x0CF2, 0x0D25, 0x0D57, 0x0D89, + 0x0DBB, 0x0DED, 0x0E1F, 0x0E51, 0x0E83, 0x0EB5, 0x0EE7, 0x0F19, 0x0F4B, 0x0F7C, 0x0FAE, 0x0FE0, 0x1012, 0x1044, + 0x1076, 0x10A8, 0x10DA, 0x110C, 0x113E, 0x116F, 0x11A1, 0x11D3, 0x1205, 0x1237, 0x1269, 0x129A, 0x12CC, 0x12FE, + 0x1330, 0x1361, 0x1393, 0x13C5, 0x13F6, 0x1428, 0x145A, 0x148C, 0x14BD, 0x14EF, 0x1520, 0x1552, 0x1584, 0x15B5, + 0x15E7, 0x1618, 0x164A, 0x167B, 0x16AD, 0x16DF, 0x1710, 0x1741, 0x1773, 0x17A4, 0x17D6, 0x1807, 0x1839, 0x186A, + 0x189B, 0x18CD, 0x18FE, 0x1930, 0x1961, 0x1992, 0x19C3, 0x19F5, 0x1A26, 0x1A57, 0x1A88, 0x1ABA, 0x1AEB, 0x1B1C, + 0x1B4D, 0x1B7E, 0x1BAF, 0x1BE1, 0x1C12, 0x1C43, 0x1C74, 0x1CA5, 0x1CD6, 0x1D07, 0x1D38, 0x1D69, 0x1D9A, 0x1DCB, + 0x1DFC, 0x1E2D, 0x1E5D, 0x1E8E, 0x1EBF, 0x1EF0, 0x1F21, 0x1F52, 0x1F82, 0x1FB3, 0x1FE4, 0x2015, 0x2045, 0x2076, + 0x20A7, 0x20D7, 0x2108, 0x2139, 0x2169, 0x219A, 0x21CA, 0x21FB, 0x222B, 0x225C, 0x228C, 0x22BD, 0x22ED, 0x231D, + 0x234E, 0x237E, 0x23AE, 0x23DF, 0x240F, 0x243F, 0x2470, 0x24A0, 0x24D0, 0x2500, 0x2530, 0x2560, 0x2591, 0x25C1, + 0x25F1, 0x2621, 0x2651, 0x2681, 0x26B1, 0x26E1, 0x2711, 0x2740, 0x2770, 0x27A0, 0x27D0, 0x2800, 0x2830, 0x285F, + 0x288F, 0x28BF, 0x28EE, 0x291E, 0x294E, 0x297D, 0x29AD, 0x29DD, 0x2A0C, 0x2A3C, 0x2A6B, 0x2A9B, 0x2ACA, 0x2AF9, + 0x2B29, 0x2B58, 0x2B87, 0x2BB7, 0x2BE6, 0x2C15, 0x2C44, 0x2C74, 0x2CA3, 0x2CD2, 0x2D01, 0x2D30, 0x2D5F, 0x2D8E, + 0x2DBD, 0x2DEC, 0x2E1B, 0x2E4A, 0x2E79, 0x2EA8, 0x2ED7, 0x2F06, 0x2F34, 0x2F63, 0x2F92, 0x2FC0, 0x2FEF, 0x301E, + 0x304C, 0x307B, 0x30A9, 0x30D8, 0x3107, 0x3135, 0x3163, 0x3192, 0x31C0, 0x31EF, 0x321D, 0x324B, 0x3279, 0x32A8, + 0x32D6, 0x3304, 0x3332, 0x3360, 0x338E, 0x33BC, 0x33EA, 0x3418, 0x3446, 0x3474, 0x34A2, 0x34D0, 0x34FE, 0x352B, + 0x3559, 0x3587, 0x35B5, 0x35E2, 0x3610, 0x363D, 0x366B, 0x3698, 0x36C6, 0x36F3, 0x3721, 0x374E, 0x377C, 0x37A9, + 0x37D6, 0x3803, 0x3831, 0x385E, 0x388B, 0x38B8, 0x38E5, 0x3912, 0x393F, 0x396C, 0x3999, 0x39C6, 0x39F3, 0x3A20, + 0x3A4D, 0x3A79, 0x3AA6, 0x3AD3, 0x3B00, 0x3B2C, 0x3B59, 0x3B85, 0x3BB2, 0x3BDE, 0x3C0B, 0x3C37, 0x3C64, 0x3C90, + 0x3CBC, 0x3CE9, 0x3D15, 0x3D41, 0x3D6D, 0x3D99, 0x3DC5, 0x3DF1, 0x3E1D, 0x3E49, 0x3E75, 0x3EA1, 0x3ECD, 0x3EF9, + 0x3F25, 0x3F50, 0x3F7C, 0x3FA8, 0x3FD3, 0x3FFF, 0x402B, 0x4056, 0x4082, 0x40AD, 0x40D8, 0x4104, 0x412F, 0x415A, + 0x4186, 0x41B1, 0x41DC, 0x4207, 0x4232, 0x425D, 0x4288, 0x42B3, 0x42DE, 0x4309, 0x4334, 0x435F, 0x4389, 0x43B4, + 0x43DF, 0x4409, 0x4434, 0x445F, 0x4489, 0x44B4, 0x44DE, 0x4508, 0x4533, 0x455D, 0x4587, 0x45B1, 0x45DC, 0x4606, + 0x4630, 0x465A, 0x4684, 0x46AE, 0x46D8, 0x4702, 0x472C, 0x4755, 0x477F, 0x47A9, 0x47D2, 0x47FC, 0x4826, 0x484F, + 0x4879, 0x48A2, 0x48CC, 0x48F5, 0x491E, 0x4948, 0x4971, 0x499A, 0x49C3, 0x49EC, 0x4A15, 0x4A3E, 0x4A67, 0x4A90, + 0x4AB9, 0x4AE2, 0x4B0B, 0x4B33, 0x4B5C, 0x4B85, 0x4BAD, 0x4BD6, 0x4BFE, 0x4C27, 0x4C4F, 0x4C78, 0x4CA0, 0x4CC8, + 0x4CF0, 0x4D19, 0x4D41, 0x4D69, 0x4D91, 0x4DB9, 0x4DE1, 0x4E09, 0x4E31, 0x4E58, 0x4E80, 0x4EA8, 0x4ED0, 0x4EF7, + 0x4F1F, 0x4F46, 0x4F6E, 0x4F95, 0x4FBD, 0x4FE4, 0x500B, 0x5032, 0x505A, 0x5081, 0x50A8, 0x50CF, 0x50F6, 0x511D, + 0x5144, 0x516B, 0x5191, 0x51B8, 0x51DF, 0x5205, 0x522C, 0x5253, 0x5279, 0x52A0, 0x52C6, 0x52EC, 0x5313, 0x5339, + 0x535F, 0x5385, 0x53AB, 0x53D1, 0x53F7, 0x541D, 0x5443, 0x5469, 0x548F, 0x54B5, 0x54DA, 0x5500, 0x5525, 0x554B, + 0x5571, 0x5596, 0x55BB, 0x55E1, 0x5606, 0x562B, 0x5650, 0x5675, 0x569B, 0x56C0, 0x56E5, 0x5709, 0x572E, 0x5753, + 0x5778, 0x579D, 0x57C1, 0x57E6, 0x580A, 0x582F, 0x5853, 0x5878, 0x589C, 0x58C0, 0x58E5, 0x5909, 0x592D, 0x5951, + 0x5975, 0x5999, 0x59BD, 0x59E1, 0x5A04, 0x5A28, 0x5A4C, 0x5A6F, 0x5A93, 0x5AB7, 0x5ADA, 0x5AFD, 0x5B21, 0x5B44, + 0x5B67, 0x5B8B, 0x5BAE, 0x5BD1, 0x5BF4, 0x5C17, 0x5C3A, 0x5C5D, 0x5C7F, 0x5CA2, 0x5CC5, 0x5CE7, 0x5D0A, 0x5D2D, + 0x5D4F, 0x5D71, 0x5D94, 0x5DB6, 0x5DD8, 0x5DFA, 0x5E1D, 0x5E3F, 0x5E61, 0x5E83, 0x5EA5, 0x5EC6, 0x5EE8, 0x5F0A, + 0x5F2C, 0x5F4D, 0x5F6F, 0x5F90, 0x5FB2, 0x5FD3, 0x5FF4, 0x6016, 0x6037, 0x6058, 0x6079, 0x609A, 0x60BB, 0x60DC, + 0x60FD, 0x611E, 0x613E, 0x615F, 0x6180, 0x61A0, 0x61C1, 0x61E1, 0x6202, 0x6222, 0x6242, 0x6263, 0x6283, 0x62A3, + 0x62C3, 0x62E3, 0x6303, 0x6323, 0x6342, 0x6362, 0x6382, 0x63A1, 0x63C1, 0x63E0, 0x6400, 0x641F, 0x643F, 0x645E, + 0x647D, 0x649C, 0x64BB, 0x64DA, 0x64F9, 0x6518, 0x6537, 0x6556, 0x6574, 0x6593, 0x65B2, 0x65D0, 0x65EF, 0x660D, + 0x662B, 0x664A, 0x6668, 0x6686, 0x66A4, 0x66C2, 0x66E0, 0x66FE, 0x671C, 0x673A, 0x6757, 0x6775, 0x6792, 0x67B0, + 0x67CD, 0x67EB, 0x6808, 0x6825, 0x6843, 0x6860, 0x687D, 0x689A, 0x68B7, 0x68D4, 0x68F1, 0x690D, 0x692A, 0x6947, + 0x6963, 0x6980, 0x699C, 0x69B9, 0x69D5, 0x69F1, 0x6A0E, 0x6A2A, 0x6A46, 0x6A62, 0x6A7E, 0x6A9A, 0x6AB5, 0x6AD1, + 0x6AED, 0x6B08, 0x6B24, 0x6B40, 0x6B5B, 0x6B76, 0x6B92, 0x6BAD, 0x6BC8, 0x6BE3, 0x6BFE, 0x6C19, 0x6C34, 0x6C4F, + 0x6C6A, 0x6C84, 0x6C9F, 0x6CBA, 0x6CD4, 0x6CEF, 0x6D09, 0x6D23, 0x6D3E, 0x6D58, 0x6D72, 0x6D8C, 0x6DA6, 0x6DC0, + 0x6DDA, 0x6DF3, 0x6E0D, 0x6E27, 0x6E40, 0x6E5A, 0x6E73, 0x6E8D, 0x6EA6, 0x6EBF, 0x6ED9, 0x6EF2, 0x6F0B, 0x6F24, + 0x6F3D, 0x6F55, 0x6F6E, 0x6F87, 0x6FA0, 0x6FB8, 0x6FD1, 0x6FE9, 0x7002, 0x701A, 0x7032, 0x704A, 0x7062, 0x707A, + 0x7092, 0x70AA, 0x70C2, 0x70DA, 0x70F2, 0x7109, 0x7121, 0x7138, 0x7150, 0x7167, 0x717E, 0x7196, 0x71AD, 0x71C4, + 0x71DB, 0x71F2, 0x7209, 0x7220, 0x7236, 0x724D, 0x7264, 0x727A, 0x7291, 0x72A7, 0x72BD, 0x72D4, 0x72EA, 0x7300, + 0x7316, 0x732C, 0x7342, 0x7358, 0x736E, 0x7383, 0x7399, 0x73AE, 0x73C4, 0x73D9, 0x73EF, 0x7404, 0x7419, 0x742E, + 0x7443, 0x7458, 0x746D, 0x7482, 0x7497, 0x74AC, 0x74C0, 0x74D5, 0x74EA, 0x74FE, 0x7512, 0x7527, 0x753B, 0x754F, + 0x7563, 0x7577, 0x758B, 0x759F, 0x75B3, 0x75C7, 0x75DA, 0x75EE, 0x7601, 0x7615, 0x7628, 0x763B, 0x764F, 0x7662, + 0x7675, 0x7688, 0x769B, 0x76AE, 0x76C1, 0x76D3, 0x76E6, 0x76F9, 0x770B, 0x771E, 0x7730, 0x7742, 0x7754, 0x7767, + 0x7779, 0x778B, 0x779D, 0x77AF, 0x77C0, 0x77D2, 0x77E4, 0x77F5, 0x7807, 0x7818, 0x782A, 0x783B, 0x784C, 0x785D, + 0x786E, 0x787F, 0x7890, 0x78A1, 0x78B2, 0x78C3, 0x78D3, 0x78E4, 0x78F4, 0x7905, 0x7915, 0x7925, 0x7936, 0x7946, + 0x7956, 0x7966, 0x7976, 0x7985, 0x7995, 0x79A5, 0x79B5, 0x79C4, 0x79D4, 0x79E3, 0x79F2, 0x7A02, 0x7A11, 0x7A20, + 0x7A2F, 0x7A3E, 0x7A4D, 0x7A5B, 0x7A6A, 0x7A79, 0x7A87, 0x7A96, 0x7AA4, 0x7AB3, 0x7AC1, 0x7ACF, 0x7ADD, 0x7AEB, + 0x7AF9, 0x7B07, 0x7B15, 0x7B23, 0x7B31, 0x7B3E, 0x7B4C, 0x7B59, 0x7B67, 0x7B74, 0x7B81, 0x7B8E, 0x7B9B, 0x7BA8, + 0x7BB5, 0x7BC2, 0x7BCF, 0x7BDC, 0x7BE8, 0x7BF5, 0x7C02, 0x7C0E, 0x7C1A, 0x7C27, 0x7C33, 0x7C3F, 0x7C4B, 0x7C57, + 0x7C63, 0x7C6F, 0x7C7A, 0x7C86, 0x7C92, 0x7C9D, 0x7CA9, 0x7CB4, 0x7CBF, 0x7CCB, 0x7CD6, 0x7CE1, 0x7CEC, 0x7CF7, + 0x7D02, 0x7D0C, 0x7D17, 0x7D22, 0x7D2C, 0x7D37, 0x7D41, 0x7D4B, 0x7D56, 0x7D60, 0x7D6A, 0x7D74, 0x7D7E, 0x7D88, + 0x7D91, 0x7D9B, 0x7DA5, 0x7DAE, 0x7DB8, 0x7DC1, 0x7DCB, 0x7DD4, 0x7DDD, 0x7DE6, 0x7DEF, 0x7DF8, 0x7E01, 0x7E0A, + 0x7E13, 0x7E1B, 0x7E24, 0x7E2C, 0x7E35, 0x7E3D, 0x7E45, 0x7E4D, 0x7E56, 0x7E5E, 0x7E66, 0x7E6D, 0x7E75, 0x7E7D, + 0x7E85, 0x7E8C, 0x7E94, 0x7E9B, 0x7EA3, 0x7EAA, 0x7EB1, 0x7EB8, 0x7EBF, 0x7EC6, 0x7ECD, 0x7ED4, 0x7EDB, 0x7EE1, + 0x7EE8, 0x7EEE, 0x7EF5, 0x7EFB, 0x7F01, 0x7F08, 0x7F0E, 0x7F14, 0x7F1A, 0x7F20, 0x7F25, 0x7F2B, 0x7F31, 0x7F36, + 0x7F3C, 0x7F41, 0x7F47, 0x7F4C, 0x7F51, 0x7F56, 0x7F5B, 0x7F60, 0x7F65, 0x7F6A, 0x7F6F, 0x7F74, 0x7F78, 0x7F7D, + 0x7F81, 0x7F85, 0x7F8A, 0x7F8E, 0x7F92, 0x7F96, 0x7F9A, 0x7F9E, 0x7FA2, 0x7FA6, 0x7FA9, 0x7FAD, 0x7FB0, 0x7FB4, + 0x7FB7, 0x7FBA, 0x7FBE, 0x7FC1, 0x7FC4, 0x7FC7, 0x7FCA, 0x7FCC, 0x7FCF, 0x7FD2, 0x7FD4, 0x7FD7, 0x7FD9, 0x7FDC, + 0x7FDE, 0x7FE0, 0x7FE2, 0x7FE4, 0x7FE6, 0x7FE8, 0x7FEA, 0x7FEC, 0x7FED, 0x7FEF, 0x7FF1, 0x7FF2, 0x7FF3, 0x7FF5, + 0x7FF6, 0x7FF7, 0x7FF8, 0x7FF9, 0x7FFA, 0x7FFB, 0x7FFB, 0x7FFC, 0x7FFD, 0x7FFD, 0x7FFE, 0x7FFE, 0x7FFE, 0x7FFE, + 0x7FFE, 0x7FFF, +}; +s16 sins(u16 x) { + s16 value; + + x >>= 4; + + if (x & 0x400) { + value = sintable[0x3FF - (x & 0x3FF)]; + } else { + value = sintable[x & 0x3FF]; + } + + if (x & 0x800) { + return -value; + } else { + return value; + } +} +s16 coss(u16 angle) { + return sins(angle + 0x4000); +} +#define FTOFRAC8(x) ((s32)MIN(((x) * (128.0f)), 127.0f) & 0xff) + +/** + * guLookAtHiliteF + * This function creates the viewing matrix (floating point) and sets the LookAt/Hilite structures + **/ +void guLookAtHiliteF(f32 mf[4][4], LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, + f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, /* light 1 direction */ + f32 xl2, f32 yl2, f32 zl2, /* light 2 direction */ + s32 hiliteWidth, s32 hiliteHeight) /* size of hilite texture */ +{ + f32 length; + f32 xLook; + f32 yLook; + f32 zLook; + f32 xRight; + f32 yRight; + f32 zRight; + f32 xHilite; + f32 yHilite; + f32 zHilite; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + length = -1.0 / sqrtf(xLook * xLook + yLook * yLook + zLook * zLook); + xLook *= length; + yLook *= length; + zLook *= length; + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + length = 1.0 / sqrtf(xRight * xRight + yRight * yRight + zRight * zRight); + xRight *= length; + yRight *= length; + zRight *= length; + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + length = 1.0 / sqrtf(xUp * xUp + yUp * yUp + zUp * zUp); + xUp *= length; + yUp *= length; + zUp *= length; + + /* hilite vectors */ + + length = 1.0 / sqrtf(xl1 * xl1 + yl1 * yl1 + zl1 * zl1); + xl1 *= length; + yl1 *= length; + zl1 *= length; + + xHilite = xl1 + xLook; + yHilite = yl1 + yLook; + zHilite = zl1 + zLook; + + length = sqrtf(xHilite * xHilite + yHilite * yHilite + zHilite * zHilite); + + if (length > 0.1) { + length = 1.0 / length; + xHilite *= length; + yHilite *= length; + zHilite *= length; + + h->h.x1 = hiliteWidth * 4 + (xHilite * xRight + yHilite * yRight + zHilite * zRight) * hiliteWidth * 2; + + h->h.y1 = hiliteHeight * 4 + (xHilite * xUp + yHilite * yUp + zHilite * zUp) * hiliteHeight * 2; + } else { + h->h.x1 = hiliteWidth * 2; + h->h.y1 = hiliteHeight * 2; + } + + length = 1.0 / sqrtf(xl2 * xl2 + yl2 * yl2 + zl2 * zl2); + xl2 *= length; + yl2 *= length; + zl2 *= length; + + xHilite = xl2 + xLook; + yHilite = yl2 + yLook; + zHilite = zl2 + zLook; + length = sqrtf(xHilite * xHilite + yHilite * yHilite + zHilite * zHilite); + if (length > 0.1) { + length = 1.0 / length; + xHilite *= length; + yHilite *= length; + zHilite *= length; + + h->h.x2 = hiliteWidth * 4 + (xHilite * xRight + yHilite * yRight + zHilite * zRight) * hiliteWidth * 2; + + h->h.y2 = hiliteHeight * 4 + (xHilite * xUp + yHilite * yUp + zHilite * zUp) * hiliteHeight * 2; + } else { + h->h.x2 = hiliteWidth * 2; + h->h.y2 = hiliteHeight * 2; + } + + /* reflectance vectors = Up and Right */ + + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +/** + * guLookAtHilite + * This function creates the viewing matrix (fixed point) and sets the LookAt/Hilite structures + * Same args as previous function + **/ +void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, + f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 hiliteWidth, + s32 hiliteHeight) { + f32 mf[4][4]; + + guLookAtHiliteF(mf, l, h, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp, xl1, yl1, zl1, xl2, yl2, zl2, hiliteWidth, + hiliteHeight); + + guMtxF2L((MtxF*)mf, m); +} +void guOrthoF(float m[4][4], float l, float r, float b, float t, float n, float f, float scale) { + int i; + int j; + guMtxIdentF(m); + m[0][0] = 2 / (r - l); + m[1][1] = 2 / (t - b); + m[2][2] = -2 / (f - n); + m[3][0] = -(r + l) / (r - l); + m[3][1] = -(t + b) / (t - b); + m[3][2] = -(f + n) / (f - n); + m[3][3] = 1; + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + m[i][j] *= scale; + } + } +} + +void guOrtho(Mtx* m, float l, float r, float b, float t, float n, float f, float scale) { + float mf[4][4]; + guOrthoF(mf, l, r, b, t, n, f, scale); + guMtxF2L(mf, m); +} + +#define GU_PI 3.1415926 + +void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { + f32 yscale; + s32 row; + s32 col; + + guMtxIdentF(mf); + + fovy *= GU_PI / 180.0; + yscale = cosf(fovy / 2) / sinf(fovy / 2); + mf[0][0] = yscale / aspect; + mf[1][1] = yscale; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = 2 * near * far / (near - far); + mf[3][3] = 0.0f; + + for (row = 0; row < 4; row++) { + for (col = 0; col < 4; col++) { + mf[row][col] *= scale; + } + } + + if (perspNorm != NULL) { + if (near + far <= 2.0) { + *perspNorm = 65535; + } else { + *perspNorm = (f64)(1 << 17) / (near + far); + if (*perspNorm <= 0) { + *perspNorm = 1; + } + } + } +} + +void guPerspective(Mtx* m, u16* perspNorm, float fovy, float aspect, float near, float far, float scale) { + float mf[4][4]; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + Matrix_MtxFToMtx((MtxF*)mf, m); + //guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + //guMtxF2L(mf, m); +} +#include "global.h" + +void guLookAtF(f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp) { + f32 length; + f32 xLook; + f32 yLook; + f32 zLook; + f32 xRight; + f32 yRight; + f32 zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + length = -1.0 / sqrtf(SQ(xLook) + SQ(yLook) + SQ(zLook)); + xLook *= length; + yLook *= length; + zLook *= length; + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + length = 1.0 / sqrtf(SQ(xRight) + SQ(yRight) + SQ(zRight)); + xRight *= length; + yRight *= length; + zRight *= length; + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + length = 1.0 / sqrtf(SQ(xUp) + SQ(yUp) + SQ(zUp)); + xUp *= length; + yUp *= length; + zUp *= length; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAt(Mtx* m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp) { + f32 mf[4][4]; + + guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); + + guMtxF2L(mf, m); +} +void guRotateF(float m[4][4], float a, float x, float y, float z) { + static float D_80097F90 = M_PI / 180.0f; + float sine; + float cosine; + float ab; + float bc; + float ca; + float t; + float xs; + float ys; + float zs; + + guNormalize(&x, &y, &z); + + a = a * D_80097F90; + + sine = sinf(a); + cosine = cosf(a); + + ab = x * y * (1 - cosine); + bc = y * z * (1 - cosine); + ca = z * x * (1 - cosine); + + guMtxIdentF(m); + + xs = x * sine; + ys = y * sine; + zs = z * sine; + + t = x * x; + m[0][0] = (1 - t) * cosine + t; + m[2][1] = bc - xs; + m[1][2] = bc + xs; + t = y * y; + m[1][1] = (1 - t) * cosine + t; + m[2][0] = ca + ys; + m[0][2] = ca - ys; + t = z * z; + m[2][2] = (1 - t) * cosine + t; + m[1][0] = ab - zs; + m[0][1] = ab + zs; +} + + +void guRotate(Mtx* m, float a, float x, float y, float z) { + float mf[4][4]; + guRotateF(mf, a, x, y, z); + guMtxF2L(mf, m); +} + +/* +void guNormalize(f32* x, f32* y, f32* z) { + f32 tmp = 1.0f / sqrtf(*x * *x + *y * *y + *z * *z); + *x = *x * tmp; + *y = *y * tmp; + *z = *z * tmp; +} +*/ + +void osSpTaskLoad(OSTask* task) { +} +void osSpTaskStartGo(OSTask* task) { +} +void osViExtendVStart(u32 arg0) { +} \ No newline at end of file diff --git a/mm/src/code/sys_cfb.c b/mm/src/code/sys_cfb.c index 383a35cc9..4b88a1d85 100644 --- a/mm/src/code/sys_cfb.c +++ b/mm/src/code/sys_cfb.c @@ -57,7 +57,7 @@ void SysCfb_SetLoResMode(void) { gSysCfbHiResEnabled = false; gScreenWidth = gCfbWidth; gScreenHeight = gCfbHeight; - gActiveViMode = &osViModeNtscLan1; + //gActiveViMode = &osViModeNtscLan1; } void SysCfb_SetHiResMode(void) { @@ -75,7 +75,7 @@ void SysCfb_SetHiResMode(void) { gScreenWidth = gCfbWidth; gScreenHeight = gCfbHeight; if ((gCfbWidth == SCREEN_WIDTH_HIRES) && (gCfbHeight == SCREEN_HEIGHT_HIRES)) { - gActiveViMode = &osViModeNtscHpf1; + //gActiveViMode = &osViModeNtscHpf1; } else { s32 rightAdjust; s32 lowerAdjust; diff --git a/mm/src/code/sys_cmpdma.c b/mm/src/code/sys_cmpdma.c index 9e1a66d2e..1b267a963 100644 --- a/mm/src/code/sys_cmpdma.c +++ b/mm/src/code/sys_cmpdma.c @@ -98,6 +98,7 @@ void CmpDma_LoadFile(uintptr_t segmentVrom, s32 id, void* dst, size_t size) { } void CmpDma_LoadAllFiles(uintptr_t segmentVrom, void* dst, size_t size) { + return; uintptr_t rom = DmaMgr_TranslateVromToRom(segmentVrom); u32 i; u32 end; diff --git a/mm/src/code/sys_flashrom.c b/mm/src/code/sys_flashrom.c index 5ebc5dcba..827dc3289 100644 --- a/mm/src/code/sys_flashrom.c +++ b/mm/src/code/sys_flashrom.c @@ -201,6 +201,7 @@ s32 SysFlashrom_WriteData(void* addr, u32 pageNum, u32 pageCount) { } void SysFlashrom_ThreadEntry(void* arg) { + #if 0 FlashromRequest* req = (FlashromRequest*)arg; switch (req->requestType) { @@ -214,9 +215,11 @@ void SysFlashrom_ThreadEntry(void* arg) { osSendMesg(&req->messageQueue, (OSMesg)req->response, OS_MESG_BLOCK); break; } + #endif } void SysFlashrom_WriteDataAsync(u8* addr, u32 pageNum, u32 pageCount) { + #if 0 FlashromRequest* req = &sFlashromRequest; if (SysFlashrom_IsInit()) { req->requestType = FLASHROM_REQUEST_WRITE; @@ -230,25 +233,28 @@ void SysFlashrom_WriteDataAsync(u8* addr, u32 pageNum, u32 pageCount) { STACK_TOP(sSysFlashromStack), Z_PRIORITY_FLASHROM); osStartThread(&sSysFlashromThread); } + #endif } s32 SysFlashrom_IsBusy(void) { - OSMesgQueue* queue = &sFlashromRequest.messageQueue; - - if (!SysFlashrom_IsInit()) { - return -1; - } - return MQ_IS_FULL(queue); + return 0; + //OSMesgQueue* queue = &sFlashromRequest.messageQueue; + // + //if (!SysFlashrom_IsInit()) { + // return -1; + //} + //return MQ_IS_FULL(queue); } s32 SysFlashrom_AwaitResult(void) { - if (!SysFlashrom_IsInit()) { - return -1; - } - osRecvMesg(&sFlashromRequest.messageQueue, NULL, OS_MESG_BLOCK); - osDestroyThread(&sSysFlashromThread); - StackCheck_Cleanup(&sSysFlashromStackInfo); - return sFlashromRequest.response; + return 0; + //if (!SysFlashrom_IsInit()) { + // return -1; + //} + //osRecvMesg(&sFlashromRequest.messageQueue, NULL, OS_MESG_BLOCK); + //osDestroyThread(&sSysFlashromThread); + //StackCheck_Cleanup(&sSysFlashromStackInfo); + //return sFlashromRequest.response; } void SysFlashrom_WriteDataSync(void* addr, u32 pageNum, u32 pageCount) { diff --git a/mm/src/code/sys_matrix.c b/mm/src/code/sys_matrix.c index f84dae383..c0700fba8 100644 --- a/mm/src/code/sys_matrix.c +++ b/mm/src/code/sys_matrix.c @@ -43,7 +43,22 @@ #include "global.h" /* data */ +#define qs1616(e) ((s32)((e)*0x00010000)) +#define IPART(x) ((qs1616(x) >> 16) & 0xFFFF) +#define FPART(x) (qs1616(x) & 0xFFFF) + +#define gdSPDefMtx(xx, yx, zx, wx, xy, yy, zy, wy, xz, yz, zz, wz, xw, yw, zw, ww) \ + { \ + { \ + (IPART(xx) << 0x10) | IPART(xy), (IPART(xz) << 0x10) | IPART(xw), (IPART(yx) << 0x10) | IPART(yy), \ + (IPART(yz) << 0x10) | IPART(yw), (IPART(zx) << 0x10) | IPART(zy), (IPART(zz) << 0x10) | IPART(zw), \ + (IPART(wx) << 0x10) | IPART(wy), (IPART(wz) << 0x10) | IPART(ww), (FPART(xx) << 0x10) | FPART(xy), \ + (FPART(xz) << 0x10) | FPART(xw), (FPART(yx) << 0x10) | FPART(yy), (FPART(yz) << 0x10) | FPART(yw), \ + (FPART(zx) << 0x10) | FPART(zy), (FPART(zz) << 0x10) | FPART(zw), (FPART(wx) << 0x10) | FPART(wy), \ + (FPART(wz) << 0x10) | FPART(ww), \ + } \ + } // clang-format off Mtx gIdentityMtx = gdSPDefMtx( 1.0f, 0.0f, 0.0f, 0.0f, @@ -1154,75 +1169,7 @@ void Matrix_SetTranslateRotateYXZ(f32 x, f32 y, f32 z, Vec3s* rot) { * @remark original name: "_MtxF_to_Mtx" */ Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest) { - s32 temp; - u16* intPart = (u16*)&dest->m[0][0]; - u16* fracPart = (u16*)&dest->m[2][0]; - - // For some reason the first 9 elements use the intPart temp for the fractional part. - temp = src->xx * 0x10000; - intPart[0] = (temp >> 0x10); - intPart[16 + 0] = temp; - - temp = src->yx * 0x10000; - intPart[1] = (temp >> 0x10); - intPart[16 + 1] = temp; - - temp = src->zx * 0x10000; - intPart[2] = (temp >> 0x10); - intPart[16 + 2] = temp; - - temp = src->wx * 0x10000; - intPart[3] = (temp >> 0x10); - intPart[16 + 3] = temp; - - temp = src->xy * 0x10000; - intPart[4] = (temp >> 0x10); - intPart[16 + 4] = temp; - - temp = src->yy * 0x10000; - intPart[5] = (temp >> 0x10); - intPart[16 + 5] = temp; - - temp = src->zy * 0x10000; - intPart[6] = (temp >> 0x10); - intPart[16 + 6] = temp; - - temp = src->wy * 0x10000; - intPart[7] = (temp >> 0x10); - intPart[16 + 7] = temp; - - temp = src->xz * 0x10000; - intPart[8] = (temp >> 0x10); - intPart[16 + 8] = temp; - - temp = src->yz * 0x10000; - intPart[9] = (temp >> 0x10); - fracPart[9] = temp; - - temp = src->zz * 0x10000; - intPart[10] = (temp >> 0x10); - fracPart[10] = temp; - - temp = src->wz * 0x10000; - intPart[11] = (temp >> 0x10); - fracPart[11] = temp; - - temp = src->xw * 0x10000; - intPart[12] = (temp >> 0x10); - fracPart[12] = temp; - - temp = src->yw * 0x10000; - intPart[13] = (temp >> 0x10); - fracPart[13] = temp; - - temp = src->zw * 0x10000; - intPart[14] = (temp >> 0x10); - fracPart[14] = temp; - - temp = src->ww * 0x10000; - intPart[15] = (temp >> 0x10); - fracPart[15] = temp; - + guMtxF2L(src, dest); return dest; } @@ -1422,50 +1369,38 @@ void Matrix_MultVec3fXZ(Vec3f* src, Vec3f* dest) { * @remark original name: "Matrix_copy_MtxF" */ void Matrix_MtxFCopy(MtxF* dest, MtxF* src) { - f32 fv0; - f32 fv1; - - // This ought to be a loop, but all attempts to match it as one have so far failed. - if (1) { - fv0 = src->mf[0][0]; - fv1 = src->mf[0][1]; - dest->mf[0][0] = fv0; - dest->mf[0][1] = fv1; - fv0 = src->mf[0][2]; - fv1 = src->mf[0][3]; - dest->mf[0][2] = fv0; - dest->mf[0][3] = fv1; - } - if (1) { - fv0 = src->mf[1][0]; - fv1 = src->mf[1][1]; - dest->mf[1][0] = fv0; - dest->mf[1][1] = fv1; - fv0 = src->mf[1][2]; - fv1 = src->mf[1][3]; - dest->mf[1][2] = fv0; - dest->mf[1][3] = fv1; - } - if (1) { - fv0 = src->mf[2][0]; - fv1 = src->mf[2][1]; - dest->mf[2][0] = fv0; - dest->mf[2][1] = fv1; - fv0 = src->mf[2][2]; - fv1 = src->mf[2][3]; - dest->mf[2][2] = fv0; - dest->mf[2][3] = fv1; - } - if (1) { - fv0 = src->mf[3][0]; - fv1 = src->mf[3][1]; - dest->mf[3][0] = fv0; - dest->mf[3][1] = fv1; - fv0 = src->mf[3][2]; - fv1 = src->mf[3][3]; - dest->mf[3][2] = fv0; - dest->mf[3][3] = fv1; - } + dest->xx = src->xx; + dest->yx = src->yx; + dest->zx = src->zx; + dest->wx = src->wx; + dest->xy = src->xy; + dest->yy = src->yy; + dest->zy = src->zy; + dest->wy = src->wy; + dest->xx = src->xx; + dest->yx = src->yx; + dest->zx = src->zx; + dest->wx = src->wx; + dest->xy = src->xy; + dest->yy = src->yy; + dest->zy = src->zy; + dest->wy = src->wy; + dest->xz = src->xz; + dest->yz = src->yz; + dest->zz = src->zz; + dest->wz = src->wz; + dest->xw = src->xw; + dest->yw = src->yw; + dest->zw = src->zw; + dest->ww = src->ww; + dest->xz = src->xz; + dest->yz = src->yz; + dest->zz = src->zz; + dest->wz = src->wz; + dest->xw = src->xw; + dest->yw = src->yw; + dest->zw = src->zw; + dest->ww = src->ww; } /** @@ -1477,25 +1412,7 @@ void Matrix_MtxFCopy(MtxF* dest, MtxF* src) { * @remark original name: "Matrix_MtxtoMtxF" */ void Matrix_MtxToMtxF(Mtx* src, MtxF* dest) { - u16* intPart = (u16*)&src->m[0][0]; - u16* fracPart = (u16*)&src->m[2][0]; - - dest->xx = ((intPart[0] << 0x10) | fracPart[0]) * (1 / (f32)0x10000); - dest->yx = ((intPart[1] << 0x10) | fracPart[1]) * (1 / (f32)0x10000); - dest->zx = ((intPart[2] << 0x10) | fracPart[2]) * (1 / (f32)0x10000); - dest->wx = ((intPart[3] << 0x10) | fracPart[3]) * (1 / (f32)0x10000); - dest->xy = ((intPart[4] << 0x10) | fracPart[4]) * (1 / (f32)0x10000); - dest->yy = ((intPart[5] << 0x10) | fracPart[5]) * (1 / (f32)0x10000); - dest->zy = ((intPart[6] << 0x10) | fracPart[6]) * (1 / (f32)0x10000); - dest->wy = ((intPart[7] << 0x10) | fracPart[7]) * (1 / (f32)0x10000); - dest->xz = ((intPart[8] << 0x10) | fracPart[8]) * (1 / (f32)0x10000); - dest->yz = ((intPart[9] << 0x10) | fracPart[9]) * (1 / (f32)0x10000); - dest->zz = ((intPart[10] << 0x10) | fracPart[10]) * (1 / (f32)0x10000); - dest->wz = ((intPart[11] << 0x10) | fracPart[11]) * (1 / (f32)0x10000); - dest->xw = ((intPart[12] << 0x10) | fracPart[12]) * (1 / (f32)0x10000); - dest->yw = ((intPart[13] << 0x10) | fracPart[13]) * (1 / (f32)0x10000); - dest->zw = ((intPart[14] << 0x10) | fracPart[14]) * (1 / (f32)0x10000); - dest->ww = ((intPart[15] << 0x10) | fracPart[15]) * (1 / (f32)0x10000); + guMtxL2F(dest, src); } // Unused diff --git a/mm/src/code/title_setup.c b/mm/src/code/title_setup.c index 8330df574..0ff2cb0df 100644 --- a/mm/src/code/title_setup.c +++ b/mm/src/code/title_setup.c @@ -49,7 +49,8 @@ void Setup_SetRegs(void) { void Setup_InitImpl(SetupState* this) { SysFlashrom_InitFlash(); - SaveContext_Init(); + // BENTODO: this doesn't crash but was stubbed in minibuild? probably just for debug purposes + // SaveContext_Init(); Setup_SetRegs(); STOP_GAMESTATE(&this->state); diff --git a/mm/src/code/z_actor.c b/mm/src/code/z_actor.c index f7f87979a..ae975af4a 100644 --- a/mm/src/code/z_actor.c +++ b/mm/src/code/z_actor.c @@ -20,7 +20,7 @@ #include "objects/object_bdoor/object_bdoor.h" // bss -FaultClient sActorFaultClient; // 2 funcs +// FaultClient sActorFaultClient; // 2 funcs CollisionPoly* D_801ED8B0; // 1 func s32 D_801ED8B4; // 2 funcs @@ -65,6 +65,7 @@ void Actor_AddToCategory(ActorContext* actorCtx, Actor* actor, u8 actorCategory) Actor* Actor_RemoveFromCategory(PlayState* play, ActorContext* actorCtx, Actor* actorToRemove); void Actor_PrintLists(ActorContext* actorCtx) { + #if 0 ActorListEntry* actorList = &actorCtx->actorLists[0]; Actor* actor; s32 i; @@ -81,6 +82,7 @@ void Actor_PrintLists(ActorContext* actorCtx) { actor = actor->next; } } + #endif } void ActorShape_Init(ActorShape* actorShape, f32 yOffset, ActorShadowFunc shadowDraw, f32 shadowScale) { @@ -2438,7 +2440,7 @@ void Actor_InitContext(PlayState* play, ActorContext* actorCtx, ActorEntry* acto Actor_SpawnEntry(actorCtx, actorEntry, play); Target_Init(&actorCtx->targetCtx, actorCtx->actorLists[ACTORCAT_PLAYER].first, play); Actor_InitHalfDaysBit(actorCtx); - Fault_AddClient(&sActorFaultClient, (void*)Actor_PrintLists, actorCtx, NULL); + //Fault_AddClient(&sActorFaultClient, (void*)Actor_PrintLists, actorCtx, NULL); Actor_SpawnHorse(play, (Player*)actorCtx->actorLists[ACTORCAT_PLAYER].first); } @@ -3148,7 +3150,7 @@ void Actor_KillAllOnHalfDayChange(PlayState* play, ActorContext* actorCtx) { void Actor_CleanupContext(ActorContext* actorCtx, PlayState* play) { s32 i; - Fault_RemoveClient(&sActorFaultClient); + //Fault_RemoveClient(&sActorFaultClient); for (i = 0; i < ARRAY_COUNT(actorCtx->actorLists); i++) { if (i != ACTORCAT_PLAYER) { @@ -3272,7 +3274,7 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) { if (overlayEntry->loadedRamAddr == NULL) { if (overlayEntry->allocType & ALLOCTYPE_ABSOLUTE) { if (actorCtx->absoluteSpace == NULL) { - actorCtx->absoluteSpace = ZeldaArena_MallocR(AM_FIELD_SIZE); + actorCtx->absoluteSpace = ZeldaArena_MallocR(0xFFFFFF); } gActorOverlayTable[index].loadedRamAddr = actorCtx->absoluteSpace; } else if (overlayEntry->allocType & ALLOCTYPE_PERMANENT) { @@ -3477,16 +3479,18 @@ Actor* Actor_Delete(ActorContext* actorCtx, Actor* actor, PlayState* play) { if (actor == actorCtx->targetCtx.bgmEnemy) { actorCtx->targetCtx.bgmEnemy = NULL; } - - AudioSfx_StopByPos(&actor->projectedPos); + // BENTODO +// AudioSfx_StopByPos(&actor->projectedPos); Actor_Destroy(actor, play); newHead = Actor_RemoveFromCategory(play, actorCtx, actor); ZeldaArena_Free(actor); - - if (overlayEntry->vramStart != NULL) { - overlayEntry->numLoaded--; - Actor_FreeOverlay(overlayEntry); + // BENTODO shouldn't need this check + if (overlayEntry != NULL) { + if (overlayEntry->vramStart != NULL) { + overlayEntry->numLoaded--; + Actor_FreeOverlay(overlayEntry); + } } return newHead; @@ -4643,7 +4647,44 @@ void Actor_UpdateFidgetTables(PlayState* play, s16* fidgetTableY, s16* fidgetTab void Actor_Noop(Actor* actor, PlayState* play) { } -#include "z_cheap_proc.c" +/** + * Draws a display list to the opaque display buffer + */ +void Gfx_DrawDListOpa(PlayState* play, Gfx* dlist) { + Gfx* dl; + + OPEN_DISPS(play->state.gfxCtx); + + dl = POLY_OPA_DISP; + + gSPDisplayList(&dl[0], gSetupDLs[SETUPDL_25]); + gSPMatrix(&dl[1], Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(&dl[2], dlist); + + POLY_OPA_DISP = &dl[3]; + + CLOSE_DISPS(play->state.gfxCtx); +} + +/** + * Draws a display list to the translucent display buffer + */ +void Gfx_DrawDListXlu(PlayState* play, Gfx* dlist) { + Gfx* dl; + + OPEN_DISPS(play->state.gfxCtx); + + dl = POLY_XLU_DISP; + + gSPDisplayList(&dl[0], gSetupDLs[SETUPDL_25]); + gSPMatrix(&dl[1], Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(&dl[2], dlist); + + POLY_XLU_DISP = &dl[3]; + + CLOSE_DISPS(play->state.gfxCtx); +} + /** * Finds the first actor instance of a specified Id and category within a given range from diff --git a/mm/src/code/z_actor_dlftbls.c b/mm/src/code/z_actor_dlftbls.c index d48ed24bc..63fbc7b62 100644 --- a/mm/src/code/z_actor_dlftbls.c +++ b/mm/src/code/z_actor_dlftbls.c @@ -13,21 +13,24 @@ #undef DEFINE_ACTOR_INTERNAL #undef DEFINE_ACTOR_UNSET -// Actor Overlay Table definition -#define DEFINE_ACTOR(name, _enumValue, allocType, _debugName) \ - { SEGMENT_ROM_START(ovl_##name), \ - SEGMENT_ROM_END(ovl_##name), \ - SEGMENT_START(ovl_##name), \ - SEGMENT_END(ovl_##name), \ - NULL, \ - &name##_InitVars, \ - NULL, \ - allocType, \ - 0 }, +//// Actor Overlay Table definition +//#define DEFINE_ACTOR(name, _enumValue, allocType, _debugName) \ +// { SEGMENT_ROM_START(ovl_##name), \ +// SEGMENT_ROM_END(ovl_##name), \ +// SEGMENT_START(ovl_##name), \ +// SEGMENT_END(ovl_##name), \ +// NULL, \ +// &name##_InitVars, \ +// NULL, \ +// allocType, \ +// 0 }, #define DEFINE_ACTOR_INTERNAL(name, _enumValue, allocType, _debugName) \ { 0, 0, NULL, NULL, NULL, &name##_InitVars, NULL, allocType, 0 }, +#define DEFINE_ACTOR(name, _enumValue, allocType, _debugName) \ + DEFINE_ACTOR_INTERNAL(name, _enumValue, allocType, _debugName) + #define DEFINE_ACTOR_UNSET(_enumValue) { 0 }, ActorOverlay gActorOverlayTable[] = { diff --git a/mm/src/code/z_camera.c b/mm/src/code/z_camera.c index ba3ce2a61..ada5b6201 100644 --- a/mm/src/code/z_camera.c +++ b/mm/src/code/z_camera.c @@ -55,7 +55,7 @@ s32 Camera_ChangeMode(Camera* camera, s16 mode); s16 Camera_ChangeSettingFlags(Camera* camera, s16 setting, s16 flags); s16 Camera_UnsetStateFlag(Camera* camera, s16 flags); -#include "z_camera_data.inc.c" +#include "z_camera_data.inc" PlayState* sCamPlayState; SwingAnimation D_801EDC30[4]; diff --git a/mm/src/code/z_camera_data.inc.c b/mm/src/code/z_camera_data.inc similarity index 100% rename from mm/src/code/z_camera_data.inc.c rename to mm/src/code/z_camera_data.inc diff --git a/mm/src/code/z_cheap_proc.c b/mm/src/code/z_cheap_proc.c deleted file mode 100644 index 82303a172..000000000 --- a/mm/src/code/z_cheap_proc.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "global.h" - -/** - * Draws a display list to the opaque display buffer - */ -void Gfx_DrawDListOpa(PlayState* play, Gfx* dlist) { - Gfx* dl; - - OPEN_DISPS(play->state.gfxCtx); - - dl = POLY_OPA_DISP; - - gSPDisplayList(&dl[0], gSetupDLs[SETUPDL_25]); - gSPMatrix(&dl[1], Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(&dl[2], dlist); - - POLY_OPA_DISP = &dl[3]; - - CLOSE_DISPS(play->state.gfxCtx); -} - -/** - * Draws a display list to the translucent display buffer - */ -void Gfx_DrawDListXlu(PlayState* play, Gfx* dlist) { - Gfx* dl; - - OPEN_DISPS(play->state.gfxCtx); - - dl = POLY_XLU_DISP; - - gSPDisplayList(&dl[0], gSetupDLs[SETUPDL_25]); - gSPMatrix(&dl[1], Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(&dl[2], dlist); - - POLY_XLU_DISP = &dl[3]; - - CLOSE_DISPS(play->state.gfxCtx); -} diff --git a/mm/src/code/z_debug_display.c b/mm/src/code/z_debug_display.c index 9dd4d86b2..3917fb97b 100644 --- a/mm/src/code/z_debug_display.c +++ b/mm/src/code/z_debug_display.c @@ -43,7 +43,7 @@ DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, return sDebugObjectListHead; } -#include "code/debug_display/debug_display.c" +#include "code/debug_display/debug_display.h" DebugDispObjectDrawFunc sDebugObjectDrawFuncTable[] = { DebugDisplay_DrawSpriteI8, DebugDisplay_DrawPolygon }; diff --git a/mm/src/code/z_demo.c b/mm/src/code/z_demo.c index 5ed6180d5..fd60742dc 100644 --- a/mm/src/code/z_demo.c +++ b/mm/src/code/z_demo.c @@ -2,6 +2,12 @@ #include "prevent_bss_reordering2.h" #include "PR/ultratypes.h" +#include "z64quake.h" +#include "z64rumble.h" +#include "z64shrink_window.h" +#include "overlays/gamestates/ovl_daytelop/z_daytelop.h" +#include "overlays/actors/ovl_En_Elf/z_en_elf.h" + s16 sCutsceneQuakeIndex; struct CutsceneCamera sCutsceneCameraInfo; u16 sCueTypeList[10]; @@ -10,12 +16,6 @@ static s16 sBssPad; u8 gDisablePlayerCsActionStartPos; s16 gDungeonBossWarpSceneId; -#include "z64quake.h" -#include "z64rumble.h" -#include "z64shrink_window.h" -#include "overlays/gamestates/ovl_daytelop/z_daytelop.h" -#include "overlays/actors/ovl_En_Elf/z_en_elf.h" - void CutsceneHandler_DoNothing(PlayState* play, CutsceneContext* csCtx); void CutsceneHandler_StartManual(PlayState* play, CutsceneContext* csCtx); void CutsceneHandler_StopManual(PlayState* play, CutsceneContext* csCtx); diff --git a/mm/src/code/z_draw.c b/mm/src/code/z_draw.c index 1d5b967d7..d1836ab09 100644 --- a/mm/src/code/z_draw.c +++ b/mm/src/code/z_draw.c @@ -249,8 +249,8 @@ static DrawItemTableEntry sDrawItemTable[] = { // GID_MASK_BLAST, OBJECT_GI_MASK21 { GetItem_DrawOpa0Xlu1, { gGiBlastMaskEmptyDL, gGiBlastMaskDL } }, // GID_FAIRY, OBJECT_GI_BOTTLE_04 - { GetItem_DrawFairyContainer, - { gGiFairyBottleEmptyDL, gGiFairyBottleGlassCorkDL, gGiFairyBottleContentsDL, &gGiFairyBottleBillboardRotMtx } }, + { GetItem_DrawFairyContainer, // BENTODO + { gGiFairyBottleEmptyDL, gGiFairyBottleGlassCorkDL, gGiFairyBottleContentsDL, NULL } }, // GID_MASK_SCENTS, OBJECT_GI_MASK22 { GetItem_DrawOpa01, { gGiMaskOfScentsFaceDL, gGiMaskOfScentsTeethDL } }, // GID_MASK_CAPTAIN, OBJECT_GI_MASK18 @@ -332,7 +332,8 @@ static DrawItemTableEntry sDrawItemTable[] = { // GID_HYLIAN_LOACH, OBJECT_GI_LOACH { GetItem_DrawOpa0Xlu1, { gGiHylianLoachEmptyDL, gGiHylianLoachDL } }, // GID_SEAHORSE_CAUGHT, OBJECT_GI_SEAHORSE - { GetItem_DrawSeahorse, { gGiSeahorseEmptyDL, gGiSeahorseBodyDL, gGiSeahorseGlowDL, &gGiSeahorseBillboardRotMtx } }, + // BENTODO + { GetItem_DrawSeahorse, { gGiSeahorseEmptyDL, gGiSeahorseBodyDL, gGiSeahorseGlowDL, NULL } }, // GID_REMAINS_GOHT, OBJECT_BSMASK { GetItem_DrawRemains, { gRemainsGohtDL, gRemainsGohtDL } }, // GID_REMAINS_GYORG, OBJECT_BSMASK diff --git a/mm/src/code/z_eff_footmark.c b/mm/src/code/z_eff_footmark.c index 806cc45e0..53d96f0c5 100644 --- a/mm/src/code/z_eff_footmark.c +++ b/mm/src/code/z_eff_footmark.c @@ -3,7 +3,7 @@ #include "macros.h" #include "functions.h" -#include "assets/code/eff_footmark/eff_footmark.c" +#include "assets/code/eff_footmark/eff_footmark.h" void EffFootmark_Init(PlayState* play) { EffFootmark* footmark; diff --git a/mm/src/code/z_eff_shield_particle.c b/mm/src/code/z_eff_shield_particle.c index e15874a78..ddde771d9 100644 --- a/mm/src/code/z_eff_shield_particle.c +++ b/mm/src/code/z_eff_shield_particle.c @@ -1,7 +1,7 @@ #include "global.h" #include "vt.h" -#include "assets/code/eff_shield_particle/eff_shield_particle.c" +#include "assets/code/eff_shield_particle/eff_shield_particle.h" #include "objects/gameplay_keep/gameplay_keep.h" void EffectShieldParticle_Init(void* thisx, void* initParamsx) { diff --git a/mm/src/code/z_effect_soft_sprite_dlftbls.c b/mm/src/code/z_effect_soft_sprite_dlftbls.c index fff77feff..f6a9bf3b0 100644 --- a/mm/src/code/z_effect_soft_sprite_dlftbls.c +++ b/mm/src/code/z_effect_soft_sprite_dlftbls.c @@ -13,15 +13,9 @@ #undef DEFINE_EFFECT_SS #undef DEFINE_EFFECT_SS_UNSET -#define DEFINE_EFFECT_SS(name, _enumValue) \ - { \ - SEGMENT_ROM_START(ovl_##name), \ - SEGMENT_ROM_END(ovl_##name), \ - SEGMENT_START(ovl_##name), \ - SEGMENT_END(ovl_##name), \ - NULL, \ - &name##_InitVars, \ - 1, \ +#define DEFINE_EFFECT_SS(name, _enumValue) \ + { \ + 0, 0, 0, 0, NULL, &name##_InitVars, 1, \ }, #define DEFINE_EFFECT_SS_UNSET(_enumValue) { 0 }, diff --git a/mm/src/code/z_fbdemo_dlftbls.c b/mm/src/code/z_fbdemo_dlftbls.c index 48d424813..9dcc57981 100644 --- a/mm/src/code/z_fbdemo_dlftbls.c +++ b/mm/src/code/z_fbdemo_dlftbls.c @@ -11,7 +11,7 @@ #undef DEFINE_TRANSITION #undef DEFINE_TRANSITION_INTERNAL - +// BENTODO #define DEFINE_TRANSITION(_enumValue, structName, _instanceName, name) \ { \ { 0, 0 }, \ diff --git a/mm/src/code/z_fbdemo_fade.c b/mm/src/code/z_fbdemo_fade.c index a9ab37d48..3d4f1933e 100644 --- a/mm/src/code/z_fbdemo_fade.c +++ b/mm/src/code/z_fbdemo_fade.c @@ -116,7 +116,7 @@ void TransitionFade_Draw(void* thisx, Gfx** gfxP) { gfx = *gfxP; gSPDisplayList(gfx++, sTransFadeSetupDL); gDPSetPrimColor(gfx++, 0, 0, color->r, color->g, color->b, color->a); - gSPDisplayList(gfx++, D_0E000000.fillRect); + gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); *gfxP = gfx; } } diff --git a/mm/src/code/z_game_dlftbls.c b/mm/src/code/z_game_dlftbls.c index cb3aee317..d2bef0b97 100644 --- a/mm/src/code/z_game_dlftbls.c +++ b/mm/src/code/z_game_dlftbls.c @@ -19,19 +19,20 @@ #define DEFINE_GAMESTATE_INTERNAL(typeName, _enumName) \ { NULL, 0, 0, NULL, NULL, NULL, typeName##_Init, typeName##_Destroy, NULL, NULL, 0, sizeof(typeName##State) }, -#define DEFINE_GAMESTATE(typeName, _enumName, segmentName) \ - { NULL, \ - (uintptr_t)SEGMENT_ROM_START(ovl_##segmentName), \ - (uintptr_t)SEGMENT_ROM_END(ovl_##segmentName), \ - SEGMENT_START(ovl_##segmentName), \ - SEGMENT_END(ovl_##segmentName), \ - NULL, \ - typeName##_Init, \ - typeName##_Destroy, \ - NULL, \ - NULL, \ - 0, \ - sizeof(typeName##State) }, +#define DEFINE_GAMESTATE(typeName, _enumName, segmentName) DEFINE_GAMESTATE_INTERNAL(typeName, _enumName) +//\ +// { NULL, \ +// (uintptr_t)SEGMENT_ROM_START(ovl_##segmentName), \ +// (uintptr_t)SEGMENT_ROM_END(ovl_##segmentName), \ +// SEGMENT_START(ovl_##segmentName), \ +// SEGMENT_END(ovl_##segmentName), \ +// NULL, \ +// typeName##_Init, \ +// typeName##_Destroy, \ +// NULL, \ +// NULL, \ +// 0, \ +// sizeof(typeName##State) }, GameStateOverlay gGameStateOverlayTable[GAMESTATE_ID_MAX] = { #include "tables/gamestate_table.h" diff --git a/mm/src/code/z_jpeg.c b/mm/src/code/z_jpeg.c index 5ccc5987d..ebe40b8b9 100644 --- a/mm/src/code/z_jpeg.c +++ b/mm/src/code/z_jpeg.c @@ -23,6 +23,7 @@ extern u64 njpgdspMainDataStart[]; * Configures and schedules a JPEG decoder task and waits for it to finish. */ void Jpeg_ScheduleDecoderTask(JpegContext* jpegCtx) { + #if 0 static OSTask_t sJpegTask = { M_NJPEGTASK, // type 0, // flags @@ -68,6 +69,7 @@ void Jpeg_ScheduleDecoderTask(JpegContext* jpegCtx) { osSendMesg(&gSchedContext.cmdQ, (OSMesg*)&jpegCtx->scTask, OS_MESG_BLOCK); Sched_SendEntryMsg(&gSchedContext); // osScKickEntryMsg osRecvMesg(&jpegCtx->mq, NULL, OS_MESG_BLOCK); + #endif } /** diff --git a/mm/src/code/z_kaleido_manager.c b/mm/src/code/z_kaleido_manager.c index d0bacdd22..88ec84840 100644 --- a/mm/src/code/z_kaleido_manager.c +++ b/mm/src/code/z_kaleido_manager.c @@ -2,11 +2,14 @@ #include "fault.h" #include "loadfragment.h" -#define KALEIDO_OVERLAY(name) \ - { \ - NULL, SEGMENT_ROM_START(ovl_##name), SEGMENT_ROM_END(ovl_##name), SEGMENT_START(ovl_##name), \ - SEGMENT_END(ovl_##name), 0, #name, \ - } +//#define KALEIDO_OVERLAY(name) \ +// { \ +// NULL, SEGMENT_ROM_START(ovl_##name), SEGMENT_ROM_END(ovl_##name), SEGMENT_START(ovl_##name), \ +// SEGMENT_END(ovl_##name), 0, #name, \ +// } + +#define KALEIDO_OVERLAY(name) \ + { NULL, 0, 0, 0, 0, 0, #name, } KaleidoMgrOverlay gKaleidoMgrOverlayTable[] = { KALEIDO_OVERLAY(kaleido_scope), @@ -83,6 +86,8 @@ void KaleidoManager_Destroy() { } void* KaleidoManager_GetRamAddr(void* vram) { + return vram; + #if 0 if (gKaleidoMgrCurOvl == NULL) { s32 pad[2]; KaleidoMgrOverlay* ovl = &gKaleidoMgrOverlayTable[0]; @@ -102,4 +107,5 @@ void* KaleidoManager_GetRamAddr(void* vram) { } return (void*)((uintptr_t)vram + gKaleidoMgrCurOvl->offset); + #endif } diff --git a/mm/src/code/z_kanfont.c b/mm/src/code/z_kanfont.c index 2a42998b4..3860cb92b 100644 --- a/mm/src/code/z_kanfont.c +++ b/mm/src/code/z_kanfont.c @@ -1,4 +1,165 @@ #include "global.h" +#include "BenPort.h" +#include "assets/interface/nes_font_static/nes_font_static.h" +#include +static const char* fontTbl[] = { + gMsgChar20SpaceTex, + gMsgChar21ExclamationMarkTex, + gMsgChar22QuotationMarkTex, + gMsgChar23NumberSignTex, + gMsgChar24DollarSignTex, + gMsgChar25PercentSignTex, + gMsgChar26AmpersandTex, + gMsgChar27ApostropheTex, + gMsgChar28LeftParenthesesTex, + gMsgChar29RightParenthesesTex, + gMsgChar2AAsteriskTex, + gMsgChar2BPlusSignTex, + gMsgChar2CCommaTex, + gMsgChar2DHyphenMinusTex, + gMsgChar2EFullStopTex, + gMsgChar2FSolidusTex, + gMsgChar30Digit0Tex, + gMsgChar31Digit1Tex, + gMsgChar32Digit2Tex, + gMsgChar33Digit3Tex, + gMsgChar34Digit4Tex, + gMsgChar35Digit5Tex, + gMsgChar36Digit6Tex, + gMsgChar37Digit7Tex, + gMsgChar38Digit8Tex, + gMsgChar39Digit9Tex, + gMsgChar3AColonTex, + gMsgChar3BSemicolonTex, + gMsgChar3CLessThanSignTex, + gMsgChar3DEqualsSignTex, + gMsgChar3EGreaterThanSignTex, + gMsgChar3FQuestionMarkTex, + gMsgChar40CommercialAtTex, + gMsgChar41LatinCapitalLetterATex, + gMsgChar42LatinCapitalLetterBTex, + gMsgChar43LatinCapitalLetterCTex, + gMsgChar44LatinCapitalLetterDTex, + gMsgChar45LatinCapitalLetterETex, + gMsgChar46LatinCapitalLetterFTex, + gMsgChar47LatinCapitalLetterGTex, + gMsgChar48LatinCapitalLetterHTex, + gMsgChar49LatinCapitalLetterITex, + gMsgChar4ALatinCapitalLetterJTex, + gMsgChar4BLatinCapitalLetterKTex, + gMsgChar4CLatinCapitalLetterLTex, + gMsgChar4DLatinCapitalLetterMTex, + gMsgChar4ELatinCapitalLetterNTex, + gMsgChar4FLatinCapitalLetterOTex, + gMsgChar50LatinCapitalLetterPTex, + gMsgChar51LatinCapitalLetterQTex, + gMsgChar52LatinCapitalLetterRTex, + gMsgChar53LatinCapitalLetterSTex, + gMsgChar54LatinCapitalLetterTTex, + gMsgChar55LatinCapitalLetterUTex, + gMsgChar56LatinCapitalLetterVTex, + gMsgChar57LatinCapitalLetterWTex, + gMsgChar58LatinCapitalLetterXTex, + gMsgChar59LatinCapitalLetterYTex, + gMsgChar5ALatinCapitalLetterZTex, + gMsgChar5BLeftSquareBracketTex, + gMsgChar5CYenSignTex, + gMsgChar5DRightSquareBracketTex, + gMsgChar5ECircumflexAccentTex, + gMsgChar5FLowLineTex, + gMsgChar60GraveAccentTex, + gMsgChar61LatinSmallLetterATex, + gMsgChar62LatinSmallLetterBTex, + gMsgChar63LatinSmallLetterCTex, + gMsgChar64LatinSmallLetterDTex, + gMsgChar65LatinSmallLetterETex, + gMsgChar66LatinSmallLetterFTex, + gMsgChar67LatinSmallLetterGTex, + gMsgChar68LatinSmallLetterHTex, + gMsgChar69LatinSmallLetterITex, + gMsgChar6ALatinSmallLetterJTex, + gMsgChar6BLatinSmallLetterKTex, + gMsgChar6CLatinSmallLetterLTex, + gMsgChar6DLatinSmallLetterMTex, + gMsgChar6ELatinSmallLetterNTex, + gMsgChar6FLatinSmallLetterOTex, + gMsgChar70LatinSmallLetterPTex, + gMsgChar71LatinSmallLetterQTex, + gMsgChar72LatinSmallLetterRTex, + gMsgChar73LatinSmallLetterSTex, + gMsgChar74LatinSmallLetterTTex, + gMsgChar75LatinSmallLetterUTex, + gMsgChar76LatinSmallLetterVTex, + gMsgChar77LatinSmallLetterWTex, + gMsgChar78LatinSmallLetterXTex, + gMsgChar79LatinSmallLetterYTex, + gMsgChar7ALatinSmallLetterZTex, + gMsgChar7BLeftCurlyBracketTex, + gMsgChar7CVerticalLineTex, + gMsgChar7DRightCurlyBracketTex, + gMsgChar7ETildeTex, + gMsgChar7FMasculineOrdinalIndicatorTex, + gMsgChar80LatinCapitalLetterAWithGraveTex, + gMsgChar81LatinCapitalLetterAWithAcuteTex, + gMsgChar82LatinCapitalLetterAWithCircumflexTex, + gMsgChar83LatinCapitalLetterAWithDiaeresisTex, + gMsgChar84LatinCapitalLetterCWithCedillaTex, + gMsgChar85LatinCapitalLetterEWithGraveTex, + gMsgChar86LatinCapitalLetterEWithAcuteTex, + gMsgChar87LatinCapitalLetterEWithCircumflexTex, + gMsgChar88LatinCapitalLetterEWithDiaeresisTex, + gMsgChar89LatinCapitalLetterIWithGraveTex, + gMsgChar8ALatinCapitalLetterIWithAcuteTex, + gMsgChar8BLatinCapitalLetterIWithCircumflexTex, + gMsgChar8CLatinCapitalLetterIWithDiaeresisTex, + gMsgChar8DLatinCapitalLetterNWithTildeTex, + gMsgChar8ELatinCapitalLetterOWithGraveTex, + gMsgChar8FLatinCapitalLetterOWithAcuteTex, + gMsgChar90LatinCapitalLetterOWithCircumflexTex, + gMsgChar91LatinCapitalLetterOWithDiaeresisTex, + gMsgChar92LatinCapitalLetterUWithGraveTex, + gMsgChar93LatinCapitalLetterUWithAcuteTex, + gMsgChar94LatinCapitalLetterUWithCircumflexTex, + gMsgChar95LatinCapitalLetterUWithDiaeresisTex, + gMsgChar96GreekSmallLetterBetaTex, + gMsgChar97LatinSmallLetterAWithGraveTex, + gMsgChar98LatinSmallLetterAWithAcuteTex, + gMsgChar99LatinSmallLetterAWithCircumflexTex, + gMsgChar9ALatinSmallLetterAWithDiaeresisTex, + gMsgChar9BLatinSmallLetterCWithCedillaTex, + gMsgChar9CLatinSmallLetterEWithGraveTex, + gMsgChar9DLatinSmallLetterEWithAcuteTex, + gMsgChar9ELatinSmallLetterEWithCircumflexTex, + gMsgChar9FLatinSmallLetterEWithDiaeresisTex, + gMsgCharA0LatinSmallLetterIWithGraveTex, + gMsgCharA1LatinSmallLetterIWithAcuteTex, + gMsgCharA2LatinSmallLetterIWithCircumflexTex, + gMsgCharA3LatinSmallLetterIWithDiaeresisTex, + gMsgCharA4LatinSmallLetterNWithTildeTex, + gMsgCharA5LatinSmallLetterOWithGraveTex, + gMsgCharA6LatinSmallLetterOWithAcuteTex, + gMsgCharA7LatinSmallLetterOWithCircumflexTex, + gMsgCharA8LatinSmallLetterOWithDiaeresisTex, + gMsgCharA9LatinSmallLetterUWithGraveTex, + gMsgCharAALatinSmallLetterUWithAcuteTex, + gMsgCharABLatinSmallLetterUWithCircumflexTex, + gMsgCharACLatinSmallLetterUWithDiaeresisTex, + gMsgCharADInvertedExclamationMarkTex, + gMsgCharAEInvertedQuestionMarkTex, + gMsgCharAFFeminineOrdinalIndicatorTex, + gMsgCharB0ButtonATex, + gMsgCharB1ButtonBTex, + gMsgCharB2ButtonCTex, + gMsgCharB3ButtonLTex, + gMsgCharB4ButtonRTex, + gMsgCharB5ButtonZTex, + gMsgCharB6ButtonCUpTex, + gMsgCharB7ButtonCDownTex, + gMsgCharB8ButtonCLeftTex, + gMsgCharB9ButtonCRightTex, + gMsgCharBAZTargetSignTex, + gMsgCharBBControlStickTex, +}; // stubbed in NTSC-U void Font_LoadChar(PlayState* play, u16 codePointIndex, s32 offset) { @@ -8,15 +169,23 @@ void Font_LoadCharNES(PlayState* play, u8 codePointIndex, s32 offset) { MessageContext* msgCtx = &play->msgCtx; Font* font = &msgCtx->font; - DmaMgr_SendRequest0(&font->charBuf[font->unk_11D88][offset], - SEGMENT_ROM_START_OFFSET(nes_font_static, (codePointIndex - ' ') * FONT_CHAR_TEX_SIZE), - FONT_CHAR_TEX_SIZE); + int fontIdx = codePointIndex - 0x20; + + if (codePointIndex < 0x8B) + memcpy(&font->charBuf[font->unk_11D88][offset], fontTbl[fontIdx], strlen(fontTbl[fontIdx]) + 1); + + // DmaMgr_SendRequest0(&font->charBuf[font->unk_11D88][offset], + //&((u8*)SEGMENT_ROM_START(nes_font_static))[(codePointIndex - ' ') * FONT_CHAR_TEX_SIZE], + // FONT_CHAR_TEX_SIZE); } void Font_LoadMessageBoxEndIcon(Font* font, u16 icon) { - DmaMgr_SendRequest0(&font->iconBuf, - SEGMENT_ROM_START_OFFSET(message_static, 5 * 0x1000 + icon * FONT_CHAR_TEX_SIZE), - FONT_CHAR_TEX_SIZE); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[icon]); + memcpy(&font->iconBuf, tex, FONT_CHAR_TEX_SIZE); + + // DmaMgr_SendRequest0(&font->iconBuf, + //&((u8*)SEGMENT_ROM_START(message_static))[5 * 0x1000 + icon * FONT_CHAR_TEX_SIZE], + // FONT_CHAR_TEX_SIZE); } static u8 sFontOrdering[] = { @@ -33,13 +202,18 @@ void Font_LoadOrderedFont(Font* font) { u8* writeLocation; while (1) { + void* tex; writeLocation = &font->fontBuf[codePointIndex * FONT_CHAR_TEX_SIZE]; - loadOffset = sFontOrdering[codePointIndex] * FONT_CHAR_TEX_SIZE; + loadOffset = sFontOrdering[codePointIndex]; // *FONT_CHAR_TEX_SIZE; if (sFontOrdering[codePointIndex] == 0) { loadOffset = 0; } - DmaMgr_SendRequest0(writeLocation, SEGMENT_ROM_START(nes_font_static) + loadOffset, FONT_CHAR_TEX_SIZE); + tex = ResourceMgr_LoadTexOrDListByName(fontTbl[loadOffset]); + memcpy(writeLocation, tex, FONT_CHAR_TEX_SIZE); + + // DmaMgr_SendRequest0(writeLocation, (uintptr_t)SEGMENT_ROM_START(nes_font_static) + loadOffset, + // FONT_CHAR_TEX_SIZE); if (sFontOrdering[codePointIndex] == 0x8C) { break; } diff --git a/mm/src/code/z_kankyo.c b/mm/src/code/z_kankyo.c index 6050cf522..f21865065 100644 --- a/mm/src/code/z_kankyo.c +++ b/mm/src/code/z_kankyo.c @@ -20,7 +20,12 @@ typedef struct { } LightningBolt; // size = 0x20 // Variables are put before most headers as a hacky way to bypass bss reordering -struct LightningStrike; +#include "z64environment.h" +#include "global.h" +#include "sys_cfb.h" +#include "objects/gameplay_keep/gameplay_keep.h" +#include "objects/gameplay_field_keep/gameplay_field_keep.h" +#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" u8 D_801F4E30; u8 D_801F4E31; @@ -59,13 +64,6 @@ u8 D_801F4F33; u8 sGameOverLightsIntensity; Gfx* sSkyboxStarsDList; -#include "z64environment.h" -#include "global.h" -#include "sys_cfb.h" -#include "objects/gameplay_keep/gameplay_keep.h" -#include "objects/gameplay_field_keep/gameplay_field_keep.h" -#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" - // Data f32 sSandstormLerpScale = 0.0f; s32 sSunScreenDepth = GPACK_ZDZ(G_MAXFBZ, 0); @@ -1049,7 +1047,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon size = sNormalSkyFiles[skybox1Index].file.vromEnd - sNormalSkyFiles[skybox1Index].file.vromStart; osCreateMesgQueue(&envCtx->loadQueue, envCtx->loadMsg, ARRAY_COUNT(envCtx->loadMsg)); DmaMgr_SendRequestImpl(&envCtx->dmaRequest, skyboxCtx->staticSegments[0], - sNormalSkyFiles[skybox1Index].file.vromStart, size, 0, &envCtx->loadQueue, NULL); + sNormalSkyFiles[skybox1Index].file.vromStart, size, 0, &envCtx->loadQueue, OS_MESG_PTR(NULL)); envCtx->skybox1Index = skybox1Index; } @@ -1058,7 +1056,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon size = sNormalSkyFiles[skybox2Index].file.vromEnd - sNormalSkyFiles[skybox2Index].file.vromStart; osCreateMesgQueue(&envCtx->loadQueue, envCtx->loadMsg, ARRAY_COUNT(envCtx->loadMsg)); DmaMgr_SendRequestImpl(&envCtx->dmaRequest, skyboxCtx->staticSegments[1], - sNormalSkyFiles[skybox2Index].file.vromStart, size, 0, &envCtx->loadQueue, NULL); + sNormalSkyFiles[skybox2Index].file.vromStart, size, 0, &envCtx->loadQueue, OS_MESG_PTR(NULL)); envCtx->skybox2Index = skybox2Index; } @@ -2000,7 +1998,7 @@ void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, (u8)(weight * 75.0f) + 180, (u8)(weight * 155.0f) + 100, (u8)envCtx->glareAlpha); - gSPDisplayList(POLY_XLU_DISP++, D_0E000000.clearFillRect); + gSPDisplayList(POLY_XLU_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); } else { envCtx->glareAlpha = 0.0f; } @@ -2182,7 +2180,7 @@ void Environment_DrawSkyboxFilters(PlayState* play) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, play->lightCtx.fogColor[0] + 16, play->lightCtx.fogColor[1] + 16, play->lightCtx.fogColor[2] + 16, 255.0f * D_801F4E74); } - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearFillRect); + gSPDisplayList(POLY_OPA_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); CLOSE_DISPS(play->state.gfxCtx); } @@ -2193,7 +2191,7 @@ void Environment_DrawSkyboxFilters(PlayState* play) { Gfx_SetupDL57_Opa(play->state.gfxCtx); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, play->envCtx.skyboxFilterColor[0], play->envCtx.skyboxFilterColor[1], play->envCtx.skyboxFilterColor[2], play->envCtx.skyboxFilterColor[3]); - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearFillRect); + gSPDisplayList(POLY_OPA_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); CLOSE_DISPS(play->state.gfxCtx); } @@ -2204,7 +2202,7 @@ void Environment_DrawLightningFlash(PlayState* play, u8 red, u8 green, u8 blue, Gfx_SetupDL57_Opa(play->state.gfxCtx); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, alpha); - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearFillRect); + gSPDisplayList(POLY_OPA_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); CLOSE_DISPS(play->state.gfxCtx); } @@ -2658,7 +2656,9 @@ void Environment_FillScreen(GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, alpha); gDPSetAlphaDither(POLY_OPA_DISP++, G_AD_DISABLE); gDPSetColorDither(POLY_OPA_DISP++, G_CD_DISABLE); - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearFillRect); + + __gSPDisplayList(POLY_OPA_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); } if (drawFlags & FILL_SCREEN_XLU) { @@ -2671,7 +2671,9 @@ void Environment_FillScreen(GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE); gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE); - gSPDisplayList(POLY_XLU_DISP++, D_0E000000.clearFillRect); + + __gSPDisplayList(POLY_XLU_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); } CLOSE_DISPS(gfxCtx); diff --git a/mm/src/code/z_lib.c b/mm/src/code/z_lib.c index afbcba0ed..c057f6e81 100644 --- a/mm/src/code/z_lib.c +++ b/mm/src/code/z_lib.c @@ -1,4 +1,5 @@ #include "global.h" +#include void* Lib_MemCpy(void* dest, void* src, size_t size) { bcopy(src, dest, size); @@ -698,8 +699,12 @@ f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed) { void Lib_Nop801004FC(void) { } +int ResourceMgr_OTRSigCheck(char* imgData); void* Lib_SegmentedToVirtual(void* ptr) { - return SEGMENTED_TO_K0(ptr); + if (ResourceMgr_OTRSigCheck(ptr)) { + return ResourceGetDataByName(ptr); // SEGMENTED_TO_VIRTUAL(ptr); + } + return ptr; } void* Lib_SegmentedToVirtualNull(void* ptr) { diff --git a/mm/src/code/z_lifemeter.c b/mm/src/code/z_lifemeter.c index d9abe151d..7d111f293 100644 --- a/mm/src/code/z_lifemeter.c +++ b/mm/src/code/z_lifemeter.c @@ -420,7 +420,7 @@ void LifeMeter_UpdateSizeAndBeep(PlayState* play) { } } -u32 LifeMeter_IsCritical(void) { +bool LifeMeter_IsCritical(void) { s16 criticalThreshold; if (gSaveContext.save.saveInfo.playerData.healthCapacity <= 0x50) { diff --git a/mm/src/code/z_map_exp.c b/mm/src/code/z_map_exp.c index 0e4849f3a..c99eb1ef9 100644 --- a/mm/src/code/z_map_exp.c +++ b/mm/src/code/z_map_exp.c @@ -227,6 +227,8 @@ void Map_Init(PlayState* play) { } void Map_DrawMinimap(PlayState* play) { + // BENTODO: crash + return; MapDisp_DrawMinimap(play, sPlayerInitPosX, sPlayerInitPosZ, sPlayerInitDir); } diff --git a/mm/src/code/z_message.c b/mm/src/code/z_message.c index c10dabe2d..202dd6575 100644 --- a/mm/src/code/z_message.c +++ b/mm/src/code/z_message.c @@ -5,6 +5,7 @@ #include "message_data_static.h" #include "interface/parameter_static/parameter_static.h" #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" +#include "BenPort.h" u8 D_801C6A70 = 0; s16 sOcarinaButtonIndexBufPos = 0; @@ -50,7 +51,7 @@ u16 gBombersNotebookWeekEventFlags[BOMBERS_NOTEBOOK_EVENT_MAX] = { // TODO: Scripts // Include message tables D_801C6B98 and D_801CFB08 -#include "src/code/z_message_tables.inc.c" +#include "src/code/z_message_tables.inc" s16 D_801CFC78[TEXTBOX_TYPE_MAX] = { 0, // TEXTBOX_TYPE_0 @@ -1819,6 +1820,8 @@ s16 D_801CFF94[] = { void Message_LoadItemIcon(PlayState* play, u16 itemId, s16 arg2) { MessageContext* msgCtx = &play->msgCtx; u16* new_var2 = &itemId; + itemId = 0; + // BENTODO: Test if (itemId == ITEM_RECOVERY_HEART) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF88[gSaveContext.options.language]); @@ -1836,37 +1839,40 @@ void Message_LoadItemIcon(PlayState* play, u16 itemId, s16 arg2) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF88[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 0xA); msgCtx->unk12014 = 0x10; - CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_static_yar), ITEM_SONG_SONATA, msgCtx->textboxSegment + 0x1000, - 0x180); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[ITEM_SONG_SONATA]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x1000); } else if (itemId == ITEM_BOMBERS_NOTEBOOK) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF70[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 6); msgCtx->unk12014 = 0x20; - CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_static_yar), ITEM_SONG_SONATA, msgCtx->textboxSegment + 0x1000, - 0x1000); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[ITEM_SONG_SONATA]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x1000); } else if (itemId <= ITEM_REMAINS_TWINMOLD) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF70[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 6); msgCtx->unk12014 = 0x20; - CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_static_yar), itemId, msgCtx->textboxSegment + 0x1000, 0x1000); + // BENTODO this wasn't done in the minibuild + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[itemId]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x1000); + //CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_static_yar), itemId, msgCtx->textboxSegment + 0x1000, 0x1000); } else if (itemId == ITEM_CC) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF70[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 8); msgCtx->unk12014 = 0x20; - CmpDma_LoadFile(SEGMENT_ROM_START(schedule_dma_static_yar), ITEM_POTION_BLUE, msgCtx->textboxSegment + 0x1000, - 0x400); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[ITEM_POTION_BLUE]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x400); } else if (itemId >= ITEM_B8) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF70[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 8); msgCtx->unk12014 = 0x20; - CmpDma_LoadFile(SEGMENT_ROM_START(schedule_dma_static_yar), (itemId - ITEM_B8), msgCtx->textboxSegment + 0x1000, - 0x800); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[itemId - ITEM_B8]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x800); } else if (itemId >= ITEM_SKULL_TOKEN) { msgCtx->unk12010 = (msgCtx->unk11FF8 - D_801CFF7C[gSaveContext.options.language]); msgCtx->unk12012 = (arg2 + 0xA); msgCtx->unk12014 = 0x18; - CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_24_static_yar), (itemId - ITEM_SKULL_TOKEN), - msgCtx->textboxSegment + 0x1000, 0x900); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[itemId - ITEM_SKULL_TOKEN]); + memcpy(msgCtx->textboxSegment + 0x1000, tex, 0x900); } if (play->pauseCtx.bombersNotebookOpen) { @@ -2175,6 +2181,9 @@ void Message_Decode(PlayState* play) { u16 curChar; u8 index2 = 0; + //BENTODO do this somewhere else + gSaveContext.options.language = LANGUAGE_ENG; + msgCtx->textDelayTimer = 0; msgCtx->textDelay = msgCtx->textDelayTimer; msgCtx->textFade = 0; @@ -2270,9 +2279,10 @@ void Message_Decode(PlayState* play) { decodedBufPos += playerNameLen - 1; spC0 += playerNameLen * (16.0f * msgCtx->textCharScale); } else if (curChar == 0x201) { - DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1000, SEGMENT_ROM_START(message_texture_static), 0x900); - DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1900, SEGMENT_ROM_START(message_texture_static) + 0x900, - 0x900); + // BENTODO + //DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1000, SEGMENT_ROM_START(message_texture_static), 0x900); + //DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1900, SEGMENT_ROM_START(message_texture_static) + 0x900, + // 0x900); numLines = 2; spD2 = 2; msgCtx->unk12012 = msgCtx->textboxY + 8; @@ -3038,8 +3048,9 @@ void func_80150A84(PlayState* play) { s32 textBoxType = msgCtx->textBoxType; if (D_801CFC78[textBoxType] != 14) { - DmaMgr_SendRequest0(msgCtx->textboxSegment, - SEGMENT_ROM_START(message_static) + D_801CFC78[textBoxType] * 0x1000, 0x1000); + // BENTODO + //DmaMgr_SendRequest0(msgCtx->textboxSegment, + // SEGMENT_ROM_START(message_static) + D_801CFC78[textBoxType] * 0x1000, 0x1000); if (!play->pauseCtx.bombersNotebookOpen) { if ((textBoxType == TEXTBOX_TYPE_0) || (textBoxType == TEXTBOX_TYPE_6) || (textBoxType == TEXTBOX_TYPE_A) || @@ -3090,12 +3101,15 @@ void Message_OpenText(PlayState* play, u16 textId) { Player* player = GET_PLAYER(play); f32 var_fv0; + // BENTODO do this somewhere else + gSaveContext.options.language = LANGUAGE_ENG; + if (play->msgCtx.msgMode == MSGMODE_NONE) { gSaveContext.prevHudVisibility = gSaveContext.hudVisibility; } if (textId == 0xFF) { - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); play->msgCtx.hudVisibility = gSaveContext.hudVisibility; Interface_SetHudVisibility(HUD_VISIBILITY_A_B_C); gSaveContext.save.unk_06 = 20; @@ -3162,23 +3176,26 @@ void Message_OpenText(PlayState* play, u16 textId) { sCharTexSize = msgCtx->textCharScale * 16.0f; sCharTexScale = 1024.0f / msgCtx->textCharScale; D_801F6B08 = 1024.0f / var_fv0; - + // BENTODO all of these if (msgCtx->textIsCredits) { Message_FindCreditsMessage(play, textId); msgCtx->msgLength = font->messageEnd; - DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(staff_message_data_static) + font->messageStart, - font->messageEnd); + //DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(staff_message_data_static) + font->messageStart, + // font->messageEnd); } else if (gSaveContext.options.language == LANGUAGE_JPN) { Message_FindMessage(play, textId); msgCtx->msgLength = font->messageEnd; - DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, - font->messageEnd); + //DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, + // font->messageEnd); } else { Message_FindMessageNES(play, textId); - msgCtx->msgLength = font->messageEnd; - DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, - font->messageEnd); - } + MessageTableEntry* msgEntry = (MessageTableEntry*)font->messageStart; + msgCtx->msgLength = msgEntry->msgSize; + memcpy(&font->msgBuf, msgEntry->segment, msgEntry->msgSize); + //msgCtx->msgLength = font->messageEnd; + //DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, + // font->messageEnd); + } // msgCtx->choiceNum = 0; msgCtx->textUnskippable = false; @@ -3231,6 +3248,8 @@ void func_801514B0(PlayState* play, u16 arg1, u8 arg2) { Font* font = &msgCtx->font; Player* player = GET_PLAYER(play); f32 temp = 1024.0f; + // BENTODO do this somewhere else + gSaveContext.options.language = LANGUAGE_ENG; msgCtx->ocarinaAction = 0xFFFF; @@ -3265,13 +3284,18 @@ void func_801514B0(PlayState* play, u16 arg1, u8 arg2) { if (gSaveContext.options.language == LANGUAGE_JPN) { Message_FindMessage(play, arg1); msgCtx->msgLength = font->messageEnd; - DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, - font->messageEnd); + // BENTODO + //DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, + // font->messageEnd); } else { Message_FindMessageNES(play, arg1); - msgCtx->msgLength = font->messageEnd; - DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, - font->messageEnd); + MessageTableEntry* msgEntry = (MessageTableEntry*)font->messageStart; + msgCtx->msgLength = msgEntry->msgSize; + memcpy(&font->msgBuf, msgEntry->segment, msgEntry->msgSize); + //msgCtx->msgLength = font->messageEnd; + // BENTODO + //DmaMgr_SendRequest0(&font->msgBuf, SEGMENT_ROM_START(message_data_static) + font->messageStart, + // font->messageEnd); } msgCtx->choiceNum = 0; msgCtx->textUnskippable = false; @@ -3285,7 +3309,8 @@ void func_801514B0(PlayState* play, u16 arg1, u8 arg2) { msgCtx->textBoxPos = arg2; msgCtx->unk11F0C = msgCtx->unk11F08 & 0xF; msgCtx->textUnskippable = true; - DmaMgr_SendRequest0(msgCtx->textboxSegment, SEGMENT_ROM_START(message_static) + (D_801CFC78[0] << 12), 0x1000); + // BENTODO + //DmaMgr_SendRequest0(msgCtx->textboxSegment, SEGMENT_ROM_START(message_static) + (D_801CFC78[0] << 12), 0x1000); msgCtx->textboxColorRed = 0; msgCtx->textboxColorGreen = 0; msgCtx->textboxColorBlue = 0; @@ -3555,7 +3580,7 @@ void Message_DisplayOcarinaStaffImpl(PlayState* play, u16 ocarinaAction) { msgCtx->textboxColorAlphaCurrent = msgCtx->textboxColorAlphaTarget; if (!noStop) { - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); noStop = gSaveContext.hudVisibility; Interface_SetHudVisibility(HUD_VISIBILITY_B_ALT); gSaveContext.hudVisibility = noStop; @@ -4154,6 +4179,8 @@ void Message_DrawMain(PlayState* play, Gfx** gfxP) { s32 j; s16 temp_v0_33; s16 temp; + // BENTODO + msgCtx->textIsCredits = false; gfx = *gfxP; @@ -5683,7 +5710,7 @@ void Message_Update(PlayState* play) { Message_CloseTextbox(play); play->msgCtx.ocarinaMode = OCARINA_MODE_END; gSaveContext.prevHudVisibility = HUD_VISIBILITY_A_B; - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); GameState_SetFramerateDivisor(&play->state, 2); if (ShrinkWindow_Letterbox_GetSizeTarget() != 0) { ShrinkWindow_Letterbox_SetSizeTarget(0); @@ -5989,8 +6016,9 @@ void Message_Update(PlayState* play) { } void Message_SetTables(PlayState* play) { - play->msgCtx.messageEntryTableNes = D_801C6B98; - play->msgCtx.messageTableStaff = D_801CFB08; + //play->msgCtx.messageEntryTableNes = D_801C6B98; + //play->msgCtx.messageTableStaff = D_801CFB08; + OTRMessage_Init(play); } void Message_Init(PlayState* play) { diff --git a/mm/src/code/z_message_nes.c b/mm/src/code/z_message_nes.c index ebbd40ab0..79c2cb4c2 100644 --- a/mm/src/code/z_message_nes.c +++ b/mm/src/code/z_message_nes.c @@ -25,11 +25,13 @@ void Message_FindMessageNES(PlayState* play, u16 textId) { while (msgEntry->textId != 0xFFFF) { if (msgEntry->textId == textId) { + font->messageStart = msgEntry; foundSegment = msgEntry->segment; msgEntry++; nextSegment = msgEntry->segment; - font->messageStart = foundSegment - segment; - font->messageEnd = nextSegment - foundSegment; + + //font->messageStart = foundSegment - segment; + //font->messageEnd = nextSegment - foundSegment; return; } msgEntry++; @@ -410,7 +412,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { for (i = textDrawPos; i < msgCtx->textDrawPos; i++) { character = msgCtx->decodedBuffer.schar[i]; - switch (character) { + switch ((u8)character) { case 0x0: if (play->pauseCtx.bombersNotebookOpen || (msgCtx->textBoxType == TEXTBOX_TYPE_D)) { msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 0; @@ -434,7 +436,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { case 0x7: case 0x8: if ((msgCtx->msgMode >= MSGMODE_NEW_CYCLE_0) && (msgCtx->msgMode <= MSGMODE_OWL_SAVE_2) && - (character == 0x2)) { + ((u8)character == 0x2)) { msgCtx->textDrawPos = msgCtx->decodedTextLen; if (msgCtx->unk120D6) { msgCtx->unk120D4 += 25; @@ -448,40 +450,40 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { } } - if (D_801D07DC[(s16)(character - 1)].r + msgCtx->unk120D4 < 0) { + if (D_801D07DC[(s16)((u8)character - 1)].r + msgCtx->unk120D4 < 0) { msgCtx->textColorR = 0; } else { - msgCtx->textColorR = D_801D07DC[(s16)(character - 1)].r + msgCtx->unk120D4; + msgCtx->textColorR = D_801D07DC[(s16)((u8)character - 1)].r + msgCtx->unk120D4; } - if (D_801D07DC[(s16)(character - 1)].g + msgCtx->unk120D4 >= 255) { - msgCtx->textColorG = D_801D07DC[(s16)(character - 1)].g; + if (D_801D07DC[(s16)((u8)character - 1)].g + msgCtx->unk120D4 >= 255) { + msgCtx->textColorG = D_801D07DC[(s16)((u8)character - 1)].g; } else { - msgCtx->textColorG = D_801D07DC[(s16)(character - 1)].g + msgCtx->unk120D4; + msgCtx->textColorG = D_801D07DC[(s16)((u8)character - 1)].g + msgCtx->unk120D4; } - if (D_801D07DC[(s16)(character - 1)].b + msgCtx->unk120D4 < 0) { + if (D_801D07DC[(s16)((u8)character - 1)].b + msgCtx->unk120D4 < 0) { msgCtx->textColorB = 0; } else { - msgCtx->textColorB = D_801D07DC[(s16)(character - 1)].b + msgCtx->unk120D4; + msgCtx->textColorB = D_801D07DC[(s16)((u8)character - 1)].b + msgCtx->unk120D4; } } else if (play->pauseCtx.bombersNotebookOpen) { - msgCtx->textColorR = D_801D089C[(s16)(character - 1)].r; - msgCtx->textColorG = D_801D089C[(s16)(character - 1)].g; - msgCtx->textColorB = D_801D089C[(s16)(character - 1)].b; + msgCtx->textColorR = D_801D089C[(s16)((u8)character - 1)].r; + msgCtx->textColorG = D_801D089C[(s16)((u8)character - 1)].g; + msgCtx->textColorB = D_801D089C[(s16)((u8)character - 1)].b; } else if (msgCtx->textBoxType == TEXTBOX_TYPE_1) { - msgCtx->textColorR = D_801D07DC[(s16)(character - 1)].r; - msgCtx->textColorG = D_801D07DC[(s16)(character - 1)].g; - msgCtx->textColorB = D_801D07DC[(s16)(character - 1)].b; + msgCtx->textColorR = D_801D07DC[(s16)((u8)character - 1)].r; + msgCtx->textColorG = D_801D07DC[(s16)((u8)character - 1)].g; + msgCtx->textColorB = D_801D07DC[(s16)((u8)character - 1)].b; } else if (msgCtx->textBoxType == TEXTBOX_TYPE_D) { - msgCtx->textColorR = D_801D086C[(s16)(character - 1)].r; - msgCtx->textColorG = D_801D086C[(s16)(character - 1)].g; - msgCtx->textColorB = D_801D086C[(s16)(character - 1)].b; + msgCtx->textColorR = D_801D086C[(s16)((u8)character - 1)].r; + msgCtx->textColorG = D_801D086C[(s16)((u8)character - 1)].g; + msgCtx->textColorB = D_801D086C[(s16)((u8)character - 1)].b; } else { - msgCtx->textColorR = D_801D080C[(s16)(character - 1)].r; - msgCtx->textColorG = D_801D080C[(s16)(character - 1)].g; - msgCtx->textColorB = D_801D080C[(s16)(character - 1)].b; + msgCtx->textColorR = D_801D080C[(s16)((u8)character - 1)].r; + msgCtx->textColorG = D_801D080C[(s16)((u8)character - 1)].g; + msgCtx->textColorB = D_801D080C[(s16)((u8)character - 1)].b; } if ((i + 1) == msgCtx->textDrawPos) { @@ -634,7 +636,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { case 0xA: i++; character = msgCtx->decodedBuffer.schar[i]; - switch (character) { + switch ((u8)character) { case 0x0: case 0x1: case 0x2: @@ -642,7 +644,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { case 0x4: case 0x5: case 0x6: - msgCtx->textDelay = character - 0x0; + msgCtx->textDelay = (u8)character - 0x0; if ((i + 1) == msgCtx->textDrawPos) { msgCtx->textDrawPos++; } @@ -777,7 +779,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { msgCtx->msgMode = MSGMODE_TEXT_DONE; if (msgCtx->textboxEndType == 0) { Audio_PlaySfx(NA_SE_SY_MESSAGE_END); - if (character == 0xBF) { + if ((u8)character == 0xBF) { Font_LoadMessageBoxEndIcon(font, 1); } else { Font_LoadMessageBoxEndIcon(font, 0); @@ -843,13 +845,19 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { if ((msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) && ((i + 1) == msgCtx->textDrawPos)) { Audio_PlaySfx(NA_SE_NONE); } - if ((character >= 0xB0) && (character <= 0xBB)) { + + if (((u8)character >= 0xB0) && ((u8)character <= 0xBB)) { + } else { + printf("Unhandled or default character: 0x%04X\n", character); + } + + if (((u8)character >= 0xB0) && ((u8)character <= 0xBB)) { sp12E = msgCtx->textColorR; sp12C = msgCtx->textColorG; sp12A = msgCtx->textColorB; - msgCtx->textColorR = D_801D083C[(s16)D_801D08CC[character - 0xB0]].r; - msgCtx->textColorG = D_801D083C[(s16)D_801D08CC[character - 0xB0]].g; - msgCtx->textColorB = D_801D083C[(s16)D_801D08CC[character - 0xB0]].b; + msgCtx->textColorR = D_801D083C[(s16)D_801D08CC[(u8)character - 0xB0]].r; + msgCtx->textColorG = D_801D083C[(s16)D_801D08CC[(u8)character - 0xB0]].g; + msgCtx->textColorB = D_801D083C[(s16)D_801D08CC[(u8)character - 0xB0]].b; Message_DrawTextChar(play, &font->charBuf[font->unk_11D88][charTexIndex], &gfx); msgCtx->textColorR = sp12E; msgCtx->textColorG = sp12C; @@ -899,7 +907,7 @@ void Message_DrawTextNES(PlayState* play, Gfx** gfxP, u16 textDrawPos) { ((msgCtx->unk120C0 + 1) >= i))) { msgCtx->textPosX += (s32)(16.0f * msgCtx->textCharScale); } else { - msgCtx->textPosX += (s32)(sNESFontWidths[character - ' '] * msgCtx->textCharScale); + msgCtx->textPosX += (s32)(sNESFontWidths[(u8)character - ' '] * msgCtx->textCharScale); } break; } @@ -1084,9 +1092,10 @@ void Message_DecodeNES(PlayState* play) { } decodedBufPos--; } else if (curChar == 0xC1) { - DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1000, SEGMENT_ROM_START(message_texture_static), 0x900); - DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1900, SEGMENT_ROM_START(message_texture_static) + 0x900, - 0x900); + // BENTODO + //DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1000, SEGMENT_ROM_START(message_texture_static), 0x900); + //DmaMgr_SendRequest0(msgCtx->textboxSegment + 0x1900, SEGMENT_ROM_START(message_texture_static) + 0x900, + // 0x900); numLines = 2; spC6 = 2; msgCtx->unk12012 = msgCtx->textboxY + 8; diff --git a/mm/src/code/z_message_tables.inc.c b/mm/src/code/z_message_tables.inc similarity index 100% rename from mm/src/code/z_message_tables.inc.c rename to mm/src/code/z_message_tables.inc diff --git a/mm/src/code/z_overlay.c b/mm/src/code/z_overlay.c index fe0857820..b24a807fd 100644 --- a/mm/src/code/z_overlay.c +++ b/mm/src/code/z_overlay.c @@ -35,7 +35,8 @@ void TransitionOverlay_VramToRamArray(TransitionOverlay* overlayEntry, void** vr s32 TransitionOverlay_Load(TransitionOverlay* overlayEntry) { s32 count; void* loadedRamAddr; - + return 3; + #if 0 if (overlayEntry->vromStart == 0) { return 3; } @@ -63,6 +64,7 @@ s32 TransitionOverlay_Load(TransitionOverlay* overlayEntry) { } return 2; } + #endif } s32 TransitionOverlay_Free(TransitionOverlay* overlayEntry) { diff --git a/mm/src/code/z_parameter.c b/mm/src/code/z_parameter.c index d076f3578..c626e66db 100644 --- a/mm/src/code/z_parameter.c +++ b/mm/src/code/z_parameter.c @@ -11,6 +11,19 @@ #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" #include "overlays/actors/ovl_En_Mm3/z_en_mm3.h" +#include "interface/week_static/week_static.h" +#include "BenPort.h" + +#include + +#define dgEmptyTexture "__OTR__textures/virtual/gEmptyTexture" +static const ALIGN_ASSET(2) char gEmptyTexture[] = dgEmptyTexture; + +static u8* sCounterDigits[] = { + (u8*)gCounterDigit0Tex, (u8*)gCounterDigit1Tex, (u8*)gCounterDigit2Tex, (u8*)gCounterDigit3Tex, + (u8*)gCounterDigit4Tex, (u8*)gCounterDigit5Tex, (u8*)gCounterDigit6Tex, (u8*)gCounterDigit7Tex, + (u8*)gCounterDigit8Tex, (u8*)gCounterDigit9Tex, +}; typedef enum { /* 0 */ PICTO_BOX_STATE_OFF, // Not using the pictograph @@ -908,6 +921,12 @@ u32 Interface_GetCompressedTimerDigits(s16 timerId) { (timerArr[4] << 4) | timerArr[5]; } +static const char* sDoWeekTable[] = { + gClockDay1stTex, + gClockDay2ndTex, + gClockDayFinalTex, +}; + void Interface_NewDay(PlayState* play, s32 day) { s32 pad; s16 i = day - 1; @@ -917,9 +936,7 @@ void Interface_NewDay(PlayState* play, s32 day) { i = 0; } - // Loads day number from week_static for the three-day clock - DmaMgr_SendRequest0((void*)(play->interfaceCtx.doActionSegment + 0x780), - SEGMENT_ROM_START_OFFSET(week_static, i * 0x510), 0x510); + play->interfaceCtx.doActionSegment[CLOCK_TIMER].mainTex = sDoWeekTable[i]; // i is used to store sceneId for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.permanentSceneFlags); i++) { @@ -2365,7 +2382,7 @@ void Interface_UpdateButtonsPart1(PlayState* play) { Message_CloseTextbox(play); if (play->msgCtx.choiceIndex != 0) { Audio_PlaySfx_MessageCancel(); - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); Interface_SetHudVisibility(HUD_VISIBILITY_A_B); sPictoState = PICTO_BOX_STATE_LENS; REMOVE_QUEST_ITEM(QUEST_PICTOGRAPH); @@ -2404,7 +2421,7 @@ void Interface_UpdateButtonsPart1(PlayState* play) { } else if (play->actorCtx.flags & ACTORCTX_FLAG_PICTO_BOX_ON) { // Related to pictograph if (!CHECK_QUEST_ITEM(QUEST_PICTOGRAPH)) { - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); Interface_SetHudVisibility(HUD_VISIBILITY_A_B); sPictoState = PICTO_BOX_STATE_LENS; } else { @@ -2473,8 +2490,8 @@ void Interface_InitMinigame(PlayState* play) { void Interface_LoadItemIconImpl(PlayState* play, u8 btn) { InterfaceContext* interfaceCtx = &play->interfaceCtx; - CmpDma_LoadFile(SEGMENT_ROM_START(icon_item_static_yar), GET_CUR_FORM_BTN_ITEM(btn), - &interfaceCtx->iconItemSegment[(u32)btn * 0x1000], 0x1000); + void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[(s32)GET_CUR_FORM_BTN_ITEM(btn)]); + memcpy(&interfaceCtx->iconItemSegment[(u32)btn * 0x1000], tex, 0x1000); } void Interface_LoadItemIcon(PlayState* play, u8 btn) { @@ -3275,7 +3292,7 @@ void Interface_LoadAButtonDoActionLabel(InterfaceContext* interfaceCtx, u16 acti DmaMgr_SendRequestImpl(&interfaceCtx->dmaRequest, (u32)interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), (u32)SEGMENT_ROM_START(do_action_static) + (action * DO_ACTION_TEX_SIZE), - DO_ACTION_TEX_SIZE, 0, &interfaceCtx->loadQueue, 0); + DO_ACTION_TEX_SIZE, 0, &interfaceCtx->loadQueue, OS_MESG_PTR(NULL)); osRecvMesg(&interfaceCtx->loadQueue, NULL, OS_MESG_BLOCK); } else { gSegments[0x09] = PHYSICAL_TO_VIRTUAL(interfaceCtx->doActionSegment); @@ -3283,6 +3300,18 @@ void Interface_LoadAButtonDoActionLabel(InterfaceContext* interfaceCtx, u16 acti } } +static const char* doActionTbl[] = { + gDoActionAttackENGTex, gDoActionCheckENGTex, gDoActionEnterENGTex, gDoActionReturnENGTex, gDoActionOpenENGTex, + gDoActionJumpENGTex, gDoActionDecideENGTex, gDoActionDiveENGTex, gDoActionFasterENGTex, gDoActionThrowENGTex, + gDoActionNaviENGTex, gDoActionClimbENGTex, gDoActionDropENGTex, gDoActionDownENGTex, gDoActionQuitENGTex, + gDoActionSpeakENGTex, gDoActionNextENGTex, gDoActionGrabENGTex, gDoActionStopENGTex, gDoActionPutAwayENGTex, + gDoActionReelENGTex, gDoActionInfoENGTex, gDoActionWarpENGTex, gDoActionSnapENGTex, gDoActionExplodeENGTex, + gDoActionDanceENGTex, gDoActionMarchENGTex, gDoActionNum1ENGTex, gDoActionNum2ENGTex, gDoActionNum3ENGTex, + gDoActionNum4ENGTex, gDoActionNum5ENGTex, gDoActionNum6ENGTex, gDoActionNum7ENGTex, gDoActionNum8ENGTex, + gDoActionCurlENGTex, gDoActionSurfaceENGTex, gDoActionSwimENGTex, gDoActionPunchENGTex, gDoActionPoundENGTex, + gDoActionHookENGTex, gDoActionShootENGTex, +}; + void Interface_SetAButtonDoAction(PlayState* play, u16 aButtonDoAction) { InterfaceContext* interfaceCtx = &play->interfaceCtx; PauseContext* pauseCtx = &play->pauseCtx; @@ -3291,7 +3320,7 @@ void Interface_SetAButtonDoAction(PlayState* play, u16 aButtonDoAction) { interfaceCtx->aButtonDoAction = aButtonDoAction; interfaceCtx->aButtonState = A_BTN_STATE_1; interfaceCtx->aButtonRoll = 0.0f; - Interface_LoadAButtonDoActionLabel(interfaceCtx, aButtonDoAction, 1); + Interface_LoadButtonDoActionLabel(play, aButtonDoAction, A_BUTTON_ACTION, ACTION_SUB); if (pauseCtx->state != PAUSE_STATE_OFF) { interfaceCtx->aButtonState = A_BTN_STATE_3; } @@ -3310,11 +3339,7 @@ void Interface_SetBButtonDoAction(PlayState* play, s16 bButtonDoAction) { } else { interfaceCtx->bButtonDoAction = bButtonDoAction; if (interfaceCtx->bButtonDoAction != DO_ACTION_NONE) { - osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, 1); - DmaMgr_SendRequestImpl(&interfaceCtx->dmaRequest, interfaceCtx->doActionSegment + 0x600, - (bButtonDoAction * 0x180) + SEGMENT_ROM_START(do_action_static), 0x180, 0, - &interfaceCtx->loadQueue, NULL); - osRecvMesg(&interfaceCtx->loadQueue, NULL, OS_MESG_BLOCK); + Interface_LoadButtonDoActionLabel(play, interfaceCtx->bButtonDoAction, B_BUTTON_ACTION, ACTION_SUB); } interfaceCtx->bButtonDoActionActive = true; @@ -3346,18 +3371,30 @@ void Interface_SetTatlCall(PlayState* play, u16 tatlCallState) { } } -void Interface_LoadBButtonDoActionLabel(PlayState* play, s16 bButtonDoAction) { +void Interface_LoadButtonDoActionLabel(PlayState* play, s16 action, s16 button, s16 state) { + static void* sDoActionTextures[] = { gDoActionAttackENGTex, gDoActionCheckENGTex }; InterfaceContext* interfaceCtx = &play->interfaceCtx; - interfaceCtx->unk_224 = bButtonDoAction; + // OTRTODO: Validate btn states Eg. A_BTN_STATE_4 + if (action >= DO_ACTION_MAX) { + action = DO_ACTION_NONE; + } - osCreateMesgQueue(&play->interfaceCtx.loadQueue, &play->interfaceCtx.loadMsg, 1); - DmaMgr_SendRequestImpl(&interfaceCtx->dmaRequest, interfaceCtx->doActionSegment + 0x480, - (bButtonDoAction * 0x180) + SEGMENT_ROM_START(do_action_static), 0x180, 0, - &interfaceCtx->loadQueue, NULL); - osRecvMesg(&interfaceCtx->loadQueue, NULL, OS_MESG_BLOCK); + if (button == 1) { + interfaceCtx->unk_224 = action; + interfaceCtx->unk_222 = 1; + } - interfaceCtx->unk_222 = 1; + char* path = action != DO_ACTION_NONE ? doActionTbl[action] : gEmptyTexture; + + switch (state) { + case 0: + interfaceCtx->doActionSegment[button].mainTex = path; + break; + case 1: + interfaceCtx->doActionSegment[button].subTex = path; + break; + } } /** @@ -3800,7 +3837,7 @@ void Magic_Update(PlayState* play) { // fallthrough case MAGIC_STATE_CONSUME_GORON_ZORA: if ((play->pauseCtx.state == PAUSE_STATE_OFF) && (play->pauseCtx.debugEditor == DEBUG_EDITOR_NONE) && - (msgCtx->msgMode == 0) && (play->gameOverCtx.state == GAMEOVER_INACTIVE) && + (msgCtx->msgMode == MSGMODE_NONE) && (play->gameOverCtx.state == GAMEOVER_INACTIVE) && (play->transitionTrigger == TRANS_TRIGGER_OFF) && (play->transitionMode == TRANS_MODE_OFF)) { if (!Play_InCsMode(play)) { interfaceCtx->magicConsumptionTimer--; @@ -4015,8 +4052,8 @@ void Interface_DrawItemButtons(PlayState* play) { gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 0); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE * 2, G_IM_FMT_IA, - DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment[START_BUTTON_ACTION].mainTex, + G_IM_FMT_IA, DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPTextureRectangle(OVERLAY_DISP++, 0x01F8, 0x0054, 0x02D4, 0x009C, G_TX_RENDERTILE, 0, 0, 0x04A6, 0x04A6); } @@ -4074,9 +4111,9 @@ void Interface_DrawItemButtons(PlayState* play) { } else { // EQUIP_SLOT_C_RIGHT gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 240, 0, interfaceCtx->cRightAlpha); } - OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, ((u8*)gButtonBackgroundTex + ((32 * 32) * (temp + 1))), - 0x20, 0x20, D_801BF9D4[temp], D_801BF9DC[temp], D_801BFAF4[temp], - D_801BFAF4[temp], D_801BF9E4[temp] * 2, D_801BF9E4[temp] * 2); + OVERLAY_DISP = + Gfx_DrawTexRectIA8(OVERLAY_DISP, gButtonBackgroundTex, 0x20, 0x20, D_801BF9D4[temp], D_801BF9DC[temp], + D_801BFAF4[temp], D_801BFAF4[temp], D_801BF9E4[temp] * 2, D_801BF9E4[temp] * 2); } } @@ -4101,10 +4138,15 @@ void Interface_DrawItemIconTexture(PlayState* play, TexturePtr texture, s16 butt s16 D_801BFB04[] = { 0xA2, 0xE4, 0xFA, 0x110 }; s16 D_801BFB0C[] = { 0x23, 0x23, 0x33, 0x23 }; +// Not static so its visible in z_kaleido_item +const char* gAmmoDigitTextures[10] = { + gAmmoDigit0Tex, gAmmoDigit1Tex, gAmmoDigit2Tex, gAmmoDigit3Tex, gAmmoDigit4Tex, + gAmmoDigit5Tex, gAmmoDigit6Tex, gAmmoDigit7Tex, gAmmoDigit8Tex, gAmmoDigit9Tex, +}; + void Interface_DrawAmmoCount(PlayState* play, s16 button, s16 alpha) { u8 i; u16 ammo; - OPEN_DISPS(play->state.gfxCtx); i = ((void)0, GET_CUR_FORM_BTN_ITEM(button)); @@ -4153,12 +4195,12 @@ void Interface_DrawAmmoCount(PlayState* play, s16 button, s16 alpha) { // Draw upper digit (tens) if ((u32)i != 0) { - OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, ((u8*)gAmmoDigit0Tex + ((8 * 8) * i)), 8, 8, + OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, gAmmoDigitTextures[i], 8, 8, D_801BFB04[button], D_801BFB0C[button], 8, 8, 1 << 10, 1 << 10); } // Draw lower digit (ones) - OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, ((u8*)gAmmoDigit0Tex + ((8 * 8) * ammo)), 8, 8, + OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, gAmmoDigitTextures[i], 8, 8, D_801BFB04[button] + 6, D_801BFB0C[button], 8, 8, 1 << 10, 1 << 10); } @@ -4177,12 +4219,13 @@ void Interface_DrawBButtonIcons(PlayState* play) { if ((interfaceCtx->unk_222 == 0) && (player->stateFlags3 & PLAYER_STATE3_1000000)) { if (gSaveContext.buttonStatus[EQUIP_SLOT_B] != BTN_DISABLED) { + gSPInvalidateTexCache(OVERLAY_DISP++, interfaceCtx->iconItemSegment); Interface_DrawItemIconTexture(play, interfaceCtx->iconItemSegment, EQUIP_SLOT_B); gDPPipeSync(OVERLAY_DISP++); gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); - - Interface_DrawAmmoCount(play, EQUIP_SLOT_B, interfaceCtx->bAlpha); + // BENTODO + // Interface_DrawAmmoCount(play, EQUIP_SLOT_B, interfaceCtx->bAlpha); } } else if ((!interfaceCtx->bButtonDoActionActive && (interfaceCtx->unk_222 == 0)) || ((interfaceCtx->bButtonDoActionActive && @@ -4203,7 +4246,7 @@ void Interface_DrawBButtonIcons(PlayState* play) { (play->sceneId != SCENE_BOWLING) && ((gSaveContext.minigameStatus != MINIGAME_STATUS_ACTIVE) || (gSaveContext.save.entrance != ENTRANCE(ROMANI_RANCH, 0))) && - ((gSaveContext.minigameStatus != MINIGAME_STATUS_ACTIVE) || !(CHECK_EVENTINF(EVENTINF_35))) && + ((gSaveContext.minigameStatus != MINIGAME_STATUS_ACTIVE) || !CHECK_EVENTINF(EVENTINF_35)) && (!CHECK_WEEKEVENTREG(WEEKEVENTREG_31_80) || (play->bButtonAmmoPlusOne != 100))) { Interface_DrawAmmoCount(play, EQUIP_SLOT_B, interfaceCtx->bAlpha); } @@ -4215,8 +4258,8 @@ void Interface_DrawBButtonIcons(PlayState* play) { gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->bAlpha); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + 0x480, G_IM_FMT_IA, 48, 16, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment[B_BUTTON_ACTION].mainTex, G_IM_FMT_IA, 48, + 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); D_801BF9B0 = 1024.0f / (D_801BF9B4[gSaveContext.options.language] / 100.0f); @@ -4230,8 +4273,8 @@ void Interface_DrawBButtonIcons(PlayState* play) { gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->bAlpha); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + 0x600, G_IM_FMT_IA, 48, 16, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment[B_BUTTON_ACTION].subTex, G_IM_FMT_IA, 48, + 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); D_801BF9B0 = 1024.0f / (D_801BF9B4[gSaveContext.options.language] / 100.0f); @@ -4351,10 +4394,10 @@ void Interface_DrawAButton(PlayState* play) { // Draw Action Label if (((interfaceCtx->aButtonState <= A_BTN_STATE_1) || (interfaceCtx->aButtonState == A_BTN_STATE_3))) { - OVERLAY_DISP = Gfx_DrawTexQuad4b(OVERLAY_DISP, interfaceCtx->doActionSegment, 3, DO_ACTION_TEX_WIDTH, - DO_ACTION_TEX_HEIGHT, 0); + OVERLAY_DISP = Gfx_DrawTexQuad4b(OVERLAY_DISP, interfaceCtx->doActionSegment[A_BUTTON_ACTION].mainTex, 3, + DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0); } else { - OVERLAY_DISP = Gfx_DrawTexQuad4b(OVERLAY_DISP, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, 3, + OVERLAY_DISP = Gfx_DrawTexQuad4b(OVERLAY_DISP, interfaceCtx->doActionSegment[A_BUTTON_ACTION].subTex, 3, DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0); } @@ -4420,9 +4463,10 @@ void Interface_DrawPauseMenuEquippingIcons(PlayState* play) { } gSPVertex(OVERLAY_DISP++, &pauseCtx->cursorVtx[16], 4, 0); - gDPLoadTextureBlock(OVERLAY_DISP++, gMagicArrowEquipEffectTex, G_IM_FMT_IA, G_IM_SIZ_8b, 32, 32, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); + // BENTODO + // gDPLoadTextureBlock(OVERLAY_DISP++, gMagicArrowEquipEffectTex, G_IM_FMT_IA, G_IM_SIZ_8b, 32, 32, 0, + // G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + // G_TX_NOLOD, G_TX_NOLOD); } gSP1Quadrangle(OVERLAY_DISP++, 0, 2, 3, 1, 0); @@ -4444,7 +4488,6 @@ void Interface_DrawClock(PlayState* play) { CLOCK_TIME(10, 0), CLOCK_TIME(11, 0), CLOCK_TIME(12, 0), CLOCK_TIME(13, 0), CLOCK_TIME(14, 0), CLOCK_TIME(15, 0), CLOCK_TIME(16, 0), CLOCK_TIME(17, 0), CLOCK_TIME(18, 0), CLOCK_TIME(19, 0), CLOCK_TIME(20, 0), CLOCK_TIME(21, 0), CLOCK_TIME(22, 0), CLOCK_TIME(23, 0), CLOCK_TIME(24, 0) - 1, - CLOCK_TIME(0, 0), }; static TexturePtr sThreeDayClockHourTextures[] = { gThreeDayClockHour12Tex, gThreeDayClockHour1Tex, gThreeDayClockHour2Tex, gThreeDayClockHour3Tex, @@ -4569,7 +4612,7 @@ void Interface_DrawClock(PlayState* play) { //! resulting in this reading into the next texture. This results in a white //! dot in the bottom center of the clock. For the three-day clock, this is //! covered by the diamond. However, it can be seen by the final-hours clock. - OVERLAY_DISP = Gfx_DrawTexRect4b(OVERLAY_DISP, gThreeDayClockBorderTex, 4, 64, 50, 96, 168, 128, 50, 1, 6, + OVERLAY_DISP = Gfx_DrawTexRect4b(OVERLAY_DISP, gThreeDayClockBorderTex, 4, 64, 48, 96, 168, 128, 50, 1, 6, 0, 1 << 10, 1 << 10); if (((CURRENT_DAY >= 4) || @@ -4674,8 +4717,8 @@ void Interface_DrawClock(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 155, sThreeDayClockAlpha); - OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, interfaceCtx->doActionSegment + 0x780, 48, 27, 137, 192, - 48, 27, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectIA8(OVERLAY_DISP, interfaceCtx->doActionSegment[CLOCK_TIMER].mainTex, 48, + 27, 137, 192, 48, 27, 1 << 10, 1 << 10); /** * Section: Draw Three-Day Clock's Star (for the Minute Tracker) @@ -4832,7 +4875,8 @@ void Interface_DrawClock(PlayState* play) { gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 155, sThreeDayClockAlpha); gSP1Quadrangle(OVERLAY_DISP++, 4, 6, 7, 5, 0); - gSPDisplayList(OVERLAY_DISP++, D_0E000000.setScissor); + __gSPDisplayList(OVERLAY_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); // Final Hours if ((CURRENT_DAY >= 4) || @@ -6008,7 +6052,7 @@ void Interface_DrawTimers(PlayState* play) { // draw sTimerDigits[3] (10s of seconds) to sTimerDigits[6] (100s of milliseconds) for (j = 0; j < 4; j++) { OVERLAY_DISP = Gfx_DrawTexRectI8( - OVERLAY_DISP, ((u8*)gCounterDigit0Tex + (8 * 16 * sTimerDigits[j + 3])), 8, 0x10, + OVERLAY_DISP, sCounterDigits[sTimerDigits[j + 3]], 8, 0x10, ((void)0, gSaveContext.timerX[sTimerId]) + sTimerDigitsOffsetX[j], ((void)0, gSaveContext.timerY[sTimerId]), sTimerDigitsWidth[j], 0xFA, 0x370, 0x370); } @@ -6016,7 +6060,7 @@ void Interface_DrawTimers(PlayState* play) { // draw sTimerDigits[3] (10s of seconds) to sTimerDigits[7] (10s of milliseconds) for (j = 0; j < 5; j++) { OVERLAY_DISP = Gfx_DrawTexRectI8( - OVERLAY_DISP, ((u8*)gCounterDigit0Tex + (8 * 16 * sTimerDigits[j + 3])), 8, 0x10, + OVERLAY_DISP, sCounterDigits[sTimerDigits[j + 3]], 8, 0x10, ((void)0, gSaveContext.timerX[sTimerId]) + sTimerDigitsOffsetX[j], ((void)0, gSaveContext.timerY[sTimerId]), sTimerDigitsWidth[j], 0xFA, 0x370, 0x370); } @@ -6025,7 +6069,7 @@ void Interface_DrawTimers(PlayState* play) { // draw sTimerDigits[3] (6s of minutes) to sTimerDigits[7] (10s of milliseconds) for (j = 0; j < 8; j++) { OVERLAY_DISP = Gfx_DrawTexRectI8( - OVERLAY_DISP, ((u8*)gCounterDigit0Tex + (8 * 16 * sTimerDigits[j])), 8, 0x10, + OVERLAY_DISP, sCounterDigits[sTimerDigits[j]], 8, 0x10, ((void)0, gSaveContext.timerX[sTimerId]) + sTimerDigitsOffsetX[j], ((void)0, gSaveContext.timerY[sTimerId]), sTimerDigitsWidth[j], 0xFA, 0x370, 0x370); } @@ -6209,9 +6253,8 @@ void Interface_DrawMinigameIcons(PlayState* play) { for (i = 0, numDigitsDrawn = 0; i < 4; i++) { if ((sMinigameScoreDigits[i] != 0) || (numDigitsDrawn != 0) || (i >= 3)) { - OVERLAY_DISP = - Gfx_DrawTexRectI8(OVERLAY_DISP, ((u8*)gCounterDigit0Tex + (8 * 16 * sMinigameScoreDigits[i])), - 8, 0x10, rectX, rectY - 2, 9, 0xFA, 0x370, 0x370); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[sMinigameScoreDigits[i]], 8, 0x10, + rectX, rectY - 2, 9, 0xFA, 0x370, 0x370); rectX += 9; numDigitsDrawn++; } @@ -6268,6 +6311,8 @@ TexturePtr sStoryTLUTs[] = { }; void Interface_Draw(PlayState* play) { + // BENTODO: there is a crash somewhere here + // return; s32 pad; InterfaceContext* interfaceCtx = &play->interfaceCtx; Player* player = GET_PLAYER(play); @@ -6284,7 +6329,10 @@ void Interface_Draw(PlayState* play) { OPEN_DISPS(play->state.gfxCtx); gSPSegment(OVERLAY_DISP++, 0x02, interfaceCtx->parameterSegment); - gSPSegment(OVERLAY_DISP++, 0x09, interfaceCtx->doActionSegment); + // BENTODO: Find if this is the correct button + + // BENTODO CRASH + gSPSegment(OVERLAY_DISP++, 0x09, interfaceCtx->doActionSegment[A_BUTTON_ACTION].mainTex); gSPSegment(OVERLAY_DISP++, 0x08, interfaceCtx->iconItemSegment); gSPSegment(OVERLAY_DISP++, 0x0B, interfaceCtx->mapSegment); @@ -6365,9 +6413,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->magicAlpha); - OVERLAY_DISP = - Gfx_DrawTexRectI8(OVERLAY_DISP, (u8*)gCounterDigit0Tex + (8 * 16 * counterDigits[2]), 8, 16, - 43, 191, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[counterDigits[2]], 8, 16, 43, 191, + 8, 16, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->magicAlpha); @@ -6380,8 +6427,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->magicAlpha); - OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, (u8*)gCounterDigit0Tex + (8 * 16 * counterDigits[3]), - 8, 16, sp2CA + 1, 191, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[counterDigits[3]], 8, 16, sp2CA + 1, + 191, 8, 16, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->magicAlpha); @@ -6397,7 +6444,7 @@ void Interface_Draw(PlayState* play) { gDPSetCombineMode(OVERLAY_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->magicAlpha); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 255); - gDPLoadTextureBlock(OVERLAY_DISP++, gGoldSkulltulaCounterIconTex, G_IM_FMT_RGBA, G_IM_SIZ_32b, 24, 24, + gDPLoadTextureBlock(OVERLAY_DISP++, gGoldSkulltulaCounterIconTex, G_IM_FMT_RGBA, G_IM_SIZ_32b, 24, 18, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPTextureRectangle(OVERLAY_DISP++, 80, 748, 176, 820, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); @@ -6421,8 +6468,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->magicAlpha); - OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, (u8*)gCounterDigit0Tex + (8 * 16 * counterDigits[2]), - 8, 16, 43, 191, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[counterDigits[2]], 8, 16, 43, 191, 8, + 16, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->magicAlpha); @@ -6434,8 +6481,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->magicAlpha); - OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, (u8*)gCounterDigit0Tex + (8 * 16 * counterDigits[3]), 8, - 16, sp2CA + 1, 191, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[counterDigits[3]], 8, 16, sp2CA + 1, 191, + 8, 16, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->magicAlpha); @@ -6481,8 +6528,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, magicAlpha); - OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, (u8*)gCounterDigit0Tex + (8 * 16 * counterDigits[sp2CC]), 8, - 16, sp2CA + 1, 207, 8, 16, 1 << 10, 1 << 10); + OVERLAY_DISP = Gfx_DrawTexRectI8(OVERLAY_DISP, sCounterDigits[counterDigits[sp2CC]], 8, 16, sp2CA + 1, 207, + 8, 16, 1 << 10, 1 << 10); gDPPipeSync(OVERLAY_DISP++); @@ -6568,7 +6615,6 @@ void Interface_Draw(PlayState* play) { Interface_DrawMinigameIcons(play); Interface_DrawTimers(play); } - // Draw pictograph focus icons if (sPictoState == PICTO_BOX_STATE_LENS) { @@ -6668,7 +6714,8 @@ void Interface_Draw(PlayState* play) { gDPPipeSync(OVERLAY_DISP++); gSPDisplayList(OVERLAY_DISP++, sScreenFillSetupDL); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 0, 0, 0, interfaceCtx->screenFillAlpha); - gSPDisplayList(OVERLAY_DISP++, D_0E000000.fillRect); + + __gSPDisplayList(OVERLAY_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); } CLOSE_DISPS(play->state.gfxCtx); @@ -6684,7 +6731,7 @@ void Interface_LoadStory(PlayState* play, s32 osMesgFlag) { } osCreateMesgQueue(&interfaceCtx->storyMsgQueue, &interfaceCtx->storyMsgBuf, 1); DmaMgr_SendRequestImpl(&interfaceCtx->dmaRequest, interfaceCtx->storySegment, interfaceCtx->storyAddr, - interfaceCtx->storySize, 0, &interfaceCtx->storyMsgQueue, NULL); + interfaceCtx->storySize, 0, &interfaceCtx->storyMsgQueue, OS_MESG_PTR(NULL)); interfaceCtx->storyDmaStatus = STORY_DMA_LOADING; // fallthrough case STORY_DMA_LOADING: @@ -7218,12 +7265,20 @@ void Interface_Init(PlayState* play) { parameterStaticSize = SEGMENT_ROM_SIZE(parameter_static); interfaceCtx->parameterSegment = THA_AllocTailAlign16(&play->state.tha, parameterStaticSize); - DmaMgr_SendRequest0(interfaceCtx->parameterSegment, SEGMENT_ROM_START(parameter_static), parameterStaticSize); + // OTRTODO + // DmaMgr_SendRequest0(interfaceCtx->parameterSegment, SEGMENT_ROM_START(parameter_static), parameterStaticSize); - interfaceCtx->doActionSegment = THA_AllocTailAlign16(&play->state.tha, 0xC90); - DmaMgr_SendRequest0(interfaceCtx->doActionSegment, SEGMENT_ROM_START(do_action_static), 0x300); - DmaMgr_SendRequest0(interfaceCtx->doActionSegment + 0x300, SEGMENT_ROM_START_OFFSET(do_action_static, 0x480), - 0x180); + interfaceCtx->doActionSegment = THA_AllocTailAlign16(&play->state.tha, sizeof(ActionLabel) * 4); + for (size_t id = 0; id < 4; id++) { + ActionLabel lbl = { gEmptyTexture, gEmptyTexture }; + interfaceCtx->doActionSegment[id] = lbl; + } + + interfaceCtx->doActionSegment[A_BUTTON_ACTION].mainTex = doActionTbl[0]; + interfaceCtx->doActionSegment[A_BUTTON_ACTION].subTex = doActionTbl[1]; + interfaceCtx->doActionSegment[START_BUTTON_ACTION].mainTex = doActionTbl[3]; + // DmaMgr_SendRequest0(interfaceCtx->doActionSegment, SEGMENT_ROM_START(do_action_static), 0x300); + // DmaMgr_SendRequest0(interfaceCtx->doActionSegment + 0x300, SEGMENT_ROM_START(do_action_static) + 0x480, 0x180); Interface_NewDay(play, CURRENT_DAY); diff --git a/mm/src/code/z_play.c b/mm/src/code/z_play.c index c17bcbfba..a5ffdf92d 100644 --- a/mm/src/code/z_play.c +++ b/mm/src/code/z_play.c @@ -1224,14 +1224,15 @@ void Play_DrawMain(PlayState* this) { SET_FULLSCREEN_VIEWPORT(&spA8); View_ApplyTo(&spA8, &sp218); - this->transitionCtx.draw(&this->transitionCtx.instanceData, &sp218); + // BENTODO: incorrect render + // this->transitionCtx.draw(&this->transitionCtx.instanceData, &sp218); } TransitionFade_Draw(&this->unk_18E48, &sp218); - + // BENTODO: fill framebuffer? if (gVisMonoColor.a != 0) { sPlayVisMono.primColor.rgba = gVisMonoColor.rgba; - VisMono_Draw(&sPlayVisMono, &sp218); + // VisMono_Draw(&sPlayVisMono, &sp218); } gSPEndDisplayList(sp218++); @@ -1267,7 +1268,8 @@ void Play_DrawMain(PlayState* this) { func_80170798(&this->pauseBgPreRender, &sp8C); } - gSPDisplayList(sp8C++, D_0E000000.syncSegments); + __gSPDisplayList(sp8C++, + 0x0E000000 + ((uintptr_t)&D_0E000000.syncSegments - (uintptr_t)&D_0E000000) + 1); POLY_OPA_DISP = sp8C; sp25B = true; goto PostWorldDraw; @@ -1562,7 +1564,11 @@ void Play_InitEnvironment(PlayState* this, s16 skyboxId) { Environment_Init(this, &this->envCtx, 0); } +void OTRPlay_InitScene(PlayState* play, s32 spawn); + void Play_InitScene(PlayState* this, s32 spawn) { + OTRPlay_InitScene(this, spawn); + #if 0 this->curSpawn = spawn; this->linkActorEntry = NULL; this->actorCsCamList = NULL; @@ -1580,9 +1586,14 @@ void Play_InitScene(PlayState* this, s32 spawn) { gSaveContext.worldMapArea = 0; Scene_ExecuteCommands(this, this->sceneSegment); Play_InitEnvironment(this, this->skyboxId); + #endif } +void OTRPlay_SpawnScene(PlayState* play, s32 sceneId, s32 spawn); + void Play_SpawnScene(PlayState* this, s32 sceneId, s32 spawn) { + OTRPlay_SpawnScene(this, sceneId, spawn); +#if 0 s32 pad; SceneTableEntry* scene = &gSceneTable[sceneId]; @@ -1592,9 +1603,10 @@ void Play_SpawnScene(PlayState* this, s32 sceneId, s32 spawn) { this->sceneConfig = scene->drawConfig; this->sceneSegment = Play_LoadFile(this, &scene->segment); scene->unk_D = 0; - gSegments[2] = OS_K0_TO_PHYSICAL(this->sceneSegment); + gSegments[2] = VIRTUAL_TO_PHYSICAL(this->sceneSegment); Play_InitScene(this, spawn); Room_AllocateAndLoad(this, &this->roomCtx); +#endif } void Play_GetScreenPos(PlayState* this, Vec3f* worldPos, Vec3f* screenPos) { @@ -2343,6 +2355,7 @@ void Play_Init(GameState* thisx) { gSaveContext.seqId = this->sequenceCtx.seqId; gSaveContext.ambienceId = this->sequenceCtx.ambienceId; AnimationContext_Update(this, &this->animationCtx); + // BENTODO: crash in Message_FindMessage Cutscene_HandleEntranceTriggers(this); gSaveContext.respawnFlag = 0; sBombersNotebookOpen = false; diff --git a/mm/src/code/z_play_hireso.c b/mm/src/code/z_play_hireso.c index 1b2572ea8..6364a6997 100644 --- a/mm/src/code/z_play_hireso.c +++ b/mm/src/code/z_play_hireso.c @@ -1083,7 +1083,8 @@ void BombersNotebook_Draw(BombersNotebook* this, GraphicsContext* gfxCtx) { BombersNotebook_DrawRows(this, &gfx); gDPPipeSync(gfx++); - gSPDisplayList(gfx++, D_0E000000.setScissor); + + __gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); BombersNotebook_DrawTimeOfDay(&gfx); @@ -1106,7 +1107,7 @@ void BombersNotebook_LoadFiles(BombersNotebook* this, s32 flag) { CmpDma_LoadAllFiles(this->scheduleDmaSegmentStart, this->scheduleDmaSegment, this->scheduleDmaSegmentSize); osCreateMesgQueue(&this->loadQueue, this->loadMsg, ARRAY_COUNT(this->loadMsg)); DmaMgr_SendRequestImpl(&this->dmaRequest, this->scheduleSegment, this->scheduleSegmentStart, - this->scheduleSegmentSize, 0, &this->loadQueue, NULL); + this->scheduleSegmentSize, 0, &this->loadQueue, OS_MESG_PTR(NULL)); this->loadState = BOMBERS_NOTEBOOK_LOAD_STATE_STARTED; // fallthrough case BOMBERS_NOTEBOOK_LOAD_STATE_STARTED: @@ -1140,6 +1141,9 @@ void BombersNotebook_Update(PlayState* play, BombersNotebook* this, Input* input s32 stickAdjY = input->rel.stick_y; s32 cursorEntryScan; + // BENTODO + return; + this->scheduleDmaSegmentStart = SEGMENT_ROM_START(schedule_dma_static_yar); this->scheduleDmaSegmentSize = SEGMENT_ROM_SIZE(schedule_dma_static_syms); this->scheduleSegmentStart = SEGMENT_ROM_START(schedule_static); diff --git a/mm/src/code/z_player_lib.c b/mm/src/code/z_player_lib.c index dda20d7da..aae9cd26d 100644 --- a/mm/src/code/z_player_lib.c +++ b/mm/src/code/z_player_lib.c @@ -204,7 +204,7 @@ void func_801229FC(Player* player) { osCreateMesgQueue(&player->maskObjectLoadQueue, &player->maskObjectLoadMsg, 1); DmaMgr_SendRequestImpl(&player->maskDmaRequest, player->maskObjectSegment, gObjectTable[objectId].vromStart, gObjectTable[objectId].vromEnd - gObjectTable[objectId].vromStart, 0, - &player->maskObjectLoadQueue, NULL); + &player->maskObjectLoadQueue, OS_MESG_PTR(NULL)); player->maskObjectLoadState++; } else if (player->maskObjectLoadState == 2) { if (osRecvMesg(&player->maskObjectLoadQueue, NULL, OS_MESG_NOBLOCK) == 0) { diff --git a/mm/src/code/z_rcp.c b/mm/src/code/z_rcp.c index b30e22440..2ae0388cb 100644 --- a/mm/src/code/z_rcp.c +++ b/mm/src/code/z_rcp.c @@ -840,7 +840,9 @@ Gfx sFillSetupDL[] = { G_TD_CLAMP | G_TP_PERSP | G_CYC_FILL | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsSPDisplayList(D_0E000000.setScissor), + // BENTODO: CRASH + // gsSPDisplayList(D_0E000000.setScissor), + gsSPDisplayList(0x0E0001C8 | 1), gsDPSetBlendColor(0x00, 0x00, 0x00, 0x08), gsSPClipRatio(FRUSTRATIO_2), gsSPEndDisplayList(), @@ -1449,8 +1451,8 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g s32 i; gSegments[0x00] = 0; - gSegments[0x0F] = (uintptr_t)gfxCtx->curFrameBuffer; - gSegments[0x0E] = (uintptr_t)gGfxMasterDL; + gSegments[0x0F] = gfxCtx->curFrameBuffer; + gSegments[0x0E] = gGfxMasterDL; zbuffer = gfxCtx->zbuffer; @@ -1458,8 +1460,10 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g masterGfx = gGfxMasterDL->setupBuffers; - gSPDisplayList(&masterGfx[0], D_0E000000.syncSegments); + __gSPDisplayList(&masterGfx[0], 0x0E000000 + ((uintptr_t)&D_0E000000.syncSegments - (uintptr_t)&D_0E000000) + 1); + gSPDisplayList(&masterGfx[1], sFillSetupDL); + gDPSetColorImage(&masterGfx[2], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); if (zbuffer != NULL) { gDPSetDepthImage(&masterGfx[3], zbuffer); @@ -1487,7 +1491,9 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g gDPSetCycleType(&masterGfx[2], G_CYC_FILL); gDPSetRenderMode(&masterGfx[3], G_RM_NOOP, G_RM_NOOP2); gDPSetFillColor(&masterGfx[4], (GPACK_RGBA5551(255, 255, 240, 0) << 16) | GPACK_RGBA5551(255, 255, 240, 0)); - gSPDisplayList(&masterGfx[5], D_0E000000.clearFillRect); + + gSPDisplayList(&masterGfx[5], 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); + gDPSetColorImage(&masterGfx[6], G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); gSPEndDisplayList(&masterGfx[7]); } @@ -1500,7 +1506,8 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g gDPSetCycleType(&masterGfx[1], G_CYC_FILL); gDPSetRenderMode(&masterGfx[2], G_RM_NOOP, G_RM_NOOP2); gDPSetFillColor(&masterGfx[3], (GPACK_RGBA5551(r, g, b, 1) << 16) | GPACK_RGBA5551(r, g, b, 1)); - gSPBranchList(&masterGfx[4], D_0E000000.clearFillRect); + + gSPBranchList(&masterGfx[4], 0x0E000000 + ((uintptr_t)&D_0E000000.clearFillRect - (uintptr_t)&D_0E000000) + 1); // Fillrect used by the above buffer clearing routines @@ -1539,10 +1546,12 @@ void func_8012CF0C(GraphicsContext* gfxCtx, s32 clearFb, s32 clearZb, u8 r, u8 g gSPDisplayList(DEBUG_DISP++, gGfxMasterDL->setupBuffers); if (clearZb) { - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearZBuffer); + __gSPDisplayList(POLY_OPA_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.clearZBuffer - (uintptr_t)&D_0E000000) + 1); } if (clearFb) { - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.clearFrameBuffer); + __gSPDisplayList(POLY_OPA_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.clearFrameBuffer - (uintptr_t)&D_0E000000) + 1); } CLOSE_DISPS(gfxCtx); diff --git a/mm/src/code/z_room.c b/mm/src/code/z_room.c index dd6aa2b9a..00397fdac 100644 --- a/mm/src/code/z_room.c +++ b/mm/src/code/z_room.c @@ -546,7 +546,12 @@ size_t Room_AllocateAndLoad(PlayState* play, RoomContext* roomCtx) { return maxRoomSize; } + +s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomNum); + s32 Room_StartRoomTransition(PlayState* play, RoomContext* roomCtx, s32 index) { + return OTRfunc_8009728C(play, roomCtx, index); + #if 0 if (roomCtx->status == 0) { size_t size; @@ -568,9 +573,15 @@ s32 Room_StartRoomTransition(PlayState* play, RoomContext* roomCtx, s32 index) { } return 0; + #endif } +void OTRPlay_InitScene(PlayState* play, s32 spawn); +s32 OTRfunc_800973FC(PlayState* play, RoomContext* roomCtx); + s32 Room_HandleLoadCallbacks(PlayState* play, RoomContext* roomCtx) { + return OTRfunc_800973FC(play, roomCtx); +#if 0 if (roomCtx->status == 1) { if (osRecvMesg(&roomCtx->loadQueue, NULL, OS_MESG_NOBLOCK) == 0) { roomCtx->status = 0; @@ -595,6 +606,7 @@ s32 Room_HandleLoadCallbacks(PlayState* play, RoomContext* roomCtx) { } return 1; + #endif } RoomDrawHandler sRoomDrawHandlers[] = { diff --git a/mm/src/code/z_scene.c b/mm/src/code/z_scene.c index 6a073ad72..445afdf4d 100644 --- a/mm/src/code/z_scene.c +++ b/mm/src/code/z_scene.c @@ -87,7 +87,7 @@ void Object_UpdateEntries(ObjectContext* objectCtx) { } else { osCreateMesgQueue(&entry->loadQueue, &entry->loadMsg, 1); DmaMgr_SendRequestImpl(&entry->dmaReq, entry->segment, objectFile->vromStart, size, 0, - &entry->loadQueue, NULL); + &entry->loadQueue, OS_MESG_PTR(NULL)); } } else if (!osRecvMesg(&entry->loadQueue, NULL, OS_MESG_NOBLOCK)) { entry->id = id; @@ -100,7 +100,8 @@ void Object_UpdateEntries(ObjectContext* objectCtx) { s32 Object_GetSlot(ObjectContext* objectCtx, s16 objectId) { s32 i; - + // BENTODO there has to be a cleaner fix. + return 1; for (i = 0; i < objectCtx->numEntries; i++) { if (ABS_ALT(objectCtx->slots[i].id) == objectId) { return i; @@ -152,7 +153,7 @@ void* func_8012F73C(ObjectContext* objectCtx, s32 slot, s16 id) { return (void*)addr; } - +#if 0 // SceneTableEntry Header Command 0x00: Spawn List void Scene_CommandSpawnList(PlayState* play, SceneCmd* cmd) { s32 loadedCount; @@ -338,12 +339,12 @@ void Scene_CommandTransitionActorList(PlayState* play, SceneCmd* cmd) { play->transitionActors.list = Lib_SegmentedToVirtual(cmd->transitionActorList.segment); MapDisp_InitTransitionActorData(play, play->transitionActors.count, play->transitionActors.list); } - +#endif // Init function for the transition system. void Scene_ResetTransitionActorList(GameState* state, TransitionActorList* transitionActors) { transitionActors->count = 0; } - +#if 0 // SceneTableEntry Header Command 0x0F: Environment Light Settings List void Scene_CommandEnvLightSettings(PlayState* play, SceneCmd* cmd) { play->envCtx.numLightSettings = cmd->lightSettingList.num; @@ -541,14 +542,14 @@ void Scene_CommandSetRegionVisitedFlag(PlayState* play, SceneCmd* cmd) { void Scene_CommandAnimatedMaterials(PlayState* play, SceneCmd* cmd) { play->sceneMaterialAnims = Lib_SegmentedToVirtual(cmd->textureAnimations.segment); } - +#endif /** * Sets the exit fade from the next entrance index. */ void Scene_SetExitFade(PlayState* play) { play->transitionType = Entrance_GetTransitionFlags(play->nextEntrance) & 0x7F; } - +#if 0 void (*sSceneCmdHandlers[SCENE_CMD_MAX])(PlayState*, SceneCmd*) = { Scene_CommandSpawnList, // SCENE_CMD_ID_SPAWN_LIST Scene_CommandActorList, // SCENE_CMD_ID_ACTOR_LIST @@ -582,7 +583,6 @@ void (*sSceneCmdHandlers[SCENE_CMD_MAX])(PlayState*, SceneCmd*) = { Scene_Command1D, // SCENE_CMD_ID_UNUSED_1D Scene_CommandMapDataChests, // SCENE_CMD_ID_MAP_DATA_CHESTS }; - /** * Executes all of the commands in a scene or room header. */ @@ -605,7 +605,7 @@ s32 Scene_ExecuteCommands(PlayState* play, SceneCmd* sceneCmd) { return 0; } - +#endif /** * Creates an entrance from the scene, spawn, and layer. */ diff --git a/mm/src/code/z_scene_proc.c b/mm/src/code/z_scene_proc.c index 2daa0ee78..ea1fb8a94 100644 --- a/mm/src/code/z_scene_proc.c +++ b/mm/src/code/z_scene_proc.c @@ -1,5 +1,6 @@ #include "prevent_bss_reordering.h" #include "global.h" +#include "BenPort.h" s32 sMatAnimStep; u32 sMatAnimFlags; @@ -393,6 +394,8 @@ void AnimatedMat_DrawMain(PlayState* play, AnimatedMaterial* matAnim, f32 alphaR }; s32 segmentAbs; s32 segment; + if (ResourceMgr_OTRSigCheck(matAnim) != 0) + matAnim = ResourceMgr_LoadAnimByName(matAnim); sMatAnimAlphaRatio = alphaRatio; sMatAnimStep = step; diff --git a/mm/src/code/z_scene_table.c b/mm/src/code/z_scene_table.c index e31e4b185..33f6e862a 100644 --- a/mm/src/code/z_scene_table.c +++ b/mm/src/code/z_scene_table.c @@ -1,5 +1,6 @@ #include "global.h" +#if 0 #define DEFINE_SCENE(name, _enumValue, textId, drawConfig, _restrictionFlags, _persistentCycleFlags) \ DECLARE_ROM_SEGMENT(name) @@ -9,9 +10,11 @@ #undef DEFINE_SCENE #undef DEFINE_SCENE_UNSET +#endif + #define DEFINE_SCENE(name, _enumValue, textId, drawConfig, _restrictionFlags, _persistentCycleFlags) \ - { { SEGMENT_ROM_START(name), SEGMENT_ROM_END(name) }, textId, 0, drawConfig, 0, 0 }, + { { 0, 0, #name }, textId, 0, drawConfig, 0, 0 }, #define DEFINE_SCENE_UNSET(_enumValue) { 0 }, diff --git a/mm/src/code/z_skelanime.c b/mm/src/code/z_skelanime.c index bb900b994..f48124926 100644 --- a/mm/src/code/z_skelanime.c +++ b/mm/src/code/z_skelanime.c @@ -1,4 +1,7 @@ #include "global.h" +#include "BenPort.h" +#include "string.h" +#include "stdio.h" #define ANIM_INTERP 1 @@ -623,6 +626,8 @@ void SkelAnime_DrawTransformFlexOpa(PlayState* play, void** skeleton, Vec3s* joi * Indices above staticIndexMax are offsets to a frame data array indexed by the frame. */ void SkelAnime_GetFrameData(AnimationHeader* animation, s32 frame, s32 limbCount, Vec3s* frameTable) { + if (ResourceMgr_OTRSigCheck(animation)) + animation = ResourceMgr_LoadAnimByName(animation); AnimationHeader* animHeader = Lib_SegmentedToVirtual(animation); JointIndex* jointIndices = Lib_SegmentedToVirtual(animHeader->jointIndices); s16* frameData = Lib_SegmentedToVirtual(animHeader->frameData); @@ -642,12 +647,16 @@ void SkelAnime_GetFrameData(AnimationHeader* animation, s32 frame, s32 limbCount } s16 Animation_GetLength(void* animation) { + if (ResourceMgr_OTRSigCheck(animation)) + animation = ResourceMgr_LoadAnimByName(animation); AnimationHeaderCommon* common = Lib_SegmentedToVirtual(animation); return common->frameCount; } s16 Animation_GetLastFrame(void* animation) { + if (ResourceMgr_OTRSigCheck(animation)) + animation = ResourceMgr_LoadAnimByName(animation); AnimationHeaderCommon* common = Lib_SegmentedToVirtual(animation); return (u16)common->frameCount - 1; @@ -1006,14 +1015,23 @@ void AnimationContext_SetLoadFrame(PlayState* play, PlayerAnimationHeader* anima AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMATION_LINKANIMETION); if (entry != NULL) { + if (ResourceMgr_OTRSigCheck(animation) != 0) + animation = ResourceMgr_LoadAnimByName(animation); PlayerAnimationHeader* playerAnimHeader = Lib_SegmentedToVirtual(animation); - s32 pad; + Vec3s* ram = frameTable; - osCreateMesgQueue(&entry->data.load.msgQueue, entry->data.load.msg, ARRAY_COUNT(entry->data.load.msg)); - DmaMgr_SendRequestImpl( - &entry->data.load.req, frameTable, - LINK_ANIMETION_OFFSET(playerAnimHeader->linkAnimSegment, (sizeof(Vec3s) * limbCount + sizeof(s16)) * frame), - sizeof(Vec3s) * limbCount + sizeof(s16), 0, &entry->data.load.msgQueue, NULL); + // osCreateMesgQueue(&entry->data.load.msgQueue, &entry->data.load.msg, 1); + // + // char animPath[2048]; + // + // snprintf(animPath, sizeof(animPath), "misc/link_animetion/gPlayerAnimData_%06X", + // (((uintptr_t)linkAnimHeader->segmentVoid - 0x07000000))); + // + // printf("Streaming %s, seg = %08X\n", animPath, linkAnimHeader->segment); + + s16* animData = /* ResourceMgr_LoadPlayerAnimByName*/ (animation->segmentVoid); + + memcpy(ram, (uintptr_t)animData + (((sizeof(Vec3s) * limbCount + 2) * frame)), sizeof(Vec3s) * limbCount + 2); } } @@ -1095,7 +1113,7 @@ void AnimationContext_SetMoveActor(PlayState* play, Actor* actor, SkelAnime* ske void AnimationContext_LoadFrame(PlayState* play, AnimationEntryData* data) { AnimEntryLoadFrame* entry = &data->load; - osRecvMesg(&entry->msgQueue, NULL, OS_MESG_BLOCK); + //osRecvMesg(&entry->msgQueue, NULL, OS_MESG_BLOCK); } /** @@ -1205,7 +1223,8 @@ void SkelAnime_InitPlayer(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHea s32 headerJointCount; s32 limbCount; size_t allocSize; - + if (ResourceMgr_OTRSigCheck(skeletonHeaderSeg) != 0) + skeletonHeaderSeg = ResourceMgr_LoadSkeletonByName(skeletonHeaderSeg, skelAnime); skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); headerJointCount = skeletonHeader->sh.limbCount; skelAnime->initFlags = flags; @@ -1354,6 +1373,15 @@ void Animation_SetMorph(PlayState* play, SkelAnime* skelAnime, f32 morphFrames) */ void PlayerAnimation_Change(PlayState* play, SkelAnime* skelAnime, PlayerAnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames) { + LinkAnimationHeader* ogAnim = animation; + + if (ResourceMgr_OTRSigCheck(animation) != 0) + animation = ResourceMgr_LoadAnimByName(animation); + + AnimationHeader* currentAnimation = (AnimationHeader*)skelAnime->animation; + if (ResourceMgr_OTRSigCheck(currentAnimation) != 0) + currentAnimation = ResourceMgr_LoadAnimByName(currentAnimation); + skelAnime->mode = mode; if ((morphFrames != 0.0f) && ((animation != skelAnime->animation) || (startFrame != skelAnime->curFrame))) { if (morphFrames < 0) { @@ -1373,6 +1401,7 @@ void PlayerAnimation_Change(PlayState* play, SkelAnime* skelAnime, PlayerAnimati skelAnime->morphWeight = 0.0f; } + skelAnime->animation = ogAnim; skelAnime->animation = animation; skelAnime->curFrame = 0.0f; skelAnime->startFrame = startFrame; @@ -1533,8 +1562,10 @@ s32 PlayerAnimation_OnFrame(SkelAnime* skelAnime, f32 frame) { void SkelAnime_Init(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount) { SkeletonHeader* skeletonHeader; + if (ResourceMgr_OTRSigCheck(skeletonHeaderSeg)) + skeletonHeaderSeg = ResourceMgr_LoadSkeletonByName(skeletonHeaderSeg, NULL); - skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); + skeletonHeader = skeletonHeaderSeg; skelAnime->limbCount = skeletonHeader->limbCount + 1; skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->segment); if (jointTable == NULL) { @@ -1556,8 +1587,9 @@ void SkelAnime_Init(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skele void SkelAnime_InitFlex(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg, AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount) { FlexSkeletonHeader* skeletonHeader; - - skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); + if (ResourceMgr_OTRSigCheck(skeletonHeaderSeg)) + skeletonHeaderSeg = ResourceMgr_LoadSkeletonByName(skeletonHeaderSeg, NULL); + skeletonHeader = skeletonHeaderSeg; skelAnime->limbCount = skeletonHeader->sh.limbCount + 1; skelAnime->dListCount = skeletonHeader->dListCount; skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->sh.segment); @@ -1582,8 +1614,9 @@ void SkelAnime_InitFlex(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeade void SkelAnime_InitSkin(GameState* gameState, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, AnimationHeader* animation) { SkeletonHeader* skeletonHeader; - - skeletonHeader = Lib_SegmentedToVirtual(skeletonHeaderSeg); + if (ResourceMgr_OTRSigCheck(skeletonHeaderSeg)) + skeletonHeaderSeg = ResourceMgr_LoadSkeletonByName(skeletonHeaderSeg, NULL); + skeletonHeader = skeletonHeaderSeg; skelAnime->limbCount = skeletonHeader->limbCount + 1; skelAnime->skeleton = Lib_SegmentedToVirtual(skeletonHeader->segment); skelAnime->jointTable = ZeldaArena_Malloc(sizeof(*skelAnime->jointTable) * skelAnime->limbCount); @@ -1770,6 +1803,15 @@ s32 SkelAnime_Once(SkelAnime* skelAnime) { */ void Animation_ChangeImpl(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames, s8 taper) { + LinkAnimationHeader* ogAnim = animation; + + if (ResourceMgr_OTRSigCheck(animation) != 0) + animation = ResourceMgr_LoadAnimByName(animation); + + AnimationHeader* currentAnimation = (AnimationHeader*)skelAnime->animation; + if (ResourceMgr_OTRSigCheck(currentAnimation) != 0) + currentAnimation = ResourceMgr_LoadAnimByName(currentAnimation); + skelAnime->mode = mode; if ((morphFrames != 0.0f) && ((animation != skelAnime->animation) || (startFrame != skelAnime->curFrame))) { if (morphFrames < 0) { @@ -1816,7 +1858,12 @@ void Animation_ChangeImpl(SkelAnime* skelAnime, AnimationHeader* animation, f32 */ void Animation_Change(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames) { + AnimationHeader* ogAnim = animation; + + if (ResourceMgr_OTRSigCheck(animation) != 0) + animation = ResourceMgr_LoadAnimByName(animation); Animation_ChangeImpl(skelAnime, animation, playSpeed, startFrame, endFrame, mode, morphFrames, ANIMTAPER_NONE); + skelAnime->animation = ogAnim; } /** @@ -1977,6 +2024,7 @@ void SkelAnime_Free(SkelAnime* skelAnime, PlayState* play) { if (skelAnime->morphTable != NULL) { ZeldaArena_Free(skelAnime->morphTable); } + ResourceMgr_UnregisterSkeleton(skelAnime); } /** diff --git a/mm/src/code/z_sub_s.c b/mm/src/code/z_sub_s.c index 44ef954eb..5758c2055 100644 --- a/mm/src/code/z_sub_s.c +++ b/mm/src/code/z_sub_s.c @@ -8,7 +8,7 @@ s16 sPathDayFlags[] = { 0x40, 0x20, 0x10, 8, 4, 2, 1, 0 }; -#include "code/sub_s/sub_s.c" +#include "code/sub_s/sub_s.h" Vec3f gOneVec3f = { 1.0f, 1.0f, 1.0f }; diff --git a/mm/src/code/z_vimode.c b/mm/src/code/z_vimode.c index 8e3d1c59f..5ab22dc1e 100644 --- a/mm/src/code/z_vimode.c +++ b/mm/src/code/z_vimode.c @@ -13,6 +13,25 @@ typedef struct { /* 0x18 */ u32 vBurst; } ViModeStruct; // size = 0x1C +#define BURST(hsync_width, color_width, vsync_width, color_start) \ + (((u32)(hsync_width)&0xFF) | (((u32)(color_width)&0xFF) << 8) | (((u32)(vsync_width)&0xF) << 16) | \ + (((u32)(color_start)&0xFFFF) << 20)) +#define WIDTH(v) (v) +#define VSYNC(v) (v) +#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration)&0xFFFF)) +#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower)&0xFFFF)) +#define START(start, end) (((u32)(start) << 16) | ((u32)(end)&0xFFFF)) + +#define FTOFIX(val, i, f) ((u32)((val) * (f32)(1 << (f))) & ((1 << ((i) + (f))) - 1)) + +#define F210(val) FTOFIX(val, 2, 10) +#define SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16)) + +#define VCURRENT(v) v +#define ORIGIN(v) v +#define VINTR(v) v +#define HSTART START +s32 osTvType = OS_TV_NTSC; void ViMode_LogPrint(OSViMode* osViMode) { } @@ -179,7 +198,15 @@ void ViMode_Configure(OSViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 ant viMode->fldRegs[1].vIntr = 2; } +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeFpalLan1; + void ViMode_Save(ViMode* viMode) { + #if 0 R_VI_MODE_EDIT_STATE = viMode->editState; R_VI_MODE_EDIT_WIDTH = viMode->viWidth; R_VI_MODE_EDIT_HEIGHT = viMode->viHeight; @@ -204,6 +231,7 @@ void ViMode_Save(ViMode* viMode) { break; } } + #endif } void ViMode_Load(ViMode* viMode) { @@ -243,6 +271,7 @@ void ViMode_Destroy(ViMode* viMode) { } void ViMode_ConfigureFeatures(ViMode* viMode, s32 viFeatures) { + #if 0 u32 ctrl = viMode->customViMode.comRegs.ctrl; if (viFeatures & OS_VI_GAMMA_ON) { @@ -264,6 +293,7 @@ void ViMode_ConfigureFeatures(ViMode* viMode, s32 viFeatures) { ctrl &= ~OS_VI_DIVOT; } viMode->customViMode.comRegs.ctrl = ctrl; + #endif } /** @@ -271,6 +301,7 @@ void ViMode_ConfigureFeatures(ViMode* viMode, s32 viFeatures) { * (through R_VI_MODE_EDIT_* entries) */ void ViMode_Update(ViMode* viMode, Input* input) { + #if 0 ViMode_Load(viMode); if ((viMode->editState == VI_MODE_EDIT_STATE_ACTIVE) || (viMode->editState == VI_MODE_EDIT_STATE_2) || @@ -376,4 +407,5 @@ void ViMode_Update(ViMode* viMode, Input* input) { } ViMode_Save(viMode); + #endif } diff --git a/mm/src/code/z_viscvg.c b/mm/src/code/z_viscvg.c index 1821805ee..ba62cfc59 100644 --- a/mm/src/code/z_viscvg.c +++ b/mm/src/code/z_viscvg.c @@ -5,7 +5,9 @@ Gfx D_801C5DD0[] = { gsDPSetOtherMode(G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PRIM | G_RM_VISCVG | G_RM_VISCVG2), - gsSPBranchList(D_0E000000.fillRect), + // BENTODO: CRASH + // gsSPBranchList(D_0E000000.fillRect), + gsSPBranchList(0x0E0002E0 | 1), }; Gfx D_801C5DE0[] = { @@ -14,7 +16,9 @@ Gfx D_801C5DE0[] = { G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_A_MEM) | GBL_c2(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_A_MEM)), - gsSPBranchList(D_0E000000.fillRect), + // BENTODO: CRASH + //gsSPBranchList(D_0E000000.fillRect), + gsSPBranchList(0x0E0002E0 | 1), }; Gfx D_801C5DF0[] = { @@ -23,7 +27,9 @@ Gfx D_801C5DF0[] = { G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM) | GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM)), - gsSPBranchList(D_0E000000.fillRect), + // BENTODO: CRASH + //gsSPBranchList(D_0E000000.fillRect), + gsSPBranchList(0x0E0002E0 | 1), }; Gfx D_801C5E00[] = { @@ -31,13 +37,17 @@ Gfx D_801C5E00[] = { gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_DISABLE | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PRIM | G_RM_CLD_SURF | G_RM_CLD_SURF2), - gsSPDisplayList(D_0E000000.fillRect), + // BENTODO: CRASH + //gsSPDisplayList(D_0E000000.fillRect), + gsSPBranchList(0x0E0002E0 | 1), gsDPSetOtherMode(G_AD_PATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_CONV | G_TF_POINT | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PRIM | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM) | GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_MEM, G_BL_A_MEM)), - gsSPBranchList(D_0E000000.fillRect), + // BENTODO: CRASH + //gsSPBranchList(D_0E000000.fillRect), + gsSPBranchList(0x0E0002E0 | 1), }; void VisCvg_Init(VisCvg* this) { @@ -59,7 +69,7 @@ void VisCvg_Draw(VisCvg* this, Gfx** gfxp) { gDPSetPrimDepth(gfx++, -1, -1); if (this->setScissor == true) { - gSPDisplayList(gfx++, D_0E000000.setScissor); + __gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); } switch (this->type) { diff --git a/mm/src/code/z_visfbuf.c b/mm/src/code/z_visfbuf.c index 62242bcec..79d403d27 100644 --- a/mm/src/code/z_visfbuf.c +++ b/mm/src/code/z_visfbuf.c @@ -54,7 +54,7 @@ void VisFbuf_DrawBgToColorImage(Gfx** gfxP, uObjBg* bg, void* img, s32 width, s3 gDPPipeSync(gfx++); // Reset the color image and scissor to frame's defaults gDPSetColorImage(gfx++, G_IM_FMT_RGBA, G_IM_SIZ_16b, gCfbWidth, D_0F000000); - gSPDisplayList(gfx++, D_0E000000.setScissor); + gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); *gfxP = gfx; } diff --git a/mm/src/code/z_vismono.c b/mm/src/code/z_vismono.c index 86937c315..94ccd5cf4 100644 --- a/mm/src/code/z_vismono.c +++ b/mm/src/code/z_vismono.c @@ -41,6 +41,8 @@ void VisMono_Init(VisMono* this) { void VisMono_Destroy(VisMono* this) { SystemArena_Free(this->dList); } +// BENTODO move to a header since it might be helpful other places. +#define GPACK_IA16(i, a) (((i) << 8) | (a)) void VisMono_DesaturateTLUT(u16* tlut) { s32 i; @@ -152,7 +154,7 @@ void VisMono_Draw(VisMono* this, Gfx** gfxp) { gDPPipeSync(gfx++); if (this->setScissor == true) { - gSPDisplayList(gfx++, D_0E000000.setScissor); + __gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); } gDPSetColor(gfx++, G_SETPRIMCOLOR, this->primColor.rgba); diff --git a/mm/src/code/z_viszbuf.c b/mm/src/code/z_viszbuf.c index 17c734cb0..2a4856af9 100644 --- a/mm/src/code/z_viszbuf.c +++ b/mm/src/code/z_viszbuf.c @@ -33,7 +33,7 @@ void VisZbuf_Draw(VisZbuf* this, Gfx** gfxP, void* zbuffer) { gDPPipeSync(gfx++); if (this->setScissor == true) { - gSPDisplayList(gfx++, D_0E000000.setScissor); + __gSPDisplayList(gfx++, 0x0E000000 + ((uintptr_t)&D_0E000000.setScissor - (uintptr_t)&D_0E000000) + 1); } gDPSetOtherMode(gfx++, diff --git a/mm/src/code/z_vr_box.c b/mm/src/code/z_vr_box.c index 605dff84c..7e57c473b 100644 --- a/mm/src/code/z_vr_box.c +++ b/mm/src/code/z_vr_box.c @@ -1,4 +1,8 @@ #include "global.h" +#include "BenPort.h" +#include "assets/misc/skyboxes/d2_cloud_static.h" +#include "assets/misc/skyboxes/d2_fine_static.h" +#include "assets/misc/skyboxes/d2_fine_pal_static.h" u32 D_801C5E30[] = { 0, 0x2000, 0x4000, 0x6000, 0x8000, 0xC000 }; @@ -17,6 +21,19 @@ s16 D_801C5EC4[] = { 24, 7, 29, 28, 25, 26, 30, 10, 26, 27, 11, 30, 27, 28, 31, 11, 28, 29, 15, 31, }; +const char* sD2FineStaticTex[] = { + gClearSkybox1Tex, gClearSkybox2Tex, gClearSkybox3Tex, gClearSkybox4Tex, gClearSkybox5Tex, +}; + +const char* sD2CloudStaticTex[] = { + gCloudySkybox1Tex, gCloudySkybox2Tex, gCloudySkybox3Tex, gCloudySkybox4Tex, gCloudySkybox5Tex, +}; + +SkyboxFiles files[] = { + { sD2FineStaticTex, gClearSkyboxTlue }, + { sD2CloudStaticTex, gClearSkyboxTlue }, +}; + s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, s32 arg7, s32 arg8) { s32 i; @@ -119,14 +136,16 @@ s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s3 phi_a2_4 = 0; for (phi_t2_4 = 0, phi_ra = 0; phi_ra < 4; phi_ra++, phi_a2_4 += 0x1F) { for (phi_a0_4 = 0, phi_t1 = 0; phi_t1 < 4; phi_t1++, phi_a0_4 += 0x1F, phi_t2_4 += 4) { - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[0] + D_801C5E30[arg8], 0, + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[0][arg8] /*+ D_801C5E30[arg8]*/, 0, G_TX_RENDERTILE, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[1] + D_801C5E30[arg8], 0x80, - 1, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, - phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[1][arg8] /*+ D_801C5E30[arg8]*/, 0x80, 1, + G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, + 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOLOD); gSP1Quadrangle(skyboxCtx->roomDL++, D_801C5EC4[phi_t2_4 + 1], D_801C5EC4[phi_t2_4 + 2], D_801C5EC4[phi_t2_4 + 3], D_801C5EC4[phi_t2_4 + 0], 3); } @@ -135,14 +154,16 @@ s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s3 phi_a2_4 = 0; for (phi_t2_4 = 0, phi_ra = 0; phi_ra < 2; phi_ra++, phi_a2_4 += 0x1F) { for (phi_a0_4 = 0, phi_t1 = 0; phi_t1 < 4; phi_t1++, phi_a0_4 += 0x1F, phi_t2_4 += 4) { - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[0] + D_801C5E30[arg8], 0, + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[0][arg8] /*+ D_801C5E30[arg8]*/, 0, G_TX_RENDERTILE, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[1] + D_801C5E30[arg8], 0x80, - 1, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, - phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[1][arg8] /*+ D_801C5E30[arg8]*/, 0x80, 1, + G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, + 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOLOD); gSP1Quadrangle(skyboxCtx->roomDL++, D_801C5EC4[phi_t2_4 + 1], D_801C5EC4[phi_t2_4 + 2], D_801C5EC4[phi_t2_4 + 3], D_801C5EC4[phi_t2_4 + 0], 3); } @@ -150,14 +171,16 @@ s32 func_80142440(SkyboxContext* skyboxCtx, Vtx* roomVtx, s32 arg2, s32 arg3, s3 phi_a2_4 -= 0x1F; for (phi_ra = 0; phi_ra < 2; phi_ra++, phi_a2_4 -= 0x1F) { for (phi_a0_4 = 0, phi_t1 = 0; phi_t1 < 4; phi_t1++, phi_a0_4 += 0x1F, phi_t2_4 += 4) { - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[0] + D_801C5E30[arg8], 0, + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[0][arg8] /*+ D_801C5E30[arg8]*/, 0, G_TX_RENDERTILE, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); - gDPLoadMultiTile(skyboxCtx->roomDL++, (uintptr_t)skyboxCtx->staticSegments[1] + D_801C5E30[arg8], 0x80, - 1, G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, - phi_a2_4 + 0x1F, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPLoadMultiTile(skyboxCtx->roomDL++, + (uintptr_t)skyboxCtx->staticSegments[1][arg8] /*+ D_801C5E30[arg8]*/, 0x80, 1, + G_IM_FMT_CI, G_IM_SIZ_8b, 128, 0, phi_a0_4, phi_a2_4, phi_a0_4 + 0x1F, phi_a2_4 + 0x1F, + 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOLOD); gSP1Quadrangle(skyboxCtx->roomDL++, D_801C5EC4[phi_t2_4 + 1], D_801C5EC4[phi_t2_4 + 2], D_801C5EC4[phi_t2_4 + 3], D_801C5EC4[phi_t2_4 + 0], 3); } @@ -193,22 +216,29 @@ void Skybox_Setup(GameState* gameState, SkyboxContext* skyboxCtx, s16 skyboxId) switch (skyboxId) { case SKYBOX_NORMAL_SKY: // Send a DMA request for the cloudy sky texture - skyboxCtx->staticSegments[0] = &D_80025D00; - size = SEGMENT_ROM_SIZE(d2_cloud_static); - segment = (void*)ALIGN8((uintptr_t)skyboxCtx->staticSegments[0] + size); - DmaMgr_SendRequest0(skyboxCtx->staticSegments[0], SEGMENT_ROM_START(d2_cloud_static), size); - + // skyboxCtx->staticSegments[0] = &D_80025D00; + // size = SEGMENT_ROM_SIZE(d2_cloud_static); + // segment = (void*)ALIGN8((uintptr_t)skyboxCtx->staticSegments[0] + size); + // DmaMgr_SendRequest0(skyboxCtx->staticSegments[0], SEGMENT_ROM_START(d2_cloud_static), size); + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[0][i] = sD2FineStaticTex[i]; + } + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[1][i] = sD2CloudStaticTex[i]; + } + skyboxCtx->paletteStaticSegment = gClearSkyboxTlue; // Send a DMA request for the clear sky texture - skyboxCtx->staticSegments[1] = segment; - size = SEGMENT_ROM_SIZE(d2_fine_static); - segment = (void*)ALIGN8((uintptr_t)segment + size); - DmaMgr_SendRequest0(skyboxCtx->staticSegments[1], SEGMENT_ROM_START(d2_fine_static), size); + // skyboxCtx->staticSegments[1] = segment; + // size = SEGMENT_ROM_SIZE(d2_fine_static); + // segment = (void*)ALIGN8((uintptr_t)segment + size); + // DmaMgr_SendRequest0(skyboxCtx->staticSegments[1], SEGMENT_ROM_START(d2_fine_static), size); // Send a DMA request for the skybox palette - skyboxCtx->paletteStaticSegment = segment; - size = SEGMENT_ROM_SIZE(d2_fine_pal_static); - segment = (void*)ALIGN8((uintptr_t)segment + size); - DmaMgr_SendRequest0(skyboxCtx->paletteStaticSegment, SEGMENT_ROM_START(d2_fine_pal_static), size); + // skyboxCtx->paletteStaticSegment = segment; + // size = SEGMENT_ROM_SIZE(d2_fine_pal_static); + // segment = (void*)ALIGN8((uintptr_t)segment + size); + // ResourceMgr_LoadTexOrDListByName(gClearSkyboxTlue); + ////DmaMgr_SendRequest0(skyboxCtx->paletteStaticSegment, SEGMENT_ROM_START(d2_fine_pal_static), size); skyboxCtx->prim.r = 145; skyboxCtx->prim.g = 120; @@ -225,6 +255,17 @@ void Skybox_Setup(GameState* gameState, SkyboxContext* skyboxCtx, s16 skyboxId) break; case SKYBOX_2: + // BENTODO: in the original code, this case does nothing + // however this causes skyboxCtx->staticSegments to be 0 which in turn causes + // the draw calls in func_80142440 to crash because of the texture address ends up being 0 + // I'm not sure if this is a mm bug or a 2s2h bug + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[0][i] = sD2FineStaticTex[i]; + } + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[1][i] = sD2CloudStaticTex[i]; + } + skyboxCtx->paletteStaticSegment = gClearSkyboxTlue; break; default: @@ -240,46 +281,60 @@ void func_80143324(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) { osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1); if (play->envCtx.skybox1Index == 0) { - // Send a DMA request for the clear sky texture - size = SEGMENT_ROM_SIZE(d2_fine_static); - - DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->staticSegments[0], - SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL); + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[0][i] = sD2FineStaticTex[i]; + } + //// Send a DMA request for the clear sky texture + // size = SEGMENT_ROM_SIZE(d2_fine_static); + // + // DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->staticSegments[0], + // SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL); } else { - // Send a DMA request for the cloudy sky texture - size = SEGMENT_ROM_SIZE(d2_cloud_static); - - DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->staticSegments[0], - SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL); + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[0][i] = sD2CloudStaticTex[i]; + } + //// Send a DMA request for the cloudy sky texture + // size = SEGMENT_ROM_SIZE(d2_cloud_static); + // + // DmaMgr_SendRequestImpl(&skyboxCtx->unk188, skyboxCtx->staticSegments[0], + // SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL); } osRecvMesg(&skyboxCtx->loadQueue, NULL, OS_MESG_BLOCK); osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1); if (play->envCtx.skybox2Index == 0) { + + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[1][i] = sD2FineStaticTex[i]; + } // Send a DMA request for the clear sky texture - size = SEGMENT_ROM_SIZE(d2_fine_static); - - DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->staticSegments[1], - SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL); + // size = SEGMENT_ROM_SIZE(d2_fine_static); + // + // DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->staticSegments[1], + // SEGMENT_ROM_START(d2_fine_static), size, 0, &skyboxCtx->loadQueue, NULL); } else { + for (size_t i = 0; i < ARRAY_COUNTU(sD2FineStaticTex); i++) { + skyboxCtx->staticSegments[1][i] = sD2CloudStaticTex[i]; + } // Send a DMA request for the cloudy sky texture - size = SEGMENT_ROM_SIZE(d2_cloud_static); - - DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->staticSegments[1], - SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL); + // size = SEGMENT_ROM_SIZE(d2_cloud_static); + // + // DmaMgr_SendRequestImpl(&skyboxCtx->unk1A8, skyboxCtx->staticSegments[1], + // SEGMENT_ROM_START(d2_cloud_static), size, 0, &skyboxCtx->loadQueue, NULL); } osRecvMesg(&skyboxCtx->loadQueue, NULL, OS_MESG_BLOCK); osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1); + skyboxCtx->paletteStaticSegment = gClearSkyboxTlue; + // size = SEGMENT_ROM_SIZE(d2_fine_pal_static); + // + //// Send a DMA request for the skybox palette + // DmaMgr_SendRequestImpl(&skyboxCtx->unk1C8, skyboxCtx->paletteStaticSegment, + // SEGMENT_ROM_START(d2_fine_pal_static), size, 0, &skyboxCtx->loadQueue, NULL); + // + // osRecvMesg(&skyboxCtx->loadQueue, NULL, OS_MESG_BLOCK); - size = SEGMENT_ROM_SIZE(d2_fine_pal_static); - - // Send a DMA request for the skybox palette - DmaMgr_SendRequestImpl(&skyboxCtx->unk1C8, skyboxCtx->paletteStaticSegment, - SEGMENT_ROM_START(d2_fine_pal_static), size, 0, &skyboxCtx->loadQueue, NULL); - - osRecvMesg(&skyboxCtx->loadQueue, NULL, OS_MESG_BLOCK); break; default: diff --git a/mm/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c b/mm/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c index 0b8a8ed0b..5510fad02 100644 --- a/mm/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c +++ b/mm/src/overlays/actors/ovl_Arrow_Fire/z_arrow_fire.c @@ -19,7 +19,7 @@ void ArrowFire_Draw(Actor* thisx, PlayState* play); void FireArrow_ChargeAndWait(ArrowFire* this, PlayState* play); void FireArrow_Fly(ArrowFire* this, PlayState* play); -#include "overlays/ovl_Arrow_Fire/ovl_Arrow_Fire.c" +#include "overlays/ovl_Arrow_Fire/ovl_Arrow_Fire.h" ActorInit Arrow_Fire_InitVars = { /**/ ACTOR_ARROW_FIRE, @@ -265,7 +265,8 @@ void ArrowFire_Draw(Actor* thisx, PlayState* play) { gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE); gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE); - gSPDisplayList(POLY_XLU_DISP++, D_0E000000.fillRect); + __gSPDisplayList(POLY_XLU_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); } Gfx_SetupDL25_Xlu(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c b/mm/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c index 4b3d7507a..e6353dc32 100644 --- a/mm/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c +++ b/mm/src/overlays/actors/ovl_Arrow_Ice/z_arrow_ice.c @@ -19,9 +19,7 @@ void ArrowIce_Draw(Actor* thisx, PlayState* play); void ArrowIce_Charge(ArrowIce* this, PlayState* play); void ArrowIce_Fly(ArrowIce* this, PlayState* play); -#include "overlays/ovl_Arrow_Ice/ovl_Arrow_Ice.c" - -static s32 sBssPad; +#include "overlays/ovl_Arrow_Ice/ovl_Arrow_Ice.h" ActorInit Arrow_Ice_InitVars = { /**/ ACTOR_ARROW_ICE, @@ -210,7 +208,8 @@ void ArrowIce_Draw(Actor* thisx, PlayState* play) { (s32)(150.0f * this->blueingEffectMagnitude) & 0xFF); gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE); gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE); - gSPDisplayList(POLY_XLU_DISP++, D_0E000000.fillRect); + __gSPDisplayList(POLY_XLU_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); } // Draw ice on the arrow diff --git a/mm/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c b/mm/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c index bd67099b4..e2b281cd9 100644 --- a/mm/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c +++ b/mm/src/overlays/actors/ovl_Arrow_Light/z_arrow_light.c @@ -19,7 +19,7 @@ void ArrowLight_Draw(Actor* thisx, PlayState* play); void ArrowLight_Charge(ArrowLight* this, PlayState* play); void ArrowLight_Fly(ArrowLight* this, PlayState* play); -#include "overlays/ovl_Arrow_Light/ovl_Arrow_Light.c" +#include "overlays/ovl_Arrow_Light/ovl_Arrow_Light.h" ActorInit Arrow_Light_InitVars = { /**/ ACTOR_ARROW_LIGHT, @@ -37,8 +37,6 @@ static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneForward, 2000, ICHAIN_STOP), }; -static s32 sBssPad; - void ArrowLight_SetupAction(ArrowLight* this, ArrowLightActionFunc actionFunc) { this->actionFunc = actionFunc; } @@ -202,7 +200,8 @@ void ArrowLight_Draw(Actor* thisx, PlayState* play) { (s32)(150.0f * this->screenFillIntensity) & 0xFF); gDPSetAlphaDither(POLY_XLU_DISP++, G_AD_DISABLE); gDPSetColorDither(POLY_XLU_DISP++, G_CD_DISABLE); - gSPDisplayList(POLY_XLU_DISP++, D_0E000000.fillRect); + __gSPDisplayList(POLY_XLU_DISP++, + 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); } Gfx_SetupDL25_Xlu(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_Boss_05/z_boss_05.c b/mm/src/overlays/actors/ovl_Boss_05/z_boss_05.c index 47d0d8277..3390ed58b 100644 --- a/mm/src/overlays/actors/ovl_Boss_05/z_boss_05.c +++ b/mm/src/overlays/actors/ovl_Boss_05/z_boss_05.c @@ -38,7 +38,8 @@ void func_809F0A64(Boss05* this, PlayState* play); void func_809F0ABC(Boss05* this, PlayState* play); void func_809F0B0C(Boss05* this, PlayState* play); -#include "overlays/ovl_Boss_05/ovl_Boss_05.c" +#include "overlays/ovl_Boss_05/ovl_Boss_05.h" +#include "objects/object_boss05/object_boss05.h" // static ColliderJntSphElementInit sJntSphElementsInit[2] = { ColliderJntSphElementInit D_809F1B2C[2] = { @@ -226,19 +227,6 @@ ActorInit Boss_05_InitVars = { /**/ Boss05_Draw, }; -extern AnimationHeader D_060006A4; -extern AnimationHeader D_06000A5C; -extern AnimationHeader D_06000ABC; -extern FlexSkeletonHeader D_060024E0; -extern AnimationHeader D_06002F0C; -extern AnimationHeader D_06003448; -extern AnimatedMaterial D_06006240[]; -extern FlexSkeletonHeader D_06006378; -extern AnimationHeader D_06006484; -extern AnimationHeader D_06006E50; -extern AnimationHeader D_06007488; -extern AnimationHeader D_06007908; - void func_809EE4E0(Boss05* this, PlayState* play) { Vec3f icePos; Vec3f iceVelocity; @@ -295,11 +283,11 @@ void Boss05_Init(Actor* thisx, PlayState* play) { this->dyna.bgId = DynaPoly_SetBgActor(play, &play->colCtx.dyna, &this->dyna.actor, colHeader); func_809EEDD0(this, play); - SkelAnime_InitFlex(play, &this->skelAnime10, &D_060024E0, &D_06000ABC, this->jointTable10, this->morphTable10, + SkelAnime_InitFlex(play, &this->skelAnime10, &gBioDekuBabaLilyPadSkel, &gBioDekuBabaLilyPadIdleAnim, this->jointTable10, this->morphTable10, 10); - SkelAnime_InitFlex(play, &this->skelAnime20, &D_06006378, &D_06006484, this->jointTable20, this->morphTable20, + SkelAnime_InitFlex(play, &this->skelAnime20, &gBioDekuBabaHeadSkel, &gBioDekuBabaHeadChompAnim, this->jointTable20, this->morphTable20, 20); - this->lastAnimFrame = Animation_GetLastFrame(&D_06006484); + this->lastAnimFrame = Animation_GetLastFrame(&gBioDekuBabaHeadChompAnim); Collider_InitAndSetJntSph(play, &this->collider2, &this->dyna.actor, &D_809F1B74, this->colliderElements2); Collider_InitAndSetJntSph(play, &this->collider1, &this->dyna.actor, &D_809F1BA8, this->colliderElements1); @@ -316,7 +304,7 @@ void Boss05_Init(Actor* thisx, PlayState* play) { CollisionHeader_GetVirtual(&sBioBabaLilypadCol, &colHeader); this->dyna.bgId = DynaPoly_SetBgActor(play, &play->colCtx.dyna, &this->dyna.actor, colHeader); - SkelAnime_InitFlex(play, &this->skelAnime10, &D_060024E0, &D_06000ABC, this->jointTable10, this->morphTable10, + SkelAnime_InitFlex(play, &this->skelAnime10, &gBioDekuBabaLilyPadSkel, &gBioDekuBabaLilyPadIdleAnim, this->jointTable10, this->morphTable10, 10); this->dyna.actor.flags &= ~ACTOR_FLAG_TARGETABLE; func_800BC154(play, &play->actorCtx, &this->dyna.actor, ACTORCAT_BG); @@ -324,11 +312,11 @@ void Boss05_Init(Actor* thisx, PlayState* play) { this->actionFunc = func_809EFAB4; this->unk198 = 1.0f; - SkelAnime_InitFlex(play, &this->skelAnime10, &D_060024E0, &D_06000ABC, this->jointTable10, this->morphTable10, + SkelAnime_InitFlex(play, &this->skelAnime10, &gBioDekuBabaLilyPadSkel, &gBioDekuBabaLilyPadIdleAnim, this->jointTable10, this->morphTable10, 10); - SkelAnime_InitFlex(play, &this->skelAnime20, &D_06006378, &D_06006484, this->jointTable20, this->morphTable20, + SkelAnime_InitFlex(play, &this->skelAnime20, &gBioDekuBabaHeadSkel, &gBioDekuBabaHeadChompAnim, this->jointTable20, this->morphTable20, 20); - this->lastAnimFrame = Animation_GetLastFrame(&D_06006484); + this->lastAnimFrame = Animation_GetLastFrame(&gBioDekuBabaHeadChompAnim); Collider_InitAndSetJntSph(play, &this->collider2, &this->dyna.actor, &D_809F1B74, this->colliderElements2); Collider_InitAndSetJntSph(play, &this->collider1, &this->dyna.actor, &D_809F1BA8, this->colliderElements1); @@ -339,7 +327,7 @@ void Boss05_Init(Actor* thisx, PlayState* play) { func_809F00CC(this, play); this->dyna.actor.colChkInfo.mass = 90; - SkelAnime_InitFlex(play, &this->skelAnime20, &D_06006378, &D_06006484, this->jointTable20, this->morphTable20, + SkelAnime_InitFlex(play, &this->skelAnime20, &gBioDekuBabaHeadSkel, &gBioDekuBabaHeadChompAnim, this->jointTable20, this->morphTable20, 20); Collider_InitAndSetJntSph(play, &this->collider1, &this->dyna.actor, &D_809F1BDC, this->colliderElements1); @@ -348,7 +336,7 @@ void Boss05_Init(Actor* thisx, PlayState* play) { this->dyna.actor.colChkInfo.damageTable = &D_809F1C20; this->dyna.actor.flags |= ACTOR_FLAG_10 | ACTOR_FLAG_20; } else if (this->dyna.actor.params >= BIO_DEKU_BABA_TYPE_10) { - SkelAnime_InitFlex(play, &this->skelAnime20, &D_06006378, &D_06006484, this->jointTable20, this->morphTable20, + SkelAnime_InitFlex(play, &this->skelAnime20, &gBioDekuBabaHeadSkel, &gBioDekuBabaHeadChompAnim, this->jointTable20, this->morphTable20, 20); this->dyna.actor.gravity = 0.0f; @@ -885,7 +873,7 @@ void func_809F0058(Boss05* this, PlayState* play) { void func_809F00CC(Boss05* this, PlayState* play) { this->actionFunc = func_809F010C; - Animation_MorphToPlayOnce(&this->skelAnime20, &D_06006E50, -5.0f); + Animation_MorphToPlayOnce(&this->skelAnime20, &gBioDekuBabaHeadTransformAnim, -5.0f); } void func_809F010C(Boss05* this, PlayState* play) { @@ -902,7 +890,7 @@ void func_809F010C(Boss05* this, PlayState* play) { void func_809F01CC(Boss05* this, PlayState* play) { this->actionFunc = func_809F0244; - Animation_MorphToLoop(&this->skelAnime20, &D_06007488, -10.0f); + Animation_MorphToLoop(&this->skelAnime20, &gBioDekuBabaHeadIdleAnim, -10.0f); this->unk162[0] = (s32)(Rand_ZeroFloat(25.0f) + 25.0f); Actor_PlaySfx(&this->dyna.actor, NA_SE_EN_MIZUBABA1_MOUTH); } @@ -922,7 +910,7 @@ void func_809F0244(Boss05* this, PlayState* play) { void func_809F02D0(Boss05* this, PlayState* play) { this->actionFunc = func_809F0374; - Animation_MorphToLoop(&this->skelAnime20, &D_06007908, 0.0f); + Animation_MorphToLoop(&this->skelAnime20, &gBioDekuBabaHeadWalkAnim, 0.0f); this->unk162[0] = (s32)(Rand_ZeroFloat(80.0f) + 60.0f); this->unk34C.x = Rand_CenteredFloat(400.0f) + this->dyna.actor.world.pos.x; this->unk34C.z = Rand_CenteredFloat(400.0f) + this->dyna.actor.world.pos.z; @@ -950,7 +938,7 @@ void func_809F0374(Boss05* this, PlayState* play) { void func_809F0474(Boss05* this, PlayState* play) { this->actionFunc = func_809F04C0; - Animation_MorphToPlayOnce(&this->skelAnime20, &D_06003448, 0.0f); + Animation_MorphToPlayOnce(&this->skelAnime20, &gBioDekuBabaHeadSpotAnim, 0.0f); this->unk162[0] = 20; } @@ -966,7 +954,7 @@ void func_809F04C0(Boss05* this, PlayState* play) { void func_809F0538(Boss05* this, PlayState* arg1) { this->actionFunc = func_809F0590; - Animation_MorphToLoop(&this->skelAnime20, &D_06000A5C, 0.0f); + Animation_MorphToLoop(&this->skelAnime20, &gBioDekuBabaHeadChargeAnim, 0.0f); this->unk162[0] = 60; this->unk358 = 0.0f; } @@ -985,8 +973,8 @@ void func_809F0590(Boss05* this, PlayState* play) { void func_809F0650(Boss05* this, PlayState* arg1) { this->actionFunc = func_809F06B8; - Animation_MorphToPlayOnce(&this->skelAnime20, &D_060006A4, 0.0f); - this->lastAnimFrame = Animation_GetLastFrame(&D_060006A4); + Animation_MorphToPlayOnce(&this->skelAnime20, &gBioDekuBabaHeadAttackAnim, 0.0f); + this->lastAnimFrame = Animation_GetLastFrame(&gBioDekuBabaHeadAttackAnim); Actor_PlaySfx(&this->dyna.actor, NA_SE_EN_MIZUBABA2_ATTACK); } @@ -999,8 +987,8 @@ void func_809F06B8(Boss05* this, PlayState* play) { void func_809F0708(Boss05* this, PlayState* play) { this->actionFunc = func_809F0780; - Animation_MorphToPlayOnce(&this->skelAnime20, &D_06002F0C, 0.0f); - this->lastAnimFrame = Animation_GetLastFrame(&D_060006A4); + Animation_MorphToPlayOnce(&this->skelAnime20, &gBioDekuBabaHeadDamagedAnim, 0.0f); + this->lastAnimFrame = Animation_GetLastFrame(&gBioDekuBabaHeadAttackAnim); Actor_SetColorFilter(&this->dyna.actor, 0x4000, 120, 0, 30); } @@ -1402,7 +1390,7 @@ void Boss05_Draw(Actor* thisx, PlayState* play) { Matrix_RotateZS(this->unk330.z, MTXMODE_APPLY); Matrix_Scale(this->dyna.actor.scale.x, this->dyna.actor.scale.y, this->dyna.actor.scale.z, MTXMODE_APPLY); - AnimatedMat_Draw(play, Lib_SegmentedToVirtual(D_06006240)); + AnimatedMat_Draw(play, Lib_SegmentedToVirtual(gBioDekuBabaHeadEyeFlashTexAnim)); SkelAnime_DrawTransformFlexOpa(play, this->skelAnime20.skeleton, this->skelAnime20.jointTable, this->skelAnime20.dListCount, func_809F1284, func_809F12A0, func_809F135C, @@ -1431,7 +1419,7 @@ void Boss05_Draw(Actor* thisx, PlayState* play) { Matrix_RotateZS(this->unk330.z, MTXMODE_APPLY); Matrix_Scale(this->dyna.actor.scale.x, this->dyna.actor.scale.y, this->dyna.actor.scale.z, MTXMODE_APPLY); - AnimatedMat_Draw(play, Lib_SegmentedToVirtual(D_06006240)); + AnimatedMat_Draw(play, Lib_SegmentedToVirtual(gBioDekuBabaHeadEyeFlashTexAnim)); SkelAnime_DrawTransformFlexOpa(play, this->skelAnime20.skeleton, this->skelAnime20.jointTable, this->skelAnime20.dListCount, func_809F1284, func_809F12A0, func_809F135C, @@ -1441,7 +1429,7 @@ void Boss05_Draw(Actor* thisx, PlayState* play) { this->drawDmgEffScale, this->dmgEffFrozenSteamScale, this->drawDmgEffAlpha, this->drawDmgEffType); } else if (this->dyna.actor.params == BIO_DEKU_BABA_TYPE_4) { - AnimatedMat_Draw(play, Lib_SegmentedToVirtual(D_06006240)); + AnimatedMat_Draw(play, Lib_SegmentedToVirtual(gBioDekuBabaHeadEyeFlashTexAnim)); if ((this->unk16C % 2) != 0) { POLY_OPA_DISP = Gfx_SetFog(POLY_OPA_DISP, 255, 0, 0, 255, 900, 1099); @@ -1455,7 +1443,7 @@ void Boss05_Draw(Actor* thisx, PlayState* play) { this->drawDmgEffScale, this->dmgEffFrozenSteamScale, this->drawDmgEffAlpha, this->drawDmgEffType); } else if (this->dyna.actor.params >= BIO_DEKU_BABA_TYPE_10) { - AnimatedMat_Draw(play, Lib_SegmentedToVirtual(D_06006240)); + AnimatedMat_Draw(play, Lib_SegmentedToVirtual(gBioDekuBabaHeadEyeFlashTexAnim)); SkelAnime_DrawFlexOpa(play, this->skelAnime20.skeleton, this->skelAnime20.jointTable, this->skelAnime20.dListCount, func_809F14AC, func_809F1550, &this->dyna.actor); diff --git a/mm/src/overlays/actors/ovl_Boss_07/z_boss_07.c b/mm/src/overlays/actors/ovl_Boss_07/z_boss_07.c index c227ac821..5e0e02689 100644 --- a/mm/src/overlays/actors/ovl_Boss_07/z_boss_07.c +++ b/mm/src/overlays/actors/ovl_Boss_07/z_boss_07.c @@ -1867,7 +1867,7 @@ void Boss07_Wrath_Damaged(Boss07* this, PlayState* play) { void Boss07_Wrath_WhipCollisionCheck(Vec3f* whipPos, f32 tension, Boss07* this, PlayState* play) { s32 i; - PlayerImpactType sp98 = -1; + PlayerImpactType sp98 = -1; Player* player = GET_PLAYER(play); f32 dx; f32 dy; @@ -2624,9 +2624,8 @@ void Boss07_Wrath_TransformLimbDraw(PlayState* play, s32 limbIndex, Actor* thisx void Boss07_Wrath_DrawShocks(Boss07* this, PlayState* play) { s32 i; - GraphicsContext* gfxCtx; - OPEN_DISPS(gfxCtx = play->state.gfxCtx); + OPEN_DISPS(play->state.gfxCtx); if ((this->unk_32C > 0.0f) || (this->unk_330 > 0.0f)) { Gfx_SetupDL25_Xlu(play->state.gfxCtx); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 255, 255, 255); @@ -2640,7 +2639,8 @@ void Boss07_Wrath_DrawShocks(Boss07* this, PlayState* play) { Matrix_ReplaceRotation(&play->billboardMtxF); Matrix_Scale(this->unk_32C, this->unk_32C, this->unk_32C, MTXMODE_APPLY); Matrix_RotateZF(Rand_ZeroFloat(2.0f * M_PI), MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gLightOrbModelDL); } for (i = this->whipShockIndexHigh; i >= this->whipShockIndexLow; i--) { @@ -2648,7 +2648,8 @@ void Boss07_Wrath_DrawShocks(Boss07* this, PlayState* play) { Matrix_ReplaceRotation(&play->billboardMtxF); Matrix_Scale(1.5f, 1.5f, 1.5f, MTXMODE_APPLY); Matrix_RotateZF(Rand_ZeroFloat(2.0f * M_PI), MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gLightOrbModelDL); } } @@ -2661,22 +2662,22 @@ void Boss07_Wrath_DrawShocks(Boss07* this, PlayState* play) { Matrix_Scale(this->unk_330, this->unk_330, this->unk_330, MTXMODE_APPLY); Matrix_RotateXFApply(Rand_ZeroFloat(2.0f * M_PI)); Matrix_RotateZF(Rand_ZeroFloat(2.0f * M_PI), MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gLightOrbModelDL); } } } - CLOSE_DISPS(gfxCtx); + CLOSE_DISPS(play->state.gfxCtx); } void Boss07_Wrath_DrawDeathLights(Boss07* this, PlayState* play, Vec3f* pos) { s32 i; f32 temp_f12_2; f32 temp_f20; - GraphicsContext* gfxCtx; s16* temp; - OPEN_DISPS(gfxCtx = play->state.gfxCtx); + OPEN_DISPS(play->state.gfxCtx); if (this->deathOrbScale > 0.0f) { Boss07_InitRand(1, 0x71B8, 0x263A); @@ -2694,7 +2695,8 @@ void Boss07_Wrath_DrawDeathLights(Boss07* this, PlayState* play, Vec3f* pos) { Matrix_RotateZF(Boss07_RandZeroOne() * M_PI * 2.0f, MTXMODE_APPLY); if (this->deathLightScale[i] > 0.0f) { Matrix_Scale(this->deathLightScale[i], 1.0f, 12.0f, MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gMajorasWrathDeathLightModelDL); } } @@ -2711,17 +2713,16 @@ void Boss07_Wrath_DrawDeathLights(Boss07* this, PlayState* play, Vec3f* pos) { gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gLightOrbModelDL); } - CLOSE_DISPS(gfxCtx); + CLOSE_DISPS(play->state.gfxCtx); } void Boss07_Static_DrawLight(Boss07* this, PlayState* play) { s32 pad; - GraphicsContext* gfxCtx; f32 sp54; f32 sp50; Player* player; - OPEN_DISPS(gfxCtx = play->state.gfxCtx); + OPEN_DISPS(play->state.gfxCtx); player = GET_PLAYER(play); if (this->introOrbScale > 0.0f) { @@ -2747,10 +2748,10 @@ void Boss07_Static_DrawLight(Boss07* this, PlayState* play) { Matrix_Scale(this->introOrbScale, this->introOrbScale, this->introOrbScale, MTXMODE_APPLY); Matrix_RotateZS(play->gameplayFrames * 0x40, MTXMODE_APPLY); - gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gLightOrbModelDL); } - CLOSE_DISPS(gfxCtx); + CLOSE_DISPS(play->state.gfxCtx); } void Boss07_Wrath_Draw(Actor* thisx, PlayState* play2) { diff --git a/mm/src/overlays/actors/ovl_Dm_Char00/z_dm_char00.c b/mm/src/overlays/actors/ovl_Dm_Char00/z_dm_char00.c index 2e071f823..691fd6302 100644 --- a/mm/src/overlays/actors/ovl_Dm_Char00/z_dm_char00.c +++ b/mm/src/overlays/actors/ovl_Dm_Char00/z_dm_char00.c @@ -7,6 +7,8 @@ #include "z_dm_char00.h" #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/object_delf/object_delf.h" +#include "z64animation.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20) @@ -678,7 +680,7 @@ void DmChar00_Init(Actor* thisx, PlayState* play) { this->unk_262 = DMCHAR00_GET_F800(thisx); ActorShape_Init(&thisx->shape, 0.0f, ActorShadow_DrawCircle, 24.0f); - SkelAnime_Init(play, &this->skelAnime, &gameplay_keep_Skel_02AF58.sh, &gameplay_keep_Anim_029140, this->jointTable, + SkelAnime_Init(play, &this->skelAnime, gameplay_keep_Skel_02AF58, &gameplay_keep_Anim_029140, this->jointTable, this->morphTable, FAIRY_LIMB_MAX); ActorShape_Init(&thisx->shape, 0.0f, NULL, 15.0f); DmChar00_ChangeAnim(&this->skelAnime, &sAnimationInfo[DMCHAR00_ANIM_0], 0); diff --git a/mm/src/overlays/actors/ovl_Dm_Char01/z_dm_char01.c b/mm/src/overlays/actors/ovl_Dm_Char01/z_dm_char01.c index 710a1863c..99dc29bc9 100644 --- a/mm/src/overlays/actors/ovl_Dm_Char01/z_dm_char01.c +++ b/mm/src/overlays/actors/ovl_Dm_Char01/z_dm_char01.c @@ -8,6 +8,7 @@ #include "z_dm_char01.h" #include "objects/object_mtoride/object_mtoride.h" #include "overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20 | ACTOR_FLAG_2000000) @@ -34,18 +35,18 @@ s16 D_80AAAE22; s16 D_80AAAE24; s16 D_80AAAE26; -#include "overlays/ovl_Dm_Char01/ovl_Dm_Char01.c" +#include "overlays/ovl_Dm_Char01/ovl_Dm_Char01.h" ActorInit Dm_Char01_InitVars = { - /**/ ACTOR_DM_CHAR01, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ OBJECT_MTORIDE, - /**/ sizeof(DmChar01), - /**/ DmChar01_Init, - /**/ DmChar01_Destroy, - /**/ DmChar01_Update, - /**/ DmChar01_Draw, + ACTOR_DM_CHAR01, + ACTORCAT_ITEMACTION, + FLAGS, + OBJECT_MTORIDE, + sizeof(DmChar01), + (ActorFunc)DmChar01_Init, + (ActorFunc)DmChar01_Destroy, + (ActorFunc)DmChar01_Update, + (ActorFunc)DmChar01_Draw, }; static InitChainEntry sInitChain[] = { @@ -53,10 +54,12 @@ static InitChainEntry sInitChain[] = { }; s16 D_80AAAAB4 = false; +Vtx* gWoodfallSceneryDynamicPoisonWaterVtxData; void DmChar01_Init(Actor* thisx, PlayState* play) { DmChar01* this = THIS; s32 i; + gWoodfallSceneryDynamicPoisonWaterVtxData = ResourceMgr_LoadVtxByName(gWoodfallSceneryDynamicPoisonWaterVtx); Actor_ProcessInitChain(&this->dyna.actor, sInitChain); Actor_SetScale(&this->dyna.actor, 1.0f); @@ -81,7 +84,7 @@ void DmChar01_Init(Actor* thisx, PlayState* play) { this->unk_348 = 255.0f; for (i = 0; i < ARRAY_COUNT(this->unk_1AC); i++) { - this->unk_1AC[i] = gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[1] * 409.6f; + this->unk_1AC[i] = gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[1] * 409.6f; } DynaPolyActor_Init(&this->dyna, 0); @@ -254,9 +257,9 @@ void func_80AA892C(DmChar01* this, PlayState* play) { this->unk_34C = 0; } - for (i = 0; i < ARRAY_COUNT(gWoodfallSceneryDynamicPoisonWaterVtx); i++) { - s32 temp_s2 = sqrtf(SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[2]) + - SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[0])); + for (i = 0; i < ARRAY_COUNT(gWoodfallSceneryDynamicPoisonWaterVtxData); i++) { + s32 temp_s2 = sqrtf(SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[2]) + + SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[0])); f32 cos = Math_CosS((temp_s2 / 1892.0f) * 0x4000); f32 temp_f20 = (1.0f - (ABS_ALT(temp_s2 - D_80AAAE22) / 1892.0f)) * D_80AAAE20 * cos; @@ -268,7 +271,7 @@ void func_80AA892C(DmChar01* this, PlayState* play) { temp_f20 += temp_f18; this->unk_1AC[i] += 1600; - gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[1] = temp_f20; + gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[1] = temp_f20; } } @@ -300,9 +303,9 @@ void func_80AA8C28(DmChar01* this, PlayState* play) { break; } - for (i = 0; i < ARRAY_COUNT(gWoodfallSceneryDynamicPoisonWaterVtx); i++) { - s32 temp_s2 = sqrtf(SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[2]) + - SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[0])); + for (i = 0; i < ARRAY_COUNT(gWoodfallSceneryDynamicPoisonWaterVtxData); i++) { + s32 temp_s2 = sqrtf(SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[2]) + + SQ((f32)gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[0])); f32 cos = Math_CosS((temp_s2 / 1892.0f) * 0x4000); f32 temp_f20 = (1.0f - (ABS_ALT(temp_s2 - D_80AAAE22) / 1892.0f)) * D_80AAAE20 * cos; @@ -314,7 +317,7 @@ void func_80AA8C28(DmChar01* this, PlayState* play) { temp_f20 += temp_f18; this->unk_1AC[i] += 1600; - gWoodfallSceneryDynamicPoisonWaterVtx[i].v.ob[1] = temp_f20; + gWoodfallSceneryDynamicPoisonWaterVtxData[i].v.ob[1] = temp_f20; } Math_SmoothStepToF(&this->unk_348, 0.0f, 0.02f, 0.6f, 0.4f); @@ -431,7 +434,7 @@ void DmChar01_Draw(Actor* thisx, PlayState* play) { gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0x96, 255, 255, 255, 255); gSPSegment(POLY_OPA_DISP++, 0x0B, - Lib_SegmentedToVirtual(gWoodfallSceneryDynamicPoisonWaterVtx)); + Lib_SegmentedToVirtual(gWoodfallSceneryDynamicPoisonWaterVtxData)); gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_OPA_DISP++, gWoodfallSceneryDynamicPoisonWaterDL); @@ -443,7 +446,7 @@ void DmChar01_Draw(Actor* thisx, PlayState* play) { gDPSetEnvColor(POLY_XLU_DISP++, 0, 0, 0, (u8)this->unk_348); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0x96, 255, 255, 255, (u8)this->unk_348); gSPSegment(POLY_XLU_DISP++, 0x0B, - Lib_SegmentedToVirtual(gWoodfallSceneryDynamicPoisonWaterVtx)); + Lib_SegmentedToVirtual(gWoodfallSceneryDynamicPoisonWaterVtxData)); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gWoodfallSceneryDynamicPoisonWaterDL); diff --git a/mm/src/overlays/actors/ovl_Dm_Char04/z_dm_char04.c b/mm/src/overlays/actors/ovl_Dm_Char04/z_dm_char04.c index 484592584..e199bdc3a 100644 --- a/mm/src/overlays/actors/ovl_Dm_Char04/z_dm_char04.c +++ b/mm/src/overlays/actors/ovl_Dm_Char04/z_dm_char04.c @@ -76,7 +76,7 @@ void DmChar04_Init(Actor* thisx, PlayState* play) { this->cueId = 99; this->timer = this->actor.params << 0xB; ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 24.0f); - SkelAnime_Init(play, &this->skelAnime, &gameplay_keep_Skel_02AF58.sh, &gameplay_keep_Anim_029140, this->jointTable, + SkelAnime_Init(play, &this->skelAnime, &gameplay_keep_Skel_02AF58, &gameplay_keep_Anim_029140, this->jointTable, this->morphTable, FAIRY_LIMB_MAX); ActorShape_Init(&this->actor.shape, 0.0f, NULL, 15.0f); DmChar04_ChangeAnim(&this->skelAnime, &sAnimationInfo[DMCHAR04_ANIM_0], 0); diff --git a/mm/src/overlays/actors/ovl_Dm_Char08/z_dm_char08.c b/mm/src/overlays/actors/ovl_Dm_Char08/z_dm_char08.c index f829219c9..25527363a 100644 --- a/mm/src/overlays/actors/ovl_Dm_Char08/z_dm_char08.c +++ b/mm/src/overlays/actors/ovl_Dm_Char08/z_dm_char08.c @@ -6,6 +6,7 @@ #include "z_dm_char08.h" #include "objects/object_kamejima/object_kamejima.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_2000000) @@ -37,18 +38,18 @@ typedef enum { } TurtleEyeMode; ActorInit Dm_Char08_InitVars = { - /**/ ACTOR_DM_CHAR08, - /**/ ACTORCAT_BG, - /**/ FLAGS, - /**/ OBJECT_KAMEJIMA, - /**/ sizeof(DmChar08), - /**/ DmChar08_Init, - /**/ DmChar08_Destroy, - /**/ DmChar08_Update, - /**/ DmChar08_Draw, + ACTOR_DM_CHAR08, + ACTORCAT_BG, + FLAGS, + OBJECT_KAMEJIMA, + sizeof(DmChar08), + (ActorFunc)DmChar08_Init, + (ActorFunc)DmChar08_Destroy, + (ActorFunc)DmChar08_Update, + (ActorFunc)DmChar08_Draw, }; -#include "overlays/ovl_Dm_Char08/ovl_Dm_Char08.c" +#include "overlays/ovl_Dm_Char08/ovl_Dm_Char08.h" typedef enum { /* 0 */ TURTLE_ANIM_IDLE, @@ -78,6 +79,10 @@ static InitChainEntry sInitChain[] = { ICHAIN_F32(uncullZoneDownward, 4000, ICHAIN_STOP), }; +static CollisionHeader* sTurtleGreatBayTempleColData; +static Vec3s* sTurtleGreatBayTempleColVerticesData; +static Vec3s* sTurtleGreatBayTempleColVertices2Data; + void DmChar08_UpdateEyes(DmChar08* this) { switch (this->eyeMode) { case TURTLE_EYEMODE_BLINK_LEFT: @@ -145,6 +150,9 @@ void DmChar08_ChangeAnim(SkelAnime* skelAnime, AnimationInfo* animInfo, u16 anim void DmChar08_Init(Actor* thisx, PlayState* play2) { PlayState* play = play2; DmChar08* this = THIS; + sTurtleGreatBayTempleColData = ResourceMgr_LoadColByName(sTurtleGreatBayTempleCol); + sTurtleGreatBayTempleColVerticesData = ResourceMgr_LoadArrayByNameAsVec3s(sTurtleGreatBayTempleColVertices); + sTurtleGreatBayTempleColVertices2Data = ResourceMgr_LoadArrayByNameAsVec3s(sTurtleGreatBayTempleColVertices2); thisx->targetMode = TARGET_MODE_5; this->eyeMode = TURTLE_EYEMODE_CLOSED; @@ -173,7 +181,7 @@ void DmChar08_Init(Actor* thisx, PlayState* play2) { this->dynapolyInitialized = true; } else if (play->sceneId == SCENE_SEA) { DynaPolyActor_Init(&this->dyna, DYNA_TRANSFORM_POS | DYNA_TRANSFORM_ROT_Y); - DynaPolyActor_LoadMesh(play, &this->dyna, &sTurtleGreatBayTempleCol); + DynaPolyActor_LoadMesh(play, &this->dyna, sTurtleGreatBayTempleColData); this->dynapolyInitialized = true; } @@ -973,18 +981,18 @@ void DmChar08_UpdateCollision(DmChar08* this, PlayState* play) { phi_f12 = 29.0f; } - sTurtleGreatBayTempleCol.polyList = sTurtleGreatBayTempleColPolygons; + sTurtleGreatBayTempleColData->polyList = sTurtleGreatBayTempleColPolygons; - for (i = 0; i < ARRAY_COUNT(sTurtleGreatBayTempleColVertices); i++) { - sTurtleGreatBayTempleColVertices[i].x = sTurtleGreatBayTempleColVertices2[i].x; + for (i = 0; i < ResourceMgr_GetArraySizeByName(sTurtleGreatBayTempleColVertices); i++) { + sTurtleGreatBayTempleColVerticesData[i].x = sTurtleGreatBayTempleColVertices2Data[i].x; } - sTurtleGreatBayTempleColVertices[0].y = (100.0f * phi_f2) + 900.0f; - sTurtleGreatBayTempleColVertices[1].y = (100.0f * phi_f2) + 900.0f; - sTurtleGreatBayTempleColVertices[2].y = (500.0f * phi_f2) + -200.0f; - sTurtleGreatBayTempleColVertices[3].y = (900.0f * phi_f2) + -800.0f; - sTurtleGreatBayTempleColVertices[5].y = 0x4B0; - sTurtleGreatBayTempleColVertices[9].y = 0x6A4; + sTurtleGreatBayTempleColVerticesData[0].y = (100.0f * phi_f2) + 900.0f; + sTurtleGreatBayTempleColVerticesData[1].y = (100.0f * phi_f2) + 900.0f; + sTurtleGreatBayTempleColVerticesData[2].y = (500.0f * phi_f2) + -200.0f; + sTurtleGreatBayTempleColVerticesData[3].y = (900.0f * phi_f2) + -800.0f; + sTurtleGreatBayTempleColVerticesData[5].y = 0x4B0; + sTurtleGreatBayTempleColVerticesData[9].y = 0x6A4; } else { phi_f0 = this->skelAnime.curFrame + 26.0f; if (phi_f0 > 29.0f) { @@ -998,18 +1006,18 @@ void DmChar08_UpdateCollision(DmChar08* this, PlayState* play) { phi_f2 = (29.0f - phi_f0) / 10.0f; } - sTurtleGreatBayTempleCol.polyList = sTurtleGreatBayTempleColPolygons2; + sTurtleGreatBayTempleColData->polyList = sTurtleGreatBayTempleColPolygons2; - for (i = 0; i < ARRAY_COUNT(sTurtleGreatBayTempleColVertices); i++) { - sTurtleGreatBayTempleColVertices[i].x = -sTurtleGreatBayTempleColVertices2[i].x; + for (i = 0; i < ResourceMgr_GetArraySizeByName(sTurtleGreatBayTempleColVertices); i++) { + sTurtleGreatBayTempleColVerticesData[i].x = -sTurtleGreatBayTempleColVertices2Data[i].x; } - sTurtleGreatBayTempleColVertices[0].y = (500.0f * phi_f2) + 720.0f; - sTurtleGreatBayTempleColVertices[1].y = (660.0f * phi_f2) + 420.0f; - sTurtleGreatBayTempleColVertices[2].y = (1130.0f * phi_f2) + -430.0f; - sTurtleGreatBayTempleColVertices[3].y = (1430.0f * phi_f2) + -1060.0f; - sTurtleGreatBayTempleColVertices[5].y = 0x4B0; - sTurtleGreatBayTempleColVertices[9].y = 0x6A4; + sTurtleGreatBayTempleColVerticesData[0].y = (500.0f * phi_f2) + 720.0f; + sTurtleGreatBayTempleColVerticesData[1].y = (660.0f * phi_f2) + 420.0f; + sTurtleGreatBayTempleColVerticesData[2].y = (1130.0f * phi_f2) + -430.0f; + sTurtleGreatBayTempleColVerticesData[3].y = (1430.0f * phi_f2) + -1060.0f; + sTurtleGreatBayTempleColVerticesData[5].y = 0x4B0; + sTurtleGreatBayTempleColVerticesData[9].y = 0x6A4; } DynaPoly_InvalidateLookup(play, &play->colCtx.dyna); } diff --git a/mm/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c b/mm/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c index 23a2ede70..38aae35c6 100644 --- a/mm/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c +++ b/mm/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c @@ -11,6 +11,7 @@ #include "overlays/effects/ovl_Effect_Ss_Hahen/z_eff_ss_hahen.h" #include "objects/object_bigslime/object_bigslime.h" #include "objects/gameplay_keep/gameplay_keep.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_10 | ACTOR_FLAG_20 | ACTOR_FLAG_200) @@ -129,24 +130,15 @@ void EnBigslime_DrawShatteringEffects(EnBigslime* this, PlayState* play); */ // Reference data: used to store the original vertices -static Vtx sBigslimeStaticVtx[BIGSLIME_NUM_VTX] = { -#include "overlays/ovl_En_Bigslime/sBigslimeStaticVtx.vtx.inc" -}; +#include "overlays/ovl_En_Bigslime/ovl_En_Bigslime.h" + +static Vtx* sBigslimeStaticVtxData; // Dynamic data: used to draw the real shape and has 2 states -static Vtx sBigslimeDynamicVtx[2][BIGSLIME_NUM_VTX] = { - { -#include "overlays/ovl_En_Bigslime/sBigslimeDynamicState0Vtx.vtx.inc" - }, - { -#include "overlays/ovl_En_Bigslime/sBigslimeDynamicState1Vtx.vtx.inc" - }, -}; +static Vtx* sBigslimeDynamicVtxData[2]; // Target data: used to define the shape the dynamic vertices morph to -static Vtx sBigslimeTargetVtx[BIGSLIME_NUM_VTX] = { -#include "overlays/ovl_En_Bigslime/sBigslimeTargetVtx.vtx.inc" -}; +static Vtx* sBigslimeTargetVtxData; /* * Triangle face @@ -213,15 +205,15 @@ static EnBigslimeTri sBigslimeTri[BIGSLIME_NUM_FACES] = { }; ActorInit En_Bigslime_InitVars = { - /**/ ACTOR_EN_BIGSLIME, - /**/ ACTORCAT_BOSS, - /**/ FLAGS, - /**/ OBJECT_BIGSLIME, - /**/ sizeof(EnBigslime), - /**/ EnBigslime_Init, - /**/ EnBigslime_Destroy, - /**/ EnBigslime_UpdateGekko, - /**/ EnBigslime_DrawGekko, + ACTOR_EN_BIGSLIME, + ACTORCAT_BOSS, + FLAGS, + OBJECT_BIGSLIME, + sizeof(EnBigslime), + (ActorFunc)EnBigslime_Init, + (ActorFunc)EnBigslime_Destroy, + (ActorFunc)EnBigslime_UpdateGekko, + (ActorFunc)EnBigslime_DrawGekko, }; static ColliderCylinderInit sCylinderInit = { @@ -322,6 +314,11 @@ void EnBigslime_Init(Actor* thisx, PlayState* play2) { EnBigslime* this = THIS; s32 i; + sBigslimeStaticVtxData = ResourceMgr_LoadVtxByName(sBigslimeStaticVtxData); + sBigslimeDynamicVtxData[0] = ResourceMgr_LoadVtxByName(sBigslimeDynamicState0Vtx); + sBigslimeDynamicVtxData[1] = ResourceMgr_LoadVtxByName(sBigslimeDynamicState1Vtx); + sBigslimeTargetVtxData = ResourceMgr_LoadVtxByName(sBigslimeTargetVtx); + Actor_ProcessInitChain(&this->actor, sInitChain); CollisionCheck_SetInfo(&this->actor.colChkInfo, &sDamageTable, &sColChkInfoInit); SkelAnime_InitFlex(play, &this->skelAnime, &gGekkoSkel, &gGekkoLookAroundAnim, this->jointTable, this->morphTable, @@ -399,8 +396,8 @@ void EnBigslime_DynamicVtxCopyState(EnBigslime* this) { s32 j; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtxDest = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - dynamicVtxSrc = &sBigslimeDynamicVtx[this->dynamicVtxState ^ 1][i]; + dynamicVtxDest = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + dynamicVtxSrc = &sBigslimeDynamicVtxData[this->dynamicVtxState ^ 1][i]; for (j = 0; j < 3; j++) { dynamicVtxDest->n.ob[j] = dynamicVtxSrc->n.ob[j]; dynamicVtxDest->n.n[j] = dynamicVtxSrc->n.n[j]; @@ -436,13 +433,13 @@ void EnBigslime_UpdateSurfaceNorm(EnBigslime* this) { } for (i = 0; i < BIGSLIME_NUM_FACES; i++) { - dynamicVtx0 = &sBigslimeDynamicVtx[this->dynamicVtxState][sBigslimeTri[i].v[0]]; - dynamicVtx12 = &sBigslimeDynamicVtx[this->dynamicVtxState][sBigslimeTri[i].v[1]]; + dynamicVtx0 = &sBigslimeDynamicVtxData[this->dynamicVtxState][sBigslimeTri[i].v[0]]; + dynamicVtx12 = &sBigslimeDynamicVtxData[this->dynamicVtxState][sBigslimeTri[i].v[1]]; vecTriEdge1.x = dynamicVtx12->n.ob[0] - dynamicVtx0->n.ob[0]; vecTriEdge1.y = dynamicVtx12->n.ob[1] - dynamicVtx0->n.ob[1]; vecTriEdge1.z = dynamicVtx12->n.ob[2] - dynamicVtx0->n.ob[2]; - dynamicVtx12 = &sBigslimeDynamicVtx[this->dynamicVtxState][sBigslimeTri[i].v[2]]; + dynamicVtx12 = &sBigslimeDynamicVtxData[this->dynamicVtxState][sBigslimeTri[i].v[2]]; vecTriEdge2.x = dynamicVtx12->n.ob[0] - dynamicVtx0->n.ob[0]; vecTriEdge2.y = dynamicVtx12->n.ob[1] - dynamicVtx0->n.ob[1]; vecTriEdge2.z = dynamicVtx12->n.ob[2] - dynamicVtx0->n.ob[2]; @@ -458,7 +455,7 @@ void EnBigslime_UpdateSurfaceNorm(EnBigslime* this) { for (i = 0; i < BIGSLIME_NUM_VTX; i++) { vtxNormAddr = &vtxNorm[i]; EnBigslime_Vec3fNormalize(vtxNormAddr); - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; dynamicVtx->n.n[0] = vtxNormAddr->x * 120.0f; dynamicVtx->n.n[1] = vtxNormAddr->y * 120.0f; dynamicVtx->n.n[2] = vtxNormAddr->z * 120.0f; @@ -476,7 +473,7 @@ void EnBigslime_GetMaxMinVertices(EnBigslime* this, Vec3f* vtxMax, Vec3f* vtxMin s32 i; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; if (vtxMaxX < dynamicVtx->n.ob[0]) { vtxMaxX = dynamicVtx->n.ob[0]; @@ -600,7 +597,7 @@ void EnBigslime_UpdateBigslimeCollider(EnBigslime* this, PlayState* play) { vtxRingMaxXZDist[i] = 0.0f; for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][j]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][j]; if (vtxRingMaxY[i] < dynamicVtx->n.ob[1]) { vtxRingMaxY[i] = dynamicVtx->n.ob[1]; } @@ -676,8 +673,8 @@ void EnBigslime_UpdateWavySurface(EnBigslime* this) { this->wavySurfaceTimer--; vtxSurfaceWave = Math_SinF(this->wavySurfaceTimer * (M_PI / 12)); for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - staticVtx = &sBigslimeStaticVtx[i]; - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + staticVtx = &sBigslimeStaticVtxData[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; for (j = 0; j < 3; j++) { // Formula: dynamicVtx = staticVtx * (1 + sin * perturbation) dynamicVtx->n.ob[j] = @@ -714,7 +711,7 @@ void EnBigslime_SetMinislimeBreakLocation(EnBigslime* this) { this->minislimeState = MINISLIME_ACTIVE_CONTINUE_STATE; for (i = 0; i < MINISLIME_NUM_SPAWN; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][minislimeSpawnVtx[i]]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][minislimeSpawnVtx[i]]; minislime = this->minislime[i]; minislime->actor.params = MINISLIME_BREAK_BIGSLIME; minislime->actor.world.pos.x = (dynamicVtx->n.ob[0] * this->actor.scale.x) + this->actor.world.pos.x; @@ -1015,6 +1012,7 @@ void EnBigslime_CallMinislime(EnBigslime* this, PlayState* play) { } } + void EnBigslime_SetupMoveOnCeiling(EnBigslime* this) { Animation_PlayLoop(&this->skelAnime, &gGekkoSwimForwardAnim); this->actor.gravity = 0.0f; @@ -1091,8 +1089,8 @@ void EnBigslime_Drop(EnBigslime* this, PlayState* play) { Math_StepToF(&this->actor.scale.y, 0.080000006f, 0.0025f); Math_StepToF(&this->actor.scale.z, 0.15f, 0.0025f); for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - staticVtx = &sBigslimeStaticVtx[i]; - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + staticVtx = &sBigslimeStaticVtxData[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; if (i > 145) { Math_StepToS(&dynamicVtx->n.ob[1], staticVtx->n.ob[1] * 0.9f, 5); } else if (i < 16) { @@ -1124,7 +1122,7 @@ void EnBigslime_CheckVtxWallBoundaries(EnBigslime* this) { s16 updateVtxY; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; vtxX = dynamicVtx->n.ob[0] * this->actor.scale.x; vtxZ = dynamicVtx->n.ob[2] * this->actor.scale.z; collisionCounter = 0; @@ -1172,8 +1170,8 @@ void EnBigslime_SetTargetVtxToWideCone(EnBigslime* this) { for (i = 0; i < BIGSLIME_NUM_RING_FACES / 2; i++) { vtxY = (((Math_CosF(i * (M_PI / 6)) + 1.0f) * 0.925f) + -0.85f) * BIGSLIME_RADIUS_F; for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; xzDist = sqrtf(SQ(staticVtx->n.ob[0]) + SQ(staticVtx->n.ob[2])); if (xzDist > 1.0f) { @@ -1191,8 +1189,8 @@ void EnBigslime_SetTargetVtxToWideCone(EnBigslime* this) { for (; i < BIGSLIME_NUM_RING_VTX; i++) { vtxY = ((Math_CosF((i - BIGSLIME_NUM_RING_FACES / 2) * (M_PI / 16)) * 0.05f) + -1.0f) * BIGSLIME_RADIUS_F; for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; xzDist = sqrtf(SQ(staticVtx->n.ob[0]) + SQ(staticVtx->n.ob[2])); if (xzDist > 1.0f) { xzScaleVtx = (BIGSLIME_RADIUS_F / (8.0f * xzDist)) * (14 - i); @@ -1208,9 +1206,9 @@ void EnBigslime_SetTargetVtxToWideCone(EnBigslime* this) { } // Bottom vtx of the sphere - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; } void EnBigslime_SetupSquishFlat(EnBigslime* this) { @@ -1246,8 +1244,8 @@ void EnBigslime_SquishFlat(EnBigslime* this, PlayState* play) { this->actor.scale.z = this->actor.scale.x; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - targetVtx = &sBigslimeTargetVtx[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; Math_SmoothStepToS(&dynamicVtx->n.ob[0], targetVtx->n.ob[0], 5, 40, 5); Math_SmoothStepToS(&dynamicVtx->n.ob[2], targetVtx->n.ob[2], 5, 40, 5); Math_SmoothStepToS(&dynamicVtx->n.ob[1], targetVtx->n.ob[1], 2, 600, 3); @@ -1297,15 +1295,15 @@ void EnBigslime_SetTargetVtxToThinCone(EnBigslime* this) { s32 targetVtxY; // Top vtx of the sphere - sBigslimeTargetVtx[0].n.ob[1] = BIGSLIME_RADIUS_S; - sBigslimeTargetVtx[0].n.ob[0] = 0; - sBigslimeTargetVtx[0].n.ob[2] = 0; + sBigslimeTargetVtxData[0].n.ob[1] = BIGSLIME_RADIUS_S; + sBigslimeTargetVtxData[0].n.ob[0] = 0; + sBigslimeTargetVtxData[0].n.ob[2] = 0; for (i = 1; i < BIGSLIME_NUM_RING_FACES / 2; i++) { upperSphereCos = (((Math_CosF((i - 1) * (M_PI / 5)) + 1.0f) * 0.925f) + -0.85f) * BIGSLIME_RADIUS_F; for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; xzDistVtx = sqrtf(SQ(staticVtx->n.ob[0]) + SQ(staticVtx->n.ob[2])); xzDistVtx = (BIGSLIME_RADIUS_F / (5.0f * xzDistVtx)) * i; // xzDistVtx is always less than 500.0f @@ -1321,8 +1319,8 @@ void EnBigslime_SetTargetVtxToThinCone(EnBigslime* this) { for (; i < BIGSLIME_NUM_RING_FACES; i++) { lowerSphereCos = Math_CosF((i - BIGSLIME_NUM_RING_FACES / 2) * (M_PI / BIGSLIME_NUM_RING_FACES)); for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; targetVtx->n.ob[0] = staticVtx->n.ob[0]; targetVtx->n.ob[2] = staticVtx->n.ob[2]; targetVtxY = (s16)(((lowerSphereCos * 0.05f) + -1.0f) * BIGSLIME_RADIUS_F); @@ -1331,9 +1329,9 @@ void EnBigslime_SetTargetVtxToThinCone(EnBigslime* this) { } // Bottom vtx of the sphere - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; } /** @@ -1357,15 +1355,15 @@ void EnBigslime_SetTargetVtxToInverseCone(EnBigslime* this) { s32 vtxY; // Top vtx of the sphere - sBigslimeTargetVtx[0].n.ob[1] = BIGSLIME_RADIUS_S; - sBigslimeTargetVtx[0].n.ob[0] = 0; - sBigslimeTargetVtx[0].n.ob[2] = 0; + sBigslimeTargetVtxData[0].n.ob[1] = BIGSLIME_RADIUS_S; + sBigslimeTargetVtxData[0].n.ob[0] = 0; + sBigslimeTargetVtxData[0].n.ob[2] = 0; for (i = 1; i < BIGSLIME_NUM_RING_FACES / 2; i++) { upperSphereCos = Math_CosF((i - 1) * (M_PI / 10)); for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; targetVtx->n.ob[0] = staticVtx->n.ob[0]; targetVtx->n.ob[2] = staticVtx->n.ob[2]; vtxY = (s16)(((upperSphereCos * 0.1f) + 0.9f) * BIGSLIME_RADIUS_F); @@ -1377,8 +1375,8 @@ void EnBigslime_SetTargetVtxToInverseCone(EnBigslime* this) { lowerSphereCos = (((Math_CosF((i - BIGSLIME_NUM_RING_FACES / 2) * (M_PI / 5)) + 1) * 0.925f) + -1.0f) * BIGSLIME_RADIUS_F; for (j = sVtxRingStartIndex[i]; j < sVtxRingStartIndex[i + 1]; j++) { - staticVtx = &sBigslimeStaticVtx[j]; - targetVtx = &sBigslimeTargetVtx[j]; + staticVtx = &sBigslimeStaticVtxData[j]; + targetVtx = &sBigslimeTargetVtxData[j]; xzDistVtx = sqrtf(SQ(staticVtx->n.ob[0]) + SQ(staticVtx->n.ob[2])); xzDistVtx = (BIGSLIME_RADIUS_F / (6.0f * xzDistVtx)) * (BIGSLIME_NUM_RING_FACES - i); // xzDistVtx is always less than 500.0f @@ -1392,9 +1390,9 @@ void EnBigslime_SetTargetVtxToInverseCone(EnBigslime* this) { } // Bottom vtx of the sphere - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; - sBigslimeTargetVtx[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[1] = -BIGSLIME_RADIUS_S; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[0] = 0; + sBigslimeTargetVtxData[BIGSLIME_NUM_VTX - 1].n.ob[2] = 0; } void EnBigslime_SetTargetVtxToStaticVtx(EnBigslime* this) { @@ -1402,10 +1400,10 @@ void EnBigslime_SetTargetVtxToStaticVtx(EnBigslime* this) { Vtx* staticVtx; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - staticVtx = &sBigslimeStaticVtx[i]; - sBigslimeTargetVtx[i].n.ob[0] = staticVtx->n.ob[0]; - sBigslimeTargetVtx[i].n.ob[2] = staticVtx->n.ob[2]; - sBigslimeTargetVtx[i].n.ob[1] = staticVtx->n.ob[1]; + staticVtx = &sBigslimeStaticVtxData[i]; + sBigslimeTargetVtxData[i].n.ob[0] = staticVtx->n.ob[0]; + sBigslimeTargetVtxData[i].n.ob[2] = staticVtx->n.ob[2]; + sBigslimeTargetVtxData[i].n.ob[1] = staticVtx->n.ob[1]; } } @@ -1454,8 +1452,8 @@ void EnBigslime_Rise(EnBigslime* this, PlayState* play) { } for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - targetVtx = &sBigslimeTargetVtx[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; Math_SmoothStepToS(&dynamicVtx->n.ob[1], targetVtx->n.ob[1], 5, 550, 3); Math_SmoothStepToS(&dynamicVtx->n.ob[0], targetVtx->n.ob[0], 5, 40, 5); Math_SmoothStepToS(&dynamicVtx->n.ob[2], targetVtx->n.ob[2], 5, 40, 5); @@ -1468,8 +1466,8 @@ void EnBigslime_Rise(EnBigslime* this, PlayState* play) { } for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - targetVtx = &sBigslimeTargetVtx[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; Math_SmoothStepToS(&dynamicVtx->n.ob[1], targetVtx->n.ob[1], 5, 50, 3); Math_SmoothStepToS(&dynamicVtx->n.ob[0], targetVtx->n.ob[0], 5, 40, 5); Math_SmoothStepToS(&dynamicVtx->n.ob[2], targetVtx->n.ob[2], 5, 40, 5); @@ -1481,8 +1479,8 @@ void EnBigslime_Rise(EnBigslime* this, PlayState* play) { } else { this->riseCounter++; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - targetVtx = &sBigslimeTargetVtx[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; Math_SmoothStepToS(&dynamicVtx->n.ob[1], targetVtx->n.ob[1], 5, 550, 3); Math_SmoothStepToS(&dynamicVtx->n.ob[0], targetVtx->n.ob[0], 5, 40, 5); Math_SmoothStepToS(&dynamicVtx->n.ob[2], targetVtx->n.ob[2], 5, 40, 5); @@ -1544,13 +1542,13 @@ void EnBigslime_CutsceneGrabPlayer(EnBigslime* this, PlayState* play) { player->actor.world.pos.y, this->actor.world.pos.y + this->actor.scale.y * -500.0f, invgrabPlayerTimer); for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; // loop over x, y, z for (j = 0; j < 3; j++) { // Linearly interpolate dynamicVtx --> staticVtx dynamicVtx->n.ob[j] += - (s16)((sBigslimeStaticVtx[i].n.ob[j] - dynamicVtx->n.ob[j]) * invgrabPlayerTimer); + (s16)((sBigslimeStaticVtxData[i].n.ob[j] - dynamicVtx->n.ob[j]) * invgrabPlayerTimer); } } @@ -1662,7 +1660,7 @@ void EnBigslime_SetupWindupThrowPlayer(EnBigslime* this) { s32 i; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; // vector dot product between each dynamicVtx and the unit normal vector describing player's thrown direction dotXYZ = (dynamicVtx->n.ob[0] * unitVecX + dynamicVtx->n.ob[1] * M_SQRT1_2 + dynamicVtx->n.ob[2] * unitVecZ) * @@ -1734,7 +1732,7 @@ void EnBigslime_WindupThrowPlayer(EnBigslime* this, PlayState* play) { // Deforming Bigslime during the final windup punch while grabbing player using vtxSurfacePerturbation for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; staticVtx = &sBigslimeStaticVtx[i]; if (this->vtxSurfacePerturbation[i] != 0.0f) { if (this->windupPunchTimer > 0) { @@ -1766,6 +1764,7 @@ void EnBigslime_WindupThrowPlayer(EnBigslime* this, PlayState* play) { } } + void EnBigslime_SetupSetDynamicVtxThrowPlayer(EnBigslime* this, PlayState* play) { this->grabPlayerTimer = 10; EnBigslime_SetTargetVtxToWideCone(this); @@ -1788,8 +1787,8 @@ void EnBigslime_SetDynamicVtxThrowPlayer(EnBigslime* this, PlayState* play) { if (this->throwPlayerTimer > 0) { invThrowPlayerTimer = 1.0f / this->throwPlayerTimer; for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - targetVtx = &sBigslimeTargetVtx[i]; - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; // loop over x, y, z for (j = 0; j < 3; j++) { @@ -1833,8 +1832,8 @@ void EnBigslime_SetupFreeze(EnBigslime* this) { // Resets frozen effect alpha to 0 for (i = 0; i < BIGSLIME_NUM_VTX; i++) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][i]; - targetVtx = &sBigslimeTargetVtx[i]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][i]; + targetVtx = &sBigslimeTargetVtxData[i]; for (j = 0; j < 3; j++) { targetVtx->n.ob[j] = dynamicVtx->n.ob[j]; } @@ -1843,12 +1842,12 @@ void EnBigslime_SetupFreeze(EnBigslime* this) { // Initalizes frozen effect alpha near bottom of sphere by increasing levels of alpha for (i = 0; i < 20; i++) { - sBigslimeTargetVtx[i + 138].n.a = 10 * i; + sBigslimeTargetVtxData[i + 138].n.a = 10 * i; } // Initalizes/seeds frozen effect alpha in bottom 4 nodes in vtx sphere to highest level of alpha for (i = 0; i < 4; i++) { - sBigslimeTargetVtx[i + 158].n.a = 200; + sBigslimeTargetVtxData[i + 158].n.a = 200; } for (i = 0; i < BIGSLIME_NUM_RING_FACES; i++) { @@ -1878,8 +1877,8 @@ void EnBigslime_Freeze(EnBigslime* this, PlayState* play) { vtxIceSeed = this->freezeTimer * 4; for (vtxIceUpdate = 0; vtxIceUpdate < 4; vtxIceUpdate++, vtxIceSeed++) { if (vtxIceSeed < BIGSLIME_NUM_VTX) { - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][vtxIceSeed]; - targetVtx = &sBigslimeTargetVtx[vtxIceSeed]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][vtxIceSeed]; + targetVtx = &sBigslimeTargetVtxData[vtxIceSeed]; randFloat = Rand_CenteredFloat(40.0f); dynamicVtx->n.ob[0] += (s16)(randFloat / this->actor.scale.x); dynamicVtx->n.ob[1] += (s16)(randFloat / this->actor.scale.y); @@ -1895,7 +1894,7 @@ void EnBigslime_Freeze(EnBigslime* this, PlayState* play) { } for (vtxIceUpdate = 4; vtxIceUpdate < BIGSLIME_NUM_VTX; vtxIceUpdate++) { - sBigslimeTargetVtx[vtxIceUpdate - 4].n.a = sBigslimeTargetVtx[vtxIceUpdate].n.a; + sBigslimeTargetVtxData[vtxIceUpdate - 4].n.a = sBigslimeTargetVtxData[vtxIceUpdate].n.a; } Actor_PlaySfx_Flagged(&this->actor, NA_SE_EV_ICE_FREEZE - SFX_FLAG); @@ -1953,11 +1952,11 @@ void EnBigslime_SetupMelt(EnBigslime* this) { this->bigslimeCollider[0].base.acFlags &= ~AC_ON; for (i = 0; i < 2; i++) { - sBigslimeTargetVtx[i].n.a = 0; + sBigslimeTargetVtxData[i].n.a = 0; } for (i = 0; i < 20; i++) { - sBigslimeTargetVtx[i + 2].n.a = 10 * i; + sBigslimeTargetVtxData[i + 2].n.a = 10 * i; } this->meltCounter = 0; @@ -1974,7 +1973,7 @@ void EnBigslime_Melt(EnBigslime* this, PlayState* play) { this->meltCounter++; if ((this->meltCounter < 70) && ((this->meltCounter % 2) != 0)) { dynamicVtx = - &sBigslimeDynamicVtx[this->dynamicVtxState][(s32)Rand_ZeroFloat(BIGSLIME_NUM_VTX) % BIGSLIME_NUM_VTX]; + &sBigslimeDynamicVtxData[this->dynamicVtxState][(s32)Rand_ZeroFloat(BIGSLIME_NUM_VTX) % BIGSLIME_NUM_VTX]; iceSmokePos.x = (dynamicVtx->n.ob[0] * this->actor.scale.x) + this->actor.world.pos.x; iceSmokePos.y = (dynamicVtx->n.ob[1] * this->actor.scale.y) + this->actor.world.pos.y; iceSmokePos.z = (dynamicVtx->n.ob[2] * this->actor.scale.z) + this->actor.world.pos.z; @@ -1983,7 +1982,7 @@ void EnBigslime_Melt(EnBigslime* this, PlayState* play) { Actor_PlaySfx_Flagged(&this->actor, NA_SE_EV_ICE_MELT_LEVEL - SFX_FLAG); for (i = 159; i >= 0; i--) { - sBigslimeTargetVtx[i + 2].n.a = sBigslimeTargetVtx[i].n.a; + sBigslimeTargetVtxData[i + 2].n.a = sBigslimeTargetVtxData[i].n.a; } if (this->meltCounter == 100) { @@ -2321,9 +2320,10 @@ void EnBigslime_SetupCutsceneDefeat(EnBigslime* this, PlayState* play) { Vec3f subCamAt; s32 i; s16 yawOffset; + AnimationHeader* anim = ResourceMgr_LoadAnimByName(gGekkoDamagedAnim); - Animation_Change(&this->skelAnime, &gGekkoDamagedAnim, 0.5f, 0.0f, - Animation_GetLastFrame(&gGekkoDamagedAnim.common), ANIMMODE_ONCE_INTERP, 0.0f); + Animation_Change(&this->skelAnime, anim, 0.5f, 0.0f, Animation_GetLastFrame(&anim->common), ANIMMODE_ONCE_INTERP, + 0.0f); this->gekkoCollider.base.acFlags &= ~AC_ON; this->defeatTimer = 60; this->actor.speed = 10.0f; @@ -2688,7 +2688,7 @@ void EnBigslime_ApplyDamageEffectGekko(EnBigslime* this, PlayState* play) { * Adds ice shard effects and calls EnBigslime_InitShockwave */ void EnBigslime_AddIceShardEffect(EnBigslime* this, PlayState* play) { - Vtx* targetVtx = &sBigslimeTargetVtx[0]; + Vtx* targetVtx = &sBigslimeTargetVtxData[0]; EnBigslimeIceShardEffect* iceShardEffect; s32 i; f32 randFloat; @@ -2992,7 +2992,7 @@ void EnBigslime_DrawBigslime(Actor* thisx, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); // Draw Bigslime - gSPSegment(POLY_XLU_DISP++, 0x09, sBigslimeDynamicVtx[this->dynamicVtxState]); + gSPSegment(POLY_XLU_DISP++, 0x09, sBigslimeDynamicVtxData[this->dynamicVtxState]); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(POLY_XLU_DISP++, gBigslimeNormalMaterialDL); gSPDisplayList(POLY_XLU_DISP++, gBigslimeModelDL); @@ -3001,7 +3001,7 @@ void EnBigslime_DrawBigslime(Actor* thisx, PlayState* play) { if ((this->actionFunc == EnBigslime_Freeze) || (this->actionFunc == EnBigslime_FrozenGround) || (this->actionFunc == EnBigslime_FrozenFall) || (this->actionFunc == EnBigslime_Melt)) { AnimatedMat_Draw(play, this->bigslimeFrozenTexAnim); - gSPSegment(POLY_XLU_DISP++, 0x09, sBigslimeTargetVtx); + gSPSegment(POLY_XLU_DISP++, 0x09, sBigslimeTargetVtxData); gSPDisplayList(POLY_XLU_DISP++, gBigslimeFrozenMaterialDL); gSPDisplayList(POLY_XLU_DISP++, gBigslimeModelDL); } @@ -3014,7 +3014,7 @@ void EnBigslime_DrawBigslime(Actor* thisx, PlayState* play) { for (i = 0; i < 28; i++) { bubblesInfoPtr = &bubblesInfo[i]; - dynamicVtx = &sBigslimeDynamicVtx[this->dynamicVtxState][bubblesInfoPtr->v]; + dynamicVtx = &sBigslimeDynamicVtxData[this->dynamicVtxState][bubblesInfoPtr->v]; billboardMtxF->xw = dynamicVtx->n.ob[0] * this->actor.scale.x * bubblesInfoPtr->scaleVtx + this->actor.world.pos.x; billboardMtxF->yw = diff --git a/mm/src/overlays/actors/ovl_En_Bom/z_en_bom.c b/mm/src/overlays/actors/ovl_En_Bom/z_en_bom.c index aa67e2e6a..3da93d361 100644 --- a/mm/src/overlays/actors/ovl_En_Bom/z_en_bom.c +++ b/mm/src/overlays/actors/ovl_En_Bom/z_en_bom.c @@ -611,7 +611,7 @@ static Vec3f D_80872EEC = { -750.0f, 0.0f, 0.0f }; static Vec3f D_80872EF8 = { -800.0f, 0.0f, 0.0f }; static Vec3f D_80872F04 = { 0.0f, 0.0f, 0.0f }; -#include "overlays/ovl_En_Bom/ovl_En_Bom.c" +#include "overlays/ovl_En_Bom/ovl_En_Bom.h" void EnBom_Draw(Actor* thisx, PlayState* play) { s32 pad; diff --git a/mm/src/overlays/actors/ovl_En_Bom_Bowl_Man/z_en_bom_bowl_man.c b/mm/src/overlays/actors/ovl_En_Bom_Bowl_Man/z_en_bom_bowl_man.c index c31a28966..9385a8f54 100644 --- a/mm/src/overlays/actors/ovl_En_Bom_Bowl_Man/z_en_bom_bowl_man.c +++ b/mm/src/overlays/actors/ovl_En_Bom_Bowl_Man/z_en_bom_bowl_man.c @@ -718,7 +718,7 @@ s32 EnBomBowlMan_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, V return false; } -#include "overlays/ovl_En_Bom_Bowl_Man/ovl_En_Bom_Bowl_Man.c" +#include "overlays/ovl_En_Bom_Bowl_Man/ovl_En_Bom_Bowl_Man.h" TexturePtr D_809C6200[] = { gEnBomBowlMan_D_809C61E0, gEnBomBowlMan_D_809C61F0, gEnBomBowlMan_D_809C61F0, diff --git a/mm/src/overlays/actors/ovl_En_Bombers/z_en_bombers.c b/mm/src/overlays/actors/ovl_En_Bombers/z_en_bombers.c index db6cb78e7..a67886832 100644 --- a/mm/src/overlays/actors/ovl_En_Bombers/z_en_bombers.c +++ b/mm/src/overlays/actors/ovl_En_Bombers/z_en_bombers.c @@ -118,7 +118,7 @@ static u8 sAnimationModes[ENBOMBERS_ANIM_MAX] = { ANIMMODE_LOOP, // ENBOMBERS_ANIM_16 }; -#include "overlays/ovl_En_Bombers/ovl_En_Bombers.c" +#include "overlays/ovl_En_Bombers/ovl_En_Bombers.h" Gfx* D_80C04818[] = { ovl_En_Bombers_DL_12C8, ovl_En_Bombers_DL_12D8, ovl_En_Bombers_DL_12D8, diff --git a/mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.c b/mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.c index 4771d116b..4976e7822 100644 --- a/mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.c +++ b/mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.c @@ -1144,7 +1144,7 @@ s32 EnBomjima_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3 return false; } -#include "overlays/ovl_En_Bomjima/ovl_En_Bomjima.c" +#include "overlays/ovl_En_Bomjima/ovl_En_Bomjima.h" void EnBomjima_Draw(Actor* thisx, PlayState* play) { static Gfx* D_80C00B28[] = { diff --git a/mm/src/overlays/actors/ovl_En_Bomjimb/z_en_bomjimb.c b/mm/src/overlays/actors/ovl_En_Bomjimb/z_en_bomjimb.c index 124ec7988..6c18f22fc 100644 --- a/mm/src/overlays/actors/ovl_En_Bomjimb/z_en_bomjimb.c +++ b/mm/src/overlays/actors/ovl_En_Bomjimb/z_en_bomjimb.c @@ -962,7 +962,7 @@ s32 EnBomjimb_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3 return false; } -#include "overlays/ovl_En_Bomjimb/ovl_En_Bomjimb.c" +#include "overlays/ovl_En_Bomjimb/ovl_En_Bomjimb.h" void EnBomjimb_Draw(Actor* thisx, PlayState* play) { static Gfx* D_80C03260[] = { diff --git a/mm/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c b/mm/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c index 226dc567b..3e14099ce 100644 --- a/mm/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c +++ b/mm/src/overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.c @@ -108,7 +108,7 @@ static TexturePtr sWaterSplashTextures[] = { NULL, }; -#include "overlays/ovl_En_Clear_Tag/ovl_En_Clear_Tag.c" +#include "overlays/ovl_En_Clear_Tag/ovl_En_Clear_Tag.h" /** * Creates a debris effect. diff --git a/mm/src/overlays/actors/ovl_En_Dg/z_en_dg.c b/mm/src/overlays/actors/ovl_En_Dg/z_en_dg.c index bdcc4b7d2..82cf4fc3f 100644 --- a/mm/src/overlays/actors/ovl_En_Dg/z_en_dg.c +++ b/mm/src/overlays/actors/ovl_En_Dg/z_en_dg.c @@ -483,7 +483,9 @@ void EnDg_TryPickUp(EnDg* this, PlayState* play) { if (Actor_HasParent(&this->actor, play)) { Actor_PlaySfx(&this->actor, NA_SE_EV_SMALL_DOG_BARK); this->grabState = DOG_GRAB_STATE_HELD; - sSelectedRacetrackDogInfo = sRacetrackDogInfo[this->index]; + if (this->index < RACEDOG_COUNT) { + sSelectedRacetrackDogInfo = sRacetrackDogInfo[this->index]; + } if (!sIsAnyDogHeld) { this->actor.flags |= ACTOR_FLAG_CANT_LOCK_ON; sIsAnyDogHeld = true; @@ -1391,34 +1393,38 @@ void EnDg_Draw(Actor* thisx, PlayState* play) { gDPPipeSync(POLY_OPA_DISP++); - switch (sRacetrackDogInfo[this->index].color) { - case DOG_COLOR_BEIGE: - gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 200, 0); - break; + if (this->index < RACEDOG_COUNT) { + switch (sRacetrackDogInfo[this->index].color) { + case DOG_COLOR_BEIGE: + gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 200, 0); + break; - case DOG_COLOR_WHITE: - gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 255, 0); - break; + case DOG_COLOR_WHITE: + gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 255, 0); + break; - case DOG_COLOR_BLUE: - gDPSetEnvColor(POLY_OPA_DISP++, 79, 79, 143, 0); - break; + case DOG_COLOR_BLUE: + gDPSetEnvColor(POLY_OPA_DISP++, 79, 79, 143, 0); + break; - case DOG_COLOR_GOLD: - gDPSetEnvColor(POLY_OPA_DISP++, 255, 207, 47, 0); - break; + case DOG_COLOR_GOLD: + gDPSetEnvColor(POLY_OPA_DISP++, 255, 207, 47, 0); + break; - case DOG_COLOR_BROWN: - gDPSetEnvColor(POLY_OPA_DISP++, 143, 79, 47, 0); - break; + case DOG_COLOR_BROWN: + gDPSetEnvColor(POLY_OPA_DISP++, 143, 79, 47, 0); + break; - case DOG_COLOR_GRAY: - gDPSetEnvColor(POLY_OPA_DISP++, 143, 143, 143, 0); - break; + case DOG_COLOR_GRAY: + gDPSetEnvColor(POLY_OPA_DISP++, 143, 143, 143, 0); + break; - default: - gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 200, 0); - break; + default: + gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 200, 0); + break; + } + } else { + gDPSetEnvColor(POLY_OPA_DISP++, 255, 255, 200, 0); } Matrix_Translate(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); diff --git a/mm/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c b/mm/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c index e03ee1999..bf4167335 100644 --- a/mm/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c +++ b/mm/src/overlays/actors/ovl_En_Dnk/z_en_dnk.c @@ -223,7 +223,7 @@ void func_80A51648(EnDnk* this, PlayState* play) { break; case ENDNK_GET_3_1: - SkelAnime_Init(play, &this->skelAnime, &object_hintnuts_Skel_0023B8.sh, NULL, this->jointTable, + SkelAnime_Init(play, &this->skelAnime, &object_hintnuts_Skel_0023B8, NULL, this->jointTable, this->morphTable, OBJECT_HINTNUTS_LIMB_MAX); EnDnk_ChangeAnim(&this->skelAnime, ENDNK_ANIM_18); break; diff --git a/mm/src/overlays/actors/ovl_En_Elf/z_en_elf.c b/mm/src/overlays/actors/ovl_En_Elf/z_en_elf.c index da222569f..29fe98f50 100644 --- a/mm/src/overlays/actors/ovl_En_Elf/z_en_elf.c +++ b/mm/src/overlays/actors/ovl_En_Elf/z_en_elf.c @@ -322,7 +322,7 @@ void EnElf_Init(Actor* thisx, PlayState* play2) { s32 fairyType; Actor_ProcessInitChain(thisx, sInitChain); - SkelAnime_Init(play, &this->skelAnime, &gameplay_keep_Skel_02AF58.sh, &gameplay_keep_Anim_029140, this->jointTable, + SkelAnime_Init(play, &this->skelAnime, &gameplay_keep_Skel_02AF58, &gameplay_keep_Anim_029140, this->jointTable, this->morphTable, FAIRY_LIMB_MAX); ActorShape_Init(&thisx->shape, 0.0f, NULL, 15.0f); thisx->shape.shadowAlpha = 255; diff --git a/mm/src/overlays/actors/ovl_En_Gakufu/z_en_gakufu.c b/mm/src/overlays/actors/ovl_En_Gakufu/z_en_gakufu.c index 1b5890e8e..af3069c51 100644 --- a/mm/src/overlays/actors/ovl_En_Gakufu/z_en_gakufu.c +++ b/mm/src/overlays/actors/ovl_En_Gakufu/z_en_gakufu.c @@ -96,7 +96,7 @@ TexturePtr sOcarinaBtnWallTextures[] = { gOcarinaATex, gOcarinaCDownTex, gOcarinaCRightTex, gOcarinaCLeftTex, gOcarinaCUpTex, }; -#include "overlays/ovl_En_Gakufu/ovl_En_Gakufu.c" +#include "overlays/ovl_En_Gakufu/ovl_En_Gakufu.h" void EnGakufu_ProcessNotes(EnGakufu* this) { OcarinaStaff* playbackStaff; diff --git a/mm/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c b/mm/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c index 4eb6a72e3..2abb6784e 100644 --- a/mm/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c +++ b/mm/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c @@ -90,17 +90,15 @@ static Gfx* D_80942E0C[][3] = { static Color_RGBA8 D_80942E30[] = { { 190, 195, 200, 255 }, { 170, 130, 90, 255 }, + { 250, 250, 250, 255 }, }; -static Color_RGBA8 D_80942E38 = { 250, 250, 250, 255 }; - static Color_RGBA8 D_80942E3C[] = { { 130, 135, 140, 255 }, { 100, 60, 20, 255 }, + { 180, 180, 180, 255 }, }; -static Color_RGBA8 D_80942E44 = { 180, 180, 180, 255 }; - static Vec3f D_80942E48 = { 0.0f, 0.0f, 0.0f }; static Vec3f D_80942E54 = { 0.0f, 0.3f, 0.0f }; static Vec3f D_80942E60 = { 0.0f, 1.0f, 0.0f }; @@ -910,7 +908,8 @@ void func_80940E38(EnGoroiwa* this, PlayState* play) { sp48.y = this->actor.world.pos.y + 20.0f; sp48.z = (Math_CosS(sp46) * sp54) + this->actor.world.pos.z; - func_800B0E48(play, &sp48, &D_80942E48, &D_80942E54, &D_80942E38, &D_80942E44, + func_800B0E48(play, &sp48, &D_80942E48, &D_80942E54, &D_80942E30[ENGOROIWA_C000_2], + &D_80942E3C[ENGOROIWA_C000_2], (Rand_ZeroOne() * 600.0f) + (600.0f * (this->actor.scale.x + 0.1f) * 0.5f), (s32)(Rand_ZeroOne() * 50.0f) + 30); } @@ -938,8 +937,8 @@ void func_80941060(EnGoroiwa* this, PlayState* play) { spAC.y = spA0.y * -0.06f; spAC.z = spA0.z * -0.06f; - func_800B0E48(play, &sp94, &spA0, &spAC, &D_80942E38, &D_80942E44, (s32)(Rand_ZeroOne() * 30.0f) + 15, - (s32)(Rand_ZeroOne() * 40.0f) + 30); + func_800B0E48(play, &sp94, &spA0, &spAC, &D_80942E30[ENGOROIWA_C000_2], &D_80942E3C[ENGOROIWA_C000_2], + (s32)(Rand_ZeroOne() * 30.0f) + 15, (s32)(Rand_ZeroOne() * 40.0f) + 30); } } diff --git a/mm/src/overlays/actors/ovl_En_Hidden_Nuts/z_en_hidden_nuts.c b/mm/src/overlays/actors/ovl_En_Hidden_Nuts/z_en_hidden_nuts.c index ed72da01a..e9754f333 100644 --- a/mm/src/overlays/actors/ovl_En_Hidden_Nuts/z_en_hidden_nuts.c +++ b/mm/src/overlays/actors/ovl_En_Hidden_Nuts/z_en_hidden_nuts.c @@ -104,7 +104,7 @@ void EnHiddenNuts_Init(Actor* thisx, PlayState* play) { EnHiddenNuts* this = THIS; ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 20.0f); - SkelAnime_Init(play, &this->skelAnime, &object_hintnuts_Skel_0023B8.sh, &object_hintnuts_Anim_0024CC, + SkelAnime_Init(play, &this->skelAnime, &object_hintnuts_Skel_0023B8, &object_hintnuts_Anim_0024CC, this->jointTable, this->morphTable, OBJECT_HINTNUTS_LIMB_MAX); Actor_SetScale(&this->actor, 0.01f); diff --git a/mm/src/overlays/actors/ovl_En_Holl/z_en_holl.c b/mm/src/overlays/actors/ovl_En_Holl/z_en_holl.c index fe39f51ae..4a56bcb7b 100644 --- a/mm/src/overlays/actors/ovl_En_Holl/z_en_holl.c +++ b/mm/src/overlays/actors/ovl_En_Holl/z_en_holl.c @@ -69,7 +69,7 @@ ActorInit En_Holl_InitVars = { /**/ EnHoll_Draw, }; -#include "overlays/ovl_En_Holl/ovl_En_Holl.c" +#include "overlays/ovl_En_Holl/ovl_En_Holl.h" static EnHoll* sInstancePlayingSound = NULL; diff --git a/mm/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c b/mm/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c index 48c918c94..919adc4b4 100644 --- a/mm/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c +++ b/mm/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c @@ -49,7 +49,7 @@ ActorInit En_Horse_Game_Check_InitVars = { /**/ EnHorseGameCheck_Draw, }; -#include "overlays/ovl_En_Horse_Game_Check/ovl_En_Horse_Game_Check.c" +#include "overlays/ovl_En_Horse_Game_Check/ovl_En_Horse_Game_Check.h" s32 func_808F8AA0(EnHorseGameCheck* this, PlayState* play) { s32 pad[3]; diff --git a/mm/src/overlays/actors/ovl_En_Ik/z_en_ik.c b/mm/src/overlays/actors/ovl_En_Ik/z_en_ik.c index c40b18e68..7d131273a 100644 --- a/mm/src/overlays/actors/ovl_En_Ik/z_en_ik.c +++ b/mm/src/overlays/actors/ovl_En_Ik/z_en_ik.c @@ -461,7 +461,7 @@ void EnIk_SetupVerticalAttack(EnIk* this) { playbackSpeed = 1.2f; } Animation_Change(&this->skelAnime, &gIronKnuckleVerticalAttackAnim, playbackSpeed, 0.0f, - Animation_GetLastFrame(&gIronKnuckleVerticalAttackAnim.common), ANIMMODE_ONCE_INTERP, -4.0f); + Animation_GetLastFrame(&gIronKnuckleVerticalAttackAnim), ANIMMODE_ONCE_INTERP, -4.0f); this->timer = 0; this->blurEffectSpawnLock = -1; this->actionFunc = EnIk_VerticalAttack; @@ -519,7 +519,7 @@ void EnIk_TakeOutAxe(EnIk* this, PlayState* play) { } else { Animation_Change( &this->skelAnime, &gIronKnuckleRecoverVerticalAttackAnim, (this->drawArmorFlags) ? 1.5f : 1.0f, 0.0f, - Animation_GetLastFrame(&gIronKnuckleRecoverVerticalAttackAnim.common), ANIMMODE_ONCE_INTERP, 0.0f); + Animation_GetLastFrame(&gIronKnuckleRecoverVerticalAttackAnim), ANIMMODE_ONCE_INTERP, 0.0f); } } } @@ -527,7 +527,7 @@ void EnIk_TakeOutAxe(EnIk* this, PlayState* play) { void EnIk_SetupHorizontalDoubleAttack(EnIk* this) { this->actor.speed = 0.0f; Animation_Change(&this->skelAnime, &gIronKnuckleHorizontalAttackAnim, (this->drawArmorFlags) ? 1.3f : 1.0f, 0.0f, - Animation_GetLastFrame(&gIronKnuckleHorizontalAttackAnim.common), ANIMMODE_ONCE_INTERP, + Animation_GetLastFrame(&gIronKnuckleHorizontalAttackAnim), ANIMMODE_ONCE_INTERP, (this->drawArmorFlags) ? 4.0f : 10.0f); this->timer = 0; this->blurEffectSpawnLock = -1; @@ -575,7 +575,7 @@ void EnIk_SetupSingleHorizontalAttack(EnIk* this) { playSpeed = 1.0f; } Animation_Change(&this->skelAnime, &gIronKnuckleHorizontalAttackAnim, playSpeed, 12.0f, - Animation_GetLastFrame(&gIronKnuckleHorizontalAttackAnim.common), ANIMMODE_ONCE_INTERP, 5.0f); + Animation_GetLastFrame(&gIronKnuckleHorizontalAttackAnim), ANIMMODE_ONCE_INTERP, 5.0f); this->timer = 0; this->blurEffectSpawnLock = -1; this->actionFunc = EnIk_SingleHorizontalAttack; diff --git a/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban.c b/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban.c index 2a12074aa..9f6e7f77a 100644 --- a/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban.c +++ b/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban.c @@ -905,7 +905,7 @@ static Gfx* sDisplayLists[] = { gSignPostUpperModelDL, gSignPostLowerModelDL, gSignPostStandModelDL, }; -#include "z_en_kanban_gfx.c" +#include "z_en_kanban_gfx.inc" static f32 sCutAngles[] = { /* CUT_POST */ 0.50f * M_PI, @@ -918,7 +918,7 @@ static f32 sCutAngles[] = { /* */ 0.00f * M_PI, }; -#include "overlays/ovl_En_Kanban/ovl_En_Kanban.c" +#include "overlays/ovl_En_Kanban/ovl_En_Kanban.h" void EnKanban_Draw(Actor* thisx, PlayState* play) { EnKanban* this = THIS; diff --git a/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban_gfx.c b/mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban_gfx.inc similarity index 100% rename from mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban_gfx.c rename to mm/src/overlays/actors/ovl_En_Kanban/z_en_kanban_gfx.inc diff --git a/mm/src/overlays/actors/ovl_En_Knight/z_en_knight.c b/mm/src/overlays/actors/ovl_En_Knight/z_en_knight.c index 80182b13c..e0768627f 100644 --- a/mm/src/overlays/actors/ovl_En_Knight/z_en_knight.c +++ b/mm/src/overlays/actors/ovl_En_Knight/z_en_knight.c @@ -8,6 +8,7 @@ #include "z64shrink_window.h" #include "overlays/actors/ovl_Mir_Ray3/z_mir_ray3.h" #include "objects/gameplay_keep/gameplay_keep.h" +#include "objects/object_knight/object_knight.h" #define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_10 | ACTOR_FLAG_20) @@ -399,65 +400,6 @@ EnKnight* D_809BEFE0; MirRay3* D_809BEFE4; EnKnightEffect D_809BEFE8[100]; -// object - -extern AnimationHeader D_060005A8; -extern AnimationHeader D_060009E0; -extern AnimationHeader D_06000D9C; -extern AnimationHeader D_06001CDC; -extern AnimationHeader D_06002174; -extern AnimationHeader D_06003008; -extern AnimationHeader D_060031F0; -extern AnimationHeader D_06003650; -extern AnimationHeader D_060040E0; -extern AnimationHeader D_06004620; -extern AnimationHeader D_06004974; -extern AnimationHeader D_06005D30; -extern AnimationHeader D_060079D4; -extern AnimationHeader D_06008390; -extern AnimationHeader D_06008524; -extern AnimationHeader D_060089E4; -extern AnimationHeader D_06008D80; -extern AnimationHeader D_06009538; -extern AnimationHeader D_06009D8C; -extern AnimationHeader D_0600A530; -extern AnimationHeader D_0600AFAC; -extern AnimationHeader D_0600B5D4; -extern AnimationHeader D_0600BCF4; -extern AnimationHeader D_0600C384; -extern AnimationHeader D_0600CDE0; -extern AnimationHeader D_0600DDCC; -extern AnimationHeader D_0600E15C; -extern AnimationHeader D_0600E45C; -extern AnimationHeader D_0600EA90; -extern AnimationHeader D_0600EF44; -extern AnimationHeader D_06010E98; -extern AnimationHeader D_06011298; -extern AnimationHeader D_06005E78; -extern AnimationHeader D_06006754; -extern AnimationHeader D_06006EF8; -extern AnimationHeader D_0600A88C; -extern AnimationHeader D_0600C7F0; -extern AnimationHeader D_0600D870; -extern AnimationHeader D_0600E7F4; -extern AnimationHeader D_0600FC78; -extern AnimationHeader D_0601024C; -extern AnimationHeader D_0602105C; -extern AnimationHeader D_06021B10; -extern AnimationHeader D_06021E34; -extern Gfx D_06013020[]; -extern Gfx D_06012DB0[]; -extern Gfx D_06012400[]; -extern AnimatedMaterial D_06018BC4; -extern AnimationHeader D_06020950; -extern AnimationHeader D_06022728; -extern AnimationHeader D_06022CAC; -extern FlexSkeletonHeader D_06020374; -extern FlexSkeletonHeader D_060201A8; -extern Gfx D_060188F8[]; -extern Gfx D_060189F0[]; -extern Gfx D_06018AF0[]; - extern Gfx D_08000000[]; void func_809B20F0(PlayState* play, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4, f32 arg5, s16 arg6) { @@ -531,7 +473,7 @@ void EnKnight_Init(Actor* thisx, PlayState* play) { if (this->actor.params == 0x64) { ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 12.0f); - SkelAnime_InitFlex(play, &this->unk194, &D_060201A8, &D_06003008, this->unk2C4, this->unk372, 29); + SkelAnime_InitFlex(play, &this->unk194, &object_knight_Skel_0201A8, &object_knight_Anim_003008, this->unk2C4, this->unk372, 29); Actor_SetScale(&this->actor, KREG(12) * 0.001f + 0.017f); func_809BA058(this, play); Collider_InitAndSetCylinder(play, &this->unk488, &this->actor, &D_809BDC38); @@ -543,10 +485,10 @@ void EnKnight_Init(Actor* thisx, PlayState* play) { this->actor.flags &= ~1; if (1) {} if (this->actor.params == 0xC8) { - SkelAnime_InitFlex(play, &this->unk194, &D_06020374, &D_060040E0, this->unk2C4, this->unk372, 0x1D); + SkelAnime_InitFlex(play, &this->unk194, &object_knight_Skel_020374, &object_knight_Anim_0040E0, this->unk2C4, this->unk372, 0x1D); Actor_SetScale(&this->actor, KREG(13) * 0.001f + 0.013f); } else { - SkelAnime_InitFlex(play, &this->unk194, &D_060201A8, &D_060040E0, this->unk2C4, this->unk372, 0x1D); + SkelAnime_InitFlex(play, &this->unk194, &object_knight_Skel_0201A8, &object_knight_Anim_0040E0, this->unk2C4, this->unk372, 0x1D); Actor_SetScale(&this->actor, KREG(13) * 0.001f + 0.017f); } if (this->actor.params == 0xCA) { @@ -561,12 +503,12 @@ void EnKnight_Init(Actor* thisx, PlayState* play) { Collider_InitAndSetJntSph(play, &this->unk594, &this->actor, &D_809BDC28, this->unk5B4); if (this->actor.params == 0x23) { Collider_InitAndSetJntSph(play, &this->unk4D4, &this->actor, &D_809BDB8C, this->unk4F4); - SkelAnime_InitFlex(play, &this->unk194, &D_06020374, &D_060040E0, this->unk2C4, this->unk372, 0x1D); + SkelAnime_InitFlex(play, &this->unk194, &object_knight_Skel_020374, &object_knight_Anim_0040E0, this->unk2C4, this->unk372, 0x1D); this->actor.colChkInfo.health = 6 - BREG(40); Actor_SetScale(&this->actor, KREG(13) * 0.001f + 0.013f); } else { Collider_InitAndSetJntSph(play, &this->unk4D4, &this->actor, &D_809BDB9C, this->unk4F4); - SkelAnime_InitFlex(play, &this->unk194, &D_060201A8, &D_060040E0, this->unk2C4, this->unk372, 0x1D); + SkelAnime_InitFlex(play, &this->unk194, &object_knight_Skel_0201A8, &object_knight_Anim_0040E0, this->unk2C4, this->unk372, 0x1D); this->actor.colChkInfo.health = 14 - BREG(41); Actor_SetScale(&this->actor, KREG(12) * 0.001f + 0.017f); this->unk290 = Rand_ZeroFloat(1.9999f); @@ -735,7 +677,7 @@ s32 func_809B31E8(EnKnight* this, PlayState* play) { } void func_809B329C(EnKnight* this, PlayState* play, s32 arg2) { - Animation_MorphToLoop(&this->unk194, &D_06020950, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_020950, -5.0f); this->actionFunc = func_809B331C; if (this == D_809BEFD0) { if (arg2) { @@ -758,8 +700,8 @@ void func_809B331C(EnKnight* this, PlayState* play) { } void func_809B3394(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_06011298, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06011298); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_011298, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_011298); this->actionFunc = func_809B33F0; } @@ -798,8 +740,8 @@ void func_809B33F0(EnKnight* this, PlayState* play) { } void func_809B35BC(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_06022728, -5.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06022728); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_022728, -5.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_022728); this->actionFunc = func_809B3618; } @@ -839,7 +781,7 @@ void func_809B3618(EnKnight* this, PlayState* play) { } void func_809B37C8(EnKnight* this, PlayState* play) { - Animation_MorphToLoop(&this->unk194, &D_06022CAC, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_022CAC, 0.0f); this->actionFunc = func_809B3834; if (this == D_809BEFD0) { this->unk14A[0] = 6; @@ -858,11 +800,11 @@ void func_809B3834(EnKnight* this, PlayState* play) { void func_809B389C(EnKnight* this, PlayState* play) { if (Rand_ZeroOne() < 0.5f) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600C384, -2.0f); - this->unk1D8 = Animation_GetLastFrame(&D_0600C384); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00C384, -2.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_00C384); } else { - Animation_MorphToPlayOnce(&this->unk194, &D_0600BCF4, -2.0f); - this->unk1D8 = Animation_GetLastFrame(&D_0600BCF4); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00BCF4, -2.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_00BCF4); } this->actionFunc = func_809B3958; this->unk14A[0] = 20; @@ -893,8 +835,8 @@ void func_809B3A7C(EnKnight* this, PlayState* play) { Vec3f sp28; if (this->actor.xzDistToPlayer <= 200.0f) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600AFAC, -3.0f); - this->unk1D8 = Animation_GetLastFrame(&D_0600AFAC); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00AFAC, -3.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_00AFAC); this->actionFunc = func_809B3B94; Matrix_RotateYS(this->unk172, MTXMODE_NEW); Matrix_MultVecZ(KREG(49) + 7.0f, &sp28); @@ -922,7 +864,7 @@ void func_809B3B94(EnKnight* this, PlayState* play) { } SkelAnime_Update(&this->unk194); if (Animation_OnFrame(&this->unk194, this->unk1D8)) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600B5D4, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00B5D4, 0.0f); Actor_PlaySfx(&this->actor, this->unk6BC); this->unk1D8 = 1000.0f; } @@ -945,8 +887,8 @@ void func_809B3CD0(EnKnight* this, PlayState* play) { } if (this->actionFunc != func_809B3DAC) { this->unk424 = this->actionFunc; - Animation_MorphToPlayOnce(&this->unk194, &D_060031F0, -2.0f); - this->unk1D8 = Animation_GetLastFrame(&D_060031F0); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0031F0, -2.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_0031F0); this->actionFunc = func_809B3DAC; } this->unk14A[0] = 5; @@ -970,7 +912,7 @@ void func_809B3DAC(EnKnight* this, PlayState* play) { } void func_809B3E9C(EnKnight* this, PlayState* play) { - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); this->actionFunc = func_809B3F0C; this->unk14A[0] = Rand_ZeroFloat(50.0f) + 20.0f; } @@ -998,7 +940,7 @@ void func_809B3F0C(EnKnight* this, PlayState* play) { void func_809B4024(EnKnight* this, PlayState* play, s16 arg2) { this->actionFunc = func_809B40E8; - Animation_MorphToPlayOnce(&this->unk194, &D_0600EF44, -2.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00EF44, -2.0f); if (Rand_ZeroOne() < 0.5f) { this->unk15A = this->actor.shape.rot.y + arg2; this->unk186 = 0x3800; @@ -1056,7 +998,7 @@ void func_809B41F8(EnKnight* this, PlayState* play) { } void func_809B42B8(EnKnight* this, PlayState* play) { - Animation_MorphToLoop(&this->unk194, &D_06004620, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_004620, -5.0f); this->actionFunc = func_809B4308; this->actor.speed = 0.0f; } @@ -1120,23 +1062,23 @@ void func_809B4308(EnKnight* this, PlayState* play) { func_809B22CC(this, play, 3); } if ((this->actor.speed > 3.0f) && (sp5C <= 3.0f)) { - Animation_MorphToLoop(&this->unk194, &D_06003650, -3.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_003650, -3.0f); if (Rand_ZeroOne() < 0.25f) { func_809B3A7C(this, play); } } if (this->actionFunc == func_809B4308) { if ((this->actor.speed < 4.0f) && (sp5C >= 4.0f)) { - Animation_MorphToLoop(&this->unk194, &D_06004620, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_004620, -5.0f); if (Rand_ZeroOne() < 0.25f) { func_809B3A7C(this, play); } } if ((this->actor.speed < 1.0f) && (sp5C >= 1.0f)) { - Animation_MorphToLoop(&this->unk194, &D_060040E0, -10.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -10.0f); } if ((this->actor.speed >= 1.0f) && (sp5C < 1.0f)) { - Animation_MorphToLoop(&this->unk194, &D_06004620, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_004620, -5.0f); } } temp_v0 = sp34 - this->actor.shape.rot.y; @@ -1159,7 +1101,7 @@ void func_809B4308(EnKnight* this, PlayState* play) { void func_809B47EC(EnKnight* this, PlayState* play, u8 arg2) { if (this->actionFunc != func_809B4880) { - Animation_MorphToLoop(&this->unk194, &D_06003650, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_003650, -5.0f); this->unk148 = 0; this->actionFunc = func_809B4880; } @@ -1188,12 +1130,12 @@ void func_809B4880(EnKnight* this, PlayState* play) { if (this->unk291 != 0) { this->unk148 = 3; this->unk2A1 = 30; - Animation_MorphToLoop(&this->unk194, &D_0600E45C, -2.0f); - this->unk1D8 = Animation_GetLastFrame(&D_0600E45C); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00E45C, -2.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_00E45C); Actor_PlaySfx(&this->actor, NA_SE_EN_STAL_FREEZE_LIGHTS); } else { this->unk148 = 1; - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); this->unk1D8 = 1000.0f; } } @@ -1201,14 +1143,14 @@ void func_809B4880(EnKnight* this, PlayState* play) { case 1: if (this->unk291 != 0) { this->unk148 = 2; - Animation_MorphToPlayOnce(&this->unk194, &D_060031F0, -2.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0031F0, -2.0f); Actor_PlaySfx(&this->actor, this->unk6B6); } goto block_24; case 2: if (this->unk291 == 0) { this->unk148 = 1; - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); } if (this->unk291 >= 8) { Math_ApproachF(&this->unk474, 1.0f, 1.0f, 0.5f); @@ -1217,7 +1159,7 @@ void func_809B4880(EnKnight* this, PlayState* play) { case 3: if (Animation_OnFrame(&this->unk194, this->unk1D8)) { this->unk148 = 2; - Animation_MorphToPlayOnce(&this->unk194, &D_060031F0, -2.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0031F0, -2.0f); this->unk1D8 = 1000.0f; } goto block_24; @@ -1240,7 +1182,7 @@ void func_809B4880(EnKnight* this, PlayState* play) { } void func_809B4BFC(EnKnight* this, PlayState* play) { - Animation_MorphToLoop(&this->unk194, &D_0600CDE0, -25.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00CDE0, -25.0f); Actor_PlaySfx(&this->actor, this->unk6B6); this->actionFunc = func_809B4C58; this->unk14A[0] = 35; @@ -1310,10 +1252,10 @@ void func_809B4F90(EnKnight* this, PlayState* arg1) { this->actionFunc = func_809B5058; temp_v0 = this->unk172 - this->actor.shape.rot.y; if (ABS_ALT(temp_v0) < 0x4000) { - Animation_MorphToPlayOnce(&this->unk194, &D_06004974, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_004974, 0.0f); this->unk148 = 0; } else { - Animation_MorphToPlayOnce(&this->unk194, &D_06000D9C, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_000D9C, 0.0f); this->unk148 = 1; } Matrix_RotateYS(this->unk172, MTXMODE_NEW); @@ -1357,10 +1299,10 @@ void func_809B51DC(EnKnight* this, PlayState* play) { this->actionFunc = func_809B52E8; temp_v0 = this->unk172 - this->actor.shape.rot.y; if (ABS_ALT(temp_v0) < 0x4000) { - Animation_MorphToPlayOnce(&this->unk194, &D_06001CDC, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_001CDC, 0.0f); this->unk1D8 = 1.0f; } else { - Animation_MorphToPlayOnce(&this->unk194, &D_06005D30, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_005D30, 0.0f); this->unk1D8 = -1.0f; } Matrix_RotateYS(this->unk172, MTXMODE_NEW); @@ -1513,7 +1455,7 @@ void func_809B592C(EnKnight* this, PlayState* play) { Vec3f sp28; this->actionFunc = func_809B5B08; - Animation_MorphToPlayOnce(&this->unk194, &D_06002174, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_002174, 0.0f); Matrix_RotateYS(this->unk172, MTXMODE_NEW); Matrix_MultVecZ(-15.0f, &sp28); this->unk2A4 = sp28.x; @@ -1532,7 +1474,7 @@ void func_809B59FC(EnKnight* this, PlayState* play) { Vec3f sp28; this->actionFunc = func_809B5B08; - Animation_MorphToPlayOnce(&this->unk194, &D_06002174, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_002174, 0.0f); Matrix_RotateYS(this->unk172, MTXMODE_NEW); Matrix_MultVecZ(KREG(90) + 14.0f, &sp28); this->unk2A4 = sp28.x; @@ -1607,9 +1549,9 @@ void func_809B5D54(EnKnight* this, PlayState* play) { break; case 1: if (this->unk290 == 0) { - Animation_MorphToPlayOnce(&this->unk194, &D_060009E0, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0009E0, 0.0f); } else { - Animation_MorphToPlayOnce(&this->unk194, &D_060005A8, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0005A8, 0.0f); } Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_STAND); this->unk290 = 1 - this->unk290; @@ -1636,7 +1578,7 @@ void func_809B5D54(EnKnight* this, PlayState* play) { void func_809B5E90(EnKnight* this, PlayState* play) { this->actionFunc = func_809B5ED0; - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); } void func_809B5ED0(EnKnight* this, PlayState* play) { @@ -1664,7 +1606,7 @@ void func_809B5ED0(EnKnight* this, PlayState* play) { void func_809B5FA8(EnKnight* this, PlayState* play) { this->actionFunc = func_809B601C; - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); this->unk148 = 0; this->unk14A[0] = Rand_ZeroFloat(10.0f) + 65.0f; } @@ -1704,7 +1646,7 @@ void func_809B601C(EnKnight* this, PlayState* play) { } if (this->unk14A[0] == 0 && func_801A46F8() == 1) { - Animation_MorphToLoop(&this->unk194, &D_0600DDCC, -3.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00DDCC, -3.0f); this->unk148 = 1; this->unk14A[0] = 0xC8; } @@ -1747,7 +1689,7 @@ void func_809B601C(EnKnight* this, PlayState* play) { void func_809B631C(EnKnight* this, PlayState* play) { if (this == D_809BEFD0) { this->actionFunc = func_809B8458; - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); } else { this->actionFunc = func_809B842C; } @@ -1778,7 +1720,7 @@ void func_809B638C(EnKnight* this, PlayState* play, s16 arg2) { } void func_809B6528(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600A530, -5.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00A530, -5.0f); this->actionFunc = func_809B6764; this->unk148 = 0; } @@ -1835,8 +1777,8 @@ void func_809B6764(EnKnight* this, PlayState* play) { } if (player->unk_D57 == 4 && func_809B31E8(this, play) != 0) { this->unk148 = 0xA; - Animation_MorphToPlayOnce(&this->unk194, &D_06008524, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06008524); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_008524, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_008524); } break; case 1: @@ -1880,13 +1822,13 @@ void func_809B6764(EnKnight* this, PlayState* play) { case 10: if (Animation_OnFrame(&this->unk194, this->unk1D8) != 0) { this->unk148 = 0xB; - Animation_MorphToPlayOnce(&this->unk194, &D_060089E4, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_060089E4); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0089E4, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_0089E4); } break; case 11: if (Animation_OnFrame(&this->unk194, this->unk1D8) != 0) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600A530, -15.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00A530, -15.0f); this->unk148 = 0; } break; @@ -1916,7 +1858,7 @@ void func_809B6764(EnKnight* this, PlayState* play) { } void func_809B6C04(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_06003008, -5.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_003008, -5.0f); this->actionFunc = func_809B6C54; this->unk14A[0] = 0x32; } @@ -1938,7 +1880,7 @@ void func_809B6C54(EnKnight* this, PlayState* play) { } void func_809B6D38(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_060079D4, -10.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0079D4, -10.0f); this->actionFunc = func_809B6D94; this->unk148 = 0; this->unk14A[0] = 0x3C; @@ -1979,8 +1921,8 @@ void func_809B6D94(EnKnight* this, PlayState* play) { } void func_809B6EC8(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_06009538, -5.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06009538); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_009538, -5.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_009538); this->actionFunc = func_809B6F40; this->unk148 = 0; this->unk14A[0] = KREG(57) + 0x96; @@ -2009,7 +1951,7 @@ void func_809B6F40(EnKnight* this, PlayState* play) { case 0: if (Animation_OnFrame(&this->unk194, this->unk1D8) != 0) { this->unk148 = 1; - Animation_MorphToLoop(&this->unk194, &D_06008D80, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_008D80, 0.0f); } func_809B638C(this, play, 0x1600); break; @@ -2021,8 +1963,8 @@ void func_809B6F40(EnKnight* this, PlayState* play) { } if (this->unk14A[0] == 0) { this->unk148 = 2; - Animation_MorphToPlayOnce(&this->unk194, &D_0600E15C, -5.0f); - this->unk1D8 = Animation_GetLastFrame(&D_0600E15C); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00E15C, -5.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_00E15C); } break; case 2: @@ -2076,7 +2018,7 @@ void func_809B71DC(EnKnight* this, PlayState* play) { /* Fallthrough */ case 1: if (this->unk684 == (u32)(sREG(64) + 0xD)) { - Animation_MorphToPlayOnce(&this->unk194, &D_06009D8C, sREG(65)); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_009D8C, sREG(65)); Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_STAND); } if (this->unk684 != (u32)(sREG(66) + 0x17)) { @@ -2088,7 +2030,7 @@ void func_809B71DC(EnKnight* this, PlayState* play) { this->unk698.x = 1354.0f; this->unk698.y = 83.0f; this->unk698.z = 2865.0f; - Animation_MorphToPlayOnce(&this->unk194, &D_06009D8C, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_009D8C, 0.0f); this->unk684 = 0; this->unk688 = 2; /* Fallthrough */ @@ -2108,7 +2050,7 @@ void func_809B71DC(EnKnight* this, PlayState* play) { Math_ApproachF(&this->unk470, temp_fa0, 1.0f, 0.5f); } if (this->unk684 == (u32)(sREG(69) + 0x32)) { - Animation_MorphToPlayOnce(&this->unk194, &D_06008390, sREG(65) + -10.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_008390, sREG(65) + -10.0f); Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_ATTACK_K); } if (this->unk684 >= (u32)(sREG(69) + 0x32)) { @@ -2143,7 +2085,7 @@ void func_809B71DC(EnKnight* this, PlayState* play) { void func_809B7708(EnKnight* this, PlayState* play) { if (this->actionFunc != func_809B52E8 && this->actionFunc != func_809B5698 && this->actionFunc != func_809B58D4) { - Animation_MorphToLoop(&this->unk194, &D_060040E0, -5.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_0040E0, -5.0f); this->actionFunc = func_809B7778; } } @@ -2217,9 +2159,9 @@ void func_809B7950(EnKnight* this, PlayState* play) { this->unk688 = 1; this->unk6B0 = 60.0f; if (this->unk424 == func_809B6764) { - Animation_MorphToPlayOnce(&this->unk194, &D_0600EA90, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00EA90, 0.0f); } else { - Animation_MorphToPlayOnce(&this->unk194, &D_0600E7F4, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00E7F4, 0.0f); } Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_STAND); case 1: @@ -2275,12 +2217,12 @@ void func_809B7950(EnKnight* this, PlayState* play) { case 3: if (this->unk684 == 7) { if (this->unk424 == func_809B6764) { - Animation_MorphToPlayOnce(&this->unk194, &D_06006EF8, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06006EF8); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_006EF8, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_006EF8); Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_STAND_RAPID); } else { - Animation_MorphToPlayOnce(&this->unk194, &D_06006754, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06006754); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_006754, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_006754); } Message_StartTextbox(play, 0x153E, NULL); } @@ -2299,7 +2241,7 @@ void func_809B7950(EnKnight* this, PlayState* play) { } if (Animation_OnFrame(&this->unk194, this->unk1D8) != 0) { - Animation_MorphToLoop(&this->unk194, &D_0600C7F0, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00C7F0, 0.0f); this->unk1D8 = 1000.0f; Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_HAND); } @@ -2307,7 +2249,7 @@ void func_809B7950(EnKnight* this, PlayState* play) { if (this->unk684 == (u32)(KREG(25) + 0x78)) { this->unk688 = 4; this->unk684 = 0; - Animation_MorphToPlayOnce(&this->unk194, &D_0600C7F0, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_00C7F0, 0.0f); } break; case 4: @@ -2333,7 +2275,7 @@ void func_809B7950(EnKnight* this, PlayState* play) { } if (this->unk684 == (u32)(BREG(17) + 0xA0)) { Message_StartTextbox(play, 0x1542, NULL); - Animation_MorphToLoop(&this->unk194, &D_0600A88C, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00A88C, 0.0f); } if (this->unk684 == (u32)(BREG(18) + 0xAA)) { Player_SetCsActionWithHaltedActors(play, &this->actor, 4); @@ -2347,21 +2289,21 @@ void func_809B7950(EnKnight* this, PlayState* play) { } } if (this->unk684 == (u32)(BREG(19) + 0xDC)) { - Animation_MorphToPlayOnce(&this->unk194, &D_06021E34, -3.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_021E34, -3.0f); } if (this->unk684 == (u32)(BREG(20) + 0xE6)) { Message_StartTextbox(play, 0x1540, NULL); } if (this->unk684 == (u32)(BREG(20) + 0xF0)) { - Animation_MorphToLoop(&this->unk194, &D_06005E78, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_005E78, 0.0f); } if (this->unk684 == (u32)(BREG(21) + 0x140)) { if (this->unk424 == func_809B6764) { - Animation_MorphToPlayOnce(&this->unk194, &D_0601024C, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_01024C, 0.0f); Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_SIT); } else { - Animation_MorphToPlayOnce(&this->unk194, &D_0602105C, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_02105C, 0.0f); } Message_CloseTextbox(play); } @@ -2527,8 +2469,8 @@ void func_809B8458(EnKnight* this, PlayState* play) { } this->unk688 = 4; this->unk684 = 0; - Animation_MorphToPlayOnce(&this->unk194, &D_06010E98, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06010E98); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_010E98, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_010E98); /* Fallthrough */ case 4: this->unk6A4 = BREG(29) * 0.01f + 0.1f; @@ -2549,7 +2491,7 @@ void func_809B8458(EnKnight* this, PlayState* play) { this->unk688 = 5; this->unk684 = 0; - Animation_MorphToLoop(&D_809BEFD8->unk194, &D_06021B10, 0.0f); + Animation_MorphToLoop(&D_809BEFD8->unk194, &object_knight_Anim_021B10, 0.0f); D_809BEFD8->actor.world.pos.x = BREG(30) + 1363.0f + 120.0f; Message_StartTextbox(play, 0x1533, NULL); this->unk6B0 = 30.0f; @@ -2567,7 +2509,7 @@ void func_809B8458(EnKnight* this, PlayState* play) { this->unk430 = KREG(42) + 200.0f; } if (Animation_OnFrame(&this->unk194, this->unk1D8)) { - Animation_MorphToLoop(&this->unk194, &D_0600FC78, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_00FC78, 0.0f); this->unk1D8 = 1000.0f; } this->unk68C.x = 1349.0f; @@ -2580,7 +2522,7 @@ void func_809B8458(EnKnight* this, PlayState* play) { D_809BEFD8->actor.world.pos.y = 45.0f; D_809BEFD8->actor.world.pos.z = BREG(31) + 2864.0f + 60.0f; if (this->unk684 == (u32)(BREG(35) + 0x2D)) { - Animation_MorphToPlayOnce(&D_809BEFD8->unk194, &D_0600D870, -10.0f); + Animation_MorphToPlayOnce(&D_809BEFD8->unk194, &object_knight_Anim_00D870, -10.0f); Actor_PlaySfx(&D_809BEFD8->actor, NA_SE_EN_DEBU_PAUSE_K); } if (this->unk684 != (u32)(BREG(33) + 0x50)) { @@ -2588,7 +2530,7 @@ void func_809B8458(EnKnight* this, PlayState* play) { } this->unk688 = 6; this->unk684 = 0; - Animation_MorphToLoop(&D_809BEFD4->unk194, &D_06021B10, 0.0f); + Animation_MorphToLoop(&D_809BEFD4->unk194, &object_knight_Anim_021B10, 0.0f); D_809BEFD4->actor.world.pos.x = BREG(30) + 1363.0f + 120.0f; D_809BEFD8->actor.world.pos.z = 3164.0f; Message_StartTextbox(play, 0x151B, NULL); @@ -2612,7 +2554,7 @@ void func_809B8458(EnKnight* this, PlayState* play) { D_809BEFD4->actor.world.pos.y = 45.0f; D_809BEFD4->actor.world.pos.z = (BREG(31) + 2864.0f) - 60.0f; if (this->unk684 == (u32)(BREG(35) + 0x2D)) { - Animation_MorphToPlayOnce(&D_809BEFD4->unk194, &D_0600D870, -10.0f); + Animation_MorphToPlayOnce(&D_809BEFD4->unk194, &object_knight_Anim_00D870, -10.0f); Actor_PlaySfx(&D_809BEFD4->actor, NA_SE_EN_YASE_PAUSE_K); } if (this->unk684 != (u32)(BREG(33) + 0x50)) { @@ -2638,12 +2580,12 @@ void func_809B8458(EnKnight* this, PlayState* play) { case 7: if (this->unk684 >= (u32)(BREG(37) + 0x14)) { if (this->unk684 == (u32)(BREG(37) + 0x14)) { - Animation_MorphToPlayOnce(&this->unk194, &D_06009D8C, 0.0f); - this->unk1D8 = Animation_GetLastFrame(&D_06009D8C); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_009D8C, 0.0f); + this->unk1D8 = Animation_GetLastFrame(&object_knight_Anim_009D8C); Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_STAND); } if (Animation_OnFrame(&this->unk194, this->unk1D8) != 0) { - Animation_MorphToLoop(&this->unk194, &D_06008390, 0.0f); + Animation_MorphToLoop(&this->unk194, &object_knight_Anim_008390, 0.0f); this->unk1D8 = 1000.0f; } } @@ -2655,8 +2597,8 @@ void func_809B8458(EnKnight* this, PlayState* play) { Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_ATTACK); } if (this->unk684 == (u32)(BREG(44) + 0x28)) { - Animation_MorphToLoop(&D_809BEFD4->unk194, &D_0600CDE0, -5.0f); - Animation_MorphToLoop(&D_809BEFD8->unk194, &D_0600CDE0, -5.0f); + Animation_MorphToLoop(&D_809BEFD4->unk194, &object_knight_Anim_00CDE0, -5.0f); + Animation_MorphToLoop(&D_809BEFD8->unk194, &object_knight_Anim_00CDE0, -5.0f); } if (this->unk684 == 40) { Actor_PlaySfx(&this->actor, NA_SE_EN_BOSU_HEAD_MID); @@ -2922,7 +2864,7 @@ void func_809B9F8C(EnKnight* this, PlayState* play) { } void func_809BA058(EnKnight* this, PlayState* play) { - Animation_MorphToPlayOnce(&this->unk194, &D_06003008, 0.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_003008, 0.0f); this->unk194.curFrame = 19.0f; this->actionFunc = func_809BA0CC; this->unk148 = 0; @@ -2975,7 +2917,7 @@ void func_809BA0CC(EnKnight* this, PlayState* play) { if (D_809BEFD0->actionFunc != func_809B52E8 && D_809BEFD0->actionFunc != func_809B5698) { this->unk14A[1] = 0; func_809B6D38(D_809BEFD0, play); - Animation_MorphToPlayOnce(&this->unk194, &D_060079D4, -10.0f); + Animation_MorphToPlayOnce(&this->unk194, &object_knight_Anim_0079D4, -10.0f); this->unk152 = 0; this->unk194.playSpeed = 0.0f; } else { @@ -3587,9 +3529,10 @@ void func_809BC2C4(EnKnight* this, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); Gfx_SetupDL25_Xlu(play->state.gfxCtx); - AnimatedMat_Draw(play, Lib_SegmentedToVirtual(&D_06018BC4)); + AnimatedMat_Draw(play, Lib_SegmentedToVirtual(&object_knight_Matanimheader_018BC4)); - gSPDisplayList(POLY_XLU_DISP++, D_08000000); + // BENTODO, will this work on 64 bit. + gSPDisplayList(POLY_XLU_DISP++, 0x08000000 | 1); if (this == D_809BEFD0) { gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, (u8)(sREG(11) + 0xB4), 255, 255, @@ -3612,14 +3555,14 @@ void func_809BC2C4(EnKnight* this, PlayState* play) { switch (this->unk44C) { case 0: - gSPDisplayList(POLY_XLU_DISP++, D_06018AF0); + gSPDisplayList(POLY_XLU_DISP++, object_knight_DL_018AF0); break; case 1: - gSPDisplayList(POLY_XLU_DISP++, D_060189F0); + gSPDisplayList(POLY_XLU_DISP++, object_knight_DL_0189F0); break; default: case 2: - gSPDisplayList(POLY_XLU_DISP++, D_060188F8); + gSPDisplayList(POLY_XLU_DISP++, object_knight_DL_0188F8); break; } @@ -3674,11 +3617,11 @@ s32 func_809BC720(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s } } else if (this == D_809BEFD8) { if (limbIndex == 0xF) { - *dList = D_06013020; + *dList = object_knight_DL_013020; } else if (limbIndex == 0x12) { - *dList = D_06012DB0; + *dList = object_knight_DL_012DB0; } else if (limbIndex == 0x13) { - *dList = D_06012400; + *dList = object_knight_DL_012400; } } return 0; diff --git a/mm/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c b/mm/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c index bb8da5efe..4251fe704 100644 --- a/mm/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c +++ b/mm/src/overlays/actors/ovl_En_Mm2/z_en_mm2.c @@ -30,7 +30,7 @@ ActorInit En_Mm2_InitVars = { /**/ EnMm2_Draw, }; -#include "overlays/ovl_En_Mm2/ovl_En_Mm2.c" +#include "overlays/ovl_En_Mm2/ovl_En_Mm2.h" void EnMm2_Init(Actor* thisx, PlayState* play) { EnMm2* this = THIS; diff --git a/mm/src/overlays/actors/ovl_En_Mm3/z_en_mm3.c b/mm/src/overlays/actors/ovl_En_Mm3/z_en_mm3.c index 42790116e..512087e9c 100644 --- a/mm/src/overlays/actors/ovl_En_Mm3/z_en_mm3.c +++ b/mm/src/overlays/actors/ovl_En_Mm3/z_en_mm3.c @@ -74,7 +74,7 @@ static AnimationInfo sAnimationInfo[] = { { &object_mm_Anim_00DA50, 1.0f, 0.0f, 10.0f, ANIMMODE_ONCE, -10.0f }, }; -#include "overlays/ovl_En_Mm3/ovl_En_Mm3.c" +#include "overlays/ovl_En_Mm3/ovl_En_Mm3.h" Vec3f D_80A704F0 = { 0.0f, 0.0f, 0.0f }; diff --git a/mm/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c b/mm/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c index 3ea5514ea..9c48e1513 100644 --- a/mm/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c +++ b/mm/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c @@ -427,7 +427,7 @@ void EnPoSisters_SetupSpinUp(EnPoSisters* this) { Animation_MorphToLoop(&this->skelAnime, &gPoeSistersAttackAnim, -5.0f); this->actor.speed = 0.0f; - this->spinupTimer = Animation_GetLastFrame(&gPoeSistersAttackAnim.common) * 3 + 3; + this->spinupTimer = Animation_GetLastFrame(&gPoeSistersAttackAnim) * 3 + 3; this->poSisterFlags &= ~POE_SISTERS_FLAG_UPDATE_SHAPE_ROT; this->actionFunc = EnPoSisters_SpinUp; } @@ -590,7 +590,7 @@ void EnPoSisters_Flee(EnPoSisters* this, PlayState* play) { void EnPoSisters_SetupSpinToInvis(EnPoSisters* this) { Animation_Change(&this->skelAnime, &gPoeSistersAppearDisappearAnim, 1.5f, 0.0f, - Animation_GetLastFrame(&gPoeSistersAppearDisappearAnim.common), ANIMMODE_ONCE, -3.0f); + Animation_GetLastFrame(&gPoeSistersAppearDisappearAnim), ANIMMODE_ONCE, -3.0f); this->invisibleTimer = 100; // 5 seconds this->actor.speed = 0.0f; this->actor.world.rot.y = this->actor.shape.rot.y; @@ -614,7 +614,7 @@ void EnPoSisters_SpinToInvis(EnPoSisters* this, PlayState* play) { void EnPoSisters_SetupSpinBackToVisible(EnPoSisters* this, PlayState* play) { Animation_Change(&this->skelAnime, &gPoeSistersAppearDisappearAnim, 1.5f, 0.0f, - Animation_GetLastFrame(&gPoeSistersAppearDisappearAnim.common), ANIMMODE_ONCE, -3.0f); + Animation_GetLastFrame(&gPoeSistersAppearDisappearAnim), ANIMMODE_ONCE, -3.0f); if (this->type == POE_SISTERS_TYPE_MEG) { this->megDistToPlayer = 110.0f; EnPoSisters_MatchPlayerXZ(this, play); diff --git a/mm/src/overlays/actors/ovl_En_Sda/z_en_sda.c b/mm/src/overlays/actors/ovl_En_Sda/z_en_sda.c index 56a6e2c32..c0afae600 100644 --- a/mm/src/overlays/actors/ovl_En_Sda/z_en_sda.c +++ b/mm/src/overlays/actors/ovl_En_Sda/z_en_sda.c @@ -70,7 +70,7 @@ Vec3f D_80947B10[] = { static s32 sPad = 0; -#include "overlays/ovl_En_Sda/ovl_En_Sda.c" +#include "overlays/ovl_En_Sda/ovl_En_Sda.h" void EnSda_Init(Actor* thisx, PlayState* play) { } diff --git a/mm/src/overlays/actors/ovl_En_Sth/z_en_sth.c b/mm/src/overlays/actors/ovl_En_Sth/z_en_sth.c index a656b1232..cdd594ddc 100644 --- a/mm/src/overlays/actors/ovl_En_Sth/z_en_sth.c +++ b/mm/src/overlays/actors/ovl_En_Sth/z_en_sth.c @@ -39,7 +39,7 @@ ActorInit En_Sth_InitVars = { /**/ NULL, }; -#include "overlays/ovl_En_Sth/ovl_En_Sth.c" +#include "overlays/ovl_En_Sth/ovl_En_Sth.h" static ColliderCylinderInit sCylinderInit = { { diff --git a/mm/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c b/mm/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c index fb7e31670..219411004 100644 --- a/mm/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c +++ b/mm/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c @@ -30,7 +30,7 @@ ActorInit En_Sth2_InitVars = { /**/ NULL, }; -#include "overlays/ovl_En_Sth2/ovl_En_Sth2.c" +#include "overlays/ovl_En_Sth2/ovl_En_Sth2.h" void EnSth2_Init(Actor* thisx, PlayState* play) { EnSth2* this = THIS; diff --git a/mm/src/overlays/actors/ovl_En_Syateki_Okuta/z_en_syateki_okuta.c b/mm/src/overlays/actors/ovl_En_Syateki_Okuta/z_en_syateki_okuta.c index fa9d864f0..e2e3d2277 100644 --- a/mm/src/overlays/actors/ovl_En_Syateki_Okuta/z_en_syateki_okuta.c +++ b/mm/src/overlays/actors/ovl_En_Syateki_Okuta/z_en_syateki_okuta.c @@ -79,7 +79,7 @@ static AnimationInfo sAnimationInfo[] = { { &gOctorokHitAnim, 1.0f, 0.0f, 0.0f, ANIMMODE_ONCE, -1.0f }, // SG_OCTO_ANIM_HIT }; -#include "assets/overlays/ovl_En_Syateki_Okuta/ovl_En_Syateki_Okuta.c" +#include "assets/overlays/ovl_En_Syateki_Okuta/ovl_En_Syateki_Okuta.h" static InitChainEntry sInitChain[] = { ICHAIN_S8(hintId, TATL_HINT_ID_OCTOROK, ICHAIN_CONTINUE), diff --git a/mm/src/overlays/actors/ovl_En_Tanron1/z_en_tanron1.c b/mm/src/overlays/actors/ovl_En_Tanron1/z_en_tanron1.c index d812b9a04..18a674a8a 100644 --- a/mm/src/overlays/actors/ovl_En_Tanron1/z_en_tanron1.c +++ b/mm/src/overlays/actors/ovl_En_Tanron1/z_en_tanron1.c @@ -32,7 +32,7 @@ ActorInit En_Tanron1_InitVars = { static s32 sPad = 0; -#include "overlays/ovl_En_Tanron1/ovl_En_Tanron1.c" +#include "overlays/ovl_En_Tanron1/ovl_En_Tanron1.h" void EnTanron1_Init(Actor* thisx, PlayState* play) { EnTanron1* this = THIS; diff --git a/mm/src/overlays/actors/ovl_En_Tk/z_en_tk.c b/mm/src/overlays/actors/ovl_En_Tk/z_en_tk.c index 639a37db1..bedd5369d 100644 --- a/mm/src/overlays/actors/ovl_En_Tk/z_en_tk.c +++ b/mm/src/overlays/actors/ovl_En_Tk/z_en_tk.c @@ -227,7 +227,7 @@ void EnTk_Init(Actor* thisx, PlayState* play) { ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 24.0f); SkelAnime_InitFlex(play, &this->skelAnime, &object_tk_Skel_00B9E8, NULL, this->jointTable, this->morphTable, 18); Animation_Change(&this->skelAnime, &object_tk_Anim_0030A4, 1.0f, 0.0f, - Animation_GetLastFrame(&object_tk_Anim_0030A4.common), ANIMMODE_LOOP, 0.0f); + Animation_GetLastFrame(&object_tk_Anim_0030A4), ANIMMODE_LOOP, 0.0f); this->unk_318 = 0; this->unk_2D4 = -1; Actor_SetScale(&this->actor, 0.01f); diff --git a/mm/src/overlays/actors/ovl_En_Tru/z_en_tru.c b/mm/src/overlays/actors/ovl_En_Tru/z_en_tru.c index 60e5d6ff1..ba5b9aa98 100644 --- a/mm/src/overlays/actors/ovl_En_Tru/z_en_tru.c +++ b/mm/src/overlays/actors/ovl_En_Tru/z_en_tru.c @@ -151,7 +151,7 @@ ActorInit En_Tru_InitVars = { /**/ EnTru_Draw, }; -#include "overlays/ovl_En_Tru/ovl_En_Tru.c" +#include "overlays/ovl_En_Tru/ovl_En_Tru.h" static Vec3f D_80A8B250 = { 0.0f, 0.02f, 0.0f }; diff --git a/mm/src/overlays/actors/ovl_En_Wf/z_en_wf.c b/mm/src/overlays/actors/ovl_En_Wf/z_en_wf.c index d2f1595cf..51f7b5897 100644 --- a/mm/src/overlays/actors/ovl_En_Wf/z_en_wf.c +++ b/mm/src/overlays/actors/ovl_En_Wf/z_en_wf.c @@ -1026,7 +1026,7 @@ void func_809924EC(EnWf* this, PlayState* play) { void func_809926D0(EnWf* this) { this->collider2.base.acFlags &= ~AC_ON; - Animation_Change(&this->skelAnime, &gWolfosBackflipAnim, -1.0f, Animation_GetLastFrame(&gWolfosBackflipAnim.common), + Animation_Change(&this->skelAnime, &gWolfosBackflipAnim, -1.0f, Animation_GetLastFrame(&gWolfosBackflipAnim), 0.0f, ANIMMODE_ONCE, -3.0f); this->unk_2A0 = 0; this->actor.speed = 6.5f; @@ -1059,7 +1059,7 @@ void func_8099282C(EnWf* this) { this->collider1.base.atFlags &= ~AT_ON; this->unk_2A0 = 10; this->actor.speed = 0.0f; - Animation_Change(&this->skelAnime, &gWolfosBlockAnim, -1.0f, Animation_GetLastFrame(&gWolfosBlockAnim.common), 0.0f, + Animation_Change(&this->skelAnime, &gWolfosBlockAnim, -1.0f, Animation_GetLastFrame(&gWolfosBlockAnim), 0.0f, ANIMMODE_ONCE, -2.0f); this->actionFunc = func_809928CC; } diff --git a/mm/src/overlays/actors/ovl_Obj_Entotu/z_obj_entotu.c b/mm/src/overlays/actors/ovl_Obj_Entotu/z_obj_entotu.c index f76b5a794..e2738b908 100644 --- a/mm/src/overlays/actors/ovl_Obj_Entotu/z_obj_entotu.c +++ b/mm/src/overlays/actors/ovl_Obj_Entotu/z_obj_entotu.c @@ -6,6 +6,7 @@ #include "z_obj_entotu.h" #include "objects/object_f53_obj/object_f53_obj.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20) @@ -17,18 +18,18 @@ void ObjEntotu_Update(Actor* thisx, PlayState* play); void ObjEntotu_Draw(Actor* thisx, PlayState* play); ActorInit Obj_Entotu_InitVars = { - /**/ ACTOR_OBJ_ENTOTU, - /**/ ACTORCAT_PROP, - /**/ FLAGS, - /**/ OBJECT_F53_OBJ, - /**/ sizeof(ObjEntotu), - /**/ ObjEntotu_Init, - /**/ ObjEntotu_Destroy, - /**/ ObjEntotu_Update, - /**/ ObjEntotu_Draw, + ACTOR_OBJ_ENTOTU, + ACTORCAT_PROP, + FLAGS, + OBJECT_F53_OBJ, + sizeof(ObjEntotu), + (ActorFunc)ObjEntotu_Init, + (ActorFunc)ObjEntotu_Destroy, + (ActorFunc)ObjEntotu_Update, + (ActorFunc)ObjEntotu_Draw, }; -#include "overlays/ovl_Obj_Entotu/ovl_Obj_Entotu.c" +#include "overlays/ovl_Obj_Entotu/ovl_Obj_Entotu.h" s32 func_80A34700(s16 minutes) { s32 ret = 0; @@ -112,6 +113,8 @@ void func_80A34A44(ObjEntotu* this, PlayState* play) { CLOSE_DISPS(play->state.gfxCtx); } +static Vtx* ovl_Obj_Entotu_Vtx_000D10Data; + void func_80A34B28(ObjEntotu* this, PlayState* play) { u8 sp57; u8 sp56; @@ -124,8 +127,8 @@ void func_80A34B28(ObjEntotu* this, PlayState* play) { this->unk_1B8.x = CLAMP(this->unk_1B8.x, 0.0f, 1.0f); - for (i = 0; i < ARRAY_COUNT(ovl_Obj_Entotu_Vtx_000D10); i++) { - this->unk_148[i].v.cn[3] = ovl_Obj_Entotu_Vtx_000D10[i].v.cn[3] * this->unk_1B8.x; + for (i = 0; i < ARRAY_COUNT(this->unk_148); i++) { + this->unk_148[i].v.cn[3] = ovl_Obj_Entotu_Vtx_000D10Data[i].v.cn[3] * this->unk_1B8.x; } if (this->unk_1B8.x > 0.0f) { @@ -151,7 +154,10 @@ void func_80A34B28(ObjEntotu* this, PlayState* play) { void ObjEntotu_Init(Actor* thisx, PlayState* play) { ObjEntotu* this = THIS; - Lib_MemCpy(this->unk_148, ovl_Obj_Entotu_Vtx_000D10, sizeof(ovl_Obj_Entotu_Vtx_000D10)); + ovl_Obj_Entotu_Vtx_000D10Data = ResourceMgr_LoadVtxArrayByName(ovl_Obj_Entotu_Vtx_000D10); + + Lib_MemCpy(this->unk_148, ovl_Obj_Entotu_Vtx_000D10Data, + ResourceMgr_GetArraySizeByName(ovl_Obj_Entotu_Vtx_000D10) * sizeof(Vtx)); this->unk_1C6 = Rand_S16Offset(0, 59); this->unk_1C4 = 0; } diff --git a/mm/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c b/mm/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c index 36f8186d9..f64affaa4 100644 --- a/mm/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c +++ b/mm/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c @@ -21,15 +21,15 @@ void ObjEtcetera_DrawIdle(Actor* thisx, PlayState* play); void ObjEtcetera_DrawAnimated(Actor* thisx, PlayState* play); ActorInit Obj_Etcetera_InitVars = { - /**/ ACTOR_OBJ_ETCETERA, - /**/ ACTORCAT_BG, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(ObjEtcetera), - /**/ ObjEtcetera_Init, - /**/ ObjEtcetera_Destroy, - /**/ ObjEtcetera_Update, - /**/ NULL, + ACTOR_OBJ_ETCETERA, + ACTORCAT_BG, + FLAGS, + GAMEPLAY_KEEP, + sizeof(ObjEtcetera), + (ActorFunc)ObjEtcetera_Init, + (ActorFunc)ObjEtcetera_Destroy, + (ActorFunc)ObjEtcetera_Update, + (ActorFunc)NULL, }; static ColliderCylinderInit sCylinderInit = { @@ -280,8 +280,8 @@ void ObjEtcetera_Setup(ObjEtcetera* this, PlayState* play) { case DEKU_FLOWER_TYPE_GOLD: case DEKU_FLOWER_TYPE_GOLD_WITH_INITIAL_BOUNCE: this->dList = gGoldDekuFlowerIdleDL; - SkelAnime_Init(play, &this->skelAnime, &gGoldDekuFlowerSkel.sh, &gDekuFlowerBounceAnim, - this->jointTable, this->morphTable, GOLD_DEKU_FLOWER_LIMB_MAX); + SkelAnime_Init(play, &this->skelAnime, &gGoldDekuFlowerSkel, &gDekuFlowerBounceAnim, this->jointTable, + this->morphTable, GOLD_DEKU_FLOWER_LIMB_MAX); this->collider.dim.height = 20; break; diff --git a/mm/src/overlays/actors/ovl_Obj_Grass/z_obj_grass.c b/mm/src/overlays/actors/ovl_Obj_Grass/z_obj_grass.c index ee845d0bb..5b354607e 100644 --- a/mm/src/overlays/actors/ovl_Obj_Grass/z_obj_grass.c +++ b/mm/src/overlays/actors/ovl_Obj_Grass/z_obj_grass.c @@ -25,7 +25,7 @@ f32 sNearestGrassGroupsDist[OBJ_GRASS_NEAREST_GROUP_MAX]; ObjGrassElement* sNearestGrassElements[OBJ_GRASS_NEAREST_ELEM_MAX]; f32 sNearestGrassElementsDistSq[OBJ_GRASS_NEAREST_ELEM_MAX]; -#include "overlays/ovl_Obj_Grass/ovl_Obj_Grass.c" +#include "overlays/ovl_Obj_Grass/ovl_Obj_Grass.h" ActorInit Obj_Grass_InitVars = { /**/ ACTOR_OBJ_GRASS, diff --git a/mm/src/overlays/actors/ovl_Obj_Jgame_Light/z_obj_jgame_light.c b/mm/src/overlays/actors/ovl_Obj_Jgame_Light/z_obj_jgame_light.c index bd88548e2..69c40c678 100644 --- a/mm/src/overlays/actors/ovl_Obj_Jgame_Light/z_obj_jgame_light.c +++ b/mm/src/overlays/actors/ovl_Obj_Jgame_Light/z_obj_jgame_light.c @@ -59,7 +59,7 @@ static ColliderCylinderInit sCylinderInit = { { 12, 45, 0, { 0, 0, 0 } }, }; -#include "assets/overlays/ovl_Obj_Jgame_Light/ovl_Obj_Jgame_Light.c" +#include "assets/overlays/ovl_Obj_Jgame_Light/ovl_Obj_Jgame_Light.h" void ObjJgameLight_Init(Actor* thisx, PlayState* play) { ObjJgameLight* this = THIS; diff --git a/mm/src/overlays/actors/ovl_Obj_Smork/z_obj_smork.c b/mm/src/overlays/actors/ovl_Obj_Smork/z_obj_smork.c index 765fd8389..922f298b8 100644 --- a/mm/src/overlays/actors/ovl_Obj_Smork/z_obj_smork.c +++ b/mm/src/overlays/actors/ovl_Obj_Smork/z_obj_smork.c @@ -6,6 +6,7 @@ #include "z_obj_smork.h" #include "objects/object_f53_obj/object_f53_obj.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_20) @@ -17,18 +18,20 @@ void ObjSmork_Update(Actor* thisx, PlayState* play); void ObjSmork_Draw(Actor* thisx, PlayState* play); ActorInit Obj_Smork_InitVars = { - /**/ ACTOR_OBJ_SMORK, - /**/ ACTORCAT_PROP, - /**/ FLAGS, - /**/ OBJECT_F53_OBJ, - /**/ sizeof(ObjSmork), - /**/ ObjSmork_Init, - /**/ ObjSmork_Destroy, - /**/ ObjSmork_Update, - /**/ ObjSmork_Draw, + ACTOR_OBJ_SMORK, + ACTORCAT_PROP, + FLAGS, + OBJECT_F53_OBJ, + sizeof(ObjSmork), + (ActorFunc)ObjSmork_Init, + (ActorFunc)ObjSmork_Destroy, + (ActorFunc)ObjSmork_Update, + (ActorFunc)ObjSmork_Draw, }; -#include "overlays/ovl_Obj_Smork/ovl_Obj_Smork.c" +#include "overlays/ovl_Obj_Smork/ovl_Obj_Smork.h" + +static Vtx* ovl_Obj_Smork_Vtx_000C10Data; u8 func_80A3D680(s16 arg0) { u8 ret = 0; @@ -104,7 +107,7 @@ void func_80A3D9C4(ObjSmork* this, PlayState* play) { this->unk_1B8 = CLAMP(this->unk_1B8, 0.0f, 1.0f); for (i = 0; i < ARRAY_COUNT(this->unk_148); i++) { - this->unk_148[i].v.cn[3] = ovl_Obj_Smork_Vtx_000C10[i].v.cn[3] * this->unk_1B8; + this->unk_148[i].v.cn[3] = ovl_Obj_Smork_Vtx_000C10Data[i].v.cn[3] * this->unk_1B8; } if (this->unk_1B8 > 0.0f) { @@ -129,8 +132,10 @@ void func_80A3D9C4(ObjSmork* this, PlayState* play) { void ObjSmork_Init(Actor* thisx, PlayState* play) { ObjSmork* this = THIS; + ovl_Obj_Smork_Vtx_000C10Data = ResourceMgr_LoadVtxArrayByName(ovl_Obj_Smork_Vtx_000C10); - Lib_MemCpy(this->unk_148, ovl_Obj_Smork_Vtx_000C10, sizeof(Vtx) * ARRAY_COUNT(ovl_Obj_Smork_Vtx_000C10)); + Lib_MemCpy(this->unk_148, ovl_Obj_Smork_Vtx_000C10, + sizeof(Vtx) * ResourceMgr_GetArraySizeByName(ovl_Obj_Smork_Vtx_000C10)); this->unk_1C6 = Rand_S16Offset(0, 59); this->unk_1C4 = 0; } diff --git a/mm/src/overlays/actors/ovl_Obj_Sound/z_obj_sound.c b/mm/src/overlays/actors/ovl_Obj_Sound/z_obj_sound.c index 51295590a..d7a285c15 100644 --- a/mm/src/overlays/actors/ovl_Obj_Sound/z_obj_sound.c +++ b/mm/src/overlays/actors/ovl_Obj_Sound/z_obj_sound.c @@ -48,6 +48,8 @@ void ObjSound_Destroy(Actor* thisx, PlayState* play) { } void ObjSound_Update(Actor* thisx, PlayState* play) { + // BENTODO: stub audio code that crashes +#if 0 ObjSound* this = THIS; if (this->soundType == OBJ_SOUND_TYPE_SFX) { @@ -65,6 +67,7 @@ void ObjSound_Update(Actor* thisx, PlayState* play) { } else { this->unk_144 = true; } +#endif } void ObjSound_Draw(Actor* thisx, PlayState* play) { diff --git a/mm/src/overlays/actors/ovl_Obj_Toudai/z_obj_toudai.c b/mm/src/overlays/actors/ovl_Obj_Toudai/z_obj_toudai.c index 7c0809096..51c57f3d7 100644 --- a/mm/src/overlays/actors/ovl_Obj_Toudai/z_obj_toudai.c +++ b/mm/src/overlays/actors/ovl_Obj_Toudai/z_obj_toudai.c @@ -16,19 +16,23 @@ void ObjToudai_Destroy(Actor* thisx, PlayState* play); void ObjToudai_Update(Actor* thisx, PlayState* play); void ObjToudai_Draw(Actor* thisx, PlayState* play); +#include "BenPort.h" + ActorInit Obj_Toudai_InitVars = { - /**/ ACTOR_OBJ_TOUDAI, - /**/ ACTORCAT_PROP, - /**/ FLAGS, - /**/ OBJECT_F53_OBJ, - /**/ sizeof(ObjToudai), - /**/ ObjToudai_Init, - /**/ ObjToudai_Destroy, - /**/ ObjToudai_Update, - /**/ ObjToudai_Draw, + ACTOR_OBJ_TOUDAI, + ACTORCAT_PROP, + FLAGS, + OBJECT_F53_OBJ, + sizeof(ObjToudai), + (ActorFunc)ObjToudai_Init, + (ActorFunc)ObjToudai_Destroy, + (ActorFunc)ObjToudai_Update, + (ActorFunc)ObjToudai_Draw, }; -#include "assets/overlays/ovl_Obj_Toudai/ovl_Obj_Toudai.c" +#include "assets/overlays/ovl_Obj_Toudai/ovl_Obj_Toudai.h" + +static Vtx* ovl_Obj_Toudai_Vtx_D_80A34590data; void func_80A33B00(ObjToudai* this, PlayState* play) { Matrix_Translate(this->actor.world.pos.x, this->actor.world.pos.y, this->actor.world.pos.z, MTXMODE_NEW); @@ -56,8 +60,8 @@ void func_80A33BB4(ObjToudai* this, PlayState* play) { this->unk_228 = CLAMP(this->unk_228, 0.0f, 1.0f); - for (i = 0; i < ARRAY_COUNT(ovl_Obj_Toudai_Vtx_D_80A34590); i++) { - this->unk_148[i].v.cn[3] = ovl_Obj_Toudai_Vtx_D_80A34590[i].v.cn[3] * this->unk_228; + for (i = 0; i < ResourceMgr_GetArraySizeByName(ovl_Obj_Toudai_Vtx_D_80A34590); i++) { + this->unk_148[i].v.cn[3] = ovl_Obj_Toudai_Vtx_D_80A34590data[i].v.cn[3] * this->unk_228; } if (this->unk_228 > 0.0f) { @@ -100,6 +104,7 @@ u8 func_80A342F4(s16 arg0) { void ObjToudai_Init(Actor* thisx, PlayState* play) { ObjToudai* this = THIS; + ovl_Obj_Toudai_Vtx_D_80A34590data = ResourceMgr_LoadVtxByName(ovl_Obj_Toudai_Vtx_D_80A34590data); Lib_MemCpy(this->unk_148, &ovl_Obj_Toudai_Vtx_D_80A34590, sizeof(ovl_Obj_Toudai_Vtx_D_80A34590)); } diff --git a/mm/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c b/mm/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c index 7414effc3..0b26f765a 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c +++ b/mm/src/overlays/actors/ovl_Oceff_Spot/z_oceff_spot.c @@ -33,7 +33,7 @@ ActorInit Oceff_Spot_InitVars = { /**/ OceffSpot_Draw, }; -#include "assets/overlays/ovl_Oceff_Spot/ovl_Oceff_Spot.c" +#include "assets/overlays/ovl_Oceff_Spot/ovl_Oceff_Spot.h" static InitChainEntry sInitChain[] = { ICHAIN_VEC3F_DIV1000(scale, 0, ICHAIN_CONTINUE), diff --git a/mm/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c b/mm/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c index 4ec6e05aa..18a3a2d44 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c +++ b/mm/src/overlays/actors/ovl_Oceff_Storm/z_oceff_storm.c @@ -168,7 +168,7 @@ void OceffStorm_Update(Actor* thisx, PlayState* play) { this->actionFunc(this, play); } -#include "assets/overlays/ovl_Oceff_Storm/ovl_Oceff_Storm.c" +#include "assets/overlays/ovl_Oceff_Storm/ovl_Oceff_Storm.h" void OceffStorm_Draw2(Actor* thisx, PlayState* play) { s32 scroll = play->state.frames & 0xFFF; diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c b/mm/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c index 66d650564..71453acd6 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe/z_oceff_wipe.c @@ -16,15 +16,15 @@ void OceffWipe_Update(Actor* thisx, PlayState* play); void OceffWipe_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe_InitVars = { - /**/ ACTOR_OCEFF_WIPE, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe), - /**/ OceffWipe_Init, - /**/ OceffWipe_Destroy, - /**/ OceffWipe_Update, - /**/ OceffWipe_Draw, + ACTOR_OCEFF_WIPE, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe), + (ActorFunc)OceffWipe_Init, + (ActorFunc)OceffWipe_Destroy, + (ActorFunc)OceffWipe_Update, + (ActorFunc)OceffWipe_Draw, }; UNK_TYPE4 D_80977200; @@ -55,7 +55,7 @@ void OceffWipe_Update(Actor* thisx, PlayState* play) { } } -#include "assets/overlays/ovl_Oceff_Wipe/ovl_Oceff_Wipe.c" +#include "assets/overlays/ovl_Oceff_Wipe/ovl_Oceff_Wipe.h" static u8 sAlphaIndices[] = { 0x01, 0x10, 0x22, 0x01, 0x20, 0x12, 0x01, 0x20, 0x12, 0x01, @@ -71,7 +71,9 @@ void OceffWipe_Draw(Actor* thisx, PlayState* play) { s32 i; Vec3f eye = GET_ACTIVE_CAM(play)->eye; Vtx* vtxPtr; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; + + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); OPEN_DISPS(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c b/mm/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c index f87f4b8ef..6340b90ae 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe2/z_oceff_wipe2.c @@ -16,18 +16,18 @@ void OceffWipe2_Update(Actor* thisx, PlayState* play); void OceffWipe2_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe2_InitVars = { - /**/ ACTOR_OCEFF_WIPE2, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe2), - /**/ OceffWipe2_Init, - /**/ OceffWipe2_Destroy, - /**/ OceffWipe2_Update, - /**/ OceffWipe2_Draw, + ACTOR_OCEFF_WIPE2, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe2), + (ActorFunc)OceffWipe2_Init, + (ActorFunc)OceffWipe2_Destroy, + (ActorFunc)OceffWipe2_Update, + (ActorFunc)OceffWipe2_Draw, }; -#include "assets/overlays/ovl_Oceff_Wipe2/ovl_Oceff_Wipe2.c" +#include "assets/overlays/ovl_Oceff_Wipe2/ovl_Oceff_Wipe2.h" s32 D_809879D0; @@ -65,7 +65,9 @@ void OceffWipe2_Draw(Actor* thisx, PlayState* play) { s32 pad[2]; Vec3f eye = GET_ACTIVE_CAM(play)->eye; Vtx* vtxPtr; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; + + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); vtxPtr = sEponaSongFrustumVtx; diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c b/mm/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c index d1564d7e1..de1a63f59 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe3/z_oceff_wipe3.c @@ -17,18 +17,18 @@ void OceffWipe3_Update(Actor* thisx, PlayState* play); void OceffWipe3_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe3_InitVars = { - /**/ ACTOR_OCEFF_WIPE3, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe3), - /**/ OceffWipe3_Init, - /**/ OceffWipe3_Destroy, - /**/ OceffWipe3_Update, - /**/ OceffWipe3_Draw, + ACTOR_OCEFF_WIPE3, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe3), + (ActorFunc)OceffWipe3_Init, + (ActorFunc)OceffWipe3_Destroy, + (ActorFunc)OceffWipe3_Update, + (ActorFunc)OceffWipe3_Draw, }; -#include "assets/overlays/ovl_Oceff_Wipe3/ovl_Oceff_Wipe3.c" +#include "assets/overlays/ovl_Oceff_Wipe3/ovl_Oceff_Wipe3.h" s32 D_80989130; @@ -66,7 +66,9 @@ void OceffWipe3_Draw(Actor* thisx, PlayState* play) { s32 pad[2]; Vec3f eye = GET_ACTIVE_CAM(play)->eye; Vtx* vtxPtr; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; + + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); vtxPtr = sSariaSongFrustumVtx; diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c b/mm/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c index 7f5f43fee..33ceaae39 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe4/z_oceff_wipe4.c @@ -16,18 +16,18 @@ void OceffWipe4_Update(Actor* thisx, PlayState* play); void OceffWipe4_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe4_InitVars = { - /**/ ACTOR_OCEFF_WIPE4, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe4), - /**/ OceffWipe4_Init, - /**/ OceffWipe4_Destroy, - /**/ OceffWipe4_Update, - /**/ OceffWipe4_Draw, + ACTOR_OCEFF_WIPE4, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe4), + (ActorFunc)OceffWipe4_Init, + (ActorFunc)OceffWipe4_Destroy, + (ActorFunc)OceffWipe4_Update, + (ActorFunc)OceffWipe4_Draw, }; -#include "assets/overlays/ovl_Oceff_Wipe4/ovl_Oceff_Wipe4.c" +#include "assets/overlays/ovl_Oceff_Wipe4/ovl_Oceff_Wipe4.h" s32 D_8099E780; @@ -65,7 +65,9 @@ void OceffWipe4_Draw(Actor* thisx, PlayState* play) { s32 pad[2]; Vec3f eye = GET_ACTIVE_CAM(play)->eye; Vtx* vtxPtr; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; + + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); if (this->counter < 16) { z = Math_SinS(this->counter * 0x400) * 1220.0f; diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe5/z_oceff_wipe5.c b/mm/src/overlays/actors/ovl_Oceff_Wipe5/z_oceff_wipe5.c index 43542180a..16609edc5 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe5/z_oceff_wipe5.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe5/z_oceff_wipe5.c @@ -5,6 +5,7 @@ */ #include "z_oceff_wipe5.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_2000000) @@ -16,15 +17,15 @@ void OceffWipe5_Update(Actor* thisx, PlayState* play); void OceffWipe5_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe5_InitVars = { - /**/ ACTOR_OCEFF_WIPE5, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe5), - /**/ OceffWipe5_Init, - /**/ OceffWipe5_Destroy, - /**/ OceffWipe5_Update, - /**/ OceffWipe5_Draw, + ACTOR_OCEFF_WIPE5, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe5), + (ActorFunc)OceffWipe5_Init, + (ActorFunc)OceffWipe5_Destroy, + (ActorFunc)OceffWipe5_Update, + (ActorFunc)OceffWipe5_Draw, }; UNK_TYPE4 D_80BC9260; @@ -37,8 +38,11 @@ void OceffWipe5_Init(Actor* thisx, PlayState* play) { this->actor.world.pos = play->cameraPtrs[play->activeCamId]->eye; } +static Vtx* gOceff5VtxData; + void OceffWipe5_Destroy(Actor* thisx, PlayState* play) { OceffWipe5* this = THIS; + gOceff5VtxData = ResourceMgr_LoadArrayByName(gOceff5VtxData); Magic_Reset(play); play->msgCtx.ocarinaSongEffectActive = false; @@ -55,7 +59,7 @@ void OceffWipe5_Update(Actor* thisx, PlayState* play) { } } -#include "assets/overlays/ovl_Oceff_Wipe5/ovl_Oceff_Wipe5.c" +#include "assets/overlays/ovl_Oceff_Wipe5/ovl_Oceff_Wipe5.h" static u8 sPrimColors[] = { 255, 255, 200, 255, 255, 200, 200, 255, 255, 255, 255, 200, 255, 200, 255, @@ -101,8 +105,9 @@ void OceffWipe5_Draw(Actor* thisx, PlayState* play) { } else { alpha = 255; } - for (i = 1; i < ARRAY_COUNT(gOceff5Vtx); i += 2) { - gOceff5Vtx[i].v.cn[3] = alpha; + + for (i = 1; i < ResourceMgr_GetArraySizeByName(gOceff5Vtx); i += 2) { + gOceff5VtxData[i].v.cn[3] = alpha; } OPEN_DISPS(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe6/z_oceff_wipe6.c b/mm/src/overlays/actors/ovl_Oceff_Wipe6/z_oceff_wipe6.c index 0bf8d89d0..c3e2e4655 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe6/z_oceff_wipe6.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe6/z_oceff_wipe6.c @@ -5,6 +5,7 @@ */ #include "z_oceff_wipe6.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_2000000) @@ -16,22 +17,25 @@ void OceffWipe6_Update(Actor* thisx, PlayState* play); void OceffWipe6_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe6_InitVars = { - /**/ ACTOR_OCEFF_WIPE6, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe6), - /**/ OceffWipe6_Init, - /**/ OceffWipe6_Destroy, - /**/ OceffWipe6_Update, - /**/ OceffWipe6_Draw, + ACTOR_OCEFF_WIPE6, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe6), + (ActorFunc)OceffWipe6_Init, + (ActorFunc)OceffWipe6_Destroy, + (ActorFunc)OceffWipe6_Update, + (ActorFunc)OceffWipe6_Draw, }; -#include "overlays/ovl_Oceff_Wipe6/ovl_Oceff_Wipe6.c" +#include "overlays/ovl_Oceff_Wipe6/ovl_Oceff_Wipe6.h" +Vtx* gOceff6VtxData; void OceffWipe6_Init(Actor* thisx, PlayState* play) { OceffWipe6* this = THIS; + gOceff6VtxData = ResourceMgr_LoadArrayByName(gOceff6Vtx); + Actor_SetScale(&this->actor, 1.0f); this->counter = 0; this->actor.world.pos = GET_ACTIVE_CAM(play)->eye; @@ -59,11 +63,14 @@ void OceffWipe6_Draw(Actor* thisx, PlayState* play) { u8 alpha; s32 i; s32 counter; - Vec3f activeCamEye = GET_ACTIVE_CAM(play)->eye; + Vec3f activeCamEye; s32 pad; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; s32 pad2; + activeCamEye = GET_ACTIVE_CAM(play)->eye; + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + if (this->counter < 32) { counter = this->counter; z = Math_SinS(counter * 0x200) * 1220.0f; @@ -77,8 +84,8 @@ void OceffWipe6_Draw(Actor* thisx, PlayState* play) { alpha = 255; } - for (i = 1; i < ARRAY_COUNT(gOceff6Vtx); i += 2) { - gOceff6Vtx[i].v.cn[3] = alpha; + for (i = 1; i < ResourceMgr_GetArraySizeByName(gOceff6Vtx); i += 2) { + gOceff6VtxData[i].v.cn[3] = alpha; } OPEN_DISPS(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_Oceff_Wipe7/z_oceff_wipe7.c b/mm/src/overlays/actors/ovl_Oceff_Wipe7/z_oceff_wipe7.c index 81c32a5e5..072aca957 100644 --- a/mm/src/overlays/actors/ovl_Oceff_Wipe7/z_oceff_wipe7.c +++ b/mm/src/overlays/actors/ovl_Oceff_Wipe7/z_oceff_wipe7.c @@ -5,6 +5,7 @@ */ #include "z_oceff_wipe7.h" +#include "BenPort.h" #define FLAGS (ACTOR_FLAG_10 | ACTOR_FLAG_2000000) @@ -16,23 +17,26 @@ void OceffWipe7_Update(Actor* thisx, PlayState* play); void OceffWipe7_Draw(Actor* thisx, PlayState* play); ActorInit Oceff_Wipe7_InitVars = { - /**/ ACTOR_OCEFF_WIPE7, - /**/ ACTORCAT_ITEMACTION, - /**/ FLAGS, - /**/ GAMEPLAY_KEEP, - /**/ sizeof(OceffWipe7), - /**/ OceffWipe7_Init, - /**/ OceffWipe7_Destroy, - /**/ OceffWipe7_Update, - /**/ OceffWipe7_Draw, + ACTOR_OCEFF_WIPE7, + ACTORCAT_ITEMACTION, + FLAGS, + GAMEPLAY_KEEP, + sizeof(OceffWipe7), + (ActorFunc)OceffWipe7_Init, + (ActorFunc)OceffWipe7_Destroy, + (ActorFunc)OceffWipe7_Update, + (ActorFunc)OceffWipe7_Draw, }; -#include "assets/overlays/ovl_Oceff_Wipe7/ovl_Oceff_Wipe7.c" +#include "assets/overlays/ovl_Oceff_Wipe7/ovl_Oceff_Wipe7.h" s32 D_80BCEB10; +static Vtx* sSongofHealingEffectFrustrumVtxData; + void OceffWipe7_Init(Actor* thisx, PlayState* play) { OceffWipe7* this = THIS; + sSongofHealingEffectFrustrumVtxData = ResourceMgr_LoadVtxByName(sSongofHealingEffectFrustrumVtx); Actor_SetScale(&this->actor, 1.0f); this->counter = 0; @@ -65,9 +69,11 @@ void OceffWipe7_Draw(Actor* thisx, PlayState* play) { s32 counter; Vec3f activeCamEye = GET_ACTIVE_CAM(play)->eye; s32 pad; - Vec3f quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + Vec3f quakeOffset; s32 pad2; + quakeOffset = Camera_GetQuakeOffset(GET_ACTIVE_CAM(play)); + if (this->counter < 32) { z = Math_SinS(this->counter * 0x200) * 1220.0f; } else { @@ -80,8 +86,8 @@ void OceffWipe7_Draw(Actor* thisx, PlayState* play) { alpha = 255; } - for (i = 1; i < ARRAY_COUNT(sSongofHealingEffectFrustrumVtx); i += 2) { - sSongofHealingEffectFrustrumVtx[i].v.cn[3] = alpha; + for (i = 1; i < ResourceMgr_GetArraySizeByName(sSongofHealingEffectFrustrumVtx); i += 2) { + sSongofHealingEffectFrustrumVtxData[i].v.cn[3] = alpha; } OPEN_DISPS(play->state.gfxCtx); diff --git a/mm/src/overlays/actors/ovl_player_actor/z_player.c b/mm/src/overlays/actors/ovl_player_actor/z_player.c index 00204c6eb..a06efff90 100644 --- a/mm/src/overlays/actors/ovl_player_actor/z_player.c +++ b/mm/src/overlays/actors/ovl_player_actor/z_player.c @@ -1780,6 +1780,8 @@ u16 D_8085C3EC[] = { }; void func_8082E00C(Player* this) { + return; + // BENTODO s32 i; u16* sfxIdPtr = D_8085C3EC; @@ -7312,7 +7314,7 @@ void func_80838830(Player* this, s16 objectId) { osCreateMesgQueue(&this->giObjectLoadQueue, &this->giObjectLoadMsg, 1); DmaMgr_SendRequestImpl(&this->giObjectDmaRequest, this->giObjectSegment, gObjectTable[objectId].vromStart, gObjectTable[objectId].vromEnd - gObjectTable[objectId].vromStart, 0, - &this->giObjectLoadQueue, NULL); + &this->giObjectLoadQueue, OS_MESG_PTR(NULL)); } } @@ -8196,7 +8198,8 @@ void func_8083A98C(Actor* thisx, PlayState* play2) { // Show controls overlay. SCENE_AYASHIISHOP does not have Zoom, so has a different one. if (this->av2.actionVar2 == 1) { - Message_StartTextbox(play, (play->sceneId == SCENE_AYASHIISHOP) ? 0x2A00 : 0x5E6, NULL); + // BENTODO: crash when going back from telescope in astral observatory + // Message_StartTextbox(play, (play->sceneId == SCENE_AYASHIISHOP) ? 0x2A00 : 0x5E6, NULL); } } else { sPlayerControlInput = play->state.input; diff --git a/mm/src/overlays/effects/ovl_Effect_Ss_Fhg_Flash/z_eff_ss_fhg_flash.c b/mm/src/overlays/effects/ovl_Effect_Ss_Fhg_Flash/z_eff_ss_fhg_flash.c index 6ab2f2b78..24afb7acb 100644 --- a/mm/src/overlays/effects/ovl_Effect_Ss_Fhg_Flash/z_eff_ss_fhg_flash.c +++ b/mm/src/overlays/effects/ovl_Effect_Ss_Fhg_Flash/z_eff_ss_fhg_flash.c @@ -50,7 +50,7 @@ u32 EffectSsFhgFlash_Init(PlayState* play, u32 index, EffectSs* this, void* init return 1; } -#include "overlays/ovl_Effect_Ss_Fhg_Flash/ovl_Effect_Ss_Fhg_Flash.c" +#include "overlays/ovl_Effect_Ss_Fhg_Flash/ovl_Effect_Ss_Fhg_Flash.h" void EffectSsFhgFlash_Draw(PlayState* play, u32 index, EffectSs* this) { s32 pad; diff --git a/mm/src/overlays/fbdemos/ovl_fbdemo_triforce/z_fbdemo_triforce.c b/mm/src/overlays/fbdemos/ovl_fbdemo_triforce/z_fbdemo_triforce.c index cf1000add..1a991d56f 100644 --- a/mm/src/overlays/fbdemos/ovl_fbdemo_triforce/z_fbdemo_triforce.c +++ b/mm/src/overlays/fbdemos/ovl_fbdemo_triforce/z_fbdemo_triforce.c @@ -6,7 +6,7 @@ #include "global.h" #include "z_fbdemo_triforce.h" -#include "assets/overlays/ovl_fbdemo_triforce/ovl_fbdemo_triforce.c" +#include "assets/overlays/ovl_fbdemo_triforce/ovl_fbdemo_triforce.h" void* TransitionTriforce_Init(void* thisx); void TransitionTriforce_Destroy(void* thisx); diff --git a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe1/z_fbdemo_wipe1.c b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe1/z_fbdemo_wipe1.c index 94285c45b..070a4a1aa 100644 --- a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe1/z_fbdemo_wipe1.c +++ b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe1/z_fbdemo_wipe1.c @@ -19,7 +19,7 @@ void TransitionWipe1_SetColor(void* thisx, u32 color); void TransitionWipe1_SetEnvColor(void* thisx, u32 color); s32 TransitionWipe1_IsDone(void* thisx); -#include "assets/overlays/ovl_fbdemo_wipe1/ovl_fbdemo_wipe1.c" +#include "assets/overlays/ovl_fbdemo_wipe1/ovl_fbdemo_wipe1.h" TransitionInit TransitionWipe1_InitVars = { TransitionWipe1_Init, TransitionWipe1_Destroy, TransitionWipe1_Update, diff --git a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe3/z_fbdemo_wipe3.c b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe3/z_fbdemo_wipe3.c index 543fc6e08..15a5be19f 100644 --- a/mm/src/overlays/fbdemos/ovl_fbdemo_wipe3/z_fbdemo_wipe3.c +++ b/mm/src/overlays/fbdemos/ovl_fbdemo_wipe3/z_fbdemo_wipe3.c @@ -19,7 +19,7 @@ void TransitionWipe3_SetColor(void* thisx, u32 color); void TransitionWipe3_SetEnvColor(void* thisx, u32 color); s32 TransitionWipe3_IsDone(void* thisx); -#include "assets/overlays/ovl_fbdemo_wipe3/ovl_fbdemo_wipe3.c" +#include "assets/overlays/ovl_fbdemo_wipe3/ovl_fbdemo_wipe3.h" TexturePtr sTransWipe3Textures[] = { fbdemo_tex_000520, fbdemo_tex_000920, fbdemo_tex_000D20, fbdemo_tex_001120, diff --git a/mm/src/overlays/gamestates/ovl_file_choose/z_file_choose_NES.c b/mm/src/overlays/gamestates/ovl_file_choose/z_file_choose_NES.c index fa1edaf6b..7b506e8b6 100644 --- a/mm/src/overlays/gamestates/ovl_file_choose/z_file_choose_NES.c +++ b/mm/src/overlays/gamestates/ovl_file_choose/z_file_choose_NES.c @@ -929,7 +929,7 @@ void FileSelect_SetWindowContentVtx(GameState* thisx) { // x-coord (left) this->windowContentVtx[vtxId + 0].v.ob[0] = this->windowContentVtx[vtxId + 2].v.ob[0] = - D_80814280[*ptr] + posX; + D_80814280[spA4[i]] + posX; // x-coord (right) this->windowContentVtx[vtxId + 1].v.ob[0] = this->windowContentVtx[vtxId + 3].v.ob[0] = this->windowContentVtx[vtxId + 0].v.ob[0] + D_80814628[i]; @@ -2404,7 +2404,7 @@ void FileSelect_Main(GameState* thisx) { gDPPipeSync(POLY_OPA_DISP++); gSPDisplayList(POLY_OPA_DISP++, sScreenFillSetupDL); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, this->screenFillAlpha); - gSPDisplayList(POLY_OPA_DISP++, D_0E000000.fillRect); + gSPDisplayList(POLY_OPA_DISP++, 0x0E000000 + ((uintptr_t)&D_0E000000.fillRect - (uintptr_t)&D_0E000000) + 1); CLOSE_DISPS(this->state.gfxCtx); } diff --git a/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_NES.c b/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_NES.c index 005fc7eb9..a78d0de45 100644 --- a/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_NES.c +++ b/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_NES.c @@ -39,11 +39,13 @@ s16 D_80814280[] = { s16 D_80814304[] = { 1, 2, 0, 1, 1, 2, 1, 1, 4, 2, 2, 2, 1, 1, 0, 2, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 4, 3, 2, 4, 1, 2, 2, 1, 1, 2, 2, 3, 2, 2, 0, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 3, + 0 }; s16 D_80814384[] = { 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0 }; s16 D_80814404[] = { diff --git a/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c b/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c index 47619b66d..a65655118 100644 --- a/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c +++ b/mm/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c @@ -1,7 +1,7 @@ #include "z_file_select.h" // Vtx Data -#include "overlays/ovl_file_choose/ovl_file_choose.c" +#include "overlays/ovl_file_choose/ovl_file_choose.h" u8 D_808141F0[] = { // 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' diff --git a/mm/src/overlays/gamestates/ovl_select/z_select.c b/mm/src/overlays/gamestates/ovl_select/z_select.c index 7a79da010..219ffe8c3 100644 --- a/mm/src/overlays/gamestates/ovl_select/z_select.c +++ b/mm/src/overlays/gamestates/ovl_select/z_select.c @@ -9,23 +9,30 @@ #include "z64view.h" #include "libc/alloca.h" #include "overlays/gamestates/ovl_title/z_title.h" +#include "overlays/gamestates/ovl_file_choose/z_file_select.h" void MapSelect_LoadConsoleLogo(MapSelectState* this) { STOP_GAMESTATE(&this->state); SET_NEXT_GAMESTATE(&this->state, ConsoleLogo_Init, sizeof(ConsoleLogoState)); + +} + +void MapSelect_LoadFileSelect(MapSelectState* this) { + STOP_GAMESTATE(&this->state); + SET_NEXT_GAMESTATE(&this->state, FileSelect_Init, sizeof(FileSelectState)); } void MapSelect_LoadGame(MapSelectState* this, u32 entrance, s32 spawn) { - if (gSaveContext.fileNum == 0xFF) { + //if (gSaveContext.fileNum == 0xFF) { Sram_InitDebugSave(); - } + //} gSaveContext.buttonStatus[EQUIP_SLOT_B] = BTN_ENABLED; gSaveContext.buttonStatus[EQUIP_SLOT_C_LEFT] = BTN_ENABLED; gSaveContext.buttonStatus[EQUIP_SLOT_C_DOWN] = BTN_ENABLED; gSaveContext.buttonStatus[EQUIP_SLOT_C_RIGHT] = BTN_ENABLED; gSaveContext.buttonStatus[EQUIP_SLOT_A] = BTN_ENABLED; - gSaveContext.hudVisibilityForceButtonAlphasByStatus = false; + gSaveContext.hudVisibilityForceButtonAlphasByStatus = true; gSaveContext.nextHudVisibility = HUD_VISIBILITY_IDLE; gSaveContext.hudVisibility = HUD_VISIBILITY_IDLE; gSaveContext.hudVisibilityTimer = 0; @@ -52,12 +59,14 @@ void MapSelect_LoadGame(MapSelectState* this, u32 entrance, s32 spawn) { gSaveContext.respawn[RESPAWN_MODE_DEKU].entrance = 0xFF; gSaveContext.respawn[RESPAWN_MODE_HUMAN].entrance = 0xFF; gWeatherMode = WEATHER_MODE_CLEAR; + gSaveContext.gameMode = GAMEMODE_NORMAL; STOP_GAMESTATE(&this->state); SET_NEXT_GAMESTATE(&this->state, Play_Init, sizeof(PlayState)); } // "Translation" (Actual name) +#ifdef Z_SELECT_JP static SceneSelectEntry sScenes[] = { // "0: OP Woods for Cutscene Use" (Forest Opening Scene) { " 0:OP" GFXP_KATAKANA "デモ" GFXP_HIRAGANA "ヨウ シンリン", MapSelect_LoadGame, ENTRANCE(CUTSCENE, 0) }, @@ -498,6 +507,448 @@ static SceneSelectEntry sScenes[] = { // "Title" (Title Screen) { "title", (void*)MapSelect_LoadConsoleLogo, 0 }, }; +#else +static SceneSelectEntry sScenes[] = { + + // "55: Laundry Area" (Laundry Pool) + { " 55: Laundry Pool", MapSelect_LoadGame, ENTRANCE(LAUNDRY_POOL, 0) }, + // "11-1: Goron Shrine" (Goron Shrine) + { " 11-1: Goron Shrine", MapSelect_LoadGame, ENTRANCE(GORON_SHRINE, 0) }, + // "1-0: Astral Observatory" (Astral Observatory) + { " 1-0: Astral Observatory", MapSelect_LoadGame, ENTRANCE(ASTRAL_OBSERVATORY, 0) }, + // "0: OP Woods for Cutscene Use" (Forest Opening Scene) + { " 0:OP" + "Forest Opening", + MapSelect_LoadGame, ENTRANCE(CUTSCENE, 0) }, + + // "0-0: Lost Woods" (Lost Woods) + { " 0-0: Lost Woods", MapSelect_LoadGame, ENTRANCE(LOST_WOODS, 0) }, + + // "1: Town Outskirts" (Termina Field) + { " 1: Termina Field", MapSelect_LoadGame, ENTRANCE(TERMINA_FIELD, 0) }, + + // "1-0: Astral Observatory" (Astral Observatory) + { " 1-0: Astral Observatory", MapSelect_LoadGame, ENTRANCE(ASTRAL_OBSERVATORY, 0) }, + + // "1-1: Astral Observatory Telescope" (Astral Observatory - Telescope) + { " 1-1: Astral Observatory Telescope", MapSelect_LoadGame, ENTRANCE(TERMINA_FIELD, 10) }, + + // "1-2: Ikana Graveyard" (Ikana Canyon Graveyard) + { " 1-2: Ikana Graveyard", MapSelect_LoadGame, ENTRANCE(IKANA_GRAVEYARD, 0) }, + + // "2: Romani Ranch" (Romani Ranch) + { " 2: Romani Ranch", MapSelect_LoadGame, ENTRANCE(ROMANI_RANCH, 0) }, + + // "3: Milk Road" (Milk Road) + { " 3: Milk Road", MapSelect_LoadGame, ENTRANCE(MILK_ROAD, 0) }, + + // "4: Main Building" ("Ranch House) + { " 4: Ranch House", MapSelect_LoadGame, ENTRANCE(RANCH_HOUSE, 1) }, + + // "5: Cow Shed" (Cow Shed) + { " 5: Cow Shed", MapSelect_LoadGame, ENTRANCE(RANCH_HOUSE, 0) }, + + // "6: Cucco Shed" (Cucco Shed) + { " 6: Cucco Shed", MapSelect_LoadGame, ENTRANCE(CUCCO_SHACK, 0) }, + + // "7: Dog Racing Area" (Doggy Racetrack) + { " 7: Doggy Racetrack", MapSelect_LoadGame, ENTRANCE(DOGGY_RACETRACK, 0) }, + + // "8: Gorman Track" (Gorman Track) + { " 8: Gorman Track", MapSelect_LoadGame, ENTRANCE(GORMAN_TRACK, 0) }, + + // "10: Mountain Village -Winter-" (Mountain Village - Winter) + { " 10: Mountain Village (Winter)", MapSelect_LoadGame, ENTRANCE(MOUNTAIN_VILLAGE_WINTER, 0) }, + + // "10-0: Mountain Village -Spring-" (Mountain Village - Spring) + { " 10-0: Mountain Village (Spring)", MapSelect_LoadGame, ENTRANCE(MOUNTAIN_VILLAGE_SPRING, 0) }, + + // "10-1: Mountain Village Blacksmith" (Mountain Smithy) + { " 10-1: Mountain Smithy", MapSelect_LoadGame, ENTRANCE(MOUNTAIN_SMITHY, 0) }, + + // "11: Goron Village -Winter-" (Goron Village - Winter) + { " 11: Goron Village (Winter)", MapSelect_LoadGame, ENTRANCE(GORON_VILLAGE_WINTER, 0) }, + + // "11-0: Goron Village -Spring-" (Goron Village - Spring) + { " 11-0: Goron Village (Spring)", MapSelect_LoadGame, ENTRANCE(GORON_VILLAGE_SPRING, 0) }, + + // "11-1: Goron Shrine" (Goron Shrine) + { " 11-1: Goron Shrine", MapSelect_LoadGame, ENTRANCE(GORON_SHRINE, 0) }, + + // "11-2: Lone Peak Shrine" (Lone Peak Shrine) + { " 11-2: Lone Peak Shrine", MapSelect_LoadGame, ENTRANCE(GROTTOS, 16) }, + + // "11-3: Goron Shop" (Goron Shop) + { " 11-3: Goron Shop", MapSelect_LoadGame, ENTRANCE(GORON_SHOP, 0) }, + + // "12: Snowhead" (Snowhead) + { " 12: Snowhead", MapSelect_LoadGame, ENTRANCE(SNOWHEAD, 0) }, + + // "13: Blizzard Path" (Path to Goron Village - Part 1) + { " 13: Blizzard Path", MapSelect_LoadGame, ENTRANCE(PATH_TO_MOUNTAIN_VILLAGE, 0) }, + + // "14: Snowball Path" (Path to Goron Village - Part 2) + { " 14: Snowball Path", MapSelect_LoadGame, ENTRANCE(PATH_TO_SNOWHEAD, 0) }, + + // "15: Goron Racetrack" (Goron Racetrack) + { " 15: Goron Racetrack", MapSelect_LoadGame, ENTRANCE(GORON_RACETRACK, 0) }, + + // "16: Goron Grave" (Darmani's Grave) + { " 16: Darmain's Grave", MapSelect_LoadGame, ENTRANCE(GORON_GRAVERYARD, 0) }, + + // "17: Snow Field Battle -Winter-" (Path to Goron Village - Winter) + { " 17: Path to Goron Village (Winter)", MapSelect_LoadGame, ENTRANCE(PATH_TO_GORON_VILLAGE_WINTER, 0) }, + + // "17-0: Snow Field Battle -Spring-" (Path to Goron Village - Spring) + { " 17-0: Path to Goron Village (Spring)", MapSelect_LoadGame, ENTRANCE(PATH_TO_GORON_VILLAGE_SPRING, 0) }, + + // "20: Swampland" (Southern Swamp) + { " 20: Southern Swamp", MapSelect_LoadGame, ENTRANCE(SOUTHERN_SWAMP_POISONED, 0) }, + + // "20-0: Swampland - Afterwards" (Southern Swamp - After Odolwa) + { " 20-0: Southern Swamp (Clear)", MapSelect_LoadGame, ENTRANCE(SOUTHERN_SWAMP_CLEARED, 0) }, + + // "20-1: Swamp Tourist Information" (Tourist Information) + { " 20-1: Swamp Tourist Information", MapSelect_LoadGame, ENTRANCE(TOURIST_INFORMATION, 0) }, + + // "20-2: Magic Hags' Potion Shop" (Magic Hags' Potion Shop) + { " 20-2: Magic Hag' Potion Shop", MapSelect_LoadGame, ENTRANCE(MAGIC_HAGS_POTION_SHOP, 0) }, + + // "21: Wood Mountain" (Woodfall) + { " 21: Woodfall", MapSelect_LoadGame, ENTRANCE(WOODFALL, 0) }, + + // "21-0: Deku Princess's Prison" (Deku Princess's Prison Cutscene: Tatl Apologizes) + { " 21-0: Deku Princess Prison", MapSelect_LoadGame, ENTRANCE(WOODFALL_TEMPLE, 1) }, + + // "22: Deku Castle" (Deku Palace) + { " 22: Deku Palace", MapSelect_LoadGame, ENTRANCE(DEKU_PALACE, 0) }, + + // "22-0: Boe Hole 0" (Deku Palace Grotto 0 - Deku Baba & Butterflies, Entrance 1) + { " 22-0: Deku Palace Grotto 0", MapSelect_LoadGame, ENTRANCE(GROTTOS, 6) }, + + // "22-1: Boe Hole 1" (Deku Palace Grotto 1 - Deku Baba & Butterflies, Entrance 2) + { " 22-1: Deku Palace Grotto 1", MapSelect_LoadGame, ENTRANCE(GROTTOS, 14) }, + + // "22-2: Boe Hole 2" (Deku Palace Grotto 2 - Skullwalltula Wall, Lower Entrance) + { " 22-2: Deku Palace Grotto 2", MapSelect_LoadGame, ENTRANCE(GROTTOS, 8) }, + + // "22-3: Boe Hole 3" (Deku Palace Grotto 3 - Skullwalltula Wall, Upper Entrance) + { " 22-3: Deku Palace Grotto 3", MapSelect_LoadGame, ENTRANCE(GROTTOS, 15) }, + + // "22-4: Boe Hole 4" (Deku Palace Grotto 4 - Bean Seller) + { " 22-4: Deku Palace Grotto 4", MapSelect_LoadGame, ENTRANCE(GROTTOS, 12) }, + + // "24: Beast Path" (Road to Swamp) + { " 24: Road to Swamp", MapSelect_LoadGame, ENTRANCE(ROAD_TO_SOUTHERN_SWAMP, 0) }, + + // "24-0: Forest Shooting Gallery" (Swamp Shooting Gallery) + { " 24-0: Swamp Shooting Gallery", MapSelect_LoadGame, ENTRANCE(SWAMP_SHOOTING_GALLERY, 0) }, + + // "25: Deku King's Chamber" (Deku Palace Throne Room) + { " 25: Deku Palace Throne Room", MapSelect_LoadGame, ENTRANCE(DEKU_KINGS_CHAMBER, 0) }, + + // "26: Woods of Mystery" (Woods of Mystery) + { " 26: Woods of Mystery", MapSelect_LoadGame, ENTRANCE(WOODS_OF_MYSTERY, 0) }, + + // "30: Great Bay Coast" (Great Bay Coast - Entrance Area) + { " 30: Great Bay Coast", MapSelect_LoadGame, ENTRANCE(GREAT_BAY_COAST, 0) }, + + // "30-0: Ocean Laboratory" (Marine Research Lab) + { " 30-0: Marine Research Lab", MapSelect_LoadGame, ENTRANCE(MARINE_RESEARCH_LAB, 0) }, + + // "30-1: Fisherman's House" (Fisherman's Hut) + { " 30-1: Fisherman's Hut", MapSelect_LoadGame, ENTRANCE(FISHERMANS_HUT, 0) }, + + // "30-2: Pointed Rock" (Twin Pillars) + { " 30-2: Twil Pillars", MapSelect_LoadGame, ENTRANCE(PINNACLE_ROCK, 0) }, + + // "31: Cape" (Great Bay Coast - River Area) + { " 31: Great Bay Coast Cape", MapSelect_LoadGame, ENTRANCE(ZORA_CAPE, 0) }, + + // "32: Outside of Pirates' Fortress" (Pirates' Fortress - Exterior) + { " 32: Pirates Fortress (Outside)", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_EXTERIOR, 0) }, + + // "32-0: Pirates' Fortress" (Pirates' Fortress - Courtyard) + { " 32-0: Pirates Fortress (Courtyard)", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS, 0) }, + + // "32-1: Pirates' Fortress - Telescope" (Pirates' Fortress - Secret Entrance, Looking Through Telescope) + { " 32-1: Pirates Fortress (Telescope)", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS, 10) }, + + // "32-2: Pirates' Fortress - Interior 0" (Pirates' Fortress - Throne Room) + { " 32-2: Pirates Fortres Interior 0", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 0) }, + + // "32-3: Pirates' Fortress - Interior 1" (Pirates' Fortress - View of Throne Room, Wasp Nest) + { " 32-3: Pirates Fortres Interior 1", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 1) }, + + // "32-4: Pirates' Fortress - Interior 2" (Pirates' Fortress - Tempting Treasure Chest, Leading to 32-5) + { " 32-4: Pirates Fortres Interior 2", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 2) }, + + // "32-5: Pirates' Fortress - Interior 3" (Pirates' Fortress - Zora Egg Room, One Shell Blade) + { " 32-5: Pirates Fortres Interior 3", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 3) }, + + // "32-6: Pirates' Fortress - Interior 4" (Pirates' Fortress - Oil Drum Room, Leading to 32-7) + { " 32-6: Pirates Fortres Interior 4", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 4) }, + + // "32-7: Pirates' Fortress - Interior 5" (Pirates' Fortress - Zora Egg Room, One Shell Blade) + { " 32-7: Pirates Fortres Interior 5", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 5) }, + + // "32-8: Pirates' Fortress - Interior 6" (Pirates' Fortress - Fenced Indoor Walkway, Leading to 32-9) + { " 32-8: Pirates Fortres Interior 6", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 6) }, + + // "32-9: Pirates' Fortress - Interior 7" (Pirates' Fortress - Zora Egg Room, One Desbreko & Treasure Chest) + { " 32-9: Pirates Fortres Interior 7", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 7) }, + + // "32-10: Pirates' Fortress - Interior 8" (Pirates' Fortress - End of Secret Entrance: Telescope Room) + { " 32-10: Pirates Fortres Interior 8", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 8) }, + + // "32-11: Pirates' Fortress - Interior 9" (Pirates' Fortress - Start of Secret Entrance) + { " 32-11: Pirates Fortres Interior 9", MapSelect_LoadGame, ENTRANCE(PIRATES_FORTRESS_INTERIOR, 9) }, + + // "33: Zora Shrine" (Zora Hall) + { " 33: Zora Hall", MapSelect_LoadGame, ENTRANCE(ZORA_HALL, 0) }, + + // "33-0: Zora Shop" (Zora Shop) + { " 33-0: Zora Shop", MapSelect_LoadGame, ENTRANCE(ZORA_HALL_ROOMS, 5) }, + + // "33-1: Zora Waiting Room" (Mikau & Tijo's Room) + { " 33-1: Mikau's Room", MapSelect_LoadGame, ENTRANCE(ZORA_HALL_ROOMS, 0) }, + + // "34: Great Bay" (Great Bay Cutscene: Pirates Approach Temple) + { " 34: Great Bay (Cutscene)", MapSelect_LoadGame, ENTRANCE(GREAT_BAY_CUTSCENE, 0) }, + + // "35: Mountain Stream Above Falls" (Waterfall Rapids) + { " 35: Waterfall Rapids", MapSelect_LoadGame, ENTRANCE(WATERFALL_RAPIDS, 0) }, + + // "40: Rock Building Shaft" (Stone Tower) + { " 40: Stone Tower", MapSelect_LoadGame, ENTRANCE(STONE_TOWER, 0) }, + + // "40-0: Heaven & Earth Are Overturned" (Stone Tower Cutscene: Tower is Flipped) + { " 40-0: Inverted Stone Tower", MapSelect_LoadGame, ENTRANCE(STONE_TOWER_INVERTED, 0) }, + + // "41: Road to Ikana" (Road to Ikana) + { " 41: Road to Ikana", MapSelect_LoadGame, ENTRANCE(ROAD_TO_IKANA, 0) }, + + // "42: Ancient Castle of Ikana" (Ancient Castle of Ikana) + { " 42: Ancient Castle of Ikana", MapSelect_LoadGame, ENTRANCE(IKANA_CASTLE, 0) }, + + // "42-0: Ancient Castle of Ikana - Interior" (Ancient Castle of Ikana - Interior) + { " 42-0: Ancient Castle of Ikana (Interior)", MapSelect_LoadGame, ENTRANCE(IKANA_CASTLE, 3) }, + + // "42-B: Ancient Castle of Ikana - Boss Room" (Ikana King's Throne) + { " 42-B: Ancient Castle of Ikana (Boss)", MapSelect_LoadGame, ENTRANCE(IGOS_DU_IKANAS_LAIR, 0) }, + + // "43: Ikana Canyon" (Ikana Canyon) + { " 43: Ikana Canyon", MapSelect_LoadGame, ENTRANCE(IKANA_CANYON, 0) }, + + // "43-0: Ikana Canyon Cave" (Sharp's Cave) + { " 43-0: Sharp's Cave", MapSelect_LoadGame, ENTRANCE(IKANA_CANYON, 14) }, + + // "43-1: Secom's House" (Sakon's Hideout) + { " 43-1: Sakon's Hideout", MapSelect_LoadGame, ENTRANCE(SAKONS_HIDEOUT, 0) }, + + // "43-2: Music Box House" (Music Box House) + { " 43-2: Music House", MapSelect_LoadGame, ENTRANCE(MUSIC_BOX_HOUSE, 0) }, + + // "50: Clock Town -East-" (East Clock Town) + { " 50: East Clock Town", MapSelect_LoadGame, ENTRANCE(EAST_CLOCK_TOWN, 0) }, + + // "50-0: Town Target Range" (Shooting Gallery) + { " 50-0: Shooting Gallery", MapSelect_LoadGame, ENTRANCE(TOWN_SHOOTING_GALLERY, 0) }, + + // "50-1: Honey and Darling's Shop" (Honey & Darling's Shop) + { " 50-1: Honey and Darling's Shop", MapSelect_LoadGame, ENTRANCE(HONEY_AND_DARLINGS_SHOP, 0) }, + + // "50-2: Treasure Chest Shop" (Treasure Chest Shop) + { " 50-2: Treasure Chest Shop", MapSelect_LoadGame, ENTRANCE(TREASURE_CHEST_SHOP, 0) }, + + // "50-3: Pots 'n' Pans Inn" (Stockpot Inn) + { " 50-3: Stockpot Inn", MapSelect_LoadGame, ENTRANCE(STOCK_POT_INN, 0) }, + + // "50-4: Mayor's House" (The Mayor's Residence) + { " 50-4: Mayor's Residence", MapSelect_LoadGame, ENTRANCE(MAYORS_RESIDENCE, 0) }, + + // "50-5: Milk Bar" (Milk Bar) + { " 50-5: Milk Bar", MapSelect_LoadGame, ENTRANCE(MILK_BAR, 0) }, + + // "51: Clock Town -West-" (West Clock Town) + { " 51: West Clock Town", MapSelect_LoadGame, ENTRANCE(WEST_CLOCK_TOWN, 0) }, + + // "51-0: Bomb Shop" (Bomb Shop) + { " 51-0: Bomb Shop", MapSelect_LoadGame, ENTRANCE(BOMB_SHOP, 0) }, + + // "51-1: Maniac Mart" (Curiosity Shop) + { " 51-1: Curiosity Shop", MapSelect_LoadGame, ENTRANCE(CURIOSITY_SHOP, 0) }, + + // "51-2: General Store" (Trading Post) + { " 51-2: Trading Post", MapSelect_LoadGame, ENTRANCE(TRADING_POST, 0) }, + + // "51-3: Sword Dojo" (Swordsman's School) + { " 51-3: Swordsman's School", MapSelect_LoadGame, ENTRANCE(SWORDMANS_SCHOOL, 0) }, + + // "51-4: Post House" (Post Office) + { " 51-4: Post Office", MapSelect_LoadGame, ENTRANCE(POST_OFFICE, 0) }, + + // "51-5: Lottery Shop" (Lottery Shop) + { " 51-5: Lottery Shop", MapSelect_LoadGame, ENTRANCE(LOTTERY_SHOP, 0) }, + + // "52: Clock Town -North-" (North Clock Town) + { " 52: North Clock Town", MapSelect_LoadGame, ENTRANCE(NORTH_CLOCK_TOWN, 0) }, + + // "53: Clocktown -South-" (South Clock Town) + { " 53: South Clock Town", MapSelect_LoadGame, ENTRANCE(SOUTH_CLOCK_TOWN, 0) }, + + // "53-0: Clock Tower Interior" (Clock Tower Interior) + { " 53-0: Clock Town Interoir", MapSelect_LoadGame, ENTRANCE(CLOCK_TOWER_INTERIOR, 0) }, + + // "54: Clock Tower Rooftop" (Clock Tower Rooftop) + { " 54: Clock Town Rooftop", MapSelect_LoadGame, ENTRANCE(CLOCK_TOWER_ROOFTOP, 0) }, + + // "55: Laundry Area" (Laundry Pool) + { " 55: Laundry Pool", MapSelect_LoadGame, ENTRANCE(LAUNDRY_POOL, 0) }, + + // "55-0: Maniac Mart - Rear Entrance" (Curiosity Shop - Back Room) + { " 55-0: Curiosity Shop (Back)", MapSelect_LoadGame, ENTRANCE(CURIOSITY_SHOP, 1) }, + + // "55-1: Maniac Mart - Peephole" (Curiosity Shop Back Room - Peephole) + { " 55-1: Curiosity Shop (Peephole)", MapSelect_LoadGame, ENTRANCE(CURIOSITY_SHOP, 2) }, + + // "100: Wood Mountain Temple" (Woodfall Temple) + { "100: Woodfall Temple", MapSelect_LoadGame, ENTRANCE(WOODFALL_TEMPLE, 0) }, + + // "100-B: Wood Mountain Temple - Boss" (Odolwa's Lair) + { "100-B: Woodfall Temple (Boss)", MapSelect_LoadGame, ENTRANCE(ODOLWAS_LAIR, 0) }, + + // "101: Snowhead Temple" (Snowhead Temple) + { "101: Snowhead Temple", MapSelect_LoadGame, ENTRANCE(SNOWHEAD_TEMPLE, 0) }, + + // "101-B: Snowhead Temple - Boss" (Goht's Lair) + { "101-B: Snowhead Temple (Boss)", MapSelect_LoadGame, ENTRANCE(GOHTS_LAIR, 0) }, + + // "102: Great Bay Temple" (Great Bay Temple) + { "102: Great Bay Temple", MapSelect_LoadGame, ENTRANCE(GREAT_BAY_TEMPLE, 0) }, + + // "102-B: Great Bay Temple - Boss" (Gyorg's Lair) + { "102-B: Great Bay Temple (Boss)", MapSelect_LoadGame, ENTRANCE(GYORGS_LAIR, 0) }, + + // "103: Rock Building Temple -Top Side-" (Stone Tower Temple) + { "103: Stone Tower Temple", MapSelect_LoadGame, ENTRANCE(STONE_TOWER_TEMPLE, 0) }, + + // "103-0: Rock Building Temple -Underside-" (Stone Tower Temple - Flipped) + { "103-0: Inverted Stone Tower Temple", MapSelect_LoadGame, ENTRANCE(STONE_TOWER_TEMPLE_INVERTED, 0) }, + + // "103-B: Rock Building Temple - Boss" (Twinmold's Lair) + { "103-B: Stone Tower Temple (Boss)", MapSelect_LoadGame, ENTRANCE(TWINMOLDS_LAIR, 0) }, + + // "104: Steppe" (On the Moon) + { "104: On The Moon", MapSelect_LoadGame, ENTRANCE(THE_MOON, 0) }, + + // "104-0: Last Deku Dungeon" (Deku Trial) + { "104-0: Deku Trial", MapSelect_LoadGame, ENTRANCE(MOON_DEKU_TRIAL, 0) }, + + // "104-1: Last Goron Dungeon" (Goron Trial) + { "104-1: Goron Trial", MapSelect_LoadGame, ENTRANCE(MOON_GORON_TRIAL, 0) }, + + // "104-2: Last Zora Dungeon" (Zora Trial) + { "104-2: Zora Trial", MapSelect_LoadGame, ENTRANCE(MOON_ZORA_TRIAL, 0) }, + + // "104-3: Last Link Dungeon" (Link Trial) + { "104-3: Link Trial", MapSelect_LoadGame, ENTRANCE(MOON_LINK_TRIAL, 0) }, + + // "104-B: Last Dungeon -Boss-" (Majora's Lair) + { "104-B: Majora's Lair", MapSelect_LoadGame, ENTRANCE(MAJORAS_LAIR, 0) }, + + // "119: Deku Shrine" (Deku Shrine) + { "119: Deku Shrine", MapSelect_LoadGame, ENTRANCE(DEKU_SHRINE, 0) }, + + // "121: Secret Shrine" (Secret Shrine) + { "121: Secret Shrine", MapSelect_LoadGame, ENTRANCE(SECRET_SHRINE, 0) }, + + // "122: Opening Dungeon" (Pond Area Cutscene: Falling of the Cliff) + { "122: Opening Dungeon", MapSelect_LoadGame, ENTRANCE(OPENING_DUNGEON, 0) }, + + // "123: Giants' Chamber" (Giants' Chamber) + { "123: Giants Chamber", MapSelect_LoadGame, ENTRANCE(GIANTS_CHAMBER, 0) }, + + // "126: Deku Minigame" (Deku Rupee Minigame) + { "126: Deku Playground", MapSelect_LoadGame, ENTRANCE(DEKU_SCRUB_PLAYGROUND, 0) }, + + // "127-0: Fairy Fountain 0" (Fairy Fountain - Clock Town) + { "127-0: Fairy Fountain (Clock Town)", MapSelect_LoadGame, ENTRANCE(FAIRY_FOUNTAIN, 0) }, + + // "127-1: Fairy Fountain 1" (Fairy Fountain - Woodfall) + { "127-1: Fairy Fountain (Woodfall)", MapSelect_LoadGame, ENTRANCE(FAIRY_FOUNTAIN, 1) }, + + // "127-2: Fairy Fountain 2" (Fairy Fountain - Snowhead) + { "127-2: Fairy Fountain (Snowhead)", MapSelect_LoadGame, ENTRANCE(FAIRY_FOUNTAIN, 2) }, + + // "127-3: Fairy Fountain 3" (Fairy Fountain - Great Bay Coast) + { "127-3: Fairy Fountain (Great Bay)", MapSelect_LoadGame, ENTRANCE(FAIRY_FOUNTAIN, 3) }, + + // "127-4: Fairy Fountain 4" (Fairy Fountain - Ikana Canyon) + { "127-4: Fairy Fountain (Ikana)", MapSelect_LoadGame, ENTRANCE(FAIRY_FOUNTAIN, 4) }, + + // "128: Swamp Spider Manor" (Swamp Spider House) + { "128: Swamp Spider House", MapSelect_LoadGame, ENTRANCE(SWAMP_SPIDER_HOUSE, 0) }, + + // "129: Ocean Spider Manor" (Oceanside Spider House) + { "129: Oceanside Spider House", MapSelect_LoadGame, ENTRANCE(OCEANSIDE_SPIDER_HOUSE, 0) }, + + // "130: Beneath the Graves - Dampe" (Beneath the Graveyard) + { "130: Dampe's Grave", MapSelect_LoadGame, ENTRANCE(DAMPES_HOUSE, 0) }, + + // "131: Beneath the Well" (Beneath the Well) + { "131: Beneath The Well", MapSelect_LoadGame, ENTRANCE(BENEATH_THE_WELL, 0) }, + + // "132: Ghost Hut" (Ghost Hut) + { "132: Ghost Hut", MapSelect_LoadGame, ENTRANCE(GHOST_HUT, 0) }, + + // "133-0: Beneath the Graves 0" (Beneath the Graveyard - Part 1) + { "133-0: Beneath The Graves 0", MapSelect_LoadGame, ENTRANCE(BENEATH_THE_GRAVERYARD, 0) }, + + // "133-1: Beneath the Graves 1" (Beneath the Graveyard - Part 2) + { "133-1: Beneath The Graves 1", MapSelect_LoadGame, ENTRANCE(BENEATH_THE_GRAVERYARD, 1) }, + + // "134-0: Secret Grotto 0" (Secret Grotto - Four Gossip Stones) + { "134-0: Secret Grotto 0", MapSelect_LoadGame, ENTRANCE(GROTTOS, 0) }, + + // "134-1: Secret Grotto 1" (Secret Grotto - Four Gossip Stones, Skulltula) + { "134-1: Secret Grotto 1", MapSelect_LoadGame, ENTRANCE(GROTTOS, 1) }, + + // "134-2: Secret Grotto 2" (Secret Grotto - Four Gossip Stones, Water Puddles) + { "134-2: Secret Grotto 2", MapSelect_LoadGame, ENTRANCE(GROTTOS, 2) }, + + // "134-3: Secret Grotto 3" (Secret Grotto - Four Gossip Stones, Water Puddle With Bugs) + { "134-3: Secret Grotto 3", MapSelect_LoadGame, ENTRANCE(GROTTOS, 3) }, + + // "134-4: Secret Grotto 4" (Secret Grotto - Chest with Blue Rupee, Deku Babas) + { "134-4: Secret Grotto 4", MapSelect_LoadGame, ENTRANCE(GROTTOS, 4) }, + + // "134-5: Secret Grotto 5" (Secret Grotto - Hot Spring, Deku Babas, Large Stones) + { "134-5: Secret Grotto 5", MapSelect_LoadGame, ENTRANCE(GROTTOS, 5) }, + + // "134-7: Secret Grotto 7" (Secret Grotto - Two Dondogos) + { "134-7: Secret Grotto 7", MapSelect_LoadGame, ENTRANCE(GROTTOS, 7) }, + + // "134-9: Secret Grotto 9" (Secret Grotto - Tall Grass With Box, Pot, Bugs) + { "134-9: Secret Grotto 9", MapSelect_LoadGame, ENTRANCE(GROTTOS, 9) }, + + // "134-10: Secret Grotto 10" (Secret Grotto - Two Cows Surrounded by Grass) + { "134-10: Secret Grotto 10", MapSelect_LoadGame, ENTRANCE(GROTTOS, 10) }, + + // "134-11: Secret Grotto 11" (Secret Grotto - Watery Hole Filled with Underwater Babas, Fish) + { "134-11: Secret Grotto 11", MapSelect_LoadGame, ENTRANCE(GROTTOS, 11) }, + + // "134-13: Secret Grotto 13" (Secret Grotto - Peahat in Center) + { "134-13: Secret Grotto 13", MapSelect_LoadGame, ENTRANCE(GROTTOS, 13) }, + + // "X 1: SPOT00" (Opening Cutscene) + { "X 1:SPOT00", MapSelect_LoadGame, ENTRANCE(CUTSCENE, 0) }, + + // "Title" (Title Screen) + { "title", (void*)MapSelect_LoadConsoleLogo, 0 }, + { "file select", (void*)MapSelect_LoadFileSelect, 0 }, +}; +#endif void MapSelect_UpdateMenu(MapSelectState* this) { s32 playerForm; @@ -804,6 +1255,8 @@ void MapSelect_PrintLoadingMessage(MapSelectState* this, GfxPrint* printer) { GfxPrint_Printf(printer, "%s", sLoadingMessages[randomMsg]); } +// Second column is unused +#ifdef Z_SELECT_JP // Second column is unused static const char* sFormLabel[][2] = { // "17 (Adult)" // 17 (Daitetsujin) @@ -817,6 +1270,20 @@ static const char* sFormLabel[][2] = { // "5 (Child)" // 5 (NTT Kodomo) { GFXP_HIRAGANA "5(コドモ)", GFXP_KATAKANA "5(NTTコドモ)" }, }; +#else +static const char* sFormLabel[][2] = { + // "17 (Adult)" // 17 (Daitetsujin) + { "Adult", "17(ダイテツジン)" }, + // "30 (Goron)" // 30 (Ice Cream -1) + { "Goron", GFXP_KATAKANA "30(アイスクリーム-1)" }, + // "78 (Zora)" // 78 (Carmen +1) + { "Zora", GFXP_KATAKANA "78(カルメン+1)" }, + // "12 (Deku)" // 12 (Majestic) + { "Deku", GFXP_KATAKANA "12(マジェスティック)" }, + // "5 (Child)" // 5 (NTT Kodomo) + { "Child", GFXP_KATAKANA "5(NTTコドモ)" }, +}; +#endif void MapSelect_PrintAgeSetting(MapSelectState* this, GfxPrint* printer, s32 playerForm) { s32 pad; @@ -854,6 +1321,7 @@ void MapSelect_PrintAgeSetting(MapSelectState* this, GfxPrint* printer, s32 play } } +#ifdef Z_SELECT_JP void MapSelect_PrintCutsceneSetting(MapSelectState* this, GfxPrint* printer, u16 csIndex) { const char* stage; const char* day; @@ -980,25 +1448,152 @@ void MapSelect_PrintCutsceneSetting(MapSelectState* this, GfxPrint* printer, u16 GfxPrint_Printf(printer, "Day:" GFXP_HIRAGANA "%s", day); } +#else +void MapSelect_PrintCutsceneSetting(MapSelectState* this, GfxPrint* printer, u16 csIndex) { + const char* stage; + const char* day; + + GfxPrint_SetPos(printer, 4, 25); + GfxPrint_SetColor(printer, 255, 255, 55, 255); + + // "-jara" used in these strings is a Kokiri speech quirk word + switch (csIndex) { + case 0: + // clang-format off + // "Afternoon-jara" + gSaveContext.save.time = CLOCK_TIME(12, 0); stage = "Afternoon"; + // clang-format on + break; + + case 0x8000: + // clang-format off + // "Morning-jara" + gSaveContext.save.time = CLOCK_TIME(6, 0) + 1; stage = "Morning"; + // clang-format on + break; + + case 0x8800: + gSaveContext.save.time = CLOCK_TIME(18, 1); + // "Night-jara" + stage = "Night"; + break; + + case 0xFFF0: + // clang-format off + // "Cutscene 00" + gSaveContext.save.time = CLOCK_TIME(12, 0); stage = "CS00"; + // clang-format on + break; + + case 0xFFF1: + // "Cutscene 01" + stage = "CS01"; + break; + + case 0xFFF2: + // "Cutscene 02" + stage = "CS02"; + break; + + case 0xFFF3: + // "Cutscene 03" + stage = "CS02"; + break; + + case 0xFFF4: + // "Cutscene 04" + stage = "CS04"; + break; + + case 0xFFF5: + // "Cutscene 05" + stage = "CS05"; + break; + + case 0xFFF6: + // "Cutscene 06" + stage = "CS06"; + break; + + case 0xFFF7: + // "Cutscene 07" + stage = "CS07"; + break; + + case 0xFFF8: + // "Cutscene 08" + stage = "CS08"; + break; + + case 0xFFF9: + // "Cutscene 09" + stage = "CS09"; + break; + + case 0xFFFA: + // "Cutscene 0A" + stage = "CS10"; + break; + + default: + stage = "???"; + break; + } + gSaveContext.skyboxTime = gSaveContext.save.time; + GfxPrint_Printf(printer, "Stage: %s", stage); + + GfxPrint_SetPos(printer, 23, 25); + GfxPrint_SetColor(printer, 255, 255, 55, 255); + + switch (gSaveContext.save.day) { + case 1: + // "The First Day" + day = "First Day"; + break; + + case 2: + // "The Next Day" + day = "Second Day"; + break; + + case 3: + // "The Final Day" + day = "Final Day"; + break; + + case 4: + // "Clear Day" + day = "New Day"; + break; + + default: + gSaveContext.save.day = 1; + // "The First Day" + day = "First Day"; + break; + } + + GfxPrint_Printf(printer, "Day: %s", day); +} +#endif void MapSelect_DrawMenu(MapSelectState* this) { GraphicsContext* gfxCtx = this->state.gfxCtx; - GfxPrint* printer; + GfxPrint printer; OPEN_DISPS(gfxCtx); Gfx_SetupDL28_Opa(gfxCtx); - printer = alloca(sizeof(GfxPrint)); - GfxPrint_Init(printer); - GfxPrint_Open(printer, POLY_OPA_DISP); + GfxPrint_Init(&printer); + GfxPrint_Open(&printer, POLY_OPA_DISP); - MapSelect_PrintMenu(this, printer); - MapSelect_PrintAgeSetting(this, printer, GET_PLAYER_FORM); - MapSelect_PrintCutsceneSetting(this, printer, ((void)0, gSaveContext.save.cutsceneIndex)); + MapSelect_PrintMenu(this, &printer); + MapSelect_PrintAgeSetting(this, &printer, GET_PLAYER_FORM); + MapSelect_PrintCutsceneSetting(this, &printer, ((void)0, gSaveContext.save.cutsceneIndex)); - POLY_OPA_DISP = GfxPrint_Close(printer); - GfxPrint_Destroy(printer); + POLY_OPA_DISP = GfxPrint_Close(&printer); + GfxPrint_Destroy(&printer); CLOSE_DISPS(gfxCtx); } diff --git a/mm/src/overlays/gamestates/ovl_title/z_title.c b/mm/src/overlays/gamestates/ovl_title/z_title.c index 3e87bb72e..2d9862460 100644 --- a/mm/src/overlays/gamestates/ovl_title/z_title.c +++ b/mm/src/overlays/gamestates/ovl_title/z_title.c @@ -10,6 +10,9 @@ #include "CIC6105.h" #include "overlays/gamestates/ovl_opening/z_opening.h" #include "misc/nintendo_rogo_static/nintendo_rogo_static.h" +#include "overlays/gamestates/ovl_select/z_select.h" +#include +#include "BenPort.h" void ConsoleLogo_UpdateCounters(ConsoleLogoState* this) { if ((this->coverAlpha == 0) && (this->visibleDuration != 0)) { @@ -76,6 +79,8 @@ void ConsoleLogo_Draw(GameState* thisx) { eye.x = -4949.148f; eye.y = 4002.5417f; eye.z = 1119.0837f; + void* shine = ResourceMgr_LoadTexOrDListByName(gNintendo64LogoTextShineTex); + char* logo = ResourceMgr_LoadTexOrDListByName(gNintendo64LogoTextTex); Hilite_DrawOpa(&object, &eye, &lightDir, this->state.gfxCtx); @@ -99,13 +104,13 @@ void ConsoleLogo_Draw(GameState* thisx) { COMBINED, ENVIRONMENT, COMBINED, 0, PRIMITIVE, 0); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 170, 255, 255, 255); gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 255, 128); - gDPLoadMultiBlock(POLY_OPA_DISP++, gNintendo64LogoTextShineTex, 0x100, 1, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, 2, 11); + gDPLoadMultiBlock(POLY_OPA_DISP++, shine, 0x100, 1, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMIRROR | G_TX_WRAP, 5, 5, 2, 11); for (idx = 0, y = 94; idx < 16; idx++, y += 2) { - gDPLoadTextureBlock(POLY_OPA_DISP++, &((u8*)gNintendo64LogoTextTex)[0x180 * idx], G_IM_FMT_I, G_IM_SIZ_8b, 192, - 2, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_OPA_DISP++, &((u8*)logo)[0x180 * idx], G_IM_FMT_I, G_IM_SIZ_8b, 192, 2, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); gDPSetTileSize(POLY_OPA_DISP++, 1, this->uls, (this->ult & 0x7F) - idx * 4, 0, 0); gSPTextureRectangle(POLY_OPA_DISP++, 97 << 2, y << 2, (97 + 192) << 2, (y + 2) << 2, G_TX_RENDERTILE, 0, 0, @@ -119,6 +124,9 @@ void ConsoleLogo_Draw(GameState* thisx) { CLOSE_DISPS(this->state.gfxCtx); } +// hack for minibuild work +void MapSelect_Init(GameState* thisx); +void FileSelect_Init(GameState* thisx); void ConsoleLogo_Main(GameState* thisx) { ConsoleLogoState* this = (ConsoleLogoState*)thisx; @@ -126,7 +134,7 @@ void ConsoleLogo_Main(GameState* thisx) { OPEN_DISPS(this->state.gfxCtx); - gSPSegment(POLY_OPA_DISP++, 0x01, this->staticSegment); + gSPSegment(OVERLAY_DISP++, 0x01, this->staticSegment); ConsoleLogo_UpdateCounters(this); ConsoleLogo_Draw(&this->state); @@ -136,7 +144,8 @@ void ConsoleLogo_Main(GameState* thisx) { gSaveContext.gameMode = GAMEMODE_TITLE_SCREEN; STOP_GAMESTATE(&this->state); - SET_NEXT_GAMESTATE(&this->state, TitleSetup_Init, sizeof(TitleSetupState)); + // hack + SET_NEXT_GAMESTATE(&this->state, MapSelect_Init, sizeof(MapSelectState)); } CLOSE_DISPS(this->state.gfxCtx); diff --git a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_item.c b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_item.c index 02f011807..8f007d974 100644 --- a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_item.c +++ b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_item.c @@ -175,6 +175,8 @@ s16 sAmmoRectHeight[] = { 150, // SLOT_PICTOGRAPH_BOX }; +extern const char* gAmmoDigitTextures[10]; + void KaleidoScope_DrawAmmoCount(PauseContext* pauseCtx, GraphicsContext* gfxCtx, s16 item, u16 ammoIndex) { s16 ammoUpperDigit; s16 ammo; @@ -224,13 +226,13 @@ void KaleidoScope_DrawAmmoCount(PauseContext* pauseCtx, GraphicsContext* gfxCtx, // Draw upper digit if (ammoUpperDigit != 0) { POLY_OPA_DISP = - Gfx_DrawTexRectIA8(POLY_OPA_DISP, ((u8*)gAmmoDigit0Tex + (8 * 8 * ammoUpperDigit)), 8, 8, + Gfx_DrawTexRectIA8(POLY_OPA_DISP,gAmmoDigitTextures[ammoUpperDigit], 8, 8, sAmmoRectLeft[ammoIndex], sAmmoRectHeight[ammoIndex], 8, 8, 1 << 10, 1 << 10); } // Draw lower digit POLY_OPA_DISP = - Gfx_DrawTexRectIA8(POLY_OPA_DISP, ((u8*)gAmmoDigit0Tex + (8 * 8 * ammo)), 8, 8, sAmmoRectLeft[ammoIndex] + 6, + Gfx_DrawTexRectIA8(POLY_OPA_DISP, gAmmoDigitTextures[ammo], 8, 8, sAmmoRectLeft[ammoIndex] + 6, sAmmoRectHeight[ammoIndex], 8, 8, 1 << 10, 1 << 10); CLOSE_DISPS(gfxCtx); @@ -306,10 +308,17 @@ void KaleidoScope_DrawItemSelect(PlayState* play) { pauseCtx->itemVtx[j + 0].v.ob[1] - 32; } } - + int itemId = gSaveContext.save.saveInfo.inventory.items[i]; + // BENTODO re add when the table is in C + if (CHECK_QUEST_ITEM(itemId) /*|| !gPlayerFormItemRestrictions[GET_PLAYER_FORM][(s32)itemId] */) { + gDPSetGrayscaleColor(POLY_OPA_DISP++, 109, 109, 109, 255); + gSPGrayscale(POLY_OPA_DISP++, true); + } gSPVertex(POLY_OPA_DISP++, &pauseCtx->itemVtx[j + 0], 4, 0); - KaleidoScope_DrawTexQuadRGBA32( - play->state.gfxCtx, gItemIcons[((void)0, gSaveContext.save.saveInfo.inventory.items[i])], 32, 32, 0); + KaleidoScope_DrawTexQuadRGBA32(play->state.gfxCtx, gItemIcons[itemId], 32, 32, 0); + gSPGrayscale(POLY_OPA_DISP++, false); + //KaleidoScope_DrawTexQuadRGBA32( + // play->state.gfxCtx, gItemIcons[((void)0, gSaveContext.save.saveInfo.inventory.items[i])], 32, 32, 0); } } diff --git a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_map.c b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_map.c index 9209510a8..bae459ecb 100644 --- a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_map.c +++ b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_map.c @@ -11,6 +11,8 @@ #include "interface/icon_item_jpn_static/icon_item_jpn_static.h" #include "archives/icon_item_24_static/icon_item_24_static_yar.h" +#include "BenPort.h" + void KaleidoScope_DrawDungeonStrayFairyCount(PlayState* play) { s16 counterDigits[2]; s16 rectLeft; @@ -549,7 +551,7 @@ void KaleidoScope_DrawWorldMap(PlayState* play) { if ((pauseCtx->pageIndex == PAUSE_MAP) && (pauseCtx->state == PAUSE_STATE_MAIN) && ((pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE) || (pauseCtx->mainState == PAUSE_MAIN_STATE_EQUIP_ITEM)) && YREG(6) && (pauseCtx->state != PAUSE_STATE_SAVEPROMPT) && !IS_PAUSE_STATE_GAMEOVER) { - + char* tex = ResourceMgr_LoadTexOrDListByName(gWorldMapImageTex); // Draw the world map image flat // Because it is flat, the texture is loaded by filling it in 8 rows at a time. // 8 is chosen because it is smaller than `TMEM_SIZE / 2 / textureWidth` and divides the texture's height. @@ -567,7 +569,7 @@ void KaleidoScope_DrawWorldMap(PlayState* play) { // Process the 128 rows of pixels for gWorldMapImageTex, 8 rows at a time over 16 iterations // Loop over yPos (t), textureIndex (j) for (t = 62, j = 0; j < 16; j++, t += 8) { - gDPLoadTextureBlock(POLY_OPA_DISP++, (u8*)gWorldMapImageTex + j * (WORLD_MAP_IMAGE_WIDTH * 8), G_IM_FMT_CI, + gDPLoadTextureBlock(POLY_OPA_DISP++, &tex[j * (WORLD_MAP_IMAGE_WIDTH * 8)], G_IM_FMT_CI, G_IM_SIZ_8b, WORLD_MAP_IMAGE_WIDTH, 8, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -603,9 +605,10 @@ void KaleidoScope_DrawWorldMap(PlayState* play) { // Process the first 72 rows of pixels for gWorldMapImageTex, 9 rows at a time over 8 iterations // Loop over quadIndex of this loop (i), quadIndex of the entire texture (k), vtxIndex (j) + char* tex = ResourceMgr_LoadTexOrDListByName(gWorldMapImageTex); for (i = 0, k = 0, j = 0; i < 8; i++, k++, j += 4) { gDPLoadTextureBlock( - POLY_OPA_DISP++, (u8*)gWorldMapImageTex + k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT), + POLY_OPA_DISP++, &tex[k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT)], G_IM_FMT_CI, G_IM_SIZ_8b, WORLD_MAP_IMAGE_WIDTH, WORLD_MAP_IMAGE_FRAG_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -619,8 +622,7 @@ void KaleidoScope_DrawWorldMap(PlayState* play) { // Process the next 54 rows of pixels for gWorldMapImageTex, 9 rows at a time over 6 iterations // Loop over quadIndex of this loop (i), quadIndex of the entire texture (k), vtxIndex (j) for (i = 0, j = 0; i < 6; i++, k++, j += 4) { - gDPLoadTextureBlock( - POLY_OPA_DISP++, (u8*)gWorldMapImageTex + k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT), + gDPLoadTextureBlock(POLY_OPA_DISP++, &tex[k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT)], G_IM_FMT_CI, G_IM_SIZ_8b, WORLD_MAP_IMAGE_WIDTH, WORLD_MAP_IMAGE_FRAG_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -629,11 +631,11 @@ void KaleidoScope_DrawWorldMap(PlayState* play) { // Process the last 2 rows of pixels for gWorldMapImageTex gDPLoadTextureBlock( - POLY_OPA_DISP++, (u8*)gWorldMapImageTex + k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT), + POLY_OPA_DISP++, &tex[k * (WORLD_MAP_IMAGE_WIDTH * WORLD_MAP_IMAGE_FRAG_HEIGHT)], G_IM_FMT_CI, G_IM_SIZ_8b, WORLD_MAP_IMAGE_WIDTH, WORLD_MAP_IMAGE_HEIGHT % WORLD_MAP_IMAGE_FRAG_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSP1Quadrangle(POLY_OPA_DISP++, j, j + 2, j + 3, j + 1, 0); + } Gfx_SetupDL42_Opa(play->state.gfxCtx); diff --git a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c index 66710080e..f0cca8e2b 100644 --- a/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c +++ b/mm/src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope_NES.c @@ -13,7 +13,10 @@ #include "interface/icon_item_gameover_static/icon_item_gameover_static.h" #include "interface/icon_item_jpn_static/icon_item_jpn_static.h" #include "interface/icon_item_vtx_static/icon_item_vtx_static.h" - +#include "BenPort.h" +#include "gfxdebuggerbridge.h" +#include "archives/item_name_static/item_name_static.h" +#include "archives/map_name_static/map_name_static.h" // Page Textures (Background of Page): // Broken up into multiple textures. // Numbered by column/row. @@ -246,7 +249,17 @@ u8 gAreaGsFlags[] = { s16 sGameOverRectPosY = 66; void Kaleido_LoadMapNameStatic(void* segment, u32 texIndex) { - CmpDma_LoadFile(SEGMENT_ROM_START(map_name_static), texIndex, segment, 0x400); + static const char* gMapNameStatics[] = { + gMapPointGreatBayENGTex, gMapPointZoraHallENGTex, gMapPointRomaniRanchENGTex, + gMapPointDekuPalaceENGTex, gMapPointWoodfallENGTex, gMapPointClockTownENGTex, + gMapPointSnowheadENGTex, gMapPointIkanaGraveyardENGTex, gMapPointIkanaCanyonENGTex, + gMapPointGoronVillageENGTex, gMapPointStoneTowerENGTex, gMapPointGreatBayCoastENGTex, + gMapPointSouthernSwampENGTex, gMapPointMountainVillageENGTex, gMapPointMilkRoadENGTex, + gMapPointZoraCapeENGTex, + }; + void* tex = ResourceMgr_LoadTexOrDListByName(gMapNameStatics[texIndex]); + memcpy(segment, tex, 0x400); + //CmpDma_LoadFile(SEGMENT_ROM_START(map_name_static), texIndex, segment, 0x400); } //! note: nothing from `map_name_static` is of size `0xA00` in US 1.0 @@ -255,7 +268,131 @@ void Kaleido_LoadMapNameStaticLarge(void* segment, u32 texIndex) { } void Kaleido_LoadItemNameStatic(void* segment, u32 texIndex) { - CmpDma_LoadFile(SEGMENT_ROM_START(item_name_static), texIndex, segment, 0x400); + static const char* gItemNameStatics[] = { + gItemNameOcarinaOfTimeENGTex, + gItemNameHerosBowENGTex, + gItemNameFireArrowENGTex, + gItemNameIceArrowENGTex, + gItemNameLightArrowENGTex, + gItemNameFairyOcarinaJPNTex, + gItemNameBombENGTex, + gItemNameBombchuENGTex, + gItemNameDekuStickENGTex, + gItemNameDekuNutENGTex, + gItemNameMagicBeansENGTex, + gItemNameLongshotJPNTex, + gItemNamePowderKegENGTex, + gItemNamePictographBoxENGTex, + gItemNameLensOfTruthENGTex, + gItemNameHookshotENGTex, + gItemNameGreatFairysSwordENGTex, + gItemNameFairySlingshotJPNTex, + gItemNameEmptyBottleENGTex, + gItemNameRedPotionENGTex, + gItemNameGreenPotionENGTex, + gItemNameBluePotionENGTex, + gItemNameFairyENGTex, + gItemNameDekuPrincessENGTex, + gItemNameFullMilkENGTex, + gItemNameHalfMilkENGTex, + gItemNameFishENGTex, + gItemNameBugENGTex, + gItemNameBlueFireENGTex, + gItemNamePoeENGTex, + gItemNameBigPoeENGTex, + gItemNameSpringWaterENGTex, + gItemNameHotSpringWaterENGTex, + gItemNameZoraEggENGTex, + gItemNameGoldDustENGTex, + gItemNameMagicalMushroomENGTex, + gItemNameSeaHorseENGTex, + gItemNameChateauRomaniENGTex, + gItemNameHylianLoachJPNTex, + gItemNameObabasDrinkJPNTex, + gItemNameMoonsTearENGTex, + gItemNameLandTitleDeedENGTex, + gItemNameSwampTitleDeedENGTex, + gItemNameMountainTitleDeedENGTex, + gItemNameOceanTitleDeedENGTex, + gItemNameRoomKeyENGTex, + gItemNameSpecialDeliveryToMamaENGTex, + gItemNameLetterToKafeiENGTex, + gItemNamePendantOfMemoriesENGTex, + gItemNameMoonsStoneJPNTex, + gItemNameDekuMaskENGTex, + gItemNameGoronMaskENGTex, + gItemNameZoraMaskENGTex, + gItemNameFierceDeitysMaskENGTex, + gItemNameMaskOfTruthENGTex, + gItemNameKafeisMaskENGTex, + gItemNameAllNightMaskENGTex, + gItemNameBunnyHoodENGTex, + gItemNameKeatonMaskENGTex, + gItemNameGarosMaskENGTex, + gItemNameRomanisMaskENGTex, + gItemNameCircusLeadersMaskENGTex, + gItemNamePostmansHatENGTex, + gItemNameCouplesMaskENGTex, + gItemNameGreatFairysMaskENGTex, + gItemNameGibdoMaskENGTex, + gItemNameDonGerosMaskENGTex, + gItemNameKamarosMaskENGTex, + gItemNameCaptainsHatENGTex, + gItemNameStoneMaskENGTex, + gItemNameBremenMaskENGTex, + gItemNameBlastMaskENGTex, + gItemNameMaskOfScentsENGTex, + gItemNameGiantsMaskENGTex, + gItemNameWindMedallionJPNTex, + gItemNameFireMedallionJPNTex, + gItemNameIceMedallionJPNTex, + gItemNameKokiriSwordENGTex, + gItemNameRazorSwordENGTex, + gItemNameGildedSwordENGTex, + gItemNameBrokenGiantsKnifeJPNTex, + gItemNameHerosShieldENGTex, + gItemNameMirrorShieldENGTex, + gItemNameQuiver30ENGTex, + gItemNameQuiver40ENGTex, + gItemNameQuiver50ENGTex, + gItemNameBombBag20ENGTex, + gItemNameBombBag30ENGTex, + gItemNameBombBag40ENGTex, + gItemNameBigKey1JPNTex, + gItemNameBigKey2JPNTex, + gItemNameBigKey3JPNTex, + gItemNameBigKey4JPNTex, + gItemNameOdolwasRemainsENGTex, + gItemNameGohtsRemainsENGTex, + gItemNameGyorgsRemainsENGTex, + gItemNameTwinmoldsRemainsENGTex, + gItemNameSonataOfAwakeningENGTex, + gItemNameGoronLullabyENGTex, + gItemNameNewWaveBossaNovaENGTex, + gItemNameElegyOfEmptynessENGTex, + gItemNameOathToOrderENGTex, + gItemNameNocturneOfShadowJPNTex, + gItemNameSongOfTimeENGTex, + gItemNameSongOfHealingENGTex, + gItemNameEponasSongENGTex, + gItemNameSongOfSoaringENGTex, + gItemNameSongOfStormsENGTex, + gItemNameSunsSongJPNTex, + gItemNameBombersNotebookENGTex, + gItemNameGoldSkulltulaJPNTex, + gItemNamePieceOfHeartENGTex, + gItemNamePieceOfHeartJPNTex, + gItemNameSunsSong2JPNTex, + gItemNameSongOfTimeJPNTex, + gItemNameLullabyIntroENGTex, + gItemNameBigKeyENGTex, + gItemNameCompassENGTex, + gItemNameDungeonMapENGTex, + gItemNameStrayFairiesENGTex, + }; + void* tex = ResourceMgr_LoadTexOrDListByName(gItemNameStatics[texIndex]); + memcpy(segment, tex, 0x400); + //CmpDma_LoadFile(SEGMENT_ROM_START(item_name_static), texIndex, segment, 0x400); } void KaleidoScope_MoveCursorToSpecialPos(PlayState* play, s16 cursorSpecialPos) { @@ -969,7 +1106,8 @@ void KaleidoScope_DrawInfoPanel(PlayState* play) { } else { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255); } - + // BENTODO is this the right way to do this? + gSPInvalidateTexCache(POLY_OPA_DISP++, pauseCtx->nameSegment); POLY_OPA_DISP = Gfx_DrawTexQuad4b(POLY_OPA_DISP, pauseCtx->nameSegment, G_IM_FMT_IA, 128, 16, 0); } } else if ((pauseCtx->mainState <= PAUSE_MAIN_STATE_SONG_PLAYBACK) || @@ -1006,7 +1144,8 @@ void KaleidoScope_DrawInfoPanel(PlayState* play) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255); //! @bug: Incorrect dimensions. Should be 64x16 - POLY_OPA_DISP = Gfx_DrawTexQuad4b(POLY_OPA_DISP, gPauseToDecideENGTex, G_IM_FMT_IA, 48, 16, 4); + //! Fixed 11/23/23 + POLY_OPA_DISP = Gfx_DrawTexQuad4b(POLY_OPA_DISP, gPauseToDecideENGTex, G_IM_FMT_IA, 64, 16, 4); } else if (pauseCtx->cursorSpecialPos != 0) { if ((pauseCtx->state == PAUSE_STATE_MAIN) && (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE)) { @@ -1051,6 +1190,7 @@ void KaleidoScope_DrawInfoPanel(PlayState* play) { gDPPipeSync(POLY_OPA_DISP++); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255); + POLY_OPA_DISP = Gfx_DrawTexQuad4b(POLY_OPA_DISP, gPauseToEquipENGTex, G_IM_FMT_IA, 64, 16, 4); } else if ((pauseCtx->pageIndex == PAUSE_MAP) && sInDungeonScene) { // No code in this case @@ -1124,7 +1264,7 @@ void KaleidoScope_UpdateNamePanel(PlayState* play) { pauseCtx->namedItem = pauseCtx->cursorItem[pauseCtx->pageIndex]; namedItem = pauseCtx->namedItem; - osCreateMesgQueue(&pauseCtx->loadQueue, &pauseCtx->loadMsg, 1); + //osCreateMesgQueue(&pauseCtx->loadQueue, &pauseCtx->loadMsg, 1); if (pauseCtx->namedItem != PAUSE_ITEM_NONE) { if ((pauseCtx->pageIndex == PAUSE_MAP) && !sInDungeonScene) { @@ -1410,7 +1550,7 @@ void KaleidoScope_UpdateOwlWarpNamePanel(PlayState* play) { pauseCtx->namedItem = pauseCtx->cursorItem[pauseCtx->pageIndex]; texIndex = pauseCtx->namedItem; - osCreateMesgQueue(&pauseCtx->loadQueue, &pauseCtx->loadMsg, 1); + //osCreateMesgQueue(&pauseCtx->loadQueue, &pauseCtx->loadMsg, 1); if (pauseCtx->namedItem != PAUSE_ITEM_NONE) { if ((pauseCtx->pageIndex == PAUSE_MAP) && !sInDungeonScene) { @@ -2793,7 +2933,7 @@ void KaleidoScope_UpdateOpening(PlayState* play) { pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE; pauseCtx->state++; // PAUSE_STATE_MAIN pauseCtx->alpha = 255; - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_RETURN); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_RETURN, B_BUTTON_ACTION, ACTION_MAIN); } else if (pauseCtx->switchPageTimer == 64) { pauseCtx->pageIndex = sPageSwitchNextPageIndex[pauseCtx->nextPageMode]; pauseCtx->nextPageMode = (pauseCtx->pageIndex * 2) + 1; @@ -2867,7 +3007,9 @@ void KaleidoScope_Update(PlayState* play) { for (itemId = 0; itemId <= ITEM_BOW_FIRE; itemId++) { if (!gPlayerFormItemRestrictions[GET_PLAYER_FORM][(s32)itemId]) { - KaleidoScope_GrayOutTextureRGBA32(Lib_SegmentedToVirtual(gItemIcons[(s32)itemId]), 0x400); + //void* tex = ResourceMgr_LoadTexOrDListByName(gItemIcons[(s32)itemId]); + //KaleidoScope_GrayOutTextureRGBA32(tex, 0x400); + //KaleidoScope_GrayOutTextureRGBA32(Lib_SegmentedToVirtual(gItemIcons[(s32)itemId]), 0x400); } } @@ -3603,7 +3745,7 @@ void KaleidoScope_Update(PlayState* play) { func_80143324(play, &play->skyboxCtx, play->skyboxId); if ((msgCtx->msgMode != 0) && (msgCtx->currentTextId == 0xFF)) { - Interface_LoadBButtonDoActionLabel(play, DO_ACTION_STOP); + Interface_LoadButtonDoActionLabel(play, DO_ACTION_STOP, B_BUTTON_ACTION, ACTION_MAIN); Interface_SetAButtonDoAction(play, DO_ACTION_STOP); Interface_SetHudVisibility(HUD_VISIBILITY_A_B_C); } else { diff --git a/run-docker.sh b/run-docker.sh new file mode 100755 index 000000000..a95d4bed8 --- /dev/null +++ b/run-docker.sh @@ -0,0 +1,3 @@ +cookie=$(xauth list | head -1 | sed "s/unix: /unix:0 /") +sudo docker build --build-arg MY_XAUTH_COOKIE="$cookie" . -t soh +sudo docker run --rm -it -e DISPLAY --net=host --device=/dev/dri --device /dev/snd -v $(pwd):/2ship soh /bin/bash