1 // bfe2 - instruction history file
2 // Copyright (c) 1999-2003 Brand Huntsman and Lee Salzman
3 //
4
5
6 #include "common.h"
7 #include "functions.h"
8
9
10 //////////////////////////////////////////////////////////////////////////
11
12 // global
13
14 // local
15 GtkCList *h_list;
16 FILE *h_logfile;
17 uint h_repeat, h_length;
18 uint32 h_last_address;
19
20 #define H_COLUMN_TITLES 4
21 gchar *h_column_titles[] = { "Physical", "Virtual", "Bytes", "Instruction" };
22
23 //////////////////////////////////////////////////////////////////////////
24
25
open_history()26 void open_history( ){
27 h_last_address = 0;
28 h_repeat = 0;
29 h_length = 0;
30
31 if((h_logfile = fopen(HISTORY_PATH, "w")) == NULL)
32 g_print("BFE: Unable to access history log file, logging disabled.\n");
33 }
34
35
36 //////////////////////////////////////////////////////////////////////////
37
38
historyInit(GtkWidget * vbox)39 void historyInit( GtkWidget *vbox ){
40 open_history();
41
42 h_list = new_list(vbox, H_COLUMN_TITLES, h_column_titles);
43 gtk_clist_column_titles_show(h_list);
44 gtk_clist_set_column_justification(h_list, 0, GTK_JUSTIFY_CENTER);
45 gtk_clist_set_column_justification(h_list, 1, GTK_JUSTIFY_CENTER);
46 gtk_clist_set_column_justification(h_list, 2, GTK_JUSTIFY_LEFT);
47 gtk_clist_set_column_justification(h_list, 3, GTK_JUSTIFY_LEFT);
48 }
49
50
historyReset()51 void historyReset( ){
52 h_last_address = 0;
53 h_repeat = 0;
54 }
55
56
historyClose()57 void historyClose( ){
58 historyRepeat();
59 if(h_logfile != NULL) fclose(h_logfile);
60 }
61
62
historyClear(GtkWidget * widget,gpointer data)63 void historyClear( GtkWidget *widget, gpointer data ){
64 gtk_clist_clear(h_list);
65
66 historyClose();
67 open_history();
68 }
69
70
historyUpdate()71 void historyUpdate( ){
72 char address[LEN_ADDRESS], virtual[LEN_ADDRESS], *row[H_COLUMN_TITLES];
73
74 if(h_last_address != i_physical_address){
75 h_last_address = i_physical_address;
76
77 historyRepeat();
78
79 snprintf(address, LEN_ADDRESS, "%.8X", i_physical_address);
80 snprintf(virtual, LEN_ADDRESS, "%.4X:%.8X", i_virtual_segment, i_virtual_offset);
81 row[0] = address;
82 row[1] = virtual;
83 row[2] = i_bytes;
84 row[3] = i_description;
85 gtk_clist_append(h_list, row);
86 h_length++;
87
88 if(h_logfile != NULL) fprintf(h_logfile, "%s %s [%s] %s\n",
89 address, virtual, i_bytes, i_description);
90
91 historyClip();
92
93 gtk_clist_moveto(h_list, h_length-1, 0, 1.0, 0.0);
94 gtk_clist_select_row(h_list, h_length-1, 0);
95 } else h_repeat++;
96 }
97
98
99 #define LEN_TEMP 32
historyRepeat()100 void historyRepeat( ){
101 char temp[LEN_TEMP];
102
103 if(h_repeat){
104 snprintf(temp, LEN_TEMP, "repeated %u times", h_repeat);
105 h_repeat = 0;
106 historyWrite(temp);
107 }
108 }
109
110
historyWrite(char * message)111 void historyWrite( char *message ){
112 char *row[H_COLUMN_TITLES];
113
114 if(h_repeat) historyRepeat();
115
116 row[0] = NULL;
117 row[1] = NULL;
118 row[2] = NULL;
119 row[3] = message;
120 gtk_clist_append(h_list, row);
121 h_length++;
122
123 if(h_logfile != NULL)
124 fprintf(h_logfile, ": %s\n", message);
125
126 historyClip();
127
128 // only instructions are selected
129 gtk_clist_moveto(h_list, h_length-1, 0, 1.0, 0.0);
130 }
131
132
historyClip()133 void historyClip( ){
134 while(h_maxlen < h_length){
135 gtk_clist_remove(h_list, 0);
136 h_length--;
137 }
138 }
139