mirror of
https://github.com/JorjBauer/aiie.git
synced 2024-12-28 05:29:51 +00:00
single track cache mode
This commit is contained in:
parent
3a1d0219dc
commit
db9978f95a
@ -14,6 +14,7 @@ extern uint32_t FreeRamEstimate();
|
|||||||
|
|
||||||
#ifdef TEENSYDUINO
|
#ifdef TEENSYDUINO
|
||||||
#define SKIPCHECKSUM
|
#define SKIPCHECKSUM
|
||||||
|
#define STATICALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PREP_SECTION(fd, t) { \
|
#define PREP_SECTION(fd, t) { \
|
||||||
@ -51,6 +52,9 @@ Woz::Woz(bool verbose, uint8_t dumpflags)
|
|||||||
memset(&di, 0, sizeof(diskInfo));
|
memset(&di, 0, sizeof(diskInfo));
|
||||||
memset(&tracks, 0, sizeof(tracks));
|
memset(&tracks, 0, sizeof(tracks));
|
||||||
randPtr = 0;
|
randPtr = 0;
|
||||||
|
#ifdef TEENSYDUINO
|
||||||
|
this->verbose = 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Woz::~Woz()
|
Woz::~Woz()
|
||||||
@ -59,13 +63,19 @@ Woz::~Woz()
|
|||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
for (int i=0; i<160; i++) {
|
||||||
|
tracks[i].trackData = NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
for (int i=0; i<160; i++) {
|
for (int i=0; i<160; i++) {
|
||||||
if (tracks[i].trackData) {
|
if (tracks[i].trackData) {
|
||||||
free(tracks[i].trackData);
|
free(tracks[i].trackData);
|
||||||
tracks[i].trackData = NULL;
|
tracks[i].trackData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (metaData) {
|
if (metaData) {
|
||||||
free(metaData);
|
free(metaData);
|
||||||
metaData = NULL;
|
metaData = NULL;
|
||||||
@ -651,15 +661,19 @@ bool Woz::loadMissingTrackFromImage(uint8_t datatrack)
|
|||||||
// autoFlushTrackData==true (trying to limit memory use)
|
// autoFlushTrackData==true (trying to limit memory use)
|
||||||
if (autoFlushTrackData == true) {
|
if (autoFlushTrackData == true) {
|
||||||
flush();
|
flush();
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
for (int i=0; i<160; i++) {
|
||||||
|
tracks[i].trackData = NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
for (int i=0; i<160; i++) {
|
for (int i=0; i<160; i++) {
|
||||||
if (tracks[i].trackData) {
|
if (tracks[i].trackData) {
|
||||||
free(tracks[i].trackData);
|
free(tracks[i].trackData);
|
||||||
tracks[i].trackData = NULL;
|
tracks[i].trackData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Based on the source image type, load the data track we're looking for
|
// Based on the source image type, load the data track we're looking for
|
||||||
if (imageType == T_WOZ) {
|
if (imageType == T_WOZ) {
|
||||||
// If the source was WOZ, just load the datatrack directly
|
// If the source was WOZ, just load the datatrack directly
|
||||||
@ -685,11 +699,16 @@ bool Woz::loadMissingTrackFromImage(uint8_t datatrack)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
tracks[datatrack].trackData = singleCachedTrack;
|
||||||
|
memset(singleCachedTrack, 0, sizeof(singleCachedTrack));
|
||||||
|
#else
|
||||||
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
||||||
if (!tracks[datatrack].trackData) {
|
if (!tracks[datatrack].trackData) {
|
||||||
fprintf(stderr, "Failed to malloc track data\n");
|
fprintf(stderr, "Failed to malloc track data\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
tracks[datatrack].startingBlock = STARTBLOCK + 13*phystrack;
|
tracks[datatrack].startingBlock = STARTBLOCK + 13*phystrack;
|
||||||
tracks[datatrack].blockCount = 13;
|
tracks[datatrack].blockCount = 13;
|
||||||
uint32_t sizeInBits = nibblizeTrack(tracks[datatrack].trackData, sectorData, imageType, phystrack);
|
uint32_t sizeInBits = nibblizeTrack(tracks[datatrack].trackData, sectorData, imageType, phystrack);
|
||||||
@ -706,11 +725,15 @@ bool Woz::loadMissingTrackFromImage(uint8_t datatrack)
|
|||||||
// If the source was a NIB file, then the datatrack is directly
|
// If the source was a NIB file, then the datatrack is directly
|
||||||
// mapped 1:1 to the physical track
|
// mapped 1:1 to the physical track
|
||||||
uint8_t phystrack = datatrack; // used for clarity of which kind of track we mean, below
|
uint8_t phystrack = datatrack; // used for clarity of which kind of track we mean, below
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
tracks[datatrack].trackData = singleCachedTrack;
|
||||||
|
memset(singleCachedTrack, 0, sizeof(singleCachedTrack));
|
||||||
|
#else
|
||||||
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
||||||
if (!tracks[datatrack].trackData) {
|
if (!tracks[datatrack].trackData) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
lseek(fd, NIBTRACKSIZE * phystrack, SEEK_SET);
|
lseek(fd, NIBTRACKSIZE * phystrack, SEEK_SET);
|
||||||
read(fd, tracks[datatrack].trackData, NIBTRACKSIZE);
|
read(fd, tracks[datatrack].trackData, NIBTRACKSIZE);
|
||||||
// FIXME: no error checking
|
// FIXME: no error checking
|
||||||
@ -728,6 +751,10 @@ bool Woz::loadMissingTrackFromImage(uint8_t datatrack)
|
|||||||
|
|
||||||
bool Woz::readDskFile(const char *filename, bool preloadTracks, uint8_t subtype)
|
bool Woz::readDskFile(const char *filename, bool preloadTracks, uint8_t subtype)
|
||||||
{
|
{
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
preloadTracks = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
autoFlushTrackData = !preloadTracks;
|
autoFlushTrackData = !preloadTracks;
|
||||||
imageType = subtype;
|
imageType = subtype;
|
||||||
@ -751,11 +778,16 @@ bool Woz::readDskFile(const char *filename, bool preloadTracks, uint8_t subtype)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
uint8_t datatrack = quarterTrackMap[phystrack*4];
|
uint8_t datatrack = quarterTrackMap[phystrack*4];
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
tracks[datatrack].trackData = singleCachedTrack;
|
||||||
|
memset(singleCachedTrack, 0, sizeof(singleCachedTrack));
|
||||||
|
#else
|
||||||
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
||||||
if (!tracks[datatrack].trackData) {
|
if (!tracks[datatrack].trackData) {
|
||||||
fprintf(stderr, "Failed to malloc track data\n");
|
fprintf(stderr, "Failed to malloc track data\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
tracks[datatrack].startingBlock = STARTBLOCK + 13*datatrack;
|
tracks[datatrack].startingBlock = STARTBLOCK + 13*datatrack;
|
||||||
tracks[datatrack].blockCount = 13;
|
tracks[datatrack].blockCount = 13;
|
||||||
uint32_t sizeInBits = nibblizeTrack(tracks[datatrack].trackData, sectorData, subtype, phystrack);
|
uint32_t sizeInBits = nibblizeTrack(tracks[datatrack].trackData, sectorData, subtype, phystrack);
|
||||||
@ -771,6 +803,9 @@ bool Woz::readDskFile(const char *filename, bool preloadTracks, uint8_t subtype)
|
|||||||
|
|
||||||
bool Woz::readNibFile(const char *filename, bool preloadTracks)
|
bool Woz::readNibFile(const char *filename, bool preloadTracks)
|
||||||
{
|
{
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
preloadTracks = false;
|
||||||
|
#endif
|
||||||
autoFlushTrackData = !preloadTracks;
|
autoFlushTrackData = !preloadTracks;
|
||||||
imageType = T_NIB;
|
imageType = T_NIB;
|
||||||
|
|
||||||
@ -793,12 +828,16 @@ bool Woz::readNibFile(const char *filename, bool preloadTracks)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t datatrack = quarterTrackMap[phystrack * 4];
|
uint8_t datatrack = quarterTrackMap[phystrack * 4];
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
tracks[datatrack].trackData = singleCachedTrack;
|
||||||
|
memset(singleCachedTrack, 0, sizeof(singleCachedTrack));
|
||||||
|
#else
|
||||||
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
tracks[datatrack].trackData = (uint8_t *)calloc(NIBTRACKSIZE, 1);
|
||||||
if (!tracks[datatrack].trackData) {
|
if (!tracks[datatrack].trackData) {
|
||||||
fprintf(stderr, "Failed to malloc track data\n");
|
fprintf(stderr, "Failed to malloc track data\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
memcpy(tracks[datatrack].trackData, nibData, NIBTRACKSIZE);
|
memcpy(tracks[datatrack].trackData, nibData, NIBTRACKSIZE);
|
||||||
tracks[datatrack].startingBlock = STARTBLOCK + 13*phystrack;
|
tracks[datatrack].startingBlock = STARTBLOCK + 13*phystrack;
|
||||||
tracks[datatrack].blockCount = 13;
|
tracks[datatrack].blockCount = 13;
|
||||||
@ -815,6 +854,9 @@ bool Woz::readNibFile(const char *filename, bool preloadTracks)
|
|||||||
|
|
||||||
bool Woz::readWozFile(const char *filename, bool preloadTracks)
|
bool Woz::readWozFile(const char *filename, bool preloadTracks)
|
||||||
{
|
{
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
preloadTracks = false;
|
||||||
|
#endif
|
||||||
imageType = T_WOZ;
|
imageType = T_WOZ;
|
||||||
autoFlushTrackData = !preloadTracks;
|
autoFlushTrackData = !preloadTracks;
|
||||||
|
|
||||||
@ -967,6 +1009,9 @@ bool Woz::readWozFile(const char *filename, bool preloadTracks)
|
|||||||
|
|
||||||
bool Woz::readFile(const char *filename, bool preloadTracks, uint8_t forceType)
|
bool Woz::readFile(const char *filename, bool preloadTracks, uint8_t forceType)
|
||||||
{
|
{
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
preloadTracks = false;
|
||||||
|
#endif
|
||||||
if (forceType == T_AUTO) {
|
if (forceType == T_AUTO) {
|
||||||
// Try to determine type from the file extension
|
// Try to determine type from the file extension
|
||||||
const char *p = strrchr(filename, '.');
|
const char *p = strrchr(filename, '.');
|
||||||
@ -1056,7 +1101,7 @@ bool Woz::parseTMAPChunk(uint32_t chunkSize)
|
|||||||
return false;
|
return false;
|
||||||
chunkSize--;
|
chunkSize--;
|
||||||
}
|
}
|
||||||
if (verbose){
|
if (verbose && 0){
|
||||||
printf("Read quarter-track map:\n");
|
printf("Read quarter-track map:\n");
|
||||||
for (int i=0; i<140; i+=4) {
|
for (int i=0; i<140; i+=4) {
|
||||||
printf("%2d %3d => %3d %3d => %3d %3d => %3d %3d => %3d\n",
|
printf("%2d %3d => %3d %3d => %3d %3d => %3d %3d => %3d\n",
|
||||||
@ -1169,16 +1214,23 @@ bool Woz::readWozDataTrack(uint8_t datatrack)
|
|||||||
if (tracks[datatrack].trackData) {
|
if (tracks[datatrack].trackData) {
|
||||||
return true; // We've already read this track's data; don't re-read it
|
return true; // We've already read this track's data; don't re-read it
|
||||||
}
|
}
|
||||||
|
#ifdef STATICALLOC
|
||||||
|
tracks[datatrack].trackData = singleCachedTrack;
|
||||||
|
memset(singleCachedTrack, 0, sizeof(singleCachedTrack));
|
||||||
|
if (count > sizeof(singleCachedTrack)) {
|
||||||
|
fprintf(stderr, "Want to alloc buffer than size of singleCachedTrack! About to overrun memory");
|
||||||
|
}
|
||||||
|
#else
|
||||||
tracks[datatrack].trackData = (uint8_t *)calloc(count, 1);
|
tracks[datatrack].trackData = (uint8_t *)calloc(count, 1);
|
||||||
if (!tracks[datatrack].trackData) {
|
if (!tracks[datatrack].trackData) {
|
||||||
perror("Failed to alloc buf to read track magnetic data");
|
perror("Failed to alloc buf to read track magnetic data");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (di.version == 1) {
|
if (di.version == 1) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
printf("Reading datatrack %d starting at byte 0x%X\n",
|
printf("Reading datatrack[1] %d starting at byte 0x%X\n",
|
||||||
datatrack,
|
datatrack,
|
||||||
tracks[datatrack].startingByte);
|
tracks[datatrack].startingByte);
|
||||||
}
|
}
|
||||||
@ -1188,7 +1240,7 @@ bool Woz::readWozDataTrack(uint8_t datatrack)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
printf("Reading datatrack %d starting at byte 0x%X\n",
|
printf("Reading datatrack[2] %d starting at byte 0x%X\n",
|
||||||
datatrack,
|
datatrack,
|
||||||
bitsStartBlock*512);
|
bitsStartBlock*512);
|
||||||
}
|
}
|
||||||
@ -1198,6 +1250,7 @@ bool Woz::readWozDataTrack(uint8_t datatrack)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t didRead = read(fd, tracks[datatrack].trackData, count);
|
uint32_t didRead = read(fd, tracks[datatrack].trackData, count);
|
||||||
|
|
||||||
if (didRead != count) {
|
if (didRead != count) {
|
||||||
printf("Failed to read all track data for track [read %d, wanted %d]\n", didRead, count);
|
printf("Failed to read all track data for track [read %d, wanted %d]\n", didRead, count);
|
||||||
return false;
|
return false;
|
||||||
|
@ -123,6 +123,7 @@ class Woz {
|
|||||||
uint8_t quarterTrackMap[40*4];
|
uint8_t quarterTrackMap[40*4];
|
||||||
diskInfo di;
|
diskInfo di;
|
||||||
trackInfo tracks[160];
|
trackInfo tracks[160];
|
||||||
|
uint8_t singleCachedTrack[0x1A00];
|
||||||
|
|
||||||
// cursor for track enumeration
|
// cursor for track enumeration
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user