home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / miditool / sda_ur22 / sda_usr2.asm < prev    next >
Encoding:
Assembly Source File  |  1988-04-21  |  7.2 KB  |  391 lines

  1. page
  2. title    SDA_USR2  -  Stand-alone routines for the SDA Midicard.
  3.  
  4. code    segment public 'code'
  5.     assume cs:code,ds:code
  6.  
  7.  
  8. ; Revisions:
  9. ;
  10. ;    01-8-88        Added dummy 'mov ax,0' instructions in _U_LOC_MC
  11. ;            to provide settle time when running in 10mh AT's
  12. ;    04-19-88    Added addr. 320 (MPU mode) support.
  13.  
  14.  
  15. ;******************************************************************
  16. ;*
  17. ;* See companion file 'SDA_USER.DOC' for more information on 
  18. ;* these subroutines.
  19. ;*
  20. ;******************************************************************
  21.  
  22.  
  23. ;******************************************************************
  24. ;*
  25. ;* This software is intended to provide access to a Downloaded
  26. ;* Systems Design Midicard such that it may be used in UART mode.
  27. ;* In this mode the interface (Midicard) will send all data
  28. ;* received from Midi IN to the host PC, and will send all data
  29. ;* from the host out MIdi OUT.  There is no direct flow of data
  30. ;* from Midi IN to Midi OUT (Midi THRU) in the Midicard in UART mode.
  31. ;* THRU capabilities must be handled by the host in this mode.
  32. ;*
  33. ;* These routines are NOT designed to be memory resident with a
  34. ;* running Promidi system.  Routines that provide services for
  35. ;* memory co-resident software (TSR) are provided as public 
  36. ;* domain 8086 assembly source in "SDA_USER.ASM".
  37. ;*
  38. ;* The following requirments must be satisfied before data may be
  39. ;* sent and received from a Midicard:
  40. ;* 
  41. ;*    1. The Midicard must be downloaded.
  42. ;*
  43. ;*    The loader program is MLOAD.EXE and the Midicard's software
  44. ;*    is in file Z8.HEX.  Both of these programs are supplied with
  45. ;*    with every Promidi system.  Before Promidi can run, the
  46. ;*    command line "MLOAD Z8" is executed (from BATCH file SDA.BAT).
  47. ;*    Once the Midicard's program has been downloaded, it is intact
  48. ;*    until the PC is powered down.  The same "MLOAD Z8" may be used
  49. ;*    in any batch file to download the Midicard.
  50. ;*
  51. ;*
  52. ;*    2. The Midicard must be located and initialized.
  53. ;*
  54. ;*    There is a file called SDA.CFG that is in the same directory
  55. ;*    as MLOAD.EXE and Z8.HEX.  This file contains (along with other data)
  56. ;*    the switch settings set by the user at instalation time that
  57. ;*    position the card in the PC's I/O space and assign it one of
  58. ;*    four interrupt addresses.
  59. ;*
  60. ;*    The provided routine "_U_LOC_MC" is used to locate the Midicard.
  61. ;*
  62. ;*
  63. ;* After these requirments have been satisfied, the I/O routines 
  64. ;* may be called.
  65. ;*
  66. ;* Before terminating, the software should ALWAYS call _U_EXIT which
  67. ;* will reset (deactivate) the Midicard. 
  68. ;*
  69. ;******************************************************************
  70.  
  71.  
  72. ;*************************************************************************
  73. ;*
  74. ;* The source file 'SDA_USR2.ASM' is provided free of charge by Systems 
  75. ;* Design Associates, Inc.  SDA does not in any way warranty this software 
  76. ;* nor is it liable for any damages resulting from its use.
  77. ;*
  78. ;*************************************************************************
  79.  
  80.  
  81.  
  82. ; MIDICARD 8255 REG. DEFINITION
  83. ; MUST CORRESPOND TO SW. 1-4 ON MIDICARD
  84.  
  85. PTA    DW    ?
  86. PTB    DW    ?
  87. PTC    DW    ?
  88. PTCNTL    DW    ?
  89.  
  90.  
  91.  
  92. ; MIDICARD INTERRUPT INFO. 
  93. ; MUST CORRESPOND TO SW 5-8 ON MIDICARD
  94.  
  95. MI_LOC    DW    ?
  96. MI_BIT    DB    ?
  97.  
  98. FILEBUF    DB    ?,?
  99. FILESTR    DB    'SDA.CFG'
  100.     DB    0
  101.  
  102.  
  103.  
  104.  
  105. PUBLIC    _U_LOC_MC,_U_SNDB,_U_RCVB,_U_EXIT,_U_TRCV
  106. page
  107.  
  108.  
  109.  
  110. ; _U_LOC_MC
  111. ;
  112. ;      THIS ROUTINE MUST BE CALLED SUCCESSFULLY (RET = 1)
  113. ;      IN ORDER TO USE "_U_SNDB" and "_U_RCVB".
  114. ;
  115. ; If the file SDA.CFG is found in the current directory,
  116. ;  this routine fills the port and interrupt location data used
  117. ;  by the I/O routines.
  118. ;
  119. ;    Returns:    ax = 0        Error.
  120. ;            ax = 1        Completed.
  121. ;
  122. ;    Regs altered - ax,bx,cx,dx
  123.  
  124. _U_LOC_MC proc far
  125.     push    si
  126.     mov    dx,offset FILESTR    ; Open SDA.CFG for reading.
  127.     mov    ax,3D00H
  128.     int    21H
  129.     jnc    ULOC1
  130.     xor    ax,ax            ; Error
  131.     jmp    ULOCRET    
  132. ULOC1:
  133.     mov    si,ax            ; Save file handle in SI
  134.     mov    bx,ax            ; Read first two bytes in SDA.CFG
  135.     mov    cx,2
  136.     mov    dx,offset FILEBUF
  137.     mov    ax,3F00H
  138.     int    21H
  139.     jnc    ULOC2
  140.     xor    ax,ax            ; Error
  141.     jmp    ULOCRET    
  142. ULOC2:
  143.     mov    bx,si            ; Close the file
  144.     mov    ax,3E00H    
  145.     int    21H
  146.  
  147.     mov    si,offset FILEBUF
  148.     mov    al,[si]            ; Get 1st byte 
  149.  
  150.     mov    bx,300H
  151.     dec    al
  152.     jz    ULOC3
  153.  
  154.     mov    bx,280H
  155.     dec    al
  156.     jz    ULOC3
  157.  
  158.     mov    bx,240H
  159.     dec    al
  160.     jz    ULOC3
  161.  
  162.     mov    bx,220H
  163.     dec    al
  164.     jz    ULOC3
  165.  
  166.     mov    bx,320H            ; MPU mode
  167.     dec    al
  168.     jz    ULOC3
  169.  
  170.     xor    ax,ax            ; Error
  171.     jmp    ULOCRET    
  172. ULOC3:    
  173.     mov    PTA,bx            ; Set up port addresses
  174.     inc    bx
  175.     mov    PTB,bx
  176.     inc    bx
  177.     mov    PTC,bx
  178.     inc    bx
  179.     mov    PTCNTL,bx
  180.  
  181.     inc    si
  182.     mov    al,[si]            ; Get 2nd byte
  183.     sub    al,4
  184.  
  185.     mov    MI_LOC,(8 + 2) * 4    ; Set up interrupt address
  186.     mov    MI_BIT,04H
  187.     dec    al
  188.     jz    ULOC4
  189.  
  190.     mov    MI_LOC,(8 + 7) * 4
  191.     mov    MI_BIT,80H
  192.     dec    al
  193.     jz    ULOC4
  194.  
  195.     mov    MI_LOC,(8 + 5) * 4
  196.     mov    MI_BIT,20H
  197.     dec    al
  198.     jz    ULOC4
  199.  
  200.     mov    MI_LOC,(8 + 4) * 4
  201.     mov    MI_BIT,10H
  202.     dec    al
  203.     jz    ULOC4
  204.     xor    ax,ax            ; Error
  205.     jmp    ULOCRET    
  206. ULOC4:    
  207.     pushf
  208.     cli
  209.     mov    dx,PTC
  210.     mov    al,1            ; Midicard mode
  211.     mov    ah,0            ; wait
  212.     mov    ah,0
  213.     out    dx,al
  214.  
  215.     mov    al,0C1H
  216.     mov    ah,0            ; wait
  217.     mov    ah,0
  218.     out    dx,al
  219.  
  220.     mov    dx,PTCNTL
  221.     mov    al,0C2H
  222.     mov    ah,0            ; wait
  223.     mov    ah,0
  224.     out    dx,al
  225.  
  226.     mov    al,0FH
  227.     mov    ah,0            ; wait
  228.     mov    ah,0
  229.     out    dx,al
  230.  
  231.     mov    al,9
  232.     mov    ah,0            ; wait
  233.     mov    ah,0
  234.     out    dx,al
  235.     mov    ax,1
  236.     popf
  237.     xor    ax,ax
  238. ULOC6:
  239.     dec    ax
  240.     jnz    ULOC6
  241. ULOC5:
  242.     mov    dx,PTC
  243.     in    al,dx
  244.     test    al,80H
  245.     jz    ULOC5
  246.  
  247.     mov    dx,PTCNTL
  248.     mov    al,5
  249.     out    dx,al
  250.  
  251.     mov    dx,PTA
  252.     mov    al,35
  253.     out    dx,al
  254. ULOCRET:
  255.     pop    si
  256.     ret
  257. _U_LOC_MC endp
  258. page
  259.  
  260.  
  261.  
  262.  
  263. ; _U_RCVB  -  If a byte is present, receive a byte from the Midicard
  264. ;
  265. ;  c  call    c = u_rcvb();
  266. ;
  267. ;  asm  call    call    _u_rcvb    ; Byte or ret. code in ax.  
  268. ;    (far)
  269. ;
  270. ;    RETURNS:    byte
  271. ;            100H        No input received
  272. ;
  273. ;    Regs Altered: ax,dx
  274.  
  275. _U_RCVB    proc    far
  276.     mov    dx,PTC
  277.     in    al,dx
  278.     test    al,20H            ; Look for input
  279.     jnz    IBFULL
  280.     mov    ax,100H            ; None
  281.     jmp    URCRET
  282. IBFULL:
  283.     mov    dx,PTA            ; Get byte
  284.     in    al,dx
  285.     xor    ah,ah
  286. URCRET:
  287.     ret
  288. _U_RCVB    endp
  289. page
  290.  
  291.  
  292.  
  293.  
  294. ; _U_TRCV  -  Test if a byte is present from the Midicard
  295. ;
  296. ;  c  call    rc = u_trcv();
  297. ;
  298. ;  asm  call    call    _u_trcv  ; Ret. code in ax.  
  299. ;    (far)
  300. ;
  301. ;    RETURNS:    0        No input.
  302. ;            1        Input present.
  303. ;
  304. ;    Regs Altered: ax,dx
  305.  
  306. _U_TRCV    proc    far
  307.     mov    dx,PTC
  308.     in    al,dx
  309.     test    al,20H            ; Look for input
  310.     jnz    UTR1
  311.     xor    ax,ax
  312.     jmp    UTRRET
  313. UTR1:
  314.     mov    ax,1
  315. UTRRET:
  316.     ret
  317. _U_TRCV    endp
  318. page
  319.  
  320.  
  321.  
  322.  
  323.  
  324. ; _U_SNDB  -  Send a byte to the Midicard.
  325. ;
  326. ;  c call    u_sndb(c);
  327. ;
  328. ;  asm call    push    ax        ; Push byte on stack
  329. ;   (far)    call    _u_sndb
  330. ;        add    sp,2
  331. ;
  332. ;
  333. ;    Regs Altered: ax,cx,dx
  334.  
  335. _U_SNDB    proc    far
  336.     push    bp
  337.     mov    bp,sp
  338.     mov    cx,[bp+6]        ; Get parameter.
  339. USND1:
  340.     mov    dx,PTC
  341.     in    al,dx
  342.     test    al,80H            ; Output buffer empty ?
  343.     jz    USND1            ; No - keep trying.
  344.  
  345.     mov    dx,PTB
  346.     in    al,dx
  347.     test    al,40H            ; Can we send Midi data ?
  348.     jnz    USND1            ; No - keep trying.
  349.  
  350.     mov    dx,PTCNTL        ; Say its Midi data
  351.     mov    al,4            ;   (not a command)
  352.     out    dx,al
  353.  
  354.     mov    dx,PTA            ; Send byte.
  355.     mov    al,cl
  356.     out    dx,al
  357.  
  358.     pop    bp
  359.     ret
  360. _U_SNDB    endp
  361. page
  362.  
  363.  
  364.  
  365.  
  366.  
  367. ; _U_EXIT  -  Reset th Midicard before terminating program.
  368. ;
  369. ;  c call    u_exit();
  370. ;
  371. ;  asm call    call    _u_exit
  372. ;   (far)
  373. ;
  374. ;
  375. ;    Regs Altered: ax,cx,dx
  376.  
  377. _U_EXIT    proc    far
  378.     pushf
  379.     cli
  380.     mov    dx,PTC
  381.     mov    al,1        ; Midicard mode
  382.     out    dx,al
  383.     popf
  384.     ret
  385. _U_EXIT    endp
  386.  
  387.  
  388.     code    ends
  389.  
  390.     END
  391.