From 994263eaf99a1cf2a436ce86b1047e8ca320e68a Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 27 May 2017 14:28:40 +0200 Subject: Add rand() function to pfunction expression parser. Use this to simulate E-B noise in Cheeky Mouse and fix the "cheese" choose. [Couriersud] --- src/lib/netlist/plib/pfunction.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/netlist/plib/pfunction.cpp') diff --git a/src/lib/netlist/plib/pfunction.cpp b/src/lib/netlist/plib/pfunction.cpp index c369dc2ed90..42f767ef562 100644 --- a/src/lib/netlist/plib/pfunction.cpp +++ b/src/lib/netlist/plib/pfunction.cpp @@ -12,6 +12,7 @@ #include #include +#include namespace plib { @@ -37,6 +38,7 @@ void pfunction::compile_postfix(const std::vector &inputs, for (const pstring &cmd : cmds) { + printf("%s %d\n", cmd.c_str(), stk); rpn_inst rc; if (cmd == "+") { rc.m_cmd = ADD; stk -= 1; } @@ -52,6 +54,8 @@ void pfunction::compile_postfix(const std::vector &inputs, { rc.m_cmd = SIN; stk -= 0; } else if (cmd == "cos") { rc.m_cmd = COS; stk -= 0; } + else if (cmd == "rand") + { rc.m_cmd = RAND; stk += 1; } else { for (unsigned i = 0; i < inputs.size(); i++) @@ -199,6 +203,9 @@ double pfunction::evaluate(const std::vector &values) OP(POW, 1, std::pow(ST2, ST1)) OP(SIN, 0, std::sin(ST2)); OP(COS, 0, std::cos(ST2)); + case RAND: + stack[ptr++] = static_cast(rand()) / static_cast(RAND_MAX); + break; case PUSH_INPUT: stack[ptr++] = values[static_cast(rc.m_param)]; break; -- cgit v1.2.3-70-g09d2