Add a replication of MSVC2003's rand() algorithm

This actually affects how the game sounds. Seriously, listen to the
dialogue boxes. Now it matches the original.
This commit is contained in:
Clownacy 2019-09-04 19:23:35 +00:00
parent e4fcf6a5e1
commit 22c967ca3a
5 changed files with 26 additions and 3 deletions

View file

@ -115,6 +115,7 @@ SOURCES = \
src/Organya \ src/Organya \
src/PixTone \ src/PixTone \
src/Profile \ src/Profile \
src/Random \
src/Resource \ src/Resource \
src/SelStage \ src/SelStage \
src/Shoot \ src/Shoot \

View file

@ -37,6 +37,7 @@
#include "NpcHit.h" #include "NpcHit.h"
#include "NpcTbl.h" #include "NpcTbl.h"
#include "Profile.h" #include "Profile.h"
#include "Random.h"
#include "SelStage.h" #include "SelStage.h"
#include "Shoot.h" #include "Shoot.h"
#include "Sound.h" #include "Sound.h"
@ -54,7 +55,7 @@ BOOL bContinue;
int Random(int min, int max) int Random(int min, int max)
{ {
const int range = max - min + 1; const int range = max - min + 1;
return min + rand() % range; return min + msvc_rand() % range;
} }
void PutNumber4(int x, int y, int value, BOOL bZero) void PutNumber4(int x, int y, int value, BOOL bZero)

View file

@ -6,6 +6,8 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Random.h"
static signed char gWaveModelTable[6][256]; static signed char gWaveModelTable[6][256];
void MakeWaveTables(void) void MakeWaveTables(void)
@ -54,9 +56,9 @@ void MakeWaveTables(void)
gWaveModelTable[4][i] = -0x40; gWaveModelTable[4][i] = -0x40;
// White noise wave // White noise wave
srand(0); msvc_srand(0);
for (i = 0; i < 256; ++i) for (i = 0; i < 256; ++i)
gWaveModelTable[5][i] = (signed char)(rand() & 0xFF) / 2; gWaveModelTable[5][i] = (signed char)(msvc_rand() & 0xFF) / 2;
} }
BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData) BOOL MakePixelWaveData(const PIXTONEPARAMETER *ptp, unsigned char *pData)

15
src/Random.cpp Normal file
View file

@ -0,0 +1,15 @@
#include "Random.h"
// A replication of MSVC's rand algorithm
static unsigned long next = 1;
int msvc_rand(void)
{
next = ((next) * 214013 + 2531011);
return ((next) >> 16) & 0x7FFF;
}
void msvc_srand(unsigned int seed)
{
next = seed;
}

4
src/Random.h Normal file
View file

@ -0,0 +1,4 @@
#pragma once
int msvc_rand(void);
void msvc_srand(unsigned int seed);