main.c
5.56 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*---------------------------------------------------------------------*
Copyright (C) 1997, Nintendo.
File main.c
Coded by Yoshitaka Yasumoto. Sep 12, 1997.
Modified by
$Id: main.c,v 1.1.1.1 2002/05/02 03:27:17 blythe Exp $
*---------------------------------------------------------------------*/
#include <ultra64.h>
#include <PR/gzsort.h>
#include "system.h"
#include "action.h"
#include "uc_assert.h"
extern Gfx clearCfb[];
extern Gfx gfxFinish[];
extern void cubeInit(void);
extern void cubePass1(Gfx **);
extern void cubePass2(Gfx **);
/*---------------------------------------------------------------------------*
* タスクデータ定義
*---------------------------------------------------------------------------*/
OSTask tlist = {
M_GFXTASK, /* task type */
OS_TASK_LOADABLE, /* task flags */
(u64 *)&rspbootTextStart, /* boot ucode ptr */
SP_BOOT_UCODE_SIZE, /* boot ucode size */
(u64 *)&gspZSort_fifoTextStart, /* ucode ptr */
SP_UCODE_SIZE, /* ucode size */
(u64 *)&gspZSort_fifoDataStart, /* ucode data ptr */
SP_UCODE_DATA_SIZE, /* ucode data size */
NULL, /* dram stack (不使用) */
0, /* dram stack size (不使用) */
(u64 *)system_rdpfifo, /* fifo buffer top */
(u64 *)system_rdpfifo+RDPFIFO_SIZE, /* fifo buffer bottom */
NULL, /* data ptr (後で設定) */
NULL, /* data size (設定不要) */
(u64 *)system_rspyield, /* yield data ptr */
OS_YIELD_DATA_SIZE, /* yield data size */
};
Gfx glist[GLIST_LEN];
/*---------------------------------------------------------------------------*
* M A I N
*---------------------------------------------------------------------------*/
void Main(void *arg)
{
u8 draw_frame = 0;
Gfx *gp;
OSTime framestart;
u32 rsp1start, rsp1end, rsp2start, rsp2end, rdpend;
actionInit();
cubeInit();
while(1){
/*------ コントローラの読み込み開始 ------*/
osContStartReadData(&siMessageQ);
/*------ リトレース待ち ------*/
osRecvMesg(&retraceMessageQ, NULL, OS_MESG_NOBLOCK);
osRecvMesg(&retraceMessageQ, NULL, OS_MESG_BLOCK);
framestart = osGetTime();
/*=======================================================================*
* Z S o r t P a s s 1
*=======================================================================*/
/*------ Gfx リスト作成 ------*/
gp = glist;
cubePass1(&gp);
gSPZEndDisplayList(gp ++);
/*------ Gfx タスク実行 ------*/
tlist.t.data_ptr = (u64 *)glist;
osWritebackDCache(glist, ((u32)gp)-((u32)glist));
rsp1start = OS_CYCLES_TO_USEC(osGetTime() - framestart) / 100;
osSpTaskStart(&tlist);
/*------ 終了待ち ------*/
#ifndef xDEBUG
osRecvMesg(&rspMessageQ, NULL, OS_MESG_BLOCK);
#else
{
int cnt = 0;
while (osRecvMesg(&rspMessageQ, NULL, OS_MESG_NOBLOCK)){
if (0 == osRecvMesg(&retraceMessageQ, NULL, OS_MESG_NOBLOCK)){
if (cnt ++ == 10){
ucDebugDMEMPrint();
ucDebugInfoPrint();
while(1);
}
}
}
}
#endif
rsp1end = OS_CYCLES_TO_USEC(osGetTime() - framestart) / 100;
#ifdef DEBUG
/*------ RSP 状態の表示 for DEBUG ------*/
if (Ac.pad[0].push & A_BUTTON){
ucDebugRdpFifoPrint(&tlist);
ucDebugAssertPrint();
ucDebugInfoPrint();
osSyncPrintf("RSP %d/%d\n",
IO_READ(SP_DMEM_START), IO_READ(SP_DMEM_START+4));
}
if (Ac.pad[0].push & B_BUTTON){
ucDebugIMEMPrint();
ucDebugDMEMPrint();
}
#endif
/*=======================================================================*
* Z S o r t P a s s 2
*=======================================================================*/
/*------ RSP 初期設定 ------*/
gp = glist;
gSPZSegment(gp ++, CFB_SEGMENT, system_cfb[draw_frame]);
gSPZRdpCmd(gp ++, clearCfb);
/*------ Gfx リスト作成 ------*/
cubePass2(&gp);
/*------ 処理メータ出力 ------*/
gSPZRdpCmd(gp ++, gfxFinish);
gSPZEndDisplayList(gp ++);
/*------ Gfx タスク実行 ------*/
tlist.t.data_ptr = (u64 *)glist;
osWritebackDCache(glist, ((u32)gp)-((u32)glist));
osWritebackDCache(gfxFinish+3, sizeof(Gfx)*9);
rsp2start = OS_CYCLES_TO_USEC(osGetTime() - framestart) / 100;
osSpTaskStart(&tlist);
/*------ 終了待ち ------*/
#ifndef xDEBUG
osRecvMesg(&rspMessageQ, NULL, OS_MESG_BLOCK);
#else
{
int cnt = 0;
while (osRecvMesg(&rspMessageQ, NULL, OS_MESG_NOBLOCK)){
if (0 == osRecvMesg(&retraceMessageQ, NULL, OS_MESG_NOBLOCK)){
if (cnt ++ == 10){
ucDebugDMEMPrint();
ucDebugInfoPrint();
while(1);
}
}
}
}
#endif
rsp2end = OS_CYCLES_TO_USEC(osGetTime() - framestart) / 100;
osRecvMesg(&rdpMessageQ, NULL, OS_MESG_BLOCK);
rdpend = OS_CYCLES_TO_USEC(osGetTime() - framestart) / 100;
/*------ 処理メーター変更 ------*/
gDPFillRectangle(&gfxFinish[3], 30, 201, 29+rsp1start, 202);
gDPFillRectangle(&gfxFinish[4], 30+rsp1end, 201, 29+rsp2start, 202);
gDPFillRectangle(&gfxFinish[7], 30+rsp1start, 204, 29+rsp1end, 205);
gDPFillRectangle(&gfxFinish[8], 30+rsp2start, 204, 29+rsp2end, 205);
gDPFillRectangle(&gfxFinish[11], 30+rsp2start, 207, 29+rdpend, 208);
/* Frame 切り替え */
osViSwapBuffer(system_cfb[draw_frame]);
draw_frame ^= 1;
/* コントローラデータ受け取り */
osRecvMesg(&siMessageQ, NULL, OS_MESG_BLOCK);
osContGetReadData(contPad);
/*------ コントローラ処理 ------*/
actionUpdate();
}
}
/*======== End of main.c ========*/