aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-02-24 01:33:45 +0100
committerPaul Oliver <contact@pauloliver.dev>2026-02-24 01:33:45 +0100
commit9f7e70904e6c0fa650323ac5e50ebf6003da333c (patch)
tree3015be498d36e8d5c960cf55667c6c825f7de493 /ui
parent0fb1497a62332e0db45f94b4f195cb37183678cb (diff)
Removes usage of Jinja templates
Use CPP to pre-process C files instead
Diffstat (limited to 'ui')
-rw-r--r--ui/curses/ui.c (renamed from ui/curses/ui.j2.c)351
-rw-r--r--ui/curses/ui_vars.py10
-rw-r--r--ui/daemon/ui.c (renamed from ui/daemon/ui.j2.c)25
-rw-r--r--ui/daemon/ui_vars.py10
4 files changed, 187 insertions, 209 deletions
diff --git a/ui/curses/ui.j2.c b/ui/curses/ui.c
index 2158eeb..faf1b6e 100644
--- a/ui/curses/ui.j2.c
+++ b/ui/curses/ui.c
@@ -1,30 +1,19 @@
-// Author: Paul Oliver <contact@pauloliver.dev>
-// Project: Salis
+#define LOG_LINE_COUNT 1024
+#define LOG_LINE_SIZE 1024
+#define PANE_WIDTH 27
+#define PROC_FIELD_WIDTH 21
+#define PROC_PAGE_LINES 12
-// Implements a curses TUI for the Salis simulator.
-// World view renders the contents of the VM memory buffer into a 7 channel image.
-// It supports zooming in and out, condensing the state of several bytes of memory
-// into single pixels (terminal cells). When zoomed in, each pixel represents a
-// single byte in memory.
+#define CTRL(x) (x & 0x1f)
-{% set pane_width = 27 %}
-{% set proc_field_width = 21 %}
-{% set proc_page_lines = 12 %}
+#if defined(NDEBUG)
+#define MIN_FPS 30
+#define MAX_FPS 60
+#else
+#define MIN_FPS 5
+#define MAX_FPS 10
+#endif
-{% set log_line_size = 1024 %}
-{% set log_line_count = 1024 %}
-
-{% macro ctrl(x) %}('{{ x }}' & 0x1f){% endmacro %}
-
-{% if not args.optimized %}
- {% set min_fps = 5 %}
- {% set max_fps = 10 %}
-{% else %}
- {% set min_fps = 30 %}
- {% set max_fps = 60 %}
-{% endif %}
-
-// pages
enum {
PAGE_CORE,
PAGE_PROCESS,
@@ -34,7 +23,6 @@ enum {
PAGE_COUNT,
};
-// color pairs
enum {
PAIR_NOUSE,
PAIR_NORMAL,
@@ -52,7 +40,7 @@ enum {
};
// GFX globals
-uint64_t g_gfx_vsiz; // zoom level
+uint64_t g_gfx_vsiz; // zoom level
uint64_t *g_gfx_inst; // instruction channel
uint64_t *g_gfx_mall; // allocated state channel
uint64_t *g_gfx_mbst; // memory block start channel
@@ -61,35 +49,35 @@ uint64_t *g_gfx_mb1s; // selected organism's memory block #2 channel
uint64_t *g_gfx_ipas; // selected organism's IP channel
uint64_t *g_gfx_spas; // selected organism's SP channel
-// TUI globals
-bool g_exit;
-bool g_running;
-unsigned g_core;
-unsigned g_page;
-bool g_proc_genes;
-uint64_t g_proc_scroll;
-uint64_t g_proc_field_scroll;
-uint64_t g_proc_gene_scroll;
-uint64_t g_proc_selected;
-uint64_t g_wrld_pos;
-uint64_t g_wrld_zoom;
-bool g_wcursor_mode;
-int g_wcursor_x;
-int g_wcursor_y;
-uint64_t g_wcursor_pointed;
-uint64_t g_log_cnt;
-unsigned g_log_ptr;
-unsigned g_log_scroll;
-bool g_log_warns[{{ log_line_count }}];
-time_t g_log_times[{{ log_line_count }}];
-char g_logs[{{ log_line_count }}][{{ log_line_size }}];
-uint64_t g_vlin;
-uint64_t g_vsiz;
-uint64_t g_vlin_rng;
-uint64_t g_vsiz_rng;
-uint64_t g_ivpt_scroll;
-char *g_line_buff;
-uint64_t g_step_block;
+// UI globals
+bool g_exit;
+bool g_running;
+unsigned g_core;
+unsigned g_page;
+bool g_proc_genes;
+uint64_t g_proc_scroll;
+uint64_t g_proc_field_scroll;
+uint64_t g_proc_gene_scroll;
+uint64_t g_proc_selected;
+uint64_t g_wrld_pos;
+uint64_t g_wrld_zoom;
+bool g_wcursor_mode;
+int g_wcursor_x;
+int g_wcursor_y;
+uint64_t g_wcursor_pointed;
+uint64_t g_log_cnt;
+unsigned g_log_ptr;
+unsigned g_log_scroll;
+bool g_log_warns[LOG_LINE_COUNT];
+time_t g_log_times[LOG_LINE_COUNT];
+char g_logs[LOG_LINE_COUNT][LOG_LINE_SIZE];
+uint64_t g_vlin;
+uint64_t g_vsiz;
+uint64_t g_vlin_rng;
+uint64_t g_vsiz_rng;
+uint64_t g_ivpt_scroll;
+char *g_line_buff;
+uint64_t g_step_block;
const wchar_t *g_zoomed_symbols = (
L"⠀⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙⡚⡛⡜⡝⡞⡟"
@@ -183,17 +171,17 @@ void gfx_clear_array(uint64_t *arry) {
memset(arry, 0, g_gfx_vsiz * sizeof(uint64_t));
}
-{% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
void gfx_accumulate_pixel(uint64_t pos, uint64_t zoom, uint64_t pixa, uint64_t *arry) {
assert(arry);
- uint64_t beg_mod = pos % {{ mvec_size }};
+ uint64_t beg_mod = pos % MVEC_SIZE;
uint64_t end_mod = beg_mod + (g_gfx_vsiz * zoom);
- uint64_t pix_mod = pixa % {{ mvec_size }};
+ uint64_t pix_mod = pixa % MVEC_SIZE;
- {% if not args.optimized %}
+#if !defined(NDEBUG)
uint64_t inc_cnt = 0;
- {% endif %}
+#endif
while (pix_mod < end_mod) {
if (pix_mod >= beg_mod && pix_mod < end_mod) {
@@ -201,23 +189,23 @@ void gfx_accumulate_pixel(uint64_t pos, uint64_t zoom, uint64_t pixa, uint64_t *
assert(pixi < g_gfx_vsiz);
arry[pixi]++;
- {% if not args.optimized %}
+#if !defined(NDEBUG)
inc_cnt++;
- {% endif %}
+#endif
}
- pix_mod += {{ mvec_size }};
+ pix_mod += MVEC_SIZE;
}
- {% if not args.optimized %}
+#if !defined(NDEBUG)
if (zoom != 1) {
assert(inc_cnt <= 2);
}
- {% endif %}
+#endif
}
-{% endif %}
+#endif
-{% if not arch_vars.mvec_loop %}
+#if !defined(MVEC_LOOP)
void gfx_accumulate_pixel(uint64_t pos, uint64_t zoom, uint64_t pixa, uint64_t *arry) {
assert(arry);
@@ -231,7 +219,7 @@ void gfx_accumulate_pixel(uint64_t pos, uint64_t zoom, uint64_t pixa, uint64_t *
assert(pixi < g_gfx_vsiz);
arry[pixi]++;
}
-{% endif %}
+#endif
void gfx_render_mbst(const struct Core *core, uint64_t pos, uint64_t zoom) {
assert(core);
@@ -321,7 +309,7 @@ void gfx_render(const struct Core *core, uint64_t pos, uint64_t zoom, uint64_t p
}
// ----------------------------------------------------------------------------
-// TUI generic functions
+// UI generic functions
// ----------------------------------------------------------------------------
void ui_line_buff_free() {
if (g_line_buff) {
@@ -419,14 +407,13 @@ void ui_print_core(int l) {
++l;
- {% if arch_vars.core_fields|length %}
+#if CORE_FIELD_COUNT != 0
ui_line(false, ++l, PAIR_HEADER, A_BOLD, "ARCH SPECIFIC");
- {% for type, name, print in arch_vars.core_fields if print %}
- {% if type == "uint64_t" %}
- ui_ulx_field(++l, "{{ name }}", g_cores[g_core].{{ name }});
- {% endif %}
- {% endfor %}
- {% endif %}
+
+#define CORE_FIELD(type, name, suffix) ui_ulx_field(++l, #name, (uint64_t)g_cores[g_core].name);
+ CORE_FIELDS
+#undef CORE_FIELD
+#endif
}
// ----------------------------------------------------------------------------
@@ -451,7 +438,7 @@ void ui_print_process_genome_header(int l) {
}
void ui_print_process_gene(int l, int gcol, uint64_t gidx, uint64_t mba, uint64_t pix, int pair) {
- assert(gcol >= {{ pane_width }} + 2);
+ assert(gcol >= PANE_WIDTH + 2);
assert(gcol < COLS);
assert(mvec_proc_is_live(&g_cores[g_core], pix));
assert(pair == PAIR_SELECTED_MB1 || pair == PAIR_SELECTED_MB2);
@@ -459,10 +446,10 @@ void ui_print_process_gene(int l, int gcol, uint64_t gidx, uint64_t mba, uint64_
const struct Core *core = &g_cores[g_core];
uint64_t addr = mba + gidx;
- uint8_t byte = mvec_get_byte(core, addr);
+ uint8_t byte = mvec_get_byte(core, addr);
wchar_t gsym[2] = { arch_symbol(byte), L'\0' };
- cchar_t cchar = { 0 };
+ cchar_t cchar = { 0 };
int pair_cell;
@@ -487,8 +474,8 @@ void ui_print_process_genes(int l, uint64_t pix) {
const struct Core *core = &g_cores[g_core];
- int scol = {{ pane_width }} + 2;
- int gcol = scol - g_proc_gene_scroll;
+ int scol = PANE_WIDTH + 2;
+ int gcol = scol - g_proc_gene_scroll;
uint64_t mb0a = arch_proc_mb0_addr(core, pix);
uint64_t mb0s = arch_proc_mb0_size(core, pix);
uint64_t mb1a = arch_proc_mb1_addr(core, pix);
@@ -518,7 +505,7 @@ void ui_print_process_field_header_element(int l, int fidx, const char *name) {
}
int foff = fidx - g_proc_field_scroll;
- int fcol = foff * {{ proc_field_width }} + {{ pane_width }} - 1;
+ int fcol = foff * PROC_FIELD_WIDTH + PANE_WIDTH - 1;
ui_field(l, fcol, PAIR_NORMAL, A_NORMAL, " : %18s", name);
}
@@ -528,9 +515,9 @@ void ui_print_process_field_header(int l) {
int fidx = 0;
- {% for _, val in arch_vars.proc_fields %}
- ui_print_process_field_header_element(l, fidx++, "{{ val }}");
- {% endfor %}
+#define PROC_FIELD(type, name) ui_print_process_field_header_element(l, fidx++, #name);
+ PROC_FIELDS
+#undef PROC_FIELD
}
void ui_print_process_field_element(int l, int fidx, int fclr, uint64_t field) {
@@ -541,7 +528,7 @@ void ui_print_process_field_element(int l, int fidx, int fclr, uint64_t field) {
}
int foff = fidx - g_proc_field_scroll;
- int fcol = foff * {{ proc_field_width }} + {{ pane_width }} - 1;
+ int fcol = foff * PROC_FIELD_WIDTH + PANE_WIDTH - 1;
ui_field(l, fcol, fclr, A_NORMAL, " : %#18lx", field);
}
@@ -554,9 +541,9 @@ void ui_print_process_fields(int l, uint64_t pix) {
int fidx = 0;
int fclr = ui_proc_pair(pix);
- {% for _, val in arch_vars.proc_fields %}
- ui_print_process_field_element(l, fidx++, fclr, proc->{{ val }});
- {% endfor %}
+#define PROC_FIELD(type, name) ui_print_process_field_element(l, fidx++, fclr, proc->name);
+ PROC_FIELDS
+#undef PROC_FIELD
}
void ui_print_process(int l) {
@@ -595,14 +582,14 @@ void ui_print_process(int l) {
void ui_world_resize() {
assert(g_wrld_zoom);
- g_vlin = 0;
- g_vsiz = 0;
+ g_vlin = 0;
+ g_vsiz = 0;
g_vlin_rng = 0;
g_vsiz_rng = 0;
- if (COLS > {{ pane_width }}) {
- g_vlin = COLS - {{ pane_width }};
- g_vsiz = LINES * g_vlin;
+ if (COLS > PANE_WIDTH) {
+ g_vlin = COLS - PANE_WIDTH;
+ g_vsiz = LINES * g_vlin;
g_vlin_rng = g_vlin * g_wrld_zoom;
g_vsiz_rng = g_vsiz * g_wrld_zoom;
@@ -610,14 +597,14 @@ void ui_world_resize() {
}
}
-{% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
void ui_print_cell(uint64_t i, uint64_t r, uint64_t x, uint64_t y) {
-{% else %}
+#else
void ui_print_cell(uint64_t i, uint64_t r, uint64_t x, uint64_t y, uint64_t a) {
-{% endif %}
- wchar_t inst_nstr[2] = { L'\0', L'\0' };
- cchar_t cchar = { 0 };
- uint64_t inst_avrg = g_gfx_inst[i] / g_wrld_zoom;
+#endif
+ wchar_t inst_nstr[2] = { L'\0', L'\0' };
+ cchar_t cchar = { 0 };
+ uint64_t inst_avrg = g_gfx_inst[i] / g_wrld_zoom;
if (g_wrld_zoom == 1) {
inst_nstr[0] = arch_symbol((uint8_t)inst_avrg);
@@ -627,11 +614,11 @@ void ui_print_cell(uint64_t i, uint64_t r, uint64_t x, uint64_t y, uint64_t a) {
int pair_cell;
- {% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
if (g_wcursor_mode && r == (uint64_t)g_wcursor_x && y == (uint64_t)g_wcursor_y) {
- {% else %}
- if (a >= {{ mvec_size }} || (g_wcursor_mode && r == (uint64_t)g_wcursor_x && y == (uint64_t)g_wcursor_y)) {
- {% endif %}
+#else
+ if (a >= MVEC_SIZE || (g_wcursor_mode && r == (uint64_t)g_wcursor_x && y == (uint64_t)g_wcursor_y)) {
+#endif
pair_cell = PAIR_NORMAL;
} else if (g_wcursor_mode && r == (uint64_t)g_wcursor_x && y == (uint64_t)g_wcursor_y) {
pair_cell = PAIR_NORMAL;
@@ -660,18 +647,18 @@ void ui_print_wcursor_bar() {
const struct Core *core = &g_cores[g_core];
- char cownr[{{ proc_field_width }}];
+ char cownr[PROC_FIELD_WIDTH];
- uint64_t cpos = g_vlin * g_wcursor_y + g_wcursor_x;
+ uint64_t cpos = g_vlin * g_wcursor_y + g_wcursor_x;
uint64_t caddr = cpos * g_wrld_zoom + g_wrld_pos;
- uint8_t cbyte = mvec_get_byte(core, caddr);
+ uint8_t cbyte = mvec_get_byte(core, caddr);
if (mvec_is_alloc(core, caddr)) {
g_wcursor_pointed = mvec_get_owner(core, caddr);
- snprintf(cownr, {{ proc_field_width }}, "%#lx", g_wcursor_pointed);
+ snprintf(cownr, PROC_FIELD_WIDTH, "%#lx", g_wcursor_pointed);
} else {
g_wcursor_pointed = (uint64_t)(-1);
- snprintf(cownr, {{ proc_field_width }}, "-");
+ snprintf(cownr, PROC_FIELD_WIDTH, "-");
}
mvprintw(
@@ -707,9 +694,9 @@ void ui_print_world(int l) {
const struct Proc *psel = proc_get(&g_cores[g_core], g_proc_selected);
- {% for _, val in arch_vars.proc_fields %}
- ui_ulx_field(l++, "{{ val }}", psel->{{ val }});
- {% endfor %}
+#define PROC_FIELD(type, name) ui_ulx_field(l++, #name, psel->name);
+ PROC_FIELDS
+#undef PROC_FIELD
if (!g_vlin) {
return;
@@ -727,16 +714,15 @@ void ui_print_world(int l) {
for (uint64_t i = 0; i < g_vsiz; ++i) {
uint64_t r = i % g_vlin;
- uint64_t x = r + {{ pane_width }};
+ uint64_t x = r + PANE_WIDTH;
uint64_t y = i / g_vlin;
- {% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
ui_print_cell(i, r, x, y);
- {% else %}
+#else
uint64_t a = g_wrld_pos + (i * g_wrld_zoom);
-
ui_print_cell(i, r, x, y, a);
- {% endif %}
+#endif
}
if (g_wcursor_mode) {
@@ -748,18 +734,18 @@ void ui_print_world(int l) {
// IPC page functions
// ----------------------------------------------------------------------------
void ui_print_ipc_field(int l, uint64_t i, int color) {
- uint8_t iinst = g_cores[g_core].iviv[i];
+ uint8_t iinst = g_cores[g_core].iviv[i];
uint64_t iaddr = g_cores[g_core].ivav[i];
- ui_field(l, {{ pane_width }}, color, A_NORMAL, "%#18x : %#18x : %#18x", i, iinst, iaddr);
+ ui_field(l, PANE_WIDTH, color, A_NORMAL, "%#18x : %#18x : %#18x", i, iinst, iaddr);
}
void ui_print_ipc_data() {
- ui_field(0, {{ pane_width }}, PAIR_NORMAL, A_NORMAL, "%18s : %18s : %18s", "ipci", "inst", "addr");
+ ui_field(0, PANE_WIDTH, PAIR_NORMAL, A_NORMAL, "%18s : %18s : %18s", "ipci", "inst", "addr");
int l = 1 - g_ivpt_scroll;
- for (uint64_t i = 0; i < {{ sync_interval }}; ++i) {
+ for (uint64_t i = 0; i < SYNC_INTERVAL; ++i) {
if (i == g_cores[g_core].ivpt) {
if (l >= 1) {
ui_print_ipc_field(l++, i, PAIR_SELECTED_PROC);
@@ -770,7 +756,7 @@ void ui_print_ipc_data() {
uint8_t iinst = g_cores[g_core].iviv[i];
- if ((iinst & {{ ipc_flag }}) != 0) {
+ if ((iinst & IPC_FLAG) != 0) {
if (l >= 1) {
ui_print_ipc_field(l++, i, PAIR_LIVE_PROC);
}
@@ -781,7 +767,7 @@ void ui_print_ipc_data() {
for (; l < LINES; ++l) {
if (l >= 1) {
- move(l, {{ pane_width }});
+ move(l, PANE_WIDTH);
clrtoeol();
}
}
@@ -809,11 +795,11 @@ void ui_info_impl(const char *format, ...) {
va_list args;
va_start(args, format);
- vsnprintf(g_logs[g_log_ptr], {{ log_line_size }}, format, args);
+ vsnprintf(g_logs[g_log_ptr], LOG_LINE_SIZE, format, args);
va_end(args);
g_log_cnt++;
- g_log_ptr = (g_log_ptr + 1) % {{ log_line_count }};
+ g_log_ptr = (g_log_ptr + 1) % LOG_LINE_COUNT;
}
void ui_warn_impl(const char *format, ...) {
@@ -822,35 +808,33 @@ void ui_warn_impl(const char *format, ...) {
va_list args;
va_start(args, format);
- vsnprintf(g_logs[g_log_ptr], {{ log_line_size }}, format, args);
+ vsnprintf(g_logs[g_log_ptr], LOG_LINE_SIZE, format, args);
va_end(args);
g_log_cnt++;
- g_log_ptr = (g_log_ptr + 1) % {{ log_line_count }};
+ g_log_ptr = (g_log_ptr + 1) % LOG_LINE_COUNT;
}
void ui_clear_log_line(int line) {
assert(line >= 0 && line < LINES);
- move(line, {{ pane_width }});
+ move(line, PANE_WIDTH);
clrtoeol();
}
void ui_print_log_line(unsigned lptr, int line) {
- assert(lptr < {{ log_line_count }});
+ assert(lptr < LOG_LINE_COUNT);
assert(line >= 0 && line < LINES);
ui_clear_log_line(line);
- // Prints a log entry
if (strlen(g_logs[lptr])) {
struct tm tm = *localtime(&g_log_times[lptr]);
- // Timestamp
ui_field(
line,
- {{ pane_width }},
+ PANE_WIDTH,
PAIR_NORMAL,
A_NORMAL,
- ": %d-%02d-%02d %02d:%02d:%02d",
+ " %d-%02d-%02d %02d:%02d:%02d",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
@@ -859,19 +843,17 @@ void ui_print_log_line(unsigned lptr, int line) {
tm.tm_sec
);
- // Level
ui_field(
line,
- {{ pane_width }} + 22,
+ PANE_WIDTH + 22,
g_log_warns[lptr] ? PAIR_WARN : PAIR_HEADER,
A_NORMAL,
- g_log_warns[lptr] ? "WARN:" : "INFO:"
+ g_log_warns[lptr] ? "[WARN]" : "[INFO]"
);
- // Message
ui_field(
line,
- {{ pane_width }} + 28,
+ PANE_WIDTH + 29,
PAIR_NORMAL,
A_NORMAL,
g_logs[lptr]
@@ -888,10 +870,10 @@ void ui_print_log(int l) {
ui_ulx_field(l++, "lptr", g_log_ptr);
unsigned lptr = g_log_ptr;
- int line = LINES + g_log_scroll;
+ int line = LINES + g_log_scroll;
while (line) {
- lptr = (lptr - 1 + {{ log_line_count }}) % {{ log_line_count }};
+ lptr = (lptr - 1 + LOG_LINE_COUNT) % LOG_LINE_COUNT;
line--;
if (line < LINES) {
@@ -915,14 +897,18 @@ void ui_print_log(int l) {
void ui_print() {
int l = 1;
- ui_line(false, l++, PAIR_HEADER, A_BOLD, "SALIS [%d:%d]", g_core, {{ args.cores }});
- ui_str_field(l++, "name", "{{ args.name }}");
- ui_ulx_field(l++, "seed", {{ args.seed }});
- ui_str_field(l++, "fbit", "{{ "yes" if args.muta_flip else "no" }}");
- ui_ulx_field(l++, "asav", {{ auto_save_interval }});
- ui_str_field(l++, "arch", "{{ args.arch }}");
- ui_ulx_field(l++, "size", {{ mvec_size }});
- ui_ulx_field(l++, "syni", {{ sync_interval }});
+ ui_line(false, l++, PAIR_HEADER, A_BOLD, "SALIS [%d:%d]", g_core, CORES);
+ ui_str_field(l++, "name", NAME);
+ ui_ulx_field(l++, "seed", SEED);
+#if defined(MUTA_FLIP)
+ ui_str_field(l++, "fbit", "yes");
+#else
+ ui_str_field(l++, "fbit", "no");
+#endif
+ ui_ulx_field(l++, "asav", AUTOSAVE_INTERVAL);
+ ui_str_field(l++, "arch", ARCH);
+ ui_ulx_field(l++, "size", MVEC_SIZE);
+ ui_ulx_field(l++, "syni", SYNC_INTERVAL);
ui_ulx_field(l++, "step", g_steps);
ui_ulx_field(l++, "sync", g_syncs);
ui_ulx_field(l++, "step", g_step_block);
@@ -956,10 +942,10 @@ void ev_vscroll(int ev) {
case PAGE_PROCESS:
switch (ev) {
case 'W':
- g_proc_scroll += (LINES > {{ proc_page_lines }}) ? LINES - {{ proc_page_lines }} : 0;
+ g_proc_scroll += (LINES > PROC_PAGE_LINES) ? LINES - PROC_PAGE_LINES : 0;
break;
case 'S':
- g_proc_scroll -= (LINES > {{ proc_page_lines }}) ? LINES - {{ proc_page_lines }} : 0;
+ g_proc_scroll -= (LINES > PROC_PAGE_LINES) ? LINES - PROC_PAGE_LINES : 0;
break;
case 'w':
g_proc_scroll += 1;
@@ -987,15 +973,15 @@ void ev_vscroll(int ev) {
g_wrld_pos += g_vlin_rng;
break;
case 's':
- {% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
g_wrld_pos -= g_vlin_rng;
- {% else %}
+#else
if (g_wrld_pos < g_vlin_rng) {
g_wrld_pos = 0;
} else {
g_wrld_pos -= g_vlin_rng;
}
- {% endif %}
+#endif
break;
case 'q':
g_wrld_pos = 0;
@@ -1030,14 +1016,14 @@ void ev_vscroll(int ev) {
switch (ev) {
case 'W':
g_log_scroll += LINES;
- g_log_scroll = g_log_scroll >= {{ log_line_count }} ? {{ log_line_count }} - 1 : g_log_scroll;
+ g_log_scroll = g_log_scroll >= LOG_LINE_COUNT ? LOG_LINE_COUNT - 1 : g_log_scroll;
break;
case 'S':
g_log_scroll -= g_log_scroll < (uint64_t)LINES ? g_log_scroll : (uint64_t)LINES;
break;
case 'w':
g_log_scroll += 1;
- g_log_scroll = g_log_scroll >= {{ log_line_count }} ? {{ log_line_count }} - 1 : g_log_scroll;
+ g_log_scroll = g_log_scroll >= LOG_LINE_COUNT ? LOG_LINE_COUNT - 1 : g_log_scroll;
break;
case 's':
g_log_scroll -= g_log_scroll ? 1 : 0;
@@ -1078,15 +1064,15 @@ void ev_hscroll(int ev) {
case PAGE_WORLD:
switch (ev) {
case 'a':
- {% if arch_vars.mvec_loop %}
+#if defined(MVEC_LOOP)
g_wrld_pos -= g_wrld_zoom;
- {% else %}
+#else
if (g_wrld_pos < g_wrld_zoom) {
g_wrld_pos = 0;
} else {
g_wrld_pos -= g_wrld_zoom;
}
- {% endif %}
+#endif
break;
case 'd':
g_wrld_pos += g_wrld_zoom;
@@ -1106,7 +1092,7 @@ void ev_zoom(int ev) {
case PAGE_WORLD:
switch (ev) {
case 'x':
- g_wrld_zoom *= (g_vlin != 0 && g_vsiz_rng < {{ mvec_size }}) ? 2 : 1;
+ g_wrld_zoom *= (g_vlin != 0 && g_vsiz_rng < MVEC_SIZE) ? 2 : 1;
ui_world_resize();
break;
case 'z':
@@ -1201,16 +1187,16 @@ void ev_handle() {
}
switch (ev) {
- case {{ ctrl('c') }}:
+ case CTRL('c'):
g_exit = true;
break;
case KEY_SLEFT:
clear();
- g_core = (g_core + {{ args.cores }} - 1) % {{ args.cores }};
+ g_core = (g_core + CORES - 1) % CORES;
break;
case KEY_SRIGHT:
clear();
- g_core = (g_core + 1) % {{ args.cores }};
+ g_core = (g_core + 1) % CORES;
break;
case KEY_LEFT:
clear();
@@ -1226,7 +1212,7 @@ void ev_handle() {
ui_world_resize();
if (g_vlin) {
- while (g_vsiz_rng >= {{ mvec_size }} * 2 && g_wrld_zoom != 1) {
+ while (g_vsiz_rng >= MVEC_SIZE * 2 && g_wrld_zoom != 1) {
g_wrld_zoom /= 2;
ui_world_resize();
}
@@ -1318,30 +1304,29 @@ void init() {
start_color();
init_color(COLOR_BLACK, 0, 0, 0);
- init_pair(PAIR_NORMAL, COLOR_WHITE, COLOR_BLACK );
- init_pair(PAIR_HEADER, COLOR_BLUE, COLOR_BLACK );
- init_pair(PAIR_WARN, COLOR_RED, COLOR_BLACK );
- init_pair(PAIR_LIVE_PROC, COLOR_BLUE, COLOR_BLACK );
- init_pair(PAIR_SELECTED_PROC, COLOR_YELLOW, COLOR_BLACK );
- init_pair(PAIR_FREE_CELL, COLOR_BLACK, COLOR_BLUE );
- init_pair(PAIR_ALLOC_CELL, COLOR_BLACK, COLOR_CYAN );
- init_pair(PAIR_MEM_BLOCK_START, COLOR_BLACK, COLOR_WHITE );
- init_pair(PAIR_SELECTED_MB1, COLOR_BLACK, COLOR_YELLOW );
- init_pair(PAIR_SELECTED_MB2, COLOR_BLACK, COLOR_GREEN );
- init_pair(PAIR_SELECTED_IP, COLOR_BLACK, COLOR_RED );
- init_pair(PAIR_SELECTED_SP, COLOR_BLACK, COLOR_MAGENTA);
+ init_pair(PAIR_NORMAL, COLOR_WHITE, COLOR_BLACK);
+ init_pair(PAIR_HEADER, COLOR_BLUE, COLOR_BLACK);
+ init_pair(PAIR_WARN, COLOR_RED, COLOR_BLACK);
+ init_pair(PAIR_LIVE_PROC, COLOR_BLUE, COLOR_BLACK);
+ init_pair(PAIR_SELECTED_PROC, COLOR_YELLOW, COLOR_BLACK);
+ init_pair(PAIR_FREE_CELL, COLOR_BLACK, COLOR_BLUE);
+ init_pair(PAIR_ALLOC_CELL, COLOR_BLACK, COLOR_CYAN);
+ init_pair(PAIR_MEM_BLOCK_START, COLOR_BLACK, COLOR_WHITE);
+ init_pair(PAIR_SELECTED_MB1, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(PAIR_SELECTED_MB2, COLOR_BLACK, COLOR_GREEN);
+ init_pair(PAIR_SELECTED_IP, COLOR_BLACK, COLOR_RED);
+ init_pair(PAIR_SELECTED_SP, COLOR_BLACK, COLOR_MAGENTA);
- // Install loggers
g_info = ui_info_impl;
g_warn = ui_warn_impl;
- {% if args.command == "new" %}
+#if defined(COMMAND_NEW)
salis_init();
- {% elif args.command == "load" %}
+#elif defined(COMMAND_LOAD)
salis_load();
- {% endif %}
+#endif
- g_wrld_zoom = 1;
+ g_wrld_zoom = 1;
g_step_block = 1;
ui_line_buff_resize();
@@ -1355,11 +1340,11 @@ void exec() {
salis_step(g_step_block - (g_steps % g_step_block));
clock_t end = clock();
- if ((end - beg) < (CLOCKS_PER_SEC / {{ min_fps }})) {
+ if ((end - beg) < (CLOCKS_PER_SEC / MIN_FPS)) {
g_step_block <<= 1;
}
- if ((end - beg) >= (CLOCKS_PER_SEC / {{ max_fps }}) && g_step_block != 1) {
+ if ((end - beg) >= (CLOCKS_PER_SEC / MAX_FPS) && g_step_block != 1) {
g_step_block >>= 1;
}
}
@@ -1372,7 +1357,7 @@ void exec() {
void quit() {
gfx_free();
ui_line_buff_free();
- salis_save("{{ sim_path }}");
+ salis_save(SIM_PATH);
salis_free();
endwin();
}
diff --git a/ui/curses/ui_vars.py b/ui/curses/ui_vars.py
index 97d2c07..54f62e3 100644
--- a/ui/curses/ui_vars.py
+++ b/ui/curses/ui_vars.py
@@ -1,5 +1,5 @@
-def gen_ui_vars(_):
- return {
- "flags": ["-lncurses", "-DNCURSES_WIDECHAR=1"],
- "includes": ["curses.h", "locale.h", "time.h"],
- }
+class UIVars:
+ def __init__(self, _):
+ self.includes = {"curses.h", "locale.h", "time.h"}
+ self.defines = {"-DNCURSES_WIDECHAR=1"}
+ self.links = {"-lncurses"}
diff --git a/ui/daemon/ui.j2.c b/ui/daemon/ui.c
index 02df79b..1f6c35c 100644
--- a/ui/daemon/ui.j2.c
+++ b/ui/daemon/ui.c
@@ -1,16 +1,9 @@
-// Author: Paul Oliver <contact@pauloliver.dev>
-// Project: Salis
-
-// Lightweight UI for the Salis simulator with minimal output.
-// Can be interrupted through OS signals.
-// Ideal for running Salis in the background.
-
volatile bool g_running;
-uint64_t g_step_block;
+uint64_t g_step_block;
void info_impl(const char *restrict fmt, ...) {
assert(fmt);
- printf("\033[1;34mINFO:\033[0m ");
+ printf("\033[1;34m[INFO]\033[0m ");
va_list args;
va_start(args, fmt);
@@ -22,7 +15,7 @@ void info_impl(const char *restrict fmt, ...) {
void warn_impl(const char *restrict fmt, ...) {
assert(fmt);
- printf("\033[1;31mWARN:\033[0m ");
+ printf("\033[1;33m[WARN]\033[0m ");
va_list args;
va_start(args, fmt);
@@ -61,16 +54,16 @@ int main() {
g_info = info_impl;
g_warn = warn_impl;
- {% if args.command == "new" %}
+#if defined(COMMAND_NEW)
salis_init();
- {% elif args.command == "load" %}
+#elif defined(COMMAND_LOAD)
salis_load();
- {% endif %}
+#endif
- g_running = true;
+ g_running = true;
g_step_block = 1;
- signal(SIGINT, sig_handler);
+ signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
while (g_running) {
@@ -78,7 +71,7 @@ int main() {
}
g_info("Saving simulation...");
- salis_save("{{ sim_path }}");
+ salis_save(SIM_PATH);
salis_free();
g_info("Exiting salis...");
diff --git a/ui/daemon/ui_vars.py b/ui/daemon/ui_vars.py
index bb6be7c..5b3d372 100644
--- a/ui/daemon/ui_vars.py
+++ b/ui/daemon/ui_vars.py
@@ -1,5 +1,5 @@
-def gen_ui_vars(_):
- return {
- "flags": [],
- "includes": ["signal.h", "stdio.h", "unistd.h"],
- }
+class UIVars:
+ def __init__(self, _):
+ self.includes = {"signal.h", "stdio.h", "unistd.h"}
+ self.defines = set()
+ self.links = set()