summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/c64/fcc.cpp
blob: 77d505e97a34fbe199dd01c2ae91628aae423441 (plain) (blame)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Tasc Final ChessCard cartridge emulation

**********************************************************************/

/*

    TODO:

    629D ldx #$00
    629F stx $0e
    62A1 sta $df00
    62A4 inc $d020
    62A7 dec $d020
    62AA cpx $0e
    62AC beq $62a4 <-- eternal loop here
    62AE rts

*/

#include "emu.h"
#include "fcc.h"



//**************************************************************************
//  MACROS/CONSTANTS
//**************************************************************************

#define G65SC02P4_TAG   "g65sc02p4"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(C64_FCC, c64_final_chesscard_device, "c64_fcc", "Final ChessCard")


//-------------------------------------------------
//  ROM( c64_fcc )
//-------------------------------------------------

ROM_START( c64_fcc )
	ROM_REGION( 0x8000, G65SC02P4_TAG, 0 )
	ROM_LOAD( "fcc_rom1", 0x0000, 0x8000, CRC(2949836a) SHA1(9e6283095df9e3f4802ed0c654101f8e37168bf6) )
ROM_END


//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const tiny_rom_entry *c64_final_chesscard_device::device_rom_region() const
{
	return ROM_NAME( c64_fcc );
}


//-------------------------------------------------
//  ADDRESS_MAP( c64_fcc_map )
//-------------------------------------------------

void c64_final_chesscard_device::c64_fcc_map(address_map &map)
{
	map(0x0000, 0x1fff).mirror(0x6000).rw(FUNC(c64_final_chesscard_device::nvram_r), FUNC(c64_final_chesscard_device::nvram_w));
	map(0x8000, 0xffff).rom().region(G65SC02P4_TAG, 0);
}


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_START(c64_final_chesscard_device::device_add_mconfig)
	MCFG_DEVICE_ADD(G65SC02P4_TAG, M65SC02, XTAL(5'000'000))
	MCFG_DEVICE_PROGRAM_MAP(c64_fcc_map)
MACHINE_CONFIG_END


//-------------------------------------------------
//  INPUT_PORTS( c64_fcc )
//-------------------------------------------------

static INPUT_PORTS_START( c64_fcc )
	PORT_START("RESET")
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F11) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF_OWNER, c64_expansion_slot_device, reset_w)
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor c64_final_chesscard_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( c64_fcc );
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  c64_final_chesscard_device - constructor
//-------------------------------------------------

c64_final_chesscard_device::c64_final_chesscard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, C64_FCC, tag, owner, clock),
	device_c64_expansion_card_interface(mconfig, *this),
	device_nvram_interface(mconfig, *this),
	m_maincpu(*this, G65SC02P4_TAG),
	m_bank(0),
	m_ramen(0)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void c64_final_chesscard_device::device_start()
{
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void c64_final_chesscard_device::device_reset()
{
	m_maincpu->reset();

	m_bank = 0;
	m_ramen = 0;
	m_game = 0;
}


//-------------------------------------------------
//  c64_cd_r - cartridge data read
//-------------------------------------------------

uint8_t c64_final_chesscard_device::c64_cd_r(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!roml)
	{
		if (m_ramen)
		{
			data = m_nvram[offset & 0x1fff];
		}
		else
		{
			data = m_roml[(m_bank << 14) | (offset & 0x3fff)];
		}
	}
	else if (!romh)
	{
		data = m_roml[(m_bank << 14) | (offset & 0x3fff)];
	}

	return data;
}


//-------------------------------------------------
//  c64_cd_w - cartridge data write
//-------------------------------------------------

void c64_final_chesscard_device::c64_cd_w(address_space &space, offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
{
	if (!roml)
	{
		if (m_ramen)
		{
			m_nvram[offset & 0x1fff] = data;
		}
	}
	else if (!io1)
	{
		/*

		    bit     description

		    0       ?
		    1
		    2
		    3
		    4
		    5
		    6
		    7

		*/

		printf("IO1 %04x %02x\n", offset, data);
		m_bank = BIT(data, 0);
	}
	else if (!io2)
	{
		/*

		    bit     description

		    0       ?
		    1
		    2
		    3
		    4
		    5
		    6
		    7       ?

		*/

		printf("IO2 %04x %02x\n", offset, data);
		m_ramen = BIT(data, 0);
		m_game = BIT(data, 7);
	}
}


//-------------------------------------------------
//  nvram_r - NVRAM read
//-------------------------------------------------

READ8_MEMBER( c64_final_chesscard_device::nvram_r )
{
	return m_nvram[offset & m_nvram.mask()];
}


//-------------------------------------------------
//  nvram_w - NVRAM write
//-------------------------------------------------

WRITE8_MEMBER( c64_final_chesscard_device::nvram_w )
{
	m_nvram[offset & m_nvram.mask()] = data;
}