subrepo:
  subdir:   "libultraship"
  merged:   "a484cda98"
upstream:
  origin:   "https://github.com/HarbourMasters/libultraship.git"
  branch:   "main"
  commit:   "a484cda98"
git-subrepo:
  version:  "0.4.1"
  origin:   "???"
  commit:   "???"
This commit is contained in:
M4xw 2022-03-22 02:52:44 +01:00
parent 39cc86c260
commit d24c8453db
698 changed files with 302994 additions and 0 deletions

356
libultraship/.gitignore vendored Normal file
View File

@ -0,0 +1,356 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
!otrlib/Lib/SDL/lib/x64
!otrlib/Lib/SDL/lib/x86
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
!libultraship/Lib/**
libultraship/DebugObj/*

12
libultraship/.gitrepo Normal file
View File

@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/HarbourMasters/libultraship.git
branch = main
commit = a484cda9802ed9c39b29e11a703fd0997f42a6af
parent = 39cc86c2608e2f75ace33fc7f43bc4f2ad743f1a
method = rebase
cmdver = 0.4.1

9
libultraship/LICENSE Normal file
View File

@ -0,0 +1,9 @@
Copyright (c) 2022 Harbour Masters
MIT License
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.

28
libultraship/Makefile Normal file
View File

@ -0,0 +1,28 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17
SRC_DIRS := $(shell find -type d -not -path "*build*")
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
LIB := otrlib.a
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
all: $(LIB)
clean:
rm -rf build $(LIB)
format:
clang-format-11 -i $(CPP_FILES) $(H_FILES)
.PHONY: all clean format
build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -I ./ -I ../ZAPD/ZAPD -I ../ZAPD/ZAPDUtils -I ../../ZAPD/lib/tinyxml2 -I otrlib/Lib/spdlog/include -c $(OUTPUT_OPTION) $<
$(LIB): $(O_FILES)
$(AR) rcs $@ $^

View File

@ -0,0 +1,29 @@
#include "OTRArchive.h"
void SaveTest()
{
auto archPtr = OtrLib::OTRArchive::CreateArchive("myarch.mpq");
auto arch = archPtr.get();
char data[] = "ABCDEFG!";
arch->AddFile("test.txt", (uintptr_t)data, sizeof(data));
}
void LoadTest()
{
std::shared_ptr<OtrLib::OTRArchive> archPtr(new OtrLib::OTRArchive("myarch.mpq"));
archPtr->LoadFile("(crcfile)");
int bp = 0;
}
int main()
{
LoadTest();
//SaveTest();
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{3c4a8151-48d1-4518-be1a-24016a5b800f}</ProjectGuid>
<RootNamespace>TestApp</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\otrlib;$(ProjectDir)..\..\ZAPD\ZAPDUtils;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)x64\Debug;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>otrlib.lib;ZAPDUtils.lib;StormLibDUS.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,64 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libultraship", "libultraship\libultraship.vcxproj", "{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestApp", "TestApp\TestApp.vcxproj", "{3C4A8151-48D1-4518-BE1A-24016A5B800F}"
ProjectSection(ProjectDependencies) = postProject
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8} = {6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "..\ZAPDTR\ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPDUtils", "..\ZAPDTR\ZAPDUtils\ZAPDUtils.vcxproj", "{A2E01C3E-D647-45D1-9788-043DEBC1A908}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.ActiveCfg = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x64.Build.0 = Debug|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.ActiveCfg = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Debug|x86.Build.0 = Debug|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.ActiveCfg = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x64.Build.0 = Release|x64
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.ActiveCfg = Release|Win32
{6DA9B521-65B7-41E2-8F8A-F0451CC18ED8}.Release|x86.Build.0 = Release|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x64.ActiveCfg = Debug|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x64.Build.0 = Debug|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x86.ActiveCfg = Debug|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Debug|x86.Build.0 = Debug|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x64.ActiveCfg = Release|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x64.Build.0 = Release|x64
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x86.ActiveCfg = Release|Win32
{3C4A8151-48D1-4518-BE1A-24016A5B800F}.Release|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.ActiveCfg = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.Build.0 = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.ActiveCfg = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.Build.0 = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.Build.0 = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.ActiveCfg = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.Build.0 = Debug|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.ActiveCfg = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.Build.0 = Debug|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.ActiveCfg = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.Build.0 = Release|x64
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.ActiveCfg = Release|Win32
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCE19FF1-37C0-49CD-915A-DD695E15F00B}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,72 @@
#include "Animation.h"
void Ship::AnimationV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
Animation* anim = (Animation*)res;
ResourceFile::ParseFileBinary(reader, res);
AnimationType animType = (AnimationType)reader->ReadUInt32();
anim->type = animType;
if (animType == AnimationType::Normal)
{
anim->frameCount = reader->ReadInt16();
uint32_t rotValuesCnt = reader->ReadUInt32();
anim->rotationValues.reserve(rotValuesCnt);
for (uint32_t i = 0; i < rotValuesCnt; i++)
anim->rotationValues.push_back(reader->ReadUInt16());
uint32_t rotIndCnt = reader->ReadUInt32();
anim->rotationIndices.reserve(rotIndCnt);
for (int i = 0; i < rotIndCnt; i++)
{
uint16_t x = reader->ReadUInt16();
uint16_t y = reader->ReadUInt16();
uint16_t z = reader->ReadUInt16();
anim->rotationIndices.push_back(RotationIndex(x, y, z));
}
anim->limit = reader->ReadInt16();
}
else if (animType == AnimationType::Curve)
{
anim->frameCount = reader->ReadInt16();
uint32_t refArrCnt = reader->ReadUInt32();
anim->refIndexArr.reserve(refArrCnt);
for (uint32_t i = 0; i < refArrCnt; i++)
anim->refIndexArr.push_back(reader->ReadUByte());
uint32_t transformDataCnt = reader->ReadUInt32();
anim->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->ReadSingle();
anim->transformDataArr.push_back(data);
}
uint32_t copyValuesCnt = reader->ReadUInt32();
anim->copyValuesArr.reserve(copyValuesCnt);
for (uint32_t i = 0; i < copyValuesCnt; i++)
{
anim->copyValuesArr.push_back(reader->ReadInt16());
}
}
else if (animType == AnimationType::Link)
{
anim->frameCount = reader->ReadInt16();
anim->segPtr = reader->ReadUInt32();
}
else if (animType == AnimationType::Legacy)
{
SPDLOG_DEBUG("BEYTAH ANIMATION?!");
}
}

View File

@ -0,0 +1,63 @@
#pragma once
#include "Resource.h"
namespace Ship
{
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) {}
};
class TransformData
{
public:
///* 0x0000 */ u16 unk_00; // appears to be flags
uint16_t unk_00;
///* 0x0002 */ s16 unk_02;
int16_t unk_02;
///* 0x0004 */ s16 unk_04;
int16_t unk_04;
///* 0x0006 */ s16 unk_06;
int16_t unk_06;
///* 0x0008 */ f32 unk_08;
float unk_08;
};
class AnimationV0 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class Animation : public Resource
{
public:
AnimationType type;
int16_t frameCount;
// NORMAL
std::vector<uint16_t> rotationValues;
std::vector<RotationIndex> rotationIndices;
int16_t limit = 0;
// CURVE
std::vector<uint8_t> refIndexArr;
std::vector<TransformData> transformDataArr;
std::vector<int16_t> copyValuesArr;
// LINK
uint32_t segPtr; // This is temp
};
}

View File

