awfull code

This commit is contained in:
Rose Apollo 2024-04-26 12:31:55 +00:00
parent 415828d694
commit 47b7870467

View File

@ -214,6 +214,111 @@ int WhereIn2DCharArray(int x, int y, char array[x][y], char *val)
return -1; return -1;
} }
void ParseArgument(char *argData, AsmLabelArray *labels, uint16_t labelOffset,
ArgumentInfo *argInfoOut, uint16_t *argOut)
{
bool pointer, value, label;
pointer = argData[0] == '*'; // location in ram / pointer in register
if (pointer)
argData++;
value = argData[0] >= '0' && argData[0] <= '9';
label = !value && argData[0] == '[';
if (!pointer && !value) // value in register / label
{
if (label)
{
*argInfoOut = value;
}
else
{
*argInfoOut = valueInRegister;
}
}
else if (!pointer && value) // value
{
*argInfoOut = value;
uint16_t modval = 0, total = 0;
switch (argData[1])
{
case 'x':
case 'X':
modval = 16;
argData += 2;
break;
case 'b':
case 'B':
modval = 2;
argData += 2;
break;
default:
modval = 10;
break;
}
for (char *a = argData; a < FindNextSpaceChar(argData, true); a++)
{
total *= modval;
switch(*a)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
total += '0' - *a;
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
total += 10 + ('a' - *a);
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
total += 10 + ('A' - *a);
break;
default:
fprintf(stderr, "FATAL CHARACTER IN NUMBER STREAM\n");
exit(-1);
}
}
*argOut = total;
}
else if (pointer && !value) // pointer in register
{
*argInfoOut = pointerInRegister;
}
else
{
fprintf(stderr, "FATAL ARGUMENT INFO\n");
exit(-1);
}
}
uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels) uint16_t *CompileAsembly(AsmInstructionArray *assembly, AsmLabelArray *labels)
{ {
uint16_t *ret = malloc(sizeof(uint16_t) * UINT16_MAX); uint16_t *ret = malloc(sizeof(uint16_t) * UINT16_MAX);