mirror of
https://github.com/sheumann/NetDisk.git
synced 2025-01-02 17:30:38 +00:00
Support DOS-order sector data in images.
Currently, this is only enabled for 2mg images where the header specifies DOS order.
This commit is contained in:
parent
797b8d247f
commit
d2f7ec3b64
65
driver.c
65
driver.c
@ -18,6 +18,13 @@
|
|||||||
|
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
|
|
||||||
|
/* Disk II-style track/sector layout (relevant to DOS-order images) */
|
||||||
|
#define TRACK_SIZE (BLOCK_SIZE * 8)
|
||||||
|
#define SECTOR_SIZE 256
|
||||||
|
/* The sectors making up each block within a track (using DOS 3.3 numbering) */
|
||||||
|
static const int sectorMap[2][8] = {{ 0, 13, 11, 9, 7, 5, 3, 1},
|
||||||
|
{14, 12, 10, 8, 6, 4, 2, 15}};
|
||||||
|
|
||||||
struct DIB dibs[NDIBS] = {0};
|
struct DIB dibs[NDIBS] = {0};
|
||||||
struct DIBList dibList = {NDIBS};
|
struct DIBList dibList = {NDIBS};
|
||||||
|
|
||||||
@ -212,11 +219,17 @@ static enum NetDiskError CheckTwoImg(Session *sess) {
|
|||||||
/* It's a 2IMG file, but is it one we can handle? */
|
/* It's a 2IMG file, but is it one we can handle? */
|
||||||
if (hdr->version > 1)
|
if (hdr->version > 1)
|
||||||
return UNSUPPORTED_2IMG_FILE;
|
return UNSUPPORTED_2IMG_FILE;
|
||||||
if (hdr->imgFormat != IMAGE_FORMAT_PRODOS_ORDER)
|
|
||||||
return UNSUPPORTED_2IMG_FILE;
|
|
||||||
if (hdr->dataLength % BLOCK_SIZE != 0)
|
if (hdr->dataLength % BLOCK_SIZE != 0)
|
||||||
return UNSUPPORTED_2IMG_FILE;
|
return UNSUPPORTED_2IMG_FILE;
|
||||||
|
|
||||||
|
if (hdr->imgFormat == IMAGE_FORMAT_DOS_33_ORDER) {
|
||||||
|
if (hdr->dataLength % TRACK_SIZE != 0)
|
||||||
|
return UNSUPPORTED_2IMG_FILE;
|
||||||
|
sess->dosOrder = TRUE;
|
||||||
|
} else if (hdr->imgFormat != IMAGE_FORMAT_PRODOS_ORDER) {
|
||||||
|
return UNSUPPORTED_2IMG_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
sess->dataOffset = hdr->dataOffset;
|
sess->dataOffset = hdr->dataOffset;
|
||||||
sess->dataLength = hdr->dataLength;
|
sess->dataLength = hdr->dataLength;
|
||||||
|
|
||||||
@ -363,7 +376,11 @@ skipCache:
|
|||||||
dp->blockNum = firstBlockNum;
|
dp->blockNum = firstBlockNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd);
|
enum NetDiskError err;
|
||||||
|
ReadStatus readStatus;
|
||||||
|
|
||||||
|
if (!sess->dosOrder) {
|
||||||
|
err = DoHTTPRequest(sess, readStart, readEnd);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
if (err == DIFFERENT_LENGTH) {
|
if (err == DIFFERENT_LENGTH) {
|
||||||
@ -380,7 +397,6 @@ skipCache:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadStatus readStatus;
|
|
||||||
InitReadTCP(sess, dp->requestCount, dp->bufferPtr);
|
InitReadTCP(sess, dp->requestCount, dp->bufferPtr);
|
||||||
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
|
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
|
||||||
/* keep reading */ ;
|
/* keep reading */ ;
|
||||||
@ -390,6 +406,47 @@ skipCache:
|
|||||||
if (readStatus != rsDone) {
|
if (readStatus != rsDone) {
|
||||||
return drvrIOError;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (dp->blockSize != BLOCK_SIZE) {
|
||||||
|
dp->transferCount = 0;
|
||||||
|
return drvrBadBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
firstBlockNum = dp->blockNum;
|
||||||
|
endBlockNum = firstBlockNum + dp->requestCount / BLOCK_SIZE;
|
||||||
|
|
||||||
|
int half = 0;
|
||||||
|
dp->transferCount = 0;
|
||||||
|
while (dp->blockNum < endBlockNum) {
|
||||||
|
readStart = (dp->blockNum >> 3) * TRACK_SIZE
|
||||||
|
+ sectorMap[half][dp->blockNum & 0x7] * SECTOR_SIZE
|
||||||
|
+ sess->dataOffset;
|
||||||
|
readEnd = readStart + (SECTOR_SIZE - 1);
|
||||||
|
|
||||||
|
err = DoHTTPRequest(sess, readStart, readEnd);
|
||||||
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
|
dp->blockNum = firstBlockNum;
|
||||||
|
return drvrIOError;
|
||||||
|
}
|
||||||
|
|
||||||
|
InitReadTCP(sess, SECTOR_SIZE, dp->bufferPtr + dp->transferCount);
|
||||||
|
while ((readStatus = TryReadTCP(sess)) == rsWaiting)
|
||||||
|
/* keep reading */ ;
|
||||||
|
|
||||||
|
if (readStatus != rsDone || sess->readCount != 0) {
|
||||||
|
dp->blockNum = firstBlockNum;
|
||||||
|
return drvrIOError;
|
||||||
|
}
|
||||||
|
|
||||||
|
dp->transferCount += SECTOR_SIZE;
|
||||||
|
|
||||||
|
half ^= 1;
|
||||||
|
if (half == 0)
|
||||||
|
dp->blockNum++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dp->blockNum = firstBlockNum;
|
||||||
|
}
|
||||||
|
|
||||||
if (useCache && sess->readCount == 0) {
|
if (useCache && sess->readCount == 0) {
|
||||||
bufferPtr = dp->bufferPtr;
|
bufferPtr = dp->bufferPtr;
|
||||||
|
2
driver.h
2
driver.h
@ -34,7 +34,7 @@ struct DIBList {
|
|||||||
struct GSOSDP {
|
struct GSOSDP {
|
||||||
Word deviceNum;
|
Word deviceNum;
|
||||||
Word callNum;
|
Word callNum;
|
||||||
void *bufferPtr;
|
Byte *bufferPtr;
|
||||||
LongWord requestCount;
|
LongWord requestCount;
|
||||||
LongWord transferCount;
|
LongWord transferCount;
|
||||||
LongWord blockNum;
|
LongWord blockNum;
|
||||||
|
@ -55,6 +55,9 @@ typedef struct Session {
|
|||||||
/* Length of disk image data */
|
/* Length of disk image data */
|
||||||
LongWord dataLength;
|
LongWord dataLength;
|
||||||
|
|
||||||
|
/* Is the image in DOS order? */
|
||||||
|
Boolean dosOrder;
|
||||||
|
|
||||||
/* Should the GS/OS block cache be used? */
|
/* Should the GS/OS block cache be used? */
|
||||||
Boolean useCache;
|
Boolean useCache;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user