From 250be7f64dbaa878ef78aab6b70180e7c7fb2e77 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 16 Jan 2015 15:41:24 +0000 Subject: [PATCH] tools/syscall6502: corrections This now generates some vaguely plausible looking code 8) --- Library/Makefile | 2 +- Library/tools/syscall_6502.c | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Library/tools/syscall_6502.c diff --git a/Library/Makefile b/Library/Makefile index 9ea55687..0158ee97 100644 --- a/Library/Makefile +++ b/Library/Makefile @@ -9,5 +9,5 @@ clean: tools/syscall: tools/syscall.c ../Kernel/include/syscall_name.h tools/syscall-z88dk: tools/syscall-z88dk.c ../Kernel/include/syscall_name.h - +tools/syscall_6502: tools/syscall_6502.c ../Kernel/include/syscall_name.h tools/binman: tools/binman.c diff --git a/Library/tools/syscall_6502.c b/Library/tools/syscall_6502.c new file mode 100644 index 00000000..422a7a28 --- /dev/null +++ b/Library/tools/syscall_6502.c @@ -0,0 +1,65 @@ +/* + * Generate the syscall functions + */ + +#include +#include +#include +#include "syscall_name.h" + +static char namebuf[128]; + +static void write_call(int n) +{ + FILE *fp; + snprintf(namebuf, 128, "fuzix6502/syscall_%s.s", syscall_name[n]); + fp = fopen(namebuf, "w"); + if (fp == NULL) { + perror(namebuf); + exit(1); + } + fprintf(fp, "\t.export _%s\n\n", syscall_name[n]); + fprintf(fp, ".proc _%s\n\tldx #%d\n", syscall_name[n], n); + fprintf(fp, "\tldy #%d\n", 2 * syscall_args[n]); + fprintf(fp, "\tjmp ($fe)\n\n.endproc\n"); + fclose(fp); +} + +static void write_call_table(void) +{ + int i; + for (i = 0; i < NR_SYSCALL; i++) + write_call(i); +} + +static void write_makefile(void) +{ + int i; + FILE *fp = fopen("fuzix6502/Makefile", "w"); + if (fp == NULL) { + perror("Makefile"); + exit(1); + } + fprintf(fp, "# Autogenerated by tools/syscall_6502\n"); + fprintf(fp, "AS = ca65\n"); + fprintf(fp, "AR = ar65\n"); + fprintf(fp, "ASRCS = syscall_%s.s\n", syscall_name[0]); + for (i = 1; i < NR_SYSCALL; i++) + fprintf(fp, "ASRCS += syscall_%s.s\n", syscall_name[i]); + fprintf(fp, "\n\nASRCALL = $(ASRCS) $(ASYS)\n"); + fprintf(fp, "\nAOBJS = $(ASRCALL:.s=.o)\n\n"); + fprintf(fp, "../syslib.lib: $(AOBJS)\n"); + fprintf(fp, "\t$(AR) a ../syslib.lib $(AOBJS)\n\n"); + fprintf(fp, "$(AOBJS): %%.o: %%.s\n"); + fprintf(fp, "\t$(AS) -o $*.o $<\n\n"); + fprintf(fp, "clean:\n"); + fprintf(fp, "\trm -f $(AOBJS) $(ASRCS) *~\n\n"); + fclose(fp); +} + +int main(int argc, char *argv[]) +{ + write_makefile(); + write_call_table(); + exit(0); +} -- 2.34.1