home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / frasrc18.zip / FR8514A.ASM < prev    next >
Assembly Source File  |  1992-11-17  |  51KB  |  2,066 lines

  1.  
  2.  
  3. IFDEF ??version
  4.     MASM51
  5.     QUIRKS
  6. ENDIF
  7.  
  8.     .MODEL    medium,c
  9.  
  10.     .8086
  11.  
  12.  
  13.  
  14. HOPEN    equ    8
  15. HSMX    equ    9
  16. HINT    equ    16
  17. HLDPAL    equ    19
  18. HBBW    equ    21
  19. HBBR    equ    23
  20. HBBCHN    equ    24
  21. HBBC    equ    25
  22. HQMODE    equ    29
  23. HRECT    equ    32
  24. HCLOSE    equ    34
  25. HINIT    equ    48
  26. HSYNC    equ    49
  27. HSPAL    equ    57
  28. HRPAL    equ    58
  29.  
  30.  
  31. HLINE    equ    0
  32. HSCOL    equ    7
  33.  
  34.  
  35. .DATA
  36.  
  37.     extrn    sxdots:word, sydots:word  ; number of dots across and down
  38.     extrn    dacbox:byte, daccount:word
  39.  
  40. afiptr        dd    0
  41.  
  42. xadj        dw    0
  43. yadj        dw    0
  44.  
  45. extrn        paldata:byte        ; 1024-byte array (in GENERAL.ASM)
  46.  
  47. extrn        stbuff:byte        ; 415-byte array (in GENERAL.ASM)
  48.  
  49. linedata    db    0
  50.  
  51. hopendata    db    3, 0, 0, 0, 0
  52. hclosedata    dw    2, 0
  53. hinitdata    dw    2, 0
  54. bbw        dw    10, 8, 0, 1, 0, 0
  55. bbr        dw    12, 8, 0, 1, 0, 0, 0
  56. smx        dw    2, 0
  57. chn        dw    6
  58.         dd    linedata
  59.         dw    1
  60. pal        dw    10, 0, 0, 256
  61.         dd    paldata
  62. hidata        dw    4, 0, 8000h
  63. amode        dw    18, 9 dup(?)
  64.  
  65.  
  66. hlinedata    dw    8, 0, 0, 0, 0
  67. hscoldata    dw    4, 0, 0
  68.  
  69.  
  70. .CODE    VIDEO_TEXT
  71.  
  72.  
  73. callafi proc    near
  74.  
  75.     push    ds        ; Pass the parameter pointer
  76.     push    si
  77.  
  78.     shl    ax,1        ; form offset from entry no. required
  79.     shl    ax,1
  80.     mov    si,ax
  81.  
  82.     les    bx, afiptr    ; entry block address to es:bx
  83.     call    dword ptr es:[bx][si]     ; call entry point
  84.  
  85.     ret            ; return to caller
  86.  
  87. callafi endp
  88.  
  89.  
  90. getafi    proc    near
  91.  
  92.     mov    ax,357fh    ; read interrupt vector 7f
  93.     int    21h
  94.     mov    ax,es
  95.     or    ax,bx        ; is 7f vector null
  96.     stc
  97.     jz    getafiret
  98.  
  99.     mov    ax,0105h    ; get Interface address
  100.     int    7fh        ; by software interrupt 7f
  101.  
  102.     jc    getafiret        ; Interface not OK if carry set
  103.  
  104.     mov    word ptr afiptr,dx    ; save afi pointer offset
  105.     mov    word ptr afiptr+2,cx    ; save afi pointer segment
  106.  
  107.     clc            ; clear carry flag
  108.  
  109. getafiret:
  110.     ret            ; return to caller
  111.  
  112. getafi endp
  113.  
  114.  
  115. do85open proc    near
  116.  
  117.     push    ax
  118.     mov    ax, HOPEN
  119.     call    callafi
  120.  
  121.     mov    ax, offset stbuff    ;get the state segment
  122.     add    ax, 15
  123.     mov    cl, 4
  124.     shr    ax, cl
  125.  
  126.     mov    bx, ds
  127.     add    ax, bx
  128.  
  129.     mov    si, offset hinitdata
  130.     mov    [si] + 2, ax
  131.  
  132.     pop    ax
  133.     call    callafi
  134.  
  135.     clc
  136.     ret
  137.  
  138. do85open    endp
  139.  
  140.  
  141. open8514    proc    near
  142.  
  143.     call    load8514dacbox    ; load dacbox for 8514/A setup  JCO 4/6/92
  144.  
  145.     call    getafi        ;get adapter interface
  146.     jc    afinotfound
  147.  
  148.     mov    bl, 0        ;if > 640 x 480 then 1024 x 768
  149.  
  150.     mov    ax, sxdots
  151.  
  152.     cmp    ax, 1024    ;if > 1024, don't use afi, JCO 4/4/92
  153.     ja    afinotfound
  154.  
  155.     cmp    ax, 800    ; must be 1024
  156.     ja    setupopen
  157.  
  158.     cmp    ax, 640    ; could be 800
  159.     ja    afinotfound
  160.  
  161.     mov    ax, sydots
  162.     cmp    ax, 480
  163.     ja    setupopen
  164.  
  165.     inc    bl
  166.  
  167. setupopen:
  168.  
  169.     mov    si, offset hopendata    ;open the adapter
  170.     mov    byte ptr [si + 2], 40h        ;zero the image but leave pallette
  171.     mov    [si + 3], bl
  172.     mov    ax, HINIT        ;initialize state
  173.  
  174.     call    do85open
  175.     jc    afinotfound
  176.  
  177.     mov    si, offset amode    ;make sure on the size
  178.     mov    ax, HQMODE        ;get the adapter mode
  179.     call    callafi
  180.  
  181.     mov    ax, amode + 10        ;get the screen width
  182.     cmp    ax, sxdots
  183.     jae    xdotsok         ;check for fit
  184.     mov    sxdots, ax
  185. xdotsok:
  186.     sub    ax, sxdots        ;save centering factor
  187.     shr    ax, 1
  188.     mov    xadj, ax
  189.  
  190.     mov    ax, amode + 12        ;get the screen height
  191.     cmp    ax, sydots
  192.     jae    ydotsok
  193.     mov    sydots, ax
  194. ydotsok:
  195.     sub    ax, sydots
  196.     shr    ax, 1
  197.     mov    yadj, ax
  198.     clc
  199.     ret
  200.  
  201. afinotfound:                ; No 8514/A interface found
  202.     stc                ; flag bad mode
  203.     ret                ;  and bail out
  204.  
  205. open8514    endp
  206.  
  207. reopen8514    proc    near
  208.  
  209.     mov    si, offset hopendata    ;open the adapter
  210.     mov    byte ptr [si + 2], 0C0h     ;zero the image but leave pallette
  211.     mov    ax, HSYNC        ;initialize state
  212.     call    do85open
  213.     ret
  214.  
  215. reopen8514    endp
  216.  
  217.  
  218. close8514    proc    near
  219.  
  220.     mov    si, offset hclosedata        ;turn off 8514a
  221.     mov    ax, HCLOSE
  222.     call    callafi
  223.  
  224.     ret
  225.  
  226. close8514    endp
  227.  
  228.  
  229. fr85wdotnew    proc    near    uses si
  230.  
  231.     mov    byte ptr [hscoldata + 2], al
  232.  
  233.     add    cx, xadj
  234.     add    dx, yadj
  235.  
  236.     mov    hlinedata + 2, cx
  237.     mov    hlinedata + 4, dx
  238.     inc    cx        ; increment x direction
  239.     mov    hlinedata + 6, cx
  240.     mov    hlinedata + 8, dx
  241.  
  242. ; set the color
  243.     mov    si, offset hscoldata
  244.     mov    ax, HSCOL
  245.     call    callafi
  246.  
  247. ; plot the point
  248.     mov    si, offset hlinedata
  249.  
  250.     mov    ax, HLINE
  251.     call    callafi
  252.  
  253.     ret
  254.  
  255. fr85wdotnew    endp
  256.  
  257.  
  258. fr85wdot    proc    near uses si
  259.  
  260.     mov    linedata, al
  261.  
  262.     mov    bbw + 4, 1        ;define the rectangle
  263. ;    mov    bbw + 6, 1
  264.     add    cx, xadj
  265.     add    dx, yadj
  266.  
  267.     mov    bbw + 8, cx
  268.     mov    bbw + 10, dx
  269.     mov    si, offset bbw
  270.     mov    ax, HBBW
  271.     call    callafi
  272.  
  273.     mov    si, offset chn
  274.     mov    word ptr [si + 2], offset linedata
  275.     mov    word ptr [si + 6], 1    ;send the data
  276.  
  277.     mov    ax, HBBCHN
  278.     call    callafi
  279.  
  280. fr85wdotx:
  281.     ret
  282.  
  283. fr85wdot    endp
  284.  
  285.  
  286. fr85wbox    proc    near uses si
  287.  
  288.     sub    ax, cx
  289.     inc    ax            ; BDT patch 11/4/90
  290. ;    add    ax, xadj
  291.     add    cx, xadj
  292.     add    dx, yadj
  293.     mov    chn + 2, si        ;point to data
  294.     mov    chn + 6, ax
  295.     mov    bbw + 4, ax        ;define the rectangle
  296. ;    mov    bbw + 6, 1        ;set in declaration
  297.     mov    bbw + 8, cx
  298.     mov    bbw + 10, dx
  299.  
  300.     mov    si, offset bbw
  301.     mov    ax, HBBW
  302.     call    callafi
  303.  
  304.     mov    si, offset chn
  305.     mov    ax, HBBCHN
  306.     call    callafi
  307.  
  308.     ret
  309.  
  310. fr85wbox    endp
  311.  
  312.  
  313. fr85rdot    proc    near uses si
  314.  
  315.     mov    bbr + 4, 1        ;define the rectangle
  316. ;    mov    bbr + 6, 1        ;set in declaration
  317.     add    cx, xadj
  318.     add    dx, yadj
  319.     mov    bbr + 10, cx
  320.     mov    bbr + 12, dx
  321.     mov    si, offset bbr
  322.     mov    ax, HBBR
  323.     call    callafi
  324.  
  325.     mov    si, offset chn
  326.     mov    word ptr [si + 2], offset linedata
  327.     mov    word ptr [si + 6], 1    ;send the data
  328.     mov    ax, HBBCHN
  329.     call    callafi
  330.  
  331.     mov    al, linedata
  332.  
  333. fr85rdotx:
  334.     ret
  335.  
  336. fr85rdot    endp
  337.  
  338. fr85rbox    proc    near uses si
  339.  
  340.     sub    ax, cx
  341.     inc    ax            ; BDT patch 11/4/90
  342. ;    add    ax, xadj
  343.     add    cx, xadj
  344.     add    dx, yadj
  345.     mov    chn + 2, di        ;point to data
  346.     mov    chn + 6, ax
  347.     mov    bbr + 4, ax        ;define the rectangle
  348. ;    mov    bbr + 6, 1        ;set in declaration
  349.     mov    bbr + 10, cx
  350.     mov    bbr + 12, dx
  351.  
  352.     mov    si, offset bbr
  353.     mov    ax, HBBR
  354.     call    callafi
  355.  
  356.     mov    si, offset chn
  357.     mov    ax, HBBCHN
  358.     call    callafi
  359.  
  360.     ret
  361.  
  362. fr85rbox    endp
  363.  
  364.  
  365. w8514pal    proc    near
  366.  
  367.     mov    si, offset dacbox
  368.  
  369.     mov    cx, daccount    ;limit daccount to 128 to avoid fliker
  370.     cmp    cx, 128
  371.     jbe    countok
  372.  
  373.     mov    cx, 128
  374.     mov    daccount, cx
  375.  
  376. countok:                ;now build 8514 pallette
  377.     mov    ax, 256         ;from the data in dacbox
  378.     mov    pal + 4, 0
  379.     mov    di, offset paldata
  380.     cld
  381. cpallp:
  382.     push    ax            ;do daccount at a time
  383.     mov    dx, di
  384.     cmp    ax, cx
  385.     jae    dopass
  386.     mov    cx, ax
  387. dopass:
  388.     mov    pal + 6, cx        ;entries this time
  389.     push    cx
  390. cpallp2:
  391.     push    ds            ;pallette format is r, b, g
  392.     pop    es            ;0 - 255 each
  393.  
  394.     lodsb                ;red
  395.     shl    al, 1
  396.     shl    al, 1
  397.     stosb
  398.     lodsb                ;green
  399.     shl    al, 1
  400.     shl    al, 1
  401.     xchg    ah, al
  402.     lodsb                ;blue
  403.     shl    al, 1
  404.     shl    al, 1
  405.     stosw
  406.     mov    al, 0            ;filler
  407.     stosb
  408.     loop    cpallp2
  409.  
  410.     push    si
  411.     push    di
  412.     push    dx
  413.  
  414.     mov    si, hidata        ;wait for flyback
  415.     mov    ax, HINT
  416.     call    callafi
  417.  
  418.     pop    dx
  419.     mov    pal + 8, dx
  420.  
  421.     mov    si, offset pal        ;load this piece
  422.     mov    ax, HLDPAL
  423.     call    callafi
  424.  
  425.     pop    di
  426.     pop    si
  427.     pop    cx
  428.     add    pal + 4, cx        ;increment the pallette index
  429.     pop    ax
  430.     sub    ax, cx
  431.     jnz    cpallp
  432.  
  433.     ret
  434.  
  435. w8514pal    endp
  436.  
  437.  
  438. ;********************************************************************
  439. ;* 8514/A Hardware Interface Routines
  440. ;* Written by Aaron M. Williams for Fractint
  441. ;* This code may be used freely by anyone for anything and freely distributed.
  442. ;* All routines here are written for a V20 (80186) or better CPU.
  443. ;* All code has been at least partially optimized for a 486 (i.e. pipelining)
  444. ;* The macros were written by Roger Brown for Adex Corporation and have been
  445. ;* placed into the public domain by Adex corporation.
  446. ;*
  447. ;* Special support has been added for the Brooktree RAMDAC, which uses 8
  448. ;* bits for rgb values instead of 6 bits.  This RAMDAC is used only in the
  449. ;* 1280x1024 mode (unless programmed otherwise)
  450. ;*
  451. ;* Completed on 3/8/92
  452.  
  453. ;* Revised by JCO on 4/12/92
  454. ; changed width to wdth and other minor fixes so it would assemble
  455. ;   using MASM 6.0
  456. ; took out duplicate variables, xadj, yadj, linedata
  457. ; took out .model C
  458. ; added VIDEO_TEXT to .code and made procedures near
  459. ; added TRANSY macro for 640x480x16 (512K), but not used
  460. ; w8514hwpal
  461. ;  Changed normal 8514/A routine to slow it down
  462. ; reopen8514hw
  463. ;  Renamed enableHIRES as reopen8514hw
  464. ;  Commented out old reopen8514hw
  465. ; open8514hw
  466. ;  Changed where board is reset so a hung board won't prevent detect of 8514/A
  467. ;  Added load8514dacbox routine to initialize colors
  468. ;  Added detection and setup of 512K 8514/A, use debug=8514 to test on 1 Meg
  469. ;  Changed foreground mix to FSS_FRGDCOL.  It's faster to use FRGD_COLOR for
  470. ;   dots and set/reset the mix for boxes.
  471. ;  Took out call to w8514hwpal, hangs machine if another video mode is not used
  472. ;   first, load8514dacbox takes care of loading initial colors
  473. ; fr85hwwdot, fr85hwrdot
  474. ;  Replaced with routines that use short stroke vectors, uses fewer port calls
  475. ; fr85hwwbox, fr85hwrbox
  476. ;  Replaced with routines that use vectors
  477. ; close8514hw
  478. ;  Made non-Adex 8514/A not use the enableVGA routine
  479. ; load8514dacbox
  480. ;  Added this routine to load dacbox
  481.  
  482. ;* Added support for ATI ULTRA 800x600x256 and 1280x1024x16 modes JCO, 11/7/92
  483.  
  484.     .286    ; we use 286 code here for speed
  485.         ; for in graphics, speed is everything
  486.  
  487. .DATA
  488.  
  489. ; Defines
  490.  
  491. BIT_0_ON        EQU    0000000000000001b
  492. BIT_1_ON        EQU    0000000000000010b
  493. BIT_2_ON        EQU    0000000000000100b
  494. BIT_3_ON        EQU    0000000000001000b
  495. BIT_4_ON        EQU    0000000000010000b
  496. BIT_5_ON        EQU    0000000000100000b
  497. BIT_6_ON        EQU    0000000001000000b
  498. BIT_7_ON        EQU    0000000010000000b
  499. BIT_8_ON        EQU    0000000100000000b
  500. BIT_9_ON        EQU    0000001000000000b
  501. BIT_10_ON        EQU    0000010000000000b
  502. BIT_11_ON        EQU    0000100000000000b
  503. BIT_12_ON        EQU    0001000000000000b
  504. BIT_13_ON        EQU    0010000000000000b
  505. BIT_14_ON        EQU    0100000000000000b
  506. BIT_15_ON        EQU    1000000000000000b
  507.  
  508. BIT_0_OFF        EQU    1111111111111110b
  509. BIT_1_OFF        EQU    1111111111111101b
  510. BIT_2_OFF        EQU    1111111111111011b
  511. BIT_3_OFF        EQU    1111111111110111b
  512. BIT_4_OFF        EQU    1111111111101111b
  513. BIT_5_OFF        EQU    1111111111011111b
  514. BIT_6_OFF        EQU    1111111110111111b
  515. BIT_7_OFF        EQU    1111111101111111b
  516. BIT_8_OFF        EQU    1111111011111111b
  517. BIT_9_OFF        EQU    1111110111111111b
  518. BIT_10_OFF        EQU    1111101111111111b
  519. BIT_11_OFF        EQU    1111011111111111b
  520. BIT_12_OFF        EQU    1110111111111111b
  521. BIT_13_OFF        EQU    1101111111111111b
  522. BIT_14_OFF        EQU    1011111111111111b
  523. BIT_15_OFF        EQU    0111111111111111b
  524.  
  525. ;==========================================
  526. ; Equates for use with Wait_Till_FIFO Macro
  527. ;==========================================
  528. ONEEMPTY        = BIT_7_ON
  529. TWOEMPTY        = BIT_6_ON
  530. THREEEMPTY        = BIT_5_ON
  531. FOUREMPTY        = BIT_4_ON
  532. FIVEEMPTY        = BIT_3_ON
  533. SIXEMPTY        = BIT_2_ON
  534. SEVENEMPTY        = BIT_1_ON
  535. EIGHTEMPTY        = BIT_0_ON
  536.  
  537. VSYNC_BIT_MASK        = BIT_0_ON
  538. DEFAULT_MASK        = 00FFh            ; Default to all 8 bits.
  539. LOCK_FLAG        = BIT_15_ON        ; Flag to lock CRTC timing regs
  540.  
  541. GE_BUSY_MASK        = BIT_9_ON        ; Mask for GE_BUSY
  542. GE_BUSY_SHFT        = 9
  543.  
  544. MAX_RES_MASK        = BIT_3_ON
  545. MAX_RES_SHFT        = 3
  546.  
  547. PATTERN_POS_MASK    = (BIT_13_ON+BIT_12_ON+BIT_11_ON+BIT_10_ON+BIT_9_ON+BIT_8_ON)
  548. PATTERN_POS_SHFT    = 8
  549.  
  550. SELECT_DPAGE_2        = BIT_1_ON
  551. SELECT_DPAGE_1        = BIT_1_OFF
  552.  
  553. SELECT_VPAGE_2        = BIT_2_ON
  554. SELECT_VPAGE_1        = BIT_2_OFF
  555.  
  556. LOWER_12_BITS        = 0FFFh            ; Mask off upper 4 bits
  557.  
  558.  
  559. ;*****************************************************************************
  560. ;
  561. ; MACRO DEFINITIONS
  562. ;
  563. ;*****************************************************************************
  564.  
  565. ;PURPOSE     : Wait until there is [number] locations available in the FIFO.
  566.  
  567.     Wait_Till_FIFO    MACRO    number
  568. LOCAL    waitfifoloop
  569.  
  570.      mov    dx, GP_STAT
  571. waitfifoloop:
  572.      in    ax, dx
  573.      test    ax, number
  574.      jnz    waitfifoloop
  575. ENDM
  576.  
  577.  
  578. ; Wait if Hardware is Busy
  579.     Wait_If_HW_Busy MACRO
  580. LOCAL    waithwloop
  581.     mov    dx, GP_STAT
  582. waithwloop:
  583.     in    ax, dx
  584.     test    ax, FSR_HWBUSY
  585.     jnz    waithwloop
  586. ENDM
  587.  
  588.  
  589. ; PURPOSE: Wait Till CPU data is Available (Used for Image Read/Write)
  590.  
  591.     Wait_Till_Data_Avail    MACRO
  592. LOCAL    waitdataloop
  593.     mov    dx, GP_STAT
  594. waitdataloop:
  595.     in    ax, dx
  596.     test    ax, 0100h
  597.     jz    waitdataloop
  598. ENDM
  599.  
  600.  
  601. ; PURPOSE: Output a word to the specified i/o port
  602.  
  603.     Out_Port    MACRO    port, value
  604.  
  605. IFIDNI <ax>, <value>    ;; [ax] already loaded
  606. ELSE
  607.     mov    ax, value
  608. ENDIF
  609.  
  610. IFIDNI    <dx>, <port>    ;; [dx] already loaded
  611. ELSE
  612.     mov    dx, port
  613. ENDIF
  614.     out    dx, ax
  615. ENDM
  616.  
  617. ; PURPOSE: Input a word from the specified i/o port
  618.  
  619.     In_Port MACRO    port
  620. IFIDNI    <dx>, <port>    ;; [dx] already loaded
  621. ELSE
  622.     mov    dx, port
  623. ENDIF
  624.     in    ax, dx
  625. ENDM
  626.  
  627.  
  628. ; PURPOSE: Output a byte to the specified i/o port
  629.  
  630.     Out_Port_Byte    MACRO    port, value
  631. IFIDNI    <al>, <value>    ;; [al] already loaded
  632. ELSE
  633.     mov    al, value
  634. ENDIF
  635. IFIDNI    <dx>, <port>    ;; [dx] already loaded
  636. ELSE
  637.     mov    dx, port
  638. ENDIF
  639.     out    dx, al
  640. ENDM
  641.  
  642.  
  643. ; PURPOSE: Input a byte from the specified i/o port
  644.  
  645.     In_Port_Byte    MACRO    port
  646.     mov    dx, port        ;; output contents of ax
  647.     in    al, dx            ;; al = value from [port]
  648. ENDM
  649.  
  650.  
  651. ; PURPOSE: Wait for Vsync to go low, then high,
  652.  
  653.         Wait_For_Vsync    MACRO
  654. LOCAL    wait_low, wait_high
  655.     mov    dx, SUBSYS_STAT
  656.     mov    ax, RVBLNKFLAG
  657.     out    dx, ax             ; Clear Vsync status bit
  658. wait_low:
  659. ;     in     ax, dx
  660. ;     test     ax, VSYNC_BIT_MASK
  661. ;     jnz     wait_low        ; causes problems with ATI ********
  662.  
  663. wait_high:
  664.     in    ax, dx
  665.     test    ax, VSYNC_BIT_MASK
  666.     jz    wait_high         ; Loop until beginning of Vysnc (blank)
  667. ENDM
  668.  
  669.  
  670. ; PURPOSE: Enter Western Digital Enhanced Mode.
  671.  
  672.     Enter_WD_Enhanced_Mode    MACRO
  673.  
  674.             mov    dx, WD_ESCAPE_REG
  675.             in    al, dx
  676. ENDM
  677.  
  678.  
  679. ; PURPOSE: Write pixel data in [ax] to PIX_TRANS port [dx]
  680. ; ENTRY  : [dx] = PIX_TRANS, data in [ax]
  681.  
  682.     Write_A_Pixel    MACRO
  683.     Out_Port    dx, ax
  684. ENDM
  685.  
  686.  
  687. ; PURPOSE: Resets MULTIFUNC_CNTL register to FCOL & MIX
  688.  
  689.     Reset_MULTIFUNC_CNTL    MACRO
  690.     Out_Port    MULTIFUNC_CNTL, 0A000h
  691. ENDM
  692.  
  693. ;
  694. ; TRANSY
  695. ;
  696. ; Translate y value for the case of 4 bpp and 640x480
  697. ; The y value is assumed to be in ax.
  698. ; The result is left in ax.
  699. ; result = (y & 1) | ((y >> 1) << 2)
  700. ; by Jonathan Osuch, 2/15/92
  701. ; Not needed by Graphics Ultra, others might need it
  702. ;
  703. TRANSY   macro
  704.          push  bx
  705.          mov   bx, ax
  706.          and   bx, 1
  707.          shr   ax, 1
  708.          shl   ax, 1
  709.          shl   ax, 1
  710.          or    ax, bx
  711.          pop   bx
  712.          endm
  713. ;
  714.  
  715.  
  716. ;========================================
  717. ; Return Value Definitions
  718. ;========================================
  719. TRUE    = 1
  720. FALSE    = 0
  721.  
  722. ;*****************************************************************************
  723. ;
  724. ;        VESA STANDARD 8514/A REGISTER MNEMONICS
  725. ;
  726. ;*****************************************************************************
  727.  
  728. ;=============================
  729. ; 8514/A READBACK REGISTER SET
  730. ;=============================
  731. SETUP_ID1        equ 00100h  ; Setup Mode Identification
  732. SETUP_ID2        equ 00101h  ; Setup Mode Identification
  733. DISP_STAT        equ 002E8h  ; Display Status
  734. WD_ESCAPE_REG        equ 028E9h  ; WD Escape Functions
  735. SUBSYS_STAT        equ 042E8h  ; Subsystem Status
  736. WD_ENHANCED_MODE_REG    equ 096E8h  ; Enter WD Enhanced Mode
  737. GP_STAT            equ 09AE8h  ; Graphics Processor Status
  738. FSR_HWBUSY        equ 00200h  ; Bit Set if Hardware Busy
  739.  
  740. ;==========================
  741. ; 8514/A WRITE REGISTER SET
  742. ;==========================
  743. SETUP_OPT        equ 00102h  ; Setup Mode Option Select
  744. H_TOTAL            equ 002E8h  ; Horizontal Total
  745. DAC_MASK        equ 002EAh  ; DAC Mask
  746. DAC_R_INDEX        equ 002EBh  ; DAC Read Index
  747. DAC_W_INDEX        equ 002ECh  ; DAC Write Index
  748. DAC_DATA        equ 002EDh  ; DAC Data
  749. H_DISP            equ 006E8h  ; Horizontal Displayed
  750. H_SYNC_STRT        equ 00AE8h  ; Horizontal Sync Start
  751. H_SYNC_WID        equ 00EE8h  ; Horizontal Sync Width
  752. V_TOTAL            equ 012E8h  ; Vertical Total
  753. V_DISP            equ 016E8h  ; Vertical Displayed
  754. V_SYNC_STRT        equ 01AE8h  ; Vertical Sync Start
  755. V_SYNC_WID        equ 01EE8h  ; Vertical Sync Width
  756. DISP_CNTL        equ 022E8h  ; Display Control
  757. SUBSYS_CNTL        equ 042E8h  ; Subsystem Control
  758. ICR_GERESET        equ 09000h  ; reset mask
  759. ICR_NORMAL        equ 08000h  ; normal mask
  760. ROM_PAGE_SEL        equ 046E8h  ; ROM Page Select
  761. ADVFUNC_CNTL        equ 04AE8h  ; Advanced Function Control
  762. MODE_VGA        equ 00010b  ;
  763. MODE_768        equ 00111b  ;
  764. MODE_480        equ 00011b  ;
  765. CUR_Y            equ 082E8h  ; Current Y Position
  766. CUR_X            equ 086E8h  ; Current X Position
  767. DESTY_AXSTP        equ 08AE8h  ; Destination Y Position /
  768.                     ; Axial Step Constant
  769. DESTX_DIASTP        equ 08EE8h  ; Destination X Position /
  770.                     ; Axial Step Constant
  771. ERR_TERM        equ 092E8h  ; Error Term
  772. MAJ_AXIS_PCNT        equ 096E8h  ; Major Axis Pixel Count
  773. CMD            equ 09AE8h  ; Command
  774. SHORT_STROKE        equ 09EE8h  ; Short Stroke Vector Trnsf
  775. BKGD_COLOR        equ 0A2E8h  ; Background Color
  776. FRGD_COLOR        equ 0A6E8h  ; Foreground Color
  777. WRT_MASK        equ 0AAE8h  ; Write Mask
  778. RD_MASK            equ 0AEE8h  ; Read Mask
  779. COLOR_CMP        equ 0B2E8h  ; Color Compare
  780. BKGD_MIX        equ 0B6E8h  ; Background Mix
  781. FRGD_MIX        equ 0BAE8h  ; Foreground Mix
  782. MULTIFUNC_CNTL        equ 0BEE8h  ; Multi-Function Control
  783. PIX_TRANS        equ 0E2E8h    ; Pixel Data Transfer
  784.  
  785. MIN_AXIS_PCNT        equ  0000h   ; Minor Axis Pixel Count
  786.  
  787. T_SCISSORS        equ   1000h   ; Top Scissors
  788. L_SCISSORS        equ   2000h   ; Left Scissors
  789. B_SCISSORS        equ   3000h   ; Bottom Scissors
  790. R_SCISSORS        equ   4000h   ; Right Scissors
  791.  
  792. MEM_CNTL        equ   5000h   ; Memory Control
  793. PATTERN_L        equ   8000h   ; Fixed Pattern - Low
  794. PATTERN_H        equ   9000h   ; Fixed Pattern - High
  795. PIX_CNTL        equ  0A000h   ; Pixel Control
  796.  
  797. ; Display Status bit field
  798. HORTOG            equ    0004h    ;
  799. VBLANK            equ    0002h    ;
  800. SENSE            equ    0001h
  801.  
  802. ; Horizontal Sync Width Bit Field
  803. HSYNCPOL_NEG        equ    0020h    ;    negative polarity
  804. HSYNCPOL_POS        equ    0000h    ;    positive polarity
  805.  
  806. ; Vertical Sync Width Bit Field
  807. VSYNCPOL_NEG        equ    0020h    ;    negative polarity
  808. VSYNCPOL_POS        equ    0000h    ;    positive polarity
  809.  
  810. ; Display control  bit field
  811. DISPEN_NC        equ   0000h    ; no change
  812. DISPEN_DISAB    equ   0040h    ; disable display, syncs, and refresh
  813. DISPEN_ENAB        equ   0020h    ; enable display, syncs, and refresh
  814. INTERLACE        equ   0010h    ; interlace enable bit
  815. DBLSCAN        equ   0008h    ; double scan bit
  816. MEMCFG_2        equ   0000h    ; 2 CAS configuration
  817. MEMCFG_4        equ   0002h    ;
  818. MEMCFG_6        equ   0004h    ;
  819. MEMCFG_8        equ   0006h    ;
  820. ODDBANKENAB        equ   0001h    ; Use alternate odd/even banks for
  821.                     ; each line
  822.  
  823. ; Subsystem status register bits
  824. _8PLANE            equ   0080h   ; 8 planes of memory installed
  825. MONITORID_MASK        equ   0070h   ; Monitor ID mask
  826. MONITORID_8503        equ   0050h   ;
  827. MONITORID_8507        equ   0010h   ;
  828. MONITORID_8512        equ   0060h   ;
  829. MONITORID_8513        equ   0060h   ;
  830. MONITORID_8514        equ   0020h   ;
  831. MONITORID_NONE        equ   0070h   ;
  832. GPIDLE            equ   0008h   ; Processor idle bit, command queue empty
  833. INVALIDIO        equ   0004h   ; Set when command written to full queue
  834.                       ; or the Pixel Data Transfer register was
  835.                       ; read when no data was available.  This
  836.                       ; bit must be cleared prior to any other
  837.                       ; operation with RINVALIDIO bit
  838. PICKFLAG        equ   0002h   ; This bit is set when a write inside the
  839.                       ; clipping rectangle is about to be made.
  840.                       ; You can clear it with RPICKFLAG
  841. VBLNKFLAG        equ   0001h   ; This bit is set at the start of the
  842.                       ; vertical blanking period.  It can only
  843.                       ; be cleared by setting RVBLNKFLG
  844.  
  845. ; Subsystem Control Register bit field
  846. GPCTRL_NC        equ    0000h    ;    no change
  847. GPCTRL_ENAB        equ    4000h    ;    enable 8514
  848. GPCTRL_RESET        equ    8000h    ;    reset 8514/A and disable
  849.                     ;    also flushes command queue
  850. CHPTEST_NC        equ    0000h    ;    no change
  851. CHPTEST_NORMAL        equ    1000h    ;    Enables synchronization between
  852.                     ;    chips
  853. CHPTEST_ENAB        equ    2000h    ;    Disables synchronization.  Use
  854.                     ;    only as a diagnostic procedure
  855. IGPIDLE            equ    0800h    ;    Enable GPIDLE interrupt.
  856.                     ;    Usually this is IRQ9 (SW IRQ2)
  857. IINVALIDIO        equ    0400h    ;    Enable invalid I/O interrupt
  858.                     ;    Interrupt when subsystem status
  859.                     ;    register INVALIDIO bit set
  860. IPICKFLAG        equ    0200h    ;    Interrupts the system when
  861.                     ;    PICKFLAG in the subsystem
  862.                     ;    status register goes high
  863. IVBLNKFLAG        equ    0100h    ;    Interrupts the system when
  864.                     ;    VBLNKFLAG in Subsystem Status
  865.                     ;    goes high
  866. RGPIDLE            equ    0008h    ;    Resets GPIDLE bit in subsystem
  867.                     ;    status register
  868. RINVALIDIO        equ    0004h    ;    Resets INVALIDIO bit in
  869.                     ;    Subsystem Status Register
  870. RPICKFLAG        equ    0002h    ;    Resets PICKFLAG in Subsystem
  871.                     ;    Status Register
  872. RVBLNKFLAG        equ    0001h    ;    Resets VBLNKFLAG in Subsystem
  873.                     ;    Status Register
  874.  
  875. ; Current X, Y and Destination X, Y mask
  876. COORD_MASK        equ    07FFh    ;    coordinate mask (2047)
  877.  
  878. ; Advanced Function Control Register bit field
  879. CLKSEL            equ    0004h    ; 1 = 44.9 MHz clock, 0 = 25.175 MHz
  880. DISSABPASSTHRU        equ    0001h    ; 0 = VGA pass through, 1 = 8514/A
  881.  
  882. ; Graphics Processor Status Register
  883. GPBUSY            equ    0200h    ; 1 when processor is busy in command
  884.                     ; and in data transfer
  885. DATARDY            equ    0100h    ; 0 = no data ready to be read
  886.                     ; 1 = data ready for reading.
  887.                     ; used for Pixel Data Transfer reads
  888.  
  889. ; Command Register
  890. CMD_NOP            equ    0000h    ; do nothing
  891. CMD_LINE        equ    2000h    ; Draw a line according to LINETYPE bit
  892.                     ; when LINETYPE = 1, bits 567 specify
  893.                     ; direction of vector with length
  894.                     ; stored in Major Axis Pixel Count
  895. CMD_RECT        equ    4000h    ; Fast-Fill Rectangle accordign to
  896.                     ; PLANEMODE.  Can read as well as write
  897.                     ; according to PCDATA and WRTDATA
  898. CMD_RECTV1        equ    6000h    ; Draws a rectangle vertically in
  899.                     ; columns starting at the upper left
  900.                     ; and working down
  901. CMD_RECTV2        equ    8000h    ; Like CMD_RECT1, except accesses 4
  902.                     ; pixels at a time horizontally rather
  903.                     ; than 1
  904. CMD_LINEAF        equ    0A000h    ; Draw line for area fill.  Only draws
  905.                     ; one pixel for each scan line crossed.
  906. CMD_BITBLT        equ    0C000h    ; Copy rectangle on display and to/from
  907.                     ; PC memory through Pixel Data Transfer
  908.                     ; register.
  909. CMD_OP_MSK        equ    0E000h    ; command mask
  910. BYTSEQ            equ    01000h    ; Selects byte ordering for pixel data
  911.                     ; transfer and short-stroke vector
  912.                     ; transfer registers only.  0 = high
  913.                     ; byte first, low byte second, 1 =
  914.                     ; low byte first, high byte second.
  915. _16BIT            equ    00200h    ; Affects Pixel Data Transfer and Short
  916.                     ; Stroke Vector Transfer registers.
  917.                     ; 0 = 8-bit access, 1 = 16-bit access
  918. PCDATA            equ    00100h    ; 0 = drawing operations use 8514/A
  919.                     ;     based data
  920.                     ; 1 = drawing operations wait for
  921.                     ;     data to be written or read from
  922.                     ;     the Pixel Data Transfer register
  923.                     ;     before proceeding to the next
  924.                     ;     pixel.  Direction of transfer
  925.                     ;     is based on WRTDATA
  926. INC_Y            equ    00080h    ; Determines y direction of lines
  927.                     ; during line drawing when LINETYPE is
  928.                     ; cleared.
  929.                     ; 0 = UP, 1 = DOWN
  930. YMAJAXIS        equ    00040h    ; Determines major axis when LINETYPE
  931.                     ; is 0.
  932.                     ; 0 = X is major axis, 1 = Y is major
  933.                     ; axis.
  934. INC_X            equ    00020h    ; Determines direction of X when drawing
  935.                     ; lines when LINETYPE = 0
  936.                     ; 0 = right to left (negative X dir)
  937.                     ; 1 = left to right (positive X dir)
  938. DRAW            equ    00010h    ; 0 = move only, no pixels drawn
  939.                     ; 1 = draw
  940. LINETYPE        equ    00008h    ; Selects line drawing algorithm
  941.                     ; 0 = normal Bresenham line drawing
  942.                     ; 1 = vector drawing CMD_NOP = short
  943.                     ;    stroke, CMD_LINE = long line
  944. LASTPIX            equ    00004h    ; 0 = last pixel for lines and vectors
  945.                     ;    drawn
  946.                     ; 1 = last pixel not drawn
  947. PLANAR            equ    00002h    ; Access is Pixel at a time or Planar
  948.                     ; 0 = Pixel, 1 = Planar
  949. WRTDATA            equ    00001h    ; 0 = read operation, 1 = write
  950.                     ; used for Pixel Data Transfer
  951.  
  952. ; Short Stroke vector transfer register
  953. ; can also be used for command register when LINETYPE=1 and CMD_LINE
  954. VECDIR_000        equ    0000h
  955. VECDIR_045        equ    0020h
  956. VECDIR_090        equ    0040h
  957. VECDIR_135        equ    0060h
  958. VECDIR_180        equ    0080h
  959. VECDIR_225        equ    00A0h
  960. VECDIR_270        equ    00C0h
  961. VECDIR_315        equ    00E0h
  962. SSVDRAW            equ    0010h    ; 0 = move position, 1 = draw vector
  963.                     ; and move
  964.  
  965. ; Background MIX register
  966. BSS_BKGDCOL        equ    0000h    ; use background color
  967. BSS_FRGDCOL        equ    0020h    ; use foreground color
  968. BSS_PCDATA        equ    0040h    ; PC data (via Pixel Data Transfer reg)
  969. BSS_BITBLT        equ    0060h    ; All-Plane Copy
  970.  
  971. ; Foreground MIX register
  972. FSS_BKGDCOL        equ    0000h    ; use background color
  973. FSS_FRGDCOL        equ    0020h    ; use foreground color
  974. FSS_PCDATA        equ    0040h    ; PC data (via Pixel Data Transfer reg)
  975. FSS_BITBLT        equ    0060h    ; All-Plane Copy
  976.  
  977. ; Mixing applications
  978. MIX_MASK        equ    001Fh    ; mask for mixing values
  979.  
  980. MIX_NOT_DST        equ    0000h    ; NOT Dst
  981. MIX_0            equ    0001h    ; All bits cleared
  982. MIX_1            equ    0002h    ; All bits set
  983.  
  984. MIX_DST            equ    0003h    ; Dst
  985. MIX_LEAVE_ALONE        equ    0003h    ; Do nothing
  986.  
  987. MIX_NOT_SRC        equ    0004h    ; NOT Src
  988.  
  989. MIX_SRC_XOR_DST        equ    0005h    ; Src XOR Dst
  990. MIX_XOR            equ    0005h    ;
  991.  
  992. MIX_NOT__SRC_XOR_DST    equ    0006h    ; NOT (Src XOR Dst)
  993. MIX_XNOR        equ    0006h    ;
  994.  
  995. MIX_SRC            equ    0007h    ; Src
  996. MIX_REPLACE        equ    0007h    ;
  997. MIX_PAINT        equ    0007h    ;
  998.  
  999. MIX_NOT_SRC_OR_NOT_DST    equ    0008h    ; Not Src OR NOT Dst
  1000. MIX_NAND        equ    0008h    ;
  1001.  
  1002. MIX_NOT_SRC_OR_DST    equ    0009h    ; NOT Src OR Dst
  1003. MIX_SRC_OR_NOT_DST    equ    000Ah    ; Src OR NOT Dst
  1004.  
  1005. MIX_SRC_OR_DST        equ    000Bh    ; Src OR Dst
  1006. MIX_OR            equ    000Bh    ;
  1007.  
  1008. MIX_SRC_AND_DST        equ    000Ch    ; Src AND Dst
  1009. MIX_AND            equ    000Ch
  1010.  
  1011. MIX_SRC_AND_NOT_DST    equ    000Dh    ; Src AND NOT Dst
  1012. MIX_NOT_SRC_AND_DST    equ    000Eh    ; NOT Src AND Dst
  1013.  
  1014. MIX_NOT_SRC_AND_NOT_DST equ    000Fh    ; NOT Src AND NOT Dst
  1015. MIX_NOR            equ    000Fh    ; Src NOR Dst
  1016.  
  1017. MIX_MIN            equ    0010h    ; MINIMUM (Src, Dst)
  1018. MIX_DST_MINUS_SRC    equ    0011h    ; Dst - Src (with underflow)
  1019. MIX_SRC_MINUS_DST    equ    0012h    ; Src - Dst (with underflow)
  1020. MIX_PLUS        equ    0013h    ; Src + Dst (with overflow)
  1021. MIX_MAX            equ    0014h    ; MAXIMUM (Src, Dst)
  1022. MIX_HALF__DST_MINUS_SRC equ    0015h    ; (Dst - Src) / 2 (with underflow)
  1023. MIX_HALF__SRC_MINUS_DST equ    0016h    ; (Src - Dst) / 2 (with underflow)
  1024. MIX_AVERAGE        equ    0017h    ; (Src + Dst) / 2 (with overflow)
  1025. MIX_DST_MINUS_SRC_SAT    equ    0018h    ; (Dst - Src) (with saturate)
  1026. MIX_SRC_MINUS_DST_SAT    equ    001Ah    ; (Src - Dst) (with saturate)
  1027. MIX_PLUS_SAT        equ    001Bh    ; (Src + Dst) (with saturate)
  1028. MIX_HALF__DST_MINUS_SRC_SAT    equ    001Ch    ; (Dst - Src) / 2 (with sat)
  1029. MIX_HALF__SRC_MINUS_DST_SAT    equ    001Eh    ; (Src - Dst) / 2 (with sat)
  1030. MIX_AVERAGE_SAT        equ    001Fh    ; (Src + Dst) / 2 (with saturate)
  1031.  
  1032. ; Memory control register
  1033. BUFSWP            equ    0010h    ; pseudo 8-plane on 4-plane board
  1034. VRTCFG_2        equ    0000h    ; vertical memory configuration
  1035. VRTCFG_4        equ    0004h
  1036. VRTCFG_6        equ    0008h
  1037. VRTCFG_8        equ    000Ch
  1038. HORCFG_4        equ    0000h    ; Horizontal memory configuration
  1039. HORCFG_5        equ    0001h
  1040. HORCFG_8        equ    0002h
  1041. HORCFG_10        equ    0003h
  1042.  
  1043. ; Pixel Control Register
  1044. MIXSEL_FRGDMIX        equ    0000h    ; use foreground mix for all drawing
  1045.                     ; operations
  1046. MIXSEL_PATT        equ    0040h    ; use fixed pattern to decide which
  1047.                     ; mix setting to use on a pixel
  1048. MIXSEL_EXPPC        equ    0080h    ; PC Data Expansion.  Use data from
  1049.                     ; Pixel Transfer Register
  1050. MIXSEL_EXPBLT        equ    00C0h    ; Bits in source plane determine
  1051.                     ; foreground or background MIX
  1052.                     ; 0 = bkgd, 1 = frgd
  1053. COLCMPOP_F        equ    0000h    ; FALSE
  1054. COLCMPOP_T        equ    0008h    ; TRUE
  1055. COLCMPOP_GE        equ    0010h    ; Dst >= CC
  1056. COLCMPOP_LT        equ    0018h    ; Dst < CC
  1057. COLCMPOP_NE        equ    0020h    ; Dst != CC
  1058. COLCMPOP_EQ        equ    0028h    ; Dst == CC
  1059. COLCMPOP_LE        equ    0030h    ; Dst <= CC
  1060. COLCMPOP_GT        equ    0038h    ; Dst > CC
  1061. PLANEMODE        equ    0004h    ; Enables plane mode for area fill and
  1062.                     ; single plane expansion
  1063.  
  1064. ; The following code was written largely by Aaron Williams
  1065. ; and largely mucked up by Jonathan Osuch
  1066.  
  1067. .DATA
  1068.     TEMP_SIZE    =     12
  1069.     NUM_ENTRIES    =    256
  1070.  
  1071. __temp_palette        DB    TEMP_SIZE DUP (?)
  1072.  
  1073. Gra_mode_ctl_sh        dw    ?
  1074. WD_enhance_mode_sh    dw    0
  1075.  
  1076. extrn    sxdots:word, sydots:word  ; number of dots across and down
  1077. extrn    dacbox:byte
  1078.  
  1079. extrn        daccount:word        ; count of entries in DAC table
  1080.  
  1081. extrn        cpu:word        ; CPU type 88, 186, etc.
  1082. extrn        debugflag:word    ; for debugging purposes
  1083.  
  1084. wdth        dw    0    ; JCO 4/11/92
  1085. height    dw    0
  1086.  
  1087. bppstatus    dw    0    ; temporary status for bpp    ; JCO 4/11/92
  1088. bpp4x640    db    0    ; flag for 4 bpp and 640x480    ; JCO 4/11/92
  1089.  
  1090. adexboard    db    0    ; set to 1 when ADEX board
  1091. currentmode    dw    0    ; points to current mode table
  1092. ati_enhance_mode    dw    0    ; 1 for 800x600, 11h for 1280x1024
  1093. loadset    dd    0C0000064h    ; entries to bios jump table
  1094. setmode    dd    0C0000068h    ; modified later if rom is moved
  1095. ati_temp    dw    0
  1096.  
  1097. ; 8514/A initialization tables written by Aaron Williams
  1098. mode640    dw    2381h    ; Western Digital Enhanced Mode Register
  1099.         dw    0003h    ; advanced function control
  1100.         dw    5006h    ; Multifunction control
  1101.         dw    0063h    ; Horizontal total
  1102.         dw    004Fh    ; Horizontal displayed
  1103.         dw    0052h    ; Horizontal sync start
  1104.         dw    002Ch    ; Horizontal sync width
  1105.         dw    0418h    ; Vertical total
  1106.         dw    03BBh    ; Vertical displayed
  1107.         dw    03D2h    ; Vertical sync start
  1108.         dw    0022h    ; Vertical sync width
  1109.         dw    0023h    ; Display control
  1110.  
  1111.  
  1112. mode1024    dw    2501h    ; Western Digital Enhanced Mode Register
  1113.                 ; I will later add options for 70hz mode,
  1114.                 ; interlaced mode, etc.  This is used only
  1115.                 ; for Adex or compatible boards
  1116.                 ; for 70 hz, change to 2581h
  1117.         dw    0007h    ; advanced function control
  1118.         dw    5006h    ; Multifunction control
  1119.         dw    00A2h    ; Horizontal total
  1120.         dw    007Fh    ; Horizontal displayed
  1121.         dw    0083h    ; Horizontal sync start
  1122.         dw    0016h    ; Horizontal sync width
  1123.         dw    0660h    ; Vertical total
  1124.         dw    05FBh    ; Vertical displayed
  1125.         dw    0600h    ; Vertical sync start
  1126.         dw    0008h    ; Vertical sync width
  1127. disp1024    dw    0023h    ; Display control
  1128.  
  1129. ; The 1280 mode is supported only on Adex boards.  If anyone has any info on
  1130. ; other boards capable of this mode, I'd like to add support.
  1131. mode1280    dw    2589h    ; WD enhanced mode register
  1132.         dw    0007h    ; advanced function control
  1133.         dw    5006h    ; Multifunction control
  1134.         dw    0069h    ; Horizontal total
  1135.         dw    004Fh    ; Horizontal displayed
  1136.         dw    0053h    ; Horizontal sync start
  1137.         dw    0009h    ; Horizontal sync width
  1138.         dw    0874h    ; Vertical total
  1139.         dw    07FFh    ; Vertical displayed
  1140.         dw    0806h    ; Vertical sync start
  1141.         dw    0003h    ; Vertical sync width
  1142.         dw    0023h    ; Display control
  1143.  
  1144. ; 4bpp mode added by JCO 4/5/92, 1024x4 same as 1024x8
  1145. mode640x4    dw    0000h    ; Western Digital Enhanced Mode Register ????
  1146.         dw    0003h    ; advanced function control
  1147.         dw    5002h    ; Multifunction control    ; This may need to be 5000h
  1148.         dw    0063h    ; Horizontal total
  1149.         dw    004Fh    ; Horizontal displayed
  1150.         dw    0052h    ; Horizontal sync start
  1151.         dw    002Ch    ; Horizontal sync width
  1152.         dw    0830h    ; Vertical total
  1153.         dw    0779h    ; Vertical displayed
  1154.         dw    07A8h    ; Vertical sync start
  1155.         dw    0022h    ; Vertical sync width
  1156.         dw    0021h    ; Display control        ; This may need to be 0020h
  1157.  
  1158.  
  1159. .CODE    VIDEO_TEXT
  1160.  
  1161. ; This routine updates the 8514/A palette
  1162. ; For modes with resolutions > 1024x768, a different DAC must be used.
  1163. ; The ADEX board uses a high-speed Brooktree DAC which uses 24 bits per
  1164. ; color instead of the usual 18 bits.
  1165. ; The data is written out in 3 parts during vertical retrace to prevent snow.
  1166. ; Normal 8514/A routine modified to slow down the spin, JCO 4/3/92
  1167. w8514hwpal      proc      near
  1168.  
  1169.     mov    si, offset dacbox
  1170.     cld
  1171.  
  1172.     ; dac_w_index
  1173.     mov    dx, DAC_W_INDEX
  1174.     mov    al, 0        ;start at beginning of 8514a palette
  1175.     out    dx, al;
  1176.  
  1177.     cmp    wdth, 1024
  1178.     jbe    writedac
  1179.     cmp    adexboard, 1
  1180.     je    wbrooktree
  1181.  
  1182.  
  1183. writedac:        ; rewritten to slow down the spin,  JCO 4/11/92
  1184.     mov    cx, daccount
  1185.     mov    bx, 0        ;use bx to hold index into the dac
  1186.  
  1187.     mov    ax, 256
  1188. cpallp:
  1189.     push    ax
  1190.     cmp    ax, cx
  1191.     jae    dopass
  1192.     mov    cx, ax
  1193. dopass:
  1194.     push    cx
  1195.  
  1196. ; wait for first vertical blank
  1197.     mov    dx, DISP_STAT
  1198. chkvblnk1:        ;loop til vertical blank
  1199.     in    ax, dx        ;read status register
  1200.     test    ax, VBLANK
  1201.     jz    chkvblnk1        ;set to 1 during vertical blank
  1202.  
  1203. ; wait for screen to display
  1204. chkvblnk2:        ;loop while screen displayed
  1205.     in    ax, dx        ;read status register
  1206.     test    ax, VBLANK
  1207.     jnz    chkvblnk2        ;set to 0 during screen display
  1208.  
  1209. ; wait for next vertical blank, make sure we didn't miss it
  1210. chkvblnk3:        ;loop til vertical blank
  1211.     in    ax, dx        ;read status register
  1212.     test    ax, VBLANK
  1213.     jz    chkvblnk3        ;set to 1 during vertical blank
  1214.  
  1215. ; move the palette in dacbox
  1216.     mov    dx, DAC_DATA
  1217.  
  1218. cpall2:
  1219.     outsb        ;put red into 8514/a palette
  1220.     outsb        ;put green into 8514/a palette
  1221.     outsb        ;put blue into 8514/a palette
  1222.  
  1223.     loop    cpall2
  1224.  
  1225.     pop    cx
  1226.     add    bx, cx
  1227.     mov    dx, DAC_W_INDEX    ;load next piece of palette
  1228.     mov    ax, bx
  1229.     out    dx, al
  1230.  
  1231.     pop    ax
  1232.     sub    ax, cx
  1233.     jnz    cpallp
  1234.  
  1235.     sti
  1236.     ret
  1237.  
  1238. wbrooktree:            ; we go here for updating the Brooktree
  1239.     mov    cx, 256        ; output first 1/3 of data
  1240.     cli
  1241.     Wait_For_Vsync        ; wait for vertical retrace
  1242.     mov    dx, 02EDh
  1243. pall1:                ; the brooktree uses 8 bits instead of 6
  1244.     lodsb
  1245.     shl    al, 2
  1246.     out    dx, al
  1247.     loop    pall1
  1248.     sti
  1249.  
  1250.     mov    cx, 256        ; output second 1/3 of data
  1251.     cli
  1252.     Wait_For_Vsync        ; wait for vertical retrace
  1253.     mov    dx, 02EDh
  1254. pall2:
  1255.     lodsb
  1256.     shl    al, 2
  1257.     out    dx, al
  1258.     loop    pall2
  1259.     sti
  1260.  
  1261.     mov    cx, 256        ; output third 1/3 of data
  1262.     cli
  1263.     Wait_For_Vsync        ; wait for vertical retrace
  1264.     mov    dx, 02EDh
  1265. pall3:
  1266.     lodsb
  1267.     shl    al, 2
  1268.     out    dx, al
  1269.     loop    pall3
  1270.  
  1271.     sti
  1272.     ret
  1273. w8514hwpal    endp
  1274.  
  1275.  
  1276. ; reopen8514hw turns off VGA pass through and enables the 8514/A display
  1277. reopen8514hw    PROC    near
  1278.     cmp    adexboard, 0
  1279.     je    enableati
  1280.  
  1281.     mov    dx, WD_ESCAPE_REG
  1282.     in    al, dx
  1283.  
  1284.     mov    si, currentmode
  1285.     mov    dx, WD_ENHANCED_MODE_REG
  1286.     outsw
  1287.     jmp    enablegeneric
  1288.  
  1289. enableati:
  1290.     cmp    ati_enhance_mode, 0
  1291.     je    enablegeneric
  1292.     mov    ax, ati_enhance_mode    ; load mode into shadow set 1 (lores)
  1293.     call    dword ptr [loadset]
  1294.     mov    ax, 1    ; set lores mode
  1295.     call    dword ptr [setmode]
  1296.     ret
  1297.  
  1298. enablegeneric:
  1299.     mov    ax, [Gra_mode_ctl_sh]    ; Read shadow register.
  1300.     or    ax, BIT_0_ON        ; Set for HIRES mode
  1301.     mov    [Gra_mode_ctl_sh], ax    ; Update shadow register.
  1302.     Out_Port    ADVFUNC_CNTL, ax
  1303.     ret
  1304. reopen8514hw    ENDP
  1305.  
  1306.  
  1307. ; open8514hw initializes the 8514/A for drawing graphics.  It test for the
  1308. ; existence of an 8514/A first.
  1309. ; CY set on error
  1310. open8514hw    proc    near
  1311.     ; Test for the existence of an 8514/A card by writing to and reading
  1312.     ; from the Error term register.
  1313.     xor    al, al
  1314.     mov    adexboard, al
  1315.  
  1316.     call    load8514dacbox    ; load dacbox for 8514/A setup  JCO 4/6/92
  1317.  
  1318.     ; Assume 8514/A present and reset it.  Otherwise a locked up board
  1319.     ;  would not appear as an 8514/A.  JCO 4/3/92
  1320.     ; reset 8514/A subsystem
  1321.     mov    dx, SUBSYS_CNTL
  1322.     mov    ax, GPCTRL_RESET+CHPTEST_NORMAL ; Reset + Normal
  1323.     out    dx, ax
  1324.     mov    ax, GPCTRL_ENAB+CHPTEST_NORMAL    ; Enable + Normal
  1325.     out    dx, ax
  1326.  
  1327.     mov    dx, ERR_TERM
  1328.     mov    ax, 5A5Ah    ; output our test value
  1329.     out    dx, ax
  1330.     jmp    $+2        ; add slight delay
  1331.     jmp    $+2
  1332.     in    ax, dx
  1333.  
  1334.     cmp    ax, 5A5Ah
  1335.     je    Found_8514    ; jump if ok
  1336.  
  1337.     stc    ; set error if not found
  1338.     ret
  1339.  
  1340. Found_8514:
  1341.     ; we need at least a 186 or better for rep outsw and stuff for speed.
  1342.     ; We won't support the 8086/8088, since it's *very* unlikely that
  1343.     ; anyone with an 8088 based machine would invest in an 8514/A
  1344.     ;
  1345.     cmp    [cpu], 88
  1346.     jne    GoodCPU
  1347.  
  1348.     stc
  1349.     ret
  1350.  
  1351. GoodCPU:                ; JCO 5/8/92
  1352.     mov    bx, sxdots        ; uncommented this section and made check
  1353.     cmp    bx, 640        ; for interlaced monitor vs non-interlaced
  1354.     jbe    monitor_ok        ; any old monitor should work non-interlaced
  1355.  
  1356.     mov    dx, SUBSYS_STAT
  1357.     in    ax,dx
  1358.     and    ax, MONITORID_MASK
  1359.     cmp    ax, MONITORID_8514    ; do we need to interlace?
  1360.     jz    setinterlaced        ; yes, jump
  1361.     cmp    ax, MONITORID_8507    ; do we need to interlace?
  1362.     jz    setinterlaced        ; yes, jump
  1363.     jmp    monitor_ok            ; use default non-interlaced mode
  1364.  
  1365. setinterlaced:
  1366.     or    disp1024, INTERLACE    ; set interlace bit, JCO 5/8/92
  1367.  
  1368. monitor_ok:
  1369.  
  1370.     mov    bpp4x640, 0        ;clear flag for y value translation
  1371.     mov    dx, SUBSYS_STAT
  1372.     in    ax, dx
  1373.  
  1374. ;************** debug 4bpp
  1375.     cmp    debugflag, 8514
  1376.     jne    notest
  1377.     test    ax, _8PLANE        ;if not set, 4bpp anyway, don't change
  1378.     jnz    notest
  1379.     xor    ax, _8PLANE        ;clear the 8bpp bit to test 4bpp
  1380. notest:
  1381. ;**************
  1382.  
  1383.     mov    bppstatus, ax        ;save the status for a while
  1384.     test    ax, _8PLANE    ;is it 8 bits per pixel?
  1385.     jnz    plane8    ;yes, 1024K video memory
  1386.  
  1387. ; no, only 512K video memory, 4 bits per pixel
  1388.  
  1389.     mov    ax, sxdots    ; AX contains H resolution
  1390.  
  1391.     ; test if 640x480x4bpp
  1392.     mov    bpp4x640, 1        ;set flag for y value translation
  1393.     mov    si, offset mode640x4    ; SI = offset of register data
  1394.     mov    bx, 640        ; BX = X resolution
  1395.     mov    cx, 480        ; CX = Y resolution
  1396.     mov    wdth, bx    ; store display width
  1397.     mov    height, cx    ; store display height
  1398.     cmp    ax, 640        ; jump if this resolution is correct
  1399.     jbe    setupopen
  1400.  
  1401.     ; test if 1024x768x4bpp
  1402.     mov    bpp4x640, 0        ;clear flag for y value translation
  1403.     mov    si, offset mode1024
  1404.     mov    bx, 1024
  1405.     mov    cx, 768
  1406.     mov    wdth, bx
  1407.     mov    height, cx
  1408.     cmp    ax, 1024
  1409.     jbe    setupopen
  1410.     stc            ; oops, to high a resolution
  1411.     ret
  1412.  
  1413. plane8:
  1414.     mov    ax, sxdots    ; AX contains H resolution
  1415.  
  1416.     ; test if 640x480
  1417.     mov    si, offset mode640    ; SI = offset of register data
  1418.     mov    bx, 640        ; BX = X resolution
  1419.     mov    cx, 480        ; CX = Y resolution
  1420.     mov    wdth, bx    ; store display width
  1421.     mov    height, cx    ; store display height
  1422.     cmp    ax, 640        ; jump if this resolution is correct
  1423.     jbe    setupopen
  1424.  
  1425.     ; test if 800x600 (special ati ultra mode)
  1426.     ; si does not need to be set, everything is in eeprom
  1427.     mov    bx, 800
  1428.     mov    cx, 600
  1429.     mov    wdth, bx
  1430.     mov    height, cx
  1431.     cmp    ax, 800
  1432.     jbe    setupopen
  1433.  
  1434.     ; test if 1024x768
  1435.     mov    si, offset mode1024
  1436.     mov    bx, 1024
  1437.     mov    cx, 768
  1438.     mov    wdth, bx
  1439.     mov    height, cx
  1440.     cmp    ax, 1024
  1441.     jbe    setupopen
  1442.  
  1443.     ; must be 1280x1024
  1444.     mov    si, offset mode1280
  1445.     mov    bx, 1280
  1446.     mov    cx, 1024
  1447.     mov    wdth, bx
  1448.     mov    height, cx
  1449.  
  1450. setupopen:
  1451.     ; test for Western Digital Chipset
  1452.     mov    currentmode, si
  1453.     mov    dx, WD_ESCAPE_REG
  1454.     in    al, dx
  1455.  
  1456.     mov    ax, 6AAAh
  1457.     mov    dx, MAJ_AXIS_PCNT
  1458.     out    dx, ax
  1459.  
  1460.     mov    dx, WD_ESCAPE_REG    ; enable enhanced mode for ADEX board
  1461.     in    al, dx
  1462.  
  1463.     mov    dx, MAJ_AXIS_PCNT ; if port 96E8 is between 3F00h and 2A00h we
  1464.     in    ax, dx          ; have a WD board, else IBM/Other
  1465.     cmp    ax, 2A00h
  1466.     jb    ati_ultra
  1467.     cmp    ax, 3F00h
  1468.     ja    ati_ultra
  1469.  
  1470.     ; We must have a Western Digital chip set.
  1471.     ; May not be Adex.
  1472.     ; Future test to implement will be to write a pixel to X,Y location
  1473.     ; with X > 1024 and read it back to check for enough memory for 1280
  1474.     ; mode.
  1475.     mov    al, 1
  1476.     mov    adexboard, al    ; set adex board
  1477.     mov    dx, WD_ESCAPE_REG    ; program WD
  1478.     in    al, dx
  1479.  
  1480.     mov    dx, WD_ENHANCED_MODE_REG
  1481.     outsw                    ; output the Western Digital
  1482.                         ; enhanced mode register
  1483.  
  1484.     mov    [WD_enhance_mode_sh], ax    ; keep a copy of it
  1485.     jmp    openOK
  1486.  
  1487. ibm_8514_step:
  1488.     jmp    ibm_8514
  1489.  
  1490. ati_ultra:
  1491.     mov    ati_enhance_mode, 0    ; make sure enhanced mode is clear
  1492. ; check for ATI
  1493.     mov    dx, 52EEh        ; ROM_ADDR_1 register
  1494.     in    ax, dx
  1495.     mov    ati_temp, ax    ; temporary save
  1496.     mov    ax, 5555h
  1497.     out    dx, ax
  1498.     Wait_If_HW_Busy        ; make sure HW is not busy
  1499.     mov    dx, 52EEh        ; ROM_ADDR_1 register
  1500.     in    ax, dx
  1501.     cmp    ax, 5555h
  1502.     jne    ibm_8514_step    ; nope must be real 8514a
  1503.  
  1504.     mov    ax, 2A2Ah
  1505.     out    dx, ax
  1506.     Wait_If_HW_Busy        ; make sure HW is not busy
  1507.     mov    dx, 52EEh        ; ROM_ADDR_1 register
  1508.     in    ax, dx
  1509.     cmp    ax, 2A2Ah
  1510.     jne    ibm_8514_step    ; nope must be real 8514a
  1511.  
  1512.     mov    ax, ati_temp
  1513.     out    dx, ax    ; restore ROM_ADDR_1 register
  1514.  
  1515.     and    ati_temp, 007Fh    ; calculate the ROM base address
  1516.     mov    ax, 80h        ; (ROM_ADDR_1 & 0x7F)*0x80 + 0xC000
  1517.     mul    ati_temp
  1518.     add    ax, 0C000h
  1519.     mov    word ptr loadset+2, ax
  1520.     mov    word ptr setmode+2, ax
  1521.  
  1522.     mov    es, ax
  1523.     mov    ax, es:4Ch    ; get ati bios revision
  1524.     cmp    al, 1h
  1525.     jl    ibm_8514    ; revision level too low, can't do it
  1526.     cmp    ah, 3h
  1527.     jl    ibm_8514    ; revision level too low, can't do it
  1528.  
  1529. ; everything appears okay
  1530.  
  1531. ; get resolution, could be 800x600 or 1280x1024
  1532.     mov    ax, sxdots    ; AX contains H resolution
  1533.     cmp    ax, 640
  1534.     jbe    ibm_8514    ; too low for 800x600
  1535.     cmp    ax, 800
  1536.     jbe    set_800x600    ; must be 800x600
  1537.     cmp    ax, 1024
  1538.     jbe    ibm_8514    ; too low for 1280x1024
  1539.     cmp    ax, 1280
  1540.     jbe    set_1280x1024    ; must be 1280x1024
  1541.     jmp    ibm_8514    ; too high
  1542.  
  1543. set_800x600:
  1544.     mov    ax, 1    ; load 800x600 into shadow set 1 (lores)
  1545.     call    dword ptr [loadset]
  1546.     jc    ibm_8514    ; didn't work, forget it
  1547.     mov    ax, 1    ; set lores mode
  1548.     call    dword ptr [setmode]
  1549.     jc    ibm_8514    ; didn't work, forget it
  1550.  
  1551.     mov    ati_enhance_mode, 1    ; save mode
  1552.     jmp    setplane8
  1553.  
  1554. set_1280x1024:
  1555.     mov    ax, 11h    ; load 1280x1024 into shadow set 1 (lores)
  1556.     call    dword ptr [loadset]
  1557.     jc    ibm_8514    ; didn't work, forget it
  1558.     mov    ax, 1    ; set lores mode
  1559.     call    dword ptr [setmode]
  1560.     jc    ibm_8514    ; didn't work, forget it
  1561.  
  1562.     mov    ati_enhance_mode, 11h    ; save mode
  1563.     jmp    setplane4    ; 4 bits/pixel
  1564.  
  1565. ibm_8514:
  1566.     lodsw    ; ignore WD enhanced mode register
  1567.     cmp    wdth, 1024    ; make sure the resolution isn't too high
  1568.     jbe    openOK
  1569.  
  1570.     stc            ; a *real* 8514/A cannot run higher than
  1571.     ret            ; 1024x768, so quit
  1572.  
  1573. openOK:
  1574.     Wait_If_HW_Busy        ; make sure HW is not busy
  1575.     mov    dx, ADVFUNC_CNTL
  1576.  
  1577.     lodsw                    ; get Multifunction Control
  1578.     mov    Gra_mode_ctl_sh, ax        ; keep a copy of it
  1579.     out    dx, ax
  1580.  
  1581.     mov    dx, MULTIFUNC_CNTL        ; program multifunction control
  1582.     outsw
  1583.  
  1584.     mov    dx, H_TOTAL            ; program HTOTAL
  1585.     outsw
  1586.  
  1587.     mov    dx, H_DISP            ; program HDISPLAYED
  1588.     outsw
  1589.  
  1590.     mov    dx, H_SYNC_STRT            ; set start of HSYNC
  1591.     outsw
  1592.  
  1593.     mov    dx, H_SYNC_WID            ; set width of HSYNC signal
  1594.     outsw
  1595.  
  1596.     mov    dx, V_TOTAL            ; set vertical total
  1597.     outsw
  1598.  
  1599.     mov    dx, V_DISP            ; set vertical resolution
  1600.     outsw
  1601.  
  1602.     mov    dx, V_SYNC_STRT            ; set start of V Sync
  1603.     outsw
  1604.  
  1605.     mov    dx, V_SYNC_WID            ; set width of V Sync signal
  1606.     outsw
  1607.  
  1608.     mov    dx, DISP_CNTL            ; set the display control
  1609.     outsw
  1610.  
  1611.     mov    ax, bppstatus        ;get status again, push/pop doesn't work!
  1612.     test    ax, _8PLANE
  1613.     jnz    setplane8
  1614.  
  1615. ; enable 4 bits per pixel
  1616. setplane4:
  1617.     mov    ax, 0Fh
  1618.     mov    dx, DAC_MASK
  1619.     out    dx, al
  1620.     mov    ax, 0FF0Fh
  1621.     mov    dx, WRT_MASK
  1622.     out    dx, ax
  1623.     jmp    doneset
  1624.  
  1625. setplane8:
  1626. ; enable 8 bits per pixel
  1627.     mov    ax, 0FFh
  1628.     mov    dx, DAC_MASK
  1629.     out    dx, al
  1630.     mov    ax, 0FFFFh
  1631.     mov    dx, WRT_MASK
  1632.     out    dx, ax
  1633.  
  1634. doneset:
  1635. ; Complete environment set up 3/20/92 JCO
  1636.     Out_Port    BKGD_MIX, <BSS_BKGDCOL or MIX_REPLACE>    ;set mixes
  1637. ; FRGD_MIX set below
  1638. ; WRT_MASK set above
  1639.     Out_Port    MULTIFUNC_CNTL, <PIX_CNTL or 0h>    ; clear lower bits
  1640. ; 3/20/92 JCO
  1641.  
  1642.     ; set clipping
  1643.     Wait_Till_FIFO    FOUREMPTY    ; wait for room in queue
  1644.     mov    dx, MULTIFUNC_CNTL
  1645.     mov    ax, T_SCISSORS
  1646.     out    dx, ax            ; set top clip to 0
  1647.     mov    ax, cx
  1648.     dec    ax
  1649.     or    ax, B_SCISSORS
  1650.     out    dx, ax            ; set bottom clip to maxy
  1651.  
  1652.     mov    ax, L_SCISSORS
  1653.     out    dx, ax            ; set left clip to 0
  1654.  
  1655.     mov    ax, bx
  1656.     dec    ax
  1657.     or    ax, R_SCISSORS        ; set right clip to maxx
  1658.     out    dx, ax
  1659.  
  1660.     ; clear screen
  1661.     Wait_Till_FIFO    SIXEMPTY       ; wait for room in FIFO
  1662.     mov    dx, FRGD_MIX
  1663.     mov    ax, 0021h    ; zero memory ?? why 21h and not 01h? JCO
  1664.     out    dx, ax
  1665.  
  1666.     xor    ax, ax
  1667.     mov    dx, CUR_X    ; set start of rectangle to 0,0
  1668.     out    dx, ax
  1669.  
  1670.     mov    dx, CUR_Y
  1671.     out    dx, ax
  1672.  
  1673.     mov    ax, wdth
  1674.     mov    dx, MAJ_AXIS_PCNT
  1675.     dec    ax
  1676.     out    dx, ax        ; set width of rectangle to draw
  1677.  
  1678.     mov    ax, height
  1679.     mov    dx, MULTIFUNC_CNTL
  1680.     dec    ax
  1681.     out    dx, ax        ; set height of rectangle to draw
  1682.  
  1683. ;    Reset_MULTIFUNC_CNTL    ; done above
  1684.     mov    dx, CMD
  1685.     mov    ax, 42F3h        ; issue rect draw command
  1686.     out    dx, ax        ; draw the rectangle
  1687.  
  1688. ;    Wait_Till_FIFO    ONEEMPTY    ; set write mask  ** done above
  1689. ;    mov    dx, WRT_MASK        ; to include all
  1690. ;    mov    ax, 00FFh            ; bits
  1691. ;    out    dx, ax
  1692.  
  1693.     Wait_Till_FIFO    THREEEMPTY    ; set foreground to default
  1694.     mov    dx, FRGD_MIX
  1695. ;    mov    ax, FSS_PCDATA + MIX_SRC
  1696.     mov    ax, FSS_FRGDCOL + MIX_SRC    ;slightly faster to not use pcdata
  1697.                             ;to draw the dots, JCO 4/12/92
  1698.     out    dx, ax
  1699.  
  1700.     xor    ax, ax
  1701.     mov    dx, CUR_X        ; set X,Y back to 0,0
  1702.     out    dx, ax
  1703.     mov    dx, CUR_Y
  1704.     out    dx, ax
  1705.  
  1706.     ; enable palette
  1707.     Wait_If_HW_Busy        ; wait until HW is done
  1708.  
  1709.     cmp    adexboard, 1    ; if adex board, we must assume a brooktree
  1710.     jne    notadexdac    ; dac at all resolutions > 1024x768
  1711.     cmp    wdth, 1024    ;
  1712.     ja    brooktree    ; jmp if using special Brooktree RAMDAC
  1713.  
  1714. notadexdac:
  1715. ;    mov    dx, 2EAh    ; set palette mask ** done above
  1716. ;    mov    al, 0FFh
  1717. ;    out    dx, al
  1718.     jmp    paletteinitdone
  1719.  
  1720. brooktree:            ; brooktree DAC requires special
  1721.     mov    dx, 2ECh    ; configuration.  This DAC is required
  1722.     mov    al, 04h        ; for 1280x1024 resolution, and it is not
  1723.     out    dx, al        ; totally compatible with the standard RAMDAC
  1724.     mov    dx, 2EAh
  1725.     mov    al, 0FFh    ; This code enables the DAC for proper operation
  1726.     out    dx, al
  1727.     mov    dx, 2ECh
  1728.     mov    al, 05h
  1729.     out    dx, al
  1730.     mov    dx, 2EAh
  1731.     mov    al, 0h
  1732.     out    dx, al
  1733.     mov    dx, 2ECh
  1734.     mov    al, 06h
  1735.     out    dx, al
  1736.     mov    dx, 2EAh
  1737.     mov    al, 040h
  1738.     out    dx, al
  1739.  
  1740. paletteinitdone:
  1741. ;    push    bx    ; This works if another video mode is used first. JCO 4/9/92
  1742. ;    push    cx    ; Using load8514dacbox, above, sets the 8514/A palette.
  1743. ;    call    w8514hwpal        ; set 8514 palette
  1744. ;    pop    cx
  1745. ;    pop    bx
  1746.  
  1747.     mov    ax, bx
  1748.     sub    ax, sxdots            ;save centering factor
  1749.     shr    ax, 1
  1750.     mov    xadj, ax
  1751.  
  1752.     mov    ax, cx
  1753.     sub    ax, sydots
  1754.     shr    ax, 1
  1755.     mov    yadj, ax
  1756.     clc            ; no errors
  1757.     ret
  1758. open8514hw    endp
  1759.  
  1760.  
  1761. ;reopen8514hw    proc    near
  1762. ; Return to 8514/A after VGA
  1763. ;    call    enableHIRES
  1764. ;    ret
  1765. ;reopen8514hw    endp
  1766.  
  1767.  
  1768. fr85hwwdot    proc    near
  1769. ; draws a pixel at cx,dx of color al
  1770.     mov    bx, dx        ; temporary save of dx (y position)
  1771.  
  1772.     push    ax        ; need to save ax register (color)
  1773.     Wait_Till_FIFO FIVEEMPTY
  1774.  
  1775.     pop    ax
  1776.     mov    dx, FRGD_COLOR
  1777.     out    dx, ax
  1778.  
  1779.     add    cx, xadj
  1780.     mov    ax, cx
  1781.     mov    dx, CUR_X
  1782.     out    dx, ax            ; set x position
  1783.  
  1784.     mov    ax, bx            ; put y position into ax
  1785.     add    ax, yadj
  1786.  
  1787. ;******* not needed by Graphics Ultra, may be needed by others.
  1788. ;******* would only be needed in 640x480x16 mode, 512K video memory
  1789. ;    cmp    bpp4x640, 1
  1790. ;    jne    wdotnorm
  1791. ;    TRANSY    ;flag set, translate y value
  1792. ;wdotnorm:
  1793.  
  1794.     mov    dx, CUR_Y
  1795.     out    dx, ax            ; set y position
  1796.  
  1797.     ; next, set up command register
  1798.     Out_Port    CMD, <CMD_NOP or LINETYPE or WRTDATA>
  1799.     Out_Port    SHORT_STROKE, <VECDIR_000 or SSVDRAW or 0> ; plot 1 pixel
  1800.  
  1801.     ret
  1802.  
  1803. fr85hwwdot    endp
  1804.  
  1805.  
  1806. fr85hwwbox    proc    near uses si
  1807. ; copies a line of data from ds:si to the display from cx,dx to ax,dx
  1808.  
  1809.     sub    ax, cx    ; delta is now in ax, 8514/a uses deltas
  1810.     mov    bx, ax    ; temporary save
  1811.  
  1812.     push    dx        ; need to save dx register (y value)
  1813.     Wait_Till_FIFO    SIXEMPTY
  1814.     pop    ax
  1815.  
  1816.     add    ax, yadj
  1817.  
  1818. ;******* not needed by Graphics Ultra, may be needed by others.
  1819. ;******* would only be needed in 640x480x16 mode, 512K video memory
  1820. ;    cmp    bpp4x640, 1
  1821. ;    jne    wboxnorm
  1822. ;    TRANSY    ;flag set, translate y value
  1823. ;wboxnorm:
  1824.  
  1825.     mov    dx, CUR_Y
  1826.     out    dx, ax    ; y position
  1827.  
  1828.     add    cx, xadj
  1829.     mov    ax, cx
  1830.     mov    dx, CUR_X
  1831.     out    dx, ax    ; x position
  1832.  
  1833.     mov    ax, bx
  1834.     mov    dx, MAJ_AXIS_PCNT
  1835.     out    dx, ax    ; line length delta
  1836.  
  1837.     Out_Port FRGD_MIX, <FSS_PCDATA or MIX_SRC>    ;set mix
  1838.  
  1839.     mov    cx, bx    ; number of pixels delta
  1840.     inc    cx        ; number of bytes to move
  1841.     shr    cx, 1        ; number of words to move
  1842.     jnc    evn        ; carry set if odd number of bytes
  1843.     inc    cx        ; write last byte
  1844. evn:
  1845.  
  1846.     Out_Port CMD, <CMD_LINE or LINETYPE or _16BIT or BYTSEQ or PCDATA \
  1847.                      or DRAW or WRTDATA or VECDIR_000>
  1848.     cld
  1849.     mov    dx, PIX_TRANS
  1850.  
  1851.     rep    outsw
  1852.  
  1853.     Out_Port FRGD_MIX, <FSS_FRGDCOL or MIX_SRC>    ;reset mix
  1854.  
  1855.     ret
  1856.  
  1857. fr85hwwbox    endp
  1858.  
  1859.  
  1860. fr85hwrdot    proc    near
  1861. ; Reads a single pixel (x,y = cx,dx).  Color returned in ax
  1862.  
  1863.     push    dx        ; need to save dx register (y value)
  1864.     Wait_Till_FIFO    FOUREMPTY
  1865.     pop    ax        ; put y position into ax
  1866.     add    ax, yadj
  1867.  
  1868. ;******* not needed by Graphics Ultra, may be needed by others.
  1869. ;******* would only be needed in 640x480x16 mode, 512K video memory
  1870. ;    cmp    bpp4x640, 1
  1871. ;    jne    rdotnorm
  1872. ;    TRANSY    ;flag set, translate y value
  1873. ;rdotnorm:
  1874.  
  1875.     mov    dx, CUR_Y
  1876.     out    dx, ax            ; set y position
  1877.  
  1878.     mov    ax, cx            ; put x position into ax
  1879.     add    ax, xadj
  1880.     mov    dx, CUR_X
  1881.     out    dx, ax            ; set x position
  1882.  
  1883.     ; next, set up command register
  1884.     Out_Port    CMD, <CMD_NOP or LINETYPE or PCDATA>
  1885.     Out_Port    SHORT_STROKE, <VECDIR_000 or SSVDRAW or 0> ; move to pixel
  1886.  
  1887.     Wait_Till_Data_Avail        ; make sure data is available to read
  1888.     In_Port    PIX_TRANS
  1889.  
  1890.     ret
  1891.  
  1892. fr85hwrdot    endp
  1893.  
  1894. fr85hwrbox    proc    near uses es
  1895. ; copies a line of data from cx,dx to ax,dx to es:di
  1896.     mov    bx, ds    ;set up string write
  1897.     mov    es, bx
  1898.  
  1899.     sub    ax, cx    ; delta is now in ax, 8514/a uses deltas
  1900.     mov    bx, ax    ; temporary save
  1901.  
  1902.     push    dx        ; need to save dx register
  1903.     Wait_Till_FIFO    FOUREMPTY
  1904.     pop    ax        ; put y value in ax
  1905.  
  1906.     add    ax, yadj
  1907.  
  1908. ;******* not needed by Graphics Ultra, may be needed by others.
  1909. ;******* would only be needed in 640x480x16 mode, 512K video memory
  1910. ;    cmp    bpp4x640, 1
  1911. ;    jne    rboxnorm
  1912. ;    TRANSY    ;flag set, translate y value
  1913. ;rboxnorm:
  1914.  
  1915.     mov    dx, CUR_Y
  1916.     out    dx, ax    ; y position
  1917.  
  1918.     add    cx, xadj
  1919.     mov    ax, cx
  1920.     mov    dx, CUR_X
  1921.     out    dx, ax    ; x position
  1922.  
  1923.     mov    ax, bx
  1924.     mov    dx, MAJ_AXIS_PCNT
  1925.     out    dx, ax  ; line length delta
  1926.  
  1927.     mov    cx, bx    ; number of pixels delta
  1928.     inc    cx        ; number of bytes to move
  1929.     shr    cx, 1        ; number of words to move
  1930.     jnc    revn        ; carry set if odd number of bytes
  1931.     inc    cx        ; read last byte
  1932. revn:
  1933.  
  1934.     Out_Port CMD, <CMD_LINE or LINETYPE or _16BIT or BYTSEQ or PCDATA \
  1935.                      or DRAW or VECDIR_000>
  1936.     cld        ; di is already set when routine is entered
  1937.     Wait_Till_Data_Avail    ; wait until data is available
  1938.     mov    dx, PIX_TRANS
  1939.  
  1940.     rep    insw
  1941.  
  1942.     ret
  1943.  
  1944. fr85hwrbox    endp
  1945.  
  1946.  
  1947. ; enableVGA causes the VGA pass-through to be enabled.
  1948. ; This was mostly written by Roger Brown, and optimized and updated by
  1949. ; Aaron Williams
  1950. enableVGA    PROC    USES   ds es si di
  1951.     ; disable DAC mask
  1952.     mov    al, 0
  1953.     Out_Port_Byte  DAC_MASK, al
  1954.  
  1955.     Wait_For_Vsync
  1956.  
  1957.     ; use VGA lock up palette for Hi Res mode 8514/a display
  1958.  
  1959.     xor    bx, bx        ; Initial palette entry
  1960.  
  1961. read_palette_loop:
  1962.     mov    di, OFFSET __temp_palette    ; Buffer address
  1963.  
  1964.     mov    al, bl        ; [1] VGA 3C8h register is byte
  1965.                 ; register, use byte output only
  1966.     mov    dx, 3c8h    ; VGA_DAC_W reg.
  1967.     out    dx, al
  1968.  
  1969.     mov    dx, 3c7h    ; set VGA DAC read index
  1970.     out    dx, al        ; any write change mode
  1971.  
  1972.     mov    cx, TEMP_SIZE    ; Number of bytes to read each pass
  1973.     mov    dx, 3c9h    ; VGA_DAC_DATA_REG
  1974.     mov    ax, ds        ; Segment of _temp_palette[]
  1975.     mov    es, ax
  1976.     cld
  1977.     rep    insb        ; Read in the palette
  1978.  
  1979.  
  1980.     ; BX->start_index, CX->count, DS:DI->DWORD
  1981.  
  1982.     Out_Port_Byte  DAC_W_INDEX, bl
  1983.     cli
  1984.     cld
  1985.     mov    si, OFFSET __temp_palette    ; Buffer address
  1986.     mov    dx, DAC_DATA
  1987.     mov    cx, (TEMP_SIZE )     ; Number of entries to write each pass
  1988.     rep outsb            ; update the DAC data
  1989.     sti
  1990.  
  1991.     mov    cx, (TEMP_SIZE / 3)
  1992.     add    bx, cx
  1993.     cmp    bx, NUM_ENTRIES
  1994.     jl    read_palette_loop
  1995.  
  1996.     ; reading vga DAC mask and writing to 8514 DAC mask 02EA
  1997.  
  1998.     mov    dx, 3c6h
  1999.     in    al, dx
  2000.     Out_Port_Byte  DAC_MASK, al
  2001.  
  2002.     ; enable vga pass-through mode
  2003.  
  2004.     mov    ax, Gra_mode_ctl_sh    ; Read shadow register.
  2005.                     ; [2] No FIFO checking needed for
  2006.                     ; 4AE8h register.
  2007.     and    ax, BIT_0_OFF        ; Set for VGA pass-through mode.
  2008.     mov    Gra_mode_ctl_sh, ax
  2009.     Out_Port    ADVFUNC_CNTL, ax;
  2010.  
  2011.     ret
  2012. enableVGA    ENDP
  2013.  
  2014.  
  2015. close8514hw    proc    near
  2016.  
  2017.     ; Re-enables VGA pass-through.
  2018.  
  2019.     cmp    adexboard, 0
  2020.     je    close_notAdex    ; Don't call enableVGA if not Adex, JCO 4/4/92
  2021.     call    enableVGA        ; This seems to transfer the dac from
  2022.                     ;  the VGA to the 8514/A and then enable
  2023.                     ;  VGA mode!!!
  2024.  
  2025.     mov    si, offset mode1024
  2026.     mov    dx, WD_ESCAPE_REG    ; program WD
  2027.     in    al, dx
  2028.  
  2029.     mov    dx, WD_ENHANCED_MODE_REG
  2030.     outsw
  2031.  
  2032. close_notAdex:
  2033.     cmp    ati_enhance_mode, 0
  2034.     je    close_notati
  2035.     mov    ax, 0    ; load defaults into shadow sets
  2036.     call    dword ptr [loadset]
  2037.     mov    ax, 0    ; set VGA passthrough
  2038.     call    dword ptr [setmode]
  2039.  
  2040. close_notati:
  2041.     mov    dx, ADVFUNC_CNTL
  2042.     mov    ax, 6
  2043.     out    dx, ax            ; enable VGA
  2044.  
  2045.     ret
  2046. close8514hw    endp
  2047.  
  2048.  
  2049. ; This routine sets 320x200x256 VGA mode and then loads dacbox, JCO 4/11/92
  2050. load8514dacbox proc near uses es
  2051.  
  2052.     mov    ax,13h            ; switch to 320x200x256 mode
  2053.     int    10h
  2054.     push    ds            ;  ...
  2055.     pop    es            ;  ...
  2056.     mov    ax,1017h        ; get the old DAC values
  2057.     mov    bx,0            ;  (assuming, of course, they exist)
  2058.     mov    cx,256        ;  ...
  2059.     mov    dx,offset dacbox    ;  ...
  2060.     int    10h            ; do it.
  2061.     ret
  2062.  
  2063. load8514dacbox    endp
  2064.  
  2065. END
  2066.