forked from ulfalizer/nesalizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapper_1.cpp
More file actions
92 lines (78 loc) · 2.53 KB
/
mapper_1.cpp
File metadata and controls
92 lines (78 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// MMC1
#include "common.h"
#include "log.h"
#include "mapper.h"
#include "rom.h"
static unsigned temp_reg;
static unsigned nth_write;
static unsigned regs[4];
static void make_effective() {
switch (regs[0] & 3) {
case 0: set_mirroring(ONE_SCREEN_LOW); break;
case 1: set_mirroring(ONE_SCREEN_HIGH); break;
case 2: set_mirroring(VERTICAL); break;
case 3: set_mirroring(HORIZONTAL); break;
}
if (regs[0] & 8) {
// 16K PRG mode
if (regs[0] & 4) {
// $8000 swappable, $C000 fixed to page $0F
set_prg_16k_bank(0, regs[3] & 0x0F);
set_prg_16k_bank(1, 0x0F);
}
else {
// $8000 fixed to page $00, $C000 swappable
set_prg_16k_bank(0, 0);
set_prg_16k_bank(1, regs[3] & 0x0F);
}
}
else
// 32K PRG mode
set_prg_32k_bank((regs[3] & 0x0F) >> 1);
if (regs[0] & 0x10) {
// 4K CHR mode
set_chr_4k_bank(0, regs[1]);
set_chr_4k_bank(1, regs[2]);
}
else
set_chr_8k_bank(regs[1] >> 1);
}
void mapper_1_init() {
// Specified
regs[0] |= 0x0C; // 16K PRG swapping (0x08), swapping 8000-BFFF (0x04)
// Guess
nth_write = temp_reg = regs[1] = regs[2] = regs[3] = 0;
make_effective();
}
void mapper_1_write(uint8_t value, uint16_t addr) {
// static uint64_t last_write_cycle;
LOG_MAPPER("MMC1: Writing $%02X to $%04X\n", value, addr);
// Writes after the first write are ignored for writes on consecutive CPU
// cycles. Bill & Ted's Excellent Adventure needs this.
// TODO: This breaks the Polynes demo. Investigate if it runs on the real
// thing.
//if (ppu_cycle == last_write_cycle + 3) return;
//last_write_cycle = ppu_cycle;
if (value & 0x80) {
nth_write = 0;
temp_reg = 0;
regs[0] |= 0x0C; // 16K PRG swapping (0x08), swapping 8000-BFFF (0x04)
make_effective();
}
else {
temp_reg = ((value & 1) << 4) | (temp_reg >> 1);
if (++nth_write == 5) {
switch ((addr >> 13) & 3) {
case 0: LOG_MAPPER("MMC1: setting flags"); break;
case 1: LOG_MAPPER("MMC1: setting CHR page 1"); break;
case 2: LOG_MAPPER("MMC1: setting CHR page 2"); break;
case 3: LOG_MAPPER("MMC1: setting PRG page"); break;
}
LOG_MAPPER(" to $%02X\n", temp_reg);
regs[(addr >> 13) & 3] = temp_reg;
nth_write = 0;
temp_reg = 0;
make_effective();
}
}
}