rmac/68kgen.c

140 lines
2.2 KiB
C
Raw Permalink Normal View History

//
// RMAC - Renamed Macro Assembler for all Atari computers
2011-12-27 00:50:27 +02:00
// 68KGEN.C - Tool to Generate 68000 Opcode Table
// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
2011-12-27 00:50:27 +02:00
// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
// Source utilised with the kind permission of Landon Dyer
//
2011-12-27 00:50:27 +02:00
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
2011-12-27 00:50:27 +02:00
#define EOS '\0'
int kwnum = 1; /* current op# for kwgen output */
FILE * kfp; /* keyword file */
2011-12-27 00:50:27 +02:00
int lineno = 0;
// Function prototypes
2011-12-27 00:50:27 +02:00
void error(char *, char *);
void procln(int, char **);
int main(int argc, char ** argv)
{
char * namv[256];
char * s;
2011-12-27 00:50:27 +02:00
int namcnt;
char ln[256];
2012-01-20 00:28:32 +02:00
if ((argc == 2) && ((kfp = fopen(argv[1], "w")) == NULL))
error("Cannot create: %s", argv[1]);
2011-12-27 00:50:27 +02:00
while (fgets(ln, 256, stdin) != NULL)
2011-12-27 00:50:27 +02:00
{
lineno++; /* bump line# */
2012-01-20 00:28:32 +02:00
2011-12-27 00:50:27 +02:00
if (*ln == '#') /* ignore comments */
continue;
/*
* Tokenize line (like the way "argc, argv" works)
* and pass it to the parser.
*/
namcnt = 0;
s = ln;
2011-12-27 00:50:27 +02:00
while (*s)
{
2011-12-27 00:50:27 +02:00
if (isspace(*s))
++s;
else
{
namv[namcnt++] = s;
2011-12-27 00:50:27 +02:00
while (*s && !isspace(*s))
s++;
2011-12-27 00:50:27 +02:00
if (isspace(*s))
*s++ = EOS;
}
}
2011-12-27 00:50:27 +02:00
if (namcnt)
procln(namcnt, namv);
}
2012-01-20 00:28:32 +02:00
return 0;
2011-12-27 00:50:27 +02:00
}
//
// Parse line
//
void procln(int namc, char ** namv)
{
2011-12-27 00:50:27 +02:00
int i, j;
// alias for previous entry
if (namc == 1)
2011-12-27 00:50:27 +02:00
{
fprintf(kfp, "%s\t%d\n", namv[0], kwnum - 1 + 1000);
2011-12-27 00:50:27 +02:00
return;
}
if (namc < 5)
{
fprintf(stderr, "%d: missing fields\n", lineno);
exit(1);
}
// output keyword name
if (*namv[0] != '-')
2011-12-27 00:50:27 +02:00
fprintf(kfp, "%s\t%d\n", namv[0], kwnum + 1000);
printf("/*%4d %-6s*/ {", kwnum, namv[0]);
if (*namv[1] == '!')
printf("CGSPECIAL");
else for(char * s=namv[1], i=0; *s; s++)
2011-12-27 00:50:27 +02:00
printf("%sSIZ%c", (i++ ? "|" : ""), *s);
2012-01-20 00:28:32 +02:00
2011-12-27 00:50:27 +02:00
printf(", %s, %s, ", namv[2], namv[3]);
// enforce little fascist percent signs
if (*namv[4] == '%')
2011-12-27 00:50:27 +02:00
{
for(i=1, j=0; i<17; i++)
2011-12-27 00:50:27 +02:00
{
j <<= 1;
if (namv[4][i] == '1' || isupper(namv[4][i]))
j++;
2011-12-27 00:50:27 +02:00
}
2011-12-27 00:50:27 +02:00
printf("0x%04x, ", j);
}
else
printf("%s, ", namv[4]);
2011-12-27 00:50:27 +02:00
if (namc == 7 && *namv[6] == '+')
printf("%d, ", kwnum + 1);
else
printf("0, ");
2011-12-27 00:50:27 +02:00
printf("%s},\n", namv[5]);
kwnum++;
2011-12-27 00:50:27 +02:00
}
2012-01-20 00:28:32 +02:00
void error(char * s, char * s1)
{
2011-12-27 00:50:27 +02:00
fprintf(stderr, s, s1);
fprintf(stderr, "\n");
exit(1);
}