Fix longjump and kernalio end of file handling

This commit is contained in:
drmortalwombat 2022-01-13 10:37:44 +01:00
parent d9946e12b9
commit c72ca3547b
6 changed files with 89 additions and 15 deletions

View File

@ -80,7 +80,7 @@ enum AsmIns
ASM_BIT = 0x20,
// Jump
ASM_JMP = 0x4c,
ASM_JMP = 0x40,
ASM_JSR = 0x2c
};

View File

@ -1,5 +1,6 @@
#include "kernalio.h"
krnioerr krnio_pstatus[16];
void krnio_setnam(const char * name)
{
@ -24,6 +25,8 @@ void krnio_setnam(const char * name)
bool krnio_open(char fnum, char device, char channel)
{
krnio_pstatus[fnum] = KRNIO_OK;
__asm
{
lda #0
@ -75,6 +78,37 @@ krnioerr krnio_status(void)
#pragma native(krnio_status)
bool krnio_load(char fnum, char device, char channel)
{
__asm
{
lda #0
sta accu
sta accu + 1
lda fnum
ldx device
ldy channel
jsr $ffba // setlfs
lda #0
ldx #0
ldy #0
jsr $FFD5 // open
bcc W1
lda #0
jmp E2
W1:
lda #1
sta accu
E2:
}
}
#pragma native(krnio_load)
bool krnio_chkout(char fnum)
{
__asm
@ -146,11 +180,15 @@ int krnio_chrin(void)
int krnio_getch(char fnum)
{
if (krnio_pstatus[fnum] == KRNIO_EOF)
return -1;
int ch = -1;
if (krnio_chkin(fnum))
{
ch = krnio_chrin();
krnioerr err = krnio_status();
krnio_pstatus[fnum] = err;
if (err)
{
if (err == KRNIO_EOF)
@ -209,6 +247,9 @@ int krnio_write(char fnum, const char * data, int num)
int krnio_read(char fnum, char * data, int num)
{
if (krnio_pstatus[fnum] == KRNIO_EOF)
return 0;
if (krnio_chkin(fnum))
{
int i = 0;
@ -217,6 +258,7 @@ int krnio_read(char fnum, char * data, int num)
{
ch = krnio_chrin();
krnioerr err = krnio_status();
krnio_pstatus[fnum] = err;
if (err && err != KRNIO_EOF)
break;
data[i++] = (char)ch;
@ -234,6 +276,9 @@ int krnio_read(char fnum, char * data, int num)
int krnio_gets(char fnum, char * data, int num)
{
if (krnio_pstatus[fnum] == KRNIO_EOF)
return 0;
if (krnio_chkin(fnum))
{
int i = 0;
@ -242,6 +287,7 @@ int krnio_gets(char fnum, char * data, int num)
{
ch = krnio_chrin();
krnioerr err = krnio_status();
krnio_pstatus[fnum] = err;
if (err && err != KRNIO_EOF)
break;
data[i++] = (char)ch;

View File

@ -16,6 +16,8 @@ enum krnioerr
KRNIO_NODEVICE = 0x80
};
extern krnioerr krnio_pstatus[16];
// Set filename for next krnio_open operation, make sure
// that the string is still valid when calling krnio_open
@ -33,6 +35,8 @@ void krnio_close(char fnum);
krnioerr krnio_status(void);
bool krnio_load(char fnum, char device, char channel);
// select the given file for stream output
bool krnio_chkout(char fnum);

View File

@ -40,11 +40,11 @@ int setjmp(jmp_buf env)
sta (env), y
iny
lda $0100, x
lda $0101, x
sta (env), y
iny
lda $0101, x
lda $0102, x
sta (env), y
iny
}
@ -95,11 +95,11 @@ void longjmp(jmp_buf env, int value)
iny
lda (env), y
sta $0100, x
sta $0101, x
iny
lda (env), y
sta $0101, x
sta $0102, x
iny
lda value

View File

@ -7824,6 +7824,8 @@ void NativeCodeBasicBlock::LoadEffectiveAddress(InterCodeProcedure* proc, const
void NativeCodeBasicBlock::CallFunction(InterCodeProcedure* proc, NativeCodeProcedure * nproc, const InterInstruction * ins)
{
if (ins->mSrc[0].mTemp < 0)
{
if (ins->mSrc[0].mLinkerObject)
{
NativeCodeInstruction lins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins->mSrc[0].mIntConst, ins->mSrc[0].mLinkerObject, NCIF_LOWER);
NativeCodeInstruction hins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins->mSrc[0].mIntConst, ins->mSrc[0].mLinkerObject, NCIF_UPPER);
@ -7834,6 +7836,17 @@ void NativeCodeBasicBlock::CallFunction(InterCodeProcedure* proc, NativeCodeProc
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
}
else
{
NativeCodeInstruction lins(ASMIT_LDA, ASMIM_IMMEDIATE, ins->mSrc[0].mIntConst & 0xff);
NativeCodeInstruction hins(ASMIT_LDA, ASMIM_IMMEDIATE, (ins->mSrc[0].mIntConst >> 8) & 0xff);
mIns.Push(lins);
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));
mIns.Push(hins);
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
}
}
else
{
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp] + 0));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));

View File

@ -271,6 +271,8 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
mScanner->NextToken();
if (mScanner->mToken == TK_IDENT)
{
int minValue = 0, maxValue = 0;
for (;;)
{
Declaration* cdec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
@ -293,16 +295,25 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint32 flags)
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_TYPE, "Integer constant expected");
}
cdec->mInteger = nitem++;
if (dec->mInteger < 0)
dec->mFlags |= DTF_SIGNED;
if (cdec->mInteger < -128 || cdec->mInteger > 127)
dec->mSize = 2;
if (dec->mInteger < minValue)
minValue = dec->mInteger;
else if (dec->mInteger > maxValue)
maxValue = dec->mInteger;
if (mScanner->mToken == TK_COMMA)
mScanner->NextToken();
else
break;
}
if (minValue < 0)
{
dec->mFlags |= DTF_SIGNED;
if (minValue < -128 || maxValue > 127)
dec->mSize = 2;
}
else if (maxValue > 255)
dec->mSize = 2;
}
if (mScanner->mToken == TK_CLOSE_BRACE)