X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=dsp56kgen.c;fp=dsp56kgen.c;h=3f263ad7c4f83821c56aa8118e1ff6f1951ee3dc;hp=0000000000000000000000000000000000000000;hb=30a208654896284b50e7b362e97d3e63ec717b96;hpb=790cd95291aa2dcfd3128652ef9c34bab1398a8d diff --git a/dsp56kgen.c b/dsp56kgen.c new file mode 100644 index 0000000..3f263ad --- /dev/null +++ b/dsp56kgen.c @@ -0,0 +1,134 @@ +// +// RMAC - Reboot's Macro Assembler for all Atari computers +// 68KGEN.C - Tool to Generate 68000 Opcode Table +// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends +// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 +// Source utilised with the kind permission of Landon Dyer +// + +#include +#include +#include + + +#define EOS '\0' + +int kwnum = 1; /* current op# for kwgen output */ +FILE * kfp; /* keyword file */ +int lineno = 0; + +// Function prototypes +void error(char *, char *); +void procln(int, char **); + + +int main(int argc, char ** argv) +{ + char * namv[256]; + char * s; + int namcnt; + char ln[256]; + + if ((argc == 2) && ((kfp = fopen(argv[1], "w")) == NULL)) + error("Cannot create: %s", argv[1]); + + while (fgets(ln, 256, stdin) != NULL) + { + lineno++; /* bump line# */ + + if (*ln == '#') /* ignore comments */ + continue; + + /* + * Tokenize line (like the way "argc, argv" works) + * and pass it to the parser. + */ + namcnt = 0; + s = ln; + + while (*s) + { + if (isspace(*s)) + ++s; + else + { + namv[namcnt++] = s; + + while (*s && !isspace(*s)) + s++; + + if (isspace(*s)) + *s++ = EOS; + } + } + + if (namcnt) + procln(namcnt, namv); + } + + return 0; +} + + +// +// Parse line +// +void procln(int namc, char ** namv) +{ + int i, j; + + // alias for previous entry + if (namc == 1) + { + fprintf(kfp, "%s\t%d\n", namv[0], kwnum - 1 + 2000); + return; + } + + if (namc < 5) + { + fprintf(stderr, "%d: missing fields\n", lineno); + exit(1); + } + + // output keyword name + if (*namv[0] != '-') + fprintf(kfp, "%s\t%d\n", namv[0], kwnum + 2000); + + printf("/*%4d %-6s*/ {", kwnum, namv[0]); + + printf("%s, %s, %s, ", namv[1], namv[2], namv[3]); + + // enforce little fascist percent signs + if (*namv[4] == '%') + { + for(i=1, j=0; i<25; i++) + { + j <<= 1; + + if (namv[4][i] == '1' || isupper(namv[4][i])) + j++; + } + + printf("0x%06x, ", j); + } + else + printf("%s, ", namv[4]); + + if (namc >= 7 && *namv[6] == '+') + printf("%d, ", kwnum + 1); + else + printf("0, "); + + printf("%s},\n", namv[5]); + + kwnum++; +} + + +void error(char * s, char * s1) +{ + fprintf(stderr, s, s1); + fprintf(stderr, "\n"); + exit(1); +} +