trunk/src/mess/machine/nes_act53.c
r0 | r27514 | |
| 1 | /*********************************************************************************************************** |
| 2 | |
| 3 | |
| 4 | NES/Famicom cartridge emulation for Action 53 |
| 5 | |
| 6 | Copyright MESS Team. |
| 7 | Visit http://mamedev.org for licensing and usage restrictions. |
| 8 | |
| 9 | |
| 10 | Here we emulate the Multi-Discrete PCB designed by Tepples for |
| 11 | this homebew multicart [mapper 28] |
| 12 | |
| 13 | ***********************************************************************************************************/ |
| 14 | |
| 15 | |
| 16 | #include "emu.h" |
| 17 | #include "machine/nes_act53.h" |
| 18 | |
| 19 | |
| 20 | #ifdef NES_PCB_DEBUG |
| 21 | #define VERBOSE 1 |
| 22 | #else |
| 23 | #define VERBOSE 0 |
| 24 | #endif |
| 25 | |
| 26 | #define LOG_MMC(x) do { if (VERBOSE) logerror x; } while (0) |
| 27 | |
| 28 | |
| 29 | //------------------------------------------------- |
| 30 | // constructor |
| 31 | //------------------------------------------------- |
| 32 | |
| 33 | const device_type NES_ACTION53 = &device_creator<nes_action53_device>; |
| 34 | |
| 35 | |
| 36 | nes_action53_device::nes_action53_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 37 | : nes_nrom_device(mconfig, NES_ACTION53, "NES Cart Action 53 PCB", tag, owner, clock, "nes_action53", __FILE__) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | void nes_action53_device::device_start() |
| 44 | { |
| 45 | common_start(); |
| 46 | save_item(NAME(m_sel)); |
| 47 | save_item(NAME(m_reg)); |
| 48 | m_reg[0] = 0x00; |
| 49 | m_reg[1] = 0x0f; |
| 50 | m_reg[2] = 0x00; |
| 51 | m_reg[3] = 0x3f; |
| 52 | } |
| 53 | |
| 54 | void nes_action53_device::pcb_reset() |
| 55 | { |
| 56 | m_chr_source = m_vrom_chunks ? CHRROM : CHRRAM; |
| 57 | // register content is not touched by reset |
| 58 | update_prg(); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /*------------------------------------------------- |
| 63 | mapper specific handlers |
| 64 | -------------------------------------------------*/ |
| 65 | |
| 66 | /*------------------------------------------------- |
| 67 | |
| 68 | Board ACTION 53 |
| 69 | |
| 70 | In MESS: *VERY* preliminary support. |
| 71 | |
| 72 | This board uses 4 registers (reg is selected by writes to 0x5xxx) |
| 73 | Info from nesdev wiki |
| 74 | |
| 75 | R:$00: [...M ..CC] |
| 76 | C = CHR Reg |
| 77 | M = Mirroring |
| 78 | This bit overwrites bit 0 of R:$80, but only if bit 1 of |
| 79 | R:$80 is clear |
| 80 | |
| 81 | R:$01: [...M PPPP] |
| 82 | P = PRG Reg |
| 83 | M = Mirroring |
| 84 | This bit overwrites bit 0 of R:$80, but only if bit 1 of |
| 85 | R:$80 is clear |
| 86 | |
| 87 | R:$80: [..GG PSMM] |
| 88 | G = Game Size (0=32K, 1=64K, 2=128K, 3=256K) |
| 89 | P = PRG Size (0=32k mode, 1=16k mode) |
| 90 | S = Slot select: |
| 91 | 0 = $C000 swappable, $8000 fixed to bottom of 32K outer bank |
| 92 | 1 = $8000 swappable, $C000 fixed to top of 32K outer bank |
| 93 | This bit is ignored when 'P' is clear (32k mode) |
| 94 | M = Mirroring control: |
| 95 | %00 = 1ScA |
| 96 | %01 = 1ScB |
| 97 | %10 = Vert |
| 98 | %11 = Horz |
| 99 | |
| 100 | R:$81: [..BB BBBB] |
| 101 | Outer PRG Reg |
| 102 | |
| 103 | |
| 104 | -------------------------------------------------*/ |
| 105 | |
| 106 | void nes_action53_device::update_prg() |
| 107 | { |
| 108 | UINT8 prg_lo = 0, prg_hi = 0, helper = 0; |
| 109 | UINT8 out = (m_reg[3] & 0x3f) << 1; // Outer PRG reg |
| 110 | UINT8 size = (m_reg[2] & 0x30) >> 4; // Game size |
| 111 | UINT8 mask = (1 << (size + 1)) - 1; // Bits to be taken from PRG reg |
| 112 | |
| 113 | if (!BIT(m_reg[2], 3)) |
| 114 | { |
| 115 | helper = (out & ~mask) | ((m_reg[1] << 1) & mask); |
| 116 | //32K mode |
| 117 | prg_lo = (helper & 0xfe); |
| 118 | prg_hi = (helper | 0x01); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | helper = (out & ~mask) | (m_reg[1] & mask); |
| 123 | if (BIT(m_reg[2], 2)) |
| 124 | { |
| 125 | //16K mode with fixed HI |
| 126 | prg_lo = helper; |
| 127 | prg_hi = (out | 0x01); |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | //16K mode with fixed LO |
| 132 | prg_lo = (out & 0xfe); |
| 133 | prg_hi = helper; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // printf("banks : 0x%2X - 0x%2X\n", prg_lo, prg_hi); |
| 138 | prg16_89ab(prg_lo); |
| 139 | prg16_cdef(prg_hi); |
| 140 | } |
| 141 | |
| 142 | void nes_action53_device::update_mirr() |
| 143 | { |
| 144 | switch (m_reg[2] & 0x03) |
| 145 | { |
| 146 | case 0: |
| 147 | set_nt_mirroring(PPU_MIRROR_LOW); |
| 148 | break; |
| 149 | case 1: |
| 150 | set_nt_mirroring(PPU_MIRROR_HIGH); |
| 151 | break; |
| 152 | case 2: |
| 153 | set_nt_mirroring(PPU_MIRROR_VERT); |
| 154 | break; |
| 155 | case 3: |
| 156 | set_nt_mirroring(PPU_MIRROR_HORZ); |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | WRITE8_MEMBER(nes_action53_device::write_l) |
| 162 | { |
| 163 | LOG_MMC(("action 53 write_l, offset: %04x, data: %02x\n", offset, data)); |
| 164 | offset += 0x100; |
| 165 | if (offset >= 0x1000) |
| 166 | m_sel = BIT(data, 0) | (BIT(data, 7) << 1); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | WRITE8_MEMBER(nes_action53_device::write_h) |
| 171 | { |
| 172 | LOG_MMC(("action 53 write_h, offset: %04x, data: %02x\n", offset, data)); |
| 173 | |
| 174 | if (m_reg[m_sel] != data) |
| 175 | { |
| 176 | m_reg[m_sel] = data; |
| 177 | |
| 178 | switch (m_sel) |
| 179 | { |
| 180 | case 0: |
| 181 | if (!BIT(m_reg[2],1)) |
| 182 | { |
| 183 | m_reg[2] &= 0xfe; |
| 184 | m_reg[2] |= BIT(data,4); |
| 185 | update_mirr(); |
| 186 | } |
| 187 | chr8(m_reg[0] & 0x03, m_chr_source); |
| 188 | break; |
| 189 | case 1: |
| 190 | if (!BIT(m_reg[2],1)) |
| 191 | { |
| 192 | m_reg[2] &= 0xfe; |
| 193 | m_reg[2] |= BIT(data,4); |
| 194 | update_mirr(); |
| 195 | } |
| 196 | update_prg(); |
| 197 | break; |
| 198 | case 2: |
| 199 | update_prg(); |
| 200 | update_mirr(); |
| 201 | break; |
| 202 | case 3: |
| 203 | update_prg(); |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | } |