- [NEW] MBC3 implementat

This commit is contained in:
2025-01-30 17:14:09 +01:00
parent 454cce304f
commit f8ce706839
3 changed files with 166 additions and 1 deletions

24
mem.cpp
View File

@@ -7,6 +7,7 @@
#include "mbc_none.h"
#include "mbc1.h"
#include "mbc3.h"
#define DIV hram[0x104] // 0xff04 - 0xfe00
#define TIMA hram[0x105] // 0xff05 - 0xfe00
@@ -19,6 +20,7 @@ namespace mem
void (*writeRom)(uint16_t, uint8_t);
uint8_t (*readRam)(uint16_t);
void (*writeRam)(uint16_t, uint8_t);
void (*tick)(void) = nullptr;;
uint8_t bootrom[256];
uint8_t *rom;
@@ -29,8 +31,10 @@ namespace mem
uint8_t tags[65536];
char *title = nullptr;
uint8_t mapper_type = 0;
uint32_t rom_size = 0;
uint32_t ram_size = 0;
uint16_t timer = 0;
uint16_t dma_address = 0;
uint8_t dma_pos = 160;
@@ -42,7 +46,7 @@ namespace mem
void init(uint8_t* rom, const int size)
{
title = (char*)&rom[0x134];
uint8_t mapper_type = rom[0x147];
mapper_type = rom[0x147];
rom_size = 32768 * (1 << rom[0x148]);
int sizes[] = { 0, 0, 8, 32, 128, 64};
ram_size = sizes[rom[0x149]] * 1024;
@@ -67,6 +71,19 @@ namespace mem
mem::readRam = mbc1::readRam;
mem::writeRam = mbc1::writeRam;
break;
case 0x0f:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
mbc3::init(rom, rom_size, ram_size);
mem::resetMbc = mbc3::reset;
mem::readRom = mbc3::readRom;
mem::writeRom = mbc3::writeRom;
mem::readRam = mbc3::readRam;
mem::writeRam = mbc3::writeRam;
mem::tick = mbc3::tick;
break;
};
APU::init();
@@ -207,6 +224,11 @@ namespace mem
uint16_t timer_frequencies[4] { 256*4, 4*4, 16*4, 64*4 };
void update_mapped(const uint32_t dt)
{
timer+=dt;
if (timer >= 4194304 ) {
timer -= 4194304;
if (mem::tick) mem::tick();
}
// DIV Divider register (0xFF04) (val com a timer bàsic)
div_counter += dt;
if (div_counter>=256) {