io(placeholder): add naive io structure
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
20
include/io.hh
Normal file
20
include/io.hh
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays)
|
||||
|
||||
namespace matar {
|
||||
class IoRegisters {
|
||||
public:
|
||||
uint8_t read(uint32_t) const;
|
||||
void write(uint32_t, uint8_t);
|
||||
|
||||
private:
|
||||
struct {
|
||||
bool post_boot_flag = false;
|
||||
bool interrupt_master_enabler = false;
|
||||
} system;
|
||||
};
|
||||
}
|
||||
|
||||
// NOLINTEND(cppcoreguidelines-avoid-c-arrays)
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "header.hh"
|
||||
#include "io.hh"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -51,6 +52,7 @@ class Memory {
|
||||
|
||||
#undef MEMORY_REGION
|
||||
|
||||
IoRegisters io;
|
||||
std::unordered_map<uint32_t, uint8_t> invalid_mem;
|
||||
std::vector<uint8_t> rom;
|
||||
Header header;
|
||||
|
40
src/io.cc
Normal file
40
src/io.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "io.hh"
|
||||
#include "util/log.hh"
|
||||
|
||||
namespace matar {
|
||||
#define ADDR static constexpr uint32_t
|
||||
|
||||
ADDR POSTFLG = 0x4000300;
|
||||
ADDR IME = 0x4000208;
|
||||
|
||||
#undef ADDR
|
||||
|
||||
uint8_t
|
||||
IoRegisters::read(uint32_t address) const {
|
||||
switch (address) {
|
||||
case POSTFLG:
|
||||
return system.post_boot_flag;
|
||||
case IME:
|
||||
return system.interrupt_master_enabler;
|
||||
default:
|
||||
glogger.warn("Unused IO address read at 0x{:08X}", address);
|
||||
}
|
||||
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
void
|
||||
IoRegisters::write(uint32_t address, uint8_t byte) {
|
||||
switch (address) {
|
||||
case POSTFLG:
|
||||
system.post_boot_flag = byte & 1;
|
||||
break;
|
||||
case IME:
|
||||
system.interrupt_master_enabler = byte & 1;
|
||||
break;
|
||||
default:
|
||||
glogger.warn("Unused IO address written at 0x{:08X}", address);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
@@ -41,6 +41,10 @@ Memory::read(uint32_t address) const {
|
||||
MATCHES(BIOS, bios)
|
||||
MATCHES(BOARD_WRAM, board_wram)
|
||||
MATCHES(CHIP_WRAM, chip_wram)
|
||||
|
||||
if (address >= 0x04000000 && address <= 0x040003FE)
|
||||
return io.read(address);
|
||||
|
||||
MATCHES(PALETTE_RAM, palette_ram)
|
||||
MATCHES(VRAM, vram)
|
||||
MATCHES(OAM_OBJ_ATTR, oam_obj_attr)
|
||||
@@ -64,6 +68,12 @@ Memory::write(uint32_t address, uint8_t byte) {
|
||||
|
||||
MATCHES(BOARD_WRAM, board_wram)
|
||||
MATCHES(CHIP_WRAM, chip_wram)
|
||||
|
||||
if (address >= 0x04000000 && address <= 0x040003FE) {
|
||||
io.write(address, byte);
|
||||
return;
|
||||
}
|
||||
|
||||
MATCHES(PALETTE_RAM, palette_ram)
|
||||
MATCHES(VRAM, vram)
|
||||
MATCHES(OAM_OBJ_ATTR, oam_obj_attr)
|
||||
|
@@ -1,6 +1,7 @@
|
||||
lib_sources = files(
|
||||
'memory.cc',
|
||||
'bus.cc'
|
||||
'bus.cc',
|
||||
'io.cc'
|
||||
)
|
||||
|
||||
subdir('util')
|
||||
|
Reference in New Issue
Block a user