From 0c97143b226e6d85b8fa383bc4b04831e2589090 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 15 Jan 2025 07:34:12 +0100 Subject: [PATCH] - Treballant en el mbc_none --- mbc_none.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mbc_none.h | 6 ++++++ 2 files changed, 62 insertions(+) create mode 100644 mbc_none.cpp create mode 100644 mbc_none.h diff --git a/mbc_none.cpp b/mbc_none.cpp new file mode 100644 index 0000000..848b9b8 --- /dev/null +++ b/mbc_none.cpp @@ -0,0 +1,56 @@ +#include "mbc_none.h" +#include "mem.h" + +namespace mbc_none +{ + uint8_t bootrom[256]; + uint8_t *rom; + uint8_t vram[8192]; + uint8_t exram[8192]; + uint8_t wram[8192]; + uint8_t hram[512]; + + uint8_t readMem(uint16_t address) + { + if (address < 0x8000) { + if ( (address < 0x0100) && ((hram[0x150]&0x01)==0) ) return bootrom[address]; + return rom[address]; + } else if (address < 0xA000) { + return vram[address - 0x8000]; + } else if (address < 0xC000) { + return exram[address - 0xA000]; + } else if (address < 0xE000) { + return wram[address - 0xC000]; + } else if (address < 0xFE00) { + return wram[address - 0xE000]; + } else { + return hram[address - 0XFE00]; + } + } + + void writeMem(uint16_t address, uint8_t value) + { + if (address < 0x8000) { + // Read Only Memory, you know... + //rom[address] = value; + } else if (address < 0xA000) { + vram[address - 0x8000] = value; + } else if (address < 0xC000) { + exram[address - 0xA000] = value; + } else if (address < 0xE000) { + wram[address - 0xC000] = value; + } else if (address < 0xFE00) { + wram[address - 0xE000] = value; + } else { + if ( (address==0xFF50) && ((value&0x01) != 1) ) return; //Only allow disabling boot room + hram[address - 0xFE00] = value; + } + } + + void init(uint8_t *rom) + { + mem::readMem = mbc_none::readMem; + mem::writeMem = mbc_none::writeMem; + mbc_none::rom = rom; + } +} \ No newline at end of file diff --git a/mbc_none.h b/mbc_none.h new file mode 100644 index 0000000..5323160 --- /dev/null +++ b/mbc_none.h @@ -0,0 +1,6 @@ +#pragma once + +namespace mbc_none +{ + void init(); +}