Returning pointers from relocated code should work (even if it's not a great idea).

This commit is contained in:
Scott Duensing 2024-02-18 18:55:12 -06:00
parent a6cee7f529
commit c7d21f850f
2 changed files with 17 additions and 3 deletions

View file

@ -29,7 +29,12 @@
Breaking things { with comments! Breaking things { with comments!
*/ */
void test(int arg1, int arg2) { const char *test(int arg1, int arg2) {
return "Pointers from a swapped bank is probably a bad idea.";
}
int test2(int arg1, int arg2) {
return 1;
} }

View file

@ -171,13 +171,22 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
// Now go backwards and look for a space. // Now go backwards and look for a space.
start = b; start = b;
while (*start != ' ') start--; while (*start != ' ') start--;
*start++ = 0; // Are they returning a pointer?
found = false;
if (*(start+1) == '*') {
found = true;
++start;
*start++ = 0;
} else {
*start++ = 0;
found = false;
}
// Yank the function name out. // Yank the function name out.
*b = 0; *b = 0;
temp = strdup(start); temp = strdup(start);
*b = '('; *b = '(';
// Write out new function definition. // Write out new function definition.
fprintf(out, "%s FAR%d_%s {\n", buffer, 8, start); fprintf(out, "%s%sFAR%d_%s {\n", buffer, found ? "*" : " ", 8, start);
// Create trampoline macro. // Create trampoline macro.
fprintf(trampoline, "#define %s(...) ({ \\\n" fprintf(trampoline, "#define %s(...) ({ \\\n"
"\t\tunsigned char ___mmu = (unsigned char)*(volatile unsigned char *)%#06x; \\\n" "\t\tunsigned char ___mmu = (unsigned char)*(volatile unsigned char *)%#06x; \\\n"