Lift RawController code
This commit is contained in:
parent
fc646f1b1b
commit
dbbec16acf
|
@ -2,6 +2,7 @@
|
|||
#include <PSX/File/Processor/cd_file_processor.hpp>
|
||||
#include <PSX/GPU/gpu_auto_load_font.hpp>
|
||||
#include <PSX/GPU/make_gpu_primitives.hpp>
|
||||
#include <PSX/Periphery/periphery.hpp>
|
||||
#include <PSX/Timer/frame_timer.hpp>
|
||||
#include <FontWriter/fonts.hpp>
|
||||
|
||||
|
@ -31,7 +32,7 @@ void font_writer_update() {
|
|||
auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count);
|
||||
new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl\n", JabyEngine::GPU::Color24::Blue(), &wiggle);
|
||||
new_font_writer.write(state, "%i (0x%p)\nWiggle (%s)\n", JabyEngine::GPU::Color24::Green(), &wiggle, wiggle_count, 0xAABBCCDD, Text[wiggle_count&0x1]);
|
||||
bios_font_writer.write(state, "!!PLANSCHBECKEN!!", JabyEngine::GPU::Color24::White());
|
||||
bios_font_writer.write(state, "!!PLANSCHBECKEN!!", JabyEngine::Periphery::controller[0][0].button.is_down(JabyEngine::Periphery::GenericButton::D7) ? JabyEngine::GPU::Color24::Blue() : JabyEngine::GPU::Color24::White());
|
||||
|
||||
if(timer.is_expired_for(50_ms)) {
|
||||
timer.reset();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "assets.hpp"
|
||||
#include <PSX/GPU/gpu.hpp>
|
||||
#include <PSX/GPU/make_gpu_primitives.hpp>
|
||||
#include <PSX/Periphery/periphery.hpp>
|
||||
#include <PSX/Timer/frame_timer.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -22,6 +23,8 @@ static void setup() {
|
|||
}
|
||||
|
||||
static void update() {
|
||||
Periphery::query_controller();
|
||||
|
||||
FontWriter::FontWriter cursor;
|
||||
|
||||
const auto end_pos = cursor.write(FontWriter::Position::create(0, 32), "Cody is cute\n&\na \x1b[8;0;0mBAAAAABY!!!");
|
||||
|
@ -45,7 +48,7 @@ void main() {
|
|||
JabyEngine::HighResTime::enable();
|
||||
|
||||
while(true) {
|
||||
const auto start = Overlay::TimerTest::start_measuring();
|
||||
const auto start = Overlay::TimerTest::start_measuring();
|
||||
update();
|
||||
render();
|
||||
Overlay::TimerTest::end_measuring(start, GPU::Display::frames_per_sec);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
#include "raw_controller.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery {
|
||||
extern RawController controller[1][1];
|
||||
|
||||
void query_controller();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
#pragma once
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery {
|
||||
enum struct ControllerType : uint8_t {
|
||||
Unkown = 0x0,
|
||||
Mouse = 0x1,
|
||||
NegCon = 0x2,
|
||||
HyperBlaster = 0x3, // Konami Lightgun
|
||||
Controller = 0x4,
|
||||
ArcadeFlightStick = 0x5,
|
||||
GCon = 0x6,
|
||||
DualShock = 0x7,
|
||||
MultiTap = 0x8
|
||||
};
|
||||
|
||||
enum struct GenericButton : uint16_t {
|
||||
D8 = (1 << 0),
|
||||
D9 = (1 << 1),
|
||||
D10 = (1 << 2),
|
||||
D11 = (1 << 3),
|
||||
D12 = (1 << 4),
|
||||
D13 = (1 << 5),
|
||||
D14 = (1 << 6),
|
||||
D15 = (1 << 7),
|
||||
D0 = (1 << 8),
|
||||
D1 = (1 << 9),
|
||||
D2 = (1 << 10),
|
||||
D3 = (1 << 11),
|
||||
D4 = (1 << 12),
|
||||
D5 = (1 << 13),
|
||||
D6 = (1 << 14),
|
||||
D7 = (1 << 15)
|
||||
};
|
||||
|
||||
struct LED {
|
||||
enum struct State : uint8_t {
|
||||
Off = 0x0,
|
||||
On = 0x1
|
||||
};
|
||||
|
||||
enum struct Lock {
|
||||
Off = 0x2,
|
||||
On = 0x3
|
||||
};
|
||||
};
|
||||
|
||||
class RawController {
|
||||
public:
|
||||
enum struct State : uint8_t
|
||||
{
|
||||
Disconnected = 0,
|
||||
EnterConfigMode = (1 << 0),
|
||||
LockAnalog = (1 << 1),
|
||||
UnlockRumble = (1 << 2),
|
||||
ExitConfigMode = (1 << 3),
|
||||
Stable = (1 << 4)
|
||||
};
|
||||
|
||||
protected:
|
||||
struct Header {
|
||||
uint8_t type;
|
||||
State state;
|
||||
uint8_t rumble0;
|
||||
uint8_t rumble1;
|
||||
|
||||
void clear() {
|
||||
this->type = 0;
|
||||
this->state = State::Disconnected;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
class ButtonState {
|
||||
private:
|
||||
uint16_t oldState;
|
||||
uint16_t currentState;
|
||||
|
||||
static bool is_down(uint16_t data, uint16_t button) {
|
||||
return ((data & button) == 0);
|
||||
}
|
||||
|
||||
void exchange_state() {
|
||||
this->oldState = this->currentState;
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename T>
|
||||
bool is_down(T button) const {
|
||||
return ButtonState::is_down(this->currentState, static_cast<uint16_t>(button));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool was_down(T button) const {
|
||||
return ButtonState::is_down(this->oldState, static_cast<uint16_t>(button));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool went_down(T button) const {
|
||||
return (!ButtonState::was_down(button) && ButtonState::is_down(button));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool went_up(T button) const {
|
||||
return (ButtonState::was_down(button) && !ButtonState::is_down(button));
|
||||
}
|
||||
|
||||
friend class RawController;
|
||||
};
|
||||
|
||||
Header header;
|
||||
ButtonState button;
|
||||
uint32_t special;
|
||||
|
||||
public:
|
||||
ControllerType get_type() const {
|
||||
return static_cast<ControllerType>((this->header.type >> 4));
|
||||
}
|
||||
|
||||
ButtonState get_button_state() const {
|
||||
return this->button;
|
||||
}
|
||||
|
||||
//For debugging only
|
||||
uint8_t get_raw_type() const {
|
||||
return this->header.type;
|
||||
}
|
||||
|
||||
uint16_t get_raw_button_state() const {
|
||||
return this->button.currentState;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include <PSX/Periphery/periphery.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery {
|
||||
RawController controller[1][1];
|
||||
|
||||
void query_controller() {
|
||||
printf("Needs implementation\n");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue