test_n64dd.c
4.19 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
/*************************************************************
test_mem.h : Nintendo 64 Music Tools Library Sample
(c) Copyright 1998, Software Creations (Holdings) Ltd.
Version 3.11
N64DD demo N64DD related source file.
**************************************************************/
/* include system header files */
#ifndef F3DEX_GBI
#define F3DEX_GBI
#endif
#include <ultra64.h>
#include <leo.h>
#include "test_n64dd.h"
#define NUM_LEO_MESGS 8
static OSMesg LeoMessages[NUM_LEO_MESGS];
static OSMesgQueue diskQ;
static OSMesg diskQBuf;
static OSPiHandle *cartrom_handle;
static OSPiHandle *diskrom_handle;
/*
* Define for error_handle routine
*/
#define RETRY 0
#define FATAL 1
s32 error_handle(s32 result)
{
LEODiskID diskID;
LEOCmd cmdBlock;
s32 error;
if (!( (result == LEO_ERROR_MEDIUM_NOT_PRESENT) ||
(result == LEO_ERROR_MEDIUM_MAY_HAVE_CHANGED )))
return FATAL;
if (result == LEO_ERROR_MEDIUM_NOT_PRESENT)
{
#ifdef _DEBUG
osSyncPrintf("Insert the disk\n");
#endif
}
while(1)
{
/*
* Do the following at a time
* 1. Wait for the users to insert the disk (if the error
* was "NO MEDIA").
* 2. Get the disk ID of the inserted disk.
*/
for (;;)
{
LeoReadDiskID(&cmdBlock, &diskID, &diskQ);
osRecvMesg(&diskQ, (OSMesg *)&error, OS_MESG_BLOCK);
if (error == 0)
break;
if (!( (error == LEO_ERROR_MEDIUM_NOT_PRESENT) ||
(error == LEO_ERROR_MEDIUM_MAY_HAVE_CHANGED )))
{
#ifdef _DEBUG
osSyncPrintf("error = 0x%x\n", error);
#endif
return FATAL;
}
}
/*
* Check that this disk is the same as the previous one.
*/
if (bcmp((void *)&leoBootID, (void *)&diskID, sizeof(LEODiskID))== 0)
return RETRY;
/*
* Since the inserted disk is the wrong one, stop the spindle
* motor and wait for the users to change the disk.
*/
#ifdef _DEBUG
osSyncPrintf("This disk is wrong. Eject it and insert the right disk.\n");
#endif
do
{
LeoSpdlMotor(&cmdBlock, SLEEP, &diskQ);
osRecvMesg(&diskQ, (OSMesg *)&error, OS_MESG_BLOCK);
if (!( (error == 0) ||
(error == LEO_ERROR_MEDIUM_NOT_PRESENT) ||
(error == LEO_ERROR_MEDIUM_MAY_HAVE_CHANGED )))
return FATAL;
} while ( error != LEO_ERROR_MEDIUM_MAY_HAVE_CHANGED );
} /* while(1) */
/* Never reached, only to remove warning message */
return 0;
} /* error_handle() */
void DiskFatalError(void)
{
osSyncPrintf("Fatal error\n");
for(;;);
}
#ifdef __GNUC__
void DiskRead(short int start, short int end, void *dest)
#else
void DiskRead(void *start, void *end, void *dest)
#endif
{
LEOCmd cmdBlock;
s32 error;
for (;;)
{
LeoReadWrite(&cmdBlock, OS_READ, (u32)start, dest, (u32)end - (u32)start, &diskQ);
osRecvMesg(&diskQ, (OSMesg *)&error, OS_MESG_BLOCK);
if (error == 0)
return;
if (error_handle(error) == FATAL)
DiskFatalError();
}
}
#ifdef __GNUC__
int DiskSize(short int start, short int end)
#else
int DiskSize(void *start, void *end)
#endif
{
s32 bytes;
s32 error;
error = LeoLBAToByte((u32)start, (u32)end-(u32)start, &bytes);
if (error!=LEO_ERROR_GOOD)
DiskFatalError();
return (bytes);
}
void DiskInitialise(void)
{
s32 error;
LEODiskID diskID;
LEOCmd cmdBlock;
cartrom_handle = osCartRomInit();
diskrom_handle = osDriveRomInit();
osCreateMesgQueue(&diskQ, &diskQBuf, 1);
error = LeoCreateLeoManager((OSPri)OS_PRIORITY_LEOMGR - 1,
(OSPri)OS_PRIORITY_LEOMGR,
LeoMessages, NUM_LEO_MESGS);
if(error != LEO_ERROR_GOOD)
if (error_handle(error) == FATAL)
DiskFatalError();
/*
* We must check that the current disk is the
* same as to booted disk
*/
for (;;)
{
LeoReadDiskID(&cmdBlock, &diskID, &diskQ);
osRecvMesg(&diskQ, (OSMesg *)&error, OS_MESG_BLOCK);
if (error == 0)
break;
if (!( (error == LEO_ERROR_MEDIUM_NOT_PRESENT) ||
(error == LEO_ERROR_MEDIUM_MAY_HAVE_CHANGED )))
{
DiskFatalError();
}
}
/*
* Check that this disk is the same as the booted one.
*/
if (bcmp((void *)&leoBootID, (void *)&diskID, sizeof(LEODiskID)) != 0)
DiskFatalError();
}
/* end of file */