SOUNDLCK.CPP 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Westwood 32 bit Library *
  23. * *
  24. * File Name : SOUNDLCK.CPP *
  25. * *
  26. * Programmer : Phil W. Gorrow *
  27. * *
  28. * Start Date : June 23, 1995 *
  29. * *
  30. * Last Update : June 23, 1995 [PWG] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include <dos.h>
  36. #include <mem.h>
  37. #include "soundint.h"
  38. #include "wwmem.h"
  39. LockedDataType LockedData;
  40. /*=========================================================================*/
  41. /* The following PRIVATE functions are in this file: */
  42. /*=========================================================================*/
  43. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  44. /***************************************************************************
  45. * INIT_LOCKED_DATA -- Initializes sound driver locked data *
  46. * *
  47. * INPUT: none *
  48. * *
  49. * OUTPUT: none *
  50. * *
  51. * HISTORY: *
  52. * 06/23/1995 PWG : Created. *
  53. *=========================================================================*/
  54. void Init_Locked_Data(void)
  55. {
  56. /*
  57. ** Initialize all of the data elements that need to be locked.
  58. */
  59. LockedData.DigiHandle = -1;
  60. LockedData.ServiceSomething = FALSE;
  61. LockedData.MagicNumber = 0xDEAF;
  62. LockedData.UncompBuffer = NULL;
  63. LockedData.StreamBufferSize = (2*SFX_MINI_STAGE_BUFFER_SIZE)+128;
  64. LockedData.StreamBufferCount = 32;
  65. LockedData.SoundVolume = 255;
  66. LockedData.ScoreVolume = 255;
  67. LockedData._int = FALSE;
  68. LockedData.MaxSamples = MAX_SFX;
  69. /*
  70. ** Lock the sound specific c functions that will cause us problems if
  71. ** they are swapped out during an interrupt.
  72. */
  73. DPMI_Lock(&LockedData, 4096L);
  74. DPMI_Lock(Simple_Copy, 4096L);
  75. DPMI_Lock(Sample_Copy, 4096L);
  76. DPMI_Lock((void *)maintenance_callback, 4096L);
  77. DPMI_Lock((void *)DigiCallback, 4096L);
  78. DPMI_Lock((void *)HMI_TimerCallback, 4096L);
  79. DPMI_Lock(Audio_Add_Long_To_Pointer, 4096L);
  80. DPMI_Lock(DPMI_Unlock, 4096L);
  81. /*
  82. ** Lock the library functions that will cause us problems if they are
  83. ** swapped out during an interrupt.
  84. */
  85. DPMI_Lock(Mem_Copy, 4096L);
  86. DPMI_Lock(Audio_Mem_Set, 4096L);
  87. DPMI_Lock(__GETDS, 4096L);
  88. /*
  89. ** Finally lock the two assembly modules that need locking. This can
  90. ** be handled by calling the lock function that is local to thier module
  91. ** swapped out during an interrupt.
  92. */
  93. Decompress_Frame_Lock();
  94. sosCODEC_Lock();
  95. }
  96. void Unlock_Locked_Data(void)
  97. {
  98. /*
  99. ** Lock the sound specific c functions that will cause us problems if
  100. ** they are swapped out during an interrupt.
  101. */
  102. DPMI_Unlock(&LockedData, 4096L);
  103. DPMI_Unlock(Simple_Copy, 4096L);
  104. DPMI_Unlock(Sample_Copy, 4096L);
  105. DPMI_Unlock((void *)maintenance_callback, 4096L);
  106. DPMI_Unlock((void *)DigiCallback, 4096L);
  107. DPMI_Unlock((void *)HMI_TimerCallback, 4096L);
  108. DPMI_Unlock(Audio_Add_Long_To_Pointer, 4096L);
  109. /*
  110. ** Lock the library functions that will cause us problems if they are
  111. ** swapped out during an interrupt.
  112. */
  113. DPMI_Unlock(Mem_Copy, 4096L);
  114. DPMI_Unlock(Audio_Mem_Set, 4096L);
  115. DPMI_Unlock(__GETDS, 4096L);
  116. /*
  117. ** Finally unlock the two assembly modules that need locking. This can
  118. ** be handled by calling the lock function that is local to thier module
  119. ** swapped out during an interrupt.
  120. */
  121. Decompress_Frame_Unlock();
  122. sosCODEC_Unlock();
  123. /*
  124. ** As a last step go though all of the sample tracker structures and make
  125. ** sure all the samples have been properly unlocked.
  126. */
  127. for (int id = 0; id < LockedData.MaxSamples; id++) {
  128. if (LockedData.SampleTracker[id].Original && !LockedData.SampleTracker[id].IsScore) {
  129. DPMI_Unlock(LockedData.SampleTracker[id].Original, LockedData.SampleTracker[id].OriginalSize);
  130. LockedData.SampleTracker[id].Original = NULL;
  131. }
  132. }
  133. }