Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/ActivisionMapper.h
2 views
1
/*
2
* Gearcoleco - ColecoVision Emulator
3
* Copyright (C) 2021 Ignacio Sanchez
4
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/
17
*
18
*/
19
20
#ifndef ACTIVISIONMAPPER_H
21
#define ACTIVISIONMAPPER_H
22
23
#include "Mapper.h"
24
#include "Cartridge.h"
25
26
class ActivisionMapper : public Mapper
27
{
28
public:
29
ActivisionMapper(Cartridge* pCartridge);
30
virtual ~ActivisionMapper();
31
32
virtual void Reset();
33
virtual u8 Read(u16 address);
34
virtual void Write(u16 address, u8 value);
35
virtual void SaveState(std::ostream& stream);
36
virtual void LoadState(std::istream& stream);
37
virtual u8 GetRomBank() { return m_RomBank; }
38
virtual u32 GetRomBankAddress() { return m_RomBankAddress; }
39
40
private:
41
u8 m_RomBank;
42
u32 m_RomBankAddress;
43
};
44
45
inline ActivisionMapper::ActivisionMapper(Cartridge* pCartridge) : Mapper(pCartridge)
46
{
47
Reset();
48
}
49
50
inline ActivisionMapper::~ActivisionMapper()
51
{
52
}
53
54
inline void ActivisionMapper::Reset()
55
{
56
m_RomBank = 0;
57
m_RomBankAddress = 0;
58
}
59
60
inline u8 ActivisionMapper::Read(u16 address)
61
{
62
u8* pRom = m_pCartridge->GetROM();
63
64
if (address < 0xC000)
65
{
66
return pRom[address & 0x3FFF];
67
}
68
else
69
{
70
#ifdef DEBUG_GEARCOLECO
71
if (address >= 0xFF80)
72
{
73
Debug("--> ** EEPROM read: %X", address);
74
}
75
#endif
76
return pRom[(address & 0x3FFF) + m_RomBankAddress];
77
}
78
}
79
80
inline void ActivisionMapper::Write(u16 address, u8 value)
81
{
82
if (m_pCartridge->HasSRAM() && (address >= 0xE000) && (address < 0xE800))
83
{
84
u8* pRom = m_pCartridge->GetROM();
85
pRom[(address + 0x800) & 0x7FFF] = value;
86
}
87
else if (address >= 0xFF90)
88
{
89
if ((address == 0xFF90) || (address == 0xFFA0) || (address == 0xFFB0))
90
{
91
m_RomBank = (address >> 4) & (m_pCartridge->GetROMBankCount() - 1);
92
m_RomBankAddress = m_RomBank << 14;
93
}
94
}
95
else
96
{
97
Debug("--> ** Attempting to write on ROM: %X %X", address, value);
98
}
99
}
100
101
inline void ActivisionMapper::SaveState(std::ostream& stream)
102
{
103
stream.write(reinterpret_cast<const char*> (&m_RomBank), sizeof(m_RomBank));
104
stream.write(reinterpret_cast<const char*> (&m_RomBankAddress), sizeof(m_RomBankAddress));
105
}
106
107
inline void ActivisionMapper::LoadState(std::istream& stream)
108
{
109
stream.read(reinterpret_cast<char*> (&m_RomBank), sizeof(m_RomBank));
110
stream.read(reinterpret_cast<char*> (&m_RomBankAddress), sizeof(m_RomBankAddress));
111
}
112
113
#endif /* ACTIVISIONMAPPER_H */
114
115