Fix issues identified by Vas and LordKale4:

- made local netlists in Cheeky Mouse static
- replace stdlib rand by 16 bit galois lfsr

(nw)
This commit is contained in:
couriersud 2017-05-27 22:13:52 +02:00
parent e110d9a2df
commit 0a2d4a256d
4 changed files with 16 additions and 4 deletions

View File

@ -121,6 +121,7 @@ namespace netlist
f = true;
}
}
//FIXME: Use power terminals!
if (!f)
log().warning(MW_1_NO_POWER_TERMINALS_ON_DEVICE_1, out_proxied->device().name());
else

View File

@ -12,7 +12,6 @@
#include <cmath>
#include <stack>
#include <stdlib.h>
namespace plib {
@ -204,7 +203,7 @@ double pfunction::evaluate(const std::vector<double> &values)
OP(SIN, 0, std::sin(ST2));
OP(COS, 0, std::cos(ST2));
case RAND:
stack[ptr++] = static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
stack[ptr++] = lfsr_random();
break;
case PUSH_INPUT:
stack[ptr++] = values[static_cast<unsigned>(rc.m_param)];

View File

@ -44,6 +44,7 @@ namespace plib {
};
public:
pfunction()
: m_lfsr(0xACE1u)
{
}
@ -79,7 +80,18 @@ namespace plib {
void compile_postfix(const std::vector<pstring> &inputs,
const std::vector<pstring> &cmds, const pstring &expr);
double lfsr_random()
{
std::uint16_t lsb = m_lfsr & 1;
m_lfsr >>= 1;
if (lsb)
m_lfsr ^= 0xB400u; // taps 15, 13, 12, 10
return static_cast<double>(m_lfsr) / static_cast<double>(0xffffu);
}
std::vector<rpn_inst> m_precompiled; //!< precompiled expression
std::uint16_t m_lfsr; //!< lfsr used for generating random numbers
};

View File

@ -41,7 +41,7 @@
* there is nothing to amplify currently.
*/
NETLIST_START(cheekyms_schematics)
static NETLIST_START(cheekyms_schematics)
// Shared chips
TTL_7404_DIP(IC1)
@ -239,7 +239,7 @@ NETLIST_END()
*
*/
NETLIST_START(NOISE)
static NETLIST_START(NOISE)
CS(FC, 0)
PARAM(FC.FUNC, "0.0000001 rand *")