Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
namespace VCC::Mac {
|
||||
struct StereoSample { float left=0, right=0; };
|
||||
inline StereoSample ConvertDAC(std::uint32_t packed) {
|
||||
// PIA packs left in the high word; DirectSound used signed 16-bit PCM.
|
||||
return {static_cast<std::int16_t>(packed>>16)/32768.0f,
|
||||
static_cast<std::int16_t>(packed&65535)/32768.0f};
|
||||
}
|
||||
// One emulation producer, one real-time consumer. No allocation or locks in read.
|
||||
// clear() is only legal after the audio engine has stopped its callback.
|
||||
class AudioBuffer {
|
||||
public:
|
||||
static constexpr std::uint64_t capacity=8192;
|
||||
std::atomic<std::uint64_t> underruns{0}, overruns{0}, consumed{0}, submitted{0}, signalSamples{0}, maximumRequest{0};
|
||||
std::atomic<float> gain{0.5f};
|
||||
std::size_t size() const { const auto r=reader.load(std::memory_order_acquire); return writer.load(std::memory_order_acquire)-r; }
|
||||
void clear() { reader.store(0); writer.store(0); }
|
||||
void write(const StereoSample* source,std::size_t count) {
|
||||
const auto w=writer.load(std::memory_order_relaxed), r=reader.load(std::memory_order_acquire);
|
||||
const auto n=std::min<std::size_t>(count,capacity-(w-r));
|
||||
std::uint64_t signal = 0;
|
||||
for(std::size_t i=0;i<n;++i) {
|
||||
data[(w+i)%capacity]=source[i];
|
||||
if (source[i].left != 0 || source[i].right != 0) ++signal;
|
||||
}
|
||||
submitted.fetch_add(count, std::memory_order_relaxed);
|
||||
signalSamples.fetch_add(signal, std::memory_order_relaxed);
|
||||
writer.store(w+n,std::memory_order_release); if(n<count) overruns.fetch_add(count-n,std::memory_order_relaxed);
|
||||
}
|
||||
void read(float* left,float* right,std::size_t count) {
|
||||
// Only the render consumer writes this high-water mark.
|
||||
if (count > maximumRequest.load(std::memory_order_relaxed)) maximumRequest.store(count, std::memory_order_relaxed);
|
||||
const auto r=reader.load(std::memory_order_relaxed), w=writer.load(std::memory_order_acquire);
|
||||
const auto n=std::min<std::size_t>(count,w-r); const float scale=gain.load(std::memory_order_relaxed);
|
||||
for(std::size_t i=0;i<n;++i) { auto s=data[(r+i)%capacity]; left[i]=s.left*scale; right[i]=s.right*scale; }
|
||||
for(std::size_t i=n;i<count;++i) left[i]=right[i]=0;
|
||||
reader.store(r+n,std::memory_order_release); consumed.fetch_add(n,std::memory_order_relaxed); if(n<count) underruns.fetch_add(count-n,std::memory_order_relaxed);
|
||||
}
|
||||
private:
|
||||
std::array<StereoSample,capacity> data{};
|
||||
std::atomic<std::uint64_t> reader{0},writer{0};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "BasicProgram.h"
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace VCC::Mac {
|
||||
namespace {
|
||||
char upper(char c) { return c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c; }
|
||||
bool alpha(char c) { c = upper(c); return c >= 'A' && c <= 'Z'; }
|
||||
bool digit(char c) { return c >= '0' && c <= '9'; }
|
||||
void fail(unsigned line, const std::string& why) {
|
||||
throw std::invalid_argument("BASIC source line " + std::to_string(line) + ": " + why);
|
||||
}
|
||||
struct TokenizedLine {
|
||||
std::vector<std::uint8_t> bytes;
|
||||
std::vector<std::pair<std::size_t, std::size_t>> spans;
|
||||
};
|
||||
TokenizedLine tokenize(const std::string& body, const std::vector<BasicToken>& dictionary) {
|
||||
TokenizedLine result;
|
||||
auto emit = [&](std::uint8_t byte, std::size_t at, std::size_t length = 1) {
|
||||
result.bytes.push_back(byte); result.spans.emplace_back(at, length);
|
||||
};
|
||||
bool data = false, identifier = false;
|
||||
for (std::size_t at = 0; at < body.size();) {
|
||||
char c = body[at];
|
||||
if (c == '"') {
|
||||
emit(c, at++);
|
||||
while (at < body.size()) { c = body[at]; emit(c, at++); if (c == '"') break; }
|
||||
continue;
|
||||
}
|
||||
if (c == ':') { emit(c, at++); data = identifier = false; continue; }
|
||||
if (data) { emit(c, at++); continue; }
|
||||
c = upper(c);
|
||||
if (identifier && (alpha(c) || digit(c))) { emit(c, at++); continue; }
|
||||
identifier = false;
|
||||
if (c == ' ' || (c >= '0' && c <= ';')) { emit(c, at++); continue; }
|
||||
if (c == '?') { emit(0x87, at++); continue; }
|
||||
if (c == '\'') {
|
||||
emit(':', at); emit(0x83, at++);
|
||||
while (at < body.size()) { emit(body[at], at); ++at; } break;
|
||||
}
|
||||
const BasicToken* found = nullptr;
|
||||
// Keep the ROM's table search order, including its identifier rules.
|
||||
for (const auto& token : dictionary) {
|
||||
if (at + token.text.size() <= body.size() &&
|
||||
std::equal(token.text.begin(), token.text.end(), body.begin() + at,
|
||||
[](char a, char b) { return a == upper(b); })) { found = &token; break; }
|
||||
}
|
||||
if (!found) { emit(c, at++); identifier = alpha(c); continue; }
|
||||
if (found->function) emit(0xff, at, found->text.size());
|
||||
else if (found->code == 0x84) emit(':', at, found->text.size());
|
||||
emit(found->code, at, found->text.size()); at += found->text.size();
|
||||
if (!found->function && found->code == 0x86) data = true;
|
||||
if (!found->function && (found->code == 0x82 || found->code == 0x83)) {
|
||||
while (at < body.size()) { emit(body[at], at); ++at; } break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
std::vector<BasicVariable> BasicProgram::inspect(const std::vector<std::uint8_t>& memory) {
|
||||
auto invalid = [] { throw std::runtime_error("BASIC variable tables are invalid or unsupported; no values were read"); };
|
||||
if (memory.size() != 0x8000) invalid();
|
||||
auto word = [&](unsigned at) { return (unsigned(memory.at(at)) << 8) | memory.at(at + 1); };
|
||||
unsigned start = word(0x19), scalar = word(0x1b), arrays = word(0x1d), end = word(0x1f), free = word(0x21);
|
||||
if (start < 0x600 || scalar < start + 2 || arrays < scalar || end < arrays || free < end ||
|
||||
free > memory.size() || (arrays - scalar) % 7) invalid();
|
||||
auto descriptor = [&](unsigned at) {
|
||||
BasicVariable v; v.address = at + 2;
|
||||
auto first = memory.at(at), second = memory.at(at + 1);
|
||||
auto a = first & 127, b = second & 127;
|
||||
if (a < 'A' || a > 'Z' || (b && !(b >= 'A' && b <= 'Z') && !(b >= '0' && b <= '9'))) invalid();
|
||||
v.name += char(a); if (b) v.name += char(b);
|
||||
v.kind = (first & 128) ? "Function" : (second & 128) ? "String" : "Number";
|
||||
if (v.kind == "String") v.name += '$';
|
||||
if (v.kind == "Function") v.name = "FN" + v.name;
|
||||
return v;
|
||||
};
|
||||
auto value = [&](unsigned at, const std::string& kind) -> std::string {
|
||||
if (at + 5 > memory.size()) { invalid(); return {}; }
|
||||
if (kind == "Function") return "User-defined function (not evaluated)";
|
||||
std::ostringstream out; out.imbue(std::locale::classic());
|
||||
if (kind == "String") {
|
||||
unsigned count = memory[at], ptr = word(at + 2);
|
||||
// Literal, heap and file-buffer strings all live in normal BASIC RAM.
|
||||
if (count && (ptr >= memory.size() || count > memory.size() - ptr))
|
||||
return "Unavailable (string points outside BASIC RAM)";
|
||||
out << '\"';
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
unsigned c = memory[ptr + i];
|
||||
if (c == '\"' || c == '\\') out << '\\' << char(c);
|
||||
else if (c >= 32 && c <= 126) out << char(c);
|
||||
else out << "\\x" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << c;
|
||||
}
|
||||
out << '\"';
|
||||
} else {
|
||||
if (!memory[at]) return "0";
|
||||
uint32_t fraction = (uint32_t(memory[at + 1] & 127) << 24) |
|
||||
(uint32_t(memory[at + 2]) << 16) | (uint32_t(memory[at + 3]) << 8) | memory[at + 4];
|
||||
double number = std::ldexp(1.0 + double(fraction) / 2147483648.0, int(memory[at]) - 129);
|
||||
if (memory[at + 1] & 128) number = -number;
|
||||
out << std::setprecision(10) << number;
|
||||
}
|
||||
return out.str();
|
||||
};
|
||||
std::vector<BasicVariable> result; std::set<std::string> names;
|
||||
for (unsigned at = scalar; at < arrays; at += 7) {
|
||||
auto v = descriptor(at);
|
||||
if (!names.insert(v.name).second) invalid();
|
||||
v.value = value(at + 2, v.kind); result.push_back(std::move(v));
|
||||
}
|
||||
names.clear();
|
||||
for (unsigned at = arrays; at < end;) {
|
||||
if (end - at < 7) invalid();
|
||||
auto v = descriptor(at);
|
||||
unsigned size = word(at + 2), rank = memory[at + 4], header = 5 + 2 * rank;
|
||||
if (!rank || size < header || size > end - at || v.kind == "Function" || !names.insert(v.name).second) invalid();
|
||||
unsigned count = 1;
|
||||
for (unsigned i = 0; i < rank; ++i) {
|
||||
unsigned length = word(at + 5 + i * 2);
|
||||
if (!length || count > (size - header) / 5 / length) invalid();
|
||||
count *= length; v.dimensions.push_back(length);
|
||||
}
|
||||
if (header + count * 5 != size) invalid();
|
||||
std::reverse(v.dimensions.begin(), v.dimensions.end());
|
||||
v.address = at + header;
|
||||
v.value = std::to_string(count) + " elements";
|
||||
for (unsigned i = 0; i < count; ++i) v.elements.push_back(value(v.address + i * 5, v.kind));
|
||||
result.push_back(std::move(v)); at += size;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::vector<std::uint8_t> BasicProgram::encode(const std::string& source, std::uint16_t start,
|
||||
std::uint16_t limit, const std::vector<BasicToken>& dictionary,
|
||||
std::vector<BasicSourceLocation>* locations) {
|
||||
if (source.size() > 1024 * 1024) throw std::invalid_argument("BASIC source exceeds the 1 MiB editor limit");
|
||||
std::map<unsigned, TokenizedLine> lines;
|
||||
if (locations) locations->clear();
|
||||
std::size_t pos = 0; unsigned sourceLine = 0;
|
||||
while (pos < source.size()) {
|
||||
++sourceLine;
|
||||
const auto rowStart = pos;
|
||||
const auto end = source.find_first_of("\r\n", pos);
|
||||
std::string text = source.substr(pos, end == std::string::npos ? end : end - pos);
|
||||
pos = end == std::string::npos ? source.size() : end + 1;
|
||||
if (end != std::string::npos && source[end] == '\r' && pos < source.size() && source[pos] == '\n') ++pos;
|
||||
for (char& c : text) {
|
||||
if (c == '\t') c = ' ';
|
||||
if (static_cast<unsigned char>(c) < 32 || static_cast<unsigned char>(c) > 126)
|
||||
fail(sourceLine, "use printable ASCII characters");
|
||||
}
|
||||
auto at = text.find_first_not_of(' '); if (at == std::string::npos) continue;
|
||||
if (text.size() - at > 249) fail(sourceLine, "line exceeds BASIC's 249-character input limit");
|
||||
if (!digit(text[at])) fail(sourceLine, "a line number is required");
|
||||
unsigned number = 0;
|
||||
while (at < text.size() && digit(text[at])) {
|
||||
number = number * 10 + (text[at++] - '0');
|
||||
if (number > 63999) fail(sourceLine, "line number must be between 0 and 63999");
|
||||
}
|
||||
while (at < text.size() && text[at] == ' ') ++at;
|
||||
if (lines.count(number)) fail(sourceLine, "duplicate line number " + std::to_string(number));
|
||||
// A bare line number deletes that line in the interpreter; replacing a
|
||||
// whole program simply omits it. Duplicate numbers still fail clearly.
|
||||
auto body = tokenize(text.substr(at), dictionary);
|
||||
for (auto& span : body.spans) span.first += rowStart + at;
|
||||
lines.emplace(number, std::move(body));
|
||||
}
|
||||
std::vector<std::uint8_t> out;
|
||||
for (const auto& [number, tokenized] : lines) {
|
||||
const auto& body = tokenized.bytes;
|
||||
if (body.empty()) continue;
|
||||
auto next = static_cast<std::size_t>(start) + out.size() + 5 + body.size();
|
||||
if (next + 2 > limit || next > 65535) throw std::invalid_argument("The BASIC program does not fit the current BASIC memory area");
|
||||
out.push_back(next >> 8); out.push_back(next & 255);
|
||||
out.push_back(number >> 8); out.push_back(number & 255);
|
||||
if (locations) for (std::size_t i = 0; i < body.size(); ++i)
|
||||
locations->push_back({static_cast<unsigned>(start + out.size() + i), number, static_cast<unsigned>(tokenized.spans[i].first), static_cast<unsigned>(tokenized.spans[i].second)});
|
||||
out.insert(out.end(), body.begin(), body.end()); out.push_back(0);
|
||||
}
|
||||
if (static_cast<std::size_t>(start) + out.size() + 2 > limit)
|
||||
throw std::invalid_argument("The BASIC program does not fit the current BASIC memory area");
|
||||
out.push_back(0); out.push_back(0); return out;
|
||||
}
|
||||
std::vector<std::uint8_t> BasicProgram::exportImage(const std::vector<std::uint8_t>& program,
|
||||
const std::string& filename, BasicExportFormat format) {
|
||||
std::string name;
|
||||
for (char c : filename) {
|
||||
c = upper(c);
|
||||
if (!alpha(c) && !digit(c)) throw std::invalid_argument("Use 1 to 8 letters or numbers for the BASIC filename");
|
||||
name.push_back(c);
|
||||
}
|
||||
if (name.empty() || name.size() > 8) throw std::invalid_argument("Use 1 to 8 letters or numbers for the BASIC filename");
|
||||
name.resize(8, ' ');
|
||||
if (program.size() < 2 || program.size() > 0x58ff || program[program.size()-1] || program[program.size()-2])
|
||||
throw std::invalid_argument("Invalid or oversized tokenized BASIC program");
|
||||
if (format == BasicExportFormat::Disk) {
|
||||
// Standard 35-track, single-sided DECB image: directory track 17,
|
||||
// sector 2 FAT, sector 3 directory. Binary BASIC SAVE adds FF + length.
|
||||
std::vector<std::uint8_t> file{0xff, static_cast<std::uint8_t>(program.size() >> 8), static_cast<std::uint8_t>(program.size())};
|
||||
file.insert(file.end(), program.begin(), program.end());
|
||||
std::vector<std::uint8_t> disk(35 * 18 * 256, 0xff);
|
||||
constexpr unsigned fat = (17 * 18 + 1) * 256, entry = (17 * 18 + 2) * 256;
|
||||
const auto granules = (file.size() + 2303) / 2304;
|
||||
for (std::size_t g = 0; g < granules; ++g) {
|
||||
const auto amount = std::min<std::size_t>(2304, file.size() - g * 2304);
|
||||
disk[fat + g] = static_cast<std::uint8_t>(g + 1 < granules ? g + 1 : 0xc0 + (amount + 255) / 256);
|
||||
const auto track = g / 2 + (g >= 34 ? 1 : 0);
|
||||
const auto offset = (track * 18 + (g % 2) * 9) * 256;
|
||||
std::copy_n(file.begin() + g * 2304, amount, disk.begin() + offset);
|
||||
}
|
||||
std::fill_n(disk.begin() + entry, 32, 0);
|
||||
std::copy(name.begin(), name.end(), disk.begin() + entry);
|
||||
std::copy_n("BAS", 3, disk.begin() + entry + 8);
|
||||
// Type 0 (BASIC), binary 0, first granule 0; final sector byte count
|
||||
// is 256 for an exactly full sector, not zero.
|
||||
const auto last = (file.size() - 1) % 256 + 1;
|
||||
disk[entry + 14] = static_cast<std::uint8_t>(last >> 8);
|
||||
disk[entry + 15] = static_cast<std::uint8_t>(last);
|
||||
return disk;
|
||||
}
|
||||
if (format != BasicExportFormat::Cassette) throw std::invalid_argument("Unknown BASIC media format");
|
||||
std::vector<std::uint8_t> tape;
|
||||
auto block = [&](std::uint8_t type, const std::vector<std::uint8_t>& data) {
|
||||
tape.insert(tape.end(), {0x55, 0x3c, type, static_cast<std::uint8_t>(data.size())});
|
||||
unsigned sum = type + static_cast<unsigned>(data.size());
|
||||
for (auto byte : data) { tape.push_back(byte); sum += byte; }
|
||||
tape.push_back(static_cast<std::uint8_t>(sum)); tape.push_back(0x55);
|
||||
};
|
||||
// Filename block: BASIC, tokenized, continuous data; execution/load fields
|
||||
// are unused by CLOAD. Leaders follow the standard cassette block layout.
|
||||
std::vector<std::uint8_t> header(name.begin(), name.end()); header.resize(15, 0);
|
||||
tape.insert(tape.end(), 128, 0x55); block(0, header);
|
||||
tape.insert(tape.end(), 128, 0x55);
|
||||
for (std::size_t at = 0; at < program.size(); at += 255) {
|
||||
const auto end = std::min(program.size(), at + 255);
|
||||
block(1, {program.begin() + at, program.begin() + end});
|
||||
}
|
||||
block(0xff, {});
|
||||
return tape;
|
||||
}
|
||||
std::string BasicProgram::decode(const std::vector<std::uint8_t>& bytes, std::uint16_t start,
|
||||
const std::vector<BasicToken>& dictionary) {
|
||||
auto bad = [] { throw std::runtime_error("The CoCo's BASIC program has an invalid line chain or unsupported token"); };
|
||||
std::string out; std::size_t at = 0; int previous = -1;
|
||||
auto word = [&](std::size_t i) { if (i + 1 >= bytes.size()) bad(); return (unsigned(bytes[i]) << 8) | bytes[i + 1]; };
|
||||
while (true) {
|
||||
unsigned next = word(at);
|
||||
if (!next) { if (at + 2 != bytes.size()) bad(); return out; }
|
||||
if (next < unsigned(start) + at + 5 || next > unsigned(start) + bytes.size() - 2) bad();
|
||||
unsigned line = word(at + 2);
|
||||
if (line > 63999 || int(line) <= previous) bad();
|
||||
previous = line; out += std::to_string(line) + " "; at += 4;
|
||||
const auto end = next - start - 1;
|
||||
if (bytes[end] != 0) bad();
|
||||
bool literal = false, remark = false, data = false;
|
||||
while (at < end) {
|
||||
auto c = bytes[at++]; if (!c) bad();
|
||||
if (c == '"' && !remark) literal = !literal;
|
||||
if (c == ':' && !literal && !remark) {
|
||||
data = false;
|
||||
if (at < end && (bytes[at] == 0x83 || bytes[at] == 0x84)) continue;
|
||||
}
|
||||
if (c < 128 || literal || remark || data) {
|
||||
if (c < 32 || c > 126) bad();
|
||||
out.push_back(c); continue;
|
||||
}
|
||||
bool function = c == 0xff;
|
||||
if (function) { if (at >= end) bad(); c = bytes[at++]; }
|
||||
auto token = std::find_if(dictionary.begin(), dictionary.end(), [&](const auto& t) { return t.function == function && t.code == c; });
|
||||
if (token == dictionary.end()) bad();
|
||||
out += token->text;
|
||||
if (!function) { remark = c == 0x82 || c == 0x83; data = c == 0x86; }
|
||||
}
|
||||
out += '\n'; at = next - start;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Mac {
|
||||
enum class BasicExportFormat { Disk, Cassette };
|
||||
struct BasicSourceLocation {
|
||||
unsigned address = 0, line = 0, offset = 0, length = 0;
|
||||
};
|
||||
struct BasicToken {
|
||||
std::string text;
|
||||
std::uint8_t code;
|
||||
bool function = false;
|
||||
};
|
||||
struct BasicVariable {
|
||||
std::string name, kind, value;
|
||||
unsigned address = 0;
|
||||
// Source-order dimension lengths; the leftmost index varies fastest.
|
||||
std::vector<unsigned> dimensions;
|
||||
std::vector<std::string> elements;
|
||||
};
|
||||
// The caller supplies the active interpreter's dictionaries, not ROM bytes.
|
||||
struct BasicProgram {
|
||||
// A bounded copy of ordinary BASIC RAM, never device reads or ROM calls.
|
||||
static std::vector<BasicVariable> inspect(const std::vector<std::uint8_t>& memory);
|
||||
static std::vector<std::uint8_t> encode(const std::string& source, std::uint16_t start,
|
||||
std::uint16_t limit, const std::vector<BasicToken>& dictionary,
|
||||
std::vector<BasicSourceLocation>* locations = nullptr);
|
||||
// Fresh, formatted media; never modifies a mounted image. The tokenized
|
||||
// program is the standard in-memory BASIC line chain including its end word.
|
||||
static std::vector<std::uint8_t> exportImage(const std::vector<std::uint8_t>& program,
|
||||
const std::string& filename, BasicExportFormat format);
|
||||
static std::string decode(const std::vector<std::uint8_t>& bytes, std::uint16_t start,
|
||||
const std::vector<BasicToken>& dictionary);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// CoCo quick-load format and address semantics retained from quickload.cpp,
|
||||
// copyright 2015 Joseph Forgione. Validate the entire stream before applying it.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Mac {
|
||||
struct BinaryImage {
|
||||
static constexpr std::size_t maxBytes = 1024 * 1024;
|
||||
struct Block { std::uint16_t address; std::vector<std::uint8_t> bytes; };
|
||||
std::vector<Block> blocks;
|
||||
std::uint16_t entry = 0;
|
||||
|
||||
static BinaryImage parse(const std::vector<std::uint8_t>& data) {
|
||||
if (data.empty() || data.size() > maxBytes)
|
||||
throw std::invalid_argument("Choose a CoCo block-format BIN file, up to 1 MiB");
|
||||
BinaryImage image;
|
||||
std::size_t offset = 0;
|
||||
while (offset < data.size()) {
|
||||
if (data.size() - offset < 5) throw std::invalid_argument("The BIN file has a truncated block header");
|
||||
const auto type = data[offset];
|
||||
const auto length = (unsigned(data[offset + 1]) << 8) | data[offset + 2];
|
||||
const auto address = std::uint16_t((unsigned(data[offset + 3]) << 8) | data[offset + 4]);
|
||||
offset += 5;
|
||||
if (type == 0xff) {
|
||||
if (length != 0 || address == 0 || address > 0x7fff)
|
||||
throw std::invalid_argument("The BIN execution record must have length zero and an address from $0001 to $7FFF");
|
||||
if (offset != data.size()) throw std::invalid_argument("The BIN file has data after its execution record");
|
||||
image.entry = address; return image;
|
||||
}
|
||||
if (type != 0) throw std::invalid_argument("The BIN file contains an unknown block type");
|
||||
if (length > data.size() - offset) throw std::invalid_argument("The BIN file has a truncated data block");
|
||||
image.blocks.push_back({address, {data.begin() + offset, data.begin() + offset + length}});
|
||||
offset += length;
|
||||
}
|
||||
throw std::invalid_argument("The BIN file is missing its execution record");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/04/10 - Craig Allsop - Add OpenGL rendering.
|
||||
//
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Build Config - conditional compile options
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef USE_NEWTIMING
|
||||
#define USE_NEWTIMING true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable the use of OpenGL display driver
|
||||
//
|
||||
#ifndef USE_OPENGL
|
||||
#define USE_OPENGL true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Legacy does not support opengl so disable it.
|
||||
//
|
||||
#ifdef _LEGACY_VCC
|
||||
#undef USE_OPENGL
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable the use of DirectX display driver
|
||||
//
|
||||
#ifndef USE_DIRECTX
|
||||
#define USE_DIRECTX true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Force directX to use 16 bit surface
|
||||
//
|
||||
#ifndef USE_DIRECTX_16BIT_SURFACE
|
||||
#define USE_DIRECTX_16BIT_SURFACE false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Force directX to use 8 bit surface
|
||||
//
|
||||
#ifndef USE_DIRECTX_8BIT_SURFACE
|
||||
#define USE_DIRECTX_8BIT_SURFACE false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable black fill to preserve aspect ratio, otherwise replicate border color.
|
||||
//
|
||||
#ifndef USE_BLACKEDGES
|
||||
#define USE_BLACKEDGES true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable rendering of debug lines
|
||||
// Needs: USE_OPENGL
|
||||
//
|
||||
#ifndef USE_DEBUG_LINES
|
||||
#define USE_DEBUG_LINES true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable debug of joystick ramp.
|
||||
// Needs: USE_DEBUG_LINES
|
||||
//
|
||||
#ifndef USE_DEBUG_RAMP
|
||||
#define USE_DEBUG_RAMP false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable debugging of mouse cursor.
|
||||
// Needs: USE_DEBUG_LINES
|
||||
//
|
||||
#ifndef USE_DEBUG_MOUSE
|
||||
#define USE_DEBUG_MOUSE false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enables the older opening window in default positing, otherwise remember position.
|
||||
//
|
||||
#ifndef USE_DEFAULT_POSITIONING
|
||||
#define USE_DEFAULT_POSITIONING false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable debugging display of audio and tape, mux and motor control, as well as output buffers.
|
||||
//
|
||||
#ifndef USE_DEBUG_AUDIOTAPE
|
||||
#define USE_DEBUG_AUDIOTAPE false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable extra debugging options.
|
||||
// Command Line:
|
||||
// -n No video output.
|
||||
// -f<n> Render <n> frames.
|
||||
// -s<file> Write <file> screenshot after rendering <n> frames.
|
||||
//
|
||||
#ifndef USE_DEBUG_OPTIONS
|
||||
#define USE_DEBUG_OPTIONS false
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable test code
|
||||
//
|
||||
#ifndef USE_DEBUG_TESTS
|
||||
#define USE_DEBUG_TESTS true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Show fps
|
||||
// Requires USE_DEBUG_LINES
|
||||
//
|
||||
#ifndef USE_FPS
|
||||
#define USE_FPS true
|
||||
#endif
|
||||
|
||||
//
|
||||
// Enable bounds checking on video buffer.
|
||||
// Disable by default as it slows debug down.
|
||||
//
|
||||
#ifndef USE_DEBUG_VIDEO_BUFFER
|
||||
#define USE_DEBUG_VIDEO_BUFFER false
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Edit options above rather than these:
|
||||
//
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Options that are always off for release
|
||||
//
|
||||
#ifdef NDEBUG
|
||||
#undef USE_DEBUG_LINES
|
||||
#define USE_DEBUG_LINES false
|
||||
#undef USE_DEBUG_AUDIOTAPE
|
||||
#define USE_DEBUG_AUDIOTAPE false
|
||||
#undef USE_DEBUG_MOUSE
|
||||
#define USE_DEBUG_MOUSE false
|
||||
#undef USE_DEBUG_TESTS
|
||||
#define USE_DEBUG_TESTS false
|
||||
#undef USE_FPS
|
||||
#define USE_FPS false
|
||||
#undef USE_DEBUG_VIDEO_BUFFER
|
||||
#define USE_DEBUG_VIDEO_BUFFER false
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// CAS waveforms and rising-edge decoder adapted from Cassette.cpp,
|
||||
// Copyright 2015 Joseph Forgione and subsequent VCC contributors.
|
||||
#include "CassetteDeck.h"
|
||||
#include "CpuMemory.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
namespace VCC::Mac {
|
||||
namespace {
|
||||
const std::uint8_t one[] = {0xC8,0xE8,0xE8,0xF8,0xF8,0xE8,0xC8,0xA8,0x78,0x50,0x50,0x30,0x10,0,0,0x10,0x30,0x30,0x50,0x80,0xA8};
|
||||
const std::uint8_t zero[] = {0xC8,0xD8,0xE8,0xE8,0xF0,0xF8,0xF8,0xF8,0xF0,0xE8,0xD8,0xC8,0xB8,0xA8,0x90,0x78,0x78,0x68,0x50,0x40,0x30,0x20,0x10,8,0,0,0,8,0x10,0x10,0x20,0x30,0x40,0x50,0x68,0x68,0x80,0x90,0xA8,0xB8};
|
||||
std::uint32_t read(const std::vector<std::uint8_t>& b, std::size_t p, unsigned n) {
|
||||
if (p > b.size() || n > b.size()-p) throw std::invalid_argument("Truncated WAV file");
|
||||
std::uint32_t v=0; for(unsigned i=0;i<n;++i) v |= std::uint32_t(b[p+i]) << (8*i); return v;
|
||||
}
|
||||
void put(std::vector<std::uint8_t>& b, std::uint32_t v, unsigned n) { while(n--) { b.push_back(v & 255); v >>= 8; } }
|
||||
bool tag(const std::vector<std::uint8_t>& b, std::size_t p, const char* s) { return p+4<=b.size() && !std::memcmp(b.data()+p,s,4); }
|
||||
std::vector<std::uint8_t> decodeWav(const std::vector<std::uint8_t>& b) {
|
||||
if (!tag(b,0,"RIFF") || !tag(b,8,"WAVE")) throw std::invalid_argument("Expected a RIFF/WAVE cassette image");
|
||||
const std::size_t end = std::size_t(read(b,4,4))+8;
|
||||
if(end>b.size() || end<12) throw std::invalid_argument("Invalid WAV length");
|
||||
unsigned encoding=0, channels=0, rate=0, bits=0, align=0;
|
||||
std::size_t start=0, length=0;
|
||||
for(std::size_t p=12;p+8<=end;) {
|
||||
const auto n=read(b,p+4,4); const auto body=p+8;
|
||||
if(n>end-body) throw std::invalid_argument("Truncated WAV chunk");
|
||||
if(tag(b,p,"fmt ")) {
|
||||
if(n<16) throw std::invalid_argument("Invalid WAV format chunk");
|
||||
encoding=read(b,body,2); channels=read(b,body+2,2); rate=read(b,body+4,4);
|
||||
align=read(b,body+12,2); bits=read(b,body+14,2);
|
||||
} else if(tag(b,p,"data") && !start) { start=body; length=n; }
|
||||
p=body+n+(n&1);
|
||||
}
|
||||
if(!start || !rate || rate<8000 || rate>192000 || channels<1 || channels>2 ||
|
||||
!((encoding==1 && (bits==8 || bits==16 || bits==24 || bits==32)) || (encoding==3 && bits==32)) ||
|
||||
align!=channels*(bits/8) || length%align)
|
||||
throw std::invalid_argument("Use mono/stereo PCM 8/16/24/32-bit or float32 WAV, 8–192 kHz");
|
||||
const std::size_t count=length/align, outCount=(std::uint64_t(count)*CassetteDeck::rate)/rate;
|
||||
if(outCount>CassetteDeck::maxBytes-44) throw std::invalid_argument("Decoded tape exceeds 64 MiB");
|
||||
std::vector<std::uint8_t> result; result.reserve(outCount);
|
||||
for(std::size_t i=0;i<outCount;++i) {
|
||||
const auto offset=start+(std::uint64_t(i)*rate/CassetteDeck::rate)*align;
|
||||
double value=0;
|
||||
for(unsigned c=0;c<channels;++c) {
|
||||
auto raw=read(b,offset+c*(bits/8),bits/8); double sample;
|
||||
if(encoding==3) { float f; std::memcpy(&f,&raw,4); if(!std::isfinite(f)) throw std::invalid_argument("Non-finite WAV sample"); sample=f; }
|
||||
else if(bits==8) sample=(int(raw)-128)/128.0;
|
||||
else { const std::int64_t signedValue = (raw & (std::uint32_t(1)<<(bits-1))) ? std::int64_t(raw)-(std::int64_t(1)<<bits) : raw; sample=double(signedValue)/double(std::int64_t(1)<<(bits-1)); }
|
||||
value+=sample;
|
||||
}
|
||||
result.push_back(static_cast<std::uint8_t>(std::clamp(value/channels*128+128,0.0,255.0)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
void CassetteDeck::resetDecoder() { bit=phase=0; elapsed=lastRise=recordBits=0; lastSample=recordByte=0; }
|
||||
void CassetteDeck::mount(const std::vector<std::uint8_t>& bytes,TapeFormat format) {
|
||||
if(bytes.size()>maxBytes || (format==TapeFormat::CAS && bytes.size()>1024*1024)) throw std::invalid_argument("Tape image is too large");
|
||||
auto next=format==TapeFormat::WAV ? decodeWav(bytes) : bytes;
|
||||
data=std::move(next); const bool fast=state.fast, motor=state.motor;
|
||||
state={}; state.fast=fast; state.motor=motor; state.mounted=true; state.format=format; state.length=data.size();
|
||||
resetDecoder(); quiet=30000;
|
||||
}
|
||||
void CassetteDeck::record(TapeFormat format) {
|
||||
const bool motor=state.motor, fast=state.fast; data.clear(); state={};
|
||||
state.motor=motor; state.fast=fast; state.mounted=true; state.format=format; state.mode=TapeMode::Recording;
|
||||
resetDecoder(); quiet=0;
|
||||
}
|
||||
void CassetteDeck::play() { if(!state.mounted) throw std::logic_error("Insert a tape first"); state.mode=TapeMode::Playing; }
|
||||
void CassetteDeck::stop() { state.mode=TapeMode::Stopped; }
|
||||
void CassetteDeck::rewind() { seek(0); }
|
||||
void CassetteDeck::seek(std::size_t position) { stop(); state.position=std::min(position,data.size()); resetDecoder(); quiet=30000; }
|
||||
void CassetteDeck::eject() { const bool motor=state.motor, fast=state.fast; data.clear(); state={}; state.motor=motor; state.fast=fast; resetDecoder(); }
|
||||
void CassetteDeck::motor(bool on) {
|
||||
if(state.motor && !on) { quiet=15000; phase=0; elapsed=lastRise=recordBits=0; recordByte=lastSample=0; }
|
||||
state.motor=on;
|
||||
}
|
||||
void CassetteDeck::setFast(bool enabled) { if(state.fast!=enabled) { phase=0; bit=0; state.fast=enabled; } }
|
||||
bool CassetteDeck::fastLoading() const { return state.fast && state.format==TapeFormat::CAS && state.mode==TapeMode::Playing && state.position<data.size(); }
|
||||
void CassetteDeck::nextBit() { phase=0; if(++bit==8) { bit=0; ++state.position; } }
|
||||
std::uint8_t CassetteDeck::fastBit() {
|
||||
if(!state.motor || !fastLoading()) return 0;
|
||||
if(quiet) return 0; // silence advances in emulated time, not host poll time
|
||||
++reads;
|
||||
const bool value=(data[state.position]>>bit)&1;
|
||||
MemWrite8(value?10:20,0x83); // same BASIC acceleration contract as coco3.cpp
|
||||
const auto level=phase==0 ? 1 : 0;
|
||||
if(++phase==2) nextBit();
|
||||
return level;
|
||||
}
|
||||
std::uint8_t CassetteDeck::tick(std::uint8_t output) {
|
||||
if(!state.motor || !state.mounted) return 128;
|
||||
if(state.mode==TapeMode::Playing) {
|
||||
if(state.position>=data.size()) { stop(); return 128; }
|
||||
if(state.format==TapeFormat::WAV) { ++reads; return data[state.position++]; }
|
||||
if(quiet) { --quiet; return 128; }
|
||||
if(fastLoading()) return 128;
|
||||
++reads;
|
||||
const bool value=(data[state.position]>>bit)&1;
|
||||
const unsigned sample=(value ? one[phase] : zero[phase]);
|
||||
if(++phase==(value?21u:40u)) nextBit();
|
||||
return sample/2+sample/4+32;
|
||||
}
|
||||
if(state.mode==TapeMode::Recording) {
|
||||
if(data.size()>=(state.format==TapeFormat::CAS?1024*1024:maxBytes-44)) { stop(); return 128; }
|
||||
++writes; // Actual motor-driven recording samples, even before a CAS byte completes.
|
||||
state.dirty=true;
|
||||
if(state.format==TapeFormat::WAV) data.push_back(output);
|
||||
else {
|
||||
++elapsed;
|
||||
if(lastSample<=128 && output>128) {
|
||||
const auto width=elapsed-lastRise;
|
||||
if(width<10 || width>50) { recordBits=0; recordByte=0; }
|
||||
else { recordByte |= (width<=30 ? 1:0)<<recordBits;
|
||||
if(++recordBits==8) { data.push_back(recordByte); recordByte=recordBits=0; }
|
||||
}
|
||||
lastRise=elapsed;
|
||||
}
|
||||
lastSample=output;
|
||||
}
|
||||
state.position=state.length=data.size();
|
||||
}
|
||||
return 128;
|
||||
}
|
||||
std::vector<std::uint8_t> CassetteDeck::exportImage() {
|
||||
stop();
|
||||
if(!state.mounted) throw std::logic_error("No tape to export");
|
||||
if(state.format==TapeFormat::CAS) return data;
|
||||
std::vector<std::uint8_t> b={'R','I','F','F'}; put(b,static_cast<std::uint32_t>(36+data.size()+(data.size()&1)),4);
|
||||
b.insert(b.end(),{'W','A','V','E','f','m','t',' '}); put(b,16,4); put(b,1,2); put(b,1,2);
|
||||
put(b,rate,4); put(b,rate,4); put(b,1,2); put(b,8,2);
|
||||
b.insert(b.end(),{'d','a','t','a'}); put(b,static_cast<std::uint32_t>(data.size()),4); b.insert(b.end(),data.begin(),data.end());
|
||||
if(data.size()&1) b.push_back(0); return b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
namespace VCC::Mac {
|
||||
enum class TapeFormat { CAS, WAV };
|
||||
enum class TapeMode { Stopped, Playing, Recording };
|
||||
struct TapeState {
|
||||
bool mounted = false, motor = false, dirty = false, fast = false;
|
||||
TapeFormat format = TapeFormat::CAS;
|
||||
TapeMode mode = TapeMode::Stopped;
|
||||
std::size_t position = 0, length = 0;
|
||||
std::uint64_t readEvents = 0, writeEvents = 0;
|
||||
};
|
||||
// Serial emulation-thread deck. Files are copied in; export never modifies a host file.
|
||||
class CassetteDeck {
|
||||
public:
|
||||
static constexpr unsigned rate = 44100;
|
||||
static constexpr std::size_t maxBytes = 64 * 1024 * 1024;
|
||||
void mount(const std::vector<std::uint8_t>& bytes, TapeFormat format);
|
||||
void record(TapeFormat format);
|
||||
void play();
|
||||
void stop();
|
||||
void rewind();
|
||||
void seek(std::size_t position);
|
||||
void eject();
|
||||
void motor(bool on);
|
||||
void setFast(bool enabled);
|
||||
bool fastLoading() const;
|
||||
std::uint8_t fastBit(); // retained ROM acceleration contract, updates $83
|
||||
std::uint8_t tick(std::uint8_t output); // one 44.1 kHz emulated sample
|
||||
std::vector<std::uint8_t> exportImage(); // stops transport; remains dirty until saved
|
||||
void markSaved() { state.dirty = false; }
|
||||
TapeState snapshot() const { auto result = state; result.readEvents = reads; result.writeEvents = writes; return result; }
|
||||
private:
|
||||
TapeState state;
|
||||
std::uint64_t reads = 0, writes = 0;
|
||||
std::vector<std::uint8_t> data;
|
||||
unsigned bit = 0, phase = 0, quiet = 0;
|
||||
unsigned elapsed = 0, lastRise = 0, recordBits = 0;
|
||||
std::uint8_t lastSample = 0, recordByte = 0;
|
||||
void resetDecoder();
|
||||
void nextBit();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/05/22 - Craig Allsop - Interrupt handling.
|
||||
//
|
||||
|
||||
// no includes here, included by 6809.c, 6309.c
|
||||
|
||||
//
|
||||
// Access cc flags as boolean
|
||||
//
|
||||
static inline bool CC(char flag)
|
||||
{
|
||||
return cc[flag] ? true : false;
|
||||
}
|
||||
|
||||
//
|
||||
// Interrupt lines reading from output of the latch
|
||||
//
|
||||
static inline bool FIRQ() { return InterruptLatch & Bit(INT_FIRQ) ? true : false; }
|
||||
static inline bool IRQ() { return InterruptLatch & Bit(INT_IRQ) ? true : false; }
|
||||
static inline bool NMI() { return InterruptLatch & Bit(INT_NMI) ? true : false; }
|
||||
|
||||
//
|
||||
// Latch the interrupt lines
|
||||
// This done per instruction top of state A (see figure 15, 6809 spec) and also waiting in SYNC
|
||||
//
|
||||
static inline void LatchInterrupts()
|
||||
{
|
||||
uint8_t OR = 0;
|
||||
for (int is = 0; is < IS_MAX; ++is)
|
||||
OR |= InterruptLine[is];
|
||||
|
||||
// clock next input
|
||||
InterruptLatch = OR;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear the nmi interrupt
|
||||
//
|
||||
static inline void ClearNMI()
|
||||
{
|
||||
InterruptLine[IS_NMI] &= BitMask(INT_NMI);
|
||||
LatchInterrupts();
|
||||
}
|
||||
|
||||
//
|
||||
// Clear state of all interrupt lines
|
||||
//
|
||||
static inline void ClearInterrupts()
|
||||
{
|
||||
for (int is = 0; is < IS_MAX; ++is)
|
||||
InterruptLine[is] = 0;
|
||||
InterruptLatch = 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CpuHost.h"
|
||||
#ifdef _WIN32
|
||||
#include "../../platforms/windows/defines.h"
|
||||
#include "../../platforms/windows/Disassembler.h"
|
||||
#endif
|
||||
|
||||
namespace VCC {
|
||||
namespace {
|
||||
#ifdef _WIN32
|
||||
// The original Windows UI remains the owner of debugger state and haltpoints.
|
||||
class DefaultHooks final : public CpuDebugHooks {
|
||||
public:
|
||||
bool IsHalted() const override { return EmuState.Debugger.IsHalted(); }
|
||||
void Halt() override { EmuState.Debugger.Halt(); }
|
||||
bool IsStepping() const override { return EmuState.Debugger.IsStepping(); }
|
||||
bool IsTracingEnabled() const override { return EmuState.Debugger.IsTracingEnabled(); }
|
||||
bool IsTracing() const override { return EmuState.Debugger.IsTracing(); }
|
||||
bool Halt_Enabled() const override { return EmuState.Debugger.Halt_Enabled(); }
|
||||
bool Break_Enabled() const override { return EmuState.Debugger.Break_Enabled(); }
|
||||
void ApplyHaltpoints(bool enabled) override { VCC::ApplyHaltpoints(enabled); }
|
||||
void DiagnosticMessage(const char* text) override { OutputDebugStringA(text); }
|
||||
void TraceVideoEvent(TraceEvent event, unsigned int line) override {
|
||||
#if USE_NEWTIMING
|
||||
EmuState.Debugger.TraceCaptureScreenEvent(event, 0, line);
|
||||
#else
|
||||
EmuState.Debugger.TraceCaptureScreenEvent(event, 0);
|
||||
#endif
|
||||
}
|
||||
void TraceRegisterWrite(const char* text) override {
|
||||
#if USE_NEWTIMING
|
||||
EmuState.Debugger.TraceCaptureScreenEvent(TraceEvent::ScreenReg, 0, 0, text);
|
||||
#endif
|
||||
}
|
||||
void TraceStart() override { EmuState.Debugger.TraceStart(); }
|
||||
void TraceCaptureBefore(long cycles, const CPUState& state) override {
|
||||
EmuState.Debugger.TraceCaptureBefore(cycles, state);
|
||||
}
|
||||
void TraceCaptureAfter(long cycles, const CPUState& state) override {
|
||||
EmuState.Debugger.TraceCaptureAfter(cycles, state);
|
||||
}
|
||||
void TraceCaptureInterruptRequest(unsigned char irq, long cycles, const CPUState& state) override {
|
||||
EmuState.Debugger.TraceCaptureInterruptRequest(irq, cycles, state);
|
||||
}
|
||||
void TraceCaptureInterruptServicing(unsigned char irq, long cycles, const CPUState& state) override {
|
||||
EmuState.Debugger.TraceCaptureInterruptServicing(irq, cycles, state);
|
||||
}
|
||||
void TraceCaptureInterruptExecuting(unsigned char irq, long cycles, const CPUState& state) override {
|
||||
EmuState.Debugger.TraceCaptureInterruptExecuting(irq, cycles, state);
|
||||
}
|
||||
};
|
||||
#else
|
||||
class DefaultHooks final : public CpuDebugHooks {
|
||||
public:
|
||||
bool IsHalted() const override { return halted; }
|
||||
void Halt() override { halted = true; }
|
||||
private:
|
||||
bool halted = false;
|
||||
};
|
||||
#endif
|
||||
DefaultHooks defaultHooks;
|
||||
CpuDebugHooks* activeHooks = &defaultHooks;
|
||||
}
|
||||
CpuDebugHooks& CpuDebugger() { return *activeHooks; }
|
||||
void SetCpuDebugHooks(CpuDebugHooks* hooks) {
|
||||
activeHooks = hooks ? hooks : &defaultHooks;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
// Retained CPU joystick-ramp clock; native input integration is still pending.
|
||||
// Windows owns this storage in joystickinput.cpp.
|
||||
int JS_Ramp_Clock = 0;
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "MachineDefs.h"
|
||||
|
||||
namespace VCC {
|
||||
// Called synchronously on the emulation thread. Install before execution and
|
||||
// keep alive until detached. This does not make the legacy CPU globals reentrant.
|
||||
class CpuDebugHooks {
|
||||
public:
|
||||
virtual ~CpuDebugHooks() = default;
|
||||
virtual bool IsHalted() const = 0;
|
||||
virtual void Halt() = 0;
|
||||
virtual bool ShouldBreakAt(unsigned short) { return true; }
|
||||
virtual bool IsStepping() const { return false; }
|
||||
// Optional source stepping runs through normal execution, including IRQs.
|
||||
// Defaults keep the Windows debugger and ordinary execution unchanged.
|
||||
virtual bool IsSourceStepping() const { return false; }
|
||||
virtual bool SourceStepBefore(const CPUState&) { return false; }
|
||||
virtual void SourceStepAfter(const CPUState&) {}
|
||||
virtual void SourceStepInterrupt(const CPUState&) {}
|
||||
virtual bool IsTracingEnabled() const { return false; }
|
||||
virtual bool IsTracing() const { return false; }
|
||||
virtual bool Halt_Enabled() const { return false; }
|
||||
virtual bool Break_Enabled() const { return false; }
|
||||
virtual void ApplyHaltpoints(bool) {}
|
||||
virtual void TraceStart() {}
|
||||
virtual void TraceRegisterWrite(const char*) {}
|
||||
virtual void TraceVideoEvent(TraceEvent, unsigned int) {}
|
||||
virtual void DiagnosticMessage(const char*) {}
|
||||
virtual void TraceCaptureBefore(long, const CPUState&) {}
|
||||
virtual void TraceCaptureAfter(long, const CPUState&) {}
|
||||
virtual void TraceCaptureInterruptRequest(unsigned char, long, const CPUState&) {}
|
||||
virtual void TraceCaptureInterruptServicing(unsigned char, long, const CPUState&) {}
|
||||
virtual void TraceCaptureInterruptExecuting(unsigned char, long, const CPUState&) {}
|
||||
};
|
||||
|
||||
CpuDebugHooks& CpuDebugger();
|
||||
// nullptr restores the platform default (the existing debugger on Windows).
|
||||
void SetCpuDebugHooks(CpuDebugHooks* hooks);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "CpuMemory.h"
|
||||
#include "tcc1014mmu.h"
|
||||
|
||||
namespace { VCC::CpuMemoryBus* isolatedBus = nullptr; }
|
||||
void VCC::SetCpuMemoryBus(CpuMemoryBus* bus) { isolatedBus = bus; }
|
||||
unsigned char MemRead8(unsigned short address) {
|
||||
return isolatedBus ? isolatedBus->Read(address) : MmuRead8(address);
|
||||
}
|
||||
void MemWrite8(unsigned char value, unsigned short address) {
|
||||
if (isolatedBus) isolatedBus->Write(value, address);
|
||||
else MmuWrite8(value, address);
|
||||
}
|
||||
unsigned short MemRead16(unsigned short address) {
|
||||
return (MemRead8(address) << 8) | MemRead8(static_cast<unsigned short>(address + 1));
|
||||
}
|
||||
void MemWrite16(unsigned short value, unsigned short address) {
|
||||
MemWrite8(static_cast<unsigned char>(value >> 8), address);
|
||||
MemWrite8(static_cast<unsigned char>(value), static_cast<unsigned short>(address + 1));
|
||||
}
|
||||
void SetMapType(unsigned char type) {
|
||||
if (isolatedBus) isolatedBus->SelectMap(type);
|
||||
else MmuSetMapType(type);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// CPU bus contract. By default this uses the real MMU and I/O decoder.
|
||||
void MemWrite8(unsigned char value, unsigned short address);
|
||||
void MemWrite16(unsigned short value, unsigned short address);
|
||||
unsigned char MemRead8(unsigned short address);
|
||||
unsigned short MemRead16(unsigned short address);
|
||||
void SetMapType(unsigned char type);
|
||||
|
||||
namespace VCC {
|
||||
// Optional isolated CPU bus (e.g. instruction tests). Install outside execution,
|
||||
// retain until detached, and restore nullptr for the actual machine MMU.
|
||||
class CpuMemoryBus {
|
||||
public:
|
||||
virtual ~CpuMemoryBus() = default;
|
||||
virtual unsigned char Read(unsigned short address) = 0;
|
||||
virtual void Write(unsigned char value, unsigned short address) = 0;
|
||||
virtual void SelectMap(unsigned char type) = 0;
|
||||
};
|
||||
void SetCpuMemoryBus(CpuMemoryBus* bus);
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Uses Mike Rojas's original VCC opcode tables. Operand formatting is isolated
|
||||
// from the Windows UI, global memory bus, and execution-cycle estimation.
|
||||
#include "DebugDisassembler.h"
|
||||
#include "OpCodeTables.h"
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace VCC::Mac {
|
||||
namespace {
|
||||
using Tables = VCC::Debugger::OpCodeTables;
|
||||
const Tables& tables() { static const Tables value; return value; }
|
||||
std::string hex(std::uint32_t value, unsigned digits) {
|
||||
std::ostringstream out;
|
||||
out << '$' << std::uppercase << std::hex << std::setfill('0') << std::setw(digits) << value;
|
||||
return out.str();
|
||||
}
|
||||
void replace(std::string& value, const std::string& from, const std::string& to) {
|
||||
const auto pos = value.find(from);
|
||||
if (pos != std::string::npos) value.replace(pos, from.size(), to);
|
||||
}
|
||||
std::string registerName(unsigned value, bool use6309) {
|
||||
constexpr const char* names[] = {"D", "X", "Y", "U", "S", "PC", "W", "V",
|
||||
"A", "B", "CC", "DP", "0", "0", "E", "F"};
|
||||
if (!use6309 && (value == 6 || value == 7 || value >= 12)) return {};
|
||||
return names[value & 15];
|
||||
}
|
||||
class Reader {
|
||||
public:
|
||||
const std::vector<std::uint8_t>& memory;
|
||||
DebugInstruction result;
|
||||
std::uint16_t pc;
|
||||
Reader(const std::vector<std::uint8_t>& bytes, std::uint16_t start) : memory(bytes), pc(start) {
|
||||
result.address = start;
|
||||
}
|
||||
unsigned byte() { const auto value = memory[pc++]; result.bytes.push_back(value); return value; }
|
||||
unsigned word() { const auto high = byte(); return (high << 8) | byte(); }
|
||||
DebugInstruction invalid() {
|
||||
result.valid = false; result.mnemonic = "FCB"; result.operand.clear();
|
||||
for (auto value : result.bytes) {
|
||||
if (!result.operand.empty()) result.operand += ',';
|
||||
result.operand += hex(value, 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool indexed(bool use6309) {
|
||||
const auto post = byte();
|
||||
constexpr const char* registers[] = {"X", "Y", "U", "S"};
|
||||
const std::string reg = registers[(post >> 5) & 3];
|
||||
if (!(post & 128)) {
|
||||
const int offset = (post & 31) - ((post & 16) ? 32 : 0);
|
||||
result.operand += std::to_string(offset) + ',' + reg;
|
||||
return true;
|
||||
}
|
||||
// Upstream's indirect W,R map key duplicates direct W,R. Correct it
|
||||
// locally without changing the Windows debugger's tables.
|
||||
if ((post & 0x9f) == 0x9e) {
|
||||
if (!use6309) return false;
|
||||
result.operand += "[W," + reg + ']'; return true;
|
||||
}
|
||||
auto key = std::bitset<8>(post).to_string();
|
||||
const auto& modes = tables().IndexingModes;
|
||||
auto found = modes.find(key);
|
||||
if (found == modes.end()) { key[1] = key[2] = 'X'; found = modes.find(key); }
|
||||
if (found == modes.end()) { key[1] = key[2] = 'R'; found = modes.find(key); }
|
||||
if (found == modes.end() || (found->second.only6309 && !use6309)) return false;
|
||||
const auto& mode = found->second;
|
||||
auto operand = mode.form;
|
||||
// Replace register placeholders only; PCR contains an actual R.
|
||||
if (key[1] == 'R') replace(operand, "R", reg);
|
||||
if (mode.numbytes) {
|
||||
const auto raw = mode.numbytes == 1 ? byte() : word();
|
||||
const int offset = mode.numbytes == 1 ? int(raw) - ((raw & 128) ? 256 : 0)
|
||||
: int(raw) - ((raw & 32768) ? 65536 : 0);
|
||||
replace(operand, "n", operand == "[n]" ? hex(raw, 4) : std::to_string(offset));
|
||||
}
|
||||
result.operand += operand;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
// Service names from NitrOS-9 defs/os9.d. Unknown/private calls stay numeric.
|
||||
std::string os9Service(unsigned code) {
|
||||
constexpr const char* system[] = {
|
||||
"F$Link", "F$Load", "F$UnLink", "F$Fork", "F$Wait", "F$Chain", "F$Exit", "F$Mem",
|
||||
"F$Send", "F$Icpt", "F$Sleep", "F$SSpd", "F$ID", "F$SPrior", "F$SSWI", "F$PErr",
|
||||
"F$PrsNam", "F$CmpNam", "F$SchBit", "F$AllBit", "F$DelBit", "F$Time", "F$STime", "F$CRC",
|
||||
"F$GPrDsc", "F$GBlkMp", "F$GModDr", "F$CpyMem", "F$SUser", "F$UnLoad", "F$Alarm",
|
||||
"", "", "F$NMLink", "F$NMLoad", "F$Debug", "", "F$TPS", "F$TimAlm",
|
||||
"F$VIRQ", "F$SRqMem", "F$SRtMem", "F$IRQ", "F$IOQu", "F$AProc", "F$NProc", "F$VModul",
|
||||
"F$Find64", "F$All64", "F$Ret64", "F$SSvc", "F$IODel", "F$SLink", "F$Boot", "F$BtMem",
|
||||
"F$GProcP", "F$Move", "F$AllRAM", "F$AllImg", "F$DelImg", "F$SetImg", "F$FreeLB", "F$FreeHB",
|
||||
"F$AllTsk", "F$DelTsk", "F$SetTsk", "F$ResTsk", "F$RelTsk", "F$DATLog", "F$DATTmp", "F$LDAXY",
|
||||
"F$LDAXYP", "F$LDDDXY", "F$LDABX", "F$STABX", "F$AllPrc", "F$DelPrc", "F$ELink", "F$FModul",
|
||||
"F$MapBlk", "F$ClrBlk", "F$DelRAM", "F$GCMDir", "F$AlHRAM", "F$ReBoot", "F$CRCMod", "F$XTime", "F$VBlock"
|
||||
};
|
||||
constexpr const char* io[] = {"I$Attach", "I$Detach", "I$Dup", "I$Create", "I$Open", "I$MakDir",
|
||||
"I$ChgDir", "I$Delete", "I$Seek", "I$Read", "I$Write", "I$ReadLn", "I$WritLn", "I$GetStt",
|
||||
"I$SetStt", "I$Close", "I$DeletX", "I$ModDsc"};
|
||||
if (code < sizeof(system) / sizeof(*system)) return system[code];
|
||||
if (code >= 0x80 && code < 0x80 + sizeof(io) / sizeof(*io)) return io[code - 0x80];
|
||||
if (code == 0x70) return "F$RegDmp";
|
||||
if (code == 0x71) return "F$NVRAM";
|
||||
return {};
|
||||
}
|
||||
DebugInstruction decode(const std::vector<std::uint8_t>& memory, bool use6309, std::uint16_t address, bool os9 = false) {
|
||||
Reader read(memory, address);
|
||||
if (os9 && memory[address] == 0x87 && memory[std::uint16_t(address + 1)] == 0xcd) {
|
||||
unsigned parity = 0;
|
||||
for (unsigned i = 0; i < 9; ++i) parity ^= memory[std::uint16_t(address + i)];
|
||||
if (parity == 0xff) {
|
||||
read.word();
|
||||
const auto size = read.word(), name = read.word(), type = read.byte(), attributes = read.byte();
|
||||
read.byte();
|
||||
read.result.mnemonic = "MODULE";
|
||||
read.result.operand = "size " + hex(size, 4) + ", name +" + hex(name, 4) +
|
||||
", type/language " + hex(type, 2) + ", attributes/revision " + hex(attributes, 2);
|
||||
if ((type & 0xf0) == 0x10 || (type & 0xf0) == 0xe0 || (type & 0xf0) == 0xc0) {
|
||||
const auto entry = read.word(), storage = read.word();
|
||||
read.result.operand += ", entry +" + hex(entry, 4) + ", data " + hex(storage, 4);
|
||||
}
|
||||
return read.result;
|
||||
}
|
||||
}
|
||||
const auto first = read.byte();
|
||||
const auto page = first == 0x10 ? 2 : first == 0x11 ? 3 : 1;
|
||||
const auto opcode = page == 1 ? first : read.byte();
|
||||
const auto& entry = page == 1 ? tables().Page1OpCodes[opcode] :
|
||||
page == 2 ? tables().Page2OpCodes[opcode] : tables().Page3OpCodes[opcode];
|
||||
// A handful of Q-register table entries predate the only6309 flag.
|
||||
const bool extra6309 = entry.name == "LDQ" || entry.name == "STQ";
|
||||
// The optional VCC HALT/BREAK pseudo-opcodes are disabled in this host.
|
||||
if ((page == 1 && opcode == 0x15) || (page == 3 && opcode == 0x3e) ||
|
||||
entry.mode == Tables::Illegal || entry.numbytes <= 0 ||
|
||||
(!use6309 && (entry.only6309 || extra6309))) return read.invalid();
|
||||
read.result.mnemonic = entry.name;
|
||||
if (os9 && page == 2 && opcode == 0x3f) {
|
||||
const auto service = read.byte();
|
||||
const auto name = os9Service(service);
|
||||
read.result.mnemonic = "OS9";
|
||||
read.result.operand = name.empty() ? '#' + hex(service, 2) : name + " (" + hex(service, 2) + ')';
|
||||
return read.result;
|
||||
}
|
||||
const bool immediateMemory = page == 1 &&
|
||||
(entry.name == "OIM" || entry.name == "AIM" || entry.name == "EIM" || entry.name == "TIM");
|
||||
if (immediateMemory) read.result.operand = '#' + hex(read.byte(), 2) + ',';
|
||||
if (page == 3 && opcode >= 0x30 && opcode <= 0x37) {
|
||||
const auto post = read.byte(); const auto direct = read.byte();
|
||||
constexpr const char* regs[] = {"CC", "A", "B"};
|
||||
if ((post >> 6) == 3) return read.invalid();
|
||||
read.result.operand = std::string(regs[post >> 6]) + ',' + std::to_string((post >> 3) & 7) +
|
||||
',' + std::to_string(post & 7) + ",<" + hex(direct, 2);
|
||||
} else if (page == 3 && opcode >= 0x38 && opcode <= 0x3b) {
|
||||
const auto post = read.byte(); const auto source = post >> 4, destination = post & 15;
|
||||
if (source > 4 || destination > 4) return read.invalid();
|
||||
const char* srcSuffix = opcode == 0x39 ? "-" : opcode == 0x3b ? "" : "+";
|
||||
const char* dstSuffix = opcode == 0x39 ? "-" : opcode == 0x3a ? "" : "+";
|
||||
read.result.operand = registerName(source, true) + srcSuffix + ',' + registerName(destination, true) + dstSuffix;
|
||||
} else if ((page == 1 && (opcode == 0x1e || opcode == 0x1f)) ||
|
||||
(page == 2 && opcode >= 0x30 && opcode <= 0x37)) {
|
||||
const auto post = read.byte();
|
||||
const auto source = registerName(post >> 4, use6309), destination = registerName(post & 15, use6309);
|
||||
if (source.empty() || destination.empty()) return read.invalid();
|
||||
read.result.operand = source + ',' + destination;
|
||||
} else if (page == 1 && opcode >= 0x34 && opcode <= 0x37) {
|
||||
const auto mask = read.byte();
|
||||
const char* regs[] = {"CC", "A", "B", "DP", "X", "Y", opcode & 2 ? "S" : "U", "PC"};
|
||||
for (unsigned i = 0; i < 8; ++i) if (mask & (1 << i)) {
|
||||
if (!read.result.operand.empty()) read.result.operand += ',';
|
||||
read.result.operand += regs[i];
|
||||
}
|
||||
if (!mask) read.result.operand = "0";
|
||||
} else switch (entry.mode) {
|
||||
case Tables::Inherent: break;
|
||||
case Tables::Direct: read.result.operand += '<' + hex(read.byte(), 2); break;
|
||||
case Tables::Extended: read.result.operand += hex(read.word(), 4); break;
|
||||
case Tables::Indexed: if (!read.indexed(use6309)) return read.invalid(); break;
|
||||
case Tables::Immediate: {
|
||||
const unsigned length = entry.numbytes - entry.oplen;
|
||||
if (length < 1 || length > 4) return read.invalid();
|
||||
std::uint32_t value = 0;
|
||||
for (unsigned i = 0; i < length; ++i) value = (value << 8) | read.byte();
|
||||
read.result.operand = '#' + hex(value, length * 2); break;
|
||||
}
|
||||
case Tables::Relative: {
|
||||
const auto value = read.byte();
|
||||
const int offset = int(value) - ((value & 128) ? 256 : 0);
|
||||
read.result.operand = hex(std::uint16_t(read.pc + offset), 4); break;
|
||||
}
|
||||
case Tables::LongRelative: {
|
||||
const auto value = read.word();
|
||||
const int offset = int(value) - ((value & 32768) ? 65536 : 0);
|
||||
read.result.operand = hex(std::uint16_t(read.pc + offset), 4); break;
|
||||
}
|
||||
default: return read.invalid();
|
||||
}
|
||||
return read.result;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DebugInstruction> Disassemble(const std::vector<std::uint8_t>& memory,
|
||||
CPUState, bool use6309, std::uint16_t start, unsigned count, bool os9) {
|
||||
if (memory.size() != 65536) throw std::invalid_argument("Disassembly requires a complete 64 KiB memory snapshot");
|
||||
if (count > 1024) throw std::invalid_argument("Disassembly is limited to 1024 instructions per snapshot");
|
||||
std::vector<DebugInstruction> result;
|
||||
result.reserve(count);
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
auto instruction = decode(memory, use6309, start, os9);
|
||||
start = std::uint16_t(start + instruction.bytes.size());
|
||||
result.push_back(std::move(instruction));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::vector<DebugInstruction> DisassembleRange(const std::vector<std::uint8_t>& memory,
|
||||
const std::vector<std::uint8_t>& available, bool use6309,
|
||||
std::uint16_t logicalStart, unsigned count, bool os9) {
|
||||
if (memory.size() > 65536 || (!available.empty() && available.size() != memory.size()) || count > 1024)
|
||||
throw std::invalid_argument("Invalid bounded disassembly capture");
|
||||
std::vector<std::uint8_t> ring(65536, 0);
|
||||
for (std::size_t i = 0; i < memory.size(); ++i) ring[std::uint16_t(logicalStart + i)] = memory[i];
|
||||
std::vector<DebugInstruction> result;
|
||||
std::size_t offset = 0;
|
||||
while (offset < memory.size() && result.size() < count) {
|
||||
const auto pc = std::uint16_t(logicalStart + offset);
|
||||
auto instruction = decode(ring, use6309, pc, os9);
|
||||
const auto remaining = memory.size() - offset;
|
||||
const auto length = std::min(instruction.bytes.size(), remaining);
|
||||
bool readable = true;
|
||||
for (std::size_t i = 0; i < length && !available.empty(); ++i) readable &= available[offset + i] != 0;
|
||||
if (!readable) {
|
||||
instruction = {}; instruction.address = pc; instruction.valid = instruction.available = false;
|
||||
instruction.bytes = {0}; instruction.mnemonic = "—"; instruction.operand = "I/O unavailable";
|
||||
} else if (instruction.bytes.size() > remaining) {
|
||||
instruction.valid = false; instruction.mnemonic = "FCB"; instruction.operand.clear();
|
||||
instruction.bytes.assign(memory.begin() + offset, memory.end());
|
||||
for (auto byte : instruction.bytes) {
|
||||
if (!instruction.operand.empty()) instruction.operand += ',';
|
||||
instruction.operand += hex(byte, 2);
|
||||
}
|
||||
instruction.operand += " ; incomplete instruction/header";
|
||||
}
|
||||
offset += instruction.bytes.size();
|
||||
result.push_back(std::move(instruction));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "MachineDefs.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Mac {
|
||||
struct DebugInstruction {
|
||||
std::uint16_t address = 0;
|
||||
std::vector<std::uint8_t> bytes;
|
||||
std::string mnemonic, operand;
|
||||
bool valid = true;
|
||||
bool available = true;
|
||||
};
|
||||
|
||||
// Decode an owned, side-effect-free snapshot of the entire CPU address space.
|
||||
// Addresses wrap at 16 bits, as instruction fetch does. count is limited to
|
||||
// 1024. Invalid encodings are emitted as FCB with valid=false and always advance.
|
||||
// CPU identity is separate from native mode: HD6309 opcodes also work in its
|
||||
// emulation mode. state is retained for future state-dependent annotations.
|
||||
std::vector<DebugInstruction> Disassemble(const std::vector<std::uint8_t>& memory,
|
||||
CPUState state, bool use6309, std::uint16_t start, unsigned count, bool os9 = false);
|
||||
|
||||
// Decode a bounded linear capture (up to 64 KiB), never reading/wrapping beyond
|
||||
// its end. logicalStart is the assumed CPU origin for relative targets; callers
|
||||
// display physical addresses separately. An unavailable byte advances one byte
|
||||
// without inventing an opcode. A partial final instruction becomes FCB.
|
||||
std::vector<DebugInstruction> DisassembleRange(const std::vector<std::uint8_t>& memory,
|
||||
const std::vector<std::uint8_t>& available, bool use6309,
|
||||
std::uint16_t logicalStart, unsigned count, bool os9 = false);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/04/10 - Craig Allsop - Add OpenGL rendering.
|
||||
//
|
||||
|
||||
#include "../../platforms/windows/defines.h"
|
||||
#include "IDisplay.h"
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
//
|
||||
// No open display, just maintains surface.
|
||||
//
|
||||
struct DisplayNone : IDisplayDirectX, IDisplayOpenGL
|
||||
{
|
||||
explicit DisplayNone(ISystemState* state) : surface(nullptr), state(state) {}
|
||||
|
||||
int Setup(void* hwnd, int width, int height, int statusHeight, bool fullscreen) override
|
||||
{
|
||||
area.x = 0;
|
||||
area.y = 0;
|
||||
area.w = (float)width;
|
||||
area.h = (float)height;
|
||||
surface = new Pixel[width * height];
|
||||
return OK;
|
||||
}
|
||||
int Cleanup() override
|
||||
{
|
||||
delete[] surface;
|
||||
surface = nullptr;
|
||||
return OK;
|
||||
}
|
||||
int GetSurface(Pixel** pixels) override
|
||||
{
|
||||
*pixels = surface;
|
||||
return OK;
|
||||
}
|
||||
int GetRect(int rectOption, Rect* rect) override
|
||||
{
|
||||
if (rect)
|
||||
{
|
||||
memcpy(rect, &area, sizeof(*rect));
|
||||
return OK;
|
||||
}
|
||||
return !OK;
|
||||
}
|
||||
int LockSurface() override
|
||||
{
|
||||
state->SetSurface(surface, 3, 640);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Render() override { return OK; }
|
||||
int Present() override { return OK; }
|
||||
int UnlockSurface() override { return OK; }
|
||||
int SetOption(int flagOption, bool enabled) override { return OK; }
|
||||
void DebugDrawText(const OpenGLFont* font, float x, float y, float size, const char* text, Pixel color) override {}
|
||||
void DebugDrawLine(float x1, float y1, float x2, float y2, Pixel color) override {}
|
||||
void DebugDrawBox(float x, float y, float w, float h, Pixel color, bool filled) override {}
|
||||
int RenderSignalLostMessage() override { return OK; }
|
||||
int RenderBox(float x, float y, float w, float h, Pixel color, bool filled) override { return OK; }
|
||||
int RenderText(const OpenGLFont* font, float x, float y, float size, const char* text) override { return OK; }
|
||||
int LoadFont(const OpenGLFont** outFont, int bitmapRes, const OpenGLFontGlyph* glyphs, int start, int end) override { return OK; }
|
||||
int RenderStatusLine(char* statusText) override { return OK; }
|
||||
|
||||
private:
|
||||
|
||||
Pixel* surface;
|
||||
ISystemState* state;
|
||||
Rect area;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/04/10 - Craig Allsop - Add OpenGL rendering.
|
||||
//
|
||||
|
||||
#include "../../platforms/windows/defines.h"
|
||||
#include "IDisplay.h"
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
//
|
||||
// Null display, stub all functions & allow no setup.
|
||||
//
|
||||
struct DisplayNull : IDisplayDirectX, IDisplayOpenGL
|
||||
{
|
||||
explicit DisplayNull(ISystemState*state) {}
|
||||
|
||||
int Setup(void* hwnd, int width, int height, int statusHeight, bool fullscreen) override { return !OK; }
|
||||
int Render() override { return OK; }
|
||||
int Present() override { return OK; }
|
||||
int Cleanup() override { return OK; }
|
||||
int SetOption(int flagOption, bool enabled) override { return OK; }
|
||||
int GetSurface(Pixel** pixels) override { return OK; }
|
||||
int GetRect(int rectOption, Rect* rect) override { return !OK; }
|
||||
int LockSurface() override { return OK; }
|
||||
int UnlockSurface() override { return OK; }
|
||||
void DebugDrawLine(float x1, float y1, float x2, float y2, Pixel color) override {}
|
||||
void DebugDrawBox(float x, float y, float w, float h, Pixel color, bool filled) override {}
|
||||
int RenderSignalLostMessage() override { return OK; }
|
||||
int RenderBox(float x, float y, float w, float h, Pixel color, bool filled) override { return OK; }
|
||||
int RenderText(const OpenGLFont* font, float x, float y, float size, const char* text) override { return OK; }
|
||||
void DebugDrawText(const OpenGLFont* font, float x, float y, float size, const char* text, Pixel color) override {};
|
||||
int LoadFont(const OpenGLFont** outFont, int bitmapRes, const OpenGLFontGlyph* glyphs, int start, int end) override { return OK; }
|
||||
int RenderStatusLine(char* statusText) override { return OK; }
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
#include "BuildConfig.h"
|
||||
#include "Event.h"
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
Event gEvents;
|
||||
Event::Event() :
|
||||
mClocks(0),
|
||||
mClocksPerCycleWithOC(DefaultClocksPerCycle * DefaultResolution),
|
||||
mClocksPerCycle(DefaultClocksPerCycle * DefaultResolution),
|
||||
mReqClocksPerCycle(DefaultClocksPerCycle),
|
||||
mReqOverclock(1),
|
||||
mOverclock(1),
|
||||
mResolution(DefaultResolution)
|
||||
{}
|
||||
|
||||
//
|
||||
// do complete reset
|
||||
//
|
||||
void Event::Reset()
|
||||
{
|
||||
mClocks = 0;
|
||||
mOverclock = 1;
|
||||
mReqOverclock = 1;
|
||||
mReqClocksPerCycle = DefaultClocksPerCycle;
|
||||
mClocksPerCycle = DefaultClocksPerCycle * mResolution;
|
||||
mClocksPerCycleWithOC = DefaultClocksPerCycle * mResolution;
|
||||
mEvents.clear();
|
||||
}
|
||||
|
||||
//
|
||||
// set current clocks per cycle
|
||||
//
|
||||
void Event::SetClocksPerCycle(Event::Clocks c)
|
||||
{
|
||||
assert(c > 0);
|
||||
mReqClocksPerCycle = c;
|
||||
}
|
||||
|
||||
//
|
||||
// set an overclock factor, 1..64
|
||||
//
|
||||
void Event::SetOverclock(size_t factor)
|
||||
{
|
||||
assert(factor > 0);
|
||||
mReqOverclock = factor;
|
||||
}
|
||||
|
||||
//
|
||||
// set the multiplier factor for a tick, default is 256.
|
||||
//
|
||||
void Event::SetResolution(size_t factor)
|
||||
{
|
||||
mResolution = factor;
|
||||
mClocksPerCycleWithOC = DefaultClocksPerCycle * mResolution;
|
||||
}
|
||||
|
||||
//
|
||||
// rebase with clocks = 0 and adjust all pending events
|
||||
//
|
||||
void Event::Rebase()
|
||||
{
|
||||
auto now = mClocks;
|
||||
|
||||
// reset to zero
|
||||
mClocks -= now;
|
||||
|
||||
// adjust pending events
|
||||
for (auto& e : mEvents)
|
||||
e.time -= now;
|
||||
|
||||
mOverclock = mReqOverclock;
|
||||
mClocksPerCycle = mReqClocksPerCycle * mResolution;
|
||||
mClocksPerCycleWithOC = mClocksPerCycle / mOverclock;
|
||||
}
|
||||
|
||||
//
|
||||
// queue function in dt from now
|
||||
//
|
||||
void Event::Queue(Clocks dtClocks, Func func, size_t id)
|
||||
{
|
||||
// insert with increasing order
|
||||
auto time = mClocks + dtClocks * mResolution;
|
||||
QueueInternal(time, func, id);
|
||||
}
|
||||
|
||||
//
|
||||
// Queue up func at dt in hz from now
|
||||
//
|
||||
void Event::Queue(Hz dtHz, Func func, size_t id)
|
||||
{
|
||||
// insert with increasing order
|
||||
auto dt = 14318180ll * mResolution / dtHz.value;
|
||||
assert(dt < SIZE_MAX);
|
||||
auto time = mClocks + (InternalClocks)dt;
|
||||
QueueInternal(time, func, id);
|
||||
}
|
||||
|
||||
//
|
||||
// Insert in order after existing elements
|
||||
//
|
||||
void Event::QueueInternal(size_t time, Func func, size_t id)
|
||||
{
|
||||
auto where = std::lower_bound(mEvents.begin(), mEvents.end(), time, [](auto& e, auto t) { return e.time <= t; });
|
||||
mEvents.insert(where, { id,time,func });
|
||||
}
|
||||
|
||||
//
|
||||
// Erase event by its id
|
||||
//
|
||||
void Event::Erase(size_t id)
|
||||
{
|
||||
if (id == 0) return;
|
||||
auto found = std::find_if(mEvents.begin(), mEvents.end(), [id](auto& e) { return e.id == id; });
|
||||
if (found != mEvents.end())
|
||||
mEvents.erase(found);
|
||||
}
|
||||
|
||||
void Event::EraseAll(size_t id)
|
||||
{
|
||||
if (id == 0) return;
|
||||
mEvents.erase(std::remove_if(mEvents.begin(), mEvents.end(),
|
||||
[id](const auto& event) { return event.id == id; }), mEvents.end());
|
||||
}
|
||||
|
||||
//
|
||||
// Reschedule 'id' from now, if id not found just queue.
|
||||
//
|
||||
void Event::ReQueue(Clocks dtClocks, Func func, size_t id)
|
||||
{
|
||||
if (id == 0) return;
|
||||
Erase(id);
|
||||
Queue(dtClocks, func, id);
|
||||
}
|
||||
|
||||
//
|
||||
// Tick clock forward by cycles processing any events it passed.
|
||||
// note: events may insert events.
|
||||
// note: < because we tick prior to advancing the clock, i.e. events
|
||||
// that occurred between t.before and up to but not including t.now.
|
||||
//
|
||||
void Event::Tick(Cycles cycles)
|
||||
{
|
||||
auto clocks = cycles * mClocksPerCycleWithOC;
|
||||
|
||||
// while events less than time + cycles
|
||||
while (!mEvents.empty() && mEvents[0].time < mClocks + clocks)
|
||||
{
|
||||
auto dt = mEvents[0].time - mClocks;
|
||||
|
||||
// advance clock so reentry calls have correct state
|
||||
mClocks += dt;
|
||||
|
||||
// reduce remaining by same amount
|
||||
clocks -= dt;
|
||||
|
||||
// get function, call after erasing
|
||||
auto func = mEvents[0].func;
|
||||
mEvents.erase(mEvents.begin());
|
||||
func();
|
||||
}
|
||||
|
||||
// advance clock remaining clocks
|
||||
mClocks += clocks;
|
||||
}
|
||||
|
||||
//
|
||||
// return the current clocks
|
||||
//
|
||||
Event::Clocks Event::GetClocks() const
|
||||
{
|
||||
return mClocks / mResolution;
|
||||
}
|
||||
|
||||
//
|
||||
// return the number of events queued
|
||||
//
|
||||
size_t Event::GetSize() const
|
||||
{
|
||||
return mEvents.size();
|
||||
}
|
||||
|
||||
#if _DEBUG
|
||||
//
|
||||
// read only access for debugging
|
||||
//
|
||||
const Event::EventItem& Event::operator[](size_t i) const
|
||||
{
|
||||
return mEvents[i];
|
||||
}
|
||||
|
||||
const Event::EventsVector& Event::Events() const
|
||||
{
|
||||
return mEvents;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_DEBUG_TESTS
|
||||
//
|
||||
// testing
|
||||
//
|
||||
bool TestEvents()
|
||||
{
|
||||
struct State { int c = 0; Event e; State() { e.SetResolution(1); } };
|
||||
|
||||
// helpers
|
||||
auto nop = []() {}; // empty func
|
||||
auto snop = [](State&) {}; // do nothing with state
|
||||
auto c = [](State& s, auto func) { return [&]() { s.c++; func(); }; }; // count calls
|
||||
auto f = [](auto ...func) { return [=](State& s) { (func(s), ...); }; }; // run sequence of funcs
|
||||
auto t = [](auto check, auto func) { State s; func(s); return check(s); }; // run func & check
|
||||
auto isSorted = [](auto& v, auto q) { for (auto f = v.begin(), i = v.begin(); ++i != v.end(); ++f) if (q(i) < q(f)) return false; return true; };
|
||||
|
||||
// operations
|
||||
auto insert1 = [=](State& s) { s.e.Queue(125, c(s, nop)); };
|
||||
auto insert2 = [=](State& s) { s.e.Queue(128, c(s, nop)); };
|
||||
auto insert3 = [=](State& s) { s.e.Queue(133, c(s, nop)); };
|
||||
auto insert4 = [=](State& s) { s.e.Queue(135, c(s, nop)); };
|
||||
auto insert5 = [=](State& s) { s.e.Queue(150, c(s, nop)); };
|
||||
auto tick = [](int n) { return [n](State& s) { s.e.Tick(n); }; };
|
||||
auto reset = [=]() { return [=](State& s) { s.e.Rebase(); }; };
|
||||
auto insertBunch = f(insert1, insert2, insert3);
|
||||
auto insertOutOfOrder1 = f(insert2, insert1, insert3);
|
||||
auto insertOutOfOrder2 = f(insert3, insert2, insert1);
|
||||
auto resetInCall = [](State& s) { return [&]() { s.e.Rebase(); }; };
|
||||
auto insertReset = [=](State& s) { s.e.Queue(127, resetInCall(s)); };
|
||||
auto insertInCall = [=](State& s) { return [&]() { s.e.Queue(1, c(s, nop)); }; }; // insert +1 after 133
|
||||
auto insertAdd = [=](State& s) { s.e.Queue(133, insertInCall(s)); };
|
||||
auto insertTagged = [=](int n) { return [=](State& s) { s.e.Queue(130, c(s, nop), n); }; };
|
||||
auto removeItem = [](int n) { return [n](State& s) { s.e.Erase(n); }; };
|
||||
|
||||
// evaluations
|
||||
auto getClocks = [](State& s) { return s.e.GetClocks(); };
|
||||
auto getSize = [](State& s) { return s.e.GetSize(); };
|
||||
auto getCalls = [](State& s) { return s.c; };
|
||||
auto getTime = [](Event::EventsVector::const_iterator& it) { return it->time; };
|
||||
auto isSortedTime = [=](auto& v) { return isSorted(v, getTime); };
|
||||
auto isOrdered = [=](State& s) { return isSortedTime(s.e.Events()); };
|
||||
auto getTimeFirst = [=](State& s) { return getTime(s.e.Events().begin()); };
|
||||
auto isPastDue = [=](State& s) { return getTimeFirst(s) < getClocks(s); };
|
||||
|
||||
// queries
|
||||
auto clocks = [=](auto func) { return t(getClocks, func); };
|
||||
auto size = [=](auto func) { return t(getSize, func); };
|
||||
auto calls = [=](auto func) { return t(getCalls, func); };
|
||||
auto ordered = [=](auto func) { return t(isOrdered, func); };
|
||||
auto firstTime = [=](auto func) { return t(getTimeFirst, func); };
|
||||
auto past = [=](auto func) { return t(isPastDue, func); };
|
||||
|
||||
// test sequences (^ = clock pos)
|
||||
auto test5 = f(insertBunch, tick(5)); // tick(5) ^125,128,133
|
||||
auto test8 = f(insertBunch, tick(8)); // tick(8) 125,^128,133
|
||||
auto test9 = f(insertBunch, tick(9)); // tick(9) 125,128,133^
|
||||
auto test83 = f(test8, tick(3)); // tick(8,3) 125^,128,133^
|
||||
auto testReset1 = f(insertReset, insertBunch, tick(8)); // ^125,127(r),128,133 + tick(8) -> ^1,134
|
||||
auto testReset2 = f(testReset1, tick(3)); // ^1,134 + tick(3) -> ^
|
||||
auto testRemove = f(insertTagged(3), insertOutOfOrder1, removeItem(3));
|
||||
auto testRemoved = f(testRemove, tick(10));
|
||||
auto testAdded = f(insert1, insertAdd, insert4, tick(9)); //^125,133,135 + tick(9) -> 125,133,a134,135^
|
||||
auto testAdd2 = f(insert5, testAdded); //^125,133,135,150 + tick(9) -> 125,133,a134,135^,150 -> 150
|
||||
auto testDups = f(insertOutOfOrder1, insertOutOfOrder2);
|
||||
auto testAdd3 = f(insert1, tick(1), insert2, tick(2), insert3, tick(9), insert4); //^125,144,181 ..-> ^327
|
||||
|
||||
// tests
|
||||
assert(clocks(snop) == 0); // clocks begins at zero
|
||||
assert(size(snop) == 0); // queue initialized at zero
|
||||
assert(calls(snop) == 0); // calls initialized at zero
|
||||
assert(size(insertBunch) == 3); // test queuing 3 has size = 3
|
||||
assert(ordered(insertBunch)); // ensure in order insert is ordered
|
||||
assert(ordered(insertOutOfOrder1)); // ensure out of order insert is ordered
|
||||
assert(ordered(insertOutOfOrder2)); // ensure out of order insert is ordered
|
||||
assert(ordered(testRemove)); // ensure in order after removal
|
||||
assert(calls(testRemoved) == 3); // 4-1 then 3 called
|
||||
assert(size(testRemoved) == 0); // advanced 10 cycles all processed
|
||||
assert(clocks(test5) == 80); // advance 5 cycles = 128 clocks
|
||||
assert(size(test8) == 2); // advance 8 cycles = 128 clocks = process 1 event leaves 1
|
||||
assert(calls(test8) == 1); // advance 8 cycles = 128 clocks = process 1 event calls 2
|
||||
assert(size(test9) == 0); // advance 8 cycles = 128 clocks, leaves 0
|
||||
assert(calls(test9) == 3); // advance 9 cycles = 144 clocks calls 3
|
||||
assert(clocks(test9) == 144); // advance 9 cycles = 144 clocks
|
||||
assert(size(test83) == 0); // advance 8,3 cycles = 176 clocks, leaves 0
|
||||
assert(calls(test83) == 3); // advance 8,3 cycles = 176 clocks, calls 3
|
||||
assert(clocks(testReset1) == 1); // advance 128 clocks with reset at 127 = 1
|
||||
assert(calls(testReset1) == 1); // advance 128 clocks with reset at 127, 2 calls
|
||||
assert(size(testReset1) == 2); // advance 128 clocks with reset at 127, 1 remaining
|
||||
assert(firstTime(testReset1) == 1); // after reset at 127 first element's time should be 1
|
||||
assert(clocks(testReset2) == 49); // advance 176 clocks with reset at 127 = 1+48
|
||||
assert(calls(testReset2) == 3); // advance 176 clocks with reset at 127, 3 calls
|
||||
assert(size(testReset2) == 0); // advance 176 clocks with reset at 127, 0 remaining
|
||||
assert(ordered(testDups)); // ensure duplicates are ordered
|
||||
assert(size(testDups) == 6); // ensure duplicates are all inserted
|
||||
assert(calls(testAdded) == 3); // ensure added during tick gets called
|
||||
assert(size(testAdded) == 0); // ensure added during tick none left
|
||||
assert(calls(testAdd2) == 3); // ensure added during tick gets called
|
||||
assert(size(testAdd2) == 1); // ensure added during tick one remains
|
||||
assert(firstTime(testAdd2) == 150); // ensure last remains is the 4th
|
||||
assert(past(testAdd2) == false); // ensure next element is not due
|
||||
assert(size(testAdd3) == 1); // multiple ticks/queues one left
|
||||
assert(calls(testAdd3) == 3); // multiple ticks/queues called 3
|
||||
assert(past(testAdd3) == false); // last is not already due
|
||||
assert(firstTime(testAdd3) == 327); // ensure last is 327 (t192+q135)
|
||||
return 0;
|
||||
}
|
||||
static bool gTestEvents = TestEvents();
|
||||
#endif // USE_DEBUG_TESTS
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
enum EventTag
|
||||
{
|
||||
ET_TIMER = 1,
|
||||
ET_AUDIO = 2,
|
||||
ET_GIME_HSYNC_FALL, ET_GIME_HSYNC_RISE, ET_GIME_HSYNC_IRQ,
|
||||
ET_GIME_VBLANK, ET_GIME_VSYNC_RISE, ET_GIME_TIMER_RESET,
|
||||
ET_GIME_TIMER_DECREMENT, ET_GIME_TIMER_IRQ,
|
||||
};
|
||||
|
||||
//
|
||||
// event queue
|
||||
//
|
||||
// requires rebase() call to reset clocks to zero at a convenient point in time
|
||||
// such as new frame, to avoid integer wrap.
|
||||
//
|
||||
// defaults to multiple of 256 clock ticks, for accurate hz/overclocking, but not essential.
|
||||
//
|
||||
// id is optional, only required for deletion/reschedule of events.
|
||||
//
|
||||
struct Event
|
||||
{
|
||||
using Clocks = size_t;
|
||||
using Cycles = size_t;
|
||||
struct Hz { size_t value; };
|
||||
using Func = std::function<void()>;
|
||||
|
||||
Event();
|
||||
|
||||
//
|
||||
// rebase with clocks = 0
|
||||
//
|
||||
void Rebase();
|
||||
|
||||
//
|
||||
// Queue up func at dt from now
|
||||
//
|
||||
void Queue(Clocks dtClocks, Func func, size_t id = 0);
|
||||
|
||||
//
|
||||
// Queue up func at dt in hz from now
|
||||
//
|
||||
void Queue(Hz dtHz, Func func, size_t id = 0);
|
||||
|
||||
//
|
||||
// Reschedule 'id' from now, if id not found just queue.
|
||||
//
|
||||
void ReQueue(Clocks dtClocks, Func func, size_t id);
|
||||
|
||||
//
|
||||
// Erase event by its id
|
||||
//
|
||||
void Erase(size_t id);
|
||||
// Cancel every pending callback owned by a tag (including delayed IRQs).
|
||||
void EraseAll(size_t id);
|
||||
|
||||
//
|
||||
// tick clock forward by cycles
|
||||
//
|
||||
void Tick(Cycles cycles);
|
||||
|
||||
//
|
||||
// return the current clock time
|
||||
//
|
||||
Clocks GetClocks() const;
|
||||
|
||||
//
|
||||
// return the number of events queued
|
||||
//
|
||||
size_t GetSize() const;
|
||||
|
||||
//
|
||||
// set current clocks per cycle. default=16
|
||||
//
|
||||
void SetClocksPerCycle(Clocks c);
|
||||
|
||||
//
|
||||
// set an overclock factor, 1..64 (clock divider)
|
||||
//
|
||||
void SetOverclock(size_t factor);
|
||||
|
||||
//
|
||||
// set the resolution (clock multiplier) for a tick, default is 256.
|
||||
// only required to be set once before using events.
|
||||
//
|
||||
void SetResolution(size_t factor);
|
||||
|
||||
//
|
||||
// do complete reset
|
||||
//
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
|
||||
template <typename T> using Vector = std::vector<T>;
|
||||
|
||||
struct EventItem
|
||||
{
|
||||
size_t id;
|
||||
Clocks time;
|
||||
Func func;
|
||||
};
|
||||
|
||||
using EventsVector = Vector<EventItem>;
|
||||
|
||||
// cycles = clocks/16
|
||||
static constexpr size_t DefaultClocksPerCycle = 16;
|
||||
static constexpr size_t DefaultResolution = 256;
|
||||
|
||||
// internally use multiplier of 256 to support overclocking
|
||||
using InternalClocks = size_t;
|
||||
|
||||
EventsVector mEvents; // events list
|
||||
InternalClocks mClocks; // current clock position
|
||||
InternalClocks mClocksPerCycleWithOC; // clocks per cycle including overclock
|
||||
InternalClocks mClocksPerCycle; // clocks per cycle
|
||||
InternalClocks mReqClocksPerCycle; // next clocks per cycle
|
||||
size_t mReqOverclock; // next overclock
|
||||
size_t mOverclock; // current overclock multiplier
|
||||
size_t mResolution; // tick resolution
|
||||
|
||||
void QueueInternal(InternalClocks dt, Func func, size_t id);
|
||||
|
||||
#ifdef _DEBUG
|
||||
friend bool TestEvents();
|
||||
|
||||
//
|
||||
// read only access for debugging
|
||||
//
|
||||
const EventItem& operator[](size_t i) const;
|
||||
const EventsVector& Events() const;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
extern Event gEvents;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
namespace VCC::Mac {
|
||||
// USE_NEWTIMING baseline: 263 scanlines, 912 master clocks each. Presentation
|
||||
// may skip frames, but neither presentation nor host timers change guest clocks.
|
||||
constexpr std::uint64_t masterClockHz = 14318180;
|
||||
constexpr std::uint64_t clocksPerFrame = 263 * 912;
|
||||
constexpr auto frameInterval = std::chrono::nanoseconds(clocksPerFrame * 1000000000ull / masterClockHz);
|
||||
// A 100 ms reserve tolerates brief owner-queue stalls without changing guest clocks.
|
||||
constexpr std::size_t audioTargetSamples = 4410;
|
||||
class FramePacer {
|
||||
public:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
void reset() { armed = false; }
|
||||
bool ready(Clock::time_point now) {
|
||||
if (armed && now < next) return false;
|
||||
// A late wake starts a new deadline; never replay seconds of stale frames.
|
||||
if (!armed || now - next > frameInterval * 4) next = now;
|
||||
armed = true; next += frameInterval; return true;
|
||||
}
|
||||
private:
|
||||
bool armed = false;
|
||||
Clock::time_point next{};
|
||||
};
|
||||
class AudioProgress {
|
||||
public:
|
||||
using Clock = std::chrono::steady_clock;
|
||||
void reset() { armed = false; }
|
||||
bool stalled(Clock::time_point now, std::uint64_t consumed) {
|
||||
if (!armed || consumed != previous) { armed = true; previous = consumed; changed = now; }
|
||||
return now - changed >= std::chrono::seconds(1);
|
||||
}
|
||||
private:
|
||||
bool armed = false;
|
||||
std::uint64_t previous = 0;
|
||||
Clock::time_point changed{};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "FrameRunner.h"
|
||||
#include "tcc1014graphics.h"
|
||||
#include "CpuHost.h"
|
||||
#include <stdexcept>
|
||||
|
||||
VCC::FrameResult VCC::RunFrame(GimeGpu& gpu, int (*execute)(int), std::size_t cycleBudget) {
|
||||
#if USE_NEWTIMING
|
||||
if (!execute) throw std::invalid_argument("Frame execution requires a CPU");
|
||||
std::size_t cycles = 0;
|
||||
for (;;) {
|
||||
if (gpu.FrameFinished()) return {FrameStop::Complete, cycles};
|
||||
if (CpuDebugger().IsHalted()) return {FrameStop::Halted, cycles};
|
||||
if (cycles >= cycleBudget) return {FrameStop::Budget, cycles};
|
||||
const int request = cycleBudget - cycles < 2 ? 1 : 2;
|
||||
const auto elapsed = static_cast<long long>(request) - execute(request);
|
||||
if (elapsed <= 0)
|
||||
return {CpuDebugger().IsHalted() ? FrameStop::Halted : FrameStop::Stalled, cycles};
|
||||
cycles += static_cast<std::size_t>(elapsed);
|
||||
}
|
||||
#else
|
||||
throw std::logic_error("RunFrame requires the event-based timing engine");
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
struct GimeGpu;
|
||||
namespace VCC {
|
||||
enum class FrameStop { Complete, Halted, Budget, Stalled };
|
||||
struct FrameResult {
|
||||
FrameStop reason;
|
||||
std::size_t cycles;
|
||||
};
|
||||
// Execute synchronously until a frame, debugger stop, or safety budget. A
|
||||
// partial frame can be resumed. The final instruction may exceed the budget.
|
||||
// No wall-clock pacing, screen locking, or audio output occurs here.
|
||||
FrameResult RunFrame(GimeGpu& gpu, int (*execute)(int), std::size_t cycleBudget);
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/04/10 - Craig Allsop - Add OpenGL rendering.
|
||||
//
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
typedef std::uint32_t uint32_t;
|
||||
typedef std::uint8_t uint8_t;
|
||||
|
||||
//
|
||||
// A single pixel 32bit, alpha is unused
|
||||
//
|
||||
union Pixel
|
||||
{
|
||||
uint32_t pixel; // ARGB
|
||||
struct
|
||||
{
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
uint8_t a;
|
||||
};
|
||||
|
||||
Pixel() = default;
|
||||
explicit Pixel(uint32_t p) : pixel(p) {}
|
||||
Pixel(uint8_t r, uint8_t g, uint8_t b) : a(255), r(r), g(g), b(b) {}
|
||||
bool operator==(const Pixel& o) const { return o.pixel == pixel; }
|
||||
bool operator!=(const Pixel& o) const { return !operator==(o); }
|
||||
};
|
||||
|
||||
//
|
||||
// Just standard colors
|
||||
//
|
||||
static Pixel ColorWhite(255, 255, 255);
|
||||
static Pixel ColorRed(255, 0, 0);
|
||||
static Pixel ColorGreen(0, 255, 0);
|
||||
static Pixel ColorBlue(0, 0, 255);
|
||||
static Pixel ColorYellow(255, 255, 0);
|
||||
static Pixel ColorBlack(0, 0, 0);
|
||||
|
||||
//
|
||||
// Interface for display output
|
||||
//
|
||||
// return values:
|
||||
// 0 = no error
|
||||
// n = see ERR_* errors in implemenation
|
||||
//
|
||||
struct IDisplay
|
||||
{
|
||||
enum
|
||||
{
|
||||
OK, // no error
|
||||
};
|
||||
|
||||
struct Rect
|
||||
{
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
enum // rectOption
|
||||
{
|
||||
OPT_RECT_DISPLAY = 1, // display surface rectangle
|
||||
OPT_RECT_RENDER, // entire render output rectangle
|
||||
OPT_RECT_SURFACE, // get rectangle of surface
|
||||
};
|
||||
|
||||
enum // flagOption
|
||||
{
|
||||
OPT_FLAG_ASPECT = 1, // force aspect ratio (default) ELSE stretch display
|
||||
OPT_FLAG_NTSC, // use 50hz aspect ELSE 60hz aspect (default)
|
||||
OPT_FLAG_RESIZEABLE,
|
||||
};
|
||||
|
||||
virtual ~IDisplay() = default;
|
||||
|
||||
// setup display:
|
||||
// width = full window width
|
||||
// height = full window height not including status bar
|
||||
// statusHeight = height to leave for status bar
|
||||
virtual int Setup(void* hwnd, int width, int height, int statusHeight, bool fullscreen) = 0;
|
||||
|
||||
//
|
||||
// render the surface to the screen
|
||||
//
|
||||
virtual int Render() = 0;
|
||||
|
||||
//
|
||||
// present buffer to the screen
|
||||
//
|
||||
virtual int Present() = 0;
|
||||
|
||||
//
|
||||
// undo entire setup and close display
|
||||
//
|
||||
virtual int Cleanup() = 0;
|
||||
|
||||
//
|
||||
// configure boolean option
|
||||
//
|
||||
virtual int SetOption(int flagOption, bool enabled) = 0;
|
||||
|
||||
//
|
||||
// return the virtual surface (RGBA format) to draw into
|
||||
//
|
||||
virtual int GetSurface(Pixel** pixels) = 0;
|
||||
|
||||
//
|
||||
// returns the queried rectangle
|
||||
//
|
||||
virtual int GetRect(int rectOption, Rect* area) = 0;
|
||||
|
||||
//
|
||||
// draw line/box in surface coordinates
|
||||
//
|
||||
virtual void DebugDrawLine(float x1, float y1, float x2, float y2, Pixel color) = 0;
|
||||
virtual void DebugDrawBox(float x, float y, float w, float h, Pixel color, bool filled) = 0;
|
||||
|
||||
//
|
||||
// for access to GetSurface
|
||||
//
|
||||
virtual int LockSurface() = 0;
|
||||
virtual int UnlockSurface() = 0;
|
||||
};
|
||||
|
||||
struct OpenGLFont;
|
||||
struct OpenGLFontGlyph;
|
||||
|
||||
struct IDisplayOpenGL : IDisplay
|
||||
{
|
||||
//
|
||||
// render a box on the screen
|
||||
//
|
||||
virtual int RenderBox(float x, float y, float w, float h, Pixel color, bool filled) = 0;
|
||||
|
||||
//
|
||||
// render the text on screen for full screen
|
||||
//
|
||||
virtual int RenderText(const OpenGLFont* font, float x, float y, float size, const char* text) = 0;
|
||||
|
||||
//
|
||||
// render debug text for current frame
|
||||
//
|
||||
virtual void DebugDrawText(const OpenGLFont* font, float x, float y, float size, const char* text, Pixel color) = 0;
|
||||
|
||||
//
|
||||
// create a new font from bitmapRes window resource
|
||||
// out: outFont or null
|
||||
//
|
||||
virtual int LoadFont(const OpenGLFont** outFont, int bitmapRes, const OpenGLFontGlyph* glyphs, int start, int end) = 0;
|
||||
|
||||
int UnlockSurface() override { return OK; }
|
||||
};
|
||||
|
||||
struct IDisplayDirectX : IDisplay
|
||||
{
|
||||
//
|
||||
// render the signal lost message for directx
|
||||
//
|
||||
virtual int RenderSignalLostMessage() = 0;
|
||||
|
||||
//
|
||||
// render the status line on screen for directx
|
||||
//
|
||||
virtual int RenderStatusLine(char* statusText) = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
// Copyright 2015 by Joseph Forgion
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with VCC. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// 2025/04/10 - Craig Allsop - Add OpenGL rendering.
|
||||
//
|
||||
|
||||
#include "IDisplay.h"
|
||||
|
||||
//
|
||||
// NOTE: USE_DEBUG_LINES must be enabled to see debug lines.
|
||||
//
|
||||
|
||||
void DebugDrawBox(float x, float y, float w, float h, VCC::Pixel color, bool filled);
|
||||
void DebugDrawLine(float x, float y, float x2, float y2, VCC::Pixel color);
|
||||
void DebugPrint(float x, float y, float size, const char* str, VCC::Pixel color);
|
||||
|
||||
inline void DebugDrawBox(int x, int y, int w, int h, VCC::Pixel color, bool filled)
|
||||
{
|
||||
DebugDrawBox((float)x, (float)y, (float)w, (float)h, color, filled);
|
||||
}
|
||||
|
||||
inline void DebugDrawLine(int x1, int y1, int x2, int y2, VCC::Pixel color)
|
||||
{
|
||||
DebugDrawLine((float)x1, (float)y1, (float)x2, (float)y2, color);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
// Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
// Enumerations for interrupts and their sources
|
||||
|
||||
// CPU interrupts (counting from 1 because legacy)
|
||||
// Pakinterface uses INT_NONE to clear cart IRQ
|
||||
enum Interrupt {
|
||||
INT_IRQ = 1,
|
||||
INT_FIRQ,
|
||||
INT_NMI,
|
||||
INT_CART
|
||||
};
|
||||
|
||||
// Interrupt sources keep track of their own state.
|
||||
// NMI is its own source and always uses this.
|
||||
enum InterruptSource {
|
||||
IS_NMI = 0,
|
||||
IS_PIA0_HSYNC,
|
||||
IS_PIA0_VSYNC,
|
||||
IS_PIA1_CD,
|
||||
IS_PIA1_CART,
|
||||
IS_GIME,
|
||||
IS_MAX
|
||||
};
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
namespace VCC::Mac {
|
||||
// PIA comparator and ramp behavior retained from joystickinput.cpp,
|
||||
// copyright 2015 Joseph Forgione. Host inputs are complete 14-bit snapshots.
|
||||
struct JoystickPort {
|
||||
unsigned x = 8191, y = 8191;
|
||||
unsigned buttons = 0, mode = 0; // standard, software, Tandy, CoCoMax
|
||||
};
|
||||
class JoystickState {
|
||||
bool ramp = false;
|
||||
unsigned target = 0;
|
||||
public:
|
||||
std::array<JoystickPort, 2> ports{}; // right, left
|
||||
void release() {
|
||||
for (auto& port : ports) { port.x = port.y = 8191; port.buttons = 0; }
|
||||
ramp = false; target = 0;
|
||||
}
|
||||
void set(unsigned port, unsigned x, unsigned y, unsigned buttons, unsigned mode) {
|
||||
if (port >= ports.size()) return;
|
||||
ports[port] = {std::min(x, 16383u), std::min(y, 16383u), buttons & 3u, std::min(mode, 3u)};
|
||||
}
|
||||
void start(bool tandy, unsigned value, unsigned axis, int& clock) {
|
||||
const auto mode = ports[(axis >> 1) & 1].mode;
|
||||
if ((tandy && mode == 2 && value == 2) || (!tandy && mode == 3 && value == 0)) {
|
||||
ramp = true; target = 0; clock = 0;
|
||||
}
|
||||
}
|
||||
unsigned char scan(unsigned char rows, unsigned axis, unsigned dac, int clock, bool fast) {
|
||||
const auto& port = ports[(axis >> 1) & 1];
|
||||
const auto value = (axis & 1) ? port.y : port.x;
|
||||
if (port.mode > 1) {
|
||||
if (ramp && target == 0) {
|
||||
target = port.mode == 2 ? std::min(1200u + ((value * 37) >> 6), 10950u)
|
||||
: std::min(800u + ((value * 21) >> 6), 14000u);
|
||||
if (port.mode == 2 && !fast) target /= 2;
|
||||
}
|
||||
if (clock > int(target)) { rows |= 0x80; ramp = false; }
|
||||
} else if (value != 0 && value >= dac) rows |= 0x80;
|
||||
if (ports[0].buttons & 1) rows &= ~1;
|
||||
if (ports[1].buttons & 1) rows &= ~2;
|
||||
if (ports[0].buttons & 2) rows &= ~4;
|
||||
if (ports[1].buttons & 2) rows &= ~8;
|
||||
return rows;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
namespace VCC::Mac {
|
||||
// CoCo matrix positions from keyboardLayout.cpp: seven rows, eight columns.
|
||||
// Bit (row * 8 + column) is held; PIA column selection and row output are active low.
|
||||
constexpr std::uint64_t KeyboardMask = (std::uint64_t{1} << 56) - 1;
|
||||
inline unsigned char ScanKeyboard(std::uint64_t keys, unsigned char columns) {
|
||||
unsigned char rows = 0;
|
||||
for (unsigned row = 0; row < 7; ++row)
|
||||
if ((keys >> (row * 8)) & static_cast<unsigned char>(~columns)) rows |= 1 << row;
|
||||
return static_cast<unsigned char>(~rows) & 0x7f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Interrupts.h"
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
struct CPUState
|
||||
{
|
||||
//
|
||||
unsigned char DP = 0;
|
||||
unsigned char CC = 0;
|
||||
unsigned char MD = 0;
|
||||
//
|
||||
unsigned char A = 0;
|
||||
unsigned char B = 0;
|
||||
unsigned char E = 0;
|
||||
unsigned char F = 0;
|
||||
unsigned short X = 0;
|
||||
unsigned short Y = 0;
|
||||
unsigned short U = 0;
|
||||
unsigned short S = 0;
|
||||
unsigned short PC = 0;
|
||||
unsigned short V = 0;
|
||||
//
|
||||
bool IsNative6309 = false;
|
||||
bool phyAddr = false; // Decode using block relative addressing
|
||||
unsigned short block = 0; // Physical address = PC + block * 0x2000
|
||||
};
|
||||
|
||||
// Trace Events
|
||||
enum class TraceEvent
|
||||
{
|
||||
Instruction, // Instruction Executed
|
||||
IRQStart, // Beginning of Interrupt Traces
|
||||
IRQRequested, // Interrupt is being asserted
|
||||
IRQMasked, // CPU acknowledged the interrupt, but it was masked, so it will be ignored
|
||||
IRQServicing, // CPU acknowledged the interrupt, and will push state onto stack
|
||||
IRQExecuting, // CPU is now passing control to the interrupt vector
|
||||
IRQEnd, // End of Interrupt Traces
|
||||
ScreenStart, // Beginning of Screen Traces
|
||||
ScreenVSYNCLow, // Screen vertical synchronization start
|
||||
ScreenVSYNCHigh, // Screen vertical synchronization end
|
||||
ScreenHSYNCLow, // Screen HSYNC synchronization start
|
||||
ScreenHSYNCHigh, // Screen HSYNC syncrhonization end
|
||||
ScreenReg,
|
||||
ScreenTopBorder, // Screen is drawing - top border
|
||||
ScreenRender, // Screen is drawing - active region
|
||||
ScreenBottomBorder, // Screen is drawing - bottom border,
|
||||
ScreenEnd, // End of Screen Traces
|
||||
EmulatorCycle, // Tracing Emulation Cycles
|
||||
};
|
||||
|
||||
// CPU Execution Tracing
|
||||
struct CPUTrace
|
||||
{
|
||||
TraceEvent event = TraceEvent::Instruction; // Trace Event type
|
||||
int frame = 0; // Frame being rendered
|
||||
int line = 0; // Line being rendered
|
||||
long cycleTime = 0; // Time since Trace start in CPU cycles
|
||||
size_t clock = 0;
|
||||
size_t frameStart = 0;
|
||||
unsigned short pc = 0; // Program Counter at time of event
|
||||
std::vector<unsigned char> bytes; // Op code bytes
|
||||
std::string instruction; // Instruction
|
||||
std::string operand; // Instruction Operand
|
||||
CPUState startState; // CPU State before instruction
|
||||
CPUState endState; // CPU State after instruction
|
||||
int execCycles = 0; // Number of cycles indicated by emulator
|
||||
int decodeCycles = 0; // Number of cycles from OpDecoder
|
||||
int emulationState = 0; // State switch in emulation cycles
|
||||
std::vector<double> emulator; // Emulation Tracing
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// make nth bit 0-7
|
||||
constexpr uint8_t Bit(uint8_t n) { return 1 << n; }
|
||||
|
||||
// make mask of nth bit 0-7
|
||||
constexpr uint8_t BitMask(uint8_t n) { return ~Bit(n); }
|
||||
|
||||
extern void (*CPUInit)();
|
||||
extern int (*CPUExec)(int);
|
||||
extern void (*CPUReset)();
|
||||
extern void (*CPUAssertInterupt)(InterruptSource, Interrupt);
|
||||
extern void (*CPUDeAssertInterupt)(InterruptSource, Interrupt);
|
||||
extern void (*CPUForcePC)(unsigned short);
|
||||
extern void (*CPUSetBreakpoints)(const std::vector<unsigned short>&);
|
||||
extern void (*CPUSetTraceTriggers)(const std::vector<unsigned short>&);
|
||||
extern VCC::CPUState(*CPUGetState)();
|
||||
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "MachineHost.h"
|
||||
#include "VideoRegisters.h"
|
||||
#include <stdexcept>
|
||||
#ifdef _WIN32
|
||||
#include "../../platforms/windows/defines.h"
|
||||
#include "../../platforms/windows/config.h"
|
||||
#include "tcc1014graphics.h"
|
||||
#include "../../platforms/windows/pakinterface.h"
|
||||
#include "../../platforms/windows/coco3.h"
|
||||
#include "../../platforms/windows/Vcc.h"
|
||||
#include "../../platforms/windows/keyboard.h"
|
||||
#include "../../platforms/windows/joystickinput.h"
|
||||
#include "../../platforms/windows/Cassette.h"
|
||||
#include <vcc/util/FileOps.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
void CaptureBit(unsigned char);
|
||||
#endif
|
||||
|
||||
namespace VCC {
|
||||
namespace {
|
||||
#ifdef _WIN32
|
||||
class WindowsMachineHost final : public MachineHost {
|
||||
public:
|
||||
bool LoadInternalRom(unsigned char* destination, std::size_t capacity) override {
|
||||
char path[MAX_PATH] = {};
|
||||
GetExtRomPath(path);
|
||||
if (!*path) {
|
||||
GetModuleFileName(nullptr, path, MAX_PATH);
|
||||
PathRemoveFileSpec(path);
|
||||
const auto used = std::strlen(path);
|
||||
std::strncat(path, "coco3.rom", MAX_PATH - used - 1);
|
||||
}
|
||||
FILE* file = std::fopen(path, "rb");
|
||||
const auto count = file ? std::fread(destination, 1, capacity, file) : 0;
|
||||
const bool ok = file && count && !std::ferror(file);
|
||||
if (file) std::fclose(file);
|
||||
if (!ok) MessageBox(nullptr, "coco3.rom load failed\nCheck ROM path.", "Error",
|
||||
MB_TASKMODAL | MB_TOPMOST | MB_SETFOREGROUND);
|
||||
return ok;
|
||||
}
|
||||
unsigned char CartridgeRead(unsigned short address) override { return PackMem8Read(address); }
|
||||
unsigned char CartridgePortRead(unsigned char port) override { return PakReadPort(port); }
|
||||
void CartridgePortWrite(unsigned char port, unsigned char value) override { PakWritePort(port, value); }
|
||||
unsigned short CartridgeAudio() override { return PackAudioSample(); }
|
||||
void VideoWrite(VideoRegister reg, unsigned int value, unsigned char index) override {
|
||||
ApplyVideoRegister(gGimeGpu, reg, value, index);
|
||||
}
|
||||
void TimerWrite(TimerRegister reg, unsigned int value) override {
|
||||
switch (reg) {
|
||||
case TimerRegister::ClockSource: SetTimerClockRate(value); break;
|
||||
case TimerRegister::Restart: RestartInterruptTimer(value); break;
|
||||
case TimerRegister::Reload: SetMasterTickCounter(value); break;
|
||||
}
|
||||
}
|
||||
void SetTurbo(unsigned char value) override { SetTurboMode(value); }
|
||||
void SetCpuSpeed(unsigned char value) override { SetCPUMultiplyerFlag(value); }
|
||||
CPUState CpuState() override { return CPUGetState(); }
|
||||
void AssertInterrupt(InterruptSource source, Interrupt interrupt) override { CPUAssertInterupt(source, interrupt); }
|
||||
void ClearInterrupt(InterruptSource source, Interrupt interrupt) override { CPUDeAssertInterupt(source, interrupt); }
|
||||
unsigned char KeyboardScan(unsigned char columns) override { return vccKeyboardGetScan(columns); }
|
||||
void JoystickStart(bool tandy, unsigned char value) override {
|
||||
if (tandy) vccJoystickStartTandy(value); else vccJoystickStartCCMax();
|
||||
}
|
||||
bool TapeFastLoad() override { return GetTapePlaybackFastLoad(); }
|
||||
unsigned char TapeInputBit() override { return CassInBitStream(); }
|
||||
void TapeMotor(unsigned char value) override { Motor(value); }
|
||||
void PrinterBit(unsigned char value) override { CaptureBit(value); }
|
||||
};
|
||||
WindowsMachineHost windowsHost;
|
||||
MachineHost* activeHost = &windowsHost;
|
||||
#else
|
||||
MachineHost* activeHost = nullptr;
|
||||
#endif
|
||||
}
|
||||
MachineHost& Machine() {
|
||||
if (!activeHost) throw std::logic_error("Install a MachineHost before using the machine core");
|
||||
return *activeHost;
|
||||
}
|
||||
void SetMachineHost(MachineHost* host) {
|
||||
#ifdef _WIN32
|
||||
activeHost = host ? host : &windowsHost;
|
||||
#else
|
||||
activeHost = host;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "MachineDefs.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace VCC {
|
||||
enum class VideoRegister {
|
||||
RamMask, Bank, Compatibility, Mode, Resolution, Border, Scroll,
|
||||
Offset, HorizontalOffset, Palette, VdgMode, VdgMode2, VdgOffset
|
||||
};
|
||||
enum class TimerRegister { ClockSource, Restart, Reload };
|
||||
|
||||
// Synchronous connections to components outside the extracted register core.
|
||||
// Install on the emulation thread before initialization; retain until detached.
|
||||
// All methods are required: missing hardware must be explicit in the host.
|
||||
class MachineHost {
|
||||
public:
|
||||
virtual ~MachineHost() = default;
|
||||
virtual bool LoadInternalRom(unsigned char* destination, std::size_t capacity) = 0;
|
||||
virtual unsigned char CartridgeRead(unsigned short address) = 0;
|
||||
virtual unsigned char CartridgePortRead(unsigned char port) = 0;
|
||||
virtual void CartridgePortWrite(unsigned char port, unsigned char value) = 0;
|
||||
virtual unsigned short CartridgeAudio() = 0;
|
||||
virtual void VideoWrite(VideoRegister reg, unsigned int value, unsigned char index = 0) = 0;
|
||||
virtual void TimerWrite(TimerRegister reg, unsigned int value) = 0;
|
||||
virtual void SetTurbo(unsigned char value) = 0;
|
||||
virtual void SetCpuSpeed(unsigned char value) = 0;
|
||||
virtual CPUState CpuState() = 0;
|
||||
virtual void AssertInterrupt(InterruptSource source, Interrupt interrupt) = 0;
|
||||
virtual void ClearInterrupt(InterruptSource source, Interrupt interrupt) = 0;
|
||||
virtual unsigned char KeyboardScan(unsigned char columns) = 0;
|
||||
virtual void JoystickStart(bool tandy, unsigned char value) = 0;
|
||||
virtual bool TapeFastLoad() = 0;
|
||||
virtual unsigned char TapeInputBit() = 0;
|
||||
virtual void TapeMotor(unsigned char value) = 0;
|
||||
virtual void PrinterBit(unsigned char value) = 0;
|
||||
};
|
||||
MachineHost& Machine();
|
||||
// nullptr restores the Windows adapter; on other hosts access then fails
|
||||
// explicitly until a host is installed. This is not a complete machine driver.
|
||||
void SetMachineHost(MachineHost* host);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,296 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "BasicProgram.h"
|
||||
#include "MachineDefs.h"
|
||||
#include "VideoHost.h"
|
||||
#include "CassetteDeck.h"
|
||||
#include "AudioBuffer.h"
|
||||
#include "PrinterCapture.h"
|
||||
#include "../devices/CartridgeDevice.h"
|
||||
#include "../devices/DriveWireTransport.h"
|
||||
#include "tcc1014mmu.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace VCC::Mac {
|
||||
enum class Processor { MC6809, HD6309 };
|
||||
enum class VideoOutput { RGB = 0, Composite = 1, CompositeAlternate = 2 };
|
||||
struct MachineConfiguration {
|
||||
Processor processor = Processor::MC6809;
|
||||
unsigned ram = 1; // retained MMU choices: 128 KiB, 512 KiB, 2 MiB, 8 MiB
|
||||
unsigned overclock = 1; // 1...16, applies only when the guest selects double speed
|
||||
unsigned frameInterval = 1; // publish one in 1...6 frames; devices always run
|
||||
void validate() const;
|
||||
};
|
||||
enum class RunState { Empty, Paused, Running };
|
||||
struct Frame {
|
||||
static constexpr unsigned width = 640, height = 480;
|
||||
std::uint64_t generation = 0, number = 0;
|
||||
VideoRect activeArea{0, 0, width, height};
|
||||
// Immutable after publication; packed 0x00RRGGBB, opaque when displayed.
|
||||
std::vector<std::uint32_t> pixels;
|
||||
};
|
||||
struct JoystickInputSnapshot {
|
||||
unsigned x = 8191, y = 8191, buttons = 0, mode = 0;
|
||||
};
|
||||
struct Snapshot {
|
||||
RunState state = RunState::Empty;
|
||||
VideoOutput videoOutput = VideoOutput::RGB;
|
||||
MachineConfiguration configuration;
|
||||
CPUState cpu;
|
||||
std::uint64_t generation = 0, frames = 0, cycles = 0;
|
||||
std::array<JoystickInputSnapshot, 2> joysticks{}; // right, left; side-effect-free host input
|
||||
bool keyboardHeld = false; // never exposes the actual typed keys
|
||||
// Explicit code replacement/edit epoch, separate from reset generation.
|
||||
std::uint64_t debuggerProgramRevision = 0, debuggerMappingFingerprint = 0;
|
||||
bool debuggerDevelopmentAttached = false, debuggerAssemblyAttached = false, debuggerSourceStepping = false;
|
||||
bool debuggerBankedDevelopment = false;
|
||||
bool basicDebugAttached = false;
|
||||
int basicStoppedLine = -1, basicSourceOffset = -1;
|
||||
unsigned basicSourceLength = 0;
|
||||
bool basicStepping = false, basicCanStepOut = false;
|
||||
int basicErrorLine = -1;
|
||||
std::string basicErrorCode;
|
||||
std::string basicDebugStatus;
|
||||
std::shared_ptr<const Frame> frame;
|
||||
};
|
||||
struct DebugCodeGuard {
|
||||
std::uint16_t address = 0;
|
||||
std::vector<std::uint8_t> bytes;
|
||||
};
|
||||
// Both page numbers identify 8 KiB RAM pages. Physical pages are the actual
|
||||
// installed RAM backing, after mirroring; a ROM overlay never matches.
|
||||
struct DebugBankedPage {
|
||||
std::uint8_t logicalPage = 0;
|
||||
std::uint32_t physicalPage = 0;
|
||||
};
|
||||
struct DebugBankedModule {
|
||||
std::string identifier;
|
||||
std::vector<DebugBankedPage> pages;
|
||||
std::vector<DebugCodeGuard> guards;
|
||||
// Absent preserves logical-point behavior. An explicit set qualifies only
|
||||
// these stops to this module; an empty set retains source/step evidence only.
|
||||
std::optional<std::vector<std::uint16_t>> breakpointAddresses = std::nullopt;
|
||||
};
|
||||
enum class SourceStepMode { Into, Over, Out };
|
||||
struct DebugSourceInstruction {
|
||||
std::uint16_t address = 0;
|
||||
std::uint32_t location = 0; // caller's stable file + source-line identity
|
||||
std::vector<std::uint8_t> bytes;
|
||||
std::string moduleIdentifier = {}; // required only for bank-qualified development
|
||||
};
|
||||
struct DebugSnapshot {
|
||||
CPUState cpu;
|
||||
RunState state = RunState::Empty;
|
||||
std::uint64_t generation = 0, cycles = 0;
|
||||
std::vector<std::uint16_t> breakpoints, disabledBreakpoints;
|
||||
std::uint16_t memoryAddress = 0;
|
||||
std::vector<std::uint8_t> memory;
|
||||
// Zero means an I/O address whose value cannot be inspected safely.
|
||||
// Never interpret the corresponding placeholder byte as a device value.
|
||||
std::vector<std::uint8_t> memoryAvailable;
|
||||
MMUState mmu;
|
||||
std::uint32_t physicalAddress = 0;
|
||||
std::vector<std::uint8_t> physicalMemory;
|
||||
std::string stopReason;
|
||||
};
|
||||
struct DebugMemoryRange {
|
||||
CPUState cpu;
|
||||
std::uint32_t address = 0, capacity = 0;
|
||||
std::uint64_t generation = 0, cycles = 0;
|
||||
std::vector<std::uint8_t> bytes, available;
|
||||
};
|
||||
enum class DebugGraphicsMode { SG4, PMODE0, PMODE1, PMODE2, PMODE3, PMODE4, HSCREEN1, HSCREEN2, HSCREEN3, HSCREEN4, CurrentGime };
|
||||
struct DebugGraphicsPixel {
|
||||
std::uint32_t byteIndex;
|
||||
std::uint8_t mask;
|
||||
};
|
||||
struct DebugGraphicsPreview {
|
||||
std::array<std::uint8_t, 16> palette{}; // Live six-bit GIME palette registers.
|
||||
std::string modeName;
|
||||
std::uint32_t address = 0, width = 0, height = 0;
|
||||
std::uint32_t bytesPerRow = 0, pixelsPerByte = 0, linesPerRow = 0, bytesPerCell = 1;
|
||||
std::uint32_t videoOrigin = 0, rowStrideBytes = 0, horizontalOffsetBytes = 0, verticalScrollLines = 0;
|
||||
std::string canvasIdentifier;
|
||||
std::uint32_t canvasAddress = 0, canvasBytes = 0, viewportOffset = 0;
|
||||
bool physical = false, text = false, semigraphics = false;
|
||||
std::uint64_t generation = 0, cycles = 0, mappingFingerprint = 0;
|
||||
// Pixel colors use the same 0x00RRGGBB packing as Frame. A row offset
|
||||
// indexes the compact byte arrays, even on scrolled or repeated rows.
|
||||
std::vector<std::uint32_t> pixels, rowByteOffsets, byteAddresses;
|
||||
std::vector<std::uint8_t> bytes, available;
|
||||
DebugGraphicsPixel pixelInfo(unsigned x, unsigned y) const;
|
||||
};
|
||||
// These declarations are supplied by the owning project's verified build
|
||||
// manifest, never by a public arbitrary-memory read request.
|
||||
struct DebugGraphicsBuffer {
|
||||
std::string identifier;
|
||||
std::uint32_t physicalAddress = 0;
|
||||
DebugGraphicsMode mode = DebugGraphicsMode::HSCREEN2;
|
||||
bool alternatePalette = false;
|
||||
std::uint32_t canvasBytes = 0; // Explicit power-of-two span for CurrentGime only.
|
||||
};
|
||||
struct DebugGraphicsCapture {
|
||||
DebugGraphicsPreview displayed;
|
||||
std::optional<DebugGraphicsPreview> declared;
|
||||
std::string declaredIdentifier;
|
||||
};
|
||||
struct DebugTraceRecord {
|
||||
TraceEvent event = TraceEvent::Instruction;
|
||||
std::uint64_t clock = 0, frame = 0;
|
||||
CPUState before, after;
|
||||
std::array<std::uint8_t, 8> bytes{};
|
||||
unsigned availableBytes = 0, line = 0;
|
||||
long cycles = 0;
|
||||
std::string detail;
|
||||
};
|
||||
struct DebugTraceSnapshot {
|
||||
bool armed = false, capturing = false, use6309 = false;
|
||||
std::uint64_t identifier = 0;
|
||||
std::size_t total = 0, limit = 0, offset = 0;
|
||||
std::string status = "No trace";
|
||||
std::vector<DebugTraceRecord> records;
|
||||
};
|
||||
// Pure formatting over an immutable export snapshot; safe off the machine queue.
|
||||
std::string FormatDebugTraceCSV(const DebugTraceSnapshot& trace);
|
||||
|
||||
// All operations, including destruction, belong on the owner's serial queue.
|
||||
// Only one loaded session is permitted because the retained core has globals.
|
||||
// Standalone low-level core tests must not run alongside a loaded session.
|
||||
class MachineSession {
|
||||
public:
|
||||
MachineSession();
|
||||
~MachineSession();
|
||||
MachineSession(const MachineSession&) = delete;
|
||||
MachineSession& operator=(const MachineSession&) = delete;
|
||||
void load(const std::vector<std::uint8_t>& rom, Processor processor = Processor::MC6809);
|
||||
void loadDiagnostic(Processor processor = Processor::MC6809);
|
||||
void debuggerLoadBinary(const std::vector<std::uint8_t>& binary, std::uint16_t breakpoint);
|
||||
void debuggerLoadBinary(const std::vector<std::uint8_t>& binary, const std::vector<std::uint16_t>& breakpoints);
|
||||
void launchAssembly(const std::vector<std::uint8_t>& binary, const std::vector<std::uint16_t>& points,
|
||||
const std::vector<DebugCodeGuard>& guards, bool pauseAtEntry, bool requires6309,
|
||||
std::uint64_t expectedGeneration, std::uint64_t expectedRevision, std::uint64_t expectedMapping);
|
||||
// Interactive grants follow only a compiled program entered with a verified Disk BASIC return.
|
||||
void armSharedCompiledCall();
|
||||
bool sharedCompiledCallActive() const;
|
||||
bool sharedCompiledCallReturned() const;
|
||||
const std::string* sharedCompiledReturnScreen() const;
|
||||
void pasteSharedCompiledKey(std::uint64_t chord);
|
||||
void pauseAssembly(const Snapshot& expected);
|
||||
void controlAssembly(bool step, const Snapshot& expected);
|
||||
void updateAssembly(const std::vector<std::uint16_t>& points, const Snapshot& expected);
|
||||
void clearAssembly(const Snapshot& expected);
|
||||
// Arms source breakpoints without changing RAM/PC or running the machine.
|
||||
// They become active only when all supplied verified code ranges match RAM.
|
||||
void debuggerArmDevelopmentBreakpoints(const std::vector<std::uint16_t>& breakpoints,
|
||||
const std::vector<DebugCodeGuard>& guards);
|
||||
// Modules may overlap in logical memory. Each stop verifies only its own
|
||||
// module's complete code and physical mappings, never unmapped overlays.
|
||||
// An empty breakpoint set retains inspectable/step-capable module evidence.
|
||||
void debuggerArmBankedDevelopmentBreakpoints(const std::vector<std::uint16_t>& breakpoints,
|
||||
const std::vector<DebugBankedModule>& modules);
|
||||
void debuggerClearDevelopmentBreakpoints();
|
||||
void debuggerContinueFromEntry(std::uint16_t entry);
|
||||
void quickLoad(const std::vector<std::uint8_t>& binary); // validate, load mapped memory, jump and run; no reset
|
||||
void configure(const MachineConfiguration& configuration); // CPU/RAM changes cold reset
|
||||
void resume();
|
||||
// A complete host-input snapshot takes effect before the first resumed CPU
|
||||
// slice, including the instruction that leaves a debugger breakpoint. The
|
||||
// returned immutable snapshot records actual staged input before that slice;
|
||||
// a new breakpoint may already have released live input when this returns.
|
||||
Snapshot resumeWithInput(std::uint64_t keys, const std::array<JoystickInputSnapshot, 2>& joysticks);
|
||||
void pause();
|
||||
void setJoystick(unsigned port, unsigned x, unsigned y, unsigned buttons, unsigned mode);
|
||||
void releaseInputs() noexcept; // neutralizes host inputs even at a paused stop
|
||||
void setVideoOutput(VideoOutput output); // presentation only; no CPU reset or audio flush
|
||||
// Host opt-in, independent of guest media and saved profiles. An empty
|
||||
// factory closes active connections and removes access to the Becker port.
|
||||
void setDriveWireFactory(Devices::DriveWireFactory factory);
|
||||
bool driveWireEnabled() const { return bool(driveWireFactory); }
|
||||
void setKeyboard(std::uint64_t keys); // complete held-key matrix, ignored unless running
|
||||
// Opt-in one-shot DOS 255 at the next RGBDOS prompt. Advances with guest
|
||||
// frames, never wall-clock sleeps; resets/real keys cancel it.
|
||||
void requestNitros9Boot();
|
||||
bool nitros9BootPending() const;
|
||||
void paste(const std::vector<std::uint64_t>& chords); // bounded, frame-paced keyboard input
|
||||
void cancelPaste();
|
||||
std::size_t pasteRemaining() const;
|
||||
bool basicExecutingStoredSource() const;
|
||||
bool basicAtDirectPrompt() const; // Recognized ROM direct-mode input stack, independent of displayed text.
|
||||
std::string basicReadSource() const;
|
||||
std::vector<BasicVariable> basicInspect(const std::string& source) const;
|
||||
std::vector<std::uint8_t> basicExportSource(const std::string& source, const std::string& filename, BasicExportFormat format) const;
|
||||
void basicLoadSource(const std::string& source, bool run, const std::vector<std::uint16_t>& breakpoints = {});
|
||||
void basicSetBreakpoints(const std::string& source, const std::vector<std::uint16_t>& lines);
|
||||
void basicClearDebug();
|
||||
void basicContinue(const std::string& source);
|
||||
void basicStep(const std::string& source, bool over);
|
||||
void basicStepOut(const std::string& source);
|
||||
std::string copyScreenText() const; // hardware text only; graphics are rejected
|
||||
void softReset(); // retain RAM; restart hardware, preserve running/paused state
|
||||
void reset(); // cold reset, preserves running/paused state
|
||||
void advance(); // one bounded frame; no-op when paused/empty
|
||||
void shutdown(); // idempotent; permits later loading
|
||||
Snapshot snapshot() const;
|
||||
// Owned snapshots on the same serial queue as execution. Reads wrap in the
|
||||
// logical 16-bit address space; no I/O read side effects are permitted.
|
||||
// Physical inspection reads installed RAM, bypassing ROM/MMU/I/O. It is
|
||||
// bounded to 256 bytes and truncates at the end; it never wraps or writes.
|
||||
DebugSnapshot debuggerSnapshot(std::uint16_t address = 0, unsigned count = 256,
|
||||
std::uint32_t physicalAddress = 0, unsigned physicalCount = 0) const;
|
||||
// Exact non-wrapping immutable range, bounded by the selected memory space.
|
||||
// Mapped I/O is explicitly unavailable; exporting it must fail, not fill zeros.
|
||||
DebugMemoryRange debuggerMemoryRange(std::uint32_t address, std::uint32_t count, bool physical) const;
|
||||
DebugGraphicsPreview debuggerGraphicsPreview(bool currentPage, bool physical, std::uint32_t address,
|
||||
DebugGraphicsMode mode, bool alternatePalette = false, const std::vector<DebugGraphicsBuffer>& canvases = {}) const;
|
||||
// Fresh, borderless previews from one paused state, not the history of the
|
||||
// last published raster frame. Reads do not advance the guest or live GPU.
|
||||
DebugGraphicsCapture debuggerGraphicsCapture(const std::optional<DebugGraphicsBuffer>& declared = std::nullopt,
|
||||
const std::vector<DebugGraphicsBuffer>& canvases = {}) const;
|
||||
void debuggerStep(); // paused only; retained Windows instruction-step semantics
|
||||
// Begins a bounded normal-execution step. advance() progresses it; pause()
|
||||
// cancels. Permanent breakpoints remain active, including inside callees.
|
||||
void debuggerStepSource(SourceStepMode mode, const std::vector<DebugSourceInstruction>& instructions,
|
||||
std::uint64_t expectedGeneration, std::uint64_t expectedProgramRevision,
|
||||
std::uint64_t expectedMappingFingerprint, std::uint16_t expectedPC,
|
||||
unsigned maximumInstructions = 1000000, unsigned maximumFrames = 600);
|
||||
void debuggerSetPC(std::uint16_t address); // paused only, same ForcePC semantics as Windows
|
||||
void debuggerSetBreakpoints(std::vector<std::uint16_t> addresses);
|
||||
void debuggerConfigureBreakpoints(std::vector<std::uint16_t> enabled, std::vector<std::uint16_t> disabled);
|
||||
// Captures stop at the bound without pausing or resetting guest execution.
|
||||
void debuggerStartTrace(unsigned maximum, const std::vector<std::uint16_t>& starts,
|
||||
const std::vector<std::uint16_t>& stops, bool screen, bool scheduler);
|
||||
void debuggerStopTrace();
|
||||
void debuggerClearTrace();
|
||||
DebugTraceSnapshot debuggerTrace(std::size_t offset = 0, unsigned count = 256) const;
|
||||
DebugTraceSnapshot debuggerTraceForExport(std::size_t first, std::size_t count) const;
|
||||
std::string debuggerExportTrace(std::size_t first, std::size_t count) const;
|
||||
// Atomic preflight, 1...256 bytes, no wrapping, mapped RAM only (below FE00).
|
||||
void debuggerWriteMemory(std::uint16_t address, const std::vector<std::uint8_t>& bytes);
|
||||
PrinterCapture& printer() { return *printerCapture; }
|
||||
const PrinterCapture& printer() const { return *printerCapture; }
|
||||
CassetteDeck& cassette() { return *tape; }
|
||||
Devices::CartridgeBus& cartridges() { return *bus; }
|
||||
std::vector<StereoSample> takeAudio(); // drains samples on the owner queue
|
||||
|
||||
private:
|
||||
void resumeImpl(const std::uint64_t* keys, const std::array<JoystickInputSnapshot, 2>* joysticks, Snapshot* staged = nullptr);
|
||||
bool basicInputState(unsigned top) const;
|
||||
void loadDevelopmentImage(const std::vector<std::uint8_t>& binary, const std::vector<std::uint16_t>& points,
|
||||
const std::vector<DebugCodeGuard>* assemblyGuards);
|
||||
void checkAssembly(const Snapshot& expected) const;
|
||||
struct Impl;
|
||||
Devices::DriveWireFactory driveWireFactory;
|
||||
std::shared_ptr<PrinterCapture> printerCapture;
|
||||
std::shared_ptr<CassetteDeck> tape;
|
||||
std::shared_ptr<Devices::CartridgeBus> bus;
|
||||
std::unique_ptr<Impl> impl;
|
||||
MachineConfiguration configuration;
|
||||
std::uint64_t generation = 0, nextTraceIdentifier = 0, debuggerProgramRevision = 0;
|
||||
VideoOutput videoOutput = VideoOutput::RGB;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,987 @@
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// OpCodeTables for 6x09 microprocessors - Part of the Debugger package for VCC
|
||||
// Author: Mike Rojas
|
||||
//
|
||||
// TODO: Let's add a capture for 6309 illegal opcodes and correct cycle behavior for 6809 illegal opcodes.
|
||||
//
|
||||
#pragma once
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 26812)
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include "MachineDefs.h"
|
||||
|
||||
namespace VCC::Debugger
|
||||
{
|
||||
|
||||
class OpCodeTables
|
||||
{
|
||||
public:
|
||||
OpCodeTables() = default;
|
||||
|
||||
// 6x09 Address Modes
|
||||
enum AddressingMode
|
||||
{
|
||||
Illegal,
|
||||
Inherent,
|
||||
Direct,
|
||||
Indexed,
|
||||
Relative,
|
||||
Extended,
|
||||
Immediate,
|
||||
LongRelative,
|
||||
OpPage2,
|
||||
OpPage3,
|
||||
};
|
||||
|
||||
// 6x09 Heuristics
|
||||
// We classify op codes into special modifiers that are used to adjust the number of bytes and clock cycles
|
||||
enum Heuristics
|
||||
{
|
||||
None, // Used for Illegal Op Codes
|
||||
Fixed, // Base Bytes and Cycles are the final values
|
||||
WaitForSYNCAdjust, // Adjust for Interrupt Delay SYNC Style
|
||||
IndexedModeAdjust, // Adjust for various indexing modes, offsets, autoincrement/decrement
|
||||
StackAdjust, // Adjust for number of registers pushed or pulled
|
||||
InterruptAdjust, // Adjust for interrupt state via CC.E
|
||||
LongBranchAdjust, // Adjust for long branch condition
|
||||
TFMAdjust, // Adjust for number of bytes transferred
|
||||
DIVAdjust, // Adjust for overflow condition
|
||||
};
|
||||
|
||||
// OpCode page entry
|
||||
struct OpCodeInfo
|
||||
{
|
||||
unsigned char opcode; // 8-bit opcode value
|
||||
std::string name; // Opcode name
|
||||
AddressingMode mode; // Addressing mode
|
||||
int num6809cycles; // Base number of cycles (6809 only and 6309 in emulation)
|
||||
int num6309cycles; // Base number of cycles (6309 native only)
|
||||
int numbytes; // Base number of bytes
|
||||
int oplen; // Number of bytes for opcode
|
||||
bool only6309; // Valid only if running a 6309, in other words, invalid on a 6809
|
||||
Heuristics modifer; // Modifer used to adjust base number of bytes and base clock cycles
|
||||
};
|
||||
|
||||
// Page 1 operations xx codes
|
||||
std::array<OpCodeTables::OpCodeInfo, 256> Page1OpCodes =
|
||||
{
|
||||
0x00, "NEG", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x01, "OIM", Direct, 6, 6, 3, 1, true, Fixed, // Illegal on 6809
|
||||
0x02, "AIM", Direct, 6, 6, 3, 1, true, Fixed, // Illegal on 6809
|
||||
0x03, "COM", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x04, "LSR", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x05, "EIM", Direct, 6, 6, 3, 1, true, Fixed, // Illegal on 6809
|
||||
0x06, "ROR", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x07, "ASR", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x08, "ASL", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x09, "ROL", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x0A, "DEC", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x0B, "TIM", Direct, 6, 6, 3, 1, true, Fixed, // Illegal on 6809
|
||||
0x0C, "INC", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
0x0D, "TST", Direct, 6, 4, 2, 1, false, Fixed,
|
||||
0x0E, "JMP", Direct, 3, 2, 2, 1, false, Fixed,
|
||||
0x0F, "CLR", Direct, 6, 5, 2, 1, false, Fixed,
|
||||
|
||||
0x10, "page2", OpPage2, 0, 0, 2, 1, false, Fixed,
|
||||
0x11, "page3", OpPage3, 0, 0, 2, 1, false, Fixed,
|
||||
0x12, "NOP", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x13, "SYNC", Inherent, 4, 3, 1, 1, false, WaitForSYNCAdjust,
|
||||
0x14, "SEXW", Inherent, 4, 4, 1, 1, true, Fixed, // Illegal on 6809
|
||||
0x15, "HALT", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x16, "LBRA", LongRelative, 5, 4, 3, 1, false, LongBranchAdjust,
|
||||
0x17, "LBSR", LongRelative, 9, 7, 3, 1, false, LongBranchAdjust,
|
||||
0x18, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x19, "DAA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x1A, "ORCC", Immediate, 3, 3, 2, 1, false, Fixed,
|
||||
0x1B, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x1C, "ANDCC", Immediate, 3, 3, 2, 1, false, Fixed,
|
||||
0x1D, "SEX", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x1E, "EXG", Immediate, 8, 5, 2, 1, false, Fixed,
|
||||
0x1F, "TFR", Immediate, 6, 4, 2, 1, false, Fixed,
|
||||
|
||||
0x20, "BRA", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x21, "BRN", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x22, "BHI", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x23, "BLS", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x24, "BCC", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x25, "BCS", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x26, "BNE", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x27, "BEQ", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x28, "BVC", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x29, "BVS", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2A, "BPL", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2B, "BMI", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2C, "BGE", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2D, "BLT", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2E, "BGT", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
0x2F, "BLE", Relative, 3, 3, 2, 1, false, Fixed,
|
||||
|
||||
0x30, "LEAX", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0x31, "LEAY", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0x32, "LEAS", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0x33, "LEAU", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0x34, "PSHS", Inherent, 5, 4, 2, 1, false, StackAdjust,
|
||||
0x35, "PULS", Inherent, 5, 4, 2, 1, false, StackAdjust,
|
||||
0x36, "PSHU", Inherent, 5, 4, 2, 1, false, StackAdjust,
|
||||
0x37, "PULU", Inherent, 5, 4, 2, 1, false, StackAdjust,
|
||||
0x38, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x39, "RTS", Inherent, 5, 4, 1, 1, false, Fixed,
|
||||
0x3A, "ABX", Inherent, 3, 1, 1, 1, false, Fixed,
|
||||
0x3B, "RTI", Inherent, 6, 6, 1, 1, false, InterruptAdjust,
|
||||
0x3C, "CWAI", Immediate, 22, 20, 2, 1, false, Fixed,
|
||||
0x3D, "MUL", Inherent, 11, 10, 1, 1, false, Fixed,
|
||||
0x3E, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x3F, "SWI", Inherent, 19, 21, 1, 1, false, Fixed,
|
||||
|
||||
0x40, "NEGA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x41, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x42, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x43, "COMA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x44, "LSRA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x45, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x46, "RORA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x47, "ASRA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x48, "LSLA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x49, "ROLA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x4A, "DECA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x4B, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x4C, "INCA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x4D, "TSTA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x4E, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x4F, "CLRA", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
|
||||
0x50, "NEGB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x51, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x52, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x53, "COMB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x54, "LSRB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x55, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x56, "RORB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x57, "ASRB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x58, "LSLB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x59, "ROLB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x5A, "DECB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x5B, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x5C, "INCB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x5D, "TSTB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
0x5E, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x5F, "CLRB", Inherent, 2, 1, 1, 1, false, Fixed,
|
||||
|
||||
0x60, "NEG", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x61, "OIM", Indexed, 7, 7, 3, 1, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0x62, "AIM", Indexed, 7, 7, 3, 1, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0x63, "COM", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x64, "LSR", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x65, "EIM", Indexed, 7, 7, 3, 1, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0x66, "ROR", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x67, "ASR", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x68, "LSL", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x69, "ROL", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x6A, "DEC", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x6B, "TIM", Indexed, 7, 7, 3, 1, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0x6C, "INC", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0x6D, "TST", Indexed, 6, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0x6E, "JMP", Indexed, 3, 3, 2, 1, false, IndexedModeAdjust,
|
||||
0x6F, "CLR", Indexed, 6, 6, 2, 1, false, IndexedModeAdjust,
|
||||
|
||||
0x70, "NEG", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x71, "OIM", Extended, 7, 7, 4, 1, true, Fixed, // Illegal on 6809
|
||||
0x72, "AIM", Extended, 7, 7, 4, 1, true, Fixed, // Illegal on 6809
|
||||
0x73, "COM", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x74, "LSR", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x75, "EIM", Extended, 7, 7, 4, 1, true, Fixed, // Illegal on 6809
|
||||
0x76, "ROR", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x77, "ASR", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x78, "LSL", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x79, "ROL", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x7A, "DEC", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x7B, "TIM", Extended, 7, 7, 4, 1, true, Fixed, // Illegal on 6809
|
||||
0x7C, "INC", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
0x7D, "TST", Extended, 7, 5, 3, 1, false, Fixed,
|
||||
0x7E, "JMP", Extended, 4, 3, 3, 1, false, Fixed,
|
||||
0x7F, "CLR", Extended, 7, 6, 3, 1, false, Fixed,
|
||||
|
||||
0x80, "SUBA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x81, "CMPA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x82, "SBCA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x83, "SUBD", Immediate, 4, 3, 3, 1, false, Fixed,
|
||||
0x84, "ANDA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x85, "BITA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x86, "LDA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x87, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0x88, "EORA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x89, "ADCA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x8A, "ORA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x8B, "ADDA", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0x8C, "CMPX", Immediate, 4, 3, 3, 1, false, Fixed,
|
||||
0x8D, "BSR", Relative, 7, 6, 2, 1, false, Fixed,
|
||||
0x8E, "LDX", Immediate, 3, 3, 3, 1, false, Fixed,
|
||||
0x8F, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
|
||||
0x90, "SUBA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x91, "CMPA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x92, "SBCA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x93, "SUBD", Direct, 6, 4, 2, 1, false, Fixed,
|
||||
0x94, "ANDA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x95, "BITA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x96, "LDA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x97, "STA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x98, "EORA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x99, "ADCA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x9A, "ORA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x9B, "ADDA", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0x9C, "CMPX", Direct, 6, 4, 2, 1, false, Fixed,
|
||||
0x9D, "JSR", Direct, 7, 6, 2, 1, false, Fixed,
|
||||
0x9E, "LDX", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
0x9F, "STX", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
|
||||
0xA0, "SUBA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA1, "CMPA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA2, "SBCA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA3, "SUBD", Indexed, 6, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xA4, "ANDA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA5, "BITA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA6, "LDA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA7, "STA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA8, "EORA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xA9, "ADCA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xAA, "ORA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xAB, "ADDA", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xAC, "CMPX", Indexed, 6, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xAD, "JSR", Indexed, 7, 6, 2, 1, false, IndexedModeAdjust,
|
||||
0xAE, "LDX", Indexed, 5, 2, 2, 1, false, IndexedModeAdjust,
|
||||
0xAF, "STX", Indexed, 5, 2, 2, 1, false, IndexedModeAdjust,
|
||||
|
||||
0xB0, "SUBA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB1, "CMPA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB2, "SBCA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB3, "SUBD", Extended, 7, 5, 3, 1, false, Fixed,
|
||||
0xB4, "ANDA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB5, "BITA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB6, "LDA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB7, "STA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB8, "EORA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xB9, "ADCA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xBA, "ORA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xBB, "ADDA", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xBC, "CMPX", Extended, 7, 5, 3, 1, false, Fixed,
|
||||
0xBD, "JSR", Extended, 8, 7, 3, 1, false, Fixed,
|
||||
0xBE, "LDX", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
0xBF, "STX", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
|
||||
0xC0, "SUBB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC1, "CMPB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC2, "SBCB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC3, "ADDD", Immediate, 4, 3, 3, 1, false, Fixed,
|
||||
0xC4, "ANDB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC5, "BITB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC6, "LDB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC7, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
0xC8, "EORB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xC9, "ADCB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xCA, "ORB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xCB, "ADDB", Immediate, 2, 2, 2, 1, false, Fixed,
|
||||
0xCC, "LDD", Immediate, 3, 3, 3, 1, false, Fixed,
|
||||
0xCD, "LDQ", Immediate, 5, 5, 5, 1, false, Fixed,
|
||||
0xCE, "LDU", Immediate, 3, 3, 3, 1, false, Fixed,
|
||||
0xCF, "-", Illegal, 0, 0, 0, 1, false, None,
|
||||
|
||||
0xD0, "SUBB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD1, "CMPB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD2, "SBCB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD3, "ADDD", Direct, 6, 4, 2, 1, false, Fixed,
|
||||
0xD4, "ANDB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD5, "BITB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD6, "LDB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD7, "STB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD8, "EORB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xD9, "ADCB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xDA, "ORB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xDB, "ADDB", Direct, 4, 3, 2, 1, false, Fixed,
|
||||
0xDC, "LDD", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
0xDD, "STD", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
0xDE, "LDU", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
0xDF, "STU", Direct, 5, 4, 2, 1, false, Fixed,
|
||||
|
||||
0xE0, "SUBB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE1, "CMPB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE2, "SBCB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE3, "ADDD", Indexed, 6, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xE4, "ANDB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE5, "BITB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE6, "LDB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE7, "STB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE8, "EORB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xE9, "ADCB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xEA, "ORB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xEB, "ADDB", Indexed, 4, 4, 2, 1, false, IndexedModeAdjust,
|
||||
0xEC, "LDD", Indexed, 5, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xED, "STD", Indexed, 5, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xEE, "LDU", Indexed, 5, 5, 2, 1, false, IndexedModeAdjust,
|
||||
0xEF, "STU", Indexed, 5, 5, 2, 1, false, IndexedModeAdjust,
|
||||
|
||||
0xF0, "SUBB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF1, "CMPB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF2, "SBCB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF3, "ADDD", Extended, 7, 5, 3, 1, false, Fixed,
|
||||
0xF4, "ANDB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF5, "BITB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF6, "LDB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF7, "STB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF8, "EORB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xF9, "ADCB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xFA, "ORB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xFB, "ADDB", Extended, 5, 4, 3, 1, false, Fixed,
|
||||
0xFC, "LDD", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
0xFD, "STD", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
0xFE, "LDU", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
0xFF, "STU", Extended, 6, 5, 3, 1, false, Fixed,
|
||||
};
|
||||
|
||||
// Page 2 operations 10xx codes
|
||||
std::array<OpCodeTables::OpCodeInfo, 256> Page2OpCodes =
|
||||
{
|
||||
0x00, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x01, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x02, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x03, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x04, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x05, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x06, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x07, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x08, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x09, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x10, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x11, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x12, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x13, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x14, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x15, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x16, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x17, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x18, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x19, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x20, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x21, "LBRN", LongRelative, 5, 5, 4, 2, false, Fixed,
|
||||
0x22, "LBHI", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x23, "LBLS", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x24, "LBCC", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x25, "LBCS", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x26, "LBNE", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x27, "LBEQ", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x28, "LBVC", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x29, "LBVS", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2A, "LBPL", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2B, "LBMI", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2C, "LBGE", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2D, "LBLT", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2E, "LBGT", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
0x2F, "LBLE", LongRelative, 5, 6, 4, 2, false, LongBranchAdjust,
|
||||
|
||||
0x30, "ADDR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x31, "ADCR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x32, "SUBR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x33, "SBCR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x34, "ANDR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x35, "ORR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x36, "EORR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x37, "CMPR", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x38, "PSHSW", Inherent, 6, 6, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x39, "PULSW", Inherent, 6, 6, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x3A, "PSHUW", Inherent, 6, 6, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x3B, "PULUW", Inherent, 6, 6, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x3C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x3D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x3E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x3F, "SWI2", Inherent, 20, 22, 2, 2, false, Fixed,
|
||||
|
||||
0x40, "NEGD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x41, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x42, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x43, "COMD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x44, "LSRD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x45, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x46, "RORD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x47, "ASRD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x48, "LSLD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x49, "ROLD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4A, "DECD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x4C, "INCD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4D, "TSTD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x4F, "CLRD", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0x50, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x51, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x52, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x53, "COMW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x54, "LSRW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x55, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x56, "RORW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x57, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x58, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x59, "ROLW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5A, "DECW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x5C, "INCW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5D, "TSTW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x5F, "CLRW", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0x60, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x61, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x62, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x63, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x64, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x65, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x66, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x67, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x68, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x69, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x70, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x71, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x72, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x73, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x74, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x75, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x76, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x77, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x78, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x79, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x80, "SUBW", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x81, "CMPW", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x82, "SBCD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x83, "CMPD", Immediate, 5, 4, 4, 2, false, Fixed,
|
||||
0x84, "ANDD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x85, "BITD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x86, "LDW", Immediate, 4, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x87, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x88, "EORD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x89, "ADCD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x8A, "ORD", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x8B, "ADDW", Immediate, 5, 4, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x8C, "CMPY", Immediate, 5, 4, 4, 2, false, Fixed,
|
||||
0x8D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x8E, "LDY", Immediate, 4, 4, 4, 2, false, Fixed,
|
||||
0x8F, "-", Illegal, 0, 0, 0, 2, false, Fixed,
|
||||
|
||||
0x90, "SUBW", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x91, "CMPW", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x92, "SBCD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x93, "CMPD", Direct, 7, 5, 3, 2, false, Fixed,
|
||||
0x94, "ANDD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x95, "BITD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x96, "LDW", Direct, 6, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x97, "STW", Direct, 6, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x98, "EORD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x99, "ADCD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x9A, "ORD", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x9B, "ADDW", Direct, 7, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x9C, "CMPY", Direct, 7, 5, 3, 2, false, Fixed,
|
||||
0x9D, "-", Illegal, 0, 0, 0, 2, false, Fixed,
|
||||
0x9E, "LDY", Direct, 6, 5, 3, 2, false, Fixed,
|
||||
0x9F, "STY", Direct, 6, 5, 3, 2, false, Fixed,
|
||||
|
||||
0xA0, "SUBW", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA1, "CMPW", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA2, "SBCD", Indexed, 7, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA3, "CMPD", Indexed, 7, 6, 3, 2, false, IndexedModeAdjust,
|
||||
0xA4, "ANDD", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA5, "BITD", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA6, "LDW", Indexed, 6, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA7, "STW", Indexed, 6, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA8, "EORD", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA9, "ADCD", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xAA, "ORD", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xAB, "ADDW", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xAC, "CMPY", Indexed, 7, 6, 3, 2, false, IndexedModeAdjust,
|
||||
0xAD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xAE, "LDY", Indexed, 6, 6, 3, 2, false, IndexedModeAdjust,
|
||||
0xAF, "STY", Indexed, 6, 6, 3, 2, false, IndexedModeAdjust,
|
||||
|
||||
0xB0, "SUBW", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB1, "CMPW", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB2, "SBCD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB3, "CMPD", Extended, 8, 6, 4, 2, false, Fixed,
|
||||
0xB4, "ANDD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB5, "BITD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB6, "LDW", Extended, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB7, "STW", Extended, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB8, "EORD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB9, "ADCD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xBA, "ORD", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xBB, "ADDW", Extended, 8, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xBC, "CMPY", Extended, 8, 6, 4, 2, false, Fixed,
|
||||
0xBD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xBE, "LDY", Extended, 7, 6, 4, 2, false, Fixed,
|
||||
0xBF, "STY", Extended, 7, 6, 4, 2, false, Fixed,
|
||||
|
||||
0xC0, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC1, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC6, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC7, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCB, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCC, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCE, "LDS", Immediate, 4, 4, 4, 2, false, Fixed,
|
||||
0xCF, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0xD0, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD1, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD6, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD7, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDB, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDC, "LDQ", Direct, 8, 7, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xDD, "STQ", Direct, 8, 7, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xDE, "LDS", Direct, 6, 5, 3, 2, false, Fixed,
|
||||
0xDF, "STS", Direct, 6, 5, 3, 2, false, Fixed,
|
||||
|
||||
0xE0, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE1, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE6, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE7, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEB, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEC, "LDQ", Indexed, 0, 8, 3, 2, false, IndexedModeAdjust,
|
||||
0xED, "STQ", Indexed, 0, 8, 3, 2, false, IndexedModeAdjust,
|
||||
0xEE, "LDS", Indexed, 6, 6, 3, 2, false, IndexedModeAdjust,
|
||||
0xEF, "STS", Indexed, 6, 6, 3, 2, false, IndexedModeAdjust,
|
||||
|
||||
0xF0, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF1, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF6, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF7, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFB, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFC, "LDQ", Extended, 0, 8, 4, 2, false, Fixed,
|
||||
0xFD, "STQ", Extended, 0, 8, 4, 2, false, Fixed,
|
||||
0xFE, "LDS", Extended, 7, 6, 4, 2, false, Fixed,
|
||||
0xFF, "STS", Extended, 7, 6, 4, 2, false, Fixed,
|
||||
};
|
||||
|
||||
// Page 3 operations 11xx codes
|
||||
std::array<OpCodeTables::OpCodeInfo, 256> Page3OpCodes =
|
||||
{
|
||||
0x00, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x01, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x02, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x03, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x04, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x05, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x06, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x07, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x08, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x09, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x0F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x10, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x11, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x12, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x13, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x14, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x15, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x16, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x17, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x18, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x19, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x1F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x20, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x21, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x22, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x23, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x24, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x25, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x26, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x27, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x28, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x29, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x2F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x30, "BAND", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x31, "BIAND", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x32, "BOR", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x33, "BIOR", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x34, "BEOR", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x35, "BIEOR", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x36, "LDBT", Direct, 7, 6, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x37, "STBT", Direct, 8, 7, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0x38, "TFM", Immediate, 6, 6, 3, 2, true, TFMAdjust, // Illegal on 6809
|
||||
0x39, "TFM", Immediate, 6, 6, 3, 2, true, TFMAdjust, // Illegal on 6809
|
||||
0x3A, "TFM", Immediate, 6, 6, 3, 2, true, TFMAdjust, // Illegal on 6809
|
||||
0x3B, "TFM", Immediate, 6, 6, 3, 2, true, TFMAdjust, // Illegal on 6809
|
||||
0x3C, "BITMD", Immediate, 4, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x3D, "LDMD", Immediate, 5, 5, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x3E, "BREAK", Inherent, 4, 2, 2, 2, false, Fixed,
|
||||
0x3F, "SWI3", Inherent, 20, 22, 2, 2, false, Fixed,
|
||||
|
||||
0x40, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x41, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x42, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x43, "COME", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x44, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x45, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x46, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x47, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x48, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x49, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x4A, "DECE", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x4C, "INCE", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4D, "TSTE", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x4E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x4F, "CLRE", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0x50, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x51, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x52, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x53, "COMF", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x54, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x55, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x56, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x57, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x58, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x59, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x5A, "DECF", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x5C, "INCF", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5D, "TSTF", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
0x5E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x5F, "CLRF", Inherent, 3, 2, 2, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0x60, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x61, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x62, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x63, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x64, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x65, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x66, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x67, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x68, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x69, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x6F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x70, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x71, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x72, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x73, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x74, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x75, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x76, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x77, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x78, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x79, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7B, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7C, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7D, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7E, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x7F, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0x80, "SUBE", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x81, "CMPE", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x82, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x83, "CMPU", Immediate, 5, 4, 4, 2, false, Fixed,
|
||||
0x84, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x85, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x86, "LDE", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x87, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x88, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x89, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x8A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x8B, "ADDE", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x8C, "CMPS", Immediate, 5, 4, 4, 2, false, Fixed,
|
||||
0x8D, "DIVD", Immediate, 25, 25, 3, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0x8E, "DIVQ", Immediate, 34, 34, 4, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0x8F, "MULD", Immediate, 28, 28, 4, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0x90, "SUBE", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x91, "CMPE", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x92, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x93, "CMPU", Direct, 7, 5, 3, 2, false, Fixed,
|
||||
0x94, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x95, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x96, "LDE", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x97, "STE", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x98, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x99, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x9A, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0x9B, "ADDE", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0x9C, "CMPS", Direct, 7, 5, 3, 2, false, Fixed,
|
||||
0x9D, "DIVD", Direct, 27, 26, 3, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0x9E, "DIVQ", Direct, 36, 35, 3, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0x9F, "MULD", Direct, 30, 29, 3, 2, true, Fixed, // Illegal on 6809
|
||||
|
||||
0xA0, "SUBE", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA1, "CMPE", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xA3, "CMPU", Indexed, 7, 6, 3, 2, true, IndexedModeAdjust,
|
||||
0xA4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xA5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xA6, "LDE", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA7, "STE", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xA8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xA9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xAA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xAB, "ADDE", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xAC, "CMPS", Indexed, 7, 6, 3, 2, false, IndexedModeAdjust,
|
||||
0xAD, "DIVD", Indexed, 27, 27, 3, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0xAE, "DIVQ", Indexed, 36, 36, 3, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0xAF, "MULD", Indexed, 30, 30, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
|
||||
0xB0, "SUBE", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB1, "CMPE", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xB3, "CMPU", Extended, 8, 6, 4, 2, false, Fixed,
|
||||
0xB4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xB5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xB6, "LDE", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB7, "STE", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xB8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xB9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xBA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xBB, "ADDE", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xBC, "CMPS", Extended, 8, 6, 4, 2, false, Fixed,
|
||||
0xBD, "DIVD", Extended, 28, 27, 4, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0xBE, "DIVQ", Extended, 37, 36, 4, 2, true, DIVAdjust, // Illegal on 6809
|
||||
0xBF, "MULD", Extended, 31, 30, 4, 2, true, Fixed, // Illegal on 6809 (Possible Adjust Needed?)
|
||||
|
||||
0xC0, "SUBF", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xC1, "CMPF", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xC2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC6, "LDF", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xC7, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xC9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCB, "ADDF", Immediate, 3, 3, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xCC, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCE, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xCF, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0xD0, "SUBF", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xD1, "CMPF", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xD2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD6, "LDF", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xD7, "STF", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xD8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xD9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDB, "ADDF", Direct, 5, 4, 3, 2, true, Fixed, // Illegal on 6809
|
||||
0xDC, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDE, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xDF, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0xE0, "SUBF", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xE1, "CMPF", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xE2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE6, "LDF", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xE7, "STF", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xE8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xE9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEB, "ADDF", Indexed, 5, 5, 3, 2, true, IndexedModeAdjust, // Illegal on 6809
|
||||
0xEC, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xED, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEE, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xEF, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
|
||||
0xF0, "SUBF", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xF1, "CMPF", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xF2, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF3, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF4, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF5, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF6, "LDF", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xF7, "STF", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xF8, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xF9, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFA, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFB, "ADDF", Extended, 6, 5, 4, 2, true, Fixed, // Illegal on 6809
|
||||
0xFC, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFD, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFE, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
0xFF, "-", Illegal, 0, 0, 0, 2, false, None,
|
||||
};
|
||||
|
||||
// Indexed Mode PostByte formats
|
||||
struct IndexModeInfo
|
||||
{
|
||||
std::string postbyte; // 8-bit postbyte key
|
||||
std::string form; // Assembler form
|
||||
int num6809cycles; // Additional number of cycles (6809 only and 6309 in emulation)
|
||||
int num6309cycles; // Additional number of cycles (6309 native only)
|
||||
int numbytes; // Additional number of bytes
|
||||
bool only6309; // Valid only if running a 6309, in other words, invalid on a 6809
|
||||
};
|
||||
|
||||
const std::map<std::string, IndexModeInfo, std::less<>> IndexingModes =
|
||||
{
|
||||
{ "1RR00100", {"1RR00100", ",R", 0, 0, 0, false } },
|
||||
{ "0RRnnnnn", {"0RRnnnnn", "n,R", 1, 1, 0, false } },
|
||||
{ "1RR01000", {"1RR01000", "n,R", 1, 1, 1, false } },
|
||||
{ "1RR01001", {"1RR01001", "n,R", 4, 3, 2, false } },
|
||||
{ "10001111", {"10001111", ",W", 0, 0, 0, true } }, // Illegal on 6809
|
||||
{ "10101111", {"10101111", "n,W", 2, 2, 2, true } }, // Illegal on 6809
|
||||
{ "1RR00110", {"1RR00110", "A,R", 1, 1, 0, false } },
|
||||
{ "1RR00101", {"1RR00101", "B,R", 1, 1, 0, false } },
|
||||
{ "1RR01011", {"1RR01011", "D,R", 4, 2, 0, false } },
|
||||
{ "1RR00111", {"1RR00111", "E,R", 1, 1, 0, true } }, // Illegal on 6809
|
||||
{ "1RR01010", {"1RR01010", "F,R", 1, 1, 0, true } }, // Illegal on 6809
|
||||
{ "1RR01110", {"1RR01110", "W,R", 1, 1, 0, true } }, // Illegal on 6809
|
||||
{ "1RR00000", {"1RR00000", ",R+", 2, 1, 0, false } },
|
||||
{ "1RR00001", {"1RR00001", ",R++", 3, 2, 0, false } },
|
||||
{ "1RR00010", {"1RR00010", ",-R", 2, 1, 0, false } },
|
||||
{ "1RR00011", {"1RR00011", ",--R", 3, 2, 0, false } },
|
||||
{ "11001111", {"11001111", ",W++", 1, 1, 0, true } }, // Illegal on 6809
|
||||
{ "11101111", {"11101111", ",--W", 1, 1, 0, true } }, // Illegal on 6809
|
||||
{ "1XX01100", {"1XX01100", "n,PCR", 1, 1, 1, false } },
|
||||
{ "1XX01101", {"1XX01101", "n,PCR", 5, 3, 2, false } },
|
||||
{ "1RR10100", {"1RR10100", "[,R]", 3, 3, 0, false } },
|
||||
{ "1RR11000", {"1RR11000", "[n,R]", 4, 4, 1, false } },
|
||||
{ "1RR11001", {"1RR11001", "[n,R]", 7, 6, 2, false } },
|
||||
{ "10010000", {"10010000", "[,W]", 3, 3, 0, true } }, // Illegal on 6809
|
||||
{ "10110000", {"10110000", "[n,W]", 5, 5, 2, true } }, // Illegal on 6809
|
||||
{ "1RR10110", {"1RR10110", "[A,R]", 4, 4, 0, false } },
|
||||
{ "1RR10101", {"1RR10101", "[B,R]", 4, 4, 0, false } },
|
||||
{ "1RR11011", {"1RR11011", "[D,R]", 7, 5, 0, false } },
|
||||
{ "1RR10111", {"1RR10111", "[E,R]", 4, 4, 0, true } }, // Illegal on 6809
|
||||
{ "1RR11010", {"1RR11010", "[F,R]", 4, 4, 0, true } }, // Illegal on 6809
|
||||
{ "1RR01110", {"1RR01110", "[W,R]", 4, 4, 0, true } }, // Illegal on 6809
|
||||
{ "1RR10001", {"1RR10001", "[,R++]", 6, 5, 0, false } },
|
||||
{ "1RR10011", {"1RR10011", "[,--R]", 6, 5, 0, false } },
|
||||
{ "11010000", {"11010000", "[,W++]", 4, 4, 0, true } }, // Illegal on 6809
|
||||
{ "11110000", {"11110000", "[,--W]", 4, 4, 0, true } }, // Illegal on 6809
|
||||
{ "1XX11100", {"1XX11100", "[n,PCR]", 4, 4, 1, false } },
|
||||
{ "1XX11101", {"1XX11101", "[n,PCR]", 8, 6, 2, false } },
|
||||
{ "10011111", {"10011111", "[n]", 5, 4, 2, false } },
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// Calculate the exact number of cycles based on CPU state
|
||||
bool ProcessHeuristics(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
|
||||
protected:
|
||||
|
||||
bool ProcessNoAdjust(const OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessIndexModeAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessInterruptAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessStackAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessLongBranchAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessTFMAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessDIVAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
bool ProcessWaitForSYNCAdjust(OpCodeInfo& opcode, const CPUState& state, CPUTrace& trace) const;
|
||||
|
||||
int AdjustCycles(OpCodeInfo& opcode, int cycles, int bytes, bool IsNative6309) const;
|
||||
|
||||
bool GetIndexMode(unsigned char postbyte, IndexModeInfo& mode, std::string& operand) const;
|
||||
std::string ToRegister(unsigned char postbyte) const;
|
||||
std::string ToInterRegister(unsigned char reg) const;
|
||||
std::string ToRelativeAddressString(int value, int operandlen) const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Mac {
|
||||
// Retains the Windows bit-banger framing: each PIA data-register write is one
|
||||
// serial sample, idle high, start low, eight data bits least-significant first.
|
||||
// This is output capture, not baud-rate detection or a DMP-130 command parser.
|
||||
// PIA DAC/cassette traffic shares the register, so capture is explicitly opt-in.
|
||||
// All access belongs to the emulation queue, including immutable copy creation.
|
||||
class PrinterCapture {
|
||||
public:
|
||||
static constexpr std::size_t capacity = 1024 * 1024;
|
||||
bool enabled() const { return capturing; }
|
||||
std::uint64_t revision() const { return changed; }
|
||||
std::uint64_t droppedBytes() const { return dropped; }
|
||||
const std::vector<std::uint8_t>& bytes() const { return data; }
|
||||
void setEnabled(bool value) {
|
||||
if (capturing == value) return;
|
||||
capturing = value; resetFraming();
|
||||
}
|
||||
// Preserve a partial character through Clear: its remaining bits must not
|
||||
// be mistaken for a fresh start bit. Hardware resets abandon that character.
|
||||
void clear() { data.clear(); dropped = 0; ++changed; }
|
||||
void resetFraming() { bits = 0; byte = 0; waiting = true; }
|
||||
void sample(unsigned char value) {
|
||||
if (!capturing) return;
|
||||
if (waiting) { if (!value) { waiting = false; bits = 0; byte = 0; } return; }
|
||||
if (value) byte |= std::uint8_t(1u << bits);
|
||||
if (++bits != 8) return;
|
||||
if (data.size() < capacity) data.push_back(byte);
|
||||
else if (dropped < std::numeric_limits<std::uint64_t>::max()) ++dropped;
|
||||
++changed; resetFraming();
|
||||
}
|
||||
private:
|
||||
bool capturing = false, waiting = true;
|
||||
unsigned bits = 0;
|
||||
std::uint8_t byte = 0;
|
||||
std::uint64_t changed = 0, dropped = 0;
|
||||
std::vector<std::uint8_t> data;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "VideoHost.h"
|
||||
#include <stdexcept>
|
||||
#ifdef _WIN32
|
||||
#include "../../platforms/windows/defines.h"
|
||||
#include "../../platforms/windows/config.h"
|
||||
#include "../../platforms/windows/DirectDrawInterface.h"
|
||||
#endif
|
||||
|
||||
namespace VCC {
|
||||
namespace {
|
||||
#ifdef _WIN32
|
||||
class WindowsVideoHost final : public VideoHost {
|
||||
public:
|
||||
VideoState& Surface() override { return EmuState; }
|
||||
void ClearSurface() override { Cls(0, &EmuState); }
|
||||
bool UseNtscArtifacts() const override { return GetPaletteType() == PALETTE_NTSC; }
|
||||
};
|
||||
WindowsVideoHost windowsHost;
|
||||
VideoHost* activeHost = &windowsHost;
|
||||
#else
|
||||
VideoHost* activeHost = nullptr;
|
||||
#endif
|
||||
}
|
||||
VideoHost& Video() {
|
||||
if (!activeHost) throw std::logic_error("Install a VideoHost before rendering");
|
||||
return *activeHost;
|
||||
}
|
||||
void SetVideoHost(VideoHost* host) {
|
||||
#ifdef _WIN32
|
||||
activeHost = host ? host : &windowsHost;
|
||||
#else
|
||||
activeHost = host;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Size and VideoArray extracted from defines.h, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include "BuildConfig.h"
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
namespace VCC {
|
||||
struct Size
|
||||
{
|
||||
int w{}, h{};
|
||||
|
||||
Size() = default;
|
||||
Size(int w, int h) :w(w), h(h) {}
|
||||
};
|
||||
|
||||
template <class T, size_t Size>
|
||||
struct VideoArray
|
||||
{
|
||||
explicit VideoArray(T* p) : data(p) {}
|
||||
|
||||
#if USE_DEBUG_VIDEO_BUFFER
|
||||
T& operator[](size_t index)
|
||||
{
|
||||
assert(index < Size);
|
||||
return data[index % Size];
|
||||
}
|
||||
|
||||
const T& operator[](size_t index) const
|
||||
{
|
||||
assert(index < Size);
|
||||
return data[index % Size];
|
||||
}
|
||||
#else
|
||||
inline T& operator[](size_t index)
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
|
||||
inline const T& operator[](size_t index) const
|
||||
{
|
||||
return data[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private:
|
||||
T* data;
|
||||
};
|
||||
|
||||
|
||||
// Active raster bounds, independent of pixel colors. Union all rendered rows
|
||||
// so split-screen modes retain every active column and line in a frame.
|
||||
struct VideoRect {
|
||||
int x = 0, y = 0, width = 0, height = 0;
|
||||
void include(int left, int top, int w, int h, Size limit) {
|
||||
const int right = std::clamp(left + w, 0, limit.w);
|
||||
const int bottom = std::clamp(top + h, 0, limit.h);
|
||||
left = std::clamp(left, 0, limit.w); top = std::clamp(top, 0, limit.h);
|
||||
if (right <= left || bottom <= top) return;
|
||||
if (!width || !height) { *this = {left, top, right-left, bottom-top}; return; }
|
||||
const int farX = std::max(x+width, right), farY = std::max(y+height, bottom);
|
||||
x = std::min(x,left); y = std::min(y,top); width = farX-x; height = farY-y;
|
||||
}
|
||||
};
|
||||
|
||||
// Borrowed emulated RAM and host-owned render surface. Pitch is in pixels
|
||||
// for the selected depth (0=8, 1=16, 2=24, 3=32), not bytes. The Mac path
|
||||
// uses a packed 640x480 array of uint32_t values in 0x00RRGGBB format.
|
||||
struct VideoState {
|
||||
unsigned char* RamBuffer = nullptr;
|
||||
unsigned short* WRamBuffer = nullptr;
|
||||
unsigned char BitDepth = 0;
|
||||
unsigned char* PTRsurface8 = nullptr;
|
||||
unsigned short* PTRsurface16 = nullptr;
|
||||
unsigned int* PTRsurface32 = nullptr;
|
||||
// Pixel row stride uses the same 32-bit range on Windows and macOS.
|
||||
int SurfacePitch = 0;
|
||||
unsigned short LineCounter = 0;
|
||||
unsigned char ScanLines = 0;
|
||||
Size WindowSize;
|
||||
};
|
||||
class VideoHost {
|
||||
public:
|
||||
virtual ~VideoHost() = default;
|
||||
virtual VideoState& Surface() = 0;
|
||||
virtual void ClearSurface() = 0;
|
||||
virtual bool UseNtscArtifacts() const = 0;
|
||||
virtual void ActiveVideoArea(int, int, int, int) {}
|
||||
// Called at the actual raster boundary, including when one instruction
|
||||
// (e.g. debugger-stepped 6309 TFM) spans several complete frames.
|
||||
virtual void FrameCompleted() {}
|
||||
};
|
||||
// Install before running the raster clock and detach after stopping it.
|
||||
VideoHost& Video();
|
||||
void SetVideoHost(VideoHost* host);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include "VideoRegisters.h"
|
||||
#include "tcc1014graphics.h"
|
||||
|
||||
void VCC::ApplyVideoRegister(GimeGpu& gpu, VideoRegister reg, unsigned int value, unsigned char index) {
|
||||
switch (reg) {
|
||||
case VideoRegister::RamMask: gpu.SetVidMask(value); break;
|
||||
case VideoRegister::Bank: gpu.SetVideoBank(value); break;
|
||||
case VideoRegister::Compatibility: gpu.SetCompatMode(value); break;
|
||||
case VideoRegister::Mode: gpu.SetGimeVmode(value); break;
|
||||
case VideoRegister::Resolution: gpu.SetGimeVres(value); break;
|
||||
case VideoRegister::Border: gpu.SetGimeBoarderColor(value); break;
|
||||
case VideoRegister::Scroll: gpu.SetVerticalScroll(value); break;
|
||||
case VideoRegister::Offset: gpu.SetVerticalOffsetRegister(value); break;
|
||||
case VideoRegister::HorizontalOffset: gpu.SetGimeHorzOffset(value); break;
|
||||
case VideoRegister::Palette: gpu.SetGimePalette(index, value); break;
|
||||
case VideoRegister::VdgMode: gpu.SetGimeVdgMode(value); break;
|
||||
case VideoRegister::VdgMode2: gpu.SetGimeVdgMode2(value); break;
|
||||
case VideoRegister::VdgOffset: gpu.SetGimeVdgOffset(value); break;
|
||||
}
|
||||
}
|
||||
|
||||
void VCC::ApplyTimerRegister(GimeGpu& gpu, TimerRegister reg, unsigned int value) {
|
||||
#if USE_NEWTIMING
|
||||
switch (reg) {
|
||||
case TimerRegister::ClockSource: gpu.SetTimerSource(value); break;
|
||||
case TimerRegister::Restart: gpu.SetTimer(value & 0xfff); gpu.ResetTimer(); break;
|
||||
case TimerRegister::Reload: gpu.SetTimer(value & 0xfff); break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "MachineHost.h"
|
||||
struct GimeGpu;
|
||||
namespace VCC {
|
||||
void ApplyVideoRegister(GimeGpu& gpu, VideoRegister reg, unsigned int value, unsigned char index = 0);
|
||||
void ApplyTimerRegister(GimeGpu& gpu, TimerRegister reg, unsigned int value);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
#ifndef __CC2FONT_H__
|
||||
#define __CC2FONT_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
static unsigned char ntsc_round_fontdata8x12[] =
|
||||
{
|
||||
0x00,0x00,0x38,0x44,0x04,0x34,0x4C,0x4C,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x28,0x44,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x78,0x24,0x24,0x38,0x24,0x24,0x78,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x78,0x24,0x24,0x24,0x24,0x24,0x78,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x40,0x40,0x70,0x40,0x40,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x40,0x40,0x70,0x40,0x40,0x40,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x40,0x40,0x4C,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x48,0x50,0x60,0x50,0x48,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x6C,0x54,0x54,0x44,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x64,0x54,0x4C,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x78,0x44,0x44,0x78,0x40,0x40,0x40,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x44,0x44,0x54,0x48,0x34,0x00,0x00,0x00,
|
||||
0x00,0x00,0x78,0x44,0x44,0x78,0x50,0x48,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x40,0x38,0x04,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x28,0x28,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x44,0x54,0x6C,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x28,0x10,0x28,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x28,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x04,0x08,0x10,0x20,0x40,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x08,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x38,0x54,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x10,0x20,0x7C,0x20,0x10,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x28,0x28,0x7C,0x28,0x7C,0x28,0x28,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x3C,0x50,0x38,0x14,0x78,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x60,0x64,0x08,0x10,0x20,0x4C,0x0C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x50,0x50,0x20,0x54,0x48,0x34,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x10,0x08,0x08,0x08,0x10,0x20,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x10,0x54,0x38,0x38,0x54,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x40,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x4C,0x54,0x64,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x04,0x38,0x40,0x40,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x04,0x08,0x04,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x40,0x78,0x04,0x04,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x40,0x40,0x78,0x44,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x04,0x08,0x10,0x20,0x40,0x40,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x44,0x3C,0x04,0x04,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x10,0x10,0x20,0x00,0x00,
|
||||
0x00,0x00,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x04,0x08,0x10,0x00,0x10,0x00,0x00,0x00,
|
||||
|
||||
|
||||
/* Block Graphics (Semigraphics 4 Graphics ) */
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
|
||||
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
|
||||
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
|
||||
0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
|
||||
0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
|
||||
/* Lower case */
|
||||
0x00,0x00,0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x40,0x40,0x58,0x64,0x44,0x64,0x58,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x38,0x44,0x40,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x04,0x04,0x34,0x4C,0x44,0x4C,0x34,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x08,0x14,0x10,0x38,0x10,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x34,0x4C,0x44,0x4C,0x34,0x04,0x38,0x00,
|
||||
0x00,0x00,0x40,0x40,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x00,0x30,0x10,0x10,0x10,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x04,0x00,0x04,0x04,0x04,0x04,0x44,0x38,0x00,0x00,
|
||||
0x00,0x00,0x40,0x40,0x48,0x50,0x60,0x50,0x48,0x00,0x00,0x00,
|
||||
0x00,0x00,0x30,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x78,0x54,0x54,0x54,0x54,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x78,0x44,0x44,0x44,0x78,0x40,0x40,0x00,
|
||||
0x00,0x00,0x00,0x00,0x3C,0x44,0x44,0x44,0x3C,0x04,0x04,0x00,
|
||||
0x00,0x00,0x00,0x00,0x58,0x64,0x40,0x40,0x40,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x3C,0x40,0x38,0x04,0x78,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x20,0x70,0x20,0x20,0x24,0x18,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x44,0x44,0x44,0x28,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x44,0x54,0x54,0x28,0x28,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x44,0x44,0x44,0x3C,0x04,0x38,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x7C,0x08,0x10,0x20,0x7C,0x00,0x00,0x00,
|
||||
0x00,0x00,0x08,0x10,0x10,0x20,0x10,0x10,0x08,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x10,0x10,0x00,0x10,0x10,0x10,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x10,0x10,0x08,0x10,0x10,0x20,0x00,0x00,0x00,
|
||||
0x00,0x00,0x20,0x54,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,288 @@
|
||||
#ifndef __CC3FONT_H__
|
||||
#define __CC3FONT_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
unsigned char cc3Fontdata8x12[] =
|
||||
{
|
||||
/* Fixed chrs 0-31 */
|
||||
0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x10,0x08,0x00,0x00,0x00, // C
|
||||
0x44,0x00,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x08,0x10,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x10,0x28,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x28,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x20,0x10,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x10,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x00,0x00,0x38,0x44,0x40,0x44,0x38,0x10,0x00,0x00,0x00,0x00, // c
|
||||
0x10,0x28,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x28,0x00,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x20,0x10,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x28,0x00,0x30,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // l
|
||||
0x10,0x28,0x00,0x30,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // i
|
||||
0x00,0x38,0x44,0x78,0x44,0x44,0x78,0x00,0x00,0x00,0x00,0x00, // B
|
||||
0x24,0x10,0x28,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // A
|
||||
0x10,0x10,0x28,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // A
|
||||
0x08,0x10,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x00,0x00,0x68,0x14,0x3C,0x50,0x3C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x3C,0x50,0x50,0x7A,0x50,0x50,0x5C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x28,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x28,0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x00,0x00,0x38,0x4C,0x54,0x64,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x10,0x28,0x00,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x20,0x10,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x38,0x4C,0x54,0x54,0x54,0x64,0x38,0x00,0x00,0x00,0x00,0x00, // 0
|
||||
0x44,0x38,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x28,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // U
|
||||
0x38,0x40,0x38,0x44,0x38,0x04,0x38,0x00,0x00,0x00,0x00,0x00, // s
|
||||
0x08,0x14,0x10,0x38,0x10,0x50,0x3C,0x00,0x00,0x00,0x00,0x00, // f
|
||||
0x10,0x10,0x7C,0x10,0x10,0x00,0x7C,0x00,0x00,0x00,0x00,0x00, // +
|
||||
0x10,0x28,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // '
|
||||
0x08,0x14,0x10,0x38,0x10,0x10,0x20,0x40,0x00,0x00,0x00,0x00, // f
|
||||
|
||||
/* Normal Text chrs 32-127 */
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space
|
||||
0x10,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00, // !
|
||||
0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // "
|
||||
0x28,0x28,0x7C,0x28,0x7C,0x28,0x28,0x00,0x00,0x00,0x00,0x00, // #
|
||||
0x10,0x3C,0x50,0x38,0x14,0x78,0x10,0x00,0x00,0x00,0x00,0x00, // $
|
||||
0x60,0x64,0x08,0x10,0x20,0x4C,0x0C,0x00,0x00,0x00,0x00,0x00, // %
|
||||
0x20,0x50,0x50,0x20,0x54,0x48,0x34,0x00,0x00,0x00,0x00,0x00, // &
|
||||
0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // '
|
||||
0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00,0x00,0x00, // (
|
||||
0x20,0x10,0x08,0x08,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00, // )
|
||||
0x00,0x10,0x54,0x38,0x38,0x54,0x10,0x00,0x00,0x00,0x00,0x00, // *
|
||||
0x00,0x10,0x10,0x7C,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00, // +
|
||||
0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20,0x00,0x00,0x00,0x00, // ,
|
||||
0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00, // .
|
||||
0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x00, // /
|
||||
0x38,0x44,0x4C,0x54,0x64,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // 0
|
||||
0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // 1
|
||||
0x38,0x44,0x04,0x38,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00, // 2
|
||||
0x38,0x44,0x04,0x08,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // 3
|
||||
0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // 4
|
||||
0x7C,0x40,0x78,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // 5
|
||||
0x38,0x40,0x40,0x78,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // 6
|
||||
0x7C,0x04,0x08,0x10,0x20,0x40,0x40,0x00,0x00,0x00,0x00,0x00, // 7
|
||||
0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // 8
|
||||
0x38,0x44,0x44,0x38,0x04,0x04,0x38,0x00,0x00,0x00,0x00,0x00, // 9
|
||||
0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00, // :
|
||||
0x00,0x00,0x10,0x00,0x00,0x10,0x10,0x20,0x00,0x00,0x00,0x00, // ;
|
||||
0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00,0x00,0x00,0x00,0x00, // <
|
||||
0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // =
|
||||
0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00, // >
|
||||
0x38,0x44,0x04,0x08,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00, // ?
|
||||
0x38,0x44,0x04,0x34,0x4C,0x4C,0x38,0x00,0x00,0x00,0x00,0x00, // @
|
||||
0x10,0x28,0x44,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // A
|
||||
0x78,0x24,0x24,0x38,0x24,0x24,0x78,0x00,0x00,0x00,0x00,0x00, // B
|
||||
0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // C
|
||||
0x78,0x24,0x24,0x24,0x24,0x24,0x78,0x00,0x00,0x00,0x00,0x00, // D
|
||||
0x7C,0x40,0x40,0x70,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00, // E
|
||||
0x7C,0x40,0x40,0x70,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00, // F
|
||||
0x38,0x44,0x40,0x40,0x4C,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // G
|
||||
0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // H
|
||||
0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // I
|
||||
0x04,0x04,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // J
|
||||
0x44,0x48,0x50,0x60,0x50,0x48,0x44,0x00,0x00,0x00,0x00,0x00, // K
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00, // L
|
||||
0x44,0x6C,0x54,0x54,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // M
|
||||
0x44,0x44,0x64,0x54,0x4C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // N
|
||||
0x38,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // O
|
||||
0x78,0x44,0x44,0x78,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00, // P
|
||||
0x38,0x44,0x44,0x44,0x54,0x48,0x34,0x00,0x00,0x00,0x00,0x00, // Q
|
||||
0x78,0x44,0x44,0x78,0x50,0x48,0x44,0x00,0x00,0x00,0x00,0x00, // R
|
||||
0x38,0x44,0x40,0x38,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // S
|
||||
0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // T
|
||||
0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // U
|
||||
0x44,0x44,0x44,0x28,0x28,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // V
|
||||
0x44,0x44,0x44,0x44,0x54,0x6C,0x44,0x00,0x00,0x00,0x00,0x00, // W
|
||||
0x44,0x44,0x28,0x10,0x28,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // X
|
||||
0x44,0x44,0x28,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // Y
|
||||
0x7C,0x04,0x08,0x10,0x20,0x40,0x7C,0x00,0x00,0x00,0x00,0x00, // Z
|
||||
0x38,0x20,0x20,0x20,0x20,0x20,0x38,0x00,0x00,0x00,0x00,0x00, // [
|
||||
0x00,0x40,0x20,0x10,0x08,0x04,0x00,0x00,0x00,0x00,0x00,0x00, // \ backslash
|
||||
0x38,0x08,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0x00, // ]
|
||||
0x10,0x38,0x54,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // Up Arrow
|
||||
0x00,0x10,0x20,0x7C,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00, // Left Arrow
|
||||
0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ^
|
||||
0x00,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x40,0x40,0x58,0x64,0x44,0x64,0x58,0x00,0x00,0x00,0x00,0x00, // b
|
||||
0x00,0x00,0x38,0x44,0x40,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // c
|
||||
0x04,0x04,0x34,0x4C,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // d
|
||||
0x00,0x00,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x08,0x14,0x10,0x38,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // f
|
||||
0x00,0x00,0x34,0x4C,0x4C,0x34,0x04,0x38,0x00,0x00,0x00,0x00, // g
|
||||
0x40,0x40,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // h
|
||||
0x00,0x10,0x00,0x30,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // i
|
||||
0x00,0x04,0x00,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00, // j
|
||||
0x40,0x40,0x48,0x50,0x60,0x50,0x48,0x00,0x00,0x00,0x00,0x00, // k
|
||||
0x30,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // l
|
||||
0x00,0x00,0x68,0x54,0x54,0x54,0x54,0x00,0x00,0x00,0x00,0x00, // m
|
||||
0x00,0x00,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // n
|
||||
0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x00,0x00,0x78,0x44,0x44,0x78,0x40,0x40,0x00,0x00,0x00,0x00, // p
|
||||
0x00,0x00,0x3C,0x44,0x44,0x3C,0x04,0x04,0x00,0x00,0x00,0x00, // q
|
||||
0x00,0x00,0x58,0x64,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00, // r
|
||||
0x00,0x00,0x3C,0x40,0x38,0x04,0x78,0x00,0x00,0x00,0x00,0x00, // s
|
||||
0x20,0x20,0x70,0x20,0x20,0x24,0x18,0x00,0x00,0x00,0x00,0x00, // t
|
||||
0x00,0x00,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x00,0x00,0x44,0x44,0x44,0x28,0x10,0x00,0x00,0x00,0x00,0x00, // v
|
||||
0x00,0x00,0x44,0x54,0x54,0x28,0x28,0x00,0x00,0x00,0x00,0x00, // w
|
||||
0x00,0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00, // x
|
||||
0x00,0x00,0x44,0x44,0x44,0x3C,0x04,0x38,0x00,0x00,0x00,0x00, // y
|
||||
0x00,0x00,0x7C,0x08,0x10,0x20,0x7C,0x00,0x00,0x00,0x00,0x00, // z
|
||||
0x08,0x10,0x10,0x20,0x10,0x10,0x08,0x00,0x00,0x00,0x00,0x00, // {
|
||||
0x10,0x10,0x10,0x00,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00, // |
|
||||
0x20,0x10,0x10,0x08,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00, // }
|
||||
0x20,0x54,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ~
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00, // _
|
||||
/* Junk padding fix me chrs 128-159 */
|
||||
0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x10,0x08,0x00,0x00,0x00, // C
|
||||
0x44,0x00,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x08,0x10,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x10,0x28,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x28,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x20,0x10,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x10,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00, // a
|
||||
0x00,0x00,0x38,0x44,0x40,0x44,0x38,0x10,0x00,0x00,0x00,0x00, // c
|
||||
0x10,0x28,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x28,0x00,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x20,0x10,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00, // e
|
||||
0x28,0x00,0x30,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // l
|
||||
0x10,0x28,0x00,0x30,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00, // i
|
||||
0x00,0x18,0x24,0x38,0x24,0x24,0x38,0x40,0x00,0x00,0x00,0x00, // B
|
||||
0x44,0x10,0x28,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // A
|
||||
0x10,0x10,0x28,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00, // A
|
||||
0x08,0x10,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x00,0x00,0x68,0x14,0x3C,0x50,0x3C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x3C,0x50,0x50,0x7A,0x50,0x50,0x5C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x28,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x28,0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x00,0x00,0x38,0x4C,0x54,0x64,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x10,0x28,0x00,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x20,0x10,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00, // u
|
||||
0x38,0x4C,0x54,0x54,0x54,0x64,0x38,0x00,0x00,0x00,0x00,0x00, // 0
|
||||
0x44,0x38,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // o
|
||||
0x28,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00, // U
|
||||
0x38,0x40,0x38,0x44,0x38,0x04,0x38,0x00,0x00,0x00,0x00,0x00, // s
|
||||
0x08,0x14,0x10,0x38,0x10,0x50,0x3C,0x00,0x00,0x00,0x00,0x00, // f
|
||||
0x10,0x10,0x7C,0x10,0x10,0x00,0x7C,0x00,0x00,0x00,0x00,0x00, // +
|
||||
0x10,0x28,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // '
|
||||
0x08,0x14,0x10,0x38,0x10,0x10,0x20,0x40,0x00,0x00,0x00,0x00, // f
|
||||
|
||||
|
||||
/* Normal Text chrs 160-255 */
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x10,0x10,0x10,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x28,0x28,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x28,0x28,0x7C,0x28,0x7C,0x28,0x28,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x3C,0x50,0x38,0x14,0x78,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x60,0x64,0x08,0x10,0x20,0x4C,0x0C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x50,0x50,0x20,0x54,0x48,0x34,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x10,0x20,0x20,0x20,0x10,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x10,0x08,0x08,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x10,0x54,0x38,0x38,0x54,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x10,0x10,0x7C,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x4C,0x54,0x64,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x30,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x04,0x38,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x04,0x08,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x18,0x28,0x48,0x7C,0x08,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x40,0x78,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x40,0x40,0x78,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x04,0x08,0x10,0x20,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x44,0x38,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x44,0x38,0x04,0x04,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x10,0x00,0x00,0x10,0x10,0x20,0x00,0x00,0x00,0x00,
|
||||
0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x04,0x08,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x04,0x34,0x4C,0x4C,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x28,0x44,0x44,0x7C,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x78,0x24,0x24,0x38,0x24,0x24,0x78,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x40,0x40,0x40,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x78,0x24,0x24,0x24,0x24,0x24,0x78,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x40,0x40,0x70,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x40,0x40,0x70,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x40,0x40,0x4C,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x04,0x04,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x48,0x50,0x60,0x50,0x48,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x6C,0x54,0x54,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x64,0x54,0x4C,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x78,0x44,0x44,0x78,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x44,0x44,0x54,0x48,0x34,0x00,0x00,0x00,0x00,0x00,
|
||||
0x78,0x44,0x44,0x78,0x50,0x48,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x44,0x40,0x38,0x04,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x44,0x28,0x28,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x44,0x44,0x54,0x6C,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x28,0x10,0x28,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x44,0x44,0x28,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x7C,0x04,0x08,0x10,0x20,0x40,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x20,0x20,0x20,0x20,0x20,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x40,0x20,0x10,0x08,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x38,0x08,0x08,0x08,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x38,0x54,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x10,0x20,0x7C,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x04,0x3C,0x44,0x3C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x40,0x40,0x58,0x64,0x44,0x64,0x58,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x40,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x04,0x04,0x34,0x4C,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x7C,0x40,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x14,0x10,0x38,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x34,0x4C,0x4C,0x34,0x04,0x38,0x00,0x00,0x00,0x00,
|
||||
0x40,0x40,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x10,0x00,0x30,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x04,0x00,0x04,0x04,0x04,0x44,0x38,0x00,0x00,0x00,0x00,
|
||||
0x40,0x40,0x48,0x50,0x60,0x50,0x48,0x00,0x00,0x00,0x00,0x00,
|
||||
0x30,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x68,0x54,0x54,0x54,0x54,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x58,0x64,0x44,0x44,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x78,0x44,0x44,0x78,0x40,0x40,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x3C,0x44,0x44,0x3C,0x04,0x04,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x58,0x64,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x3C,0x40,0x38,0x04,0x78,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x20,0x70,0x20,0x20,0x24,0x18,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x4C,0x34,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x28,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x54,0x54,0x28,0x28,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x44,0x44,0x44,0x3C,0x04,0x38,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x7C,0x08,0x10,0x20,0x7C,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x10,0x10,0x20,0x10,0x10,0x08,0x00,0x00,0x00,0x00,0x00,
|
||||
0x10,0x10,0x10,0x00,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x10,0x10,0x08,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x54,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00
|
||||
};
|
||||
|
||||
#endif
|
||||
+7706
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,34 @@
|
||||
#ifndef __HD6309_H__
|
||||
#define __HD6309_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MachineDefs.h"
|
||||
|
||||
void HD6309Init();
|
||||
int HD6309Exec( int);
|
||||
void HD6309Reset();
|
||||
void HD6309AssertInterupt(InterruptSource, Interrupt);
|
||||
void HD6309DeAssertInterupt(InterruptSource, Interrupt);
|
||||
void HD6309ForcePC(unsigned short);
|
||||
void HD6309PrepareBasicCall(unsigned short stack);
|
||||
VCC::CPUState HD6309GetState();
|
||||
void HD6309SetBreakpoints(const std::vector<unsigned short>& breakpoints);
|
||||
void HD6309SetTraceTriggers(const std::vector<unsigned short>& triggers);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,513 @@
|
||||
#ifndef __HD6309DEFS_H__
|
||||
#define __HD6309DEFS_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//CC Flag masks
|
||||
constexpr auto E = 7u;
|
||||
constexpr auto F = 6u;
|
||||
constexpr auto H = 5u;
|
||||
constexpr auto I = 4u;
|
||||
constexpr auto N = 3u;
|
||||
constexpr auto Z = 2u;
|
||||
constexpr auto V = 1u;
|
||||
constexpr auto C = 0u;
|
||||
|
||||
//MD Flag masks
|
||||
constexpr auto NATIVE6309 = 0u;
|
||||
constexpr auto FIRQMODE = 1u;
|
||||
constexpr auto ILLEGAL = 6u;
|
||||
constexpr auto ZERODIV = 7u;
|
||||
|
||||
// MC6309 Vector table
|
||||
constexpr auto VTRAP = 0xFFF0u;
|
||||
constexpr auto VSWI3 = 0xFFF2u;
|
||||
constexpr auto VSWI2 = 0xFFF4u;
|
||||
constexpr auto VFIRQ = 0xFFF6u;
|
||||
constexpr auto VIRQ = 0xFFF8u;
|
||||
constexpr auto VSWI = 0xFFFAu;
|
||||
constexpr auto VNMI = 0xFFFCu;
|
||||
constexpr auto VRESET = 0xFFFEu;
|
||||
|
||||
|
||||
|
||||
|
||||
//Opcode Defs
|
||||
//Last Char (D) Direct (I) Inherent (R) Relative (M) Immediate (X) Indexed (E) extened
|
||||
constexpr auto NEG_D = 0x00u;
|
||||
constexpr auto OIM_D = 0x01u; //6309
|
||||
constexpr auto AIM_D = 0x02u; //6309
|
||||
constexpr auto COM_D = 0x03u;
|
||||
constexpr auto LSR_D = 0x04u;
|
||||
constexpr auto EIM_D = 0x05u; //6309
|
||||
constexpr auto ROR_D = 0x06u;
|
||||
constexpr auto ASR_D = 0x07u;
|
||||
constexpr auto ASL_D = 0x08u;
|
||||
constexpr auto ROL_D = 0x09u;
|
||||
constexpr auto DEC_D = 0x0Au;
|
||||
constexpr auto TIM_D = 0x0Bu; //6309
|
||||
constexpr auto INC_D = 0x0Cu;
|
||||
constexpr auto TST_D = 0x0Du;
|
||||
constexpr auto JMP_D = 0x0Eu;
|
||||
constexpr auto CLR_D = 0x0Fu;
|
||||
|
||||
constexpr auto Page2 = 0x10u;
|
||||
constexpr auto Page3 = 0x11u;
|
||||
constexpr auto NOP_I = 0x12u;
|
||||
constexpr auto SYNC_I = 0x13u;
|
||||
constexpr auto SEXW_I = 0x14u; //6309
|
||||
constexpr auto HALT = 0x15u; //Vcc Halt_0x15
|
||||
constexpr auto LBRA_R = 0x16u;
|
||||
constexpr auto LBSR_R = 0x17u;
|
||||
constexpr auto DAA_I = 0x19u;
|
||||
constexpr auto ORCC_M = 0x1Au;
|
||||
constexpr auto ANDCC_M = 0x1Cu;
|
||||
constexpr auto SEX_I = 0x1Du;
|
||||
constexpr auto EXG_M = 0x1Eu;
|
||||
constexpr auto TFR_M = 0x1Fu;
|
||||
|
||||
constexpr auto BRA_R = 0x20u;
|
||||
constexpr auto BRN_R = 0x21u;
|
||||
constexpr auto BHI_R = 0x22u;
|
||||
constexpr auto BLS_R = 0x23u;
|
||||
constexpr auto BHS_R = 0x24u;
|
||||
constexpr auto BLO_R = 0x25u;
|
||||
constexpr auto BNE_R = 0x26u;
|
||||
constexpr auto BEQ_R = 0x27u;
|
||||
constexpr auto BVC_R = 0x28u;
|
||||
constexpr auto BVS_R = 0x29u;
|
||||
constexpr auto BPL_R = 0x2Au;
|
||||
constexpr auto BMI_R = 0x2Bu;
|
||||
constexpr auto BGE_R = 0x2Cu;
|
||||
constexpr auto BLT_R = 0x2Du;
|
||||
constexpr auto BGT_R = 0x2Eu;
|
||||
constexpr auto BLE_R = 0x2Fu;
|
||||
|
||||
constexpr auto LEAX_X = 0x30u;
|
||||
constexpr auto LEAY_X = 0x31u;
|
||||
constexpr auto LEAS_X = 0x32u;
|
||||
constexpr auto LEAU_X = 0x33u;
|
||||
constexpr auto PSHS_M = 0x34u;
|
||||
constexpr auto PULS_M = 0x35u;
|
||||
constexpr auto PSHU_M = 0x36u;
|
||||
constexpr auto PULU_M = 0x37u;
|
||||
constexpr auto RTS_I = 0x39u;
|
||||
constexpr auto ABX_I = 0x3Au;
|
||||
constexpr auto RTI_I = 0x3Bu;
|
||||
constexpr auto CWAI_I = 0x3Cu;
|
||||
constexpr auto MUL_I = 0x3Du;
|
||||
constexpr auto RESET = 0x3Eu; //Undocumented instruction
|
||||
constexpr auto SWI1_I = 0x3Fu;
|
||||
|
||||
constexpr auto NEGA_I = 0x40u;
|
||||
constexpr auto COMA_I = 0x43u;
|
||||
constexpr auto LSRA_I = 0x44u;
|
||||
constexpr auto RORA_I = 0x46u;
|
||||
constexpr auto ASRA_I = 0x47u;
|
||||
constexpr auto ASLA_I = 0x48u;
|
||||
constexpr auto ROLA_I = 0x49u;
|
||||
constexpr auto DECA_I = 0x4Au;
|
||||
constexpr auto INCA_I = 0x4Cu;
|
||||
constexpr auto TSTA_I = 0x4Du;
|
||||
constexpr auto CLRA_I = 0x4Fu;
|
||||
|
||||
constexpr auto NEGB_I = 0x50u;
|
||||
constexpr auto COMB_I = 0x53u;
|
||||
constexpr auto LSRB_I = 0x54u;
|
||||
constexpr auto RORB_I = 0x56u;
|
||||
constexpr auto ASRB_I = 0x57u;
|
||||
constexpr auto ASLB_I = 0x58u;
|
||||
constexpr auto ROLB_I = 0x59u;
|
||||
constexpr auto DECB_I = 0x5Au;
|
||||
constexpr auto INCB_I = 0x5Cu;
|
||||
constexpr auto TSTB_I = 0x5Du;
|
||||
constexpr auto CLRB_I = 0x5Fu;
|
||||
|
||||
constexpr auto NEG_X = 0x60u;
|
||||
constexpr auto OIM_X = 0x61u; //6309
|
||||
constexpr auto AIM_X = 0x62u; //6309
|
||||
constexpr auto COM_X = 0x63u;
|
||||
constexpr auto LSR_X = 0x64u;
|
||||
constexpr auto EIM_X = 0x65u; //6309
|
||||
constexpr auto ROR_X = 0x66u;
|
||||
constexpr auto ASR_X = 0x67u;
|
||||
constexpr auto ASL_X = 0x68u;
|
||||
constexpr auto ROL_X = 0x69u;
|
||||
constexpr auto DEC_X = 0x6Au;
|
||||
constexpr auto TIM_X = 0x6Bu; //6309
|
||||
constexpr auto INC_X = 0x6Cu;
|
||||
constexpr auto TST_X = 0x6Du;
|
||||
constexpr auto JMP_X = 0x6Eu;
|
||||
constexpr auto CLR_X = 0x6Fu;
|
||||
|
||||
constexpr auto NEG_E = 0x70u;
|
||||
constexpr auto OIM_E = 0x71u; //6309
|
||||
constexpr auto AIM_E = 0x72u; //6309
|
||||
constexpr auto COM_E = 0x73u;
|
||||
constexpr auto LSR_E = 0x74u;
|
||||
constexpr auto EIM_E = 0x75u; //6309
|
||||
constexpr auto ROR_E = 0x76u;
|
||||
constexpr auto ASR_E = 0x77u;
|
||||
constexpr auto ASL_E = 0x78u;
|
||||
constexpr auto ROL_E = 0x79u;
|
||||
constexpr auto DEC_E = 0x7Au;
|
||||
constexpr auto TIM_E = 0x7Bu; //6309
|
||||
constexpr auto INC_E = 0x7Cu;
|
||||
constexpr auto TST_E = 0x7Du;
|
||||
constexpr auto JMP_E = 0x7Eu;
|
||||
constexpr auto CLR_E = 0x7Fu;
|
||||
|
||||
constexpr auto SUBA_M = 0x80u;
|
||||
constexpr auto CMPA_M = 0x81u;
|
||||
constexpr auto SBCA_M = 0x82u;
|
||||
constexpr auto SUBD_M = 0x83u;
|
||||
constexpr auto ANDA_M = 0x84u;
|
||||
constexpr auto BITA_M = 0x85u;
|
||||
constexpr auto LDA_M = 0x86u;
|
||||
constexpr auto EORA_M = 0x88u;
|
||||
constexpr auto ADCA_M = 0x89u;
|
||||
constexpr auto ORA_M = 0x8Au;
|
||||
constexpr auto ADDA_M = 0x8Bu;
|
||||
constexpr auto CMPX_M = 0x8Cu;
|
||||
constexpr auto BSR_R = 0x8Du;
|
||||
constexpr auto LDX_M = 0x8Eu;
|
||||
|
||||
constexpr auto SUBA_D = 0x90u;
|
||||
constexpr auto CMPA_D = 0x91u;
|
||||
constexpr auto SBCA_D = 0x92u;
|
||||
constexpr auto SUBD_D = 0x93u;
|
||||
constexpr auto ANDA_D = 0x94u;
|
||||
constexpr auto BITA_D = 0x95u;
|
||||
constexpr auto LDA_D = 0x96u;
|
||||
constexpr auto STA_D = 0x97u;
|
||||
constexpr auto EORA_D = 0x98u;
|
||||
constexpr auto ADCA_D = 0x99u;
|
||||
constexpr auto ORA_D = 0x9Au;
|
||||
constexpr auto ADDA_D = 0x9Bu;
|
||||
constexpr auto CMPX_D = 0x9Cu;
|
||||
constexpr auto BSR_D = 0x9Du;
|
||||
constexpr auto LDX_D = 0x9Eu;
|
||||
constexpr auto STX_D = 0x9Fu;
|
||||
|
||||
constexpr auto SUBA_X = 0xA0u;
|
||||
constexpr auto CMPA_X = 0xA1u;
|
||||
constexpr auto SBCA_X = 0xA2u;
|
||||
constexpr auto SUBD_X = 0xA3u;
|
||||
constexpr auto ANDA_X = 0xA4u;
|
||||
constexpr auto BITA_X = 0xA5u;
|
||||
constexpr auto LDA_X = 0xA6u;
|
||||
constexpr auto STA_X = 0xA7u;
|
||||
constexpr auto EORA_X = 0xA8u;
|
||||
constexpr auto ADCA_X = 0xA9u;
|
||||
constexpr auto ORA_X = 0xAAu;
|
||||
constexpr auto ADDA_X = 0xABu;
|
||||
constexpr auto CMPX_X = 0xACu;
|
||||
constexpr auto BSR_X = 0xADu;
|
||||
constexpr auto LDX_X = 0xAEu;
|
||||
constexpr auto STX_X = 0xAFu;
|
||||
|
||||
constexpr auto SUBA_E = 0xB0u;
|
||||
constexpr auto CMPA_E = 0xB1u;
|
||||
constexpr auto SBCA_E = 0xB2u;
|
||||
constexpr auto SUBD_E = 0xB3u;
|
||||
constexpr auto ANDA_E = 0xB4u;
|
||||
constexpr auto BITA_E = 0xB5u;
|
||||
constexpr auto LDA_E = 0xB6u;
|
||||
constexpr auto STA_E = 0xB7u;
|
||||
constexpr auto EORA_E = 0xB8u;
|
||||
constexpr auto ADCA_E = 0xB9u;
|
||||
constexpr auto ORA_E = 0xBAu;
|
||||
constexpr auto ADDA_E = 0xBBu;
|
||||
constexpr auto CMPX_E = 0xBCu;
|
||||
constexpr auto BSR_E = 0xBDu;
|
||||
constexpr auto LDX_E = 0xBEu;
|
||||
constexpr auto STX_E = 0xBFu;
|
||||
|
||||
constexpr auto SUBB_M = 0xC0u;
|
||||
constexpr auto CMPB_M = 0xC1u;
|
||||
constexpr auto SBCB_M = 0xC2u;
|
||||
constexpr auto ADDD_M = 0xC3u;
|
||||
constexpr auto ANDB_M = 0xC4u;
|
||||
constexpr auto BITB_M = 0xC5u;
|
||||
constexpr auto LDB_M = 0xC6u;
|
||||
constexpr auto EORB_M = 0xC8u;
|
||||
constexpr auto ADCB_M = 0xC9u;
|
||||
constexpr auto ORB_M = 0xCAu;
|
||||
constexpr auto ADDB_M = 0xCBu;
|
||||
constexpr auto LDD_M = 0xCCu;
|
||||
constexpr auto LDQ_M = 0xCDu; //6309
|
||||
constexpr auto LDU_M = 0xCEu;
|
||||
|
||||
constexpr auto SUBB_D = 0xD0u;
|
||||
constexpr auto CMPB_D = 0xD1u;
|
||||
constexpr auto SBCB_D = 0xD2u;
|
||||
constexpr auto ADDD_D = 0xD3u;
|
||||
constexpr auto ANDB_D = 0xD4u;
|
||||
constexpr auto BITB_D = 0xD5u;
|
||||
constexpr auto LDB_D = 0xD6u;
|
||||
constexpr auto STB_D = 0XD7u;
|
||||
constexpr auto EORB_D = 0xD8u;
|
||||
constexpr auto ADCB_D = 0xD9u;
|
||||
constexpr auto ORB_D = 0xDAu;
|
||||
constexpr auto ADDB_D = 0xDBu;
|
||||
constexpr auto LDD_D = 0xDCu;
|
||||
constexpr auto STD_D = 0xDDu;
|
||||
constexpr auto LDU_D = 0xDEu;
|
||||
constexpr auto STU_D = 0xDFu;
|
||||
|
||||
constexpr auto SUBB_X = 0xE0u;
|
||||
constexpr auto CMPB_X = 0xE1u;
|
||||
constexpr auto SBCB_X = 0xE2u;
|
||||
constexpr auto ADDD_X = 0xE3u;
|
||||
constexpr auto ANDB_X = 0xE4u;
|
||||
constexpr auto BITB_X = 0xE5u;
|
||||
constexpr auto LDB_X = 0xE6u;
|
||||
constexpr auto STB_X = 0xE7u;
|
||||
constexpr auto EORB_X = 0xE8u;
|
||||
constexpr auto ADCB_X = 0xE9u;
|
||||
constexpr auto ORB_X = 0xEAu;
|
||||
constexpr auto ADDB_X = 0xEBu;
|
||||
constexpr auto LDD_X = 0xECu;
|
||||
constexpr auto STD_X = 0xEDu;
|
||||
constexpr auto LDU_X = 0xEEu;
|
||||
constexpr auto STU_X = 0xEFu;
|
||||
|
||||
constexpr auto SUBB_E = 0xF0u;
|
||||
constexpr auto CMPB_E = 0xF1u;
|
||||
constexpr auto SBCB_E = 0xF2u;
|
||||
constexpr auto ADDD_E = 0xF3u;
|
||||
constexpr auto ANDB_E = 0xF4u;
|
||||
constexpr auto BITB_E = 0xF5u;
|
||||
constexpr auto LDB_E = 0xF6u;
|
||||
constexpr auto STB_E = 0xF7u;
|
||||
constexpr auto EORB_E = 0xF8u;
|
||||
constexpr auto ADCB_E = 0xF9u;
|
||||
constexpr auto ORB_E = 0xFAu;
|
||||
constexpr auto ADDB_E = 0xFBu;
|
||||
constexpr auto LDD_E = 0xFCu;
|
||||
constexpr auto STD_E = 0xFDu;
|
||||
constexpr auto LDU_E = 0xFEu;
|
||||
constexpr auto STU_E = 0xFFu;
|
||||
|
||||
//******************Page 2 Codes*****************************
|
||||
constexpr auto LBRN_R = 0x21u;
|
||||
constexpr auto LBHI_R = 0x22u;
|
||||
constexpr auto LBLS_R = 0x23u;
|
||||
constexpr auto LBHS_R = 0x24u;
|
||||
constexpr auto LBCS_R = 0x25u;
|
||||
constexpr auto LBNE_R = 0x26u;
|
||||
constexpr auto LBEQ_R = 0x27u;
|
||||
constexpr auto LBVC_R = 0x28u;
|
||||
constexpr auto LBVS_R = 0x29u;
|
||||
constexpr auto LBPL_R = 0x2Au;
|
||||
constexpr auto LBMI_R = 0x2Bu;
|
||||
constexpr auto LBGE_R = 0x2Cu;
|
||||
constexpr auto LBLT_R = 0x2Du;
|
||||
constexpr auto LBGT_R = 0x2Eu;
|
||||
constexpr auto LBLE_R = 0x2Fu;
|
||||
constexpr auto ADDR = 0x30u; //6309
|
||||
constexpr auto ADCR = 0x31u; //6309
|
||||
constexpr auto SUBR = 0x32u; //6309
|
||||
constexpr auto SBCR = 0x33u; //6309
|
||||
constexpr auto ANDR = 0x34u; //6309
|
||||
constexpr auto ORR = 0x35u; //6309
|
||||
constexpr auto EORR = 0x36u; //6309
|
||||
constexpr auto CMPR = 0x37u; //6309
|
||||
constexpr auto PSHSW = 0x38u; //6309
|
||||
constexpr auto PULSW = 0x39u; //6309
|
||||
constexpr auto PSHUW = 0x3Au; //6309
|
||||
constexpr auto PULUW = 0x3Bu; //6309
|
||||
constexpr auto SWI2_I = 0x3Fu;
|
||||
constexpr auto NEGD_I = 0x40u; //6309
|
||||
constexpr auto COMD_I = 0x43u; //6309
|
||||
constexpr auto LSRD_I = 0x44u; //6309
|
||||
constexpr auto RORD_I = 0x46u; //6309
|
||||
constexpr auto ASRD_I = 0x47u; //6309
|
||||
constexpr auto ASLD_I = 0x48u; //6309
|
||||
constexpr auto ROLD_I = 0x49u; //6309
|
||||
constexpr auto DECD_I = 0x4Au; //6309
|
||||
constexpr auto INCD_I = 0x4Cu; //6309
|
||||
constexpr auto TSTD_I = 0x4Du; //6309
|
||||
constexpr auto CLRD_I = 0x4Fu; //6309
|
||||
constexpr auto COMW_I = 0x53u; //6309
|
||||
constexpr auto LSRW_I = 0x54u; //6309
|
||||
constexpr auto RORW_I = 0x56u; //6309
|
||||
constexpr auto ROLW_I = 0x59u; //6309
|
||||
constexpr auto DECW_I = 0x5Au; //6309
|
||||
constexpr auto INCW_I = 0x5Cu; //6309
|
||||
constexpr auto TSTW_I = 0x5Du; //6309
|
||||
constexpr auto CLRW_I = 0x5Fu; //6309
|
||||
constexpr auto SUBW_M = 0x80u; //6309
|
||||
constexpr auto CMPW_M = 0x81u; //6309
|
||||
constexpr auto SBCD_M = 0x82u; //6309
|
||||
constexpr auto CMPD_M = 0x83u;
|
||||
constexpr auto ANDD_M = 0x84u; //6309
|
||||
constexpr auto BITD_M = 0x85u; //6309
|
||||
constexpr auto LDW_M = 0x86u; //6309
|
||||
constexpr auto EORD_M = 0x88u; //6309
|
||||
constexpr auto ADCD_M = 0x89u; //6309
|
||||
constexpr auto ORD_M = 0x8Au; //6309
|
||||
constexpr auto ADDW_M = 0x8Bu; //6309
|
||||
constexpr auto CMPY_M = 0x8Cu;
|
||||
constexpr auto LDY_M = 0x8Eu;
|
||||
constexpr auto SUBW_D = 0x90u; //6309
|
||||
constexpr auto CMPW_D = 0x91u; //6309
|
||||
constexpr auto SBCD_D = 0x92u; //6309
|
||||
constexpr auto CMPD_D = 0x93u;
|
||||
constexpr auto ANDD_D = 0x94u; //6309
|
||||
constexpr auto BITD_D = 0x95u; //6309
|
||||
constexpr auto LDW_D = 0x96u; //6309
|
||||
constexpr auto STW_D = 0x97u; //6309
|
||||
constexpr auto EORD_D = 0x98u; //6309
|
||||
constexpr auto ADCD_D = 0x99u; //6309
|
||||
constexpr auto ORD_D = 0x9Au; //6309
|
||||
constexpr auto ADDW_D = 0x9Bu; //6309
|
||||
constexpr auto CMPY_D = 0x9Cu;
|
||||
constexpr auto LDY_D = 0x9Eu;
|
||||
constexpr auto STY_D = 0x9Fu;
|
||||
constexpr auto SUBW_X = 0xA0u; //6309
|
||||
constexpr auto CMPW_X = 0xA1u; //6309
|
||||
constexpr auto SBCD_X = 0xA2u; //6309
|
||||
constexpr auto CMPD_X = 0xA3u;
|
||||
constexpr auto ANDD_X = 0xA4u; //6309
|
||||
constexpr auto BITD_X = 0xA5u; //6309
|
||||
constexpr auto LDW_X = 0xA6u; //6309
|
||||
constexpr auto STW_X = 0xA7u; //6309
|
||||
constexpr auto EORD_X = 0xA8u; //6309
|
||||
constexpr auto ADCD_X = 0xA9u; //6309
|
||||
constexpr auto ORD_X = 0xAAu; //6309
|
||||
constexpr auto ADDW_X = 0xABu; //6309
|
||||
constexpr auto CMPY_X = 0xACu;
|
||||
constexpr auto LDY_X = 0xAEu;
|
||||
constexpr auto STY_X = 0xAFu;
|
||||
constexpr auto SUBW_E = 0xB0u; //6309
|
||||
constexpr auto CMPW_E = 0xB1u; //6309
|
||||
constexpr auto SBCD_E = 0xB2u; //6309
|
||||
constexpr auto CMPD_E = 0xB3u;
|
||||
constexpr auto ANDD_E = 0xB4u; //6309
|
||||
constexpr auto BITD_E = 0xB5u; //6309
|
||||
constexpr auto LDW_E = 0xB6u; //6309
|
||||
constexpr auto STW_E = 0xB7u; //6309
|
||||
constexpr auto EORD_E = 0xB8u; //6309
|
||||
constexpr auto ADCD_E = 0xB9u; //6309
|
||||
constexpr auto ORD_E = 0xBAu; //6309
|
||||
constexpr auto ADDW_E = 0xBBu; //6309
|
||||
constexpr auto CMPY_E = 0xBCu;
|
||||
constexpr auto LDY_E = 0xBEu;
|
||||
constexpr auto STY_E = 0xBFu;
|
||||
constexpr auto LDS_I = 0xCEu;
|
||||
constexpr auto LDQ_D = 0xDCu; //6309
|
||||
constexpr auto STQ_D = 0xDDu; //6309
|
||||
constexpr auto LDS_D = 0xDEu;
|
||||
constexpr auto STS_D = 0xDFu;
|
||||
constexpr auto LDQ_X = 0xECu;
|
||||
constexpr auto STQ_X = 0xEDu;
|
||||
constexpr auto LDS_X = 0xEEu;
|
||||
constexpr auto STS_X = 0xEFu;
|
||||
constexpr auto LDQ_E = 0xFCu; //6309
|
||||
constexpr auto STQ_E = 0xFDu; //6309
|
||||
constexpr auto LDS_E = 0xFEu;
|
||||
constexpr auto STS_E = 0xFFu;
|
||||
|
||||
//*******************Page 3 Codes*********************************
|
||||
constexpr auto BAND = 0x30u; //6309
|
||||
constexpr auto BIAND = 0x31u; //6309
|
||||
constexpr auto BOR = 0x32u; //6309
|
||||
constexpr auto BIOR = 0x33u; //6309
|
||||
constexpr auto BEOR = 0x34u; //6309
|
||||
constexpr auto BIEOR = 0x35u; //6309
|
||||
constexpr auto LDBT = 0x36u; //6309
|
||||
constexpr auto STBT = 0x37u; //6309
|
||||
constexpr auto TFM1 = 0x38u; //6309
|
||||
constexpr auto TFM2 = 0x39u; //6309
|
||||
constexpr auto TFM3 = 0x3Au; //6309
|
||||
constexpr auto TFM4 = 0x3Bu; //6309
|
||||
constexpr auto BITMD_M = 0x3Cu; //6309
|
||||
constexpr auto LDMD_M = 0x3Du; //6309
|
||||
constexpr auto BREAK = 0x3Eu; //VCC Halt_0x113e
|
||||
constexpr auto SWI3_I = 0x3Fu;
|
||||
constexpr auto COME_I = 0x43u; //6309
|
||||
constexpr auto DECE_I = 0x4Au; //6309
|
||||
constexpr auto INCE_I = 0x4Cu; //6309
|
||||
constexpr auto TSTE_I = 0x4Du; //6309
|
||||
constexpr auto CLRE_I = 0x4Fu; //6309
|
||||
constexpr auto COMF_I = 0x53u; //6309
|
||||
constexpr auto DECF_I = 0x5Au; //6309
|
||||
constexpr auto INCF_I = 0x5Cu; //6309
|
||||
constexpr auto TSTF_I = 0x5Du; //6309
|
||||
constexpr auto CLRF_I = 0x5Fu; //6309
|
||||
constexpr auto SUBE_M = 0x80u; //6309
|
||||
constexpr auto CMPE_M = 0x81u; //6309
|
||||
constexpr auto CMPU_M = 0x83u;
|
||||
constexpr auto LDE_M = 0x86u; //6309
|
||||
constexpr auto ADDE_M = 0x8Bu; //6309
|
||||
constexpr auto CMPS_M = 0x8Cu;
|
||||
constexpr auto DIVD_M = 0x8Du; //6309
|
||||
constexpr auto DIVQ_M = 0x8Eu; //6309
|
||||
constexpr auto MULD_M = 0x8Fu; //6309
|
||||
constexpr auto SUBE_D = 0x90u; //6309
|
||||
constexpr auto CMPE_D = 0x91u; //6309
|
||||
constexpr auto CMPU_D = 0x93u;
|
||||
constexpr auto LDE_D = 0x96u; //6309
|
||||
constexpr auto STE_D = 0x97u; //6309
|
||||
constexpr auto ADDE_D = 0x9Bu; //6309
|
||||
constexpr auto CMPS_D = 0x9Cu;
|
||||
constexpr auto DIVD_D = 0x9Du; //6309
|
||||
constexpr auto DIVQ_D = 0x9Eu; //6309
|
||||
constexpr auto MULD_D = 0x9Fu; //6309
|
||||
constexpr auto SUBE_X = 0xA0u; //6309
|
||||
constexpr auto CMPE_X = 0xA1u; //6309
|
||||
constexpr auto CMPU_X = 0xA3u;
|
||||
constexpr auto LDE_X = 0xA6u; //6309
|
||||
constexpr auto STE_X = 0xA7u; //6309
|
||||
constexpr auto ADDE_X = 0xABu; //6309
|
||||
constexpr auto CMPS_X = 0xACu;
|
||||
constexpr auto DIVD_X = 0xADu; //6309
|
||||
constexpr auto DIVQ_X = 0xAEu; //6309
|
||||
constexpr auto MULD_X = 0xAFu; //6309
|
||||
constexpr auto SUBE_E = 0xB0u; //6309
|
||||
constexpr auto CMPE_E = 0xB1u; //6309
|
||||
constexpr auto CMPU_E = 0xB3u;
|
||||
constexpr auto LDE_E = 0xB6u; //6309
|
||||
constexpr auto STE_E = 0xB7u; //6309
|
||||
constexpr auto ADDE_E = 0xBBu; //6309
|
||||
constexpr auto CMPS_E = 0xBCu;
|
||||
constexpr auto DIVD_E = 0xBDu; //6309
|
||||
constexpr auto DIVQ_E = 0xBEu; //6309
|
||||
constexpr auto MULD_E = 0xBFu; //6309
|
||||
constexpr auto SUBF_M = 0xC0u; //6309
|
||||
constexpr auto CMPF_M = 0xC1u; //6309
|
||||
constexpr auto LDF_M = 0xC6u; //6309
|
||||
constexpr auto ADDF_M = 0xCBu; //6309
|
||||
constexpr auto SUBF_D = 0xD0u; //6309
|
||||
constexpr auto CMPF_D = 0xD1u; //6309
|
||||
constexpr auto LDF_D = 0xD6u; //6309
|
||||
constexpr auto STF_D = 0xD7u; //6309
|
||||
constexpr auto ADDF_D = 0xDBu; //6309
|
||||
constexpr auto SUBF_X = 0xE0u; //6309
|
||||
constexpr auto CMPF_X = 0xE1u; //6309
|
||||
constexpr auto LDF_X = 0xE6u; //6309
|
||||
constexpr auto STF_X = 0xE7u; //6309
|
||||
constexpr auto ADDF_X = 0xEBu; //6309
|
||||
constexpr auto SUBF_E = 0xF0u; //6309
|
||||
constexpr auto CMPF_E = 0xF1u; //6309
|
||||
constexpr auto LDF_E = 0xF6u; //6309
|
||||
constexpr auto STF_E = 0xF7u; //6309
|
||||
constexpr auto ADDF_E = 0xFBu; //6309
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "iobus.h"
|
||||
#include "mc6821.h"
|
||||
#include "tcc1014registers.h"
|
||||
#include "MachineHost.h"
|
||||
unsigned char port_read(unsigned short addr)
|
||||
{
|
||||
unsigned char port=0,temp=0;
|
||||
port = (addr & 0xFF);
|
||||
|
||||
switch (port)
|
||||
{
|
||||
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
temp=pia0_read(port); //MC6821 P.I.A Keyboard access $FF00-$FF03
|
||||
break;
|
||||
|
||||
case 0x20:
|
||||
case 0x21:
|
||||
case 0x22:
|
||||
case 0x23:
|
||||
|
||||
temp=pia1_read(port); //MC6821 P.I.A Sound and VDG Control
|
||||
break;
|
||||
|
||||
case 0xC0:
|
||||
case 0xC1:
|
||||
case 0xC2:
|
||||
case 0xC3:
|
||||
case 0xC4:
|
||||
case 0xC5:
|
||||
case 0xC6:
|
||||
case 0xC7:
|
||||
case 0xC8:
|
||||
case 0xC9:
|
||||
case 0xCA:
|
||||
case 0xCB:
|
||||
case 0xCC:
|
||||
case 0xCD:
|
||||
case 0xCE:
|
||||
case 0xCF:
|
||||
case 0xD0:
|
||||
case 0xD1:
|
||||
case 0xD2:
|
||||
case 0xD3:
|
||||
case 0xD4:
|
||||
case 0xD5:
|
||||
case 0xD6:
|
||||
case 0xD7:
|
||||
case 0xD8:
|
||||
case 0xD9:
|
||||
case 0xDA:
|
||||
case 0xDB:
|
||||
case 0xDC:
|
||||
case 0xDD:
|
||||
case 0xDE:
|
||||
case 0xDF:
|
||||
temp=sam_read(port); //MC6883 S.A.M. address range $FFC0-$FFDF
|
||||
break;
|
||||
|
||||
case 0xF0:
|
||||
case 0xF1:
|
||||
case 0xF2:
|
||||
case 0xF3:
|
||||
case 0xF4:
|
||||
case 0xF5:
|
||||
case 0xF6:
|
||||
case 0xF7:
|
||||
case 0xF8:
|
||||
case 0xF9:
|
||||
case 0xFA:
|
||||
case 0xFB:
|
||||
case 0xFC:
|
||||
case 0xFD:
|
||||
case 0xFE:
|
||||
case 0xFF:
|
||||
temp=sam_read(port); // SAM controls IRQ Vectors at $FFF0 - $FFFF
|
||||
break;
|
||||
|
||||
case 0x90: //TCC1014 G.I.M.E.
|
||||
case 0x91:
|
||||
case 0x92:
|
||||
case 0x93:
|
||||
case 0x94:
|
||||
case 0x95:
|
||||
case 0x96:
|
||||
case 0x97:
|
||||
case 0x98:
|
||||
case 0x99:
|
||||
case 0x9A:
|
||||
case 0x9B:
|
||||
case 0x9C:
|
||||
case 0x9D:
|
||||
case 0x9E:
|
||||
case 0x9F:
|
||||
case 0xA0:
|
||||
case 0xA1:
|
||||
case 0xA2:
|
||||
case 0xA3:
|
||||
case 0xA4:
|
||||
case 0xA5:
|
||||
case 0xA6:
|
||||
case 0xA7:
|
||||
case 0xA8:
|
||||
case 0xA9:
|
||||
case 0xAA:
|
||||
case 0xAB:
|
||||
case 0xAC:
|
||||
case 0xAD:
|
||||
case 0xAE:
|
||||
case 0xAF:
|
||||
case 0xB0:
|
||||
case 0xB1:
|
||||
case 0xB2:
|
||||
case 0xB3:
|
||||
case 0xB4:
|
||||
case 0xB5:
|
||||
case 0xB6:
|
||||
case 0xB7:
|
||||
case 0xB8:
|
||||
case 0xB9:
|
||||
case 0xBA:
|
||||
case 0xBB:
|
||||
case 0xBC:
|
||||
case 0xBD:
|
||||
case 0xBE:
|
||||
case 0xBF:
|
||||
temp=GimeRead(port);
|
||||
break;
|
||||
default:
|
||||
temp=VCC::Machine().CartridgePortRead(port);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
void port_write(unsigned char data,unsigned short addr)
|
||||
{
|
||||
unsigned char port=0;
|
||||
port = (addr & 0xFF);
|
||||
|
||||
switch (port)
|
||||
{
|
||||
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
pia0_write(data,port); //MC6821 P.I.A Keyboard access $FF00-$FF03
|
||||
break;
|
||||
|
||||
case 0x20:
|
||||
case 0x21:
|
||||
case 0x22:
|
||||
case 0x23:
|
||||
pia1_write(data,port); //MC6821 P.I.A Sound and VDG Control
|
||||
break;
|
||||
|
||||
case 0xC0:
|
||||
case 0xC1:
|
||||
case 0xC2:
|
||||
case 0xC3:
|
||||
case 0xC4:
|
||||
case 0xC5:
|
||||
case 0xC6:
|
||||
case 0xC7:
|
||||
case 0xC8:
|
||||
case 0xC9:
|
||||
case 0xCA:
|
||||
case 0xCB:
|
||||
case 0xCC:
|
||||
case 0xCD:
|
||||
case 0xCE:
|
||||
case 0xCF:
|
||||
case 0xD0:
|
||||
case 0xD1:
|
||||
case 0xD2:
|
||||
case 0xD3:
|
||||
case 0xD4:
|
||||
case 0xD5:
|
||||
case 0xD6:
|
||||
case 0xD7:
|
||||
case 0xD8:
|
||||
case 0xD9:
|
||||
case 0xDA:
|
||||
case 0xDB:
|
||||
case 0xDC:
|
||||
case 0xDD:
|
||||
case 0xDE:
|
||||
case 0xDF:
|
||||
sam_write(port); //MC6883 S.A.M. address range $FFC0-$FFDF
|
||||
break;
|
||||
|
||||
case 0x90:
|
||||
case 0x91:
|
||||
case 0x92:
|
||||
case 0x93:
|
||||
case 0x94:
|
||||
case 0x95:
|
||||
case 0x96:
|
||||
case 0x97:
|
||||
case 0x98:
|
||||
case 0x99:
|
||||
case 0x9A:
|
||||
case 0x9B:
|
||||
case 0x9C:
|
||||
case 0x9D:
|
||||
case 0x9E:
|
||||
case 0x9F:
|
||||
case 0xA0:
|
||||
case 0xA1:
|
||||
case 0xA2:
|
||||
case 0xA3:
|
||||
case 0xA4:
|
||||
case 0xA5:
|
||||
case 0xA6:
|
||||
case 0xA7:
|
||||
case 0xA8:
|
||||
case 0xA9:
|
||||
case 0xAA:
|
||||
case 0xAB:
|
||||
case 0xAC:
|
||||
case 0xAD:
|
||||
case 0xAE:
|
||||
case 0xAF:
|
||||
case 0xB0:
|
||||
case 0xB1:
|
||||
case 0xB2:
|
||||
case 0xB3:
|
||||
case 0xB4:
|
||||
case 0xB5:
|
||||
case 0xB6:
|
||||
case 0xB7:
|
||||
case 0xB8:
|
||||
case 0xB9:
|
||||
case 0xBA:
|
||||
case 0xBB:
|
||||
case 0xBC:
|
||||
case 0xBD:
|
||||
case 0xBE:
|
||||
case 0xBF:
|
||||
GimeWrite(port,data);
|
||||
break;
|
||||
default:
|
||||
VCC::Machine().CartridgePortWrite(port,data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef __IOBUS_H__
|
||||
#define __IOBUS_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
unsigned char port_read(unsigned short addr);
|
||||
void port_write(unsigned char data,unsigned short addr);
|
||||
|
||||
#endif
|
||||
+3720
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,36 @@
|
||||
#ifndef __MC6809_H__
|
||||
#define __MC6809_H__
|
||||
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MachineDefs.h"
|
||||
|
||||
void MC6809Init();
|
||||
int MC6809Exec( int);
|
||||
void MC6809Reset();
|
||||
void MC6809AssertInterupt(InterruptSource, Interrupt);
|
||||
void MC6809DeAssertInterupt(InterruptSource, Interrupt);
|
||||
void MC6809ForcePC(unsigned short);
|
||||
void MC6809PrepareBasicCall(unsigned short stack);
|
||||
void MC6809SetBreakpoints(const std::vector<unsigned short>& breakpoints);
|
||||
void MC6809SetTraceTriggers(const std::vector<unsigned short>& triggers);
|
||||
VCC::CPUState MC6809GetState();
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//CC Flag masks
|
||||
constexpr auto E = 7u;
|
||||
constexpr auto F = 6u;
|
||||
constexpr auto H = 5u;
|
||||
constexpr auto I = 4u;
|
||||
constexpr auto N = 3u;
|
||||
constexpr auto Z = 2u;
|
||||
constexpr auto V = 1u;
|
||||
constexpr auto C = 0u;
|
||||
|
||||
// MC6809 Vector table
|
||||
constexpr auto VSWI3 = 0xFFF2u;
|
||||
constexpr auto VSWI2 = 0xFFF4u;
|
||||
constexpr auto VFIRQ = 0xFFF6u;
|
||||
constexpr auto VIRQ = 0xFFF8u;
|
||||
constexpr auto VSWI = 0xFFFAu;
|
||||
constexpr auto VNMI = 0xFFFCu;
|
||||
constexpr auto VRESET = 0xFFFEu;
|
||||
|
||||
//Opcode Defs
|
||||
//Last Char (D) Direct (I) Inherent (R) Relative (M) Immediate (X) Indexed (E) extened
|
||||
constexpr auto NEG_D = 0x00u;
|
||||
constexpr auto COM_D = 0x03u;
|
||||
constexpr auto LSR_D = 0x04u;
|
||||
constexpr auto ROR_D = 0x06u;
|
||||
constexpr auto ASR_D = 0x07u;
|
||||
constexpr auto ASL_D = 0x08u;
|
||||
constexpr auto ROL_D = 0x09u;
|
||||
constexpr auto DEC_D = 0x0Au;
|
||||
constexpr auto INC_D = 0x0Cu;
|
||||
constexpr auto TST_D = 0x0Du;
|
||||
constexpr auto JMP_D = 0x0Eu;
|
||||
constexpr auto CLR_D = 0x0Fu;
|
||||
|
||||
constexpr auto Page2 = 0x10u;
|
||||
constexpr auto Page3 = 0x11u;
|
||||
constexpr auto NOP_I = 0x12u;
|
||||
constexpr auto SYNC_I = 0x13u;
|
||||
constexpr auto HALT = 0x15u; // Vcc Halt_15
|
||||
constexpr auto LBRA_R = 0x16u;
|
||||
constexpr auto LBSR_R = 0x17u;
|
||||
constexpr auto DAA_I = 0x19u;
|
||||
constexpr auto ORCC_M = 0x1Au;
|
||||
constexpr auto ANDCC_M = 0x1Cu;
|
||||
constexpr auto SEX_I = 0x1Du;
|
||||
constexpr auto EXG_M = 0x1Eu;
|
||||
constexpr auto TFR_M = 0x1Fu;
|
||||
|
||||
constexpr auto BRA_R = 0x20u;
|
||||
constexpr auto BRN_R = 0x21u;
|
||||
constexpr auto BHI_R = 0x22u;
|
||||
constexpr auto BLS_R = 0x23u;
|
||||
constexpr auto BHS_R = 0x24u;
|
||||
constexpr auto BLO_R = 0x25u;
|
||||
constexpr auto BNE_R = 0x26u;
|
||||
constexpr auto BEQ_R = 0x27u;
|
||||
constexpr auto BVC_R = 0x28u;
|
||||
constexpr auto BVS_R = 0x29u;
|
||||
constexpr auto BPL_R = 0x2Au;
|
||||
constexpr auto BMI_R = 0x2Bu;
|
||||
constexpr auto BGE_R = 0x2Cu;
|
||||
constexpr auto BLT_R = 0x2Du;
|
||||
constexpr auto BGT_R = 0x2Eu;
|
||||
constexpr auto BLE_R = 0x2Fu;
|
||||
|
||||
constexpr auto LEAX_X = 0x30u;
|
||||
constexpr auto LEAY_X = 0x31u;
|
||||
constexpr auto LEAS_X = 0x32u;
|
||||
constexpr auto LEAU_X = 0x33u;
|
||||
constexpr auto PSHS_M = 0x34u;
|
||||
constexpr auto PULS_M = 0x35u;
|
||||
constexpr auto PSHU_M = 0x36u;
|
||||
constexpr auto PULU_M = 0x37u;
|
||||
constexpr auto RTS_I = 0x39u;
|
||||
constexpr auto ABX_I = 0x3Au;
|
||||
constexpr auto RTI_I = 0x3Bu;
|
||||
constexpr auto CWAI_I = 0x3Cu;
|
||||
constexpr auto MUL_I = 0x3Du;
|
||||
constexpr auto RESET = 0x3Eu; //Undocumented instruction
|
||||
constexpr auto SWI1_I = 0x3Fu;
|
||||
|
||||
constexpr auto NEGA_I = 0x40u;
|
||||
constexpr auto COMA_I = 0x43u;
|
||||
constexpr auto LSRA_I = 0x44u;
|
||||
constexpr auto RORA_I = 0x46u;
|
||||
constexpr auto ASRA_I = 0x47u;
|
||||
constexpr auto ASLA_I = 0x48u;
|
||||
constexpr auto ROLA_I = 0x49u;
|
||||
constexpr auto DECA_I = 0x4Au;
|
||||
constexpr auto INCA_I = 0x4Cu;
|
||||
constexpr auto TSTA_I = 0x4Du;
|
||||
constexpr auto CLRA_I = 0x4Fu;
|
||||
|
||||
constexpr auto NEGB_I = 0x50u;
|
||||
constexpr auto COMB_I = 0x53u;
|
||||
constexpr auto LSRB_I = 0x54u;
|
||||
constexpr auto RORB_I = 0x56u;
|
||||
constexpr auto ASRB_I = 0x57u;
|
||||
constexpr auto ASLB_I = 0x58u;
|
||||
constexpr auto ROLB_I = 0x59u;
|
||||
constexpr auto DECB_I = 0x5Au;
|
||||
constexpr auto INCB_I = 0x5Cu;
|
||||
constexpr auto TSTB_I = 0x5Du;
|
||||
constexpr auto CLRB_I = 0x5Fu;
|
||||
|
||||
constexpr auto NEG_X = 0x60u;
|
||||
constexpr auto COM_X = 0x63u;
|
||||
constexpr auto LSR_X = 0x64u;
|
||||
constexpr auto ROR_X = 0x66u;
|
||||
constexpr auto ASR_X = 0x67u;
|
||||
constexpr auto ASL_X = 0x68u;
|
||||
constexpr auto ROL_X = 0x69u;
|
||||
constexpr auto DEC_X = 0x6Au;
|
||||
constexpr auto INC_X = 0x6Cu;
|
||||
constexpr auto TST_X = 0x6Du;
|
||||
constexpr auto JMP_X = 0x6Eu;
|
||||
constexpr auto CLR_X = 0x6Fu;
|
||||
|
||||
constexpr auto NEG_E = 0x70u;
|
||||
constexpr auto COM_E = 0x73u;
|
||||
constexpr auto LSR_E = 0x74u;
|
||||
constexpr auto ROR_E = 0x76u;
|
||||
constexpr auto ASR_E = 0x77u;
|
||||
constexpr auto ASL_E = 0x78u;
|
||||
constexpr auto ROL_E = 0x79u;
|
||||
constexpr auto DEC_E = 0x7Au;
|
||||
constexpr auto INC_E = 0x7Cu;
|
||||
constexpr auto TST_E = 0x7Du;
|
||||
constexpr auto JMP_E = 0x7Eu;
|
||||
constexpr auto CLR_E = 0x7Fu;
|
||||
|
||||
constexpr auto SUBA_M = 0x80u;
|
||||
constexpr auto CMPA_M = 0x81u;
|
||||
constexpr auto SBCA_M = 0x82u;
|
||||
constexpr auto SUBD_M = 0x83u;
|
||||
constexpr auto ANDA_M = 0x84u;
|
||||
constexpr auto BITA_M = 0x85u;
|
||||
constexpr auto LDA_M = 0x86u;
|
||||
constexpr auto EORA_M = 0x88u;
|
||||
constexpr auto ADCA_M = 0x89u;
|
||||
constexpr auto ORA_M = 0x8Au;
|
||||
constexpr auto ADDA_M = 0x8Bu;
|
||||
constexpr auto CMPX_M = 0x8Cu;
|
||||
constexpr auto BSR_R = 0x8Du;
|
||||
constexpr auto LDX_M = 0x8Eu;
|
||||
|
||||
constexpr auto SUBA_D = 0x90u;
|
||||
constexpr auto CMPA_D = 0x91u;
|
||||
constexpr auto SBCA_D = 0x92u;
|
||||
constexpr auto SUBD_D = 0x93u;
|
||||
constexpr auto ANDA_D = 0x94u;
|
||||
constexpr auto BITA_D = 0x95u;
|
||||
constexpr auto LDA_D = 0x96u;
|
||||
constexpr auto STA_D = 0x97u;
|
||||
constexpr auto EORA_D = 0x98u;
|
||||
constexpr auto ADCA_D = 0x99u;
|
||||
constexpr auto ORA_D = 0x9Au;
|
||||
constexpr auto ADDA_D = 0x9Bu;
|
||||
constexpr auto CMPX_D = 0x9Cu;
|
||||
constexpr auto BSR_D = 0x9Du;
|
||||
constexpr auto LDX_D = 0x9Eu;
|
||||
constexpr auto STX_D = 0x9Fu;
|
||||
|
||||
constexpr auto SUBA_X = 0xA0u;
|
||||
constexpr auto CMPA_X = 0xA1u;
|
||||
constexpr auto SBCA_X = 0xA2u;
|
||||
constexpr auto SUBD_X = 0xA3u;
|
||||
constexpr auto ANDA_X = 0xA4u;
|
||||
constexpr auto BITA_X = 0xA5u;
|
||||
constexpr auto LDA_X = 0xA6u;
|
||||
constexpr auto STA_X = 0xA7u;
|
||||
constexpr auto EORA_X = 0xA8u;
|
||||
constexpr auto ADCA_X = 0xA9u;
|
||||
constexpr auto ORA_X = 0xAAu;
|
||||
constexpr auto ADDA_X = 0xABu;
|
||||
constexpr auto CMPX_X = 0xACu;
|
||||
constexpr auto BSR_X = 0xADu;
|
||||
constexpr auto LDX_X = 0xAEu;
|
||||
constexpr auto STX_X = 0xAFu;
|
||||
|
||||
constexpr auto SUBA_E = 0xB0u;
|
||||
constexpr auto CMPA_E = 0xB1u;
|
||||
constexpr auto SBCA_E = 0xB2u;
|
||||
constexpr auto SUBD_E = 0xB3u;
|
||||
constexpr auto ANDA_E = 0xB4u;
|
||||
constexpr auto BITA_E = 0xB5u;
|
||||
constexpr auto LDA_E = 0xB6u;
|
||||
constexpr auto STA_E = 0xB7u;
|
||||
constexpr auto EORA_E = 0xB8u;
|
||||
constexpr auto ADCA_E = 0xB9u;
|
||||
constexpr auto ORA_E = 0xBAu;
|
||||
constexpr auto ADDA_E = 0xBBu;
|
||||
constexpr auto CMPX_E = 0xBCu;
|
||||
constexpr auto BSR_E = 0xBDu;
|
||||
constexpr auto LDX_E = 0xBEu;
|
||||
constexpr auto STX_E = 0xBFu;
|
||||
|
||||
constexpr auto SUBB_M = 0xC0u;
|
||||
constexpr auto CMPB_M = 0xC1u;
|
||||
constexpr auto SBCB_M = 0xC2u;
|
||||
constexpr auto ADDD_M = 0xC3u;
|
||||
constexpr auto ANDB_M = 0xC4u;
|
||||
constexpr auto BITB_M = 0xC5u;
|
||||
constexpr auto LDB_M = 0xC6u;
|
||||
constexpr auto EORB_M = 0xC8u;
|
||||
constexpr auto ADCB_M = 0xC9u;
|
||||
constexpr auto ORB_M = 0xCAu;
|
||||
constexpr auto ADDB_M = 0xCBu;
|
||||
constexpr auto LDD_M = 0xCCu;
|
||||
constexpr auto LDU_M = 0xCEu;
|
||||
|
||||
constexpr auto SUBB_D = 0xD0u;
|
||||
constexpr auto CMPB_D = 0xD1u;
|
||||
constexpr auto SBCB_D = 0xD2u;
|
||||
constexpr auto ADDD_D = 0xD3u;
|
||||
constexpr auto ANDB_D = 0xD4u;
|
||||
constexpr auto BITB_D = 0xD5u;
|
||||
constexpr auto LDB_D = 0xD6u;
|
||||
constexpr auto STB_D = 0XD7u;
|
||||
constexpr auto EORB_D = 0xD8u;
|
||||
constexpr auto ADCB_D = 0xD9u;
|
||||
constexpr auto ORB_D = 0xDAu;
|
||||
constexpr auto ADDB_D = 0xDBu;
|
||||
constexpr auto LDD_D = 0xDCu;
|
||||
constexpr auto STD_D = 0xDDu;
|
||||
constexpr auto LDU_D = 0xDEu;
|
||||
constexpr auto STU_D = 0xDFu;
|
||||
|
||||
constexpr auto SUBB_X = 0xE0u;
|
||||
constexpr auto CMPB_X = 0xE1u;
|
||||
constexpr auto SBCB_X = 0xE2u;
|
||||
constexpr auto ADDD_X = 0xE3u;
|
||||
constexpr auto ANDB_X = 0xE4u;
|
||||
constexpr auto BITB_X = 0xE5u;
|
||||
constexpr auto LDB_X = 0xE6u;
|
||||
constexpr auto STB_X = 0xE7u;
|
||||
constexpr auto EORB_X = 0xE8u;
|
||||
constexpr auto ADCB_X = 0xE9u;
|
||||
constexpr auto ORB_X = 0xEAu;
|
||||
constexpr auto ADDB_X = 0xEBu;
|
||||
constexpr auto LDD_X = 0xECu;
|
||||
constexpr auto STD_X = 0xEDu;
|
||||
constexpr auto LDU_X = 0xEEu;
|
||||
constexpr auto STU_X = 0xEFu;
|
||||
|
||||
constexpr auto SUBB_E = 0xF0u;
|
||||
constexpr auto CMPB_E = 0xF1u;
|
||||
constexpr auto SBCB_E = 0xF2u;
|
||||
constexpr auto ADDD_E = 0xF3u;
|
||||
constexpr auto ANDB_E = 0xF4u;
|
||||
constexpr auto BITB_E = 0xF5u;
|
||||
constexpr auto LDB_E = 0xF6u;
|
||||
constexpr auto STB_E = 0xF7u;
|
||||
constexpr auto EORB_E = 0xF8u;
|
||||
constexpr auto ADCB_E = 0xF9u;
|
||||
constexpr auto ORB_E = 0xFAu;
|
||||
constexpr auto ADDB_E = 0xFBu;
|
||||
constexpr auto LDD_E = 0xFCu;
|
||||
constexpr auto STD_E = 0xFDu;
|
||||
constexpr auto LDU_E = 0xFEu;
|
||||
constexpr auto STU_E = 0xFFu;
|
||||
|
||||
//******************Page 2 Codes*****************************
|
||||
constexpr auto LBRN_R = 0x21u;
|
||||
constexpr auto LBHI_R = 0x22u;
|
||||
constexpr auto LBLS_R = 0x23u;
|
||||
constexpr auto LBHS_R = 0x24u;
|
||||
constexpr auto LBCS_R = 0x25u;
|
||||
constexpr auto LBNE_R = 0x26u;
|
||||
constexpr auto LBEQ_R = 0x27u;
|
||||
constexpr auto LBVC_R = 0x28u;
|
||||
constexpr auto LBVS_R = 0x29u;
|
||||
constexpr auto LBPL_R = 0x2Au;
|
||||
constexpr auto LBMI_R = 0x2Bu;
|
||||
constexpr auto LBGE_R = 0x2Cu;
|
||||
constexpr auto LBLT_R = 0x2Du;
|
||||
constexpr auto LBGT_R = 0x2Eu;
|
||||
constexpr auto LBLE_R = 0x2Fu;
|
||||
constexpr auto SWI2_I = 0x3Fu;
|
||||
constexpr auto CMPD_M = 0x83u;
|
||||
constexpr auto CMPY_M = 0x8Cu;
|
||||
constexpr auto LDY_M = 0x8Eu;
|
||||
constexpr auto CMPD_D = 0x93u;
|
||||
constexpr auto CMPY_D = 0x9Cu;
|
||||
constexpr auto LDY_D = 0x9Eu;
|
||||
constexpr auto STY_D = 0x9Fu;
|
||||
constexpr auto CMPD_X = 0xA3u;
|
||||
constexpr auto CMPY_X = 0xACu;
|
||||
constexpr auto LDY_X = 0xAEu;
|
||||
constexpr auto STY_X = 0xAFu;
|
||||
constexpr auto CMPD_E = 0xB3u;
|
||||
constexpr auto CMPY_E = 0xBCu;
|
||||
constexpr auto LDY_E = 0xBEu;
|
||||
constexpr auto STY_E = 0xBFu;
|
||||
constexpr auto LDS_I = 0xCEu;
|
||||
constexpr auto LDS_D = 0xDEu;
|
||||
constexpr auto STS_D = 0xDFu;
|
||||
constexpr auto LDQ_X = 0xECu;
|
||||
constexpr auto STQ_X = 0xEDu;
|
||||
constexpr auto LDS_X = 0xEEu;
|
||||
constexpr auto STS_X = 0xEFu;
|
||||
constexpr auto LDS_E = 0xFEu;
|
||||
constexpr auto STS_E = 0xFFu;
|
||||
|
||||
//*******************Page 3 Codes*********************************
|
||||
constexpr auto BREAK = 0x3Eu; // Vcc Halt_113E
|
||||
constexpr auto SWI3_I = 0x3Fu;
|
||||
constexpr auto CMPU_M = 0x83u;
|
||||
constexpr auto CMPS_M = 0x8Cu;
|
||||
constexpr auto CMPU_D = 0x93u;
|
||||
constexpr auto CMPS_D = 0x9Cu;
|
||||
constexpr auto CMPU_X = 0xA3u;
|
||||
constexpr auto CMPS_X = 0xACu;
|
||||
constexpr auto CMPU_E = 0xB3u;
|
||||
constexpr auto CMPS_E = 0xBCu;
|
||||
@@ -0,0 +1,453 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
$FF00 (65280) PIA 0 side A data
|
||||
Bit 7 Joystick Comparison Input
|
||||
Bit 6 Keyboard Row 7
|
||||
Bit 5 Row 6
|
||||
Bit 4 Row 5
|
||||
Bit 3 Row 4 & Left Joystick Switch 2
|
||||
Bit 2 Row 3 & Right Joystick Switch 2
|
||||
Bit 1 Row 2 & Left Joystick Switch 1
|
||||
Bit 0 Row 1 & Right Joystick Switch 1
|
||||
|
||||
$FF01 (65281) PIA 0 side A control
|
||||
Bit 7 HSYNC Flag
|
||||
Bit 6 Unused
|
||||
Bit 5 1
|
||||
Bit 4 1
|
||||
Bit 3 Select Line LSB of MUX
|
||||
Bit 2 DATA DIRECTION TOGGLE 0 sets data direction 1 = normal
|
||||
Bit 1 IRQ POLARITY 0 = flag set on falling edge 1=set on rising edge
|
||||
Bit 0 HSYNC IRQ 0 = disabled 1 = enabled
|
||||
|
||||
$FF02 (65282) PIA 0 side B data
|
||||
Bit 7 KEYBOARD COLUMN 8
|
||||
Bit 6 7 / RAM SIZE OUTPUT
|
||||
Bit 5 6
|
||||
Bit 4 5
|
||||
Bit 3 4
|
||||
Bit 2 3
|
||||
Bit 1 2
|
||||
Bit 0 KEYBOARD COLUMN 1
|
||||
|
||||
$FF03 (65283) PIA 0 side B control
|
||||
Bit 7 VSYNC FLAG
|
||||
Bit 6 N/A
|
||||
Bit 5 1
|
||||
Bit 4 1
|
||||
Bit 3 SELECT LINE MSB of MUX
|
||||
Bit 2 data direction 1=normal
|
||||
Bit 1 IRQ POLARITY 0=flag set on falling edge 1=set on rising edge
|
||||
Bit 0 VSYNC IRQ 0=disabled 1=enabled
|
||||
|
||||
$FF20 (65312) PIA 1 side A data
|
||||
Bit 7 6 BIT DAC MSB
|
||||
Bit 6
|
||||
Bit 5
|
||||
Bit 4
|
||||
Bit 3
|
||||
Bit 2 6 BIT DAC LSB
|
||||
Bit 1 RS-232C DATA OUTPUT
|
||||
Bit 0 CASSETTE DATA INPUT
|
||||
|
||||
$FF21 (65313) PIA 1 side A control
|
||||
Bit 7 CD FIRQ FLAG
|
||||
Bit 6 N/A
|
||||
Bit 5 1
|
||||
Bit 4 1
|
||||
Bit 3 CASSETTE MOTOR CONTROL 0=OFF 1=ON
|
||||
Bit 2 data direction 1=normal
|
||||
Bit 1 FIRQ POLARITY 0=falling 1=rising
|
||||
Bit 0 CD FIRQ (RS-232C) 0=FIRQ disabled 1=enabled
|
||||
|
||||
$FF22 (65314) PIA 1 side B data reg
|
||||
Bit 7 VDG CONTROL A/G Alphanum = 0, graphics =1
|
||||
Bit 6 VDG CONTROL GM2
|
||||
Bit 5 GM1 & invert
|
||||
Bit 4 VDG CONTROL GM0 & shift toggle
|
||||
Bit 3 RGB Monitor sensing (INPUT) CSS - Color Set Select 0,1
|
||||
Bit 2 RAM SIZE INPUT
|
||||
Bit 1 SINGLE BIT SOUND OUTPUT
|
||||
Bit 0 RS-232C DATA INPUT
|
||||
|
||||
$FF23 (65315) PIA 1 side B control
|
||||
Bit 7 CART FIRQ FLAG
|
||||
Bit 6 N/A
|
||||
Bit 5 1
|
||||
Bit 4 1
|
||||
Bit 3 SOUND ENABLE
|
||||
Bit 2 $FF22 data direction 1 = normal
|
||||
Bit 1 FIRQ POLARITY 0 = falling 1 = rising
|
||||
Bit 0 CART FIRQ 0 = FIRQ disabled 1 = enabled
|
||||
*/
|
||||
|
||||
#include "mc6821.h"
|
||||
#include "MachineHost.h"
|
||||
#include <cstdint>
|
||||
|
||||
static unsigned char rega[4]={0,0,0,0}; //PIA0
|
||||
static unsigned char regb[4]={0,0,0,0}; //PIA1
|
||||
static unsigned char rega_dd[4]={0,0,0,0};
|
||||
static unsigned char regb_dd[4]={0,0,0,0};
|
||||
static unsigned char LeftChannel=0,RightChannel=0;
|
||||
static unsigned char Asample=0,Ssample=0,Csample=0;
|
||||
static bool CartInserted = false, CartAutoStart = true;
|
||||
// Shift Row Col
|
||||
unsigned char pia0_read(unsigned char port)
|
||||
{
|
||||
unsigned char dda,ddb;
|
||||
dda=(rega[1] & 4);
|
||||
ddb=(rega[3] & 4);
|
||||
|
||||
switch (port)
|
||||
{
|
||||
case 1: // cpu read FF01
|
||||
return(rega[port]);
|
||||
break;
|
||||
|
||||
case 3: // cpu read FF03
|
||||
return(rega[port]);
|
||||
break;
|
||||
|
||||
case 0: // cpu read FF00
|
||||
if (dda)
|
||||
{
|
||||
rega[1]=(rega[1] & 63);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
return (VCC::Machine().KeyboardScan(rega[2]|~rega_dd[2])); //Read
|
||||
}
|
||||
else
|
||||
return(rega_dd[port]);
|
||||
break;
|
||||
|
||||
case 2: // cpu read FF02
|
||||
if (ddb)
|
||||
{
|
||||
rega[3]=(rega[3] & 63);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA0_VSYNC, INT_IRQ);
|
||||
return(rega[port] & rega_dd[port]);
|
||||
}
|
||||
else
|
||||
return(rega_dd[port]);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char pia1_read(unsigned char port)
|
||||
{
|
||||
static unsigned int Flag=0;
|
||||
unsigned char dda,ddb;
|
||||
port-=0x20;
|
||||
dda=(regb[1] & 4);
|
||||
ddb=(regb[3] & 4);
|
||||
|
||||
switch (port)
|
||||
{
|
||||
case 1: // cpu read FF21
|
||||
case 3: // cpu read FF23
|
||||
return(regb[port]);
|
||||
break;
|
||||
|
||||
case 2: // cpu read FF22
|
||||
if (ddb)
|
||||
{
|
||||
regb[3]= (regb[3] & 63);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA1_CART, INT_FIRQ);
|
||||
return(regb[port] & regb_dd[port]);
|
||||
}
|
||||
else
|
||||
return(regb_dd[port]);
|
||||
break;
|
||||
|
||||
case 0: // cpu read FF20
|
||||
if (dda)
|
||||
{
|
||||
regb[1]=(regb[1] & 63); //Cass In
|
||||
VCC::Machine().ClearInterrupt(IS_PIA1_CD, INT_FIRQ);
|
||||
if (VCC::Machine().TapeFastLoad())
|
||||
Flag = (regb[port] & 0xFE) | VCC::Machine().TapeInputBit();
|
||||
else
|
||||
Flag = regb[port];//& regb_dd[port];
|
||||
return Flag;
|
||||
}
|
||||
else
|
||||
return(regb_dd[port]);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pia0_write(unsigned char data,unsigned char port)
|
||||
{
|
||||
unsigned char dda,ddb;
|
||||
dda=(rega[1] & 4);
|
||||
ddb=(rega[3] & 4);
|
||||
|
||||
switch (port)
|
||||
{
|
||||
case 0: // cpu write FF00
|
||||
if (dda) {
|
||||
if (data == 0) VCC::Machine().JoystickStart(false, 0);
|
||||
rega[port]=data;
|
||||
} else {
|
||||
rega_dd[port]=data;
|
||||
}
|
||||
return;
|
||||
case 2: // cpu write FF02
|
||||
if (ddb)
|
||||
rega[port]=data;
|
||||
else
|
||||
rega_dd[port]=data;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 1: // cpu write FF01
|
||||
rega[port]= (data & 0x3F);
|
||||
|
||||
if (data & 0x01) {}
|
||||
else if ((data & 0x28) == 0x08) {}
|
||||
else VCC::Machine().ClearInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
|
||||
return;
|
||||
break;
|
||||
|
||||
case 3: // cpu write FF03
|
||||
rega[port]= (data & 0x3F);
|
||||
|
||||
if (data & 0x01) {}
|
||||
else if ((data & 0x28) == 0x08) {}
|
||||
else VCC::Machine().ClearInterrupt(IS_PIA0_VSYNC, INT_IRQ);
|
||||
|
||||
return;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void pia1_write(unsigned char data,unsigned char port)
|
||||
{
|
||||
unsigned char dda,ddb;
|
||||
port-=0x20;
|
||||
|
||||
dda=(regb[1] & 4);
|
||||
ddb=(regb[3] & 4);
|
||||
switch (port)
|
||||
{
|
||||
case 0: // cpu write FF20
|
||||
if (dda)
|
||||
{
|
||||
VCC::Machine().JoystickStart(true, data);
|
||||
regb[port]=data;
|
||||
VCC::Machine().PrinterBit((regb[0]&2)>>1);
|
||||
if (GetMuxState() == 0)
|
||||
{
|
||||
if ((regb[3] & 8) != 0)//==0 for cassette writes
|
||||
{
|
||||
Asample = (regb[0] & 0xFC) >> 1; //0 to 127
|
||||
}
|
||||
else
|
||||
{
|
||||
Csample = (regb[0] & 0xFC);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
regb_dd[port]=data;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 2: // cpu write FF22
|
||||
if (ddb)
|
||||
{
|
||||
regb[port]=(data & regb_dd[port]);
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::VdgMode2, (regb[2] & 248) >>3);
|
||||
Ssample=(regb[port] & 2)<<6;
|
||||
}
|
||||
else
|
||||
regb_dd[port]=data;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 1: // cpu write FF21
|
||||
regb[port]= (data & 0x3F);
|
||||
VCC::Machine().TapeMotor((data & 8)>>3);
|
||||
return;
|
||||
break;
|
||||
|
||||
case 3: // cpu write FF22
|
||||
regb[port]= (data & 0x3F);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char VDG_Mode()
|
||||
{
|
||||
return( (regb[2] & 248) >>3);
|
||||
}
|
||||
|
||||
|
||||
void irq_hs(int phase) //63.5 uS
|
||||
{
|
||||
|
||||
switch (phase)
|
||||
{
|
||||
case FALLING: //HS went High to low
|
||||
if (rega[1] & 2) //IRQ on low to High transition
|
||||
return;
|
||||
rega[1]=(rega[1] | 128);
|
||||
if (rega[1] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
break;
|
||||
|
||||
case RISING: //HS went Low to High
|
||||
if ( !(rega[1] & 2) ) //IRQ High to low transition
|
||||
return;
|
||||
rega[1]=(rega[1] | 128);
|
||||
if (rega[1] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
break;
|
||||
|
||||
case ANY:
|
||||
rega[1]=(rega[1] | 128);
|
||||
if (rega[1] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
break;
|
||||
} //END switch
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void irq_fs(int phase) //60HZ Vertical sync pulse 16.667 mS
|
||||
{
|
||||
if ((CartInserted == 1) && (CartAutoStart == 1))
|
||||
AssertCart();
|
||||
switch (phase)
|
||||
{
|
||||
case 0: //FS went High to low
|
||||
if ((rega[3] & 2) == 0) //IRQ on High to low transition
|
||||
{
|
||||
rega[3] = (rega[3] | 128);
|
||||
if (rega[3] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA0_VSYNC, INT_IRQ);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
|
||||
case 1: //FS went Low to High
|
||||
|
||||
if (rega[3] & 2) //IRQ Low to High transition
|
||||
{
|
||||
rega[3] = (rega[3] | 128);
|
||||
if (rega[3] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA0_VSYNC, INT_IRQ);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
} //END switch
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void AssertCart()
|
||||
{
|
||||
regb[3]=(regb[3] | 128);
|
||||
if (regb[3] & 1)
|
||||
VCC::Machine().AssertInterrupt(IS_PIA1_CART, INT_FIRQ);
|
||||
else
|
||||
VCC::Machine().ClearInterrupt(IS_PIA1_CART, INT_FIRQ);
|
||||
}
|
||||
|
||||
void PiaReset()
|
||||
{
|
||||
Asample = Ssample = Csample = 0; // output latches must not survive a machine reset
|
||||
VCC::Machine().ClearInterrupt(IS_PIA0_HSYNC, INT_IRQ);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA0_VSYNC, INT_IRQ);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA1_CD, INT_FIRQ);
|
||||
VCC::Machine().ClearInterrupt(IS_PIA1_CART, INT_FIRQ);
|
||||
// Clear the PIA registers
|
||||
for (uint8_t index=0; index<4; index++)
|
||||
{
|
||||
rega[index]=0;
|
||||
regb[index]=0;
|
||||
rega_dd[index]=0;
|
||||
regb_dd[index]=0;
|
||||
}
|
||||
}
|
||||
|
||||
// Get analog I/O select.
|
||||
unsigned char GetMuxState()
|
||||
{
|
||||
return ( ((rega[1] & 8)>>3) + ((rega[3] & 8) >>2));
|
||||
}
|
||||
|
||||
// Return 14 bit value for DAC comparator. Coco DAC is six bits
|
||||
// but value is extended to allow more resolution.
|
||||
unsigned int DACState()
|
||||
{
|
||||
return (regb[0] & 0xFCu) << 6; // PA1 carries serial output and PA0 is cassette input.
|
||||
}
|
||||
|
||||
void SetCart(bool lineState)
|
||||
{
|
||||
CartInserted = lineState;
|
||||
return;
|
||||
}
|
||||
|
||||
PiaSoundState GetPIASoundState()
|
||||
{
|
||||
return {static_cast<unsigned char>((regb[0] & 0xFC) >> 1), Ssample, (regb[3] & 8) != 0};
|
||||
}
|
||||
|
||||
unsigned int GetDACSample()
|
||||
{
|
||||
auto pakSample = VCC::Machine().CartridgeAudio();
|
||||
auto pakLeft = pakSample >> 8;
|
||||
auto pakRight = pakSample & 0xFF;
|
||||
auto dacSample = Asample;
|
||||
auto bitSample = Ssample;
|
||||
auto left = (pakLeft + dacSample + bitSample) << 7;
|
||||
auto right = (pakRight + dacSample + bitSample) << 7;
|
||||
// removed previous "slow high pass filter" that
|
||||
// destroys daggorath's proper heartbeat sound -ca 2025-06-02
|
||||
return (left << 16) | (right & 0xFFFF);
|
||||
}
|
||||
|
||||
unsigned char SetCartAutoStart(unsigned char Tmp)
|
||||
{
|
||||
if (Tmp !=255)
|
||||
CartAutoStart=Tmp;
|
||||
return CartAutoStart;
|
||||
}
|
||||
|
||||
unsigned char GetCasSample()
|
||||
{
|
||||
return Csample;
|
||||
}
|
||||
|
||||
void SetCassetteSample(unsigned char Sample)
|
||||
{
|
||||
regb[0]=regb[0] & 0xFE;
|
||||
if (Sample>0x7F)
|
||||
regb[0]=regb[0] | 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#ifndef __MC6821_H__
|
||||
#define __MC6821_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
unsigned char pia0_read(unsigned char port);
|
||||
void pia0_write(unsigned char data,unsigned char port);
|
||||
unsigned char pia1_read(unsigned char port);
|
||||
void pia1_write(unsigned char data,unsigned char port);
|
||||
|
||||
void ClosePrintFile();
|
||||
void SetSerialParams(unsigned char);
|
||||
void SetMonState(bool);
|
||||
unsigned char VDG_Mode();
|
||||
void irq_hs(int);
|
||||
void irq_fs(int);
|
||||
void AssertCart();
|
||||
void SetCart(bool lineState);
|
||||
unsigned char SetCartAutoStart(unsigned char);
|
||||
void PiaReset();
|
||||
unsigned char GetMuxState();
|
||||
unsigned int DACState();
|
||||
unsigned int GetDACSample(); // retained Windows packed mixer
|
||||
// Read-only CoCo speaker inputs. Routing belongs to the native sampler; the
|
||||
// DAC keeps changing during joystick measurements even with sound disabled.
|
||||
struct PiaSoundState { unsigned char dac, singleBit; bool enabled; };
|
||||
PiaSoundState GetPIASoundState();
|
||||
unsigned char GetCasSample();
|
||||
void SetCassetteSample(unsigned char);
|
||||
int OpenPrintFile(const char *);
|
||||
// FIXME: These need to be turned into an enum and the signature of functions
|
||||
// that use them updated.
|
||||
constexpr auto FALLING = 0u;
|
||||
constexpr auto RISING = 1u;
|
||||
constexpr auto ANY = 2u;
|
||||
constexpr auto RAMPMAX = 900u;
|
||||
|
||||
// FIXME: These need to be turned into an enum and the signature of functions
|
||||
// that use them updated.
|
||||
const int PIA_MUX_DAC = 0;
|
||||
const int PIA_MUX_CASSETTE = 1;
|
||||
const int PIA_MUX_CARTRIDGE = 2;
|
||||
const int PIA_MUX_UNUSED = 3;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,303 @@
|
||||
#ifndef __TCC1014GRAPHICS_H__
|
||||
#define __TCC1014GRAPHICS_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "VideoHost.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "Event.h"
|
||||
#include <vector>
|
||||
|
||||
static unsigned char Lpf[4]={192,199,225,225}; // 2 is really undefined but I gotta put something here.
|
||||
static unsigned char VcenterTable[4] = { 25,19,8,8 };
|
||||
#if USE_NEWTIMING
|
||||
static unsigned char TopOffScreenTable[4] = { 11,15,11,11 };
|
||||
#else
|
||||
static unsigned char TopOffScreenTable[4] = { 11,14,11,11 };
|
||||
#endif
|
||||
static unsigned char BottomOffScreenTable[4] = { 5,1,5,5 };
|
||||
|
||||
// Display registers and derived raster state can be copied into a detached
|
||||
// renderer. Timers, interrupt callbacks and the live beam stay on the GPU.
|
||||
struct GimeDisplayState
|
||||
{
|
||||
unsigned int VidMask = 0x1FFFF;
|
||||
unsigned char VresIndex = 0;
|
||||
unsigned char CC2Offset = 0, CC2VDGMode = 0, CC2VDGPiaMode = 0;
|
||||
unsigned short VerticalOffsetRegister = 0;
|
||||
unsigned char CompatMode = 0;
|
||||
unsigned char MonType = 1;
|
||||
unsigned char CC3Vmode = 0, CC3Vres = 0, CC3BoarderColor = 0;
|
||||
unsigned int StartofVidram = 0, NewStartofVidram = 0;
|
||||
unsigned char LinesperScreen = 0;
|
||||
unsigned char Bpp = 0;
|
||||
unsigned char LinesperRow = 1, BytesperRow = 32;
|
||||
unsigned char GraphicsMode = 0;
|
||||
unsigned char TextFGColor = 0, TextBGColor = 0;
|
||||
unsigned char TextFGPalette = 0, TextBGPalette = 0;
|
||||
unsigned char PaletteIndex = 0;
|
||||
unsigned short PixelsperLine = 0, VPitch = 32;
|
||||
unsigned char Stretch = 0, PixelsperByte = 0;
|
||||
unsigned char HorzCenter = 0, VertCenter = 0;
|
||||
unsigned char LowerCase = 0, InvertAll = 0, ExtendedText = 1;
|
||||
unsigned char HorzOffsetReg = 0;
|
||||
unsigned char Hoffset = 0;
|
||||
unsigned char NewHoffset = 0;
|
||||
unsigned short TagY = 0;
|
||||
unsigned char VertScroll = 0;
|
||||
unsigned char UnderlineRow = 0;
|
||||
unsigned int BoarderColor32 = 0;
|
||||
unsigned short BoarderColor16 = 0;
|
||||
unsigned char BoarderColor8 = 0;
|
||||
unsigned int DistoOffset = 0;
|
||||
#if !USE_NEWTIMING
|
||||
unsigned char BoarderChange = 3;
|
||||
#endif
|
||||
unsigned char MasterMode = 0;
|
||||
unsigned char ColorInvert = 1;
|
||||
unsigned char BlinkState = 1;
|
||||
unsigned char TopBoarder = 0, BottomBoarder = 0, TopOffScreen = 0, BottomOffScreen = 0;
|
||||
bool UserFlipped = false;
|
||||
unsigned int last_mmode = 0;
|
||||
const char* curr_gmode = "";
|
||||
const char* last_gmode = "";
|
||||
unsigned char Palette[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //Coco 3 6 bit colors
|
||||
unsigned char Palette8Bit[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
unsigned short Palette16Bit[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //Color values translated to 16bit 32BIT
|
||||
unsigned int Palette32Bit[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //Color values translated to 24/32 bits
|
||||
};
|
||||
|
||||
struct GimeGpu : GimeDisplayState
|
||||
{
|
||||
using Surface32 = VCC::VideoArray<unsigned int, 640 * 480>;
|
||||
|
||||
#if USE_NEWTIMING
|
||||
template <typename A, typename B> using Pair = std::pair<A, B>;
|
||||
template <typename T> using Vector = std::vector<T>;
|
||||
using UpdateFunction = std::function<void()>;
|
||||
using RasterUpdate = std::function<void(GimeGpu&)>;
|
||||
using SyncFunction = std::function<void(int)>;
|
||||
|
||||
GimeGpu(SyncFunction hSync, SyncFunction vSync);
|
||||
#endif
|
||||
GimeGpu();
|
||||
GimeGpu(const GimeGpu&) = delete;
|
||||
GimeGpu& operator=(const GimeGpu&) = delete;
|
||||
|
||||
//This routine gets called every time a software video register get updated.
|
||||
void SetupDisplay();
|
||||
int Pmode4MonType() const;
|
||||
bool UsesNtscPmode4Renderer() const;
|
||||
void TogBlinkState();
|
||||
|
||||
unsigned int GetRowLine(int y)
|
||||
{
|
||||
auto vScroll = CompatMode == 0 ? VertScroll : 0;
|
||||
auto rowLine = (y + vScroll) % LinesperRow;
|
||||
return rowLine;
|
||||
}
|
||||
|
||||
unsigned int GetAddressStart(int y)
|
||||
{
|
||||
auto vScroll = CompatMode == 0 ? VertScroll : 0;
|
||||
auto row = (y + vScroll) / LinesperRow;
|
||||
if ((CC3Vmode & 7) == 7) row = 0;
|
||||
return StartofVidram + (row * VPitch * ExtendedText);
|
||||
}
|
||||
|
||||
unsigned int GetYStride(int y, unsigned int pitch)
|
||||
{
|
||||
return (((y + VertCenter) * 2) * pitch) + HorzCenter - 1;
|
||||
}
|
||||
|
||||
unsigned char GetFontRowCC3(unsigned char ch, unsigned int line)
|
||||
{
|
||||
extern unsigned char cc3Fontdata8x12[];
|
||||
if (line > 11) return 0;
|
||||
return cc3Fontdata8x12[ch * 12 + line];
|
||||
}
|
||||
|
||||
|
||||
int GetBytesPerRow() const;
|
||||
int GetGraphicsMode() const;
|
||||
unsigned char GetHorizontalBorderSize() const;
|
||||
unsigned char SetMonitorType(unsigned char Type);
|
||||
unsigned char SetScanLines(unsigned char Lines);
|
||||
unsigned int GetStartOfVidram() const;
|
||||
unsigned short GetDisplayedPixelsPerLine() const;
|
||||
void SetLinesperScreen(unsigned char Lines);
|
||||
void FlipArtifacts();
|
||||
void GimeInit();
|
||||
void GimeReset();
|
||||
#if !USE_NEWTIMING
|
||||
void InvalidateBoarder();
|
||||
void SetBoarderChange();
|
||||
#endif
|
||||
void SetCompatMode(unsigned char Register);
|
||||
void SetGimeBoarderColor(unsigned char data);
|
||||
void SetGimeHorzOffset(unsigned char data);
|
||||
void SetGimePalette(unsigned char palette, unsigned char color);
|
||||
void SetGimeVdgMode(unsigned char VdgMode);
|
||||
void SetGimeVdgMode2(unsigned char Vdgmode2);
|
||||
void SetGimeVdgOffset(unsigned char Offset);
|
||||
void SetVerticalScroll(unsigned char scroll);
|
||||
void SetGimeVmode(unsigned char vmode);
|
||||
void SetGimeVres(unsigned char vres);
|
||||
void SetPaletteType();
|
||||
void SetVerticalOffsetRegister(unsigned short Register);
|
||||
void SetVideoBank(unsigned char data);
|
||||
void SetVidMask(unsigned int data);
|
||||
bool CopyPalette(const GimeGpu& other);
|
||||
void SetDefaultPalette();
|
||||
|
||||
void DrawTopBoarder8(VCC::VideoState* DTState);
|
||||
void DrawTopBoarder16(VCC::VideoState* DTState);
|
||||
void DrawTopBoarder24(VCC::VideoState* /*DTState*/);
|
||||
void DrawTopBoarder32(VCC::VideoState* DTState);
|
||||
|
||||
void DrawBottomBoarder8(VCC::VideoState* DTState);
|
||||
void DrawBottomBoarder16(VCC::VideoState* DTState);
|
||||
void DrawBottomBoarder24(VCC::VideoState* DTState);
|
||||
void DrawBottomBoarder32(VCC::VideoState* DTState);
|
||||
|
||||
void UpdateScreen8(VCC::VideoState* US8State);
|
||||
void UpdateScreen16(VCC::VideoState* USState16);
|
||||
void UpdateScreen24(VCC::VideoState* /*USState24*/);
|
||||
void UpdateScreen32(VCC::VideoState* USState32);
|
||||
void UpdateScreen32To(unsigned char* buffer, unsigned int* surface, int lineCounter, int surfacePitch, bool scanLines, bool reportModeChange = true);
|
||||
|
||||
#if USE_NEWTIMING
|
||||
// Copy register state, including pending palette and offset writes, to a detached GPU.
|
||||
void CopySnapshotStateTo(GimeGpu& preview) const;
|
||||
// Render current VRAM without running the CPU or advancing the beam.
|
||||
VCC::VideoRect RenderSnapshot32(const VCC::VideoState& source, std::vector<std::uint32_t>& pixels) const;
|
||||
void SetupColorSet(unsigned char set);
|
||||
|
||||
// mark the beginning of a new line ready to capture events
|
||||
void BeginCpuLine();
|
||||
|
||||
// finalize the current line
|
||||
void EndCpuLine();
|
||||
|
||||
// Apply now in immediate mode, or at the beam position of the guest write.
|
||||
void ApplyLineUpdate(RasterUpdate change);
|
||||
|
||||
// updates the timer value (on write to $ff94/$ff95)
|
||||
void SetTimer(unsigned int time);
|
||||
|
||||
// restart the timer (on write to init1)
|
||||
void ResetTimer();
|
||||
void SetTimerSource(unsigned char rate);
|
||||
// Cancel scheduled raster/timer work before replacing a running instance.
|
||||
void StopEvents();
|
||||
|
||||
// true when current frame has completed (for one call, auto resets)
|
||||
bool FrameFinished();
|
||||
|
||||
// returns the time from start of the line
|
||||
VCC::Event::Clocks GetLineStartClock() { return mCpuLine.LineStartClock; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
void RenderNTSCPixel2x2(Surface32 surface32, size_t surfaceDest, int XpitchDest, char colorIndex, char scanLines);
|
||||
void RenderPMODE4NTSC(Surface32 surface32, size_t surfaceDest, int XpitchDest, const unsigned char* ram, unsigned int rowStart, char scanLines);
|
||||
|
||||
static void MakeRGBPalette();
|
||||
static void MakeCMPpalette();
|
||||
|
||||
#if USE_NEWTIMING
|
||||
void TimerRestart();
|
||||
void QueueEvent(size_t clocks, UpdateFunction func, size_t id);
|
||||
unsigned char mTimerClockRate = 0;
|
||||
std::shared_ptr<int> mEventLifetime = std::make_shared<int>(0);
|
||||
|
||||
// retrigger timer interrupt after reaching zero
|
||||
void TimerRetrigger();
|
||||
|
||||
// issue the timer interrupt, retriggers
|
||||
void TimerInterrupt(int delay);
|
||||
|
||||
// decrement the timer counter and set interrupt at zero
|
||||
void DecrementTimerAndSet();
|
||||
|
||||
// process changes up to pixel x coordinate
|
||||
void ProcessCpuLine(unsigned int pixelx);
|
||||
|
||||
// draw regions (top, active, bottom)
|
||||
void DrawTopBorder();
|
||||
void DrawActiveArea();
|
||||
void DrawBottomBorder();
|
||||
|
||||
// draw single raster line
|
||||
void DrawRaster();
|
||||
|
||||
// when hsync/vsync falls
|
||||
void VSyncFall();
|
||||
void HSyncFall();
|
||||
void VBlank();
|
||||
|
||||
// issue hsync/vsync interrupts
|
||||
void VSYNC(int level);
|
||||
void HSYNC(int level);
|
||||
|
||||
// queue next hsync fall/rise event & gime hsync interrupt
|
||||
void HSyncQueueEvents(int offset = 0);
|
||||
|
||||
static auto constexpr VIDEO_LINES = 263;
|
||||
static auto constexpr VSYNC_RISE = 4;
|
||||
|
||||
static auto constexpr CLK_HSYNC = 80;
|
||||
static auto constexpr CLK_LINE = 912;
|
||||
static auto constexpr CLK_TIMER_IRQ_ISSUE_DELAY = 16; // 3.3
|
||||
static auto constexpr CLK_TIMER_IRQ_RESET_DELAY = 8; // 3.4
|
||||
static auto constexpr CLK_TIMER_DECR_DELAY = 912 - 16;
|
||||
static auto constexpr CLK_VSYNC_RISE = CLK_LINE * VSYNC_RISE;
|
||||
|
||||
struct CpuLineUpdates
|
||||
{
|
||||
size_t Index;
|
||||
Vector<Pair<VCC::Event::Clocks, RasterUpdate>> Data;
|
||||
VCC::Event::Clocks LineStartClock;
|
||||
};
|
||||
|
||||
CpuLineUpdates mCpuLine{}; // the line history
|
||||
int mClockVSyncFall; // vsync fall time from last hsync fall
|
||||
int mClockHSync; // hsync (gime)
|
||||
int mLeftEdge; // pixels to left screen edge
|
||||
int mRightEdge; // pixels to right screen edge
|
||||
int mLeftDraw; // offset from real pixel to left screen edge
|
||||
unsigned int mLineCount; // raster line; wraps at VIDEO_LINES, also used by tracing
|
||||
size_t mTimerCount; // current timer countdown
|
||||
size_t mTimer; // current timer value in lines
|
||||
bool mTimerSet; // flag if timer interrupt is ready to fire
|
||||
bool mFrameFinished; // flag when frame completed
|
||||
bool mImmediate; // flag when instance is immediate mode
|
||||
SyncFunction mHSync; // called on hsync
|
||||
SyncFunction mVSync; // called on vsync
|
||||
#endif
|
||||
};
|
||||
|
||||
//
|
||||
// notes:
|
||||
// 3.3 - fast timer delay before issued (mpatdemo)
|
||||
// 3.4 - slow timer delay after reset when crossing hsync
|
||||
|
||||
extern GimeGpu gGimeGpu;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tcc1014mmu.h"
|
||||
#include "iobus.h"
|
||||
#include "tcc1014registers.h"
|
||||
#include "MachineHost.h"
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
|
||||
static unsigned char *MemPages[1024];
|
||||
static unsigned short MemPageOffsets[1024];
|
||||
static unsigned char *memory=nullptr; //Emulated RAM
|
||||
static unsigned char *InternalRomBuffer=nullptr;
|
||||
static unsigned char MmuTask=0; // $FF91 bit 0
|
||||
static unsigned char MmuEnabled=0; // $FF90 bit 6
|
||||
static unsigned char RamVectors=0; // $FF90 bit 3
|
||||
static unsigned char MmuState=0; // Composite variable handles MmuTask and MmuEnabled
|
||||
static unsigned char RomMap=0; // $FF90 bit 1-0
|
||||
static unsigned char MapType=0; // $FFDE/FFDF toggle Map type 0 = ram/rom
|
||||
static unsigned short MmuRegisters[4][8]; // $FFA0 - FFAF
|
||||
static unsigned int MemConfig[4]={0x20000,0x80000,0x200000,0x800000};
|
||||
static unsigned short RamMask[4]={15,63,255,1023};
|
||||
static unsigned char StateSwitch[4]={8,56,56,56};
|
||||
static unsigned char VectorMask[4]={15,63,63,63};
|
||||
static unsigned char VectorMaska[4]={12,60,60,60};
|
||||
static unsigned int VidMask[4]={0x1FFFF,0x7FFFF,0x1FFFFF,0x7FFFFF};
|
||||
static unsigned char CurrentRamConfig=1;
|
||||
static unsigned short MmuPrefix=0;
|
||||
static unsigned int RamSize=0;
|
||||
std::atomic_bool mem_initializing;
|
||||
|
||||
void UpdateMmuArray();
|
||||
|
||||
/*****************************************************************************************
|
||||
* MmuInit Initilize and allocate memory for RAM Internal and External ROM Images. *
|
||||
* Copy Rom Images to buffer space and reset GIME MMU registers to 0 *
|
||||
* Returns nullptr if any of the above fail. *
|
||||
*****************************************************************************************/
|
||||
unsigned char * MmuInit(unsigned char RamConfig)
|
||||
{
|
||||
if (RamConfig >= 4) return nullptr;
|
||||
// This flag guards legacy debugger reads, not concurrent machine ownership.
|
||||
// Initialization, execution and teardown must be serialized by the host.
|
||||
struct Initializing {
|
||||
Initializing() { mem_initializing = true; }
|
||||
~Initializing() { mem_initializing = false; }
|
||||
} initializing;
|
||||
const auto size = MemConfig[RamConfig];
|
||||
std::unique_ptr<unsigned char[]> ram(new (std::nothrow) unsigned char[size]);
|
||||
std::unique_ptr<unsigned char[]> rom(new (std::nothrow) unsigned char[0x8000]);
|
||||
if (!ram || !rom) return nullptr;
|
||||
std::fill_n(rom.get(), 0x8000, 0xFF);
|
||||
if (!VCC::Machine().LoadInternalRom(rom.get(), 0x8000)) return nullptr;
|
||||
|
||||
// Preserve the upstream power-on pattern, without an aliased uint32_t store.
|
||||
uint32_t value = 0xFFFFFFFF;
|
||||
for (size_t i = 0; i < size; i += 4) {
|
||||
if ((i & 0xFF) != 0) value ^= 0xFFFFFFFF;
|
||||
std::memcpy(ram.get() + i, &value, sizeof(value));
|
||||
}
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::RamMask, VidMask[RamConfig]);
|
||||
delete[] memory;
|
||||
delete[] InternalRomBuffer;
|
||||
memory = ram.release();
|
||||
InternalRomBuffer = rom.release();
|
||||
RamSize = size;
|
||||
CurrentRamConfig = RamConfig;
|
||||
MmuReset();
|
||||
return memory;
|
||||
}
|
||||
|
||||
void MmuShutdown()
|
||||
{
|
||||
delete[] memory;
|
||||
delete[] InternalRomBuffer;
|
||||
memory = nullptr;
|
||||
InternalRomBuffer = nullptr;
|
||||
RamSize = 0;
|
||||
std::fill_n(MemPages, 1024, nullptr);
|
||||
}
|
||||
|
||||
unsigned char GetRamConfiguration() { return CurrentRamConfig; }
|
||||
|
||||
void MmuReset()
|
||||
{
|
||||
if (!memory) return;
|
||||
unsigned int Index1=0,Index2=0;
|
||||
MmuTask=0;
|
||||
MmuEnabled=0;
|
||||
RamVectors=0;
|
||||
MmuState=0;
|
||||
RomMap=0;
|
||||
MapType=0;
|
||||
MmuPrefix=0;
|
||||
for (Index1=0;Index1<8;Index1++)
|
||||
for (Index2=0;Index2<4;Index2++)
|
||||
MmuRegisters[Index2][Index1]=Index1+StateSwitch[CurrentRamConfig];
|
||||
|
||||
for (Index1=0;Index1<1024;Index1++)
|
||||
{
|
||||
MemPages[Index1]=memory+( (Index1 & RamMask[CurrentRamConfig]) *0x2000);
|
||||
MemPageOffsets[Index1]=1;
|
||||
}
|
||||
SetRomMap(0);
|
||||
SetMapType(0);
|
||||
return;
|
||||
}
|
||||
|
||||
VCC::MMUState GetMMUState()
|
||||
{
|
||||
VCC::MMUState state;
|
||||
if (!memory) return state;
|
||||
|
||||
state.ActiveTask = MmuTask;
|
||||
state.Enabled = MmuEnabled != 0;
|
||||
|
||||
for (auto i = 0U; i < state.Task0.size(); ++i)
|
||||
{
|
||||
state.Task0[i] = MmuRegisters[0][i];
|
||||
state.Task1[i] = MmuRegisters[1][i];
|
||||
}
|
||||
|
||||
state.RamVectors = RamVectors;
|
||||
state.RomMap = RomMap;
|
||||
state.AllRAM = MapType != 0;
|
||||
state.Prefix = MmuPrefix;
|
||||
state.RAMBytes = RamSize;
|
||||
state.RAMVectorAddress = 0x2000u * VectorMask[CurrentRamConfig] + 0x1e00;
|
||||
for (unsigned bank = 0; bank < state.Effective.size(); ++bank) {
|
||||
auto& mapping = state.Effective[bank];
|
||||
mapping.Page = MmuRegisters[MmuState][bank];
|
||||
mapping.RAMStart = (mapping.Page & RamMask[CurrentRamConfig]) * 0x2000u;
|
||||
mapping.SourceStart = mapping.RAMStart;
|
||||
// Match UpdateMmuArray: only the actual reserved page indices receive
|
||||
// ROM overlays. A mirrored RAM page with a different raw index stays RAM.
|
||||
if (!MapType && mapping.Page >= VectorMaska[CurrentRamConfig] &&
|
||||
mapping.Page <= VectorMask[CurrentRamConfig]) {
|
||||
const unsigned romBank = mapping.Page - VectorMaska[CurrentRamConfig];
|
||||
if (RomMap == 2 || (RomMap < 2 && romBank < 2)) {
|
||||
mapping.Source = VCC::MMUSource::InternalROM;
|
||||
mapping.SourceStart = romBank * 0x2000;
|
||||
} else {
|
||||
mapping.Source = VCC::MMUSource::CartridgeROM;
|
||||
mapping.SourceStart = (romBank ^ 2) * 0x2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void GetMMUPage(size_t page, std::array<unsigned char, 8192>& outBuffer)
|
||||
{
|
||||
if (!memory || page >= RamSize / outBuffer.size()) {
|
||||
outBuffer.fill(0xFF);
|
||||
return;
|
||||
}
|
||||
auto offset = page * 8192;
|
||||
std::copy(memory + offset, memory + offset + outBuffer.size(), outBuffer.begin());
|
||||
}
|
||||
|
||||
|
||||
void SetVectors(unsigned char data)
|
||||
{
|
||||
RamVectors=!!data; //Bit 3 of $FF90 MC3
|
||||
return;
|
||||
}
|
||||
|
||||
void SetMmuRegister(unsigned char Register,unsigned char data)
|
||||
{
|
||||
unsigned char BankRegister,Task;
|
||||
BankRegister = Register & 7;
|
||||
Task=!!(Register & 8);
|
||||
MmuRegisters[Task][BankRegister]= MmuPrefix |(data & RamMask[CurrentRamConfig]); //gime.c returns what was written so I can get away with this
|
||||
return;
|
||||
}
|
||||
|
||||
void SetRomMap(unsigned char data)
|
||||
{
|
||||
RomMap=(data & 3);
|
||||
UpdateMmuArray();
|
||||
return;
|
||||
}
|
||||
|
||||
void MmuSetMapType(unsigned char type)
|
||||
{
|
||||
MapType=!!type;
|
||||
UpdateMmuArray();
|
||||
return;
|
||||
}
|
||||
|
||||
void Set_MmuTask(unsigned char task)
|
||||
{
|
||||
MmuTask=task & 1;
|
||||
MmuState= (!MmuEnabled)<<1 | MmuTask;
|
||||
return;
|
||||
}
|
||||
|
||||
void Set_MmuEnabled (unsigned char usingmmu)
|
||||
{
|
||||
MmuEnabled=usingmmu;
|
||||
MmuState= (!MmuEnabled)<<1 | MmuTask;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char * Getint_rom_pointer()
|
||||
{
|
||||
return InternalRomBuffer;
|
||||
}
|
||||
|
||||
// LoadRom() loads Coco3.rom. It is called by MmuInit() here
|
||||
// and by SoftReset() in Vcc.c. If LoadRom() fails VCC can not run.
|
||||
void LoadRom()
|
||||
{
|
||||
if (!InternalRomBuffer) return;
|
||||
std::array<unsigned char, 0x8000> rom;
|
||||
rom.fill(0xFF);
|
||||
if (VCC::Machine().LoadInternalRom(rom.data(), rom.size()))
|
||||
std::copy(rom.begin(), rom.end(), InternalRomBuffer);
|
||||
}
|
||||
|
||||
// Coco3 MMU Code
|
||||
unsigned char MmuRead8(unsigned short address)
|
||||
{
|
||||
if (!memory) return 0xFF;
|
||||
if (address<0xFE00)
|
||||
{
|
||||
if (MemPageOffsets[MmuRegisters[MmuState][address>>13]]==1)
|
||||
return(MemPages[MmuRegisters[MmuState][address>>13]][address & 0x1FFF]);
|
||||
return( VCC::Machine().CartridgeRead( MemPageOffsets[MmuRegisters[MmuState][address>>13]] + (address & 0x1FFF) ));
|
||||
}
|
||||
if (address>0xFEFF)
|
||||
return (port_read(address));
|
||||
if (RamVectors) //Address must be $FE00 - $FEFF
|
||||
return(memory[(0x2000*VectorMask[CurrentRamConfig])|(address & 0x1FFF)]);
|
||||
if (MemPageOffsets[MmuRegisters[MmuState][address>>13]]==1)
|
||||
return(MemPages[MmuRegisters[MmuState][address>>13]][address & 0x1FFF]);
|
||||
return( VCC::Machine().CartridgeRead( MemPageOffsets[MmuRegisters[MmuState][address>>13]] + (address & 0x1FFF) ));
|
||||
}
|
||||
|
||||
// Debugger does not want to do port reads that change state
|
||||
unsigned char SafeMemRead8(unsigned short address)
|
||||
{
|
||||
// Do nothing if memory is in initializing state
|
||||
if (mem_initializing || !memory) return 0;
|
||||
// Filter port reads that are not GIME or SAM
|
||||
if ((address > 0xFEFF) && (address < 0xFF90)) return memory[address];
|
||||
// Return gime registers without state change, e.g. ff92/ff93 change state
|
||||
if (address >= 0xFF90 && address <= 0xFFBF) return SafeGimeRead((uint8_t)(address&0xFF));
|
||||
// Otherwise use normal MMU MemRead8
|
||||
return MemRead8(address);
|
||||
}
|
||||
|
||||
void MmuWrite8(unsigned char data,unsigned short address)
|
||||
{
|
||||
if (!memory) return;
|
||||
if (address<0xFE00)
|
||||
{
|
||||
if (MapType | (MmuRegisters[MmuState][address>>13] <VectorMaska[CurrentRamConfig]) | (MmuRegisters[MmuState][address>>13] > VectorMask[CurrentRamConfig]))
|
||||
MemPages[MmuRegisters[MmuState][address>>13]][address & 0x1FFF]=data;
|
||||
return;
|
||||
}
|
||||
if (address>0xFEFF)
|
||||
{
|
||||
port_write(data,address);
|
||||
return;
|
||||
}
|
||||
if (RamVectors) //Address must be $FE00 - $FEFF
|
||||
{
|
||||
memory[(0x2000 * VectorMask[CurrentRamConfig]) | (address & 0x1FFF)] = data;
|
||||
}
|
||||
else if (MapType | (MmuRegisters[MmuState][address >> 13] < VectorMaska[CurrentRamConfig]) | (MmuRegisters[MmuState][address >> 13] > VectorMask[CurrentRamConfig]))
|
||||
{
|
||||
MemPages[MmuRegisters[MmuState][address >> 13]][address & 0x1FFF] = data;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Returns TRUE if address is writable RAM (Not Cart, Not a Port)
|
||||
bool MemCheckWrite(unsigned short address)
|
||||
{
|
||||
if (!memory) return false;
|
||||
if (address<0xFE00)
|
||||
{
|
||||
if (MapType | (MmuRegisters[MmuState][address>>13] <VectorMaska[CurrentRamConfig]) | (MmuRegisters[MmuState][address>>13] > VectorMask[CurrentRamConfig]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char VCC_CPU_FASTCALL fMemRead8(unsigned short address)
|
||||
{
|
||||
return MemRead8(address);
|
||||
}
|
||||
|
||||
void VCC_CPU_FASTCALL fMemWrite8(unsigned char data, unsigned short address)
|
||||
{
|
||||
MemWrite8(data, address);
|
||||
}
|
||||
|
||||
unsigned short GetMem(unsigned long address) {
|
||||
if (mem_initializing || !memory) return 0; // To prevent access exceptions
|
||||
if (address < RamSize)
|
||||
return(memory[address]);
|
||||
else
|
||||
return 0xFF;
|
||||
}
|
||||
void SetMem(unsigned long address, unsigned short data) {
|
||||
if (address < RamSize)
|
||||
memory[address] = (unsigned char) data;
|
||||
}
|
||||
|
||||
unsigned char * Get_mem_pointer()
|
||||
{
|
||||
return memory;
|
||||
}
|
||||
|
||||
void SetDistoRamBank(unsigned char data)
|
||||
{
|
||||
|
||||
switch (CurrentRamConfig)
|
||||
{
|
||||
case 0: // 128K
|
||||
return;
|
||||
break;
|
||||
case 1: //512K
|
||||
return;
|
||||
break;
|
||||
case 2: //2048K
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Bank, data & 3);
|
||||
SetMmuPrefix(0);
|
||||
return;
|
||||
break;
|
||||
case 3: //8192K //No Can 3
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Bank, data & 0x0F);
|
||||
SetMmuPrefix( (data & 0x30)>>4);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void SetMmuPrefix(unsigned char data)
|
||||
{
|
||||
MmuPrefix=(data & 3)<<8;
|
||||
return;
|
||||
}
|
||||
|
||||
void UpdateMmuArray()
|
||||
{
|
||||
if (!memory) return;
|
||||
if (MapType)
|
||||
{
|
||||
MemPages[VectorMask[CurrentRamConfig]-3]=memory+(0x2000*(VectorMask[CurrentRamConfig]-3));
|
||||
MemPages[VectorMask[CurrentRamConfig]-2]=memory+(0x2000*(VectorMask[CurrentRamConfig]-2));
|
||||
MemPages[VectorMask[CurrentRamConfig]-1]=memory+(0x2000*(VectorMask[CurrentRamConfig]-1));
|
||||
MemPages[VectorMask[CurrentRamConfig]]=memory+(0x2000*VectorMask[CurrentRamConfig]);
|
||||
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-3]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-2]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-1]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]]=1;
|
||||
return;
|
||||
}
|
||||
switch (RomMap)
|
||||
{
|
||||
case 0:
|
||||
case 1: //16K Internal 16K External
|
||||
MemPages[VectorMask[CurrentRamConfig]-3]=InternalRomBuffer;
|
||||
MemPages[VectorMask[CurrentRamConfig]-2]=InternalRomBuffer+0x2000;
|
||||
MemPages[VectorMask[CurrentRamConfig]-1]=nullptr;
|
||||
MemPages[VectorMask[CurrentRamConfig]]=nullptr;
|
||||
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-3]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-2]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-1]=0;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]]=0x2000;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 2: // 32K Internal
|
||||
MemPages[VectorMask[CurrentRamConfig]-3]=InternalRomBuffer;
|
||||
MemPages[VectorMask[CurrentRamConfig]-2]=InternalRomBuffer+0x2000;
|
||||
MemPages[VectorMask[CurrentRamConfig]-1]=InternalRomBuffer+0x4000;
|
||||
MemPages[VectorMask[CurrentRamConfig]]=InternalRomBuffer+0x6000;
|
||||
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-3]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-2]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-1]=1;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]]=1;
|
||||
return;
|
||||
break;
|
||||
|
||||
case 3: //32K External
|
||||
MemPages[VectorMask[CurrentRamConfig]-1]=nullptr;
|
||||
MemPages[VectorMask[CurrentRamConfig]]=nullptr;
|
||||
MemPages[VectorMask[CurrentRamConfig]-3]=nullptr;
|
||||
MemPages[VectorMask[CurrentRamConfig]-2]=nullptr;
|
||||
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-1]=0;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]]=0x2000;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-3]=0x4000;
|
||||
MemPageOffsets[VectorMask[CurrentRamConfig]-2]=0x6000;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#ifndef __TCC1014MMU_H__
|
||||
#define __TCC1014MMU_H__
|
||||
#include <array>
|
||||
#include "CpuMemory.h"
|
||||
|
||||
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define VCC_CPU_FASTCALL __fastcall
|
||||
#else
|
||||
#define VCC_CPU_FASTCALL
|
||||
#endif
|
||||
|
||||
namespace VCC
|
||||
{
|
||||
enum class MMUSource { RAM = 0, InternalROM = 1, CartridgeROM = 2 };
|
||||
struct MMUMapping
|
||||
{
|
||||
std::uint16_t Page = 0; // latched page, before installed-RAM mirroring
|
||||
std::uint32_t RAMStart = 0; // backing RAM even when a ROM overlays it
|
||||
std::uint32_t SourceStart = 0; // physical RAM or ROM-relative byte offset
|
||||
MMUSource Source = MMUSource::RAM;
|
||||
};
|
||||
|
||||
struct MMUState
|
||||
{
|
||||
bool Enabled = false;
|
||||
int ActiveTask = 0;
|
||||
int RamVectors = 0;
|
||||
int RomMap = 0;
|
||||
|
||||
std::array<int, 8> Task0{};
|
||||
std::array<int, 8> Task1{};
|
||||
bool AllRAM = false;
|
||||
std::uint16_t Prefix = 0; // prefix for subsequent MMU register writes
|
||||
std::uint32_t RAMBytes = 0;
|
||||
std::uint32_t RAMVectorAddress = 0; // fixed physical start for FE00–FEFF
|
||||
// The mapping actually used by CPU reads, including fixed banks while
|
||||
// disabled. FE00–FEFF may override row 7; FF00–FFFF is the I/O/vector
|
||||
// window, and FFF0–FFFF always reads internal ROM at offset 7FF0.
|
||||
std::array<MMUMapping, 8> Effective{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
VCC::MMUState GetMMUState();
|
||||
void GetMMUPage(size_t page, std::array<unsigned char, 8192>& outBuffer);
|
||||
|
||||
unsigned char SafeMemRead8(unsigned short);
|
||||
unsigned char * MmuInit(unsigned char);
|
||||
unsigned char * Getint_rom_pointer();
|
||||
unsigned short GetMem(unsigned long);
|
||||
void SetMem(unsigned long, unsigned short);
|
||||
bool MemCheckWrite(unsigned short address);
|
||||
|
||||
void VCC_CPU_FASTCALL fMemWrite8(unsigned char,unsigned short );
|
||||
unsigned char VCC_CPU_FASTCALL fMemRead8(unsigned short);
|
||||
|
||||
void LoadRom();
|
||||
void Set_MmuTask(unsigned char);
|
||||
void SetMmuRegister(unsigned char,unsigned char);
|
||||
void Set_MmuEnabled (unsigned char );
|
||||
void SetRomMap(unsigned char );
|
||||
void SetVectors(unsigned char);
|
||||
void MmuReset();
|
||||
void MmuShutdown();
|
||||
unsigned char GetRamConfiguration();
|
||||
// Direct MMU implementation; CPU clients normally use CpuMemory.h.
|
||||
unsigned char MmuRead8(unsigned short address);
|
||||
void MmuWrite8(unsigned char value, unsigned short address);
|
||||
void MmuSetMapType(unsigned char type);
|
||||
void SetDistoRamBank(unsigned char);
|
||||
void SetMmuPrefix(unsigned char);
|
||||
unsigned char * Get_mem_pointer();
|
||||
|
||||
// FIXME: These need to be turned into an enum and the signature of functions
|
||||
// that use them updated.
|
||||
#define _128K 0
|
||||
#define _512K 1
|
||||
#define _2M 2
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,482 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include "tcc1014mmu.h"
|
||||
#include "tcc1014registers.h"
|
||||
#include "MachineHost.h"
|
||||
#include "CpuHost.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
static unsigned char VDG_Mode=0;
|
||||
static unsigned char Dis_Offset=0;
|
||||
static unsigned char MPU_Rate=0;
|
||||
static unsigned char GimeRegisters[256];
|
||||
static unsigned short VerticalOffsetRegister=0;
|
||||
void SetInit0(unsigned char);
|
||||
void SetInit1(unsigned char);
|
||||
void SetTimerMSB();
|
||||
void SetTimerLSB();
|
||||
unsigned char GetInit0();
|
||||
|
||||
//
|
||||
// Gime interrupt bits
|
||||
//
|
||||
constexpr auto GIME_INTR_TIMER = 1u << 5;
|
||||
constexpr auto GIME_INTR_HSYNC = 1u << 4;
|
||||
constexpr auto GIME_INTR_VSYNC = 1u << 3;
|
||||
constexpr auto GIME_INTR_RS232 = 1u << 2;
|
||||
constexpr auto GIME_INTR_KEYB = 1u << 1;
|
||||
constexpr auto GIME_INTR_CART = 1u << 0;
|
||||
|
||||
//
|
||||
// Gime interrupt status
|
||||
//
|
||||
static auto GimeFirqState = 0u;
|
||||
static auto GimeIrqState = 0u;
|
||||
static auto LastGimeFirq = 0u;
|
||||
static auto LastGimeIrq = 0u;
|
||||
|
||||
//
|
||||
// Gime irq/firq enabled to cpu?
|
||||
//
|
||||
bool GimeIrqToCpuEnabled() { return GimeRegisters[0x90] & 0x20; }
|
||||
bool GimeFirqToCpuEnabled() { return GimeRegisters[0x90] & 0x10; }
|
||||
|
||||
//
|
||||
// Returns the current timer counter
|
||||
//
|
||||
unsigned short GimeTimerCounter()
|
||||
{
|
||||
return ((GimeRegisters[0x94] << 8) + GimeRegisters[0x95]) & 0xFFF;
|
||||
}
|
||||
|
||||
//
|
||||
// Set interrupt GIME_INTR* flag
|
||||
//
|
||||
void GimeSetInterrupt(unsigned int flag)
|
||||
{
|
||||
// merge to internal state when enabled
|
||||
GimeIrqState |= (flag & GimeRegisters[0x92]) & 0x3F;
|
||||
GimeFirqState |= (flag & GimeRegisters[0x93]) & 0x3F;
|
||||
|
||||
// update state for enabled interrupt to cpu
|
||||
auto prevIrq = LastGimeIrq;
|
||||
auto prevFirq = LastGimeFirq;
|
||||
LastGimeIrq = GimeIrqToCpuEnabled() ? GimeIrqState : 0;
|
||||
LastGimeFirq = GimeFirqToCpuEnabled() ? GimeFirqState : 0;
|
||||
|
||||
// on state changed update irq line to cpu
|
||||
if (prevIrq != LastGimeIrq)
|
||||
{
|
||||
if (LastGimeIrq)
|
||||
VCC::Machine().AssertInterrupt(IS_GIME, INT_IRQ);
|
||||
else
|
||||
VCC::Machine().ClearInterrupt(IS_GIME, INT_IRQ);
|
||||
}
|
||||
|
||||
// on state changed update firq line to cpu
|
||||
if (prevFirq != LastGimeFirq)
|
||||
{
|
||||
if (LastGimeFirq)
|
||||
VCC::Machine().AssertInterrupt(IS_GIME, INT_FIRQ);
|
||||
else
|
||||
VCC::Machine().ClearInterrupt(IS_GIME, INT_FIRQ);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Clear gime irq GIME_INTR* flag, returns previous state.
|
||||
//
|
||||
unsigned char GimeClearIrq()
|
||||
{
|
||||
auto prevIrqState = GimeIrqState;
|
||||
auto prevIrq = LastGimeIrq;
|
||||
GimeIrqState = 0;
|
||||
LastGimeIrq = 0;
|
||||
|
||||
// if was previously set, clear line
|
||||
if (prevIrq && !LastGimeIrq)
|
||||
VCC::Machine().ClearInterrupt(IS_GIME, INT_IRQ);
|
||||
|
||||
return (unsigned char)prevIrqState;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear gime firq GIME_INTR* flag, returns previous state.
|
||||
//
|
||||
unsigned char GimeClearFirq()
|
||||
{
|
||||
auto prevFirqState = GimeFirqState;
|
||||
auto prevFirq = LastGimeFirq;
|
||||
GimeFirqState = 0;
|
||||
LastGimeFirq = 0;
|
||||
|
||||
// if was previously set, clear line
|
||||
if (prevFirq && !LastGimeFirq)
|
||||
VCC::Machine().ClearInterrupt(IS_GIME, INT_FIRQ);
|
||||
|
||||
return (unsigned char)prevFirqState;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset gime registers to defaults
|
||||
//
|
||||
void GimeRegistersReset()
|
||||
{
|
||||
// Release the CPU lines as well as the register-side latches.
|
||||
GimeClearIrq();
|
||||
GimeClearFirq();
|
||||
memset(GimeRegisters, 0, sizeof(GimeRegisters));
|
||||
|
||||
GimeFirqState = 0u;
|
||||
GimeIrqState = 0u;
|
||||
LastGimeFirq = 0u;
|
||||
LastGimeIrq = 0u;
|
||||
|
||||
VDG_Mode = 0;
|
||||
Dis_Offset = 0;
|
||||
MPU_Rate = 0;
|
||||
VerticalOffsetRegister = 0;
|
||||
}
|
||||
|
||||
void GimeWrite(unsigned char port,unsigned char data)
|
||||
{
|
||||
#if USE_NEWTIMING
|
||||
auto log = [](const char* fmt, auto ...args)
|
||||
{
|
||||
if (!VCC::CpuDebugger().IsTracingEnabled()) return;
|
||||
char tmp[100];
|
||||
std::snprintf(tmp, sizeof(tmp), fmt, args...);
|
||||
VCC::CpuDebugger().TraceRegisterWrite(tmp);
|
||||
};
|
||||
auto changed = GimeRegisters[port] ^ data;
|
||||
auto ifZeroTimerInterrupt = [changed]()
|
||||
{
|
||||
// interrupt on timer being enabled (Arkanoid sound)
|
||||
if ((changed & GIME_INTR_TIMER) && GimeTimerCounter() == 0)
|
||||
GimeAssertTimerInterupt();
|
||||
};
|
||||
auto bit = [data](int n) { return (data >> n) & 1; };
|
||||
auto bits = [data](int n, int m) { return (data >> n) & ((1 << (m - n + 1)) - 1); };
|
||||
#else
|
||||
auto log = [](auto...) {};
|
||||
auto changed = GimeRegisters[port] ^ data;
|
||||
auto bit = [](int) { return 0; };
|
||||
auto bits = [](int,int) { return 0; };
|
||||
|
||||
// when timer is 0 and its enabled, it interrupts almost immediately
|
||||
auto ifZeroTimerInterrupt = [changed,data]()
|
||||
{
|
||||
if ((data & changed & GIME_INTR_TIMER) && GimeTimerCounter() == 0)
|
||||
GimeAssertTimerInterupt();
|
||||
};
|
||||
#endif
|
||||
|
||||
GimeRegisters[port] = data;
|
||||
|
||||
switch (port)
|
||||
{
|
||||
case 0x90:
|
||||
log("INIT0: %02X CC1=%d MMU=%d IEN=%d FEN=%d", data, bit(7), bit(6), bit(5), bit(4));
|
||||
SetInit0(data);
|
||||
GimeSetInterrupt(GimeIrqState | GimeFirqState);
|
||||
break;
|
||||
|
||||
case 0x91:
|
||||
log("INIT1: %02X TINS=%d Task=%d", data, bit(5), bit(0));
|
||||
SetInit1(data);
|
||||
break;
|
||||
|
||||
case 0x92:
|
||||
log("IRQ: %02X", data);
|
||||
if (!data) GimeClearIrq(); // 3.3,3.8
|
||||
ifZeroTimerInterrupt();
|
||||
break;
|
||||
|
||||
case 0x93:
|
||||
log("FIRQ: %02X", data);
|
||||
if (!data) GimeClearFirq(); // as above
|
||||
ifZeroTimerInterrupt();
|
||||
break;
|
||||
|
||||
case 0x94:
|
||||
log("TMRH: %d", ((GimeRegisters[0x94] & 15) << 8) | GimeRegisters[0x95]);
|
||||
SetTimerMSB();
|
||||
break;
|
||||
|
||||
case 0x95:
|
||||
log("TMRL: %d", ((GimeRegisters[0x94] & 15) << 8) | GimeRegisters[0x95]);
|
||||
SetTimerLSB();
|
||||
break;
|
||||
|
||||
case 0x96:
|
||||
log("TURBO: %02X", data);
|
||||
VCC::Machine().SetTurbo(data & 1);
|
||||
break;
|
||||
|
||||
case 0x97:
|
||||
log("$97: %02X", data);
|
||||
break;
|
||||
|
||||
case 0x98:
|
||||
log("VMODE: %02X BP=%d LPR=%d", data, bit(7), bits(0, 2));
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Mode, data);
|
||||
break;
|
||||
|
||||
case 0x99:
|
||||
log("VRES: LPF=%d HR=%d CR=%d", bits(5, 6), bits(2, 4), bits(0, 1));
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Resolution, data);
|
||||
break;
|
||||
|
||||
case 0x9A:
|
||||
log("BDRC: %d", data);
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Border, data);
|
||||
break;
|
||||
|
||||
case 0x9B:
|
||||
log("BANK: %02X", data);
|
||||
SetDistoRamBank(data);
|
||||
break;
|
||||
|
||||
case 0x9C:
|
||||
log("VSC: %d", bits(0, 3));
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Scroll, GimeRegisters[0x9C]);
|
||||
break;
|
||||
|
||||
case 0x9D:
|
||||
case 0x9E:
|
||||
log("VOFF: %05X", ((GimeRegisters[0x9D] << 8) | GimeRegisters[0x9E]) * 8);
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Offset, (GimeRegisters[0x9D] << 8) | GimeRegisters[0x9E]);
|
||||
break;
|
||||
|
||||
case 0x9F:
|
||||
log("HOFF: %d HVEN=%d", bits(0, 6) * 2, bit(7));
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::HorizontalOffset, data);
|
||||
break;
|
||||
|
||||
case 0xA0:case 0xA1:case 0xA2:case 0xA3:case 0xA4:case 0xA5:case 0xA6:case 0xA7:
|
||||
case 0xA8:case 0xA9:case 0xAA:case 0xAB:case 0xAC:case 0xAD:case 0xAE:case 0xAF:
|
||||
log("MMU: %X=%02X (%02X...)", port, data, data*2);
|
||||
SetMmuRegister(port, data);
|
||||
break;
|
||||
|
||||
case 0xB0:case 0xB1:case 0xB2:case 0xB3:case 0xB4:case 0xB5:case 0xB6:case 0xB7:
|
||||
case 0xB8:case 0xB9:case 0xBA:case 0xBB:case 0xBC:case 0xBD:case 0xBE:case 0xBF:
|
||||
log("PAL: %d=%d", port - 0xB0, bits(0, 5));
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Palette, data & 63, port - 0xB0);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// return gime registers (normally unreadable) for the debugger/memory window
|
||||
// and without changing any state.
|
||||
//
|
||||
unsigned char SafeGimeRead(unsigned char port)
|
||||
{
|
||||
// TODO: return last irq state
|
||||
if (port == 0x92) return GimeRegisters[port];
|
||||
if (port == 0x93) return GimeRegisters[port];
|
||||
return GimeRegisters[port];
|
||||
}
|
||||
|
||||
unsigned char GimeRead(unsigned char port)
|
||||
{
|
||||
auto lastBus = []()
|
||||
{
|
||||
auto cpuState = VCC::Machine().CpuState();
|
||||
return cpuState.PC < 0xFF00 ? MemRead8(cpuState.PC) : 0;
|
||||
};
|
||||
|
||||
// iobus sets port range 0x90 to 0xBF
|
||||
auto data = 0;
|
||||
switch (port)
|
||||
{
|
||||
case 0x92:
|
||||
// note, clear all irq flags & interrupt line should be cleared if was
|
||||
// set otherwise extra interrupts will occur. this is noticable in robocop
|
||||
// the sound will repeat/stutter.
|
||||
// note, return internal flags to program, see rtaylor's timer dsk.
|
||||
return GimeClearIrq();
|
||||
case 0x93:
|
||||
// note, as above.
|
||||
return GimeClearFirq();
|
||||
default:
|
||||
data = GimeRegisters[port];
|
||||
// mmu registers,
|
||||
if (port >= 0xA0 && port <= 0xAF)
|
||||
{
|
||||
// - if 128k or 512k upper bits are not driven by gime
|
||||
if (GetRamConfiguration() <= 1)
|
||||
return (lastBus() & 0xC0) | (data & 0x3F);
|
||||
|
||||
// - else if 2048/8192k read all bits
|
||||
return data;
|
||||
}
|
||||
|
||||
// palette registers, read lower bits
|
||||
if (port >= 0xB0 && port <= 0xBF)
|
||||
return (lastBus() & 0xC0) | (data & 0x3F);
|
||||
|
||||
// other gime registers are unreadable
|
||||
return lastBus();
|
||||
}
|
||||
}
|
||||
|
||||
void SetInit0(unsigned char data)
|
||||
{
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::Compatibility, !!(data & 128));
|
||||
Set_MmuEnabled (!!(data & 64)); //MMUEN
|
||||
SetRomMap(data & 3); //MC0-MC1
|
||||
SetVectors(data & 8); //MC3
|
||||
}
|
||||
|
||||
void SetInit1(unsigned char data)
|
||||
{
|
||||
Set_MmuTask(data & 1); //TR
|
||||
VCC::Machine().TimerWrite(VCC::TimerRegister::ClockSource, data & 32); //TINS
|
||||
}
|
||||
|
||||
unsigned char GetInit0()
|
||||
{
|
||||
unsigned char data=0;
|
||||
return data;
|
||||
}
|
||||
|
||||
void SetTimerMSB() //94
|
||||
{
|
||||
VCC::Machine().TimerWrite(VCC::TimerRegister::Restart, GimeTimerCounter());
|
||||
}
|
||||
|
||||
void SetTimerLSB() //95
|
||||
{
|
||||
// does not restart timer but just update the cached time
|
||||
VCC::Machine().TimerWrite(VCC::TimerRegister::Reload, GimeTimerCounter());
|
||||
}
|
||||
|
||||
void GimeAssertKeyboardInterupt()
|
||||
{
|
||||
GimeSetInterrupt(GIME_INTR_KEYB);
|
||||
}
|
||||
|
||||
void GimeAssertVertInterupt()
|
||||
{
|
||||
GimeSetInterrupt(GIME_INTR_VSYNC);
|
||||
}
|
||||
|
||||
void GimeAssertHorzInterupt()
|
||||
{
|
||||
GimeSetInterrupt(GIME_INTR_HSYNC);
|
||||
}
|
||||
|
||||
void GimeAssertTimerInterupt()
|
||||
{
|
||||
GimeSetInterrupt(GIME_INTR_TIMER);
|
||||
}
|
||||
|
||||
void GimeAssertCartInterupt()
|
||||
{
|
||||
GimeSetInterrupt(GIME_INTR_CART);
|
||||
}
|
||||
unsigned char sam_read(unsigned char port) //SAM don't talk much :)
|
||||
{
|
||||
|
||||
if ( (port>=0xF0) & (port <=0xFF)) //IRQ vectors from rom
|
||||
return Getint_rom_pointer() ? Getint_rom_pointer()[0x7F00 + port] : 0xFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
void sam_write(unsigned char port)
|
||||
{
|
||||
unsigned char mask=0;
|
||||
unsigned char reg=0;
|
||||
|
||||
if ((port >=0xC6) & (port <=0xD3)) //VDG Display offset Section
|
||||
{
|
||||
port=port-0xC6;
|
||||
reg= ((port & 0x0E)>>1);
|
||||
mask= 1<<reg;
|
||||
Dis_Offset= Dis_Offset & (0xFF-mask); //Shut the bit off
|
||||
if (port & 1)
|
||||
Dis_Offset= Dis_Offset | mask;
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::VdgOffset, Dis_Offset);
|
||||
}
|
||||
|
||||
if ((port >=0xC0) & (port <=0xC5)) //VDG Mode
|
||||
{
|
||||
port=port-0xC0;
|
||||
reg= ((port & 0x0E)>>1);
|
||||
mask= 1<<reg;
|
||||
VDG_Mode = VDG_Mode & (0xFF-mask);
|
||||
if (port & 1)
|
||||
VDG_Mode = VDG_Mode | mask;
|
||||
VCC::Machine().VideoWrite(VCC::VideoRegister::VdgMode, VDG_Mode);
|
||||
}
|
||||
|
||||
if ( (port==0xDE) | (port ==0xDF))
|
||||
SetMapType(port&1);
|
||||
|
||||
// RAM high speed poke
|
||||
if (port==0xD9)
|
||||
VCC::Machine().SetCpuSpeed(1);
|
||||
|
||||
if (port==0xD8)
|
||||
VCC::Machine().SetCpuSpeed(0);
|
||||
|
||||
//
|
||||
// todo: ROM high speed poke, currently unsupported by vcc
|
||||
// should only be fast in rom not ram so can't just use
|
||||
// SetCPUMultiplyerFlag.
|
||||
//
|
||||
// if (port==0xD7)
|
||||
// SetCPUMultiplyerFlag (1);
|
||||
//
|
||||
// if (port==0xD6)
|
||||
// SetCPUMultiplyerFlag (0);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void mc6883_reset()
|
||||
{
|
||||
VDG_Mode=0;
|
||||
Dis_Offset=0;
|
||||
MPU_Rate=0;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char VDG_Offset()
|
||||
{
|
||||
return Dis_Offset;
|
||||
}
|
||||
|
||||
unsigned char VDG_Modes()
|
||||
{
|
||||
return VDG_Mode;
|
||||
}
|
||||
|
||||
// notes:
|
||||
// 3.3 - zero reg resets flags
|
||||
// 3.8 - clear partial flags has no effect
|
||||
//
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef __TCC1014REGISTERS_H__
|
||||
#define __TCC1014REGISTERS_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
void GimeWrite(unsigned char,unsigned char);
|
||||
unsigned char GimeRead(unsigned char);
|
||||
unsigned char SafeGimeRead(unsigned char port); // for debug only
|
||||
void GimeAssertKeyboardInterupt();
|
||||
void GimeRegistersReset();
|
||||
void GimeAssertHorzInterupt();
|
||||
void GimeAssertVertInterupt();
|
||||
void GimeAssertTimerInterupt();
|
||||
void GimeAssertCartInterupt();
|
||||
unsigned char sam_read(unsigned char);
|
||||
void sam_write(unsigned char);
|
||||
void mc6883_reset();
|
||||
unsigned char VDG_Offset();
|
||||
unsigned char VDG_Modes();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// MPI routing adapted from pakrouter.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Devices {
|
||||
// Synchronous emulation-thread callbacks. Devices never own a native window
|
||||
// or scheduler callback. Folder-backed SDC owns bounded file handles on this
|
||||
// same queue. The bus stops delivering ticks on detach.
|
||||
class DeviceHost {
|
||||
public:
|
||||
virtual ~DeviceHost() = default;
|
||||
virtual void cartridgeNmi() = 0;
|
||||
virtual void resetBeckerPort() {}
|
||||
virtual std::uint8_t readBeckerPort(std::uint8_t) { return 0; }
|
||||
virtual void writeBeckerPort(std::uint8_t, std::uint8_t) {}
|
||||
virtual void cartridgeLine(bool) {}
|
||||
virtual std::uint8_t cartridgeReadMemory(std::uint16_t) { return 0xff; }
|
||||
virtual void cartridgeWriteMemory(std::uint16_t, std::uint8_t) {}
|
||||
};
|
||||
class CartridgeDevice {
|
||||
public:
|
||||
virtual ~CartridgeDevice() = default;
|
||||
virtual void reset() = 0;
|
||||
virtual void horizontalSync(DeviceHost&) = 0;
|
||||
virtual std::uint8_t readMemory(std::uint16_t) const = 0;
|
||||
virtual std::uint8_t readPort(std::uint8_t, DeviceHost&) = 0;
|
||||
virtual void writePort(std::uint8_t, std::uint8_t, DeviceHost&) = 0;
|
||||
// Called once per emulated 44.1 kHz sample, even when host output is muted.
|
||||
virtual void advanceAudio() {}
|
||||
virtual std::uint16_t audio() const { return 0; }
|
||||
virtual bool hasExternalAudioOutput() const { return false; }
|
||||
// An active cartridge SND output uses unsigned PCM with 128 at silence.
|
||||
// Presence is distinct from sample zero, which is a valid negative peak.
|
||||
virtual bool hasCartridgeAudioOutput() const { return false; }
|
||||
virtual bool cartLine() const { return false; }
|
||||
};
|
||||
enum class DeviceKind { FD502, RamDisk, Orchestra90, SpeechSound };
|
||||
// Explicit built-in registry; no dynamic libraries or Windows entry points.
|
||||
// ROM images use RomCartridge; additional built-in devices can join this registry.
|
||||
std::unique_ptr<CartridgeDevice> makeDevice(DeviceKind, const std::vector<std::uint8_t>& rom);
|
||||
|
||||
// Five retained assignments: single cartridge (0), Multi-Pak slots (1...4).
|
||||
// Routing follows pakrouter.cpp: CTS ROM, SCS FF40-FF5F, other ports broadcast;
|
||||
// first nonzero read wins, all active slots receive ticks and NMI is ungated.
|
||||
class CartridgeBus final : private DeviceHost {
|
||||
public:
|
||||
using Slots = std::array<std::shared_ptr<CartridgeDevice>, 5>;
|
||||
void connect(DeviceHost* host) {
|
||||
if (destination && destination != host) destination->cartridgeLine(false);
|
||||
destination = host; publishLine();
|
||||
}
|
||||
void install(std::unique_ptr<CartridgeDevice> next) {
|
||||
slots[0] = std::move(next); reset();
|
||||
}
|
||||
void configure(Slots next, bool enabled, unsigned physical) {
|
||||
if (physical < 1 || physical > 4) throw std::invalid_argument("MPI slot must be 1 through 4");
|
||||
// One device instance may be retained in each mode, never twice in MPI.
|
||||
for (unsigned i = 1; i < 5; ++i)
|
||||
for (unsigned j = i + 1; j < 5; ++j)
|
||||
if (next[i] && next[i] == next[j]) throw std::invalid_argument("Duplicate MPI device instance");
|
||||
slots = std::move(next); mpi = enabled; switchSlot = physical; reset();
|
||||
}
|
||||
void reset() {
|
||||
if (destination) destination->resetBeckerPort();
|
||||
for (unsigned i = 0; i < 5; ++i) {
|
||||
if (!slots[i]) continue;
|
||||
bool seen = false;
|
||||
for (unsigned j = 0; j < i; ++j) if (slots[j] == slots[i]) seen = true;
|
||||
if (!seen) slots[i]->reset();
|
||||
}
|
||||
cts = scs = mpi ? switchSlot : 0; publishLine();
|
||||
}
|
||||
bool multiPak() const { return mpi; }
|
||||
unsigned physicalSlot() const { return switchSlot; }
|
||||
unsigned romSlot() const { return cts; }
|
||||
unsigned ioSlot() const { return scs; }
|
||||
CartridgeDevice* at(unsigned slot) const { return slots.at(slot).get(); }
|
||||
void horizontalSync() {
|
||||
if (!destination) return;
|
||||
if (!mpi) { if (slots[0]) slots[0]->horizontalSync(*this); }
|
||||
else for (unsigned i = 4; i > 0; --i) if (slots[i]) slots[i]->horizontalSync(*this);
|
||||
publishLine();
|
||||
}
|
||||
std::uint8_t readMemory(std::uint16_t address) const { return slots[cts] ? slots[cts]->readMemory(address) : 0xff; }
|
||||
std::uint8_t readPort(std::uint8_t port) {
|
||||
if (!mpi) return read(0, port);
|
||||
if (port == 0x7f) return ((cts - 1) << 4) | (scs - 1);
|
||||
if (port >= 0x40 && port <= 0x5f) return read(scs, port);
|
||||
for (unsigned i = 1; i <= 4; ++i) if (auto value = read(i, port)) return value;
|
||||
return 0;
|
||||
}
|
||||
void writePort(std::uint8_t port, std::uint8_t value) {
|
||||
if (!mpi) { write(0, port, value); return; }
|
||||
if (port == 0x7f) { cts = ((value >> 4) & 3) + 1; scs = (value & 3) + 1; publishLine(); return; }
|
||||
if (port >= 0x40 && port <= 0x5f) { write(scs, port, value); return; }
|
||||
for (unsigned i = 1; i <= 4; ++i) write(i, port, value);
|
||||
}
|
||||
void advanceAudio() {
|
||||
if (!mpi) { if (slots[0]) slots[0]->advanceAudio(); }
|
||||
else for (unsigned i = 1; i <= 4; ++i) if (slots[i]) slots[i]->advanceAudio();
|
||||
}
|
||||
enum class AudioOutputs { All, ExternalOnly };
|
||||
std::uint16_t audio(AudioOutputs outputs = AudioOutputs::All) const {
|
||||
auto sampleOf = [outputs](const std::shared_ptr<CartridgeDevice>& device) -> std::uint16_t {
|
||||
if (!device || (outputs == AudioOutputs::ExternalOnly && !device->hasExternalAudioOutput())) return 0;
|
||||
return device->audio();
|
||||
};
|
||||
if (!mpi) return sampleOf(slots[0]);
|
||||
int left = 0, right = 0; bool any = false;
|
||||
for (unsigned i = 1; i <= 4; ++i) {
|
||||
auto sample = sampleOf(slots[i]);
|
||||
if (sample) { any = true; left += (sample >> 8) - 128; right += (sample & 255) - 128; }
|
||||
}
|
||||
return any ? (std::clamp(left + 128, 0, 255) << 8) | std::clamp(right + 128, 0, 255) : 0;
|
||||
}
|
||||
std::array<float, 2> speakerAudio() const {
|
||||
std::array<float, 2> result{};
|
||||
auto add = [&](const std::shared_ptr<CartridgeDevice>& device) {
|
||||
if (!device || !device->hasCartridgeAudioOutput()) return;
|
||||
const auto value = device->audio();
|
||||
result[0] += (int(value >> 8) - 128) / 256.0f;
|
||||
result[1] += (int(value & 255) - 128) / 256.0f;
|
||||
};
|
||||
if (!mpi) add(slots[0]);
|
||||
else for (unsigned i = 1; i <= 4; ++i) add(slots[i]);
|
||||
return result;
|
||||
}
|
||||
CartridgeDevice* current() { return slots[cts].get(); }
|
||||
private:
|
||||
void publishLine() { if (destination) destination->cartridgeLine(slots[cts] && slots[cts]->cartLine()); }
|
||||
std::uint8_t cartridgeReadMemory(std::uint16_t address) override { return destination ? destination->cartridgeReadMemory(address) : 0xff; }
|
||||
void cartridgeWriteMemory(std::uint16_t address, std::uint8_t value) override { if (destination) destination->cartridgeWriteMemory(address, value); }
|
||||
std::uint8_t readBeckerPort(std::uint8_t port) override { return destination ? destination->readBeckerPort(port) : 0; }
|
||||
void writeBeckerPort(std::uint8_t port, std::uint8_t value) override { if (destination) destination->writeBeckerPort(port, value); }
|
||||
void cartridgeNmi() override { if (destination) destination->cartridgeNmi(); }
|
||||
std::uint8_t read(unsigned slot, std::uint8_t port) { return slots[slot] ? slots[slot]->readPort(port, *this) : 0; }
|
||||
void write(unsigned slot, std::uint8_t port, std::uint8_t value) { if (slots[slot]) slots[slot]->writePort(port, value, *this); }
|
||||
DeviceHost* destination = nullptr;
|
||||
Slots slots;
|
||||
bool mpi = false;
|
||||
unsigned switchSlot = 4, cts = 0, scs = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Independent implementation of the DriveWire virtual-channel protocol.
|
||||
// https://github.com/DrPitre/DriveWire/blob/main/DriveWire%20Specification.md
|
||||
#include "DriveWireDevice.h"
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
namespace VCC::Devices {
|
||||
namespace {
|
||||
using Byte = std::uint8_t;
|
||||
constexpr Byte readStatus = 0x41, dataPort = 0x42;
|
||||
constexpr Byte drvInit = 0x5a, pollChannels = 0x43, serialInit = 0x45, serialTerm = 0xc5;
|
||||
constexpr Byte serialReadMany = 0x63, serialWriteMany = 0x64, serialWrite = 0xc3;
|
||||
constexpr Byte serialGetStat = 0x44, serialSetStat = 0xc4, fastBase = 0x80;
|
||||
constexpr Byte ssComSt = 0x28, ssOpen = 0x29, ssClose = 0x2a;
|
||||
constexpr Byte notReady = 246;
|
||||
|
||||
// Fixed lengths include the opcode. Variable-length packets grow once their
|
||||
// length field arrives. Consume known out-of-scope operations as units so a
|
||||
// printer byte or disk sector cannot accidentally become a network command.
|
||||
std::size_t packetLength(Byte op) {
|
||||
if ((op >= fastBase && op <= 0x8f) || (op >= 0x90 && op <= 0x9e)) return 2;
|
||||
switch (op) {
|
||||
case 0x01: case 0x02: case 0x50: case drvInit: case serialInit: case serialTerm: return 2;
|
||||
case 0x47: case 0x53: case serialReadMany: case serialWriteMany:
|
||||
case serialWrite: case serialGetStat: case serialSetStat: return 3;
|
||||
case 0x52: case 0x72: case 0xd2: case 0xf2: return 5;
|
||||
case 0x57: case 0x77: return 263;
|
||||
case 0x42: return 24;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void append(std::deque<Byte>& queue, const std::string& text) {
|
||||
queue.insert(queue.end(), text.begin(), text.end());
|
||||
}
|
||||
|
||||
bool matchesWord(const std::string& word, const char* lowercase) {
|
||||
return std::equal(word.begin(), word.end(), lowercase, lowercase + std::char_traits<char>::length(lowercase),
|
||||
[](unsigned char a, char b) { return (a >= 'A' && a <= 'Z' ? a + ('a' - 'A') : a) == b; });
|
||||
}
|
||||
}
|
||||
|
||||
void DriveWireDevice::reset() {
|
||||
for (auto& channel : channels) channel = Channel{};
|
||||
packet.clear();
|
||||
replies.clear();
|
||||
needed = 0;
|
||||
nextPoll = 0;
|
||||
}
|
||||
|
||||
void DriveWireDevice::setFactory(DriveWireFactory replacement) {
|
||||
reset();
|
||||
factory = std::move(replacement);
|
||||
}
|
||||
|
||||
Byte DriveWireDevice::readPort(Byte port) {
|
||||
if (port == readStatus) return replies.empty() ? 0 : 2;
|
||||
if (port != dataPort || replies.empty()) return 0;
|
||||
Byte byte = replies.front();
|
||||
replies.pop_front();
|
||||
return byte;
|
||||
}
|
||||
|
||||
void DriveWireDevice::reply(Byte value) {
|
||||
// The guest normally reads each response before issuing another request.
|
||||
// Bound storage even for a guest that never reads the Becker data register.
|
||||
if (replies.size() < 4096) replies.push_back(value);
|
||||
}
|
||||
|
||||
void DriveWireDevice::writePort(Byte port, Byte byte) {
|
||||
if (port != dataPort) return;
|
||||
if (packet.empty()) needed = packetLength(byte);
|
||||
packet.push_back(byte);
|
||||
const Byte op = packet.front();
|
||||
if (packet.size() == 2 && (op == 0x01 || op == 0x02)) needed += byte;
|
||||
if (packet.size() == 3 && op == serialWriteMany) needed += byte;
|
||||
if (packet.size() == 3 && op == serialSetStat && byte == ssComSt) needed += 26;
|
||||
if (packet.size() < needed) return;
|
||||
// Extended sector reads return 256 zero bytes for an absent drive. The
|
||||
// guest still sends its checksum before receiving the final error.
|
||||
if ((op == 0xd2 || op == 0xf2) && needed == 5) {
|
||||
for (unsigned i = 0; i < 256; ++i) reply(0);
|
||||
needed += 2;
|
||||
return;
|
||||
}
|
||||
finishPacket();
|
||||
packet.clear();
|
||||
}
|
||||
|
||||
void DriveWireDevice::finishPacket() {
|
||||
const Byte op = packet.front();
|
||||
if (op == 0xff || op == 0xfe || op == 0xf8) { reset(); return; }
|
||||
if (op == drvInit) { reply(4); return; }
|
||||
if (op == pollChannels) { poll(); return; }
|
||||
if (op >= fastBase && op < fastBase + channels.size()) {
|
||||
writeChannel(op - fastBase, &packet[1], 1);
|
||||
return;
|
||||
}
|
||||
switch (op) {
|
||||
case 0x01: case 0x02: reply(0); return;
|
||||
case 0x52: case 0x72: case 0xd2: case 0xf2: case 0x57: case 0x77: reply(notReady); return;
|
||||
default: break;
|
||||
}
|
||||
if (packet.size() < 2 || packet[1] >= channels.size()) return;
|
||||
auto& channel = channels[packet[1]];
|
||||
if (op == serialTerm || (op == serialSetStat && packet[2] == ssClose)) {
|
||||
channel = Channel{};
|
||||
} else if (op == serialInit || (op == serialSetStat && packet[2] == ssOpen)) {
|
||||
if (channel.mode == Channel::inactive) channel.mode = Channel::command;
|
||||
} else if (op == serialReadMany) {
|
||||
auto count = packet[2];
|
||||
if (count > channel.incoming.size()) return;
|
||||
while (count--) {
|
||||
reply(channel.incoming.front());
|
||||
channel.incoming.pop_front();
|
||||
}
|
||||
} else if (op == serialWrite) {
|
||||
writeChannel(packet[1], &packet[2], 1);
|
||||
} else if (op == serialWriteMany) {
|
||||
writeChannel(packet[1], packet.data() + 3, packet[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void DriveWireDevice::finishChannel(Channel& channel, const char* message) {
|
||||
if (*message) append(channel.incoming, message);
|
||||
channel.socket.reset();
|
||||
channel.mode = Channel::closing;
|
||||
}
|
||||
|
||||
void DriveWireDevice::runCommand(Channel& channel) {
|
||||
std::istringstream input(std::move(channel.line));
|
||||
channel.line.clear();
|
||||
std::string tcp, connect, host, portText, excess;
|
||||
if (!(input >> tcp >> connect >> host >> portText) || (input >> excess) ||
|
||||
!matchesWord(tcp, "tcp") || !matchesWord(connect, "connect")) {
|
||||
finishChannel(channel, "FAIL 203\n\r");
|
||||
return;
|
||||
}
|
||||
std::uint16_t port = 0;
|
||||
const auto end = portText.data() + portText.size();
|
||||
const auto parsed = std::from_chars(portText.data(), end, port);
|
||||
if (parsed.ec != std::errc{} || parsed.ptr != end || !port || host.size() > 253) {
|
||||
finishChannel(channel, "FAIL 203\n\r");
|
||||
return;
|
||||
}
|
||||
if (factory) channel.socket = factory(host, port);
|
||||
if (channel.socket) channel.mode = Channel::connecting;
|
||||
else finishChannel(channel, "FAIL 246\n\r");
|
||||
}
|
||||
|
||||
void DriveWireDevice::writeChannel(unsigned index, const Byte* bytes, std::size_t count) {
|
||||
auto& channel = channels[index];
|
||||
for (std::size_t pos = 0; pos < count; ++pos) {
|
||||
if (channel.mode == Channel::online) {
|
||||
if (!channel.socket->write(bytes + pos, count - pos)) finishChannel(channel, "");
|
||||
return;
|
||||
}
|
||||
if (channel.mode != Channel::command) return;
|
||||
Byte byte = bytes[pos];
|
||||
if (byte == '\r' || byte == '\n') {
|
||||
if (!channel.line.empty()) runCommand(channel);
|
||||
} else if (byte < 32 || byte > 126 || channel.line.size() >= 512) {
|
||||
finishChannel(channel, "FAIL 203\n\r");
|
||||
} else {
|
||||
channel.line.push_back(static_cast<char>(byte));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DriveWireDevice::update(Channel& channel) {
|
||||
if (!channel.socket) return;
|
||||
// Poll the socket only on a virtual-channel poll. The socket retains
|
||||
// additional input until the emulated OS drains our bounded receive queue.
|
||||
auto state = channel.socket->state();
|
||||
using State = DriveWireTransport::State;
|
||||
if (state == State::connecting) return;
|
||||
if (channel.mode == Channel::connecting) {
|
||||
if (state == State::failed) { finishChannel(channel, "FAIL 246\n\r"); return; }
|
||||
// NitrOS-9 netlib reads this modem result line before consuming
|
||||
// socket data. Its TCP commands use SUCCESS or FAIL <OS-9 error>;
|
||||
// numeric DW administration responses are a different command family.
|
||||
append(channel.incoming, "SUCCESS\n\r");
|
||||
channel.mode = Channel::online;
|
||||
}
|
||||
if (!channel.incoming.empty()) return;
|
||||
Byte bytes[255];
|
||||
const auto count = channel.socket->read(bytes, sizeof bytes);
|
||||
channel.incoming.insert(channel.incoming.end(), bytes, bytes + count);
|
||||
if (!count && (state == State::closed || state == State::failed)) finishChannel(channel, "");
|
||||
}
|
||||
|
||||
void DriveWireDevice::poll() {
|
||||
for (std::size_t offset = 0; offset < channels.size(); ++offset) {
|
||||
const auto index = (nextPoll + offset) % channels.size();
|
||||
auto& channel = channels[index];
|
||||
update(channel);
|
||||
auto count = channel.incoming.size();
|
||||
if (count > 1) {
|
||||
reply(static_cast<Byte>(0x11 + index));
|
||||
reply(static_cast<Byte>(std::min<std::size_t>(255, count)));
|
||||
} else if (count == 1) {
|
||||
reply(static_cast<Byte>(1 + index));
|
||||
reply(channel.incoming.front());
|
||||
channel.incoming.pop_front();
|
||||
} else if (channel.mode == Channel::closing) {
|
||||
reply(0x10);
|
||||
reply(static_cast<Byte>(index));
|
||||
channel = Channel{};
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
nextPoll = (index + 1) % channels.size();
|
||||
return;
|
||||
}
|
||||
reply(0);
|
||||
reply(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include "DriveWireTransport.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Devices {
|
||||
// Single-emulation-thread endpoint. The two Becker registers carry DriveWire
|
||||
// transactions; a virtual serial channel can independently open an outbound TCP stream.
|
||||
class DriveWireDevice {
|
||||
public:
|
||||
void setFactory(DriveWireFactory factory);
|
||||
void reset();
|
||||
std::uint8_t readPort(std::uint8_t port);
|
||||
void writePort(std::uint8_t port, std::uint8_t byte);
|
||||
private:
|
||||
struct Channel {
|
||||
enum Mode { inactive, command, connecting, online, closing } mode = inactive;
|
||||
std::unique_ptr<DriveWireTransport> socket;
|
||||
std::string line;
|
||||
std::deque<std::uint8_t> incoming;
|
||||
};
|
||||
DriveWireFactory factory;
|
||||
std::array<Channel, 15> channels;
|
||||
std::size_t nextPoll = 0;
|
||||
std::deque<std::uint8_t> replies;
|
||||
std::vector<std::uint8_t> packet;
|
||||
std::size_t needed = 0;
|
||||
void finishPacket();
|
||||
void poll();
|
||||
void writeChannel(unsigned index, const std::uint8_t* bytes, std::size_t count);
|
||||
void runCommand(Channel&);
|
||||
void update(Channel&);
|
||||
static void finishChannel(Channel&, const char* message);
|
||||
void reply(std::uint8_t value);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace VCC::Devices {
|
||||
|
||||
// A fresh outbound byte stream per guest connection. All methods, including
|
||||
// destruction, return without waiting for network I/O. Drain read() after EOF.
|
||||
class DriveWireTransport {
|
||||
public:
|
||||
enum class State { connecting, connected, closed, failed };
|
||||
|
||||
virtual ~DriveWireTransport() = default;
|
||||
virtual State state() = 0;
|
||||
virtual std::size_t read(std::uint8_t* bytes, std::size_t capacity) = 0;
|
||||
// Accepts the entire span, or returns false without queuing any of it.
|
||||
virtual bool write(const std::uint8_t* bytes, std::size_t count) = 0;
|
||||
};
|
||||
|
||||
using DriveWireFactory = std::function<std::unique_ptr<DriveWireTransport>(const std::string&, std::uint16_t)>;
|
||||
|
||||
|
||||
std::unique_ptr<DriveWireTransport> makeDriveWireTCPConnection(const std::string& host, std::uint16_t port);
|
||||
|
||||
} // namespace VCC::Devices
|
||||
@@ -0,0 +1,381 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Adapted from the image geometry/sector paths in wd1793.cpp,
|
||||
// copyright 2015 Joseph Forgione. Host handles and physical drives are excluded.
|
||||
#include "DiskImage.h"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace VCC::Devices {
|
||||
namespace {
|
||||
constexpr auto invalid = std::numeric_limits<std::size_t>::max();
|
||||
using Bytes = std::vector<std::uint8_t>;
|
||||
|
||||
unsigned littleWord(const Bytes& bytes, std::size_t offset) {
|
||||
return bytes[offset] | (unsigned(bytes[offset + 1]) << 8);
|
||||
}
|
||||
|
||||
std::uint16_t crcByte(std::uint16_t crc, std::uint8_t value) {
|
||||
crc ^= std::uint16_t(value) << 8;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : crc << 1;
|
||||
return crc;
|
||||
}
|
||||
|
||||
std::uint16_t fieldCRC(const Bytes& bytes, std::size_t start, unsigned size,
|
||||
unsigned stride, bool mfm) {
|
||||
// CCITT after three A1 sync bytes in MFM; FM starts with the address mark.
|
||||
std::uint16_t crc = mfm ? 0xcdb4 : 0xffff;
|
||||
for (unsigned i = 0; i < size; ++i) crc = crcByte(crc, bytes[start + i * stride]);
|
||||
return crc;
|
||||
}
|
||||
|
||||
struct AddressMark {
|
||||
std::size_t id;
|
||||
unsigned stride;
|
||||
bool mfm;
|
||||
|
||||
bool crcValid(const Bytes& bytes) const { return fieldCRC(bytes, id, 7, stride, mfm) == 0; }
|
||||
};
|
||||
|
||||
std::vector<AddressMark> trackIDs(const Bytes& bytes, std::size_t base, std::size_t length) {
|
||||
std::vector<AddressMark> ids;
|
||||
for (unsigned slot = 0; slot < 64; ++slot) {
|
||||
const auto pointer = littleWord(bytes, base + slot * 2);
|
||||
if (pointer == 0 || pointer == 0xffff) break;
|
||||
const auto offset = pointer & 0x3fff;
|
||||
const bool mfm = pointer & 0x8000;
|
||||
// Mixed-density DMK stores each FM byte twice. Single-density-only
|
||||
// images and images with the ignore-density flag store it just once.
|
||||
const unsigned stride = mfm || (bytes[4] & 0xc0) ? 1 : 2;
|
||||
if (offset >= 128 && offset + 7 * stride <= length && bytes[base + offset] == 0xfe)
|
||||
ids.push_back({base + offset, stride, mfm});
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
struct SectorLocation {
|
||||
std::size_t mark = invalid;
|
||||
unsigned size = 0, stride = 1;
|
||||
bool mfm = false;
|
||||
};
|
||||
|
||||
SectorLocation findSector(const Bytes& bytes, std::size_t track, std::size_t length,
|
||||
unsigned cylinder, unsigned sector) {
|
||||
// Some protected tracks contain malformed pointers, duplicate IDs, or IDs
|
||||
// without data marks. Leave the entire track intact for READ TRACK.
|
||||
auto ids = trackIDs(bytes, track, length);
|
||||
// The FD-502 verifies the address CRC before recognizing a sector.
|
||||
// Protected disks can index stray FE patterns in the sync gap before
|
||||
// a genuine data mark. Those pointers cannot end the preceding field.
|
||||
ids.erase(std::remove_if(ids.begin(), ids.end(), [&](const AddressMark& id) {
|
||||
return !id.crcValid(bytes);
|
||||
}), ids.end());
|
||||
for (const auto& id : ids) {
|
||||
const auto at = id.id;
|
||||
const unsigned stride = id.stride;
|
||||
if (bytes[at + stride] != cylinder || bytes[at + 3 * stride] != sector) continue;
|
||||
const unsigned size = 128u << (bytes[at + 4 * stride] & 3);
|
||||
auto end = track + length;
|
||||
for (const auto& next : ids)
|
||||
if (next.id > at) end = std::min(end, next.id);
|
||||
const auto start = at + 7 * stride;
|
||||
const auto searchEnd = std::min(end, start + 43 * stride);
|
||||
for (auto mark = start; mark < searchEnd; mark += stride) {
|
||||
if (bytes[mark] < 0xf8 || bytes[mark] > 0xfb) continue;
|
||||
if (mark + (1 + size + 2) * stride <= end)
|
||||
return {mark, size, stride, id.mfm};
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void validate(const DiskGeometry& g) {
|
||||
if (!g.tracks || g.tracks > 256 || !g.sides || g.sides > 2 ||
|
||||
!g.sectors || g.sectors > 64 || g.sizeCode > 3 ||
|
||||
g.firstSector > 255 || g.firstSector + g.sectors > 256)
|
||||
throw std::invalid_argument("Unsupported DSK geometry");
|
||||
}
|
||||
}
|
||||
DiskImage DiskImage::load(const std::vector<std::uint8_t>& bytes, bool writeProtected) {
|
||||
if (bytes.size() < 256 || bytes.size() > maxBytes)
|
||||
throw std::invalid_argument("DSK image is empty, too short, or too large");
|
||||
DiskImage image;
|
||||
image.header = bytes.size() % 256;
|
||||
const auto declaredHeader = littleWord(bytes, 2);
|
||||
// A headerless DSK can begin with arbitrary sector data, including 'dk'.
|
||||
// Use the header's dimensions to disambiguate whole-track raw images.
|
||||
const bool validRawSize = bytes.size() % (18 * 256) == 0;
|
||||
const bool vdkDimensions = declaredHeader >= 12 && bytes[8] != 0 &&
|
||||
(bytes[9] == 1 || bytes[9] == 2) &&
|
||||
bytes.size() == declaredHeader + std::size_t(bytes[8]) * bytes[9] * 18 * 256;
|
||||
const bool signedVDK = bytes[0] == 'd' && bytes[1] == 'k' &&
|
||||
(!validRawSize || vdkDimensions);
|
||||
// CreateDiskHeader in Windows VCC also emits a 12-byte VDK header
|
||||
// containing only the side count. Identify just that known legacy layout.
|
||||
const bool legacyVDK = image.header == 12 && bytes[9] >= 1 && bytes[9] <= 2 &&
|
||||
std::all_of(bytes.begin(), bytes.begin() + 9, [](auto b){ return b == 0; }) &&
|
||||
bytes[10] == 0 && bytes[11] == 0;
|
||||
const auto trackLength = declaredHeader;
|
||||
const unsigned dmkSides = bytes[4] & 0x10 ? 1 : 2;
|
||||
const bool dmkGeometry = bytes[1] && trackLength > 128 && trackLength <= 0x4000 &&
|
||||
bytes.size() == 16 + std::size_t(bytes[1]) * dmkSides * trackLength;
|
||||
const bool dmkHeader = (bytes[0] == 0 || bytes[0] == 0xff) && !(bytes[4] & ~0xd0) &&
|
||||
std::all_of(bytes.begin() + 5, bytes.begin() + 16, [](auto b){ return b == 0; });
|
||||
auto& g = image.geom;
|
||||
if (dmkGeometry && dmkHeader) {
|
||||
image.kind = DiskFormat::DMK;
|
||||
image.header = 16;
|
||||
image.trackLength = trackLength;
|
||||
image.headerProtection = bytes[0] == 0xff;
|
||||
g.tracks = bytes[1];
|
||||
g.sides = dmkSides;
|
||||
} else if (signedVDK || legacyVDK) {
|
||||
image.kind = DiskFormat::VDK;
|
||||
image.header = signedVDK ? declaredHeader : 12;
|
||||
if (image.header < 12 || image.header >= bytes.size() || bytes[5] > 0x10 ||
|
||||
(bytes[11] & 7) || bytes[9] < 1 || bytes[9] > 2)
|
||||
throw std::invalid_argument("Invalid or unsupported VDK header");
|
||||
g.sides = bytes[9];
|
||||
const auto trackSize = g.sides * g.sectors * g.sectorBytes();
|
||||
const auto payload = bytes.size() - image.header;
|
||||
g.tracks = static_cast<unsigned>(payload / trackSize);
|
||||
if (payload % trackSize || (signedVDK && bytes[8] != g.tracks))
|
||||
throw std::invalid_argument("VDK dimensions do not match its complete disk tracks");
|
||||
validate(g);
|
||||
image.headerProtection = bytes[10] & 1;
|
||||
} else {
|
||||
// Upstream infers JVC headers from size modulo 256. Keep that layout,
|
||||
// including one-byte headers, but reject attribute-byte/track containers.
|
||||
if (image.header > 4)
|
||||
throw std::invalid_argument("Unrecognized or invalid floppy image header");
|
||||
if (image.header >= 1) g.sectors = bytes[0];
|
||||
if (image.header >= 2) g.sides = bytes[1];
|
||||
if (image.header >= 3) g.sizeCode = bytes[2];
|
||||
if (image.header >= 4) g.firstSector = bytes[3];
|
||||
if (!image.header) {
|
||||
const unsigned total = (unsigned(bytes[0]) << 16) | (unsigned(bytes[1]) << 8) | bytes[2];
|
||||
const unsigned sides = (bytes[16] & 1) + 1;
|
||||
if (bytes[3] == 18 && total && total % (sides * 18) == 0 &&
|
||||
std::size_t(total) * 256 == bytes.size()) {
|
||||
image.kind = DiskFormat::OS9; g.sides = sides;
|
||||
}
|
||||
}
|
||||
validate(g); // check shifts/divisors before calculating the track count
|
||||
const auto trackSize = std::size_t(g.sides) * g.sectors * g.sectorBytes();
|
||||
const auto payload = bytes.size() - image.header;
|
||||
if (payload % trackSize)
|
||||
throw std::invalid_argument("DSK image must contain complete tracks");
|
||||
g.tracks = unsigned(payload / trackSize);
|
||||
validate(g);
|
||||
}
|
||||
image.data = bytes; image.protectedImage = writeProtected;
|
||||
return image;
|
||||
}
|
||||
DiskImage DiskImage::blank(DiskGeometry g, DiskFormat format) {
|
||||
validate(g);
|
||||
const auto payload = std::size_t(g.tracks) * g.sides * g.sectors * g.sectorBytes();
|
||||
DiskImage image;
|
||||
image.geom = g;
|
||||
image.kind = format;
|
||||
image.changed = true;
|
||||
if (format == DiskFormat::DMK || format == DiskFormat::VDK) {
|
||||
// Both containers have byte-sized track counts. New disks use the
|
||||
// standard CoCo double-density layout that Disk BASIC can format.
|
||||
if (g.tracks > 255 || g.sectors != 18 || g.sizeCode != 1 || g.firstSector != 1)
|
||||
throw std::invalid_argument("New DMK and VDK disks require standard 18-sector geometry");
|
||||
if (format == DiskFormat::DMK) {
|
||||
image.header = 16;
|
||||
image.trackLength = 6400;
|
||||
image.data.assign(image.header + std::size_t(g.tracks) * g.sides * image.trackLength, 0x4e);
|
||||
std::fill_n(image.data.begin(), image.header, 0);
|
||||
image.data[1] = g.tracks;
|
||||
image.data[2] = image.trackLength & 0xff;
|
||||
image.data[3] = image.trackLength >> 8;
|
||||
image.data[4] = g.sides == 1 ? 0x10 : 0;
|
||||
for (auto base = image.header; base < image.data.size(); base += image.trackLength)
|
||||
std::fill_n(image.data.begin() + base, 128, 0); // blank IDAM tables
|
||||
} else {
|
||||
image.header = 12;
|
||||
image.data.assign(image.header + payload, 0xff);
|
||||
const Bytes header{'d', 'k', 12, 0, 0x10, 0x10, 0, 0,
|
||||
std::uint8_t(g.tracks), std::uint8_t(g.sides), 0, 0};
|
||||
std::copy(header.begin(), header.end(), image.data.begin());
|
||||
}
|
||||
return image;
|
||||
}
|
||||
if (format != DiskFormat::JVC) throw std::invalid_argument("Unsupported blank disk format");
|
||||
if (payload % 256) throw std::invalid_argument("JVC payload must be a multiple of 256 bytes");
|
||||
if (payload + 4 > maxBytes) throw std::invalid_argument("DSK geometry exceeds image limit");
|
||||
// Preserve the conventional headerless 18x256 single-sided DSK layout.
|
||||
image.header = (g.sides == 1 && g.sectors == 18 && g.sizeCode == 1 && g.firstSector == 1) ? 0 : 4;
|
||||
image.data.assign(payload + image.header, 0xff);
|
||||
if (image.header) {
|
||||
image.data[0] = g.sectors; image.data[1] = g.sides;
|
||||
image.data[2] = g.sizeCode; image.data[3] = g.firstSector;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
std::size_t DiskImage::offset(unsigned track, unsigned side, unsigned sector) const {
|
||||
if (track >= geom.tracks || side >= geom.sides || sector < geom.firstSector ||
|
||||
sector - geom.firstSector >= geom.sectors) return invalid;
|
||||
return header + ((std::size_t(track) * geom.sides + side) * geom.sectors +
|
||||
sector - geom.firstSector) * geom.sectorBytes();
|
||||
}
|
||||
std::size_t DiskImage::dmkTrack(unsigned track, unsigned side) const {
|
||||
if (kind != DiskFormat::DMK || track >= geom.tracks || side >= geom.sides) return invalid;
|
||||
return header + (std::size_t(track) * geom.sides + side) * trackLength;
|
||||
}
|
||||
|
||||
Bytes DiskImage::readAddress(unsigned track, unsigned side, unsigned ordinal, std::uint8_t* wdStatus) const {
|
||||
if (wdStatus) *wdStatus = 0;
|
||||
if (track >= geom.tracks || side >= geom.sides) return {};
|
||||
if (kind != DiskFormat::DMK)
|
||||
return {std::uint8_t(track), std::uint8_t(side),
|
||||
std::uint8_t(geom.firstSector + ordinal % geom.sectors),
|
||||
std::uint8_t(geom.sizeCode), 0, 0};
|
||||
const auto ids = trackIDs(data, dmkTrack(track, side), trackLength);
|
||||
if (ids.empty()) return {};
|
||||
const auto& id = ids[ordinal % ids.size()];
|
||||
if (wdStatus && !id.crcValid(data)) *wdStatus = 0x08;
|
||||
Bytes address(6);
|
||||
for (unsigned i = 0; i < address.size(); ++i) address[i] = data[id.id + (i + 1) * id.stride];
|
||||
return address;
|
||||
}
|
||||
|
||||
Bytes DiskImage::readTrack(unsigned track, unsigned side) const {
|
||||
const auto base = dmkTrack(track, side);
|
||||
if (base == invalid) return {};
|
||||
return {data.begin() + base + 128, data.begin() + base + trackLength};
|
||||
}
|
||||
|
||||
Bytes DiskImage::readSector(unsigned track, unsigned side, unsigned sector, int cylinder,
|
||||
std::uint8_t* wdStatus) const {
|
||||
if (wdStatus) *wdStatus = 0;
|
||||
if (kind == DiskFormat::DMK) {
|
||||
const auto base = dmkTrack(track, side);
|
||||
if (base == invalid) return {};
|
||||
const auto field = findSector(data, base, trackLength, cylinder < 0 ? track : unsigned(cylinder), sector);
|
||||
if (field.mark == invalid) return {};
|
||||
Bytes result(field.size);
|
||||
for (unsigned i = 0; i < field.size; ++i)
|
||||
result[i] = data[field.mark + (i + 1) * field.stride];
|
||||
if (wdStatus) {
|
||||
if (data[field.mark] != 0xfb) *wdStatus |= 0x20;
|
||||
if (fieldCRC(data, field.mark, field.size + 3, field.stride, field.mfm) != 0) *wdStatus |= 0x08;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (cylinder >= 0 && unsigned(cylinder) != track) return {};
|
||||
const auto at = offset(track, side, sector);
|
||||
if (at == invalid) return {};
|
||||
return {data.begin() + at, data.begin() + at + geom.sectorBytes()};
|
||||
}
|
||||
|
||||
bool DiskImage::writeSector(unsigned track, unsigned side, unsigned sector, const Bytes& bytes,
|
||||
int cylinder, bool deleted) {
|
||||
if (writeProtected()) return false;
|
||||
if (kind == DiskFormat::DMK) {
|
||||
const auto base = dmkTrack(track, side);
|
||||
if (base == invalid) return false;
|
||||
const auto field = findSector(data, base, trackLength, cylinder < 0 ? track : unsigned(cylinder), sector);
|
||||
if (field.mark == invalid || bytes.size() != field.size) return false;
|
||||
auto pos = data.begin() + field.mark;
|
||||
auto put = [&](std::uint8_t byte) { pos = std::fill_n(pos, field.stride, byte); };
|
||||
put(deleted ? 0xf8 : 0xfb);
|
||||
for (auto byte : bytes) put(byte);
|
||||
const auto crc = fieldCRC(data, field.mark, field.size + 1, field.stride, field.mfm);
|
||||
put(crc >> 8);
|
||||
put(crc & 0xff);
|
||||
} else {
|
||||
if (cylinder >= 0 && unsigned(cylinder) != track) return false;
|
||||
const auto at = offset(track, side, sector);
|
||||
if (at == invalid || bytes.size() != geom.sectorBytes()) return false;
|
||||
std::copy(bytes.begin(), bytes.end(), data.begin() + at);
|
||||
}
|
||||
changed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Translate an FD-502 format command into a fresh DMK track. Parse field
|
||||
// boundaries before publishing anything: FE and FB inside sector data are
|
||||
// data, not new ID pointers. F7 generates a two-byte CRC on the medium, so
|
||||
// the device can reach the index hole before consuming the trailing gap.
|
||||
bool DiskImage::formatDMK(std::size_t base, const Bytes& stream) {
|
||||
const bool mfm = !(data[4] & 0x40);
|
||||
Bytes raw(128, 0);
|
||||
raw.reserve(trackLength);
|
||||
unsigned pointerBytes = 0, sectorSize = 0;
|
||||
bool awaitingData = false;
|
||||
auto decode = [mfm](std::uint8_t token) -> std::uint8_t {
|
||||
if (mfm && token == 0xf5) return 0xa1;
|
||||
if (mfm && token == 0xf6) return 0xc2;
|
||||
return token;
|
||||
};
|
||||
std::size_t i = 0;
|
||||
while (i < stream.size() && raw.size() < trackLength) {
|
||||
const auto byte = stream[i++];
|
||||
const bool id = byte == 0xfe;
|
||||
const bool dam = byte >= 0xf8 && byte <= 0xfb && awaitingData;
|
||||
if (!id && !dam) {
|
||||
raw.push_back(decode(byte));
|
||||
continue;
|
||||
}
|
||||
const auto at = raw.size();
|
||||
const unsigned size = id ? 4 : sectorSize;
|
||||
if (at + 1 + size + 2 > trackLength || i + size >= stream.size()) return false;
|
||||
if (id) {
|
||||
if (awaitingData || pointerBytes == 128) return false;
|
||||
const auto pointer = at | (mfm ? 0x8000 : 0);
|
||||
raw[pointerBytes++] = pointer & 0xff;
|
||||
raw[pointerBytes++] = pointer >> 8;
|
||||
}
|
||||
raw.push_back(byte);
|
||||
for (unsigned member = 0; member < size; ++member) raw.push_back(decode(stream[i++]));
|
||||
if (id) sectorSize = 128u << (raw[at + 4] & 3);
|
||||
if (stream[i] == 0xf7) {
|
||||
++i;
|
||||
const auto crc = fieldCRC(raw, at, size + 1, 1, mfm);
|
||||
raw.push_back(crc >> 8);
|
||||
raw.push_back(crc & 0xff);
|
||||
} else {
|
||||
if (i + 2 > stream.size()) return false;
|
||||
raw.push_back(stream[i++]);
|
||||
raw.push_back(stream[i++]);
|
||||
}
|
||||
awaitingData = id;
|
||||
}
|
||||
if (raw.size() != trackLength || !pointerBytes || awaitingData) return false;
|
||||
std::copy(raw.begin(), raw.end(), data.begin() + base);
|
||||
changed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DiskImage::formatTrack(unsigned track, unsigned side, const std::vector<std::uint8_t>& stream) {
|
||||
if (writeProtected() || track >= geom.tracks || side >= geom.sides || stream.size() != writeTrackBytes()) return false;
|
||||
if (kind == DiskFormat::DMK) return formatDMK(dmkTrack(track, side), stream);
|
||||
auto next = *this;
|
||||
bool haveId = false, wrote = false;
|
||||
unsigned sector = 0;
|
||||
for (std::size_t i = 0; i < stream.size();) {
|
||||
const auto byte = stream[i++];
|
||||
if (byte == 0xfe) {
|
||||
if (haveId || stream.size() - i < 5) return false;
|
||||
if (stream[i] != track || stream[i + 1] != side || stream[i + 3] != geom.sizeCode) return false;
|
||||
sector = stream[i + 2];
|
||||
if (offset(track, side, sector) == invalid) return false;
|
||||
i += 5; // cylinder, side, sector, length code, generated-CRC token
|
||||
haveId = true;
|
||||
} else if (byte == 0xfb) {
|
||||
if (!haveId || stream.size() - i < geom.sectorBytes()) return false;
|
||||
const std::vector<std::uint8_t> bytes(stream.begin() + i, stream.begin() + i + geom.sectorBytes());
|
||||
if (!next.writeSector(track, side, sector, bytes)) return false;
|
||||
i += geom.sectorBytes(); haveId = false; wrote = true;
|
||||
}
|
||||
}
|
||||
if (haveId || !wrote) return false;
|
||||
data.swap(next.data); changed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Geometry/sector layout adapted from wd1793.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC::Devices {
|
||||
enum class DiskFormat { JVC, OS9, DMK, VDK };
|
||||
struct DiskGeometry {
|
||||
unsigned tracks = 35, sides = 1, sectors = 18, sizeCode = 1, firstSector = 1;
|
||||
unsigned sectorBytes() const { return 128u << sizeCode; }
|
||||
};
|
||||
// Bounded, owned image bytes. No host I/O occurs during guest execution.
|
||||
// Loading is strict: complete tracks only, with no fabricated short reads.
|
||||
class DiskImage {
|
||||
public:
|
||||
static constexpr std::size_t maxBytes = 16 * 1024 * 1024;
|
||||
static DiskImage load(const std::vector<std::uint8_t>&, bool writeProtected = false);
|
||||
// Creates blank media. Guest DSKINI supplies the filesystem.
|
||||
static DiskImage blank(DiskGeometry = {}, DiskFormat = DiskFormat::JVC);
|
||||
const DiskGeometry& geometry() const { return geom; }
|
||||
DiskFormat format() const { return kind; }
|
||||
std::size_t containerHeaderBytes() const { return header; }
|
||||
bool writeProtected() const { return protectedImage || formatWriteProtected(); }
|
||||
bool formatWriteProtected() const { return headerProtection; }
|
||||
void setWriteProtected(bool value) { protectedImage = value; }
|
||||
bool dirty() const { return changed; }
|
||||
void markSaved() { changed = false; }
|
||||
void markDirty() { changed = true; } // Successful host-editor replacement still needs persistence.
|
||||
const std::vector<std::uint8_t>& bytes() const { return data; }
|
||||
std::vector<std::uint8_t> readSector(unsigned track, unsigned side, unsigned sector,
|
||||
int cylinder = -1, std::uint8_t* wdStatus = nullptr) const;
|
||||
bool writeSector(unsigned track, unsigned side, unsigned sector, const std::vector<std::uint8_t>&,
|
||||
int cylinder = -1, bool deleted = false);
|
||||
std::vector<std::uint8_t> readTrack(unsigned track, unsigned side) const;
|
||||
std::vector<std::uint8_t> readAddress(unsigned track, unsigned side, unsigned ordinal,
|
||||
std::uint8_t* wdStatus = nullptr) const;
|
||||
std::size_t writeTrackBytes() const { return kind == DiskFormat::DMK ? trackLength - 128 : 6272; }
|
||||
// WD1793 write-track token stream, as used by the retained FD-502 controller.
|
||||
// Validates the entire stream before applying any sector updates.
|
||||
bool formatTrack(unsigned track, unsigned side, const std::vector<std::uint8_t>&);
|
||||
private:
|
||||
DiskImage() = default;
|
||||
std::size_t offset(unsigned track, unsigned side, unsigned sector) const;
|
||||
std::size_t dmkTrack(unsigned track, unsigned side) const;
|
||||
bool formatDMK(std::size_t track, const std::vector<std::uint8_t>& stream);
|
||||
DiskGeometry geom;
|
||||
DiskFormat kind = DiskFormat::JVC;
|
||||
std::size_t header = 0, trackLength = 0;
|
||||
std::vector<std::uint8_t> data;
|
||||
bool protectedImage = false, headerProtection = false, changed = false;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Portable adaptation of FD502/wd1793.cpp, copyright 2015 Joseph Forgione.
|
||||
// Retains port decoding, command families, scanline step/settle timing and
|
||||
// delayed transfer completion. Windows I/O, DLL state and physical drives are
|
||||
// replaced by owned instances and a bounded DiskImage backend. See FLOPPY_CORE.md.
|
||||
#include "Fd502Device.h"
|
||||
#include "../RamDiskDevice.h"
|
||||
#include "../Orchestra90Device.h"
|
||||
#include "../SpeechSoundDevice.h"
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace VCC::Devices {
|
||||
std::unique_ptr<CartridgeDevice> makeDevice(DeviceKind kind, const std::vector<std::uint8_t>& rom) {
|
||||
switch (kind) {
|
||||
case DeviceKind::FD502: return std::make_unique<Fd502Device>(rom);
|
||||
case DeviceKind::RamDisk: return std::make_unique<RamDiskDevice>();
|
||||
case DeviceKind::SpeechSound: return std::make_unique<SpeechSoundDevice>(rom);
|
||||
case DeviceKind::Orchestra90: return std::make_unique<Orchestra90Device>(rom);
|
||||
}
|
||||
throw std::invalid_argument("Unknown built-in cartridge device");
|
||||
}
|
||||
Fd502Device::Fd502Device(const std::vector<std::uint8_t>& rom) {
|
||||
transfer.reserve(6272);
|
||||
setROM(rom);
|
||||
}
|
||||
void Fd502Device::setROM(const std::vector<std::uint8_t>& rom) {
|
||||
if (rom.size() != 8192 && rom.size() != 16384)
|
||||
throw std::invalid_argument("FD-502 needs an 8 or 16 KiB disk ROM");
|
||||
romBytes.fill(0xff); // same padding as the Windows external-ROM loader
|
||||
std::copy(rom.begin(), rom.end(), romBytes.begin());
|
||||
reset();
|
||||
}
|
||||
void Fd502Device::reset() {
|
||||
status = data = track = sector = control = 0; command = idle;
|
||||
selected = -1; side = 0; stepDirection = 1; stepMilliseconds = 6;
|
||||
delay = 0; waiter = indexCounter = 0; lostData = false; ticks = 0;
|
||||
transfer.clear(); cursor = 0; addressOrdinals.fill(0);
|
||||
// Mechanical head position, mounted images, dirty data and turbo preference survive.
|
||||
}
|
||||
std::uint8_t Fd502Device::readMemory(std::uint16_t address) const { return romBytes[address & 0x3fff]; }
|
||||
DiskImage* Fd502Device::selectedImage() { return selected >= 0 && disks[selected] ? &*disks[selected] : nullptr; }
|
||||
const DiskImage* Fd502Device::image(unsigned drive) const {
|
||||
if (drive >= disks.size()) throw std::out_of_range("Floppy drive must be 0 through 3");
|
||||
return disks[drive] ? &*disks[drive] : nullptr;
|
||||
}
|
||||
void Fd502Device::checkMediaChange(unsigned drive, bool discard) const {
|
||||
const auto* disk = image(drive);
|
||||
if (command != idle) throw std::logic_error("Stop the floppy controller before changing media");
|
||||
if (disk && disk->dirty() && !discard) throw std::logic_error("Save or discard the modified disk before replacing it");
|
||||
}
|
||||
void Fd502Device::mount(unsigned drive, DiskImage disk, bool discard) {
|
||||
checkMediaChange(drive, discard); disks[drive] = std::move(disk); addressOrdinals[drive] = 0;
|
||||
}
|
||||
void Fd502Device::eject(unsigned drive, bool discard) { checkMediaChange(drive, discard); disks[drive].reset(); }
|
||||
void Fd502Device::markSaved(unsigned drive) {
|
||||
image(drive); // validate the index even when empty
|
||||
if (disks[drive]) disks[drive]->markSaved();
|
||||
}
|
||||
void Fd502Device::setWriteProtected(unsigned drive, bool enabled) {
|
||||
if (!image(drive)) throw std::logic_error("Insert a disk first");
|
||||
if (command != idle) throw std::logic_error("Wait for the disk operation to finish");
|
||||
disks[drive]->setWriteProtected(enabled);
|
||||
}
|
||||
FloppySnapshot Fd502Device::snapshot() const {
|
||||
return {selected, side, track, sector, selected >= 0 ? heads[selected] : 0,
|
||||
status, motor(), command != idle, ticks};
|
||||
}
|
||||
void Fd502Device::done(DeviceHost& host, std::uint8_t result) {
|
||||
command = idle; status = result; transfer.clear(); cursor = 0;
|
||||
lostData = false; waiter = 0;
|
||||
if (control & 0x20) host.cartridgeNmi();
|
||||
}
|
||||
std::uint8_t Fd502Device::readPort(std::uint8_t port, DeviceHost& host) {
|
||||
switch (port) {
|
||||
case 0x41: case 0x42: return host.readBeckerPort(port);
|
||||
case 0x48: return status;
|
||||
case 0x49: return track;
|
||||
case 0x4a: return sector;
|
||||
case 0x4b:
|
||||
if (command == 8 || command == 9 || command == 12 || command == 14) return readData(host);
|
||||
return data;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
void Fd502Device::writePort(std::uint8_t port, std::uint8_t value, DeviceHost& host) {
|
||||
switch (port) {
|
||||
case 0x40: {
|
||||
int next = -1;
|
||||
if (value & 1) next = 0;
|
||||
if (value & 2) next = 1;
|
||||
if (value & 4) next = 2;
|
||||
unsigned nextSide = (value & 0x40) ? 1 : 0;
|
||||
if (next < 0 && nextSide) { next = 3; nextSide = 0; }
|
||||
// Never write a buffered sector into a newly selected drive or side.
|
||||
if (command != idle && (selected != next || side != nextSide)) done(host, recordNotFound);
|
||||
selected = next; side = nextSide; control = value;
|
||||
break;
|
||||
}
|
||||
case 0x42: host.writeBeckerPort(port, value); break;
|
||||
case 0x48: dispatch(value, host); break;
|
||||
case 0x49: if (command == idle) track = value; break;
|
||||
case 0x4a: if (command == idle) sector = value; break;
|
||||
case 0x4b:
|
||||
if (command == 10 || command == 11 || command == 15) writeData(value, host);
|
||||
else if (command == idle) data = value;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
void Fd502Device::dispatch(std::uint8_t value, DeviceHost& host) {
|
||||
const auto next = value >> 4;
|
||||
if (command != idle && next != 13) return;
|
||||
if (next == 13) {
|
||||
// Force interrupt is unconditional when any of its low four bits is set,
|
||||
// matching the upstream controller's simplified interrupt conditions.
|
||||
command = idle; status = 0; cursor = 0; transfer.clear(); lostData = false;
|
||||
if (value & 15) host.cartridgeNmi();
|
||||
return;
|
||||
}
|
||||
command = next; status = busy; lostData = false;
|
||||
sectorStatus = 0; deletedWrite = (value & 1) != 0;
|
||||
transfer.clear(); cursor = 0; waiter = 0;
|
||||
if (next <= 7) {
|
||||
static constexpr unsigned stepTimes[] = {6, 12, 20, 30};
|
||||
stepMilliseconds = stepTimes[value & 3];
|
||||
delay = turbo ? 1 : 10 + 15 * stepMilliseconds;
|
||||
if (next == 1) {
|
||||
stepDirection = selected >= 0 && heads[selected] > data ? -1 : 1;
|
||||
track = data;
|
||||
}
|
||||
} else {
|
||||
delay = (next == 10 || next == 11 || next == 15) ? 5 : 1;
|
||||
if (next == 8 || next == 9 || next == 12 || next == 14) status |= drq;
|
||||
// Fail unmounted/protected writes before accepting any guest payload.
|
||||
if (!selectedImage()) done(host, recordNotFound);
|
||||
else if ((next == 10 || next == 11 || next == 15) && selectedImage()->writeProtected())
|
||||
done(host, writeProtect | recordNotFound);
|
||||
}
|
||||
}
|
||||
bool Fd502Device::prepare(DeviceHost& host) {
|
||||
if (!transfer.empty()) return true;
|
||||
auto* disk = selectedImage();
|
||||
if (!disk || side >= disk->geometry().sides || heads[selected] >= disk->geometry().tracks ||
|
||||
(disk->format() != DiskFormat::DMK && heads[selected] != track)) {
|
||||
done(host, recordNotFound); return false;
|
||||
}
|
||||
const unsigned head = heads[selected];
|
||||
if (command == 12) {
|
||||
const unsigned ordinal = disk->format() == DiskFormat::DMK ? addressOrdinals[selected]++ : indexCounter / 176;
|
||||
transfer = disk->readAddress(head, side, ordinal, §orStatus);
|
||||
} else if (command == 14) {
|
||||
transfer = disk->readTrack(head, side); // only track containers carry a raw revolution
|
||||
} else if (command == 15) {
|
||||
transfer.assign(disk->writeTrackBytes(), 0);
|
||||
} else {
|
||||
const bool writing = command == 10 || command == 11;
|
||||
sectorStatus = 0;
|
||||
transfer = disk->readSector(head, side, sector, track, writing ? nullptr : §orStatus);
|
||||
if (writing) std::fill(transfer.begin(), transfer.end(), 0);
|
||||
}
|
||||
if (transfer.empty()) { done(host, recordNotFound); return false; }
|
||||
return true;
|
||||
}
|
||||
bool Fd502Device::finishTransfer(DeviceHost& host) {
|
||||
const auto previous = command;
|
||||
if (previous == 10 || previous == 11 || previous == 15) {
|
||||
auto* disk = selectedImage();
|
||||
const bool written = disk && (previous == 15 ? disk->formatTrack(heads[selected], side, transfer) :
|
||||
disk->writeSector(heads[selected], side, sector, transfer, track, deletedWrite));
|
||||
if (!written) { done(host, recordNotFound); return false; }
|
||||
}
|
||||
if (previous == 8 || previous == 9 || previous == 10 || previous == 11) ++sector;
|
||||
const bool multiSector = previous == 9 || previous == 11;
|
||||
if (lostData) sectorStatus |= lost;
|
||||
if (multiSector && !(sectorStatus & (lost | crcError)) && sector != 0) {
|
||||
transfer.clear(); cursor = 0; waiter = 0;
|
||||
return prepare(host); // multi-sector stops with RNF at end of track
|
||||
}
|
||||
if (multiSector && sector == 0 && !(sectorStatus & (lost | crcError))) sectorStatus |= recordNotFound;
|
||||
done(host, sectorStatus);
|
||||
return false;
|
||||
}
|
||||
std::uint8_t Fd502Device::readData(DeviceHost& host) {
|
||||
if (!motor() || !prepare(host)) return 0;
|
||||
// Retain delayed completion so the guest stores the last byte before NMI.
|
||||
if (cursor == transfer.size() && !finishTransfer(host)) return 0;
|
||||
++reads[selected];
|
||||
const auto result = transfer[cursor++]; status = busy | drq; waiter = 0;
|
||||
return result;
|
||||
}
|
||||
void Fd502Device::writeData(std::uint8_t value, DeviceHost& host) {
|
||||
if (!motor() || !prepare(host)) return;
|
||||
if (cursor == transfer.size() && !finishTransfer(host)) return;
|
||||
++writes[selected];
|
||||
transfer[cursor++] = value; status = busy | drq; waiter = 0;
|
||||
}
|
||||
void Fd502Device::horizontalSync(DeviceHost& host) {
|
||||
++ticks;
|
||||
if (!motor()) return;
|
||||
// Stable 5 Hz index timing in upstream scanline units; omit rand() wobble
|
||||
// so separate device instances and regression runs are deterministic.
|
||||
indexCounter = (indexCounter + 1) % 3144;
|
||||
if ((command <= 7 || command == idle) && selectedImage()) {
|
||||
status = (status & ~drq) | (indexCounter > 3114 ? drq : 0);
|
||||
}
|
||||
if (command == idle || --delay > 0) return;
|
||||
delay = 1;
|
||||
if (command <= 7) {
|
||||
if (selected < 0) { done(host, recordNotFound); return; }
|
||||
auto& head = heads[selected];
|
||||
if (command == 0 || command == 1) {
|
||||
const unsigned target = command == 0 ? 0 : data;
|
||||
if (head != target) {
|
||||
head = head < target ? head + 1 : head - 1;
|
||||
delay = turbo ? 1 : 15 * stepMilliseconds;
|
||||
return;
|
||||
}
|
||||
track = target;
|
||||
} else {
|
||||
if (command == 4 || command == 5) stepDirection = 1;
|
||||
if (command == 6 || command == 7) stepDirection = -1;
|
||||
if (stepDirection > 0) head = std::min(head + 1, 255u);
|
||||
else if (head) --head;
|
||||
if (command & 1) track = std::uint8_t(track + stepDirection);
|
||||
}
|
||||
const auto* disk = selectedImage();
|
||||
done(host, (head == 0 ? 4 : 0) | (disk && disk->writeProtected() ? writeProtect : 0));
|
||||
} else {
|
||||
++waiter;
|
||||
if (command == 10 || command == 11 || command == 15) status |= drq;
|
||||
if (waiter <= 5) return;
|
||||
if (!transfer.empty() && cursor == transfer.size()) { finishTransfer(host); return; }
|
||||
lostData = true;
|
||||
if (command == 10 || command == 11 || command == 15) writeData(0, host);
|
||||
else readData(host);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// WD1793 command model adapted from wd1793.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include "DiskImage.h"
|
||||
#include "../CartridgeDevice.h"
|
||||
#include <array>
|
||||
#include <optional>
|
||||
|
||||
namespace VCC::Devices {
|
||||
struct FloppySnapshot {
|
||||
int drive = -1;
|
||||
unsigned side = 0, track = 0, sector = 0, head = 0;
|
||||
std::uint8_t status = 0;
|
||||
bool motor = false, busy = false;
|
||||
std::uint64_t ticks = 0;
|
||||
};
|
||||
class Fd502Device final : public CartridgeDevice {
|
||||
public:
|
||||
explicit Fd502Device(const std::vector<std::uint8_t>& rom);
|
||||
void setROM(const std::vector<std::uint8_t>& rom); // validate before changing; retains drives
|
||||
void reset() override;
|
||||
void horizontalSync(DeviceHost&) override;
|
||||
std::uint8_t readMemory(std::uint16_t) const override;
|
||||
std::uint8_t readPort(std::uint8_t, DeviceHost&) override;
|
||||
void writePort(std::uint8_t, std::uint8_t, DeviceHost&) override;
|
||||
// Mount receives an already validated image. Invalid input cannot replace media.
|
||||
// Busy controllers reject media changes; dirty images require explicit discard.
|
||||
void mount(unsigned drive, DiskImage image, bool discard = false);
|
||||
void eject(unsigned drive, bool discard = false);
|
||||
const DiskImage* image(unsigned drive) const;
|
||||
void markSaved(unsigned drive);
|
||||
void setWriteProtected(unsigned drive, bool enabled);
|
||||
void setTurbo(bool enabled) { turbo = enabled; }
|
||||
FloppySnapshot snapshot() const;
|
||||
std::uint64_t readEvents(unsigned drive) const { return reads.at(drive); }
|
||||
std::uint64_t writeEvents(unsigned drive) const { return writes.at(drive); }
|
||||
private:
|
||||
static constexpr std::uint8_t idle = 255, busy = 1, drq = 2, lost = 4,
|
||||
crcError = 8, recordNotFound = 0x10, writeProtect = 0x40;
|
||||
std::array<std::uint8_t, 16384> romBytes;
|
||||
std::array<std::optional<DiskImage>, 4> disks;
|
||||
std::array<unsigned, 4> heads{}, addressOrdinals{};
|
||||
// Guest data transfers, independent of motor, dirty state and host saves.
|
||||
std::array<std::uint64_t, 4> reads{}, writes{};
|
||||
std::vector<std::uint8_t> transfer;
|
||||
std::size_t cursor = 0;
|
||||
std::uint8_t status = 0, data = 0, track = 0, sector = 0, command = idle, control = 0;
|
||||
int selected = -1, stepDirection = 1, delay = 0;
|
||||
unsigned side = 0, stepMilliseconds = 6, waiter = 0, indexCounter = 0;
|
||||
std::uint8_t sectorStatus = 0; // CRC and deleted-data mark from the current read
|
||||
bool deletedWrite = false, lostData = false, turbo = false;
|
||||
std::uint64_t ticks = 0;
|
||||
DiskImage* selectedImage();
|
||||
bool motor() const { return control & 8; }
|
||||
void dispatch(std::uint8_t, DeviceHost&);
|
||||
void done(DeviceHost&, std::uint8_t result);
|
||||
bool prepare(DeviceHost&);
|
||||
bool finishTransfer(DeviceHost&);
|
||||
std::uint8_t readData(DeviceHost&);
|
||||
void writeData(std::uint8_t, DeviceHost&);
|
||||
void checkMediaChange(unsigned, bool) const;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Portable CC3 VHD protocol adapted from cc3vhd.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include "../CartridgeDevice.h"
|
||||
#include "VirtualClock.h"
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
namespace VCC::Devices {
|
||||
class HardDiskImage {
|
||||
public:
|
||||
static constexpr std::size_t sectorSize = 256, maxBytes = 512u * 1024 * 1024;
|
||||
struct Record { std::uint32_t sector; std::uint64_t revision; std::array<std::uint8_t,256> bytes; };
|
||||
struct Save { std::size_t length; bool initial; std::vector<Record> records; };
|
||||
explicit HardDiskImage(std::vector<std::uint8_t> data, bool protectedImage = false, bool unsaved = false)
|
||||
: data(std::move(data)), protectedImage(protectedImage), initial(unsaved) {
|
||||
if (this->data.empty() || this->data.size() > maxBytes || this->data.size() % sectorSize)
|
||||
throw std::invalid_argument("Hard disks must contain whole 256-byte sectors, from 256 bytes to 512 MiB");
|
||||
}
|
||||
static HardDiskImage blank(std::size_t size) {
|
||||
if (!size || size > maxBytes || size % sectorSize) throw std::invalid_argument("Invalid hard disk size");
|
||||
return HardDiskImage(std::vector<std::uint8_t>(size), false, true);
|
||||
}
|
||||
std::array<std::uint8_t,256> read(std::uint32_t sector) const {
|
||||
if (sector >= maxBytes / sectorSize) throw std::out_of_range("Hard disk sector exceeds 512 MiB");
|
||||
std::array<std::uint8_t,256> result{};
|
||||
const std::size_t offset = std::size_t(sector) * sectorSize;
|
||||
if (offset < data.size()) std::copy_n(data.begin() + offset, sectorSize, result.begin());
|
||||
return result; // The Windows interface permits zero-filled reads past EOF.
|
||||
}
|
||||
bool write(std::uint32_t sector, const std::array<std::uint8_t,256>& bytes) {
|
||||
if (protectedImage || sector >= maxBytes / sectorSize) return false;
|
||||
const std::size_t offset = std::size_t(sector) * sectorSize;
|
||||
const bool grows = offset + sectorSize > data.size();
|
||||
if (grows) data.resize(offset + sectorSize);
|
||||
if (!grows && std::equal(bytes.begin(), bytes.end(), data.begin() + offset)) return true;
|
||||
std::copy(bytes.begin(), bytes.end(), data.begin() + offset);
|
||||
dirtySectors[sector] = ++revision; return true;
|
||||
}
|
||||
Save capture() const {
|
||||
Save result{data.size(), initial, {}};
|
||||
result.records.reserve(dirtySectors.size());
|
||||
for (auto [sector, version] : dirtySectors) result.records.push_back({sector, version, read(sector)});
|
||||
return result;
|
||||
}
|
||||
void acknowledge(const Save& saved) {
|
||||
if (saved.initial) initial = false;
|
||||
for (const auto& record : saved.records) {
|
||||
auto it = dirtySectors.find(record.sector);
|
||||
if (it != dirtySectors.end() && it->second == record.revision) dirtySectors.erase(it);
|
||||
}
|
||||
}
|
||||
bool dirty() const { return initial || !dirtySectors.empty(); }
|
||||
bool writeProtected() const { return protectedImage; }
|
||||
void protect(bool enabled) { protectedImage = enabled; }
|
||||
const std::vector<std::uint8_t>& bytes() const { return data; }
|
||||
private:
|
||||
std::vector<std::uint8_t> data;
|
||||
std::map<std::uint32_t, std::uint64_t> dirtySectors;
|
||||
std::uint64_t revision = 0;
|
||||
bool protectedImage, initial;
|
||||
};
|
||||
|
||||
class HardDiskDevice final : public CartridgeDevice {
|
||||
public:
|
||||
void reset() override { drive = 0; sector = 0; address = 0; status = 0xff; clock.reset(); }
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
std::uint8_t readMemory(std::uint16_t) const override { return 0xff; }
|
||||
std::uint8_t readPort(std::uint8_t port, DeviceHost&) override {
|
||||
if (clockEnabled && (port == 0x78 || port == 0x79 || port == 0x7c)) return clock.read(port);
|
||||
switch (port) {
|
||||
case 0x80: return sector >> 16; case 0x81: return sector >> 8; case 0x82: return sector;
|
||||
case 0x83: return status; case 0x84: return address >> 8; case 0x85: return address; case 0x86: return drive;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost& host) override {
|
||||
if (executing) return; // DMA into I/O must not recursively execute a command.
|
||||
switch (port) {
|
||||
case 0x80: sector = (sector & 0x00ffff) | (std::uint32_t(value) << 16); break;
|
||||
case 0x81: sector = (sector & 0xff00ff) | (std::uint32_t(value) << 8); break;
|
||||
case 0x82: sector = (sector & 0xffff00) | value; break;
|
||||
case 0x83: command(value, host); break;
|
||||
case 0x84: address = (address & 255) | (std::uint16_t(value) << 8); break;
|
||||
case 0x85: address = (address & 0xff00) | value; break;
|
||||
case 0x86: if (value < 2) drive = value; break;
|
||||
}
|
||||
}
|
||||
void mount(unsigned index, HardDiskImage next) { checkChange(index); images[index] = std::move(next); status = 0; sector = address = 0; }
|
||||
void eject(unsigned index, bool discard = false) { checkChange(index, discard); images[index].reset(); status = 4; }
|
||||
HardDiskImage* image(unsigned index) { return images.at(index) ? &*images[index] : nullptr; }
|
||||
void configureClock(bool enabled, bool readOnly) { clockEnabled = enabled; clock.setReadOnly(readOnly); }
|
||||
unsigned selectedDrive() const { return drive; }
|
||||
std::uint32_t selectedSector() const { return sector; }
|
||||
std::uint8_t result() const { return status; }
|
||||
bool isClockEnabled() const { return clockEnabled; }
|
||||
bool isClockReadOnly() const { return clock.readOnly(); }
|
||||
std::uint64_t readEvents(unsigned index) const { return reads.at(index); }
|
||||
std::uint64_t writeEvents(unsigned index) const { return writes.at(index); }
|
||||
std::uint64_t flushRequests() const { return flushes; }
|
||||
private:
|
||||
void checkChange(unsigned index, bool discard = false) {
|
||||
if (index > 1) throw std::invalid_argument("Hard disk drive must be 0 or 1");
|
||||
if (images[index] && images[index]->dirty() && !discard) throw std::logic_error("Save or discard the hard disk before replacing it");
|
||||
}
|
||||
void command(std::uint8_t value, DeviceHost& host) {
|
||||
auto* disk = image(drive);
|
||||
if (!disk) { status = 4; return; }
|
||||
if (value > 2) { status = 0xfe; return; }
|
||||
if (value == 2) { sector = address = 0; ++flushes; status = 0; return; }
|
||||
if (sector >= HardDiskImage::maxBytes / 256) { status = 4; return; }
|
||||
if (value == 1 && disk->writeProtected()) { status = 5; return; }
|
||||
struct Guard { bool& flag; Guard(bool& f):flag(f) { flag = true; } ~Guard() { flag = false; } } guard(executing);
|
||||
const auto dma = address;
|
||||
if (value == 0) {
|
||||
const auto bytes = disk->read(sector);
|
||||
++reads[drive];
|
||||
for (unsigned i = 0; i < 256; ++i) host.cartridgeWriteMemory(std::uint16_t(dma + i), bytes[i]);
|
||||
} else {
|
||||
std::array<std::uint8_t,256> bytes;
|
||||
for (unsigned i = 0; i < 256; ++i) bytes[i] = host.cartridgeReadMemory(std::uint16_t(dma + i));
|
||||
if (disk->write(sector, bytes)) ++writes[drive];
|
||||
}
|
||||
status = 0;
|
||||
}
|
||||
std::array<std::optional<HardDiskImage>,2> images;
|
||||
std::uint32_t sector = 0;
|
||||
std::uint16_t address = 0;
|
||||
std::uint8_t drive = 0, status = 0xff;
|
||||
bool executing = false, clockEnabled = true;
|
||||
std::uint64_t flushes = 0;
|
||||
std::array<std::uint64_t, 2> reads{}, writes{};
|
||||
VirtualClock clock;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// DS1315 serial protocol adapted from libcommon/vcc/devices/cloud9.cpp,
|
||||
// copyright 2015 Joseph Forgione. Guest writes affect only this virtual clock.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
namespace VCC::Devices {
|
||||
class VirtualClock {
|
||||
public:
|
||||
explicit VirtualClock(std::function<std::time_t()> now = [] { return std::time(nullptr); }) : now(std::move(now)) {}
|
||||
void reset() { input = output = 0; active = false; count = 0; }
|
||||
void setReadOnly(bool value) { locked = value; }
|
||||
bool readOnly() const { return locked; }
|
||||
std::uint8_t read(std::uint8_t port) {
|
||||
if (port == 0x7c) {
|
||||
if (!active) return 0;
|
||||
auto bit = output & 1; output >>= 1;
|
||||
if (++count == 64) { active = false; count = 0; input = 0; }
|
||||
return bit;
|
||||
}
|
||||
if (port != 0x78 && port != 0x79) return 0;
|
||||
input = (input >> 1) | (std::uint64_t(port & 1) << 63);
|
||||
if (active) {
|
||||
if (++count == 64) { if (!locked) setVirtualTime(input); active = false; count = 0; input = 0; }
|
||||
} else if (input == 0x5ca33ac55ca33ac5ULL) { output = timePacket(); active = true; count = 0; input = 0; }
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
static unsigned bcd(unsigned value) { return ((value / 10) << 4) | (value % 10); }
|
||||
static unsigned decimal(unsigned value) { return (value >> 4) * 10 + (value & 15); }
|
||||
std::uint64_t timePacket() {
|
||||
auto time = now() + offset; std::tm fields{};
|
||||
#ifdef _WIN32
|
||||
localtime_s(&fields, &time);
|
||||
#else
|
||||
localtime_r(&time, &fields);
|
||||
#endif
|
||||
// VCC/NitrOS-9 uses years since 1900; 2026 is encoded as $C6.
|
||||
return (std::uint64_t(bcd(fields.tm_year) & 255) << 56) |
|
||||
(std::uint64_t(bcd(fields.tm_mon + 1)) << 48) | (std::uint64_t(bcd(fields.tm_mday)) << 40) |
|
||||
(std::uint64_t(fields.tm_wday) << 32) | (std::uint64_t(bcd(fields.tm_hour)) << 24) |
|
||||
(std::uint64_t(bcd(fields.tm_min)) << 16) | (std::uint64_t(bcd(fields.tm_sec)) << 8);
|
||||
}
|
||||
void setVirtualTime(std::uint64_t packet) {
|
||||
std::tm fields{};
|
||||
fields.tm_sec = decimal((packet >> 8) & 255); fields.tm_min = decimal((packet >> 16) & 255);
|
||||
auto hour = unsigned((packet >> 24) & 255);
|
||||
fields.tm_hour = (hour & 0x80) ? decimal(hour & 0x1f) % 12 + ((hour & 0x20) ? 12 : 0) : decimal(hour & 0x3f);
|
||||
fields.tm_mday = decimal((packet >> 40) & 255); fields.tm_mon = decimal((packet >> 48) & 255) - 1;
|
||||
fields.tm_year = decimal((packet >> 56) & 255); fields.tm_isdst = -1;
|
||||
if (fields.tm_sec > 59 || fields.tm_min > 59 || fields.tm_hour > 23 || fields.tm_mday < 1 || fields.tm_mday > 31 || fields.tm_mon < 0 || fields.tm_mon > 11) return;
|
||||
auto time = std::mktime(&fields);
|
||||
if (time != std::time_t(-1)) offset = time - now();
|
||||
}
|
||||
std::function<std::time_t()> now;
|
||||
std::time_t offset = 0;
|
||||
std::uint64_t input = 0, output = 0;
|
||||
unsigned count = 0;
|
||||
bool active = false, locked = true;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Adapted from orch90/orch90.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include "CartridgeDevice.h"
|
||||
|
||||
namespace VCC::Devices {
|
||||
class Orchestra90Device final : public CartridgeDevice {
|
||||
public:
|
||||
explicit Orchestra90Device(std::vector<std::uint8_t> bytes = {}) : rom(std::move(bytes)) {
|
||||
if (!rom.empty() && rom.size() != 8192)
|
||||
throw std::invalid_argument("Orchestra-90 requires an 8 KiB ROM, or no ROM for sound-only use");
|
||||
}
|
||||
// The Windows PakReset reloads ROM/asserts CART, but leaves both DACs alone.
|
||||
// Our owned ROM is immutable; resetting never reopens a host file.
|
||||
void reset() override {}
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
bool cartLine() const override { return !rom.empty(); }
|
||||
std::uint8_t readMemory(std::uint16_t address) const override {
|
||||
return rom.empty() ? 0xff : rom[address & 8191];
|
||||
}
|
||||
std::uint8_t readPort(std::uint8_t, DeviceHost&) override { return 0; }
|
||||
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost&) override {
|
||||
// Tandy schematic, appendix E: decoder Y0 drives IC5/left JK1;
|
||||
// Y1 drives IC4/right JK2. The legacy Windows DLL swapped these.
|
||||
if (port == 0x7a) left = value;
|
||||
if (port == 0x7b) right = value;
|
||||
}
|
||||
bool hasExternalAudioOutput() const override { return true; }
|
||||
std::uint16_t audio() const override { return (std::uint16_t(left) << 8) | right; }
|
||||
bool hasROM(const std::vector<std::uint8_t>& bytes) const { return rom == bytes; }
|
||||
private:
|
||||
std::vector<std::uint8_t> rom;
|
||||
std::uint8_t left = 0, right = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Register behavior from Ramdisk/Ramdisk.cpp, copyright 2015 Joseph Forgione.
|
||||
#pragma once
|
||||
#include "CartridgeDevice.h"
|
||||
#include "Ramdisk/memboard.h"
|
||||
|
||||
namespace VCC::Devices {
|
||||
class RamDiskDevice final : public CartridgeDevice {
|
||||
public:
|
||||
// The Windows device exports no PakReset: reset preserves RAM and latches.
|
||||
void reset() override {}
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
// Missing PakReadMemoryByte uses zero in the Windows cartridge loader.
|
||||
std::uint8_t readMemory(std::uint16_t) const override { return 0; }
|
||||
std::uint8_t readPort(std::uint8_t port, DeviceHost&) override {
|
||||
return port == 0x43 ? memory.read() : 0;
|
||||
}
|
||||
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost&) override {
|
||||
if (port == 0x43) memory.write(value);
|
||||
else memory.addressPort(port, value);
|
||||
}
|
||||
private:
|
||||
RamDiskMemory memory;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include "memboard.h"
|
||||
|
||||
// Legacy Windows DLL entry points share the same memory implementation as the
|
||||
// native cartridge. Reinitialization starts a fresh, zero-filled board.
|
||||
static std::unique_ptr<VCC::Devices::RamDiskMemory> board;
|
||||
bool InitMemBoard()
|
||||
{
|
||||
try { board = std::make_unique<VCC::Devices::RamDiskMemory>(); }
|
||||
catch (const std::bad_alloc&) { return true; }
|
||||
return false;
|
||||
}
|
||||
bool WritePort(unsigned char port, unsigned char data)
|
||||
{
|
||||
if (board) board->addressPort(port, data);
|
||||
return false;
|
||||
}
|
||||
bool WriteArray(unsigned char data)
|
||||
{
|
||||
if (board) board->write(data);
|
||||
return false;
|
||||
}
|
||||
unsigned char ReadArray()
|
||||
{
|
||||
return board ? board->read() : 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef __MEMBOARD_H__
|
||||
#define __MEMBOARD_H__
|
||||
/*
|
||||
Copyright 2015 by Joseph Forgione
|
||||
This file is part of VCC (Virtual Color Computer).
|
||||
|
||||
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define RAMSIZE 1024*512
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace VCC { namespace Devices {
|
||||
// Per-device ownership of the original 19-bit address latch and 512 KB RAM.
|
||||
// Explicit shifts preserve the register order without host-endian unions.
|
||||
class RamDiskMemory {
|
||||
public:
|
||||
RamDiskMemory() : bytes(RAMSIZE, 0) {}
|
||||
void addressPort(std::uint8_t port, std::uint8_t value) {
|
||||
switch (port) {
|
||||
case 0x40: address = (address & 0x7ff00) | value; break;
|
||||
case 0x41: address = (address & 0x700ff) | (std::uint32_t(value) << 8); break;
|
||||
case 0x42: address = (address & 0x0ffff) | (std::uint32_t(value & 7) << 16); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
void write(std::uint8_t value) { bytes[address] = value; }
|
||||
std::uint8_t read() const { return bytes[address]; }
|
||||
private:
|
||||
std::uint32_t address = 0;
|
||||
std::vector<std::uint8_t> bytes;
|
||||
};
|
||||
} }
|
||||
|
||||
|
||||
bool InitMemBoard();
|
||||
bool WritePort(unsigned char,unsigned char);
|
||||
bool WriteArray(unsigned char);
|
||||
unsigned char ReadArray();
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Mapping retained from libcommon/vcc/bus/rom_cartridge.cpp (Joseph Forgione).
|
||||
#pragma once
|
||||
#include "CartridgeDevice.h"
|
||||
#include <stdexcept>
|
||||
namespace VCC::Devices {
|
||||
class RomCartridge final : public CartridgeDevice {
|
||||
public:
|
||||
explicit RomCartridge(std::vector<std::uint8_t> bytes) : bytes(std::move(bytes)) {
|
||||
if (this->bytes.empty() || this->bytes.size() > 262144)
|
||||
throw std::invalid_argument("Choose a nonempty raw cartridge ROM no larger than 256 KiB");
|
||||
}
|
||||
void reset() override { bank = 0; }
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
bool cartLine() const override { return true; }
|
||||
std::uint8_t readMemory(std::uint16_t address) const override {
|
||||
return bytes[((address & 32767) + bank) % bytes.size()];
|
||||
}
|
||||
std::uint8_t readPort(std::uint8_t, DeviceHost&) override { return 0; }
|
||||
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost&) override {
|
||||
if (port == 0x40) bank = (value & 15) << 14;
|
||||
}
|
||||
private:
|
||||
std::vector<std::uint8_t> bytes;
|
||||
std::size_t bank = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,745 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Protocol derived from VCC's SDC simulator, E. J. Jaquay (2025), and the
|
||||
// CoCo SDC User Guide, Darren Atkinson. Host storage is a native POSIX adapter.
|
||||
#include "SDCDevice.h"
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace VCC::Devices {
|
||||
namespace {
|
||||
constexpr std::uint8_t busyReady = 3, invalid = 0x84, ioError = 0x88,
|
||||
notFound = 0x90, inUse = 0xa0, protectedError = 0xc0;
|
||||
constexpr std::uint64_t maximumBytes = 512ull * 1024 * 1024;
|
||||
struct Failure : std::runtime_error {
|
||||
std::uint8_t status;
|
||||
Failure(std::uint8_t status, const std::string& what) : runtime_error(what), status(status) {}
|
||||
};
|
||||
struct FD {
|
||||
int value = -1;
|
||||
FD() = default;
|
||||
explicit FD(int value) : value(value) {}
|
||||
~FD() { if (value >= 0) close(value); }
|
||||
FD(FD&& other) noexcept : value(std::exchange(other.value, -1)) {}
|
||||
FD& operator=(FD&& other) noexcept { if (value >= 0) close(value); value = std::exchange(other.value, -1); return *this; }
|
||||
FD(const FD&) = delete;
|
||||
explicit operator bool() const { return value >= 0; }
|
||||
};
|
||||
std::string upper(std::string value) {
|
||||
for (auto& c : value) if (c >= 'a' && c <= 'z') c -= 'a' - 'A';
|
||||
return value;
|
||||
}
|
||||
bool shortName(const std::string& name) {
|
||||
auto dot = name.find('.');
|
||||
const auto base = dot == std::string::npos ? name : name.substr(0, dot);
|
||||
const auto ext = dot == std::string::npos ? "" : name.substr(dot + 1);
|
||||
if (base.empty() || base.size() > 8 || ext.size() > 3) return false;
|
||||
for (unsigned char c : base + ext)
|
||||
if (c <= 32 || c >= 127 || std::strchr("\"*+,/:;<=>?[\\]|", c) || c == '.') return false;
|
||||
return true;
|
||||
}
|
||||
std::string fatName(std::string name) {
|
||||
if (name.size() == 11 && name.find('.') == std::string::npos) {
|
||||
auto base = name.substr(0,8), ext = name.substr(8);
|
||||
while (!base.empty() && base.back() == ' ') base.pop_back();
|
||||
while (!ext.empty() && ext.back() == ' ') ext.pop_back();
|
||||
return base + (ext.empty() ? "" : "." + ext);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
bool wildcard(const std::string& p, const std::string& n) {
|
||||
if (p == "*.*") return true;
|
||||
std::size_t i = 0, j = 0, star = std::string::npos, back = 0;
|
||||
while (j < n.size()) {
|
||||
if (i < p.size() && (p[i] == '?' || p[i] == n[j])) { ++i; ++j; }
|
||||
else if (i < p.size() && p[i] == '*') { star = i++; back = j; }
|
||||
else if (star != std::string::npos) { i = star + 1; j = ++back; }
|
||||
else return false;
|
||||
}
|
||||
while (i < p.size() && p[i] == '*') ++i;
|
||||
return i == p.size();
|
||||
}
|
||||
unsigned diskNumber(const std::string& name) {
|
||||
auto dot=name.find('.'); auto base=name.substr(0,dot);
|
||||
return !base.empty() && base.back()>='1' && base.back()<='9' ? base.back()-'0' : 0;
|
||||
}
|
||||
std::vector<std::string> names(int fd) {
|
||||
// openat(".") obtains an independent directory offset (dup alone does not).
|
||||
int next = openat(fd, ".", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
||||
if (next < 0) throw Failure(ioError, "The SD card folder could not be read.");
|
||||
DIR* dir = fdopendir(next);
|
||||
if (!dir) { close(next); throw Failure(ioError, "The SD card folder could not be listed."); }
|
||||
std::vector<std::string> result;
|
||||
while (auto ent = readdir(dir)) {
|
||||
std::string n = ent->d_name;
|
||||
if (n != "." && n != "..") result.push_back(n);
|
||||
if (result.size() > 65536) { closedir(dir); throw Failure(ioError, "The SD card folder has too many entries."); }
|
||||
}
|
||||
closedir(dir);
|
||||
std::sort(result.begin(), result.end(), [](const auto& a, const auto& b) { return upper(a) < upper(b); });
|
||||
return result;
|
||||
}
|
||||
std::string actualName(int fd, const std::string& desired, bool mustExist = true) {
|
||||
std::string result;
|
||||
for (const auto& n : names(fd)) if (upper(n) == upper(desired)) {
|
||||
if (!result.empty()) throw Failure(invalid, "Two SD files have the same case-insensitive name.");
|
||||
result = n;
|
||||
}
|
||||
if (!result.empty()) return result;
|
||||
if (mustExist) throw Failure(notFound, "SD file or folder not found: " + desired);
|
||||
return desired;
|
||||
}
|
||||
std::string join(const std::vector<std::string>& parts) {
|
||||
std::string result;
|
||||
for (const auto& p : parts) { if (!result.empty()) result += '/'; result += p; }
|
||||
return result;
|
||||
}
|
||||
}
|
||||
struct SDCDevice::Impl {
|
||||
struct Entry {
|
||||
std::string name, path;
|
||||
bool directory = false, readOnly = true;
|
||||
std::uint32_t size = 0;
|
||||
std::array<std::uint8_t,16> record() const {
|
||||
std::array<std::uint8_t,16> r{};
|
||||
std::fill_n(r.begin(),11,' ');
|
||||
auto dot = name.find('.');
|
||||
std::string base = dot == std::string::npos ? name : name.substr(0,dot);
|
||||
std::string ext = dot == std::string::npos ? "" : name.substr(dot+1);
|
||||
if (name == "..") { base = ".."; ext.clear(); }
|
||||
base = upper(base); ext = upper(ext);
|
||||
std::copy_n(base.begin(),std::min<std::size_t>(8,base.size()),r.begin());
|
||||
std::copy_n(ext.begin(),std::min<std::size_t>(3,ext.size()),r.begin()+8);
|
||||
r[11] = (directory ? 0x10 : 0) | (readOnly ? 1 : 0);
|
||||
for (unsigned i=0;i<4;++i) r[12+i] = size >> (24-i*8);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
struct Disk {
|
||||
FD fd;
|
||||
Entry entry;
|
||||
std::size_t header = 0;
|
||||
unsigned sides = 1, sectors = 18;
|
||||
bool raw = false, writable = false, formatReadOnly = false;
|
||||
struct stat expected{};
|
||||
std::vector<Entry> set;
|
||||
std::size_t setIndex = 0;
|
||||
std::uint64_t reads = 0, writes = 0;
|
||||
};
|
||||
std::vector<std::uint8_t> rom;
|
||||
std::string rootFolder, error;
|
||||
FD root;
|
||||
bool protectedCard;
|
||||
std::vector<std::string> cwd;
|
||||
std::array<Disk,2> disks;
|
||||
bool latched = false, receive = false, byteMode = false, streaming = false;
|
||||
std::uint8_t command = 0, status = 0, bankData = 0, bank = 0;
|
||||
std::array<std::uint8_t,3> params{}, reply{};
|
||||
std::array<std::uint8_t,512> buffer{};
|
||||
unsigned offset = 0, count = 0, half = 0;
|
||||
std::uint32_t streamBlock = 0;
|
||||
std::vector<Entry> directory;
|
||||
std::size_t cursor = 0;
|
||||
bool directoryInitiated = false;
|
||||
std::uint8_t floppyDrive = 0, track = 0, sector = 1, floppyData = 0, floppyStatus = 0;
|
||||
bool floppyWrite = false;
|
||||
unsigned floppyOffset = 0, floppyCount = 0;
|
||||
std::array<std::uint8_t,256> floppyBuffer{};
|
||||
|
||||
Impl(std::vector<std::uint8_t> bytes, std::string folder, bool protect)
|
||||
: rom(std::move(bytes)), rootFolder(std::move(folder)), protectedCard(protect) {
|
||||
if (!rom.empty() && rom.size() != 8192 && rom.size() != 16384)
|
||||
throw std::invalid_argument("SDC-DOS ROM must contain 8 or 16 KiB.");
|
||||
if (!rootFolder.empty()) {
|
||||
std::error_code ec;
|
||||
auto canonical = std::filesystem::canonical(rootFolder,ec);
|
||||
if (ec) throw std::invalid_argument("The SD card folder is unavailable. Choose it again.");
|
||||
rootFolder = canonical.string();
|
||||
root = FD(open(rootFolder.c_str(),O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW));
|
||||
if (!root) throw std::invalid_argument("The SD card folder could not be opened.");
|
||||
}
|
||||
}
|
||||
std::vector<std::string> components(const std::string& input) const {
|
||||
if (!root) throw Failure(notFound,"No SD card folder is selected.");
|
||||
if (input.size() > 255 || input.find('\\') != std::string::npos || input.find(':') != std::string::npos)
|
||||
throw Failure(invalid,"Invalid SD path.");
|
||||
for (unsigned char c : input)
|
||||
if (c < 32 || c >= 127) throw Failure(invalid,"SD paths must use printable ASCII names.");
|
||||
auto out = !input.empty() && input.front() == '/' ? std::vector<std::string>{} : cwd;
|
||||
std::istringstream stream(input);
|
||||
for (std::string part; std::getline(stream,part,'/');) {
|
||||
part = fatName(part);
|
||||
if (part.empty() || part == ".") continue;
|
||||
if (part == "..") {
|
||||
if (out.empty()) throw Failure(invalid,"SD paths cannot leave the selected folder.");
|
||||
out.pop_back();
|
||||
} else out.push_back(part);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
FD openDir(const std::vector<std::string>& parts) const {
|
||||
if (!root) throw Failure(notFound,"No SD card folder is selected.");
|
||||
FD fd(dup(root.value));
|
||||
for (const auto& p : parts) {
|
||||
const auto n = actualName(fd.value,p);
|
||||
FD next(openat(fd.value,n.c_str(),O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC));
|
||||
if (!next) throw Failure(invalid,"SD paths must use real directories inside the selected folder.");
|
||||
fd = std::move(next);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
struct Parent { FD fd; std::string name; std::vector<std::string> parts; };
|
||||
Parent parent(const std::string& path, bool exists = true) const {
|
||||
auto parts = components(path);
|
||||
if (parts.empty()) throw Failure(invalid,"An SD file name is required.");
|
||||
auto name = parts.back(); parts.pop_back();
|
||||
auto fd = openDir(parts);
|
||||
name = actualName(fd.value,name,exists);
|
||||
return {std::move(fd),name,parts};
|
||||
}
|
||||
Entry entry(int fd, const std::string& name, const std::vector<std::string>& parts) const {
|
||||
struct stat s{};
|
||||
if (fstatat(fd,name.c_str(),&s,AT_SYMLINK_NOFOLLOW) || (!S_ISREG(s.st_mode) && !S_ISDIR(s.st_mode)))
|
||||
throw Failure(invalid,"SD files cannot be symbolic links or special devices.");
|
||||
if (s.st_size < 0 || std::uint64_t(s.st_size) > maximumBytes)
|
||||
throw Failure(invalid,"SD images are limited to 512 MiB.");
|
||||
auto full = parts; full.push_back(name);
|
||||
return {name,"/"+join(full),S_ISDIR(s.st_mode),(s.st_mode & 0222) == 0,
|
||||
S_ISDIR(s.st_mode) ? 0u : static_cast<std::uint32_t>(s.st_size)};
|
||||
}
|
||||
std::vector<Entry> list(const std::string& path, bool includeParent) const {
|
||||
auto parts = components(path.empty() ? "*" : path);
|
||||
std::string pattern = "*";
|
||||
if (!parts.empty() && !path.empty() && path.back() != '/') { pattern = parts.back(); parts.pop_back(); }
|
||||
auto fd = openDir(parts);
|
||||
std::vector<Entry> out;
|
||||
if (includeParent && !parts.empty() && (pattern == "*" || pattern == "*.*"))
|
||||
out.push_back({"..","",true,false,0});
|
||||
for (const auto& name : names(fd.value)) {
|
||||
if (!shortName(name) || !wildcard(upper(pattern),upper(name))) continue;
|
||||
try { out.push_back(entry(fd.value,name,parts)); } catch (const Failure&) { continue; }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
bool mountedPath(const std::string& path) const {
|
||||
for (const auto& d : disks) if (d.fd && upper(d.entry.path) == upper(path)) return true;
|
||||
return false;
|
||||
}
|
||||
Disk openDisk(const Entry& e, bool raw) {
|
||||
auto p = parent(e.path);
|
||||
Disk d;
|
||||
d.entry = entry(p.fd.value,p.name,p.parts);
|
||||
if (d.entry.directory) throw Failure(invalid,"An SD disk image is required.");
|
||||
d.raw = raw;
|
||||
if (!protectedCard && !d.entry.readOnly) {
|
||||
d.fd = FD(openat(p.fd.value,p.name.c_str(),O_RDWR | O_NOFOLLOW | O_CLOEXEC));
|
||||
d.writable = bool(d.fd);
|
||||
}
|
||||
if (!d.fd) d.fd = FD(openat(p.fd.value,p.name.c_str(),O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
|
||||
if (!d.fd) throw Failure(ioError,"The SD disk image could not be opened.");
|
||||
struct stat s{};
|
||||
if (fstat(d.fd.value,&s) || !S_ISREG(s.st_mode) || s.st_size < 0 || std::uint64_t(s.st_size) > maximumBytes)
|
||||
throw Failure(invalid,"Invalid SD disk image.");
|
||||
d.entry.size = static_cast<std::uint32_t>(s.st_size);
|
||||
d.expected = s;
|
||||
if (!raw) {
|
||||
std::array<std::uint8_t,12> h{};
|
||||
auto n = pread(d.fd.value,h.data(),h.size(),0);
|
||||
if (n < 12) throw Failure(invalid,"The SD disk image is too short.");
|
||||
if (std::memcmp(h.data(),"SDF1",4) == 0)
|
||||
throw Failure(invalid,"SDF track images are not supported yet. Use a DSK image.");
|
||||
d.header = d.entry.size % 256;
|
||||
if (!d.header) d.sides = (d.entry.size/256 > 720 && d.entry.size/256 <= 2880) ? 2 : 1;
|
||||
else if (d.header <= 4) {
|
||||
d.sectors = h[0];
|
||||
if (d.header >= 2) d.sides = h[1];
|
||||
if (!d.sectors || (d.sides != 1 && d.sides != 2) || (d.header >= 3 && h[2] != 1) || (d.header >= 4 && h[3] != 1))
|
||||
throw Failure(invalid,"This JVC image geometry is unsupported (256-byte sectors are required).");
|
||||
} else if (d.header == 12 && h[0] == 'd' && h[1] == 'k' && h[2] == 12 && h[3] == 0) {
|
||||
d.sides = h[9];
|
||||
if (d.sides != 1 && d.sides != 2) throw Failure(invalid,"Invalid VDK side count.");
|
||||
if (h[10] & 1) { d.writable = false; d.formatReadOnly = true; }
|
||||
} else throw Failure(invalid,"Unsupported SD image header. Use a raw, JVC or VDK disk image.");
|
||||
}
|
||||
return d;
|
||||
}
|
||||
static bool sameRevision(const struct stat& a,const struct stat& b) {
|
||||
#ifdef __APPLE__
|
||||
const auto am=a.st_mtimespec,bm=b.st_mtimespec,ac=a.st_ctimespec,bc=b.st_ctimespec;
|
||||
#else
|
||||
const auto am=a.st_mtim,bm=b.st_mtim,ac=a.st_ctim,bc=b.st_ctim;
|
||||
#endif
|
||||
return a.st_dev==b.st_dev && a.st_ino==b.st_ino && a.st_size==b.st_size &&
|
||||
am.tv_sec==bm.tv_sec && am.tv_nsec==bm.tv_nsec && ac.tv_sec==bc.tv_sec && ac.tv_nsec==bc.tv_nsec;
|
||||
}
|
||||
void verifyRevision(const Disk& d) const {
|
||||
// An atomic save by another app replaces the path but leaves this open
|
||||
// descriptor pointing at an unlinked file. Never report those writes as
|
||||
// saved. Also reject in-place size/content revisions observed since our
|
||||
// mount or last write, instead of silently combining two editors' data.
|
||||
struct stat selected{},heldRoot{},held{},atPath{};
|
||||
if (lstat(rootFolder.c_str(),&selected) || fstat(root.value,&heldRoot) ||
|
||||
!S_ISDIR(selected.st_mode) || selected.st_dev!=heldRoot.st_dev || selected.st_ino!=heldRoot.st_ino)
|
||||
throw Failure(ioError,"The SD card folder moved or was replaced. Select the folder again before saving.");
|
||||
auto p=parent(d.entry.path);
|
||||
if (fstat(d.fd.value,&held) || fstatat(p.fd.value,p.name.c_str(),&atPath,AT_SYMLINK_NOFOLLOW) ||
|
||||
!S_ISREG(atPath.st_mode) || !sameRevision(held,d.expected) || !sameRevision(atPath,d.expected))
|
||||
throw Failure(ioError,"The SD image changed outside VCC. Eject and mount it again before saving.");
|
||||
}
|
||||
void protect(bool value) {
|
||||
if (protectedCard==value) return;
|
||||
if (value) {
|
||||
// Locking must always succeed, even after the source has vanished.
|
||||
protectedCard=true;
|
||||
for (auto& d : disks) if (d.fd) {
|
||||
try {
|
||||
verifyRevision(d);
|
||||
auto p=parent(d.entry.path);
|
||||
FD next(openat(p.fd.value,p.name.c_str(),O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
|
||||
struct stat candidate{};
|
||||
if (next && !fstat(next.value,&candidate) && sameRevision(candidate,d.expected)) d.fd=std::move(next);
|
||||
} catch (const Failure&) { /* keep readable media; the card lock prevents every write */ }
|
||||
d.writable=false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::array<FD,2> next;
|
||||
std::array<bool,2> writable{};
|
||||
// Prepare both replacement descriptors before changing either drive or
|
||||
// the card lock. Protection uses actual O_RDONLY descriptors as well as
|
||||
// command gating; unlocking never reopens a changed/replaced file.
|
||||
for (unsigned i=0;i<2;++i) {
|
||||
auto& d=disks[i]; if (!d.fd) continue;
|
||||
verifyRevision(d);
|
||||
auto p=parent(d.entry.path);
|
||||
if (!value && !d.formatReadOnly && !d.entry.readOnly) {
|
||||
next[i]=FD(openat(p.fd.value,p.name.c_str(),O_RDWR|O_NOFOLLOW|O_CLOEXEC));
|
||||
writable[i]=bool(next[i]);
|
||||
}
|
||||
if (!next[i]) next[i]=FD(openat(p.fd.value,p.name.c_str(),O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
|
||||
struct stat candidate{};
|
||||
if (!next[i] || fstat(next[i].value,&candidate) || !sameRevision(candidate,d.expected))
|
||||
throw Failure(ioError,"The SD image could not be reopened safely. Mount it again.");
|
||||
}
|
||||
for (unsigned i=0;i<2;++i) if (next[i]) {
|
||||
disks[i].fd=std::move(next[i]); disks[i].writable=writable[i];
|
||||
}
|
||||
protectedCard=value;
|
||||
}
|
||||
void checkOtherDrive(unsigned drive,const Disk& candidate) const {
|
||||
const auto& other=disks[1-drive];
|
||||
if (!other.fd) return;
|
||||
struct stat a{},b{};
|
||||
if (fstat(candidate.fd.value,&a) || fstat(other.fd.value,&b))
|
||||
throw Failure(ioError,"The SD image identity could not be checked.");
|
||||
if (a.st_dev==b.st_dev && a.st_ino==b.st_ino)
|
||||
throw Failure(inUse,"This SD image is already mounted in the other drive.");
|
||||
}
|
||||
void mount(unsigned drive, const std::string& path, bool raw = false) {
|
||||
if (drive > 1) throw std::invalid_argument("SDC drive must be 0 or 1.");
|
||||
if (path.empty()) { eject(drive); return; }
|
||||
auto found = list(path,false);
|
||||
if (found.empty() && path.find('.') == std::string::npos) found = list(path+".DSK",false);
|
||||
if (found.empty() && path.find('.') == std::string::npos) found = list(path+"*",false);
|
||||
if (found.size() == 1 && found[0].directory) {
|
||||
found = list(found[0].path+"/*.DSK",false);
|
||||
found.erase(std::remove_if(found.begin(),found.end(),[](const Entry& e){ return !diskNumber(e.name); }),found.end());
|
||||
std::stable_sort(found.begin(),found.end(),[](const Entry& a,const Entry& b){ return diskNumber(a.name)<diskNumber(b.name); });
|
||||
}
|
||||
found.erase(std::remove_if(found.begin(),found.end(),[](const Entry& e){ return e.directory; }),found.end());
|
||||
if (found.empty()) throw Failure(notFound,"No matching SD disk images were found.");
|
||||
if (disks[1-drive].fd && upper(found.front().path) == upper(disks[1-drive].entry.path))
|
||||
throw Failure(inUse,"This SD image is already mounted in the other drive.");
|
||||
auto next = openDisk(found.front(),raw);
|
||||
checkOtherDrive(drive,next);
|
||||
next.set = std::move(found);
|
||||
next.reads = disks[drive].reads; next.writes = disks[drive].writes;
|
||||
disks[drive] = std::move(next);
|
||||
}
|
||||
void eject(unsigned drive) {
|
||||
if (drive > 1) throw std::invalid_argument("SDC drive must be 0 or 1.");
|
||||
auto reads = disks[drive].reads, writes = disks[drive].writes;
|
||||
disks[drive] = Disk{};
|
||||
disks[drive].reads = reads; disks[drive].writes = writes;
|
||||
}
|
||||
void nextDisk(unsigned drive, unsigned position = 0) {
|
||||
if (drive > 1) throw std::invalid_argument("SDC drive must be 0 or 1.");
|
||||
auto& d = disks[drive];
|
||||
if (d.set.empty()) throw Failure(notFound,"There is no mounted disk set.");
|
||||
auto index=d.set.size();
|
||||
unsigned current=diskNumber(d.entry.name), best=10;
|
||||
for (std::size_t i=0;i<d.set.size();++i) {
|
||||
unsigned n=diskNumber(d.set[i].name);
|
||||
if ((position && n==position) || (!position && n>current && n<best)) { index=i; best=n; }
|
||||
}
|
||||
if (index==d.set.size() && !position)
|
||||
for (std::size_t i=0;i<d.set.size();++i) if(diskNumber(d.set[i].name)==1) { index=i; break; }
|
||||
if (index >= d.set.size()) throw Failure(notFound,"Disk number is outside the mounted set (numbered 1 through 9).");
|
||||
if (disks[1-drive].fd && upper(d.set[index].path) == upper(disks[1-drive].entry.path))
|
||||
throw Failure(inUse,"This SD image is already mounted in the other drive.");
|
||||
auto next = openDisk(d.set[index],d.raw);
|
||||
checkOtherDrive(drive,next);
|
||||
next.set = d.set; next.setIndex = index; next.reads = d.reads; next.writes = d.writes;
|
||||
d = std::move(next);
|
||||
}
|
||||
std::uint64_t diskOffset(unsigned drive, std::uint32_t lsn, unsigned size, bool singleSide) const {
|
||||
const auto& d = disks[drive];
|
||||
if (!d.fd) throw Failure(notFound,"No SD image is mounted in drive " + std::to_string(drive) + ".");
|
||||
std::uint64_t adjusted = lsn;
|
||||
if (singleSide && d.sides == 2) adjusted += (lsn/d.sectors)*d.sectors;
|
||||
auto offset = adjusted * size + (size == 512 ? 0 : d.header);
|
||||
if (offset + size > maximumBytes) throw Failure(notFound,"SD sector is outside the supported image range.");
|
||||
return offset;
|
||||
}
|
||||
void readDisk(unsigned drive, std::uint32_t lsn, unsigned size, bool singleSide, std::uint8_t* out) {
|
||||
auto offset = diskOffset(drive,lsn,size,singleSide);
|
||||
auto& d = disks[drive];
|
||||
if (offset + size > d.entry.size) throw Failure(notFound,"SD sector is past the end of the image.");
|
||||
ssize_t result;
|
||||
do { result = pread(d.fd.value,out,size,static_cast<off_t>(offset)); } while (result < 0 && errno == EINTR);
|
||||
if (result != size) throw Failure(ioError,"The SD image could not be read completely.");
|
||||
++d.reads;
|
||||
}
|
||||
void writeDisk(unsigned drive, std::uint32_t lsn, bool singleSide, const std::uint8_t* data) {
|
||||
auto offset = diskOffset(drive,lsn,256,singleSide);
|
||||
auto& d = disks[drive];
|
||||
if (protectedCard || !d.writable) throw Failure(protectedError,"The SD card or disk image is write protected.");
|
||||
verifyRevision(d);
|
||||
// Disk images can grow (raw files start empty). A bounded single pwrite
|
||||
// acknowledges success only after all bytes are accepted by the host.
|
||||
ssize_t result;
|
||||
do { result = pwrite(d.fd.value,data,256,static_cast<off_t>(offset)); } while (result < 0 && errno == EINTR);
|
||||
if (result != 256) throw Failure(ioError,"The SD image could not be saved completely.");
|
||||
if (fstat(d.fd.value,&d.expected)) throw Failure(ioError,"The saved SD image could not be verified.");
|
||||
d.entry.size = static_cast<std::uint32_t>(std::max<std::uint64_t>(d.entry.size,offset+256));
|
||||
++d.writes;
|
||||
}
|
||||
void loadReply(const std::uint8_t* bytes, unsigned length) {
|
||||
if (length > buffer.size()) throw Failure(invalid,"Invalid SD reply length.");
|
||||
std::copy_n(bytes,length,buffer.begin());
|
||||
offset = half = 0; count = length; receive = false; reply = {}; status = 0;
|
||||
}
|
||||
void nextStream() {
|
||||
const auto& d = disks[command&1];
|
||||
if (std::uint64_t(streamBlock)*512 >= d.entry.size) { streaming = false; status = 0; count = 0; return; }
|
||||
// A short final host block is padded, matching SD-card sector granularity.
|
||||
auto offsetInFile = diskOffset(command&1,streamBlock,512,false);
|
||||
auto size = static_cast<unsigned>(std::min<std::uint64_t>(512,d.entry.size-offsetInFile));
|
||||
buffer.fill(0);
|
||||
ssize_t got;
|
||||
do { got = pread(d.fd.value,buffer.data(),size,static_cast<off_t>(offsetInFile)); } while (got < 0 && errno == EINTR);
|
||||
if (got != size) throw Failure(ioError,"SD streaming read failed.");
|
||||
++disks[command&1].reads;
|
||||
offset = half = 0; count = 512; status = 0; ++streamBlock;
|
||||
}
|
||||
void fail(const Failure& f) {
|
||||
status = f.status; error = f.what(); count = offset = half = 0; receive = streaming = false;
|
||||
}
|
||||
void dispatch(std::uint8_t code) {
|
||||
bool wasStreaming = streaming;
|
||||
command = code; status = 0; reply = {}; count = offset = half = 0; error.clear();
|
||||
receive = streaming = false; byteMode = (code&4) != 0;
|
||||
auto lsn = (std::uint32_t(params[0])<<16) | (params[1]<<8) | params[2];
|
||||
switch (code&0xf0) {
|
||||
case 0x80:
|
||||
readDisk(code&1,lsn,256,(code&2)!=0,buffer.data()); count = 256; break;
|
||||
case 0x90:
|
||||
if (!disks[code&1].fd) throw Failure(notFound,"No image mounted for SD streaming.");
|
||||
streaming = true; streamBlock = lsn; nextStream(); break;
|
||||
case 0xa0: case 0xe0:
|
||||
receive = true; count = 256; buffer.fill(0); break;
|
||||
case 0xc0: info(); break;
|
||||
case 0xd0:
|
||||
if (!wasStreaming && params[0]=='#') nextDisk(code&1,params[1]);
|
||||
break;
|
||||
default: throw Failure(invalid,"Unsupported SDC command.");
|
||||
}
|
||||
}
|
||||
void info() {
|
||||
auto& d = disks[command&1]; byteMode = false;
|
||||
switch (params[0]) {
|
||||
case 'I': {
|
||||
if (!d.fd) throw Failure(notFound,"No SD image is mounted.");
|
||||
auto e = d.entry; e.readOnly = protectedCard || !d.writable;
|
||||
std::array<std::uint8_t,256> r{}; auto rec=e.record();
|
||||
std::copy_n(rec.begin(),12,r.begin());
|
||||
for (unsigned i=0;i<4;++i) r[28+i]=e.size>>(8*i);
|
||||
loadReply(r.data(),r.size()); break;
|
||||
}
|
||||
case 'C': {
|
||||
std::array<std::uint8_t,256> r{};
|
||||
// Root is an immediate failed/not-found response, not a READY
|
||||
// block followed by failure. SDC Explorer uses carry from its
|
||||
// command routine to terminate its parent-directory walk; that
|
||||
// routine consumes READY blocks without rechecking final status.
|
||||
if (cwd.empty()) { status=notFound; break; }
|
||||
Entry e; e.name = cwd.back(); e.directory = true;
|
||||
auto rec = e.record(); std::copy(rec.begin(),rec.end(),r.begin());
|
||||
loadReply(r.data(),r.size()); break;
|
||||
}
|
||||
case 'Q': {
|
||||
if (!d.fd) throw Failure(notFound,"No SD image is mounted.");
|
||||
auto sectors = (d.entry.size-d.header)/256;
|
||||
reply = {std::uint8_t(sectors>>16),std::uint8_t(sectors>>8),std::uint8_t(sectors)};
|
||||
status = 0; break;
|
||||
}
|
||||
case '>': {
|
||||
if (!directoryInitiated) throw Failure(notFound,"An SD directory listing has not been initiated.");
|
||||
std::array<std::uint8_t,256> r{};
|
||||
for (unsigned i=0;i<16 && cursor<directory.size();++i,++cursor) {
|
||||
auto rec = directory[cursor].record(); std::copy(rec.begin(),rec.end(),r.begin()+i*16);
|
||||
}
|
||||
loadReply(r.data(),r.size()); break;
|
||||
}
|
||||
case '+': nextDisk(command&1); break;
|
||||
case 'V': reply = {0,0,1}; break; // Match the implemented baseline protocol, not a hardware firmware claim.
|
||||
default: throw Failure(invalid,"Unsupported SDC information command: " + std::to_string(params[0]) + ".");
|
||||
}
|
||||
}
|
||||
std::string blockString(unsigned start) const {
|
||||
auto end = std::find(buffer.begin()+start,buffer.begin()+256,0);
|
||||
if (end == buffer.begin()+256) throw Failure(invalid,"SD command string is not terminated.");
|
||||
return std::string(buffer.begin()+start,end);
|
||||
}
|
||||
void writable() const {
|
||||
if (protectedCard) throw Failure(protectedError,"The SD card is write protected.");
|
||||
}
|
||||
void update() {
|
||||
if (buffer[1] != ':') throw Failure(invalid,"Invalid SDC extended command.");
|
||||
auto path = blockString(2);
|
||||
switch (buffer[0]) {
|
||||
case 'M': case 'm': mount(command&1,path,buffer[0]=='m'); break;
|
||||
case 'D': {
|
||||
if (path == ".." && cwd.empty()) break;
|
||||
auto next = components(path); auto test = openDir(next); cwd = std::move(next); break;
|
||||
}
|
||||
case 'L': directory = list(path,true); cursor = 0; directoryInitiated = true; break;
|
||||
case 'N': case 'n': {
|
||||
if (params[1] != 0) throw Failure(invalid,"SDF creation is not supported. Use ordinary NEW disks.");
|
||||
auto p = parent(path,false);
|
||||
if (!shortName(p.name)) throw Failure(invalid,"New SD files need an 8.3 name.");
|
||||
struct stat existing{};
|
||||
if (!fstatat(p.fd.value,p.name.c_str(),&existing,AT_SYMLINK_NOFOLLOW)) { mount(command&1,path,buffer[0]=='n'); break; }
|
||||
writable();
|
||||
FD fd(openat(p.fd.value,p.name.c_str(),O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC,0600));
|
||||
if (!fd) throw Failure(errno==EEXIST ? inUse : ioError,"The new SD file could not be created (it may already exist).");
|
||||
bool raw = buffer[0]=='n';
|
||||
if (!raw && ftruncate(fd.value,161280)) {
|
||||
unlinkat(p.fd.value,p.name.c_str(),0); throw Failure(ioError,"The new SD disk could not be initialized.");
|
||||
}
|
||||
mount(command&1,path,raw); break;
|
||||
}
|
||||
case 'K': {
|
||||
writable(); auto p = parent(path,false);
|
||||
if (!shortName(p.name)) throw Failure(invalid,"New SD folders need an 8.3 name.");
|
||||
if (mkdirat(p.fd.value,p.name.c_str(),0700)) throw Failure(ioError,"The SD folder could not be created.");
|
||||
break;
|
||||
}
|
||||
case 'X': case 'R': {
|
||||
writable(); auto p = parent(path);
|
||||
auto e = entry(p.fd.value,p.name,p.parts);
|
||||
if (mountedPath(e.path)) throw Failure(inUse,"An SD image must be ejected before renaming or deleting it.");
|
||||
for (const auto& d : disks) if (d.fd && upper(d.entry.path).find(upper(e.path)+"/")==0)
|
||||
throw Failure(inUse,"This folder contains a mounted SD image.");
|
||||
if (e.directory && (upper("/"+join(cwd)) == upper(e.path) || upper("/"+join(cwd)).find(upper(e.path)+"/")==0))
|
||||
throw Failure(inUse,"The current SD folder cannot be renamed or removed.");
|
||||
if (buffer[0]=='X') {
|
||||
if (unlinkat(p.fd.value,p.name.c_str(),e.directory ? AT_REMOVEDIR : 0))
|
||||
throw Failure(errno==ENOTEMPTY ? inUse : ioError,"The SD item could not be removed; folders must be empty.");
|
||||
} else {
|
||||
auto target = blockString(static_cast<unsigned>(3+path.size()));
|
||||
auto q = parent(target,false);
|
||||
if (!shortName(q.name)) throw Failure(invalid,"SD names must use the 8.3 format.");
|
||||
struct stat exists{};
|
||||
if (!fstatat(q.fd.value,q.name.c_str(),&exists,AT_SYMLINK_NOFOLLOW)) throw Failure(inUse,"The destination SD item already exists.");
|
||||
#ifdef __APPLE__
|
||||
if (renameatx_np(p.fd.value,p.name.c_str(),q.fd.value,q.name.c_str(),RENAME_EXCL))
|
||||
#else
|
||||
if (renameat(p.fd.value,p.name.c_str(),q.fd.value,q.name.c_str()))
|
||||
#endif
|
||||
throw Failure(ioError,"The SD item could not be renamed.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: throw Failure(invalid,"Unsupported SDC extended command.");
|
||||
}
|
||||
status = 0;
|
||||
}
|
||||
void receiveByte(std::uint8_t byte) {
|
||||
buffer[offset++] = byte;
|
||||
if (--count) return;
|
||||
receive = false; offset = 0;
|
||||
if ((command&0xf0)==0xa0) {
|
||||
auto lsn = (std::uint32_t(params[0])<<16) | (params[1]<<8) | params[2];
|
||||
writeDisk(command&1,lsn,(command&2)!=0,buffer.data()); status = 0;
|
||||
} else update();
|
||||
}
|
||||
std::uint8_t replyByte(std::uint8_t port) {
|
||||
if (receive || !count) return reply[port-0x49];
|
||||
std::uint8_t value;
|
||||
if (byteMode) {
|
||||
if (port != 0x4b) return reply[1];
|
||||
value = buffer[offset++]; --count;
|
||||
} else {
|
||||
unsigned bit = port == 0x4a ? 1 : 2;
|
||||
value = buffer[offset+(port==0x4b ? 1 : 0)];
|
||||
half |= bit;
|
||||
if (half == 3) { half = 0; offset += 2; count -= 2; }
|
||||
}
|
||||
if (!count && streaming) nextStream();
|
||||
return value;
|
||||
}
|
||||
void reset() {
|
||||
for (unsigned i=0;i<2;++i) eject(i);
|
||||
cwd.clear(); directory.clear(); cursor = 0; directoryInitiated = false;
|
||||
latched = receive = byteMode = streaming = false;
|
||||
command = status = bankData = bank = 0; params = {}; reply = {};
|
||||
offset = count = half = 0; error.clear();
|
||||
floppyDrive = track = floppyData = floppyStatus = 0; sector = 1;
|
||||
floppyWrite = false; floppyOffset = floppyCount = 0;
|
||||
if (!root) return;
|
||||
// User-selected startup configuration is capped; it is data, not host commands.
|
||||
try {
|
||||
auto p = parent("/startup.cfg");
|
||||
FD fd(openat(p.fd.value,p.name.c_str(),O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
|
||||
struct stat s{};
|
||||
if (!fd || fstat(fd.value,&s) || !S_ISREG(s.st_mode) || s.st_size > 16384) throw Failure(invalid,"Invalid SDC startup.cfg.");
|
||||
std::string text(static_cast<std::size_t>(s.st_size),'\0');
|
||||
if (pread(fd.value,text.data(),text.size(),0) != static_cast<ssize_t>(text.size())) throw Failure(ioError,"SDC startup.cfg could not be read.");
|
||||
std::istringstream lines(text);
|
||||
for (std::string line; std::getline(lines,line);) {
|
||||
if (!line.empty() && line.back()=='\r') line.pop_back();
|
||||
if (line.size()<3 || line[1]!='=') continue;
|
||||
try {
|
||||
if (line[0]=='0' || line[0]=='1') mount(line[0]-'0',line.substr(2));
|
||||
else if (line[0]=='D') { auto next = components(line.substr(2)); auto test = openDir(next); cwd = std::move(next); }
|
||||
} catch (const Failure& f) { error = f.what(); }
|
||||
}
|
||||
} catch (const Failure& f) { if (f.status != notFound) error = f.what(); }
|
||||
status = 0;
|
||||
}
|
||||
void floppyCommand(std::uint8_t value, DeviceHost& host) {
|
||||
floppyWrite = false; floppyCount = floppyOffset = 0; floppyStatus = 0;
|
||||
switch(value>>4) {
|
||||
case 0: track=0; host.cartridgeNmi(); break;
|
||||
case 1: track=floppyData; host.cartridgeNmi(); break;
|
||||
case 2: case 3: host.cartridgeNmi(); break;
|
||||
case 4: case 5: if(track<255) ++track; host.cartridgeNmi(); break;
|
||||
case 6: case 7: if(track) --track; host.cartridgeNmi(); break;
|
||||
case 8: case 9:
|
||||
if (disks[floppyDrive].raw) throw Failure(invalid,"Raw SD files do not support floppy commands.");
|
||||
if (!sector || sector>disks[floppyDrive].sectors) throw Failure(notFound,"Invalid floppy sector.");
|
||||
readDisk(floppyDrive,track*disks[floppyDrive].sectors+sector-1,256,true,floppyBuffer.data());
|
||||
floppyCount=256; floppyStatus=3; break;
|
||||
case 10: case 11:
|
||||
if (disks[floppyDrive].raw) throw Failure(invalid,"Raw SD files do not support floppy commands.");
|
||||
if (protectedCard || !disks[floppyDrive].writable) throw Failure(protectedError,"SD image is write protected.");
|
||||
if (!sector || sector>disks[floppyDrive].sectors) throw Failure(notFound,"Invalid floppy sector.");
|
||||
floppyWrite=true; floppyCount=256; floppyStatus=3; break;
|
||||
case 13: if(value&8) host.cartridgeNmi(); break;
|
||||
default: throw Failure(invalid,"This SDC floppy command is not supported.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SDCDevice::SDCDevice(std::vector<std::uint8_t> rom, std::string rootFolder, bool protectedCard)
|
||||
: impl(std::make_unique<Impl>(std::move(rom),std::move(rootFolder),protectedCard)) { impl->reset(); }
|
||||
SDCDevice::~SDCDevice() = default;
|
||||
void SDCDevice::reset() { impl->reset(); }
|
||||
std::uint8_t SDCDevice::readMemory(std::uint16_t address) const {
|
||||
const auto& p=*impl;
|
||||
if (p.rom.empty() || p.bank != 0) return 0xff;
|
||||
auto offset = address & 0x3fff;
|
||||
return p.rom[offset % p.rom.size()];
|
||||
}
|
||||
std::uint8_t SDCDevice::readPort(std::uint8_t port, DeviceHost& host) {
|
||||
auto& p=*impl;
|
||||
try {
|
||||
if (p.latched) {
|
||||
if(port==0x48) return p.count ? busyReady : p.status;
|
||||
if(port==0x49) return p.reply[0];
|
||||
if(port==0x4a || port==0x4b) return p.replyByte(port);
|
||||
} else {
|
||||
if(port==0x43) return p.bank | (p.bankData&0xf8);
|
||||
if(port==0x48) return p.floppyStatus;
|
||||
if(port==0x49) return p.track;
|
||||
if(port==0x4a) return p.sector;
|
||||
if(port==0x4b) {
|
||||
if(p.floppyCount && !p.floppyWrite) {
|
||||
auto value=p.floppyBuffer[p.floppyOffset++];
|
||||
if(!--p.floppyCount) { p.floppyStatus=0; host.cartridgeNmi(); }
|
||||
return value;
|
||||
}
|
||||
return p.floppyData;
|
||||
}
|
||||
}
|
||||
} catch(const Failure& f) { p.fail(f); }
|
||||
return 0;
|
||||
}
|
||||
void SDCDevice::writePort(std::uint8_t port, std::uint8_t value, DeviceHost& host) {
|
||||
auto& p=*impl;
|
||||
try {
|
||||
if(port==0x40) {
|
||||
if(p.latched) {
|
||||
p.latched = p.streaming = p.receive = false;
|
||||
p.count = p.status = 0;
|
||||
// SDC-DOS reads the reply registers while forming its next LSN.
|
||||
// A previous V (version) reply must not offset that sector by one.
|
||||
p.params = {};
|
||||
p.reply = {};
|
||||
}
|
||||
else if((value&0x43)==0x43) { p.latched=true; p.status=0; }
|
||||
else if(value&1) p.floppyDrive=0;
|
||||
else if(value&2) p.floppyDrive=1;
|
||||
return;
|
||||
}
|
||||
if(p.latched) {
|
||||
if(port==0x48) p.dispatch(value);
|
||||
else if(port==0x49) p.params[0]=value;
|
||||
else if(port==0x4a || port==0x4b) {
|
||||
if(p.receive && p.count) p.receiveByte(value);
|
||||
else p.params[port-0x49]=value;
|
||||
}
|
||||
} else {
|
||||
if(port==0x42) p.bankData=value;
|
||||
else if(port==0x43) { if(!(value&0x80)) p.bank=value&7; }
|
||||
else if(port==0x48) p.floppyCommand(value,host);
|
||||
else if(port==0x49) p.track=value;
|
||||
else if(port==0x4a) p.sector=value;
|
||||
else if(port==0x4b) {
|
||||
p.floppyData=value;
|
||||
if(p.floppyWrite && p.floppyCount) {
|
||||
p.floppyBuffer[p.floppyOffset++]=value;
|
||||
if(!--p.floppyCount) {
|
||||
p.writeDisk(p.floppyDrive,p.track*p.disks[p.floppyDrive].sectors+p.sector-1,true,p.floppyBuffer.data());
|
||||
p.floppyStatus=0; p.floppyWrite=false; host.cartridgeNmi();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(const Failure& f) {
|
||||
p.fail(f);
|
||||
if(!p.latched) { p.floppyStatus = f.status==protectedError ? 0x40 : 0x10; p.floppyCount=0; p.floppyWrite=false; host.cartridgeNmi(); }
|
||||
}
|
||||
}
|
||||
SDCDevice::Snapshot SDCDevice::snapshot() const {
|
||||
Snapshot out;
|
||||
const auto& p=*impl;
|
||||
out.rootFolder=p.rootFolder; out.currentDirectory="/"+join(p.cwd); out.error=p.error; out.writeProtected=p.protectedCard;
|
||||
for(unsigned i=0;i<2;++i) {
|
||||
const auto& d=p.disks[i]; auto& s=out.drives[i];
|
||||
s.name=d.entry.path; s.mounted=bool(d.fd); s.writeProtected=p.protectedCard||!d.writable;
|
||||
s.reads=d.reads; s.writes=d.writes;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
void SDCDevice::mount(unsigned drive, const std::string& guestPath) { impl->mount(drive,guestPath); }
|
||||
void SDCDevice::eject(unsigned drive) { impl->eject(drive); }
|
||||
void SDCDevice::nextDisk(unsigned drive) { impl->nextDisk(drive); }
|
||||
void SDCDevice::setWriteProtected(bool value) { impl->protect(value); }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// CoCo SDC protocol adapted from sdc/sdc.cpp by E. J. Jaquay (2025).
|
||||
#pragma once
|
||||
#include "CartridgeDevice.h"
|
||||
#include <string>
|
||||
|
||||
namespace VCC::Devices {
|
||||
// A selected host folder represents an SD card. All operations run on the
|
||||
// emulation queue. Guest paths are confined to that folder, including through
|
||||
// symlinks and case-insensitive lookup. Guest writes are synchronous, bounded
|
||||
// sector writes; no delayed dirty-image autosave or hidden working copy exists.
|
||||
class SDCDevice final : public CartridgeDevice {
|
||||
public:
|
||||
struct DriveStatus {
|
||||
std::string name;
|
||||
bool mounted = false, writeProtected = true;
|
||||
std::uint64_t reads = 0, writes = 0;
|
||||
};
|
||||
struct Snapshot {
|
||||
std::string rootFolder, currentDirectory, error;
|
||||
bool writeProtected = true;
|
||||
std::array<DriveStatus, 2> drives;
|
||||
};
|
||||
SDCDevice(std::vector<std::uint8_t> rom, std::string rootFolder, bool writeProtected = true);
|
||||
~SDCDevice() override;
|
||||
void reset() override;
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
std::uint8_t readMemory(std::uint16_t) const override;
|
||||
std::uint8_t readPort(std::uint8_t, DeviceHost&) override;
|
||||
void writePort(std::uint8_t, std::uint8_t, DeviceHost&) override;
|
||||
Snapshot snapshot() const;
|
||||
// UI operations throw with a useful error and preserve the previous mount
|
||||
// on failure. The equivalent guest commands return SDC status bits.
|
||||
void mount(unsigned drive, const std::string& guestPath);
|
||||
void eject(unsigned drive);
|
||||
void nextDisk(unsigned drive);
|
||||
void setWriteProtected(bool);
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
#include "CartridgeDevice.h"
|
||||
#include "ssc/ssc_core.h"
|
||||
|
||||
namespace VCC::Devices {
|
||||
// Internal bridge payload: 4096-byte PIC firmware, then 2048-byte speech ROM.
|
||||
// Neither chip ROM is visible in the CoCo cartridge memory address space.
|
||||
class SpeechSoundDevice final : public CartridgeDevice {
|
||||
public:
|
||||
explicit SpeechSoundDevice(const std::vector<std::uint8_t>& bytes = {}) {
|
||||
if (!bytes.empty() && bytes.size() != 6144)
|
||||
throw std::invalid_argument("Speech/Sound needs a 4 KiB PIC ROM and a 2 KiB speech ROM");
|
||||
if (!bytes.empty()) {
|
||||
core.LoadPicRom(bytes.data(), 4096);
|
||||
core.LoadSpeechRom(bytes.data() + 4096, 2048);
|
||||
}
|
||||
core.SetTickRateHz(44100.0); reset();
|
||||
}
|
||||
// SscCore callbacks capture its address: never copy or move the device.
|
||||
SpeechSoundDevice(const SpeechSoundDevice&) = delete;
|
||||
SpeechSoundDevice& operator=(const SpeechSoundDevice&) = delete;
|
||||
void reset() override { core.Reset(); ticks = 0; }
|
||||
void horizontalSync(DeviceHost&) override {}
|
||||
void advanceAudio() override { if (ready()) { core.Tick(); ++ticks; } }
|
||||
std::uint8_t readMemory(std::uint16_t) const override { return 0xff; }
|
||||
std::uint8_t readPort(std::uint8_t port, DeviceHost&) override { return ready() ? core.ReadPort(port) : 0; }
|
||||
void writePort(std::uint8_t port, std::uint8_t value, DeviceHost&) override { if (ready()) core.WritePort(port, value); }
|
||||
std::uint16_t audio() const override {
|
||||
const auto value = ready() ? core.LatchedSample() : 0;
|
||||
return (std::uint16_t(value) << 8) | value;
|
||||
}
|
||||
bool hasCartridgeAudioOutput() const override { return ready(); }
|
||||
bool ready() const { return core.RomsLoaded(); }
|
||||
std::uint64_t audioTicks() const { return ticks; }
|
||||
const ssc::SscCore& diagnostics() const { return core; }
|
||||
private:
|
||||
ssc::SscCore core;
|
||||
std::uint64_t ticks = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
SSC wiring and SP0256/TMS7000 portions are derived from MAME:
|
||||
Copyright holders: Tim Lindner, Joseph Zbiciak, hap.
|
||||
See the individual source headers for component provenance.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,192 @@
|
||||
// ay8913.cpp -- see ay8913.h for design notes.
|
||||
|
||||
#include "ay8913.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ssc {
|
||||
|
||||
// Logarithmic approximation of the AY's per-channel volume table
|
||||
// (-2dB per step, level 15 = full scale, level 0 = silence). See the
|
||||
// header comment: this is not a measured-silicon table, just a
|
||||
// reasonable-sounding approximation of the chip's documented
|
||||
// logarithmic response.
|
||||
const int16_t Ay8913::kVolumeTable[16] = {
|
||||
0, 1304, 1642, 2067, 2603, 3277, 4125, 5193,
|
||||
6538, 8231, 10362, 13045, 16422, 20675, 26028, 32767
|
||||
};
|
||||
|
||||
Ay8913::Ay8913()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void Ay8913::Reset()
|
||||
{
|
||||
for (auto& r : m_regs) r = 0;
|
||||
m_selected = 0;
|
||||
m_step_accum = 0.0;
|
||||
for (int i = 0; i < 3; i++) { m_tone_counter[i] = 0; m_tone_output[i] = 1; }
|
||||
m_noise_counter = 0;
|
||||
m_noise_lfsr = 1;
|
||||
m_noise_output = 1;
|
||||
m_env_counter = 0;
|
||||
m_env_step = 0;
|
||||
m_env_dir_up = true;
|
||||
m_env_holding = false;
|
||||
}
|
||||
|
||||
void Ay8913::SelectRegister(uint8_t reg)
|
||||
{
|
||||
m_selected = reg & 0x0f;
|
||||
}
|
||||
|
||||
void Ay8913::WriteData(uint8_t data)
|
||||
{
|
||||
m_regs[m_selected] = data;
|
||||
|
||||
if (m_selected == 13) {
|
||||
// envelope shape write resets the ramp
|
||||
m_env_step = 0;
|
||||
m_env_holding = false;
|
||||
m_env_dir_up = (data & 0x04) != 0; // Attack
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Ay8913::ReadData() const
|
||||
{
|
||||
return m_regs[m_selected];
|
||||
}
|
||||
|
||||
int Ay8913::TonePeriod(int ch) const
|
||||
{
|
||||
int fine = m_regs[ch * 2];
|
||||
int coarse = m_regs[ch * 2 + 1] & 0x0f;
|
||||
int p = (coarse << 8) | fine;
|
||||
return p ? p : 1;
|
||||
}
|
||||
|
||||
int Ay8913::NoisePeriod() const
|
||||
{
|
||||
int p = m_regs[6] & 0x1f;
|
||||
return p ? p : 1;
|
||||
}
|
||||
|
||||
int Ay8913::EnvPeriod() const
|
||||
{
|
||||
int fine = m_regs[11];
|
||||
int coarse = m_regs[12];
|
||||
int p = (coarse << 8) | fine;
|
||||
return p ? p : 1;
|
||||
}
|
||||
|
||||
void Ay8913::TickOneEnvelopeStep()
|
||||
{
|
||||
if (m_env_holding) return;
|
||||
|
||||
uint8_t shape = m_regs[13];
|
||||
bool cont = (shape & 0x08) != 0;
|
||||
bool alt = (shape & 0x02) != 0;
|
||||
bool hold = (shape & 0x01) != 0;
|
||||
|
||||
m_env_step++;
|
||||
if (m_env_step >= 32)
|
||||
{
|
||||
if (!cont)
|
||||
{
|
||||
m_env_step = 32;
|
||||
m_env_holding = true;
|
||||
}
|
||||
else if (hold)
|
||||
{
|
||||
m_env_step = 31;
|
||||
m_env_holding = true;
|
||||
if (alt) m_env_dir_up = !m_env_dir_up;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_env_step = 0;
|
||||
if (alt) m_env_dir_up = !m_env_dir_up;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Ay8913::CurrentEnvelopeLevel() const
|
||||
{
|
||||
uint8_t shape = m_regs[13];
|
||||
bool cont = (shape & 0x08) != 0;
|
||||
|
||||
if (!cont && m_env_holding)
|
||||
return 0;
|
||||
|
||||
int step = m_env_step & 31;
|
||||
int level = m_env_dir_up ? step : (31 - step);
|
||||
return level >> 1; // 0..31 -> 0..15
|
||||
}
|
||||
|
||||
int16_t Ay8913::Render(double seconds)
|
||||
{
|
||||
if (m_clock_hz <= 0.0) return 0;
|
||||
|
||||
double steps = seconds * (m_clock_hz / 8.0) + m_step_accum;
|
||||
long whole = (long)steps;
|
||||
m_step_accum = steps - double(whole);
|
||||
|
||||
// Safety cap: never iterate an absurd number of internal steps in
|
||||
// one call (e.g. if the host passes a huge `seconds` by mistake).
|
||||
if (whole > 1'000'000) whole = 1'000'000;
|
||||
|
||||
for (long i = 0; i < whole; i++)
|
||||
{
|
||||
for (int ch = 0; ch < 3; ch++)
|
||||
{
|
||||
if (++m_tone_counter[ch] >= TonePeriod(ch)) {
|
||||
m_tone_counter[ch] = 0;
|
||||
m_tone_output[ch] ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (++m_noise_counter >= NoisePeriod()) {
|
||||
m_noise_counter = 0;
|
||||
// 17-bit LFSR, taps at bit0 and bit3 (standard AY polynomial)
|
||||
uint32_t bit = ((m_noise_lfsr ^ (m_noise_lfsr >> 3)) & 1);
|
||||
m_noise_lfsr = (m_noise_lfsr >> 1) | (bit << 16);
|
||||
m_noise_output = int(m_noise_lfsr & 1);
|
||||
}
|
||||
|
||||
if (++m_env_counter >= EnvPeriod()) {
|
||||
m_env_counter = 0;
|
||||
TickOneEnvelopeStep();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t mixer = m_regs[7];
|
||||
int32_t mix = 0;
|
||||
|
||||
for (int ch = 0; ch < 3; ch++)
|
||||
{
|
||||
bool tone_enabled = ((mixer >> ch) & 1) == 0; // active low
|
||||
bool noise_enabled = ((mixer >> (ch + 3)) & 1) == 0; // active low
|
||||
|
||||
bool tone_bit = tone_enabled ? (m_tone_output[ch] != 0) : true;
|
||||
bool noise_bit = noise_enabled ? (m_noise_output != 0) : true;
|
||||
|
||||
if (!(tone_bit && noise_bit)) continue; // silent this instant
|
||||
|
||||
uint8_t ampreg = m_regs[8 + ch];
|
||||
int volIndex;
|
||||
if (ampreg & 0x10) volIndex = CurrentEnvelopeLevel();
|
||||
else volIndex = ampreg & 0x0f;
|
||||
|
||||
mix += kVolumeTable[volIndex & 0x0f];
|
||||
}
|
||||
|
||||
// Average the (up to 3) contributing channels down so the mix
|
||||
// doesn't clip when all three are active simultaneously.
|
||||
mix /= 3;
|
||||
if (mix > 32767) mix = 32767;
|
||||
if (mix < -32768) mix = -32768;
|
||||
return int16_t(mix);
|
||||
}
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,94 @@
|
||||
// ay8913.h
|
||||
//
|
||||
// Standalone emulation of the General Instrument AY-3-8913 Programmable
|
||||
// Sound Generator, as used inside the Tandy Speech/Sound Cartridge (the
|
||||
// SSC uses the single-ended-output '8913 variant, which is functionally
|
||||
// the tone/noise/envelope core of the AY-3-8910 minus the two 8-bit
|
||||
// parallel I/O ports and minus the three separate channel pins -- the
|
||||
// '8913 mixes all three channels internally and brings out one analog
|
||||
// output).
|
||||
//
|
||||
// This is an original clean-room implementation written from the
|
||||
// published AY-3-8910/8912/8913 datasheet register model (16 registers,
|
||||
// three 12-bit tone generators, one 5-bit noise generator, one 16-bit
|
||||
// hardware envelope generator with the ten standard shapes, one 8-bit
|
||||
// mixer/enable register, three 4/5-bit channel amplitude registers) --
|
||||
// it is not a port of MAME's ay8910.cpp. The tone/noise/envelope timing
|
||||
// follows the datasheet's documented divide ratios (tone/noise: input
|
||||
// clock/8 internal step, toggle every period counts, giving the
|
||||
// datasheet's f = clock/(16*N); envelope: same /8 step, one of 32 ramp
|
||||
// positions advanced every period counts, giving f = clock/(8*16*N)).
|
||||
// The per-level output amplitude table is a logarithmic approximation
|
||||
// (roughly -2dB/step) rather than a measured-silicon table, since no
|
||||
// authoritative published table was available while writing this --
|
||||
// see the comment on kVolumeTable below if you want to substitute a
|
||||
// more precisely measured table later.
|
||||
//
|
||||
// Port for VCC SSC cartridge: 2026
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace ssc {
|
||||
|
||||
class Ay8913 {
|
||||
public:
|
||||
Ay8913();
|
||||
|
||||
void Reset();
|
||||
|
||||
// Latch a register number (0-15; only 0-13 are meaningful on the
|
||||
// '8913, since it has no I/O ports).
|
||||
void SelectRegister(uint8_t reg);
|
||||
|
||||
// Write to the currently-selected register.
|
||||
void WriteData(uint8_t data);
|
||||
|
||||
// Read back the currently-selected register (used by the SSC's PIC
|
||||
// firmware to poll status via the D-port bus turnaround).
|
||||
uint8_t ReadData() const;
|
||||
|
||||
// Sets the chip's input clock (Hz) -- the SSC drives this at the
|
||||
// doubled CoCo E-clock, ~1.789772MHz.
|
||||
void SetClock(double clock_hz) { m_clock_hz = clock_hz; }
|
||||
|
||||
// Advances the internal generators by `seconds` of wall-clock time
|
||||
// and returns one mixed output sample, roughly normalized to
|
||||
// [-32767, 32767] (silence = 0). Intended to be called once per
|
||||
// host audio tick (e.g. once per CoCo scanline).
|
||||
int16_t Render(double seconds);
|
||||
|
||||
private:
|
||||
static constexpr int kNumRegs = 16;
|
||||
|
||||
uint8_t m_regs[kNumRegs] = {0};
|
||||
uint8_t m_selected = 0;
|
||||
|
||||
double m_clock_hz = 1789772.0;
|
||||
double m_step_accum = 0.0; // fractional internal (/8) steps owed
|
||||
|
||||
// tone generators (A,B,C)
|
||||
int m_tone_counter[3] = {0, 0, 0};
|
||||
int m_tone_output[3] = {1, 1, 1};
|
||||
|
||||
// noise generator
|
||||
int m_noise_counter = 0;
|
||||
uint32_t m_noise_lfsr = 1;
|
||||
int m_noise_output = 1;
|
||||
|
||||
// envelope generator
|
||||
int m_env_counter = 0;
|
||||
int m_env_step = 0; // 0-31 ramp position
|
||||
bool m_env_dir_up = true; // current ramp direction
|
||||
bool m_env_holding = false;
|
||||
|
||||
int TonePeriod(int ch) const;
|
||||
int NoisePeriod() const;
|
||||
int EnvPeriod() const;
|
||||
void TickOneEnvelopeStep();
|
||||
int CurrentEnvelopeLevel() const; // 0-31 shape position -> 0-15 vol index
|
||||
|
||||
static const int16_t kVolumeTable[16];
|
||||
};
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,705 @@
|
||||
// sp0256.cpp
|
||||
// See sp0256.h for provenance/license notes. Mechanical port of MAME's
|
||||
// sp0256.cpp LPC-12 filter and microsequencer to a standalone class.
|
||||
|
||||
#include "sp0256.h"
|
||||
|
||||
namespace ssc {
|
||||
|
||||
Sp0256::Sp0256()
|
||||
{
|
||||
m_rom = std::make_unique<uint8_t[]>(0x10000);
|
||||
std::memset(m_rom.get(), 0, 0x10000);
|
||||
m_scratch = std::make_unique<int16_t[]>(kScbufSize);
|
||||
std::memset(m_scratch.get(), 0, kScbufSize * sizeof(int16_t));
|
||||
m_filt.rng = 1;
|
||||
}
|
||||
|
||||
void Sp0256::LoadRom(const uint8_t* al2_2k, size_t len)
|
||||
{
|
||||
std::memset(m_rom.get(), 0, 0x10000);
|
||||
if (al2_2k && len) {
|
||||
size_t n = len < 0x800 ? len : 0x800;
|
||||
std::memcpy(m_rom.get() + 0x1000, al2_2k, n);
|
||||
}
|
||||
}
|
||||
|
||||
void Sp0256::SetSby(int line_state)
|
||||
{
|
||||
if (m_sby_line != line_state) {
|
||||
m_sby_line = line_state;
|
||||
}
|
||||
}
|
||||
|
||||
void Sp0256::Reset()
|
||||
{
|
||||
m_fifo_head = m_fifo_tail = m_fifo_bitp = 0;
|
||||
m_filt = Lpc12{};
|
||||
m_filt.rng = 1;
|
||||
m_halted = 1;
|
||||
m_filt.rpt = -1;
|
||||
m_lrq = 1;
|
||||
m_ald = 0;
|
||||
m_pc = 0;
|
||||
m_stack = 0;
|
||||
m_fifo_sel = 0;
|
||||
m_mode = 0;
|
||||
m_page = 0x1000 << 3;
|
||||
m_silent = 1;
|
||||
m_sby_line = 0;
|
||||
if (DataRequestChanged) DataRequestChanged(true);
|
||||
SetSby(1);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// LIMIT / LPC12 update -- ported verbatim (algorithmically) from MAME
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
int16_t Sp0256::Lpc12::Limit(int16_t s)
|
||||
{
|
||||
if (s > 8191) return 8191;
|
||||
if (s < -8192) return -8192;
|
||||
return s;
|
||||
}
|
||||
|
||||
int Sp0256::Lpc12::Update(int num_samp, int16_t* out, uint32_t* optr)
|
||||
{
|
||||
int i;
|
||||
int oidx = int(*optr);
|
||||
|
||||
for (i = 0; i < num_samp; i++)
|
||||
{
|
||||
bool do_int = false;
|
||||
uint16_t samp = 0;
|
||||
if (per)
|
||||
{
|
||||
if (cnt <= 0)
|
||||
{
|
||||
cnt += per;
|
||||
samp = uint16_t(amp);
|
||||
rpt--;
|
||||
do_int = interp != 0;
|
||||
for (int j = 0; j < 6; j++) z_data[j][1] = z_data[j][0] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
samp = 0;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (--cnt <= 0)
|
||||
{
|
||||
do_int = interp != 0;
|
||||
cnt = kPerNoise;
|
||||
rpt--;
|
||||
for (int j = 0; j < 6; j++) z_data[j][0] = z_data[j][1] = 0;
|
||||
}
|
||||
|
||||
const bool bit = (rng & 1) != 0;
|
||||
rng = (rng >> 1) ^ (bit ? 0x4001u : 0u);
|
||||
samp = bit ? uint16_t(amp) : uint16_t(-amp);
|
||||
}
|
||||
|
||||
if (do_int)
|
||||
{
|
||||
r[0] = uint8_t(r[0] + r[14]);
|
||||
r[1] = uint8_t(r[1] + r[15]);
|
||||
amp = (r[0] & 0x1F) << (((r[0] & 0xE0) >> 5) + 0);
|
||||
per = r[1];
|
||||
}
|
||||
|
||||
if (rpt <= 0) break;
|
||||
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
int s = int16_t(samp);
|
||||
s += (int(b_coef[j]) * int(z_data[j][1])) >> 9;
|
||||
s += (int(f_coef[j]) * int(z_data[j][0])) >> 8;
|
||||
samp = uint16_t(s);
|
||||
z_data[j][1] = z_data[j][0];
|
||||
z_data[j][0] = int16_t(samp);
|
||||
}
|
||||
|
||||
out[oidx++ & kScbufMask] = int16_t(Limit(int16_t(samp)) << 2);
|
||||
}
|
||||
|
||||
*optr = uint32_t(oidx);
|
||||
return i;
|
||||
}
|
||||
|
||||
void Sp0256::Lpc12::Regdec()
|
||||
{
|
||||
amp = (r[0] & 0x1F) << (((r[0] & 0xE0) >> 5) + 0);
|
||||
cnt = 0;
|
||||
per = r[1];
|
||||
|
||||
static constexpr int16_t qtbl[128] = {
|
||||
0, 9, 17, 25, 33, 41, 49, 57,
|
||||
65, 73, 81, 89, 97, 105, 113, 121,
|
||||
129, 137, 145, 153, 161, 169, 177, 185,
|
||||
193, 201, 209, 217, 225, 233, 241, 249,
|
||||
257, 265, 273, 281, 289, 297, 301, 305,
|
||||
309, 313, 317, 321, 325, 329, 333, 337,
|
||||
341, 345, 349, 353, 357, 361, 365, 369,
|
||||
373, 377, 381, 385, 389, 393, 397, 401,
|
||||
405, 409, 413, 417, 421, 425, 427, 429,
|
||||
431, 433, 435, 437, 439, 441, 443, 445,
|
||||
447, 449, 451, 453, 455, 457, 459, 461,
|
||||
463, 465, 467, 469, 471, 473, 475, 477,
|
||||
479, 481, 482, 483, 484, 485, 486, 487,
|
||||
488, 489, 490, 491, 492, 493, 494, 495,
|
||||
496, 497, 498, 499, 500, 501, 502, 503,
|
||||
504, 505, 506, 507, 508, 509, 510, 511
|
||||
};
|
||||
|
||||
auto IQ = [](uint8_t x) -> int16_t {
|
||||
return (x & 0x80) ? int16_t(qtbl[0x7F & uint8_t(-x)]) : int16_t(-qtbl[x]);
|
||||
};
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
b_coef[i] = IQ(r[2 + 2 * i]);
|
||||
f_coef[i] = IQ(r[3 + 2 * i]);
|
||||
}
|
||||
|
||||
interp = (r[14] || r[15]) ? 1 : 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// SP0256 data-format tables -- verbatim from MAME (see original for
|
||||
// bitfield documentation: len/shift/param/delta/field/clr5/clrall).
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#define CR(l,s,p,d,f,c5,ca) \
|
||||
( \
|
||||
(((l) & 15) << 0) | \
|
||||
(((s) & 15) << 4) | \
|
||||
(((p) & 15) << 8) | \
|
||||
(((d) & 1) << 12) | \
|
||||
(((f) & 1) << 13) | \
|
||||
(((c5) & 1) << 14) | \
|
||||
(((ca) & 1) << 15) \
|
||||
)
|
||||
|
||||
#define CR_DELTA CR(0,0,0,1,0,0,0)
|
||||
#define CR_FIELD CR(0,0,0,0,1,0,0)
|
||||
#define CR_CLR5 CR(0,0,0,0,0,1,0)
|
||||
#define CR_CLRA CR(0,0,0,0,0,0,1)
|
||||
#define CR_LEN(x) ((x) & 15)
|
||||
#define CR_SHF(x) (((x) >> 4) & 15)
|
||||
#define CR_PRM(x) (((x) >> 8) & 15)
|
||||
|
||||
enum { AM = 0, PR, B0, F0, B1, F1, B2, F2, B3, F3, B4, F4, B5, F5, IA, IP };
|
||||
|
||||
static const uint16_t sp0256_datafmt[] =
|
||||
{
|
||||
/* 0 */ CR( 0, 0, 0, 0, 0, 0, 1),
|
||||
/* 1 */ CR( 8, 0, AM, 0, 0, 0, 1),
|
||||
/* 2 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 3 */ CR( 8, 0, B0, 0, 0, 0, 0),
|
||||
/* 4 */ CR( 8, 0, F0, 0, 0, 0, 0),
|
||||
/* 5 */ CR( 8, 0, B1, 0, 0, 0, 0),
|
||||
/* 6 */ CR( 8, 0, F1, 0, 0, 0, 0),
|
||||
/* 7 */ CR( 8, 0, B2, 0, 0, 0, 0),
|
||||
/* 8 */ CR( 8, 0, F2, 0, 0, 0, 0),
|
||||
/* 9 */ CR( 8, 0, B3, 0, 0, 0, 0),
|
||||
/* 10 */ CR( 8, 0, F3, 0, 0, 0, 0),
|
||||
/* 11 */ CR( 8, 0, B4, 0, 0, 0, 0),
|
||||
/* 12 */ CR( 8, 0, F4, 0, 0, 0, 0),
|
||||
/* 13 */ CR( 8, 0, B5, 0, 0, 0, 0),
|
||||
/* 14 */ CR( 8, 0, F5, 0, 0, 0, 0),
|
||||
/* 15 */ CR( 8, 0, IA, 0, 0, 0, 0),
|
||||
/* 16 */ CR( 8, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 17 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 18 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 19 */ CR( 4, 3, B3, 0, 0, 0, 0),
|
||||
/* 20 */ CR( 6, 2, F3, 0, 0, 0, 0),
|
||||
/* 21 */ CR( 7, 1, B4, 0, 0, 0, 0),
|
||||
/* 22 */ CR( 6, 2, F4, 0, 0, 0, 0),
|
||||
/* 23 */ CR( 8, 0, B5, 0, 0, 0, 0),
|
||||
/* 24 */ CR( 8, 0, F5, 0, 0, 0, 0),
|
||||
|
||||
/* 25 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 26 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 27 */ CR( 6, 1, B3, 0, 0, 0, 0),
|
||||
/* 28 */ CR( 7, 1, F3, 0, 0, 0, 0),
|
||||
/* 29 */ CR( 8, 0, B4, 0, 0, 0, 0),
|
||||
/* 30 */ CR( 8, 0, F4, 0, 0, 0, 0),
|
||||
/* 31 */ CR( 8, 0, B5, 0, 0, 0, 0),
|
||||
/* 32 */ CR( 8, 0, F5, 0, 0, 0, 0),
|
||||
|
||||
/* 33 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 34 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 35 */ CR( 6, 2, F3, 0, 1, 0, 0),
|
||||
/* 36 */ CR( 6, 2, F4, 0, 1, 0, 0),
|
||||
/* 37 */ CR( 8, 0, F5, 0, 1, 0, 0),
|
||||
|
||||
/* 38 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 39 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 40 */ CR( 7, 1, F3, 0, 1, 0, 0),
|
||||
/* 41 */ CR( 8, 0, F4, 0, 1, 0, 0),
|
||||
/* 42 */ CR( 8, 0, F5, 0, 1, 0, 0),
|
||||
|
||||
/* 43 */ 0,
|
||||
/* 44 */ 0,
|
||||
|
||||
/* 45 */ CR( 4, 2, AM, 1, 0, 0, 0),
|
||||
/* 46 */ CR( 5, 0, PR, 1, 0, 0, 0),
|
||||
/* 47 */ CR( 3, 4, B0, 1, 0, 0, 0),
|
||||
/* 48 */ CR( 3, 3, F0, 1, 0, 0, 0),
|
||||
/* 49 */ CR( 3, 4, B1, 1, 0, 0, 0),
|
||||
/* 50 */ CR( 3, 3, F1, 1, 0, 0, 0),
|
||||
/* 51 */ CR( 3, 4, B2, 1, 0, 0, 0),
|
||||
/* 52 */ CR( 3, 3, F2, 1, 0, 0, 0),
|
||||
/* 53 */ CR( 3, 3, B3, 1, 0, 0, 0),
|
||||
/* 54 */ CR( 4, 2, F3, 1, 0, 0, 0),
|
||||
/* 55 */ CR( 4, 1, B4, 1, 0, 0, 0),
|
||||
/* 56 */ CR( 4, 2, F4, 1, 0, 0, 0),
|
||||
/* 57 */ CR( 5, 0, B5, 1, 0, 0, 0),
|
||||
/* 58 */ CR( 5, 0, F5, 1, 0, 0, 0),
|
||||
|
||||
/* 59 */ CR( 4, 2, AM, 1, 0, 0, 0),
|
||||
/* 60 */ CR( 5, 0, PR, 1, 0, 0, 0),
|
||||
/* 61 */ CR( 4, 1, B0, 1, 0, 0, 0),
|
||||
/* 62 */ CR( 4, 2, F0, 1, 0, 0, 0),
|
||||
/* 63 */ CR( 4, 1, B1, 1, 0, 0, 0),
|
||||
/* 64 */ CR( 4, 2, F1, 1, 0, 0, 0),
|
||||
/* 65 */ CR( 4, 1, B2, 1, 0, 0, 0),
|
||||
/* 66 */ CR( 4, 2, F2, 1, 0, 0, 0),
|
||||
/* 67 */ CR( 4, 1, B3, 1, 0, 0, 0),
|
||||
/* 68 */ CR( 5, 1, F3, 1, 0, 0, 0),
|
||||
/* 69 */ CR( 5, 0, B4, 1, 0, 0, 0),
|
||||
/* 70 */ CR( 5, 0, F4, 1, 0, 0, 0),
|
||||
/* 71 */ CR( 5, 0, B5, 1, 0, 0, 0),
|
||||
/* 72 */ CR( 5, 0, F5, 1, 0, 0, 0),
|
||||
|
||||
/* 73 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 74 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 75 */ CR( 5, 3, F0, 0, 1, 0, 0),
|
||||
/* 76 */ CR( 5, 3, F1, 0, 1, 0, 0),
|
||||
/* 77 */ CR( 5, 3, F2, 0, 1, 0, 0),
|
||||
|
||||
/* 78 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 79 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 80 */ CR( 6, 2, F0, 0, 1, 0, 0),
|
||||
/* 81 */ CR( 6, 2, F1, 0, 1, 0, 0),
|
||||
/* 82 */ CR( 6, 2, F2, 0, 1, 0, 0),
|
||||
|
||||
/* 83 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 84 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 85 */ CR( 3, 4, B0, 0, 0, 0, 0),
|
||||
/* 86 */ CR( 5, 3, F0, 0, 0, 0, 0),
|
||||
/* 87 */ CR( 3, 4, B1, 0, 0, 0, 0),
|
||||
/* 88 */ CR( 5, 3, F1, 0, 0, 0, 0),
|
||||
/* 89 */ CR( 3, 4, B2, 0, 0, 0, 0),
|
||||
/* 90 */ CR( 5, 3, F2, 0, 0, 0, 0),
|
||||
/* 91 */ CR( 4, 3, B3, 0, 0, 0, 0),
|
||||
/* 92 */ CR( 6, 2, F3, 0, 0, 0, 0),
|
||||
/* 93 */ CR( 7, 1, B4, 0, 0, 0, 0),
|
||||
/* 94 */ CR( 6, 2, F4, 0, 0, 0, 0),
|
||||
/* 95 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 96 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 97 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 98 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 99 */ CR( 6, 1, B0, 0, 0, 0, 0),
|
||||
/* 100 */ CR( 6, 2, F0, 0, 0, 0, 0),
|
||||
/* 101 */ CR( 6, 1, B1, 0, 0, 0, 0),
|
||||
/* 102 */ CR( 6, 2, F1, 0, 0, 0, 0),
|
||||
/* 103 */ CR( 6, 1, B2, 0, 0, 0, 0),
|
||||
/* 104 */ CR( 6, 2, F2, 0, 0, 0, 0),
|
||||
/* 105 */ CR( 6, 1, B3, 0, 0, 0, 0),
|
||||
/* 106 */ CR( 7, 1, F3, 0, 0, 0, 0),
|
||||
/* 107 */ CR( 8, 0, B4, 0, 0, 0, 0),
|
||||
/* 108 */ CR( 8, 0, F4, 0, 0, 0, 0),
|
||||
/* 109 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 110 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 111 */ CR( 4, 2, AM, 1, 0, 0, 0),
|
||||
/* 112 */ CR( 5, 0, PR, 1, 0, 0, 0),
|
||||
/* 113 */ CR( 3, 3, B3, 1, 0, 0, 0),
|
||||
/* 114 */ CR( 4, 2, F3, 1, 0, 0, 0),
|
||||
/* 115 */ CR( 4, 1, B4, 1, 0, 0, 0),
|
||||
/* 116 */ CR( 4, 2, F4, 1, 0, 0, 0),
|
||||
/* 117 */ CR( 5, 0, B5, 1, 0, 0, 0),
|
||||
/* 118 */ CR( 5, 0, F5, 1, 0, 0, 0),
|
||||
|
||||
/* 119 */ CR( 4, 2, AM, 1, 0, 0, 0),
|
||||
/* 120 */ CR( 5, 0, PR, 1, 0, 0, 0),
|
||||
/* 121 */ CR( 4, 1, B3, 1, 0, 0, 0),
|
||||
/* 122 */ CR( 5, 1, F3, 1, 0, 0, 0),
|
||||
/* 123 */ CR( 5, 0, B4, 1, 0, 0, 0),
|
||||
/* 124 */ CR( 5, 0, F4, 1, 0, 0, 0),
|
||||
/* 125 */ CR( 5, 0, B5, 1, 0, 0, 0),
|
||||
/* 126 */ CR( 5, 0, F5, 1, 0, 0, 0),
|
||||
|
||||
/* 127 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 128 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
|
||||
/* 129 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 130 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 131 */ CR( 3, 4, B0, 0, 0, 0, 0),
|
||||
/* 132 */ CR( 5, 3, F0, 0, 0, 0, 0),
|
||||
/* 133 */ CR( 3, 4, B1, 0, 0, 0, 0),
|
||||
/* 134 */ CR( 5, 3, F1, 0, 0, 0, 0),
|
||||
/* 135 */ CR( 3, 4, B2, 0, 0, 0, 0),
|
||||
/* 136 */ CR( 5, 3, F2, 0, 0, 0, 0),
|
||||
/* 137 */ CR( 4, 3, B3, 0, 0, 0, 0),
|
||||
/* 138 */ CR( 6, 2, F3, 0, 0, 0, 0),
|
||||
/* 139 */ CR( 7, 1, B4, 0, 0, 0, 0),
|
||||
/* 140 */ CR( 6, 2, F4, 0, 0, 0, 0),
|
||||
/* 141 */ CR( 8, 0, B5, 0, 0, 0, 0),
|
||||
/* 142 */ CR( 8, 0, F5, 0, 0, 0, 0),
|
||||
/* 143 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 144 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 145 */ CR( 6, 2, AM, 0, 0, 0, 1),
|
||||
/* 146 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 147 */ CR( 6, 1, B0, 0, 0, 0, 0),
|
||||
/* 148 */ CR( 6, 2, F0, 0, 0, 0, 0),
|
||||
/* 149 */ CR( 6, 1, B1, 0, 0, 0, 0),
|
||||
/* 150 */ CR( 6, 2, F1, 0, 0, 0, 0),
|
||||
/* 151 */ CR( 6, 1, B2, 0, 0, 0, 0),
|
||||
/* 152 */ CR( 6, 2, F2, 0, 0, 0, 0),
|
||||
/* 153 */ CR( 6, 1, B3, 0, 0, 0, 0),
|
||||
/* 154 */ CR( 7, 1, F3, 0, 0, 0, 0),
|
||||
/* 155 */ CR( 8, 0, B4, 0, 0, 0, 0),
|
||||
/* 156 */ CR( 8, 0, F4, 0, 0, 0, 0),
|
||||
/* 157 */ CR( 8, 0, B5, 0, 0, 0, 0),
|
||||
/* 158 */ CR( 8, 0, F5, 0, 0, 0, 0),
|
||||
/* 159 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 160 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 161 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 162 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 163 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 164 */ CR( 5, 3, F0, 0, 1, 0, 0),
|
||||
/* 165 */ CR( 5, 3, F1, 0, 1, 0, 0),
|
||||
/* 166 */ CR( 5, 3, F2, 0, 1, 0, 0),
|
||||
/* 167 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 168 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
|
||||
/* 169 */ CR( 0, 0, 0, 0, 0, 1, 0),
|
||||
/* 170 */ CR( 6, 2, AM, 0, 0, 0, 0),
|
||||
/* 171 */ CR( 8, 0, PR, 0, 0, 0, 0),
|
||||
/* 172 */ CR( 6, 2, F0, 0, 1, 0, 0),
|
||||
/* 173 */ CR( 6, 2, F1, 0, 1, 0, 0),
|
||||
/* 174 */ CR( 6, 2, F2, 0, 1, 0, 0),
|
||||
/* 175 */ CR( 5, 0, IA, 0, 0, 0, 0),
|
||||
/* 176 */ CR( 5, 0, IP, 0, 0, 0, 0),
|
||||
};
|
||||
|
||||
static const int16_t sp0256_df_idx[16 * 8] =
|
||||
{
|
||||
/* OPCODE 0000 */ -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* OPCODE 1000 */ -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* OPCODE 0100 */ 17, 22, 17, 24, 25, 30, 25, 32,
|
||||
/* OPCODE 1100 */ 83, 94, 129,142, 97, 108, 145,158,
|
||||
/* OPCODE 0010 */ 83, 96, 129,144, 97, 110, 145,160,
|
||||
/* OPCODE 1010 */ 73, 77, 74, 77, 78, 82, 79, 82,
|
||||
/* OPCODE 0110 */ 33, 36, 34, 37, 38, 41, 39, 42,
|
||||
/* OPCODE 1110 */ 127,128, 127,128, 127,128, 127,128,
|
||||
/* OPCODE 0001 */ 1, 14, 1, 16, 1, 14, 1, 16,
|
||||
/* OPCODE 1001 */ 45, 56, 45, 58, 59, 70, 59, 72,
|
||||
/* OPCODE 0101 */ 161,166, 162,166, 169,174, 170,174,
|
||||
/* OPCODE 1101 */ 111,116, 111,118, 119,124, 119,126,
|
||||
/* OPCODE 0011 */ 161,168, 162,168, 169,176, 170,176,
|
||||
/* OPCODE 1011 */ -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* OPCODE 0111 */ -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
/* OPCODE 1111 */ 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static inline uint32_t bitrev32(uint32_t val)
|
||||
{
|
||||
val = ((val & 0xFFFF0000) >> 16) | ((val & 0x0000FFFF) << 16);
|
||||
val = ((val & 0xFF00FF00) >> 8) | ((val & 0x00FF00FF) << 8);
|
||||
val = ((val & 0xF0F0F0F0) >> 4) | ((val & 0x0F0F0F0F) << 4);
|
||||
val = ((val & 0xCCCCCCCC) >> 2) | ((val & 0x33333333) << 2);
|
||||
val = ((val & 0xAAAAAAAA) >> 1) | ((val & 0x55555555) << 1);
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t Sp0256::Getb(int len)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
if (m_fifo_sel)
|
||||
{
|
||||
uint32_t d0 = m_fifo[(m_fifo_tail ) & 63];
|
||||
uint32_t d1 = m_fifo[(m_fifo_tail + 1) & 63];
|
||||
data = ((d1 << 10) | d0) >> m_fifo_bitp;
|
||||
|
||||
m_fifo_bitp += len;
|
||||
if (m_fifo_bitp >= 10) { m_fifo_tail++; m_fifo_bitp -= 10; }
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx0 = (m_pc ) >> 3;
|
||||
int idx1 = (m_pc + 8) >> 3;
|
||||
uint32_t d0 = m_rom[idx0 & 0xffff];
|
||||
uint32_t d1 = m_rom[idx1 & 0xffff];
|
||||
data = ((d1 << 8) | d0) >> (m_pc & 7);
|
||||
m_pc += len;
|
||||
}
|
||||
|
||||
data &= (uint32_t(1) << len) - 1;
|
||||
return data;
|
||||
}
|
||||
|
||||
void Sp0256::Micro()
|
||||
{
|
||||
uint8_t immed4, opcode;
|
||||
uint16_t cr;
|
||||
int ctrl_xfer;
|
||||
int repeat;
|
||||
int i, idx0, idx1;
|
||||
|
||||
// Safety fuse: well-formed allophone ROM data always resolves to a
|
||||
// repeat count or a halt within a handful of iterations. This bound
|
||||
// is not present in the original hardware/ROM (which is trusted) but
|
||||
// protects the host process if the user points the DLL at a
|
||||
// corrupt or wrong ROM file, so a bad file hangs speech instead of
|
||||
// hanging VCC.
|
||||
int safety = 4096;
|
||||
|
||||
while (m_filt.rpt <= 0)
|
||||
{
|
||||
if (--safety <= 0) { m_halted = 1; m_pc = 0; m_filt.rpt = 1; SetSby(1); return; }
|
||||
|
||||
if (m_halted && !m_lrq)
|
||||
{
|
||||
m_pc = m_ald | (0x1000 << 3);
|
||||
m_fifo_sel = 0;
|
||||
m_halted = 0;
|
||||
m_lrq = 1;
|
||||
m_ald = 0;
|
||||
for (i = 0; i < 16; i++) m_filt.r[i] = 0;
|
||||
if (DataRequestChanged) DataRequestChanged(true);
|
||||
}
|
||||
|
||||
if (m_halted)
|
||||
{
|
||||
m_filt.rpt = 1;
|
||||
m_lrq = 1;
|
||||
m_ald = 0;
|
||||
for (i = 0; i < 16; i++) m_filt.r[i] = 0;
|
||||
SetSby(1);
|
||||
return;
|
||||
}
|
||||
|
||||
immed4 = uint8_t(Getb(4));
|
||||
opcode = uint8_t(Getb(4));
|
||||
repeat = 0;
|
||||
ctrl_xfer = 0;
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case 0x0:
|
||||
{
|
||||
if (immed4)
|
||||
{
|
||||
m_page = bitrev32(immed4) >> 13;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t btrg = uint32_t(m_stack);
|
||||
m_stack = 0;
|
||||
if (!btrg) { m_halted = 1; m_pc = 0; ctrl_xfer = 1; }
|
||||
else { m_pc = int(btrg); ctrl_xfer = 1; }
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 0xE:
|
||||
case 0xD:
|
||||
{
|
||||
uint32_t btrg = m_page | (bitrev32(immed4) >> 17) | (bitrev32(Getb(8)) >> 21);
|
||||
ctrl_xfer = 1;
|
||||
if (opcode == 0xD) m_stack = (m_pc + 7) & ~7;
|
||||
m_pc = int(btrg);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x1:
|
||||
{
|
||||
m_mode = uint32_t(((immed4 & 8) >> 2) | (immed4 & 4) | ((immed4 & 3) << 4));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
repeat = immed4 | (m_mode & 0x30);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (opcode != 1) m_mode &= 0xF;
|
||||
|
||||
if (ctrl_xfer)
|
||||
{
|
||||
m_fifo_sel = (m_pc == kFifoAddr) ? 1 : 0;
|
||||
if (m_fifo_sel && m_fifo_bitp)
|
||||
{
|
||||
if (m_fifo_tail < m_fifo_head) m_fifo_tail++;
|
||||
m_fifo_bitp = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!repeat) continue;
|
||||
|
||||
m_filt.rpt = repeat + 1;
|
||||
|
||||
i = (opcode << 3) | int(m_mode & 6);
|
||||
idx0 = sp0256_df_idx[i++];
|
||||
idx1 = sp0256_df_idx[i];
|
||||
|
||||
for (i = idx0; i <= idx1; i++)
|
||||
{
|
||||
int len, shf, delta, field, prm, clra, clr5;
|
||||
int8_t value;
|
||||
|
||||
cr = sp0256_datafmt[i];
|
||||
len = CR_LEN(cr);
|
||||
shf = CR_SHF(cr);
|
||||
prm = CR_PRM(cr);
|
||||
clra = cr & CR_CLRA;
|
||||
clr5 = cr & CR_CLR5;
|
||||
delta = cr & CR_DELTA;
|
||||
field = cr & CR_FIELD;
|
||||
value = 0;
|
||||
|
||||
if (clra)
|
||||
{
|
||||
for (int j = 0; j < 16; j++) m_filt.r[j] = 0;
|
||||
m_silent = 1;
|
||||
}
|
||||
if (clr5) m_filt.r[B5] = m_filt.r[F5] = 0;
|
||||
|
||||
if (len)
|
||||
{
|
||||
value = int8_t(Getb(len));
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (delta)
|
||||
{
|
||||
if (value & (1 << (len - 1))) value = int8_t(unsigned(value) | (~0u << len));
|
||||
}
|
||||
if (shf) value = int8_t(value << shf);
|
||||
|
||||
m_silent = 0;
|
||||
|
||||
if (field)
|
||||
{
|
||||
m_filt.r[prm] &= uint8_t(~(~0u << shf));
|
||||
m_filt.r[prm] |= uint8_t(value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (delta)
|
||||
{
|
||||
m_filt.r[prm] = uint8_t(m_filt.r[prm] + value);
|
||||
continue;
|
||||
}
|
||||
|
||||
m_filt.r[prm] = uint8_t(value);
|
||||
}
|
||||
|
||||
if (opcode == 0xF)
|
||||
{
|
||||
m_silent = 1;
|
||||
m_filt.r[1] = kPerPause;
|
||||
}
|
||||
|
||||
m_filt.Regdec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Sp0256::Ald(uint8_t data)
|
||||
{
|
||||
if (!m_lrq) return; // busy, drop write (matches real chip behavior)
|
||||
|
||||
m_lrq = 0;
|
||||
m_ald = int(data) << 4;
|
||||
if (DataRequestChanged) DataRequestChanged(false);
|
||||
SetSby(0);
|
||||
}
|
||||
|
||||
void Sp0256::GenerateSamples(int16_t* out, int count)
|
||||
{
|
||||
// The internal scratch ring buffer is kScbufSize samples. A single
|
||||
// request for >= that many samples can make the head pointer wrap
|
||||
// all the way back onto the tail pointer, which makes a full buffer
|
||||
// indistinguishable from an empty one and hangs the drain loop below
|
||||
// (this edge case exists in the original hardware-accurate algorithm
|
||||
// too, it's just never exercised there because callers only ever ask
|
||||
// for small audio-callback-sized chunks). Chunk any larger request
|
||||
// so that invariant is never violated.
|
||||
constexpr int kMaxChunk = kScbufSize / 2;
|
||||
while (count > kMaxChunk) {
|
||||
GenerateSamples(out, kMaxChunk);
|
||||
out += kMaxChunk;
|
||||
count -= kMaxChunk;
|
||||
}
|
||||
|
||||
int output_index = 0;
|
||||
|
||||
while (output_index < count)
|
||||
{
|
||||
while (m_sc_tail != m_sc_head)
|
||||
{
|
||||
out[output_index++] = m_scratch[m_sc_tail++ & kScbufMask];
|
||||
// m_sc_tail must be wrapped back into the ring buffer's index
|
||||
// range immediately, exactly like MAME's own drain loop does
|
||||
// (`m_sc_tail &= SCBUF_MASK;` right here) -- m_sc_head is
|
||||
// masked after every write in the block below, so leaving
|
||||
// m_sc_tail unmasked lets it grow past m_sc_head's wrapped
|
||||
// value the first time total output crosses a kScbufSize
|
||||
// (4096-sample) boundary. From that point on `m_sc_tail !=
|
||||
// m_sc_head` is permanently (falsely) true -- this loop keeps
|
||||
// "draining" stale/stale-wrapped scratch contents forever and
|
||||
// Micro()/Update() are never invoked again, silently freezing
|
||||
// all further speech a fraction of a second after the chip
|
||||
// starts ticking (this was the root cause of "cartridge loads
|
||||
// and commands reach the firmware, but no sound ever plays").
|
||||
m_sc_tail &= kScbufMask;
|
||||
if (output_index >= count) break;
|
||||
}
|
||||
if (output_index >= count) break;
|
||||
|
||||
int length = count - output_index;
|
||||
int did_samp = 0;
|
||||
if (length > 0) do
|
||||
{
|
||||
if (m_filt.rpt <= 0) Micro();
|
||||
|
||||
int do_samp = length - did_samp;
|
||||
if (int(m_sc_head + do_samp - m_sc_tail) > kScbufSize)
|
||||
do_samp = int(m_sc_tail + kScbufSize - m_sc_head);
|
||||
|
||||
if (do_samp == 0) break;
|
||||
|
||||
if (m_silent && m_filt.rpt <= 0)
|
||||
{
|
||||
uint32_t y = m_sc_head;
|
||||
for (int x = 0; x < do_samp; x++) m_scratch[y++ & kScbufMask] = 0;
|
||||
m_sc_head += do_samp;
|
||||
did_samp += do_samp;
|
||||
}
|
||||
else
|
||||
{
|
||||
did_samp += m_filt.Update(do_samp, m_scratch.get(), &m_sc_head);
|
||||
}
|
||||
m_sc_head &= kScbufMask;
|
||||
|
||||
} while (m_filt.rpt >= 0 && length > did_samp);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,116 @@
|
||||
// sp0256.h
|
||||
//
|
||||
// Standalone, portable emulation of the General Instrument SP0256-AL2
|
||||
// Narrator Speech Processor, adapted for use inside a Tandy Speech/Sound
|
||||
// Cartridge (SSC) emulation for VCC.
|
||||
//
|
||||
// This is a from-source port of the LPC-12 filter, microsequencer and
|
||||
// allophone data-format tables from MAME's src/devices/sound/sp0256.cpp /
|
||||
// sp0256.h (license: BSD-3-Clause, copyright Joseph Zbiciak, Tim Lindner,
|
||||
// originally written by Joe Zbiciak). The MAME device_sound_interface /
|
||||
// sound_stream / device_t framework has been replaced with a simple
|
||||
// pull-based sample generator so the core can run standalone inside a
|
||||
// Windows DLL. The DSP algorithm, quantization table, opcode data-format
|
||||
// tables and microsequencer logic are preserved unchanged from the
|
||||
// original.
|
||||
//
|
||||
// The chip requires its own 2KB internal mask ROM image (sp0256-al2.bin,
|
||||
// CRC32 b504ac15) to be supplied by the caller at runtime -- this code
|
||||
// does not embed or distribute that ROM. It is placed at byte offset
|
||||
// $1000 within a 64KB address window, matching the physical chip's
|
||||
// internal addressing and matching how MAME's coco_ssc.cpp loads it
|
||||
// (ROM_LOAD("sp0256-al2.bin", 0x1000, 0x0800, ...)).
|
||||
//
|
||||
// license:BSD-3-Clause
|
||||
// Original copyright-holders: Joseph Zbiciak, Tim Lindner (MAME sp0256 core)
|
||||
// Port for VCC SSC cartridge: 2026
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace ssc {
|
||||
|
||||
class Sp0256 {
|
||||
public:
|
||||
Sp0256();
|
||||
|
||||
// Load the 2KB SP0256-AL2 mask ROM dump at its native offset ($1000)
|
||||
// within the chip's 64KB address window.
|
||||
void LoadRom(const uint8_t* al2_2k, size_t len);
|
||||
|
||||
// Notified when the chip's DRQ ("ready for next command") state
|
||||
// changes: true = ready to accept an ALD write (used to drive the
|
||||
// TMS7040's INT1 line in the SSC).
|
||||
std::function<void(bool ready)> DataRequestChanged;
|
||||
|
||||
void Reset();
|
||||
|
||||
// ALD (Address LoaD): write an allophone/command byte (6 bits used).
|
||||
void Ald(uint8_t data);
|
||||
|
||||
// True while the chip is speaking (not on standby).
|
||||
bool Standby() const { return m_sby_line != 0; }
|
||||
|
||||
// Generates `count` mono samples at the chip's native output rate
|
||||
// (clock/CLOCK_DIVIDER, ~10.02kHz at the standard 3.12MHz clock) into
|
||||
// `out`, running the microsequencer as needed. Samples are signed
|
||||
// 16-bit PCM.
|
||||
void GenerateSamples(int16_t* out, int count);
|
||||
|
||||
// Native output sample rate for a given input clock, matching the
|
||||
// original CLOCK_DIVIDER constant.
|
||||
static int SampleRateForClock(int clock_hz) { return clock_hz / kClockDivider; }
|
||||
|
||||
private:
|
||||
static constexpr int kClockDivider = 6 * 4 * 13;
|
||||
static constexpr int kScbufSize = 4096;
|
||||
static constexpr int kScbufMask = kScbufSize - 1;
|
||||
static constexpr int kPerPause = 64;
|
||||
static constexpr int kPerNoise = 64;
|
||||
static constexpr int kFifoAddr = (0x1800 << 3);
|
||||
|
||||
struct Lpc12 {
|
||||
int rpt = 0, cnt = 0;
|
||||
uint32_t per = 0, rng = 1;
|
||||
int amp = 0;
|
||||
int16_t f_coef[6] = {0};
|
||||
int16_t b_coef[6] = {0};
|
||||
int16_t z_data[6][2] = {{0}};
|
||||
uint8_t r[16] = {0};
|
||||
int interp = 0;
|
||||
|
||||
int Update(int num_samp, int16_t* out, uint32_t* optr);
|
||||
void Regdec();
|
||||
static int16_t Limit(int16_t s);
|
||||
};
|
||||
|
||||
std::unique_ptr<uint8_t[]> m_rom; // 64KB window
|
||||
Lpc12 m_filt;
|
||||
|
||||
int m_sby_line = 1;
|
||||
bool m_silent = 1;
|
||||
|
||||
std::unique_ptr<int16_t[]> m_scratch;
|
||||
uint32_t m_sc_head = 0, m_sc_tail = 0;
|
||||
|
||||
int m_lrq = 1;
|
||||
int m_ald = 0;
|
||||
int m_pc = 0;
|
||||
int m_stack = 0;
|
||||
int m_fifo_sel = 0;
|
||||
int m_halted = 1;
|
||||
uint32_t m_mode = 0;
|
||||
uint32_t m_page = 0x1000 << 3;
|
||||
|
||||
uint32_t m_fifo_head = 0, m_fifo_tail = 0, m_fifo_bitp = 0;
|
||||
uint16_t m_fifo[64] = {0};
|
||||
|
||||
void SetSby(int line_state);
|
||||
uint32_t Getb(int len);
|
||||
void Micro();
|
||||
};
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,275 @@
|
||||
// ssc_core.cpp -- see ssc_core.h for design notes and provenance.
|
||||
|
||||
#include "ssc_core.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace ssc {
|
||||
|
||||
// Port C bit assignments, ported from MAME's coco_ssc.cpp.
|
||||
// (A8/A9/A10 -- the RAM address extension bits -- share their bit
|
||||
// positions with BC1/BDIR/CS below; they aren't named separately here
|
||||
// because the RAM address is always derived from the whole port C byte
|
||||
// masked to 11 bits, matching the original's address computation.)
|
||||
static constexpr uint8_t C_BC1 = 0x01;
|
||||
static constexpr uint8_t C_RRW = 0x08;
|
||||
static constexpr uint8_t C_BDR = 0x08;
|
||||
static constexpr uint8_t C_RCS = 0x10;
|
||||
static constexpr uint8_t C_ALD = 0x20;
|
||||
static constexpr uint8_t C_ACS = 0x40;
|
||||
static constexpr uint8_t C_BSY = 0x80;
|
||||
|
||||
// See SetTickRateHz() / m_tick_hz in ssc_core.h for why this is a runtime
|
||||
// value (default 44100Hz) rather than a compile-time scanline-rate
|
||||
// constant -- it's driven by how often the host ABI actually calls Tick().
|
||||
static constexpr double kTmsInputClockHz = 1789772.0; // CoCo E-clock (~894886Hz) doubled on-cartridge
|
||||
static constexpr double kSpoClockHz = 3120000.0; // SP0256's own ceramic-resonator clock
|
||||
static const double kSpoSampleRate = Sp0256::SampleRateForClock(int(kSpoClockHz)); // 10000Hz
|
||||
|
||||
// SAC (Sound Activity Circuit) constants, ported from cocossc_sac_device
|
||||
static constexpr float kSacHpfAlpha = 0.99f;
|
||||
static constexpr float kSacAttackCoeff = 0.0026f;
|
||||
static constexpr float kSacDecayCoeff = 0.0003f;
|
||||
static constexpr float kSacThreshOn = 0.05f;
|
||||
static constexpr float kSacThreshOff = 0.01f;
|
||||
|
||||
static constexpr float kSp0256Gain = 1.75f;
|
||||
static constexpr float kAy8913Gain = 2.0f;
|
||||
|
||||
SscCore::SscCore()
|
||||
{
|
||||
m_cpu.InPortA = [this]() { return OnPortARead(); };
|
||||
m_cpu.OutPortB = [this](uint8_t d) { OnPortBWrite(d); };
|
||||
m_cpu.InPortC = [this]() { return OnPortCRead(); };
|
||||
m_cpu.OutPortC = [this](uint8_t d) { OnPortCWrite(d); };
|
||||
m_cpu.InPortD = [this]() { return OnPortDRead(); };
|
||||
m_cpu.OutPortD = [this](uint8_t d) { OnPortDWrite(d); };
|
||||
|
||||
m_spo.DataRequestChanged = [this](bool ready) { OnSpeechDrqChanged(ready); };
|
||||
|
||||
m_ay.SetClock(kTmsInputClockHz); // AY is clocked from the same doubled-E line as the PIC
|
||||
}
|
||||
|
||||
bool SscCore::LoadPicRom(const uint8_t* data, size_t len)
|
||||
{
|
||||
m_cpu.LoadRom(data, len);
|
||||
m_pic_rom_loaded = (len == 4096);
|
||||
return m_pic_rom_loaded;
|
||||
}
|
||||
|
||||
bool SscCore::LoadSpeechRom(const uint8_t* data, size_t len)
|
||||
{
|
||||
m_spo.LoadRom(data, len);
|
||||
m_speech_rom_loaded = (len == 0x800);
|
||||
return m_speech_rom_loaded;
|
||||
}
|
||||
|
||||
void SscCore::Reset()
|
||||
{
|
||||
m_reset_line = 1;
|
||||
m_tms_busy = false;
|
||||
m_porta_latch = 0;
|
||||
m_portb_latch = 0;
|
||||
m_portc_latch = 0xff;
|
||||
m_portd_latch = 0;
|
||||
m_cpu_cycle_accum = 0.0;
|
||||
m_spo_sample_accum = 0.0;
|
||||
m_last_spo_sample = 0;
|
||||
m_latched_sample = 128;
|
||||
m_sac_hpf_prev_in = m_sac_hpf_prev_out = m_sac_envelope = 0.0f;
|
||||
m_sac_active = false;
|
||||
std::memset(m_staticram, 0, sizeof(m_staticram));
|
||||
|
||||
m_cpu.Reset();
|
||||
m_ay.Reset();
|
||||
m_spo.Reset();
|
||||
}
|
||||
|
||||
uint8_t SscCore::ReadPort(uint8_t port)
|
||||
{
|
||||
switch (port)
|
||||
{
|
||||
case 0x7d:
|
||||
return 0xff;
|
||||
|
||||
case 0x7e:
|
||||
{
|
||||
uint8_t data = 0x1f;
|
||||
if (!m_tms_busy) data |= 0x80;
|
||||
if (m_spo.Standby()) data |= 0x40;
|
||||
if (m_sac_active == false) data |= 0x20; // bit set = "not currently making sound"
|
||||
return data;
|
||||
}
|
||||
|
||||
// Any port that isn't ours must return 0, not 0xff. VCC's MPI
|
||||
// arbitrates PackPortRead() across all four slots by taking the
|
||||
// first NON-ZERO response from any loaded cartridge (mirroring
|
||||
// real open-collector bus behavior, where a device that isn't
|
||||
// being addressed stays silent rather than driving the bus).
|
||||
// Returning 0xff here for ports we don't own -- e.g. the FD-502
|
||||
// disk controller's own I/O ports -- would hijack every other
|
||||
// cartridge's port reads out from under it the moment this
|
||||
// cartridge is inserted, corrupting status bytes read from
|
||||
// unrelated hardware (this was reported as a spurious "?WP
|
||||
// ERROR" from DECB's DIR command while this cartridge was
|
||||
// plugged into an MPI slot alongside a disk controller).
|
||||
default:
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
void SscCore::WritePort(uint8_t port, uint8_t data)
|
||||
{
|
||||
switch (port)
|
||||
{
|
||||
case 0x7d:
|
||||
if (data & 1) m_spo.Reset();
|
||||
if (((m_reset_line & 1) == 1) && ((data & 1) == 0)) {
|
||||
m_cpu.Reset();
|
||||
m_ay.Reset();
|
||||
m_tms_busy = false;
|
||||
}
|
||||
m_reset_line = data;
|
||||
break;
|
||||
|
||||
case 0x7e:
|
||||
m_porta_latch = data;
|
||||
m_tms_busy = true;
|
||||
m_command_count++;
|
||||
m_cpu.SetIrqLine(Tms7000Irq::Int3, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SscCore::OnPortARead()
|
||||
{
|
||||
uint8_t v = m_porta_latch;
|
||||
m_cpu.SetIrqLine(Tms7000Irq::Int3, false);
|
||||
return v;
|
||||
}
|
||||
|
||||
void SscCore::OnPortBWrite(uint8_t data)
|
||||
{
|
||||
m_portb_latch = data;
|
||||
}
|
||||
|
||||
uint8_t SscCore::OnPortCRead()
|
||||
{
|
||||
return m_portc_latch;
|
||||
}
|
||||
|
||||
void SscCore::OnPortCWrite(uint8_t data)
|
||||
{
|
||||
if ((data & C_RCS) == 0 && (data & C_RRW) == 0) // static RAM write
|
||||
{
|
||||
uint16_t address = uint16_t((uint16_t(data) << 8) | m_portb_latch) & 0x7ff;
|
||||
m_staticram[address] = m_portd_latch;
|
||||
}
|
||||
|
||||
if ((data & C_ACS) == 0) // AY chip selected
|
||||
{
|
||||
if ((data & (C_BDR | C_BC1)) == (C_BDR | C_BC1)) // BDIR=1, BC1=1: latch address
|
||||
m_ay.SelectRegister(m_portd_latch);
|
||||
|
||||
if (((data & C_BDR) == C_BDR) && ((data & C_BC1) == 0)) { // BDIR=1, BC1=0: write data
|
||||
m_ay.WriteData(m_portd_latch);
|
||||
m_ay_write_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (((m_portc_latch & C_ALD) == C_ALD) && ((data & C_ALD) == 0) && (m_portd_latch < 64)) {
|
||||
m_spo.Ald(m_portd_latch); // ALD strobe (falling edge)
|
||||
m_ald_count++;
|
||||
// Codes 0-4 are the standard SP0256-AL2 pause variants (PA1-PA5)
|
||||
// -- legitimately silent, and the firmware appears to re-strobe
|
||||
// one of these continuously as part of its own idle-loop
|
||||
// housekeeping (confirmed: AldCount() climbs at thousands/sec
|
||||
// even with zero host commands, same as AyWriteCount()). Track
|
||||
// strobes of a genuine speech code (5-63) separately so this
|
||||
// stops being a false-positive "is it really talking" signal.
|
||||
if (m_portd_latch >= 5) m_ald_speech_count++;
|
||||
}
|
||||
|
||||
if (((m_portc_latch & C_BSY) == 0) && ((data & C_BSY) == C_BSY))
|
||||
m_tms_busy = false; // BSY handshake released (rising edge)
|
||||
|
||||
m_portc_latch = data;
|
||||
}
|
||||
|
||||
uint8_t SscCore::OnPortDRead()
|
||||
{
|
||||
if (((m_portc_latch & C_RCS) == 0) && ((m_portc_latch & C_RRW) == C_RRW))
|
||||
{
|
||||
uint16_t address = uint16_t((uint16_t(m_portc_latch) << 8) | m_portb_latch) & 0x7ff;
|
||||
m_portd_latch = m_staticram[address];
|
||||
}
|
||||
|
||||
if ((m_portc_latch & C_ACS) == 0)
|
||||
{
|
||||
if (((m_portc_latch & C_BDR) == 0) && ((m_portc_latch & C_BC1) == C_BC1))
|
||||
m_portd_latch = m_ay.ReadData();
|
||||
}
|
||||
|
||||
return m_portd_latch;
|
||||
}
|
||||
|
||||
void SscCore::OnPortDWrite(uint8_t data)
|
||||
{
|
||||
m_portd_latch = data;
|
||||
}
|
||||
|
||||
void SscCore::OnSpeechDrqChanged(bool ready)
|
||||
{
|
||||
m_cpu.SetIrqLine(Tms7000Irq::Int1, ready);
|
||||
}
|
||||
|
||||
bool SscCore::SoundActivityOutput(float x)
|
||||
{
|
||||
// High-pass filter to remove DC offset, then an asymmetric-attack/
|
||||
// decay envelope follower with hysteresis -- ported directly from
|
||||
// cocossc_sac_device::sound_stream_update / sound_activity_circuit_output.
|
||||
float y = kSacHpfAlpha * (m_sac_hpf_prev_out + x - m_sac_hpf_prev_in);
|
||||
m_sac_hpf_prev_in = x;
|
||||
m_sac_hpf_prev_out = y;
|
||||
|
||||
float rect = std::fabs(y);
|
||||
if (rect > m_sac_envelope) m_sac_envelope += (rect - m_sac_envelope) * kSacAttackCoeff;
|
||||
else m_sac_envelope += (rect - m_sac_envelope) * kSacDecayCoeff;
|
||||
|
||||
if (m_sac_active && m_sac_envelope < kSacThreshOff) m_sac_active = false;
|
||||
else if (m_sac_envelope > kSacThreshOn) m_sac_active = true;
|
||||
|
||||
return m_sac_active;
|
||||
}
|
||||
|
||||
void SscCore::Tick()
|
||||
{
|
||||
// --- advance the PIC7040 ---
|
||||
m_cpu_cycle_accum += (kTmsInputClockHz / 2.0) / m_tick_hz;
|
||||
int cpu_cycles = int(m_cpu_cycle_accum);
|
||||
m_cpu_cycle_accum -= cpu_cycles;
|
||||
if (cpu_cycles > 0) m_cpu.Execute(cpu_cycles);
|
||||
|
||||
// --- advance the AY-3-8913 ---
|
||||
int16_t ay_sample = m_ay.Render(1.0 / m_tick_hz);
|
||||
|
||||
// --- advance the SP0256 (its own, independent, ~10kHz clock) ---
|
||||
m_spo_sample_accum += kSpoSampleRate / m_tick_hz;
|
||||
while (m_spo_sample_accum >= 1.0) {
|
||||
m_spo.GenerateSamples(&m_last_spo_sample, 1);
|
||||
m_spo_sample_accum -= 1.0;
|
||||
}
|
||||
|
||||
// --- Sound Activity Circuit status (feeds the $FF7E status bit) ---
|
||||
SoundActivityOutput(ay_sample / 32768.0f);
|
||||
|
||||
// --- mix and latch the output sample as an unsigned DAC-style byte ---
|
||||
float mix = (ay_sample / 32768.0f) * kAy8913Gain + (m_last_spo_sample / 32768.0f) * kSp0256Gain;
|
||||
mix = std::max(-1.0f, std::min(1.0f, mix));
|
||||
m_latched_sample = uint8_t(std::lround(mix * 127.0f) + 128);
|
||||
}
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,164 @@
|
||||
// ssc_core.h
|
||||
//
|
||||
// Top-level glue for the Tandy Speech/Sound Cartridge emulation: wires
|
||||
// together the TMS7040 (PIC7040) microcontroller, the AY-3-8913 PSG, the
|
||||
// SP0256-AL2 speech chip and 2KB of static RAM exactly as the real
|
||||
// hardware -- and MAME's coco_ssc.cpp reference model -- connect them:
|
||||
//
|
||||
// Port A: host -> chip command byte (from CoCo $FF7E write)
|
||||
// Port B: RAM address bits A0-A7
|
||||
// Port C: bus controller (RAM A8-A10/R-W/CS, AY BC1/BDIR/CS, SP0256
|
||||
// ALD strobe, BUSY handshake line back to the host)
|
||||
// Port D: 8-bit data bus shared by RAM, the AY, and port-C latch data
|
||||
//
|
||||
// This class is framework-agnostic (no VCC/Windows types) so it can be
|
||||
// unit-tested standalone; ssc_dll.cpp adapts it to VCC's cpak DLL ABI.
|
||||
//
|
||||
// Provenance: the port/bit wiring is a port of the logic in MAME's
|
||||
// src/devices/bus/coco/coco_ssc.cpp (license: BSD-3-Clause, copyright
|
||||
// tim lindner).
|
||||
//
|
||||
// license:BSD-3-Clause / port for VCC SSC cartridge: 2026
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "tms7000.h"
|
||||
#include "ay8913.h"
|
||||
#include "sp0256.h"
|
||||
|
||||
namespace ssc {
|
||||
|
||||
class SscCore {
|
||||
public:
|
||||
SscCore();
|
||||
|
||||
// ROM images: pic-7040-510.bin (4096 bytes) and sp0256-al2.bin
|
||||
// (2048 bytes). Returns false if a buffer is the wrong size (still
|
||||
// loads what it can -- see LoadRoms in ssc_core.cpp).
|
||||
bool LoadPicRom(const uint8_t* data, size_t len);
|
||||
bool LoadSpeechRom(const uint8_t* data, size_t len);
|
||||
bool RomsLoaded() const { return m_pic_rom_loaded && m_speech_rom_loaded; }
|
||||
|
||||
void Reset();
|
||||
|
||||
// CoCo-side I/O, matching coco_ssc.cpp's ff7d_read/ff7d_write:
|
||||
// port 0x7D: control/reset
|
||||
// port 0x7E: command byte / status
|
||||
uint8_t ReadPort(uint8_t port);
|
||||
void WritePort(uint8_t port, uint8_t data);
|
||||
|
||||
// Advance emulation by exactly one Tick()-call's worth of real
|
||||
// elapsed time and latch a new output audio sample. IMPORTANT: how
|
||||
// much real time that is depends entirely on how often the *host*
|
||||
// actually calls Tick(), which is a per-ABI-generation detail, not
|
||||
// a universal constant -- see SetTickRateHz() below. Defaults to
|
||||
// 44100Hz (one call per audio sample), which is what real VCC does
|
||||
// for the classic ModuleAudioSample() pak ABI (confirmed directly
|
||||
// against VCC's own source, both current main and the vcc-2.1.9.1
|
||||
// tag: audio.cpp's AudioOut()/GetDACSample() pulls the cartridge's
|
||||
// audio export at a real, wall-clock-accurate 44100Hz with no
|
||||
// batching in between -- NOT the ~15720Hz video scanline rate an
|
||||
// earlier version of this code assumed here).
|
||||
void Tick();
|
||||
|
||||
// Overrides the real-world rate (in Hz) that one Tick() call is
|
||||
// assumed to represent. Only needed if your VCC generation's pak
|
||||
// ABI ticks this differently than the 44100Hz default above -- e.g.
|
||||
// the newer "cpak" ABI's PakProcessHorizontalSync callback really
|
||||
// does appear to fire at the classic ~15720Hz CoCo scanline rate
|
||||
// (per an embedded comment in VCCE/VCC's own current orch90.cpp:
|
||||
// "called every scan line 262 Lines * 60 Frames = 15780 Hz 15720"),
|
||||
// which is a genuinely different cadence than the old ABI's
|
||||
// 44100Hz audio-sample pull -- see ssc_dll.cpp.
|
||||
void SetTickRateHz(double hz) { m_tick_hz = hz; }
|
||||
double TickRateHz() const { return m_tick_hz; }
|
||||
|
||||
// Returns the most recently latched output sample as an unsigned
|
||||
// 8-bit DAC-style code (0-255, ~128 = silence) -- the same
|
||||
// convention VCC's other sound paks (e.g. Orchestra-90) use for
|
||||
// PakSampleAudio(), so ssc_dll.cpp can pack it straight into both
|
||||
// channels of the returned unsigned short.
|
||||
uint8_t LatchedSample() const { return m_latched_sample; }
|
||||
|
||||
// Debug/introspection, mainly for real-ROM validation and bug
|
||||
// reports -- not used by ssc_dll.cpp in normal operation.
|
||||
uint16_t CpuPc() const { return m_cpu.PC(); }
|
||||
uint32_t CpuIllegalCount() const { return m_cpu.IllegalCount(); }
|
||||
uint32_t AyWriteCount() const { return m_ay_write_count; }
|
||||
uint32_t AldCount() const { return m_ald_count; }
|
||||
// Subset of AldCount() where the strobed code was a genuine
|
||||
// phoneme (5-63), not one of the PA1-PA5 pause variants (0-4) the
|
||||
// firmware appears to spam continuously on its own as idle-loop
|
||||
// housekeeping. Unlike AldCount(), this stays at 0 unless the
|
||||
// firmware is actually asking the SP0256 to say a real sound.
|
||||
uint32_t AldSpeechCount() const { return m_ald_speech_count; }
|
||||
bool Busy() const { return m_tms_busy; }
|
||||
// Count of command bytes the HOST has written to $FF7E since reset.
|
||||
// Unlike AyWriteCount()/AldCount() (which climb on their own from
|
||||
// the firmware's internal idle-loop bus chatter, even with zero
|
||||
// host commands), this increments ONLY on a genuine write from the
|
||||
// CoCo side -- the cleanest available signal for "is the program
|
||||
// actually talking to this cartridge".
|
||||
uint32_t CommandCount() const { return m_command_count; }
|
||||
|
||||
private:
|
||||
Tms7000 m_cpu;
|
||||
Ay8913 m_ay;
|
||||
Sp0256 m_spo;
|
||||
uint8_t m_staticram[2048] = {0};
|
||||
|
||||
bool m_pic_rom_loaded = false;
|
||||
bool m_speech_rom_loaded = false;
|
||||
|
||||
// $FF7D/$FF7E glue state (mirrors coco_ssc_device's members)
|
||||
uint8_t m_reset_line = 1;
|
||||
bool m_tms_busy = false;
|
||||
uint8_t m_porta_latch = 0;
|
||||
|
||||
// last value driven on ports B/C/D, needed for edge detection and
|
||||
// for combinational read-back (port B/D are also readable)
|
||||
uint8_t m_portb_latch = 0;
|
||||
uint8_t m_portc_latch = 0xff;
|
||||
uint8_t m_portd_latch = 0;
|
||||
|
||||
// Sound Activity Circuit (SAC): a simple envelope-follower + high
|
||||
// pass filter on the AY's output, used only to derive the $FF7E
|
||||
// "sound active" status bit -- ported from cocossc_sac_device.
|
||||
float m_sac_hpf_prev_in = 0.0f;
|
||||
float m_sac_hpf_prev_out = 0.0f;
|
||||
float m_sac_envelope = 0.0f;
|
||||
bool m_sac_active = false;
|
||||
|
||||
uint8_t m_latched_sample = 128;
|
||||
|
||||
// diagnostic counters (see AyWriteCount()/AldCount() above)
|
||||
uint32_t m_ay_write_count = 0;
|
||||
uint32_t m_ald_count = 0;
|
||||
uint32_t m_ald_speech_count = 0;
|
||||
uint32_t m_command_count = 0;
|
||||
|
||||
// fractional accumulators for cross-clock-domain ticking
|
||||
double m_cpu_cycle_accum = 0.0;
|
||||
double m_spo_sample_accum = 0.0;
|
||||
|
||||
// see SetTickRateHz() above
|
||||
double m_tick_hz = 44100.0;
|
||||
int16_t m_last_spo_sample = 0;
|
||||
|
||||
// port callbacks wired to m_cpu
|
||||
uint8_t OnPortARead();
|
||||
void OnPortBWrite(uint8_t data);
|
||||
uint8_t OnPortCRead();
|
||||
void OnPortCWrite(uint8_t data);
|
||||
uint8_t OnPortDRead();
|
||||
void OnPortDWrite(uint8_t data);
|
||||
|
||||
void OnSpeechDrqChanged(bool ready);
|
||||
|
||||
bool SoundActivityOutput(float ay_sample_normalized);
|
||||
};
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,94 @@
|
||||
// Functional test for the AY-3-8913 core: program channel A with a known
|
||||
// tone period, render audio, and verify the measured frequency (by
|
||||
// counting zero-crossings) matches the datasheet formula
|
||||
// f = clock / (16 * TP).
|
||||
#include "../ay8913.h"
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
using namespace ssc;
|
||||
|
||||
static double MeasureFrequency(Ay8913& ay, double sample_rate, int nsamples)
|
||||
{
|
||||
std::vector<int16_t> buf(nsamples);
|
||||
for (int i = 0; i < nsamples; i++)
|
||||
buf[i] = ay.Render(1.0 / sample_rate);
|
||||
|
||||
// The AY's tone output is a unipolar square wave (0 or +vol), not a
|
||||
// bipolar one, so measure by counting level *transitions* rather
|
||||
// than zero crossings.
|
||||
int transitions = 0;
|
||||
for (int i = 1; i < nsamples; i++)
|
||||
if (buf[i - 1] != buf[i]) transitions++;
|
||||
|
||||
double seconds = nsamples / sample_rate;
|
||||
// Each full cycle produces 2 transitions (low->high, high->low).
|
||||
return (transitions / 2.0) / seconds;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const double clock_hz = 1789772.0; // doubled CoCo E-clock, as the SSC uses
|
||||
|
||||
// Test a few tone periods across the range.
|
||||
int periods[] = { 100, 255, 512, 1000 };
|
||||
bool all_ok = true;
|
||||
|
||||
for (int tp : periods) {
|
||||
Ay8913 ay;
|
||||
ay.SetClock(clock_hz);
|
||||
ay.SelectRegister(0); ay.WriteData(uint8_t(tp & 0xff)); // tone A fine
|
||||
ay.SelectRegister(1); ay.WriteData(uint8_t((tp >> 8) & 0x0f)); // tone A coarse
|
||||
ay.SelectRegister(8); ay.WriteData(0x0f); // channel A full volume, no envelope
|
||||
ay.SelectRegister(7); ay.WriteData(0b111110); // tone A enabled, others disabled (active-low bits)
|
||||
|
||||
double expected = clock_hz / (16.0 * tp);
|
||||
// Sample well above Nyquist for the tone under test so our simple
|
||||
// zero-crossing counter is accurate.
|
||||
double sample_rate = std::max(50000.0, expected * 40.0);
|
||||
double measured = MeasureFrequency(ay, sample_rate, int(sample_rate * 0.2));
|
||||
|
||||
double err_pct = std::fabs(measured - expected) / expected * 100.0;
|
||||
std::printf("TP=%4d expected=%8.2fHz measured=%8.2fHz err=%.2f%%\n",
|
||||
tp, expected, measured, err_pct);
|
||||
|
||||
if (err_pct > 2.0) all_ok = false;
|
||||
}
|
||||
|
||||
// Sanity: mixer disabled AND amplitude 0 should produce true silence.
|
||||
{
|
||||
Ay8913 ay;
|
||||
ay.SetClock(clock_hz);
|
||||
ay.SelectRegister(0); ay.WriteData(50);
|
||||
ay.SelectRegister(8); ay.WriteData(0x00); // amplitude 0
|
||||
ay.SelectRegister(7); ay.WriteData(0xff); // everything disabled
|
||||
bool silent = true;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
if (ay.Render(1.0 / 50000.0) != 0) silent = false;
|
||||
std::printf("amplitude-0 silence check: %s\n", silent ? "PASS" : "FAIL");
|
||||
if (!silent) all_ok = false;
|
||||
}
|
||||
|
||||
// Sanity: full mixer disable with nonzero amplitude should produce a
|
||||
// *constant* (non-oscillating) output -- disabling both tone and
|
||||
// noise for a channel ties that mixer input high, per the real AY's
|
||||
// AND-gate mixer, so the channel still contributes a constant level.
|
||||
{
|
||||
Ay8913 ay;
|
||||
ay.SetClock(clock_hz);
|
||||
ay.SelectRegister(0); ay.WriteData(50);
|
||||
ay.SelectRegister(8); ay.WriteData(0x0f);
|
||||
ay.SelectRegister(7); ay.WriteData(0xff);
|
||||
int16_t first = ay.Render(1.0 / 50000.0);
|
||||
bool constant = true;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
if (ay.Render(1.0 / 50000.0) != first) constant = false;
|
||||
std::printf("mixer-all-off constant-level check: %s\n", constant ? "PASS" : "FAIL");
|
||||
if (!constant) all_ok = false;
|
||||
}
|
||||
|
||||
std::printf(all_ok ? "PASS\n" : "FAIL\n");
|
||||
return all_ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Standalone smoke test for the ported TMS7000 core: hand-assembles a
|
||||
// tiny loop (INC A; JMP back) at the internal ROM's reset vector target
|
||||
// and confirms the CPU fetches the reset vector, runs the loop, and that
|
||||
// register A actually increments and wraps as expected.
|
||||
#include "../tms7000.h"
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
|
||||
using namespace ssc;
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t rom[4096];
|
||||
for (auto& b : rom) b = 0xff; // illegal-opcode filler, should never be hit
|
||||
|
||||
// Program at $F000:
|
||||
// F000: B3 INC A
|
||||
// F001: E0 FD JMP -3 (back to F000)
|
||||
rom[0x000] = 0xB3;
|
||||
rom[0x001] = 0xE0;
|
||||
rom[0x002] = (uint8_t)-3;
|
||||
|
||||
// Reset vector at $FFFE/$FFFF -> $F000 (big-endian).
|
||||
// ROM array covers $F000-$FFFF, so $FFFE -> index $0FFE, $FFFF -> $0FFF.
|
||||
rom[0xFFE] = 0xF0;
|
||||
rom[0xFFF] = 0x00;
|
||||
|
||||
Tms7000 cpu;
|
||||
cpu.LoadRom(rom, sizeof(rom));
|
||||
cpu.Reset();
|
||||
|
||||
if (cpu.PC() != 0xF000) {
|
||||
std::printf("FAIL: reset vector fetch wrong, PC=$%04X (expected $F000)\n", cpu.PC());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Run enough cycles for A to wrap around a few times.
|
||||
// INC A (am_a): 5 icount. JMP taken: 3 + shortbranch(taken: 2+2=4) = 7 icount.
|
||||
// One loop iteration = 12 icount ticks.
|
||||
int total = 0;
|
||||
for (int i = 0; i < 50; i++) {
|
||||
total += cpu.Execute(12 * 30); // 30 loop iterations worth per call
|
||||
}
|
||||
|
||||
uint8_t a = cpu.PeekReg(0);
|
||||
std::printf("OK: PC=$%04X A=$%02X after %d icount ticks\n", cpu.PC(), a, total);
|
||||
|
||||
// A should have wrapped many times; just confirm it's a plausible byte
|
||||
// and that the loop is still executing at F000/F001/F002.
|
||||
assert(cpu.PC() >= 0xF000 && cpu.PC() <= 0xF003);
|
||||
std::printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Smoke test for the ported SP0256 core: without the real AL2 mask ROM
|
||||
// (which we don't distribute) we can't validate actual speech output,
|
||||
// but we can confirm the microsequencer/filter run for an extended
|
||||
// period on arbitrary ROM content without crashing, hanging, or
|
||||
// producing NaN/out-of-range samples, and that ALD triggers activity.
|
||||
#include "../sp0256.h"
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace ssc;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<uint8_t> fakerom(0x800);
|
||||
// Deterministic pseudo-random filler so the microsequencer has
|
||||
// varied (but reproducible) "allophone" data to chew on.
|
||||
unsigned seed = 12345;
|
||||
for (auto& b : fakerom) {
|
||||
seed = seed * 1103515245u + 12345u;
|
||||
b = uint8_t(seed >> 16);
|
||||
}
|
||||
|
||||
Sp0256 chip;
|
||||
chip.LoadRom(fakerom.data(), fakerom.size());
|
||||
chip.Reset();
|
||||
|
||||
bool drq_seen = false;
|
||||
chip.DataRequestChanged = [&](bool ready) { if (ready) drq_seen = true; };
|
||||
|
||||
assert(chip.Standby());
|
||||
|
||||
chip.Ald(0x00); // kick off "allophone 0" from whatever garbage is at page $1000
|
||||
assert(!chip.Standby());
|
||||
|
||||
std::vector<int16_t> buf(4096);
|
||||
long total = 0;
|
||||
for (int block = 0; block < 500; block++) {
|
||||
chip.GenerateSamples(buf.data(), int(buf.size()));
|
||||
for (auto s : buf) {
|
||||
assert(s >= -32768 && s <= 32767); // range sanity
|
||||
}
|
||||
total += long(buf.size());
|
||||
|
||||
// Occasionally feed another command once the chip reports ready,
|
||||
// simulating a host streaming allophones.
|
||||
if (block % 37 == 0) chip.Ald(uint8_t(block & 0x3f));
|
||||
}
|
||||
|
||||
std::printf("OK: generated %ld samples, drq_seen=%d, standby=%d\n",
|
||||
total, drq_seen, chip.Standby());
|
||||
std::printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// End-to-end smoke test for SscCore: without the real PIC7040/SP0256
|
||||
// ROM dumps (not distributed here -- see README.md) this can't validate
|
||||
// actual firmware behavior, but it exercises the full port-glue wiring,
|
||||
// timing accumulators, and audio mixing path against synthetic ROM data
|
||||
// for an extended run to catch crashes, hangs, and out-of-range output.
|
||||
#include "../ssc_core.h"
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
using namespace ssc;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<uint8_t> pic_rom(4096);
|
||||
std::vector<uint8_t> spo_rom(0x800);
|
||||
unsigned seed = 42;
|
||||
auto rnd = [&]() { seed = seed * 1103515245u + 12345u; return uint8_t(seed >> 16); };
|
||||
for (auto& b : pic_rom) b = rnd();
|
||||
for (auto& b : spo_rom) b = rnd();
|
||||
|
||||
// Reset vector -> $F000, matching the smoke_cpu test, so the CPU
|
||||
// has a defined (if arbitrary) place to start executing synthetic
|
||||
// "firmware".
|
||||
pic_rom[0xffe] = 0xf0;
|
||||
pic_rom[0xfff] = 0x00;
|
||||
|
||||
SscCore ssc;
|
||||
assert(ssc.LoadPicRom(pic_rom.data(), pic_rom.size()));
|
||||
assert(ssc.LoadSpeechRom(spo_rom.data(), spo_rom.size()));
|
||||
assert(ssc.RomsLoaded());
|
||||
ssc.Reset();
|
||||
|
||||
// $FF7D read should always be 0xFF.
|
||||
assert(ssc.ReadPort(0x7d) == 0xff);
|
||||
|
||||
// Writing $FF7E should raise the busy flag (bit7 clear) immediately.
|
||||
ssc.WritePort(0x7e, 0x55);
|
||||
uint8_t status = ssc.ReadPort(0x7e);
|
||||
assert((status & 0x80) == 0); // busy -> bit7 clear
|
||||
|
||||
// Run for a few seconds' worth of Tick() calls (each representing
|
||||
// 1/ssc.TickRateHz() sec of real time, 44100Hz by default -- see
|
||||
// SetTickRateHz() in ssc_core.h) and make sure nothing crashes/hangs
|
||||
// and the output sample stays in range.
|
||||
const double tick_hz = ssc.TickRateHz();
|
||||
const int scanlines = int(tick_hz * 3);
|
||||
for (int i = 0; i < scanlines; i++) {
|
||||
ssc.Tick();
|
||||
uint8_t s = ssc.LatchedSample();
|
||||
(void)s; // uint8_t is inherently in [0,255]; this just confirms the call is safe
|
||||
|
||||
// Occasionally poke the host-facing ports as real 6809 code would.
|
||||
if (i % 977 == 0) ssc.WritePort(0x7e, uint8_t(i));
|
||||
if (i % 5000 == 0) { uint8_t p = ssc.ReadPort(0x7e); (void)p; }
|
||||
if (i % 100000 == 99999) { ssc.WritePort(0x7d, 0x00); ssc.WritePort(0x7d, 0x01); } // pulse cart reset line
|
||||
}
|
||||
|
||||
std::printf("OK: ran %d ticks (%.1f seconds of CoCo time) without crashing/hanging\n",
|
||||
scanlines, scanlines / tick_hz);
|
||||
std::printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,727 @@
|
||||
// tms7000.cpp
|
||||
// See tms7000.h for provenance/license notes. This is a mechanical port of
|
||||
// MAME's tms7000.cpp / tms7000op.cpp opcode semantics and cycle counts to a
|
||||
// standalone class with no emulator framework dependency.
|
||||
|
||||
#include "tms7000.h"
|
||||
|
||||
namespace ssc {
|
||||
|
||||
Tms7000::Tms7000()
|
||||
{
|
||||
std::memset(m_rf, 0, sizeof(m_rf));
|
||||
std::memset(m_rom, 0, sizeof(m_rom));
|
||||
}
|
||||
|
||||
void Tms7000::LoadRom(const uint8_t* data, size_t len)
|
||||
{
|
||||
std::memset(m_rom, 0xff, sizeof(m_rom));
|
||||
if (data && len) {
|
||||
size_t n = len < sizeof(m_rom) ? len : sizeof(m_rom);
|
||||
std::memcpy(m_rom, data, n);
|
||||
}
|
||||
m_rom_loaded = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// memory map:
|
||||
// $0000-$007F 128 bytes internal register-file RAM
|
||||
// $0080-$00FF unmapped register-file addresses (reads as 0, writes ignored)
|
||||
// $0100-$010B peripheral file (IOCNT0, timer 1, ports A-D)
|
||||
// $010C-$EFFF unused / open bus (reads as 0xFF, writes ignored)
|
||||
// $F000-$FFFF 4KB internal ROM
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
uint8_t Tms7000::Read8(uint16_t address)
|
||||
{
|
||||
if (address < 0x0080) return m_rf[address];
|
||||
if (address < 0x0100) return 0x00; // unmapped rf
|
||||
if (address < 0x010c) return ReadP(uint8_t(address - 0x0100));
|
||||
if (address >= 0xf000) return m_rom[address - 0xf000];
|
||||
return 0xff; // open bus
|
||||
}
|
||||
|
||||
void Tms7000::Write8(uint16_t address, uint8_t data)
|
||||
{
|
||||
if (address < 0x0080) { m_rf[address] = data; return; }
|
||||
if (address < 0x0100) { return; } // unmapped rf
|
||||
if (address < 0x010c) { WriteP(uint8_t(address - 0x0100), data); return; }
|
||||
// ROM and open bus: writes ignored
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// peripheral file
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
uint8_t Tms7000::ReadP(uint8_t offset)
|
||||
{
|
||||
switch (offset)
|
||||
{
|
||||
case 0x00: return m_io_control[0];
|
||||
|
||||
case 0x02: return uint8_t(m_timer_decrementer);
|
||||
|
||||
case 0x03: return uint8_t(m_timer_capture_latch);
|
||||
|
||||
case 0x04: // port A data (input-only from host)
|
||||
return (InPortA ? InPortA() : 0xff);
|
||||
|
||||
case 0x06: // port B data (write-only; reads back output latch)
|
||||
return m_port_latch[1];
|
||||
|
||||
case 0x08: // port C data
|
||||
return (InPortC ? (InPortC() & ~m_port_ddr[2]) : 0) | (m_port_latch[2] & m_port_ddr[2]);
|
||||
|
||||
case 0x09: return m_port_ddr[2];
|
||||
|
||||
case 0x0a: // port D data
|
||||
return (InPortD ? (InPortD() & ~m_port_ddr[3]) : 0) | (m_port_latch[3] & m_port_ddr[3]);
|
||||
|
||||
case 0x0b: return m_port_ddr[3];
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::WriteP(uint8_t offset, uint8_t data)
|
||||
{
|
||||
switch (offset)
|
||||
{
|
||||
case 0x00: // IOCNT0
|
||||
// d0,d2,d4: INT1,2,3 enable d1,d3,d5: INT1,2,3 flag (write-1-clears)
|
||||
m_io_control[0] = (m_io_control[0] & (~data & 0x2a)) | (data & 0xd5);
|
||||
if (data & 0x02) FlagExtInterrupt(0);
|
||||
if (data & 0x20) FlagExtInterrupt(1);
|
||||
CheckInterrupts();
|
||||
break;
|
||||
|
||||
case 0x02: // timer data (reload value)
|
||||
m_timer_data = data;
|
||||
break;
|
||||
|
||||
case 0x03: // timer control
|
||||
m_timer_control = data;
|
||||
TimerReload();
|
||||
break;
|
||||
|
||||
case 0x04: // port A: no write / no ddr on TMS7000
|
||||
break;
|
||||
|
||||
case 0x06: // port B data (write only, ddr fixed to 0xff)
|
||||
if (OutPortB) OutPortB(data);
|
||||
m_port_latch[1] = data;
|
||||
break;
|
||||
|
||||
case 0x08: // port C data
|
||||
if (OutPortC) OutPortC(data & m_port_ddr[2]);
|
||||
m_port_latch[2] = data;
|
||||
break;
|
||||
|
||||
case 0x09: // port C ddr
|
||||
m_port_ddr[2] = data;
|
||||
break;
|
||||
|
||||
case 0x0a: // port D data
|
||||
if (OutPortD) OutPortD(data & m_port_ddr[3]);
|
||||
m_port_latch[3] = data;
|
||||
break;
|
||||
|
||||
case 0x0b: // port D ddr
|
||||
m_port_ddr[3] = data;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// reset / interrupts
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void Tms7000::Reset()
|
||||
{
|
||||
if (m_idle_state) { m_pc++; m_idle_state = false; }
|
||||
|
||||
WriteP(0x04, 0xff); // port a (no-op, kept for parity with original)
|
||||
WriteP(0x06, 0xff); // port b -> drives OutPortB(0xff)
|
||||
m_port_ddr[0] = 0x00;
|
||||
m_port_ddr[2] = 0x00;
|
||||
m_port_ddr[3] = 0x00;
|
||||
WriteP(0x08, 0xff); // port c -> drives OutPortC(0) (ddr==0 so masked to 0)
|
||||
WriteP(0x0a, 0xff); // port d -> drives OutPortD(0)
|
||||
|
||||
m_sr = 0;
|
||||
WriteP(0x00, 0x00); // IOCNT0
|
||||
|
||||
m_sp = 0xff;
|
||||
m_op = 0xff;
|
||||
ExecuteOne(m_op);
|
||||
m_icount -= 3; // 17 total, matching MAME's device_reset()
|
||||
|
||||
m_irq_state[0] = m_irq_state[1] = false;
|
||||
m_timer_running = false;
|
||||
m_timer_ticks_remaining = 0;
|
||||
}
|
||||
|
||||
void Tms7000::SetIrqLine(Tms7000Irq line, bool asserted)
|
||||
{
|
||||
int extline = (line == Tms7000Irq::Int1) ? 0 : 1;
|
||||
|
||||
if (m_irq_state[extline] != asserted)
|
||||
{
|
||||
m_irq_state[extline] = asserted;
|
||||
FlagExtInterrupt(extline);
|
||||
|
||||
if (m_irq_state[extline])
|
||||
{
|
||||
if (extline == 1) // INT3 latches timer capture
|
||||
m_timer_capture_latch = uint16_t(m_timer_decrementer);
|
||||
CheckInterrupts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::FlagExtInterrupt(int extline)
|
||||
{
|
||||
if (extline != 0 && extline != 1) return;
|
||||
if (m_irq_state[extline])
|
||||
m_io_control[0] |= (0x02 << (4 * extline));
|
||||
else
|
||||
m_io_control[0] &= ~(0x02 << (4 * extline));
|
||||
}
|
||||
|
||||
void Tms7000::CheckInterrupts()
|
||||
{
|
||||
if (!(m_sr & SR_I)) return;
|
||||
|
||||
// INT1 (bits 0-1), INT2 (bits 2-3, timer), INT3 (bits 4-5) all live in
|
||||
// IOCNT0 on the 70x0 family; INT4/5 (IOCNT1) don't exist on TMS7040.
|
||||
for (int irqline = 0; irqline < 3; irqline++)
|
||||
{
|
||||
int shift = irqline * 2;
|
||||
if (((m_io_control[0] >> shift) & 3) == 3)
|
||||
{
|
||||
m_io_control[0] &= ~(0x02 << shift);
|
||||
if (irqline == 0 || irqline == 2)
|
||||
FlagExtInterrupt(irqline / 2);
|
||||
DoInterrupt(irqline);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::DoInterrupt(int irqline)
|
||||
{
|
||||
if (m_idle_state) { m_icount -= 17; m_pc++; m_idle_state = false; }
|
||||
else m_icount -= 19;
|
||||
|
||||
Push8(m_sr);
|
||||
Push16(m_pc);
|
||||
m_sr = 0;
|
||||
m_pc = (uint16_t(Read8(0xfffc - irqline * 2)) << 8) | Read8(0xfffd - irqline * 2);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// timer (TMS7040: one internal timer, "automatic reload" mode only —
|
||||
// this is the mode the SSC firmware uses)
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void Tms7000::TimerRun()
|
||||
{
|
||||
m_timer_prescaler = m_timer_control & 0x1f;
|
||||
if ((m_timer_control & 0xe0) == 0x80)
|
||||
{
|
||||
// period, in icount ticks: 16*(prescaler+1) input-clock cycles,
|
||||
// divided by the /2 instruction clock divider == 8*(prescaler+1)
|
||||
m_timer_ticks_remaining = 8L * (m_timer_prescaler + 1);
|
||||
m_timer_running = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_timer_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::TimerReload()
|
||||
{
|
||||
m_timer_running = false;
|
||||
if (m_timer_control & 0x80)
|
||||
{
|
||||
m_timer_decrementer = m_timer_data;
|
||||
TimerRun();
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::TimerTickLow()
|
||||
{
|
||||
if (--m_timer_decrementer < 0)
|
||||
{
|
||||
TimerReload();
|
||||
m_io_control[0] |= 0x08; // INT2 flag
|
||||
CheckInterrupts();
|
||||
}
|
||||
}
|
||||
|
||||
void Tms7000::TickTimers(int elapsed_icount)
|
||||
{
|
||||
if (!m_timer_running) return;
|
||||
m_timer_ticks_remaining -= elapsed_icount;
|
||||
while (m_timer_ticks_remaining <= 0 && m_timer_running)
|
||||
{
|
||||
TimerTickLow();
|
||||
if (m_timer_running)
|
||||
m_timer_ticks_remaining += 8L * (m_timer_prescaler + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// execute
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
int Tms7000::Execute(int cycles)
|
||||
{
|
||||
m_icount = cycles;
|
||||
CheckInterrupts();
|
||||
|
||||
do
|
||||
{
|
||||
int before = m_icount;
|
||||
m_op = Read8(m_pc++);
|
||||
ExecuteOne(m_op);
|
||||
TickTimers(before - m_icount);
|
||||
} while (m_icount > 0);
|
||||
|
||||
return cycles - m_icount;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// flag helpers (kept as free functions operating on m_sr via macros,
|
||||
// mirroring the original for auditability)
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#define GET_C() (m_sr >> 7 & 1)
|
||||
#define SET_C(x) m_sr = (m_sr & 0x7f) | ((x) >> 1 & 0x80)
|
||||
#define SET_NZ(x) m_sr = (m_sr & 0x9f) | ((x) >> 1 & 0x40) | (((x) & 0xff) ? 0 : 0x20)
|
||||
#define SET_CNZ(x) m_sr = (m_sr & 0x1f) | ((x) >> 1 & 0xc0) | (((x) & 0xff) ? 0 : 0x20)
|
||||
|
||||
#define WB_NO -1
|
||||
#define AM_WB(write_func, address, param1, param2) \
|
||||
int result = (this->*op)(param1, param2); \
|
||||
if (result > WB_NO) write_func(address, uint8_t(result))
|
||||
|
||||
void Tms7000::AmA(OpFunc op) { m_icount -= 5; AM_WB(WriteR8, 0, ReadR8(0), 0); }
|
||||
void Tms7000::AmB(OpFunc op) { m_icount -= 5; AM_WB(WriteR8, 1, ReadR8(1), 0); }
|
||||
void Tms7000::AmR(OpFunc op) { m_icount -= 7; uint8_t r = Imm8(); AM_WB(WriteR8, r, ReadR8(r), 0); }
|
||||
void Tms7000::AmA2a(OpFunc op) { m_icount -= 6; AM_WB(WriteR8, 0, ReadR8(0), ReadR8(0)); }
|
||||
void Tms7000::AmA2b(OpFunc op) { m_icount -= 6; AM_WB(WriteR8, 1, ReadR8(1), ReadR8(0)); }
|
||||
void Tms7000::AmA2p(OpFunc op) { m_icount -= 10; uint8_t r = Imm8(); AM_WB(WriteP, r, ReadP(r), ReadR8(0)); }
|
||||
void Tms7000::AmA2r(OpFunc op) { m_icount -= 8; uint8_t r = Imm8(); AM_WB(WriteR8, r, ReadR8(r), ReadR8(0)); }
|
||||
void Tms7000::AmB2a(OpFunc op) { m_icount -= 5; AM_WB(WriteR8, 0, ReadR8(0), ReadR8(1)); }
|
||||
void Tms7000::AmB2b(OpFunc op) { m_icount -= 6; AM_WB(WriteR8, 1, ReadR8(1), ReadR8(1)); }
|
||||
void Tms7000::AmB2r(OpFunc op) { m_icount -= 7; uint8_t r = Imm8(); AM_WB(WriteR8, r, ReadR8(r), ReadR8(1)); }
|
||||
void Tms7000::AmB2p(OpFunc op) { m_icount -= 9; uint8_t r = Imm8(); AM_WB(WriteP, r, ReadP(r), ReadR8(1)); }
|
||||
void Tms7000::AmR2a(OpFunc op) { m_icount -= 8; AM_WB(WriteR8, 0, ReadR8(0), ReadR8(Imm8())); }
|
||||
void Tms7000::AmR2b(OpFunc op) { m_icount -= 8; AM_WB(WriteR8, 1, ReadR8(1), ReadR8(Imm8())); }
|
||||
void Tms7000::AmR2r(OpFunc op) { m_icount -= 10; uint8_t param2 = ReadR8(Imm8()); uint8_t r = Imm8(); AM_WB(WriteR8, r, ReadR8(r), param2); }
|
||||
void Tms7000::AmI2a(OpFunc op) { m_icount -= 7; AM_WB(WriteR8, 0, ReadR8(0), Imm8()); }
|
||||
void Tms7000::AmI2b(OpFunc op) { m_icount -= 7; AM_WB(WriteR8, 1, ReadR8(1), Imm8()); }
|
||||
void Tms7000::AmI2r(OpFunc op) { m_icount -= 9; uint8_t param2 = Imm8(); uint8_t r = Imm8(); AM_WB(WriteR8, r, ReadR8(r), param2); }
|
||||
void Tms7000::AmI2p(OpFunc op) { m_icount -= 11; uint8_t param2 = Imm8(); uint8_t r = Imm8(); AM_WB(WriteP, r, ReadP(r), param2); }
|
||||
void Tms7000::AmP2a(OpFunc op) { m_icount -= 9; AM_WB(WriteR8, 0, ReadR8(0), ReadP(Imm8())); }
|
||||
void Tms7000::AmP2b(OpFunc op) { m_icount -= 8; AM_WB(WriteR8, 1, ReadR8(1), ReadP(Imm8())); }
|
||||
|
||||
#undef AM_WB
|
||||
|
||||
// common opcodes -- 1 param
|
||||
int Tms7000::OpClr(uint8_t, uint8_t) { uint8_t t = 0; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpDec(uint8_t p1, uint8_t) { uint16_t t = p1 - 1; SET_NZ(t); SET_C(~t); return t; }
|
||||
int Tms7000::OpInc(uint8_t p1, uint8_t) { uint16_t t = p1 + 1; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpInv(uint8_t p1, uint8_t) { uint8_t t = ~p1; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpRl(uint8_t p1, uint8_t) { uint16_t t = (p1 << 1) | (p1 >> 7); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpRlc(uint8_t p1, uint8_t) { uint16_t t = (p1 << 1) | GET_C(); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpRr(uint8_t p1, uint8_t) { uint16_t t = (p1 >> 1) | (p1 << 8) | (p1 << 7 & 0x80); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpRrc(uint8_t p1, uint8_t) { uint16_t t = (p1 >> 1) | (p1 << 8) | (GET_C() << 7); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpSwap(uint8_t p1, uint8_t) { m_icount -= 3; uint16_t t = (p1 >> 4) | (p1 << 4); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpXchb(uint8_t p1, uint8_t) { m_icount -= 1; uint8_t t = ReadR8(1); SET_CNZ(t); WriteR8(1, p1); return t; }
|
||||
|
||||
// 2 params
|
||||
int Tms7000::OpAdc(uint8_t p1, uint8_t p2) { uint16_t t = p1 + p2 + GET_C(); SET_CNZ(t); return t; }
|
||||
int Tms7000::OpAdd(uint8_t p1, uint8_t p2) { uint16_t t = p1 + p2; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpAnd(uint8_t p1, uint8_t p2) { uint8_t t = p1 & p2; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpCmp(uint8_t p1, uint8_t p2) { uint16_t t = p1 - p2; SET_NZ(t); SET_C(~t); return WB_NO; }
|
||||
int Tms7000::OpMpy(uint8_t p1, uint8_t p2)
|
||||
{
|
||||
m_icount -= 39;
|
||||
uint16_t t = uint16_t(p1) * uint16_t(p2);
|
||||
SET_CNZ(t >> 8);
|
||||
// Result always lands in the A:B register pair (A=high byte, B=low byte).
|
||||
// WriteR16(r, v) writes the high byte to (r-1) and the low byte to r,
|
||||
// so r=1 (B) places the high byte in A(0) and the low byte in B(1).
|
||||
WriteR16(1, t);
|
||||
return WB_NO;
|
||||
}
|
||||
int Tms7000::OpMov(uint8_t, uint8_t p2) { uint8_t t = p2; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpOr(uint8_t p1, uint8_t p2) { uint8_t t = p1 | p2; SET_CNZ(t); return t; }
|
||||
int Tms7000::OpSbb(uint8_t p1, uint8_t p2) { uint16_t t = p1 - p2 - (!GET_C()); SET_NZ(t); SET_C(~t); return t; }
|
||||
int Tms7000::OpSub(uint8_t p1, uint8_t p2) { uint16_t t = p1 - p2; SET_NZ(t); SET_C(~t); return t; }
|
||||
int Tms7000::OpXor(uint8_t p1, uint8_t p2) { uint8_t t = p1 ^ p2; SET_CNZ(t); return t; }
|
||||
|
||||
static const uint8_t lut_bcd_out[6] = { 0x00, 0x06, 0x00, 0x66, 0x60, 0x66 };
|
||||
|
||||
int Tms7000::OpDac(uint8_t p1, uint8_t p2)
|
||||
{
|
||||
m_icount -= 2;
|
||||
int c = GET_C();
|
||||
uint8_t h1 = p1 >> 4 & 0xf, l1 = p1 & 0xf;
|
||||
uint8_t h2 = p2 >> 4 & 0xf, l2 = p2 & 0xf;
|
||||
uint8_t d = ((l1 + l2 + c) < 10) ? 0 : 1;
|
||||
if ((h1 + h2) == 9) d |= 2; else if ((h1 + h2) > 9) d |= 4;
|
||||
uint8_t t = p1 + p2 + c + lut_bcd_out[d];
|
||||
SET_CNZ(t);
|
||||
if (d > 2) m_sr |= SR_C;
|
||||
return t;
|
||||
}
|
||||
|
||||
int Tms7000::OpDsb(uint8_t p1, uint8_t p2)
|
||||
{
|
||||
m_icount -= 2;
|
||||
int c = !GET_C();
|
||||
uint8_t h1 = p1 >> 4 & 0xf, l1 = p1 & 0xf;
|
||||
uint8_t h2 = p2 >> 4 & 0xf, l2 = p2 & 0xf;
|
||||
uint8_t d = ((l1 - c) >= l2) ? 0 : 1;
|
||||
if (h1 == h2) d |= 2; else if (h1 < h2) d |= 4;
|
||||
uint8_t t = p1 - p2 - c - lut_bcd_out[d];
|
||||
SET_CNZ(t);
|
||||
if (d <= 2) m_sr |= SR_C;
|
||||
return t;
|
||||
}
|
||||
|
||||
void Tms7000::ShortBranch(bool check)
|
||||
{
|
||||
m_icount -= 2;
|
||||
int8_t d = int8_t(Imm8());
|
||||
if (check) { m_pc += d; m_icount -= 2; }
|
||||
}
|
||||
|
||||
void Tms7000::Jmp(bool check) { m_icount -= 3; ShortBranch(check); }
|
||||
|
||||
int Tms7000::OpDjnz(uint8_t p1, uint8_t) { uint16_t t = p1 - 1; ShortBranch(t != 0); return t; }
|
||||
int Tms7000::OpBtjo(uint8_t p1, uint8_t p2) { uint8_t t = p1 & p2; SET_CNZ(t); ShortBranch(t != 0); return WB_NO; }
|
||||
int Tms7000::OpBtjz(uint8_t p1, uint8_t p2) { uint8_t t = uint8_t(~p1) & p2; SET_CNZ(t); ShortBranch(t != 0); return WB_NO; }
|
||||
|
||||
void Tms7000::DecdA() { m_icount -= 9; uint32_t t = ReadR16(0) - 1; WriteR16(0, uint16_t(t)); SET_NZ(t >> 8); SET_C(~(t >> 8)); }
|
||||
void Tms7000::DecdB() { m_icount -= 9; uint32_t t = ReadR16(1) - 1; WriteR16(1, uint16_t(t)); SET_NZ(t >> 8); SET_C(~(t >> 8)); }
|
||||
void Tms7000::DecdR() { m_icount -= 11; uint8_t r = Imm8(); uint32_t t = ReadR16(r) - 1; WriteR16(r, uint16_t(t)); SET_NZ(t >> 8); SET_C(~(t >> 8)); }
|
||||
|
||||
void Tms7000::CmpaDir() { m_icount -= 12; uint16_t t = ReadR8(0) - Read8(Imm16()); SET_NZ(t); SET_C(~t); }
|
||||
void Tms7000::CmpaInx() { m_icount -= 14; uint16_t t = ReadR8(0) - Read8(Imm16() + ReadR8(1)); SET_NZ(t); SET_C(~t); }
|
||||
void Tms7000::CmpaInd() { m_icount -= 11; uint16_t t = ReadR8(0) - Read8(ReadR16(Imm8())); SET_NZ(t); SET_C(~t); }
|
||||
|
||||
void Tms7000::LdaDir() { m_icount -= 11; uint8_t t = Read8(Imm16()); WriteR8(0, t); SET_CNZ(t); }
|
||||
void Tms7000::LdaInx() { m_icount -= 13; uint8_t t = Read8(Imm16() + ReadR8(1)); WriteR8(0, t); SET_CNZ(t); }
|
||||
void Tms7000::LdaInd() { m_icount -= 10; uint8_t t = Read8(ReadR16(Imm8())); WriteR8(0, t); SET_CNZ(t); }
|
||||
|
||||
void Tms7000::StaDir() { m_icount -= 11; uint8_t t = ReadR8(0); Write8(Imm16(), t); SET_CNZ(t); }
|
||||
void Tms7000::StaInx() { m_icount -= 13; uint8_t t = ReadR8(0); Write8(Imm16() + ReadR8(1), t); SET_CNZ(t); }
|
||||
void Tms7000::StaInd() { m_icount -= 10; uint8_t t = ReadR8(0); Write8(ReadR16(Imm8()), t); SET_CNZ(t); }
|
||||
|
||||
void Tms7000::MovdDir() { m_icount -= 15; uint16_t t = Imm16(); WriteR16(Imm8(), t); SET_CNZ(t >> 8); }
|
||||
void Tms7000::MovdInx() { m_icount -= 17; uint16_t t = Imm16() + ReadR8(1); WriteR16(Imm8(), t); SET_CNZ(t >> 8); }
|
||||
void Tms7000::MovdInd() { m_icount -= 14; uint16_t t = ReadR16(Imm8()); WriteR16(Imm8(), t); SET_CNZ(t >> 8); }
|
||||
|
||||
void Tms7000::BrDir() { m_icount -= 10; m_pc = Imm16(); }
|
||||
void Tms7000::BrInx() { m_icount -= 12; m_pc = Imm16() + ReadR8(1); }
|
||||
void Tms7000::BrInd() { m_icount -= 9; m_pc = ReadR16(Imm8()); }
|
||||
|
||||
void Tms7000::CallDir() { m_icount -= 14; uint16_t t = Imm16(); Push16(m_pc); m_pc = t; }
|
||||
void Tms7000::CallInx() { m_icount -= 16; uint16_t t = Imm16() + ReadR8(1); Push16(m_pc); m_pc = t; }
|
||||
void Tms7000::CallInd() { m_icount -= 13; uint16_t t = ReadR16(Imm8()); Push16(m_pc); m_pc = t; }
|
||||
|
||||
void Tms7000::Trap(uint8_t address)
|
||||
{
|
||||
m_icount -= 14;
|
||||
Push16(m_pc);
|
||||
uint16_t vec = 0xff00 | address;
|
||||
m_pc = (uint16_t(Read8(vec)) << 8) | Read8(uint16_t(vec + 1));
|
||||
}
|
||||
|
||||
void Tms7000::Reti() { m_icount -= 9; m_pc = Pull16(); m_sr = Pull8() & 0xf0; CheckInterrupts(); }
|
||||
void Tms7000::Rets() { m_icount -= 7; m_pc = Pull16(); }
|
||||
|
||||
void Tms7000::PopA() { m_icount -= 6; uint8_t t = Pull8(); WriteR8(0, t); SET_CNZ(t); }
|
||||
void Tms7000::PopB() { m_icount -= 6; uint8_t t = Pull8(); WriteR8(1, t); SET_CNZ(t); }
|
||||
void Tms7000::PopR() { m_icount -= 8; uint8_t t = Pull8(); WriteR8(Imm8(), t); SET_CNZ(t); }
|
||||
void Tms7000::PopSt() { m_icount -= 6; m_sr = Pull8() & 0xf0; CheckInterrupts(); }
|
||||
|
||||
void Tms7000::PushA() { m_icount -= 6; uint8_t t = ReadR8(0); Push8(t); SET_CNZ(t); }
|
||||
void Tms7000::PushB() { m_icount -= 6; uint8_t t = ReadR8(1); Push8(t); SET_CNZ(t); }
|
||||
void Tms7000::PushR() { m_icount -= 8; uint8_t t = ReadR8(Imm8()); Push8(t); SET_CNZ(t); }
|
||||
void Tms7000::PushSt(){ m_icount -= 6; Push8(m_sr); }
|
||||
|
||||
void Tms7000::Nop() { m_icount -= 5; }
|
||||
void Tms7000::Idle() { m_icount -= 6; m_pc--; m_idle_state = true; }
|
||||
void Tms7000::Dint() { m_icount -= 5; m_sr &= ~(SR_N | SR_Z | SR_C | SR_I); }
|
||||
void Tms7000::Eint() { m_icount -= 5; m_sr |= (SR_N | SR_Z | SR_C | SR_I); CheckInterrupts(); }
|
||||
void Tms7000::Ldsp() { m_icount -= 5; m_sp = ReadR8(1); }
|
||||
void Tms7000::Stsp() { m_icount -= 6; WriteR8(1, m_sp); }
|
||||
void Tms7000::Setc() { m_icount -= 5; m_sr = (m_sr & ~SR_N) | SR_C | SR_Z; }
|
||||
|
||||
void Tms7000::Illegal(uint8_t) { m_icount -= 5; m_illegal_count++; }
|
||||
|
||||
#undef GET_C
|
||||
#undef SET_C
|
||||
#undef SET_NZ
|
||||
#undef SET_CNZ
|
||||
#undef WB_NO
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// dispatch (opcode map identical to MAME's tms7000_device::execute_one)
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void Tms7000::ExecuteOne(uint8_t op)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case 0x00: Nop(); break;
|
||||
case 0x01: Idle(); break;
|
||||
case 0x05: Eint(); break;
|
||||
case 0x06: Dint(); break;
|
||||
case 0x07: Setc(); break;
|
||||
case 0x08: PopSt(); break;
|
||||
case 0x09: Stsp(); break;
|
||||
case 0x0a: Rets(); break;
|
||||
case 0x0b: Reti(); break;
|
||||
case 0x0d: Ldsp(); break;
|
||||
case 0x0e: PushSt(); break;
|
||||
|
||||
case 0x12: AmR2a(&Tms7000::OpMov); break;
|
||||
case 0x13: AmR2a(&Tms7000::OpAnd); break;
|
||||
case 0x14: AmR2a(&Tms7000::OpOr); break;
|
||||
case 0x15: AmR2a(&Tms7000::OpXor); break;
|
||||
case 0x16: AmR2a(&Tms7000::OpBtjo); break;
|
||||
case 0x17: AmR2a(&Tms7000::OpBtjz); break;
|
||||
case 0x18: AmR2a(&Tms7000::OpAdd); break;
|
||||
case 0x19: AmR2a(&Tms7000::OpAdc); break;
|
||||
case 0x1a: AmR2a(&Tms7000::OpSub); break;
|
||||
case 0x1b: AmR2a(&Tms7000::OpSbb); break;
|
||||
case 0x1c: AmR2a(&Tms7000::OpMpy); break;
|
||||
case 0x1d: AmR2a(&Tms7000::OpCmp); break;
|
||||
case 0x1e: AmR2a(&Tms7000::OpDac); break;
|
||||
case 0x1f: AmR2a(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x22: AmI2a(&Tms7000::OpMov); break;
|
||||
case 0x23: AmI2a(&Tms7000::OpAnd); break;
|
||||
case 0x24: AmI2a(&Tms7000::OpOr); break;
|
||||
case 0x25: AmI2a(&Tms7000::OpXor); break;
|
||||
case 0x26: AmI2a(&Tms7000::OpBtjo); break;
|
||||
case 0x27: AmI2a(&Tms7000::OpBtjz); break;
|
||||
case 0x28: AmI2a(&Tms7000::OpAdd); break;
|
||||
case 0x29: AmI2a(&Tms7000::OpAdc); break;
|
||||
case 0x2a: AmI2a(&Tms7000::OpSub); break;
|
||||
case 0x2b: AmI2a(&Tms7000::OpSbb); break;
|
||||
case 0x2c: AmI2a(&Tms7000::OpMpy); break;
|
||||
case 0x2d: AmI2a(&Tms7000::OpCmp); break;
|
||||
case 0x2e: AmI2a(&Tms7000::OpDac); break;
|
||||
case 0x2f: AmI2a(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x32: AmR2b(&Tms7000::OpMov); break;
|
||||
case 0x33: AmR2b(&Tms7000::OpAnd); break;
|
||||
case 0x34: AmR2b(&Tms7000::OpOr); break;
|
||||
case 0x35: AmR2b(&Tms7000::OpXor); break;
|
||||
case 0x36: AmR2b(&Tms7000::OpBtjo); break;
|
||||
case 0x37: AmR2b(&Tms7000::OpBtjz); break;
|
||||
case 0x38: AmR2b(&Tms7000::OpAdd); break;
|
||||
case 0x39: AmR2b(&Tms7000::OpAdc); break;
|
||||
case 0x3a: AmR2b(&Tms7000::OpSub); break;
|
||||
case 0x3b: AmR2b(&Tms7000::OpSbb); break;
|
||||
case 0x3c: AmR2b(&Tms7000::OpMpy); break;
|
||||
case 0x3d: AmR2b(&Tms7000::OpCmp); break;
|
||||
case 0x3e: AmR2b(&Tms7000::OpDac); break;
|
||||
case 0x3f: AmR2b(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x42: AmR2r(&Tms7000::OpMov); break;
|
||||
case 0x43: AmR2r(&Tms7000::OpAnd); break;
|
||||
case 0x44: AmR2r(&Tms7000::OpOr); break;
|
||||
case 0x45: AmR2r(&Tms7000::OpXor); break;
|
||||
case 0x46: AmR2r(&Tms7000::OpBtjo); break;
|
||||
case 0x47: AmR2r(&Tms7000::OpBtjz); break;
|
||||
case 0x48: AmR2r(&Tms7000::OpAdd); break;
|
||||
case 0x49: AmR2r(&Tms7000::OpAdc); break;
|
||||
case 0x4a: AmR2r(&Tms7000::OpSub); break;
|
||||
case 0x4b: AmR2r(&Tms7000::OpSbb); break;
|
||||
case 0x4c: AmR2r(&Tms7000::OpMpy); break;
|
||||
case 0x4d: AmR2r(&Tms7000::OpCmp); break;
|
||||
case 0x4e: AmR2r(&Tms7000::OpDac); break;
|
||||
case 0x4f: AmR2r(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x52: AmI2b(&Tms7000::OpMov); break;
|
||||
case 0x53: AmI2b(&Tms7000::OpAnd); break;
|
||||
case 0x54: AmI2b(&Tms7000::OpOr); break;
|
||||
case 0x55: AmI2b(&Tms7000::OpXor); break;
|
||||
case 0x56: AmI2b(&Tms7000::OpBtjo); break;
|
||||
case 0x57: AmI2b(&Tms7000::OpBtjz); break;
|
||||
case 0x58: AmI2b(&Tms7000::OpAdd); break;
|
||||
case 0x59: AmI2b(&Tms7000::OpAdc); break;
|
||||
case 0x5a: AmI2b(&Tms7000::OpSub); break;
|
||||
case 0x5b: AmI2b(&Tms7000::OpSbb); break;
|
||||
case 0x5c: AmI2b(&Tms7000::OpMpy); break;
|
||||
case 0x5d: AmI2b(&Tms7000::OpCmp); break;
|
||||
case 0x5e: AmI2b(&Tms7000::OpDac); break;
|
||||
case 0x5f: AmI2b(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x62: AmB2a(&Tms7000::OpMov); break;
|
||||
case 0x63: AmB2a(&Tms7000::OpAnd); break;
|
||||
case 0x64: AmB2a(&Tms7000::OpOr); break;
|
||||
case 0x65: AmB2a(&Tms7000::OpXor); break;
|
||||
case 0x66: AmB2a(&Tms7000::OpBtjo); break;
|
||||
case 0x67: AmB2a(&Tms7000::OpBtjz); break;
|
||||
case 0x68: AmB2a(&Tms7000::OpAdd); break;
|
||||
case 0x69: AmB2a(&Tms7000::OpAdc); break;
|
||||
case 0x6a: AmB2a(&Tms7000::OpSub); break;
|
||||
case 0x6b: AmB2a(&Tms7000::OpSbb); break;
|
||||
case 0x6c: AmB2a(&Tms7000::OpMpy); break;
|
||||
case 0x6d: AmB2a(&Tms7000::OpCmp); break;
|
||||
case 0x6e: AmB2a(&Tms7000::OpDac); break;
|
||||
case 0x6f: AmB2a(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x72: AmI2r(&Tms7000::OpMov); break;
|
||||
case 0x73: AmI2r(&Tms7000::OpAnd); break;
|
||||
case 0x74: AmI2r(&Tms7000::OpOr); break;
|
||||
case 0x75: AmI2r(&Tms7000::OpXor); break;
|
||||
case 0x76: AmI2r(&Tms7000::OpBtjo); break;
|
||||
case 0x77: AmI2r(&Tms7000::OpBtjz); break;
|
||||
case 0x78: AmI2r(&Tms7000::OpAdd); break;
|
||||
case 0x79: AmI2r(&Tms7000::OpAdc); break;
|
||||
case 0x7a: AmI2r(&Tms7000::OpSub); break;
|
||||
case 0x7b: AmI2r(&Tms7000::OpSbb); break;
|
||||
case 0x7c: AmI2r(&Tms7000::OpMpy); break;
|
||||
case 0x7d: AmI2r(&Tms7000::OpCmp); break;
|
||||
case 0x7e: AmI2r(&Tms7000::OpDac); break;
|
||||
case 0x7f: AmI2r(&Tms7000::OpDsb); break;
|
||||
|
||||
case 0x80: AmP2a(&Tms7000::OpMov); break;
|
||||
case 0x82: AmA2p(&Tms7000::OpMov); break;
|
||||
case 0x83: AmA2p(&Tms7000::OpAnd); break;
|
||||
case 0x84: AmA2p(&Tms7000::OpOr); break;
|
||||
case 0x85: AmA2p(&Tms7000::OpXor); break;
|
||||
case 0x86: AmA2p(&Tms7000::OpBtjo); break;
|
||||
case 0x87: AmA2p(&Tms7000::OpBtjz); break;
|
||||
case 0x88: MovdDir(); break;
|
||||
case 0x8a: LdaDir(); break;
|
||||
case 0x8b: StaDir(); break;
|
||||
case 0x8c: BrDir(); break;
|
||||
case 0x8d: CmpaDir(); break;
|
||||
case 0x8e: CallDir(); break;
|
||||
|
||||
case 0x91: AmP2b(&Tms7000::OpMov); break;
|
||||
case 0x92: AmB2p(&Tms7000::OpMov); break;
|
||||
case 0x93: AmB2p(&Tms7000::OpAnd); break;
|
||||
case 0x94: AmB2p(&Tms7000::OpOr); break;
|
||||
case 0x95: AmB2p(&Tms7000::OpXor); break;
|
||||
case 0x96: AmB2p(&Tms7000::OpBtjo); break;
|
||||
case 0x97: AmB2p(&Tms7000::OpBtjz); break;
|
||||
// NOTE: opcodes 0x98-0x9e are the *indirect* (register-pair
|
||||
// pointer) addressing-mode family, and 0xa8-0xae are the
|
||||
// *indexed* (16-bit immediate + B-register offset) family --
|
||||
// confirmed byte-for-byte against MAME's tms7000.cpp
|
||||
// execute_one() dispatch table. An earlier version of this file
|
||||
// had these two families swapped (0x98-0x9e wrongly wired to
|
||||
// the Inx handlers, 0xa8-0xae wrongly wired to the Ind
|
||||
// handlers), which silently mis-decoded every instruction using
|
||||
// either opcode range: since IndX consumes a 16-bit immediate
|
||||
// operand and Ind consumes only an 8-bit one, the swap caused
|
||||
// the CPU to consume the wrong number of operand bytes and
|
||||
// permanently desync from the real instruction stream from that
|
||||
// point on, well before this specific SSC firmware ever reaches
|
||||
// the code that dispatches a received host command.
|
||||
case 0x98: MovdInd(); break;
|
||||
case 0x9a: LdaInd(); break;
|
||||
case 0x9b: StaInd(); break;
|
||||
case 0x9c: BrInd(); break;
|
||||
case 0x9d: CmpaInd(); break;
|
||||
case 0x9e: CallInd(); break;
|
||||
|
||||
case 0xa2: AmI2p(&Tms7000::OpMov); break;
|
||||
case 0xa3: AmI2p(&Tms7000::OpAnd); break;
|
||||
case 0xa4: AmI2p(&Tms7000::OpOr); break;
|
||||
case 0xa5: AmI2p(&Tms7000::OpXor); break;
|
||||
case 0xa6: AmI2p(&Tms7000::OpBtjo); break;
|
||||
case 0xa7: AmI2p(&Tms7000::OpBtjz); break;
|
||||
case 0xa8: MovdInx(); break;
|
||||
case 0xaa: LdaInx(); break;
|
||||
case 0xab: StaInx(); break;
|
||||
case 0xac: BrInx(); break;
|
||||
case 0xad: CmpaInx(); break;
|
||||
case 0xae: CallInx(); break;
|
||||
|
||||
case 0xb0: AmA2a(&Tms7000::OpMov); break;
|
||||
case 0xb1: AmB2a(&Tms7000::OpMov); break;
|
||||
case 0xb2: AmA(&Tms7000::OpDec); break;
|
||||
case 0xb3: AmA(&Tms7000::OpInc); break;
|
||||
case 0xb4: AmA(&Tms7000::OpInv); break;
|
||||
case 0xb5: AmA(&Tms7000::OpClr); break;
|
||||
case 0xb6: AmA(&Tms7000::OpXchb); break;
|
||||
case 0xb7: AmA(&Tms7000::OpSwap); break;
|
||||
case 0xb8: PushA(); break;
|
||||
case 0xb9: PopA(); break;
|
||||
case 0xba: AmA(&Tms7000::OpDjnz); break;
|
||||
case 0xbb: DecdA(); break;
|
||||
case 0xbc: AmA(&Tms7000::OpRr); break;
|
||||
case 0xbd: AmA(&Tms7000::OpRrc); break;
|
||||
case 0xbe: AmA(&Tms7000::OpRl); break;
|
||||
case 0xbf: AmA(&Tms7000::OpRlc); break;
|
||||
|
||||
case 0xc0: AmA2b(&Tms7000::OpMov); break;
|
||||
case 0xc1: AmB2b(&Tms7000::OpMov); break;
|
||||
case 0xc2: AmB(&Tms7000::OpDec); break;
|
||||
case 0xc3: AmB(&Tms7000::OpInc); break;
|
||||
case 0xc4: AmB(&Tms7000::OpInv); break;
|
||||
case 0xc5: AmB(&Tms7000::OpClr); break;
|
||||
case 0xc6: AmB(&Tms7000::OpXchb); break;
|
||||
case 0xc7: AmB(&Tms7000::OpSwap); break;
|
||||
case 0xc8: PushB(); break;
|
||||
case 0xc9: PopB(); break;
|
||||
case 0xca: AmB(&Tms7000::OpDjnz); break;
|
||||
case 0xcb: DecdB(); break;
|
||||
case 0xcc: AmB(&Tms7000::OpRr); break;
|
||||
case 0xcd: AmB(&Tms7000::OpRrc); break;
|
||||
case 0xce: AmB(&Tms7000::OpRl); break;
|
||||
case 0xcf: AmB(&Tms7000::OpRlc); break;
|
||||
|
||||
case 0xd0: AmA2r(&Tms7000::OpMov); break;
|
||||
case 0xd1: AmB2r(&Tms7000::OpMov); break;
|
||||
case 0xd2: AmR(&Tms7000::OpDec); break;
|
||||
case 0xd3: AmR(&Tms7000::OpInc); break;
|
||||
case 0xd4: AmR(&Tms7000::OpInv); break;
|
||||
case 0xd5: AmR(&Tms7000::OpClr); break;
|
||||
case 0xd6: AmR(&Tms7000::OpXchb); break;
|
||||
case 0xd7: AmR(&Tms7000::OpSwap); break;
|
||||
case 0xd8: PushR(); break;
|
||||
case 0xd9: PopR(); break;
|
||||
case 0xda: AmR(&Tms7000::OpDjnz); break;
|
||||
case 0xdb: DecdR(); break;
|
||||
case 0xdc: AmR(&Tms7000::OpRr); break;
|
||||
case 0xdd: AmR(&Tms7000::OpRrc); break;
|
||||
case 0xde: AmR(&Tms7000::OpRl); break;
|
||||
case 0xdf: AmR(&Tms7000::OpRlc); break;
|
||||
|
||||
case 0xe0: Jmp(true); break;
|
||||
case 0xe1: Jmp((m_sr & SR_N) != 0); break;
|
||||
case 0xe2: Jmp((m_sr & SR_Z) != 0); break;
|
||||
case 0xe3: Jmp((m_sr & SR_C) != 0); break;
|
||||
case 0xe4: Jmp(!(m_sr & (SR_Z | SR_N))); break;
|
||||
case 0xe5: Jmp(!(m_sr & SR_N)); break;
|
||||
case 0xe6: Jmp(!(m_sr & SR_Z)); break;
|
||||
case 0xe7: Jmp(!(m_sr & SR_C)); break;
|
||||
|
||||
case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef:
|
||||
case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7:
|
||||
case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff:
|
||||
Trap(op << 1); break;
|
||||
|
||||
default: Illegal(op); break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ssc
|
||||
@@ -0,0 +1,217 @@
|
||||
// tms7000.h
|
||||
//
|
||||
// Standalone, portable emulation of the Texas Instruments TMS7000 /
|
||||
// TMS7040 microcontroller core, adapted for use as the "PIC7040" engine
|
||||
// inside a Tandy Speech/Sound Cartridge (SSC) emulation for VCC.
|
||||
//
|
||||
// This is a from-source port of the instruction set, addressing modes,
|
||||
// interrupt logic and internal timer logic documented in MAME's
|
||||
// src/devices/cpu/tms7000/tms7000.cpp / tms7000.h / tms7000op.cpp
|
||||
// (license: BSD-3-Clause, copyright hap, Tim Lindner). The MAME device
|
||||
// framework (device_t, address_map, emu_timer, attotime, save_item,
|
||||
// debugger hooks, disassembler) has been stripped out and replaced with
|
||||
// plain callbacks and a cycle-budget Execute() loop so the core can run
|
||||
// standalone inside a Windows DLL with no emulator framework underneath
|
||||
// it. The opcode table, cycle counts, flag behavior and timer math are
|
||||
// preserved from the original as closely as possible.
|
||||
//
|
||||
// Only the TMS7040 configuration is implemented: 128 bytes of internal
|
||||
// register-file RAM at $0000-$007F, the peripheral file at $0100-$010B
|
||||
// (I/O control, one timer, ports A-D), and 4KB of internal ROM at
|
||||
// $F000-$FFFF. This matches how the SSC's PIC7040 is wired: it uses no
|
||||
// external memory bus, only its four I/O ports.
|
||||
//
|
||||
// license:BSD-3-Clause
|
||||
// Original copyright-holders: hap, Tim Lindner (MAME tms7000 core)
|
||||
// Port for VCC SSC cartridge: 2026
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
|
||||
namespace ssc {
|
||||
|
||||
// External interrupt line identifiers (INT2/4/5 are internally generated
|
||||
// by the timer logic and are not exposed here).
|
||||
enum class Tms7000Irq {
|
||||
Int1 = 0, // wired to SP0256 DRQ in the SSC
|
||||
Int3 = 1, // wired to "host wrote a command byte" in the SSC
|
||||
};
|
||||
|
||||
class Tms7000 {
|
||||
public:
|
||||
Tms7000();
|
||||
|
||||
// --- host wiring -------------------------------------------------
|
||||
// Internal ROM image (4096 bytes) must be supplied before Reset().
|
||||
void LoadRom(const uint8_t* data, size_t len);
|
||||
|
||||
// Port callbacks. Port A is input-only (host -> chip), Port B is
|
||||
// output-only, Ports C and D are bidirectional, matching the real
|
||||
// TMS7040 wiring used by the SSC.
|
||||
std::function<uint8_t()> InPortA;
|
||||
std::function<void(uint8_t)> OutPortB;
|
||||
std::function<uint8_t()> InPortC;
|
||||
std::function<void(uint8_t)> OutPortC;
|
||||
std::function<uint8_t()> InPortD;
|
||||
std::function<void(uint8_t)> OutPortD;
|
||||
|
||||
// --- execution -----------------------------------------------------
|
||||
void Reset();
|
||||
|
||||
// Runs instructions until at least `cycles` worth of icount has been
|
||||
// consumed (icount units == input-clock cycles / 2, matching the
|
||||
// TMS7000's fixed /2 internal clock divider). Returns the number of
|
||||
// cycles actually consumed (>= cycles, since instructions are atomic).
|
||||
int Execute(int cycles);
|
||||
|
||||
// External interrupt line control (level-sensitive, active-high
|
||||
// "asserted" semantics matching MAME's execute_set_input: call with
|
||||
// asserted=true to assert, false to clear).
|
||||
void SetIrqLine(Tms7000Irq line, bool asserted);
|
||||
|
||||
// Debug/introspection
|
||||
uint16_t PC() const { return m_pc; }
|
||||
uint8_t PeekReg(uint8_t r) const { return m_rf[r & 0x7f]; }
|
||||
// Count of undefined-opcode fetches since Reset() -- a real firmware
|
||||
// image running correctly should keep this at 0; a nonzero count is
|
||||
// a strong signal the CPU has run off into data or a decode bug.
|
||||
uint32_t IllegalCount() const { return m_illegal_count; }
|
||||
|
||||
private:
|
||||
// ---- addressable state ----
|
||||
uint8_t m_rf[128]; // internal register file RAM ($00-$7F); R0=A, R1=B
|
||||
uint8_t m_rom[4096]; // internal ROM ($F000-$FFFF)
|
||||
bool m_rom_loaded = false;
|
||||
|
||||
uint16_t m_pc = 0;
|
||||
uint32_t m_illegal_count = 0;
|
||||
uint8_t m_sp = 0;
|
||||
uint8_t m_sr = 0; // status register: C N Z I . . . .
|
||||
uint8_t m_op = 0;
|
||||
int m_icount = 0;
|
||||
|
||||
bool m_irq_state[2] = { false, false };
|
||||
bool m_idle_state = false;
|
||||
|
||||
uint8_t m_io_control[2] = { 0, 0 }; // IOCNT0 (only [0] used by TMS7040)
|
||||
|
||||
// one hardware timer (TMS7040 family only implements timer 1)
|
||||
uint8_t m_timer_data = 0;
|
||||
uint8_t m_timer_control = 0;
|
||||
int m_timer_decrementer = 0;
|
||||
int m_timer_prescaler = 0;
|
||||
uint16_t m_timer_capture_latch = 0;
|
||||
bool m_timer_running = false;
|
||||
long m_timer_ticks_remaining = 0; // icount ticks until next prescaler decrement
|
||||
|
||||
uint8_t m_port_latch[4] = { 0, 0, 0, 0 }; // A,B,C,D output latches
|
||||
uint8_t m_port_ddr[4] = { 0, 0, 0, 0 }; // A,B,C,D direction regs
|
||||
|
||||
// ---- memory access ----
|
||||
uint8_t Read8(uint16_t address);
|
||||
void Write8(uint16_t address, uint8_t data);
|
||||
uint8_t ReadR8(uint8_t r) { return Read8(r); }
|
||||
void WriteR8(uint8_t r, uint8_t v) { Write8(r, v); }
|
||||
uint16_t ReadR16(uint8_t r) { return (uint16_t(Read8((r - 1) & 0xff)) << 8) | Read8(r); }
|
||||
void WriteR16(uint8_t r, uint16_t v) { Write8((r - 1) & 0xff, v >> 8); Write8(r, v & 0xff); }
|
||||
|
||||
uint8_t ReadP(uint8_t offset);
|
||||
void WriteP(uint8_t offset, uint8_t data);
|
||||
|
||||
uint8_t Imm8() { return Read8(m_pc++); }
|
||||
uint16_t Imm16() { uint16_t hi = Read8(m_pc++); return (hi << 8) | Read8(m_pc++); }
|
||||
|
||||
uint8_t Pull8() { return Read8(m_sp--); }
|
||||
void Push8(uint8_t data) { Write8(++m_sp, data); }
|
||||
uint16_t Pull16() { uint16_t lo = Read8(m_sp--); return lo | (uint16_t(Read8(m_sp--)) << 8); }
|
||||
void Push16(uint16_t data) { Write8(++m_sp, data >> 8 & 0xff); Write8(++m_sp, data & 0xff); }
|
||||
|
||||
// ---- status flags ----
|
||||
enum { SR_C = 0x80, SR_N = 0x40, SR_Z = 0x20, SR_I = 0x10 };
|
||||
|
||||
// ---- interrupts ----
|
||||
void FlagExtInterrupt(int extline);
|
||||
void CheckInterrupts();
|
||||
void DoInterrupt(int irqline);
|
||||
|
||||
// ---- timer ----
|
||||
void TimerRun();
|
||||
void TimerReload();
|
||||
void TimerTickLow();
|
||||
void TickTimers(int elapsed_icount);
|
||||
|
||||
// ---- opcode dispatch ----
|
||||
void ExecuteOne(uint8_t op);
|
||||
|
||||
typedef int (Tms7000::*OpFunc)(uint8_t, uint8_t);
|
||||
int OpClr(uint8_t, uint8_t);
|
||||
int OpDec(uint8_t, uint8_t);
|
||||
int OpInc(uint8_t, uint8_t);
|
||||
int OpInv(uint8_t, uint8_t);
|
||||
int OpRl(uint8_t, uint8_t);
|
||||
int OpRlc(uint8_t, uint8_t);
|
||||
int OpRr(uint8_t, uint8_t);
|
||||
int OpRrc(uint8_t, uint8_t);
|
||||
int OpSwap(uint8_t, uint8_t);
|
||||
int OpXchb(uint8_t, uint8_t);
|
||||
int OpAdc(uint8_t, uint8_t);
|
||||
int OpAdd(uint8_t, uint8_t);
|
||||
int OpAnd(uint8_t, uint8_t);
|
||||
int OpCmp(uint8_t, uint8_t);
|
||||
int OpDac(uint8_t, uint8_t);
|
||||
int OpDsb(uint8_t, uint8_t);
|
||||
int OpMpy(uint8_t, uint8_t);
|
||||
int OpMov(uint8_t, uint8_t);
|
||||
int OpOr(uint8_t, uint8_t);
|
||||
int OpSbb(uint8_t, uint8_t);
|
||||
int OpSub(uint8_t, uint8_t);
|
||||
int OpXor(uint8_t, uint8_t);
|
||||
int OpDjnz(uint8_t, uint8_t);
|
||||
int OpBtjo(uint8_t, uint8_t);
|
||||
int OpBtjz(uint8_t, uint8_t);
|
||||
|
||||
void AmA(OpFunc op);
|
||||
void AmB(OpFunc op);
|
||||
void AmR(OpFunc op);
|
||||
void AmA2a(OpFunc op);
|
||||
void AmA2b(OpFunc op);
|
||||
void AmA2r(OpFunc op);
|
||||
void AmA2p(OpFunc op);
|
||||
void AmB2a(OpFunc op);
|
||||
void AmB2b(OpFunc op);
|
||||
void AmB2r(OpFunc op);
|
||||
void AmB2p(OpFunc op);
|
||||
void AmR2a(OpFunc op);
|
||||
void AmR2b(OpFunc op);
|
||||
void AmR2r(OpFunc op);
|
||||
void AmI2a(OpFunc op);
|
||||
void AmI2b(OpFunc op);
|
||||
void AmI2r(OpFunc op);
|
||||
void AmI2p(OpFunc op);
|
||||
void AmP2a(OpFunc op);
|
||||
void AmP2b(OpFunc op);
|
||||
|
||||
void ShortBranch(bool check);
|
||||
void Jmp(bool check);
|
||||
void BrDir(); void BrInx(); void BrInd();
|
||||
void CallDir(); void CallInx(); void CallInd();
|
||||
void CmpaDir(); void CmpaInx(); void CmpaInd();
|
||||
void DecdA(); void DecdB(); void DecdR();
|
||||
void Dint(); void Eint(); void Idle();
|
||||
void LdaDir(); void LdaInx(); void LdaInd();
|
||||
void Ldsp();
|
||||
void MovdDir(); void MovdInx(); void MovdInd();
|
||||
void Nop();
|
||||
void PopA(); void PopB(); void PopR(); void PopSt();
|
||||
void PushA(); void PushB(); void PushR(); void PushSt();
|
||||
void Reti(); void Rets();
|
||||
void Setc();
|
||||
void StaDir(); void StaInx(); void StaInd();
|
||||
void Stsp();
|
||||
void Trap(uint8_t address);
|
||||
void Illegal(uint8_t op);
|
||||
};
|
||||
|
||||
} // namespace ssc
|
||||
Reference in new issue
Block a user