Extended .do & .po support for 140KB+n*4KB disk images

where n=[35..40]
This commit is contained in:
tomch 2009-02-17 22:53:52 +00:00
parent 44872bf99e
commit a73a1a9b2e
3 changed files with 65 additions and 41 deletions

View File

@ -1,10 +1,12 @@
#pragma once
#define DRIVE_1 0
#define DRIVE_2 1
#define DRIVE_1 0
#define DRIVE_2 1
#define DRIVES 2
#define TRACKS 35
#define DRIVES 2
#define TRACKS_STANDARD 35
#define TRACKS_EXTRA 5 // Allow up to a 40-track .dsk image (160KB)
#define TRACKS (TRACKS_STANDARD+TRACKS_EXTRA)
extern BOOL enhancedisk;
extern string DiskPathFilename[2];

View File

@ -155,7 +155,7 @@ LPBYTE Code62 (int sector) {
// STARTING AT 4K INTO THE WORK BUFFER.
{
LPBYTE sectorbase = workbuffer+(sector << 8);
LPBYTE resultptr = workbuffer+0x1000;
LPBYTE resultptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
BYTE offset = 0xAC;
while (offset != 0x02) {
BYTE value = 0;
@ -180,8 +180,8 @@ LPBYTE Code62 (int sector) {
// BLOCK OF 343 BYTES STARTING AT 5K INTO THE WORK BUFFER.
{
BYTE savedval = 0;
LPBYTE sourceptr = workbuffer+0x1000;
LPBYTE resultptr = workbuffer+0x1400;
LPBYTE sourceptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
LPBYTE resultptr = workbuffer+TRACK_DENIBBLIZED_SIZE+0x400;
int loop = 342;
while (loop--) {
*(resultptr++) = savedval ^ *sourceptr;
@ -196,14 +196,14 @@ LPBYTE Code62 (int sector) {
// ZERO BITS. THE CONVERTED BLOCK OF 343 BYTES IS STORED STARTING AT 4K
// INTO THE WORK BUFFER.
{
LPBYTE sourceptr = workbuffer+0x1400;
LPBYTE resultptr = workbuffer+0x1000;
LPBYTE sourceptr = workbuffer+TRACK_DENIBBLIZED_SIZE+0x400;
LPBYTE resultptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
int loop = 343;
while (loop--)
*(resultptr++) = diskbyte[(*(sourceptr++)) >> 2];
}
return workbuffer+0x1000;
return workbuffer+TRACK_DENIBBLIZED_SIZE;
}
//===========================================================================
@ -225,8 +225,8 @@ void Decode62 (LPBYTE imageptr) {
// USING OUR TABLE, CONVERT THE DISK BYTES BACK INTO 6-BIT BYTES
{
LPBYTE sourceptr = workbuffer+0x1000;
LPBYTE resultptr = workbuffer+0x1400;
LPBYTE sourceptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
LPBYTE resultptr = workbuffer+TRACK_DENIBBLIZED_SIZE+0x400;
int loop = 343;
while (loop--)
*(resultptr++) = sixbitbyte[*(sourceptr++) & 0x7F];
@ -236,8 +236,8 @@ void Decode62 (LPBYTE imageptr) {
// TO UNDO THE EFFECTS OF THE CHECKSUMMING PROCESS
{
BYTE savedval = 0;
LPBYTE sourceptr = workbuffer+0x1400;
LPBYTE resultptr = workbuffer+0x1000;
LPBYTE sourceptr = workbuffer+TRACK_DENIBBLIZED_SIZE+0x400;
LPBYTE resultptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
int loop = 342;
while (loop--) {
*resultptr = savedval ^ *(sourceptr++);
@ -247,8 +247,8 @@ void Decode62 (LPBYTE imageptr) {
// CONVERT THE 342 6-BIT BYTES INTO 256 8-BIT BYTES
{
LPBYTE lowbitsptr = workbuffer+0x1000;
LPBYTE sectorbase = workbuffer+0x1056;
LPBYTE lowbitsptr = workbuffer+TRACK_DENIBBLIZED_SIZE;
LPBYTE sectorbase = workbuffer+TRACK_DENIBBLIZED_SIZE+0x56;
BYTE offset = 0xAC;
while (offset != 0x02) {
if (offset >= 0xAC)
@ -272,7 +272,7 @@ void Decode62 (LPBYTE imageptr) {
//===========================================================================
void DenibblizeTrack (LPBYTE trackimage, BOOL dosorder, int nibbles) {
ZeroMemory(workbuffer,0x1000);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
// SEARCH THROUGH THE TRACK IMAGE FOR EACH SECTOR. FOR EVERY SECTOR
// WE FIND, COPY THE NIBBLIZED DATA FOR THAT SECTOR INTO THE WORK
@ -299,13 +299,13 @@ void DenibblizeTrack (LPBYTE trackimage, BOOL dosorder, int nibbles) {
int loop = 0;
int tempoffset = offset;
while (loop < 384) {
*(workbuffer+0x1000+loop++) = *(trackimage+tempoffset++);
*(workbuffer+TRACK_DENIBBLIZED_SIZE+loop++) = *(trackimage+tempoffset++);
if (tempoffset >= nibbles)
tempoffset = 0;
}
if (byteval[2] == 0x96)
sector = ((*(workbuffer+0x1004) & 0x55) << 1)
| (*(workbuffer+0x1005) & 0x55);
sector = ((*(workbuffer+TRACK_DENIBBLIZED_SIZE+4) & 0x55) << 1)
| (*(workbuffer+TRACK_DENIBBLIZED_SIZE+5) & 0x55);
else if (byteval[2] == 0xAD) {
Decode62(workbuffer+(sectornumber[dosorder][sector] << 8));
sector = 0;
@ -317,7 +317,7 @@ void DenibblizeTrack (LPBYTE trackimage, BOOL dosorder, int nibbles) {
//===========================================================================
DWORD NibblizeTrack (LPBYTE trackimagebuffer, BOOL dosorder, int track) {
ZeroMemory(workbuffer+4096,4096);
ZeroMemory(workbuffer+TRACK_DENIBBLIZED_SIZE,TRACK_DENIBBLIZED_SIZE);
LPBYTE imageptr = trackimagebuffer;
BYTE sector = 0;
@ -422,6 +422,28 @@ DWORD AplDetect (LPBYTE imageptr, DWORD imagesize) {
((length+4+((256-((length+4) & 255)) & 255)) == imagesize));
}
//===========================================================================
static bool IsValidImageSize(DWORD uImageSize)
{
if ((TRACKS>TRACKS_STANDARD) && (uImageSize > TRACKS*TRACK_DENIBBLIZED_SIZE))
return false; // >160KB
if (uImageSize >= TRACKS_STANDARD*TRACK_DENIBBLIZED_SIZE)
{
// Is uImageSize == 140KB + n*4K?
const bool bStandardSize = (((uImageSize - TRACKS_STANDARD*TRACK_DENIBBLIZED_SIZE) % TRACK_DENIBBLIZED_SIZE) == 0);
if (bStandardSize)
return true;
}
const bool bInvalidSize = ( ((uImageSize < 143105) || (uImageSize > 143364)) &&
(uImageSize != 143403) &&
(uImageSize != 143488) );
return !bInvalidSize;
}
/****************************************************************************
*
* DOS ORDER (DO) FORMAT IMPLEMENTATION
@ -429,10 +451,10 @@ DWORD AplDetect (LPBYTE imageptr, DWORD imagesize) {
***/
//===========================================================================
DWORD DoDetect (LPBYTE imageptr, DWORD imagesize) {
if (((imagesize < 143105) || (imagesize > 143364)) &&
(imagesize != 143403) && (imagesize != 143488))
return 0;
DWORD DoDetect (LPBYTE imageptr, DWORD imagesize)
{
if (!IsValidImageSize(imagesize))
return 0;
// CHECK FOR A DOS ORDER IMAGE OF A DOS DISKETTE
{
@ -463,9 +485,9 @@ DWORD DoDetect (LPBYTE imageptr, DWORD imagesize) {
//===========================================================================
void DoRead (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimagebuffer, int *nibbles) {
SetFilePointer(ptr->file,ptr->offset+(track << 12),NULL,FILE_BEGIN);
ZeroMemory(workbuffer,4096);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
DWORD bytesread;
ReadFile(ptr->file,workbuffer,4096,&bytesread,NULL);
ReadFile(ptr->file,workbuffer,TRACK_DENIBBLIZED_SIZE,&bytesread,NULL);
*nibbles = NibblizeTrack(trackimagebuffer,1,track);
if (!enhancedisk)
SkewTrack(track,*nibbles,trackimagebuffer);
@ -473,11 +495,11 @@ void DoRead (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimagebuf
//===========================================================================
void DoWrite (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimage, int nibbles) {
ZeroMemory(workbuffer,4096);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
DenibblizeTrack(trackimage,1,nibbles);
SetFilePointer(ptr->file,ptr->offset+(track << 12),NULL,FILE_BEGIN);
DWORD byteswritten;
WriteFile(ptr->file,workbuffer,4096,&byteswritten,NULL);
WriteFile(ptr->file,workbuffer,TRACK_DENIBBLIZED_SIZE,&byteswritten,NULL);
}
/****************************************************************************
@ -529,9 +551,9 @@ void IieRead (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimagebu
if (*(ptr->header+13) <= 2) {
IieConvertSectorOrder(ptr->header+14);
SetFilePointer(ptr->file,(track << 12)+30,NULL,FILE_BEGIN);
ZeroMemory(workbuffer,4096);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
DWORD bytesread;
ReadFile(ptr->file,workbuffer,4096,&bytesread,NULL);
ReadFile(ptr->file,workbuffer,TRACK_DENIBBLIZED_SIZE,&bytesread,NULL);
*nibbles = NibblizeTrack(trackimagebuffer,2,track);
}
@ -610,10 +632,10 @@ void Nib2Write (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimage
***/
//===========================================================================
DWORD PoDetect (LPBYTE imageptr, DWORD imagesize) {
if (((imagesize < 143105) || (imagesize > 143364)) &&
(imagesize != 143488))
return 0;
DWORD PoDetect (LPBYTE imageptr, DWORD imagesize)
{
if (!IsValidImageSize(imagesize))
return 0;
// CHECK FOR A PRODOS ORDER IMAGE OF A DOS DISKETTE
{
@ -644,9 +666,9 @@ DWORD PoDetect (LPBYTE imageptr, DWORD imagesize) {
//===========================================================================
void PoRead (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimagebuffer, int *nibbles) {
SetFilePointer(ptr->file,ptr->offset+(track << 12),NULL,FILE_BEGIN);
ZeroMemory(workbuffer,4096);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
DWORD bytesread;
ReadFile(ptr->file,workbuffer,4096,&bytesread,NULL);
ReadFile(ptr->file,workbuffer,TRACK_DENIBBLIZED_SIZE,&bytesread,NULL);
*nibbles = NibblizeTrack(trackimagebuffer,0,track);
if (!enhancedisk)
SkewTrack(track,*nibbles,trackimagebuffer);
@ -654,11 +676,11 @@ void PoRead (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimagebuf
//===========================================================================
void PoWrite (imageinfoptr ptr, int track, int quartertrack, LPBYTE trackimage, int nibbles) {
ZeroMemory(workbuffer,4096);
ZeroMemory(workbuffer,TRACK_DENIBBLIZED_SIZE);
DenibblizeTrack(trackimage,0,nibbles);
SetFilePointer(ptr->file,ptr->offset+(track << 12),NULL,FILE_BEGIN);
DWORD byteswritten;
WriteFile(ptr->file,workbuffer,4096,&byteswritten,NULL);
WriteFile(ptr->file,workbuffer,TRACK_DENIBBLIZED_SIZE,&byteswritten,NULL);
}
/****************************************************************************
@ -732,7 +754,7 @@ void ImageDestroy () {
//===========================================================================
void ImageInitialize () {
workbuffer = (LPBYTE)VirtualAlloc(NULL,0x2000,MEM_COMMIT,PAGE_READWRITE);
workbuffer = (LPBYTE)VirtualAlloc(NULL, TRACK_DENIBBLIZED_SIZE*2, MEM_COMMIT, PAGE_READWRITE);
}
//===========================================================================

View File

@ -1,8 +1,8 @@
#pragma once
#define TRACKS 35
#define IMAGETYPES 7
#define NIBBLES 6656
#define TRACK_DENIBBLIZED_SIZE 4096
BOOL ImageBoot (HIMAGE);
void ImageClose (HIMAGE);