Skip to content

Commit cef60bf

Browse files
committed
Update to mGBA 0.7.0
1 parent 52199d6 commit cef60bf

File tree

164 files changed

+6973
-2178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+6973
-2178
lines changed

Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleSignature</key>
1818
<string>????</string>
1919
<key>CFBundleVersion</key>
20-
<string>0.6.3</string>
20+
<string>0.7.0</string>
2121
<key>NSPrincipalClass</key>
2222
<string>OEGameCoreController</string>
2323
<key>OEGameCoreClass</key>

include/mgba-util/arm-algo.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
#define ARM_ALGO_H
88

99
#ifdef __arm__
10-
void _to16Bit(uint16_t* dest, uint32_t* src, size_t words);
11-
1210
#if defined(__ARM_NEON)
1311
void _neon2x(void* dest, void* src, int width, int height);
1412
void _neon4x(void* dest, void* src, int width, int height);
1513
#endif
1614
#endif
1715

18-
#endif
16+
#endif

include/mgba-util/common.h

+13-6
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ typedef intptr_t ssize_t;
119119
#define STORE_32LE(SRC, ADDR, ARR) { \
120120
uint32_t _addr = (ADDR); \
121121
void* _ptr = (ARR); \
122-
__asm__("stwbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr)); \
122+
__asm__("stwbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr) : "memory"); \
123123
}
124124

125125
#define STORE_16LE(SRC, ADDR, ARR) { \
126126
uint32_t _addr = (ADDR); \
127127
void* _ptr = (ARR); \
128-
__asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr)); \
128+
__asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr) : "memory"); \
129129
}
130130

131131
#define LOAD_64LE(DEST, ADDR, ARR) { \
@@ -136,12 +136,13 @@ typedef intptr_t ssize_t;
136136
uint32_t lo; \
137137
}; \
138138
uint64_t b64; \
139-
} *bswap = (void*) &DEST; \
139+
} bswap; \
140140
const void* _ptr = (ARR); \
141141
__asm__( \
142142
"lwbrx %0, %2, %3 \n" \
143143
"lwbrx %1, %2, %4 \n" \
144-
: "=r"(bswap->lo), "=r"(bswap->hi) : "b"(_ptr), "r"(_addr), "r"(_addr + 4)); \
144+
: "=&r"(bswap.lo), "=&r"(bswap.hi) : "b"(_ptr), "r"(_addr), "r"(_addr + 4)) ; \
145+
DEST = bswap.b64; \
145146
}
146147

147148
#define STORE_64LE(SRC, ADDR, ARR) { \
@@ -152,12 +153,12 @@ typedef intptr_t ssize_t;
152153
uint32_t lo; \
153154
}; \
154155
uint64_t b64; \
155-
} *bswap = (void*) &SRC; \
156+
} bswap = { .b64 = SRC }; \
156157
const void* _ptr = (ARR); \
157158
__asm__( \
158159
"stwbrx %0, %2, %3 \n" \
159160
"stwbrx %1, %2, %4 \n" \
160-
: : "r"(bswap->hi), "r"(bswap->lo), "b"(_ptr), "r"(_addr), "r"(_addr + 4)); \
161+
: : "r"(bswap.hi), "r"(bswap.lo), "b"(_ptr), "r"(_addr), "r"(_addr + 4) : "memory"); \
161162
}
162163

163164
#elif defined(__llvm__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
@@ -177,8 +178,12 @@ typedef intptr_t ssize_t;
177178
#define STORE_64LE(SRC, ADDR, ARR) *(uint64_t*) ((uintptr_t) (ARR) + (size_t) (ADDR)) = SRC
178179
#define STORE_32LE(SRC, ADDR, ARR) *(uint32_t*) ((uintptr_t) (ARR) + (size_t) (ADDR)) = SRC
179180
#define STORE_16LE(SRC, ADDR, ARR) *(uint16_t*) ((uintptr_t) (ARR) + (size_t) (ADDR)) = SRC
181+
#ifdef _MSC_VER
182+
#define LOAD_32BE(DEST, ADDR, ARR) DEST = _byteswap_ulong(((uint32_t*) ARR)[(ADDR) >> 2])
183+
#else
180184
#define LOAD_32BE(DEST, ADDR, ARR) DEST = __builtin_bswap32(((uint32_t*) ARR)[(ADDR) >> 2])
181185
#endif
186+
#endif
182187