@ -0,0 +1,357 @@
#include "Archive.h"
#include "Resource.h"
#include "File.h"
#include "spdlog/spdlog.h"
#include "Utils/StringHelper.h"
#include "Lib/StrHash64.h"
#include <filesystem>
namespace Ship {
Archive::Archive(const std::string& MainPath, bool enableWriting) : Archive(MainPath, "", enableWriting)
{
mainMPQ = nullptr;
}
Archive::Archive(const std::string& MainPath, const std::string& PatchesPath, bool enableWriting, bool genCRCMap) : MainPath(MainPath), PatchesPath(PatchesPath) {
mainMPQ = nullptr;
Load(enableWriting, genCRCMap);
}
Archive::~Archive() {
Unload();
}
bool Archive::IsMainMPQValid()
{
return mainMPQ != nullptr;
}
std::shared_ptr<Archive> Archive::CreateArchive(const std::string& archivePath, int fileCapacity)
{
Archive* archive = new Archive(archivePath, true);
TCHAR* t_filename = new TCHAR[archivePath.size() + 1];
t_filename[archivePath.size()] = 0;
std::copy(archivePath.begin(), archivePath.end(), t_filename);
bool success = SFileCreateArchive(t_filename, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2, fileCapacity, &archive->mainMPQ);
int error = GetLastError();
if (success) {
archive->mpqHandles[archivePath] = archive->mainMPQ;
return std::make_shared<Archive>(*archive);
} else {
SPDLOG_ERROR("({}) We tried to create an archive, but it has fallen and cannot get up.");
return nullptr;
}
}
std::shared_ptr<File> Archive::LoadFile(const std::string& filePath, bool includeParent, std::shared_ptr<File> FileToLoad) {
HANDLE fileHandle = NULL;
if (!SFileOpenFileEx(mainMPQ, filePath.c_str(), 0, &fileHandle)) {
SPDLOG_ERROR("({}) Failed to open file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->bHasLoadError = true;
return nullptr;
}
DWORD dwFileSize = SFileGetFileSize(fileHandle, 0);
std::shared_ptr<char[]> fileData(new char[dwFileSize]);
DWORD dwBytes;
if (!SFileReadFile(fileHandle, fileData.get(), dwFileSize, &dwBytes, NULL)) {
SPDLOG_ERROR("({}) Failed to read file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
if (!SFileCloseFile(fileHandle)) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq after read failure in archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
}
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->bHasLoadError = true;
return nullptr;
}
if (!SFileCloseFile(fileHandle)) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
}
if (FileToLoad == nullptr) {
FileToLoad = std::make_shared<File>();
FileToLoad->path = filePath;
}
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->parent = includeParent ? shared_from_this() : nullptr;
FileToLoad->buffer = fileData;
FileToLoad->dwBufferSize = dwFileSize;
FileToLoad->bIsLoaded = true;
return FileToLoad;
}
std::shared_ptr<File> Archive::LoadPatchFile(const std::string& filePath, bool includeParent, std::shared_ptr<File> FileToLoad) {
HANDLE fileHandle = NULL;
HANDLE mpqHandle = NULL;
for(auto [path, handle] : mpqHandles) {
if (SFileOpenFileEx(mpqHandle, filePath.c_str(), 0, &fileHandle)) {
std::unique_lock Lock(FileToLoad->FileLoadMutex);
FileToLoad->bHasLoadError = false;
mpqHandle = handle;
}
}
if(!mpqHandle) {
FileToLoad->bHasLoadError = true;
return FileToLoad;
}
DWORD dwFileSize = SFileGetFileSize(fileHandle, 0);
std::shared_ptr<char[]> fileData(new char[dwFileSize]);
DWORD dwBytes;
if (!SFileReadFile(fileHandle, fileData.get(), dwFileSize, &dwBytes, NULL)) {
SPDLOG_ERROR("({}) Failed to read file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
if (!SFileCloseFile(fileHandle)) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq after read failure in archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
}
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->bHasLoadError = true;
return nullptr;
}
if (!SFileCloseFile(fileHandle)) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath.c_str(), MainPath.c_str());
}
if (FileToLoad == nullptr) {
FileToLoad = std::make_shared<File>();
FileToLoad->path = filePath;
}
std::unique_lock<std::mutex> Lock(FileToLoad->FileLoadMutex);
FileToLoad->parent = includeParent ? shared_from_this() : nullptr;
FileToLoad->buffer = fileData;
FileToLoad->dwBufferSize = dwFileSize;
FileToLoad->bIsLoaded = true;
return FileToLoad;
}
bool Archive::AddFile(const std::string& path, uintptr_t fileData, DWORD dwFileSize) {
HANDLE hFile;
SYSTEMTIME sysTime;
GetSystemTime(&sysTime);
FILETIME t;
SystemTimeToFileTime(&sysTime, &t);
ULONGLONG stupidHack = static_cast<uint64_t>(t.dwHighDateTime) << (sizeof(t.dwHighDateTime) * 8) | t.dwLowDateTime;
if (!SFileCreateFile(mainMPQ, path.c_str(), stupidHack, dwFileSize, 0, MPQ_FILE_COMPRESS, &hFile)) {
SPDLOG_ERROR("({}) Failed to create file of {} bytes {} in archive {}", GetLastError(), dwFileSize, path.c_str(), MainPath.c_str());
return false;
}
if (!SFileWriteFile(hFile, (void*)fileData, dwFileSize, MPQ_COMPRESSION_ZLIB)) {
SPDLOG_ERROR("({}) Failed to write {} bytes to {} in archive {}", GetLastError(), dwFileSize, path.c_str(), MainPath.c_str());
if (!SFileCloseFile(hFile)) {
SPDLOG_ERROR("({}) Failed to close file {} after write failure in archive {}", GetLastError(), path.c_str(), MainPath.c_str());
}
return false;
}
if (!SFileFinishFile(hFile)) {
SPDLOG_ERROR("({}) Failed to finish file {} in archive {}", GetLastError(), path.c_str(), MainPath.c_str());
if (!SFileCloseFile(hFile)) {
SPDLOG_ERROR("({}) Failed to close file {} after finish failure in archive {}", GetLastError(), path.c_str(), MainPath.c_str());
}
return false;
}
// SFileFinishFile already frees the handle, so no need to close it again.
addedFiles.push_back(path);
hashes[CRC64(path.c_str())] = path;
return true;
}
bool Archive::RemoveFile(const std::string& path) {
// TODO: Notify the resource manager and child Files
if (!SFileRemoveFile(mainMPQ, path.c_str(), 0)) {
SPDLOG_ERROR("({}) Failed to remove file {} in archive {}", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}
return true;
}
bool Archive::RenameFile(const std::string& oldPath, const std::string& newPath) {
// TODO: Notify the resource manager and child Files
if (!SFileRenameFile(mainMPQ, oldPath.c_str(), newPath.c_str())) {
SPDLOG_ERROR("({}) Failed to rename file {} to {} in archive {}", GetLastError(), oldPath.c_str(), newPath.c_str(), MainPath.c_str());
return false;
}
return true;
}
std::vector<SFILE_FIND_DATA> Archive::ListFiles(const std::string& searchMask) {
auto fileList = std::vector<SFILE_FIND_DATA>();
SFILE_FIND_DATA findContext;
HANDLE hFind;
hFind = SFileFindFirstFile(mainMPQ, searchMask.c_str(), &findContext, nullptr);
//if (hFind && GetLastError() != ERROR_NO_MORE_FILES) {
if (hFind != nullptr) {
fileList.push_back(findContext);
bool fileFound;
do {
fileFound = SFileFindNextFile(hFind, &findContext);
if (fileFound) {
fileList.push_back(findContext);
}
else if (!fileFound && GetLastError() != ERROR_NO_MORE_FILES)
//else if (!fileFound)
{
SPDLOG_ERROR("({}), Failed to search with mask {} in archive {}", GetLastError(), searchMask.c_str(), MainPath.c_str());
if (!SListFileFindClose(hFind)) {
SPDLOG_ERROR("({}) Failed to close file search {} after failure in archive {}", GetLastError(), searchMask.c_str(), MainPath.c_str());
}
return fileList;
}
} while (fileFound);
}
else if (GetLastError() != ERROR_NO_MORE_FILES) {
SPDLOG_ERROR("({}), Failed to search with mask {} in archive {}", GetLastError(), searchMask.c_str(), MainPath.c_str());
return fileList;
}
if (hFind != nullptr)
{
if (!SFileFindClose(hFind)) {
SPDLOG_ERROR("({}) Failed to close file search {} in archive {}", GetLastError(), searchMask.c_str(), MainPath.c_str());
}
}
return fileList;
}
bool Archive::HasFile(const std::string& filename) {
bool result = false;
auto start = std::chrono::steady_clock::now();
auto lst = ListFiles(filename);
for (const auto& item : lst) {
if (item.cFileName == filename) {
result = true;
break;
}
}
auto end = std::chrono::steady_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
return result;
}
std::string Archive::HashToString(uint64_t hash) {
return hashes[hash];
}
bool Archive::Load(bool enableWriting, bool genCRCMap) {
return LoadMainMPQ(enableWriting, genCRCMap) && LoadPatchMPQs();
}
bool Archive::Unload()
{
bool success = true;
for (const auto& mpqHandle : mpqHandles) {
if (!SFileCloseArchive(mpqHandle.second)) {
SPDLOG_ERROR("({}) Failed to close mpq {}", GetLastError(), mpqHandle.first.c_str());
success = false;
}
}
mainMPQ = nullptr;
return success;
}
bool Archive::LoadPatchMPQs() {
// OTRTODO: We also want to periodically scan the patch directories for new MPQs. When new MPQs are found we will load the contents to fileCache and then copy over to gameResourceAddresses
if (PatchesPath.length() > 0) {
if (std::filesystem::is_directory(PatchesPath)) {
for (const auto& p : std::filesystem::recursive_directory_iterator(PatchesPath)) {
if (StringHelper::IEquals(p.path().extension().string(), ".otr") || StringHelper::IEquals(p.path().extension().string(), ".mpq")) {
SPDLOG_ERROR("Reading {} mpq patch", p.path().string().c_str());
if (!LoadPatchMPQ(p.path().string())) {
return false;
}
}
}
}
}
return true;
}
bool Archive::LoadMainMPQ(bool enableWriting, bool genCRCMap) {
HANDLE mpqHandle = NULL;
std::string fullPath = std::filesystem::absolute(MainPath).string();
std::wstring wFileName = std::filesystem::absolute(MainPath).wstring();
if (!SFileOpenArchive(wFileName.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
SPDLOG_ERROR("({}) Failed to open main mpq file {}.", GetLastError(), fullPath.c_str());
return false;
}
mpqHandles[fullPath] = mpqHandle;
mainMPQ = mpqHandle;
if (genCRCMap) {
auto listFile = LoadFile("(listfile)", false);
std::vector<std::string> lines = StringHelper::Split(std::string(listFile->buffer.get(), listFile->dwBufferSize), "\n");
for (size_t i = 0; i < lines.size(); i++) {
std::string line = StringHelper::Strip(lines[i], "\r");
//uint64_t hash = StringHelper::StrToL(lines[i], 16);
uint64_t hash = CRC64(line.c_str());
hashes[hash] = line;
}
}
return true;
}
bool Archive::LoadPatchMPQ(const std::string& path) {
HANDLE patchHandle = NULL;
std::string fullPath = std::filesystem::absolute(path).string();
if (mpqHandles.contains(fullPath)) {
return true;
}
std::wstring wPath = std::filesystem::absolute(path).wstring();
if (!SFileOpenArchive(wPath.c_str(), 0, MPQ_OPEN_READ_ONLY, &patchHandle)) {
SPDLOG_ERROR("({}) Failed to open patch mpq file {} while applying to {}.", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}
if (!SFileOpenPatchArchive(mainMPQ, wPath.c_str(), "", 0)) {
SPDLOG_ERROR("({}) Failed to apply patch mpq file {} to main mpq {}.", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}
mpqHandles[fullPath] = patchHandle;
return true;
}
}

View File

@ -0,0 +1,55 @@
#pragma once
#undef _DLL
#include <string>
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
#include "Resource.h"
//#include "Lib/StrHash64.h"
#include "Lib/StormLib/StormLib.h"
namespace Ship
{
class File;
class Archive : public std::enable_shared_from_this<Archive>
{
public:
Archive(const std::string& MainPath, bool enableWriting);
Archive(const std::string& MainPath, const std::string& PatchesPath, bool enableWriting, bool genCRCMap = true);
~Archive();
bool IsMainMPQValid();
static std::shared_ptr<Archive> CreateArchive(const std::string& archivePath, int fileCapacity);
std::shared_ptr<File> LoadFile(const std::string& filePath, bool includeParent = true, std::shared_ptr<File> FileToLoad = nullptr);
std::shared_ptr<File> LoadPatchFile(const std::string& filePath, bool includeParent = true, std::shared_ptr<File> FileToLoad = nullptr);
bool AddFile(const std::string& path, uintptr_t fileData, DWORD dwFileSize);
bool RemoveFile(const std::string& path);
bool RenameFile(const std::string& oldPath, const std::string& newPath);
std::vector<SFILE_FIND_DATA> ListFiles(const std::string& searchMask);
bool HasFile(const std::string& searchMask);
std::string HashToString(uint64_t hash);
protected:
bool Load(bool enableWriting, bool genCRCMap);
bool Unload();
private:
std::string MainPath;
std::string PatchesPath;
std::map<std::string, HANDLE> mpqHandles;
std::vector<std::string> addedFiles;
std::map<uint64_t, std::string> hashes;
HANDLE mainMPQ;
bool LoadMainMPQ(bool enableWriting, bool genCRCMap);
bool LoadPatchMPQs();
bool LoadPatchMPQ(const std::string& path);
};
}

View File

@ -0,0 +1,61 @@
#include "Array.h"
#include "Vertex.h"
namespace Ship
{
void ArrayV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
Array* arr = (Array*)res;
ResourceFile::ParseFileBinary(reader, res);
ZResourceType resType = (ZResourceType)reader->ReadUInt32();
uint32_t arrayCnt = reader->ReadUInt32();
for (uint32_t i = 0; i < arrayCnt; i++)
{
if (resType == ZResourceType::Vertex)
{
Vtx data;
data.x = reader->ReadInt16();
data.y = reader->ReadInt16();
data.z = reader->ReadInt16();
data.flag = reader->ReadUInt16();
data.s = reader->ReadInt16();
data.t = reader->ReadInt16();
data.r = reader->ReadUByte();
data.g = reader->ReadUByte();
data.b = reader->ReadUByte();
data.a = reader->ReadUByte();
arr->vertices.push_back(data);
}
else
{
ScalarType scalType = (ScalarType)reader->ReadUInt32();
int iter = 1;
if (resType == ZResourceType::Vector)
iter = reader->ReadUInt32();
for (int k = 0; k < iter; k++)
{
ScalarData data;
switch (scalType)
{
case ScalarType::ZSCALAR_S16:
data.s16 = reader->ReadInt16();
break;
case ScalarType::ZSCALAR_U16:
data.u16 = reader->ReadUInt16();
break;
// OTRTODO: IMPLEMENT OTHER TYPES!
}
arr->scalars.push_back(data);
}
}
}
}
}

View File

@ -0,0 +1,85 @@
#pragma once
#include "Resource.h"
#include "Vertex.h"
namespace Ship
{
typedef union ScalarData
{
uint8_t u8;
int8_t s8;
uint16_t u16;
int16_t s16;
uint32_t u32;
int32_t s32;
uint64_t u64;
int64_t s64;
float f32;
double f64;
} ScalarData;
enum class ScalarType
{
ZSCALAR_NONE,
ZSCALAR_S8,
ZSCALAR_U8,
ZSCALAR_X8,
ZSCALAR_S16,
ZSCALAR_U16,
ZSCALAR_X16,
ZSCALAR_S32,
ZSCALAR_U32,
ZSCALAR_X32,
ZSCALAR_S64,
ZSCALAR_U64,
ZSCALAR_X64,
ZSCALAR_F32,
ZSCALAR_F64
};
// OTRTODO: Replace this with something that can be shared between the exporter and importer...
enum class ZResourceType
{
Error,
Animation,
Array,
AltHeader,
Background,
Blob,
CollisionHeader,
Cutscene,
DisplayList,
Limb,
LimbTable,
Mtx,
Path,
PlayerAnimationData,
Room,
RoomCommand,
Scalar,
Scene,
Skeleton,
String,
Symbol,
Texture,
TextureAnimation,
TextureAnimationParams,
Vector,
Vertex,
};
class ArrayV0 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class Array : public Resource
{
public:
std::vector<ScalarData> scalars;
std::vector<Vtx> vertices;
};
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "stdint.h"
namespace Ship {
class AudioPlayer {
public:
AudioPlayer() { };
virtual bool Init(void) = 0;
virtual int Buffered(void) = 0;
virtual int GetDesiredBuffered(void) = 0;
virtual void Play(const uint8_t* buf, uint32_t len) = 0;
};
}

View File

@ -0,0 +1,18 @@
#include "Blob.h"
namespace Ship
{
void BlobV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
Blob* blob = (Blob*)res;
ResourceFile::ParseFileBinary(reader, blob);
uint32_t dataSize = reader->ReadUInt32();
blob->data.reserve(dataSize);
for (uint32_t i = 0; i < dataSize; i++)
blob->data.push_back(reader->ReadUByte());
}
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "Resource.h"
namespace Ship
{
class BlobV0 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class Blob : public Resource
{
public:
std::vector<uint8_t> data;
};
};

View File

@ -0,0 +1,99 @@
#include "CollisionHeader.h"
void Ship::CollisionHeaderV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
CollisionHeader* col = (CollisionHeader*)res;
ResourceFile::ParseFileBinary(reader, res);
col->absMinX = reader->ReadInt16();
col->absMinY = reader->ReadInt16();
col->absMinZ = reader->ReadInt16();
col->absMaxX = reader->ReadInt16();
col->absMaxY = reader->ReadInt16();
col->absMaxZ = reader->ReadInt16();
uint32_t vtxCnt = reader->ReadInt32();
col->vertices.reserve(vtxCnt);
for (uint32_t i = 0; i < vtxCnt; i++)
{
float x = reader->ReadInt16();
float y = reader->ReadInt16();
float z = reader->ReadInt16();
col->vertices.push_back(Vec3f(x, y, z));
}
uint32_t polyCnt = reader->ReadUInt32();
col->polygons.reserve(polyCnt);
for (uint32_t i = 0; i < polyCnt; i++)
col->polygons.push_back(Ship::PolygonEntry(reader));
uint32_t polyTypesCnt = reader->ReadUInt32();
col->polygonTypes.reserve(polyTypesCnt);
for (uint32_t i = 0; i < polyTypesCnt; i++)
col->polygonTypes.push_back(reader->ReadUInt64());
col->camData = new CameraDataList();
uint32_t camEntriesCnt = reader->ReadUInt32();
col->camData->entries.reserve(camEntriesCnt);
for (uint32_t i = 0; i < camEntriesCnt; i++)
{
Ship::CameraDataEntry* entry = new Ship::CameraDataEntry();
entry->cameraSType = reader->ReadUInt16();
entry->numData = reader->ReadInt16();
entry->cameraPosDataIdx = reader->ReadInt32();
col->camData->entries.push_back(entry);
}
uint32_t camPosCnt = reader->ReadInt32();
col->camData->cameraPositionData.reserve(camPosCnt);
for (uint32_t i = 0; i < camPosCnt; i++)
{
Ship::CameraPositionData* entry = new Ship::CameraPositionData();
entry->x = reader->ReadInt16();
entry->y = reader->ReadInt16();
entry->z = reader->ReadInt16();
col->camData->cameraPositionData.push_back(entry);
}
uint32_t waterBoxCnt = reader->ReadInt32();
col->waterBoxes.reserve(waterBoxCnt);
for (uint32_t i = 0; i < waterBoxCnt; i++)
{
Ship::WaterBoxHeader 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();
col->waterBoxes.push_back(waterBox);
}
}
Ship::PolygonEntry::PolygonEntry(BinaryReader* reader)
{
type = reader->ReadUInt16();
vtxA = reader->ReadUInt16();
vtxB = reader->ReadUInt16();
vtxC = reader->ReadUInt16();
a = reader->ReadUInt16();
b = reader->ReadUInt16();
c = reader->ReadUInt16();
d = reader->ReadUInt16();
}
Ship::WaterBoxHeader::WaterBoxHeader()
{
}

View File

@ -0,0 +1,85 @@
#pragma once
#include <vector>
#include <string>
#include "Resource.h"
#include "Vec2f.h"
#include "Vec3f.h"
#include "Color3b.h"
namespace Ship
{
class PolygonEntry
{
public:
uint16_t type;
uint16_t vtxA, vtxB, vtxC;
uint16_t a, b, c, d;
PolygonEntry(BinaryReader* reader);
};
class WaterBoxHeader
{
public:
int16_t xMin;
int16_t ySurface;
int16_t zMin;
int16_t xLength;
int16_t zLength;
int16_t pad;
int32_t properties;
WaterBoxHeader();
};
class CameraDataEntry
{
public:
uint16_t cameraSType;
int16_t numData;
int32_t cameraPosDataIdx;
};
class CameraPositionData
{
public:
int16_t x, y, z;
};
class CameraDataList
{
public:
std::vector<CameraDataEntry*> entries;
std::vector<CameraPositionData*> cameraPositionData;
};
class CollisionHeaderV0 : public ResourceFile
{
public:
int16_t absMinX, absMinY, absMinZ;
int16_t absMaxX, absMaxY, absMaxZ;
std::vector<Vec3f> vertices;
std::vector<PolygonEntry> polygons;
std::vector<uint64_t> polygonTypes;
std::vector<WaterBoxHeader> waterBoxes;
CameraDataList* camData = nullptr;
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class CollisionHeader : public Resource
{
public:
int16_t absMinX, absMinY, absMinZ;
int16_t absMaxX, absMaxY, absMaxZ;
std::vector<Vec3f> vertices;
std::vector<PolygonEntry> polygons;
std::vector<uint64_t> polygonTypes;
std::vector<WaterBoxHeader> waterBoxes;
CameraDataList* camData = nullptr;
};
}

View File

@ -0,0 +1,159 @@
#include "ConfigFile.h"
#include "spdlog/spdlog.h"
#include "GlobalCtx2.h"
#include "Window.h"
namespace Ship {
ConfigFile::ConfigFile(std::shared_ptr<GlobalCtx2> Context, const std::string& Path) : Context(Context), Path(Path), File(Path.c_str()) {
if (Path.empty()) {
SPDLOG_ERROR("ConfigFile received an empty file name");
exit(EXIT_FAILURE);
}
if (!File.read(Val)) {
if (!CreateDefaultConfig()) {
SPDLOG_ERROR("Failed to create default configs");
exit(EXIT_FAILURE);
}
}
}
ConfigFile::~ConfigFile() {
if (!Save()) {
SPDLOG_ERROR("Failed to save configs!!!");
}
SPDLOG_INFO("destruct configfile");
}
mINI::INIMap<std::string>& ConfigFile::operator[](const std::string& Section) {
return Val[Section];
}
mINI::INIMap<std::string> ConfigFile::get(const std::string& Section) {
return Val.get(Section);
}
bool ConfigFile::has(const std::string& Section) {
return Val.has(Section);
}
bool ConfigFile::remove(const std::string& Section) {
return Val.remove(Section);
}
void ConfigFile::clear() {
Val.clear();
}
std::size_t ConfigFile::size() const {
return Val.size();
}
bool ConfigFile::Save() {
return File.write(Val);
}
bool ConfigFile::CreateDefaultConfig() {
(*this)["ARCHIVE"]["Main Archive"] = "oot.otr";
(*this)["ARCHIVE"]["Patches Directory"] = "";
(*this)["CONTROLLERS"]["CONTROLLER 1"] = "Auto";
(*this)["CONTROLLERS"]["CONTROLLER 2"] = "Unplugged";
(*this)["CONTROLLERS"]["CONTROLLER 3"] = "Unplugged";
(*this)["CONTROLLERS"]["CONTROLLER 4"] = "Unplugged";
(*this)["KEYBOARD SHORTCUTS"]["KEY_FULLSCREEN"] = std::to_string(0x044);
(*this)["KEYBOARD SHORTCUTS"]["KEY_CONSOLE"] = std::to_string(0x029);
(*this)["WINDOW"]["WINDOW WIDTH"] = std::to_string(320);
(*this)["WINDOW"]["WINDOW HEIGHT"] = std::to_string(240);
(*this)["WINDOW"]["FULLSCREEN WIDTH"] = std::to_string(1920);
(*this)["WINDOW"]["FULLSCREEN HEIGHT"] = std::to_string(1080);
(*this)["WINDOW"]["FULLSCREEN"] = std::to_string(false);
(*this)["WINDOW"]["GFX BACKEND"] = "";
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_CRIGHT)] = std::to_string(0x14D);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_CLEFT)] = std::to_string(0x14B);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_CDOWN)] = std::to_string(0x150);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_CUP)] = std::to_string(0x148);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_R)] = std::to_string(0x013);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_L)] = std::to_string(0x012);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_DRIGHT)] = std::to_string(0x023);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_DLEFT)] = std::to_string(0x021);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_DDOWN)] = std::to_string(0x022);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_DUP)] = std::to_string(0x014);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_START)] = std::to_string(0x039);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_Z)] = std::to_string(0x02C);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_B)] = std::to_string(0x02E);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_A)] = std::to_string(0x02D);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_STICKRIGHT)] = std::to_string(0x020);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_STICKLEFT)] = std::to_string(0x01E);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_STICKDOWN)] = std::to_string(0x01F);
(*this)["KEYBOARD CONTROLLER BINDING 1"][STR(BTN_STICKUP)] = std::to_string(0x011);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_CRIGHT)] = std::to_string(0x14D);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_CLEFT)] = std::to_string(0x14B);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_CDOWN)] = std::to_string(0x150);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_CUP)] = std::to_string(0x148);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_R)] = std::to_string(0x013);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_L)] = std::to_string(0x012);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_DRIGHT)] = std::to_string(0x023);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_DLEFT)] = std::to_string(0x021);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_DDOWN)] = std::to_string(0x022);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_DUP)] = std::to_string(0x014);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_START)] = std::to_string(0x039);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_Z)] = std::to_string(0x02C);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_B)] = std::to_string(0x02E);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_A)] = std::to_string(0x02D);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_STICKRIGHT)] = std::to_string(0x020);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_STICKLEFT)] = std::to_string(0x01E);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_STICKDOWN)] = std::to_string(0x01F);
(*this)["KEYBOARD CONTROLLER BINDING 2"][STR(BTN_STICKUP)] = std::to_string(0x011);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_CRIGHT)] = std::to_string(0x14D);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_CLEFT)] = std::to_string(0x14B);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_CDOWN)] = std::to_string(0x150);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_CUP)] = std::to_string(0x148);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_R)] = std::to_string(0x013);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_L)] = std::to_string(0x012);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_DRIGHT)] = std::to_string(0x023);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_DLEFT)] = std::to_string(0x021);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_DDOWN)] = std::to_string(0x022);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_DUP)] = std::to_string(0x014);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_START)] = std::to_string(0x039);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_Z)] = std::to_string(0x02C);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_B)] = std::to_string(0x02E);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_A)] = std::to_string(0x02D);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_STICKRIGHT)] = std::to_string(0x020);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_STICKLEFT)] = std::to_string(0x01E);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_STICKDOWN)] = std::to_string(0x01F);
(*this)["KEYBOARD CONTROLLER BINDING 3"][STR(BTN_STICKUP)] = std::to_string(0x011);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_CRIGHT)] = std::to_string(0x14D);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_CLEFT)] = std::to_string(0x14B);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_CDOWN)] = std::to_string(0x150);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_CUP)] = std::to_string(0x148);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_R)] = std::to_string(0x013);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_L)] = std::to_string(0x012);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_DRIGHT)] = std::to_string(0x023);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_DLEFT)] = std::to_string(0x021);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_DDOWN)] = std::to_string(0x022);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_DUP)] = std::to_string(0x014);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_START)] = std::to_string(0x039);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_Z)] = std::to_string(0x02C);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_B)] = std::to_string(0x02E);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_A)] = std::to_string(0x02D);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_STICKRIGHT)] = std::to_string(0x020);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_STICKLEFT)] = std::to_string(0x01E);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_STICKDOWN)] = std::to_string(0x01F);
(*this)["KEYBOARD CONTROLLER BINDING 4"][STR(BTN_STICKUP)] = std::to_string(0x011);
(*this)["SDL CONTROLLER 1"]["GUID"] = "";
(*this)["SDL CONTROLLER 2"]["GUID"] = "";
(*this)["SDL CONTROLLER 3"]["GUID"] = "";
(*this)["SDL CONTROLLER 4"]["GUID"] = "";
return File.generate(Val);
}
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <string>
#include <memory>
#include "Lib/mINI/src/mini/ini.h"
#include "UltraController.h"
#include "LUSMacros.h"
namespace Ship {
class GlobalCtx2;
class ConfigFile {
public:
ConfigFile(std::shared_ptr<GlobalCtx2> Context, const std::string& Path);
~ConfigFile();
bool Save();
// Expose the ini values.
mINI::INIMap<std::string>& operator[](const std::string& Section);
mINI::INIMap<std::string> get(const std::string& Section);
bool has(const std::string& Section);
bool remove(const std::string& Section);
void clear();
std::size_t size() const;
std::shared_ptr<GlobalCtx2> GetContext() { return Context.lock(); }
protected:
bool CreateDefaultConfig();
private:
mINI::INIFile File;
mINI::INIStructure Val;
std::weak_ptr<GlobalCtx2> Context;
std::string Path;
};
}

