From 58ab6818ed0ed3d590fc08cbca4f39155af6a727 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:34:23 +0200 Subject: [PATCH] Add alignment for functions --- include/conio.c | 31 +++++++++++++++++++++++++++++++ include/conio.h | 4 ++++ oscar64/InterCodeGenerator.cpp | 19 ++++++++++++++++--- oscar64/Parser.cpp | 16 +++++++++++++++- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/include/conio.c b/include/conio.c index afc8e1a..6b4b008 100644 --- a/include/conio.c +++ b/include/conio.c @@ -32,6 +32,12 @@ __asm bsinit jsr 0xff81 sta 0xff01 } +__asm dswap +{ + sta 0xff00 + jsr 0xff5f + sta 0xff01 +} #pragma code(code) #elif defined(__PLUS4__) #pragma code(lowcode) @@ -94,6 +100,31 @@ __asm bsinit #define bsinit 0xff81 #endif +#if defined(__C128__) +void dispmode40col(void) +{ + if (*(volatile char *)0xd7 >= 128) + { + __asm + { + jsr dswap + } + } +} + +void dispmode80col(void) +{ + if (*(volatile char *)0xd7 < 128) + { + __asm + { + jsr dswap + } + } +} +#endif + + void iocharmap(IOCharMap chmap) { giocharmap = chmap; diff --git a/include/conio.h b/include/conio.h index 28a72b4..f1749b3 100644 --- a/include/conio.h +++ b/include/conio.h @@ -18,6 +18,10 @@ extern IOCharMap giocharmap; void iocharmap(IOCharMap chmap); +#if defined(__C128__) +void dispmode40col(void); +void dispmode80col(void); +#endif int kbhit(void); diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 6c85e03..3b61f44 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -473,7 +473,7 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression* ex Declaration* dec = exp->mDecValue; - dec->mLinkerObject = mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_NATIVE_CODE); + dec->mLinkerObject = mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_NATIVE_CODE, dec->mAlignment); uint8* d = dec->mLinkerObject->AddSpace(osize); @@ -600,7 +600,20 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression* ex } else if (aexp->mType == DT_ARGUMENT || aexp->mType == DT_VARIABLE) { - if (refvars) + if (aexp->mFlags & DTF_GLOBAL) + { + InitGlobalVariable(mod, aexp); + + LinkerReference ref; + ref.mObject = dec->mLinkerObject; + ref.mOffset = offset; + ref.mFlags = LREF_LOWBYTE; + ref.mRefObject = aexp->mLinkerObject; + ref.mRefOffset = 0; + ref.mRefObject->mFlags |= LOBJF_RELEVANT; + dec->mLinkerObject->AddReference(ref); + } + else if (refvars) { int j = 0; while (j < refvars->Size() && (*refvars)[j] != aexp) @@ -4635,7 +4648,7 @@ void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedur InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod, Expression* exp, Declaration * dec) { - InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE)); + InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE, dec->mAlignment)); #if 0 if (proc->mIdent && !strcmp(proc->mIdent->mString, "main")) diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 9565772..aaeef30 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -7322,7 +7322,8 @@ Expression* Parser::ParseAssembler(void) if ((ilast->mLeft->mDecValue->mType == DT_CONST_INTEGER && ilast->mLeft->mDecValue->mInteger < 256) || (ilast->mLeft->mDecValue->mType == DT_VARIABLE_REF && !(ilast->mLeft->mDecValue->mBase->mFlags & DTF_GLOBAL)) || (ilast->mLeft->mDecValue->mType == DT_VARIABLE && !(ilast->mLeft->mDecValue->mFlags & DTF_GLOBAL)) || - ilast->mLeft->mDecValue->mType == DT_ARGUMENT) + (ilast->mLeft->mDecValue->mType == DT_VARIABLE && (ilast->mLeft->mDecValue->mFlags & DTF_ZEROPAGE)) || + ilast->mLeft->mDecValue->mType == DT_ARGUMENT) { if (ilast->mAsmInsMode == ASMIM_ABSOLUTE && HasAsmInstructionMode(ilast->mAsmInsType, ASMIM_ZERO_PAGE)) ilast->mAsmInsMode = ASMIM_ZERO_PAGE; @@ -8072,6 +8073,19 @@ void Parser::ParsePragma(void) else mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for alignment expected"); } + else if (dec && dec->mType == DT_CONST_FUNCTION) + { + mScanner->NextToken(); + ConsumeToken(TK_COMMA); + + Expression* exp = ParseRExpression(); + if (exp->mType == EX_CONSTANT && exp->mDecValue->mType == DT_CONST_INTEGER) + { + dec->mAlignment = int(exp->mDecValue->mInteger); + } + else + mErrors->Error(mScanner->mLocation, EERR_PRAGMA_PARAMETER, "Integer number for alignment expected"); + } else { mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Variable not found");