home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / DRIVERS / IBMPC / CGACHAR.ASM < prev    next >
Assembly Source File  |  2000-02-11  |  3KB  |  141 lines

  1. ;
  2. ; Name:        _cgachar
  3. ;
  4. ; Function:    Display a character in 640*200 2-colour mode
  5. ;
  6. ; Call:        Microsoft C:
  7. ;
  8. ;        void
  9. ;        _cgachar(c, x, y, fgd, bkgd)
  10. ;        int    c;            /* character code */
  11. ;        int    x, y;            /* upper left pixel */
  12. ;        int    fgd, bkgd;        /* fore and background pixel values */
  13. ;
  14. ;
  15.  
  16. argc        equ    word ptr [bp+6]    ; stack frame addressing
  17. argx        equ    word ptr [bp+8]
  18. argy        equ    word ptr [bp+10]
  19. argfgd        equ    byte ptr [bp+12]
  20. argbkgd        equ    byte ptr [bp+14]
  21.  
  22. varmask        equ    [bp-8]
  23. vartoggle    equ    [bp-10]
  24.  
  25.         extrn    _chartab:word
  26.         extrn    __fontsize:word
  27.         extrn    cgapaddr:far
  28.  
  29. CGAA_TEXT    segment byte public 'CODE'
  30.         assume    cs:CGAA_TEXT
  31.  
  32.         public    _cgachar
  33. _cgachar    proc    far
  34.  
  35.         push    bp        ; preserve call registers
  36.         mov    bp,sp
  37.         sub    sp,8        ; stack space for local variables
  38.         push    di
  39.         push    si
  40.         push    ds
  41.  
  42. ; set up foreground pixel toggle mask
  43.  
  44.         mov    ah,argfgd    ; AH = 0 or 1 (foreground pixel value)
  45.         ror    ah,1        ; high order bit of AH = 0 or 1
  46.         cwd            ; propogate high-order bit through DX
  47.         not    dx
  48.         mov    vartoggle,dx
  49.  
  50. ; calculate first pixel address
  51.  
  52.         mov    ax,argy        ; ax = y
  53.         mov    bx,argx        ; bx = x
  54.         sub    ax,__fontsize
  55.         call    cgapaddr    ; ES:BX -> buffer
  56.                     ; CL = # bits to shift left
  57.  
  58.         xor    cl,7        ; CL = # bits to rotate right
  59.  
  60.         mov    ax,0FF00h
  61.         ror    ax,cl        ; AX = bit mask in proper position
  62.         mov    varmask,ax
  63.  
  64. ; set up video buffer addressing
  65.  
  66.         mov    dx,2000h    ; increment for video buffer interleave
  67.         mov    di,80-2000h    ; increment from last to first interleave
  68.         test    bx,2000h    ; set zero flag if BX is 1st interleave
  69.         jz    L01
  70.  
  71.         xchg    di,dx        ; exchange increment values if 1st pixel
  72.                     ; lies in 1st interleave
  73.  
  74. ; set up character definition table addressing
  75.  
  76. L01:        mov    ch,byte ptr __fontsize
  77.         cmp    ch,16
  78.         je    big
  79.  
  80.         mov    ax,0f000h
  81.         mov    ds,ax
  82.         mov    ax,0fa6eh
  83.         mov    si,ax
  84.         
  85.         jmp    cont1
  86. big:
  87.         mov    ax, SEG _chartab
  88.         mov    ds, ax
  89.         mov    si, OFFSET _chartab
  90. cont1:
  91.         mov    ax,argc
  92.         mul    ch
  93.         add    si,ax
  94.         
  95.         test    cl,cl        ; test # bits to rotate
  96.         jnz    L20        ; jump if character is not byte aligned
  97.  
  98. ; routine for byte-aligned characters
  99.  
  100.         mov    ah,vartoggle    ; AH = foreground toggle mask
  101.         xchg    ch,cl        ; CX = points
  102.  
  103. L10:        lodsb            ; AL = bit patterb for next pixel row
  104.         xor    al,ah        ; toggle pixels if foreground = 0
  105.         mov    es:[bx],al    ; store pixels in buffer
  106.  
  107.         add    bx,dx        ; BX = next row in buffer
  108.         xchg    di,dx        ; swap buffer increments
  109.         loop    L10
  110.         jmp    short Lexit
  111.  
  112. ; routine for non byte-aligned characters
  113.  
  114. L20:        mov    ax,varmask
  115.         and    es:[bx],ax    ; mask character pixels in buffer
  116.  
  117.         xor    ah,ah
  118.         lodsb            ; AX = bit pattern for next pixel row
  119.         xor    al,vartoggle    ; toggle pixels if foreground = 0
  120.  
  121.         ror    ax,cl        ; rotate pixels into position
  122.         or    es:[bx],ax    ; store pixels in buffer
  123.  
  124.         add    bx,dx        ; BX = next row in buffer
  125.         xchg    di,dx        ; swap buffer increments
  126.         dec    ch
  127.         jnz    L20
  128.  
  129. Lexit:        pop    ds        ; restore caller registers and return
  130.         pop    si
  131.         pop    di
  132.         mov    sp,bp
  133.         pop    bp
  134.         ret
  135.  
  136. _cgachar    endp
  137.  
  138. CGAA_TEXT    ends
  139.  
  140.         end
  141.