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

  1.  
  2.     TITLE    HGCMODE    - Sets Hercules Graphics mode (on page 1)
  3.     NAME    HGCMODE
  4.     PAGE    55,132
  5.  
  6.     COMMENT    $
  7.     
  8.     Establish Various Hercules modes
  9.  
  10.     Caller:    Microsoft C
  11.  
  12.         void
  13.         hgc_config()    /* Set Hercules to "full" config */
  14.  
  15.         void
  16.         hgc_gmode()    /* Set Graphics mode (on page 1) */
  17.  
  18.         void
  19.         hgc_tmode()    /* Set Text mode */
  20.  
  21.         void
  22.         _hgc_clear()    /* Clear the graphics screen */
  23.  
  24.         void
  25.         hgc_backbuf()    /* Displays page 1, Sets page 0 for writing */
  26.  
  27.         void
  28.         hgc_frontbuf()    /* Displays page 0, Sets page 1 for writing */
  29.  
  30.         void
  31.         hgc_swapbuf()    /* Swaps page 0 and page 1 on display */
  32.         
  33.     $
  34.         
  35. config_switch        equ         03bfh
  36. TextSeg            equ        0b000h
  37. DisplaySeg0        equ        0b000h
  38. DisplaySeg1        equ        0b800h
  39. page0            equ        00000000b
  40. page1            equ        10000000b
  41. dmc_port        equ        03b8h
  42. index_6845        equ        03b4h
  43. disp_stat_port        equ        03bah
  44. text            equ        00000000b
  45. graphics        equ        00000010b
  46. off_screen        equ        00000000b
  47. on_screen        equ        00001000b
  48.  
  49. public _hgc_config, _hgc_clear, _hgc_gmode, _hgc_tmode
  50. PUBLIC    _hgc_backbuf, _hgc_frontbuf, _hgc_swapbuf
  51.  
  52. herc_data segment    word public    'data'
  53. ttable        db    61h,50h,52h,0fh,19h,06h,19h,19h,02h,0dh,0bh,0ch
  54. gtable        db    35h,2dh,2eh,07h,5bh,02h,57h,57h,02h,03h,00h,00h
  55. herc_data ends
  56.  
  57.     extrn    __buffer_segment:word
  58.     extrn    __cur_color:word
  59.  
  60. herc_text    segment byte public 'code'
  61.  
  62.     dgroup    group    herc_data
  63.     assume cs:herc_text, ds:dgroup
  64.  
  65. wait_v_retrace    macro
  66.     local        in_v_retrace, not_in_v_retrace
  67.     mov        dx,disp_stat_port
  68. in_v_retrace:
  69.     in        al,dx
  70.     shl        al,1
  71.     jnc        in_v_retrace
  72. not_in_v_retrace:
  73.     in        al,dx
  74.     shl        al,1
  75.     jc        not_in_v_retrace
  76.     endm
  77.     
  78.  
  79. vertical_retrace    proc far
  80.     wait_v_retrace
  81.     ret
  82. vertical_retrace    endp
  83.  
  84. _hgc_config proc far
  85.     push    bp
  86.     mov        bp,sp
  87.     mov        al,3
  88.     mov        dx,config_switch
  89.     out        dx,al
  90.     mov        sp,bp
  91.     pop        bp
  92.     ret
  93. _hgc_config    endp
  94.     
  95. _hgc_clear proc far
  96.     push        bp
  97.     mov        bp,sp
  98.     push        di
  99.     push        cx
  100.     pushf
  101.     mov        cx,__buffer_segment
  102.     mov        es,cx
  103.     xor        di,di
  104.     cmp        __cur_color, 0
  105.     jne        white
  106.     xor        ax,ax
  107.     jmp        next
  108. white:
  109.     mov        ax,0ffffh
  110. next:
  111.     mov        cx,16*1024
  112.     cld
  113.     rep        stosw
  114.     popf
  115.     pop        cx
  116.     pop        di
  117.     mov        ax, 14
  118.     mov        sp,bp
  119.     pop        bp
  120.     ret    
  121. _hgc_clear        endp
  122.  
  123. setmod    proc        far
  124.     pushf
  125.     mov        dx,dmc_port    
  126.     out        dx,al
  127.     mov        dx,index_6845
  128.     mov        cx,12
  129.     xor        ah,ah
  130.     cld
  131. next_6845:
  132.     mov        al,ah
  133.     out        dx,al
  134.     inc        dx
  135.     lodsb
  136.     out        dx,al
  137.     inc        ah
  138.     dec         dx
  139.     loop        next_6845
  140.     popf
  141.     ret
  142. setmod    endp
  143.  
  144. _hgc_tmode    proc far
  145.     push        bp
  146.     mov        bp,sp
  147.     sub        sp, 10
  148.     push        di    
  149.     push        si
  150.     push        bx
  151.     push        cx
  152.     push        dx
  153.     lea        si,ttable
  154.     call        setmod
  155.     call        vertical_retrace
  156.     xor        ax,ax
  157.     mov        al,page0 + on_screen
  158.     add        al,text
  159.     mov        dx,dmc_port
  160.     out        dx,al
  161.     mov        __buffer_segment, displayseg0
  162.     pop        dx
  163.     pop        cx
  164.     pop        bx
  165.     pop        si
  166.     pop        di
  167.     mov        sp,bp
  168.     pop        bp
  169.     ret
  170. _hgc_tmode    endp
  171.  
  172. _hgc_gmode    proc far
  173.     push        bp
  174.     mov        bp,sp
  175.     sub        sp,10
  176.     push        di    
  177.     push        si
  178.     push        bx
  179.     push        cx
  180.     push        dx
  181.     xor        ax,ax
  182.     mov        al,graphics
  183.     lea        si,gtable
  184.     call        setmod
  185.     mov        al,page1 + on_screen
  186.     add        al,graphics
  187.     push        ax
  188.      call        vertical_retrace
  189.     pop        ax
  190.     mov        dx,dmc_port
  191.     out        dx,al
  192.     mov        __buffer_segment, displayseg1
  193.     pop        dx    
  194.     pop        cx    
  195.     pop        bx    
  196.     pop        si
  197.     pop        di
  198.     mov        sp,bp
  199.     pop        bp
  200.     ret
  201. _hgc_gmode    endp
  202.  
  203.     comment    $
  204.         displays page0 (internal routine)
  205.     $
  206.  
  207. hgc_page0    proc    far
  208.     push        bp
  209.     mov        bp, sp
  210.  
  211.     push        dx
  212.     call        vertical_retrace
  213.     mov        dx, dmc_port
  214.     mov        ax, page0
  215.     add        al, graphics + on_screen
  216.     out        dx, al
  217.     pop        dx
  218.     mov        sp, bp
  219.     pop        bp
  220.     ret
  221. hgc_page0        endp
  222.  
  223.     comment    $
  224.         displays page1 (internal routine).
  225.     $
  226.  
  227. hgc_page1    proc    far
  228.     push        bp
  229.     mov        bp, sp
  230.  
  231.     push        dx
  232.     call        vertical_retrace
  233.     mov        dx, dmc_port
  234.     mov        ax, page1
  235.     add        al, graphics + on_screen
  236.     out        dx, al
  237.     pop        dx
  238.     mov        sp, bp
  239.     pop        bp
  240.     ret
  241. hgc_page1        endp
  242.     
  243.     
  244.     comment    $
  245.         displays page1, sets page 0 for writing.
  246.     $
  247.  
  248. _hgc_backbuf    proc    far
  249.     push        bp
  250.     mov        bp, sp
  251.  
  252.     call        hgc_page1
  253.     mov        __buffer_segment, displayseg0
  254.  
  255.     mov        ax, 1    ; return value
  256.     mov        sp, bp
  257.     pop        bp
  258.     ret
  259. _hgc_backbuf        endp    
  260.  
  261.     comment    $
  262.         displays page1, sets page 1 for writing.
  263.         (This ensures that written page is the display page).
  264.     $
  265.  
  266. _hgc_frontbuf    proc    far
  267.     push        bp
  268.     mov        bp, sp
  269.  
  270.     call        hgc_page1
  271.     mov        __buffer_segment, displayseg1
  272.  
  273.     mov        sp, bp
  274.     pop        bp
  275.     ret
  276. _hgc_frontbuf        endp    
  277.  
  278.  
  279.     comment    $
  280.         display current buffer (page)
  281.         set drawing in other buffer (page)
  282.     $
  283.  
  284. _hgc_swapbuf    proc    far
  285.     push        bp
  286.     mov        bp, sp
  287.  
  288.     cmp        __buffer_segment, displayseg0
  289.     je        disp_page0
  290.     call        hgc_page1
  291.     mov        __buffer_segment, displayseg0
  292.     jmp        go
  293.  
  294. disp_page0:
  295.     call        hgc_page0
  296.     mov        __buffer_segment, displayseg1
  297.  
  298. go:
  299.     mov        sp, bp
  300.     pop        bp
  301.     ret
  302. _hgc_swapbuf        endp    
  303.  
  304. herc_text ends
  305.  
  306.     end
  307.