View File

@ -0,0 +1,96 @@
#include "Controller.h"
#include "GlobalCtx2.h"
#include "stox.h"
#include <memory>
namespace Ship {
Controller::Controller(int32_t dwControllerNumber) : dwControllerNumber(dwControllerNumber) {
dwPressedButtons = 0;
wStickX = 0;
wStickY = 0;
wGyroX = 0;
wGyroY = 0;
Attachment = nullptr;
}
void Controller::Read(OSContPad* pad) {
ReadFromSource();
pad->button |= dwPressedButtons & 0xFFFF;
if (pad->stick_x == 0) {
if (dwPressedButtons & BTN_STICKLEFT) {
pad->stick_x = -128;
}
else if (dwPressedButtons & BTN_STICKRIGHT) {
pad->stick_x = 127;
}
else {
pad->stick_x = wStickX;
}
}
if (pad->stick_y == 0) {
if (dwPressedButtons & BTN_STICKDOWN) {
pad->stick_y = -128;
}
else if (dwPressedButtons & BTN_STICKUP) {
pad->stick_y = 127;
}
else {
pad->stick_y = wStickY;
}
}
pad->gyro_x = wGyroX;
pad->gyro_y = wGyroY;
}
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {
// Update the config value.
std::string ConfSection = GetBindingConfSection();
std::shared_ptr<ConfigFile> pConf = GlobalCtx2::GetInstance()->GetConfig();
ConfigFile& Conf = *pConf.get();
Conf[ConfSection][szButtonName] = dwScancode;
// Reload the button mapping from Config
LoadBinding();
}
void Controller::LoadBinding() {
std::string ConfSection = GetBindingConfSection();
std::shared_ptr<ConfigFile> pConf = GlobalCtx2::GetInstance()->GetConfig();
ConfigFile& Conf = *pConf.get();
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CRIGHT)])] = BTN_CRIGHT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CLEFT)])] = BTN_CLEFT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CDOWN)])] = BTN_CDOWN;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CUP)])] = BTN_CUP;
//ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CRIGHT + "_2")])] = BTN_CRIGHT;
//ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CLEFT + "_2")])] = BTN_CLEFT;
//ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CDOWN + "_2")])] = BTN_CDOWN;
//ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_CUP + "_2")])] = BTN_CUP;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_R)])] = BTN_R;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_L)])] = BTN_L;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_DRIGHT)])] = BTN_DRIGHT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_DLEFT)])] = BTN_DLEFT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_DDOWN)])] = BTN_DDOWN;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_DUP)])] = BTN_DUP;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_START)])] = BTN_START;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_Z)])] = BTN_Z;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_B)])] = BTN_B;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_A)])] = BTN_A;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_STICKRIGHT)])] = BTN_STICKRIGHT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_STICKLEFT)])] = BTN_STICKLEFT;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_STICKDOWN)])] = BTN_STICKDOWN;
ButtonMapping[Ship::stoi(Conf[ConfSection][STR(BTN_STICKUP)])] = BTN_STICKUP;
}
std::string Controller::GetConfSection() {
return GetControllerType() + " CONTROLLER " + std::to_string(GetControllerNumber() + 1);
}
std::string Controller::GetBindingConfSection() {
return GetControllerType() + " CONTROLLER BINDING " + std::to_string(GetControllerNumber() + 1);
}
}

View File

@ -0,0 +1,45 @@
#pragma once
#include <memory>
#include <map>
#include <string>
#include "stdint.h"
#include "UltraController.h"
#include "ControllerAttachment.h"
#define EXTENDED_SCANCODE_BIT (1 << 8)
#define AXIS_SCANCODE_BIT (1 << 9)
namespace Ship {
class Controller {
public:
Controller(int32_t dwControllerNumber);
void Read(OSContPad* pad);
virtual void ReadFromSource() = 0;
virtual void WriteToSource(ControllerCallback* controller) = 0;
bool isRumbling;
void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode);
std::shared_ptr<ControllerAttachment> GetAttachment() { return Attachment; }
int32_t GetControllerNumber() { return dwControllerNumber; }
protected:
int32_t dwPressedButtons;
std::map<int32_t, int32_t> ButtonMapping;
int8_t wStickX;
int8_t wStickY;
float wGyroX;
float wGyroY;
virtual std::string GetControllerType() = 0;
virtual std::string GetConfSection() = 0;
virtual std::string GetBindingConfSection() = 0;
void LoadBinding();
private:
std::shared_ptr<ControllerAttachment> Attachment;
int32_t dwControllerNumber;
};
}

View File

@ -0,0 +1,5 @@
#include "ControllerAttachment.h"
namespace Ship {
}

View File

@ -0,0 +1,8 @@
#pragma once
namespace Ship {
class ControllerAttachment {
};
}

View File

@ -0,0 +1,21 @@
#include "Cutscene.h"
void Ship::CutsceneV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
Cutscene* cs = (Cutscene*)res;
ResourceFile::ParseFileBinary(reader, res);
uint32_t numEntries = reader->ReadUInt32();
cs->commands.reserve(numEntries);
for (uint32_t i = 0; i < numEntries; i++)
{
uint32_t data = reader->ReadUInt32();
uint16_t opcode = data >> 16;
cs->commands.push_back(data);
}
//int bp = 0;
}

View File

@ -0,0 +1,28 @@
#pragma once
#include "Resource.h"
namespace Ship
{
class CutsceneV0 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class CutsceneCommand
{
public:
uint32_t commandID;
uint32_t commandIndex;
CutsceneCommand() {};
};
class Cutscene : public Resource
{
public:
//int32_t endFrame;
std::vector<uint32_t> commands;
};
}

View File

@ -0,0 +1,100 @@
#include "cvar.h"
#include <map>
#include <string>
#include <PR/ultra64/gbi.h>
std::map<std::string, CVar*> cvars;
CVar* CVar_GetVar(char* name) {
std::string key(name);
return cvars.contains(key) ? cvars[key] : nullptr;
}
extern "C" CVar* CVar_Get(char* name) {
return CVar_GetVar(name);
}
extern "C" s32 CVar_GetS32(char* name, s32 defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar != nullptr) {
if (cvar->type == CVAR_TYPE_S32)
return cvar->value.valueS32;
}
return defaultValue;
}
extern "C" float CVar_GetFloat(char* name, float defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar != nullptr) {
if (cvar->type == CVAR_TYPE_FLOAT)
return cvar->value.valueFloat;
}
return defaultValue;
}
extern "C" char* CVar_GetString(char* name, char* defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar != nullptr) {
if (cvar->type == CVAR_TYPE_STRING)
return cvar->value.valueStr;
}
return defaultValue;
}
extern "C" void CVar_SetS32(char* name, s32 value) {
CVar* cvar = CVar_Get(name);
if (!cvar) {
cvar = new CVar;
cvars[std::string(name)] = cvar;
}
cvar->type = CVAR_TYPE_S32;
cvar->value.valueS32 = value;
}
void CVar_SetFloat(char* name, float value) {
CVar* cvar = CVar_Get(name);
if (!cvar) {
cvar = new CVar;
cvars[std::string(name)] = cvar;
}
cvar->type = CVAR_TYPE_FLOAT;
cvar->value.valueFloat = value;
}
void CVar_SetString(char* name, char* value) {
CVar* cvar = CVar_Get(name);
if (!cvar) {
cvar = new CVar;
cvars[std::string(name)] = cvar;
}
cvar->type = CVAR_TYPE_STRING;
cvar->value.valueStr = value;
}
extern "C" void CVar_RegisterS32(char* name, s32 defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar == nullptr)
CVar_SetS32(name, defaultValue);
}
extern "C" void CVar_RegisterFloat(char* name, float defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar == nullptr)
CVar_SetFloat(name, defaultValue);
}
extern "C" void CVar_RegisterString(char* name, char* defaultValue) {
CVar* cvar = CVar_Get(name);
if (cvar == nullptr)
CVar_SetString(name, defaultValue);
}

View File

@ -0,0 +1,49 @@
#ifndef _CVAR_H
#define _CVAR_H
#include <PR/ultra64/gbi.h>
typedef enum CVarType { CVAR_TYPE_S32, CVAR_TYPE_FLOAT, CVAR_TYPE_STRING } CVarType;
typedef struct CVar {
char* name;
CVarType type;
union {
s32 valueS32;
float valueFloat;
char* valueStr;
} value;
} CVar;
#ifdef __cplusplus
extern "C"
{
#endif
//#include <ultra64.h>
CVar* CVar_Get(char* name);
s32 CVar_GetS32(char* name, s32 defaultValue);
float CVar_GetFloat(char* name, float defaultValue);
char* CVar_GetString(char* name, char* defaultValue);
void CVar_SetS32(char* name, s32 value);
void CVar_RegisterS32(char* name, s32 defaultValue);
void CVar_RegisterFloat(char* name, float defaultValue);
void CVar_RegisterString(char* name, char* defaultValue);
#ifdef __cplusplus
};
#endif
#ifdef __cplusplus
#include <map>
#include <string>
extern std::map<std::string, CVar*> cvars;
CVar* CVar_GetVar(char* name);
void CVar_SetFloat(char* name, float value);
void CVar_SetString(char* name, char* value);
#endif
#endif

View File

