summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/juicebox.cpp
blob: 03f4da0ffd102ed588b50d9fccf6e636d8213097 (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// license:BSD-3-Clause
// copyright-holders:Tim Schuerewegen
/*******************************************************************************

    Mattel Juice Box

    (C) 2011 Tim Schuerewegen

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

#include "emu.h"
#include "cpu/arm7/arm7.h"
#include "machine/s3c44b0.h"
#include "machine/smartmed.h"
#include "sound/dac.h"
#include "sound/volt_reg.h"
#include "emupal.h"
#include "screen.h"
#include "softlist.h"
#include "speaker.h"


//#define JUICEBOX_ENTER_DEBUG_MENU
//#define JUICEBOX_DISPLAY_ROM_ID

#define VERBOSE_LEVEL ( 0 )

struct jb_smc_t
{
	int add_latch;
	int cmd_latch;
	int busy;
};

class juicebox_state : public driver_device
{
public:
	juicebox_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_maincpu(*this, "maincpu")
		, m_s3c44b0(*this, "s3c44b0")
		, m_smartmedia(*this, "smartmedia")
	{ }

	void juicebox(machine_config &config);

	void init_juicebox();

	DECLARE_INPUT_CHANGED_MEMBER(port_changed);

private:
	required_device<cpu_device> m_maincpu;
	required_device<s3c44b0_device> m_s3c44b0;
	required_device<smartmedia_image_device> m_smartmedia;
	uint32_t port[9];
	jb_smc_t smc;

	#if defined(JUICEBOX_ENTER_DEBUG_MENU) || defined(JUICEBOX_DISPLAY_ROM_ID)
	int port_g_read_count;
	#endif
	uint32_t juicebox_nand_r(offs_t offset, uint32_t mem_mask = ~0);
	void juicebox_nand_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
	virtual void machine_start() override;
	virtual void machine_reset() override;
	inline void verboselog(int n_level, const char *s_fmt, ...) ATTR_PRINTF(3,4);
	void smc_reset();
	void smc_init();
	uint8_t smc_read();
	void smc_write(uint8_t data);
	uint32_t s3c44b0_gpio_port_r(offs_t offset);
	void s3c44b0_gpio_port_w(offs_t offset, uint32_t data);
	//void s3c44b0_i2s_data_w(offs_t offset, uint16_t data);
	void juicebox_map(address_map &map);
};

inline void juicebox_state::verboselog(int n_level, const char *s_fmt, ...)
{
	if (VERBOSE_LEVEL >= n_level)
	{
		va_list v;
		char buf[32768];
		va_start( v, s_fmt);
		vsprintf( buf, s_fmt, v);
		va_end( v);
		logerror( "%s: %s", machine().describe_context(), buf);
	}
}


/***************************************************************************
    MACHINE HARDWARE
***************************************************************************/


// SMARTMEDIA

void juicebox_state::smc_reset( )
{
	verboselog(5, "smc_reset\n");
	smc.add_latch = 0;
	smc.cmd_latch = 0;
}

void juicebox_state::smc_init( )
{
	verboselog(5, "smc_init\n");
	smc_reset();
}

uint8_t juicebox_state::smc_read( )
{
	uint8_t data;
	if (m_smartmedia->is_present())
	{
		data = m_smartmedia->data_r();
	}
	else
	{
		data = 0xFF;
	}
	verboselog(5, "smc_read %08X\n", data);
	return data;
}

void juicebox_state::smc_write( uint8_t data)
{
	verboselog(5, "smc_write %08X\n", data);
	if (m_smartmedia->is_present())
	{
		if (smc.cmd_latch)
		{
			verboselog(5, "smartmedia_command_w %08X\n", data);
			m_smartmedia->command_w(data);
		}
		else if (smc.add_latch)
		{
			verboselog(5, "smartmedia_address_w %08X\n", data);
			m_smartmedia->address_w(data);
		}
		else
		{
			verboselog(5, "smartmedia_data_w %08X\n", data);
			m_smartmedia->data_w(data);
		}
	}
}

uint32_t juicebox_state::s3c44b0_gpio_port_r(offs_t offset)
{
	uint32_t data = port[offset];
	switch (offset)
	{
		case S3C44B0_GPIO_PORT_A :
		{
			data = 0x00000210;
		}
		break;
		case S3C44B0_GPIO_PORT_B :
		{
			data = 0x00000000;
		}
		break;
		case S3C44B0_GPIO_PORT_C :
		{
			// 0C0062C4 -> bit 8 is turned on
			//data |= 1 << 13;
			data = 0x0000FF15;
			data &= (1 << 2) | (1 << 9) | (1 << 10) | (1 << 11);
			data |= (1 << 2) | (1 << 9) | (1 << 10) | (1 << 11);
		}
		break;
		case S3C44B0_GPIO_PORT_D :
		{
			data = 0x00000010;
		}
		break;
		case S3C44B0_GPIO_PORT_E :
		{
			data = 0x000000DF;
		}
		break;
		case S3C44B0_GPIO_PORT_F :
		{
			data = data | (0 << 7);
			data = 0x0000009F;
			data &= ~0xE0;
			if (smc.cmd_latch) data = data | 0x00000020;
			if (smc.add_latch) data = data | 0x00000040;
			if (!smc.busy) data = data | 0x00000080;
		}
		break;
		case S3C44B0_GPIO_PORT_G :
		{
			data = 0x0000009F;
			data = (data & ~0x1F) | (ioport( "PORTG")->read() & 0x1F);
			#if defined(JUICEBOX_ENTER_DEBUG_MENU)
			if (port_g_read_count++ < 1)
			{
				data = 0x00000095; // PLAY + REVERSE
			}
			#elif defined(JUICEBOX_DISPLAY_ROM_ID)
			if (port_g_read_count++ < 3)
			{
				data = 0x0000008A; // RETURN + FORWARD + STAR
			}
			#endif
		}
		break;
	}
//  data = ((machine().rand() & 0xFF) << 24) | ((machine().rand() & 0xFF) << 16) | ((machine().rand() & 0xFF) << 8) | ((machine().rand() & 0xFF) << 0);
	return data;
}

void juicebox_state::s3c44b0_gpio_port_w(offs_t offset, uint32_t data)
{
	port[offset] = data;
	switch (offset)
	{
		case S3C44B0_GPIO_PORT_F :
		{
			smc.cmd_latch = ((data & 0x00000020) != 0);
			smc.add_latch = ((data & 0x00000040) != 0);
			verboselog( 5, "s3c44b0_gpio_port_w - nand cle %d ale %d\n", (data & 0x20) ? 1 : 0, (data & 0x40) ? 1 : 0);
		}
		break;
	}
}

// ...

uint32_t juicebox_state::juicebox_nand_r(offs_t offset, uint32_t mem_mask)
{
	uint32_t data = 0;
	if (ACCESSING_BITS_0_7) data = data | (smc_read() <<  0);
	if (ACCESSING_BITS_8_15) data = data | (smc_read() <<  8);
	if (ACCESSING_BITS_16_23) data = data | (smc_read() << 16);
	if (ACCESSING_BITS_24_31) data = data | (smc_read() << 24);
	verboselog( 5, "juicebox_nand_r %08X %08X %08X\n", offset, mem_mask, data);
	return data;
}

void juicebox_state::juicebox_nand_w(offs_t offset, uint32_t data, uint32_t mem_mask)
{
	verboselog( 5, "juicebox_nand_w %08X %08X %08X\n", offset, mem_mask, data);
	if (ACCESSING_BITS_0_7) smc_write((data >>  0) & 0xFF);
	if (ACCESSING_BITS_8_15) smc_write((data >>  8) & 0xFF);
	if (ACCESSING_BITS_16_23) smc_write((data >> 16) & 0xFF);
	if (ACCESSING_BITS_24_31) smc_write((data >> 24) & 0xFF);
}

// ...

INPUT_CHANGED_MEMBER(juicebox_state::port_changed)
{
	m_s3c44b0->request_eint(param);
}

// ...

void juicebox_state::machine_start()
{
	address_space &space = m_maincpu->space(AS_PROGRAM);

	smc_init();

	space.install_readwrite_handler(0x01c00000, 0x01c0000b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::cpuwrap_r)), write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::cpuwrap_w)));
	space.install_readwrite_handler(0x01d00000, 0x01d0002b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::uart_0_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::uart_0_w)));
	space.install_readwrite_handler(0x01d04000, 0x01d0402b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::uart_1_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::uart_1_w)));
	space.install_readwrite_handler(0x01d14000, 0x01d14013, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::sio_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::sio_w)));
	space.install_readwrite_handler(0x01d18000, 0x01d18013, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::iis_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::iis_w)));
	space.install_readwrite_handler(0x01d20000, 0x01d20057, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::gpio_r)),    write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::gpio_w)));
	space.install_readwrite_handler(0x01d30000, 0x01d3000b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::wdt_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::wdt_w)));
	space.install_readwrite_handler(0x01d40000, 0x01d4000b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::adc_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::adc_w)));
	space.install_readwrite_handler(0x01d50000, 0x01d5004f, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::pwm_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::pwm_w)));
	space.install_readwrite_handler(0x01d60000, 0x01d6000f, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::iic_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::iic_w)));
	space.install_readwrite_handler(0x01d80000, 0x01d8000f, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::clkpow_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::clkpow_w)));
	space.install_readwrite_handler(0x01e00000, 0x01e0003f, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::irq_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::irq_w)));
	space.install_readwrite_handler(0x01e80000, 0x01e8001b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::zdma_0_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::zdma_0_w)));
	space.install_readwrite_handler(0x01e80020, 0x01e8003b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::zdma_1_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::zdma_1_w)));
	space.install_readwrite_handler(0x01f00000, 0x01f00047, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::lcd_r)),     write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::lcd_w)));
	space.install_readwrite_handler(0x01f80000, 0x01f8001b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::bdma_0_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::bdma_0_w)));
	space.install_readwrite_handler(0x01f80020, 0x01f8003b, read32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::bdma_1_r)),  write32_delegate(*m_s3c44b0, FUNC(s3c44b0_device::bdma_1_w)));
}

