home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / EDSCREEN.ZIP / SCREEN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-05-18  |  28.5 KB  |  928 lines

  1. (*****************************************************************************)
  2. (*                                                                           *)
  3. (*                   F U L L   S C R E E N   E D I T O R                     *)
  4. (*                                                                           *)
  5. (*                           By Martine Wedlake                              *)
  6. (*                                                                           *)
  7. (*       This  programme  may be copied,  or modified in  any way  for non-  *)
  8. (*  commercial uses.  If you would like to use this programme in a business  *)
  9. (*  environment please write  me for licencing,  and so I can keep track of  *)
  10. (*  its success.   If you like this programme a  donation would  be awfully  *)
  11. (*  nice of you.  Thanks!                                                    *)
  12. (*                                Martine Wedlake                            *)
  13. (*                                4551 N.E. Simpson St.                      *)
  14. (*                                Portland Or                                *)
  15. (*                                97218                                      *)
  16. (*                                                                           *)
  17. (*****************************************************************************)
  18.  
  19. program screen;
  20. const
  21.   version='1.5';
  22. type
  23.   str15=string[15];
  24.   string_of_10=STRING[10];                  {These are here because they are}
  25.   string_of_255=STRING[255];                {use in procedure/function }
  26.   string_of_80=STRING[80];
  27.   Character_12_array=ARRAY[1..12] OF CHAR;
  28.   hexword=string[4];
  29. var
  30.   f_screen:file;                            {the input file}
  31.   f_source:text;                            {the output file}
  32.   screen:byte;
  33.   procname:string[100];
  34.   dates:str15;
  35.   key:char;
  36.   direct:boolean;
  37.   background:integer;
  38.  
  39. function hex(v:integer):hexword;
  40.  
  41. const
  42.   map:array[0..15] of char ='0123456789ABCDEF';
  43.  
  44. var
  45.   tmp:hexword;
  46.  
  47. begin
  48.   tmp[4]:=map[(v and $7FFF) mod 16];
  49.   tmp[3]:=map[(v shr 4) mod 16];
  50.   tmp[2]:=map[(v shr 8) mod 16];
  51.   tmp[1]:=map[(v shr 12) mod 16];
  52.   tmp[0]:=#4;
  53.   hex:=tmp;
  54. end;
  55.  
  56. function upstring(str:string_of_255){------returns uppercase strings}
  57.                   :string_of_255;
  58.  
  59. { This will take a string and return it's uppercase counterpart.}
  60.  
  61. var
  62.   temp_str:string_of_255;
  63.   temp:integer;
  64. begin
  65.   temp:=1;                                 {initialize the counter variable}
  66.   temp_str:='';                            {initialize the dummy string}
  67.   for temp:=1 to length(str) do            {loop and set it to upper case}
  68.   temp_str:=temp_str+upcase(copy(str,temp,1));
  69.   upstring:=temp_str;                      {return the correct value}
  70. end;                                       {end of the upstring function}
  71.  
  72. PROCEDURE cursor(on:BOOLEAN);{---------------This sets the cursor on/off}
  73.  
  74. {procedure cursor will set the cursor on or off depending if the argument sent
  75.  is true or false.  If the argument is false the cursor will be turned off,
  76.  if the argument is true the cursor is the cursor is turned on.}
  77.  
  78. CONST
  79.   video_io=$10;                             {this is the interrupt number}
  80. VAR
  81.   regs:RECORD CASE INTEGER OF               {this sets up the registers}
  82.                 1: (AX,BX,CX,DX,BP,DI,SI,DS,ES,Flags: INTEGER);
  83.                 2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  84.               END;
  85. BEGIN
  86.   IF on THEN                                {if the user wants a cursor then}
  87.   BEGIN
  88.     regs.ch:=$06;                           {set the registers up for display}
  89.     regs.cl:=$07;                           {ch = start line, cl = end line}
  90.   END
  91.   ELSE                                      {else, the cursor is not displayed}
  92.   BEGIN
  93.     regs.ch:=$20;                           {set the register up for non-}
  94.     regs.cl:=$00;                           {display, ch=$20 doesn't display}
  95.   END;
  96.   regs.ah:=$01;
  97.   regs.al:=$00;
  98.   Intr(video_io,regs);
  99. END;
  100.  
  101. procedure center(stringy:string_of_80);{-----this centers a line of text}
  102.  
  103. { Centers a line of text at the present Y co-ordinate.}
  104.  
  105. var
  106.   endpos:integer;
  107. begin
  108.   gotoxy(40-length(stringy) div 2,wherey);  {goto position}
  109.   write(stringy);                           {write string}
  110. end;                                        {end of center procedure}
  111.  
  112. PROCEDURE Dir(msk:character_12_array);{------this prints a directory out}
  113.  
  114. { Dir returns the directory of the default disk drive.  To use you must
  115.   call dir(mask)  where mask is a string of 12 characters to look for.  You
  116.   must have all 12 characters for this to work.  If you want a directory of
  117.   the whole disk use '????????.???' for input. }
  118.  
  119. TYPE
  120.   String20= STRING[ 20 ];
  121.   RegRec=RECORD                             {set up the registers}
  122.            AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : INTEGER;
  123.          END;                               {end of regrec}
  124. VAR
  125.   Regs : RegRec;                            {the registers}
  126.   DTA  : ARRAY [ 1..43 ] OF Byte;
  127.   Mask : Character_12_array;                {The mask used for lookup}
  128.   NamR : String20;                          {resulting filename}
  129.   Error,                                    {errors that may occur}
  130.   I    : INTEGER;                           {counter}
  131. BEGIN                                       {main body of program DirList}
  132.   FillChar(DTA,SIZEOF(DTA),0);              {Initialize the DTA buffer}
  133.   FillChar(Mask,SIZEOF(Mask),0);            {Initialize the mask}
  134.   FillChar(NamR,SIZEOF(NamR),0);            {Initialize the file name}
  135.   Regs.AX := $1A00;                         {Function used to set the DTA}
  136.   Regs.DS := Seg(DTA);                      {store the parameter segment in DS}
  137.   Regs.DX := Ofs(DTA);                      {  "    "      "     offset in DX}
  138.   MSDos(Regs);                              {Set DTA location}
  139.   Error := 0;                               {no error at start}
  140.   mask:=msk;                                {Mask must be initialized here}
  141.   Regs.AX := $4E00;                         {Get first directory entry}
  142.   Regs.DS := Seg(Mask);                     {Point to the file Mask}
  143.   Regs.DX := Ofs(Mask);                     {Points the offset of mask}
  144.   Regs.CX := 22;                            {Store the option}
  145.   MSDos(Regs);                              {Execute MSDos call}
  146.   Error := Regs.AX AND $FF;                 {Get Error return}
  147.   I := 1;                                   {initialize 'I' to the 1st element}
  148.   IF (Error = 0) THEN                       {if no error then...}
  149.     REPEAT                                  {repeat until invalid chars}
  150.       NamR[I] := CHR(Mem[Seg(DTA):Ofs(DTA)+29+I]);{get character of filename}
  151.       I := I + 1;                           {increment pointer}
  152.     UNTIL NOT (NamR[I-1] IN [' '..'~']) OR (I>20);{check validity}
  153.   NamR[0] := CHR(I-1);                      {set string length because}
  154.   WRITE(namR:20);
  155.   WHILE (Error = 0) DO BEGIN                {assigning by element does not set}
  156.     Error := 0;                             {length}
  157.     Regs.AX := $4F00;                       {Function used to get the next}
  158.                                             {directory entry}
  159.     Regs.CX := 22;                          {Set the file option}
  160.     MSDos( Regs );                          {Call MSDos}
  161.     Error := Regs.AX AND $FF;               {get the Error return}
  162.     I := 1;                                 {intialize pointer}
  163.     REPEAT                                  {repeat until not valid chars}
  164.       NamR[I] := CHR(Mem[Seg(DTA):Ofs(DTA)+29+I]);{get character of filename}
  165.       I := I + 1;                           {increment pointer}
  166.     UNTIL NOT (NamR[I-1] IN [' '..'~'] ) OR (I > 20);{check validity}
  167.     NamR[0] := CHR(I-1);
  168.     IF (Error = 0)                          {if no error found}
  169.       THEN WRITE(NamR:20)                   {write filename}
  170.   END;
  171.   IF WhereX<>1 THEN WRITELN;
  172. END;                                        {of program DirList  }
  173.  
  174. procedure border(x,y,x2,y2,forg,{------------This makes a lined border}
  175.                  back:integer;
  176.                  double:boolean);
  177.  
  178. { Border will put a double or single lined border by specifying the top left
  179.   and bottom left co-ordinates for the border.  x,y is the co-ordinate of the
  180.   top left.  x2,y2 is the co-ordinate of the bottom right.  Forg is the
  181.   forground colour, while Back is the background colour.  If double is true
  182.   the border will be a double line.  If it is false, then it will be a single
  183.   line border.}
  184.  
  185. var
  186.   old_x,
  187.   old_y,
  188.   loop:integer;
  189.   top_left,
  190.   top_right,
  191.   bot_left,
  192.   bot_right,
  193.   accross,
  194.   down:char;
  195. BEGIN
  196.   if (x2<x) or (y2<y) or (y>24) or (x>80)   {check to see that parameters valid}
  197.             or (y<1) or (x<1) then
  198.   begin                                     {if not valid then write error}
  199.     clrscr;
  200.     textcolor(white);
  201.     textbackground(black);
  202.     writeln('ERROR in procedure boarder.  Co-ordanates incorrect.');
  203.     halt;
  204.   end;
  205.   old_x:=wherex;                            {remember x,y of currsor}
  206.   old_y:=wherey;
  207.   TextColor(forg);                          {set the colours to be used}
  208.   textbackground(back);
  209.   if double then                            {assign the various characters for}
  210.   begin                                     {corners, vertical, and horizontal}
  211.     top_left:=#201;                         {lines}
  212.     top_right:=#187;
  213.     bot_left:=#200;
  214.     bot_right:=#188;
  215.     accross:=#205;
  216.     down:=#186;
  217.   end
  218.   else
  219.   begin                                     {For single lines}
  220.     top_left:=#218;
  221.     top_right:=#191;
  222.     bot_left:=#192;
  223.     bot_right:=#217;
  224.     accross:=#196;
  225.     down:=#179;
  226.   end;
  227.   gotoxy(x,y);
  228.   WRITE(top_left);                          {output the corner pieces}
  229.   gotoxy(x2,y);
  230.   WRITELN(top_right);
  231.   gotoxy(x,y2);
  232.   WRITE(bot_left);
  233.   gotoxy(x2,y2);
  234.   WRITE(bot_right);
  235.   FOR loop:=x+1 TO x2-1 DO                 {loop for the horz. line}
  236.   begin
  237.     gotoxy(loop,y);
  238.     WRITE(accross);
  239.     gotoxy(loop,y2);
  240.     write(accross);
  241.   end;
  242.   for loop:=y+1 to y2-1 do                  {loop for the vert. lines}
  243.   begin
  244.     gotoxy(x,loop);
  245.     WRITE(down);
  246.     gotoxy(x2,loop);
  247.     write(down);
  248.   end;
  249.   gotoxy(old_x,old_y);                      {restore cursor pos}
  250.   textcolor(white);                         {set colour to "normal"}
  251.   textbackground(black);
  252. END;
  253.  
  254. PROCEDURE title(title1:string_of_80);{-------this prints out the title}
  255.  
  256. { Title prints out a nice title with the title automatically centered
  257.   on the screen and with a border around it.  Use title(name)  where the
  258.   title you want to print is name.  Name must be a string.  It can be any
  259.   length. }
  260.  
  261. VAR
  262.   loop,                                     {a loop counter}
  263.   string_length,                            {the length of the title string}
  264.   x_position:INTEGER;                       {the position for centering title}
  265. BEGIN
  266.   ClrScr;
  267.   GotoXY(1,3);
  268.   TextColor(white);                         {title is in white}
  269.   Center(title1);                           {write title out}
  270.   string_length:=LENGTH(title1);            {assigns the length of title}
  271.   x_position:=40-(string_length DIV 2)-1;
  272.   border(x_position,2,x_position+string_length+1,
  273.          4,lightblue,black,true);
  274.   TextColor(lightblue);                     {frame is lightblue}
  275.   gotoxy(1,6);
  276. END;
  277.  
  278. FUNCTION date:string_of_10;{-----------------returns the date in the system}
  279.  
  280. {  Date returns a string composing of the date.  To use code
  281.    Date_now:=date;  The date is return in the format of mm-dd-yy.}
  282.  
  283. PROCEDURE zerofill(VAR sample:string_of_10);{replaces spaces with 0's}
  284. VAR
  285.   I:INTEGER;                                {i is just a counter}
  286. BEGIN
  287.   FOR i:=1 TO LENGTH(sample) DO IF sample[i]=' ' THEN sample[i]:='0';
  288. END;
  289.  
  290. VAR
  291.   DateString:string_of_10;                  {the string of date}
  292.   month,                                    {the various time frames}
  293.   day,
  294.   year:STRING[2];
  295.   regs:RECORD CASE INTEGER OF               {this sets up the registers}
  296.                 1: (AX,BX,CX,DX,BP,DI,SI,DS,ES,Flags: INTEGER);
  297.                 2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  298.               END;
  299. BEGIN
  300. WITH regs DO                                {use the defined registers}
  301.  BEGIN
  302.    AH:=$2A;                                 {pass 2Ah through AH}
  303.    Flags:=0;                                {reset flags}
  304.    MSDos(Regs);                             {call interrupt 21h}
  305.    STR((CX MOD 100):2,year);                {do convertions for year}
  306.    STR(DL:2,Day);                           {"      "        "  day }
  307.    STR(DH:2,Month);                         {"      "        "  month}
  308.    DateString:=month+'-'+day+'-'+Year;      {put the date together}
  309.    zerofill(DateString);                    {fill in any spaces}
  310.    date:=datestring                         {pass date to function call}
  311.  END                                        {end of with regs}
  312. END;                                        {end of date function}
  313.  
  314.  
  315. PROCEDURE waitkey;{--------------------------Press any key to continue proc.}
  316.  
  317. { This is a very simple but useful procedure to wait for a keypress to
  318.   continue with the program.}
  319.  
  320. VAR
  321.   key:CHAR;
  322. BEGIN
  323.   cursor(FALSE);                            {turn cursor off}
  324.   GotoXY(1,25);                             {set colour and position}
  325.   TextColor(black);
  326.   TextBackGround(white);
  327.   center('Press any key to continue with program.');{write message}
  328.   REPEAT UNTIL KeyPressed;                  {wait for key}
  329.   READ(Kbd,key);                            {store the key so it won't}
  330.   GotoXY(1,25);                             {screw up the next read(kbd)}
  331.   TextColor(white);                         {restore colour}
  332.   TextBackGround(black);
  333.   DelLine;                                  {erase message}
  334.   cursor(TRUE);                             {restore cursor}
  335. END;                                        {end of the waitkey procedure}
  336.  
  337.  
  338. procedure video(cond:boolean);{--------------Turns on or off the display}
  339.  
  340. { This will turn the display on or off.  You can still write to the screen
  341.   but the text will not be seen until you set video(on).  I have set up two
  342.   constants for this procedure -- On=True, Off=false.  You can use these
  343.   constants instead of true/false. NOTE: Some turbo instuctions will auto-
  344.   matically set the video as on.  Some are ClrScr, TextMode, etc}
  345.  
  346. begin
  347.   repeat until port[$3da] and 8=8;          {wait for video sync}
  348.   if cond then
  349.     port[$3d8]:=mem[$40:$65] or 8           {restore display}
  350.   else
  351.     port[$3d8]:=$25;                        {turn off display by setting regs}
  352. end;                                        {end of video procedure}
  353.  
  354. procedure readatt(x,y:integer;{--------------Reads in the char/attribute of screen}
  355.                   var forg,back:integer;
  356.                   var chrr:char);
  357. var
  358.   regs:RECORD CASE INTEGER OF               {this sets up the registers}
  359.                 1: (AX,BX,CX,DX,BP,DI,SI,DS,ES,Flags: INTEGER);
  360.                 2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  361.               END;
  362.   old_x,
  363.   old_y,
  364.   chrs:integer;
  365.   blink:boolean;
  366.  
  367. begin
  368.   old_x:=wherex;                            {save old cursor pos to restore}
  369.   old_y:=wherey;
  370.   gotoxy(x,y);                              {set cursor, for bios routine}
  371.   with regs do
  372.   begin
  373.     ah:=$08;                                {set function, read char/attribute}
  374.     bh:=$00;                                {page = 0}
  375.     intr($10,regs);
  376.     chrr:=chr(al);                          {al is the character}
  377.     forg:=ah and 15;                        {take out the forground}
  378.     if ah and 128=128 then forg:=forg or 16; {is the blinking on, if so set bit}
  379.     back:=(ah and 112) shr 4;               {take out background and shift right}
  380.   end;
  381.   gotoxy(old_x,old_y);                      {restore cursor position}
  382. end;                                        {end of readatt procedure}
  383.  
  384. function exist(filename:string_of_255){------tests if a file exists}
  385.                :boolean;
  386.  
  387. { This routine will check to see if a file exists or not.}
  388.  
  389. var
  390.   f_test:file;
  391.  
  392. begin
  393.   assign(f_test,filename);
  394.   {$I-}
  395.   reset(f_test);
  396.   {$I+}
  397.   exist:=(ioresult = 0);
  398.   close(f_test);
  399. end;                                        {End of function exist}
  400.  
  401. function quit_yn:boolean;
  402. begin
  403.   clrscr;
  404.   gotoxy(22,12);
  405.   write('Do you want to exit the program? Y/N ');
  406.   repeat
  407.     read(kbd,key);
  408.     key:=upcase(key);
  409.   until key in['Y','N'];
  410.   quit_yn:=key='Y';
  411. end;
  412.  
  413. procedure quit;
  414. begin
  415.   title(' E X I T ');
  416.   gotoxy(1,6);
  417.   {$I-}
  418.   close(f_source);
  419.   {$i+}
  420.   if ioresult<>0 then ;
  421.   textcolor(lightgray);
  422.   halt;
  423. end;
  424.  
  425. procedure error(err_num:integer);
  426. var
  427.   key:char;
  428. begin
  429.   case err_num of
  430.     1:begin
  431.         gotoxy(1,24);
  432.         textcolor(black);
  433.         textbackground(white);
  434.         center(#7+'ERROR - File does not exist!  Please Re-enter.');
  435.         textcolor(white);
  436.         textbackground(black);
  437.         waitkey;
  438.         gotoxy(1,24);
  439.         clreol;
  440.       end;
  441.   end;
  442. end;
  443.  
  444. function colr(colr_num:integer):str15;
  445. var
  446.   blink:boolean;
  447.   colrs:str15;
  448. begin
  449.   if colr_num >= 16 then
  450.   begin
  451.     blink:=true;
  452.     colr_num:=colr_num - 16;
  453.   end
  454.   else
  455.     blink:=false;
  456.   case colr_num of
  457.     0 :colrs:='Black';
  458.     1 :colrs:='Blue';
  459.     2 :colrs:='Green';
  460.     3 :colrs:='Cyan';
  461.     4 :colrs:='Red';
  462.     5 :colrs:='Magenta';
  463.     6 :colrs:='Brown';
  464.     7 :colrs:='LightGray';
  465.     8 :colrs:='DarkGray';
  466.     9 :colrs:='LightBlue';
  467.     10:colrs:='LightGreen';
  468.     11:colrs:='LightCyan';
  469.     12:colrs:='LightRed';
  470.     13:colrs:='LightMagenta';
  471.     14:colrs:='Yellow';
  472.     15:colrs:='White';
  473.   end;
  474.   if blink then colrs:=colrs+'+Blink';
  475.   colr:=colrs;
  476. end;
  477.  
  478. PROCEDURE TitleScreen;
  479. var
  480.   counter:integer;
  481.   key:char;
  482. BEGIN
  483.   TextColor(LightGray);
  484.   TextBackground(Black);
  485.   ClrScr;
  486.   video(false);
  487.   gotoxy(19,1);
  488.   TextColor(White);
  489.   TextBackground(Cyan);
  490.   Writeln('┌────────────────────────────────────────┐');
  491.   gotoxy(19,2);
  492.   TextColor(White);
  493.   TextBackground(Cyan);
  494.   Write('│');
  495.   TextColor(LightGray);
  496.   TextBackground(Blue);
  497.   Write(' ╔═══╕   ╔══╕  ╔══╗  ╔══╕  ╔══╕  ╔╗  ╥  ');
  498.   TextColor(White);
  499.   TextBackground(Cyan);
  500.   Writeln('│');
  501.   gotoxy(19,3);
  502.   TextColor(White);
  503.   TextBackground(Cyan);
  504.   Write('│');
  505.   TextColor(LightGray);
  506.   TextBackground(Blue);
  507.   Write(' ╚═══╗   ║     ║  ║  ║     ║     ║╚╗ ║  ');
  508.   TextColor(White);
  509.   TextBackground(Cyan);
  510.   Writeln('│');
  511.   gotoxy(19,4);
  512.   TextColor(White);
  513.   TextBackground(Cyan);
  514.   Write('│');
  515.   TextColor(LightGray);
  516.   TextBackground(Blue);
  517.   Write('     ║   ║     ╠═╦╝  ╠╡    ╠╡    ║ ╚╗║  ');
  518.   TextColor(White);
  519.   TextBackground(Cyan);
  520.   Writeln('│');
  521.   gotoxy(19,5);
  522.   TextColor(White);
  523.   TextBackground(Cyan);
  524.   Write('│');
  525.   TextColor(LightGray);
  526.   TextBackground(Blue);
  527.   Write(' ╘═══╝   ╚══╛  ╨ ╚╕  ╚══╛  ╚══╛  ╨  ╚╝  ');
  528.   TextColor(White);
  529.   TextBackground(Cyan);
  530.   Writeln('│');
  531.   gotoxy(19,6);
  532.   TextColor(White);
  533.   TextBackground(Cyan);
  534.   Write('│');
  535.   TextColor(LightGray);
  536.   TextBackground(Blue);
  537.   Write(' ╥   ╥   ╔══╗  ╒╦╕  ╒══╦══╕  ╔══╕  ╔══╗ ');
  538.   TextColor(White);
  539.   TextBackground(Cyan);
  540.   Write('│');
  541.   gotoxy(19,7);
  542.   TextColor(White);
  543.   TextBackground(Cyan);
  544.   Write('│');
  545.   TextColor(LightGray);
  546.   TextBackground(Blue);
  547.   Write(' ║   ║   ║  ║   ║      ║     ║     ║  ║ ');
  548.   TextColor(White);
  549.   TextBackground(Cyan);
  550.   Write('│');
  551.   gotoxy(19,8);
  552.   TextColor(White);
  553.   TextBackground(Cyan);
  554.   Write('│');
  555.   TextColor(LightGray);
  556.   TextBackground(Blue);
  557.   Write(' ║╔╧╗║   ╠═╦╝   ║      ║     ╠╡    ╠═╦╝ ');
  558.   TextColor(White);
  559.   TextBackground(Cyan);
  560.   Write('│');
  561.   gotoxy(19,9);
  562.   TextColor(White);
  563.   TextBackground(Cyan);
  564.   Write('│');
  565.   TextColor(LightGray);
  566.   TextBackground(Blue);
  567.   Write(' ╚╝ ╚╝   ╨ ╚╕  ╘╩╛    ─╨─    ╚══╛  ╨ ╚╕ ');
  568.   TextColor(White);
  569.   TextBackground(Cyan);
  570.   Write('│');
  571.   gotoxy(19,10);
  572.   TextColor(White);
  573.   TextBackground(Cyan);
  574.   Writeln('└────────────────────────────────────────┘');
  575.   video(true);
  576.   TextColor(LightGray);
  577.   TextBackground(Black);
  578.   gotoxy(27,12);
  579.   Write('S O U R C E   W R I T E R');
  580.   gotoxy(29,14);
  581.   Writeln('By Martine B. Wedlake');
  582.   Writeln;
  583.   Writeln('':7,'The author wishes to note that this programme may be freely copied');
  584.   Writeln('':7,'and distributed as long as there are no costs imposed for the copy');
  585.   Writeln('':7,'other than prices  for the media itself.  If anyone has any querys');
  586.   Writeln('':7,'he can reach me at:');
  587.   Writeln('':28,'Martine Wedlake');
  588.   Writeln('':28,'4551 N.E. Portland, OR');
  589.   Writeln('':28,'97218');
  590.   writeln;
  591.   Writeln('':21,'(C) Copywrite 1987, Martine B. Wedlake');
  592.   write('':30,'<<< Press a Key >>>');
  593.   counter:=0;
  594.   repeat
  595.     counter:=counter+1;
  596.   until keypressed or (counter=30000);
  597.   if keypressed then read(kbd,key);
  598.   clrscr;
  599. END;
  600.  
  601. procedure filenames;         {This procedure gets and opens the files}
  602. var
  603.   fil1,
  604.   fil2:string[12];
  605.   ok:boolean;
  606.   key:char;
  607. begin
  608.   repeat
  609.     title(' S C R E E N   W R I T E R ');
  610.     gotoxy(1,6);
  611.     center('Version: '+version);
  612.     fil1:='';
  613.     gotoxy(1,8);
  614.     center('Use <DIR> for directory, or <CR> to exit.');
  615.     gotoxy(1,10);
  616.     write('Enter file name to read in from ScrEdit :');
  617.     clreol;
  618.     readln(fil1);
  619.     if fil1='' then quit;                   {Check to see if user quits}
  620.     fil1:=upstring(fil1);
  621.     if fil1 ='DIR' then
  622.     begin
  623.       title(' D I R E C T O R Y ');
  624.       gotoxy(1,6);
  625.       dir('????????.SCR');
  626.       fil1:=#255;
  627.       waitkey;
  628.     end
  629.      else
  630.     begin
  631.       if pos('.',fil1) = 0 then fil1:=fil1+'.SCR';  {add on extention}
  632.       gotoxy(42,10);
  633.       write(fil1);
  634.       if not exist(fil1) then error(1);           {give error if not on disk}
  635.     end;
  636.   until exist(fil1);
  637.   assign(f_screen,fil1);
  638.   reset(f_screen);
  639.   repeat
  640.     fil2:='';
  641.     gotoxy(1,12);
  642.     write('Enter file name to output the source to :');
  643.     clreol;
  644.     readln(fil2);
  645.     if fil2='' then quit;
  646.     fil2:=upstring(fil2);
  647.     if fil2 ='DIR' then
  648.     begin
  649.       title(' D I R E C T O R Y ');
  650.       gotoxy(1,6);
  651.       dir('????????.PAS');
  652.       waitkey;
  653.       title(' S C R E E N   W R I T E R ');
  654.       gotoxy(1,6);
  655.       center('Version: '+version);
  656.       gotoxy(1,8);
  657.       center('Use <DIR> for directory, or <CR> to exit.');
  658.       gotoxy(1,10);
  659.       write('Enter file name to read in from ScrEdit :',fil1);
  660.       gotoxy(1,12);
  661.       write('Enter file name to output the source to :');
  662.       ok:=false;
  663.     end
  664.      else
  665.     begin
  666.       if pos('.',fil2) = 0 then fil2:=fil2+'.PAS';     {add extention}
  667.       gotoxy(42,12);
  668.       write(fil2);
  669.       if exist(fil2) then        {check to make sure user wants to overwrite}
  670.       begin
  671.         gotoxy(1,24);
  672.         center('File Already exists!  Press <O> Overwrite, <R> Re-enter, <E> Exit');
  673.         repeat
  674.           read(kbd,key);
  675.           key:=upcase(key);
  676.         until key in['O','R','E'];
  677.         gotoxy(1,24);
  678.         clreol;
  679.         if key='E' then quit;
  680.         ok:=(key = 'O');
  681.       end
  682.       else ok:=true;
  683.     end;
  684.   until ok;
  685.   assign(f_source,fil2);
  686.   rewrite(f_source);
  687.   gotoxy(1,14);
  688.   write('Please enter todays date: ',date,#8#8#8#8#8#8#8#8); {write sytem date}
  689.   readln(dates);
  690.   if dates='' then dates:=date;
  691.   gotoxy(1,16);
  692.   write('Please enter the name of your procedure: TitleScreen');
  693.   gotoxy(42,16);
  694.   repeat until keypressed;
  695.   clreol;
  696.   procname:='';
  697.   read(procname);
  698.   if procname='' then procname:='TitleScreen';
  699.   gotoxy(42,16);
  700.   write(procname);
  701.   gotoxy(1,18);
  702.   write('Do you want [D]irect Screen Writing, or [S]ource Code [D/S]? ');
  703.   repeat
  704.     read(kbd,key);
  705.     key:=upcase(key);
  706.   until key in['D','S'];
  707.   direct:=(key='D');
  708. end;
  709.  
  710. function find_prominent:integer;
  711. var
  712.   lett:char;
  713.   colours:array[0..7] of integer;
  714.   forg,
  715.   back,
  716.   x,
  717.   y,
  718.   max:integer;
  719. begin
  720.   for x:=0 to 7 do colours[x]:=0;
  721.   for x:=1 to 80 do
  722.   begin
  723.     for y:=1 to 24 do
  724.     begin
  725.       readatt(x,y,forg,back,lett);
  726.       colours[back]:=colours[back]+1;
  727.     end;
  728.   end;
  729.   max:=0;
  730.   for x:=0 to 7 do if colours[x]>max then max:=colours[x];
  731.   x:=0;
  732.   while colours[x]<>max do x:=x+1;
  733.   find_prominent:=x;
  734. end;
  735.  
  736. procedure do_source_header;    {THis will put the procedure header on file}
  737. begin
  738.   writeln(f_source,'PROCEDURE ',Procname,';');
  739.   writeln(f_source,'BEGIN');
  740.   writeln(f_source,'  {This screen was done with the aid of the Screen Writer program}');
  741.   writeln(f_source,'  {Date: ',dates,'}');
  742.   writeln(f_source,'  TextColor(LightGray);');
  743.   writeln(f_source,'  TextBackground(',colr(background),');');
  744.   writeln(f_source,'  ClrScr;');
  745. end;
  746.  
  747. procedure load;          {THis loads in the picture file}
  748. var
  749.   counter:integer;
  750.   scrn_mem:array[0..1920] of integer;
  751. begin
  752.   reset(f_screen);
  753.   blockread(f_screen,scrn_mem,30);
  754.   close(f_screen);
  755.   for counter:=0 to 1919 do memw[$B800:counter*2]:=scrn_mem[counter];
  756. end;
  757.  
  758. procedure start_line(ln:boolean);
  759. begin
  760.   write(f_source,'  Write');
  761.   if ln then write(f_source,'ln');
  762.   write(f_source,'(''');
  763. end;
  764.  
  765. procedure end_line;
  766. begin
  767.   writeln(f_source,''');');
  768. end;
  769.  
  770. procedure do_textcolor(forg:integer);
  771. begin
  772.   writeln(f_source,'  TextColor(',colr(forg),');');
  773. end;
  774.  
  775. procedure do_textbackground(back:integer);
  776. begin
  777.   writeln(f_source,'  TextBackground(',colr(back),');');
  778. end;
  779.  
  780. function sol(background,y:integer):integer;
  781. var
  782.   counter,
  783.   forground,
  784.   colour:integer;
  785.   letter:char;
  786. begin
  787.   counter:=0;
  788.   repeat
  789.     counter:=counter+1;
  790.     readatt(counter,y,forground,colour,letter);
  791.   until (colour <> background) or (letter <> ' ') or (counter = 80);
  792.   sol:=counter;
  793. end;
  794.  
  795. function eol(background,y:integer):integer;
  796. var
  797.   counter,
  798.   forground,
  799.   colour:integer;
  800.   letter:char;
  801. begin
  802.   counter:=80;
  803.   repeat
  804.     counter:=counter-1;
  805.     readatt(counter,y,forground,colour,letter);
  806.   until (colour <> background) or (letter <> ' ') or (counter = 1);
  807.   eol:=counter;
  808. end;
  809.  
  810. procedure do_source1;               {THis will create source code }
  811. var
  812.   old_forg,
  813.   old_back,
  814.   forg,
  815.   back,
  816.   x,y:integer;
  817.   character:char;
  818. begin
  819.   readatt(1,1,old_forg,old_back,character);   {set up origional colours}
  820.   do_textcolor(old_forg);
  821.   do_textbackground(old_back);
  822.   start_line(true);
  823.   for y:= 1 to 24 do
  824.   begin
  825.     for x:=sol(old_back,y) to eol(old_back,y) do
  826.     begin
  827.       gotoxy(1,y);
  828.       readatt(x,y,forg,back,character);
  829.       if (forg<>old_forg) or (back<>old_back) then
  830.       begin
  831.         end_line;
  832.         if forg<>old_forg then
  833.         begin
  834.           do_textcolor(forg);
  835.           old_forg:=forg;
  836.         end;
  837.         if back<>old_back then
  838.         begin
  839.           do_textbackground(back);
  840.           old_back:=back;
  841.         end;
  842.         start_line(false);
  843.         case character of
  844.           #39:write(f_source,#39#39);
  845.           #26:write(f_source,''',#26,''');
  846.           else write(f_source,character);
  847.         end;
  848.       end
  849.       else
  850.       begin
  851.         case character of
  852.           #39:write(f_source,#39#39);
  853.           #26:write(f_source,''',#26,''');
  854.           else write(f_source,character);
  855.         end;
  856.       end;
  857.     end;
  858.     end_line;
  859.     if y<>24 then
  860.       start_line(true);
  861.       end;
  862.   writeln(f_source,'END;');
  863. end;
  864.  
  865. procedure do_source2;          {THis is the direct screen write method}
  866. var
  867.   forg,
  868.   back,
  869.   screen_mem,
  870.   value,
  871.   x,
  872.   y:integer;
  873.   let:char;
  874.   cr:boolean;
  875. begin
  876.   x:=1;
  877.   y:=1;
  878.   cr:=false;
  879.   for screen_mem:=0 to 1919 do     {loop through the screen}
  880.   begin
  881.     gotoxy(x,y);
  882.     value:=memw[$b800:screen_mem*2];      {get value}
  883.     readatt(x,y,forg,back,let);           {just for cursor and background}
  884.     if not ((let=' ') and (back=background)) then  {try to get rid of useless chars}
  885.     begin
  886.       write(f_source,'  MemW[$b800:$',hex(screen_mem*2),']:=$',hex(value),';');
  887.       if cr then writeln(f_source);
  888.       cr:=not cr
  889.     end;
  890.     x:=x+1;
  891.     if x>80 then
  892.     begin
  893.       x:=1;
  894.       y:=y+1;
  895.     end;
  896.   end;
  897.   {$i-}
  898.   if cr then writeln(f_source);
  899.   writeln(f_source,'END;');
  900.   {$i+}
  901.   if ioresult<>0 then
  902.   begin
  903.     clrscr;
  904.     write(ioresult);
  905.     halt;
  906.   end;
  907. end;
  908.  
  909. begin
  910.   titlescreen;
  911.   repeat
  912.     filenames;
  913.     cursor(false);
  914.     load;
  915.     background:=find_prominent;
  916.     do_source_header;
  917.     cursor(true);
  918.     gotoxy(1,1);
  919.     if not direct then
  920.       do_source1
  921.     else
  922.       do_source2;
  923.     close(f_source);
  924.     waitkey;
  925.   until quit_yn;
  926.   title(' E N D   O F   T H E   P R O G R A M ');
  927.   textcolor(lightgray);
  928. end.