131
131
crystal_state(const machine_config &mconfig, device_type type, const char *tag)
132
: driver_device(mconfig, type, tag) { }
132
: driver_device(mconfig, type, tag) ,
133
m_sysregs(*this, "sysregs"),
134
m_workram(*this, "workram"),
135
m_vidregs(*this, "vidregs"),
136
m_textureram(*this, "textureram"),
137
m_frameram(*this, "frameram"),
138
m_reset_patch(*this, "reset_patch"){ }
134
140
/* memory pointers */
136
UINT32 * m_textureram;
141
required_shared_ptr<UINT32> m_sysregs;
142
required_shared_ptr<UINT32> m_workram;
143
required_shared_ptr<UINT32> m_vidregs;
144
required_shared_ptr<UINT32> m_textureram;
145
required_shared_ptr<UINT32> m_frameram;
146
required_shared_ptr<UINT32> m_reset_patch;
140
147
// UINT32 * m_nvram; // currently this uses generic nvram handling
142
149
#ifdef IDLE_LOOP_SPEEDUP
153
160
UINT32 m_DMActrl[2];
154
161
UINT8 m_OldPort4;
155
UINT32 *m_ResetPatch;
157
163
device_t *m_maincpu;
164
ds1302_device *m_ds1302;
159
165
device_t *m_vr0video;
166
DECLARE_READ32_MEMBER(FlipCount_r);
167
DECLARE_WRITE32_MEMBER(FlipCount_w);
168
DECLARE_READ32_MEMBER(Input_r);
169
DECLARE_WRITE32_MEMBER(IntAck_w);
170
DECLARE_WRITE32_MEMBER(Banksw_w);
171
DECLARE_WRITE32_MEMBER(Timer0_w);
172
DECLARE_READ32_MEMBER(Timer0_r);
173
DECLARE_WRITE32_MEMBER(Timer1_w);
174
DECLARE_READ32_MEMBER(Timer1_r);
175
DECLARE_WRITE32_MEMBER(Timer2_w);
176
DECLARE_READ32_MEMBER(Timer2_r);
177
DECLARE_WRITE32_MEMBER(Timer3_w);
178
DECLARE_READ32_MEMBER(Timer3_r);
179
DECLARE_READ32_MEMBER(FlashCmd_r);
180
DECLARE_WRITE32_MEMBER(FlashCmd_w);
181
DECLARE_READ32_MEMBER(PIO_r);
182
DECLARE_WRITE32_MEMBER(PIO_w);
183
DECLARE_READ32_MEMBER(DMA0_r);
184
DECLARE_WRITE32_MEMBER(DMA0_w);
185
DECLARE_READ32_MEMBER(DMA1_r);
186
DECLARE_WRITE32_MEMBER(DMA1_w);
162
189
static void IntReq( running_machine &machine, int num )
180
static READ32_HANDLER( FlipCount_r )
207
READ32_MEMBER(crystal_state::FlipCount_r)
182
crystal_state *state = space->machine().driver_data<crystal_state>();
184
210
#ifdef IDLE_LOOP_SPEEDUP
185
UINT32 IntPend = space->read_dword(0x01800c0c);
186
state->m_FlipCntRead++;
187
if (state->m_FlipCntRead >= 16 && !IntPend && state->m_FlipCount != 0)
188
device_suspend(state->m_maincpu, SUSPEND_REASON_SPIN, 1);
211
UINT32 IntPend = space.read_dword(0x01800c0c);
213
if (m_FlipCntRead >= 16 && !IntPend && m_FlipCount != 0)
214
device_suspend(m_maincpu, SUSPEND_REASON_SPIN, 1);
190
return ((UINT32) state->m_FlipCount) << 16;
216
return ((UINT32) m_FlipCount) << 16;
193
static WRITE32_HANDLER( FlipCount_w )
219
WRITE32_MEMBER(crystal_state::FlipCount_w)
195
crystal_state *state = space->machine().driver_data<crystal_state>();
197
222
if (mem_mask & 0x00ff0000)
199
224
int fc = (data >> 16) & 0xff;
201
state->m_FlipCount++;
202
227
else if (fc == 0)
203
state->m_FlipCount = 0;
207
static READ32_HANDLER( Input_r )
232
READ32_MEMBER(crystal_state::Input_r)
209
crystal_state *state = space->machine().driver_data<crystal_state>();
212
return input_port_read(space->machine(), "P1_P2");
236
return ioport("P1_P2")->read();
213
237
else if (offset == 1)
214
return input_port_read(space->machine(), "P3_P4");
238
return ioport("P3_P4")->read();
215
239
else if( offset == 2)
217
UINT8 Port4 = input_port_read(space->machine(), "SYSTEM");
218
if (!(Port4 & 0x10) && ((state->m_OldPort4 ^ Port4) & 0x10)) //coin buttons trigger IRQs
219
IntReq(space->machine(), 12);
220
if (!(Port4 & 0x20) && ((state->m_OldPort4 ^ Port4) & 0x20))
221
IntReq(space->machine(), 19);
222
state->m_OldPort4 = Port4;
223
return /*dips*/input_port_read(space->machine(), "DSW") | (Port4 << 16);
241
UINT8 Port4 = ioport("SYSTEM")->read();
242
if (!(Port4 & 0x10) && ((m_OldPort4 ^ Port4) & 0x10)) //coin buttons trigger IRQs
243
IntReq(machine(), 12);
244
if (!(Port4 & 0x20) && ((m_OldPort4 ^ Port4) & 0x20))
245
IntReq(machine(), 19);
247
return /*dips*/ioport("DSW")->read() | (Port4 << 16);
228
static WRITE32_HANDLER( IntAck_w )
252
WRITE32_MEMBER(crystal_state::IntAck_w)
230
crystal_state *state = space->machine().driver_data<crystal_state>();
231
UINT32 IntPend = space->read_dword(0x01800c0c);
254
UINT32 IntPend = space.read_dword(0x01800c0c);
233
256
if (mem_mask & 0xff)
235
258
IntPend &= ~(1 << (data & 0x1f));
236
space->write_dword(0x01800c0c, IntPend);
259
space.write_dword(0x01800c0c, IntPend);
238
device_set_input_line(state->m_maincpu, SE3208_INT, CLEAR_LINE);
261
device_set_input_line(m_maincpu, SE3208_INT, CLEAR_LINE);
240
263
if (mem_mask & 0xff00)
241
state->m_IntHigh = (data >> 8) & 7;
264
m_IntHigh = (data >> 8) & 7;
244
267
static IRQ_CALLBACK( icallback )
258
281
return 0; //This should never happen
261
static WRITE32_HANDLER( Banksw_w )
284
WRITE32_MEMBER(crystal_state::Banksw_w)
263
crystal_state *state = space->machine().driver_data<crystal_state>();
265
state->m_Bank = (data >> 1) & 7;
266
if (state->m_Bank <= 2)
267
memory_set_bankptr(space->machine(), "bank1", space->machine().region("user1")->base() + state->m_Bank * 0x1000000);
287
m_Bank = (data >> 1) & 7;
289
membank("bank1")->set_base(machine().root_device().memregion("user1")->base() + m_Bank * 0x1000000);
269
memory_set_bankptr(space->machine(), "bank1", space->machine().region("user2")->base());
291
membank("bank1")->set_base(machine().root_device().memregion("user2")->base());
272
294
static TIMER_CALLBACK( Timercb )
299
321
COMBINE_DATA(&state->m_Timerctrl[which]);
302
static WRITE32_HANDLER( Timer0_w )
304
Timer_w(space, 0, data, mem_mask);
307
static READ32_HANDLER( Timer0_r )
309
crystal_state *state = space->machine().driver_data<crystal_state>();
310
return state->m_Timerctrl[0];
313
static WRITE32_HANDLER( Timer1_w )
315
Timer_w(space, 1, data, mem_mask);
318
static READ32_HANDLER( Timer1_r )
320
crystal_state *state = space->machine().driver_data<crystal_state>();
321
return state->m_Timerctrl[1];
324
static WRITE32_HANDLER( Timer2_w )
326
Timer_w(space, 2, data, mem_mask);
329
static READ32_HANDLER( Timer2_r )
331
crystal_state *state = space->machine().driver_data<crystal_state>();
332
return state->m_Timerctrl[2];
335
static WRITE32_HANDLER( Timer3_w )
337
Timer_w(space, 3, data, mem_mask);
340
static READ32_HANDLER( Timer3_r )
342
crystal_state *state = space->machine().driver_data<crystal_state>();
343
return state->m_Timerctrl[3];
346
static READ32_HANDLER( FlashCmd_r )
348
crystal_state *state = space->machine().driver_data<crystal_state>();
350
if ((state->m_FlashCmd & 0xff) == 0xff)
324
WRITE32_MEMBER(crystal_state::Timer0_w)
326
Timer_w(&space, 0, data, mem_mask);
329
READ32_MEMBER(crystal_state::Timer0_r)
331
return m_Timerctrl[0];
334
WRITE32_MEMBER(crystal_state::Timer1_w)
336
Timer_w(&space, 1, data, mem_mask);
339
READ32_MEMBER(crystal_state::Timer1_r)
341
return m_Timerctrl[1];
344
WRITE32_MEMBER(crystal_state::Timer2_w)
346
Timer_w(&space, 2, data, mem_mask);
349
READ32_MEMBER(crystal_state::Timer2_r)
351
return m_Timerctrl[2];
354
WRITE32_MEMBER(crystal_state::Timer3_w)
356
Timer_w(&space, 3, data, mem_mask);
359
READ32_MEMBER(crystal_state::Timer3_r)
361
return m_Timerctrl[3];
364
READ32_MEMBER(crystal_state::FlashCmd_r)
367
if ((m_FlashCmd & 0xff) == 0xff)
352
if (state->m_Bank <= 2)
354
UINT32 *ptr = (UINT32*)(space->machine().region("user1")->base() + state->m_Bank * 0x1000000);
371
UINT32 *ptr = (UINT32*)(machine().root_device().memregion("user1")->base() + m_Bank * 0x1000000);
358
375
return 0xffffffff;
360
if ((state->m_FlashCmd & 0xff) == 0x90)
377
if ((m_FlashCmd & 0xff) == 0x90)
362
if (state->m_Bank <= 2)
363
380
return 0x00180089; //Intel 128MBit
365
382
return 0xffffffff;
370
static WRITE32_HANDLER( FlashCmd_w )
372
crystal_state *state = space->machine().driver_data<crystal_state>();
373
state->m_FlashCmd = data;
376
static READ32_HANDLER( PIO_r )
378
crystal_state *state = space->machine().driver_data<crystal_state>();
382
static WRITE32_HANDLER( PIO_w )
384
crystal_state *state = space->machine().driver_data<crystal_state>();
387
WRITE32_MEMBER(crystal_state::FlashCmd_w)
392
READ32_MEMBER(crystal_state::PIO_r)
397
WRITE32_MEMBER(crystal_state::PIO_w)
385
399
UINT32 RST = data & 0x01000000;
386
400
UINT32 CLK = data & 0x02000000;
387
401
UINT32 DAT = data & 0x10000000;
390
state->m_ds1302->reset();
392
ds1302_dat_w(state->m_ds1302, 0, DAT ? 1 : 0);
393
ds1302_clk_w(state->m_ds1302, 0, CLK ? 1 : 0);
395
if (ds1302_read(state->m_ds1302, 0))
396
space->write_dword(0x01802008, space->read_dword(0x01802008) | 0x10000000);
403
m_ds1302->ce_w(RST ? 1 : 0);
404
m_ds1302->io_w(DAT ? 1 : 0);
405
m_ds1302->sclk_w(CLK ? 1 : 0);
407
if (m_ds1302->io_r())
408
space.write_dword(0x01802008, space.read_dword(0x01802008) | 0x10000000);
398
space->write_dword(0x01802008, space->read_dword(0x01802008) & (~0x10000000));
410
space.write_dword(0x01802008, space.read_dword(0x01802008) & (~0x10000000));
400
COMBINE_DATA(&state->m_PIO);
412
COMBINE_DATA(&m_PIO);
403
415
INLINE void DMA_w( address_space *space, int which, UINT32 data, UINT32 mem_mask )
443
455
COMBINE_DATA(&state->m_DMActrl[which]);
446
static READ32_HANDLER( DMA0_r )
448
crystal_state *state = space->machine().driver_data<crystal_state>();
449
return state->m_DMActrl[0];
452
static WRITE32_HANDLER( DMA0_w )
454
DMA_w(space, 0, data, mem_mask);
457
static READ32_HANDLER( DMA1_r )
459
crystal_state *state = space->machine().driver_data<crystal_state>();
460
return state->m_DMActrl[1];
463
static WRITE32_HANDLER( DMA1_w )
465
DMA_w(space, 1, data, mem_mask);
469
static ADDRESS_MAP_START( crystal_mem, AS_PROGRAM, 32 )
458
READ32_MEMBER(crystal_state::DMA0_r)
463
WRITE32_MEMBER(crystal_state::DMA0_w)
465
DMA_w(&space, 0, data, mem_mask);
468
READ32_MEMBER(crystal_state::DMA1_r)
473
WRITE32_MEMBER(crystal_state::DMA1_w)
475
DMA_w(&space, 1, data, mem_mask);
479
static ADDRESS_MAP_START( crystal_mem, AS_PROGRAM, 32, crystal_state )
470
480
AM_RANGE(0x00000000, 0x0001ffff) AM_ROM AM_WRITENOP
472
482
AM_RANGE(0x01200000, 0x0120000f) AM_READ(Input_r)
483
493
AM_RANGE(0x01800810, 0x01800813) AM_READWRITE(DMA1_r, DMA1_w)
485
495
AM_RANGE(0x01800c04, 0x01800c07) AM_WRITE(IntAck_w)
486
AM_RANGE(0x01800000, 0x0180ffff) AM_RAM AM_BASE_MEMBER(crystal_state, m_sysregs)
487
AM_RANGE(0x02000000, 0x027fffff) AM_RAM AM_BASE_MEMBER(crystal_state, m_workram)
496
AM_RANGE(0x01800000, 0x0180ffff) AM_RAM AM_SHARE("sysregs")
497
AM_RANGE(0x02000000, 0x027fffff) AM_RAM AM_SHARE("workram")
489
499
AM_RANGE(0x030000a4, 0x030000a7) AM_READWRITE(FlipCount_r, FlipCount_w)
491
AM_RANGE(0x03000000, 0x0300ffff) AM_RAM AM_BASE_MEMBER(crystal_state, m_vidregs)
492
AM_RANGE(0x03800000, 0x03ffffff) AM_RAM AM_BASE_MEMBER(crystal_state, m_textureram)
493
AM_RANGE(0x04000000, 0x047fffff) AM_RAM AM_BASE_MEMBER(crystal_state, m_frameram)
494
AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE("vrender", vr0_snd_read, vr0_snd_write)
501
AM_RANGE(0x03000000, 0x0300ffff) AM_RAM AM_SHARE("vidregs")
502
AM_RANGE(0x03800000, 0x03ffffff) AM_RAM AM_SHARE("textureram")
503
AM_RANGE(0x04000000, 0x047fffff) AM_RAM AM_SHARE("frameram")
504
AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE_LEGACY("vrender", vr0_snd_read, vr0_snd_write)
496
506
AM_RANGE(0x05000000, 0x05000003) AM_READWRITE(FlashCmd_r, FlashCmd_w)
497
507
AM_RANGE(0x05000000, 0x05ffffff) AM_ROMBANK("bank1")
499
AM_RANGE(0x44414F4C, 0x44414F7F) AM_RAM AM_BASE_MEMBER(crystal_state, m_ResetPatch)
509
AM_RANGE(0x44414F4C, 0x44414F7F) AM_RAM AM_SHARE("reset_patch")
555
565
crystal_state *state = machine.driver_data<crystal_state>();
557
567
if (state->m_Bank <= 2)
558
memory_set_bankptr(machine, "bank1", machine.region("user1")->base() + state->m_Bank * 0x1000000);
568
state->membank("bank1")->set_base(state->memregion("user1")->base() + state->m_Bank * 0x1000000);
560
memory_set_bankptr(machine, "bank1", machine.region("user2")->base());
570
state->membank("bank1")->set_base(state->memregion("user2")->base());
563
573
static MACHINE_START( crystal )
677
688
tail = GetVidReg(space, 0x80);
678
689
while ((head & 0x7ff) != (tail & 0x7ff))
680
DoFlip = vrender0_ProcessPacket(state->m_vr0video, 0x03800000 + head * 64, DrawDest, (UINT8*)state->m_textureram);
691
// ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros!
692
DoFlip = vrender0_ProcessPacket(state->m_vr0video, 0x03800000 + head * 64, DrawDest, reinterpret_cast<UINT8*>(state->m_textureram.target()));