ch81/cores/board.h

55 lines
1.5 KiB
C
Raw Permalink Normal View History

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