183188
#define MAKE_MASK(START, END) (((1 << ((END) - (START))) - 1) << (START))
184189
#define CHECK_BITS(SRC, START, END) ((SRC) & MAKE_MASK(START, END))
@@ -191,9 +196,11 @@ typedef intptr_t ssize_t;
191196
#ifdef _MSC_VER
192197
#define ATTRIBUTE_UNUSED
193198
#define ATTRIBUTE_FORMAT(X, Y, Z)
199+
#define ATTRIBUTE_NOINLINE
194200
#else
195201
#define ATTRIBUTE_UNUSED __attribute__((unused))
196202
#define ATTRIBUTE_FORMAT(X, Y, Z) __attribute__((format(X, Y, Z)))
203+
#define ATTRIBUTE_NOINLINE __attribute__((noinline))
197204
#endif
198205

199206
#define DECL_BITFIELD(NAME, TYPE) typedef TYPE NAME

include/mgba-util/crc32.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ CXX_GUARD_START
1212

1313
struct VFile;
1414

15+
#ifndef HAVE_CRC32
16+
uint32_t crc32(uint32_t crc, const void* buf, size_t size);
17+
#else
18+
#include <zlib.h>
19+
#endif
20+
1521
uint32_t doCrc32(const void* buf, size_t size);
16-
uint32_t updateCrc32(uint32_t crc, const void* buf, size_t size);
1722
uint32_t fileCrc32(struct VFile* file, size_t endOffset);
1823

1924
CXX_GUARD_END

include/mgba-util/elf-read.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* Copyright (c) 2013-2017 Jeffrey Pfau
2+
*
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6+
#ifndef ELF_READ_H
7+
#define ELF_READ_H
8+
9+
#include <mgba-util/common.h>
10+
11+
CXX_GUARD_START
12+
13+
#ifdef USE_ELF
14+
15+
#include <libelf.h>
16+
17+
#include <mgba-util/vector.h>
18+
19+
struct ELF;
20+
struct VFile;
21+
22+
DECLARE_VECTOR(ELFProgramHeaders, Elf32_Phdr);
23+
DECLARE_VECTOR(ELFSectionHeaders, Elf32_Shdr);
24+
25+
struct ELF* ELFOpen(struct VFile*);
26+
void ELFClose(struct ELF*);
27+
28+
void* ELFBytes(struct ELF*, size_t* size);
29+
30+
uint16_t ELFMachine(struct ELF*);
31+
uint32_t ELFEntry(struct ELF*);
32+
33+
void ELFGetProgramHeaders(struct ELF*, struct ELFProgramHeaders*);
34+
35+
size_t ELFFindSection(struct ELF*, const char* name);
36+
void ELFGetSectionHeaders(struct ELF*, struct ELFSectionHeaders*);
37+
Elf32_Shdr* ELFGetSectionHeader(struct ELF*, size_t index);
38+
39+
const char* ELFGetString(struct ELF*, size_t section, size_t string);
40+
41+
#endif
42+
43+
CXX_GUARD_END
44+
45+
#endif

include/mgba-util/formatting.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ CXX_GUARD_START
1212

1313
#include "locale.h"
1414

15-
#if defined(__APPLE__) || defined(__FreeBSD__)
16-
#include "xlocale.h"
15+
#ifdef HAVE_XLOCALE
16+
#include <xlocale.h>
1717
#elif !defined(HAVE_LOCALE)
1818
typedef const char* locale_t;
1919
#endif

include/mgba-util/gui.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum {
4747
BATTERY_HIGH = 3,
4848
BATTERY_FULL = 4,
4949

50-
BATTERY_CHARGING = 8
50+
BATTERY_CHARGING = 8,
51+
BATTERY_NOT_PRESENT = 16
5152
};
5253