@ -0,0 +1,31 @@
#include "DisplayList.h"
#include "PR/ultra64/gbi.h"
namespace Ship
{
void DisplayListV0::ParseFileBinary(BinaryReader* reader, Resource* res)
{
DisplayList* dl = (DisplayList*)res;
ResourceFile::ParseFileBinary(reader, res);
while (reader->GetBaseAddress() % 8 != 0)
reader->ReadByte();
while (true)
{
uint64_t data = reader->ReadUInt64();
dl->instructions.push_back(data);
uint8_t opcode = data >> 24;
// These are 128-bit commands, so read an extra 64 bits...
if (opcode == G_SETTIMG_OTR || opcode == G_DL_OTR || opcode == G_VTX_OTR || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR)
dl->instructions.push_back(reader->ReadUInt64());
if (opcode == G_ENDDL)
break;
}
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <vector>
#include <string>
#include "Resource.h"
#include "Vec2f.h"
#include "Vec3f.h"
#include "Color3b.h"
namespace Ship
{
class DisplayListV0 : public ResourceFile
{
public:
void ParseFileBinary(BinaryReader* reader, Resource* res) override;
};
class DisplayList : public Resource
{
public:
std::vector<uint64_t> instructions;
};
}

View File

@ -0,0 +1,15 @@
#include "Environment.h"
#include <map>
#include <string>
std::map<std::string, std::string> environmentVars;
namespace SohUtils {
void saveEnvironmentVar(const std::string& key, const std::string& value) {
environmentVars[key] = value;
}
std::string getEnvironmentVar(const std::string& key) {
return environmentVars[key];
}
}

View File

@ -0,0 +1,8 @@
#pragma once
#include <string>
namespace SohUtils {
void saveEnvironmentVar(const std::string& key, const std::string& value);
std::string getEnvironmentVar(const std::string& key);
}

View File

@ -0,0 +1,25 @@
#include "AnimationFactory.h"
namespace Ship
{
Animation* AnimationFactory::ReadAnimation(BinaryReader* reader)
{
Animation* anim = new Animation();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
AnimationV0 Anim = AnimationV0();
Anim.ParseFileBinary(reader, anim);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return anim;
}
};

View File

@ -0,0 +1,11 @@
#include "../Animation.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class AnimationFactory
{
public:
static Animation* ReadAnimation(BinaryReader* reader);
};
}

View File

@ -0,0 +1,25 @@
#include "ArrayFactory.h"
namespace Ship
{
Array* ArrayFactory::ReadArray(BinaryReader* reader)
{
Array* arr = new Array();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
ArrayV0 arrayObj = ArrayV0();
arrayObj.ParseFileBinary(reader, arr);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return arr;
}
};

View File

@ -0,0 +1,11 @@
#include "../Array.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class ArrayFactory
{
public:
static Array* ReadArray(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "BlobFactory.h"
namespace Ship
{
Blob* BlobFactory::ReadBlob(BinaryReader* reader)
{
Blob* blob = new Blob();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
BlobV0 blobFac = BlobV0();
blobFac.ParseFileBinary(reader, blob);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return blob;
}
}

View File

@ -0,0 +1,11 @@
#include "../Blob.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class BlobFactory
{
public:
static Blob* ReadBlob(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "CollisionHeaderFactory.h"
namespace Ship
{
CollisionHeader* CollisionHeaderFactory::ReadCollisionHeader(BinaryReader* reader)
{
CollisionHeader* colHeader = new CollisionHeader();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
CollisionHeaderV0 col = CollisionHeaderV0();
col.ParseFileBinary(reader, colHeader);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return colHeader;
}
};

View File

@ -0,0 +1,11 @@
#include "../CollisionHeader.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class CollisionHeaderFactory
{
public:
static CollisionHeader* ReadCollisionHeader(BinaryReader* reader);
};
}

View File

@ -0,0 +1,25 @@
#include "CutsceneFactory.h"
namespace Ship
{
Cutscene* CutsceneFactory::ReadCutscene(BinaryReader* reader)
{
Cutscene* cs = new Cutscene();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
CutsceneV0 cutscene = CutsceneV0();
cutscene.ParseFileBinary(reader, cs);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return cs;
}
}

View File

@ -0,0 +1,11 @@
#include "../Cutscene.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class CutsceneFactory
{
public:
static Cutscene* ReadCutscene(BinaryReader* reader);
};
}

View File

@ -0,0 +1,27 @@
#include "DisplayListFactory.h"
namespace Ship
{
DisplayList* DisplayListFactory::ReadDisplayList(BinaryReader* reader)
{
DisplayList* dl = new DisplayList();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
DisplayListV0 DL = DisplayListV0();
DL.ParseFileBinary(reader, dl);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return dl;
}
}

View File

@ -0,0 +1,11 @@
#include "../DisplayList.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class DisplayListFactory
{
public:
static DisplayList* ReadDisplayList(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "MaterialFactory.h"
namespace Ship
{
Material* MaterialFactory::ReadMaterial(BinaryReader* reader)
{
Material* mat = new Material();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
MaterialV0 Material = MaterialV0();
Material.ParseFileBinary(reader, mat);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return mat;
}
}

View File

@ -0,0 +1,11 @@
#include "../Material.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class MaterialFactory
{
public:
static Material* ReadMaterial(BinaryReader* reader);
};
}

View File

@ -0,0 +1,22 @@
#include "MtxFactory.h"
namespace Ship
{
Matrix* MtxFactory::ReadMtx(BinaryReader* reader) {
Matrix* mtx = new Matrix();
uint32_t version = reader->ReadUInt32();
switch (version)
{
case 0:
{
MatrixV0 Mtx = MatrixV0();
Mtx.ParseFileBinary(reader, mtx);
}
break;
default:
//VERSION NOT SUPPORTED
break;
}
return mtx;
}
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "../Matrix.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class MtxFactory
{
public:
static Matrix* ReadMtx(BinaryReader* reader);
};
}

View File

@ -0,0 +1,71 @@
#include "OTRResourceLoader.h"
#include "OTRMaterialFactory.h"
#include "OTRSceneFactory.h"
#include "OTRCollisionHeaderFactory.h"
#include "OTRDisplayListFactory.h"
#include "OTRPlayerAnimationFactory.h"
#include "OTRSkeletonFactory.h"
#include "OTRSkeletonLimbFactory.h"
#include "OTRAnimationFactory.h"
#include "OTRVtxFactory.h"
#include "OTRCutsceneFactory.h"
#include "OTRArrayFactory.h"
#include "OTRPathFactory.h"
namespace OtrLib
{
OTRResource* OTRResourceLoader::LoadResource(BinaryReader* reader)
{
Endianess endianess = (Endianess)reader->ReadByte();
// TODO: Setup the binaryreader to use the resource's endianess
ResourceType resourceType = (ResourceType)reader->ReadUInt32();
OTRResource* result = nullptr;
switch (resourceType)
{
case ResourceType::OTRMaterial:
result = OTRMaterialFactory::ReadMaterial(reader);
break;
case ResourceType::OTRRoom:
result = OTRSceneFactory::ReadScene(reader);
break;
case ResourceType::OTRCollisionHeader:
result = OTRCollisionHeaderFactory::ReadCollisionHeader(reader);
break;
case ResourceType::OTRDisplayList:
result = OTRDisplayListFactory::ReadDisplayList(reader);
break;
case ResourceType::OTRPlayerAnimation:
result = OTRPlayerAnimationFactory::ReadPlayerAnimation(reader);
break;
case ResourceType::OTRSkeleton:
result = OTRSkeletonFactory::ReadSkeleton(reader);
break;
case ResourceType::OTRSkeletonLimb:
result = OTRSkeletonLimbFactory::ReadSkeletonLimb(reader);
break;
case ResourceType::OTRVtx:
result = OTRVtxFactory::ReadVtx(reader);
break;
case ResourceType::OTRAnimation:
result = OTRAnimationFactory::ReadAnimation(reader);
break;
case ResourceType::OTRCutscene:
result = OTRCutsceneFactory::ReadCutscene(reader);
break;
case ResourceType::OTRArray:
result = OTRArrayFactory::ReadArray(reader);
break;
case ResourceType::OTRPath:
result = OTRPathFactory::ReadPath(reader);
break;
default:
// RESOURCE TYPE NOT SUPPORTED
break;
}
return result;
}
}

View File

@ -0,0 +1,25 @@
#include "PathFactory.h"
namespace Ship
{
Path* PathFactory::ReadPath(BinaryReader* reader)
{
Path* path = new Path();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
PathV0 Path;
Path.ParseFileBinary(reader, path);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return path;
}
};

View File

@ -0,0 +1,11 @@
#include "../Path.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class PathFactory
{
public:
static Path* ReadPath(BinaryReader* reader);
};
}

View File

@ -0,0 +1,27 @@
#include "PlayerAnimationFactory.h"
namespace Ship
{
PlayerAnimation* PlayerAnimationFactory::ReadPlayerAnimation(BinaryReader* reader)
{
PlayerAnimation* anim = new PlayerAnimation();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
PlayerAnimationV0 Anim = PlayerAnimationV0();
Anim.ParseFileBinary(reader, anim);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return anim;
}
}

View File

@ -0,0 +1,11 @@
#include "../PlayerAnimation.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class PlayerAnimationFactory
{
public:
static PlayerAnimation* ReadPlayerAnimation(BinaryReader* reader);
};
}

View File

@ -0,0 +1,105 @@
#include "ResourceLoader.h"
#include "MaterialFactory.h"
#include "SceneFactory.h"
#include "CollisionHeaderFactory.h"
#include "DisplayListFactory.h"
#include "PlayerAnimationFactory.h"
#include "SkeletonFactory.h"
#include "SkeletonLimbFactory.h"
#include "AnimationFactory.h"
#include "VtxFactory.h"
#include "CutsceneFactory.h"
#include "ArrayFactory.h"
#include "PathFactory.h"
#include "TextFactory.h"
#include "TextureFactory.h"
#include "BlobFactory.h"
#include "MtxFactory.h"
#include <Utils/MemoryStream.h>
namespace Ship
{
Resource* ResourceLoader::LoadResource(std::shared_ptr<File> FileToLoad)
{
auto memStream = std::make_shared<MemoryStream>(FileToLoad->buffer.get(), FileToLoad->dwBufferSize);
auto reader = std::make_shared<BinaryReader>(memStream);
Endianess endianess = (Endianess)reader->ReadByte();
for (int i = 0; i < 3; i++)
reader->ReadByte();
// OTRTODO: Setup the binaryreader to use the resource's endianess
ResourceType resourceType = (ResourceType)reader->ReadUInt32();
Resource* result = nullptr;
switch (resourceType)
{
case ResourceType::Material:
result = MaterialFactory::ReadMaterial(reader.get());
break;
case ResourceType::Texture:
result = TextureFactory::ReadTexture(reader.get());
break;
case ResourceType::Room:
result = SceneFactory::ReadScene(reader.get());
break;
case ResourceType::CollisionHeader:
result = CollisionHeaderFactory::ReadCollisionHeader(reader.get());
break;
case ResourceType::DisplayList:
result = DisplayListFactory::ReadDisplayList(reader.get());
break;
case ResourceType::PlayerAnimation:
result = PlayerAnimationFactory::ReadPlayerAnimation(reader.get());
break;
case ResourceType::Skeleton:
result = SkeletonFactory::ReadSkeleton(reader.get());
break;
case ResourceType::SkeletonLimb:
result = SkeletonLimbFactory::ReadSkeletonLimb(reader.get());
break;
case ResourceType::Vertex:
result = VertexFactory::ReadVtx(reader.get());
break;
case ResourceType::Animation:
result = AnimationFactory::ReadAnimation(reader.get());
break;
case ResourceType::Cutscene:
result = CutsceneFactory::ReadCutscene(reader.get());
break;
case ResourceType::Array:
result = ArrayFactory::ReadArray(reader.get());
break;
case ResourceType::Path:
result = PathFactory::ReadPath(reader.get());
break;
case ResourceType::Text:
result = TextFactory::ReadText(reader.get());
break;
case ResourceType::Blob:
result = BlobFactory::ReadBlob(reader.get());
break;
case ResourceType::Matrix:
result = MtxFactory::ReadMtx(reader.get());
break;
default:
// RESOURCE TYPE NOT SUPPORTED
break;
}
if (result != nullptr) {
result->file = FileToLoad;
result->resType = resourceType;
} else {
if (FileToLoad != nullptr) {
SPDLOG_ERROR("Failed to load resource of type {} \"{}\"", resourceType, FileToLoad->path);
} else {
SPDLOG_ERROR("Failed to load resource because the file did not load.");
}
}
return result;
}
}

View File

@ -0,0 +1,11 @@
#include "../Resource.h"
#include "../File.h"
namespace Ship
{
class ResourceLoader
{
public:
static Resource* LoadResource(std::shared_ptr<File> FileToLoad);
};
}

View File

@ -0,0 +1,26 @@
#include "SceneFactory.h"
namespace Ship
{
Scene* SceneFactory::ReadScene(BinaryReader* reader)
{
Scene* scene = new Scene();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
SceneV0 Scene = SceneV0();
Scene.ParseFileBinary(reader, scene);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return scene;
}
}

View File

@ -0,0 +1,11 @@
#include "../Scene.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class SceneFactory
{
public:
static Scene* ReadScene(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "SkeletonFactory.h"
namespace Ship
{
Skeleton* SkeletonFactory::ReadSkeleton(BinaryReader* reader)
{
Skeleton* skel = new Skeleton();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
SkeletonV0 Skel = SkeletonV0();
Skel.ParseFileBinary(reader, skel);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return skel;
}
}

View File

@ -0,0 +1,11 @@
#include "../Skeleton.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class SkeletonFactory
{
public:
static Skeleton* ReadSkeleton(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "SkeletonLimbFactory.h"
namespace Ship
{
SkeletonLimb* SkeletonLimbFactory::ReadSkeletonLimb(BinaryReader* reader)
{
SkeletonLimb* limb = new SkeletonLimb();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
SkeletonLimbV0 Limb = SkeletonLimbV0();
Limb.ParseFileBinary(reader, limb);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return limb;
}
}

View File

@ -0,0 +1,11 @@
#include "../SkeletonLimb.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class SkeletonLimbFactory
{
public:
static SkeletonLimb* ReadSkeletonLimb(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "TextFactory.h"
namespace Ship
{
Text* TextFactory::ReadText(BinaryReader* reader)
{
Text* txt = new Text();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
TextV0 txtFac = TextV0();
txtFac.ParseFileBinary(reader, txt);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return txt;
}
}

View File

@ -0,0 +1,11 @@
#include "../Text.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class TextFactory
{
public:
static Text* ReadText(BinaryReader* reader);
};
}

View File

@ -0,0 +1,26 @@
#include "TextureFactory.h"
namespace Ship
{
Texture* TextureFactory::ReadTexture(BinaryReader* reader)
{
Texture* tex = new Texture();
Version version = (Version)reader->ReadUInt32();
switch (version)
{
case Version::Deckard:
{
TextureV0 texFac = TextureV0();
texFac.ParseFileBinary(reader, tex);
}
break;
default:
// VERSION NOT SUPPORTED
break;
}
return tex;
}
}

View File

@ -0,0 +1,11 @@
#include "../Texture.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class TextureFactory
{
public:
static Texture* ReadTexture(BinaryReader* reader);
};
}

View File

@ -0,0 +1,22 @@
#include "VtxFactory.h"
namespace Ship
{
Vertex* VertexFactory::ReadVtx(BinaryReader* reader) {
Vertex* vtx = new Vertex();
uint32_t version = reader->ReadUInt32();
switch (version)
{
case 0:
{
VertexV0 Vtx = VertexV0();
Vtx.ParseFileBinary(reader, vtx);
}
break;
default:
//VERSION NOT SUPPORTED
break;
}
return vtx;
}
}

View File

@ -0,0 +1,12 @@
#pragma once
#include "../Vertex.h"
#include "Utils/BinaryReader.h"
namespace Ship
{
class VertexFactory
{
public:
static Vertex* ReadVtx(BinaryReader* reader);
};
}

View File

@ -0,0 +1 @@
#include "File.h"

View File

@ -0,0 +1,22 @@
#pragma once
#include <string>
#include <memory>
#include "GlobalCtx2.h"
namespace Ship {
class Archive;
class File
{
public:
std::shared_ptr<Archive> parent;
std::string path;
std::shared_ptr<char[]> buffer;
uint32_t dwBufferSize;
bool bIsLoaded = false;
bool bHasLoadError = false;
std::condition_variable FileLoadNotifier;
std::mutex FileLoadMutex;
};
}

View File

@ -0,0 +1,133 @@
#include "GameSettings.h"
// Audio
#include <PR/ultra64/sptask.h>
#include <PR/ultra64/pi.h>
#include <PR/ultra64/message.h>
#include <PR/ultra64/types.h>
#include "ConfigFile.h"
#include "Cvar.h"
#include "GlobalCtx2.h"
#include "SohImGuiImpl.h"
#include "stox.h"
#include "../../soh/include/z64audio.h"
#include <string>
#include "SohHooks.h"
#define ABS(var) var < 0 ? -(var) : var
using namespace Ship;
namespace Game {
bool DeSyncAudio = false;
SoHConfigType Settings;
const std::string ConfSection = DEBUG_SECTION;
const std::string AudioSection = AUDIO_SECTION;
const std::string ControllerSection = CONTROLLER_SECTION;
const std::string EnhancementSection = ENHANCEMENTS_SECTION;
void UpdateAudio() {
Audio_SetGameVolume(SEQ_BGM_MAIN, Settings.audio.music_main);
Audio_SetGameVolume(SEQ_BGM_SUB, Settings.audio.music_sub);
Audio_SetGameVolume(SEQ_FANFARE, Settings.audio.fanfare);
Audio_SetGameVolume(SEQ_SFX, Settings.audio.sfx);
}
void LoadSettings() {
const std::shared_ptr<ConfigFile> pConf = GlobalCtx2::GetInstance()->GetConfig();
ConfigFile& Conf = *pConf;
// Debug
SohImGui::console->opened = stob(Conf[ConfSection]["console"]);
Settings.debug.menu_bar = stob(Conf[ConfSection]["menu_bar"]);
Settings.debug.soh = stob(Conf[ConfSection]["soh_debug"]);
Settings.debug.n64mode = stob(Conf[ConfSection]["n64_mode"]);
// Enhancements
Settings.enhancements.fast_text = stob(Conf[EnhancementSection]["fast_text"]);
CVar_SetS32(const_cast<char*>("gFastText"), Settings.enhancements.fast_text);
Settings.enhancements.disable_lod = stob(Conf[EnhancementSection]["disable_lod"]);
CVar_SetS32(const_cast<char*>("gDisableLOD"), Settings.enhancements.disable_lod);
Settings.enhancements.animated_pause_menu = stob(Conf[EnhancementSection]["animated_pause_menu"]);
CVar_SetS32(const_cast<char*>("gPauseLiveLink"), Settings.enhancements.animated_pause_menu);
Settings.enhancements.debug_mode = stob(Conf[EnhancementSection]["debug_mode"]);
CVar_SetS32(const_cast<char*>("gDebugEnabled"), Settings.enhancements.debug_mode);
Settings.audio.master = Ship::stof(Conf[AudioSection]["master"]);
CVar_SetFloat(const_cast<char*>("gGameMasterVolume"), Settings.audio.master);
Settings.audio.music_main = Ship::stof(Conf[AudioSection]["music_main"]);
CVar_SetFloat(const_cast<char*>("gMainMusicVolume"), Settings.audio.music_main);
Settings.audio.music_sub = Ship::stof(Conf[AudioSection]["music_sub"]);
CVar_SetFloat(const_cast<char*>("gSubMusicVolume"), Settings.audio.music_sub);
Settings.audio.sfx = Ship::stof(Conf[AudioSection]["sfx"]);
CVar_SetFloat(const_cast<char*>("gSFXMusicVolume"), Settings.audio.sfx);
Settings.audio.fanfare = Ship::stof(Conf[AudioSection]["fanfare"]);
CVar_SetFloat(const_cast<char*>("gFanfareVolume"), Settings.audio.fanfare);
Settings.controller.gyro_sensitivity = Ship::stof(Conf[ControllerSection]["gyro_sensitivity"]);
CVar_SetFloat(const_cast<char*>("gGyroSensitivity"), Settings.controller.gyro_sensitivity);
Settings.controller.rumble_strength = Ship::stof(Conf[ControllerSection]["rumble_strength"]);
CVar_SetFloat(const_cast<char*>("gRumbleStrength"), Settings.controller.rumble_strength);
Settings.controller.input_scale = Ship::stof(Conf[ControllerSection]["input_scale"]);
CVar_SetFloat(const_cast<char*>("gInputScale"), Settings.controller.input_scale);
Settings.controller.input_enabled = stob(Conf[ControllerSection]["input_enabled"]);
CVar_SetS32(const_cast<char*>("gInputEnabled"), Settings.controller.input_enabled);
UpdateAudio();
}
void SaveSettings() {
const std::shared_ptr<ConfigFile> pConf = GlobalCtx2::GetInstance()->GetConfig();
ConfigFile& Conf = *pConf;
// Debug
Conf[ConfSection]["console"] = std::to_string(SohImGui::console->opened);
Conf[ConfSection]["menu_bar"] = std::to_string(Settings.debug.menu_bar);
Conf[ConfSection]["soh_debug"] = std::to_string(Settings.debug.soh);
Conf[ConfSection]["n64_mode"] = std::to_string(Settings.debug.n64mode);
// Audio
Conf[AudioSection]["master"] = std::to_string(Settings.audio.master);
Conf[AudioSection]["music_main"] = std::to_string(Settings.audio.music_main);
Conf[AudioSection]["music_sub"] = std::to_string(Settings.audio.music_sub);
Conf[AudioSection]["sfx"] = std::to_string(Settings.audio.sfx);
Conf[AudioSection]["fanfare"] = std::to_string(Settings.audio.fanfare);
// Enhancements
Conf[EnhancementSection]["fast_text"] = std::to_string(Settings.enhancements.fast_text);
Conf[EnhancementSection]["disable_lod"] = std::to_string(Settings.enhancements.disable_lod);
Conf[EnhancementSection]["animated_pause_menu"] = std::to_string(Settings.enhancements.animated_pause_menu);
Conf[EnhancementSection]["debug_mode"] = std::to_string(Settings.enhancements.debug_mode);
Conf[ControllerSection]["gyro_sensitivity"] = std::to_string(Settings.controller.gyro_sensitivity);
Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength);
Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale);
Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled);
Conf.Save();
}
void InitSettings() {
ModInternal::registerHookListener({ AUDIO_INIT, [](HookEvent ev) {
UpdateAudio();
}});
}
void SetSeqPlayerVolume(SeqPlayers playerId, float volume) {
Audio_SetGameVolume(playerId, volume);
}
}

View File

@ -0,0 +1,56 @@
#pragma once
struct SoHConfigType {
// Debug
struct {
bool soh = false;
bool n64mode = false;
bool menu_bar = false;
bool soh_sink = true;
} debug;
// Audio
struct {
float master = 1.0f;
float music_main = 1.0f;
float fanfare = 1.0f;
float sfx = 1.0f;
float music_sub = 1.0f;
} audio;
// Enhancements
struct {
bool fast_text = false;
bool disable_lod = false;
bool animated_pause_menu = false;
bool debug_mode = false;
} enhancements;
struct {
float gyro_sensitivity = 1.0f;
float rumble_strength = 1.0f;
float input_scale = 1.0f;
bool input_enabled = false;
} controller;
};
enum SeqPlayers {
/* 0 */ SEQ_BGM_MAIN,
/* 1 */ SEQ_FANFARE,
/* 2 */ SEQ_SFX,
/* 3 */ SEQ_BGM_SUB,
/* 4 */ SEQ_MAX
};
#define DEBUG_SECTION "DEBUG SETTINGS"
#define AUDIO_SECTION "AUDIO SETTINGS"
#define CONTROLLER_SECTION "CONTROLLER SECTION"
#define ENHANCEMENTS_SECTION "ENHANCEMENT SETTINGS"
namespace Game {
extern SoHConfigType Settings;
void InitSettings();
void LoadSettings();
void SaveSettings();
void SetSeqPlayerVolume(SeqPlayers playerId, float volume);
}

View File

@ -0,0 +1,85 @@
#include "GlobalCtx2.h"
#include <iostream>
#include <vector>
#include "ResourceMgr.h"
#include "Window.h"
#include "spdlog/async.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/sohconsole_sink.h"
#include "ModManager.h"
namespace Ship {
std::weak_ptr<GlobalCtx2> GlobalCtx2::Context;
ModManager* INSTANCE;
std::shared_ptr<GlobalCtx2> GlobalCtx2::GetInstance() {
return Context.lock();
}
std::shared_ptr<GlobalCtx2> GlobalCtx2::CreateInstance(const std::string& Name) {
if (Context.expired()) {
auto Shared = std::make_shared<GlobalCtx2>(Name);
Context = Shared;
Shared->InitWindow();
return Shared;
} else {
SPDLOG_DEBUG("Trying to create a context when it already exists.");
}
return GetInstance();
}
GlobalCtx2::GlobalCtx2(const std::string& Name) : Name(Name), MainPath(""), PatchesPath("") {
}
GlobalCtx2::~GlobalCtx2() {
SPDLOG_INFO("destruct GlobalCtx2");
INSTANCE->Exit();
}
void GlobalCtx2::InitWindow() {
InitLogging();
Config = std::make_shared<ConfigFile>(GlobalCtx2::GetInstance(), "shipofharkinian.ini");
MainPath = (*Config)["ARCHIVE"]["Main Archive"];
if (MainPath.empty()) {
MainPath = "oot.otr";
}
PatchesPath = (*Config)["ARCHIVE"]["Patches Directory"];
if (PatchesPath.empty()) {
PatchesPath = "./";
}
ResMan = std::make_shared<ResourceMgr>(GlobalCtx2::GetInstance(), MainPath, PatchesPath);
Win = std::make_shared<Window>(GlobalCtx2::GetInstance());
if (!ResMan->DidLoadSuccessfully())
{
MessageBox(NULL, L"Main OTR file not found!", L"Uh oh", MB_OK);
exit(1);
}
INSTANCE = new ModManager(ResMan);
INSTANCE->Init();
}
void GlobalCtx2::InitLogging() {
try {
// Setup Logging
spdlog::init_thread_pool(8192, 1);
auto SohConsoleSink = std::make_shared<spdlog::sinks::soh_sink_mt>();
auto ConsoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
auto FileSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/" + GetName() + ".log", 1024 * 1024 * 10, 10);
SohConsoleSink->set_level(spdlog::level::trace);
ConsoleSink->set_level(spdlog::level::trace);
FileSink->set_level(spdlog::level::trace);
std::vector<spdlog::sink_ptr> Sinks{ ConsoleSink, FileSink, SohConsoleSink };
Logger = std::make_shared<spdlog::async_logger>(GetName(), Sinks.begin(), Sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
GetLogger()->set_level(spdlog::level::trace);
GetLogger()->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%@] [%l] %v");
spdlog::register_logger(GetLogger());
spdlog::set_default_logger(GetLogger());
}
catch (const spdlog::spdlog_ex& ex) {
std::cout << "Log initialization failed: " << ex.what() << std::endl;
}
}
}

View File

@ -0,0 +1,41 @@
#pragma once
#ifdef __cplusplus
#include <memory>
#include "spdlog/spdlog.h"
#include "ConfigFile.h"
namespace Ship {
class ResourceMgr;
class Window;
class GlobalCtx2 {
public:
static std::shared_ptr<GlobalCtx2> GetInstance();
static std::shared_ptr<GlobalCtx2> CreateInstance(const std::string& Name);
std::string GetName() { return Name; }
std::shared_ptr<Window> GetWindow() { return Win; }
std::shared_ptr<ResourceMgr> GetResourceManager() { return ResMan; }
std::shared_ptr<spdlog::logger> GetLogger() { return Logger; }
std::shared_ptr<ConfigFile> GetConfig() { return Config; }
GlobalCtx2(const std::string& Name);
~GlobalCtx2();
protected:
void InitWindow();
void InitLogging();
private:
static std::weak_ptr <GlobalCtx2> Context;
std::shared_ptr<spdlog::logger> Logger;
std::shared_ptr<Window> Win;
std::shared_ptr<ConfigFile> Config; // Config needs to be after the Window because we call the Window during it's destructor.
std::shared_ptr<ResourceMgr> ResMan;
std::string Name;
std::string MainPath;
std::string PatchesPath;
};
}
#endif

View File

@ -0,0 +1,56 @@
#include "KeyboardController.h"
#include "GlobalCtx2.h"
namespace Ship {
KeyboardController::KeyboardController(int32_t dwControllerNumber) : Controller(dwControllerNumber) {
LoadBinding();
}
KeyboardController::~KeyboardController() {
}
bool KeyboardController::PressButton(int32_t dwScancode) {
if (ButtonMapping.contains(dwScancode)) {
dwPressedButtons |= ButtonMapping[dwScancode];
return true;
}
return false;
}
bool KeyboardController::ReleaseButton(int32_t dwScancode) {
if (ButtonMapping.contains(dwScancode)) {
dwPressedButtons &= ~ButtonMapping[dwScancode];
return true;
}
return false;
}
void KeyboardController::ReleaseAllButtons() {
dwPressedButtons = 0;
}
void KeyboardController::ReadFromSource() {
wStickX = 0;
wStickY = 0;
}
void KeyboardController::WriteToSource(ControllerCallback* controller)
{
}
std::string KeyboardController::GetControllerType() {
return "KEYBOARD";
}
std::string KeyboardController::GetConfSection() {
return GetControllerType() + " CONTROLLER " + std::to_string(GetControllerNumber() + 1);
}
std::string KeyboardController::GetBindingConfSection() {
return GetControllerType() + " CONTROLLER BINDING " + std::to_string(GetControllerNumber() + 1);
}
}

View File

@ -0,0 +1,23 @@
#pragma once
#include "Controller.h"
#include <string>
namespace Ship {
class KeyboardController : public Controller {
public:
KeyboardController(int32_t dwControllerNumber);
~KeyboardController();
void ReadFromSource();
void WriteToSource(ControllerCallback* controller);
bool PressButton(int32_t dwScancode);
bool ReleaseButton(int32_t dwScancode);
void ReleaseAllButtons();
protected:
std::string GetControllerType();
std::string GetConfSection();
std::string GetBindingConfSection();
};
}

View File

@ -0,0 +1,3 @@
#pragma once
#define STR(define) (std::string(#define))

View File

@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/Emill/n64-fast3d-engine
branch = master
commit = 7353aa30570682ef3bfe31cffc115f1561163270
parent = 36d578a78dff501c380e24b2c41fda62c173ea20
method = merge
cmdver = 0.4.3

View File

@ -0,0 +1,19 @@
Copyright (c) 2020 Emill, MaikelChan
Redistribution and use in source forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form are not allowed.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,33 @@
# Nintendo 64 Fast3D renderer
Implementation of a Fast3D renderer for games built originally for the Nintendo 64 platform.
For rendering OpenGL, Direct3D 11 and Direct3D 12 are supported.
Supported windowing systems are GLX (used on Linux), DXGI (used on Windows) and SDL (generic).
# Usage
See `gfx_pc.h`. You will also need a copy of `PR/gbi.h`, found in libultra.
First call `gfx_init(struct GfxWindowManagerAPI *wapi, struct GfxRenderingAPI *rapi, const char *game_name, bool start_in_fullscreen)` and supply the desired backends at program start.
Some callbacks can be set on `wapi`. See `gfx_window_manager_api.h` for more info.
Each game main loop iteration should look like this:
```C
gfx_start_frame(); // Handles input events such as keyboard and window events
// perform game logic here
gfx_run(cmds); // submit display list and render a frame
// do more expensive work here, such as play audio
gfx_end_frame(); // this just waits until the frame is shown on the screen (vsync), to provide correct game timing
```
When you are ready to start the main loop, call `wapi->main_loop(one_iteration_func)`.
For the best experience, please change the Vtx and Mtx structures to use floats instead of fixed point arithmetic (`GBI_FLOATS`).
# License
See LICENSE.txt. Redistributions are allowed only in source form, not in binary form.

View File

@ -0,0 +1,491 @@
#ifndef ULTRA64_ABI_H
#define ULTRA64_ABI_H
/* Audio commands: */
#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
/*
* Audio flags
*/
#define A_INIT 0x01
#define A_CONTINUE 0x00
#define A_LOOP 0x02
#define A_OUT 0x02
#define A_LEFT 0x02
#define A_RIGHT 0x00
#define A_VOL 0x04
#define A_RATE 0x00
#define A_AUX 0x08
#define A_NOAUX 0x00
#define A_MAIN 0x00
#define A_MIX 0x10
/*
* Data Structures.
*/
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 gain : 16;
u32 addr;
} Aadpcm;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 gain : 16;
u32 addr;
} Apolef;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 pad1 : 16;
u32 addr;
} Aenvelope;
typedef struct {
u32 cmd : 8;
u32 pad1 : 8;
u32 dmem : 16;
u32 pad2 : 16;
u32 count : 16;
} Aclearbuff;
typedef struct {
u32 cmd : 8;
u32 pad1 : 8;
u32 pad2 : 16;
u32 inL : 16;
u32 inR : 16;
} Ainterleave;
typedef struct {
u32 cmd : 8;
u32 pad1 : 24;
u32 addr;
} Aloadbuff;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 pad1 : 16;
u32 addr;
} Aenvmixer;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 gain : 16;
u32 dmemi : 16;
u32 dmemo : 16;
} Amixer;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 dmem2 : 16;
u32 addr;
} Apan;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 pitch : 16;
u32 addr;
} Aresample;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 pad1 : 16;
u32 addr;
} Areverb;
typedef struct {
u32 cmd : 8;
u32 pad1 : 24;
u32 addr;
} Asavebuff;
typedef struct {
u32 cmd : 8;
u32 pad1 : 24;
u32 pad2 : 2;
u32 number : 4;
u32 base : 24;
} Asegment;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 dmemin : 16;
u32 dmemout : 16;
u32 count : 16;
} Asetbuff;
typedef struct {
u32 cmd : 8;
u32 flags : 8;
u32 vol : 16;
u32 voltgt : 16;
u32 volrate : 16;
} Asetvol;
typedef struct {
u32 cmd : 8;
u32 pad1 : 8;
u32 dmemin : 16;
u32 dmemout : 16;
u32 count : 16;
} Admemmove;
typedef struct {
u32 cmd : 8;
u32 pad1 : 8;
u32 count : 16;
u32 addr;
} Aloadadpcm;
typedef struct {
u32 cmd : 8;
u32 pad1 : 8;
u32 pad2 : 16;
u32 addr;
} Asetloop;
/*
* Generic Acmd Packet
*/
typedef struct {
u32 w0;
u32 w1;
} Awords;
typedef union {
Awords words;
Aadpcm adpcm;
Apolef polef;
Aclearbuff clearbuff;
Aenvelope envelope;
Ainterleave interleave;
Aloadbuff loadbuff;
Aenvmixer envmixer;
Aresample resample;
Areverb reverb;
Asavebuff savebuff;
Asegment segment;
Asetbuff setbuff;
Asetvol setvol;
Admemmove dmemmove;
Aloadadpcm loadadpcm;
Amixer mixer;
Asetloop setloop;
long long int force_union_align; /* dummy, force alignment */
} Acmd;
/*
* ADPCM State
*/
#define ADPCMVSIZE 8
#define ADPCMFSIZE 16
typedef short ADPCM_STATE[ADPCMFSIZE];
/*
* Pole filter state
*/
typedef short POLEF_STATE[4];
/*
* Resampler state
*/
typedef short RESAMPLE_STATE[16];
/*
* Resampler constants
*/
#define UNITY_PITCH 0x8000
#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */
/*
* Enveloper/Mixer state
*/
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 = (u32)(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 = (u32)(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 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 aS8Dec(pkt, a1, a2) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = _SHIFTL(A_S8DEC, 24, 8) | _SHIFTL(a1, 16, 8); \
_a->words.w1 = (u32)(a2); \
}
#define aClearBuffer(pkt, d, c) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \
_a->words.w1 = (u32)(c); \
}
#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 = (u32)(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 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 aLoadBuffer(pkt, s, d, c) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = (_SHIFTL(A_LOADBUFF, 24, 8) | \
_SHIFTL((c) >> 4, 16, 8) | _SHIFTL(d, 0, 16)); \
_a->words.w1 = (u32)(s); \
}
#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 = (u32)(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 = (u32)(s); \
}
#define aSaveBuffer(pkt, s, d, c) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = (_SHIFTL(A_SAVEBUFF, 24, 8) | \
_SHIFTL((c) >> 4, 16, 8) | _SHIFTL(s, 0, 16)); \
_a->words.w1 = (u32)(d); \
}
#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 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 = (u32)(tr); \
}
#define aSetLoop(pkt, a) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \
_a->words.w1 = (u32)(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 aLoadADPCM(pkt, c, d) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \
_a->words.w1 = (u32)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 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 = (u32)(addr); \
}
#define aDuplicate(pkt, count, dmemi, dmemo, a4) \
{ \
Acmd *_a = (Acmd *)pkt; \
\
_a->words.w0 = (_SHIFTL(A_DUPLICATE, 24, 8) | \
_SHIFTL(count, 16, 8) | _SHIFTL(dmemi, 0, 16)); \
_a->words.w1 = _SHIFTL(dmemo, 16, 16) | _SHIFTL(a4, 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); \
}
#endif /* ULTRA64_ABI_H */

