X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=compile.c;h=4360d97b767b317484592741cadef7cae4c7b76c;hb=60a3a6d1fe65dd15507d0e9e9472df4d1e097b89;hp=c501e5b787f2a381735509439d655306705d0f7d;hpb=978168523abcc3e4f06c23df57dc47541cd995ca;p=open-adventure.git diff --git a/compile.c b/compile.c index c501e5b..4360d97 100644 --- a/compile.c +++ b/compile.c @@ -1,13 +1,21 @@ +/* + * The dungeon compiler. Turns adventure.text into a set of C initializers + * defining (mostly) invariant state. A couple of slots are messed with + * at runtime. + */ +#include "sizes.h" + #define LINESIZE 100 #define RTXSIZ 277 #define CLSMAX 12 -#define LOCSIZ 185 #define LINSIZ 12600 #define TRNSIZ 5 #define TABSIZ 330 #define VRBSIZ 35 #define HNTSIZ 20 #define TRVSIZ 885 +#define TOKLEN 5 +#define HINTLEN 5 #include #include @@ -22,11 +30,11 @@ const char advent_to_ascii[] = {0, 32, 33, 34, 39, 40, 41, 42, 43, 44, 45, 46, 6 const char ascii_to_advent[] = {0, 74, 75, 76, 77, 78, 79, 80, 81, 82, 0, 0, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 0, 1, 2, 106, 107, 63, 108, 3, 4, 5, 6, 7, 8, 9, 10, 109, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 110, 111, 112, 113, 114, 115, 116, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 117, 118, 119, 120, 121, 122, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 123, 124, 125, 126, 83}; // Global variables for use in functions below that can gradually disappear as code is cleaned up -long LNLENG; -long LNPOSN; -char INLINE[LINESIZE+1]; -long NEWLOC; -long OLDLOC; +static long LNLENG; +static long LNPOSN; +static char INLINE[LINESIZE+1]; +static long NEWLOC; +static long OLDLOC; // Storage for what comes out of the database long LINUSE; @@ -55,7 +63,7 @@ long ATAB[TABSIZ + 1]; long PLAC[NOBJECTS+1]; long FIXD[NOBJECTS+1]; long ACTSPK[VRBSIZ + 1]; -long HINTS[HNTSIZ + 1][5]; +long HINTS[HNTSIZ + 1][HINTLEN]; bool is_set(long, long); long GETTXT(long, long, long); @@ -73,7 +81,7 @@ void read_hints(FILE*); void read_sound_text(FILE*); void write_0d(FILE*, FILE*, long, char*); void write_1d(FILE*, FILE*, long[], long, char*); -void write_hints(FILE*, FILE*, long[][5], long, long, char*); +void write_hints(FILE*, FILE*, long[][HINTLEN], long, long, char*); void write_files(FILE*, FILE*); bool is_set(long var, long position) @@ -105,7 +113,7 @@ long GETTXT(long SKIP,long ONEWRD, long UPPER) { } TEXT=0; - for (int I=1; I<=5; I++) { + for (int I=1; I<=TOKLEN; I++) { TEXT=TEXT*64; if(LNPOSN > LNLENG || (ONEWRD && INLINE[LNPOSN] == 0)) continue; @@ -260,13 +268,18 @@ int read_database(FILE* database) { * section 6's stuff. CTEXT(N) points to a player-class message. TTEXT is for * section 14. We also clear COND (see description of section 9 for details). */ - for (int I=1; I<=300; I++) { - if(I <= NOBJECTS) PTEXT[I] = 0; - if(I <= RTXSIZ) RTEXT[I] = 0; - if(I <= CLSMAX) CTEXT[I] = 0; - if(I <= NOBJECTS) OBJSND[I] = 0; - if(I <= NOBJECTS) OBJTXT[I] = 0; - if(I > LOCSIZ) break; + for (int I=1; I<=NOBJECTS; I++) { + PTEXT[I] = 0; + OBJSND[I] = 0; + OBJTXT[I] = 0; + } + for (int I=1; I<=RTXSIZ; I++) { + RTEXT[I] = 0; + } + for (int I=1; I<=CLSMAX; I++) { + CTEXT[I] = 0; + } + for (int I=1; I<=LOCSIZ; I++) { STEXT[I] = 0; LTEXT[I] = 0; COND[I] = 0; @@ -500,7 +513,7 @@ void read_sound_text(FILE* database) * to set up ATLOC(N) as the first object at location N, and * LINK(OBJ) as the next object at the same location as OBJ. * (OBJ>NOBJECTS indicates that FIXED(OBJ-NOBJECTS)=LOC; LINK(OBJ) is - * still the correct link to use.) ABB is zeroed; it controls + * still the correct link to use.) game.abbrev is zeroed; it controls * whether the abbreviated description is printed. Counts modulo 5 * unless "LOOK" is used. */ @@ -527,7 +540,7 @@ void write_1d(FILE* c_file, FILE* header_file, long array[], long dim, char* var fprintf(header_file, "extern long %s[%ld];\n", varname, dim); } -void write_hints(FILE* c_file, FILE* header_file, long matrix[][5], long dim1, long dim2, char* varname) +void write_hints(FILE* c_file, FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, char* varname) { fprintf(c_file, "long %s[][%ld] = {\n", varname, dim2); for (int i = 0; i < dim1; ++i) @@ -546,16 +559,17 @@ void write_hints(FILE* c_file, FILE* header_file, long matrix[][5], long dim1, l void write_files(FILE* c_file, FILE* header_file) { // preprocessor defines for the header - fprintf(header_file, "#define NOBJECTS %d\n", NOBJECTS); + fprintf(header_file, "#include \"sizes.h\"\n"); fprintf(header_file, "#define RTXSIZ 277\n"); fprintf(header_file, "#define CLSMAX 12\n"); - fprintf(header_file, "#define LOCSIZ 185\n"); fprintf(header_file, "#define LINSIZ %d\n", LINSIZ); fprintf(header_file, "#define TRNSIZ 5\n"); fprintf(header_file, "#define TABSIZ 330\n"); fprintf(header_file, "#define VRBSIZ 35\n"); fprintf(header_file, "#define HNTSIZ 20\n"); fprintf(header_file, "#define TRVSIZ 885\n"); + fprintf(header_file, "#define TOKLEN %d\n", TOKLEN); + fprintf(header_file, "#define HINTLEN %d\n", HINTLEN); fprintf(header_file, "\n"); // include the header in the C file