diff options
author | Paul Oliver <contact@pauloliver.dev> | 2025-02-09 13:07:55 -0800 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2025-02-09 13:07:55 -0800 |
commit | 519e1e0f76b8fcf3fcefa84a15bfd904c087c273 (patch) | |
tree | b449767607e40b0745a495f1ccb1784924d41988 | |
parent | 6edade339744b6631717242b0111f5dc1ae79194 (diff) |
-rw-r--r-- | src/graphics.c | 21 | ||||
-rw-r--r-- | src/salis.c | 44 | ||||
-rw-r--r-- | src/ui/curses.c | 25 |
3 files changed, 83 insertions, 7 deletions
diff --git a/src/graphics.c b/src/graphics.c index 8114f30..780b879 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -89,10 +89,9 @@ void gfx_render_inst(const Core *core, u64 pos, u64 zoom) { for (u64 j = 0; j < zoom; ++j) { u64 addr = pos + (i * zoom) + j; - u8 byte = mvec_get_byte(core, addr); - g_gfx_inst[i] += byte; - g_gfx_mall[i] += (byte & MALL_FLAG) ? 1 : 0; + g_gfx_inst[i] += mvec_get_byte(core, addr); + g_gfx_mall[i] += mvec_is_alloc(core, addr) ? 1 : 0; } } } @@ -102,6 +101,7 @@ void gfx_clear_array(u64 *arry) { memset(arry, 0, g_gfx_vsiz * sizeof(u64)); } +#ifdef MVEC_LOOP void gfx_accumulate_pixel(u64 pos, u64 zoom, u64 pixa, u64 *arry) { assert(arry); @@ -134,6 +134,21 @@ void gfx_accumulate_pixel(u64 pos, u64 zoom, u64 pixa, u64 *arry) { } #endif } +#else +void gfx_accumulate_pixel(u64 pos, u64 zoom, u64 pixa, u64 *arry) { + assert(arry); + + u64 end = pos + (g_gfx_vsiz * zoom); + + if (pixa < pos || pixa >= end) { + return; + } + + u64 pixi = (pixa - pos) / zoom; + assert(pixi < g_gfx_vsiz); + arry[pixi]++; +} +#endif void gfx_render_mbst(const Core *core, u64 pos, u64 zoom) { assert(core); diff --git a/src/salis.c b/src/salis.c index 814dd0d..6714038 100644 --- a/src/salis.c +++ b/src/salis.c @@ -73,51 +73,93 @@ const Proc g_dead_proc; char g_mnemo_table[0x100][MNEMONIC_BUFF_SIZE]; #endif +#ifdef MVEC_LOOP u64 mvec_loop(u64 addr) { return addr % MVEC_SIZE; } +#endif bool mvec_is_alloc(const Core *core, u64 addr) { assert(core); +#ifdef MVEC_LOOP return core->mvec[mvec_loop(addr)] & MALL_FLAG ? true : false; +#else + if (addr < MVEC_SIZE) { + return core->mvec[addr] & MALL_FLAG ? true : false; + } else { + return true; + } +#endif } void mvec_alloc(Core *core, u64 addr) { assert(core); assert(!mvec_is_alloc(core, addr)); +#ifdef MVEC_LOOP core->mvec[mvec_loop(addr)] |= MALL_FLAG; +#else + assert(addr < MVEC_SIZE); + core->mvec[addr] |= MALL_FLAG; +#endif core->mall++; } void mvec_free(Core *core, u64 addr) { assert(core); assert(mvec_is_alloc(core, addr)); +#ifdef MVEC_LOOP core->mvec[mvec_loop(addr)] ^= MALL_FLAG; +#else + assert(addr < MVEC_SIZE); + core->mvec[addr] ^= MALL_FLAG; +#endif core->mall--; } u8 mvec_get_byte(const Core *core, u64 addr) { assert(core); +#ifdef MVEC_LOOP return core->mvec[mvec_loop(addr)]; +#else + if (addr < MVEC_SIZE) { + return core->mvec[addr]; + } else { + return 0; + } +#endif } u8 mvec_get_inst(const Core *core, u64 addr) { assert(core); +#ifdef MVEC_LOOP return core->mvec[mvec_loop(addr)] & INST_MASK; +#else + if (addr < MVEC_SIZE) { + return core->mvec[addr] & INST_MASK; + } else { + return 0; + } +#endif } void mvec_set_inst(Core *core, u64 addr, u8 inst) { assert(core); assert(inst < INST_CAPS); +#ifdef MVEC_LOOP core->mvec[mvec_loop(addr)] &= MALL_FLAG; core->mvec[mvec_loop(addr)] |= inst; +#else + assert(addr < MVEC_SIZE); + core->mvec[addr] &= MALL_FLAG; + core->mvec[addr] |= inst; +#endif } #if MUTA_FLIP_BIT == 1 void mvec_flip_bit(Core *core, u64 addr, int bit) { assert(core); assert(bit < 8); - core->mvec[mvec_loop(addr)] ^= (1 << bit) & INST_MASK; + core->mvec[addr] ^= (1 << bit) & INST_MASK; } #endif diff --git a/src/ui/curses.c b/src/ui/curses.c index 8f91d9f..1d70ca7 100644 --- a/src/ui/curses.c +++ b/src/ui/curses.c @@ -337,7 +337,7 @@ void ui_world_resize() { } } -void ui_print_cell(u64 i, u64 r, u64 x, u64 y) { +void ui_print_cell(u64 i, u64 r, u64 x, u64 y, u64 a) { wchar_t inst_nstr[2] = { L'\0', L'\0' }; cchar_t cchar = { 0 }; u64 inst_avrg = g_gfx_inst[i] / g_wrld_zoom; @@ -350,7 +350,9 @@ void ui_print_cell(u64 i, u64 r, u64 x, u64 y) { int pair_cell; - if (g_wcursor_mode && r == (u64)g_wcursor_x && y == (u64)g_wcursor_y) { + if (a >= MVEC_SIZE) { + pair_cell = PAIR_NORMAL; + } else if (g_wcursor_mode && r == (u64)g_wcursor_x && y == (u64)g_wcursor_y) { pair_cell = PAIR_NORMAL; } else if (g_gfx_ipas[i] != 0) { pair_cell = PAIR_SELECTED_IP; @@ -460,8 +462,9 @@ void ui_print_world(int l) { u64 r = i % g_vlin; u64 x = r + PANE_WIDTH; u64 y = i / g_vlin; + u64 a = g_wrld_pos + (i * g_wrld_zoom); - ui_print_cell(i, r, x, y); + ui_print_cell(i, r, x, y, a); } if (g_wcursor_mode) { @@ -591,7 +594,15 @@ void ev_vscroll(int ev) { g_wrld_pos += g_vlin_rng; break; case 's': +#ifdef MVEC_LOOP g_wrld_pos -= g_vlin_rng; +#else + if (g_wrld_pos < g_vlin_rng) { + g_wrld_pos = 0; + } else { + g_wrld_pos -= g_vlin_rng; + } +#endif break; case 'q': g_wrld_pos = 0; @@ -652,7 +663,15 @@ void ev_hscroll(int ev) { case PAGE_WORLD: switch (ev) { case 'a': +#ifdef MVEC_LOOP g_wrld_pos -= g_wrld_zoom; +#else + if (g_wrld_pos < g_wrld_zoom) { + g_wrld_pos = 0; + } else { + g_wrld_pos -= g_wrld_zoom; + } +#endif break; case 'd': g_wrld_pos += g_wrld_zoom; |