mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-11-26 00:49:20 +00:00
1 line
34 KiB
C
1 line
34 KiB
C
|
/*
SONYEMDV.c
Copyright (C) 2009 Philip Cummins, Jesus A. Alvarez, Paul C. Pratt
You can redistribute this file and/or modify it under the terms
of version 2 of the GNU General Public License as published by
the Free Software Foundation. You should have received a copy
of the license along with this file; see the file COPYING.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
license for more details.
*/
/*
SONY floppy disk EMulated DeVice
The Sony hardware is not actually emulated. Instead the
ROM is patched to replace the Sony disk driver with
code that calls Mini vMac extensions implemented in
the file.
Information neeeded to better support the Disk Copy 4.2
format was found in libdc42.c of the Lisa Emulator Project
by Ray A. Arachelian, and adapted to Mini vMac
by Jesus A. Alvarez.
*/
#ifndef AllFiles
#include "SYSDEPNS.h"
#include "MYOSGLUE.h"
#include "ENDIANAC.h"
#include "EMCONFIG.h"
#include "GLOBGLUE.h"
#include "MINEM68K.h"
#endif
#include "SONYEMDV.h"
LOCALVAR ui5b vSonyMountedMask = 0;
#define vSonyIsLocked(Drive_No) \
((vSonyWritableMask & ((ui5b)1 << (Drive_No))) == 0)
#define vSonyIsMounted(Drive_No) \
((vSonyMountedMask & ((ui5b)1 << (Drive_No))) != 0)
LOCALFUNC blnr vSonyNextPendingInsert0(tDrive *Drive_No)
{
/* find next drive to Mount */
ui5b MountPending = vSonyInsertedMask & (~ vSonyMountedMask);
if (MountPending != 0) {
tDrive i;
for (i = 0; i < NumDrives; ++i) {
if ((MountPending & ((ui5b)1 << i)) != 0) {
*Drive_No = i;
return trueblnr; /* only one disk at a time */
}
}
}
return falseblnr;
}
LOCALFUNC tMacErr CheckReadableDrive(tDrive Drive_No)
{
tMacErr result;
if (Drive_No >= NumDrives) {
result = mnvm_nsDrvErr;
} else if (! vSonyIsMounted(Drive_No)) {
result = mnvm_offLinErr;
} else {
result = mnvm_noErr;
}
return result;
}
LOCALFUNC tMacErr vSonyTransferVM(blnr IsWrite,
CPTR Buffera, tDrive Drive_No,
ui5r Sony_Start, ui5r Sony_Count, ui5r *Sony_ActCount)
{
/*
Transfer data between emulated disk and emulated memory. Taking
into account that the emulated memory may not be contiguous in
real memory. (Though it generally is for macintosh emulation.)
*/
tMacErr result;
ui5b contig;
ui5r actual;
ui3p Buffer;
ui5r offset = Sony_Start;
ui5r n = Sony_Count;
label_1:
if (0 == n) {
result = mnvm_noErr;
} else {
Buffer = get_real_address0(n, ! IsWrite, Buffera, &contig);
if (0 == contig) {
result = mnvm_miscErr;
} else {
result = vSonyTransfer(IsWrite, Buffer, Drive_No,
offset, contig, &actual);
offset += actual;
Buffera += actual;
n -= actual;
if (mnvm_noErr == result) {
goto label_1;
}
}
}
if (nullpr != Sony_ActCount) {
*Sony_ActCount = Sony_Count - n;
}
return result;
}
LOCALPROC MyMoveBytesVM(CPTR srcPtr, CPTR dstPtr, si5b byteCount)
{
ui3p src;
ui3p dst;
ui5b contigSrc;
ui5b contigDst;
ui5r contig;
label_1:
if (0 != byteCount) {
src = get_real_address0(byteCount, falseblnr, srcPtr,
&contigSrc);
dst = get_real_address0(byteCount, trueblnr, dstPtr,
&contigDst);
if ((0 == contigSrc) || (0 == contigDst)) {
ReportAbnormal("MyMoveBytesVM fails");
} else {
contig = (contigSrc < contigDst) ? contigSrc : contigDst;
MyMoveBytes(src, dst, contig);
srcPtr += contig;
dstPtr += contig;
byteCount -= contig;
goto label_1;
}
}
}
LOCALVAR ui5r ImageDataOffset[NumDrives];
/* size of any header in disk image file */
LOCALVAR ui5r ImageDataSize[NumDrives];
/* size of disk image file contents */
#if Sony_SupportTags
LOCALVAR ui5r ImageTagOffset[NumDrives];
/* offset to disk image file tags */
#endif
#if Sony_SupportDC42
#define kDC42offset_diskName 0
#define kDC42offset_dataSize 64
#define kDC42offset_tagSize 68
#define kDC42offset_dataChecksum 72
#define kDC42offset_tagChecksum 76
#define kDC42offset_diskFormat 80
#define kDC42offset_formatByte 81
#define kDC42offset_private
|