chore: stage bunch of size_t to uint32_t

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-06-11 22:52:07 +05:30
parent 028c80f6cb
commit 0062ad424b
5 changed files with 23 additions and 24 deletions

View File

@@ -8,14 +8,14 @@ class Bus {
public: public:
Bus(const Memory& memory); Bus(const Memory& memory);
uint8_t read_byte(size_t address); uint8_t read_byte(uint32_t address);
void write_byte(size_t address, uint8_t byte); void write_byte(uint32_t address, uint8_t byte);
uint16_t read_halfword(size_t address); uint16_t read_halfword(uint32_t address);
void write_halfword(size_t address, uint16_t halfword); void write_halfword(uint32_t address, uint16_t halfword);
uint32_t read_word(size_t address); uint32_t read_word(uint32_t address);
void write_word(size_t address, uint32_t word); void write_word(uint32_t address, uint32_t word);
private: private:
std::shared_ptr<Memory> memory; std::shared_ptr<Memory> memory;

View File

@@ -10,15 +10,16 @@
namespace matar { namespace matar {
class Memory { class Memory {
public: public:
static constexpr size_t BIOS_SIZE = 1024 * 16; static constexpr uint32_t BIOS_SIZE = 1024 * 16;
Memory(std::array<uint8_t, BIOS_SIZE>&& bios, std::vector<uint8_t>&& rom); Memory(std::array<uint8_t, BIOS_SIZE>&& bios, std::vector<uint8_t>&& rom);
uint8_t read(size_t address) const; uint8_t read(uint32_t address) const;
void write(size_t address, uint8_t byte); void write(uint32_t address, uint8_t byte);
private: private:
#define MEMORY_REGION(name, start) static constexpr size_t name##_START = start; #define MEMORY_REGION(name, start) \
static constexpr uint32_t name##_START = start;
#define DECL_MEMORY(name, ident, start, end) \ #define DECL_MEMORY(name, ident, start, end) \
MEMORY_REGION(name, start) \ MEMORY_REGION(name, start) \
@@ -50,7 +51,7 @@ class Memory {
#undef MEMORY_REGION #undef MEMORY_REGION
std::unordered_map<size_t, uint8_t> invalid_mem; std::unordered_map<uint32_t, uint8_t> invalid_mem;
std::vector<uint8_t> rom; std::vector<uint8_t> rom;
Header header; Header header;
void parse_header(); void parse_header();

View File

@@ -7,17 +7,17 @@ Bus::Bus(const Memory& memory)
: memory(std::make_shared<Memory>(memory)) {} : memory(std::make_shared<Memory>(memory)) {}
uint8_t uint8_t
Bus::read_byte(size_t address) { Bus::read_byte(uint32_t address) {
return memory->read(address); return memory->read(address);
} }
void void
Bus::write_byte(size_t address, uint8_t byte) { Bus::write_byte(uint32_t address, uint8_t byte) {
memory->write(address, byte); memory->write(address, byte);
} }
uint16_t uint16_t
Bus::read_halfword(size_t address) { Bus::read_halfword(uint32_t address) {
if (address & 0b01) if (address & 0b01)
glogger.warn("Reading a non aligned halfword address"); glogger.warn("Reading a non aligned halfword address");
@@ -25,7 +25,7 @@ Bus::read_halfword(size_t address) {
} }
void void
Bus::write_halfword(size_t address, uint16_t halfword) { Bus::write_halfword(uint32_t address, uint16_t halfword) {
if (address & 0b01) if (address & 0b01)
glogger.warn("Writing to a non aligned halfword address"); glogger.warn("Writing to a non aligned halfword address");
@@ -34,7 +34,7 @@ Bus::write_halfword(size_t address, uint16_t halfword) {
} }
uint32_t uint32_t
Bus::read_word(size_t address) { Bus::read_word(uint32_t address) {
if (address & 0b11) if (address & 0b11)
glogger.warn("Reading a non aligned word address"); glogger.warn("Reading a non aligned word address");
@@ -43,7 +43,7 @@ Bus::read_word(size_t address) {
} }
void void
Bus::write_word(size_t address, uint32_t word) { Bus::write_word(uint32_t address, uint32_t word) {
if (address & 0b11) if (address & 0b11)
glogger.warn("Writing to a non aligned word address"); glogger.warn("Writing to a non aligned word address");

View File

@@ -57,7 +57,7 @@ sub(uint32_t a, uint32_t b, bool& carry, bool& overflow) {
uint32_t result = a - b; uint32_t result = a - b;
carry = b <= a; carry = a >= b;
overflow = s1 != s2 && s2 == get_bit(result, 31); overflow = s1 != s2 && s2 == get_bit(result, 31);
return result; return result;

View File

@@ -1,9 +1,7 @@
#include "memory.hh" #include "memory.hh"
#include "header.hh" #include "header.hh"
#include "util/bits.hh"
#include "util/crypto.hh" #include "util/crypto.hh"
#include "util/log.hh" #include "util/log.hh"
#include <bitset>
#include <stdexcept> #include <stdexcept>
namespace matar { namespace matar {
@@ -35,7 +33,7 @@ Memory::Memory(std::array<uint8_t, BIOS_SIZE>&& bios,
}; };
uint8_t uint8_t
Memory::read(size_t address) const { Memory::read(uint32_t address) const {
#define MATCHES(AREA, area) \ #define MATCHES(AREA, area) \
if (address >= AREA##_START && address < AREA##_START + area.size()) \ if (address >= AREA##_START && address < AREA##_START + area.size()) \
return area[address - AREA##_START]; return area[address - AREA##_START];
@@ -57,7 +55,7 @@ Memory::read(size_t address) const {
} }
void void
Memory::write(size_t address, uint8_t byte) { Memory::write(uint32_t address, uint8_t byte) {
#define MATCHES(AREA, area) \ #define MATCHES(AREA, area) \
if (address >= AREA##_START && address < AREA##_START + area.size()) { \ if (address >= AREA##_START && address < AREA##_START + area.size()) { \
area[address - AREA##_START] = byte; \ area[address - AREA##_START] = byte; \
@@ -159,7 +157,7 @@ Memory::parse_header() {
if (rom[0xB2] != 0x96) if (rom[0xB2] != 0x96)
glogger.error("HEADER: invalid fixed byte at 0xB2"); glogger.error("HEADER: invalid fixed byte at 0xB2");
for (size_t i = 0xB5; i < 0xBC; i++) { for (uint32_t i = 0xB5; i < 0xBC; i++) {
if (rom[i] != 0x00) if (rom[i] != 0x00)
glogger.error("HEADER: invalid fixed bytes at 0xB5"); glogger.error("HEADER: invalid fixed bytes at 0xB5");
} }
@@ -168,7 +166,7 @@ Memory::parse_header() {
// checksum // checksum
{ {
size_t i = 0xA0, chk = 0; uint32_t i = 0xA0, chk = 0;
while (i <= 0xBC) while (i <= 0xBC)
chk -= rom[i++]; chk -= rom[i++];
chk -= 0x19; chk -= 0x19;