From 83fa10f4590287e35566c00050a05df022eadc46 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Fri, 4 Oct 2019 01:40:50 +0200 Subject: [PATCH] [GTK3] Implement sprite viewer --- gtk3/main.c | 49 +++++++++++++++++++++++++++++++++++++ gtk3/resources/ui/window.ui | 9 ++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/gtk3/main.c b/gtk3/main.c index b5ce8b3..add97d3 100644 --- a/gtk3/main.c +++ b/gtk3/main.c @@ -37,6 +37,10 @@ static uint32_t tileset_buffer[tileset_buffer_length] = {0}; #define tilemap_buffer_length 256 * 256 * 4 static uint32_t tilemap_buffer[tilemap_buffer_length] = {0}; +static GB_oam_info_t oamInfo[40]; +static uint16_t oamCount; +static uint8_t oamHeight; + static uint8_t pressed_buttons; // List of GActions for the `app` prefix @@ -1064,7 +1068,52 @@ static void vblank(GB_gameboy_t *gb) { }; } else if (g_strcmp0("vram_viewer_sprites", active) == 0) { + GtkListStore *store = builder_get(GTK_LIST_STORE, "sprite_list_store"); + GtkTreeIter iter; + gtk_list_store_clear(store); + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); + + oamCount = GB_get_oam_info(gb, oamInfo, &oamHeight); + + for (unsigned row = 0; row < oamCount; ++row) { + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_bytes( + g_bytes_new(oamInfo[row].image, 128 * sizeof(uint32_t)), + GDK_COLORSPACE_RGB, true, 8, 8, oamHeight, 8 * sizeof(uint32_t) + ); + + GdkPixbuf *dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, 8 * 2, oamHeight * 2); + + gdk_pixbuf_scale(pixbuf, dest, + 0, 0, 8 * 2, oamHeight * 2, + 0, 0, 2.0, 2.0, + GDK_INTERP_NEAREST + ); + + g_object_unref(pixbuf); + + gtk_list_store_insert_with_values(store, &iter, -1, + 0, dest, + 1, itoa(oamInfo[row].x - 8), + 2, itoa(oamInfo[row].y - 16), + 3, g_strdup_printf("$%02x", oamInfo[row].tile), + 4, g_strdup_printf("$%04x", 0x8000 + oamInfo[row].tile * 0x10), + 5, g_strdup_printf("$%04x", oamInfo[row].oam_addr), + 6, GB_is_cgb(gb) + ? g_strdup_printf("%c%c%c%d%d", + oamInfo[row].flags & 0x80? 'P' : '-', + oamInfo[row].flags & 0x40? 'Y' : '-', + oamInfo[row].flags & 0x20? 'X' : '-', + oamInfo[row].flags & 0x08? 1 : 0, + oamInfo[row].flags & 0x07) + : g_strdup_printf("%c%c%c%d", + oamInfo[row].flags & 0x80? 'P' : '-', + oamInfo[row].flags & 0x40? 'Y' : '-', + oamInfo[row].flags & 0x20? 'X' : '-', + oamInfo[row].flags & 0x10? 1 : 0), + -1 + ); + } } else if (g_strcmp0("vram_viewer_palettes", active) == 0) { diff --git a/gtk3/resources/ui/window.ui b/gtk3/resources/ui/window.ui index 35045f8..816a3f4 100644 --- a/gtk3/resources/ui/window.ui +++ b/gtk3/resources/ui/window.ui @@ -1441,7 +1441,10 @@ Maximilian Mader https://github.com/max-m 32 - + + + 0 + @@ -1495,7 +1498,7 @@ Maximilian Mader https://github.com/max-m - 4 + 5 @@ -1506,7 +1509,7 @@ Maximilian Mader https://github.com/max-m - 5 + 6