void juicebox_state::machine_reset()
{
	m_maincpu->reset();
	smc_reset();
}

/***************************************************************************
    ADDRESS MAPS
***************************************************************************/

void juicebox_state::juicebox_map(address_map &map)
{
	map(0x00000000, 0x007fffff).rom();
	map(0x04000000, 0x04ffffff).rw(FUNC(juicebox_state::juicebox_nand_r), FUNC(juicebox_state::juicebox_nand_w));
	map(0x0c000000, 0x0c1fffff).ram().mirror(0x00600000);
}

/***************************************************************************
    MACHINE DRIVERS
***************************************************************************/

void juicebox_state::init_juicebox()
{
	// do nothing
}

void juicebox_state::juicebox(machine_config &config)
{
	ARM7(config, m_maincpu, 66000000);
	m_maincpu->set_addrmap(AS_PROGRAM, &juicebox_state::juicebox_map);

	PALETTE(config, "palette").set_entries(32768);

	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_LCD));
	screen.set_refresh_hz(60);
	screen.set_vblank_time(ATTOSECONDS_IN_USEC(2500)); /* not accurate */
	screen.set_size(240, 160);
	screen.set_visarea(0, 240 - 1, 0, 160 - 1);
	screen.set_screen_update("s3c44b0", FUNC(s3c44b0_device::video_update));

	SPEAKER(config, "speaker").front_center();
	DAC_16BIT_R2R_TWOS_COMPLEMENT(config, "dac", 0).add_route(ALL_OUTPUTS, "speaker", 1.0); // unknown DAC
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref"));
	vref.add_route(0, "dac", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "dac", -1.0, DAC_VREF_NEG_INPUT);

	S3C44B0(config, m_s3c44b0, 10000000);
	m_s3c44b0->set_cpu("maincpu");
	m_s3c44b0->gpio_port_r_cb().set(FUNC(juicebox_state::s3c44b0_gpio_port_r));
	m_s3c44b0->gpio_port_w_cb().set(FUNC(juicebox_state::s3c44b0_gpio_port_w));
	m_s3c44b0->i2s_data_w_cb().set("dac", FUNC(dac_word_interface::data_w));

	SMARTMEDIA(config, m_smartmedia, 0);

	/* software lists */
	SOFTWARE_LIST(config, "cart_list").set_original("juicebox");
}

