home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mt32ds10.zip / MT32DISP.BAS next >
BASIC Source File  |  1992-11-16  |  9KB  |  178 lines

  1. '╔══════════════════════════════════════════════════════════════════════════════╗
  2. '║   PROGRAM: MT32DISP.EXE Version 1.00                           LENGTH: 132   ║
  3. '║                                                                              ║
  4. '║      This program sends MIDI exclusive message data to the Roland MPU-401.   ║
  5. '║   The exclusive message contains information specific for the Roland MT-32.  ║
  6. '║   The message is Data Set (DT1, 12h) that passes the user's text to the      ║
  7. '║   MT-32 display's address area.  The format for the exclusive message is:    ║
  8. '║                                                                              ║
  9. '║   Exclusive  Manufacturer's  Device  Model  Command   Data ..........  EOX   ║
  10. '║    Status        ID            ID     ID      ID                             ║
  11. '║     F0h          41h           10h    16h     12h     20h 00h 00h ...  F7h   ║
  12. '║                (Roland)       (#17) (MT-32)  (DT1)    (LCD address)          ║
  13. '║                                                                              ║
  14. '║          TITLE: Text To MT-32 LCD Display Program                            ║
  15. '║       COMPILER: Microsoft QuickBASIC 4.5                                     ║
  16. '║   DEVELOPED BY: John J. Hanney, jr.                                          ║
  17. '║           DATE: 23 December 1989.                                            ║
  18. '║       MODIFIED: 16 November 1992 Version 1.00 (QB 4.5) JJHjr.                ║
  19. '║                                                                              ║
  20. '║   (C)Copyright 1989, 1992 John J. Hanney, jr.                                ║
  21. '║   All rights reserved.                                                       ║
  22. '╚══════════════════════════════════════════════════════════════════════════════╝
  23.  
  24. REM set up variables, etc ...
  25.         DEFINT M                'Make al "M" variables integers.
  26.         L$ = CHR$(10)           'L$=Line feed.
  27.         MCMDPORT = &H331        'Midi command port.
  28.         MSTATPORT = &H331       'Midi status port.
  29.         MDATAPORT = &H330       'Midi data port.
  30.         MDSR = &H80             'Data Send Register.
  31.         MDRR = &H40             'Data Read Register.
  32.         MACK = &HFE             'Acknowledgement.
  33.         MRETSTAT = 0            'Return status from midi subroutines..
  34.         MWORK1 = 0              'Work variable #1 for midi subroutines.
  35.         MWORK2 = 0              'Work variable #2 for midi subroutines.
  36.         MTRIES = 0              'Counter for midi subroutines.
  37. REM Variables that may require change ...
  38.         MAXTRIES = 5120         'Time out value, for compiled run.
  39.                                 '   Can use 512 for interpretive run.
  40.         MTDEV = &H10            'MT-32 device number = 17.  Remember, 17 is "really" 16 (10h).
  41.                                 '   Change if device other than 17.
  42.  
  43. '════════════════════════════════════════════════════════════════════════════════
  44.  
  45. '┌─────────────────────┐
  46. '│ Display title once. │
  47. '└─────────────────────┘
  48.         PRINT "MT32DISP: Text To MT-32 LCD Display Program"
  49.         PRINT TAB(11); "Version 1.00 - Freeware"
  50.         PRINT TAB(11); "By: John J. Hanney, jr."; L$
  51.  
  52. '════════════════════════════════════════════════════════════════════════════════
  53.  
  54. BEGIN10:
  55. '┌────────────────┐
  56. '│ Reset MPU-401. │
  57. '└────────────────┘
  58.         GOSUB MIDIRESET: IF MRETSTAT <> 0 THEN GOTO STEPERR10
  59.  
  60. BEGIN20:
  61. '┌──────────────────────────────────────────────────────────────────────┐
  62. '│ Line input text into Z$.  (Use line input so quotes can be entered.) │
  63. '└──────────────────────────────────────────────────────────────────────┘
  64.         Z$ = ""
  65.         LINE INPUT "Key in 20 characters and press ENTER (nothing to quit): ", Z$
  66.         IF Z$ = "" THEN GOTO STEPEND
  67.  
  68. '────────────────────────────────────────────────────────────────────────────────
  69.  
  70. FIXDATA:
  71. '┌─────────────────────────────────────────┐
  72. '│ Fix text so only ASCII 32-127 are used. │
  73. '└─────────────────────────────────────────┘
  74.         Z$ = LEFT$(Z$, 20): Y = &H20    'Y=Inital Checksum
  75.         FOR Z = 1 TO LEN(Z$)            'Won't do this if LEN(Z$)=0
  76. REM ----------- Make character a space if not ASCII 32-127.
  77.                 IF MID$(Z$, Z, 1) < " " OR MID$(Z$, Z, 1) > CHR$(127) THEN MID$(Z$, Z, 1) = " "
  78. REM ----------- Add character to checksum.
  79.                 Y = Y + ASC(MID$(Z$, Z, 1))
  80.         NEXT Z
  81. '┌───────────────────────────────────┐
  82. '│ Prefix Z$ with exclusive message. │
  83. '└───────────────────────────────────┘
  84.         Z$ = CHR$(&HF0) + CHR$(&H41) + CHR$(MTDEV) + CHR$(&H16) + CHR$(&H12) + CHR$(&H20) + CHR$(0) + CHR$(0) + Z$
  85. '┌───────────────────────┐
  86. '│ Add checksum and EOX. │
  87. '└───────────────────────┘
  88.         Z$ = Z$ + CHR$(&H80 - (Y AND &H7F)) + CHR$(&HF7)
  89.  
  90. SENDDATA10:
  91. '┌───────────────────────────┐
  92. '│ Put MPU-401 in UART mode. │
  93. '└───────────────────────────┘
  94.         MWORK1 = &H3F                           '3Fh="UART" Midi Command.
  95.         Z = 0: MRETSTAT = 1                     'Init counter and Midi return status.
  96.         DO WHILE Z < 2 AND MRETSTAT <> 0
  97.                 GOSUB PUTCMD: Z = Z + 1         'Send UART Midi Command.
  98.         LOOP
  99.         IF MRETSTAT <> 0 THEN GOTO STEPERR10
  100.  
  101. SENDDATA20:
  102. '┌─────────────────────────────────────────────────┐
  103. '│ Send each byte of exclusive message to MPU-401. │
  104. '└─────────────────────────────────────────────────┘
  105.         FOR Z = 1 TO LEN(Z$)
  106.                 MWORK1 = ASC(MID$(Z$, Z, 1))    'Place byte in MWORK1.
  107.                 GOSUB PUTDATA                   'Send data, ignore MRETSTAT
  108.         NEXT Z
  109.         GOTO BEGIN10
  110.  
  111. '════════════════════════════════════════════════════════════════════════════════
  112.  
  113. STEPERR10:
  114.         PRINT "MT32DISP Error: MPU-401 not responding ...": BEEP
  115.         GOTO STEPEND
  116.  
  117. STEPEND:
  118.         PRINT L$; "MT32DISP: Complete ...": END
  119.  
  120. ' ╔═════════════╗
  121. '═╣ SUBROUTINES ╠════════════════════════════════════════════════════════════════
  122. ' ╚═════════════╝
  123.  
  124. REM --- MIDI Subroutines ---
  125. '┌───────────────────────────────────────────────────────────────┐
  126. '│   Send A Command To The Midi Command Port                     │
  127. '│   MRETSTAT =  0 ...... Successful.                            │
  128. '│   MRETSTAT =  1 ...... MPU-IPC not in receive state.          │
  129. '│   MRETSTAT =  2 ...... MPU-IPC did not clear DSR bit.         │
  130. '│   MRETSTAT =  3 ...... ACK not received.                      │
  131. '└───────────────────────────────────────────────────────────────┘
  132. PUTCMD:         MRETSTAT = 0: MTRIES = MAXTRIES
  133. PUTCMDB:        MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 1: GOTO PUTCMDZ
  134.                 IF (INP(MSTATPORT) AND MDRR) <> 0 THEN MWORK2 = INP(MDATAPORT): GOTO PUTCMDB
  135.                 OUT MSTATPORT, MWORK1: MTRIES = MAXTRIES
  136. PUTCMDC:        MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 2: GOTO PUTCMDZ
  137.                 IF (INP(MSTATPORT) AND MDSR) <> 0 THEN GOTO PUTCMDC
  138.                 IF INP(MDATAPORT) <> MACK THEN MRETSTAT = 3
  139. PUTCMDZ:        RETURN
  140.  
  141. '┌───────────────────────────────────────────────────────────────┐
  142. '│   Get Data From Midi Data Port                                │
  143. '│   MRETSTAT =  0 ...... Successful.                            │
  144. '│   MRETSTAT =  2 ...... MPU-IPC did not clear DSR bit.         │
  145. '└───────────────────────────────────────────────────────────────┘
  146. GETDATA:        MRETSTAT = 0: MTRIES = MAXTRIES
  147. GETDATAB:       MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 2: GOTO GETDATAZ
  148.                 IF (INP(MSTATPORT) AND MDSR) <> 0 THEN GOTO GETDATAB
  149.                 MWORK1 = INP(MDATAPORT)
  150. GETDATAZ:       RETURN
  151.  
  152. '┌───────────────────────────────────────────────────────────────┐
  153. '│   Send Data Thru Midi Data Port                               │
  154. '│   MRETSTAT =  0 ...... Successful.                            │
  155. '│   MRETSTAT =  1 ...... MPU-IPC not in receive state.          │
  156. '└───────────────────────────────────────────────────────────────┘
  157. PUTDATA:        MRETSTAT = 0: MTRIES = MAXTRIES
  158. PUTDATAB:       MTRIES = MTRIES - 1: IF MTRIES = 0 THEN MRETSTAT = 1: GOTO GETDATAZ
  159.                 IF (INP(MSTATPORT) AND MDRR) <> 0 THEN MWORK2 = INP(MDATAPORT): GOTO PUTDATAB
  160.                 OUT MDATAPORT, MWORK1
  161. PUTDATAZ:       RETURN
  162.  
  163. '────────────────────────────────────────────────────────────────────────────────
  164.  
  165. REM --- Other Subroutines ---
  166.  
  167. '┌───────────────────────────────────────────────────────────────┐
  168. '│   Reset MPU-401 ...                                           │
  169. '└───────────────────────────────────────────────────────────────┘
  170. MIDIRESET:
  171.         MWORK1 = &HFF                           'FFh=Reset Midi Command.
  172.         Z = 0: MRETSTAT = 1                     'Init counter and Midi return status.
  173.         DO WHILE Z < 2 AND MRETSTAT <> 0
  174.                 GOSUB PUTCMD: Z = Z + 1         'Send Reset Midi Command.
  175.         LOOP
  176.         RETURN
  177.  
  178.