Index: class.c ================================================================== --- class.c +++ class.c @@ -47,10 +47,11 @@ Uint8 back_color=1; Uint8 inv_back_color=9; char**stringpool; AnimationSlot anim_slot[8]; Uint8 keymask[256/8]; +Uint16 array_size; #define HASH_SIZE 8888 #define LOCAL_HASH_SIZE 5555 typedef struct { Uint16 id; @@ -873,10 +874,25 @@ case 0xC000 ... 0xFFFF: return MVALUE(tokenv-0xBF00); } } ParseError("Constant value expected\n"); } + +static Uint32 parse_array(void) { + Uint32 x,y,z; + nxttok(); + if(tokent!=TF_INT) ParseError("Number expected\n"); + x=tokenv; + nxttok(); + if(tokent!=TF_INT) ParseError("Number expected\n"); + y=tokenv; + if(x<1 || x>64 || y<1 || y>255) ParseError("Array dimension out of range\n"); + z=array_size; + if(z+x*y>0xFFFE) ParseError("Out of array memory\n"); + array_size+=x*y; + return z|(y<<16)|(x<<24); +} static void begin_label_stack(void) { labelstack=0; labelptr=malloc(0x8000*sizeof(Uint16)); if(!labelptr) fatal("Allocation failed\n"); @@ -1640,11 +1656,16 @@ break; case 0x2800 ... 0x2FFF: // Define initial values of global variables i=tokenv-0x2800; nxttok(); if(tokent==TF_CLOSE) break; - initglobals[i]=parse_constant_value(); + if(Tokenf(TF_NAME) && tokenv==OP_ARRAY) { + initglobals[i].t=TY_ARRAY; + initglobals[i].u=parse_array(); + } else { + initglobals[i]=parse_constant_value(); + } nxttok(); if(tokent!=TF_CLOSE) ParseError("Expected close parenthesis\n"); break; case OP_BACKGROUND: nxttok(); @@ -1724,7 +1745,11 @@ if(vst) sqlite3_finalize(vst); free(glohash); for(i=1;icflags&CF_NOCLASS1)) fatal("Class $%s mentioned but not defined\n",classes[i]->name); if(macros) for(i=0;i ) Define a class. See the section about class definitions for details. (@ ) Define a global variable and its initial value. + +(@ Array ) + Define a global variable whose value is a reference to a new array, with + the specified dimensions. The maximum number of columns is 64, and the + maximum number of rows is 255, and he maximum number of cells in all + arrays in total is 65534. ( ) Defines a default message code for all classes which do not specify their own code for this message. Index: exec.c ================================================================== --- exec.c +++ exec.c @@ -34,10 +34,11 @@ unsigned char*quiz_text; Inventory*inventory; Uint32 ninventory; char**levelstrings; Uint16 nlevelstrings; +Value*array_data; typedef struct { Uint16 msg; Uint32 from; Value arg1,arg2,arg3; Index: fileform1.txt ================================================================== --- fileform1.txt +++ fileform1.txt @@ -282,10 +282,12 @@ [38/2*] 0=ObjTopAt, 1=ObjBottomAt, 2=VolumeAt, 3=HeightAt, 4=Delta [39*] Self [40/3*] ObjClassAt + +[47*] Array reference; next word is the array address. [48*] Key [49*] Animation constant: 0=STOP, 1=ONCE, 2=LOOP, 8=OSC Index: heromesh.h ================================================================== --- heromesh.h +++ heromesh.h @@ -14,10 +14,11 @@ #define TY_STRING 4 #define TY_SOUND 5 #define TY_USOUND 6 #define TY_FOR 7 #define TY_MARK 8 +#define TY_ARRAY 9 #define TY_MAXTYPE 15 // The level file format requires type codes 0 to 3 to be as is; other codes may change. typedef struct { union { @@ -165,10 +166,11 @@ extern Sint32 max_volume; // max total volume to allow moving diagonally (default 10000) extern Uint8 back_color,inv_back_color; extern char**stringpool; extern AnimationSlot anim_slot[8]; extern Uint8 keymask[256/8]; +extern Uint16 array_size; Uint16 get_message_ptr(int c,int m); void load_classes(void); // == bindings == @@ -249,10 +251,11 @@ extern unsigned char*quiz_text; extern Inventory*inventory; extern Uint32 ninventory; extern char**levelstrings; extern Uint16 nlevelstrings; +extern Value*array_data; const char*value_string_ptr(Value v); void pfunlink(Uint32 n); void pflink(Uint32 n); Uint32 objalloc(Uint16 c); Index: instruc ================================================================== --- instruc +++ instruc @@ -253,10 +253,16 @@ tmark in nin -mbegin +; Arrays +-Array +,GetArray +InitArray +,SetArray + ; Specials *Function *Local *Label *String Index: instruc.h ================================================================== --- instruc.h +++ instruc.h @@ -365,17 +365,23 @@ #define OP_MARK 32946 #define OP_TMARK 32947 #define OP_IN 32948 #define OP_NIN 32949 #define OP_MBEGIN 32950 -#define OP_FUNCTION 32951 -#define OP_LOCAL 32952 -#define OP_LABEL 32953 -#define OP_STRING 32954 -#define OP_INT16 32955 -#define OP_INT32 32956 -#define OP_DISPATCH 32957 +#define OP_ARRAY 32951 +#define OP_GETARRAY 32952 +#define OP_GETARRAY_C 35000 +#define OP_INITARRAY 32953 +#define OP_SETARRAY 32954 +#define OP_SETARRAY_C 35002 +#define OP_FUNCTION 32955 +#define OP_LOCAL 32956 +#define OP_LABEL 32957 +#define OP_STRING 32958 +#define OP_INT16 32959 +#define OP_INT32 32960 +#define OP_DISPATCH 32961 #ifdef HEROMESH_CLASS static const Op_Names op_names[]={ {"*",8486936}, {"+",8421398}, {"-",8421399}, @@ -386,10 +392,11 @@ {"ARRIVED",8389124}, {"Animate",8421505}, {"Arg1",8552563}, {"Arg2",8552564}, {"Arg3",8552565}, +{"Array",8683703}, {"Arrivals",8618081}, {"Arrived",8618079}, {"Assassinate",8487042}, {"B",9437196}, {"BANG",8389380}, @@ -452,10 +459,11 @@ {"FlushClass",8421516}, {"FlushObj",8487053}, {"From",8421490}, {"GLASS",8389379}, {"GLISSANT",8389419}, +{"GetArray",8487096}, {"GetInventory",8421518}, {"HAWK",8389425}, {"HEARTBEAT",8389407}, {"HIT",8389134}, {"HITBY",8389135}, @@ -466,10 +474,11 @@ {"INIT",8389120}, {"IgnoreKey",8421520}, {"Image",8618044}, {"InPlace",8683644}, {"Inertia",9142333}, +{"InitArray",8421561}, {"Input",8683642}, {"IntMove",10584209}, {"Invisible",8618084}, {"JAYAYAYNG",8389416}, {"JUMPED",8389128}, @@ -547,10 +556,11 @@ {"SUNK",8389131}, {"SW",9437189}, {"Self",8421488}, {"Send",10584231}, {"SendEx",10584232}, +{"SetArray",8487098}, {"SetInventory",8421545}, {"Shape",8618040}, {"ShapeDir",8618063}, {"Sharp",8618062}, {"Shovable",8618064}, @@ -665,7 +675,7 @@ {"tmark",8421555}, {"tuck",8421380}, {"until",8683534}, {"while",8683535}, }; -#define N_OP_NAMES 290 +#define N_OP_NAMES 294 #endif