/* Nick Peaden Mike Stenburg Freshman Engineering Design Day Project 2005 Computer Architecture - Simulator/Emulator Simulates hardware of an E101SCS chip with a graphicsl interface. */ #include "gtk/gtk.h" #include "gui.h" #include int main(int argc, char *argv[]) { /*Define Main as MainWindow and Input as InputDialog*/ MainWindow Main; InputDialog Input; char mem[4096]; int reg[16]; /* Initialize GTK */ gtk_init(&argc, &argv); init_main_window(&Main); /*g_print("%c\n", argv[1][3]);*/ /*if (argv[1][3] == '1') put_char_to_out(&Main, "ABCA");*/ load_file(&mem, argv[1]); /*g_print("%h", mem[0]);*/ /* Begin application code */ gtk_main(); /* Exit with no error return status with a pause */ /*system("pause");*/ return 0; } /*HEADER gui.h*/ /* E101SCS GUI Definition Source File */ #include "gtk/gtk.h" #include /*Structures for MainWindow and DialogWindow*/ typedef struct MAINWINDOW { GtkWidget *window; GtkWidget *hbox; GtkWidget *label; GtkWidget *output; } MainWindow; typedef struct INPUTDIALOG { GtkWidget *dialog; GtkWidget *hbox; GtkWidget *label; GtkWidget *input; GtkWidget *enter; } InputDialog; /*Function for delete_event, exits program*/ gboolean quit_program(GtkWidget *widget) { gtk_main_quit(); /*Program will STOP execution*/ return FALSE; } /*Function for InputDialog, destroys it*/ void destroy_dialog(GtkWidget *widget) { /*gtk_widget_destroy(GTK_WIDGET(widget));*/ gtk_widget_hide_all(GTK_WIDGET(widget)); } char get_input_text(GtkWidget *entry) { /*char *c; *c = (char)* gtk_entry_get_text(GTK_ENTRY(entry)); g_print("%c\n", *c);*/ } void init_main_window(MainWindow *main) { /*Create window widget*/ main->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(GTK_OBJECT(main->window), "delete_event", G_CALLBACK(quit_program), NULL); /* Set title */ gtk_window_set_title(GTK_WINDOW(main->window), "E101SCS Sim"); /* Border */ gtk_container_set_border_width(GTK_CONTAINER(main->window), 10); /* hbox creation */ main->hbox = gtk_hbox_new(FALSE, 0); /* Add box to window */ gtk_container_add(GTK_CONTAINER(main->window), main->hbox); /*Create "Output: " label and pack it*/ main->label = gtk_label_new("Output: "); gtk_box_pack_start(GTK_BOX(main->hbox), main->label, FALSE, FALSE, 0); /*Create EntryBox to output to and make non-user-editable*/ main->output = gtk_entry_new(); gtk_entry_set_width_chars(GTK_ENTRY(main->output), 20); gtk_editable_set_editable(GTK_EDITABLE(main->output), FALSE); gtk_box_pack_end(GTK_BOX(main->hbox), main->output, FALSE, FALSE, 0); /*Display Widgets*/ gtk_widget_show_all(main->window); } void init_input_dialog(InputDialog *input) { /*Create the dialog window, set it modal*/ input->dialog = gtk_dialog_new(); gtk_window_set_modal(GTK_WINDOW(input->dialog), TRUE); gtk_window_set_title(GTK_WINDOW(input->dialog), "StdIn"); gtk_dialog_set_has_separator(GTK_DIALOG(input->dialog), FALSE); /*Create packing box*/ input->hbox = gtk_hbox_new(FALSE, 5); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(input->dialog)->vbox), input->hbox); /*Make and insert a label into the dialog*/ input->label = gtk_label_new("Input a Character:"); gtk_box_pack_start(GTK_BOX(input->hbox), input->label, FALSE, FALSE, 0); /*Make and insert input box*/ input->input = gtk_entry_new_with_max_length(1); gtk_entry_set_width_chars(GTK_ENTRY(input->input), 5); gtk_box_pack_end(GTK_BOX(input->hbox), input->input, FALSE, FALSE, 0); /*Create enter button and assign the callback*/ input->enter = gtk_button_new_with_label("Input"); gtk_button_box_set_layout(GTK_BUTTON_BOX(GTK_DIALOG(input->dialog)->action_area), GTK_BUTTONBOX_SPREAD); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(input->dialog)->action_area), input->enter, FALSE, FALSE, 0); /*g_signal_connect_swapped(GTK_OBJECT(input->enter), "clicked", G_CALLBACK(get_input_text), input->input);*/ g_signal_connect_swapped(GTK_OBJECT(input->enter), "clicked", G_CALLBACK(destroy_dialog), input->dialog); /*Show Dialog*/ gtk_widget_show_all(input->dialog); gtk_dialog_run(GTK_DIALOG(input->dialog)); } int get_char_from_in(InputDialog *input) { int c; init_input_dialog(input); c = (int)* gtk_entry_get_text(GTK_ENTRY(input->input)); return c; } void put_char_to_out(MainWindow *main, char *data) { gtk_entry_append_text(GTK_ENTRY(main->output), data); } void load_file(char *mem[], char *file){ FILE *stream; int i=0; char c; stream = fopen(file, "r"); while (c != EOF) { c = fgetc(stream); if (c >= 48 && c <= 57) { *mem[i] = c - 48; } else if (c >= 65 && c <= 70) { *mem[i] = c - 55; } *mem[i] << 4; c = fgetc(stream); if (c >= 48 && c <= 57) { *mem[i] += c - 48; } else if (c >= 65 && c <= 70) { *mem[i] += c - 55; } g_print("%h ", mem[i]); i++; } }