Fix parameter address reference in __asm embedding

This commit is contained in:
drmortalwombat 2024-06-11 13:07:50 +02:00
parent 5ccfab0342
commit c99c1756a9
4 changed files with 44 additions and 23 deletions

View File

@ -54,7 +54,7 @@ bool krnio_open(char fnum, char device, char channel)
{ {
krnio_pstatus[fnum] = KRNIO_OK; krnio_pstatus[fnum] = KRNIO_OK;
__asm return __asm
{ {
lda #0 lda #0
sta accu sta accu
@ -75,7 +75,7 @@ bool krnio_open(char fnum, char device, char channel)
lda #1 lda #1
sta accu sta accu
E2: E2:
} };
} }
@ -94,13 +94,13 @@ void krnio_close(char fnum)
krnioerr krnio_status(void) krnioerr krnio_status(void)
{ {
__asm return __asm
{ {
jsr $ffb7 // readst jsr $ffb7 // readst
sta accu sta accu
lda #0 lda #0
sta accu + 1 sta accu + 1
} };
} }
#pragma native(krnio_status) #pragma native(krnio_status)
@ -108,7 +108,7 @@ krnioerr krnio_status(void)
bool krnio_load(char fnum, char device, char channel) bool krnio_load(char fnum, char device, char channel)
{ {
__asm return __asm
{ {
lda fnum lda fnum
ldx device ldx device
@ -124,14 +124,14 @@ bool krnio_load(char fnum, char device, char channel)
rol rol
eor #1 eor #1
sta accu sta accu
} };
} }
#pragma native(krnio_load) #pragma native(krnio_load)
bool krnio_save(char device, const char* start, const char* end) bool krnio_save(char device, const char* start, const char* end)
{ {
__asm return __asm
{ {
lda #0 lda #0
ldx device ldx device
@ -147,14 +147,14 @@ bool krnio_save(char device, const char* start, const char* end)
rol rol
eor #1 eor #1
sta accu sta accu
} };
} }
#pragma native(krnio_save) #pragma native(krnio_save)
bool krnio_chkout(char fnum) bool krnio_chkout(char fnum)
{ {
__asm return __asm
{ {
ldx fnum ldx fnum
jsr $ffc9 // chkout jsr $ffc9 // chkout
@ -163,14 +163,14 @@ bool krnio_chkout(char fnum)
rol rol
eor #1 eor #1
sta accu sta accu
} };
} }
#pragma native(krnio_chkout) #pragma native(krnio_chkout)
bool krnio_chkin(char fnum) bool krnio_chkin(char fnum)
{ {
__asm return __asm
{ {
ldx fnum ldx fnum
jsr $ffc6 // chkin jsr $ffc6 // chkin
@ -179,7 +179,7 @@ bool krnio_chkin(char fnum)
rol rol
eor #1 eor #1
sta accu sta accu
} };
} }
#pragma native(krnio_chkin) #pragma native(krnio_chkin)
@ -196,23 +196,23 @@ void krnio_clrchn(void)
bool krnio_chrout(char ch) bool krnio_chrout(char ch)
{ {
__asm return __asm
{ {
lda ch lda ch
jsr $ffd2 // chrout jsr $ffd2 // chrout
sta accu sta accu
} };
} }
#pragma native(krnio_chrout) #pragma native(krnio_chrout)
char krnio_chrin(void) char krnio_chrin(void)
{ {
__asm return __asm
{ {
jsr $ffcf // chrin jsr $ffcf // chrin
sta accu sta accu
} };
} }
#pragma native(krnio_chrin) #pragma native(krnio_chrin)

View File

@ -44,7 +44,7 @@ krnioerr krnio_status(void);
bool krnio_load(char fnum, char device, char channel); bool krnio_load(char fnum, char device, char channel);
__noinline bool krnio_save(char device, const char* start, const char* end); bool krnio_save(char device, const char* start, const char* end);
// select the given file for stream output // select the given file for stream output

View File

@ -802,6 +802,16 @@ bool NativeCodeInstruction::IsUsedResultInstructions(NumberSet& requiredTemps)
requiredTemps += mAddress; requiredTemps += mAddress;
requiredTemps += mAddress + 1; requiredTemps += mAddress + 1;
break; break;
case ASMIM_IMMEDIATE:
if (mFlags & NICF_TMPREF)
{
if (mFlags & NCIF_LOWER)
requiredTemps += mAddress;
if (mFlags & NCIF_UPPER)
requiredTemps += mAddress + 1;
}
break;
} }
// check carry flags // check carry flags
@ -13329,6 +13339,15 @@ NativeCodeInstruction NativeCodeBasicBlock::DecodeNative(const InterInstruction*
lref = lobj->FindReference(offset); lref = lobj->FindReference(offset);
address = lobj->mData[offset++]; address = lobj->mData[offset++];
if (lref) if (lref)
{
if (lref->mFlags & LREF_TEMPORARY)
{
address = lobj->mTemporaries[lref->mRefOffset];
flags |= NICF_TMPREF | NCIF_LOWER;
if (lobj->mTempSizes[lref->mRefOffset] > 1)
flags |= NCIF_UPPER;
}
else
{ {
d.mMode = ASMIM_IMMEDIATE_ADDRESS; d.mMode = ASMIM_IMMEDIATE_ADDRESS;
linkerObject = lref->mRefObject; linkerObject = lref->mRefObject;
@ -13338,6 +13357,7 @@ NativeCodeInstruction NativeCodeBasicBlock::DecodeNative(const InterInstruction*
else else
flags = NCIF_UPPER; flags = NCIF_UPPER;
} }
}
break; break;
} }

View File

@ -122,6 +122,7 @@ static const uint32 NCIF_FEXEC = 0x00000040;
static const uint32 NCIF_JSRFLAGS = 0x00000080; static const uint32 NCIF_JSRFLAGS = 0x00000080;
static const uint32 NICT_INDEXFLIPPED = 0x00000100; static const uint32 NICT_INDEXFLIPPED = 0x00000100;
static const uint32 NICT_ZPFLIPPED = 0x00000200; static const uint32 NICT_ZPFLIPPED = 0x00000200;
static const uint32 NICF_TMPREF = 0x00000400;
static const uint32 NCIF_USE_CPU_REG_A = 0x00001000; static const uint32 NCIF_USE_CPU_REG_A = 0x00001000;
static const uint32 NCIF_USE_CPU_REG_X = 0x00002000; static const uint32 NCIF_USE_CPU_REG_X = 0x00002000;