5354
struct GUIBackground {

include/mgba-util/gui/file-select.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CXX_GUARD_START
1414

1515
struct VFile;
1616

17-
bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filter)(struct VFile*));
17+
bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*));
1818

1919
CXX_GUARD_END
2020

include/mgba-util/gui/menu.h

+25
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,37 @@ CXX_GUARD_START
1212

1313
#include <mgba-util/vector.h>
1414

15+
#define GUI_V_V (struct GUIVariant) { .type = GUI_VARIANT_VOID }
16+
#define GUI_V_U(U) (struct GUIVariant) { .type = GUI_VARIANT_UNSIGNED, .v.u = (U) }
17+
#define GUI_V_I(I) (struct GUIVariant) { .type = GUI_VARIANT_INT, .v.i = (I) }
18+
#define GUI_V_F(F) (struct GUIVariant) { .type = GUI_VARIANT_FLOAT, .v.f = (F) }
19+
#define GUI_V_S(S) (struct GUIVariant) { .type = GUI_VARIANT_STRING, .v.s = (S) }
20+
21+
enum GUIVariantType {
22+
GUI_VARIANT_VOID = 0,
23+
GUI_VARIANT_UNSIGNED,
24+
GUI_VARIANT_INT,
25+
GUI_VARIANT_FLOAT,
26+
GUI_VARIANT_STRING
27+
};
28+
29+
struct GUIVariant {
30+
enum GUIVariantType type;
31+
union {
32+
unsigned u;
33+
int i;
34+
float f;
35+
const char* s;
36+
} v;
37+
};
38+
1539
struct GUIMenu;
1640
struct GUIMenuItem {
1741
const char* title;
1842
void* data;
1943
unsigned state;
2044
const char* const* validStates;
45+
const struct GUIVariant* stateMappings;
2146
unsigned nStates;
2247
struct GUIMenu* submenu;
2348
};

include/mgba-util/platform/3ds/threading.h

+3-22
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,9 @@
1111
#include <3ds.h>
1212
#include <malloc.h>
1313

14-
#ifdef _3DS
15-
// ctrulib already has a type called Thread
16-
#define Thread CustomThread
17-
#endif
18-
1914
#define THREAD_ENTRY void
2015
typedef ThreadFunc ThreadEntry;
2116

22-
typedef struct {
23-
Handle handle;
24-
u8* stack;
25-
} Thread;
2617
typedef LightLock Mutex;
2718
typedef struct {
2819
Mutex mutex;
@@ -103,22 +94,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
10394
if (!entry || !thread) {
10495
return 1;
10596
}
106-
thread->stack = memalign(8, 0x8000);
107-
if (!thread->stack) {
108-
return 1;
109-
}
110-
bool isNew3DS;
111-
APT_CheckNew3DS(&isNew3DS);
112-
if (isNew3DS && svcCreateThread(&thread->handle, entry, (u32) context, (u32*) &thread->stack[0x8000], 0x18, 2) == 0) {
113-
return 0;
114-
}
115-
return svcCreateThread(&thread->handle, entry, (u32) context, (u32*) &thread->stack[0x8000], 0x18, -1);
97+
*thread = threadCreate(entry, context, 0x8000, 0x18, 2, true);
98+
return !*thread;
11699
}
117100

118101
static inline int ThreadJoin(Thread thread) {
119-
svcWaitSynchronization(thread.handle, U64_MAX);
120-
free(thread.stack);
121-
return 0;
102+
return threadJoin(thread, U64_MAX);
122103
}
123104

