#include "na_macro.inc" .bss nadMessagesProcessed: .space 2 .text THUMB_CODE #define SD9_CAPTURECOPY (16*4) #define SD9_NADCOUNTER 68 .macro get_chptr result, clobber @ get channel pointer from d8-d15 ldr \result,=0x4000400 @ ldrb \clobber, [r0, #1] @ lsl \clobber, #4 @ add \result, \clobber @ .endm @ private function nadUpdateSharedSoundControl @ r3 = data @ r0 = message ldr r1,=naSharedData9 ldr r1, [r1] ldrb r2, [r0, #1] lsl r2, #2 str r3, [r1, r2] @bx lr @ also increment counter add r1, #SD9_NADCOUNTER ldr r2, [r1] add r2, #1 str r2, [r1] bx lr private function incrementProcessCounter ldr r1,=naSharedData9 ldr r1, [r1] add r1, #SD9_NADCOUNTER ldr r2, [r1] add r2, #1 str r2, [r1] bx lr @------------------------------------------------------------------------------- public function nadSetChannelRegister @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index ldrb r1, [r0, #2] @ r1 = register index ldr r3, [r0, #4] @ r0 = data cmp r1, #1 @ "switch" register index blt .scr_cnt @ beq .scr_sad @ cmp r1, #3 @ blt .scr_tmr @ beq .scr_pnt @ .scr_len: @ case 4/len: str r3, [r2, #12] @ b incrementProcessCounter .scr_cnt: @ case 0/cnt: str r3, [r2, #0] @ b nadUpdateSharedSoundControl .scr_sad: @ case 1/sad: str r3, [r2, #4] @ b incrementProcessCounter .scr_tmr: @ case 2/tmr: strh r3, [r2, #8] @ b incrementProcessCounter .scr_pnt: @ case 3/pnt: strh r3, [r2, #10] @ b incrementProcessCounter @------------------------------------------------------------------------------- public function nadSetChannelVolume @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index ldrh r1, [r0, #2] @ copy volume,shift strh r1, [r2, #0] @ ldr r3, [r2] b nadUpdateSharedSoundControl @------------------------------------------------------------------------------- public function nadSetChannelPanning @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index ldrb r1, [r0, #2] @ copy panning strb r1, [r2, #2] @ ldr r3, [r2] b nadUpdateSharedSoundControl @------------------------------------------------------------------------------- public function nadSetChannelDuty @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index ldrb r3, [r2, #3] @ copy waveduty ldrb r1, [r0, #2] @ lsr r3, #3 @ lsl r3, #3 @ orr r3, r1 @ strb r3, [r2, #3] @ ldr r3, [r2] b nadUpdateSharedSoundControl @bx lr @ @------------------------------------------------------------------------------- public function nadSetChannelSource @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index @------------------------------------------------------------------------------- ldrb r1, [r0, #2] @ set format lsl r1, #3 @ ldrb r3, [r0, #3] @ lsl r3, #5 @ orr r1, r3 @ strb r1, [r2, #3] @ @------------------------------------------------------------------------------- ldr r3, [r0, #4] @ copy SRC str r3, [r2, #4] @ @------------------------------------------------------------------------------- ldr r3, [r0, #8] @ copy LEN str r3, [r2, #12] @ @------------------------------------------------------------------------------- mov r3, #0 @ copy PNT or 0 for oneshot lsr r1, #4 @ bcc .noloop @ ldr r3, [r0, #12] @ .noloop: @ strh r3, [r2, #8] @ @------------------------------------------------------------------------------- ldr r3, [r2] b nadUpdateSharedSoundControl @------------------------------------------------------------------------------- public function nadSetChannelSourcePSG @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index @------------------------------------------------------------------------------- ldrb r1, [r0, #2] @ set psg source add r1, #(1<<3)|(3<<5) @ strb r1, [r2, #3] @ @------------------------------------------------------------------------------- ldr r3, [r2] b nadUpdateSharedSoundControl @------------------------------------------------------------------------------- public function nadSetChannelSourceNoise @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index @------------------------------------------------------------------------------- mov r1, #(1<<3)|(3<<5) @ strb r1, [r2, #3] @ @------------------------------------------------------------------------------- ldr r3, [r2] b nadUpdateSharedSoundControl @------------------------------------------------------------------------------- public function nadSetChannelTimer @------------------------------------------------------------------------------- get_chptr r2, r1 @ r2 = channels + index @------------------------------------------------------------------------------- ldrh r1, [r0, #2] @ strh r1, [r2, #8] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteSOUNDCNT @------------------------------------------------------------------------------- ldrh r1, [r0, #2] @ copy soundcnt ldr r0,=0x4000500 @ strh r1, [r0] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteSOUNDBIAS @------------------------------------------------------------------------------- ldrh r1, [r0, #2] @ copy soundbias ldr r0,=0x4000504 @ strh r1, [r0] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteCaptureControl @------------------------------------------------------------------------------- ldrb r1, [r0, #1] @ copy capture cnt ldrb r2, [r0, #2] @ ldr r0,=0x4000508 @ strb r2, [r0, r1] @ @------------------------------------------------------------------------------- ldr r0,=naSharedData9 @ copy capture cnts ldr r0, [r0] @ add r0, #SD9_CAPTURECOPY @ ldr r1,=0x4000508 @ ldrh r1, [r1] @ strh r1, [r0] @ b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteCaptureControl2 @------------------------------------------------------------------------------- ldrh r1, [r0, #2] @ write controls ldr r0,=0x4000508 @ strh r1, [r0] @ @------------------------------------------------------------------------------- ldr r0,=naSharedData9 @ copy controls ldr r0, [r0] @ add r0, #SD9_CAPTURECOPY @ ldr r1,=0x4000508 @ ldrh r1, [r1] @ strh r1, [r0] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteCaptureDest @------------------------------------------------------------------------------- ldrb r1, [r0, #1] @ copy capture cnt ldr r2, [r0, #4] @ ldr r0,=0x4000510 @ x510 or x518 lsl r1, #3 @ str r2, [r0, r1] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadWriteCaptureLength @------------------------------------------------------------------------------- ldrb r1, [r0, #1] @ copy capture len ldrh r2, [r0, #2] @ ldr r0,=0x4000514 @ x514 or x51C lsl r1, #3 @ strh r2, [r0, r1] @ @------------------------------------------------------------------------------- b incrementProcessCounter @------------------------------------------------------------------------------- public function nadCopySharedCaptureControls @------------------------------------------------------------------------------- ldr r0,=naSharedData9 ldr r0, [r0] add r0, #SD9_CAPTURECOPY ldr r1,=0x4000508 ldrh r1, [r1] strh r1, [r0] bx lr ARM_CODE @------------------------------------------------------------------------------- public function nadStartChannels @------------------------------------------------------------------------------- push {r0,lr} @bl naSuspendIRQ @ <-safe in fifo handler? pop {r0} ldrh r0, [r0, #2] @ ldr r1,=0x4000403 @ @------------------------------------------------------------------------------- 1: movs r0, r0, lsr#1 @ enable channels ldrb r2, [r1], #16 @ orr r2, #0x80 @ strcsb r2, [r1, #-16] @ movs r0, r0, lsr#1 @ unroll 1x ldrb r2, [r1], #16 @ orr r2, #0x80 @ strcsb r2, [r1, #-16] @ bne 1b @ @------------------------------------------------------------------------------- @bl naRestoreIRQ @ safe? @------------------------------------------------------------------------------- bl nadCopySharedChannelControls ldr r0,=naSharedData9 ldr r0, [r0] ldr r1, [r0, #SD9_NADCOUNTER] add r1, #1 str r1, [r0, #SD9_NADCOUNTER] pop {lr} bx lr @------------------------------------------------------------------------------- public function nadStopChannels @------------------------------------------------------------------------------- push {r0,lr} @bl naSuspendIRQ pop {r0} ldrh r0, [r0, #2] @ ldr r1,=0x4000403 @ @------------------------------------------------------------------------------- 1: movs r0, r0, lsr#1 @ disable channels ldrb r2, [r1], #16 @ bic r2, #0x80 @ strcsb r2, [r1, #-16] @ bne 1b @ @------------------------------------------------------------------------------- bl nadCopySharedChannelControls ldr r0,=naSharedData9 ldr r0, [r0] ldr r1, [r0, #SD9_NADCOUNTER] add r1, #1 str r1, [r0, #SD9_NADCOUNTER] pop {lr} bx lr @------------------------------------------------------------------------------- public function nadCopySharedChannelControls @------------------------------------------------------------------------------- push {r4-r7, lr} @ lol bl naSuspendIRQ ldr r0,=naSharedData9 ldr r0, [r0] ldr r1,=0x4000400+15*16 ldr r14, [r1], #-16 ldr r12, [r1], #-16 ldr r7, [r1], #-16 ldr r6, [r1], #-16 ldr r5, [r1], #-16 ldr r4, [r1], #-16 ldr r3, [r1], #-16 ldr r2, [r1], #-16 push {r2-r7,r12,r14} ldr r14, [r1], #-16 ldr r12, [r1], #-16 ldr r7, [r1], #-16 ldr r6, [r1], #-16 ldr r5, [r1], #-16 ldr r4, [r1], #-16 ldr r3, [r1], #-16 ldr r2, [r1], #-16 stmia r0!, {r2-r7,r12,r14} pop {r2-r7,r12,r14} stmia r0!, {r2-r7,r12,r14} bl naRestoreIRQ pop {r4-r7, lr} bx lr