diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 7553edd..11f40a0 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -1177,9 +1177,17 @@ bool Compiler::BuildLZO(const char* targetPath) bool Compiler::WriteOutputFile(const char* targetPath, DiskImage * d64) { char prgPath[200], mapPath[200], asmPath[200], lblPath[200], intPath[200], bcsPath[200], dbjPath[200]; + char basePath[200]; + + strcpy_s(basePath, targetPath); + int i = strlen(basePath); + while (i > 0 && basePath[i - 1] != '/' && basePath[i - 1] != '\\' && basePath[i - 1] != ':') + i--; + if (i > 0) + basePath[i] = 0; strcpy_s(prgPath, targetPath); - int i = strlen(prgPath); + i = strlen(prgPath); while (i > 0 && prgPath[i - 1] != '.') i--; if (i > 0) @@ -1213,7 +1221,7 @@ bool Compiler::WriteOutputFile(const char* targetPath, DiskImage * d64) strcat_s(prgPath, "prg"); if (mCompilerOptions & COPT_VERBOSE) printf("Writing <%s>\n", prgPath); - mLinker->WritePrgFile(prgPath); + mLinker->WritePrgFile(prgPath, basePath); } } else if (mCompilerOptions & COPT_TARGET_CRT) diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index fdc12d3..70bc040 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -1174,7 +1174,7 @@ bool Linker::WriteXexFile(const char* filename) return false; } -bool Linker::WritePrgFile(const char* filename) +bool Linker::WritePrgFile(const char* filename, const char* pathname) { FILE* file; fopen_s(&file, filename, "wb"); @@ -1185,10 +1185,36 @@ bool Linker::WritePrgFile(const char* filename) int done = fwrite(mMemory + mProgramStart - 2, 1, mProgramEnd - mProgramStart + 2, file); fclose(file); - return done == mProgramEnd - mProgramStart + 2; + if (done == mProgramEnd - mProgramStart + 2) + { + for (int i = 0; i < mOverlays.Size(); i++) + { + char ofname[200]; + strcpy_s(ofname, pathname); + strcat_s(ofname, mOverlays[i]->mIdent->mString); + strcat_s(ofname, ".prg"); + + fopen_s(&file, ofname, "wb"); + if (file) + { + int b = mOverlays[i]->mBank; + int s = mCartridgeBankStart[b]; + + mCartridge[b][s - 2] = s & 0xff; + mCartridge[b][s - 1] = s >> 8; + + fwrite(mCartridge[b] + s - 22, 1, mCartridgeBankEnd[b] - s + 2, file); + fclose(file); + } + else + return false; + } + + return true; + } } - else - return false; + + return false; } static int memlzcomp(uint8 * dp, const uint8 * sp, int size) diff --git a/oscar64/Linker.h b/oscar64/Linker.h index 6d009fd..e150481 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -266,7 +266,7 @@ public: // void AddReference(const LinkerReference& ref); bool WritePrgFile(DiskImage * image, const char* filename); - bool WritePrgFile(const char* filename); + bool WritePrgFile(const char* filename, const char * pathname); bool WriteXexFile(const char* filename); bool WriteMapFile(const char* filename); bool WriteAsmFile(const char* filename, const char * version);