253 |
|
|
254 |
|
|
255 |
|
/* |
256 |
+ |
* Set error code in DskErr |
257 |
+ |
*/ |
258 |
+ |
|
259 |
+ |
static int16 set_dsk_err(int16 err) |
260 |
+ |
{ |
261 |
+ |
WriteMacInt16(0x142, err); |
262 |
+ |
return err; |
263 |
+ |
} |
264 |
+ |
|
265 |
+ |
|
266 |
+ |
/* |
267 |
|
* Driver Open() routine |
268 |
|
*/ |
269 |
|
|
284 |
|
WriteMacInt32(0x134, 0xdeadbeef); |
285 |
|
|
286 |
|
// Clear DskErr |
287 |
< |
WriteMacInt16(0x142, 0); |
287 |
> |
set_dsk_err(0); |
288 |
|
|
289 |
|
// Install drives |
290 |
|
for (DriveInfo *info = first_drive_info; info; info = info->next) { |
343 |
|
// Drive valid and disk inserted? |
344 |
|
DriveInfo *info; |
345 |
|
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
346 |
< |
return nsDrvErr; |
346 |
> |
return set_dsk_err(nsDrvErr); |
347 |
|
if (!ReadMacInt8(info->status + dsDiskInPlace)) |
348 |
< |
return offLinErr; |
348 |
> |
return set_dsk_err(offLinErr); |
349 |
|
WriteMacInt8(info->status + dsDiskInPlace, 2); // Disk accessed |
350 |
|
|
351 |
|
// Get parameters |
353 |
|
size_t length = ReadMacInt32(pb + ioReqCount); |
354 |
|
loff_t position = ReadMacInt32(dce + dCtlPosition); |
355 |
|
if ((length & 0x1ff) || (position & 0x1ff)) |
356 |
< |
return paramErr; |
356 |
> |
return set_dsk_err(paramErr); |
357 |
|
|
358 |
|
size_t actual = 0; |
359 |
|
if ((ReadMacInt16(pb + ioTrap) & 0xff) == aRdCmd) { |
361 |
|
// Read |
362 |
|
actual = Sys_read(info->fh, buffer, position, length); |
363 |
|
if (actual != length) |
364 |
< |
return readErr; |
364 |
> |
return set_dsk_err(readErr); |
365 |
|
|
366 |
|
// Clear TagBuf |
367 |
|
WriteMacInt32(0x2fc, 0); |
372 |
|
|
373 |
|
// Write |
374 |
|
if (info->read_only) |
375 |
< |
return wPrErr; |
375 |
> |
return set_dsk_err(wPrErr); |
376 |
|
actual = Sys_write(info->fh, buffer, position, length); |
377 |
|
if (actual != length) |
378 |
< |
return writErr; |
378 |
> |
return set_dsk_err(writErr); |
379 |
|
} |
380 |
|
|
381 |
|
// Update ParamBlock and DCE |
382 |
|
WriteMacInt32(pb + ioActCount, actual); |
383 |
|
WriteMacInt32(dce + dCtlPosition, ReadMacInt32(dce + dCtlPosition) + actual); |
384 |
< |
return noErr; |
384 |
> |
return set_dsk_err(noErr); |
385 |
|
} |
386 |
|
|
387 |
|
|
397 |
|
// General codes |
398 |
|
switch (code) { |
399 |
|
case 1: // KillIO |
400 |
< |
return -1; |
400 |
> |
return set_dsk_err(-1); |
401 |
|
|
402 |
|
case 9: // Track cache |
403 |
< |
return noErr; |
403 |
> |
return set_dsk_err(noErr); |
404 |
|
|
405 |
|
case 65: // Periodic action (accRun, "insert" disks on startup) |
406 |
|
mount_mountable_volumes(); |
413 |
|
// Drive valid? |
414 |
|
DriveInfo *info; |
415 |
|
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
416 |
< |
return nsDrvErr; |
416 |
> |
return set_dsk_err(nsDrvErr); |
417 |
|
|
418 |
|
// Drive-specific codes |
419 |
+ |
int16 err = noErr; |
420 |
|
switch (code) { |
421 |
|
case 5: // Verify disk |
422 |
< |
if (ReadMacInt8(info->status + dsDiskInPlace) > 0) |
423 |
< |
return noErr; |
424 |
< |
else |
413 |
< |
return verErr; |
422 |
> |
if (ReadMacInt8(info->status + dsDiskInPlace) <= 0) |
423 |
> |
err = verErr; |
424 |
> |
break; |
425 |
|
|
426 |
|
case 6: // Format disk |
427 |
|
if (info->read_only) |
428 |
< |
return wPrErr; |
428 |
> |
err = wPrErr; |
429 |
|
else if (ReadMacInt8(info->status + dsDiskInPlace) > 0) { |
430 |
< |
if (SysFormat(info->fh)) |
431 |
< |
return noErr; |
421 |
< |
else |
422 |
< |
return writErr; |
430 |
> |
if (!SysFormat(info->fh)) |
431 |
> |
err = writErr; |
432 |
|
} else |
433 |
< |
return offLinErr; |
433 |
> |
err = offLinErr; |
434 |
> |
break; |
435 |
|
|
436 |
|
case 7: // Eject |
437 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) > 0) { |
438 |
|
SysEject(info->fh); |
439 |
|
WriteMacInt8(info->status + dsDiskInPlace, 0); |
440 |
|
} |
441 |
< |
return noErr; |
441 |
> |
break; |
442 |
|
|
443 |
|
case 8: // Set tag buffer |
444 |
|
info->tag_buffer = ReadMacInt32(pb + csParam); |
445 |
< |
return noErr; |
445 |
> |
break; |
446 |
|
|
447 |
|
case 21: // Get drive icon |
448 |
|
WriteMacInt32(pb + csParam, SonyDriveIconAddr); |
449 |
< |
return noErr; |
449 |
> |
break; |
450 |
|
|
451 |
|
case 22: // Get disk icon |
452 |
|
WriteMacInt32(pb + csParam, SonyDiskIconAddr); |
453 |
< |
return noErr; |
453 |
> |
break; |
454 |
|
|
455 |
|
case 23: // Get drive info |
456 |
|
if (info->num == 1) |
457 |
|
WriteMacInt32(pb + csParam, 0x0004); // Internal drive |
458 |
|
else |
459 |
|
WriteMacInt32(pb + csParam, 0x0104); // External drive |
460 |
< |
return noErr; |
460 |
> |
break; |
461 |
|
|
462 |
< |
case 0x5343: { // Format and write to disk ('SC'), used by DiskCopy |
462 |
> |
case 0x5343: // Format and write to disk ('SC'), used by DiskCopy |
463 |
|
if (!ReadMacInt8(info->status + dsDiskInPlace)) |
464 |
< |
return offLinErr; |
465 |
< |
if (info->read_only) |
466 |
< |
return wPrErr; |
467 |
< |
|
468 |
< |
void *data = Mac2HostAddr(ReadMacInt32(pb + csParam + 2)); |
469 |
< |
size_t actual = Sys_write(info->fh, data, 0, 2880*512); |
470 |
< |
if (actual != 2880*512) |
471 |
< |
return writErr; |
472 |
< |
else |
473 |
< |
return noErr; |
464 |
< |
} |
464 |
> |
err = offLinErr; |
465 |
> |
else if (info->read_only) |
466 |
> |
err = wPrErr; |
467 |
> |
else { |
468 |
> |
void *data = Mac2HostAddr(ReadMacInt32(pb + csParam + 2)); |
469 |
> |
size_t actual = Sys_write(info->fh, data, 0, 2880*512); |
470 |
> |
if (actual != 2880*512) |
471 |
> |
err = writErr; |
472 |
> |
} |
473 |
> |
break; |
474 |
|
|
475 |
|
default: |
476 |
|
printf("WARNING: Unknown SonyControl(%d)\n", code); |
477 |
< |
return controlErr; |
477 |
> |
err = controlErr; |
478 |
> |
break; |
479 |
|
} |
480 |
+ |
|
481 |
+ |
return set_dsk_err(err); |
482 |
|
} |
483 |
|
|
484 |
|
|
494 |
|
// Drive valid? |
495 |
|
DriveInfo *info; |
496 |
|
if ((info = get_drive_info(ReadMacInt16(pb + ioVRefNum))) == NULL) |
497 |
< |
return nsDrvErr; |
497 |
> |
return set_dsk_err(nsDrvErr); |
498 |
|
|
499 |
+ |
int16 err = noErr; |
500 |
|
switch (code) { |
501 |
|
case 6: // Return format list |
502 |
|
if (ReadMacInt16(pb + csParam) > 0) { |
504 |
|
WriteMacInt16(pb + csParam, 1); // 1 format |
505 |
|
WriteMacInt32(adr, 2880); // 2880 sectors |
506 |
|
WriteMacInt32(adr + 4, 0xd2120050); // 2 heads, 18 secs/track, 80 tracks |
494 |
– |
return noErr; |
507 |
|
} else |
508 |
< |
return paramErr; |
508 |
> |
err = paramErr; |
509 |
> |
break; |
510 |
|
|
511 |
|
case 8: // Get drive status |
512 |
|
Mac2Mac_memcpy(pb + csParam, info->status, 22); |
513 |
< |
return noErr; |
513 |
> |
break; |
514 |
|
|
515 |
|
case 10: // Get disk type |
516 |
|
WriteMacInt32(pb + csParam, ReadMacInt32(info->status + dsMFMDrive) & 0xffffff00 | 0xfe); |
517 |
< |
return noErr; |
517 |
> |
break; |
518 |
|
|
519 |
|
case 0x4456: // Duplicator version supported ('DV') |
520 |
|
WriteMacInt16(pb + csParam, 0x0410); |
521 |
< |
return noErr; |
521 |
> |
break; |
522 |
|
|
523 |
|
case 0x5343: // Get address header format byte ('SC') |
524 |
|
WriteMacInt8(pb + csParam, 0x22); // 512 bytes/sector |
525 |
< |
return noErr; |
525 |
> |
break; |
526 |
|
|
527 |
|
default: |
528 |
|
printf("WARNING: Unknown SonyStatus(%d)\n", code); |
529 |
< |
return statusErr; |
529 |
> |
err = statusErr; |
530 |
> |
break; |
531 |
|
} |
532 |
+ |
|
533 |
+ |
return set_dsk_err(err); |
534 |
|
} |
535 |
|
|
536 |
|
|