Skip to content

Commit bd712e8

Browse files
committed
Port to libogc2
1 parent 885d78a commit bd712e8

File tree

14 files changed

+381
-338
lines changed

14 files changed

+381
-338
lines changed

.github/workflows/ngc.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
ngcn:
77
runs-on: ubuntu-latest
88
container:
9-
image: devkitpro/devkitppc:latest
9+
image: ghcr.io/extremscorner/libogc2:latest
1010
steps:
1111
- uses: actions/checkout@v4
1212
- name: Install build requirements
@@ -15,7 +15,7 @@ jobs:
1515
apt install ninja-build
1616
- name: Configure CMake
1717
run: |
18-
/opt/devkitpro/portlibs/gamecube/bin/powerpc-eabi-cmake -S . -B build -G Ninja \
18+
/opt/devkitpro/libogc2/gamecube/bin/powerpc-eabi-cmake -S . -B build -G Ninja \
1919
-DCMAKE_INSTALL_PREFIX=prefix
2020
- name: Build
2121
run: cmake --build build --verbose --parallel
@@ -26,14 +26,14 @@ jobs:
2626
( cd prefix; find ) | LC_ALL=C sort -u
2727
- name: Verify CMake configuration files
2828
run: |
29-
/opt/devkitpro/portlibs/gamecube/bin/powerpc-eabi-cmake -S cmake/test -B cmake_config_build -G Ninja \
29+
/opt/devkitpro/libogc2/gamecube/bin/powerpc-eabi-cmake -S cmake/test -B cmake_config_build -G Ninja \
3030
-DTEST_SHARED=FALSE \
3131
-DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} \
3232
-DCMAKE_BUILD_TYPE=Release
3333
cmake --build cmake_config_build --verbose
3434
- name: Extract CC/CXX/CFLAGS/CXXFLAGS from CMake toolchain
3535
run: |
36-
/opt/devkitpro/portlibs/gamecube/bin/powerpc-eabi-cmake -S .github/cmake -B /tmp/cmake_extract \
36+
/opt/devkitpro/libogc2/gamecube/bin/powerpc-eabi-cmake -S .github/cmake -B /tmp/cmake_extract \
3737
-DCMAKE_BUILD_TYPE=Release \
3838
-DVAR_PATH=/tmp/ngc_env.txt
3939
cat /tmp/ngc_env.txt >> $GITHUB_ENV

.github/workflows/nwii.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
nwii:
77
runs-on: ubuntu-latest
88
container:
9-
image: devkitpro/devkitppc:latest
9+
image: ghcr.io/extremscorner/libogc2:latest
1010
steps:
1111
- uses: actions/checkout@v4
1212
- name: Install build requirements
@@ -15,7 +15,7 @@ jobs:
1515
apt install ninja-build
1616
- name: Configure CMake
1717
run: |
18-
/opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S . -B build -G Ninja \
18+
/opt/devkitpro/libogc2/wii/bin/powerpc-eabi-cmake -S . -B build -G Ninja \
1919
-DCMAKE_INSTALL_PREFIX=prefix
2020
- name: Build
2121
run: cmake --build build --verbose --parallel
@@ -26,14 +26,14 @@ jobs:
2626
( cd prefix; find ) | LC_ALL=C sort -u
2727
- name: Verify CMake configuration files
2828
run: |
29-
/opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S cmake/test -B cmake_config_build -G Ninja \
29+
/opt/devkitpro/libogc2/wii/bin/powerpc-eabi-cmake -S cmake/test -B cmake_config_build -G Ninja \
3030
-DTEST_SHARED=FALSE \
3131
-DCMAKE_PREFIX_PATH=${{ env.SDL2_DIR }} \
3232
-DCMAKE_BUILD_TYPE=Release
3333
cmake --build cmake_config_build --verbose
3434
- name: Extract CC/CXX/CFLAGS/CXXFLAGS from CMake toolchain
3535
run: |
36-
/opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S .github/cmake -B /tmp/cmake_extract \
36+
/opt/devkitpro/libogc2/wii/bin/powerpc-eabi-cmake -S .github/cmake -B /tmp/cmake_extract \
3737
-DCMAKE_BUILD_TYPE=Release \
3838
-DVAR_PATH=/tmp/ngc_env.txt
3939
cat /tmp/ngc_env.txt >> $GITHUB_ENV

