// // OSD_RegisterFunction() -- Registers a new function // int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const osdfuncparm_t*)) { symbol_t *symb; const char *cp; if (!osdinited) OSD_Init(); if (!name) { Bprintf("OSD_RegisterFunction(): may not register a function with a null name\n"); return -1; } if (!name[0]) { Bprintf("OSD_RegisterFunction(): may not register a function with no name\n"); return -1; } // check for illegal characters in name for (cp = name; *cp; cp++) { if ((cp == name) && (*cp >= '0') && (*cp <= '9')) { Bprintf("OSD_RegisterFunction(): first character of function name \"%s\" must not be a numeral\n", name); return -1; } if ((*cp < '0') || (*cp > '9' && *cp < 'A') || (*cp > 'Z' && *cp < 'a' && *cp != '_') || (*cp > 'z')) { Bprintf("OSD_RegisterFunction(): illegal character in function name \"%s\"\n", name); return -1; } } if (!help) help = "(no description for this function)"; if (!func) { Bprintf("OSD_RegisterFunction(): may not register a null function\n"); return -1; } symb = findexactsymbol(name); if (symb) { Bprintf("OSD_RegisterFunction(): \"%s\" is already defined\n", name); return -1; } symb = addnewsymbol(name); if (!symb) { Bprintf("OSD_RegisterFunction(): Failed registering function \"%s\"\n", name); return -1; } symb->name = name; symb->help = help; symb->func = func; return 0; }
void saveart (short tilenum, short xlen, short ylen) { int i, x, p, pend; pend = ylookup[ylen]; tilesizx[tilenum] = xlen; tilesizy[tilenum] = ylen; i = 0; for(x=0;x<xlen;x++) for(p=x;p<pend;p+=320) tempbuf[i++] = screen[p]; if (Bwrite(fil2,&tempbuf[0],i) < 0) { Bprintf("NOT ENOUGH DISK SPACE!\n"); exit(0); } }
void convpalette(void) { int i, fil3; short danumshades; i = 0; while (Bstrncasecmp(wadata[i],"PLAYPAL",7) != 0) i++; Blseek(fil1,wadplc[i],BSEEK_SET); Bread(fil1,pal,768); for(i=0;i<768;i++) pal[i] >>= 2; i = 0; while (Bstrncasecmp(wadata[i],"COLORMAP",8) != 0) i++; Blseek(fil1,wadplc[i],BSEEK_SET); Bread(fil1,palookup,8192); if ((fil3 = Bopen("palette.dat",BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1) { Bprintf("Cannot save palette.dat\n"); exit(0); } Bwrite(fil3,pal,768); danumshades = 32; Bwrite(fil3,&danumshades,2); Bwrite(fil3,palookup,8192); Bclose(fil3); }
void allocache(intptr_t *newhandle, int32_t newbytes, char *newlockptr) { int32_t i, /*j,*/ z, zz, bestz=0, daval, bestval, besto=0, o1, o2, sucklen, suckz; //printf(" ==> asking for %d bytes, ", newbytes); // Make all requests a multiple of 16 bytes newbytes = (newbytes+15)&0xfffffff0; //printf("allocated %d bytes\n", newbytes); if ((unsigned)newbytes > (unsigned)cachesize) { Bprintf("Cachesize: %d\n",cachesize); Bprintf("*Newhandle: 0x%" PRIxPTR ", Newbytes: %d, *Newlock: %d\n",(intptr_t)newhandle,newbytes,*newlockptr); reportandexit("BUFFER TOO BIG TO FIT IN CACHE!"); } if (*newlockptr == 0) { reportandexit("ALLOCACHE CALLED WITH LOCK OF 0!"); } //Find best place bestval = 0x7fffffff; o1 = cachesize; for (z=cacnum-1; z>=0; z--) { o1 -= cac[z].leng; o2 = o1+newbytes; if (o2 > cachesize) continue; daval = 0; for (i=o1,zz=z; i<o2; i+=cac[zz++].leng) { if (*cac[zz].lock == 0) continue; if (*cac[zz].lock >= 200) { daval = 0x7fffffff; break; } daval += mulscale32(cac[zz].leng+65536,lockrecip[*cac[zz].lock]); if (daval >= bestval) break; } if (daval < bestval) { bestval = daval; besto = o1; bestz = z; if (bestval == 0) break; } } //printf("%d %d %d\n",besto,newbytes,*newlockptr); if (bestval == 0x7fffffff) reportandexit("CACHE SPACE ALL LOCKED UP!"); //Suck things out for (sucklen=-newbytes,suckz=bestz; sucklen<0; sucklen+=cac[suckz++].leng) if (*cac[suckz].lock) *cac[suckz].hand = 0; //Remove all blocks except 1 suckz -= (bestz+1); cacnum -= suckz; copybufbyte(&cac[bestz+suckz],&cac[bestz],(cacnum-bestz)*sizeof(cactype)); cac[bestz].hand = newhandle; *newhandle = cachestart+(intptr_t)besto; cac[bestz].leng = newbytes; cac[bestz].lock = newlockptr; cachecount++; //Add new empty block if necessary if (sucklen <= 0) return; bestz++; if (bestz == cacnum) { cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); cac[bestz].leng = sucklen; cac[bestz].lock = &zerochar; return; } if (*cac[bestz].lock == 0) { cac[bestz].leng += sucklen; return; } cacnum++; if (cacnum > MAXCACHEOBJECTS) reportandexit("Too many objects in cache! (cacnum > MAXCACHEOBJECTS)"); for (z=cacnum-1; z>bestz; z--) cac[z] = cac[z-1]; cac[bestz].leng = sucklen; cac[bestz].lock = &zerochar; }