diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index aa1cda9d..ccc59197 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -10,10 +10,10 @@ jobs: steps: - name: Checkout libogc2 - uses: actions/checkout@v2 + uses: actions/checkout@main - name: Checkout libfat - uses: actions/checkout@v2 + uses: actions/checkout@main with: repository: extremscorner/libfat path: libfat @@ -26,7 +26,7 @@ jobs: working-directory: libfat - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@main with: name: libogc2 path: /opt/devkitpro/libogc2 diff --git a/README.md b/README.md index 03eaaefe..7ec351fc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # libogc2 [![libogc2 build](https://github.com/extremscorner/libogc2/actions/workflows/continuous-integration-workflow.yml/badge.svg)](https://github.com/extremscorner/libogc2/actions/workflows/continuous-integration-workflow.yml) + +## Projects using libogc2 + +- [GCMM](https://github.com/suloku/gcmm) - GameCube memory card manager +- [iplboot](https://github.com/redolution/iplboot) - Minimal GameCube IPL +- [Swiss](https://github.com/emukidid/swiss-gc) - The swiss army knife of GameCube homebrew +- [Wii64/Cube64](https://github.com/emukidid/Wii64) - Nintendo 64 emulator diff --git a/gc/ogc/cache.h b/gc/ogc/cache.h index a70de294..2e2ce6de 100644 --- a/gc/ogc/cache.h +++ b/gc/ogc/cache.h @@ -306,12 +306,13 @@ void L2Enhance(void); void LCEnable(void); void LCDisable(void); +BOOL LCIsEnable(void); void LCLoadBlocks(void *,void *,u32); void LCStoreBlocks(void *,void *,u32); u32 LCLoadData(void *,void *,u32); u32 LCStoreData(void *,void *,u32); u32 LCQueueLength(void); -u32 LCQueueWait(u32); +void LCQueueWait(u32); void LCFlushQueue(void); void LCAlloc(void *,u32); void LCAllocNoInvalidate(void *,u32); diff --git a/gc/ogc/video.h b/gc/ogc/video.h index bfc69353..5ee7e086 100644 --- a/gc/ogc/video.h +++ b/gc/ogc/video.h @@ -87,6 +87,16 @@ void VIDEO_Flush(void); */ void VIDEO_SetBlack(bool black); +void VIDEO_Set3D(bool threeD); + +/*! + * \fn u32 VIDEO_GetRetraceCount(void) + * \brief Get current retrace count + * + * \return retracecount + */ +u32 VIDEO_GetRetraceCount(void); + /*! * \fn u32 VIDEO_GetNextField(void) diff --git a/gc/wiiuse/wpad.h b/gc/wiiuse/wpad.h index 952d9d62..a1203d82 100644 --- a/gc/wiiuse/wpad.h +++ b/gc/wiiuse/wpad.h @@ -45,7 +45,13 @@ enum { WPAD_BALANCE_BOARD, WPAD_MAX_WIIMOTES, }; - + +#define WPAD_LED_NONE 0x00 +#define WPAD_LED_1 0x01 +#define WPAD_LED_2 0x02 +#define WPAD_LED_3 0x04 +#define WPAD_LED_4 0x08 + #define WPAD_BUTTON_2 0x0001 #define WPAD_BUTTON_1 0x0002 #define WPAD_BUTTON_B 0x0004 @@ -168,6 +174,7 @@ typedef void (*WPADDataCallback)(s32 chan, const WPADData *data); typedef void (*WPADShutdownCallback)(s32 chan); s32 WPAD_Init(void); +s32 WPAD_ControlLed(s32 chan,s32 leds); s32 WPAD_ControlSpeaker(s32 chan,s32 enable); s32 WPAD_ReadEvent(s32 chan, WPADData *data); s32 WPAD_DroppedEvents(s32 chan); diff --git a/libogc/cache.c b/libogc/cache.c index 44fe5920..304d419a 100644 --- a/libogc/cache.c +++ b/libogc/cache.c @@ -96,15 +96,12 @@ u32 LCStoreData(void *dstAddr,void *srcAddr,u32 nCount) u32 LCQueueLength(void) { - u32 hid2 = mfspr(920); - return _SHIFTR(hid2,4,4); + return _SHIFTR(mfspr(920),24,4); } -u32 LCQueueWait(u32 len) +void LCQueueWait(u32 len) { - len++; - while(_SHIFTR(mfspr(920),4,4)>=len); - return len; + while(_SHIFTR(mfspr(920),24,4)>len); } void LCFlushQueue(void) diff --git a/libogc/cache_asm.S b/libogc/cache_asm.S index a6e39de9..61de44e1 100644 --- a/libogc/cache_asm.S +++ b/libogc/cache_asm.S @@ -36,31 +36,30 @@ DCFlashInvalidate: mfspr r3,HID0 ori r3,r3,0x0400 mtspr HID0,r3 - isync blr .globl DCEnable DCEnable: + sync mfspr r3,HID0 ori r3,r3,0x4000 mtspr HID0,r3 - isync blr .globl DCDisable DCDisable: + sync mfspr r3,HID0 rlwinm r3,r3,0,18,16 mtspr HID0,r3 - isync blr .globl DCFreeze DCFreeze: + sync mfspr r3,HID0 ori r3,r3,0x1000 mtspr HID0,r3 - isync blr .globl DCUnfreeze @@ -68,7 +67,6 @@ DCUnfreeze: mfspr r3,HID0 rlwinm r3,r3,0,20,18 mtspr HID0,r3 - isync blr .globl DCTouchLoad @@ -98,140 +96,116 @@ DCBlockInvalidate: .globl DCInvalidateRange DCInvalidateRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbi r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbi r0,r3 + addi r3,r3,32 + bdnz 1b blr .globl DCFlushRange DCFlushRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbf r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbf r0,r3 + addi r3,r3,32 + bdnz 1b sc blr .globl DCStoreRange DCStoreRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbst r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbst r0,r3 + addi r3,r3,32 + bdnz 1b sc blr .globl DCFlushRangeNoSync DCFlushRangeNoSync: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbf r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbf r0,r3 + addi r3,r3,32 + bdnz 1b blr .globl DCStoreRangeNoSync DCStoreRangeNoSync: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbst r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbst r0,r3 + addi r3,r3,32 + bdnz 1b blr .globl DCZeroRange DCZeroRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbz r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbz r0,r3 + addi r3,r3,32 + bdnz 1b blr .globl DCTouchRange DCTouchRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - dcbt r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: dcbt r0,r3 + addi r3,r3,32 + bdnz 1b blr .globl ICInvalidateRange ICInvalidateRange: - cmplwi r4, 0 # zero or negative size? + cmplwi r4,0 blelr - clrlwi. r5, r3, 27 # check for lower bits set in address - beq 1f - addi r4, r4, 0x20 -1: - addi r4, r4, 0x1f - srwi r4, r4, 5 - mtctr r4 -2: - icbi r0, r3 - addi r3, r3, 0x20 - bdnz 2b + clrlwi r5,r3,27 + add r4,r4,r5 + addi r4,r4,31 + srwi r4,r4,5 + mtctr r4 +1: icbi r0,r3 + addi r3,r3,32 + bdnz 1b sync isync blr @@ -241,31 +215,30 @@ ICFlashInvalidate: mfspr r3,HID0 ori r3,r3,0x0800 mtspr HID0,r3 - isync blr .globl ICEnable ICEnable: + isync mfspr r3,HID0 ori r3,r3,0x8000 mtspr HID0,r3 - isync blr .globl ICDisable ICDisable: + isync mfspr r3,HID0 rlwinm r3,r3,0,17,15 mtspr HID0,r3 - isync blr .globl ICFreeze ICFreeze: + isync mfspr r3,HID0 ori r3,r3,0x2000 mtspr HID0,r3 - isync blr .globl ICUnfreeze @@ -273,7 +246,6 @@ ICUnfreeze: mfspr r3,HID0 rlwinm r3,r3,0,19,17 mtspr HID0,r3 - isync blr .globl ICBlockInvalidate @@ -292,29 +264,26 @@ L2Init: stw r0,4(sp) stwu sp,-16(sp) stw r31,12(sp) - mfmsr r3 - mr r31,r3 + mfmsr r31 sync li r3,48 mtmsr r3 sync bl L2Disable bl L2GlobalInvalidate - mr r3,r31 - mtmsr r3 + mtmsr r31 lwz r0,20(sp) lwz r31,12(sp) + addi sp,sp,16 mtlr r0 blr .globl L2Enable L2Enable: - sync - mfspr r3,L2CR; + mfspr r3,L2CR oris r0,r3,0x8000 rlwinm r3,r0,0,11,9 mtspr L2CR,r3 - sync blr .globl L2Disable @@ -336,21 +305,45 @@ L2GlobalInvalidate: oris r3,r3,0x0020 mtspr L2CR,r3 1: mfspr r3,L2CR - clrlwi r0,r3,31 - cmplwi r0,0x0000 + clrlwi. r0,r3,31 bne 1b mfspr r3,L2CR rlwinm r3,r3,0,11,9 mtspr L2CR,r3 2: mfspr r3,L2CR - clrlwi r0,r3,31 - cmplwi r0,0x0000 + clrlwi. r0,r3,31 bne 2b lwz r0,12(sp) addi sp,sp,8 mtlr r0 blr + .globl L2SetDataOnly +L2SetDataOnly: + cmpwi r3,0 + beq 1f + mfspr r3,L2CR + oris r3,r3,0x0040 + mtspr L2CR,r3 + blr +1: mfspr r3,L2CR + rlwinm r3,r3,0,10,8 + mtspr L2CR,r3 + blr + + .globl L2SetWriteThrough +L2SetWriteThrough: + cmpwi r3,0 + beq 1f + mfspr r3,L2CR + oris r3,r3,0x0008 + mtspr L2CR,r3 + blr +1: mfspr r3,L2CR + rlwinm r3,r3,0,13,11 + mtspr L2CR,r3 + blr + .globl __LCEnable __LCEnable: mfmsr r5 @@ -361,7 +354,7 @@ __LCEnable: mtctr r4 1: dcbt r0,r3 dcbst r0,r3 - addi r3,r3,32 + addi r3,r3,32 bdnz 1b mfspr r4,HID2 oris r4,r4,0x100f @@ -418,6 +411,12 @@ LCDisable: mtspr HID2,r4 blr + .globl LCIsEnable +LCIsEnable: + mfspr r4,HID2 + extrwi r3,r4,1,3 + blr + .globl LCAllocOneTag LCAllocOneTag: cmpwi r3,0 @@ -448,7 +447,7 @@ LCAllocTags: .globl LCLoadBlocks LCLoadBlocks: extrwi r6,r5,5,25 - clrlwi r4,r4,4 + clrlwi r4,r4,3 or r6,r6,r4 mtspr DMAU,r6 clrlslwi r6,r5,30,2 @@ -460,7 +459,7 @@ LCLoadBlocks: .globl LCStoreBlocks LCStoreBlocks: extrwi r6,r5,5,25 - clrlwi r4,r4,4 + clrlwi r3,r3,3 or r6,r6,r3 mtspr DMAU,r6 clrlslwi r6,r5,30,2 @@ -468,4 +467,3 @@ LCStoreBlocks: ori r6,r6,0x0002 mtspr DMAL,r6 blr - diff --git a/libogc/system_asm.S b/libogc/system_asm.S index 4f3eca1c..06a85f58 100644 --- a/libogc/system_asm.S +++ b/libogc/system_asm.S @@ -212,13 +212,13 @@ __InitPS: .extern ICEnable .extern DCEnable .extern L2Init + .extern L2SetWriteThrough .extern L2Enable .globl __InitCache __InitCache: - mflr r0 - stw r0, 4(sp) - stwu sp, -16(sp) - stw r31, 12(sp) + mflr r0 + stw r0,4(sp) + stwu sp,-8(sp) mfspr r3,HID0 rlwinm. r0,r3, 0, 16, 16 // Check if the Instruction Cache has been enabled or not. @@ -232,20 +232,15 @@ ICEnabled: bl DCEnable DCEnabled: - - mfspr r3, L2CR - clrrwi. r0, r3, 31 // Check if the Locked Cache has been enabled or not. - bne L2Enabled bl L2Init + li r3,1 + bl L2SetWriteThrough bl L2Enable -L2Enabled: - # Restore the non-volatile registers to their previous values and return. - lwz r0, 20(sp) - lwz r31, 12(sp) - addi sp, sp, 16 - mtlr r0 + lwz r0,12(sp) + addi sp,sp,8 + mtlr r0 blr .globl __InitSystem diff --git a/libogc/video.c b/libogc/video.c index 7914c1f0..70281191 100644 --- a/libogc/video.c +++ b/libogc/video.c @@ -2788,6 +2788,23 @@ void VIDEO_SetBlack(bool black) _CPU_ISR_Restore(level); } +void VIDEO_Set3D(bool threeD) +{ + u32 level; + + _CPU_ISR_Disable(level); + HorVer.threeD = threeD; + regs[1] = (regs[1]&~0x0008)|(_SHIFTL(threeD,3,1)); + changed |= VI_REGCHANGE(1); + __setScalingRegs(HorVer.panSizeX,HorVer.dispSizeX,HorVer.threeD); + _CPU_ISR_Restore(level); +} + +u32 VIDEO_GetRetraceCount(void) +{ + return retraceCount; +} + u32 VIDEO_GetNextField(void) { u32 level,nextfield; diff --git a/wiiuse/wpad.c b/wiiuse/wpad.c index 3e66b358..bfcad485 100644 --- a/wiiuse/wpad.c +++ b/wiiuse/wpad.c @@ -1212,6 +1212,34 @@ s32 WPAD_SetIdleThresholds(s32 chan, s32 btns, s32 ir, s32 accel, s32 js, s32 wb return WPAD_ERR_NONE; } +s32 WPAD_ControlLed(s32 chan,s32 leds) +{ + int i; + s32 ret; + u32 level; + + if(chan == WPAD_CHAN_ALL) { + for(i=WPAD_CHAN_0; i=WPAD_MAX_WIIMOTES) return WPAD_ERR_BAD_CHANNEL; + + _CPU_ISR_Disable(level); + if(__wpads_inited==WPAD_STATE_DISABLED) { + _CPU_ISR_Restore(level); + return WPAD_ERR_NOT_READY; + } + + if(__wpads[chan]!=NULL) + wiiuse_set_leds(__wpads[chan],(leds<<4)&0xf0,NULL); + + _CPU_ISR_Restore(level); + return WPAD_ERR_NONE; +} + s32 WPAD_ControlSpeaker(s32 chan,s32 enable) { int i;