int run (char **args,int bg, char *comm,char *in, char *out) { pid_t pid = fork(); int status; if(in) redir_input(in); if(out) redir_output(out); if(pid == 0) { if(bg) raise(SIGSTOP); execvp(args[0],args); perror(args[0]); exit(-1); } else { if(bg) { appendJob(comm,pid); } else { actual_pid = pid; waitpid(pid,&status,0); actual_pid = -1; if(WIFEXITED(status)) return WEXITSTATUS(status); else return -1; } } }
void SAM(C64 *the_c64) { bool done = false; char c; TheCPU = the_c64->TheCPU; TheCPU1541 = the_c64->TheCPU1541; TheVIC = the_c64->TheVIC; TheSID = the_c64->TheSID; TheCIA1 = the_c64->TheCIA1; TheCIA2 = the_c64->TheCIA2; // Get CPU registers and current memory configuration TheCPU->GetState(&R64); TheCPU->ExtConfig = (~R64.ddr | R64.pr) & 7; TheCPU1541->GetState(&R1541); #ifdef __riscos__ Wimp_CommandWindow((int)"SAM"); #endif #ifdef AMIGA if (!(fin = fout = ferr = fopen("CON:0/0/640/480/SAM", "w+"))) return; #else fin = stdin; fout = stdout; ferr = stdout; #endif access_1541 = false; address = R64.pc; fprintf(ferr, "\n *** SAM - Simple Assembler and Monitor ***\n *** Press 'h' for help ***\n\n"); init_abort(); display_registers(); while (!done) { if (access_1541) fprintf(ferr, "1541> "); else fprintf(ferr, "C64> "); fflush(ferr); read_line(); while ((c = get_char()) == ' ') ; switch (c) { case 'a': // Assemble get_token(); assemble(); break; case 'b': // Binary dump get_token(); binary_dump(); break; case 'c': // Compare get_token(); compare(); break; case 'd': // Disassemble get_token(); disassemble(); break; case 'e': // Interrupt vectors int_vectors(); break; case 'f': // Fill get_token(); fill(); break; case 'h': // Help help(); break; case 'i': // ASCII dump get_token(); ascii_dump(); break; case 'k': // Memory configuration get_token(); mem_config(); break; case 'l': // Load data get_token(); load_data(); break; case 'm': // Memory dump get_token(); memory_dump(); break; case 'n': // Screen code dump get_token(); screen_dump(); break; case 'o': // Redirect output get_token(); redir_output(); break; case 'p': // Sprite dump get_token(); sprite_dump(); break; case 'r': // Registers get_reg_token(); registers(); break; case 's': // Save data get_token(); save_data(); break; case 't': // Transfer get_token(); transfer(); break; case 'v': // View machine state view_state(); break; case 'x': // Exit done = true; break; case ':': // Change memory get_token(); modify(); break; case '1': // Switch to 1541 mode access_1541 = true; break; case '6': // Switch to C64 mode access_1541 = false; break; case '?': // Compute expression get_token(); print_expr(); break; case '\n': // Blank line break; default: // Unknown command error("Unknown command"); break; } } exit_abort(); #ifdef AMIGA fclose(fin); #endif if (fout != ferr) fclose(fout); #ifdef __riscos__ Wimp_CommandWindow(-1); #endif // Set CPU registers TheCPU->SetState(&R64); TheCPU1541->SetState(&R1541); }