11#pragma once
22#include " stdafx.h"
3- #include " MMC3.h"
4- #include " MemoryManager.h"
3+ #include " MMC3_215.h"
54
6- class Unl158B : public MMC3
5+ class Unl158B : public MMC3_215
76{
87private:
9- const uint8_t _protectionLut[8 ] = { 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x04 , 0x0F , 0x00 };
8+ const uint8_t _protectionLut[8 ][8 ] = {
9+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
10+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 },
11+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x04 , 0x00 , 0x00 },
12+ { 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x04 , 0x05 , 0x00 },
13+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
14+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
15+ { 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 },
16+ { 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x04 , 0x0F , 0x00 }
17+ };
18+
1019 uint8_t _reg;
1120
1221protected:
1322 bool AllowRegisterRead () override { return true ; }
1423
1524 void InitMapper () override
1625 {
17- _reg = 0 ;
26+ _reg = 7 ;
27+ MMC3_215::InitMapper ();
1828 AddRegisterRange (0x5000 , 0x5FFF , MemoryOperation::Any);
1929 RemoveRegisterRange (0x8000 , 0xFFFF , MemoryOperation::Read);
20- MMC3::InitMapper ();
21- }
22-
23- void Reset (bool softReset) override
24- {
25- _reg = 0 ;
26- ResetMmc3 ();
27- MMC3::Reset (softReset);
2830 }
2931
3032 void StreamState (bool saving) override
3133 {
32- MMC3 ::StreamState (saving);
34+ MMC3_215 ::StreamState (saving);
3335 Stream (_reg);
3436 }
3537
36- void SelectPRGPage (uint16_t slot, uint16_t page, PrgMemoryType memoryType = PrgMemoryType::PrgRom) override
37- {
38- if (_reg & 0x80 ) {
39- uint32_t bank = _reg & 0x07 ;
40- if (_reg & 0x20 ) {
41- SelectPrgPage4x (0 , (bank & 0x06 ) << 1 );
42- } else {
43- SelectPrgPage2x (0 , bank << 1 );
44- SelectPrgPage2x (1 , bank << 1 );
45- }
46- } else {
47- MMC3::SelectPRGPage (slot, page & 0x0F );
48- }
49- }
50-
5138 uint8_t ReadRegister (uint16_t addr) override
5239 {
53- return _console->GetMemoryManager ()->GetOpenBus () | _protectionLut[addr & 0x07 ];
40+ return ( _console->GetMemoryManager ()->GetOpenBus () & 0xF0 ) | _protectionLut[_reg] [addr & 0x07 ];
5441 }
5542
5643 void WriteRegister (uint16_t addr, uint8_t value) override
5744 {
58- if (addr <= 0x5FFF ) {
59- if ((addr & 0x07 ) == 0 ) {
60- _reg = value;
61- UpdatePrgMapping ();
62- }
63- } else {
64- MMC3::WriteRegister (addr, value);
45+ if ((addr <= 0x5FFF ) && ((addr & 0xF007 ) == 0x5002 )) {
46+ _reg = value & 0x07 ;
6547 }
48+ MMC3_215::WriteRegister (addr, value);
6649 }
6750};
0 commit comments