Catnip.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
catnip_package(SDL2 DEFAULT all)
3+
4+
catnip_add_preset(gamecube
5+
TOOLSET GameCube
6+
BUILD_TYPE Release
7+
)
8+
9+
catnip_add_preset(wii
10+
TOOLSET Wii
11+
BUILD_TYPE Release
12+
)

src/audio/ogc/SDL_ogcaudio.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ static SDL_INLINE void contextUnlock(_THIS)
104104
LWP_MutexUnlock(this->hidden->lock);
105105
}
106106

107-
static void audio_frame_finished(AESNDPB *pb, u32 state, void *arg)
107+
static void audio_frame_finished(AESNDPB *pb, u32 state)
108108
{
109-
SDL_AudioDevice *this = (SDL_AudioDevice *)arg;
109+
SDL_AudioDevice *this = (SDL_AudioDevice *)AESND_GetVoiceUserData(pb);
110110

111111
if (state == VOICE_STATE_STREAM) {
112112
const size_t buffer_size = DMA_BUFFER_SIZE;
@@ -151,7 +151,7 @@ static int OGCAUDIO_OpenDevice(_THIS, const char *devname)
151151
this->hidden = hidden;
152152

153153
AESND_Init();
154-
AESND_Pause(1);
154+
AESND_Pause(true);
155155

156156
/* Initialise internal state */
157157
LWP_MutexInit(&hidden->lock, false);
@@ -178,17 +178,18 @@ static int OGCAUDIO_OpenDevice(_THIS, const char *devname)
178178
/* Update the fragment size as size in bytes */
179179
SDL_CalculateAudioSpec(&this->spec);
180180

181-
hidden->voice = AESND_AllocateVoiceWithArg(audio_frame_finished, this);
181+
hidden->voice = AESND_AllocateVoice(audio_frame_finished);
182182
if (hidden->voice == NULL)
183183
return -1;
184184

185185
// start audio
186+
AESND_SetVoiceUserData(hidden->voice, this);
186187
AESND_SetVoiceFormat(hidden->voice, hidden->format);
187188
AESND_SetVoiceFrequency(hidden->voice, this->spec.freq);
188189
AESND_SetVoiceBuffer(hidden->voice, hidden->dma_buffers[0], DMA_BUFFER_SIZE);
189190
AESND_SetVoiceStream(hidden->voice, true);
190-
AESND_SetVoiceStop(hidden->voice, 0);
191-
AESND_Pause(0);
191+
AESND_SetVoiceStop(hidden->voice, false);
192+
AESND_Pause(false);
192193

193194
return 0;
194195
}
@@ -235,7 +236,7 @@ static void OGCAUDIO_CloseDevice(_THIS)
235236
hidden->voice = NULL;
236237
}
237238

238-
AESND_Pause(1);
239+
AESND_Pause(true);
239240
FreePrivateData(this);
240241
}
241242

src/joystick/ogc/SDL_sysjoystick.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static const char *OGC_JoystickGetDeviceName(int device_index)
423423
return NULL;
424424

