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

  1.         TITLE    'Listing 9-4'
  2.         NAME    DisplayCharHGC
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        DisplayCharHGC
  7. ;
  8. ; Function:    Display a character in Hercules 720x348 monochrome graphics mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void DisplayCharHGC(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             [bp-2]
  29. VARtoggle    EQU             [bp-4]
  30. VAR9bits    EQU    byte ptr [bp-6]
  31.  
  32.  
  33. _TEXT        SEGMENT    byte public 'CODE'
  34.         ASSUME    cs:_TEXT
  35.  
  36.         EXTRN    PixelAddrHGC:near
  37.  
  38.         PUBLIC    _DisplayCharHGC
  39. _DisplayCharHGC    PROC    near
  40.  
  41.         push    bp        ; preserve caller registers
  42.         mov    bp,sp
  43.         sub    sp,6        ; stack space for local variables
  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    PixelAddrHGC    ; ES:BX -> buffer
  53.                     ; CL := # bits to shift left
  54.  
  55.         xor    cl,7        ; CL := # bits to rotate right
  56.  
  57. ; set up 8- or 9-bit mask
  58.  
  59.         mov    ax,40h
  60.         mov    ds,ax        ; DS := segment of BIOS Video
  61.                     ;  Display Data area
  62.  
  63.         mov    ax,0FF00h    ; AX := 8-bit mask
  64.         mov    VAR9bits,0    ; zero this flag
  65.  
  66.         cmp    byte ptr ds:[4Ah],90    ; does CRT_COLS = 90?
  67.         je    L01        ; jump if characters are 8 pixels wide
  68.  
  69.         mov    ah,7Fh        ; AX := 9-bit mask
  70.         cmp    ARGc,0C0h
  71.         jb    L01        ; jump if character code ...
  72.  
  73.         cmp    ARGc,0DFh
  74.         ja    L01        ; ... outside of range 0C0-0DFh
  75.  
  76.         inc    VAR9bits    ; set flag to extend to 9 bits
  77.  
  78. L01:        ror    ax,cl        ; AX := bit mask in proper position
  79.         mov    VARmask,ax
  80.  
  81. ; set up foreground pixel toggle mask
  82.  
  83.         mov    ah,ARGfgd    ; AH := 0 or 1 (foreground pixel value)
  84.         ror    ah,1        ; high-order bit of AH := 0 or 1
  85.         cwd            ; propagate high-order bit through DX
  86.         not    dx        ; DX :=     0 if foreground = 1
  87.                     ;    or FFFFh if foreground = 0
  88.         mov    ax,VARmask
  89.         not    ax
  90.         and    dx,ax        ; zero unused bits of toggle mask in DX
  91.         mov    VARtoggle,dx
  92.  
  93. ; set up character definition table addressing
  94.  
  95.         push    bx        ; preserve buffer address
  96.  
  97.         mov    ch,ds:[85h]    ; CH := POINTS (pixel rows in character)
  98.  
  99.         xor    ax,ax
  100.         mov    ds,ax        ; DS := absolute zero
  101.  
  102.         mov    ax,ARGc        ; AL := character code
  103.         cmp    al,80h
  104.         jae    L02
  105.  
  106.         mov    bx,43h*4    ; DS:BX -> int 43h vector if char < 80h
  107.         jmp    short L03
  108.  
  109. L02:        mov    bx,1Fh*4    ; DS:BX -> int 1Fh vector if char >= 80h
  110.         sub    al,80h        ; put character code in range of table 
  111.  
  112. L03:        lds    si,ds:[bx]    ; DS:SI -> start of character table
  113.         mul    ch        ; AX := offset into char def table
  114.                     ;  (POINTS * char code)
  115.         add    si,ax        ; SI := addr of char def
  116.  
  117.         pop    bx        ; restore buffer address
  118.  
  119. ; mask and set pixels in the video buffer
  120.  
  121. L20:        mov    ax,VARmask
  122.         and    es:[bx],ax    ; mask character pixels in buffer
  123.  
  124.         xor    ah,ah
  125.         lodsb            ; AX := bit pattern for next pixel row
  126.         cmp    VAR9bits,0
  127.         je    L21        ; jump if character is 8 pixels wide
  128.  
  129.         ror    ax,1        ; copy lo-order bit of AX into ...
  130.         rcl    al,1        ;  hi-order bit
  131.  
  132. L21:        ror    ax,cl        ; rotate pixels into position
  133.         xor    ax,VARtoggle    ; toggle pixels if foreground = 0
  134.         or    es:[bx],ax    ; store pixels in buffer
  135.  
  136.         add    bx,2000h    ; increment to next portion of interleave
  137.         jns    L22
  138.  
  139.         add    bx,90-8000h    ; increment to first portion of interleave
  140.  
  141. L22:        dec    ch
  142.         jnz    L20
  143.  
  144.  
  145. Lexit:        pop    ds        ; restore registers and return
  146.         pop    di
  147.         pop    si
  148.         mov    sp,bp
  149.         pop    bp
  150.         ret
  151.  
  152. _DisplayCharHGC    ENDP
  153.  
  154. _TEXT        ENDS
  155.  
  156.         END
  157.