1 /* ----------------------------------------------------------------------
3 * PACKAGE: as31 - 8031/8051 Assembler.
6 * The file contains main(). It handles the arguments and makes
7 * sure that pass 1 is done before pass 2 etc...
10 * Jan. 19, 1990 - Created. (Ken Stauffer)
13 * All code in this file written by Ken Stauffer (University of Calgary).
14 * January, 1990. "Written by: Ken Stauffer"
16 * April, 2000, Paul Stoffregen: see Makefile for details
29 void do_assemble(GtkWidget *widget, gpointer *data);
30 gint delete_handler(GtkWidget *widget, gpointer *data);
33 /* make all the GTK widgets global, instead of passing lots */
34 /* of pointers into the callbacks, through the parser, etc */
36 GtkWidget *file_label, *file_entry, *otype_combo;
37 GtkWidget *list_check, *go_button;
38 GtkWidget *otype_label, *output_text;
39 GtkWidget *main_window, *main_vbox;
40 GtkWidget *top_hbox, *middle_hbox, *bottom_hbox;
43 int main(int argc, char **argv)
49 gtk_init(&argc, &argv);
51 /* create all the gtk widgets... it's a pain to type in all */
52 /* this stuff, maybe someday I'll have to learn about glade */
54 file_label = gtk_label_new("ASM File: ");
55 gtk_label_set_justify(GTK_LABEL(file_label), GTK_JUSTIFY_RIGHT);
56 gtk_widget_show(file_label);
58 otype_label = gtk_label_new("Output Format");
59 gtk_label_set_justify(GTK_LABEL(otype_label), GTK_JUSTIFY_RIGHT);
60 gtk_widget_show(otype_label);
62 file_entry = gtk_entry_new();
63 /* fill in a default filename, from a previous session ??? */
64 gtk_widget_show(file_entry);
66 list_check = gtk_check_button_new_with_label("Create List File");
67 /* check or unchecked based on previous usage */
68 gtk_widget_show(list_check);
70 otype_combo = gtk_combo_new();
73 while ((desc = emit_desc_lookup(n++)) != NULL) {
74 otypelist = g_list_append(otypelist, strdup(desc));
76 gtk_combo_set_popdown_strings(GTK_COMBO(otype_combo), otypelist);
77 gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(otype_combo)->entry),
79 /* set to same output format as a previous run ?? */
80 gtk_widget_show(otype_combo);
82 go_button = gtk_button_new_with_label("Assemble");
83 gtk_widget_show(go_button);
85 output_text = gtk_text_new(NULL, NULL);
86 gtk_text_set_editable(GTK_TEXT(output_text), FALSE);
87 gtk_widget_show(output_text);
89 top_hbox = gtk_hbox_new(FALSE, 2);
90 gtk_box_pack_start(GTK_BOX(top_hbox), file_label, FALSE, FALSE, 2);
91 gtk_box_pack_start(GTK_BOX(top_hbox), file_entry, TRUE, TRUE, 2);
92 gtk_widget_show(top_hbox);
94 middle_hbox = gtk_hbox_new(FALSE, 2);
95 gtk_box_pack_start(GTK_BOX(middle_hbox), otype_label, FALSE, FALSE, 2);
96 gtk_box_pack_start(GTK_BOX(middle_hbox), otype_combo, FALSE, FALSE, 2);
97 gtk_widget_show(middle_hbox);
99 bottom_hbox = gtk_hbox_new(FALSE, 2);
100 gtk_box_pack_start(GTK_BOX(bottom_hbox), go_button, FALSE, FALSE, 2);
101 gtk_box_pack_start(GTK_BOX(bottom_hbox), list_check, FALSE, FALSE, 2);
102 gtk_widget_show(bottom_hbox);
104 main_vbox = gtk_vbox_new(FALSE, 2);
105 gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, FALSE, FALSE, 2);
106 gtk_box_pack_start(GTK_BOX(main_vbox), middle_hbox, FALSE, FALSE, 2);
107 gtk_box_pack_start(GTK_BOX(main_vbox), bottom_hbox, FALSE, FALSE, 2);
108 gtk_box_pack_start(GTK_BOX(main_vbox), output_text, TRUE, TRUE, 2);
109 gtk_widget_show(main_vbox);
111 main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
112 gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
113 gtk_widget_show(main_window);
115 /* attach signal handlers so we can actually do something */
117 gtk_signal_connect(GTK_OBJECT(main_window), "delete_event",
118 GTK_SIGNAL_FUNC(delete_handler), NULL);
120 gtk_signal_connect(GTK_OBJECT(go_button), "pressed",
121 GTK_SIGNAL_FUNC(do_assemble), NULL);
123 /* that's it, everything past here is a callback from GTK */
125 mesg("WARNING: this is an alpha-quality release.\n");
126 mesg("It WILL crash the second time you assemble !!\n");
127 mesg("Please report any problems that occur on the\n");
128 mesg("first assembly to: paul@pjrc.com\n");
135 /* actually do the assembly. The entire assembly is done from */
136 /* start to finish in this callback attached to the "assemble now" */
137 /* button. It's not so nice to spend a lot of CPU time in a */
138 /* callback, because all the gtk widgets stop responding until */
139 /* we're done, but it keeps things simple, and at least the */
140 /* window manager takes care of raise/lower and reposition, */
141 /* ...unlike ms windoze where those are handled by the */
142 /* application's event loop. It would be "nice" to launch a */
143 /* thread that would do the assembly, but for a simple free */
144 /* software project (where the assembly completes rapidly on */
145 /* any modern cpu), I don't want to bother with all the unpleasant */
146 /* threading issues */
149 do_assemble(GtkWidget *widget, gpointer *data)
151 const char *fmt=NULL, *filename;
155 /* collect info from the GTK widgets */
157 do_lst = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(list_check));
159 filename = gtk_entry_get_text(GTK_ENTRY(file_entry));
160 if (filename == NULL || *filename == '\0') {
161 mesg("You need to specify the ASM file\n");
165 fmt = emit_desc_to_name_lookup(gtk_entry_get_text(
166 GTK_ENTRY(GTK_COMBO(otype_combo)->entry)));
168 mesg("Please select a valid output type\n");
172 /* now we can begin working like normal */
174 r = run_as31(filename, do_lst, 0, fmt, NULL, NULL);
177 mesg("Assembly complete, no errors :)\n");
182 /* quit the program if they close it */
185 delete_handler(GtkWidget *widget, gpointer *data)
192 /* the assembler calls here to display any messages */
194 void mesg(const char *str)
196 if (str == NULL) str = "(null)";
197 /* printf("%s", str); */
198 gtk_text_insert(GTK_TEXT(output_text), NULL, NULL,
199 NULL, str, strlen(str));