#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;
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. */
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);
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)
{
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);
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);
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);
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) {
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);
/* Display ASCII characters. */
gtk_list_store_set(store, &iter, COL_ASCII, ascii_str, -1);
- Address += DATA_COLS;
+ Address += cfg->bits_per_row;
}
}
}
}
+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))) {
} else {
cfg->view_int_memory = 0;
}
+
+ emugtk_restart_gui();
}
void toggle_ext_memory(GtkWidget *widget, gpointer data)
} else {
cfg->view_ext_memory = 0;
}
+
+ emugtk_restart_gui();
}
void
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)
{
/* 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);
}