int machine_append(Triple *t,Handler h) { Code stmt = get_ready_stmt(); bind_code(t,stmt); machine_step(stmt ); if(h) h(t); return set_ready_event(0); }
int machine_step_fetch(Triple *t,Handler h) { Code stmt = get_ready_stmt(); machine_step(stmt); machine_triple(stmt,t); if(h) h(t); return set_ready_event(0); }
int machine_loop(Triple *t,Handler h) { int events; Code stmt = get_ready_stmt(); if(stmt) do { events=machine_step(stmt); if(events & EV_Error) G_printf("err: loop "); else if((events & EV_Data) && h) h(t); } while( !(events & EV_Done) ); machine_reset(stmt); return 0; }
void emscripten_run() { /* Run until screen is updated */ while (!video_updated()) machine_step(); /* Stop machine if frame count is reached */ if ((frames > 0) && (--frames == 0)) machine->running = false; /* Quit once user has requested it (or if frame count is reached) */ if (!machine->running) quit(); }
int qson_to_table(TABLE * table,char * buff,int count) { int i;Triple *in;int len; machine_set_operator(&table->operators[append_operator],0); in = &table->operators[append_data]; i = 0; while(i < count) { //use blob append format in->key = (char *) buff; sscanf(in->key,"%4d%c%3d",&len,&in->link,&in->pointer); machine_reset(table->stmt); bind_code(&table->operators[append_operator],table->stmt); machine_step(table->stmt); i+= (len+8); buff+= (len+8); } return i; }
int mem_to_table(TABLE* table,int * buff,int mode) { int rows,total; int i;Triple *data; Triple * Qson; start_table((TABLE *) table,append_operator); data = &(table)->operators[append_data]; Qson = (Triple *) (buff+2); rows = Qson[0].pointer; total = 0; for(i=0;i<rows;i++) { *data = Qson[i]; DBG_printf("MT%s%c%3d\n",Qson[i].key,Qson[i].link,Qson[i].pointer); //len = (int) Qson.key; // for blob bind machine_reset(table->stmt); bind_code(&(table)->operators[append_operator],table->stmt); machine_step(table->stmt); } return rows; }
int main(int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-rom")) { if (++i == argc) usage(); if (++i == argc) usage(); FILE *rom = fopen(argv[i], "r"); if (!rom) { fprintf(stderr, "Could not open ROM file: '%s'\n", argv[i]); return 1; } add_rom(argv[i-1], rom); fclose(rom); } else if (!strcmp(argv[i], "-n")) { if (++i == argc) usage(); steps = atoi(argv[i]); } else if (!strcmp(argv[i], "-in")) { if (++i == argc) usage(); infile = argv[i]; } else if (!strcmp(argv[i], "-out")) { if (++i == argc) usage(); outfile = argv[i]; } else { filename = argv[i]; } } if (filename == NULL) usage(); // Load program FILE *p_in; p_in = fopen(filename, "r"); if (!p_in) { fprintf(stderr, "Error: could not open file %s for input.\n", filename); return 1; } t_program* program = load_dumb_netlist(p_in); fclose(p_in); // Setup input and outputs FILE *input = stdin, *output = stdout; if (infile != NULL) { input = fopen(infile, "r"); if (!infile) { fprintf(stderr, "Error: could not open file %s for input.\n", infile); return 1; } } if (outfile != NULL) { output = fopen(outfile, "w"); if (!output) { fprintf(stderr, "Error: could not open file %s for output.\n", outfile); return 1; } } // Run t_machine *machine = init_machine(program); machine_banner(machine, output); i = 0; while (i < steps || steps == 0) { read_inputs(machine, input); machine_step(machine); write_outputs(machine, output); i++; } // Cleanup if (input != stdin) fclose(input); if (output != stdout) fclose(output); // No need to free memory, the OS deletes everything anyways when the process ends. return 0; }
void retro_run(void) { /* Run until screen is updated */ while (!video_updated()) machine_step(); }