1 |
|
/* |
2 |
|
* disk.cpp - Generic disk driver |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2000 Christian Bauer |
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 |
90 |
|
// Icon address (Mac address space, set by PatchROM()) |
91 |
|
uint32 DiskIconAddr; |
92 |
|
|
93 |
+ |
// Flag: Control(accRun) has been called, interrupt routine is now active |
94 |
+ |
static bool acc_run_called = false; |
95 |
+ |
|
96 |
|
|
97 |
|
/* |
98 |
|
* Get pointer to drive info, NULL = invalid drive number |
187 |
|
|
188 |
|
|
189 |
|
/* |
190 |
+ |
* Mount volumes for which the to_be_mounted flag is set |
191 |
+ |
* (called during interrupt time) |
192 |
+ |
*/ |
193 |
+ |
|
194 |
+ |
static void mount_mountable_volumes(void) |
195 |
+ |
{ |
196 |
+ |
DriveInfo *info = first_drive_info; |
197 |
+ |
while (info != NULL) { |
198 |
+ |
|
199 |
+ |
// Disk in drive? |
200 |
+ |
if (!ReadMacInt8(info->status + dsDiskInPlace)) { |
201 |
+ |
|
202 |
+ |
// No, check if disk was inserted |
203 |
+ |
if (SysIsDiskInserted(info->fh)) |
204 |
+ |
DiskMountVolume(info->fh); |
205 |
+ |
} |
206 |
+ |
|
207 |
+ |
// Mount disk if flagged |
208 |
+ |
if (info->to_be_mounted) { |
209 |
+ |
D(bug(" mounting drive %d\n", info->num)); |
210 |
+ |
M68kRegisters r; |
211 |
+ |
r.d[0] = info->num; |
212 |
+ |
r.a[0] = 7; // diskEvent |
213 |
+ |
Execute68kTrap(0xa02f, &r); // PostEvent() |
214 |
+ |
info->to_be_mounted = false; |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
info = info->next; |
218 |
+ |
} |
219 |
+ |
} |
220 |
+ |
|
221 |
+ |
|
222 |
+ |
/* |
223 |
|
* Driver Open() routine |
224 |
|
*/ |
225 |
|
|
229 |
|
|
230 |
|
// Set up DCE |
231 |
|
WriteMacInt32(dce + dCtlPosition, 0); |
232 |
+ |
acc_run_called = false; |
233 |
|
|
234 |
|
// Install drives |
235 |
|
for (DriveInfo *info = first_drive_info; info; info = info->next) { |
265 |
|
info->num_blocks = SysGetFileSize(info->fh) / 512; |
266 |
|
info->to_be_mounted = true; |
267 |
|
} |
268 |
< |
D(bug(" %ld blocks\n", info->num_blocks)); |
268 |
> |
D(bug(" %d blocks\n", info->num_blocks)); |
269 |
|
WriteMacInt16(info->status + dsDriveSize, info->num_blocks & 0xffff); |
270 |
|
WriteMacInt16(info->status + dsDriveS1, info->num_blocks >> 16); |
271 |
|
|
343 |
|
case 1: // KillIO |
344 |
|
return noErr; |
345 |
|
|
346 |
< |
case 65: { // Periodic action ("insert" disks on startup and check for disk changes) |
347 |
< |
DriveInfo *info = first_drive_info; |
348 |
< |
while (info != NULL) { |
349 |
< |
|
313 |
< |
// Disk in drive? |
314 |
< |
if (!ReadMacInt8(info->status + dsDiskInPlace)) { |
315 |
< |
|
316 |
< |
// No, check if disk was inserted |
317 |
< |
if (SysIsDiskInserted(info->fh)) |
318 |
< |
DiskMountVolume(info->fh); |
319 |
< |
} |
320 |
< |
|
321 |
< |
// Mount disk if flagged |
322 |
< |
if (info->to_be_mounted) { |
323 |
< |
D(bug(" mounting drive %d\n", info->num)); |
324 |
< |
M68kRegisters r; |
325 |
< |
r.d[0] = info->num; |
326 |
< |
r.a[0] = 7; // diskEvent |
327 |
< |
Execute68kTrap(0xa02f, &r); // PostEvent() |
328 |
< |
info->to_be_mounted = false; |
329 |
< |
} |
330 |
< |
|
331 |
< |
info = info->next; |
332 |
< |
} |
346 |
> |
case 65: { // Periodic action (accRun, "insert" disks on startup) |
347 |
> |
mount_mountable_volumes(); |
348 |
> |
WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000); // Disable periodic action |
349 |
> |
acc_run_called = true; |
350 |
|
return noErr; |
351 |
|
} |
352 |
|
} |
427 |
|
uint32 sel = ReadMacInt32(pb + csParam); |
428 |
|
D(bug(" driver gestalt %c%c%c%c\n", sel >> 24, sel >> 16, sel >> 8, sel)); |
429 |
|
switch (sel) { |
430 |
< |
case 'vers': // Version |
430 |
> |
case FOURCC('v','e','r','s'): // Version |
431 |
|
WriteMacInt32(pb + csParam + 4, 0x01008000); |
432 |
|
break; |
433 |
< |
case 'devt': // Device type |
433 |
> |
case FOURCC('d','e','v','t'): // Device type |
434 |
|
if (info != NULL) { |
435 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) == 8) |
436 |
< |
WriteMacInt32(pb + csParam + 4, 'disk'); |
436 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('d','i','s','k')); |
437 |
|
else |
438 |
< |
WriteMacInt32(pb + csParam + 4, 'rdsk'); |
438 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('r','d','s','k')); |
439 |
|
} else |
440 |
< |
WriteMacInt32(pb + csParam + 4, 'disk'); |
440 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('d','i','s','k')); |
441 |
|
break; |
442 |
< |
case 'intf': // Interface type |
443 |
< |
WriteMacInt32(pb + csParam + 4, 'basi'); |
442 |
> |
case FOURCC('i','n','t','f'): // Interface type |
443 |
> |
WriteMacInt32(pb + csParam + 4, EMULATOR_ID_4); |
444 |
|
break; |
445 |
< |
case 'sync': // Only synchronous operation? |
445 |
> |
case FOURCC('s','y','n','c'): // Only synchronous operation? |
446 |
|
WriteMacInt32(pb + csParam + 4, 0x01000000); |
447 |
|
break; |
448 |
< |
case 'boot': // Boot ID |
448 |
> |
case FOURCC('b','o','o','t'): // Boot ID |
449 |
|
if (info != NULL) |
450 |
|
WriteMacInt16(pb + csParam + 4, info->num); |
451 |
|
else |
452 |
|
WriteMacInt16(pb + csParam + 4, 0); |
453 |
|
WriteMacInt16(pb + csParam + 6, (uint16)DiskRefNum); |
454 |
|
break; |
455 |
< |
case 'wide': // 64-bit access supported? |
455 |
> |
case FOURCC('w','i','d','e'): // 64-bit access supported? |
456 |
|
WriteMacInt16(pb + csParam + 4, 0x0100); |
457 |
|
break; |
458 |
< |
case 'purg': // Purge flags |
458 |
> |
case FOURCC('p','u','r','g'): // Purge flags |
459 |
|
WriteMacInt32(pb + csParam + 4, 0); |
460 |
|
break; |
461 |
< |
case 'ejec': // Eject flags |
461 |
> |
case FOURCC('e','j','e','c'): // Eject flags |
462 |
|
WriteMacInt32(pb + csParam + 4, 0x00030003); // Don't eject on shutdown/restart |
463 |
|
break; |
464 |
< |
case 'flus': // Flush flags |
464 |
> |
case FOURCC('f','l','u','s'): // Flush flags |
465 |
|
WriteMacInt16(pb + csParam + 4, 0); |
466 |
|
break; |
467 |
< |
case 'vmop': // Virtual memory attributes |
467 |
> |
case FOURCC('v','m','o','p'): // Virtual memory attributes |
468 |
|
WriteMacInt32(pb + csParam + 4, 0); // Drive not available for VM |
469 |
|
break; |
470 |
|
default: |
481 |
|
// Drive-specific codes |
482 |
|
switch (code) { |
483 |
|
case 8: // Get drive status |
484 |
< |
memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); |
484 |
> |
Mac2Mac_memcpy(pb + csParam, info->status, 22); |
485 |
|
return noErr; |
486 |
|
|
487 |
|
default: |
489 |
|
return statusErr; |
490 |
|
} |
491 |
|
} |
492 |
+ |
|
493 |
+ |
|
494 |
+ |
/* |
495 |
+ |
* Driver interrupt routine (1Hz) - check for volumes to be mounted |
496 |
+ |
*/ |
497 |
+ |
|
498 |
+ |
void DiskInterrupt(void) |
499 |
+ |
{ |
500 |
+ |
if (!acc_run_called) |
501 |
+ |
return; |
502 |
+ |
|
503 |
+ |
mount_mountable_volumes(); |
504 |
+ |
} |