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

  1.                 TITLE   'Listing 2-4'
  2.         NAME    HercGraphMode
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        HercGraphMode
  7. ;
  8. ; Function:    Establish Hercules 720x348 graphics mode on HGC, HGC+, InColor
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;                void HercGraphMode();
  13. ;
  14.  
  15. DGROUP        GROUP    _DATA
  16.  
  17. _TEXT        SEGMENT    byte public 'CODE'
  18.         ASSUME    cs:_TEXT,ds:DGROUP
  19.  
  20.         PUBLIC    _HercGraphMode
  21. _HercGraphMode    PROC    near
  22.  
  23.         push    bp        ; preserve caller registers
  24.         mov    bp,sp
  25.         push    si
  26.         push    di
  27.  
  28. ; Update Video BIOS Data Area with reasonable values
  29.  
  30.         mov    ax,40h
  31.         mov    es,ax
  32.         mov    di,49h        ; ES:DI := 0040:0049 (BIOS data area)
  33.  
  34.         mov    si,offset DGROUP:BIOSData
  35.         mov    cx,BIOSDataLen
  36.         rep    movsb        ; update BIOS data area
  37.  
  38. ; Set Configuration Switch
  39.  
  40.         mov    dx,3BFh        ; DX := Configuration Switch port
  41.         mov    al,1        ; AL bit 1 := 0 (exclude 2nd 32K of
  42.                     ;          video buffer)
  43.                     ; AL bit 0 := 1 (allow graphics mode
  44.         out    dx,al        ;         setting via 3B8h)
  45.  
  46. ; Blank the screen to avoid interference during CRTC programming
  47.  
  48.         mov    dx,3B8h        ; DX := CRTC Mode Control Register port
  49.         xor    al,al        ; AL bit 3 := 0 (disable video signal)
  50.         out    dx,al        ; blank the screen
  51.  
  52. ; Program the CRTC
  53.  
  54.         sub    dl,4        ; DX := CRTC Address Reg port 3B4h
  55.  
  56.         mov    si,offset DGROUP:CRTCParms
  57.         mov    cx,CRTCParmsLen
  58.  
  59. L01:        lodsw            ; AL := CRTC register number
  60.                     ; AH := data for this register
  61.         out    dx,ax
  62.         loop    L01
  63.  
  64. ; Set graphics mode
  65.  
  66.         add    dl,4        ; DX := 3B8h (CRTC Mode Control Reg)
  67.         mov    al,CRTMode    ; AL bit 1 = 1 (enable graphics mode)
  68.                     ;    bit 3 = 1 (enable video)
  69.         out    dx,al
  70.  
  71.         pop    di        ; restore registers and exit
  72.         pop    si
  73.         mov    sp,bp
  74.         pop    bp
  75.         ret
  76.  
  77. _HercGraphMode    ENDP
  78.  
  79. _TEXT        ENDS
  80.  
  81.  
  82. _DATA        SEGMENT    word public 'DATA'
  83.  
  84.                 ; These are the parameters recommended by Hercules.
  85.                 ; They are based on 16 pixels/character and
  86.                 ; 4 scan lines per character.
  87.  
  88. CRTCParms    DB    00h,35h    ; Horizontal Total:  54 characters
  89.         DB    01h,2Dh    ; Horizontal Displayed:  45 characters
  90.         DB    02h,2Eh    ; Horizontal Sync Position:  at 46th character
  91.         DB    03h,07h    ; Horizontal Sync Width:  7 character clocks
  92.  
  93.         DB    04h,5Bh    ; Vertical Total:  92 characters (368 lines)
  94.         DB    05h,02h    ; Vertical Adjust:  2 scan lines
  95.         DB    06h,57h    ; Vertical Displayed:  87 character rows (348 lines)
  96.         DB    07h,57h    ; Vertical Sync Position:  after 87th char row
  97.  
  98.         DB    09h,03h    ; Max Scan Line:  4 scan lines per char
  99.  
  100. CRTCParmsLen    EQU    ($-CRTCParms)/2
  101.  
  102. BIOSData    DB    7    ; CRT_MODE
  103.         DW    80    ; CRT_COLS
  104.         DW    8000h    ; CRT_LEN
  105.         DW    0    ; CRT_START
  106.         DW    8 dup(0) ; CURSOR_POSN
  107.         DW    0    ; CURSOR_MODE
  108.         DB    0    ; ACTIVE_PAGE
  109. CRTCAddr    DW    3B4h    ; ADDR_6845
  110. CRTMode        DB    0Ah    ; CRT_MODE_SET (value for port 3B8h)
  111.         DB    0    ; CRT_PALETTE (unused)
  112.  
  113. BIOSDataLen    EQU    $-BIOSData
  114.  
  115. _DATA        ENDS
  116.  
  117.         END
  118.