ref: 22c967ca3a4a4c40b9f7840697de99174a56ff97
parent: e4fcf6a5e19ece9977a4a4f6fad683d09b70f9dc
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Sep 4 15:23:35 EDT 2019
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.
--- a/Makefile
+++ b/Makefile
@@ -115,6 +115,7 @@
src/Organya \
src/PixTone \
src/Profile \
+ src/Random \
src/Resource \
src/SelStage \
src/Shoot \
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -37,6 +37,7 @@
#include "NpcHit.h"
#include "NpcTbl.h"
#include "Profile.h"
+#include "Random.h"
#include "SelStage.h"
#include "Shoot.h"
#include "Sound.h"
@@ -54,7 +55,7 @@
int Random(int min, int max)
{
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)
--- a/src/PixTone.cpp
+++ b/src/PixTone.cpp
@@ -6,6 +6,8 @@
#include "WindowsWrapper.h"
+#include "Random.h"
+
static signed char gWaveModelTable[6][256];
void MakeWaveTables(void)
@@ -54,9 +56,9 @@
gWaveModelTable[4][i] = -0x40;
// White noise wave
- srand(0);
+ msvc_srand(0);
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)
--- /dev/null
+++ b/src/Random.cpp
@@ -1,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;
+}
--- /dev/null
+++ b/src/Random.h
@@ -1,0 +1,4 @@
+#pragma once
+
+int msvc_rand(void);
+void msvc_srand(unsigned int seed);
--
⑨