coastline 0.0.4
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1#ifndef COASTLINE_SYSTEM_H
2#define COASTLINE_SYSTEM_H
3
8
9#include <PR/gbi.h>
10#include <PR/os.h>
11#include <PR/os_cont.h>
12#include <PR/sptask.h>
13#include <PR/ultratypes.h>
14
15#include "common/assetdma.h"
17#include "common/debugmessage.h"
19#include "common/frametime.h"
20#include "common/render.h"
21#include "common/screen.h"
22#include "common/screendraw.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
29typedef struct {
33
42extern u16 g_aFramebuffer0[];
43
52extern u16 g_aFramebuffer1[];
53
60extern u16 g_aDepthBuffer[];
61
62#if TGR_PLATFORM == TGR_PLATFORM_N64 && defined(ENABLE_PATCHES)
64#define N64_ACTIVE_DEPTH_BUFFER \
65 ((g_dwScreenScaleShift && osMemSize > 0x400000) ? (u16 *)0x80400000 : g_aDepthBuffer)
66#else
68#define N64_ACTIVE_DEPTH_BUFFER g_aDepthBuffer
69#endif
70
81
92
100extern u8 *g_pInflateHeapEnd;
102
112
125
137
149
159
171
183
192extern u16 *g_apFramebuffers[2];
193
204extern s32 g_dwFrameDeltaMs;
205
217
228#if TGR_BOSS_RALLY
229void StartLowResFrame(ViewportRect *views);
230#else
232#endif
233
245
257
269
281
294
309void ClearZBufferRect(s32 x, s32 y, s32 width, s32 height);
310
322
333extern OSIoMesg g_aIoMessagePool[32];
334
335#if !TGR_BOSS_RALLY
347#endif /* !TGR_BOSS_RALLY */
348
349#if !TGR_BOSS_RALLY
361#endif /* !TGR_BOSS_RALLY */
362
374
382extern OSMesg g_aDmaMsgBuf[32];
384
395#if TGR_PLATFORM != TGR_PLATFORM_SDL
396extern OSMesgQueue g_RspEventMsgQueue;
397#endif
398
408extern OSMesg g_aRspEventMsgBuf[1];
410
422
430extern OSMesg g_aRspDoneMsgBuf[1];
432
443#if TGR_PLATFORM != TGR_PLATFORM_SDL
444extern OSMesgQueue g_RdpEventMsgQueue;
445#endif
446
456extern OSMesg g_aRdpEventMsgBuf[1];
458
470
478extern OSMesg g_aRdpDoneMsgBuf[1];
480
492#if TGR_PLATFORM != TGR_PLATFORM_SDL
493extern OSMesgQueue g_ViRetracePollMesgQueue;
494#endif
495
505extern OSMesg g_ViRetracePollMesgBuf[1];
507
519
527extern OSMesg g_ViRetraceMesgBuf[1];
529
540#if TGR_PLATFORM != TGR_PLATFORM_SDL
541extern u32 g_dwDummyOsMesg;
542#endif
543
554#if TGR_PLATFORM != TGR_PLATFORM_SDL
555extern s32 g_dwVblankCounter;
556#endif
557
567extern OSThread g_RspDoneThreadObj;
568
575extern OSThread g_RdpDoneThreadObj;
576
577#if TGR_REGION == TGR_REGION_EU || TGR_REGION == TGR_REGION_JP
584extern OSThread g_PreNmiResetHandlerThreadObj;
585#endif
586
593extern OSThread g_MainGameThreadObj;
594
601extern OSThread g_BootIdleThreadObj;
602
609extern OSThread g_FaultThreadObj;
610
611/* The words of the stacks of the threads. */
612#define THREAD_STACK_WORDS 0x200
613#define MAIN_STACK_WORDS 0x800
614#define IDLE_STACK_WORDS 0x100
615#define FAULT_STACK_WORDS 0x100
616
625extern u32 g_adwRspDoneThreadStack[THREAD_STACK_WORDS];
626
633extern u32 g_adwRdpDoneThreadStack[THREAD_STACK_WORDS];
634
635#if TGR_REGION == TGR_REGION_EU || TGR_REGION == TGR_REGION_JP
640extern u32 g_adwPreNmiResetThreadStack[THREAD_STACK_WORDS];
641#endif
642
649extern u32 g_adwMainThreadStack[MAIN_STACK_WORDS];
650
657extern u32 g_adwIdleThreadStack[IDLE_STACK_WORDS];
658
665extern u32 g_adwFaultThreadStack[FAULT_STACK_WORDS];
667
677
678#if TGR_BOSS_RALLY
685extern DisplayListCommand g_abDisplayListMemory[];
687#define g_aGfxDisplayListPool g_abDisplayListMemory
688#endif
689
701
713
725
733extern OSMesg g_aSiEventMesgBuf[1];
735
747
759
771
779extern u32 g_dwDmaChunkSize;
781
791
799extern OSMesg g_aFaultMsgBuf[1];
800
807extern OSThread *g_pFaultedThread;
809
818extern s32 g_dwFaultState;
819
829extern char *g_apszBootArgv[];
830
839extern char **g_ppszMainArgv;
840
848extern s32 *g_pdwMainArgc;
850
860
868extern OSMesg g_aPiMgrCmdMsgBuf[32];
870
877
885
898
910
924#ifdef __cplusplus
925extern "C"
926#endif
927 s32 UnusedVblankQueryStub(s32 unused0, s32 unused1);
928
940void RspDoneThread(void *arg);
941
953void RdpDoneThread(void *arg);
954
955#if TGR_REGION == TGR_REGION_JP || TGR_REGION == TGR_REGION_EU
963
969extern OSMesg g_aPreNmiMesgBuf[1];
971
979
989#endif /* TGR_REGION == TGR_REGION_JP || TGR_REGION == TGR_REGION_EU */
990
1002void ViRetraceThread(void *arg);
1003
1013
1025
1035void StubFunction(s32 unused);
1036
1046void FaultThread(void *arg);
1047
1058void BootIdleThread(void *arg);
1059
1061#if TGR_BOSS_RALLY
1062#define DISPLAY_LIST_COMMANDS 12000
1063#else
1064#define DISPLAY_LIST_COMMANDS 6000
1065#endif
1066
1068#define DISPLAY_LIST_RESERVED 64
1069
1082#if TGR_BOSS_RALLY
1084void BeginDisplayList(ViewportRect *views, s32 highRes);
1085#else
1086void BeginDisplayList(s32 highRes);
1087#endif
1088
1100#ifdef __cplusplus
1101extern "C"
1102#endif
1103 void StubEmptyVoid(s32 unused0, ...);
1104
1115extern OSTask g_aGfxTask[2];
1116
1125extern u64 g_aRspBootUcode[];
1126
1127#if TGR_PLATFORM == TGR_PLATFORM_N64
1136extern u64 g_aRspBootUcodeEnd[];
1137
1145extern u64 g_aGspUcodeText[];
1147
1156extern u64 g_abRspUcodeData[];
1157#endif /* TGR_PLATFORM == TGR_PLATFORM_N64 */
1158
1169extern u8 g_abRspDramStackBuffer[];
1170
1181#if !TGR_BOSS_RALLY
1182extern u64 *g_pRdpOutputBuffer[2];
1183#endif
1184
1196
1197#if !TGR_BOSS_RALLY
1209#endif /* !TGR_BOSS_RALLY */
1210
1211#if !TGR_BOSS_RALLY
1223#endif /* !TGR_BOSS_RALLY */
1224
1225#if !TGR_BOSS_RALLY
1235extern s32 g_dwPeakShadowVertexCount;
1236#endif /* !TGR_BOSS_RALLY */
1237
1238#if !TGR_BOSS_RALLY
1247extern s32 g_dwPeakDisplayListCommands;
1249#endif /* !TGR_BOSS_RALLY */
1250
1251#if !TGR_BOSS_RALLY
1262extern s32 g_dwFirstFlushDone;
1263#endif /* !TGR_BOSS_RALLY */
1264
1265#if !TGR_BOSS_RALLY
1277extern u32 g_dwFlushDuration;
1278#endif /* !TGR_BOSS_RALLY */
1279
1280#if !TGR_BOSS_RALLY
1290extern u32 g_dwFlushInterval;
1291#endif /* !TGR_BOSS_RALLY */
1292
1293#if !TGR_BOSS_RALLY
1302extern u32 g_dwFlushStartTime;
1304#endif /* !TGR_BOSS_RALLY */
1305
1317
1318#if !TGR_BOSS_RALLY
1328extern u32 g_dwLastFlushValue;
1330#endif /* !TGR_BOSS_RALLY */
1331
1343
1355
1364
1373
1374#if TGR_REGION == TGR_REGION_EU
1377
1380#endif
1381
1392extern s32 g_dwViGammaEnabled;
1393
1394#ifdef __cplusplus
1395}
1396#endif
1397
1398#endif /* COASTLINE_SYSTEM_H */
The state the renderer shares between the parts of a frame.
Gfx DisplayListCommand
A display-list command in the Nintendo 64 renderer.
Definition displaylistops.h:21
The time of the last frame.
The graphics binary interface types the gu routines fill in for the RSP microcode.
Public interface of the libultra operating system, as the game links it.
struct OSThread_s OSThread
A thread: its place in the queues, its state, and the registers saved when it last stopped.
struct OSMesgQueue_s OSMesgQueue
A message queue: a ring of messages and the threads blocked sending or receiving.
void * OSMesg
Definition os.h:73
The controllers and the Controller Pak file system.
#define MAXCONTROLLERS
The ports of the console.
Definition os_cont.h:17
The size of the frame, and the routines of the screen the main loop calls.
RSP tasks.
The bump allocator zcalloc() draws from.
Definition system.h:29
u8 * cur
Definition system.h:30
u8 * end
Definition system.h:31
What osContInit() learns of a controller.
Definition os_cont.h:98
An I/O request to a device manager: a DMA between RDRAM and a device.
Definition os.h:210
A video mode: the registers of the video interface for a resolution and television standard.
Definition os.h:310
The rectangle of the screen a view fills.
Definition render.h:134
u64 g_aRspBootUcode[]
The boot microcode of the RSP.
u16 * g_apFramebuffers[2]
The two frame buffers.
u8 g_aInflateHeapBuffer[]
The room the heap of zlib takes while the game loads, and that the sound effects of a race are loaded...
char * g_apszBootArgv[]
The arguments of a development kit and their count, which starts at 1, and the copies of the argument...
u32 g_dwFlushValueSource
A word FlushDisplayList() copies each frame, and the copy.
void UpdateFrameTiming(void)
Update the timing of the frames from the CPU timer.
s32 g_dwIoMessagePendingCount
The DMA started and not yet waited for.
void InitRenderingSubsystem(void)
Set up the display, the RSP and RDP state, and the system threads.
OSViMode g_ViModeMpalLan1
The MPAL low-resolution video mode.
s32 g_dwPrevElapsedTimeMs
The time of the frame before, in milliseconds.
s32 g_dwDisplayModeChangeCountdown
The frames until the video mode changes to the resolution BeginDisplayList() was given,...
s32 g_dwIoMessagePoolIndex
The message of g_aIoMessagePool last handed out.
s32 g_dwPreNmiResetPending
Set once the reset button has been pressed.
u16 g_aDepthBuffer[]
The depth buffer, of 16-bit depths, near the start of the memory.
OSMesgQueue g_PiMgrCmdQueue
The queue of the commands of the PI manager.
void RdpDoneThread(void *arg)
Forward each finished frame of the RDP to g_RdpDoneMsgQueue, marking the timing bars.
OSMesgQueue g_RspDoneMsgQueue
The queue the RSP event reaches, and the queue the thread forwards it to.
u64 g_qwTimestampBase
The clock of the frames, in counts of the CPU counter.
s32 UnusedVblankQueryStub(s32 unused0, s32 unused1)
Return 0.
s32 g_bRaceScreenActive
Whether the screen of a race runs, which makes UpdateFrameTiming() step a fixed 1/30 of a second a fr...
void StartHighResFrame(void)
Start the display list of a frame in the high-resolution mode.
void PreNmiResetHandlerThread(void *arg)
Wait for the reset button, then silence the sound, record the reset, and blank the screen,...
OSViMode g_ViModeNtscLan1
The video modes of the NTSC and the MPAL consoles.
s32 g_dwFirstFlushDone
Whether a frame has been sent to the RSP.
s32 g_dwFrameDeltaMs
The time the last frame took.
void ClearDepthBuffer(void)
Fill the whole depth buffer with the farthest depth, then draw to the frame buffer again.
u32 g_dwAlphaDitherMode
The alpha dither the screens draw with, as the other-mode bits gDPSetAlphaDither() takes.
void FlushDisplayList(void)
End the display list of the frame and run it.
OSMesgQueue g_DmaMessageQueue
The queue a finished DMA sends to.
void StartLowResFrame(void)
Start the display list of a frame in the low-resolution mode.
void ResetFrameClock(void)
Restart the clock of the frames from zero.
OSMesgQueue g_RdpDoneMsgQueue
The queue the RDP event reaches, and the queue the thread forwards it to.
OSMesgQueue g_ViRetraceMesgQueue
The queue of the retrace of ViRetraceThread(), which nothing starts, and the queue each retrace reach...
void FaultThread(void *arg)
Wait for faults and keep the thread that faulted.
OSTask g_aGfxTask[2]
The tasks of the RSP, one for each frame buffer.
void StubEmptyVoid(s32 unused0,...)
Do nothing.
s32 g_dwPeakShadowCommandCount
The most commands of a shadow, vertices of a shadow, and commands of a frame seen.
u64 g_aRspBootUcodeEnd[]
The end of the RSP boot microcode, at the start of the graphics microcode.
void BootIdleThread(void *arg)
Read the arguments of a development kit, start the managers, the fault thread and the main thread,...
u32 g_dwScreenUnblankDelay
The frames to wait before the display returns after inflateInit2_() blanks it to use the frame buffer...
InflateAllocator g_inflateAllocator
The state of the allocator inflateInit2_() gives zlib.
void BeginDisplayList(s32 highRes)
Start the display list of a frame in a resolution, with the render modes every frame starts with.
s32 g_dwFaultState
Cleared once by the fault thread.
u16 g_aFramebuffer1[]
The second 320-by-240 frame buffer of 16-bit pixels.
s32 g_dwDisplayListCommandCount
The commands of the display list of the last frame.
OSViMode g_ViModeNtscHaf1
The video modes of the high resolution.
s32 g_dwViGammaEnabled
Whether the video interface corrects the gamma.
u32 g_dwFrameTimestamp
The CPU counter at the last frame.
s32 g_dwAppliedScreenScaleShift
The resolution the video mode was last set to.
void RspDoneThread(void *arg)
Forward each finished task of the RSP to g_RspDoneMsgQueue, marking the timing bars.
void WaitForDmaMessages(void)
Wait for every DMA started to finish.
u16 g_aFramebuffer0[]
The first of the two frame buffers, of 320 by 240 16-bit pixels.
s32 g_dwElapsedTimeMs
The time UpdateFrameTiming() counts, in milliseconds.
u8 g_abRspDramStackBuffer[]
The memory of the matrix stack of the RSP, 16 bytes more than the stack to align it.
void ClearZBufferRect(s32 x, s32 y, s32 width, s32 height)
Fill a rectangle of the depth buffer with the farthest depth.
f32 g_fCountsPerMillisecond
The counts of the CPU counter a millisecond.
void UnusedFrameTimingStub(void)
Do nothing.
char ** g_ppszMainArgv
The boot argument vector shared with the rendering initialiser.
void StubFunction(s32 unused)
Do nothing; where a debugger would stop.
OSMesgQueue g_PreNmiMesgQueue
The queue of the reset button, and its buffer.
u8 * g_pInflateHeapBase
The heap DecompressFromRom() lends to zlib, or NULL to let inflateInit2_() borrow the frame buffers.
OSMesgQueue g_FaultMsgQueue
The queue of the fault event and the thread that faulted.
u16 g_wScreenFrameCount
The frames a screen has shown, for screens that count them.
Gfx g_aGfxDisplayListPool[]
The value the events send.
u32 g_dwFlushDuration
The counts of the CPU counter the end of a frame took, between the ends of two frames,...
u64 * g_pRdpOutputBuffer[2]
The start and end of the buffer the RDP commands go to.
DisplayListCommand * g_pDisplayListBase
The start of the display lists.
OSContStatus g_aContStatus[MAXCONTROLLERS]
What the controllers reported at the start.
OSViMode g_ViModePalLan1
The PAL low-resolution video mode.
u64 g_abRspUcodeData[]
The data of the graphics microcode.
u32 g_dwColorDitherMode
The color dither the screens draw with, as the other-mode bits gDPSetColorDither() takes.
void ViRetraceThread(void *arg)
Forward each retrace to g_ViRetraceMesgQueue and count it.
u32 g_dwKeepScreenBlanked
Whether the display stays black whatever a frame would show.
OSIoMesg g_aIoMessagePool[32]
The messages of the DMA, which AllocIoMessage() hands out in turn.
OSViMode g_ViModeMpalHaf1
The MPAL high-resolution video mode.
void WaitForVblankMessage(void)
Wait for the next retrace.
s32 g_dwOutputBuffReserve
The doublewords at the end of the output buffer the tasks do not use.
OSIoMesg * AllocIoMessage(void)
Take a message of the DMA, waiting for a DMA to finish when every one is in flight.
OSViMode g_ViModePalHaf1
The copies of the PAL video modes the game sets.
Integer and floating-point types of libultra.
unsigned int u32
Definition ultratypes.h:20
float f32
Definition ultratypes.h:38
unsigned short u16
Definition ultratypes.h:19
int s32
Definition ultratypes.h:25
unsigned long long u64
Definition ultratypes.h:21
unsigned char u8
Definition ultratypes.h:18
A display list command for the Fast3D microcode.
Definition gbi.h:132
A task for the RSP, aligned to 8 bytes.
Definition sptask.h:44