Fix overlay prg file save

This commit is contained in:
drmortalwombat 2024-01-27 17:11:10 +01:00
parent 2ad71ef867
commit 974688a8a5
6 changed files with 59 additions and 32 deletions

View File

@ -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
}
}

View File

@ -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

View File

@ -1097,6 +1097,7 @@ bool Compiler::GenerateCode(void)
if (mCompilerOptions & COPT_OPTIMIZE_BASIC)
{
mLinker->CombineSameConst();
mLinker->InlineSimpleJumps();
mLinker->CheckDirectJumps();
}

View File

@ -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

View File

@ -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);

View File

@ -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: