From: Hugo Villeneuve Date: Tue, 22 Oct 2013 03:04:16 +0000 (-0400) Subject: Add view menu option for selecting bits per row (8/16) X-Git-Tag: v2.0.0~113 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=3edb6517f8ddd7e7d9b10a9f4cfe794cdf4981e6;p=emu8051.git Add view menu option for selecting bits per row (8/16) --- diff --git a/src/memwin.c b/src/memwin.c index 4c8cc22..446f9d4 100644 --- a/src/memwin.c +++ b/src/memwin.c @@ -33,17 +33,17 @@ #include "regwin.h" #include "memwin.h" #include "emugtk.h" +#include "app-config.h" -#define DATA_COLS 16 /* Must be a power of 2 */ -#define DATA_ROWS_INT (INT_MEM_SIZE / DATA_COLS) -#define DATA_ROWS_EXT (1024 / DATA_COLS) +extern struct app_config_t *cfg; + +static int COL_ASCII; +static int N_COLUMNS; enum { COL_ADDRESS = 0, COL_DATA0, - COL_ASCII = DATA_COLS + 1, - N_COLUMNS, }; static GtkWidget *memlist_internal; @@ -153,7 +153,7 @@ memwin_init_columns(GtkWidget *listview, int memory_id) gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); - for (i = COL_DATA0; i < (COL_DATA0 + DATA_COLS); i++) { + for (i = COL_DATA0; i < (COL_DATA0 + cfg->bits_per_row); i++) { char col_name[8]; /* Create new renderer for each editable cell. */ @@ -174,7 +174,7 @@ memwin_init_columns(GtkWidget *listview, int memory_id) GUINT_TO_POINTER(memory_id)); /* Use two digits only if DATA_ROWS > 10 */ - if (DATA_COLS < 10) + if (cfg->bits_per_row < 10) sprintf(col_name, "B%1d", i - COL_DATA0); else sprintf(col_name, "B%02d", i - COL_DATA0); @@ -195,6 +195,23 @@ memwin_init_columns(GtkWidget *listview, int memory_id) gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); } +static int +compute_data_rows(int memory_id) +{ + int data_rows; + + if (memory_id == INT_MEM_ID) { + data_rows = (INT_MEM_SIZE / cfg->bits_per_row); + } else if (memory_id == EXT_MEM_ID) { + data_rows = 1024 / cfg->bits_per_row; + } else { + log_fail("Invalid memory type"); + exit(1); + } + + return data_rows; +} + GtkWidget * memwin_init(char *title, int memory_id) { @@ -204,6 +221,9 @@ memwin_init(char *title, int memory_id) GtkWidget *memlist; int data_rows; + COL_ASCII = cfg->bits_per_row + 1; + N_COLUMNS = COL_ASCII + 1; + frame = gtk_frame_new(title); scrollwin = gtk_scrolled_window_new(NULL, NULL); @@ -217,14 +237,7 @@ memwin_init(char *title, int memory_id) gtk_container_add(GTK_CONTAINER(frame), scrollwin); - if (memory_id == INT_MEM_ID) { - data_rows = DATA_ROWS_INT; - } else if (memory_id == EXT_MEM_ID) { - data_rows = DATA_ROWS_EXT; - } else { - log_fail("Invalid memory type"); - exit(1); - } + data_rows = compute_data_rows(memory_id); /* Creating a model */ store = memwin_init_store(data_rows); @@ -267,12 +280,12 @@ memwin_refresh(int memory_id) Address = 0; + data_rows = compute_data_rows(memory_id); + if (memory_id == INT_MEM_ID) { memlist = memlist_internal; - data_rows = DATA_ROWS_INT; } else if (memory_id == EXT_MEM_ID) { memlist = memlist_external; - data_rows = DATA_ROWS_EXT; } else { log_fail("Invalid memory type"); exit(1); @@ -284,7 +297,7 @@ memwin_refresh(int memory_id) int valid; GtkTreeIter iter; char str[4+1]; /* Maximum str len is for address column (4 digits) */ - char ascii_str[DATA_COLS+1]; + char ascii_str[16+1]; /* Maximum 16 data columns. */ int col; if (row == 0) { @@ -307,7 +320,7 @@ memwin_refresh(int memory_id) gtk_list_store_set(store, &iter, COL_ADDRESS, str, -1); - for (col = 0; col < DATA_COLS; col++) { + for (col = 0; col < cfg->bits_per_row; col++) { u_int8_t data; data = memory_read8(memory_id, Address + col); @@ -326,6 +339,6 @@ memwin_refresh(int memory_id) /* Display ASCII characters. */ gtk_list_store_set(store, &iter, COL_ASCII, ascii_str, -1); - Address += DATA_COLS; + Address += cfg->bits_per_row; } } diff --git a/src/viewmenu.c b/src/viewmenu.c index cf27685..37d5b9a 100644 --- a/src/viewmenu.c +++ b/src/viewmenu.c @@ -46,6 +46,19 @@ void toggle_layout(GtkWidget *widget, gpointer data) } } +void toggle_bits_per_row(GtkWidget *widget, gpointer data) +{ + int bits_per_row; + + bits_per_row = GPOINTER_TO_UINT(data); + + if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { + log_info(" Bits per row = %d", bits_per_row); + cfg->bits_per_row = bits_per_row; + emugtk_restart_gui(); + } +} + void toggle_int_memory(GtkWidget *widget, gpointer data) { if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { @@ -54,6 +67,8 @@ void toggle_int_memory(GtkWidget *widget, gpointer data) } else { cfg->view_int_memory = 0; } + + emugtk_restart_gui(); } void toggle_ext_memory(GtkWidget *widget, gpointer data) @@ -64,6 +79,8 @@ void toggle_ext_memory(GtkWidget *widget, gpointer data) } else { cfg->view_ext_memory = 0; } + + emugtk_restart_gui(); } void @@ -99,6 +116,39 @@ view_add_layout_submenu(GtkWidget *parent) gtk_menu_shell_append(GTK_MENU_SHELL(parent), layout); } +void +view_add_bits_per_row_submenu(GtkWidget *parent) +{ + GtkWidget *submenu; + GtkWidget *item; + GtkWidget *item1; + GtkWidget *item2; + GSList *group = NULL; + + submenu = gtk_menu_new(); + + item = gtk_menu_item_new_with_label("Bits per row"); + + item1 = gtk_radio_menu_item_new_with_label(group, "8"); + group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item1)); + item2 = gtk_radio_menu_item_new_with_label(group, "16"); + + if (cfg->bits_per_row == 8) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item1), TRUE); + else + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item2), TRUE); + + g_signal_connect(G_OBJECT(item1), "activate", + G_CALLBACK(toggle_bits_per_row), (gpointer) 8); + g_signal_connect(G_OBJECT(item2), "activate", + G_CALLBACK(toggle_bits_per_row), (gpointer) 16); + + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); + gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item1); + gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item2); + gtk_menu_shell_append(GTK_MENU_SHELL(parent), item); +} + void ViewAddMenu(GtkWidget *menu_bar) { @@ -127,6 +177,11 @@ ViewAddMenu(GtkWidget *menu_bar) /* Add layout submenu */ view_add_layout_submenu(menu); + AddMenuSeparator(menu); + + /* Add bits per row submenu */ + view_add_bits_per_row_submenu(menu); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), menu); gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), view); }