Add kernal banking for plus/4 kernalio.c

This commit is contained in:
drmortalwombat 2024-08-30 18:40:48 +02:00
parent 17ec90cfe7
commit 759a701df8
2 changed files with 60 additions and 16 deletions

View File

@ -16,7 +16,18 @@ void krnio_setbnk(char filebank, char namebank)
#pragma native(krnio_setbnk)
#endif
void krnio_setnam(const char * name)
#if defined(__PLUS4__)
#pragma code(lowcode)
#define BANKIN sta 0xff3e
#define BANKOUT sta 0xff3f
#define BANKINLINE __noinline
#else
#define BANKIN
#define BANKOUT
#define BANKINLINE
#endif
BANKINLINE void krnio_setnam(const char * name)
{
__asm
{
@ -31,26 +42,30 @@ void krnio_setnam(const char * name)
tya
W1: ldx name
ldy name + 1
BANKIN
jsr $ffbd // setnam
BANKOUT
}
}
#pragma native(krnio_setnam)
void krnio_setnam_n(const char * name, char len)
BANKINLINE void krnio_setnam_n(const char * name, char len)
{
__asm
{
lda len
ldx name
ldy name + 1
BANKIN
jsr $ffbd // setnam
BANKOUT
}
}
#pragma native(krnio_setnam_n)
bool krnio_open(char fnum, char device, char channel)
BANKINLINE bool krnio_open(char fnum, char device, char channel)
{
krnio_pstatus[fnum] = KRNIO_OK;
@ -60,6 +75,8 @@ bool krnio_open(char fnum, char device, char channel)
sta accu
sta accu + 1
BANKIN
lda fnum
ldx device
ldy channel
@ -74,6 +91,8 @@ bool krnio_open(char fnum, char device, char channel)
W1:
lda #1
sta accu
BANKOUT
E2:
};
@ -81,22 +100,26 @@ bool krnio_open(char fnum, char device, char channel)
#pragma native(krnio_open)
void krnio_close(char fnum)
BANKINLINE void krnio_close(char fnum)
{
__asm
{
BANKIN
lda fnum
jsr $ffc3 // close
BANKOUT
}
}
#pragma native(krnio_close)
krnioerr krnio_status(void)
BANKINLINE krnioerr krnio_status(void)
{
return __asm
{
BANKIN
jsr $ffb7 // readst
BANKOUT
sta accu
lda #0
sta accu + 1
@ -106,10 +129,11 @@ krnioerr krnio_status(void)
#pragma native(krnio_status)
bool krnio_load(char fnum, char device, char channel)
BANKINLINE bool krnio_load(char fnum, char device, char channel)
{
return __asm
{
BANKIN
lda fnum
ldx device
ldy channel
@ -119,6 +143,7 @@ bool krnio_load(char fnum, char device, char channel)
ldx #0
ldy #0
jsr $FFD5 // load
BANKOUT
lda #0
rol
@ -129,10 +154,11 @@ bool krnio_load(char fnum, char device, char channel)
#pragma native(krnio_load)
bool krnio_save(char device, const char* start, const char* end)
BANKINLINE bool krnio_save(char device, const char* start, const char* end)
{
return __asm
{
BANKIN
lda #0
ldx device
ldy #0
@ -143,6 +169,8 @@ bool krnio_save(char device, const char* start, const char* end)
ldy end+1
jsr $FFD8 // save
BANKOUT
lda #0
rol
eor #1
@ -152,12 +180,14 @@ bool krnio_save(char device, const char* start, const char* end)
#pragma native(krnio_save)
bool krnio_chkout(char fnum)
BANKINLINE bool krnio_chkout(char fnum)
{
return __asm
{
BANKIN
ldx fnum
jsr $ffc9 // chkout
BANKOUT
lda #0
rol
@ -168,12 +198,14 @@ bool krnio_chkout(char fnum)
#pragma native(krnio_chkout)
bool krnio_chkin(char fnum)
BANKINLINE bool krnio_chkin(char fnum)
{
return __asm
{
BANKIN
ldx fnum
jsr $ffc6 // chkin
BANKOUT
lda #0
rol
@ -184,39 +216,49 @@ bool krnio_chkin(char fnum)
#pragma native(krnio_chkin)
void krnio_clrchn(void)
BANKINLINE void krnio_clrchn(void)
{
__asm
{
BANKIN
jsr $ffcc // clrchn
BANKOUT
}
}
#pragma native(krnio_clrchn)
bool krnio_chrout(char ch)
BANKINLINE bool krnio_chrout(char ch)
{
return __asm
{
BANKIN
lda ch
jsr $ffd2 // chrout
sta accu
BANKOUT
};
}
#pragma native(krnio_chrout)
char krnio_chrin(void)
BANKINLINE char krnio_chrin(void)
{
return __asm
{
BANKIN
jsr $ffcf // chrin
sta accu
BANKOUT
};
}
#pragma native(krnio_chrin)
#if defined(__PLUS4__)
#pragma code(code)
#endif
int krnio_getch(char fnum)
{
if (krnio_pstatus[fnum] == KRNIO_EOF)

View File

@ -552,12 +552,12 @@ bool Compiler::GenerateCode(void)
if (mCompilerOptions & COPT_NATIVE)
{
regionStartup = mLinker->AddRegion(identStartup, 0x1001, 0x1080);
regionLowcode = mLinker->AddRegion(identLowcode, 0x1080, 0x1100);
regionLowcode = mLinker->AddRegion(identLowcode, 0x1080, 0x1180);
}
else
{
regionStartup = mLinker->AddRegion(identStartup, 0x1001, 0x1080);
regionLowcode = mLinker->AddRegion(identLowcode, 0x1080, 0x1000);
regionLowcode = mLinker->AddRegion(identLowcode, 0x1080, 0x1180);
}
regionLowcode->mSections.Push(mCompilationUnits->mSectionLowCode);
break;
@ -633,6 +633,8 @@ bool Compiler::GenerateCode(void)
regionBytecode = mLinker->AddRegion(identBytecode, 0x1d00, 0x1e00);
break;
case TMACH_PLUS4:
regionBytecode = mLinker->AddRegion(identBytecode, 0x1200, 0x1300);
break;
case TMACH_VIC20:
regionBytecode = mLinker->AddRegion(identBytecode, 0x1100, 0x1200);
break;
@ -698,7 +700,7 @@ bool Compiler::GenerateCode(void)
regionMain = mLinker->AddRegion(identMain, 0x1e00, 0xc000);
break;
case TMACH_PLUS4:
regionMain = mLinker->AddRegion(identMain, 0x1200, 0xfc00);
regionMain = mLinker->AddRegion(identMain, 0x1300, 0xfc00);
break;
case TMACH_VIC20:
regionMain = mLinker->AddRegion(identMain, 0x1200, 0x1e00);
@ -753,7 +755,7 @@ bool Compiler::GenerateCode(void)
regionMain = mLinker->AddRegion(identMain, 0x1c80, 0xc000);
break;
case TMACH_PLUS4:
regionMain = mLinker->AddRegion(identMain, 0x1100, 0xfc00);
regionMain = mLinker->AddRegion(identMain, 0x1180, 0xfc00);
break;
case TMACH_VIC20:
regionMain = mLinker->AddRegion(identMain, 0x1080, 0x1e00);