1 |
cebix |
1.1 |
/* |
2 |
|
|
* macos_util.h - MacOS definitions/utility functions |
3 |
|
|
* |
4 |
|
|
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifndef MACOS_UTIL_H |
22 |
|
|
#define MACOS_UTIL_H |
23 |
|
|
|
24 |
|
|
#include "cpu_emulation.h" |
25 |
gbeauche |
1.3 |
#include "thunks.h" |
26 |
|
|
#include <stddef.h> |
27 |
cebix |
1.1 |
|
28 |
|
|
|
29 |
|
|
/* |
30 |
|
|
* General definitions |
31 |
|
|
*/ |
32 |
|
|
|
33 |
|
|
struct Point { |
34 |
|
|
int16 v; |
35 |
|
|
int16 h; |
36 |
|
|
}; |
37 |
|
|
|
38 |
|
|
struct Rect { |
39 |
|
|
int16 top; |
40 |
|
|
int16 left; |
41 |
|
|
int16 bottom; |
42 |
|
|
int16 right; |
43 |
|
|
}; |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
/* |
47 |
|
|
* Queues |
48 |
|
|
*/ |
49 |
|
|
|
50 |
|
|
enum { // Queue types |
51 |
|
|
dummyType = 0, |
52 |
|
|
vType = 1, |
53 |
|
|
ioQType = 2, |
54 |
|
|
drvQType = 3, |
55 |
|
|
evType = 4, |
56 |
|
|
fsQType = 5, |
57 |
|
|
sIQType = 6, |
58 |
|
|
dtQType = 7, |
59 |
|
|
nmType = 8 |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
enum { // QElem struct |
63 |
|
|
qLink = 0, |
64 |
|
|
qType = 4, |
65 |
|
|
qData = 6 |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
enum { // QHdr struct |
69 |
|
|
qFlags = 0, |
70 |
|
|
qHead = 2, |
71 |
|
|
qTail = 6 |
72 |
|
|
}; |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/* |
76 |
|
|
* Definitions for Deferred Task Manager |
77 |
|
|
*/ |
78 |
|
|
|
79 |
|
|
enum { // DeferredTask struct |
80 |
|
|
dtFlags = 6, |
81 |
|
|
dtAddr = 8, |
82 |
|
|
dtParam = 12, |
83 |
|
|
dtReserved = 16 |
84 |
|
|
}; |
85 |
|
|
|
86 |
|
|
|
87 |
|
|
/* |
88 |
|
|
* Definitions for Device Manager |
89 |
|
|
*/ |
90 |
|
|
|
91 |
|
|
// Error codes |
92 |
|
|
enum { |
93 |
|
|
noErr = 0, |
94 |
|
|
controlErr = -17, /* I/O System Errors */ |
95 |
|
|
statusErr = -18, /* I/O System Errors */ |
96 |
|
|
readErr = -19, /* I/O System Errors */ |
97 |
|
|
writErr = -20, /* I/O System Errors */ |
98 |
|
|
badUnitErr = -21, /* I/O System Errors */ |
99 |
|
|
unitEmptyErr = -22, /* I/O System Errors */ |
100 |
|
|
openErr = -23, /* I/O System Errors */ |
101 |
|
|
closErr = -24, /* I/O System Errors */ |
102 |
|
|
abortErr = -27, /* IO call aborted by KillIO */ |
103 |
|
|
notOpenErr = -28, /* Driver not open */ |
104 |
|
|
dskFulErr = -34, /* disk full */ |
105 |
|
|
nsvErr = -35, /* no such volume */ |
106 |
|
|
ioErr = -36, /* I/O error (bummers) */ |
107 |
|
|
bdNamErr = -37, /* bad name */ |
108 |
|
|
fnOpnErr = -38, /* file not open */ |
109 |
|
|
eofErr = -39, /* End-of-file encountered */ |
110 |
|
|
posErr = -40, /* tried to position to before start of file (r/w) */ |
111 |
|
|
tmfoErr = -42, /* too many files open */ |
112 |
|
|
fnfErr = -43, /* file not found */ |
113 |
|
|
wPrErr = -44, /* diskette is write protected. */ |
114 |
|
|
fLckdErr = -45, /* file is locked */ |
115 |
|
|
fBsyErr = -47, /* file busy, dir not empty */ |
116 |
|
|
dupFNErr = -48, /* duplicate filename already exists */ |
117 |
|
|
paramErr = -50, /* error in user parameter list */ |
118 |
|
|
rfNumErr = -51, /* bad ioRefNum */ |
119 |
|
|
permErr = -54, /* permission error */ |
120 |
|
|
nsDrvErr = -56, /* no such driver number */ |
121 |
|
|
extFSErr = -58, /* external file system */ |
122 |
|
|
noDriveErr = -64, /* drive not installed */ |
123 |
|
|
offLinErr = -65, /* r/w requested for an off-line drive */ |
124 |
|
|
noNybErr = -66, /* couldn't find 5 nybbles in 200 tries */ |
125 |
|
|
noAdrMkErr = -67, /* couldn't find valid addr mark */ |
126 |
|
|
dataVerErr = -68, /* read verify compare failed */ |
127 |
|
|
badCksmErr = -69, /* addr mark checksum didn't check */ |
128 |
|
|
badBtSlpErr = -70, /* bad addr mark bit slip nibbles */ |
129 |
|
|
noDtaMkErr = -71, /* couldn't find a data mark header */ |
130 |
|
|
badDCksum = -72, /* bad data mark checksum */ |
131 |
|
|
badDBtSlp = -73, /* bad data mark bit slip nibbles */ |
132 |
|
|
wrUnderrun = -74, /* write underrun occurred */ |
133 |
|
|
cantStepErr = -75, /* step handshake failed */ |
134 |
|
|
tk0BadErr = -76, /* track 0 detect doesn't change */ |
135 |
|
|
initIWMErr = -77, /* unable to initialize IWM */ |
136 |
|
|
twoSideErr = -78, /* tried to read 2nd side on a 1-sided drive */ |
137 |
|
|
spdAdjErr = -79, /* unable to correctly adjust disk speed */ |
138 |
|
|
seekErr = -80, /* track number wrong on address mark */ |
139 |
|
|
sectNFErr = -81, /* sector number never found on a track */ |
140 |
|
|
fmt1Err = -82, /* can't find sector 0 after track format */ |
141 |
|
|
fmt2Err = -83, /* can't get enough sync */ |
142 |
|
|
verErr = -84, /* track failed to verify */ |
143 |
|
|
memFullErr = -108, |
144 |
|
|
dirNFErr = -120 /* directory not found */ |
145 |
|
|
}; |
146 |
|
|
|
147 |
|
|
// Misc constants |
148 |
|
|
enum { |
149 |
|
|
goodbye = -1, /* heap being reinitialized */ |
150 |
|
|
|
151 |
|
|
ioInProgress = 1, /* predefined value of ioResult while I/O is pending */ |
152 |
|
|
aRdCmd = 2, /* low byte of ioTrap for Read calls */ |
153 |
|
|
aWrCmd = 3, /* low byte of ioTrap for Write calls */ |
154 |
|
|
asyncTrpBit = 10, /* trap word modifier */ |
155 |
|
|
noQueueBit = 9, /* trap word modifier */ |
156 |
|
|
|
157 |
|
|
dReadEnable = 0, /* set if driver responds to read requests */ |
158 |
|
|
dWritEnable = 1, /* set if driver responds to write requests */ |
159 |
|
|
dCtlEnable = 2, /* set if driver responds to control requests */ |
160 |
|
|
dStatEnable = 3, /* set if driver responds to status requests */ |
161 |
|
|
dNeedGoodBye = 4, /* set if driver needs time for performing periodic tasks */ |
162 |
|
|
dNeedTime = 5, /* set if driver needs time for performing periodic tasks */ |
163 |
|
|
dNeedLock = 6, /* set if driver must be locked in memory as soon as it is opened */ |
164 |
|
|
|
165 |
|
|
dOpened = 5, /* driver is open */ |
166 |
|
|
dRAMBased = 6, /* dCtlDriver is a handle (1) or pointer (0) */ |
167 |
|
|
drvrActive = 7, /* driver is currently processing a request */ |
168 |
|
|
|
169 |
|
|
rdVerify = 64, |
170 |
|
|
|
171 |
|
|
fsCurPerm = 0, // Whatever is currently allowed |
172 |
|
|
fsRdPerm = 1, // Exclusive read |
173 |
|
|
fsWrPerm = 2, // Exclusive write |
174 |
|
|
fsRdWrPerm = 3, // Exclusive read/write |
175 |
|
|
fsRdWrShPerm = 4, // Shared read/write |
176 |
|
|
|
177 |
|
|
fsAtMark = 0, // At current mark |
178 |
|
|
fsFromStart = 1, // Set mark rel to BOF |
179 |
|
|
fsFromLEOF = 2, // Set mark rel to logical EOF |
180 |
|
|
fsFromMark = 3, // Set mark rel to current mark |
181 |
|
|
|
182 |
|
|
sony = 0, |
183 |
|
|
hard20 = 1 |
184 |
|
|
}; |
185 |
|
|
|
186 |
|
|
enum { /* Large Volume Constants */ |
187 |
|
|
kWidePosOffsetBit = 8, |
188 |
|
|
kMaximumBlocksIn4GB = 0x007FFFFF |
189 |
|
|
}; |
190 |
|
|
|
191 |
|
|
enum { // IOParam struct |
192 |
|
|
ioTrap = 6, |
193 |
|
|
ioCmdAddr = 8, |
194 |
|
|
ioCompletion = 12, |
195 |
|
|
ioResult = 16, |
196 |
|
|
ioNamePtr = 18, |
197 |
|
|
ioVRefNum = 22, |
198 |
|
|
ioRefNum = 24, |
199 |
|
|
ioVersNum = 26, |
200 |
|
|
ioPermssn = 27, |
201 |
|
|
ioMisc = 28, |
202 |
|
|
ioBuffer = 32, |
203 |
|
|
ioReqCount = 36, |
204 |
|
|
ioActCount = 40, |
205 |
|
|
ioPosMode = 44, |
206 |
|
|
ioPosOffset = 46, |
207 |
|
|
ioWPosOffset = 46, // Wide positioning offset when ioPosMode has kWidePosOffsetBit set |
208 |
|
|
SIZEOF_IOParam = 50 |
209 |
|
|
}; |
210 |
|
|
|
211 |
|
|
enum { // CntrlParam struct |
212 |
|
|
csCode = 26, |
213 |
|
|
csParam = 28 |
214 |
|
|
}; |
215 |
|
|
|
216 |
|
|
enum { // DrvSts struct |
217 |
|
|
dsTrack = 0, |
218 |
|
|
dsWriteProt = 2, |
219 |
|
|
dsDiskInPlace = 3, |
220 |
|
|
dsInstalled = 4, |
221 |
|
|
dsSides = 5, |
222 |
|
|
dsQLink = 6, |
223 |
|
|
dsQType = 10, |
224 |
|
|
dsQDrive = 12, |
225 |
|
|
dsQRefNum = 14, |
226 |
|
|
dsQFSID = 16, |
227 |
|
|
dsTwoSideFmt = 18, |
228 |
|
|
dsNewIntf = 19, |
229 |
|
|
dsDiskErrs = 20, |
230 |
|
|
dsMFMDrive = 22, |
231 |
|
|
dsMFMDisk = 23, |
232 |
|
|
dsTwoMegFmt = 24 |
233 |
|
|
}; |
234 |
|
|
|
235 |
|
|
enum { // DrvSts2 struct |
236 |
|
|
dsDriveSize = 18, |
237 |
|
|
dsDriveS1 = 20, |
238 |
|
|
dsDriveType = 22, |
239 |
|
|
dsDriveManf = 24, |
240 |
|
|
dsDriveChar = 26, |
241 |
|
|
dsDriveMisc = 28, |
242 |
|
|
SIZEOF_DrvSts = 30 |
243 |
|
|
}; |
244 |
|
|
|
245 |
|
|
enum { // DCtlEntry struct |
246 |
|
|
dCtlDriver = 0, |
247 |
|
|
dCtlFlags = 4, |
248 |
|
|
dCtlQHdr = 6, |
249 |
|
|
dCtlPosition = 16, |
250 |
|
|
dCtlStorage = 20, |
251 |
|
|
dCtlRefNum = 24, |
252 |
|
|
dCtlCurTicks = 26, |
253 |
|
|
dCtlWindow = 30, |
254 |
|
|
dCtlDelay = 34, |
255 |
|
|
dCtlEMask = 36, |
256 |
|
|
dCtlMenu = 38, |
257 |
|
|
dCtlSlot = 40, |
258 |
|
|
dCtlSlotId = 41, |
259 |
|
|
dCtlDevBase = 42, |
260 |
|
|
dCtlOwner = 46, |
261 |
|
|
dCtlExtDev = 50, |
262 |
|
|
dCtlFillByte = 51, |
263 |
|
|
dCtlNodeID = 52 |
264 |
|
|
}; |
265 |
|
|
|
266 |
|
|
|
267 |
|
|
/* |
268 |
|
|
* Definitions for native Device Manager |
269 |
|
|
*/ |
270 |
|
|
|
271 |
|
|
// Registry EntryID |
272 |
|
|
struct RegEntryID { |
273 |
|
|
uint32 contents[4]; |
274 |
|
|
}; |
275 |
|
|
|
276 |
|
|
// Command codes |
277 |
|
|
enum { |
278 |
|
|
kOpenCommand = 0, |
279 |
|
|
kCloseCommand = 1, |
280 |
|
|
kReadCommand = 2, |
281 |
|
|
kWriteCommand = 3, |
282 |
|
|
kControlCommand = 4, |
283 |
|
|
kStatusCommand = 5, |
284 |
|
|
kKillIOCommand = 6, |
285 |
|
|
kInitializeCommand = 7, /* init driver and device*/ |
286 |
|
|
kFinalizeCommand = 8, /* shutdown driver and device*/ |
287 |
|
|
kReplaceCommand = 9, /* replace an old driver*/ |
288 |
|
|
kSupersededCommand = 10, /* prepare to be replaced by a new driver*/ |
289 |
|
|
kSuspendCommand = 11, /* prepare driver to go to sleep*/ |
290 |
|
|
kResumeCommand = 12 /* wake up sleeping driver*/ |
291 |
|
|
}; |
292 |
|
|
|
293 |
|
|
// Command kinds |
294 |
|
|
enum { |
295 |
|
|
kSynchronousIOCommandKind = 0x00000001, |
296 |
|
|
kAsynchronousIOCommandKind = 0x00000002, |
297 |
|
|
kImmediateIOCommandKind = 0x00000004 |
298 |
|
|
}; |
299 |
|
|
|
300 |
|
|
|
301 |
|
|
/* |
302 |
|
|
* Definitions for Mixed Mode Manager |
303 |
|
|
*/ |
304 |
|
|
|
305 |
|
|
typedef uint32 ProcInfoType; |
306 |
|
|
typedef int8 ISAType; |
307 |
|
|
typedef uint16 RoutineFlagsType; |
308 |
gbeauche |
1.3 |
typedef uint32 ProcPtr; |
309 |
cebix |
1.1 |
typedef uint8 RDFlagsType; |
310 |
|
|
|
311 |
|
|
struct RoutineRecord { |
312 |
|
|
ProcInfoType procInfo; /* calling conventions */ |
313 |
|
|
int8 reserved1; /* Must be 0 */ |
314 |
|
|
ISAType ISA; /* Instruction Set Architecture */ |
315 |
|
|
RoutineFlagsType routineFlags; /* Flags for each routine */ |
316 |
|
|
ProcPtr procDescriptor; /* Where is the thing weĠre calling? */ |
317 |
|
|
uint32 reserved2; /* Must be 0 */ |
318 |
|
|
uint32 selector; /* For dispatched routines, the selector */ |
319 |
|
|
}; |
320 |
|
|
|
321 |
|
|
struct RoutineDescriptor { |
322 |
|
|
uint16 goMixedModeTrap; /* Our A-Trap */ |
323 |
|
|
int8 version; /* Current Routine Descriptor version */ |
324 |
|
|
RDFlagsType routineDescriptorFlags; /* Routine Descriptor Flags */ |
325 |
|
|
uint32 reserved1; /* Unused, must be zero */ |
326 |
|
|
uint8 reserved2; /* Unused, must be zero */ |
327 |
|
|
uint8 selectorInfo; /* If a dispatched routine, calling convention, else 0 */ |
328 |
|
|
uint16 routineCount; /* Number of routines in this RD */ |
329 |
|
|
RoutineRecord routineRecords[1]; /* The individual routines */ |
330 |
|
|
}; |
331 |
|
|
|
332 |
gbeauche |
1.3 |
struct SheepRoutineDescriptor |
333 |
|
|
: public SheepVar |
334 |
|
|
{ |
335 |
|
|
SheepRoutineDescriptor(ProcInfoType procInfo, uint32 procedure) |
336 |
|
|
: SheepVar(sizeof(RoutineDescriptor)) |
337 |
|
|
{ |
338 |
|
|
const uintptr desc = addr(); |
339 |
|
|
Mac_memset(desc, 0, sizeof(RoutineDescriptor)); |
340 |
|
|
WriteMacInt16(desc + offsetof(RoutineDescriptor, goMixedModeTrap), 0xAAFE); |
341 |
|
|
WriteMacInt8 (desc + offsetof(RoutineDescriptor, version), 7); |
342 |
|
|
WriteMacInt32(desc + offsetof(RoutineDescriptor, routineRecords[0].procInfo), procInfo); |
343 |
|
|
WriteMacInt8 (desc + offsetof(RoutineDescriptor, routineRecords[0].ISA), 1); |
344 |
|
|
WriteMacInt16(desc + offsetof(RoutineDescriptor, routineRecords[0].routineFlags), 0 | 0 | 4); |
345 |
|
|
WriteMacInt32(desc + offsetof(RoutineDescriptor, routineRecords[0].procDescriptor), procedure); |
346 |
cebix |
1.1 |
} |
347 |
gbeauche |
1.3 |
}; |
348 |
cebix |
1.1 |
|
349 |
|
|
|
350 |
|
|
// Functions |
351 |
|
|
extern void MacOSUtilReset(void); |
352 |
|
|
extern void Enqueue(uint32 elem, uint32 list); // Enqueue QElem to list |
353 |
|
|
extern int FindFreeDriveNumber(int num); // Find first free drive number, starting at "num" |
354 |
|
|
extern void MountVolume(void *fh); // Mount volume with given file handle (see sys.h) |
355 |
|
|
extern void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size); // Calculate disk image file layout given file size and first 256 data bytes |
356 |
|
|
extern void *FindLibSymbol(char *lib, char *sym); // Find symbol in shared library |
357 |
|
|
extern void InitCallUniversalProc(void); // Init CallUniversalProc() |
358 |
|
|
extern long CallUniversalProc(void *upp, uint32 info); // CallUniversalProc() |
359 |
|
|
extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time |
360 |
|
|
|
361 |
|
|
// Construct four-character-code from string |
362 |
|
|
#define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d)) |
363 |
|
|
|
364 |
|
|
// Emulator identification codes (4 and 2 characters) |
365 |
|
|
const uint32 EMULATOR_ID_4 = 0x62616168; // 'baah' |
366 |
|
|
const uint16 EMULATOR_ID_2 = 0x6261; // 'ba' |
367 |
|
|
|
368 |
|
|
// Test if basic MacOS initializations (of the ROM) are done |
369 |
|
|
static inline bool HasMacStarted(void) |
370 |
|
|
{ |
371 |
|
|
return ReadMacInt32(0xcfc) == FOURCC('W','L','S','C'); // Mac warm start flag |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
#endif |