aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTa180m2020-05-18 13:29:08 -0500
committerTa180m2020-05-18 13:29:08 -0500
commitfce6a15b48b96d3aff30103786f2481c2a450f86 (patch)
tree7e3f46b4c21b11884085e4ea872461943b3ab244
parent522577f7442bd3e590999a332a6a36559fe6b582 (diff)
Added Mapper 7v1.1
-rw-r--r--README.md6
-rw-r--r--main.cpp27
2 files changed, 27 insertions, 6 deletions
diff --git a/README.md b/README.md
index cde3e67..7a30cf4 100644
--- a/README.md
+++ b/README.md
@@ -36,13 +36,13 @@ C++ 1 5 85 708
### *nix systems
```sh
git clone --recursive https://github.com/Ta180m/BadNES && cd BadNES
-g++ main.cpp -o badnes -std=c++11 -lSDL2main -lSDL2
+g++ main.cpp -o badnes -std=c++11 -lSDL2main -lSDL2 -O3
```
### Windows
```sh
git clone --recursive https://github.com/Ta180m/BadNES && cd BadNES
-g++ main.cpp -o badnes -std=c++11 -IC:\mingw\include\SDL2 -LC:\mingw\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2
+g++ main.cpp -o badnes -std=c++11 -IC:\mingw\include\SDL2 -LC:\mingw\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -O3
```
## Usage
@@ -72,7 +72,7 @@ I really like LaiNES: it's very minimal and compact — but it has several depen
I'm working on it right now.
### What do you mean by "nearly complete"?
-I'll say it's complete once I finish implementing the APU, savestates, and maybe Mapper 7.
+I'll say it's complete once I finish implementing the APU and savestates.
## Credits
Special thanks to [Andrea Orru](https://github.com/AndreaOrru) for creating [LaiNES](https://github.com/AndreaOrru/LaiNES), the emulator that this project derives much of its code from. \ No newline at end of file
diff --git a/main.cpp b/main.cpp
index 1ba7550..6b58e16 100644
--- a/main.cpp
+++ b/main.cpp
@@ -36,7 +36,7 @@ namespace CPU {
}
namespace PPU {
enum Scanline { VISIBLE, POST, NMI, PRE };
- enum Mirroring { VERTICAL, HORIZONTAL };
+ enum Mirroring { VERTICAL, HORIZONTAL, ONE_SCREEN_HI, ONE_SCREEN_LO, FOUR_SCREEN };
struct Sprite { // Sprite buffer
// Index in OAM, X position, Y position, Tile index, Attributes, Tile data (low), Tile data (high)
u8 id, x, y, tile, attr, dataL, dataH;
@@ -146,8 +146,10 @@ class Mapper1 : public Mapper {
if (regs[0] & 0b10000) { map_chr<4>(0, regs[1]); map_chr<4>(1, regs[2]); } // 4KB CHR
else map_chr<8>(0, regs[1] >> 1); // 8KB CHR
switch (regs[0] & 0b11) { // Set mirroring
- 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;
}
}
public:
@@ -258,6 +260,22 @@ public:
if (irqEnabled and irqCounter == 0) CPU::set_irq();
}
};
+class Mapper7 : public Mapper {
+ u8 regs[1];
+ // Apply the registers state
+ void apply() {
+ map_prg<32>(0, regs[0] & 0b00001111); // 32 kb PRG ROM Banks, 0x8000 - 0xFFFF swappable
+ map_chr<8>(0, 0); // 8k of CHR (ram)
+ set_mirroring((regs[0] & 0b00010000) ? PPU::ONE_SCREEN_HI : PPU::ONE_SCREEN_LO); // Mirroring based on bit 5
+ }
+public:
+ Mapper7(u8* rom) : Mapper(rom) { regs[0] = 0; apply(); }
+ u8 write(u16 addr, u8 v) {
+ if (addr & 0x8000) { regs[0] = v; apply(); } // Bank switching
+ return v;
+ }
+ u8 chr_write(u16 addr, u8 v) { return chr[addr] = v; }
+};
// Actual code
namespace APU {
@@ -477,6 +495,8 @@ namespace PPU {
switch (mirroring) {
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;
}
}
@@ -715,6 +735,7 @@ namespace Cartridge {
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(), PPU::reset();
}