forked from badman12345/osmose-rpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOMapper_GG.cpp
142 lines (133 loc) · 3.57 KB
/
IOMapper_GG.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
137
138
139
140
141
142
/*****************************************************************************
*
* File: IOMapper_GG.cpp
*
* Project: Osmose emulator.
*
* Description: This class will handle GAMEGEAR emulator input/output operation.
*
* Author: Vedder Bruno
* Date: 08/10/2004, 18h00
*
* URL: http://bcz.emu-france.com/
*****************************************************************************/
#include "IOMapper_GG.h"
#include <stdlib.h>
// Constructor.
IOMapper_GG::IOMapper_GG(VDP &v, SN76489 &p) : IOMapper(v, p)
{
reset();
}
// Reset GAMEGEAR additionnal ports.
void IOMapper_GG::reset()
{
IOMapper::reset();
port0x0 = 0xC0;
port0x1 = 0x7F;
port0x2 = 0xFF;
port0x3 = 0x00;
port0x4 = 0xFF;
port0x5 = 0x00;
port0x6 = 0xFF;
}
/*----------------------------------------------------------------------*/
/* Based on Charles MacDonald documentation, this method dispatches */
/* port read, depending on A7, A6 and A0 address line. */
/*----------------------------------------------------------------------*/
unsigned char IOMapper_GG::in8(unsigned port)
{
if (port == 0x0) return port0x0;
if (port == 0x1) return port0x1;
if (port == 0x2) return port0x2;
if (port == 0x3) return port0x3;
if (port == 0x4) return port0x4;
if (port == 0x5) return port0x5;
if (port == 0x6) return port0x6;
if (port == 0x3E)
{
return port3E;
cout << "MEM CTRL Port 0x3E: Read, value is " << hex << setw(2) << setfill('0') << (int)port3E << endl;
}
if (port <= 0x3F)
{
//cout << "NOT IMPLEMENTED / EXPERIMENTAL: Read port <=0x3f" << endl;
return (port & 0xff);
}
if (port <= 0x7F)
{
if (port & BIT0) // Read H counter port.
{
#ifdef VDP_VERBOSE
cout << "NOT IMPLEMENTED: VDP port H COUTNER 0x7F read."<< endl;
#endif
return 0xFF;
}
else // Read on VDP Vertical counter
{
#ifdef VDP_VERBOSE
cout << "VDP, port V COUTNER 0x7E read."<< endl;
#endif
return vdp.v_counter;
}
}
if (port <= 0xBF) // Read VDP status flag
{
if (port & BIT0)
{
#ifdef VDP_VERBOSE
cout << "VDP status read."<< endl;
#endif
return vdp.readStatusFlag();
}
else // Read VDP Data port
{
#ifdef VDP_VERBOSE
cout << "CRAM/VRAM read."<< endl;
#endif
return vdp.readDataPort();
}
}
// Port is > 0xBF and < 0xFF
if (port & BIT0)
{
#ifdef PAD_VERBOSE
cout << "Port PAD2 0xDD read."<< endl;
#endif
return portPAD2;
}
else
{
#ifdef PAD_VERBOSE
cout << "Port PAD1 0xDC read."<< endl;
#endif
if (opt.inputType == PADDLE)
{
flipFlop^=1;
if (flipFlop == true)
{
portPAD1 |= BIT5;
portPAD1 &= 0xf0;
portPAD1 |= (paddleValue >> 4);
}
else
{
portPAD1 &= ~BIT5;
portPAD1 &= 0xf0;
portPAD1 |= (paddleValue & 0x0f);
}
}
return portPAD1;
}
cout << "Unkown port "<< hex << setw(2) << setfill('0') << (int)port << " read."<< endl;
}
void IOMapper_GG::out8(unsigned address, unsigned char data)
{
/* Call parent method. */
if (address == 0) {port0x0 = data; return;}
if (address == 1) {port0x1 = data; return;}
if (address == 2) {port0x2 = data; return;}
if (address == 3) {port0x3 = data; return;}
if (address == 4) {port0x4 = data; return;}
if (address == 5) {port0x5 = data; return;}
IOMapper::out8( address, data);
}