Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/ColecoVisionIOPorts.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 COLECOVISIONIOPORTS_H
21
#define COLECOVISIONIOPORTS_H
22
23
#include "IOPorts.h"
24
25
class Audio;
26
class Video;
27
class Input;
28
class Cartridge;
29
class CVMemory;
30
class Processor;
31
32
class ColecoVisionIOPorts : public IOPorts
33
{
34
public:
35
ColecoVisionIOPorts(Audio* pAudio, Video* pVideo, Input* pInput, Cartridge* pCartridge, CVMemory* pMemory, Processor* pProcessor);
36
~ColecoVisionIOPorts();
37
void Reset();
38
u8 In(u8 port);
39
void Out(u8 port, u8 value);
40
private:
41
Audio* m_pAudio;
42
Video* m_pVideo;
43
Input* m_pInput;
44
Cartridge* m_pCartridge;
45
CVMemory* m_pMemory;
46
Processor* m_pProcessor;
47
};
48
49
#include "Video.h"
50
#include "Audio.h"
51
#include "Input.h"
52
#include "Cartridge.h"
53
#include "CVMemory.h"
54
#include "Processor.h"
55
56
inline u8 ColecoVisionIOPorts::In(u8 port)
57
{
58
switch(port & 0xE0) {
59
case 0xA0:
60
{
61
if (port & 0x01)
62
{
63
return m_pVideo->GetStatusFlags();
64
}
65
else
66
{
67
return m_pVideo->GetDataPort();
68
}
69
break;
70
}
71
case 0xE0:
72
{
73
return m_pInput->ReadInput(port);
74
}
75
default:
76
{
77
if (port == 0x52)
78
{
79
return m_pAudio->SGMRead();
80
}
81
return 0xFF;
82
}
83
}
84
85
Debug("--> ** Attempting to read from port $%X", port);
86
87
return 0xFF;
88
}
89
90
inline void ColecoVisionIOPorts::Out(u8 port, u8 value)
91
{
92
switch(port & 0xE0) {
93
case 0x80:
94
{
95
m_pInput->SetInputSegment(Input::SegmentKeypadRightButtons);
96
break;
97
}
98
case 0xA0:
99
{
100
if (port & 0x01)
101
{
102
m_pVideo->WriteControl(value);
103
}
104
else
105
{
106
m_pVideo->WriteData(value);
107
}
108
break;
109
}
110
case 0xC0:
111
{
112
m_pInput->SetInputSegment(Input::SegmentJoystickLeftButtons);
113
break;
114
}
115
case 0xE0:
116
{
117
m_pAudio->WriteAudioRegister(value);
118
m_pProcessor->InjectTStates(32);
119
break;
120
}
121
default:
122
{
123
if (port == 0x50)
124
{
125
m_pAudio->SGMRegister(value);
126
break;
127
}
128
else if (port == 0x51)
129
{
130
m_pAudio->SGMWrite(value);
131
break;
132
}
133
else if (port == 0x53)
134
{
135
m_pMemory->EnableSGMUpper((value & 0x01) != 0);
136
}
137
else if (port == 0x7F)
138
{
139
m_pMemory->EnableSGMLower((~value & 0x02) != 0);
140
m_pMemory->EnableSGMUpper((value & 0x01) != 0);
141
}
142
else
143
{
144
Debug("--> ** Output to port $%X: %X", port, value);
145
}
146
}
147
}
148
}
149
150
#endif /* COLECOVISIONIOPORTS_H */
151
152