diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-23 20:45:37 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-23 20:45:37 +0200 |
commit | 4959741a7eaac3b429912a1ccfd7ebe06d41ef0d (patch) | |
tree | b6d9a25de3cd38af4b9214534c066538cc3f783a | |
parent | eeeacde00c589cb227746b164a39372356d1eeec (diff) | |
download | stepper-4959741a7eaac3b429912a1ccfd7ebe06d41ef0d.tar.gz stepper-4959741a7eaac3b429912a1ccfd7ebe06d41ef0d.zip |
Add back cursor drawing
-rw-r--r-- | src/assets.c | 2 | ||||
-rw-r--r-- | src/drawing.c | 40 | ||||
-rw-r--r-- | src/globals.c | 10 | ||||
-rw-r--r-- | src/main.c | 17 | ||||
-rw-r--r-- | src/profiling.c | 85 | ||||
-rw-r--r-- | src/renderer_m0.c | 78 | ||||
-rw-r--r-- | src/sequencer.c | 2 |
7 files changed, 100 insertions, 134 deletions
diff --git a/src/assets.c b/src/assets.c index 64a2265..f685a05 100644 --- a/src/assets.c +++ b/src/assets.c | |||
@@ -81,7 +81,7 @@ static const u32 note_name_sprites[] = { | |||
81 | 0xe0000000, 0xe0202020, 0x0e000000, 0x0e0a0e0a, | 81 | 0xe0000000, 0xe0202020, 0x0e000000, 0x0e0a0e0a, |
82 | }; | 82 | }; |
83 | 83 | ||
84 | u32 ch_btn_sprite[] = { | 84 | static const u32 ch_btn_sprite[] = { |
85 | // CH1 | 85 | // CH1 |
86 | 0x888e80ff, 0xff808e88, | 86 | 0x888e80ff, 0xff808e88, |
87 | 0xa1a100ff, 0xff00a9e1, | 87 | 0xa1a100ff, 0xff00a9e1, |
diff --git a/src/drawing.c b/src/drawing.c index 0f6afb0..83ffb50 100644 --- a/src/drawing.c +++ b/src/drawing.c | |||
@@ -80,7 +80,7 @@ draw_trigger(size_t chan, size_t i) { | |||
80 | size_t offset_y = i < 8 ? 0 : TRIG_OFFSET_Y; | 80 | size_t offset_y = i < 8 ? 0 : TRIG_OFFSET_Y; |
81 | size_t x = TRIG_START_X + offset_x; | 81 | size_t x = TRIG_START_X + offset_x; |
82 | size_t y = TRIG_START_Y + offset_y; | 82 | size_t y = TRIG_START_Y + offset_y; |
83 | u32 *tile = ¬e_name_sprites[4 * trig.note]; | 83 | const u32 *tile = ¬e_name_sprites[4 * trig.note]; |
84 | draw_icn(x, y, &tile[0], COL_FG, 1, 0); | 84 | draw_icn(x, y, &tile[0], COL_FG, 1, 0); |
85 | draw_icn(x + 8, y, &tile[2], COL_FG, 1, 0); | 85 | draw_icn(x + 8, y, &tile[2], COL_FG, 1, 0); |
86 | } else { | 86 | } else { |
@@ -99,11 +99,11 @@ draw_trig_cursor(size_t i, u8 clr) { | |||
99 | } | 99 | } |
100 | 100 | ||
101 | void | 101 | void |
102 | draw_right_col_cursor(u8 clr) { | 102 | draw_right_col_cursor(int i, u8 clr) { |
103 | size_t x0 = 0; | 103 | size_t x0 = 0; |
104 | size_t x1 = 0; | 104 | size_t x1 = 0; |
105 | size_t y = 0; | 105 | size_t y = 0; |
106 | switch (right_col_selection_loc) { | 106 | switch (i) { |
107 | case R_COL_BPM: { | 107 | case R_COL_BPM: { |
108 | x0 = BPM_START_X; | 108 | x0 = BPM_START_X; |
109 | x1 = x0 + R_COL_W; | 109 | x1 = x0 + R_COL_W; |
@@ -593,7 +593,7 @@ draw_parameters_wave(void) { | |||
593 | 593 | ||
594 | // Draw default wave buttons. | 594 | // Draw default wave buttons. |
595 | { | 595 | { |
596 | u32 *tile = default_wave_buttons; | 596 | const u32 *tile = default_wave_buttons; |
597 | size_t x = PARAMS_START_X; | 597 | size_t x = PARAMS_START_X; |
598 | size_t y = PARAMS_START_Y + PARAMS_H - 12; | 598 | size_t y = PARAMS_START_Y + PARAMS_H - 12; |
599 | for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) { | 599 | for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) { |
@@ -1246,6 +1246,36 @@ draw_parameters(void) { | |||
1246 | } | 1246 | } |
1247 | 1247 | ||
1248 | void | 1248 | void |
1249 | draw_cursors(void) { | 1249 | clear_cursors(void) { |
1250 | draw_trig_cursor(last_trig_loc, COL_BG); | ||
1251 | draw_channel_cursor(last_channel_loc, COL_BG); | ||
1252 | draw_pattern_cursor(last_pattern_loc, COL_BG); | ||
1253 | draw_right_col_cursor(last_right_col_loc, COL_BG); | ||
1254 | } | ||
1250 | 1255 | ||
1256 | void | ||
1257 | draw_cursors(void) { | ||
1258 | clear_cursors(); | ||
1259 | if (input_handler == handle_trigger_selection) { | ||
1260 | draw_trig_cursor(trig_selection_loc, COL_CURSOR); | ||
1261 | } | ||
1262 | if (input_handler == handle_channel_selection) { | ||
1263 | draw_channel_cursor(channel_selection_loc, COL_CURSOR); | ||
1264 | } else { | ||
1265 | draw_channel_cursor(channel_selection_loc, COL_GREY); | ||
1266 | } | ||
1267 | if (input_handler == handle_pattern_selection) { | ||
1268 | draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); | ||
1269 | } else { | ||
1270 | draw_pattern_cursor(pattern_selection_loc, COL_GREY); | ||
1271 | } | ||
1272 | if (input_handler == handle_right_col_selection) { | ||
1273 | draw_right_col_cursor(right_col_selection_loc, COL_CURSOR); | ||
1274 | } | ||
1275 | if (input_handler == handle_param_selection_sq1 || | ||
1276 | input_handler == handle_param_selection_sq2 || | ||
1277 | input_handler == handle_param_selection_wave || | ||
1278 | input_handler == handle_param_selection_noise) { | ||
1279 | draw_params_cursor(param_selection_loc, COL_CURSOR); | ||
1280 | } | ||
1251 | } | 1281 | } |
diff --git a/src/globals.c b/src/globals.c index bf0c5b6..e718dd4 100644 --- a/src/globals.c +++ b/src/globals.c | |||
@@ -9,9 +9,13 @@ int channel_selection_loc = 0; | |||
9 | int pattern_selection_loc = 0; | 9 | int pattern_selection_loc = 0; |
10 | int right_col_selection_loc = 0; | 10 | int right_col_selection_loc = 0; |
11 | int play_status = 0; | 11 | int play_status = 0; |
12 | static int current_pattern = 0; | 12 | int current_pattern = 0; |
13 | static int next_pattern = 0; | 13 | int next_pattern = 0; |
14 | static int current_bank = 0; | 14 | int current_bank = 0; |
15 | u32 last_trig_loc = 0; | ||
16 | u32 last_channel_loc = 0; | ||
17 | u32 last_pattern_loc = 0; | ||
18 | u32 last_right_col_loc = 0; | ||
15 | 19 | ||
16 | // | 20 | // |
17 | // Color indexes. | 21 | // Color indexes. |
@@ -18,7 +18,6 @@ WITH REGARD TO THIS SOFTWARE. | |||
18 | #define PROF_ENABLE 1 | 18 | #define PROF_ENABLE 1 |
19 | #include "profiling.c" | 19 | #include "profiling.c" |
20 | 20 | ||
21 | |||
22 | void | 21 | void |
23 | render(void) { | 22 | render(void) { |
24 | PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); | 23 | PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); |
@@ -67,12 +66,16 @@ render(void) { | |||
67 | redraw_params = false; | 66 | redraw_params = false; |
68 | } | 67 | } |
69 | 68 | ||
70 | // TODO: Make sure we are drawing the cursors properly. | ||
71 | // PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); | ||
72 | // PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); | ||
73 | // PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); | ||
74 | |||
75 | // PROF(draw_current_step(COL_RED), draw_cursor_cycles); | 69 | // PROF(draw_current_step(COL_RED), draw_cursor_cycles); |
70 | PROF(draw_cursors(), draw_cursor_cycles); | ||
71 | } | ||
72 | |||
73 | void | ||
74 | update(void) { | ||
75 | last_trig_loc = trig_selection_loc; | ||
76 | last_channel_loc = channel_selection_loc; | ||
77 | last_pattern_loc = pattern_selection_loc; | ||
78 | last_right_col_loc = right_col_selection_loc; | ||
76 | } | 79 | } |
77 | 80 | ||
78 | int | 81 | int |
@@ -101,8 +104,8 @@ main(void) { | |||
101 | PROF_SHOW(); | 104 | PROF_SHOW(); |
102 | FRAME_START(); | 105 | FRAME_START(); |
103 | PROF(flip_buffer(), flip_cycles); | 106 | PROF(flip_buffer(), flip_cycles); |
107 | PROF(update(), update_cycles); | ||
104 | PROF(handle_sequencer_input(), input_cycles); | 108 | PROF(handle_sequencer_input(), input_cycles); |
105 | // TODO: Update function to performa animations, etc. | ||
106 | PROF(render(), render_cycles); | 109 | PROF(render(), render_cycles); |
107 | FRAME_END(); | 110 | FRAME_END(); |
108 | } | 111 | } |
diff --git a/src/profiling.c b/src/profiling.c index a3b073b..0255552 100644 --- a/src/profiling.c +++ b/src/profiling.c | |||
@@ -60,8 +60,9 @@ static bool profile_show = true; | |||
60 | txt_printf(">PARAM %.8lu\n", avg_draw_param_cycles);\ | 60 | txt_printf(">PARAM %.8lu\n", avg_draw_param_cycles);\ |
61 | txt_printf(">PIANO %.8lu\n", avg_draw_piano_cycles);\ | 61 | txt_printf(">PIANO %.8lu\n", avg_draw_piano_cycles);\ |
62 | txt_printf(">CURSOR %.8lu\n", avg_draw_cursor_cycles);\ | 62 | txt_printf(">CURSOR %.8lu\n", avg_draw_cursor_cycles);\ |
63 | txt_printf("RENDER %.8lu\n", avg_render_cycles);\ | 63 | txt_printf("UPDATE %.8lu\n", avg_update_cycles);\ |
64 | txt_printf("INPUT %.8lu\n", avg_input_cycles);\ | 64 | txt_printf("INPUT %.8lu\n", avg_input_cycles);\ |
65 | txt_printf("RENDER %.8lu\n", avg_render_cycles);\ | ||
65 | txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\ | 66 | txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\ |
66 | txt_render();\ | 67 | txt_render();\ |
67 | }\ | 68 | }\ |
@@ -82,53 +83,57 @@ static bool profile_show = true; | |||
82 | 83 | ||
83 | static u32 prof_frame_counter = 0; | 84 | static u32 prof_frame_counter = 0; |
84 | 85 | ||
85 | static u32 frame_cycles = 0; | 86 | static u32 frame_cycles = 0; |
86 | static u32 flip_cycles = 0; | 87 | static u32 flip_cycles = 0; |
87 | static u32 clear_cycles = 0; | 88 | static u32 clear_cycles = 0; |
88 | static u32 input_cycles = 0; | 89 | static u32 input_cycles = 0; |
89 | static u32 draw_trigs_cycles = 0; | 90 | static u32 draw_trigs_cycles = 0; |
90 | static u32 draw_btn_cycles = 0; | 91 | static u32 draw_btn_cycles = 0; |
91 | static u32 draw_piano_cycles = 0; | 92 | static u32 draw_piano_cycles = 0; |
92 | static u32 draw_param_cycles = 0; | 93 | static u32 draw_param_cycles = 0; |
93 | static u32 draw_cursor_cycles = 0; | 94 | static u32 draw_cursor_cycles = 0; |
94 | static u32 render_cycles = 0; | 95 | static u32 render_cycles = 0; |
96 | static u32 update_cycles = 0; | ||
95 | 97 | ||
96 | static u32 avg_frame_cycles = 0; | 98 | static u32 avg_frame_cycles = 0; |
97 | static u32 avg_flip_cycles = 0; | 99 | static u32 avg_flip_cycles = 0; |
98 | static u32 avg_clear_cycles = 0; | 100 | static u32 avg_clear_cycles = 0; |
99 | static u32 avg_input_cycles = 0; | 101 | static u32 avg_input_cycles = 0; |
100 | static u32 avg_draw_trigs_cycles = 0; | 102 | static u32 avg_draw_trigs_cycles = 0; |
101 | static u32 avg_draw_btns_cycles = 0; | 103 | static u32 avg_draw_btns_cycles = 0; |
102 | static u32 avg_draw_piano_cycles = 0; | 104 | static u32 avg_draw_piano_cycles = 0; |
103 | static u32 avg_draw_param_cycles = 0; | 105 | static u32 avg_draw_param_cycles = 0; |
104 | static u32 avg_draw_cursor_cycles = 0; | 106 | static u32 avg_draw_cursor_cycles = 0; |
105 | static u32 avg_render_cycles = 0; | 107 | static u32 avg_render_cycles = 0; |
108 | static u32 avg_update_cycles = 0; | ||
106 | 109 | ||
107 | #if PROF_ENABLE == 1 | 110 | #if PROF_ENABLE == 1 |
108 | #define FRAME_START()\ | 111 | #define FRAME_START()\ |
109 | do { \ | 112 | do { \ |
110 | if (prof_frame_counter == PROF_N_FRAMES) {\ | 113 | if (prof_frame_counter == PROF_N_FRAMES) {\ |
111 | avg_frame_cycles = frame_cycles / prof_frame_counter;\ | 114 | avg_frame_cycles = frame_cycles / prof_frame_counter;\ |
112 | avg_flip_cycles = flip_cycles / prof_frame_counter;\ | 115 | avg_flip_cycles = flip_cycles / prof_frame_counter;\ |
113 | avg_clear_cycles = clear_cycles / prof_frame_counter;\ | 116 | avg_clear_cycles = clear_cycles / prof_frame_counter;\ |
114 | avg_draw_trigs_cycles = draw_trigs_cycles / prof_frame_counter;\ | 117 | avg_draw_trigs_cycles = draw_trigs_cycles / prof_frame_counter;\ |
115 | avg_draw_btns_cycles = draw_btn_cycles / prof_frame_counter;\ | 118 | avg_draw_btns_cycles = draw_btn_cycles / prof_frame_counter;\ |
116 | avg_draw_piano_cycles = draw_piano_cycles / prof_frame_counter;\ | 119 | avg_draw_piano_cycles = draw_piano_cycles / prof_frame_counter;\ |
117 | avg_draw_param_cycles = draw_param_cycles / prof_frame_counter;\ | 120 | avg_draw_param_cycles = draw_param_cycles / prof_frame_counter;\ |
118 | avg_draw_cursor_cycles = draw_cursor_cycles / prof_frame_counter;\ | 121 | avg_draw_cursor_cycles = draw_cursor_cycles / prof_frame_counter;\ |
119 | avg_input_cycles = input_cycles / prof_frame_counter;\ | 122 | avg_input_cycles = input_cycles / prof_frame_counter;\ |
120 | avg_render_cycles = render_cycles / prof_frame_counter;\ | 123 | avg_render_cycles = render_cycles / prof_frame_counter;\ |
121 | frame_cycles = 0;\ | 124 | avg_update_cycles = update_cycles / prof_frame_counter;\ |
122 | flip_cycles = 0;\ | 125 | frame_cycles = 0;\ |
123 | clear_cycles = 0;\ | 126 | flip_cycles = 0;\ |
124 | input_cycles = 0;\ | 127 | clear_cycles = 0;\ |
128 | input_cycles = 0;\ | ||
125 | render_cycles = 0;\ | 129 | render_cycles = 0;\ |
126 | draw_trigs_cycles = 0;\ | 130 | update_cycles = 0;\ |
127 | draw_param_cycles = 0;\ | 131 | draw_trigs_cycles = 0;\ |
132 | draw_param_cycles = 0;\ | ||
128 | draw_cursor_cycles = 0;\ | 133 | draw_cursor_cycles = 0;\ |
129 | draw_btn_cycles = 0;\ | 134 | draw_btn_cycles = 0;\ |
130 | draw_piano_cycles = 0;\ | 135 | draw_piano_cycles = 0;\ |
131 | prof_frame_counter = 0;\ | 136 | prof_frame_counter = 0;\ |
132 | }\ | 137 | }\ |
133 | profile_start();\ | 138 | profile_start();\ |
134 | } while (0) | 139 | } while (0) |
diff --git a/src/renderer_m0.c b/src/renderer_m0.c index bf15f56..eb19718 100644 --- a/src/renderer_m0.c +++ b/src/renderer_m0.c | |||
@@ -615,84 +615,6 @@ draw_icn(size_t x, size_t y, u8 *sprite, u8 clr, u8 flip_x, u8 flip_y) { | |||
615 | dirty_tiles[tile_y] |= dirty; | 615 | dirty_tiles[tile_y] |= dirty; |
616 | } | 616 | } |
617 | 617 | ||
618 | IWRAM_CODE | ||
619 | void | ||
620 | draw_tile(size_t x, size_t y, Tile *tile, u8 clr) { | ||
621 | BOUNDCHECK_SCREEN(x, y); | ||
622 | size_t tile_x0 = x / 8; | ||
623 | size_t tile_x1 = (x + 7) / 8; | ||
624 | size_t tile_y = y / 8; | ||
625 | size_t start_col = x % 8; | ||
626 | size_t start_row = y % 8; | ||
627 | size_t shift_left = start_col * 4; | ||
628 | size_t shift_right = (8 - start_col) * 4; | ||
629 | u32 dirty = (1 << tile_x0) | (1 << tile_x1); | ||
630 | u32 *dst = &backbuf[start_row + (tile_x0 + tile_y * 32) * 8]; | ||
631 | // BOUNDCHECK_SCREEN(x, y); | ||
632 | |||
633 | // // Find row position for the given x/y coordinates. | ||
634 | // size_t tile_x = x / 8; | ||
635 | // size_t tile_y = y / 8; | ||
636 | // size_t start_col = x % 8; | ||
637 | // size_t start_row = y % 8; | ||
638 | |||
639 | // // Get a pointer to the backbuffer and the tile row. | ||
640 | // size_t pos = start_row + (tile_x + tile_y * 32) * 8; | ||
641 | // u32 *backbuffer = &BACKBUF[pos]; | ||
642 | u32 *row = tile; | ||
643 | u32 row_mask_left = 0xFFFFFFFF << shift_left; | ||
644 | u32 row_mask_right = 0xFFFFFFFF >> shift_right; | ||
645 | |||
646 | // Draw the tiles. There are 4 possible cases: | ||
647 | // 1. The tile is exactly at the tile boundary. | ||
648 | // 2. The tile spans 2 tiles horizontally. | ||
649 | // 3. The tile spans 2 tiles vertically. | ||
650 | // 4. The tile spans 4 tiles. | ||
651 | if (start_col == 0 && start_row == 0) { | ||
652 | for (size_t i = 0; i < (8 - start_row); i++, dst++) { | ||
653 | BOUNDCHECK_SCREEN(x, y + i); | ||
654 | dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; | ||
655 | } | ||
656 | dirty_tiles[tile_y] |= 1 << tile_x0; | ||
657 | } else if (start_row == 0) { | ||
658 | for (size_t i = 0; i < 8; i++, dst++) { | ||
659 | BOUNDCHECK_SCREEN(x, y + i); | ||
660 | dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
661 | dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
662 | } | ||
663 | dirty_tiles[tile_y] |= 1 << tile_x0; | ||
664 | dirty_tiles[tile_y] |= 1 << (tile_x0 + 1); | ||
665 | } else if (start_col == 0) { | ||
666 | for (size_t i = 0; i < (8 - start_row); i++, dst++) { | ||
667 | BOUNDCHECK_SCREEN(x, y + i); | ||
668 | dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; | ||
669 | } | ||
670 | dst += 8 * 31; | ||
671 | for (size_t i = (8 - start_row); i < 8; i++, dst++) { | ||
672 | BOUNDCHECK_SCREEN(x, y + i); | ||
673 | dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; | ||
674 | } | ||
675 | dirty_tiles[tile_y] |= 1 << tile_x0; | ||
676 | dirty_tiles[tile_y + 1] |= 1 << tile_x0; | ||
677 | } else { | ||
678 | for (size_t i = 0; i < (8 - start_row); i++, dst++) { | ||
679 | BOUNDCHECK_SCREEN(x, y + i); | ||
680 | dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
681 | dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
682 | } | ||
683 | dst += 8 * 31; | ||
684 | for (size_t i = (8 - start_row); i < 8; i++, dst++) { | ||
685 | BOUNDCHECK_SCREEN(x, y + i); | ||
686 | dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); | ||
687 | dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); | ||
688 | } | ||
689 | dirty_tiles[tile_y] |= 1 << tile_x0; | ||
690 | dirty_tiles[tile_y] |= 1 << (tile_x0 + 1); | ||
691 | dirty_tiles[tile_y + 1] |= 1 << tile_x0; | ||
692 | dirty_tiles[tile_y + 1] |= 1 << (tile_x0 + 1); | ||
693 | } | ||
694 | } | ||
695 | |||
696 | // | 618 | // |
697 | // Flipping buffers/copying memory. | 619 | // Flipping buffers/copying memory. |
698 | // | 620 | // |
diff --git a/src/sequencer.c b/src/sequencer.c index 34e2695..c793a3f 100644 --- a/src/sequencer.c +++ b/src/sequencer.c | |||
@@ -409,6 +409,7 @@ handle_param_selection_sq1(void) { | |||
409 | } | 409 | } |
410 | } | 410 | } |
411 | param_selection_loc = CLAMP(loc + inc, 0, 6); | 411 | param_selection_loc = CLAMP(loc + inc, 0, 6); |
412 | redraw_params = true; | ||
412 | } | 413 | } |
413 | if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { | 414 | if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { |
414 | int inc = 0; | 415 | int inc = 0; |
@@ -431,6 +432,7 @@ handle_param_selection_sq1(void) { | |||
431 | } | 432 | } |
432 | } | 433 | } |
433 | param_selection_loc = CLAMP(loc + inc, 0, 6); | 434 | param_selection_loc = CLAMP(loc + inc, 0, 6); |
435 | redraw_params = true; | ||
434 | } | 436 | } |
435 | 437 | ||
436 | // Adjust parameter. | 438 | // Adjust parameter. |