swissChili | bb478f1 | 2020-08-07 20:45:07 -0700 | [diff] [blame^] | 1 | #include "screen.h" |
| 2 | #include "cpu.h" |
| 3 | |
| 4 | struct nk_color byte_to_color(uint8_t b) |
| 5 | { |
| 6 | struct nk_color c; |
| 7 | c.r = (b >> 6) * (255 / 0b11); |
| 8 | c.g = ((b >> 2) & 0b111) * (255 / 0b111); |
| 9 | c.b = (b & 0b11) * (255 / 0b11); |
| 10 | c.a = 255; |
| 11 | return c; |
| 12 | } |
| 13 | |
| 14 | void screen(struct nk_context *ctx, uint8_t *mem, uint8_t size) |
| 15 | { |
| 16 | struct nk_command_buffer *out = nk_window_get_canvas(ctx); |
| 17 | |
| 18 | struct nk_rect bounds; |
| 19 | enum nk_widget_layout_states state = nk_widget(&bounds, ctx); |
| 20 | |
| 21 | if (!state) |
| 22 | return; |
| 23 | |
| 24 | //nk_fill_rect(out, bounds, 0, nk_rgb(255, 0, 0)); |
| 25 | |
| 26 | //return; |
| 27 | |
| 28 | for (int i = 0; i < CPU_FB_H; i++) |
| 29 | { |
| 30 | for (int j = 0; j < CPU_FB_W; j++) |
| 31 | { |
| 32 | nk_fill_rect(out, |
| 33 | nk_rect(bounds.x + i * size, bounds.y + j * size, |
| 34 | size, size), 0.0f, |
| 35 | byte_to_color(mem[i * CPU_FB_H + j])); |
| 36 | } |
| 37 | } |
| 38 | } |