Browse Source

Added core list and load support.

master
Ian Burgmyer 4 years ago
parent
commit
a44c48ce97
  1. 8
      libplip/Plip.cpp
  2. 4
      libplip/Plip.h
  3. 9
      libplip/PlipCore.cpp
  4. 19
      libplip/PlipCore.h
  5. 52
      plip-sdl/main.cpp

8
libplip/Plip.cpp

@ -13,10 +13,18 @@ namespace Plip {
m_video = video;
}
PlipCore* Plip::GetCore() {
return m_core;
}
PlipInput* Plip::GetInput() {
return m_input;
}
std::vector<PlipCoreDescription> Plip::GetSupportedCores() {
return PlipCore::GetSupportedCores();
}
std::string Plip::GetVersion() {
#ifndef GIT_FOUND
return PRODUCT_NAME;

4
libplip/Plip.h

@ -13,12 +13,14 @@
#include "Video/PlipVideo.h"
namespace Plip {
class Plip {
class Plip final {
public:
explicit Plip(PlipVideo *video);
static std::string GetVersion();
static std::vector<PlipCoreDescription> GetSupportedCores();
PlipCore* GetCore();
PlipInput* GetInput();
PlipVideo* GetVideo();
PlipError Load(PlipValidCore core, const std::string &path);

9
libplip/PlipCore.cpp

@ -9,4 +9,13 @@ namespace Plip {
PlipCore::PlipCore(PlipInput *input) {
m_input = input;
}
std::vector<PlipCoreDescription> PlipCore::GetSupportedCores() {
std::vector<PlipCoreDescription> coreList;
for(auto core : m_supportedCores)
coreList.push_back(core);
return coreList;
}
}

19
libplip/PlipCore.h

@ -6,6 +6,7 @@
#pragma once
#include <string>
#include <vector>
#include "PlipError.h"
#include "Input/PlipInput.h"
@ -16,9 +17,17 @@ namespace Plip {
Chip8
};
struct PlipCoreDescription {
const char *name;
PlipValidCore descriptor;
const char *description;
};
class PlipCore {
public:
virtual const PlipMemoryMap* GetMemoryMap() final { return m_memoryMap; }
static std::vector<PlipCoreDescription> GetSupportedCores();
virtual PlipMemoryMap* GetMemoryMap() final { return m_memoryMap; }
virtual PlipError Load(const std::string &path) = 0;
protected:
@ -26,5 +35,13 @@ namespace Plip {
PlipInput *m_input;
PlipMemoryMap *m_memoryMap = new PlipMemoryMap();
static constexpr PlipCoreDescription m_supportedCores[] = {
{
"chip8",
PlipValidCore::Chip8,
"CHIP-8"
}
};
};
}

52
plip-sdl/main.cpp

@ -111,6 +111,22 @@ int main(int argc, char **argv) {
return 0;
}
auto coreList = Plip::Plip::GetSupportedCores();
if(opts["list-cores"].count()) {
std::cout << "Supported cores:\n\n";
std::cout << " Name | Description\n";
std::cout << "--------------------------------\n";
for(auto core : coreList) {
std::string name = core.name;
name.append(10 - name.length(), ' '); // Pad string.
std::cout << " " << name << " | " << core.description << '\n';
}
std::cout << std::endl;
return 0;
}
if(!opts.count("core") || !opts.count("filename")) {
std::cerr << "The name of the core and the filename must be specified!\n\n"
<< "Please see the usage information (" << argv[0] << " -h) for more information." << std::endl;
@ -130,6 +146,25 @@ int main(int argc, char **argv) {
std::cerr << "Error opening config file: " << configFile << std::endl;
}
// Check for core name validity.
auto found = false;
auto coreName = opts["core"].as<std::string>();
auto filename = opts["filename"].as<std::string>();
Plip::PlipValidCore coreTag;
for(auto core : coreList) {
if(core.name != coreName) continue;
found = true;
coreTag = core.descriptor;
break;
}
if(!found) {
std::cout << "Invalid core specified (" << coreName << ").\n\n";
std::cout << "Please check the core list (" << argv[0] << " -l) for valid entries." << std::endl;
return 1;
}
for(auto param : intParamMapping) {
if(opts[param[0]].count()) {
config->SetValue(
@ -150,6 +185,23 @@ int main(int argc, char **argv) {
auto timer = new PlipSdl::TimerSdl();
#endif
auto result = plip->Load(coreTag, filename);
switch(result) {
case Plip::PlipError::FileNotFound:
std::cout << "File not found (" << filename << ")!\n" << std::endl;
return 1;
case Plip::PlipError::InvalidCore:
std::cout << "BUG: Core implemented improperly!\n" << std::endl;
return 1;
default:
break;
}
auto dCore = plip->GetCore();
auto dMap = dCore->GetMemoryMap();
auto b = dMap->GetByte(0x200);
std::cout << b << std::endl;
gameLoop(plip, config, timer);
SDL_Quit();

Loading…
Cancel
Save