From 5660e8f546d48b9626aac1b77c3a08d2ce974d0b Mon Sep 17 00:00:00 2001 From: Tomasz Slanina Date: Thu, 27 Aug 2009 00:25:52 +0000 Subject: [PATCH] Brap Boys Improvements - Redumped GFX Roms [Guru] - Added hitbox simulation based on suprnova / game requirements [Tomasz Slanina] - Converted MCU writes to use write_byte [David Haywood] - Added kludge to reset MCU data write address to prevent game from running out of ram and crashing [David Haywood] - Added DSWs [David Haywood] New games added or promoted from NOT_WORKING status --------------------------------------------------- B.Rap Boys / B.Rap Boys Special [David Haywood, Tomasz Slanina, Luca Elia] --- src/mame/drivers/kaneko16.c | 128 ++++++++++--- src/mame/machine/kaneko16.c | 346 +++++++++++++++++++++++++++++++++--- 2 files changed, 422 insertions(+), 52 deletions(-) diff --git a/src/mame/drivers/kaneko16.c b/src/mame/drivers/kaneko16.c index 8fe2e5ade09..58bfac2cf2f 100644 --- a/src/mame/drivers/kaneko16.c +++ b/src/mame/drivers/kaneko16.c @@ -57,6 +57,15 @@ To Do: - Finish the Inputs (different wheels and pedals) - Find infos about the communication stuff (even if it won't be supported) +[brapboys / shogwarr] + +- Verify collision protection on real hardware +- Figure out how MCU resets writeback address (currently hacked) +- Find relationship between Key tables and final datablock +- Clean up debug code file writes etc. (when above are done only!) +- Interrupt timing? (some sprites flicker) +- Sprite buffering (2 frames?, or related to above) + Dip locations verified from manual for: - berlwall @@ -68,6 +77,8 @@ Dip locations verified from manual for: - gtmr2 - shogwarr + + ***************************************************************************/ #include "driver.h" @@ -806,10 +817,9 @@ static WRITE16_HANDLER( shogwarr_oki_bank_w ) extern void calc3_mcu_run(running_machine *machine); -static WRITE16_HANDLER( calc3_run ) -{ -// calc3_mcu_run(space->machine); -} +WRITE16_HANDLER(shogwarr_calc_w); +READ16_HANDLER(shogwarr_calc_r); + static ADDRESS_MAP_START( shogwarr, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x000000, 0x03ffff) AM_ROM // ROM @@ -818,7 +828,7 @@ static ADDRESS_MAP_START( shogwarr, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x280000, 0x280001) AM_WRITE(calc3_mcu_com0_w) AM_RANGE(0x290000, 0x290001) AM_WRITE(calc3_mcu_com1_w) AM_RANGE(0x2b0000, 0x2b0001) AM_WRITE(calc3_mcu_com2_w) - AM_RANGE(0x2c0000, 0x2c0001) AM_WRITE(calc3_run) // guess, might be irqack + //AM_RANGE(0x2c0000, 0x2c0001) AM_WRITE(calc3_run) // guess, might be irqack AM_RANGE(0x2d0000, 0x2d0001) AM_WRITE(calc3_mcu_com3_w) AM_RANGE(0x380000, 0x380fff) AM_RAM_WRITE(paletteram16_xGGGGGRRRRRBBBBB_word_w) AM_BASE(&paletteram16) // Palette AM_RANGE(0x400000, 0x400001) AM_DEVREADWRITE8("oki1", okim6295_r, okim6295_w, 0x00ff) // Samples @@ -830,7 +840,7 @@ static ADDRESS_MAP_START( shogwarr, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x603000, 0x603fff) AM_RAM AM_BASE(&kaneko16_vscroll_0) AM_RANGE(0x800000, 0x80000f) AM_RAM_WRITE(kaneko16_layers_0_regs_w) AM_BASE(&kaneko16_layers_0_regs) // Layers 0 Regs AM_RANGE(0x900000, 0x90001f) AM_RAM_WRITE(kaneko16_sprites_regs_w) AM_BASE(&kaneko16_sprites_regs) // Sprites Regs - AM_RANGE(0xa00014, 0xa00015) AM_READ(kaneko16_rnd_r) // Random Number ? + AM_RANGE(0xa00000, 0xa0007f) AM_READWRITE(shogwarr_calc_r, shogwarr_calc_w) // Random Number ? AM_RANGE(0xa80000, 0xa80001) AM_READWRITE(watchdog_reset16_r, watchdog_reset16_w) // Watchdog AM_RANGE(0xb80000, 0xb80001) AM_READ_PORT("P1") AM_RANGE(0xb80002, 0xb80003) AM_READ_PORT("P2") @@ -1575,6 +1585,71 @@ static INPUT_PORTS_START( shogwarr ) INPUT_PORTS_END +static INPUT_PORTS_START( brapboys ) + PORT_START("P1") /* b80000.w */ + PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) + PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) + PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) + PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) + PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) + PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) + PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_START1 ) + PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN1 ) + + PORT_START("P2") /* b80002.w */ + PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) + PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) + PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) + PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) + PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) + PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) + PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_START2 ) + PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN2 ) + + PORT_START("SYSTEM") /* b80004.w */ + PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(3) + PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(3) + PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(3) + PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(3) + PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3) + PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3) + PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_START3 ) + PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_COIN3 ) + + PORT_START("UNK") /* ? - b80006.w */ + PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN ) + PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNKNOWN ) + + PORT_START("DSW1") + PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) ) + PORT_DIPSETTING( 0x01, DEF_STR( Off ) ) + PORT_DIPSETTING( 0x00, DEF_STR( On ) ) + PORT_SERVICE(0x02, IP_ACTIVE_LOW ) + PORT_DIPNAME( 0x04, 0x04, "Switch Test" ) + PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) + PORT_DIPSETTING( 0x00, DEF_STR( On ) ) + PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) ) + PORT_DIPSETTING( 0x08, DEF_STR( Off ) ) + PORT_DIPSETTING( 0x00, DEF_STR( On ) ) + PORT_DIPNAME( 0x10, 0x10, "Coin Type" ) + PORT_DIPSETTING( 0x10, "Local Coin" ) + PORT_DIPSETTING( 0x00, "Common Coin" ) + PORT_DIPNAME( 0x20, 0x20, DEF_STR( Players ) ) + PORT_DIPSETTING( 0x20, "3" ) + PORT_DIPSETTING( 0x00, "2" ) + PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Difficulty ) ) + PORT_DIPSETTING( 0x80, DEF_STR( Easy ) ) + PORT_DIPSETTING( 0xc0, DEF_STR( Normal ) ) + PORT_DIPSETTING( 0x40, DEF_STR( Hard ) ) + PORT_DIPSETTING( 0x00, DEF_STR( Very_Hard) ) +INPUT_PORTS_END + /*************************************************************************** @@ -3484,14 +3559,12 @@ ROM_START( brapboys ) /* Single PCB, fully populated, no rom sub board */ ROM_LOAD( "rb-040.u33", 0x000000, 0x020000, CRC(757c6e19) SHA1(0f1c37b1b1eb6b230c593e4648c4302f413a61f5) ) ROM_REGION( 0x800000, "gfx1", 0 ) /* Sprites */ - /* prety sure all these are at least half size */ - ROM_LOAD( "rb-020.u2", 0x080000, 0x080000, BAD_DUMP CRC(b038440e) SHA1(9e32cb62358ab846470d9a75d4dab771d608a3cf) ) // too small? - ROM_LOAD( "rb-021.u76", 0x180000, 0x080000, BAD_DUMP CRC(b7e2d362) SHA1(7e98e5b3d1ee972fc4cf9bebd33a3ca96a77357c) ) // too small? - ROM_LOAD( "rb-022.u77", 0x280000, 0x080000, BAD_DUMP CRC(8d40c97a) SHA1(353b0a4a508f2fff8eeed680b1f685c7fdc29a7d) ) // too small? - ROM_LOAD( "rb-023.u78", 0x380000, 0x080000, BAD_DUMP CRC(dcf11c8d) SHA1(eed801f7cca3d3a941b1a4e4815cac9d20d970f7) ) // too small? - ROM_LOAD( "rb-024.u79", 0x400000, 0x080000, BAD_DUMP CRC(65fa6447) SHA1(551e540d7bf412753b4a7098e25e6f9d8774bcf4) ) // right? title logo - ROM_LOAD( "rb-025.u80", 0x500000, 0x040000, CRC(36cd6b90) SHA1(45c50f2652726ded67c9c24185a71a6367e09270) ) // odd size.. guy on title screen, select screen might be correct - //ROM_LOAD( "rb-026.u5", 0x580000, 0x080000, CRC(bb7604d4) SHA1(57d51ce4ea2000f9a50bae326cfcb66ec494249f) ) // not on this set? + ROM_LOAD( "rb-020.c2", 0x000000, 0x100000, CRC(ce220d38) SHA1(b88d7c89a3e1a826bf19a1fa692ec77c944596d9) ) + ROM_LOAD( "rb-021.u76", 0x100000, 0x100000, CRC(74001407) SHA1(90002056ceb4e0401246950b8c3f996af0a2463c) ) + ROM_LOAD( "rb-022.u77", 0x200000, 0x100000, CRC(cb3f42dc) SHA1(5415f15621924dd263b8fe7daaf3dc25d470b814) ) + ROM_LOAD( "rb-023.u78", 0x300000, 0x100000, CRC(0e6530c5) SHA1(72bff46f0672927e540f4f3546ae533dd0a231e0) ) + ROM_LOAD( "rb-024.u79", 0x400000, 0x080000, CRC(65fa6447) SHA1(551e540d7bf412753b4a7098e25e6f9d8774bcf4) ) // correct, both halves identical when dumped as larger + ROM_LOAD( "rb-025.u80", 0x500000, 0x040000, CRC(36cd6b90) SHA1(45c50f2652726ded67c9c24185a71a6367e09270) ) // eprom, contains title logo for this version ROM_REGION( 0x400000, "gfx2", 0 ) /* Tiles (scrambled) */ ROM_LOAD( "rb-010.u65", 0x000000, 0x100000, CRC(ffd73f87) SHA1(1a661f71976be61c22d9b962850e738ba17f1d45) ) @@ -3516,6 +3589,7 @@ ROM_START( brapboys ) /* Single PCB, fully populated, no rom sub board */ ROM_FILL( 0x00000, 0x400000*16, 0x00 ) ROM_END + ROM_START( brapboysj ) /* The Japanese version has an extra rom??? and used a rom sub board */ ROM_REGION( 0x040000, "maincpu", 0 ) /* 68000 Code */ ROM_LOAD16_BYTE( "rb-004.u61", 0x000000, 0x020000, CRC(5432442c) SHA1(f0f7328ece96ef25e6d4fd1958d734f64a9ef371) ) @@ -3526,13 +3600,13 @@ ROM_START( brapboysj ) /* The Japanese version has an extra rom??? and used a ro ROM_REGION( 0x1000000, "gfx1", 0 ) /* Sprites */ /* prety sure all these are at least half size */ - ROM_LOAD( "rb-020.u2", 0x080000, 0x080000, BAD_DUMP CRC(b038440e) SHA1(9e32cb62358ab846470d9a75d4dab771d608a3cf) ) // too small? - ROM_LOAD( "rb-021.u76", 0x180000, 0x080000, BAD_DUMP CRC(b7e2d362) SHA1(7e98e5b3d1ee972fc4cf9bebd33a3ca96a77357c) ) // too small? - ROM_LOAD( "rb-022.u77", 0x280000, 0x080000, BAD_DUMP CRC(8d40c97a) SHA1(353b0a4a508f2fff8eeed680b1f685c7fdc29a7d) ) // too small? - ROM_LOAD( "rb-023.u78", 0x380000, 0x080000, BAD_DUMP CRC(dcf11c8d) SHA1(eed801f7cca3d3a941b1a4e4815cac9d20d970f7) ) // too small? - ROM_LOAD( "rb-024.u79", 0x400000, 0x080000, BAD_DUMP CRC(65fa6447) SHA1(551e540d7bf412753b4a7098e25e6f9d8774bcf4) ) // right? title logo - ROM_LOAD( "rb-025.u4", 0x500000, 0x080000, CRC(aa795ba5) SHA1(c5256dcceded2e76f548b60c18e51d0dd0209d81) ) // special title screen - ROM_LOAD( "rb-026.u5", 0x580000, 0x080000, CRC(bb7604d4) SHA1(57d51ce4ea2000f9a50bae326cfcb66ec494249f) ) // logs that bounce past + ROM_LOAD( "rb-020.c2", 0x000000, 0x100000, CRC(ce220d38) SHA1(b88d7c89a3e1a826bf19a1fa692ec77c944596d9) ) + ROM_LOAD( "rb-021.u76", 0x100000, 0x100000, CRC(74001407) SHA1(90002056ceb4e0401246950b8c3f996af0a2463c) ) + ROM_LOAD( "rb-022.u77", 0x200000, 0x100000, CRC(cb3f42dc) SHA1(5415f15621924dd263b8fe7daaf3dc25d470b814) ) + ROM_LOAD( "rb-023.u78", 0x300000, 0x100000, CRC(0e6530c5) SHA1(72bff46f0672927e540f4f3546ae533dd0a231e0) ) + ROM_LOAD( "rb-024.u79", 0x400000, 0x080000, CRC(65fa6447) SHA1(551e540d7bf412753b4a7098e25e6f9d8774bcf4) ) // correct, both halves identical when dumped as larger + ROM_LOAD( "rb-025.u4", 0x500000, 0x080000, CRC(aa795ba5) SHA1(c5256dcceded2e76f548b60c18e51d0dd0209d81) ) // eprom, special title screen + ROM_LOAD( "rb-026.u5", 0x580000, 0x080000, CRC(bb7604d4) SHA1(57d51ce4ea2000f9a50bae326cfcb66ec494249f) ) // eprom, logs that bounce past ROM_REGION( 0x400000, "gfx2", 0 ) /* Tiles (scrambled) */ @@ -3735,11 +3809,13 @@ GAME( 1994, gtmrusa, gtmr, gtmr, gtmr, gtmr2, ROT0, "Kaneko", "Gre GAME( 1995, gtmr2, 0, gtmr2, gtmr2, gtmr2, ROT0, "Kaneko", "Mille Miglia 2: Great 1000 Miles Rally (95/05/24)", 0 ) GAME( 1995, gtmr2a, gtmr2, gtmr2, gtmr2, gtmr2, ROT0, "Kaneko", "Mille Miglia 2: Great 1000 Miles Rally (95/04/04)", 0 ) GAME( 1995, gtmr2u, gtmr2, gtmr2, gtmr2, gtmr2, ROT0, "Kaneko", "Great 1000 Miles Rally 2 USA (95/05/18)", 0 ) +// some functionality of the protection chip still needs investigating on these, but they seem to be playable +GAME( 1992, brapboys, 0, shogwarr, brapboys, brapboys, ROT0, "Kaneko", "B.Rap Boys (World)", 0 ) +GAME( 1992, brapboysj,brapboys, shogwarr, brapboys, brapboys, ROT0, "Kaneko", "B.Rap Boys Special (Japan)", 0 ) /* Non-working games (mainly due to protection) */ -GAME( 1992, shogwarr, 0, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Shogun Warriors", GAME_NOT_WORKING ) -GAME( 1992, shogwarre,shogwarr, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Shogun Warriors (Euro)", GAME_NOT_WORKING ) -GAME( 1992, fjbuster, shogwarr, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Fujiyama Buster (Japan)", GAME_NOT_WORKING ) -GAME( 1992, brapboys, 0, shogwarr, shogwarr, brapboys, ROT0, "Kaneko", "B.Rap Boys (World)", GAME_NOT_WORKING ) -GAME( 1992, brapboysj,brapboys, shogwarr, shogwarr, brapboys, ROT0, "Kaneko", "B.Rap Boys Special (Japan)", GAME_NOT_WORKING ) +GAME( 1992, shogwarr, 0, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Shogun Warriors", GAME_NOT_WORKING ) +GAME( 1992, shogwarre,shogwarr, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Shogun Warriors (Euro)", GAME_NOT_WORKING ) +GAME( 1992, fjbuster, shogwarr, shogwarr, shogwarr, calc3, ROT0, "Kaneko", "Fujiyama Buster (Japan)", GAME_NOT_WORKING ) + diff --git a/src/mame/machine/kaneko16.c b/src/mame/machine/kaneko16.c index e6d55e397b7..4187ffcef17 100644 --- a/src/mame/machine/kaneko16.c +++ b/src/mame/machine/kaneko16.c @@ -17,14 +17,13 @@ Currently none of the MCUs' internal roms are dumped so simulation is used #include "kanekotb.h" // TOYBOX MCU trojaning results + +#define CALC3_VERBOSE_OUTPUT 0 + #define MCU_RESPONSE(d) memcpy(&kaneko16_mcu_ram[mcu_offset], d, sizeof(d)) UINT16 *kaneko16_mcu_ram; -static int global_offset=0; - -int unk[2]; - /*************************************************************************** Gals Panic (set 2) Gals Panic (set 3) @@ -38,6 +37,7 @@ int unk[2]; - bonkadv only uses Random Number, XY Overlap Collision bit and register '0x02' */ + static struct { UINT16 x1p, y1p, x1s, y1s; UINT16 x2p, y2p, x2s, y2s; @@ -151,6 +151,7 @@ WRITE16_HANDLER(bloodwar_calc_w) rect2 <-----> | <-----------> | <---> result <----------> | <--------> | <----> */ + static INT16 calc_compute_x(void) { INT16 x_coll; @@ -165,6 +166,7 @@ static INT16 calc_compute_x(void) return x_coll; } + static INT16 calc_compute_y(void) { INT16 y_coll; @@ -240,6 +242,259 @@ READ16_HANDLER(bloodwar_calc_r) return 0; } +/* + B Rap Boys + Shogun Warriors + +*/ + + +static struct { + int x1p, y1p, z1p, x1s, y1s, z1s; + int x2p, y2p, z2p, x2s, y2s, z2s; + + int x1po, y1po, z1po, x1so, y1so, z1so; + int x2po, y2po, z2po, x2so, y2so, z2so; + + int x12, y12, z12, x21, y21, z21; + + int x_coll, y_coll, z_coll; + + int x1tox2, y1toy2, z1toz2; + + UINT16 mult_a, mult_b; + + UINT16 flags; + UINT16 mode; + +} shogwarr_hit; + + +//calculate simple intersection of two segments + +static int shogwarr_calc_compute(int x1, int w1, int x2, int w2) +{ + int dist; + + if(x2>=x1 && x2+w2<=(x1+w1)) + { + //x2 inside x1 + dist=w2; + } + else + { + if(x1>=x2 && x1+w1<=(x2+w2)) + { + //x1 inside x2 + dist=w1; + } + else + { + if(x2>=2; + shogwarr_calc_org(mode&3, shogwarr_hit.y1po, shogwarr_hit.y1so, &shogwarr_hit.y1p, &shogwarr_hit.y1s); + mode>>=2; + shogwarr_calc_org(mode&3, shogwarr_hit.z1po, shogwarr_hit.z1so, &shogwarr_hit.z1p, &shogwarr_hit.z1s); + + mode>>=4; + + shogwarr_calc_org(mode&3, shogwarr_hit.x2po, shogwarr_hit.x2so, &shogwarr_hit.x2p, &shogwarr_hit.x2s); + mode>>=2; + shogwarr_calc_org(mode&3, shogwarr_hit.y2po, shogwarr_hit.y2so, &shogwarr_hit.y2p, &shogwarr_hit.y2s); + mode>>=2; + shogwarr_calc_org(mode&3, shogwarr_hit.z2po, shogwarr_hit.z2so, &shogwarr_hit.z2p, &shogwarr_hit.z2s); + + + shogwarr_hit.x1tox2=abs(shogwarr_hit.x2po-shogwarr_hit.x1po); + shogwarr_hit.y1toy2=abs(shogwarr_hit.y2po-shogwarr_hit.y1po); + shogwarr_hit.z1toz2=abs(shogwarr_hit.z2po-shogwarr_hit.z1po); + + + shogwarr_hit.x_coll = shogwarr_calc_compute(shogwarr_hit.x1p, shogwarr_hit.x1s, shogwarr_hit.x2p, shogwarr_hit.x2s); + shogwarr_hit.y_coll = shogwarr_calc_compute(shogwarr_hit.y1p, shogwarr_hit.y1s, shogwarr_hit.y2p, shogwarr_hit.y2s); + shogwarr_hit.z_coll = shogwarr_calc_compute(shogwarr_hit.z1p, shogwarr_hit.z1s, shogwarr_hit.z2p, shogwarr_hit.z2s); + + + // 4th nibble: Y Absolute Collision -> possible values = 9,8,4,3,2 + if (shogwarr_hit.y1p > shogwarr_hit.y2p) shogwarr_hit.flags |= 0x2000; + else if (shogwarr_hit.y1p == shogwarr_hit.y2p) shogwarr_hit.flags |= 0x4000; + else if (shogwarr_hit.y1p < shogwarr_hit.y2p) shogwarr_hit.flags |= 0x8000; + if (shogwarr_hit.y_coll<0) shogwarr_hit.flags |= 0x1000; + + // 3rd nibble: X Absolute Collision -> possible values = 9,8,4,3,2 + if (shogwarr_hit.x1p > shogwarr_hit.x2p) shogwarr_hit.flags |= 0x0200; + else if (shogwarr_hit.x1p == shogwarr_hit.x2p) shogwarr_hit.flags |= 0x0400; + else if (shogwarr_hit.x1p < shogwarr_hit.x2p) shogwarr_hit.flags |= 0x0800; + if (shogwarr_hit.x_coll<0) shogwarr_hit.flags |= 0x0100; + + // 2nd nibble: Z Absolute Collision -> possible values = 9,8,4,3,2 + if (shogwarr_hit.z1p > shogwarr_hit.z2p) shogwarr_hit.flags |= 0x0020; + else if (shogwarr_hit.z1p == shogwarr_hit.z2p) shogwarr_hit.flags |= 0x0040; + else if (shogwarr_hit.z1p < shogwarr_hit.z2p) shogwarr_hit.flags |= 0x0080; + if (shogwarr_hit.z_coll<0) shogwarr_hit.flags |= 0x0010; + + // 1st nibble: XYZ Overlap Collision + if ((shogwarr_hit.x_coll>=0)&&(shogwarr_hit.y_coll>=0)&&(shogwarr_hit.z_coll>=0)) shogwarr_hit.flags |= 0x0008; + if ((shogwarr_hit.x_coll>=0)&&(shogwarr_hit.z_coll>=0)) shogwarr_hit.flags |= 0x0004; + if ((shogwarr_hit.y_coll>=0)&&(shogwarr_hit.z_coll>=0)) shogwarr_hit.flags |= 0x0002; + if ((shogwarr_hit.x_coll>=0)&&(shogwarr_hit.y_coll>=0)) shogwarr_hit.flags |= 0x0001; +} + + +WRITE16_HANDLER(shogwarr_calc_w) +{ + int idx=offset*4; + switch (idx) + { + // p is position, s is size + case 0x00: + case 0x28: + + shogwarr_hit.x1po = data; break; + + case 0x04: + case 0x2c: + shogwarr_hit.x1so = data; break; + + case 0x08: + case 0x30: + shogwarr_hit.y1po = data; break; + + case 0x0c: + case 0x34: + shogwarr_hit.y1so = data; break; + + case 0x10: + case 0x58: + shogwarr_hit.x2po = data; break; + + case 0x14: + case 0x5c: + shogwarr_hit.x2so = data; break; + + case 0x18: + case 0x60: + shogwarr_hit.y2po = data; break; + + case 0x1c: + case 0x64: + shogwarr_hit.y2so = data; break; + + case 0x38: + case 0x50: + shogwarr_hit.z1po = data; break; + case 0x3c: + case 0x54: + shogwarr_hit.z1so = data; break; + + case 0x20: + case 0x68: + shogwarr_hit.z2po = data; break; + + case 0x24: + case 0x6c: + shogwarr_hit.z2so = data; break; + + case 0x70: + shogwarr_hit.mode=data;break; + + default: + logerror("CPU #0 PC %06x: warning - write unmapped hit address %06x [ %06x] = %06x\n",cpu_get_pc(space->cpu),offset<<1, idx, data); + } + + shogwarr_recalc_collisions(); +} + + +READ16_HANDLER(shogwarr_calc_r) +{ + + int idx=offset*4; + + switch (idx) + { + case 0x00: // X distance + case 0x10: + return shogwarr_hit.x_coll; + + case 0x04: // Y distance + case 0x14: + return shogwarr_hit.y_coll; + + case 0x18: // Z distance + return shogwarr_hit.z_coll; + + case 0x08: + case 0x1c: + + return shogwarr_hit.flags; + + case 0x28: + return (mame_rand(space->machine) & 0xffff); + + case 0x40: return shogwarr_hit.x1po; + case 0x44: return shogwarr_hit.x1so; + case 0x48: return shogwarr_hit.y1po; + case 0x4c: return shogwarr_hit.y1so; + case 0x50: return shogwarr_hit.z1po; + case 0x54: return shogwarr_hit.z1so; + + case 0x58: return shogwarr_hit.x2po; + case 0x5c: return shogwarr_hit.x2so; + case 0x60: return shogwarr_hit.y2po; + case 0x64: return shogwarr_hit.y2so; + case 0x68: return shogwarr_hit.z2po; + case 0x6c: return shogwarr_hit.z2so; + + case 0x80: return shogwarr_hit.x1tox2; + case 0x84: return shogwarr_hit.y1toy2; + case 0x88: return shogwarr_hit.z1toz2; + + default: + logerror("CPU #0 PC %06x: warning - read unmapped calc address %06x [ %06x]\n",cpu_get_pc(space->cpu),offset<<1, idx); + } + + return 0; +} + /*************************************************************************** CALC3 MCU: @@ -591,9 +846,11 @@ static UINT8 calc3_blocksize_offset; static UINT16 calc3_dataend; static UINT16 calc3_database; +static int data_header[2]; + UINT32 calc3_writeaddress; UINT32 calc3_writeaddress_current; -UINT16 calc3_dsw_addr; +UINT16 calc3_dsw_addr = 0x00; UINT16 calc3_eeprom_addr; UINT16 calc3_poll_addr; UINT16 cakc3_checkumaddress; @@ -617,6 +874,7 @@ static UINT8 shift_bits(UINT8 dat, int bits) // endian safe? you're having a laugh int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, int dstoffset) { + const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); UINT8* rom = memory_region(machine,"cpu1"); UINT8 numregions; UINT16 length; @@ -669,8 +927,7 @@ int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, length = rom[offset+0] | (rom[offset+1]<<8); offset+=2; - global_offset=offset; - +#if CALC3_VERBOSE_OUTPUT if (inline_table_size) { printf("Block %02x Found Base %04x - Inline Encryption (size %02x) - Mode? %02x Shift %01x Unk %01x Key (unused?) %02x Length %04x\n", tabnum, calc3_database, inline_table_size, calc3_shift, calc3_mode, calc3_unknown, calc3_decryption_key_byte, length); @@ -679,9 +936,9 @@ int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, { printf("Block %02x Found Base %04x - Mode? %02x Shift %01x Unk %01x Key %02x Length %04x\n", tabnum, calc3_database, calc3_mode, calc3_shift, calc3_unknown, calc3_decryption_key_byte, length); } - +#endif // copy + decrypt the table to the specified memory area - if (dstram) + //if (dstram) { int i; @@ -693,7 +950,13 @@ int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, // except this will break shogun going into game, must be specific conditions for // this, or it can remember addresses and restore those - //calc3_writeaddress_current = calc3_writeaddress; + + // hack, set it to a known address instead of trying to restore to anywhere specific.. + // might break at some point tho, eg if it doesn't write command 06 often enough because it trys to use another one like 07... + // need to understand the meaning of this (test hw?) + if (calc3_mode==0x06) calc3_writeaddress_current = 0x202000; + // also calls empty table with Mode? 07 + // maybe they reset to different points? return 0; } @@ -804,10 +1067,20 @@ int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, } if(local_counter>1) - - dstram[(dstoffset+i)^1] = dat; + { + if (space) + { + memory_write_byte(space, dstoffset+i, dat); + } + + // debug, used to output tables at the start + if (dstram) + { + dstram[(dstoffset+i)^1] = dat; + } + } else - unk[local_counter]=dat; + data_header[local_counter]=dat; ++local_counter; } @@ -905,10 +1178,20 @@ int calc3_decompress_table(running_machine* machine, int tabnum, UINT8* dstram, } if(local_counter>1) - - dstram[(dstoffset+i)^1] = dat; + { + if (space) + { + memory_write_byte(space, dstoffset+i, dat); + } + + // debug, used to output tables at the start + if (dstram) + { + dstram[(dstoffset+i)^1] = dat; + } + } else - unk[local_counter]=dat; + data_header[local_counter]=dat; ++local_counter; @@ -940,7 +1223,7 @@ DRIVER_INIT(calc3_scantables) { calc3_mcu_crc+=rom[x]; } - printf("crc %04x\n",calc3_mcu_crc); + //printf("crc %04x\n",calc3_mcu_crc); numregions = rom[0]; for (x=0;x>1)+0] = 0x0000; @@ -1054,15 +1345,16 @@ void calc3_mcu_run(running_machine *machine) // set our current write / stack pointer to the address specified calc3_writeaddress_current = calc3_writeaddress; - +#if CALC3_VERBOSE_OUTPUT printf("Calc 3 Init Command - %04x DSW addr\n", calc3_dsw_addr); printf("Calc 3 Init Command - %04x Eeprom Address\n", calc3_eeprom_addr); printf("Calc 3 Init Command - %04x Future Commands Base\n", calc3_mcu_command_offset); printf("Calc 3 Init Command - %04x Poll / Busy Address\n", calc3_poll_addr); printf("Calc 3 Init Command - %04x ROM Checksum Address\n", cakc3_checkumaddress); printf("Calc 3 Init Command - %08x Data Write Address\n", calc3_writeaddress); - - kaneko16_mcu_ram[calc3_dsw_addr/2] =( ~input_port_read(machine, "DSW1"))&0xff; // DSW // dsw actually updates in realtime - mcu reads+writes it every frame +#endif + memory_write_byte(space, calc3_dsw_addr+0x200000, ( ~input_port_read(machine, "DSW1"))&0xff); // // DSW // dsw actually updates in realtime - mcu reads+writes it every frame + kaneko16_mcu_ram[cakc3_checkumaddress / 2] = calc3_mcu_crc; // MCU Rom Checksum! for (i=0;i<0x40;i++) @@ -1089,20 +1381,22 @@ void calc3_mcu_run(running_machine *machine) UINT8 commandtabl = (param1&0xff00) >> 8; UINT16 commandaddr =param2;// (param1&0x00ff) | (param2&0xff00); UINT8 commandunk = (param1&0x00ff); // brap boys sets.. seems to cause further writebasck address displacement?? (when tested on hw it looked like a simple +, but that doesn't work for brapboys...) - +#if CALC3_VERBOSE_OUTPUT printf("transfer %d table %02x writeback address %04x unknown %02x\n", i, commandtabl, commandaddr, commandunk); - +#endif { int length; - length = calc3_decompress_table(machine, commandtabl, (UINT8*)kaneko16_mcu_ram, (calc3_writeaddress_current&0xffff)-2); + length = calc3_decompress_table(machine, commandtabl, 0, calc3_writeaddress_current-2); if (length) { int write=commandaddr; +#if CALC3_VERBOSE_OUTPUT printf("writing back address %08x to %08x %08x\n", calc3_writeaddress_current, commandaddr,write); - kaneko16_mcu_ram[(write>>1)+0] =unk[1];// (calc3_writeaddress_current>>16)&0xffff; - kaneko16_mcu_ram[(write>>1)+1] =unk[0];// (calc3_writeaddress_current&0xffff); +#endif + kaneko16_mcu_ram[(write>>1)+0] =data_header[1];// (calc3_writeaddress_current>>16)&0xffff; + kaneko16_mcu_ram[(write>>1)+1] =data_header[0];// (calc3_writeaddress_current&0xffff); write=commandaddr+(char)commandunk; kaneko16_mcu_ram[(write>>1)+0] = (calc3_writeaddress_current>>16)&0xffff; kaneko16_mcu_ram[(write>>1)+1] = (calc3_writeaddress_current&0xffff);