From 0577aa3569f3ad303e62038415dbd93210ae0063 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 26 May 2022 19:00:14 -0500 Subject: [PATCH] SMS: early Nuked-PSG modding --- extern/Nuked-PSG/ympsg.c | 8 +++++--- extern/Nuked-PSG/ympsg.h | 4 +++- src/engine/platform/sms.cpp | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/extern/Nuked-PSG/ympsg.c b/extern/Nuked-PSG/ympsg.c index 8c1715ec..f6b8247b 100644 --- a/extern/Nuked-PSG/ympsg.c +++ b/extern/Nuked-PSG/ympsg.c @@ -125,10 +125,10 @@ static void YMPSG_ClockInternal1(ympsg_t *chip) } else if (noise_of && !chip->noise_of) { - noise_bit1 = (chip->noise >> 15) & 1; + noise_bit1 = (chip->noise >> chip->noise_tap2) & 1; noise_bit2 = (chip->noise >> 12) & 1; noise_bit1 ^= noise_bit2; - noise_next = ((noise_bit1 && ((chip->noise_data >> 2) & 1)) || ((chip->noise & 32767) == 0)); + noise_next = ((noise_bit1 && ((chip->noise_data >> 2) & 1)) || ((chip->noise & chip->noise_size) == 0)); chip->noise <<= 1; chip->noise |= noise_next; } @@ -253,11 +253,13 @@ uint16_t YMPSG_Read(ympsg_t *chip) return data; } -void YMPSG_Init(ympsg_t *chip) +void YMPSG_Init(ympsg_t *chip, uint8_t real_sn) { uint32_t i; memset(chip, 0, sizeof(ympsg_t)); YMPSG_SetIC(chip, 1); + chip->noise_tap2 = real_sn ? 13 : 15; + chip->noise_size = real_sn ? 16383 : 32767; for (i = 0; i < 16; i++) { YMPSG_Clock(chip); diff --git a/extern/Nuked-PSG/ympsg.h b/extern/Nuked-PSG/ympsg.h index f1596214..06310580 100644 --- a/extern/Nuked-PSG/ympsg.h +++ b/extern/Nuked-PSG/ympsg.h @@ -46,6 +46,8 @@ typedef struct { uint8_t sign_l; uint8_t noise_sign_l; uint16_t noise; + uint8_t noise_tap2; + uint16_t noise_size; uint8_t test; uint8_t volume_out[4]; @@ -62,7 +64,7 @@ typedef struct { void YMPSG_Write(ympsg_t *chip, uint8_t data); uint16_t YMPSG_Read(ympsg_t *chip); -void YMPSG_Init(ympsg_t *chip); +void YMPSG_Init(ympsg_t *chip, uint8_t real_sn); void YMPSG_SetIC(ympsg_t *chip, uint32_t ic); void YMPSG_Clock(ympsg_t *chip); float YMPSG_GetOutput(ympsg_t *chip); diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index 302317e9..c0dd9ed5 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -358,7 +358,7 @@ void DivPlatformSMS::reset() { addWrite(0xffffffff,0); } sn->device_start(); - YMPSG_Init(&sn_nuked); + YMPSG_Init(&sn_nuked,isRealSN); snNoiseMode=3; rWrite(0xe7); updateSNMode=false;