|
|
1.1 ! root 1: /* W_wad.c */ ! 2: ! 3: #include "doomdef.h" ! 4: /* include "r_local.h" */ ! 5: ! 6: ! 7: /*=============== */ ! 8: /* TYPES */ ! 9: /*=============== */ ! 10: ! 11: ! 12: typedef struct ! 13: { ! 14: char identification[4]; /* should be IWAD */ ! 15: int numlumps; ! 16: int infotableofs; ! 17: } wadinfo_t; ! 18: ! 19: ! 20: byte *wadfileptr; ! 21: ! 22: /*============= */ ! 23: /* GLOBALS */ ! 24: /*============= */ ! 25: ! 26: lumpinfo_t *lumpinfo; /* points directly to rom image */ ! 27: int numlumps; ! 28: void *lumpcache[MAXLUMPS]; ! 29: ! 30: ! 31: void strupr (char *s) ! 32: { ! 33: char c; ! 34: ! 35: while ( (c = *s) != 0) ! 36: { ! 37: if (c >= 'a' && c <= 'z') ! 38: c -= 'a'-'A'; ! 39: *s++ = c; ! 40: } ! 41: } ! 42: ! 43: ! 44: ! 45: #define WINDOW_SIZE 4096 ! 46: #define LOOKAHEAD_SIZE 16 ! 47: ! 48: #define LENSHIFT 4 /* this must be log2(LOOKAHEAD_SIZE) */ ! 49: ! 50: unsigned char *decomp_input; ! 51: unsigned char *decomp_output; ! 52: extern int decomp_start; ! 53: ! 54: void decode(unsigned char *input, unsigned char *output) ! 55: { ! 56: #ifdef JAGUAR ! 57: decomp_input = input; ! 58: decomp_output = output; ! 59: ! 60: gpufinished = zero; ! 61: gpucodestart = (int)&decomp_start; ! 62: while (!I_RefreshCompleted () ) ! 63: ; ! 64: #else ! 65: int getidbyte = 0; ! 66: int len; ! 67: int pos; ! 68: int i; ! 69: unsigned char *source; ! 70: int idbyte = 0; ! 71: ! 72: while (1) ! 73: { ! 74: ! 75: /* get a new idbyte if necessary */ ! 76: if (!getidbyte) idbyte = *input++; ! 77: getidbyte = (getidbyte + 1) & 7; ! 78: ! 79: if (idbyte&1) ! 80: { ! 81: /* decompress */ ! 82: pos = *input++ << LENSHIFT; ! 83: pos = pos | (*input >> LENSHIFT); ! 84: source = output - pos - 1; ! 85: len = (*input++ & 0xf)+1; ! 86: if (len==1) break; ! 87: for (i=0 ; i<len ; i++) ! 88: *output++ = *source++; ! 89: } else { ! 90: *output++ = *input++; ! 91: } ! 92: ! 93: idbyte = idbyte >> 1; ! 94: ! 95: } ! 96: #endif ! 97: } ! 98: ! 99: /* ! 100: ============================================================================ ! 101: ! 102: LUMP BASED ROUTINES ! 103: ! 104: ============================================================================ ! 105: */ ! 106: ! 107: /* ! 108: ==================== ! 109: = ! 110: = W_Init ! 111: = ! 112: ==================== ! 113: */ ! 114: ! 115: void W_Init (void) ! 116: { ! 117: int infotableofs; ! 118: ! 119: wadfileptr = I_WadBase (); ! 120: ! 121: if (D_strncasecmp(((wadinfo_t*)wadfileptr)->identification,"IWAD",4)) ! 122: I_Error ("Wad file doesn't have IWAD id\n"); ! 123: ! 124: numlumps = BIGLONG(((wadinfo_t*)wadfileptr)->numlumps); ! 125: ! 126: infotableofs = BIGLONG(((wadinfo_t*)wadfileptr)->infotableofs); ! 127: lumpinfo = (lumpinfo_t *) (wadfileptr + infotableofs); ! 128: } ! 129: ! 130: ! 131: /* ! 132: ==================== ! 133: = ! 134: = W_CheckNumForName ! 135: = ! 136: = Returns -1 if name not found ! 137: = ! 138: ==================== ! 139: */ ! 140: ! 141: int W_CheckNumForName (char *name) ! 142: { ! 143: char name8[12]; ! 144: int v1,v2; ! 145: lumpinfo_t *lump_p; ! 146: ! 147: /* make the name into two integers for easy compares */ ! 148: D_memset (name8,0,sizeof(name8)); ! 149: D_strncpy (name8,name,8); ! 150: name8[8] = 0; /* in case the name was a full 8 chars */ ! 151: strupr (name8); /* case insensitive */ ! 152: ! 153: v1 = *(int *)name8; ! 154: v2 = *(int *)&name8[4]; ! 155: ! 156: ! 157: /* scan backwards so patch lump files take precedence */ ! 158: ! 159: lump_p = lumpinfo + numlumps; ! 160: ! 161: /* used for stripping out the hi bit of the first character of the */ ! 162: /* name of the lump */ ! 163: ! 164: #ifdef i386 ! 165: #define HIBIT (1<<7) ! 166: #else ! 167: #define HIBIT (1<<31) ! 168: #endif ! 169: ! 170: while (lump_p-- != lumpinfo) ! 171: if (*(int *)&lump_p->name[4] == v2 ! 172: && (*(int *)lump_p->name & ~HIBIT) == v1) ! 173: return lump_p - lumpinfo; ! 174: ! 175: ! 176: return -1; ! 177: } ! 178: ! 179: ! 180: /* ! 181: ==================== ! 182: = ! 183: = W_GetNumForName ! 184: = ! 185: = Calls W_CheckNumForName, but bombs out if not found ! 186: = ! 187: ==================== ! 188: */ ! 189: ! 190: int W_GetNumForName (char *name) ! 191: { ! 192: int i; ! 193: ! 194: i = W_CheckNumForName (name); ! 195: if (i != -1) ! 196: return i; ! 197: ! 198: I_Error ("W_GetNumForName: %s not found!",name); ! 199: return -1; ! 200: } ! 201: ! 202: ! 203: /* ! 204: ==================== ! 205: = ! 206: = W_LumpLength ! 207: = ! 208: = Returns the buffer size needed to load the given lump ! 209: = ! 210: ==================== ! 211: */ ! 212: ! 213: int W_LumpLength (int lump) ! 214: { ! 215: if (lump >= numlumps) ! 216: I_Error ("W_LumpLength: %i >= numlumps",lump); ! 217: return BIGLONG(lumpinfo[lump].size); ! 218: } ! 219: ! 220: ! 221: /* ! 222: ==================== ! 223: = ! 224: = W_ReadLump ! 225: = ! 226: = Loads the lump into the given buffer, which must be >= W_LumpLength() ! 227: = ! 228: ==================== ! 229: */ ! 230: ! 231: void W_ReadLump (int lump, void *dest) ! 232: { ! 233: lumpinfo_t *l; ! 234: ! 235: if (lump >= numlumps) ! 236: I_Error ("W_ReadLump: %i >= numlumps",lump); ! 237: l = lumpinfo+lump; ! 238: if (l->name[0] & 0x80) /* compressed */ ! 239: { ! 240: decode((unsigned char *) (wadfileptr + BIGLONG(l->filepos)), ! 241: (unsigned char *) dest); ! 242: } ! 243: else ! 244: D_memcpy (dest, wadfileptr + BIGLONG(l->filepos), BIGLONG(l->size)); ! 245: } ! 246: ! 247: ! 248: ! 249: /* ! 250: ==================== ! 251: = ! 252: = W_CacheLumpNum ! 253: = ! 254: ==================== ! 255: */ ! 256: ! 257: void *W_CacheLumpNum (int lump, int tag) ! 258: { ! 259: if ((unsigned)lump >= numlumps) ! 260: I_Error ("W_CacheLumpNum: %i >= numlumps",lump); ! 261: ! 262: if (!lumpcache[lump]) ! 263: { /* read the lump in */ ! 264: /*printf ("cache miss on lump %i\n",lump); */ ! 265: Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]); ! 266: W_ReadLump (lump, lumpcache[lump]); ! 267: } ! 268: else ! 269: Z_ChangeTag (lumpcache[lump],tag); ! 270: /*else printf ("cache hit on lump %i\n",lump); */ ! 271: ! 272: return lumpcache[lump]; ! 273: } ! 274: ! 275: ! 276: /* ! 277: ==================== ! 278: = ! 279: = W_CacheLumpName ! 280: = ! 281: ==================== ! 282: */ ! 283: ! 284: void *W_CacheLumpName (char *name, int tag) ! 285: { ! 286: return W_CacheLumpNum (W_GetNumForName(name), tag); ! 287: } ! 288:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.