425425
if (index >= GC_JOYSTICKS_START && index < GC_JOYSTICKS_END) {
426-
sprintf(joy_name, "Gamecube %d", index);
426+
sprintf(joy_name, "GameCube %d", index);
427427
#ifdef __wii__
428428
} else if (index >= WII_WIIMOTES_START && index < WII_WIIMOTES_END) {
429429
char *name_ptr = joy_name;
@@ -1082,13 +1082,13 @@ static void _HandleGCJoystickUpdate(SDL_Joystick *joystick)
10821082

10831083
axis = PAD_TriggerL(index);
10841084
if (prev_state->gamecube.triggerL != axis) {
1085-
SDL_PrivateJoystickAxis(joystick, 4, axis << 7);
1085+
SDL_PrivateJoystickAxis(joystick, 4, (axis * 257) - 32768);
10861086
prev_state->gamecube.triggerL = axis;
10871087
}
10881088

10891089
axis = PAD_TriggerR(index);
10901090
if (prev_state->gamecube.triggerR != axis) {
1091-
SDL_PrivateJoystickAxis(joystick, 5, axis << 7);
1091+
SDL_PrivateJoystickAxis(joystick, 5, (axis * 257) - 32768);
10921092
prev_state->gamecube.triggerR = axis;
10931093
}
10941094
}

src/thread/ogc/SDL_syscond.c

Lines changed: 95 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,59 @@
11
/*
2-
SDL - Simple DirectMedia Layer
3-
Copyright (C) 1997-2006 Sam Lantinga
4-
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
9-
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
14-
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
19-
Sam Lantinga
20-
slouken@libsdl.org
2+
Simple DirectMedia Layer
3+
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
2. Altered source versions must be plainly marked as such, and must not be
18+
misrepresented as being the original software.
19+
3. This notice may not be removed or altered from any source distribution.
2120
*/
22-
#include "SDL_config.h"
21+
#include "../../SDL_internal.h"
2322

24-
/* An implementation of condition variables using semaphores and mutexes */
25-
/*
26-
This implementation borrows heavily from the BeOS condition variable
27-
implementation, written by Christopher Tate and Owen Smith. Thanks!
28-
*/
23+
#include <errno.h>
24+
#include <ogc/cond.h>
25+
#include <ogc/timesupp.h>
2926

3027
#include "SDL_thread.h"
3128
#include "SDL_sysmutex_c.h"
3229

33-
#include <ogcsys.h>
34-
#include <ogc/cond.h>
35-
3630
struct SDL_cond
3731
{
3832
cond_t cond;
3933
};
4034

