diff --git a/engine/qclib/initlib.c b/engine/qclib/initlib.c index a2712332..1bb3dab2 100644 --- a/engine/qclib/initlib.c +++ b/engine/qclib/initlib.c @@ -539,6 +539,8 @@ progfuncs_t * InitProgs(progexterns_t *ext) funcs->callargc = &funcs->pr_argc; funcs->parms = ext; + + SetEndian(); return funcs; } diff --git a/engine/qclib/pr_edict.c b/engine/qclib/pr_edict.c index 1321acd7..e8fdf30f 100644 --- a/engine/qclib/pr_edict.c +++ b/engine/qclib/pr_edict.c @@ -2311,7 +2311,7 @@ retry: // byte swap the header #ifndef NOENDIAN for (i=0 ; iversion == PROG_VERSION) @@ -2413,7 +2413,7 @@ retry: Sys_Error("Bad intsize"); } s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_statements16), len, 2, (char *)(((int *)pr_statements16)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_statements16), len, 2, (char *)(((int *)pr_statements16)+1), s); current_progstate->statements = (dstatement16_t *)s; } @@ -2431,7 +2431,7 @@ retry: Sys_Error("Bad intsize"); } s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_globaldefs16), len, 2, (char *)(((int *)pr_globaldefs16)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_globaldefs16), len, 2, (char *)(((int *)pr_globaldefs16)+1), s); gd16 = *(ddef16_t**)¤t_progstate->globaldefs = (ddef16_t *)s; } @@ -2449,7 +2449,7 @@ retry: Sys_Error("Bad intsize"); } s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_fielddefs16), len, 2, (char *)(((int *)pr_fielddefs16)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_fielddefs16), len, 2, (char *)(((int *)pr_fielddefs16)+1), s); *(ddef16_t**)¤t_progstate->fielddefs = (ddef16_t *)s; } @@ -2457,7 +2457,7 @@ retry: { len=sizeof(dfunction_t)*pr_progs->numfunctions; s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_functions), len, 2, (char *)(((int *)pr_functions)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_functions), len, 2, (char *)(((int *)pr_functions)+1), s); fnc = pr_functions = (dfunction_t *)s; } @@ -2465,7 +2465,7 @@ retry: { len=sizeof(char)*pr_progs->numstrings; s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_strings), len, 2, (char *)(((int *)pr_strings)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_strings), len, 2, (char *)(((int *)pr_strings)+1), s); pr_strings = (char *)s; } @@ -2473,7 +2473,7 @@ retry: { len=sizeof(float)*pr_progs->numglobals; s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_globals), len, 2, (char *)(((int *)pr_globals)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_globals), len, 2, (char *)(((int *)pr_globals)+1), s); glob = pr_globals = (float *)s; } @@ -2481,7 +2481,7 @@ retry: { len=sizeof(int)*pr_progs->numstatements; s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_linenums), len, 2, (char *)(((int *)pr_linenums)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_linenums), len, 2, (char *)(((int *)pr_linenums)+1), s); pr_linenums = (int *)s; } @@ -2489,7 +2489,7 @@ retry: { len=sizeof(typeinfo_t)*pr_progs->numtypes; s = PRHunkAlloc(progfuncs, len); - QC_decode(progfuncs, LittleLong(*(int *)pr_types), len, 2, (char *)(((int *)pr_types)+1), s); + QC_decode(progfuncs, PRLittleLong(*(int *)pr_types), len, 2, (char *)(((int *)pr_types)+1), s); pr_types = (typeinfo_t *)s; } @@ -2563,12 +2563,12 @@ retry: for (i=0 ; inumfunctions; i++) { #ifndef NOENDIAN - fnc[i].first_statement = LittleLong (fnc[i].first_statement); - fnc[i].parm_start = LittleLong (fnc[i].parm_start); - fnc[i].s_name = (string_t)LittleLong ((long)fnc[i].s_name); - fnc[i].s_file = (string_t)LittleLong ((long)fnc[i].s_file); - fnc[i].numparms = LittleLong (fnc[i].numparms); - fnc[i].locals = LittleLong (fnc[i].locals); + fnc[i].first_statement = PRLittleLong (fnc[i].first_statement); + fnc[i].parm_start = PRLittleLong (fnc[i].parm_start); + fnc[i].s_name = (string_t)PRLittleLong ((long)fnc[i].s_name); + fnc[i].s_file = (string_t)PRLittleLong ((long)fnc[i].s_file); + fnc[i].numparms = PRLittleLong (fnc[i].numparms); + fnc[i].locals = PRLittleLong (fnc[i].locals); #endif /* if (!strncmp(fnc[i].s_name+pr_strings, "ext_", 4)) { @@ -2599,7 +2599,7 @@ retry: //actual global values #ifndef NOENDIAN for (i=0 ; inumglobals ; i++) - ((int *)glob)[i] = LittleLong (((int *)glob)[i]); + ((int *)glob)[i] = PRLittleLong (((int *)glob)[i]); #endif if (pr_types) @@ -2607,13 +2607,13 @@ retry: for (i=0 ; inumtypes ; i++) { #ifndef NOENDIAN - pr_types[i].type = LittleLong(current_progstate->types[i].type); - pr_types[i].next = LittleLong(current_progstate->types[i].next); - pr_types[i].aux_type = LittleLong(current_progstate->types[i].aux_type); - pr_types[i].num_parms = LittleLong(current_progstate->types[i].num_parms); - pr_types[i].ofs = LittleLong(current_progstate->types[i].ofs); - pr_types[i].size = LittleLong(current_progstate->types[i].size); - pr_types[i].name = (string_t)LittleLong((long)current_progstate->types[i].name); + pr_types[i].type = PRLittleLong(current_progstate->types[i].type); + pr_types[i].next = PRLittleLong(current_progstate->types[i].next); + pr_types[i].aux_type = PRLittleLong(current_progstate->types[i].aux_type); + pr_types[i].num_parms = PRLittleLong(current_progstate->types[i].num_parms); + pr_types[i].ofs = PRLittleLong(current_progstate->types[i].ofs); + pr_types[i].size = PRLittleLong(current_progstate->types[i].size); + pr_types[i].name = (string_t)PRLittleLong((long)current_progstate->types[i].name); #endif pr_types[i].name += stringadjust; } @@ -2630,9 +2630,9 @@ retry: for (i=0 ; inumglobaldefs ; i++) { #ifndef NOENDIAN - gd16[i].type = LittleShort (gd16[i].type); - gd16[i].ofs = LittleShort (gd16[i].ofs); - gd16[i].s_name = (string_t)LittleLong ((long)gd16[i].s_name); + gd16[i].type = PRLittleShort (gd16[i].type); + gd16[i].ofs = PRLittleShort (gd16[i].ofs); + gd16[i].s_name = (string_t)PRLittleLong ((long)gd16[i].s_name); #endif gd16[i].s_name += stringadjust; } @@ -2641,9 +2641,9 @@ retry: for (i=0 ; inumfielddefs ; i++) { #ifndef NOENDIAN - fld16[i].type = LittleShort (fld16[i].type); - fld16[i].ofs = LittleShort (fld16[i].ofs); - fld16[i].s_name = (string_t)LittleLong ((long)fld16[i].s_name); + fld16[i].type = PRLittleShort (fld16[i].type); + fld16[i].ofs = PRLittleShort (fld16[i].ofs); + fld16[i].s_name = (string_t)PRLittleLong ((long)fld16[i].s_name); #endif if (reorg) { @@ -2666,9 +2666,9 @@ retry: for (i=0 ; inumglobaldefs ; i++) { #ifndef NOENDIAN - pr_globaldefs32[i].type = LittleLong (pr_globaldefs32[i].type); - pr_globaldefs32[i].ofs = LittleLong (pr_globaldefs32[i].ofs); - pr_globaldefs32[i].s_name = (string_t)LittleLong ((long)pr_globaldefs32[i].s_name); + pr_globaldefs32[i].type = PRLittleLong (pr_globaldefs32[i].type); + pr_globaldefs32[i].ofs = PRLittleLong (pr_globaldefs32[i].ofs); + pr_globaldefs32[i].s_name = (string_t)PRLittleLong ((long)pr_globaldefs32[i].s_name); #endif pr_globaldefs32[i].s_name += stringadjust; } @@ -2676,9 +2676,9 @@ retry: for (i=0 ; inumfielddefs ; i++) { #ifndef NOENDIAN - pr_fielddefs32[i].type = LittleLong (pr_fielddefs32[i].type); - pr_fielddefs32[i].ofs = LittleLong (pr_fielddefs32[i].ofs); - pr_fielddefs32[i].s_name = (string_t)LittleLong ((long)pr_fielddefs32[i].s_name); + pr_fielddefs32[i].type = PRLittleLong (pr_fielddefs32[i].type); + pr_fielddefs32[i].ofs = PRLittleLong (pr_fielddefs32[i].ofs); + pr_fielddefs32[i].s_name = (string_t)PRLittleLong ((long)pr_fielddefs32[i].s_name); #endif if (reorg) @@ -2705,10 +2705,10 @@ retry: for (i=0 ; inumstatements ; i++) { #ifndef NOENDIAN - st16[i].op = LittleShort(st16[i].op); - st16[i].a = LittleShort(st16[i].a); - st16[i].b = LittleShort(st16[i].b); - st16[i].c = LittleShort(st16[i].c); + st16[i].op = PRLittleShort(st16[i].op); + st16[i].a = PRLittleShort(st16[i].a); + st16[i].b = PRLittleShort(st16[i].b); + st16[i].c = PRLittleShort(st16[i].c); #endif if (st16[i].op >= OP_CALL1 && st16[i].op <= OP_CALL8) { @@ -2731,10 +2731,10 @@ retry: for (i=0 ; inumstatements ; i++) { #ifndef NOENDIAN - pr_statements32[i].op = LittleLong(pr_statements32[i].op); - pr_statements32[i].a = LittleLong(pr_statements32[i].a); - pr_statements32[i].b = LittleLong(pr_statements32[i].b); - pr_statements32[i].c = LittleLong(pr_statements32[i].c); + pr_statements32[i].op = PRLittleLong(pr_statements32[i].op); + pr_statements32[i].a = PRLittleLong(pr_statements32[i].a); + pr_statements32[i].b = PRLittleLong(pr_statements32[i].b); + pr_statements32[i].c = PRLittleLong(pr_statements32[i].c); #endif if (pr_statements32[i].op >= OP_CALL1 && pr_statements32[i].op <= OP_CALL8) { @@ -2756,10 +2756,10 @@ retry: for (i=0 ; inumstatements ; i++) { #ifndef NOENDIAN - pr_statements32[i].op = LittleLong(pr_statements32[i].op); - pr_statements32[i].a = LittleLong(pr_statements32[i].a); - pr_statements32[i].b = LittleLong(pr_statements32[i].b); - pr_statements32[i].c = LittleLong(pr_statements32[i].c); + pr_statements32[i].op = PRLittleLong(pr_statements32[i].op); + pr_statements32[i].a = PRLittleLong(pr_statements32[i].a); + pr_statements32[i].b = PRLittleLong(pr_statements32[i].b); + pr_statements32[i].c = PRLittleLong(pr_statements32[i].c); #endif if (pr_statements32[i].op >= OP_CALL1 && pr_statements32[i].op <= OP_CALL8) { diff --git a/engine/qclib/progsint.h b/engine/qclib/progsint.h index 55bfd534..da68238d 100644 --- a/engine/qclib/progsint.h +++ b/engine/qclib/progsint.h @@ -101,12 +101,12 @@ void StripExtension (char *path); -extern short (*BigShort) (short l); -extern short (*LittleShort) (short l); -extern long (*BigLong) (long l); -extern long (*LittleLong) (long l); -extern float (*BigFloat) (float l); -extern float (*LittleFloat) (float l); +extern short (*PRBigShort) (short l); +extern short (*PRLittleShort) (short l); +extern long (*PRBigLong) (long l); +extern long (*PRLittleLong) (long l); +extern float (*PRBigFloat) (float l); +extern float (*PRLittleFloat) (float l); diff --git a/engine/qclib/progslib.h b/engine/qclib/progslib.h index 32ad4da8..2860c034 100644 --- a/engine/qclib/progslib.h +++ b/engine/qclib/progslib.h @@ -43,6 +43,8 @@ typedef struct { #define sizeofevalc sizeof(evalc_t) typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer, ev_integer, ev_variant, ev_struct, ev_union} etype_t; +//the number of pointers to variables (as opposed to functions - those are fine) in these structures is excessive. +//Many of the functions are also obsolete. struct progfuncs_s { int progsversion; //PROGSTRUCT_VERSION @@ -51,15 +53,15 @@ struct progfuncs_s { progsnum_t (*LoadProgs) (progfuncs_t *prinst, char *s, int headercrc, builtin_t *builtins, int numbuiltins); //load a progs int (*InitEnts) (progfuncs_t *prinst, int max_ents); //returns size of edicts for use with nextedict macro void (*ExecuteProgram) (progfuncs_t *prinst, func_t fnum); //start execution - pbool (*SwitchProgs) (progfuncs_t *prinst, progsnum_t num); //switch to a different progs - my aim is to make this obsolete + pbool (*SwitchProgs) (progfuncs_t *prinst, progsnum_t num); //switch to a different progs - this should be obsolete. struct globalvars_s *(*globals) (progfuncs_t *prinst, progsnum_t num); //get the globals of a progs - struct entvars_s *(*entvars) (progfuncs_t *prinst, struct edict_s *ent); //return a pointer to the entvars of an ent + struct entvars_s *(*entvars) (progfuncs_t *prinst, struct edict_s *ent); //return a pointer to the entvars of an ent. can be achieved via the edict_t structure instead, so obsolete. void (VARGS *RunError) (progfuncs_t *prinst, char *msg, ...); //builtins call this to say there was a problem void (*PrintEdict) (progfuncs_t *prinst, struct edict_s *ed); //get a listing of all vars on an edict (sent back via 'print') - struct edict_s *(*ED_Alloc) (progfuncs_t *prinst); - void (*ED_Free) (progfuncs_t *prinst, struct edict_s *ed); + struct edict_s *(*EntAlloc) (progfuncs_t *prinst); + void (*EntFree) (progfuncs_t *prinst, struct edict_s *ed); struct edict_s *(*EDICT_NUM) (progfuncs_t *prinst, int n); //get the nth edict int (*NUM_FOR_EDICT) (progfuncs_t *prinst, struct edict_s *e); //so you can find out what that 'n' will be @@ -68,7 +70,7 @@ struct progfuncs_s { char *(*VarString) (progfuncs_t *prinst, int first); //returns a string made up of multiple arguments - struct progstate_s **progstate; //these are so the macros work properly + struct progstate_s **progstate; //internal to the library. func_t (*FindFunction) (progfuncs_t *prinst, char *funcname, progsnum_t num); @@ -86,7 +88,7 @@ struct progfuncs_s { union eval_s *(*FindGlobal) (progfuncs_t *prinst, char *name, progsnum_t num); //find a pointer to the globals value char *(*AddString) (progfuncs_t *prinst, char *val, int minlength); //dump a string into the progs memory (for setting globals and whatnot) - void *(*Tempmem) (progfuncs_t *prinst, int ammount, char *whatfor); //grab some mem for as long as the progs stays loaded (for strings) + void *(*Tempmem) (progfuncs_t *prinst, int ammount, char *whatfor); //grab some mem for as long as the progs stays loaded union eval_s *(*GetEdictFieldValue) (progfuncs_t *prinst, struct edict_s *ent, char *name, evalc_t *s); //get an entityvar (cache it) and return the possible values struct edict_s *(*ProgsToEdict) (progfuncs_t *prinst, int progs); //edicts are stored as ints and need to be adjusted @@ -115,16 +117,16 @@ struct progfuncs_s { char *stringtable; //qc strings are all relative. add to a qc string. this is required for support of frikqcc progs that strip string immediates. int fieldadjust; //FrikQCC style arrays can cause problems due to field remapping. This causes us to leave gaps but offsets identical. - struct qcthread_s *(*Fork) (progfuncs_t *prinst); + struct qcthread_s *(*Fork) (progfuncs_t *prinst); //returns a pointer to a thread which can be resumed via RunThread. void (*RunThread) (progfuncs_t *prinst, struct qcthread_s *thread); - void (*AbortStack) (progfuncs_t *prinst); + void (*AbortStack) (progfuncs_t *prinst); //annigilates the current stack, positioning on a return statement. It is expected that this is only used via a builtin! - int lastcalledbuiltinnumber; + int lastcalledbuiltinnumber; //useful with non-implemented opcodes. int (*RegisterFieldVar) (progfuncs_t *prinst, unsigned int type, char *name, int requestedpos, int origionalofs); - char *tempstringbase; - int tempstringnum; + char *tempstringbase; //for engine's use. Store your base tempstring pointer here. + int tempstringnum; //for engine's use. }; typedef struct progexterns_s { @@ -140,10 +142,10 @@ typedef struct progexterns_s { void (*entspawn) (struct edict_s *ent); //ent has been spawned, but may not have all the extra variables (that may need to be set) set pbool (*entcanfree) (struct edict_s *ent); //return true to stop ent from being freed - void (*stateop) (progfuncs_t *prinst, float var, func_t func); - void (*cstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc); - void (*cwstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc); - void (*thinktimeop) (progfuncs_t *prinst, struct edict_s *ent, float varb); + void (*stateop) (progfuncs_t *prinst, float var, func_t func); //what to do on qc's state opcode. + void (*cstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc); //a hexen2 opcode. + void (*cwstateop) (progfuncs_t *prinst, float vara, float varb, func_t currentfunc); //a hexen2 opcode. + void (*thinktimeop) (progfuncs_t *prinst, struct edict_s *ent, float varb); //a hexen2 opcode. //used when loading a game @@ -159,12 +161,12 @@ typedef struct progexterns_s { enum {PR_NOCOMPILE, PR_COMPILENEXIST, PR_COMPILEEXISTANDCHANGED, PR_COMPILECHANGED, PR_COMPILEALWAYS, PR_COMPILEIGNORE} autocompile; - double *gametime; + double *gametime; //used to prevent the vm from reusing an entity faster than 2 secs. - struct edict_s **sv_edicts; - int *sv_num_edicts; + struct edict_s **sv_edicts; //pointer to the engine's reference to world. + int *sv_num_edicts; //pointer to the engine's edict count. - int (*useeditor) (char *filename, int line, int nump, char **parms); + int (*useeditor) (char *filename, int line, int nump, char **parms); //called on syntax errors or step-by-step debugging. } progparms_t, progexterns_t; void QC_AddSharedVar(progfuncs_t *progfuncs, int start, int size); @@ -209,8 +211,8 @@ typedef union eval_s #define PR_RegisterFieldVar(pf,type,name,reqofs,qcofs) (*pf->RegisterFieldVar) (pf,type,name,reqofs,qcofs) -#define ED_Alloc(pf) (*pf->ED_Alloc) (pf) -#define ED_Free(pf, ed) (*pf->ED_Free) (pf, ed) +#define ED_Alloc(pf) (*pf->EntAlloc) (pf) +#define ED_Free(pf, ed) (*pf->EntFree) (pf, ed) #define PR_LoadEnts(pf, s, kf) (*pf->load_ents) (pf, s, kf) #define PR_SaveEnts(pf, buf, size, mode) (*pf->save_ents) (pf, buf, size, mode) @@ -230,11 +232,6 @@ typedef union eval_s #define PR_PrintEdict(pf,ed) (*pf->PrintEdict) (pf, ed) -//#define sv_edicts (*progfuncs->sv_edicts) -//#define current_progstate (*progfuncs->progstate) - -//#define pr_num_edicts (*progfuncs->sv_num_edicts) - #define PR_FindFunction(pf, name, num) (*pf->FindFunction) (pf, name, num) #define PR_FindGlobal(pf, name, progs) (*pf->FindGlobal) (pf, name, progs) #define PR_AddString(pf, ed, len) (*pf->AddString) (pf, ed, len) @@ -250,6 +247,7 @@ typedef union eval_s //builtin funcs (which operate on globals) +//To use these outside of builtins, you will likly have to use the 'globals' method. #define G_FLOAT(o) (((float *)pr_globals)[o]) #define G_FLOAT2(o) (((float *)pr_globals)[OFS_PARM0 + o*3]) #define G_INT(o) (((int *)pr_globals)[o]) @@ -261,6 +259,7 @@ typedef union eval_s #define PR_GetString(p,s) (s?s + p->stringtable:"") #define PR_GetStringOfs(p,o) (G_INT(o)?G_INT(o) + p->stringtable:"") +#define PR_SetStringOfs(p,o,s) (G_INT(o) = s - p->stringtable) #define PR_SetString(p, s) ((s&&*s)?(s - p->stringtable):0) #define PR_NewString(p, s, l) (PR_AddString(p, s, l) - p->stringtable) diff --git a/engine/qclib/qcc_cmdlib.c b/engine/qclib/qcc_cmdlib.c index 52ddee6d..0f0342e7 100644 --- a/engine/qclib/qcc_cmdlib.c +++ b/engine/qclib/qcc_cmdlib.c @@ -17,6 +17,99 @@ char **myargv; char qcc_token[1024]; int qcc_eof; +/* +============================================================================ + + BYTE ORDER FUNCTIONS + +============================================================================ +*/ +short (*PRBigShort) (short l); +short (*PRLittleShort) (short l); +long (*PRBigLong) (long l); +long (*PRLittleLong) (long l); +float (*PRBigFloat) (float l); +float (*PRLittleFloat) (float l); + + +short QCC_SwapShort (short l) +{ + qbyte b1,b2; + + b1 = l&255; + b2 = (l>>8)&255; + + return (b1<<8) + b2; +} + +short QCC_Short (short l) +{ + return l; +} + + +long QCC_SwapLong (long l) +{ + qbyte b1,b2,b3,b4; + + b1 = l&255; + b2 = (l>>8)&255; + b3 = (l>>16)&255; + b4 = (l>>24)&255; + + return ((long)b1<<24) + ((long)b2<<16) + ((long)b3<<8) + b4; +} + +long QCC_Long (long l) +{ + return l; +} + + +float QCC_SwapFloat (float l) +{ + union {qbyte b[4]; float f;} in, out; + + in.f = l; + out.b[0] = in.b[3]; + out.b[1] = in.b[2]; + out.b[2] = in.b[1]; + out.b[3] = in.b[0]; + + return out.f; +} + +float QCC_Float (float l) +{ + return l; +} + +void SetEndian(void) +{ + union {qbyte b[2]; unsigned short s;} ed; + ed.s = 255; + if (ed.b[0] == 255) + { + PRBigShort = QCC_SwapShort; + PRLittleShort = QCC_Short; + PRBigLong = QCC_SwapLong; + PRLittleLong = QCC_Long; + PRBigFloat = QCC_SwapFloat; + PRLittleFloat = QCC_Float; + } + else + { + PRBigShort = QCC_Short; + PRLittleShort = QCC_SwapShort; + PRBigLong = QCC_Long; + PRLittleLong = QCC_SwapLong; + PRBigFloat = QCC_Float; + PRLittleFloat = QCC_SwapFloat; + } +} + + + #ifndef MINIMAL /* ================ @@ -603,137 +696,6 @@ long ParseNum (char *str) -/* -============================================================================ - - BYTE ORDER FUNCTIONS - -============================================================================ -*/ - -#ifdef __BIG_ENDIAN__ - -short QCC_LittleShort (short l) -{ - qbyte b1,b2; - - b1 = l&255; - b2 = (l>>8)&255; - - return (b1<<8) + b2; -} - -short QCC_BigShort (short l) -{ - return l; -} - - -long QCC_LittleLong (long l) -{ - qbyte b1,b2,b3,b4; - - b1 = l&255; - b2 = (l>>8)&255; - b3 = (l>>16)&255; - b4 = (l>>24)&255; - - return ((long)b1<<24) + ((long)b2<<16) + ((long)b3<<8) + b4; -} - -long QCC_BigLong (long l) -{ - return l; -} - - -float QCC_LittleFloat (float l) -{ - union {qbyte b[4]; float f;} in, out; - - in.f = l; - out.b[0] = in.b[3]; - out.b[1] = in.b[2]; - out.b[2] = in.b[1]; - out.b[3] = in.b[0]; - - return out.f; -} - -float QCC_BigFloat (float l) -{ - return l; -} - - -#else - - -short QCC_BigShort (short l) -{ - qbyte b1,b2; - - b1 = l&255; - b2 = (l>>8)&255; - - return (b1<<8) + b2; -} - -short QCC_LittleShort (short l) -{ - return l; -} - - -long QCC_BigLong (long l) -{ - qbyte b1,b2,b3,b4; - - b1 = (qbyte)(l&255); - b2 = (qbyte)((l>>8)&255); - b3 = (qbyte)((l>>16)&255); - b4 = (qbyte)((l>>24)&255); - - return ((long)b1<<24) + ((long)b2<<16) + ((long)b3<<8) + b4; -} - -long QCC_LittleLong (long l) -{ - return l; -} - -float QCC_BigFloat (float l) -{ - union {qbyte b[4]; float f;} in, out; - - in.f = l; - out.b[0] = in.b[3]; - out.b[1] = in.b[2]; - out.b[2] = in.b[1]; - out.b[3] = in.b[0]; - - return out.f; -} - -float QCC_LittleFloat (float l) -{ - return l; -} - -#endif - -void SetEndian(void) -{ - if (!BigShort) - { - BigShort = QCC_BigShort; - LittleShort = QCC_LittleShort; - BigLong = QCC_BigLong; - LittleLong = QCC_LittleLong; - BigFloat = QCC_BigFloat; - LittleFloat = QCC_LittleFloat; - } -} diff --git a/engine/qclib/qccmain.c b/engine/qclib/qccmain.c index d1ab5e2f..e80e7c83 100644 --- a/engine/qclib/qccmain.c +++ b/engine/qclib/qccmain.c @@ -395,10 +395,10 @@ int WriteSourceFiles(int h, dprograms_t *progs, pbool sourceaswell) continue; SafeWrite(h, f->filename, strlen(f->filename)+1); - i = LittleLong(f->size); + i = PRLittleLong(f->size); SafeWrite(h, &i, sizeof(int)); - i = LittleLong(encrpytmode); + i = PRLittleLong(encrpytmode); SafeWrite(h, &i, sizeof(int)); if (encrpytmode) @@ -794,7 +794,7 @@ strofs = (strofs+3)&~3; len = QC_encode(progfuncs, strofs*sizeof(char), 2, (char *)strings, h); //write i = SafeSeek (h, 0, SEEK_CUR); SafeSeek(h, progs.ofs_strings, SEEK_SET);//seek back - len = LittleLong(len); + len = PRLittleLong(len); SafeWrite (h, &len, sizeof(int)); //write size. SafeSeek(h, i, SEEK_SET); } @@ -822,10 +822,10 @@ strofs = (strofs+3)&~3; case 32: for (i=0 ; iMAX_PARMS)?MAX_PARMS:functions[i].numparms); - functions[i].locals = LittleLong (functions[i].locals); + functions[i].first_statement = PRLittleLong (functions[i].first_statement); + functions[i].parm_start = PRLittleLong (functions[i].parm_start); + functions[i].s_name = PRLittleLong (functions[i].s_name); + functions[i].s_file = PRLittleLong (functions[i].s_file); + functions[i].numparms = PRLittleLong ((functions[i].numparms>MAX_PARMS)?MAX_PARMS:functions[i].numparms); + functions[i].locals = PRLittleLong (functions[i].locals); } if (progs.blockscompressed&8) @@ -895,7 +895,7 @@ strofs = (strofs+3)&~3; len = QC_encode(progfuncs, numfunctions*sizeof(QCC_dfunction_t), 2, (char *)functions, h); //write i = SafeSeek (h, 0, SEEK_CUR); SafeSeek(h, progs.ofs_functions, SEEK_SET);//seek back - len = LittleLong(len); + len = PRLittleLong(len); SafeWrite (h, &len, sizeof(int)); //write size. SafeSeek(h, i, SEEK_SET); } @@ -909,9 +909,9 @@ strofs = (strofs+3)&~3; progs.numglobaldefs = numglobaldefs; for (i=0 ; ifilepos = LittleLong (SafeSeek (packhandle, 0, SEEK_CUR)); - pf->filelen = LittleLong (remaining); + pf->filepos = PRLittleLong (SafeSeek (packhandle, 0, SEEK_CUR)); + pf->filelen = PRLittleLong (remaining); strcpy (pf->name, name); printf ("%64s : %7i\n", pf->name, remaining); @@ -1966,8 +1966,8 @@ void QCC_PackFile (char *src, char *name) in = SafeOpenRead (src); remaining = filelength (in); - pf->filepos = LittleLong (lseek (packhandle, 0, SEEK_CUR)); - pf->filelen = LittleLong (remaining); + pf->filepos = PRLittleLong (lseek (packhandle, 0, SEEK_CUR)); + pf->filelen = PRLittleLong (remaining); strcpy (pf->name, name); printf ("%64s : %7i\n", pf->name, remaining); @@ -2127,8 +2127,8 @@ void _QCC_CopyFiles (int blocknum, int copytype, char *srcdir, char *destdir) header.id[2] = 'C'; header.id[3] = 'K'; dirlen = (qbyte *)pf - (qbyte *)pfiles; - header.dirofs = LittleLong(SafeSeek (packhandle, 0, SEEK_CUR)); - header.dirlen = LittleLong(dirlen); + header.dirofs = PRLittleLong(SafeSeek (packhandle, 0, SEEK_CUR)); + header.dirlen = PRLittleLong(dirlen); SafeWrite (packhandle, pfiles, dirlen); @@ -2576,6 +2576,8 @@ void QCC_main (int argc, char **argv) //as part of the quake engine #endif char *s; + SetEndian(); + myargc = argc; myargv = argv; @@ -2652,8 +2654,6 @@ void QCC_main (int argc, char **argv) //as part of the quake engine } */ - SetEndian(); - strcpy(QCC_copyright, "This file was created with ForeThought's modified QuakeC compiler\nThanks to ID Software"); for (p = 0; p < 5; p++) strcpy(QCC_Packname[p], ""); @@ -3268,13 +3268,6 @@ void new_QCC_ContinueCompile(void) #ifdef QCCONLY progfuncs_t *progfuncs; -short (*BigShort) (short l); -short (*LittleShort) (short l); -long (*BigLong) (long l); -long (*LittleLong) (long l); -float (*BigFloat) (float l); -float (*LittleFloat) (float l); - /* ============== LoadFile