Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (68 loc) · 3.25 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (68 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* ================================================================================================
* File: main.cpp
* Brief: PS2 application entry point. Sets the filesystem base path, boots the
* Quake II common layer, then runs the frame loop forever.
*
* This source code is released under the GNU GPL v2 license.
* ================================================================================================ */
#include "ps2/common.h"
#include "ps2/system/iop_boot.h"
#include "ps2/renderer/profile.h"
#include "ps2/renderer/splash_screen.h"
#include "ps2/debug/exception_handler.h"
#include "ps2/debug/log_file.h"
int main(int argc, char ** argv)
{
#if PS2_QUAKE_DEBUG
// First thing, ahead of even the memory accounting: a bad pointer any time
// after this prints its cause, the faulting instruction and a call stack
// instead of hanging the EE with three lines of emulator output. Costs
// nothing until something faults, and is compiled out of release.
ps2::debug::InstallExceptionHandlers();
#endif // PS2_QUAKE_DEBUG
// Book the RAM we never get to allocate (EE kernel, ELF image, stack) against
// ps2::heap::MemTag::ElfSys. Must happen before anything touches the heap, so that what the
// tags add up to stays a faithful picture of the console's 32MB.
ps2::heap::TagsAddSystemMem();
// Sys_Milliseconds counts from its first call. Made here, it puts every log line's stamp and
// the IOP boot report's times against the start of main(), the boot included.
Sys_Milliseconds();
// The id logo, on screen within milliseconds, while the IOP drivers come up and the game data
// is found, which can take seconds on a console. It stays up until the game's first frame.
ps2::splash::Show();
// Locate the game data - host: first, HDD/PFS next, USB mass: last - before
// Qcommon_Init runs FS_InitFilesystem. On HDD/USB it sits next to the ELF,
// whose directory (and HDD partition) comes from the path the
// loader passes as argv[0]. A build with -DPS2_FS_BASE_PATH=\"...\" pins
// the base path and skips the detection, for debugging.
#ifdef PS2_FS_BASE_PATH
const char * const basePath = PS2_FS_BASE_PATH;
#else // PS2_FS_BASE_PATH
const char * const basePath = ps2::sys::DetectBasePathAndBootIop((argc > 0) ? argv[0] : nullptr);
#endif // PS2_FS_BASE_PATH
FS_SetDefaultBasePath(basePath);
// The log file goes next to baseq2/, and starts now so it covers all of Qcommon_Init.
ps2::debug::LogFileOpen(basePath);
Qcommon_Init(argc, argv);
int oldtime = Sys_Milliseconds();
for (;;)
{
int newtime;
int frametime;
do
{
newtime = Sys_Milliseconds();
frametime = newtime - oldtime;
} while (frametime < 1);
// The whole frame - server, client, renderer and the vsync wait.
{
PS2_PROFILE_SCOPED_EVENT(ps2::prof_evt::Frame);
Qcommon_Frame(frametime);
}
// Deliberately outside the scope above: the dump is tens of milliseconds
// of stdout and must not land in the timings it is reporting. The frame
// it stretches is dropped rather than logged (see FrameLogFlush).
ps2::debug::FrameLogFlush();
oldtime = newtime;
}
}