From c22e26c5cb6f39cc446f5419679a068f10466f24 Mon Sep 17 00:00:00 2001 From: MooglyGuy Date: Sun, 27 Jan 2019 21:54:17 +0100 Subject: -spg2xx: More correct PRNG emulation, nw --- src/devices/machine/spg2xx.cpp | 48 +++++++++++------------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/devices/machine/spg2xx.cpp b/src/devices/machine/spg2xx.cpp index a5e3aa11288..19bc7151b3b 100644 --- a/src/devices/machine/spg2xx.cpp +++ b/src/devices/machine/spg2xx.cpp @@ -1025,38 +1025,6 @@ void spg2xx_device::uart_rx(uint8_t data) } } -static uint16_t prng_mul(uint16_t a, uint16_t b) -{ - uint16_t d = 0; - if (a >= 0x8000) a &= 0x7fff; - if (b >= 0x8000) b &= 0x7fff; - for (int i = 0; i < 16; i++) - { - d = (d > 0x4000) ? ((d << 1) - 0x8000) : (d << 1); - if (a & 0x8000) - d += b; - if (d >= 0x8000) - d -= 0x8000; - a <<= 1; - } - return d; -} - -static uint16_t prng_pow(uint16_t value, uint16_t exponent) -{ - uint16_t r = 1; - while (exponent > 0) - { - if (exponent & 1) - { - r = prng_mul(r, value); - } - exponent >>= 1; - value = prng_mul(value, value); - } - return r; -} - READ16_MEMBER(spg2xx_device::io_r) { static const char *const gpioregs[] = { "GPIO Data Port", "GPIO Buffer Port", "GPIO Direction Port", "GPIO Attribute Port", "GPIO IRQ/Latch Port" }; @@ -1134,16 +1102,14 @@ READ16_MEMBER(spg2xx_device::io_r) case 0x2c: // PRNG 0 { const uint16_t value = m_io_regs[0x2c]; - const uint16_t pow14 = prng_pow(value, 14); - m_io_regs[0x2c] = (pow14*value + pow14 + 1) & 0x7fff; + m_io_regs[0x2c] = ((value << 1) | (BIT(value, 14) ^ BIT(value, 13))) & 0x7fff; return value; } case 0x2d: // PRNG 1 { const uint16_t value = m_io_regs[0x2d]; - const uint16_t pow14 = prng_pow(value, 14); - m_io_regs[0x2d] = (pow14*value + pow14 + 1) & 0x7fff; + m_io_regs[0x2d] = ((value << 1) | (BIT(value, 14) ^ BIT(value, 13))) & 0x7fff; return value; } @@ -1712,6 +1678,16 @@ WRITE16_MEMBER(spg2xx_device::io_w) break; } + case 0x2c: // PRNG 0 seed + LOGMASKED(LOG_IO_WRITES, "io_w: PRNG 0 seed = %04x\n", data & 0x7fff); + m_io_regs[offset] = data & 0x7fff; + break; + + case 0x2d: // PRNG 1 seed + LOGMASKED(LOG_IO_WRITES, "io_w: PRNG 1 seed = %04x\n", data & 0x7fff); + m_io_regs[offset] = data & 0x7fff; + break; + case 0x2e: // FIQ Source Select { static const char* const s_fiq_select[8] = -- cgit v1.2.3