1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 02:30:44 +00:00

Redesigned GEOS VLIR linking:

- No more post-linking with resource compiler, rather ld65 directly creates the VLIR CVT file.
- No more dynamic linker config creation, rather the built-in 'geos' config is usable both for SEQ CVT and VLIR CVT files.

ToDos:
- Have ld65 accept alignment to $FD.
- Adjust docs / samples.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5314 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
ol.sc 2011-12-26 22:54:04 +00:00
parent 1947d15c48
commit d810ed97d2
4 changed files with 646 additions and 647 deletions

View File

@ -7,7 +7,7 @@
.export _exit .export _exit
.export __STARTUP__ : absolute = 1 ; Mark as startup .export __STARTUP__ : absolute = 1 ; Mark as startup
.import __RAM_START__, __RAM_SIZE__ ; Linker generated .import __VLIR0_START__, __VLIR0_SIZE__ ; Linker generated
.import __STACKSIZE__ ; Linker generated .import __STACKSIZE__ ; Linker generated
.import initlib, donelib .import initlib, donelib
.import callmain .import callmain
@ -26,9 +26,9 @@
; Setup stack ; Setup stack
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #<(__VLIR0_START__ + __VLIR0_SIZE__ + __STACKSIZE__)
sta sp sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) lda #>(__VLIR0_START__ + __VLIR0_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr sta sp+1 ; Set argument stack ptr
; Call module constructors ; Call module constructors

View File

