A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
2#include "host/KTestSystem.hh"
3#include "host/Option.hh"
4
5#include <egg/core/ExpHeap.hh>
6
7#include <algorithm>
8#include <array>
9#include <string_view>
10#include <utility>
11
12using namespace Kinoko;
13
14#if defined(__arm64__) || defined(__aarch64__)
15static void FlushDenormalsToZero() {
16 uint64_t fpcr;
17 asm("mrs %0, fpcr" : "=r"(fpcr));
18 asm("msr fpcr, %0" ::"r"(fpcr | (1 << 24)));
19}
20#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
21#include <immintrin.h>
22
23static void FlushDenormalsToZero() {
24 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
25}
26#endif
27
28using ModeEntry = std::pair<std::string_view, KSystem *(*)()>;
29
30static constexpr std::array<ModeEntry, 2> MODE_MAP = {{
31 {"test", []() -> KSystem * { return KTestSystem::CreateInstance(); }},
32 {"replay", []() -> KSystem * { return KReplaySystem::CreateInstance(); }},
33}};
34
35static void *s_memorySpace = nullptr;
36static EGG::Heap *s_rootHeap = nullptr;
37
38static void InitMemory() {
39 s_memorySpace = malloc(MEMORY_SPACE_SIZE);
40 s_rootHeap = EGG::ExpHeap::create(s_memorySpace, MEMORY_SPACE_SIZE, DEFAULT_OPT);
41 s_rootHeap->setName("EGGRoot");
43
45}
46
47int main(int argc, char **argv) {
48 FlushDenormalsToZero();
49 InitMemory();
50
51 if (argc < 2) {
52 PANIC("Too few arguments!");
53 }
54
55 // The first argument is the executable, so we ignore it
56 // The second argument is the mode
57 const std::string_view mode = argv[1];
58
59 auto it = std::ranges::find(MODE_MAP, mode, &ModeEntry::first);
60 if (it == MODE_MAP.end()) {
61 PANIC("Invalid mode!");
62 }
63
64 KSystem *sys = it->second();
65 sys->parseOptions(argc - 2, argv + 2);
66 sys->init();
67 return sys->run() ? 0 : 1;
68}
#define PANIC(m,...)
Definition Logger.hh:27
static ExpHeap * create(void *startAddress, size_t size, u16 opt)
A high-level representation of a memory heap for managing dynamic memory allocation....
Definition Heap.hh:25
Heap * becomeCurrentHeap()
Definition Heap.cc:40
void setName(const char *name)
Definition Heap.hh:92
static void SetRootHeap(Heap *heap)
static KReplaySystem * CreateInstance()
Base interface for a Kinoko system.
Definition KSystem.hh:10
virtual bool run()=0
Executes a run.
virtual void init()=0
Initializes the system.
virtual void parseOptions(int argc, char **argv)=0
Parses non-generic command line options.
static KTestSystem * CreateInstance()
static EGG::Heap * s_rootHeap
Definition main.cc:36
int main(int argc, char **argv)
Definition main.cc:47
static constexpr std::array< ModeEntry, 2 > MODE_MAP
Definition main.cc:30
static void * s_memorySpace
Definition main.cc:35
static void InitMemory()
Definition main.cc:38
std::pair< std::string_view, KSystem *(*)()> ModeEntry
Definition main.cc:28