示例#1
0
static void
entry_to_mm (gchar * entry_name, gchar * spin_name, guint8 * base)
{
  GtkSpinButton *sb;
  GtkEntry *entry;
  const gchar *s;
  gint val;

  g_assert (spin_name);
  g_assert (base);

  sb = GTK_SPIN_BUTTON (lookup_widget (app->window_main, spin_name));
  g_assert (sb);

  entry = GTK_ENTRY (lookup_widget (app->window_main, entry_name));
  g_assert (entry);

  s = gtk_entry_get_text (entry);

  if (!asm_util_parse_number ((gchar *) s, &val))
	{
	  gui_app_show_msg (GTK_MESSAGE_INFO,
						_("Enter a valid number within range"));
	  return;
	}

  base[(gint) gtk_spin_button_get_value (sb)] = val;
  if (!strcmp (entry_name,"main_mem_entry"))
    gui_list_memory_update_single (gtk_spin_button_get_value_as_int (sb));
  if (!strcmp (entry_name,"main_io_entry"))
    gui_list_io_update_single (gtk_spin_button_get_value_as_int (sb));
}
示例#2
0
static gboolean
ori_save (gchar * fn, gboolean replace)
{
  gchar *text;
  FILE *fp;
  char *nullstr = "NULLSTRING";
  int ret;

  if (!fn)
	fn = nullstr;

  if (replace)
	{
	  fp = fopen (fn, "r");
	  if (fp != NULL)
		{
		  GtkWidget *dialog;
		  GtkResponseType response;
		  dialog = gtk_message_dialog_new (GTK_WINDOW(app->window_main),
						   GTK_DIALOG_DESTROY_WITH_PARENT,
						   GTK_MESSAGE_QUESTION, 
						   GTK_BUTTONS_YES_NO,
						   _("File already exists; overwrite it?"));
		  response = gtk_dialog_run (GTK_DIALOG (dialog));
		  gtk_widget_destroy (dialog);

		  if (response == GTK_RESPONSE_NO)
			return FALSE;

		  fclose (fp);
		}
	}
  text = gui_editor_get_text (app->editor);
  fp = fopen (fn, "w");
  if (fp == NULL)
	{
	  gchar errmsg[MAX_ERR_MSG_SIZE + 1];
	  g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to save <%s>"),
				  fn);
	  gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg);
	  return TRUE;
	}
  // return value stored just to avoid compiler warnings.
  ret = fwrite (text, 1, strlen (text), fp);
  gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE);
  
  /* debug */
  fclose (fp);

  g_free (text);
  if (replace)
	_set_file_name (fn);

  return TRUE;
}
示例#3
0
void
on_step_out1_activate (GtkMenuItem * menuitem, gpointer user_data)
{
  if (b_get_state () == B_STATE_IDLE)
	on_assemble1_activate (NULL, NULL);

  if (asm_error == FALSE)
	return;
  if (!b_resume_execution (B_TRACE_OUT))
	{
	  gui_app_show_msg (GTK_MESSAGE_ERROR, _("Error in step out"));
	}
}
示例#4
0
static gboolean
ori_save (gchar * fn, gboolean replace)
{
  gchar *text;
  GFile *fp;
  GFileOutputStream *file_out;
  GError *error = NULL;
  char *nullstr = "NULLSTRING";
  gssize bytes;

  if (!fn)
	fn = nullstr;

  fp = g_file_new_for_uri (fn);

  file_out = g_file_create (fp, G_FILE_CREATE_NONE, NULL, &error);
  if ((file_out == NULL) && (error->code == G_IO_ERROR_EXISTS))
	{
	  if (replace)
		{
		  g_error_free (error);
		/* replace file */
		  file_out = g_file_replace (fp, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error);
		}
	}
  text = gui_editor_get_text (app->editor);
  if (file_out == NULL)
	{
	  gchar errmsg[MAX_ERR_MSG_SIZE + 1];
	  g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to save <%s>"),
				  fn);
	  gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg);
	  return TRUE;
	}
  bytes = g_output_stream_write (G_OUTPUT_STREAM (file_out), text, strlen (text), NULL, NULL);
  gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE);
  
  /* debug */
  g_output_stream_close (G_OUTPUT_STREAM (file_out), NULL, NULL);

  g_free (text);
  if (replace)
	_set_file_name (fn);

  /*g_error_free (error);*/
  return TRUE;
}
示例#5
0
void
on_io_list_start_changed (GtkEntry *entry, gpointer user_data)
{
  gint start_addr;
  gchar *text;
  g_assert (entry);

  if (!asm_util_parse_number (text = (gchar *)gtk_entry_get_text (GTK_ENTRY (entry)),&start_addr))
  {
    gui_app_show_msg (GTK_MESSAGE_INFO, _("Enter a valid number within range (0-255 / 0h-00FFh)"));
    return;
  }
  gui_list_io_set_start (start_addr);
  gui_list_io_update ();
  text[strlen (text)] = 'h';
  gtk_entry_set_text (GTK_ENTRY (entry), text);
}
示例#6
0
void
on_io_list_start_clicked (GtkButton * button, gpointer user_data)
{
  GtkWidget *start_entry;
  gint start_addr;
  gchar *text;

  start_entry = lookup_widget (app->window_main, "io_list_start");
  g_assert (start_entry);

  if (!asm_util_parse_number (text = (gchar *)gtk_entry_get_text (GTK_ENTRY (start_entry)), &start_addr))
  {
    gui_app_show_msg (GTK_MESSAGE_INFO, _("Enter a valid number within range (0-255 / 0h-00FFh)"));
    return;
  }
  gui_list_io_set_start (start_addr);
  gui_list_io_update ();
  text[strlen (text)] = 'h';
  gtk_entry_set_text (GTK_ENTRY (start_entry), text);
}
示例#7
0
void
on_execute1_activate (GtkMenuItem * menuitem, gpointer user_data)
{
  if (b_get_state () == B_STATE_IDLE)
	on_assemble1_activate (NULL, NULL);

  if (asm_error == FALSE)
	return;

  if (!b_execute ())
	{
	  gui_app_show_msg (GTK_MESSAGE_ERROR,
						_("Error executing program"));
	}

  /* update */
  gui_view_update_all ();


}
示例#8
0
void
on_assemble1_activate (GtkMenuItem * menuitem, gpointer user_data)
{
  /* assemble file */
  gchar *a_text;

  /* la */
  validate_start_addr ();

  /* get text */
  a_text = gui_editor_get_text (app->editor);

  asm_error = b_assemble (a_text, start_addr);
  if (asm_error == FALSE)
	gui_app_show_msg (GTK_MESSAGE_WARNING,
					  _("Program has errors. Check the Message pane."));

  g_free (a_text);

  //disp_list( b_get_src() );
}
示例#9
0
void
ori_open (gchar * fn, gboolean replace)
{

  GString *gstr;
  GFile *fp;
  GFileInputStream *file_in;
  char *nullstr = "NULLSTRING";
  gssize bytes = 1;

  if (!fn)
	fn = nullstr;

  fp = g_file_new_for_uri (fn);

  if (fp == NULL)
	{
	  gchar errmsg[MAX_ERR_MSG_SIZE + 1];
	  g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to open <%s>"),
				  fn);
	  gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg);
	  return;
	}

  gstr = g_string_new ("");
  file_in = g_file_read (fp, NULL, NULL);
  
  while (bytes != 0)
	{
	  gchar buf[100] = { 0 };
	  bytes = g_input_stream_read (G_INPUT_STREAM (file_in), buf, 100, NULL, NULL);
	  g_string_append_len (gstr, buf, bytes);
	}
  g_input_stream_close (G_INPUT_STREAM (file_in), NULL, NULL);

  gui_editor_set_text (app->editor, gstr->str);
  gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE);

  /* Set breakpoints as instructed in the source */
  {
	gchar *str = gstr->str;
	gint ln = 0;

	gchar **lines = NULL;

	g_assert (str);

	lines = g_strsplit (str, "\n", -1);
	g_assert (lines);

	/* for each line */
	while (lines[ln])
	  {
		/* check for ;@ */
		if (strlen (lines[ln]) > 1)
		  {
			if (lines[ln][0] == ';'
				&& lines[ln][1] == '@')
			  {
				/* add breakpoint */
				gui_editor_set_mark (app->editor,
									 ln + 1, TRUE);
				//exit(99);
			  }
		  }
		ln++;
	  }

	g_strfreev (lines);
  }

  g_string_free (gstr, TRUE);
  if (replace)
	_set_file_name (fn);
}
示例#10
0
void
ori_open (gchar * fn, gboolean replace)
{

  GString *gstr;
  FILE *fp;
  char *nullstr = "NULLSTRING";
  char *ret;
  if (!fn)
	fn = nullstr;

  fp = fopen (fn, "r");

  if (fp == NULL)
	{
	  gchar errmsg[MAX_ERR_MSG_SIZE + 1];
	  g_snprintf (errmsg, MAX_ERR_MSG_SIZE, _("Failed to open <%s>"),
				  fn);
	  gui_app_show_msg (GTK_MESSAGE_ERROR, errmsg);
	  return;
	}

  gstr = g_string_new ("");

  while (!feof (fp))
	{
	  gchar buf[300] = { 0 };
	  // return value stored just to avoid compiler warnings.
	  ret = fgets (buf, 100, fp);
	  g_string_append (gstr, buf);
	}

  gui_editor_set_text (app->editor, gstr->str);
  gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE);

  /* Set breakpoints as instructed in the source */
  {
	gchar *str = gstr->str;
	gint ln = 0;

	gchar **lines = NULL;

	g_assert (str);

	lines = g_strsplit (str, "\n", -1);
	g_assert (lines);

	/* for each line */
	while (lines[ln])
	  {
		/* check for ;@ */
		if (strlen (lines[ln]) > 1)
		  {
			if (lines[ln][0] == ';'
				&& lines[ln][1] == '@')
			  {
				/* add breakpoint */
				gui_editor_set_mark (app->editor,
									 ln + 1, TRUE);
				//exit(99);
			  }
		  }
		ln++;
	  }

	g_strfreev (lines);
  }

  g_string_free (gstr, TRUE);
  if (replace)
	_set_file_name (fn);
}