Browse Source

Cleanup, change to use indexing storage for `V` operator

master
cancel 6 years ago
parent
commit
e4627a7fd7
  1. 46
      sim.c

46
sim.c

@ -10,7 +10,7 @@ static Glyph const indexed_glyphs[] = {
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', // 24 - 35 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', // 24 - 35
}; };
enum { Glyphs_index_max = sizeof indexed_glyphs }; enum { Glyphs_index_count = sizeof indexed_glyphs };
// Always returns 0 through (sizeof indexed_glyphs) - 1, and works on // Always returns 0 through (sizeof indexed_glyphs) - 1, and works on
// capitalized glyphs as well. The index of the lower-cased glyph is returned // capitalized glyphs as well. The index of the lower-cased glyph is returned
@ -62,15 +62,17 @@ static Usz index_of(Glyph c) {
} }
#endif #endif
static Usz safe_index_of(Glyph c) { return index_of(c) % 36; }
static inline Glyph glyph_of(Usz index) { static inline Glyph glyph_of(Usz index) {
assert(index < Glyphs_index_max); assert(index < Glyphs_index_count);
return indexed_glyphs[index]; return indexed_glyphs[index];
} }
static Glyph glyphs_add(Glyph a, Glyph b) { static Glyph glyphs_add(Glyph a, Glyph b) {
Usz ia = index_of(a); Usz ia = index_of(a);
Usz ib = index_of(b); Usz ib = index_of(b);
return indexed_glyphs[(ia + ib) % Glyphs_index_max]; return indexed_glyphs[(ia + ib) % Glyphs_index_count];
} }
static inline bool glyph_is_lowercase(Glyph g) { return g & (1 << 5); } static inline bool glyph_is_lowercase(Glyph g) { return g & (1 << 5); }
@ -369,7 +371,7 @@ BEGIN_OPERATOR(midi)
oe->octave = (U8)usz_clamp(octave_num, 1, 9); oe->octave = (U8)usz_clamp(octave_num, 1, 9);
oe->note = note_num; oe->note = note_num;
oe->velocity = midi_velocity_of(velocity_g); oe->velocity = midi_velocity_of(velocity_g);
oe->bar_divisor = (U8)usz_clamp(index_of(length_g), 1, Glyphs_index_max); oe->bar_divisor = (U8)usz_clamp(index_of(length_g), 1, Glyphs_index_count);
END_OPERATOR END_OPERATOR
BEGIN_OPERATOR(osc) BEGIN_OPERATOR(osc)
@ -670,43 +672,25 @@ BEGIN_OPERATOR(uturn)
END_OPERATOR END_OPERATOR
BEGIN_OPERATOR(variable) BEGIN_OPERATOR(variable)
// hacky until we clean up
LOWERCASE_REQUIRES_BANG; LOWERCASE_REQUIRES_BANG;
PORT(0, -1, IN | PARAM); PORT(0, -1, IN | PARAM);
PORT(0, 1, IN); PORT(0, 1, IN | PARAM);
PORT(1, 0, OUT); PORT(1, 0, OUT);
{
Glyph left = PEEK(0, -1); Glyph left = PEEK(0, -1);
Usz var_idx;
if (left >= 'A' && left <= 'Z') {
var_idx = (Usz)('Z' - left);
} else if (left >= 'a' && left <= 'z') {
var_idx = (Usz)(('Z' - 'A') + ('z' - left) + 1);
} else {
goto next_phase;
}
Glyph right = PEEK(0, 1); Glyph right = PEEK(0, 1);
if (right == '.') if (right == '.')
goto next_phase;
extra_params->vars_slots[var_idx] = right;
}
next_phase : {
Glyph left = PEEK(0, -1);
if (left != '.')
return; return;
Glyph right = PEEK(0, 1); if (left == '.') {
Usz var_idx; // Read
if (right >= 'A' && right <= 'Z') { Usz var_idx = safe_index_of(right);
var_idx = (Usz)('Z' - right);
} else if (right >= 'a' && right <= 'z') {
var_idx = (Usz)(('Z' - 'A') + ('z' - right) + 1);
} else {
return;
}
Glyph result = extra_params->vars_slots[var_idx]; Glyph result = extra_params->vars_slots[var_idx];
if (result == '.') if (result == '.')
return; return;
POKE(1, 0, result); POKE(1, 0, result);
} else {
// Write
Usz var_idx = safe_index_of(left);
extra_params->vars_slots[var_idx] = right;
} }
END_OPERATOR END_OPERATOR
@ -748,7 +732,7 @@ END_OPERATOR
void orca_run(Gbuffer gbuf, Mbuffer mbuf, Usz height, Usz width, void orca_run(Gbuffer gbuf, Mbuffer mbuf, Usz height, Usz width,
Usz tick_number, Oevent_list* oevent_list, Usz tick_number, Oevent_list* oevent_list,
Piano_bits piano_bits) { Piano_bits piano_bits) {
Glyph vars_slots[('Z' - 'A' + 1) + ('z' - 'a' + 1)]; Glyph vars_slots[Glyphs_index_count];
memset(vars_slots, '.', sizeof(vars_slots)); memset(vars_slots, '.', sizeof(vars_slots));
mbuffer_clear(mbuf, height, width); mbuffer_clear(mbuf, height, width);
oevent_list_clear(oevent_list); oevent_list_clear(oevent_list);

Loading…
Cancel
Save