Skip to content

Commit

Permalink
NESController.cpp stub
Browse files Browse the repository at this point in the history
  • Loading branch information
ogamespec committed Aug 24, 2023
1 parent c62c18f commit d0ed2c5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
10 changes: 8 additions & 2 deletions IO/AbstractIODevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace IO
{
#define IO_MaxStates 0x100 // Maximum number of IO device actuators

struct IOState
{
std::string actuator_name;
Expand All @@ -14,19 +16,23 @@ namespace IO
class IODevice
{
protected:
std::map<size_t, IOState> states;
IOState states[IO_MaxStates]{};

public:
IODevice() {}
virtual ~IODevice() {}

virtual uint32_t GetID() { return DeviceID::Abstract; }
virtual std::string GetName() { return "Abstract"; }
virtual void GetIOStates(std::list<size_t>& io_states) {}
virtual int GetIOStates() { return 0; }
virtual std::string GetIOStateName(size_t io_state) { return ""; }

virtual void SetState(size_t io_state, uint32_t value) {}
virtual uint32_t GetState(size_t io_state) { return 0; }

/// <summary>
/// The number and types of IO port signals are determined by the Motherboard implementation. The IODevice implementation must take this into account
/// </summary>
virtual void sim(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[]) {}
};
}
70 changes: 70 additions & 0 deletions IO/NESController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
// NES Controller simulator
#include "pch.h"

namespace IO
{
NESController::NESController()
{
states[(size_t)NESControllerState::Up].actuator_name = "Up";
states[(size_t)NESControllerState::Up].value = 0;
states[(size_t)NESControllerState::Down].actuator_name = "Down";
states[(size_t)NESControllerState::Down].value = 0;
states[(size_t)NESControllerState::Left].actuator_name = "Left";
states[(size_t)NESControllerState::Left].value = 0;
states[(size_t)NESControllerState::Right].actuator_name = "Right";
states[(size_t)NESControllerState::Right].value = 0;
states[(size_t)NESControllerState::Select].actuator_name = "Select";
states[(size_t)NESControllerState::Select].value = 0;
states[(size_t)NESControllerState::Start].actuator_name = "Start";
states[(size_t)NESControllerState::Start].value = 0;
states[(size_t)NESControllerState::B].actuator_name = "B";
states[(size_t)NESControllerState::B].value = 0;
states[(size_t)NESControllerState::A].actuator_name = "A";
states[(size_t)NESControllerState::A].value = 0;
}

NESController::~NESController()
{
}

uint32_t NESController::GetID()
{
return DeviceID::NESController;
}

std::string NESController::GetName()
{
return "NES Controller";
}

int NESController::GetIOStates()
{
return (int)NESControllerState::Max;
}

std::string NESController::GetIOStateName(size_t io_state)
{
if (io_state < (size_t)NESControllerState::Max) {
return states[io_state].actuator_name;
}
else {
return "";
}
}

void NESController::SetState(size_t io_state, uint32_t value)
{
if (io_state < (size_t)NESControllerState::Max) {
states[io_state].value = value;
}
}

uint32_t NESController::GetState(size_t io_state)
{
if (io_state < (size_t)NESControllerState::Max) {
return states[io_state].value;
}
else {
return 0;
}
}

void NESController::sim(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[])
{
}
}
30 changes: 30 additions & 0 deletions IO/NESController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
// NES Controller simulator
#pragma once

namespace IO
{
enum class NESControllerState
{
Up = 0,
Down,
Left,
Right,
Select,
Start,
B,
A,
Max,
};

class NESController : public IODevice
{
public:
NESController();
virtual ~NESController();

virtual uint32_t GetID() override;
virtual std::string GetName() override;
virtual int GetIOStates() override;
virtual std::string GetIOStateName(size_t io_state) override;

virtual void SetState(size_t io_state, uint32_t value) override;
virtual uint32_t GetState(size_t io_state) override;

virtual void sim(BaseLogic::TriState inputs[], BaseLogic::TriState outputs[]) override;
};
}

0 comments on commit d0ed2c5

Please sign in to comment.