| 1 | /* DSP_MIXER -> PCM VOICE SOFTWARE PROCESSOR (8-16 Bits Mono/Stereo Voices) |
| 2 | |
| 3 | // Thanks to Duddie for you hard work and documentation |
| 4 | |
| 5 | Copyright (c) 2008 Hermes <www.entuwii.net> |
| 6 | All rights reserved. |
| 7 | |
| 8 | SPDX-License-Identifier: BSD-3-Clause |
| 9 | |
| 10 | */ |
| 11 | |
| 12 | #include "HermesText.h" |
| 13 | |
| 14 | const char s_hermes_text[21370] = R"( |
| 15 | /********************************/ |
| 16 | /** REGISTER NAMES **/ |
| 17 | /********************************/ |
| 18 | |
| 19 | AR0: equ 0x00 ; address registers |
| 20 | AR1: equ 0x01 |
| 21 | AR2: equ 0x02 |
| 22 | AR3: equ 0x03 // used as jump function selector |
| 23 | |
| 24 | IX0: equ 0x04 // LEFT_VOLUME accel |
| 25 | IX1: equ 0x05 // RIGHT_VOLUME accel |
| 26 | IX2: equ 0x06 // ADDRH_SMP accel |
| 27 | IX3: equ 0x07 // ADDRL_SMP accel |
| 28 | |
| 29 | R08: equ 0x08 // fixed to 48000 value |
| 30 | R09: equ 0x09 // problems using this |
| 31 | R0A: equ 0x0a // ADDREH_SMP accel |
| 32 | R0B: equ 0x0b // ADDREL_SMP accel |
| 33 | |
| 34 | ST0: equ 0x0c |
| 35 | ST1: equ 0x0d |
| 36 | ST2: equ 0x0e |
| 37 | ST3: equ 0x0f |
| 38 | |
| 39 | CONFIG: equ 0x12 |
| 40 | SR: equ 0x13 |
| 41 | |
| 42 | PRODL: equ 0x14 |
| 43 | PRODM: equ 0x15 |
| 44 | PRODH: equ 0x16 |
| 45 | PRODM2: equ 0x17 |
| 46 | |
| 47 | AXL0: equ 0x18 |
| 48 | AXL1: equ 0x19 |
| 49 | AXH0: equ 0x1A // SMP_R accel |
| 50 | AXH1: equ 0x1b // SMP_L accel |
| 51 | |
| 52 | ACC0: equ 0x20 // accumulator (global) |
| 53 | ACC1: equ 0x21 |
| 54 | |
| 55 | ACL0: equ 0x1c // Low accumulator |
| 56 | ACL1: equ 0x1d |
| 57 | ACM0: equ 0x1e // Mid accumulator |
| 58 | ACM1: equ 0x1f |
| 59 | ACH0: equ 0x10 // Sign extended 8 bit register 0 |
| 60 | ACH1: equ 0x11 // Sign extended 8 bit register 1 |
| 61 | |
| 62 | /********************************/ |
| 63 | /** HARDWARE REGISTER ADDRESS **/ |
| 64 | /********************************/ |
| 65 | |
| 66 | DSCR: equ 0xffc9 ; DSP DMA Control Reg |
| 67 | DSBL: equ 0xffcb ; DSP DMA Block Length |
| 68 | DSPA: equ 0xffcd ; DSP DMA DMEM Address |
| 69 | DSMAH: equ 0xffce ; DSP DMA Mem Address H |
| 70 | DSMAL: equ 0xffcf ; DSP DMA Mem Address L |
| 71 | |
| 72 | DIRQ: equ 0xfffb ; DSP Irq Request |
| 73 | DMBH: equ 0xfffc ; DSP Mailbox H |
| 74 | DMBL: equ 0xfffd ; DSP Mailbox L |
| 75 | CMBH: equ 0xfffe ; CPU Mailbox H |
| 76 | CMBL: equ 0xffff ; CPU Mailbox L |
| 77 | |
| 78 | DMA_TO_DSP: equ 0 |
| 79 | DMA_TO_CPU: equ 1 |
| 80 | |
| 81 | /**************************************************************/ |
| 82 | /* NUM_SAMPLES SLICE */ |
| 83 | /**************************************************************/ |
| 84 | |
| 85 | NUM_SAMPLES: equ 1024 ; 1024 stereo samples 16 bits |
| 86 | |
| 87 | |
| 88 | /**************************************************************/ |
| 89 | /* SOUND CHANNEL REGS */ |
| 90 | /**************************************************************/ |
| 91 | |
| 92 | MEM_REG2: equ 0x0 |
| 93 | MEM_VECTH: equ MEM_REG2 |
| 94 | MEM_VECTL: equ MEM_REG2+1 |
| 95 | RETURN: equ MEM_REG2+2 |
| 96 | |
| 97 | /**************************************************************/ |
| 98 | /* CHANNEL DATAS */ |
| 99 | /**************************************************************/ |
| 100 | |
| 101 | MEM_REG: equ MEM_REG2+0x10 |
| 102 | |
| 103 | ADDRH_SND: equ MEM_REG // Output buffer |
| 104 | ADDRL_SND: equ MEM_REG+1 |
| 105 | |
| 106 | DELAYH_SND: equ MEM_REG+2 // Delay samples High word |
| 107 | DELAYL_SND: equ MEM_REG+3 // Delay samples Low word |
| 108 | |
| 109 | CHAN_REGS: equ MEM_REG+4 // specific regs for the channel |
| 110 | |
| 111 | FLAGSH_SMP: equ CHAN_REGS+0 // contains number of bytes for step (1-> Mono 8 bits, 2-> Stereo 8 bits and Mono 16 bits, 4-> Stereo 16 bits) |
| 112 | FLAGSL_SMP: equ CHAN_REGS+1 // 0->Mono 8 bits, 1->Stereo 8 bits, 2->Mono 16 bits 3 -> Stereo 16 bits |
| 113 | |
| 114 | ADDRH_SMP: equ CHAN_REGS+2 // start address |
| 115 | ADDRL_SMP: equ CHAN_REGS+3 |
| 116 | |
| 117 | ADDREH_SMP: equ CHAN_REGS+4 // end address |
| 118 | ADDREL_SMP: equ CHAN_REGS+5 |
| 119 | |
| 120 | FREQH_SMP: equ CHAN_REGS+6 // Freq in Hz to play |
| 121 | FREQL_SMP: equ CHAN_REGS+7 |
| 122 | |
| 123 | SMP_L: equ CHAN_REGS+8 // last sample for left (used to joint various buffers) |
| 124 | SMP_R: equ CHAN_REGS+9 // last sample for right (used to joint various buffers) |
| 125 | |
| 126 | COUNTERH_SMP: equ CHAN_REGS+10 // pitch counter |
| 127 | COUNTERL_SMP: equ CHAN_REGS+11 |
| 128 | |
| 129 | LEFT_VOLUME: equ CHAN_REGS+12 // volume (0 to 255) |
| 130 | RIGHT_VOLUME: equ CHAN_REGS+13 |
| 131 | |
| 132 | ADDR2H_SMP: equ CHAN_REGS+14 // start address of buffer two (to joint) |
| 133 | ADDR2L_SMP: equ CHAN_REGS+15 |
| 134 | |
| 135 | ADDR2EH_SMP: equ CHAN_REGS+16 // end address of buffer two (to joint) |
| 136 | ADDR2EL_SMP: equ CHAN_REGS+17 |
| 137 | |
| 138 | LEFT_VOLUME2: equ CHAN_REGS+18 // volume (0 to 255) for buffer two |
| 139 | RIGHT_VOLUME2: equ CHAN_REGS+19 |
| 140 | |
| 141 | BACKUPH_SMP: equ CHAN_REGS+20 // start address backup |
| 142 | BACKUPL_SMP: equ CHAN_REGS+21 |
| 143 | |
| 144 | /**************************************************************/ |
| 145 | /* VOICE SAMPLE BUFFER DATAS */ |
| 146 | /**************************************************************/ |
| 147 | |
| 148 | MEM_SAMP: equ CHAN_REGS+0x20 |
| 149 | |
| 150 | |
| 151 | data_end: equ MEM_SAMP+0x20 |
| 152 | |
| 153 | /**************************************************************/ |
| 154 | /* SND OUTPUT DATAS */ |
| 155 | /**************************************************************/ |
| 156 | |
| 157 | MEM_SND: equ data_end ; it need 2048 words (4096 bytes) |
| 158 | |
| 159 | |
| 160 | |
| 161 | /*** START CODE ***/ |
| 162 | |
| 163 | /**************************************************************/ |
| 164 | /* EXCEPTION TABLE */ |
| 165 | /**************************************************************/ |
| 166 | |
| 167 | jmp exception0 |
| 168 | jmp exception1 |
| 169 | jmp exception2 |
| 170 | jmp exception3 |
| 171 | jmp exception4 |
| 172 | jmp exception5 |
| 173 | jmp exception6 |
| 174 | jmp exception7 |
| 175 | |
| 176 | lri $CONFIG, #0xff |
| 177 | lri $SR,#0 |
| 178 | s16 |
| 179 | clr15 |
| 180 | m0 |
| 181 | |
| 182 | /**************************************************************/ |
| 183 | /* main */ |
| 184 | /**************************************************************/ |
| 185 | |
| 186 | main: |
| 187 | |
| 188 | // send init token to CPU |
| 189 | |
| 190 | si @DMBH, #0xdcd1 |
| 191 | si @DMBL, #0x0000 |
| 192 | si @DIRQ, #1 |
| 193 | |
| 194 | recv_cmd: |
| 195 | // check if previous mail is received from the CPU |
| 196 | |
| 197 | call wait_for_dsp_mail |
| 198 | |
| 199 | // wait a mail from CPU |
| 200 | |
| 201 | call wait_for_cpu_mail |
| 202 | |
| 203 | si @DMBH, #0xdcd1 |
| 204 | |
| 205 | clr $ACC0 |
| 206 | lri $ACM0,#0xcdd1 |
| 207 | cmp |
| 208 | jz sys_command |
| 209 | |
| 210 | clr $ACC1 |
| 211 | lrs $ACM1, @CMBL |
| 212 | |
| 213 | cmpi $ACM1, #0x111 // fill the internal sample buffer and process the voice internally |
| 214 | jz input_samples |
| 215 | |
| 216 | cmpi $ACM1, #0x112 // get samples from the external buffer to the internal buffer and process the voice mixing the samples internally |
| 217 | jz input_samples2 |
| 218 | |
| 219 | cmpi $ACM1, #0x123 // get the address of the voice datas buffer (CHANNEL DATAS) |
| 220 | jz get_data_addr |
| 221 | |
| 222 | cmpi $ACM1, #0x222 // process the voice mixing the samples internally |
| 223 | jz input_next_samples |
| 224 | |
| 225 | cmpi $ACM1, #0x666 // send the samples for the internal buffer to the external buffer |
| 226 | jz send_samples |
| 227 | |
| 228 | cmpi $ACM1, #0x777 // special: to dump the IROM Datas (remember disable others functions from the interrupt vector to use) |
| 229 | jz rom_dump_word // (CMBH+0x8000) contains the address of IROM |
| 230 | |
| 231 | cmpi $ACM1, #0x888 // Used for test |
| 232 | jz polla_loca |
| 233 | |
| 234 | cmpi $ACM1, #0x999 |
| 235 | jz task_terminate |
| 236 | |
| 237 | si @DMBL, #0x0004 // return 0 as ignore command |
| 238 | si @DIRQ, #0x1 // set the interrupt |
| 239 | jmp recv_cmd |
| 240 | |
| 241 | task_terminate: |
| 242 | si @DMBL, #0x0003 |
| 243 | si @DIRQ, #0x1 |
| 244 | jmp recv_cmd |
| 245 | |
| 246 | sys_command: |
| 247 | clr $ACC1 |
| 248 | lrs $ACM1, @CMBL |
| 249 | |
| 250 | cmpi $ACM1,#0x0001 |
| 251 | jz run_nexttask |
| 252 | |
| 253 | cmpi $ACM1,#0x0002 |
| 254 | jz 0x8000 |
| 255 | |
| 256 | jmp recv_cmd |
| 257 | |
| 258 | run_nexttask: |
| 259 | s16 |
| 260 | call wait_for_cpu_mail |
| 261 | lrs $29,@CMBL |
| 262 | call wait_for_cpu_mail |
| 263 | lrs $29,@CMBL |
| 264 | call wait_for_cpu_mail |
| 265 | lrs $29,@CMBL |
| 266 | call wait_for_cpu_mail |
| 267 | lr $5,@CMBL |
| 268 | andi $31,#0x0fff |
| 269 | mrr $4,$31 |
| 270 | call wait_for_cpu_mail |
| 271 | lr $7,@CMBL |
| 272 | call wait_for_cpu_mail |
| 273 | lr $6,@CMBL |
| 274 | call wait_for_cpu_mail |
| 275 | lr $0,@CMBL |
| 276 | call wait_for_cpu_mail |
| 277 | lrs $24,@CMBL |
| 278 | andi $31,#0x0fff |
| 279 | mrr $26,$31 |
| 280 | call wait_for_cpu_mail |
| 281 | lrs $25,@CMBL |
| 282 | call wait_for_cpu_mail |
| 283 | lrs $27,@CMBL |
| 284 | sbclr #0x05 |
| 285 | sbclr #0x06 |
| 286 | jmp 0x80b5 |
| 287 | halt |
| 288 | |
| 289 | /**************************************************************************************************************************************/ |
| 290 | // send the samples for the internal buffer to the external buffer |
| 291 | |
| 292 | send_samples: |
| 293 | |
| 294 | lri $AR0, #MEM_SND |
| 295 | lris $AXL1, #DMA_TO_CPU; |
| 296 | lri $AXL0, #NUM_SAMPLES*4 ; len |
| 297 | lr $ACM0, @ADDRH_SND |
| 298 | lr $ACL0, @ADDRL_SND |
| 299 | |
| 300 | call do_dma |
| 301 | si @DMBL, #0x0004 |
| 302 | si @DIRQ, #0x1 // set the interrupt |
| 303 | jmp recv_cmd |
| 304 | |
| 305 | /**************************************************************************************************************************************/ |
| 306 | // get the address of the voice datas buffer (CHANNEL DATAS) |
| 307 | |
| 308 | get_data_addr: |
| 309 | call wait_for_cpu_mail |
| 310 | |
| 311 | lrs $ACM0, @CMBH |
| 312 | lr $ACL0, @CMBL |
| 313 | |
| 314 | sr @MEM_VECTH, $ACM0 |
| 315 | sr @MEM_VECTL, $ACL0 |
| 316 | |
| 317 | si @DIRQ, #0x0 // clear the interrupt |
| 318 | jmp recv_cmd |
| 319 | |
| 320 | /**************************************************************************************************************************************/ |
| 321 | // fill the internal sample buffer and process the voice internally |
| 322 | |
| 323 | input_samples: |
| 324 | |
| 325 | clr $ACC0 |
| 326 | lr $ACM0, @MEM_VECTH |
| 327 | lr $ACL0, @MEM_VECTL |
| 328 | |
| 329 | lris $AXL0, #0x0004 |
| 330 | sr @RETURN, $AXL0 |
| 331 | si @DIRQ, #0x0000 |
| 332 | |
| 333 | // program DMA to get datas |
| 334 | |
| 335 | lri $AR0, #MEM_REG |
| 336 | lris $AXL1, #DMA_TO_DSP |
| 337 | lris $AXL0, #64 ; len |
| 338 | |
| 339 | call do_dma |
| 340 | |
| 341 | lri $AR1, #MEM_SND |
| 342 | lri $ACL1, #0; |
| 343 | |
| 344 | lri $AXL0, #NUM_SAMPLES |
| 345 | bloop $AXL0, loop_get1 |
| 346 | |
| 347 | srri @$AR1, $ACL1 |
| 348 | srri @$AR1, $ACL1 |
| 349 | |
| 350 | loop_get1: |
| 351 | nop |
| 352 | |
| 353 | lr $ACM0, @ADDRH_SND |
| 354 | lr $ACL0, @ADDRL_SND |
| 355 | jmp start_main |
| 356 | |
| 357 | /**************************************************************************************************************************************/ |
| 358 | // get samples from the external buffer to the internal buffer and process the voice mixing the samples internally |
| 359 | |
| 360 | input_samples2: |
| 361 | |
| 362 | clr $ACC0 |
| 363 | lr $ACM0, @MEM_VECTH |
| 364 | lr $ACL0, @MEM_VECTL |
| 365 | |
| 366 | lris $AXL0, #0x0004 |
| 367 | sr @RETURN, $AXL0 |
| 368 | si @DIRQ, #0x0000 |
| 369 | |
| 370 | // program DMA to get datas |
| 371 | |
| 372 | lri $AR0, #MEM_REG |
| 373 | lri $AXL1, #DMA_TO_DSP |
| 374 | lris $AXL0, #64 ; len |
| 375 | |
| 376 | call do_dma |
| 377 | |
| 378 | lr $ACM0, @ADDRH_SND |
| 379 | lr $ACL0, @ADDRL_SND |
| 380 | |
| 381 | lri $AR0, #MEM_SND |
| 382 | lris $AXL1, #DMA_TO_DSP; |
| 383 | lri $AXL0, #NUM_SAMPLES*4; len |
| 384 | |
| 385 | call do_dma |
| 386 | |
| 387 | jmp start_main |
| 388 | |
| 389 | /**************************************************************************************************************************************/ |
| 390 | // process the voice mixing the samples internally |
| 391 | |
| 392 | input_next_samples: |
| 393 | |
| 394 | clr $ACC0 |
| 395 | lr $ACM0, @MEM_VECTH |
| 396 | lr $ACL0, @MEM_VECTL |
| 397 | |
| 398 | lris $AXL0, #0x0004 |
| 399 | sr @RETURN, $AXL0 |
| 400 | si @DIRQ, #0x0000 |
| 401 | |
| 402 | // program DMA to get datas |
| 403 | |
| 404 | lri $AR0, #MEM_REG |
| 405 | lris $AXL1, #DMA_TO_DSP |
| 406 | lris $AXL0, #64 ; len |
| 407 | |
| 408 | call do_dma |
| 409 | |
| 410 | /**************************************************************************************************************************************/ |
| 411 | // mixing and control pitch to create 1024 Stereo Samples at 16 bits from here |
| 412 | |
| 413 | start_main: |
| 414 | |
| 415 | lri $R08, #48000 |
| 416 | |
| 417 | // load the previous samples used |
| 418 | |
| 419 | lr $AXH0, @SMP_R |
| 420 | lr $AXH1, @SMP_L |
| 421 | |
| 422 | // optimize the jump function to get MONO/STEREO 8/16 bits samples |
| 423 | |
| 424 | lr $ACM1, @FLAGSL_SMP |
| 425 | andi $ACM1, #0x3 |
| 426 | addi $ACM1, #sample_selector |
| 427 | mrr $AR3, $ACM1 |
| 428 | ilrr $ACM1, @$AR3 |
| 429 | mrr $AR3, $ACM1 // AR3 contains the jump loaded from sample selector |
| 430 | |
| 431 | clr $ACC0 |
| 432 | |
| 433 | // test for channel paused |
| 434 | |
| 435 | lr $ACM0, @FLAGSL_SMP |
| 436 | andcf $ACM0, #0x20 |
| 437 | jlz end_main |
| 438 | |
| 439 | // load the sample address |
| 440 | |
| 441 | lr $ACM0, @ADDRH_SMP |
| 442 | lr $ACL0, @ADDRL_SMP |
| 443 | |
| 444 | // test if ADDR_SMP & ADDR2H_SMP are zero |
| 445 | |
| 446 | tst $ACC0 |
| 447 | jnz do_not_change1 |
| 448 | |
| 449 | // set return as "change of buffer" |
| 450 | |
| 451 | lris $AXL0, #0x0004 |
| 452 | sr @RETURN, $AXL0 |
| 453 | |
| 454 | // change to buffer 2 if it is possible |
| 455 | |
| 456 | call change_buffer |
| 457 | |
| 458 | // stops if again 0 address |
| 459 | |
| 460 | tst $ACC0 |
| 461 | jz save_datas_end |
| 462 | |
| 463 | do_not_change1: |
| 464 | |
| 465 | |
| 466 | // backup the external sample address |
| 467 | |
| 468 | mrr $IX2, $ACM0 |
| 469 | mrr $IX3, $ACL0 |
| 470 | |
| 471 | |
| 472 | // load the counter pitch |
| 473 | |
| 474 | //lr $r08, @COUNTERH_SMP |
| 475 | //lr $r09, @COUNTERL_SMP |
| 476 | |
| 477 | // load the end address of the samples |
| 478 | |
| 479 | lr $r0a, @ADDREH_SMP |
| 480 | lr $r0b, @ADDREL_SMP |
| 481 | |
| 482 | // load AR1 with internal buffer address |
| 483 | |
| 484 | lri $AR1, #MEM_SND |
| 485 | |
| 486 | ///////////////////////////////////// |
| 487 | // delay time section |
| 488 | ///////////////////////////////////// |
| 489 | |
| 490 | // load AXL0 with the samples to be processed |
| 491 | |
| 492 | lri $AXL0, #NUM_SAMPLES |
| 493 | |
| 494 | // test if DELAY == 0 and skip or not |
| 495 | |
| 496 | clr $ACC0 |
| 497 | clr $ACC1 |
| 498 | lr $ACH0, @DELAYH_SND |
| 499 | lr $ACM0, @DELAYL_SND |
| 500 | tst $ACC0 |
| 501 | jz no_delay |
| 502 | |
| 503 | // samples left and right to 0 |
| 504 | |
| 505 | lris $AXH0, #0 |
| 506 | lris $AXH1, #0 |
| 507 | |
| 508 | // load the samples to be processed in ACM1 |
| 509 | |
| 510 | mrr $ACM1, $AXL0 |
| 511 | l_delay: |
| 512 | iar $AR1 // skip two samples |
| 513 | iar $AR1 |
| 514 | decm $ACM1 |
| 515 | jz exit_delay1 // exit1 if samples to be processed == 0 |
| 516 | |
| 517 | decm $ACM0 |
| 518 | jz exit_delay2 // exit2 if delay time == 0 |
| 519 | jmp l_delay |
| 520 | |
| 521 | // store the remanent delay and ends |
| 522 | |
| 523 | exit_delay1: |
| 524 | decm $ACM0 |
| 525 | |
| 526 | sr @DELAYH_SND, $ACH0 |
| 527 | sr @DELAYL_SND, $ACM0 |
| 528 | |
| 529 | lris $AXL0,#0 ; exit from loop |
| 530 | |
| 531 | jmp no_delay |
| 532 | |
| 533 | |
| 534 | exit_delay2: |
| 535 | |
| 536 | // store delay=0 and continue |
| 537 | |
| 538 | sr @DELAYH_SND, $ACH0 |
| 539 | sr @DELAYL_SND, $ACM0 |
| 540 | mrr $AXL0, $ACL1 // load remanent samples to be processed in AXL0 |
| 541 | |
| 542 | no_delay: |
| 543 | |
| 544 | ///////////////////////////////////// |
| 545 | // end of delay time section |
| 546 | ///////////////////////////////////// |
| 547 | )" // Work around C2026 on MSVC, which allows at most 16380 single-byte characters in a single |
| 548 | // non-concatenated string literal (but you can concatenate multiple shorter string literals to |
| 549 | // produce a longer string just fine). (This comment is not part of the actual test program, |
| 550 | // and instead there is a single blank line at this location.) |
| 551 | R"( |
| 552 | /* bucle de generacion de samples */ |
| 553 | |
| 554 | |
| 555 | // load the sample buffer with address aligned to 32 bytes blocks (first time) |
| 556 | |
| 557 | si @DSCR, #DMA_TO_DSP // very important!: load_smp_addr_align and jump_load_smp_addr need fix this DMA Register (I gain some cycles so) |
| 558 | |
| 559 | // load_smp_addr_align input: $IX2:$IX3 |
| 560 | |
| 561 | call load_smp_addr_align |
| 562 | |
| 563 | // load the volume registers |
| 564 | |
| 565 | lr $IX0, @LEFT_VOLUME |
| 566 | lr $IX1, @RIGHT_VOLUME |
| 567 | |
| 568 | // test the freq value |
| 569 | |
| 570 | clr $ACC0 |
| 571 | lr $ACH0, @FREQH_SMP |
| 572 | lr $ACM0, @FREQL_SMP |
| 573 | |
| 574 | clr $ACC1 |
| 575 | ;lri $ACM1,#48000 |
| 576 | mrr $ACM1, $R08 |
| 577 | cmp |
| 578 | |
| 579 | // select the output of the routine to process stereo-mono 8/16bits samples |
| 580 | |
| 581 | lri $AR0, #get_sample // fast method <=48000 |
| 582 | |
| 583 | // if number is greater freq>48000 fix different routine |
| 584 | |
| 585 | ifg |
| 586 | lri $AR0, #get_sample2 // slow method >48000 |
| 587 | |
| 588 | // loops for samples to be processed |
| 589 | |
| 590 | bloop $AXL0, loop_end |
| 591 | |
| 592 | //srri @$AR1, $AXH0 // put sample R |
| 593 | //srri @$AR1, $AXH1 // put sample L |
| 594 | |
| 595 | // Mix right sample section |
| 596 | |
| 597 | lrr $ACL0, @$AR1 // load in ACL0 the right sample from the internal buffer |
| 598 | movax $ACC1, $AXL1 // big trick :) load the current sample <<16 and sign extended |
| 599 | |
| 600 | asl $ACC0,#24 // convert sample from buffer to 24 bit number with sign extended (ACH0:ACM0) |
| 601 | asr $ACC0,#-8 |
| 602 | |
| 603 | add $ACC0,$ACC1 // current_sample+buffer sample |
| 604 | |
| 605 | cmpi $ACM0,#32767 // limit to 32767 |
| 606 | jle right_skip |
| 607 | |
| 608 | lri $ACM0, #32767 |
| 609 | jmp right_skip2 |
| 610 | |
| 611 | right_skip: |
| 612 | |
| 613 | cmpi $ACM0,#-32768 // limit to -32768 |
| 614 | ifle |
| 615 | lri $ACM0, #-32768 |
| 616 | |
| 617 | right_skip2: |
| 618 | |
| 619 | srri @$AR1, $ACM0 // store the right sample mixed to the internal buffer and increment AR1 |
| 620 | |
| 621 | // Mix left sample section |
| 622 | |
| 623 | lrr $ACL0, @$AR1 // load in ACL0 the left sample from the internal buffer |
| 624 | |
| 625 | movax $ACC1, $AXL0 // big trick :) load the current sample <<16 and sign extended |
| 626 | |
| 627 | asl $ACC0, #24 // convert sample from buffer to 24 bit number with sign extended (ACH0:ACM0) |
| 628 | asr $ACC0, #-8 |
| 629 | |
| 630 | add $ACC0, $ACC1 // current_sample+buffer sample |
| 631 | |
| 632 | cmpi $ACM0,#32767 // limit to 32767 |
| 633 | jle left_skip |
| 634 | |
| 635 | lri $ACM0, #32767 |
| 636 | jmp left_skip2 |
| 637 | |
| 638 | left_skip: |
| 639 | |
| 640 | cmpi $ACM0,#-32768 // limit to -32768 |
| 641 | ifle |
| 642 | lri $ACM0, #-32768 |
| 643 | |
| 644 | left_skip2: |
| 645 | |
| 646 | srri @$AR1, $ACM0 // store the left sample mixed to the internal buffer and increment AR1 |
| 647 | |
| 648 | // adds the counter with the voice frequency and test if it >=48000 to get the next sample |
| 649 | |
| 650 | clr $ACC1 |
| 651 | lr $ACH1, @COUNTERH_SMP |
| 652 | lr $ACM1, @COUNTERL_SMP |
| 653 | clr $ACC0 |
| 654 | lr $ACH0, @FREQH_SMP |
| 655 | lr $ACM0, @FREQL_SMP |
| 656 | |
| 657 | add $ACC1,$ACC0 |
| 658 | clr $ACC0 |
| 659 | //lri $ACM0,#48000 |
| 660 | mrr $ACM0, $R08 |
| 661 | |
| 662 | cmp |
| 663 | |
| 664 | jrnc $AR0 //get_sample or get_sample2 method |
| 665 | |
| 666 | sr @COUNTERH_SMP, $ACH1 |
| 667 | sr @COUNTERL_SMP, $ACM1 |
| 668 | |
| 669 | jmp loop_end |
| 670 | |
| 671 | // get a new sample for freq > 48000 Hz |
| 672 | |
| 673 | get_sample2: // slow method |
| 674 | |
| 675 | sub $ACC1,$ACC0 // restore the counter |
| 676 | |
| 677 | // restore the external sample buffer address |
| 678 | |
| 679 | clr $ACC0 |
| 680 | mrr $ACM0, $IX2 // load ADDRH_SMP |
| 681 | mrr $ACL0, $IX3 // load ADDRL_SMP |
| 682 | |
| 683 | lr $AXL1, @FLAGSH_SMP // add the step to get the next samples |
| 684 | addaxl $ACC0, $AXL1 |
| 685 | |
| 686 | mrr $IX2, $ACM0 // store ADDRH_SMP |
| 687 | mrr $IX3, $ACL0 // store ADDRL_SMP |
| 688 | |
| 689 | mrr $ACM0, $ACL0 |
| 690 | andf $ACM0, #0x1f |
| 691 | |
| 692 | // load_smp_addr_align input: $IX2:$IX3 call if (ACM0 & 0x1f)==0 |
| 693 | |
| 694 | calllz load_smp_addr_align |
| 695 | |
| 696 | clr $ACC0 |
| 697 | //lri $ACM0,#48000 |
| 698 | mrr $ACM0, $R08 |
| 699 | |
| 700 | cmp |
| 701 | |
| 702 | jle get_sample2 |
| 703 | |
| 704 | sr @COUNTERH_SMP, $ACH1 |
| 705 | sr @COUNTERL_SMP, $ACM1 |
| 706 | |
| 707 | mrr $ACM0, $IX2 // load ADDRH_SMP |
| 708 | mrr $ACL0, $IX3 // load ADDRL_SMP |
| 709 | |
| 710 | clr $ACC1 |
| 711 | mrr $ACM1, $r0a // load ADDREH_SMP |
| 712 | mrr $ACL1, $r0b // load ADDREL_SMP |
| 713 | |
| 714 | // compares if the current address is >= end address to change the buffer or stops |
| 715 | |
| 716 | cmp |
| 717 | |
| 718 | // if addr>addr end get a new buffer (if you uses double buffer) |
| 719 | |
| 720 | jc get_new_buffer |
| 721 | |
| 722 | // load samples from dma, return $ar2 with the addr to get the samples and return using $ar0 to the routine to process 8-16bits Mono/Stereo |
| 723 | |
| 724 | jmp jump_load_smp_addr |
| 725 | |
| 726 | // get a new sample for freq <= 48000 Hz |
| 727 | |
| 728 | get_sample: // fast method |
| 729 | |
| 730 | sub $ACC1,$ACC0 // restore the counter |
| 731 | sr @COUNTERH_SMP, $ACH1 |
| 732 | sr @COUNTERL_SMP, $ACM1 |
| 733 | |
| 734 | // restore the external sample buffer address |
| 735 | |
| 736 | clr $ACC0 |
| 737 | mrr $ACM0, $IX2 // load ADDRH_SMP |
| 738 | mrr $ACL0, $IX3 // load ADDRL_SMP |
| 739 | |
| 740 | lr $AXL1, @FLAGSH_SMP // add the step to get the next samples |
| 741 | addaxl $ACC0, $AXL1 |
| 742 | |
| 743 | clr $ACC1 |
| 744 | mrr $ACM1, $r0a // load ADDREH_SMP |
| 745 | mrr $ACL1, $r0b // load ADDREL_SMP |
| 746 | |
| 747 | // compares if the current address is >= end address to change the buffer or stops |
| 748 | |
| 749 | cmp |
| 750 | jc get_new_buffer |
| 751 | |
| 752 | // load the new sample from the buffer |
| 753 | |
| 754 | mrr $IX2, $ACM0 // store ADDRH_SMP |
| 755 | mrr $IX3, $ACL0 // store ADDRL_SMP |
| 756 | |
| 757 | // load samples from dma, return $ar2 with the addr and return using $ar0 to the routine to process 8-16bits Mono/Stereo or addr_get_sample_again |
| 758 | |
| 759 | jmp jump_load_smp_addr |
| 760 | |
| 761 | sample_selector: |
| 762 | cw mono_8bits |
| 763 | cw mono_16bits |
| 764 | cw stereo_8bits |
| 765 | cw stereo_16bits |
| 766 | |
| 767 | get_new_buffer: |
| 768 | |
| 769 | // set return as "change of buffer": it need to change the sample address |
| 770 | |
| 771 | lris $AXL0, #0x0004 |
| 772 | sr @RETURN, $AXL0 |
| 773 | |
| 774 | call change_buffer // load add from addr2 |
| 775 | |
| 776 | // addr is 0 ? go to zero_samples and exit |
| 777 | |
| 778 | tst $acc0 |
| 779 | jz zero_samples |
| 780 | |
| 781 | // load_smp_addr_align input: $IX2:$IX3 |
| 782 | |
| 783 | call load_smp_addr_align // force the load the samples cached (address aligned) |
| 784 | |
| 785 | // jump_load_smp_addr: $IX2:$IX3 |
| 786 | // load samples from dma, return $ar2 with the addr to get the samples and return using $ar0 to the routine to process 8-16bits Mono/Stereo |
| 787 | |
| 788 | jmp jump_load_smp_addr |
| 789 | |
| 790 | // set to 0 the current samples |
| 791 | |
| 792 | zero_samples: |
| 793 | |
| 794 | lris $AXH0, #0 |
| 795 | lris $AXH1, #0 |
| 796 | jmp out_samp |
| 797 | |
| 798 | mono_8bits: |
| 799 | |
| 800 | // 8 bits mono |
| 801 | mrr $ACM1, $IX3 |
| 802 | lrri $ACL0, @$AR2 |
| 803 | andf $ACM1, #0x1 |
| 804 | |
| 805 | iflz // obtain sample0-sample1 from 8bits packet |
| 806 | asr $ACC0, #-8 |
| 807 | asl $ACC0, #8 |
| 808 | |
| 809 | mrr $AXH1,$ACL0 |
| 810 | mrr $AXH0,$ACL0 |
| 811 | jmp out_samp |
| 812 | |
| 813 | stereo_8bits: |
| 814 | |
| 815 | // 8 bits stereo |
| 816 | |
| 817 | lrri $ACL0, @$AR2 |
| 818 | mrr $ACM0, $ACL0 |
| 819 | andi $ACM0, #0xff00 |
| 820 | mrr $AXH1, $ACM0 |
| 821 | lsl $ACC0, #8 |
| 822 | mrr $AXH0, $ACL0 |
| 823 | |
| 824 | jmp out_samp |
| 825 | |
| 826 | mono_16bits: |
| 827 | |
| 828 | // 16 bits mono |
| 829 | |
| 830 | lrri $AXH1, @$AR2 |
| 831 | mrr $AXH0,$AXH1 |
| 832 | jmp out_samp |
| 833 | |
| 834 | stereo_16bits: |
| 835 | |
| 836 | // 16 bits stereo |
| 837 | |
| 838 | lrri $AXH1, @$AR2 |
| 839 | lrri $AXH0, @$AR2 |
| 840 | |
| 841 | out_samp: |
| 842 | |
| 843 | // multiply sample x volume |
| 844 | |
| 845 | // LEFT_VOLUME |
| 846 | mrr $AXL0,$IX0 |
| 847 | mul $AXL0,$AXH0 |
| 848 | movp $ACC0 |
| 849 | asr $ACC0,#-8 |
| 850 | mrr $AXH0, $ACL0 |
| 851 | |
| 852 | // RIGHT VOLUME |
| 853 | mrr $AXL1,$IX1 |
| 854 | mul $AXL1,$AXH1 |
| 855 | movp $ACC0 |
| 856 | asr $ACC0,#-8 |
| 857 | mrr $AXH1, $ACL0 |
| 858 | |
| 859 | loop_end: |
| 860 | nop |
| 861 | |
| 862 | end_process: |
| 863 | |
| 864 | // load the sample address |
| 865 | |
| 866 | clr $ACC0 |
| 867 | mrr $ACM0, $IX2 |
| 868 | mrr $ACL0, $IX3 |
| 869 | |
| 870 | tst $ACC0 |
| 871 | jnz save_datas_end |
| 872 | |
| 873 | // set return as "change of buffer" |
| 874 | |
| 875 | lris $AXL0, #0x0004 |
| 876 | sr @RETURN, $AXL0 |
| 877 | |
| 878 | // change to buffer 2 if it is possible |
| 879 | |
| 880 | call change_buffer |
| 881 | |
| 882 | save_datas_end: |
| 883 | |
| 884 | sr @ADDRH_SMP, $IX2 |
| 885 | sr @ADDRL_SMP, $IX3 |
| 886 | sr @SMP_R, $AXH0 |
| 887 | sr @SMP_L, $AXH1 |
| 888 | |
| 889 | end_main: |
| 890 | |
| 891 | // program DMA to send the CHANNEL DATAS changed |
| 892 | |
| 893 | clr $ACC0 |
| 894 | lr $ACM0, @MEM_VECTH |
| 895 | lr $ACL0, @MEM_VECTL |
| 896 | |
| 897 | lri $AR0, #MEM_REG |
| 898 | lris $AXL1, #DMA_TO_CPU |
| 899 | lris $AXL0, #64 ; len |
| 900 | |
| 901 | call do_dma |
| 902 | |
| 903 | si @DMBH, #0xdcd1 |
| 904 | lr $ACL0, @RETURN |
| 905 | |
| 906 | sr @DMBL, $ACL0 |
| 907 | si @DIRQ, #0x1 // set the interrupt |
| 908 | |
| 909 | jmp recv_cmd |
| 910 | |
| 911 | change_buffer: |
| 912 | |
| 913 | clr $ACC0 |
| 914 | lr $ACM0, @LEFT_VOLUME2 |
| 915 | lr $ACL0, @RIGHT_VOLUME2 |
| 916 | sr @LEFT_VOLUME, $ACM0 |
| 917 | sr @RIGHT_VOLUME, $ACL0 |
| 918 | mrr $IX0, $ACM0 |
| 919 | mrr $IX1, $ACL0 |
| 920 | |
| 921 | lr $ACM0, @ADDR2EH_SMP |
| 922 | lr $ACL0, @ADDR2EL_SMP |
| 923 | sr @ADDREH_SMP, $ACM0 |
| 924 | sr @ADDREL_SMP, $ACL0 |
| 925 | mrr $r0a, $ACM0 |
| 926 | mrr $r0b, $ACL0 |
| 927 | |
| 928 | lr $ACM0, @ADDR2H_SMP |
| 929 | lr $ACL0, @ADDR2L_SMP |
| 930 | sr @ADDRH_SMP, $ACM0 |
| 931 | sr @ADDRL_SMP, $ACL0 |
| 932 | sr @BACKUPH_SMP, $ACM0 |
| 933 | sr @BACKUPL_SMP, $ACL0 |
| 934 | mrr $IX2, $ACM0 |
| 935 | mrr $IX3, $ACL0 |
| 936 | |
| 937 | lr $ACM1, @FLAGSL_SMP |
| 938 | andcf $ACM1, #0x4 |
| 939 | retlz |
| 940 | |
| 941 | sr @ADDR2H_SMP, $ACH0 |
| 942 | sr @ADDR2L_SMP, $ACH0 |
| 943 | sr @ADDR2EH_SMP, $ACH0 |
| 944 | sr @ADDR2EL_SMP, $ACH0 |
| 945 | ret |
| 946 | |
| 947 | /**************************************************************/ |
| 948 | /* DMA ROUTINE */ |
| 949 | /**************************************************************/ |
| 950 | |
| 951 | do_dma: |
| 952 | |
| 953 | sr @DSMAH, $ACM0 |
| 954 | sr @DSMAL, $ACL0 |
| 955 | sr @DSPA, $AR0 |
| 956 | sr @DSCR, $AXL1 |
| 957 | sr @DSBL, $AXL0 |
| 958 | |
| 959 | wait_dma: |
| 960 | |
| 961 | lrs $ACM1, @DSCR |
| 962 | andcf $ACM1, #0x4 |
| 963 | jlz wait_dma |
| 964 | ret |
| 965 | |
| 966 | |
| 967 | wait_for_dsp_mail: |
| 968 | |
| 969 | lrs $ACM1, @DMBH |
| 970 | andcf $ACM1, #0x8000 |
| 971 | jlz wait_for_dsp_mail |
| 972 | ret |
| 973 | |
| 974 | wait_for_cpu_mail: |
| 975 | |
| 976 | lrs $ACM1, @cmbh |
| 977 | andcf $ACM1, #0x8000 |
| 978 | jlnz wait_for_cpu_mail |
| 979 | ret |
| 980 | |
| 981 | load_smp_addr_align: |
| 982 | |
| 983 | mrr $ACL0, $IX3 // load ADDRL_SMP |
| 984 | |
| 985 | lsr $ACC0, #-5 |
| 986 | lsl $ACC0, #5 |
| 987 | sr @DSMAH, $IX2 |
| 988 | sr @DSMAL, $ACL0 |
| 989 | si @DSPA, #MEM_SAMP |
| 990 | ;si @DSCR, #DMA_TO_DSP |
| 991 | si @DSBL, #0x20 |
| 992 | |
| 993 | wait_dma1: |
| 994 | lrs $ACM0, @DSCR |
| 995 | andcf $ACM0, #0x4 |
| 996 | jlz wait_dma1 |
| 997 | |
| 998 | lri $AR2, #MEM_SAMP |
| 999 | ret |
| 1000 | |
| 1001 | |
| 1002 | ////////////////////////////////////////// |
| 1003 | |
| 1004 | jump_load_smp_addr: |
| 1005 | |
| 1006 | mrr $ACM0, $IX3 // load ADDRL_SMP |
| 1007 | asr $ACC0, #-1 |
| 1008 | andi $ACM0, #0xf |
| 1009 | jz jump_load_smp_dma |
| 1010 | |
| 1011 | addi $ACM0, #MEM_SAMP |
| 1012 | mrr $AR2, $ACM0 |
| 1013 | jmpr $AR3 |
| 1014 | |
| 1015 | jump_load_smp_dma: |
| 1016 | |
| 1017 | sr @DSMAH, $IX2 |
| 1018 | sr @DSMAL, $IX3 |
| 1019 | si @DSPA, #MEM_SAMP |
| 1020 | ;si @DSCR, #DMA_TO_DSP // to gain some cycles |
| 1021 | si @DSBL, #0x20 |
| 1022 | |
| 1023 | wait_dma2: |
| 1024 | lrs $ACM0, @DSCR |
| 1025 | andcf $ACM0, #0x4 |
| 1026 | jlz wait_dma2 |
| 1027 | |
| 1028 | lri $AR2, #MEM_SAMP |
| 1029 | jmpr $AR3 |
| 1030 | |
| 1031 | // exception table |
| 1032 | |
| 1033 | exception0: // RESET |
| 1034 | rti |
| 1035 | |
| 1036 | exception1: // STACK OVERFLOW |
| 1037 | rti |
| 1038 | |
| 1039 | exception2: |
| 1040 | rti |
| 1041 | |
| 1042 | exception3: |
| 1043 | rti |
| 1044 | |
| 1045 | exception4: |
| 1046 | rti |
| 1047 | |
| 1048 | exception5: // ACCELERATOR ADDRESS OVERFLOW |
| 1049 | rti |
| 1050 | |
| 1051 | exception6: |
| 1052 | rti |
| 1053 | |
| 1054 | exception7: |
| 1055 | rti |
| 1056 | |
| 1057 | // routine to read a word of the IROM space |
| 1058 | |
| 1059 | rom_dump_word: |
| 1060 | |
| 1061 | clr $ACC0 |
| 1062 | |
| 1063 | lr $ACM0, @CMBH |
| 1064 | ori $ACM0, #0x8000 |
| 1065 | mrr $AR0, $ACM0 |
| 1066 | clr $ACC0 |
| 1067 | ilrr $ACM0, @$AR0 |
| 1068 | sr @DMBH, $ACL0 |
| 1069 | sr @DMBL, $ACM0 |
| 1070 | ;si @DIRQ, #0x1 // set the interrupt |
| 1071 | clr $ACC0 |
| 1072 | jmp recv_cmd |
| 1073 | |
| 1074 | polla_loca: |
| 1075 | |
| 1076 | clr $ACC0 |
| 1077 | lri $acm0, #0x0 |
| 1078 | andf $acm0,#0x1 |
| 1079 | |
| 1080 | sr @DMBH, $sr |
| 1081 | sr @DMBL, $acm0 |
| 1082 | ;si @DIRQ, #0x1 // set the interrupt |
| 1083 | clr $ACC0 |
| 1084 | jmp recv_cmd |
| 1085 | |
| 1086 | )"; |