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

  1. code      segment   byte public
  2. assume    cs:code
  3. public    gtxttran
  4. page 60,132
  5. ;                    val val val     val      VAR    VAR
  6. ; procedure gtxttran(gdx,gdy,color,fontlines,fontbase,instring);
  7. ; transparent text writing
  8. ;
  9. gdx       equ  [BP+20]
  10. gdy       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. gtxttran 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.  
  39.      mov     dx,3CEh         ; Graphics Controller port address
  40.      mov     al,8
  41.      out     dx,al           ; select register 8
  42.  
  43.      mov     dx,3C4h         ; Sequencer/Map Mode port address
  44.      mov     al,2
  45.      out     dx,al           ; Select "Map Mask" register 2
  46.  
  47.  
  48. ;
  49.      mov     ax,gdx          ; get X address from stack frame
  50.      shr     ax,1
  51.      shr     ax,1
  52.      shr     ax,1            ; compute memory address ofset  AX := x/8
  53.      mov     gdx,ax           ; save back on stack
  54. ;
  55.      les     SI,instring     ; get doulbleword base address of string
  56.      xor     ch,ch           ; clear ch
  57.      mov     cl,byte ptr ES:[si]  ; points to length of string
  58. strloop:                     ; loop for number of characters in string
  59.      push    CX              ; save string count for outer loop
  60.      inc     SI              ; make si point to nextchar
  61.      mov     bl,byte ptr ES:[SI]      ; SI points to next char - read into bx
  62.      inc     bl              ; move to next char: we work from bottom to top
  63.      mov     ax,fontlines    ; get number of lines/char in font
  64.      mov     cx,ax           ; keep for use as loop counter
  65.      mul     bl              ; ax := bl (character) * al (bytes/char)
  66.      mov     bx,ax           ; leave font character ofset in BX
  67.      push    ES              ; save char seg.
  68.      push    SI              ; save char pointer
  69.  
  70. ;
  71. ; loop for the number of lines
  72. charloop:                    ; loop through the font's scanlines bottom to top
  73. ;
  74.      mov     ax,gdy          ; get Y address (a pixel row)
  75.      add     ax,cx           ; add in scanlin ofset to Y value
  76.      dec     ax              ; subtract 1 because cx is 1 based inst. of 0
  77.      mov     dx,80d
  78.      mul     dx              ; AX := (y * 80)  (80 bytes per row)
  79.  
  80.      add     ax,gdx          ; AX := (y * 80) + x/8          (offset)
  81.  
  82.      mov     di,ax           ; save EGA memory ofset in DI
  83.  
  84. ; Set the "Bit Mask" register
  85.      dec     bx              ; move to next scanline in font
  86.  
  87.      les     SI,fontbase     ; get dblword base address of font
  88. ;
  89.  
  90.      mov     dx,3CFh         ; bit mask register
  91.      mov     al,ES:[BX][SI]  ; get bit mask byte from font
  92.      out     dx,al           ; load the bit mask into reg 8
  93.      mov     dx,3C5h         ; seq mapmode reg.
  94.      mov     al,0Fh          ; enablee writes to all planes for
  95.                              ; pixels where the char will go
  96.      out     dx,al
  97. ;
  98.  
  99.  
  100. ; Set all 4 bits in the pixel to '0'
  101.      mov     al,[di]         ; Read at address A000:offset
  102.                                 ; This latches all 4 bit planes.
  103.                                 ; (The byte "read" is ignored.)
  104.      mov     al,0
  105.      mov     [di],al         ; Write at address A000:offset
  106.                                 ; This sets the bit-masked bits to '0'
  107.                                 ; and stores the latched bytes to the
  108.                                 ; bit planes
  109.  
  110. ; Set bits in the appropriate bit planes to '1'
  111.  
  112.      mov     ax,color        ; AL := map mask (i.e., pixel color value)
  113.      out     dx,al           ; Load the map mask into SMM reg 2.
  114.                                 ; This enables the appropriate bit planes.
  115.  
  116.      mov     al,[di]         ; Latch the bit plane data.
  117.      mov     al,0FFh
  118.      mov     [di],al         ; Set bits to '1' in appropriate planes.
  119.  
  120. ;
  121.  
  122.  
  123.      loop    charloop        ; decrement cx and do next scanline
  124.  
  125.      pop     SI              ; pop character pointer
  126.      pop     ES              ;  "     "      segement
  127.      inc     word ptr gdx    ; move screen position to next char over
  128.  
  129.      pop     CX              ; get outer loop - counting chars in string
  130.      loop    strloop
  131.  
  132. ; Restore default EGA graphics status
  133.      mov     dx,3C4h
  134.      mov     al,2            ; Again, select ...
  135.      out     dx,al           ; ... Sequencer/Map Mask register 2.
  136.  
  137.      mov     dx,3C5h
  138.      mov     al,0Fh          ; Default map mask
  139.      out     dx,al           ; Enable all 4 bit planes
  140.  
  141.      mov     dx,3CEh
  142.      mov     al,8            ; Again, select ...
  143.      out     dx,al           ; ... Graphics Controller register 8
  144.  
  145.      mov     dx,3CFh
  146.      mov     al,0FFh          ; Default bit mask
  147.      out     dx,al           ; Restore default bit mask
  148.  
  149.      pop       ds
  150.      pop       bp
  151.      ret       16d
  152. gtxttran endp
  153.  
  154. code ends
  155.  
  156.      end
  157.