From d75a261663521280e03c6955f373c25dff18b527 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Thu, 3 Oct 2019 23:26:40 +0200 Subject: [PATCH] [GTK3] Handle VRAM viewer tilemap and -set options --- gtk3/main.c | 61 ++++++++++++++++++++++++++++++++----- gtk3/resources/ui/window.ui | 7 ++--- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index 17105df..b5ce8b3 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -1015,15 +1015,60 @@ static void vblank(GB_gameboy_t *gb) { } if (vram_viewer_visible) { - // TODO: Only update what is needed - GB_draw_tileset(gb, tileset_buffer, GB_PALETTE_NONE, 0); - GB_draw_tilemap(gb, tilemap_buffer, GB_PALETTE_AUTO, 0, GB_MAP_AUTO, GB_TILESET_AUTO); + const gchar *active = gtk_stack_get_visible_child_name(builder_get(GTK_STACK, "vram_viewer_stack")); - scrollRect = (Rect){ - GB_read_memory(gb, 0xFF00 | GB_IO_SCX), - GB_read_memory(gb, 0xFF00 | GB_IO_SCY), - 160, 144 - }; + if (g_strcmp0("vram_viewer_tileset", active) == 0) { + const gchar *palette_id = gtk_combo_box_get_active_id(builder_get(GTK_COMBO_BOX, "vram_viewer_tileset_palette_selector")); + + GB_palette_type_t palette_type = g_str_has_prefix(palette_id, "bg")? GB_PALETTE_BACKGROUND : GB_PALETTE_OAM; + uint8_t palette_index = g_ascii_digit_value(palette_id[palette_type == GB_PALETTE_OAM ? 3 : 2]); + + GB_draw_tileset(gb, tileset_buffer, + palette_type, + palette_index + ); + } + else if (g_strcmp0("vram_viewer_tilemap", active) == 0) { + const gchar *palette_id = gtk_combo_box_get_active_id(builder_get(GTK_COMBO_BOX, "vram_viewer_tilemap_palette_selector")); + uint8_t palette_index = 0; + GB_palette_type_t palette_type = GB_PALETTE_AUTO; + + if (g_strcmp0("auto", palette_id) != 0) { + palette_type = g_str_has_prefix(palette_id, "bg")? GB_PALETTE_BACKGROUND : GB_PALETTE_OAM; + palette_index = g_ascii_digit_value(palette_id[palette_type == GB_PALETTE_OAM ? 3 : 2]); + } + + GB_map_type_t map_type = GB_MAP_AUTO; + const gchar *map_type_id = gtk_combo_box_get_active_id(builder_get(GTK_COMBO_BOX, "vram_viewer_tilemap_tilemap_selector")); + if (g_strcmp0("auto", map_type_id) != 0) { + map_type = (g_strcmp0("9800", map_type_id) == 0)? GB_MAP_9800 : GB_MAP_9C00; + } + + GB_tileset_type_t tileset_type = GB_TILESET_AUTO; + const gchar *tileset_type_id = gtk_combo_box_get_active_id(builder_get(GTK_COMBO_BOX, "vram_viewer_tilemap_tileset_selector")); + if (g_strcmp0("auto", tileset_type_id) != 0) { + tileset_type = (g_strcmp0("8800", tileset_type_id) == 0)? GB_TILESET_8800 : GB_TILESET_8000; + } + + GB_draw_tilemap(gb, tilemap_buffer, + palette_type, + palette_index, + map_type, + tileset_type + ); + + scrollRect = (Rect){ + GB_read_memory(gb, 0xFF00 | GB_IO_SCX), + GB_read_memory(gb, 0xFF00 | GB_IO_SCY), + 160, 144 + }; + } + else if (g_strcmp0("vram_viewer_sprites", active) == 0) { + + } + else if (g_strcmp0("vram_viewer_palettes", active) == 0) { + + } // Queue a redraw of the VRAM viewer gtk_widget_queue_draw(GTK_WIDGET(vram_viewer)); diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index f207480..35045f8 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -1203,7 +1203,6 @@ Maximilian Mader https://github.com/max-m True False 0 - fgngfn bg0 Background Palette 0 @@ -1289,7 +1288,7 @@ Maximilian Mader https://github.com/max-m 6 3 - + True False 0 @@ -1323,7 +1322,7 @@ Maximilian Mader https://github.com/max-m - + True False 0 @@ -1373,7 +1372,7 @@ Maximilian Mader https://github.com/max-m - + True False 0