home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / masm / masm6 / show / pagerp.asm < prev    next >
Encoding:
Assembly Source File  |  1991-01-14  |  6.7 KB  |  203 lines

  1. ;* PAGERP.ASM - Module containing routines for paging through a file and
  2. ;* writing text to the screen buffer. Works with main module SHOWP.ASM.
  3.  
  4.         TITLE   Pager
  5.         .MODEL  small, pascal, os_os2
  6.         .286
  7.  
  8. INCL_NOCOMMON   EQU 1         ; Enable call groups
  9. INCL_VIO        EQU 1
  10.  
  11.         INCLUDE os2.inc
  12.         INCLUDE show.inc
  13.  
  14.         .CODE
  15.  
  16. ;* Pager - Displays status line and all the text lines for a screen.
  17. ;*
  18. ;* Params: cLines - lines to scroll (negative up, positive down)
  19. ;*
  20. ;* Uses:   Global variables: segBuf, offBuf, yCur
  21. ;*
  22. ;* Return: None
  23.  
  24. Pager   PROC,
  25.         cLines:SWORD
  26.  
  27.         mov     es, segBuf              ; Initialize buffer position
  28.         mov     di, offBuf
  29.  
  30.         mov     cx, cLines              ; Get line count
  31.         mov     ax, 10                  ; Search for linefeed
  32.  
  33.         or      cx, cx                  ; Argument 0?
  34.         jl      backward                ; If below, backward
  35.         jg      foreward                ; If above, forward
  36.         jmp     showit                  ; If equal, done
  37.  
  38. backward:
  39.         call    GoBack                  ; Adjust backward
  40.         jmp     showit                  ; Show screen
  41.  
  42. foreward:
  43.         call    GoForeward              ; Adjust forward
  44.  
  45. ; Write line number to status line
  46.  
  47. showit:
  48.         cld                             ; Forward
  49.         push    di                      ; Save
  50.         push    ds                      ; ES = DS
  51.         pop     es
  52.  
  53.         INVOKE  BinToStr,               ; Write line number as string
  54.                 yCur,
  55.                 ADDR stLine[LINE_POS]
  56.  
  57. ; Fill in status line
  58.  
  59.         mov     cx, 6                   ; Six spaces to fill
  60.         sub     cx, ax                  ; Subtract those already done
  61.         mov     al, ' '                 ; Fill with space
  62.         rep     stosb
  63.  
  64.         INVOKE  VioWrtCharStrAtt,       ; Write to screen
  65.                 ADDR stLine,
  66.                 X_MAX,
  67.                 0,
  68.                 0,
  69.                 ADDR atSta,
  70.                 0
  71.  
  72.         pop     di                      ; Update position
  73.         mov     si, di
  74.         mov     cx, yMax                ; Lines per screen
  75.  
  76.         .REPEAT
  77.         mov     bx, yMax                ; Lines per screen
  78.         inc     bx                      ; Adjust for 0
  79.         sub     bx, cx                  ; Calculate current row
  80.         push    cx                      ; Save line number
  81.         mov     es, segBuf              ; Reload
  82.  
  83.         INVOKE  ShowLine,               ; Write line to screen
  84.                 es::si,                 ; Pointer to current position
  85.                 bx,                     ; Line number
  86.                 cbBuf,                  ; File length (for bounds check)
  87.                 ADDR atScr              ; Attribute
  88.  
  89.         pop     cx                      ; Restore line number
  90.         mov     si, ax                  ; Get returned position
  91.  
  92.         dec     cx                      ; Count the line
  93.         .UNTIL  (ax >= cbBuf) || !cx    ; Continue if more lines and not
  94.         jcxz    exit                    ; Done if more lines,
  95.                                         ;   else fill screen with spaces
  96.         mov     ax, X_MAX               ; Columns times remaining lines
  97.         mul     cl
  98.         mov     dx, ax                  ; INVOKE uses AX, so use DX
  99.         sub     cx, yMax                ; Calculate starting line
  100.         neg     cx
  101.         inc     cx
  102.  
  103.         INVOKE  VioWrtNCell,            ; Write space cells
  104.                 ADDR celScr,            ; Cell of space and attribute
  105.                 dx,                     ; Number of cells to fill
  106.                 cx,                     ; Line to start fill
  107.                 0,                      ; Column 0
  108.                 0                       ; Console handle
  109. exit:
  110.         ret
  111.  
  112. Pager   ENDP
  113.  
  114.  
  115. ;* ShowLine - Writes a line of text to the screen.
  116. ;*
  117. ;* Params: pchIn - Far pointer to input text
  118. ;*         y - Line number
  119. ;*         cbMax - Maximum number of characters (file length)
  120. ;*         pcelAtrib - Far pointer to attribute
  121. ;*
  122. ;* Return: None
  123.  
  124. ShowLine PROC USES si di,
  125.         pchIn:PBYTE,
  126.         y:WORD,
  127.         cbMax:WORD,
  128.         pcelAtrib:PBYTE
  129.  
  130.         LOCAL   achOut[X_MAX]:BYTE
  131.  
  132.         push    ds                      ; Save
  133.         push    ss                      ; ES = SS
  134.         pop     es
  135.         lea     di, achOut              ; Destination line
  136.         lds     si, pchIn               ; Source line
  137.         mov     cx, X_MAX               ; Cells per row
  138.         mov     bx, di                  ; Save copy of start for tab calc
  139. loop1:
  140.         lodsb                           ; Get character
  141.         cmp     al, 9                   ; Tab?
  142.         je      filltab                 ; Space out tab
  143.         cmp     al, 13                  ; CR?
  144.         je      filleol                 ; Fill rest of line with spaces
  145.         stosb                           ; Copy out
  146.         cmp     si, cbMax               ; Check for end of file
  147.         ja      filleol
  148.         loop    loop1
  149. loop2:
  150.         lodsb                           ; Throw away rest of line to truncate
  151.         cmp     si, cbMax               ; Check for end of file
  152.         ja      exit
  153.         cmp     al, 13                  ; Check for end of line
  154.         jne     loop2
  155.         inc     si                      ; Throw away line feed
  156.  
  157.         jmp     exit                    ; Done
  158. filltab:
  159.         push    bx                      ; Fill tab with spaces
  160.         push    cx
  161.  
  162.         sub     bx, di                  ; Get current position in line
  163.         neg     bx
  164.  
  165.         mov     cx, 8                   ; Default count 8
  166.         and     bx, 7                   ; Get modulus
  167.         sub     cx, bx                  ; Subtract
  168.         mov     bx, cx                  ; Save modulus
  169.  
  170.         mov     al, ' '                 ; Write spaces
  171.         rep     stosb
  172.  
  173.         pop     cx
  174.         sub     cx, bx                  ; Adjust count
  175.         .IF     sign?
  176.         sub     cx, cx                  ; Make negative count 0
  177.         .ENDIF
  178.  
  179.         pop     bx
  180.         jcxz    loop2                   ; If beyond limit done
  181.         jmp     loop1
  182. filleol:
  183.         inc     si                      ; After CR, throw away LF
  184.         mov     al, ' '                 ; Fill rest of line
  185.         rep     stosb
  186. exit:
  187.         pop     ds
  188.         INVOKE  VioWrtCharStrAtt,
  189.                 ADDR achOut,
  190.                 X_MAX,
  191.                 y,
  192.                 0,
  193.                 pcelAtrib,
  194.                 0
  195.  
  196.         mov     ax, si                  ; Return position
  197.         ret
  198.  
  199. ShowLine ENDP
  200.  
  201.  
  202.         END
  203.