-
Notifications
You must be signed in to change notification settings - Fork 9
/
render.c
135 lines (109 loc) · 3.45 KB
/
render.c
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "render.h"
#include "static.h"
#include "src/debug_out.h"
#include "memory.h"
#include "src/assert.h"
#include "tex/textures.h"
#include "src/sprite.h"
#include "src/spritefont.h"
/*
* Task header.
*/
OSTask taskHeader =
{
M_GFXTASK, /* type of task */
OS_TASK_DP_WAIT, /* flags - wait for DP to be available */
NULL, /* ucode boot (fill in later) */
0, /* ucode boot size (fill in later) */
NULL, /* ucode (fill in later) */
SP_UCODE_SIZE, /* ucode size */
NULL, /* ucode data (fill in later) (to init DMEM) */
SP_UCODE_DATA_SIZE, /* ucode data size */
&dram_stack[0], /* stack used by ucode */
SP_DRAM_STACK_SIZE8, /* size of stack */
&rdp_output[0], /* fifo output buffer start */
&rdp_output[0]+RDP_OUTPUT_LEN, /* fifo output buffer end */
NULL, /* display list pointer (fill in later) */
0, /* display list size (ignored) */
NULL, /* yield buffer (used if yield will occur) */
0 /* yield buffer length */
};
/*
* global variables
*/
Dynamic dynamic; /* dynamic data */
int draw_buffer=0; /* frame buffer being updated (0 or 1) */
int fontcol[4]; /* color for shadowed fonts */
u16* cfb;
u8 isBlack = 1;
void renderDebugLog()
{
int x, y;
x = 18;
y = 18;
spriteSetColor(gGBFont.spriteLayer, 55, 255, 155, 255);
char *cstring = getDebugString();
renderText(&gGBFont, cstring, 18, 18, 0);
}
void renderFrame(int clear)
{
OSTask* theadp = &taskHeader;
Dynamic* dynamicp = &dynamic;
Gfx* glistp = dynamicp->glist;
/*
* Tell RCP where each segment is
*/
gSPSegment(glistp++, 0, 0x0); /* physical segment */
gDPSetColorImage(glistp++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WD, OS_K0_TO_PHYSICAL(getColorBuffer()));
if (clear)
{
gDPSetFillColor(glistp++, GPACK_RGBA5551(1, 1, 1, 1) << 16 | GPACK_RGBA5551(1, 1, 1, 1));
gDPSetCycleType(glistp++, G_CYC_FILL);
gDPFillRectangle(glistp++, 0, 0, SCREEN_WD-1, SCREEN_HT-1);
}
gDPSetScissor(glistp++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WD, SCREEN_HT);
/*
* Initialize RCP state.
*/
gSPDisplayList(glistp++, init_dl);
gDPPipeSync(glistp++);
gDPSetCycleType(glistp++, G_CYC_1CYCLE);
renderDebugLog();
finishSprites(&glistp);
gDPFullSync(glistp++);
gSPEndDisplayList(glistp++);
teqassert(glistp <= dynamicp->glist + GLIST_LEN);
theadp->t.ucode_boot = (u64 *) rspbootTextStart;
theadp->t.ucode_boot_size =
(u32) rspbootTextEnd - (u32) rspbootTextStart;
theadp->t.ucode = (u64 *) gspF3DEX2_fifoTextStart;
theadp->t.ucode_data = (u64 *) gspF3DEX2_fifoDataStart;
theadp->t.data_ptr = (u64 *) dynamicp->glist;
theadp->t.data_size =
(u32) ((glistp - dynamicp->glist) * sizeof(Gfx));
osWritebackDCache(&dynamic, sizeof(dynamic));
osSpTaskStart(theadp);
(void)osRecvMesg(&rdpMessageQ, NULL, OS_MESG_BLOCK);
if (isBlack)
{
isBlack = 0;
osViBlack(0);
}
osViSwapBuffer(getColorBuffer());
while (!MQ_IS_EMPTY(&retraceMessageQ))
{
(void) osRecvMesg(&retraceMessageQ, NULL, OS_MESG_NOBLOCK);
}
(void) osRecvMesg(&retraceMessageQ, NULL, OS_MESG_BLOCK);
draw_buffer = (draw_buffer + 1) % BUFFER_COUNT;
}
u16* getColorBuffer()
{
return cfb + draw_buffer * (SCREEN_WD * SCREEN_HT);
}
void* initColorBuffers(void* memoryEnd)
{
cfb = (u16*)memoryEnd - BUFFER_COUNT * SCREEN_WD * SCREEN_HT;
zeroMemory(cfb, sizeof(u16) * BUFFER_COUNT * SCREEN_WD * SCREEN_HT);
return cfb;
}