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 |
|
} |
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 |
+ |
} |