@ -1,15 +1,11 @@
/* GEOS resource compiler
/*
GEOS resource compiler
by Maciej 'YTM/Elysium' Witkowiak by Maciej 'YTM/Elysium' Witkowiak
see GEOSLib documentation for license info see GEOSLib documentation for license info
*/ */
/* /* - make it work, then do it better
- make it work, then do it better
- more or less comments? it was hard to code, should be even harder to - more or less comments? it was hard to code, should be even harder to
understand =D understand =D
- add loadable icons feature (binary - 63 bytes) - add loadable icons feature (binary - 63 bytes)
@ -25,156 +21,139 @@
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include "grc65.h"
/* common stuff */ /* common stuff */
#include "fname.h" #include "fname.h"
#include "abend.h" #include "abend.h"
#include "chartype.h" #include "chartype.h"
#include "xmalloc.h" #include "xmalloc.h"
void VLIRLinker(int argc, char *argv[]) { /* I hope that no one will be able to create a .grc bigger than this... */
FILE *outCVT, *input; #define BLOODY_BIG_BUFFER 65000
unsigned char *buffer;
unsigned char vlirtabt[127];
unsigned char vlirtabs[127];
int i,j,lastarg;
unsigned l;
int bytes;
int blocks,rest;
i=2; /* there are no 6MB GEOS binaries... I hope! */
#define THIS_BUFFER_IS_SOOO_HUGE 6000000
/* check if we know enough */
if (argc<4) struct menuitem {
AbEnd("too few arguments, required [out] [cvthead] [vlir0] ...\n"); char *name;
char *type;
char *target;
struct menuitem *next;
};
/* first open and copy CVT header */ struct menu {
char *name;
int top, left;
int bot, right;
char *type;
struct menuitem *item;
};
outCVT = fopen(argv[i],"wb+"); struct appheader {
if (outCVT==NULL) int year, month, day, hour, min;
AbEnd("can't open output:%s\n",strerror(errno)); int mode;
int dostype;
int geostype;
int structure;
char *dosname;
char *classname;
char *version;
char *author;
char *info;
};
++i; const char *mainToken[] = {"MENU", "HEADER", "ICON", "DIALOG", "VLIR", ""};
input = fopen(argv[i],"rb");
if (input==NULL)
AbEnd("can't open input:%s\n",strerror(errno));
buffer = xmalloc(THIS_BUFFER_IS_SOOO_HUGE); const char *hdrFTypes[] = {"APPLICATION", "AUTO_EXEC", "DESK_ACC", "ASSEMBLY",
memset(buffer,0,THIS_BUFFER_IS_SOOO_HUGE); "DISK_DEVICE", "PRINTER", "SYSTEM", ""};
bytes = fread(buffer,1,1024,input); const char *hdrFields[] = {"author", "info", "date", "dostype", "mode", "structure", ""};
fclose(input);
if (bytes!=508)
AbEnd("%s is not a cvt header\n",argv[i]);
fwrite(buffer,1,bytes,outCVT); const char *hdrDOSTp[] = {"seq", "SEQ", "prg", "PRG", "usr", "USR", ""};
/* now put 254 bytes of VLIR table, to update later */ const char *hdrStructTp[] = {"seq", "SEQ", "vlir", "VLIR", ""};
/* clear out things */ const char *hdrModes[] = {"any", "40only", "80only", "c64only", ""};
memset(buffer,0,512);
fwrite(buffer,1,254,outCVT); const int BSWTab[] = {0, 0x005, 0x007, 0x00b, 0x011, 0x017, 0x01d, 0x023,
for (l=0;l<sizeof(vlirtabt)/sizeof(vlirtabt[0]);l++) { 0x025, 0x029, 0x02d, 0x033, 0x039, 0x03c, 0x041, 0x043, 0x04a, 0x04f,
vlirtabt[l]=0; 0x052, 0x056, 0x05a, 0x05f, 0x063, 0x068, 0x06d, 0x072, 0x077, 0x079,
vlirtabs[l]=0; 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;
int forceFlag = 0;
char outputCMode[2] = "w";
char outputSMode[2] = "w";
void printUsage(void) {
printf("Usage: %s [options] file\n"
"Options:\n"
"\t-h, -?\t\tthis help\n"
"\t-f\t\tforce writting files\n"
"\t-o name\t\tname C output file\n"
"\t-s name\t\tname asm output file\n",
ProgName);
} }
/* scan arguments for the last one that is not blank or nonexistant */
j=argc;
lastarg=argc-1;
while (j!=3) {
--j;
if ((strcmp(argv[j],"blank")==0)||(strcmp(argv[j],"noexist")==0))
--lastarg;
}
/* now read all VLIR chains, align to 254 bytes */
++i;
j=0;
while (i!=argc) {
if (strcmp(argv[i],"blank")==0) {
vlirtabt[j]=0; vlirtabs[j]=0; }
else if (strcmp(argv[i],"noexist")==0) {
vlirtabt[j]=0; vlirtabs[j]=0xff; }
else {
memset(buffer,0,bytes+512);
input = fopen(argv[i],"rb");
if (input==NULL)
AbEnd("couldn't open %s:%s\n",argv[i],strerror(errno));
bytes = fread(buffer,1,THIS_BUFFER_IS_SOOO_HUGE,input);
fclose(input);
if (bytes==0)
AbEnd("couldn't read %s:%s\n",argv[i],strerror(errno));
blocks = bytes / 254;
rest = bytes % 254;
if (rest==0) {
rest = 255;
--blocks;
} else {
++rest;
}
vlirtabt[j]=blocks+1; vlirtabs[j]=rest;
/* do not pad the last chain - it doesn't change or break anything
but filesize in bytes of .cvt will be identical to native cvt */
if (i==lastarg)
fwrite(buffer,1,bytes,outCVT);
else
fwrite(buffer,1,(blocks+1)*254,outCVT);
}
++j;
++i;
}
free(buffer);
/* now rewind and update VLIR table */
fflush(outCVT);
fseek(outCVT,508,SEEK_SET);
for (l=0;l<sizeof(vlirtabt)/sizeof(vlirtabt[0]);l++) {
fputc(vlirtabt[l],outCVT);
fputc(vlirtabs[l],outCVT);
}
fclose(outCVT);
exit(EXIT_SUCCESS);
}
void printCHeader(void) { void printCHeader(void) {
fprintf(outputCFile, "\n/*\n\tThis file was generated by GEOS Resource Compiler\n" fprintf(outputCFile,
"\n\tDO NOT EDIT! Any changes will be lost!\n" "//\n"
"\n\tEdit proper resource file instead\n" "//\tThis file was generated by GEOS Resource Compiler\n"
"\n*/\n\n"); "//\n"
"//\tDO NOT EDIT! Any changes will be lost!\n"
"//\n"
"//\tEdit proper resource file instead\n"
"//\n\n");
} }
void printSHeader(void) { void printSHeader(void) {
fprintf(outputSFile, "\n;\n;\tThis file was generated by GEOS Resource Compiler\n;" fprintf(outputSFile,
"\n;\tDO NOT EDIT! Any changes will be lost!\n;" ";\n"
"\n;\tEdit proper resource file instead\n;" ";\tThis file was generated by GEOS Resource Compiler\n"
"\n;\n\n"); ";\n"
";\tDO NOT EDIT! Any changes will be lost!\n"
";\n"
";\tEdit proper resource file instead\n"
";\n\n");
} }
void printVHeader (void) {
fprintf(outputVFile, "\n#\n#\tThis file was generated by GEOS Resource Compiler\n#"
"\n#\tDO NOT EDIT! Any changes will be lost!\n#"
"\n#\tEdit proper resource file instead\n#"
"\n#\tLook at end of this file to find commandline that must be used\n"
"#\tto invoke ld65 and grc65 (as VLIR linker)\n#"
"\n#\n\n");
}
void openCFile(void) { void openCFile(void) {
if ((CFnum == 0) && (forceFlag == 0)) { if ((CFnum == 0) && (forceFlag == 0)) {
/* test if file exists already and no forcing*/ /* test if file exists already and no forcing*/
if ((outputCFile = fopen(outputCName,"r")) != 0) if ((outputCFile = fopen(outputCName,"r")) != 0)
AbEnd("file %s already exists, aborting\n", outputCName); AbEnd("file %s already exists, aborting\n", outputCName);
} }
if ((outputCFile = fopen (outputCName,outputCMode))==0)
if ((outputCFile = fopen(outputCName,outputCMode)) == 0) {
AbEnd("can't open file %s for writing: %s\n", outputCName, strerror(errno)); AbEnd("can't open file %s for writing: %s\n", outputCName, strerror(errno));
}
if (CFnum == 0) { if (CFnum == 0) {
outputCMode[0] = 'a'; outputCMode[0] = 'a';
printCHeader(); printCHeader();
@ -182,14 +161,19 @@ void openCFile (void) {
} }
} }
void openSFile(void) { void openSFile(void) {
if ((SFnum == 0) && (forceFlag == 0)) { if ((SFnum == 0) && (forceFlag == 0)) {
/* test if file exists already and no forcing*/ /* test if file exists already and no forcing*/
if ((outputSFile = fopen(outputSName,"r")) != 0) if ((outputSFile = fopen(outputSName,"r")) != 0)
AbEnd("file %s already exists, aborting\n", outputSName); AbEnd("file %s already exists, aborting\n", outputSName);
} }
if ((outputSFile = fopen (outputSName,outputSMode))==0)
if ((outputSFile = fopen(outputSName, outputSMode)) == 0) {
AbEnd("can't open file %s for writing: %s\n", outputSName, strerror(errno)); AbEnd("can't open file %s for writing: %s\n", outputSName, strerror(errno));
}
if (SFnum == 0) { if (SFnum == 0) {
outputSMode[0] = 'a'; outputSMode[0] = 'a';
printSHeader(); printSHeader();
@ -197,34 +181,9 @@ void openSFile (void) {
} }
} }
void openVFile (void) {
if ((VFnum==0) && (forceFlag==0)) {
/* test if file exists already and no forcing*/
if ((outputVFile = fopen (outputVName,"r"))!=0)
AbEnd("file %s already exists, aborting\n", outputVName);
}
if ((outputVFile = fopen (outputVName,outputVMode))==0)
AbEnd("can't open file %s for writting: %s\n",outputVName,strerror (errno));
if (VFnum==0) {
outputVMode[0]='a';
printVHeader();
VFnum++;
}
}
void printUsage (void) {
printf("Usage: %s [options] file\n"
"Options:\n"
"\t-h, -?\t\tthis help\n"
"\t-f\t\tforce writting files\n"
"\t-o name\t\tname C output file\n"
"\t-s name\t\tname asm output file\n"
"\t-l name\t\tname ld65 config output file (for vlir)\n"
"Or as VLIR linker: %s -vlir output.cvt header [vlir0] ... [blank] ... [vlir_n]\n",
ProgName,ProgName);
}
int findToken(const char **tokenTbl, const char *token) { 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 */ /* takes as input table of tokens and token, returns position in table or -1 if not found */
int a = 0; int a = 0;
@ -232,54 +191,70 @@ int a=0;
if (strcmp(tokenTbl[a], token) == 0) break; if (strcmp(tokenTbl[a], token) == 0) break;
a++; a++;
} }
if (strlen(tokenTbl[a]) == 0) a = -1; if (strlen(tokenTbl[a]) == 0) a = -1;
return a; return a;
} }
char *nextPhrase() { char *nextPhrase() {
return strtok(NULL, "\""); return strtok(NULL, "\"");
} }
char *nextWord() { char *nextWord() {
return strtok(NULL, " "); return strtok(NULL, " ");
} }
void setLen(char *name, unsigned len) { void setLen(char *name, unsigned len) {
if (strlen(name) > len) if (strlen(name) > len)
name[len] = '\0'; name[len] = '\0';
} }
void fillOut(char *name, int len, char *filler) { void fillOut(char *name, int len, char *filler) {
int a; int a;
setLen(name, len); setLen(name, len);
fprintf(outputSFile, ".byte \"%s\"\n\t\t", name); fprintf(outputSFile, "\t.byte \"%s\"\n", name);
a = len - strlen(name);
if (a!=0) { a = strlen(name);
fprintf(outputSFile, ".byte %s", filler); if (a < len) {
while (--a!=0) fprintf(outputSFile, ", %s", filler); fprintf(outputSFile, "\t.res (%i - %i), %s\n", len, a, filler);
fprintf(outputSFile, "\n\t\t");
} }
} }
char *bintos(unsigned char a, char out[7]) { char *bintos(unsigned char a, char out[7]) {
int i=0; int i=0;
for (; i < 8; i++) { for (; i < 8; i++) {
out[7 - i] = ((a & 1) == 0) ? '0' : '1'; out[7 - i] = ((a & 1) == 0) ? '0' : '1';
a = a >> 1; }; a = a >> 1;
}
out[i] = '\0'; out[i] = '\0';
return out; return out;
} }
int getNameSize(const char *word) { int getNameSize(const char *word) {
/* count length of a word using BSW 9 font table */ /* count length of a word using BSW 9 font table */
int a = 0, i = 0; int a = 0, i = 0;
while (word[i] != '\0') { while (word[i] != '\0') {
a+=(BSWTab[word[i]-31] - BSWTab[word[i]-32]); i++; } a += (BSWTab[word[i] - 31] - BSWTab[word[i] - 32]);
i++;
}
return a; return a;
} }
void DoMenu(void) { void DoMenu(void) {
int a, size, tmpsize, item = 0; int a, size, tmpsize, item = 0;
@ -326,8 +301,7 @@ struct menuitem *curItem, *newItem;
curItem->next = NULL; curItem->next = NULL;
/* Count menu sizes */ /* count menu sizes */
size = 0; size = 0;
curItem = myMenu.item; curItem = myMenu.item;
if (strstr(myMenu.type, "HORIZONTAL") != NULL) { if (strstr(myMenu.type, "HORIZONTAL") != NULL) {
@ -336,7 +310,7 @@ struct menuitem *curItem, *newItem;
for (a = 0; a != item; a++) { for (a = 0; a != item; a++) {
size += getNameSize(curItem->name); size += getNameSize(curItem->name);
curItem = curItem->next; curItem = curItem->next;
}; }
} else { } else {
/* menu is VERTICAL, ysize=item*15, count largest xsize of all items +~8? */ /* menu is VERTICAL, ysize=item*15, count largest xsize of all items +~8? */
myMenu.bot = myMenu.top + (14 * item); myMenu.bot = myMenu.top + (14 * item);
@ -344,37 +318,51 @@ struct menuitem *curItem, *newItem;
tmpsize = getNameSize(curItem->name); tmpsize = getNameSize(curItem->name);
size = (size > tmpsize) ? size : tmpsize; size = (size > tmpsize) ? size : tmpsize;
curItem = curItem->next; curItem = curItem->next;
}; }
}; }
myMenu.right = myMenu.left + size - 1; myMenu.right = myMenu.left + size - 1;
curItem = myMenu.item; curItem = myMenu.item;
for (a = 0; a != item; a++) { for (a = 0; a != item; a++) {
/* print prototype only if MENU_ACTION or DYN_SUB_MENU are present in type */ /* 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)) if ((strstr(curItem->type, "MENU_ACTION") != NULL) || (strstr(curItem->type, "DYN_SUB_MENU") != NULL)) {
fprintf(outputCFile, "void %s (void);\n", curItem->target); fprintf(outputCFile,
"void %s (void);\n",
curItem->target);
}
curItem=curItem->next; curItem=curItem->next;
} }
fprintf(outputCFile, "\nconst void %s = {\n\t(char)%i, (char)%i,\n\t(int)%i, (int)%i,\n\t" fprintf(outputCFile,
"(char)(%i | %s),\n", myMenu.name, myMenu.top, myMenu.bot, myMenu.left, "\n"
myMenu.right, item, myMenu.type); "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; curItem = myMenu.item;
for (a = 0; a != item; a++) { for (a = 0; a != item; a++) {
fprintf(outputCFile, "\t%s, (char)%s, (int)", curItem->name, curItem->type); 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)) if ((strstr(curItem->type, "SUB_MENU") != NULL) && (strstr(curItem->type, "DYN_SUB_MENU") == NULL))
fprintf(outputCFile, "&"); fprintf(outputCFile,
fprintf(outputCFile, "%s,\n", curItem->target); "&");
fprintf(outputCFile,
"%s,\n",
curItem->target);
curItem = curItem->next; curItem = curItem->next;
} }
fprintf(outputCFile, "\t};\n\n"); fprintf(outputCFile,
"};\n\n");
if (fclose(outputCFile) != 0) if (fclose(outputCFile) != 0)
AbEnd("error closing %s: %s\n", outputCName, strerror(errno)); AbEnd("error closing %s: %s\n", outputCName, strerror(errno));
} }
void DoHeader(void) { void DoHeader(void) {
time_t t; time_t t;
@ -392,9 +380,14 @@ int a, b;
a = findToken(hdrFTypes, token); a = findToken(hdrFTypes, token);
switch (a) { switch (a) {
case 0: myHead.geostype = 6; break; case 0:
case 1: myHead.geostype = 14; break; myHead.geostype = 6;
default: AbEnd("filetype '%s' is not supported yet\n", token); break;
case 1:
myHead.geostype = 14;
break;
default:
AbEnd("filetype '%s' is not supported yet\n", token);
} }
myHead.dosname = nextPhrase(); myHead.dosname = nextPhrase();
@ -419,8 +412,9 @@ int a, b;
myHead.hour = my_tm->tm_hour; myHead.hour = my_tm->tm_hour;
myHead.min = my_tm->tm_min; myHead.min = my_tm->tm_min;
if (strcmp(nextWord(),"{")!=0) if (strcmp(nextWord(), "{") != 0) {
AbEnd("header '%s' has no opening bracket!\n", myHead.dosname); AbEnd("header '%s' has no opening bracket!\n", myHead.dosname);
}
do { do {
token = nextWord(); token = nextWord();
@ -430,9 +424,11 @@ int a, b;
AbEnd("unknown field '%s' in header '%s'\n", token, myHead.dosname); AbEnd("unknown field '%s' in header '%s'\n", token, myHead.dosname);
break; break;
case 0: /* author */ case 0: /* author */
myHead.author = nextPhrase(); break; myHead.author = nextPhrase();
break;
case 1: /* info */ case 1: /* info */
myHead.info = nextPhrase(); break; myHead.info = nextPhrase();
break;
case 2: /* date */ case 2: /* date */
myHead.year = atoi(nextWord()); myHead.year = atoi(nextWord());
myHead.month = atoi(nextWord()); myHead.month = atoi(nextWord());
@ -455,13 +451,17 @@ int a, b;
case -1: case -1:
AbEnd("unknown mode in header '%s'\n", myHead.dosname); AbEnd("unknown mode in header '%s'\n", myHead.dosname);
case 0: case 0:
myHead.mode = 0x40; break; myHead.mode = 0x40;
break;
case 1: case 1:
myHead.mode = 0x00; break; myHead.mode = 0x00;
break;
case 2: case 2:
myHead.mode = 0xc0; break; myHead.mode = 0xc0;
break;
case 3: case 3:
myHead.mode = 0x80; break; myHead.mode = 0x80;
break;
} }
break; break;
case 5: /* structure */ case 5: /* structure */
@ -470,10 +470,12 @@ int a, b;
AbEnd("unknown structure type in header '%s'\n", myHead.dosname); AbEnd("unknown structure type in header '%s'\n", myHead.dosname);
case 0: case 0:
case 1: case 1:
myHead.structure = 0; break; myHead.structure = 0;
break;
case 2: case 2:
case 3: case 3:
myHead.structure = 1; break; myHead.structure = 1;
break;
} }
break; break;
} }
@ -483,24 +485,38 @@ int a, b;
/* OK, all information is gathered, do flushout */ /* OK, all information is gathered, do flushout */
fprintf(outputSFile, fprintf(outputSFile,
"\t\t\t.segment \"HEADER\"\n\n\t\t.byte %i\n\t\t.word 0\n\t\t", myHead.dostype); "\n"
"\t\t.segment \"DIRENTRY\"\n\n"
"\t.byte %i\n"
"\t.word 0\n", myHead.dostype);
fillOut(myHead.dosname, 16, "$a0"); fillOut(myHead.dosname, 16, "$a0");
fprintf(outputSFile, fprintf(outputSFile,
".word 0\n\t\t.byte %i\n\t\t.byte %i\n\t\t.byte %i, %i, %i, %i, %i\n\n\t\t" "\t.word 0\n"
".word 0\n\t\t.byte \"PRG formatted GEOS file V1.0\"\n\n\t\t.res $c4\n\n\t\t" "\t.byte %i\n"
".byte 3, 21, 63 | $80\n\t\t", "\t.byte %i\n"
myHead.structure, myHead.geostype, myHead.year, myHead.month, myHead.day, "\t.byte %i, %i, %i, %i, %i\n\n"
myHead.hour, myHead.min); "\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);
fprintf(outputSFile,
"\n"
"\t\t.segment \"FILEINFO\"\n\n"
"\t.import __VLIR0_START__, __STARTUP_RUN__\n\n"
"\t.byte 3, 21, 63 | $80\n");
for (a = 0; a != 63; a = a + 3) { for (a = 0; a != 63; a = a + 3) {
fprintf(outputSFile, fprintf(outputSFile,
".byte %%%s, %%%s, %%%s\n\t\t", "\t.byte %%%s, %%%s, %%%s\n",
bintos(icon1[a], i1), bintos(icon1[a+1], i2), bintos(icon1[a+2], i3)); }; bintos(icon1[a], i1), bintos(icon1[a+1], i2), bintos(icon1[a+2], i3));
}
fprintf(outputSFile, fprintf(outputSFile,
"\n\t\t.byte %i, %i, %i\n\t\t.word $0400, $0400-1, $0400\n\n\t\t", "\t.byte %i, %i, %i\n"
"\t.word __VLIR0_START__, __VLIR0_START__ - 1, __STARTUP_RUN__\n\n",
myHead.dostype, myHead.geostype, myHead.structure); myHead.dostype, myHead.geostype, myHead.structure);
fillOut(myHead.classname, 12, "$20"); fillOut(myHead.classname, 12, "$20");
@ -508,106 +524,117 @@ int a, b;
fillOut(myHead.version, 4, "0"); fillOut(myHead.version, 4, "0");
fprintf(outputSFile, fprintf(outputSFile,
".byte 0, 0, 0\n\t\t.byte %i\n\n\t\t", myHead.mode); "\t.byte 0, 0, 0\n"
"\t.byte %i\n\n", myHead.mode);
setLen(myHead.author, 62); setLen(myHead.author, 62);
fprintf(outputSFile, fprintf(outputSFile,
".byte \"%s\"\n\t\t.byte 0\n\t\t.res (63-%i)\n\n\t\t", "\t.byte \"%s\"\n"
"\t.byte 0\n"
"\t.res (63 - %i)\n\n",
myHead.author, (int)(strlen(myHead.author) + 1)); myHead.author, (int)(strlen(myHead.author) + 1));
setLen(myHead.info, 95); setLen(myHead.info, 95);
fprintf(outputSFile, fprintf(outputSFile,
".byte \"%s\"\n\t\t.byte 0\n\t\t.res (96-%i)\n\n", "\t.byte \"%s\"\n"
myHead.info, (int) (strlen(myHead.info)+1)); "\t.byte 0\n\n", myHead.info);
if (fclose (outputSFile) != 0) if (fclose (outputSFile) != 0)
AbEnd("error closing %s: %s\n", outputSName, strerror(errno)); AbEnd("error closing %s: %s\n", outputSName, strerror(errno));
} }
void DoVLIR(void) { void DoVLIR(void) {
char *token; char *token;
char *headname; int record, lastrecord;
int i,numchains,vlirbase; int vlirsize, vlirtable[127];
struct vlirentry {
char *chainname;
int exist;
};
struct vlirentry vlirtable[127]; openSFile();
openVFile(); vlirsize = strtol(nextWord(), NULL, 0);
headname = nextWord(); if (strcmp(nextWord(), "{") != 0) {
vlirbase = strtol(nextWord(),NULL,0);
if (strcmp(nextWord(),"{")!=0)
AbEnd ("VLIR description has no opening bracket!\n"); AbEnd ("VLIR description has no opening bracket!\n");
}
numchains=0; lastrecord = -1;
memset(vlirtable, 0, sizeof(vlirtable));
do { do {
token = nextWord(); token = nextWord();
if (strcmp(token, "}") == 0) break; if (strcmp(token, "}") == 0) break;
numchains++;
if (numchains>127) {
AbEnd("Too many VLIR chains!\n");
}
vlirtable[numchains].chainname=token;
/* for first chain - name header */ record = atoi(token);
if (numchains==1) { if (record < 0 || record > 126) {
fprintf(outputVFile,"MEMORY {\n\tHEADER: start = $204, size = 508, file = \"%s\";\n" AbEnd("VLIR record %i is out of range 0-126.\n", record);
"\tVLIR0: start = $0400, size = $5C00, file = \"%s\";\n",headname,token);
} else {
/* for all other - segment */
/* ignore non-existing segments */
vlirtable[numchains].exist=1;
if ( (strcmp(token,"blank")==0) || (strcmp(token,"noexist")==0) ) {
vlirtable[numchains].exist=0;
fprintf(outputVFile,"#");
} }
fprintf(outputVFile,"\tVLIR%i: start = $%x, size = $%x, file = \"%s\";\n", if (vlirtable[record] == 1) {
numchains-1,vlirbase,0x5c00-vlirbase,token); AbEnd("VLIR record %i is defined twice.\n", record);
} }
vlirtable[record] = 1;
if (record > lastrecord) lastrecord = record;
} while (strcmp(token, "}") != 0); } while (strcmp(token, "}") != 0);
fprintf(outputVFile,"}\n\n");
if (numchains==0) { if (lastrecord == -1) {
AbEnd("There must be at least one VLIR chain.\n"); AbEnd("There must be at least one VLIR record.\n");
};
/* now put segments info */
fprintf(outputVFile,"SEGMENTS {\n\tHEADER: load = HEADER, type = ro;\n"
"\tCODE: load = VLIR0, type = ro;\n"
"\tRODATA: load = VLIR0, type = ro;\n"
"\tDATA: load = VLIR0, type = rw;\n"
"\tBSS: load = VLIR0, type = bss, define = yes;\n\n");
for (i=2;i<=numchains;i++) {
if (vlirtable[i].exist==0) {
fprintf(outputVFile,"#");
} }
fprintf(outputVFile,"\tVLIR%i: load = VLIR%i, type = rw, define = yes;\n",i-1,i-1);
}
fprintf(outputVFile,"}\n");
/* now put usage info */ /* always include record 0 */
fprintf(outputVFile,"\n# ld65 -o output.cvt -C %s file1.o file2.o ...",outputVName); vlirtable[0] = 1;
fprintf(outputVFile,"\n# grc65 -vlir outputname %s",headname);
for (i=1;i<=numchains;i++) {
fprintf(outputVFile," %s",vlirtable[i].chainname);
}
fprintf(outputVFile,"\n");
if (fclose (outputVFile)!=0) /* OK, all information is gathered, do flushout */
AbEnd("error closing %s: %s\n",outputVName,strerror (errno));
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");
}
}
fprintf(outputSFile,
"\n");
if (fclose(outputSFile) != 0)
AbEnd("error closing %s: %s\n", outputSName, strerror(errno));
openCFile();
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));
}
char *filterInput(FILE *F, char *tbl) { char *filterInput(FILE *F, char *tbl) {
/* loads file into buffer filtering it out */ /* loads file into buffer filtering it out */
int a, prevchar = -1, i = 0, bracket = 0, quote = 1; int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
@ -620,13 +647,26 @@ int a, prevchar=-1, i=0, bracket=0, quote=1;
if ((a == '{') || (a == '(')) bracket++; if ((a == '{') || (a == '(')) bracket++;
if ((a == '}') || (a == ')')) bracket--; if ((a == '}') || (a == ')')) bracket--;
} }
if (a==EOF) { tbl[i]='\0'; xrealloc(tbl, i+1); break; }; if (a == EOF) {
tbl[i] = '\0';
xrealloc(tbl, i + 1);
break;
}
if (IsSpace(a)) { if (IsSpace(a)) {
if ((prevchar!=' ') && (prevchar!=-1)) { tbl[i++]=' '; prevchar=' '; } if ((prevchar != ' ') && (prevchar != -1)) {
tbl[i++] = ' ';
prevchar = ' ';
}
} else { } else {
if (a==';' && quote) { do { a = getc (F); } while (a!='\n'); fseek(F,-1,SEEK_CUR); } if (a == ';' && quote) {
else { do {
tbl[i++]=a; prevchar=a; } a = getc(F);
} while (a != '\n');
fseek(F, -1, SEEK_CUR);
} else {
tbl[i++] = a;
prevchar = a;
}
} }
} }
@ -635,6 +675,7 @@ int a, prevchar=-1, i=0, bracket=0, quote=1;
return tbl; return tbl;
} }
void processFile(const char *filename) { void processFile(const char *filename) {
FILE *F; FILE *F;
@ -645,8 +686,9 @@ char *token;
int head = 0; /* number of processed HEADER sections */ int head = 0; /* number of processed HEADER sections */
int vlir = 0; /* number of processed VLIR sections */ int vlir = 0; /* number of processed VLIR sections */
if ((F = fopen (filename,"r"))==0) if ((F = fopen(filename, "r")) == 0) {
AbEnd("can't open file %s for reading: %s\n", filename, strerror(errno)); AbEnd("can't open file %s for reading: %s\n", filename, strerror(errno));
}
str = filterInput(F, xmalloc(BLOODY_BIG_BUFFER)); str = filterInput(F, xmalloc(BLOODY_BIG_BUFFER));
@ -655,8 +697,9 @@ int vlir=0; /* number of processed VLIR sections */
do { do {
if (str != NULL) { if (str != NULL) {
switch (findToken(mainToken, token)) { switch (findToken(mainToken, token)) {
case 0:
case 0: DoMenu(); break; DoMenu();
break;
case 1: case 1:
if (++head != 1) { if (++head != 1) {
AbEnd("more than one HEADER section, aborting.\n"); AbEnd("more than one HEADER section, aborting.\n");
@ -673,20 +716,25 @@ int vlir=0; /* number of processed VLIR sections */
DoVLIR(); DoVLIR();
} }
break; break;
default: AbEnd ("unknown section %s.\n",token); break; default:
AbEnd("unknown section %s.\n",token);
break;
} }
} }
token = nextWord(); token = nextWord();
} while (token != NULL); } while (token != NULL);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int ffile = 0, i = 1; int ffile = 0, i = 1;
ProgName = argv[0]; ProgName = argv[0];
while (i < argc) { while (i < argc) {
const char *arg = argv[i]; const char *arg = argv[i];
if (arg[0] == '-') { if (arg[0] == '-') {
switch (arg[1]) { switch (arg[1]) {
case 'f': case 'f':
@ -698,40 +746,26 @@ int ffile=0, i=1;
case 's': case 's':
outputSName = argv[++i]; outputSName = argv[++i];
break; break;
case 'l':
outputVName=argv[++i];
break;
case 'h': case 'h':
case '?': case '?':
printUsage(); printUsage();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'v': default:
if (strcmp(arg,"-vlir")==0) {
VLIRLinker(argc,argv);
exit (EXIT_SUCCESS);
break;
} else {
AbEnd("unknown option %s\n", arg); AbEnd("unknown option %s\n", arg);
break;
}
default: AbEnd("unknown option %s\n",arg);
} }
} else { } else {
ffile++; ffile++;
if (outputCName==NULL) if (outputCName == NULL) outputCName = MakeFilename(arg, ".h");
outputCName = MakeFilename(arg,".h"); if (outputSName == NULL) outputSName = MakeFilename(arg, ".s");
if (outputSName==NULL)
outputSName = MakeFilename(arg,".s");
if (outputVName==NULL)
outputVName = MakeFilename(arg,".cfg");
processFile(arg); processFile(arg);
} }
i++; i++;
} }
if (ffile == 0) AbEnd("no input file\n"); if (ffile == 0) AbEnd("no input file\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -1,77 +0,0 @@
/* I hope that no one will be able to create a .grc bigger than this... */
#define BLOODY_BIG_BUFFER 65000
/* there are no 6MB GEOS binaries... I hope! */
#define THIS_BUFFER_IS_SOOO_HUGE 6000000
struct menuitem {
char *name;
char *type;
char *target;
struct menuitem *next; };
struct menu {
char *name;
int top, left;
int bot, right;
char *type;
struct menuitem *item; };
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; };
const char *mainToken[] = {
"MENU", "HEADER", "ICON", "DIALOG", "VLIR", "" };
const char *hdrFTypes[] = {
"APPLICATION", "AUTO_EXEC", "DESK_ACC", "ASSEMBLY", "DISK_DEVICE", "PRINTER", "SYSTEM", "" };
const char *hdrFields[] = {
"author", "info", "date", "dostype", "mode", "structure", "" };
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, *outputVName=NULL;
FILE *outputCFile, *outputSFile, *outputVFile;
int CFnum=0, SFnum=0, VFnum=0;
int forceFlag=0;
char outputCMode[2]="w";
char outputSMode[2]="w";
char outputVMode[2]="w";

View File

@ -1,22 +1,64 @@
SYMBOLS { SYMBOLS {
__STACKSIZE__: type = weak, value = $0400; # 1k stack __STACKSIZE__: type = weak, value = $0400; # 1k stack
__OVERLAYSIZE__: type = weak, value = $0000; # no overlays by default
__OVERLAYADDR__: type = weak, value = $6000 - __OVERLAYSIZE__;
} }
MEMORY { MEMORY {
ZP: file = "", define = yes, start = $0058, size = $0028; CVT: file = %O, start = $0, size = $80000;
HEADER: file = %O, start = $0204, size = $01FC; ZP: define = yes, start = $58, size = $1A + $06;
RAM: file = %O, define = yes, start = $0400, size = $5C00 - __STACKSIZE__; VLIR0: define = yes, start = $0400, size = __OVERLAYADDR__ - __STACKSIZE__ - $0400;
VLIR1: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR2: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR3: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR4: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR5: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR6: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR7: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR8: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR9: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR10: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR11: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR12: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR13: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR14: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR15: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR16: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR17: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR18: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
VLIR19: define = yes, start = __OVERLAYADDR__, size = __OVERLAYSIZE__;
} }
SEGMENTS { SEGMENTS {
HEADER: load = HEADER, type = ro; ZEROPAGE: type = zp, load = ZP;
STARTUP: load = RAM, type = ro; EXTZP: type = zp, load = ZP;
LOWCODE: load = RAM, type = ro, optional = yes; DIRENTRY: type = ro, load = CVT, align = $FE;
INIT: load = RAM, type = ro, define = yes, optional = yes; FILEINFO: type = ro, load = CVT, align = $FE;
CODE: load = RAM, type = ro; RECORDS: type = ro, load = CVT, align = $FE, optional = yes;
RODATA: load = RAM, type = ro; STARTUP: type = ro, run = VLIR0, load = CVT, align_load = $FE, define = yes;
DATA: load = RAM, type = rw; LOWCODE: type = ro, run = VLIR0, load = CVT, optional = yes;
BSS: load = RAM, type = bss, define = yes; INIT: type = ro, run = VLIR0, load = CVT, define = yes, optional = yes;
ZEROPAGE: load = ZP, type = zp; CODE: type = ro, run = VLIR0, load = CVT;
EXTZP: load = ZP, type = zp; RODATA: type = ro, run = VLIR0, load = CVT;
DATA: type = rw, run = VLIR0, load = CVT;
BSS: type = bss, load = VLIR0, define = yes;
OVERLAY1: type = ro, run = VLIR1, load = CVT, align_load = $FE, optional = yes;
OVERLAY2: type = ro, run = VLIR2, load = CVT, align_load = $FE, optional = yes;
OVERLAY3: type = ro, run = VLIR3, load = CVT, align_load = $FE, optional = yes;
OVERLAY4: type = ro, run = VLIR4, load = CVT, align_load = $FE, optional = yes;
OVERLAY5: type = ro, run = VLIR5, load = CVT, align_load = $FE, optional = yes;
OVERLAY6: type = ro, run = VLIR6, load = CVT, align_load = $FE, optional = yes;
OVERLAY7: type = ro, run = VLIR7, load = CVT, align_load = $FE, optional = yes;
OVERLAY8: type = ro, run = VLIR8, load = CVT, align_load = $FE, optional = yes;
OVERLAY9: type = ro, run = VLIR9, load = CVT, align_load = $FE, optional = yes;
OVERLAY10: type = ro, run = VLIR10, load = CVT, align_load = $FE, optional = yes;
OVERLAY11: type = ro, run = VLIR11, load = CVT, align_load = $FE, optional = yes;
OVERLAY12: type = ro, run = VLIR12, load = CVT, align_load = $FE, optional = yes;
OVERLAY13: type = ro, run = VLIR13, load = CVT, align_load = $FE, optional = yes;
OVERLAY14: type = ro, run = VLIR14, load = CVT, align_load = $FE, optional = yes;
OVERLAY15: type = ro, run = VLIR15, load = CVT, align_load = $FE, optional = yes;
OVERLAY16: type = ro, run = VLIR16, load = CVT, align_load = $FE, optional = yes;
OVERLAY17: type = ro, run = VLIR17, load = CVT, align_load = $FE, optional = yes;
OVERLAY18: type = ro, run = VLIR18, load = CVT, align_load = $FE, optional = yes;
OVERLAY19: type = ro, run = VLIR19, load = CVT, align_load = $FE, optional = yes;
} }
FEATURES { FEATURES {
CONDES: segment = INIT, CONDES: segment = INIT,