sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

audio.s (49523B)


      1 .rsp
      2 
      3 .include "rsp/rsp_defs.inc"
      4 
      5 // This file assumes DATA_FILE and CODE_FILE are set on the command line
      6 
      7 .if version() < 110
      8     .error "armips 0.11 or newer is required"
      9 .endif
     10 
     11 .ifdef VERSION_SH
     12 .definelabel VERSION_SH_CN, 1
     13 .elseifdef VERSION_CN
     14 .definelabel VERSION_SH_CN, 1
     15 .endif
     16 
     17 .macro jumpTableEntry, addr
     18   .dh addr & 0xFFFF
     19 .endmacro
     20 
     21 // Audio flags
     22 A_INIT     equ 0x01
     23 A_CONTINUE equ 0x00
     24 A_LOOP     equ 0x02
     25 A_OUT      equ 0x02
     26 A_LEFT     equ 0x02
     27 A_RIGHT    equ 0x00
     28 A_VOL      equ 0x04
     29 A_RATE     equ 0x00
     30 A_AUX      equ 0x08
     31 A_NOAUX    equ 0x00
     32 A_MAIN     equ 0x00
     33 A_MIX      equ 0x10
     34 
     35 .create DATA_FILE, 0x0000
     36 
     37 .dh 0x0000, 0x0001, 0x0002, 0xffff, 0x0020, 0x0800, 0x7fff, 0x4000 // 0x00000000
     38 
     39 // 0x10 - 0x1F: command dispatch table
     40 dispatchTable:
     41   jumpTableEntry cmd_SPNOOP
     42   jumpTableEntry cmd_ADPCM
     43   jumpTableEntry cmd_CLEARBUFF
     44 .ifdef VERSION_SH_CN
     45   jumpTableEntry cmd_SPNOOP
     46 
     47   jumpTableEntry cmd_ADDMIXER
     48   jumpTableEntry cmd_RESAMPLE
     49   jumpTableEntry cmd_RESAMPLE_ZOH
     50   jumpTableEntry cmd_SPNOOP
     51 
     52   jumpTableEntry cmd_SETBUFF
     53   jumpTableEntry cmd_SPNOOP
     54   jumpTableEntry cmd_DMEMMOVE
     55   jumpTableEntry cmd_LOADADPCM
     56 
     57   jumpTableEntry cmd_MIXER
     58   jumpTableEntry cmd_INTERLEAVE
     59   jumpTableEntry cmd_SPNOOP
     60   jumpTableEntry cmd_SETLOOP
     61 
     62   jumpTableEntry cmd_DMEMMOVE2
     63   jumpTableEntry cmd_DOWNSAMPLE_HALF
     64   jumpTableEntry cmd_ENVSETUP1
     65   jumpTableEntry cmd_ENVMIXER
     66 
     67   jumpTableEntry cmd_LOADBUFF
     68   jumpTableEntry cmd_SAVEBUFF
     69   jumpTableEntry cmd_ENVSETUP2
     70   jumpTableEntry cmd_S8DEC
     71 
     72   jumpTableEntry cmd_HILOGAIN
     73   jumpTableEntry cmd_1c7c
     74   jumpTableEntry cmd_DUPLICATE
     75   jumpTableEntry cmd_FILTER
     76 
     77   jumpTableEntry cmd_SPNOOP
     78   jumpTableEntry cmd_SPNOOP
     79   jumpTableEntry cmd_SPNOOP
     80   jumpTableEntry cmd_SPNOOP
     81 .else
     82   jumpTableEntry cmd_ENVMIXER
     83   jumpTableEntry cmd_LOADBUFF
     84   jumpTableEntry cmd_RESAMPLE
     85   jumpTableEntry cmd_SAVEBUFF
     86   jumpTableEntry cmd_SEGMENT
     87   jumpTableEntry cmd_SETBUFF
     88   jumpTableEntry cmd_SETVOL
     89   jumpTableEntry cmd_DMEMMOVE
     90   jumpTableEntry cmd_LOADADPCM
     91   jumpTableEntry cmd_MIXER
     92   jumpTableEntry cmd_INTERLEAVE
     93   jumpTableEntry cmd_POLEF
     94   jumpTableEntry cmd_SETLOOP
     95 .endif
     96 
     97 .dh 0xf000, 0x0f00, 0x00f0, 0x000f, 0x0001, 0x0010, 0x0100, 0x1000 // 0x00000030
     98 data0040:
     99 .dh 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c, 0x000e, 0x0010 // 0x00000040
    100 .dh 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001 // 0x00000050
    101 .dh 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0100, 0x0200 // 0x00000060
    102 .dh 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000 // 0x00000070
    103 .dh 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000 // 0x00000080
    104 .dh 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000 // 0x00000090
    105 .dh 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001 // 0x000000a0
    106 .dh 0x2000, 0x4000, 0x6000, 0x8000, 0xa000, 0xc000, 0xe000, 0xffff // 0x000000b0
    107 .ifdef VERSION_SH_CN
    108 .dh 0x0000, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
    109 .dh 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
    110 .endif
    111 .dh 0x0c39, 0x66ad, 0x0d46, 0xffdf, 0x0b39, 0x6696, 0x0e5f, 0xffd8 // 0x000000c0
    112 .dh 0x0a44, 0x6669, 0x0f83, 0xffd0, 0x095a, 0x6626, 0x10b4, 0xffc8 // 0x000000d0
    113 .dh 0x087d, 0x65cd, 0x11f0, 0xffbf, 0x07ab, 0x655e, 0x1338, 0xffb6 // 0x000000e0
    114 .dh 0x06e4, 0x64d9, 0x148c, 0xffac, 0x0628, 0x643f, 0x15eb, 0xffa1 // 0x000000f0
    115 .dh 0x0577, 0x638f, 0x1756, 0xff96, 0x04d1, 0x62cb, 0x18cb, 0xff8a // 0x00000100
    116 .dh 0x0435, 0x61f3, 0x1a4c, 0xff7e, 0x03a4, 0x6106, 0x1bd7, 0xff71 // 0x00000110
    117 .dh 0x031c, 0x6007, 0x1d6c, 0xff64, 0x029f, 0x5ef5, 0x1f0b, 0xff56 // 0x00000120
    118 .dh 0x022a, 0x5dd0, 0x20b3, 0xff48, 0x01be, 0x5c9a, 0x2264, 0xff3a // 0x00000130
    119 .dh 0x015b, 0x5b53, 0x241e, 0xff2c, 0x0101, 0x59fc, 0x25e0, 0xff1e // 0x00000140
    120 .dh 0x00ae, 0x5896, 0x27a9, 0xff10, 0x0063, 0x5720, 0x297a, 0xff02 // 0x00000150
    121 .dh 0x001f, 0x559d, 0x2b50, 0xfef4, 0xffe2, 0x540d, 0x2d2c, 0xfee8 // 0x00000160
    122 .dh 0xffac, 0x5270, 0x2f0d, 0xfedb, 0xff7c, 0x50c7, 0x30f3, 0xfed0 // 0x00000170
    123 .dh 0xff53, 0x4f14, 0x32dc, 0xfec6, 0xff2e, 0x4d57, 0x34c8, 0xfebd // 0x00000180
    124 .dh 0xff0f, 0x4b91, 0x36b6, 0xfeb6, 0xfef5, 0x49c2, 0x38a5, 0xfeb0 // 0x00000190
    125 .dh 0xfedf, 0x47ed, 0x3a95, 0xfeac, 0xfece, 0x4611, 0x3c85, 0xfeab // 0x000001a0
    126 .dh 0xfec0, 0x4430, 0x3e74, 0xfeac, 0xfeb6, 0x424a, 0x4060, 0xfeaf // 0x000001b0
    127 .dh 0xfeaf, 0x4060, 0x424a, 0xfeb6, 0xfeac, 0x3e74, 0x4430, 0xfec0 // 0x000001c0
    128 .dh 0xfeab, 0x3c85, 0x4611, 0xfece, 0xfeac, 0x3a95, 0x47ed, 0xfedf // 0x000001d0
    129 .dh 0xfeb0, 0x38a5, 0x49c2, 0xfef5, 0xfeb6, 0x36b6, 0x4b91, 0xff0f // 0x000001e0
    130 .dh 0xfebd, 0x34c8, 0x4d57, 0xff2e, 0xfec6, 0x32dc, 0x4f14, 0xff53 // 0x000001f0
    131 .dh 0xfed0, 0x30f3, 0x50c7, 0xff7c, 0xfedb, 0x2f0d, 0x5270, 0xffac // 0x00000200
    132 .dh 0xfee8, 0x2d2c, 0x540d, 0xffe2, 0xfef4, 0x2b50, 0x559d, 0x001f // 0x00000210
    133 .dh 0xff02, 0x297a, 0x5720, 0x0063, 0xff10, 0x27a9, 0x5896, 0x00ae // 0x00000220
    134 .dh 0xff1e, 0x25e0, 0x59fc, 0x0101, 0xff2c, 0x241e, 0x5b53, 0x015b // 0x00000230
    135 .dh 0xff3a, 0x2264, 0x5c9a, 0x01be, 0xff48, 0x20b3, 0x5dd0, 0x022a // 0x00000240
    136 .dh 0xff56, 0x1f0b, 0x5ef5, 0x029f, 0xff64, 0x1d6c, 0x6007, 0x031c // 0x00000250
    137 .dh 0xff71, 0x1bd7, 0x6106, 0x03a4, 0xff7e, 0x1a4c, 0x61f3, 0x0435 // 0x00000260
    138 .dh 0xff8a, 0x18cb, 0x62cb, 0x04d1, 0xff96, 0x1756, 0x638f, 0x0577 // 0x00000270
    139 .dh 0xffa1, 0x15eb, 0x643f, 0x0628, 0xffac, 0x148c, 0x64d9, 0x06e4 // 0x00000280
    140 .dh 0xffb6, 0x1338, 0x655e, 0x07ab, 0xffbf, 0x11f0, 0x65cd, 0x087d // 0x00000290
    141 .dh 0xffc8, 0x10b4, 0x6626, 0x095a, 0xffd0, 0x0f83, 0x6669, 0x0a44 // 0x000002a0
    142 .dh 0xffd8, 0x0e5f, 0x6696, 0x0b39, 0xffdf, 0x0d46, 0x66ad, 0x0c39 // 0x000002b0
    143 .ifdef VERSION_SH_CN
    144 .dh 0xFFFF, 0xDFFF, 0xBFFF, 0x9FFF, 0x7FFF, 0x5FFF, 0x3FFF, 0x1FFF
    145 .dh 0x0000, 0x2000, 0x4000, 0x6000, 0x8000, 0xA000, 0xC000, 0xE000
    146 .dh 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000A, 0x000C, 0x000E
    147 .endif
    148 
    149 .definelabel segmentTable, 0x320
    150 
    151 .ifdef VERSION_SH_CN
    152 .definelabel audioStruct, 0x320
    153 .else
    154 .definelabel audioStruct, 0x360
    155 .endif
    156 audio_in_buf        equ 0x00 // 0x360
    157 audio_out_buf       equ 0x02 // 0x362
    158 audio_count         equ 0x04 // 0x364
    159 audio_vol_left      equ 0x06 // 0x366
    160 audio_vol_right     equ 0x08 // 0x366
    161 audio_aux_buf0      equ 0x0a // 0x36a
    162 audio_aux_buf1      equ 0x0c // 0x36c
    163 audio_aux_buf2      equ 0x0e // 0x36e
    164 audio_loop_value    equ 0x10 // 0x370 (shared)
    165 audio_target_left   equ 0x10 // 0x370 (shared)
    166 audio_rate_hi_left  equ 0x12 // 0x372 (shared)
    167 audio_rate_lo_left  equ 0x14 // 0x374
    168 audio_target_right  equ 0x16 // 0x376
    169 audio_rate_hi_right equ 0x18 // 0x378
    170 .ifdef VERSION_SH_CN
    171 .definelabel audio_rate_lo_right, 0x04 // 0x37a
    172 .else
    173 .definelabel audio_rate_lo_right, 0x1a // 0x37a
    174 .endif
    175 audio_dry_gain      equ 0x1c // 0x37c
    176 audio_wet_gain      equ 0x1e // 0x37e
    177 
    178 .ifdef VERSION_SH_CN
    179 .definelabel nextTaskEntry, 0x340
    180 .definelabel adpcmTable,    0x3c0
    181 .else
    182 .definelabel nextTaskEntry, 0x380 // next task entries (0x140 bytes)
    183 .definelabel adpcmTable,    0x4c0 // (16*8 16-bit entries)
    184 .endif
    185 
    186 .definelabel dmemBase,      0x5c0 // all samples stored that is transferred to DMEM
    187 .definelabel tmpData,       0xF90 // temporary area
    188 
    189 .close // DATA_FILE
    190 
    191 
    192 .create CODE_FILE, 0x04001080
    193 
    194     addi  $24, $zero, audioStruct
    195     addi  $23, $zero, tmpData
    196     lw    $28, 0x30($1)        // task_data
    197     lw    $27, 0x34($1)        // task_data_size
    198     mfc0  $5, DPC_STATUS
    199     andi  $4, $5, DPC_STATUS_XBUS_DMA
    200     beqz  $4, @@audio_040010b4
    201      andi  $4, $5, DPC_STATUS_DMA_BUSY
    202     beqz  $4, @@audio_040010b4
    203      nop
    204 @@dpc_dma_busy:
    205     mfc0  $4, DPC_STATUS
    206     andi  $4, $4, DPC_STATUS_DMA_BUSY
    207     bgtz  $4, @@dpc_dma_busy
    208 @@audio_040010b4:
    209      nop
    210     jal   audio_04001150
    211      nop
    212 .ifndef VERSION_SH_CN
    213     addi  $2, $zero, 0x000f
    214     addi  $1, $zero, segmentTable
    215 @@audio_040010c8:
    216     sw    $zero, 0x00($1)
    217     bgtz  $2, @@audio_040010c8
    218      addi  $2, $2, -1
    219 .endif
    220 
    221 dma_busy:
    222     mfc0  $2, SP_DMA_BUSY
    223     bnez  $2, dma_busy
    224      addi  $29, $zero, nextTaskEntry
    225     mtc0  $zero, SP_SEMAPHORE  // release semaphore
    226 audio_040010e4:
    227     lw    $26, 0x00($29)       // first word of command
    228     lw    $25, 0x04($29)       // second word of command
    229     srl   $1, $26, 23          // cmd byte << 1
    230     andi  $1, $1, 0x00fe
    231     addi  $28, $28, 8
    232     addi  $27, $27, -8
    233     addi  $29, $29, 8
    234     addi  $30, $30, -8
    235     add   $2, $zero, $1
    236     lh    $2, (dispatchTable)($2)
    237     jr    $2
    238      nop
    239     break
    240 
    241 cmd_SPNOOP:
    242     bgtz  $30, audio_040010e4
    243      nop
    244     blez  $27, @@audio_04001138
    245      nop
    246     jal   audio_04001150
    247      nop
    248     j     dma_busy
    249      nop
    250 @@audio_04001138:
    251     ori   $1, $zero, 0x4000
    252     mtc0  $1, SP_STATUS
    253     break
    254     nop
    255 @@forever:
    256     b     @@forever
    257      nop
    258 
    259 audio_04001150:
    260     addi  $5, $ra, 0x0000
    261     add   $2, $zero, $28
    262     addi  $3, $27, 0x0000
    263 .ifdef VERSION_SH_CN
    264     addi  $4, $3, -0x80
    265 .else
    266     addi  $4, $3, -0x0140
    267 .endif
    268     blez  $4, @@audio_0400116c
    269      addi  $1, $zero, nextTaskEntry
    270 .ifdef VERSION_SH_CN
    271     addi  $3, $zero, 0x80
    272 .else
    273     addi  $3, $zero, 0x0140
    274 .endif
    275 @@audio_0400116c:
    276     addi  $30, $3, 0x0000
    277     jal   dma_read_start
    278      addi  $3, $3, -1
    279     addi  $29, $zero, nextTaskEntry
    280     jr    $5
    281      nop
    282 
    283 dma_read_start:
    284     mfc0  $4, SP_SEMAPHORE
    285     bnez  $4, dma_read_start
    286      nop
    287 @@dma_not_full:
    288     mfc0  $4, SP_DMA_FULL
    289     bnez  $4, @@dma_not_full
    290      nop
    291     mtc0  $1, SP_MEM_ADDR
    292     mtc0  $2, SP_DRAM_ADDR
    293     mtc0  $3, SP_RD_LEN
    294     jr    $ra
    295      nop
    296 
    297 dma_write_start:
    298     mfc0  $4, SP_SEMAPHORE
    299     bnez  $4, dma_write_start
    300      nop
    301 @@dma_not_full:
    302     mfc0  $4, SP_DMA_FULL
    303     bnez  $4, @@dma_not_full
    304      nop
    305     mtc0  $1, SP_MEM_ADDR
    306     mtc0  $2, SP_DRAM_ADDR
    307     mtc0  $3, SP_WR_LEN
    308     jr    $ra
    309      nop
    310 
    311 cmd_CLEARBUFF:
    312     andi  $3, $25, 0xffff
    313     beqz  $3, cmd_SPNOOP
    314 .ifndef VERSION_SH_CN
    315      addi  $4, $zero, dmemBase
    316 .endif
    317     andi  $2, $26, 0xffff
    318 .ifndef VERSION_SH_CN
    319     add   $2, $2, $4
    320 .endif
    321 .ifdef VERSION_SH_CN
    322     vxor  $v0, $v0, $v0
    323 .else
    324     vxor  $v1, $v1, $v1
    325 .endif
    326     addi  $3, $3, -0x10
    327 @@audio_040011f8:
    328 .ifdef VERSION_SH_CN
    329     sdv   $v0[0], 0x0($2)
    330     sdv   $v0[0], 0x8($2)
    331 .else
    332     sdv   $v1[0], 0x0($2)
    333     sdv   $v1[0], 0x8($2)
    334 .endif
    335     addi  $2, $2, 0x10
    336     bgtz  $3, @@audio_040011f8
    337      addi  $3, $3, -0x10
    338     j     cmd_SPNOOP
    339      nop
    340 
    341 .ifndef VERSION_SH_CN
    342 cmd_LOADBUFF:
    343     lhu   $3, (audio_count)($24)
    344     beqz  $3, cmd_SPNOOP
    345      sll   $2, $25, 8
    346     srl   $2, $2, 8
    347     srl   $4, $25, 24
    348     sll   $4, $4, 2
    349     lw    $5, (segmentTable)($4)
    350     add   $2, $2, $5
    351     lhu   $1, (audio_in_buf)($24)
    352     jal   dma_read_start
    353      addi  $3, $3, -1
    354 @@dma_read_busy:
    355     mfc0  $1, SP_DMA_BUSY
    356     bnez  $1, @@dma_read_busy
    357      nop
    358     j     cmd_SPNOOP
    359      mtc0  $zero, SP_SEMAPHORE
    360 
    361 cmd_SAVEBUFF:
    362     lhu   $3, (audio_count)($24)
    363     beqz  $3, cmd_SPNOOP
    364      sll   $2, $25, 8
    365     srl   $2, $2, 8
    366     srl   $4, $25, 24
    367     sll   $4, $4, 2
    368     lw    $5, (segmentTable)($4)
    369     add   $2, $2, $5
    370     lhu   $1, (audio_out_buf)($24)
    371     jal   dma_write_start
    372      addi  $3, $3, -1
    373 @@dma_write_busy:
    374     mfc0  $1, SP_DMA_BUSY
    375     bnez  $1, @@dma_write_busy
    376      nop
    377     j     cmd_SPNOOP
    378      mtc0  $zero, SP_SEMAPHORE
    379 
    380 cmd_LOADADPCM:
    381     sll   $2, $25, 8
    382     srl   $2, $2, 8
    383     srl   $4, $25, 24
    384     sll   $4, $4, 2
    385     lw    $5, (segmentTable)($4)
    386     add   $2, $2, $5
    387     addi  $1, $zero, adpcmTable
    388     andi  $3, $26, 0xffff
    389     jal   dma_read_start
    390      addi  $3, $3, -1
    391 @@dma_read_busy:
    392     mfc0  $1, SP_DMA_BUSY
    393     bnez  $1, @@dma_read_busy
    394      nop
    395     j     cmd_SPNOOP
    396      mtc0  $zero, SP_SEMAPHORE
    397 .endif
    398 cmd_SEGMENT:
    399 .ifndef VERSION_SH_CN
    400     sll   $3, $25, 8           // Least significant 24-bits offset
    401     srl   $3, $3, 8
    402     srl   $2, $25, 24          // Most significant 8-bits segment number
    403     sll   $2, $2, 2
    404     add   $4, $zero, $2
    405     j     cmd_SPNOOP
    406      sw    $3, (segmentTable)($4)
    407 .endif
    408 
    409 .ifndef VERSION_SH_CN
    410 cmd_SETBUFF:
    411     addi  $1, $26, dmemBase
    412     srl   $2, $25, 16
    413     addi  $2, $2, dmemBase
    414     srl   $4, $26, 16
    415     andi  $4, $4, A_AUX
    416     bgtz  $4, @@audio_04001318
    417      addi  $3, $25, dmemBase
    418     sh    $1, (audio_in_buf)($24)
    419     sh    $2, (audio_out_buf)($24)
    420     j     cmd_SPNOOP
    421      sh    $25, (audio_count)($24)
    422 @@audio_04001318:
    423     sh    $3, (audio_aux_buf2)($24)
    424     sh    $1, (audio_aux_buf0)($24)
    425     j     cmd_SPNOOP
    426      sh    $2, (audio_aux_buf1)($24)
    427 .endif
    428 
    429 .ifdef VERSION_SH_CN
    430 cmd_SETBUFF:
    431     srl   $2, $25, 16
    432     sh    $26, 0($24)
    433     sh    $2, 2($24)
    434 .else
    435 cmd_SETVOL:
    436     srl   $2, $26, 16
    437     andi  $1, $2, A_AUX
    438     beqz  $1, @@audio_04001344
    439      andi  $1, $2, A_VOL
    440     sh    $26, (audio_dry_gain)($24)
    441     j     cmd_SPNOOP
    442      sh    $25, (audio_wet_gain)($24)
    443 @@audio_04001344:
    444     beqz  $1, @@audio_04001364
    445      andi  $1, $2, A_LEFT
    446     beqz  $1, @@audio_0400135c
    447      nop
    448     j     cmd_SPNOOP
    449      sh    $26, (audio_vol_left)($24)
    450 @@audio_0400135c:
    451     j     cmd_SPNOOP
    452      sh    $26, (audio_vol_right)($24)
    453 @@audio_04001364:
    454     beqz  $1, @@audio_0400137c
    455      srl   $1, $25, 16
    456     sh    $26, (audio_target_left)($24)
    457     sh    $1, (audio_rate_hi_left)($24)
    458     j     cmd_SPNOOP
    459      sh    $25, (audio_rate_lo_left)($24)
    460 @@audio_0400137c:
    461     sh    $26, (audio_target_right)($24)
    462     sh    $1, (audio_rate_hi_right)($24)
    463 .endif
    464     j     cmd_SPNOOP
    465      sh    $25, (audio_rate_lo_right)($24)
    466 
    467 cmd_INTERLEAVE:
    468 .ifdef VERSION_SH_CN
    469     andi  $a0, $k0, 0xffff
    470     srl   $at, $k0, 12
    471     andi  $at, $at, 0xff0
    472     andi  $v1, $t9, 0xffff
    473     srl   $v0, $t9, 16
    474 @@audio_040013a8:
    475     ldv   $v1[0], 0x0($2)
    476     ldv   $v2[0], 0x0($3)
    477     addi  $at, $at, -8
    478     addi  $a0, $a0, 16
    479     ssv   $v1[0], 0xF0($4)
    480     ssv   $v1[2], 0xF4($4)
    481     addi  $v0, $v0, 8
    482     ssv   $v1[4], 0xF8($4)
    483     ssv   $v1[6], 0xFC($4)
    484     ssv   $v2[0], 0xF2($4)
    485     addi  $v1, $v1, 8
    486     ssv   $v2[2], 0xF6($4)
    487     ssv   $v2[4], 0xFA($4)
    488 .else
    489     lhu   $1, (audio_count)($24)
    490     lhu   $4, (audio_out_buf)($24)
    491     beqz  $1, cmd_SPNOOP
    492      andi  $3, $25, 0xffff
    493     addi  $3, $3, dmemBase
    494     srl   $2, $25, 16
    495     addi  $2, $2, dmemBase
    496 @@audio_040013a8:
    497     lqv   $v1[0], 0x00($2)
    498     lqv   $v2[0], 0x00($3)
    499     ssv   $v1[0], 0x00($4)
    500     ssv   $v2[0], 0x02($4)
    501     ssv   $v1[2], 0x04($4)
    502     ssv   $v2[2], 0x06($4)
    503     ssv   $v1[4], 0x08($4)
    504     ssv   $v2[4], 0x0a($4)
    505     ssv   $v1[6], 0x0c($4)
    506     ssv   $v2[6], 0x0e($4)
    507     ssv   $v1[8], 0x10($4)
    508     ssv   $v2[8], 0x12($4)
    509     ssv   $v1[10], 0x14($4)
    510     ssv   $v2[10], 0x16($4)
    511     ssv   $v1[12], 0x18($4)
    512     ssv   $v2[12], 0x1a($4)
    513     ssv   $v1[14], 0x1c($4)
    514     ssv   $v2[14], 0x1e($4)
    515     addi  $1, $1, -0x10
    516     addi  $2, $2, 0x10
    517     addi  $3, $3, 0x10
    518 .endif
    519     bgtz  $1, @@audio_040013a8
    520 .ifdef VERSION_SH_CN
    521      ssv   $v2[6], 0xFE($a0)
    522 .else
    523      addi  $4, $4, 0x20
    524 .endif
    525     j     cmd_SPNOOP
    526      nop
    527 
    528 cmd_DMEMMOVE:
    529     andi  $1, $25, 0xffff
    530     beqz  $1, cmd_SPNOOP
    531      andi  $2, $26, 0xffff
    532 .ifndef VERSION_SH_CN
    533     addi  $2, $2, dmemBase
    534 .endif
    535     srl   $3, $25, 16
    536 .ifndef VERSION_SH_CN
    537     addi  $3, $3, dmemBase
    538 .endif
    539 @@audio_04001424:
    540     ldv   $v1[0], 0x0($2)
    541     ldv   $v2[0], 0x8($2)
    542     addi  $1, $1, -0x10
    543     addi  $2, $2, 0x10
    544     sdv   $v1[0], 0x0($3)
    545     sdv   $v2[0], 0x8($3)
    546     bgtz  $1, @@audio_04001424
    547      addi  $3, $3, 0x10
    548     j     cmd_SPNOOP
    549      nop
    550 
    551 cmd_SETLOOP:
    552     sll   $1, $25, 8
    553     srl   $1, $1, 8
    554 .ifndef VERSION_SH_CN
    555     srl   $3, $25, 24
    556     sll   $3, $3, 2
    557     lw    $2, (segmentTable)($3)
    558     add   $1, $1, $2
    559     sw    $1, (audio_loop_value)($24)
    560 .endif
    561     j     cmd_SPNOOP
    562 .ifdef VERSION_SH_CN
    563      sw    $at, 0x10($t8)
    564 .else
    565      nop
    566 .endif
    567 
    568 cmd_ADPCM:
    569     lqv   $v31[0], 0x00($zero)
    570     vxor  $v27, $v27, $v27
    571     lhu   $21, (audio_in_buf)($24)
    572     vxor  $v25, $v25, $v25
    573     vxor  $v24, $v24, $v24
    574     addi  $20, $21, 1
    575     lhu   $19, (audio_out_buf)($24)
    576     vxor  $v13, $v13, $v13
    577     vxor  $v14, $v14, $v14
    578     lhu   $18, (audio_count)($24)
    579     vxor  $v15, $v15, $v15
    580 .ifndef VERSION_SH_CN
    581     lui   $1, 0x00ff
    582 .endif
    583     vxor  $v16, $v16, $v16
    584 .ifdef VERSION_SH_CN
    585     sll   $s1, $t9, 8
    586 .else
    587     ori   $1, $1, 0xffff
    588 .endif
    589     vxor  $v17, $v17, $v17
    590 .ifndef VERSION_SH_CN
    591     and   $17, $25, $1
    592 .endif
    593     vxor  $v18, $v18, $v18
    594 .ifdef VERSION_SH_CN
    595     srl   $s1, $s1, 8
    596 .else
    597     srl   $2, $25, 24
    598 .endif
    599     vxor  $v19, $v19, $v19
    600 .ifndef VERSION_SH_CN
    601     sll   $2, $2, 2
    602     lw    $3, (segmentTable)($2)
    603     add   $17, $17, $3          // last frame addr
    604 .endif
    605     sqv   $v27[0], 0x00($19)
    606     sqv   $v27[0], 0x10($19)
    607     srl   $1, $26, 16
    608     andi  $1, $1, A_INIT
    609     bgtz  $1, @@audio_0400150c
    610      srl   $1, $26, 16
    611     andi  $1, $1, A_LOOP
    612     beq   $zero, $1, @@audio_040014f0
    613      addi  $2, $17, 0x00
    614     lw    $2, (audio_loop_value)($24)
    615 @@audio_040014f0:
    616     addi  $1, $19, 0x0000
    617     jal   dma_read_start
    618      addi  $3, $zero, 0x1f
    619 @@dma_read_busy:
    620     mfc0  $5, SP_DMA_BUSY
    621     bnez  $5, @@dma_read_busy
    622      nop
    623     mtc0  $zero, SP_SEMAPHORE
    624 @@audio_0400150c:
    625 .ifdef VERSION_SH_CN
    626     addi  $16, $zero, 0x0050
    627 .else
    628     addi  $16, $zero, 0x0030
    629 .endif
    630     addi  $15, $zero, adpcmTable
    631     ldv   $v25[0], 0x00($16)
    632     ldv   $v24[8], 0x00($16)
    633     ldv   $v23[0], 0x08($16)
    634     ldv   $v23[8], 0x08($16)
    635     lqv   $v27[0], 0x10($19)    // last 8 frames
    636     addi  $19, $19, 0x20
    637     beqz  $18, @@audio_040016e8
    638      ldv   $v1[0], 0x00($20)
    639     lbu   $1, 0x00($21)
    640     andi  $11, $1, 0x000f
    641     sll   $11, $11, 5
    642     vand  $v3, $v25, $v1[0]
    643     add   $13, $11, $15
    644     vand  $v4, $v24, $v1[1]
    645     srl   $14, $1, 4
    646     vand  $v5, $v25, $v1[2]
    647     addi  $2, $zero, 12
    648     vand  $v6, $v24, $v1[3]
    649     sub   $14, $2, $14
    650     addi  $2, $14, -1
    651     addi  $3, $zero, 1
    652     sll   $3, $3, 15
    653     srlv  $4, $3, $2
    654     mtc2  $4, $v22[0]
    655     lqv   $v21[0], 0x00($13)
    656     lqv   $v20[0], 0x10($13)
    657     addi  $13, $13, -2
    658     lrv   $v19[0], 0x20($13)
    659     addi  $13, $13, -2
    660     lrv   $v18[0], 0x20($13)
    661     addi  $13, $13, -2
    662     lrv   $v17[0], 0x20($13)
    663     addi  $13, $13, -2
    664     lrv   $v16[0], 0x20($13)
    665     addi  $13, $13, -2
    666     lrv   $v15[0], 0x20($13)
    667     addi  $13, $13, -2
    668     lrv   $v14[0], 0x20($13)
    669     addi  $13, $13, -2
    670     lrv   $v13[0], 0x20($13)
    671 @@audio_040015b4:
    672     addi  $20, $20, 9
    673     vmudn $v30, $v3, $v23
    674     addi  $21, $21, 9
    675     vmadn $v30, $v4, $v23
    676     ldv   $v1[0], 0x00($20)
    677     vmudn $v29, $v5, $v23
    678     lbu   $1, 0x00($21)
    679     vmadn $v29, $v6, $v23
    680     blez  $14, @@audio_040015e4
    681      andi  $11, $1, 0x000f
    682     vmudm $v30, $v30, $v22[0]
    683     vmudm $v29, $v29, $v22[0]
    684 @@audio_040015e4:
    685     sll   $11, $11, 5
    686     vand  $v3, $v25, $v1[0]
    687     add   $13, $11, $15
    688     vand  $v4, $v24, $v1[1]
    689     vand  $v5, $v25, $v1[2]
    690     vand  $v6, $v24, $v1[3]
    691     srl   $14, $1, 4
    692     vmudh $v2, $v21, $v27[6]
    693     addi  $2, $zero, 12
    694     vmadh $v2, $v20, $v27[7]
    695     sub   $14, $2, $14
    696     vmadh $v2, $v19, $v30[0]
    697     addi  $2, $14, -1
    698     vmadh $v2, $v18, $v30[1]
    699     addi  $3, $zero, 1
    700     vmadh $v2, $v17, $v30[2]
    701     sll   $3, $3, 15
    702     vmadh $v2, $v16, $v30[3]
    703     srlv  $4, $3, $2
    704     vmadh $v28, $v15, $v30[4]
    705     mtc2  $4, $v22[0]
    706     vmadh $v2, $v14, $v30[5]
    707     vmadh $v2, $v13, $v30[6]
    708     vmadh $v2, $v30, $v31[5]
    709     vsar  $v26, $v7, $v28[1]
    710     vsar  $v28, $v7, $v28[0]
    711     vmudn $v2, $v26, $v31[4]
    712     vmadh $v28, $v28, $v31[4]
    713     vmudh $v2, $v19, $v29[0]
    714     addi  $12, $13, -2
    715     vmadh $v2, $v18, $v29[1]
    716     lrv   $v19[0], 0x20($12)
    717     vmadh $v2, $v17, $v29[2]
    718     addi  $12, $12, -2
    719     vmadh $v2, $v16, $v29[3]
    720     lrv   $v18[0], 0x20($12)
    721     vmadh $v2, $v15, $v29[4]
    722     addi  $12, $12, -2
    723     vmadh $v2, $v14, $v29[5]
    724     lrv   $v17[0], 0x20($12)
    725     vmadh $v2, $v13, $v29[6]
    726     addi  $12, $12, -2
    727     vmadh $v2, $v29, $v31[5]
    728     lrv   $v16[0], 0x20($12)
    729     vmadh $v2, $v21, $v28[6]
    730     addi  $12, $12, -2
    731     vmadh $v2, $v20, $v28[7]
    732     lrv   $v15[0], 0x20($12)
    733     vsar  $v26, $v7, $v27[1]
    734     addi  $12, $12, -2
    735     vsar  $v27, $v7, $v27[0]
    736     lrv   $v14[0], 0x20($12)
    737     addi  $12, $12, -2
    738     lrv   $v13[0], 0x20($12)
    739     lqv   $v21[0], 0x00($13)
    740     vmudn $v2, $v26, $v31[4]
    741     lqv   $v20[0], 0x10($13)
    742     vmadh $v27, $v27, $v31[4]
    743     addi  $18, $18, -0x20
    744     sdv   $v28[0], 0x00($19)
    745     sdv   $v28[8], 0x08($19)
    746     sdv   $v27[0], 0x10($19)
    747     sdv   $v27[8], 0x18($19)
    748     bgtz  $18, @@audio_040015b4
    749      addi  $19, $19, 0x20
    750 @@audio_040016e8:
    751     addi  $1, $19, -0x20
    752     addi  $2, $17, 0x00
    753     jal   dma_write_start
    754      addi  $3, $zero, 0x1f
    755 @@dma_write_busy:
    756     mfc0  $5, SP_DMA_BUSY
    757     bnez  $5, @@dma_write_busy
    758      nop
    759     j     cmd_SPNOOP
    760      mtc0  $zero, SP_SEMAPHORE
    761 
    762 cmd_POLEF: // unused by SM64
    763 .ifndef VERSION_SH_CN
    764     lqv   $v31[0], 0x0000($zero)
    765     vxor  $v28, $v28, $v28
    766     lhu   $21, (audio_in_buf)($24)
    767     vxor  $v17, $v17, $v17
    768     lhu   $20, (audio_out_buf)($24)
    769     vxor  $v18, $v18, $v18
    770     lhu   $19, (audio_count)($24)
    771     vxor  $v19, $v19, $v19
    772     beqz  $19, @@audio_04001874
    773      andi  $14, $26, 0xffff
    774     mtc2  $14, $v31[10]
    775     sll   $14, $14, 2
    776     mtc2  $14, $v16[0]
    777     lui   $1, 0x00ff
    778     vxor  $v20, $v20, $v20
    779     ori   $1, $1, 0xffff
    780     vxor  $v21, $v21, $v21
    781     and   $18, $25, $1
    782     vxor  $v22, $v22, $v22
    783     srl   $2, $25, 24
    784     vxor  $v23, $v23, $v23
    785     sll   $2, $2, 2
    786     lw    $3, (segmentTable)($2)
    787     add   $18, $18, $3
    788     slv   $v28[0], 0x00($23)
    789     srl   $1, $26, 16
    790     andi  $1, $1, 0x0001
    791     bgtz  $1, @@audio_040017a0
    792      nop
    793     addi  $1, $23, 0x0000
    794     addi  $2, $18, 0x0000
    795     jal   dma_read_start
    796      addi  $3, $zero, 7
    797 .endif
    798 @@dma_read_busy:
    799 .ifndef VERSION_SH_CN
    800     mfc0  $5, SP_DMA_BUSY
    801     bnez  $5, @@dma_read_busy
    802      nop
    803     mtc0  $zero, SP_SEMAPHORE
    804 .endif
    805 @@audio_040017a0:
    806 .ifndef VERSION_SH_CN
    807     addi  $13, $zero, adpcmTable
    808     addi  $1, $zero, 0x0004
    809     mtc2  $1, $v14[0]
    810     lqv   $v24[0], 0x0010($13)
    811     vmudm $v16, $v24, $v16[0]
    812     ldv   $v28[8], 0x00($23)
    813     sqv   $v16[0], 0x10($13)
    814     lqv   $v25[0], 0x00($13)
    815     addi  $13, $13, -2
    816     lrv   $v23[0], 0x20($13)
    817     addi  $13, $13, -2
    818     lrv   $v22[0], 0x20($13)
    819     addi  $13, $13, -2
    820     lrv   $v21[0], 0x20($13)
    821     addi  $13, $13, -2
    822     lrv   $v20[0], 0x20($13)
    823     addi  $13, $13, -2
    824     lrv   $v19[0], 0x20($13)
    825     addi  $13, $13, -2
    826     lrv   $v18[0], 0x20($13)
    827     addi  $13, $13, -2
    828     lrv   $v17[0], 0x20($13)
    829     ldv   $v30[0], 0x00($21)
    830     ldv   $v30[8], 0x08($21)
    831 .endif
    832 @@audio_04001800:
    833 .ifndef VERSION_SH_CN
    834     vmudh $v16, $v25, $v28[6]
    835     addi  $21, $21, 0x10
    836     vmadh $v16, $v24, $v28[7]
    837     addi  $19, $19, -0x10
    838     vmadh $v16, $v23, $v30[0]
    839     vmadh $v16, $v22, $v30[1]
    840     vmadh $v16, $v21, $v30[2]
    841     vmadh $v16, $v20, $v30[3]
    842     vmadh $v28, $v19, $v30[4]
    843     vmadh $v16, $v18, $v30[5]
    844     vmadh $v16, $v17, $v30[6]
    845     vmadh $v16, $v30, $v31[5]
    846     ldv   $v30[0], 0x00($21)
    847     vsar  $v26, $v15, $v28[1]
    848     ldv   $v30[8], 0x08($21)
    849     vsar  $v28, $v15, $v28[0]
    850     vmudn $v16, $v26, $v14[0]
    851     vmadh $v28, $v28, $v14[0]
    852     sdv   $v28[0], 0x00($20)
    853     sdv   $v28[8], 0x08($20)
    854     bgtz  $19, @@audio_04001800
    855      addi  $20, $20, 0x10
    856     addi  $1, $20, -8
    857     addi  $2, $18, 0x00
    858     jal   dma_write_start
    859      addi  $3, $zero, 7
    860 .endif
    861 @@dma_write_busy:
    862 .ifndef VERSION_SH_CN
    863     mfc0  $5, SP_DMA_BUSY
    864     bnez  $5, @@dma_write_busy
    865      nop
    866 .endif
    867 @@audio_04001874:
    868 .ifndef VERSION_SH_CN
    869     j     cmd_SPNOOP
    870      mtc0  $zero, SP_SEMAPHORE
    871 .endif
    872 
    873 cmd_RESAMPLE:
    874     lh    $8, (audio_in_buf)($24)
    875     lh    $19, (audio_out_buf)($24)
    876     lh    $18, (audio_count)($24)
    877 .ifdef VERSION_SH_CN
    878     sll   $v0, $t9, 8
    879     srl   $v0, $v0, 8
    880 .else
    881     lui   $4, 0x00ff
    882     ori   $4, $4, 0xffff
    883     and   $2, $25, $4
    884     srl   $5, $25, 24
    885     sll   $5, $5, 2
    886     lw    $6, (segmentTable)($5)
    887     add   $2, $2, $6          // physical address of state_addr
    888 .endif
    889     addi  $1, $23, 0x0000
    890     sw    $2, 0x40($23)       // overwrite TASK_UCODE ptr
    891     addi  $3, $zero, 0x1f
    892     srl   $7, $26, 16
    893     andi  $10, $7, A_INIT
    894     bgtz  $10, @@audio_040018dc
    895      nop
    896     jal   dma_read_start
    897      nop
    898 @@dma_read_busy:
    899     mfc0  $1, SP_DMA_BUSY
    900     bnez  $1, @@dma_read_busy
    901      nop
    902     j     @@audio_040018e8
    903      mtc0  $zero, SP_SEMAPHORE
    904 @@audio_040018dc:
    905     sh    $zero, 0x08($23)
    906     vxor  $v16, $v16, $v16
    907     sdv   $v16[0], 0x00($23)
    908 @@audio_040018e8:
    909     andi  $10, $7, 0x02      // A_LOOP? A_OUT?
    910     beqz  $10, @@audio_04001908
    911 .ifdef VERSION_SH_CN
    912      ldv   $v16[0], 0x00($23)
    913     addi  $t0, $t0, -4
    914     ssv   $v16[0], 0x00($t0)
    915     ssv   $v16[4], 0x02($t0)
    916     j     @@audio_c410c
    917      nop
    918 .else
    919      nop
    920     lh    $11, 0x0a($23)
    921     lqv   $v3[0], 0x10($23)
    922     sdv   $v3[0], -0x10($8)
    923     sdv   $v3[8], -0x08($8)
    924     sub   $8, $8, $11
    925 .endif
    926 
    927 @@audio_04001908:
    928 .ifdef VERSION_SH_CN
    929     andi  $t2, $a3, 4
    930     beqz  $t2, @@audio_c4104
    931      nop
    932     addi  $t0, $t0, -16
    933     ssv   $v16[0], 0x00($t0)
    934     ssv   $v16[0], 0x02($t0)
    935     ssv   $v16[2], 0x04($t0)
    936     ssv   $v16[2], 0x06($t0)
    937     ssv   $v16[4], 0x08($t0)
    938     ssv   $v16[4], 0x0a($t0)
    939     ssv   $v16[6], 0x0c($t0)
    940     ssv   $v16[6], 0x0e($t0)
    941     j     @@audio_c410c
    942      nop
    943 @@audio_c4104:
    944 .endif
    945     addi  $8, $8, -8
    946 .ifdef VERSION_SH_CN
    947     sdv   $v16[0], 0x00($8)
    948 .endif
    949 @@audio_c410c:
    950     lsv   $v23[14], 0x08($23)   // saved pitch_accumulator
    951 .ifdef VERSION_SH_CN
    952     ldv   $v16[0], 0x00($8)
    953 .else
    954     ldv   $v16[0], 0x00($23)    // saved next 4 unprocessed samples
    955     sdv   $v16[0], 0x00($8)     // store them before the input samples
    956 .endif
    957     mtc2  $8, $v18[4]
    958 .ifdef VERSION_SH_CN
    959     addi  $10, $zero, 0x100
    960 .else
    961     addi  $10, $zero, 0xc0
    962 .endif
    963     mtc2  $10, $v18[6]
    964     mtc2  $26, $v18[8]          // pitch
    965     addi  $10, $zero, 0x40
    966     mtc2  $10, $v18[10]
    967 .ifdef VERSION_SH_CN
    968     addi  $9, $zero, 0x60
    969 .else
    970     addi  $9, $zero, data0040
    971 .endif
    972     lqv   $v31[0], 0x10($9)     // 0x50
    973     lqv   $v25[0], 0x00($9)     // 0x40
    974     vsub  $v25, $v25, $v31
    975     lqv   $v30[0], 0x20($9)     // 0x60
    976     lqv   $v29[0], 0x30($9)     // 0x70
    977     lqv   $v28[0], 0x40($9)     // 0x80
    978     lqv   $v27[0], 0x50($9)     // 0x90
    979     lqv   $v26[0], 0x60($9)     // 0xA0
    980     vsub  $v25, $v25, $v31
    981     lqv   $v24[0], 0x70($9)     // 0xB0
    982     addi  $21, $23, 0x20
    983     addi  $20, $23, 0x30
    984     vxor  $v22, $v22, $v22
    985     vmudm $v23, $v31, $v23[7]   // load pitch_accumulator into every vector element
    986     vmadm $v22, $v25, $v18[4]   // (accumulate with pitch times index) >> 16
    987     vmadn $v23, $v31, $v30[0]   // result & 0xffff
    988     vmudn $v21, $v31, $v18[2]   // load the in address into every vector element
    989     vmadn $v21, $v22, $v30[2]   // accumulate with 2 * $v22
    990     vmudl $v17, $v23, $v18[5]   // 64 * $v23 >> 16
    991     vmudn $v17, $v17, $v30[4]   // * 8
    992     vmadn $v17, $v31, $v18[3]   // += 0x00c0 (resample lookup table address)
    993     lqv   $v25[0], 0x00($9)
    994     sqv   $v21[0], 0x00($21)
    995     sqv   $v17[0], 0x00($20)
    996     ssv   $v23[7], 0x08($23)
    997     lh    $17, 0x00($21)
    998     lh    $9, 0x00($20)
    999     lh    $13, 0x08($21)
   1000     lh    $5, 0x08($20)
   1001     lh    $16, 0x02($21)
   1002     lh    $8, 0x02($20)
   1003     lh    $12, 0x0a($21)
   1004     lh    $4, 0x0a($20)
   1005     lh    $15, 0x04($21)
   1006     lh    $7, 0x04($20)
   1007     lh    $11, 0x0c($21)
   1008     lh    $3, 0x0c($20)
   1009     lh    $14, 0x06($21)
   1010     lh    $6, 0x06($20)
   1011     lh    $10, 0x0e($21)
   1012     lh    $2, 0x0e($20)
   1013 @@audio_040019d8:
   1014     ldv   $v16[0], 0x00($17)
   1015     vmudm $v23, $v31, $v23[7]
   1016     ldv   $v15[0], 0x00($9)
   1017     vmadh $v23, $v31, $v22[7]
   1018     ldv   $v16[8], 0x00($13)
   1019     vmadm $v22, $v25, $v18[4]
   1020     ldv   $v15[8], 0x00($5)
   1021     vmadn $v23, $v31, $v30[0]
   1022     ldv   $v14[0], 0x00($16)
   1023     vmudn $v21, $v31, $v18[2]
   1024     ldv   $v13[0], 0x00($8)
   1025     vmadn $v21, $v22, $v30[2]
   1026     ldv   $v14[8], 0x00($12)
   1027     vmudl $v17, $v23, $v18[5]
   1028     ldv   $v13[8], 0x00($4)
   1029     ldv   $v12[0], 0x00($15)
   1030     ldv   $v11[0], 0x00($7)
   1031     ldv   $v12[8], 0x00($11)
   1032     vmudn $v17, $v17, $v30[4]
   1033     ldv   $v11[8], 0x00($3)
   1034     ldv   $v10[0], 0x00($14)
   1035     ldv   $v9[0], 0x00($6)
   1036     vmadn $v17, $v31, $v18[3]
   1037     ldv   $v10[8], 0x00($10)
   1038     vmulf $v8, $v16, $v15
   1039     ldv   $v9[8], 0x00($2)
   1040     vmulf $v7, $v14, $v13
   1041     sqv   $v21[0], 0x00($21)
   1042     vmulf $v6, $v12, $v11
   1043     sqv   $v17[0], 0x00($20)
   1044     lh    $17, 0x00($21)
   1045     vmulf $v5, $v10, $v9
   1046     lh    $9, 0x00($20)
   1047     vadd  $v8, $v8, $v8[1q]
   1048     lh    $13, 0x08($21)
   1049     vadd  $v7, $v7, $v7[1q]
   1050     lh    $5, 0x08($20)
   1051     vadd  $v6, $v6, $v6[1q]
   1052     lh    $16, 0x02($21)
   1053     vadd  $v5, $v5, $v5[1q]
   1054     lh    $8, 0x02($20)
   1055     vadd  $v8, $v8, $v8[2h]
   1056     lh    $12, 0x0a($21)
   1057     vadd  $v7, $v7, $v7[2h]
   1058     lh    $4, 0x0a($20)
   1059     vadd  $v6, $v6, $v6[2h]
   1060     lh    $15, 0x04($21)
   1061     vadd  $v5, $v5, $v5[2h]
   1062     lh    $7, 0x04($20)
   1063     vmudn $v4, $v29, $v8[0h]
   1064     lh    $11, 0x0c($21)
   1065     vmadn $v4, $v28, $v7[0h]
   1066     lh    $3, 0x0c($20)
   1067     vmadn $v4, $v27, $v6[0h]
   1068     lh    $14, 0x06($21)
   1069     vmadn $v4, $v26, $v5[0h]
   1070     lh    $6, 0x06($20)
   1071     lh    $10, 0x0e($21)
   1072     addi  $18, $18, -0x10
   1073     sqv   $v4[0], 0x00($19)
   1074     blez  $18, @@audio_04001ad8
   1075      lh    $2, 0x0e($20)
   1076     j     @@audio_040019d8
   1077      addi  $19, $19, 0x0010
   1078 @@audio_04001ad8:
   1079     ssv   $v23[0], 0x08($23)
   1080     ldv   $v16[0], 0x00($17)
   1081     sdv   $v16[0], 0x00($23)
   1082 .ifndef VERSION_SH_CN
   1083     lh    $6, (audio_in_buf)($24)
   1084     addi  $17, $17, 8
   1085     sub   $5, $17, $6
   1086     andi  $4, $5, 0x000f
   1087     sub   $17, $17, $4
   1088     beqz  $4, @@audio_04001b04
   1089      addi $7, $zero, 0x10
   1090     sub   $4, $7, $4
   1091 @@audio_04001b04:
   1092     sh    $4, 0x0a($23)
   1093     ldv   $v3[0], 0x00($17)
   1094     ldv   $v3[8], 0x08($17)
   1095     sqv   $v3[0], 0x10($23)
   1096 .endif
   1097     lw    $2, 0x40($23)
   1098     addi  $1, $23, 0x00
   1099     jal   dma_write_start
   1100      addi  $3, $zero, 0x1f
   1101 @@dma_write_busy:
   1102     mfc0  $5, SP_DMA_BUSY
   1103     bnez  $5, @@dma_write_busy
   1104      nop
   1105     j     cmd_SPNOOP
   1106      mtc0  $zero, SP_SEMAPHORE
   1107 
   1108 .ifdef VERSION_SH_CN
   1109 cmd_DMEMMOVE2:
   1110     srl   $t7, $k0, 16
   1111     andi  $t7, $t7, 0xff
   1112     andi  $t5, $k0, 0xffff
   1113     srl   $t6, $t9, 0x10
   1114 @@audio_30C314:
   1115     addi  $t7, $t7, -1
   1116     andi  $t4, $t9, 0xffff
   1117 @@audio_30C31C:
   1118     lqv   $v1[0], 0x00($t5)
   1119     lqv   $v2[0], 0x10($t5)
   1120     addi  $t4, $t4, -0x20
   1121     addi  $t5, $t5, 0x20
   1122     sqv   $v1[0], 0x00($t6)
   1123     sqv   $v2[0], 0x10($t6)
   1124     bgtz  $t4, @@audio_30C31C
   1125      addi  $t6, $t6, 0x20
   1126     bgtz  $t7, @@audio_30C314
   1127      nop
   1128     j cmd_SPNOOP
   1129      nop
   1130 
   1131 cmd_DUPLICATE:
   1132     srl   $t7, $k0, 0x10
   1133     andi  $t7, $t7, 0xff
   1134     andi  $t5, $k0, 0xffff
   1135     srl   $t6, $t9, 0x10
   1136     lqv   $v1[0], 0x00($t5)
   1137     lqv   $v2[0], 0x10($t5)
   1138     lqv   $v3[0], 0x20($t5)
   1139     lqv   $v4[0], 0x30($t5)
   1140     lqv   $v5[0], 0x40($t5)
   1141     lqv   $v6[0], 0x50($t5)
   1142     lqv   $v7[0], 0x60($t5)
   1143     lqv   $v8[0], 0x70($t5)
   1144 @@audio_30C37C:
   1145     addi  $t7, $t7, -1
   1146     sqv   $v1[0], 0x00($t6)
   1147     sqv   $v2[0], 0x10($t6)
   1148     sqv   $v3[0], 0x20($t6)
   1149     sqv   $v4[0], 0x30($t6)
   1150     sqv   $v5[0], 0x40($t6)
   1151     sqv   $v6[0], 0x50($t6)
   1152     sqv   $v7[0], 0x60($t6)
   1153     sqv   $v8[0], 0x70($t6)
   1154     bgtz  $t7, @@audio_30C37C
   1155      addi $t6, $t6, 0x80
   1156     j cmd_SPNOOP
   1157      nop
   1158 
   1159 cmd_DOWNSAMPLE_HALF:
   1160     andi  $t4, $k0, 0xffff
   1161     andi  $t6, $t9, 0xffff
   1162     srl   $t5, $t9, 0x10
   1163 @@audio_30C3BC:
   1164     lsv   $v1[0], 0x00($t5)
   1165     lsv   $v2[0], 0x08($t5)
   1166     lsv   $v3[0], 0x10($t5)
   1167     lsv   $v4[0], 0x18($t5)
   1168     lsv   $v1[2], 0x04($t5)
   1169     lsv   $v2[2], 0x0c($t5)
   1170     lsv   $v3[2], 0x14($t5)
   1171     lsv   $v4[2], 0x1c($t5)
   1172     addi  $t5, $t5, 0x20
   1173     slv   $v1[0], 0x00($t6)
   1174     slv   $v2[0], 0x04($t6)
   1175     slv   $v3[0], 0x08($t6)
   1176     addi  $t4, $t4, -8
   1177     slv   $v4[0], 0x0c($t6)
   1178     bgtz  $t4, @@audio_30C3BC
   1179      addi $t6, $t6, 0x10
   1180     j cmd_SPNOOP
   1181      nop
   1182 .endif
   1183 
   1184 .ifndef VERSION_SH_CN
   1185 cmd_ENVMIXER:
   1186     lui   $4, 0x00ff
   1187     ori   $4, $4, 0xffff
   1188     and   $2, $25, $4
   1189     srl   $5, $25, 24
   1190     sll   $5, $5, 2
   1191     lw    $6, (segmentTable)($5)
   1192     add   $2, $2, $6
   1193     addi  $1, $23, 0x00
   1194     addi  $3, $zero, 0x4f
   1195     vxor  $v0, $v0, $v0
   1196     addi  $11, $zero, 0x40
   1197     lqv   $v31[0], 0x10($11)    // all 0001
   1198     lqv   $v10[0], 0x00($zero)  // element 6 is 0x7fff
   1199     srl   $12, $26, 16
   1200     andi  $10, $12, A_INIT
   1201     beqz  $10, @@audio_04001b84
   1202      lqv   $v24[0], 0x10($24)
   1203     j     @@audio_04001bb0
   1204      nop
   1205 @@audio_04001b84:
   1206     jal   dma_read_start
   1207      nop
   1208 @@dma_read_busy:
   1209     mfc0  $5, SP_DMA_BUSY
   1210     bnez  $5, @@dma_read_busy
   1211      nop
   1212     mtc0  $zero, SP_SEMAPHORE
   1213     lqv   $v20[0], 0x00($23)
   1214     lqv   $v21[0], 0x10($23)
   1215     lqv   $v18[0], 0x20($23)
   1216     lqv   $v19[0], 0x30($23)
   1217     lqv   $v24[0], 0x40($23)
   1218 @@audio_04001bb0:
   1219     lh    $13, (audio_in_buf)($24)
   1220     lh    $19, (audio_out_buf)($24)
   1221     lh    $18, (audio_aux_buf0)($24)
   1222     lh    $17, (audio_aux_buf1)($24)
   1223     lh    $16, (audio_aux_buf2)($24)
   1224     lh    $14, (audio_count)($24)
   1225     addi  $15, $zero, 0x10
   1226     mfc2  $21, $v24[2]
   1227     mfc2  $20, $v24[8]
   1228     andi  $9, $12, 0x0008
   1229     bgtz  $9, @@audio_04001bec
   1230      nop
   1231     addi  $17, $23, 0x50
   1232     add   $16, $zero, $17
   1233     addi  $15, $zero, 0
   1234 @@audio_04001bec:
   1235     beqz  $10, @@audio_04001cf0
   1236      lqv   $v30[0], 0x70($11)
   1237     lqv   $v17[0], 0x00($13)
   1238     lqv   $v29[0], 0x00($19)
   1239     lqv   $v27[0], 0x00($17)
   1240     vxor  $v21, $v21, $v21
   1241     lsv   $v20[14], 0x06($24)
   1242     vmudm $v23, $v20, $v24[2]
   1243     vmadh $v22, $v20, $v24[1]
   1244     vmadn $v23, $v31, $v0[0]
   1245     vsubc $v23, $v23, $v21
   1246     vsub  $v22, $v22, $v20
   1247     vmudl $v23, $v30, $v23[7]
   1248     vmadn $v23, $v30, $v22[7]
   1249     vmadm $v22, $v31, $v0[0]
   1250     vmadm $v21, $v31, $v21[7]
   1251     vmadh $v20, $v31, $v20[7]
   1252     bgtz  $21, @@audio_04001c44
   1253      vmadn $v21, $v31, $v0[0]
   1254     vge   $v20, $v20, $v24[0]
   1255     j     @@audio_04001c48
   1256      nop
   1257 @@audio_04001c44:
   1258     vcl   $v20, $v20, $v24[0]
   1259 @@audio_04001c48:
   1260     vmulf $v16, $v20, $v24[6]
   1261     vmulf $v15, $v20, $v24[7]
   1262     vmulf $v29, $v29, $v10[6]
   1263     vmacf $v29, $v17, $v16
   1264     vmulf $v27, $v27, $v10[6]
   1265     vmacf $v27, $v17, $v15
   1266     sqv   $v29[0], 0x00($19)
   1267     sqv   $v27[0], 0x00($17)
   1268     lqv   $v28[0], 0x00($18)
   1269     lqv   $v26[0], 0x00($16)
   1270     vxor  $v19, $v19, $v19
   1271     lsv   $v18[14], 0x08($24)
   1272     vmudm $v23, $v18, $v24[5]
   1273     vmadh $v22, $v18, $v24[4]
   1274     vmadn $v23, $v31, $v0[0]
   1275     vsubc $v23, $v23, $v19
   1276     vsub  $v22, $v22, $v18
   1277     vmudl $v23, $v30, $v23[7]
   1278     vmadn $v23, $v30, $v22[7]
   1279     vmadm $v22, $v31, $v0[0]
   1280     vmadm $v19, $v31, $v19[7]
   1281     vmadh $v18, $v31, $v18[7]
   1282     bgtz  $20, @@audio_04001cb4
   1283      vmadn $v19, $v31, $v0[0]
   1284     vge   $v18, $v18, $v24[3]
   1285     j     @@audio_04001cb8
   1286      nop
   1287 @@audio_04001cb4:
   1288     vcl   $v18, $v18, $v24[3]
   1289 @@audio_04001cb8:
   1290     vmulf $v16, $v18, $v24[6]
   1291     vmulf $v15, $v18, $v24[7]
   1292     vmulf $v28, $v28, $v10[6]
   1293     vmacf $v28, $v17, $v16
   1294     vmulf $v26, $v26, $v10[6]
   1295     vmacf $v26, $v17, $v15
   1296     sqv   $v28[0], 0x00($18)
   1297     sqv   $v26[0], 0x00($16)
   1298     addi  $14, $14, -0x10
   1299     addi  $13, $13, 0x10
   1300     addi  $19, $19, 0x10
   1301     addi  $18, $18, 0x10
   1302     add   $17, $17, $15
   1303     add   $16, $16, $15
   1304 @@audio_04001cf0:
   1305     vmudl $v23, $v21, $v24[2]
   1306     vmadm $v23, $v20, $v24[2]
   1307     vmadn $v23, $v21, $v24[1]
   1308     vmadh $v20, $v20, $v24[1]
   1309     vmadn $v21, $v31, $v0[0]
   1310 @@audio_04001d04:
   1311     bgtz  $21, @@audio_04001d30
   1312      lqv   $v17[0], 0x00($13)
   1313     vge   $v20, $v20, $v24[0]
   1314     vmudl $v23, $v19, $v24[5]
   1315     vmadm $v23, $v18, $v24[5]
   1316     vmadn $v23, $v19, $v24[4]
   1317     lqv   $v29[0], 0x00($19)
   1318     vmadh $v18, $v18, $v24[4]
   1319     lqv   $v27[0], 0x00($17)
   1320     j     @@audio_04001d50
   1321      vmadn $v19, $v31, $v0[0]
   1322 @@audio_04001d30:
   1323     vcl   $v20, $v20, $v24[0]
   1324     vmudl $v23, $v19, $v24[5]
   1325     vmadm $v23, $v18, $v24[5]
   1326     vmadn $v23, $v19, $v24[4]
   1327     lqv   $v29[0], 0x00($19)
   1328     vmadh $v18, $v18, $v24[4]
   1329     lqv   $v27[0], 0x00($17)
   1330     vmadn $v19, $v31, $v0[0]
   1331 @@audio_04001d50:
   1332     vmulf $v16, $v20, $v24[6]
   1333     sqv   $v20[0], 0x00($23)
   1334     vmulf $v15, $v20, $v24[7]
   1335     sqv   $v21[0], 0x10($23)
   1336     vmulf $v29, $v29, $v10[6]
   1337     vmacf $v29, $v17, $v16
   1338     lqv   $v28[0], 0x00($18)
   1339     vmulf $v27, $v27, $v10[6]
   1340     lqv   $v26[0], 0x00($16)
   1341     vmacf $v27, $v17, $v15
   1342     bgtz  $20, @@audio_04001da0
   1343      sqv   $v29[0], 0x00($19)
   1344     vge   $v18, $v18, $v24[3]
   1345     vmudl $v23, $v21, $v24[2]
   1346     sqv   $v27[0], 0x00($17)
   1347     vmadm $v23, $v20, $v24[2]
   1348     vmadn $v23, $v21, $v24[1]
   1349     vmadh $v20, $v20, $v24[1]
   1350     j     @@audio_04001dbc
   1351      vmadn $v21, $v31, $v0[0]
   1352 @@audio_04001da0:
   1353     vcl   $v18, $v18, $v24[3]
   1354     vmudl $v23, $v21, $v24[2]
   1355     sqv   $v27[0], 0x00($17)
   1356     vmadm $v23, $v20, $v24[2]
   1357     vmadn $v23, $v21, $v24[1]
   1358     vmadh $v20, $v20, $v24[1]
   1359     vmadn $v21, $v31, $v0[0]
   1360 @@audio_04001dbc:
   1361     vmulf $v16, $v18, $v24[6]
   1362     addi  $14, $14, -0x10
   1363     vmulf $v15, $v18, $v24[7]
   1364     addi  $19, $19, 0x10
   1365     vmulf $v28, $v28, $v10[6]
   1366     add   $17, $17, $15
   1367     vmacf $v28, $v17, $v16
   1368     addi  $13, $13, 0x10
   1369     vmulf $v26, $v26, $v10[6]
   1370     vmacf $v26, $v17, $v15
   1371     sqv   $v28[0], 0x00($18)
   1372     addi  $18, $18, 0x10
   1373     blez  $14, @@audio_04001dfc
   1374      sqv   $v26[0], 0x00($16)
   1375     j     @@audio_04001d04
   1376      add   $16, $16, $15
   1377 @@audio_04001dfc:
   1378     sqv   $v18[0], 0x20($23)
   1379     sqv   $v19[0], 0x30($23)
   1380     sqv   $v24[0], 0x40($23)
   1381     jal   dma_write_start
   1382      addi  $3, $zero, 0x004f
   1383 @@dma_write_busy:
   1384     mfc0  $5, SP_DMA_BUSY
   1385     bnez  $5, @@dma_write_busy
   1386      nop
   1387     j     cmd_SPNOOP
   1388      mtc0  $zero, SP_SEMAPHORE
   1389 
   1390 cmd_MIXER:
   1391     lqv   $v31[0], 0x00($zero)   // element 6 is 0x7fff
   1392     lhu   $18, (audio_count)($24)
   1393     beqz  $18, @@cmd_mixer_done  // skip operation when count is 0
   1394      nop
   1395     andi  $19, $25, 0xffff
   1396     addi  $19, $19, dmemBase     // dmemout + DMEM_BASE
   1397     srl   $20, $25, 16
   1398     addi  $20, $20, dmemBase     // dmemin + DMEM_BASE
   1399     andi  $17, $26, 0xffff
   1400     mtc2  $17, $v30[0]
   1401     lqv   $v27[0], 0x00($19)
   1402     lqv   $v29[0], 0x00($20)
   1403     lqv   $v26[0], 0x10($19)
   1404     lqv   $v28[0], 0x10($20)
   1405 @@audio_04001e5c:
   1406     vmulf $v27, $v27, $v31[6]
   1407     addi  $18, $18, -0x20
   1408     vmacf $v27, $v29, $v30[0]
   1409     addi  $20, $20, 0x20
   1410     sqv   $v27[0], 0x00($19)
   1411     vmulf $v26, $v26, $v31[6]
   1412     lqv   $v29[0], 0x00($20)
   1413     vmacf $v26, $v28, $v30[0]
   1414     lqv   $v28[0], 0x10($20)
   1415     sqv   $v26[0], 0x10($19)
   1416     addi  $19, $19, 0x20
   1417     lqv   $v27[0], 0x00($19)
   1418     bgtz  $18, @@audio_04001e5c
   1419      lqv   $v26[0], 0x10($19)
   1420 @@cmd_mixer_done:
   1421     j     cmd_SPNOOP
   1422      nop
   1423     nop
   1424 .endif
   1425 
   1426 .ifdef VERSION_SH_CN
   1427 cmd_ENVMIXER:
   1428     vxor  $v4, $v4, $v4
   1429     vxor  $v0, $v0, $v0
   1430     lqv   $v3[0], 0x0(r0)
   1431     add   $21, $21, $21
   1432     mtc2  $21, $v4[0]
   1433     mtc2  $21, $v4[2]
   1434     srl   $12, $26, 12
   1435     andi  $19, $12, 0xff0
   1436     add   $22, $22, $22
   1437     mtc2  $22, $v4[4]
   1438     mtc2  $22, $v4[6]
   1439     srl   $12, $25, 20
   1440     andi  $14, $12, 0xff0
   1441     add   $11, $11, $11
   1442     mtc2  $11, $v4[8]
   1443     mtc2  $11, $v4[10]
   1444     srl   $12, $25, 12
   1445     andi  $15, $12, 0xff0
   1446     srl   $12, $25, 4
   1447     andi  $16, $12, 0xff0
   1448     sll   $12, $25, 4
   1449     andi  $17, $12, 0xff0
   1450     andi  $12, $26, 0x2
   1451     lhu   $12, 0xe0(r12)
   1452     mtc2  $12, $v2[0]
   1453     andi  $12, $26, 0x1
   1454     sll   $12, $12, 1
   1455     lhu   $12, 0xe0(r12)
   1456     mtc2  $12, $v2[2]
   1457     srl   $12, $26, 8
   1458     andi  $20, $12, 0xff
   1459     vadd  $v0, $v0, $v0
   1460     andi  $10, $26, 0x4
   1461     lqv   $v8[0], 0x0(r19)
   1462 
   1463 @audio_400196c:
   1464     lqv   $v15[0], 0x10(r19)
   1465     addi  $19, $19, 0x20
   1466     vmudm $v9, $v8, $v1[0]
   1467     vmudm $v10, $v8, $v1[2]
   1468     addi  $20, $20, 0xfff0
   1469     lqv   $v11[0], 0x0(r14)
   1470     lqv   $v12[0], 0x0(r15)
   1471     vmudm $v16, $v15, $v1[1]
   1472     vmudm $v17, $v15, $v1[3]
   1473     lqv   $v18[0], 0x10(r14)
   1474     lqv   $v19[0], 0x10(r15)
   1475     vxor  $v9, $v9, $v2[0]
   1476     vxor  $v10, $v10, $v2[1]
   1477     lqv   $v13[0], 0x0(r16)
   1478     lqv   $v14[0], 0x0(r17)
   1479     vadd  $v11, $v11, $v9
   1480     vadd  $v12, $v12, $v10
   1481     vmudm $v9, $v9, $v1[4]
   1482     vmudm $v10, $v10, $v1[4]
   1483     vxor  $v16, $v16, $v2[0]
   1484     vxor  $v17, $v17, $v2[1]
   1485     lqv   $v20[0], 0x10(r16)
   1486     lqv   $v21[0], 0x10(r17)
   1487     vadd  $v18, $v18, $v16
   1488     vadd  $v19, $v19, $v17
   1489     vmudm $v16, $v16, $v1[5]
   1490     vmudm $v17, $v17, $v1[5]
   1491     sqv   $v11[0], 0x0(r14)
   1492     bne   $10, $0, @audio_4001a34
   1493     sqv   $v12[0], 0x0(r15)
   1494     vadd  $v13, $v13, $v9
   1495     vadd  $v14, $v14, $v10
   1496     sqv   $v18[0], 0x10(r14)
   1497     sqv   $v19[0], 0x10(r15)
   1498     vadd  $v20, $v20, $v16
   1499     vadd  $v21, $v21, $v17
   1500 @audio_40019fc:
   1501     addi  $14, $14, 0x20
   1502     sqv   $v13[0], 0x0(r16)
   1503     sqv   $v14[0], 0x0(r17)
   1504     addi  $15, $15, 0x20
   1505     lqv   $v8[0], 0x0(r19)
   1506     sqv   $v20[0], 0x10(r16)
   1507     sqv   $v21[0], 0x10(r17)
   1508     addi  $16, $16, 0x20
   1509     vaddc $v1, $v1, $v4
   1510     addi  $17, $17, 0x20
   1511     bgtz  $20, @audio_400196c
   1512     vadd  $v0, $v0, $v0
   1513     j     cmd_SPNOOP
   1514      vxor $v0, $v0, $v0
   1515 @audio_4001a34:
   1516     vadd  $v13, $v13, $v10
   1517     vadd  $v14, $v14, $v9
   1518     sqv   $v18[0], 0x10(r14)
   1519     sqv   $v19[0], 0x10(r15)
   1520     vadd  $v20, $v20, $v17
   1521     j     @audio_40019fc
   1522      vadd $v21, $v21, $v16
   1523 
   1524 cmd_ENVSETUP1:
   1525     vxor  $v1, $v1, $v1
   1526     andi  $11, $26, 0xffff
   1527     srl   $12, $26, 8
   1528     andi  $12, $12, 0xff00
   1529     mtc2  $12, $v1[8]
   1530     add   $12, $12, $11
   1531     mtc2  $12, $v1[10]
   1532     srl   $21, $25, 16
   1533     j     cmd_SPNOOP
   1534      andi $22, $25, 0xffff
   1535 
   1536 cmd_ENVSETUP2:
   1537     srl   $12, $25, 16
   1538     mtc2  $12, $v1[0]
   1539     add   $12, $12, $21
   1540     mtc2  $12, $v1[2]
   1541     andi  $12, $25, 0xffff
   1542     mtc2  $12, $v1[4]
   1543     add   $12, $12, $22
   1544     j     cmd_SPNOOP
   1545      mtc2  $12, $v1[6]
   1546 
   1547 @audio_4001a9c:
   1548     srl   $3, $26, 12
   1549     andi  $3, $3, 0xff0
   1550     andi  $1, $26, 0xffff
   1551 @audio_4001aa8:
   1552     sll   $2, $25, 8
   1553     jr    $31
   1554      srl  $2, $2, 8
   1555 
   1556 cmd_LOADBUFF:
   1557     jal   @audio_4001a9c
   1558      nop
   1559     jal   dma_read_start
   1560      addi $3, $3, 0xffff
   1561 @audio_4001ac4:
   1562     mfc0  $1, sp_dma_busy
   1563     bne   $1, $0, @audio_4001ac4
   1564      nop
   1565     j     cmd_SPNOOP
   1566      mtc0 $0, sp_semaphore
   1567 
   1568 cmd_SAVEBUFF:
   1569     jal   @audio_4001a9c
   1570      nop
   1571     jal   dma_write_start
   1572      addi $3, $3, 0xffff
   1573     j     @audio_4001ac4
   1574      nop
   1575 
   1576 cmd_LOADADPCM:
   1577     jal   @audio_4001aa8
   1578      addi $1, $0, adpcmTable
   1579     andi  $3, $26, 0xffff
   1580     jal   dma_read_start
   1581      addi $3, $3, 0xffff
   1582     j     @audio_4001ac4
   1583      nop
   1584 
   1585 cmd_MIXER:
   1586     lqv   $v31[0], 0x0(r0)
   1587     srl   $18, $26, 12
   1588     andi  $18, $18, 0xff0
   1589     andi  $19, $25, 0xffff
   1590     srl   $20, $25, 16
   1591     andi  $17, $26, 0xffff
   1592     mtc2  $17, $v30[0]
   1593     lqv   $v27[0], 0x0(r19)
   1594     lqv   $v29[0], 0x0(r20)
   1595     lqv   $v26[0], 0x10(r19)
   1596     lqv   $v28[0], 0x10(r20)
   1597 @audio_4001b38:
   1598     vmulf $v27, $v27, $v31[6]
   1599     addi  $18, $18, 0xffe0
   1600     vmacf $v27, $v29, $v30[0]
   1601     addi  $20, $20, 0x20
   1602     vmulf $v26, $v26, $v31[6]
   1603     vmacf $v26, $v28, $v30[0]
   1604     lqv   $v29[0], 0x0(r20)
   1605     sqv   $v27[0], 0x0(r19)
   1606     lqv   $v27[0], 0x20(r19)
   1607     lqv   $v28[0], 0x10(r20)
   1608     sqv   $v26[0], 0x10(r19)
   1609     addi  $19, $19, 0x20
   1610     bgtz  $18, @audio_4001b38
   1611      lqv  $v26[0], 0x10(r19)
   1612     j cmd_SPNOOP
   1613      nop
   1614 
   1615 cmd_S8DEC:
   1616     lhu   $13, (audio_in_buf)(r24)
   1617     vxor  $v2, $v2, $v2
   1618     lhu   $14, (audio_out_buf)(r24)
   1619     vxor  $v3, $v3, $v3
   1620     lhu   $12, (audio_count)(r24)
   1621     sll   $17, $25, 8
   1622     srl   $17, $17, 8                   // state addr
   1623     sqv   $v2[0], 0x0(r14)              // store 0 to first 16 samples if A_INIT
   1624     sqv   $v3[0], 0x10(r14)
   1625     srl   $1, $26, 16
   1626     andi  $1, $1, 0x1
   1627     bgtz  $1, @audio_4001bd8            // A_INIT
   1628      srl  $1, $26, 16
   1629     andi  $1, $1, 0x2
   1630     beq   $0, $1, @audio_4001bbc        // A_LOOP
   1631      addi $2, $17, 0x0
   1632     lw    $2, (audio_loop_value)(r24)
   1633 @audio_4001bbc:
   1634     addi  $1, $14, 0x0
   1635     jal   dma_read_start
   1636      addi $3, $0, 0x1f
   1637 @audio_4001bc8:
   1638     mfc0  $5, sp_dma_busy
   1639     bne   $5, $0, @audio_4001bc8
   1640      nop
   1641     mtc0  $0, sp_semaphore
   1642 @audio_4001bd8:
   1643     addi  $14, $14, 0x20
   1644     beq   $12, $0, @audio_4001c04       // this of very few ops allows count=0
   1645      nop
   1646 @audio_4001be4:
   1647     lpv   $v2[0], 0x0(r13)              // load each byte to upper 8 bits per elem
   1648     lpv   $v3[0], 0x8(r13)
   1649     addi  $13, $13, 0x10
   1650     addi  $12, $12, 0xffe0
   1651     sqv   $v2[0], 0x0(r14)
   1652     sqv   $v3[0], 0x10(r14)
   1653     bgtz  $12, @audio_4001be4
   1654      addi $14, $14, 0x20
   1655 @audio_4001c04:
   1656     addi  $1, $14, 0xffe0               // write last 16 samples to the state
   1657     addi  $2, $17, 0x0
   1658     jal   dma_write_start
   1659      addi  $3, $0, 0x1f
   1660 @audio_4001c14:
   1661     mfc0  $5, sp_dma_busy
   1662     bne   $5, $0, @audio_4001c14
   1663      nop
   1664     j     cmd_SPNOOP
   1665      mtc0 $0, sp_semaphore
   1666 
   1667 cmd_HILOGAIN:
   1668     andi  $12, $26, 0xffff
   1669     srl   $13, $25, 16
   1670     srl   $15, $26, 4
   1671     andi  $15, $15, 0xf000
   1672     mtc2  $15, $v3[2]
   1673     srl   $15, $26, 20
   1674     andi  $15, $15, 0xf
   1675     mtc2  $15, $v3[0]
   1676 @audio_4001c48:
   1677     lqv   $v1[0], 0x0(r13)
   1678     lqv   $v2[0], 0x10(r13)
   1679     vmudm $v4, $v1, $v3[1]
   1680     vmadh $v4, $v1, $v3[0]
   1681     vmudm $v5, $v2, $v3[1]
   1682     vmadh $v5, $v2, $v3[0]
   1683     sqv   $v4[0], 0x0(r13)
   1684     sqv   $v5[0], 0x10(r13)
   1685     addi  $12, $12, 0xffe0
   1686     bgtz  $12, @audio_4001c48
   1687     addi  $13, $13, 0x20
   1688     j     cmd_SPNOOP
   1689      vxor $v0, $v0, $v0
   1690 
   1691 cmd_1c7c:
   1692     andi  $12, $26, 0xffff
   1693     srl   $13, $25, 16
   1694     addi  $14, $13, 0x0
   1695     andi  $15, $25, 0xffff
   1696     srl   $11, $26, 16
   1697     andi  $11, $11, 0xff
   1698     add   $15, $15, $11
   1699     ldv   $v11[0], 0x0(r15)
   1700     ldv   $v12[0], 0x10(r15)
   1701     ldv   $v13[0], 0x20(r15)
   1702     ldv   $v14[0], 0x30(r15)
   1703     ldv   $v11[8], 0x8(r15)
   1704     ldv   $v12[8], 0x18(r15)
   1705     ldv   $v13[8], 0x28(r15)
   1706     ldv   $v14[8], 0x38(r15)
   1707 @audio_4001cb8:
   1708     lqv   $v3[0], 0x0(r13)
   1709     lqv   $v4[0], 0x10(r13)
   1710     lqv   $v5[0], 0x20(r13)
   1711     lqv   $v6[0], 0x30(r13)
   1712     vmudh $v3, $v3, $v11
   1713     vmudh $v4, $v4, $v12
   1714     vmudh $v5, $v5, $v13
   1715     vmudh $v6, $v6, $v14
   1716     sqv   $v3[0], 0x0(r13)
   1717     sqv   $v4[0], 0x10(r13)
   1718     sqv   $v5[0], 0x20(r13)
   1719     sqv   $v6[0], 0x30(r13)
   1720     addi  $12, $12, 0xffc0
   1721     bgtz  $12, @audio_4001cb8
   1722      addi  $13, $13, 0x40
   1723     j     cmd_SPNOOP
   1724      nop
   1725 
   1726 cmd_FILTER:
   1727     addi  $13, $23, 0x0
   1728     vxor  $v0, $v0, $v0
   1729     addi  $14, $23, 0x10
   1730     sqv   $v0[0], 0x0(r13)
   1731     sll   $2, $25, 8
   1732     srl   $2, $2, 8
   1733     srl   $12, $26, 16
   1734     andi  $12, $12, 0xff
   1735     beq   $12, $0, @audio_4001d68
   1736      nop
   1737     addi  $12, $12, 0xffff
   1738     beq   $12, $0, @audio_4001d88
   1739      nop
   1740     andi  $15, $26, 0xffff
   1741     vxor  $v0, $v0, $v0
   1742     sqv   $v0[0], 0x0(r14)
   1743     sqv   $v0[0], 0x20(r14)
   1744     addi  $1, $14, 0x10
   1745     addi  $3, $0, 0xf
   1746     jal   dma_read_start
   1747      nop
   1748     mfc0  $5, sp_dma_busy
   1749     bne   $5, $0, 0x4001d50
   1750     nop
   1751     mtc0  $0, sp_semaphore
   1752     j     cmd_SPNOOP
   1753      nop
   1754 @audio_4001d68:
   1755     add   $1, $13, $0
   1756     addi  $3, $0, 0xf
   1757     jal   dma_read_start
   1758     nop
   1759 @audio_4001d78:
   1760     mfc0  $5, sp_dma_busy
   1761     bne   $5, $0, 0x4001d78
   1762      nop
   1763     mtc0  $0, sp_semaphore
   1764 @audio_4001d88:
   1765     add   $1, $13, $0
   1766     andi  $11, $26, 0xffff
   1767     lqv   $v24[0], 0x10(r14)
   1768     ldv   $v28[0], 0x8(r14)
   1769     ldv   $v28[8], 0x10(r14)
   1770     ldv   $v20[0], 0x18(r14)
   1771     ldv   $v20[8], 0x20(r14)
   1772     addi  $14, $14, 0x2
   1773     ldv   $v31[0], 0x0(r14)
   1774     ldv   $v31[8], 0x8(r14)
   1775     ldv   $v17[0], 0x10(r14)
   1776     ldv   $v17[8], 0x18(r14)
   1777     ldv   $v27[0], 0x8(r14)
   1778     ldv   $v27[8], 0x10(r14)
   1779     ldv   $v21[0], 0x18(r14)
   1780     ldv   $v21[8], 0x20(r14)
   1781     addi  $14, $14, 0x2
   1782     ldv   $v30[0], 0x0(r14)
   1783     ldv   $v30[8], 0x8(r14)
   1784     ldv   $v26[0], 0x8(r14)
   1785     ldv   $v26[8], 0x10(r14)
   1786     ldv   $v18[0], 0x10(r14)
   1787     ldv   $v18[8], 0x18(r14)
   1788     ldv   $v22[0], 0x18(r14)
   1789     ldv   $v22[8], 0x20(r14)
   1790     addi  $14, $14, 0x2
   1791     ldv   $v29[0], 0x0(r14)
   1792     ldv   $v29[8], 0x8(r14)
   1793     ldv   $v25[0], 0x8(r14)
   1794     ldv   $v25[8], 0x10(r14)
   1795     ldv   $v19[0], 0x10(r14)
   1796     ldv   $v19[8], 0x18(r14)
   1797     ldv   $v23[0], 0x18(r14)
   1798     ldv   $v23[8], 0x20(r14)
   1799     lqv   $v15[0], 0x0(r13)
   1800 @audio_4001e14:
   1801     lqv   $v16[0], 0x0(r11)
   1802     vxor  $v14, $v14, $v14
   1803     vmulf $v0, $v0, $v0
   1804     vmacf $v14, $v23, $v15[1]
   1805     vmacf $v14, $v22, $v15[2]
   1806     vmacf $v14, $v21, $v15[3]
   1807     vmacf $v14, $v20, $v15[4]
   1808     vmacf $v14, $v19, $v15[5]
   1809     vmacf $v14, $v18, $v15[6]
   1810     vmacf $v14, $v17, $v15[7]
   1811     vmacf $v14, $v24, $v16[0]
   1812     vmacf $v14, $v25, $v16[1]
   1813     vmacf $v14, $v26, $v16[2]
   1814     vmacf $v14, $v27, $v16[3]
   1815     vmacf $v14, $v28, $v16[4]
   1816     vmacf $v14, $v29, $v16[5]
   1817     vmacf $v14, $v30, $v16[6]
   1818     vmacf $v14, $v31, $v16[7]
   1819     addi  $15, $15, 0xfff0
   1820     sqv   $v14[0], 0x0(r11)
   1821     addi  $11, $11, 0x10
   1822     bgtz  $15, @audio_4001e14
   1823      vaddc $v15, $v0, $v16
   1824     sqv   $v16[0], 0x0(r13)
   1825     addi  $3, $0, 0xf
   1826     jal   dma_write_start
   1827      nop
   1828 @audio_4001e80:
   1829     mfc0 $5, sp_dma_busy
   1830     bne  $5, $0, @audio_4001e80
   1831     nop
   1832     mtc0 $0, sp_semaphore
   1833     j    cmd_SPNOOP
   1834      nop
   1835 
   1836 cmd_ADDMIXER:
   1837     vaddc $v31, $v31, $v31
   1838     srl   $18, $26, 12
   1839     andi  $18, $18, 0xff0
   1840     andi  $19, $25, 0xffff
   1841     srl   $20, $25, 16
   1842     lqv   $v27[0], 0x0(r19)
   1843 @audio_4001eb0:
   1844     lqv   $v29[0], 0x0(r20)
   1845     lqv   $v26[0], 0x10(r19)
   1846     lqv   $v28[0], 0x10(r20)
   1847     lqv   $v25[0], 0x20(r19)
   1848     lqv   $v23[0], 0x20(r20)
   1849     lqv   $v24[0], 0x30(r19)
   1850     lqv   $v22[0], 0x30(r20)
   1851     addi  $20, $20, 0x40
   1852     vadd  $v27, $v27, $v29
   1853     vadd  $v26, $v26, $v28
   1854     vadd  $v25, $v25, $v23
   1855     vadd  $v24, $v24, $v22
   1856     addi  $18, $18, 0xffc0
   1857     sqv   $v27[0], 0x0(r19)
   1858     sqv   $v26[0], 0x10(r19)
   1859     sqv   $v25[0], 0x20(r19)
   1860     sqv   $v24[0], 0x30(r19)
   1861     addi  $19, $19, 0x40
   1862     bgtz  $18, @audio_4001eb0
   1863      lqv  $v27[0], 0x0(r19)
   1864     j     cmd_SPNOOP
   1865      nop
   1866 
   1867 cmd_RESAMPLE_ZOH:
   1868     lh    $14, 0x0(r24)
   1869     lh    $15, 0x2(r24)
   1870     lh    $13, 0x4(r24)
   1871     andi  $12, $26, 0xffff
   1872     sll   $12, $12, 2
   1873     andi  $10, $25, 0xffff
   1874     sll   $14, $14, 16
   1875     or    $10, $10, $14
   1876 @audio_4001f28:
   1877     srl   $11, $10, 16
   1878     andi  $11, $11, 0xfffe
   1879     lsv   $v1[0], 0x0(r11)
   1880     add   $10, $10, $12
   1881     srl   $11, $10, 16
   1882     andi  $11, $11, 0xfffe
   1883     lsv   $v1[2], 0x0(r11)
   1884     add   $10, $10, $12
   1885     srl   $11, $10, 16
   1886     andi  $11, $11, 0xfffe
   1887     lsv   $v1[4], 0x0(r11)
   1888     add   $10, $10, $12
   1889     srl   $11, $10, 16
   1890     andi  $11, $11, 0xfffe
   1891     lsv   $v1[6], 0x0(r11)
   1892     add   $10, $10, $12
   1893     addi  $13, $13, 0xfff8
   1894     sdv   $v1[0], 0x0(r15)
   1895     addi  $15, $15, 0x8
   1896     bgtz  $13, @audio_4001f28
   1897      nop
   1898     jal   cmd_SPNOOP
   1899      nop
   1900 .endif
   1901 
   1902 .close // CODE_FILE