View File

@ -0,0 +1,177 @@
#ifndef ULTRA64_CONTROLLER_H
#define ULTRA64_CONTROLLER_H
#include "message.h"
#define SIAccessQueueSize 2
#define BLOCKSIZE 32
#define MAXCONTROLLERS 4
#define PFS_ONE_PAGE 8
#define PFS_PAGE_SIZE (BLOCKSIZE*PFS_ONE_PAGE)
#define CONT_CMD_REQUEST_STATUS 0
#define CONT_CMD_READ_BUTTON 1
#define CONT_CMD_READ_MEMPACK 2
#define CONT_CMD_WRITE_MEMPACK 3
#define CONT_CMD_READ_EEPROM 4
#define CONT_CMD_WRITE_EEPROM 5
#define CONT_CMD_RESET 0xFF
#define CONT_CMD_REQUEST_STATUS_TX 1
#define CONT_CMD_READ_BUTTON_TX 1
#define CONT_CMD_READ_MEMPACK_TX 3
#define CONT_CMD_WRITE_MEMPACK_TX 35
#define CONT_CMD_READ_EEPROM_TX 2
#define CONT_CMD_WRITE_EEPROM_TX 10
#define CONT_CMD_RESET_TX 1
#define CONT_CMD_REQUEST_STATUS_RX 3
#define CONT_CMD_READ_BUTTON_RX 4
#define CONT_CMD_READ_MEMPACK_RX 33
#define CONT_CMD_WRITE_MEMPACK_RX 1
#define CONT_CMD_READ_EEPROM_RX 8
#define CONT_CMD_WRITE_EEPROM_RX 1
#define CONT_CMD_RESET_RX 3
#define CONT_CMD_NOP 0xFF
#define CONT_CMD_END 0xFE // Indicates end of a command
#define CONT_CMD_EXE 1 // Set pif ram status byte to this to do a command
#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 DIR_STATUS_EMPTY 0
#define DIR_STATUS_UNKNOWN 1
#define DIR_STATUS_OCCUPIED 2
#define PFS_FORCE 1
#define PFS_DELETE 1
#define PFS_LABEL_AREA 7
#define PFS_ERR_NOPACK 1
/* controller errors */
#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
/* Controller status */
#define CONT_CARD_ON 0x01
#define CONT_CARD_PULL 0x02
#define CONT_ADDR_CRC_ER 0x04
#define CONT_EEPROM_BUSY 0x80
/* 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_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
typedef struct {
/* 0x00 */ uintptr_t ram[15];
/* 0x3C */ u32 status;
} OSPifRam; // size = 0x40
typedef struct {
/* 0x00 */ u16 type;
/* 0x02 */ u8 status;
/* 0x03 */ u8 err_no;
} OSContStatus; // size = 0x04
typedef struct {
/* 0x00 */ u16 button;
/* 0x02 */ s8 stick_x;
/* 0x03 */ s8 stick_y;
/* 0x04 */ u8 err_no;
/* 0x05 */ f32 gyro_x;
/* 0x09 */ f32 gyro_y;
} OSContPad; // size = 0x0D
typedef struct {
/* 0x00 */ u8 rumble;
/* 0x01 */ u8 ledColor;
} ControllerCallback; // size = 0x02
typedef struct {
/* 0x00 */ void* address;
/* 0x04 */ u8 databuffer[32];
/* 0x24 */ u8 addressCrc;
/* 0x25 */ u8 dataCrc;
/* 0x26 */ u8 CONT_ERR_CONTRFAILno;
} OSContRamIo; // size = 0x28
// Original name: __OSContRequesFormat
typedef struct {
/* 0x00 */ u8 align;
/* 0x01 */ u8 txsize;
/* 0x02 */ u8 rxsize;
/* 0x03 */ u8 poll;
/* 0x04 */ u8 typeh;
/* 0x05 */ u8 typel;
/* 0x06 */ u8 status;
/* 0x07 */ u8 align1;
} __OSContRequestHeader; // size = 0x8
// Original name: __OSContRequesHeaderFormatShort
typedef struct {
/* 0x00 */ u8 txsize;
/* 0x01 */ u8 rxsize;
/* 0x02 */ u8 poll;
/* 0x03 */ u8 typeh;
/* 0x04 */ u8 typel;
/* 0x05 */ u8 status;
} __OSContRequestHeaderAligned; // size = 0x6
// Original Name: __OSContRamReadFormat
typedef struct {
/* 0x00 */ u8 unk_00;
/* 0x01 */ u8 txsize;
/* 0x02 */ u8 rxsize;
/* 0x03 */ u8 poll;
/* 0x04 */ u8 hi;
/* 0x05 */ u8 lo;
/* 0x06 */ u8 data[BLOCKSIZE];
/* 0x26 */ u8 datacrc;
} __OSContRamHeader; // size = 0x27
// Original name: __OSContReadFormat
typedef struct {
/* 0x00 */ u8 align;
/* 0x01 */ u8 txsize;
/* 0x02 */ u8 rxsize;
/* 0x03 */ u8 poll;
/* 0x04 */ u16 button;
/* 0x06 */ s8 joyX;
/* 0x07 */ s8 joyY;
} __OSContReadHeader; // size = 0x8
#endif

