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

  1.         TITLE    'Listing 9-5'
  2.         NAME    DisplayChar13
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        DisplayChar13
  7. ;
  8. ; Function:    Display a character in MCGA/VGA 320x200 256-color mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void DisplayChar13(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. BytesPerLine    EQU    320
  29.  
  30. _TEXT        SEGMENT    byte public 'CODE'
  31.         ASSUME    cs:_TEXT
  32.  
  33.         EXTRN    PixelAddr13:near
  34.  
  35.         PUBLIC    _DisplayChar13
  36. _DisplayChar13    PROC    near
  37.  
  38.         push    bp        ; preserve caller registers
  39.         mov    bp,sp
  40.         push    si
  41.         push    di
  42.         push    ds
  43.  
  44. ; calculate first pixel address
  45.  
  46.         mov    ax,ARGy        ; AX := y
  47.         mov    bx,ARGx        ; BX := x
  48.         call    PixelAddr13    ; ES:BX -> buffer
  49.         mov    di,bx        ; ES:DI -> buffer
  50.  
  51. ; set up character definition table addressing
  52.  
  53.         mov    ax,40h
  54.         mov    ds,ax        ; DS := segment of BIOS Video
  55.                     ;  Display Data area
  56.         mov    cx,ds:[85h]    ; CX := POINTS (pixel rows in character)
  57.  
  58.         xor    ax,ax
  59.         mov    ds,ax        ; DS := absolute zero
  60.  
  61.         mov    ax,ARGc        ; AL := character code
  62.         mov    bx,43h*4    ; DS:BX -> int 43h vector if char < 80h
  63.         lds    si,ds:[bx]    ; DS:SI -> start of character table
  64.         mul    cl        ; AX := offset into char def table
  65.                     ;  (POINTS * char code)
  66.         add    si,ax        ; SI := addr of char def
  67.         
  68. ; store the character in the video buffer
  69.  
  70.         mov    bl,ARGfgd    ; BL := foreground pixel value
  71.         mov    bh,ARGbkgd    ; BH := background pixel value
  72.  
  73. L10:        push    cx        ; preserve CX across loop
  74.         mov    cx,8        ; CX := character width in pixels
  75.         lodsb
  76.         mov    ah,al        ; AH := bit pattern for next pixel row
  77.  
  78. L11:        mov    al,bl        ; AL := foreground pixel value
  79.         shl    ah,1        ; carry flag := high-order bit
  80.         jc    L12        ; jump if bit pattern specifies a
  81.                     ;  foreground pixel (bit = 1)
  82.         mov    al,bh        ; AL := background pixel value
  83.  
  84. L12:        stosb            ; update one pixel in the buffer
  85.         loop    L11
  86.  
  87.         add    di,BytesPerLine-8 ; increment buffer address to next
  88.                       ;  row of pixels
  89.         pop    cx
  90.         loop    L10        ; loop down character
  91.  
  92.         pop    ds        ; restore registers and return
  93.         pop    di
  94.         pop    si
  95.         mov    sp,bp
  96.         pop    bp
  97.         ret
  98.  
  99. _DisplayChar13    ENDP
  100.  
  101. _TEXT        ENDS
  102.  
  103.         END
  104.