Example #1
0
void main_loop (void)
{ 
  clear_all_buttons (); 
  
  if (botcfg.state == STATE_RECORDING)
  {
    fprintf (stdout, "RECORDING\n");
    if (record_start () != 0)
    {
      fprintf (stderr, "Error setting up record buffer\n");
      botcfg.state = STATE_EXITING;
    }
    wait_for_snes_powerup ();
  }
  else if (botcfg.state == STATE_PLAYBACK)
  {
    fprintf (stdout, "PLAYBACK\n");
    if (playback_start () != 0)
    {
      fprintf (stderr, "Error setting up playback buffer\n");
      botcfg.state = STATE_EXITING;
    }
    wait_for_snes_powerup ();
  }
  
  interrupt_enable();
 
  if (botcfg.state == STATE_PLAYBACK || botcfg.state == STATE_RECORDING)
    wait_for_first_latch ();
  
  while (botcfg.state != STATE_EXITING)
  {
    if (botcfg.state != STATE_PLAYBACK && botcfg.state != STATE_MACRO)
    {
      read_joystick_inputs();
    }

    if (!snes_is_on())
    {
      fprintf (stdout, "SNES poweroff detected\n");
      botcfg.state = STATE_EXITING;
    }
  }
  //Always attempt a save before exiting
  record_save ();
}
Example #2
0
int main (int argc, char **argv)
{
  botcfg.state = STATE_INIT;
   //piHiPri (45);
  if (setup () != 0)
  {
    fprintf (stderr, "Error setting up\n");
    return 1;
  }

  if (read_options (argc, argv) != 0)
  {
    fprintf (stderr, "Error reading options\n");
    return 1;
  }
  
  if (botcfg.state == STATE_INIT)
  {
    //User didn't chose either record or replay, falling back to passthrough
    botcfg.state = STATE_RUNNING;
  }
  
  if (joystick_setup () != 0)
  {
    fprintf (stderr, "Error setting up joysticks\n");
    return 1;
  }
  
  //drop_privs ();
  
  if (check_pid ())
  {
    fprintf (stderr, "Are we already running?\n");
    return 1;
  }
  
  main_loop ();
  clear_all_buttons (); 
  fprintf (stdout, "Exiting...\n");
  remove_pid ();
  return 0 ;
}
Example #3
0
static void
update_table_button(UIMCandWinHorizontalGtk *horizontal_cwin, guint new_page)
{
  UIMCandWinGtk *cwin;
  GtkTreeModel *model;
  GPtrArray *buttons;
  GtkTreeIter ti;
  gboolean has_next;
  gint display_limit, len, cand_index = 0;

  cwin = UIM_CAND_WIN_GTK(horizontal_cwin);
  if (!cwin->stores->pdata[new_page]) {
    return;
  }
  model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]);
  buttons = horizontal_cwin->buttons;
  display_limit = cwin->display_limit;
  len = buttons->len;

  clear_all_buttons(buttons);
  has_next = gtk_tree_model_get_iter_first(model, &ti);
  while (has_next) {
    gchar *heading;
    gchar *cand_str;
    GtkEventBox *button = NULL;

    gtk_tree_model_get(model, &ti, COLUMN_HEADING, &heading,
        COLUMN_CANDIDATE, &cand_str, TERMINATOR);
    if (cand_str != NULL) {
      button = assign_cellbutton(horizontal_cwin, cand_index, display_limit);
      if (button != NULL) {
        GtkWidget *label;
        label = gtk_bin_get_child(GTK_BIN(button));
        if (heading && heading[0] != '\0') {
          gchar *text = g_strdup_printf("%s: %s", heading, cand_str);
          gtk_label_set_text(GTK_LABEL(label), text);
          g_free(text);
	} else {
          gtk_label_set_text(GTK_LABEL(label), cand_str);
	}
	scale_label(button, PANGO_SCALE_LARGE);
      }
    }

    g_free(cand_str);
    g_free(heading);
    cand_index++;
    has_next = gtk_tree_model_iter_next(model, &ti);
  }

  if (cand_index < len) {
    gint i;
    for (i = len - 1; i >= cand_index; i--) {
      struct index_button *idxbutton;
      idxbutton = g_ptr_array_index(buttons, i);
      if (idxbutton == horizontal_cwin->selected)
        horizontal_cwin->selected = NULL;
      gtk_widget_destroy(GTK_WIDGET(idxbutton->button));
      g_free(idxbutton);
      g_ptr_array_remove_index(buttons, i);
    }
#if !GTK_CHECK_VERSION(3, 4, 0)
    gtk_table_resize(GTK_TABLE(cwin->view), 1, cand_index);
#endif
  }
}