Skip to content

Instantly share code, notes, and snippets.

@yupferris
Last active March 9, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yupferris/1246f6106a45e01cbb9ccea73919c9a4 to your computer and use it in GitHub Desktop.
Save yupferris/1246f6106a45e01cbb9ccea73919c9a4 to your computer and use it in GitHub Desktop.
Virtual Bowling sample playback routine reversing notes
// Super high-level playroutine overview:
// Timer reload set to 12, 13, 5 (depending on sample)
// Timer int fires every ??us (sample rate of ??hz)
// Store 0x1d in timer control (small interval, zero interrupt enable, clear zero status, timer enable)
// Output volume to VOICE_1_ENVELOPE_DATA
// Sample value -> register value lookup table:
0xffffd258 00 10 20 30 40 50 60 70 80 90 a0 b0 c0 d0 e0 f0
// Sample playback routine (only thing the timer is used for in this game)
* 0xfff03dc6 64cd0880 ld.w -32760[r4], r11 // r11 = Samples left
0xfff03dca 4ba5ffff addi 0xffff, r11, r10
0xfff03dce 44dd0880 st.w r10, -32760[r4] // Decrement samples left
0xfff03dd2 0694 bnz 0x6 (0xfff03dd8)
0xfff03dd4 00a81800 jr 24 (0xfff03dec)
// Samples left not 0
0xfff03dd8 20bc0005 movhi 0x500, r0, r1
0xfff03ddc 41cdc80a ld.w 2760[r1], r10 // r10 = 0x02000000
0xfff03de0 60a11d00 movea 0x1d, r0, r11 // r11 = 0x0000001d
0xfff03de4 6ad12000 st.b r11, 32[r10] // TIMER_CONTROL_REG = r11
0xfff03de8 00a82200 jr 34 (0xfff03e0a)
// Samples left 0 (don't seem to hit this code path)
0xfff03dec 20bc0005 movhi 0x500, r0, r1
0xfff03df0 41cdc80a ld.w 2760[r1], r10 // r10 = 0x02000000
0xfff03df4 60a11000 movea 0x10, r0, r11 // r11 = 0x00000010
0xfff03df8 6ad12000 st.b r11, 32[r10] // TIMER_CONTROL_REG = r11
0xfff03dfc 4c41 mov 12, r10 // r10 = 12
0xfff03dfe 44dd1480 st.w r10, -32748[r4] // ??? = r10 (12)
0xfff03e02 44cd1080 ld.w -32752[r4], r10 // r10 = VOICE_1_ENVELOPE_DATA addr
0xfff03e06 0ad00000 st.b r0, 0[r10] // Write out 0 to VOICE_1_ENVELOPE_DATA
0xfff03e0a 44cd0480 ld.w -32764[r4], r10 // Flip 0x80 bit of -32764[r4] (appears to select which nybble of the data byte we output)
0xfff03e0e 4ab98000 xori 0x80, r10, r10
0xfff03e12 44dd0480 st.w r10, -32764[r4]
0xfff03e16 44cd0480 ld.w -32764[r4], r10 // Branch based on 0x80 bit of -32764[r4]
0xfff03e1a 4ab58000 andi 0x80, r10, r10
0xfff03e1e 0694 bnz 0x6 (0xfff03e24)
0xfff03e20 00a82800 jr 40 (0xfff03e48)
// Output low nybble
0xfff03e24 44cd1080 ld.w -32752[r4], r10 // r10 = VOICE_1_ENVELOPE_DATA addr
0xfff03e28 64cd0c80 ld.w -32756[r4], r11 // r11 = Sample data ptr
0xfff03e2c 6bc10000 ld.b 0[r11], r11 // r11 = Sample data byte
0xfff03e30 6bb5ff00 andi 0xff, r11, r11 // r11 &= 0xff
0xfff03e34 6bb50f00 andi 0xf, r11, r11 // r11 &= 0x0f
0xfff03e38 2bbc0000 movhi 0x0, r11, r1 // r1 = Volume register LUT index
0xfff03e3c 61c158d2 ld.b -11688[r1], r11 // r11 = sample
0xfff03e40 6ad10000 st.b r11, 0[r10] // Write out byte to VOICE_1_ENVELOPE_DATA
0xfff03e44 00a82c00 jr 44 (0xfff03e70)
// Output high nybble and increment data pointer
0xfff03e48 44cd1080 ld.w -32752[r4], r10 // r10 = VOICE_1_ENVELOPE_DATA addr
0xfff03e4c 64cd0c80 ld.w -32756[r4], r11 // r11 = Sample data ptr
0xfff03e50 6bc10000 ld.b 0[r11], r11 // r11 = Sample data byte
0xfff03e54 6bb5ff00 andi 0xff, r11, r11 // r11 &= 0xff
0xfff03e58 645d sar 4, r11 // r11 >>= 4
0xfff03e5a 2bbc0000 movhi 0x0, r11, r1 // r1 = Volume register LUT index
0xfff03e5e 61c158d2 ld.b -11688[r1], r11 // r11 = sample
0xfff03e62 6ad10000 st.b r11, 0[r10] // Write out byte to VOICE_1_ENVELOPE_DATA
0xfff03e66 44cd0c80 ld.w -32756[r4], r10 // Increment sample data ptr
0xfff03e6a 4145 add 1, r10
0xfff03e6c 44dd0c80 st.w r10, -32756[r4]
0xfff03e70 1f18 jmp [r31]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment