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 (); }
void record_insert(record *r, const char * const name, const uint32_t score) { if (r != NULL) { const size_t name_length = sizeof(char) * (strlen(name) + 1); r->entry_count ++; if (r->entries == NULL) { r->entries = malloc(sizeof(entry)); r->entries->name = malloc(name_length); memset(r->entries->name, '\0', name_length); strcpy(r->entries->name, name); r->entries->score = score; } else { r->entries = realloc(r->entries, sizeof(entry) * r->entry_count); r->entries[r->entry_count - 1].name = malloc(name_length); memset(r->entries[r->entry_count - 1].name, '\0', name_length); strcpy(r->entries[r->entry_count - 1].name, name); r->entries[r->entry_count - 1].score = score; } record_save(r); } }