home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / v5lib.asm < prev    next >
Encoding:
Assembly Source File  |  1980-01-01  |  5.1 KB  |  114 lines

  1. ;       Video_Display Library (part 5)
  2.  
  3. _TEXT   segment byte public 'CODE'      ; Place the code in the code segment
  4.         assume CS:_TEXT                 ; Assume the CS register points to it
  5.  
  6.         public _scrClr
  7.  
  8. _scrClr   proc near
  9.         push    bp
  10.         mov     bp,sp
  11.         push    di
  12.         push    si
  13.         mov     al,0              ; Set number of lines to scroll to 0
  14.         mov     ch,0              ; Set upper-left row
  15.         mov     cl,0              ; Set upper-left column
  16.         mov     dh,24             ; Set lower-right row
  17.         mov     dl,79             ; Set lower-right Column
  18.         mov     bh,7              ; Set blank lines attribute
  19.         mov     ah,6              ; Scroll page up interrupt
  20.         int     10H
  21.         mov     ah,15             ; Get page number
  22.         int     10H
  23.         mov     dx,0              ; Set position to (0,0)
  24.         mov     ah,2
  25.         int     10H
  26.         pop     si
  27.         pop     di
  28.         pop     bp
  29.         ret
  30. _scrClr   endp
  31.  
  32. ; _scrPuts(s)
  33. ;
  34. ; Function: Do a TTY style write of the null-terminated string pointed
  35. ; to by s.
  36. ;
  37. ; Algorithm: Directly write the characters to the display, then update
  38. ; the cursor to the end of the string written.
  39. ;
  40. ; Comments: This function does not implement full TTY style output; most
  41. ; importantly, it will not scroll the display when the end is reached.
  42.  
  43.         public  _scrPuts        ; Routine is available to other modules
  44.  
  45.         s = 4                   ; The offset to the s parameter
  46.  
  47. _scrPuts proc near              ; NEAR type subroutine
  48.         push    bp              ; Save the BP register
  49.         mov     bp,sp           ; Set BP to SP, so we can access the parameters
  50.         push    di              ; Save the DI register
  51.         push    si              ; Save the SI register
  52.         push    es              ; Save the ES register
  53.         mov     ah,15           ; Get mode & active page number by calling
  54.         int     10H             ;   the ROM BIOS
  55.         mov     cx,0B000H       ; Assume monochrome adapter base address
  56.         cmp     al,7            ; Check it by checking the display mode
  57.         je      setma           ; If it is monochrome, branch
  58.         mov     cx,0B800H       ; Otherwise, set the base address to CGA
  59. setma:  mov     es,cx           ; ES = adapter base address
  60.         mov     si,[bp+s]       ; SI = start of string to write
  61.         mov     ah,3            ; Get cursor position into DH/DL by calling
  62.         int     10H             ;   the ROM BIOS
  63. ;
  64. ; Calculate the character position offset:
  65. ;
  66. calcCh: push    es              ; Save display memory ES
  67.         xor     ax,ax           ; Point ES to low memory (i.e., zero it)
  68.         mov     es,ax
  69.         mov     al,dh           ; AL = row of cursor
  70.         mov     bl,es:44AH      ; BL = screen width in characters
  71.         mul     bl              ; AX = row # times columns per row
  72.         mov     cl,dl           ; CX = column of cursor
  73.         xor     ch,ch
  74.         add     ax,cx           ; Add the column number to AX
  75.         shl     ax,1            ; Adjust for char/attribute (multiply by 2)
  76.         add     ax,es:44EH      ; Add in the page start address (from low mem)
  77.         mov     di,ax           ; Point DI at next display byte
  78.         pop     es              ; Restore ES to the screen memory base
  79. ;
  80. ; Main character copying loop:
  81. ;
  82. loop:   lods    byte ptr [si]   ; Get the next character in the string
  83.         or      al,al           ; Check for end-of-string
  84.         jz      exit            ; If end-of-string, exit
  85.         cmp     al,0DH          ; Check for carriage return
  86.         jne     notCR           ; If not carriage return, branch
  87.         xor     dl,dl           ; Go to the first column, this line
  88.         jmp     calcCh          ; Go recalc display pointer
  89. notCR:  cmp     al,0AH          ; Check for line feed
  90.         jne     notLF           ; If not line feed, branch
  91.         inc     dh              ; Go to the next line, this column
  92.         jmp     calcCh          ; Go recalc display pointer
  93. notLF:  cmp     al,' '          ; Check for other control characters
  94.         jl      loop            ; If it is a control character, skip it
  95.         cmp     dl,bl           ; Are we off the right edge of the screen?
  96.         je      loop            ; If yes, don't display this one
  97.         stos    byte ptr es:[di]; Store the character into display memory
  98.         inc     di              ; Skip over display attribute
  99.         inc     dl              ; Next column
  100.         jmp     loop            ; Go do the next one
  101.  
  102. exit:   mov     ah,2            ; Set the new cursor position by calling
  103.         int     10H             ;   the ROM BIOS
  104.         pop     es              ; Restore the ES register
  105.         pop     si              ; Restore the SI register
  106.         pop     di              ; Restore the DI register
  107.         pop     bp              ; Restore the BP register
  108.         ret                     ; Return to calling program
  109. _scrPuts endp                   ; End of subroutine
  110.  
  111. _TEXT   ends                    ; End of code segment
  112.         end                     ; End of assembly code
  113.  
  114.