forked from Pokes303/WUPDownloader
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsdl.patch
5602 lines (5571 loc) · 196 KB
/
sdl.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19298e379..ce8007311 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,13 +276,18 @@ if(USE_GCC OR USE_CLANG)
set(OPT_DEF_GCC_ATOMICS ON)
endif()
+if(WIIU)
+ # Prefer coreinit atomics on Wii U due to a hardware bug in load-exclusive and store-exclusive instructions
+ set(OPT_DEF_GCC_ATOMICS OFF)
+endif()
+
# Default option knobs
if(APPLE OR ARCH_64 OR MSVC_CLANG)
if(NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm")
set(OPT_DEF_SSEMATH ON)
endif()
endif()
-if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS)
+if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS OR WIIU)
set(OPT_DEF_LIBC ON)
endif()
@@ -387,7 +392,7 @@ if(EMSCRIPTEN)
set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
endif()
-if(VITA OR PSP OR PS2 OR N3DS)
+if(VITA OR PSP OR PS2 OR N3DS OR WIIU)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
endif()
@@ -862,7 +867,7 @@ if(SDL_ASSEMBLY)
check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
- if(SDL_ALTIVEC)
+ if(SDL_ALTIVEC AND NOT WIIU)
set(CMAKE_REQUIRED_FLAGS "-maltivec")
check_c_source_compiles("
#include <altivec.h>
@@ -2824,6 +2829,47 @@ elseif(N3DS)
else()
message_error("SDL_FILE must be enabled to build on N3DS")
endif()
+
+elseif(WIIU)
+ if(SDL_AUDIO)
+ set(SDL_AUDIO_DRIVER_WIIU 1)
+ file(GLOB WIIU_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wiiu/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_AUDIO_SOURCES})
+ set(HAVE_SDL_AUDIO TRUE)
+ endif()
+
+ if(SDL_JOYSTICK)
+ set(SDL_JOYSTICK_WIIU 1)
+ file(GLOB WIIU_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/wiiu/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_JOYSTICK_SOURCES})
+ set(HAVE_SDL_JOYSTICK TRUE)
+ endif()
+
+ if(SDL_THREADS)
+ set(SDL_THREAD_WIIU 1)
+ file(GLOB WIIU_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL2_SOURCE_DIR}/src/thread/wiiu/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_THREAD_SOURCES})
+ set(HAVE_SDL_THREADS TRUE)
+ endif()
+
+ if(SDL_TIMERS)
+ set(SDL_TIMER_WIIU 1)
+ file(GLOB WIIU_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/wiiu/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_TIMER_SOURCES})
+ set(HAVE_SDL_TIMERS TRUE)
+ endif()
+
+ if(SDL_VIDEO)
+ set(SDL_VIDEO_DRIVER_WIIU 1)
+ set(SDL_VIDEO_RENDER_WIIU 1)
+ file(GLOB WIIU_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/wiiu/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WIIU_VIDEO_SOURCES})
+ set(HAVE_SDL_VIDEO TRUE)
+ endif()
+
+ list(APPEND EXTRA_LIBS
+ wut
+ )
endif()
if(HAVE_VULKAN AND NOT SDL_LOADSO)
diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h
index 22ea0191a..e956ccf4f 100644
--- a/include/SDL_atomic.h
+++ b/include/SDL_atomic.h
@@ -230,6 +230,10 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
#include <mbarrier.h>
#define SDL_MemoryBarrierRelease() __machine_rel_barrier()
#define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
+#elif defined(__WIIU__)
+#include <coreinit/cache.h>
+#define SDL_MemoryBarrierRelease() OSMemoryBarrier()
+#define SDL_MemoryBarrierAcquire() OSMemoryBarrier()
#else
/* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
#define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
@@ -242,7 +246,7 @@ typedef void (*SDL_KernelMemoryBarrierFunc)();
#define SDL_CPUPauseInstruction() __asm__ __volatile__("pause\n") /* Some assemblers can't do REP NOP, so go with PAUSE. */
#elif (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__)
#define SDL_CPUPauseInstruction() __asm__ __volatile__("yield" ::: "memory")
-#elif (defined(__powerpc__) || defined(__powerpc64__))
+#elif (defined(__powerpc__) || defined(__powerpc64__) || defined(__WIIU__))
#define SDL_CPUPauseInstruction() __asm__ __volatile__("or 27,27,27");
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#define SDL_CPUPauseInstruction() _mm_pause() /* this is actually "rep nop" and not a SIMD instruction. No inline asm in MSVC x86-64! */
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index b8e2144aa..b05ca5b2b 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -327,6 +327,7 @@
#cmakedefine SDL_AUDIO_DRIVER_PSP @SDL_AUDIO_DRIVER_PSP@
#cmakedefine SDL_AUDIO_DRIVER_PS2 @SDL_AUDIO_DRIVER_PS2@
#cmakedefine SDL_AUDIO_DRIVER_N3DS @SDL_AUDIO_DRIVER_N3DS@
+#cmakedefine SDL_AUDIO_DRIVER_WIIU @SDL_AUDIO_DRIVER_WIIU@
/* Enable various input drivers */
#cmakedefine SDL_INPUT_LINUXEV @SDL_INPUT_LINUXEV@
@@ -352,6 +353,7 @@
#cmakedefine SDL_JOYSTICK_PSP @SDL_JOYSTICK_PSP@
#cmakedefine SDL_JOYSTICK_PS2 @SDL_JOYSTICK_PS2@
#cmakedefine SDL_JOYSTICK_N3DS @SDL_JOYSTICK_N3DS@
+#cmakedefine SDL_JOYSTICK_WIIU @SDL_JOYSTICK_WIIU@
#cmakedefine SDL_HAPTIC_DUMMY @SDL_HAPTIC_DUMMY@
#cmakedefine SDL_HAPTIC_LINUX @SDL_HAPTIC_LINUX@
#cmakedefine SDL_HAPTIC_IOKIT @SDL_HAPTIC_IOKIT@
@@ -386,6 +388,7 @@
#cmakedefine SDL_THREAD_PSP @SDL_THREAD_PSP@
#cmakedefine SDL_THREAD_PS2 @SDL_THREAD_PS2@
#cmakedefine SDL_THREAD_N3DS @SDL_THREAD_N3DS@
+#cmakedefine SDL_THREAD_WIIU @SDL_THREAD_WIIU@
/* Enable various timer systems */
#cmakedefine SDL_TIMER_HAIKU @SDL_TIMER_HAIKU@
@@ -397,6 +400,7 @@
#cmakedefine SDL_TIMER_PSP @SDL_TIMER_PSP@
#cmakedefine SDL_TIMER_PS2 @SDL_TIMER_PS2@
#cmakedefine SDL_TIMER_N3DS @SDL_TIMER_N3DS@
+#cmakedefine SDL_TIMER_WIIU @SDL_TIMER_WIIU@
/* Enable various video drivers */
#cmakedefine SDL_VIDEO_DRIVER_ANDROID @SDL_VIDEO_DRIVER_ANDROID@
@@ -419,6 +423,7 @@
#cmakedefine SDL_VIDEO_DRIVER_RISCOS @SDL_VIDEO_DRIVER_RISCOS@
#cmakedefine SDL_VIDEO_DRIVER_PSP @SDL_VIDEO_DRIVER_PSP@
#cmakedefine SDL_VIDEO_DRIVER_PS2 @SDL_VIDEO_DRIVER_PS2@
+#cmakedefine SDL_VIDEO_DRIVER_WIIU @SDL_VIDEO_DRIVER_WIIU@
#cmakedefine SDL_VIDEO_DRIVER_KMSDRM @SDL_VIDEO_DRIVER_KMSDRM@
#cmakedefine SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC @SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC@
@@ -463,6 +468,7 @@
#cmakedefine SDL_VIDEO_RENDER_VITA_GXM @SDL_VIDEO_RENDER_VITA_GXM@
#cmakedefine SDL_VIDEO_RENDER_PS2 @SDL_VIDEO_RENDER_PS2@
#cmakedefine SDL_VIDEO_RENDER_PSP @SDL_VIDEO_RENDER_PSP@
+#cmakedefine SDL_VIDEO_RENDER_WIIU @SDL_VIDEO_RENDER_WIIU@
/* Enable OpenGL support */
#cmakedefine SDL_VIDEO_OPENGL @SDL_VIDEO_OPENGL@
diff --git a/include/SDL_endian.h b/include/SDL_endian.h
index 582c3a8b8..39db7cade 100644
--- a/include/SDL_endian.h
+++ b/include/SDL_endian.h
@@ -79,7 +79,7 @@ _m_prefetch(void *__P)
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
(defined(__MIPS__) && defined(__MIPSEB__)) || \
defined(__ppc__) || defined(__POWERPC__) || defined(__powerpc__) || defined(__PPC__) || \
- defined(__sparc__)
+ defined(__sparc__) || defined(_BIG_ENDIAN) || (__BIG_ENDIAN__ == 1)
#define SDL_BYTEORDER SDL_BIG_ENDIAN
#else
#define SDL_BYTEORDER SDL_LIL_ENDIAN
diff --git a/include/SDL_platform.h b/include/SDL_platform.h
index d2a7e052d..262e1c37f 100644
--- a/include/SDL_platform.h
+++ b/include/SDL_platform.h
@@ -200,6 +200,10 @@
#if defined(PS2)
#define __PS2__ 1
#endif
+#if defined(__WIIU__)
+#undef __WIIU__
+#define __WIIU__ 1
+#endif
/* The NACL compiler defines __native_client__ and __pnacl__
* Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi
diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h
index 6de63cad6..76c6c6c8d 100644
--- a/include/SDL_test_common.h
+++ b/include/SDL_test_common.h
@@ -40,6 +40,9 @@
#elif defined(__VITA__)
#define DEFAULT_WINDOW_WIDTH 960
#define DEFAULT_WINDOW_HEIGHT 544
+#elif defined(__WIIU__)
+#define DEFAULT_WINDOW_WIDTH 1280
+#define DEFAULT_WINDOW_HEIGHT 720
#else
#define DEFAULT_WINDOW_WIDTH 640
#define DEFAULT_WINDOW_HEIGHT 480
diff --git a/include/SDL_video.h b/include/SDL_video.h
index c70facb5e..fe3850bf8 100644
--- a/include/SDL_video.h
+++ b/include/SDL_video.h
@@ -124,6 +124,8 @@ typedef enum
SDL_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip */
SDL_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu */
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
+ SDL_WINDOW_WIIU_GAMEPAD_ONLY = 0x01000000, /**< Wii U: window must be drawn only on the Gamepad */
+ SDL_WINDOW_WIIU_TV_ONLY = 0x02000000, /**< Wii U: window must be drawn only on the TV */
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
diff --git a/src/SDL.c b/src/SDL.c
index 8ccfa1751..eaaf5434a 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -624,6 +624,8 @@ SDL_GetPlatform(void)
return "Nokia N-Gage";
#elif __3DS__
return "Nintendo 3DS";
+#elif __WIIU__
+ return "Wii U";
#else
return "Unknown (see SDL_platform.h)";
#endif
diff --git a/src/SDL_log.c b/src/SDL_log.c
index f710dd8a5..7ebdfea8b 100644
--- a/src/SDL_log.c
+++ b/src/SDL_log.c
@@ -39,6 +39,10 @@
#include <android/log.h>
#endif
+#if defined(__WIIU__)
+#include <coreinit/debug.h>
+#endif
+
#include "stdlib/SDL_vacopy.h"
@@ -471,6 +475,10 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
SDL_NSLog(SDL_priority_prefixes[priority], message);
return;
}
+#elif defined(__WIIU__)
+ {
+ OSReport("SDL: %s: %s\n", SDL_priority_prefixes[priority], message);
+ }
#elif defined(__PSP__) || defined(__PS2__)
{
FILE* pFile;
diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c
index ba2ecff9e..0dcc20d48 100644
--- a/src/atomic/SDL_atomic.c
+++ b/src/atomic/SDL_atomic.c
@@ -35,6 +35,10 @@
#include <atomic.h>
#endif
+#if defined(__WIIU__)
+#include <coreinit/atomic.h>
+#endif
+
/* The __atomic_load_n() intrinsic showed up in different times for different compilers. */
#if defined(__clang__)
# if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
@@ -45,7 +49,7 @@
# endif
# endif
#elif defined(__GNUC__)
-# if (__GNUC__ >= 5)
+# if (__GNUC__ >= 5) && defined(HAVE_GCC_ATOMICS)
# define HAVE_ATOMIC_LOAD_N 1
# endif
#endif
@@ -99,7 +103,7 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
Contributed by Bob Pendleton, [email protected]
*/
-#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(__MACOSX__) && !defined(__SOLARIS__) && !defined(HAVE_WATCOM_ATOMICS)
+#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(__MACOSX__) && !defined(__SOLARIS__) && !defined(HAVE_WATCOM_ATOMICS) && !defined(__WIIU__)
#define EMULATE_CAS 1
#endif
@@ -132,6 +136,8 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval);
#elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval);
+#elif defined(__WIIU__)
+ return OSCompareAndSwapAtomic((volatile uint32_t *)&a->value, (uint32_t)oldval, (uint32_t)newval);
#elif defined(HAVE_GCC_ATOMICS)
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
#elif defined(__MACOSX__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
@@ -161,6 +167,8 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval);
#elif defined(HAVE_WATCOM_ATOMICS)
return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
+#elif defined(__WIIU__)
+ return OSCompareAndSwapAtomic((volatile uint32_t *)a, (uint32_t)oldval, (uint32_t)newval);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_bool_compare_and_swap(a, oldval, newval);
#elif defined(__MACOSX__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
@@ -193,6 +201,9 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
return _InterlockedExchange((long*)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xchg_watcom(&a->value, v);
+#elif defined(__WIIU__)
+ a->value = v;
+ return v;
#elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(&a->value, v);
#elif defined(__SOLARIS__)
@@ -213,6 +224,9 @@ SDL_AtomicSetPtr(void **a, void *v)
return _InterlockedExchangePointer(a, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return (void *) _SDL_xchg_watcom((int *)a, (long)v);
+#elif defined(__WIIU__)
+ *a = v;
+ return v;
#elif defined(HAVE_GCC_ATOMICS)
return __sync_lock_test_and_set(a, v);
#elif defined(__SOLARIS__)
@@ -234,12 +248,14 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
return _InterlockedExchangeAdd((long*)&a->value, v);
#elif defined(HAVE_WATCOM_ATOMICS)
return _SDL_xadd_watcom(&a->value, v);
+#elif defined(__WIIU__)
+ return OSAddAtomic((volatile int32_t *)&a->value, v);
#elif defined(HAVE_GCC_ATOMICS)
return __sync_fetch_and_add(&a->value, v);
#elif defined(__SOLARIS__)
- int pv = a->value;
- membar_consumer();
- atomic_add_int((volatile uint_t*)&a->value, v);
+ int pv = a->value;
+ membar_consumer();
+ atomic_add_int((volatile uint_t*)&a->value, v);
return pv;
#else
int value;
@@ -253,7 +269,9 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
int
SDL_AtomicGet(SDL_atomic_t *a)
{
-#ifdef HAVE_ATOMIC_LOAD_N
+#if defined(__WIIU__)
+ return a->value;
+#elif defined(HAVE_ATOMIC_LOAD_N)
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
#elif defined(HAVE_MSC_ATOMICS)
SDL_COMPILE_TIME_ASSERT(atomic_get, sizeof(long) == sizeof(a->value));
@@ -278,7 +296,9 @@ SDL_AtomicGet(SDL_atomic_t *a)
void *
SDL_AtomicGetPtr(void **a)
{
-#ifdef HAVE_ATOMIC_LOAD_N
+#if defined(__WIIU__)
+ return *a;
+#elif defined(HAVE_ATOMIC_LOAD_N)
return __atomic_load_n(a, __ATOMIC_SEQ_CST);
#elif defined(HAVE_MSC_ATOMICS)
return _InterlockedCompareExchangePointer(a, NULL, NULL);
diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c
index 2035ba6bd..e2a3f1cae 100644
--- a/src/atomic/SDL_spinlock.c
+++ b/src/atomic/SDL_spinlock.c
@@ -36,6 +36,12 @@
#include <unixlib/local.h>
#endif
+#if defined(__WIIU__)
+#include <coreinit/cache.h>
+#include <coreinit/atomic.h>
+#include <coreinit/thread.h>
+#endif
+
#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
#include <xmmintrin.h>
#endif
@@ -152,6 +158,8 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
// enable interuption
if(oldintr) { EIntr(); }
return res;
+#elif defined(__WIIU__)
+ return OSCompareAndSwapAtomic((volatile uint32_t *)lock, 0u, 1u);
#else
#error Please implement for your platform.
return SDL_FALSE;
@@ -168,8 +176,12 @@ SDL_AtomicLock(SDL_SpinLock *lock)
iterations++;
SDL_CPUPauseInstruction();
} else {
+#if defined(__WIIU__)
+ OSSleepTicks(1);
+#else
/* !!! FIXME: this doesn't definitely give up the current timeslice, it does different things on various platforms. */
SDL_Delay(0);
+#endif
}
}
}
@@ -177,7 +189,11 @@ SDL_AtomicLock(SDL_SpinLock *lock)
void
SDL_AtomicUnlock(SDL_SpinLock *lock)
{
-#if HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
+#if defined(__WIIU__)
+ *lock = 0;
+ OSMemoryBarrier();
+
+#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
__sync_lock_release(lock);
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index b1b87d151..896957be5 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -123,6 +123,9 @@ static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_OS2
&OS2AUDIO_bootstrap,
#endif
+#if SDL_AUDIO_DRIVER_WIIU
+ &WIIUAUDIO_bootstrap,
+#endif
#if SDL_AUDIO_DRIVER_DISK
&DISKAUDIO_bootstrap,
#endif
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index 002ae2a33..3e2d583e7 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -212,6 +212,7 @@ extern AudioBootStrap VITAAUD_bootstrap;
extern AudioBootStrap N3DSAUDIO_bootstrap;
extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
extern AudioBootStrap OS2AUDIO_bootstrap;
+extern AudioBootStrap WIIUAUDIO_bootstrap;
#endif /* SDL_sysaudio_h_ */
diff --git a/src/audio/wiiu/SDL_wiiuaudio.c b/src/audio/wiiu/SDL_wiiuaudio.c
new file mode 100644
index 000000000..e6f128915
--- /dev/null
+++ b/src/audio/wiiu/SDL_wiiuaudio.c
@@ -0,0 +1,425 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2018-2018 Ash Logan <[email protected]>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_WIIU
+
+#include <stdio.h>
+#include <malloc.h>
+
+#include "SDL_audio.h"
+#include "SDL_error.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_wiiuaudio.h"
+#include "SDL_wiiuaudio_mix.h"
+
+#include <sndcore2/core.h>
+#include <sndcore2/voice.h>
+#include <sndcore2/drcvs.h>
+#include <coreinit/core.h>
+#include <coreinit/cache.h>
+#include <coreinit/thread.h>
+#include <coreinit/time.h>
+#include <coreinit/memorymap.h>
+
+#define WIIUAUDIO_DRIVER_NAME "wiiu"
+
+#define AX_MAIN_AFFINITY OS_THREAD_ATTRIB_AFFINITY_CPU1
+
+static void _WIIUAUDIO_framecallback();
+static SDL_AudioDevice* cb_this;
+#define cb_hidden cb_this->hidden
+
+/* Some helpers for AX-related math */
+/* Absolute address to an AXVoiceOffsets offset */
+#define calc_ax_offset(offs, addr) (((void*)addr - offs.data) \
+ / sizeof_sample(offs))
+
+#define sizeof_sample(offs) (offs.dataType == AX_VOICE_FORMAT_LPCM8 ? 1 : 2)
+
+/* +1, but never goes above NUM_BUFFERS */
+#define next_id(id) (id + 1) % NUM_BUFFERS
+
+static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
+ int ret = 0;
+ AXVoiceOffsets offs;
+ AXVoiceVeData vol = {
+ .volume = 0x8000,
+ };
+ uint32_t old_affinity;
+ float srcratio;
+ Uint8* mixbuf = NULL;
+ uint32_t mixbuf_allocation_count = 0;
+ Uint8* mixbuf_allocations[32];
+
+ this->hidden = (struct SDL_PrivateAudioData*)SDL_malloc(sizeof(*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_zerop(this->hidden);
+
+/* We *must not* change cores when setting stuff up */
+ old_affinity = OSGetThreadAffinity(OSGetCurrentThread());
+ OSSetThreadAffinity(OSGetCurrentThread(), AX_MAIN_AFFINITY);
+
+/* Take a quick aside to init the wiiu audio */
+ if (!AXIsInit()) {
+ /* Init the AX audio engine */
+ AXInitParams initparams = {
+ .renderer = AX_INIT_RENDERER_48KHZ,
+ .pipeline = AX_INIT_PIPELINE_SINGLE,
+ };
+ AXInitWithParams(&initparams);
+ } else printf("DEBUG: AX already up?\n");
+
+ if (this->spec.channels < 1) this->spec.channels = 1;
+ if (this->spec.channels > WIIU_MAX_VALID_CHANNELS)
+ this->spec.channels = WIIU_MAX_VALID_CHANNELS;
+
+/* Force wiiu-compatible audio formats.
+ TODO verify - unsigned or signed? */
+ switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
+ case 8:
+ /* TODO 8-bit audio sounds broken */
+ /*this->spec.format = AUDIO_S8;
+ break;*/
+ case 16:
+ default:
+ this->spec.format = AUDIO_S16MSB;
+ break;
+ }
+
+ //TODO maybe round this->spec.samples up even when >?
+ //maybe even force at least 2* so we get more frame callbacks to think
+ if (this->spec.samples < AXGetInputSamplesPerFrame()) {
+ this->spec.samples = AXGetInputSamplesPerFrame();
+ }
+
+/* We changed channels and samples, so recalculate the spec */
+ SDL_CalculateAudioSpec(&this->spec);
+
+/* Allocate buffers for double-buffering and samples.
+ Make sure the entire mixbuf is in a 512MiB block for the DSP to be accessible. */
+ for (int i = 0; i < 32; i++) {
+ Uint32 physStart, physEnd;
+ mixbuf = memalign(0x40, this->spec.size * NUM_BUFFERS);
+ if (!mixbuf) {
+ break;
+ }
+
+ physStart = OSEffectiveToPhysical((uint32_t) mixbuf) & 0x1fffffff;
+ physEnd = physStart + this->spec.size * NUM_BUFFERS;
+ if ((physEnd & 0xe0000000) == 0) {
+ break;
+ }
+
+ mixbuf_allocations[mixbuf_allocation_count] = mixbuf;
+ mixbuf_allocation_count++;
+ mixbuf = NULL;
+ }
+
+/* Free the failed attempts */
+ while (mixbuf_allocation_count--) {
+ free(mixbuf_allocations[mixbuf_allocation_count]);
+ }
+
+ if (!mixbuf) {
+ printf("Couldn't allocate mix buffer\n");
+ ret = SDL_OutOfMemory();
+ goto end;
+ }
+
+ memset(mixbuf, 0, this->spec.size * NUM_BUFFERS);
+ DCStoreRange(mixbuf, this->spec.size * NUM_BUFFERS);
+
+ for (int i = 0; i < NUM_BUFFERS; i++) {
+ this->hidden->mixbufs[i] = mixbuf + this->spec.size * i;
+ }
+
+/* Allocate a scratch buffer for deinterleaving operations */
+ this->hidden->deintvbuf = SDL_malloc(this->spec.size);
+ if (this->hidden->deintvbuf == NULL) {
+ AXQuit();
+ printf("DEBUG: Couldn't allocate deinterleave buffer");
+ ret = SDL_SetError("Couldn't allocate deinterleave buffer");
+ goto end;
+ }
+
+
+ for (int i = 0; i < this->spec.channels; i++) {
+ /* Get a voice, top priority */
+ this->hidden->voice[i] = AXAcquireVoice(31, NULL, NULL);
+ if (!this->hidden->voice[i]) {
+ AXQuit();
+ printf("DEBUG: couldn't get voice\n");
+ ret = SDL_OutOfMemory();
+ goto end;
+ }
+
+ /* Start messing with it */
+ AXVoiceBegin(this->hidden->voice[i]);
+ AXSetVoiceType(this->hidden->voice[i], 0);
+
+ /* Set the voice's volume. */
+ AXSetVoiceVe(this->hidden->voice[i], &vol);
+ switch (this->spec.channels) {
+ case 1: /* mono */ {
+ AXSetVoiceDeviceMix(this->hidden->voice[i],
+ AX_DEVICE_TYPE_DRC, 0, mono_mix[i]);
+ AXSetVoiceDeviceMix(this->hidden->voice[i],
+ AX_DEVICE_TYPE_TV, 0, mono_mix[i]);
+ } break;
+ case 2: /* stereo */ {
+ AXSetVoiceDeviceMix(this->hidden->voice[i],
+ AX_DEVICE_TYPE_DRC, 0, stereo_mix[i]);
+ AXSetVoiceDeviceMix(this->hidden->voice[i],
+ AX_DEVICE_TYPE_TV, 0, stereo_mix[i]);
+ } break;
+ }
+
+ /* Set the samplerate conversion ratio
+ <source sample rate> / <target sample rate> */
+ srcratio = (float)this->spec.freq / (float)AXGetInputSamplesPerSec();
+ AXSetVoiceSrcRatio(this->hidden->voice[i], srcratio);
+ AXSetVoiceSrcType(this->hidden->voice[i], AX_VOICE_SRC_TYPE_LINEAR);
+
+ /* Set up the offsets for the first mixbuf */
+ switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
+ case 8:
+ offs.dataType = AX_VOICE_FORMAT_LPCM8;
+ offs.endOffset = this->spec.samples;
+ break;
+ case 16:
+ default:
+ offs.dataType = AX_VOICE_FORMAT_LPCM16;
+ offs.endOffset = this->spec.samples;
+ break;
+ }
+ offs.loopingEnabled = AX_VOICE_LOOP_ENABLED;
+ offs.loopOffset = 0;
+ offs.currentOffset = 0;
+
+ if (offs.dataType == AX_VOICE_FORMAT_LPCM8) {
+ offs.data = this->hidden->mixbufs[0]
+ + this->spec.samples * i * sizeof(Uint8);
+ } else if (offs.dataType == AX_VOICE_FORMAT_LPCM16) {
+ offs.data = this->hidden->mixbufs[0]
+ + this->spec.samples * i * sizeof(Uint16);
+ }
+ AXSetVoiceOffsets(this->hidden->voice[i], &offs);
+
+ /* Set the last good loopcount */
+ this->hidden->last_loopcount = AXGetVoiceLoopCount(this->hidden->voice[i]);
+
+ /* Offsets are set for playing the first mixbuf, so we should render the second */
+ this->hidden->playingid = 0;
+ this->hidden->renderingid = 1;
+
+ /* Start playing. */
+ AXSetVoiceState(this->hidden->voice[i], AX_VOICE_STATE_PLAYING);
+
+ /* Okay, we're good */
+ AXVoiceEnd(this->hidden->voice[i]);
+ }
+
+ cb_this = this; //wish there was a better way
+ AXRegisterAppFrameCallback(_WIIUAUDIO_framecallback);
+
+end: ;
+/* Put the thread affinity back to normal - we won't call any more AX funcs */
+ OSSetThreadAffinity(OSGetCurrentThread(), old_affinity);
+ return ret;
+}
+
+/* Called every 3ms before a frame of audio is rendered. Keep it fast! */
+static void _WIIUAUDIO_framecallback() {
+ int playing_buffer = -1;
+ AXVoiceOffsets offs[6];
+ void* endaddr;
+
+ for (int i = 0; i < cb_this->spec.channels; i++) {
+ AXGetVoiceOffsets(cb_hidden->voice[i], &offs[i]);
+ }
+
+/* Figure out which buffer is being played by the hardware */
+ for (int i = 0; i < NUM_BUFFERS; i++) {
+ void* buf = cb_hidden->mixbufs[i];
+ uint32_t startOffset = calc_ax_offset(offs[0], buf);
+ uint32_t endOffset = startOffset + cb_this->spec.samples;
+
+ /* NOTE endOffset definitely needs to be <= (AX plays the sample at
+ endOffset), dunno about startOffset */
+ if (offs[0].currentOffset >= startOffset &&
+ offs[0].currentOffset <= endOffset) {
+ playing_buffer = i;
+ break;
+ }
+ }
+
+ if (playing_buffer < 0 || playing_buffer >= NUM_BUFFERS) {
+ /* UM */
+ /* Uncomment for craploads of debug info */
+ /*printf("bad buffer %d\n" "|> %08X, %08X-%08X\n" \
+ "0: xxxxxxxx, %08X-%08X (%08X@%08X)\n" \
+ "1: xxxxxxxx, %08X-%08X (%08X@%08X)\n", \
+ playing_buffer, offs.currentOffset, offs.loopOffset, offs.endOffset,
+ calc_ax_offset(offs, (void*)cb_hidden->mixbufs[0]),
+ calc_ax_offset(offs, (void*)cb_hidden->mixbufs[0] + cb_this->spec.size),
+ cb_this->spec.size, (void*)cb_hidden->mixbufs[0],
+ calc_ax_offset(offs, (void*)cb_hidden->mixbufs[1]),
+ calc_ax_offset(offs, (void*)cb_hidden->mixbufs[1] + cb_this->spec.size),
+ cb_this->spec.size, (void*)cb_hidden->mixbufs[1]);*/
+ printf("DEBUG: Playing an invalid buffer? This is not a good sign.\n");
+ playing_buffer = 0;
+ }
+
+/* Make sure playingid is in sync with the hardware */
+ cb_hidden->playingid = playing_buffer;
+
+/* Make sure the end offset is correct for the playing buffer */
+ for (int i = 0; i < cb_this->spec.channels; i++) {
+ /* Calculate end address, aka start of the next (i+1) channel's buffer */
+ endaddr = cb_hidden->mixbufs[cb_hidden->playingid] +
+ (cb_this->spec.samples * sizeof_sample(offs[i]) * (i + 1));
+
+ /* Trial end error to try and limit popping */
+ endaddr -= 2;
+
+ AXSetVoiceEndOffset(
+ cb_hidden->voice[i],
+ calc_ax_offset(offs[i], endaddr)
+ );
+
+ /* The next buffer is good to go, set the loop offset */
+ if (cb_hidden->renderingid != next_id(cb_hidden->playingid)) {
+ /* Calculate start address for this channel's buffer */
+ void* loopaddr = cb_hidden->mixbufs[next_id(cb_hidden->playingid)] +
+ (cb_this->spec.samples * sizeof_sample(offs[i]) * i);
+
+ AXSetVoiceLoopOffset(cb_hidden->voice[i], calc_ax_offset(offs[i], loopaddr));
+ /* Otherwise, make sure the loop offset is correct for the playing buffer */
+ } else {
+ void* loopaddr = cb_hidden->mixbufs[cb_hidden->playingid] +
+ (cb_this->spec.samples * sizeof_sample(offs[i]) * i);
+
+ AXSetVoiceLoopOffset(cb_hidden->voice[i], calc_ax_offset(offs[i], loopaddr));
+ }
+ }
+}
+
+static void WIIUAUDIO_PlayDevice(_THIS) {
+/* Deinterleave stereo audio */
+ switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
+ case 8: {
+ Uint8* samples = (Uint8*)this->hidden->mixbufs[this->hidden->renderingid];
+ Uint8* deintv = (Uint8*)this->hidden->deintvbuf;
+
+ /* Store the samples in a separate deinterleaved buffer */
+ for (int ch = 0; ch < this->spec.channels; ch++) {
+ for (int i = 0; i < this->spec.samples; i++) {
+ deintv[this->spec.samples * ch + i] = samples[i * this->spec.channels + ch];
+ }
+ }
+ } break;
+ case 16: {
+ Uint16* samples = (Uint16*)this->hidden->mixbufs[this->hidden->renderingid];
+ Uint16* deintv = (Uint16*)this->hidden->deintvbuf;
+
+ /* Store the samples in a separate deinterleaved buffer */
+ for (int ch = 0; ch < this->spec.channels; ch++) {
+ for (int i = 0; i < this->spec.samples; i++) {
+ deintv[this->spec.samples * ch + i] = samples[i * this->spec.channels + ch];
+ }
+ }
+ } break;
+ default: {} break;
+ }
+
+/* Copy the deinterleaved buffer to the mixing buffer */
+ memcpy(
+ this->hidden->mixbufs[this->hidden->renderingid],
+ this->hidden->deintvbuf,
+ this->spec.size
+ );
+/* Comment this out for broken-record mode ;3 */
+ DCStoreRange(this->hidden->mixbufs[this->hidden->renderingid], this->spec.size);
+/* Signal we're no longer rendering this buffer, AX callback will notice later */
+ this->hidden->renderingid = next_id(this->hidden->renderingid);
+}
+
+static void WIIUAUDIO_WaitDevice(_THIS) {
+/* TODO use real thread sync stuff */
+ while (SDL_AtomicGet(&this->enabled) && this->hidden->renderingid == this->hidden->playingid) {
+ OSSleepTicks(OSMillisecondsToTicks(3));
+ }
+}
+
+static Uint8* WIIUAUDIO_GetDeviceBuf(_THIS) {
+/* SDL will write audio samples into this buffer */
+ return this->hidden->mixbufs[this->hidden->renderingid];
+}
+
+static void WIIUAUDIO_CloseDevice(_THIS) {
+ if (AXIsInit()) {
+ AXDeregisterAppFrameCallback(_WIIUAUDIO_framecallback);
+ for (int i = 0; i < SIZEOF_ARR(this->hidden->voice); i++) {
+ if (this->hidden->voice[i]) {
+ AXFreeVoice(this->hidden->voice[i]);
+ this->hidden->voice[i] = NULL;
+ }
+ }
+ AXQuit();
+ }
+ if (this->hidden->mixbufs[0]) free(this->hidden->mixbufs[0]);
+ if (this->hidden->deintvbuf) SDL_free(this->hidden->deintvbuf);
+ SDL_free(this->hidden);
+}
+
+static void WIIUAUDIO_ThreadInit(_THIS) {
+/* Bump our thread's priority a bit */
+ OSThread* currentThread = OSGetCurrentThread();
+ int32_t priority = OSGetThreadPriority(currentThread);
+ priority -= 1;
+ OSSetThreadPriority(currentThread, priority);
+}
+
+static SDL_bool WIIUAUDIO_Init(SDL_AudioDriverImpl* impl) {
+ impl->OpenDevice = WIIUAUDIO_OpenDevice;
+ impl->PlayDevice = WIIUAUDIO_PlayDevice;
+ impl->WaitDevice = WIIUAUDIO_WaitDevice;
+ impl->GetDeviceBuf = WIIUAUDIO_GetDeviceBuf;
+ impl->CloseDevice = WIIUAUDIO_CloseDevice;
+ impl->ThreadInit = WIIUAUDIO_ThreadInit;
+
+ impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
+
+ return SDL_TRUE;
+}
+
+AudioBootStrap WIIUAUDIO_bootstrap = {
+ WIIUAUDIO_DRIVER_NAME, "Wii U AX Audio Driver", WIIUAUDIO_Init, 0,
+};
+
+#endif //SDL_AUDIO_DRIVER_WIIU
diff --git a/src/audio/wiiu/SDL_wiiuaudio.h b/src/audio/wiiu/SDL_wiiuaudio.h
new file mode 100644
index 000000000..41cb4a48b
--- /dev/null
+++ b/src/audio/wiiu/SDL_wiiuaudio.h
@@ -0,0 +1,51 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <[email protected]>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_wiiuaudio_h_
+#define SDL_wiiuaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+#include <sndcore2/voice.h>
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+#define NUM_BUFFERS 2
+
+#define SIZEOF_ARR(arr) (sizeof(arr) / sizeof(arr[0]))
+
+struct SDL_PrivateAudioData {
+ /* 6 possible voices for 6 channels */
+ AXVoice* voice[6];
+ /* The raw allocated mixing buffer. */
+ Uint8 *rawbuf;
+ /* Individual mixing buffers. */
+ Uint8 *mixbufs[NUM_BUFFERS];
+ /* Deinterleaving buffer. */
+ Uint8 *deintvbuf;
+
+ int renderingid;
+ int playingid;
+ uint32_t last_loopcount;
+};
+
+#endif /* SDL_wiiuaudio_h_ */
diff --git a/src/audio/wiiu/SDL_wiiuaudio_mix.h b/src/audio/wiiu/SDL_wiiuaudio_mix.h
new file mode 100644
index 000000000..57b661c89
--- /dev/null
+++ b/src/audio/wiiu/SDL_wiiuaudio_mix.h
@@ -0,0 +1,65 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <[email protected]>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_wiiuaudio_mix_h_
+#define SDL_wiiuaudio_mix_h_
+
+/* Some defines to help make the code below more readable */
+#define AX_VOICE(x) x
+#define AX_CHANNEL_LEFT 0
+#define AX_CHANNEL_RIGHT 1
+#define AX_BUS_MASTER 0
+
+/* TODO: AXGetDeviceChannelCount. For now we'll use Decaf's values.
+ * According to Decaf, the TV has 6 channels and the gamepad has 4. We set up
+ * both arrays with 6, the Gamepad callbacks just won't use the whole buffer. */
+#define AX_NUM_CHANNELS 6
+
+static AXVoiceDeviceMixData stereo_mix[2 /* voices */][AX_NUM_CHANNELS] = {
+ [AX_VOICE(0)] = {
+ [AX_CHANNEL_LEFT] = {
+ .bus = {
+ [AX_BUS_MASTER] = { .volume = 0x8000 },
+ }
+ },
+ },
+ [AX_VOICE(1)] = {
+ [AX_CHANNEL_RIGHT] = {
+ .bus = {
+ [AX_BUS_MASTER] = { .volume = 0x8000 },
+ }
+ },
+ },
+};
+static AXVoiceDeviceMixData mono_mix[1 /* voice */][AX_NUM_CHANNELS] = {
+ [AX_VOICE(0)] = {
+ [AX_CHANNEL_LEFT] = { .bus = {
+ [AX_BUS_MASTER] = { .volume = 0x8000 },
+ }},
+ [AX_CHANNEL_RIGHT] = { .bus = {