2011-12-26 22:54:04 +00:00
|
|
|
/* GEOS resource compiler
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
by Maciej 'YTM/Elysium' Witkowiak
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
see GEOSLib documentation for license info
|
2000-06-22 21:00:33 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
/* - make it work, then do it better
|
|
|
|
- more or less comments? it was hard to code, should be even harder to
|
|
|
|
understand =D
|
|
|
|
- add loadable icons feature (binary - 63 bytes)
|
2000-06-22 21:00:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* - err, maybe free allocated memory, huh? (who cares, it's just a little prog...)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2002-12-17 09:10:57 +00:00
|
|
|
/* common stuff */
|
|
|
|
#include "fname.h"
|
|
|
|
#include "abend.h"
|
|
|
|
#include "chartype.h"
|
2009-09-24 15:05:48 +00:00
|
|
|
#include "xmalloc.h"
|
2002-07-12 16:36:05 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
/* I hope that no one will be able to create a .grc bigger than this... */
|
|
|
|
#define BLOODY_BIG_BUFFER 65000
|
2002-07-12 16:36:05 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
/* there are no 6MB GEOS binaries... I hope! */
|
|
|
|
#define THIS_BUFFER_IS_SOOO_HUGE 6000000
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
struct menuitem {
|
|
|
|
char *name;
|
|
|
|
char *type;
|
|
|
|
char *target;
|
|
|
|
struct menuitem *next;
|
|
|
|
};
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
struct menu {
|
|
|
|
char *name;
|
|
|
|
int top, left;
|
|
|
|
int bot, right;
|
|
|
|
char *type;
|
|
|
|
struct menuitem *item;
|
|
|
|
};
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
struct appheader {
|
|
|
|
int year, month, day, hour, min;
|
|
|
|
int mode;
|
|
|
|
int dostype;
|
|
|
|
int geostype;
|
|
|
|
int structure;
|
|
|
|
char *dosname;
|
|
|
|
char *classname;
|
|
|
|
char *version;
|
|
|
|
char *author;
|
|
|
|
char *info;
|
2011-12-27 01:11:22 +00:00
|
|
|
char *icon;
|
2011-12-26 22:54:04 +00:00
|
|
|
};
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
const char *mainToken[] = {"MENU", "HEADER", "ICON", "DIALOG", "VLIR", ""};
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
const char *hdrFTypes[] = {"APPLICATION", "AUTO_EXEC", "DESK_ACC", "ASSEMBLY",
|
|
|
|
"DISK_DEVICE", "PRINTER", "SYSTEM", ""};
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-27 01:11:22 +00:00
|
|
|
const char *hdrFields[] = {"author", "info", "date", "dostype", "mode", "structure", "icon", ""};
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
const char *hdrDOSTp[] = {"seq", "SEQ", "prg", "PRG", "usr", "USR", ""};
|
|
|
|
|
|
|
|
const char *hdrStructTp[] = {"seq", "SEQ", "vlir", "VLIR", ""};
|
|
|
|
|
|
|
|
const char *hdrModes[] = {"any", "40only", "80only", "c64only", ""};
|
|
|
|
|
|
|
|
const int BSWTab[] = {0, 0x005, 0x007, 0x00b, 0x011, 0x017, 0x01d, 0x023,
|
|
|
|
0x025, 0x029, 0x02d, 0x033, 0x039, 0x03c, 0x041, 0x043, 0x04a, 0x04f,
|
|
|
|
0x052, 0x056, 0x05a, 0x05f, 0x063, 0x068, 0x06d, 0x072, 0x077, 0x079,
|
|
|
|
0x07c, 0x080, 0x084, 0x088, 0x08e, 0x094, 0x09a, 0x09f, 0x0a4, 0x0a9,
|
|
|
|
0x0ad, 0x0b1, 0x0b6, 0x0bc, 0x0be, 0x0c2, 0x0c8, 0x0cc, 0x0d4, 0x0da,
|
|
|
|
0x0e0, 0x0e5, 0x0eb, 0x0f0, 0x0f5, 0x0f9, 0x0fe, 0x104, 0x10c, 0x112,
|
|
|
|
0x118, 0x11e, 0x121, 0x129, 0x12c, 0x132, 0x13a, 0x13e, 0x143, 0x148,
|
|
|
|
0x14d, 0x152, 0x157, 0x15a, 0x15f, 0x164, 0x166, 0x168, 0x16d, 0x16f,
|
|
|
|
0x177, 0x17c, 0x182, 0x187, 0x18c, 0x18f, 0x193, 0x196, 0x19b, 0x1a1,
|
|
|
|
0x1a9, 0x1af, 0x1b4, 0x1ba, 0x1be, 0x1c0, 0x1c4, 0x1ca, 0x1d2, 0x1dd};
|
|
|
|
|
|
|
|
const unsigned char icon1[] = {255, 255, 255, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 128, 0, 1,
|
|
|
|
128, 0, 1, 128, 0, 1, 255, 255, 255};
|
|
|
|
|
|
|
|
char *ProgName; /* for AbEnd, later remove and use common/cmdline.h */
|
|
|
|
|
|
|
|
char *outputCName = NULL, *outputSName = NULL;
|
|
|
|
FILE *outputCFile, *outputSFile;
|
|
|
|
int CFnum = 0, SFnum = 0;
|
|
|
|
char outputCMode[2] = "w";
|
|
|
|
char outputSMode[2] = "w";
|
|
|
|
|
|
|
|
|
|
|
|
void printUsage(void) {
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2005-03-24 20:08:41 +00:00
|
|
|
printf("Usage: %s [options] file\n"
|
|
|
|
"Options:\n"
|
|
|
|
"\t-h, -?\t\tthis help\n"
|
|
|
|
"\t-o name\t\tname C output file\n"
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t-s name\t\tname asm output file\n",
|
|
|
|
ProgName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void printCHeader(void) {
|
|
|
|
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"//\n"
|
2011-12-27 01:11:22 +00:00
|
|
|
"//\tThis file was generated by the GEOS Resource Compiler\n"
|
2011-12-26 22:54:04 +00:00
|
|
|
"//\n"
|
|
|
|
"//\tDO NOT EDIT! Any changes will be lost!\n"
|
|
|
|
"//\n"
|
2011-12-27 01:11:22 +00:00
|
|
|
"//\tEdit proper resource file instead.\n"
|
2011-12-26 22:54:04 +00:00
|
|
|
"//\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void printSHeader(void) {
|
|
|
|
|
|
|
|
fprintf(outputSFile,
|
|
|
|
";\n"
|
2011-12-27 01:11:22 +00:00
|
|
|
";\tThis file was generated by the GEOS Resource Compiler\n"
|
2011-12-26 22:54:04 +00:00
|
|
|
";\n"
|
|
|
|
";\tDO NOT EDIT! Any changes will be lost!\n"
|
|
|
|
";\n"
|
2011-12-27 01:11:22 +00:00
|
|
|
";\tEdit proper resource file instead.\n"
|
2011-12-26 22:54:04 +00:00
|
|
|
";\n\n");
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void openCFile(void) {
|
|
|
|
|
|
|
|
if ((outputCFile = fopen(outputCName,outputCMode)) == 0) {
|
|
|
|
AbEnd("can't open file %s for writing: %s\n", outputCName, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CFnum == 0) {
|
|
|
|
outputCMode[0] = 'a';
|
|
|
|
printCHeader();
|
|
|
|
CFnum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void openSFile(void) {
|
|
|
|
|
|
|
|
if ((outputSFile = fopen(outputSName, outputSMode)) == 0) {
|
|
|
|
AbEnd("can't open file %s for writing: %s\n", outputSName, strerror(errno));
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
if (SFnum == 0) {
|
|
|
|
outputSMode[0] = 'a';
|
|
|
|
printSHeader();
|
|
|
|
SFnum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int findToken(const char **tokenTbl, const char *token) {
|
|
|
|
|
|
|
|
/* takes as input table of tokens and token, returns position in table or -1 if not found */
|
|
|
|
int a = 0;
|
|
|
|
|
|
|
|
while (strlen(tokenTbl[a]) != 0) {
|
|
|
|
if (strcmp(tokenTbl[a], token) == 0) break;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(tokenTbl[a]) == 0) a = -1;
|
2000-06-22 21:00:33 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
char *nextPhrase() {
|
|
|
|
return strtok(NULL, "\"");
|
2011-12-26 22:54:04 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
char *nextWord() {
|
|
|
|
return strtok(NULL, " ");
|
2011-12-26 22:54:04 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void setLen(char *name, unsigned len) {
|
|
|
|
if (strlen(name) > len)
|
|
|
|
name[len] = '\0';
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
void fillOut(char *name, int len, char *filler) {
|
|
|
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
setLen(name, len);
|
|
|
|
fprintf(outputSFile, "\t.byte \"%s\"\n", name);
|
|
|
|
|
|
|
|
a = strlen(name);
|
|
|
|
if (a < len) {
|
|
|
|
fprintf(outputSFile, "\t.res (%i - %i), %s\n", len, a, filler);
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
|
2002-12-17 09:10:57 +00:00
|
|
|
char *bintos(unsigned char a, char out[7]) {
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
for (; i < 8; i++) {
|
|
|
|
out[7 - i] = ((a & 1) == 0) ? '0' : '1';
|
|
|
|
a = a >> 1;
|
|
|
|
}
|
|
|
|
out[i] = '\0';
|
|
|
|
|
|
|
|
return out;
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
int getNameSize(const char *word) {
|
|
|
|
|
|
|
|
/* count length of a word using BSW 9 font table */
|
|
|
|
int a = 0, i = 0;
|
|
|
|
|
|
|
|
while (word[i] != '\0') {
|
|
|
|
a += (BSWTab[word[i] - 31] - BSWTab[word[i] - 32]);
|
|
|
|
i++;
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void DoMenu(void) {
|
|
|
|
|
|
|
|
int a, size, tmpsize, item = 0;
|
|
|
|
char *token;
|
|
|
|
char namebuff[255] = "";
|
|
|
|
struct menu myMenu;
|
|
|
|
struct menuitem *curItem, *newItem;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
openCFile();
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
myMenu.name = nextWord();
|
|
|
|
myMenu.left = atoi(nextWord());
|
|
|
|
myMenu.top = atoi(nextWord());
|
|
|
|
myMenu.type = nextWord();
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
if (strcmp(nextWord(), "{") != 0) {
|
|
|
|
AbEnd("menu '%s' description has no opening bracket!\n", myMenu.name);
|
|
|
|
}
|
2009-09-24 15:05:48 +00:00
|
|
|
curItem = xmalloc(sizeof(struct menuitem));
|
2011-12-26 22:54:04 +00:00
|
|
|
myMenu.item = curItem;
|
2000-06-22 21:00:33 +00:00
|
|
|
do {
|
2011-12-26 22:54:04 +00:00
|
|
|
token = nextWord();
|
|
|
|
if (strcmp(token, "}") == 0) break;
|
|
|
|
if (token[strlen(token) - 1] != '"') {
|
|
|
|
strcpy(namebuff, token);
|
|
|
|
do {
|
|
|
|
token = nextWord();
|
|
|
|
strcat(namebuff, " ");
|
|
|
|
strcat(namebuff, token);
|
|
|
|
} while (token[strlen(token) - 1] != '"');
|
|
|
|
token = xmalloc(strlen(namebuff));
|
|
|
|
strcpy(token, namebuff);
|
|
|
|
}
|
|
|
|
curItem->name = token;
|
|
|
|
curItem->type = nextWord();
|
|
|
|
curItem->target = nextWord();
|
|
|
|
newItem = xmalloc(sizeof(struct menuitem));
|
|
|
|
curItem->next = newItem;
|
|
|
|
curItem = newItem;
|
|
|
|
item++;
|
|
|
|
} while (strcmp(token, "}") != 0);
|
|
|
|
if (item == 0) AbEnd("menu '%s' has 0 items!\n", myMenu.name);
|
|
|
|
if (item > 31) AbEnd("menu '%s' has too many items!\n", myMenu.name);
|
|
|
|
|
|
|
|
curItem->next = NULL;
|
|
|
|
|
|
|
|
/* count menu sizes */
|
|
|
|
size = 0;
|
|
|
|
curItem = myMenu.item;
|
|
|
|
if (strstr(myMenu.type, "HORIZONTAL") != NULL) {
|
|
|
|
/* menu is HORIZONTAL, ysize=15, sum xsize of all items +~8?*/
|
|
|
|
myMenu.bot = myMenu.top + 15;
|
|
|
|
for (a = 0; a != item; a++) {
|
|
|
|
size += getNameSize(curItem->name);
|
|
|
|
curItem = curItem->next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* menu is VERTICAL, ysize=item*15, count largest xsize of all items +~8? */
|
|
|
|
myMenu.bot = myMenu.top + (14 * item);
|
|
|
|
for (a = 0; a != item; a++) {
|
|
|
|
tmpsize = getNameSize(curItem->name);
|
|
|
|
size = (size > tmpsize) ? size : tmpsize;
|
|
|
|
curItem = curItem->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
myMenu.right = myMenu.left + size - 1;
|
|
|
|
|
|
|
|
curItem = myMenu.item;
|
|
|
|
for (a = 0; a != item; a++) {
|
|
|
|
/* print prototype only if MENU_ACTION or DYN_SUB_MENU are present in type */
|
|
|
|
if ((strstr(curItem->type, "MENU_ACTION") != NULL) || (strstr(curItem->type, "DYN_SUB_MENU") != NULL)) {
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"void %s (void);\n",
|
|
|
|
curItem->target);
|
|
|
|
}
|
|
|
|
curItem=curItem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"\n"
|
|
|
|
"const void %s = {\n"
|
|
|
|
"\t(char)%i, (char)%i,\n"
|
|
|
|
"\t(int)%i, (int)%i,\n"
|
|
|
|
"\t(char)(%i | %s),\n",
|
|
|
|
myMenu.name, myMenu.top, myMenu.bot, myMenu.left, myMenu.right, item, myMenu.type);
|
|
|
|
|
|
|
|
curItem = myMenu.item;
|
|
|
|
for (a = 0; a != item; a++) {
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"\t%s, (char)%s, (int)",
|
|
|
|
curItem->name, curItem->type);
|
|
|
|
if ((strstr(curItem->type, "SUB_MENU") != NULL) && (strstr(curItem->type, "DYN_SUB_MENU") == NULL))
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"&");
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"%s,\n",
|
|
|
|
curItem->target);
|
|
|
|
curItem = curItem->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outputCFile,
|
|
|
|
"};\n\n");
|
|
|
|
|
|
|
|
if (fclose(outputCFile) != 0)
|
|
|
|
AbEnd("error closing %s: %s\n", outputCName, strerror(errno));
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void DoHeader(void) {
|
|
|
|
|
|
|
|
time_t t;
|
|
|
|
struct tm *my_tm;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
struct appheader myHead;
|
|
|
|
char *token;
|
|
|
|
char i1[9], i2[9], i3[9];
|
|
|
|
int a, b;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
openSFile();
|
|
|
|
|
|
|
|
token = nextWord();
|
2000-11-17 10:31:39 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
a = findToken(hdrFTypes, token);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
switch (a) {
|
2011-12-26 22:54:04 +00:00
|
|
|
case 0:
|
|
|
|
myHead.geostype = 6;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
myHead.geostype = 14;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AbEnd("filetype '%s' is not supported yet\n", token);
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
myHead.dosname = nextPhrase();
|
|
|
|
nextPhrase();
|
|
|
|
myHead.classname = nextPhrase();
|
|
|
|
nextPhrase();
|
|
|
|
myHead.version = nextPhrase();
|
|
|
|
|
|
|
|
/* put default values into myHead here */
|
|
|
|
myHead.author = "cc65";
|
|
|
|
myHead.info = "Program compiled with cc65 and GEOSLib.";
|
2011-12-26 22:54:04 +00:00
|
|
|
myHead.dostype = 128 + 3;
|
2002-07-10 18:43:04 +00:00
|
|
|
myHead.structure = 0;
|
2000-06-22 21:00:33 +00:00
|
|
|
myHead.mode = 0;
|
2011-12-27 01:11:22 +00:00
|
|
|
myHead.icon = NULL;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
t = time(NULL);
|
2011-12-26 22:54:04 +00:00
|
|
|
my_tm = localtime(&t);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
myHead.year = my_tm->tm_year;
|
|
|
|
myHead.month = my_tm->tm_mon+1;
|
|
|
|
myHead.day = my_tm->tm_mday;
|
|
|
|
myHead.hour = my_tm->tm_hour;
|
|
|
|
myHead.min = my_tm->tm_min;
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
if (strcmp(nextWord(), "{") != 0) {
|
|
|
|
AbEnd("header '%s' has no opening bracket!\n", myHead.dosname);
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
do {
|
2011-12-26 22:54:04 +00:00
|
|
|
token = nextWord();
|
|
|
|
if (strcmp(token, "}") == 0) break;
|
|
|
|
switch (a = findToken(hdrFields, token)) {
|
|
|
|
case -1:
|
|
|
|
AbEnd("unknown field '%s' in header '%s'\n", token, myHead.dosname);
|
|
|
|
break;
|
|
|
|
case 0: /* author */
|
|
|
|
myHead.author = nextPhrase();
|
|
|
|
break;
|
|
|
|
case 1: /* info */
|
|
|
|
myHead.info = nextPhrase();
|
|
|
|
break;
|
|
|
|
case 2: /* date */
|
|
|
|
myHead.year = atoi(nextWord());
|
|
|
|
myHead.month = atoi(nextWord());
|
|
|
|
myHead.day = atoi(nextWord());
|
|
|
|
myHead.hour = atoi(nextWord());
|
|
|
|
myHead.min = atoi(nextWord());
|
|
|
|
break;
|
|
|
|
case 3: /* dostype */
|
|
|
|
switch (b = findToken(hdrDOSTp, nextWord())) {
|
|
|
|
case -1:
|
|
|
|
AbEnd("unknown dostype in header '%s'\n", myHead.dosname);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
myHead.dostype = b / 2 + 128 + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: /* mode */
|
|
|
|
switch (b = findToken(hdrModes, nextWord())) {
|
|
|
|
case -1:
|
|
|
|
AbEnd("unknown mode in header '%s'\n", myHead.dosname);
|
|
|
|
case 0:
|
|
|
|
myHead.mode = 0x40;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
myHead.mode = 0x00;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
myHead.mode = 0xc0;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
myHead.mode = 0x80;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: /* structure */
|
|
|
|
switch (b = findToken(hdrStructTp, nextWord())) {
|
|
|
|
case -1:
|
|
|
|
AbEnd("unknown structure type in header '%s'\n", myHead.dosname);
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
myHead.structure = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
myHead.structure = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2011-12-27 01:11:22 +00:00
|
|
|
case 6: /* icon */
|
|
|
|
myHead.icon = nextPhrase();
|
|
|
|
break;
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
2000-11-17 10:31:39 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
} while (strcmp(token, "}") != 0);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
/* OK, all information is gathered, do flushout */
|
|
|
|
|
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\n"
|
|
|
|
"\t\t.segment \"DIRENTRY\"\n\n"
|
|
|
|
"\t.byte %i\n"
|
|
|
|
"\t.word 0\n", myHead.dostype);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fillOut(myHead.dosname, 16, "$a0");
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t.word 0\n"
|
|
|
|
"\t.byte %i\n"
|
|
|
|
"\t.byte %i\n"
|
|
|
|
"\t.byte %i, %i, %i, %i, %i\n\n"
|
|
|
|
"\t.word 0\n"
|
|
|
|
"\t.byte \"PRG formatted GEOS file V1.0\"\n\n",
|
|
|
|
myHead.structure, myHead.geostype,
|
|
|
|
myHead.year, myHead.month, myHead.day, myHead.hour, myHead.min);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fprintf(outputSFile,
|
|
|
|
"\n"
|
|
|
|
"\t\t.segment \"FILEINFO\"\n\n"
|
|
|
|
"\t.import __VLIR0_START__, __STARTUP_RUN__\n\n"
|
|
|
|
"\t.byte 3, 21, 63 | $80\n");
|
|
|
|
|
2011-12-27 01:11:22 +00:00
|
|
|
if (myHead.icon != NULL) {
|
2011-12-26 22:54:04 +00:00
|
|
|
fprintf(outputSFile,
|
2011-12-27 01:11:22 +00:00
|
|
|
"\t.incbin \"%s\", 0, 63\n",
|
|
|
|
myHead.icon);
|
|
|
|
} else {
|
|
|
|
for (a = 0; a != 63; a = a + 3) {
|
|
|
|
fprintf(outputSFile,
|
|
|
|
"\t.byte %%%s, %%%s, %%%s\n",
|
|
|
|
bintos(icon1[a], i1), bintos(icon1[a+1], i2), bintos(icon1[a+2], i3));
|
|
|
|
}
|
2011-12-26 22:54:04 +00:00
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t.byte %i, %i, %i\n"
|
|
|
|
"\t.word __VLIR0_START__, __VLIR0_START__ - 1, __STARTUP_RUN__\n\n",
|
|
|
|
myHead.dostype, myHead.geostype, myHead.structure);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fillOut(myHead.classname, 12, "$20");
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fillOut(myHead.version, 4, "0");
|
2000-11-17 10:31:39 +00:00
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t.byte 0, 0, 0\n"
|
|
|
|
"\t.byte %i\n\n", myHead.mode);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
setLen(myHead.author, 62);
|
2000-06-22 21:00:33 +00:00
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t.byte \"%s\"\n"
|
|
|
|
"\t.byte 0\n"
|
|
|
|
"\t.res (63 - %i)\n\n",
|
|
|
|
myHead.author, (int)(strlen(myHead.author) + 1));
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
setLen(myHead.info, 95);
|
|
|
|
fprintf(outputSFile,
|
2011-12-26 22:54:04 +00:00
|
|
|
"\t.byte \"%s\"\n"
|
|
|
|
"\t.byte 0\n\n", myHead.info);
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
if (fclose (outputSFile) != 0)
|
|
|
|
AbEnd("error closing %s: %s\n", outputSName, strerror(errno));
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void DoVLIR(void) {
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
char *token;
|
|
|
|
int record, lastrecord;
|
|
|
|
int vlirsize, vlirtable[127];
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
openSFile();
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
vlirsize = strtol(nextWord(), NULL, 0);
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
if (strcmp(nextWord(), "{") != 0) {
|
|
|
|
AbEnd ("VLIR description has no opening bracket!\n");
|
|
|
|
}
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
lastrecord = -1;
|
|
|
|
memset(vlirtable, 0, sizeof(vlirtable));
|
2002-07-10 18:43:04 +00:00
|
|
|
|
|
|
|
do {
|
2011-12-26 22:54:04 +00:00
|
|
|
token = nextWord();
|
|
|
|
if (strcmp(token, "}") == 0) break;
|
|
|
|
|
|
|
|
record = atoi(token);
|
|
|
|
if (record < 0 || record > 126) {
|
|
|
|
AbEnd("VLIR record %i is out of range 0-126.\n", record);
|
|
|
|
}
|
|
|
|
if (vlirtable[record] == 1) {
|
|
|
|
AbEnd("VLIR record %i is defined twice.\n", record);
|
|
|
|
}
|
|
|
|
|
|
|
|
vlirtable[record] = 1;
|
|
|
|
if (record > lastrecord) lastrecord = record;
|
|
|
|
} while (strcmp(token, "}") != 0);
|
|
|
|
|
|
|
|
if (lastrecord == -1) {
|
|
|
|
AbEnd("There must be at least one VLIR record.\n");
|
2002-07-10 18:43:04 +00:00
|
|
|
}
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
/* always include record 0 */
|
|
|
|
vlirtable[0] = 1;
|
|
|
|
|
|
|
|
/* OK, all information is gathered, do flushout */
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fprintf(outputSFile,
|
|
|
|
"\n"
|
|
|
|
"\t\t.segment \"RECORDS\"\n\n"
|
|
|
|
"\t.export __OVERLAYSIZE__ : absolute = $%04x\n\n",
|
|
|
|
vlirsize);
|
|
|
|
|
|
|
|
for (record = 0; record <= lastrecord; record++) {
|
|
|
|
if (vlirtable[record] == 1) {
|
|
|
|
fprintf(outputSFile,
|
|
|
|
"\t.import __VLIR%i_START__, __VLIR%i_LAST__\n",
|
|
|
|
record, record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(outputSFile,
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
for (record = 0; record <= lastrecord; record++) {
|
|
|
|
if (vlirtable[record] == 1) {
|
|
|
|
fprintf(outputSFile,
|
|
|
|
"\t.byte .lobyte ((__VLIR%i_LAST__ - __VLIR%i_START__ - 1) / 254) + 1\n"
|
|
|
|
"\t.byte .lobyte ((__VLIR%i_LAST__ - __VLIR%i_START__ - 1) .MOD 254) + 2\n",
|
|
|
|
record, record, record, record);
|
|
|
|
} else {
|
|
|
|
fprintf(outputSFile,
|
|
|
|
"\t.byte $00\n"
|
|
|
|
"\t.byte $FF\n");
|
|
|
|
}
|
2002-07-10 18:43:04 +00:00
|
|
|
}
|
2011-12-26 22:54:04 +00:00
|
|
|
fprintf(outputSFile,
|
|
|
|
"\n");
|
|
|
|
|
|
|
|
if (fclose(outputSFile) != 0)
|
|
|
|
AbEnd("error closing %s: %s\n", outputSName, strerror(errno));
|
|
|
|
|
|
|
|
openCFile();
|
2002-07-10 18:43:04 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
fprintf(outputCFile,
|
|
|
|
"extern void _OVERLAYADDR__;\n"
|
|
|
|
"extern void _OVERLAYSIZE__;\n\n"
|
|
|
|
"#define OVERLAY_ADDR (char*) &_OVERLAYADDR__\n"
|
|
|
|
"#define OVERLAY_SIZE (unsigned)&_OVERLAYSIZE__\n\n");
|
|
|
|
|
|
|
|
if (fclose(outputCFile) != 0)
|
|
|
|
AbEnd("error closing %s: %s\n", outputCName, strerror(errno));
|
2002-07-10 18:43:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
|
|
|
|
char *filterInput(FILE *F, char *tbl) {
|
|
|
|
|
|
|
|
/* loads file into buffer filtering it out */
|
|
|
|
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
while (1) {
|
2011-12-26 22:54:04 +00:00
|
|
|
a = getc(F);
|
|
|
|
if ((a == '\n') || (a == '\015')) a = ' ';
|
|
|
|
if (a == ',' && quote) a = ' ';
|
|
|
|
if (a == '\042') quote =! quote;
|
|
|
|
if (quote) {
|
|
|
|
if ((a == '{') || (a == '(')) bracket++;
|
|
|
|
if ((a == '}') || (a == ')')) bracket--;
|
|
|
|
}
|
|
|
|
if (a == EOF) {
|
|
|
|
tbl[i] = '\0';
|
|
|
|
xrealloc(tbl, i + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (IsSpace(a)) {
|
|
|
|
if ((prevchar != ' ') && (prevchar != -1)) {
|
|
|
|
tbl[i++] = ' ';
|
|
|
|
prevchar = ' ';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (a == ';' && quote) {
|
|
|
|
do {
|
|
|
|
a = getc(F);
|
|
|
|
} while (a != '\n');
|
|
|
|
fseek(F, -1, SEEK_CUR);
|
|
|
|
} else {
|
|
|
|
tbl[i++] = a;
|
|
|
|
prevchar = a;
|
|
|
|
}
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
if (bracket != 0) AbEnd("there are unclosed brackets!\n");
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
return tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
void processFile(const char *filename) {
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
FILE *F;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
char *str;
|
|
|
|
char *token;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
int head = 0; /* number of processed HEADER sections */
|
|
|
|
int vlir = 0; /* number of processed VLIR sections */
|
|
|
|
|
|
|
|
if ((F = fopen(filename, "r")) == 0) {
|
|
|
|
AbEnd("can't open file %s for reading: %s\n", filename, strerror(errno));
|
|
|
|
}
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
str = filterInput(F, xmalloc(BLOODY_BIG_BUFFER));
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
token = strtok(str, " ");
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
do {
|
2011-12-26 22:54:04 +00:00
|
|
|
if (str != NULL) {
|
|
|
|
switch (findToken(mainToken, token)) {
|
|
|
|
case 0:
|
|
|
|
DoMenu();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (++head != 1) {
|
|
|
|
AbEnd("more than one HEADER section, aborting.\n");
|
|
|
|
} else {
|
|
|
|
DoHeader();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: break; /* icon not implemented yet */
|
|
|
|
case 3: break; /* dialog not implemented yet */
|
|
|
|
case 4:
|
|
|
|
if (++vlir != 1) {
|
|
|
|
AbEnd("more than one VLIR section, aborting.\n");
|
|
|
|
} else {
|
|
|
|
DoVLIR();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AbEnd("unknown section %s.\n",token);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
token = nextWord();
|
|
|
|
} while (token != NULL);
|
2000-06-22 21:00:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
2011-12-26 22:54:04 +00:00
|
|
|
int ffile = 0, i = 1;
|
2000-06-22 21:00:33 +00:00
|
|
|
|
2002-12-17 09:10:57 +00:00
|
|
|
ProgName = argv[0];
|
2011-12-26 22:54:04 +00:00
|
|
|
|
2000-06-22 21:00:33 +00:00
|
|
|
while (i < argc) {
|
2011-12-26 22:54:04 +00:00
|
|
|
const char *arg = argv[i];
|
|
|
|
|
|
|
|
if (arg[0] == '-') {
|
|
|
|
switch (arg[1]) {
|
|
|
|
case 'o':
|
|
|
|
outputCName = argv[++i];
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
outputSName = argv[++i];
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
printUsage();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AbEnd("unknown option %s\n", arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ffile++;
|
|
|
|
|
|
|
|
if (outputCName == NULL) outputCName = MakeFilename(arg, ".h");
|
|
|
|
if (outputSName == NULL) outputSName = MakeFilename(arg, ".s");
|
|
|
|
|
|
|
|
processFile(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ffile == 0) AbEnd("no input file\n");
|
2000-06-22 21:00:33 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|