Make shore memcpy calls intrinsic

This commit is contained in:
drmortalwombat 2022-01-27 23:08:57 +01:00
parent 79a841a422
commit dfe3d71f85
4 changed files with 98 additions and 0 deletions

View File

@ -23,6 +23,8 @@ void * memmove(void * dst, const void * src, int size);
#pragma intrinsic(strcpy)
#pragma intrinsic(memcpy)
#pragma compile("string.c")
#endif

View File

@ -1895,6 +1895,43 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
}
}
}
else if (!strcmp(iname->mString, "memcpy"))
{
if (exp->mRight->mType == EX_LIST)
{
Expression* tex = exp->mRight->mLeft, * sex = exp->mRight->mRight->mLeft, * nex = exp->mRight->mRight->mRight;
if (nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger < 128)
{
vl = TranslateExpression(procType, proc, block, tex, breakBlock, continueBlock, inlineMapper);
if (vl.mType->mType == DT_TYPE_ARRAY)
vl = Dereference(proc, block, vl, 1);
else
vl = Dereference(proc, block, vl);
vr = TranslateExpression(procType, proc, block, sex, breakBlock, continueBlock, inlineMapper);
if (vr.mType->mType == DT_TYPE_ARRAY)
vr = Dereference(proc, block, vr, 1);
else
vr = Dereference(proc, block, vr);
if (!TheCharPointerTypeDeclaration->CanAssign(vl.mType))
mErrors->Error(tex->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types");
if (!TheConstCharPointerTypeDeclaration->CanAssign(vr.mType))
mErrors->Error(sex->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types");
InterInstruction* ins = new InterInstruction();
ins->mCode = IC_COPY;
ins->mSrc[0].mType = IT_POINTER;
ins->mSrc[0].mTemp = vr.mTemp;
ins->mSrc[1].mType = IT_POINTER;
ins->mSrc[1].mTemp = vl.mTemp;
ins->mConst.mOperandSize = nex->mDecValue->mInteger;
block->Append(ins);
return vl;
}
}
}
else
{
mErrors->Error(exp->mLeft->mDecValue->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown intrinsic function", iname->mString);

View File

@ -0,0 +1,58 @@
#include <c64/vic.h>
#include <c64/rasterirq.h>
#include <string.h>
const char Text[] =
S"LABORUM RERUM QUO. QUASI IN, SEQUI, TENETUR VOLUPTATEM RERUM "
S"PORRO NON ET MAIORES ALIAS ODIO EST EOS. MAGNAM APERIAM CUM ET "
S"ESSE TEMPORE ITAQUE TEMPORA VOLUPTAS ET IPSAM IPSAM EARUM. ID "
S"SUSCIPIT QUIA RERUM REPREHENDERIT ERROR ET UT. DOLOR ID "
S"CORPORIS, EOS? UNDE VERO ISTE QUIA? EAQUE EAQUE. IN. AUT ID "
S"EXPEDITA ILLUM MOLESTIAS, ";
// Raster interrupt command structure for change to scrolled and back
RIRQCode scroll, restore;
static int x;
// Loop through text
__interrupt void doscroll(void)
{
// Update raster IRQ for scroll line with new horizontal scroll offset
rirq_data(&scroll, 0, 7 - (x & 7));
// Copy scrolled version of text when switching over char border
if ((x & 7) == 0)
memcpy((char *)0x0400 + 40 * 24, Text + ((x >> 3) & 255), 40);
x++;
}
int main(void)
{
// initialize raster IRQ
rirq_init(true);
// Build switch to scroll line IRQ
rirq_build(&scroll, 1);
// Change control register two with this IRQ
rirq_write(&scroll, 0, &vic.ctrl2, 0);
// Put it onto the scroll line
rirq_set(0, 50 + 24 * 8, &scroll);
// Build the switch to normal IRQ
rirq_build(&restore, 2);
// re-enable left and right column and reset horizontal scroll
rirq_write(&restore, 0, &vic.ctrl2, VIC_CTRL2_CSEL);
// call scroll copy code
rirq_call(&restore, 1, doscroll);
// place this at the top of the screen before the display starts
rirq_set(1, 4, &restore);
// sort the raster IRQs
rirq_sort();
// start raster IRQ processing
rirq_start();
return 0;
}

View File

@ -2,3 +2,4 @@ call ..\..\bin\oscar64 colorbars.c
call ..\..\bin\oscar64 openborder.c
call ..\..\bin\oscar64 textcrawler.c
call ..\..\bin\oscar64 movingbars.c -n
call ..\..\bin\oscar64 autocrawler.c -n