Guest User

Untitled

a guest
Jul 18th, 2019
476
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SND_PaintChannelFrom8:
  2. // r0: int true_lvol
  3. // r1: int true_rvol
  4. // r2: char *sfx
  5. // r3: int count
  6.  
  7. stmfd sp!, {r4, r5, r6, r7, r8, r10}
  8.  
  9. ldr ip, =paintbuffer
  10. ldr ip, [ip]
  11. sub r3, r3, #1 // we'll count backwards
  12. mov r0, r0, asl #16 // pre-scale both volumes by 2^16
  13. mov r1, r1, asl #16
  14.  
  15. // r10 = 0xffff0000
  16. ldrh r10, =0xffff
  17. .loop:
  18. ldrsb r4, [r2, r3] // load *sfx[i] -> r4
  19.  
  20. // keep endianness in mind here
  21. // buffer looks like [left_0, left_1, right_0, right_1] in memory
  22. // but it is loaded as [right1, right0, left1, left0] to registers
  23. ldr r8, [ip, r3, lsl #2] // load paintbuffer[0:1] = RIGHTCHANNEL:LEFTCHANNEL
  24.  
  25. // handle high half (right channel) first
  26. mul r5, r4, r1 // SCALEDRIGHT = SFXI * (true_rvol << 16) -- bottom half is zero
  27.  
  28. // r7 holds right channel in high half (dirty bottom half)
  29. qadd r7, r5, r8 // RIGHTCHANORIG = SCALEDRIGHT + RIGHTCHANORIG (high half)
  30.  
  31. bic r7, r7, r10 // zero bottom bits of r7
  32.  
  33. // trash r5, r6 and handle left channel
  34. mul r5, r4, r0 // SCALEDLEFT = SFXI * (true_rvol << 16)
  35.  
  36. mov r8, r8, lsl #16 // extract original left channel from paintbuffer
  37.  
  38. // r8 holds left channel in high half with zero bottom half
  39. qadd r8, r5, r8
  40.  
  41. // combine the two 16-bit samples in r7 as 32-bit [left:right]
  42. // (use lsr to not sign-extend the lower half)
  43. orr r7, r7, r8, lsr #16
  44.  
  45. str r7, [ip, r3, lsl #2] // write 32-bit to paintbuffer
  46.  
  47. subs r3, r3, #1
  48. bne .loop
  49.  
  50. ldmfd sp!, {r4, r5, r6, r7, r8, r10}
  51.  
  52. bx lr
RAW Paste Data