From 9e3420771442a9e19a27ab11a3e4910a9f6dc7a9 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 18 Mar 2014 18:34:22 +0200 Subject: [PATCH] capslib raw dump support. --- od-win32/caps/CapsAPI.h | 77 ++++++++++++++++++++++++++++++++++-- od-win32/caps/CapsLib.h | 16 ++++++-- od-win32/caps/Comlib.h | 4 +- od-win32/caps/caps_win32.cpp | 59 ++++++++++++++++++++++++--- od-win32/caps/caps_win32.h | 4 +- 5 files changed, 145 insertions(+), 15 deletions(-) diff --git a/od-win32/caps/CapsAPI.h b/od-win32/caps/CapsAPI.h index 3eb08186..367b646e 100644 --- a/od-win32/caps/CapsAPI.h +++ b/od-win32/caps/CapsAPI.h @@ -135,15 +135,52 @@ struct CapsTrackInfoT2 { typedef struct CapsTrackInfoT2 *PCAPSTRACKINFOT2; +// disk sector information block +struct CapsSectorInfo { + UDWORD descdatasize; // data size in bits from IPF descriptor + UDWORD descgapsize; // gap size in bits from IPF descriptor + UDWORD datasize; // data size in bits from decoder + UDWORD gapsize; // gap size in bits from decoder + UDWORD datastart; // data start position in bits from decoder + UDWORD gapstart; // gap start position in bits from decoder + UDWORD gapsizews0; // gap size before write splice + UDWORD gapsizews1; // gap size after write splice + UDWORD gapws0mode; // gap size mode before write splice + UDWORD gapws1mode; // gap size mode after write splice + UDWORD celltype; // bitcell type + UDWORD enctype; // encoder type +}; + +typedef struct CapsSectorInfo *PCAPSSECTORINFO; + +// disk data information block +struct CapsDataInfo { + UDWORD type; // data type + UDWORD start; // start position + UDWORD size; // size in bits +}; + +typedef struct CapsDataInfo *PCAPSDATAINFO; + +// disk data information block +struct CapsRevolutionInfo { + SDWORD next; // the revolution number used by the next track lock call + SDWORD last; // the revolution number used by the lack track lock call + SDWORD real; // the real revolution number used by the last track lock call + SDWORD max; // the maximum revolution available for the selected track, <0 unlimited/randomized, 0 empty +}; + +typedef struct CapsRevolutionInfo *PCAPSREVOLUTIONINFO; + #pragma pack(pop) -// image type +// CapsImageInfo.image type enum { ciitNA=0, // invalid image type ciitFDD // floppy disk }; -// platform IDs, not about configuration, but intended use +// CapsImageInfo.platform IDs, not about configuration, but intended use enum { ciipNA=0, // invalid platform (dummy entry) ciipAmiga, @@ -157,7 +194,7 @@ enum { ciipAtari8 }; -// track type +// CapsTrackInfo.track type enum { ctitNA=0, // invalid type ctitNoise, // cells are unformatted (random size) @@ -165,6 +202,40 @@ enum { ctitVar // variable density }; +// CapsSectorInfo.bitcell type +enum { + csicNA=0, // invalid cell type + csic2us // 2us cells +}; + +// CapsSectorInfo.encoder type +enum { + csieNA=0, // undefined encoder + csieMFM, // MFM + csieRaw // no encoder used, test data only +}; + +// CapsSectorInfo.gap size mode +enum { + csiegmFixed=0, // fixed size, can't be changed + csiegmAuto, // size can be changed, resize information calculated automatically + csiegmResize // size can be changed, resize information is scripted +}; + +// CapsDataInfo.data type +enum { + cditNA=0, // undefined + cditWeak // weak bits +}; + +// CAPSGetInfo inftype +enum { + cgiitNA=0, // illegal + cgiitSector, // CapsSectorInfo + cgiitWeak, // CapsDataInfo, weak bits + cgiitRevolution // CapsRevolutionInfo +}; + // image error status enum { imgeOk=0, diff --git a/od-win32/caps/CapsLib.h b/od-win32/caps/CapsLib.h index dbb13da9..646bc613 100644 --- a/od-win32/caps/CapsLib.h +++ b/od-win32/caps/CapsLib.h @@ -5,7 +5,7 @@ #ifdef CAPS_USER #define LIB_USER #endif -#include "comlib.h" +#include "ComLib.h" ExtSub SDWORD __cdecl CAPSInit(); ExtSub SDWORD __cdecl CAPSExit(); @@ -16,10 +16,20 @@ ExtSub SDWORD __cdecl CAPSLockImageMemory(SDWORD id, PUBYTE buffer, UDWORD lengt ExtSub SDWORD __cdecl CAPSUnlockImage(SDWORD id); ExtSub SDWORD __cdecl CAPSLoadImage(SDWORD id, UDWORD flag); ExtSub SDWORD __cdecl CAPSGetImageInfo(PCAPSIMAGEINFO pi, SDWORD id); -ExtSub SDWORD __cdecl CAPSLockTrack(PCAPSTRACKINFO pi, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD flag); +ExtSub SDWORD __cdecl CAPSLockTrack(PVOID ptrackinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD flag); ExtSub SDWORD __cdecl CAPSUnlockTrack(SDWORD id, UDWORD cylinder, UDWORD head); ExtSub SDWORD __cdecl CAPSUnlockAllTracks(SDWORD id); ExtSub PCHAR __cdecl CAPSGetPlatformName(UDWORD pid); -ExtSub SDWORD __cdecl CAPSGetVersionInfo(PCAPSVERSIONINFO pi, UDWORD flag); +ExtSub SDWORD __cdecl CAPSGetVersionInfo(PVOID pversioninfo, UDWORD flag); +ExtSub UDWORD __cdecl CAPSFdcGetInfo(SDWORD iid, PCAPSFDC pc, SDWORD ext); +ExtSub SDWORD __cdecl CAPSFdcInit(PCAPSFDC pc); +ExtSub void __cdecl CAPSFdcReset(PCAPSFDC pc); +ExtSub void __cdecl CAPSFdcEmulate(PCAPSFDC pc, UDWORD cyclecnt); +ExtSub UDWORD __cdecl CAPSFdcRead(PCAPSFDC pc, UDWORD address); +ExtSub void __cdecl CAPSFdcWrite(PCAPSFDC pc, UDWORD address, UDWORD data); +ExtSub SDWORD __cdecl CAPSFdcInvalidateTrack(PCAPSFDC pc, SDWORD drive); +ExtSub SDWORD __cdecl CAPSFormatDataToMFM(PVOID pformattrack, UDWORD flag); +ExtSub SDWORD __cdecl CAPSGetInfo(PVOID pinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD inftype, UDWORD infid); +ExtSub SDWORD __cdecl CAPSSetRevolution(SDWORD id, UDWORD value); #endif diff --git a/od-win32/caps/Comlib.h b/od-win32/caps/Comlib.h index 4eb091e3..cab19ca1 100644 --- a/od-win32/caps/Comlib.h +++ b/od-win32/caps/Comlib.h @@ -15,6 +15,6 @@ #endif -#define ExtSub -#define ExtVar +#define ExtSub extern "C" DllSub +#define ExtVar extern "C" DllVar diff --git a/od-win32/caps/caps_win32.cpp b/od-win32/caps/caps_win32.cpp index 1449f192..39c204f2 100644 --- a/od-win32/caps/caps_win32.cpp +++ b/od-win32/caps/caps_win32.cpp @@ -15,6 +15,8 @@ #include "ComType.h" #include "CapsAPI.h" +#define CAPS_TRACKTIMING 1 + static SDWORD caps_cont[4]= {-1, -1, -1, -1}; static int caps_locked[4]; static int caps_flags = DI_LOCK_DENVAR|DI_LOCK_DENNOISE|DI_LOCK_NOISE|DI_LOCK_UPDATEFD|DI_LOCK_TYPE|DI_LOCK_OVLBIT; @@ -41,6 +43,10 @@ typedef SDWORD (__cdecl* CAPSUNLOCKALLTRACKS)(SDWORD); static CAPSUNLOCKALLTRACKS pCAPSUnlockAllTracks; typedef SDWORD (__cdecl* CAPSGETVERSIONINFO)(PCAPSVERSIONINFO,UDWORD); static CAPSGETVERSIONINFO pCAPSGetVersionInfo; +typedef SDWORD (__cdecl* CAPSGETINFO)(PVOID pinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD inftype, UDWORD infid); +static CAPSGETINFO pCAPSGetInfo; +typedef SDWORD (__cdecl* CAPSSETREVOLUTION)(SDWORD id, UDWORD value); +static CAPSSETREVOLUTION pCAPSSetRevolution; int caps_init (void) { @@ -84,6 +90,9 @@ int caps_init (void) pCAPSUnlockTrack = (CAPSUNLOCKTRACK)GetProcAddress (h, "CAPSUnlockTrack"); pCAPSUnlockAllTracks = (CAPSUNLOCKALLTRACKS)GetProcAddress (h, "CAPSUnlockAllTracks"); pCAPSGetVersionInfo = (CAPSGETVERSIONINFO)GetProcAddress (h, "CAPSGetVersionInfo"); + pCAPSGetInfo = (CAPSGETINFO)GetProcAddress (h, "CAPSGetInfo"); + pCAPSSetRevolution = (CAPSSETREVOLUTION)GetProcAddress (h, "CAPSSetRevolution"); + init = 1; cvi.type = 1; pCAPSGetVersionInfo (&cvi, 0); @@ -196,7 +205,7 @@ static void mfmcopy (uae_u16 *mfm, uae_u8 *data, int len) } } -static int load (struct CapsTrackInfoT2 *ci, int drv, int track, bool seed) +static int load (struct CapsTrackInfoT2 *ci, int drv, int track, bool seed, bool newtrack) { int flags; @@ -210,17 +219,21 @@ static int load (struct CapsTrackInfoT2 *ci, int drv, int track, bool seed) } else { ci->type = 1; } +#if 0 + if (newtrack) + flags |= DI_LOCK_NOUPDATE; +#endif if (pCAPSLockTrack ((PCAPSTRACKINFO)ci, caps_cont[drv], track / 2, track & 1, flags) != imgeOk) return 0; return 1; } -int caps_loadrevolution (uae_u16 *mfmbuf, int drv, int track, int *tracklength) +int caps_loadrevolution (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *nextrev) { int len; struct CapsTrackInfoT2 ci; - if (!load (&ci, drv, track, false)) + if (!load (&ci, drv, track, false, false)) return 0; if (oldlib) len = ci.tracklen * 8; @@ -228,18 +241,52 @@ int caps_loadrevolution (uae_u16 *mfmbuf, int drv, int track, int *tracklength) len = ci.tracklen; *tracklength = len; mfmcopy (mfmbuf, ci.trackbuf, len); +#if CAPS_TRACKTIMING + if (ci.timelen > 0 && tracktiming) { + for (int i = 0; i < ci.timelen; i++) + tracktiming[i] = (uae_u16)ci.timebuf[i]; + } +#endif + if (nextrev && pCAPSGetInfo) { + CapsRevolutionInfo pinfo; + *nextrev = 0; + pCAPSGetInfo(&pinfo, caps_cont[drv], track / 2, track & 1, cgiitRevolution, 0); + //write_log (_T("get next rev = %d\n"), pinfo.next); + if (pinfo.max > 0) + *nextrev = pinfo.next; + } return 1; } -int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *multirev, int *gapoffset) +int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *multirev, int *gapoffset, int *nextrev, bool sametrack) { int len; struct CapsTrackInfoT2 ci; + CapsRevolutionInfo pinfo; if (tracktiming) *tracktiming = 0; - if (!load (&ci, drv, track, true)) + + if (nextrev && pCAPSSetRevolution) { + if (sametrack) { + pCAPSSetRevolution(caps_cont[drv], *nextrev); + //write_log (_T("set rev = %d\n"), *nextrev); + } else { + pCAPSSetRevolution(caps_cont[drv], 0); + } + } + + if (!load (&ci, drv, track, true, sametrack != true)) return 0; + + if (nextrev && sametrack && pCAPSGetInfo) { + *nextrev = 0; + pCAPSGetInfo(&pinfo, caps_cont[drv], track / 2, track & 1, cgiitRevolution, 0); + //write_log (_T("get next rev = %d\n"), pinfo.next); + if (pinfo.max > 0) + *nextrev = pinfo.next; + } + *multirev = (ci.type & CTIT_FLAG_FLAKEY) ? 1 : 0; if (oldlib) { len = ci.tracklen * 8; @@ -258,10 +305,12 @@ int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, i fclose (f); } #endif +#if CAPS_TRACKTIMING if (ci.timelen > 0 && tracktiming) { for (int i = 0; i < ci.timelen; i++) tracktiming[i] = (uae_u16)ci.timebuf[i]; } +#endif #if 0 write_log (_T("caps: drive:%d track:%d len:%d multi:%d timing:%d type:%d overlap:%d\n"), drv, track, len, *multirev, ci.timelen, type, ci.overlap); diff --git a/od-win32/caps/caps_win32.h b/od-win32/caps/caps_win32.h index 7d534ebb..b8b7a9d0 100644 --- a/od-win32/caps/caps_win32.h +++ b/od-win32/caps/caps_win32.h @@ -1,6 +1,6 @@ int caps_init (void); void caps_unloadimage (int drv); int caps_loadimage (struct zfile *zf, int drv, int *num_tracks); -int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *multirev, int *gapoffset); -int caps_loadrevolution (uae_u16 *mfmbuf, int drv, int track, int *tracklength); +int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *multirev, int *gapoffset, int *nextrev, bool setrev); +int caps_loadrevolution (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, int *tracklength, int *nextrev); -- 2.47.3