home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / bbs / picsuncr.arc / PICSUNCR.PAS < prev    next >
Pascal/Delphi Source File  |  1991-08-11  |  10KB  |  337 lines

  1. { PICSUNCR.PAS vers 1.0  06mar88
  2.   by W. Brimhall  Z-Node 52  (602)996-8739
  3.  
  4.   This program adds Uncrunch support to a modified CP/M 80 PICS vers
  5.   1.6 system.
  6.  
  7.   To install make sure your .MCH, .MDM & .CLK file names match the
  8.   ones below then compile this program with the cHn option using the
  9.   same Start & End addresses as the main PICS program. The resulting
  10.   PICSUNCR.CHN file must then be placed in the same file area with
  11.   PICS.COM. The main PICS program must also be re-compiled with the
  12.   new uncrunch support files.
  13.  
  14.   The main PICS program passes parameters to PICSUNCR in these global
  15.   variables:
  16.  
  17.       name          type          desc
  18.       =========     ============  ==================================
  19.       in_library    boolean       true if library file open
  20.       libr_file     untyped file  file to uncrunch if in_library
  21.       XfrFile       untyped file  file to uncrunch if not in_library
  22.       SetDrv        integer       file area Drive
  23.       SetUsr        integer       file area User
  24.       HomDrv        integer       PICS.COM Drive
  25.       HomUsr        integer       PICS.COM User
  26.       remote_online boolean       true if online with remote system
  27.       local_online  boolean       true if online with local console
  28.       usr_rec       record        User data
  29.  
  30.   The file will be open and ready to access once the correct file area
  31.   is selected. If it is a LBR file it will be positioned to the record
  32.   containing the selected file member.
  33.  
  34.   The file is uncrunched and typed using UNCREL by Steven Greenberg. The
  35.   main PICS.COM program is then re-executed.  This chained file scheme was
  36.   necessary because of the 24k buffer needed for UNCREL to operate.
  37.  
  38.   The main PICS program requires these modifications:
  39.    1) It must chain to PICSUNCR.CHN when a crunched file is specified
  40.       for the <T>ype command.
  41.    2) It must preserve the heap during the chain & execute.
  42.    3) It must go directly into file mode when it is executed by Turbo
  43.       Pascal instead of CP/M.
  44. }
  45.  
  46. program picsuncr;
  47. {$C-}
  48.  
  49. {*****************************************}
  50. {* Global variables shared with PICS.COM *}
  51. {*****************************************}
  52.  
  53.   {$I PICSDEF.INC}    { PICS definitions }
  54.   {$I PICSTYPE.INC}   { PICS Type statements }
  55.   {$I PICSVAR.INC}    { PICS Variables }
  56.   {$I picsvar1.unc}   { New file with global uncrunch variables }
  57.  
  58. {***************************************}
  59. {* Variables used by PICSUNCR.CHN only *}
  60. {***************************************}
  61.  
  62.   var
  63.     fbyte: byte;
  64.     x, BufferPtr, curin,
  65.     lastc, NoOfRecs, line_count, remaining: integer;
  66.     EndOFFile: Boolean;
  67.  
  68. {**************************}
  69. {* Machine dependent code *}
  70. {**************************}
  71.  
  72. { These files names must match your PICS hardware files. }
  73.  
  74.   {$I pics.MCH}             { Terminal and channel routines }
  75.   {$I pics.MDM}             { Modem routines }
  76.  
  77. {************************************************}
  78. {* Procedures duplicated from main PICS program *}
  79. {************************************************}
  80.  
  81. function online: boolean;
  82. { Determine whether system is still online - local or remote }
  83.   begin
  84.     if remote_online
  85.       then if ch_carck
  86.              then online := TRUE
  87.              else
  88.                begin
  89.                  putstat('Carrier lost');
  90.                  mdhangup;
  91.                  remote_online := FALSE;
  92.                  online := FALSE
  93.                end
  94.       else online := local_online;
  95.   end;
  96.  
  97. Procedure PutChar(ch: char);
  98. { User written I/O driver to output character }
  99.   var
  100.     i: integer;
  101.   begin
  102.     if user_rec.shift_lock
  103.       then ch := UpCase(ch);
  104.     if printer_copy
  105.       then BDOS(5, ord(ch));
  106.     if online
  107.       then
  108.         begin
  109.           if (ch <> BEL) or local_online
  110.             then BDOS(6, ord(ch));
  111.           if remote_copy
  112.             then
  113.               begin
  114.                 ch_out($7F and ord(ch));
  115.                 if ch = CR
  116.                   then for i := 1 to user_rec.nulls do
  117.                     ch_out(ord(NUL));
  118.                 if ch = LF
  119.                   then for i := 1 to (user_rec.nulls shr 2) do
  120.                     ch_out(ord(NUL))
  121.               end
  122.         end
  123.   end;
  124.  
  125. function GetChar: char;
  126. { Get character: no wait, no echo }
  127.   var
  128.     ch: char;
  129.   begin
  130.     if keypressed
  131.       then
  132.         begin
  133.           read(KBD, ch);
  134.           if (not online) and (not (ch in [^C, LF, CR]))
  135.             then ch := NUL;
  136.           case ch of
  137.             ^W: begin
  138.                   op_chat := TRUE;
  139.                   ch := ' '
  140.                 end;
  141.             ^E: begin
  142.                   remote_copy := not remote_copy;
  143.                   if remote_copy
  144.                     then putstat('Remote copy on')
  145.                     else putstat('Remote copy off');
  146.                   ch := NUL
  147.                 end;
  148.             ^R: begin
  149.                   delay_down := not delay_down;
  150.                   if delay_down
  151.                     then putstat('Delayed shutdown on')
  152.                     else putstat('Delayed shutdown off');
  153.                   ch := NUL
  154.                 end;
  155.             ^T: begin
  156.                   remote_online := FALSE;
  157.                   mdhangup;
  158.                   ch := NUL
  159.                 end;
  160.             LF: begin
  161.                   putstat('^W: CHAT, ^E: Remote copy on/off, ^R: Remote offline - delayed, ^T: Twit');
  162.                   ch := NUL
  163.                 end
  164.           end
  165.         end
  166.     else if remote_online and remote_copy and ch_carck and ch_inprdy
  167.       then ch := chr($7F and ch_inp)
  168.       else ch := NUL;
  169.     GetChar := ch
  170.   end;
  171.  
  172. function brk: boolean;
  173. { Check for break or pause }
  174.   var
  175.     ch: char;
  176.   begin
  177.     ch := GetChar;
  178.     while ch = DC3 do                       { ^S }
  179.       repeat
  180.         ch := GetChar
  181.       until (not online) or (ch <> NUL);
  182.     brk := (not online) or (ch = ETX)       { ^C }
  183.   end;
  184.  
  185. procedure pause;
  186. { Pause for user response before continuing }
  187.   begin
  188.     Write(USR, 'Press any key to continue...');
  189.     if user_rec.noisy
  190.       then Write(USR, BEL);
  191.     repeat
  192.     until (not online) or (GetChar <> NUL);
  193.     Write(USR, CR, ' ':28, CR)
  194.   end;
  195.  
  196. procedure SetSect(Drive, User: integer);
  197. { Set to file section }
  198.   begin
  199.     BDOS(seldrive, Drive);
  200.     BDOS(getseluser, User)
  201.   end;
  202.  
  203. {**********************************}
  204. {* New procedures for Uncrunching *}
  205. {**********************************}
  206.  
  207.   procedure getbyt; forward;
  208.  
  209.   procedure out; forward;
  210.  
  211.   procedure uncrel;
  212.     begin
  213.       {$I UNCREL.UNC}  { patched vers of UNCREL.INC }
  214.  
  215.       {UNCREL.INC must have following addresses patched in:
  216.  
  217.          byte          address
  218.          ----          -----------------
  219.          1+2            24k uncr buffer
  220.          7+8            getbyt routine
  221.          10+11          out routine
  222.  
  223.         The calling SP is stored at Uncrel+542h. To abort the uncrunch
  224.        procedure the in or out routine must restore the SP to this value
  225.        and execute a Z80 RET instruction. }
  226.  
  227.   end;
  228.  
  229.   function getc: integer;
  230.   { Get an 8 bit value from the input buffer - read block if necessary }
  231.     begin
  232.       if BufferPtr > 128 then
  233.         begin
  234.           if in_library
  235.             then
  236.               {$I-} BlockRead(libr_file, Buffer, 1) {$I+}
  237.             else
  238.           {$I-} BlockRead(XfrFile, Buffer, 1) {$I+};
  239.           EndOfFile := (IOresult <> 0);
  240.           BufferPtr := 1
  241.         end;
  242.       getc := Buffer[BufferPtr];
  243.       BufferPtr := succ(BufferPtr)
  244.     end;
  245.  
  246.   procedure uncr_fname;
  247.   { Display uncrunched file name }
  248.     var
  249.       b: byte;
  250.     begin
  251.       write(USR,'      ===> ');
  252.       for i:= 1 to 2 do
  253.         b:=getc;                 { skip header bytes (76feh) }
  254.       while (b <> 0) do          { display uncrunched file name }
  255.         begin
  256.           write(USR,char(b));
  257.           b:=getc
  258.         end;
  259.       for b:=1 to 2 do
  260.         writeln(USR);
  261.       BufferPtr:=1;              { Reset pointer to start of file }
  262.       line_count:=3
  263.     end;
  264.  
  265.   procedure getbyte;
  266.     begin
  267.       if EndOFFile then { exit from Uncrel if premature eof }
  268.         begin
  269.           writeln(USR);
  270.           inline(
  271.             $ed/$7b/uncrel+$542/    { ld sp,(uncrel+542h) ;restore old sp }
  272.             $c9)                    { ret }
  273.         end;
  274.       fbyte := getc;
  275.          end;
  276.  
  277.   procedure output;
  278.   { Output uncruched bytes to USR output driver. Filter clear screen
  279.     and form feed chars. Insert screen breaks & monitor for ^S and
  280.     ^C. }
  281.    begin
  282.      if (fbyte <> $1a) and (fbyte <> $0c) then
  283.        begin  { filter clear screen & form feed chars }
  284.           write(USR,char(fbyte));
  285.             if (user_rec.lines <> 99) and (char(fbyte) = LF) then
  286.               begin
  287.                 line_count := succ(line_count);
  288.                 if line_count mod user_rec.lines = 0
  289.                   then pause
  290.               end;
  291.        end;
  292.      if brk then { Exit Uncrel if ^C is entered }
  293.        begin
  294.          writeln(USR);
  295.          inline(
  296.            $ed/$7b/uncrel+$542/    { ld sp,(uncrel+542h) ;restore old sp }
  297.            $c9)                    { ret }
  298.        end;
  299.    end;
  300.  
  301.   procedure getbyt;
  302.   { Get a byte from crunched file }
  303.     begin
  304.       inline(
  305.         $cd/getbyte/  {call getbyte}
  306.         $3a/fbyte    {ld a,(fbyte)}
  307.       );
  308.     end;
  309.  
  310.   procedure out;
  311.   { Output uncrunched byte to User output routine }
  312.     begin
  313.       inline(
  314.         $32/fbyte/    {ld (fbyte),a}
  315.         $cd/output   {call output}
  316.       );
  317.     end;
  318.  
  319. {*****************}
  320. {* Main  program *}
  321. {*****************}
  322.  
  323.   begin
  324.     UsrOutPtr:=addr(putchar);      { Reassign USR: to PICS output driver }
  325.     BufferPtr := MaxInt;           { Force a file read }
  326.     SetSect(SetDrv,SetUsr);        { Select DU: of file area }
  327.     uncr_fname;                    { Display uncrunched file name }
  328.     uncrel;                        { Uncrunch & type the file }
  329.     if not in_library then         { Close the file if not in LBR }
  330.       close (XfrFile);
  331.     SetSect(HomDrv,HomUsr);        { Select DU: of PICS.COM }
  332.     assign(chain_file,'PICS.COM');
  333.     execute(chain_file);           { Reexecute PICS.COM }
  334.   end.
  335.  
  336. { end of PICSuncr.pas }
  337.