1 ////////////////////////////////////////////////////
2 ////////////////////////////////////////////////////
6 ////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////
14 ////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////
19 void CheckMapScroll(void)
24 if (keydown[0x4b]) // left arrow
26 int i,j,imax,jmax,tilesmoved;
34 if (keydown[0x1d]) // CTRL-KEY
37 if (keydown[0x38]) // ALT-KEY
61 if (tilesmoved<screenw)
62 CopyScreen(0,8,infomaxw-(tilesmoved<<(tsize-1)),screenh<<(tsize+2),tilesmoved<<(tsize-1),8);
68 for (i=0;i<tilesmoved;i++)
71 unsigned tilet,tilem,tilei,loc;
73 loc=(ybase+j)*mapwidth+xbase+i;
75 tilet=*(MapBkgnd+loc);
76 tilem=*(MapFrgnd+loc)+tilenum;
77 tilei=*(MapInfoPl+loc)+tilenum;
79 CombineTiles(tilet*viewton-BkgndColor*(!viewton),tilem*viewmon,tilei*viewion,tsize);
82 DrawTile(i<<(tsize-1),j*(4<<tsize)+8,tsize);
83 CheckInfoValues(i,j,tilei);
84 CheckSelectEdges(i+xbase,j+ybase,i,j);
90 if (keydown[0x36] || keydown[0x1d])
98 if (keydown[0x4d]) // right arrow
100 int i,j,imax,jmax,tilesmoved;
104 if (xbase+screenw<mapwidth)
108 if (keydown[0x1d]) // CTRL-KEY
111 if (keydown[0x38]) // ALT-KEY
113 xbase=mapwidth-screenw;
131 if (xbase+screenw+tilesmoved>=mapwidth)
132 tilesmoved=mapwidth-screenw-xbase;
136 if (tilesmoved<screenw)
137 CopyScreen(tilesmoved<<(tsize-1),8,infomaxw-(tilesmoved<<(tsize-1)),screenh<<(tsize+2),0,8);
143 for (i=0;i<tilesmoved;i++)
146 unsigned tilet,tilem,tilei,loc;
148 loc=(ybase+j)*mapwidth+xbase+screenw-tilesmoved+i;
150 tilet=*(MapBkgnd+loc);
151 tilem=*(MapFrgnd+loc)+tilenum;
152 tilei=*(MapInfoPl+loc)+tilenum;
154 CombineTiles(tilet*viewton-BkgndColor*(!viewton),tilem*viewmon,tilei*viewion,tsize);
157 DrawTile(infomaxw-((tilesmoved-i)<<(tsize-1)),j*(4<<tsize)+8,tsize);
158 CheckInfoValues(screenw-tilesmoved+i,j,tilei);
159 CheckSelectEdges(screenw-tilesmoved+i+xbase,j+ybase,i+screenw-tilesmoved,j);
165 if (keydown[0x36] || keydown[0x1d])
166 while(keydown[0x4d]);
173 if (keydown[0x48]) // up arrow
175 int i,j,imax,jmax,tilesmoved;
183 if (keydown[0x1d]) // CTRL-KEY
186 if (keydown[0x38]) // ALT-KEY
205 if (ybase<tilesmoved)
210 if (tilesmoved<screenh)
211 CopyScreen(0,8,infomaxw,(screenh-tilesmoved)<<(tsize+2),0,8+(tilesmoved<<(tsize+2)));
217 for (j=0;j<tilesmoved;j++)
220 unsigned tilet,tilem,tilei,loc;
222 loc=(ybase+j)*mapwidth+xbase+i;
224 tilet=*(MapBkgnd+loc);
225 tilem=*(MapFrgnd+loc)+tilenum;
226 tilei=*(MapInfoPl+loc)+tilenum;
228 CombineTiles(tilet*viewton-BkgndColor*(!viewton),tilem*viewmon,tilei*viewion,tsize);
231 DrawTile(i<<(tsize-1),8+(j<<(tsize+2)),tsize);
232 CheckInfoValues(i,j,tilei);
233 CheckSelectEdges(i+xbase,j+ybase,i,j);
239 if (keydown[0x36] || keydown[0x1d])
240 while(keydown[0x48]);
247 if (keydown[0x50]) // down arrow
249 int i,j,imax,jmax,tilesmoved;
253 if (ybase+screenh<mapheight)
257 if (keydown[0x1d]) // CTRL-KEY
260 if (keydown[0x38]) // ALT-KEY
262 ybase=mapheight-screenh;
279 if (ybase+screenh+tilesmoved>=mapheight)
280 tilesmoved=mapheight-screenh-ybase;
284 if (tilesmoved<screenh)
285 CopyScreen(0,8+(tilesmoved<<(tsize+2)),infomaxw,(screenh-tilesmoved)<<(tsize+2),0,8);
291 for (j=0;j<tilesmoved;j++)
294 unsigned tilet,tilem,tilei,loc;
296 loc=(ybase+j+screenh-tilesmoved)*mapwidth+xbase+i;
298 tilet=*(MapBkgnd+loc);
299 tilem=*(MapFrgnd+loc)+tilenum;
300 tilei=*(MapInfoPl+loc)+tilenum;
302 CombineTiles(tilet*viewton-BkgndColor*(!viewton),tilem*viewmon,tilei*viewion,tsize);
305 DrawTile(i<<(tsize-1),8+((screenh-tilesmoved+j)<<(tsize+2)),tsize);
306 CheckInfoValues(i,screenh-tilesmoved+j,tilei);
307 CheckSelectEdges(i+xbase,screenh-tilesmoved+j+ybase,i,j+screenh-tilesmoved);
314 if (keydown[0x36] || keydown[0x1d])
315 while(keydown[0x50]);
321 ////////////////////////////////////////////////////
323 // Copy a screen section to another, mode independent
325 ////////////////////////////////////////////////////
326 void CopyScreen(int srcx,int srcy,int width,int height,int destx,int desty)
330 case CGA: CopyCGA(srcx,srcy,width,height,destx,desty); break;
332 case EGA2:outport(SCindex,0x0f00 | SCmapmask);CopyEGA(srcx,srcy,width,height,destx,desty); break;
333 case VGA: CopyVGA(srcx,srcy,width,height,destx,desty);
338 ////////////////////////////////////////////////////
340 // See if either of the Select edges are visible on the map
343 ////////////////////////////////////////////////////
344 void CheckSelectEdges(int x,int y,int i,int j)
361 if (y==SelY2 && x==SelX2)
365 case 1: drawchar(i,j+1,8);
367 case 2: drawchar(i*2+1,j*2+2,8);
368 drawchar(i*2+1,j*2+1,5);
369 drawchar(i*2,j*2+2,7);
371 case 3: drawchar(i*4+3,j*4+4,8);
373 drawchar(i*4+3,j*4+3,5);
374 drawchar(i*4+3,j*4+2,5);
375 drawchar(i*4+3,j*4+1,5);
377 drawchar(i*4+2,j*4+4,7);
378 drawchar(i*4+1,j*4+4,7);
379 drawchar(i*4,j*4+4,7);
384 if (y==SelY1 && x==SelX1)
388 case 1: drawchar(i,j+1,1);
390 case 2: drawchar(i*2,j*2+1,1);
391 drawchar(i*2+1,j*2+1,2);
392 drawchar(i*2,j*2+2,4);
394 case 3: drawchar(i*4,j*4+1,1);
396 drawchar(i*4+1,j*4+1,2);
397 drawchar(i*4+2,j*4+1,2);
398 drawchar(i*4+3,j*4+1,2);
400 drawchar(i*4,j*4+2,4);
401 drawchar(i*4,j*4+3,4);
402 drawchar(i*4,j*4+4,4);
407 if (y==SelY2 && x==SelX1)
411 case 1: drawchar(i,j+1,6);
413 case 2: drawchar(i*2 ,j*2+2,6);
414 drawchar(i*2+1,j*2+2,7);
415 drawchar(i*2 ,j*2+1,4);
417 case 3: drawchar(i*4,j*4+4,6);
419 drawchar(i*4+1,j*4+4,7);
420 drawchar(i*4+2,j*4+4,7);
421 drawchar(i*4+3,j*4+4,7);
423 drawchar(i*4,j*4+1,4);
424 drawchar(i*4,j*4+2,4);
425 drawchar(i*4,j*4+3,4);
430 if (y==SelY1 && x==SelX2)
434 case 1: drawchar(i,j+1,3);
436 case 2: drawchar(i*2+1,j*2+1,3);
437 drawchar(i*2+1,j*2+2,5);
438 drawchar(i*2 ,j*2+1,2);
440 case 3: drawchar(i*4+3,j*4+1,3);
442 drawchar(i*4+3,j*4+4,5);
443 drawchar(i*4+3,j*4+3,5);
444 drawchar(i*4+3,j*4+2,5);
446 drawchar(i*4+2,j*4+4,7);
447 drawchar(i*4+1,j*4+4,7);
448 drawchar(i*4,j*4+4,7);
453 if (y==SelY1 && x>SelX1 && x<SelX2)
457 case 3: drawchar(i*4+2,j*4+1,2);
458 drawchar(i*4+3,j*4+1,2);
459 drawchar(i*4+1,j*4+1,2);
460 drawchar(i*4 ,j*4+1,2);
462 case 2: drawchar(i*2+1,j*2+1,2);
463 drawchar(i*2 ,j*2+1,2);
465 case 1: drawchar(i,j+1,2);
470 if (y==SelY2 && x>SelX1 && x<SelX2)
474 case 1: drawchar(i,j+1,7);
476 case 2: drawchar(i*2,j*2+2,7);
477 drawchar(i*2+1,j*2+2,7);
479 case 3: drawchar(i*4 ,j*4+4,7);
480 drawchar(i*4+1,j*4+4,7);
481 drawchar(i*4+2,j*4+4,7);
482 drawchar(i*4+3,j*4+4,7);
487 if (x==SelX1 && y>SelY1 && y<SelY2)
491 case 3: drawchar(i*4,j*4+3,4);
492 drawchar(i*4,j*4+4,4);
493 drawchar(i*4,j*4+2,4);
494 drawchar(i*4,j*4+1,4);
496 case 2: drawchar(i*2,j*2+2,4);
497 drawchar(i*2,j*2+1,4);
499 case 1: drawchar(i,j+1,4);
504 if (x==SelX2 && y>SelY1 && y<SelY2)
508 case 1: drawchar(i,j+1,5);
510 case 2: drawchar(i*2+1,j*2+1,5);
511 drawchar(i*2+1,j*2+2,5);
513 case 3: drawchar(i*4+3,j*4+1,5);
514 drawchar(i*4+2,j*4+1,5);
515 drawchar(i*4+1,j*4+1,5);
516 drawchar(i*4 ,j*4+1,5);
523 ////////////////////////////////////////////////////
525 // FLOATING PASTE REGION!
527 ////////////////////////////////////////////////////
528 void CheckFloatPaste(int mx,int my)
533 if (SnapMode && PasteMode && (pixely>=8 || pixely<infoy*8))
535 mx=(mx/snapxsize)*snapxsize+snapx;
536 my=(my/snapysize)*snapysize+snapy;
542 if (mx>=xbase+screenw)
544 if (my>=ybase+screenh)
548 if (!PasteMode || (px==mx && py==my) || (pixely<8 || pixely>infoy*8))
551 if (mx>mapwidth || my>mapheight)
568 ////////////////////////////////////////////////////
570 // DRAW FLOATING PASTE REGION
572 void DrawFloatPaste(void)
577 if (px==-1 || py==-1 || !PasteMode)
580 // NOW, DRAW IT IN A NEW LOCATION!
586 if (py+maxh>mapheight)
588 if (py+maxh-ybase>screenh)
589 maxh=screenh-(py-ybase);
592 if (px+maxw>mapwidth)
594 if (px+maxw-xbase>screenw)
595 maxw=screenw-(px-xbase);
597 switch(TileCopy.MapOrTileSelect)
599 case 0: // MAP PASTE DRAW
603 unsigned tilet,tilem,tilei,loc,loc1,oldt,oldm,oldi;
606 loc=(TileCopy.y+j)*mapwidth+TileCopy.x+i;
607 loc1=(py+j)*mapwidth+px+i;
609 tilet=*(CutBkgnd+loc);
611 tilem=*(CutFrgnd+loc)+tilenum;
614 oldm=MapFrgnd[loc1]+tilenum;
615 tilei=*(CutInfoPl+loc)+tilenum;
618 oldi=MapInfoPl[loc1]+tilenum;
620 theT=(TileCopy.PlanesCopied&BPLANE)?tilet:-BkgndColor;
621 if (theT==-BkgndColor && viewton)
623 theM=(TileCopy.PlanesCopied&FPLANE)?tilem:0;
624 if (!theM && viewmon && !(TileCopy.PlanesCopied&FPLANE && F3_flag))
626 theI=(TileCopy.PlanesCopied&IPLANE)?tilei:0;
627 if (!theI && viewion && !(TileCopy.PlanesCopied&IPLANE && F3_flag))
630 CombineTiles(theT,theM,theI,tsize);
633 DrawTile((px+i-xbase)<<(tsize-1),(py+j-ybase)*(4<<tsize)+8,tsize);
637 case 1: // TILE PASTE DRAW
641 int val=(j+TileCopy.y)*selectcols+TileCopy.x+i;
642 unsigned tilem,tilei,loc;
644 loc=(py+j)*mapwidth+px+i;
646 tilem=MapFrgnd[loc]+tilenum;
647 tilei=MapInfoPl[loc]+tilenum;
649 if (XMSlookup[val]!=-1)
651 CombineTiles(viewton?val:-BkgndColor,
657 DrawTile((px+i-xbase)<<(tsize-1),(py+j-ybase)*(4<<tsize)+8,tsize);
662 case 2: // MASKED PASTE DRAW
666 int val=(j+TileCopy.y)*selectcols+TileCopy.x+i+tilenum+maxiconrows*selectcols;
667 unsigned tilet,tilei,loc;
669 loc=(py+j)*mapwidth+px+i;
672 tilei=MapInfoPl[loc]+tilenum;
674 if (XMSlookup[val]!=-1)
676 CombineTiles(viewton?tilet:-BkgndColor,
682 DrawTile((px+i-xbase)<<(tsize-1),(py+j-ybase)*(4<<tsize)+8,tsize);
690 ////////////////////////////////////////////////////
692 // ERASE FLOATING PASTE REGION
694 void EraseFloatPaste(void)
699 if (px==-1 || py==-1 || !PasteMode)
703 // ERASE THE FLOATING REGION
704 // (PRECLIPPING REGION)
709 if (py+maxh>mapheight)
711 if (py+maxh-ybase>screenh)
712 maxh=screenh-(py-ybase);
715 if (px+maxw>mapwidth)
717 if (px+maxw-xbase>screenw)
718 maxw=screenw-(px-xbase);
723 unsigned tile_t,tile_m,tile_i,loc;
725 loc=(py+j)*mapwidth+px+i;
727 tile_t=*(MapBkgnd+loc);
728 tile_m=*(MapFrgnd+loc)+tilenum;
729 tile_i=*(MapInfoPl+loc)+tilenum;
731 CombineTiles(viewton?tile_t:-BkgndColor,viewmon?tile_m:0,viewion?tile_i:0,tsize);
734 DrawTile((px+i-xbase)<<(tsize-1),(py+j-ybase)*(4<<tsize)+8,tsize);
741 ////////////////////////////////////////////////////
743 // SAVE CUT BUFFERS TO XMS BEFORE MAP LOAD/CREATE
745 ////////////////////////////////////////////////////
746 void SaveCutBuffers(void)
752 // IS SOMETHING IN THE COPY BUFFER?
753 // IF SO, PRESERVE AS MUCH AS POSSIBLE
755 if (!TileCopy.MapOrTileSelect)
757 size=(2L*TileCopy.w*TileCopy.h)*(((TileCopy.PlanesCopied&BPLANE)>0)+
758 ((TileCopy.PlanesCopied&FPLANE)>0)+((TileCopy.PlanesCopied&IPLANE)>0));
760 xms1=XMSAllocate(size);
763 if (TileCopy.PlanesCopied&BPLANE)
764 for (j=0;j<TileCopy.h;j++)
766 XMSmove(0,(long)MK_FP(CutBkgnd,2L*((TileCopy.y+j)*mapwidth)+2L*TileCopy.x),
767 xms1,off,2L*TileCopy.w);
771 if (TileCopy.PlanesCopied&FPLANE)
772 for (j=0;j<TileCopy.h;j++)
774 XMSmove(0,(long)MK_FP(CutFrgnd,2L*((TileCopy.y+j)*mapwidth)+2L*TileCopy.x),
775 xms1,off,2L*TileCopy.w);
779 if (TileCopy.PlanesCopied&IPLANE)
780 for (j=0;j<TileCopy.h;j++)
782 XMSmove(0,(long)MK_FP(CutInfoPl,2L*((TileCopy.y+j)*mapwidth)+2L*TileCopy.x),
783 xms1,off,2L*TileCopy.w);
790 ////////////////////////////////////////////////////
792 // RESTORE CUT BUFFERS FROM XMS AFTER MAP LOAD/CREATE
794 ////////////////////////////////////////////////////
795 void RestoreCutBuffers(void)
798 // COPY BACK STUFF IN XMS
800 if (!TileCopy.MapOrTileSelect)
803 int newwidth,newheight,j;
805 newwidth=(TileCopy.w>mapwidth)?mapwidth:TileCopy.w;
806 newheight=(TileCopy.h>mapheight)?mapheight:TileCopy.h;
810 if (TileCopy.PlanesCopied&BPLANE)
811 for (j=0;j<newheight;j++)
813 XMSmove(xms1,off,0,(long)MK_FP(CutBkgnd,2L*(j*mapwidth)),2L*newwidth);
818 if (TileCopy.PlanesCopied&FPLANE)
819 for (j=0;j<newheight;j++)
821 XMSmove(xms1,off,0,(long)MK_FP(CutFrgnd,2L*(j*mapwidth)),2L*newwidth);
826 if (TileCopy.PlanesCopied&IPLANE)
827 for (j=0;j<newheight;j++)
829 XMSmove(xms1,off,0,(long)MK_FP(CutInfoPl,2L*(j*mapwidth)),2L*newwidth);
834 TileCopy.x=TileCopy.y=0;
836 TileCopy.h=newheight;
838 XMSFreeMem(xms1); // RELEASE THE MEMORY
842 ////////////////////////////////////////////////////
844 // SEE IF THERE'S AN INFO VALUES AT THE CURRENT POSITION
845 // THAT NEEDS TO BE PRINTED
847 ////////////////////////////////////////////////////
848 void CheckInfoValues(int i,int j,int tilei)
855 unsigned loc,temp,p=0;
857 loc=(j+ybase)*mapwidth+i+xbase;
861 if (MapBkgnd[loc]==whicht)
870 if (MapFrgnd[loc]==whichtm-tilenum)
872 temp=whichtm-tilenum;
878 if ((unsigned)MapInfoPl[loc]==whichi-tilenum)
894 printhexb(temp&0xff);
896 case 3: printhex(temp);
900 if (viewion && tilei>lasticon)
908 printhexb(tilei-tilenum>>8);
911 printhexb(tilei-tilenum&0xff);
913 case 3: printhex(tilei-tilenum);
918 ////////////////////////////////////////////////////
920 // Item - Edit Map Edges
922 ////////////////////////////////////////////////////
923 btype MapEdgeB[]={{"\xb",7,3,1},
928 DialogDef MapEdgeD={" PICK MAP EDGE\n"
930 16,18,5,&MapEdgeB[0],NULL};
932 void Item_EditMapEdges(void)
934 int which,val,newwidth,newheight,b,f,i,
935 _seg *tempB,_seg *tempF,_seg *tempI;
936 unsigned dx,dy,obx,oby,k,j,modified=0;
939 b=MapFileHeader->maptype&BPLANE;
940 f=MapFileHeader->maptype&FPLANE;
941 i=MapFileHeader->maptype&IPLANE;
943 DrawDialog(&MapEdgeD,1);
944 GetDialogXY(&MapEdgeD,&dx,&dy);
951 printint(MapHeader.width);
953 printint(MapHeader.height);
958 which=CheckButtons(&MapEdgeD);
959 GetButtonXY(&MapEdgeD,which-1,&obx,&oby);
961 if (which>=1 && which<=4)
966 print("+ or - value");
967 DrawBorder(dx,dy+10,15,2,1);
974 // ERASE THE ARROW AND INPUT BAR
977 print(MapEdgeB[which-1].text);
978 bar(dx,dy+9,dx+15,dy+12,' ');
981 if (val==(int)ESCOUT)
989 // ADD OR DELETE FROM TOP
992 newheight=mapheight+val;
993 size=2L*newheight*mapwidth;
994 if (size<=0 || size>0x10000L)
997 ErrDialog("Invalid Map height!"," OK ");
1001 // FREE UP SOME MEMORY!
1003 RemoveUndoBuffers();
1007 MMFreePtr((memptr *)&CutBkgnd);
1008 MMAllocate((memptr *)&tempB,size);
1012 MMFreePtr((memptr *)&CutFrgnd);
1013 MMAllocate((memptr *)&tempF,size);
1017 MMFreePtr((memptr *)&CutInfoPl);
1018 MMAllocate((memptr *)&tempI,size);
1023 // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE)
1024 for (j=abs(val);j<mapheight;j++)
1025 for (k=0;k<mapwidth;k++)
1028 tempB[(j+val)*mapwidth+k]=MapBkgnd[j*mapwidth+k];
1030 tempF[(j+val)*mapwidth+k]=MapFrgnd[j*mapwidth+k];
1032 tempI[(j+val)*mapwidth+k]=MapInfoPl[j*mapwidth+k];
1037 for (j=0;j<mapheight+val;j++)
1038 for (k=0;k<mapwidth;k++)
1043 tempB[j*mapwidth+k]=whicht;
1045 tempF[j*mapwidth+k]=whichtm-tilenum;
1047 tempI[j*mapwidth+k]=whichi-tilenum;
1052 tempB[j*mapwidth+k]=MapBkgnd[(j-val)*mapwidth+k];
1054 tempF[j*mapwidth+k]=MapFrgnd[(j-val)*mapwidth+k];
1056 tempI[j*mapwidth+k]=MapInfoPl[(j-val)*mapwidth+k];
1061 // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED
1064 MMFreePtr((memptr *)&MapBkgnd);
1065 MMAllocate((memptr *)&MapBkgnd,size);
1069 MMFreePtr((memptr *)&MapFrgnd);
1070 MMAllocate((memptr *)&MapFrgnd,size);
1074 MMFreePtr((memptr *)&MapInfoPl);
1075 MMAllocate((memptr *)&MapInfoPl,size);
1078 // COPY THE REGION BACK IN...
1079 for (j=0;j<newheight;j++)
1080 for (k=0;k<mapwidth;k++)
1083 MapBkgnd[j*mapwidth+k]=tempB[j*mapwidth+k];
1085 MapFrgnd[j*mapwidth+k]=tempF[j*mapwidth+k];
1087 MapInfoPl[j*mapwidth+k]=tempI[j*mapwidth+k];
1090 // TOAST THE 'TEMP' BUFFERS & REALLOCATE THE 'CUT' BUFFERS
1093 MMFreePtr((memptr *)&tempB);
1094 MMAllocate((memptr *)&CutBkgnd,size);
1098 MMFreePtr((memptr *)&tempF);
1099 MMAllocate((memptr *)&CutFrgnd,size);
1103 MMFreePtr((memptr *)&tempI);
1104 MMAllocate((memptr *)&CutInfoPl,size);
1107 mapheight=newheight;
1108 MapHeader.height=newheight;
1109 modified=DirtyFlag=1;
1110 AllocateUndoBuffers();
1112 SaveUndo(0,0,mapwidth,mapheight);
1113 RestoreCutBuffers();
1118 // ADD OR DELETE FROM BOTTOM
1121 newheight=mapheight+val;
1122 size=2L*newheight*mapwidth;
1123 if (size<=0 || size>0x10000L)
1125 RestoreBackground();
1126 ErrDialog("Invalid Map height!"," OK ");
1130 // FREE UP SOME MEMORY!
1132 RemoveUndoBuffers();
1135 MMFreePtr((memptr *)&CutBkgnd);
1136 MMAllocate((memptr *)&tempB,size);
1140 MMFreePtr((memptr *)&CutFrgnd);
1141 MMAllocate((memptr *)&tempF,size);
1145 MMFreePtr((memptr *)&CutInfoPl);
1146 MMAllocate((memptr *)&tempI,size);
1151 // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE)
1152 for (j=0;j<mapheight+val;j++)
1153 for (k=0;k<mapwidth;k++)
1156 tempB[j*mapwidth+k]=MapBkgnd[j*mapwidth+k];
1158 tempF[j*mapwidth+k]=MapFrgnd[j*mapwidth+k];
1160 tempI[j*mapwidth+k]=MapInfoPl[j*mapwidth+k];
1165 for (j=0;j<mapheight+val;j++)
1166 for (k=0;k<mapwidth;k++)
1171 tempB[j*mapwidth+k]=whicht;
1173 tempF[j*mapwidth+k]=whichtm-tilenum;
1175 tempI[j*mapwidth+k]=whichi-tilenum;
1180 tempB[j*mapwidth+k]=MapBkgnd[j*mapwidth+k];
1182 tempF[j*mapwidth+k]=MapFrgnd[j*mapwidth+k];
1184 tempI[j*mapwidth+k]=MapInfoPl[j*mapwidth+k];
1189 // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED
1192 MMFreePtr((memptr *)&MapBkgnd);
1193 MMAllocate((memptr *)&MapBkgnd,size);
1197 MMFreePtr((memptr *)&MapFrgnd);
1198 MMAllocate((memptr *)&MapFrgnd,size);
1202 MMFreePtr((memptr *)&MapInfoPl);
1203 MMAllocate((memptr *)&MapInfoPl,size);
1206 // COPY THE REGION BACK IN...
1207 for (j=0;j<newheight;j++)
1208 for (k=0;k<mapwidth;k++)
1211 MapBkgnd[j*mapwidth+k]=tempB[j*mapwidth+k];
1213 MapFrgnd[j*mapwidth+k]=tempF[j*mapwidth+k];
1215 MapInfoPl[j*mapwidth+k]=tempI[j*mapwidth+k];
1218 // TOAST THE 'TEMP' BUFFERS & REALLOCATE THE 'CUT' BUFFERS
1221 MMFreePtr((memptr *)&tempB);
1222 MMAllocate((memptr *)&CutBkgnd,size);
1226 MMFreePtr((memptr *)&tempF);
1227 MMAllocate((memptr *)&CutFrgnd,size);
1231 MMFreePtr((memptr *)&tempI);
1232 MMAllocate((memptr *)&CutInfoPl,size);
1235 mapheight=newheight;
1236 MapHeader.height=newheight;
1237 modified=DirtyFlag=1;
1238 AllocateUndoBuffers();
1240 SaveUndo(0,0,mapwidth,mapheight);
1241 RestoreCutBuffers();
1246 // ADD OR DELETE FROM LEFTEDGE
1249 newwidth=mapwidth+val;
1250 size=2L*newwidth*mapheight;
1251 if (size<=0 || size>0x10000L)
1253 RestoreBackground();
1254 ErrDialog("Invalid Map width!"," OK ");
1258 // FREE UP SOME MEMORY!
1260 RemoveUndoBuffers();
1263 MMFreePtr((memptr *)&CutBkgnd);
1264 MMAllocate((memptr *)&tempB,size);
1268 MMFreePtr((memptr *)&CutFrgnd);
1269 MMAllocate((memptr *)&tempF,size);
1273 MMFreePtr((memptr *)&CutInfoPl);
1274 MMAllocate((memptr *)&tempI,size);
1279 // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE)
1280 for (j=0;j<mapheight;j++)
1281 for (k=abs(val);k<mapwidth;k++)
1284 tempB[j*newwidth+k+val]=MapBkgnd[j*mapwidth+k];
1286 tempF[j*newwidth+k+val]=MapFrgnd[j*mapwidth+k];
1288 tempI[j*newwidth+k+val]=MapInfoPl[j*mapwidth+k];
1293 for (j=0;j<mapheight;j++)
1294 for (k=0;k<mapwidth+val;k++)
1299 tempB[j*newwidth+k]=whicht;
1301 tempF[j*newwidth+k]=whichtm-tilenum;
1303 tempI[j*newwidth+k]=whichi-tilenum;
1308 tempB[j*newwidth+k]=MapBkgnd[j*mapwidth+k-val];
1310 tempF[j*newwidth+k]=MapFrgnd[j*mapwidth+k-val];
1312 tempI[j*newwidth+k]=MapInfoPl[j*mapwidth+k-val];
1317 // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED
1320 MMFreePtr((memptr *)&MapBkgnd);
1321 MMAllocate((memptr *)&MapBkgnd,size);
1325 MMFreePtr((memptr *)&MapFrgnd);
1326 MMAllocate((memptr *)&MapFrgnd,size);
1330 MMFreePtr((memptr *)&MapInfoPl);
1331 MMAllocate((memptr *)&MapInfoPl,size);
1334 // COPY THE REGION BACK IN...
1335 for (j=0;j<mapheight;j++)
1336 for (k=0;k<newwidth;k++)
1339 MapBkgnd[j*newwidth+k]=tempB[j*newwidth+k];
1341 MapFrgnd[j*newwidth+k]=tempF[j*newwidth+k];
1343 MapInfoPl[j*newwidth+k]=tempI[j*newwidth+k];
1346 // TOAST THE 'TEMP' BUFFERS & REALLOCATE THE 'CUT' BUFFERS
1349 MMFreePtr((memptr *)&tempB);
1350 MMAllocate((memptr *)&CutBkgnd,size);
1354 MMFreePtr((memptr *)&tempF);
1355 MMAllocate((memptr *)&CutFrgnd,size);
1359 MMFreePtr((memptr *)&tempI);
1360 MMAllocate((memptr *)&CutInfoPl,size);
1364 MapHeader.width=newwidth;
1365 modified=DirtyFlag=1;
1366 AllocateUndoBuffers();
1368 SaveUndo(0,0,mapwidth,mapheight);
1369 RestoreCutBuffers();
1374 // ADD OR DELETE FROM RIGHTEDGE
1377 newwidth=mapwidth+val;
1378 size=2L*newwidth*mapheight;
1379 if (size<=0 || size>0x10000L)
1381 RestoreBackground();
1382 ErrDialog("Invalid Map width!"," OK ");
1386 // FREE UP SOME MEMORY!
1388 RemoveUndoBuffers();
1391 MMFreePtr((memptr *)&CutBkgnd);
1392 MMAllocate((memptr *)&tempB,size);
1396 MMFreePtr((memptr *)&CutFrgnd);
1397 MMAllocate((memptr *)&tempF,size);
1401 MMFreePtr((memptr *)&CutInfoPl);
1402 MMAllocate((memptr *)&tempI,size);
1407 // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE)
1408 for (j=0;j<mapheight;j++)
1409 for (k=0;k<mapwidth+val;k++)
1412 tempB[j*newwidth+k]=MapBkgnd[j*mapwidth+k];
1414 tempF[j*newwidth+k]=MapFrgnd[j*mapwidth+k];
1416 tempI[j*newwidth+k]=MapInfoPl[j*mapwidth+k];
1421 for (j=0;j<mapheight;j++)
1422 for (k=0;k<mapwidth+val;k++)
1427 tempB[j*newwidth+k]=whicht;
1429 tempF[j*newwidth+k]=whichtm-tilenum;
1431 tempI[j*newwidth+k]=whichi-tilenum;
1436 tempB[j*newwidth+k]=MapBkgnd[j*mapwidth+k];
1438 tempF[j*newwidth+k]=MapFrgnd[j*mapwidth+k];
1440 tempI[j*newwidth+k]=MapInfoPl[j*mapwidth+k];
1445 // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED
1448 MMFreePtr((memptr *)&MapBkgnd);
1449 MMAllocate((memptr *)&MapBkgnd,size);
1453 MMFreePtr((memptr *)&MapFrgnd);
1454 MMAllocate((memptr *)&MapFrgnd,size);
1458 MMFreePtr((memptr *)&MapInfoPl);
1459 MMAllocate((memptr *)&MapInfoPl,size);
1462 // COPY THE REGION BACK IN...
1463 for (j=0;j<mapheight;j++)
1464 for (k=0;k<newwidth;k++)
1467 MapBkgnd[j*newwidth+k]=tempB[j*newwidth+k];
1469 MapFrgnd[j*newwidth+k]=tempF[j*newwidth+k];
1471 MapInfoPl[j*newwidth+k]=tempI[j*newwidth+k];
1474 // TOAST THE 'TEMP' BUFFERS & REALLOCATE THE 'CUT' BUFFERS
1477 MMFreePtr((memptr *)&tempB);
1478 MMAllocate((memptr *)&CutBkgnd,size);
1482 MMFreePtr((memptr *)&tempF);
1483 MMAllocate((memptr *)&CutFrgnd,size);
1487 MMFreePtr((memptr *)&tempI);
1488 MMAllocate((memptr *)&CutInfoPl,size);
1492 MapHeader.width=newwidth;
1493 modified=DirtyFlag=1;
1494 AllocateUndoBuffers();
1496 SaveUndo(0,0,mapwidth,mapheight);
1497 RestoreCutBuffers();
1500 } while(which && which!=5);
1501 RestoreBackground();
1506 InitDesktop(TED5MenuBar,0);
1514 ////////////////////////////////////////////////////
1516 // Display amount of memory available
1518 ////////////////////////////////////////////////////
1519 btype ShowMemb={" OK ",6,11,2};
1520 DialogDef ShowMemd={"Extended Memory \n"
1525 "----------------\n"
1528 ,16,13,1,&ShowMemb,PrintMem};
1530 void Item_PrintMem(void)
1532 DoDialog(&ShowMemd);
1535 void PrintMem(int x,int y)
1542 itoa(XMSTotalFree(),memstring,10);
1543 strcat(memstring,"K");
1548 total=(MMTotalFree()*16L)/1024;
1549 ltoa(total,memstring,10);
1550 strcat(memstring,"K");
1584 ////////////////////////////////////////////////////
1586 // CARMACIZE THE MAP FILE!
1588 ////////////////////////////////////////////////////
1589 void Item_Huffman(void)
1591 OutputHeadStr NewFileHeader;
1592 char huffname[14]="GAMEMAPS.",huffheadname[14]="MAPSHEAD.",tempstr[200],
1593 mapidstr[8]=IDSTRING,objname[14],dictname[14],tempname[14];
1594 int dx,dy,i,oxb,oyb,maplengths[100];
1595 MapHeaderStr TempHeader;
1596 memptr block,block1,block2;
1597 long size,fsize,nsize;
1602 strcat(huffname,ext);
1603 strcat(huffheadname,ext);
1604 strcpy(tempstr,"This will take a while.\n");
1605 strcat(tempstr,huffname);
1606 strcat(tempstr,". [ ]");
1607 ErrDialog(tempstr,"");
1618 MMFreePtr((memptr *)&MapBkgnd);
1619 MMFreePtr((memptr *)&CutBkgnd);
1623 MMFreePtr((memptr *)&MapFrgnd);
1624 MMFreePtr((memptr *)&CutFrgnd);
1628 MMFreePtr((memptr *)&MapInfoPl);
1629 MMFreePtr((memptr *)&CutInfoPl);
1633 // Now, time to Carmacize all the maps
1637 print("Carmacizing");
1641 SaveFile(huffname,(char huge *)&mapidstr,fsize,strlen(mapidstr));
1642 fsize+=strlen(mapidstr);
1644 memset(&maplengths,0,sizeof(long)*100);
1645 memset(&NewFileHeader,0,sizeof(OutputHeadStr));
1646 MMAllocate(&block1,sizeof(MapHeaderStr));
1648 if (MapFileHeader->dataoffsets[i]!=-1)
1655 LoadFile(mapname,(char huge *)&TempHeader,MapFileHeader->dataoffsets[i],sizeof(MapHeaderStr));
1658 // COMPRESS EACH MAP PLANE
1661 if (MapFileHeader->maptype&BPLANE)
1663 size=TempHeader.mapbkgndlen;
1664 MMAllocate(&block,size);
1665 MMAllocate(&block2,size);
1666 LoadFile(mapname,block,TempHeader.mapbkgndpl,size);
1667 *(int _seg *)block2=TempHeader.mapbkgndlen;
1668 nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2;
1669 maplengths[i]+=nsize;
1672 RestoreBackground();
1679 ErrDialog("ESC out of this infernal thing!"," YES! ");
1683 SaveFile(huffname,block2,fsize,nsize);
1684 TempHeader.mapbkgndpl=fsize;
1685 TempHeader.mapbkgndlen=nsize;
1690 if (MapFileHeader->maptype&FPLANE)
1692 size=TempHeader.mapfrgndlen;
1693 MMAllocate(&block,size);
1694 MMAllocate(&block2,size);
1695 LoadFile(mapname,block,TempHeader.mapfrgndpl,size);
1696 *(int _seg *)block2=TempHeader.mapfrgndlen;
1697 nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2;
1698 maplengths[i]+=nsize;
1701 RestoreBackground();
1708 ErrDialog("ESC out of this infernal thing!"," YES! ");
1712 SaveFile(huffname,block2,fsize,nsize);
1713 TempHeader.mapfrgndpl=fsize;
1714 TempHeader.mapfrgndlen=nsize;
1719 if (MapFileHeader->maptype&IPLANE)
1721 size=TempHeader.mapinfolen;
1722 MMAllocate(&block,size);
1723 MMAllocate(&block2,size);
1724 LoadFile(mapname,block,TempHeader.mapinfopl,size);
1725 *(int _seg *)block2=TempHeader.mapinfolen;
1726 nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2;
1727 maplengths[i]+=nsize;
1730 RestoreBackground();
1737 ErrDialog("ESC out of this infernal thing!"," YES! ");
1741 SaveFile(huffname,block2,fsize,nsize);
1742 TempHeader.mapinfopl=fsize;
1743 TempHeader.mapinfolen=nsize;
1753 nsize=sizeof(TempHeader);
1754 maplengths[i]+=nsize;
1755 SaveFile(huffname,(char huge *)&TempHeader,fsize,nsize);
1756 NewFileHeader.dataoffsets[i]=fsize;
1759 SaveFile(huffname,"!ID!",fsize,4);
1766 // COPY PERTINENT MAPFILEHEADER DATA TO NEWFILEHEADER
1769 char outname[14],tempname[14]="MTEMP.TMP",doutname[14];
1772 strcpy(outname,ext);
1773 strcat(outname,"MHEAD.OBJ");
1775 NewFileHeader.RLEWtag=MapFileHeader->RLEWtag;
1776 fsize=sizeof(OutputHeadStr);
1777 SaveFile(tempname,(char huge *)&NewFileHeader,0,fsize);
1779 for (i=0;i<numtplanes;i++)
1781 SaveFile(tempname,MK_FP(Tinfo[i],0),fsize,tilenum);
1784 for (i=0;i<numtmplanes;i++)
1786 SaveFile(tempname,MK_FP(TMinfo[i],0),fsize,tilemnum);
1790 MakeOBJ(tempname,outname,"_maphead",FARDATA,"MapHeader");
1791 // unlink(tempname);
1794 RestoreBackground();
1798 // FINSIHED. PRINT REPORT?
1800 if (Message("Finished with compression.\n"
1801 "Print report on lengths?")==2)
1803 fprintf(stdprn,"TED5 Carmacized Map Lengths for .%s\n\n",ext);
1804 fprintf(stdprn,"#\tMap Name\t\tLength\n");
1805 fprintf(stdprn,"_\t--------\t\t------\n");
1807 if (MapFileHeader->dataoffsets[i]!=-1)
1810 strcpy(tstr,MapNames[i]);
1811 while(strlen(tstr)<16)
1813 fprintf(stdprn,"%d\t%s\t%d\n",i,tstr,maplengths[i]);
1815 fprintf(stdprn,"%c",12);
1824 ////////////////////////////////////////////////////
1826 // Item - Change the LAUNCH name
1828 ////////////////////////////////////////////////////
1829 btype CLNb={" ",1,5,1};
1830 DialogDef CLNd={"Current LAUNCH name:\n\n\nNew LAUNCH name:",38,7,1,&CLNb,NULL};
1832 void Item_LAUNCHname(void)
1838 DrawDialog(&CLNd,1);
1839 GetDialogXY(&CLNd,&sx,&sy);
1843 GetButtonXY(&CLNd,0,&sx,&sy);
1844 if (input(tempstr,36))
1846 strcpy(launchname,tempstr);
1850 RestoreBackground();
1854 ////////////////////////////////////////////////////
1856 // Item - Change the PARM string
1858 ////////////////////////////////////////////////////
1859 btype CPSb={" ",1,5,1};
1860 DialogDef CPSd={"Current PARM string:\n\n\nNew PARM string:",38,7,1,&CPSb,NULL};
1862 void Item_PARMstring(void)
1868 DrawDialog(&CPSd,1);
1869 GetDialogXY(&CPSd,&sx,&sy);
1873 GetButtonXY(&CPSd,0,&sx,&sy);
1874 if (input(tempstr,36))
1876 strcpy(parmstring,tempstr);
1877 _fstrcpy(TEDInfo->parmstring,(char far *)parmstring);
1881 RestoreBackground();
1885 ////////////////////////////////////////////////////
1887 // Item - Change Icon Rows
1889 ////////////////////////////////////////////////////
1890 btype CIRb={" ",8,4,1};
1891 DialogDef CIRd={"Enter amount of icons\n"
1893 "Use + or -.",22,6,1,&CIRb,NULL};
1895 void Item_ChangeIconRows(void)
1897 unsigned i,j,dx,dy,max,oxbase,oybase,base;
1902 if (!(MapFileHeader->maptype&IPLANE))
1904 ErrDialog("You don't have an icon plane!"," OK ");
1913 DrawDialog(&CIRd,1);
1914 GetButtonXY(&CIRd,0,&dx,&dy);
1920 if (!value || value==(int)ESCOUT)
1922 RestoreBackground();
1926 value=SGN(value)*(18*((abs(value)+17)/18));
1928 base=18*maxiconrows;
1929 maxiconrows+=value/18;
1930 MapFileHeader->NumIconRows+=value/18;
1933 RestoreBackground();
1937 // MAKE SURE WE ADJUST TILEINFOM!
1939 MMAllocate(&block,tilemnum+value);
1940 for (i=0;i<numtmplanes;i++)
1942 _fmemset(block,0,tilemnum+value);
1943 movedata((unsigned)TMinfo[i],0,(unsigned)block,0,base);
1944 movedata((unsigned)TMinfo[i],base,
1945 (unsigned)block,base+value,tilemnum-base);
1946 MMFreePtr((memptr *)&TMinfo[i]);
1947 MMAllocate((memptr *)&TMinfo[i],tilemnum+value);
1948 movedata((unsigned)block,0,(unsigned)TMinfo[i],0,tilemnum+value);
1951 MapFileHeader->oldtilemnum=tilemnum+value;
1955 // RUN THROUGH EACH MAP AND ADJUST TILEM VALUES
1958 if (MapFileHeader->dataoffsets[i]>=0)
1962 max=mapwidth*mapheight;
1976 ErrDialog("If your map looks messed up,\n"
1977 "you need to change the amount\n"
1978 "of icons in your IGRAB script\n"
1979 "and re-grab your tiles!"," OK ");
1983 ////////////////////////////////////////////////////
1985 // Item - Change LAUNCH Icon
1987 ////////////////////////////////////////////////////
1988 void Item_ChangeLaunchIcon(void)
1991 TEDInfo->permicon=whichi-tilenum;
1997 ////////////////////////////////////////////////////
1999 // Item - Change Background color
2001 ////////////////////////////////////////////////////
2002 btype CBCb[]={{"\xb",5,2,1},
2005 DialogDef CBCd={"Change Backgrnd Color!",22,4,3,&CBCb[0],0};
2006 void Item_ChangeBkgndColor(void)
2012 which=DoDialog(&CBCd);
2019 TEDInfo->BackgndColor=BkgndColor;
2025 if (++BkgndColor>15)
2027 TEDInfo->BackgndColor=BkgndColor;
2032 } while(which>0 && which<3);