vgbc/input/joypad.h
2023-09-12 00:15:15 +02:00

41 lines
789 B
C++

#pragma once
#include <memory/device.h>
#include <cpu/cpu.h>
class Joypad : public Mem_device {
public:
enum Key {
A,B,Select,Start,
Right,Left,Up,Down,
};
private:
Cpu& cpu;
bool keystates[8];
bool action_select;
bool direction_select;
enum P1Reg {
P1ActionSelect = 0b00100000,
P1DirectionSelect = 0b00010000,
P1Down = 0b00001000,
P1Start = 0b00001000,
P1Up = 0b00000100,
P1Select = 0b00000100,
P1Left = 0b00000010,
P1B = 0b00000010,
P1Right = 0b00000001,
P1A = 0b00000001,
};
public:
Joypad(Cpu& cpu);
void setKeyState(Key k, bool pressed);
virtual void write8(u16 addr, u8 data);
virtual u8 read8(u16 addr);
};