home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 10 / 10_12.asm next >
Encoding:
Assembly Source File  |  1988-08-11  |  4.5 KB  |  178 lines

  1.         TITLE    'Listing 10-12'
  2.         NAME    AlphaModeSet
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        AlphaModeSet
  7. ;
  8. ;        Program the CRTC in 80-column EGA alphanumeric modes
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            void AlphaModeSet(w,h,c);
  13. ;
  14. ;            int    w;    /* width of character matrix */
  15. ;            int    h;    /* height of character matrix */
  16. ;            int    c;    /* character code size */
  17. ;
  18.  
  19. ARGw        EQU    byte ptr [bp+4]        ; must be 8 or 9 pixels wide
  20. ARGh        EQU    byte ptr [bp+6]        ; must be 2-32 pixels high
  21. ARGc        EQU    byte ptr [bp+8]        ; must be 8 or 9 bits
  22.  
  23. CRT_MODE    EQU    49h        ; addresses in video BIOS data area
  24. CRT_COLS    EQU    4Ah
  25. ADDR_6845    EQU    63h
  26.  
  27. DGROUP        GROUP    _DATA
  28.  
  29. _TEXT        SEGMENT    byte public 'CODE'
  30.         ASSUME    cs:_TEXT,ds:DGROUP
  31.  
  32.         PUBLIC    _AlphaModeSet
  33. _AlphaModeSet    PROC    near
  34.  
  35.         push    bp        ; preserve caller registers
  36.         mov    bp,sp
  37.         push    si
  38.  
  39. ; Program the CRTC
  40.  
  41.         mov    bx,40h
  42.         mov    es,bx        ; ES := video BIOS data segment
  43.  
  44.         mov    bl,ARGw        ; BL := character width
  45.         mov    bh,ARGh        ; BH := character height
  46.         call    SetCRTC
  47.  
  48. ; Program the Sequencer and Attribute Controller for 8 or 9 dots per character
  49.  
  50.         mov    dx,3C4h
  51.         mov    ax,0100h    ; AH bit 1 := 0 (synchronous reset)
  52.                     ; AL := 0 (Reset register number)
  53.         cli            ; disable interrupts
  54.         out    dx,ax        ; Sequencer synchronous reset
  55.  
  56.         mov    bx,1        ; BH,BL := values for 8-wide chars:
  57.                     ;  BH := 0 (value for Horiz Pel Pan)
  58.                     ;  BL := 1 (value for Clocking Mode)
  59.         cmp    ARGw,8
  60.         je    L01        ; jump if 8-wide characters
  61.  
  62.         mov    bx,0800h    ; BH,BL := values for 9-wide characters
  63.  
  64. L01:        mov    ah,bl        ; AH := value for Clocking Mode reg
  65.         mov    al,1        ; AL := Clocking Mode reg number
  66.         out    dx,ax        ; program the Sequencer
  67.  
  68.         mov    ax,0300h    ; AH := 3 (disable reset)
  69.                     ; AL := 0 (Sequencer register number)
  70.         out    dx,ax        ; disable Sequencer reset
  71.         sti            ; enable interrupts
  72.  
  73.         mov    bl,13h        ; BL := Horizontal Pel Pan reg number
  74.         mov    ax,1000h    ; AH := 10H (INT 10H function number)
  75.                     ; AL := 0 (set specified register)
  76.         int    10h        ; program Attribute Controller
  77.  
  78. ; Program the Attribute Controller for 8- or 9-bit character codes
  79.  
  80.         mov    ax,1000h    ; AH := 10H (INT 10H function number)
  81.                     ; AL := 0 (set specified register)
  82.         mov    bx,0F12h    ; BH := 0FH (Color Plane Enable value)
  83.                     ; BL := 12H (Color Plane Enable reg #)
  84.         cmp    ARGc,8
  85.         je    L02        ; jump if 8-bit character codes
  86.  
  87.         mov    bh,7        ; BH bit 3 := 0 (ignore bit 3 of all
  88.                     ;  attributes)
  89. L02:        int    10h        ; update Color Plane Enable register
  90.  
  91. ; update video BIOS data area
  92.  
  93.         cmp    byte ptr es:[CRT_MODE],7
  94.         jne    L03        ; jump if not monochrome mode
  95.  
  96.         mov    ax,720        ; AX := displayed pixels per row
  97.         div    ARGw        ; AL := displayed character columns
  98.         mov    es:[CRT_COLS],al
  99.  
  100. L03:        pop    si
  101.         pop    bp
  102.         ret
  103.  
  104. _AlphaModeSet    ENDP
  105.  
  106.  
  107. SetCRTC         PROC    near        ; Caller:    BH = character height
  108.                     ;        BL = character width
  109.  
  110.         push    dx
  111.         mov    dx,es:[ADDR_6845]  ; CRTC I/O port
  112.  
  113. ; establish CRTC vertical timing and cursor position in character matrix
  114.  
  115.         push    bx        ; preserve height and width
  116.         mov    ax,1110h    ; AH := 11H (INT 10H function number)
  117.                     ; AL := 0 (user alpha load)
  118.         xor    cx,cx        ; CX := 0 (store no characters)
  119.         int    10h        ; call BIOS to program CRTC for
  120.                     ;  vertical size of characters
  121.  
  122.         pop    ax        ; AH := character height
  123.         push    ax        ; preserve height and width
  124.         sub    ah,2        ; AH := starting scan line for cursor
  125.         mov    al,0Ah        ; AL := 0AH (Cursor Start reg number)
  126.         out    dx,ax        ; update CRTC Cursor Start register
  127.  
  128.         mov    ax,000Bh    ; AH := 0 (Cursor End value)
  129.                     ; AL := 0BH (Cursor End reg number)
  130.         out    dx,ax        ; update CRTC Cursor End register
  131.  
  132. ; establish CRTC horizontal timing
  133.  
  134.         pop    bx        ; BX := character height and width
  135.         cmp    byte ptr es:[CRT_MODE],7
  136.         jne    L10        ; exit if not monochrome mode
  137.  
  138.         xor    bh,bh        ; BX := character width
  139.         sub    bl,8        ; BX := 0 or 1
  140.         neg    bx        ; BX := 0 or 0FFFFH
  141.         and    bx,14        ; BX := 0 or 14 (offset into table)
  142.         mov    si,bx        ; SI := offset into table
  143.  
  144.         add    si,offset DGROUP:HorizParms    ; DS:SI -> parameters
  145.         call    UpdateCRTC
  146.  
  147. L10:        pop    dx
  148.         ret
  149.  
  150. SetCRTC         ENDP
  151.  
  152.  
  153. UpdateCRTC    PROC    near        ; Caller:    DX = CRTC address port
  154.                     ;        DS:SI -> parameters
  155.                     ; Destroys:    AX,CX
  156.  
  157.         mov    cx,7        ; CX := number of registers to update
  158.         
  159. L20:        lodsw            ; AH := data for CRTC register in AL
  160.         out    dx,ax        ; update the register
  161.         loop    L20
  162.  
  163.         ret
  164.  
  165. UpdateCRTC    ENDP
  166.  
  167. _TEXT        ENDS
  168.  
  169.  
  170. _DATA        SEGMENT    word public 'DATA'
  171.  
  172. HorizParms    DW    6C00h,5901h,6002h,2403h,5B04h,6A05h,2D13h  ; 8-wide
  173.         DW    6000h,4F01h,5602h,3A03h,5104h,6005h,2813h  ; 9-wide
  174.  
  175. _DATA        ENDS
  176.  
  177.         END
  178.