home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / sndbords / proaudio / pas_sdk1 / pas-sdk1.arj / PAS / SUBS / FM / 3812A.ASM next >
Assembly Source File  |  1992-09-24  |  11KB  |  524 lines

  1. ;$Author:   DCODY  $
  2. ;$Date:   24 Sep 1992 08:51:56  $
  3. ;$Header:   X:/sccs/fm/3812a.asv   1.4   24 Sep 1992 08:51:56   DCODY  $
  4. ;$Log:   X:/sccs/fm/3812a.asv  $
  5. ;  
  6. ;     Rev 1.4   24 Sep 1992 08:51:56   DCODY
  7. ;  changed MVGetHardware to mvGetHardware
  8. ;  
  9. ;     Rev 1.3   20 Jul 1992 11:40:56   DCODY
  10. ;  call to mvGetHWVersion requests active I/O detection.
  11. ;  
  12. ;     Rev 1.2   17 Jul 1992 13:55:46   DCODY
  13. ;  base I/O address can now move...
  14. ;  
  15. ;     Rev 1.1   27 Jun 1992 14:47:08   DCODY
  16. ;  fixed FMsplit for the opl3, and outdual3812 now programs one
  17. ;  side of the OPL3 at a time.
  18. ;  
  19. ;     Rev 1.0   26 Jun 1992 14:21:58   BCRANE
  20. ;  Initial revision.
  21. ;  
  22. ;     Rev 1.3   26 Jun 1992 14:12:08   DCODY
  23. ;  added the parameter to the gethwversion call.
  24. ;  
  25. ;     Rev 1.2   25 Jun 1992 21:11:10   DCODY
  26. ;  finished the init routine. Made timing loops variable based
  27. ;  upon the installed FM chip.
  28. ;  
  29. ;     Rev 1.1   23 Jun 1992 16:32:30   DCODY
  30. ;  PAS2 update
  31. ;  
  32. ;     Rev 1.0   15 Jun 1992 09:39:46   BCRANE
  33. ;  Initial revision.
  34. ;$Logfile:   X:/sccs/fm/3812a.asv  $
  35. ;$Modtimes$
  36. ;$Revision:   1.4  $
  37.  
  38.         Title 3812/OPL3 Access Routines
  39.  
  40. ;   /*\
  41. ;---|*|---===< 3821A.ASM >====----
  42. ;---|*|
  43. ;---|*| This is the output routine to write data to the twin 3821 chips,
  44. ;---|*| or OPL-3 4OP synth chip.
  45. ;---|*|
  46. ;---|*| Media Vision, Inc. Copyright (c) 1991,1992. All Rights Reserved.
  47. ;---|*|
  48. ;   \*/
  49.  
  50.     .xlist
  51.     include model.inc
  52.         include masm.inc
  53.     include state.inc
  54.         include target.inc
  55.     include common.inc
  56.     .list
  57.  
  58.         .data
  59.  
  60.     extrn    _MVHWVersionBits   :word
  61.     extrn    _MVTranslateCode   :word
  62.     extrn    mvhwShadowPointer  :dword
  63.  
  64. indexwrite    dw    05        ; 3812 index write delays
  65. datawrite       dw      35              ; 3812 data write delays
  66. splitmode    db    0        ; 00 = mono, 01 = stereo
  67.  
  68.     .code
  69.  
  70.     externADDR   mvGetHWVersion
  71.     externADDR   MVInitStatePtr
  72.  
  73. ;
  74. ;   /*\
  75. ;---|*|---===< mvFMInitMode (int) >====----
  76. ;---|*|
  77. ;---|*| This routine initializes the Dual 3812/OPL-3 chip
  78. ;---|*|
  79. ;---|*| Entry Conditions:
  80. ;---|*|     wParm1 = 0 to setup for mono, 1 to setup for sterero
  81. ;---|*|
  82. ;---|*| Exit Conditions:
  83. ;---|*|     AX,BX,CX,DX modified
  84. ;---|*|
  85. ;   \*/
  86.     public    mvFMInitMode
  87. mvFMInitMode    proc
  88.     push    bp
  89.     mov    bp,sp
  90. ;
  91. ; validate the hardware if not done already.
  92. ;
  93.     cmp    [_MVHWVersionBits],-1    ; check to see if we know the hardware
  94.     jnz    @F
  95.     mov    ax,USE_ACTIVE_ADDR
  96.     push    ax
  97.     call    mvGetHWVersion        ; get the hardware version
  98.     add    sp,2
  99.         cmp     al,-1                   ; everything here?
  100.     jz    mvmfexit        ; no, exit out now...
  101.     ;
  102.     @@:
  103. ;
  104. ; validate the state table pointer
  105. ;
  106.     cmp    word ptr [mvhwShadowPointer+2],0
  107.     jnz    @F
  108.     call    MVInitStatePtr
  109. ;
  110. ; setup I/O delays based upon the installed FM chip
  111. ;
  112.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  113.     jz    @F               ; which are okay, exit out now...
  114.     mov    [indexwrite],3           ; OPL3 index write delays
  115.     mov    [datawrite], 3           ; OPL3 data    write delays
  116. ;
  117. @@:
  118. ;
  119. ; set the chips in mono mode, then flush them.
  120. ;
  121.     sub    ax,ax            ; set the chip(s) in mono mode
  122.     mov    splitmode,al
  123.     call    FMsplit
  124.  
  125.     mov    dx,LFMADDR        ; flush the left/right side
  126.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  127.     call    flushit
  128. ;
  129. ; now, split the chips into stereo mode if requested to do so
  130. ;
  131.     cmp    wptr wParm1,0        ; all done?
  132.     jz    mvmfexit        ; yes, exit
  133.  
  134.     mov    al,1            ; split it now
  135.         mov     splitmode,al
  136.     call    FMsplit
  137. ;
  138. mvmfexit:
  139.     pop    bp
  140.         ret
  141.  
  142. mvFMInitMode    endp
  143.  
  144. ;
  145. ;   /*\
  146. ;---|*|---===< outdual3812(int,int,int) >====----
  147. ;---|*|
  148. ;---|*| This routine writes index/data to
  149. ;---|*| both chips in an interleaved fashion.
  150. ;---|*|
  151. ;---|*| Entry Conditions:
  152. ;---|*|     wParm1 is the chip index value
  153. ;---|*|     wParm2 is the left    FM chip data
  154. ;---|*|     wParm3 is the right FM chip data
  155. ;---|*|
  156. ;---|*| Exit Conditions:
  157. ;---|*|     AX,DX,CX modified
  158. ;---|*|
  159. ;   \*/
  160.  
  161.     public    outdual3812
  162. outdual3812    proc
  163. ;
  164. ; this is kinda screwy, but if we're in mono mode, don't write to both sides
  165. ;
  166.     cmp    splitmode,0        ; are we doing both?
  167.     jjnz    outleft3812        ; no, just do the left side...
  168. ;
  169. ; frame the stack and continue.
  170. ;
  171.     push    bp
  172.     mov    bp,sp
  173. ;
  174. ; write the index to both chips
  175. ;
  176.         mov     dx,LFMADDR              ; get the left 3812 address
  177.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  178.         mov     al,wParm1               ; get the index value
  179. ;
  180. ; special case the OPL3 since it only really has one index register.
  181. ;
  182.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  183.     jnz    outtoopl3           ; which are okay, exit out now...
  184. ;
  185. ; the dual 3812s can have interleaved I/O to speed up the pace
  186. ;
  187.     out    dx,al            ; output to both chips
  188.     add    dx,2
  189.     out    dx,al
  190. ;
  191. ; wait the proper delays for either FM chip
  192. ;
  193.     mov    cx,[indexwrite]
  194.     ;
  195.     @@:
  196.         in      al,dx
  197.     loop    @B
  198. ;
  199. ; write the data out to the chip now
  200. ;
  201.     dec    dx            ; move back to the left FM data reg
  202.     mov    al,byte ptr wParm2
  203.     mov    ah,byte ptr wParm3
  204.  
  205.     out    dx,al            ; write the data out
  206.     add    dx,2
  207.     xchg    ah,al
  208.     out    dx,al
  209. ;
  210. ; wait the proper delays for either FM chip
  211. ;
  212.     mov    cx,[datawrite]
  213.     ;
  214.     @@:
  215.     in    al,dx
  216.     loop    @B
  217.  
  218.     pop    bp
  219.     ret
  220. ;
  221. outtoopl3:
  222. ;
  223. ; do the left side of the OPL3 first
  224. ;
  225.     ; write the left index
  226.  
  227.         out     dx,al                   ; output to both chips
  228.     mov    cx,[indexwrite]
  229.     ;
  230.     @@:
  231.         in      al,dx
  232.     loop    @B
  233.  
  234.     ; write the left data
  235.  
  236.         inc     dx                      ; move to the left FM data reg
  237.     mov    al,wParm2
  238.     out    dx,al            ; write the data out
  239.     mov    cx,[datawrite]
  240.     ;
  241.     @@:
  242.     in    al,dx
  243.     loop    @B
  244. ;
  245. ; do the right side of the OPL3 next
  246. ;
  247.     ; write the right index
  248.  
  249.     inc    dx
  250.         mov     ax,wParm1               ; get the index value
  251.         out     dx,al                   ; output to both chips
  252.     mov    cx,[indexwrite]
  253.     ;
  254.     @@:
  255.         in      al,dx
  256.     loop    @B
  257.  
  258.     ; write the right data
  259.  
  260.         inc     dx                      ; move to the left FM data reg
  261.     mov    al,wParm3
  262.  
  263.     out    dx,al            ; write the data out
  264.     mov    cx,[datawrite]
  265.     ;
  266.     @@:
  267.     in    al,dx
  268.     loop    @B
  269.  
  270.     pop    bp
  271.     ret
  272.  
  273. outdual3812    endp
  274.  
  275. ;
  276. ;   /*\
  277. ;---|*|---===< outleft3812(int,int) >====----
  278. ;---|*|
  279. ;---|*| This routine writes index/data to the left FM chip.
  280. ;---|*|
  281. ;---|*| Entry Conditions:
  282. ;---|*|     wParm1 is the left FM index
  283. ;---|*|     wParm2 is the left FM chip data
  284. ;---|*|
  285. ;---|*| Exit Conditions:
  286. ;---|*|     AX,DX,CX modified
  287. ;---|*|
  288. ;   \*/
  289.  
  290.     public    outleft3812
  291. outleft3812    proc
  292.     push    bp
  293.     mov    bp,sp
  294. ;
  295. ; write the index to both chips
  296. ;
  297.         mov     dx,LFMADDR              ; get the left 3812 address
  298.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  299. ;
  300. fm_common_output label near
  301. ;
  302. ; output the index to the single chip
  303. ;
  304.         mov     ax,wParm1               ; get the index value
  305.     out    dx,al            ; output to both chips
  306.     mov    cx,[indexwrite]
  307. ;
  308. @@:
  309.         in      al,dx                   ; slow down for the index to settle
  310.     loop    @B
  311.  
  312.     inc    dx            ; move to the data register
  313.  
  314.         mov     ax,wParm2
  315.     out    dx,al            ; write the data out
  316.  
  317.     mov    cx,[datawrite]
  318. ;
  319. @@:
  320.     in    al,dx
  321.     loop    @B
  322.  
  323.     pop    bp
  324.     ret
  325.  
  326. outleft3812    endp
  327.  
  328. ;
  329. ;   /*\
  330. ;---|*|---===< outright3812(int,int) >====----
  331. ;---|*|
  332. ;---|*| This routine writes index/data to the right FM chip.
  333. ;---|*|
  334. ;---|*| Entry Conditions:
  335. ;---|*|     wParm1 is the right FM index
  336. ;---|*|     wParm1 is the right FM chip data
  337. ;---|*|
  338. ;---|*| Exit Conditions:
  339. ;---|*|     AX,DX,CX modified
  340. ;---|*|
  341. ;   \*/
  342.  
  343.     public    outright3812
  344. outright3812    proc
  345.     push    bp
  346.     mov    bp,sp
  347. ;
  348. ; write the index to both chips
  349. ;
  350.     mov    dx,RFMADDR        ; get the right 3812 address
  351.         xor     dx,[_MVTranslateCode]   ; translate to the board address
  352.         jmp     short fm_common_output
  353.  
  354. outright3812    endp
  355.  
  356. ;
  357. ;--------------------------==========================--------------------------
  358. ;--------------------------====< local routines >====--------------------------
  359. ;--------------------------==========================--------------------------
  360. ;
  361.  
  362. ;
  363. ;   /*\
  364. ;---|*|---===< flushit >====----
  365. ;---|*|
  366. ;---|*| Reset both sides of the FM chip(s)
  367. ;---|*|
  368. ;---|*| Entry Conditions:
  369. ;---|*|     none
  370. ;---|*|
  371. ;---|*| Exit Conditions:
  372. ;---|*|     AX,BX,CX,DX modified
  373. ;---|*|
  374. ;   \*/
  375. ;
  376. flushit proc    near
  377.     mov    ax,1        ; reg 1
  378.     call    fmout
  379.  
  380.         inc     ax              ; reg 2
  381.     call    fmout
  382.  
  383.         inc     ax              ; reg 3
  384.     call    fmout
  385.  
  386.         inc     ax              ; reg 4
  387.     call    fmout
  388.  
  389.         mov     al,8            ; reg 8
  390.     call    fmout
  391.  
  392.         mov     al,20h          ; flush all others from reg 20 to reg FF
  393.     mov    cx,0FFh-20h
  394. ;
  395. @@:
  396.     call    fmout
  397.     inc    ax
  398.     loop    @B
  399.  
  400.     ret
  401.  
  402. flushit endp
  403.  
  404. ;
  405. ;   /*\
  406. ;---|*|---===< FMsplit >====----
  407. ;---|*|
  408. ;---|*| Split or combine the FM sides.
  409. ;---|*|
  410. ;---|*| Entry Conditions:
  411. ;---|*|     AL = 1 for stereo, 0 for mono
  412. ;---|*|
  413. ;---|*| Exit Conditions:
  414. ;---|*|     AX,BX,CX,DX modified
  415. ;---|*|
  416. ;   \*/
  417. ;
  418. FMsplit proc    near
  419. ;
  420. ; record either MONO or STEREO in the state table
  421. ;
  422.     push    es
  423.     push    di
  424.     les    di,[mvhwShadowPointer]       ; we have to record in in the state
  425. ;
  426. ; maintain the split state fact in the old split FM bit
  427. ;
  428.     mov    ah,al                 ; save an original copy
  429.     cmp    al,1                 ; set carry if zero
  430.     sbb    al,al                 ; al = FF for mono
  431.     and    al,bMImonofm             ; keep the bit if mono
  432.  
  433.         and     es:[di._audiomixr],NOT bMImonofm ; flush the bit
  434.     or    es:[di._audiomixr],al         ; maybe set it
  435.     mov    al,es:[di._audiomixr]         ; load a copy for old pas
  436.  
  437.     pop    di
  438.     pop    es
  439. ;
  440. ; if OPL3, go do it's split, else just write out the new mixer setting
  441. ;
  442.         test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  443.     jnz    splitopl3           ; which are okay, exit out now...
  444.  
  445.     mov    dx,AUDIOMIXR           ; get the mixer address
  446.     xor    dx,[_MVTranslateCode]       ; translate to the board address
  447.     out    dx,al               ; send the bits out to the h/w
  448.  
  449.         ret
  450. ;
  451. splitopl3:
  452.     mov    al,5               ; send it to the right FM reg 5
  453.     mov    dx,RFMADDR
  454.         xor     dx,[_MVTranslateCode]      ; translate to the board address
  455.     out    dx,al               ; send the index
  456.  
  457.         mov     cx,[indexwrite]
  458.     ;
  459.     @@:
  460.     in    al,dx               ; wait the prescribed period
  461.     loop    @B
  462.  
  463.     inc    dx
  464.         mov     al,ah
  465.     out    dx,al               ; send the data byte
  466.  
  467.         mov     cx,[datawrite]
  468.     ;
  469.     @@:
  470.     in    al,dx               ; wait the prescribed period
  471.     loop    @B
  472.  
  473.         ret
  474.  
  475. FMsplit endp
  476.  
  477. ;
  478. ;   /*\
  479. ;---|*|---===< fmout >====----
  480. ;---|*|
  481. ;---|*| write to one of the chips.
  482. ;---|*|
  483. ;---|*| Entry Conditions:
  484. ;---|*|     DX holds the base address (left side or right side)
  485. ;---|*|     AL holds the index register value
  486. ;---|*|     AH holds the data  register value
  487. ;---|*|
  488. ;---|*| Exit Conditions:
  489. ;---|*|     no registers modified
  490. ;---|*|
  491. ;   \*/
  492. ;
  493. fmout   proc    near
  494.     push    ax
  495.     push    cx
  496.  
  497.     out    dx,al
  498.     mov    cx,[indexwrite]
  499. ;
  500. @@:
  501.     in    al,dx
  502.     loop    @B
  503.  
  504.     xchg    ah,al
  505.     inc    dx
  506.     out    dx,al
  507.  
  508.         mov     cx,[datawrite]
  509. ;
  510. @@:
  511.     in    al,dx
  512.     loop    @B
  513.  
  514.     dec    dx
  515.  
  516.     pop    cx
  517.     pop    ax
  518.     ret
  519.  
  520. fmout    endp
  521.  
  522.         end
  523.  
  524.