Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper 7 support #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "mappers/mapper2.hpp"
#include "mappers/mapper3.hpp"
#include "mappers/mapper4.hpp"
#include "mappers/mapper7.hpp"
#include "ppu.hpp"
#include "cartridge.hpp"

Expand Down Expand Up @@ -57,6 +58,7 @@ void load(const char* fileName)
case 2: mapper = new Mapper2(rom); break;
case 3: mapper = new Mapper3(rom); break;
case 4: mapper = new Mapper4(rom); break;
case 7: mapper = new Mapper7(rom); break;
}

CPU::power();
Expand Down
19 changes: 19 additions & 0 deletions src/include/mappers/mapper7.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "mapper.hpp"
#include "ppu.hpp"

class Mapper7 : public Mapper
{
u8 regs[1];
void apply();

public:
Mapper7(u8* rom) : Mapper(rom)
{
regs[0] = 0;
apply();
}

u8 write(u16 addr, u8 v);
u8 chr_write(u16 addr, u8 v);
};
2 changes: 1 addition & 1 deletion src/include/ppu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PPU {


enum Scanline { VISIBLE, POST, NMI, PRE };
enum Mirroring { VERTICAL, HORIZONTAL };
enum Mirroring { VERTICAL, HORIZONTAL, ONE_SCREEN_HI, ONE_SCREEN_LO, FOUR_SCREEN };

/* Sprite buffer */
struct Sprite
Expand Down
6 changes: 4 additions & 2 deletions src/mappers/mapper1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ void Mapper1::apply()
// Set mirroring:
switch (regs[0] & 0b11)
{
case 2: set_mirroring(PPU::VERTICAL); break;
case 3: set_mirroring(PPU::HORIZONTAL); break;
case 0: set_mirroring(PPU::ONE_SCREEN_LO); break;
case 1: set_mirroring(PPU::ONE_SCREEN_HI); break;
case 2: set_mirroring(PPU::VERTICAL); break;
case 3: set_mirroring(PPU::HORIZONTAL); break;
}
}

Expand Down
39 changes: 39 additions & 0 deletions src/mappers/mapper7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "ppu.hpp"
#include "mappers/mapper7.hpp"

/* Based off of https://wiki.nesdev.com/w/index.php/AxROM */

/* Apply the registers state */
void Mapper7::apply()
{
/*
* 32 kb PRG ROM Banks
* 0x8000 - 0xFFFF swappable
*/
map_prg<32>(0, regs[0] & 0b00001111);

/* 8k of CHR (ram) */
map_chr<8>(0, 0);

/* Mirroring based on bit 5 */
set_mirroring((regs[0] & 0b00010000) ? PPU::ONE_SCREEN_HI : PPU::ONE_SCREEN_LO);
}

u8 Mapper7::write(u16 addr, u8 v)
{
/* check for bus contingency? (addr & 0x8000 == v?)
* Seems not neccesary */

/* bank switching */
if (addr & 0x8000)
{
regs[0] = v;
apply();
}
return v;
}

u8 Mapper7::chr_write(u16 addr, u8 v)
{
return chr[addr] = v;
}
3 changes: 3 additions & 0 deletions src/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ u16 nt_mirror(u16 addr)
{
case VERTICAL: return addr % 0x800;
case HORIZONTAL: return ((addr / 2) & 0x400) + (addr % 0x400);
case ONE_SCREEN_LO:
case ONE_SCREEN_HI:
return ((addr & 0x3ff) + ((mirroring == ONE_SCREEN_HI) ? 0x400 : 0x0)) - 0x2000;
default: return addr - 0x2000;
}
}
Expand Down