]> git.lizzy.rs Git - plan9front.git/commitdiff
games/snes: implement DSP noise
authorMichael Forney <mforney@mforney.org>
Wed, 17 Feb 2021 10:19:50 +0000 (11:19 +0100)
committerMichael Forney <mforney@mforney.org>
Wed, 17 Feb 2021 10:19:50 +0000 (11:19 +0100)
I'm not sure if this LFSR is the same one used by the hardware or is
arbitrary, but it matches the noise sequence used by all other snes
emulators I looked at.

sys/src/games/snes/dsp.c

index 13406d216394e3c172078bc7760f7520d5f01cc3..4b5c0cfd2343dfc43e57fb6f8c779f3fc6d191e1 100644 (file)
@@ -6,7 +6,7 @@
 #include "fns.h"
 
 u8int dsp[256], dspstate;
-u16int dspcounter, noise;
+u16int dspcounter, noise = 0x8000;
 static s16int samp[2], echoin[2];
 
 enum {
@@ -517,6 +517,8 @@ dspstep(void)
                }
                if(dspcounter-- == 0)
                        dspcounter = 0x77ff;
+               if(envyes(dsp[FLG] & 0x1f))
+                       noise = (noise << 13 ^ noise << 14) & 0x8000 | noise >> 1 & ~1;
                break;
        case 31: voice(0, 4); voice(2, 1); break;
        }