home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / GRFTXT.ZIP / GRAFTEX2.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-02-01  |  6.2 KB  |  181 lines

  1. code      segment   byte public
  2. assume    cs:code
  3. public    gtxtsol
  4. page 60,132
  5. ;                   val val val     val      VAR    VAR
  6. ; procedure gtxtsol(gdx,gdy,color,fontlines,fontbase,instring);
  7.  
  8. gdx       equ  [BP+22]
  9. gdy       equ  [BP+20]
  10. backgnd   equ  [BP+18]
  11. color     equ  [BP+16]
  12. fontlines equ  [BP+14]
  13. fontbase  equ  [BP+10]
  14. instring  equ  [BP+6]
  15.  
  16. gtxtsol proc    far
  17.  
  18.      push      bp
  19.      mov       bp,sp
  20.      push      ds
  21. ;
  22. ; Calculate byte address (segment & offset) and bit mask
  23.  
  24. ;
  25.      mov     dx,040h         ; bios data segment
  26.      mov     ds,dx
  27.      mov     si,062h
  28.      mov     al,[si]       ; get active display page
  29.  
  30.      mov     dx,0A000h       ; base page of EGA/VGA memory
  31. ;
  32.      or      al,al           ; set flags
  33.      jz      page0           ; if zero, skip ofset add
  34.      add     dh,8            ; ofset to second page base of A800h
  35.  
  36. page0:
  37.      mov     ds,dx           ; DS := EGA buffer segment address
  38.      mov     dx,3C4h         ; Sequencer/Map Mode port address
  39.      mov     al,2
  40.      out     dx,al           ; Select "Map Mask" register 2
  41.                              ; this is the only SEQ register we'll be using
  42.      mov     dx,3CEh
  43.      mov     al,8            ; point to graphics controller register
  44.      out     dx,al           ; this is the only GR.Cont. register we'll use
  45.  
  46.  
  47.      mov     ax,gdx          ; get X address from stack frame
  48.      shr     ax,1
  49.      shr     ax,1
  50.      shr     ax,1            ; compute memory address ofset  AX := x/8
  51.      mov     gdx,ax           ; save back on stack
  52. ;
  53. ;
  54.      les     SI,instring     ; get doubleword base address of string
  55.      xor     ch,ch           ; clear ch
  56.      mov     cl,byte ptr ES:[si]  ; points to length of string
  57.  
  58. ; loop for the number of characters in the string
  59.  
  60. strloop:                     ; loop for number of characters in string
  61.      push    CX              ; save string count for outer loop
  62.      inc     SI              ; make si point to nextchar
  63. ;
  64.      mov     bl,byte ptr ES:[SI]      ; SI points to next char - read into bx
  65.      inc     bl              ; move to next char: we work from bottom to top
  66.      mov     ax,fontlines    ; get number of lines/char in font
  67.      mov     cx,ax           ; keep for use as loop counter
  68.      mul     bl              ; ax := bl (character) * al (bytes/char)
  69.      mov     bx,ax           ; leave font character ofset in BX
  70. ;
  71.      push    ES              ; save char seg.
  72.      push    SI              ; save char pointer
  73. ;
  74. ;
  75. charloop:                    ; loop through the font's scanlines bottom to top
  76. ;
  77.      mov     ax,gdy          ; get Y address (a pixel row) from stack frame
  78.      add     ax,cx           ; add scanline ofset to pixel row
  79.      dec     ax              ; compensate for 1-based numbering on CX scanlines
  80.      mov     dx,80d
  81.      mul     dx              ; AX := (y * 80)  (80 bytes per row)
  82.                              ; AX now contains Y base address (y * 80)
  83.      add     ax,gdx          ; AX := (y * 80) + x/8          (offset)
  84.  
  85.      mov     di,ax           ; save EGA memory ofset in DI
  86.  
  87.      dec     bx              ; move to next scanline in font
  88.  
  89.      les     SI,fontbase     ; get dblword base address of font
  90.  
  91. ; clear all bit planes first
  92. ;
  93.      mov     dx,3C5h
  94.      mov     ax,0Fh          ; AL := map mask (enable all bit planes here)
  95.      out     dx,al           ; Load the map mask into Seq Map Mode reg 2.
  96.  
  97.      mov     al,0
  98.      mov     [di],al         ; clear all planes
  99.  
  100. ; Set bits in the appropriate bit planes to '1' for background
  101. ;
  102.      mov     ax,backgnd      ; AL := map mask (i.e., backgnd color value)
  103.      or      al,al           ; set flags
  104.      jz      backOK          ; skip the background write if black
  105.  
  106.      out     dx,al           ; Load the map mask into SMM reg 2.
  107.                              ; This enables the appropriate bit planes.
  108.  
  109.      mov     al,ES:[BX][SI]      ;get bit mask byte from font
  110.      not     al              ; only set bits which are _not_ set in font
  111.      mov     [di],al         ; Set bits to '1' in appropriate planes. for bkgnd
  112.  
  113. ; now check to see if there are any common bit planes between the foreground
  114. ; and background. If there are, we have to use the graphics controller's
  115. ; bitmap register to "insert" the font. If not, skip this stuff and write
  116. ; faster!
  117.  
  118.      mov     ax,color
  119.      out     dx,al           ; write to mask register
  120.      and     ax,backgnd
  121.      jz      backOK          ; if no bit planes in common, then skip around
  122.  
  123.      mov     dx,3CFh
  124.      mov     al,ES:[BX][SI]  ; get bit mask byte from font
  125.      out     dx,al           ; write to bitmask register
  126.  
  127.      mov     al,[di]         ; read into bitplane latches
  128.      mov     al,0FFh
  129.      mov     [di],al         ; write to bitplanes with bitmask
  130.  
  131.      jmp     endchar
  132. ;
  133. ;
  134. backOK:                      ; now do actual foreground color
  135.      mov     ax,color        ; AL := map mask (i.e., pixel color value)
  136.      out     dx,al           ; Load the map mask into SMM reg 2.
  137.                              ; This enables the appropriate bit planes.
  138.  
  139.      mov     al,ES:[BX][SI]  ; get bit mask byte from font
  140.      mov     [di],al         ; Set bits to '1' in appropriate planes.
  141.  
  142.  
  143. endchar:
  144.  
  145.  
  146.      loop    charloop        ; decrement cx and do next scanline
  147.  
  148. ;
  149.      pop     SI              ; pop character pointer
  150.      pop     ES              ;  "     "      segement
  151.      inc     word ptr gdx    ; move screen position 8 pixels, to next char
  152.  
  153.      pop     CX              ; get outer loop - counting chars in string
  154.      loop    strloop
  155.  
  156. ; Restore default EGA graphics status
  157.      mov     dx,3C4h
  158.      mov     al,2            ; Again, select ...
  159.      out     dx,al           ; ... Sequencer/Map Mask register 2.
  160.  
  161.      mov     dx,3C5h
  162.      mov     al,0Fh          ; Default map mask
  163.      out     dx,al           ; Enable all 4 bit planes
  164.  
  165.      mov     dx,3CEh
  166.      mov     al,8            ; Again, select ...
  167.      out     dx,al           ; ... Graphics Controller register 8
  168.  
  169.      mov     dx,3CFh
  170.      mov     al,0FFh          ; Default bit mask
  171.      out     dx,al           ; Restore default bit mask
  172.  
  173.      pop       ds
  174.      pop       bp
  175.      ret       18d
  176. gtxtsol endp
  177.  
  178. code ends
  179.  
  180.      end
  181.