View File

@ -0,0 +1,18 @@
#ifndef ULTRA64_CONVERT_H
#define ULTRA64_CONVERT_H
#define OS_CLOCK_RATE 62500000LL
#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4)
#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL))
#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL))
#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_K1_TO_PHYSICAL(x) (0)//(u32)(((char*)(x)-0xA0000000))
#define OS_PHYSICAL_TO_K0(x) (void*)(((u32)(x)+0x80000000))
#define OS_PHYSICAL_TO_K1(x) (void*)(((u32)(x)+0xA0000000))
#endif

View File

@ -0,0 +1,45 @@
#ifndef ULTRA64_EXCEPTION_H
#define ULTRA64_EXCEPTION_H
#include "types.h"
// Interrupt masks
#define OS_IM_NONE 0x00000001
#define OS_IM_SW1 0x00000501
#define OS_IM_SW2 0x00000601
#define OS_IM_CART 0x00000C01
#define OS_IM_PRENMI 0x00001401
#define OS_IM_RDBWRITE 0x00002401
#define OS_IM_RDBREAD 0x00004401
#define OS_IM_COUNTER 0x00008401
#define OS_IM_CPU 0x0000FF01
#define OS_IM_SP 0x00010401
#define OS_IM_SI 0x00020401
#define OS_IM_AI 0x00040401
#define OS_IM_VI 0x00080401
#define OS_IM_PI 0x00100401
#define OS_IM_DP 0x00200401
#define OS_IM_ALL 0x003FFF01
#define RCP_IMASK 0x003F0000
#define RCP_IMASKSHIFT 16
typedef u32 OSIntMask;
typedef u32 OSHWIntr;
typedef struct {
/* 0x00 */ void* callback;
/* 0x04 */ void* sp;
} __osHwInt; // size = 0x08
OSIntMask osSetIntMask(OSIntMask);
void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*callback)(void), void *sp);
void __osGetHWIntrRoutine(OSHWIntr interrupt, s32 (**callbackOut)(void), void **spOut);
void __osSetGlobalIntMask(OSHWIntr mask);
void __osResetGlobalIntMask(OSHWIntr mask);
extern __osHwInt __osHwIntTable[];
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,379 @@
#ifndef GS2DEX_H
#define GS2DEX_H
#ifdef _LANGUAGE_C_PLUS_PLUS
extern "C" {
#endif
/*===========================================================================*
* 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)))
/*===========================================================================*
* Data structures for S2DEX microcode
*===========================================================================*/
/*---------------------------------------------------------------------------*
* Background
*---------------------------------------------------------------------------*/
#define G_BGLT_LOADBLOCK 0x0033
#define G_BGLT_LOADTILE 0xfff4
#define G_BG_FLAG_FLIPS 0x01
#define G_BG_FLAG_FLIPT 0x10
/* Non scalable background plane */
typedef struct {
u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */
u16 imageW; /* width of the texture (u10.2) */
s16 frameX; /* upper-left position of transferred frame (s10.2) */
u16 frameW; /* width of transferred frame (u10.2) */
u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */
u16 imageH; /* height of the texture (u10.2) */
s16 frameY; /* upper-left position of transferred frame (s10.2) */
u16 frameH; /* height of transferred frame (u10.2) */
u64 *imagePtr; /* texture source address on DRAM */
u16 imageLoad; /* which to use, LoadBlock or LoadTile */
u8 imageFmt; /* format of texel - G_IM_FMT_* */
u8 imageSiz; /* size of texel - G_IM_SIZ_* */
u16 imagePal; /* pallet number */
u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */
/* The following is set in the initialization routine guS2DInitBg(). There is no need for the user to set it. */
u16 tmemW; /* TMEM width and Word size of frame 1 line.
At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz)
At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */
u16 tmemH; /* height of TMEM loadable at a time (s13.2) 4 times value
When the normal texture, 512/tmemW*4
When the CI texture, 256/tmemW*4 */
u16 tmemLoadSH; /* SH value
At LoadBlock, tmemSize/2-1
At LoadTile, tmemW*16-1 */
u16 tmemLoadTH; /* TH value or Stride value
At LoadBlock, GS_CALC_DXT(tmemW)
At LoadTile, tmemH-1 */
u16 tmemSizeW; /* skip value of imagePtr for image 1-line
At LoadBlock, tmemW*2
At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */
u16 tmemSize; /* skip value of imagePtr for 1-loading
= tmemSizeW*tmemH */
} uObjBg_t; /* 40 bytes */
/* Scalable background plane */
typedef struct {
u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */
u16 imageW; /* width of texture (u10.2) */
s16 frameX; /* upper-left position of transferred frame (s10.2) */
u16 frameW; /* width of transferred frame (u10.2) */
u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */
u16 imageH; /* height of texture (u10.2) */
s16 frameY; /* upper-left position of transferred frame (s10.2) */
u16 frameH; /* height of transferred frame (u10.2) */
u64 *imagePtr; /* texture source address on DRAM */
u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */
u8 imageFmt; /* format of texel - G_IM_FMT_* */
u8 imageSiz; /* size of texel - G_IM_SIZ_* */
u16 imagePal; /* pallet number */
u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */
u16 scaleW; /* scale value of X-direction (u5.10) */
u16 scaleH; /* scale value of Y-direction (u5.10) */
s32 imageYorig; /* start point of drawing on image (s20.5) */
u8 padding[4];
} uObjScaleBg_t; /* 40 bytes */
typedef union {
uObjBg_t b;
uObjScaleBg_t s;
long long int force_structure_alignment;
} uObjBg;
/*---------------------------------------------------------------------------*
* 2D Objects
*---------------------------------------------------------------------------*/
#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 */
u16 scaleW; /* u5.10 Scaling of u5.10 width direction */
u16 imageW; /* u10.5 width of u10.5 texture (length of S-direction) */
u16 paddingX; /* Unused - Always 0 */
s16 objY; /* s10.2 OBJ y-coordinate of s10.2 OBJ upper-left end */
u16 scaleH; /* u5.10 Scaling of u5.10 height direction */
u16 imageH; /* u10.5 height of u10.5 texture (length of T-direction) */
u16 paddingY; /* Unused - Always 0 */
u16 imageStride; /* folding width of texel (In units of 64bit word) */
u16 imageAdrs; /* texture header position in TMEM (In units of 64bit word) */
u8 imageFmt; /* format of texel - G_IM_FMT_* */
u8 imageSiz; /* size of texel - G_IM_SIZ_* */
u8 imagePal; /* pallet number (0-7) */
u8 imageFlags; /* The display flag - G_OBJ_FLAG_FLIP* */
} uObjSprite_t; /* 24 bytes */
typedef union {
uObjSprite_t s;
long long int force_structure_alignment;
} uObjSprite;
/*---------------------------------------------------------------------------*
* 2D Matrix
*---------------------------------------------------------------------------*/
typedef struct {
s32 A, B, C, D; /* s15.16 */
s16 X, Y; /* s10.2 */
u16 BaseScaleX; /* u5.10 */
u16 BaseScaleY; /* u5.10 */
} uObjMtx_t; /* 24 bytes */
typedef union {
uObjMtx_t m;
long long int force_structure_alignment;
} uObjMtx;
typedef struct {
s16 X, Y; /* s10.2 */
u16 BaseScaleX; /* u5.10 */
u16 BaseScaleY; /* u5.10 */
} uObjSubMtx_t; /* 8 bytes */
typedef union {
uObjSubMtx_t m;
long long int force_structure_alignment;
} uObjSubMtx;
/*---------------------------------------------------------------------------*
* Loading into TMEM
*---------------------------------------------------------------------------*/
#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))))
typedef struct {
u32 type; /* G_OBJLT_TXTRBLOCK divided into types */
u64 *image; /* texture source address on DRAM */
u16 tmem; /* loaded TMEM word address (8byteWORD) */
u16 tsize; /* Texture size, Specified by macro GS_TB_TSIZE() */
u16 tline; /* width of Texture 1-line, Specified by macro GS_TB_TLINE() */
u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */
u32 flag; /* STATE flag */
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)
typedef struct {
u32 type; /* G_OBJLT_TXTRTILE divided into types */
u64 *image; /* texture source address on DRAM */
u16 tmem; /* loaded TMEM word address (8byteWORD)*/
u16 twidth; /* width of Texture (Specified by macro GS_TT_TWIDTH()) */
u16 theight; /* height of Texture (Specified by macro GS_TT_THEIGHT()) */
u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */
u32 flag; /* STATE flag */
u32 mask; /* STATE mask */
} uObjTxtrTile_t; /* 24 bytes */
#define GS_PAL_HEAD(head) ((head)+256)
#define GS_PAL_NUM(num) ((num)-1)
typedef struct {
u32 type; /* G_OBJLT_TLUT divided into types */
u64 *image; /* texture source address on DRAM */
u16 phead; /* pallet number of load header (Between 256 and 511) */
u16 pnum; /* loading pallet number -1 */
u16 zero; /* Assign 0 all the time */
u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12)*/
u32 flag; /* STATE flag */
u32 mask; /* STATE mask */
} uObjTxtrTLUT_t; /* 24 bytes */
typedef union {
uObjTxtrBlock_t block;
uObjTxtrTile_t tile;
uObjTxtrTLUT_t tlut;
long long int force_structure_alignment;
} uObjTxtr;
/*---------------------------------------------------------------------------*
* Loading into TMEM & 2D Objects
*---------------------------------------------------------------------------*/
typedef struct {
uObjTxtr txtr;
uObjSprite sprite;
} uObjTxSprite; /* 48 bytes */
/*===========================================================================*
* 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
#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
#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))
/*---------------------------------------------------------------------------*
* 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)
/*---------------------------------------------------------------------------*
* 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)
/*---------------------------------------------------------------------------*
* 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)
/*---------------------------------------------------------------------------*
* 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); }
/*---------------------------------------------------------------------------*
* Set general status
*---------------------------------------------------------------------------*/
#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))
/*---------------------------------------------------------------------------*
* 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 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 | \
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
/*===========================================================================*
* External functions
*===========================================================================*/
extern u64 gspS2DEX_fifoTextStart[], gspS2DEX_fifoTextEnd[];
extern u64 gspS2DEX_fifoDataStart[], gspS2DEX_fifoDataEnd[];
extern u64 gspS2DEX_fifo_dTextStart[], gspS2DEX_fifo_dTextEnd[];
extern u64 gspS2DEX_fifo_dDataStart[], gspS2DEX_fifo_dDataEnd[];
extern u64 gspS2DEX2_fifoTextStart[], gspS2DEX2_fifoTextEnd[];
extern u64 gspS2DEX2_fifoDataStart[], gspS2DEX2_fifoDataEnd[];
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*/
extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8);
extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *);
#else
extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8);
extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *);
#endif
#ifdef _LANGUAGE_C_PLUS_PLUS
}
#endif
#endif /* GS2DEX_H */
/*======== End of gs2dex.h ========*/

View File

@ -0,0 +1,8 @@
#ifndef ULTRA64_GU_H
#define ULTRA64_GU_H
#define GU_PI 3.1415926
#define ROUND(x) (s32)(((x) >= 0.0) ? ((x) + 0.5) : ((x) - 0.5))
#endif

View File

@ -0,0 +1,90 @@
#ifndef ULTRA64_HARDWARE_H
#define ULTRA64_HARDWARE_H
#define HW_REG(reg, type) *(volatile type*)((reg) | 0xa0000000)
#define AI_DRAM_ADDR_REG 0x04500000
#define AI_LEN_REG 0x04500004
#define AI_CONTROL_REG 0x04500008
#define AI_STATUS_REG 0x0450000C
#define AI_STATUS_AI_FULL (1 << 31)
#define AI_STATUS_AI_BUSY (1 << 30)
#define AI_DACRATE_REG 0x04500010
#define AI_BITRATE_REG 0x04500014
#define VI_STATUS_REG 0x04400000
#define VI_CONTROL_REG 0x04400000
#define VI_ORIGIN_REG 0x04400004
#define VI_DRAM_ADDR_REG 0x04400004
#define VI_WIDTH_REG 0x04400008
#define VI_H_WIDTH_REG 0x04400008
#define VI_INTR_REG 0x0440000C
#define VI_V_INTER_REG 0x0440000C
#define VI_CURRENT_REG 0x04400010
#define VI_V_CURRENT_LINE_REG 0x04400010
#define VI_BURST_REG 0x04400014
#define VI_TIMING_REG 0x04400014
#define VI_V_SYNC_REG 0x04400018 //VI vertical sync
#define VI_H_SYNC_REG 0x0440001C //VI horizontal sync
#define VI_LEAP_REG 0x04400020 //VI horizontal sync leap
#define VI_H_SYNC_LEAP_REG 0x04400020
#define VI_H_START_REG 0x04400024 //VI horizontal video
#define VI_H_VIDEO_REG 0x04400024
#define VI_V_START_REG 0x04400028 //VI vertical video
#define VI_V_VIDEO_REG 0x04400028
#define VI_V_BURST_REG 0x0440002C //VI vertical burst
#define VI_X_SCALE_REG 0x04400030 //VI x-scale
#define VI_Y_SCALE_REG 0x04400034 //VI y-scale
#define SP_IMEM_START 0x04001000
#define SP_DMEM_START 0x04000000
#define SP_MEM_ADDR_REG 0x04040000
#define SP_DRAM_ADDR_REG 0x04040004
#define SP_RD_LEN_REG 0x04040008
#define SP_WR_LEN_REG 0x0404000C
#define SP_STATUS_REG 0x04040010
#define SP_PC_REG 0x04080000
#define PI_DRAM_ADDR_REG 0x04600000 //PI DRAM address
#define PI_CART_ADDR_REG 0x04600004 //PI pbus (cartridge) address
#define PI_RD_LEN_REG 0x04600008 //PI read length
#define PI_WR_LEN_REG 0x0460000C //PI write length
#define PI_STATUS_REG 0x04600010 //PI status
#define PI_BSD_DOM1_LAT_REG 0x04600014 //PI dom1 latency
#define PI_DOMAIN1_REG 0x04600014
#define PI_BSD_DOM1_PWD_REG 0x04600018 //PI dom1 pulse width
#define PI_BSD_DOM1_PGS_REG 0x0460001C //PI dom1 page size
#define PI_BSD_DOM1_RLS_REG 0x04600020 //PI dom1 release
#define PI_BSD_DOM2_LAT_REG 0x04600024 //PI dom2 latency
#define PI_DOMAIN2_REG 0x04600024
#define PI_BSD_DOM2_PWD_REG 0x04600028 //PI dom2 pulse width
#define PI_BSD_DOM2_PGS_REG 0x0460002C //PI dom2 page size
#define PI_BSD_DOM2_RLS_REG 0x04600030 //PI dom2 release
#define PI_STATUS_BUSY 0x1
#define PI_STATUS_IOBUSY 0x2
#define PI_STATUS_ERROR 0x3
#define PI_STATUS_RESET_CONTROLLER 0x1
#define PI_STATUS_CLEAR_INTR 0x2
#define SI_DRAM_ADDR_REG 0x04800000
#define SI_PIF_ADDR_RD64B_REG 0x04800004
#define SI_PIF_ADDR_WR64B_REG 0x04800010
#define SI_STATUS_REG 0x04800018
#define SI_STATUS_DMA_BUSY 0x1
#define SI_STATUS_IO_READ_BUSY 0x2
#define SI_STATUS_DMA_ERROR 0x8
#define SI_STATUS_INTERRUPT (1 << 12)
#define PIF_RAM_START 0x1FC007C0
#define MI_INIT_MODE_REG 0x04300000
#define MI_MODE_REG MI_INIT_MODE_REG
#define MI_VERSION_REG 0x04300004
#define MI_INTR_REG 0x04300008
#define MI_INTR_MASK_REG 0x0430000C
#endif

View File

@ -0,0 +1,24 @@
#ifndef ULTRA64_INTERNAL_H
#define ULTRA64_INTERNAL_H
#include "pi.h"
typedef struct {
/* 0x00 */ u32 initialized;
/* 0x04 */ OSThread* mgrThread;
/* 0x08 */ OSMesgQueue* cmdQueue;
/* 0x0C */ OSMesgQueue* eventQueue;
/* 0x10 */ OSMesgQueue* acccessQueue;
/* 0x14 */ s32 (*piDmaCallback)(s32, u32, void*, size_t);
/* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, u32, void*, size_t);
} OSMgrArgs; // size = 0x1C
typedef struct {
/* 0x00 */ OSMesgQueue* queue;
/* 0x04 */ OSMesg msg;
} __OSEventState; // size = 0x08
extern OSMgrArgs __osPiDevMgr;
extern __OSEventState __osEventStateTab[];
#endif

View File

@ -0,0 +1,6 @@
#ifndef ULTRA64_INTERRUPT_H
#define ULTRA64_INTERRUPT_H
typedef u32 OSIntMask;
#endif

View File

