/*
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"/*
ReportAbnormalID unused 0x090B - 0x09FF
*/LOCALVARui5bvSonyMountedMask=0;#define vSonyIsLocked(Drive_No) \ ((vSonyWritableMask & ((ui5b)1 << (Drive_No))) == 0)#define vSonyIsMounted(Drive_No) \ ((vSonyMountedMask & ((ui5b)1 << (Drive_No))) != 0)LOCALFUNCblnrvSonyNextPendingInsert0(tDrive*Drive_No){/* find next drive to Mount */ui5bMountPending=vSonyInsertedMask&(~vSonyMountedMask);if(MountPending!=0){tDrivei;for(i=0;i<NumDrives;++i){if((MountPending&((ui5b)1<<i))!=0){*Drive_No=i;returntrueblnr;/* only one disk at a time */}}}returnfalseblnr;}LOCALFUNCtMacErrCheckReadableDrive(tDriveDrive_No){tMacErrresult;if(Drive_No>=NumDrives){result=mnvm_nsDrvErr;}elseif(!vSonyIsMounted(Drive_No)){result=mnvm_offLinErr;}else{result=mnvm_noErr;}returnresult;}LOCALFUNCtMacErrvSonyTransferVM(blnrIsWrite,CPTRBuffera,tDriveDrive_No,ui5rSony_Start,ui5rSony_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.)
*/tMacErrresult;ui5bcontig;ui5ractual;ui3pBuffer;ui5roffset=Sony_Start;ui5rn=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){gotolabel_1;}}}if(nullpr!=Sony_ActCount){*Sony_ActCount=Sony_Count-n;}returnresult;}LOCALPROCMyMoveBytesVM(CPTRsrcPtr,CPTRdstPtr,si5bbyteCount){ui3psrc;ui3pdst;ui5bcontigSrc;ui5bcontigDst;ui5rcontig;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)){ReportAbnormalID(0x0901,"MyMoveBytesVM fails");}else{contig=(contigSrc<contigDst)?contigSrc:contigDst;MyMoveBytes(src,dst,contig);srcPtr+=contig;dstPtr+=contig;byteCount-=contig;gotolabel_1;}}}LOCALVARui5rImageDataOffset[NumDrives];/* size of any header in disk image file */LOCALVARui5rImageDataSize[NumDrives];/* size of disk image file contents */#if Sony_SupportTagsLOCALVARui5rImageTagOffset[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