home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 10 / mycd10.iso / share / os2 / sonido / ultra08a / toolkit / ultradev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-24  |  13.3 KB  |  368 lines

  1. #define INCL_DOSDEVICES
  2. #include <os2.h>
  3. #include "struct.h"
  4.  
  5. // IOCTL commands
  6. #define GUS_COMMANDS            0x0F
  7. #define UltraDevSetNVoices        0x50
  8. #define UltraDevEnableOutput        0x51
  9. #define UltraDevDisableOutput        0x52
  10. #define UltraDevPokeData        0x53
  11. #define UltraDevPeekData        0x54
  12. #define UltraDevMemAlloc        0x55
  13. #define UltraDevMemFree            0x56
  14. #define UltraDevMemInit            0x57
  15. #define UltraDevStartTimer        0x58
  16. #define UltraDevStopTimer        0x59
  17. #define UltraDevBlockTimerHandler1    0x5A
  18. #define UltraDevBlockTimerHandler2    0x5B
  19. #define UltraDevStartVoice        0x5C
  20. #define UltraDevStopVoice        0x5D
  21. #define UltraDevSetBalance        0x5E
  22. #define UltraDevSetFrequency        0x5F
  23. #define UltraDevVectorLinearVolume    0x60
  24. #define UltraDevPrepare4DMAXfer        0x61
  25. #define UltraDevUnblockAll        0x62
  26. #define UltraDevSetAll            0x63
  27. #define UltraDevGetAccess               0x6A
  28. #define UltraDevReleaseAccess              0x6B
  29. #define UltraDevSizeDRAM        0x6D
  30. #define UltraDevGetDriverVersion    0x6E
  31.  
  32. extern HFILE GUSHandle;
  33.  
  34. /******************************************************************************/
  35. /******************************************************************************/
  36. APIRET UltraSetNVoices(numvoices)
  37. int numvoices;
  38. {
  39. ULONG ParmLength=0, DataLength=4;
  40.  
  41. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevSetNVoices, NULL, 0, &ParmLength,
  42.          &numvoices, 4, &DataLength));
  43. }
  44. /******************************************************************************/
  45. /******************************************************************************/
  46. APIRET UltraGetAccess()
  47. {
  48. ULONG DataLength = 0, ParmLength = 0;
  49.  
  50. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevGetAccess, NULL, 0,
  51.          &ParmLength, NULL, 0, &DataLength));
  52. }
  53. /******************************************************************************/
  54. /******************************************************************************/
  55. APIRET UltraReleaseAccess()
  56. {
  57. ULONG DataLength = 0, ParmLength = 0;
  58.  
  59. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevReleaseAccess, NULL, 0,
  60.          &ParmLength, NULL, 0, &DataLength));
  61. }
  62. /******************************************************************************/
  63. /******************************************************************************/
  64. APIRET UltraEnableOutput()
  65. {
  66. ULONG DataLength = 0, ParmLength = 0;
  67.  
  68. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevEnableOutput, NULL, 0,
  69.          &ParmLength, NULL, 0, &DataLength));
  70. }
  71. /******************************************************************************/
  72. /******************************************************************************/
  73. APIRET UltraDisableOutput()
  74. {
  75. ULONG DataLength = 0, ParmLength = 0;
  76.  
  77. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevDisableOutput, NULL, 0,
  78.          &ParmLength, NULL, 0, &DataLength));
  79. }
  80. /******************************************************************************/
  81. /******************************************************************************/
  82. APIRET UltraBlockTimerHandler1()
  83. {
  84. ULONG ParmLength = 0, DataLength = 0;
  85. // block until timer interrupt
  86. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevBlockTimerHandler1, NULL, 0, &ParmLength,
  87.                 NULL, 0, &DataLength));
  88. }
  89. /******************************************************************************/
  90. /******************************************************************************/
  91. APIRET UltraBlockTimerHandler2()
  92. {
  93. ULONG ParmLength = 0, DataLength = 0;
  94. // block until timer interrupt
  95. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevBlockTimerHandler2, NULL, 0, &ParmLength,
  96.                  NULL, 0, &DataLength));
  97. /******************************************************************************/
  98. /******************************************************************************/
  99. APIRET UltraStartTimer(timer, time)
  100. int timer;
  101. int time;
  102. {
  103. TimerStruct tbuffer;
  104. ULONG ParmLength, DataLength;
  105.  
  106. ParmLength = 0;
  107. DataLength = sizeof(TimerStruct);
  108. tbuffer.timer = (short int)timer;
  109. tbuffer.time = (unsigned char)time;
  110. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevStartTimer, NULL, 0, &ParmLength,
  111.         &tbuffer, DataLength, &DataLength));
  112. }
  113. /******************************************************************************/
  114. /******************************************************************************/
  115. APIRET UltraStopTimer(timer)
  116. int timer;
  117. {
  118. ULONG ParmLength, DataLength;
  119.  
  120. ParmLength = 0;
  121. DataLength = 4; 
  122. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevStopTimer, NULL, 0, &ParmLength,
  123.          &timer, 4, &DataLength));
  124. }
  125. /******************************************************************************/
  126. /******************************************************************************/
  127. APIRET UltraSetBalance(voice, data)
  128. int voice;
  129. int data;
  130. {
  131. ULONG ParmLength = 0, DataLength;
  132. BalanceStruct bbuffer;
  133.  
  134. DataLength = sizeof(BalanceStruct);
  135. bbuffer.voice = (short int)voice;
  136. bbuffer.data = (unsigned char)data;
  137. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevSetBalance, NULL, 0,
  138.         &ParmLength, &bbuffer, DataLength, &DataLength));
  139. }
  140. /******************************************************************************/
  141. /******************************************************************************/
  142. APIRET UltraSetFrequency(voice, freq)
  143. int voice;
  144. int freq;
  145. {
  146. ULONG ParmLength = 0, DataLength;
  147. FreqStruct fbuffer;
  148.  
  149. DataLength = sizeof(FreqStruct);
  150. fbuffer.voice = (short int)voice;
  151. fbuffer.speed_khz = (short int)freq;
  152. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevSetFrequency, NULL, 0,
  153.         &ParmLength, &fbuffer, DataLength, &DataLength));
  154. }
  155. /******************************************************************************/
  156. /******************************************************************************/
  157. APIRET UltraMemFree(int size, int location)
  158. {
  159. ULONG ParmLength = 0, DataLength = sizeof(AllocStruct);
  160. AllocStruct abuffer;
  161.  
  162.  abuffer.size = size;
  163.  abuffer.location = location;
  164.  return(DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevMemFree, NULL,
  165.         0, &ParmLength, &abuffer, DataLength, &DataLength)) ;
  166. }
  167. /******************************************************************************/
  168. /******************************************************************************/
  169. APIRET UltraMemAlloc(size, location)
  170. unsigned long size;
  171. unsigned long *location;
  172. {
  173. ULONG ParmLength = 0, DataLength;
  174. AllocStruct abuffer;
  175. APIRET rc;
  176.  
  177. DataLength = sizeof(AllocStruct);
  178. abuffer.size = size;
  179. abuffer.location = *location;
  180.  
  181. rc = DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevMemAlloc, NULL,
  182.            0, &ParmLength, &abuffer, DataLength, &DataLength);
  183.  
  184. *location = abuffer.location; /* location in DRAM GUS */
  185. return(rc);
  186. }
  187. /******************************************************************************/
  188. /******************************************************************************/
  189. APIRET UltraMemInit()
  190. {
  191. ULONG ParmLength = 0, DataLength = 0;
  192.  
  193.  return(DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevMemAlloc, NULL,
  194.                 0, &ParmLength, NULL, 0, &DataLength));
  195. }
  196. /******************************************************************************/
  197. /******************************************************************************/
  198. APIRET UltraDownload(dataptr, control, dram_loc, size, wait)
  199. char *dataptr;
  200. unsigned char control;
  201. unsigned long dram_loc;
  202. unsigned int size;
  203. int wait;
  204. {
  205. ULONG ParmLength = 0, DataLength;
  206. APIRET rc;
  207. ULONG written;
  208. XferStruct xbuffer;
  209.  
  210.  /* structure voor UltraPrepare4DMAXfer IOCtl call */
  211.  DataLength = sizeof(XferStruct);
  212.  xbuffer.control = control;     //control byte (data width, signed/unsigned)
  213.  xbuffer.dram_loc = dram_loc;
  214.  
  215.  while(TRUE) {
  216.      if(size > 63*1024) {//16 bit segments in a 32 bit world 8(
  217.          rc = DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevPrepare4DMAXfer, NULL,
  218.                    0, &ParmLength, &xbuffer, DataLength, &DataLength);
  219.         if(rc != 0)         return(rc);
  220.         rc = DosWrite(GUSHandle, dataptr, 63*1024, &written);
  221.         if(rc != 0)        return(rc);
  222.         dram_loc += 63*1024;
  223.         xbuffer.dram_loc = dram_loc;
  224.         dataptr += 63*1024;
  225.         size -= 63*1024;
  226.      }
  227.      else   break;
  228.  }
  229.  if(size > 0) {
  230.      rc = DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevPrepare4DMAXfer, NULL,
  231.                 0, &ParmLength, &xbuffer, DataLength, &DataLength);
  232.      if(rc != 0)         return(rc);
  233.      return( DosWrite(GUSHandle, dataptr, size, &written)); //last transfer
  234.  }
  235.  else    return(0);
  236. }
  237. /******************************************************************************/
  238. /******************************************************************************/
  239. APIRET UltraPokeData(address, data)
  240. long address;
  241. int data;
  242. {
  243. ULONG ParmLength = 0, DataLength;
  244. PokeStruct pbuffer;
  245.  
  246. pbuffer.address = address;
  247. pbuffer.data = (unsigned char)data;
  248. DataLength = sizeof(pbuffer);
  249. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevPokeData, NULL, 0,
  250.         &ParmLength, &pbuffer, DataLength, &DataLength));
  251. }
  252. /******************************************************************************/
  253. /******************************************************************************/
  254. APIRET UltraPeekData(int *address)
  255. {
  256. ULONG ParmLength = 0, DataLength;
  257.  
  258. DataLength = sizeof(int);
  259. return(DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevPeekData, NULL, 0, &ParmLength,
  260.                    address, DataLength, &DataLength));
  261. }
  262. /******************************************************************************/
  263. /******************************************************************************/
  264. APIRET UltraUnblockAll()
  265. {
  266. ULONG ParmLength = 0, DataLength = 0;
  267.  
  268. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevUnblockAll, NULL, 0, &ParmLength,
  269.           NULL, 0, &DataLength));
  270. }
  271. /******************************************************************************/
  272. /******************************************************************************/
  273. APIRET UltraStopVoice(int c)
  274. {
  275. ULONG ParmLength = 0, DataLength = 2;
  276. short int voice;
  277.  
  278. voice = (short int)c;
  279. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevStopVoice, NULL, 0, &ParmLength,
  280.             &voice, DataLength, &DataLength));
  281. }
  282. /******************************************************************************/
  283. /******************************************************************************/
  284. APIRET UltraVectorLinearVolume(voice, end_idx, rate, mode)
  285. int voice;
  286. unsigned int end_idx;        /* end location in ultra DRAM */
  287. unsigned char rate;            /* 0 to 63 */
  288. unsigned char mode;            /* mode to run the volume ramp in ... */
  289. {
  290. ULONG ParmLength, DataLength;
  291. VolumeStruct vbuffer;
  292.  
  293. vbuffer.voice = (short int)voice;
  294. vbuffer.end_idx = (short int)end_idx;
  295. vbuffer.rate = rate;
  296. vbuffer.mode = mode;
  297. DataLength = sizeof(VolumeStruct);
  298. ParmLength = 0;
  299. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevVectorLinearVolume,
  300.          NULL, 0, &ParmLength, &vbuffer, DataLength, &DataLength));
  301. }
  302. /******************************************************************************/
  303. /******************************************************************************/
  304. APIRET UltraSetAll(voice, balance, freq, volume, rate, mode)
  305. int voice;
  306. char balance;
  307. int freq, volume;
  308. unsigned char rate;            /* 0 to 63 */
  309. unsigned char mode;            /* mode to run the volume ramp in ... */
  310. {
  311. ULONG ParmLength = 0, DataLength;
  312. AllStruct abuffer;
  313.  
  314. DataLength = sizeof(AllStruct);
  315. abuffer.voice = (short int)voice;
  316. abuffer.balance = (unsigned char)balance;
  317. abuffer.freq = (unsigned short int)freq;
  318. abuffer.volume = (unsigned short int)volume;
  319. abuffer.rate = rate;
  320. abuffer.mode = mode;
  321. return( DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevSetAll, NULL, 0,
  322.             &ParmLength, &abuffer, DataLength, &DataLength));
  323. }
  324. /******************************************************************************/
  325. /******************************************************************************/
  326. APIRET UltraStartVoice(gusvoice, begin, start, end, mode)
  327. int gusvoice;         /* voice to start */
  328. unsigned int begin;     /* start location in ultra DRAM */
  329. unsigned int start;     /* start loop location in ultra DRAM */
  330. unsigned int end;     /* end location in ultra DRAM */
  331. unsigned char mode;     /* mode to run the voice (loop etc) */
  332. {
  333. ULONG ParmLength = 0, DataLength;
  334. VoiceStruct voice;
  335.  
  336. voice.voice = (short int)gusvoice;
  337. voice.begin = begin; // start in DRAM
  338. voice.start = start; //start loop
  339. voice.end = end;
  340. voice.mode = mode;
  341. DataLength = sizeof(VoiceStruct);
  342. return(    DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevStartVoice, NULL, 0,
  343.             &ParmLength, &voice, DataLength, &DataLength));
  344. }
  345. /******************************************************************************/
  346. /******************************************************************************/
  347. APIRET UltraSizeDram(int *size)
  348. {
  349. ULONG ParmLength = 0, DataLength;
  350.  
  351.   DataLength = sizeof(int);
  352.   return(DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevSizeDRAM, NULL, 0, &ParmLength,
  353.                      size, DataLength, &DataLength));
  354. }
  355. /******************************************************************************/
  356. /******************************************************************************/
  357. APIRET UltraGetDriverVersion(int *version)
  358. {
  359. ULONG ParmLength = 0, DataLength;
  360. //High word contains major version, low word minor version
  361.  
  362.   DataLength = sizeof(int);
  363.   return(DosDevIOCtl(GUSHandle, GUS_COMMANDS, UltraDevGetDriverVersion, NULL, 0, &ParmLength,
  364.                      version, DataLength, &DataLength));
  365. }
  366. /******************************************************************************/
  367. /******************************************************************************/