@ -0,0 +1,44 @@
#ifndef ULTRA64_MBI_H
#define ULTRA64_MBI_H
/*
* Header file for the Media Binary Interface
*
* NOTE: This file is included by the RSP microcode, so any C-specific
* constructs must be bracketed by #ifdef _LANGUAGE_C
*
*/
/*
* the SHIFT macros are used to build display list commands, inserting
* bit-fields into a 32-bit word. They take a value, a shift amount,
* and a width.
*
* For the left shift, the lower bits of the value are masked,
* then shifted left.
*
* For the right shift, the value is shifted right, then the lower bits
* are masked.
*
* (NOTE: _SHIFTL(v, 0, 32) won't work, just use an assignment)
*
*/
#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
#define _SHIFTR(v, s, w) \
((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))
#define G_ON (1)
#define G_OFF (0)
#include <stdint.h>
#include "gbi.h"
#include "abi.h"
#define NUM_SEGMENTS (16)
#define SEGMENT_OFFSET(a) ((u32)(a) & 0x00FFFFFF)
#define SEGMENT_NUMBER(a) (((u32)(a) << 4) >> 28)
#define SEGMENT_ADDR(num, off) (((num) << 24) + (off))
#endif

View File

@ -0,0 +1,39 @@
#ifndef ULTRA64_MESSAGE_H
#define ULTRA64_MESSAGE_H
#include "thread.h"
#define OS_MESG_NOBLOCK 0
#define OS_MESG_BLOCK 1
typedef void* OSMesg;
typedef u32 OSEvent;
#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 */
typedef struct OSMesgQueue {
/* 0x00 */ OSThread* mtqueue;
/* 0x04 */ OSThread* fullqueue;
/* 0x08 */ s32 validCount;
/* 0x0C */ s32 first;
/* 0x10 */ s32 msgCount;
/* 0x14 */ OSMesg* msg;
} OSMesgQueue; // size = 0x18
#endif

View File

@ -0,0 +1,15 @@
#ifndef ULTRA64_MOTOR_H
#define ULTRA64_MOTOR_H
#include "pfs.h"
#define MOTOR_START 1
#define MOTOR_STOP 0
#define osMotorStart(x) __osMotorAccess((x), MOTOR_START)
#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP)
s32 __osMotorAccess(OSPfs* pfs, u32 vibrate);
s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel);
#endif

View File

@ -0,0 +1,137 @@
#ifndef ULTRA64_PFS_H
#define ULTRA64_PFS_H
#include "message.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 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
/* File System flag */
#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
/* Definition for page usage */
#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 */
/* Definition for bank */
#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_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_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)
typedef struct {
/* 0x00 */ s32 status;
/* 0x04 */ OSMesgQueue* queue;
/* 0x08 */ s32 channel;
/* 0x0C */ u8 id[32];
/* 0x2C */ u8 label[32];
/* 0x4C */ s32 version;
/* 0x50 */ s32 dir_size;
/* 0x54 */ s32 inode_table; /* block location */
/* 0x58 */ s32 minode_table; /* mirrioring inode_table */
/* 0x5C */ s32 dir_table; /* block location */
/* 0x60 */ s32 inodeStartPage; /* page # */
/* 0x64 */ u8 banks;
/* 0x65 */ u8 activebank;
} OSPfs; // size = 0x68
typedef struct {
/* 0x00 */ u32 file_size; /* bytes */
/* 0x04 */ u32 game_code;
/* 0x08 */ u16 company_code;
/* 0x0C */ char ext_name[4];
/* 0x10 */ char game_name[16];
} OSPfsState; // size = 0x20
typedef union {
struct {
/* 0x00 */ u8 bank;
/* 0x01 */ u8 page;
} inode_t;
/* 0x00 */ u16 ipage;
} __OSInodeUnit; // size = 0x02
typedef struct {
/* 0x00 */ __OSInodeUnit inodePage[128];
} __OSInode; // size = 0x100
typedef struct {
/* 0x00 */ u32 game_code;
/* 0x04 */ u16 company_code;
/* 0x06 */ __OSInodeUnit start_page;
/* 0x08 */ u8 status;
/* 0x09 */ s8 reserved;
/* 0x0A */ u16 data_sum;
/* 0x0C */ u8 ext_name[PFS_FILE_EXT_LEN];
/* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN];
} __OSDir; // size = 0x20
typedef struct {
/* 0x00 */ u32 repaired;
/* 0x04 */ u32 random;
/* 0x08 */ u64 serialMid;
/* 0x10 */ u64 serialLow;
/* 0x18 */ u16 deviceid;
/* 0x1A */ u8 banks;
/* 0x1B */ u8 version;
/* 0x1C */ u16 checksum;
/* 0x1E */ u16 invertedChecksum;
} __OSPackId; // size = 0x20
typedef struct {
/* 0x000 */ __OSInode inode;
/* 0x100 */ u8 bank;
/* 0x101 */ u8 map[PFS_INODE_DIST_MAP];
} __OSInodeCache; // size = 0x202
#endif

View File

@ -0,0 +1,83 @@
#ifndef ULTRA64_PI_H
#define ULTRA64_PI_H
#include "message.h"
typedef struct {
/* 0x00 */ u32 errStatus;
/* 0x04 */ void* dramAddr;
/* 0x08 */ void* C2Addr;
/* 0x0C */ u32 sectorSize;
/* 0x10 */ u32 C1ErrNum;
/* 0x14 */ u32 C1ErrSector[4];
} __OSBlockInfo; // size = 0x24
typedef struct {
/* 0x00 */ u32 cmdType;
/* 0x04 */ u16 transferMode;
/* 0x06 */ u16 blockNum;
/* 0x08 */ s32 sectorNum;
/* 0x0C */ u32 devAddr;
/* 0x10 */ u32 bmCtlShadow;
/* 0x14 */ u32 seqCtlShadow;
/* 0x18 */ __OSBlockInfo block[2];
} __OSTranxInfo; // size = 0x60
typedef struct OSPiHandle {
/* 0x00 */ struct OSPiHandle* next;
/* 0x04 */ u8 type;
/* 0x05 */ u8 latency;
/* 0x06 */ u8 pageSize;
/* 0x07 */ u8 relDuration;
/* 0x08 */ u8 pulse;
/* 0x09 */ u8 domain;
/* 0x0C */ u32 baseAddress;
/* 0x10 */ u32 speed;
/* 0x14 */ __OSTranxInfo transferInfo;
} OSPiHandle; // size = 0x74
typedef struct {
/* 0x00 */ u8 type;
/* 0x04 */ u32 address;
} OSPiInfo; // size = 0x08
typedef struct {
/* 0x00 */ u16 type;
/* 0x02 */ u8 pri;
/* 0x03 */ u8 status;
/* 0x04 */ OSMesgQueue* retQueue;
} OSIoMesgHdr; // size = 0x08
typedef struct {
/* 0x00 */ OSIoMesgHdr hdr;
/* 0x08 */ void* dramAddr;
/* 0x0C */ u32 devAddr;
/* 0x10 */ size_t size;
/* 0x14 */ OSPiHandle* piHandle;
} OSIoMesg; // size = 0x18
#define OS_READ 0 // device -> RDRAM
#define OS_WRITE 1 // device <- RDRAM
#define OS_OTHERS 2 // for disk drive transfers
#define PI_DOMAIN1 0
#define PI_DOMAIN2 1
#define OS_MESG_TYPE_LOOPBACK 10
#define OS_MESG_TYPE_DMAREAD 11
#define OS_MESG_TYPE_DMAWRITE 12
#define OS_MESG_TYPE_VRETRACE 13
#define OS_MESG_TYPE_COUNTER 14
#define OS_MESG_TYPE_EDMAREAD 15
#define OS_MESG_TYPE_EDMAWRITE 16
#define OS_MESG_PRI_NORMAL 0
#define OS_MESG_PRI_HIGH 1
#define DEVICE_TYPE_CART 0 /* ROM cartridge */
#define DEVICE_TYPE_BULK 1 /* ROM bulk */
#define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */
#define DEVICE_TYPE_SRAM 3 /* SRAM */
#define DEVICE_TYPE_INIT 7 /* initial value */
#endif

View File

@ -0,0 +1,33 @@
#ifndef ULTRA64_PRINTF_H
#define ULTRA64_PRINTF_H
#include "types.h"
typedef struct {
/* 0x0 */ union {
/* 0x0 */ s64 ll;
/* 0x0 */ f64 ld;
} v;
/* 0x8 */ char* s;
/* 0xC */ s32 n0;
/* 0x10 */ s32 nz0;
/* 0x14 */ s32 n1;
/* 0x18 */ s32 nz1;
/* 0x1C */ s32 n2;
/* 0x20 */ s32 nz2;
/* 0x24 */ s32 prec;
/* 0x28 */ s32 width;
/* 0x2C */ u32 nchar;
/* 0x30 */ u32 flags;
/* 0x34 */ u8 qual;
} _Pft; // size = 0x38
typedef void* (*PrintCallback)(void*, const char*, u32);
#define FLAGS_SPACE 1
#define FLAGS_PLUS 2
#define FLAGS_MINUS 4
#define FLAGS_HASH 8
#define FLAGS_ZERO 16
#endif

View File

