From 3e45ae73d5575582972f3f1169466a590814aefa Mon Sep 17 00:00:00 2001 From: Nicola Pisanti Date: Mon, 20 May 2019 22:44:15 +0200 Subject: [PATCH] replaces banger with bounce operator --- sim.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/sim.c b/sim.c index 197db99..42ec0ec 100644 --- a/sim.c +++ b/sim.c @@ -221,7 +221,7 @@ static void oper_poke_and_stun(Glyph* restrict gbuffer, Mark* restrict mbuffer, #define ALPHA_OPERATORS(_) \ _('A', add) \ - _('B', banger) \ + _('B', bounce) \ _('C', clock) \ _('D', delay) \ _('E', movement) \ @@ -425,22 +425,25 @@ BEGIN_OPERATOR(add) POKE(1, 0, indexed_glyphs[(a + b) % Glyphs_index_count]); END_OPERATOR -BEGIN_OPERATOR(banger) +BEGIN_OPERATOR(bounce) LOWERCASE_REQUIRES_BANG; - PORT(0, 1, IN | NONLOCKING); + PORT(0, -1, IN | PARAM); + PORT(0, 1, IN); PORT(1, 0, OUT); - Glyph g = PEEK(0, 1); - Glyph result; - switch (g) { - case '1': - case '*': - case MOVEMENT_CASES: - result = '*'; - break; - default: - result = '.'; + Usz rate = index_of(PEEK(0, -1)); + Usz to = index_of(PEEK(0, 1)); + if (rate == 0) + rate = 1; + if (to < 2) { + POKE(1, 0, glyph_of(0)); + return; } - POKE(1, 0, result); + to = to - 1; + Usz key = (Tick_number / rate) % (to * 2); + if (key > to) + key = to - (key - to); + Glyph g = glyph_of(key); + POKE(1, 0, g); END_OPERATOR BEGIN_OPERATOR(clock)