diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index 4adc7e91..78a6d2ad 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -28,6 +28,7 @@ install( context.hpp core.hpp gfx.hpp + input.hpp media.hpp mem.hpp DESTINATION diff --git a/src/nostalgia/core/gba/addresses.hpp b/src/nostalgia/core/gba/addresses.hpp index e2f5caf3..ad4b9b47 100644 --- a/src/nostalgia/core/gba/addresses.hpp +++ b/src/nostalgia/core/gba/addresses.hpp @@ -62,6 +62,11 @@ using interrupt_handler = void (*)(void); #define REG_BG2VOFS *reinterpret_cast(0x0400001a) #define REG_BG3VOFS *reinterpret_cast(0x0400001e) +///////////////////////////////////////////////////////////////// +// User Input + +#define REG_GAMEPAD *reinterpret_cast(0x04000130) + ///////////////////////////////////////////////////////////////// // Memory Addresses diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index e3eca6b2..c96e5efd 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "addresses.hpp" #include "bios.hpp" @@ -54,4 +55,8 @@ uint64_t ticksMs() { return g_timerMs; } +bool buttonDown(Key k) { + return !(REG_GAMEPAD & k); +} + } diff --git a/src/nostalgia/core/input.hpp b/src/nostalgia/core/input.hpp new file mode 100644 index 00000000..b0c8cf72 --- /dev/null +++ b/src/nostalgia/core/input.hpp @@ -0,0 +1,29 @@ +/* + * Copyright 2016 - 2020 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace nostalgia::core { + +enum Key { + // GBA implementation currently relies on GamePad entry order + GamePad_A = 1, + GamePad_B = 2, + GamePad_Select = 4, + GamePad_Start = 8, + GamePad_Right = 16, + GamePad_Left = 32, + GamePad_Up = 64, + GamePad_Down = 128, + GamePad_R = 256, + GamePad_L = 512, +}; + +[[nodiscard]] bool buttonDown(Key); + +} diff --git a/src/nostalgia/core/sdl/core.cpp b/src/nostalgia/core/sdl/core.cpp index 33698453..88484e09 100644 --- a/src/nostalgia/core/sdl/core.cpp +++ b/src/nostalgia/core/sdl/core.cpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace nostalgia::core { @@ -52,4 +53,8 @@ uint64_t ticksMs() { return SDL_GetTicks();; } +bool buttonDown(Key) { + return false; +} + }