From 7cd59fbdadf8735b38e9cd2acf7697e644dcd796 Mon Sep 17 00:00:00 2001 From: fig02 Date: Fri, 2 May 2025 04:44:09 -0400 Subject: Audio internal lib: Merge dcache.c and aisetnextbuf.c into os.c (#2522) --- spec/spec | 3 +- src/audio/internal/aisetnextbuf.c | 44 --------------------------- src/audio/internal/dcache.c | 16 ---------- src/audio/internal/os.c | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 62 deletions(-) delete mode 100644 src/audio/internal/aisetnextbuf.c delete mode 100644 src/audio/internal/dcache.c create mode 100644 src/audio/internal/os.c diff --git a/spec/spec b/spec/spec index ffbd4ac81..60437c4bf 100644 --- a/spec/spec +++ b/spec/spec @@ -681,8 +681,7 @@ beginseg include "$(BUILD_DIR)/src/audio/internal/heap.o" include "$(BUILD_DIR)/src/audio/internal/load.o" include "$(BUILD_DIR)/src/audio/internal/thread.o" - include "$(BUILD_DIR)/src/audio/internal/dcache.o" - include "$(BUILD_DIR)/src/audio/internal/aisetnextbuf.o" + include "$(BUILD_DIR)/src/audio/internal/os.o" #if OOT_PAL_N64 pad_text pad_text diff --git a/src/audio/internal/aisetnextbuf.c b/src/audio/internal/aisetnextbuf.c deleted file mode 100644 index bb6b0f0b7..000000000 --- a/src/audio/internal/aisetnextbuf.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "ultra64.h" - -/** - * Submits an audio buffer to be consumed by the Audio DAC. The audio interface can queue a second DMA while another - * is in progress and automatically begin the next one as soon as the current DMA completes. If there is already a - * second DMA queued (DMA is full), -1 is returned to indicate the buffer could not be submitted. - * - * Note that this is not the same as the original libultra osAiSetNextBuffer, see comments in the function. - * - * @param buf Next audio buffer. Must be an 8-byte aligned KSEG0 (0x80XXXXXX) address. - * @param size Length of next audio buffer in bytes, maximum size 0x40000 bytes / 256 KiB. Should be a multiple of 8. - * @return 0 if the DMA was enqueued successfully, -1 if the DMA could not yet be queued. - */ -s32 osAiSetNextBuffer(void* buf, u32 size) { - static u8 hdwrBugFlag = false; - u32 bufAdjusted = (u32)buf; - s32 status; - - // Workaround for a hardware bug. If the end of the previous buffer was on an 0x2000 byte boundary, adjust the - // start of the next buffer. - if (hdwrBugFlag) { - bufAdjusted -= 0x2000; - } - // Current buffer ends on an 0x2000 byte boundary, set flag to account for this in next buffer. - if ((((u32)buf + size) & 0x1FFF) == 0) { - hdwrBugFlag = true; - } else { - hdwrBugFlag = false; - } - - // Originally a call to __osAiDeviceBusy - //! @bug The original __osAiDeviceBusy call was above the hardware bug workaround to ensure that it was only - //! performed when a transfer was guaranteed to start. If this condition passes and this function returns without - //! submitting a buffer for DMA, the code above will lose track of when to apply the workaround. - status = IO_READ(AI_STATUS_REG); - if (status & AI_STATUS_FIFO_FULL) { - return -1; - } - - // OS_K0_TO_PHYSICAL replaces osVirtualToPhysical, this replacement assumes that only KSEG0 addresses are given. - IO_WRITE(AI_DRAM_ADDR_REG, OS_K0_TO_PHYSICAL(bufAdjusted)); - IO_WRITE(AI_LEN_REG, size); - return 0; -} diff --git a/src/audio/internal/dcache.c b/src/audio/internal/dcache.c deleted file mode 100644 index 5c50a6997..000000000 --- a/src/audio/internal/dcache.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "ultra64.h" -#include "z64audio.h" - -void Audio_InvalDCache(void* buf, s32 size) { - OSIntMask prevMask = osSetIntMask(OS_IM_NONE); - - osInvalDCache(buf, size); - osSetIntMask(prevMask); -} - -void Audio_WritebackDCache(void* buf, s32 size) { - OSIntMask prevMask = osSetIntMask(OS_IM_NONE); - - osWritebackDCache(buf, size); - osSetIntMask(prevMask); -} diff --git a/src/audio/internal/os.c b/src/audio/internal/os.c new file mode 100644 index 000000000..4bbb0d2fd --- /dev/null +++ b/src/audio/internal/os.c @@ -0,0 +1,63 @@ +/** + * Original Filename: os.c + */ + +#include "ultra64.h" +#include "z64audio.h" + +void Audio_InvalDCache(void* buf, s32 size) { + OSIntMask prevMask = osSetIntMask(OS_IM_NONE); + + osInvalDCache(buf, size); + osSetIntMask(prevMask); +} + +void Audio_WritebackDCache(void* buf, s32 size) { + OSIntMask prevMask = osSetIntMask(OS_IM_NONE); + + osWritebackDCache(buf, size); + osSetIntMask(prevMask); +} + +/** + * Submits an audio buffer to be consumed by the Audio DAC. The audio interface can queue a second DMA while another + * is in progress and automatically begin the next one as soon as the current DMA completes. If there is already a + * second DMA queued (DMA is full), -1 is returned to indicate the buffer could not be submitted. + * + * Note that this is not the same as the original libultra osAiSetNextBuffer, see comments in the function. + * + * @param buf Next audio buffer. Must be an 8-byte aligned KSEG0 (0x80XXXXXX) address. + * @param size Length of next audio buffer in bytes, maximum size 0x40000 bytes / 256 KiB. Should be a multiple of 8. + * @return 0 if the DMA was enqueued successfully, -1 if the DMA could not yet be queued. + */ +s32 osAiSetNextBuffer(void* buf, u32 size) { + static u8 hdwrBugFlag = false; + u32 bufAdjusted = (u32)buf; + s32 status; + + // Workaround for a hardware bug. If the end of the previous buffer was on an 0x2000 byte boundary, adjust the + // start of the next buffer. + if (hdwrBugFlag) { + bufAdjusted -= 0x2000; + } + // Current buffer ends on an 0x2000 byte boundary, set flag to account for this in next buffer. + if ((((u32)buf + size) & 0x1FFF) == 0) { + hdwrBugFlag = true; + } else { + hdwrBugFlag = false; + } + + // Originally a call to __osAiDeviceBusy + //! @bug The original __osAiDeviceBusy call was above the hardware bug workaround to ensure that it was only + //! performed when a transfer was guaranteed to start. If this condition passes and this function returns without + //! submitting a buffer for DMA, the code above will lose track of when to apply the workaround. + status = IO_READ(AI_STATUS_REG); + if (status & AI_STATUS_FIFO_FULL) { + return -1; + } + + // OS_K0_TO_PHYSICAL replaces osVirtualToPhysical, this replacement assumes that only KSEG0 addresses are given. + IO_WRITE(AI_DRAM_ADDR_REG, OS_K0_TO_PHYSICAL(bufAdjusted)); + IO_WRITE(AI_LEN_REG, size); + return 0; +} -- cgit v1.2.3