home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / GUILIB.ZIP / DISPCHAR.ASM < prev    next >
Assembly Source File  |  1992-11-27  |  5KB  |  204 lines

  1.         TITLE    'Listing 9-6'
  2.         NAME    DisplayChar10
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        DisplayChar10
  7. ;
  8. ; Function:    Display a character in native EGA and VGA graphics modes
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void DisplayChar10(c,x,y,fgd,bkgd);
  13. ;
  14. ;            int c;            /* character code */
  15. ;
  16. ;            int x,y;        /* upper left pixel */
  17. ;
  18. ;            int fgd,bkgd;        /* foreground and background
  19. ;                            pixel values */
  20. ;
  21.  
  22. ARGc        EQU    word ptr [bp+4]    ; stack frame addressing
  23. ARGx        EQU    word ptr [bp+6]
  24. ARGy        EQU    word ptr [bp+8]
  25. ARGfgd        EQU    byte ptr [bp+10]
  26. ARGbkgd        EQU    byte ptr [bp+12]
  27.  
  28. VARshift    EQU             [bp-2]
  29.  
  30. BytesPerLine    =    80        ; (must 40 in 320x200 16-color mode)
  31. RMWbits        =    00h        ; Read-Modify-Write bits
  32.  
  33. _TEXT        SEGMENT    byte public 'CODE'
  34.         ASSUME    cs:_TEXT
  35.  
  36.         EXTRN    PixelAddr10:near
  37.  
  38.         PUBLIC    _DisplayChar10
  39. _DisplayChar10    PROC    near
  40.  
  41.         push    bp        ; preserve caller registers
  42.         mov    bp,sp
  43.         sub    sp,2        ; stack space for local variable
  44.         push    si
  45.         push    di
  46.         push    ds
  47.  
  48. ; calculate first pixel address
  49.  
  50.         mov    ax,ARGy        ; AX := y
  51.         mov    bx,ARGx        ; BX := x
  52.         call    PixelAddr10    ; ES:BX -> buffer
  53.                     ; CL := # bits to shift left to mask
  54.                     ;  pixel
  55.         inc    cx
  56.         and    cl,7        ; CL := # bits to shift to mask char
  57.  
  58.         mov    ch,0FFh
  59.         shl    ch,cl        ; CH := bit mask for right side of char
  60.         mov    VARshift,cx
  61.  
  62.         push    es        ; preserve video buffer segment
  63.         mov    si,bx        ; SI := video buffer offset
  64.  
  65. ; set up character definition table addressing
  66.  
  67.         mov    ax,40h
  68.         mov    ds,ax        ; DS := segment of BIOS Video
  69.                     ;  Display Data area
  70.         mov    cx,ds:[85h]    ; CX := POINTS (pixel rows in character)
  71.  
  72.         xor    ax,ax
  73.         mov    ds,ax        ; DS := absolute zero
  74.  
  75.         mov    ax,ARGc        ; AL := character code
  76.         mov    bx,43h*4    ; DS:BX -> int 43h vector
  77.         les    di,ds:[bx]    ; ES:DI -> start of character table
  78.         mul    cl        ; AX := offset into char def table
  79.                     ;  (POINTS * char code)
  80.         add    di,ax        ; DI := addr of char def
  81.  
  82.         pop    ds        ; DS:SI -> video buffer
  83.  
  84. ; set up Graphics Controller registers
  85.  
  86.         mov    dx,3CEh        ; Graphics Controller address reg port
  87.  
  88.         mov    ax,0A05h    ; AL :=  Mode register number
  89.                     ; AH :=  Write Mode 2 (bits 0-1)
  90.                     ;     Read Mode 1 (bit 4)
  91.         out    dx,ax
  92.  
  93.         mov    ah,RMWbits    ; AH := Read-Modify-Write bits
  94.         mov    al,3        ; AL := Data Rotate/Function Select reg
  95.         out    dx,ax
  96.  
  97.         mov    ax,0007        ; AH := Color Don't Care bits
  98.                     ; AL := Color Don't Care reg number
  99.         out    dx,ax        ; "don't care" for all bit planes 
  100.  
  101. ; select output routine depending on whether character is byte-aligned
  102.  
  103.         mov    bl,ARGfgd    ; BL := foreground pixel value
  104.         mov    bh,ARGbkgd    ; BH := background pixel value
  105.  
  106.         cmp    byte ptr VARshift,0   ; test # bits to shift
  107.         jne    L20        ; jump if character is not byte-aligned
  108.  
  109.  
  110. ; routine for byte-aligned characters
  111.  
  112.         mov    al,8        ; AL := Bit Mask register number 
  113.  
  114. L10:        mov    ah,es:[di]    ; AH := pattern for next row of pixels
  115.         out    dx,ax        ; update Bit Mask register
  116.         and    [si],bl        ; update foreground pixels
  117.  
  118.         not    ah
  119.         out    dx,ax
  120.         and    [si],bh        ; update background pixels
  121.  
  122.         inc    di        ; ES:DI -> next byte in char def table
  123.         add    si,BytesPerLine    ; increment to next line in video buffer
  124.         loop    L10
  125.         jmp    short Lexit
  126.  
  127.  
  128. ; routine for non-byte-aligned characters
  129.  
  130. L20:        push    cx        ; preserve loop counter
  131.         mov    cx,VARshift    ; CH := mask for left side of character
  132.                     ; CL := # bits to shift left
  133. ; left side of character
  134.  
  135.         mov    al,es:[di]    ; AL := bits for next row of pixels
  136.         xor    ah,ah
  137.         shl    ax,cl        ; AH := bits for left side of char
  138.                     ; AL := bits for right side of char
  139.         push    ax        ; save bits for right side on stack
  140.         mov    al,8        ; AL := Bit Mask Register number
  141.         out    dx,ax        ; set bit mask for foreground pixels
  142.  
  143.         and    [si],bl        ; update foreground pixels
  144.  
  145.         not    ch        ; CH := mask for left side of char
  146.         xor    ah,ch        ; AH := bits for background pixels
  147.         out    dx,ax        ; set bit mask
  148.  
  149.         and    [si],bh        ; update background pixels
  150.  
  151. ; right side of character
  152.  
  153.         pop    ax
  154.         mov    ah,al        ; AH := bits for right side of char
  155.         mov    al,8
  156.         out    dx,ax        ; set bit mask
  157.  
  158.         inc    si        ; DS:SI -> right side of char in buffer
  159.  
  160.         and    [si],bl        ; update foreground pixels
  161.  
  162.         not    ch        ; CH := mask for right side of char
  163.         xor    ah,ch        ; AH := bits for background pixels
  164.         out    dx,ax        ; set bit mask
  165.  
  166.         and    [si],bh        ; update background pixels
  167.  
  168. ; increment to next row of pixels in character
  169.  
  170.         inc    di        ; ES:DI -> next byte in char def table
  171.         dec    si
  172.         add    si,BytesPerLine    ; DS:SI -> next line in video buffer
  173.  
  174.         pop    cx
  175.         loop    L20
  176.  
  177.  
  178. ; restore default Graphics Controller registers
  179.  
  180. Lexit:        mov    ax,0FF08h    ; default Bit Mask
  181.         out    dx,ax
  182.  
  183.         mov    ax,0005        ; default Mode register
  184.         out    dx,ax
  185.  
  186.         mov    ax,0003        ; default Data Rotate/Function Select
  187.         out    dx,ax
  188.  
  189.         mov    ax,0F07h    ; default Color Don't Care
  190.         out    dx,ax
  191.  
  192.         pop    ds        ; restore caller registers and return
  193.         pop    di
  194.         pop    si
  195.         mov    sp,bp
  196.         pop    bp
  197.         ret
  198.  
  199. _DisplayChar10    ENDP
  200.  
  201. _TEXT        ENDS
  202.  
  203.         END
  204.