home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 67.img / VGAKIT34.ZIP / BANKS.ASM next >
Assembly Source File  |  1990-05-04  |  11KB  |  723 lines

  1.  
  2.     include    model.h
  3.  
  4. ;
  5. ;    VGAKIT Version 3.4
  6. ;
  7. ;    Copyright 1988,89,90 John Bridges
  8. ;    Free for use in commercial, shareware or freeware applications
  9. ;
  10. ;    BANKS.ASM
  11. ;
  12. .data
  13.  
  14. OSEG    equ    DS:            ;segment override for variable access
  15.  
  16. bankadr    dw    ?
  17. if @Codesize
  18. bankseg    dw    ?
  19. endif
  20.  
  21.     public    curbk
  22.  
  23. curbk    dw    ?
  24.  
  25.     public    vga512
  26.  
  27. vga512    dw    ?
  28.  
  29.     public    cirrus,video7,tseng,tseng4,paradise,chipstech,trident
  30.     public    ativga,everex,aheada,aheadb,oaktech
  31.  
  32. cirrus    dw    ?
  33. video7    dw    ?
  34. tseng    dw    ?
  35. tseng4    dw    ?
  36. paradise dw    ?
  37. chipstech dw    ?
  38. trident    dw    ?
  39. ativga    dw    ?
  40. everex    dw    ?
  41. aheada    dw    ?
  42. aheadb    dw    ?
  43. oaktech    dw    ?
  44.  
  45. first    dw    ?        ;flag so whichvga() is only called once
  46. retval    dw    ?        ;first return value from whichvga()
  47.  
  48. .code
  49.  
  50.     public    newbank
  51.     public    whichvga
  52.  
  53. newbank    proc            ;bank number is in AX
  54.     cli
  55.     mov    OSEG[curbk],ax
  56. if @Codesize
  57.     jmp    dword ptr OSEG[bankadr]
  58. else
  59.     jmp    word ptr OSEG[bankadr]
  60. endif
  61.  
  62. _tseng::                ;Tseng
  63.     push    ax
  64.     push    dx
  65.     and    al,7
  66.     mov    ah,al
  67.     shl    al,1
  68.     shl    al,1
  69.     shl    al,1
  70.     or    al,ah
  71.     or    al,01000000b
  72.     mov    dx,3cdh
  73.     out    dx,al
  74.     sti
  75.     pop    dx
  76.     pop    ax
  77.     ret
  78.  
  79.  
  80. _tseng4::            ;Tseng 4000 series
  81.     push    ax
  82.     push    dx
  83.     mov    ah,al
  84.     mov    dx,3bfh            ;Enable access to extended registers
  85.     mov    al,3
  86.     out    dx,al
  87.     mov    dl,0d8h
  88.     mov    al,0a0h
  89.     out    dx,al
  90.     and    ah,15
  91.     mov    al,ah
  92.     shl    al,1
  93.     shl    al,1
  94.     shl    al,1
  95.     shl    al,1
  96.     or    al,ah
  97.     mov    dl,0cdh
  98.     out    dx,al
  99.     sti
  100.     pop    dx
  101.     pop    ax
  102.     ret
  103.  
  104.  
  105. _trident::            ;Trident
  106.     push    ax
  107.     push    dx
  108.     mov    dx,3ceh        ;set page size to 64k
  109.     mov    al,6
  110.     out    dx,al
  111.     inc    dl
  112.     in    al,dx
  113.     dec    dl
  114.     or    al,4
  115.     mov    ah,al
  116.     mov    al,6
  117.     out    dx,ax
  118.         
  119.     mov    dl,0c4h        ;switch to BPS mode
  120.     mov    al,0bh
  121.     out    dx,al
  122.     inc    dl
  123.     in    al,dx
  124.     dec    dl
  125.  
  126.     mov    ah,byte ptr OSEG[curbk]
  127.     xor    ah,2
  128.     mov    dx,3c4h
  129.     mov    al,0eh
  130.     out    dx,ax
  131.     sti
  132.     pop    dx
  133.     pop    ax
  134.     ret
  135.  
  136.  
  137. _video7::            ;Video 7
  138.     push    ax
  139.     push    dx
  140.     push    cx
  141.     and    ax,15
  142.     mov    ch,al
  143.     mov    dx,3c4h
  144.     mov    ax,0ea06h
  145.     out    dx,ax
  146.     mov    ah,ch
  147.     and    ah,1
  148.     mov    al,0f9h
  149.     out    dx,ax
  150.     mov    al,ch
  151.     and    al,1100b
  152.     mov    ah,al
  153.     shr    ah,1
  154.     shr    ah,1
  155.     or    ah,al
  156.     mov    al,0f6h
  157.     out    dx,al
  158.     inc    dx
  159.     in    al,dx
  160.     dec    dx
  161.     and    al,not 1111b
  162.     or    ah,al
  163.     mov    al,0f6h
  164.     out    dx,ax
  165.     mov    ah,ch
  166.     mov    cl,4
  167.     shl    ah,cl
  168.     and    ah,100000b
  169.     mov    dl,0cch
  170.     in    al,dx
  171.     mov    dl,0c2h
  172.     and    al,not 100000b
  173.     or    al,ah
  174.     out    dx,al
  175.     sti
  176.     pop    cx
  177.     pop    dx
  178.     pop    ax
  179.     ret
  180.  
  181.     
  182. _paradise::            ;Paradise
  183.     push    ax
  184.     push    dx
  185.     mov    dx,3ceh
  186.     mov    ax,50fh        ;turn off write protect on VGA registers
  187.     out    dx,ax
  188.     mov    ah,byte ptr OSEG[curbk]
  189.     shl    ah,1
  190.     shl    ah,1
  191.     shl    ah,1
  192.     shl    ah,1
  193.     mov    al,9
  194.     out    dx,ax
  195.     sti
  196.     pop    dx
  197.     pop    ax
  198.     ret
  199.  
  200.  
  201. _chipstech::            ;Chips & Tech
  202.     push    ax
  203.     push    dx
  204.     mov     dx,46e8h    ;place chip in setup mode
  205.     mov     ax,1eh
  206.     out     dx,ax
  207.     mov     dx,103h        ;enable extended registers
  208.     mov     ax,0080h
  209.     out     dx,ax
  210.     mov     dx,46e8h    ;bring chip out of setup mode
  211.     mov     ax,0eh
  212.     out     dx,ax
  213.     mov    ah,byte ptr OSEG[curbk]
  214.     shl    ah,1        ;change 64k bank number into 16k bank number
  215.     shl    ah,1
  216.     mov    al,10h
  217.     mov    dx,3d6h
  218.     out    dx,ax
  219.     sti
  220.     pop    dx
  221.     pop    ax
  222.     ret
  223.  
  224.  
  225. _ativga::            ;ATI VGA Wonder
  226.     push    ax
  227.     push    dx
  228.     mov    ah,al
  229.     mov    dx,1ceh
  230.     mov    al,0b2h
  231.     out    dx,al
  232.     inc    dl
  233.     in    al,dx
  234.     shl    ah,1
  235.     and    al,0e1h
  236.     or    ah,al
  237.     mov    al,0b2h
  238.     dec    dl
  239.     out    dx,ax
  240.     sti
  241.     pop    dx
  242.     pop    ax
  243.     ret
  244.  
  245.  
  246. _everex::            ;Everex
  247.     push    ax
  248.     push    dx
  249.     push    cx
  250.     mov    cl,al
  251.     mov    dx,3c4h
  252.     mov    al,8
  253.     out    dx,al
  254.     inc    dl
  255.     in    al,dx
  256.     dec    dl
  257.     shl    al,1
  258.     shr    cl,1
  259.     rcr    al,1
  260.     mov    ah,al
  261.     mov    al,8
  262.     out    dx,ax
  263.     mov    dl,0cch
  264.     in    al,dx
  265.     mov    dl,0c2h
  266.     and    al,0dfh
  267.     shr    cl,1
  268.     jc    nob2
  269.     or    al,20h
  270. nob2:    out    dx,al
  271.     sti
  272.     pop    cx
  273.     pop    dx
  274.     pop    ax
  275.     ret
  276.  
  277.  
  278. _aheada::            ;Ahead Systems Ver A
  279.     push    ax
  280.     push    dx
  281.     push    cx
  282.     mov    ch,al
  283.         mov     dx,3ceh        ;Enable extended registers
  284.         mov     ax,200fh
  285.         out     dx,ax
  286.     mov    dl,0cch        ;bit 0
  287.     in    al,dx
  288.     mov    dl,0c2h
  289.     and    al,11011111b
  290.     shr    ch,1
  291.     jnc    skpa
  292.     or    al,00100000b
  293. skpa:    out    dx,al
  294.     mov    dl,0cfh        ;bits 1,2,3
  295.     mov    al,0
  296.     out    dx,al
  297.     inc    dx
  298.     in    al,dx
  299.     dec    dx
  300.     and    al,11111000b
  301.     or    al,ch
  302.     mov    ah,al
  303.     mov    al,0
  304.     out    dx,ax
  305.     sti
  306.     pop    cx
  307.     pop    dx
  308.     pop    ax
  309.     ret
  310.  
  311.  
  312. _aheadb::            ;Ahead Systems Ver A
  313.     push    ax
  314.     push    dx
  315.     push    cx
  316.     mov    ch,al
  317.         mov     dx,3ceh        ;Enable extended registers
  318.         mov     ax,200fh
  319.         out     dx,ax
  320.     mov    ah,ch
  321.     mov    cl,4
  322.     shl    ah,cl
  323.     or    ah,ch
  324.     mov    al,0dh
  325.     out    dx,ax
  326.     sti
  327.     pop    cx
  328.     pop    dx
  329.     pop    ax
  330.     ret
  331.  
  332.  
  333. _oaktech::            ;Oak Technology Inc OTI-067
  334.     push    ax
  335.     push    dx
  336.     and    al,15
  337.     mov    ah,al
  338.     shl    al,1
  339.     shl    al,1
  340.     shl    al,1
  341.     shl    al,1
  342.     or    al,ah
  343.     mov    dx,3dfh
  344.     out    dx,al
  345.     sti
  346.     pop    dx
  347.     pop    ax
  348.     ret
  349.  
  350.  
  351. _nobank::
  352.     sti
  353.     ret
  354.  
  355. newbank    endp
  356.  
  357. bkadr    macro    func
  358.     mov    [func],1
  359.     mov    [bankadr],offset _&func
  360. if @Codesize
  361.     mov    [bankseg],seg _&func
  362. endif
  363.     endm
  364.  
  365. nojmp    macro
  366.     local    lbl
  367.     jmp    lbl
  368. lbl:
  369.     endm
  370.     
  371.  
  372. whichvga proc    uses si
  373.     cmp    [first],0
  374.     jz    gotest
  375.     mov    ax,[retval]
  376.     ret
  377. gotest:    mov    [bankadr],offset _nobank
  378. if @Codesize
  379.     mov    [bankseg],seg _nobank
  380. endif
  381.     mov    [curbk],0
  382.     mov    [vga512],0
  383.     mov    [cirrus],0
  384.     mov    [video7],0
  385.     mov    [tseng],0
  386.     mov    [tseng4],0
  387.     mov    [paradise],0
  388.     mov    [chipstech],0
  389.     mov    [trident],0
  390.     mov    [ativga],0
  391.     mov    [everex],0
  392.     mov    [aheada],0
  393.     mov    [aheadb],0
  394.     mov    [oaktech],0
  395.     mov    [first],1
  396.     mov    si,1
  397.     mov    ax,0c000h
  398.     mov    es,ax
  399.     cmp    word ptr es:[40h],'13'
  400.     jnz    noati
  401.     bkadr    ativga
  402.     cli
  403.     mov    dx,1ceh
  404.     mov    al,0bbh
  405.     out    dx,al
  406.     inc    dl
  407.     in    al,dx
  408.     sti
  409.     and    al,20h
  410.     jz    no512
  411.     mov    [vga512],1
  412. no512:    jmp    fini
  413.  
  414. noati:    mov    ax,7000h        ;Test for Everex
  415.     xor    bx,bx
  416.     cld
  417.     int    10h
  418.     cmp    al,70h
  419.     jnz    noev
  420.     bkadr    everex
  421.     and    ch,11000000b
  422.     jz    skp    
  423.     mov    [vga512],1
  424. skp:    and    dx,0fff0h
  425.     cmp    dx,6780h
  426.     jz    yeste
  427.     cmp    dx,2360h
  428.     jnz    note
  429. yeste:    bkadr    trident
  430. note:    jmp    fini
  431.  
  432. noev:    mov    dx,3c4h            ;Test for Trident
  433.     mov    al,0bh
  434.     out    dx,al
  435.     inc    dl
  436.     in    al,dx
  437.     cmp    al,0fh
  438.     ja    notri
  439.     cmp    al,2
  440.     jb    notri
  441.     bkadr    trident
  442.     mov    [vga512],1
  443.     jmp    fini
  444.  
  445. notri:    mov    ax,6f00h        ;Test for Video 7
  446.     xor    bx,bx
  447.     cld
  448.     int    10h
  449.     cmp    bx,'V7'
  450.     jnz    nov7
  451.     bkadr    video7
  452.     mov    ax,6f07h
  453.     cld
  454.     int    10h
  455.     and    ah,7fh
  456.     cmp    ah,1
  457.     jbe    skp2
  458.     mov    [vga512],1
  459. skp2:    jmp    fini
  460.  
  461. nov7:    call    _cirrus            ;Test for Cirrus
  462.     cmp    [cirrus],0
  463.     je    noci
  464.     jmp    fini
  465.  
  466. noci:    mov    dx,3ceh            ;Test for Paradise
  467.     mov    al,9            ;check Bank switch register
  468.     out    dx,al
  469.     inc    dx
  470.     in    al,dx
  471.     dec    dx
  472.     or    al,al
  473.     jnz    nopd
  474.  
  475.     mov    ax,50fh            ;turn off write protect on VGA registers
  476.     out    dx,ax
  477.     mov    dx,offset _pdrsub
  478.     mov    cx,1
  479.     call    _chkbk
  480.     jc    nopd            ;if bank 0 and 1 same not paradise
  481.     bkadr    paradise
  482. ;    mov    cx,64
  483. ;    call    _chkbk
  484. ;    jc    skp3            ;if bank 0 and 64 same only 256k
  485.     mov    [vga512],1
  486. skp3:    jmp    fini
  487.  
  488. nopd:    mov    ax,5f00h        ;Test for Chips & Tech
  489.     xor    bx,bx
  490.     cld
  491.     int    10h
  492.     cmp    al,5fh
  493.     jnz    noct
  494.     bkadr    chipstech
  495.     cmp    bh,1
  496.     jb    skp4
  497.     mov    [vga512],1
  498. skp4:    jmp    fini
  499.  
  500. noct:    mov    ch,0
  501.     mov    dx,3d4h            ;check for Tseng 4000 series
  502.     mov    al,33h
  503.     out    dx,al
  504.     inc    dx
  505.     in    al,dx
  506.     dec    dx
  507.     mov    cl,al
  508.     mov    ax,00a33h
  509.     out    dx,ax
  510.     mov    al,33h
  511.     out    dx,al
  512.     inc    dx
  513.     in    al,dx
  514.     and     al,0fh
  515.     dec    dx
  516.     cmp    al,00ah
  517.     jnz    skp5
  518.     mov    ax,00533h
  519.     out    dx,ax
  520.     mov    al,33h
  521.     out    dx,al
  522.     inc    dx
  523.     in    al,dx
  524.     dec    dx
  525.     and     al,0fh
  526.     cmp    al,005h
  527.     jnz    skp5
  528.     mov    al,33h
  529.     mov    ah,cl
  530.     out    dx,ax
  531.     mov    ch,1
  532.  
  533.     mov    dx,3bfh            ;Enable access to extended registers
  534.     mov    al,3
  535.     out    dx,al
  536.     mov    dl,0d8h
  537.     mov    al,0a0h
  538.     out    dx,al
  539.  
  540. skp5:    mov    dx,3cdh            ;Test for Tseng
  541.     in    al,dx            ;save bank switch register
  542.     mov    cl,al
  543.     mov    al,0aah            ;test register with 0aah
  544.     out    dx,al
  545.     in    al,dx
  546.     cmp    al,0aah
  547.     jnz    nots
  548.     mov    al,055h            ;test register with 055h
  549.     out    dx,al
  550.     in    al,dx
  551.     cmp    al,055h
  552.     jnz    nots
  553.     mov    al,cl
  554.     out    dx,al
  555.     bkadr    tseng
  556.     mov    [vga512],1
  557.  
  558.     cmp    ch,0
  559.     jz    oldts
  560.     bkadr    tseng4
  561. oldts:    jmp    short fini
  562.  
  563. nots:    
  564.         mov     dx,3ceh        ;Test for Above A or B chipsets
  565.         mov     ax,200fh
  566.         out     dx,ax
  567.         inc    dx
  568.     nojmp
  569.         in      al,dx
  570.     cmp    al,21h
  571.     jz    verb
  572.     cmp    al,20h
  573.     jnz    noab
  574.     bkadr    aheada
  575.     mov    [vga512],1
  576.     jmp    short fini
  577.  
  578. verb:    bkadr    aheadb
  579.     mov    [vga512],1
  580.     jmp    short fini
  581.  
  582. noab:    mov    dx,3deh
  583.     in    al,dx
  584.     and    al,11100000b
  585.     cmp    al,01100000b
  586.     jnz    nooak
  587.     bkadr    oaktech
  588.     mov    al,0dh
  589.     out    dx,al
  590.     inc    dx
  591.     nojmp
  592.     in    al,dx
  593.     test    al,80h
  594.     jz    no4ram
  595.     mov    [vga512],1
  596. no4ram:    jmp    short fini
  597.     
  598. nooak:    mov    si,0
  599.  
  600. fini:    mov    ax,si
  601.     mov    [retval],ax
  602.     ret
  603. whichvga endp
  604.  
  605.  
  606. _cirrus    proc    near
  607.     mov    dx,3d4h        ; assume 3dx addressing
  608.     mov    al,0ch        ; screen a start address hi
  609.     out    dx,al        ; select index
  610.     inc    dx        ; point to data
  611.     mov    ah,al        ; save index in ah
  612.     in    al,dx        ; get screen a start address hi
  613.     xchg    ah,al        ; swap index and data
  614.     push    ax        ; save old value
  615.     push    dx        ; save crtc address
  616.     xor    al,al        ; clear crc
  617.     out    dx,al        ; and out to the crtc
  618.  
  619.     mov    al,1fh        ; Eagle ID register
  620.     dec    dx        ; back to index
  621.     out    dx,al        ; select index
  622.     inc    dx        ; point to data
  623.     in    al,dx        ; read the id register
  624.     mov    bh,al        ; and save it in bh
  625.  
  626.     mov    cl,4        ; nibble swap rotate count
  627.     mov    dx,3c4h        ; sequencer/extensions
  628.     mov    bl,6        ; extensions enable register
  629.  
  630.     ror    bh,cl        ; compute extensions disable value
  631.     mov    ax,bx        ; extensions disable
  632.     out    dx,ax        ; disable extensions
  633.     inc    dx        ; point to data
  634.     in    al,dx        ; read enable flag
  635.     or    al,al        ; disabled ?
  636.     jnz    exit        ; nope, not an cirrus
  637.  
  638.     ror    bh,cl        ; compute extensions enable value
  639.     dec    dx        ; point to index
  640.     mov    ax,bx        ; extensions enable
  641.     out    dx,ax        ; enable extensions
  642.     inc    dx        ; point to data
  643.     in    al,dx        ; read enable flag
  644.     cmp    al,1        ; enabled ?
  645.     jne    exit        ; nope, not an cirrus
  646.     mov    [cirrus],1
  647.     mov    [bankadr],offset _nobank
  648. if @Codesize
  649.     mov    [bankseg],seg _nobank
  650. endif
  651. exit:    pop    dx        ; restore crtc address
  652.     dec    dx        ; point to index
  653.     pop    ax        ; recover crc index and data
  654.     out    dx,ax        ; restore crc value
  655.     ret
  656. _cirrus    endp
  657.  
  658. _chkbk    proc    near        ;paradise bank switch check
  659.     mov    di,0b800h
  660.     mov    es,di
  661.     xor    di,di
  662.     mov    bx,1234h
  663.     call    _gochk
  664.     jnz    badchk
  665.     mov    bx,4321h
  666.     call    _gochk
  667.     jnz    badchk
  668.     clc
  669.     ret
  670. badchk:    stc
  671.     ret
  672. _chkbk    endp
  673.  
  674. _gochk    proc    near
  675.     push    si
  676.     mov    si,bx
  677.  
  678.     mov    al,cl
  679.     call    dx
  680.     xchg    bl,es:[di]
  681.     mov    al,ch
  682.     call    dx
  683.     xchg    bh,es:[di]
  684.  
  685.     xchg    si,bx
  686.  
  687.     mov    al,cl
  688.     call    dx
  689.     xor    bl,es:[di]
  690.     mov    al,ch
  691.     call    dx
  692.     xor    bh,es:[di]
  693.  
  694.     xchg    si,bx
  695.  
  696.     mov    al,ch
  697.     call    dx
  698.     mov    es:[di],bh
  699.     mov    al,cl
  700.     call    dx
  701.     mov    es:[di],bl
  702.  
  703.     mov    al,0
  704.     call    dx
  705.     or    si,si
  706.     pop    si
  707.     ret
  708. _gochk    endp
  709.  
  710.  
  711. _pdrsub    proc    near        ;Paradise
  712.     push    dx
  713.     mov    ah,al
  714.     mov    dx,3ceh
  715.     mov    al,9
  716.     out    dx,ax
  717.     pop    dx
  718.     ret
  719. _pdrsub    endp
  720.  
  721.     end
  722.  
  723.