From 974688a8a53a7468c3685441d85de61242624a58 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:11:10 +0100 Subject: [PATCH] Fix overlay prg file save --- include/conio.c | 30 ++++++++----------------- include/conio.h | 18 +++++++-------- oscar64/Compiler.cpp | 1 + oscar64/Linker.cpp | 39 ++++++++++++++++++++++++++++++++- oscar64/Linker.h | 1 + oscar64/NativeCodeGenerator.cpp | 2 +- 6 files changed, 59 insertions(+), 32 deletions(-) diff --git a/include/conio.c b/include/conio.c index 30d9273..f698ac4 100644 --- a/include/conio.c +++ b/include/conio.c @@ -221,18 +221,16 @@ __asm getpch } -int kbhit(void) +char kbhit(void) { __asm { lda $c6 sta accu - lda #0 - sta accu + 1 } } -int getche(void) +char getche(void) { __asm { @@ -243,13 +241,11 @@ int getche(void) sta accu jsr putpch - lda #0 - sta accu + 1 } } -int getch(void) +char getch(void) { __asm { @@ -259,23 +255,19 @@ int getch(void) beq L1 sta accu - lda #0 - sta accu + 1 } } -int getchx(void) +char getchx(void) { __asm { jsr getpch sta accu - lda #0 - sta accu + 1 } } -void putch(int c) +void putch(char c) { __asm { lda c @@ -296,7 +288,7 @@ void textcursor(bool show) *(char *)0xcc = show ? 0 : 1; } -void gotoxy(int cx, int cy) +void gotoxy(char cx, char cy) { __asm { @@ -307,7 +299,7 @@ void gotoxy(int cx, int cy) } } -void textcolor(int c) +void textcolor(char c) { __asm { @@ -316,24 +308,20 @@ void textcolor(int c) } } -int wherex(void) +char wherex(void) { __asm { lda $d3 sta accu - lda #0 - sta accu + 1 } } -int wherey(void) +char wherey(void) { __asm { lda $d6 sta accu - lda #0 - sta accu + 1 } } diff --git a/include/conio.h b/include/conio.h index 59fc634..58e485b 100644 --- a/include/conio.h +++ b/include/conio.h @@ -43,27 +43,27 @@ void dispmode80col(void); #define PETSCII_F7 0x88 #define PETSCII_F8 0x8c -int kbhit(void); +char kbhit(void); -int getche(void); +char getche(void); -int getch(void); +char getch(void); // like getch but does not wait, returns zero if no // key is pressed -int getchx(void); +char getchx(void); -void putch(int c); +void putch(char c); void clrscr(void); -void gotoxy(int x, int y); +void gotoxy(char x, char y); -void textcolor(int c); +void textcolor(char c); -int wherex(void); +char wherex(void); -int wherey(void); +char wherey(void); // show or hide the text cursor diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 11f40a0..d41c88a 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -1097,6 +1097,7 @@ bool Compiler::GenerateCode(void) if (mCompilerOptions & COPT_OPTIMIZE_BASIC) { mLinker->CombineSameConst(); + mLinker->InlineSimpleJumps(); mLinker->CheckDirectJumps(); } diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index 70bc040..3163bc7 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -390,6 +390,43 @@ bool Linker::Forwards(LinkerObject* pobj, LinkerObject* lobj) return false; } +void Linker::InlineSimpleJumps(void) +{ + for (int i = 0; i < mObjects.Size(); i++) + { + LinkerObject* cobj(mObjects[i]); + if (cobj->mType == LOT_NATIVE_CODE) + { + for (int j = 0; j < cobj->mReferences.Size(); j++) + { + LinkerReference* cref = cobj->mReferences[j]; + if (cref->mOffset > 0 && cref->mOffset < cobj->mSize + 2 && (cref->mFlags & (LREF_HIGHBYTE | LREF_LOWBYTE)) == (LREF_HIGHBYTE | LREF_LOWBYTE)) + { + if (cref->mRefObject->mType == LOT_NATIVE_CODE && cref->mRefObject->mSize == 3 && + cobj->mSection == cref->mRefObject->mSection && cref->mRefOffset == 0 && + cref->mRefObject->mData[0] == 0x4c) + { + LinkerObject* tobj(cref->mRefObject); + if (tobj->mReferences.Size()) + { + cref->mRefObject = tobj->mReferences[0]->mRefObject; + cref->mRefOffset = tobj->mReferences[0]->mRefOffset; + } + else + { + cobj->mData[cref->mOffset + 0] = tobj->mData[1]; + cobj->mData[cref->mOffset + 1] = tobj->mData[2]; + cref->mFlags = 0; + cref->mRefObject = cobj; + } + } + } + } + } + + } + +} void Linker::CheckDirectJumps(void) @@ -1203,7 +1240,7 @@ bool Linker::WritePrgFile(const char* filename, const char* pathname) mCartridge[b][s - 2] = s & 0xff; mCartridge[b][s - 1] = s >> 8; - fwrite(mCartridge[b] + s - 22, 1, mCartridgeBankEnd[b] - s + 2, file); + fwrite(mCartridge[b] + s - 2, 1, mCartridgeBankEnd[b] - s + 2, file); fclose(file); } else diff --git a/oscar64/Linker.h b/oscar64/Linker.h index e150481..f5e09cd 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -301,6 +301,7 @@ public: void CheckDirectJumps(void); void CollectReferences(void); void CombineSameConst(void); + void InlineSimpleJumps(void); void PatchReferences(bool inlays); void CopyObjects(bool inlays); void PlaceObjects(void); diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 4809c90..32d36f3 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -12733,7 +12733,7 @@ NativeCodeInstruction NativeCodeBasicBlock::DecodeNative(const InterInstruction* linkerObject = lref->mRefObject; address = lref->mRefOffset; } - else + else if (d.mType != ASMIT_JSR) flags |= NCIF_VOLATILE; break; case ASMIM_ZERO_PAGE: