Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dskgen: Added option to force creation of a new Amsdos header #154

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpctelera/tools/dskgen/include/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -147,4 +147,4 @@ struct AmsdosHeader {

#pragma pack(pop)

#endif
#endif
20 changes: 10 additions & 10 deletions cpctelera/tools/dskgen/src/Dsk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -244,7 +244,7 @@ void Dsk::fillAmsdosHeader(struct AmsdosHeader* header, const FileToProcess& fil
checksum += *(ptr);
++ptr;
}

header->CheckSum = checksum;
}

Expand Down Expand Up @@ -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];
Expand Down
6 changes: 4 additions & 2 deletions cpctelera/tools/dskgen/src/Types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions cpctelera/tools/dskgen/src/dskgen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down