home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / pas_sdk1 / pas / subs / misc / mvout.asm < prev    next >
Encoding:
Assembly Source File  |  1992-09-24  |  9.4 KB  |  299 lines

  1.  
  2.         page    64,131
  3.     Title    MVOUT  --  Pro Audio Spectrum direct I/O
  4.  
  5. ;   /*\
  6. ;---|*|-------------------------====< MVOUT >====-------------------------
  7. ;---|*|
  8. ;---|*|  This module contains some code for supporting direct I/O to the PAS
  9. ;---|*|  where the hardware is write only. All calls reference the state
  10. ;---|*|  table to guarrantee proper I/O values.
  11. ;---|*|
  12. ;---|*|  Media Vision, Inc. Copyright (c) 1991,1992. All Rights Reserved.
  13. ;---|*|
  14. ;   \*/
  15.  
  16.  
  17.     .xlist
  18.     include model.inc
  19.         include masm.inc
  20.     include state.inc
  21.     include common.inc
  22.     .list
  23.  
  24.     .data
  25. ;
  26. ; The following label allows us to calculate an offset for the tables of
  27. ; addresses
  28. ;
  29. FirstDataByte   label   byte            ; !!!!!! must be the 1st entry in
  30. ;                    ; the data segmment!!!
  31. ;
  32. ; our first pass flag - set to -1 for first entry, will be zeroed out
  33. ;
  34. invmso_first    db    -1        ; -1 for first pass, to be zeroed out
  35.  
  36. ;
  37. ; Hardware Shadowing Table of Registers
  38. ;
  39.         public  shadowregtable
  40. shadowregtable    label    word
  41.     dw    SYSSPKRTMR        ; 00042h ; System Speaker Timer Address
  42.     dw    SYSTMRCTLR        ; 00043h ; System Timer Control Register
  43.     dw    SYSSPKRREG        ; 00061h ; System Speaker Register
  44.     dw    JOYSTICK        ; 00201h ; Joystick Register
  45.     dw    LFMADDR         ; 00388h ; Left  FM Synthesizer Address Register
  46.     dw    LFMDATA         ; 00389h ; Left  FM Synthesizer Data Register
  47.     dw    RFMADDR         ; 0038Ah ; Right FM Synthesizer Address Register
  48.     dw    RFMDATA         ; 0038Bh ; Right FM Synthesizer Data Register
  49.     dw    DFMADDR     ;AUXADDR; 00788h ; Dual  FM Synthesizer Address Register
  50.     dw    DFMDATA     ;AUXDATA; 00789h ; Dual  FM Synthesizer Data Register
  51.         dw      0                       ; 0078Ah ; reserved for future use
  52.     dw    0            ; 0078Bh ; reserved for future use
  53.         dw      AUDIOMIXR               ; 00B88h ; Audio Mixer Control Register
  54.     dw    INTRCTLRST        ; 00B89h ; Interrupt Status Register
  55.     dw    AUDIOFILT        ; 00B8Ah ; Audio Filter Control Register
  56.     dw    INTRCTLR        ; 00B8Bh ; Interrupt Control Register
  57.     dw    PCMDATA         ; 00F88h ; PCM data I/O register
  58.     dw    0            ; 00F89h ; reserved for future use
  59.     dw    CROSSCHANNEL        ; 00F8Ah ; Cross Channel
  60.     dw    0            ; 00F8Bh ; reserved for future use
  61.         dw      SAMPLERATE              ; 01388h ; Sample Rate Timer Register
  62.     dw    SAMPLECNT        ; 01389h ; Sample Count Register
  63.     dw    SPKRTMR         ; 0138Ah ; Local Speaker Timer Address
  64.     dw    TMRCTLR         ; 0138Bh ; Local Timer Control Register
  65.     dw    MDIRQVECT        ; 01788H ; MIDI IRQ Vector Register
  66.     dw    MDSYSCTLR        ; 01789H ; MIDI System Control Register
  67.     dw    MDSYSSTAT        ; 0178AH ; MIDI IRQ Status Register
  68.     dw    MDIRQCLR        ; 0178BH ; MIDI IRQ Clear Register
  69.     dw    MDGROUP4        ; 01B88H ; MIDI Group #4 Register
  70.     dw    MDGROUP5        ; 01B89H ; MIDI Group #5 Register
  71.     dw    MDGROUP6        ; 01B8AH ; MIDI Group #6 Register
  72.     dw    MDGROUP7        ; 01B8BH ; MIDI Group #7 Register
  73.  
  74. SHADOWTABLELEN  equ     28              ; 28 entries in the shadow data table
  75.  
  76. ;
  77. ; Storage Locations for the data
  78. ;
  79.     public    shadowdatatable
  80. shadowdatatable label    word
  81.     dw    offset _sysspkrtmr    ; 00042h ; System Speaker Timer Address
  82.     dw    offset _systmrctlr    ; 00043h ; System Timer Control Register
  83.     dw    offset _sysspkrreg    ; 00061h ; System Speaker Register
  84.     dw    offset _joystick    ; 00201h ; Joystick Register
  85.     dw    offset _lfmaddr     ; 00388h ; Left  FM Synthesizer Address Register
  86.     dw    offset _lfmdata     ; 00389h ; Left  FM Synthesizer Data Register
  87.     dw    offset _rfmaddr     ; 0038Ah ; Right FM Synthesizer Address Register
  88.     dw    offset _rfmdata     ; 0038Bh ; Right FM Synthesizer Data Register
  89.     dw    offset _dfmaddr     ; 00788h ; Dual  FM Synthesizer Address Register
  90.     dw    offset _dfmdata     ; 00789h ; Dual  FM Synthesizer Data Register
  91.     dw    0            ; 0078Ah ; reserved for future use
  92.     dw    0            ; 0078Bh ; reserved for future use
  93.         dw      offset _audiomixr       ; 00B88h ; Audio Mixer Control Register
  94.     dw    offset _intrctlrst    ; 00B89h ; Interrupt Status Register
  95.     dw    offset _audiofilt    ; 00B8Ah ; Audio Filter Control Register
  96.     dw    offset _intrctlr    ; 00B8Bh ; Interrupt Control Register
  97.     dw    offset _pcmdata     ; 00F88h ; PCM data I/O register
  98.         dw      0                       ; 00F89h ; reserved for future use
  99.         dw      offset _crosschannel    ; 00F8Ah ; Cross Channel
  100.     dw    0            ; 00F8Bh ; reserved for future use
  101.         dw      offset _samplerate      ; 01388h ; Sample Rate Timer Register
  102.     dw    offset _samplecnt    ; 01389h ; Sample Count Register
  103.     dw    offset _spkrtmr     ; 0138Ah ; Local Speaker Timer Address
  104.     dw    offset _tmrctlr     ; 0138Bh ; Local Timer Control Register
  105.     dw    offset _mdirqvect    ; 01788H ; MIDI IRQ Vector Register
  106.     dw    offset _mdsysctlr    ; 01789H ; MIDI System Control Register
  107.     dw    offset _mdsysstat    ; 0178AH ; MIDI IRQ Status Register
  108.     dw    offset _mdirqclr    ; 0178BH ; MIDI IRQ Clear Register
  109.     dw    offset _mdgroup1    ; 01B88H ; MIDI Group #4 Register
  110.     dw    offset _mdgroup2    ; 01B89H ; MIDI Group #5 Register
  111.     dw    offset _mdgroup3    ; 01B8AH ; MIDI Group #6 Register
  112.     dw    offset _mdgroup4    ; 01B8BH ; MIDI Group #7 Register
  113.  
  114.     extrn    mvhwShadowPointer    :dword
  115.     extrn    _MVTranslateCode    :word     ; hardware I/O offset
  116.     extrn    _MVHWVersionBits    :word     ; hardware bits
  117.  
  118. ;
  119. ;---------------------------========================---------------------------
  120. ;---------------------------====< CODE SECTION >====---------------------------
  121. ;---------------------------========================---------------------------
  122. ;
  123.     .code
  124.  
  125.     externADDR MVInitStatePtr    ; state table pointer stuff
  126.     externADDR mvGetHWVersion    ; find the board address...
  127.  
  128. ;
  129. ;   /*\
  130. ;---|*|
  131. ;---|*|---------------====< Prototypes >====---------------
  132. ;---|*|
  133. ;---|*| void MVOut( int, int, int )
  134. ;---|*|
  135. ;---|*| Output a masked byte directly to the hardware, and return the new value
  136. ;---|*|
  137. ;---|*| Entry Conditions:
  138. ;---|*|     wParm1 is the port address
  139. ;---|*|     wParm2 is the and mask of bits to be written
  140. ;---|*|     wParm3 is the xor data to be written
  141. ;---|*|
  142. ;---|*| Exit Conditions:
  143. ;---|*|     if wParm2 = 0,  al = read from hardware, ah = shadowed data
  144. ;---|*|     if wParm2 = !0, value is written to the hardware & shadow table
  145. ;   \*/
  146. ;
  147.     public    MVOut
  148. MVOut   PROC
  149.     push    bp
  150.     mov    bp,sp
  151. ;
  152. ; this code can only be processed once per loading
  153. ;
  154.     cmp    [invmso_first],-1    ; have we been here?
  155.     jnz    @F            ; yes, don't do this again
  156.     mov    [invmso_first],0    ; no, so pass by just once
  157.     call    __initmvout
  158.     call    MVInitStatePtr        ; initialize the state table
  159.     @@:
  160. ;
  161. ; perform the read from the state table, or write to the hardware
  162. ;
  163.         push    es
  164.  
  165.     mov    dx,wParm1        ; port address
  166.  
  167.     call    _getregisterptr     ; get the shadow hardware register ptr
  168.         jc      mvout_exit              ; IO address not found
  169.  
  170.     mov    cx,wParm2        ; mask
  171.         mov     ax,wParm3               ; data
  172.  
  173.     jcxz    mvout_read        ; read request, just return the data
  174.  
  175.     and    al,cl            ; merge new and old bits
  176.     not    cl            ; get the other bits
  177.     and    cl,es:[bx]        ; from the shadow state
  178.     or    al,cl            ; and merge them in
  179.     xor    dx,[_MVTranslateCode]    ; xlate the board address
  180.     out    dx,al            ; output to the hardware
  181.     mov    es:[bx],al        ; save the new state
  182. ;
  183. mvout_exit:
  184.     pop    es
  185.     pop    bp
  186.     ret
  187. ;
  188. mvout_read:
  189.     mov    al,es:[bx]        ; gets the value from the state table
  190.     jmp    short mvout_exit
  191.  
  192. MVOut    endp
  193.  
  194. ;
  195. ;   /*\
  196. ;---|*|---------------====< __initmvout() >====---------------
  197. ;---|*|
  198. ;---|*| Initializes this body of code. It will try to find the int 2F DOS
  199. ;---|*| interface to the MVPROAS device. Once found, the new state table
  200. ;---|*| pointer will be loaded.
  201. ;---|*|
  202. ;---|*| Entry Conditions:
  203. ;---|*|     None
  204. ;---|*|
  205. ;---|*| Exit Conditions:
  206. ;---|*|     DX:AX point to the state table
  207. ;   \*/
  208.  
  209. __initmvout    proc    near
  210.     push    es
  211.     push    di
  212.     mov    ax,ds
  213.     mov    es,ax
  214. ;
  215. ; adjust the shadow data table offsets to the correct linked offset
  216. ;
  217.     mov    cx,SHADOWTABLELEN    ; table length...
  218.         lea     bx,FirstDataByte        ; the compiled offsets must be adjusted
  219.     lea    di,shadowdatatable    ; DI points to the table
  220.     ;
  221.     @@:
  222.     add    es:[di],bx        ; move the offsets in the table
  223.     inc    di
  224.         inc     di
  225.     loop    @B
  226.  
  227.     cmp    [_MVHWVersionBits],-1    ; already found?
  228.     jnz    inmv_done        ; yes, continue on..
  229.  
  230.     mov    ax,USE_ACTIVE_ADDR    ; defaults to the original address
  231.     push    ax
  232.     call    mvGetHWVersion        ; find the board address...
  233.     add    sp,2
  234. ;
  235. inmv_done:
  236.         pop     di
  237.     pop    es
  238.     ret
  239.  
  240. __initmvout    endp
  241.  
  242. ;
  243. ;---------------------====< _getregisterptr >====---------------
  244. ;
  245. ; Get a pointer to the state table
  246. ;
  247. ; Entry Conditions:
  248. ;     DX holds the port address
  249. ;
  250. ; Exit Conditions:
  251. ;     ES:BX holds the pointer, no other registers modified
  252. ;
  253. _getregisterptr proc    near
  254.     push    di            ; no toucha dees...
  255.     push    cx
  256.  
  257.     mov    cx,ds
  258.     mov    es,cx
  259.     lea    di,shadowregtable    ; look in the register table
  260.     mov    cx,SHADOWTABLELEN
  261.  
  262.     xchg    ax,dx            ; ax holds the port address
  263.     cld
  264.     repne    scasw
  265.     xchg    ax,dx            ; restore 'em...
  266.  
  267.     stc                ; just in case we bomb out
  268.         jne     @F                      ; no match, bomb out...
  269.  
  270. if MODELSIZE eq 0
  271.     assume    es:@code        ; tiny (.com) model is same as code
  272. else
  273.     assume    es:@data        ; all other has a data segment
  274. endif
  275.  
  276.         sub     di,offset shadowregtable+2 ; create an offset into the table
  277.     mov    bx,es:[shadowdatatable+di] ; bx = the offset from the 1st ptr
  278.     mov    di,es:[shadowdatatable+0]  ; grab the first ptr
  279.     sub    bx,di               ; bx holds a zero based offset
  280.     les    di,mvhwShadowPointer       ; get the true state table pointer
  281.     add    bx,di               ; bx now points into the true table
  282.         assume  es:nothing
  283.  
  284.     clc                ; was found, indicate so...
  285. ;
  286. @@:
  287.     pop    cx
  288.     pop    di
  289.         ret
  290.  
  291. _getregisterptr endp
  292.  
  293. ;   /*\
  294. ;---|*| end of MVOut
  295. ;   \*/
  296.  
  297.         end
  298.  
  299.