Some small changes for NES support: hopefully not broken anything!

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2017-12-26 22:46:16 +00:00
parent df1f47fb36
commit d4782a66db
5 changed files with 34 additions and 24 deletions

View File

@ -8,7 +8,7 @@ namespace EightBit {
class Ricoh2A03 final : public MOS6502 {
public:
Ricoh2A03(Bus& bus);
~Ricoh2A03();
virtual ~Ricoh2A03() = default;
protected:
virtual void SBC(uint8_t data) final;

View File

@ -1 +1,4 @@
#pragma once
#include <mos6502.h>
#include <Bus.h>

View File

@ -5,9 +5,6 @@ EightBit::Ricoh2A03::Ricoh2A03(Bus& bus)
: MOS6502(bus) {
}
EightBit::Ricoh2A03::~Ricoh2A03() {
}
void EightBit::Ricoh2A03::SBC(uint8_t data) {
MOS6502::SBC_b(data);
}

View File

@ -3,19 +3,35 @@
#include <cstdint>
#include <vector>
#include <string>
#include <fstream>
namespace EightBit {
class Memory {
public:
static int load(std::ifstream& file, std::vector<uint8_t>& output, int writeOffset, int readOffset, int limit, int maximumSize);
static int load(const std::string& path, std::vector<uint8_t>& output, int writeOffset, int readOffset, int limit, int maximumSize);
Memory(size_t size = 0)
: m_bytes(size) {
}
size_t size() const { return m_bytes.size(); }
int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) {
const auto maximumSize = (int)m_bytes.size() - writeOffset;
return load(file, m_bytes, writeOffset, readOffset, limit, maximumSize);
}
int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) {
const auto maximumSize = (int)m_bytes.size() - writeOffset;
return loadBinary(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
return load(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
}
int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) {
if (limit < 0)
limit = (int)bytes.size() - readOffset;
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset);
return limit;
}
protected:
@ -31,13 +47,5 @@ namespace EightBit {
private:
std::vector<uint8_t> m_bytes;
static int loadBinary(
const std::string& path,
std::vector<uint8_t>& output,
int writeOffset,
int readOffset,
int limit,
int maximumSize);
};
}

View File

@ -2,20 +2,11 @@
#include "Memory.h"
#include <iostream>
#include <fstream>
int EightBit::Memory::loadBinary(
const std::string& path,
std::vector<uint8_t>& output,
int writeOffset,
int readOffset,
int limit,
int maximumSize) {
int EightBit::Memory::load(std::ifstream& file, std::vector<uint8_t>& output, const int writeOffset, const int readOffset, int limit, const int maximumSize) {
std::ifstream file;
file.exceptions(std::ios::failbit | std::ios::badbit);
file.seekg(0, std::ios::end);
file.open(path, std::ios::binary | std::ios::ate);
const auto size = (int)file.tellg();
if ((maximumSize > 0) && ((size - readOffset) > maximumSize))
throw std::runtime_error("Binary cannot fit");
@ -30,6 +21,17 @@ int EightBit::Memory::loadBinary(
output.resize(extent);
file.read((char*)&output[writeOffset], limit);
return size;
}
int EightBit::Memory::load(const std::string& path, std::vector<uint8_t>& output, const int writeOffset, const int readOffset, const int limit, const int maximumSize) {
std::ifstream file;
file.exceptions(std::ios::failbit | std::ios::badbit);
file.open(path, std::ios::binary | std::ios::ate);
const auto size = load(file, output, writeOffset, readOffset, limit, maximumSize);
file.close();
return size;