From 5f25c0bf306d316c87fca9d3fe160d6661be230d Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 23 Oct 2022 15:03:16 +0200 Subject: Library bugfixes and additions, _sdk_log_inner() removal --- libpsn00b/psxpress/vlc.s | 152 +++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 91 deletions(-) (limited to 'libpsn00b/psxpress/vlc.s') diff --git a/libpsn00b/psxpress/vlc.s b/libpsn00b/psxpress/vlc.s index 885a3f7..75e33d3 100644 --- a/libpsn00b/psxpress/vlc.s +++ b/libpsn00b/psxpress/vlc.s @@ -29,17 +29,17 @@ .set VLC_Context_block_index, 20 .set VLC_Context_coeff_index, 21 -.set DECDCTSMALLTAB_lut0, 0 -.set DECDCTSMALLTAB_lut2, 4 -.set DECDCTSMALLTAB_lut3, 36 -.set DECDCTSMALLTAB_lut4, 292 -.set DECDCTSMALLTAB_lut5, 308 -.set DECDCTSMALLTAB_lut7, 324 -.set DECDCTSMALLTAB_lut8, 356 -.set DECDCTSMALLTAB_lut9, 420 -.set DECDCTSMALLTAB_lut10, 484 -.set DECDCTSMALLTAB_lut11, 548 -.set DECDCTSMALLTAB_lut12, 612 +.set DECDCTTAB_lut0, 0 +.set DECDCTTAB_lut2, 4 +.set DECDCTTAB_lut3, 36 +.set DECDCTTAB_lut4, 292 +.set DECDCTTAB_lut5, 308 +.set DECDCTTAB_lut7, 324 +.set DECDCTTAB_lut8, 356 +.set DECDCTTAB_lut9, 420 +.set DECDCTTAB_lut10, 484 +.set DECDCTTAB_lut11, 548 +.set DECDCTTAB_lut12, 612 .section .text.DecDCTvlcStart .global DecDCTvlcStart @@ -115,7 +115,7 @@ _vlc_skip_context_load: # Obtain the addresses of the lookup table and jump area in advance so that # they don't have to be retrieved for each coefficient decoded. lw $t8, _vlc_huffman_table - la $t9, .Lac_jump_area + la $t9, .Lac_prefix_10 beqz $a2, .Lstop_processing addiu $a1, 4 # output = (uint16_t *) &output[1] @@ -123,32 +123,32 @@ _vlc_skip_context_load: .Lprocess_next_code_loop: # while (max_size) # This is the "hot" part of the decoder, executed for each code in the # bitstream. The first step is to determine if the next code is a DC or AC - # coefficient. The GTE is also given the task of counting the number of - # leading zeroes/ones, which takes 2 more cycles. + # coefficient. bnez $t7, .Lprocess_ac_coefficient - mtc2 $t0, $30 + addiu $t7, 1 # coeff_index++ bnez $t4, .Lprocess_dc_v3_coefficient - #nop + li $v1, 0x01ff .Lprocess_dc_v2_coefficient: # if (!coeff_index && !is_v3) # The DC coefficient in version 2 frames is not compressed. Value 0x1ff is # used to signal the end of the bitstream. srl $v0, $t0, 22 # prefix = (window >> (32 - 10)) - li $v1, 0x01ff beq $v0, $v1, .Lstop_processing # if (prefix == 0x1ff) break or $v0, $t3 # *output = prefix | quant_scale sll $t0, 10 # window <<= 10 - addiu $t5, -10 # bit_offset -= 10 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -10 # bit_offset -= 10 .Lprocess_dc_v3_coefficient: # if (!coeff_index && is_v3) # TODO: version 3 is currently not supported. jr $ra li $v0, -1 - #b .Lwrite_value .Lprocess_ac_coefficient: # if (coeff_index) + # Start counting the number of leading zeroes/ones using the GTE. This + # takes 2 more cycles. + mtc2 $t0, $30 + # Check whether the prefix code is one of the shorter, more common ones. srl $v0, $t0, 30 li $v1, 3 @@ -157,33 +157,34 @@ _vlc_skip_context_load: beq $v0, $v1, .Lac_prefix_10 li $v1, 1 beq $v0, $v1, .Lac_prefix_01 - #srl $v0, $t0, 29 - #beq $v0, $v1, .Lac_prefix_001 - #nop + nop # If the code is longer, retrieve the number of leading zeroes from the GTE # and use it as an index into the jump area. Each block in the area is 8 # instructions long and handles decoding a specific prefix. mfc2 $v0, $31 - nop - andi $v0, 15 # jump_addr = &ac_jump_area[(prefix % 16) * 8 * sizeof(u32)] - sll $v0, 5 + li $v1, 11 + bgt $v0, $v1, .Lreturn_error # if (prefix > 11) return -1 + sll $v0, 5 # jump_addr = &ac_jump_area[prefix * 8 * sizeof(u32)] addu $v0, $t9 jr $v0 nop +.Lreturn_error: + jr $ra + li $v0, -1 + .Lac_prefix_11: # Prefix 11 is followed by a single bit. srl $v0, $t0, 28 # index = ((window >> (32 - 2 - 1)) & 1) * sizeof(u16) andi $v0, 2 addu $v0, $t8 # value = table->lut0[index] - lhu $v0, DECDCTSMALLTAB_lut0($v0) + lhu $v0, DECDCTTAB_lut0($v0) sll $t0, 3 # window <<= 3 - addiu $t5, -3 # bit_offset -= 3 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -3 # bit_offset -= 3 + #.word 0 -.Lac_jump_area: .Lac_prefix_10: # Prefix 10 marks the end of a block. li $v0, 0xfe00 # value = 0xfe00 @@ -202,11 +203,10 @@ _vlc_skip_context_load: srl $v0, $t0, 25 # index = ((window >> (32 - 2 - 3)) & 7) * sizeof(u32) andi $v0, 28 addu $v0, $t8 # value = table->lut2[index] - lw $v0, DECDCTSMALLTAB_lut2($v0) - addiu $t7, 1 # coeff_index++ + lw $v0, DECDCTTAB_lut2($v0) b .Lupdate_window_and_write srl $v1, $v0, 16 # length = value >> 16 - .word 0 + .word 0, 0 .Lac_prefix_001: # Prefix 001 can be followed by a 6-bit lookup index starting with 00, or a @@ -214,136 +214,106 @@ _vlc_skip_context_load: srl $v0, $t0, 21 # index = ((window >> (32 - 3 - 6)) & 63) * sizeof(u32) andi $v0, 252 addu $v0, $t8 # value = table->lut3[index] - lw $v0, DECDCTSMALLTAB_lut3($v0) - addiu $t7, 1 # coeff_index++ + lw $v0, DECDCTTAB_lut3($v0) b .Lupdate_window_and_write srl $v1, $v0, 16 # length = value >> 16 - .word 0 + .word 0, 0 .Lac_prefix_0001: # Prefix 0001 is followed by a 3-bit lookup index. srl $v0, $t0, 24 # index = ((window >> (32 - 4 - 3)) & 7) * sizeof(u16) andi $v0, 14 addu $v0, $t8 # value = table->lut4[index] - lhu $v0, DECDCTSMALLTAB_lut4($v0) + lhu $v0, DECDCTTAB_lut4($v0) sll $t0, 7 # window <<= 4 + 3 - addiu $t5, -7 # bit_offset -= 4 + 3 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -7 # bit_offset -= 4 + 3 + .word 0 .Lac_prefix_00001: # Prefix 00001 is followed by a 3-bit lookup index. srl $v0, $t0, 23 # index = ((window >> (32 - 5 - 3)) & 7) * sizeof(u16) andi $v0, 14 addu $v0, $t8 # value = table->lut5[index] - lhu $v0, DECDCTSMALLTAB_lut5($v0) + lhu $v0, DECDCTTAB_lut5($v0) sll $t0, 8 # window <<= 5 + 3 - addiu $t5, -8 # bit_offset -= 5 + 3 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -8 # bit_offset -= 5 + 3 + .word 0 .Lac_prefix_000001: # Prefix 000001 is an escape code followed by a full 16-bit MDEC value. srl $v0, $t0, 10 # value = window >> (32 - 6 - 16) sll $t0, 22 # window <<= 6 + 16 - addiu $t5, -22 # bit_offset -= 6 + 16 b .Lwrite_value - addiu $t7, 1 # coeff_index++ - .word 0, 0, 0 + addiu $t5, -22 # bit_offset -= 6 + 16 + .word 0, 0, 0, 0 .Lac_prefix_0000001: # Prefix 0000001 is followed by a 4-bit lookup index. srl $v0, $t0, 20 # index = ((window >> (32 - 7 - 4)) & 15) * sizeof(u16) andi $v0, 30 addu $v0, $t8 # value = table->lut7[index] - lhu $v0, DECDCTSMALLTAB_lut7($v0) + lhu $v0, DECDCTTAB_lut7($v0) sll $t0, 11 # window <<= 7 + 4 - addiu $t5, -11 # bit_offset -= 7 + 4 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -11 # bit_offset -= 7 + 4 + .word 0 .Lac_prefix_00000001: # Prefix 00000001 is followed by a 5-bit lookup index. srl $v0, $t0, 18 # index = ((window >> (32 - 8 - 5)) & 31) * sizeof(u16) andi $v0, 62 addu $v0, $t8 # value = table->lut8[index] - lhu $v0, DECDCTSMALLTAB_lut8($v0) + lhu $v0, DECDCTTAB_lut8($v0) sll $t0, 13 # window <<= 8 + 5 - addiu $t5, -13 # bit_offset -= 8 + 5 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -13 # bit_offset -= 8 + 5 + .word 0 .Lac_prefix_000000001: # Prefix 000000001 is followed by a 5-bit lookup index. srl $v0, $t0, 17 # index = ((window >> (32 - 9 - 5)) & 31) * sizeof(u16) andi $v0, 62 addu $v0, $t8 # value = table->lut9[index] - lhu $v0, DECDCTSMALLTAB_lut9($v0) + lhu $v0, DECDCTTAB_lut9($v0) sll $t0, 14 # window <<= 9 + 5 - addiu $t5, -14 # bit_offset -= 9 + 5 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -14 # bit_offset -= 9 + 5 + .word 0 .Lac_prefix_0000000001: # Prefix 0000000001 is followed by a 5-bit lookup index. srl $v0, $t0, 16 # index = ((window >> (32 - 10 - 5)) & 31) * sizeof(u16) andi $v0, 62 addu $v0, $t8 # value = table->lut10[index] - lhu $v0, DECDCTSMALLTAB_lut10($v0) + lhu $v0, DECDCTTAB_lut10($v0) sll $t0, 15 # window <<= 10 + 5 - addiu $t5, -15 # bit_offset -= 10 + 5 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -15 # bit_offset -= 10 + 5 + .word 0 .Lac_prefix_00000000001: # Prefix 00000000001 is followed by a 5-bit lookup index. srl $v0, $t0, 15 # index = ((window >> (32 - 11 - 5)) & 31) * sizeof(u16) andi $v0, 62 addu $v0, $t8 # value = table->lut11[index] - lhu $v0, DECDCTSMALLTAB_lut11($v0) + lhu $v0, DECDCTTAB_lut11($v0) sll $t0, 16 # window <<= 11 + 5 - addiu $t5, -16 # bit_offset -= 11 + 5 b .Lwrite_value - addiu $t7, 1 # coeff_index++ + addiu $t5, -16 # bit_offset -= 11 + 5 + .word 0 .Lac_prefix_000000000001: # Prefix 000000000001 is followed by a 5-bit lookup index. srl $v0, $t0, 14 # index = ((window >> (32 - 12 - 5)) & 31) * sizeof(u16) andi $v0, 62 addu $v0, $t8 # value = table->lut12[index] - lhu $v0, DECDCTSMALLTAB_lut12($v0) + lhu $v0, DECDCTTAB_lut12($v0) sll $t0, 17 # window <<= 12 + 5 - addiu $t5, -17 # bit_offset -= 12 + 5 b .Lwrite_value - addiu $t7, 1 # coeff_index++ - - # Prefix 0000000000001 is not valid. - beqz $t0, .Lstop_processing - nop - jr $ra - li $v0, -1 - .word 0, 0, 0, 0 - - # Prefix 00000000000001 is not valid. - beqz $t0, .Lstop_processing - nop - jr $ra - li $v0, -1 - .word 0, 0, 0, 0 - - # Prefix 000000000000001 is not valid. - beqz $t0, .Lstop_processing - nop - jr $ra - li $v0, -1 - .word 0, 0, 0, 0 - - # Prefix 0000000000000001 is not valid. - beqz $t0, .Lstop_processing - nop - jr $ra - li $v0, -1 - #.word 0, 0, 0, 0 + addiu $t5, -17 # bit_offset -= 12 + 5 + .word 0 .Lupdate_window_and_write: sllv $t0, $t0, $v1 # window <<= length -- cgit v1.2.3 From 4dbf47f129a55428b90df2805228fbd481e1d117 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Thu, 27 Oct 2022 12:04:11 +0200 Subject: Fix SPU_TRANSFER_BY_IO mode, add IRQ/DMA enums --- libpsn00b/include/psxcd.h | 4 +- libpsn00b/include/psxetc.h | 35 ++++++++++++++-- libpsn00b/include/psxspu.h | 5 ++- libpsn00b/psxcd/psxcd.c | 2 +- libpsn00b/psxetc/interrupts.c | 8 ++-- libpsn00b/psxpress/vlc.s | 9 ++--- libpsn00b/psxspu/common.c | 93 ++++++++++++++++++++++++++++--------------- 7 files changed, 107 insertions(+), 49 deletions(-) (limited to 'libpsn00b/psxpress/vlc.s') diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index 0460f20..bd89f53 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -136,7 +136,7 @@ extern "C" { int CdInit(void); CdlLOC* CdIntToPos(int i, CdlLOC *p); -int CdPosToInt(CdlLOC *p); +int CdPosToInt(const CdlLOC *p); int CdGetToc(CdlLOC *toc); int CdControl(uint8_t com, const void *param, uint8_t *result); @@ -159,7 +159,7 @@ uint32_t CdReadCallback(CdlCB func); int CdStatus(void); int CdMode(void); -int CdMix(CdlATV *vol); +int CdMix(const CdlATV *vol); /* ORIGINAL CODE */ CdlDIR* CdOpenDir(const char* path); diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h index 24485d9..3b18784 100644 --- a/libpsn00b/include/psxetc.h +++ b/libpsn00b/include/psxetc.h @@ -6,16 +6,43 @@ #ifndef __PSXETC_H #define __PSXETC_H +/* IRQ and DMA channel definitions */ + +typedef enum _IRQ_Channel { + IRQ_VBLANK = 0, + IRQ_GPU = 1, + IRQ_CD = 2, + IRQ_DMA = 3, + IRQ_TIMER0 = 4, + IRQ_TIMER1 = 5, + IRQ_TIMER2 = 6, + IRQ_SIO0 = 7, + IRQ_SIO1 = 8, + IRQ_SPU = 9, + IRQ_GUN = 10, + IRQ_PIO = 10 +} IRQ_Channel; + +typedef enum _DMA_Channel { + DMA_MDEC_IN = 0, + DMA_MDEC_OUT = 1, + DMA_GPU = 2, + DMA_CD = 3, + DMA_SPU = 4, + DMA_PIO = 5, + DMA_OTC = 6 +} DMA_Channel; + /* Public API */ #ifdef __cplusplus extern "C" { #endif -void *InterruptCallback(int irq, void (*func)(void)); -void *GetInterruptCallback(int irq); -void *DMACallback(int dma, void (*func)(void)); -void *GetDMACallback(int dma); +void *InterruptCallback(IRQ_Channel irq, void (*func)(void)); +void *GetInterruptCallback(IRQ_Channel irq); +void *DMACallback(DMA_Channel dma, void (*func)(void)); +void *GetDMACallback(DMA_Channel dma); int ResetCallback(void); void RestartCallback(void); diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index 7858e88..05737f7 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -125,8 +125,9 @@ extern "C" { void SpuInit(void); -void SpuRead(uint32_t *data, size_t size); -void SpuWrite(const uint32_t *data, size_t size); +size_t SpuRead(uint32_t *data, size_t size); +size_t SpuWrite(const uint32_t *data, size_t size); +size_t SpuWritePartly(const uint32_t *data, size_t size); SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode); uint32_t SpuSetTransferStartAddr(uint32_t addr); int SpuIsTransferCompleted(int mode); diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index d8d0686..9392d30 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -208,7 +208,7 @@ CdlLOC *CdIntToPos(int i, CdlLOC *p) { } -int CdPosToInt(CdlLOC *p) +int CdPosToInt(const CdlLOC *p) { return ((75*(btoi(p->minute)*60))+(75*btoi(p->second))+btoi(p->sector))-150; } diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c index cc9d12c..0d926c4 100644 --- a/libpsn00b/psxetc/interrupts.c +++ b/libpsn00b/psxetc/interrupts.c @@ -98,7 +98,7 @@ static void _global_dma_handler(void) { /* IRQ and DMA handler API */ -void *InterruptCallback(int irq, void (*func)(void)) { +void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) return 0; @@ -115,14 +115,14 @@ void *InterruptCallback(int irq, void (*func)(void)) { return old_callback; } -void *GetInterruptCallback(int irq) { +void *GetInterruptCallback(IRQ_Channel irq) { if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) return 0; return _irq_handlers[irq]; } -void *DMACallback(int dma, void (*func)(void)) { +void *DMACallback(DMA_Channel dma, void (*func)(void)) { if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) return 0; @@ -150,7 +150,7 @@ void *DMACallback(int dma, void (*func)(void)) { return old_callback; } -void *GetDMACallback(int dma) { +void *GetDMACallback(DMA_Channel dma) { if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) return 0; diff --git a/libpsn00b/psxpress/vlc.s b/libpsn00b/psxpress/vlc.s index 75e33d3..f3a1c67 100644 --- a/libpsn00b/psxpress/vlc.s +++ b/libpsn00b/psxpress/vlc.s @@ -145,17 +145,16 @@ _vlc_skip_context_load: li $v0, -1 .Lprocess_ac_coefficient: # if (coeff_index) - # Start counting the number of leading zeroes/ones using the GTE. This - # takes 2 more cycles. - mtc2 $t0, $30 - - # Check whether the prefix code is one of the shorter, more common ones. + # Check whether the prefix code is one of the shorter, more common ones, + # and start counting the number of leading zeroes/ones using the GTE (which + # takes 2 more cycles). srl $v0, $t0, 30 li $v1, 3 beq $v0, $v1, .Lac_prefix_11 li $v1, 2 beq $v0, $v1, .Lac_prefix_10 li $v1, 1 + mtc2 $t0, $30 beq $v0, $v1, .Lac_prefix_01 nop diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c index 1613ca9..ca4b201 100644 --- a/libpsn00b/psxspu/common.c +++ b/libpsn00b/psxspu/common.c @@ -8,6 +8,8 @@ #include #include +#define _min(x, y) (((x) < (y)) ? (x) : (y)) + #define WRITABLE_AREA_ADDR 0x200 #define DMA_CHUNK_LENGTH 16 #define STATUS_TIMEOUT 0x100000 @@ -28,7 +30,7 @@ static void _wait_status(uint16_t mask, uint16_t value) { _sdk_log("status register timeout (0x%04x)\n", SPU_STAT); } -static void _dma_transfer(uint32_t *data, size_t length, int write) { +static size_t _dma_transfer(uint32_t *data, size_t length, int write) { if (length % 4) _sdk_log("can't transfer a number of bytes that isn't multiple of 4\n"); @@ -38,8 +40,7 @@ static void _dma_transfer(uint32_t *data, size_t length, int write) { length += DMA_CHUNK_LENGTH - 1; } - SPU_DMA_CTRL = 0x0004; // Reset transfer mode - SPU_CTRL &= 0xffcf; // Disable DMA request + SPU_CTRL &= 0xffcf; // Disable DMA request _wait_status(0x0030, 0x0000); // Enable DMA request for writing (2) or reading (3) @@ -47,7 +48,7 @@ static void _dma_transfer(uint32_t *data, size_t length, int write) { SPU_ADDR = _transfer_addr; SPU_CTRL |= ctrl; - _wait_status(0x0430, ctrl); + _wait_status(0x0030, ctrl); DMA_MADR(4) = (uint32_t) data; if (length < DMA_CHUNK_LENGTH) @@ -56,6 +57,42 @@ static void _dma_transfer(uint32_t *data, size_t length, int write) { DMA_BCR(4) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); DMA_CHCR(4) = 0x01000200 | write; + return length; +} + +static size_t _manual_write(const uint16_t *data, size_t length) { + if (length % 2) + _sdk_log("can't transfer a number of bytes that isn't multiple of 2\n"); + + length /= 2; + + SPU_CTRL &= 0xffcf; // Disable DMA request + _wait_status(0x0030, 0x0000); + + // Manual transfers have to be done by filling up the SPU's transfer buffer + // and then letting the SPU empty it one 64-byte chunk at a time. + uint16_t addr = _transfer_addr; + + while (length) { + size_t chunk = _min(DMA_CHUNK_LENGTH * 2, length); + length -= chunk; + + SPU_ADDR = addr; + addr += chunk / 4; + + for (; chunk; chunk--) + SPU_DATA = *(data++); + + SPU_CTRL |= 0x0010; // Manual transfer mode + _wait_status(0x0030, 0x0010); + _wait_status(0x0400, 0x0000); + + // This additional delay is required according to nocash docs. + for (int i = 0; i < 1000; i++) + __asm__ volatile(""); + } + + return length; } /* Public API */ @@ -81,17 +118,16 @@ void SpuInit(void) { DMA_DPCR |= 0x000b0000; // Enable DMA4 DMA_CHCR(4) = 0x00000201; // Stop DMA4 - SPU_CTRL = 0xc011; // Enable SPU, DAC, CD audio, set manual transfer mode - _wait_status(0x001f, 0x0011); + SPU_DMA_CTRL = 0x0004; // Reset transfer mode + SPU_CTRL = 0xc001; // Enable SPU, DAC, CD audio, disable DMA request + _wait_status(0x003f, 0x0001); - // Upload a dummy ADPCM block to the first 16 bytes of SPU RAM. This may be - // freely used or overwritten. - SPU_ADDR = WRITABLE_AREA_ADDR; - _wait_status(0x0400, 0x0000); + // Upload a dummy looping ADPCM block to the first 16 bytes of SPU RAM. + // This may be freely used or overwritten. + uint32_t block[4] = { 0x0500, 0, 0, 0 }; - SPU_DATA = 0x0500; - for (int i = 7; i; i--) - SPU_DATA = 0x0000; + _transfer_addr = WRITABLE_AREA_ADDR; + _manual_write((const uint16_t *) block, 16); // "Play" the dummy block on all channels. This will reset the start // address and ADSR envelope status of each channel. @@ -111,31 +147,26 @@ void SpuInit(void) { SPU_CD_VOL_R = 0x7fff; } -void SpuRead(uint32_t *data, size_t size) { - _dma_transfer(data, size, 0); +size_t SpuRead(uint32_t *data, size_t size) { + return _dma_transfer(data, size, 0) * 4; } -void SpuWrite(const uint32_t *data, size_t size) { +size_t SpuWrite(const uint32_t *data, size_t size) { if (_transfer_addr < WRITABLE_AREA_ADDR) - return; + return 0; // I/O transfer mode is not that useful, but whatever. - if (_transfer_mode) { - SPU_ADDR = _transfer_addr; - SPU_CTRL = (SPU_CTRL & 0xffcf) | 0x0010; // Manual transfer mode - _wait_status(0x0400, 0x0000); - - for (int i = size; i; i -= 4) { - uint32_t value = *(data++); - - SPU_DATA = (uint16_t) value; - SPU_DATA = (uint16_t) (value >> 16); - } + if (_transfer_mode) + return _manual_write((const uint16_t *) data, size) * 2; + else + return _dma_transfer((uint32_t *) data, size, 1) * 4; +} - return; - } +size_t SpuWritePartly(const uint32_t *data, size_t size) { + size_t _size = SpuWrite(data, size); - _dma_transfer((uint32_t *) data, size, 1); + _transfer_addr += (_size + 1) / 2; + return _size; } SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode) { -- cgit v1.2.3