10. Maygate Cell
Randomly sets the state of a wire to be 1 or 0.
byte 1: wire to set. 0 by default.
For now, this is just a cointoss (50/50) probability.
If the data is non-zero, maygate can function as a conditional jump. The random state of 1 will cause a jump to the location stored in the data byte.
<<exfuncs>>=
static int maygate(trig_vm *vm,
int pos,
uint32_t cmd,
uint32_t data)
{
int byte;
int wire;
double rnd;
byte = (cmd >> 8) & 0xFF;
/* right most bit */
byte &= -byte;
wire = 0;
while (byte >>= 1) wire++;
rnd = (double) rand() / RAND_MAX;
if (rnd > 0.5) {
trig_vm_wire_set(vm, wire, 1);
} else {
trig_vm_wire_set(vm, wire, 0);
}
if (data == 0) {
return (pos + 1) % 32;
} else {
if (rnd > 0.5) {
int go;
byte = data;
byte &= -byte;
go = 0;
while (byte >>= 1) go++;
return go;
} else {
return (pos + 1) % 32;
}
}
}
prev | home | next