-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGMCCartridge.cpp
138 lines (101 loc) · 2.35 KB
/
GMCCartridge.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "GMCCartridge.h"
#include <Windows.h>
#undef AddMenuSeparator
#undef AddMenuItem
#undef LoadMenu
GMCCartridge::GMCCartridge()
: Cartridge("Game Master Catridge", "SN76489")
{}
void GMCCartridge::LoadConfiguration(const std::string& filename)
{
Cartridge::LoadConfiguration(filename);
m_Configuration = Configuration(filename);
}
void GMCCartridge::LoadMenu()
{
AddMenuItem("", 0, ItemType::Head);
AddMenuSeparator();
AddMenuItem("Select GMC ROM", 5000 + MenuItems::SelectRom, ItemType::StandAlone);
AddMenuItem("", 1, ItemType::Head);
}
std::string GMCCartridge::GetStatusMessage() const
{
std::string message("GMC Active");
const auto activeRom(ExtractFilename(m_ROMImage.GetFilename()));
if (m_ROMImage.HasImage())
{
message += " (" + activeRom + " Loaded)";
}
else
{
message += activeRom.empty() ? " (No ROM Selected)" : "(Unable to load `" + activeRom + "`)";
}
return message;
}
void GMCCartridge::OnMenuItemSelected(unsigned char menuId)
{
if (menuId == MenuItems::SelectRom)
{
const auto selectedFile(SelectROMFile());
// if (!selectedFile.has_value())
if (selectedFile.empty())
{
return;
}
//if (!m_ROMImage.Load(*selectedFile))
//{
// MessageBoxA(nullptr, "Unable to open file", "Error", MB_OK);
// return;
//}
MessageBoxA(
nullptr,
"A new ROM file has been you selected. Press F9 to reset\nyour Color Computer and activate the ROM.",
"ROM Selected",
MB_OK);
m_Configuration.SetActiveRom(selectedFile.data());
AssetCartridgeLine(false);
AssetCartridgeLine(true);
}
}
void GMCCartridge::OnReset()
{
m_PSG.device_start();
if (m_ROMImage.Load(m_Configuration.GetActiveRom()))
{
AssetCartridgeLine(false);
AssetCartridgeLine(true);
}
else
{
m_ROMImage.Unload();
}
}
unsigned short GMCCartridge::UpdateAudio()
{
SN76489Device::stream_sample_t lbuffer, rbuffer;
return m_PSG.sound_stream_update(lbuffer, rbuffer);
}
unsigned char GMCCartridge::OnReadMemory(unsigned short address) const
{
return m_ROMImage.Read(address);
}
void GMCCartridge::OnWritePort(unsigned char port, unsigned char data)
{
switch (port)
{
case Ports::BankSelect:
m_ROMImage.SetBank(data);
break;
case Ports::PSG:
m_PSG.write(data);
break;
}
}
unsigned char GMCCartridge::OnReadPort(unsigned char port) const
{
if (port == Ports::BankSelect)
{
return m_ROMImage.GetBank();
}
return 0;
}