@ -0,0 +1,367 @@
#ifndef ULTRA64_R4300_H
#define ULTRA64_R4300_H
#ifdef _LANGUAGE_C
#include "types.h"
#define U32(x) ((u32)x)
#define C_REG(x) (x)
#else
#define U32(x) (x)
#define C_REG(x) $x
#endif
// Segment base addresses and sizes
#define KUBASE 0
#define KUSIZE 0x80000000
#define K0BASE 0x80000000
#define K0SIZE 0x20000000
#define K1BASE 0xA0000000
#define K1SIZE 0x20000000
#define K2BASE 0xC0000000
#define K2SIZE 0x20000000
// Exception vectors
#define SIZE_EXCVEC 0x80 // Size of an exc. vec
#define UT_VEC K0BASE // utlbmiss vector
#define R_VEC (K1BASE + 0x1FC00000) // reset vector
#define XUT_VEC (K0BASE + 0x80) // extended address tlbmiss
#define ECC_VEC (K0BASE + 0x100) // Ecc exception vector
#define E_VEC (K0BASE + 0x180) // Gen. exception vector
// Address conversion macros
#define K0_TO_K1(x) (U32(x) | 0xA0000000) // kseg0 to kseg1
#define K1_TO_K0(x) (U32(x) & 0x9FFFFFFF) // kseg1 to kseg0
#define K0_TO_PHYS(x) (U32(x) & 0x1FFFFFFF) // kseg0 to physical
#define K1_TO_PHYS(x) (U32(x) & 0x1FFFFFFF) // kseg1 to physical
#define KDM_TO_PHYS(x) (U32(x) & 0x1FFFFFFF) // direct mapped to physical
#define PHYS_TO_K0(x) (U32(x) | 0x80000000) // physical to kseg0
#define PHYS_TO_K1(x) (U32(x) | 0xA0000000) // physical to kseg1
// Address predicates
#define IS_KSEG0(x) (U32(x) >= K0BASE && U32(x) < K1BASE)
#define IS_KSEG1(x) (U32(x) >= K1BASE && U32(x) < K2BASE)
#define IS_KSEGDM(x) (U32(x) >= K0BASE && U32(x) < K2BASE)
#define IS_KSEG2(x) (U32(x) >= K2BASE && U32(x) < KPTE_SHDUBASE)
#define IS_KPTESEG(x) (U32(x) >= KPTE_SHDUBASE)
#define IS_KUSEG(x) (U32(x) < K0BASE)
// TLB size constants
#define NTLBENTRIES 31 /* entry 31 is reserved by rdb */
#define TLBHI_VPN2MASK 0xFFFFE000
#define TLBHI_VPN2SHIFT 13
#define TLBHI_PIDMASK 0xFF
#define TLBHI_PIDSHIFT 0
#define TLBHI_NPID 255 // 255 to fit in 8 bits
#define TLBLO_PFNMASK 0x3FFFFFC0
#define TLBLO_PFNSHIFT 6
#define TLBLO_CACHMASK 0x38 // cache coherency algorithm
#define TLBLO_CACHSHIFT 3
#define TLBLO_UNCACHED 0x10 // not cached
#define TLBLO_NONCOHRNT 0x18 // Cacheable non-coherent
#define TLBLO_EXLWR 0x28 // Exclusive write
#define TLBLO_D 0x4 // writeable
#define TLBLO_V 0x2 // valid bit
#define TLBLO_G 0x1 // global access bit
#define TLBINX_PROBE 0x80000000
#define TLBINX_INXMASK 0x3F
#define TLBINX_INXSHIFT 0
#define TLBRAND_RANDMASK 0x3F
#define TLBRAND_RANDSHIFT 0
#define TLBWIRED_WIREDMASK 0x3F
#define TLBCTXT_BASEMASK 0xFF800000
#define TLBCTXT_BASESHIFT 23
#define TLBCTXT_BASEBITS 9
#define TLBCTXT_VPNMASK 0x7FFFF0
#define TLBCTXT_VPNSHIFT 4
#define TLBPGMASK_4K 0x0
#define TLBPGMASK_16K 0x6000
#define TLBPGMASK_64K 0x1E000
/*
* Status register
*/
#define SR_CUMASK 0xF0000000 // coproc usable bits
#define SR_CU3 0x80000000 // Coprocessor 3 usable
#define SR_CU2 0x40000000 // Coprocessor 2 usable
#define SR_CU1 0x20000000 // Coprocessor 1 usable
#define SR_CU0 0x10000000 // Coprocessor 0 usable
#define SR_RP 0x08000000 // Reduced power (quarter speed)
#define SR_FR 0x04000000 // MIPS III FP register mode
#define SR_RE 0x02000000 // Reverse endian
#define SR_ITS 0x01000000 // Instruction trace support
#define SR_BEV 0x00400000 // Use boot exception vectors
#define SR_TS 0x00200000 // TLB shutdown
#define SR_SR 0x00100000 // Soft reset occured
#define SR_CH 0x00040000 // Cache hit for last 'cache' op
#define SR_CE 0x00020000 // Create ECC
#define SR_DE 0x00010000 // ECC of parity does not cause error
// Interrupt enable bits
// (NOTE: bits set to 1 enable the corresponding level interrupt)
#define SR_IMASK 0x0000FF00 // Interrupt mask
#define SR_IMASK8 0x00000000 // mask level 8
#define SR_IMASK7 0x00008000 // mask level 7
#define SR_IMASK6 0x0000C000 // mask level 6
#define SR_IMASK5 0x0000E000 // mask level 5
#define SR_IMASK4 0x0000F000 // mask level 4
#define SR_IMASK3 0x0000F800 // mask level 3
#define SR_IMASK2 0x0000FC00 // mask level 2
#define SR_IMASK1 0x0000FE00 // mask level 1
#define SR_IMASK0 0x0000FF00 // mask level 0
#define SR_IBIT8 0x00008000 // bit level 8
#define SR_IBIT7 0x00004000 // bit level 7
#define SR_IBIT6 0x00002000 // bit level 6
#define SR_IBIT5 0x00001000 // bit level 5
#define SR_IBIT4 0x00000800 // bit level 4
#define SR_IBIT3 0x00000400 // bit level 3
#define SR_IBIT2 0x00000200 // bit level 2
#define SR_IBIT1 0x00000100 // bit level 1
#define SR_IMASKSHIFT 8
#define SR_KX 0x00000080 // extended-addr TLB vec in kernel
#define SR_SX 0x00000040 // xtended-addr TLB vec supervisor
#define SR_UX 0x00000020 // xtended-addr TLB vec in user mode
#define SR_KSU_MASK 0x00000018 // mode mask
#define SR_KSU_USR 0x00000010 // user mode
#define SR_KSU_SUP 0x00000008 // supervisor mode
#define SR_KSU_KER 0x00000000 // kernel mode
#define SR_ERL 0x00000004 // Error level, 1=>cache error
#define SR_EXL 0x00000002 // Exception level, 1=>exception
#define SR_IE 0x00000001 // interrupt enable, 1=>enable
// Cause Register
#define CAUSE_BD 0x80000000 // Branch delay slot
#define CAUSE_CEMASK 0x30000000 // coprocessor error
#define CAUSE_CESHIFT 28
// Interrupt pending bits
#define CAUSE_IP8 0x00008000 // External level 8 pending - COMPARE
#define CAUSE_IP7 0x00004000 // External level 7 pending - INT4
#define CAUSE_IP6 0x00002000 // External level 6 pending - INT3
#define CAUSE_IP5 0x00001000 // External level 5 pending - INT2
#define CAUSE_IP4 0x00000800 // External level 4 pending - INT1
#define CAUSE_IP3 0x00000400 // External level 3 pending - INT0
#define CAUSE_SW2 0x00000200 // Software level 2 pending
#define CAUSE_SW1 0x00000100 // Software level 1 pending
#define CAUSE_IPMASK 0x0000FF00 // Pending interrupt mask
#define CAUSE_IPSHIFT 8
#define CAUSE_EXCMASK 0x0000007C // Cause code bits
#define CAUSE_EXCSHIFT 2
// Cause register exception codes
#define EXC_CODE(x) ((x) << 2)
// Hardware exception codes
#define EXC_INT EXC_CODE(0) // interrupt
#define EXC_MOD EXC_CODE(1) // TLB mod
#define EXC_RMISS EXC_CODE(2) // Read TLB Miss
#define EXC_WMISS EXC_CODE(3) // Write TLB Miss
#define EXC_RADE EXC_CODE(4) // Read Address Error
#define EXC_WADE EXC_CODE(5) // Write Address Error
#define EXC_IBE EXC_CODE(6) // Instruction Bus Error
#define EXC_DBE EXC_CODE(7) // Data Bus Error
#define EXC_SYSCALL EXC_CODE(8) // SYSCALL
#define EXC_BREAK EXC_CODE(9) // BREAKpoint
#define EXC_II EXC_CODE(10) // Illegal Instruction
#define EXC_CPU EXC_CODE(11) // CoProcessor Unusable
#define EXC_OV EXC_CODE(12) // OVerflow
#define EXC_TRAP EXC_CODE(13) // Trap exception
#define EXC_VCEI EXC_CODE(14) // Virt. Coherency on Inst. fetch
#define EXC_FPE EXC_CODE(15) // Floating Point Exception
#define EXC_WATCH EXC_CODE(23) // Watchpoint reference
#define EXC_VCED EXC_CODE(31) // Virt. Coherency on data read
// C0_PRID Defines
#define C0_IMPMASK 0xFF00
#define C0_IMPSHIFT 8
#define C0_REVMASK 0xFF
#define C0_MAJREVMASK 0xF0
#define C0_MAJREVSHIFT 4
#define C0_MINREVMASK 0xF
// Coprocessor 0 operations
#define C0_READI 0x1 // read ITLB entry addressed by C0_INDEX
#define C0_WRITEI 0x2 // write ITLB entry addressed by C0_INDEX
#define C0_WRITER 0x6 // write ITLB entry addressed by C0_RAND
#define C0_PROBE 0x8 // probe for ITLB entry addressed by TLBHI
#define C0_RFE 0x10 // restore for exception
// 'cache' instruction definitions
// Target cache
#define CACH_PI 0x0 // specifies primary inst. cache
#define CACH_PD 0x1 // primary data cache
#define CACH_SI 0x2 // secondary instruction cache
#define CACH_SD 0x3 // secondary data cache
// Cache operations
#define C_IINV 0x0 // index invalidate (inst, 2nd inst)
#define C_IWBINV 0x0 // index writeback inval (d, sd)
#define C_ILT 0x4 // index load tag (all)
#define C_IST 0x8 // index store tag (all)
#define C_CDX 0xC // create dirty exclusive (d, sd)
#define C_HINV 0x10 // hit invalidate (all)
#define C_HWBINV 0x14 // hit writeback inv. (d, sd)
#define C_FILL 0x14 // fill (i)
#define C_HWB 0x18 // hit writeback (i, d, sd)
#define C_HSV 0x1C // hit set virt. (si, sd)
// Cache size definitions
#define ICACHE_SIZE 0x4000 // 16K
#define ICACHE_LINESIZE 32 // 8 words
#define ICACHE_LINEMASK (ICACHE_LINESIZE - 1)
#define DCACHE_SIZE 0x2000 // 8K
#define DCACHE_LINESIZE 16 // 4 words
#define DCACHE_LINEMASK (DCACHE_LINESIZE - 1)
// C0_CONFIG register definitions
#define CONFIG_CM 0x80000000 // 1 == Master-Checker enabled
#define CONFIG_EC 0x70000000 // System Clock ratio
#define CONFIG_EC_1_1 0x6 // System Clock ratio 1 :1
#define CONFIG_EC_3_2 0x7 // System Clock ratio 1.5 :1
#define CONFIG_EC_2_1 0x0 // System Clock ratio 2 :1
#define CONFIG_EC_3_1 0x1 // System Clock ratio 3 :1
#define CONFIG_EP 0x0F000000 // Transmit Data Pattern
#define CONFIG_SB 0x00C00000 // Secondary cache block size
#define CONFIG_SS 0x00200000 // Split scache: 0 == I&D combined
#define CONFIG_SW 0x00100000 // scache port: 0==128, 1==64
#define CONFIG_EW 0x000C0000 // System Port width: 0==64, 1==32
#define CONFIG_SC 0x00020000 // 0 -> 2nd cache present
#define CONFIG_SM 0x00010000 // 0 -> Dirty Shared Coherency enable
#define CONFIG_BE 0x00008000 // Endian-ness: 1 --> BE
#define CONFIG_EM 0x00004000 // 1 -> ECC mode, 0 -> parity
#define CONFIG_EB 0x00002000 // Block order:1->sequent,0->subblock
#define CONFIG_IC 0x00000E00 // Primary Icache size
#define CONFIG_DC 0x000001C0 // Primary Dcache size
#define CONFIG_IB 0x00000020 // Icache block size
#define CONFIG_DB 0x00000010 // Dcache block size
#define CONFIG_CU 0x00000008 // Update on Store-conditional
#define CONFIG_K0 0x00000007 // K0SEG Coherency algorithm
#define CONFIG_UNCACHED 0x00000002 // K0 is uncached
#define CONFIG_NONCOHRNT 0x00000003
#define CONFIG_COHRNT_EXLWR 0x00000005
#define CONFIG_SB_SHFT 22 // shift SB to bit position 0
#define CONFIG_IC_SHFT 9 // shift IC to bit position 0
#define CONFIG_DC_SHFT 6 // shift DC to bit position 0
#define CONFIG_BE_SHFT 15 // shift BE to bit position 0
// C0_TAGLO definitions for setting/getting cache states and physaddr bits
#define SADDRMASK 0xFFFFE000 // 31..13 -> scache paddr bits 35..17
#define SVINDEXMASK 0x00000380 // 9..7: prim virt index bits 14..12
#define SSTATEMASK 0x00001C00 // bits 12..10 hold scache line state
#define SINVALID 0x00000000 // invalid --> 000 == state 0
#define SCLEANEXCL 0x00001000 // clean exclusive --> 100 == state 4
#define SDIRTYEXCL 0x00001400 // dirty exclusive --> 101 == state 5
#define SECC_MASK 0x0000007F // low 7 bits are ecc for the tag
#define SADDR_SHIFT 4 // shift STagLo (31..13) to 35..17
#define PADDRMASK 0xFFFFFF00 // PTagLo31..8->prim paddr bits35..12
#define PADDR_SHIFT 4 // roll bits 35..12 down to 31..8
#define PSTATEMASK 0x00C0 // bits 7..6 hold primary line state
#define PINVALID 0x0000 // invalid --> 000 == state 0
#define PCLEANEXCL 0x0080 // clean exclusive --> 10 == state 2
#define PDIRTYEXCL 0x00C0 // dirty exclusive --> 11 == state 3
#define PPARITY_MASK 0x0001 // low bit is parity bit (even).
// C0_CACHE_ERR definitions.
#define CACHERR_ER 0x80000000 // 0: inst ref, 1: data ref
#define CACHERR_EC 0x40000000 // 0: primary, 1: secondary
#define CACHERR_ED 0x20000000 // 1: data error
#define CACHERR_ET 0x10000000 // 1: tag error
#define CACHERR_ES 0x08000000 // 1: external ref, e.g. snoo
#define CACHERR_EE 0x04000000 // error on SysAD bus
#define CACHERR_EB 0x02000000 // complicated, see spec.
#define CACHERR_EI 0x01000000 // complicated, see spec.
#define CACHERR_SIDX_MASK 0x003FFFF8 // secondary cache index
#define CACHERR_PIDX_MASK 0x00000007 // primary cache index
#define CACHERR_PIDX_SHIFT 12 // bits 2..0 are paddr14..12
/*
* R4000 family supports hardware watchpoints:
* C0_WATCHLO:
* bits 31..3 are bits 31..3 of physaddr to watch
* bit 2: reserved; must be written as 0.
* bit 1: when set causes a watchpoint trap on load accesses to paddr.
* bit 0: when set traps on stores to paddr;
* C0_WATCHHI
* bits 31..4 are reserved and must be written as zeros.
* bits 3..0 are bits 35..32 of the physaddr to watch
*/
#define WATCHLO_WTRAP 0x00000001
#define WATCHLO_RTRAP 0x00000002
#define WATCHLO_ADDRMASK 0xFFFFFFF8
#define WATCHLO_VALIDMASK 0xFFFFFFFB
#define WATCHHI_VALIDMASK 0x0000000F
// Coprocessor 0 registers
#define C0_INX C_REG(0)
#define C0_RAND C_REG(1)
#define C0_ENTRYLO0 C_REG(2)
#define C0_ENTRYLO1 C_REG(3)
#define C0_CONTEXT C_REG(4)
#define C0_PAGEMASK C_REG(5) // page mask
#define C0_WIRED C_REG(6) // # wired entries in tlb
#define C0_BADVADDR C_REG(8)
#define C0_COUNT C_REG(9) // free-running counter
#define C0_ENTRYHI C_REG(10)
#define C0_COMPARE C_REG(11) // counter comparison reg.
#define C0_SR C_REG(12)
#define C0_CAUSE C_REG(13)
#define C0_EPC C_REG(14)
#define C0_PRID C_REG(15) // revision identifier
#define C0_CONFIG C_REG(16) // hardware configuration
#define C0_LLADDR C_REG(17) // load linked address
#define C0_WATCHLO C_REG(18) // watchpoint
#define C0_WATCHHI C_REG(19) // watchpoint
#define C0_ECC C_REG(26) // S-cache ECC and primary parity
#define C0_CACHE_ERR C_REG(27) // cache error status
#define C0_TAGLO C_REG(28) // cache operations
#define C0_TAGHI C_REG(29) // cache operations
#define C0_ERROR_EPC C_REG(30) // ECC error prg. counter
// floating-point status register
#define C1_FPCSR C_REG(31)
#define FPCSR_FS 0x01000000 // flush denorm to zero
#define FPCSR_C 0x00800000 // condition bit
#define FPCSR_CE 0x00020000 // cause: unimplemented operation
#define FPCSR_CV 0x00010000 // cause: invalid operation
#define FPCSR_CZ 0x00008000 // cause: division by zero
#define FPCSR_CO 0x00004000 // cause: overflow
#define FPCSR_CU 0x00002000 // cause: underflow
#define FPCSR_CI 0x00001000 // cause: inexact operation
#define FPCSR_EV 0x00000800 // enable: invalid operation
#define FPCSR_EZ 0x00000400 // enable: division by zero
#define FPCSR_EO 0x00000200 // enable: overflow
#define FPCSR_EU 0x00000100 // enable: underflow
#define FPCSR_EI 0x00000080 // enable: inexact operation
#define FPCSR_FV 0x00000040 // flag: invalid operation
#define FPCSR_FZ 0x00000020 // flag: division by zero
#define FPCSR_FO 0x00000010 // flag: overflow
#define FPCSR_FU 0x00000008 // flag: underflow
#define FPCSR_FI 0x00000004 // flag: inexact operation
#define FPCSR_RM_MASK 0x00000003 // rounding mode mask
#define FPCSR_RM_RN 0x00000000 // round to nearest
#define FPCSR_RM_RZ 0x00000001 // round to zero
#define FPCSR_RM_RP 0x00000002 // round to positive infinity
#define FPCSR_RM_RM 0x00000003 // round to negative infinity
#endif

View File

@ -0,0 +1,95 @@
#ifndef ULTRA64_RCP_H
#define ULTRA64_RCP_H
#define HW_REG(reg, type) *(volatile type*)((reg) | 0xA0000000)
#define AI_DRAM_ADDR_REG 0x04500000
#define AI_LEN_REG 0x04500004
#define AI_CONTROL_REG 0x04500008
#define AI_STATUS_REG 0x0450000C
#define AI_DACRATE_REG 0x04500010
#define AI_BITRATE_REG 0x04500014
#define AI_STATUS_AI_FULL (1 << 31)
#define AI_STATUS_AI_BUSY (1 << 30)
#define VI_STATUS_REG 0x04400000
#define VI_CONTROL_REG VI_STATUS_REG
#define VI_ORIGIN_REG 0x04400004
#define VI_DRAM_ADDR_REG VI_ORIGIN_REG
#define VI_WIDTH_REG 0x04400008
#define VI_H_WIDTH_REG VI_WIDTH_REG
#define VI_INTR_REG 0x0440000C
#define VI_V_INTER_REG VI_H_WIDTH_REG
#define VI_CURRENT_REG 0x04400010
#define VI_V_CURRENT_LINE_REG VI_CURRENT_REG
#define VI_BURST_REG 0x04400014
#define VI_TIMING_REG VI_BURST_REG
#define VI_V_SYNC_REG 0x04400018 //VI vertical sync
#define VI_H_SYNC_REG 0x0440001C //VI horizontal sync
#define VI_LEAP_REG 0x04400020 //VI horizontal sync leap
#define VI_H_SYNC_LEAP_REG VI_LEAP_REG
#define VI_H_START_REG 0x04400024 //VI horizontal video
#define VI_H_VIDEO_REG VI_H_START_REG
#define VI_V_START_REG 0x04400028 //VI vertical video
#define VI_V_VIDEO_REG VI_V_START_REG
#define VI_V_BURST_REG 0x0440002C //VI vertical burst
#define VI_X_SCALE_REG 0x04400030 //VI x-scale
#define VI_Y_SCALE_REG 0x04400034 //VI y-scale
#define SP_IMEM_START 0x04001000
#define SP_DMEM_START 0x04000000
#define SP_MEM_ADDR_REG 0x04040000
#define SP_DRAM_ADDR_REG 0x04040004
#define SP_RD_LEN_REG 0x04040008
#define SP_WR_LEN_REG 0x0404000C
#define SP_STATUS_REG 0x04040010
#define SP_PC_REG 0x04080000
#define PI_DRAM_ADDR_REG 0x04600000 //PI DRAM address
#define PI_CART_ADDR_REG 0x04600004 //PI pbus (cartridge) address
#define PI_RD_LEN_REG 0x04600008 //PI read length
#define PI_WR_LEN_REG 0x0460000C //PI write length
#define PI_STATUS_REG 0x04600010 //PI status
#define PI_BSD_DOM1_LAT_REG 0x04600014 //PI dom1 latency
#define PI_DOMAIN1_REG 0x04600014
#define PI_BSD_DOM1_PWD_REG 0x04600018 //PI dom1 pulse width
#define PI_BSD_DOM1_PGS_REG 0x0460001C //PI dom1 page size
#define PI_BSD_DOM1_RLS_REG 0x04600020 //PI dom1 release
#define PI_BSD_DOM2_LAT_REG 0x04600024 //PI dom2 latency
#define PI_DOMAIN2_REG 0x04600024
#define PI_BSD_DOM2_PWD_REG 0x04600028 //PI dom2 pulse width
#define PI_BSD_DOM2_PGS_REG 0x0460002C //PI dom2 page size
#define PI_BSD_DOM2_RLS_REG 0x04600030 //PI dom2 release
#define PI_STATUS_BUSY 0x1
#define PI_STATUS_IOBUSY 0x2
#define PI_STATUS_ERROR 0x4
#define PI_STATUS_RESET_CONTROLLER 0x1
#define PI_STATUS_CLEAR_INTR 0x2
#define SI_DRAM_ADDR_REG 0x04800000
#define SI_PIF_ADDR_RD64B_REG 0x04800004
#define SI_PIF_ADDR_WR64B_REG 0x04800010
#define SI_STATUS_REG 0x04800018
#define SI_STATUS_DMA_BUSY 0x1
#define SI_STATUS_IO_READ_BUSY 0x2
#define SI_STATUS_DMA_ERROR 0x8
#define SI_STATUS_INTERRUPT (1 << 12)
#define PIF_RAM_START 0x1FC007C0
#define MI_INIT_MODE_REG 0x04300000
#define MI_MODE_REG MI_INIT_MODE_REG
#define MI_VERSION_REG 0x04300004
#define MI_INTR_REG 0x04300008
#define MI_INTR_MASK_REG 0x0430000C
#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */
#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */
#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */
#endif

View File

@ -0,0 +1,51 @@
#ifndef ULTRA64_RDP_H
#define ULTRA64_RDP_H
/* DP Command Registers */
#define DPC_REG_BASE 0xA4100000
#define DPC_START_REG (*(vu32*)(DPC_REG_BASE + 0x00))
#define DPC_END_REG (*(vu32*)(DPC_REG_BASE + 0x04))
#define DPC_CURRENT_REG (*(vu32*)(DPC_REG_BASE + 0x08))
#define DPC_STATUS_REG (*(vu32*)(DPC_REG_BASE + 0x0C))
#define DPC_CLOCK_REG (*(vu32*)(DPC_REG_BASE + 0x10))
#define DPC_BUFBUSY_REG (*(vu32*)(DPC_REG_BASE + 0x14))
#define DPC_PIPEBUSY_REG (*(vu32*)(DPC_REG_BASE + 0x18))
#define DPC_TMEM_REG (*(vu32*)(DPC_REG_BASE + 0x1C))
/* DP Span Registers */
#define DPS_REG_BASE 0xA4200000
#define DPS_TBIST_REG (*(vu32*)(DPS_REG_BASE + 0x00))
#define DPS_TEST_MODE_REG (*(vu32*)(DPS_REG_BASE + 0x04))
#define DPS_BUFTEST_ADDR_REG (*(vu32*)(DPS_REG_BASE + 0x08))
#define DPS_BUFTEST_DATA_REG (*(vu32*)(DPS_REG_BASE + 0x0C))
/* DP Status Read Flags */
#define DPC_STATUS_XBUS_DMEM_DMA 0x001
#define DPC_STATUS_FREEZE 0x002
#define DPC_STATUS_FLUSH 0x004
#define DPC_STATUS_START_GCLK 0x008
#define DPC_STATUS_TMEM_BUSY 0x010
#define DPC_STATUS_PIPE_BUSY 0x020
#define DPC_STATUS_CMD_BUSY 0x040
#define DPC_STATUS_CBUF_READY 0x080
#define DPC_STATUS_DMA_BUSY 0x100
#define DPC_STATUS_END_VALID 0x200
#define DPC_STATUS_START_VALID 0x400
/* DP Status Write Flags */
#define DPC_CLR_XBUS_DMEM_DMA 0x0001
#define DPC_SET_XBUS_DMEM_DMA 0x0002
#define DPC_CLR_FREEZE 0x0004
#define DPC_SET_FREEZE 0x0008
#define DPC_CLR_FLUSH 0x0010
#define DPC_SET_FLUSH 0x0020
#define DPC_CLR_TMEM_CTR 0x0040
#define DPC_CLR_PIPE_CTR 0x0080
#define DPC_CLR_CMD_CTR 0x0100
#define DPC_CLR_CLOCK_CTR 0x0200
#endif

Some files were not shown because too many files have changed in this diff Show More