Damn thats pretty clean Haze. I came up with a solution before I was referred to this post, and its not nearly as clean and it uses the dkong_base machine driver.
static MACHINE_START( d2k )
{
dkong_state *state = machine->driver_data;
state->hardware_type = HARDWARE_TKG04;
state_save_register_global(state->dma_latch);
}
const eeprom_interface eeprom_interface_d2k =
{
7, // address bits 7
8, // data bits 8
"*110", // read 1 10 aaaaaa
"*101", // write 1 01 aaaaaa dddddddddddddddd
"*111", // erase 1 11 aaaaaa
"*10000xxxx", // lock 1 00 00xxxx
"*10011xxxx", // unlock 1 00 11xxxx
1,
// "*10001xxxx" // write all 1 00 01xxxx dddddddddddddddd
// "*10010xxxx" // erase all 1 00 10xxxx
};
NVRAM_HANDLER( d2k )
{
if (read_or_write)
eeprom_save(file);
else
{
eeprom_init(&eeprom_interface_d2k);
if (file) eeprom_load(file);
}
}
static READ8_HANDLER( d2k_eeprom_r )
{
return eeprom_read_bit();
}
static WRITE8_HANDLER( d2k_eeprom_w )
{
eeprom_write_bit(data & 1);
eeprom_set_clock_line( (data & 2) ? ASSERT_LINE : CLEAR_LINE );
eeprom_set_cs_line( (data & 4) ? CLEAR_LINE : ASSERT_LINE );
}
static READ8_HANDLER( d2k_eeprom_unk )
/* This address is read (result discarded), just before CS is asserted */
{
return 0;
}
static WRITE8_HANDLER( d2k_rombank_w )
{
memory_set_bank(1, data & 1 );
memory_set_bank(2, data & 1 );
}
static ADDRESS_MAP_START( d2k_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x5fff) AM_ROMBANK(1)
AM_RANGE(0x0007, 0x0007) AM_WRITENOP
AM_RANGE(0x6000, 0x68ff) AM_RAM
AM_RANGE(0x6900, 0x6a7f) AM_RAM AM_BASE_MEMBER(dkong_state, sprite_ram)
AM_SIZE_MEMBER(dkong_state, sprite_ram_size)
AM_RANGE(0x6a80, 0x73ff) AM_RAM
AM_RANGE(0x7400, 0x77ff) AM_RAM_WRITE(dkong_videoram_w)
AM_BASE_MEMBER(dkong_state, video_ram)
AM_RANGE(0x7800, 0x780f) AM_DEVREADWRITE(DMA8257, "dma8257", dma8257_r, dma8257_w)
AM_RANGE(0x7c00, 0x7c00) AM_READ_PORT("IN0") AM_LATCH8_WRITE("ls175.3d")
AM_RANGE(0x7c80, 0x7c80) AM_READ_PORT("IN1") AM_WRITE(radarscp_grid_color_w)
AM_RANGE(0x7d00, 0x7d00) AM_READ(dkong_in2_r)
AM_RANGE(0x7d00, 0x7d07) AM_DEVWRITE(LATCH8, "ls259.6h", latch8_bit0_w)
AM_RANGE(0x7d80, 0x7d80) AM_READ_PORT("DSW0") AM_WRITE(dkong_audio_irq_w)
AM_RANGE(0x7d81, 0x7d81) AM_WRITE(radarscp_grid_enable_w)
AM_RANGE(0x7d82, 0x7d82) AM_WRITE(dkong_flipscreen_w)
AM_RANGE(0x7d83, 0x7d83) AM_WRITE(dkong_spritebank_w)
AM_RANGE(0x7d84, 0x7d84) AM_WRITE(interrupt_enable_w)
AM_RANGE(0x7d85, 0x7d85) AM_DEVWRITE(DMA8257, "dma8257", p8257_drq_w)
AM_RANGE(0x7d86, 0x7d87) AM_WRITE(dkong_palettebank_w)
AM_RANGE(0xc000, 0xc000) AM_READ(d2k_eeprom_unk)
AM_RANGE(0xc800, 0xc800) AM_READWRITE(d2k_eeprom_r, d2k_eeprom_w)
AM_RANGE(0xd000, 0xdfff) AM_ROM
AM_RANGE(0xe000, 0xe000) AM_WRITE(d2k_rombank_w)
AM_RANGE(0xe800, 0xffff) AM_ROMBANK(2)
ADDRESS_MAP_END
static MACHINE_RESET( d2k )
{
UINT8 *ROM = memory_region(machine, "main");
MACHINE_RESET_CALL(dkong);
memory_configure_bank(1, 0, 2, &ROM[0x10000], 0x8000); // rom at 0-0x5fff is banked (dk or d2k)
memory_configure_bank(2, 0, 2, &ROM[0x16800], 0x8000); // 2nd bank
d2k_rombank_w( machine, 0, 0); // select dk at bootup
}
static MACHINE_DRIVER_START( d2k )
MDRV_IMPORT_FROM(dkong_base)
MDRV_CPU_MODIFY("main")
MDRV_CPU_PROGRAM_MAP(d2k_map,0)
MDRV_NVRAM_HANDLER(d2k)
MDRV_SCREEN_MODIFY("main")
MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1) // needed to disguise a bug in the test screen
MDRV_MACHINE_START(d2k)
MDRV_MACHINE_RESET(d2k)
/* sound hardware */
MDRV_IMPORT_FROM(dkong2b_audio)
MACHINE_DRIVER_END
static DRIVER_INIT( d2k )
{
UINT8 *ROM = memory_region(machine, "main");
int i, m, n;
/* Fix data lines */
for( i = 0x20000; i < 0x30000; i++ )
ROM[i] = BITSWAP8( ROM[i], 1, 4, 5, 7, 6, 0, 3, 2 );
/* Fix address lines */
for (i = 0; i < 0x100; i++)
{
m = (BITSWAP8( i, 7, 2, 0, 1, 5, 6, 4, 3 ) << 8) | 0x20000;
n = (i << 8) | 0x10000;
memcpy( &ROM[n], &ROM[m], 0x100);
}
/* the lines below are to fix a bug that appears in the test screen if the width is set any wider,
but adding this fix breaks the rom checksum. So, cheated by making the screen narrower. */
// ROM[0x14e69] = 0; // fix error in clear-screen routine - v1.2
// ROM[0x14e77] = 0; // fix error in clear-screen routine - v1.1
memcpy( &ROM[0xd000], &ROM[0x1d000], 0x1000); // mirror for E830 trickery
memory_configure_bank(1, 0, 2, &ROM[0x10000], 0x8000); // rom at 0-0x5fff is banked (dk or d2k)
memory_configure_bank(2, 0, 2, &ROM[0x16800], 0x8000); // 2nd bank
d2k_rombank_w( machine, 0, 0); // select dk at bootup
}
ROM_START( d2k )
ROM_REGION( 0x30000, "main", 0 )
ROM_LOAD( "d2k.bin", 0x20000, 0x10000, CRC(6e95ca0d) SHA1(c058add0f146d577e3df0ba60828fe1734e78d01) )
ROM_REGION( 0x1800, "sound", 0 ) /* sound */
ROM_LOAD( "s_3i_b.bin", 0x0000, 0x0800, CRC(45a4ed06) SHA1(144d24464c1f9f01894eb12f846952290e6e32ef) )
ROM_RELOAD( 0x0800, 0x0800 )
ROM_LOAD( "s_3j_b.bin", 0x1000, 0x0800, CRC(4743fe92) SHA1(6c82b57637c0212a580591397e6a5a1718f19fd2) )
ROM_REGION( 0x1000, "gfx1", ROMREGION_DISPOSE )
ROM_LOAD( "v_5h_b.bin", 0x0000, 0x0800, CRC(12c8c95d) SHA1(a57ff5a231c45252a63b354137c920a1379b70a3) )
ROM_LOAD( "v_3pt.bin", 0x0800, 0x0800, CRC(15e9c5e9) SHA1(976eb1e18c74018193a35aa86cff482ebfc5cc4e) )
ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
ROM_LOAD( "l_4m_b.bin", 0x0000, 0x0800, CRC(59f8054d) SHA1(793dba9bf5a5fe76328acdfb90815c243d2a65f1) )
ROM_LOAD( "l_4n_b.bin", 0x0800, 0x0800, CRC(672e4714) SHA1(92e5d379f4838ac1fa44d448ce7d142dae42102f) )
ROM_LOAD( "l_4r_b.bin", 0x1000, 0x0800, CRC(feaa59ee) SHA1(ecf95db5a20098804fc8bd59232c66e2e0ed3db4) )
ROM_LOAD( "l_4s_b.bin", 0x1800, 0x0800, CRC(20f2ef7e) SHA1(3bc482a38bf579033f50082748ee95205b0f673d) )
ROM_REGION( 0x0300, "proms", 0 )
ROM_LOAD( "c-2k.bpr", 0x0000, 0x0100, CRC(e273ede5) SHA1(b50ec9e1837c00c20fb2a4369ec7dd0358321127) ) /* palette low 4 bits (inverted) */
ROM_LOAD( "c-2j.bpr", 0x0100, 0x0100, CRC(d6412358) SHA1(f9c872da2fe8e800574ae3bf483fb3ccacc92eb3) ) /* palette high 4 bits (inverted) */
ROM_LOAD( "v-5e.bpr", 0x0200, 0x0100, CRC(b869b8f5) SHA1(c2bdccbf2654b64ea55cd589fd21323a9178a660) ) /* character color codes on a per-column basis */
ROM_END
ROM_START( d2k11 )
ROM_REGION( 0x30000, "main", 0 )
ROM_LOAD( "d2k11.bin", 0x20000, 0x10000, CRC(2048fc42) SHA1(e427a09ed8e792ee8ce01cd0b07c6a0d5a7c5536) )
ROM_REGION( 0x1800, "sound", 0 ) /* sound */
ROM_LOAD( "s_3i_b.bin", 0x0000, 0x0800, CRC(45a4ed06) SHA1(144d24464c1f9f01894eb12f846952290e6e32ef) )
ROM_RELOAD( 0x0800, 0x0800 )
ROM_LOAD( "s_3j_b.bin", 0x1000, 0x0800, CRC(4743fe92) SHA1(6c82b57637c0212a580591397e6a5a1718f19fd2) )
ROM_REGION( 0x1000, "gfx1", ROMREGION_DISPOSE )
ROM_LOAD( "v_5h_b.bin", 0x0000, 0x0800, CRC(12c8c95d) SHA1(a57ff5a231c45252a63b354137c920a1379b70a3) )
ROM_LOAD( "v_3pt.bin", 0x0800, 0x0800, CRC(15e9c5e9) SHA1(976eb1e18c74018193a35aa86cff482ebfc5cc4e) )
ROM_REGION( 0x2000, "gfx2", ROMREGION_DISPOSE )
ROM_LOAD( "l_4m_b.bin", 0x0000, 0x0800, CRC(59f8054d) SHA1(793dba9bf5a5fe76328acdfb90815c243d2a65f1) )
ROM_LOAD( "l_4n_b.bin", 0x0800, 0x0800, CRC(672e4714) SHA1(92e5d379f4838ac1fa44d448ce7d142dae42102f) )
ROM_LOAD( "l_4r_b.bin", 0x1000, 0x0800, CRC(feaa59ee) SHA1(ecf95db5a20098804fc8bd59232c66e2e0ed3db4) )
ROM_LOAD( "l_4s_b.bin", 0x1800, 0x0800, CRC(20f2ef7e) SHA1(3bc482a38bf579033f50082748ee95205b0f673d) )
ROM_REGION( 0x0300, "proms", 0 )
ROM_LOAD( "c-2k.bpr", 0x0000, 0x0100, CRC(e273ede5) SHA1(b50ec9e1837c00c20fb2a4369ec7dd0358321127) ) /* palette low 4 bits (inverted) */
ROM_LOAD( "c-2j.bpr", 0x0100, 0x0100, CRC(d6412358) SHA1(f9c872da2fe8e800574ae3bf483fb3ccacc92eb3) ) /* palette high 4 bits (inverted) */
ROM_LOAD( "v-5e.bpr", 0x0200, 0x0100, CRC(b869b8f5) SHA1(c2bdccbf2654b64ea55cd589fd21323a9178a660) ) /* character color codes on a per-column basis */
ROM_END
GAME( 2006, d2k, dkong, d2k, dkong, d2k, ROT90, "Jeff Kulczycki", "Donkey Kong II: Jumpman Returns (v1.2) [h]", GAME_SUPPORTS_SAVE )
GAME( 2006, d2k11, dkong, d2k, dkong, d2k, ROT90, "Jeff Kulczycki", "Donkey Kong II: Jumpman Returns (v1.1) [h]", GAME_SUPPORTS_SAVE )
I left all the hackery that was in Robbbert's d2k driver, but yours is MUCH cleaner and uses the dkong2b base instead of dkong_base which helps clean the code a lot.