snd_mixa.s 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. //
  19. // snd_mixa.s
  20. // x86 assembly-language sound code
  21. //
  22. #include "qasm.h"
  23. #if id386
  24. .text
  25. #if 0
  26. //----------------------------------------------------------------------
  27. // 8-bit sound-mixing code
  28. //----------------------------------------------------------------------
  29. #define ch 4+16
  30. #define sc 8+16
  31. #define count 12+16
  32. .globl C(S_PaintChannelFrom8)
  33. C(S_PaintChannelFrom8):
  34. pushl %esi // preserve register variables
  35. pushl %edi
  36. pushl %ebx
  37. pushl %ebp
  38. // int data;
  39. // short *lscale, *rscale;
  40. // unsigned char *sfx;
  41. // int i;
  42. movl ch(%esp),%ebx
  43. movl sc(%esp),%esi
  44. // if (ch->leftvol > 255)
  45. // ch->leftvol = 255;
  46. // if (ch->rightvol > 255)
  47. // ch->rightvol = 255;
  48. movl ch_leftvol(%ebx),%eax
  49. movl ch_rightvol(%ebx),%edx
  50. cmpl $255,%eax
  51. jna LLeftSet
  52. movl $255,%eax
  53. LLeftSet:
  54. cmpl $255,%edx
  55. jna LRightSet
  56. movl $255,%edx
  57. LRightSet:
  58. // lscale = snd_scaletable[ch->leftvol >> 3];
  59. // rscale = snd_scaletable[ch->rightvol >> 3];
  60. // sfx = (signed char *)sc->data + ch->pos;
  61. // ch->pos += count;
  62. andl $0xF8,%eax
  63. addl $20,%esi
  64. movl (%esi),%esi
  65. andl $0xF8,%edx
  66. movl ch_pos(%ebx),%edi
  67. movl count(%esp),%ecx
  68. addl %edi,%esi
  69. shll $7,%eax
  70. addl %ecx,%edi
  71. shll $7,%edx
  72. movl %edi,ch_pos(%ebx)
  73. addl $(C(snd_scaletable)),%eax
  74. addl $(C(snd_scaletable)),%edx
  75. subl %ebx,%ebx
  76. movb -1(%esi,%ecx,1),%bl
  77. testl $1,%ecx
  78. jz LMix8Loop
  79. movl (%eax,%ebx,4),%edi
  80. movl (%edx,%ebx,4),%ebp
  81. addl C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size),%edi
  82. addl C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size),%ebp
  83. movl %edi,C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size)
  84. movl %ebp,C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size)
  85. movb -2(%esi,%ecx,1),%bl
  86. decl %ecx
  87. jz LDone
  88. // for (i=0 ; i<count ; i++)
  89. // {
  90. LMix8Loop:
  91. // data = sfx[i];
  92. // paintbuffer[i].left += lscale[data];
  93. // paintbuffer[i].right += rscale[data];
  94. movl (%eax,%ebx,4),%edi
  95. movl (%edx,%ebx,4),%ebp
  96. addl C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size),%edi
  97. addl C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size),%ebp
  98. movb -2(%esi,%ecx,1),%bl
  99. movl %edi,C(paintbuffer)+psp_left-psp_size(,%ecx,psp_size)
  100. movl %ebp,C(paintbuffer)+psp_right-psp_size(,%ecx,psp_size)
  101. movl (%eax,%ebx,4),%edi
  102. movl (%edx,%ebx,4),%ebp
  103. movb -3(%esi,%ecx,1),%bl
  104. addl C(paintbuffer)+psp_left-psp_size*2(,%ecx,psp_size),%edi
  105. addl C(paintbuffer)+psp_right-psp_size*2(,%ecx,psp_size),%ebp
  106. movl %edi,C(paintbuffer)+psp_left-psp_size*2(,%ecx,psp_size)
  107. movl %ebp,C(paintbuffer)+psp_right-psp_size*2(,%ecx,psp_size)
  108. // }
  109. subl $2,%ecx
  110. jnz LMix8Loop
  111. LDone:
  112. popl %ebp
  113. popl %ebx
  114. popl %edi
  115. popl %esi
  116. ret
  117. #endif
  118. //----------------------------------------------------------------------
  119. // Transfer of stereo buffer to 16-bit DMA buffer code
  120. //----------------------------------------------------------------------
  121. .globl C(S_WriteLinearBlastStereo16)
  122. C(S_WriteLinearBlastStereo16):
  123. pushl %edi
  124. pushl %ebx
  125. // int i;
  126. // int val;
  127. movl C(snd_linear_count),%ecx
  128. movl C(snd_p),%ebx
  129. movl C(snd_out),%edi
  130. // for (i=0 ; i<snd_linear_count ; i+=2)
  131. // {
  132. LWLBLoopTop:
  133. // val = (snd_p[i]*snd_vol)>>8;
  134. // if (val > 0x7fff)
  135. // snd_out[i] = 0x7fff;
  136. // else if (val < (short)0x8000)
  137. // snd_out[i] = (short)0x8000;
  138. // else
  139. // snd_out[i] = val;
  140. movl -8(%ebx,%ecx,4),%eax
  141. sarl $8,%eax
  142. cmpl $0x7FFF,%eax
  143. jg LClampHigh
  144. cmpl $0xFFFF8000,%eax
  145. jnl LClampDone
  146. movl $0xFFFF8000,%eax
  147. jmp LClampDone
  148. LClampHigh:
  149. movl $0x7FFF,%eax
  150. LClampDone:
  151. // val = (snd_p[i+1]*snd_vol)>>8;
  152. // if (val > 0x7fff)
  153. // snd_out[i+1] = 0x7fff;
  154. // else if (val < (short)0x8000)
  155. // snd_out[i+1] = (short)0x8000;
  156. // else
  157. // snd_out[i+1] = val;
  158. movl -4(%ebx,%ecx,4),%edx
  159. sarl $8,%edx
  160. cmpl $0x7FFF,%edx
  161. jg LClampHigh2
  162. cmpl $0xFFFF8000,%edx
  163. jnl LClampDone2
  164. movl $0xFFFF8000,%edx
  165. jmp LClampDone2
  166. LClampHigh2:
  167. movl $0x7FFF,%edx
  168. LClampDone2:
  169. shll $16,%edx
  170. andl $0xFFFF,%eax
  171. orl %eax,%edx
  172. movl %edx,-4(%edi,%ecx,2)
  173. // }
  174. subl $2,%ecx
  175. jnz LWLBLoopTop
  176. // snd_p += snd_linear_count;
  177. popl %ebx
  178. popl %edi
  179. ret
  180. #endif // id386