home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / UN_CRT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  4KB  |  103 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 335 of 362                                                               
  3. From : Lou Duchez                          1:157/200.0          01 Jun 93  06:21 
  4. To   : Michael Deakins                                                           
  5. Subj : ANSI, batch file exec'ing                                              
  6. ────────────────────────────────────────────────────────────────────────────────
  7. MD>I have two questions. First, How can I display ANSI files from a Pascal
  8. MD>program by using the CON driver (read: ANSI.SYS) instead of going to the
  9. MD>trouble of writing a terminal emulator, and still remain
  10. MD>window-relative? I used TP5.5's WRITE procedure to write to a file
  11. MD>assigned to the CON device instead of the CRT unit's standard OutPut,
  12. MD>but this obliterated my status line at the bottom of the screen when the
  13. MD>ANSI file scrolled. Is there an easy way to write to the CON device
  14. MD>while remaining window-relative without having to modify ANSI.SYS or
  15. MD>write a terminal emulation procedure?
  16. MD> My second question: How can I call a batch file from within a Pascal
  17. MD>program and pass %1-%9 parameters to it? I'm aware of the EXEC
  18. MD>procedure, but doesn't that only work on executables?
  19.  
  20. Second question first: you're right about EXEC calling only executables.
  21. So try calling "COMMAND.COM" as your program, and give it parameters of
  22. "/C " plus the batch file name plus whatever arguments you intend to pass.
  23. (That tells the system to run a single command out of DOS.)  Look up
  24. ParamCount and ParamStr() to see how Pascal uses command-line parameters.
  25.  
  26. First question second: you know, I addressed this problem just yesterday
  27. trying to write a program.  I concluded that, if you're going to bypass
  28. CRT, you need to do a lot of "manual" work yourself to keep a window
  29. going.  Let me show you the tools I devised:
  30.  
  31.  
  32.  
  33. ---PROCEDURE ATSCROLL: SCROLLS A SCREEN REGION UP OR DOWN (negative or
  34.    positive number in LINESDOWN, respectively)}
  35.  
  36. procedure atscroll(x1, y1, x2, y2: byte; linesdown: integer);
  37. var tmpbyte, intbyte, clearattrib: byte;
  38. begin
  39.   if linesdown <> 0 then begin
  40.     clearattrib := foxfore + foxback shl 4;
  41.     x1 := x1 - 1;
  42.     y1 := y1 - 1;
  43.     x2 := x2 - 1;
  44.     y2 := y2 - 1;
  45.     if linesdown > 0 then intbyte := $07 else intbyte := $06;
  46.     tmpbyte := abs(linesdown);
  47.     asm
  48.       mov ah, intbyte
  49.       mov al, tmpbyte
  50.       mov bh, clearattrib
  51.       mov ch, y1
  52.       mov cl, x1
  53.       mov dh, y2
  54.       mov dl, x2
  55.       int 10h
  56.       end;
  57.     end;
  58.   end;
  59.  
  60.  
  61.  
  62. {---FUNCTION YPOS: Returns the line the cursor is on.  I wrote it because
  63.    I don't always trust WHEREY (or WHEREX): they report, for example, the
  64.    cursor position relative to a text window.  So I had it lying around,
  65.    and I opted to use it in my routines.}
  66.  
  67. function ypos: byte;
  68. var tmpbyt: byte;
  69. begin
  70.   asm
  71.     mov ah, 03h
  72.     mov bh, 0
  73.     int 10h
  74.     mov tmpbyt, dh
  75.     end;
  76.   ypos := tmpbyt + 1;
  77.   end;
  78.  
  79.  
  80.  
  81. {--- PROCEDURE WRITEANDFIXOVERHANG: I use it in place of WRITELN in my
  82.     program: before writing a line of text, it checks if there's room
  83.     at the bottom of the screen.  If not, it scrolls the screen up
  84.     before writing.  Keep in mind that this program is bent on preserving
  85.     the top three or four screen lines, not the bottom lines.}
  86.  
  87. procedure writeandfixoverhang(strin: string);
  88. const scrollat: byte = 24;
  89. var overhang: byte;
  90. begin
  91.   if ypos >= scrollat then begin
  92.     overhang := ypos - scrollat + 1;
  93.     atscroll(0, 4 + overhang, 0, 80, 25, -overhang);
  94.     movecursor(1, ypos - overhang);
  95.     end;
  96.   writeln(strin);
  97.   end;
  98.  
  99.  
  100. So assuming your text lines don't get too long (line longer than 160 chars),
  101. these routines will keep the top of your screen from getting eaten.  If you
  102. want to preserve space at the bottom of the screen instead (or both top and
  103. bottom), change WRITEANDFIXOVERHANG.