1 /*
2    Copyright (C) 1998,1999,2000,2001
3    T. Scott Dattalo and Ralf Forsberg
4 
5 This file is part of gpsim.
6 
7 gpsim is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11 
12 gpsim is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with gpsim; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21 
22 #include <typeinfo>
23 
24 #include "../config.h"
25 #ifdef HAVE_GUI
26 
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <glib.h>
30 
31 #include "gui_src.h"
32 #include "gui_processor.h"
33 
34 #include "../src/gpsim_interface.h"
35 #include "../src/pic-instructions.h"
36 #include "../src/processor.h"
37 #include "../src/value.h"
38 
39 static gint
key_press(GtkWidget *,GdkEventKey * key,gpointer data)40 key_press(GtkWidget *, GdkEventKey *key, gpointer data)
41 {
42   SourceBrowser_Window *sbw = static_cast<SourceBrowser_Window *>(data);
43 
44   if (!sbw) return FALSE;
45   if (!sbw->pma) return FALSE;
46   if (!sbw->gp) return FALSE;
47   if (!sbw->gp->cpu) return FALSE;
48 
49   switch (key->keyval) {
50   case 's':
51   case 'S':
52   case GDK_KEY_F7:
53     sbw->pma->step(1);
54     break;
55   case 'o':
56   case 'O':
57   case 'n':
58   case GDK_KEY_F8:
59     sbw->pma->step_over();
60     break;
61   case 'r':
62   case 'R':
63   case GDK_KEY_F9:
64     get_interface().start_simulation();
65     break;
66   case GDK_KEY_Escape:
67     sbw->pma->stop();
68     break;
69   case 'f':
70   case 'F':
71     sbw->pma->finish();
72     break;
73   default:
74     return FALSE;
75   }
76 
77   return TRUE;
78 }
79 
SourceBrowser_Window(const char * name)80 SourceBrowser_Window::SourceBrowser_Window(const char *name)
81   : GUI_Object(name)
82 {
83   gtk_container_set_border_width(GTK_CONTAINER(window), 0);
84 
85   vbox = gtk_vbox_new(FALSE, 0);
86   gtk_widget_show(vbox);
87   gtk_container_add(GTK_CONTAINER(window), vbox);
88 
89   /* Add a signal handler for key press events. This will capture
90    * key commands for single stepping, running, etc.
91    */
92   g_signal_connect(window, "key_press_event",
93                      G_CALLBACK(key_press),
94                      (gpointer) this);
95 }
96 
Update()97 void SourceBrowser_Window::Update()
98 {
99   if(!gp || !gp->cpu)
100     return;
101 
102   SetPC(gp->cpu->pma->get_PC());
103 }
104 
Create()105 void SourceBrowser_Window::Create()
106 {
107   last_simulation_mode = eSM_INITIAL;
108 }
109 
SetTitle()110 void SourceBrowser_Window::SetTitle() {
111 
112   if (!gp->cpu || !pma) {
113       return;
114   }
115 
116   if (last_simulation_mode != eSM_INITIAL &&
117     ((last_simulation_mode == eSM_RUNNING &&
118     gp->cpu->simulation_mode == eSM_RUNNING) ||
119     (last_simulation_mode != eSM_RUNNING &&
120     gp->cpu->simulation_mode != eSM_RUNNING)) &&
121     sLastPmaName == pma->name()) {
122       return;
123   }
124 
125   last_simulation_mode = gp->cpu->simulation_mode;
126   const char * sStatus;
127   if (gp->cpu->simulation_mode == eSM_RUNNING)
128     sStatus = "Run";
129   else // if (gp->cpu->simulation_mode == eSM_STOPPED)
130     sStatus = "Stopped";
131 
132   char *buffer = g_strdup_printf("Source Browser: [%s] %s", sStatus, pma->name().c_str());
133   sLastPmaName = pma->name();
134   gtk_window_set_title (GTK_WINDOW (window), buffer);
135   g_free(buffer);
136 }
137 
SelectAddress(Value * addrSym)138 void SourceBrowser_Window::SelectAddress(Value *addrSym)
139 {
140 
141   if(typeid(*addrSym) == typeid(LineNumberSymbol) ||
142      typeid(*addrSym) == typeid(AddressSymbol)) {
143 
144     int i;
145     addrSym->get(i);
146     SelectAddress(i);
147   }
148 
149 }
150 
151 #endif // HAVE_GUI
152