124105
static inline void ThreadSetName(const char* name) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* Copyright (c) 2013-2018 Jeffrey Pfau
2+
*
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6+
#ifndef SWITCH_THREADING_H
7+
#define SWITCH_THREADING_H
8+
9+
#include <mgba-util/common.h>
10+
11+
#include <switch.h>
12+
13+
#define THREAD_ENTRY void
14+
typedef ThreadFunc ThreadEntry;
15+
typedef CondVar Condition;
16+
17+
static inline int MutexInit(Mutex* mutex) {
18+
mutexInit(mutex);
19+
return 0;
20+
}
21+
22+
static inline int MutexDeinit(Mutex* mutex) {
23+
UNUSED(mutex);
24+
return 0;
25+
}
26+
27+
static inline int MutexLock(Mutex* mutex) {
28+
mutexLock(mutex);
29+
return 0;
30+
}
31+
32+
static inline int MutexTryLock(Mutex* mutex) {
33+
return mutexTryLock(mutex);
34+
}
35+
36+
static inline int MutexUnlock(Mutex* mutex) {
37+
mutexUnlock(mutex);
38+
return 0;
39+
}
40+
41+
static inline int ConditionInit(Condition* cond) {
42+
condvarInit(cond);
43+
return 0;
44+
}
45+
46+
static inline int ConditionDeinit(Condition* cond) {
47+
UNUSED(cond);
48+
return 0;
49+
}
50+
51+
static inline int ConditionWait(Condition* cond, Mutex* mutex) {
52+
return condvarWait(cond, mutex);
53+
}
54+
55+
static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
56+
return condvarWaitTimeout(cond, mutex, timeoutMs * 1000000LL);
57+
}
58+
59+
static inline int ConditionWake(Condition* cond) {
60+
return condvarWakeOne(cond);
61+
}
62+
63+
static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context) {
64+
if (!entry || !thread) {
65+
return 1;
66+
}
67+
int res = threadCreate(thread, entry, context, 0x8000, 0x3B, 1);
68+
if(R_FAILED(res)) {
69+
return res;
70+
}
71+
return threadStart(thread);
72+
}
73+
74+
static inline int ThreadJoin(Thread thread) {
75+
int res = threadWaitForExit(&thread);
76+
if(R_FAILED(res)) {
77+
return res;
78+
}
79+
return threadClose(&thread);
80+
}
81+
82+
static inline void ThreadSetName(const char* name) {
83+
UNUSED(name);
84+
// Unimplemented
85+
}
86+
87+
#endif

include/mgba-util/png-io.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ enum {
2626

2727
png_structp PNGWriteOpen(struct VFile* source);
2828
png_infop PNGWriteHeader(png_structp png, unsigned width, unsigned height);
29+
png_infop PNGWriteHeaderA(png_structp png, unsigned width, unsigned height);
2930
png_infop PNGWriteHeader8(png_structp png, unsigned width, unsigned height);
3031
bool PNGWritePalette(png_structp png, png_infop info, const uint32_t* palette, unsigned entries);
3132
bool PNGWritePixels(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
33+
bool PNGWritePixelsA(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
3234
bool PNGWritePixels8(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
3335
bool PNGWriteCustomChunk(png_structp png, const char* name, size_t size, void* data);
3436
void PNGWriteClose(png_structp png, png_infop info);
@@ -40,6 +42,8 @@ png_structp PNGReadOpen(struct VFile* source, unsigned offset);
4042
bool PNGInstallChunkHandler(png_structp png, void* context, ChunkHandler handler, const char* chunkName);
4143
bool PNGReadHeader(png_structp png, png_infop info);
4244
bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
45+
bool PNGReadPixelsA(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
46+
bool PNGReadPixels8(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride);
4347
bool PNGIgnorePixels(png_structp png, png_infop info);
4448
bool PNGReadFooter(png_structp png, png_infop end);
4549
void PNGReadClose(png_structp png, png_infop info, png_infop end);

include/mgba-util/ring-fifo.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct RingFIFO {
2020
void RingFIFOInit(struct RingFIFO* buffer, size_t capacity);
2121
void RingFIFODeinit(struct RingFIFO* buffer);
2222
size_t RingFIFOCapacity(const struct RingFIFO* buffer);
23+
size_t RingFIFOSize(const struct RingFIFO* buffer);
2324
void RingFIFOClear(struct RingFIFO* buffer);
2425
size_t RingFIFOWrite(struct RingFIFO* buffer, const void* value, size_t length);
2526
size_t RingFIFORead(struct RingFIFO* buffer, void* output, size_t length);

0 commit comments

Comments
 (0)