home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 9 / 9_7.asm < prev   
Encoding:
Assembly Source File  |  1988-08-11  |  4.1 KB  |  181 lines

  1.         TITLE    'Listing 9-7'
  2.         NAME    DisplayCharInC
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        DisplayCharInC
  7. ;
  8. ; Function:    Display a character in InColor 720x348 16-color mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void DisplayCharInC(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. VARmask        EQU    word ptr [bp-2]
  29. VAR9bits    EQU    byte ptr [bp-4]
  30.  
  31. _TEXT        SEGMENT    byte public 'CODE'
  32.         ASSUME    cs:_TEXT
  33.  
  34.         EXTRN    PixelAddrHGC:near
  35.  
  36.         PUBLIC    _DisplayCharInC
  37. _DisplayCharInC    PROC    near
  38.  
  39.         push    bp        ; preserve caller registers
  40.         mov    bp,sp
  41.         sub    sp,4        ; stack space for local variables
  42.         push    si
  43.         push    di
  44.         push    ds
  45.  
  46. ; calculate first pixel address
  47.  
  48.         mov    ax,ARGy        ; AX := y
  49.         mov    bx,ARGx        ; BX := x
  50.         call    PixelAddrHGC    ; ES:BX -> buffer
  51.                     ; CL := # bits to shift left to mask
  52.                     ;  pixel
  53.         xor    cl,7        ; CL := # bits to rotate right
  54.  
  55.         push    es        ; preserve video buffer segment
  56.         mov    si,bx        ; DI := video buffer offset
  57.  
  58. ; set up flag for 8- or 9-bit characters
  59.  
  60.         mov    ax,40h
  61.         mov    ds,ax        ; DS := segment of BIOS Video
  62.                     ;  Display Data area
  63.  
  64.         mov    ax,0FF00h    ; AX := 8-bit mask
  65.         mov    VAR9bits,0    ; zero this flag
  66.  
  67.         cmp    byte ptr ds:[4Ah],90    ; does CRT_COLS = 90?
  68.         je    L01        ; jump if characters are 8 pixels wide
  69.  
  70.         mov    ah,7Fh        ; AX := 9-bit mask
  71.         cmp    ARGc,0C0h
  72.         jb    L01        ; jump if character code ...
  73.  
  74.         cmp    ARGc,0DFh
  75.         ja    L01        ; ... outside of range 0C0-0DFh
  76.  
  77.         inc    VAR9bits    ; set flag to extend to 9 bits
  78.  
  79. L01:        ror    ax,cl        ; AX := bit mask in proper position
  80.         mov    VARmask,ax
  81.  
  82. ; set up character definition table addressing
  83.  
  84.         mov    ax,40h
  85.         mov    ds,ax        ; DS := segment of BIOS Video
  86.                     ;  Display Data area
  87.         mov    ch,ds:[85h]    ; CH := POINTS (pixel rows in character)
  88.  
  89.         xor    ax,ax
  90.         mov    ds,ax        ; DS := absolute zero
  91.  
  92.         mov    ax,ARGc        ; AL := character code
  93.         cmp    al,80h
  94.         jae    L02
  95.  
  96.         mov    bx,43h*4    ; DS:BX -> int 43h vector if char < 80h
  97.         jmp    short L03
  98.  
  99. L02:        mov    bx,1Fh*4    ; DS:BX -> int 1Fh vector if char >= 80h
  100.         sub    al,80h        ; put character code in range of table 
  101.  
  102. L03:        les    di,ds:[bx]    ; ES:DI -> start of character table
  103.         mul    ch        ; AX := offset into char def table
  104.                     ;  (POINTS * char code)
  105.         add    di,ax        ; DI := addr of char def
  106.  
  107.         pop    ds        ; DS:SI -> video buffer
  108.  
  109. ; set up control registers
  110.  
  111.         mov    dx,3B4h        ; control register I/O port
  112.  
  113.         push    cx        ; preserve CX
  114.         mov    ah,ARGbkgd    ; AH := background pixel value
  115.         mov    cl,4
  116.         shl    ah,cl        ; AH bits 4-7 := background pixel value
  117.         or    ah,ARGfgd    ; AH bits 0-3 := foreground pixel value
  118.         pop    cx        ; restore CX
  119.  
  120.         mov    al,1Ah        ; AL := Read/Write Color reg number
  121.         out    dx,ax        ; set Read/Write Color value
  122.  
  123. ; mask and set pixels in the video buffer
  124.  
  125. L20:        xor    bh,bh
  126.         mov    bl,es:[di]    ; BX := bit pattern for next pixel row
  127.         inc    di        ; increment pointer to char def table
  128.         cmp    VAR9bits,0
  129.  
  130.         je    L21        ; jump if character is 8 pixels wide
  131.  
  132.         ror    bx,1        ; copy lo-order bit of BX into ...
  133.         rcl    bl,1        ;  hi-order bit
  134.  
  135. L21:        ror    bx,cl        ; rotate pixels into position
  136.  
  137.         mov    ax,5F19h    ; AH bit 6 := 1 (mask polarity)
  138.                     ; AH bits 4-5 := 01b (write mode 1)
  139.                     ; AH bits 0-3 := 1111b (don't care bits)
  140.                     ; AL := 19h (Read/Write Control reg)
  141.         out    dx,ax        ; set up Read/Write control reg
  142.  
  143.         or    [si],bl        ; update foreground pixels
  144.         or    [si+1],bh
  145.  
  146.         mov    ah,6Fh        ; set up write mode 2
  147.         out    dx,ax
  148.  
  149.         or    bx,VARmask    ; BX := background pixel bit pattern
  150.         or    [si],bl        ; update background pixels
  151.         or    [si+1],bh
  152.  
  153.         add    si,2000h    ; increment to next portion of interleave
  154.         jns    L22
  155.  
  156.         add    si,90-8000h    ; increment to first portion of interleave
  157.  
  158. L22:        dec    ch
  159.         jnz    L20
  160.  
  161. ; restore default InColor register values
  162.  
  163.         mov    ax,4019h    ; default Read/Write Control reg
  164.         out    dx,ax
  165.  
  166.         mov    ax,071Ah    ; default Read/Write Color reg
  167.         out    dx,ax
  168.  
  169.         pop    ds        ; restore registers and return
  170.         pop    di
  171.         pop    si
  172.         mov    sp,bp
  173.         pop    bp
  174.         ret
  175.  
  176. _DisplayCharInC    ENDP
  177.  
  178. _TEXT        ENDS
  179.  
  180.         END
  181.