static int work_turing(void) { int i = 0; init_tape(); while(1){ for(i = 0; i < rule_len; i++) if((rule[i].stat_now == stat) && (rule[i].char_now == tape[tape_pos])) break; /* 没有找到 */ if(i >= rule_len){ fprintf(stderr, "%s:%d: ERROR RULES: stat=%d, char=%d\n\n", __FILE__, __LINE__, stat, tape[tape_pos]); exit(1); } /* 更新状态 */ stat = rule[i].stat_next; tape[tape_pos] = rule[i].char_next; printf("[i=%d][%d]stat:[%d] tape:[%d]\n", i, tape_pos,stat, tape[tape_pos]); if(rule[i].dir) tape_pos++; else tape_pos--; if(stat <= REJECT) break; } return stat; }
char* bf_get_data(void) { char* data = strdup(buffer); init_buffer(); init_tape(); return data; }
/// Funkce main int main(int argc, char *argv[]) { if(argc != 2) { Error(ERROR_GEN_PARAM); fprintf(stderr, HELP_MSG); return ERROR_GEN; } FILE *file = fopen(argv[1], "r"); if(file == NULL) { Error(ERROR_GEN_FILE, argv[1]); return ERROR_GEN; } // nastaveni vstupu input = file; // inicializace pasky instrukci init_tape(); int x = parser(); if(x < 0) { Error(x); fclose(file); delete_tape(); drop_functions(); drop_literals(); return (-x) / 100; } fclose(file); #ifdef DEBUG print_tape(); #endif // vyhledove x = execute(); if(x < 0) Error(x); // uklid tabulky funkci drop_functions(); // uklid tabulky literalu drop_literals(); // uklid seznamu instrukci return (-x) / 100; }
void bf_do_cmd(int size, char* cmd) { int stack = 0; int pc = 0; if( 0 == tape_inited ) init_tape(); if( 0 == cmd ) return; while( 1 ){ if( pc >= size ) break; switch( (char)cmd[pc] ){ case '+': tape[get_tape_pos()]++; break; case '-': tape[get_tape_pos()]--; break; case '.': // save in buffer push_buffer( tape[get_tape_pos()] ); break; case ',': tape[get_tape_pos()] = cmd[pc]; break; case '>': inc_tape_pos(); break; case '<': dec_tape_pos(); break; case '[': if( 0 == tape[get_tape_pos()] ){ pc++; while( 1 ){ if( pc >= size ) break; if( stack <= 0 && cmd[pc] == ']' ) break; if( cmd[pc] == '[' ) stack++; if( cmd[pc] == ']' ) stack--; pc++; } } break; case ']': pc--; while( 1 ){ if( pc < 0 ) break; if( stack <= 0 && cmd[pc] == '[' ) break; if( cmd[pc] == ']' ) stack++; if( cmd[pc] == '[' ) stack--; pc--; } pc--; break; case '*': // invoke syscall break; default: break; } pc++; } return; }
void init_all(int argc, char **argv) { cpu_info(); char *config = 0, *bpx = 0, *labels = 0; char opt; while ((opt = getopt(argc, argv, "i:l:b:")) != EOF) switch (opt) { case 'i': config = optarg; break; case 'b': bpx = optarg; break; case 'l': labels = optarg; } temp.Minimized = false; init_z80tables(); init_ie_help(); load_config(config); //make_samples(); #ifdef MOD_GS init_gs(); #endif init_leds(); init_tape(); init_hdd_cd(); start_dx(); init_debug(); applyconfig(); main_reset(); autoload(); init_bpx(bpx); init_labels(labels); temp.Gdiplus = GdiplusStartup(); if (!temp.Gdiplus) { color(CONSCLR_WARNING); printf("warning: gdiplus.dll was not loaded, only SCR and BMP screenshots available\n"); } if (comp.ts.vdac2) { if (!vdac2::open_ft8xx()) { color(CONSCLR_WARNING); printf("warning: ft8xx library was not loaded\n"); comp.ts.vdac2 = false; } } load_errors = 0; trd_toload = 0; *(DWORD*)trd_loaded = 0; // clear loaded flags, don't see autoload'ed images for (; optind < argc; optind++) { char fname[0x200], *temp; GetFullPathName(argv[optind], sizeof fname, fname, &temp); trd_toload = DefaultDrive; // auto-select if (!loadsnap(fname)) errmsg("error loading <%s>", argv[optind]), load_errors = 1; } if (load_errors) { int code = MessageBox(wnd, "Some files, specified in\r\ncommand line, failed to load\r\n\r\nContinue emulation?", "File loading error", MB_YESNO | MB_ICONWARNING); if (code != IDYES) exit(); } SetCurrentDirectory(conf.workdir); // timeBeginPeriod(1); InitializeCriticalSection(&tsu_toggle_cr); }