diff --git a/cpctelera/tools/dskgen/include/Types.hpp b/cpctelera/tools/dskgen/include/Types.hpp index e6a2e33ec..657294152 100644 --- a/cpctelera/tools/dskgen/include/Types.hpp +++ b/cpctelera/tools/dskgen/include/Types.hpp @@ -12,7 +12,7 @@ using namespace std; #define AMSDOS_EMPTY_BYTE 0xE5 -typedef enum { HDR_NONE=0, HDR_AMSDOS=1 } HeaderType; +typedef enum { HDR_NONE=0, HDR_AMSDOS=1, HDR_CREATE_AMSDOS=2 } HeaderType; // RAW catalog: it stores in the first sector the following info for each file: // Side (1byte), @@ -147,4 +147,4 @@ struct AmsdosHeader { #pragma pack(pop) -#endif \ No newline at end of file +#endif diff --git a/cpctelera/tools/dskgen/src/Dsk.cc b/cpctelera/tools/dskgen/src/Dsk.cc index d054d7d21..5b8862444 100644 --- a/cpctelera/tools/dskgen/src/Dsk.cc +++ b/cpctelera/tools/dskgen/src/Dsk.cc @@ -60,8 +60,8 @@ void Dsk::advanceSectors(u8 sectors) { void Dsk::updateCurrentBlock(void) { this->_currentBlock = ( - (this->_currentTrack * this->_specs.sectorsPerTrack + (this->_currentSector - this->_specs.firstSectorNumber)) * - this->_specs.sectSizeInRecords * DSK_RECORD_SIZE) + (this->_currentTrack * this->_specs.sectorsPerTrack + (this->_currentSector - this->_specs.firstSectorNumber)) * + this->_specs.sectSizeInRecords * DSK_RECORD_SIZE) / this->_blockSize; } @@ -83,7 +83,7 @@ void Dsk::initDskHeader(void) { this->_dskHeader.Sides = this->_numSides; this->_dskHeader.Tracks = this->_numTracks; - + u16 trackSize = (((u16)this->_specs.sectorsPerTrack * this->_specs.sectSizeInRecords) / 2) + 1; this->_dskHeader.Unused = trackSize << 8; @@ -136,12 +136,12 @@ int Dsk::AddFile(FileToProcess &file) { f.read((char*)fileData, (streamsize)file.Length); f.close(); - if(file.Header == HDR_AMSDOS) { - if(!checkAmsdosHeader(fileData)) { + if((file.Header == HDR_AMSDOS)||(file.Header == HDR_CREATE_AMSDOS)) { + if((!checkAmsdosHeader(fileData))||(file.Header == HDR_CREATE_AMSDOS)) { u8 headerSize = sizeof(struct AmsdosHeader); u32 newLength = file.Length + headerSize; u8* newData = new u8[newLength]; - + memcpy(newData + headerSize, fileData, file.Length); u8* oldData = fileData; delete oldData; @@ -223,8 +223,8 @@ bool Dsk::checkAmsdosHeader(u8* buffer) { for (u8 i=0; i<67; ++i) { checksum += (*bufPtr); ++bufPtr; - } - return checkSumInHeader == checksum; + } + return ((checkSumInHeader == checksum)&&(checksum!=0)); } void Dsk::fillAmsdosHeader(struct AmsdosHeader* header, const FileToProcess& file) { @@ -244,7 +244,7 @@ void Dsk::fillAmsdosHeader(struct AmsdosHeader* header, const FileToProcess& fil checksum += *(ptr); ++ptr; } - + header->CheckSum = checksum; } @@ -288,7 +288,7 @@ void Dsk::Save(string &path) { DskTrack *track = &this->_dskTracks[t]; f.write((const char*)track, 24); int sIdx = 0; - + int s = 0; for (s = 0; s < this->_specs.sectorsPerTrack; ++s) { DskSector *sector = &track->Sectors[sIdx]; diff --git a/cpctelera/tools/dskgen/src/Types.cc b/cpctelera/tools/dskgen/src/Types.cc index 1fd52d944..50efd4d4e 100644 --- a/cpctelera/tools/dskgen/src/Types.cc +++ b/cpctelera/tools/dskgen/src/Types.cc @@ -7,7 +7,7 @@ CatalogType ParseCatalogType(const string &catStr) { if(tmpStr == "none") { result = CAT_NONE; } else if(tmpStr == "raw") { - result = CAT_RAW; + result = CAT_RAW; } else if(tmpStr == "cpm") { result = CAT_CPM; } else { @@ -47,9 +47,11 @@ HeaderType ParseHeaderType(const string &hdrStr) { result = HDR_NONE; } else if(tmpStr == "amsdos") { result = HDR_AMSDOS; + } else if(tmpStr == "createamsdos") { + result = HDR_CREATE_AMSDOS; } else { stringstream ss; - ss << "Header type not recognized: " << hdrStr << "\n.Valid values are: AMSDOS or NONE.\n"; + ss << "Header type not recognized: " << hdrStr << "\n.Valid values are: AMSDOS, CREATEAMSDOS or NONE.\n"; throw ss.str(); } return result; diff --git a/cpctelera/tools/dskgen/src/dskgen.cc b/cpctelera/tools/dskgen/src/dskgen.cc index 202d20315..c14c7c03b 100644 --- a/cpctelera/tools/dskgen/src/dskgen.cc +++ b/cpctelera/tools/dskgen/src/dskgen.cc @@ -11,7 +11,7 @@ int initializeParser(ezOptionParser &parser) { parser.add("NONE", false, 1, 0, "Catalog type. Valid values are: NONE, RAW or CPM.\n\nNONE: No catalog is added. This can be used if sectors will be read in raw mode, or if the first file to add contains CATART data.\n\nRAW: A catalog is created in RAW mode. This catalog is not understood by the OS, see the docs.\n\nCPM: Standard CPM catalog, understood by AMSDOS.", "-c", "--catalog", vCat); ezOptionValidator* vDskType = new ezOptionValidator("t", "in", "SYSTEM,DATA,IBM,CUSTOM", true); parser.add("SYSTEM", false, 1, 0, "Disk type. Valid values are SYSTEM, DATA, IBM and CUSTOM.", "-t", "--type", vDskType); - parser.add("", true, 1, ';', "Specifies the files to insert. File Specified as path,header,loadAddr,exeAddr. Header values can be NONE or AMSDOS. Default header value is NONE, default addresses are 0x0.", "-f", "--files"); + parser.add("", true, 1, ';', "Specifies the files to insert. File Specified as path,header,loadAddr,exeAddr. Header values can be NONE, AMSDOS or CREATEAMSDOS. Default header value is NONE, default addresses are 0x0.", "-f", "--files"); parser.add("2", false, 1, 0, "Specifies the sides of the disk. Default value is 2 sides.", "-s", "--sides"); parser.add("", false, 1, 0, "Specifies the file that contains boot code por |CPM booting. Only valid for SYSTEM or CUSTOM files.", "-b"); parser.add("80", false, 1, 0, "Specifies the number of tracks in the disk. Default value is 80.", "--tracks"); @@ -49,7 +49,7 @@ int extractOptions(ezOptionParser &switches, Options &options) { if(switches.isSet("--initialTrack")) { if(options.OutputDiskType != DSK_CUSTOM) { - cout << "WARNING: Custom initial track specification is only allowed for CUSTOM files. This setting will be ignored." << endl; + cout << "WARNING: Custom initial track specification is only allowed for CUSTOM files. This setting will be ignored." << endl; } else { int initialTrack; switches.get("--initialTrack")->getInt(initialTrack); @@ -76,10 +76,10 @@ int extractOptions(ezOptionParser &switches, Options &options) { int sectorsPerBlock = (blockSize / sectorSize); options.DiskParams.numBlocks = (u8) (((tracks - options.DiskParams.reservedTracks) * options.DiskParams.sectorsPerTrack) / sectorsPerBlock) - 1; } - } + } if(switches.isSet("--sectors")) { if(options.OutputDiskType != DSK_CUSTOM) { - cout << "WARNING: Custom sector number specification is only allowed for CUSTOM files. This setting will be ignored." << endl; + cout << "WARNING: Custom sector number specification is only allowed for CUSTOM files. This setting will be ignored." << endl; } else { int sectorsPerTrack; int blockSize = DSK_RECORD_SIZE * (1 << options.DiskParams.blockShift); @@ -94,7 +94,7 @@ int extractOptions(ezOptionParser &switches, Options &options) { } if(switches.isSet("--initialSector")) { if(options.OutputDiskType != DSK_CUSTOM) { - cout << "WARNING: Custom initial sector specification is only allowed for CUSTOM files. This setting will be ignored." << endl; + cout << "WARNING: Custom initial sector specification is only allowed for CUSTOM files. This setting will be ignored." << endl; } else { int initalSector; switches.get("--initialSector")->getInt(initalSector); @@ -150,11 +150,11 @@ int main(int argc, const char** argv) showUsage(switches); return -1; } - + Dsk disk(opt.NumSides, opt.DiskParams, opt.Catalog); if(!opt.BootFile.empty()) { if(disk.AddBootFile(opt.BootFile)) { - cout << "ERROR: Couldn't process file '" << opt.BootFile << "'." << endl; + cout << "ERROR: Couldn't process file '" << opt.BootFile << "'." << endl; } }