├── src ├── lua │ ├── plat │ │ ├── cmd │ │ │ ├── cdef.lua │ │ │ ├── util.lua │ │ │ ├── init.lua │ │ │ └── screen.lua │ │ ├── 3ds │ │ │ ├── button.lua │ │ │ ├── mouse.lua │ │ │ ├── main.lua │ │ │ ├── util.lua │ │ │ ├── screen.lua │ │ │ └── init.lua │ │ └── love │ │ │ ├── util.lua │ │ │ ├── mouse.lua │ │ │ ├── init.lua │ │ │ ├── button.lua │ │ │ └── screen.lua │ ├── object.lua │ ├── mouse.lua │ ├── red │ │ ├── start_menu │ │ │ ├── render.lua │ │ │ └── party.lua │ │ ├── dex.lua │ │ ├── render │ │ │ ├── custom_sprites.lua │ │ │ ├── dialogue.lua │ │ │ ├── battle.lua │ │ │ └── bpp.lua │ │ ├── init.lua │ │ ├── string.lua │ │ ├── map.lua │ │ ├── dialogue.lua │ │ └── cheats.lua │ ├── config.lua │ ├── env.lua │ ├── game.lua │ ├── ui │ │ ├── button.lua │ │ ├── view.lua │ │ └── label.lua │ ├── wip │ │ ├── paint.lua │ │ ├── tmp.lua │ │ ├── debugserver.lua │ │ └── serverbrowser.lua │ ├── debug_menu.lua │ ├── preinit.lua │ ├── cdef │ │ └── desktop.lua │ ├── art │ │ └── lua_logo.lua │ ├── gif.lua │ ├── button.lua │ ├── display.lua │ ├── rom.lua │ ├── player.lua │ ├── net │ │ ├── server.lua │ │ └── client.lua │ ├── ogg.lua │ ├── init.lua │ ├── bitmap.lua │ └── screen.lua └── c │ ├── common │ ├── wrappers.c │ ├── stb.c │ └── zip.c │ └── 3ds │ └── mgba.c ├── .gitignore ├── 3ds_stuff ├── icon.png └── cia │ ├── sound.wav │ └── banner.png ├── res └── font │ ├── hack.ttf │ ├── NotoSans-Bold.ttf │ ├── NotoSans-Regular.ttf │ └── SourceCodePro-Medium.ttf ├── .gitmodules ├── deps └── include │ ├── mgba │ ├── platform │ │ ├── 3ds │ │ │ ├── bios.wav │ │ │ ├── icons.raw │ │ │ ├── banner.cgfx │ │ │ ├── 3ds-vfs.h │ │ │ ├── ctr-gpu.h │ │ │ ├── uishader.v.pica │ │ │ ├── CMakeToolchain.txt │ │ │ └── uishader.g.pica │ │ └── video-backend.h │ ├── gb │ │ ├── core.h │ │ ├── test │ │ │ └── gb.h │ │ ├── renderers │ │ │ ├── tile-cache.h │ │ │ └── software.h │ │ ├── cli.h │ │ ├── interface.h │ │ ├── overrides.h │ │ ├── sio.h │ │ ├── cheats.h │ │ ├── mbc.h │ │ ├── timer.h │ │ └── io.h │ ├── gba │ │ ├── core.h │ │ ├── test │ │ │ └── gba.h │ │ ├── hle-bios.h │ │ ├── hle-bios.make │ │ ├── renderers │ │ │ ├── tile-cache.h │ │ │ └── thread-proxy.h │ │ ├── extra │ │ │ ├── sharkport.h │ │ │ └── cli.h │ │ ├── rr │ │ │ ├── vbm.h │ │ │ ├── rr.h │ │ │ └── mgm.h │ │ ├── cheats │ │ │ ├── parv3.h │ │ │ └── gameshark.h │ │ ├── input.h │ │ ├── bios.h │ │ ├── overrides.h │ │ ├── vfame.h │ │ ├── interface.h │ │ ├── sio │ │ │ └── lockstep.h │ │ └── sio.h │ ├── util │ │ ├── test │ │ │ ├── util.h │ │ │ └── suite.h │ │ ├── hash.h │ │ ├── patch-ips.h │ │ ├── patch-ups.h │ │ ├── memory.h │ │ ├── gui │ │ │ ├── file-select.h │ │ │ ├── font-metrics.h │ │ │ ├── menu.h │ │ │ └── font.h │ │ ├── export.h │ │ ├── crc32.h │ │ ├── arm-algo.h │ │ ├── patch.h │ │ ├── nointro.h │ │ ├── ring-fifo.h │ │ ├── patch-fast.h │ │ ├── formatting.h │ │ ├── circle-buffer.h │ │ ├── string.h │ │ ├── png-io.h │ │ ├── table.h │ │ ├── configuration.h │ │ ├── arm-algo.S │ │ ├── threading.h │ │ ├── math.h │ │ └── gui.h │ ├── core │ │ ├── test │ │ │ └── core.h │ │ ├── version.h │ │ ├── cpu.h │ │ ├── version.c.in │ │ ├── rewind.h │ │ ├── library.h │ │ ├── sync.h │ │ ├── directories.h │ │ ├── serialize.h │ │ ├── log.h │ │ ├── tile-cache.h │ │ ├── interface.h │ │ ├── input.h │ │ ├── cheats.h │ │ └── thread.h │ ├── arm │ │ ├── debugger │ │ │ ├── cli-debugger.h │ │ │ ├── memory-debugger.h │ │ │ └── debugger.h │ │ ├── isa-thumb.h │ │ ├── macros.h │ │ ├── isa-arm.h │ │ ├── decoder-inlines.h │ │ └── emitter-inlines.h │ ├── lr35902 │ │ ├── debugger │ │ │ ├── cli-debugger.h │ │ │ └── debugger.h │ │ └── isa-lr35902.h │ ├── feature │ │ ├── gui │ │ │ ├── gui-config.h │ │ │ ├── remap.h │ │ │ └── gui-runner.h │ │ ├── imagemagick │ │ │ └── imagemagick-gif-encoder.h │ │ ├── commandline.h │ │ └── ffmpeg │ │ │ └── ffmpeg-encoder.h │ └── debugger │ │ ├── gdb-stub.h │ │ ├── parser.h │ │ ├── cli-debugger.h │ │ └── debugger.h │ └── lua │ ├── lua.hpp │ ├── lualib.h │ └── luajit.h ├── .travis.yml ├── README.md └── main.lua /src/lua/plat/cmd/cdef.lua: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | rom 3 | deps/lib 4 | src/lua/config 5 | -------------------------------------------------------------------------------- /3ds_stuff/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/3ds_stuff/icon.png -------------------------------------------------------------------------------- /res/font/hack.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/res/font/hack.ttf -------------------------------------------------------------------------------- /3ds_stuff/cia/sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/3ds_stuff/cia/sound.wav -------------------------------------------------------------------------------- /3ds_stuff/cia/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/3ds_stuff/cia/banner.png -------------------------------------------------------------------------------- /res/font/NotoSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/res/font/NotoSans-Bold.ttf -------------------------------------------------------------------------------- /res/font/NotoSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/res/font/NotoSans-Regular.ttf -------------------------------------------------------------------------------- /res/font/SourceCodePro-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/res/font/SourceCodePro-Medium.ttf -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/build_system"] 2 | path = deps/build_system 3 | url = https://github.com/N64N64/aite 4 | -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/bios.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/deps/include/mgba/platform/3ds/bios.wav -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/icons.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/deps/include/mgba/platform/3ds/icons.raw -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/banner.cgfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/N64N64/LunaRoja/HEAD/deps/include/mgba/platform/3ds/banner.cgfx -------------------------------------------------------------------------------- /src/lua/object.lua: -------------------------------------------------------------------------------- 1 | Object = {} 2 | 3 | function Object:new() 4 | return setmetatable({}, {__index = self}) 5 | end 6 | 7 | return Object 8 | -------------------------------------------------------------------------------- /src/c/common/wrappers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fseek_wrapper(FILE *f, long offset, int whence) 4 | { 5 | return fseek(f, offset, whence); 6 | } 7 | -------------------------------------------------------------------------------- /src/lua/mouse.lua: -------------------------------------------------------------------------------- 1 | Mouse = {} 2 | 3 | if PLATFORM == 'cmd' then 4 | function Mouse.Scan() end 5 | else 6 | require('plat.'..PLATFORM..'.mouse') 7 | end 8 | 9 | return Mouse 10 | -------------------------------------------------------------------------------- /deps/include/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // C++ wrapper for LuaJIT header files. 2 | 3 | extern "C" { 4 | #include "lua.h" 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | #include "luajit.h" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/button.lua: -------------------------------------------------------------------------------- 1 | function Button.Scan() 2 | C.hidScanInput() 3 | Button.KeysDown = C.hidKeysDown() 4 | Button.KeysUp = C.hidKeysUp() 5 | Button.KeysHeld = C.hidKeysHeld() 6 | end 7 | -------------------------------------------------------------------------------- /src/lua/plat/love/util.lua: -------------------------------------------------------------------------------- 1 | function ls(dir) 2 | if string.has_prefix(dir, PATH) then 3 | dir = string.sub(dir, #PATH + 1, #dir) 4 | end 5 | return love.filesystem.getDirectoryItems(dir) 6 | end 7 | -------------------------------------------------------------------------------- /src/c/common/stb.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "stb/stb_image.h" 3 | 4 | #define STB_IMAGE_WRITE_IMPLEMENTATION 5 | #include "stb/stb_image_write.h" 6 | 7 | #ifdef _WIN32 8 | #define alloca _alloca 9 | #endif 10 | #include "stb/stb_vorbis.h" 11 | -------------------------------------------------------------------------------- /src/lua/plat/cmd/util.lua: -------------------------------------------------------------------------------- 1 | function ls(dir) 2 | local i = 0 3 | local t = {} 4 | local f = io.popen('ls '..dir) 5 | for filename in f:lines() do 6 | i = i + 1 7 | t[i] = filename 8 | end 9 | f:close() 10 | return t 11 | end 12 | -------------------------------------------------------------------------------- /deps/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 | struct mCore; 10 | struct mCore* GBCoreCreate(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/include/mgba/gb/test/gb.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 TEST_GB_H 7 | #define TEST_GB_H 8 | #include "util/common.h" 9 | 10 | int TestRunGB(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/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 | struct mCore; 10 | struct mCore* GBACoreCreate(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/mouse.lua: -------------------------------------------------------------------------------- 1 | local touch = ffi.new('touchPosition[1]') 2 | function Mouse.Scan() 3 | Mouse.isdown = Button.isdown(Button.touch) 4 | Mouse.isup = Button.isup(Button.touch) 5 | Mouse.isheld = Button.isheld(Button.touch) 6 | if Mouse.isheld then 7 | C.hidTouchRead(touch) 8 | Mouse.x = tonumber(touch[0].px) 9 | Mouse.y = tonumber(touch[0].py) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/test/gba.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 TEST_GBA_H 7 | #define TEST_GBA_H 8 | #include "util/common.h" 9 | 10 | int TestRunGBA(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/include/mgba/util/test/util.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 TEST_UTIL_H 7 | #define TEST_UTIL_H 8 | #include "util/common.h" 9 | 10 | int TestRunUtil(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/include/mgba/core/test/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 TEST_M_CORE_H 7 | #define TEST_M_CORE_H 8 | #include "util/common.h" 9 | 10 | int TestRunCore(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | extern const uint8_t hleBios[]; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | uint32_t hash32(const void* key, int len, uint32_t seed); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct Patch; 12 | 13 | bool loadPatchIPS(struct Patch* patch); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct Patch; 12 | 13 | bool loadPatchUPS(struct Patch* patch); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/lua/red/start_menu/render.lua: -------------------------------------------------------------------------------- 1 | local start_menu_open = false 2 | 3 | emu:hook(Red.sym.DisplayStartMenu, function() 4 | if start_menu_open then return end 5 | 6 | RENDER_CALLBACKS.startmenu = function() 7 | emu:render() 8 | end 9 | start_menu_open = true 10 | end) 11 | 12 | emu:hook(Red.sym.CloseStartMenu, function() 13 | if not start_menu_open then return end 14 | 15 | RENDER_CALLBACKS.startmenu = nil 16 | start_menu_open = false 17 | end) 18 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | void* anonymousMemoryMap(size_t size); 12 | void mappedMemoryFree(void* memory, size_t size); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | struct CLIDebuggerSystem; 12 | void ARMCLIDebuggerCreate(struct CLIDebuggerSystem* debugger); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/main.lua: -------------------------------------------------------------------------------- 1 | require 'plat.3ds.util' 2 | require 'preinit' 3 | math.randomseed(tonumber(C.osGetTime())) 4 | require 'init' 5 | 6 | local lasttime 7 | function CALCULATE_DT(DT) 8 | local curtime = tonumber(C.osGetTime())/1000 9 | if not lasttime then 10 | lasttime = curtime 11 | else 12 | DT = curtime - lasttime 13 | lasttime = curtime 14 | end 15 | return DT 16 | end 17 | 18 | while C.aptMainLoop() do 19 | if MAIN_LOOP() then 20 | break 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /deps/include/mgba/lr35902/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 LR35902_CLI_DEBUGGER_H 7 | #define LR35902_CLI_DEBUGGER_H 8 | 9 | #include "util/common.h" 10 | 11 | struct CLIDebuggerSystem; 12 | void LR35902CLIDebuggerCreate(struct CLIDebuggerSystem* debugger); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/vfs.h" 10 | 11 | #include <3ds.h> 12 | 13 | FS_Archive sdmcArchive; 14 | 15 | struct VFile* VFileOpen3DS(FS_Archive* archive, const char* path, int flags); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deps/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 "util/gui.h" 10 | 11 | struct VFile; 12 | 13 | bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filter)(struct VFile*)); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /deps/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 "util/gui/font.h" 10 | 11 | extern struct GUIFontGlyphMetric defaultFontMetrics[]; 12 | extern struct GUIIconMetric defaultIconMetrics[]; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | struct ARMCore; 12 | 13 | typedef void (*ThumbInstruction)(struct ARMCore*, uint16_t opcode); 14 | extern const ThumbInstruction _thumbTable[0x400]; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/include/mgba/feature/gui/gui-config.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_CONFIG_H 7 | #define GUI_CONFIG_H 8 | 9 | #include "util/common.h" 10 | 11 | struct mGUIRunner; 12 | struct GUIMenuItem; 13 | void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "gba/memory.h"' >> $@ 17 | echo >> $@ 18 | xxd -i $< | sed -e 's/unsigned char hle_bios_bin\[\]/const uint8_t hleBios[SIZE_BIOS]/' | grep -v hle_bios_bin_len >> $@ 19 | -------------------------------------------------------------------------------- /deps/include/mgba/lr35902/isa-lr35902.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_LR35902_H 7 | #define ISA_LR35902_H 8 | 9 | #include "util/common.h" 10 | 11 | struct LR35902Core; 12 | 13 | typedef void (*LR35902Instruction)(struct LR35902Core*); 14 | extern const LR35902Instruction _lr35902InstructionTable[0x100]; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/util.lua: -------------------------------------------------------------------------------- 1 | local line = 0 2 | function console(...) 3 | local t = {} 4 | for i,v in ipairs({...}) do 5 | t[i] = tostring(v) 6 | end 7 | io.write('\x1b[0'..line..';00H'..table.concat(t, ', ')) 8 | line = line + 1 9 | if line > 9 then 10 | line = 0 11 | end 12 | end 13 | 14 | function write(str, x, y) 15 | x = x or 0 16 | y = y or 0 17 | io.write(string.format('\x1b[%.2d;%.2dH%s', y, x, str)) 18 | end 19 | 20 | function print(s) 21 | s = tostring(s) 22 | return C.svcOutputDebugString(s, #s) 23 | end 24 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 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 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct VFile; 12 | 13 | bool exportPaletteRIFF(struct VFile* vf, size_t entries, const uint16_t* colors); 14 | bool exportPaletteACT(struct VFile* vf, size_t entries, const uint16_t* colors); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | struct ARMDebugger; 12 | 13 | void ARMDebuggerInstallMemoryShim(struct ARMDebugger* debugger); 14 | void ARMDebuggerRemoveMemoryShim(struct ARMDebugger* debugger); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct VFile; 12 | 13 | uint32_t doCrc32(const void* buf, size_t size); 14 | uint32_t updateCrc32(uint32_t crc, const void* buf, size_t size); 15 | uint32_t fileCrc32(struct VFile* file, size_t endOffset); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deps/include/mgba/gb/renderers/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 GB_TILE_CACHE_H 7 | #define GB_TILE_CACHE_H 8 | 9 | #include "util/common.h" 10 | 11 | struct GBVideo; 12 | struct mTileCache; 13 | 14 | void GBVideoTileCacheInit(struct mTileCache* cache); 15 | void GBVideoTileCacheAssociate(struct mTileCache* cache, struct GBVideo* video); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/lua/plat/cmd/init.lua: -------------------------------------------------------------------------------- 1 | LUAPATH = PATH..'/src/lua' 2 | PLATFORM = 'cmd' 3 | package.path = LUAPATH..'/?.lua;' 4 | ..LUAPATH..'/?/init.lua;' 5 | ..package.path 6 | 7 | require 'preinit' 8 | require 'plat.cmd.util' 9 | require 'init' 10 | 11 | function CALCULATE_DT() 12 | return 1/60 13 | end 14 | 15 | MAIN_LOOP() 16 | 17 | emu = Gameboy:new(ROMPATH) 18 | Red:reset() 19 | 20 | MAIN_LOOP() 21 | 22 | print(startserver()) 23 | 24 | if not(arg[2] == 'test') then 25 | while true do 26 | MAIN_LOOP() 27 | C.usleep(CALCULATE_DT()*1000*1000) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #define ARM_PREFETCH_CYCLES (1 + cpu->memory.activeSeqCycles32) 12 | 13 | struct ARMCore; 14 | 15 | typedef void (*ARMInstruction)(struct ARMCore*, uint32_t opcode); 16 | extern const ARMInstruction _armTable[0x1000]; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/renderers/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 GBA_TILE_CACHE_H 7 | #define GBA_TILE_CACHE_H 8 | 9 | #include "util/common.h" 10 | 11 | struct GBAVideo; 12 | struct mTileCache; 13 | 14 | void GBAVideoTileCacheInit(struct mTileCache* cache); 15 | void GBAVideoTileCacheAssociate(struct mTileCache* cache, struct GBAVideo* video); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/extra/sharkport.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_SHARKPORT_H 7 | #define GBA_SHARKPORT_H 8 | 9 | #include "util/common.h" 10 | 11 | struct GBA; 12 | struct VFile; 13 | 14 | bool GBASavedataImportSharkPort(struct GBA* gba, struct VFile* vf, bool testChecksum); 15 | bool GBASavedataExportSharkPort(const struct GBA* gba, struct VFile* vf); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deps/include/mgba/util/arm-algo.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 ARM_ALGO_H 7 | #define ARM_ALGO_H 8 | 9 | #ifdef __arm__ 10 | void _to16Bit(uint16_t* dest, uint32_t* src, size_t words); 11 | 12 | #if defined(__ARM_NEON) 13 | void _neon2x(void* dest, void* src, int width, int height); 14 | void _neon4x(void* dest, void* src, int width, int height); 15 | #endif 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /deps/include/mgba/gba/rr/vbm.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 | #include "util/common.h" 7 | 8 | #include "gba/rr/rr.h" 9 | 10 | struct GBAVBMContext { 11 | struct GBARRContext d; 12 | 13 | bool isPlaying; 14 | 15 | struct VFile* vbmFile; 16 | int32_t inputOffset; 17 | }; 18 | 19 | void GBAVBMContextCreate(struct GBAVBMContext*); 20 | 21 | bool GBAVBMSetStream(struct GBAVBMContext*, struct VFile*); 22 | -------------------------------------------------------------------------------- /deps/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 | extern const char* const gitCommit; 10 | extern const char* const gitCommitShort; 11 | extern const char* const gitBranch; 12 | extern const int gitRevision; 13 | extern const char* const binaryName; 14 | extern const char* const projectName; 15 | extern const char* const projectVersion; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "gba/cheats.h" 10 | 11 | extern const uint32_t GBACheatProActionReplaySeeds[4]; 12 | 13 | bool GBACheatAddProActionReplayRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); 14 | int GBACheatProActionReplayProbability(uint32_t op1, uint32_t op2); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/lua/plat/love/mouse.lua: -------------------------------------------------------------------------------- 1 | function Mouse.Scan() 2 | local washeld = Mouse.isheld 3 | 4 | local isheld = love.mouse.isDown(1) 5 | 6 | if isheld then 7 | local xpad = Screen.bottom.width/4 8 | local ypad = Screen.top.height 9 | 10 | Mouse.x = love.mouse.getX() - xpad 11 | Mouse.y = love.mouse.getY() - ypad 12 | 13 | if Mouse.x < 0 or Mouse.x > Screen.bottom.width or Mouse.y < 0 then 14 | isheld = false 15 | end 16 | end 17 | 18 | 19 | Mouse.isheld = isheld 20 | Mouse.isdown = Mouse.isheld and not washeld 21 | Mouse.isup = washeld and not Mouse.isheld 22 | end 23 | -------------------------------------------------------------------------------- /deps/include/mgba/gb/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 | #ifdef USE_CLI_DEBUGGER 10 | #include "debugger/cli-debugger.h" 11 | 12 | struct GBCLIDebugger { 13 | struct CLIDebuggerSystem d; 14 | 15 | struct mCore* core; 16 | 17 | bool frameAdvance; 18 | bool inVblank; 19 | }; 20 | 21 | struct CLIDebuggerSystem* GBCLIDebuggerCreate(struct mCore*); 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/lua/plat/cmd/screen.lua: -------------------------------------------------------------------------------- 1 | function Screen.init() 2 | Screen.top.width = 400 3 | Screen.top.height = 240 4 | Screen.top.size = Screen.top.width*Screen.top.height*3 5 | Screen.top.pix = ffi.new('uint8_t[?]', Screen.top.size) 6 | 7 | Screen.bottom.width = 320 8 | Screen.bottom.height = 240 9 | Screen.bottom.size = Screen.bottom.width*Screen.bottom.height*3 10 | Screen.bottom.pix = ffi.new('uint8_t[?]', Screen.bottom.size) 11 | end 12 | 13 | function Screen.startframe() 14 | C.memset(Screen.top.pix, 0, Screen.top.size) 15 | C.memset(Screen.bottom.pix, 0, Screen.bottom.size) 16 | end 17 | 18 | function Screen.endframe() 19 | end 20 | -------------------------------------------------------------------------------- /deps/include/mgba/feature/gui/remap.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 GUI_REMAP_H 7 | #define GUI_REMAP_H 8 | 9 | #include "util/common.h" 10 | 11 | struct GUIInputKeys { 12 | const char* name; 13 | uint32_t id; 14 | const char* const* keyNames; 15 | size_t nKeys; 16 | }; 17 | 18 | struct GUIParams; 19 | struct mInputMap; 20 | 21 | void mGUIRemapKeys(struct GUIParams*, struct mInputMap*, const struct GUIInputKeys*); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | enum mCPUComponentType { 12 | CPU_COMPONENT_DEBUGGER, 13 | CPU_COMPONENT_CHEAT_DEVICE, 14 | CPU_COMPONENT_MAX 15 | }; 16 | 17 | struct mCPUComponent { 18 | uint32_t id; 19 | void (*init)(void* cpu, struct mCPUComponent* component); 20 | void (*deinit)(struct mCPUComponent* component); 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /deps/include/mgba/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 | #ifdef USE_CLI_DEBUGGER 10 | #include "debugger/cli-debugger.h" 11 | 12 | struct mCore; 13 | 14 | struct GBACLIDebugger { 15 | struct CLIDebuggerSystem d; 16 | 17 | struct mCore* core; 18 | 19 | bool frameAdvance; 20 | bool inVblank; 21 | }; 22 | 23 | struct GBACLIDebugger* GBACLIDebuggerCreate(struct mCore*); 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "core/version.h" 7 | 8 | const char* const gitCommit = "${GIT_COMMIT}"; 9 | const char* const gitCommitShort = "${GIT_COMMIT_SHORT}"; 10 | const char* const gitBranch = "${GIT_BRANCH}"; 11 | const int gitRevision = ${GIT_REV}; 12 | const char* const binaryName = "${BINARY_NAME}"; 13 | const char* const projectName = "${PROJECT_NAME}"; 14 | const char* const projectVersion = "${VERSION_STRING}"; 15 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct VFile; 12 | 13 | struct Patch { 14 | struct VFile* vf; 15 | 16 | size_t (*outputSize)(struct Patch* patch, size_t inSize); 17 | bool (*applyPatch)(struct Patch* patch, const void* in, size_t inSize, void* out, size_t outSize); 18 | }; 19 | 20 | bool loadPatch(struct VFile* vf, struct Patch* patch); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/lua/config.lua: -------------------------------------------------------------------------------- 1 | cheats = {} 2 | cheats.all_badges = false 3 | cheats.instawarp = true 4 | cheats.hide_pokemon_logo = true 5 | cheats.walk_thru_walls = false 6 | cheats.invisible2trainers = true 7 | cheats.skip_oak_speech = true 8 | cheats.fastwalk = true 9 | cheats.repel = false 10 | cheats.skip_intro = true 11 | cheats.bike = false 12 | cheats.always_win = false 13 | cheats.skip_follow_oak = false 14 | 15 | config = {} 16 | config.audio = NDSP_ON 17 | config.render_map = true 18 | config.render_mgba = true 19 | config.render_mgba_top = false 20 | config.use_custom_tiles = false 21 | config.show_hidden_sprites = false 22 | config.show_item_hex = false 23 | 24 | ROOT.config = config 25 | ROOT.cheats = cheats 26 | -------------------------------------------------------------------------------- /src/lua/env.lua: -------------------------------------------------------------------------------- 1 | Env = {} 2 | 3 | -- environments for running untrusted Lua code 4 | 5 | function Env.Empty() 6 | return {} 7 | end 8 | 9 | function Env.Basic() 10 | return table.copy{ 11 | table = table, 12 | next = next, 13 | pairs = pairs, 14 | print = print, 15 | select = select, 16 | tonumber = tonumber, 17 | tostring = tostring, 18 | type = type, 19 | unpack = unpack, 20 | string = string, 21 | math = math, 22 | os = { 23 | date = os.date, 24 | clock = os.clock, 25 | difftime = os.difftime, 26 | time = os.time, 27 | } 28 | } 29 | end 30 | return Env 31 | -------------------------------------------------------------------------------- /deps/include/mgba/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 | #endif 26 | -------------------------------------------------------------------------------- /src/lua/game.lua: -------------------------------------------------------------------------------- 1 | -- gmod 2 | Game = {} 3 | 4 | require 'wip.serverbrowser' 5 | RENDER_CALLBACKS = {} 6 | RENDER_CALLBACKS.lua_logo = require 'art.lua_logo' 7 | 8 | UPDATE_CALLBACKS = {} 9 | 10 | local firstrun = true 11 | function Game.render() 12 | if emu and not firstrun then 13 | emu:run() 14 | 15 | Red:run() 16 | Red:render() 17 | end 18 | if not firstrun and not emu then 19 | 20 | if ROMFILE then 21 | emu = Gameboy:new(ROMFILE) 22 | Red:reset() 23 | RENDER_CALLBACKS.lua_logo = nil 24 | end 25 | end 26 | firstrun = false 27 | 28 | for k,v in pairs(RENDER_CALLBACKS) do 29 | v() 30 | end 31 | end 32 | 33 | return Game 34 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "core/input.h" 10 | 11 | extern const struct mInputPlatformInfo GBAInputInfo; 12 | 13 | enum GBAKey { 14 | GBA_KEY_A = 0, 15 | GBA_KEY_B = 1, 16 | GBA_KEY_SELECT = 2, 17 | GBA_KEY_START = 3, 18 | GBA_KEY_RIGHT = 4, 19 | GBA_KEY_LEFT = 5, 20 | GBA_KEY_UP = 6, 21 | GBA_KEY_DOWN = 7, 22 | GBA_KEY_R = 8, 23 | GBA_KEY_L = 9, 24 | GBA_KEY_MAX, 25 | GBA_KEY_NONE = -1 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "arm/arm.h" 12 | #include "core/log.h" 13 | 14 | mLOG_DECLARE_CATEGORY(GBA_BIOS); 15 | 16 | void GBASwi16(struct ARMCore* cpu, int immediate); 17 | void GBASwi32(struct ARMCore* cpu, int immediate); 18 | 19 | uint32_t GBAChecksum(uint32_t* memory, size_t size); 20 | extern const uint32_t GBA_BIOS_CHECKSUM; 21 | extern const uint32_t GBA_DS_BIOS_CHECKSUM; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/lua/ui/button.lua: -------------------------------------------------------------------------------- 1 | function UI.Button(self, f, txt) 2 | local orig = self.draw or function() end 3 | function self:draw(scr, x, y) 4 | if Mouse.isup and self:contains_mouse() then 5 | self:pressed() 6 | end 7 | orig(self, scr, x, y) 8 | end 9 | self.pressed = f or self.pressed 10 | 11 | if txt then 12 | local label = UI.Label:new(txt) 13 | label.font = Font.Default 14 | label.fontsize = 12 15 | label.background_color = false 16 | label:paint() 17 | label.x = (self.width - label.width)/2 18 | label.y = (self.height - label.height)/2 19 | self.label = label 20 | self:add_subview(label) 21 | end 22 | return self 23 | end 24 | 25 | return UI.Button 26 | -------------------------------------------------------------------------------- /src/lua/wip/paint.lua: -------------------------------------------------------------------------------- 1 | local Paint = {} 2 | function lol(i) 3 | Paint.set_bitmap(Red.tiles[0x00][i]) 4 | end 5 | 6 | local function scalecopy(bmap, scale) 7 | end 8 | 9 | function Paint.set_bitmap(bmap) 10 | if bmap.channels ~= 3 then 11 | error('unsupported bmap') 12 | end 13 | self.bitmap = bmap 14 | self.canvas = Bitmap:new(bmap.pix, bmap.width, bmap.height, bmap.channels) 15 | local scale = math.floor(math.min(Screen.bottom.height/bmap.height, Screen.bottom.width/bmap.width)) 16 | self.canvas:scale(scale) 17 | end 18 | 19 | function Paint.render() 20 | if not self.bitmap then return end 21 | 22 | self.canvas:draw(Screen.bottom, 0, 0) 23 | end 24 | 25 | Paint.mode = { 26 | rendercallback = Paint.render, 27 | } 28 | return Paint 29 | -------------------------------------------------------------------------------- /deps/include/mgba/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 | -------------------------------------------------------------------------------- /src/lua/debug_menu.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | DebugMenu = Object.new(super) 3 | 4 | local debug_label = UI.Label:new() 5 | function DebugMenu.render() 6 | if emu and config.render_mgba then 7 | emu:render(Screen.bottom, 0, 0) 8 | end 9 | 10 | Toggler:render() 11 | 12 | if DEBUG_TEXT or not emu then 13 | local text 14 | if emu then 15 | text = tostring(DEBUG_TEXT) 16 | else 17 | text = 'ROM path: '..PATH..'/rom/' 18 | end 19 | if not(debug_label.text == text) then 20 | debug_label.text = text 21 | debug_label:paint() 22 | end 23 | debug_label:render(Screen.bottom, Screen.bottom.width - debug_label.width, Screen.bottom.height - debug_label.fontsize) 24 | end 25 | end 26 | 27 | return DebugMenu 28 | -------------------------------------------------------------------------------- /deps/include/mgba/util/nointro.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 NOINTRO_H 7 | #define NOINTRO_H 8 | 9 | #include "util/common.h" 10 | 11 | struct NoIntroGame { 12 | const char* name; 13 | const char* romName; 14 | const char* description; 15 | size_t size; 16 | uint32_t crc32; 17 | uint8_t md5[16]; 18 | uint8_t sha1[20]; 19 | bool verified; 20 | }; 21 | 22 | struct NoIntroDB; 23 | struct VFile; 24 | 25 | struct NoIntroDB* NoIntroDBLoad(struct VFile* vf); 26 | void NoIntroDBDestroy(struct NoIntroDB* db); 27 | bool NoIntroDBLookupGameByCRC(const struct NoIntroDB* db, uint32_t crc32, struct NoIntroGame* game); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/lua/wip/tmp.lua: -------------------------------------------------------------------------------- 1 | 2 | xx = {} 3 | oo = {} 4 | -- put this in lua/red/render/init.lua: 5 | -- if not xx[i] and not(pictureid == 0) and (is_player or (xblk >= 0 and yblk >= 0)) and (config.show_hidden_sprites or oo[i] or not(s1.SpriteImageIdx == 0xff) or not hidden_sprites[i]) then 6 | 7 | function print_missable_sprite_info() 8 | for i=0,red.wram.wNumSprites do 9 | local miss = red.wram.wMissableObjectList[i] 10 | if miss.id == 0xff then break end 11 | local s1 = red.wram.wSpriteStateData1[miss.id] 12 | print(string.format('%.2x %.2x %.2x ', miss.id, s1.SpriteImageIdx, miss.index)) 13 | end 14 | 15 | for i=0,4-1 do 16 | local s = '' 17 | for x=0,8-1 do 18 | s = s..string.format('%.2x', red.wram.wMissableObjectFlags[i*8 + x]) 19 | end 20 | print('') 21 | print(s) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /src/lua/preinit.lua: -------------------------------------------------------------------------------- 1 | ROOT = {} 2 | local path = LUAPATH..'/config/preautorun.lua' 3 | local f = io.open(path, 'r') 4 | if f then 5 | f:close() 6 | dofile(path) 7 | end 8 | 9 | 10 | 11 | ffi = require 'ffi' 12 | bit = require 'bit' 13 | 14 | require 'config' 15 | require 'cdef' 16 | require 'util' 17 | require 'env' 18 | 19 | require 'object' 20 | 21 | require 'font' 22 | require 'bitmap' 23 | require 'gif' 24 | 25 | Net = {} 26 | require 'net.server' 27 | require 'net.client' 28 | 29 | UI = {} 30 | require 'ui.view' 31 | require 'ui.label' 32 | require 'ui.picker' 33 | require 'ui.button' 34 | 35 | require 'screen' 36 | require 'button' 37 | require 'mouse' 38 | 39 | require 'keyboard' 40 | require 'display' 41 | require 'gameboy' 42 | require 'console' 43 | require 'toggler' 44 | require 'rom' 45 | require 'red' 46 | require 'tile_editor' 47 | require 'player' 48 | require 'ogg' 49 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct RingFIFO { 12 | void* data; 13 | size_t capacity; 14 | void* readPtr; 15 | void* writePtr; 16 | }; 17 | 18 | void RingFIFOInit(struct RingFIFO* buffer, size_t capacity); 19 | void RingFIFODeinit(struct RingFIFO* buffer); 20 | size_t RingFIFOCapacity(const struct RingFIFO* buffer); 21 | void RingFIFOClear(struct RingFIFO* buffer); 22 | size_t RingFIFOWrite(struct RingFIFO* buffer, const void* value, size_t length); 23 | size_t RingFIFORead(struct RingFIFO* buffer, void* output, size_t length); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | enum GBModel { 12 | GB_MODEL_AUTODETECT = 0xFF, 13 | GB_MODEL_DMG = 0x00, 14 | GB_MODEL_SGB = 0x40, 15 | GB_MODEL_CGB = 0x80, 16 | GB_MODEL_AGB = 0xC0 17 | }; 18 | 19 | enum GBMemoryBankControllerType { 20 | GB_MBC_AUTODETECT = -1, 21 | GB_MBC_NONE = 0, 22 | GB_MBC1 = 1, 23 | GB_MBC2 = 2, 24 | GB_MBC3 = 3, 25 | GB_MBC5 = 5, 26 | GB_MBC6 = 6, 27 | GB_MBC7 = 7, 28 | GB_MMM01 = 0x10, 29 | GB_HuC1 = 0x11, 30 | GB_HuC3 = 0x12, 31 | GB_MBC3_RTC = 0x103, 32 | GB_MBC5_RUMBLE = 0x105 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "gba/cheats.h" 10 | 11 | extern const uint32_t GBACheatGameSharkSeeds[4]; 12 | 13 | void GBACheatDecryptGameShark(uint32_t* op1, uint32_t* op2, const uint32_t* seeds); 14 | void GBACheatReseedGameShark(uint32_t* seeds, uint16_t params, const uint8_t* t1, const uint8_t* t2); 15 | void GBACheatSetGameSharkVersion(struct GBACheatSet* cheats, int version); 16 | bool GBACheatAddGameSharkRaw(struct GBACheatSet* cheats, uint32_t op1, uint32_t op2); 17 | int GBACheatGameSharkProbability(uint32_t op1, uint32_t op2); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "gb/interface.h" 12 | 13 | struct GBCartridgeOverride { 14 | int headerCrc32; 15 | enum GBModel model; 16 | enum GBMemoryBankControllerType mbc; 17 | }; 18 | 19 | struct Configuration; 20 | bool GBOverrideFind(const struct Configuration*, struct GBCartridgeOverride* override); 21 | void GBOverrideSave(struct Configuration*, const struct GBCartridgeOverride* override); 22 | 23 | struct GB; 24 | void GBOverrideApply(struct GB*, const struct GBCartridgeOverride*); 25 | void GBOverrideApplyDefaults(struct GB*); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/lua/cdef/desktop.lua: -------------------------------------------------------------------------------- 1 | local ext 2 | if ffi.os == 'Windows' then 3 | ext = 'dll' 4 | elseif ffi.os == 'OSX' then 5 | ext = 'dylib' 6 | else -- default to something like Linux or BSD 7 | ext = 'so' 8 | end 9 | ffi.mgba = ffi.load(PATH..'/deps/lib/love/libmgba.'..ext, true) 10 | ffi.luared = ffi.load(PATH..'/build/love/luared.'..ext, true) 11 | if ffi.os == 'Windows' then 12 | ffi.freetype = ffi.load(PATH..'/deps/lib/love/freetype6.dll') 13 | elseif PLATFORM == 'love' then 14 | ffi.freetype = ffi.C 15 | elseif NO_FREETYPE then 16 | ffi.freetype = {} 17 | else 18 | ffi.freetype = ffi.load'freetype' 19 | end 20 | 21 | if ffi.os == 'Linux' then 22 | O_CREAT = 0x40 23 | elseif ffi.os == 'Windows' then 24 | O_CREAT = 0x100 25 | elseif ffi.os == 'OSX' or ffi.os == 'BSD' then 26 | O_CREAT = 0x0200 27 | else 28 | error('unknown platform') 29 | end 30 | 31 | O_RDWR = 2 32 | SEEK_END = 2 33 | SEEK_SET = 0 34 | -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/ctr-gpu.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015 Yuri Kunde Schlesner 2 | * Copyright (c) 2016 Jeffrey Pfau 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 | 8 | #ifndef GUI_GPU_H 9 | #define GUI_GPU_H 10 | 11 | #include <3ds.h> 12 | #include 13 | 14 | bool ctrInitGpu(void); 15 | void ctrDeinitGpu(void); 16 | 17 | void ctrSetViewportSize(s16 w, s16 h, bool tilt); 18 | 19 | void ctrActivateTexture(C3D_Tex* texture); 20 | void ctrTextureMultiply(void); 21 | void ctrTextureBias(u32 color); 22 | void ctrAddRectEx(u32 color, s16 x, s16 y, s16 w, s16 h, s16 u, s16 v, s16 uw, s16 vh, float rotate); 23 | void ctrAddRect(u32 color, s16 x, s16 y, s16 u, s16 v, s16 w, s16 h); 24 | void ctrFlushBatch(void); 25 | void ctrFinalize(void); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/lua/art/lua_logo.lua: -------------------------------------------------------------------------------- 1 | local x = Screen.top.width/2 2 | local y = Screen.top.height/2 3 | local scale = Screen.top.height/4 4 | local moon_radius = 1 - math.sqrt(2)/2 5 | 6 | local dist_to_moon = scale/math.sin(math.pi/4) 7 | 8 | local period = 25.6 -- seconds it takes for moon to orbit 9 | local angle = 0 10 | 11 | LUA_COLOR = {0x8a, 0x0a, 0x2e} 12 | 13 | return function() 14 | angle = angle + DT*2*math.pi/period 15 | 16 | local r, g, b = unpack(LUA_COLOR) 17 | 18 | ffi.luared.draw_set_color(r, g, b) 19 | 20 | -- planet 21 | Screen.top:circle(x, y, scale) 22 | 23 | -- moon 24 | local moonx = x + math.cos(angle)*dist_to_moon 25 | local moony = y + math.sin(angle)*dist_to_moon 26 | Screen.top:circle(moonx, moony, scale*moon_radius) 27 | 28 | -- crater 29 | ffi.luared.draw_set_color(r/5, g/5, b/5) 30 | Screen.top:circle(x + scale*(1-2*moon_radius), y - scale*(1-2*moon_radius), scale*moon_radius) 31 | 32 | end 33 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | struct GB; 12 | struct GBSIO { 13 | struct GB* p; 14 | 15 | int32_t nextEvent; 16 | int32_t period; 17 | int remainingBits; 18 | 19 | uint8_t pendingSB; 20 | }; 21 | 22 | DECL_BITFIELD(GBRegisterSC, uint8_t); 23 | DECL_BIT(GBRegisterSC, ShiftClock, 0); 24 | DECL_BIT(GBRegisterSC, ClockSpeed, 1); 25 | DECL_BIT(GBRegisterSC, Enable, 7); 26 | 27 | void GBSIOInit(struct GBSIO* sio); 28 | void GBSIOReset(struct GBSIO* sio); 29 | void GBSIODeinit(struct GBSIO* sio); 30 | int32_t GBSIOProcessEvents(struct GBSIO* sio, int32_t cycles); 31 | void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "core/cheats.h" 12 | #include "util/vector.h" 13 | 14 | enum GBCheatType { 15 | GB_CHEAT_AUTODETECT, 16 | GB_CHEAT_GAMESHARK, 17 | GB_CHEAT_GAME_GENIE, 18 | GB_CHEAT_VBA 19 | }; 20 | 21 | struct GBCheatPatch { 22 | uint16_t address; 23 | int8_t newValue; 24 | int8_t oldValue; 25 | int segment; 26 | bool applied; 27 | bool checkByte; 28 | }; 29 | 30 | DECLARE_VECTOR(GBCheatPatchList, struct GBCheatPatch); 31 | 32 | struct GBCheatSet { 33 | struct mCheatSet d; 34 | struct GBCheatPatchList romPatches; 35 | }; 36 | 37 | struct mCheatDevice* GBCheatDeviceCreate(void); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "util/patch.h" 12 | #include "util/vector.h" 13 | 14 | #define PATCH_FAST_EXTENT 256 15 | 16 | struct PatchFastExtent { 17 | size_t length; 18 | size_t offset; 19 | uint32_t extent[PATCH_FAST_EXTENT]; 20 | }; 21 | 22 | DECLARE_VECTOR(PatchFastExtents, struct PatchFastExtent); 23 | 24 | struct PatchFast { 25 | struct Patch d; 26 | 27 | struct PatchFastExtents extents; 28 | }; 29 | 30 | void initPatchFast(struct PatchFast*); 31 | void deinitPatchFast(struct PatchFast*); 32 | bool diffPatchFast(struct PatchFast* patch, const void* restrict in, const void* restrict out, size_t size); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /deps/include/mgba/lr35902/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 | #include "debugger/debugger.h" 7 | 8 | struct LR35902DebugBreakpoint { 9 | uint16_t address; 10 | int segment; 11 | }; 12 | 13 | struct LR35902DebugWatchpoint { 14 | uint16_t address; 15 | int segment; 16 | enum mWatchpointType type; 17 | }; 18 | 19 | DECLARE_VECTOR(LR35902DebugBreakpointList, struct LR35902DebugBreakpoint); 20 | DECLARE_VECTOR(LR35902DebugWatchpointList, struct LR35902DebugWatchpoint); 21 | 22 | struct LR35902Debugger { 23 | struct mDebuggerPlatform d; 24 | struct LR35902Core* cpu; 25 | 26 | struct LR35902DebugBreakpointList breakpoints; 27 | struct LR35902DebugWatchpointList watchpoints; 28 | }; 29 | 30 | struct mDebuggerPlatform* LR35902DebuggerPlatformCreate(void); 31 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "gba/savedata.h" 12 | 13 | #define IDLE_LOOP_NONE 0xFFFFFFFF 14 | 15 | struct GBACartridgeOverride { 16 | char id[4]; 17 | enum SavedataType savetype; 18 | int hardware; 19 | uint32_t idleLoop; 20 | bool mirroring; 21 | }; 22 | 23 | struct Configuration; 24 | bool GBAOverrideFind(const struct Configuration*, struct GBACartridgeOverride* override); 25 | void GBAOverrideSave(struct Configuration*, const struct GBACartridgeOverride* override); 26 | 27 | struct GBA; 28 | void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*); 29 | void GBAOverrideApplyDefaults(struct GBA*); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "core/core.h" 12 | #include "gb/gb.h" 13 | #include "gb/video.h" 14 | 15 | struct GBVideoSoftwareRenderer { 16 | struct GBVideoRenderer d; 17 | 18 | color_t* outputBuffer; 19 | int outputBufferStride; 20 | 21 | uint8_t row[GB_VIDEO_HORIZONTAL_PIXELS + 8]; 22 | 23 | color_t palette[128]; 24 | 25 | uint32_t* temporaryBuffer; 26 | 27 | uint8_t scy; 28 | uint8_t scx; 29 | uint8_t wy; 30 | uint8_t wx; 31 | uint8_t currentWy; 32 | 33 | GBRegisterLCDC lcdc; 34 | enum GBModel model; 35 | }; 36 | 37 | void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "util/vector.h" 12 | 13 | DECLARE_VECTOR(mCoreRewindPatches, struct PatchFast); 14 | 15 | struct VFile; 16 | struct mCoreRewindContext { 17 | struct mCoreRewindPatches patchMemory; 18 | size_t current; 19 | size_t size; 20 | struct VFile* previousState; 21 | struct VFile* currentState; 22 | }; 23 | 24 | void mCoreRewindContextInit(struct mCoreRewindContext*, size_t entries); 25 | void mCoreRewindContextDeinit(struct mCoreRewindContext*); 26 | 27 | struct mCore; 28 | void mCoreRewindAppend(struct mCoreRewindContext*, struct mCore*); 29 | bool mCoreRewindRestore(struct mCoreRewindContext*, struct mCore*); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: required 3 | matrix: 4 | include: 5 | - os: linux 6 | dist: trusty 7 | compiler: gcc 8 | install: 9 | - |- 10 | sudo apt-get clean && 11 | sudo apt-get update && 12 | sudo apt-get install -y -q luajit && 13 | git clone https://github.com/rweichler/aite build/.aite && 14 | git clone https://github.com/N64N64/mgba && 15 | git clone --recursive https://github.com/pret/pokered --depth=50 && 16 | path="$(pwd)"; cd; 17 | wget https://github.com/rednex/rgbds/archive/v0.2.5.tar.gz -O rgbds.tar.gz && 18 | tar xf rgbds.tar.gz && 19 | cd rgbds-0.2.5 && 20 | sudo make install && 21 | cd - && 22 | rm -rf rgbds && cd "$path" && 23 | cd pokered && make && cd "$path" 24 | cd mgba && luajit ../build/.aite/main.lua && mkdir -p ../deps/lib/love && cp build_aite/libmgba.so ../deps/lib/love/ && cd "$path" && mkdir rom 25 | 26 | script: ./compile.lua love && ./compile.lua update_devkitarm && ./compile.lua 3ds && ./main.lua pokered/pokered.gbc test 27 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "locale.h" 12 | 13 | #if defined(__APPLE__) || defined(__FreeBSD__) 14 | #include "xlocale.h" 15 | #elif !defined(HAVE_LOCALE) 16 | typedef const char* locale_t; 17 | #endif 18 | 19 | int ftostr_l(char* restrict str, size_t size, float f, locale_t locale); 20 | 21 | #ifndef HAVE_STRTOF_L 22 | float strtof_l(const char* restrict str, char** restrict end, locale_t locale); 23 | #endif 24 | 25 | int ftostr_u(char* restrict str, size_t size, float f); 26 | float strtof_u(const char* restrict str, char** restrict end); 27 | 28 | #ifndef HAVE_LOCALTIME_R 29 | struct tm* localtime_r(const time_t* timep, struct tm* result); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/uishader.v.pica: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2015 Yuri Kunde Schlesner 2 | ; Copyright (c) 2016 Jeffrey Pfau 3 | 4 | ; 5 | ; This Source Code Form is subject to the terms of the Mozilla Public 6 | ; License, v. 2.0. If a copy of the MPL was not distributed with this 7 | ; file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | 9 | ; uishader.vsh - Simply multiplies input position and texcoords with 10 | ; corresponding matrices before outputting 11 | 12 | ; Uniforms 13 | 14 | ; Constants 15 | .constf consts1(0.0, 1.0, 0.0039215686, -1.0) 16 | 17 | ; Outputs 18 | .out out_pos position 19 | .out out_tc0 texcoord0 20 | .out out_col color 21 | .out out_rot dummy 22 | 23 | ; Inputs 24 | .alias in_pos v0 25 | .alias in_tc0 v1 26 | .alias in_col v2 27 | .alias in_rot v3 28 | 29 | .entry vshMain 30 | .proc vshMain 31 | mov out_pos, in_pos 32 | mov out_tc0, in_tc0 33 | mul out_rot, consts1.ywyx, in_rot.xyy 34 | 35 | ; Normalize color by multiplying by 1 / 255 36 | mul out_col, consts1.z, in_col 37 | 38 | end 39 | .end 40 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "core/core.h" 12 | #include "util/vector.h" 13 | 14 | struct mLibraryEntry { 15 | char* filename; 16 | char* title; 17 | char internalTitle[17]; 18 | char internalCode[9]; 19 | size_t filesize; 20 | enum mPlatform platform; 21 | }; 22 | 23 | DECLARE_VECTOR(mLibraryListing, struct mLibraryEntry); 24 | 25 | struct mLibrary { 26 | struct mLibraryListing listing; 27 | }; 28 | 29 | void mLibraryInit(struct mLibrary*); 30 | void mLibraryDeinit(struct mLibrary*); 31 | 32 | struct VDir; 33 | struct VFile; 34 | void mLibraryLoadDirectory(struct mLibrary* library, struct VDir* dir); 35 | void mLibraryAddEntry(struct mLibrary* library, const char* filename, struct VFile* vf); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/lua/plat/love/init.lua: -------------------------------------------------------------------------------- 1 | function love.load() 2 | PLATFORM = 'love' 3 | PATH = love.filesystem.getSource() 4 | while string.sub(PATH, #PATH, #PATH) == '/' do 5 | PATH = string.sub(PATH, 1, #PATH - 1) 6 | end 7 | LUAPATH = PATH..'/src/lua' 8 | package.path = LUAPATH..'/?.lua;' 9 | ..LUAPATH..'/?/init.lua;' 10 | ..package.path 11 | require 'preinit' 12 | require 'plat.love.util' 13 | require 'init' 14 | love.window.setMode(Screen.top.width, Screen.top.height + Screen.bottom.height) 15 | love.window.setTitle('3DS Simulator') 16 | end 17 | 18 | function CALCULATE_DT() 19 | return DT 20 | end 21 | 22 | function love.update(dt) 23 | DT = dt 24 | if MAIN_LOOP() then 25 | love.event.quit() 26 | end 27 | end 28 | 29 | function love.draw() 30 | love.graphics.setBackgroundColor(90, 30, 30) 31 | love.graphics.setColor(255, 255, 255) 32 | love.graphics.draw(Screen.top.love, 0, Screen.top.height, -math.pi/2) 33 | love.graphics.draw(Screen.bottom.love, Screen.bottom.width/4, Screen.top.height + Screen.bottom.height, -math.pi/2) 34 | end 35 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/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 "util/common.h" 13 | 14 | enum GBAVFameCartType { 15 | VFAME_NO = 0, 16 | VFAME_STANDARD = 1, 17 | VFAME_GEORGE = 2 18 | }; 19 | 20 | struct GBAVFameCart { 21 | enum GBAVFameCartType cartType; 22 | int sramMode; 23 | int romMode; 24 | int8_t writeSequence[5]; 25 | bool acceptingModeChange; 26 | }; 27 | 28 | void GBAVFameInit(struct GBAVFameCart* cart); 29 | void GBAVFameDetect(struct GBAVFameCart* cart, uint32_t* rom, size_t romSize); 30 | void GBAVFameSramWrite(struct GBAVFameCart* cart, uint32_t address, uint8_t value, uint8_t* sramData); 31 | uint32_t GBAVFameModifyRomAddress(struct GBAVFameCart* cart, uint32_t address, size_t romSize); 32 | uint32_t GBAVFameGetPatternValue(uint32_t address, int bits); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "core/log.h" 12 | 13 | mLOG_DECLARE_CATEGORY(GB_MBC); 14 | 15 | struct GB; 16 | struct GBMemory; 17 | void GBMBCInit(struct GB* gb); 18 | void GBMBCSwitchBank(struct GBMemory* memory, int bank); 19 | void GBMBCSwitchSramBank(struct GB* gb, int bank); 20 | 21 | struct GBMBCRTCSaveBuffer { 22 | uint32_t sec; 23 | uint32_t min; 24 | uint32_t hour; 25 | uint32_t days; 26 | uint32_t daysHi; 27 | uint32_t latchedSec; 28 | uint32_t latchedMin; 29 | uint32_t latchedHour; 30 | uint32_t latchedDays; 31 | uint32_t latchedDaysHi; 32 | uint64_t unixTime; 33 | }; 34 | void GBMBCRTCRead(struct GB* gb); 35 | void GBMBCRTCWrite(struct GB* gb); 36 | 37 | uint8_t GBMBC7Read(struct GBMemory*, uint16_t address); 38 | void GBMBC7Write(struct GBMemory*, uint16_t address, uint8_t value); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /deps/include/mgba/feature/imagemagick/imagemagick-gif-encoder.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 IMAGEMAGICK_GIF_ENCODER 7 | #define IMAGEMAGICK_GIF_ENCODER 8 | 9 | #include "gba/gba.h" 10 | 11 | #define MAGICKCORE_HDRI_ENABLE 0 12 | #define MAGICKCORE_QUANTUM_DEPTH 8 13 | 14 | #include 15 | 16 | struct ImageMagickGIFEncoder { 17 | struct mAVStream d; 18 | MagickWand* wand; 19 | char* outfile; 20 | uint32_t* frame; 21 | 22 | unsigned currentFrame; 23 | int frameskip; 24 | int delayMs; 25 | 26 | unsigned iwidth; 27 | unsigned iheight; 28 | }; 29 | 30 | void ImageMagickGIFEncoderInit(struct ImageMagickGIFEncoder*); 31 | void ImageMagickGIFEncoderSetParams(struct ImageMagickGIFEncoder* encoder, int frameskip, int delayMs); 32 | bool ImageMagickGIFEncoderOpen(struct ImageMagickGIFEncoder*, const char* outfile); 33 | bool ImageMagickGIFEncoderClose(struct ImageMagickGIFEncoder*); 34 | bool ImageMagickGIFEncoderIsOpen(struct ImageMagickGIFEncoder*); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/renderers/thread-proxy.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_THREAD_PROXY_H 7 | #define VIDEO_THREAD_PROXY_H 8 | 9 | #include "gba/video.h" 10 | #include "util/threading.h" 11 | #include "util/ring-fifo.h" 12 | 13 | enum GBAVideoThreadProxyState { 14 | PROXY_THREAD_STOPPED = 0, 15 | PROXY_THREAD_IDLE, 16 | PROXY_THREAD_BUSY 17 | }; 18 | 19 | struct GBAVideoThreadProxyRenderer { 20 | struct GBAVideoRenderer d; 21 | struct GBAVideoRenderer* backend; 22 | 23 | Thread thread; 24 | Condition fromThreadCond; 25 | Condition toThreadCond; 26 | Mutex mutex; 27 | enum GBAVideoThreadProxyState threadState; 28 | 29 | struct RingFIFO dirtyQueue; 30 | 31 | uint32_t vramDirtyBitmap; 32 | uint32_t oamDirtyBitmap[16]; 33 | 34 | uint16_t* vramProxy; 35 | union GBAOAM oamProxy; 36 | uint16_t paletteProxy[512]; 37 | }; 38 | 39 | void GBAVideoThreadProxyRendererCreate(struct GBAVideoThreadProxyRenderer* renderer, struct GBAVideoRenderer* backend); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | DECL_BITFIELD(GBRegisterTAC, uint8_t); 12 | DECL_BITS(GBRegisterTAC, Clock, 0, 2); 13 | DECL_BIT(GBRegisterTAC, Run, 2); 14 | 15 | enum { 16 | GB_DMG_DIV_PERIOD = 16 17 | }; 18 | 19 | struct GB; 20 | struct GBTimer { 21 | struct GB* p; 22 | 23 | int32_t nextEvent; 24 | int32_t eventDiff; 25 | 26 | uint32_t internalDiv; 27 | int32_t nextDiv; 28 | uint32_t timaPeriod; 29 | bool irqPending; 30 | }; 31 | 32 | void GBTimerReset(struct GBTimer*); 33 | int32_t GBTimerProcessEvents(struct GBTimer*, int32_t cycles); 34 | void GBTimerDivReset(struct GBTimer*); 35 | uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac); 36 | 37 | struct GBSerializedState; 38 | void GBTimerSerialize(const struct GBTimer* timer, struct GBSerializedState* state); 39 | void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* state); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/lua/plat/love/button.lua: -------------------------------------------------------------------------------- 1 | local citra = { 2 | a = Button.a, 3 | s = Button.b, 4 | up = Button.cpad_up, 5 | down = Button.cpad_down, 6 | left = Button.cpad_left, 7 | right = Button.cpad_right, 8 | m = Button.start, 9 | n = Button.select, 10 | t = Button.dup, 11 | g = Button.ddown, 12 | f = Button.dleft, 13 | h = Button.dright, 14 | i = Button.cstick_up, 15 | k = Button.cstick_down, 16 | j = Button.cstick_left, 17 | l = Button.cstick_right, 18 | z = Button.x, 19 | x = Button.y, 20 | ['1'] = Button.zl, 21 | ['2'] = Button.zr, 22 | } 23 | 24 | function Button.Scan() 25 | local lastheld = Button.KeysHeld 26 | 27 | Button.KeysHeld = 0 28 | Button.KeysDown = 0 29 | Button.KeysUp = 0 30 | 31 | for k,v in pairs(citra) do 32 | if love.keyboard.isDown(k) then 33 | Button.KeysHeld = bit.bor(Button.KeysHeld, v) 34 | if not(bit.band(lastheld, v) ~= 0) then -- wasnt held last frame 35 | Button.KeysDown = bit.bor(Button.KeysDown, v) 36 | end 37 | elseif bit.band(lastheld, v) ~= 0 then -- was held last frame 38 | Button.KeysUp = bit.bor(Button.KeysUp, v) 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **NOTE:** For both platforms, you must supply your own symfile and ROM and place them in the `rom` directory (create it if it does not exist). The symfile must have the same basename as the rom. So, for example, if your ROM was named `example.gb`, your symfile must be named `example.sym`. 2 | 3 | ### 3DS Build 4 | 5 | Linux / Mac only. 6 | 7 | 1. Install LuaJIT 8 | 2. Run `./compile.lua 3ds`. It will take a while. 9 | 10 | Then, copy `build/luared.3dsx`, `build/luared.smdh`, the `lua` folder, and the `res` folder to the `/3ds/luared` folder on your SD card. 11 | 12 | ### Build for Mac / Linux / Windows 13 | 14 | 1. Compile [this mGBA edit](https://github.com/N64N64/mgba) and then copy libmgba.dll or libmgba.so or libmgba.dylib (depending on your OS) to `deps/lib/love/` in this repo. Create the directories if they don't exist. 15 | 2. Install LuaJIT, zlib, and [löve2d](https://love2d.org/) (0.10.2 or newer) 16 | 3. Windows: Put [this .dll](https://github.com/N64N64/mgba/releases/download/1/freetype6.dll) in `deps\lib\love` 17 | 4. Run `./compile.lua love` (Windows: `luajit.exe compile.lua`) 18 | 19 | Open the LÖVE executable with the repo directory to run it. 20 | 21 | ### IRC 22 | 23 | [#luared](https://kiwiirc.com/client/irc.freenode.net?channel=#luared) on freenode 24 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "debugger/debugger.h" 12 | 13 | #include "util/socket.h" 14 | 15 | #define GDB_STUB_MAX_LINE 1200 16 | #define GDB_STUB_INTERVAL 32 17 | 18 | enum GDBStubAckState { 19 | GDB_ACK_PENDING = 0, 20 | GDB_ACK_RECEIVED, 21 | GDB_NAK_RECEIVED, 22 | GDB_ACK_OFF 23 | }; 24 | 25 | struct GDBStub { 26 | struct mDebugger d; 27 | 28 | char line[GDB_STUB_MAX_LINE]; 29 | char outgoing[GDB_STUB_MAX_LINE]; 30 | enum GDBStubAckState lineAck; 31 | 32 | Socket socket; 33 | Socket connection; 34 | 35 | bool shouldBlock; 36 | int untilPoll; 37 | 38 | bool supportsSwbreak; 39 | bool supportsHwbreak; 40 | }; 41 | 42 | void GDBStubCreate(struct GDBStub*); 43 | bool GDBStubListen(struct GDBStub*, int port, const struct Address* bindAddress); 44 | 45 | void GDBStubHangup(struct GDBStub*); 46 | void GDBStubShutdown(struct GDBStub*); 47 | 48 | void GDBStubUpdate(struct GDBStub*); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "util/threading.h" 12 | 13 | struct mCoreSync { 14 | int videoFramePending; 15 | bool videoFrameWait; 16 | bool videoFrameOn; 17 | Mutex videoFrameMutex; 18 | Condition videoFrameAvailableCond; 19 | Condition videoFrameRequiredCond; 20 | 21 | bool audioWait; 22 | Condition audioRequiredCond; 23 | Mutex audioBufferMutex; 24 | 25 | float fpsTarget; 26 | }; 27 | 28 | void mCoreSyncPostFrame(struct mCoreSync* sync); 29 | void mCoreSyncForceFrame(struct mCoreSync* sync); 30 | bool mCoreSyncWaitFrameStart(struct mCoreSync* sync); 31 | void mCoreSyncWaitFrameEnd(struct mCoreSync* sync); 32 | void mCoreSyncSetVideoSync(struct mCoreSync* sync, bool wait); 33 | 34 | void mCoreSyncProduceAudio(struct mCoreSync* sync, bool wait); 35 | void mCoreSyncLockAudio(struct mCoreSync* sync); 36 | void mCoreSyncUnlockAudio(struct mCoreSync* sync); 37 | void mCoreSyncConsumeAudio(struct mCoreSync* sync); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /deps/include/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Standard library header. 3 | ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LUALIB_H 7 | #define _LUALIB_H 8 | 9 | #include "lua.h" 10 | 11 | #define LUA_FILEHANDLE "FILE*" 12 | 13 | #define LUA_COLIBNAME "coroutine" 14 | #define LUA_MATHLIBNAME "math" 15 | #define LUA_STRLIBNAME "string" 16 | #define LUA_TABLIBNAME "table" 17 | #define LUA_IOLIBNAME "io" 18 | #define LUA_OSLIBNAME "os" 19 | #define LUA_LOADLIBNAME "package" 20 | #define LUA_DBLIBNAME "debug" 21 | #define LUA_BITLIBNAME "bit" 22 | #define LUA_JITLIBNAME "jit" 23 | #define LUA_FFILIBNAME "ffi" 24 | 25 | LUALIB_API int luaopen_base(lua_State *L); 26 | LUALIB_API int luaopen_math(lua_State *L); 27 | LUALIB_API int luaopen_string(lua_State *L); 28 | LUALIB_API int luaopen_table(lua_State *L); 29 | LUALIB_API int luaopen_io(lua_State *L); 30 | LUALIB_API int luaopen_os(lua_State *L); 31 | LUALIB_API int luaopen_package(lua_State *L); 32 | LUALIB_API int luaopen_debug(lua_State *L); 33 | LUALIB_API int luaopen_bit(lua_State *L); 34 | LUALIB_API int luaopen_jit(lua_State *L); 35 | LUALIB_API int luaopen_ffi(lua_State *L); 36 | 37 | LUALIB_API void luaL_openlibs(lua_State *L); 38 | 39 | #ifndef lua_assert 40 | #define lua_assert(x) ((void)0) 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/lua/gif.lua: -------------------------------------------------------------------------------- 1 | local super = require 'bitmap' 2 | Gif = Object.new(super) 3 | 4 | function Gif.new(_, self, frames) 5 | if not(getmetatable(self).__index == Bitmap) then 6 | error('must be a bitmap') 7 | end 8 | assert(math.floor(frames) == frames) 9 | getmetatable(self).__index = Gif 10 | self.frames = frames or 1 11 | self.height = self.height / frames 12 | return self 13 | end 14 | 15 | function Gif:set_frames(frames) 16 | local pix = ffi.new('uint8_t[?]', ffi.sizeof(self.pix)*frames/self.frames) 17 | ffi.copy(pix, self.pix, math.min(ffi.sizeof(self.pix), ffi.sizeof(pix))) 18 | self.pix = pix 19 | self.frames = frames 20 | end 21 | 22 | function Gif:draw(frame, scr, x, y) 23 | local off = frame*self.width*self.height*self.channels 24 | ffi.luared.dumbcopy( 25 | scr.pix, scr.width, scr.height, x, y, 26 | self.pix + off, self.width, self.height, 3 27 | ) 28 | end 29 | 30 | function Gif:drawaf(frame, scr, x, y, should_flip) 31 | local off = frame*self.width*self.height*self.channels 32 | ffi.luared.dumbcopyaf( 33 | scr.pix, scr.width, scr.height, x, y, 34 | self.pix + off, self.width, self.height, SPRITE_INVIS_COLOR, should_flip and true or false 35 | ) 36 | end 37 | 38 | getmetatable(Gif).__call = Gif.new 39 | return Gif 40 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/interface.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_INTERFACE_H 7 | #define GBA_INTERFACE_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "core/interface.h" 12 | 13 | enum GBASIOMode { 14 | SIO_NORMAL_8 = 0, 15 | SIO_NORMAL_32 = 1, 16 | SIO_MULTI = 2, 17 | SIO_UART = 3, 18 | SIO_GPIO = 8, 19 | SIO_JOYBUS = 12 20 | }; 21 | 22 | struct GBA; 23 | struct GBAAudio; 24 | struct GBASIO; 25 | struct GBAVideoRenderer; 26 | 27 | extern const int GBA_LUX_LEVELS[10]; 28 | 29 | struct GBALuminanceSource { 30 | void (*sample)(struct GBALuminanceSource*); 31 | 32 | uint8_t (*readLuminance)(struct GBALuminanceSource*); 33 | }; 34 | 35 | struct GBASIODriver { 36 | struct GBASIO* p; 37 | 38 | bool (*init)(struct GBASIODriver* driver); 39 | void (*deinit)(struct GBASIODriver* driver); 40 | bool (*load)(struct GBASIODriver* driver); 41 | bool (*unload)(struct GBASIODriver* driver); 42 | uint16_t (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); 43 | int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles); 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 12 | struct VDir; 13 | 14 | struct mDirectorySet { 15 | char baseName[PATH_MAX]; 16 | struct VDir* base; 17 | struct VDir* archive; 18 | struct VDir* save; 19 | struct VDir* patch; 20 | struct VDir* state; 21 | struct VDir* screenshot; 22 | }; 23 | 24 | void mDirectorySetInit(struct mDirectorySet* dirs); 25 | void mDirectorySetDeinit(struct mDirectorySet* dirs); 26 | 27 | void mDirectorySetAttachBase(struct mDirectorySet* dirs, struct VDir* base); 28 | void mDirectorySetDetachBase(struct mDirectorySet* dirs); 29 | 30 | struct VFile* mDirectorySetOpenPath(struct mDirectorySet* dirs, const char* path, bool (*filter)(struct VFile*)); 31 | struct VFile* mDirectorySetOpenSuffix(struct mDirectorySet* dirs, struct VDir* dir, const char* suffix, int mode); 32 | 33 | struct mCoreOptions; 34 | void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptions* opts); 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/screen.lua: -------------------------------------------------------------------------------- 1 | local size = ffi.new('uint16_t[2]') 2 | function Screen.init() 3 | C.gfxInitDefault() 4 | C.lua_initted_gfx = true 5 | 6 | C.gfxGetFramebuffer(GFX_TOP, GFX_LEFT, size+0, size+1) 7 | Screen.top.width = size[1] 8 | Screen.top.height = size[0] 9 | Screen.top.size = Screen.top.width*Screen.top.height*3 10 | Screen.top.pix = ffi.new('uint8_t[?]', Screen.top.size) 11 | 12 | C.gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, size+0, size+1) 13 | Screen.bottom.width = size[1] 14 | Screen.bottom.height = size[0] 15 | Screen.bottom.size = Screen.bottom.width*Screen.bottom.height*3 16 | Screen.bottom.pix = ffi.new('uint8_t[?]', Screen.bottom.size) 17 | end 18 | 19 | function Screen.startframe() 20 | C.memset(Screen.top.pix, 0, Screen.top.size) 21 | C.memset(Screen.bottom.pix, 0, Screen.bottom.size) 22 | end 23 | 24 | function Screen.endframe() 25 | local pix = C.gfxGetFramebuffer(GFX_TOP, GFX_LEFT, size+0, size+1) 26 | C.lastcopy(pix, Screen.top.pix, Screen.top.width, Screen.top.height) 27 | local pix = C.gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, size+0, size+1) 28 | C.lastcopy(pix, Screen.bottom.pix, Screen.bottom.width, Screen.bottom.height) 29 | C.gfxFlushBuffers() 30 | C.gfxSwapBuffers() 31 | C.gspWaitForEvent(GSPGPU_EVENT_VBlank0, true) 32 | end 33 | -------------------------------------------------------------------------------- /src/lua/wip/debugserver.lua: -------------------------------------------------------------------------------- 1 | local debugserver = {} 2 | 3 | local buf 4 | local connfd = -1 5 | local hostname = ffi.new('char[200]') 6 | C.gethostname(hostname, ffi.sizeof(hostname)) 7 | hostname = ffi.string(hostname) 8 | local port = 27716 9 | 10 | function disconnect() 11 | C.closesocket(connfd) 12 | connfd = -1 13 | buf = nil 14 | end 15 | 16 | function debugserver:run() 17 | if connfd == -1 then 18 | buf = ffi.new('char[512]') 19 | connfd = C.server_getconnection(port) 20 | write('get', 0, 21) 21 | elseif buf then 22 | C.recv(connfd, buf, ffi.sizeof(buf), 0) 23 | local len = 0 24 | for i=0,ffi.sizeof(buf)-1 do 25 | if buf[i] == string.byte('\n') then 26 | len = i 27 | break 28 | end 29 | end 30 | local f, err = load(ffi.string(buf, len)) 31 | if f then 32 | local success, result = pcall(f) 33 | if not success then 34 | result = 'err: '..result 35 | end 36 | write(tostring(result), 0, 24) 37 | else 38 | write('lerr: '..err, 0, 24) 39 | end 40 | end 41 | 42 | write(hostname..':'..port, 0, 20) 43 | write(' connfd: '..connfd, 0, 22) 44 | write('listenfd: '..C._listenfd, 0, 23) 45 | end 46 | 47 | return debugserver 48 | -------------------------------------------------------------------------------- /src/lua/button.lua: -------------------------------------------------------------------------------- 1 | Button = { 2 | a = 0, 3 | b = 1, 4 | select = 2, 5 | start = 3, 6 | dright = 4, 7 | dleft = 5, 8 | dup = 6, 9 | ddown = 7, 10 | r = 8, 11 | l = 9, 12 | x = 10, 13 | y = 11, 14 | zl = 14, 15 | zr = 15, 16 | touch = 20, 17 | cstick_right = 24, 18 | cstick_left = 25, 19 | cstick_up = 26, 20 | cstick_down = 27, 21 | cpad_right = 28, 22 | cpad_left = 29, 23 | cpad_up = 30, 24 | cpad_down = 31, 25 | } 26 | for k,v in pairs(Button) do 27 | Button[k] = bit.lshift(1, v) 28 | end 29 | Button.right = bit.bor(Button.dright, Button.cpad_right) 30 | Button.left = bit.bor(Button.dleft, Button.cpad_left) 31 | Button.up = bit.bor(Button.dup, Button.cpad_up) 32 | Button.down = bit.bor(Button.ddown, Button.cpad_down) 33 | 34 | for k,v in pairs(Button) do 35 | Button[string.upper(k)] = v 36 | end 37 | 38 | Button.KeysHeld = 0 39 | Button.KeysDown = 0 40 | Button.KeysUp = 0 41 | 42 | function Button.isdown(key) 43 | return bit.band(Button.KeysDown, key) ~= 0 44 | end 45 | 46 | function Button.isup(key) 47 | return bit.band(Button.KeysUp, key) ~= 0 48 | end 49 | 50 | function Button.isheld(key) 51 | return bit.band(Button.KeysHeld, key) ~= 0 52 | end 53 | 54 | if PLATFORM == 'cmd' then 55 | function Button.Scan() end 56 | else 57 | require('plat.'..PLATFORM..'.button') 58 | end 59 | 60 | return Button 61 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #ifdef _WIN32 12 | #include 13 | typedef HWND WHandle; 14 | #else 15 | typedef void* WHandle; 16 | #endif 17 | 18 | struct VideoBackend { 19 | void (*init)(struct VideoBackend*, WHandle handle); 20 | void (*deinit)(struct VideoBackend*); 21 | void (*setDimensions)(struct VideoBackend*, unsigned width, unsigned height); 22 | void (*swap)(struct VideoBackend*); 23 | void (*clear)(struct VideoBackend*); 24 | void (*resized)(struct VideoBackend*, unsigned w, unsigned h); 25 | void (*postFrame)(struct VideoBackend*, const void* frame); 26 | void (*drawFrame)(struct VideoBackend*); 27 | void (*setMessage)(struct VideoBackend*, const char* message); 28 | void (*clearMessage)(struct VideoBackend*); 29 | 30 | void* user; 31 | unsigned width; 32 | unsigned height; 33 | 34 | bool filter; 35 | bool lockAspectRatio; 36 | }; 37 | 38 | struct VideoShader { 39 | const char* name; 40 | const char* author; 41 | const char* description; 42 | void* preprocessShader; 43 | void* passes; 44 | size_t nPasses; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/lua/display.lua: -------------------------------------------------------------------------------- 1 | DISPLAY = {} 2 | 3 | local current 4 | local function swap(new) 5 | current = new 6 | 7 | for k,v in pairs(DISPLAY) do 8 | DISPLAY[k] = nil 9 | end 10 | end 11 | local function call(_, ...) 12 | if not ... then return current[1] end 13 | 14 | swap{...} 15 | Keyboard.callbacks.display = function(...) 16 | for _,v in ipairs(current) do 17 | v.key(...) 18 | end 19 | end 20 | 21 | end 22 | 23 | local function map(t, k) 24 | local result 25 | local typ = type(current[1][k]) 26 | if typ == 'function' then 27 | result = function() 28 | for _,v in ipairs(current) do 29 | local f = v[k] 30 | if f then 31 | f(v) 32 | end 33 | end 34 | end 35 | else 36 | error('nyi') 37 | end 38 | rawset(DISPLAY, k, result) 39 | return result 40 | end 41 | local function index(t, k) 42 | if type(k) == 'number' then 43 | return current[k] 44 | else 45 | return map(t, k) 46 | end 47 | end 48 | 49 | local function newindex(t, k, v) 50 | if type(k) == 'number' then 51 | current[k] = v 52 | swap(current) 53 | else 54 | error('not allowed') 55 | end 56 | end 57 | 58 | return setmetatable(DISPLAY, { 59 | __call = call, 60 | __index = index, 61 | __newindex = newindex, 62 | }) 63 | -------------------------------------------------------------------------------- /src/lua/red/dex.lua: -------------------------------------------------------------------------------- 1 | Red.Dex = {} 2 | 3 | -- mons 4 | 5 | Red.Dex.Species = {} 6 | 7 | for i=1,190 do 8 | local mon = {} 9 | mon.species = i 10 | mon.no = Red.rom.PokedexOrder[mon.species-1] 11 | mon.name = Red.GetString(Red.rom.MonsterNames + 10*(mon.species-1), nil, nil, 10) 12 | 13 | Red.Dex[mon.no] = mon 14 | Red.Dex[string.lower(mon.name)] = mon 15 | Red.Dex[mon.name] = mon 16 | Red.Dex.Species[mon.species] = mon 17 | end 18 | 19 | local mrmime = Red.Dex['MR.MIME'] 20 | Red.Dex.mrmime = mrmime 21 | Red.Dex.MRMIME = mrmime 22 | 23 | -- moves 24 | 25 | Red.Dex.Move = {} 26 | for i=1,165 do 27 | local move = {} 28 | move.no = i 29 | move.name = Red.GetString(Red.rom.MoveNames, i - 1) 30 | 31 | Red.Dex.Move[move.no] = move 32 | Red.Dex.Move[move.name] = move 33 | local underscore = string.gsub(move.name, ' ', '_') 34 | Red.Dex.Move[underscore] = move 35 | Red.Dex.Move[string.lower(underscore)] = move 36 | end 37 | 38 | -- types 39 | 40 | Red.Dex.Type = {} 41 | for i=0,0x1a do 42 | if i <= 0x08 or i >= 0x14 then 43 | local type = {} 44 | local rom = Red.rom.TypeNames + i*2 45 | local rom = emu:rom(Red.sym.TypeNames.bank, rom[0] + rom[1]*0x100) 46 | type.name = Red.GetString(rom) 47 | type.no = i 48 | 49 | Red.Dex.Type[type.no] = type 50 | Red.Dex.Type[type.name] = type 51 | Red.Dex.Type[string.lower(type.name)] = type 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | struct CircleBuffer { 12 | void* data; 13 | size_t capacity; 14 | size_t size; 15 | void* readPtr; 16 | void* writePtr; 17 | }; 18 | 19 | void CircleBufferInit(struct CircleBuffer* buffer, unsigned capacity); 20 | void CircleBufferDeinit(struct CircleBuffer* buffer); 21 | size_t CircleBufferSize(const struct CircleBuffer* buffer); 22 | size_t CircleBufferCapacity(const struct CircleBuffer* buffer); 23 | void CircleBufferClear(struct CircleBuffer* buffer); 24 | int CircleBufferWrite8(struct CircleBuffer* buffer, int8_t value); 25 | int CircleBufferWrite16(struct CircleBuffer* buffer, int16_t value); 26 | int CircleBufferWrite32(struct CircleBuffer* buffer, int32_t value); 27 | int CircleBufferRead8(struct CircleBuffer* buffer, int8_t* value); 28 | int CircleBufferRead16(struct CircleBuffer* buffer, int16_t* value); 29 | int CircleBufferRead32(struct CircleBuffer* buffer, int32_t* value); 30 | size_t CircleBufferRead(struct CircleBuffer* buffer, void* output, size_t length); 31 | size_t CircleBufferDump(const struct CircleBuffer* buffer, void* output, size_t length); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #ifndef HAVE_STRNDUP 12 | // This is sometimes a macro 13 | char* strndup(const char* start, size_t len); 14 | #endif 15 | 16 | #ifndef HAVE_STRDUP 17 | char* strdup(const char* str); 18 | #endif 19 | 20 | char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len); 21 | bool endswith(const char* restrict s1, const char* restrict end); 22 | 23 | size_t toUtf8(uint32_t unichar, char* buffer); 24 | int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length); 25 | char* utf16to8(const uint16_t* utf16, size_t length); 26 | uint32_t utf8Char(const char** unicode, size_t* length); 27 | uint32_t utf16Char(const uint16_t** unicode, size_t* length); 28 | 29 | int hexDigit(char digit); 30 | const char* hex32(const char* line, uint32_t* out); 31 | const char* hex24(const char* line, uint32_t* out); 32 | const char* hex16(const char* line, uint16_t* out); 33 | const char* hex12(const char* line, uint16_t* out); 34 | const char* hex8(const char* line, uint8_t* out); 35 | const char* hex4(const char* line, uint8_t* out); 36 | 37 | void rtrim(char* string); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /deps/include/mgba/util/gui/menu.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_MENU_H 7 | #define GUI_MENU_H 8 | 9 | #include "util/vector.h" 10 | 11 | struct GUIMenu; 12 | struct GUIMenuItem { 13 | const char* title; 14 | void* data; 15 | unsigned state; 16 | const char* const* validStates; 17 | unsigned nStates; 18 | struct GUIMenu* submenu; 19 | }; 20 | 21 | DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem); 22 | 23 | struct GUIBackground; 24 | struct GUIMenu { 25 | const char* title; 26 | const char* subtitle; 27 | struct GUIMenuItemList items; 28 | size_t index; 29 | struct GUIBackground* background; 30 | }; 31 | 32 | enum GUIMenuExitReason { 33 | GUI_MENU_EXIT_ACCEPT, 34 | GUI_MENU_EXIT_BACK, 35 | GUI_MENU_EXIT_CANCEL, 36 | }; 37 | 38 | enum GUIMessageBoxButtons { 39 | GUI_MESSAGE_BOX_OK = 1, 40 | GUI_MESSAGE_BOX_CANCEL = 2 41 | }; 42 | 43 | struct GUIParams; 44 | enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* menu, struct GUIMenuItem** item); 45 | 46 | ATTRIBUTE_FORMAT(printf, 4, 5) 47 | enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...); 48 | 49 | void GUIDrawBattery(struct GUIParams* params); 50 | void GUIDrawClock(struct GUIParams* params); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/lua/red/render/custom_sprites.lua: -------------------------------------------------------------------------------- 1 | Red.CustomSprites = {} 2 | local bikexoffsets = { 3 | 0, 4 | 0, 5 | 1, 6 | -1, 7 | -1, 8 | 0 9 | } 10 | Red.CustomSprites.red_on_bike = { 11 | addr = {0x05, 0x4000, 0xc0}, 12 | postprocess = function(oldpix) 13 | -- custom sprite frankensteining... 14 | -- making it so that the hat isn't 15 | -- cut off at the top due to the 16 | -- 16x16 px restraint 17 | local redpix = getspritefromrom(1, true) 18 | local newpix = ffi.new('uint8_t[?]', 16*17*6*3) 19 | C.memset(newpix, SPRITE_INVIS_COLOR, ffi.sizeof(newpix)) 20 | for i=0,6-1 do 21 | local xoffset = bikexoffsets[i+1] 22 | local outpix = newpix + 16*17*3*i 23 | local bikepix = oldpix + 16*16*3*i 24 | local redpix = redpix + 16*16*3*(i % 3) 25 | -- red's head 26 | for y=0,6-1 do 27 | for x=0,14-1 do 28 | local outpix = outpix + 16*3*y + 3*(x + 1 + xoffset) 29 | local redpix = redpix + 16*3*y + 3*(x + 1) 30 | outpix[0] = redpix[0] 31 | outpix[1] = redpix[1] 32 | outpix[2] = redpix[2] 33 | end 34 | end 35 | -- bike body 36 | for y=0,17-6-1 do 37 | C.memcpy(outpix + 16*3*(y + 6), bikepix + 16*3*(y + 5), 16*3) 38 | end 39 | end 40 | return newpix, 17, 17*6 41 | end, 42 | } 43 | return Red.CustomSprites 44 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #ifdef USE_PNG 12 | 13 | #include 14 | 15 | struct VFile; 16 | 17 | enum { 18 | PNG_HEADER_BYTES = 8 19 | }; 20 | 21 | png_structp PNGWriteOpen(struct VFile* source); 22 | png_infop PNGWriteHeader(png_structp png, unsigned width, unsigned height); 23 | bool PNGWritePixels(png_structp png, unsigned width, unsigned height, unsigned stride, const void* pixels); 24 | bool PNGWriteCustomChunk(png_structp png, const char* name, size_t size, void* data); 25 | void PNGWriteClose(png_structp png, png_infop info); 26 | 27 | typedef int (*ChunkHandler)(png_structp, png_unknown_chunkp); 28 | 29 | bool isPNG(struct VFile* source); 30 | png_structp PNGReadOpen(struct VFile* source, unsigned offset); 31 | bool PNGInstallChunkHandler(png_structp png, void* context, ChunkHandler handler, const char* chunkName); 32 | bool PNGReadHeader(png_structp png, png_infop info); 33 | bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width, unsigned height, unsigned stride); 34 | bool PNGIgnorePixels(png_structp png, png_infop info); 35 | bool PNGReadFooter(png_structp png, png_infop end); 36 | void PNGReadClose(png_structp png, png_infop info, png_infop end); 37 | 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "debugger/debugger.h" 12 | 13 | struct mArguments { 14 | char* fname; 15 | char* patch; 16 | char* cheatsFile; 17 | char* movie; 18 | char* bios; 19 | int logLevel; 20 | int frameskip; 21 | 22 | enum mDebuggerType debuggerType; 23 | bool debugAtStart; 24 | bool showHelp; 25 | bool showVersion; 26 | }; 27 | 28 | struct mCoreConfig; 29 | struct mSubParser { 30 | const char* usage; 31 | bool (*parse)(struct mSubParser* parser, int option, const char* arg); 32 | void (*apply)(struct mSubParser* parser, struct mCoreConfig* config); 33 | const char* extraOptions; 34 | void* opts; 35 | }; 36 | 37 | struct mGraphicsOpts { 38 | int multiplier; 39 | bool fullscreen; 40 | }; 41 | 42 | bool parseArguments(struct mArguments* args, int argc, char* const* argv, 43 | struct mSubParser* subparser); 44 | void applyArguments(const struct mArguments* args, struct mSubParser* subparser, struct mCoreConfig* config); 45 | void freeArguments(struct mArguments* args); 46 | 47 | void usage(const char* arg0, const char* extraOptions); 48 | void version(const char* arg0); 49 | 50 | void initParserForGraphics(struct mSubParser* parser, struct mGraphicsOpts* opts); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/c/3ds/mgba.c: -------------------------------------------------------------------------------- 1 | #ifdef USE_MGBA 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static lua_State *L = NULL; 8 | 9 | bool aaas_call_callback(int callback) 10 | { 11 | lua_rawgeti(L, LUA_REGISTRYINDEX, callback); 12 | lua_pcall(L, 0, 1, 0); 13 | if(lua_isboolean(L, -1) && lua_toboolean(L, -1)) { 14 | return true; 15 | } else { 16 | return false; 17 | } 18 | } 19 | 20 | void aaas_add_pc_hook(int bank, int pc, int callback); 21 | int l_aaas_add_pc_hook(lua_State *l) 22 | { 23 | L = l; 24 | if(!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isfunction(L, 3)) { 25 | return luaL_error(L, "invalid arguments"); 26 | } 27 | lua_pushvalue(L, 3); 28 | aaas_add_pc_hook(lua_tonumber(L, 1), lua_tonumber(L, 2), luaL_ref(L, LUA_REGISTRYINDEX)); 29 | return 0; 30 | } 31 | 32 | static int postAudioBufferFunc = -1; 33 | void aaas_postAudioBuffer(void *arg1, void *arg2, void *arg3) 34 | { 35 | if(postAudioBufferFunc == -1) { 36 | return; 37 | } 38 | lua_rawgeti(L, LUA_REGISTRYINDEX, postAudioBufferFunc); 39 | lua_pushlightuserdata(L, arg1); 40 | lua_pushlightuserdata(L, arg2); 41 | lua_pushlightuserdata(L, arg3); 42 | lua_pcall(L, 3, 0, 0); 43 | } 44 | 45 | int l_aaas_set_postAudioBuffer(lua_State *L) 46 | { 47 | if(!lua_isfunction(L, 1)) { 48 | return luaL_error(L, "expected function"); 49 | } 50 | lua_pushvalue(L, 1); 51 | postAudioBufferFunc = luaL_ref(L, LUA_REGISTRYINDEX); 52 | return 0; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | #include "debugger.h" 11 | 12 | enum LexState { 13 | LEX_ERROR = -1, 14 | LEX_ROOT = 0, 15 | LEX_EXPECT_IDENTIFIER, 16 | LEX_EXPECT_BINARY, 17 | LEX_EXPECT_DECIMAL, 18 | LEX_EXPECT_HEX, 19 | LEX_EXPECT_PREFIX, 20 | LEX_EXPECT_OPERATOR 21 | }; 22 | 23 | enum Operation { 24 | OP_ASSIGN, 25 | OP_ADD, 26 | OP_SUBTRACT, 27 | OP_MULTIPLY, 28 | OP_DIVIDE 29 | }; 30 | 31 | struct Token { 32 | enum TokenType { 33 | TOKEN_ERROR_TYPE, 34 | TOKEN_UINT_TYPE, 35 | TOKEN_IDENTIFIER_TYPE, 36 | TOKEN_OPERATOR_TYPE, 37 | TOKEN_OPEN_PAREN_TYPE, 38 | TOKEN_CLOSE_PAREN_TYPE, 39 | TOKEN_SEGMENT_TYPE, 40 | } type; 41 | union { 42 | uint32_t uintValue; 43 | char* identifierValue; 44 | enum Operation operatorValue; 45 | }; 46 | }; 47 | 48 | struct LexVector { 49 | struct LexVector* next; 50 | struct Token token; 51 | }; 52 | 53 | struct ParseTree { 54 | struct Token token; 55 | struct ParseTree* lhs; 56 | struct ParseTree* rhs; 57 | }; 58 | 59 | size_t lexExpression(struct LexVector* lv, const char* string, size_t length); 60 | void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv); 61 | 62 | void lexFree(struct LexVector* lv); 63 | void parseFree(struct ParseTree* tree); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/lua/rom.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Rom = Object.new(super) 3 | 4 | function Rom:new(path, romptr) 5 | local self = super.new(self) 6 | 7 | self.path = path 8 | 9 | if not romptr then 10 | self.path = path 11 | romptr = io.readbin(self.path) 12 | end 13 | 14 | self.romptr = romptr 15 | 16 | -- parse symfile 17 | local t = string.split(self.path, '%.') 18 | t[#t] = nil 19 | local sympath = table.concat(t, '.')..'.sym' 20 | local f = io.open(sympath) 21 | if not f then 22 | error('You must place your symfile in '..sympath) 23 | end 24 | self.sym = {} 25 | for line in f:lines() do 26 | local bank, addr, name = string.match(line, '(%w%w)%:(%w%w%w%w) (.+)') 27 | if bank and addr and name then 28 | bank = tonumber(bank, 16) 29 | addr = tonumber(addr, 16) 30 | local t = {bank = bank, addr = addr, name = name} 31 | self.sym[name] = t 32 | self.sym[bank*0x10000 + addr] = t 33 | end 34 | end 35 | f:close() 36 | 37 | -- rom metatable 38 | self.rom = setmetatable({}, { 39 | __index = function(t, k) 40 | local sym = self.sym[k] 41 | return sym and self:lookup(sym.bank, sym.addr) 42 | end, 43 | __newindex = function() 44 | error('not allowed') 45 | end, 46 | }) 47 | 48 | return self 49 | end 50 | 51 | function Rom:lookup(bank, addr) 52 | assert(addr < 0x8000) 53 | return self.romptr + bit.band(addr, 0x4000 - 1) + bank * 0x4000 54 | end 55 | 56 | return Rom 57 | -------------------------------------------------------------------------------- /src/lua/player.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Player = Object.new(super) 3 | 4 | Player.nick = 'MingeBag' 5 | 6 | Player.Attrs = {'id', 'nick', 'x', 'y', 'map', 'dir', 'anim', 'diffx', 'diffy'} 7 | Player.Peers = {} 8 | 9 | function Player:new() 10 | local self = super.new(self) 11 | return self 12 | end 13 | 14 | function Player:update() 15 | if not Red.wram then return end 16 | if self.x == Red.wram.wXCoord 17 | and self.y == Red.wram.wYCoord 18 | and self.map == Red.wram.wCurMap 19 | and self.dir == Red.wram.wSpriteStateData1[0].FacingDirection 20 | and self.anim == Red.wram.wSpriteStateData1[0].AnimFrameCounter 21 | and self.diffx == Red.diffx 22 | and self.diffy == Red.diffy 23 | then return end 24 | 25 | self.x = Red.wram.wXCoord 26 | self.y = Red.wram.wYCoord 27 | self.map = Red.wram.wCurMap 28 | self.dir = Red.wram.wSpriteStateData1[0].FacingDirection 29 | self.anim = Red.wram.wSpriteStateData1[0].AnimFrameCounter 30 | self.diffx = Red.diffx or 0 31 | self.diffy = Red.diffy or 0 32 | return true 33 | end 34 | 35 | function Player:serialize() 36 | local t = {__class = 'Player'} 37 | populate(t, self, Player.Attrs) 38 | return serialize(t) 39 | end 40 | 41 | function Player.Decode(t) 42 | if not t.id then 43 | error('id not set') 44 | end 45 | 46 | local self = Player.Peers[t.id] 47 | if not self then 48 | self = Player:new() 49 | Player.Peers[t.id] = self 50 | end 51 | populate(self, t, Player.Attrs) 52 | return self 53 | end 54 | 55 | return Player 56 | -------------------------------------------------------------------------------- /deps/include/mgba/util/table.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 TABLE_H 7 | #define TABLE_H 8 | 9 | #include "util/common.h" 10 | 11 | struct TableList; 12 | 13 | struct Table { 14 | struct TableList* table; 15 | size_t tableSize; 16 | void (*deinitializer)(void*); 17 | }; 18 | 19 | void TableInit(struct Table*, size_t initialSize, void (deinitializer(void*))); 20 | void TableDeinit(struct Table*); 21 | 22 | void* TableLookup(const struct Table*, uint32_t key); 23 | void TableInsert(struct Table*, uint32_t key, void* value); 24 | 25 | void TableRemove(struct Table*, uint32_t key); 26 | void TableClear(struct Table*); 27 | 28 | void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user); 29 | 30 | static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) { 31 | TableInit(table, initialSize, deinitializer); 32 | } 33 | 34 | static inline void HashTableDeinit(struct Table* table) { 35 | TableDeinit(table); 36 | } 37 | 38 | void* HashTableLookup(const struct Table*, const char* key); 39 | void HashTableInsert(struct Table*, const char* key, void* value); 40 | 41 | void HashTableRemove(struct Table*, const char* key); 42 | void HashTableClear(struct Table*); 43 | 44 | void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/lua/red/init.lua: -------------------------------------------------------------------------------- 1 | Red = {} 2 | Red.Tilesize = 8 3 | 4 | local function init() 5 | init = function() end 6 | 7 | require 'red.symbols' 8 | require 'red.dialogue' 9 | require 'red.start_menu.render' 10 | require 'red.start_menu.bag' 11 | require 'red.start_menu.party' 12 | require 'red.render' 13 | require 'red.cheats' 14 | require 'red.string' 15 | require 'red.pic' 16 | require 'red.dex' 17 | require 'red.map' 18 | 19 | Toggler.OnUpdate.red = function() 20 | Red:reset() 21 | end 22 | end 23 | 24 | function Red:overworld() 25 | if cheats.repel then 26 | self.wram.wRepelRemainingSteps = 2 27 | end 28 | if not(cheats.bike == nil) then 29 | self.wram.wWalkBikeSurfState = cheats.bike and 1 or 0 30 | end 31 | if cheats.all_badges then 32 | self.wram.wObtainedBadges = 0xff 33 | end 34 | self.wram.wMapPalOffset = 0 -- override flash 35 | end 36 | 37 | function Red:battle() 38 | self.wram.wEnemyMonNick = 'lololo' 39 | local friend = self.wram.wBattleMon 40 | local enemy = self.wram.wEnemyMon 41 | 42 | friend.Type2 = math.ceil(math.random() * 6) 43 | if cheats.always_win then 44 | enemy.HP = 0 45 | end 46 | 47 | friend.Moves[3] = math.ceil(math.random() * 60) 48 | friend.PP[3] = 14 49 | end 50 | 51 | function Red:run() 52 | if self.wram.wIsInBattle == 0 then 53 | self:overworld() 54 | else 55 | self:battle() 56 | end 57 | end 58 | 59 | function Red:reset() 60 | init() 61 | 62 | emu:resetrom() 63 | self:patch_cheats() 64 | end 65 | 66 | return Red 67 | -------------------------------------------------------------------------------- /src/lua/red/string.lua: -------------------------------------------------------------------------------- 1 | function Red.GetString(rom, index, delim, strlen) 2 | strlen = strlen or math.huge 3 | index = index or 0 4 | delim = delim or 80 5 | 6 | local str = '' 7 | local idx = 0 8 | for i=0,math.huge do 9 | if idx == index then 10 | rom = rom + i 11 | break 12 | end 13 | if rom[i] == delim then 14 | idx = idx + 1 15 | end 16 | end 17 | for i=0,strlen-1 do 18 | if rom[i] == delim then break end 19 | str = str..Red.CharDecode(rom[i], true) 20 | end 21 | return str 22 | end 23 | 24 | Red.CharOffset = 128 - string.byte('A') 25 | local decode = {} 26 | decode[79] = ' ' 27 | decode[81] = '\n' 28 | decode[82] = 'RED' 29 | decode[83] = 'BLUE' 30 | decode[84] = 'POKe' 31 | decode[85] = ' ' 32 | decode[127] = ' ' 33 | decode[156] = ':' 34 | decode[186] = 'e' 35 | decode[188] = '\'l' 36 | decode[189] = '\'s' 37 | decode[190] = '\'t' 38 | decode[227] = '-' 39 | decode[228] = '\'r' 40 | decode[229] = '\'m' 41 | decode[230] = '?' 42 | decode[231] = '!' 43 | decode[232] = '.' 44 | decode[240] = '$' 45 | decode[244] = ',' 46 | local A = string.byte('A') 47 | local a = string.byte('a') 48 | local Z = string.byte('Z') 49 | local z = string.byte('z') 50 | function Red.CharDecode(lol, use_fallback) 51 | local c = lol - Red.CharOffset 52 | local i = lol - 246 53 | if c >= A and c <= Z or c >= a and c <= z then 54 | return string.char(c) 55 | elseif i >= 0 and i <= 9 then 56 | return tostring(i) 57 | else 58 | return decode[lol] or (use_fallback and '['..lol..']') 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | enum mStateExtdataTag { 12 | EXTDATA_NONE = 0, 13 | EXTDATA_SCREENSHOT = 1, 14 | EXTDATA_SAVEDATA = 2, 15 | EXTDATA_CHEATS = 3, 16 | EXTDATA_MAX 17 | }; 18 | 19 | #define SAVESTATE_SCREENSHOT 1 20 | #define SAVESTATE_SAVEDATA 2 21 | #define SAVESTATE_CHEATS 4 22 | 23 | struct mStateExtdataItem { 24 | int32_t size; 25 | void* data; 26 | void (*clean)(void*); 27 | }; 28 | 29 | struct mStateExtdata { 30 | struct mStateExtdataItem data[EXTDATA_MAX]; 31 | }; 32 | 33 | bool mStateExtdataInit(struct mStateExtdata*); 34 | void mStateExtdataDeinit(struct mStateExtdata*); 35 | void mStateExtdataPut(struct mStateExtdata*, enum mStateExtdataTag, struct mStateExtdataItem*); 36 | bool mStateExtdataGet(struct mStateExtdata*, enum mStateExtdataTag, struct mStateExtdataItem*); 37 | 38 | struct VFile; 39 | bool mStateExtdataSerialize(struct mStateExtdata* extdata, struct VFile* vf); 40 | bool mStateExtdataDeserialize(struct mStateExtdata* extdata, struct VFile* vf); 41 | 42 | struct mCore; 43 | bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags); 44 | bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags); 45 | void* mCoreExtractState(struct mCore* core, struct VFile* vf, struct mStateExtdata* extdata); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /deps/include/mgba/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 | #include "debugger/debugger.h" 7 | 8 | struct ARMDebugBreakpoint { 9 | uint32_t address; 10 | bool isSw; 11 | struct { 12 | uint32_t opcode; 13 | enum ExecutionMode mode; 14 | } sw; 15 | }; 16 | 17 | struct ARMDebugWatchpoint { 18 | uint32_t address; 19 | enum mWatchpointType type; 20 | }; 21 | 22 | DECLARE_VECTOR(ARMDebugBreakpointList, struct ARMDebugBreakpoint); 23 | DECLARE_VECTOR(ARMDebugWatchpointList, struct ARMDebugWatchpoint); 24 | 25 | struct ARMDebugger { 26 | struct mDebuggerPlatform d; 27 | struct ARMCore* cpu; 28 | 29 | struct ARMDebugBreakpointList breakpoints; 30 | struct ARMDebugBreakpointList swBreakpoints; 31 | struct ARMDebugWatchpointList watchpoints; 32 | struct ARMMemory originalMemory; 33 | 34 | void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); 35 | 36 | bool (*setSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); 37 | bool (*clearSoftwareBreakpoint)(struct ARMDebugger*, uint32_t address, enum ExecutionMode mode, uint32_t opcode); 38 | }; 39 | 40 | struct mDebuggerPlatform* ARMDebuggerPlatformCreate(void); 41 | bool ARMDebuggerSetSoftwareBreakpoint(struct mDebuggerPlatform* debugger, uint32_t address, enum ExecutionMode mode); 42 | void ARMDebuggerClearSoftwareBreakpoint(struct mDebuggerPlatform* debugger, uint32_t address); 43 | -------------------------------------------------------------------------------- /src/lua/red/render/dialogue.lua: -------------------------------------------------------------------------------- 1 | -- This entire thing is a hack. 2 | -- It just checks for that little 3 | -- pokeball in the top left corner 4 | -- on the emulator screen. If it's 5 | -- there, then it just redraws the 6 | -- emulator on the top screen. 7 | 8 | --[[ 9 | ....... 10 | ...##.. 11 | ..#.##. 12 | .###### 13 | .#....# 14 | ..#..#. 15 | ...##.# 16 | ]] 17 | local X = true 18 | local o = false 19 | local check = { 20 | {o, o, o, X, X}, 21 | {o, o, X, o, X, X}, 22 | {o, X, X, X, X, X, X}, 23 | {o, X, o, o, o, o, X}, 24 | {o, o, X, o, o, X}, 25 | {o, o, o, X, X}, 26 | } 27 | 28 | local strs = {} 29 | 30 | -- mGBA platform 31 | -- difference quirk 32 | local black, white 33 | if PLATFORM == '3ds' then 34 | black = {0, 0} 35 | white = {223, 255} 36 | else 37 | black = {0, 0, 0, 0} 38 | white = {0xff, 0xff, 0xff, 0} 39 | end 40 | assert(#black == #white) 41 | local siz = #black 42 | 43 | for _,row in ipairs(check) do 44 | local s = ffi.new('uint8_t[?]', #row * siz) 45 | for i,char in ipairs(row) do 46 | local color 47 | if char == o then 48 | color = white 49 | elseif char == X then 50 | color = black 51 | end 52 | for j=1,siz do 53 | s[siz*(i - 1) + j - 1] = color[j] 54 | end 55 | end 56 | table.insert(strs, s) 57 | end 58 | 59 | function RENDER_DIALOGUE() 60 | for i,s in ipairs(strs) do 61 | local y = 97 + i - 1 62 | local pix = emu.pix + siz*y*emu.width 63 | if not(C.memcmp(pix, s, ffi.sizeof(s)) == 0) then 64 | return 65 | end 66 | end 67 | 68 | emu:render() 69 | end 70 | -------------------------------------------------------------------------------- /src/lua/red/map.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Red.Map = Object.new(super) 3 | 4 | 5 | local all = {} 6 | function Red.Map.Clear() 7 | all = {} 8 | end 9 | 10 | function Red.Map:new(map) 11 | if all[map] then 12 | return all[map] 13 | end 14 | local self = super.new(self) 15 | 16 | 17 | self.map = map 18 | self.wram = {} 19 | self.wram.header, self.wram.blocks = getmapheader(self.map) 20 | self.tileset = self.wram.header[0] 21 | self.blockwidth = self.wram.header[2] 22 | self.blockheight = self.wram.header[1] 23 | self.tilewidth = 2*self.blockwidth 24 | self.tileheight = 2*self.blockheight 25 | self.width = 16*self.tilewidth 26 | self.height = 16*self.tileheight 27 | 28 | self.pix = ffi.new('uint8_t *[?]', self.tilewidth*self.tileheight) 29 | 30 | for y=0,self.blockheight-1 do 31 | for x=0,self.blockwidth-1 do 32 | local tileno = self.wram.blocks[y*self.blockwidth + x] 33 | local block = gettilefromrom(self.tileset, tileno) 34 | local pix = self.pix + 4*y*self.blockwidth + 2*x 35 | pix[0] = block.nw.pix 36 | pix[1] = block.ne.pix 37 | local pix = pix + 2*self.blockwidth 38 | pix[0] = block.sw.pix 39 | pix[1] = block.se.pix 40 | end 41 | end 42 | 43 | 44 | 45 | 46 | all[map] = self 47 | return self 48 | end 49 | 50 | function Red.Map:draw(scr, x, y) 51 | ffi.luared.tilecopy( 52 | scr.pix, scr.width, scr.height, x, y, 53 | self.pix, self.tilewidth, self.tileheight 54 | ) 55 | end 56 | 57 | getmetatable(Red.Map).__call = function(x, ...) 58 | return Red.Map:new(...) 59 | end 60 | 61 | return Red.Map 62 | -------------------------------------------------------------------------------- /src/c/common/zip.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #ifdef _3DS 7 | // minimal zlib.h 8 | typedef void *gzFile; 9 | typedef long z_off_t; 10 | gzFile gzopen(const char*, const char*); 11 | int gzread(gzFile, void *, unsigned); 12 | z_off_t gzseek(gzFile, z_off_t, int whence); 13 | int gzclose(gzFile); 14 | #else 15 | #include 16 | #endif 17 | 18 | 19 | #define MIN(a, b) (a < b ? a : b) 20 | 21 | bool untargz(const char *filename, const char *outfolder) 22 | { 23 | gzFile f = gzopen(filename, "rb"); 24 | 25 | if(f == NULL) { 26 | return false; 27 | } 28 | 29 | while(true) { 30 | char name[100]; 31 | gzread(f, name, 100); 32 | 33 | gzseek(f, 24, SEEK_CUR); 34 | 35 | char size[12]; 36 | gzread(f, size, 12); 37 | long siz = strtol(size, NULL, 8); 38 | if(siz == 0) { 39 | break; 40 | } 41 | 42 | char path[100 + strlen(outfolder) + 2]; 43 | strcpy(path, outfolder); 44 | strcat(path, "/"); 45 | strcat(path, name); 46 | FILE *outf = fopen(path, "w"); 47 | if(outf == NULL) { 48 | return false; 49 | } 50 | 51 | gzseek(f, 376, SEEK_CUR); 52 | 53 | long remaining = siz; 54 | char contents[512]; 55 | while(remaining > 0) { 56 | int len = MIN(512, remaining); 57 | gzread(f, contents, len); 58 | fwrite(contents, len, 1, outf); 59 | remaining = remaining - len; 60 | } 61 | fclose(outf); 62 | 63 | gzseek(f, 512 - (siz % 512), SEEK_CUR); 64 | } 65 | gzclose(f); 66 | return true; 67 | } 68 | -------------------------------------------------------------------------------- /deps/include/mgba/util/test/suite.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 SUITE_H 7 | #define SUITE_H 8 | #include "util/common.h" 9 | 10 | #include 11 | #include 12 | 13 | #define M_TEST_DEFINE(NAME) static void NAME (void **state ATTRIBUTE_UNUSED) 14 | 15 | #define M_TEST_SUITE(NAME) _testSuite_ ## NAME 16 | #define M_TEST_SUITE_RUN(NAME) (printf("\nRunning suite %s\n", # NAME), M_TEST_SUITE(NAME)()) 17 | #define M_TEST_SUITE_DEFINE(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, NULL, __VA_ARGS__) 18 | #define M_TEST_SUITE_DEFINE_SETUP(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, NULL, __VA_ARGS__) 19 | #define M_TEST_SUITE_DEFINE_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, NULL, _testSuite_teardown_ ## NAME, __VA_ARGS__) 20 | #define M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(NAME, ...) M_TEST_SUITE_DEFINE_EX(NAME, _testSuite_setup_ ## NAME, _testSuite_teardown_ ## NAME, __VA_ARGS__) 21 | #define M_TEST_SUITE_DEFINE_EX(NAME, SETUP, TEARDOWN, ...) \ 22 | int M_TEST_SUITE(NAME) (void) { \ 23 | const static struct CMUnitTest tests[] = { \ 24 | __VA_ARGS__ \ 25 | }; \ 26 | return cmocka_run_group_tests_name(# NAME, tests, SETUP, TEARDOWN); \ 27 | } 28 | 29 | #define M_TEST_SUITE_SETUP(NAME) static int _testSuite_setup_ ## NAME (void **state ATTRIBUTE_UNUSED) 30 | #define M_TEST_SUITE_TEARDOWN(NAME) static int _testSuite_teardown_ ## NAME (void **state ATTRIBUTE_UNUSED) 31 | 32 | #define M_TEST_SUITE_DECLARE(NAME) extern int M_TEST_SUITE(NAME) (void) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env luajit 2 | 3 | if love then 4 | dofile(love.filesystem.getSource()..'/src/lua/plat/love/init.lua') 5 | else 6 | ROMPATH = arg[1] 7 | if ROMPATH == nil then 8 | local f = io.open('src/lua/config/cmd_rom.lua') 9 | if f then 10 | f:close() 11 | ROMPATH = dofile('src/lua/config/cmd_rom.lua') 12 | else 13 | print('Usage: '..arg[0]..' rom.gb') 14 | return 15 | end 16 | end 17 | local function runcmd(cmd) 18 | local f = io.popen(cmd, 'r') 19 | local s =f:read('*a') 20 | f:close() 21 | return s 22 | end 23 | local function string_split(self, sep) 24 | local fields = {} 25 | string.gsub(self, '([^'..sep..']+)', function(c) table.insert(fields, c) end) 26 | return fields 27 | end 28 | local function get_folder_from_path(path) 29 | local components = string_split(path, '/') 30 | components[#components] = nil 31 | local prefix = string.sub(path,1,1) == '/' and '/' or './' 32 | return prefix..table.concat(components, '/') 33 | end 34 | local function where_is_main_dot_lua() 35 | local path = arg[0] 36 | local symlink = runcmd('readlink "'..path..'"') 37 | if #symlink == 0 then 38 | return get_folder_from_path(path) 39 | elseif not (string.sub(symlink, 1, 3) == '../') then 40 | return get_folder_from_path(symlink) 41 | end 42 | -- get absolute path 43 | return get_folder_from_path(get_folder_from_path(get_folder_from_path(path))..'/'..string.sub(symlink, 4, #symlink)) 44 | end 45 | 46 | PATH = where_is_main_dot_lua() 47 | 48 | dofile(PATH..'/src/lua/plat/cmd/init.lua') 49 | end 50 | -------------------------------------------------------------------------------- /src/lua/plat/love/screen.lua: -------------------------------------------------------------------------------- 1 | local pix 2 | function Screen.init() 3 | Screen.top.width = 600 4 | Screen.top.height = 400 5 | Screen.top.size = Screen.top.width*Screen.top.height*3 6 | Screen.top.pix = ffi.new('uint8_t[?]', Screen.top.size) 7 | 8 | Screen.bottom.width = 320 9 | Screen.bottom.height = 240 10 | Screen.bottom.size = Screen.bottom.width*Screen.bottom.height*3 11 | Screen.bottom.pix = ffi.new('uint8_t[?]', Screen.bottom.size) 12 | 13 | Screen.top.lovedata = love.image.newImageData(Screen.top.height, Screen.top.width) 14 | Screen.top.love = love.graphics.newImage(Screen.top.lovedata) 15 | Screen.top.love:setFilter('linear', 'nearest') 16 | 17 | Screen.bottom.lovedata = love.image.newImageData(Screen.bottom.height, Screen.bottom.width) 18 | Screen.bottom.love = love.graphics.newImage(Screen.bottom.lovedata) 19 | Screen.bottom.love:setFilter('linear', 'nearest') 20 | 21 | pix = ffi.new('uint8_t[?]', math.max(ffi.sizeof(Screen.top.pix), ffi.sizeof(Screen.bottom.pix))) 22 | end 23 | 24 | function Screen.startframe() 25 | C.memset(Screen.top.pix, 0, Screen.top.size) 26 | C.memset(Screen.bottom.pix, 0, Screen.bottom.size) 27 | end 28 | 29 | function Screen.endframe() 30 | -- need to manually copy the pixelbuffer in one by one D: 31 | ffi.luared.lastcopy(pix, Screen.top.pix, Screen.top.width, Screen.top.height) 32 | ffi.luared.lovecopy(ffi.cast('uint8_t *', Screen.top.lovedata:getPointer()), pix, Screen.top.width*Screen.top.height) 33 | Screen.top.love:refresh() 34 | 35 | ffi.luared.lastcopy(pix, Screen.bottom.pix, Screen.bottom.width, Screen.bottom.height) 36 | ffi.luared.lovecopy(ffi.cast('uint8_t *', Screen.bottom.lovedata:getPointer()), pix, Screen.bottom.width*Screen.bottom.height) 37 | Screen.bottom.love:refresh() 38 | end 39 | -------------------------------------------------------------------------------- /deps/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 "util/table.h" 10 | 11 | struct VFile; 12 | 13 | struct Configuration { 14 | struct Table sections; 15 | struct Table root; 16 | }; 17 | 18 | void ConfigurationInit(struct Configuration*); 19 | void ConfigurationDeinit(struct Configuration*); 20 | 21 | void ConfigurationSetValue(struct Configuration*, const char* section, const char* key, const char* value); 22 | void ConfigurationSetIntValue(struct Configuration*, const char* section, const char* key, int value); 23 | void ConfigurationSetUIntValue(struct Configuration*, const char* section, const char* key, unsigned value); 24 | void ConfigurationSetFloatValue(struct Configuration*, const char* section, const char* key, float value); 25 | 26 | bool ConfigurationHasSection(const struct Configuration*, const char* section); 27 | const char* ConfigurationGetValue(const struct Configuration*, const char* section, const char* key); 28 | 29 | void ConfigurationClearValue(struct Configuration*, const char* section, const char* key); 30 | 31 | bool ConfigurationRead(struct Configuration*, const char* path); 32 | bool ConfigurationReadVFile(struct Configuration*, struct VFile* vf); 33 | bool ConfigurationWrite(const struct Configuration*, const char* path); 34 | bool ConfigurationWriteSection(const struct Configuration*, const char* path, const char* section); 35 | 36 | void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | enum mLogLevel { 12 | mLOG_FATAL = 0x01, 13 | mLOG_ERROR = 0x02, 14 | mLOG_WARN = 0x04, 15 | mLOG_INFO = 0x08, 16 | mLOG_DEBUG = 0x10, 17 | mLOG_STUB = 0x20, 18 | mLOG_GAME_ERROR = 0x40, 19 | 20 | mLOG_ALL = 0x7F 21 | }; 22 | 23 | struct mLogger { 24 | void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args); 25 | }; 26 | 27 | struct mLogger* mLogGetContext(void); 28 | void mLogSetDefaultLogger(struct mLogger*); 29 | int mLogGenerateCategory(const char*); 30 | const char* mLogCategoryName(int); 31 | 32 | ATTRIBUTE_FORMAT(printf, 3, 4) 33 | static inline void mLog(int category, enum mLogLevel level, const char* format, ...) { 34 | struct mLogger* context = mLogGetContext(); 35 | va_list args; 36 | va_start(args, format); 37 | if (context) { 38 | context->log(context, category, level, format, args); 39 | } else { 40 | printf("%s: ", mLogCategoryName(category)); 41 | vprintf(format, args); 42 | printf("\n"); 43 | } 44 | va_end(args); 45 | } 46 | 47 | #define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__) 48 | 49 | #define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); 50 | #define mLOG_DEFINE_CATEGORY(CATEGORY, NAME) \ 51 | int _mLOG_CAT_ ## CATEGORY (void) { \ 52 | static int category = 0; \ 53 | if (!category) { \ 54 | category = mLogGenerateCategory(NAME); \ 55 | } \ 56 | return category; \ 57 | } 58 | 59 | mLOG_DECLARE_CATEGORY(STATUS) 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/rr/rr.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_RR_H 7 | #define GBA_RR_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "core/log.h" 12 | #include "gba/serialize.h" 13 | 14 | struct VFile; 15 | 16 | mLOG_DECLARE_CATEGORY(GBA_RR); 17 | 18 | enum GBARRInitFrom { 19 | INIT_EX_NIHILO = 0, 20 | INIT_FROM_SAVEGAME = 1, 21 | INIT_FROM_SAVESTATE = 2, 22 | INIT_FROM_BOTH = 3, 23 | }; 24 | 25 | struct GBARRContext { 26 | void (*destroy)(struct GBARRContext*); 27 | 28 | bool (*startPlaying)(struct GBARRContext*, bool autorecord); 29 | void (*stopPlaying)(struct GBARRContext*); 30 | bool (*startRecording)(struct GBARRContext*); 31 | void (*stopRecording)(struct GBARRContext*); 32 | 33 | bool (*isPlaying)(const struct GBARRContext*); 34 | bool (*isRecording)(const struct GBARRContext*); 35 | 36 | void (*nextFrame)(struct GBARRContext*); 37 | void (*logInput)(struct GBARRContext*, uint16_t input); 38 | uint16_t (*queryInput)(struct GBARRContext*); 39 | bool (*queryReset)(struct GBARRContext*); 40 | 41 | void (*stateSaved)(struct GBARRContext*, struct GBASerializedState*); 42 | void (*stateLoaded)(struct GBARRContext*, const struct GBASerializedState*); 43 | 44 | struct VFile* (*openSavedata)(struct GBARRContext* mgm, int flags); 45 | struct VFile* (*openSavestate)(struct GBARRContext* mgm, int flags); 46 | 47 | uint32_t frames; 48 | uint32_t lagFrames; 49 | enum GBARRInitFrom initFrom; 50 | 51 | uint32_t rrCount; 52 | 53 | struct VFile* savedata; 54 | }; 55 | 56 | void GBARRDestroy(struct GBARRContext*); 57 | 58 | void GBARRInitRecord(struct GBA*); 59 | void GBARRInitPlay(struct GBA*); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /deps/include/mgba/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 SIO_LOCKSTEP_H 7 | #define SIO_LOCKSTEP_H 8 | 9 | #include "gba/sio.h" 10 | 11 | enum GBASIOLockstepPhase { 12 | TRANSFER_IDLE = 0, 13 | TRANSFER_STARTING, 14 | TRANSFER_STARTED, 15 | TRANSFER_FINISHING, 16 | TRANSFER_FINISHED 17 | }; 18 | 19 | struct GBASIOLockstep { 20 | struct GBASIOLockstepNode* players[MAX_GBAS]; 21 | int attached; 22 | int attachedMulti; 23 | int attachedNormal; 24 | 25 | uint16_t multiRecv[MAX_GBAS]; 26 | uint32_t normalRecv[MAX_GBAS]; 27 | enum GBASIOLockstepPhase transferActive; 28 | int32_t transferCycles; 29 | 30 | bool (*signal)(struct GBASIOLockstep*, unsigned mask); 31 | bool (*wait)(struct GBASIOLockstep*, unsigned mask); 32 | void (*addCycles)(struct GBASIOLockstep*, int id, int32_t cycles); 33 | int32_t (*useCycles)(struct GBASIOLockstep*, int id, int32_t cycles); 34 | void (*unload)(struct GBASIOLockstep*, int id); 35 | void* context; 36 | #ifndef NDEBUG 37 | int transferId; 38 | #endif 39 | }; 40 | 41 | struct GBASIOLockstepNode { 42 | struct GBASIODriver d; 43 | struct GBASIOLockstep* p; 44 | 45 | volatile int32_t nextEvent; 46 | int32_t eventDiff; 47 | bool normalSO; 48 | int id; 49 | enum GBASIOMode mode; 50 | bool transferFinished; 51 | #ifndef NDEBUG 52 | int transferId; 53 | enum GBASIOLockstepPhase phase; 54 | #endif 55 | }; 56 | 57 | void GBASIOLockstepInit(struct GBASIOLockstep*); 58 | void GBASIOLockstepDeinit(struct GBASIOLockstep*); 59 | 60 | void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*); 61 | 62 | bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); 63 | void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/lua/plat/3ds/init.lua: -------------------------------------------------------------------------------- 1 | jit.off() 2 | local oldprint = print 3 | PATH = '/3ds/luared' 4 | LUAPATH = PATH..'/lua' 5 | PLATFORM = '3ds' 6 | package.path = LUAPATH..'/?.lua;' 7 | ..LUAPATH..'/?/init.lua;' 8 | ..package.path 9 | 10 | local success, err = xpcall(function() 11 | require 'plat.3ds.main' 12 | end, debug.traceback) 13 | 14 | if success and not ERROR then return true end 15 | 16 | io.write('\x1b[2J') 17 | 18 | local GFX_TOP = 0 19 | local GFX_BOTTOM = 1 20 | local KEY_START = bit.lshift(1, 3) 21 | local GSPGPU_EVENT_VBlank0 = 2 22 | 23 | err = err or ERROR 24 | 25 | if not C then return err end 26 | 27 | if not C.lua_initted_gfx then 28 | C.gfxInitDefault() 29 | C.lua_initted_gfx = true 30 | end 31 | 32 | C.consoleInit(GFX_TOP, nil) 33 | io.write('\x1b[00;00HLua died :( Press start to exit\n\n') 34 | if not(print == oldprint) then 35 | -- print the error to the debugger 36 | print(err) 37 | end 38 | 39 | -- print the error to the 3ds screen 40 | local i = 0 41 | for s in string.gmatch(err, '[^\n]+') do 42 | if not(s == '\n') then 43 | if i and i > 22 then 44 | -- dont want to overscan now do we? 45 | C.consoleInit(GFX_BOTTOM, nil) 46 | i = nil 47 | end 48 | io.write(s) 49 | io.write('\n') 50 | if i then 51 | -- line wrapping on text thats longer 52 | -- than 50 chars 53 | i = i + 1 54 | local n = #s 55 | while n > 50 do 56 | n = n - 50 57 | i = i + 1 58 | end 59 | end 60 | end 61 | end 62 | io.write('\n') 63 | 64 | -- render loop 65 | 66 | while C.aptMainLoop() do 67 | C.hidScanInput() 68 | local down = C.hidKeysDown() 69 | if bit.band(down, KEY_START) ~= 0 then 70 | break 71 | end 72 | C.gfxFlushBuffers() 73 | C.gfxSwapBuffers() 74 | C.gspWaitForEvent(GSPGPU_EVENT_VBlank0, true) 75 | end 76 | 77 | return true 78 | -------------------------------------------------------------------------------- /src/lua/net/server.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Net.Server = Object.new(super) 3 | 4 | function Net.Server:new(port) 5 | ffi.luared.net_init() 6 | local self = super.new(self) 7 | 8 | self.clients = {} 9 | self.port = port 10 | 11 | local hostname = ffi.new('char[200]') 12 | C.gethostname(hostname, ffi.sizeof(hostname)) 13 | self.hostname = ffi.string(hostname) 14 | 15 | return self 16 | end 17 | 18 | function Net.Server:listen() 19 | if self.fd then 20 | error('server already started') 21 | end 22 | 23 | local fd = C.server_start(self.port) 24 | if fd ~= -1 then 25 | self.fd = fd 26 | else 27 | error('couldnt start server') 28 | end 29 | end 30 | 31 | function Net.Server:close() 32 | for i=1,#self.clients do 33 | self.clients[i]:close() 34 | self.clients[i] = nil 35 | end 36 | if self.fd then 37 | C.closesocket(self.fd) 38 | self.fd = nil 39 | end 40 | end 41 | 42 | function Net.Server.onnewclient() 43 | end 44 | 45 | local buf = ffi.new('char[512]') 46 | function Net.Server:run() 47 | if not self.fd then error('not listening') end 48 | 49 | -- get new connections 50 | local fd = C.server_listen(self.fd) 51 | if fd >= 0 then 52 | print('got new client') 53 | local client = Net.Client:new(fd) 54 | table.insert(self.clients, client) 55 | self:onnewclient(client) 56 | end 57 | 58 | -- listen on existing connections 59 | local i = 0 60 | while i < #self.clients do 61 | i = i + 1 62 | local client = self.clients[i] 63 | if client:recv() == false then 64 | -- disconnected 65 | print('disconnected') 66 | table.remove(self.clients, i) 67 | i = i - 1 68 | end 69 | end 70 | end 71 | 72 | function Net.Server:send(...) 73 | for _,client in ipairs(self.clients) do 74 | client:send(...) 75 | end 76 | end 77 | 78 | return Net.Server 79 | -------------------------------------------------------------------------------- /src/lua/ui/view.lua: -------------------------------------------------------------------------------- 1 | local super = require 'object' 2 | UI.View = Object.new(super) 3 | 4 | function UI.View:new(x, y, width, height) 5 | local self = super.new(self) 6 | self.x = x or 0 7 | self.y = y or 0 8 | self.width = width 9 | self.height = height 10 | self.subviews = {} 11 | return self 12 | end 13 | 14 | function UI.View:absolute_coords() 15 | if self.superview then 16 | local x, y = self.superview:absolute_coords() 17 | return self.x + x, self.y + y 18 | else 19 | return self.x, self.y 20 | end 21 | end 22 | 23 | function UI.View:contains_point(x, y) 24 | local absx, absy = self:absolute_coords() 25 | 26 | return x > absx and y > absy and 27 | x < absx + self.width and y < absy + self.height 28 | end 29 | 30 | function UI.View:contains_mouse() 31 | return self:contains_point(Mouse.x, Mouse.y) 32 | end 33 | 34 | function UI.View:add_subview(subview) 35 | self.subviews[#self.subviews + 1] = subview 36 | subview.superview = self 37 | end 38 | 39 | function UI.View:remove_from_superview() 40 | local subviews = self.superview.subviews 41 | for i=1,#subviews do 42 | if subviews[i] == self then 43 | table.remove(subviews, i) 44 | return 45 | end 46 | end 47 | error('superview doesnt have this subview? something weird is going on') 48 | end 49 | 50 | function UI.View:draw(scr, x, y) 51 | if self.background_color then 52 | ffi.luared.draw_set_color(unpack(self.background_color)) 53 | scr:rect(x, y, self.width, self.height) 54 | end 55 | end 56 | 57 | function UI.View:postdraw(scr, x, y) 58 | end 59 | 60 | function UI.View:render(scr, x, y) 61 | if self.hidden then return end 62 | assert(scr) 63 | 64 | x = (x or 0) + self.x 65 | y = (y or 0) + self.y 66 | 67 | self:draw(scr, x, y) 68 | 69 | for i=1,#self.subviews do 70 | self.subviews[i]:render(scr, x, y) 71 | end 72 | 73 | self:postdraw(scr, x, y) 74 | 75 | end 76 | 77 | return UI.View 78 | -------------------------------------------------------------------------------- /deps/include/mgba/util/arm-algo.S: -------------------------------------------------------------------------------- 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 | #if defined(__ARM_NEON) && !defined(PSP2) 7 | # r0: Destination 8 | # r1: Source 9 | # r2: Number of words to copy as halfwords 10 | .global _to16Bit 11 | _to16Bit: 12 | push {r4-r10} 13 | mov r8, r0 14 | mov r9, r1 15 | mov r10, r2 16 | .L0: 17 | tst r10, #15 18 | beq .L1 19 | ldr r0, [r9], #4 20 | strh r0, [r8], #2 21 | sub r10, #1 22 | b .L0 23 | .L1: 24 | vld4.16 {d0, d1, d2, d3}, [r9]! 25 | vld4.16 {d4, d5, d6, d7}, [r9]! 26 | vst2.16 {d0, d2}, [r8]! 27 | vst2.16 {d4, d6}, [r8]! 28 | subs r10, #16 29 | bne .L1 30 | pop {r4-r10} 31 | bx lr 32 | 33 | # r0: Destination 34 | # r1: Source 35 | # r2: Width 36 | # r3: Height 37 | .global _neon2x 38 | _neon2x: 39 | push {r4-r5} 40 | lsl r4, r2, #2 41 | .n20: 42 | mov r2, r4, lsr #4 43 | add r5, r0, r4 44 | .n21: 45 | vld2.32 {d0[], d1[]}, [r1]! 46 | vmov d2, d0 47 | vmov d3, d1 48 | vzip.16 d0, d2 49 | vzip.16 d1, d3 50 | vst1.32 {q0}, [r0]! 51 | vst1.32 {q0}, [r5]! 52 | subs r2, #1 53 | bne .n21 54 | subs r3, #1 55 | mov r0, r5 56 | bne .n20 57 | pop {r4-r5} 58 | bx lr 59 | 60 | .global _neon4x 61 | _neon4x: 62 | push {r4-r7} 63 | lsl r4, r2, #3 64 | .n40: 65 | mov r2, r4, lsr #5 66 | add r5, r0, r4 67 | add r6, r5, r4 68 | add r7, r6, r4 69 | .n41: 70 | vld4.16 {d0[], d1[], d2[], d3[]}, [r1]! 71 | vst1.16 {d0}, [r0]! 72 | vst1.16 {d0}, [r5]! 73 | vst1.16 {d0}, [r6]! 74 | vst1.16 {d0}, [r7]! 75 | vst1.16 {d1}, [r0]! 76 | vst1.16 {d1}, [r5]! 77 | vst1.16 {d1}, [r6]! 78 | vst1.16 {d1}, [r7]! 79 | vst1.16 {d2}, [r0]! 80 | vst1.16 {d2}, [r5]! 81 | vst1.16 {d2}, [r6]! 82 | vst1.16 {d2}, [r7]! 83 | vst1.16 {d3}, [r0]! 84 | vst1.16 {d3}, [r5]! 85 | vst1.16 {d3}, [r6]! 86 | vst1.16 {d3}, [r7]! 87 | subs r2, #1 88 | bne .n41 89 | subs r3, #1 90 | mov r0, r7 91 | bne .n40 92 | pop {r4-r7} 93 | bx lr 94 | #endif 95 | 96 | .section .note.GNU-stack,"",%progbits 97 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #ifndef DISABLE_THREADING 12 | #ifdef USE_PTHREADS 13 | #include "platform/posix/threading.h" 14 | #elif _WIN32 15 | #include "platform/windows/threading.h" 16 | #elif PSP2 17 | #include "platform/psp2/threading.h" 18 | #elif _3DS 19 | #include "platform/3ds/threading.h" 20 | #else 21 | #define DISABLE_THREADING 22 | #endif 23 | #endif 24 | #ifdef DISABLE_THREADING 25 | #ifdef _3DS 26 | // ctrulib already has a type called Thread 27 | #include <3ds/thread.h> 28 | #else 29 | typedef void* Thread; 30 | #endif 31 | typedef void* Mutex; 32 | typedef void* Condition; 33 | 34 | static inline int MutexInit(Mutex* mutex) { 35 | UNUSED(mutex); 36 | return 0; 37 | } 38 | 39 | static inline int MutexDeinit(Mutex* mutex) { 40 | UNUSED(mutex); 41 | return 0; 42 | } 43 | 44 | static inline int MutexLock(Mutex* mutex) { 45 | UNUSED(mutex); 46 | return 0; 47 | } 48 | 49 | static inline int MutexTryLock(Mutex* mutex) { 50 | UNUSED(mutex); 51 | return 0; 52 | } 53 | 54 | static inline int MutexUnlock(Mutex* mutex) { 55 | UNUSED(mutex); 56 | return 0; 57 | } 58 | 59 | static inline int ConditionInit(Condition* cond) { 60 | UNUSED(cond); 61 | return 0; 62 | } 63 | 64 | static inline int ConditionDeinit(Condition* cond) { 65 | UNUSED(cond); 66 | return 0; 67 | } 68 | 69 | static inline int ConditionWait(Condition* cond, Mutex* mutex) { 70 | UNUSED(cond); 71 | UNUSED(mutex); 72 | return 0; 73 | } 74 | 75 | static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) { 76 | UNUSED(cond); 77 | UNUSED(mutex); 78 | UNUSED(timeoutMs); 79 | return 0; 80 | } 81 | 82 | static inline int ConditionWake(Condition* cond) { 83 | UNUSED(cond); 84 | return 0; 85 | } 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | static inline uint32_t popcount32(unsigned bits) { 12 | bits = bits - ((bits >> 1) & 0x55555555); 13 | bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); 14 | return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; 15 | } 16 | 17 | static inline unsigned clz32(uint32_t bits) { 18 | #if defined(__GNUC__) || __clang__ 19 | return __builtin_clz(bits); 20 | #else 21 | static const int table[256] = { 22 | 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 23 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 24 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 25 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 28 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 29 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 38 | }; 39 | 40 | if (bits & 0xFF000000) { 41 | return table[bits >> 24]; 42 | } else if (bits & 0x00FF0000) { 43 | return table[bits >> 16] + 8; 44 | } else if (bits & 0x0000FF00) { 45 | return table[bits >> 8] + 16; 46 | } 47 | return table[bits] + 24; 48 | #endif 49 | } 50 | 51 | static inline uint32_t toPow2(uint32_t bits) { 52 | if (!bits) { 53 | return 0; 54 | } 55 | unsigned lz = clz32(bits - 1); 56 | return 1 << (32 - lz); 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | #include "core/input.h" 12 | #include "util/vector.h" 13 | 14 | struct GUIFont; 15 | 16 | enum GUIInput { 17 | GUI_INPUT_NONE = -1, 18 | GUI_INPUT_SELECT = 0, 19 | GUI_INPUT_BACK, 20 | GUI_INPUT_CANCEL, 21 | 22 | GUI_INPUT_UP, 23 | GUI_INPUT_DOWN, 24 | GUI_INPUT_LEFT, 25 | GUI_INPUT_RIGHT, 26 | 27 | GUI_INPUT_USER_START = 0x8, 28 | 29 | GUI_INPUT_MAX = 0x20 30 | }; 31 | 32 | enum GUICursorState { 33 | GUI_CURSOR_NOT_PRESENT = 0, 34 | GUI_CURSOR_UP, 35 | GUI_CURSOR_DOWN, 36 | GUI_CURSOR_CLICKED, 37 | GUI_CURSOR_DRAGGING 38 | }; 39 | 40 | enum { 41 | BATTERY_EMPTY = 0, 42 | BATTERY_LOW = 1, 43 | BATTERY_HALF = 2, 44 | BATTERY_HIGH = 3, 45 | BATTERY_FULL = 4, 46 | 47 | BATTERY_CHARGING = 8 48 | }; 49 | 50 | struct GUIBackground { 51 | void (*draw)(struct GUIBackground*, void* context); 52 | }; 53 | 54 | struct GUIParams { 55 | unsigned width; 56 | unsigned height; 57 | const struct GUIFont* font; 58 | const char* basePath; 59 | 60 | void (*drawStart)(void); 61 | void (*drawEnd)(void); 62 | uint32_t (*pollInput)(const struct mInputMap*); 63 | enum GUICursorState (*pollCursor)(unsigned* x, unsigned* y); 64 | int (*batteryState)(void); 65 | void (*guiPrepare)(void); 66 | void (*guiFinish)(void); 67 | 68 | // State 69 | struct mInputMap keyMap; 70 | int inputHistory[GUI_INPUT_MAX]; 71 | enum GUICursorState cursorState; 72 | int cx, cy; 73 | 74 | // Directories 75 | char currentPath[PATH_MAX]; 76 | size_t fileIndex; 77 | }; 78 | 79 | void GUIInit(struct GUIParams* params); 80 | void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput); 81 | enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y); 82 | void GUIInvalidateKeys(struct GUIParams* params); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/lua/ogg.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Ogg = Object.new(super) 3 | 4 | -- this doesnt work 5 | 6 | -- int stb_vorbis_decode_memory(const uint8 *mem, int len, int *channels, int *sample_rate, short **output); 7 | 8 | function Ogg:new(path) 9 | if created[path] then 10 | return created[path] 11 | end 12 | local self = super.new(self) 13 | 14 | local int = ffi.new('int[2]') 15 | local output = ffi.new('short *[1]') 16 | 17 | local bin = io.readbin(path) 18 | self.len = C.stb_vorbis_decode_memory(bin, ffi.sizeof(bin), int+0, int+1, output) 19 | if self.len <= 0 then 20 | error('couldnt open file: '..self.len) 21 | end 22 | 23 | self.channels = int[0] 24 | self.sample_rate = int[1] 25 | self.data = output[0] 26 | 27 | return SETGC(self, function() 28 | C.free(output[0]) 29 | end) 30 | end 31 | 32 | function Ogg:play() 33 | if PLAYING_SOUND then 34 | error('already playing') 35 | end 36 | PLAYING_SOUND = true 37 | UPDATE_CALLBACKS.ogg = function() 38 | local startId = bufferId 39 | while dspBuffer[bufferId].status == C.NDSP_WBUF_QUEUED or dspBuffer[bufferId].status == C.NDSP_WBUF_PLAYING do 40 | bufferId = bit.band(bufferId + 1, DSP_BUFFERS - 1) 41 | if bufferId == startId then 42 | return 43 | end 44 | end 45 | local tmpBuf = dspBuffer[bufferId].data_pcm16 46 | ffi.fill(dspBuffer+bufferId, ffi.sizeof(dspBuffer[bufferId])) 47 | dspBuffer[bufferId].data_pcm16 = tmpBuf 48 | dspBuffer[bufferId].nsamples = AUDIO_SAMPLES 49 | 50 | local len = math.min(self.len, AUDIO_SAMPLES * 2 * ffi.sizeof('s16')) 51 | ffi.copy(tmpBuf, self.data, len) 52 | C.DSP_FlushDataCache(tmpBuf, len) 53 | C.ndspChnWaveBufAdd(0, dspBuffer+bufferId) 54 | 55 | self.len = self.len - len 56 | self.data = self.data + len 57 | 58 | if self.len == 0 then 59 | PLAYING_SOUND = false 60 | UPDATE_CALLBACKS.ogg = nil 61 | end 62 | end 63 | end 64 | 65 | 66 | return Ogg 67 | -------------------------------------------------------------------------------- /deps/include/mgba/gba/rr/mgm.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 RR_MGM_H 7 | #define RR_MGM_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "gba/rr/rr.h" 12 | 13 | struct GBA; 14 | struct VDir; 15 | struct VFile; 16 | 17 | enum GBAMGMTag { 18 | // Playback tags 19 | TAG_INVALID = 0x00, 20 | TAG_INPUT = 0x01, 21 | TAG_FRAME = 0x02, 22 | TAG_LAG = 0x03, 23 | TAG_RESET = 0x04, 24 | 25 | // Stream chunking tags 26 | TAG_BEGIN = 0x10, 27 | TAG_END = 0x11, 28 | TAG_PREVIOUSLY = 0x12, 29 | TAG_NEXT_TIME = 0x13, 30 | TAG_MAX_STREAM = 0x14, 31 | 32 | // Recording information tags 33 | TAG_FRAME_COUNT = 0x20, 34 | TAG_LAG_COUNT = 0x21, 35 | TAG_RR_COUNT = 0x22, 36 | TAG_INIT = 0x24, 37 | TAG_INIT_EX_NIHILO = 0x24 | INIT_EX_NIHILO, 38 | TAG_INIT_FROM_SAVEGAME = 0x24 | INIT_FROM_SAVEGAME, 39 | TAG_INIT_FROM_SAVESTATE = 0x24 | INIT_FROM_SAVESTATE, 40 | TAG_INIT_FROM_BOTH = 0x24 | INIT_FROM_BOTH, 41 | 42 | // User metadata tags 43 | TAG_AUTHOR = 0x30, 44 | TAG_COMMENT = 0x31, 45 | 46 | TAG_EOF = INT_MAX 47 | }; 48 | 49 | struct GBAMGMContext { 50 | struct GBARRContext d; 51 | 52 | // Playback state 53 | bool isPlaying; 54 | bool autorecord; 55 | 56 | // Recording state 57 | bool isRecording; 58 | bool inputThisFrame; 59 | 60 | // Metadata 61 | uint32_t streamId; 62 | 63 | uint32_t maxStreamId; 64 | off_t maxStreamIdOffset; 65 | off_t initFromOffset; 66 | off_t rrCountOffset; 67 | 68 | // Streaming state 69 | struct VDir* streamDir; 70 | struct VFile* metadataFile; 71 | struct VFile* movieStream; 72 | uint16_t currentInput; 73 | enum GBAMGMTag peekedTag; 74 | uint32_t nextTime; 75 | uint32_t previously; 76 | }; 77 | 78 | void GBAMGMContextCreate(struct GBAMGMContext*); 79 | 80 | bool GBAMGMSetStream(struct GBAMGMContext* mgm, struct VDir* stream); 81 | bool GBAMGMCreateStream(struct GBAMGMContext* mgm, enum GBARRInitFrom initFrom); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /deps/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 "util/common.h" 10 | 11 | DECL_BITFIELD(mTileCacheConfiguration, uint32_t); 12 | DECL_BIT(mTileCacheConfiguration, ShouldStore, 0); 13 | 14 | DECL_BITFIELD(mTileCacheSystemInfo, uint32_t); 15 | DECL_BITS(mTileCacheSystemInfo, Palette0BPP, 0, 2); 16 | DECL_BITS(mTileCacheSystemInfo, Palette0Count, 2, 4); 17 | DECL_BITS(mTileCacheSystemInfo, Palette1BPP, 8, 2); 18 | DECL_BITS(mTileCacheSystemInfo, Palette1Count, 10, 4); 19 | DECL_BITS(mTileCacheSystemInfo, MaxTiles, 16, 13); 20 | 21 | struct mTileCacheEntry { 22 | uint32_t paletteVersion; 23 | uint32_t vramVersion; 24 | uint8_t vramClean; 25 | uint8_t paletteId; 26 | uint8_t activePalette; 27 | uint8_t padding; 28 | }; 29 | 30 | struct mTileCache { 31 | uint16_t* cache; 32 | struct mTileCacheEntry* status; 33 | uint32_t* globalPaletteVersion[2]; 34 | 35 | int activePalette; 36 | unsigned entries; 37 | unsigned count; 38 | unsigned entriesPerTile; 39 | unsigned bpp; 40 | 41 | uint16_t* vram; 42 | uint16_t* palette; 43 | uint16_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); 53 | void mTileCacheWriteVRAM(struct mTileCache* cache, uint32_t address); 54 | void mTileCacheWritePalette(struct mTileCache* cache, uint32_t address); 55 | void mTileCacheSetPalette(struct mTileCache* cache, int palette); 56 | 57 | const uint16_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId); 58 | const uint16_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/lua/wip/serverbrowser.lua: -------------------------------------------------------------------------------- 1 | local path = LUAPATH..'/config/servers.lua' 2 | 3 | local input = '' 4 | local ip = UI.Label:new('IP: ') 5 | ip.font = Font.MonoSpace 6 | ip:paint() 7 | 8 | local cancel = UI.Label:new('Press B to cancel') 9 | cancel:paint() 10 | 11 | local options = {} 12 | local saved_ips = {} 13 | 14 | local function closure(v) 15 | return function() 16 | startclient(v) 17 | DEBUG_TEXT = 'Connected to '..v 18 | end 19 | end 20 | 21 | ServerBrowser = {} 22 | function ServerBrowser:render() 23 | if Button.isdown(Button.b) then 24 | DISPLAY(Game, DebugMenu) 25 | end 26 | cancel:draw(Screen.top, 0, 0) 27 | ip:draw(Screen.top, (Screen.top.width - ip.width)/2, (Screen.top.height - ip.height)/2) 28 | Keyboard:render() 29 | end 30 | function ServerBrowser.key(key) 31 | if key == '\n' then 32 | table.insert(options, closure(input)) 33 | startclient(input) 34 | DEBUG_TEXT = 'Connected to '..input 35 | DISPLAY(Game, DebugMenu) 36 | local found = false 37 | for i,v in ipairs(saved_ips) do 38 | if v == input then 39 | found = true 40 | break 41 | end 42 | end 43 | if not found then 44 | table.insert(saved_ips, input) 45 | local f = io.open(path, 'w') 46 | f:write('return {\n') 47 | for i,v in pairs(saved_ips) do 48 | f:write(' "'..v..'",\n') 49 | end 50 | f:write('}\n') 51 | f:close() 52 | end 53 | else 54 | if key == '\b' then 55 | input = string.sub(input, 1, #input - 1) 56 | elseif #key == 1 then 57 | input = input..key 58 | end 59 | ip.text = 'IP: '..input 60 | ip:paint() 61 | end 62 | end 63 | 64 | local f = io.open(path, 'r') 65 | if f then 66 | f:close() 67 | saved_ips = dofile(path) 68 | for k,v in pairs(saved_ips) do 69 | options[v] = closure(v) 70 | end 71 | end 72 | 73 | 74 | options['add new'] = function() 75 | ip.text = 'IP: ' 76 | ip:paint() 77 | DISPLAY(ServerBrowser) 78 | end 79 | 80 | ROOT['connect to server'] = options 81 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "core/log.h" 12 | #include "gba/interface.h" 13 | 14 | #define MAX_GBAS 4 15 | 16 | extern const int GBASIOCyclesPerTransfer[4][MAX_GBAS]; 17 | 18 | mLOG_DECLARE_CATEGORY(GBA_SIO); 19 | 20 | enum { 21 | RCNT_INITIAL = 0x8000 22 | }; 23 | 24 | struct GBASIODriverSet { 25 | struct GBASIODriver* normal; 26 | struct GBASIODriver* multiplayer; 27 | struct GBASIODriver* joybus; 28 | }; 29 | 30 | struct GBASIO { 31 | struct GBA* p; 32 | 33 | enum GBASIOMode mode; 34 | struct GBASIODriverSet drivers; 35 | struct GBASIODriver* activeDriver; 36 | 37 | uint16_t rcnt; 38 | // TODO: Convert to bitfields 39 | union { 40 | struct { 41 | unsigned sc : 1; 42 | unsigned internalSc : 1; 43 | unsigned si : 1; 44 | unsigned idleSo : 1; 45 | unsigned : 4; 46 | unsigned start : 1; 47 | unsigned : 3; 48 | unsigned length : 1; 49 | unsigned : 1; 50 | unsigned irq : 1; 51 | unsigned : 1; 52 | } normalControl; 53 | 54 | struct { 55 | unsigned baud : 2; 56 | unsigned slave : 1; 57 | unsigned ready : 1; 58 | unsigned id : 2; 59 | unsigned error : 1; 60 | unsigned busy : 1; 61 | unsigned : 6; 62 | unsigned irq : 1; 63 | unsigned : 1; 64 | } multiplayerControl; 65 | 66 | uint16_t siocnt; 67 | }; 68 | }; 69 | 70 | void GBASIOInit(struct GBASIO* sio); 71 | void GBASIODeinit(struct GBASIO* sio); 72 | void GBASIOReset(struct GBASIO* sio); 73 | 74 | void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers); 75 | void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode); 76 | 77 | void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value); 78 | void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value); 79 | uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value); 80 | 81 | int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/CMakeToolchain.txt: -------------------------------------------------------------------------------- 1 | if(DEFINED ENV{DEVKITPRO}) 2 | set(DEVKITPRO $ENV{DEVKITPRO}) 3 | else() 4 | message(FATAL_ERROR "Could not find DEVKITPRO in environment") 5 | endif() 6 | 7 | if(DEFINED ENV{DEVKITARM}) 8 | set(DEVKITARM $ENV{DEVKITARM}) 9 | else() 10 | set(DEVKITARM ${DEVKITPRO}/devkitARM) 11 | endif() 12 | 13 | if(DEFINED ENV{CTRULIB}) 14 | set(CTRULIB $ENV{CTRULIB}) 15 | else() 16 | set(CTRULIB ${DEVKITPRO}/libctru) 17 | endif() 18 | 19 | set(extension) 20 | if (CMAKE_HOST_WIN32) 21 | set(extension .exe) 22 | endif() 23 | 24 | set(CMAKE_PROGRAM_PATH ${DEVKITARM}/bin) 25 | set(cross_prefix arm-none-eabi-) 26 | set(arch_flags "-march=armv6k -mtune=mpcore -mfpu=vfp -mfloat-abi=hard") 27 | set(inc_flags "-I${CTRULIB}/include ${arch_flags} -mword-relocations") 28 | set(link_flags "-L${CTRULIB}/lib -lctru -specs=3dsx.specs ${arch_flags}") 29 | 30 | set(CMAKE_SYSTEM_NAME Generic CACHE INTERNAL "system name") 31 | set(CMAKE_SYSTEM_PROCESSOR arm CACHE INTERNAL "processor") 32 | set(CMAKE_LIBRARY_ARCHITECTURE arm-none-eabi CACHE INTERNAL "abi") 33 | 34 | find_program(CMAKE_AR ${cross_prefix}gcc-ar${extension}) 35 | find_program(CMAKE_RANLIB ${cross_prefix}gcc-ranlib${extension}) 36 | find_program(CMAKE_C_COMPILER ${cross_prefix}gcc${extension}) 37 | find_program(CMAKE_CXX_COMPILER ${cross_prefix}g++${extension}) 38 | find_program(CMAKE_ASM_COMPILER ${cross_prefix}gcc${extension}) 39 | find_program(CMAKE_LINKER ${cross_prefix}ld${extension}) 40 | set(CMAKE_C_FLAGS ${inc_flags} CACHE INTERNAL "c compiler flags") 41 | set(CMAKE_ASM_FLAGS ${inc_flags} CACHE INTERNAL "assembler flags") 42 | set(CMAKE_CXX_FLAGS ${inc_flags} CACHE INTERNAL "cxx compiler flags") 43 | 44 | set(CMAKE_EXE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "exe link flags") 45 | set(CMAKE_MODULE_LINKER_FLAGS ${link_flags} CACHE INTERNAL "module link flags") 46 | set(CMAKE_SHARED_LINKER_FLAGS ${link_flags} CACHE INTERNAL "shared link flags") 47 | 48 | set(CMAKE_FIND_ROOT_PATH ${DEVKITARM}/arm-none-eabi) 49 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE INTERNAL "") 50 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE INTERNAL "") 51 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE INTERNAL "") 52 | set(PKG_CONFIG_EXECUTABLE "/dev/null" CACHE INTERNAL "" FORCE) 53 | 54 | set(3DS ON) 55 | add_definitions(-D_3DS -DARM11) 56 | -------------------------------------------------------------------------------- /deps/include/mgba/feature/gui/gui-runner.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 GUI_RUNNER_H 7 | #define GUI_RUNNER_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "core/config.h" 12 | #include "feature/gui/remap.h" 13 | #include "gba/hardware.h" 14 | #include "util/circle-buffer.h" 15 | #include "util/gui.h" 16 | 17 | enum mGUIInput { 18 | mGUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START, 19 | mGUI_INPUT_DECREASE_BRIGHTNESS, 20 | mGUI_INPUT_SCREEN_MODE, 21 | mGUI_INPUT_SCREENSHOT, 22 | mGUI_INPUT_FAST_FORWARD, 23 | }; 24 | 25 | struct mGUIBackground { 26 | struct GUIBackground d; 27 | struct mGUIRunner* p; 28 | 29 | color_t* screenshot; 30 | int screenshotId; 31 | }; 32 | 33 | struct mCore; 34 | struct mGUIRunnerLux { 35 | struct GBALuminanceSource d; 36 | int luxLevel; 37 | }; 38 | 39 | struct mGUIRunner { 40 | struct mCore* core; 41 | struct GUIParams params; 42 | 43 | struct mGUIBackground background; 44 | struct mGUIRunnerLux luminanceSource; 45 | 46 | struct mInputMap guiKeys; 47 | struct mCoreConfig config; 48 | struct GUIMenuItem* configExtra; 49 | size_t nConfigExtra; 50 | 51 | struct GUIInputKeys* keySources; 52 | 53 | const char* port; 54 | float fps; 55 | int64_t lastFpsCheck; 56 | int32_t totalDelta; 57 | struct CircleBuffer fpsBuffer; 58 | 59 | void (*setup)(struct mGUIRunner*); 60 | void (*teardown)(struct mGUIRunner*); 61 | void (*gameLoaded)(struct mGUIRunner*); 62 | void (*gameUnloaded)(struct mGUIRunner*); 63 | void (*prepareForFrame)(struct mGUIRunner*); 64 | void (*drawFrame)(struct mGUIRunner*, bool faded); 65 | void (*drawScreenshot)(struct mGUIRunner*, const color_t* pixels, unsigned width, unsigned height, bool faded); 66 | void (*paused)(struct mGUIRunner*); 67 | void (*unpaused)(struct mGUIRunner*); 68 | void (*incrementScreenMode)(struct mGUIRunner*); 69 | void (*setFrameLimiter)(struct mGUIRunner*, bool limit); 70 | uint16_t (*pollGameInput)(struct mGUIRunner*); 71 | }; 72 | 73 | void mGUIInit(struct mGUIRunner*, const char* port); 74 | void mGUIDeinit(struct mGUIRunner*); 75 | void mGUIRun(struct mGUIRunner*, const char* path); 76 | void mGUIRunloop(struct mGUIRunner*); 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/lua/red/start_menu/party.lua: -------------------------------------------------------------------------------- 1 | local show_party_hax 2 | 3 | local function label(str) 4 | local label = UI.Label:new(str) 5 | label.color = {0x00, 0x00, 0x00} 6 | label.background_color = {0xff, 0xff, 0xff} 7 | label:paint() 8 | return label 9 | end 10 | 11 | function show_party_hax(idx) 12 | local party = {} 13 | for i=0,Red.wram.wPartyCount-1 do 14 | local species = Red.wram.wPartySpecies[i] 15 | local pic = getpic(species, 'front') 16 | local bmap = getbmon(pic) 17 | local dex = Red.Dex.Species[species] 18 | 19 | local nick = Red.wram.wPartyMonNicks[i] 20 | local mon = Red.wram.wPartyMons[i] 21 | local moves = '' 22 | for i=0,3 do 23 | local move = Red.Dex.Move[mon.box.Moves[i]] 24 | if not move then 25 | moves = string.sub(moves, 1, #moves - 2) 26 | break 27 | end 28 | moves = moves..move.name..', ' 29 | end 30 | if not(nick == dex.name) then 31 | nick = nick..' ('..dex.name..')' 32 | end 33 | local labels = { 34 | label(nick), 35 | label('Lvl '..mon.Level), 36 | label('Moves: '..moves), 37 | } 38 | table.insert(party, {labels = labels, bmap = bmap}) 39 | end 40 | RENDER_CALLBACKS.partymenu = function() 41 | if Button.isdown(Button.b) then 42 | RENDER_CALLBACKS.partymenu = nil 43 | emu.halt = false 44 | end 45 | C.draw_set_color(0xff, 0xff, 0xff) 46 | Screen.top:rect(0, 0, Screen.top.width, Screen.top.height) 47 | local y = 0 48 | for i,v in ipairs(party) do 49 | v.bmap:draw(Screen.top, 0, y) 50 | for i,label in ipairs(v.labels) do 51 | local y = y + label.fontsize*(i-1) 52 | label:draw(Screen.top, v.bmap.width, y) 53 | end 54 | y = y + v.bmap.height 55 | end 56 | end 57 | end 58 | 59 | 60 | 61 | 62 | local party_open = false 63 | 64 | emu:hook(Red.sym.RedisplayStartMenu, function() 65 | party_open = false 66 | end) 67 | 68 | emu:hook(Red.sym.StartMenu_Pokemon, function() 69 | if party_open then return end 70 | party_open = true 71 | 72 | Button.KeysDown = 0 73 | show_party_hax(1) 74 | 75 | emu.halt = true 76 | return true 77 | end) 78 | -------------------------------------------------------------------------------- /src/lua/net/client.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Net.Client = Object.new(super) 3 | 4 | function Net.Client:new(fd) 5 | ffi.luared.net_init() 6 | local self = super.new(self) 7 | 8 | self.fd = fd -- optional 9 | 10 | return self 11 | end 12 | 13 | function Net.Client:connect(ip, port) 14 | if self.fd then 15 | error('connection already established') 16 | end 17 | self.remote_ip = ip 18 | self.remote_port = port 19 | local fd = ffi.luared.client_start(ip, tostring(port)) 20 | if fd == -1 then 21 | error('could not connect: '..ffi.string(ffi.luared.lr_net_error)) 22 | end 23 | self.fd = fd 24 | end 25 | 26 | function Net.Client:is_connected() 27 | return self.fd and (PLATFORM == '3ds' or not self.remote_ip or ffi.luared.client_is_connected(self.fd)) 28 | end 29 | 30 | function Net.Client:close() 31 | if not self.fd then return end 32 | 33 | ffi.luared.closesocket(self.fd) 34 | self.fd = nil 35 | end 36 | 37 | local buf = ffi.new('char[512]') 38 | function Net.Client:recv() 39 | if not self:is_connected() then 40 | error('not connected') 41 | end 42 | 43 | local len = C.recv(self.fd, buf, ffi.sizeof(buf), 0) 44 | if len == 0 then 45 | self.fd = nil 46 | return false 47 | elseif len ~= -1 then 48 | local data = ffi.string(buf, len) 49 | self.backlog = self.backlog or {} 50 | if self.partialdata then 51 | data = self.partialdata..data 52 | self.partialdata = nil 53 | end 54 | local parsedlen = 0 55 | for line in string.gmatch(data, "([^\n]*)\n") do 56 | parsedlen = #line + 1 57 | table.insert(self.backlog, line) 58 | end 59 | if not(parsedlen == #data) then 60 | self.partialdata = string.sub(data, parsedlen + 1, #data) 61 | end 62 | return true 63 | end 64 | end 65 | 66 | function Net.Client:send(data) 67 | if not self:is_connected() then 68 | error('not connected') 69 | end 70 | 71 | if type(data) == 'string' then 72 | return C.send(self.fd, data, #data, 0) 73 | elseif type(data) == 'cdata' then 74 | return C.send(self.fd, data, ffi.sizeof(data), 0) 75 | elseif type(data) == 'table' then 76 | return self:send(data:serialize()) 77 | else 78 | error('unsupportred type '..type(data)) 79 | end 80 | end 81 | 82 | return Net.Client 83 | -------------------------------------------------------------------------------- /src/lua/ui/label.lua: -------------------------------------------------------------------------------- 1 | local super = require 'ui.view' 2 | UI.Label = Object.new(super) 3 | 4 | local C_FONTS = {} 5 | 6 | --[[ 7 | local back_button = ui.button:new('< Back') 8 | back_button.x = 0 9 | back_button.y = 0 10 | back_button.font = Font.Default 11 | back_button.fontsize = 20 12 | function back_button:pressed() 13 | DISPLAY[2] = DebugMenu 14 | end 15 | ]] 16 | 17 | function UI.Label:new(text, fontsize, color) 18 | local self = super.new(self) 19 | self.text = text 20 | self.color = color or {0xff, 0xff, 0xff} 21 | self.background_color = {0x00, 0x00, 0x00} 22 | self.font = Font.Default 23 | self.fontsize = fontsize or 12 24 | return self 25 | end 26 | 27 | local intptr = ffi.new('int[2]') 28 | function UI.Label:paint() 29 | if not self.text then error('text not set') end 30 | 31 | if not(self.lasttext == self.text) then 32 | self.cfont = Font:new(self.font) 33 | local pix, width, height = self.cfont:paint(self.text, self.fontsize) 34 | self.width = width 35 | self.height = height 36 | 37 | if pix == ffi.NULL then error('wtf') end 38 | self.rawbmap = Bitmap:new{ 39 | pix = pix, 40 | width = width, 41 | height = height, 42 | channels = 1, 43 | } 44 | end 45 | 46 | if self.background_color == false then 47 | self.bmap = self.rawbmap 48 | else 49 | local w,h = self.width,self.height 50 | local bmap = Bitmap:new(w, h) 51 | ffi.luared.draw_set_color(unpack(self.background_color)) 52 | ffi.luared.draw_rect(bmap.pix, w, h, 0, 0, w, h) 53 | ffi.luared.draw_set_color(unpack(self.color)) 54 | ffi.luared.purealphacopy( 55 | bmap.pix, w, h, 0, 0, 56 | self.rawbmap.pix, w, h 57 | ) 58 | self.bmap = bmap 59 | end 60 | self.lasttext = self.text 61 | end 62 | 63 | function UI.Label:unpaint() 64 | self.bmap = nil 65 | end 66 | 67 | function UI.Label:draw(scr, x, y) 68 | if not self.bmap then error('label not painted') end 69 | 70 | if self.background_color == false then 71 | ffi.luared.draw_set_color(unpack(self.color)) 72 | ffi.luared.purealphacopy( 73 | scr.pix, scr.width, scr.height, x, y, 74 | self.bmap.pix, self.bmap.width, self.bmap.height 75 | ) 76 | else 77 | self.bmap:draw(scr, x, y) 78 | end 79 | end 80 | 81 | return UI.Label 82 | -------------------------------------------------------------------------------- /deps/include/mgba/debugger/cli-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 CLI_DEBUGGER_H 7 | #define CLI_DEBUGGER_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "debugger.h" 12 | 13 | #ifdef USE_CLI_DEBUGGER 14 | #include 15 | 16 | struct CLIDebugger; 17 | 18 | struct CLIDebugVector { 19 | struct CLIDebugVector* next; 20 | enum CLIDVType { 21 | CLIDV_ERROR_TYPE, 22 | CLIDV_INT_TYPE, 23 | CLIDV_CHAR_TYPE, 24 | } type; 25 | union { 26 | char* charValue; 27 | struct { 28 | int32_t intValue; 29 | int segmentValue; 30 | }; 31 | }; 32 | }; 33 | 34 | typedef void (*CLIDebuggerCommand)(struct CLIDebugger*, struct CLIDebugVector*); 35 | typedef struct CLIDebugVector* (*CLIDVParser)(struct CLIDebugger* debugger, const char* string, size_t length); 36 | 37 | struct CLIDebuggerCommandSummary { 38 | const char* name; 39 | CLIDebuggerCommand command; 40 | CLIDVParser parser; 41 | const char* summary; 42 | }; 43 | 44 | struct CLIDebuggerSystem { 45 | struct CLIDebugger* p; 46 | 47 | void (*init)(struct CLIDebuggerSystem*); 48 | void (*deinit)(struct CLIDebuggerSystem*); 49 | bool (*custom)(struct CLIDebuggerSystem*); 50 | 51 | void (*disassemble)(struct CLIDebuggerSystem*, struct CLIDebugVector* dv); 52 | uint32_t (*lookupIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); 53 | uint32_t (*lookupPlatformIdentifier)(struct CLIDebuggerSystem*, const char* name, struct CLIDebugVector* dv); 54 | void (*printStatus)(struct CLIDebuggerSystem*); 55 | 56 | struct CLIDebuggerCommandSummary* commands; 57 | const char* name; 58 | struct CLIDebuggerCommandSummary* platformCommands; 59 | const char* platformName; 60 | }; 61 | 62 | struct CLIDebugger { 63 | struct mDebugger d; 64 | 65 | struct CLIDebuggerSystem* system; 66 | 67 | EditLine* elstate; 68 | History* histate; 69 | }; 70 | 71 | struct CLIDebugVector* CLIDVParse(struct CLIDebugger* debugger, const char* string, size_t length); 72 | struct CLIDebugVector* CLIDVStringParse(struct CLIDebugger* debugger, const char* string, size_t length); 73 | 74 | void CLIDebuggerCreate(struct CLIDebugger*); 75 | void CLIDebuggerAttachSystem(struct CLIDebugger*, struct CLIDebuggerSystem*); 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /src/lua/red/render/battle.lua: -------------------------------------------------------------------------------- 1 | local function monbank(num) 2 | -- game freak was lazy and hardcoded it 3 | -- so i have to too :( 4 | if num <= 0x1e then 5 | return 0x09 6 | elseif num <= 0x49 then 7 | return 0x0a 8 | elseif num <= 0x72 then 9 | return 0x0b 10 | elseif num <= 0x98 then 11 | return 0x0c 12 | else 13 | return 0x0d 14 | end 15 | end 16 | 17 | function getpic(species, facing) 18 | if species < 1 or species > 190 then return end 19 | local self = Red 20 | local siz = 28 21 | local offset 22 | if facing == 'front' then 23 | offset = 11 24 | elseif facing == 'back' then 25 | offset = 13 26 | end 27 | 28 | if species == 21 then 29 | -- mew get special treatment 30 | local rom = self.rom.MewBaseStats + offset 31 | local addr = rom[0] + rom[1]*0x100 32 | return emu:rom(0x01, addr) 33 | else 34 | local dex = self.rom.PokedexOrder[species - 1] 35 | if dex == 0 then return end 36 | local rom = self.rom.MonBaseStats + (dex - 1)*siz + offset 37 | local addr = rom[0] + rom[1]*0x100 38 | return emu:rom(monbank(species), addr) 39 | end 40 | end 41 | 42 | local lastfriend, lastenemy 43 | local friendbmap, enemybmap 44 | 45 | function Red:render_battlesprites() 46 | local friend = self.wram.wBattleMon.Species 47 | local enemy = self.wram.wEnemyMon.Species 48 | 49 | local friendpic = getpic(friend, 'back') 50 | local enemypic = getpic(enemy, 'front') 51 | 52 | if not friendpic then 53 | friendbmap = nil 54 | lastfriend = nil 55 | elseif not(lastfriend == friend) then 56 | lastfriend = friend 57 | friendbmap = getbmon(friendpic) 58 | end 59 | 60 | if not enemypic then 61 | enemybmap = nil 62 | lastenemy = nil 63 | elseif not(lastenemy == enemy) then 64 | lastenemy = enemy 65 | enemybmap = getbmon(enemypic) 66 | end 67 | 68 | if friendbmap then 69 | friendbmap:draw(Screen.top, 0, Screen.top.height - friendbmap.height) 70 | end 71 | 72 | if enemybmap then 73 | enemybmap:draw(Screen.top, Screen.top.width - enemybmap.width, 0) 74 | end 75 | end 76 | 77 | function getbmon(rom) 78 | local self = Red 79 | local pic = Red.Pic:new(rom) 80 | local bpp = pic:decompress() 81 | 82 | return BPP(bpp, pic.width, pic.height, 'transpose') 83 | end 84 | -------------------------------------------------------------------------------- /src/lua/red/render/bpp.lua: -------------------------------------------------------------------------------- 1 | local switcharoo = { 2 | 0, 3 | 2, 4 | 3, 5 | } 6 | 7 | local invis_color = {SPRITE_INVIS_COLOR, SPRITE_INVIS_COLOR, SPRITE_INVIS_COLOR} 8 | 9 | local step -- forward decl 10 | 11 | function BPP(getbpp, width, height, ...) 12 | local is_sprite, make_ff_invis_anyway, transpose, raw 13 | for _,v in ipairs{...} do 14 | if v == 'is_sprite' then 15 | is_sprite = true 16 | elseif v == 'make_ff_invis_anyway' then 17 | make_ff_invis_anyway = true 18 | elseif v == 'transpose' then 19 | transpose = true 20 | elseif v == 'raw' then 21 | raw = true 22 | end 23 | end 24 | 25 | if not(type(getbpp) == 'function') then 26 | local ptr = getbpp 27 | getbpp = function(i) 28 | return ptr + i*16 29 | end 30 | end 31 | 32 | local pix = ffi.new('uint8_t[?]', width*height*3) 33 | 34 | for i=0,(width/Red.Tilesize)*(height/Red.Tilesize)-1 do 35 | step(pix, getbpp(i), i, width/Red.Tilesize, is_sprite, make_ff_invis_anyway, transpose) 36 | end 37 | 38 | if raw then return pix end 39 | 40 | local bmap = Bitmap:new{ 41 | pix = pix, 42 | width = width, 43 | height = height, 44 | channels = 3, 45 | } 46 | return bmap 47 | end 48 | 49 | function step(pix, bpp, i, width, is_sprite, make_ff_invis_anyway, transpose) 50 | local yy = Red.Tilesize*math.floor(i/width) 51 | local xx = Red.Tilesize*math.floor(i%width) 52 | if transpose then 53 | local tmp = xx 54 | xx = yy 55 | yy = tmp 56 | end 57 | for y=0,Red.Tilesize-1 do 58 | local low = bpp[2*y + 0] 59 | local high = bpp[2*y + 1] 60 | for x=0,Red.Tilesize-1 do 61 | local val = bit.band(1, bit.rshift(low, 7-x)) 62 | val = val + 2*bit.band(1, bit.rshift(high, 7-x)) 63 | val = 3 - val 64 | --val = math.floor(val*0xff/3) 65 | if is_sprite then 66 | val = switcharoo[val + 1] 67 | elseif make_ff_invis_anyway and val == 3 then 68 | val = nil 69 | end 70 | local idx = (yy+y)*width*8 + x + xx 71 | local color = val and Rainbow[val+1] or invis_color 72 | pix[idx*3 + 0] = color[0+1] 73 | pix[idx*3 + 1] = color[1+1] 74 | pix[idx*3 + 2] = color[2+1] 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /deps/include/mgba/core/interface.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 CORE_INTERFACE_H 7 | #define CORE_INTERFACE_H 8 | 9 | #include "util/common.h" 10 | 11 | struct mCore; 12 | 13 | #ifdef COLOR_16_BIT 14 | typedef uint16_t color_t; 15 | #define BYTES_PER_PIXEL 2 16 | #else 17 | typedef uint32_t color_t; 18 | #define BYTES_PER_PIXEL 4 19 | #endif 20 | 21 | #define M_R5(X) ((X) & 0x1F) 22 | #define M_G5(X) (((X) >> 5) & 0x1F) 23 | #define M_B5(X) (((X) >> 10) & 0x1F) 24 | 25 | #define M_R8(X) (((((X) << 3) & 0xF8) * 0x21) >> 5) 26 | #define M_G8(X) (((((X) >> 2) & 0xF8) * 0x21) >> 5) 27 | #define M_B8(X) (((((X) >> 7) & 0xF8) * 0x21) >> 5) 28 | 29 | struct blip_t; 30 | 31 | struct mCoreCallbacks { 32 | void* context; 33 | void (*videoFrameStarted)(void* context); 34 | void (*videoFrameEnded)(void* context); 35 | void (*coreCrashed)(void* context); 36 | }; 37 | 38 | struct mAVStream { 39 | void (*videoDimensionsChanged)(struct mAVStream*, unsigned width, unsigned height); 40 | void (*postVideoFrame)(struct mAVStream*, const color_t* buffer, size_t stride); 41 | void (*postAudioFrame)(struct mAVStream*, int16_t left, int16_t right); 42 | void (*postAudioBuffer)(struct mAVStream*, struct blip_t* left, struct blip_t* right); 43 | }; 44 | 45 | struct mKeyCallback { 46 | uint16_t (*readKeys)(struct mKeyCallback*); 47 | }; 48 | 49 | struct mStopCallback { 50 | void (*stop)(struct mStopCallback*); 51 | }; 52 | 53 | struct mRotationSource { 54 | void (*sample)(struct mRotationSource*); 55 | 56 | int32_t (*readTiltX)(struct mRotationSource*); 57 | int32_t (*readTiltY)(struct mRotationSource*); 58 | 59 | int32_t (*readGyroZ)(struct mRotationSource*); 60 | }; 61 | 62 | struct mRTCSource { 63 | void (*sample)(struct mRTCSource*); 64 | 65 | time_t (*unixTime)(struct mRTCSource*); 66 | }; 67 | 68 | enum mRTCGenericType { 69 | RTC_NO_OVERRIDE, 70 | RTC_FIXED, 71 | RTC_FAKE_EPOCH 72 | }; 73 | 74 | struct mRTCGenericSource { 75 | struct mRTCSource d; 76 | struct mCore* p; 77 | enum mRTCGenericType override; 78 | int64_t value; 79 | }; 80 | 81 | void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core); 82 | 83 | struct mRumble { 84 | void (*setRumble)(struct mRumble*, int enable); 85 | }; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/lua/init.lua: -------------------------------------------------------------------------------- 1 | ROOT['load ROM'] = {} 2 | for _,v in pairs(ls(PATH..'/rom') or {}) do 3 | if string.has_suffix(v, '.gbc') or string.has_suffix(v, '.gb') then 4 | ROOT['load ROM'][v] = function() 5 | emu = Gameboy:new(PATH..'/rom/'..v) 6 | RENDER_CALLBACKS.lua_logo = nil 7 | Red:reset() 8 | end 9 | end 10 | end 11 | 12 | 13 | ROOT['tile editor'] = function() 14 | DISPLAY[2] = TileEditor 15 | end 16 | 17 | ROOT.console = function() 18 | DISPLAY(Console) 19 | end 20 | ROOT.quit = function() 21 | if PLATFORM == '3ds' then 22 | wants_to_exit = true 23 | else 24 | SHOULD_QUIT = true 25 | end 26 | end 27 | 28 | Screen.init() 29 | 30 | require 'game' 31 | require 'debug_menu' 32 | DISPLAY(Game, DebugMenu) 33 | 34 | local quit_label = UI.Label:new() 35 | quit_label.text = 'Press A to quit' 36 | quit_label.color = {0xdd, 0x22, 0x22} 37 | quit_label.fontsize = 30 38 | quit_label:paint() 39 | quit_label.x = (Screen.top.width - quit_label.width)/2 40 | quit_label.y = (Screen.top.height - quit_label.height)/2 41 | 42 | local cancel_label = UI.Label:new() 43 | cancel_label.text = 'Press B to cancel' 44 | cancel_label.color = {0xdd, 0xdd, 0xdd} 45 | cancel_label.fontsize = 20 46 | cancel_label:paint() 47 | cancel_label.x = (Screen.top.width - cancel_label.width)/2 48 | cancel_label.y = quit_label.y + quit_label.height 49 | 50 | DT = 0 51 | 52 | function MAIN_LOOP() 53 | 54 | DT = CALCULATE_DT(DT) 55 | 56 | if SHOULD_QUIT then 57 | return true 58 | end 59 | 60 | 61 | Button.Scan() 62 | Mouse.Scan() 63 | if wants_to_exit then 64 | if Button.isdown(Button.a) then 65 | return true 66 | elseif Button.isdown(Button.b) then 67 | wants_to_exit = false 68 | return 69 | end 70 | end 71 | 72 | for k,v in pairs(UPDATE_CALLBACKS) do 73 | v() 74 | end 75 | 76 | Screen.startframe() 77 | DISPLAY.render() 78 | 79 | if wants_to_exit then 80 | C.draw_set_color(0x00, 0x00, 0x00) 81 | Screen.top:rect(0, quit_label.y - 5, Screen.top.width, quit_label.height + cancel_label.height + 10) 82 | quit_label:render(Screen.top) 83 | cancel_label:render(Screen.top) 84 | end 85 | 86 | Screen.endframe() 87 | end 88 | 89 | require 'tmp' 90 | 91 | local path = LUAPATH..'/config/autorun.lua' 92 | local f = io.open(path, 'r') 93 | if f then 94 | f:close() 95 | dofile(path) 96 | end 97 | -------------------------------------------------------------------------------- /src/lua/bitmap.lua: -------------------------------------------------------------------------------- 1 | local super = Object 2 | Bitmap = Object.new(super) 3 | 4 | local loaded_bitmaps 5 | function Bitmap.ResetCache() 6 | loaded_bitmaps = setmetatable({}, {__mode = 'v'}) 7 | end 8 | Bitmap.ResetCache() 9 | 10 | local ptr = ffi.new('int[3]') 11 | function Bitmap:new(arg1, arg2, arg3, arg4) 12 | local self = super.new(self) 13 | if type(arg1) == 'string' then 14 | local path = arg1 15 | if loaded_bitmaps[path] then 16 | return loaded_bitmaps[path] 17 | else 18 | loaded_bitmaps[path] = self 19 | end 20 | 21 | -- init 22 | local cpix = C.stbi_load(path, ptr + 0, ptr + 1, ptr + 2, arg2 or 0) 23 | if cpix == ffi.NULL then 24 | local reason = C.stbi_failure_reason() 25 | if reason == ffi.NULL then 26 | error('failed: (path: '..path..')') 27 | else 28 | error(ffi.string(C.stbi_failure_reason())..' (path: '..path..')') 29 | end 30 | end 31 | self.width, self.height, self.channels = ptr[0], ptr[1], ptr[2] 32 | 33 | -- copy external C data into something garbage collectable 34 | self.pix = ffi.new('uint8_t[?]', self.width*self.height*self.channels) 35 | ffi.copy(self.pix, cpix, ffi.sizeof(self.pix)) 36 | C.free(cpix) 37 | 38 | self.path = path 39 | elseif type(arg1) == 'table' and not arg2 then 40 | self = arg1 41 | setmetatable(self, {__index = Bitmap}) 42 | elseif type(arg1) == 'number' and type(arg2) == 'number' and not arg4 then 43 | arg3 = arg3 or 3 44 | self.width, self.height, self.channels = arg1, arg2, arg3 45 | self.pix = ffi.new('uint8_t[?]', self.width*self.height*self.channels) 46 | elseif arg1 and arg2 and arg3 and arg4 then 47 | self.pix, self.width, self.height, self.channels = arg1, arg2, arg3, arg4 48 | else 49 | error('invalid args') 50 | end 51 | 52 | return self 53 | end 54 | 55 | function Bitmap:save(path) 56 | C.stbi_write_png(path, self.width, self.height, self.channels, self.pix, self.width*self.channels) 57 | end 58 | 59 | function Bitmap:draw(scr, x, y) 60 | ffi.luared.dumbcopy( 61 | scr.pix, scr.width, scr.height, x, y, 62 | self.pix, self.width, self.height, 3 63 | ) 64 | end 65 | 66 | function Bitmap:drawaf(scr, x, y, should_flip) 67 | ffi.luared.dumbcopyaf( 68 | scr.pix, scr.width, scr.height, x, y, 69 | self.pix, self.width, self.height, SPRITE_INVIS_COLOR, should_flip and true or false 70 | ) 71 | end 72 | 73 | return Bitmap 74 | -------------------------------------------------------------------------------- /src/lua/red/dialogue.lua: -------------------------------------------------------------------------------- 1 | -- WIP dialogue reader / printer 2 | 3 | local convert_str, update_labels --forward decl 4 | 5 | emu:hook(Red.sym.PrintText_NoCreatingTextBox, function() 6 | local hl = emu.gb.cpu.hl 7 | local bank = emu.gb.memory.currentBank 8 | 9 | if hl >= 0x8000 then 10 | -- i have no idea why this is even necessary 11 | return 12 | end 13 | 14 | local romfile, rom 15 | 16 | if not TRANSLATION_ROM then 17 | rom = emu:rom(bank, hl) 18 | romfile = emu.romfile 19 | else 20 | local sym = Red.sym[bank*0x10000 + hl] 21 | if not sym then 22 | error(string.format('could not lookup symbol for %.2x:%.4x', bank, hl)) 23 | end 24 | rom = TRANSLATION_ROM.rom[sym.name] 25 | if not rom then 26 | error('could not lookup symbol for '..sym.name) 27 | end 28 | romfile = TRANSLATION_ROM 29 | end 30 | 31 | if rom[0] == 0x17 then 32 | local addr = rom[2] * 0x100 + rom[1] 33 | local bank = rom[3] 34 | local rom = romfile:lookup(bank, addr) 35 | local str = convert_str(rom + 1) 36 | 37 | update_labels(str) 38 | end 39 | end) 40 | 41 | function convert_str(rom) 42 | local str = '' 43 | local i = 0 44 | while true do 45 | local x = rom[i] 46 | if x == 0 or x == 87 then break end 47 | 48 | local conv = Red.CharDecode(x, true) 49 | if x == 80 and rom[i + 1] == 1 then 50 | -- apparently 80, then 1 triggers reading from wram?? 51 | local addr = rom[i + 2] + rom[i + 3]*0x100 52 | str = str..convert_str(emu.wram + addr) 53 | i = i + 3 54 | else 55 | str = str..conv 56 | end 57 | i = i + 1 58 | end 59 | return str 60 | end 61 | 62 | 63 | -- Shitty printer 64 | 65 | local labels 66 | function update_labels(dialogue) 67 | labels = {} 68 | local function doit(s) 69 | local siz = 45 70 | if #s > siz then 71 | doit(string.sub(s, 1, siz)) 72 | doit(string.sub(s, siz+1, #s)) 73 | return 74 | end 75 | 76 | local label = UI.Label:new(s) 77 | label:paint() 78 | table.insert(labels, label) 79 | end 80 | for i,s in ipairs(string.split(dialogue, '\n')) do 81 | doit(s) 82 | end 83 | end 84 | function SHITTY_DIALOGUE_PRINTER() 85 | if labels then 86 | for i,label in ipairs(labels) do 87 | label:draw(Screen.bottom, 0, emu.height + (i - 1)*label.fontsize) 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /deps/include/mgba/util/gui/font.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_FONT_H 7 | #define GUI_FONT_H 8 | 9 | #include "util/common.h" 10 | 11 | struct GUIFont; 12 | struct GUIFont* GUIFontCreate(void); 13 | void GUIFontDestroy(struct GUIFont*); 14 | 15 | enum GUIAlignment { 16 | GUI_ALIGN_LEFT = 1, 17 | GUI_ALIGN_HCENTER = 3, 18 | GUI_ALIGN_RIGHT = 2, 19 | 20 | GUI_ALIGN_TOP = 4, 21 | GUI_ALIGN_VCENTER = 12, 22 | GUI_ALIGN_BOTTOM = 8, 23 | }; 24 | 25 | enum GUIOrientation { 26 | GUI_ORIENT_0, 27 | GUI_ORIENT_90_CCW, 28 | GUI_ORIENT_180, 29 | GUI_ORIENT_270_CCW, 30 | 31 | GUI_ORIENT_VMIRROR, 32 | GUI_ORIENT_HMIRROR, 33 | 34 | GUI_ORIENT_90_CW = GUI_ORIENT_270_CCW, 35 | GUI_ORIENT_270_CW = GUI_ORIENT_90_CCW 36 | }; 37 | 38 | enum GUIIcon { 39 | GUI_ICON_BATTERY_FULL, 40 | GUI_ICON_BATTERY_HIGH, 41 | GUI_ICON_BATTERY_HALF, 42 | GUI_ICON_BATTERY_LOW, 43 | GUI_ICON_BATTERY_EMPTY, 44 | GUI_ICON_SCROLLBAR_THUMB, 45 | GUI_ICON_SCROLLBAR_TRACK, 46 | GUI_ICON_SCROLLBAR_BUTTON, 47 | GUI_ICON_CURSOR, 48 | GUI_ICON_POINTER, 49 | GUI_ICON_BUTTON_CIRCLE, 50 | GUI_ICON_BUTTON_CROSS, 51 | GUI_ICON_BUTTON_TRIANGLE, 52 | GUI_ICON_BUTTON_SQUARE, 53 | GUI_ICON_BUTTON_HOME, 54 | GUI_ICON_MAX, 55 | }; 56 | 57 | struct GUIFontGlyphMetric { 58 | int width; 59 | int height; 60 | struct { 61 | int top; 62 | int right; 63 | int bottom; 64 | int left; 65 | } padding; 66 | }; 67 | 68 | struct GUIIconMetric { 69 | int x; 70 | int y; 71 | int width; 72 | int height; 73 | }; 74 | 75 | unsigned GUIFontHeight(const struct GUIFont*); 76 | unsigned GUIFontGlyphWidth(const struct GUIFont*, uint32_t glyph); 77 | unsigned GUIFontSpanWidth(const struct GUIFont*, const char* text); 78 | void GUIFontIconMetrics(const struct GUIFont*, enum GUIIcon icon, unsigned* w, unsigned* h); 79 | 80 | ATTRIBUTE_FORMAT(printf, 6, 7) 81 | void GUIFontPrintf(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text, ...); 82 | void GUIFontPrint(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text); 83 | void GUIFontDrawGlyph(const struct GUIFont*, int x, int y, uint32_t color, uint32_t glyph); 84 | void GUIFontDrawIcon(const struct GUIFont*, int x, int y, enum GUIAlignment, enum GUIOrientation, uint32_t color, enum GUIIcon); 85 | void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/lua/red/cheats.lua: -------------------------------------------------------------------------------- 1 | function Red:patch_cheats() 2 | if cheats.hide_pokemon_logo then 3 | local rom = emu:patcher(self.sym.DisplayTitleScreen) 4 | rom = rom + Gameboy.InstructionOffset(rom, 23) 5 | rom[0] = 0x00 -- nop 6 | rom[1] = 0x00 7 | rom[2] = 0x00 8 | end 9 | if cheats.skip_follow_oak then 10 | local rom = emu:patcher(self.sym.PalletTownScript0) 11 | rom[0] = 0xc9 -- ret 12 | end 13 | if cheats.walk_thru_walls then 14 | local rom = emu:patcher(self.sym.CollisionCheckOnLand) 15 | rom[0] = 0xa7 -- and a 16 | rom[1] = 0xc9 -- ret 17 | end 18 | if cheats.invisible2trainers then 19 | local rom = emu:patcher(self.sym.CheckSpriteCanSeePlayer) 20 | rom[0] = 0xc3 -- jp 21 | rom[1] = 0xe1 22 | rom[2] = 0x69 23 | end 24 | if cheats.skip_oak_speech then 25 | -- skip the speech 26 | local rom = emu:patcher(self.sym.OakSpeech) 27 | rom = rom + Gameboy.InstructionOffset(rom, 23) 28 | rom[0] = 0xc9 -- ret 29 | 30 | -- ninten/sony is cute, but no. 31 | local rom = emu:patcher(self.sym.NintenText) 32 | rom[0] = string.byte('R') + Red.CharOffset 33 | rom[1] = string.byte('E') + Red.CharOffset 34 | rom[2] = string.byte('D') + Red.CharOffset 35 | rom[3] = 80 36 | 37 | local rom = emu:patcher(self.sym.SonyText) 38 | rom[0] = string.byte('B') + Red.CharOffset 39 | rom[1] = string.byte('L') + Red.CharOffset 40 | rom[2] = string.byte('U') + Red.CharOffset 41 | rom[3] = string.byte('E') + Red.CharOffset 42 | rom[4] = 80 43 | end 44 | if cheats.instawarp then 45 | local rom = emu:patcher(self.sym.PlayMapChangeSound) 46 | rom[0] = 0xc9 -- ret 47 | end 48 | 49 | if cheats.fastwalk then 50 | local rom = emu:patcher(self.sym['OverworldLoopLessDelay.moveAhead']) 51 | rom = rom + Gameboy.InstructionOffset(rom, 11) -- maybe should be 7? 52 | rom[0] = 0x3e -- ld a, 53 | rom[1] = 0x01 -- $01 54 | rom[2] = 0x00 -- nop 55 | end 56 | if cheats.skip_intro then 57 | -- gamefreak/gengar battle 58 | local rom = emu:patcher(self.sym.Init) 59 | rom = rom + Gameboy.InstructionOffset(rom, 72) 60 | for i=0,4 do 61 | rom[i] = 0x00 -- nop 62 | end 63 | 64 | -- ash + charmander 65 | local rom = emu:patcher(self.sym.SetDefaultNamesBeforeTitlescreen) 66 | rom = rom + Gameboy.InstructionOffset(rom, 26) 67 | rom[0] = 0xc3 -- jp 68 | rom[1] = 0x68 69 | rom[2] = 0x44 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /deps/include/mgba/feature/ffmpeg/ffmpeg-encoder.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 FFMPEG_ENCODER 7 | #define FFMPEG_ENCODER 8 | 9 | #include "gba/gba.h" 10 | 11 | #include 12 | #include 13 | 14 | // Version 57.16 in FFmpeg 15 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100) 16 | #define FFMPEG_USE_PACKETS 17 | #endif 18 | 19 | // Version 57.15 in libav 20 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 35, 0) 21 | #define FFMPEG_USE_NEW_BSF 22 | #endif 23 | 24 | // Version 57.14 in libav 25 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 0) 26 | #define FFMPEG_USE_CODECPAR 27 | #endif 28 | 29 | #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 8, 0) 30 | #define FFMPEG_USE_PACKET_UNREF 31 | #endif 32 | 33 | struct FFmpegEncoder { 34 | struct mAVStream d; 35 | struct AVFormatContext* context; 36 | 37 | unsigned audioBitrate; 38 | const char* audioCodec; 39 | 40 | unsigned videoBitrate; 41 | const char* videoCodec; 42 | 43 | const char* containerFormat; 44 | 45 | struct AVCodecContext* audio; 46 | enum AVSampleFormat sampleFormat; 47 | int sampleRate; 48 | uint16_t* audioBuffer; 49 | size_t audioBufferSize; 50 | uint16_t* postaudioBuffer; 51 | size_t postaudioBufferSize; 52 | AVFrame* audioFrame; 53 | size_t currentAudioSample; 54 | int64_t currentAudioFrame; 55 | int64_t nextAudioPts; // TODO (0.6): Remove 56 | struct AVAudioResampleContext* resampleContext; 57 | #ifdef FFMPEG_USE_NEW_BSF 58 | struct AVBSFContext* absf; // Needed for AAC in MP4 59 | #else 60 | struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4 61 | #endif 62 | struct AVStream* audioStream; 63 | 64 | struct AVCodecContext* video; 65 | enum AVPixelFormat pixFormat; 66 | struct AVFrame* videoFrame; 67 | int width; 68 | int height; 69 | int iwidth; 70 | int iheight; 71 | int64_t currentVideoFrame; 72 | struct SwsContext* scaleContext; 73 | struct AVStream* videoStream; 74 | }; 75 | 76 | void FFmpegEncoderInit(struct FFmpegEncoder*); 77 | bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr); 78 | bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr); 79 | bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container); 80 | void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height); 81 | bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*); 82 | bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile); 83 | void FFmpegEncoderClose(struct FFmpegEncoder*); 84 | bool FFmpegEncoderIsOpen(struct FFmpegEncoder*); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /deps/include/lua/luajit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ 3 | ** 4 | ** Copyright (C) 2005-2015 Mike Pall. All rights reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining 7 | ** a copy of this software and associated documentation files (the 8 | ** "Software"), to deal in the Software without restriction, including 9 | ** without limitation the rights to use, copy, modify, merge, publish, 10 | ** distribute, sublicense, and/or sell copies of the Software, and to 11 | ** permit persons to whom the Software is furnished to do so, subject to 12 | ** the following conditions: 13 | ** 14 | ** The above copyright notice and this permission notice shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | ** 25 | ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 26 | */ 27 | 28 | #ifndef _LUAJIT_H 29 | #define _LUAJIT_H 30 | 31 | #include "lua.h" 32 | 33 | #define LUAJIT_VERSION "LuaJIT 2.0.4" 34 | #define LUAJIT_VERSION_NUM 20004 /* Version 2.0.4 = 02.00.04. */ 35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_0_4 36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2015 Mike Pall" 37 | #define LUAJIT_URL "http://luajit.org/" 38 | 39 | /* Modes for luaJIT_setmode. */ 40 | #define LUAJIT_MODE_MASK 0x00ff 41 | 42 | enum { 43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ 44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ 45 | 46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */ 47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ 48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ 49 | 50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ 51 | 52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ 53 | 54 | LUAJIT_MODE_MAX 55 | }; 56 | 57 | /* Flags or'ed in to the mode. */ 58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ 59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ 60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ 61 | 62 | /* LuaJIT public C API. */ 63 | 64 | /* Control the JIT engine. */ 65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); 66 | 67 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */ 68 | LUA_API void LUAJIT_VERSION_SYM(void); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/lua/screen.lua: -------------------------------------------------------------------------------- 1 | Screen = {} 2 | local mt = {__index = Screen} 3 | Screen.top = setmetatable({}, mt) 4 | Screen.bottom = setmetatable({}, mt) 5 | 6 | require('plat.'..PLATFORM..'.screen') 7 | 8 | function Screen:pixel(x, y, r, g, b, a) 9 | if not USE_LUA_FALLBACK then 10 | ffi.luared.draw_pixel(self.pix, self.width, self.height, x, y) 11 | return 12 | end 13 | 14 | if x < 0 or x >= self.width or 15 | y < 0 or y >= self.height 16 | then 17 | error('('..x..', '..y..') is out of range ('..self.width..', '..self.height..')') 18 | end 19 | 20 | x = math.floor(x + 1) 21 | y = math.floor(y + 1) 22 | 23 | -- the 3ds screen is in a weird format 24 | local i = self.height*x - y 25 | i = i*3 26 | if a then 27 | self.pix[i + 0] = self.pix[i + 0]*(1-a) + r*a 28 | self.pix[i + 1] = self.pix[i + 1]*(1-a) + b*a 29 | self.pix[i + 2] = self.pix[i + 2]*(1-a) + g*a 30 | else 31 | self.pix[i + 0] = r 32 | self.pix[i + 1] = b 33 | self.pix[i + 2] = g 34 | end 35 | end 36 | 37 | local function pixel(pix, width, height, x, y, r, g, b, a) 38 | x = math.floor(x + 0.5) 39 | y = math.floor(y + 0.5) 40 | 41 | if x < 0 or x >= width or 42 | y < 0 or y >= height 43 | then 44 | return 45 | end 46 | pix = pix + 3*(width*y + x) 47 | if not a then 48 | pix[0] = r 49 | pix[1] = g 50 | pix[2] = b 51 | else 52 | pix[0] = pix[0]*(1-a) + r*a 53 | pix[1] = pix[1]*(1-a) + g*a 54 | pix[2] = pix[2]*(1-a) + b*a 55 | end 56 | end 57 | 58 | function Screen:line(x1, y1, x2, y2, r, g, b, a, POOP) 59 | if not POOP and not USE_LUA_FALLBACK then 60 | ffi.luared.draw_line(self.pix, self.width, self.height, x1, y1, x2, y2) 61 | return 62 | end 63 | local distx = x2 - x1 64 | local disty = y2 - y1 65 | local steps = math.abs(distx) > math.abs(disty) and distx or disty 66 | steps = math.abs(steps) 67 | 68 | local dx = distx / steps 69 | local dy = disty / steps 70 | 71 | local x = x1 72 | local y = y1 73 | for i=1,steps do 74 | if POOP then 75 | pixel(self.pix, self.width, self.height, x, y, r, g, b, a) 76 | else 77 | self:pixel(x, y, r, g, b, a) 78 | end 79 | x = x + dx 80 | y = y + dy 81 | end 82 | if POOP then 83 | pixel(self.pix, self.width, self.height, x2, y2, r, g, b, a) 84 | else 85 | self:pixel(x2, y2, r, g, b, a) 86 | end 87 | end 88 | 89 | function Screen:circle(x, y, r, should_outline) 90 | ffi.luared.draw_circle(self.pix, self.width, self.height, x, y, r, should_outline and true or false) 91 | end 92 | 93 | function Screen:rect(x, y, width, height) 94 | ffi.luared.draw_rect(self.pix, self.width, self.height, x, y, width, height) 95 | end 96 | 97 | return Screen 98 | -------------------------------------------------------------------------------- /deps/include/mgba/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 "util/common.h" 10 | 11 | #include "core/log.h" 12 | 13 | mLOG_DECLARE_CATEGORY(GB_IO); 14 | 15 | enum GBIORegisters { 16 | REG_JOYP = 0x00, 17 | REG_SB = 0x01, 18 | REG_SC = 0x02, 19 | 20 | // Timing 21 | REG_DIV = 0x04, 22 | REG_TIMA = 0x05, 23 | REG_TMA = 0x06, 24 | REG_TAC = 0x07, 25 | 26 | // Interrupts 27 | REG_IF = 0x0F, 28 | REG_IE = 0xFF, 29 | 30 | // Audio 31 | REG_NR10 = 0x10, 32 | REG_NR11 = 0x11, 33 | REG_NR12 = 0x12, 34 | REG_NR13 = 0x13, 35 | REG_NR14 = 0x14, 36 | REG_NR21 = 0x16, 37 | REG_NR22 = 0x17, 38 | REG_NR23 = 0x18, 39 | REG_NR24 = 0x19, 40 | REG_NR30 = 0x1A, 41 | REG_NR31 = 0x1B, 42 | REG_NR32 = 0x1C, 43 | REG_NR33 = 0x1D, 44 | REG_NR34 = 0x1E, 45 | REG_NR41 = 0x20, 46 | REG_NR42 = 0x21, 47 | REG_NR43 = 0x22, 48 | REG_NR44 = 0x23, 49 | REG_NR50 = 0x24, 50 | REG_NR51 = 0x25, 51 | REG_NR52 = 0x26, 52 | 53 | REG_WAVE_0 = 0x30, 54 | REG_WAVE_1 = 0x31, 55 | REG_WAVE_2 = 0x32, 56 | REG_WAVE_3 = 0x33, 57 | REG_WAVE_4 = 0x34, 58 | REG_WAVE_5 = 0x35, 59 | REG_WAVE_6 = 0x36, 60 | REG_WAVE_7 = 0x37, 61 | REG_WAVE_8 = 0x38, 62 | REG_WAVE_9 = 0x39, 63 | REG_WAVE_A = 0x3A, 64 | REG_WAVE_B = 0x3B, 65 | REG_WAVE_C = 0x3C, 66 | REG_WAVE_D = 0x3D, 67 | REG_WAVE_E = 0x3E, 68 | REG_WAVE_F = 0x3F, 69 | 70 | // Video 71 | REG_LCDC = 0x40, 72 | REG_STAT = 0x41, 73 | REG_SCY = 0x42, 74 | REG_SCX = 0x43, 75 | REG_LY = 0x44, 76 | REG_LYC = 0x45, 77 | REG_DMA = 0x46, 78 | REG_BGP = 0x47, 79 | REG_OBP0 = 0x48, 80 | REG_OBP1 = 0x49, 81 | REG_WY = 0x4A, 82 | REG_WX = 0x4B, 83 | 84 | // CGB 85 | REG_KEY1 = 0x4D, 86 | REG_VBK = 0x4F, 87 | REG_HDMA1 = 0x51, 88 | REG_HDMA2 = 0x52, 89 | REG_HDMA3 = 0x53, 90 | REG_HDMA4 = 0x54, 91 | REG_HDMA5 = 0x55, 92 | REG_RP = 0x56, 93 | REG_BCPS = 0x68, 94 | REG_BCPD = 0x69, 95 | REG_OCPS = 0x6A, 96 | REG_OCPD = 0x6B, 97 | REG_UNK6C = 0x6C, 98 | REG_SVBK = 0x70, 99 | REG_UNK72 = 0x72, 100 | REG_UNK73 = 0x73, 101 | REG_UNK74 = 0x74, 102 | REG_UNK75 = 0x75, 103 | REG_UNK76 = 0x76, 104 | REG_UNK77 = 0x77, 105 | REG_MAX = 0x100 106 | }; 107 | 108 | extern const char* const GBIORegisterNames[]; 109 | 110 | struct GB; 111 | void GBIOInit(struct GB* gb); 112 | void GBIOReset(struct GB* gb); 113 | 114 | void GBIOWrite(struct GB* gb, unsigned address, uint8_t value); 115 | uint8_t GBIORead(struct GB* gb, unsigned address); 116 | 117 | struct GBSerializedState; 118 | void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state); 119 | void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state); 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /deps/include/mgba/core/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 M_INPUT_H 7 | #define M_INPUT_H 8 | 9 | #include "util/common.h" 10 | 11 | struct Configuration; 12 | 13 | struct mInputPlatformInfo { 14 | const char* platformName; 15 | const char** keyId; 16 | size_t nKeys; 17 | }; 18 | 19 | struct mInputMap { 20 | struct mInputMapImpl* maps; 21 | size_t numMaps; 22 | const struct mInputPlatformInfo* info; 23 | }; 24 | 25 | struct mInputAxis { 26 | int highDirection; 27 | int lowDirection; 28 | int32_t deadHigh; 29 | int32_t deadLow; 30 | }; 31 | 32 | void mInputMapInit(struct mInputMap*, const struct mInputPlatformInfo* info); 33 | void mInputMapDeinit(struct mInputMap*); 34 | 35 | int mInputMapKey(const struct mInputMap*, uint32_t type, int key); 36 | int mInputMapKeyBits(const struct mInputMap* map, uint32_t type, uint32_t bits, unsigned offset); 37 | void mInputBindKey(struct mInputMap*, uint32_t type, int key, int input); 38 | int mInputQueryBinding(const struct mInputMap*, uint32_t type, int input); 39 | void mInputUnbindKey(struct mInputMap*, uint32_t type, int input); 40 | 41 | int mInputMapAxis(const struct mInputMap*, uint32_t type, int axis, int value); 42 | int mInputClearAxis(const struct mInputMap*, uint32_t type, int axis, int keys); 43 | void mInputBindAxis(struct mInputMap*, uint32_t type, int axis, const struct mInputAxis* description); 44 | void mInputUnbindAxis(struct mInputMap*, uint32_t type, int axis); 45 | void mInputUnbindAllAxes(struct mInputMap*, uint32_t type); 46 | const struct mInputAxis* mInputQueryAxis(const struct mInputMap*, uint32_t type, int axis); 47 | void mInputEnumerateAxes(const struct mInputMap*, uint32_t type, void (handler(int axis, const struct mInputAxis* description, void* user)), void* user); 48 | 49 | void mInputMapLoad(struct mInputMap*, uint32_t type, const struct Configuration*); 50 | void mInputMapSave(const struct mInputMap*, uint32_t type, struct Configuration*); 51 | 52 | bool mInputProfileLoad(struct mInputMap*, uint32_t type, const struct Configuration*, const char* profile); 53 | void mInputProfileSave(const struct mInputMap*, uint32_t type, struct Configuration*, const char* profile); 54 | 55 | const char* mInputGetPreferredDevice(const struct Configuration*, const char* platformName, uint32_t type, int playerId); 56 | void mInputSetPreferredDevice(struct Configuration*, const char* platformName, uint32_t type, int playerId, const char* deviceName); 57 | 58 | const char* mInputGetCustomValue(const struct Configuration* config, const char* platformName, uint32_t type, const char* key, 59 | const char* profile); 60 | void mInputSetCustomValue(struct Configuration* config, const char* platformName, uint32_t type, const char* key, const char* value, 61 | const char* profile); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /deps/include/mgba/platform/3ds/uishader.g.pica: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2015 Yuri Kunde Schlesner 2 | ; Copyright (c) 2016 Jeffrey Pfau 3 | ; 4 | ; This Source Code Form is subject to the terms of the Mozilla Public 5 | ; License, v. 2.0. If a copy of the MPL was not distributed with this 6 | ; file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | ; Inputs 9 | .alias in_pos v0 ; [x, y, w, h] 10 | .alias in_tc0 v1 ; [u, v, uw, vh] 11 | .alias in_col v2 12 | .alias in_rot v3 13 | 14 | .gsh point c0 15 | 16 | ; Uniforms 17 | .fvec projectionMtx[4] 18 | .fvec textureMtx[2] 19 | 20 | ; Constants 21 | .constf consts1(0.0, 1.0, -0.5, -1.0) 22 | 23 | ; Outputs 24 | .out out_pos position 25 | .out out_tc0 texcoord0 26 | .out out_col color 27 | 28 | .entry gshMain 29 | .proc gshMain 30 | ; Set up the vertex endpoints 31 | mov r0.xy, in_pos.zw 32 | mov r0.zw, consts1.xx 33 | mov r4.xy, in_pos.xy 34 | add r5, r4.xyzw, r0.xwww 35 | add r6, r4.xyzw, r0.xyww 36 | add r7, r4.xyzw, r0.wyww 37 | 38 | ; Create rotation matrix 39 | mov r8, in_rot.xzww 40 | mov r9, in_rot.yxww 41 | mov r10.zw, consts1.zy 42 | 43 | ; Transform coordinates 44 | dp4 r10.x, r8, r4 45 | dp4 r10.y, r9, r4 46 | dp4 r0.x, projectionMtx[0], r10 47 | dp4 r0.y, projectionMtx[1], r10 48 | dp4 r0.z, projectionMtx[2], r10 49 | dp4 r0.w, projectionMtx[3], r10 50 | 51 | dp4 r10.x, r8, r5 52 | dp4 r10.y, r9, r5 53 | dp4 r1.x, projectionMtx[0], r10 54 | dp4 r1.y, projectionMtx[1], r10 55 | dp4 r1.z, projectionMtx[2], r10 56 | dp4 r1.w, projectionMtx[3], r10 57 | 58 | dp4 r10.x, r8, r6 59 | dp4 r10.y, r9, r6 60 | dp4 r2.x, projectionMtx[0], r10 61 | dp4 r2.y, projectionMtx[1], r10 62 | dp4 r2.z, projectionMtx[2], r10 63 | dp4 r2.w, projectionMtx[3], r10 64 | 65 | dp4 r10.x, r8, r7 66 | dp4 r10.y, r9, r7 67 | dp4 r3.x, projectionMtx[0], r10 68 | dp4 r3.y, projectionMtx[1], r10 69 | dp4 r3.z, projectionMtx[2], r10 70 | dp4 r3.w, projectionMtx[3], r10 71 | 72 | ; Set up the texture endpoints 73 | mov r6.xy, in_tc0.xy 74 | add r7.xy, r6.xy, in_tc0.zw 75 | 76 | dp4 r4.x, textureMtx[0], r6 77 | dp4 r4.y, textureMtx[1], r6 78 | mov r4.zw, consts1.xy 79 | 80 | dp4 r5.x, textureMtx[0], r7 81 | dp4 r5.y, textureMtx[1], r7 82 | mov r5.zw, consts1.xy 83 | 84 | ; Emit top-left 85 | setemit 0 86 | mov out_pos, r0 87 | mov out_tc0.xyzw, r4.xyzw 88 | mov out_col, in_col 89 | emit 90 | 91 | ; Emit bottom-left 92 | setemit 1 93 | mov out_pos, r1 94 | mov out_tc0.x, r5.x 95 | mov out_tc0.y, r4.y 96 | mov out_tc0.z, consts1.x 97 | mov out_tc0.w, consts1.y 98 | mov out_col, in_col 99 | emit 100 | 101 | ; Emit bottom-right 102 | setemit 2, prim 103 | mov out_pos, r2 104 | mov out_tc0.xyzw, r5.xyzw 105 | mov out_col, in_col 106 | emit 107 | 108 | ; Emit top-right 109 | setemit 1, prim inv 110 | mov out_pos, r3 111 | mov out_tc0.x, r4.x 112 | mov out_tc0.y, r5.y 113 | mov out_tc0.z, consts1.x 114 | mov out_tc0.w, consts1.y 115 | mov out_col, in_col 116 | emit 117 | 118 | end 119 | .end 120 | -------------------------------------------------------------------------------- /deps/include/mgba/core/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 CHEATS_H 7 | #define CHEATS_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "core/cpu.h" 12 | #include "core/log.h" 13 | #include "util/vector.h" 14 | 15 | #define MAX_ROM_PATCHES 4 16 | 17 | enum mCheatType { 18 | CHEAT_ASSIGN, 19 | CHEAT_ASSIGN_INDIRECT, 20 | CHEAT_AND, 21 | CHEAT_ADD, 22 | CHEAT_OR, 23 | CHEAT_IF_EQ, 24 | CHEAT_IF_NE, 25 | CHEAT_IF_LT, 26 | CHEAT_IF_GT, 27 | CHEAT_IF_ULT, 28 | CHEAT_IF_UGT, 29 | CHEAT_IF_AND, 30 | CHEAT_IF_LAND, 31 | CHEAT_IF_NAND 32 | }; 33 | 34 | struct mCheat { 35 | enum mCheatType type; 36 | int width; 37 | uint32_t address; 38 | uint32_t operand; 39 | uint32_t repeat; 40 | uint32_t negativeRepeat; 41 | 42 | int32_t addressOffset; 43 | int32_t operandOffset; 44 | }; 45 | 46 | mLOG_DECLARE_CATEGORY(CHEATS); 47 | 48 | DECLARE_VECTOR(mCheatList, struct mCheat); 49 | DECLARE_VECTOR(StringList, char*); 50 | 51 | struct mCheatDevice; 52 | struct mCheatSet { 53 | struct mCheatList list; 54 | 55 | void (*deinit)(struct mCheatSet* set); 56 | void (*add)(struct mCheatSet* set, struct mCheatDevice* device); 57 | void (*remove)(struct mCheatSet* set, struct mCheatDevice* device); 58 | 59 | bool (*addLine)(struct mCheatSet* set, const char* cheat, int type); 60 | void (*copyProperties)(struct mCheatSet* set, struct mCheatSet* oldSet); 61 | 62 | void (*parseDirectives)(struct mCheatSet* set, const struct StringList* directives); 63 | void (*dumpDirectives)(struct mCheatSet* set, struct StringList* directives); 64 | 65 | void (*refresh)(struct mCheatSet* set, struct mCheatDevice* device); 66 | 67 | char* name; 68 | bool enabled; 69 | struct StringList lines; 70 | }; 71 | 72 | DECLARE_VECTOR(mCheatSets, struct mCheatSet*); 73 | 74 | struct mCheatDevice { 75 | struct mCPUComponent d; 76 | struct mCore* p; 77 | 78 | struct mCheatSet* (*createSet)(struct mCheatDevice*, const char* name); 79 | 80 | struct mCheatSets cheats; 81 | }; 82 | 83 | struct VFile; 84 | 85 | void mCheatDeviceCreate(struct mCheatDevice*); 86 | void mCheatDeviceDestroy(struct mCheatDevice*); 87 | void mCheatDeviceClear(struct mCheatDevice*); 88 | 89 | void mCheatSetInit(struct mCheatSet*, const char* name); 90 | void mCheatSetDeinit(struct mCheatSet*); 91 | void mCheatSetRename(struct mCheatSet*, const char* name); 92 | 93 | bool mCheatAddLine(struct mCheatSet*, const char* line, int type); 94 | 95 | void mCheatAddSet(struct mCheatDevice*, struct mCheatSet*); 96 | void mCheatRemoveSet(struct mCheatDevice*, struct mCheatSet*); 97 | 98 | bool mCheatParseFile(struct mCheatDevice*, struct VFile*); 99 | bool mCheatSaveFile(struct mCheatDevice*, struct VFile*); 100 | 101 | void mCheatRefresh(struct mCheatDevice*, struct mCheatSet*); 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /deps/include/mgba/core/thread.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_THREAD_H 7 | #define M_CORE_THREAD_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "core/log.h" 12 | #include "core/rewind.h" 13 | #include "core/sync.h" 14 | #include "util/threading.h" 15 | 16 | struct mCoreThread; 17 | struct mCore; 18 | 19 | typedef void (*ThreadCallback)(struct mCoreThread* threadContext); 20 | 21 | enum mCoreThreadState { 22 | THREAD_INITIALIZED = -1, 23 | THREAD_RUNNING = 0, 24 | THREAD_REWINDING, 25 | THREAD_MAX_RUNNING = THREAD_REWINDING, 26 | THREAD_INTERRUPTED, 27 | THREAD_INTERRUPTING, 28 | THREAD_PAUSED, 29 | THREAD_PAUSING, 30 | THREAD_RUN_ON, 31 | THREAD_WAITING, 32 | THREAD_RESETING, 33 | THREAD_EXITING, 34 | THREAD_SHUTDOWN, 35 | THREAD_CRASHED 36 | }; 37 | 38 | struct mCoreThread; 39 | struct mThreadLogger { 40 | struct mLogger d; 41 | struct mCoreThread* p; 42 | }; 43 | 44 | struct mCoreThread { 45 | // Input 46 | struct mCore* core; 47 | 48 | // Threading state 49 | Thread thread; 50 | enum mCoreThreadState state; 51 | 52 | Mutex stateMutex; 53 | Condition stateCond; 54 | enum mCoreThreadState savedState; 55 | int interruptDepth; 56 | bool frameWasOn; 57 | 58 | struct mThreadLogger logger; 59 | enum mLogLevel logLevel; 60 | ThreadCallback startCallback; 61 | ThreadCallback resetCallback; 62 | ThreadCallback cleanCallback; 63 | ThreadCallback frameCallback; 64 | void* userData; 65 | void (*run)(struct mCoreThread*); 66 | 67 | struct mCoreSync sync; 68 | struct mCoreRewindContext rewind; 69 | }; 70 | 71 | bool mCoreThreadStart(struct mCoreThread* threadContext); 72 | bool mCoreThreadHasStarted(struct mCoreThread* threadContext); 73 | bool mCoreThreadHasExited(struct mCoreThread* threadContext); 74 | bool mCoreThreadHasCrashed(struct mCoreThread* threadContext); 75 | void mCoreThreadMarkCrashed(struct mCoreThread* threadContext); 76 | void mCoreThreadEnd(struct mCoreThread* threadContext); 77 | void mCoreThreadReset(struct mCoreThread* threadContext); 78 | void mCoreThreadJoin(struct mCoreThread* threadContext); 79 | 80 | bool mCoreThreadIsActive(struct mCoreThread* threadContext); 81 | void mCoreThreadInterrupt(struct mCoreThread* threadContext); 82 | void mCoreThreadInterruptFromThread(struct mCoreThread* threadContext); 83 | void mCoreThreadContinue(struct mCoreThread* threadContext); 84 | 85 | void mCoreThreadRunFunction(struct mCoreThread* threadContext, void (*run)(struct mCoreThread*)); 86 | 87 | void mCoreThreadPause(struct mCoreThread* threadContext); 88 | void mCoreThreadUnpause(struct mCoreThread* threadContext); 89 | bool mCoreThreadIsPaused(struct mCoreThread* threadContext); 90 | void mCoreThreadTogglePause(struct mCoreThread* threadContext); 91 | void mCoreThreadPauseFromThread(struct mCoreThread* threadContext); 92 | void mCoreThreadWaitFromThread(struct mCoreThread* threadContext); 93 | void mCoreThreadStopWaiting(struct mCoreThread* threadContext); 94 | 95 | void mCoreThreadSetRewinding(struct mCoreThread* threadContext, bool); 96 | 97 | struct mCoreThread* mCoreThreadGet(void); 98 | struct mLogger* mCoreThreadLogger(void); 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /deps/include/mgba/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 DEBUGGER_H 7 | #define DEBUGGER_H 8 | 9 | #include "util/common.h" 10 | 11 | #include "arm/arm.h" 12 | #include "core/log.h" 13 | #include "util/vector.h" 14 | 15 | mLOG_DECLARE_CATEGORY(DEBUGGER); 16 | 17 | extern const uint32_t DEBUGGER_ID; 18 | 19 | enum mDebuggerType { 20 | DEBUGGER_NONE = 0, 21 | #ifdef USE_CLI_DEBUGGER 22 | DEBUGGER_CLI, 23 | #endif 24 | #ifdef USE_GDB_STUB 25 | DEBUGGER_GDB, 26 | #endif 27 | DEBUGGER_MAX 28 | }; 29 | 30 | enum mDebuggerState { 31 | DEBUGGER_PAUSED, 32 | DEBUGGER_RUNNING, 33 | DEBUGGER_CUSTOM, 34 | DEBUGGER_SHUTDOWN 35 | }; 36 | 37 | enum mWatchpointType { 38 | WATCHPOINT_WRITE = 1, 39 | WATCHPOINT_READ = 2, 40 | WATCHPOINT_RW = WATCHPOINT_WRITE | WATCHPOINT_READ 41 | }; 42 | 43 | enum mBreakpointType { 44 | BREAKPOINT_HARDWARE, 45 | BREAKPOINT_SOFTWARE 46 | }; 47 | 48 | enum mDebuggerEntryReason { 49 | DEBUGGER_ENTER_MANUAL, 50 | DEBUGGER_ENTER_ATTACHED, 51 | DEBUGGER_ENTER_BREAKPOINT, 52 | DEBUGGER_ENTER_WATCHPOINT, 53 | DEBUGGER_ENTER_ILLEGAL_OP 54 | }; 55 | 56 | struct mDebugWatchpoint { 57 | uint32_t address; 58 | enum mWatchpointType type; 59 | }; 60 | 61 | extern const char* ERROR_MISSING_ARGS; 62 | extern const char* ERROR_OVERFLOW; 63 | 64 | struct mDebuggerEntryInfo { 65 | uint32_t address; 66 | union { 67 | struct { 68 | uint32_t oldValue; 69 | uint32_t newValue; 70 | enum mWatchpointType watchType; 71 | enum mWatchpointType accessType; 72 | }; 73 | 74 | struct { 75 | uint32_t opcode; 76 | enum mBreakpointType breakType; 77 | }; 78 | }; 79 | }; 80 | 81 | struct mDebugger; 82 | struct mDebuggerPlatform { 83 | struct mDebugger* p; 84 | 85 | void (*init)(void* cpu, struct mDebuggerPlatform*); 86 | void (*deinit)(struct mDebuggerPlatform*); 87 | void (*entered)(struct mDebuggerPlatform*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); 88 | 89 | bool (*hasBreakpoints)(struct mDebuggerPlatform*); 90 | void (*setBreakpoint)(struct mDebuggerPlatform*, uint32_t address); 91 | void (*clearBreakpoint)(struct mDebuggerPlatform*, uint32_t address); 92 | void (*setWatchpoint)(struct mDebuggerPlatform*, uint32_t address, enum mWatchpointType type); 93 | void (*clearWatchpoint)(struct mDebuggerPlatform*, uint32_t address); 94 | void (*checkBreakpoints)(struct mDebuggerPlatform*); 95 | }; 96 | 97 | struct mDebugger { 98 | struct mCPUComponent d; 99 | struct mDebuggerPlatform* platform; 100 | enum mDebuggerState state; 101 | struct mCore* core; 102 | 103 | void (*init)(struct mDebugger*); 104 | void (*deinit)(struct mDebugger*); 105 | 106 | void (*paused)(struct mDebugger*); 107 | void (*entered)(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); 108 | void (*custom)(struct mDebugger*); 109 | }; 110 | 111 | struct mDebugger* mDebuggerCreate(enum mDebuggerType type, struct mCore*); 112 | void mDebuggerAttach(struct mDebugger*, struct mCore*); 113 | void mDebuggerRun(struct mDebugger*); 114 | void mDebuggerEnter(struct mDebugger*, enum mDebuggerEntryReason, struct mDebuggerEntryInfo*); 115 | 116 | 117 | #endif 118 | --------------------------------------------------------------------------------