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