Skip to content

Commit

Permalink
Add support for iNES Mapper 007 (AxROM), Mirroring
Browse files Browse the repository at this point in the history
Add support for iNES Mapper 007 (AxROM) which should enable Battletoads
and Marble Madness. Add support for one-screen mirroring.

(bit broken at the moment)
  • Loading branch information
kraln committed Nov 29, 2016
1 parent e98a72e commit 97f8416
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
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
38 changes: 38 additions & 0 deletions src/mappers/mapper7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#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] & 0x7);

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

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

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

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

u8 Mapper7::chr_write(u16 addr, u8 v)
{
return chr[addr] = v;
}
19 changes: 19 additions & 0 deletions src/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);
};
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:
addr = (addr & 0x3ff) + ((mirroring == ONE_SCREEN_HI) ? 0x400 : 0x0);
default: return addr - 0x2000;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/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

0 comments on commit 97f8416

Please sign in to comment.