465
465
/* init rom bank, some games don't set this, and will assume bank 0,set 0 */
467
UINT8 *rom = machine.region("maincpu")->base();
469
memory_configure_bank(machine, "bank1", 0, 8, &rom[0x01000], 0x10000);
471
memory_set_bank(machine, "bank1", 0);
467
UINT8 *rom = state->memregion("maincpu")->base();
469
state->membank("bank1")->configure_entries(0, 8, &rom[0x01000], 0x10000);
471
state->membank("bank1")->set_entry(0);
472
472
machine.device("maincpu")->reset();
517
517
The controls for it exist however, in the form of the Soundboard PIA CB2 pin, which is
518
518
used in some cabinets instead of the main control.
520
static WRITE8_HANDLER( bankswitch_w )
520
WRITE8_MEMBER(mpu4_state::bankswitch_w)
522
mpu4_state *state = space->machine().driver_data<mpu4_state>();
523
522
// printf("bank %02x\n", data);
525
state->m_pageval = (data & 0x03);
526
memory_set_bank(space->machine(), "bank1", (state->m_pageval + (state->m_pageset ? 4 : 0)) & 0x07);
530
static READ8_HANDLER( bankswitch_r )
532
return memory_get_bank(space->machine(), "bank1");
536
static WRITE8_HANDLER( bankset_w )
538
mpu4_state *state = space->machine().driver_data<mpu4_state>();
539
state->m_pageval = (data - 2);//writes 2 and 3, to represent 0 and 1 - a hangover from the half page design?
540
memory_set_bank(space->machine(), "bank1", (state->m_pageval + (state->m_pageset ? 4 : 0)) & 0x07);
524
m_pageval = (data & 0x03);
525
membank("bank1")->set_entry((m_pageval + (m_pageset ? 4 : 0)) & 0x07);
529
READ8_MEMBER(mpu4_state::bankswitch_r)
531
return membank("bank1")->entry();
535
WRITE8_MEMBER(mpu4_state::bankset_w)
537
m_pageval = (data - 2);//writes 2 and 3, to represent 0 and 1 - a hangover from the half page design?
538
membank("bank1")->set_entry((m_pageval + (m_pageset ? 4 : 0)) & 0x07);
1101
1099
coin_lockout_w(device->machine(), 1, (pia_ic5->b_output() & 0x02) );
1102
1100
coin_lockout_w(device->machine(), 2, (pia_ic5->b_output() & 0x04) );
1103
1101
coin_lockout_w(device->machine(), 3, (pia_ic5->b_output() & 0x08) );
1104
return input_port_read(device->machine(), "AUX2") | state->m_aux2_input;
1102
return device->machine().root_device().ioport("AUX2")->read() | state->m_aux2_input;
1417
1415
/* The orange inputs are polled twice as often as the black ones, for reasons of efficiency.
1418
1416
This is achieved via connecting every input line to an AND gate, thus allowing two strobes
1419
1417
to represent each orange input bank (strobes are active low). */
1420
pia_ic5->cb1_w(input_port_read(device->machine(), "AUX2") & 0x80);
1421
return input_port_read(device->machine(), portnames[state->m_input_strobe]);
1418
pia_ic5->cb1_w(device->machine().root_device().ioport("AUX2")->read() & 0x80);
1419
return device->machine().root_device().ioport(portnames[state->m_input_strobe])->read();
1616
1614
/* This is a bit of a cheat - since we don't clock into the OKI chip directly, we need to
1617
1615
calculate the oscillation frequency in advance. We're running the timer for interrupt
1618
1616
purposes, but the frequency calculation is done by plucking the values out as they are written.*/
1619
WRITE8_HANDLER( ic3ss_w )
1617
WRITE8_MEMBER(mpu4_state::ic3ss_w)
1621
device_t *ic3ss = space->machine().device("ptm_ic3ss");
1622
mpu4_state *state = space->machine().driver_data<mpu4_state>();
1619
device_t *ic3ss = machine().device("ptm_ic3ss");
1623
1620
downcast<ptm6840_device *>(ic3ss)->write(offset,data);
1624
device_t *msm6376 = space->machine().device("msm6376");
1621
device_t *msm6376 = machine().device("msm6376");
1626
1623
if (offset == 3)
1630
1627
if (offset == 6)
1632
state->m_t3h = data;
1634
1631
if (offset == 7)
1636
state->m_t3l = data;
1639
float num = (1720000/((state->m_t3l + 1)*(state->m_t3h + 1)));
1640
float denom1 = ((state->m_t3h *(state->m_t3l + 1)+ 1)/(2*(state->m_t1 + 1)));
1636
float num = (1720000/((m_t3l + 1)*(m_t3h + 1)));
1637
float denom1 = ((m_t3h *(m_t3l + 1)+ 1)/(2*(m_t1 + 1)));
1642
1639
int denom2 = denom1 +0.5;//need to round up, this gives same precision as chip
1643
1640
int freq=num*denom2;
2360
static WRITE8_HANDLER( characteriser_w )
2357
WRITE8_MEMBER(mpu4_state::characteriser_w)
2362
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2365
LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X", cpu_get_previouspc(&space->device()),offset,data));
2366
if (!state->m_current_chr_table)
2361
LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X", cpu_get_previouspc(&space.device()),offset,data));
2362
if (!m_current_chr_table)
2368
logerror("No Characteriser Table @ %04x\n", cpu_get_previouspc(&space->device()));
2364
logerror("No Characteriser Table @ %04x\n", cpu_get_previouspc(&space.device()));
2399
2395
// Rather than the search strategy, we can map the calls directly here. Note that they are hex versions of the square number series
2402
state->m_lamp_col = 0;
2405
state->m_lamp_col = 1;
2408
state->m_lamp_col = 2;
2411
state->m_lamp_col = 3;
2414
state->m_lamp_col = 4;
2417
state->m_lamp_col = 5;
2420
state->m_lamp_col = 6;
2423
state->m_lamp_col = 7;
2426
LOG_CHR(("Characteriser find 2 column %02X\n",state->m_lamp_col));
2422
LOG_CHR(("Characteriser find 2 column %02X\n",m_lamp_col));
2431
static READ8_HANDLER( characteriser_r )
2427
READ8_MEMBER(mpu4_state::characteriser_r)
2433
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2434
if (!state->m_current_chr_table)
2429
if (!m_current_chr_table)
2436
logerror("No Characteriser Table @ %04x", cpu_get_previouspc(&space->device()));
2431
logerror("No Characteriser Table @ %04x", cpu_get_previouspc(&space.device()));
2438
2433
/* a cheat ... many early games use a standard check */
2439
int addr = cpu_get_reg(&space->device(), M6809_X);
2434
int addr = cpu_get_reg(&space.device(), M6809_X);
2440
2435
if ((addr>=0x800) && (addr<=0xfff)) return 0x00; // prevent recursion, only care about ram/rom areas for this cheat.
2442
UINT8 ret = space->read_byte(addr);
2437
UINT8 ret = space.read_byte(addr);
2443
2438
logerror(" (returning %02x)",ret);
2445
2440
logerror("\n");
2450
2445
LOG_CHR(("Characteriser read offset %02X \n",offset));
2451
2446
if (offset == 0)
2453
LOG_CHR(("Characteriser read data %02X \n",state->m_current_chr_table[state->m_prot_col].response));
2454
return state->m_current_chr_table[state->m_prot_col].response;
2448
LOG_CHR(("Characteriser read data %02X \n",m_current_chr_table[m_prot_col].response));
2449
return m_current_chr_table[m_prot_col].response;
2456
2451
if (offset == 3)
2458
LOG_CHR(("Characteriser read data off 3 %02X \n",state->m_current_chr_table[state->m_lamp_col+64].response));
2459
return state->m_current_chr_table[state->m_lamp_col+64].response;
2453
LOG_CHR(("Characteriser read data off 3 %02X \n",m_current_chr_table[m_lamp_col+64].response));
2454
return m_current_chr_table[m_lamp_col+64].response;
2502
static WRITE8_HANDLER( bwb_characteriser_w )
2497
WRITE8_MEMBER(mpu4_state::bwb_characteriser_w)
2504
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2507
LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X \n", cpu_get_previouspc(&space->device()),offset,data));
2508
if (!state->m_current_chr_table)
2509
fatalerror("No Characteriser Table @ %04x\n", cpu_get_previouspc(&space->device()));
2501
LOG_CHR_FULL(("%04x Characteriser write offset %02X data %02X \n", cpu_get_previouspc(&space.device()),offset,data));
2502
if (!m_current_chr_table)
2503
fatalerror("No Characteriser Table @ %04x\n", cpu_get_previouspc(&space.device()));
2511
2505
if ((offset & 0x3f)== 0)//initialisation is always at 0x800
2513
if (!state->m_chr_state)
2515
state->m_chr_state=1;
2516
state->m_chr_counter=0;
2520
state->m_init_col ++;
2524
state->m_init_col =0;
2528
state->m_chr_value = space->machine().rand();
2522
m_chr_value = machine().rand();
2529
2523
for (x = 0; x < 4; x++)
2531
if (state->m_current_chr_table[(x)].call == call)
2525
if (m_current_chr_table[(x)].call == call)
2533
2527
if (x == 0) // reinit
2535
state->m_bwb_return = 0;
2537
state->m_chr_value = bwb_chr_table_common[(state->m_bwb_return)];
2538
state->m_bwb_return++;
2531
m_chr_value = bwb_chr_table_common[(m_bwb_return)];
2544
static READ8_HANDLER( bwb_characteriser_r )
2538
READ8_MEMBER(mpu4_state::bwb_characteriser_r)
2546
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2548
2541
LOG_CHR(("Characteriser read offset %02X \n",offset));
2551
2544
if (offset ==0)
2553
switch (state->m_chr_counter)
2546
switch (m_chr_counter)
2561
return state->m_bwb_chr_table1[(((state->m_chr_counter + 1) / 7) - 1)].response;
2554
return m_bwb_chr_table1[(((m_chr_counter + 1) / 7) - 1)].response;
2566
if (state->m_chr_counter > 34)
2559
if (m_chr_counter > 34)
2568
state->m_chr_counter = 35;
2569
state->m_chr_state = 2;
2571
state->m_chr_counter ++;
2572
return state->m_chr_value;
2578
return state->m_chr_value;
2582
2575
/* Common configurations */
2584
static WRITE8_HANDLER( mpu4_ym2413_w )
2577
WRITE8_MEMBER(mpu4_state::mpu4_ym2413_w)
2586
device_t *ym = space->machine().device("ym2413");
2579
device_t *ym = machine().device("ym2413");
2587
2580
if (ym) ym2413_w(ym,offset,data);
2590
static READ8_HANDLER( mpu4_ym2413_r )
2583
READ8_MEMBER(mpu4_state::mpu4_ym2413_r)
2592
// device_t *ym = space->machine().device("ym2413");
2585
// device_t *ym = machine().device("ym2413");
2593
2586
// return ym2413_read(ym,offset);
2598
2591
void mpu4_install_mod4yam_space(address_space *space)
2600
space->install_legacy_read_handler(0x0880, 0x0882, FUNC(mpu4_ym2413_r));
2601
space->install_legacy_write_handler(0x0880, 0x0881, FUNC(mpu4_ym2413_w));
2593
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2594
space->install_read_handler(0x0880, 0x0882, read8_delegate(FUNC(mpu4_state::mpu4_ym2413_r),state));
2595
space->install_write_handler(0x0880, 0x0881, write8_delegate(FUNC(mpu4_state::mpu4_ym2413_w),state));
2604
2598
void mpu4_install_mod4oki_space(address_space *space)
2600
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2606
2601
pia6821_device *pia_ic4ss = space->machine().device<pia6821_device>("pia_ic4ss");
2607
2602
ptm6840_device *ptm_ic3ss = space->machine().device<ptm6840_device>("ptm_ic3ss");
2609
2604
space->install_readwrite_handler(0x0880, 0x0883, 0, 0, read8_delegate(FUNC(pia6821_device::read), pia_ic4ss), write8_delegate(FUNC(pia6821_device::write), pia_ic4ss));
2610
2605
space->install_read_handler(0x08c0, 0x08c7, 0, 0, read8_delegate(FUNC(ptm6840_device::read), ptm_ic3ss));
2611
space->install_legacy_write_handler(0x08c0, 0x08c7, 0, 0, FUNC(ic3ss_w));
2606
space->install_write_handler(0x08c0, 0x08c7, 0, 0, write8_delegate(FUNC(mpu4_state::ic3ss_w),state));
2614
2609
void mpu4_install_mod4bwb_space(address_space *space)
2616
space->install_legacy_readwrite_handler(0x0810, 0x0810, 0, 0, FUNC(bwb_characteriser_r),FUNC(bwb_characteriser_w));
2611
mpu4_state *state = space->machine().driver_data<mpu4_state>();
2612
space->install_readwrite_handler(0x0810, 0x0810, 0, 0, read8_delegate(FUNC(mpu4_state::bwb_characteriser_r),state),write8_delegate(FUNC(mpu4_state::bwb_characteriser_w),state));
2617
2613
mpu4_install_mod4oki_space(space);
2872
2866
mpu4_state *state = machine.driver_data<mpu4_state>();
2873
2867
DRIVER_INIT_CALL(m4default);
2874
2868
state->m_bwb_bank=1;
2875
space->install_legacy_write_handler(0x0858, 0x0858, 0, 0, FUNC(bankswitch_w));
2876
space->install_legacy_write_handler(0x0878, 0x0878, 0, 0, FUNC(bankset_w));
2869
space->install_write_handler(0x0858, 0x0858, 0, 0, write8_delegate(FUNC(mpu4_state::bankswitch_w),state));
2870
space->install_write_handler(0x0878, 0x0878, 0, 0, write8_delegate(FUNC(mpu4_state::bankset_w),state));
2879
static READ8_HANDLER( crystal_sound_r )
2873
READ8_MEMBER(mpu4_state::crystal_sound_r)
2881
return space->machine().rand();
2875
return machine().rand();
2884
static WRITE8_HANDLER( crystal_sound_w )
2878
WRITE8_MEMBER(mpu4_state::crystal_sound_w)
2886
2880
printf("crystal_sound_w %02x\n",data);
2889
2883
static DRIVER_INIT (m_frkstn)
2891
2885
address_space *space = machine.device("maincpu")->memory().space(AS_PROGRAM);
2886
mpu4_state *state = machine.driver_data<mpu4_state>();
2893
2887
DRIVER_INIT_CALL(m4default_bigbank);
2894
space->install_legacy_read_handler(0x0880, 0x0880, 0, 0, FUNC(crystal_sound_r));
2895
space->install_legacy_write_handler(0x0881, 0x0881, 0, 0, FUNC(crystal_sound_w));
2888
space->install_read_handler(0x0880, 0x0880, 0, 0, read8_delegate(FUNC(mpu4_state::crystal_sound_r),state));
2889
space->install_write_handler(0x0881, 0x0881, 0, 0, write8_delegate(FUNC(mpu4_state::crystal_sound_w),state));
2898
2892
/* generate a 50 Hz signal (based on an RC time) */
2908
2902
update_meters(state);//run at 100Hz to sync with PIAs
2911
static ADDRESS_MAP_START( mpu4_memmap, AS_PROGRAM, 8 )
2905
static ADDRESS_MAP_START( mpu4_memmap, AS_PROGRAM, 8, mpu4_state )
2912
2906
AM_RANGE(0x0000, 0x07ff) AM_RAM AM_SHARE("nvram")
2913
2907
AM_RANGE(0x0800, 0x0810) AM_READWRITE(characteriser_r,characteriser_w)
2914
2908
AM_RANGE(0x0850, 0x0850) AM_READWRITE(bankswitch_r,bankswitch_w) /* write bank (rom page select) */
2915
/* AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) */ //Runs hoppers
2916
AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE_MODERN("ptm_ic2", ptm6840_device, read, write)/* PTM6840 IC2 */
2917
AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE_MODERN("pia_ic3", pia6821_device, read, write) /* PIA6821 IC3 */
2918
AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE_MODERN("pia_ic4", pia6821_device, read, write) /* PIA6821 IC4 */
2919
AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE_MODERN("pia_ic5", pia6821_device, read, write) /* PIA6821 IC5 */
2920
AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE_MODERN("pia_ic6", pia6821_device, read, write) /* PIA6821 IC6 */
2921
AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE_MODERN("pia_ic7", pia6821_device, read, write) /* PIA6821 IC7 */
2922
AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE_MODERN("pia_ic8", pia6821_device, read, write) /* PIA6821 IC8 */
2909
/* AM_RANGE(0x08e0, 0x08e7) AM_READWRITE_LEGACY(68681_duart_r,68681_duart_w) */ //Runs hoppers
2910
AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("ptm_ic2", ptm6840_device, read, write)/* PTM6840 IC2 */
2911
AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_device, read, write) /* PIA6821 IC3 */
2912
AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_device, read, write) /* PIA6821 IC4 */
2913
AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_device, read, write) /* PIA6821 IC5 */
2914
AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_device, read, write) /* PIA6821 IC6 */
2915
AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_device, read, write) /* PIA6821 IC7 */
2916
AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_device, read, write) /* PIA6821 IC8 */
2923
2917
AM_RANGE(0x1000, 0xffff) AM_ROMBANK("bank1") /* 64k paged ROM (4 pages) */
2924
2918
ADDRESS_MAP_END
10887
10881
ROM_LOAD( "sv_20a__.4_1", 0x0000, 0x020000, CRC(0e790ae8) SHA1(48f055f3f1f5d3392b7fba1c5c30624c1f230327) )
10888
10882
ROM_LOAD( "sv_20sb_.4_1", 0x0000, 0x020000, CRC(e88c1c29) SHA1(49d180068e4ae9cb65a58e65b4e1ac4d6657ae1d) )
10889
10883
ROM_LOAD( "svi20___.4_1", 0x0000, 0x020000, CRC(643037ed) SHA1(d4063faba3069625474dd761f9ad2dcf2f710a19) )
10884
ROM_LOAD( "sinbadbwb1_1game.bin", 0x0000, 0x020000, CRC(cfe152a7) SHA1(b8ecfa8b763d04515b65eb902c18dba7198191c3) )
10891
10886
ROM_REGION( 0x180000, "msm6376", ROMREGION_ERASE00 )
10887
//These were with the last listed set, though I have no reason to believe they aren't valid for all BwB Sinbad games
10888
ROM_LOAD( "sinbadbwb1_2snd.bin", 0x000000, 0x080000, CRC(2ee60ce6) SHA1(865860639e8471f97ace0beac2f4c7fddb8ca97c) )
10889
ROM_LOAD( "sinbadbwb1_3snd.bin", 0x000000, 0x080000, CRC(7701e5cc) SHA1(4f9ff91f2b6b15a9c08396b52fc8509ba476ed8d) )
15234
15231
DRIVER_INIT( crystal )
15236
15233
DRIVER_INIT_CALL(m_frkstn);
15237
descramble_crystal(machine.region( "maincpu" )->base(), 0x0000, 0x10000, 0x00);
15234
descramble_crystal(machine.root_device().memregion( "maincpu" )->base(), 0x0000, 0x10000, 0x00);
15240
15237
DRIVER_INIT( crystali )
15242
15239
DRIVER_INIT_CALL(m_frkstn);
15243
descramble_crystal(machine.region( "maincpu" )->base(), 0x0000, 0x10000, 0xff); // invert after decrypt?!
15240
descramble_crystal(machine.root_device().memregion( "maincpu" )->base(), 0x0000, 0x10000, 0xff); // invert after decrypt?!