home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / dskutl / reform16.arc / REFORMAT.IN4 < prev    next >
Text File  |  1987-05-22  |  12KB  |  228 lines

  1. {REFORMAT.IN4
  2.  Fast Write routine.
  3.  This does only a modicum of "flicker control" for slow or color
  4.  video cards.  Other versions are available for that if you just HAVE
  5.  to have such a thing.  Remember, REFORMAT is NOT a video-oriented utility.
  6.  If you have a weird video setup that doesn't permit direct write
  7.  to video memory, there's lots of "generic" code to use the regular
  8.  Turbo Pascal WRITE or WRITELN instructions.
  9.  Toad Hall.
  10. }
  11.  
  12. PROCEDURE WriteF(col,row : INTEGER; S : Line);
  13.   {Fast direct screen memory writing utility.
  14.    Permits x/y positioning anywhere on the screen, centering
  15.    at any y coordinate, line clearing (whole line or a specified
  16.    x coordinate), and line filling (whole line or a specified
  17.    x coordinate).
  18.    Special rules:
  19.      IF the first character of the string has an ASCII value above 127,
  20.      WriteF will assume this is a repeating character and fill a whole line
  21.      with that character.  Ignores rest of string (if it exists).
  22.      Naturally, if you send an ASCII 32+127, this will blank a line!
  23.      Filling starts at x coord, of course.
  24.  
  25.      IF the x coordinate is 0, WriteF will center the string according to
  26.      the current window size (the global variable width).
  27.  
  28.      IF the y coordinate is 0, WriteF will use the global variable toadY
  29.      as the current y coordinate (in the current window) and write this
  30.      line there.  toadY will be incremented.
  31.  
  32.      IF the y coordinate is NOT 0, WriteF will write at y, and will update
  33.      the global toadY to that coordinate.  toadY will NOT be incremented.
  34.  
  35.      IF we are filling, toadY will NOT increment.
  36.  
  37.    Toad Hall.
  38.   }
  39.   BEGIN
  40.     InLine(
  41.    $1E             {    push    DS            ;actual start of code}
  42.   /$06             {    push    ES            ;might as well save this
  43.                                                too}
  44.   /$8A/$96/>COL    {    mov     DL,>col[BP]   ;desired column}
  45.   /$8A/$A6/>ROW    {    mov     AH,>row[BP]   ;desired row}
  46.   /$08/$E4         {    or      AH,AH         ;zero?}
  47.   /$75/$04         {    jne     W2            ; nope, got a row val}
  48.   /$8A/$26/>TOADY  {    mov     AH,[>toadY]   ; 0, so make it toadY}
  49.                    {W2:}
  50.   /$88/$E6         {    mov     DH,AH         ;we use it here}
  51.  
  52.   /$8A/$2E/>WIDTH  {    mov     CH,[>width]   ;get global width variable}
  53.                    {;point ES:SI to the string (relative to stack, of
  54.                      course)}
  55.   /$8D/$BE/>S      {    lea     DI,>S[BP]     ;ES:SI = string vector}
  56.   /$57             {    push    DI}
  57.   /$5E             {    pop     SI           ;gonna use for source later}
  58.   /$36             {    SS:}
  59.   /$8A/$0C         {    mov     CL,[SI]       ;get str length into CX}
  60.   /$16             {    push    SS            ;the string var segment}
  61.   /$07             {    pop     ES            ;ES=SS}
  62.  
  63.   /$46             {    inc     SI            ;bump past str length}
  64.   /$47             {    inc     DI            ;here too}
  65.                    {;test to see if a clear or fill.}
  66.                    {;indicated by first string char being >127.}
  67.  
  68.   /$31/$C0         {    xor     AX,AX         ;clear a fill flag}
  69.   /$50             {    push    AX}
  70.   /$88/$F4         {    mov     AH,DH         ;get row back}
  71.   /$FE/$C4         {    inc     AH            ;assume we incr toadY}
  72.   /$26             {    ES:}
  73.   /$8A/$04         {    mov     AL,[SI]       ;get first char}
  74.   /$3C/$80         {    cmp     AL,128        ;is hi bit set?}
  75.   /$72/$12         {    jb      W3Y           ;nope, do centering test}
  76.  
  77.   /$88/$E9         {    mov     CL,CH         ;length=window width}
  78.   /$28/$D1         {    sub     CL,DL         ;minus col offset}
  79.   /$3C/$A0         {    cmp     AL,$A0        ;is it a hi-bit space?}
  80.   /$75/$08         {    jne     W3B           ; nope}
  81.   /$FE/$C1         {    inc     CL}
  82.   /$B0/$20         {    mov     AL,$20        ; yep, make it so}
  83.   /$8A/$26/>TOADY  {    mov     AH,[>toadY]   ;insure toadY doesn't change}
  84.                    {;must clear the old AX on the stack (0's, remember?)}
  85.                    {;and save our new value for the screen fill.}
  86.                    {W3B:}
  87.   /$5B             {    pop     BX            ;remove the zero fillflag}
  88.   /$50             {    push    AX            ;save fillchar}
  89.                    {W3Y:}
  90.   /$88/$26/>TOADY  {    mov     [>toadY],AH   ;post updated toadY}
  91.   /$08/$D2         {    or      DL,DL         ;0 = column=centering?}
  92.   /$75/$14         {    jne     W3Z           ; nope}
  93.                    {;centering a string, compute left margin offset.}
  94.   /$B2/$01         {    mov     DL,1          ;assume adjusted left margin}
  95.   /$88/$E8         {    mov     AL,CH         ;legal width}
  96.   /$28/$C8         {    sub     AL,CL         ;left over to justify}
  97.   /$76/$0C         {    jbe     W3Z           ;<= 0 left over}
  98.   /$78/$0A         {    js      W3Z  ;new}
  99.  
  100.   /$3C/$01         {    cmp     AL,1          ;just 1 left?}
  101.   /$74/$06         {    je      W3Z           ;yep, start at left margin}
  102.   /$04/$02         {    add     AL,2          ;fixes centering for text}
  103.   /$D0/$E8         {    shr     AL,1          ;divide in half}
  104.   /$88/$C2         {    mov     DL,AL         ;make THAT the col value}
  105.                    {;writing at col, protect right window margin}
  106.                    {W3Z:}
  107.   /$31/$C0         {    xor     AX,AX}
  108.   /$88/$C8         {    mov     AL,CL         ;string length}
  109.   /$00/$D0         {    add     AL,DL         ;add in col offset}
  110.   /$38/$E8         {    cmp     AL,CH         ;subtract scr width}
  111.   /$76/$08         {    jbe     W4            ; fine, <=}
  112.   /$88/$E8         {    mov     AL,CH         ; bad, make width - col}
  113.   /$28/$D0         {    sub     AL,DL}
  114.   /$FE/$C0         {    inc     AL            ;adjust for subtract}
  115.   /$88/$C1         {    mov     CL,AL}
  116.  
  117.                    {W4:}
  118.   /$FE/$CE         {    dec     DH}
  119.   /$FE/$CA         {    dec     DL            ;and col to 0..79}
  120.   /$02/$36/>WTOP   {    add     DH,[>wTop]    ;add in window Y coord
  121.                                                      offset}
  122.   /$02/$16/>WLEFT  {    add     DL,[>wLeft]   ;add in window left offset}
  123.   /$30/$ED         {    xor     CH,CH         ;clear to just length in
  124.                                                lsb}
  125.   /$88/$F0         {    mov     AL,DH         ;get the row value}
  126.   /$B3/$50         {    mov     BL,$50        ;fiddle for scrn absolute}
  127.   /$F6/$E3         {    mul     BL            ;rows * 90}
  128.   /$29/$DB         {    sub     BX,BX         ;clear msb}
  129.   /$88/$D3         {    mov     BL,DL         ;col for lsb}
  130.   /$01/$D8         {    add     AX,BX         ;add them}
  131.   /$01/$C0         {    add     AX,AX         ;*2}
  132.   /$89/$C7         {    mov     DI,AX         ;ES:DI=screen offset}
  133.   /$00/$CA         {    add     DL,CL         ;add str length for cursor psn}
  134.  
  135.   /$B4/$0F         {    mov     AH,15         ;get cur video mode}
  136.   /$CD/$10         {    int     $10           ;cur video page returned in
  137.                                                BH}
  138.   /$88/$C3         {    mov     BL,AL         ;save current mode in BL}
  139.   /$58             {    POP     AX            ;get fillchar-flag back}
  140.   /$50             {    PUSH    AX            ;save again}
  141.   /$08/$C0         {    OR      AL,AL         ;0 means no special char}
  142.   /$74/$02         {    je      W4A           ; no special char/clreol}
  143.   /$28/$CA         {    sub     DL,CL         ;force back to col}
  144.                    {W4A:}
  145.   /$53             {    push    BX            ;save page, mode}
  146.                    {;stack now has page/mode, fillchar-flag}
  147.   /$B4/$02         {    mov     AH,2          ;set cursor psn svc}
  148.   /$CD/$10         {    int     $10           ;ROM-BIOS video}
  149.   /$5B             {    pop     BX            ;restore page/mode}
  150.  
  151.   /$58             {    pop     AX            ;restore fillchar-flag in AL}
  152.                    {;stack clear}
  153.   /$8A/$26/>COLOR  {    mov     AH,[>color]   ;here's the attribute}
  154.                    {;might as well do this anyway, tho not needed if}
  155.                    {;just filling.  test takes longer than the push/pop.}
  156.  
  157.                    {;here goes DS, no more variable access!}
  158.   /$06             {    push    ES            ;string segment}
  159.   /$1F             {    pop     DS            ;DS:SI string vector}
  160.   /$BA/$00/$B0     {    mov     DX,$B000      ;assume mono screen}
  161.   /$80/$FB/$07     {    cmp     BL,7          ;mono?}
  162.   /$74/$03         {    jz      W4B           ; yep (save this ZF)}
  163.   /$BA/$00/$B8     {    mov     DX,$B800      ; nope, make it color}
  164.                    {W4B:}
  165.   /$8E/$C2         {    mov     ES,DX         ;assign ES to screen}
  166.   /$89/$C3         {    mov     BX,AX         ;will use it here}
  167.                    {;AH, BH = attribute,}
  168.                    {;AL, BL = fill char or 0}
  169.  
  170.   /$74/$2E         {    jz      W5            ;ZF = mono}
  171.  
  172.   /$BA/$DA/$03     {    mov     DX,$03DA      ;color board port}
  173.                    {;redundant code is better than a test}
  174.                    {;in the middle of our loop.}
  175.   /$08/$C0         {    or      AL,AL         ;doing a normal write?}
  176.   /$74/$14         {    je      WL1           ; yep}
  177.                    {;doing a fill, char in BL}
  178.                    {FL1:}
  179.   /$EC             {    in      AL,DX         ;color board ready?}
  180.   /$A8/$01         {    test    AL,1}
  181.   /$75/$FB         {    jnz     FL1           ; nope}
  182.   /$FA             {    cli                   ;no interrupts}
  183.                    {FL2:}
  184.   /$EC             {    in      AL,DX         ;color board still ready?}
  185.   /$A8/$01         {    test    AL,1}
  186.   /$74/$FB         {    jz      FL2           ; nope}
  187.   /$89/$D8         {    mov     AX,BX         ;fill char, attrib}
  188.   /$AB             {    stosw                 ;stuff word to scr,}
  189.                                               {inx DI by 2}
  190.   /$E2/$F0         {    loop    FL1           ;test color board again}
  191.   /$28/$C0         {    sub     AL,AL         ;dumb way to exit}
  192.   /$74/$20         {    jz      WX}
  193.  
  194.                    {;doing a normal color write, attrib already in AH}
  195.                    {WL1:}
  196.   /$EC             {    in      AL,DX         ;color board ready?}
  197.   /$A8/$01         {    test    AL,1}
  198.   /$75/$FB         {    jnz     WL1           ; nope}
  199.   /$FA             {    cli                   ;no interrupts}
  200.                    {WL2:}
  201.   /$EC             {    in      AL,DX         ;color board still ready?}
  202.   /$A8/$01         {    test    AL,1}
  203.   /$74/$FB         {    jz      WL2           ; nope}
  204.   /$AC             {    lodsb                 ;get a string byte}
  205.   /$AB             {    stosw                 ;stuff word to scr,}
  206.   /$E2/$F1         {    loop    WL1           ;test color board again}
  207.   /$28/$C0         {    sub     AL,AL         ;funny test here}
  208.   /$74/$0D         {    jz      WX            ;dumb way to exit}
  209.  
  210.                    {;doing a mono fill}
  211.                    {W5:}
  212.   /$08/$C0         {    or      AL,AL         ;0=normal write}
  213.   /$74/$05         {    je      WL3           ; yep, do a string}
  214.                    {;AL=fill char}
  215.                    {;AH=attribute}
  216.   /$F2/$AB         {    rep stosw             ;ES:DI stuff CX words to scr}
  217.   /$E9/$04/$00     {    jmp     WX            ;..and exit}
  218.                    {WL3:}
  219.   /$AC             {    lodsb                 ;DS:SI snarf a string char}
  220.                                               { into AL}
  221.   /$AB             {    stosw                 ;ES:DI stuff word to scr}
  222.   /$E2/$FC         {    loop    WL3           ;for whole string}
  223.                    {WX:}
  224.   /$07             {    pop     ES            ;restore seg regs}
  225.   /$1F             {    pop     DS}
  226. );
  227.   END;  {of WriteF}
  228.