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

  1.         TITLE    'Listing 10-14'
  2.         NAME    AlphaModeSet
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        AlphaModeSet
  7. ;
  8. ; Function:    Program the CRTC in alphanumeric modes on HGC+ or InColor card
  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 4-16 pixels high
  21. ARGc        EQU    byte ptr [bp+8]        ; must be 8 or 12 bits
  22.  
  23. CRT_COLS    EQU    4Ah
  24. CRT_LEN        EQU    4Ch
  25. CRT_MODE_SET    EQU    65h
  26. ROWS        EQU    84h
  27.  
  28. DGROUP        GROUP    _DATA
  29.  
  30. _TEXT        SEGMENT    byte public 'CODE'
  31.         ASSUME    cs:_TEXT,ds:DGROUP
  32.  
  33.         PUBLIC    _AlphaModeSet
  34. _AlphaModeSet    PROC    near
  35.  
  36.         push    bp        ; preserve caller registers
  37.         mov    bp,sp
  38.         push    ds
  39.         push    si
  40.  
  41. ; Set Configuration Switch to bring RAM starting at B000:4000 into memory map
  42.  
  43.         mov    dx,3BFh        ; DX := Configuration Switch port
  44.         mov    al,1        ; AL bit 1 := 0 (exclude 2nd 32K of
  45.                     ;          video buffer)
  46.                     ; AL bit 0 := 1 (make RAM at B000:4000
  47.         out    dx,ax        ;          addressable)
  48.  
  49. ; Blank the screen to avoid interference during CRTC programming
  50.  
  51.         mov    dx,3B8h        ; DX := CRTC Mode Control Register port
  52.         xor    al,al        ; AL bit 3 := 0 (disable video signal)
  53.         out    dx,al        ; blank the screen
  54.  
  55. ; Program the CRTC
  56.  
  57.         mov    bh,ARGw        ; BH := character width
  58.         mov    bl,ARGh        ; BL := character height
  59.         call    SetHercCRTC
  60.  
  61. ; Set the xModeReg
  62.  
  63.         mov    dx,3B4h        ; DX := CRTC address port
  64.         mov    ax,114h        ; AH bit 0 := 1 (enable RAM-based
  65.                     ;  character generator)
  66.                     ; AL := 14h (xModeReg number)
  67.         cmp    ARGw,9
  68.         je    L01        ; jump if 9-wide characters
  69.  
  70.         or    ah,2        ; AH bit 1 := 1 (8-wide characters)
  71.  
  72. L01:        cmp    ARGc,8
  73.         je    L02        ; jump if 8-bit character codes
  74.  
  75.         or    ah,4        ; AH bit 2 := 1 (12-bit character codes)
  76.  
  77. L02:        out    dx,ax        ; update the register
  78.  
  79. ; update video BIOS data area
  80.  
  81.         mov    ax,40h
  82.         mov    ds,ax        ; DS := video BIOS data segment
  83.  
  84.         mov    ax,720        ; AX := displayed pixels per row
  85.         div    ARGw        ; AL := displayed character columns
  86.         mov    ds:[CRT_COLS],al
  87.  
  88.         mov    ax,350        ; AX := number of displayed scan lines
  89.         div    ARGh        ; AL := displayed character rows
  90.         dec    al        ; AL := (character rows) - 1
  91.         mov    ds:[ROWS],al
  92.  
  93.         inc    al
  94.         mul    byte ptr ds:[CRT_COLS]
  95.         shl    ax,1        ; AX := rows * columns * 2
  96.         mov    ds:[CRT_LEN],ax
  97.  
  98. ; re-enable display and exit
  99.  
  100.         mov    dx,3B8h        ; DX := CRT Mode Control port
  101.         mov    al,ds:[CRT_MODE_SET]    ; restore previous value
  102.         out    dx,al
  103.  
  104.         pop    si
  105.         pop    ds
  106.         pop    bp
  107.         ret
  108.  
  109. _AlphaModeSet    ENDP
  110.  
  111.  
  112. SetHercCRTC    PROC    near        ; Caller:    BH = character width
  113.                     ;        BL = character height
  114.  
  115.         push    dx
  116.         mov    dx,3B4h        ; DX := CRTC Address Reg port 3B4h
  117.  
  118. ; establish cursor position in character matrix
  119.  
  120.         mov    ah,bl
  121.         dec    ah        ; AH := value for Max Scan Line reg
  122.         mov    al,9        ; AL := Max Scan Line register number
  123.         out    dx,ax
  124.  
  125.         mov    al,0Bh        ; AL := Cursor End reg number
  126.         out    dx,ax        ; set cursor to end on last line of
  127.                     ;   character matrix
  128.  
  129.         sub    ax,101h        ; AH := second-to-last line
  130.                     ; AL := 0AH (Cursor Start reg number)
  131.         out    dx,ax        ; set cursor to start on second-to-
  132.                     ;  last line
  133.  
  134. ; compute offsets into parameter tables
  135.  
  136.         sub    bx,0804h    ; BH := 0 or 1
  137.                     ; BL := 0 through 12
  138.         add    bx,bx
  139.         add    bx,bx        ; BH := 0 or 4
  140.                     ; BL := 0 through 48
  141. ; establish CRTC horizontal timing
  142.  
  143.         push    bx        ; preserve BX
  144.         mov    bl,bh
  145.         xor    bh,bh        ; BX := 0 or 4
  146.         add    bx,offset DGROUP:HorizParms    ; DS:BX -> parameters
  147.  
  148.         mov    al,0        ; AL := first CRTC reg to update
  149.         call    UpdateCRTC
  150.  
  151. ; establish vertical timing
  152.  
  153.         pop    bx
  154.         xor    bh,bh        ; BX := 0 through 48
  155.         add    bx,offset DGROUP:VertParms    ; DS:BX -> parameters
  156.  
  157.         mov    al,4        ; AL := first CRTC reg to update
  158.         call    UpdateCRTC
  159.  
  160.         pop    dx        ; restore DX
  161.         ret
  162.  
  163. SetHercCRTC    ENDP
  164.  
  165.  
  166. UpdateCRTC    PROC    near        ; Caller:    AL = first reg number
  167.                     ;        DX = CRTC address port
  168.                     ;        DS:BX -> parameters
  169.                     ; Destroys:    AX,CX
  170.  
  171.         mov    cx,4        ; CX := number of registers to update
  172.         
  173. L10:        mov    ah,[bx]        ; AH := data for CRTC register in AL
  174.         out    dx,ax        ; update the register
  175.         inc    ax        ; AL := next register number
  176.         inc    bx        ; DS:BX -> next value in table
  177.         loop    L10
  178.  
  179.         ret
  180.  
  181. UpdateCRTC    ENDP
  182.  
  183. _TEXT        ENDS
  184.  
  185.  
  186. _DATA        SEGMENT    word public 'DATA'
  187.  
  188. HorizParms    DB    6Dh,5Ah,5Ch,0Fh        ; 8 pixels wide
  189.         DB    61h,50h,52h,0Fh        ; 9 pixels wide
  190.  
  191.  
  192. VertParms    DB    5Ch,02h,58h,59h        ; 4 scan lines high
  193.         DB    4Ah,00h,46h,46h        ; 5
  194.         DB    3Dh,04h,3Ah,3Bh        ; 6
  195.         DB    34h,06h,32h,33h        ; 7
  196.         DB    2Dh,02h,2Bh,2Ch        ; 8
  197.         DB    28h,01h,26h,27h        ; 9
  198.         DB    24h,00h,23h,23h        ; 10
  199.         DB    20h,07h,1Fh,20h        ; 11
  200.         DB    1Dh,0Ah,1Dh,1Dh        ; 12
  201.         DB    1Bh,06h,1Ah,1Bh        ; 13
  202.         DB    19h,06h,19h,19h        ; 14
  203.         DB    17h,0Ah,17h,17h        ; 15
  204.         DB    16h,02h,15h,16h
  205.  
  206. _DATA        ENDS
  207.  
  208.         END
  209.