?? build.c
字號:
/* * "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman * Ken Silverman's official web site: "http://www.advsys.net/ken" * See the included license file "BUILDLIC.TXT" for license info. * This file has been modified from Ken Silverman's original release */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include "engine.h"#include "platform.h"#include "build.h"#include "pragmas.h"#include "display.h"#include "bstub.h"#define MAXMENUFILES 256#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((unsigned short)crc)>>8)&65535)^dat]))static long crctable[256];static char kensig[24];#define KEYFIFOSIZ 64volatile unsigned char keystatus[256];static volatile unsigned char keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend;static volatile unsigned char readch, oldreadch, extended, keytemp;long vel, svel, angvel;#define NUMKEYS 19unsigned char buildkeys[NUMKEYS] ={ 0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39, 0x1e,0x2c,0xd1,0xc9,0x33,0x34, 0x9c,0x1c,0xd,0xc,0xf,};long posx, posy, posz, horiz = 100;short ang, cursectnum;long hvel;static long synctics = 0, lockclock = 0;extern volatile long stereomode;extern char vgacompatible;extern char picsiz[MAXTILES];extern long startposx, startposy, startposz;extern short startang, startsectnum;extern long frameplace, pageoffset, ydim16;extern long cachesize, artsize;static short oldmousebstatus = 0, brightness = 0;long zlock = 0x7fffffff, zmode = 0, whitecol, kensplayerheight = 32;short defaultspritecstat = 0;static short localartfreq[MAXTILES];static short localartlookup[MAXTILES], localartlookupnum;char tempbuf[4096];char names[MAXTILES][17];short asksave = 0;extern short editstatus, searchit;extern long searchx, searchy; /* search input */extern short searchsector, searchwall, searchstat; /* search output */extern short pointhighlight, linehighlight, highlightcnt;short grid = 3, gridlock = 1, showtags = 1;long zoom = 768, gettilezoom = 1;int numsprites;short highlight[MAXWALLS];short highlightsector[MAXSECTORS], highlightsectorcnt = -1;/*extern char textfont[128][8];*/static char pskysearch[MAXSECTORS];short temppicnum, tempcstat, templotag, temphitag, tempextra;char tempshade, temppal, tempvis, tempxrepeat, tempyrepeat;char somethingintab = 255;static char boardfilename[13], oboardfilename[13];static long repeatcountx, repeatcounty;static char menuname[MAXMENUFILES][17], curpath[80], menupath[80];static long menunamecnt, menuhighlight;static long fillist[640];static char scantoasc[128] ={ 0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0, 'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s', 'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v', 'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0, 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};static char scantoascwithshift[128] ={ 0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0, 'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S', 'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V', 'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0, 0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1', '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};void keytimerstuff(void){ if (keystatus[buildkeys[5]] == 0) { if (keystatus[buildkeys[2]] > 0) angvel = max(angvel-16,-128); if (keystatus[buildkeys[3]] > 0) angvel = min(angvel+16,127); } else { if (keystatus[buildkeys[2]] > 0) svel = min(svel+8,127); if (keystatus[buildkeys[3]] > 0) svel = max(svel-8,-128); } if (keystatus[buildkeys[0]] > 0) vel = min(vel+8,127); if (keystatus[buildkeys[1]] > 0) vel = max(vel-8,-128); if (keystatus[buildkeys[12]] > 0) svel = min(svel+8,127); if (keystatus[buildkeys[13]] > 0) svel = max(svel-8,-128); if (angvel < 0) angvel = min(angvel+12,0); if (angvel > 0) angvel = max(angvel-12,0); if (svel < 0) svel = min(svel+2,0); if (svel > 0) svel = max(svel-2,0); if (vel < 0) vel = min(vel+2,0); if (vel > 0) vel = max(vel-2,0);}void __interrupt __far timerhandler(void){ totalclock++; keytimerstuff(); #ifdef PLATFORM_DOS outp(0x20,0x20); #endif}void __interrupt __far keyhandler(void){ /* * ryan sez: End Of Interrupt call on DOS. This seems like a * dangerous place to put it, if you ask me, but oh well. --ryan. */ #ifdef PLATFORM_DOS koutp(0x20,0x20); #endif oldreadch = readch; readch = _readlastkeyhit(); #if 0 printf("keyhandler() got a (0x%X) ... \n", readch); #endif /* * ryan sez: these inp/outp calls read the keyboard state, * reset the keyboard, and put the original state back in. * This is apparently needed on some XTs, but not newer boxes, and * obviously never on Linux. --ryan. */ #ifdef PLATFORM_DOS keytemp = kinp(0x61); koutp(0x61,keytemp|128); koutp(0x61,keytemp&127); #else keytemp = readch; #endif if ((readch|1) == 0xe1) { extended = 128; return; } if (oldreadch != readch) { if ((readch&128) == 0) { keytemp = readch+extended; if (keystatus[keytemp] == 0) { keystatus[keytemp] = 1; keyfifo[keyfifoend] = keytemp; keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1; keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1)); } } else { keytemp = (readch&127)+extended; keystatus[keytemp] = 0; keyfifo[keyfifoend] = keytemp; keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 0; keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1)); } } extended = 0;}static void _initkeys(void){ long i; keyfifoplc = 0; keyfifoend = 0; for(i=0;i<256;i++) keystatus[i] = 0; initkeys(); /* rcg06082001 platform driver-specific initialization. */}#define loadbyte(fil,tempbuf,bufplc,dat) \{ \ if (bufplc == 0) \ { \ for(bufplc=0;bufplc<4096;bufplc++) \ tempbuf[bufplc] = 0; \ bufplc = 0; \ read(fil,tempbuf,4096); \ } \ dat = tempbuf[bufplc]; \ bufplc = ((bufplc+1)&4095); \} \int loadnames(void){ char buffer[80], firstch, ch; long fil, i, num, buffercnt, bufplc; if ((fil = open("names.h",O_BINARY|O_RDWR,S_IREAD)) == -1) return(-1); bufplc = 0; do { loadbyte(fil,tempbuf,bufplc,firstch); } while (firstch != '#'); while ((firstch == '#') || (firstch == '/')) { do { loadbyte(fil,tempbuf,bufplc,ch); } while (ch > 32); buffercnt = 0; do { loadbyte(fil,tempbuf,bufplc,ch); if (ch > 32) buffer[buffercnt++] = ch; } while (ch > 32); num = 0; do { loadbyte(fil,tempbuf,bufplc,ch); if ((ch >= 48) && (ch <= 57)) num = num*10+(ch-48); } while ((ch != '\r') && (ch != '\n')); for(i=0;i<buffercnt;i++) names[num][i] = buffer[i]; names[num][buffercnt] = 0; loadbyte(fil,tempbuf,bufplc,firstch); while ((firstch == '\r') || (firstch == '\n')) loadbyte(fil,tempbuf,bufplc,firstch); } close(fil); return(0);}void initcrc(void){ long i, j, k, a; for(j=0;j<256;j++) /* Calculate CRC table */ { k = (j<<8); a = 0; for(i=7;i>=0;i--) { if (((k^a)&0x8000) > 0) a = ((a<<1)&65535) ^ 0x1021; /* 0x1021 = genpoly */ else a = ((a<<1)&65535); k = ((k<<1)&65535); } crctable[j] = (a&65535); }}void initmenupaths(char *filename){ long i; strcpy(curpath,filename); i = 0; while ((i < 80) && (curpath[i] != 0)) i++; while ((i > 0) && (curpath[i] != 92)) i--; curpath[i] = 0; strcpy(menupath,curpath);}void showmouse(void){ long i; for(i=1;i<=4;i++) { plotpixel(searchx+i,searchy,whitecol); plotpixel(searchx-i,searchy,whitecol); plotpixel(searchx,searchy-i,whitecol); plotpixel(searchx,searchy+i,whitecol); }}void fixrepeats(short i){ long dax, day, dist; dax = wall[wall[i].point2].x-wall[i].x; day = wall[wall[i].point2].y-wall[i].y; dist = ksqrt(dax*dax+day*day); dax = wall[i].xrepeat; day = wall[i].yrepeat; wall[i].xrepeat = (char)min(max(mulscale10(dist,day),1),255);}long gettile(long tilenum){ char snotbuf[80]; long i, j, k, otilenum, topleft, gap, temp, templong; long xtiles, ytiles, tottiles; xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles; otilenum = tilenum; keystatus[0x2f] = 0; for(i=0;i<MAXTILES;i++) { localartfreq[i] = 0; localartlookup[i] = i; } if ((searchstat == 1) || (searchstat == 2)) for(i=0;i<numsectors;i++) { localartfreq[sector[i].ceilingpicnum]++; localartfreq[sector[i].floorpicnum]++; } if (searchstat == 0) for(i=0;i<numwalls;i++) localartfreq[wall[i].picnum]++; if (searchstat == 4) for(i=0;i<numwalls;i++) localartfreq[wall[i].overpicnum]++; if (searchstat == 3) for(i=0;i<MAXSPRITES;i++) if (sprite[i].statnum < MAXSTATUS) localartfreq[sprite[i].picnum]++; gap = (MAXTILES>>1); do { for(i=0;i<MAXTILES-gap;i++) { temp = i; while ((localartfreq[temp] < localartfreq[temp+gap]) && (temp >= 0)) { templong = localartfreq[temp]; localartfreq[temp] = localartfreq[temp+gap]; localartfreq[temp+gap] = templong; templong = localartlookup[temp]; localartlookup[temp] = localartlookup[temp+gap]; localartlookup[temp+gap] = templong; if (tilenum == temp) tilenum = temp+gap; else if (tilenum == temp+gap) tilenum = temp; temp -= gap; } } gap >>= 1; } while (gap > 0); localartlookupnum = 0; while (localartfreq[localartlookupnum] > 0) localartlookupnum++; if (localartfreq[0] == 0) { tilenum = otilenum; localartlookupnum = MAXTILES; for(i=0;i<MAXTILES;i++) localartlookup[i] = i; } topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom); if (topleft < 0) topleft = 0; if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); while ((keystatus[0x1c]|keystatus[1]) == 0) { drawtilescreen(topleft,tilenum); if ((vidoption != 2) && ((vidoption != 1) || (vgacompatible == 1))) limitrate(); nextpage(); synctics = totalclock-lockclock; lockclock += synctics; if ((keystatus[0x37] > 0) && (gettilezoom < 2)) { gettilezoom++; topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom); if (topleft < 0) topleft = 0; if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); keystatus[0x37] = 0; } if ((keystatus[0xb5] > 0) && (gettilezoom > 0)) { gettilezoom--; topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom); if (topleft < 0) topleft = 0; if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); keystatus[0xb5] = 0; } if ((keystatus[0xcb] > 0) && (tilenum > 0)) tilenum--, keystatus[0xcb] = 0; if ((keystatus[0xcd] > 0) && (tilenum < MAXTILES-1)) tilenum++, keystatus[0xcd] = 0; if ((keystatus[0xc8] > 0) && (tilenum >= (xtiles<<gettilezoom))) tilenum-=(xtiles<<gettilezoom), keystatus[0xc8] = 0; if ((keystatus[0xd0] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom))) tilenum+=(xtiles<<gettilezoom), keystatus[0xd0] = 0; if ((keystatus[0xc9] > 0) && (tilenum >= (xtiles<<gettilezoom))) { tilenum-=(tottiles<<(gettilezoom<<1)); if (tilenum < 0) tilenum = 0; keystatus[0xc9] = 0; } if ((keystatus[0xd1] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom))) { tilenum+=(tottiles<<(gettilezoom<<1)); if (tilenum >= MAXTILES) tilenum = MAXTILES-1; keystatus[0xd1] = 0; } if (keystatus[0x2f] > 0) /* V */ { keystatus[0x2f] = 0; if (tilenum < localartlookupnum) tilenum = localartlookup[tilenum]; else tilenum = 0; localartlookupnum = MAXTILES; for(i=0;i<MAXTILES;i++) localartlookup[i] = i; } if (keystatus[0x22] > 0) /* G (goto) */ { if (tilenum < localartlookupnum) /* Automatically press 'V' */ tilenum = localartlookup[tilenum]; else tilenum = 0; localartlookupnum = MAXTILES; for(i=0;i<MAXTILES;i++) localartlookup[i] = i; keystatus[0x22] = 0; j = tilenum; while (keystatus[1] == 0) { drawtilescreen(topleft,tilenum); if ((vidoption != 2) && ((vidoption != 1) || (vgacompatible == 1))) limitrate(); sprintf(snotbuf,"Goto tile: %ld_ ",j); printext256(0,0,whitecol,0,snotbuf,0); nextpage(); for(k=0;k<10;k++) if (keystatus[((k+9)%10)+2] > 0) { keystatus[((k+9)%10)+2] = 0; i = (j*10)+k; if (i < MAXTILES) j = i; } if (keystatus[0xe] > 0) { keystatus[0xe] = 0; j /= 10; } if (keystatus[0x1c] > 0) { keystatus[0x1c] = 0; tilenum = j; break; } } } while (tilenum < topleft) topleft -= (xtiles<<gettilezoom); while (tilenum >= topleft+(tottiles<<(gettilezoom<<1))) topleft += (xtiles<<gettilezoom); if (topleft < 0) topleft = 0; if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1)); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -