1 ////////////////////////////////////////////////////
4 // MultiVideo mode, MultiTile size, MultiMap editor
5 // by John Romero (C) 1991 Id Software
8 // -------------------------------------------------
9 // Mar 19 91 - Starting this thing! Getting it to
10 // compile with the JHUFF and MEM stuff.
12 // Mar 20 91 - Got the whole deal compiling and wrote
13 // the EGA drawchar routine and got most of
16 // Mar 25 91 - Forgot some days in there! Got the XMS
17 // stuff going and started the big initialization
18 // part. Past init will be lots easier!
20 // Mar 30 91 - Got map selection and dimensioning and
21 // allocation done. Added more MENU abilities to
22 // allow more flexible dialogs.
24 // Apr 7 91 - Got project initialization done. Got
25 // tiles into XMS. Wrote XMS routines for all
26 // memory functions needed.
28 // Apr 12 91 - FINALLY got the maps loading and saving
29 // correctly - NO THANKS TO MR.C OVER THERE! You
30 // see, he can't remember whether his expansion
31 // routines use the compressed or expanded length
32 // and that was causing me quite a problem. Got
33 // it solved and the map shuffling shit works
34 // PERFECTLY now! Got tile select in, map stats,
37 // Apr 19 91 - Got all 3 planes working (drawing,etc.)
38 // TileSelect screens jam...lots of little options
39 // thrown in... !!! I got my '75 Cougar !!!
41 // Apr 25 91 - Got map dimension changing done! Fixed
42 // some small bugs...had a WHOPPER of a fucking
43 // bug today ... I was overwriting the stack
44 // when the first background save happened. I'm SURE
45 // I allocated enough memory -- I don't know...
47 // Apr 27 91 - Map Edge Select works (for Copy) & now I
48 // draw a frame around the entire region.
50 // May 01 91 - Added a nice feature - retaining the Copy
51 // buffer wherever it may get toasted. Used XMS so
52 // I didn't chew mainmem. Also made it so you can
53 // turn the plane READ/WRITEs ON/OFF (obvious advantage).
54 // Got Copy/Paste from everywhere with FloatingPaste!
56 // May 03 91 - Got entering values for infoplane stuff & all
57 // that shit encompasses. Trying to get a cursor drawn
58 // (with backgrnd save/restore) in CGA & EGA3 modes.
59 // Wish me luck! ... FUCK IT! I removed EGA3 mode -- it
60 // was too much shit & kludgery to get a cursor going.
62 // May 08 91 - Well! Let's see...I got Huffman map compression
63 // done; wrote a MakeOBJ function that can be used within
64 // the Memory Manager or Standard Borland C. Added .OBJ
65 // generation to IGRAB. Started the function to generate
66 // graphic map dumps. Modified the MapHeader stuff more
67 // when John needed "extras".
69 // May 09 91 - Finished ILBM & Apple Preferred map dumps!
70 // Fixed a couple hidden bugs, made some things nicer,
71 // started on Flood Fill...
73 // May 11 91 - Got the TILEINFO/M stuff structured and loading
74 // and saving (with compression). Putting all the "hidden"
75 // commands in the menus...
77 // May 13 91 - Stuck in a PROJECT SELECT option (for the Keen2
78 // trilogy, it'll be nice).
80 // May 16 91 - Got all of TILEINFO stuff finished. Tom and
81 // Jason's first day! Tom BETAed IGRAB & TED5 big time.
82 // Had to basically dump the GraphHeaderStr and just
83 // make the ?GAHEAD.ext file all dataoffsets! (The simpler,
86 // May 19 91 - Almost got the Flood Fill mode working...Tom
87 // started drawing maps a little early & now I need to add
88 // a little kludge-fix to reformat his old maps...
90 // May 22 91 - Got AWESOME UNDO working ... fixed the nagging little
91 // paste/scrolling bug fixed (separated the PasteErase
92 // & PasteDraw routines) ... finished Block Fill ... fixed
93 // the floating paste/tile showthru bug ...
95 // May 27 91 - Basically finished up. Tom is BETAing now. I need
96 // to make SelectMap accept the arrows & make an array for
97 // the map names instead of the sorry way I'm doing it now.
99 // Jun 2 91 - Got level launching working! Been working on
100 // TED5 and IGRAB docs and MUSE most of the time.
102 // Jun 18 91 - v0.13 because John C.'s system didn't have
103 // the SCmapmask set to 15 in CopyEGA!
105 // Jun 20 91 - v0.14: It's annoying to LAUNCH the game and come
106 // back at the top-left corner!
108 // Jun 26 91 - v0.17: Made LAUNCH with ICON CHANGE ctrl-alt-L
109 // because Tomshit was having problems...adding Unused Tile
110 // Scan...fixing a couple minor Tom-irritants...
112 // Jul 12 91 - v0.23: Made VGA & CGA work! Fixed a small
113 // bug with plane-on starting...added a GridMode for the
114 // FloatingPaste...XMS Map-Cache...now saves the Launchname
115 // in TEDINFO? so user program doesn't need to send anything
116 // back but /LAUNCHED...finally fixed nagging FloatingPaste
117 // multi-plane viewing bug...
119 // Jul 19 91 - v0.24: Changed TEDINFO structure and added GFXINFO
120 // to IGRAB. Got most all bugs out...lowercase input now...
122 // Jul 23 91 - v0.26: Only write out .H if it needs to...got the
123 // SnapPaste feature in that Tom wanted...
125 // Aug 08 91 - v0.28: I can't believe this shit! Mr. Tom decided
126 // to enter the value "0xF00D" into the map, which was my secret
127 // value for passing an ESC press back from "inputint". I made
130 // Aug 09 91 - v0.29: I FUCKING FRIED THE LIB_A.ASM & LIB.C FILES!
131 // THESE USED TO HOLD TED5'S TILE-DRAWING AND CGA/VGA ROUTINES!
132 // AAAARRRRGGGG!!!! Trying to recontruct the program. It'll
133 // take a bit (I was trying to fix a bug in EditMapNames).
135 // Aug 14 91 - v0.30: Just got finished fixing the FRIED SOURCE HELL!
137 // Aug 16 91 - v0.31: Heh heh, I added the ViewMap function!
139 // Aug 19 91 - v0.32: Added the MapImport function and it works! YES!
141 // Aug 22-23 - v0.35: Fixed a WHOLE BUNCH of little things and added
142 // some cool features like easier TILEINFO entering, default
143 // Import drive, F3 to toggle Paste Overlay, etc. Very nice now.
145 // Aug 24 91 - v0.38: Fixed a bug in passing multiple command-line
146 // parameters to LAUNCHed program. Let user enter new parms and
147 // a new launch name while in TED5. Added the CarmackCompression
148 // and trashed the Huffman shit.
150 // Sep 07 91 - v0.40: Only ViewMap planes viewable instead of all; flag
151 // currently loaded map in SelectMap dialog; check NumIconRows for
152 // a bogus value for old TED5 compatibility; show map dimensions in
153 // ChangeMapEdges dialog; CTRL-ALT-arrows will go to map edges.
155 // Sep 12 91 - v0.41: Let user PERMANENTLY change the Launch icon. Also,
156 // the plane flags are always saved!
158 // Sep 27 91 - v0.43: Added REVIEW_MAP function. Fixed a hard-to-find bug
159 // in the BlockFill-with-pattern function.
161 // Sep 29 91 - v0.44: Fixed small annoying bug w/Flood-fill w/pattern.
163 // Oct 12 91 - v0.45: Added the PrintReport feature after Carmacizing
166 // Nov 24 91 - v0.48: Saving the Import Path, added TILEINFOM copying
167 // from one area to another, getting rid of the "turning the plane
168 // viewing ON automatically sets it for writing."
170 // May 22 92 - v0.49: Added graphics-select switch to get rid of a dialog.
172 // Oct 20 95 - v0.50: Fixed EGA scrolling bug, added screensaver which comes
173 // on automatically after 2 minutes. Timelimit adjustable
174 // through TIMELIMIT command line MED
176 ////////////////////////////////////////////////////
180 extern unsigned _stklen=0x2000;
182 ////////////////////////////////////////////////////
186 ////////////////////////////////////////////////////
187 extern char far TEDCHAR,far VGAPAL,tdata;
188 extern unsigned doubled[256];
192 MapFileHeaderStr _seg *MapFileHeader;
193 char _seg *Tinfo[10],_seg *TMinfo[10],_seg *GraphHeader;
194 long _seg *XMSlookup,_seg *EgaXMSlookup,_seg *CgaXMSlookup,_seg *VgaXMSlookup;
195 int _seg *MapBkgnd,_seg *MapFrgnd,_seg *MapInfoPl,
196 _seg *CutBkgnd,_seg *CutFrgnd,_seg *CutInfoPl;
197 MapHeaderStr MapHeader;
199 TempStruct LaunchInfo;
200 InfoStruct _seg *TEDInfo;
201 GfxStruct _seg *GFXInfo;
202 video lastvideo,videomode;
203 screentype whichscreen=TILES;
206 char launchname[64],ext[4],format[2],projname[64],mapname[64],planes,
207 infoname[64],mapheadname[64],MapNames[100][16],parmstring[64];
208 char SM_name[64],SM_loadname[64],BkgndColor,GfxToUse;
210 unsigned temp,whichmap,numtplanes,tilenum,tilemnum,numtmplanes,left,
211 DirtyFlag,tilelen,tilemlen,whicht,whichtm,whichi,
212 tsize,infoy,infomaxw,mapwidth,mapheight,screenw,usingbat,
213 screenh,planeton,planemon,planeion,maxiconrows,lasticon,firsticon,
214 viewton,viewmon,viewion,XMSundoB,XMSundoF,XMSundoI,launched,
215 XMSmaps,EgaXMS,CgaXMS,VgaXMS,xmshandle,GridMode,SnapMode,snapx,
216 snapy,snapxsize,snapysize,writeH,NoAbout,F3_flag;
217 int tilebase=0,tilembase=0,infobaron=1,xbase,ybase,scrnbot,scrnrgt,
218 FillMode=0,PasteMode=0,SelectMode=0,SelX1=-1,SelY1=-1,PasteOK=0,SelX2=-1,
219 SelY2=-1,pixelx,pixely,selectcols,px,py,lastmap=-1,TIybase,TIymbase,TIxbase,
220 TIxmbase,BfillMode,Plotting,TsearchMode,NoXMSFlag;
221 long CgaXMSsize,EgaXMSsize,VgaXMSsize;
222 long tics, tictime=1092L*2L;
226 // harderr-called routine
234 ////////////////////////////////////////////////////
236 // Start of The Beast From Hell
238 ////////////////////////////////////////////////////
249 DeskEventLoop(HandleEvent,Continuous);
252 ////////////////////////////////////////////////////
254 // Parse the commandline
256 ////////////////////////////////////////////////////
257 void ParseCmdline(void)
261 for (i=1;i<_argc;i++)
263 _argv[i]=strupr(_argv[i]);
265 if (_argv[i][0]=='-' || _argv[i][0]=='/')
268 if (!strcmp(_argv[i],"?"))
270 printf(TITLESTR" by John Romero (C) 1991 Id Software, Inc.\n\n");
271 printf("Command Line parameters:\n");
272 printf("/? : gets this stuff\n");
273 printf("/EXT=??? : set the project extension\n");
274 printf("<filename> : set the Launch filename\n");
275 printf("/PARMS=<string> : set parms to Launch with\n");
276 printf("/NOXMSMAPS : don't cache maps in XMS\n");
277 printf("/GFX=??? : set gfx to use - E,C,V\n");
278 printf("/TIME=??? : half-minutes until screenblanker (default 2 minutes)\n");
282 if (!strncmp(_argv[i],"EXT=",4))
283 strcpy(ext,&_argv[i][4]);
285 if (!strncmp(_argv[i],"GFX=",4))
286 GfxToUse = _argv[i][4];
288 if (!strcmp(_argv[i],"LAUNCH"))
291 if (!strcmp(_argv[i],"BAT"))
294 if (!strncmp(_argv[i],"PARMS=",6))
295 strcpy(parmstring,&_argv[i][6]);
297 if (!strncmp(_argv[i],"TIME=",5))
298 tictime=(atol(&_argv[i][5]))*546L;
300 if (!strcmp(_argv[i],"NOXMSMAPS"))
303 if (!strcmp(_argv[i],"NOABOUT"))
306 strcpy(launchname,_argv[i]);
311 ////////////////////////////////////////////////////
313 // Event handler - called when button is pressed
316 ////////////////////////////////////////////////////
317 void HandleEvent(void)
319 int pixelx,pixely,mx,my,b0,b1;
323 b1=(MouseButton()>>1)&1;
325 MouseCoords(&mx,&my);
330 // PLOT OR PICK-UP TILE
332 if (my>=8 && my<infoy*8 && (b0 || b1))
334 mx=xbase+(mx>>(tsize+2));
335 my=ybase+((my-8)>>(tsize+2));
339 if (mx>=mapwidth || my>=mapheight)
346 // SELECT BOTTOM-RIGHT EDGE
348 if (SelectMode || BfillMode)
352 if ((SelX1==-1 && SelY1==-1) ||
353 (SelX2<SelX1 || SelY2<SelY1))
367 while(MouseButton());
368 DoFloodFill(mx,my,1);
376 whicht=*(MapBkgnd+loc);
378 whichtm=*(MapFrgnd+loc)+tilenum;
380 whichi=*(MapInfoPl+loc)+tilenum;
384 // IF WE'RE IN TILESEARCH MODE, SHOW IT!
389 while(MouseButton()>>1);
395 // SELECT TOP-LEFT EDGE
397 if (SelectMode || BfillMode)
401 if ((SelX2==-1 && SelY2==-1) ||
402 (SelX1>SelX2 || SelY1>SelY2))
410 while(MouseButton());
418 while(MouseButton());
419 DoFloodFill(mx,my,0);
422 // PASTE A CHUNK O' TILES/MAP
427 if (TileCopy.MapOrTileSelect) // TILE-SELECT AREA?
433 mx=(mx/snapxsize)*snapxsize+snapx;
434 my=(my/snapysize)*snapysize+snapy;
437 if (mx+TileCopy.w>mapwidth ||
438 my+TileCopy.h>mapheight)
445 UndoRegion.w=TileCopy.w;
446 UndoRegion.h=TileCopy.h;
449 switch(TileCopy.MapOrTileSelect)
452 for (j=0;j<TileCopy.h;j++)
453 for (i=0;i<TileCopy.w;i++)
455 int val=(j+TileCopy.y)*selectcols+TileCopy.x+i;
456 if (XMSlookup[val]!=-1)
457 MapBkgnd[(my+j)*mapwidth+mx+i]=val;
461 for (j=0;j<TileCopy.h;j++)
462 for (i=0;i<TileCopy.w;i++)
464 int val=(j+TileCopy.y)*selectcols+TileCopy.x+i+tilenum+maxiconrows*selectcols;
465 if (XMSlookup[val]!=-1)
466 MapFrgnd[(my+j)*mapwidth+mx+i]=val-tilenum;
473 while(MouseButton());
482 mx=(mx/snapxsize)*snapxsize+snapx;
483 my=(my/snapysize)*snapysize+snapy;
486 if (mx+TileCopy.w-1<mapwidth && my+TileCopy.h-1<mapheight)
492 UndoRegion.w=TileCopy.w;
493 UndoRegion.h=TileCopy.h;
495 for (j=0;j<TileCopy.h;j++)
496 for (i=0;i<TileCopy.w;i++)
501 if (TileCopy.PlanesCopied&BPLANE)
502 MapBkgnd[(j+my)*mapwidth+mx+i]=
503 CutBkgnd[(j+TileCopy.y)*mapwidth+TileCopy.x+i];
504 if (TileCopy.PlanesCopied&FPLANE)
506 theM=CutFrgnd[(j+TileCopy.y)*mapwidth+TileCopy.x+i];
508 MapFrgnd[(j+my)*mapwidth+mx+i]=theM;
510 if (TileCopy.PlanesCopied&IPLANE)
512 theI=CutInfoPl[(j+TileCopy.y)*mapwidth+TileCopy.x+i];
514 MapInfoPl[(j+my)*mapwidth+mx+i]=theI;
524 while(MouseButton());
532 unsigned oldt,oldm,oldi;
535 // ARE WE STARTING THE PLOTTING REGION?
542 UndoRegion.w=UndoRegion.h=1;
547 // FLOAT THE PLOTTING REGION
553 if (mx+1>UndoRegion.x+UndoRegion.w)
554 UndoRegion.w=mx-UndoRegion.x+1;
555 if (my+1>UndoRegion.y+UndoRegion.h)
556 UndoRegion.h=my-UndoRegion.y+1;
559 *(MapBkgnd+loc)=whicht;
561 *(MapFrgnd+loc)=whichtm-tilenum;
563 *(MapInfoPl+loc)=whichi-tilenum;
566 oldm=MapFrgnd[loc]+tilenum;
567 oldi=MapInfoPl[loc]+tilenum;
569 CombineTiles(viewton?oldt:-BkgndColor,viewmon*oldm,oldi*viewion,tsize);
573 DrawTile((mx-xbase)<<(tsize-1),(my-ybase)*(4<<tsize)+8,tsize);
574 CheckInfoValues(mx-xbase,my-ybase,oldi);
586 if (b0 && pixely>infoy*8)
591 if (pixelx<8*14 && tilemnum)
594 if (pixelx<8*20 && tilemnum)
600 #define PEL_WRITE_ADR 0x3c8
601 #define PEL_READ_ADR 0x3c7
602 #define PEL_DATA 0x3c9
603 #define PEL_MASK 0x3c6
605 void ScreenBlank ( void )
624 unsigned char far * screen=(unsigned char far *)0xa0000000l;
643 outp (PEL_WRITE_ADR,0);
646 outp (PEL_DATA, (unsigned char)((i*r)>>10));
647 outp (PEL_DATA, (unsigned char)((i*g)>>10));
648 outp (PEL_DATA, (unsigned char)((i*b)>>10));
652 xdir=random(size<<1)-size;
655 ydir=random(size<<1)-size;
658 if ((random(100)-80)>0)
667 if ((snake[0].x<size+1) || (snake[0].x>320-(size+1)))
672 else if (abs(xdir)>size-1)
674 if ((snake[0].y<size+1) || (snake[0].y>200-(size+1)))
679 else if (abs(ydir)>size-1)
685 for (j=snake[x].y,cury=320*snake[x].y;j<snake[x].y+size;j++,cury+=320)
686 _fmemset((screen+cury+snake[x].x),255-x,size);
690 _fmemset((screen+(320*snake[x].y)+snake[x].x),255-x,size);
695 MouseCoords(&pixelx,&pixely);
696 if ((oldx!=pixelx) || (oldy!=pixely))
704 ////////////////////////////////////////////////////
706 // Routine called continuously by DeskEventLoop
708 ////////////////////////////////////////////////////
709 void Continuous(void)
711 static int oldx, oldy;
712 if (biostime(0,0)-tics>tictime)
727 MouseCoords(&pixelx,&pixely);
728 if ((oldx!=pixelx) || (oldy!=pixely))
738 // PLANE "WRITE" SELECTION
740 if (keydown[2] && viewton)
749 if (keydown[3] && tilemnum && (MapFileHeader->maptype&FPLANE) && viewmon)
758 if (keydown[4] && (MapFileHeader->maptype&IPLANE) && viewion)
769 // PLANE "VIEW" SELECTION
782 if (keydown[6] && tilemnum && (MapFileHeader->maptype&FPLANE))
793 if (keydown[7] && (MapFileHeader->maptype&IPLANE))
806 // Cancel COPY or PASTE or FLOOD FILL or BLOCK FILL
808 if (keydown[1] && (PasteMode || SelectMode || FillMode ||
809 BfillMode || TsearchMode))
819 SnapMode=TsearchMode=BfillMode=FillMode=PasteMode=SelectMode=0;
820 SelX1=SelX2=SelY1=SelY2=-1;
827 // END OF COPY || BLOCK FILL
829 if (keydown[0x1c] && (SelectMode || BfillMode))
834 while(keydown[0x1c]);
857 SelX1=SelX2=SelY1=SelY2=-1;
869 TileCopy.w=SelX2-SelX1+1;
870 TileCopy.h=SelY2-SelY1+1;
871 TileCopy.MapOrTileSelect=0;
872 TileCopy.PlanesCopied=planeton*BPLANE | planemon*FPLANE | planeion*IPLANE;
878 for (j=SelY1;j<=SelY2;j++)
879 for (i=SelX1;i<=SelX2;i++)
882 CutBkgnd[j*mapwidth+i]=MapBkgnd[j*mapwidth+i];
884 CutFrgnd[j*mapwidth+i]=MapFrgnd[j*mapwidth+i];
886 CutInfoPl[j*mapwidth+i]=MapInfoPl[j*mapwidth+i];
890 SelX1=SelX2=SelY1=SelY2=-1;
900 // See if we want to scroll the map!
903 CheckFloatPaste((pixelx>>(tsize+2))+xbase,((pixely-8)>>(tsize+2))+ybase);
906 ////////////////////////////////////////////////////
908 // Draw the current map on the screen at xbase,ybase
910 ////////////////////////////////////////////////////
929 unsigned tilet,tilem,tilei,loc;
931 loc=(ybase+j)*mapwidth+xbase+i;
933 tilet=*(MapBkgnd+loc);
934 tilem=*(MapFrgnd+loc)+tilenum;
935 tilei=*(MapInfoPl+loc)+tilenum;
937 CombineTiles(tilet*viewton-BkgndColor*(!viewton),tilem*viewmon,tilei*viewion,tsize);
940 DrawTile(i<<(tsize-1),j*(4<<tsize)+8,tsize);
941 CheckInfoValues(i,j,tilei);
942 CheckSelectEdges(i+xbase,j+ybase,i,j);
949 ////////////////////////////////////////////////////
951 // Figure out SCREENW,SCREENH from videomode & tsize
953 ////////////////////////////////////////////////////
954 void FigureScreenEdges(void)
961 screenw=40>>(tsize-1);
962 screenh=22>>(tsize-1);
965 screenw=80>>(tsize-1);
966 screenh=57>>(tsize-1);
971 infoy=100; // WAY OFF THE BOTTOM!
972 screenh+=2*(tsize==1)+(tsize==2);
977 ////////////////////////////////////////////////////
979 // Print the coords on the INFOBAR
981 ////////////////////////////////////////////////////
982 void PrintCoords(void)
991 MouseCoords(&mx,&my);
992 if (my<8 || my>=infoy*8)
1015 my=(my-8)>>(tsize+2);
1025 ////////////////////////////////////////////////////
1029 ////////////////////////////////////////////////////
1030 void DrawInfoBar(void)
1038 CheckFloatPaste((pixelx>>(tsize+2))+xbase,((pixely-8)>>(tsize+2))+ybase);
1052 oy=sy=23-2*(tsize==3);
1056 oy=sy=58-2*(tsize==3)-1*(tsize==2);
1062 bar(0,infoy,infomaxw-1,infoy+1,' ');
1068 print("Copy Mode\nESC to exit");
1075 print("Tile Search Mode\nESC to exit");
1082 print("Block Fill Mode\nESC to exit");
1089 print("Paste Mode\nESC to exit");
1096 print("Flood Fill Mode\nESC to exit");
1100 CombineTiles(whicht,0,0,tsize);
1101 DrawTile(ox,oy*8+8*(tsize==1),tsize);
1102 sx=ox+2+2*(tsize==3);
1113 CombineTiles(-BkgndColor,whichtm,0,tsize);
1114 DrawTile(ox,oy*8+8*(tsize==1),tsize);
1115 sx=ox+2+2*(tsize==3);
1117 (whichtm==tilenum)?print(" No "):printhex(whichtm-tilenum);
1120 (whichtm==tilenum)?print("Tile"):printint(whichtm-tilenum);
1124 CombineTiles(-ICONBACK,(whichi>lasticon)?firsticon:whichi,0,tsize);
1125 DrawTile(ox,oy*8+8*(tsize==1),tsize);
1126 sx=ox+2+2*(tsize==3);
1128 (whichi==tilenum)?print(" No "):printhex(whichi-tilenum);
1131 (whichi==tilenum)?print("Icon"):printint(whichi-tilenum);
1144 sx=infomaxw-((videomode==EGA2)?19:18);
1149 sx=infomaxw-((videomode==EGA2)?21:20);
1155 sx=infomaxw-((videomode==EGA2)?20:19);
1159 sx=infomaxw-((videomode==EGA2)?19:18);
1161 (planeton)?print("B"):print(" ");
1162 (planemon)?print("F"):print(" ");
1163 (planeion)?print("I"):print(" ");
1170 (viewton)?print("b"):print(" ");
1171 (viewmon)?print("f"):print(" ");
1172 (viewion)?print("i"):print(" ");
1174 if (videomode==EGA2)
1176 sx=screencenterx-strlen(MapHeader.name)/2;
1178 print(MapHeader.name);
1186 ////////////////////////////////////////////////////
1187 ////////////////////////////////////////////////////
1188 ////////////////////////////////////////////////////
1192 // * Project Select if multiple projects
1193 // * If Project has NO LEVELS:
1196 // * Init TEDINFO file
1197 // * Load TILES into XMS
1199 ////////////////////////////////////////////////////
1200 ////////////////////////////////////////////////////
1201 ////////////////////////////////////////////////////
1202 char bstrings[10][15];
1203 btype ProjButns[10];
1204 DialogDef ProjSelect={"Select the project to work on:",
1205 30,0,0,&ProjButns[0],DrawProjBord};
1210 unsigned i,loop,which;
1216 ErrDialog("Sorry, but TED5 will NOT\n"
1217 "operate without a mouse!\n"," Press ENTER ");
1218 Quit("Only REAL developers have a mouse!");
1222 ErrDialog("Initializing. One moment.","");
1224 // Create bit-doubling lookup table
1225 // for CGA font creation
1227 for (loop=0;loop<256;loop++)
1229 unsigned result,temp=loop;
1244 doubled[loop]=result;
1255 RestoreBackground();
1257 LoadGraphStuff(0,TEDInfo->lastvid);
1260 if (!launched && !NoAbout)
1266 ////////////////////////////////////////////////////
1267 ////////////////////////////////////////////////////
1269 // Load the MAPTEMP.ext header in...
1271 ////////////////////////////////////////////////////
1272 ////////////////////////////////////////////////////
1273 btype SelectTsizeb[]={{" 8x8 ",1,2,1},
1276 DialogDef SelectTsize={" Which tile size to use?"
1277 ,26,10,3,&SelectTsizeb[0],STnot};
1279 void LoadMapHeader(void)
1281 unsigned size,i,j,pflag;
1285 strcpy(mapheadname,"MAPTHEAD.");
1286 strcat(mapheadname,ext);
1287 strcpy(mapname,"MAPTEMP.");
1288 strcat(mapname,ext);
1289 strcpy(SM_name,"MAPTEMP1.");
1290 strcat(SM_name,ext);
1291 strcpy(SM_loadname,"MAPTEMP.");
1292 strcat(SM_loadname,ext);
1294 if (access(mapheadname,0))
1298 // Gotta create a new map file!
1300 MMAllocate((memptr *)&MapFileHeader,sizeof(MapFileHeaderStr));
1301 for (i=0;i<sizeof(MapFileHeaderStr);i++)
1302 *((char _seg *)MapFileHeader+i)=0;
1304 MapFileHeader->RLEWtag=0xabcd;
1307 MapFileHeader->dataoffsets[i]=-1;
1308 MapFileHeader->datalengths[i]=0;
1309 memset(MapNames[i],0,16);
1312 if (!GFXInfo->num8 &&
1319 ErrDialog("Uhh...you 'neglected' to\n"
1320 "grab tiles to use. Running\n"
1321 "TED5 is quite useless at\n"
1322 "this point, I'm afraid.","Duh!");
1323 Quit("Get some tiles ... quick! Me hungry!");
1326 if (!GFXInfo->num8 &&
1330 ErrDialog("You may have grabbed some\n"
1331 "MASKED tiles, but I require\n"
1332 "NON-MASKED tiles as a\n"
1333 "minimum requirement!","Geez...");
1334 Quit("Please grab some normal tiles!");
1337 types+=(GFXInfo->num8>0)+(GFXInfo->num16>0)+(GFXInfo->num32>0);
1345 which=DoDialog(&SelectTsize);
1355 if (!GFXInfo->num16)
1359 if (!GFXInfo->num32)
1364 MapFileHeader->tsize=TEDInfo->tsize=tsize=which;
1377 MapFileHeader->tsize=tsize=TEDInfo->tsize;
1381 // pick the planes that all maps will use
1383 if (PickMorePlanes())
1387 // initialize TILEINFO/TILEINFOM
1392 tilenum=GFXInfo->num8;
1393 tilemnum=GFXInfo->num8m;
1396 tilenum=GFXInfo->num16;
1397 tilemnum=GFXInfo->num16m;
1400 tilenum=GFXInfo->num32;
1401 tilemnum=GFXInfo->num32m;
1404 if (numtplanes || numtmplanes) // only input if applicable
1405 Item_EditTinfoNames(); // void where prohibited
1407 // now create a map!
1410 FigureScreenEdges();
1411 MapFileHeader->NumIconRows=maxiconrows=InputIconAmount();
1414 // MAP FILE ALREADY IN PLACE. LOAD STUFF IN...
1418 memptr block,tempblock;
1420 LoadIn(mapheadname,(memptr *)&MapFileHeader);
1423 // See if the NumIconRows is toasty (old TED5 compatibility)
1425 if (MapFileHeader->NumIconRows>50)
1426 MapFileHeader->NumIconRows=4;
1429 // has the TEDINFO?.ext file been changed?
1430 // if so, reconstruct pertinent data...
1432 if (!TEDInfo->tsize)
1434 tsize=TEDInfo->tsize=MapFileHeader->tsize;
1438 tilenum=GFXInfo->num8;
1439 tilemnum=GFXInfo->num8m;
1442 tilenum=GFXInfo->num16;
1443 tilemnum=GFXInfo->num16m;
1446 tilenum=GFXInfo->num32;
1447 tilemnum=GFXInfo->num32m;
1451 maxiconrows=MapFileHeader->NumIconRows;
1454 // Read-in all the Map Names
1457 if (MapFileHeader->dataoffsets[i]!=-1)
1459 MapHeaderStr TempHead;
1461 LoadFile(mapname,(char huge *)&TempHead,
1462 MapFileHeader->dataoffsets[i],sizeof(MapHeaderStr));
1463 strcpy(MapNames[i],TempHead.name);
1466 FigureScreenEdges();
1468 if (!TEDInfo->level)
1471 if (MapFileHeader->dataoffsets[i]!=-1)
1473 whichmap=TEDInfo->level=i;
1478 whichmap=TEDInfo->level;
1480 LoadMap(TEDInfo->level);
1483 // IF WE WERE LAUNCHED AND CHARACTER POSITION WAS CHANGED,
1486 if (launched && (TEDInfo->lastx || TEDInfo->lasty))
1490 for (i=0;i<mapwidth*mapheight;i++)
1491 if (MapInfoPl[i]==TEDInfo->permicon)
1494 MapInfoPl[TEDInfo->lasty*mapwidth+TEDInfo->lastx]=TEDInfo->permicon;
1495 TEDInfo->lastx=TEDInfo->lasty=0;
1504 xbase=TEDInfo->oscrx;
1505 ybase=TEDInfo->oscry;
1506 if (xbase+screenw>mapwidth)
1507 xbase=mapwidth-screenw;
1508 if (ybase+screenh>mapheight)
1509 ybase=mapheight-screenh;
1512 _fmemcpy((void far *)parmstring,(void far *)TEDInfo->parmstring,64);
1515 // LOAD TILEINFO/M AND ADJUST IF IT CHANGED
1517 numtplanes=MapFileHeader->numtplanes;
1518 numtmplanes=MapFileHeader->numtmplanes;
1521 for (i=0;i<numtplanes;i++)
1524 // SPACE FOR OLD TILEINFO TO DECOMPRESS INTO
1526 MMAllocate(&tempblock,MapFileHeader->oldtilenum);
1528 // SPACE FOR OLD TILEINFO TO LOAD INTO
1530 MMAllocate(&block,MapFileHeader->tileinfolen[i]);
1531 LoadFile(mapheadname,MK_FP(block,0),MapFileHeader->tileinfooff[i],MapFileHeader->tileinfolen[i]);
1533 // DECOMPRESS FROM "BLOCK" TO "TEMPBLOCK"
1535 RLEBExpand(MK_FP(block,0),MK_FP(tempblock,0),
1536 MapFileHeader->oldtilenum,MapFileHeader->RLEWtag);
1539 // ALLOCATE TINFO ARRAY
1541 MMAllocate((memptr *)&Tinfo[i],tilenum);
1543 // MOVE FROM "TEMPBLOCK" TO "TINFO[I]" ARRAY
1545 if (MapFileHeader->oldtilenum<tilenum)
1547 movedata((unsigned)tempblock,0,(unsigned)Tinfo[i],0,MapFileHeader->oldtilenum);
1549 // IF NEW TILEINFO IS MORE, FILL END WITH 0s
1551 for (j=MapFileHeader->oldtilenum;j<tilenum;j++)
1557 movedata((unsigned)tempblock,0,(unsigned)Tinfo[i],0,tilenum);
1558 if (MapFileHeader->oldtilenum>tilenum)
1562 MMFreePtr(&tempblock);
1568 ErrDialog("The new TILEINFO data has\n"
1569 "been expanded to accomodate\n"
1570 "the newly grabbed tiles."," OK ");
1573 ErrDialog("The new TILEINFO data has\n"
1574 "been shrunk due to a reduced\n"
1575 "amount of tiles."," OK ");
1579 if (tilemnum && (MapFileHeader->maptype&FPLANE))
1580 for (i=0;i<numtmplanes;i++)
1582 MMAllocate(&tempblock,MapFileHeader->oldtilemnum);
1583 MMAllocate(&block,MapFileHeader->tileinfomlen[i]);
1584 LoadFile(mapheadname,MK_FP(block,0),MapFileHeader->tileinfomoff[i],MapFileHeader->tileinfomlen[i]);
1585 RLEBExpand(MK_FP(block,0),MK_FP(tempblock,0),
1586 MapFileHeader->oldtilemnum,MapFileHeader->RLEWtag);
1588 MMAllocate((memptr *)&TMinfo[i],tilemnum);
1589 if (MapFileHeader->oldtilemnum<tilemnum)
1591 movedata((unsigned)tempblock,0,(unsigned)TMinfo[i],0,MapFileHeader->oldtilemnum);
1592 for (j=MapFileHeader->oldtilemnum;j<tilemnum;j++)
1598 movedata((unsigned)tempblock,0,(unsigned)TMinfo[i],0,tilemnum);
1599 if (MapFileHeader->oldtilemnum>tilemnum)
1603 MMFreePtr(&tempblock);
1609 ErrDialog("The new TILEINFOM data has\n"
1610 "been expanded to accomodate\n"
1611 "the newly grabbed masked tiles."," OK ");
1614 ErrDialog("The new TILEINFOM data has\n"
1615 "been shrunk due to a reduced\n"
1616 "amount of tiles."," OK ");
1624 if (MapFileHeader->maptype&FPLANE)
1626 if (MapFileHeader->maptype&IPLANE)
1628 planemon=planeion=0;
1634 // LOAD THE MAPFILE INTO XMS IF ENOUGH ROOM
1636 if (1024L*XMSTotalFree()>2L*filelen(mapname) && !NoXMSFlag)
1638 #define LBCSIZE 0x4000
1640 long size,clen,coff;
1643 size=filelen(mapname);
1644 MMAllocate(&block,LBCSIZE);
1645 XMSmaps=XMSAllocate(size);
1648 // LOAD ENTIRE MAPFILE FROM DISK TO XMS!
1657 LoadFile(mapname,MK_FP(block,0),coff,clen);
1658 XMSmove(0,(long)MK_FP(block,0),XMSmaps,coff,clen);
1668 void STnot(int x,int y)
1673 print("<-Not available");
1676 printint(GFXInfo->num8);
1677 print(" total tiles");
1681 if (!GFXInfo->num16)
1682 print("<-Not available");
1685 printint(GFXInfo->num16);
1686 print(" total tiles");
1690 if (!GFXInfo->num32)
1691 print("<-Not available");
1694 printint(GFXInfo->num32);
1695 print(" total tiles");
1700 ////////////////////////////////////////////////////
1701 ////////////////////////////////////////////////////
1703 // Load the graphheader file & ?GAGRAPH.ext file and stick it in XMS!
1705 ////////////////////////////////////////////////////
1706 ////////////////////////////////////////////////////
1707 int LoadGraphStuff(int rtn,video newvid)
1709 #define NUMFASTDECOMP 100 // # of tiles in fast decompress buffer
1711 char gname[14]="?GAHEAD.",gname1[14]="?GAGRAPH.",_seg *packed,_seg *unpack,
1712 dictname[14]="?GADICT.",hufftable[1020],_seg *CacheBlock;
1713 unsigned index,indexm,num,numm,i,realnum,realnumm,ox,oy,cacheon=0,_seg *tile_len,
1714 _seg *tilem_len,cacheon_h;
1715 long expsize,expmsize,xmsoff=0,unpackoff,unpackmax,unpacksize,
1717 video tempvid,pickedvid;
1725 strcat(dictname,ext);
1727 gname1[0]=format[0];
1728 dictname[0]=format[0];
1733 case 'C': pickedvid=CGA; break;
1734 case 'E': pickedvid=EGA1; break;
1735 case 'V': pickedvid=VGA;
1738 pickedvid=TEDInfo->lastvid;
1741 // VALIDATE GRAPHICS MODE
1743 tempvid=rtn?newvid:pickedvid;
1748 if (access(gname,0))
1755 TEDInfo->lastvid=CGA;
1756 dictname[0]=format[0]=gname1[0]='C';
1758 InitDesktop(TED5MenuBar,1);
1765 if (access(gname,0))
1772 TEDInfo->lastvid=tempvid;
1773 dictname[0]=format[0]=gname1[0]='E';
1775 InitDesktop(TED5MenuBar,1);
1781 if (access(gname,0))
1790 TEDInfo->lastvid=VGA;
1791 dictname[0]=format[0]=gname1[0]='V';
1793 InitDesktop(TED5MenuBar,1);
1801 // FIND HEADER & LOAD IT
1803 if (access(gname,0))
1805 char errstr[100]="Can't find the ";
1807 strcat(errstr,format);
1808 strcat(errstr,"GAHEAD.");
1810 strcat(errstr,"\nfile! Maybe you didn't\n"
1811 "copy it from the graphics\n"
1814 ErrDialog(errstr," OK ");
1817 Quit("You're stupid! Copy the damn file!");
1820 LoadIn(gname,(memptr *)&GraphHeader);
1822 switch(MapFileHeader->tsize)
1825 index=GFXInfo->off8;
1826 indexm=GFXInfo->off8m;
1828 numm=GFXInfo->num8m;
1829 if (indexm==index+1)
1831 ErrDialog("I'm sorry, but you need to\n"
1832 "capture your 8x8 tiles\n"
1833 "individually, and not in a\n"
1834 "big chunk."," Alright ");
1837 Quit("Regrab-time, bag o' shit!");
1842 case CGA: expsize=16; expmsize=32; break;
1844 case EGA2: expsize=32; expmsize=40; break;
1845 case VGA: expsize=64; expmsize=128;
1849 index=GFXInfo->off16;
1850 indexm=GFXInfo->off16m;
1852 numm=GFXInfo->num16m;
1855 case CGA: expsize=64; expmsize=128; break;
1857 case EGA2: expsize=128; expmsize=128+32; break;
1858 case VGA: expsize=256; expmsize=512;
1862 index=GFXInfo->off32;
1863 indexm=GFXInfo->off32m;
1865 numm=GFXInfo->num32m;
1868 case CGA: expsize=256; expmsize=512; break;
1870 case EGA2: expsize=512; expsize=512+4*32; break;
1871 case VGA: expsize=1024; expmsize=2048;
1876 // MOVE TILES INTO XMS MEMORY!
1879 MMAllocate((memptr *)&packed,expmsize);
1880 unpackmax=expmsize*NUMFASTDECOMP;
1881 MMAllocate((memptr *)&unpack,unpackmax);
1886 offsets=MK_FP(GraphHeader,0);
1889 // LOAD DICTIONARY IN & INITIALIZE IT
1895 if (access(dictname,0))
1897 char errst[200]="I can't find the \n";
1899 strcat(errst,dictname);
1900 strcat(errst," file!");
1902 ErrDialog(errst," OK ");
1905 Quit("Look in the graphics grab directory!");
1908 LoadIn(dictname,(memptr *)&block);
1909 movedata((unsigned)block,0,FP_SEG(hufftable),FP_OFF(hufftable),1020);
1910 MMFreePtr((memptr *)&block);
1911 OptimizeNodes((huffnode *)hufftable);
1915 // Count up the REAL number of tiles there are!
1916 // Build tables for tile lengths
1918 MMAllocate((memptr *)&tile_len,num*2);
1919 for (realnum=i=0;i<num;i++)
1925 if (OFF3(offsets,i+index)!=0xffffff)
1928 if (OFF3(offsets,i+index+1)!=0xffffff)
1929 tile_len[i]=OFF3(offsets,i+index+1)-OFF3(offsets,i+index);
1931 for (j=i+1;j<num+numm;j++)
1932 if (OFF3(offsets,j+index)!=0xffffff)
1934 tile_len[i]=OFF3(offsets,j+index)-OFF3(offsets,i+index);
1942 MMAllocate((memptr *)&tilem_len,numm*2);
1943 for (realnumm=i=0;i<numm;i++)
1948 if (OFF3(offsets,i+indexm)!=0xffffff)
1951 if (OFF3(offsets,i+indexm+1)!=0xffffff)
1952 tilem_len[i]=OFF3(offsets,i+indexm+1)-OFF3(offsets,i+indexm);
1954 for (j=i+1;j<numm+1;j++)
1955 if (OFF3(offsets,j+indexm)!=0xffffff)
1957 tilem_len[i]=OFF3(offsets,j+indexm)-OFF3(offsets,i+indexm);
1966 // DON'T REALLOCATE THIS IF WE'RE COMING BACK FROM A LAUNCH!
1970 long size=expsize*realnum+expmsize*realnumm,savings=0;
1973 if (1024L*XMSTotalFree()<size)
1975 savings=CgaXMSsize+EgaXMSsize+VgaXMSsize;
1976 if (1024L*XMSTotalFree()<size-savings)
1979 ErrDialog("Not enough memory to load\n"
1980 "requested graphics.\n"," OK ");
1982 MMFreePtr((memptr *)&GraphHeader);
1983 MMFreePtr((memptr *)&packed);
1984 MMFreePtr((memptr *)&unpack);
1989 Quit("Get more Extended memory!");
1995 MMFreePtr((memptr *)&CgaXMSlookup);
2000 MMFreePtr((memptr *)&EgaXMSlookup);
2005 MMFreePtr((memptr *)&VgaXMSlookup);
2007 CgaXMSsize=EgaXMSsize=VgaXMSsize=CgaXMS=EgaXMS=VgaXMS=0;
2013 xmshandle=CgaXMS=XMSAllocate(size);
2018 xmshandle=EgaXMS=XMSAllocate(size);
2022 xmshandle=VgaXMS=XMSAllocate(size);
2026 ErrDialog("GRAPHICS INSTALLATION\n"
2027 "Decompressing and\n"
2028 "moving tiles into\n"
2029 "Extended memory:","");
2036 CgaXMS=TEDInfo->OldCgaXMS;
2037 EgaXMS=TEDInfo->OldEgaXMS;
2038 VgaXMS=TEDInfo->OldVgaXMS;
2040 CgaXMSsize=TEDInfo->OldCgaXMSsize;
2041 EgaXMSsize=TEDInfo->OldEgaXMSsize;
2042 VgaXMSsize=TEDInfo->OldVgaXMSsize;
2047 MMAllocate((memptr *)&CgaXMSlookup,size);
2048 XMSmove(TEDInfo->CgaXMSlook,0,0,(long)MK_FP(CgaXMSlookup,0),size);
2049 XMSFreeMem(TEDInfo->CgaXMSlook);
2050 TEDInfo->CgaXMSlook=0;
2054 MMAllocate((memptr *)&EgaXMSlookup,size);
2055 XMSmove(TEDInfo->EgaXMSlook,0,0,(long)MK_FP(EgaXMSlookup,0),size);
2056 XMSFreeMem(TEDInfo->EgaXMSlook);
2057 TEDInfo->EgaXMSlook=0;
2061 MMAllocate((memptr *)&VgaXMSlookup,size);
2062 XMSmove(TEDInfo->VgaXMSlook,0,0,(long)MK_FP(VgaXMSlookup,0),size);
2063 XMSFreeMem(TEDInfo->VgaXMSlook);
2064 TEDInfo->VgaXMSlook=0;
2071 XMSlookup=CgaXMSlookup;
2076 XMSlookup=EgaXMSlookup;
2080 XMSlookup=VgaXMSlookup;
2083 ErrDialog("RE-INITIALIZING...","");
2090 // INSTALL GRAPHICS IF NOT A LAUNCH...
2097 MMAllocate((memptr *)&CgaXMSlookup,(num+numm)*4);
2098 XMSlookup=CgaXMSlookup;
2102 MMAllocate((memptr *)&EgaXMSlookup,(num+numm)*4);
2103 XMSlookup=EgaXMSlookup;
2106 MMAllocate((memptr *)&VgaXMSlookup,(num+numm)*4);
2107 XMSlookup=VgaXMSlookup;
2112 // SET UP MEMORY CACHE IF ENOUGH IS AVAILABLE...
2115 if (filelen(gname1)<16L*MMTotalFree())
2117 LoadIn(gname1,(memptr *)&CacheBlock);
2122 // DAMN! TRY XMS AS A LAST RESORT...
2124 if (filelen(gname1)<1024l*XMSTotalFree())
2126 #define TMPBUFSIZE 32000l
2127 long amtleft,tmpoff=0,tmpsize;
2131 amtleft=filelen(gname1);
2132 MMAllocate(&tblock,TMPBUFSIZE);
2133 cacheon_h=XMSAllocate(amtleft);
2137 LoadFile(gname1,MK_FP(tblock,0),tmpoff,tmpsize);
2138 XMSmove(0,(long)MK_FP(tblock,0),cacheon_h,tmpoff,tmpsize);
2139 amtleft-=TMPBUFSIZE;
2141 tmpsize=(amtleft>TMPBUFSIZE)?TMPBUFSIZE:amtleft;
2151 // MOVE NONMASKED TILES INTO XMS MEMORY!
2153 unpacksize=unpackoff=0;
2160 off=OFF3(offsets,index+i);
2161 if (off==0xffffff) // SPARSE TILE?
2170 // GET COMPRESSED TILE DATA FROM CACHE OR DISK
2175 // HUFFMAN DECOMPRESS
2177 HuffExpand((unsigned char huge *)CacheBlock+off,(unsigned char huge *)unpack+unpackoff,
2178 expsize,(huffnode *)hufftable);
2183 XMSmove(cacheon_h,off,0,(long)packed,size);
2185 // HUFFMAN DECOMPRESS
2187 HuffExpand((unsigned char huge *)packed,(unsigned char huge *)unpack+unpackoff,
2188 expsize,(huffnode *)hufftable);
2192 LoadFile(gname1,(char huge *)packed,off,size);
2194 // HUFFMAN DECOMPRESS
2196 HuffExpand((unsigned char huge *)packed,(unsigned char huge *)unpack+unpackoff,
2197 expsize,(huffnode *)hufftable);
2200 unpacksize+=expsize;
2203 *(XMSlookup+i)=xmsoff;
2206 if (unpacksize>unpackmax-expsize)
2208 XMSmove(0,(long)MK_FP(unpack,0),xmshandle,unpackxms,unpacksize);
2209 unpacksize=unpackoff=0;
2214 printint(num+numm-i);
2228 MMFreePtr((memptr *)&CgaXMSlookup);
2234 MMFreePtr((memptr *)&EgaXMSlookup);
2239 MMFreePtr((memptr *)&VgaXMSlookup);
2247 XMSlookup=CgaXMSlookup;
2252 XMSlookup=EgaXMSlookup;
2256 XMSlookup=VgaXMSlookup;
2259 MMFreePtr((memptr *)&GraphHeader);
2260 MMFreePtr((memptr *)&packed);
2261 MMFreePtr((memptr *)&unpack);
2264 MMFreePtr((memptr *)&CacheBlock);
2269 Quit("XMS LOADING ABORTED!");
2273 // FLUSH THE FAST(?)-CACHE
2277 XMSmove(0,(long)MK_FP(unpack,0),xmshandle,unpackxms,unpacksize);
2278 unpacksize=unpackoff=0;
2283 // MOVE MASKED TILES INTO XMS MEMORY!
2285 for (i=0;i<numm;i++)
2289 off=OFF3(offsets,indexm+i);
2290 if (off==0xffffff) // SPARSE TILE?
2292 *(XMSlookup+i+num)=-1;
2299 // GET COMPRESSED TILE DATA FROM CACHE OR DISK
2304 // HUFFMAN DECOMPRESS
2306 HuffExpand((unsigned char huge *)CacheBlock+off,(unsigned char huge *)unpack+unpackoff,
2307 expmsize,(huffnode *)hufftable);
2312 XMSmove(cacheon_h,off,0,(long)packed,size);
2314 // HUFFMAN DECOMPRESS
2316 HuffExpand((unsigned char huge *)packed,(unsigned char huge *)unpack+unpackoff,
2317 expmsize,(huffnode *)hufftable);
2321 LoadFile(gname1,(char huge *)packed,off,size);
2323 // HUFFMAN DECOMPRESS
2325 HuffExpand((unsigned char huge *)packed,(unsigned char huge *)unpack+unpackoff,
2326 expmsize,(huffnode *)hufftable);
2329 unpacksize+=expmsize;
2330 unpackoff+=expmsize;
2332 *(XMSlookup+i+num)=xmsoff;
2335 if (unpacksize>unpackmax-expmsize)
2337 XMSmove(0,(long)MK_FP(unpack,0),xmshandle,unpackxms,unpacksize);
2338 unpacksize=unpackoff=0;
2358 MMFreePtr((memptr *)&CgaXMSlookup);
2364 MMFreePtr((memptr *)&EgaXMSlookup);
2369 MMFreePtr((memptr *)&VgaXMSlookup);
2377 XMSlookup=CgaXMSlookup;
2382 XMSlookup=EgaXMSlookup;
2386 XMSlookup=VgaXMSlookup;
2389 MMFreePtr((memptr *)&GraphHeader);
2390 MMFreePtr((memptr *)&packed);
2391 MMFreePtr((memptr *)&unpack);
2394 MMFreePtr((memptr *)&CacheBlock);
2399 Quit("XMS LOADING ABORTED!");
2402 // FLUSH THE FAST-CACHE
2406 XMSmove(0,(long)MK_FP(unpack,0),xmshandle,unpackxms,unpacksize);
2407 unpacksize=unpackoff=0;
2412 MMFreePtr((memptr *)&CacheBlock);
2415 XMSFreeMem(cacheon_h);
2419 // GET RID OF TILE-FILE CACHE MEMORY (OR WE'RE TOASTY)
2421 MMFreePtr((memptr *)&GraphHeader);
2422 MMFreePtr((memptr *)&packed);
2423 MMFreePtr((memptr *)&unpack);
2425 MMFreePtr((memptr *)&tile_len);
2426 MMFreePtr((memptr *)&tilem_len);
2434 case 1: lasticon=tilenum+36*maxiconrows;
2436 case 2: lasticon=tilenum+18*maxiconrows;
2438 case 3: lasticon=tilenum+7*maxiconrows;
2442 RestoreBackground();
2447 ////////////////////////////////////////////////////
2448 ////////////////////////////////////////////////////
2450 // Load TEDINFO.ext file
2452 ////////////////////////////////////////////////////
2453 ////////////////////////////////////////////////////
2454 void LoadInfoFile(void)
2456 char pname[14]="TEDINFO.",gfxname[14]="GFXINFO";
2460 // Load the TEDINFO.ext file!
2463 strcpy(infoname,pname);
2465 if (access(pname,0))
2467 MMAllocate((memptr *)&TEDInfo,sizeof(InfoStruct));
2468 _fmemset(TEDInfo,0,sizeof(InfoStruct));
2470 TEDInfo->pflags=0x27; // 0010 0111
2473 LoadIn(pname,(memptr *)&TEDInfo);
2475 tsize=TEDInfo->tsize;
2477 _fmemcpy((char far *)TEDInfo->launchname,(char far *)launchname,14);
2480 // LOAD THE "GFXINFO?.EXT" FILE
2482 strcat(gfxname,format);
2483 strcat(gfxname,".");
2484 strcat(gfxname,ext);
2485 LoadIn(gfxname,(memptr *)&GFXInfo);
2490 tilenum=GFXInfo->num8;
2491 tilemnum=GFXInfo->num8m;
2494 tilenum=GFXInfo->num16;
2495 tilemnum=GFXInfo->num16m;
2498 tilenum=GFXInfo->num32;
2499 tilemnum=GFXInfo->num32m;
2502 _fstrcpy((char far *)launchname,(char far *)TEDInfo->launchname);
2505 TEDInfo->lastvid=LaunchInfo.lastmode;
2508 // SET PLANE FLAGS BACK TO NORMAL
2510 planeton=(TEDInfo->pflags>>6)&1;
2511 planemon=(TEDInfo->pflags>>5)&1;
2512 planeion=(TEDInfo->pflags>>4)&1;
2513 viewton=(TEDInfo->pflags>>2)&1;
2514 viewmon=(TEDInfo->pflags>>1)&1;
2515 viewion=(TEDInfo->pflags)&1;
2518 // SET BACKGROUND COLOR
2520 BkgndColor=TEDInfo->BackgndColor;
2522 TEDInfo->BackgndColor=BkgndColor=O_FGNDBACK;
2526 ////////////////////////////////////////////////////
2527 ////////////////////////////////////////////////////
2529 // Find ?GAGRAPH.ext file
2531 ////////////////////////////////////////////////////
2532 ////////////////////////////////////////////////////
2533 void FindGraphFile(void)
2536 char pname[15]="?GAGRAPH.*",*tempstr,tiname[13]="TEDINFO.TMP";
2541 // RETURNING FROM LAUNCH...GET INFO BACK
2545 LoadFile(tiname,(char huge *)&LaunchInfo,0,0);
2547 videomode=LaunchInfo.lastmode;
2561 strcpy(ext,LaunchInfo.ext);
2562 projname[0]=format[0];
2563 strcat(projname,"GAGRAPH.");
2564 strcat(projname,ext);
2569 // Find ?GAGRAPH.ext
2573 strcpy(pname,"?GAGRAPH.");
2577 if (findfirst(pname,&ffblk,FA_ARCH))
2579 ErrDialog("I can't find a graphics\nfile! (ex:?GAGRAPH.ext)"," Alright ");
2580 Quit("Can't work without graphics ya know!");
2585 format[0] = GfxToUse;
2590 strcpy(bstrings[0],ffblk.ff_name);
2591 ProjButns[0].xoff=9;
2592 ProjButns[0].yoff=2;
2593 ProjButns[0].border=0;
2594 ProjButns[0].text=bstrings[0];
2597 if (findnext(&ffblk))
2599 strcpy(bstrings[i],ffblk.ff_name);
2600 ProjButns[i].xoff=9;
2601 ProjButns[i].yoff=2+i;
2602 ProjButns[i].border=0;
2603 ProjButns[i].text=bstrings[i];
2605 ProjSelect.numbuttons=i;
2606 ProjSelect.height=i+3;
2612 which=DoDialog(&ProjSelect);
2616 tempstr=strpbrk(bstrings[which],".")+1;
2617 strcpy(ext,tempstr);
2618 format[0]=bstrings[which][0];
2621 strcpy(projname,bstrings[which]);
2625 // draw border for project window
2627 void DrawProjBord(int x,int y)
2629 DrawBorder(x+8,y+1,13,ProjSelect.height-2,1);
2633 ////////////////////////////////////////////////////
2635 // Input amount of icons to reserve
2636 // Returns maximum # of icon rows to reserve
2638 ////////////////////////////////////////////////////
2639 btype ICb={" ",8,3,1};
2640 DialogDef ICd={"Enter maximum amount\nof icons to reserve:",20,5,1,&ICb,NULL};
2642 int InputIconAmount(void)
2648 if (!(MapFileHeader->maptype&IPLANE))
2655 GetDialogXY(&ICd,&sx,&sy);
2656 GetButtonXY(&ICd,0,&sx,&sy);
2657 if (input(tempstr,3))
2659 value=atoi(tempstr);
2663 RestoreBackground();
2664 return (value+17)/18;
2671 ////////////////////////////////////////////////////
2672 ////////////////////////////////////////////////////
2674 // Unhook everything
2676 ////////////////////////////////////////////////////
2677 ////////////////////////////////////////////////////
2688 XMSFreeMem(XMSundoB);
2690 XMSFreeMem(XMSundoF);
2692 XMSFreeMem(XMSundoI);
2694 XMSFreeMem(XMSmaps);
2697 void PatchPointers(void)
2702 ////////////////////////////////////////////////////
2703 ////////////////////////////////////////////////////
2707 ////////////////////////////////////////////////////
2708 ////////////////////////////////////////////////////
2709 MenuDef AboutMenu[]=
2710 {{"About...",Item_About,0,0},
2711 {"Video Mode Switch",Item_ModeSwitch,0,0x43},
2712 {"Last Video Mode",Item_LastVideo,ALT,0x2c},
2713 {"Memory Available",Item_PrintMem,0,0x44},
2714 {"Launch Project",Item_Launch,ALT,0x26},
2715 {"--------------------",NULL,0,0},
2716 // {"Display Unused Tiles",Item_CountTiles,0,0},
2717 {"Project Re-Select",Item_ProjectReSelect,0,0},
2718 {"Visit DOS",Item_VisitDOS,0,0}
2722 {{"Edit New Map",Item_EditMap,ALT,0x18},
2723 {"Save Map",Item_SaveMap,ALT,0x1f},
2724 {"Create Map",Item_CreateMap,ALT,0x2e},
2725 {"Delete Map",Item_DeleteMap,ALT,0x20},
2726 {"Switch Map",Item_SwitchMap,ALT,0x11},
2727 {"Amputate Maps",Item_Amputate},
2728 {"---------------",NULL,0,0},
2729 {"Import Maps",Item_ImportMaps,0,0},
2730 {"Change ICON Rows",Item_ChangeIconRows,0,0},
2731 {"Carmacize Maps",Item_Huffman,0,0},
2732 {"Quit TED5",Item_Quit,ALT,0x2d}};
2735 {{"Switch to Last Map",Item_LastMap,ALT,0x32},
2736 {"Edit TILEINFO/M Values",Item_EditTinfoValues,ALT,0x14},
2737 {"Change LAUNCH name",Item_LAUNCHname,0,0},
2738 {"Change PARM string",Item_PARMstring,0,0},
2739 {"Edit TILEINFO/M Names",Item_EditTinfoNames,0,0},
2740 {"Add/Del TILEINFO/M Planes",Item_AddDelTinfo,0,0},
2741 {"Edit MAP Names",Item_EditMapNames,0,0},
2742 {"Change MAP Edges",Item_EditMapEdges,0,0}};
2746 {"Copy Mode",Item_Copy,0,0x2e},
2747 {"Paste Mode",Item_Paste,0,0x19},
2748 {"Block Fill",Item_BlockFill,0,0x30},
2749 {"Flood Fill",Item_FloodFill,0,0x21},
2750 {"Undo last action",Item_Undo,0,0x16},
2751 {"Tile Search",Item_TileSearch,0,0x14},
2752 {"GridMode toggle",Item_GridMode,0,0x22},
2753 {"Snap-Paste toggle",Item_SnapTog,0,0x1f},
2754 {"Paste Overlay toggle",Item_POtog,0,0x3d}
2760 {"Select Tile",Item_SelectTile,0,0x39},
2761 {"Map Stats",Item_MapStats,0,0x17},
2762 {"Toggle INFOBAR",Item_ToggleInfo,0,0x42},
2763 {"New INFOPLANE value",Item_InputInfoplane,0,0x1c},
2764 {"View Map & Goto",Item_ViewMap,ALT,0x2f},
2765 {"ReView Map & Goto",Item_ReviewMap,0,0xe},
2766 {"Change LAUNCH icon",Item_ChangeLaunchIcon,0,0},
2767 {"Change bkgnd color",Item_ChangeBkgndColor,0,0},
2768 {"TILEINFOM Copy",Item_TINFOCopy,0,0},
2769 {"Graphic Map Dump",Item_GraphicDump,0,0}
2773 MBarDef TED5MenuBar[]=
2774 {{9,AboutMenu," ? "},
2775 {11,FileMenu,"File"},
2776 {8,EditMenu,"Edit"},
2777 {9,ModeMenu,"Modes"},
2778 {10,MiscMenu,"Misc"},