home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 423.lha / Prism_v1.10 / Prism.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-01  |  56.0 KB  |  2,149 lines

  1. /************************************************************************
  2. *                       Prism - THE Amiga ANSI Animator            *
  3. *                              By: Colin Vernon                         *
  4. *             Prism 1.00 - October 15, 1989            *
  5. *  lc -ma -cu Prism.c                            *
  6. *  blink lib:cback.o Prism.o LIB lib:lcm.lib lib:lc.lib lib:amiga.lib   *
  7. ************************************************************************/
  8. #include "stdio.h"
  9. #include "stdlib.h"
  10. #include "exec/types.h"
  11. #include "exec/memory.h"
  12. #include "intuition/intuition.h"
  13. #include "graphics/sprite.h"
  14. #include "proto/dos.h"
  15. #include "dos.h"
  16. #include "libraries/diskfont.h"
  17.  
  18. #define MAXHEIGHT 24
  19. #define MAXWIDTH 80
  20. #define MINHEIGHT 1
  21. #define MINWIDTH 1
  22. #define MAXCHARSETS 12
  23. #define SPACE 0x20
  24. #define BACKSPACE 0x08
  25. #define LINEFEED 0x0a
  26. #define FORMFEED 0x0c
  27. #define RETURN 0x0d
  28. #define TAB 0x09
  29. #define CURSOR_UP 'A'
  30. #define CURSOR_DOWN 'B'
  31. #define CURSOR_RIGHT 'C'
  32. #define CURSOR_LEFT 'D'
  33. #define ESC 0x1b
  34. #define MAXINPUTLEN 80
  35.  
  36. struct ANSI 
  37.      struct ANSI *next;
  38.      struct ANSI *previous;
  39.      short x;
  40.      short y;
  41.      short fcolour;
  42.      short bcolour;
  43.      UBYTE letter;
  44.      UBYTE attr;
  45. };
  46. /***** End Of Header *****/
  47. static unsigned char Titlebar[] = "Prism 1.10 By Colin Vernon";
  48. struct IntuitionBase *IntuitionBase;
  49. struct GfxBase *GfxBase;
  50. ULONG *DiskfontBase;
  51. struct Screen *WorkScreen;
  52. struct Window *WorkWindow;
  53. struct Window *Gads;
  54. struct Window *ReqWindow;
  55. struct IntuiMessage *message;
  56. struct IOStdReq ioStdReq;
  57. struct Device *ConsoleDevice = NULL;
  58. struct SimpleSprite Cursor;
  59.  
  60. void OpenLibs(), CloseLibs();
  61. ULONG OpenDevice();
  62. SHORT RawKeyConvert();
  63. /************************** Sprite Defs *********************************/
  64. UWORD Cursor_Data[] = 
  65. {
  66.     0,0,
  67.     0xf000, 0xf000,
  68.     0x0000, 0x0000,
  69.     0x0000, 0x0000,
  70.     0x0000, 0x0000,
  71.     0x0000, 0x0000,
  72.     0x0000, 0x0000,
  73.     0x0000, 0x0000,
  74.     0xf000, 0xf000,
  75.     0,0
  76. };
  77. UWORD Blank_Data[] =
  78. {
  79.     0,0,
  80.     0x0000, 0x0000,    0x0000, 0x0000,    0x0000, 0x0000,    0x0000, 0x0000,
  81.     0x0000, 0x0000,    0x0000, 0x0000,    0x0000, 0x0000,    0x0000, 0x0000,
  82.     0,0
  83. };
  84. WORD Spr1;
  85. UWORD *ChipCursor, *ChipBlank, *Helping;
  86. /*************************** Gadget Definitions **************************/
  87. struct IntuiText Colour15 ={0,15,JAM2,0,0,NULL," 15 ",NULL,};
  88. struct IntuiText Colour14 ={0,14,JAM2,0,0,NULL," 14 ",NULL,};
  89. struct IntuiText Colour13 ={0,13,JAM2,0,0,NULL," 13 ",NULL,};
  90. struct IntuiText Colour12 ={0,12,JAM2,0,0,NULL," 12 ",NULL,};
  91. struct IntuiText Colour11 ={0,11,JAM2,0,0,NULL," 11 ",NULL,};
  92. struct IntuiText Colour10 ={0,10,JAM2,0,0,NULL," 10 ",NULL,};
  93. struct IntuiText Colour9 ={0,9,JAM2,0,0,NULL,"  9 ",NULL,};
  94. struct IntuiText Colour8 ={0,8,JAM2,0,0,NULL,"  8 ",NULL,};
  95. struct IntuiText Colour7 ={0,7,JAM2,0,0,NULL,"  7 ",NULL,};
  96. struct IntuiText Colour6 ={0,6,JAM2,0,0,NULL,"  6 ",NULL,};
  97. struct IntuiText Colour5 ={0,5,JAM2,0,0,NULL,"  5 ",NULL,};
  98. struct IntuiText Colour4 ={0,4,JAM2,0,0,NULL,"  4 ",NULL,};
  99. struct IntuiText Colour3 ={0,3,JAM2,0,0,NULL,"  3 ",NULL,};
  100. struct IntuiText Colour2 ={0,2,JAM2,0,0,NULL,"  2 ",NULL,};
  101. struct IntuiText Colour1 ={0,1,JAM2,0,0,NULL,"  1 ",NULL,};
  102. struct IntuiText Colour0 ={1,0,JAM2,0,0,NULL,"  0 ",NULL,};
  103.  
  104. struct IntuiText ForeBackText =
  105. {
  106.     15,0,JAM2,2,6,NULL,(UBYTE *)"Fore/Back",NULL
  107. };
  108. struct Gadget ForeBackGadget =
  109. {
  110.     NULL,560,10,76,19,
  111.     GADGHCOMP | SELECTED,RELVERIFY,BOOLGADGET,
  112.     NULL,NULL,&ForeBackText,0,NULL,17,NULL
  113. };
  114. struct Gadget SelColour15 =
  115. {
  116.     &ForeBackGadget,512,11,32,8,
  117.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  118.     NULL,NULL,&Colour15,0,NULL,16,NULL
  119. };
  120.  
  121. struct Gadget SelColour14 =
  122. {
  123.     &SelColour15,478,11,32,8,
  124.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  125.     NULL,NULL,&Colour14,0,NULL,15,NULL
  126. };
  127.  
  128. struct Gadget SelColour13 =
  129. {
  130.     &SelColour14,444,11,32,8,
  131.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  132.     NULL,NULL,&Colour13,0,NULL,14,NULL
  133. };
  134.  
  135. struct Gadget SelColour12 =
  136. {
  137.     &SelColour13,410,11,32,8,
  138.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  139.     NULL,NULL,&Colour12,0,NULL,13,NULL
  140. };
  141.  
  142. struct Gadget SelColour11 =
  143. {
  144.     &SelColour12,376,11,32,8,
  145.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  146.     NULL,NULL,&Colour11,0,NULL,12,NULL
  147. };
  148.  
  149. struct Gadget SelColour10 =
  150. {
  151.     &SelColour11,342,11,32,8,
  152.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  153.     NULL,NULL,&Colour10,0,NULL,11,NULL
  154. };
  155.  
  156. struct Gadget SelColour9 =
  157. {
  158.     &SelColour10,308,11,32,8,
  159.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  160.     NULL,NULL,&Colour9,0,NULL,10,NULL
  161. };
  162.  
  163. struct Gadget SelColour8 =
  164. {
  165.     &SelColour9,274,11,32,8,
  166.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  167.     NULL,NULL,&Colour8,0,NULL,9,NULL
  168. };
  169.  
  170. struct Gadget SelColour7 =
  171. {
  172.     &SelColour8,240,11,32,8,
  173.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  174.     NULL,NULL,&Colour7,0,NULL,8,NULL
  175. };
  176.  
  177. struct Gadget SelColour6 =
  178. {
  179.     &SelColour7,206,11,32,8,
  180.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  181.     NULL,NULL,&Colour6,0,NULL,7,NULL
  182. };
  183.  
  184. struct Gadget SelColour5 =
  185. {
  186.     &SelColour6,172,11,32,8,
  187.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  188.     NULL,NULL,&Colour5,0,NULL,6,NULL
  189. };
  190.  
  191. struct Gadget SelColour4 =
  192. {
  193.     &SelColour5,138,11,32,8,
  194.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  195.     NULL,NULL,&Colour4,0,NULL,5,NULL
  196. };
  197.  
  198. struct Gadget SelColour3 =
  199. {
  200.     &SelColour4,104,11,32,8,
  201.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  202.     NULL,NULL,&Colour3,0,NULL,4,NULL
  203. };
  204.  
  205. struct Gadget SelColour2 =
  206. {
  207.     &SelColour3,70,11,32,8,
  208.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  209.     NULL,NULL,&Colour2,0,NULL,3,NULL
  210. };
  211.  
  212. struct Gadget SelColour1 =
  213. {
  214.     &SelColour2,36,11,32,8, 
  215.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE,BOOLGADGET,
  216.     NULL,NULL,&Colour1,0,NULL,2,NULL
  217. };
  218.  
  219. struct Gadget SelColour0 =
  220. {
  221.     &SelColour1,    /* NextGadget */
  222.     2,11,32,8,  /* LeftEdge, TopEdge, Width, Height*/
  223.     GADGHCOMP,  /* Flags */
  224.     RELVERIFY | GADGIMMEDIATE,   /* Activation */
  225.     BOOLGADGET,     /* Gadget Type */
  226.     NULL, /* Gadget Render */
  227.     NULL,       /* Select Render */
  228.     &Colour0,       /* GadgetText */
  229.     0,          /* MutualExclude */
  230.     NULL,       /* SpecialInfo */
  231.     1,          /* GadgetID */
  232.     NULL        /* UserData */
  233. };
  234. /************************** Requester Definitions ************************/
  235. /***** The About Requester *****/
  236. struct IntuiText AboutProg7Text =
  237. {
  238.     4,7,JAM2,30,59,NULL,"version.",NULL
  239. };
  240. struct IntuiText AboutProg6Text =
  241. {
  242.     4,7,JAM2,30,50,NULL,
  243.     "so no registration fee is required for a fully working",
  244.     &AboutProg7Text
  245. };
  246. struct IntuiText AboutProg5Text =
  247. {
  248.     4,7,JAM2,30,41,NULL,
  249.     "are not modified.  This version of Prism is public domain",
  250.     &AboutProg6Text
  251. };
  252. struct IntuiText AboutProg4Text =
  253. {
  254.     4,7,JAM2,30,32,NULL,
  255.     "distributed as long as the original files in the archive",
  256.     &AboutProg5Text
  257. };
  258. struct IntuiText AboutProg3Text =
  259. {
  260.     4,7,JAM2,30,23,NULL,
  261.     "Prism is an ANSI animator for the Amiga.  It can be",
  262.     &AboutProg4Text
  263. };
  264. struct IntuiText AboutProgText =
  265. {
  266.     1,7,JAM1,205,9,NULL,"Prism by Colin Vernon",&AboutProg3Text
  267. };
  268. /***** The File Requester *****/
  269. unsigned char PathBuffer[512] = "";
  270. unsigned char FileBuffer[33] = "Unnamed.ans";
  271. unsigned char UndoBuffer[512];
  272. UBYTE FileStr[8][33];
  273. WORD RenderB[4];
  274. struct Gadget ReqFiles[8];
  275. struct IntuiText FileStInfo[8];
  276. struct StringInfo PathInfo =
  277. {
  278.     &PathBuffer[0],&UndoBuffer[0],
  279.     0,511,0,0,0,0,0,0,NULL,0,NULL
  280. };
  281. struct StringInfo FileInfo =
  282. {
  283.     &FileBuffer[0], &UndoBuffer[0],
  284.     0,31,0,0,0,0,0,0,NULL,0,NULL
  285. };
  286. struct IntuiText GenStrInfo =
  287. {
  288.     7,0,JAM2,0,0,NULL,NULL,NULL
  289. };
  290. struct PropInfo SlideInfo =
  291. {
  292.     AUTOKNOB | FREEVERT, 0x0000, 0x0000, 0x0800, 0x0800, 0,0,0,0,0,0
  293. };
  294. SHORT StringPairs[] =
  295. {
  296.     0,0,241,0,241,9,0,9,0,0
  297. };
  298. SHORT SelectPairs[] =
  299. {
  300.     0,0,61,0,61,11,0,11,0,0,
  301. };
  302.  
  303. struct Border StringBorder =
  304. {
  305.     -1,-1,3,0,JAM1,5,StringPairs,NULL,
  306. };
  307. struct Border SelectBorder =
  308. {
  309.     0,0,3,0,JAM1,5,SelectPairs,NULL,
  310. };
  311. struct IntuiText ParentText =
  312. {
  313.     7,0,JAM2,6,2,NULL,"Parent",NULL,
  314. };
  315. struct IntuiText PathText =
  316. {
  317.     7,0,JAM2,-58,0,NULL,"Drawer",NULL,
  318. };
  319. struct IntuiText FileText =
  320. {
  321.     7,0,JAM2,-42,0,NULL,"File",NULL,
  322. };
  323. struct IntuiText CancelText =
  324. {
  325.     7,0,JAM2,6,2,NULL,"Cancel",NULL,
  326. };
  327. struct IntuiText OKText =
  328. {
  329.     7,0,JAM2,22,2,NULL,"OK",NULL,
  330. };
  331. struct Gadget FileNameGadget =
  332. {
  333.     NULL,20,120,240,8,
  334.     GADGHCOMP, RELVERIFY, BOOLGADGET,
  335.     NULL, NULL, NULL,
  336.     NULL, NULL, 0, NULL
  337. };
  338. struct Gadget Parent =
  339. {
  340.     &ReqFiles[0],135,125,62,12,
  341.     GADGHCOMP, RELVERIFY, BOOLGADGET,
  342.     (APTR)&SelectBorder, NULL, &ParentText,
  343.     NULL,NULL,6,NULL
  344. };
  345. struct Gadget Slide =
  346. {
  347.     &Parent,293,32,15,73,
  348.     GADGHCOMP, RELVERIFY, PROPGADGET,
  349.     (APTR)RenderB,NULL,NULL,
  350.     NULL,(APTR)&SlideInfo,5,NULL
  351. };
  352. struct Gadget Path =
  353. {
  354.     &Slide,65,20,240,8,
  355.     GADGHCOMP, RELVERIFY, STRGADGET,
  356.     (APTR)&StringBorder,NULL,&PathText,
  357.     NULL,(APTR)&PathInfo,4,NULL
  358. };
  359. struct Gadget File =
  360. {
  361.     &Path,65,110,240,8,
  362.     GADGHCOMP, RELVERIFY, STRGADGET,
  363.     (APTR)&StringBorder,NULL,&FileText,
  364.     NULL,(APTR)&FileInfo,3,NULL
  365. };
  366. struct Gadget Cancel =
  367. {
  368.     &File,240,125,62,12,
  369.     GADGHCOMP,RELVERIFY, BOOLGADGET,
  370.     (APTR)&SelectBorder,NULL,&CancelText,
  371.     NULL,NULL,1,NULL
  372. };
  373. struct Gadget OK =
  374. {
  375.     &Cancel,30,125,62,12,
  376.     GADGHCOMP, RELVERIFY, BOOLGADGET,
  377.     (APTR)&SelectBorder,NULL,&OKText,
  378.     NULL,NULL,2,NULL
  379. };
  380.  
  381. /***** The Requester Window *****/
  382. struct NewWindow RequesterWindow =
  383. {
  384.     135,50,370,100,0,7,
  385.     GADGETUP,
  386.     SIMPLE_REFRESH | ACTIVATE,NULL,NULL,NULL,NULL,NULL,0,0,0,0,
  387.     CUSTOMSCREEN,
  388. };
  389. /***** The True Requester Definition *****/
  390. struct Requester FileSelectBox;
  391. /*************************************************************************/
  392. struct TextAttr WorkFont =
  393. {
  394.     (STRPTR)"IBM.font",
  395.     8,
  396.     FS_NORMAL,
  397.     FPF_DISKFONT | FPF_ROMFONT
  398. };
  399. struct TextAttr DisplayFont =
  400. {
  401.     (STRPTR)"topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT
  402. };
  403. struct NewScreen FirstWorkScreen =
  404. {
  405.     0,-1,        /* LeftEdge, TopEdge    */
  406.     640,202,    /* Width, Height    */
  407.     4,        /* Depth        */
  408.     4,7,        /* DetailPen, BlockPen    */
  409.     HIRES | SPRITES,/* ViewModes        */
  410.     CUSTOMSCREEN,    /* Type                */
  411.     &DisplayFont,    /* Font                   */
  412.     Titlebar,
  413.     NULL,        /* Gadgets        */
  414.     NULL,        /* CustonBitMap            */
  415. };
  416.  
  417. struct NewWindow FirstWorkWindow =
  418. {
  419.     0,10,        /* LeftEdge, TopEdge    */
  420.     640,192,    /* Width, Height    */
  421.     4,7,        /* DetailPen, BlockPen    */
  422.     MOUSEBUTTONS |    /* IDCMP Flags        */
  423.     RAWKEY |
  424.     MENUPICK,
  425.     SMART_REFRESH |    /* Flags        */
  426.     ACTIVATE |
  427.     BORDERLESS |
  428.     GIMMEZEROZERO,
  429.     NULL,           /* First Gadget         */
  430.     NULL,        /* CheckMark            */
  431.     NULL,        /* Window Title        */
  432.     NULL,        /* Screen        */
  433.     NULL,        /* BitMap        */
  434.     0,0,        /* Min Width, Height    */
  435.     0,0,        /* Max Width, Height    */
  436.     CUSTOMSCREEN,    /* Type                */
  437. };
  438.  
  439. struct NewWindow GadgetWindow =
  440. {
  441.     0,170,
  442.     640,30,
  443.     4,7,
  444.     GADGETUP | ACTIVEWINDOW,
  445.     SMART_REFRESH | WINDOWDRAG,
  446.     &SelColour0,
  447.     NULL,
  448.     "Gadget Box",
  449.     NULL,
  450.     NULL,
  451.     0,0,
  452.     0,0,
  453.     CUSTOMSCREEN
  454. };
  455.  
  456. struct InputEvent inputEvent =
  457. {
  458.     0,IECLASS_RAWKEY,0,0,0
  459. };
  460. UWORD AtrColours[16] =
  461. {
  462.     0x000,0xf00,0x3f1,0xfe0,0x00f,0xf0c,0x2cd,0xddd,
  463.     0x444,0x800,0x281,0x870,0x008,0x806,0x177,0x888
  464. };
  465. /**************************** Menu Definition **************************/
  466. struct IntuiText FourplanesText =
  467. {
  468.     4,7,JAM2,18,1,&DisplayFont,"16 Colors",NULL
  469. };
  470. struct IntuiText ThreeplanesText =
  471. {
  472.     4,7,JAM2,18,1,&DisplayFont,"8 Colors",NULL
  473. };
  474. struct IntuiText TwoplanesText =
  475. {
  476.     4,7,JAM2,18,1,&DisplayFont,"4 Colors",NULL
  477. };
  478. struct IntuiText ColorsText =
  479. {
  480.     4,7,JAM2,0,1,&DisplayFont,"Colors",NULL
  481. };
  482. struct IntuiText QuitText =
  483. {
  484.     4,7,JAM2,0,1,&DisplayFont,"Quit",NULL
  485. };
  486. struct IntuiText AppendText =
  487. {
  488.     4,7,JAM2,0,1,&DisplayFont,"Append",NULL
  489. };
  490. struct IntuiText SaveText =
  491. {
  492.     4,7,JAM2,0,1,&DisplayFont,"Save",NULL
  493. };
  494. struct IntuiText LoadText =
  495. {
  496.     4,7,JAM2,0,1,&DisplayFont,"Load",NULL
  497. };
  498. struct IntuiText ClearText =
  499. {
  500.     4,7,JAM2,0,1,&DisplayFont,"Clear",NULL
  501. };
  502. struct IntuiText PlaybackText =
  503. {
  504.     4,7,JAM2,0,1,&DisplayFont,"Playback",NULL
  505. };
  506. struct IntuiText AboutText =
  507. {
  508.     4,7,JAM2,0,1,&DisplayFont,"About",NULL
  509. };
  510. struct MenuItem Fourplanes =
  511. {
  512.     NULL,80,20,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
  513.     CHECKIT|CHECKED,3,(APTR)&FourplanesText,NULL,'4',NULL,0
  514. };
  515. struct MenuItem Threeplanes =
  516. {
  517.     &Fourplanes,80,10,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
  518.     CHECKIT,5,(APTR)&ThreeplanesText,NULL,'3',NULL,0
  519. };
  520. struct MenuItem Twoplanes =
  521. {
  522.     &Threeplanes,80,0,130,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ|
  523.     CHECKIT,6,(APTR)&TwoplanesText,NULL,'2',NULL,0
  524. };
  525. struct MenuItem Colors =
  526. {
  527.     NULL,0,0,110,10,ITEMTEXT | ITEMENABLED | HIGHCOMP,0,
  528.     (APTR)&ColorsText,NULL,0,&Twoplanes,0
  529. };
  530. struct MenuItem Quit =
  531. {
  532.     NULL,0,60,120,10,ITEMTEXT | ITEMENABLED | HIGHBOX | COMMSEQ,0,
  533.     (APTR)&QuitText,NULL,'Q',NULL,0
  534. };
  535. struct MenuItem AppSave =
  536. {
  537.     NULL,80,10,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP,0,
  538.     (APTR)&SaveText,NULL,0,NULL,0
  539. };
  540. struct MenuItem AppLoad =
  541. {
  542.     &AppSave,80,0,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP,0,
  543.     (APTR)&LoadText,NULL,0,NULL,0
  544. };
  545. struct MenuItem Append =
  546. {
  547.     &Quit,0,50,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP,0,
  548.     (APTR)&AppendText,NULL,0,&AppLoad,0
  549. };
  550. struct MenuItem Save =
  551. {
  552.     &Append,0,40,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,0,
  553.     (APTR)&SaveText,NULL,'S',NULL,0
  554. };
  555. struct MenuItem Load =
  556. {
  557.     &Save,0,30,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,0,
  558.     (APTR)&LoadText,NULL,'L',NULL,0
  559. };
  560. struct MenuItem Clear =
  561. {
  562.     &Load,0,20,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,0,
  563.     (APTR)&ClearText,NULL,'C',NULL,0
  564. };    
  565. struct MenuItem Playback =
  566. {
  567.     &Clear,0,10,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,0,
  568.     (APTR)&PlaybackText,NULL,'P',NULL,0
  569. };
  570. struct MenuItem About =
  571. {
  572.     &Playback,0,0,120,10,ITEMTEXT | ITEMENABLED | HIGHCOMP,0,
  573.     (APTR)&AboutText,NULL,0,NULL,0
  574. };
  575. struct Menu Setup =
  576. {
  577.     NULL,
  578.     100,0,100,10,
  579.     MENUENABLED,
  580.     "Setup",
  581.     &Colors
  582. };
  583. struct Menu Project =
  584. {
  585.     &Setup,
  586.     0, 0, 100, 10,
  587.     MENUENABLED,
  588.     "Project",
  589.     &About
  590. };
  591. /**************************** External Variables ************************/
  592. UBYTE Buffer[MAXINPUTLEN];
  593. SHORT scanner;
  594. struct ANSI storage = { NULL,NULL,-1,-1,-1,-1,NULL };
  595. struct ANSI *sdlstptr, *lastptr, *middle, *front, *back;
  596. struct TextFont *TFont;
  597. SHORT conDevErr = FALSE;
  598. int length = 0,position = 0;    /* used to display where editor is */
  599. int cx = 1, cy = 1;        /* cursor co-ordinates */
  600. static int maxlinelength = 255;
  601. static int tabspacing = 8;
  602. BOOL changes = FALSE;
  603. static char funckey[MAXCHARSETS][8] =
  604. {
  605.     {0xb3, 0xc4, 0xc5, 0xc0, 0xd9, 0xda, 0xbf, 0xd8},
  606.     {0xba, 0xcd, 0xce, 0xc8, 0xbc, 0xc9, 0xbb, 0xd7},
  607.     {0xc1, 0xc2, 0xb4, 0xc3, 0xca, 0xcb, 0xb9, 0xcc},
  608.     {0xbe, 0xd4, 0xb8, 0xd5, 0xbd, 0xd3, 0xb7, 0xd6},
  609.     {0xd0, 0xd2, 0xb6, 0xc7, 0xcf, 0xd1, 0xb5, 0xc6},
  610.     {0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xb0, 0xb1, 0xb2},
  611.     {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7},
  612.     {0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7},
  613.     {0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef},
  614.     {0xf0, 0xf1, 0xf2, 0xf3, 0xfe, 0xf6, 0xfd, 0xfb},
  615.     {0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf},
  616.     {0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfc}
  617. };
  618. long _stack = 10000;        /* my Load-And-Stay Resident stack size */
  619. char *_procname = "Prism";    /* my proceedure name */
  620. long _priority = 0;        /* A regular priority */
  621. long _BackGroundIO = 0;        /* If this != 0, I can Write() to CLI but
  622.                    I must Close(_Backstdout) when done */
  623. extern BPTR _Backstdout;    /* CLI file handle */
  624.  
  625. struct IntuiText GeneralText =
  626. {
  627.     1,0,        /* FrontPen, BackPen */
  628.     JAM2,       /* DrawMode */
  629.     0,0,        /* LeftEdge, TopEdge */
  630.     &WorkFont,  /* Font */
  631.     Buffer,
  632.     NULL
  633. };
  634. /************************************************************************
  635. *                       And now.... THE BEGINNING!!                    *
  636. ************************************************************************/
  637. main()
  638. {
  639.     ULONG MessageClass;
  640.     USHORT code, qualifier;
  641.     
  642.     struct Message *GetMsg();
  643.     char memusestr[81];        /* display position and length */
  644.     int mx, my;            /* mouse co-ordinates */
  645.     int fcolour = 7;        /* initialize fourground colour */
  646.     int bcolour = 0;
  647.     int tabplace, tempnum, memleft, jx, jy;
  648.     short int presset = 0;
  649.     BOOL mbuttons = FALSE, BGmode = FALSE, gadwinfront = TRUE;
  650.     struct Gadget *GadgetPtr;
  651.     USHORT GadgetID;
  652.     
  653.     FirstWorkScreen.Depth = 4;
  654.     OpenLibs();
  655.     lastptr = &storage;
  656.     middle = lastptr;
  657.     
  658.     FOREVER
  659.     {
  660.     mx = (int) (WorkWindow->GZZMouseX)/8+1;
  661.     my = (int) (WorkWindow->GZZMouseY)/8+1;
  662.         if (cx >= MINWIDTH && cx <= MAXWIDTH && cy >= MINHEIGHT &&
  663.         cy <= MAXHEIGHT)
  664.     {
  665.         jx = (cx-1)*8-2;
  666.         jy = (cy-1)*8+FirstWorkWindow.TopEdge;
  667.         MoveSprite(&WorkScreen->ViewPort,&Cursor,jx,jy);
  668.     }
  669.  
  670.     if (message = (struct IntuiMessage *)GetMsg(WorkWindow->UserPort))
  671.     {
  672.         MessageClass = message->Class;
  673.         code = message->Code;
  674.             qualifier = message->Qualifier;
  675.         ReplyMsg(message);
  676.             if (MessageClass & MOUSEBUTTONS)
  677.             {
  678.                 switch(code)
  679.                 {
  680.                     case SELECTDOWN :
  681.                         mbuttons = TRUE;
  682.                         break;
  683.                                         
  684.                     case SELECTUP :
  685.                         mbuttons = FALSE;
  686.                         break;
  687.                 }
  688.             }
  689.         else switch (MessageClass)
  690.         {
  691.                 case RAWKEY :
  692.                     if(!(code & IECODE_UP_PREFIX))
  693.                     {
  694.                         inputEvent.ie_Code = code;
  695.                         inputEvent.ie_Qualifier = qualifier;
  696.             scanner = RawKeyConvert(&inputEvent,Buffer,
  697.                 MAXINPUTLEN,NULL);
  698.                         Buffer[scanner] = NULL;
  699.             if(Buffer[0]==0x9b && scanner>1)
  700.             {
  701.                 switch(Buffer[1])
  702.                 {
  703.                 case CURSOR_UP :
  704.                                 cy--;
  705.                                 if(cy < MINHEIGHT)
  706.                                    cy = MINHEIGHT;
  707.                 break;
  708.                 
  709.                 case CURSOR_DOWN :
  710.                                 cy++;
  711.                                 if(cy > MAXHEIGHT)
  712.                                    cy = MAXHEIGHT;
  713.                 break;
  714.                 
  715.                 case CURSOR_LEFT :
  716.                 if(qualifier & IEQUALIFIER_CONTROL)
  717.                 {
  718.                     if(middle != NULL && middle != &storage)
  719.                     {
  720.                     back = middle;
  721.                     tempnum = 1;
  722.                     while(back != NULL && 
  723.                           back != &storage &&
  724.                           tempnum == 1)
  725.                     {
  726.                         back=back->previous;
  727.                         if(middle->x == back->x &&
  728.                            middle->y == back->y)
  729.                         {
  730.                         memusestr[0]=back->letter;
  731.                         memusestr[1]=NULL;
  732.                         ColourTextXY(WorkWindow,
  733.                          memusestr,back->x,back->y,
  734.                          back->fcolour,
  735.                          back->bcolour);
  736.                          tempnum = 0;
  737.                         }
  738.                     }
  739.                     if(back==NULL || back==&storage)
  740.                     {
  741.                         memusestr[0] = SPACE;
  742.                         memusestr[1] = NULL;
  743.                         ColourTextXY(WorkWindow,
  744.                           memusestr,middle->x,
  745.                           middle->y,1,0);
  746.                     }
  747.                     middle=middle->previous;
  748.                     if(middle != &storage)
  749.                     {
  750.                         cx = middle->x;
  751.                         cy = middle->y;
  752.                     }
  753.                     else
  754.                     {
  755.                         cx = MINWIDTH;
  756.                         cy = MINHEIGHT;
  757.                     } 
  758.                     --position;
  759.                     }
  760.                 } 
  761.                 else
  762.                 {
  763.                     cx--;
  764.                     if(cx < MINWIDTH) cx = MINWIDTH;
  765.                 }
  766.                 break;
  767.                 
  768.                 case CURSOR_RIGHT :
  769.                 if(qualifier & IEQUALIFIER_CONTROL)
  770.                 {
  771.                     if(middle != NULL)
  772.                     {
  773.                     if(middle->next != NULL)
  774.                     {
  775.                         middle=middle->next;
  776.                         cx = middle->x; cy = middle->y;
  777.                         ++position;
  778.                     }
  779.                     memusestr[0]=middle->letter;
  780.                     memusestr[1]=NULL;
  781.                     ColourTextXY(WorkWindow,memusestr,
  782.                       middle->x,middle->y,
  783.                       middle->fcolour,middle->bcolour);
  784.                     }
  785.                 } 
  786.                 else
  787.                 {
  788.                     cx++;
  789.                     if(cx > MAXWIDTH) cx = MAXWIDTH;
  790.                 }
  791.                 break;
  792.                 
  793.                 default :
  794.                 if (scanner == 3 && Buffer[2] == '~')
  795.                 {
  796.                     if (Buffer[1] == '?')
  797.                     {
  798.                     if(gadwinfront)
  799.                     {
  800.                         WindowToBack(Gads);
  801.                         gadwinfront = FALSE;
  802.                     }
  803.                     else
  804.                     {
  805.                         WindowToFront(Gads);
  806.                         gadwinfront = TRUE;
  807.                     }
  808.                     break;
  809.                     }
  810.                     Buffer[2] = NULL;
  811.                     tempnum = atoi(&Buffer[1]);
  812.                     Buffer[2] = '~';
  813.                         if(tempnum >= 0 && tempnum <= 7)
  814.                         {
  815.                     Buffer[0] = funckey[presset][tempnum];
  816.                     Buffer[1] = NULL;
  817.                     scanner = 1;
  818.                         }
  819.                     if(tempnum == 8)
  820.                         {
  821.                     ++presset;
  822.                     if(presset > MAXCHARSETS-1)
  823.                         presset = 0;
  824.                          }
  825.                         if(tempnum == 9)
  826.                         {
  827.                     --presset;
  828.                     if(presset < 0)
  829.                             presset = MAXCHARSETS-1;
  830.                         }
  831.                 }
  832.                 }
  833.             }
  834.                         if(scanner > 0 && Buffer[0] != 0x9b)
  835.                         {
  836.                             switch(Buffer[0])
  837.                             {
  838.                                 case RETURN : 
  839.                                     cx = MINWIDTH;
  840.                                     cy++;
  841.                                     if (cy > MAXHEIGHT)
  842.                                         cy = MAXHEIGHT;
  843.                                     break;
  844.                                 
  845.                                 case BACKSPACE :
  846.                                     if (lastptr == &storage ||
  847.                     middle == &storage)
  848.                                         break;
  849.                     back = middle;
  850.                     tempnum = 1;
  851.                     while(back != NULL && back != &storage 
  852.                         && tempnum == 1)
  853.                     {
  854.                     back=back->previous;
  855.                     if(middle->x == back->x &&
  856.                        middle->y == back->y)
  857.                     {
  858.                         memusestr[0]=back->letter;
  859.                         memusestr[1]=NULL;
  860.                         ColourTextXY(WorkWindow,
  861.                           memusestr,back->x,back->y,
  862.                           back->fcolour,back->bcolour);
  863.                         tempnum = 0;
  864.                     }
  865.                     }
  866.                     if(back==NULL || back==&storage)
  867.                     {
  868.                     memusestr[0] = SPACE;
  869.                     memusestr[1] = NULL;
  870.                     ColourTextXY(WorkWindow,
  871.                       memusestr,middle->x,middle->y,1,0);
  872.                     }
  873.                     if(middle->next == NULL)
  874.                     {
  875.                     free((char *)lastptr);
  876.                                     lastptr = sdlstptr;
  877.                                     sdlstptr = sdlstptr->previous;
  878.                                     lastptr->next = NULL;
  879.                     memusestr[0] = lastptr->letter;
  880.                     memusestr[1] = NULL;
  881.                     if(lastptr != &storage)
  882.                     {
  883.                         ColourTextXY(WorkWindow,memusestr,
  884.                           lastptr->x,lastptr->y,
  885.                           lastptr->fcolour,lastptr->bcolour);
  886.                         cx = lastptr->x; cy = lastptr->y;
  887.                     }
  888.                     middle = lastptr;
  889.                     }
  890.                     else
  891.                     {
  892.                     for(back = middle, front = back->next;
  893.                         front != NULL; back=back->next,
  894.                         front = back->next)
  895.                     {
  896.                         back->fcolour = front->fcolour;
  897.                         back->bcolour = front->bcolour;
  898.                         back->x = front->x;
  899.                         back->y = front->y;
  900.                         back->letter = front->letter;
  901.                         back->attr = front->attr;
  902.                     }
  903.                     free((char *)lastptr);
  904.                                     lastptr = sdlstptr;
  905.                                     sdlstptr = sdlstptr->previous;
  906.                                     lastptr->next = NULL;
  907.                     middle = middle->previous;
  908.                     memusestr[0] = middle->letter;
  909.                     memusestr[1] = NULL;
  910.                     if(middle != &storage)
  911.                     {
  912.                         ColourTextXY(WorkWindow,memusestr,
  913.                         middle->x,middle->y,
  914.                         middle->fcolour,middle->bcolour);
  915.                         cx = middle->x; cy = middle->y;
  916.                     }
  917.                     }
  918.                                     position--; length--; changes = TRUE;
  919.                                     break;
  920.                                     
  921.                                 case TAB :
  922.                                     tabplace = cx;
  923.                     tabplace += (tabspacing -
  924.                         ((cx-1) % tabspacing));
  925.                                     if(tabplace > MAXWIDTH)
  926.                                     {
  927.                                         tabplace = MINWIDTH;
  928.                                         cy++;
  929.                                         if(cy > MAXHEIGHT)
  930.                                             cy = MAXHEIGHT;
  931.                                     }
  932.                                     cx = tabplace;
  933.                                     break;
  934.                                                     
  935.                                 default :
  936.                 for(tempnum = 0; tempnum < scanner;
  937.                     tempnum++)
  938.                 {
  939.                                     if (Buffer[tempnum] < 32 || 
  940.                     Buffer[tempnum] == 127) break;
  941.                                     sdlstptr = lastptr;
  942.                                     lastptr = (struct ANSI *)
  943.                                         malloc(sizeof(struct ANSI));
  944.                                     if (lastptr == NULL)
  945.                     {
  946.                     lastptr = sdlstptr;
  947.                     sdlstptr = lastptr->previous;
  948.                                         break;
  949.                     }
  950.                     sdlstptr->next = lastptr;
  951.                     lastptr->previous = sdlstptr;
  952.                     lastptr->next = NULL;
  953.                     if (middle->next == lastptr)
  954.                     {
  955.                                     lastptr->letter = Buffer[tempnum];
  956.                                     lastptr->x = cx;
  957.                                     lastptr->y = cy;
  958.                                     lastptr->fcolour = fcolour;
  959.                     lastptr->bcolour = bcolour;
  960.                     middle = lastptr;
  961.                     } 
  962.                     else
  963.                     {
  964.                     middle = middle->next;
  965.                     for(back = lastptr,
  966.                         front = back->previous;
  967.                         back != middle;
  968.                         back = back->previous,
  969.                         front = back->previous)
  970.                     {
  971.                         back->fcolour = front->fcolour;
  972.                         back->bcolour = front->bcolour;
  973.                         back->x = front->x;
  974.                         back->y = front->y;
  975.                         back->letter = front->letter;
  976.                         back->attr = front->attr;
  977.                     }
  978.                                     middle->letter = Buffer[tempnum];
  979.                                     middle->x = cx;
  980.                                     middle->y = cy;
  981.                                     middle->fcolour = fcolour;
  982.                     middle->bcolour = bcolour;
  983.                     }
  984.                                     ColourTextXY(WorkWindow,
  985.                                         Buffer,cx,cy,fcolour,bcolour);
  986.                                     cx++;
  987.                                     if(cx > MAXWIDTH)
  988.                                     {
  989.                                         cx = MINWIDTH; cy++;
  990.                                         if (cy > MAXHEIGHT)
  991.                                             cy=MAXHEIGHT;
  992.                                     }
  993.                                     position++; length++;
  994.                     changes = TRUE;
  995.                 }
  996.                                 break;
  997.                             }
  998.                         }
  999.                     }
  1000.                     break;
  1001.  
  1002.                 case MENUPICK :
  1003.                     MenuAnalyse(code);
  1004.                     break;
  1005.         }
  1006.     } 
  1007.     else
  1008.     {
  1009.         sprintf(memusestr,"P:X=%2d Y=%2d",mx,my);
  1010.         if(mx < 1 || my < 1)
  1011.             sprintf(memusestr,"P:         ");
  1012.         ColourText(Gads,memusestr,488,1,7,0);
  1013.         sprintf(memusestr,"C:X=%2d Y=%2d",cx,cy);
  1014.         ColourText(Gads,memusestr,380,1,7,0);
  1015.             sprintf(memusestr,"Pos: %5d  Len: %5d",position,length);
  1016.             ColourText(Gads,memusestr,2,1,7,0);
  1017.             sprintf(memusestr,"ForeC: %2d  BackC: %2d",fcolour,bcolour);
  1018.             ColourText(Gads,memusestr,200,1,fcolour,bcolour);
  1019.         sprintf(memusestr,
  1020.             "Set:%2d F1=%c F2=%c F3=%c F4=%c F5=%c F6=%c F7=%c F8=%c",
  1021.         presset+1,funckey[presset][0],funckey[presset][1],
  1022.         funckey[presset][2],funckey[presset][3],
  1023.         funckey[presset][4],funckey[presset][5],
  1024.         funckey[presset][6],funckey[presset][7]);
  1025.         ColourText(Gads,memusestr,3,20,7,0);
  1026.         sprintf(memusestr,"Free Memory:%7d",memleft = AvailMem(0));
  1027.         ColourText(Gads,memusestr,390,20,3,0);
  1028.     }
  1029.     if (message = (struct IntuiMessage *)
  1030.         GetMsg(Gads->UserPort))
  1031.     {
  1032.         MessageClass = message->Class;
  1033.         code = message->Code;
  1034.             qualifier = message->Qualifier;
  1035.             GadgetPtr = (struct Gadget *) message->IAddress;
  1036.         ReplyMsg(message);
  1037.             GadgetID = GadgetPtr->GadgetID;
  1038.             switch(MessageClass)
  1039.             {
  1040.                 case GADGETUP :
  1041.             if (GadgetID == 17)
  1042.             {
  1043.                 BGmode ^= TRUE;
  1044.             break;
  1045.             }
  1046.             if (BGmode == TRUE)
  1047.             {
  1048.             if (GadgetID >= 1 && GadgetID <=8)
  1049.             {
  1050.                 bcolour = (int)GadgetID-1;
  1051.                 BGmode = FALSE;
  1052.             }
  1053.             } else {
  1054.                         if (GadgetID >= 1 && GadgetID <= 16)
  1055.                         {
  1056.                             fcolour = (int)GadgetID - 1;
  1057.                         }
  1058.             }
  1059.                     break;
  1060.                     
  1061.         case ACTIVEWINDOW :
  1062.                     ActivateWindow(WorkWindow);
  1063.                     break;
  1064.             }
  1065.             ActivateWindow(WorkWindow);
  1066.         }
  1067.         if (mbuttons)
  1068.         {
  1069.             /**** Move the cursor to (mx,my) ****/;
  1070.             cx = mx;
  1071.             cy = my;
  1072.         if (cx < MINWIDTH) cx = MINWIDTH;
  1073.         if (cx > MAXWIDTH) cx = MAXWIDTH;
  1074.         if (cy < MINHEIGHT) cy = MINHEIGHT;
  1075.         if (cy > MAXHEIGHT) cy = MAXHEIGHT;
  1076.         }
  1077.     }
  1078. }
  1079. /************************************************************************
  1080. *                Now, for the Libraries that need to be opened            *
  1081. ************************************************************************/
  1082. void OpenLibs()
  1083. {
  1084.     void *OpenLibrary();
  1085.     struct Window *OpenWindow();
  1086.     struct Screen *OpenScreen();
  1087.     int i;
  1088.     
  1089.     if(!(IntuitionBase = (struct IntuitionBase *)
  1090.     OpenLibrary("intuition.library", 0L)))
  1091.     {
  1092.     CloseLibs("Intuition Library cannot be found");
  1093.     exit(FALSE);
  1094.     }
  1095.     if(!(GfxBase = (struct GfxBase *)
  1096.     OpenLibrary("graphics.library", 0L)))
  1097.     {
  1098.     CloseLibs("Graphics Library cannot be found");
  1099.     exit(FALSE);
  1100.     }
  1101.     if((DiskfontBase = (ULONG*)
  1102.     OpenLibrary("diskfont.library",0))==NULL)
  1103.     {
  1104.     CloseLibs("Diskfont Library cannot be found");
  1105.     exit(FALSE);
  1106.     }
  1107.     if((TFont = (struct TextFont *) 
  1108.     OpenDiskFont(&WorkFont)) == NULL)
  1109.     {
  1110.     WorkFont.ta_Name = (STRPTR)"topaz.font";
  1111.     WorkFont.ta_YSize = TOPAZ_EIGHTY;
  1112.     }
  1113.     ChipCursor = (UWORD*)AllocMem(sizeof(Cursor_Data),MEMF_CLEAR|MEMF_CHIP);
  1114.     ChipBlank = (UWORD*)AllocMem(sizeof(Blank_Data),MEMF_CLEAR|MEMF_CHIP);
  1115.     if ((ChipCursor == 0) | (ChipBlank == 0)) CloseLibs("No chip memory");
  1116.     Helping = ChipCursor;
  1117.     for (i=0; i<(sizeof(Cursor_Data)/sizeof(UWORD));i++)
  1118.     {
  1119.     *Helping = Cursor_Data[i];
  1120.     Helping++;
  1121.     }
  1122.     for (i=0; i<(sizeof(Blank_Data)/sizeof(UWORD));i++)
  1123.     {
  1124.     *Helping = Blank_Data[i];
  1125.     Helping++;
  1126.     }
  1127.     Cursor.x = -1;
  1128.     Cursor.y = 36;
  1129.     Cursor.height = 8;
  1130.     Spr1 = GetSprite(&Cursor,-1);
  1131.     if(Spr1 == -1)
  1132.     {
  1133.     CloseLibs("Sprite cannot be displayed");
  1134.     exit(FALSE);
  1135.     }
  1136.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1137.  
  1138.     OpenSAW();
  1139.     
  1140.     if (!(OpenDevice("console.device",-1L,&ioStdReq,0L)))
  1141.         ConsoleDevice = ioStdReq.io_Device;
  1142.     else 
  1143.     CloseLibs("Could not open console.device");
  1144. }
  1145. OpenSAW()
  1146. {
  1147.     struct ViewPort *vp;
  1148.  
  1149.     if(!(WorkScreen = (struct Screen *)
  1150.     OpenScreen(&FirstWorkScreen)))
  1151.     {
  1152.     CloseLibs("Screen cannot be opened");
  1153.     exit(FALSE);
  1154.     }
  1155.     vp = &WorkScreen->ViewPort;
  1156.     LoadRGB4(vp,AtrColours,16);
  1157.     RemakeDisplay();
  1158.     FirstWorkWindow.Screen = WorkScreen;
  1159.     if(!(WorkWindow = (struct Window *)    OpenWindow(&FirstWorkWindow)))
  1160.     {
  1161.     CloseLibs("Window cannot be opened");
  1162.     exit(FALSE);
  1163.     }
  1164.     GadgetWindow.Screen = WorkScreen;
  1165.     if(!(Gads = (struct Window *) OpenWindow(&GadgetWindow)))
  1166.     {
  1167.     CloseLibs("Gadget window cannot be opened");
  1168.     exit(FALSE);
  1169.     }
  1170.     SetMenuStrip(WorkWindow, &Project);
  1171.     return(0);
  1172. }
  1173. /************************************************************************
  1174. *       If Libraries have to be opened, then they have to be closed!    *
  1175. ************************************************************************/
  1176. void CloseLibs(str)
  1177. char *str;
  1178. {
  1179.     int dummy=0, handle;
  1180.     
  1181.     FreeAllMem();
  1182.     if(Spr1 != -1)    FreeSprite(Spr1);
  1183.     if(ChipCursor != 0) FreeMem(ChipCursor,sizeof(Cursor_Data));
  1184.     if(ChipBlank != 0)    FreeMem(ChipBlank,sizeof(Blank_Data));
  1185.     CloseSAW();
  1186.     if(TFont)        CloseFont(TFont);
  1187.     if(DiskfontBase)    CloseLibrary(DiskfontBase);
  1188.     if(GfxBase)            CloseLibrary(GfxBase);
  1189.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  1190.     if(str[0] != '~')
  1191.     {    
  1192.         handle = open("RAW:160/50/320/25/Prism",0,dummy);
  1193.         if (handle != -1)
  1194.         {
  1195.         write(handle,str,strlen(str));
  1196.         Delay(120L);
  1197.         close(handle);
  1198.         }
  1199.     }
  1200. }
  1201. CloseSAW()
  1202. {
  1203.     if(Gads)    CloseWindow(Gads);
  1204.     if(WorkWindow)
  1205.     {
  1206.         ClearMenuStrip(WorkWindow);
  1207.     CloseWindow(WorkWindow);
  1208.     }
  1209.     if(WorkScreen)    CloseScreen(WorkScreen);
  1210.     return(0);
  1211. }
  1212. /*************************************************************************
  1213. *                  The colour version of the Text routine                *
  1214. *************************************************************************/
  1215. ColourText(w_ptr,s,x,y,fc,bc)
  1216. struct Window *w_ptr;
  1217. char *s;
  1218. int x,y;
  1219. int fc,bc;
  1220. {
  1221.     GeneralText.FrontPen = (UBYTE) fc;
  1222.     GeneralText.BackPen = (UBYTE) bc;
  1223.     GeneralText.IText = (UBYTE *) s;
  1224.     PrintIText(w_ptr->RPort,&GeneralText,x,y);
  1225.     return(TRUE);
  1226. }
  1227. /*************************************************************************
  1228. *      X and Y now represent the row and column of TEXT and not bits     *
  1229. *************************************************************************/
  1230. ColourTextXY(w_ptr,s,x,y,fc,bc)
  1231. struct Window *w_ptr;
  1232. char *s;
  1233. int x,y;
  1234. int fc,bc;
  1235. {
  1236.     int ix,iy;
  1237.     
  1238.     GeneralText.FrontPen = (UBYTE) fc;
  1239.     GeneralText.BackPen = (UBYTE) bc;
  1240.     GeneralText.IText = (UBYTE *) s;
  1241.  
  1242.     if (x < MINWIDTH || x > MAXWIDTH || y < MINHEIGHT || y > MAXHEIGHT)
  1243.         return(FALSE);
  1244.     ix = (x-1)*8; /* to calculate distance by text size and not pixels */
  1245.     iy = (y-1)*8;
  1246.     
  1247.     PrintIText(w_ptr->RPort,&GeneralText,ix,iy);
  1248.     return(TRUE);
  1249. }
  1250. /*************************************************************************
  1251. *                         Free the used memory                           *
  1252. *************************************************************************/
  1253. FreeAllMem()
  1254. {
  1255.     struct IntuiText ClearingText =
  1256.     {
  1257.     4,7,JAM2,126,11,NULL,"Clearing Current ANSI.  Please Wait.",NULL
  1258.     };
  1259.     
  1260.     InitRequester(&FileSelectBox);
  1261.     FileSelectBox.LeftEdge = 50;
  1262.     FileSelectBox.TopEdge = 85;
  1263.     FileSelectBox.Width = 540;
  1264.     FileSelectBox.Height = 30;
  1265.     FileSelectBox.ReqText = &ClearingText;
  1266.     FileSelectBox.BackFill = 7;
  1267.     Request(&FileSelectBox, WorkWindow);
  1268.     for(lastptr=storage.next; lastptr != NULL; lastptr = lastptr->next)
  1269.     {
  1270.     free((char *)lastptr);
  1271.     }
  1272.     storage.next = NULL;
  1273.     lastptr = &storage;
  1274.     middle = lastptr;
  1275.     length = 0; position = 0;
  1276.     cx = MINWIDTH; cy = MINHEIGHT; changes = FALSE;
  1277.     EndRequest(&FileSelectBox, WorkWindow);
  1278.     return(TRUE);
  1279. }
  1280. /*************************************************************************
  1281. *               Attempt to playback what what stored in Memory           *
  1282. *************************************************************************/
  1283. PlayBack()
  1284. {
  1285.     char displaystr[2];
  1286.     char *LeftMouse = (char *)0xBFE001;
  1287.     
  1288.     position = length = 0;
  1289.     ClearWorkWindow();
  1290.     WindowToFront(WorkWindow);
  1291.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
  1292.     Delay(30L);
  1293.     displaystr[1] = NULL;
  1294.     for(lastptr=storage.next; lastptr != NULL; lastptr = lastptr->next)
  1295.     {
  1296.         displaystr[0] = lastptr->letter;
  1297.         ColourTextXY(WorkWindow,displaystr,lastptr->x,lastptr->y,
  1298.             lastptr->fcolour,lastptr->bcolour);
  1299.     ++position;++length;
  1300.     if((*LeftMouse & 0x40)==0x40) Delay(1L);
  1301.     }
  1302.     lastptr = sdlstptr->next;
  1303.     middle = lastptr;
  1304.     cx = middle->x; cy = middle->y;
  1305.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1306.     WindowToBack(WorkWindow);
  1307.     return(TRUE);
  1308. }
  1309. /*************************************************************************
  1310. *                        Clear the WorkWindow                            *
  1311. *************************************************************************/
  1312. ClearWorkWindow()
  1313. {
  1314.     int i;
  1315.     static char blanker[] = "                                                                                ";
  1316.     
  1317.     for (i = 0; i <= 206; i += 8)
  1318.     {
  1319.         ColourText(WorkWindow,blanker,0,i,1,0);
  1320.     }
  1321.     return(TRUE);
  1322. }
  1323. /************************************************************************
  1324. *               Analyse which item was picked on the menu               *
  1325. ************************************************************************/
  1326. MenuAnalyse(Menunumber)
  1327. USHORT Menunumber;
  1328. {
  1329.     USHORT Menu, MenuItem, SubItem;
  1330.     
  1331.     Menu = MENUNUM(Menunumber);
  1332.     MenuItem = ITEMNUM(Menunumber);
  1333.     SubItem = SUBNUM(Menunumber);
  1334.     switch(Menu)
  1335.     {
  1336.         case 0 :    /* The "Project" Menu */
  1337.             ProjectMenu(MenuItem,SubItem);
  1338.             break;
  1339.         
  1340.     case 1 :    /* The "Setup" Menu */
  1341.         SetupMenu(MenuItem,SubItem);
  1342.         break;
  1343.     }
  1344.     return(TRUE);
  1345. }
  1346. ProjectMenu(MenuItem,SubItem)
  1347. USHORT MenuItem, SubItem;
  1348. {
  1349.     BOOL GetResponce;
  1350.     
  1351.     switch(MenuItem)
  1352.     {
  1353.         case 0 :    /* The "About" MenuItem */
  1354.             AboutReq();
  1355.             break;
  1356.             
  1357.         case 1 :    /* The "Playback" MenuItem */
  1358.             PlayBack();
  1359.             break;
  1360.             
  1361.         case 2 :    /* The "Clear" MenuItem */
  1362.         GetResponce = AreYouSure("Clear Memory?");
  1363.         if(GetResponce == TRUE)
  1364.         {
  1365.         if(changes == TRUE)
  1366.         {
  1367.             GetResponce = AreYouSure("Save with new changes?");
  1368.             if(GetResponce == TRUE) SaveANSI(TRUE);
  1369.         }
  1370.         FreeAllMem();
  1371.         ClearWorkWindow();
  1372.         }
  1373.             break;
  1374.  
  1375.         case 3 :    /* The "Load" MenuItem */
  1376.         LoadANSI(TRUE);
  1377.             break;
  1378.         
  1379.     case 4 :    /* The "Save" MenuItem */
  1380.         SaveANSI(TRUE);
  1381.         break;
  1382.         
  1383.     case 5 :    /* The "Append" Submenu */
  1384.         switch(SubItem)
  1385.         {
  1386.         case 0 :    /* The "Append Load" SubItem */
  1387.             LoadANSI(FALSE);
  1388.             break;
  1389.         case 1 :    /* The "Append Save" SubItem */
  1390.             SaveANSI(FALSE);
  1391.             break;
  1392.         }
  1393.         break;
  1394.  
  1395.     case 6 :    /* The "Quit" MenuItem */
  1396.         GetResponce = AreYouSure("Exit Prism?");
  1397.         if(GetResponce == TRUE)
  1398.         {
  1399.         if(changes == TRUE)
  1400.         {
  1401.             GetResponce = AreYouSure("Save with new changes?");
  1402.             if(GetResponce == TRUE) SaveANSI(TRUE);
  1403.         }
  1404.         CloseLibs("~");
  1405.         exit(TRUE);
  1406.         }
  1407.         break;
  1408.     }
  1409.     return(TRUE);
  1410. }
  1411. SetupMenu(MenuItem,SubItem)
  1412. USHORT MenuItem,SubItem;
  1413. {
  1414.     switch(MenuItem)
  1415.     {
  1416.     case 0 :    /* The "Colors" SubMenu */
  1417.         SelColour3.NextGadget = &SelColour4;
  1418.         SelColour7.NextGadget = &SelColour8;
  1419.         switch(SubItem)
  1420.         {
  1421.         case 0 :    /* The "2 Planes" SubItem */
  1422.             CloseSAW();
  1423.             FirstWorkScreen.Depth = 2;
  1424.             SelColour3.NextGadget = &ForeBackGadget;
  1425.             OpenSAW();
  1426.             break;
  1427.             
  1428.         case 1 :    /* The "3 Planes" SubItem */
  1429.             CloseSAW();
  1430.             FirstWorkScreen.Depth = 3;
  1431.             SelColour7.NextGadget = &ForeBackGadget;
  1432.             OpenSAW();
  1433.             break;
  1434.             
  1435.         case 2 :    /* The "4 Planes" SubItem */
  1436.             CloseSAW();
  1437.             FirstWorkScreen.Depth = 4;
  1438.             OpenSAW();
  1439.             break;
  1440.         }
  1441.         break;
  1442.     }
  1443.     return(TRUE);
  1444. }
  1445. /************************************************************************
  1446. *                     An "Are You Sure?" Requester                      *
  1447. ************************************************************************/
  1448. AreYouSure(yousaidit)
  1449. char *yousaidit;
  1450. {
  1451.     BOOL Responce;
  1452.     
  1453.     struct IntuiText Really =
  1454.     {
  1455.         0,1,JAM1,40,5,NULL,NULL,NULL
  1456.     };
  1457.     struct IntuiText Yes =
  1458.     {
  1459.         0,1,JAM1,5,3,NULL,"YES",NULL
  1460.     };
  1461.     struct IntuiText No =
  1462.     {
  1463.         0,1,JAM1,5,3,NULL,"NO!",NULL
  1464.     };
  1465.     Really.IText = (UBYTE *)yousaidit;
  1466.     Responce = AutoRequest(WorkWindow,&Really,&Yes,&No,0,0,
  1467.     TextLength(WorkWindow->RPort,yousaidit,strlen(yousaidit))+100,50);
  1468.     return((int)Responce);
  1469. }
  1470. /*************************************************************************
  1471. *              The "Something Went Wrong" Requester Routine              *
  1472. *************************************************************************/
  1473. GenErrorReq(thecatch)
  1474. char *thecatch;
  1475. {
  1476.     BOOL Answer = FALSE;
  1477.     struct IntuiText SomethingText =
  1478.     {
  1479.         0,1,JAM2,15,8,NULL,NULL,NULL
  1480.     };
  1481.     struct IntuiText AlrightText =
  1482.     {
  1483.         0,1,JAM2,5,3,NULL,"OK?",NULL
  1484.     };
  1485.     SomethingText.IText = (UBYTE *)thecatch;
  1486.     Answer = AutoRequest(WorkWindow,&SomethingText,NULL,&AlrightText,0,0,
  1487.     TextLength(WorkWindow->RPort,thecatch,strlen(thecatch))+100,37);
  1488.     return((int)Answer);
  1489. }
  1490. /*************************************************************************
  1491. *                     The "About" Requester Routine                      *
  1492. *************************************************************************/
  1493. AboutReq()
  1494. {
  1495.     BOOL Answer = FALSE, Waiting;
  1496.     char *LeftMouse = (char *)0xBFE001;
  1497.  
  1498.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
  1499.     RequesterWindow.LeftEdge = 41;
  1500.     RequesterWindow.TopEdge = 20;
  1501.     RequesterWindow.Width = 558;
  1502.     RequesterWindow.Height = 82;
  1503.     RequesterWindow.Title = NULL;
  1504.     RequesterWindow.Screen = WorkScreen;
  1505.     RequesterWindow.FirstGadget = NULL;
  1506.     InitRequester(&FileSelectBox);
  1507.     FileSelectBox.LeftEdge = 4;
  1508.     FileSelectBox.TopEdge = 2;
  1509.     FileSelectBox.Width = 550;
  1510.     FileSelectBox.Height = 90;
  1511.     FileSelectBox.ReqText = &AboutProgText;
  1512.     FileSelectBox.BackFill = 7;
  1513.     if(!(ReqWindow = (struct Window *) OpenWindow(&RequesterWindow)))
  1514.     {
  1515.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1516.         return(FALSE);
  1517.     }
  1518.     Request(&FileSelectBox, ReqWindow);
  1519.     Waiting = TRUE;
  1520.     while(Waiting)
  1521.     {
  1522.     if(!((*LeftMouse & 0x40) == 0x40)) Waiting = FALSE;
  1523.     }
  1524.     EndRequest(&FileSelectBox, ReqWindow);
  1525.     if (ReqWindow)  CloseWindow(ReqWindow);
  1526.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1527.     return((int)Answer);
  1528. }
  1529. /************************************************************************
  1530. *               Load ANSI from Disk                *
  1531. ************************************************************************/
  1532. LoadANSI(loadtype)
  1533. BOOL loadtype;
  1534. {
  1535.     FILE *ansiin;
  1536.     BOOL Answer;
  1537.     char ch;
  1538.     int cx = 1, cy = 1, fcolour = 1, bcolour = 0;
  1539.     int esclength, semicount, scanplace, actualnum, biggerbit;
  1540.     BOOL endofit;
  1541.  
  1542.     struct IntuiText LoadingText =
  1543.     {
  1544.     4,7,JAM2,122,11,NULL,"Loading ANSI from disk.  Please Wait.",NULL
  1545.     };
  1546.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
  1547.     if(loadtype == TRUE)
  1548.     Answer = MakeFileReq("Load");
  1549.     else
  1550.     Answer = MakeFileReq("Append Load");
  1551.     if (Answer == FALSE) 
  1552.     {
  1553.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1554.     return(FALSE);
  1555.     }
  1556.     if (!(ansiin = fopen(FileBuffer,"r")))
  1557.     {
  1558.         GenErrorReq("File can't open for read!");
  1559.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1560.         return(FALSE);
  1561.     }
  1562. /***** Start Loading *****/
  1563.     if (loadtype == TRUE)
  1564.     {
  1565.     FreeAllMem();
  1566.     ClearWorkWindow();
  1567.     }
  1568.     InitRequester(&FileSelectBox);
  1569.     FileSelectBox.LeftEdge = 50;
  1570.     FileSelectBox.TopEdge = 85;
  1571.     FileSelectBox.Width = 540;
  1572.     FileSelectBox.Height = 30;
  1573.     FileSelectBox.ReqText = &LoadingText;
  1574.     FileSelectBox.BackFill = 7;
  1575.     Request(&FileSelectBox, WorkWindow);
  1576.     while((ch = getc(ansiin)) != EOF)
  1577.     {
  1578.     switch(ch)
  1579.     {
  1580.         case ESC :
  1581.         esclength = semicount = 0;
  1582.         do {
  1583.             ch = getc(ansiin);
  1584.             Buffer[esclength] = ch;
  1585.             esclength++;
  1586.             if (ch == ';') ++semicount;
  1587.            } while (ch == '[' || ch == ';' ||
  1588.             (ch >= '0' && ch <= '9'));
  1589.         Buffer[esclength] = NULL;
  1590.         switch(Buffer[esclength-1])
  1591.         {
  1592.             case 'm':
  1593.             if (esclength == 3 && Buffer[1] == '0')
  1594.             {
  1595.                 fcolour = 1; bcolour = 0;
  1596.                 break;
  1597.             }
  1598.             else
  1599.             {
  1600.                 scanplace = 0; endofit = TRUE;
  1601.                 while(endofit)
  1602.                 {
  1603.                 actualnum = numscan(Buffer,&scanplace);
  1604.                 if (actualnum == -1) endofit = FALSE;
  1605.                 switch(actualnum)
  1606.                 {
  1607.                     case 0:
  1608.                     biggerbit = 0;
  1609.                     break;
  1610.                     
  1611.                     case 1:
  1612.                     biggerbit = 1;
  1613.                     break;
  1614.                     
  1615.                     case 30:
  1616.                     if(biggerbit == 1) fcolour = 8;
  1617.                     else fcolour = 0;
  1618.                     break;
  1619.                     
  1620.                     case 31:
  1621.                         if(biggerbit == 1) fcolour = 9;
  1622.                     else fcolour = 1;
  1623.                     break;
  1624.                     
  1625.                     case 32:
  1626.                         if (biggerbit == 1) fcolour = 10;
  1627.                     else fcolour = 2;
  1628.                     break;
  1629.                     
  1630.                     case 33:
  1631.                         if (biggerbit == 1) fcolour = 11;
  1632.                     else fcolour = 3;
  1633.                     break;
  1634.                     
  1635.                     case 34:
  1636.                     if (biggerbit == 1) fcolour = 12;
  1637.                     else fcolour = 4;
  1638.                     break;
  1639.                     
  1640.                     case 35:
  1641.                     if (biggerbit == 1) fcolour = 13;
  1642.                     else fcolour = 5;
  1643.                     break;
  1644.                     
  1645.                     case 36:
  1646.                         if (biggerbit == 1) fcolour = 14;
  1647.                     else fcolour = 6;
  1648.                     break;
  1649.                     
  1650.                     case 37:
  1651.                         if (biggerbit == 1) fcolour = 15;
  1652.                     else fcolour = 7;
  1653.                     break;
  1654.                     
  1655.                     case 40: bcolour = 0; break;
  1656.                     case 41: bcolour = 1; break;
  1657.                     case 42: bcolour = 2; break;
  1658.                     case 43: bcolour = 3; break;
  1659.                     case 44: bcolour = 4; break;
  1660.                     case 45: bcolour = 5; break;
  1661.                     case 46: bcolour = 6; break;
  1662.                     case 47: bcolour = 7; break;
  1663.                 }
  1664.                 }
  1665.             }
  1666.             break;
  1667.  
  1668.             case 'H':
  1669.             if(esclength == 2)
  1670.             {
  1671.                 cx = MINWIDTH; cy = MINHEIGHT;
  1672.             }
  1673.             else if(semicount == 1)
  1674.             {
  1675.                 scanplace = 0;
  1676.                 actualnum = numscan(Buffer,&scanplace);
  1677.                 if (actualnum >= MINHEIGHT && actualnum <=
  1678.                 MAXHEIGHT) cy = actualnum;
  1679.                 actualnum = numscan(Buffer,&scanplace);
  1680.                 if (actualnum >= MINWIDTH && actualnum <=
  1681.                 MAXWIDTH) cx = actualnum;
  1682.             }
  1683.             else if(semicount == 0 && esclength > 2)
  1684.             {
  1685.                 scanplace = 0;
  1686.                 actualnum = numscan(Buffer,&scanplace);
  1687.                 if (actualnum >= MINHEIGHT && actualnum <=
  1688.                 MAXHEIGHT) cy = actualnum;
  1689.                 cx = MINWIDTH;
  1690.             }
  1691.             break;
  1692.             
  1693.             case CURSOR_UP:
  1694.             scanplace = 0;
  1695.             actualnum = numscan(Buffer,&scanplace);
  1696.             if (actualnum == -1) cy--;
  1697.             else cy -= actualnum;
  1698.             if(cy < MINHEIGHT) cy = MINHEIGHT;
  1699.             break;
  1700.  
  1701.             case CURSOR_DOWN:
  1702.             scanplace = 0;
  1703.             actualnum = numscan(Buffer,&scanplace);
  1704.             if (actualnum == -1) cy++;
  1705.             else cy += actualnum;
  1706.             if(cy > MAXHEIGHT) cy = MAXHEIGHT;
  1707.             break;
  1708.  
  1709.             case CURSOR_RIGHT:
  1710.             scanplace = 0;
  1711.             actualnum = numscan(Buffer,&scanplace);
  1712.             if (actualnum == -1) cx++;
  1713.             else cx += actualnum;
  1714.             if(cx > MAXWIDTH) cx = MAXWIDTH;
  1715.             break;
  1716.  
  1717.             case CURSOR_LEFT:
  1718.             scanplace = 0;
  1719.             actualnum = numscan(Buffer,&scanplace);
  1720.             if (actualnum == -1) cx--;
  1721.             else cx -= actualnum;
  1722.             if(cx < MINWIDTH) cx = MINWIDTH;
  1723.             break;
  1724.         }
  1725.         break;
  1726.         
  1727.         case LINEFEED : 
  1728.         cx = MINWIDTH;
  1729.         cy++;
  1730.         if (cy > MAXHEIGHT) cy = MAXHEIGHT;
  1731.         break;
  1732.  
  1733.         default :
  1734.         if (ch < 32 || ch == 127) break;
  1735.         sdlstptr = lastptr;
  1736.         lastptr = (struct ANSI *) malloc(sizeof(struct ANSI));
  1737.         if (lastptr == NULL) break;
  1738.         middle = lastptr;
  1739.         sdlstptr->next = lastptr;
  1740.         lastptr->previous = sdlstptr;
  1741.         lastptr->next = NULL;
  1742.         lastptr->letter = ch;
  1743.         lastptr->x = cx;
  1744.         lastptr->y = cy;
  1745.         lastptr->fcolour = fcolour;
  1746.         lastptr->bcolour = bcolour;
  1747.         cx++;
  1748.         if(cx > MAXWIDTH)
  1749.         {
  1750.             cx = MINWIDTH; cy++;
  1751.             if (cy > MAXHEIGHT) cy=MAXHEIGHT;
  1752.         }
  1753.     }
  1754.     }    
  1755.     fclose(ansiin);
  1756.     EndRequest(&FileSelectBox, WorkWindow);
  1757.     PlayBack();
  1758.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1759.     return(TRUE);
  1760. }
  1761. numscan(str,place)
  1762. char *str;
  1763. int *place;
  1764. {
  1765.     int num, holder;
  1766.     char convert[11];
  1767.     
  1768.     holder = *place;
  1769.     while(str[holder] < '0' || str[holder] > '9')
  1770.     {
  1771.     if(str[holder] == NULL)    return(-1);
  1772.     holder++;
  1773.     }
  1774.     num = atoi(&str[holder]);
  1775.     sprintf(convert,"%d",num);
  1776.     holder += strlen(convert);
  1777.     *place = holder;
  1778.     return(num);
  1779. }
  1780. /************************************************************************
  1781. *                           Save ANSI to disk                           *
  1782. ************************************************************************/
  1783. SaveANSI(savetype)
  1784. BOOL savetype;
  1785. {
  1786.     FILE *ansiout;
  1787.     struct ANSI *behindptr;
  1788.     BOOL Answer;
  1789.     short int bit8;
  1790.     int truefcol, truebcol, linelength, xpos, ypos;
  1791.     char outputstr[41], endofline[41], savetypechr[2];
  1792.     
  1793.     struct IntuiText SavingText =
  1794.     {
  1795.     4,7,JAM2,134,11,NULL,"Saving ANSI to disk.  Please Wait.",NULL
  1796.     };
  1797.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipBlank);
  1798.     if(savetype == TRUE)
  1799.     {
  1800.     savetypechr[0] = 'w';
  1801.     savetypechr[1] = NULL;
  1802.     Answer = MakeFileReq("Save");
  1803.     }
  1804.     else
  1805.     {
  1806.     savetypechr[0] = 'a';
  1807.     savetypechr[1] = NULL;
  1808.     Answer = MakeFileReq("Append Save");
  1809.     }
  1810.     if (Answer == FALSE) 
  1811.     {
  1812.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1813.     return(FALSE);
  1814.     }
  1815.     if (!(ansiout = fopen(FileBuffer,savetypechr)))
  1816.     {
  1817.         GenErrorReq("File can't open for write!");
  1818.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1819.         return(FALSE);
  1820.     }
  1821. /***** Start Saving *****/
  1822.     InitRequester(&FileSelectBox);
  1823.     FileSelectBox.LeftEdge = 50;
  1824.     FileSelectBox.TopEdge = 85;
  1825.     FileSelectBox.Width = 540;
  1826.     FileSelectBox.Height = 30;
  1827.     FileSelectBox.ReqText = &SavingText;
  1828.     FileSelectBox.BackFill = 7;
  1829.     Request(&FileSelectBox, WorkWindow);
  1830.     fprintf(ansiout,"%c[0m%c[H%c[J",ESC,ESC,ESC);
  1831.     linelength = 10;
  1832.     for(lastptr=storage.next; lastptr != NULL; lastptr = lastptr->next)
  1833.     {
  1834.         behindptr = lastptr->previous;
  1835.     xpos = behindptr->x+1; ypos = behindptr->y;
  1836.     if(xpos > MAXWIDTH)
  1837.     {
  1838.         xpos = MINWIDTH;
  1839.         ypos++;
  1840.         if(ypos > MAXHEIGHT) ypos = MAXHEIGHT;
  1841.     }    
  1842. /***** Check for colour changes *****/
  1843.         if((lastptr->fcolour != behindptr->fcolour) ||
  1844.         (lastptr->bcolour != behindptr->bcolour))
  1845.         {
  1846.         truefcol = lastptr->fcolour;
  1847.         truebcol = lastptr->bcolour;
  1848.         if(behindptr->bcolour == lastptr->bcolour)
  1849.         {
  1850.         if(FirstWorkScreen.Depth <= 3 && truefcol < 8)
  1851.             sprintf(outputstr,"%c[3%dm",ESC,truefcol);
  1852.         else
  1853.         {
  1854.                 if(truefcol&8) bit8 = 1; else bit8 = 0;
  1855.                 sprintf(outputstr,"%c[%d;3%dm",ESC,bit8,truefcol&7);
  1856.         }
  1857.         }
  1858.         else if(behindptr->fcolour == lastptr->fcolour)
  1859.         {
  1860.         sprintf(outputstr,"%c[4%dm",ESC,truebcol);
  1861.         }
  1862.         else
  1863.         {
  1864.             if(FirstWorkScreen.Depth <= 3 && truefcol < 8)
  1865.             sprintf(outputstr,"%c[3%d;4%dm",ESC,truefcol,truebcol);
  1866.         else
  1867.         {
  1868.             if(truefcol&8) bit8 = 1; else bit8 = 0;
  1869.                 sprintf(outputstr,"%c[%d;3%d;4%dm",ESC,bit8,truefcol&7,
  1870.             truebcol);
  1871.         }
  1872.         }
  1873.             linelength += strlen(outputstr);
  1874.             if((linelength+1) >= maxlinelength)
  1875.             {
  1876.         sprintf(endofline,"%c%c[%d;%dH",RETURN,ESC,ypos,xpos);
  1877.                 fprintf(ansiout,"%s",endofline);
  1878.                 linelength = strlen(endofline);
  1879.         linelength += strlen(outputstr);
  1880.             }
  1881.             fprintf(ansiout,"%s",outputstr);
  1882.         }
  1883. /***** Check for position changes *****/
  1884.         if((lastptr->x != xpos) || (lastptr->y != ypos))
  1885.         {
  1886.         if(xpos == lastptr->x && ypos > lastptr->y)
  1887.         {
  1888.         if(ypos - lastptr->y == 1)
  1889.             sprintf(outputstr,"%c[A",ESC);
  1890.         else
  1891.             sprintf(outputstr,"%c[%dA",ESC,ypos - lastptr->y);
  1892.         }
  1893.         else if(xpos == lastptr->x && ypos < lastptr->y)
  1894.         {
  1895.         if(lastptr->y - ypos == 1)
  1896.             sprintf(outputstr,"%c[B",ESC);
  1897.         else
  1898.             sprintf(outputstr,"%c[%dB",ESC,lastptr->y - ypos);
  1899.         }
  1900.         else if(xpos < lastptr->x && ypos == lastptr->y)
  1901.         {
  1902.         if(lastptr->x - xpos == 1)
  1903.             sprintf(outputstr,"%c[C",ESC);
  1904.         else
  1905.             sprintf(outputstr,"%c[%dC",ESC,lastptr->x - xpos);
  1906.         }
  1907.         else if(xpos > lastptr->x && ypos == lastptr->y)
  1908.         {
  1909.         if(xpos - lastptr->x == 1)
  1910.             sprintf(outputstr,"%c[D",ESC);
  1911.         else
  1912.             sprintf(outputstr,"%c[%dD",ESC,xpos - lastptr->x);
  1913.         }
  1914.         else
  1915.         sprintf(outputstr,"%c[%d;%dH",ESC,lastptr->y,lastptr->x);
  1916.         linelength += strlen(outputstr);
  1917.         if((linelength+1) >= maxlinelength)
  1918.         {
  1919.         fprintf(ansiout,"%c",RETURN);
  1920.         sprintf(outputstr,"%c[%d;%dH",ESC,lastptr->y,lastptr->x);
  1921.         linelength = strlen(outputstr);
  1922.         }
  1923.         fprintf(ansiout,"%s",outputstr);
  1924.         }
  1925. /***** Print the actual character *****/
  1926.         if((linelength+1) >= maxlinelength)
  1927.         {
  1928.             fprintf(ansiout,"%c",RETURN);
  1929.             sprintf(outputstr,"%c[%d;%dH",ESC,lastptr->y,lastptr->x);
  1930.             fprintf(ansiout,"%s",outputstr);
  1931.             linelength = strlen(outputstr);
  1932.         }
  1933.         fprintf(ansiout,"%c",lastptr->letter);
  1934.         linelength++;
  1935.     }
  1936.     lastptr = sdlstptr->next;
  1937.     fclose(ansiout);
  1938.     changes = FALSE;
  1939.     EndRequest(&FileSelectBox, WorkWindow);
  1940.     ChangeSprite(&WorkScreen->ViewPort,&Cursor,ChipCursor);
  1941.     return(TRUE);
  1942. }
  1943. /************************************************************************
  1944. *                Make File Requester                *
  1945. ************************************************************************/
  1946. MakeFileReq(string)
  1947. char *string;
  1948. {
  1949.     int error, formula;
  1950.     struct Gadget *GadgetPtr;
  1951.     struct IntuiMessage *ReqMess;
  1952.     struct FILEINFO GetFilename;
  1953.     USHORT GadgetID;
  1954.     ULONG MessageClass;
  1955.     BOOL Waiton = TRUE, readdir = TRUE;
  1956.     char names[3000], *pointers[300], *showme;
  1957.     short int count=0;
  1958.     
  1959.     RequesterWindow.LeftEdge = 155;
  1960.     RequesterWindow.TopEdge = 25;
  1961.     RequesterWindow.Width = 330;
  1962.     RequesterWindow.Height = 147;
  1963.     RequesterWindow.Title = (UBYTE *)string;
  1964.     RequesterWindow.Screen = WorkScreen;
  1965.     RequesterWindow.FirstGadget = &OK;
  1966.  
  1967.     for (error=0; error<8; error++)
  1968.     {
  1969.     ReqFiles[error] = FileNameGadget;
  1970.     FileStInfo[error] = GenStrInfo;
  1971.     FileStInfo[error].IText = (UBYTE *)&FileStr[error];
  1972.     ReqFiles[error].TopEdge = 33 + error * 9;
  1973.     ReqFiles[error].GadgetID = 20 + error;
  1974.     ReqFiles[error].GadgetText = &FileStInfo[error];
  1975.     ReqFiles[error].NextGadget = &ReqFiles[error+1];
  1976.     }
  1977.     ReqFiles[7].NextGadget = NULL;
  1978.     
  1979.     if(!(ReqWindow = (struct Window *) OpenWindow(&RequesterWindow)))
  1980.         return(FALSE);
  1981.     if(error = chdir(PathBuffer))
  1982.     GenErrorReq("No directory!");
  1983.     while (Waiton)
  1984.     {
  1985.         if(ReqMess = (struct IntuiMessage *)
  1986.            GetMsg(ReqWindow->UserPort))
  1987.         {
  1988.         MessageClass = ReqMess->Class;
  1989.         GadgetPtr = (struct Gadget *) ReqMess->IAddress;
  1990.         ReplyMsg(ReqMess);
  1991.         GadgetID = GadgetPtr->GadgetID;
  1992.         if (MessageClass == GADGETUP)
  1993.         {
  1994.         if (GadgetID >= 20 && GadgetID <= 27)
  1995.         {
  1996.             if(FileStr[GadgetID-20][0] != '»')
  1997.             {
  1998.             error = strcmp(FileStr[GadgetID-20],FileBuffer);
  1999.             if(error)
  2000.             {
  2001.                 strcpy(FileBuffer,FileStr[GadgetID-20]);
  2002.                 RefreshGList(&File,ReqWindow,NULL,1);
  2003.             }
  2004.             else
  2005.             {
  2006.                 if (ReqWindow)  CloseWindow(ReqWindow);
  2007.                 return(TRUE);
  2008.             }
  2009.             }
  2010.             else
  2011.             {
  2012.             chdir(&FileStr[GadgetID-20][1]);
  2013.             getcd(0,PathBuffer);
  2014.                 readdir = TRUE;
  2015.             count = 0;
  2016.             }
  2017.             RefreshGList(&Path,ReqWindow,NULL,1);
  2018.         }
  2019.         else switch(GadgetID)
  2020.         {
  2021.             case 4:     /* The "Path" Gadget */
  2022.             if(error = chdir(PathBuffer))
  2023.             GenErrorReq("No such directory!");
  2024.             else
  2025.             {
  2026.                 readdir = TRUE;
  2027.             count = 0;
  2028.             }
  2029.             break;
  2030.  
  2031.             case 1:     /* The "Cancel" Gadget */
  2032.             if (ReqWindow)  CloseWindow(ReqWindow);
  2033.             return(FALSE);
  2034.             break;
  2035.             
  2036.             case 2:    /* The "OK" Gadget */
  2037.             Waiton = FALSE;
  2038.             break;
  2039.             
  2040.             case 3:    /* The "File" Gadget */
  2041.             Waiton = FALSE;
  2042.             break;
  2043.  
  2044.             case 5:    /* The "Slider" Gadget */
  2045.             if(count > 8)
  2046.             {
  2047.             formula = SlideInfo.VertPot/(65535/(count-8));
  2048.             showfiles(&pointers[formula],count);
  2049.             }
  2050.             break;
  2051.             
  2052.             case 6:    /* The "Parent" Gadget */
  2053.             chdir("/");
  2054.             getcd(0,PathBuffer);
  2055.             RefreshGList(&Path,ReqWindow,NULL,1);
  2056.             readdir = TRUE;
  2057.             count = 0;
  2058.         }
  2059.         }
  2060.         }
  2061.     if(readdir)
  2062.     {
  2063.         if(count < 1)
  2064.         {
  2065.         showme = &names[0];
  2066.         error = dfind(&GetFilename,"#?",1);
  2067.         if(error == 0)
  2068.         {
  2069.             if(GetFilename.fib_DirEntryType > 0)
  2070.             showme = (char *)stpcpy(showme,"»");
  2071.             showme = (char *)stpcpy(showme,&GetFilename.fib_FileName[0]);
  2072.             showme++;
  2073.             *(showme) = NULL;
  2074.             count = strbpl(pointers,300,names);
  2075.             SlideInfo.VertPot = 0;
  2076.             SlideInfo.VertBody = 65535;
  2077.             showfiles(pointers,count);
  2078.             RefreshGList(&Slide,ReqWindow,NULL,1);
  2079.         }
  2080.         else 
  2081.         {
  2082.             readdir = FALSE;
  2083.             for(error = 0; error < sizeof(names); ++error)
  2084.             names[error] = NULL;
  2085.             count = strbpl(pointers,300,names);
  2086.             showfiles(pointers,count);
  2087.         }
  2088.         }
  2089.         else
  2090.         {
  2091.         error = dnext(&GetFilename);
  2092.         if(error == 0 && (showme+32 < names+sizeof(names)))
  2093.         {
  2094.             if(GetFilename.fib_DirEntryType > 0)
  2095.                 showme = (char *)stpcpy(showme,"»");
  2096.             showme = (char *)stpcpy(showme,&GetFilename.fib_FileName[0]);
  2097.             ++count; ++showme;
  2098.             *(showme) = NULL;
  2099.             count = strbpl(pointers,300,names);
  2100.             if (count > 8)
  2101.             {
  2102.             SlideInfo.VertBody = (65535/count)*8;
  2103.             formula = SlideInfo.VertPot/(65535/(count-8));
  2104.             showfiles(&pointers[formula],count);
  2105.             }
  2106.             else
  2107.             {
  2108.             SlideInfo.VertBody = 65535;
  2109.             showfiles(pointers,count);
  2110.             }
  2111.             RefreshGList(&Slide,ReqWindow,NULL);
  2112.         }
  2113.         else
  2114.         {
  2115.             readdir = FALSE;
  2116.             tqsort(pointers,count);
  2117.             showfiles(pointers,count);
  2118.             SlideInfo.VertPot = 0;
  2119.             RefreshGList(&Slide,ReqWindow,NULL,1);
  2120.         }
  2121.         }
  2122.     }
  2123.     }
  2124.     if (ReqWindow)  CloseWindow(ReqWindow);
  2125.     return(TRUE);
  2126. }
  2127. showfiles(strstuff,max)
  2128. char *strstuff[];
  2129. int max;
  2130. {
  2131.     int i;
  2132.  
  2133.     for(i = 0; i < 8; i++)
  2134.     {
  2135.     sprintf(FileStr[i],"%-30s","                              ");
  2136.     if(i > max)
  2137.     {
  2138.         RefreshGList(&ReqFiles[i],ReqWindow,NULL,1);
  2139.     }
  2140.     else
  2141.     {
  2142.         sprintf(FileStr[i],"%-30s",strstuff[i]);
  2143.         RefreshGList(&ReqFiles[i],ReqWindow,NULL,1);
  2144.         strcpy(FileStr[i],strstuff[i]);
  2145.     }
  2146.     }
  2147.     return(TRUE);
  2148. }