home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / sphinx / examples / vga / tinydraw.c__ < prev    next >
Encoding:
Text File  |  1994-05-14  |  50.0 KB  |  2,011 lines

  1. /*
  2.     SPHINX Programming (C) 1994
  3.     NAME:  TINYDRAW.C--
  4.     DESCRIPTION:  The under 19K, 320x200-256 drawing program for creating
  5.                   and editing:
  6.                        *.CUT image files
  7.                        *.III icon files
  8.                        *.SCR screen files
  9.                        *.PAL palette files
  10.                        *.COM picture files (self displaying)
  11.                        *.PCX picture and cut files
  12.     RUN FILE SIZE:  18698 bytes.
  13.     SYSTEM REQUIREMENTS:
  14.         - 8086, but for colour cycling option or flood file 80286+ CPU
  15.           required, for ellipses, 80386+ required.
  16.         - VGA or better display
  17.         - 20K free disk space
  18.         - 300K free memory
  19.         - Microsoft Compatable Mouse and Driver
  20.     PROPERTY OF:  Peter Cellik
  21.     Last Modified:  14 May 1994
  22. */
  23.  
  24.  
  25. ? print "Building TINYDRAW.COM, the 320x200 256 colour drawing program.\n"
  26.  
  27. ? use8086          // restrict code to 8086, for the good old PC's and XT's
  28. ? resize TRUE      // resize memory block
  29. ? resizemessage  "Unable to resize program memory block.\n"
  30. ? stack 20*1024    // 20k stack
  31. ? alignword TRUE   // align words
  32. ? parsecommandline TRUE // do not parse the command line
  33.  
  34. ?include "KEYCODES.H--"   // include keyboard key codes
  35. ?include "FILE.H--"       // include readfile() and writefile()
  36. ?include "VIDEO.H--"      // include video mode values
  37. ?include "VGA.H--"        // include some graphics procedures
  38. ?include "VGAFONT.H--"    // include small vga font support
  39. ?include "DOS.H--"        // include DTA_ADDRESS
  40. ?include "WRITE.H--"      // text display procedures
  41. ?include "GWRITE.H--"     // text display in graphics mode
  42. ?include "STRING.H--"     // get some string functions
  43. ?include "RANDOM.H--"     // random number generator
  44. ?include "MOUSE.H--"      // mouse stuff
  45. ?include "VGAFILL.H--"    // flood fill routine
  46. ?include "VGA386.H--"     // ellipse commands
  47. ?include "PCX.H--"        // PCX file format support
  48.  
  49. byte bye = "\nThis version of TINYDRAW is FREEWARE.\n"
  50.              "Feel free to copy it and share it with your friends,\n"
  51.              "so long as it is not modified in any way.\n"
  52.              "If you have any loose cash, suggestions or questions\n"
  53.              "you can contact me at the following address:\n\n"             
  54.              "PETER CELLIK\n"
  55.              "RR#2 Site 33 C11\n"
  56.              "Gabriola Is.  B.C.\n"
  57.              "V0R 1X0\n"
  58.              "CANADA\n\n\n"
  59.              "Have a nice day, or two.\n";
  60.  
  61. word screenbuf1ptr,screenbuf2ptr;
  62. word iiibufptr,cutbufptr;
  63.  
  64. ?define  CLEARCOLOR  45   // transparent color for icons
  65.  
  66. enum { d_UNDO,d_FILLEDDOTS, d_OPENDOTS, d_RANDOMFILLEDDOTS, d_RANDOMOPENDOTS,
  67.        d_SETDOTSIZE, d_TEXT, d_SMALLTEXT, d_DRAWLINE, d_LINE,
  68.        d_XORLINE, d_ORIGINLINE, d_INCORIGINLINE,
  69.        d_BOX, d_BAR, d_XORBOX, d_XORBAR, d_FLOODFILL, d_ELLIPSE,
  70.        d_CUTIII, d_CUTCUT, d_PUTIII, d_PUTCUT, d_DRAWIII, d_DRAWCUT,
  71.        d_RESIZECUT,
  72.        d_SAVEIII, d_LOADIII, d_SAVECUT, d_LOADCUT, d_SAVEPCXCUT, d_LOADPCXCUT,
  73.        d_SAVECOM, d_LOADCOM, d_SAVEPCX, d_LOADPCX,
  74.        d_SAVESCR, d_LOADSCR, d_SAVEPAL, d_LOADPAL, d_LOADPCXPAL,
  75.        d_NUKE, d_CYCLE, d_EXIT, OPTIONS };
  76. byte commandstr = "UNDO             <u>\000"
  77.                   "Draw Filled Dots <d>\000"  "Draw UnFilled Dots  \000"
  78.                   "Random Filled Dots  \000"  "Random UnFilled Dots\000"
  79.                   "Set Dot Size     <D>\000"  "Put Text         <t>\000"
  80.                   "Put Small Text   <T>\000"
  81.                   "Curved Line      <l>\000"  "Straight Line    <L>\000"
  82.                   "XOR Straight Line   \000"
  83.                   "Origin Line         \000"  "Incrementing Origin \000"  
  84.                   "Rectangle        <r>\000"  "Filled Rectangle <R>\000"
  85.                   "XOR Rectangle       \000"  "XOR Filled Rectangle\000"
  86.                   "Flood Fill       <f>\000"  "Ellipse          <e>\000"
  87.                   "Cut Icon         <C>\000"  "Cut CUT          <c>\000"
  88.                   "Put Icon         <P>\000"  "Put CUT          <p>\000"
  89.                   "Draw With Icon      \000"  "Draw With CUT       \000"
  90.                   "Resize CUT          \000"
  91.                   "Save Icon       <F8>\000"  "Load Icon       <F7>\000"  
  92.                   "Save CUT        <F6>\000"  "Load CUT        <F5>\000"
  93.                   "Save CUT as PCX     \000"  "Load CUT from PCX   \000"
  94.                   "Save Picture    <F2>\000"  "Load Picture    <F3>\000"
  95.                   "Save Picture as PCX \000"  "Load PCX Picture    \000"
  96.                   "Save Screen         \000"  "Load Screen         \000"
  97.                   "Save Palette    <F9>\000"  "Load Palette   <F10>\000"
  98.           "Load PCX Palette    \000"
  99.                   "Clear Picture    <N>\000"  "Toggle Cycling <tab>\000" 
  100.                   "EXIT TINY DRAW <ESC>\000";
  101. ?define  COLORSELECTSTART  OPTIONS+1/2*8
  102. byte drawtype = d_DRAWLINE;
  103. word dotxsize = 1, dotysize = 1;
  104.  
  105. byte colour = 8;     /* current colour */
  106.  
  107. ?define FILENAMELEN 36
  108. byte scrfilename[FILENAMELEN] = "NAMELESS.SCR";  /* screen file name */
  109. byte palfilename[FILENAMELEN] = "NAMELESS.PAL";  /* palette file name */
  110. byte iiifilename[FILENAMELEN] = "NAMELESS.III";  /* icon file name */
  111. byte cutfilename[FILENAMELEN] = "NAMELESS.CUT";  /* cut file name */
  112. byte comfilename[FILENAMELEN] = "NAMELESS.COM";  /* com file name */
  113. byte pcxfilename[FILENAMELEN] = "NAMELESS.PCX";  /* pcx file name */
  114.  
  115. ?define  SCREENSIZE  64000  /* size of screen in bytes */
  116.  
  117. ?define PALSIZE    256*3    /* size of palette buffer 256 colours * RGB */
  118. byte palette[PALSIZE] = FROM "TINYDRAW.PAL";  // buffer for palette 
  119. byte palettehold[PALSIZE];              // temp buffer for palette 
  120.  
  121. byte did = TRUE;    /* was something done on the screen flag */
  122. byte quit = FALSE;  /* finished flag */
  123.  
  124. word undobuf = 0;   /* segment address modifier for screen buffer */ 
  125. word iiisize = 0;   // size in bytes of current icon image (III)
  126. word cutsize = 0;   // size in bytes of current cut image (CUT)
  127.  
  128. /************************* start of timer int ****************************/
  129. byte cycleit = TRUE;      /* temp off/on used by main program */
  130. byte cycleon = FALSE;     /* activate/disactivate flag */
  131.  
  132. ?define TIMERINT  0x8
  133. byte busy=0,cyclecount=0,redblue=0;
  134. word oldtimerhandle[2];
  135. byte holdR,holdG,holdB;
  136. ?define  DACSTART    46
  137. ?define  CYCLESTART  DACSTART*3
  138. ?define  DACS        2+8+8*3  
  139. byte flashflip=0;
  140. ?define  FLASHCOLOR  46
  141. ?define  FLASH       FLASHCOLOR*3
  142. ?define  FLASHCOLOR2 47
  143. ?define  FLASH2      FLASHCOLOR2*3
  144.  
  145.  
  146. interrupt timerhandle ()
  147. {
  148. $ PUSHF
  149. $ CS:
  150. $ CALL FAR oldtimerhandle;
  151. $ PUSH ES
  152. $ PUSH DS
  153. $ PUSHA
  154. DS = CS;
  155. if( busy == FALSE )
  156.     {busy = TRUE;
  157.     if( cycleit )
  158.       if( cycleon )
  159.         {holdR = palette[CYCLESTART  +24+6];
  160.         holdG = palette[CYCLESTART+1+24+6];
  161.         holdB = palette[CYCLESTART+2+24+6];
  162.         COPYFAR(DS,#palette[CYCLESTART+24+6],DS,#palette[CYCLESTART+3+24+6],7*3);
  163.         palette[CYCLESTART+48+3] = holdR;
  164.         palette[CYCLESTART+48+4] = holdG;
  165.         palette[CYCLESTART+48+5] = holdB;
  166.         redblue = 1 - redblue;
  167.         IF( redblue == 1 )
  168.             {holdR = palette[CYCLESTART+6];
  169.             holdG = palette[CYCLESTART+1+6];
  170.             holdB = palette[CYCLESTART+2+6];
  171.             COPYFAR(DS,#palette[CYCLESTART+6],DS,#palette[CYCLESTART+3+6],3*3);
  172.             palette[CYCLESTART  +6+9] = holdR;
  173.             palette[CYCLESTART+1+6+9] = holdG;
  174.             palette[CYCLESTART+2+6+9] = holdB;}
  175.         ELSE{holdR = palette[CYCLESTART+6+12];
  176.             holdG = palette[CYCLESTART+1+6+12];
  177.             holdB = palette[CYCLESTART+2+6+12];
  178.             COPYFAR(DS,#palette[CYCLESTART+6+12],DS,#palette[CYCLESTART+6+12+3],3*3);
  179.             palette[CYCLESTART+6+12+9] = holdR;
  180.             palette[CYCLESTART+1+6+12+9] = holdG;
  181.             palette[CYCLESTART+2+6+12+9] = holdB;} 
  182.         flashflip = 1-flashflip;
  183.         IF( flashflip == 1 )
  184.             {palette[FLASH] = RAND()&63;
  185.             palette[FLASH+1] = RAND()&63;
  186.             palette[FLASH+2] = RAND()&63;}
  187.         ELSE{palette[FLASH2] = RAND()&63;
  188.             palette[FLASH2+1] = RAND()&63;
  189.             palette[FLASH2+2] = RAND()&64;}
  190.         @ WAITVSYNC();
  191.         @ SETVGADAC(DACSTART, ,DACS, , ,#palette[CYCLESTART]);
  192.         }
  193.     busy = FALSE;
  194.     }
  195. $ POPA
  196. $ POP DS
  197. $ POP ES
  198. }
  199.  
  200.  
  201. /**************************** MOUSE routines ******************************/ 
  202.  
  203. word x,y;      /* global variable for mouse pointer x and y coordinates */ 
  204. byte buttons;  /* global variable mouse button status */ 
  205.  
  206. void getmouse ()
  207. {@ GETMOUSEXY();
  208. y = DX;
  209. buttons = BL;
  210. x = CX /2;     /* adjust x after so as not to undefine the regs */
  211. }
  212.  
  213.  
  214. void waitmouse ()
  215. /* wait until both mouse buttons are released, or a key is pressed */
  216. byte done;
  217. {done = FALSE;
  218. do {getmouse();
  219.     IF( buttons == 0 )
  220.         done = TRUE;
  221.     IF( KBHIT() )
  222.         {BIOSREADKEY();
  223.         done = TRUE;}    
  224.     } while( done == FALSE );
  225. }
  226.  
  227. /********************* main() routines **********************************/ 
  228.  
  229. void SETCOLOR ()    // AL contains new current colour to be set 
  230. /* set the current drawing colour and border colour */
  231. {colour = AL; 
  232. cycleit = FALSE;
  233. SETBORDERCOLOR(AL);
  234. cycleit = TRUE;
  235. }
  236.  
  237.  
  238. /********** start screen text ***********/
  239.  
  240. void startscreen ()
  241. word i;
  242. byte done;
  243. {HIDEMOUSE();
  244. GWRITESTR("TINYDRAW  ",31);
  245. GWRITESTR("Version 1.03  ",15);
  246. GWRITESTR("By: Peter Cellik",7);
  247. xorbar19(0,0,320,8,16);
  248. i = 64;
  249. do {
  250.     line19(0,i-64+8,319,8,i);
  251.     line19(319,199+64-i,0,199,i);
  252.     i++; 
  253.     } while( i < 256 );
  254. SHOWMOUSE();
  255. done = FALSE;
  256. do {
  257.     IF( KBHIT() <> 0 )
  258.         done = TRUE;
  259.     getmouse();
  260.     IF( buttons <> 0 )
  261.         done = TRUE;
  262.     } while (done == FALSE);
  263. HIDEMOUSE();
  264. clearscreen();
  265. SHOWMOUSE();
  266. }
  267.  
  268.  
  269. byte getbuffers ()
  270. {
  271. @ALLOCBESTFIT();
  272. screenbuf1ptr = GETMEM(4000);
  273. IF( screenbuf1ptr == 0 )
  274.     return(1);
  275. screenbuf2ptr = GETMEM(4000);
  276. IF( screenbuf2ptr == 0 )
  277.     return(1);
  278. iiibufptr = GETMEM(4001);
  279. IF( iiibufptr == 0 )
  280.     return(1);
  281. cutbufptr = GETMEM(4001);
  282. IF( cutbufptr == 0 )
  283.     return(1);
  284. return(0);
  285. }
  286.  
  287.  
  288. void loadstartupfiles ()
  289. word count,length,numparams;
  290. byte str[80];
  291. {
  292. HIDEMOUSE();
  293. numparams = PARAMCOUNT();
  294. count = 0;
  295. do {
  296.     strcpy(#str,PARAMSTR(count));
  297.     length = STRLEN(#str);
  298.     if( length > 4 )
  299.         {
  300.         STR_UP(#str);
  301.         IF( STRCMP(#str+length-4,".PAL") == 0 )
  302.             {strcpy(#palfilename,#str);
  303.             readpalfile();}
  304.         else IF( STRCMP(#str+length-4,".SCR") == 0 )
  305.             {strcpy(#scrfilename,#str);
  306.             readscrfile();}
  307.         else IF( STRCMP(#str+length-4,".COM") == 0 )
  308.             {strcpy(#comfilename,#str);
  309.             readcomfile();}
  310.         ELSE IF( STRCMP(#str+length-4,".III") == 0 )
  311.             {strcpy(#iiifilename,#str);
  312.             readiiifile();}
  313.         ELSE IF( STRCMP(#str+length-4,".CUT") == 0 )
  314.             {strcpy(#cutfilename,#str);
  315.             readcutfile();}
  316.         ELSE IF( STRCMP(#str+length-4,".PCX") == 0 )
  317.             {strcpy(#pcxfilename,#str);
  318.             readpcxfile();}
  319.         ELSE BEEP();
  320.         }
  321.     ELSE BEEP();
  322.     count++;
  323.     } while( count < numparams ); 
  324. comeback();
  325. }
  326.  
  327.  
  328. main ()
  329. {
  330. IF( byte getbuffers() == 1 )   /* allocate screen and cut buffers */
  331.     {WRITESTR("Not enough free memory, 300k required.\n");
  332.     EXIT(-1);
  333.     }
  334. @ SETVIDEOMODE( vid_320x200_256 );    /* set video mode */
  335. IF( @ GETVIDEOMODE() != vid_320x200_256)  /* check if mode setting worked */
  336.     {WRITESTR("Unable to enter 320x200 256 colour video mode.");
  337.     EXIT(-1);}
  338. clearscreen();
  339. WAITVSYNC();
  340. SETVGAPALETTE( ,0,256,#palette);  
  341. @ GETINTVECT(#oldtimerhandle,TIMERINT);
  342. SETINTVECT( ,TIMERINT,CS,#timerhandle);
  343.  
  344. @ RESETMOUSE();
  345. SHOWMOUSE();
  346. go();
  347. remember();
  348. SETBORDERCOLOR(colour);
  349.  
  350. IF( byte GETCPU() >= 2 )
  351.     cycleon = TRUE - cycleon;
  352.  
  353. IF( PARAMCOUNT() == 0 )
  354.     {startscreen();
  355.     docommandscreen();
  356.     }
  357. ELSE loadstartupfiles();
  358.  
  359. IF( quit == FALSE )
  360.     {do {doit();
  361.         } while( quit == FALSE );
  362.     }
  363.  
  364. SETINTVECT( ,TIMERINT,oldtimerhandle[2],oldtimerhandle[0]);
  365. HIDEMOUSE();
  366. @ SETVIDEOMODE( vid_text80c );    /* return to text mode */
  367. WRITESTR("SPHINX Programming 1994\n");
  368. WRITESTR("\nTINYDRAW was compiled using ");
  369. WRITESTR(__COMPILER__);      /* display compiler name and version */
  370. WRITELN();   
  371. WRITESTR(#bye);              /* display ending message */
  372. }
  373.  
  374.  
  375. byte reallyquit ()
  376. {go();
  377. putwindow(5*8,8*8,29*8,1*8);
  378. GOTOXY(5,8);
  379. WRITESTR("Exit TinyDraw?  [Y]es or [N]o");
  380. AX = BIOSREADKEY();
  381. IF( AL == 'Y' )
  382.     return(TRUE);
  383. IF( AL == 'y' )
  384.     return(TRUE);
  385. comeback();
  386. return(FALSE);
  387. }
  388.  
  389.  
  390. byte dothekey ()
  391. {AX = BIOSREADKEY();
  392.  
  393. IF(AX==k_up)
  394.     SETCOLOR( colour+1 );
  395. else IF(AX==k_down)
  396.     SETCOLOR( colour-1 );
  397. else IF(AX==k_F1)
  398.     helpscreen();
  399. else IF(AX==k_F2)
  400.     savecom();
  401. else IF(AX==k_F3)
  402.     loadcom();
  403. else IF(AX==k_F5)
  404.     loadcut();
  405. else IF(AX==k_F6)
  406.     savecut();
  407. else IF(AX==k_F7)
  408.     loadiii();
  409. else IF(AX==k_F8)
  410.     saveiii();
  411. else IF(AX==k_F9)
  412.     loadpal();
  413. else IF(AX==k_F10)
  414.     savepal();
  415. else IF(AX==k_tab)
  416.     {IF( byte GETCPU() >= 2 )
  417.         cycleon = TRUE - cycleon;
  418.     ELSE BEEP();}
  419. else IF(AX==k_backspace)
  420.     doundo();
  421. else IF(AX==k_delete)
  422.     {HIDEMOUSE();
  423.     getmouse();
  424.     SETCOLOR( GETPIXEL19( ,x, ,y) );
  425.     SHOWMOUSE();}
  426. else IF(AL=='u')
  427.     doundo();
  428. else IF(AL=='U')
  429.     doundo();
  430. else IF(AL=='t')
  431.     drawtype = d_TEXT;
  432. else IF(AL=='T')
  433.     drawtype = d_SMALLTEXT;
  434. else IF(AL=='d')
  435.     drawtype = d_FILLEDDOTS;
  436. else IF(AL=='D')
  437.     drawtype = d_SETDOTSIZE;
  438. else IF(AL=='l')
  439.     drawtype = d_DRAWLINE;
  440. else IF(AL=='L')
  441.     drawtype = d_LINE;
  442. else IF(AL=='R')
  443.     drawtype = d_BAR;
  444. ELSE IF(AL=='r')
  445.     drawtype = d_BOX;
  446. ELSE IF(AL=='c')
  447.     drawtype = d_CUTCUT;
  448. ELSE IF(AL=='C')
  449.     drawtype = d_CUTIII;
  450. ELSE IF(AL=='p')
  451.     drawtype = d_PUTCUT;
  452. ELSE IF(AL=='P')
  453.     drawtype = d_PUTIII;
  454. ELSE IF(AL=='f')
  455.     {IF( byte GETCPU() >= 2 )
  456.         drawtype = d_FLOODFILL;
  457.     ELSE BEEP();}
  458. ELSE IF(AL=='e')
  459.     {IF( byte GETCPU() >= 3 )
  460.         drawtype = d_ELLIPSE;
  461.     ELSE BEEP();}
  462. ELSE IF(AL=='N')
  463.     donuke();
  464. ELSE IF(AX==k_esc)
  465.     quit = reallyquit();
  466. ELSE BEEP();
  467. }
  468.  
  469.  
  470. void doit ()
  471. {IF( KBHIT() != 0 )
  472.     dothekey();
  473. else{getmouse();
  474.     if(buttons==1)
  475.         {if( drawtype == d_FILLEDDOTS )
  476.             dodots(TRUE,FALSE);
  477.         else IF( drawtype == d_OPENDOTS )
  478.             dodots(FALSE,FALSE);
  479.         else IF( drawtype == d_RANDOMFILLEDDOTS )
  480.             dodots(TRUE,TRUE);
  481.         else IF( drawtype == d_RANDOMOPENDOTS )
  482.             dodots(FALSE,TRUE);
  483.         else IF( drawtype == d_TEXT )
  484.             dotext();
  485.         else IF( drawtype == d_SMALLTEXT )
  486.             dosmalltext();
  487.         else IF( drawtype == d_DRAWIII )
  488.             drawcutoriii(TRUE);
  489.         else IF( drawtype == d_DRAWCUT )
  490.             drawcutoriii(FALSE);
  491.         else IF( drawtype == d_CUTIII )
  492.             cutiii();
  493.         ELSE IF( drawtype == d_PUTIII )
  494.             putcutoriii(TRUE);
  495.         ELSE IF( drawtype == d_PUTCUT )
  496.             putcutoriii(FALSE);
  497.         ELSE IF( drawtype == d_SETDOTSIZE )
  498.             dotwodrag(); 
  499.         ELSE IF( drawtype == d_CUTCUT )
  500.             dotwodrag(); 
  501.         ELSE IF( drawtype == d_DRAWLINE )
  502.             dodrawline(); 
  503.         ELSE IF( drawtype == d_ORIGINLINE )
  504.             dooriginline(FALSE); 
  505.         ELSE IF( drawtype == d_INCORIGINLINE )
  506.             dooriginline(TRUE); 
  507.         ELSE IF( drawtype == d_FLOODFILL )
  508.             dofloodfill(); 
  509.         ELSE dotwocoord();
  510.         }
  511.     ELSE IF(buttons==2)
  512.         docommandscreen();
  513.     }
  514. }
  515.  
  516.  
  517. void dotwocoord ()
  518. word holdx,holdy;   /* used for holding mouse status */
  519. word deltax,deltay,startx,starty,oldx,oldy;
  520. word olddeltax,olddeltay,oldstartx,oldstarty;
  521. {holdx = x;
  522. holdy = y;
  523. startx = x;
  524. starty = y;
  525. oldx = startx;
  526. oldy = starty;
  527. deltax = 1;
  528. deltay = 1;
  529. HIDEMOUSE();
  530. IF( drawtype == d_BAR )
  531.     bar19(startx,starty,deltax,deltay,colour);
  532. else IF( drawtype == d_BOX )  
  533.     box19(startx,starty,deltax,deltay,colour);
  534. else IF( drawtype == d_XORLINE )  
  535.     xorline19(holdx,holdy,x,y,colour);
  536. else IF( drawtype == d_XORBOX )  
  537.     xorbox19(startx,starty,deltax,deltay,colour);
  538. else IF( drawtype == d_ELLIPSE )  
  539.     ellipse19_386(deltax/2+startx,deltay/2+starty,deltax/2,deltay/2,colour);
  540. ELSE IF( drawtype == d_XORBAR )  
  541.     xorbar19(startx,starty,deltax,deltay,colour);
  542. ELSE IF( drawtype == d_LINE )  
  543.     line19(holdx,holdy,x,y,colour);
  544. ELSE IF( drawtype == d_RESIZECUT )
  545.     {$ PUSH DS
  546.     DS = iiibufptr;
  547.     putresized19(holdx,holdy,deltax,deltay,0);
  548.     $ POP DS
  549.     }
  550. ELSE BEEP();
  551. do {getmouse();
  552.     BL = FALSE;
  553.     IF( oldx <> x )
  554.         BL = TRUE;
  555.     IF( oldy <> y )
  556.         BL = TRUE;
  557.     if( BL == TRUE )
  558.         {oldx = x;
  559.         oldy = y;
  560.         IF( drawtype == d_ELLIPSE )
  561.             {deltax++;
  562.             deltay++;
  563.             }
  564.         $ PUSH DS
  565.         IF( undobuf == 0 )
  566.             DS = screenbuf1ptr;
  567.         ELSE DS = screenbuf2ptr;
  568.         trans19(startx,starty,deltax,deltay);     
  569.         $ POP DS
  570.         IF( drawtype == d_ELLIPSE )
  571.             {deltax--;
  572.             deltay--;
  573.             }
  574.         IF( x > holdx )
  575.             {deltax = x-holdx+1;
  576.             startx = holdx;}  
  577.         ELSE IF( x < holdx )
  578.             {deltax = holdx-x+1;
  579.             startx = x;}  
  580.         ELSE{deltax = 1;
  581.             startx = holdx;}
  582.  
  583.         IF( y > holdy )
  584.             {deltay = y-holdy+1;
  585.             starty = holdy;}  
  586.         ELSE IF( y < holdy )
  587.             {deltay = holdy-y+1;
  588.             starty = y;}  
  589.         ELSE{deltay = 1;
  590.             starty = holdy;}
  591.  
  592.         IF( drawtype == d_BAR )
  593.             bar19(startx,starty,deltax,deltay,colour);
  594.         else IF( drawtype == d_BOX )  
  595.             box19(startx,starty,deltax,deltay,colour);
  596.         else IF( drawtype == d_XORLINE )  
  597.             xorline19(holdx,holdy,x,y,colour);
  598.         else IF( drawtype == d_XORBOX )  
  599.             xorbox19(startx,starty,deltax,deltay,colour);
  600.         else IF( drawtype == d_ELLIPSE )  
  601.             ellipse19_386(deltax/2+startx,deltay/2+starty,deltax/2,deltay/2,colour);
  602.         ELSE IF( drawtype == d_XORBAR )  
  603.             xorbar19(startx,starty,deltax,deltay,colour);
  604.         ELSE IF( drawtype == d_LINE )  
  605.             line19(holdx,holdy,x,y,colour);
  606.         ELSE IF( drawtype == d_RESIZECUT )
  607.             {$ PUSH DS
  608.             DS = cutbufptr;
  609.             putresized19(startx,starty,deltax,deltay,0);
  610.             $ POP DS
  611.             }
  612.         ELSE BEEP();
  613.         }
  614.    } while( buttons != 0 ); 
  615.  
  616. IF( drawtype == d_RESIZECUT )
  617.     {getimage19(startx,starty,deltax,deltay,cutbufptr,0);
  618.     cutsize = deltax*deltay+4;
  619.     drawtype = d_PUTCUT;
  620.     $ PUSH DS
  621.     IF( undobuf == 0 )
  622.         DS = screenbuf1ptr;
  623.     ELSE DS = screenbuf2ptr;
  624.     trans19(startx,starty,deltax,deltay);     
  625.     $ POP DS
  626.     @ SHOWMOUSE();
  627.     }
  628. ELSE remember();
  629. }
  630.  
  631.  
  632. void dotwodrag ()
  633. word holdx,holdy;   /* used for holding mouse status */
  634. word deltax,deltay,startx,starty;
  635. word olddeltax,olddeltay,oldstartx,oldstarty;
  636. byte dragcolor;
  637. {holdx = x;
  638. holdy = y;
  639. startx = x;
  640. starty = y;
  641. deltax = 1;
  642. deltay = 1;
  643. HIDEMOUSE();
  644. dragcolor = RAND();
  645. xorbox19(startx,starty,deltax,deltay,dragcolor); 
  646. do {
  647.     olddeltax = deltax;
  648.     olddeltay = deltay;
  649.     oldstartx = startx;
  650.     oldstarty = starty;
  651.     getmouse();    
  652.     IF( x > holdx )
  653.         {deltax = x-holdx+1;
  654.         startx = holdx;}  
  655.     ELSE IF( x < holdx )
  656.         {deltax = holdx-x+1;
  657.         startx = x;}  
  658.     ELSE{deltax = 1;
  659.         startx = holdx;}
  660.  
  661.     IF( y > holdy )
  662.         {deltay = y-holdy+1;
  663.         starty = holdy;}  
  664.     ELSE IF( y < holdy )
  665.         {deltay = holdy-y+1;
  666.         starty = y;}  
  667.     ELSE{deltay = 1;
  668.         starty = holdy;}
  669.     xorbox19(oldstartx,oldstarty,olddeltax,olddeltay,dragcolor); 
  670.     dragcolor = RAND();
  671.     xorbox19(startx,starty,deltax,deltay,dragcolor); 
  672.    
  673.    } while( buttons != 0 ); 
  674. xorbox19(startx,starty,deltax,deltay,dragcolor); 
  675.  
  676. IF( drawtype == d_SETDOTSIZE )
  677.     {dotxsize = deltax;
  678.     dotysize = deltay;
  679.     drawtype = d_FILLEDDOTS;
  680.     }
  681. ELSE IF( drawtype == d_CUTCUT )
  682.     {getimage19(startx,starty,deltax,deltay,cutbufptr,0);
  683.     ES = cutbufptr;
  684.     cutsize = ESWORD[0]*ESWORD[2]+4;
  685.     drawtype = d_PUTCUT;
  686.     }
  687. SHOWMOUSE();
  688. }
  689.  
  690.  
  691. void go ()    /* Hide mouse and ensure that undo buffer is up to date */
  692. {HIDEMOUSE();
  693. DL = FALSE;
  694. IF( did == TRUE )
  695.     {undobuf = 1 - undobuf;
  696.     IF( undobuf == 0 )
  697.         COPYFARW(screenbuf1ptr,0,VGA_SEG,0,32000);
  698.     ELSE COPYFARW(screenbuf2ptr,0,VGA_SEG,0,32000);
  699.     did = FALSE;
  700.     }
  701. }
  702.  
  703.  
  704. void comeback ()   /* restore screen after go(); */
  705. {IF( undobuf == 0 )
  706.     COPYFARW(VGA_SEG,0,screenbuf1ptr,0,32000);
  707. ELSE COPYFARW(VGA_SEG,0,screenbuf2ptr,0,32000);
  708. @ SHOWMOUSE();
  709. }
  710.  
  711.  
  712. void remember ()   /* force update of undo buffer */
  713. {@ SHOWMOUSE();
  714. did = TRUE;
  715. go();
  716. @ SHOWMOUSE();
  717. }
  718.  
  719.  
  720. void docommandscreen ()
  721. byte done,chold,hidden;
  722. word commandhold,poscommand,poscolour;
  723. word startx,starty,deltax,deltay,key;
  724. {go();
  725. GOTOXY(0,0);
  726. DI = 0;
  727. SI = 0;
  728. do {IF( DI == drawtype )
  729.         GWRITESTR(#commandstr[SI],1);
  730.     ELSE GWRITESTR(#commandstr[SI],SI&1+2);
  731.     DI++;
  732.     SI += 21;
  733.     } while( DI < OPTIONS );
  734.  
  735. deltax = 0;
  736. do {bar19(deltax%64*5,deltax/64*5+COLORSELECTSTART,5,5,deltax);
  737.     deltax++;
  738.     } while( deltax < 256 );
  739.  
  740. waitmouse();
  741. @ SHOWMOUSE();
  742. done = 0;
  743. commandhold = OPTIONS;
  744. startx = 1000;
  745. hidden = FALSE;
  746. do {
  747.     IF( startx <> 1000 )
  748.         {WAITVSYNC();
  749.         xorbox19(startx,starty,deltax,deltay,chold);
  750.         }
  751.     chold = RAND();
  752.     getmouse();
  753.     AX = y/8 * 40;
  754.     BX = AX;
  755.     AX = x/8 + BX;
  756.     BX = AX;
  757.     poscommand = BX/20;
  758.     IF( poscommand < OPTIONS )
  759.         {startx = poscommand & 1 * 160;
  760.         starty = poscommand / 2 * 8;
  761.         IF( hidden == FALSE )
  762.             {HIDEMOUSE();
  763.             hidden = TRUE;}
  764.         deltax = 160;
  765.         deltay = 8;
  766.         WAITVSYNC();
  767.         xorbox19(startx,starty,160,8,chold);
  768.         }
  769.     else{
  770.         poscolour = y - COLORSELECTSTART / 5 * 64 * 5 + x / 5;
  771.         IF( poscolour < 256 )
  772.             {startx = poscolour % 64 * 5;
  773.             starty = poscolour / 64 * 5 + COLORSELECTSTART;
  774.             IF( hidden == FALSE )
  775.                 {HIDEMOUSE();
  776.                 hidden = TRUE;}
  777.             deltax = 5;
  778.             deltay = 5;
  779.             WAITVSYNC();
  780.             xorbox19(startx,starty,5,5,chold);
  781.             }
  782.         ELSE{startx = 1000;
  783.             IF( hidden == TRUE )
  784.                 {SHOWMOUSE();
  785.                 hidden = FALSE;
  786.                 }
  787.             } 
  788.         }
  789.  
  790.     IF( buttons == 1 )
  791.         {IF( poscommand < OPTIONS )
  792.             {commandhold = poscommand;
  793.             done = TRUE;}
  794.         ELSE IF( poscolour < 256 )
  795.             {SETCOLOR( poscolour );
  796.             waitmouse();}
  797.         ELSE done = TRUE;
  798.         }
  799.     ELSE IF( buttons == 2 )
  800.         done = TRUE;
  801.     if( KBHIT() <> 0 )
  802.         {key = BIOSREADKEY();
  803.         if( poscolour < 256 )
  804.             {AX = poscolour *3;
  805.             DI = AX;
  806.             cycleit = FALSE;
  807.             if( key == k_up )
  808.                 palette[DI+1] = palette[DI+1] +1 & 63;
  809.             else IF( key == k_down )
  810.                 palette[DI+1] = palette[DI+1] -1 & 63;
  811.             ELSE IF( key == k_pageup )
  812.                 palette[DI+2] = palette[DI+2] +1 & 63;
  813.             ELSE IF( key == k_pagedown )
  814.                 palette[DI+2] = palette[DI+2] -1 & 63;
  815.             ELSE IF( key == k_home )
  816.                 palette[DI] = palette[DI] +1 & 63;
  817.             ELSE IF( key == k_end )
  818.                 palette[DI] = palette[DI] -1 & 63;
  819.             ELSE IF( key == k_esc )
  820.                 done = TRUE;
  821.             SETVGAPALETTE( ,poscolour,1,#palette[DI]);  
  822.             cycleit = TRUE;
  823.             }
  824.         ELSE IF( key == k_esc )
  825.             done = TRUE;
  826.         }
  827.    } while( done == FALSE );
  828. IF( hidden == FALSE )
  829.     HIDEMOUSE();
  830. comeback();
  831. waitmouse();
  832. IF( commandhold == d_EXIT )
  833.     quit = reallyquit();
  834. else IF( commandhold == d_UNDO )
  835.     doundo();
  836. else IF( commandhold == d_NUKE )
  837.     donuke();
  838. else IF( commandhold == d_SAVECOM )
  839.     savecom();
  840. else IF( commandhold == d_LOADCOM )
  841.     loadcom();
  842. else IF( commandhold == d_SAVEPCX )
  843.     savepcx();
  844. else IF( commandhold == d_LOADPCX )
  845.     loadpcx();
  846. else IF( commandhold == d_SAVEPCXCUT )
  847.     savepcxcut();
  848. else IF( commandhold == d_LOADPCXCUT )
  849.     loadpcxcut();
  850. else IF( commandhold == d_SAVESCR )
  851.     savescr();
  852. else IF( commandhold == d_LOADSCR )
  853.     loadscr();
  854. else IF( commandhold == d_LOADPCXPAL )
  855.     loadpcxpal();
  856. else IF( commandhold == d_CYCLE )
  857.     {IF( byte GETCPU() >= 2 )
  858.         cycleon = TRUE - cycleon;
  859.     ELSE BEEP();}
  860. else IF( commandhold == d_FLOODFILL )
  861.     {IF( byte GETCPU() >= 2 )
  862.         drawtype = d_FLOODFILL;
  863.     ELSE BEEP();}
  864. else IF( commandhold == d_ELLIPSE )
  865.     {IF( byte GETCPU() >= 3 )
  866.         drawtype = d_ELLIPSE;
  867.     ELSE BEEP();}
  868. ELSE IF( commandhold == d_SAVEPAL )
  869.     savepal();
  870. ELSE IF( commandhold == d_LOADPAL )
  871.     loadpal();
  872. ELSE IF( commandhold == d_SAVEIII )
  873.     saveiii();
  874. ELSE IF( commandhold == d_LOADIII )
  875.     loadiii();
  876. ELSE IF( commandhold == d_SAVECUT )
  877.     savecut();
  878. ELSE IF( commandhold == d_LOADCUT )
  879.     loadcut();
  880. ELSE IF( commandhold <> OPTIONS )
  881.     drawtype = commandhold;
  882. }
  883.  
  884.  
  885. void helpscreen ()
  886. {BEEP();      // help?  You must be kidding.
  887. }
  888.  
  889.  
  890. /******************* COMPLEX DRAW TYPES HANDLED ***************************/ 
  891.  
  892. void dodots ( byte filleddots; byte randomcolour )
  893. byte colourhold;
  894. {HIDEMOUSE();
  895. colourhold = colour;
  896. do {getmouse();
  897.     IF( randomcolour == TRUE )
  898.         colour = RAND();
  899.     IF( filleddots == TRUE )
  900.         bar19(x,y,dotxsize,dotysize,colour);
  901.     ELSE box19(x,y,dotxsize,dotysize,colour);
  902.     } while( buttons <> 0 );
  903. colour = colourhold;
  904. remember();
  905. }
  906.  
  907.  
  908. void dofloodfill ()
  909. {HIDEMOUSE();
  910. fill19(x,y,colour);
  911. remember();
  912. waitmouse();
  913. }
  914.  
  915.  
  916. void doundo ()
  917. {go();
  918. undobuf = 1 - undobuf;
  919. comeback();
  920. }
  921.  
  922.  
  923. void donuke ()
  924. {go();
  925. clearscreen();
  926. remember();
  927. }
  928.  
  929.  
  930. void cutiii ()
  931. word holdx,holdy;   /* used for holding mouse status */
  932. word deltax,deltay,startx,starty;
  933. word olddeltax,olddeltay,oldstartx,oldstarty;
  934. word xsize,ycount,planes;
  935. byte dragcolor;
  936. {holdx = x;
  937. holdy = y;
  938. startx = x;
  939. starty = y;
  940. deltax = 4;
  941. deltay = 1;
  942. HIDEMOUSE();
  943. dragcolor = RAND();
  944. xorbox19(startx,starty,deltax,deltay,dragcolor); 
  945. do {
  946.     olddeltax = deltax;
  947.     olddeltay = deltay;
  948.     oldstartx = startx;
  949.     oldstarty = starty;
  950.     getmouse();    
  951.     IF( x > holdx )
  952.         {deltax = x-holdx/4*4+4;
  953.         startx = holdx;}  
  954.     ELSE IF( x < holdx )
  955.         {deltax = holdx-x/4*4+4;
  956.         startx = x;}  
  957.     ELSE{deltax = 4;
  958.         startx = holdx;}
  959.  
  960.     IF( y > holdy )
  961.         {deltay = y-holdy+1;
  962.         starty = holdy;}  
  963.     ELSE IF( y < holdy )
  964.         {deltay = holdy-y+1;
  965.         starty = y;}  
  966.     ELSE{deltay = 1;
  967.         starty = holdy;}
  968.     xorbox19(oldstartx,oldstarty,olddeltax,olddeltay,dragcolor); 
  969.     dragcolor = RAND();
  970.     xorbox19(startx,starty,deltax,deltay,dragcolor); 
  971.    
  972.    } while( buttons != 0 ); 
  973. xorbox19(startx,starty,deltax,deltay,dragcolor); 
  974. iiisize = deltax*deltay +2;
  975.  
  976. $ PUSH DS
  977. ES = iiibufptr;
  978. DS = VGA_SEG;
  979. xsize = deltax /4;
  980. ESBYTE[0] = xsize;
  981. ESBYTE[1] = deltay;
  982. DI = 2;
  983. planes = 0;
  984. do {
  985.     ycount = 0;
  986.     do {
  987.         AX = starty+ycount*320 +startx +planes;
  988.         SI = AX;
  989.         CX = xsize;
  990.         loop(CX)
  991.             {$ MOVSB
  992.             SI += 3;
  993.             }
  994.         ycount++;
  995.         } while( ycount < deltay );
  996.     planes++;
  997.     } while( planes < 4 );
  998. $ POP DS
  999.  
  1000. SHOWMOUSE();
  1001. drawtype = d_PUTIII;
  1002. }
  1003.  
  1004.  
  1005. void putiii ()  /* put iii image at location specified by mouse x and y */
  1006. word xsize,ysize;
  1007. word startx,starty;
  1008. word planes,ycount;
  1009. {
  1010. startx = x;
  1011. starty = y;
  1012. $ PUSH DS
  1013. DS = iiibufptr;
  1014. ES = VGA_SEG;
  1015. xsize = DSBYTE[0];
  1016. ysize = DSBYTE[1];
  1017. SI = 2;
  1018. planes = 0;
  1019. do {
  1020.     ycount = 0;
  1021.     do {
  1022.         AX = starty+ycount*320 +startx +planes;
  1023.         DI = AX;
  1024.         CX = xsize;
  1025.         loop(CX)
  1026.             {$ LODSB
  1027.             IF( AL <> CLEARCOLOR )
  1028.                 $ STOSB
  1029.             ELSE DI++;
  1030.             DI += 3;
  1031.             }
  1032.         ycount++;
  1033.         } while( ycount < ysize );
  1034.     planes++;
  1035.     } while( planes < 4 );
  1036. $ POP DS
  1037. }
  1038.  
  1039.  
  1040. void putcutoriii (byte iiiflag)
  1041. word xsize,ysize,lastx,lasty;
  1042. {
  1043. HIDEMOUSE();
  1044. lastx = x;
  1045. lasty = y;
  1046.  
  1047. IF( iiiflag == FALSE )
  1048.     {IF( cutsize == 0 )
  1049.         {BEEP();
  1050.         SHOWMOUSE();
  1051.         return;}
  1052.     DI = lastx;
  1053.     SI = lasty;
  1054.     $ PUSH DS
  1055.     DS = cutbufptr;
  1056.     xsize = DSWORD[0];
  1057.     ysize = DSWORD[2];
  1058.     putimage19(DI,SI,0);
  1059.     $ POP DS
  1060.     }
  1061. ELSE{IF( iiisize == 0 )
  1062.         {BEEP();
  1063.         SHOWMOUSE();
  1064.         return;}
  1065.     ES = iiibufptr;
  1066.     xsize = ESBYTE[0]*4;
  1067.     ysize = ESBYTE[1];
  1068.     putiii();
  1069.     } 
  1070. do {getmouse();
  1071.     BL = FALSE;
  1072.     IF( x <> lastx )
  1073.         BL = TRUE;
  1074.     IF( y <> lasty )
  1075.         BL = TRUE;
  1076.     IF( BL == TRUE )
  1077.         {$ PUSH DS
  1078.         IF( undobuf == 0 )
  1079.             DS = screenbuf1ptr;
  1080.         ELSE DS = screenbuf2ptr;
  1081.         trans19(lastx,lasty,xsize,ysize);     
  1082.         $ POP DS
  1083.         IF( iiiflag == FALSE )
  1084.             {DI = x;
  1085.             SI = y;
  1086.             BL = colour;
  1087.             $ PUSH DS
  1088.             DS = cutbufptr;
  1089.             overimage19(DI,SI,0,BL);
  1090.             $ POP DS
  1091.             }
  1092.         ELSE putiii();
  1093.         lastx = x;
  1094.         lasty = y;
  1095.         }
  1096.     } while (buttons <> 0);
  1097.  
  1098. remember();
  1099. }
  1100.  
  1101.  
  1102. void drawcutoriii (byte iiiflag)
  1103. {
  1104. HIDEMOUSE();
  1105. do {getmouse();
  1106.     IF( iiiflag == FALSE )
  1107.         {IF( cutsize == 0 )
  1108.             {BEEP();
  1109.             SHOWMOUSE();
  1110.             return;}
  1111.         DI = x;
  1112.         SI = y;
  1113.         BL = colour;
  1114.         $ PUSH DS
  1115.         DS = cutbufptr;
  1116.         overimage19(DI,SI,0,BL);
  1117.         $ POP DS
  1118.         }
  1119.     ELSE{IF( iiisize == 0 )
  1120.             {BEEP();
  1121.             SHOWMOUSE();
  1122.             return;}
  1123.         putiii();
  1124.         } 
  1125.     } while (buttons <> 0);
  1126. remember();
  1127. }
  1128.  
  1129.  
  1130. void dooriginline (byte inc)
  1131. word holdx,holdy,oldx,oldy;
  1132. byte thecolour;
  1133. {holdx = x;
  1134. holdy = y;
  1135. HIDEMOUSE();
  1136. thecolour = colour;
  1137. do {getmouse();
  1138.     IF( inc == TRUE )
  1139.         {IF( oldx <> x )
  1140.             thecolour++;
  1141.         ELSE IF( oldy <> y )
  1142.             thecolour++;
  1143.         }
  1144.     line19(holdx,holdy,x,y,thecolour); 
  1145.     oldx = x;
  1146.     oldy = y;
  1147.     } while ( buttons <> 0 );
  1148. remember();
  1149. }
  1150.  
  1151.  
  1152. void dodrawline ()
  1153. word holdx,holdy;
  1154. {holdx = x;
  1155. holdy = y;
  1156. HIDEMOUSE();
  1157. do {
  1158.     IF( KBHIT() != 0 )
  1159.         {AX = BIOSREADKEY();
  1160.         IF(AX==k_up)
  1161.             SETCOLOR( colour+1 );
  1162.         ELSE IF(AX==k_down)
  1163.             SETCOLOR( colour-1 );
  1164.         }
  1165.     getmouse();
  1166.     line19(holdx,holdy,x,y,colour); 
  1167.     holdx = x;
  1168.     holdy = y;
  1169.     } while ( buttons <> 0 );
  1170. remember();
  1171. }
  1172.  
  1173.  
  1174. ?define FONTSIZE 8   // BIOS font is an 8x8 pixel font
  1175.  
  1176. void dotext ()
  1177. word textx,texty,startx,hold;
  1178. byte done;
  1179. byte undercursor[FONTSIZE*FONTSIZE+4];
  1180. {
  1181. textx = x/FONTSIZE;
  1182. texty = y/FONTSIZE;
  1183. startx = textx;
  1184. HIDEMOUSE();
  1185. done = FALSE;
  1186. do {
  1187.     getimage19(textx*FONTSIZE,texty*FONTSIZE,FONTSIZE,FONTSIZE,SS,#undercursor);
  1188.     do {
  1189.         box19(textx*FONTSIZE,texty*FONTSIZE,FONTSIZE,FONTSIZE,RAND());
  1190.         } while ( KBHIT() == 0 );
  1191.     putimage19(textx*FONTSIZE,texty*FONTSIZE,#undercursor);
  1192.  
  1193.     AX = BIOSREADKEY();
  1194.     IF( AX == k_backspace )
  1195.         {IF( textx >= 1 )
  1196.             textx--;
  1197.         ELSE{textx = 39;
  1198.             texty--;}
  1199.         $ PUSH DS
  1200.         IF( undobuf == 0 )
  1201.             DS = screenbuf1ptr;
  1202.         ELSE DS = screenbuf2ptr;
  1203.         trans19(textx*FONTSIZE,texty*FONTSIZE,FONTSIZE,FONTSIZE);
  1204.         $ POP DS}
  1205.     else IF( AX == k_delete )
  1206.         {$ PUSH DS
  1207.         IF( undobuf == 0 )
  1208.             DS = screenbuf1ptr;
  1209.         ELSE DS = screenbuf2ptr;
  1210.         trans19(textx*FONTSIZE,texty*FONTSIZE,FONTSIZE,FONTSIZE);
  1211.         $ POP DS}
  1212.     ELSE IF( AX == k_esc )
  1213.         done = TRUE;
  1214.     ELSE IF( AX == k_return )
  1215.         {textx = startx;
  1216.         texty++;}
  1217.     ELSE IF( AX == k_up )
  1218.         texty--;
  1219.     ELSE IF( AX == k_down )
  1220.         texty++; 
  1221.     ELSE IF( AX == k_left )
  1222.         {IF( textx >= 1 )
  1223.             textx--;
  1224.         ELSE{textx = 39;
  1225.             texty--;}
  1226.         }
  1227.     ELSE IF( AX == k_right )
  1228.         textx++; 
  1229.     ELSE{hold = AX;
  1230.         GOTOXY(textx,texty);
  1231.         GWRITE(hold,colour);
  1232.         textx++;
  1233.         } 
  1234.  
  1235.     IF( texty >= 25 )
  1236.         texty = 0;
  1237.     IF( textx >= 40 )
  1238.         textx = 0;
  1239.     
  1240.     } while( done == FALSE ); 
  1241. remember();
  1242. }
  1243.  
  1244.  
  1245. ?define SMALLFONTWIDTH  6
  1246. ?define SMALLFONTHEIGHT 5
  1247.  
  1248. void dosmalltext ()
  1249. word textx,texty,startx,hold;
  1250. byte done;
  1251. byte undercursor[SMALLFONTWIDTH*SMALLFONTHEIGHT+4];
  1252. {
  1253. textx = x;
  1254. texty = y;
  1255. startx = textx;
  1256. HIDEMOUSE();
  1257. done = FALSE;
  1258. do {
  1259.     getimage19(textx,texty,SMALLFONTWIDTH,SMALLFONTHEIGHT,SS,#undercursor);
  1260.     do {
  1261.         box19(textx,texty,SMALLFONTWIDTH,SMALLFONTHEIGHT,RAND());
  1262.         } while ( KBHIT() == 0 );
  1263.     putimage19(textx,texty,#undercursor);
  1264.  
  1265.     AX = BIOSREADKEY();
  1266.     IF( AX == k_backspace )
  1267.         {IF( textx >= SMALLFONTWIDTH )
  1268.             textx -= SMALLFONTWIDTH;
  1269.         ELSE{textx =  320-SMALLFONTWIDTH;
  1270.             texty -= SMALLFONTHEIGHT;}
  1271.         $ PUSH DS
  1272.         IF( undobuf == 0 )
  1273.             DS = screenbuf1ptr;
  1274.         ELSE DS = screenbuf2ptr;
  1275.         trans19(textx,texty,SMALLFONTWIDTH,SMALLFONTHEIGHT);
  1276.         $ POP DS}
  1277.     else IF( AX == k_delete )
  1278.         {$ PUSH DS
  1279.         IF( undobuf == 0 )
  1280.             DS = screenbuf1ptr;
  1281.         ELSE DS = screenbuf2ptr;
  1282.         trans19(textx,texty,SMALLFONTWIDTH,SMALLFONTHEIGHT);
  1283.         $ POP DS}
  1284.     else IF( AX == k_esc )
  1285.         done = TRUE;
  1286.     ELSE IF( AX == k_return )
  1287.         {textx = startx;
  1288.         texty += SMALLFONTHEIGHT;}
  1289.     ELSE IF( AX == k_up )
  1290.         texty -= SMALLFONTHEIGHT;
  1291.     ELSE IF( AX == k_down )
  1292.         texty += SMALLFONTHEIGHT; 
  1293.     ELSE IF( AX == k_left )
  1294.         {IF( textx >= SMALLFONTWIDTH )
  1295.             textx -= SMALLFONTWIDTH;
  1296.         ELSE{textx =  320-SMALLFONTWIDTH;
  1297.             texty -= SMALLFONTHEIGHT;}
  1298.         }
  1299.     ELSE IF( AX == k_right )
  1300.         textx += SMALLFONTWIDTH; 
  1301.     ELSE{hold = AX;
  1302.         over5x5letter19(textx,texty,hold,colour);
  1303.         textx += SMALLFONTWIDTH;
  1304.         } 
  1305.  
  1306.     IF( textx >= 320 )
  1307.         {textx = 0;
  1308.         texty += SMALLFONTHEIGHT;};
  1309.     IF( texty >= 200 )
  1310.         texty = 0;
  1311.     
  1312.     } while( done == FALSE ); 
  1313. remember();
  1314. }
  1315.  
  1316. /************************* FILE ROUTINES START ***************************/
  1317.  
  1318. byte saving = "SAVING ...";
  1319. byte entersaveesc = "<ENTER> to Save, <ESC> to Abort.";
  1320. byte savemes1 = "Enter ";
  1321. byte savemes2 = " File Name To Save:";
  1322.  
  1323. byte savescrmes = "Screen";
  1324.  
  1325. void savescr ()
  1326. {go();
  1327. putwindow(16,32,36*8,24);
  1328. GOTOXY(2,4);
  1329. WRITESTR(#savemes1);
  1330. WRITESTR(#savescrmes);
  1331. WRITESTR(#savemes2);
  1332. GOTOXY(2,6);
  1333. WRITESTR(#entersaveesc);
  1334. IF( byte readstr(2,5,#scrfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1335.     {comeback();
  1336.     return;}
  1337. putwindow(15*8,10*8,80,8);
  1338. GOTOXY(15,10);
  1339. WRITESTR(#saving);
  1340.  
  1341. IF( undobuf == 0 )
  1342.     {IF( writefile(#scrfilename,screenbuf1ptr,0,SCREENSIZE)<>SCREENSIZE )
  1343.         BEEP();
  1344.     }
  1345. ELSE{IF( writefile(#scrfilename,screenbuf2ptr,0,SCREENSIZE)<>SCREENSIZE )
  1346.         BEEP();
  1347.     }
  1348. comeback();
  1349. }
  1350.  
  1351.  
  1352. byte loading = "LOADING ...";
  1353.  
  1354. void loadscr ()
  1355. {go();
  1356. IF( byte getfilename("*.SCR",64000,#scrfilename) )
  1357.     {putwindow(14*8,10*8,88,8);
  1358.     GOTOXY(14,10);
  1359.     WRITESTR(#loading);
  1360.     readscrfile();
  1361.     }
  1362. comeback();
  1363. waitmouse();
  1364. }
  1365.  
  1366.  
  1367. byte savepalmes = "Palette";
  1368.  
  1369. void savepal ()
  1370. {go();
  1371. putwindow(16,32,36*8,24);
  1372. GOTOXY(2,4);
  1373. WRITESTR(#savemes1);
  1374. WRITESTR(#savepalmes);
  1375. WRITESTR(#savemes2);
  1376. GOTOXY(2,6);
  1377. WRITESTR(#entersaveesc);
  1378. IF( byte readstr(2,5,#palfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1379.     {comeback();
  1380.     return;}
  1381. putwindow(15*8,10*8,80,8);
  1382. GOTOXY(15,10);
  1383. WRITESTR(#saving);
  1384. cycleit = FALSE;
  1385. COPYFARW(DS,#palettehold,DS,#palette,PALSIZE/2);
  1386. cycleit = TRUE;
  1387. IF( writefile(#palfilename,DS,#palettehold,PALSIZE) <> PALSIZE)
  1388.     BEEP();   
  1389. comeback();
  1390. }
  1391.  
  1392.  
  1393. void loadpal ()
  1394. {go();
  1395. IF( byte getfilename("*.PAL",PALSIZE,#palfilename) )
  1396.     {putwindow(14*8,10*8,88,8);
  1397.     GOTOXY(14,10);
  1398.     WRITESTR(#loading);
  1399.     readpalfile();
  1400.     }
  1401. comeback();
  1402. waitmouse();
  1403. }
  1404.  
  1405.  
  1406. void loadpcxpal ()
  1407. {go();
  1408. IF( byte getfilename("*.PCX",0,#pcxfilename) )
  1409.     {putwindow(14*8,10*8,88,8);
  1410.     GOTOXY(14,10);
  1411.     WRITESTR(#loading);
  1412.     readpcxpalfile();
  1413.     }
  1414. comeback();
  1415. waitmouse();
  1416. }
  1417.  
  1418.  
  1419. void saveiii ()
  1420. {IF( iiisize == 0 )
  1421.     {BEEP();
  1422.     return;};
  1423. go();
  1424. putwindow(16,32,36*8,24);
  1425. GOTOXY(2,4);
  1426. WRITESTR(#savemes1);
  1427. WRITESTR("Icon");
  1428. WRITESTR(#savemes2);
  1429. GOTOXY(2,6);
  1430. WRITESTR(#entersaveesc);
  1431. IF( byte readstr(2,5,#iiifilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1432.     {comeback();
  1433.     return;}
  1434. putwindow(15*8,10*8,80,8);
  1435. GOTOXY(15,10);
  1436. WRITESTR(#saving);
  1437. IF( writefile(#iiifilename,iiibufptr,0,iiisize) <> iiisize )
  1438.     BEEP();
  1439. comeback();
  1440. }
  1441.  
  1442.  
  1443. void loadiii ()
  1444. {go();
  1445. IF( byte getfilename("*.III",3,#iiifilename) )
  1446.     {putwindow(14*8,10*8,88,8);
  1447.     GOTOXY(14,10);
  1448.     WRITESTR(#loading);
  1449.     readiiifile();
  1450.     }
  1451. comeback();
  1452. waitmouse();
  1453. }
  1454.  
  1455.  
  1456. void savecut ()
  1457. {IF( cutsize == 0 )
  1458.     {BEEP();
  1459.     return;};
  1460. go();
  1461. putwindow(16,32,36*8,24);
  1462. GOTOXY(2,4);
  1463. WRITESTR(#savemes1);
  1464. WRITESTR("Cut");
  1465. WRITESTR(#savemes2);
  1466. GOTOXY(2,6);
  1467. WRITESTR(#entersaveesc);
  1468. IF( byte readstr(2,5,#cutfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1469.     {comeback();
  1470.     return;}
  1471. putwindow(15*8,10*8,80,8);
  1472. GOTOXY(15,10);
  1473. WRITESTR(#saving);
  1474. IF( writefile(#cutfilename,cutbufptr,0,cutsize) <> cutsize )
  1475.     BEEP();
  1476. comeback();
  1477. }
  1478.  
  1479.  
  1480. void loadcut ()
  1481. {go();
  1482. IF( byte getfilename("*.CUT",5,#cutfilename) )
  1483.     {putwindow(14*8,10*8,88,8);
  1484.     GOTOXY(14,10);
  1485.     WRITESTR(#loading);
  1486.     readcutfile();
  1487.     }
  1488. comeback();
  1489. waitmouse();
  1490. }
  1491.  
  1492.  
  1493. void savepcxcut ()
  1494. {IF( cutsize == 0 )
  1495.     {BEEP();
  1496.     return;};
  1497. go();
  1498. putwindow(16,32,36*8,24);
  1499. GOTOXY(2,4);
  1500. WRITESTR(#savemes1);
  1501. WRITESTR("PCX Cut");
  1502. WRITESTR(#savemes2);
  1503. GOTOXY(2,6);
  1504. WRITESTR(#entersaveesc);
  1505. IF( byte readstr(2,5,#pcxfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1506.     {comeback();
  1507.     return;}
  1508. putwindow(15*8,10*8,80,8);
  1509. GOTOXY(15,10);
  1510. WRITESTR(#saving);
  1511.  
  1512. cycleit = FALSE;
  1513. COPYFARW(DS,#palettehold,DS,#palette,PALSIZE/2);
  1514. cycleit = TRUE;
  1515.  
  1516. ES = cutbufptr;
  1517. IF( savePCX(#pcxfilename,cutbufptr,4,ESWORD[0],ESWORD[2],DS,#palettehold) != pcx_e_ok )
  1518.     BEEP();
  1519.  
  1520. comeback();
  1521. }
  1522.  
  1523.  
  1524. void loadpcxcut ()
  1525. {go();
  1526. IF( byte getfilename("*.PCX",0,#pcxfilename) )
  1527.     {putwindow(14*8,10*8,88,8);
  1528.     GOTOXY(14,10);
  1529.     WRITESTR(#loading);
  1530.     readpcxcutfile();
  1531.     }
  1532. comeback();
  1533. waitmouse();
  1534. }
  1535.  
  1536.  
  1537. byte script = FROM "TINYDRAW.BIN";
  1538. ?define SCRIPTSIZE 75+1
  1539.  
  1540. void savecom () 
  1541. word filehandle;
  1542. {go();
  1543. putwindow(16,32,36*8,24);
  1544. GOTOXY(2,4);
  1545. WRITESTR(#savemes1);
  1546. WRITESTR("Picture");
  1547. WRITESTR(#savemes2);
  1548. GOTOXY(2,6);
  1549. WRITESTR(#entersaveesc);
  1550. IF( byte readstr(2,5,#comfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1551.     {comeback();
  1552.     return;}
  1553. putwindow(15*8,10*8,80,8);
  1554. GOTOXY(15,10);
  1555. WRITESTR(#saving);
  1556. cycleit = FALSE;
  1557. COPYFARW(DS,#palettehold,DS,#palette,PALSIZE/2);
  1558. cycleit = TRUE;
  1559. filehandle = FCREATE( , ,0,#comfilename);   /* create file to write */
  1560. IF(filehandle != 0)                    /* if file openned OK */
  1561.     {FWRITE( ,filehandle,SCRIPTSIZE,#script);
  1562.     FWRITE( ,filehandle,PALSIZE,#palettehold);
  1563.     $ PUSH DS
  1564.     IF( undobuf == 0 )
  1565.         DS = screenbuf1ptr;
  1566.     ELSE DS = screenbuf2ptr;
  1567.     FWRITE( ,filehandle,SCREENSIZE,0);
  1568.     $ POP DS
  1569.     FCLOSE( ,filehandle);  /* close the file */
  1570.     }
  1571. ELSE BEEP();
  1572. comeback();
  1573. }
  1574.  
  1575.  
  1576. void loadcom ()
  1577. {go();
  1578. if( byte getfilename("*.COM",SCRIPTSIZE+PALSIZE+SCREENSIZE,#comfilename) )
  1579.     {putwindow(14*8,10*8,88,8);
  1580.     GOTOXY(14,10);
  1581.     WRITESTR(#loading);
  1582.     readcomfile();
  1583.     }
  1584. comeback();
  1585. waitmouse();
  1586. }
  1587.  
  1588.  
  1589. void savepcx () 
  1590. word filehandle;
  1591. {go();
  1592. putwindow(16,32,36*8,24);
  1593. GOTOXY(2,4);
  1594. WRITESTR(#savemes1);
  1595. WRITESTR("PCX Picture");
  1596. WRITESTR(#savemes2);
  1597. GOTOXY(2,6);
  1598. WRITESTR(#entersaveesc);
  1599. IF( byte readstr(2,5,#pcxfilename,FILENAMELEN-1,TRUE,15) == FALSE )
  1600.     {comeback();
  1601.     return;}
  1602. putwindow(15*8,10*8,80,8);
  1603. GOTOXY(15,10);
  1604. WRITESTR(#saving);
  1605. cycleit = FALSE;
  1606. COPYFARW(DS,#palettehold,DS,#palette,PALSIZE/2);
  1607. cycleit = TRUE;
  1608.  
  1609. IF( undobuf == 0 )
  1610.     {IF( savePCX(#pcxfilename,screenbuf1ptr,0,320,200,DS,#palettehold) != pcx_e_ok )
  1611.         BEEP();
  1612.     }
  1613. ELSE{IF( savePCX(#pcxfilename,screenbuf2ptr,0,320,200,DS,#palettehold) != pcx_e_ok )
  1614.         BEEP();
  1615.     }
  1616.  
  1617. comeback();
  1618. }
  1619.  
  1620.  
  1621. void loadpcx ()
  1622. {go();
  1623. if( byte getfilename("*.PCX",0,#pcxfilename) )
  1624.     {putwindow(14*8,10*8,88,8);
  1625.     GOTOXY(14,10);
  1626.     WRITESTR(#loading);
  1627.     readpcxfile();
  1628.     }
  1629. comeback();
  1630. waitmouse();
  1631. }
  1632.  
  1633.  
  1634. /********************* STRING reading ROUTINES START ***********************/
  1635.  
  1636. byte readstr(byte xpos,ypos; word straddress,maxlength; byte upcase,attr )
  1637. word pos,i,key;
  1638. byte done;
  1639. {pos = 0;
  1640. done = 0;
  1641. DH = ypos;
  1642. DL = xpos;
  1643. @ SETTEXTPOSITION( ,0, ,DX);
  1644. pos = 0;
  1645. DI = straddress;
  1646. IF( DSBYTE[DI] != 0 )
  1647.     {do {GWRITE(DSBYTE[DI],attr);
  1648.         DI++;
  1649.         pos++;
  1650.         } while( DSBYTE[DI] != 0 );
  1651.     }
  1652. GWRITE('_',15);
  1653. do {
  1654.     key = BIOSREADKEY();
  1655.     IF( key == k_return )
  1656.         done = TRUE +1;
  1657.     else IF( key == k_esc )
  1658.         done = FALSE +1;
  1659.     else IF( key == k_backspace )
  1660.         {IF( pos > 0 )
  1661.             {GWRITE(8,attr);
  1662.             GWRITE(' ',attr);
  1663.             GWRITE(8,attr);
  1664.             GWRITE(8,attr);
  1665.             GWRITE('_',15);
  1666.             pos--;
  1667.             }
  1668.         }
  1669.     else IF( key == k_left )
  1670.         {IF( pos > 0 )
  1671.             {GWRITE(8,attr);
  1672.             GWRITE(' ',attr);
  1673.             GWRITE(8,attr);
  1674.             GWRITE(8,attr);
  1675.             GWRITE('_',15);
  1676.             pos--;
  1677.             }
  1678.         }
  1679.     ELSE{
  1680.         DL = key;
  1681.         IF( DL <> 0 )
  1682.             {IF( upcase == 1 )
  1683.                 {IF( DL >= 'a' )
  1684.                     IF( DL <= 'z' )
  1685.                         key -= 'a' - 'A';
  1686.                 }
  1687.             IF( pos < maxlength )
  1688.                 {GWRITE(8,attr);
  1689.                 GWRITE(key,attr);
  1690.                 GWRITE('_',15);
  1691.                 BX = straddress+pos;
  1692.                 DSBYTE[BX] = key;
  1693.                 pos++;}
  1694.             } 
  1695.         }
  1696.     } while( done == 0 );
  1697. BX = straddress+pos;
  1698. DSBYTE[BX] = 0;
  1699. GWRITE(8,attr);
  1700. GWRITE(' ',attr);
  1701. return(done-1);
  1702. }
  1703.  
  1704.  
  1705. void putwindow(word xloc; word yloc; word xsize; word ysize)
  1706. word i;
  1707. {bar19(xloc,yloc,xsize,ysize,0);
  1708. i = 1;
  1709. do {box19(xloc-i,yloc-i,xsize+i+i,ysize+i+i,i);
  1710.     i++;
  1711.     } while( i <= 4 );
  1712. }
  1713.  
  1714.  
  1715. void clearscreen ()
  1716. {@ FILLSCREEN19(byte CLEARCOLOR);
  1717. }
  1718.  
  1719.  
  1720. /******** filename selection and display starts *****************/
  1721.  
  1722. ?define MAXFILES 1000  /* error check for max value still to be done!!! */
  1723. ?define FILEWIDTH 12+1
  1724. byte filelist[FILEWIDTH*MAXFILES];
  1725. word filecount;
  1726. byte fileloadinstruct1 = " Select File Name With LEFT Button  ";
  1727. byte fileloadinstruct2 = "OR Press RIGHT Mouse Button To Abort";
  1728. byte downtext = "DOWN";
  1729. byte uptext = " UP ";
  1730. byte nofiles = "* NO MATCHING FILES *";
  1731. ?define FILEBOXSTARTY  4
  1732. ?define FILEBOXSTARTX  10
  1733. ?define UPBOXSTARTX   25
  1734. ?define UPBOXSTARTY   5
  1735. ?define DOWNBOXSTARTX   25
  1736. ?define DOWNBOXSTARTY   7
  1737.  
  1738. byte getfilename (word searchtype,minfilesize,destfilebuf)
  1739. word start,len,selected;
  1740. byte done,scrollflag;
  1741. {putwindow(2*8,1*8,36*8,2*8);
  1742. GOTOXY(2,1);
  1743. WRITESTR(#fileloadinstruct1);
  1744. GOTOXY(2,2);
  1745. WRITESTR(#fileloadinstruct2);
  1746. fillfilelist(searchtype,minfilesize);
  1747. IF( filecount == 0 )
  1748.     {putwindow(8*8,5*8,21*8,1*8);
  1749.     GOTOXY(8,5);
  1750.     WRITESTR(#nofiles);
  1751.     do {getmouse();
  1752.         } while(buttons == 0);
  1753.     return(FALSE);}
  1754. len = 20;
  1755. scrollflag = TRUE;
  1756. IF( filecount <= 20 )
  1757.     {len = filecount;
  1758.     scrollflag = FALSE;}
  1759. start=0;
  1760. putwindow(FILEBOXSTARTX*8,FILEBOXSTARTY*8,FILEWIDTH-1*8,len*8);
  1761. displaypartoflist(start,start+len);
  1762. IF(scrollflag == TRUE)
  1763.     {putwindow(UPBOXSTARTX*8,UPBOXSTARTY*8,4*8,8);
  1764.     GOTOXY(UPBOXSTARTX,UPBOXSTARTY);
  1765.     WRITESTR(#uptext);
  1766.     putwindow(DOWNBOXSTARTX*8,DOWNBOXSTARTY*8,4*8,8);
  1767.     GOTOXY(DOWNBOXSTARTX,DOWNBOXSTARTY);
  1768.     WRITESTR(#downtext);
  1769.     }
  1770. done = FALSE;
  1771. waitmouse();
  1772. SHOWMOUSE();
  1773. do {getmouse();
  1774.     IF(buttons == 2)
  1775.         done = 1;
  1776.     else if(buttons == 1)
  1777.         {x = x/8;
  1778.         y = y/8;
  1779.         if(x>=FILEBOXSTARTX)
  1780.             {x-=FILEBOXSTARTX;
  1781.             IF(x<FILEWIDTH-1)
  1782.                 {IF(y>=FILEBOXSTARTY)
  1783.                     {y-=FILEBOXSTARTY;
  1784.                     IF(y<len)
  1785.                         {copynear(destfilebuf,y+start*FILEWIDTH+#filelist,FILEWIDTH);
  1786.                         done = 2;}
  1787.                     }
  1788.                 }
  1789.             ELSE{IF(scrollflag == TRUE)
  1790.                     IF(x >= UPBOXSTARTX-FILEBOXSTARTX)
  1791.                         IF(x < UPBOXSTARTX+4-FILEBOXSTARTX)
  1792.                             {IF(y == UPBOXSTARTY)
  1793.                 {IF(start>0)
  1794.                     {start--;
  1795.                                     redisplaylist(start,len);}
  1796.                  }
  1797.                             ELSE IF(y == DOWNBOXSTARTY)
  1798.                                 {IF(len+start<filecount)
  1799.                     {start++;
  1800.                     redisplaylist(start,len);}
  1801.                 }
  1802.                             }
  1803.                 }
  1804.             } 
  1805.         }
  1806.     IF(KBHIT()!=0)
  1807.         {AX = BIOSREADKEY();
  1808.         IF(AX == k_esc)
  1809.             done = 1;
  1810.         }
  1811.     } while( done == FALSE );
  1812. HIDEMOUSE();
  1813. IF( done == 1 )
  1814.     return(FALSE);
  1815. return(TRUE);    
  1816. }
  1817.  
  1818.  
  1819. void redisplaylist (word start,len)
  1820. {HIDEMOUSE();
  1821. bar19(FILEBOXSTARTX*8,FILEBOXSTARTY*8,FILEWIDTH-1*8,len*8,0);
  1822. displaypartoflist(start,start+len);
  1823. SHOWMOUSE();
  1824. }
  1825.  
  1826.  
  1827. void displaypartoflist (word start,end)
  1828. word count;
  1829. {IF( end > filecount )
  1830.     end = filecount;
  1831. count = 0;
  1832. IF( start < end )
  1833.     do {GOTOXY(FILEBOXSTARTX,FILEBOXSTARTY+count);
  1834.         WRITESTR(start*FILEWIDTH+#filelist);
  1835.         start++;
  1836.         count++;
  1837.         } while(start < end);
  1838. }
  1839.  
  1840.  
  1841. void fillfilelist (word searchtype,minfilesize)
  1842. /* fills filelist buffer with all matching filenames */
  1843. {filecount = 0;
  1844. IF( FINDFIRSTFILE( , ,0,searchtype) == 0 )
  1845.     {do {IF(DSWORD[DTA_ADDRESS+0x1A] >= minfilesize)
  1846.             {copynear(filecount*FILEWIDTH+#filelist,DTA_ADDRESS+0x1E,FILEWIDTH);
  1847.             filecount++;}
  1848.         } while( FINDNEXTFILE() == 0);
  1849.     }
  1850. }
  1851.  
  1852.  
  1853. /********************* FILE LOADING PROCEDURES START **********************/
  1854.  
  1855.  
  1856. void readcomfile ()
  1857. /*
  1858. Loads the COM file specified by the string 'comfilename'.
  1859. */
  1860. word filehandle;
  1861. {
  1862. filehandle = FOPEN(0, , ,#comfilename);   /* open file to read */
  1863. if(filehandle != 0)                       /* if file openned OK */
  1864.     {FREAD( ,filehandle,SCRIPTSIZE,#palettehold);
  1865.     IF( FREAD( ,filehandle,PALSIZE,#palettehold) != PALSIZE)
  1866.         BEEP();
  1867.     ELSE{undobuf = 1 - undobuf;
  1868.         $ PUSH DS
  1869.         IF( undobuf == 0 )
  1870.             DS = screenbuf1ptr;
  1871.         ELSE DS = screenbuf2ptr;
  1872.         IF( FREAD( ,filehandle,SCREENSIZE,0) != SCREENSIZE )
  1873.             {$ POP DS
  1874.             BEEP();
  1875.             undobuf = 1 - undobuf;}
  1876.         ELSE{$ POP DS
  1877.             cycleit = FALSE;
  1878.             COPYFARW(DS,#palette,DS,#palettehold,PALSIZE/2);
  1879.             WAITVSYNC();
  1880.             SETVGAPALETTE( ,0,256,#palette);  
  1881.             cycleon = FALSE; 
  1882.             cycleit = TRUE;
  1883.             }
  1884.         }
  1885.     FCLOSE( ,filehandle);  /* close the file */
  1886.     }
  1887. ELSE BEEP();
  1888. }
  1889.  
  1890.  
  1891. void readpcxfile ()
  1892. /*
  1893. Loads the PCX file specified by the string 'pcxfilename'.
  1894. */
  1895. {
  1896. IF( undobuf == 0 )
  1897.     {IF( byte readPCX(#pcxfilename,screenbuf2ptr,0,64000,pcx_raw) != pcx_e_ok )
  1898.         {BEEP();
  1899.         return;
  1900.         }
  1901.     }
  1902. else{IF( byte readPCX(#pcxfilename,screenbuf1ptr,0,64000,pcx_raw) != pcx_e_ok )
  1903.         {BEEP();
  1904.         return;
  1905.         }
  1906.     }
  1907. IF( byte readPCXpalette(#pcxfilename,DS,#palettehold) != pcx_e_ok )
  1908.     {BEEP();
  1909.     return;
  1910.     }
  1911.  
  1912. undobuf = 1 - undobuf;
  1913. cycleit = FALSE;
  1914. COPYFARW(DS,#palette,DS,#palettehold,PALSIZE/2);
  1915. WAITVSYNC();
  1916. SETVGAPALETTE( ,0,256,#palette);  
  1917. cycleon = FALSE; 
  1918. cycleit = TRUE;
  1919. }
  1920.  
  1921.  
  1922. void readcutfile ()
  1923. /*
  1924. Loads the CUT file specified by the string 'cutfilename'.
  1925. */
  1926. {cutsize = readfile(#cutfilename,cutbufptr,0,64004);
  1927. IF( cutsize < 5 )
  1928.     {BEEP();
  1929.     cutsize = 0;}
  1930. ELSE drawtype = d_PUTCUT;
  1931. }
  1932.  
  1933.  
  1934. void readpcxcutfile ()
  1935. /*
  1936. Loads the PCX file specified by the string 'pcxfilename'.
  1937. */
  1938. {
  1939. IF( byte readPCX(#pcxfilename,cutbufptr,0,64004,pcx_cut) != pcx_e_ok )
  1940.     {BEEP();
  1941.     cutsize = 0;
  1942.     }
  1943. ELSE{ES = cutbufptr;
  1944.     cutsize = ESWORD[0] * ESWORD[2] + 4;
  1945.     drawtype = d_PUTCUT;
  1946.     }
  1947. }
  1948.  
  1949.  
  1950. void readiiifile ()
  1951. /*
  1952. Loads the III file specified by the string 'iiifilename'.
  1953. */
  1954. {iiisize = readfile(#iiifilename,iiibufptr,0,64002);
  1955. IF( iiisize < 3 )
  1956.     {BEEP();
  1957.     iiisize = 0;}
  1958. ELSE drawtype = d_PUTIII;
  1959. }
  1960.  
  1961.  
  1962. void readpalfile ()
  1963. /*
  1964. Loads the PAL file specified by the string 'palfilename'.
  1965. */
  1966. {IF( readfile(#palfilename,DS,#palettehold,PALSIZE) <> PALSIZE)
  1967.     BEEP();
  1968. ELSE{cycleit = FALSE;
  1969.     COPYFARW(DS,#palette,DS,#palettehold,PALSIZE/2);
  1970.     WAITVSYNC();
  1971.     SETVGAPALETTE( ,0,256,#palette);  
  1972.     cycleon = FALSE; 
  1973.     cycleit = TRUE;
  1974.     }
  1975. }
  1976.  
  1977.  
  1978. void readpcxpalfile ()
  1979. /*
  1980. Loads the PAL file specified by the string 'pcxfilename'.
  1981. */
  1982. {
  1983. IF( byte readPCXpalette(#pcxfilename,DS,#palettehold) != pcx_e_ok )
  1984.     BEEP();
  1985. ELSE{cycleit = FALSE;
  1986.     COPYFARW(DS,#palette,DS,#palettehold,PALSIZE/2);
  1987.     WAITVSYNC();
  1988.     SETVGAPALETTE( ,0,256,#palette);  
  1989.     cycleon = FALSE; 
  1990.     cycleit = TRUE;
  1991.     }
  1992. }
  1993.  
  1994.  
  1995. void readscrfile ()
  1996. /*
  1997. Loads the PAL file specified by the string 'palfilename'.
  1998. */
  1999. {undobuf = 1 - undobuf;
  2000. IF( undobuf == 0 )
  2001.     {IF( readfile(#scrfilename,screenbuf1ptr,0,SCREENSIZE) <> SCREENSIZE)
  2002.         {BEEP();
  2003.         undobuf = 1 - undobuf;}
  2004.     }
  2005. ELSE{IF( readfile(#scrfilename,screenbuf2ptr,0,SCREENSIZE) <> SCREENSIZE)
  2006.         {BEEP();
  2007.         undobuf = 1 - undobuf;}
  2008.     }
  2009. }
  2010.  
  2011. /* end of TINYDRAW.C-- */