ipl4main.c
6.67 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/********************************************************************************
NINTENDO64 Disk Drive IPL4
main module
July 17, 1997
********************************************************************************/
#include <ultra64.h>
#include <PR/os_internal.h>
#include "ipl4.h"
static OSThread idleThread; /* idle thread record */
static OSThread mainThread; /* main thread record */
static OSThread grphThread; /* graphics thread record */
static OSThread diskThread; /* disk thread record */
static OSThread rmonThread; /* disk thread record */
uwlong bootStack[STACKSIZE64]; /* boot process stack memory */
static uwlong idleStack[STACKSIZE64]; /* idle thread stack memory */
static uwlong mainStack[STACKSIZE64]; /* main thread stack memory */
static uwlong grphStack[STACKSIZE64]; /* graphics thread stack memory */
static uwlong diskStack[STACKSIZE64]; /* disk thread stack memory */
static uwlong rmonStack[STACKSIZE64]; /* idle thread stack memory */
OSMesgQueue mainMesgque; /* main thread message queue */
OSMesgQueue grphMesgque; /* graphics thread message queue */
OSMesgQueue diskMesgque; /* disk drive thread message queue */
OSMesgQueue PimgMesgque; /* PI manager message queue */
static OSMesg mainMesgbuf[NUM_MAIN_MESGS]; /* main thread message buffer */
static OSMesg grphMesgbuf[NUM_GRPH_MESGS]; /* graphics thread message buffer */
static OSMesg diskMesgbuf[NUM_DISK_MESGS]; /* disk thread message buffer */
static OSMesg PimgMesgbuf[NUM_PIMG_MESGS]; /* PI manager message buffer */
IPLHeader bootHeader; /* application boot header */
DiskStatus diskStatus; /* disk I/O status */
int diskErrorNo; /* disk I/O error number */
int memoryPack; /* memory pack active */
int clockSetting = FALSE; /* clock setting active */
int systemReset = FALSE; /* Pre-NMI active */
/********************************************************************************/
/* */
/* Read a data block from ROM. */
/* */
/********************************************************************************/
extern long
osPiStartDma(OSIoMesg *IOMesg, long prio, long dir, ulong romStart, void *ramAddr, ulong size, OSMesgQueue *mesgque)
{
#ifdef DISKROM
OSPiHandle *PiHandle = osDriveRomInit();
#else
OSPiHandle *PiHandle = osCartRomInit();
#endif
IOMesg->hdr.pri = prio;
IOMesg->hdr.retQueue = mesgque;
IOMesg->dramAddr = ramAddr;
IOMesg->devAddr = romStart;
IOMesg->size = size;
PiHandle->transferInfo.cmdType = OS_OTHERS;
osEPiStartDma(PiHandle, IOMesg, dir);
return(0);
}
long
osPiStartDma_DriveRomOnly(OSIoMesg *IOMesg, long prio, long dir, ulong romStart, void *ramAddr, ulong size, OSMesgQueue *mesgque)
{
OSPiHandle *PiHandle = osDriveRomInit();
IOMesg->hdr.pri = prio;
IOMesg->hdr.retQueue = mesgque;
IOMesg->dramAddr = ramAddr;
IOMesg->devAddr = romStart;
IOMesg->size = size;
PiHandle->transferInfo.cmdType = OS_OTHERS;
osEPiStartDma(PiHandle, IOMesg, dir);
return(0);
}
/********************************************************************************/
/* */
/* Main loop. */
/* */
/********************************************************************************/
static void
MainLoop(void)
{
OSMesg event;
ulong status = 0;
while (TRUE) {
osRecvMesg(&mainMesgque, &event, OS_MESG_BLOCK);
if (event == MESG_MAIN_LOADDONE) {
if (diskStatus == DISK_STAT_LOADEND) {
osSendMesg(&grphMesgque, MESG_GRPH_STOPGFX, OS_MESG_BLOCK);
status |= MAIN_STAT_LOADDONE;
}
}
else if (event == MESG_MAIN_GRPHDONE) {
status |= MAIN_STAT_GRPHDONE;
}
if (!systemReset && status == (MAIN_STAT_LOADDONE|MAIN_STAT_GRPHDONE)) {
BootDiskImage(&bootHeader);
}
}
}
/********************************************************************************/
/* */
/* Get memory size. */
/* */
/********************************************************************************/
static ulong
GetMemorySize(void)
{
ulong *memory;
ulong memsize = 0x00300000;
do {
memsize += 0x00100000;
memory = (ulong *)(0xA0000000L + memsize);
memory[0x00000] = 0x12345678L;
memory[0x3ffff] = 0x87654321L;
} while (memory[0x00000] == 0x12345678L && memory[0x3ffff] == 0x87654321L);
return(memsize);
}
/********************************************************************************/
/* */
/* Main process. */
/* */
/********************************************************************************/
static void
MainProcess(void *arg)
{
// memoryPack = (osMemSize >= 0x00800000);
memoryPack = (GetMemorySize() >= 0x00800000);
osCreateMesgQueue(&mainMesgque, mainMesgbuf, NUM_MAIN_MESGS);
osCreateMesgQueue(&grphMesgque, grphMesgbuf, NUM_GRPH_MESGS);
osCreateMesgQueue(&diskMesgque, diskMesgbuf, NUM_DISK_MESGS);
osCreateThread(&diskThread, DISK_THREAD_ID, DiskProcess, arg, diskStack + STACKSIZE64, DISK_PRIORITY);
osCreateThread(&grphThread, GRPH_THREAD_ID, GrphProcess, arg, grphStack + STACKSIZE64, GRPH_PRIORITY);
osStartThread(&diskThread); /* must start before graphics thread */
osStartThread(&grphThread);
MainLoop();
}
/********************************************************************************/
/* */
/* Idle process. */
/* */
/********************************************************************************/
static void
IdleProcess(void *arg)
{
osCreateViManager(OS_PRIORITY_VIMGR);
osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
osViBlack(TRUE);
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
osViSetSpecialFeatures(OS_VI_GAMMA_OFF );
osCreatePiManager((OSPri)OS_PRIORITY_PIMGR, &PimgMesgque, PimgMesgbuf, NUM_PIMG_MESGS);
/* Start RMON */
// osCreateThread(&rmonThread, 0, rmonMain, NULL, rmonStack + STACKSIZE64, OS_PRIORITY_RMON);
// osStartThread(&rmonThread);
osCreateThread(&mainThread, MAIN_THREAD_ID, MainProcess, arg, mainStack + STACKSIZE64, MAIN_PRIORITY);
osStartThread(&mainThread);
osSetThreadPri(NULL, OS_PRIORITY_IDLE);
while(1);
}
/********************************************************************************/
/* */
/* Boot process. */
/* */
/********************************************************************************/
extern void
BootProcess(void)
{
osInitialize();
__osSetHWIntrRoutine((OSHWIntr)1, __osLeoInterrupt);
osCreateThread(&idleThread, IDLE_THREAD_ID, IdleProcess, NULL, idleStack + STACKSIZE64, BOOT_PRIORITY);
osStartThread(&idleThread);
}