diff --git a/Makefile b/Makefile index 5c2a807b..e6eae1d8 100755 --- a/Makefile +++ b/Makefile @@ -271,7 +271,6 @@ $(BUILD_DIR)/lib/src/unknown_0C9C90.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 $(BUILD_DIR)/lib/src/osEepromWrite.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osEepromRead.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/osSetTimer.o: OPT_FLAGS := -O1 -$(BUILD_DIR)/lib/src/osVirtualToPhysical.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/%.o: MIPSISET := -mips2 $(BUILD_DIR)/lib/src/mips1/%.o: MIPSISET := -mips1 diff --git a/lib/asm/non_matchings/unknown_0C9970/osAiSetNextBuffer.s b/lib/asm/non_matchings/unknown_0C9970/osAiSetNextBuffer.s deleted file mode 100644 index 0b80d732..00000000 --- a/lib/asm/non_matchings/unknown_0C9970/osAiSetNextBuffer.s +++ /dev/null @@ -1,52 +0,0 @@ -glabel osAiSetNextBuffer -/* 0C9970 800C8D70 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 0C9974 800C8D74 3C0F800E */ lui $t7, %hi(D_800E3790) # $t7, 0x800e -/* 0C9978 800C8D78 91EF3790 */ lbu $t7, %lo(D_800E3790)($t7) -/* 0C997C 800C8D7C AFA40020 */ sw $a0, 0x20($sp) -/* 0C9980 800C8D80 8FAE0020 */ lw $t6, 0x20($sp) -/* 0C9984 800C8D84 AFBF0014 */ sw $ra, 0x14($sp) -/* 0C9988 800C8D88 AFA50024 */ sw $a1, 0x24($sp) -/* 0C998C 800C8D8C 11E00003 */ beqz $t7, .L800C8D9C -/* 0C9990 800C8D90 AFAE001C */ sw $t6, 0x1c($sp) -/* 0C9994 800C8D94 25D8E000 */ addiu $t8, $t6, -0x2000 -/* 0C9998 800C8D98 AFB8001C */ sw $t8, 0x1c($sp) -.L800C8D9C: -/* 0C999C 800C8D9C 8FB90020 */ lw $t9, 0x20($sp) -/* 0C99A0 800C8DA0 8FA80024 */ lw $t0, 0x24($sp) -/* 0C99A4 800C8DA4 24012000 */ li $at, 8192 -/* 0C99A8 800C8DA8 03284821 */ addu $t1, $t9, $t0 -/* 0C99AC 800C8DAC 312A3FFF */ andi $t2, $t1, 0x3fff -/* 0C99B0 800C8DB0 15410005 */ bne $t2, $at, .L800C8DC8 -/* 0C99B4 800C8DB4 00000000 */ nop -/* 0C99B8 800C8DB8 240B0001 */ li $t3, 1 -/* 0C99BC 800C8DBC 3C01800E */ lui $at, %hi(D_800E3790) # $at, 0x800e -/* 0C99C0 800C8DC0 10000003 */ b .L800C8DD0 -/* 0C99C4 800C8DC4 A02B3790 */ sb $t3, %lo(D_800E3790)($at) -.L800C8DC8: -/* 0C99C8 800C8DC8 3C01800E */ lui $at, %hi(D_800E3790) # $at, 0x800e -/* 0C99CC 800C8DCC A0203790 */ sb $zero, %lo(D_800E3790)($at) -.L800C8DD0: -/* 0C99D0 800C8DD0 0C034D9C */ jal __osAiDeviceBusy -/* 0C99D4 800C8DD4 00000000 */ nop -/* 0C99D8 800C8DD8 10400003 */ beqz $v0, .L800C8DE8 -/* 0C99DC 800C8DDC 00000000 */ nop -/* 0C99E0 800C8DE0 10000009 */ b .L800C8E08 -/* 0C99E4 800C8DE4 2402FFFF */ li $v0, -1 -.L800C8DE8: -/* 0C99E8 800C8DE8 0C03233C */ jal osVirtualToPhysical -/* 0C99EC 800C8DEC 8FA4001C */ lw $a0, 0x1c($sp) -/* 0C99F0 800C8DF0 3C0CA450 */ lui $t4, 0xa450 -/* 0C99F4 800C8DF4 AD820000 */ sw $v0, ($t4) -/* 0C99F8 800C8DF8 8FAD0024 */ lw $t5, 0x24($sp) -/* 0C99FC 800C8DFC 3C0FA450 */ lui $t7, %hi(D_A4500004) # $t7, 0xa450 -/* 0C9A00 800C8E00 00001025 */ move $v0, $zero -/* 0C9A04 800C8E04 ADED0004 */ sw $t5, %lo(D_A4500004)($t7) -.L800C8E08: -/* 0C9A08 800C8E08 8FBF0014 */ lw $ra, 0x14($sp) -/* 0C9A0C 800C8E0C 27BD0020 */ addiu $sp, $sp, 0x20 -/* 0C9A10 800C8E10 03E00008 */ jr $ra -/* 0C9A14 800C8E14 00000000 */ nop - -/* 0C9A18 800C8E18 00000000 */ nop -/* 0C9A1C 800C8E1C 00000000 */ nop - diff --git a/lib/src/mips1/al/reverb.c b/lib/src/mips1/al/reverb.c index c1a17c29..eb4ec0b3 100644 --- a/lib/src/mips1/al/reverb.c +++ b/lib/src/mips1/al/reverb.c @@ -5,7 +5,7 @@ #include "macros.h" #include "libultra_internal.h" #include "audio_internal.h" -#include "../../osVirtualToPhysical.h" +#include "../../os/osVirtualToPhysical.h" /************ .data ************/ diff --git a/lib/src/os/osAiSetNextBuffer.c b/lib/src/os/osAiSetNextBuffer.c new file mode 100644 index 00000000..cf93fef8 --- /dev/null +++ b/lib/src/os/osAiSetNextBuffer.c @@ -0,0 +1,41 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8D70 */ + +#include "types.h" +#include "macros.h" +#include +#include +#include "osVirtualToPhysical.h" + +u8 hdwrBugFlag = 0; + +/** + * It is worth noting that a previous hardware bug has been fixed by a software + * patch in osAiSetNextBuffer. This bug occurred when the address of the end of the + * buffer specified by osAiSetNextBuffer was at a specific value. This value + * occurred when the following was true: + * + * (vaddr + nbytes) & 0x00003FFF == 0x00002000 + * + * (when the buffer ends with address of lower 14 bits 0x2000) In this case, the + * DMA transfer does not complete successfully. This can cause clicks and pops in + * the audio output. This bug no longer requires special handling by the application + * because it is now patched by osAiSetNextBuffer. + */ +s32 osAiSetNextBuffer(void *bufPtr, u32 size) { + char *bptr = bufPtr; + if (hdwrBugFlag != 0) + bptr -= 0x2000; + + if ((((u32)bufPtr + size) & 0x3fff) == 0x2000) + hdwrBugFlag = 1; + else + hdwrBugFlag = 0; + + if (__osAiDeviceBusy()) + return -1; + + IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); + IO_WRITE(AI_LEN_REG, size); + return 0; +} diff --git a/lib/src/osVirtualToPhysical.c b/lib/src/os/osVirtualToPhysical.c similarity index 100% rename from lib/src/osVirtualToPhysical.c rename to lib/src/os/osVirtualToPhysical.c diff --git a/lib/src/osVirtualToPhysical.h b/lib/src/os/osVirtualToPhysical.h similarity index 100% rename from lib/src/osVirtualToPhysical.h rename to lib/src/os/osVirtualToPhysical.h diff --git a/lib/src/unknown_0C9970.c b/lib/src/unknown_0C9970.c deleted file mode 100644 index 92294c27..00000000 --- a/lib/src/unknown_0C9970.c +++ /dev/null @@ -1,9 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8D70 */ - -#include "types.h" -#include "macros.h" - -u8 D_800E3790 = 0; - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9970/osAiSetNextBuffer.s") diff --git a/lib/src/unknown_0D29F0.c b/lib/src/unknown_0D29F0.c index fcd38aaa..daad706c 100644 --- a/lib/src/unknown_0D29F0.c +++ b/lib/src/unknown_0D29F0.c @@ -4,7 +4,7 @@ #include "types.h" #include "macros.h" #include "libultra_internal.h" -#include "osVirtualToPhysical.h" +#include "os/osVirtualToPhysical.h" typedef struct { diff --git a/lib/src/unknown_0D3160.c b/lib/src/unknown_0D3160.c index 5fd3605b..659ac3dc 100644 --- a/lib/src/unknown_0D3160.c +++ b/lib/src/unknown_0D3160.c @@ -5,7 +5,7 @@ #include "macros.h" #include "libultra_internal.h" #include "PR/rcp.h" -#include "osVirtualToPhysical.h" +#include "os/osVirtualToPhysical.h" GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3160/__osDisableInt.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3160/__osRestoreInt.s")