ref: ca259636fa5a55cfb0445acd4b665f98865013b9
parent: 2eeb52c125842593fd8340af8deb268f286e1ce6
author: cancel <cancel@cancel.fm>
date: Tue Dec 4 10:47:53 EST 2018
Add '!' (keys) operator
--- a/.clang-format
+++ b/.clang-format
@@ -2,5 +2,5 @@
PointerAlignment: Left
ReflowComments: false
-MacroBlockBegin: "^BEGIN_SOLO_PHASE_.|^BEGIN_DUAL_PHASE_.|^BEGIN_DUAL_PORTS|^BEGIN_HASTE|^BEGIN_IF_."
+MacroBlockBegin: "^BEGIN_SOLO_PHASE_.|^BEGIN_DUAL_PHASE_.|^BEGIN_ACTIVE_PORTS|^BEGIN_DUAL_PORTS|^BEGIN_HASTE|^BEGIN_IF_."
MacroBlockEnd: "^END_PHASE|^END_PORTS|^END_HASTE|^END_IF"
--- a/sim.c
+++ b/sim.c
@@ -126,6 +126,7 @@
Usz size;
Bank_cursor cursor;
Glyph const* vars_slots;
+ Piano_bits piano_bits;
} Oper_bank_read_params;
static void oper_bank_store(Oper_bank_write_params* bank_params, Usz width,
@@ -257,6 +258,10 @@
{ \
bool const Oper_ports_enabled = Dual_is_active;
+#define BEGIN_ACTIVE_PORTS \
+ { \
+ bool const Oper_ports_enabled = true;
+
#define DUAL_IS_ACTIVE Dual_is_active
#define IS_AWAKE (!(cell_flags & (Mark_flag_lock | Mark_flag_sleep)))
@@ -283,6 +288,7 @@
//////// Operators
#define ORCA_SOLO_OPERATORS(_) \
+ _('!', keys) \
_('#', comment) \
_('*', bang)
@@ -322,12 +328,25 @@
'N' : case 'n' : case 'E' : case 'e' : case 'S' : case 's' : case 'W' \
: case 'w' : case 'Z' : case 'z'
-BEGIN_SOLO_PHASE_0(bang)
- if (IS_AWAKE) {
- BECOME('.');
- }
+BEGIN_SOLO_PHASE_0(keys)
+ BEGIN_ACTIVE_PORTS
+ PORT(0, 1, IN);
+ PORT(1, 0, OUT);
+ END_PORTS
END_PHASE
-BEGIN_SOLO_PHASE_1(bang)
+BEGIN_SOLO_PHASE_1(keys)
+ Glyph g = PEEK(0, 1);
+ Piano_bits pb = piano_bits_of(g);
+ // instead of this extra branch, could maybe just leave output port unlocked
+ // so the '*' goes away on its own?
+ if (pb == ORCA_PIANO_BITS_NONE)
+ return;
+ Glyph o;
+ if (ORCA_LIKELY((pb & bank_params->piano_bits) == ORCA_PIANO_BITS_NONE))
+ o = '.';
+ else
+ o = '*';
+ POKE(1, 0, o);
END_PHASE
BEGIN_SOLO_PHASE_0(comment)
@@ -347,6 +366,14 @@
BEGIN_SOLO_PHASE_1(comment)
END_PHASE
+BEGIN_SOLO_PHASE_0(bang)
+ if (IS_AWAKE) {
+ BECOME('.');
+ }
+END_PHASE
+BEGIN_SOLO_PHASE_1(bang)
+END_PHASE
+
BEGIN_DUAL_PHASE_0(add)
REALIZE_DUAL;
BEGIN_DUAL_PORTS
@@ -934,7 +961,6 @@
void orca_run(Gbuffer gbuf, Mbuffer mbuf, Usz height, Usz width,
Usz tick_number, Bank* bank, Piano_bits piano_bits) {
- (void)piano_bits;
Glyph vars_slots[('Z' - 'A' + 1) + ('z' - 'a' + 1)];
memset(vars_slots, '.', sizeof(vars_slots));
mbuffer_clear(mbuf, height, width);
@@ -946,7 +972,8 @@
Oper_bank_read_params bank_read_params;
bank_read_params.bank = bank;
bank_read_params.size = bank_write_params.size;
- bank_read_params.vars_slots = &vars_slots[0];
bank_cursor_reset(&bank_read_params.cursor);
+ bank_read_params.vars_slots = &vars_slots[0];
+ bank_read_params.piano_bits = piano_bits;
sim_phase_1(gbuf, mbuf, height, width, tick_number, &bank_read_params);
}
--- a/tui_main.c
+++ b/tui_main.c
@@ -83,6 +83,8 @@
case 'Z':
case 'z':
return Glyph_class_movement;
+ case '!':
+ return Glyph_class_uppercase;
case '*':
return Glyph_class_bang;
case '#':
@@ -497,6 +499,7 @@
Tui_cursor tui_cursor;
tui_cursor_init(&tui_cursor);
Tui_input_mode input_mode = Tui_input_mode_normal;
+ Piano_bits piano_bits = ORCA_PIANO_BITS_NONE;
Usz tick_num = 0;
Usz ruler_spacing_y = 8;
Usz ruler_spacing_x = 8;
@@ -522,7 +525,7 @@
field_resize_raw_if_necessary(&scratch_field, field.height, field.width);
field_copy(&field, &scratch_field);
orca_run(field.buffer, markmap_r.buffer, field.height, field.width,
- tick_num, &bank, ORCA_PIANO_BITS_NONE);
+ tick_num, &bank, piano_bits);
field_copy(&scratch_field, &field);
needs_remarking = false;
}
@@ -565,7 +568,6 @@
}
wrefresh(cont_win);
- Piano_bits piano_bits = ORCA_PIANO_BITS_NONE;
int key;
// ncurses gives us ERR if there was no user input. We'll sleep for 0
// seconds, so that we'll yield CPU time to the OS instead of looping as
@@ -651,6 +653,7 @@
orca_run(field.buffer, markmap_r.buffer, field.height, field.width,
tick_num, &bank, piano_bits);
++tick_num;
+ piano_bits = ORCA_PIANO_BITS_NONE;
needs_remarking = true;
break;
default: