void copy_current_bank_to(uint8_t target_bank) { // Compute the source bank uint8_t sourceBank = ( (current_program.number+1) / 10 ) * 10; // Write programs uint32_t data; uint8_t program_index; for (program_index=0; program_index<10; program_index++) { // Bank 0 contains only 9 programs, so we have to skip certain actions if (program_index == 9) { // If bank 0 is the target, do nothing if (target_bank == 0) { break; } // If bank 0 is the source, write an empty program if (sourceBank == 0) { data = program_initializer; } } else { data = read_program_data(sourceBank + program_index); } write_program((target_bank*10) + program_index, data); } }
int main() { volatile uint16_t t; volatile uint16_t buff[2] = {0,0}; IOWR_ALTERA_AVALON_PIO_DATA(PIO_MODE_SELOUT_BASE, 0x0); IOWR_ALTERA_AVALON_PIO_DATA(PIO_KEYOUT_BASE, 0x7); //alt_putstr("Hello from Nios II!\n"); /* Event loop never exits. */ while (1) { t = alt_getchar(); //alt_printf("%x",t); buff[1] = buff[0]; buff[0] = t; if(buff[1] == 'W' && buff[0] == 'R'){ //alt_putstr("write start\n"); write_program(); } else if(buff[1] == 'R' && buff[0] == 'D'){ //alt_putstr("read start\n"); read_program(); } } return 0; }
void wipe_current_bank(void) { // Write programs uint8_t bank = ( (current_program.number+1) / 10 ) * 10; uint8_t i; for (i=0; i<10; i++) { write_program(bank+i, program_initializer); } // Apply the changes enter_program(current_program.number); }
void write_programs(char *storage) { list *l; definition *def; for (l = defined; l != NULL; l = l->next) { def = (definition *) l->val; if (def->def_kind == DEF_PROGRAM) { write_program(def, storage); } } }
void write_stubs(void) { list *l; definition *def; f_print(fout, "\nstatic struct timeval TIMEOUT = { %d, 0 };\n", DEFAULT_TIMEOUT); for (l = defined; l != NULL; l = l->next) { def = (definition *) l->val; if (def->def_kind == DEF_PROGRAM) { write_program(def); } } }
void write_program_to_file(Block* block, const char* filename) { Value strs; write_program(block, &strs); FILE* file = fopen(filename, "w"); int str_count = list_length(&strs); for (int i=0; i < str_count; i++) { caValue* str = list_get(&strs, i); const char* cstr = as_cstring(str); fwrite(cstr, 1, strlen(cstr), file); } fclose(file); }
void write_stubs(void) { list *l; definition *def; f_print(fout, "\n/* Default timeout can be changed using clnt_control() */\n"); f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n", DEFAULT_TIMEOUT); for (l = defined; l != NULL; l = l->next) { def = (definition *) l->val; if (def->def_kind == DEF_PROGRAM) write_program(def); } }
/* quit from edit mode. Put player back into the regular game mode */ void do_quit(dbref player, dbref program) { log_status("PROGRAM SAVED: %s by %s(%d)", unparse_object(player, program), NAME(player), player); write_program(PROGRAM_FIRST(program), program); if (tp_log_programs) log_program_text(PROGRAM_FIRST(program), player, program); free_prog_text(PROGRAM_FIRST(program)); PROGRAM_SET_FIRST(program, NULL); FLAGS(program) &= ~INTERNAL; FLAGS(player) &= ~INTERACTIVE; PLAYER_SET_CURR_PROG(player, NOTHING); DBDIRTY(player); DBDIRTY(program); }
static gboolean gnm_lpsolve_prepare (GnmSolver *sol, WorkbookControl *wbc, GError **err, GnmLPSolve *lp) { gboolean ok; g_return_val_if_fail (sol->status == GNM_SOLVER_STATUS_READY, FALSE); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARING); ok = write_program (sol, wbc, err); if (ok) gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARED); else { gnm_lpsolve_cleanup (lp); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_ERROR); } return ok; }
static gboolean gnm_glpk_prepare (GnmSolver *sol, WorkbookControl *wbc, GError **err, GnmGlpk *lp) { gboolean ok; int fd; g_return_val_if_fail (sol->status == GNM_SOLVER_STATUS_READY, FALSE); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARING); ok = write_program (sol, wbc, err); if (!ok) goto fail; fd = g_file_open_tmp ("program-XXXXXX.out", &lp->result_filename, err); if (fd == -1) { g_set_error (err, G_FILE_ERROR, 0, _("Failed to create file for solution")); goto fail; } close (fd); if (sol->params->options.sensitivity_report) { fd = g_file_open_tmp ("program-XXXXXX.ran", &lp->ranges_filename, err); if (fd == -1) { g_set_error (err, G_FILE_ERROR, 0, _("Failed to create file for sensitivity report")); goto fail; } close (fd); } gnm_solver_set_status (sol, GNM_SOLVER_STATUS_PREPARED); return TRUE; fail: gnm_glpk_cleanup (lp); gnm_solver_set_status (sol, GNM_SOLVER_STATUS_ERROR); return FALSE; }
int main(int argc, char *argv[]) { int ret = 1; char *basic_buf; int basic_len; /* Get options */ if (parse_cmdline(argc, argv)) { return ret; } /* Get length of binfile */ binlen = get_binlen(opt.binfile); if (binlen == 0) { fprintf(stderr, "Error: empty or non-existing BIN-file, giving up\n"); goto cleanup; } if (opt.scrfile) { if (get_binlen(opt.scrfile) != SCRLEN) { fprintf(stderr, "Error: wrong filesize on %s\n", opt.scrfile); goto cleanup; } } /* Open filepointers */ if (open_files()) { fprintf(stderr, "Error: could not open files, giving up\n"); goto cleanup; } snprintf(basenamez, opt.baselen + 1, "%s", opt.basename); if (!opt.no_basic) { /* Creater BASIC loader code */ if (create_basic_loader()) { fprintf(stderr, "Error: could not create BASIC loader, giving up\n"); } if (basic_get(&basic_buf, &basic_len)) { fprintf(stderr, "Error: could not create BASIC loader, giving up\n"); goto cleanup; } /* Write BASIC loader */ if (write_program(basic_buf, basic_len, "Loader")) { goto cleanup; } /* Write SCREEN$ data */ if (opt.scrfile) { if (write_code("Screen", scrfp, SCRLEN, SCRADDR)) { goto cleanup; } } } /* Write machine code from BIN-file */ if (write_code(basenamez, binfp, binlen, opt.load_address)) { goto cleanup; } /* Success */ printf("0 OK, 0:1 (%s)\n", opt.tapfile); ret = 0; cleanup: if (scrfp) fclose(scrfp); if (binfp) fclose(binfp); if (tapfp) fclose(tapfp); parse_cleanup(); return ret; }
void copy_current_program_to(uint8_t target_program) { // Copy program write_program(target_program, current_program.data); }
void wipe_current_program(void) { write_program(current_program.number, program_initializer); enter_program(current_program.number); }
void update_current_program(uint32_t program_data) { current_program.data = program_data; write_program(current_program.number, program_data); }
void dbnz_write_all(FILE * output, struct dbnz_compile_state *s, const struct dbnz_source *source_files, size_t source_file_num) { fprintf(output, "%" PRIuMAX " %" PRIuMAX "\n", (uintmax_t) s->proglen, (uintmax_t) ALIGN(s->constant_num)); write_constants(output, s); write_program(output, s, source_files, source_file_num); }