diff --git a/include/ultra64.h b/include/ultra64.h index d309026b97..49323cc2bd 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -11,6 +11,7 @@ #include "ultra64/sptask.h" #include "ultra64/thread.h" #include "ultra64/rcp.h" +#include "ultra64/rdp.h" #include "ultra64/rsp.h" #include "ultra64/vi.h" diff --git a/include/ultra64/hardware.h b/include/ultra64/hardware.h index c3eb8dd4cb..ae6470d51d 100644 --- a/include/ultra64/hardware.h +++ b/include/ultra64/hardware.h @@ -96,6 +96,7 @@ #define SI_STATUS_INTERRUPT (1 << 12) #define PIF_RAM_START 0x1FC007C0 +#define PIF_RAM_SIZE 0x40 #define MI_INIT_MODE_REG 0x04300000 #define MI_MODE_REG MI_INIT_MODE_REG diff --git a/include/ultra64/rdp.h b/include/ultra64/rdp.h new file mode 100644 index 0000000000..b4b3bb532f --- /dev/null +++ b/include/ultra64/rdp.h @@ -0,0 +1,45 @@ +#ifndef ULTRA64_RDP_H +#define ULTRA64_RDP_H + +/* DP Command Registers */ +#define DPC_START_REG 0x04100000 +#define DPC_END_REG 0x04100004 +#define DPC_CURRENT_REG 0x04100008 +#define DPC_STATUS_REG 0x0410000C +#define DPC_CLOCK_REG 0x04100010 +#define DPC_BUFBUSY_REG 0x04100014 +#define DPC_PIPEBUSY_REG 0x04100018 +#define DPC_TMEM_REG 0x0410001C + +/* DP Span Registers */ +#define DPS_TBIST_REG 0x04200000 +#define DPS_TEST_MODE_REG 0x04200004 +#define DPS_BUFTEST_ADDR_REG 0x04200008 +#define DPS_BUFTEST_DATA_REG 0x0420000C + +/* DP Status Read Flags */ +#define DPC_STATUS_XBUS_DMEM_DMA (1 << 0) +#define DPC_STATUS_FREEZE (1 << 1) +#define DPC_STATUS_FLUSH (1 << 2) +#define DPC_STATUS_START_GCLK (1 << 3) +#define DPC_STATUS_TMEM_BUSY (1 << 4) +#define DPC_STATUS_PIPE_BUSY (1 << 5) +#define DPC_STATUS_CMD_BUSY (1 << 6) +#define DPC_STATUS_CBUF_READY (1 << 7) +#define DPC_STATUS_DMA_BUSY (1 << 8) +#define DPC_STATUS_END_VALID (1 << 9) +#define DPC_STATUS_START_VALID (1 << 10) + +/* DP Status Write Flags */ +#define DPC_CLR_XBUS_DMEM_DMA (1 << 0) +#define DPC_SET_XBUS_DMEM_DMA (1 << 1) +#define DPC_CLR_FREEZE (1 << 2) +#define DPC_SET_FREEZE (1 << 3) +#define DPC_CLR_FLUSH (1 << 4) +#define DPC_SET_FLUSH (1 << 5) +#define DPC_CLR_TMEM_CTR (1 << 6) +#define DPC_CLR_PIPE_CTR (1 << 7) +#define DPC_CLR_CMD_CTR (1 << 8) +#define DPC_CLR_CLOCK_CTR (1 << 9) + +#endif diff --git a/include/variables.h b/include/variables.h index 93b7790cb2..6249405258 100644 --- a/include/variables.h +++ b/include/variables.h @@ -8,7 +8,7 @@ // pre-boot variables extern u32 osTvType; extern u32 osRomType; -extern u32 osRomBase; +extern uintptr_t osRomBase; extern u32 osResetType; extern u32 osCicId; extern u32 osVersion; diff --git a/spec b/spec index 2983af4dc4..c9458d9390 100644 --- a/spec +++ b/spec @@ -170,7 +170,7 @@ beginseg include "build/src/libultra/voice/voicecontwrite20.o" include "build/src/libultra/io/crc.o" include "build/src/libultra/os/getactivequeue.o" - include "build/src/libultra/gu/normalize.o" + include "build/asm/boot/normalize.text.o" include "build/asm/boot/setcompare.text.o" include "build/asm/boot/getcompare.text.o" include "build/src/libultra/io/dpgetstat.o" diff --git a/src/libultra/gu/normalize.c b/src/libultra/gu/normalize.c deleted file mode 100644 index 3fdbbe880a..0000000000 --- a/src/libultra/gu/normalize.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "global.h" - -#pragma GLOBAL_ASM("asm/non_matchings/boot/normalize/guNormalize.s") diff --git a/src/libultra/io/aigetlen.c b/src/libultra/io/aigetlen.c index e3e7289aca..58d8db4875 100644 --- a/src/libultra/io/aigetlen.c +++ b/src/libultra/io/aigetlen.c @@ -1,5 +1,5 @@ #include "global.h" u32 osAiGetLength(void) { - return *(u32*)0xA4500004; + return HW_REG(AI_LEN_REG, u32); } diff --git a/src/libultra/io/aisetfreq.c b/src/libultra/io/aisetfreq.c index ef0a8d2deb..8702941b9a 100644 --- a/src/libultra/io/aisetfreq.c +++ b/src/libultra/io/aisetfreq.c @@ -1,3 +1,20 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/aisetfreq/osAiSetFrequency.s") +s32 osAiSetFrequency(u32 frequency) { + u8 bitrate; + f32 dacRateF = ((f32)osViClock / frequency) + 0.5f; + u32 dacRate = dacRateF; + + if (dacRate < 132) { + return -1; + } + + bitrate = (dacRate / 66); + if (bitrate > 16) { + bitrate = 16; + } + + HW_REG(AI_DACRATE_REG, u32) = dacRate - 1; + HW_REG(AI_BITRATE_REG, u32) = bitrate - 1; + return osViClock / (s32)dacRate; +} diff --git a/src/libultra/io/crc.c b/src/libultra/io/crc.c index e2f3fb9912..acae7b4081 100644 --- a/src/libultra/io/crc.c +++ b/src/libultra/io/crc.c @@ -34,7 +34,7 @@ * \f[ m(X) X^n = Q(X) p(X) + R(X) \f] * (\f$ R(X) \f$ is the *remainder after dividing by \f$ p(X) \f$*). * - Therefore, \f$ m(X) X^n - R(X) \f$ is divisible by the generator polynomial. This means that if we append the - * binary number corresponding to \f$ R(X) \f$ to the message and rerun the algorithm, we will get 0 if now errors have + * binary number corresponding to \f$ R(X) \f$ to the message and rerun the algorithm, we will get 0 if no errors have * been introduced. * * diff --git a/src/libultra/io/dpgetstat.c b/src/libultra/io/dpgetstat.c index 763c6622e4..0c4b3073ba 100644 --- a/src/libultra/io/dpgetstat.c +++ b/src/libultra/io/dpgetstat.c @@ -1,5 +1,5 @@ #include "global.h" u32 osDpGetStatus(void) { - return *(u32*)0xA410000C; + return HW_REG(DPC_STATUS_REG, u32); } diff --git a/src/libultra/io/dpsetstat.c b/src/libultra/io/dpsetstat.c index c653a08173..d2655626c6 100644 --- a/src/libultra/io/dpsetstat.c +++ b/src/libultra/io/dpsetstat.c @@ -1,5 +1,5 @@ #include "global.h" void osDpSetStatus(u32 data) { - *(u32*)0xA410000C = data; + HW_REG(DPC_STATUS_REG, u32) = data; } diff --git a/src/libultra/io/pirawdma.c b/src/libultra/io/pirawdma.c index 242a91c24e..07aa1b8221 100644 --- a/src/libultra/io/pirawdma.c +++ b/src/libultra/io/pirawdma.c @@ -1,23 +1,22 @@ #include "global.h" -s32 __osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, size_t size) { - register int stat; +s32 __osPiRawStartDma(s32 direction, uintptr_t devAddr, void* dramAddr, size_t size) { + register int status = HW_REG(PI_STATUS_REG, u32); - stat = *(vu32*)0xA4600010; - while (stat & (2 | 1)) { - stat = *(vu32*)0xA4600010; + while (status & (PI_STATUS_IOBUSY | PI_STATUS_BUSY)) { + status = HW_REG(PI_STATUS_REG, u32); } - *(u32*)0xA4600000 = osVirtualToPhysical(dramAddr); + HW_REG(PI_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); - *(u32*)0xA4600004 = ((osRomBase | devAddr) & 0x1fffffff); + HW_REG(PI_CART_ADDR_REG, u32) = ((osRomBase | devAddr) & 0x1FFFFFFF); switch (direction) { - case 0: - *(u32*)0xA460000C = size - 1; + case OS_READ: + HW_REG(PI_WR_LEN_REG, u32) = size - 1; break; - case 1: - *(u32*)0xA4600008 = size - 1; + case OS_WRITE: + HW_REG(PI_RD_LEN_REG, u32) = size - 1; break; default: return -1; diff --git a/src/libultra/io/si.c b/src/libultra/io/si.c index 6de5874b90..563c682765 100644 --- a/src/libultra/io/si.c +++ b/src/libultra/io/si.c @@ -1,11 +1,11 @@ #include "global.h" -int __osSiDeviceBusy() { - register u32 status; - status = *(u32*)0xA4800018; - if (status & 3) { - return 1; +s32 __osSiDeviceBusy() { + register u32 status = HW_REG(SI_STATUS_REG, u32); + + if (status & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { + return true; } else { - return 0; + return false; } } diff --git a/src/libultra/io/sirawdma.c b/src/libultra/io/sirawdma.c index ff57e21c23..eb62fa2a30 100644 --- a/src/libultra/io/sirawdma.c +++ b/src/libultra/io/sirawdma.c @@ -1,24 +1,24 @@ #include "global.h" s32 __osSiRawStartDma(s32 direction, void* dramAddr) { - if ((*(u32*)0xA4800018 & 0x3) != 0) { + if (HW_REG(SI_STATUS_REG, u32) & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { return -1; } - if (direction == 1) { - osWritebackDCache(dramAddr, 64); + if (direction == OS_WRITE) { + osWritebackDCache(dramAddr, PIF_RAM_SIZE); } - *(u32*)0xA4800000 = osVirtualToPhysical(dramAddr); + HW_REG(SI_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); - if (direction == 0) { - *(u32*)0xA4800004 = 0x1FC007C0; + if (direction == OS_READ) { + HW_REG(SI_PIF_ADDR_RD64B_REG, void*) = (void*)PIF_RAM_START; } else { - *(u32*)0xA4800010 = 0x1FC007C0; + HW_REG(SI_PIF_ADDR_WR64B_REG, void*) = (void*)PIF_RAM_START; } - if (direction == 0) { - osInvalDCache(dramAddr, 64); + if (direction == OS_READ) { + osInvalDCache(dramAddr, PIF_RAM_SIZE); } return 0; } diff --git a/src/libultra/io/sp.c b/src/libultra/io/sp.c index db2e5b4511..c028c76927 100644 --- a/src/libultra/io/sp.c +++ b/src/libultra/io/sp.c @@ -5,6 +5,7 @@ s32 __osSpDeviceBusy(void) { if (status & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { return true; + } else { + return false; } - return false; } diff --git a/src/libultra/io/spgetstat.c b/src/libultra/io/spgetstat.c index 98a3dc23b6..8987b2414a 100644 --- a/src/libultra/io/spgetstat.c +++ b/src/libultra/io/spgetstat.c @@ -1,5 +1,5 @@ #include "global.h" u32 __osSpGetStatus() { - return *(vu32*)0xA4040010; + return HW_REG(SP_STATUS_REG, u32); } diff --git a/src/libultra/io/sprawdma.c b/src/libultra/io/sprawdma.c index 95395a29d5..494f3db50d 100644 --- a/src/libultra/io/sprawdma.c +++ b/src/libultra/io/sprawdma.c @@ -1,17 +1,17 @@ #include "global.h" s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, size_t size) { - if (__osSpDeviceBusy() != 0) { + if (__osSpDeviceBusy()) { return -1; } - *(vu32*)0xA4040000 = devAddr; - *(vu32*)0xA4040004 = osVirtualToPhysical(dramAddr); + HW_REG(SP_MEM_ADDR_REG, u32) = devAddr; + HW_REG(SP_DRAM_ADDR_REG, u32) = osVirtualToPhysical(dramAddr); - if (direction == 0) { - *(vu32*)0xA404000C = size - 1; + if (direction == OS_READ) { + HW_REG(SP_WR_LEN_REG, u32) = size - 1; } else { - *(vu32*)0xA4040008 = size - 1; + HW_REG(SP_RD_LEN_REG, u32) = size - 1; } return 0; diff --git a/src/libultra/io/spsetstat.c b/src/libultra/io/spsetstat.c index 346577218d..eb183eab47 100644 --- a/src/libultra/io/spsetstat.c +++ b/src/libultra/io/spsetstat.c @@ -1,5 +1,5 @@ #include "global.h" void __osSpSetStatus(u32 data) { - *(vu32*)0xA4040010 = data; + HW_REG(SP_STATUS_REG, u32) = data; } diff --git a/src/libultra/io/vi.c b/src/libultra/io/vi.c index 7b64b4449b..ec0b1de700 100644 --- a/src/libultra/io/vi.c +++ b/src/libultra/io/vi.c @@ -17,7 +17,7 @@ void __osViInit(void) { __osViNext->modep = &osViModePalLan1; } else if (osTvType == OS_TV_MPAL) { __osViNext->modep = &osViModeMpalLan1; - } else { + } else { // OS_TV_NTSC or OS_TV_UNK28 __osViNext->modep = &osViModeNtscLan1; }