Files
86Box/src/disc_random.c
OBattler f6ef1f833c Vastly overhauled the UI, there's now a completely new Settings dialog as well as a status bar with disk activity icons and removable drive menus;
Thoroughly clean up the code to vastly reduce the number of compiler warnings and found and fixed several bugs in the process;
Applied all mainline PCem commits;
Added SCSI hard disk emulation;
Commented out all unfinished machines and graphics cards;
Added the AOpen AP53 and ASUS P/I-P55T2 machines as well as another Tyan 440FX machine, all three with AMI WinBIOS (patch from TheCollector1995);
Added the Diamond Stealth 3D 3000 (S3 ViRGE/VX) graphics card (patch from TheCollector1995);
Added the PS/2 XT IDE (AccuLogic) HDD Controller (patch from TheCollector1995);
Added Microsoft/Logitech Bus Mouse emulation (patch from waltje);
Overhauled the makefiles (patch from waltje);
Added the Adaptec AHA-1542CF SCSI controller (patch from waltje);
Added preliminary (but still unfinished) Adaptec AHA-154x SCSI controller BIOS support (patch from waltje);
Added an ISABugger debugging device (patch from waltje);
Added sanity checks to the Direct3D code.
2017-05-05 01:49:42 +02:00

75 lines
1.3 KiB
C

/* Better random number generator by Battler. */
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "disc_random.h"
uint32_t preconst = 0x6ED9EBA1;
static __inline__ uint32_t rotl32c (uint32_t x, uint32_t n)
{
assert (n<32);
return (x<<n) | (x>>(-n&31));
}
static __inline__ uint32_t rotr32c (uint32_t x, uint32_t n)
{
assert (n<32);
return (x>>n) | (x<<(-n&31));
}
#define ROTATE_LEFT rotl32c
#define ROTATE_RIGHT rotr32c
static __inline__ unsigned long long rdtsc(void)
{
unsigned hi, lo;
#ifdef __MSC__
__asm {
rdtsc
mov hi, edx ; EDX:EAX is already standard return!!
mov lo, eax
}
#else
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
#endif
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
}
static uint32_t RDTSC(void)
{
return (uint32_t) (rdtsc());
}
static void disc_random_twist(uint32_t *val)
{
*val = ROTATE_LEFT(*val, rand() % 32);
*val ^= 0x5A827999;
*val = ROTATE_RIGHT(*val, rand() % 32);
*val ^= 0x4ED32706;
}
uint8_t disc_random_generate()
{
uint16_t r = 0;
r = (rand() ^ ROTATE_LEFT(preconst, rand() % 32)) % 256;
disc_random_twist(&preconst);
return (r & 0xff);
}
void disc_random_init()
{
uint32_t seed = RDTSC();
srand(seed);
return;
}