static INPUT_PORTS_START( juicebox )
	PORT_START( "PORTG" )
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_CHANGED_MEMBER(DEVICE_SELF, juicebox_state, port_changed, 0) PORT_NAME("RETURN") PORT_PLAYER(1)
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_CHANGED_MEMBER(DEVICE_SELF, juicebox_state, port_changed, 0) PORT_NAME("PLAY") PORT_PLAYER(1)
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_CHANGED_MEMBER(DEVICE_SELF, juicebox_state, port_changed, 0) PORT_NAME("FORWARD") PORT_PLAYER(1)
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_CHANGED_MEMBER(DEVICE_SELF, juicebox_state, port_changed, 0) PORT_NAME("REVERSE") PORT_PLAYER(1)
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_CHANGED_MEMBER(DEVICE_SELF, juicebox_state, port_changed, 0) PORT_NAME("STAR") PORT_PLAYER(1)
INPUT_PORTS_END

/***************************************************************************
    GAME DRIVERS
***************************************************************************/

ROM_START( juicebox )
	ROM_REGION( 0x800000, "maincpu", 0 )
	ROM_SYSTEM_BIOS( 0, "juicebox", "Juice Box v.28 08242004" )
	ROMX_LOAD( "juicebox.rom", 0, 0x800000, CRC(ac731197) SHA1(8278891c3531b3b6b5fec2a97a3ef6f0de1ac81d), ROM_BIOS(0) )
	ROM_SYSTEM_BIOS( 1, "uclinuxp", "uClinux 2.4.24-uc0 (patched)" )
	ROMX_LOAD( "newboot.rom", 0, 0x1A0800, CRC(443f48b7) SHA1(38f0dc07b5cf02b972a851aa9e87f5d93d03f629), ROM_BIOS(1) )
	ROM_SYSTEM_BIOS( 2, "uclinux", "uClinux 2.4.24-uc0" )
	ROMX_LOAD( "image.rom", 0, 0x19E400, CRC(6c0308bf) SHA1(5fe21a38a4cd0d86bb60920eb100138b0e924d90), ROM_BIOS(2) )
ROM_END

COMP(2004, juicebox, 0, 0, juicebox, juicebox, juicebox_state, init_juicebox, "Mattel", "Juice Box", 0)