summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2008-07-24 05:03:19 +0000
committer Aaron Giles <aaron@aarongiles.com>2008-07-24 05:03:19 +0000
commit81abccd04b121a2419b4a7b5a182688e5d066bc3 (patch)
tree5f996c0f8371722424a4a30bf30ee471f65fe71d
parentce7838d0b55c55508852adf40c06b15cc049810d (diff)
Make the tinklpit keycus implementation cuter
There is not enough data to be sure it's a LFSR, but it doesn't look bad as one. OG.
-rw-r--r--src/emu/mamecore.h11
-rw-r--r--src/mame/drivers/namcona1.c21
2 files changed, 22 insertions, 10 deletions
diff --git a/src/emu/mamecore.h b/src/emu/mamecore.h
index 5d3953edac4..ae8c605bc39 100644
--- a/src/emu/mamecore.h
+++ b/src/emu/mamecore.h
@@ -298,6 +298,17 @@ DECL_NORETURN void CLIB_DECL fatalerror_exitcode(int exitcode, const char *text,
INLINE FUNCTIONS
***************************************************************************/
+/* population count */
+INLINE int popcount(UINT32 val)
+{
+ int count;
+
+ for (count = 0; val != 0; count++)
+ val &= val - 1;
+ return count;
+}
+
+
/* convert a series of 32 bits into a float */
INLINE float u2f(UINT32 v)
{
diff --git a/src/mame/drivers/namcona1.c b/src/mame/drivers/namcona1.c
index 55d94fed60c..35d0938dfc6 100644
--- a/src/mame/drivers/namcona1.c
+++ b/src/mame/drivers/namcona1.c
@@ -707,8 +707,8 @@ static WRITE16_HANDLER( mcu_command_w )
*/
static READ16_HANDLER( custom_key_r )
{
- static UINT8 keyseq;
static UINT16 count;
+ static UINT32 keyval;
int old_count;
old_count = count;
@@ -763,17 +763,18 @@ static READ16_HANDLER( custom_key_r )
case NAMCO_TINKLPIT:
if( offset==7 ) return 0x016f;
- if( offset==4 ) keyseq = 0;
+ if( offset==4 ) keyval = 0;
if( offset==3 )
{
- static const UINT16 data[] =
- {
- 0x0000,0x2000,0x2100,0x2104,0x0106,0x0007,0x4003,0x6021,
- 0x61a0,0x31a4,0x9186,0x9047,0xc443,0x6471,0x6db0,0x39bc,
- 0x9b8e,0x924f,0xc643,0x6471,0x6db0,0x19bc,0xba8e,0xb34b,
- 0xe745,0x4576,0x0cb7,0x789b,0xdb29,0xc2ec,0x16e2,0xb491
- };
- return data[(keyseq++)&0x1f];
+ UINT16 res;
+ res = BITSWAP16(keyval, 22,26,31,23,18,20,16,30,24,21,25,19,17,29,28,27);
+
+ keyval >>= 1;
+printf("popcount(%08X) = %d\n", keyval & 0x58000c00, popcount(keyval & 0x58000c00));
+ if((!keyval) || (popcount(keyval & 0x58000c00) & 1))
+ keyval ^= 0x80000000;
+
+ return res;
}
break;