4135
/* Create a condition variable */
42-
SDL_cond * SDL_CreateCond(void)
36+
SDL_cond *SDL_CreateCond(void)
4337
{
4438
SDL_cond *cond;
4539

46-
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
47-
if (cond) {
48-
if (LWP_CondInit(&(cond->cond)) < 0) {
49-
SDL_DestroyCond(cond);
40+
cond = (SDL_cond *)SDL_malloc(sizeof(SDL_cond));
41+
if (cond != NULL) {
42+
if (LWP_CondInit(&cond->cond) != 0) {
43+
SDL_SetError("LWP_CondInit() failed");
44+
SDL_free(cond);
5045
cond = NULL;
5146
}
5247
} else {
5348
SDL_OutOfMemory();
5449
}
55-
return (cond);
50+
return cond;
5651
}
5752

5853
/* Destroy a condition variable */
5954
void SDL_DestroyCond(SDL_cond *cond)
6055
{
61-
if (cond) {
56+
if (cond != NULL) {
6257
LWP_CondDestroy(cond->cond);
6358
SDL_free(cond);
6459
}
@@ -67,65 +62,92 @@ void SDL_DestroyCond(SDL_cond *cond)
6762
/* Restart one of the threads that are waiting on the condition variable */
6863
int SDL_CondSignal(SDL_cond *cond)
6964
{
70-
if (!cond) {
71-
SDL_SetError("Passed a NULL condition variable");
72-
return -1;
65+
if (cond == NULL) {
66+
return SDL_InvalidParamError("cond");
7367
}
7468

75-
return LWP_CondSignal(cond->cond) == 0 ? 0 : -1;
76-
69+
if (LWP_CondSignal(cond->cond) != 0) {
70+
return SDL_SetError("LWP_CondSignal() failed");
71+
}
72+
return 0;
7773
}
7874

7975
/* Restart all threads that are waiting on the condition variable */
8076
int SDL_CondBroadcast(SDL_cond *cond)
8177
{
82-
if (!cond) {
83-
SDL_SetError("Passed a NULL condition variable");
84-
return -1;
78+
if (cond == NULL) {
79+
return SDL_InvalidParamError("cond");
8580
}
8681

87-
return LWP_CondBroadcast(cond->cond) == 0 ? 0 : -1;
82+
if (LWP_CondBroadcast(cond->cond) != 0) {
83+
return SDL_SetError("LWP_CondBroadcast() failed");
84+
}
85+
return 0;
8886
}
8987

9088
/* Wait on the condition variable for at most 'ms' milliseconds.
91-
The mutex must be locked before entering this function!
92-
The mutex is unlocked during the wait, and locked again after the wait.
93-
94-
Typical use:
95-
96-
Thread A:
97-
SDL_LockMutex(lock);
98-
while ( ! condition ) {
99-
SDL_CondWait(cond);
100-
}
101-
SDL_UnlockMutex(lock);
102-
103-
Thread B:
104-
SDL_LockMutex(lock);
105-
...
106-
condition = true;
107-
...
108-
SDL_UnlockMutex(lock);
109-
*/
89+
The mutex must be locked before entering this function!
90+
The mutex is unlocked during the wait, and locked again after the wait.
11091
92+
Typical use:
11193
94+
Thread A:
95+
SDL_LockMutex(lock);
96+
while ( ! condition ) {
97+
SDL_CondWait(cond, lock);
98+
}
99+
SDL_UnlockMutex(lock);
100+
101+
Thread B:
102+
SDL_LockMutex(lock);
103+
...
104+
condition = true;
105+
...
106+
SDL_CondSignal(cond);
107+
SDL_UnlockMutex(lock);
108+
*/
112109
int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
113110
{
114-
struct timespec time;
111+
int retval;
112+
struct timespec tv;
115113

116-
if (!cond) {
117-
SDL_SetError("Passed a NULL condition variable");
118-
return -1;
114+
if (cond == NULL) {
115+
return SDL_InvalidParamError("cond");
116+
}
117+
if (mutex == NULL) {
118+
return SDL_InvalidParamError("mutex");
119119
}
120-
//LWP_CondTimedWait expects relative timeout
121-
time.tv_sec = (ms / 1000);
122-
time.tv_nsec = (ms % 1000) * 1000000;
123120

124-
return LWP_CondTimedWait(cond->cond, mutex->id, &time);
121+
tv.tv_sec = ms / TB_MSPERSEC;
122+
tv.tv_nsec = (ms % TB_MSPERSEC) * TB_NSPERMS;
123+
124+
retval = LWP_CondTimedWait(cond->cond, mutex->id, &tv);
125+
if (retval != 0) {
126+
if (retval == ETIMEDOUT) {
127+
retval = SDL_MUTEX_TIMEDOUT;
128+
} else {
129+
retval = SDL_SetError("LWP_CondTimedWait() failed");
130+
}
131+
}
132+
return retval;
125133
}
126134

127-
/* Wait on the condition variable forever */
135+
/* Wait on the condition variable, unlocking the provided mutex.
136+
The mutex must be locked before entering this function!
137+
*/
128138
int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
129139
{
130-
return LWP_CondWait(cond->cond, mutex->id);
140+
if (cond == NULL) {
141+
return SDL_InvalidParamError("cond");
142+
}
143+
if (mutex == NULL) {
144+
return SDL_InvalidParamError("mutex");
145+
}
146+
147+
if (LWP_CondWait(cond->cond, mutex->id) != 0) {
148+
return SDL_SetError("LWP_CondWait() failed");
149+
}
150+
return 0;
131151
}
152+
153+
/* vi: set ts=4 sw=4 expandtab: */

0 commit comments

Comments
 (0)