From 4959741a7eaac3b429912a1ccfd7ebe06d41ef0d Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 23 Apr 2023 20:45:37 +0200 Subject: Add back cursor drawing --- src/assets.c | 2 +- src/drawing.c | 40 ++++++++++++++++++++++---- src/globals.c | 10 +++++-- src/main.c | 17 ++++++----- src/profiling.c | 85 +++++++++++++++++++++++++++++-------------------------- src/renderer_m0.c | 78 -------------------------------------------------- src/sequencer.c | 2 ++ 7 files changed, 100 insertions(+), 134 deletions(-) (limited to 'src') 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[] = { 0xe0000000, 0xe0202020, 0x0e000000, 0x0e0a0e0a, }; -u32 ch_btn_sprite[] = { +static const u32 ch_btn_sprite[] = { // CH1 0x888e80ff, 0xff808e88, 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) { size_t offset_y = i < 8 ? 0 : TRIG_OFFSET_Y; size_t x = TRIG_START_X + offset_x; size_t y = TRIG_START_Y + offset_y; - u32 *tile = ¬e_name_sprites[4 * trig.note]; + const u32 *tile = ¬e_name_sprites[4 * trig.note]; draw_icn(x, y, &tile[0], COL_FG, 1, 0); draw_icn(x + 8, y, &tile[2], COL_FG, 1, 0); } else { @@ -99,11 +99,11 @@ draw_trig_cursor(size_t i, u8 clr) { } void -draw_right_col_cursor(u8 clr) { +draw_right_col_cursor(int i, u8 clr) { size_t x0 = 0; size_t x1 = 0; size_t y = 0; - switch (right_col_selection_loc) { + switch (i) { case R_COL_BPM: { x0 = BPM_START_X; x1 = x0 + R_COL_W; @@ -593,7 +593,7 @@ draw_parameters_wave(void) { // Draw default wave buttons. { - u32 *tile = default_wave_buttons; + const u32 *tile = default_wave_buttons; size_t x = PARAMS_START_X; size_t y = PARAMS_START_Y + PARAMS_H - 12; for (size_t i = 0, k = 0; i < 4 * 2; i += 2, k++) { @@ -1246,6 +1246,36 @@ draw_parameters(void) { } void -draw_cursors(void) { +clear_cursors(void) { + draw_trig_cursor(last_trig_loc, COL_BG); + draw_channel_cursor(last_channel_loc, COL_BG); + draw_pattern_cursor(last_pattern_loc, COL_BG); + draw_right_col_cursor(last_right_col_loc, COL_BG); +} +void +draw_cursors(void) { + clear_cursors(); + if (input_handler == handle_trigger_selection) { + draw_trig_cursor(trig_selection_loc, COL_CURSOR); + } + if (input_handler == handle_channel_selection) { + draw_channel_cursor(channel_selection_loc, COL_CURSOR); + } else { + draw_channel_cursor(channel_selection_loc, COL_GREY); + } + if (input_handler == handle_pattern_selection) { + draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); + } else { + draw_pattern_cursor(pattern_selection_loc, COL_GREY); + } + if (input_handler == handle_right_col_selection) { + draw_right_col_cursor(right_col_selection_loc, COL_CURSOR); + } + if (input_handler == handle_param_selection_sq1 || + input_handler == handle_param_selection_sq2 || + input_handler == handle_param_selection_wave || + input_handler == handle_param_selection_noise) { + draw_params_cursor(param_selection_loc, COL_CURSOR); + } } 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; int pattern_selection_loc = 0; int right_col_selection_loc = 0; int play_status = 0; -static int current_pattern = 0; -static int next_pattern = 0; -static int current_bank = 0; +int current_pattern = 0; +int next_pattern = 0; +int current_bank = 0; +u32 last_trig_loc = 0; +u32 last_channel_loc = 0; +u32 last_pattern_loc = 0; +u32 last_right_col_loc = 0; // // Color indexes. diff --git a/src/main.c b/src/main.c index aa5bd43..525a0d9 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,6 @@ WITH REGARD TO THIS SOFTWARE. #define PROF_ENABLE 1 #include "profiling.c" - void render(void) { PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); @@ -67,12 +66,16 @@ render(void) { redraw_params = false; } - // TODO: Make sure we are drawing the cursors properly. - // PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); - // PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); - // PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); - // PROF(draw_current_step(COL_RED), draw_cursor_cycles); + PROF(draw_cursors(), draw_cursor_cycles); +} + +void +update(void) { + last_trig_loc = trig_selection_loc; + last_channel_loc = channel_selection_loc; + last_pattern_loc = pattern_selection_loc; + last_right_col_loc = right_col_selection_loc; } int @@ -101,8 +104,8 @@ main(void) { PROF_SHOW(); FRAME_START(); PROF(flip_buffer(), flip_cycles); + PROF(update(), update_cycles); PROF(handle_sequencer_input(), input_cycles); - // TODO: Update function to performa animations, etc. PROF(render(), render_cycles); FRAME_END(); } 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; txt_printf(">PARAM %.8lu\n", avg_draw_param_cycles);\ txt_printf(">PIANO %.8lu\n", avg_draw_piano_cycles);\ txt_printf(">CURSOR %.8lu\n", avg_draw_cursor_cycles);\ - txt_printf("RENDER %.8lu\n", avg_render_cycles);\ + txt_printf("UPDATE %.8lu\n", avg_update_cycles);\ txt_printf("INPUT %.8lu\n", avg_input_cycles);\ + txt_printf("RENDER %.8lu\n", avg_render_cycles);\ txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\ txt_render();\ }\ @@ -82,53 +83,57 @@ static bool profile_show = true; static u32 prof_frame_counter = 0; -static u32 frame_cycles = 0; -static u32 flip_cycles = 0; -static u32 clear_cycles = 0; -static u32 input_cycles = 0; -static u32 draw_trigs_cycles = 0; -static u32 draw_btn_cycles = 0; -static u32 draw_piano_cycles = 0; -static u32 draw_param_cycles = 0; -static u32 draw_cursor_cycles = 0; -static u32 render_cycles = 0; +static u32 frame_cycles = 0; +static u32 flip_cycles = 0; +static u32 clear_cycles = 0; +static u32 input_cycles = 0; +static u32 draw_trigs_cycles = 0; +static u32 draw_btn_cycles = 0; +static u32 draw_piano_cycles = 0; +static u32 draw_param_cycles = 0; +static u32 draw_cursor_cycles = 0; +static u32 render_cycles = 0; +static u32 update_cycles = 0; -static u32 avg_frame_cycles = 0; -static u32 avg_flip_cycles = 0; -static u32 avg_clear_cycles = 0; -static u32 avg_input_cycles = 0; -static u32 avg_draw_trigs_cycles = 0; -static u32 avg_draw_btns_cycles = 0; -static u32 avg_draw_piano_cycles = 0; -static u32 avg_draw_param_cycles = 0; -static u32 avg_draw_cursor_cycles = 0; -static u32 avg_render_cycles = 0; +static u32 avg_frame_cycles = 0; +static u32 avg_flip_cycles = 0; +static u32 avg_clear_cycles = 0; +static u32 avg_input_cycles = 0; +static u32 avg_draw_trigs_cycles = 0; +static u32 avg_draw_btns_cycles = 0; +static u32 avg_draw_piano_cycles = 0; +static u32 avg_draw_param_cycles = 0; +static u32 avg_draw_cursor_cycles = 0; +static u32 avg_render_cycles = 0; +static u32 avg_update_cycles = 0; #if PROF_ENABLE == 1 #define FRAME_START()\ do { \ if (prof_frame_counter == PROF_N_FRAMES) {\ - avg_frame_cycles = frame_cycles / prof_frame_counter;\ - avg_flip_cycles = flip_cycles / prof_frame_counter;\ - avg_clear_cycles = clear_cycles / prof_frame_counter;\ - avg_draw_trigs_cycles = draw_trigs_cycles / prof_frame_counter;\ - avg_draw_btns_cycles = draw_btn_cycles / prof_frame_counter;\ - avg_draw_piano_cycles = draw_piano_cycles / prof_frame_counter;\ - avg_draw_param_cycles = draw_param_cycles / prof_frame_counter;\ - avg_draw_cursor_cycles = draw_cursor_cycles / prof_frame_counter;\ - avg_input_cycles = input_cycles / prof_frame_counter;\ - avg_render_cycles = render_cycles / prof_frame_counter;\ - frame_cycles = 0;\ - flip_cycles = 0;\ - clear_cycles = 0;\ - input_cycles = 0;\ + avg_frame_cycles = frame_cycles / prof_frame_counter;\ + avg_flip_cycles = flip_cycles / prof_frame_counter;\ + avg_clear_cycles = clear_cycles / prof_frame_counter;\ + avg_draw_trigs_cycles = draw_trigs_cycles / prof_frame_counter;\ + avg_draw_btns_cycles = draw_btn_cycles / prof_frame_counter;\ + avg_draw_piano_cycles = draw_piano_cycles / prof_frame_counter;\ + avg_draw_param_cycles = draw_param_cycles / prof_frame_counter;\ + avg_draw_cursor_cycles = draw_cursor_cycles / prof_frame_counter;\ + avg_input_cycles = input_cycles / prof_frame_counter;\ + avg_render_cycles = render_cycles / prof_frame_counter;\ + avg_update_cycles = update_cycles / prof_frame_counter;\ + frame_cycles = 0;\ + flip_cycles = 0;\ + clear_cycles = 0;\ + input_cycles = 0;\ render_cycles = 0;\ - draw_trigs_cycles = 0;\ - draw_param_cycles = 0;\ + update_cycles = 0;\ + draw_trigs_cycles = 0;\ + draw_param_cycles = 0;\ draw_cursor_cycles = 0;\ - draw_btn_cycles = 0;\ - draw_piano_cycles = 0;\ - prof_frame_counter = 0;\ + draw_btn_cycles = 0;\ + draw_piano_cycles = 0;\ + prof_frame_counter = 0;\ }\ profile_start();\ } 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) { dirty_tiles[tile_y] |= dirty; } -IWRAM_CODE -void -draw_tile(size_t x, size_t y, Tile *tile, u8 clr) { - BOUNDCHECK_SCREEN(x, y); - size_t tile_x0 = x / 8; - size_t tile_x1 = (x + 7) / 8; - size_t tile_y = y / 8; - size_t start_col = x % 8; - size_t start_row = y % 8; - size_t shift_left = start_col * 4; - size_t shift_right = (8 - start_col) * 4; - u32 dirty = (1 << tile_x0) | (1 << tile_x1); - u32 *dst = &backbuf[start_row + (tile_x0 + tile_y * 32) * 8]; - // BOUNDCHECK_SCREEN(x, y); - - // // Find row position for the given x/y coordinates. - // size_t tile_x = x / 8; - // size_t tile_y = y / 8; - // size_t start_col = x % 8; - // size_t start_row = y % 8; - - // // Get a pointer to the backbuffer and the tile row. - // size_t pos = start_row + (tile_x + tile_y * 32) * 8; - // u32 *backbuffer = &BACKBUF[pos]; - u32 *row = tile; - u32 row_mask_left = 0xFFFFFFFF << shift_left; - u32 row_mask_right = 0xFFFFFFFF >> shift_right; - - // Draw the tiles. There are 4 possible cases: - // 1. The tile is exactly at the tile boundary. - // 2. The tile spans 2 tiles horizontally. - // 3. The tile spans 2 tiles vertically. - // 4. The tile spans 4 tiles. - if (start_col == 0 && start_row == 0) { - for (size_t i = 0; i < (8 - start_row); i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; - } - dirty_tiles[tile_y] |= 1 << tile_x0; - } else if (start_row == 0) { - for (size_t i = 0; i < 8; i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); - dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); - } - dirty_tiles[tile_y] |= 1 << tile_x0; - dirty_tiles[tile_y] |= 1 << (tile_x0 + 1); - } else if (start_col == 0) { - for (size_t i = 0; i < (8 - start_row); i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; - } - dst += 8 * 31; - for (size_t i = (8 - start_row); i < 8; i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | row[i] * clr; - } - dirty_tiles[tile_y] |= 1 << tile_x0; - dirty_tiles[tile_y + 1] |= 1 << tile_x0; - } else { - for (size_t i = 0; i < (8 - start_row); i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); - dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); - } - dst += 8 * 31; - for (size_t i = (8 - start_row); i < 8; i++, dst++) { - BOUNDCHECK_SCREEN(x, y + i); - dst[0] = (dst[0] & ~row_mask_left) | (row[i] * clr << shift_left); - dst[8] = (dst[8] & ~row_mask_right) | (row[i] * clr >> shift_right); - } - dirty_tiles[tile_y] |= 1 << tile_x0; - dirty_tiles[tile_y] |= 1 << (tile_x0 + 1); - dirty_tiles[tile_y + 1] |= 1 << tile_x0; - dirty_tiles[tile_y + 1] |= 1 << (tile_x0 + 1); - } -} - // // Flipping buffers/copying memory. // 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) { } } param_selection_loc = CLAMP(loc + inc, 0, 6); + redraw_params = true; } if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { int inc = 0; @@ -431,6 +432,7 @@ handle_param_selection_sq1(void) { } } param_selection_loc = CLAMP(loc + inc, 0, 6); + redraw_params = true; } // Adjust parameter. -- cgit v1.2.1