├── .gitignore
├── Info.plist
├── LICENSE
├── README.md
├── en.lproj
└── InfoPlist.strings
├── include
├── mgba-util
│ ├── circle-buffer.h
│ ├── common.h
│ ├── configuration.h
│ ├── convolve.h
│ ├── crc32.h
│ ├── dllexports.h
│ ├── elf-read.h
│ ├── export.h
│ ├── formatting.h
│ ├── gui.h
│ ├── gui
│ │ ├── file-select.h
│ │ ├── font-metrics.h
│ │ ├── font.h
│ │ └── menu.h
│ ├── hash.h
│ ├── macros.h
│ ├── math.h
│ ├── memory.h
│ ├── patch.h
│ ├── patch
│ │ ├── fast.h
│ │ ├── ips.h
│ │ └── ups.h
│ ├── platform
│ │ ├── 3ds
│ │ │ ├── 3ds-vfs.h
│ │ │ └── threading.h
│ │ ├── posix
│ │ │ └── threading.h
│ │ ├── psp2
│ │ │ ├── sce-vfs.h
│ │ │ └── threading.h
│ │ ├── switch
│ │ │ └── threading.h
│ │ └── windows
│ │ │ ├── getopt.h
│ │ │ └── threading.h
│ ├── png-io.h
│ ├── ring-fifo.h
│ ├── socket.h
│ ├── string.h
│ ├── table.h
│ ├── text-codec.h
│ ├── threading.h
│ ├── vector.h
│ └── vfs.h
└── mgba
│ ├── core
│ ├── bitmap-cache.h
│ ├── blip_buf.h
│ ├── cache-set.h
│ ├── cheats.h
│ ├── config.h
│ ├── core.h
│ ├── cpu.h
│ ├── directories.h
│ ├── input.h
│ ├── interface.h
│ ├── library.h
│ ├── lockstep.h
│ ├── log.h
│ ├── map-cache.h
│ ├── mem-search.h
│ ├── rewind.h
│ ├── scripting.h
│ ├── serialize.h
│ ├── sync.h
│ ├── thread.h
│ ├── tile-cache.h
│ ├── timing.h
│ └── version.h
│ ├── debugger
│ └── debugger.h
│ ├── feature
│ ├── commandline.h
│ ├── thread-proxy.h
│ ├── updater.h
│ └── video-logger.h
│ ├── gb
│ ├── core.h
│ └── interface.h
│ ├── gba
│ ├── core.h
│ └── interface.h
│ ├── internal
│ ├── arm
│ │ ├── arm.h
│ │ ├── debugger
│ │ │ ├── cli-debugger.h
│ │ │ ├── debugger.h
│ │ │ └── memory-debugger.h
│ │ ├── decoder-inlines.h
│ │ ├── decoder.h
│ │ ├── emitter-arm.h
│ │ ├── emitter-inlines.h
│ │ ├── emitter-thumb.h
│ │ ├── isa-arm.h
│ │ ├── isa-inlines.h
│ │ ├── isa-thumb.h
│ │ └── macros.h
│ ├── debugger
│ │ ├── cli-debugger.h
│ │ ├── gdb-stub.h
│ │ ├── parser.h
│ │ ├── stack-trace.h
│ │ └── symbols.h
│ ├── defines.h
│ ├── gb
│ │ ├── audio.h
│ │ ├── cheats.h
│ │ ├── debugger
│ │ │ ├── debugger.h
│ │ │ └── symbols.h
│ │ ├── extra
│ │ │ └── cli.h
│ │ ├── gb.h
│ │ ├── input.h
│ │ ├── io.h
│ │ ├── mbc.h
│ │ ├── memory.h
│ │ ├── overrides.h
│ │ ├── renderers
│ │ │ ├── cache-set.h
│ │ │ ├── proxy.h
│ │ │ └── software.h
│ │ ├── serialize.h
│ │ ├── sio.h
│ │ ├── sio
│ │ │ ├── lockstep.h
│ │ │ └── printer.h
│ │ ├── timer.h
│ │ └── video.h
│ ├── gba
│ │ ├── audio.h
│ │ ├── bios.h
│ │ ├── cart
│ │ │ ├── ereader.h
│ │ │ ├── gpio.h
│ │ │ ├── matrix.h
│ │ │ └── vfame.h
│ │ ├── cheats.h
│ │ ├── dma.h
│ │ ├── extra
│ │ │ ├── audio-mixer.h
│ │ │ └── cli.h
│ │ ├── gba.h
│ │ ├── input.h
│ │ ├── io.h
│ │ ├── memory.h
│ │ ├── overrides.h
│ │ ├── renderers
│ │ │ ├── cache-set.h
│ │ │ ├── common.h
│ │ │ ├── gl.h
│ │ │ ├── proxy.h
│ │ │ └── video-software.h
│ │ ├── savedata.h
│ │ ├── serialize.h
│ │ ├── sharkport.h
│ │ ├── sio.h
│ │ ├── sio
│ │ │ ├── dolphin.h
│ │ │ ├── gbp.h
│ │ │ └── lockstep.h
│ │ ├── timer.h
│ │ └── video.h
│ ├── script
│ │ ├── lua.h
│ │ └── socket.h
│ └── sm83
│ │ ├── debugger
│ │ ├── cli-debugger.h
│ │ ├── debugger.h
│ │ └── memory-debugger.h
│ │ ├── decoder.h
│ │ ├── emitter-sm83.h
│ │ ├── isa-sm83.h
│ │ └── sm83.h
│ └── script
│ ├── context.h
│ ├── macros.h
│ └── types.h
├── mGBA.xcodeproj
├── TemplateIcon.icns
└── project.pbxproj
└── src
├── arm
├── CMakeLists.txt
├── arm.c
├── debugger
│ ├── cli-debugger.c
│ ├── debugger.c
│ └── memory-debugger.c
├── decoder-arm.c
├── decoder-thumb.c
├── decoder.c
├── isa-arm.c
└── isa-thumb.c
├── core
├── CMakeLists.txt
├── bitmap-cache.c
├── cache-set.c
├── cheats.c
├── config.c
├── core.c
├── directories.c
├── flags.h.in
├── input.c
├── interface.c
├── library.c
├── lockstep.c
├── log.c
├── map-cache.c
├── mem-search.c
├── rewind.c
├── scripting.c
├── serialize.c
├── sync.c
├── test
│ ├── core.c
│ └── scripting.c
├── thread.c
├── tile-cache.c
├── timing.c
└── version.c.in
├── gb
├── CMakeLists.txt
├── audio.c
├── cheats.c
├── core.c
├── debugger
│ ├── cli.c
│ ├── debugger.c
│ └── symbols.c
├── extra
│ └── proxy.c
├── gb.c
├── input.c
├── io.c
├── mbc.c
├── memory.c
├── overrides.c
├── renderers
│ ├── cache-set.c
│ └── software.c
├── serialize.c
├── sio.c
├── sio
│ ├── lockstep.c
│ └── printer.c
├── test
│ ├── core.c
│ ├── gbx.c
│ ├── mbc.c
│ ├── memory.c
│ └── rtc.c
├── timer.c
└── video.c
├── gba
├── CMakeLists.txt
├── audio.c
├── bios.c
├── cart
│ ├── ereader.c
│ ├── gpio.c
│ ├── matrix.c
│ └── vfame.c
├── cheats.c
├── cheats
│ ├── codebreaker.c
│ ├── gameshark.c
│ ├── gameshark.h
│ ├── parv3.c
│ └── parv3.h
├── core.c
├── debugger
│ └── cli.c
├── dma.c
├── extra
│ ├── audio-mixer.c
│ ├── battlechip.c
│ └── proxy.c
├── gba.c
├── hle-bios.c
├── hle-bios.h
├── hle-bios.make
├── hle-bios.s
├── input.c
├── io.c
├── memory.c
├── overrides.c
├── renderers
│ ├── cache-set.c
│ ├── common.c
│ ├── gl.c
│ ├── software-bg.c
│ ├── software-mode0.c
│ ├── software-obj.c
│ ├── software-private.h
│ └── video-software.c
├── savedata.c
├── serialize.c
├── sharkport.c
├── sio.c
├── sio
│ ├── dolphin.c
│ ├── gbp.c
│ ├── joybus.c
│ └── lockstep.c
├── test
│ ├── cheats.c
│ └── core.c
├── timer.c
└── video.c
├── platform
├── openemu
│ ├── Info.plist.in
│ ├── OEGBASystemResponderClient.h
│ ├── mGBAGameCore.h
│ └── mGBAGameCore.m
├── posix
│ └── memory.c
└── video-backend.h
├── third-party
├── blip_buf
│ ├── blip_buf.c
│ └── license.txt
└── inih
│ ├── LICENSE.txt
│ ├── README.md
│ ├── ini.c
│ └── ini.h
└── util
├── CMakeLists.txt
├── circle-buffer.c
├── configuration.c
├── convolve.c
├── crc32.c
├── elf-read.c
├── export.c
├── formatting.c
├── gbk-table.c
├── gui.c
├── gui
├── file-select.c
├── font-metrics.c
├── font.c
└── menu.c
├── hash.c
├── memory.c
├── patch-fast.c
├── patch-ips.c
├── patch-ups.c
├── patch.c
├── png-io.c
├── ring-fifo.c
├── string.c
├── table.c
├── test
├── string-parser.c
├── string-utf8.c
├── suite.h
├── table.c
├── text-codec.c
└── vfs.c
├── text-codec.c
├── vfs.c
└── vfs
├── vfs-devlist.c
├── vfs-dirent.c
├── vfs-fd.c
├── vfs-fifo.c
├── vfs-file.c
├── vfs-lzma.c
├── vfs-mem.c
└── vfs-zip.c
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | *.DS_Store
3 | OEBuildVersion.h
4 | */build/*
5 | *.pbxuser
6 | !default.pbxuser
7 | *.mode1v3
8 | !default.mode1v3
9 | *.mode2v3
10 | !default.mode2v3
11 | *.perspectivev3
12 | !default.perspectivev3
13 | *.xcworkspace
14 | !OpenEmu.xcworkspace
15 | !default.xcworkspace
16 | xcuserdata
17 | profile
18 | *.moved-aside
19 | icon?
20 |
--------------------------------------------------------------------------------
/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 | OEGameCoreController
23 | OEGameCoreClass
24 | mGBAGameCore
25 | OEGameCoreOptions
26 |
27 | openemu.system.gba
28 |
29 | OEGameCoreRewindBufferSeconds
30 | 60
31 | OEGameCoreRewindInterval
32 | 0
33 | OEGameCoreSupportsCheatCode
34 |
35 | OEGameCoreSupportsRewinding
36 |
37 |
38 |
39 | OEGameCorePlayerCount
40 | 1
41 | OEProjectURL
42 | https://mgba.io/
43 | OESystemIdentifiers
44 |
45 | openemu.system.gba
46 |
47 | SUEnableAutomaticChecks
48 |
49 | SUFeedURL
50 | https://raw.github.com/OpenEmu/OpenEmu-Update/master/mgba_appcast.xml
51 |
52 |
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # mGBA-Core
2 | OpenEmu Core plugin with mGBA to support GBA emulation
3 |
--------------------------------------------------------------------------------
/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/include/mgba-util/circle-buffer.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 CIRCLE_BUFFER_H
7 | #define CIRCLE_BUFFER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct CircleBuffer {
14 | void* data;
15 | size_t capacity;
16 | size_t size;
17 | void* readPtr;
18 | void* writePtr;
19 | };
20 |
21 | void CircleBufferInit(struct CircleBuffer* buffer, unsigned capacity);
22 | void CircleBufferDeinit(struct CircleBuffer* buffer);
23 | size_t CircleBufferSize(const struct CircleBuffer* buffer);
24 | size_t CircleBufferCapacity(const struct CircleBuffer* buffer);
25 | void CircleBufferClear(struct CircleBuffer* buffer);
26 | int CircleBufferWrite8(struct CircleBuffer* buffer, int8_t value);
27 | int CircleBufferWrite16(struct CircleBuffer* buffer, int16_t value);
28 | int CircleBufferWrite32(struct CircleBuffer* buffer, int32_t value);
29 | size_t CircleBufferWrite(struct CircleBuffer* buffer, const void* input, size_t length);
30 | int CircleBufferRead8(struct CircleBuffer* buffer, int8_t* value);
31 | int CircleBufferRead16(struct CircleBuffer* buffer, int16_t* value);
32 | int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value);
33 | size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length);
34 | size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length);
35 |
36 | CXX_GUARD_END
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/include/mgba-util/configuration.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 CONFIGURATION_H
7 | #define CONFIGURATION_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct VFile;
16 |
17 | struct Configuration {
18 | struct Table sections;
19 | struct Table root;
20 | };
21 |
22 | void ConfigurationInit(struct Configuration*);
23 | void ConfigurationDeinit(struct Configuration*);
24 |
25 | void ConfigurationSetValue(struct Configuration*, const char* section, const char* key, const char* value);
26 | void ConfigurationSetIntValue(struct Configuration*, const char* section, const char* key, int value);
27 | void ConfigurationSetUIntValue(struct Configuration*, const char* section, const char* key, unsigned value);
28 | void ConfigurationSetFloatValue(struct Configuration*, const char* section, const char* key, float value);
29 |
30 | bool ConfigurationHasSection(const struct Configuration*, const char* section);
31 | void ConfigurationDeleteSection(struct Configuration*, const char* section);
32 |
33 | const char* ConfigurationGetValue(const struct Configuration*, const char* section, const char* key);
34 |
35 | void ConfigurationClearValue(struct Configuration*, const char* section, const char* key);
36 |
37 | bool ConfigurationRead(struct Configuration*, const char* path);
38 | bool ConfigurationReadVFile(struct Configuration*, struct VFile* vf);
39 | bool ConfigurationWrite(const struct Configuration*, const char* path);
40 | bool ConfigurationWriteSection(const struct Configuration*, const char* path, const char* section);
41 | bool ConfigurationWriteVFile(const struct Configuration*, struct VFile* vf);
42 |
43 | void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user);
44 | void ConfigurationEnumerate(const struct Configuration* configuration, const char* section, void (*handler)(const char* key, const char* value, void* user), void* user);
45 |
46 | CXX_GUARD_END
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/include/mgba-util/convolve.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2021 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 CONVOLVE_H
7 | #define CONVOLVE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct ConvolutionKernel {
14 | float* kernel;
15 | size_t* dims;
16 | size_t rank;
17 | };
18 |
19 | void ConvolutionKernelCreate(struct ConvolutionKernel* kernel, size_t rank, size_t* dims);
20 | void ConvolutionKernelDestroy(struct ConvolutionKernel* kernel);
21 |
22 | void ConvolutionKernelFillRadial(struct ConvolutionKernel* kernel, bool normalize);
23 | void ConvolutionKernelFillCircle(struct ConvolutionKernel* kernel, bool normalize);
24 |
25 | // TODO: Make image container struct?
26 | void Convolve1DPad0PackedS32(const int32_t* restrict src, int32_t* restrict dst, size_t length, const struct ConvolutionKernel* restrict kernel);
27 |
28 | void Convolve2DClampPacked8(const uint8_t* restrict src, uint8_t* restrict dst, size_t width, size_t height, size_t stride, const struct ConvolutionKernel* restrict kernel);
29 | void Convolve2DClampChannels8(const uint8_t* restrict src, uint8_t* restrict dst, size_t width, size_t height, size_t stride, size_t channels, const struct ConvolutionKernel* restrict kernel);
30 |
31 | CXX_GUARD_END
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/include/mgba-util/crc32.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 CRC32_H
7 | #define CRC32_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct VFile;
14 |
15 | #ifndef HAVE_CRC32
16 | uint32_t crc32(uint32_t crc, const void* buf, size_t size);
17 | #else
18 | #include
19 | #endif
20 |
21 | uint32_t doCrc32(const void* buf, size_t size);
22 | uint32_t fileCrc32(struct VFile* file, size_t endOffset);
23 |
24 | CXX_GUARD_END
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/include/mgba-util/dllexports.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2020 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 MGBA_EXPORT_H
7 | #define MGBA_EXPORT_H
8 |
9 | #if defined(BUILD_STATIC) || !defined(_MSC_VER) || defined(MGBA_STANDALONE)
10 | #define MGBA_EXPORT
11 | #else
12 | #ifdef MGBA_DLL
13 | #define MGBA_EXPORT __declspec(dllexport)
14 | #else
15 | #define MGBA_EXPORT __declspec(dllimport)
16 | #endif
17 | #endif
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/mgba-util/elf-read.h:
--------------------------------------------------------------------------------
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
10 |
11 | CXX_GUARD_START
12 |
13 | #ifdef USE_ELF
14 |
15 | #include
16 |
17 | #include
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
46 |
--------------------------------------------------------------------------------
/include/mgba-util/export.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 EXPORT_H
7 | #define EXPORT_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct VFile;
14 |
15 | bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors);
16 | bool exportPaletteACT(struct VFile* vf, size_t entries, const uint16_t* colors);
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/include/mgba-util/formatting.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 FORMATTING_H
7 | #define FORMATTING_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include "locale.h"
14 |
15 | #ifdef HAVE_XLOCALE
16 | #include
17 | #elif !defined(HAVE_LOCALE)
18 | typedef const char* locale_t;
19 | #endif
20 |
21 | int ftostr_l(char* restrict str, size_t size, float f, locale_t locale);
22 |
23 | #ifndef HAVE_STRTOF_L
24 | float strtof_l(const char* restrict str, char** restrict end, locale_t locale);
25 | #endif
26 |
27 | int ftostr_u(char* restrict str, size_t size, float f);
28 | float strtof_u(const char* restrict str, char** restrict end);
29 |
30 | #ifndef HAVE_LOCALTIME_R
31 | struct tm* localtime_r(const time_t* timep, struct tm* result);
32 | #endif
33 |
34 | CXX_GUARD_END
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/mgba-util/gui.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GUI_H
7 | #define GUI_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | // TODO: Fix layering violation
14 | #include
15 | #include
16 |
17 | #define MAX_KEYBOARD_LEN 256
18 | #define MAX_KEYBOARD_TITLE_LEN 128
19 |
20 | struct GUIFont;
21 |
22 | enum GUIInput {
23 | GUI_INPUT_NONE = -1,
24 | GUI_INPUT_SELECT = 0,
25 | GUI_INPUT_BACK,
26 | GUI_INPUT_CANCEL,
27 |
28 | GUI_INPUT_UP,
29 | GUI_INPUT_DOWN,
30 | GUI_INPUT_LEFT,
31 | GUI_INPUT_RIGHT,
32 |
33 | GUI_INPUT_USER_START = 0x8,
34 |
35 | GUI_INPUT_MAX = 0x20
36 | };
37 |
38 | enum GUICursorState {
39 | GUI_CURSOR_NOT_PRESENT = 0,
40 | GUI_CURSOR_UP,
41 | GUI_CURSOR_DOWN,
42 | GUI_CURSOR_CLICKED,
43 | GUI_CURSOR_DRAGGING
44 | };
45 |
46 | enum GUIKeyboardStatus {
47 | GUI_KEYBOARD_DONE = 0,
48 | GUI_KEYBOARD_CANCEL,
49 | };
50 |
51 | enum GUIKeyFunction {
52 | GUI_KEYFUNC_INPUT_DATA = 0,
53 | GUI_KEYFUNC_CHANGE_KB,
54 | GUI_KEYFUNC_SHIFT_KB,
55 | GUI_KEYFUNC_BACKSPACE,
56 | GUI_KEYFUNC_ENTER,
57 | GUI_KEYFUNC_CANCEL,
58 | GUI_KEYFUNC_LEFT,
59 | GUI_KEYFUNC_RIGHT,
60 | };
61 |
62 | enum {
63 | BATTERY_EMPTY = 0,
64 | BATTERY_LOW = 25,
65 | BATTERY_HALF = 50,
66 | BATTERY_HIGH = 75,
67 | BATTERY_FULL = 100,
68 | BATTERY_VALUE = 0x7F,
69 | BATTERY_PERCENTAGE_VALID = 0x80,
70 |
71 | BATTERY_CHARGING = 0x100,
72 | BATTERY_NOT_PRESENT = 0x200,
73 | };
74 |
75 | struct GUIBackground {
76 | void (*draw)(struct GUIBackground*, void* context);
77 | };
78 |
79 | struct GUIKeyboardParams {
80 | char title[MAX_KEYBOARD_TITLE_LEN];
81 | char result[MAX_KEYBOARD_LEN];
82 | size_t maxLen;
83 | bool multiline;
84 | };
85 |
86 | struct GUIKey {
87 | const char* name;
88 | const void* data;
89 | int width;
90 | enum GUIKeyFunction function;
91 | };
92 |
93 | struct GUIKeyboard {
94 | struct {
95 | int offset;
96 | struct GUIKey* keys;
97 | } rows[5];
98 | int width;
99 | };
100 |
101 | struct GUIParams {
102 | unsigned width;
103 | unsigned height;
104 | struct GUIFont* font;
105 | const char* basePath;
106 |
107 | void (*drawStart)(void);
108 | void (*drawEnd)(void);
109 | uint32_t (*pollInput)(const struct mInputMap*);
110 | enum GUICursorState (*pollCursor)(unsigned* x, unsigned* y);
111 | int (*batteryState)(void);
112 | void (*guiPrepare)(void);
113 | void (*guiFinish)(void);
114 | enum GUIKeyboardStatus (*getText)(struct GUIKeyboardParams*);
115 |
116 | // State
117 | struct mInputMap keyMap;
118 | int inputHistory[GUI_INPUT_MAX];
119 | enum GUICursorState cursorState;
120 | int cx, cy;
121 |
122 | // Directories
123 | char currentPath[PATH_MAX];
124 | size_t fileIndex;
125 | };
126 |
127 | void GUIInit(struct GUIParams* params);
128 | void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput);
129 | enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y);
130 | void GUIInvalidateKeys(struct GUIParams* params);
131 |
132 | void GUIKeyboardParamsInit(struct GUIKeyboardParams*);
133 |
134 | CXX_GUARD_END
135 |
136 | #endif
137 |
--------------------------------------------------------------------------------
/include/mgba-util/gui/file-select.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GUI_FILE_CHOOSER_H
7 | #define GUI_FILE_CHOOSER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct VFile;
16 |
17 | bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect);
18 |
19 | CXX_GUARD_END
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/include/mgba-util/gui/font-metrics.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 DEFAULT_FONT_METRICS_H
7 | #define DEFAULT_FONT_METRICS_H
8 |
9 | #include
10 |
11 | extern struct GUIFontGlyphMetric defaultFontMetrics[];
12 | extern struct GUIIconMetric defaultIconMetrics[];
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/include/mgba-util/hash.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 HASH_H
7 | #define HASH_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | uint32_t hash32(const void* key, size_t len, uint32_t seed);
14 |
15 | CXX_GUARD_END
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/include/mgba-util/macros.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2022 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 M_MACROS_H
7 | #define M_MACROS_H
8 |
9 | #define _mCPP_CAT(A, B) A ## B
10 |
11 | #define _mIDENT(...) __VA_ARGS__
12 | #define _mCALL(FN, ...) _mIDENT(FN(__VA_ARGS__))
13 | #define _mCAT(A, B) _mCPP_CAT(A, B)
14 | #define _mSTRINGIFY(X, ...) #X
15 |
16 | #define _mCALL_0(FN, ...)
17 | #define _mCALL_1(FN, A) FN(A)
18 | #define _mCALL_2(FN, A, B) FN(A), FN(B)
19 | #define _mCALL_3(FN, A, ...) FN(A), _mCALL_2(FN, __VA_ARGS__)
20 | #define _mCALL_4(FN, A, ...) FN(A), _mCALL_3(FN, __VA_ARGS__)
21 | #define _mCALL_5(FN, A, ...) FN(A), _mCALL_4(FN, __VA_ARGS__)
22 | #define _mCALL_6(FN, A, ...) FN(A), _mCALL_5(FN, __VA_ARGS__)
23 | #define _mCALL_7(FN, A, ...) FN(A), _mCALL_6(FN, __VA_ARGS__)
24 | #define _mCALL_8(FN, A, ...) FN(A), _mCALL_7(FN, __VA_ARGS__)
25 | #define _mCALL_9(FN, A, ...) FN(A), _mCALL_8(FN, __VA_ARGS__)
26 |
27 | #define _mCOMMA_0(N, ...) N
28 | #define _mCOMMA_1(N, ...) N, __VA_ARGS__
29 | #define _mCOMMA_2(N, ...) N, __VA_ARGS__
30 | #define _mCOMMA_3(N, ...) N, __VA_ARGS__
31 | #define _mCOMMA_4(N, ...) N, __VA_ARGS__
32 | #define _mCOMMA_5(N, ...) N, __VA_ARGS__
33 | #define _mCOMMA_6(N, ...) N, __VA_ARGS__
34 | #define _mCOMMA_7(N, ...) N, __VA_ARGS__
35 | #define _mCOMMA_8(N, ...) N, __VA_ARGS__
36 | #define _mCOMMA_9(N, ...) N, __VA_ARGS__
37 |
38 | #define _mEVEN_0(...)
39 | #define _mEVEN_1(A, B, ...) A
40 | #define _mEVEN_2(A, B, ...) A, _mIDENT(_mEVEN_1(__VA_ARGS__))
41 | #define _mEVEN_3(A, B, ...) A, _mIDENT(_mEVEN_2(__VA_ARGS__))
42 | #define _mEVEN_4(A, B, ...) A, _mIDENT(_mEVEN_3(__VA_ARGS__))
43 | #define _mEVEN_5(A, B, ...) A, _mIDENT(_mEVEN_4(__VA_ARGS__))
44 | #define _mEVEN_6(A, B, ...) A, _mIDENT(_mEVEN_5(__VA_ARGS__))
45 | #define _mEVEN_7(A, B, ...) A, _mIDENT(_mEVEN_6(__VA_ARGS__))
46 | #define _mEVEN_8(A, B, ...) A, _mIDENT(_mEVEN_7(__VA_ARGS__))
47 | #define _mEVEN_9(A, B, ...) A, _mIDENT(_mEVEN_7(__VA_ARGS__))
48 |
49 | #define _mODD_0(...)
50 | #define _mODD_1(A, B, ...) B
51 | #define _mODD_2(A, B, ...) B, _mIDENT(_mODD_1(__VA_ARGS__))
52 | #define _mODD_3(A, B, ...) B, _mIDENT(_mODD_2(__VA_ARGS__))
53 | #define _mODD_4(A, B, ...) B, _mIDENT(_mODD_3(__VA_ARGS__))
54 | #define _mODD_5(A, B, ...) B, _mIDENT(_mODD_4(__VA_ARGS__))
55 | #define _mODD_6(A, B, ...) B, _mIDENT(_mODD_5(__VA_ARGS__))
56 | #define _mODD_7(A, B, ...) B, _mIDENT(_mODD_6(__VA_ARGS__))
57 | #define _mODD_8(A, B, ...) B, _mIDENT(_mODD_7(__VA_ARGS__))
58 | #define _mODD_9(A, B, ...) B, _mIDENT(_mODD_7(__VA_ARGS__))
59 |
60 | #define _mIF0_0(...) __VA_ARGS__
61 | #define _mIF0_1(...)
62 | #define _mIF0_2(...)
63 | #define _mIF0_3(...)
64 | #define _mIF0_4(...)
65 | #define _mIF0_5(...)
66 | #define _mIF0_6(...)
67 | #define _mIF0_7(...)
68 | #define _mIF0_8(...)
69 | #define _mIF0_9(...)
70 |
71 | #define _mSUCC_0 1
72 | #define _mSUCC_1 2
73 | #define _mSUCC_2 3
74 | #define _mSUCC_3 4
75 | #define _mSUCC_4 5
76 | #define _mSUCC_5 6
77 | #define _mSUCC_6 7
78 | #define _mSUCC_7 8
79 | #define _mSUCC_8 9
80 |
81 | #define _mPRED_1 0
82 | #define _mPRED_2 1
83 | #define _mPRED_3 2
84 | #define _mPRED_4 3
85 | #define _mPRED_5 4
86 | #define _mPRED_6 5
87 | #define _mPRED_7 6
88 | #define _mPRED_8 7
89 | #define _mPRED_9 8
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/include/mgba-util/math.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 UTIL_MATH_H
7 | #define UTIL_MATH_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #ifndef HAVE_POPCOUNT32
14 | static inline uint32_t popcount32(unsigned bits) {
15 | bits = bits - ((bits >> 1) & 0x55555555);
16 | bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333);
17 | return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
18 | }
19 | #endif
20 |
21 | static inline unsigned clz32(uint32_t bits) {
22 | #if defined(__GNUC__) || __clang__
23 | if (!bits) {
24 | return 32;
25 | }
26 | return __builtin_clz(bits);
27 | #else
28 | static const int table[256] = {
29 | 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
30 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
31 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
32 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
33 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
34 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
35 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
45 | };
46 |
47 | if (bits & 0xFF000000) {
48 | return table[bits >> 24];
49 | } else if (bits & 0x00FF0000) {
50 | return table[bits >> 16] + 8;
51 | } else if (bits & 0x0000FF00) {
52 | return table[bits >> 8] + 16;
53 | }
54 | return table[bits] + 24;
55 | #endif
56 | }
57 |
58 | static inline uint32_t toPow2(uint32_t bits) {
59 | if (!bits) {
60 | return 0;
61 | }
62 | unsigned lz = clz32(bits - 1);
63 | return 1 << (32 - lz);
64 | }
65 |
66 | static inline int reduceFraction(int* num, int* den) {
67 | int n = *num;
68 | int d = *den;
69 | while (d != 0) {
70 | int temp = n % d;
71 | n = d;
72 | d = temp;
73 | }
74 | *num /= n;
75 | *den /= n;
76 | return n;
77 | }
78 |
79 | #define TYPE_GENERICIZE(MACRO) \
80 | MACRO(int, Int) \
81 | MACRO(unsigned, UInt)
82 |
83 | #define LOCK_ASPECT_RATIO(T, t) \
84 | static inline void lockAspectRatio ## t(T refW, T refH, T* w, T* h) { \
85 | if (*w * refH > *h * refW) { \
86 | *w = *h * refW / refH; \
87 | } else if (*w * refH < *h * refW) { \
88 | *h = *w * refH / refW; \
89 | } \
90 | }
91 |
92 | TYPE_GENERICIZE(LOCK_ASPECT_RATIO)
93 | #undef LOCK_ASPECT_RATIO
94 |
95 | #define LOCK_INTEGER_RATIO(T, t) \
96 | static inline void lockIntegerRatio ## t(T ref, T* val) { \
97 | if (*val >= ref) { \
98 | *val -= *val % ref; \
99 | } \
100 | }
101 |
102 | TYPE_GENERICIZE(LOCK_INTEGER_RATIO)
103 | #undef LOCK_INTEGER_RATIO
104 |
105 | #undef TYPE_GENERICIZE
106 | CXX_GUARD_END
107 |
108 | #endif
109 |
--------------------------------------------------------------------------------
/include/mgba-util/memory.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 MEMORY_H
7 | #define MEMORY_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | void* anonymousMemoryMap(size_t size);
14 | void mappedMemoryFree(void* memory, size_t size);
15 |
16 | CXX_GUARD_END
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/mgba-util/patch.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 PATCH_H
7 | #define PATCH_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct VFile;
14 |
15 | struct Patch {
16 | struct VFile* vf;
17 |
18 | size_t (*outputSize)(struct Patch* patch, size_t inSize);
19 | bool (*applyPatch)(struct Patch* patch, const void* in, size_t inSize, void* out, size_t outSize);
20 | };
21 |
22 | bool loadPatch(struct VFile* vf, struct Patch* patch);
23 |
24 | CXX_GUARD_END
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/include/mgba-util/patch/fast.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 PATCH_FAST_H
7 | #define PATCH_FAST_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | #define PATCH_FAST_EXTENT 128
17 |
18 | struct PatchFastExtent {
19 | size_t length;
20 | size_t offset;
21 | uint32_t extent[PATCH_FAST_EXTENT];
22 | };
23 |
24 | DECLARE_VECTOR(PatchFastExtents, struct PatchFastExtent);
25 |
26 | struct PatchFast {
27 | struct Patch d;
28 |
29 | struct PatchFastExtents extents;
30 | };
31 |
32 | void initPatchFast(struct PatchFast*);
33 | void deinitPatchFast(struct PatchFast*);
34 | bool diffPatchFast(struct PatchFast* patch, const void* restrict in, const void* restrict out, size_t size);
35 |
36 | CXX_GUARD_END
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/include/mgba-util/patch/ips.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 PATCH_IPS_H
7 | #define PATCH_IPS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct Patch;
14 |
15 | bool loadPatchIPS(struct Patch* patch);
16 |
17 | CXX_GUARD_END
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/mgba-util/patch/ups.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 PATCH_UPS_H
7 | #define PATCH_UPS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct Patch;
14 |
15 | bool loadPatchUPS(struct Patch* patch);
16 |
17 | CXX_GUARD_END
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/mgba-util/platform/3ds/3ds-vfs.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 N3DS_VFS_H
7 | #define N3DS_VFS_H
8 |
9 | #include
10 |
11 | #include <3ds.h>
12 |
13 | extern FS_Archive sdmcArchive;
14 |
15 | struct VFile* VFileOpen3DS(FS_Archive* archive, const char* path, int flags);
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/include/mgba-util/platform/3ds/threading.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 N3DS_THREADING_H
7 | #define N3DS_THREADING_H
8 |
9 | #include
10 |
11 | #include <3ds.h>
12 | #include
13 |
14 | #define THREAD_ENTRY void
15 | typedef ThreadFunc ThreadEntry;
16 |
17 | typedef LightLock Mutex;
18 | typedef CondVar Condition;
19 |
20 | static inline int MutexInit(Mutex* mutex) {
21 | LightLock_Init(mutex);
22 | return 0;
23 | }
24 |
25 | static inline int MutexDeinit(Mutex* mutex) {
26 | UNUSED(mutex);
27 | return 0;
28 | }
29 |
30 | static inline int MutexLock(Mutex* mutex) {
31 | LightLock_Lock(mutex);
32 | return 0;
33 | }
34 |
35 | static inline int MutexTryLock(Mutex* mutex) {
36 | return LightLock_TryLock(mutex);
37 | }
38 |
39 | static inline int MutexUnlock(Mutex* mutex) {
40 | LightLock_Unlock(mutex);
41 | return 0;
42 | }
43 |
44 | static inline int ConditionInit(Condition* cond) {
45 | CondVar_Init(cond);
46 | return 0;
47 | }
48 |
49 | static inline int ConditionDeinit(Condition* cond) {
50 | UNUSED(cond);
51 | return 0;
52 | }
53 |
54 | static inline int ConditionWait(Condition* cond, Mutex* mutex) {
55 | CondVar_Wait(cond, mutex);
56 | return 0;
57 | }
58 |
59 | static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
60 | return CondVar_WaitTimeout(cond, mutex, timeoutMs * 10000000LL);
61 | }
62 |
63 | static inline int ConditionWake(Condition* cond) {
64 | CondVar_Signal(cond);
65 | return 0;
66 | }
67 |
68 | static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context) {
69 | if (!entry || !thread) {
70 | return 1;
71 | }
72 | *thread = threadCreate(entry, context, 0x8000, 0x18, 2, false);
73 | return !*thread;
74 | }
75 |
76 | static inline int ThreadJoin(Thread* thread) {
77 | Result res = threadJoin(*thread, U64_MAX);
78 | threadFree(*thread);
79 | return res;
80 | }
81 |
82 | static inline void ThreadSetName(const char* name) {
83 | UNUSED(name);
84 | // Unimplemented
85 | }
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/include/mgba-util/platform/psp2/sce-vfs.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 SCE_VFS_H
7 | #define SCE_VFS_H
8 |
9 | #ifdef PSP2
10 | #include
11 | #include
12 | #else
13 | #include
14 | #endif
15 |
16 | struct VFile* VFileOpenSce(const char* path, int flags, SceMode mode);
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/mgba-util/platform/switch/threading.h:
--------------------------------------------------------------------------------
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
10 |
11 | #include
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, NULL, 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
88 |
--------------------------------------------------------------------------------
/include/mgba-util/platform/windows/threading.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 WINDOWS_THREADING_H
7 | #define WINDOWS_THREADING_H
8 |
9 | #include
10 |
11 | #define _WIN32_WINNT 0x0600
12 | #include
13 | #define THREAD_ENTRY DWORD WINAPI
14 | typedef THREAD_ENTRY ThreadEntry(LPVOID);
15 |
16 | typedef HANDLE Thread;
17 | typedef CRITICAL_SECTION Mutex;
18 | typedef CONDITION_VARIABLE Condition;
19 |
20 | static inline int MutexInit(Mutex* mutex) {
21 | InitializeCriticalSection(mutex);
22 | return GetLastError();
23 | }
24 |
25 | static inline int MutexDeinit(Mutex* mutex) {
26 | DeleteCriticalSection(mutex);
27 | return GetLastError();
28 | }
29 |
30 | static inline int MutexLock(Mutex* mutex) {
31 | EnterCriticalSection(mutex);
32 | return GetLastError();
33 | }
34 |
35 | static inline int MutexTryLock(Mutex* mutex) {
36 | if (TryEnterCriticalSection(mutex)) {
37 | return 0;
38 | }
39 | return 1;
40 | }
41 |
42 | static inline int MutexUnlock(Mutex* mutex) {
43 | LeaveCriticalSection(mutex);
44 | return GetLastError();
45 | }
46 |
47 | static inline int ConditionInit(Condition* cond) {
48 | InitializeConditionVariable(cond);
49 | return GetLastError();
50 | }
51 |
52 | static inline int ConditionDeinit(Condition* cond) {
53 | // This is a no-op on Windows
54 | UNUSED(cond);
55 | return 0;
56 | }
57 |
58 | static inline int ConditionWait(Condition* cond, Mutex* mutex) {
59 | SleepConditionVariableCS(cond, mutex, INFINITE);
60 | return GetLastError();
61 | }
62 |
63 | static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
64 | SleepConditionVariableCS(cond, mutex, timeoutMs);
65 | return GetLastError();
66 | }
67 |
68 | static inline int ConditionWake(Condition* cond) {
69 | WakeAllConditionVariable(cond);
70 | return GetLastError();
71 | }
72 |
73 | static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context) {
74 | *thread = CreateThread(NULL, 0, entry, context, 0, 0);
75 | return GetLastError();
76 | }
77 |
78 | static inline int ThreadJoin(Thread* thread) {
79 | DWORD error = WaitForSingleObject(*thread, INFINITE);
80 | if (error == WAIT_FAILED) {
81 | return GetLastError();
82 | }
83 | return 0;
84 | }
85 |
86 | static inline int ThreadSetName(const char* name) {
87 | UNUSED(name);
88 | return -1;
89 | }
90 |
91 | #if (__STDC_VERSION__ < 201112L) || (__STDC_NO_THREADS__ == 1)
92 | typedef DWORD ThreadLocal;
93 |
94 | static inline void ThreadLocalInitKey(ThreadLocal* key) {
95 | *key = TlsAlloc();
96 | }
97 |
98 | static inline void ThreadLocalSetKey(ThreadLocal key, void* value) {
99 | TlsSetValue(key, value);
100 | }
101 |
102 | static inline void* ThreadLocalGetValue(ThreadLocal key) {
103 | return TlsGetValue(key);
104 | }
105 | #endif
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/include/mgba-util/png-io.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 PNG_IO_H
7 | #define PNG_IO_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #ifdef USE_PNG
14 |
15 | // png.h defines its own version of restrict which conflicts with mGBA's.
16 | #ifdef restrict
17 | #undef restrict
18 | #endif
19 | #include
20 |
21 | struct VFile;
22 |
23 | enum {
24 | PNG_HEADER_BYTES = 8
25 | };
26 |
27 | png_structp PNGWriteOpen(struct VFile* source);
28 | png_infop PNGWriteHeader(png_structp png, unsigned width, unsigned height);
29 | png_infop PNGWriteHeaderA(png_structp png, unsigned width, unsigned height);
30 | png_infop PNGWriteHeader8(png_structp png, unsigned width, unsigned height);
31 | bool PNGWritePalette(png_structp png, png_infop info, const uint32_t* palette, unsigned entries);
32 | 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);
34 | bool PNGWritePixels8(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels);
35 | bool PNGWriteCustomChunk(png_structp png, const char* name, size_t size, void* data);
36 | void PNGWriteClose(png_structp png, png_infop info);
37 |
38 | typedef int (*ChunkHandler)(png_structp, png_unknown_chunkp);
39 |
40 | bool isPNG(struct VFile* source);
41 | png_structp PNGReadOpen(struct VFile* source, unsigned offset);
42 | bool PNGInstallChunkHandler(png_structp png, void* context, ChunkHandler handler, const char* chunkName);
43 | bool PNGReadHeader(png_structp png, png_infop info);
44 | 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);
47 | bool PNGIgnorePixels(png_structp png, png_infop info);
48 | bool PNGReadFooter(png_structp png, png_infop end);
49 | void PNGReadClose(png_structp png, png_infop info, png_infop end);
50 |
51 | #endif
52 |
53 | CXX_GUARD_END
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/mgba-util/ring-fifo.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 RING_FIFO_H
7 | #define RING_FIFO_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct RingFIFO {
14 | void* data;
15 | size_t capacity;
16 | void* readPtr;
17 | void* writePtr;
18 | };
19 |
20 | void RingFIFOInit(struct RingFIFO* buffer, size_t capacity);
21 | void RingFIFODeinit(struct RingFIFO* buffer);
22 | size_t RingFIFOCapacity(const struct RingFIFO* buffer);
23 | size_t RingFIFOSize(const struct RingFIFO* buffer);
24 | void RingFIFOClear(struct RingFIFO* buffer);
25 | size_t RingFIFOWrite(struct RingFIFO* buffer, const void* value, size_t length);
26 | size_t RingFIFORead(struct RingFIFO* buffer, void* output, size_t length);
27 |
28 | CXX_GUARD_END
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/include/mgba-util/string.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 UTIL_STRING_H
7 | #define UTIL_STRING_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #ifndef HAVE_STRNDUP
14 | // This is sometimes a macro
15 | char* strndup(const char* start, size_t len);
16 | #endif
17 |
18 | #ifndef HAVE_STRDUP
19 | char* strdup(const char* str);
20 | #endif
21 |
22 | #ifndef HAVE_STRLCPY
23 | size_t strlcpy(char* restrict dst, const char* restrict src, size_t dstsize);
24 | #endif
25 |
26 | char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);
27 | bool endswith(const char* restrict s1, const char* restrict end);
28 | bool startswith(const char* restrict s1, const char* restrict start);
29 |
30 | size_t toUtf8(uint32_t unichar, char* buffer);
31 | size_t toUtf16(uint32_t unichar, uint16_t* buffer);
32 | int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
33 | char* utf16to8(const uint16_t* utf16, size_t length);
34 | uint32_t utf8Char(const char** unicode, size_t* length);
35 | uint32_t utf16Char(const uint16_t** unicode, size_t* length);
36 | char* latin1ToUtf8(const char* latin1, size_t length);
37 | char* gbkToUtf8(const char* gbk, size_t length);
38 | size_t utf8strlen(const char* string);
39 |
40 | int hexDigit(char digit);
41 | const char* hex32(const char* line, uint32_t* out);
42 | const char* hex24(const char* line, uint32_t* out);
43 | const char* hex16(const char* line, uint16_t* out);
44 | const char* hex12(const char* line, uint16_t* out);
45 | const char* hex8(const char* line, uint8_t* out);
46 | const char* hex4(const char* line, uint8_t* out);
47 |
48 | void rtrim(char* string);
49 |
50 | ssize_t parseQuotedString(const char* unparsed, ssize_t unparsedLen, char* parsed, ssize_t parsedLen);
51 | bool wildcard(const char* search, const char* string);
52 |
53 | CXX_GUARD_END
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/mgba-util/text-codec.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 TEXT_CODEC_H
7 | #define TEXT_CODEC_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct TextCodecNode;
14 | struct TextCodec {
15 | struct TextCodecNode* forwardRoot;
16 | struct TextCodecNode* reverseRoot;
17 | };
18 |
19 | struct TextCodecIterator {
20 | struct TextCodecNode* root;
21 | struct TextCodecNode* current;
22 | };
23 |
24 | struct VFile;
25 | bool TextCodecLoadTBL(struct TextCodec*, struct VFile*, bool createReverse);
26 | void TextCodecDeinit(struct TextCodec*);
27 |
28 | void TextCodecStartDecode(struct TextCodec*, struct TextCodecIterator*);
29 | void TextCodecStartEncode(struct TextCodec*, struct TextCodecIterator*);
30 |
31 | ssize_t TextCodecAdvance(struct TextCodecIterator*, uint8_t byte, uint8_t* output, size_t outputLength);
32 | ssize_t TextCodecFinish(struct TextCodecIterator*, uint8_t* output, size_t outputLength);
33 |
34 | CXX_GUARD_END
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/mgba-util/threading.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 THREADING_H
7 | #define THREADING_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #ifndef DISABLE_THREADING
14 | #ifdef USE_PTHREADS
15 | #include
16 | #elif defined(_WIN32)
17 | #include
18 | #elif defined(PSP2)
19 | #include
20 | #elif defined(__3DS__)
21 | #include
22 | #elif defined(__SWITCH__)
23 | #include
24 | #else
25 | #define DISABLE_THREADING
26 | #endif
27 | #endif
28 |
29 | #ifndef DISABLE_THREADING
30 | #if (__STDC_VERSION__ >= 201112L) && (__STDC_NO_THREADS__ != 1)
31 | #define ThreadLocal _Thread_local void*
32 | #define ThreadLocalInitKey(X)
33 | #define ThreadLocalSetKey(K, V) K = V
34 | #define ThreadLocalGetValue(K) K
35 | #endif
36 | #else
37 | #ifdef __3DS__
38 | // ctrulib already has a type called Thread
39 | #include <3ds/thread.h>
40 | #elif defined(__SWITCH__)
41 | #include
42 | #else
43 | typedef void* Thread;
44 | #endif
45 | #ifdef __SWITCH__
46 | #include
47 | #else
48 | typedef void* Mutex;
49 | #endif
50 | typedef void* Condition;
51 | typedef int ThreadLocal;
52 |
53 | static inline int MutexInit(Mutex* mutex) {
54 | UNUSED(mutex);
55 | return 0;
56 | }
57 |
58 | static inline int MutexDeinit(Mutex* mutex) {
59 | UNUSED(mutex);
60 | return 0;
61 | }
62 |
63 | static inline int MutexLock(Mutex* mutex) {
64 | UNUSED(mutex);
65 | return 0;
66 | }
67 |
68 | static inline int MutexTryLock(Mutex* mutex) {
69 | UNUSED(mutex);
70 | return 0;
71 | }
72 |
73 | static inline int MutexUnlock(Mutex* mutex) {
74 | UNUSED(mutex);
75 | return 0;
76 | }
77 |
78 | static inline int ConditionInit(Condition* cond) {
79 | UNUSED(cond);
80 | return 0;
81 | }
82 |
83 | static inline int ConditionDeinit(Condition* cond) {
84 | UNUSED(cond);
85 | return 0;
86 | }
87 |
88 | static inline int ConditionWait(Condition* cond, Mutex* mutex) {
89 | UNUSED(cond);
90 | UNUSED(mutex);
91 | return 0;
92 | }
93 |
94 | static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
95 | UNUSED(cond);
96 | UNUSED(mutex);
97 | UNUSED(timeoutMs);
98 | return 0;
99 | }
100 |
101 | static inline int ConditionWake(Condition* cond) {
102 | UNUSED(cond);
103 | return 0;
104 | }
105 |
106 | static inline void ThreadLocalInitKey(ThreadLocal* key) {
107 | UNUSED(key);
108 | }
109 |
110 | static inline void ThreadLocalSetKey(ThreadLocal key, void* value) {
111 | UNUSED(key);
112 | UNUSED(value);
113 | }
114 |
115 | static inline void* ThreadLocalGetValue(ThreadLocal key) {
116 | UNUSED(key);
117 | return NULL;
118 | }
119 | #endif
120 |
121 | CXX_GUARD_END
122 |
123 | #endif
124 |
--------------------------------------------------------------------------------
/include/mgba/core/bitmap-cache.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 M_BITMAP_CACHE_H
7 | #define M_BITMAP_CACHE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | DECL_BITFIELD(mBitmapCacheConfiguration, uint32_t);
16 | DECL_BIT(mBitmapCacheConfiguration, ShouldStore, 0);
17 |
18 | DECL_BITFIELD(mBitmapCacheSystemInfo, uint32_t);
19 | DECL_BITS(mBitmapCacheSystemInfo, EntryBPP, 0, 3);
20 | DECL_BIT(mBitmapCacheSystemInfo, UsesPalette, 3);
21 | DECL_BITS(mBitmapCacheSystemInfo, Width, 4, 10);
22 | DECL_BITS(mBitmapCacheSystemInfo, Height, 14, 10);
23 | DECL_BITS(mBitmapCacheSystemInfo, Buffers, 24, 2);
24 |
25 | struct mBitmapCacheEntry {
26 | uint32_t paletteVersion;
27 | uint32_t vramVersion;
28 | uint8_t vramClean;
29 | };
30 |
31 | struct mBitmapCache {
32 | color_t* cache;
33 | struct mBitmapCacheEntry* status;
34 |
35 | uint32_t globalPaletteVersion;
36 |
37 | uint8_t* vram;
38 | color_t* palette;
39 |
40 | uint32_t bitsSize;
41 | uint32_t bitsStart[2];
42 | uint32_t stride;
43 | uint8_t buffer;
44 |
45 | mBitmapCacheConfiguration config;
46 | mBitmapCacheSystemInfo sysConfig;
47 |
48 | void* context;
49 | };
50 |
51 | void mBitmapCacheInit(struct mBitmapCache* cache);
52 | void mBitmapCacheDeinit(struct mBitmapCache* cache);
53 | void mBitmapCacheConfigure(struct mBitmapCache* cache, mBitmapCacheConfiguration config);
54 | void mBitmapCacheConfigureSystem(struct mBitmapCache* cache, mBitmapCacheSystemInfo config);
55 | void mBitmapCacheWriteVRAM(struct mBitmapCache* cache, uint32_t address);
56 | void mBitmapCacheWritePalette(struct mBitmapCache* cache, uint32_t entry, color_t color);
57 |
58 | void mBitmapCacheCleanRow(struct mBitmapCache* cache, struct mBitmapCacheEntry* entry, unsigned y);
59 | bool mBitmapCacheCheckRow(struct mBitmapCache* cache, const struct mBitmapCacheEntry* entry, unsigned y);
60 | const color_t* mBitmapCacheGetRow(struct mBitmapCache* cache, unsigned y);
61 |
62 | CXX_GUARD_END
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/include/mgba/core/blip_buf.h:
--------------------------------------------------------------------------------
1 | /** \file
2 | Sample buffer that resamples from input clock rate to output sample rate */
3 |
4 | /* blip_buf 1.1.0 */
5 | #ifndef BLIP_BUF_H
6 | #define BLIP_BUF_H
7 |
8 | #ifdef __cplusplus
9 | extern "C" {
10 | #endif
11 |
12 | /** First parameter of most functions is blip_t*, or const blip_t* if nothing
13 | is changed. */
14 | typedef struct blip_t blip_t;
15 |
16 | /** Creates new buffer that can hold at most sample_count samples. Sets rates
17 | so that there are blip_max_ratio clocks per sample. Returns pointer to new
18 | buffer, or NULL if insufficient memory. */
19 | blip_t* blip_new( int sample_count );
20 |
21 | /** Sets approximate input clock rate and output sample rate. For every
22 | clock_rate input clocks, approximately sample_rate samples are generated. */
23 | void blip_set_rates( blip_t*, double clock_rate, double sample_rate );
24 |
25 | enum { /** Maximum clock_rate/sample_rate ratio. For a given sample_rate,
26 | clock_rate must not be greater than sample_rate*blip_max_ratio. */
27 | blip_max_ratio = 0x100000 };
28 |
29 | /** Clears entire buffer. Afterwards, blip_samples_avail() == 0. */
30 | void blip_clear( blip_t* );
31 |
32 | /** Adds positive/negative delta into buffer at specified clock time. */
33 | void blip_add_delta( blip_t*, unsigned int clock_time, int delta );
34 |
35 | /** Same as blip_add_delta(), but uses faster, lower-quality synthesis. */
36 | void blip_add_delta_fast( blip_t*, unsigned int clock_time, int delta );
37 |
38 | /** Length of time frame, in clocks, needed to make sample_count additional
39 | samples available. */
40 | int blip_clocks_needed( const blip_t*, int sample_count );
41 |
42 | enum { /** Maximum number of samples that can be generated from one time frame. */
43 | blip_max_frame = 4000 };
44 |
45 | /** Makes input clocks before clock_duration available for reading as output
46 | samples. Also begins new time frame at clock_duration, so that clock time 0 in
47 | the new time frame specifies the same clock as clock_duration in the old time
48 | frame specified. Deltas can have been added slightly past clock_duration (up to
49 | however many clocks there are in two output samples). */
50 | void blip_end_frame( blip_t*, unsigned int clock_duration );
51 |
52 | /** Number of buffered samples available for reading. */
53 | int blip_samples_avail( const blip_t* );
54 |
55 | /** Reads and removes at most 'count' samples and writes them to 'out'. If
56 | 'stereo' is true, writes output to every other element of 'out', allowing easy
57 | interleaving of two buffers into a stereo sample stream. Outputs 16-bit signed
58 | samples. Returns number of samples actually read. */
59 | int blip_read_samples( blip_t*, short out [], int count, int stereo );
60 |
61 | /** Frees buffer. No effect if NULL is passed. */
62 | void blip_delete( blip_t* );
63 |
64 |
65 | /* Deprecated */
66 | typedef blip_t blip_buffer_t;
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/include/mgba/core/cache-set.h:
--------------------------------------------------------------------------------
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 M_CACHE_SET_H
7 | #define M_CACHE_SET_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | DECLARE_VECTOR(mMapCacheSet, struct mMapCache);
19 | DECLARE_VECTOR(mBitmapCacheSet, struct mBitmapCache);
20 | DECLARE_VECTOR(mTileCacheSet, struct mTileCache);
21 |
22 | struct mCacheSet {
23 | struct mMapCacheSet maps;
24 | struct mBitmapCacheSet bitmaps;
25 | struct mTileCacheSet tiles;
26 | };
27 |
28 | void mCacheSetInit(struct mCacheSet*, size_t nMaps, size_t nBitmaps, size_t nTiles);
29 | void mCacheSetDeinit(struct mCacheSet*);
30 |
31 | void mCacheSetAssignVRAM(struct mCacheSet*, void* vram);
32 |
33 | void mCacheSetWriteVRAM(struct mCacheSet*, uint32_t address);
34 | void mCacheSetWritePalette(struct mCacheSet*, uint32_t entry, color_t color);
35 |
36 | CXX_GUARD_END
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/include/mgba/core/cpu.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_CPU_H
7 | #define M_CPU_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | enum mCPUComponentType {
14 | CPU_COMPONENT_DEBUGGER,
15 | CPU_COMPONENT_CHEAT_DEVICE,
16 | CPU_COMPONENT_MISC_1,
17 | CPU_COMPONENT_MISC_2,
18 | CPU_COMPONENT_MISC_3,
19 | CPU_COMPONENT_MISC_4,
20 | CPU_COMPONENT_MAX
21 | };
22 |
23 | struct mCPUComponent {
24 | uint32_t id;
25 | void (*init)(void* cpu, struct mCPUComponent* component);
26 | void (*deinit)(struct mCPUComponent* component);
27 | };
28 |
29 | CXX_GUARD_END
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/include/mgba/core/directories.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 DIRECTORIES_H
7 | #define DIRECTORIES_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
14 | struct VDir;
15 |
16 | struct mDirectorySet {
17 | char baseName[PATH_MAX];
18 | struct VDir* base;
19 | struct VDir* archive;
20 | struct VDir* save;
21 | struct VDir* patch;
22 | struct VDir* state;
23 | struct VDir* screenshot;
24 | struct VDir* cheats;
25 | };
26 |
27 | void mDirectorySetInit(struct mDirectorySet* dirs);
28 | void mDirectorySetDeinit(struct mDirectorySet* dirs);
29 |
30 | void mDirectorySetAttachBase(struct mDirectorySet* dirs, struct VDir* base);
31 | void mDirectorySetDetachBase(struct mDirectorySet* dirs);
32 |
33 | struct VFile* mDirectorySetOpenPath(struct mDirectorySet* dirs, const char* path, bool (*filter)(struct VFile*));
34 | struct VFile* mDirectorySetOpenSuffix(struct mDirectorySet* dirs, struct VDir* dir, const char* suffix, int mode);
35 |
36 | struct mCoreOptions;
37 | void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptions* opts);
38 | #endif
39 |
40 | CXX_GUARD_END
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/include/mgba/core/library.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_LIBRARY_H
7 | #define M_LIBRARY_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | struct mLibraryEntry {
17 | const char* base;
18 | const char* filename;
19 | const char* title;
20 | char internalTitle[17];
21 | char internalCode[9];
22 | enum mPlatform platform;
23 | size_t filesize;
24 | uint32_t crc32;
25 | };
26 |
27 | #ifdef USE_SQLITE3
28 |
29 | DECLARE_VECTOR(mLibraryListing, struct mLibraryEntry);
30 |
31 | struct mLibrary;
32 | struct mLibrary* mLibraryCreateEmpty(void);
33 | struct mLibrary* mLibraryLoad(const char* filename);
34 | void mLibraryDestroy(struct mLibrary*);
35 |
36 | struct VDir;
37 | struct VFile;
38 | void mLibraryLoadDirectory(struct mLibrary* library, const char* base, bool recursive);
39 | void mLibraryClear(struct mLibrary* library);
40 |
41 | size_t mLibraryCount(struct mLibrary* library, const struct mLibraryEntry* constraints);
42 | size_t mLibraryGetEntries(struct mLibrary* library, struct mLibraryListing* out, size_t numEntries, size_t offset, const struct mLibraryEntry* constraints);
43 | void mLibraryEntryFree(struct mLibraryEntry* entry);
44 | struct VFile* mLibraryOpenVFile(struct mLibrary* library, const struct mLibraryEntry* entry);
45 |
46 | struct NoIntroDB;
47 | void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db);
48 |
49 | #endif
50 |
51 | CXX_GUARD_END
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/mgba/core/lockstep.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 SIO_LOCKSTEP_H
7 | #define SIO_LOCKSTEP_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | enum mLockstepPhase {
14 | TRANSFER_IDLE = 0,
15 | TRANSFER_STARTING,
16 | TRANSFER_STARTED,
17 | TRANSFER_FINISHING,
18 | TRANSFER_FINISHED
19 | };
20 |
21 | struct mLockstep {
22 | int attached;
23 | enum mLockstepPhase transferActive;
24 | int32_t transferCycles;
25 |
26 | void (*lock)(struct mLockstep*);
27 | void (*unlock)(struct mLockstep*);
28 |
29 | bool (*signal)(struct mLockstep*, unsigned mask);
30 | bool (*wait)(struct mLockstep*, unsigned mask);
31 | void (*addCycles)(struct mLockstep*, int id, int32_t cycles);
32 | int32_t (*useCycles)(struct mLockstep*, int id, int32_t cycles);
33 | int32_t (*unusedCycles)(struct mLockstep*, int id);
34 | void (*unload)(struct mLockstep*, int id);
35 | void* context;
36 | #ifndef NDEBUG
37 | int transferId;
38 | #endif
39 | };
40 |
41 | void mLockstepInit(struct mLockstep*);
42 | void mLockstepDeinit(struct mLockstep*);
43 |
44 | static inline void mLockstepLock(struct mLockstep* lockstep) {
45 | if (lockstep->lock) {
46 | lockstep->lock(lockstep);
47 | }
48 | }
49 |
50 | static inline void mLockstepUnlock(struct mLockstep* lockstep) {
51 | if (lockstep->unlock) {
52 | lockstep->unlock(lockstep);
53 | }
54 | }
55 |
56 | CXX_GUARD_END
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/include/mgba/core/log.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_LOG_H
7 | #define M_LOG_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum mLogLevel {
16 | mLOG_FATAL = 0x01,
17 | mLOG_ERROR = 0x02,
18 | mLOG_WARN = 0x04,
19 | mLOG_INFO = 0x08,
20 | mLOG_DEBUG = 0x10,
21 | mLOG_STUB = 0x20,
22 | mLOG_GAME_ERROR = 0x40,
23 |
24 | mLOG_ALL = 0x7F
25 | };
26 |
27 | struct Table;
28 | struct mLogFilter {
29 | int defaultLevels;
30 | struct Table categories;
31 | struct Table levels;
32 | };
33 |
34 | struct mLogger {
35 | void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args);
36 | struct mLogFilter* filter;
37 | };
38 |
39 | struct mStandardLogger {
40 | struct mLogger d;
41 | bool logToStdout;
42 | struct VFile* logFile;
43 | };
44 |
45 | struct mLogger* mLogGetContext(void);
46 | void mLogSetDefaultLogger(struct mLogger*);
47 | int mLogGenerateCategory(const char*, const char*);
48 | const char* mLogCategoryName(int);
49 | const char* mLogCategoryId(int);
50 | int mLogCategoryById(const char*);
51 |
52 | struct mCoreConfig;
53 | void mStandardLoggerInit(struct mStandardLogger*);
54 | void mStandardLoggerDeinit(struct mStandardLogger*);
55 | void mStandardLoggerConfig(struct mStandardLogger*, struct mCoreConfig* config);
56 |
57 | void mLogFilterInit(struct mLogFilter*);
58 | void mLogFilterDeinit(struct mLogFilter*);
59 | void mLogFilterLoad(struct mLogFilter*, const struct mCoreConfig*);
60 | void mLogFilterSave(const struct mLogFilter*, struct mCoreConfig*);
61 | void mLogFilterSet(struct mLogFilter*, const char* category, int levels);
62 | void mLogFilterReset(struct mLogFilter*, const char* category);
63 | bool mLogFilterTest(const struct mLogFilter*, int category, enum mLogLevel level);
64 | int mLogFilterLevels(const struct mLogFilter*, int category);
65 |
66 | ATTRIBUTE_FORMAT(printf, 3, 4)
67 | void mLog(int category, enum mLogLevel level, const char* format, ...);
68 |
69 | ATTRIBUTE_FORMAT(printf, 4, 5)
70 | void mLogExplicit(struct mLogger*, int category, enum mLogLevel level, const char* format, ...);
71 |
72 | #define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY, mLOG_ ## LEVEL, __VA_ARGS__)
73 |
74 | #define mLOG_DECLARE_CATEGORY(CATEGORY) extern int _mLOG_CAT_ ## CATEGORY;
75 | #define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \
76 | int _mLOG_CAT_ ## CATEGORY; \
77 | CONSTRUCTOR(_mLOG_CAT_ ## CATEGORY ## _INIT) { \
78 | _mLOG_CAT_ ## CATEGORY = mLogGenerateCategory(NAME, ID); \
79 | }
80 |
81 | MGBA_EXPORT mLOG_DECLARE_CATEGORY(STATUS)
82 |
83 | CXX_GUARD_END
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/include/mgba/core/map-cache.h:
--------------------------------------------------------------------------------
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 M_MAP_CACHE_H
7 | #define M_MAP_CACHE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | DECL_BITFIELD(mMapCacheConfiguration, uint32_t);
17 | DECL_BIT(mMapCacheConfiguration, ShouldStore, 0);
18 |
19 | DECL_BITFIELD(mMapCacheSystemInfo, uint32_t);
20 | DECL_BITS(mMapCacheSystemInfo, PaletteBPP, 0, 2);
21 | DECL_BITS(mMapCacheSystemInfo, PaletteCount, 2, 4);
22 | DECL_BITS(mMapCacheSystemInfo, TilesWide, 8, 4);
23 | DECL_BITS(mMapCacheSystemInfo, TilesHigh, 12, 4);
24 | DECL_BITS(mMapCacheSystemInfo, MacroTileSize, 16, 7);
25 | DECL_BITS(mMapCacheSystemInfo, MapAlign, 23, 2);
26 | DECL_BITS(mMapCacheSystemInfo, WriteAlign, 25, 2);
27 |
28 | DECL_BITFIELD(mMapCacheEntryFlags, uint16_t);
29 | DECL_BITS(mMapCacheEntryFlags, PaletteId, 0, 4);
30 | DECL_BIT(mMapCacheEntryFlags, VramClean, 4);
31 | DECL_BIT(mMapCacheEntryFlags, HMirror, 5);
32 | DECL_BIT(mMapCacheEntryFlags, VMirror, 6);
33 | DECL_BITS(mMapCacheEntryFlags, Mirror, 5, 2);
34 |
35 | #define mMapCacheTileCount(C) (1 << mMapCacheSystemInfoGetTilesWide((C)->sysConfig)) * (1 << mMapCacheSystemInfoGetTilesHigh((C)->sysConfig))
36 |
37 | struct mMapCacheEntry {
38 | uint32_t vramVersion;
39 | uint16_t tileId;
40 | mMapCacheEntryFlags flags;
41 | struct mTileCacheEntry tileStatus[16];
42 | };
43 |
44 | struct mTileCache;
45 | struct mTileCacheEntry;
46 | struct mMapCache {
47 | color_t* cache;
48 | struct mTileCache* tileCache;
49 | struct mMapCacheEntry* status;
50 |
51 | uint8_t* vram;
52 |
53 | uint32_t mapStart;
54 | uint32_t mapSize;
55 |
56 | uint32_t tileStart;
57 |
58 | mMapCacheConfiguration config;
59 | mMapCacheSystemInfo sysConfig;
60 |
61 | void (*mapParser)(struct mMapCache*, struct mMapCacheEntry* entry, void* vram);
62 | void* context;
63 | };
64 |
65 | void mMapCacheInit(struct mMapCache* cache);
66 | void mMapCacheDeinit(struct mMapCache* cache);
67 | void mMapCacheConfigure(struct mMapCache* cache, mMapCacheConfiguration config);
68 | void mMapCacheConfigureSystem(struct mMapCache* cache, mMapCacheSystemInfo config);
69 | void mMapCacheConfigureMap(struct mMapCache* cache, uint32_t mapStart);
70 | void mMapCacheWriteVRAM(struct mMapCache* cache, uint32_t address);
71 |
72 | uint32_t mMapCacheTileId(struct mMapCache* cache, unsigned x, unsigned y);
73 |
74 | bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* entry, unsigned x, unsigned y);
75 | void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y);
76 |
77 | void mMapCacheCleanRow(struct mMapCache* cache, unsigned y);
78 | const color_t* mMapCacheGetRow(struct mMapCache* cache, unsigned y);
79 |
80 | CXX_GUARD_END
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/include/mgba/core/mem-search.h:
--------------------------------------------------------------------------------
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 CORE_MEM_SEARCH_H
7 | #define CORE_MEM_SEARCH_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum mCoreMemorySearchType {
16 | mCORE_MEMORY_SEARCH_INT,
17 | mCORE_MEMORY_SEARCH_STRING,
18 | mCORE_MEMORY_SEARCH_GUESS,
19 | };
20 |
21 | enum mCoreMemorySearchOp {
22 | mCORE_MEMORY_SEARCH_EQUAL,
23 | mCORE_MEMORY_SEARCH_GREATER,
24 | mCORE_MEMORY_SEARCH_LESS,
25 | mCORE_MEMORY_SEARCH_ANY,
26 | mCORE_MEMORY_SEARCH_DELTA,
27 | mCORE_MEMORY_SEARCH_DELTA_POSITIVE,
28 | mCORE_MEMORY_SEARCH_DELTA_NEGATIVE,
29 | mCORE_MEMORY_SEARCH_DELTA_ANY,
30 | };
31 |
32 | struct mCoreMemorySearchParams {
33 | int memoryFlags;
34 | enum mCoreMemorySearchType type;
35 | enum mCoreMemorySearchOp op;
36 | int align;
37 | int width;
38 | union {
39 | const char* valueStr;
40 | int32_t valueInt;
41 | };
42 | };
43 |
44 | struct mCoreMemorySearchResult {
45 | uint32_t address;
46 | int segment;
47 | uint32_t guessDivisor;
48 | uint32_t guessMultiplier;
49 | enum mCoreMemorySearchType type;
50 | int width;
51 | int32_t oldValue;
52 | };
53 |
54 | DECLARE_VECTOR(mCoreMemorySearchResults, struct mCoreMemorySearchResult);
55 |
56 | struct mCore;
57 | void mCoreMemorySearch(struct mCore* core, const struct mCoreMemorySearchParams* params, struct mCoreMemorySearchResults* out, size_t limit);
58 | void mCoreMemorySearchRepeat(struct mCore* core, const struct mCoreMemorySearchParams* params, struct mCoreMemorySearchResults* inout);
59 |
60 | CXX_GUARD_END
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/include/mgba/core/rewind.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_CORE_REWIND_H
7 | #define M_CORE_REWIND_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #ifndef DISABLE_THREADING
15 | #include
16 | #endif
17 |
18 | DECLARE_VECTOR(mCoreRewindPatches, struct PatchFast);
19 |
20 | struct VFile;
21 | struct mCoreRewindContext {
22 | struct mCoreRewindPatches patchMemory;
23 | size_t current;
24 | size_t size;
25 | struct VFile* previousState;
26 | struct VFile* currentState;
27 |
28 | #ifndef DISABLE_THREADING
29 | bool onThread;
30 | Thread thread;
31 | Condition cond;
32 | Mutex mutex;
33 | bool ready;
34 | #endif
35 | };
36 |
37 | void mCoreRewindContextInit(struct mCoreRewindContext*, size_t entries, bool onThread);
38 | void mCoreRewindContextDeinit(struct mCoreRewindContext*);
39 |
40 | struct mCore;
41 | void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*);
42 | bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*);
43 |
44 | CXX_GUARD_END
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/include/mgba/core/serialize.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_SERIALIZE_H
7 | #define M_SERIALIZE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | enum mStateExtdataTag {
14 | EXTDATA_NONE = 0,
15 | EXTDATA_SCREENSHOT = 1,
16 | EXTDATA_SAVEDATA = 2,
17 | EXTDATA_CHEATS = 3,
18 | EXTDATA_RTC = 4,
19 | EXTDATA_META_TIME = 0x101,
20 | EXTDATA_META_CREATOR = 0x102,
21 | EXTDATA_MAX
22 | };
23 |
24 | #define SAVESTATE_SCREENSHOT 1
25 | #define SAVESTATE_SAVEDATA 2
26 | #define SAVESTATE_CHEATS 4
27 | #define SAVESTATE_RTC 8
28 | #define SAVESTATE_METADATA 16
29 | #define SAVESTATE_ALL 31
30 |
31 | struct mStateExtdataItem {
32 | int32_t size;
33 | void* data;
34 | void (*clean)(void*);
35 | };
36 |
37 | struct mStateExtdata {
38 | struct mStateExtdataItem data[EXTDATA_MAX];
39 | };
40 |
41 | void mStateExtdataInit(struct mStateExtdata*);
42 | void mStateExtdataDeinit(struct mStateExtdata*);
43 | void mStateExtdataPut(struct mStateExtdata*, enum mStateExtdataTag, struct mStateExtdataItem*);
44 | bool mStateExtdataGet(struct mStateExtdata*, enum mStateExtdataTag, struct mStateExtdataItem*);
45 |
46 | struct VFile;
47 | bool mStateExtdataSerialize(struct mStateExtdata* extdata, struct VFile* vf);
48 | bool mStateExtdataDeserialize(struct mStateExtdata* extdata, struct VFile* vf);
49 |
50 | struct mCore;
51 | bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags);
52 | bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags);
53 | void* mCoreExtractState(struct mCore* core, struct VFile* vf, struct mStateExtdata* extdata);
54 | bool mCoreExtractExtdata(struct mCore* core, struct VFile* vf, struct mStateExtdata* extdata);
55 |
56 | CXX_GUARD_END
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/include/mgba/core/sync.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_CORE_SYNC_H
7 | #define M_CORE_SYNC_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct mCoreSync {
16 | int videoFramePending;
17 | bool videoFrameWait;
18 | Mutex videoFrameMutex;
19 | Condition videoFrameAvailableCond;
20 | Condition videoFrameRequiredCond;
21 |
22 | bool audioWait;
23 | Condition audioRequiredCond;
24 | Mutex audioBufferMutex;
25 |
26 | float fpsTarget;
27 | };
28 |
29 | void mCoreSyncPostFrame(struct mCoreSync* sync);
30 | void mCoreSyncForceFrame(struct mCoreSync* sync);
31 | bool mCoreSyncWaitFrameStart(struct mCoreSync* sync);
32 | void mCoreSyncWaitFrameEnd(struct mCoreSync* sync);
33 | void mCoreSyncSetVideoSync(struct mCoreSync* sync, bool wait);
34 |
35 | struct blip_t;
36 | bool mCoreSyncProduceAudio(struct mCoreSync* sync, const struct blip_t*, size_t samples);
37 | void mCoreSyncLockAudio(struct mCoreSync* sync);
38 | void mCoreSyncUnlockAudio(struct mCoreSync* sync);
39 | void mCoreSyncConsumeAudio(struct mCoreSync* sync);
40 |
41 | CXX_GUARD_END
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/include/mgba/core/tile-cache.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_TILE_CACHE_H
7 | #define M_TILE_CACHE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | DECL_BITFIELD(mTileCacheConfiguration, uint32_t);
16 | DECL_BIT(mTileCacheConfiguration, ShouldStore, 0);
17 |
18 | DECL_BITFIELD(mTileCacheSystemInfo, uint32_t);
19 | DECL_BITS(mTileCacheSystemInfo, PaletteBPP, 0, 2);
20 | DECL_BITS(mTileCacheSystemInfo, PaletteCount, 2, 4);
21 | DECL_BITS(mTileCacheSystemInfo, MaxTiles, 16, 13);
22 |
23 | struct mTileCacheEntry {
24 | uint32_t paletteVersion;
25 | uint32_t vramVersion;
26 | uint8_t vramClean;
27 | uint8_t paletteId;
28 | uint16_t padding;
29 | };
30 |
31 | struct mTileCache {
32 | color_t* cache;
33 | struct mTileCacheEntry* status;
34 | uint32_t* globalPaletteVersion;
35 |
36 | uint32_t tileBase;
37 | uint32_t paletteBase;
38 | unsigned entriesPerTile;
39 | unsigned bpp;
40 |
41 | uint16_t* vram;
42 | color_t* palette;
43 | color_t temporaryTile[64];
44 |
45 | mTileCacheConfiguration config;
46 | mTileCacheSystemInfo sysConfig;
47 | };
48 |
49 | void mTileCacheInit(struct mTileCache* cache);
50 | void mTileCacheDeinit(struct mTileCache* cache);
51 | void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config);
52 | void mTileCacheConfigureSystem(struct mTileCache* cache, mTileCacheSystemInfo config, uint32_t tileBase, uint32_t paletteBase);
53 | void mTileCacheWriteVRAM(struct mTileCache* cache, uint32_t address);
54 | void mTileCacheWritePalette(struct mTileCache* cache, uint32_t entry, color_t color);
55 |
56 | const color_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId);
57 | const color_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId);
58 | const color_t* mTileCacheGetPalette(struct mTileCache* cache, unsigned paletteId);
59 | const uint16_t* mTileCacheGetVRAM(struct mTileCache* cache, unsigned tileId);
60 |
61 | CXX_GUARD_END
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/include/mgba/core/timing.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 M_CORE_TIMING
7 | #define M_CORE_TIMING
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct mTiming;
14 | struct mTimingEvent {
15 | void* context;
16 | void (*callback)(struct mTiming*, void* context, uint32_t);
17 | const char* name;
18 | uint32_t when;
19 | unsigned priority;
20 |
21 | struct mTimingEvent* next;
22 | };
23 |
24 | struct mTiming {
25 | struct mTimingEvent* root;
26 | struct mTimingEvent* reroot;
27 |
28 | uint64_t globalCycles;
29 | uint32_t masterCycles;
30 | int32_t* relativeCycles;
31 | int32_t* nextEvent;
32 | };
33 |
34 | void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent);
35 | void mTimingDeinit(struct mTiming* timing);
36 |
37 | void mTimingClear(struct mTiming* timing);
38 | void mTimingInterrupt(struct mTiming* timing);
39 |
40 | void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when);
41 | void mTimingScheduleAbsolute(struct mTiming* timing, struct mTimingEvent*, int32_t when);
42 | void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent*);
43 | bool mTimingIsScheduled(const struct mTiming* timing, const struct mTimingEvent*);
44 |
45 | int32_t mTimingTick(struct mTiming* timing, int32_t cycles);
46 |
47 | int32_t mTimingCurrentTime(const struct mTiming* timing);
48 | uint64_t mTimingGlobalTime(const struct mTiming* timing);
49 |
50 | int32_t mTimingNextEvent(struct mTiming* timing);
51 | int32_t mTimingUntil(const struct mTiming* timing, const struct mTimingEvent*);
52 |
53 | CXX_GUARD_END
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/mgba/core/version.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 VERSION_H
7 | #define VERSION_H
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | #include
14 |
15 | extern MGBA_EXPORT const char* const gitCommit;
16 | extern MGBA_EXPORT const char* const gitCommitShort;
17 | extern MGBA_EXPORT const char* const gitBranch;
18 | extern MGBA_EXPORT const int gitRevision;
19 | extern MGBA_EXPORT const char* const binaryName;
20 | extern MGBA_EXPORT const char* const projectName;
21 | extern MGBA_EXPORT const char* const projectVersion;
22 |
23 | #ifdef __cplusplus
24 | }
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/include/mgba/feature/commandline.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 COMMAND_LINE_H
7 | #define COMMAND_LINE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | #include
16 |
17 | struct mArguments {
18 | char* fname;
19 | char* patch;
20 | char* cheatsFile;
21 | char* savestate;
22 | char* bios;
23 | int logLevel;
24 | int frameskip;
25 |
26 | struct Table configOverrides;
27 |
28 | enum mDebuggerType debuggerType;
29 | bool debugAtStart;
30 | bool showHelp;
31 | bool showVersion;
32 | };
33 |
34 | struct mOption {
35 | const char* name;
36 | bool arg;
37 | char shortEquiv;
38 | };
39 |
40 | struct mCoreConfig;
41 | struct mSubParser {
42 | const char* usage;
43 | bool (*parse)(struct mSubParser* parser, int option, const char* arg);
44 | bool (*parseLong)(struct mSubParser* parser, const char* option, const char* arg);
45 | void (*apply)(struct mSubParser* parser, struct mCoreConfig* config);
46 | const char* extraOptions;
47 | const struct mOption* longOptions;
48 | void* opts;
49 | };
50 |
51 | struct mGraphicsOpts {
52 | int multiplier;
53 | bool fullscreen;
54 | };
55 |
56 | void usage(const char* arg0, const char* prologue, const char* epilogue, const struct mSubParser* subparsers, int nSubparsers);
57 | void version(const char* arg0);
58 |
59 | bool mArgumentsParse(struct mArguments* args, int argc, char* const* argv, struct mSubParser* subparsers, int nSubparsers);
60 | void mArgumentsApply(const struct mArguments* args, struct mSubParser* subparsers, int nSubparsers, struct mCoreConfig* config);
61 | void mArgumentsDeinit(struct mArguments* args);
62 |
63 | void mSubParserGraphicsInit(struct mSubParser* parser, struct mGraphicsOpts* opts);
64 |
65 | CXX_GUARD_END
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/include/mgba/feature/thread-proxy.h:
--------------------------------------------------------------------------------
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 VIDEO_THREAD_PROXY_H
7 | #define VIDEO_THREAD_PROXY_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include "video-logger.h"
15 | #include
16 | #include
17 |
18 | enum mVideoThreadProxyState {
19 | PROXY_THREAD_STOPPED = 0,
20 | PROXY_THREAD_IDLE,
21 | PROXY_THREAD_BUSY
22 | };
23 |
24 | struct mVideoThreadProxy {
25 | struct mVideoLogger d;
26 |
27 | Thread thread;
28 | Condition fromThreadCond;
29 | Condition toThreadCond;
30 | Mutex mutex;
31 | enum mVideoThreadProxyState threadState;
32 | enum mVideoLoggerEvent event;
33 |
34 | struct RingFIFO dirtyQueue;
35 | };
36 |
37 | void mVideoThreadProxyCreate(struct mVideoThreadProxy* renderer);
38 |
39 | CXX_GUARD_END
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/include/mgba/feature/updater.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2021 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 M_UPDATER_H
7 | #define M_UPDATER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | struct StringList;
17 | struct Table;
18 |
19 | struct mUpdaterContext {
20 | struct Configuration manifest;
21 | };
22 |
23 | struct mUpdate {
24 | const char* path;
25 | size_t size;
26 | int rev;
27 | const char* version;
28 | const char* commit;
29 | const char* sha256;
30 | };
31 |
32 | bool mUpdaterInit(struct mUpdaterContext*, const char* manifest);
33 | void mUpdaterDeinit(struct mUpdaterContext*);
34 | void mUpdaterGetPlatforms(const struct mUpdaterContext*, struct StringList* out);
35 | void mUpdaterGetUpdates(const struct mUpdaterContext*, const char* platform, struct Table* out);
36 | void mUpdaterGetUpdateForChannel(const struct mUpdaterContext*, const char* platform, const char* channel, struct mUpdate* out);
37 | const char* mUpdaterGetBucket(const struct mUpdaterContext*);
38 | void mUpdateRecord(struct mCoreConfig*, const char* prefix, const struct mUpdate*);
39 | bool mUpdateLoad(const struct mCoreConfig*, const char* prefix, struct mUpdate*);
40 |
41 | void mUpdateRegister(struct mCoreConfig*, const char* arg0, const char* updatePath);
42 | void mUpdateDeregister(struct mCoreConfig*);
43 |
44 | const char* mUpdateGetRoot(const struct mCoreConfig*);
45 | const char* mUpdateGetCommand(const struct mCoreConfig*);
46 | const char* mUpdateGetArchiveExtension(const struct mCoreConfig*);
47 | bool mUpdateGetArchivePath(const struct mCoreConfig*, char* out, size_t outLength);
48 |
49 | CXX_GUARD_END
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/include/mgba/gb/core.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_CORE_H
7 | #define GB_CORE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct mCore;
14 | struct mCore* GBCoreCreate(void);
15 | #ifndef MINIMAL_CORE
16 | struct mCore* GBVideoLogPlayerCreate(void);
17 | #endif
18 |
19 | CXX_GUARD_END
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/include/mgba/gb/interface.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_INTERFACE_H
7 | #define GB_INTERFACE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum GBModel {
16 | GB_MODEL_AUTODETECT = 0xFF,
17 | GB_MODEL_DMG = 0x00,
18 | GB_MODEL_SGB = 0x20,
19 | GB_MODEL_MGB = 0x40,
20 | GB_MODEL_SGB2 = GB_MODEL_MGB | GB_MODEL_SGB,
21 | GB_MODEL_CGB = 0x80,
22 | GB_MODEL_SCGB = GB_MODEL_CGB | GB_MODEL_SGB,
23 | GB_MODEL_AGB = 0xC0
24 | };
25 |
26 | enum GBMemoryBankControllerType {
27 | GB_MBC_AUTODETECT = -1,
28 | GB_MBC_NONE = 0,
29 | GB_MBC1 = 1,
30 | GB_MBC2 = 2,
31 | GB_MBC3 = 3,
32 | GB_MBC5 = 5,
33 | GB_MBC6 = 6,
34 | GB_MBC7 = 7,
35 | GB_MMM01 = 0x10,
36 | GB_HuC1 = 0x11,
37 | GB_HuC3 = 0x12,
38 | GB_POCKETCAM = 0x13,
39 | GB_TAMA5 = 0x14,
40 | GB_MBC3_RTC = 0x103,
41 | GB_MBC5_RUMBLE = 0x105,
42 | GB_UNL_WISDOM_TREE = 0x200,
43 | GB_UNL_PKJD = 0x203,
44 | GB_UNL_NT_NEW = 0x212,
45 | GB_UNL_BBD = 0x220, // Also used as a mask for MBCs that need special read behavior
46 | GB_UNL_HITEK = 0x221,
47 | GB_UNL_SACHEN_MMC1 = 0x230,
48 | GB_UNL_SACHEN_MMC2 = 0x231,
49 | };
50 |
51 | enum GBVideoLayer {
52 | GB_LAYER_BACKGROUND = 0,
53 | GB_LAYER_WINDOW,
54 | GB_LAYER_OBJ
55 | };
56 |
57 | struct GBSIODriver {
58 | struct GBSIO* p;
59 |
60 | bool (*init)(struct GBSIODriver* driver);
61 | void (*deinit)(struct GBSIODriver* driver);
62 | void (*writeSB)(struct GBSIODriver* driver, uint8_t value);
63 | uint8_t (*writeSC)(struct GBSIODriver* driver, uint8_t value);
64 | };
65 |
66 | struct VFile;
67 |
68 | bool GBIsROM(struct VFile* vf);
69 | bool GBIsBIOS(struct VFile* vf);
70 |
71 | enum GBModel GBNameToModel(const char*);
72 | const char* GBModelToName(enum GBModel);
73 |
74 | int GBValidModels(const uint8_t* bank0);
75 |
76 | CXX_GUARD_END
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/include/mgba/gba/core.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GBA_CORE_H
7 | #define GBA_CORE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct mCore;
14 | struct mCore* GBACoreCreate(void);
15 | #ifndef MINIMAL_CORE
16 | struct mCore* GBAVideoLogPlayerCreate(void);
17 | #endif
18 |
19 | CXX_GUARD_END
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/debugger/cli-debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 ARM_CLI_DEBUGGER_H
7 | #define ARM_CLI_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct CLIDebuggerSystem;
14 | void ARMCLIDebuggerCreate(struct CLIDebuggerSystem* debugger);
15 |
16 | CXX_GUARD_END
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/debugger/debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 ARM_DEBUGGER_H
7 | #define ARM_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | #include
16 | #include
17 |
18 | struct ParseTree;
19 | struct ARMDebugBreakpoint {
20 | struct mBreakpoint d;
21 | struct {
22 | uint32_t opcode;
23 | enum ExecutionMode mode;
24 | } sw;
25 | };
26 |
27 | DECLARE_VECTOR(ARMDebugBreakpointList, struct ARMDebugBreakpoint);
28 |
29 | struct ARMDebugger {
30 | struct mDebuggerPlatform d;
31 | struct ARMCore* cpu;
32 |
33 | struct ARMDebugBreakpointList breakpoints;
34 | struct ARMDebugBreakpointList swBreakpoints;
35 | struct mWatchpointList watchpoints;
36 | struct ARMMemory originalMemory;
37 |
38 | ssize_t nextId;
39 | uint32_t stackTraceMode;
40 |
41 | void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*);
42 |
43 | bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode);
44 | void (*clearSoftwareBreakpoint)(struct ARMDebugger*, const struct ARMDebugBreakpoint*);
45 | };
46 |
47 | struct mDebuggerPlatform* ARMDebuggerPlatformCreate(void);
48 | ssize_t ARMDebuggerSetSoftwareBreakpoint(struct mDebuggerPlatform* debugger, uint32_t address, enum ExecutionMode mode);
49 |
50 | CXX_GUARD_END
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/debugger/memory-debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 MEMORY_DEBUGGER_H
7 | #define MEMORY_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct ARMDebugger;
14 |
15 | void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger);
16 | void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger);
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/decoder-inlines.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 ARM_DECODER_INLINES_H
7 | #define ARM_DECODER_INLINES_H
8 |
9 | #include "decoder.h"
10 |
11 | #include "arm.h"
12 |
13 | #include
14 | #include
15 |
16 | #define LOAD_CYCLES \
17 | info->iCycles = 1; \
18 | info->nDataCycles = 1;
19 |
20 | #define STORE_CYCLES \
21 | info->sInstructionCycles = 0; \
22 | info->nInstructionCycles = 1; \
23 | info->nDataCycles = 1;
24 |
25 | static inline bool ARMInstructionIsBranch(enum ARMMnemonic mnemonic) {
26 | switch (mnemonic) {
27 | case ARM_MN_B:
28 | case ARM_MN_BL:
29 | case ARM_MN_BX:
30 | // TODO: case: ARM_MN_BLX:
31 | return true;
32 | default:
33 | return false;
34 | }
35 | }
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/emitter-inlines.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 EMITTER_INLINES_H
7 | #define EMITTER_INLINES_H
8 |
9 | #define DO_4(DIRECTIVE) \
10 | DIRECTIVE, \
11 | DIRECTIVE, \
12 | DIRECTIVE, \
13 | DIRECTIVE
14 |
15 | #define DO_8(DIRECTIVE) \
16 | DIRECTIVE, \
17 | DIRECTIVE, \
18 | DIRECTIVE, \
19 | DIRECTIVE, \
20 | DIRECTIVE, \
21 | DIRECTIVE, \
22 | DIRECTIVE, \
23 | DIRECTIVE
24 |
25 | #define DO_256(DIRECTIVE) \
26 | DO_4(DO_8(DO_8(DIRECTIVE)))
27 |
28 | #define DO_INTERLACE(LEFT, RIGHT) \
29 | LEFT, \
30 | RIGHT
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/isa-arm.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 ISA_ARM_H
7 | #define ISA_ARM_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #define ARM_PREFETCH_CYCLES (1 + cpu->memory.activeSeqCycles32)
14 |
15 | struct ARMCore;
16 |
17 | typedef void (*ARMInstruction)(struct ARMCore*, uint32_t opcode);
18 | extern const ARMInstruction _armTable[0x1000];
19 |
20 | CXX_GUARD_END
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/isa-thumb.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 ISA_THUMB_H
7 | #define ISA_THUMB_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct ARMCore;
14 |
15 | typedef void (*ThumbInstruction)(struct ARMCore*, unsigned opcode);
16 | extern const ThumbInstruction _thumbTable[0x400];
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/include/mgba/internal/arm/macros.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 MACROS_H
7 | #define MACROS_H
8 |
9 | #include
10 |
11 | #define LOAD_64 LOAD_64LE
12 | #define LOAD_32 LOAD_32LE
13 | #define LOAD_16 LOAD_16LE
14 | #define STORE_64 STORE_64LE
15 | #define STORE_32 STORE_32LE
16 | #define STORE_16 STORE_16LE
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/mgba/internal/debugger/cli-debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 CLI_DEBUGGER_H
7 | #define CLI_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | extern const char* ERROR_MISSING_ARGS;
16 | extern const char* ERROR_OVERFLOW;
17 | extern const char* ERROR_INVALID_ARGS;
18 | extern const char* INFO_BREAKPOINT_ADDED;
19 | extern const char* INFO_WATCHPOINT_ADDED;
20 |
21 | struct CLIDebugger;
22 | struct VFile;
23 |
24 | struct CLIDebugVector {
25 | struct CLIDebugVector* next;
26 | enum CLIDVType {
27 | CLIDV_ERROR_TYPE,
28 | CLIDV_INT_TYPE,
29 | CLIDV_CHAR_TYPE,
30 | } type;
31 | char* charValue;
32 | int32_t intValue;
33 | int segmentValue;
34 | };
35 |
36 | typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*);
37 |
38 | struct CLIDebuggerCommandSummary {
39 | const char* name;
40 | CLIDebuggerCommand command;
41 | const char* format;
42 | const char* summary;
43 | };
44 |
45 | struct CLIDebuggerCommandAlias {
46 | const char* name;
47 | const char* original;
48 | };
49 |
50 | struct CLIDebuggerSystem {
51 | struct CLIDebugger* p;
52 |
53 | void (*init)(struct CLIDebuggerSystem*);
54 | void (*deinit)(struct CLIDebuggerSystem*);
55 | bool (*custom)(struct CLIDebuggerSystem*);
56 |
57 | void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv);
58 | void (*printStatus)(struct CLIDebuggerSystem*);
59 |
60 | struct CLIDebuggerCommandSummary* commands;
61 | struct CLIDebuggerCommandAlias* commandAliases;
62 | const char* name;
63 | struct CLIDebuggerCommandSummary* platformCommands;
64 | struct CLIDebuggerCommandAlias* platformCommandAliases;
65 | const char* platformName;
66 | };
67 |
68 | struct CLIDebuggerBackend {
69 | struct CLIDebugger* p;
70 |
71 | void (*init)(struct CLIDebuggerBackend*);
72 | void (*deinit)(struct CLIDebuggerBackend*);
73 |
74 | ATTRIBUTE_FORMAT(printf, 2, 3)
75 | void (*printf)(struct CLIDebuggerBackend*, const char* fmt, ...);
76 | const char* (*readline)(struct CLIDebuggerBackend*, size_t* len);
77 | void (*lineAppend)(struct CLIDebuggerBackend*, const char* line);
78 | const char* (*historyLast)(struct CLIDebuggerBackend*, size_t* len);
79 | void (*historyAppend)(struct CLIDebuggerBackend*, const char* line);
80 | void (*interrupt)(struct CLIDebuggerBackend*);
81 | };
82 |
83 | struct CLIDebugger {
84 | struct mDebugger d;
85 |
86 | struct CLIDebuggerSystem* system;
87 | struct CLIDebuggerBackend* backend;
88 |
89 | int traceRemaining;
90 | struct VFile* traceVf;
91 | bool skipStatus;
92 | };
93 |
94 | void CLIDebuggerCreate(struct CLIDebugger*);
95 | void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*);
96 | void CLIDebuggerAttachBackend(struct CLIDebugger*, struct CLIDebuggerBackend*);
97 |
98 | bool CLIDebuggerTabComplete(struct CLIDebugger*, const char* token, bool initial, size_t len);
99 |
100 | bool CLIDebuggerRunCommand(struct CLIDebugger* debugger, const char* line, size_t count);
101 | #ifdef ENABLE_SCRIPTING
102 | void CLIDebuggerScriptEngineInstall(struct mScriptBridge* sb);
103 | #endif
104 |
105 | CXX_GUARD_END
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/include/mgba/internal/debugger/gdb-stub.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 GDB_STUB_H
7 | #define GDB_STUB_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | #include
16 |
17 | #define GDB_STUB_MAX_LINE 1200
18 | #define GDB_STUB_INTERVAL 32
19 |
20 | enum GDBStubAckState {
21 | GDB_ACK_PENDING = 0,
22 | GDB_ACK_RECEIVED,
23 | GDB_NAK_RECEIVED,
24 | GDB_ACK_OFF
25 | };
26 |
27 | enum GDBWatchpointsBehvaior {
28 | GDB_WATCHPOINT_STANDARD_LOGIC = 0,
29 | GDB_WATCHPOINT_OVERRIDE_LOGIC,
30 | GDB_WATCHPOINT_OVERRIDE_LOGIC_ANY_WRITE,
31 | };
32 |
33 | struct GDBStub {
34 | struct mDebugger d;
35 |
36 | char line[GDB_STUB_MAX_LINE];
37 | char outgoing[GDB_STUB_MAX_LINE];
38 | char memoryMapXml[GDB_STUB_MAX_LINE];
39 | enum GDBStubAckState lineAck;
40 |
41 | Socket socket;
42 | Socket connection;
43 |
44 | bool shouldBlock;
45 | int untilPoll;
46 |
47 | bool supportsSwbreak;
48 | bool supportsHwbreak;
49 |
50 | enum GDBWatchpointsBehvaior watchpointsBehavior;
51 | };
52 |
53 | void GDBStubCreate(struct GDBStub*);
54 | bool GDBStubListen(struct GDBStub*, int port, const struct Address* bindAddress, enum GDBWatchpointsBehvaior watchpointsBehavior);
55 |
56 | void GDBStubHangup(struct GDBStub*);
57 | void GDBStubShutdown(struct GDBStub*);
58 |
59 | void GDBStubUpdate(struct GDBStub*);
60 |
61 | CXX_GUARD_END
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/include/mgba/internal/debugger/parser.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 PARSER_H
7 | #define PARSER_H
8 |
9 | #include
10 |
11 | #include
12 |
13 | CXX_GUARD_START
14 |
15 | struct Token;
16 | DECLARE_VECTOR(LexVector, struct Token);
17 |
18 | enum Operation {
19 | OP_ASSIGN,
20 | OP_ADD,
21 | OP_SUBTRACT,
22 | OP_MULTIPLY,
23 | OP_DIVIDE,
24 | OP_MODULO,
25 | OP_AND,
26 | OP_OR,
27 | OP_XOR,
28 | OP_LESS,
29 | OP_GREATER,
30 | OP_EQUAL,
31 | OP_NOT_EQUAL,
32 | OP_LOGICAL_AND,
33 | OP_LOGICAL_OR,
34 | OP_LE,
35 | OP_GE,
36 | OP_NEGATE,
37 | OP_FLIP,
38 | OP_NOT,
39 | OP_SHIFT_L,
40 | OP_SHIFT_R,
41 | OP_DEREFERENCE,
42 | };
43 |
44 | struct Token {
45 | enum TokenType {
46 | TOKEN_ERROR_TYPE = 0,
47 | TOKEN_UINT_TYPE,
48 | TOKEN_IDENTIFIER_TYPE,
49 | TOKEN_OPERATOR_TYPE,
50 | TOKEN_OPEN_PAREN_TYPE,
51 | TOKEN_CLOSE_PAREN_TYPE,
52 | TOKEN_SEGMENT_TYPE,
53 | } type;
54 | union {
55 | uint32_t uintValue;
56 | char* identifierValue;
57 | enum Operation operatorValue;
58 | };
59 | };
60 |
61 | struct ParseTree {
62 | struct Token token;
63 | struct ParseTree* p;
64 | struct ParseTree* lhs;
65 | struct ParseTree* rhs;
66 | int precedence;
67 | };
68 |
69 | size_t lexExpression(struct LexVector* lv, const char* string, size_t length, const char* eol);
70 | void lexFree(struct LexVector* lv);
71 |
72 | struct ParseTree* parseTreeCreate(void);
73 | void parseFree(struct ParseTree* tree);
74 | bool parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
75 |
76 | struct mDebugger;
77 | bool mDebuggerEvaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, int32_t* value, int* segment);
78 |
79 | CXX_GUARD_END
80 |
81 | #endif
82 |
--------------------------------------------------------------------------------
/include/mgba/internal/debugger/stack-trace.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2020 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 STACK_TRACE_H
7 | #define STACK_TRACE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | struct mDebuggerSymbols;
18 |
19 | enum mStackTraceMode {
20 | STACK_TRACE_DISABLED = 0,
21 | STACK_TRACE_ENABLED = 1,
22 | STACK_TRACE_BREAK_ON_RETURN = 2,
23 | STACK_TRACE_BREAK_ON_CALL = 4,
24 | STACK_TRACE_BREAK_ON_BOTH = STACK_TRACE_BREAK_ON_RETURN | STACK_TRACE_BREAK_ON_CALL
25 | };
26 |
27 | struct mStackFrame {
28 | int callSegment;
29 | uint32_t callAddress;
30 | int entrySegment;
31 | uint32_t entryAddress;
32 | int frameBaseSegment;
33 | uint32_t frameBaseAddress;
34 | void* regs;
35 | bool finished;
36 | bool breakWhenFinished;
37 | bool interrupt;
38 | };
39 |
40 | DECLARE_VECTOR(mStackFrames, struct mStackFrame);
41 |
42 | struct mStackTrace {
43 | struct mStackFrames stack;
44 | size_t registersSize;
45 |
46 | void (*formatRegisters)(struct mStackFrame* frame, char* out, size_t* length);
47 | };
48 |
49 | void mStackTraceInit(struct mStackTrace* stack, size_t registersSize);
50 | void mStackTraceDeinit(struct mStackTrace* stack);
51 |
52 | void mStackTraceClear(struct mStackTrace* stack);
53 | size_t mStackTraceGetDepth(struct mStackTrace* stack);
54 | struct mStackFrame* mStackTracePush(struct mStackTrace* stack, uint32_t pc, uint32_t destAddress, uint32_t sp, void* regs);
55 | struct mStackFrame* mStackTracePushSegmented(struct mStackTrace* stack, int pcSegment, uint32_t pc, int destSegment, uint32_t destAddress, int spSegment, uint32_t sp, void* regs);
56 | struct mStackFrame* mStackTraceGetFrame(struct mStackTrace* stack, uint32_t frame);
57 | void mStackTraceFormatFrame(struct mStackTrace* stack, struct mDebuggerSymbols* st, uint32_t frame, char* out, size_t* length);
58 | void mStackTracePop(struct mStackTrace* stack);
59 |
60 | CXX_GUARD_END
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/include/mgba/internal/debugger/symbols.h:
--------------------------------------------------------------------------------
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 DEBUGGER_SYMBOLS_H
7 | #define DEBUGGER_SYMBOLS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct mDebuggerSymbols;
14 |
15 | struct mDebuggerSymbols* mDebuggerSymbolTableCreate(void);
16 | void mDebuggerSymbolTableDestroy(struct mDebuggerSymbols*);
17 |
18 | bool mDebuggerSymbolLookup(const struct mDebuggerSymbols*, const char* name, int32_t* value, int* segment);
19 | const char* mDebuggerSymbolReverseLookup(const struct mDebuggerSymbols*, int32_t value, int segment);
20 |
21 | void mDebuggerSymbolAdd(struct mDebuggerSymbols*, const char* name, int32_t value, int segment);
22 | void mDebuggerSymbolRemove(struct mDebuggerSymbols*, const char* name);
23 |
24 | struct VFile;
25 | void mDebuggerLoadARMIPSSymbols(struct mDebuggerSymbols*, struct VFile* vf);
26 |
27 | CXX_GUARD_END
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/mgba/internal/defines.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2022 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 M_INTERNAL_DEFINES_H
7 | #define M_INTERNAL_DEFINES_H
8 |
9 | #define mSAVEDATA_CLEANUP_THRESHOLD 15
10 |
11 | enum {
12 | mSAVEDATA_DIRT_NONE = 0,
13 | mSAVEDATA_DIRT_NEW = 1,
14 | mSAVEDATA_DIRT_SEEN = 2,
15 | };
16 |
17 | static inline bool mSavedataClean(int* dirty, uint32_t* dirtAge, uint32_t frameCount) {
18 | if (*dirty & mSAVEDATA_DIRT_NEW) {
19 | *dirtAge = frameCount;
20 | *dirty &= ~mSAVEDATA_DIRT_NEW;
21 | if (!(*dirty & mSAVEDATA_DIRT_SEEN)) {
22 | *dirty |= mSAVEDATA_DIRT_SEEN;
23 | }
24 | } else if ((*dirty & mSAVEDATA_DIRT_SEEN) && frameCount - *dirtAge > mSAVEDATA_CLEANUP_THRESHOLD) {
25 | *dirty = 0;
26 | return true;
27 | }
28 | return false;
29 | }
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/cheats.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_CHEATS_H
7 | #define GB_CHEATS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum GBCheatType {
16 | GB_CHEAT_AUTODETECT,
17 | GB_CHEAT_GAMESHARK,
18 | GB_CHEAT_GAME_GENIE,
19 | GB_CHEAT_VBA
20 | };
21 |
22 | struct mCheatDevice* GBCheatDeviceCreate(void);
23 |
24 | CXX_GUARD_END
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/debugger/debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 GB_DEBUGGER_H
7 | #define GB_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct GB;
14 | struct mDebuggerPlatform;
15 |
16 | struct mDebuggerPlatform* GBDebuggerCreate(struct GB* gb);
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
--------------------------------------------------------------------------------
/include/mgba/internal/gb/debugger/symbols.h:
--------------------------------------------------------------------------------
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 GB_SYMBOLS_H
7 | #define GB_SYMBOLS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct mDebuggerSymbols;
14 | struct VFile;
15 | void GBLoadSymbols(struct mDebuggerSymbols*, struct VFile* vf);
16 |
17 | CXX_GUARD_END
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/extra/cli.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_CLI_H
7 | #define GB_CLI_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct GBCLIDebugger {
16 | struct CLIDebuggerSystem d;
17 |
18 | struct mCore* core;
19 |
20 | bool frameAdvance;
21 | bool inVblank;
22 | };
23 |
24 | struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore*);
25 |
26 | CXX_GUARD_END
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/input.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 GB_INPUT_H
7 | #define GB_INPUT_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | extern MGBA_EXPORT const struct mInputPlatformInfo GBInputInfo;
16 |
17 | enum GBKey {
18 | GB_KEY_A = 0,
19 | GB_KEY_B = 1,
20 | GB_KEY_SELECT = 2,
21 | GB_KEY_START = 3,
22 | GB_KEY_RIGHT = 4,
23 | GB_KEY_LEFT = 5,
24 | GB_KEY_UP = 6,
25 | GB_KEY_DOWN = 7,
26 | GB_KEY_MAX,
27 | };
28 |
29 | CXX_GUARD_END
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/io.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_IO_H
7 | #define GB_IO_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | mLOG_DECLARE_CATEGORY(GB_IO);
16 |
17 | enum GBIORegisters {
18 | GB_REG_JOYP = 0x00,
19 | GB_REG_SB = 0x01,
20 | GB_REG_SC = 0x02,
21 |
22 | // Timing
23 | GB_REG_DIV = 0x04,
24 | GB_REG_TIMA = 0x05,
25 | GB_REG_TMA = 0x06,
26 | GB_REG_TAC = 0x07,
27 |
28 | // Interrupts
29 | GB_REG_IF = 0x0F,
30 | GB_REG_IE = 0xFF,
31 |
32 | // Audio
33 | GB_REG_NR10 = 0x10,
34 | GB_REG_NR11 = 0x11,
35 | GB_REG_NR12 = 0x12,
36 | GB_REG_NR13 = 0x13,
37 | GB_REG_NR14 = 0x14,
38 | GB_REG_NR21 = 0x16,
39 | GB_REG_NR22 = 0x17,
40 | GB_REG_NR23 = 0x18,
41 | GB_REG_NR24 = 0x19,
42 | GB_REG_NR30 = 0x1A,
43 | GB_REG_NR31 = 0x1B,
44 | GB_REG_NR32 = 0x1C,
45 | GB_REG_NR33 = 0x1D,
46 | GB_REG_NR34 = 0x1E,
47 | GB_REG_NR41 = 0x20,
48 | GB_REG_NR42 = 0x21,
49 | GB_REG_NR43 = 0x22,
50 | GB_REG_NR44 = 0x23,
51 | GB_REG_NR50 = 0x24,
52 | GB_REG_NR51 = 0x25,
53 | GB_REG_NR52 = 0x26,
54 |
55 | GB_REG_WAVE_0 = 0x30,
56 | GB_REG_WAVE_1 = 0x31,
57 | GB_REG_WAVE_2 = 0x32,
58 | GB_REG_WAVE_3 = 0x33,
59 | GB_REG_WAVE_4 = 0x34,
60 | GB_REG_WAVE_5 = 0x35,
61 | GB_REG_WAVE_6 = 0x36,
62 | GB_REG_WAVE_7 = 0x37,
63 | GB_REG_WAVE_8 = 0x38,
64 | GB_REG_WAVE_9 = 0x39,
65 | GB_REG_WAVE_A = 0x3A,
66 | GB_REG_WAVE_B = 0x3B,
67 | GB_REG_WAVE_C = 0x3C,
68 | GB_REG_WAVE_D = 0x3D,
69 | GB_REG_WAVE_E = 0x3E,
70 | GB_REG_WAVE_F = 0x3F,
71 |
72 | // Video
73 | GB_REG_LCDC = 0x40,
74 | GB_REG_STAT = 0x41,
75 | GB_REG_SCY = 0x42,
76 | GB_REG_SCX = 0x43,
77 | GB_REG_LY = 0x44,
78 | GB_REG_LYC = 0x45,
79 | GB_REG_DMA = 0x46,
80 | GB_REG_BGP = 0x47,
81 | GB_REG_OBP0 = 0x48,
82 | GB_REG_OBP1 = 0x49,
83 | GB_REG_WY = 0x4A,
84 | GB_REG_WX = 0x4B,
85 |
86 | // CGB
87 | GB_REG_KEY0 = 0x4C,
88 | GB_REG_KEY1 = 0x4D,
89 | GB_REG_VBK = 0x4F,
90 | GB_REG_BANK = 0x50,
91 | GB_REG_HDMA1 = 0x51,
92 | GB_REG_HDMA2 = 0x52,
93 | GB_REG_HDMA3 = 0x53,
94 | GB_REG_HDMA4 = 0x54,
95 | GB_REG_HDMA5 = 0x55,
96 | GB_REG_RP = 0x56,
97 | GB_REG_BCPS = 0x68,
98 | GB_REG_BCPD = 0x69,
99 | GB_REG_OCPS = 0x6A,
100 | GB_REG_OCPD = 0x6B,
101 | GB_REG_OPRI = 0x6C,
102 | GB_REG_SVBK = 0x70,
103 | GB_REG_PSWX = 0x72,
104 | GB_REG_PSWY = 0x73,
105 | GB_REG_PSW = 0x74,
106 | GB_REG_UNK75 = 0x75,
107 | GB_REG_PCM12 = 0x76,
108 | GB_REG_PCM34 = 0x77,
109 | GB_REG_MAX = 0x100
110 | };
111 |
112 | extern MGBA_EXPORT const char* const GBIORegisterNames[];
113 |
114 | struct GB;
115 | void GBIOInit(struct GB* gb);
116 | void GBIOReset(struct GB* gb);
117 |
118 | void GBIOWrite(struct GB* gb, unsigned address, uint8_t value);
119 | uint8_t GBIORead(struct GB* gb, unsigned address);
120 |
121 | struct GBSerializedState;
122 | void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state);
123 | void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state);
124 |
125 | CXX_GUARD_END
126 |
127 | #endif
128 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/mbc.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_MBC_H
7 | #define GB_MBC_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | mLOG_DECLARE_CATEGORY(GB_MBC);
16 |
17 | struct GB;
18 | struct GBMemory;
19 | void GBMBCInit(struct GB* gb);
20 | void GBMBCReset(struct GB* gb);
21 | void GBMBCSwitchBank(struct GB* gb, int bank);
22 | void GBMBCSwitchBank0(struct GB* gb, int bank);
23 | void GBMBCSwitchHalfBank(struct GB* gb, int half, int bank);
24 | void GBMBCSwitchSramBank(struct GB* gb, int bank);
25 | void GBMBCSwitchSramHalfBank(struct GB* gb, int half, int bank);
26 |
27 | enum GBMemoryBankControllerType GBMBCFromGBX(const void* fourcc);
28 |
29 | enum GBCam {
30 | GBCAM_WIDTH = 128,
31 | GBCAM_HEIGHT = 112
32 | };
33 |
34 | struct GBMBCRTCSaveBuffer {
35 | uint32_t sec;
36 | uint32_t min;
37 | uint32_t hour;
38 | uint32_t days;
39 | uint32_t daysHi;
40 | uint32_t latchedSec;
41 | uint32_t latchedMin;
42 | uint32_t latchedHour;
43 | uint32_t latchedDays;
44 | uint32_t latchedDaysHi;
45 | uint64_t unixTime;
46 | };
47 |
48 | struct GBMBCHuC3SaveBuffer {
49 | uint8_t regs[0x80];
50 | uint64_t latchedUnix;
51 | };
52 |
53 | struct GBMBCTAMA5SaveBuffer {
54 | uint8_t rtcTimerPage[0x8];
55 | uint8_t rtcAlarmPage[0x8];
56 | uint8_t rtcFreePage0[0x8];
57 | uint8_t rtcFreePage1[0x8];
58 | uint64_t latchedUnix;
59 | };
60 |
61 | void GBMBCRTCRead(struct GB* gb);
62 | void GBMBCRTCWrite(struct GB* gb);
63 |
64 | void GBMBCHuC3Read(struct GB* gb);
65 | void GBMBCHuC3Write(struct GB* gb);
66 |
67 | void GBMBCTAMA5Read(struct GB* gb);
68 | void GBMBCTAMA5Write(struct GB* gb);
69 |
70 | CXX_GUARD_END
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/overrides.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_OVERRIDES_H
7 | #define GB_OVERRIDES_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum GBColorLookup {
16 | GB_COLORS_NONE = 0,
17 | GB_COLORS_CGB = 1,
18 | GB_COLORS_SGB = 2,
19 | GB_COLORS_SGB_CGB_FALLBACK = GB_COLORS_CGB | GB_COLORS_SGB
20 | };
21 |
22 | struct GBCartridgeOverride {
23 | int headerCrc32;
24 | enum GBModel model;
25 | enum GBMemoryBankControllerType mbc;
26 |
27 | uint32_t gbColors[12];
28 | };
29 |
30 | struct GBColorPreset {
31 | const char* name;
32 | uint32_t colors[12];
33 | };
34 |
35 | struct Configuration;
36 | bool GBOverrideFind(const struct Configuration*, struct GBCartridgeOverride* override);
37 | bool GBOverrideColorFind(struct GBCartridgeOverride* override, enum GBColorLookup);
38 | void GBOverrideSave(struct Configuration*, const struct GBCartridgeOverride* override);
39 |
40 | size_t GBColorPresetList(const struct GBColorPreset** presets);
41 |
42 | struct GB;
43 | void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*);
44 | void GBOverrideApplyDefaults(struct GB*);
45 |
46 | CXX_GUARD_END
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/renderers/cache-set.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_TILE_CACHE_H
7 | #define GB_TILE_CACHE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct GBVideo;
14 | struct mCacheSet;
15 |
16 | void GBVideoCacheInit(struct mCacheSet* cache);
17 | void GBVideoCacheAssociate(struct mCacheSet* cache, struct GBVideo* video);
18 |
19 | void GBVideoCacheWriteVideoRegister(struct mCacheSet* cache, uint16_t address, uint8_t value);
20 |
21 | CXX_GUARD_END
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/renderers/proxy.h:
--------------------------------------------------------------------------------
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 GB_VIDEO_PROXY_H
7 | #define GB_VIDEO_PROXY_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | struct GBVideoProxyRenderer {
17 | struct GBVideoRenderer d;
18 | struct GBVideoRenderer* backend;
19 | struct mVideoLogger* logger;
20 | enum GBModel model;
21 | };
22 |
23 | void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GBVideoRenderer* backend);
24 | void GBVideoProxyRendererShim(struct GBVideo* video, struct GBVideoProxyRenderer* renderer);
25 | void GBVideoProxyRendererUnshim(struct GBVideo* video, struct GBVideoProxyRenderer* renderer);
26 |
27 | CXX_GUARD_END
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/renderers/software.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_RENDERER_SOFTWARE_H
7 | #define GB_RENDERER_SOFTWARE_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | struct GBVideoRendererSprite {
18 | struct GBObj obj;
19 | int8_t index;
20 | };
21 |
22 | struct GBVideoSoftwareRenderer {
23 | struct GBVideoRenderer d;
24 |
25 | color_t* outputBuffer;
26 | int outputBufferStride;
27 |
28 | // TODO: Implement the pixel FIFO
29 | uint16_t row[GB_VIDEO_HORIZONTAL_PIXELS + 8];
30 |
31 | color_t palette[192];
32 | uint8_t lookup[192];
33 |
34 | uint32_t* temporaryBuffer;
35 |
36 | uint8_t scy;
37 | uint8_t scx;
38 | uint8_t wy;
39 | uint8_t wx;
40 | uint8_t currentWy;
41 | uint8_t currentWx;
42 | int lastY;
43 | int lastX;
44 | bool hasWindow;
45 |
46 | GBRegisterLCDC lcdc;
47 | enum GBModel model;
48 |
49 | struct GBVideoRendererSprite obj[GB_VIDEO_MAX_LINE_OBJ];
50 | int objMax;
51 |
52 | int16_t objOffsetX;
53 | int16_t objOffsetY;
54 | int16_t offsetScx;
55 | int16_t offsetScy;
56 | int16_t offsetWx;
57 | int16_t offsetWy;
58 |
59 | int sgbTransfer;
60 | uint8_t sgbPacket[128];
61 | uint8_t sgbCommandHeader;
62 | bool sgbBorders;
63 | uint32_t sgbBorderMask[18];
64 |
65 | uint8_t lastHighlightAmount;
66 | };
67 |
68 | void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*);
69 |
70 | CXX_GUARD_END
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/sio.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_SIO_H
7 | #define GB_SIO_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | #define MAX_GBS 2
18 |
19 | extern const int GBSIOCyclesPerTransfer[2];
20 |
21 | mLOG_DECLARE_CATEGORY(GB_SIO);
22 |
23 | struct GB;
24 | struct GBSIODriver;
25 | struct GBSIO {
26 | struct GB* p;
27 |
28 | struct mTimingEvent event;
29 | struct GBSIODriver* driver;
30 |
31 | int32_t nextEvent;
32 | int32_t period;
33 | int remainingBits;
34 |
35 | uint8_t pendingSB;
36 | };
37 |
38 | DECL_BITFIELD(GBRegisterSC, uint8_t);
39 | DECL_BIT(GBRegisterSC, ShiftClock, 0);
40 | DECL_BIT(GBRegisterSC, ClockSpeed, 1);
41 | DECL_BIT(GBRegisterSC, Enable, 7);
42 |
43 | void GBSIOInit(struct GBSIO* sio);
44 | void GBSIOReset(struct GBSIO* sio);
45 | void GBSIODeinit(struct GBSIO* sio);
46 | void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver);
47 | void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc);
48 | void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb);
49 |
50 | CXX_GUARD_END
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/sio/lockstep.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_SIO_LOCKSTEP_H
7 | #define GB_SIO_LOCKSTEP_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | struct GBSIOLockstep {
18 | struct mLockstep d;
19 | struct GBSIOLockstepNode* players[MAX_GBS];
20 |
21 | uint8_t pendingSB[MAX_GBS];
22 | bool masterClaimed;
23 | };
24 |
25 | struct GBSIOLockstepNode {
26 | struct GBSIODriver d;
27 | struct GBSIOLockstep* p;
28 | struct mTimingEvent event;
29 |
30 | volatile int32_t nextEvent;
31 | int32_t eventDiff;
32 | int id;
33 | bool transferFinished;
34 | #ifndef NDEBUG
35 | int transferId;
36 | enum mLockstepPhase phase;
37 | #endif
38 | };
39 |
40 | void GBSIOLockstepInit(struct GBSIOLockstep*);
41 |
42 | void GBSIOLockstepNodeCreate(struct GBSIOLockstepNode*);
43 |
44 | bool GBSIOLockstepAttachNode(struct GBSIOLockstep*, struct GBSIOLockstepNode*);
45 | void GBSIOLockstepDetachNode(struct GBSIOLockstep*, struct GBSIOLockstepNode*);
46 |
47 | CXX_GUARD_END
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/sio/printer.h:
--------------------------------------------------------------------------------
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 GB_PRINTER_H
7 | #define GB_PRINTER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum GBPrinterPacketByte {
16 | GB_PRINTER_BYTE_MAGIC_0,
17 | GB_PRINTER_BYTE_MAGIC_1,
18 | GB_PRINTER_BYTE_COMMAND,
19 | GB_PRINTER_BYTE_COMPRESSION,
20 | GB_PRINTER_BYTE_LENGTH_0,
21 | GB_PRINTER_BYTE_LENGTH_1,
22 | GB_PRINTER_BYTE_DATA,
23 | GB_PRINTER_BYTE_CHECKSUM_0,
24 | GB_PRINTER_BYTE_CHECKSUM_1,
25 | GB_PRINTER_BYTE_KEEPALIVE,
26 | GB_PRINTER_BYTE_STATUS,
27 |
28 | GB_PRINTER_BYTE_COMPRESSED_DATUM,
29 | GB_PRINTER_BYTE_UNCOMPRESSED_DATA
30 | };
31 |
32 | enum GBPrinterStatus {
33 | GB_PRINTER_STATUS_CHECKSUM_ERROR = 0x01,
34 | GB_PRINTER_STATUS_PRINTING = 0x02,
35 | GB_PRINTER_STATUS_PRINT_REQ = 0x04,
36 | GB_PRINTER_STATUS_READY = 0x08,
37 | GB_PRINTER_STATUS_LOW_BATTERY = 0x10,
38 | GB_PRINTER_STATUS_TIMEOUT = 0x20,
39 | GB_PRINTER_STATUS_PAPER_JAM = 0x40,
40 | GB_PRINTER_STATUS_TEMPERATURE_ISSUE = 0x80
41 | };
42 |
43 | enum GBPrinterCommand {
44 | GB_PRINTER_COMMAND_INIT = 0x1,
45 | GB_PRINTER_COMMAND_PRINT = 0x2,
46 | GB_PRINTER_COMMAND_DATA = 0x4,
47 | GB_PRINTER_COMMAND_STATUS = 0xF,
48 | };
49 |
50 | struct GBPrinter {
51 | struct GBSIODriver d;
52 |
53 | void (*print)(struct GBPrinter*, int height, const uint8_t* data);
54 |
55 | uint8_t* buffer;
56 | uint16_t checksum;
57 | enum GBPrinterCommand command;
58 | uint16_t remainingBytes;
59 | uint8_t remainingCmpBytes;
60 | unsigned currentIndex;
61 | bool compression;
62 |
63 | uint8_t byte;
64 | enum GBPrinterPacketByte next;
65 | uint8_t status;
66 | int printWait;
67 | };
68 |
69 | void GBPrinterCreate(struct GBPrinter* printer);
70 | void GBPrinterDonePrinting(struct GBPrinter* printer);
71 |
72 | CXX_GUARD_END
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/include/mgba/internal/gb/timer.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GB_TIMER_H
7 | #define GB_TIMER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | DECL_BITFIELD(GBRegisterTAC, uint8_t);
16 | DECL_BITS(GBRegisterTAC, Clock, 0, 2);
17 | DECL_BIT(GBRegisterTAC, Run, 2);
18 |
19 | enum {
20 | GB_DMG_DIV_PERIOD = 16
21 | };
22 |
23 | struct GB;
24 | struct GBTimer {
25 | struct GB* p;
26 |
27 | struct mTimingEvent event;
28 | struct mTimingEvent irq;
29 |
30 | uint32_t internalDiv;
31 | int32_t nextDiv;
32 | uint32_t timaPeriod;
33 | };
34 |
35 | void GBTimerReset(struct GBTimer*);
36 | void GBTimerDivReset(struct GBTimer*);
37 | uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac);
38 |
39 | struct GBSerializedState;
40 | void GBTimerSerialize(const struct GBTimer* timer, struct GBSerializedState* state);
41 | void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* state);
42 |
43 | CXX_GUARD_END
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/bios.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_BIOS_H
7 | #define GBA_BIOS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | mLOG_DECLARE_CATEGORY(GBA_BIOS);
16 |
17 | enum GBASwi {
18 | GBA_SWI_SOFT_RESET = 0x00,
19 | GBA_SWI_REGISTER_RAM_RESET = 0x01,
20 | GBA_SWI_HALT = 0x02,
21 | GBA_SWI_STOP = 0x03,
22 | GBA_SWI_INTR_WAIT = 0x04,
23 | GBA_SWI_VBLANK_INTR_WAIT = 0x05,
24 | GBA_SWI_DIV = 0x06,
25 | GBA_SWI_DIV_ARM = 0x07,
26 | GBA_SWI_SQRT = 0x08,
27 | GBA_SWI_ARCTAN = 0x09,
28 | GBA_SWI_ARCTAN2 = 0x0A,
29 | GBA_SWI_CPU_SET = 0x0B,
30 | GBA_SWI_CPU_FAST_SET = 0x0C,
31 | GBA_SWI_GET_BIOS_CHECKSUM = 0x0D,
32 | GBA_SWI_BG_AFFINE_SET = 0x0E,
33 | GBA_SWI_OBJ_AFFINE_SET = 0x0F,
34 | GBA_SWI_BIT_UNPACK = 0x10,
35 | GBA_SWI_LZ77_UNCOMP_WRAM = 0x11,
36 | GBA_SWI_LZ77_UNCOMP_VRAM = 0x12,
37 | GBA_SWI_HUFFMAN_UNCOMP = 0x13,
38 | GBA_SWI_RL_UNCOMP_WRAM = 0x14,
39 | GBA_SWI_RL_UNCOMP_VRAM = 0x15,
40 | GBA_SWI_DIFF_8BIT_UNFILTER_WRAM = 0x16,
41 | GBA_SWI_DIFF_8BIT_UNFILTER_VRAM = 0x17,
42 | GBA_SWI_DIFF_16BIT_UNFILTER = 0x18,
43 | GBA_SWI_SOUND_BIAS = 0x19,
44 | GBA_SWI_SOUND_DRIVER_INIT = 0x1A,
45 | GBA_SWI_SOUND_DRIVER_MODE = 0x1B,
46 | GBA_SWI_SOUND_DRIVER_MAIN = 0x1C,
47 | GBA_SWI_SOUND_DRIVER_VSYNC = 0x1D,
48 | GBA_SWI_SOUND_CHANNEL_CLEAR = 0x1E,
49 | GBA_SWI_MIDI_KEY_2_FREQ = 0x1F,
50 | GBA_SWI_MUSIC_PLAYER_OPEN = 0x20,
51 | GBA_SWI_MUSIC_PLAYER_START = 0x21,
52 | GBA_SWI_MUSIC_PLAYER_STOP = 0x22,
53 | GBA_SWI_MUSIC_PLAYER_CONTINUE = 0x23,
54 | GBA_SWI_MUSIC_PLAYER_FADE_OUT = 0x24,
55 | GBA_SWI_MULTI_BOOT = 0x25,
56 | GBA_SWI_HARD_RESET = 0x26,
57 | GBA_SWI_CUSTOM_HALT = 0x27,
58 | GBA_SWI_SOUND_DRIVER_VSYNC_OFF = 0x28,
59 | GBA_SWI_SOUND_DRIVER_VSYNC_ON = 0x29,
60 | GBA_SWI_SOUND_DRIVER_GET_JUMP_LIST = 0x2A,
61 | };
62 |
63 | struct ARMCore;
64 | void GBASwi16(struct ARMCore* cpu, int immediate);
65 | void GBASwi32(struct ARMCore* cpu, int immediate);
66 |
67 | uint32_t GBAChecksum(uint32_t* memory, size_t size);
68 | extern const uint32_t GBA_BIOS_CHECKSUM;
69 | extern const uint32_t GBA_DS_BIOS_CHECKSUM;
70 |
71 | CXX_GUARD_END
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/cart/matrix.h:
--------------------------------------------------------------------------------
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 GBA_MATRIX_H
7 | #define GBA_MATRIX_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #define GBA_MATRIX_MAPPINGS_MAX 16
14 |
15 | struct GBAMatrix {
16 | uint32_t cmd;
17 | uint32_t paddr;
18 | uint32_t vaddr;
19 | uint32_t size;
20 |
21 | uint32_t mappings[GBA_MATRIX_MAPPINGS_MAX];
22 | };
23 |
24 | struct GBA;
25 | void GBAMatrixReset(struct GBA*);
26 | void GBAMatrixWrite(struct GBA*, uint32_t address, uint32_t value);
27 | void GBAMatrixWrite16(struct GBA*, uint32_t address, uint16_t value);
28 |
29 | struct GBASerializedState;
30 | void GBAMatrixSerialize(const struct GBA* memory, struct GBASerializedState* state);
31 | void GBAMatrixDeserialize(struct GBA* memory, const struct GBASerializedState* state);
32 |
33 | CXX_GUARD_END
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/cart/vfame.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2016 taizou
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 |
7 | // Support for copy protected unlicensed games from the company Vast Fame
8 |
9 | #ifndef GBA_VFAME_H
10 | #define GBA_VFAME_H
11 |
12 | #include
13 |
14 | CXX_GUARD_START
15 |
16 | enum GBAVFameCartType {
17 | VFAME_NO = 0,
18 | VFAME_STANDARD = 1,
19 | VFAME_GEORGE = 2
20 | };
21 |
22 | struct GBAVFameCart {
23 | enum GBAVFameCartType cartType;
24 | int sramMode;
25 | int romMode;
26 | int8_t writeSequence[5];
27 | bool acceptingModeChange;
28 | };
29 |
30 | void GBAVFameInit(struct GBAVFameCart* cart);
31 | void GBAVFameDetect(struct GBAVFameCart* cart, uint32_t* rom, size_t romSize);
32 | void GBAVFameSramWrite(struct GBAVFameCart* cart, uint32_t address, uint8_t value, uint8_t* sramData);
33 | uint32_t GBAVFameModifyRomAddress(struct GBAVFameCart* cart, uint32_t address, size_t romSize);
34 | uint32_t GBAVFameGetPatternValue(uint32_t address, int bits);
35 |
36 | CXX_GUARD_END
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/dma.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GBA_DMA_H
7 | #define GBA_DMA_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | enum GBADMAControl {
16 | GBA_DMA_INCREMENT = 0,
17 | GBA_DMA_DECREMENT = 1,
18 | GBA_DMA_FIXED = 2,
19 | GBA_DMA_INCREMENT_RELOAD = 3
20 | };
21 |
22 | enum GBADMATiming {
23 | GBA_DMA_TIMING_NOW = 0,
24 | GBA_DMA_TIMING_VBLANK = 1,
25 | GBA_DMA_TIMING_HBLANK = 2,
26 | GBA_DMA_TIMING_CUSTOM = 3
27 | };
28 |
29 | DECL_BITFIELD(GBADMARegister, uint16_t);
30 | DECL_BITS(GBADMARegister, DestControl, 5, 2);
31 | DECL_BITS(GBADMARegister, SrcControl, 7, 2);
32 | DECL_BIT(GBADMARegister, Repeat, 9);
33 | DECL_BIT(GBADMARegister, Width, 10);
34 | DECL_BIT(GBADMARegister, DRQ, 11);
35 | DECL_BITS(GBADMARegister, Timing, 12, 2);
36 | DECL_BIT(GBADMARegister, DoIRQ, 14);
37 | DECL_BIT(GBADMARegister, Enable, 15);
38 |
39 | mLOG_DECLARE_CATEGORY(GBA_DMA);
40 |
41 | struct GBADMA {
42 | GBADMARegister reg;
43 |
44 | uint32_t source;
45 | uint32_t dest;
46 | int32_t count;
47 | uint32_t nextSource;
48 | uint32_t nextDest;
49 | int32_t nextCount;
50 | uint32_t when;
51 | };
52 |
53 | struct GBA;
54 | void GBADMAInit(struct GBA* gba);
55 | void GBADMAReset(struct GBA* gba);
56 |
57 | uint32_t GBADMAWriteSAD(struct GBA* gba, int dma, uint32_t address);
58 | uint32_t GBADMAWriteDAD(struct GBA* gba, int dma, uint32_t address);
59 | void GBADMAWriteCNT_LO(struct GBA* gba, int dma, uint16_t count);
60 | uint16_t GBADMAWriteCNT_HI(struct GBA* gba, int dma, uint16_t control);
61 |
62 | struct GBADMA;
63 | void GBADMASchedule(struct GBA* gba, int number, struct GBADMA* info);
64 | void GBADMARunHblank(struct GBA* gba, int32_t cycles);
65 | void GBADMARunVblank(struct GBA* gba, int32_t cycles);
66 | void GBADMARunDisplayStart(struct GBA* gba, int32_t cycles);
67 | void GBADMAUpdate(struct GBA* gba);
68 |
69 | CXX_GUARD_END
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/extra/audio-mixer.h:
--------------------------------------------------------------------------------
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 GBA_AUDIO_MIXER_H
7 | #define GBA_AUDIO_MIXER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | void GBAAudioMixerCreate(struct GBAAudioMixer* mixer);
16 |
17 | CXX_GUARD_END
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/extra/cli.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_CLI_H
7 | #define GBA_CLI_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct mCore;
16 |
17 | struct GBACLIDebugger {
18 | struct CLIDebuggerSystem d;
19 |
20 | struct mCore* core;
21 |
22 | bool frameAdvance;
23 | bool inVblank;
24 | };
25 |
26 | struct GBACLIDebugger* GBACLIDebuggerCreate(struct mCore*);
27 |
28 | CXX_GUARD_END
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/input.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GBA_INPUT_H
7 | #define GBA_INPUT_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | extern MGBA_EXPORT const struct mInputPlatformInfo GBAInputInfo;
16 |
17 | enum GBAKey {
18 | GBA_KEY_A = 0,
19 | GBA_KEY_B = 1,
20 | GBA_KEY_SELECT = 2,
21 | GBA_KEY_START = 3,
22 | GBA_KEY_RIGHT = 4,
23 | GBA_KEY_LEFT = 5,
24 | GBA_KEY_UP = 6,
25 | GBA_KEY_DOWN = 7,
26 | GBA_KEY_R = 8,
27 | GBA_KEY_L = 9,
28 | GBA_KEY_MAX,
29 | GBA_KEY_NONE = -1
30 | };
31 |
32 | CXX_GUARD_END
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/overrides.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_OVERRIDES_H
7 | #define GBA_OVERRIDES_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | #define IDLE_LOOP_NONE 0xFFFFFFFF
16 |
17 | struct GBACartridgeOverride {
18 | char id[4];
19 | enum SavedataType savetype;
20 | int hardware;
21 | uint32_t idleLoop;
22 | bool mirroring;
23 | bool vbaBugCompat;
24 | };
25 |
26 | struct Configuration;
27 | bool GBAOverrideFind(const struct Configuration*, struct GBACartridgeOverride* override);
28 | void GBAOverrideSave(struct Configuration*, const struct GBACartridgeOverride* override);
29 |
30 | struct GBA;
31 | void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*);
32 | void GBAOverrideApplyDefaults(struct GBA*, const struct Configuration*);
33 |
34 | CXX_GUARD_END
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/renderers/cache-set.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GBA_CACHE_SET_H
7 | #define GBA_CACHE_SET_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct GBAVideo;
14 | struct mCacheSet;
15 |
16 | void GBAVideoCacheInit(struct mCacheSet* cache);
17 | void GBAVideoCacheAssociate(struct mCacheSet* cache, struct GBAVideo* video);
18 | void GBAVideoCacheWriteVideoRegister(struct mCacheSet* cache, uint32_t address, uint16_t value);
19 |
20 | CXX_GUARD_END
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/renderers/common.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 GBA_RENDERER_COMMON_H
7 | #define GBA_RENDERER_COMMON_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | struct GBAVideoRendererSprite {
16 | struct GBAObj obj;
17 | int16_t y;
18 | int16_t endY;
19 | int16_t cycles;
20 | int8_t index;
21 | };
22 |
23 | int GBAVideoRendererCleanOAM(struct GBAObj* oam, struct GBAVideoRendererSprite* sprites, int offsetY);
24 |
25 | CXX_GUARD_END
26 |
27 | #endif
--------------------------------------------------------------------------------
/include/mgba/internal/gba/renderers/proxy.h:
--------------------------------------------------------------------------------
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 GBA_VIDEO_PROXY_H
7 | #define GBA_VIDEO_PROXY_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | struct GBAVideoProxyRenderer {
17 | struct GBAVideoRenderer d;
18 | struct GBAVideoRenderer* backend;
19 | struct mVideoLogger* logger;
20 | };
21 |
22 | void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct GBAVideoRenderer* backend);
23 | void GBAVideoProxyRendererShim(struct GBAVideo* video, struct GBAVideoProxyRenderer* renderer);
24 | void GBAVideoProxyRendererUnshim(struct GBAVideo* video, struct GBAVideoProxyRenderer* renderer);
25 |
26 | CXX_GUARD_END
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/sharkport.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2021 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 GBA_SHARKPORT_H
7 | #define GBA_SHARKPORT_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct GBA;
14 | struct VFile;
15 |
16 | int GBASavedataSharkPortPayloadSize(struct VFile* vf);
17 | void* GBASavedataSharkPortGetPayload(struct VFile* vf, size_t* size, uint8_t* header, bool testChecksum);
18 | bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChecksum);
19 | bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf);
20 |
21 | int GBASavedataGSVPayloadSize(struct VFile* vf);
22 | void* GBASavedataGSVGetPayload(struct VFile* vf, size_t* size, uint8_t* ident, bool testChecksum);
23 | bool GBASavedataImportGSV(struct GBA* gba, struct VFile* vf, bool testChecksum);
24 |
25 | CXX_GUARD_END
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/sio.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_SIO_H
7 | #define GBA_SIO_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | #define MAX_GBAS 4
18 |
19 | extern const int GBASIOCyclesPerTransfer[4][MAX_GBAS];
20 |
21 | mLOG_DECLARE_CATEGORY(GBA_SIO);
22 |
23 | enum {
24 | RCNT_INITIAL = -0x8000
25 | };
26 |
27 | enum {
28 | JOY_CMD_RESET = 0xFF,
29 | JOY_CMD_POLL = 0x00,
30 | JOY_CMD_TRANS = 0x14,
31 | JOY_CMD_RECV = 0x15,
32 |
33 | JOYSTAT_TRANS = 8,
34 | JOYSTAT_RECV = 2,
35 |
36 | JOYCNT_RESET = 1,
37 | JOYCNT_RECV = 2,
38 | JOYCNT_TRANS = 4,
39 | };
40 |
41 | DECL_BITFIELD(GBASIONormal, uint16_t);
42 | DECL_BIT(GBASIONormal, Sc, 0);
43 | DECL_BIT(GBASIONormal, InternalSc, 1);
44 | DECL_BIT(GBASIONormal, Si, 2);
45 | DECL_BIT(GBASIONormal, IdleSo, 3);
46 | DECL_BIT(GBASIONormal, Start, 7);
47 | DECL_BIT(GBASIONormal, Length, 12);
48 | DECL_BIT(GBASIONormal, Irq, 14);
49 | DECL_BITFIELD(GBASIOMultiplayer, uint16_t);
50 | DECL_BITS(GBASIOMultiplayer, Baud, 0, 2);
51 | DECL_BIT(GBASIOMultiplayer, Slave, 2);
52 | DECL_BIT(GBASIOMultiplayer, Ready, 3);
53 | DECL_BITS(GBASIOMultiplayer, Id, 4, 2);
54 | DECL_BIT(GBASIOMultiplayer, Error, 6);
55 | DECL_BIT(GBASIOMultiplayer, Busy, 7);
56 | DECL_BIT(GBASIOMultiplayer, Irq, 14);
57 |
58 | struct GBASIODriverSet {
59 | struct GBASIODriver* normal;
60 | struct GBASIODriver* multiplayer;
61 | struct GBASIODriver* joybus;
62 | };
63 |
64 | struct GBASIO {
65 | struct GBA* p;
66 |
67 | enum GBASIOMode mode;
68 | struct GBASIODriverSet drivers;
69 | struct GBASIODriver* activeDriver;
70 |
71 | uint16_t rcnt;
72 | uint16_t siocnt;
73 |
74 | struct GBASIOPlayer gbp;
75 | };
76 |
77 | void GBASIOInit(struct GBASIO* sio);
78 | void GBASIODeinit(struct GBASIO* sio);
79 | void GBASIOReset(struct GBASIO* sio);
80 |
81 | void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
82 | void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
83 |
84 | void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
85 | void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
86 | uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value);
87 |
88 | int GBASIOJOYSendCommand(struct GBASIODriver* sio, enum GBASIOJOYCommand command, uint8_t* data);
89 |
90 | CXX_GUARD_END
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/sio/dolphin.h:
--------------------------------------------------------------------------------
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 SIO_DOLPHIN_H
7 | #define SIO_DOLPHIN_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 |
16 | #include
17 |
18 | extern const uint16_t DOLPHIN_CLOCK_PORT;
19 | extern const uint16_t DOLPHIN_DATA_PORT;
20 |
21 | struct GBASIODolphin {
22 | struct GBASIODriver d;
23 | struct mTimingEvent event;
24 |
25 | Socket data;
26 | Socket clock;
27 |
28 | int32_t clockSlice;
29 | int state;
30 | bool active;
31 | };
32 |
33 | void GBASIODolphinCreate(struct GBASIODolphin*);
34 | void GBASIODolphinDestroy(struct GBASIODolphin*);
35 |
36 | bool GBASIODolphinConnect(struct GBASIODolphin*, const struct Address* address, short dataPort, short clockPort);
37 | bool GBASIODolphinIsConnected(struct GBASIODolphin*);
38 |
39 | CXX_GUARD_END
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/sio/gbp.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2021 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 GBA_GBP_H
7 | #define GBA_GBP_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct GBASIOPlayer;
14 | struct GBASIOPlayerKeyCallback {
15 | struct mKeyCallback d;
16 | struct GBASIOPlayer* p;
17 | };
18 |
19 | struct GBASIOPlayer {
20 | struct GBASIODriver d;
21 | struct GBA* p;
22 | unsigned inputsPosted;
23 | int txPosition;
24 | struct mTimingEvent event;
25 | struct GBASIOPlayerKeyCallback callback;
26 | bool oldOpposingDirections;
27 | struct mKeyCallback* oldCallback;
28 | };
29 |
30 | void GBASIOPlayerInit(struct GBASIOPlayer* gbp);
31 | void GBASIOPlayerReset(struct GBASIOPlayer* gbp);
32 |
33 | struct GBAVideo;
34 | void GBASIOPlayerUpdate(struct GBA* gba);
35 | bool GBASIOPlayerCheckScreen(const struct GBAVideo* video);
36 |
37 | CXX_GUARD_END
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/sio/lockstep.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_SIO_LOCKSTEP_H
7 | #define GBA_SIO_LOCKSTEP_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | struct GBASIOLockstep {
18 | struct mLockstep d;
19 | struct GBASIOLockstepNode* players[MAX_GBAS];
20 | int attachedMulti;
21 | int attachedNormal;
22 |
23 | uint16_t multiRecv[MAX_GBAS];
24 | uint32_t normalRecv[MAX_GBAS];
25 | };
26 |
27 | struct GBASIOLockstepNode {
28 | struct GBASIODriver d;
29 | struct GBASIOLockstep* p;
30 | struct mTimingEvent event;
31 |
32 | volatile int32_t nextEvent;
33 | int32_t eventDiff;
34 | bool normalSO;
35 | int id;
36 | enum GBASIOMode mode;
37 | bool transferFinished;
38 | #ifndef NDEBUG
39 | int transferId;
40 | enum mLockstepPhase phase;
41 | #endif
42 | };
43 |
44 | void GBASIOLockstepInit(struct GBASIOLockstep*);
45 |
46 | void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
47 |
48 | bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
49 | void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
50 |
51 | CXX_GUARD_END
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/include/mgba/internal/gba/timer.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 GBA_TIMER_H
7 | #define GBA_TIMER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | DECL_BITFIELD(GBATimerFlags, uint32_t);
16 | DECL_BITS(GBATimerFlags, PrescaleBits, 0, 4);
17 | DECL_BIT(GBATimerFlags, CountUp, 4);
18 | DECL_BIT(GBATimerFlags, DoIrq, 5);
19 | DECL_BIT(GBATimerFlags, Enable, 6);
20 |
21 | struct GBA;
22 | struct GBATimer {
23 | uint16_t reload;
24 | int32_t lastEvent;
25 | struct mTimingEvent event;
26 | GBATimerFlags flags;
27 | };
28 |
29 | void GBATimerInit(struct GBA* gba);
30 | void GBATimerUpdateRegister(struct GBA* gba, int timer, int32_t cyclesLate);
31 | void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
32 | void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
33 |
34 | CXX_GUARD_END
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/include/mgba/internal/script/lua.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2022 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 M_SCRIPT_LUA_H
7 | #define M_SCRIPT_LUA_H
8 | #include
9 |
10 | extern struct mScriptEngine2* const mSCRIPT_ENGINE_LUA;
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/include/mgba/internal/script/socket.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2022 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 M_SCRIPT_SOCKET_H
7 | #define M_SCRIPT_SOCKET_H
8 |
9 | enum mSocketErrorCode {
10 | mSCRIPT_SOCKERR_UNKNOWN_ERROR = -1,
11 | mSCRIPT_SOCKERR_OK = 0,
12 | mSCRIPT_SOCKERR_AGAIN,
13 | mSCRIPT_SOCKERR_ADDRESS_IN_USE,
14 | mSCRIPT_SOCKERR_CONNECTION_REFUSED,
15 | mSCRIPT_SOCKERR_DENIED,
16 | mSCRIPT_SOCKERR_FAILED,
17 | mSCRIPT_SOCKERR_NETWORK_UNREACHABLE,
18 | mSCRIPT_SOCKERR_NOT_FOUND,
19 | mSCRIPT_SOCKERR_NO_DATA,
20 | mSCRIPT_SOCKERR_OUT_OF_MEMORY,
21 | mSCRIPT_SOCKERR_TIMEOUT,
22 | mSCRIPT_SOCKERR_UNSUPPORTED,
23 | };
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/include/mgba/internal/sm83/debugger/cli-debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 SM83_CLI_DEBUGGER_H
7 | #define SM83_CLI_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct CLIDebuggerSystem;
14 | void SM83CLIDebuggerCreate(struct CLIDebuggerSystem* debugger);
15 |
16 | CXX_GUARD_END
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/include/mgba/internal/sm83/debugger/debugger.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 SM83_DEBUGGER_H
7 | #define SM83_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #include
14 |
15 | #include
16 |
17 | struct SM83Segment {
18 | uint16_t start;
19 | uint16_t end;
20 | const char* name;
21 | };
22 |
23 | struct CLIDebuggerSystem;
24 | struct SM83Debugger {
25 | struct mDebuggerPlatform d;
26 | struct SM83Core* cpu;
27 |
28 | struct mBreakpointList breakpoints;
29 | struct mWatchpointList watchpoints;
30 | struct SM83Memory originalMemory;
31 |
32 | ssize_t nextId;
33 |
34 | const struct SM83Segment* segments;
35 |
36 | void (*printStatus)(struct CLIDebuggerSystem*);
37 | };
38 |
39 | struct mDebuggerPlatform* SM83DebuggerPlatformCreate(void);
40 |
41 | CXX_GUARD_END
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/include/mgba/internal/sm83/debugger/memory-debugger.h:
--------------------------------------------------------------------------------
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 SM83_MEMORY_DEBUGGER_H
7 | #define SM83_MEMORY_DEBUGGER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct SM83Debugger;
14 |
15 | void SM83DebuggerInstallMemoryShim(struct SM83Debugger* debugger);
16 | void SM83DebuggerRemoveMemoryShim(struct SM83Debugger* debugger);
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/include/mgba/internal/sm83/decoder.h:
--------------------------------------------------------------------------------
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 SM83_DECODER_H
7 | #define SM83_DECODER_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | enum SM83Condition {
14 | SM83_COND_NONE = 0x0,
15 | SM83_COND_C = 0x1,
16 | SM83_COND_Z = 0x2,
17 | SM83_COND_NC = 0x3,
18 | SM83_COND_NZ = 0x4
19 | };
20 |
21 | enum SM83Mnemonic {
22 | SM83_MN_ILL = 0,
23 | SM83_MN_ADC,
24 | SM83_MN_ADD,
25 | SM83_MN_AND,
26 | SM83_MN_BIT,
27 | SM83_MN_CALL,
28 | SM83_MN_CCF,
29 | SM83_MN_CP,
30 | SM83_MN_CPL,
31 | SM83_MN_DAA,
32 | SM83_MN_DEC,
33 | SM83_MN_DI,
34 | SM83_MN_EI,
35 | SM83_MN_HALT,
36 | SM83_MN_INC,
37 | SM83_MN_JP,
38 | SM83_MN_JR,
39 | SM83_MN_LD,
40 | SM83_MN_NOP,
41 | SM83_MN_OR,
42 | SM83_MN_POP,
43 | SM83_MN_PUSH,
44 | SM83_MN_RES,
45 | SM83_MN_RET,
46 | SM83_MN_RETI,
47 | SM83_MN_RL,
48 | SM83_MN_RLC,
49 | SM83_MN_RR,
50 | SM83_MN_RRC,
51 | SM83_MN_RST,
52 | SM83_MN_SBC,
53 | SM83_MN_SCF,
54 | SM83_MN_SET,
55 | SM83_MN_SLA,
56 | SM83_MN_SRA,
57 | SM83_MN_SRL,
58 | SM83_MN_STOP,
59 | SM83_MN_SUB,
60 | SM83_MN_SWAP,
61 | SM83_MN_XOR,
62 |
63 | SM83_MN_MAX
64 | };
65 |
66 | enum SM83Register {
67 | SM83_REG_B = 1,
68 | SM83_REG_C,
69 | SM83_REG_D,
70 | SM83_REG_E,
71 | SM83_REG_H,
72 | SM83_REG_L,
73 | SM83_REG_A,
74 | SM83_REG_F,
75 | SM83_REG_BC,
76 | SM83_REG_DE,
77 | SM83_REG_HL,
78 | SM83_REG_AF,
79 |
80 | SM83_REG_SP,
81 | SM83_REG_PC
82 | };
83 |
84 | enum {
85 | SM83_OP_FLAG_IMPLICIT = 1,
86 | SM83_OP_FLAG_MEMORY = 2,
87 | SM83_OP_FLAG_INCREMENT = 4,
88 | SM83_OP_FLAG_DECREMENT = 8,
89 | SM83_OP_FLAG_RELATIVE = 16,
90 | };
91 |
92 | struct SM83Operand {
93 | uint8_t reg;
94 | uint8_t flags;
95 | uint16_t immediate;
96 | };
97 |
98 | struct SM83InstructionInfo {
99 | uint8_t opcode[3];
100 | uint8_t opcodeSize;
101 | struct SM83Operand op1;
102 | struct SM83Operand op2;
103 | unsigned mnemonic;
104 | unsigned condition;
105 | };
106 |
107 | size_t SM83Decode(uint8_t opcode, struct SM83InstructionInfo* info);
108 | int SM83Disassemble(struct SM83InstructionInfo* info, uint16_t pc, char* buffer, int blen);
109 |
110 | CXX_GUARD_END
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/include/mgba/internal/sm83/isa-sm83.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 ISA_SM83_H
7 | #define ISA_SM83_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | struct SM83Core;
14 |
15 | typedef void (*SM83Instruction)(struct SM83Core*);
16 | extern const SM83Instruction _sm83InstructionTable[0x100];
17 |
18 | CXX_GUARD_END
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/mGBA.xcodeproj/TemplateIcon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OpenEmu/mGBA-Core/3829cdb34fd90efff2d1240dd037c075f2cf2e38/mGBA.xcodeproj/TemplateIcon.icns
--------------------------------------------------------------------------------
/src/arm/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include(ExportDirectory)
2 | set(SOURCE_FILES
3 | arm.c
4 | decoder-arm.c
5 | decoder.c
6 | decoder-thumb.c
7 | isa-arm.c
8 | isa-thumb.c)
9 |
10 | set(DEBUGGER_FILES
11 | debugger/cli-debugger.c
12 | debugger/debugger.c
13 | debugger/memory-debugger.c)
14 |
15 | source_group("ARM core" FILES ${SOURCE_FILES})
16 | source_group("ARM debugger" FILES ${DEBUGGER_FILES})
17 |
18 | export_directory(ARM SOURCE_FILES)
19 | export_directory(ARM_DEBUGGER DEBUGGER_FILES)
--------------------------------------------------------------------------------
/src/core/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include(ExportDirectory)
2 | set(SOURCE_FILES
3 | bitmap-cache.c
4 | cache-set.c
5 | cheats.c
6 | config.c
7 | core.c
8 | directories.c
9 | input.c
10 | interface.c
11 | library.c
12 | lockstep.c
13 | log.c
14 | map-cache.c
15 | mem-search.c
16 | rewind.c
17 | serialize.c
18 | sync.c
19 | thread.c
20 | tile-cache.c
21 | timing.c)
22 |
23 | set(TEST_FILES
24 | test/core.c)
25 |
26 | if(ENABLE_SCRIPTING)
27 | set(SCRIPTING_FILES
28 | scripting.c)
29 |
30 | if(USE_LUA)
31 | list(APPEND TEST_FILES
32 | test/scripting.c)
33 | endif()
34 | endif()
35 |
36 | source_group("mCore" FILES ${SOURCE_FILES})
37 | source_group("mCore scripting" FILES ${SCRIPTING_FILES})
38 | source_group("mCore tests" FILES ${TEST_FILES})
39 |
40 | export_directory(CORE SOURCE_FILES)
41 | export_directory(CORE_SCRIPT SCRIPTING_FILES)
42 | export_directory(CORE_TEST TEST_FILES)
43 |
--------------------------------------------------------------------------------
/src/core/cache-set.c:
--------------------------------------------------------------------------------
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 | #include
7 |
8 | DEFINE_VECTOR(mMapCacheSet, struct mMapCache);
9 | DEFINE_VECTOR(mBitmapCacheSet, struct mBitmapCache);
10 | DEFINE_VECTOR(mTileCacheSet, struct mTileCache);
11 |
12 | void mCacheSetInit(struct mCacheSet* cache, size_t nMaps, size_t nBitmaps, size_t nTiles) {
13 | mMapCacheSetInit(&cache->maps, nMaps);
14 | mMapCacheSetResize(&cache->maps, nMaps);
15 | mBitmapCacheSetInit(&cache->bitmaps, nBitmaps);
16 | mBitmapCacheSetResize(&cache->bitmaps, nBitmaps);
17 | mTileCacheSetInit(&cache->tiles, nTiles);
18 | mTileCacheSetResize(&cache->tiles, nTiles);
19 |
20 | size_t i;
21 | for (i = 0; i < nMaps; ++i) {
22 | mMapCacheInit(mMapCacheSetGetPointer(&cache->maps, i));
23 | }
24 | for (i = 0; i < nBitmaps; ++i) {
25 | mBitmapCacheInit(mBitmapCacheSetGetPointer(&cache->bitmaps, i));
26 | }
27 | for (i = 0; i < nTiles; ++i) {
28 | mTileCacheInit(mTileCacheSetGetPointer(&cache->tiles, i));
29 | }
30 | }
31 |
32 | void mCacheSetDeinit(struct mCacheSet* cache) {
33 | size_t i;
34 | for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
35 | mMapCacheDeinit(mMapCacheSetGetPointer(&cache->maps, i));
36 | }
37 | mMapCacheSetDeinit(&cache->maps);
38 | for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
39 | mBitmapCacheDeinit(mBitmapCacheSetGetPointer(&cache->bitmaps, i));
40 | }
41 | mBitmapCacheSetDeinit(&cache->bitmaps);
42 | for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
43 | mTileCacheDeinit(mTileCacheSetGetPointer(&cache->tiles, i));
44 | }
45 | mTileCacheSetDeinit(&cache->tiles);
46 | }
47 |
48 | void mCacheSetAssignVRAM(struct mCacheSet* cache, void* vram) {
49 | size_t i;
50 | for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
51 | mMapCacheSetGetPointer(&cache->maps, i)->vram = vram;
52 | }
53 | for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
54 | mBitmapCacheSetGetPointer(&cache->bitmaps, i)->vram = vram;
55 | }
56 | for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
57 | struct mTileCache* tileCache = mTileCacheSetGetPointer(&cache->tiles, i);
58 | tileCache->vram = (void*) ((uintptr_t) vram + tileCache->tileBase);
59 | }
60 | }
61 |
62 | void mCacheSetWriteVRAM(struct mCacheSet* cache, uint32_t address) {
63 | size_t i;
64 | for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
65 | mMapCacheWriteVRAM(mMapCacheSetGetPointer(&cache->maps, i), address);
66 | }
67 | for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
68 | mBitmapCacheWriteVRAM(mBitmapCacheSetGetPointer(&cache->bitmaps, i), address);
69 | }
70 | for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
71 | mTileCacheWriteVRAM(mTileCacheSetGetPointer(&cache->tiles, i), address);
72 | }
73 | }
74 |
75 | void mCacheSetWritePalette(struct mCacheSet* cache, uint32_t entry, color_t color) {
76 | size_t i;
77 | for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
78 | mBitmapCacheWritePalette(mBitmapCacheSetGetPointer(&cache->bitmaps, i), entry, color);
79 | }
80 | for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
81 | mTileCacheWritePalette(mTileCacheSetGetPointer(&cache->tiles, i), entry, color);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/core/flags.h.in:
--------------------------------------------------------------------------------
1 | #ifndef FLAGS_H
2 | #define FLAGS_H
3 |
4 | #ifndef MINIMAL_CORE
5 | #cmakedefine MINIMAL_CORE @MINIMAL_CORE@
6 | #endif
7 |
8 | // BUILD flags
9 |
10 | #ifndef BUILD_GL
11 | #cmakedefine BUILD_GL
12 | #endif
13 |
14 | #ifndef BUILD_GLES2
15 | #cmakedefine BUILD_GLES2
16 | #endif
17 |
18 | #ifndef BUILD_GLES3
19 | #cmakedefine BUILD_GLES3
20 | #endif
21 |
22 | // Miscellaneous flags
23 |
24 | #ifndef COLOR_16_BIT
25 | #cmakedefine COLOR_16_BIT
26 | #endif
27 |
28 | #ifndef COLOR_5_6_5
29 | #cmakedefine COLOR_5_6_5
30 | #endif
31 |
32 | #ifndef DISABLE_THREADING
33 | #cmakedefine DISABLE_THREADING
34 | #endif
35 |
36 | #ifndef FIXED_ROM_BUFFER
37 | #cmakedefine FIXED_ROM_BUFFER
38 | #endif
39 |
40 | // M_CORE flags
41 |
42 | #ifndef M_CORE_GBA
43 | #cmakedefine M_CORE_GBA
44 | #endif
45 |
46 | #ifndef M_CORE_GB
47 | #cmakedefine M_CORE_GB
48 | #endif
49 |
50 | // ENABLE flags
51 |
52 | #ifndef ENABLE_SCRIPTING
53 | #cmakedefine ENABLE_SCRIPTING
54 | #endif
55 |
56 | // USE flags
57 |
58 | #ifndef USE_DEBUGGERS
59 | #cmakedefine USE_DEBUGGERS
60 | #endif
61 |
62 | #ifndef USE_EDITLINE
63 | #cmakedefine USE_EDITLINE
64 | #endif
65 |
66 | #ifndef USE_ELF
67 | #cmakedefine USE_ELF
68 | #endif
69 |
70 | #ifndef USE_EPOXY
71 | #cmakedefine USE_EPOXY
72 | #endif
73 |
74 | #ifndef USE_FFMPEG
75 | #cmakedefine USE_FFMPEG
76 | #endif
77 |
78 | #ifndef USE_GDB_STUB
79 | #cmakedefine USE_GDB_STUB
80 | #endif
81 |
82 | #ifndef USE_LIBAV
83 | #cmakedefine USE_LIBAV
84 | #endif
85 |
86 | #ifndef USE_LIBAVRESAMPLE
87 | #cmakedefine USE_LIBAVRESAMPLE
88 | #endif
89 |
90 | #ifndef USE_LIBSWRESAMPLE
91 | #cmakedefine USE_LIBSWRESAMPLE
92 | #endif
93 |
94 | #ifndef USE_LIBZIP
95 | #cmakedefine USE_LIBZIP
96 | #endif
97 |
98 | #ifndef USE_LZMA
99 | #cmakedefine USE_LZMA
100 | #endif
101 |
102 | #ifndef USE_MINIZIP
103 | #cmakedefine USE_MINIZIP
104 | #endif
105 |
106 | #ifndef USE_PNG
107 | #cmakedefine USE_PNG
108 | #endif
109 |
110 | #ifndef USE_PTHREADS
111 | #cmakedefine USE_PTHREADS
112 | #endif
113 |
114 | #ifndef USE_SQLITE3
115 | #cmakedefine USE_SQLITE3
116 | #endif
117 |
118 | #ifndef USE_ZLIB
119 | #cmakedefine USE_ZLIB
120 | #endif
121 |
122 | // HAVE flags
123 |
124 | #ifndef HAVE_POPCOUNT32
125 | #cmakedefine HAVE_POPCOUNT32
126 | #endif
127 |
128 | #endif
129 |
--------------------------------------------------------------------------------
/src/core/lockstep.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include
7 |
8 | void mLockstepInit(struct mLockstep* lockstep) {
9 | lockstep->attached = 0;
10 | lockstep->transferActive = 0;
11 | #ifndef NDEBUG
12 | lockstep->transferId = 0;
13 | #endif
14 | lockstep->lock = NULL;
15 | lockstep->unlock = NULL;
16 | }
17 |
18 | void mLockstepDeinit(struct mLockstep* lockstep) {
19 | UNUSED(lockstep);
20 | }
21 |
22 | // TODO: Migrate nodes
23 |
--------------------------------------------------------------------------------
/src/core/test/core.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include "util/test/suite.h"
7 |
8 | #include
9 | #include
10 |
11 | #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
12 | M_TEST_DEFINE(findNullPath) {
13 | struct mCore* core = mCoreFind(NULL);
14 | assert_null(core);
15 | }
16 | #endif
17 |
18 | M_TEST_DEFINE(findNullVF) {
19 | struct mCore* core = mCoreFindVF(NULL);
20 | assert_null(core);
21 | }
22 |
23 | M_TEST_DEFINE(findEmpty) {
24 | struct VFile* vf = VFileMemChunk(NULL, 0);
25 | assert_non_null(vf);
26 | struct mCore* core = mCoreFindVF(vf);
27 | assert_null(core);
28 | vf->close(vf);
29 | }
30 |
31 | M_TEST_SUITE_DEFINE(mCore,
32 | #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
33 | cmocka_unit_test(findNullPath),
34 | #endif
35 | cmocka_unit_test(findNullVF),
36 | cmocka_unit_test(findEmpty))
37 |
--------------------------------------------------------------------------------
/src/core/version.c.in:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include
7 |
8 | MGBA_EXPORT const char* const gitCommit = "${GIT_COMMIT}";
9 | MGBA_EXPORT const char* const gitCommitShort = "${GIT_COMMIT_SHORT}";
10 | MGBA_EXPORT const char* const gitBranch = "${GIT_BRANCH}";
11 | MGBA_EXPORT const int gitRevision = ${GIT_REV};
12 | MGBA_EXPORT const char* const binaryName = "${BINARY_NAME}";
13 | MGBA_EXPORT const char* const projectName = "${PROJECT_NAME}";
14 | MGBA_EXPORT const char* const projectVersion = "${VERSION_STRING}";
15 |
--------------------------------------------------------------------------------
/src/gb/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include(ExportDirectory)
2 | set(SOURCE_FILES
3 | audio.c
4 | cheats.c
5 | core.c
6 | gb.c
7 | input.c
8 | io.c
9 | mbc.c
10 | memory.c
11 | overrides.c
12 | serialize.c
13 | renderers/cache-set.c
14 | renderers/software.c
15 | sio.c
16 | timer.c
17 | video.c)
18 |
19 | set(SIO_FILES
20 | sio/lockstep.c
21 | sio/printer.c)
22 |
23 | set(EXTRA_FILES
24 | extra/proxy.c)
25 |
26 | set(DEBUGGER_FILES
27 | debugger/cli.c
28 | debugger/debugger.c
29 | debugger/symbols.c)
30 |
31 | set(TEST_FILES
32 | test/core.c
33 | test/gbx.c
34 | test/mbc.c
35 | test/memory.c
36 | test/rtc.c)
37 |
38 | source_group("GB board" FILES ${SOURCE_FILES})
39 | source_group("GB extras" FILES ${EXTRA_FILES} ${SIO_FILES})
40 | source_group("GB debugger" FILES ${DEBUGGER_FILES})
41 | source_group("GB tests" FILES ${TEST_FILES})
42 |
43 | export_directory(GB SOURCE_FILES)
44 | export_directory(GB_SIO SIO_FILES)
45 | export_directory(GB_EXTRA EXTRA_FILES)
46 | export_directory(GB_DEBUGGER DEBUGGER_FILES)
47 | export_directory(GB_TEST TEST_FILES)
48 |
--------------------------------------------------------------------------------
/src/gb/debugger/debugger.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | static const struct SM83Segment _GBSegments[] = {
16 | { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM },
17 | { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 },
18 | { 0 }
19 | };
20 |
21 | static const struct SM83Segment _GBCSegments[] = {
22 | { .name = "ROM", .start = GB_BASE_CART_BANK1, .end = GB_BASE_VRAM },
23 | { .name = "RAM", .start = GB_BASE_EXTERNAL_RAM, .end = GB_BASE_WORKING_RAM_BANK0 },
24 | { .name = "WRAM", .start = GB_BASE_WORKING_RAM_BANK1, .end = 0xE000 },
25 | { .name = "VRAM", .start = GB_BASE_VRAM, .end = GB_BASE_EXTERNAL_RAM },
26 | { 0 }
27 | };
28 |
29 | static void _printStatus(struct CLIDebuggerSystem* debugger) {
30 | struct CLIDebuggerBackend* be = debugger->p->backend;
31 | struct GB* gb = debugger->p->d.core->board;
32 | be->printf(be, "IE: %02X IF: %02X IME: %i\n", gb->memory.ie, gb->memory.io[GB_REG_IF], gb->memory.ime);
33 | be->printf(be, "LCDC: %02X STAT: %02X LY: %02X\n", gb->memory.io[GB_REG_LCDC], gb->memory.io[GB_REG_STAT] | 0x80, gb->memory.io[GB_REG_LY]);
34 | be->printf(be, "Next video mode: %i\n", mTimingUntil(&gb->timing, &gb->video.modeEvent) / 4);
35 | }
36 |
37 | struct mDebuggerPlatform* GBDebuggerCreate(struct GB* gb) {
38 | struct SM83Debugger* platform = (struct SM83Debugger*) SM83DebuggerPlatformCreate();
39 | if (gb->model >= GB_MODEL_CGB) {
40 | platform->segments = _GBCSegments;
41 | } else {
42 | platform->segments = _GBSegments;
43 | }
44 | platform->printStatus = _printStatus;
45 | return &platform->d;
46 | }
47 |
--------------------------------------------------------------------------------
/src/gb/debugger/symbols.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | void GBLoadSymbols(struct mDebuggerSymbols* st, struct VFile* vf) {
13 | char line[512];
14 |
15 | while (true) {
16 | ssize_t bytesRead = vf->readline(vf, line, sizeof(line));
17 | if (bytesRead <= 0) {
18 | break;
19 | }
20 | if (line[bytesRead - 1] == '\n') {
21 | line[bytesRead - 1] = '\0';
22 | }
23 | int segment = -1;
24 | uint32_t address = 0;
25 |
26 | uint8_t byte;
27 | const char* buf = line;
28 | while (buf && bytesRead >= 2) {
29 | buf = hex8(buf, &byte);
30 | if (!buf) {
31 | break;
32 | }
33 | address <<= 8;
34 | address += byte;
35 | bytesRead -= 2;
36 |
37 | if (buf[0] == ':') {
38 | segment = address;
39 | address = 0;
40 | ++buf;
41 | }
42 | if (isspace((int) buf[0])) {
43 | break;
44 | }
45 | }
46 | if (!buf || bytesRead < 1) {
47 | continue;
48 | }
49 |
50 | while (isspace((int) buf[0]) && bytesRead > 0) {
51 | --bytesRead;
52 | ++buf;
53 | }
54 |
55 | if (!bytesRead) {
56 | continue;
57 | }
58 |
59 | mDebuggerSymbolAdd(st, buf, address, segment);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/gb/input.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 | #include
7 |
8 | #include
9 |
10 | const struct mInputPlatformInfo GBInputInfo = {
11 | .platformName = "gb",
12 | .keyId = (const char*[]) {
13 | "A",
14 | "B",
15 | "Select",
16 | "Start",
17 | "Right",
18 | "Left",
19 | "Up",
20 | "Down",
21 | },
22 | .nKeys = GB_KEY_MAX,
23 | .hat = {
24 | .up = GB_KEY_UP,
25 | .left = GB_KEY_LEFT,
26 | .down = GB_KEY_DOWN,
27 | .right = GB_KEY_RIGHT
28 | }
29 | };
30 |
--------------------------------------------------------------------------------
/src/gb/sio.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O", "gb.sio");
13 |
14 | const int GBSIOCyclesPerTransfer[2] = {
15 | 512,
16 | 16
17 | };
18 |
19 | void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate);
20 |
21 | void GBSIOInit(struct GBSIO* sio) {
22 | sio->pendingSB = 0xFF;
23 | sio->event.context = sio;
24 | sio->event.name = "GB SIO";
25 | sio->event.callback = _GBSIOProcessEvents;
26 | sio->event.priority = 0x30;
27 |
28 | sio->driver = NULL;
29 | }
30 |
31 | void GBSIOReset(struct GBSIO* sio) {
32 | sio->nextEvent = INT_MAX;
33 | sio->remainingBits = 0;
34 | GBSIOSetDriver(sio, sio->driver);
35 | }
36 |
37 | void GBSIODeinit(struct GBSIO* sio) {
38 | UNUSED(sio);
39 | // Nothing to do yet
40 | }
41 |
42 | void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver) {
43 | if (sio->driver) {
44 | if (sio->driver->deinit) {
45 | sio->driver->deinit(sio->driver);
46 | }
47 | }
48 | if (driver) {
49 | driver->p = sio;
50 |
51 | if (driver->init) {
52 | if (!driver->init(driver)) {
53 | driver->deinit(driver);
54 | mLOG(GB_SIO, ERROR, "Could not initialize SIO driver");
55 | return;
56 | }
57 | }
58 | }
59 | sio->driver = driver;
60 | }
61 |
62 | void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate) {
63 | UNUSED(cyclesLate);
64 | struct GBSIO* sio = context;
65 | bool doIRQ = false;
66 | if (sio->remainingBits) {
67 | doIRQ = true;
68 | --sio->remainingBits;
69 | sio->p->memory.io[GB_REG_SB] &= ~(128 >> sio->remainingBits);
70 | sio->p->memory.io[GB_REG_SB] |= sio->pendingSB & (128 >> sio->remainingBits);
71 | }
72 | if (!sio->remainingBits) {
73 | sio->p->memory.io[GB_REG_SC] = GBRegisterSCClearEnable(sio->p->memory.io[GB_REG_SC]);
74 | if (doIRQ) {
75 | sio->p->memory.io[GB_REG_IF] |= (1 << GB_IRQ_SIO);
76 | GBUpdateIRQs(sio->p);
77 | sio->pendingSB = 0xFF;
78 | }
79 | } else {
80 | mTimingSchedule(timing, &sio->event, sio->period * (2 - sio->p->doubleSpeed));
81 | }
82 | }
83 |
84 | void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb) {
85 | if (!sio->driver) {
86 | return;
87 | }
88 | sio->driver->writeSB(sio->driver, sb);
89 | }
90 |
91 | void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc) {
92 | sio->period = GBSIOCyclesPerTransfer[GBRegisterSCGetClockSpeed(sc)]; // TODO Shift Clock
93 | if (GBRegisterSCIsEnable(sc)) {
94 | if (GBRegisterSCIsShiftClock(sc)) {
95 | mTimingDeschedule(&sio->p->timing, &sio->event);
96 | mTimingSchedule(&sio->p->timing, &sio->event, sio->period * (2 - sio->p->doubleSpeed));
97 | sio->remainingBits = 8;
98 | }
99 | } else {
100 | mTimingDeschedule(&sio->p->timing, &sio->event);
101 | }
102 | if (sio->driver) {
103 | sio->driver->writeSC(sio->driver, sc);
104 | }
105 | }
106 |
107 |
--------------------------------------------------------------------------------
/src/gb/test/core.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include "util/test/suite.h"
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | M_TEST_DEFINE(create) {
14 | struct mCore* core = GBCoreCreate();
15 | assert_non_null(core);
16 | assert_true(core->init(core));
17 | core->deinit(core);
18 | }
19 |
20 | M_TEST_DEFINE(platform) {
21 | struct mCore* core = GBCoreCreate();
22 | assert_non_null(core);
23 | assert_int_equal(core->platform(core), mPLATFORM_GB);
24 | assert_true(core->init(core));
25 | core->deinit(core);
26 | }
27 |
28 | M_TEST_DEFINE(reset) {
29 | struct mCore* core = GBCoreCreate();
30 | assert_non_null(core);
31 | assert_true(core->init(core));
32 | mCoreInitConfig(core, NULL);
33 | core->reset(core);
34 | mCoreConfigDeinit(&core->config);
35 | core->deinit(core);
36 | }
37 |
38 | M_TEST_DEFINE(loadNullROM) {
39 | struct mCore* core = GBCoreCreate();
40 | assert_non_null(core);
41 | assert_true(core->init(core));
42 | mCoreInitConfig(core, NULL);
43 | assert_false(core->loadROM(core, NULL));
44 | core->reset(core);
45 | mCoreConfigDeinit(&core->config);
46 | core->deinit(core);
47 | }
48 |
49 | M_TEST_DEFINE(isROM) {
50 | struct VFile* vf = VFileMemChunk(NULL, 2048);
51 | GBSynthesizeROM(vf);
52 | assert_true(GBIsROM(vf));
53 | struct mCore* core = mCoreFindVF(vf);
54 | assert_non_null(core);
55 | assert_int_equal(core->platform(core), mPLATFORM_GB);
56 | vf->close(vf);
57 | assert_true(core->init(core));
58 |
59 | core->deinit(core);
60 | }
61 |
62 | M_TEST_SUITE_DEFINE(GBCore,
63 | cmocka_unit_test(create),
64 | cmocka_unit_test(platform),
65 | cmocka_unit_test(reset),
66 | cmocka_unit_test(loadNullROM),
67 | cmocka_unit_test(isROM))
68 |
--------------------------------------------------------------------------------
/src/gb/test/memory.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include "util/test/suite.h"
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | M_TEST_SUITE_SETUP(GBMemory) {
15 | struct VFile* vf = VFileMemChunk(NULL, GB_SIZE_CART_BANK0 * 4);
16 | GBSynthesizeROM(vf);
17 | struct mCore* core = GBCoreCreate();
18 | core->init(core);
19 | mCoreInitConfig(core, NULL);
20 | core->loadROM(core, vf);
21 | *state = core;
22 | return 0;
23 | }
24 |
25 | M_TEST_SUITE_TEARDOWN(GBMemory) {
26 | if (!*state) {
27 | return 0;
28 | }
29 | struct mCore* core = *state;
30 | mCoreConfigDeinit(&core->config);
31 | core->deinit(core);
32 | return 0;
33 | }
34 |
35 | M_TEST_DEFINE(patchROMBank0) {
36 | struct mCore* core = *state;
37 | struct GB* gb = core->board;
38 | int8_t oldExpected = gb->memory.rom[0];
39 | int8_t old;
40 | int8_t newExpected = 0x40;
41 |
42 | core->reset(core);
43 | GBPatch8(gb->cpu, 0, newExpected, &old, 0);
44 | assert_int_equal(old, oldExpected);
45 | assert_int_equal(gb->memory.rom[0], newExpected);
46 | assert_int_equal(GBView8(gb->cpu, 0, 0), newExpected);
47 | }
48 |
49 | M_TEST_DEFINE(patchROMBank1) {
50 | struct mCore* core = *state;
51 | struct GB* gb = core->board;
52 | int8_t oldExpected = gb->memory.rom[GB_SIZE_CART_BANK0];
53 | int8_t old;
54 | int8_t newExpected = 0x41;
55 |
56 | core->reset(core);
57 | GBPatch8(gb->cpu, GB_SIZE_CART_BANK0, newExpected, &old, 1);
58 | assert_int_equal(old, oldExpected);
59 | assert_int_equal(gb->memory.rom[GB_SIZE_CART_BANK0], newExpected);
60 | assert_int_equal(GBView8(gb->cpu, GB_SIZE_CART_BANK0, 1), newExpected);
61 | }
62 |
63 | M_TEST_DEFINE(patchROMBank2) {
64 | struct mCore* core = *state;
65 | struct GB* gb = core->board;
66 | int8_t oldExpected = gb->memory.rom[GB_SIZE_CART_BANK0 * 2];
67 | int8_t old;
68 | int8_t newExpected = 0x42;
69 |
70 | core->reset(core);
71 | GBPatch8(gb->cpu, GB_SIZE_CART_BANK0, newExpected, &old, 2);
72 | assert_int_equal(old, oldExpected);
73 | assert_int_equal(gb->memory.rom[GB_SIZE_CART_BANK0 * 2], newExpected);
74 | assert_int_equal(GBView8(gb->cpu, GB_SIZE_CART_BANK0, 2), newExpected);
75 | }
76 |
77 | M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(GBMemory,
78 | cmocka_unit_test(patchROMBank0),
79 | cmocka_unit_test(patchROMBank1),
80 | cmocka_unit_test(patchROMBank2))
81 |
--------------------------------------------------------------------------------
/src/gba/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include(ExportDirectory)
2 | set(SOURCE_FILES
3 | ../gb/audio.c
4 | audio.c
5 | bios.c
6 | cart/ereader.c
7 | cart/gpio.c
8 | cart/matrix.c
9 | cart/vfame.c
10 | cheats.c
11 | cheats/codebreaker.c
12 | cheats/gameshark.c
13 | cheats/parv3.c
14 | core.c
15 | dma.c
16 | gba.c
17 | hle-bios.c
18 | input.c
19 | io.c
20 | memory.c
21 | overrides.c
22 | renderers/cache-set.c
23 | renderers/common.c
24 | renderers/gl.c
25 | renderers/software-bg.c
26 | renderers/software-mode0.c
27 | renderers/software-obj.c
28 | renderers/video-software.c
29 | savedata.c
30 | serialize.c
31 | sharkport.c
32 | sio.c
33 | sio/gbp.c
34 | sio/joybus.c
35 | timer.c
36 | video.c)
37 |
38 | set(SIO_FILES
39 | sio/dolphin.c
40 | sio/lockstep.c)
41 |
42 | set(EXTRA_FILES
43 | extra/audio-mixer.c
44 | extra/battlechip.c
45 | extra/proxy.c)
46 |
47 | set(DEBUGGER_FILES
48 | debugger/cli.c)
49 |
50 | set(TEST_FILES
51 | test/cheats.c
52 | test/core.c)
53 |
54 | source_group("GBA board" FILES ${SOURCE_FILES})
55 | source_group("GBA extras" FILES ${EXTRA_FILES} ${SIO_FILES})
56 | source_group("GBA debugger" FILES ${DEBUGGER_FILES})
57 | source_group("GBA tests" FILES ${TEST_FILES})
58 |
59 | export_directory(GBA SOURCE_FILES)
60 | export_directory(GBA_SIO SIO_FILES)
61 | export_directory(GBA_EXTRA EXTRA_FILES)
62 | export_directory(GBA_DEBUGGER DEBUGGER_FILES)
63 | export_directory(GBA_TEST TEST_FILES)
64 |
--------------------------------------------------------------------------------
/src/gba/cheats/gameshark.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_CHEATS_GAMESHARK_H
7 | #define GBA_CHEATS_GAMESHARK_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | extern const uint32_t GBACheatGameSharkSeeds[4];
14 |
15 | enum GBACheatGameSharkVersion {
16 | GBA_GS_NOT_SET = 0,
17 | GBA_GS_GSAV1 = 1,
18 | GBA_GS_GSAV1_RAW = 2,
19 | GBA_GS_PARV3 = 3,
20 | GBA_GS_PARV3_RAW = 4
21 | };
22 |
23 | struct GBACheatSet;
24 | void GBACheatDecryptGameShark(uint32_t* op1, uint32_t* op2, const uint32_t* seeds);
25 | void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1, const uint8_t* t2);
26 | void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, enum GBACheatGameSharkVersion version);
27 | bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2);
28 | int GBACheatGameSharkProbability(uint32_t op1, uint32_t op2);
29 |
30 | CXX_GUARD_END
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/src/gba/cheats/parv3.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 GBA_CHEATS_PARV3_H
7 | #define GBA_CHEATS_PARV3_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | extern const uint32_t GBACheatProActionReplaySeeds[4];
14 |
15 | struct GBACheatSet;
16 | bool GBACheatAddProActionReplayRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2);
17 | int GBACheatProActionReplayProbability(uint32_t op1, uint32_t op2);
18 |
19 | CXX_GUARD_END
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/src/gba/hle-bios.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 HLE_BIOS_H
7 | #define HLE_BIOS_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | extern const uint8_t hleBios[];
14 |
15 | CXX_GUARD_END
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/src/gba/hle-bios.make:
--------------------------------------------------------------------------------
1 | PREFIX := $(DEVKITARM)/bin/arm-none-eabi-
2 | AS := $(PREFIX)as
3 | OBJCOPY := $(PREFIX)objcopy
4 |
5 | all: hle-bios.c
6 |
7 | hle-bios.o: hle-bios.s
8 | $(AS) -o $@ $<
9 |
10 | hle-bios.bin: hle-bios.o
11 | $(OBJCOPY) -O binary $< $@
12 |
13 | hle-bios.c: hle-bios.bin
14 | echo '#include "hle-bios.h"' > $@
15 | echo >> $@
16 | echo '#include ' >> $@
17 | echo >> $@
18 | xxd -i $< | sed -e 's/unsigned char hle_bios_bin\[\]/const uint8_t hleBios[SIZE_BIOS]/' -e 's/^ \+/\t/' | grep -v hle_bios_bin_len >> $@
19 |
--------------------------------------------------------------------------------
/src/gba/input.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include
7 |
8 | #include
9 |
10 | MGBA_EXPORT const struct mInputPlatformInfo GBAInputInfo = {
11 | .platformName = "gba",
12 | .keyId = (const char*[]) {
13 | "A",
14 | "B",
15 | "Select",
16 | "Start",
17 | "Right",
18 | "Left",
19 | "Up",
20 | "Down",
21 | "R",
22 | "L"
23 | },
24 | .nKeys = GBA_KEY_MAX,
25 | .hat = {
26 | .up = GBA_KEY_UP,
27 | .left = GBA_KEY_LEFT,
28 | .down = GBA_KEY_DOWN,
29 | .right = GBA_KEY_RIGHT
30 | }
31 | };
32 |
--------------------------------------------------------------------------------
/src/gba/renderers/common.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2019 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 | #include
7 |
8 | #include
9 |
10 | int GBAVideoRendererCleanOAM(struct GBAObj* oam, struct GBAVideoRendererSprite* sprites, int offsetY) {
11 | int i;
12 | int oamMax = 0;
13 | for (i = 0; i < 128; ++i) {
14 | struct GBAObj obj;
15 | LOAD_16LE(obj.a, 0, &oam[i].a);
16 | LOAD_16LE(obj.b, 0, &oam[i].b);
17 | LOAD_16LE(obj.c, 0, &oam[i].c);
18 | if (GBAObjAttributesAIsTransformed(obj.a) || !GBAObjAttributesAIsDisable(obj.a)) {
19 | int width = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][0];
20 | int height = GBAVideoObjSizes[GBAObjAttributesAGetShape(obj.a) * 4 + GBAObjAttributesBGetSize(obj.b)][1];
21 | int cycles = width;
22 | if (GBAObjAttributesAIsTransformed(obj.a)) {
23 | height <<= GBAObjAttributesAGetDoubleSize(obj.a);
24 | width <<= GBAObjAttributesAGetDoubleSize(obj.a);
25 | cycles = 10 + width * 2;
26 | }
27 | if (GBAObjAttributesAGetY(obj.a) >= GBA_VIDEO_VERTICAL_PIXELS && GBAObjAttributesAGetY(obj.a) + height < VIDEO_VERTICAL_TOTAL_PIXELS) {
28 | continue;
29 | }
30 | if (GBAObjAttributesBGetX(obj.b) >= GBA_VIDEO_HORIZONTAL_PIXELS && GBAObjAttributesBGetX(obj.b) + width < 512) {
31 | continue;
32 | }
33 | int y = GBAObjAttributesAGetY(obj.a) + offsetY;
34 | sprites[oamMax].y = y;
35 | sprites[oamMax].endY = y + height;
36 | sprites[oamMax].cycles = cycles;
37 | sprites[oamMax].obj = obj;
38 | sprites[oamMax].index = i;
39 | ++oamMax;
40 | }
41 | }
42 | return oamMax;
43 | }
44 |
--------------------------------------------------------------------------------
/src/gba/test/core.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2016 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 | #include "util/test/suite.h"
7 |
8 | #include
9 | #include
10 |
11 | M_TEST_DEFINE(create) {
12 | struct mCore* core = GBACoreCreate();
13 | assert_non_null(core);
14 | assert_true(core->init(core));
15 | core->deinit(core);
16 | }
17 |
18 | M_TEST_DEFINE(platform) {
19 | struct mCore* core = GBACoreCreate();
20 | assert_non_null(core);
21 | assert_true(core->platform(core) == mPLATFORM_GBA);
22 | assert_true(core->init(core));
23 | core->deinit(core);
24 | }
25 |
26 | M_TEST_DEFINE(reset) {
27 | struct mCore* core = GBACoreCreate();
28 | assert_non_null(core);
29 | assert_true(core->init(core));
30 | mCoreInitConfig(core, NULL);
31 | core->reset(core);
32 | mCoreConfigDeinit(&core->config);
33 | core->deinit(core);
34 | }
35 |
36 | M_TEST_DEFINE(loadNullROM) {
37 | struct mCore* core = GBACoreCreate();
38 | assert_non_null(core);
39 | assert_true(core->init(core));
40 | assert_false(core->loadROM(core, NULL));
41 | mCoreInitConfig(core, NULL);
42 | core->reset(core);
43 | mCoreConfigDeinit(&core->config);
44 | core->deinit(core);
45 | }
46 |
47 | M_TEST_SUITE_DEFINE(GBACore,
48 | cmocka_unit_test(create),
49 | cmocka_unit_test(platform),
50 | cmocka_unit_test(reset),
51 | cmocka_unit_test(loadNullROM))
52 |
--------------------------------------------------------------------------------
/src/platform/openemu/Info.plist.in:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${PROJECT_NAME}
9 | CFBundleIconFile
10 | mGBA
11 | CFBundleIdentifier
12 | com.endrift.mgba
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | ${VERSION_STRING}
21 | NSPrincipalClass
22 | OEGameCoreController
23 | OEGameCoreClass
24 | mGBAGameCore
25 | OEGameCoreOptions
26 |
27 | openemu.system.gba
28 |
29 | OEGameCoreRewindBufferSeconds
30 | 60
31 | OEGameCoreRewindInterval
32 | 0
33 | OEGameCoreSupportsRewinding
34 |
35 | OEGameCoreSupportsCheatCode
36 |
37 |
38 |
39 | OEGameCorePlayerCount
40 | 1
41 | OEProjectURL
42 | https://mgba.io/
43 | OESystemIdentifiers
44 |
45 | openemu.system.gba
46 |
47 | SUEnableAutomaticChecks
48 | 1
49 | SUFeedURL
50 | https://raw.github.com/OpenEmu/OpenEmu-Update/master/mgba_appcast.xml
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/platform/openemu/OEGBASystemResponderClient.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2011, OpenEmu Team
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright
7 | notice, this list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright
9 | notice, this list of conditions and the following disclaimer in the
10 | documentation and/or other materials provided with the distribution.
11 | * Neither the name of the OpenEmu Team nor the
12 | names of its contributors may be used to endorse or promote products
13 | derived from this software without specific prior written permission.
14 |
15 | THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY
16 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY
19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #import
28 |
29 | @protocol OESystemResponderClient;
30 |
31 | typedef enum _OEGBAButton
32 | {
33 | OEGBAButtonUp,
34 | OEGBAButtonDown,
35 | OEGBAButtonLeft,
36 | OEGBAButtonRight,
37 | OEGBAButtonA,
38 | OEGBAButtonB,
39 | OEGBAButtonL,
40 | OEGBAButtonR,
41 | OEGBAButtonStart,
42 | OEGBAButtonSelect,
43 | OEGBAButtonCount
44 | } OEGBAButton;
45 |
46 | @protocol OEGBASystemResponderClient
47 |
48 | - (oneway void)didPushGBAButton:(OEGBAButton)button forPlayer:(NSUInteger)player;
49 | - (oneway void)didReleaseGBAButton:(OEGBAButton)button forPlayer:(NSUInteger)player;
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/src/platform/openemu/mGBAGameCore.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | OE_EXPORTED_CLASS
5 | @interface mGBAGameCore : OEGameCore
6 | @end
7 |
--------------------------------------------------------------------------------
/src/platform/posix/memory.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 | #include
7 |
8 | #ifndef DISABLE_ANON_MMAP
9 | #ifdef __SANITIZE_ADDRESS__
10 | #define DISABLE_ANON_MMAP
11 | #elif defined(__has_feature)
12 | #if __has_feature(address_sanitizer)
13 | #define DISABLE_ANON_MMAP
14 | #endif
15 | #endif
16 | #endif
17 |
18 | #ifndef DISABLE_ANON_MMAP
19 | #include
20 |
21 | void* anonymousMemoryMap(size_t size) {
22 | return mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
23 | }
24 |
25 | void mappedMemoryFree(void* memory, size_t size) {
26 | munmap(memory, size);
27 | }
28 | #else
29 | void* anonymousMemoryMap(size_t size) {
30 | return calloc(1, size);
31 | }
32 |
33 | void mappedMemoryFree(void* memory, size_t size) {
34 | UNUSED(size);
35 | free(memory);
36 | }
37 | #endif
38 |
--------------------------------------------------------------------------------
/src/platform/video-backend.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 VIDEO_BACKEND_H
7 | #define VIDEO_BACKEND_H
8 |
9 | #include
10 |
11 | CXX_GUARD_START
12 |
13 | #ifdef _WIN32
14 | #include
15 | typedef HWND WHandle;
16 | #else
17 | typedef void* WHandle;
18 | #endif
19 |
20 | struct VideoBackend {
21 | void (*init)(struct VideoBackend*, WHandle handle);
22 | void (*deinit)(struct VideoBackend*);
23 | void (*setDimensions)(struct VideoBackend*, unsigned width, unsigned height);
24 | void (*swap)(struct VideoBackend*);
25 | void (*clear)(struct VideoBackend*);
26 | void (*resized)(struct VideoBackend*, unsigned w, unsigned h);
27 | void (*postFrame)(struct VideoBackend*, const void* frame);
28 | void (*drawFrame)(struct VideoBackend*);
29 | void (*setMessage)(struct VideoBackend*, const char* message);
30 | void (*clearMessage)(struct VideoBackend*);
31 |
32 | void* user;
33 | unsigned width;
34 | unsigned height;
35 |
36 | bool filter;
37 | bool lockAspectRatio;
38 | bool lockIntegerScaling;
39 | bool interframeBlending;
40 | };
41 |
42 | struct VideoShader {
43 | const char* name;
44 | const char* author;
45 | const char* description;
46 | void* preprocessShader;
47 | void* passes;
48 | size_t nPasses;
49 | };
50 |
51 | CXX_GUARD_END
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/third-party/inih/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | The "inih" library is distributed under the New BSD license:
3 |
4 | Copyright (c) 2009, Ben Hoyt
5 | All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions are met:
9 | * Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | * Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | * Neither the name of Ben Hoyt nor the names of its contributors
15 | may be used to endorse or promote products derived from this software
16 | without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY BEN HOYT ''AS IS'' AND ANY
19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL BEN HOYT BE LIABLE FOR ANY
22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/src/util/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include(ExportDirectory)
2 | set(BASE_SOURCE_FILES
3 | circle-buffer.c
4 | configuration.c
5 | crc32.c
6 | formatting.c
7 | gbk-table.c
8 | hash.c
9 | string.c
10 | table.c
11 | vfs.c)
12 |
13 | set(SOURCE_FILES
14 | ${BASE_SOURCE_FILES}
15 | convolve.c
16 | elf-read.c
17 | export.c
18 | patch.c
19 | patch-fast.c
20 | patch-ips.c
21 | patch-ups.c
22 | png-io.c
23 | ring-fifo.c
24 | text-codec.c)
25 |
26 | set(GUI_FILES
27 | gui.c
28 | gui/file-select.c
29 | gui/font.c
30 | gui/font-metrics.c
31 | gui/menu.c)
32 |
33 | set(TEST_FILES
34 | test/string-parser.c
35 | test/string-utf8.c
36 | test/table.c
37 | test/text-codec.c
38 | test/vfs.c)
39 |
40 | if(NOT DEFINED OS_SRC)
41 | set(OS_FILES memory.c)
42 | export_directory(OS OS_FILES)
43 | endif()
44 |
45 | source_group("Utilities" FILES ${SOURCE_FILES})
46 | source_group("GUI source" FILES ${GUI_FILES})
47 | source_group("Utilities tests" FILES ${TEST_FILES})
48 |
49 | export_directory(UTIL_BASE BASE_SOURCE_FILES)
50 | export_directory(UTIL SOURCE_FILES)
51 | export_directory(GUI GUI_FILES)
52 | export_directory(UTIL_TEST TEST_FILES)
53 |
--------------------------------------------------------------------------------
/src/util/export.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 | #include
7 |
8 | #include
9 | #include
10 |
11 | bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors) {
12 | if (entries > 0xFFFF) {
13 | return false;
14 | }
15 | uint32_t chunkSize = 4 + 4 * entries;
16 | uint32_t size = chunkSize + 12;
17 |
18 | // Header
19 | if (vf->write(vf, "RIFF", 4) < 4) {
20 | return false;
21 | }
22 | if (VFileWrite32LE(vf, size) < 4) {
23 | return false;
24 | }
25 | if (vf->write(vf, "PAL ", 4) < 4) {
26 | return false;
27 | }
28 |
29 | // Data chunk
30 | if (vf->write(vf, "data", 4) < 4) {
31 | return false;
32 | }
33 | if (VFileWrite32LE(vf, chunkSize) < 4) {
34 | return false;
35 | }
36 | if (VFileWrite16LE(vf, 0x0300) < 2) {
37 | return false;
38 | }
39 | if (VFileWrite16LE(vf, entries) < 2) {
40 | return false;
41 | }
42 |
43 | size_t i;
44 | for (i = 0; i < entries; ++i) {
45 | uint8_t block[4] = {
46 | M_R8(colors[i]),
47 | M_G8(colors[i]),
48 | M_B8(colors[i]),
49 | 0
50 | };
51 | if (vf->write(vf, block, 4) < 4) {
52 | return false;
53 | }
54 | }
55 |
56 | return true;
57 | }
58 |
59 | bool exportPaletteACT(struct VFile* vf, size_t entries, const uint16_t* colors) {
60 | if (entries > 256) {
61 | return false;
62 | }
63 | size_t i;
64 | for (i = 0; i < entries; ++i) {
65 | uint8_t block[3] = {
66 | M_R8(colors[i]),
67 | M_G8(colors[i]),
68 | M_B8(colors[i]),
69 | };
70 | if (vf->write(vf, block, 3) < 3) {
71 | return false;
72 | }
73 | }
74 | for (; i < 256; ++i) {
75 | uint8_t block[3] = { 0, 0, 0 };
76 | if (vf->write(vf, block, 3) < 3) {
77 | return false;
78 | }
79 | }
80 | return true;
81 | }
82 |
--------------------------------------------------------------------------------
/src/util/formatting.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 | #include
7 |
8 | #include
9 |
10 | int ftostr_l(char* restrict str, size_t size, float f, locale_t locale) {
11 | #ifdef HAVE_SNPRINTF_L
12 | return snprintf_l(str, size, locale, "%.*g", FLT_DIG, f);
13 | #elif defined(HAVE_USELOCALE)
14 | locale_t old = uselocale(locale);
15 | int res = snprintf(str, size, "%.*g", FLT_DIG, f);
16 | uselocale(old);
17 | return res;
18 | #elif defined(HAVE_SETLOCALE)
19 | char* old = setlocale(LC_NUMERIC, locale);
20 | int res = snprintf(str, size, "%.*g", FLT_DIG, f);
21 | setlocale(LC_NUMERIC, old);
22 | return res;
23 | #else
24 | UNUSED(locale);
25 | return snprintf(str, size, "%.*g", FLT_DIG, f);
26 | #endif
27 | }
28 |
29 | #ifndef HAVE_STRTOF_L
30 | float strtof_l(const char* restrict str, char** restrict end, locale_t locale) {
31 | #ifdef HAVE_USELOCALE
32 | locale_t old = uselocale(locale);
33 | float res = strtof(str, end);
34 | uselocale(old);
35 | return res;
36 | #elif defined(HAVE_SETLOCALE)
37 | char* old = setlocale(LC_NUMERIC, locale);
38 | float res = strtof(str, end);
39 | setlocale(LC_NUMERIC, old);
40 | return res;
41 | #else
42 | UNUSED(locale);
43 | return strtof(str, end);
44 | #endif
45 | }
46 | #endif
47 |
48 | int ftostr_u(char* restrict str, size_t size, float f) {
49 | #if HAVE_LOCALE
50 | locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
51 | #else
52 | locale_t l = "C";
53 | #endif
54 | int res = ftostr_l(str, size, f, l);
55 | #if HAVE_LOCALE
56 | freelocale(l);
57 | #endif
58 | return res;
59 | }
60 |
61 | float strtof_u(const char* restrict str, char** restrict end) {
62 | #if HAVE_LOCALE
63 | locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
64 | #else
65 | locale_t l = "C";
66 | #endif
67 | float res = strtof_l(str, end, l);
68 | #if HAVE_LOCALE
69 | freelocale(l);
70 | #endif
71 | return res;
72 | }
73 |
74 | #ifndef HAVE_LOCALTIME_R
75 | struct tm* localtime_r(const time_t* t, struct tm* date) {
76 | #ifdef _WIN32
77 | localtime_s(date, t);
78 | return date;
79 | #elif defined(PSP2)
80 | extern struct tm* sceKernelLibcLocaltime_r(const time_t* t, struct tm* date);
81 | return sceKernelLibcLocaltime_r(t, date);
82 | #else
83 | #warning localtime_r not emulated on this platform
84 | return 0;
85 | #endif
86 | }
87 | #endif
88 |
--------------------------------------------------------------------------------
/src/util/gui.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2015 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 | #include
7 |
8 | #define KEY_DELAY 45
9 | #define KEY_REPEAT 5
10 |
11 | void GUIInit(struct GUIParams* params) {
12 | memset(params->inputHistory, 0, sizeof(params->inputHistory));
13 | strncpy(params->currentPath, params->basePath, PATH_MAX);
14 | }
15 |
16 | void GUIPollInput(struct GUIParams* params, uint32_t* newInputOut, uint32_t* heldInput) {
17 | uint32_t input = params->pollInput(¶ms->keyMap);
18 | uint32_t newInput = 0;
19 | int i;
20 | for (i = 0; i < GUI_INPUT_MAX; ++i) {
21 | if (input & (1 << i)) {
22 | ++params->inputHistory[i];
23 | } else {
24 | params->inputHistory[i] = -1;
25 | }
26 | if (!params->inputHistory[i] || (params->inputHistory[i] >= KEY_DELAY && !(params->inputHistory[i] % KEY_REPEAT))) {
27 | newInput |= (1 << i);
28 | }
29 | }
30 | if (newInputOut) {
31 | *newInputOut = newInput;
32 | }
33 | if (heldInput) {
34 | *heldInput = input;
35 | }
36 | }
37 |
38 | enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y) {
39 | if (!params->pollCursor) {
40 | return GUI_CURSOR_NOT_PRESENT;
41 | }
42 | enum GUICursorState state = params->pollCursor(x, y);
43 | if (params->cursorState == GUI_CURSOR_DOWN) {
44 | int dragX = *x - params->cx;
45 | int dragY = *y - params->cy;
46 | if (dragX * dragX + dragY * dragY > 25) {
47 | params->cursorState = GUI_CURSOR_DRAGGING;
48 | return GUI_CURSOR_DRAGGING;
49 | }
50 | if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
51 | params->cursorState = GUI_CURSOR_UP;
52 | return GUI_CURSOR_CLICKED;
53 | }
54 | } else {
55 | params->cx = *x;
56 | params->cy = *y;
57 | }
58 | if (params->cursorState == GUI_CURSOR_DRAGGING) {
59 | if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
60 | params->cursorState = GUI_CURSOR_UP;
61 | return GUI_CURSOR_UP;
62 | }
63 | return GUI_CURSOR_DRAGGING;
64 | }
65 | params->cursorState = state;
66 | return params->cursorState;
67 | }
68 |
69 | void GUIInvalidateKeys(struct GUIParams* params) {
70 | int i;
71 | for (i = 0; i < GUI_INPUT_MAX; ++i) {
72 | params->inputHistory[i] = 0;
73 | }
74 | }
75 |
76 | void GUIKeyboardParamsInit(struct GUIKeyboardParams* keyboard) {
77 | memset(keyboard->title, 0, sizeof(keyboard->title));
78 | memset(keyboard->result, 0, sizeof(keyboard->result));
79 | keyboard->maxLen = sizeof(keyboard->result);
80 | keyboard->multiline = false;
81 | }
82 |
--------------------------------------------------------------------------------
/src/util/hash.c:
--------------------------------------------------------------------------------
1 | // MurmurHash3 was written by Austin Appleby, and is placed in the public
2 | // domain. The author hereby disclaims copyright to this source code.
3 |
4 | #include
5 |
6 | #if defined(_MSC_VER)
7 |
8 | #define FORCE_INLINE __forceinline
9 |
10 | #include
11 |
12 | #define ROTL32(x,y) _rotl(x,y)
13 |
14 | #else
15 |
16 | #define FORCE_INLINE inline __attribute__((always_inline))
17 |
18 | static inline uint32_t rotl32(uint32_t x, int8_t r) {
19 | return (x << r) | (x >> (32 - r));
20 | }
21 |
22 | #define ROTL32(x, y) rotl32(x, y)
23 |
24 | #endif
25 |
26 | //-----------------------------------------------------------------------------
27 | // Block read - if your platform needs to do endian-swapping or can only
28 | // handle aligned reads, do the conversion here
29 |
30 | static FORCE_INLINE uint32_t getblock32(const uint32_t* p, ssize_t i) {
31 | uint32_t ret;
32 | LOAD_32LE(ret, i << 2, p);
33 | return ret;
34 | }
35 |
36 | //-----------------------------------------------------------------------------
37 | // Finalization mix - force all bits of a hash block to avalanche
38 |
39 | static FORCE_INLINE uint32_t fmix32(uint32_t h) {
40 | h ^= h >> 16;
41 | h *= 0x85ebca6b;
42 | h ^= h >> 13;
43 | h *= 0xc2b2ae35;
44 | h ^= h >> 16;
45 |
46 | return h;
47 | }
48 |
49 | //-----------------------------------------------------------------------------
50 |
51 | uint32_t hash32(const void* key, size_t len, uint32_t seed) {
52 | const uint8_t* data = (const uint8_t*) key;
53 | const int nblocks = len / 4;
54 |
55 | uint32_t h1 = seed;
56 |
57 | const uint32_t c1 = 0xcc9e2d51;
58 | const uint32_t c2 = 0x1b873593;
59 |
60 | //----------
61 | // body
62 |
63 | const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4);
64 |
65 | int i;
66 | for (i = -nblocks; i; i++) {
67 | uint32_t k1 = getblock32(blocks, i);
68 |
69 | k1 *= c1;
70 | k1 = ROTL32(k1, 15);
71 | k1 *= c2;
72 |
73 | h1 ^= k1;
74 | h1 = ROTL32(h1, 13);
75 | h1 = h1 * 5 + 0xe6546b64;
76 | }
77 |
78 | //----------
79 | // tail
80 |
81 | const uint8_t* tail = (const uint8_t*)(data + nblocks * 4);
82 |
83 | uint32_t k1 = 0;
84 |
85 | switch(len & 3) {
86 | case 3:
87 | k1 ^= tail[2] << 16;
88 | // Fall through
89 | case 2:
90 | k1 ^= tail[1] << 8;
91 | // Fall through
92 | case 1:
93 | k1 ^= tail[0];
94 | k1 *= c1;
95 | k1 = ROTL32(k1, 15);
96 | k1 *= c2;
97 | h1 ^= k1;
98 | };
99 |
100 | //----------
101 | // finalization
102 |
103 | h1 ^= len;
104 |
105 | h1 = fmix32(h1);
106 |
107 | return h1;
108 | }
109 |
--------------------------------------------------------------------------------
/src/util/memory.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2020 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 | #include
7 |
8 | void* anonymousMemoryMap(size_t size) {
9 | return calloc(1, size);
10 | }
11 |
12 | void mappedMemoryFree(void* memory, size_t size) {
13 | UNUSED(size);
14 | free(memory);
15 | }
16 |
--------------------------------------------------------------------------------
/src/util/patch-ips.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2013-2014 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 | #include
7 |
8 | #include