ch81/cores/board.h
Michael Hope 334aea068c
All checks were successful
/ core (push) Successful in 5m37s
ch81: add a LICENSE and README
2026-05-14 12:13:31 +02:00

55 lines
1.5 KiB
C++

/*
* Copyright 2026 Michael Hope <michaelh@juju.nz>
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <cstdint>
#include <span>
namespace ch81 {
// Board implements the board specific memory and IO.
class Board {
public:
virtual ~Board() = default;
// Returns a pointer to the emulated memory at `address`, if any.
[[nodiscard]] virtual uint8_t* map(uint16_t address) = 0;
// Reads a byte from memory at `address`.
[[nodiscard]] virtual uint8_t read(uint16_t address) = 0;
// Writes `value` to memory at `address`. If `address` is not emulated then
// the write is discarded.
virtual void write(uint16_t address, uint8_t value) = 0;
// Fetches an instruction byte from `address`. A specialised version of
// `read`.
[[nodiscard]] virtual uint8_t fetch(uint16_t address) = 0;
// Reads a byte from I/O port `port`.
[[nodiscard]] virtual uint8_t in(uint16_t port) = 0;
// Writes `value` to I/O port `port`. If `port` is not emulated then the write
// is discarded.
virtual void out(uint8_t port, uint8_t value) = 0;
// Returns true if a jump to `target` should also cause an emulator exit.
[[nodiscard]] virtual bool trap_jump(uint16_t target) = 0;
// Returns true if an interrupt is pending. May update state.
[[nodiscard]] virtual bool irqs() = 0;
[[nodiscard]] virtual uint16_t read16(uint16_t address) {
return read(address) | (read(address + 1) << 8);
}
virtual void write16(uint16_t address, uint16_t value) {
write(address, value & 0xFF);
write(address + 1, value >> 8);
}
};
} // namespace ch81