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 list_proglines(dbref player, dbref program, struct frame *fr, int start, int end) { int range[2]; int argc; struct line *tmpline; if (start == end || end == 0) { range[0] = start; range[1] = start; argc = 1; } else { range[0] = start; range[1] = end; argc = 2; } if (!fr->brkpt.proglines || program != fr->brkpt.lastproglisted) { free_prog_text(fr->brkpt.proglines); fr->brkpt.proglines = read_program(program); fr->brkpt.lastproglisted = program; } tmpline = DBFETCH(program)->sp.program.first; DBSTORE(program, sp.program.first, fr->brkpt.proglines); do_list(player, program, range, argc); DBSTORE(program, sp.program.first, tmpline); return; }
int main(int argc, char* argv[]) { struct Stack stack; struct Program program; int exit_code = 1, file_nr, size; FILE * code_file; stack_new(&stack, 100); debug(" * created stack of 100"); if (argc > 1) { for (file_nr = 1; file_nr < argc; file_nr++) { #ifdef DEBUG printf(" * open file '%s'\n", argv[file_nr]); #endif code_file = fopen(argv[file_nr], "r"); debug(" * start programm"); size = program_size(code_file); fseek(code_file, 0, SEEK_SET); program_new(&program, size); debug(" * created programm, start reading..."); read_program(code_file, &program); exit_code = interprete(&stack, &program); fclose(code_file); } } else { debug(" ! no programm specified, vm will end"); printf("usage: %s {simple-language.slc}\n", argv[0]); } return exit_code; }
int init( ) { // charge 12 triangles, soit un cube... Mesh cube= read_mesh("data/flat_bbox.obj"); printf(" %u positions\n", (unsigned int) cube.positions.size()); // compile le shader program, le program est selectionne program= read_program("tutos/tuto3GL.glsl"); // transfere les 36 positions dans le tableau declare par le vertex shader // etape 1 : recuperer l'identifiant de l'uniform GLint location= glGetUniformLocation(program, "positions"); // uniform vec3 positions[36]; // etape 2 : modifier sa valeur glUniform3fv(location, cube.positions.size(), &cube.positions.front().x); // mesh n'est plus necessaire release_mesh(cube); // creer un vertex array object glGenVertexArrays(1, &vao); // etat openGL par defaut glClearColor(0.2, 0.2, 0.2, 1); // definir la couleur par defaut glClearDepth(1.f); // profondeur par defaut glDepthFunc(GL_LESS); // ztest, conserver l'intersection la plus proche de la camera glEnable(GL_DEPTH_TEST); // activer le ztest return 0; }
/* Use this to create a program. First, find a program that matches that name. If there's one, then we put him into edit mode and do it. Otherwise, we create a new object for him, and call it a program. */ void do_prog(int descr, dbref player, const char *name) { dbref i; struct match_data md; if (Typeof(player) != TYPE_PLAYER) { anotify_nolisten2(player, CFAIL "Only players can edit programs."); return; } else if (!Mucker(player)) { anotify_nolisten2(player, CFAIL NOMBIT_MESG); return; } else if (!tp_building || tp_db_readonly) { anotify_nolisten2(player, CFAIL NOBUILD_MESG); return; } else if (!*name) { anotify_nolisten2(player, CINFO "No program name given."); return; } init_match(descr, player, name, TYPE_PROGRAM, &md); match_possession(&md); match_neighbor(&md); match_registered(&md); match_absolute(&md); if ((i = match_result(&md)) == NOTHING) { i = new_program(OWNER(player), name); FLAGS(i) |= INTERNAL; DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CSUCC "Program %s created with number %d.", name, i); anotify_nolisten2(player, CINFO "Entering editor."); } else if (i == AMBIGUOUS) { anotify_nolisten2(player, CINFO "I don't know which one you mean!"); return; } else { if ((Typeof(i) != TYPE_PROGRAM) || !controls(player, i)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } else if (FLAGS(i) & INTERNAL) { anotify_nolisten2(player, CFAIL NOEDIT_MESG); return; } DBFETCH(i)->sp.program.first = read_program(i); FLAGS(i) |= INTERNAL; DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CINFO "Entering editor for %s.", unparse_object(player, i)); /* list current line */ do_list(player, i, 0, 0, 0); DBDIRTY(i); } FLAGS(player) |= INTERACTIVE; DBDIRTY(player); }
int main(int argc, char **argv) { if(argc > 1) { input_file = fopen(argv[1], "r"); } else { input_file = input_file; } unsigned char memory[65535]; unsigned char instructions[65535]; int pointer = 0; int ip = 0; int instruction = 0; for(pointer =0; pointer < 65535; pointer++) memory[pointer] = 0; for(pointer =0; pointer < 65535; pointer++) instructions[pointer] = 99; read_program(instructions); pointer = 0; while((instruction = instructions[ip]) != 99) { switch(instruction) { case INC: pointer++; break; case DEC: pointer--; break; case IN: memory[pointer] = getc(stdin); break; case OUT: putc(memory[pointer], stdout); break; case INC_B: memory[pointer] += 1; break; case DEC_B: memory[pointer] -= 1; break; case SKIP: if(memory[pointer] == 0) ip++; break; case SKIP_G: if(memory[pointer] > 0) ip++; break; case GO: ip = memory[pointer]-1; break; default: fprintf(stderr, "Should not be here\n"); return 1; } ip++; } return 0; }
/** * List program lines to a player * * This is used by the debugger for listing lines and for backtraces. * Uses the editor's list_program under the hood. * * @see list_program * * @param player the player to send the listing to * @param program the program to list * @param fr the running program frame * @param start the start line * @param end the end line */ void list_proglines(dbref player, dbref program, struct frame *fr, int start, int end) { int range[2]; int argc; if (start == end || end == 0) { range[0] = start; range[1] = start; argc = 1; } else { range[0] = start; range[1] = end; argc = 2; } /* Make sure we have the lines of code loaded for display */ if (!fr->brkpt.proglines || program != fr->brkpt.lastproglisted) { free_prog_text(fr->brkpt.proglines); fr->brkpt.proglines = (struct line *) read_program(program); fr->brkpt.lastproglisted = program; } { /* * We have to change the program position in order to do the * listing, so we use this tmpline so we can reset it when * we are done. */ struct line *tmpline = PROGRAM_FIRST(program); PROGRAM_SET_FIRST(program, fr->brkpt.proglines); { int tmpflg = (FLAGS(player) & INTERNAL); FLAGS(player) |= INTERNAL; list_program(player, program, range, argc, 0); if (!tmpflg) { FLAGS(player) &= ~INTERNAL; } } PROGRAM_SET_FIRST(program, tmpline); } return; }
void do_list_header(dbref player, dbref program) { struct line *curr = read_program(program); while (curr && (curr->this_line)[0] == '(') { notify(player, curr->this_line); curr = curr->next; } if (!(FLAGS(program) & INTERNAL)) { free_prog_text(curr); } notify(player, "Done."); }
// application void reload_program( ) { if(program == 0) program= read_program(program_filename); else reload_program(program, program_filename); // recupere les erreurs, si necessaire program_area= program_format_errors(program, program_log); if(program_log.size() > 0) printf("[boom]\n%s\n", program_log.c_str()); program_failed= (program_log.size() > 0); }
GLuint make_mesh_program( Mesh& m, const bool use_texcoord, const bool use_normal, const bool use_color ) { std::string definitions; if(m.texcoords.size() > 0 && use_texcoord) definitions.append("#define USE_TEXCOORD\n"); if(m.normals.size() > 0 && use_normal) definitions.append("#define USE_NORMAL\n"); if(m.colors.size() > 0 && use_color) definitions.append("#define USE_COLOR\n"); if(definitions.size() > 0) printf("[mesh program definitions]\n%s", definitions.c_str()); return read_program("data/shaders/mesh.glsl", definitions.c_str()); }
void do_edit(int descr, dbref player, const char *name) { dbref i; struct match_data md; if (Typeof(player) != TYPE_PLAYER) { anotify_nolisten2(player, CFAIL "Only players can edit programs."); return; } else if (!Mucker(player)) { anotify_nolisten2(player, CFAIL NOMBIT_MESG); return; } else if (tp_db_readonly) { anotify_nolisten2(player, CFAIL DBRO_MESG); return; } else if (!*name) { anotify_nolisten2(player, CINFO "No program name given."); return; } init_match(descr, player, name, TYPE_PROGRAM, &md); match_possession(&md); match_neighbor(&md); match_registered(&md); match_absolute(&md); if ((i = noisy_match_result(&md)) == NOTHING || i == AMBIGUOUS) return; if ((Typeof(i) != TYPE_PROGRAM) || !controls(player, i)) { anotify_fmt(player, CFAIL "%s", tp_noperm_mesg); return; } else if (FLAGS(i) & INTERNAL) { anotify_nolisten2(player, CFAIL NOEDIT_MESG); return; } FLAGS(i) |= INTERNAL; DBFETCH(i)->sp.program.first = read_program(i); DBFETCH(player)->sp.player.curr_prog = i; anotify_fmt(player, CINFO "Entering editor for %s.", unparse_object(player, i)); /* list current line */ do_list(player, i, 0, 0, 0); FLAGS(player) |= INTERACTIVE; DBDIRTY(i); DBDIRTY(player); }
void prim_cancallp(PRIM_PROTOTYPE) { CHECKOP(2); oper2 = POP(); /* string: public function name */ oper1 = POP(); /* dbref: Program dbref to check */ if (oper1->type != PROG_OBJECT) abort_interp("Expected dbref argument. (1)"); if (!valid_object(oper1)) abort_interp("Invalid dbref (1)"); if (Typeof(oper1->data.objref) != TYPE_PROGRAM) abort_interp("Object is not a MUF Program. (1)"); if (oper2->type != PROG_STRING) abort_interp("Expected string argument. (2)"); if (!oper2->data.string) abort_interp("Invalid Null string argument. (2)"); if (!(PROGRAM_CODE(oper1->data.objref))) { struct line *tmpline; tmpline = PROGRAM_FIRST(oper1->data.objref); PROGRAM_SET_FIRST(oper1->data.objref, (struct line *) read_program(oper1->data.objref)); do_compile(-1, OWNER(oper1->data.objref), oper1->data.objref, 0); free_prog_text(PROGRAM_FIRST(oper1->data.objref)); PROGRAM_SET_FIRST(oper1->data.objref, tmpline); } result = 0; if (ProgMLevel(oper1->data.objref) > 0 && (mlev >= 4 || OWNER(oper1->data.objref) == ProgUID || Linkable(oper1->data.objref)) ) { struct publics *pbs; pbs = PROGRAM_PUBS(oper1->data.objref); while (pbs) { if (!strcasecmp(oper2->data.string->data, pbs->subname)) break; pbs = pbs->next; } if (pbs && mlev >= pbs->mlev) result = 1; } CHECKOFLOW(1); CLEAR(oper1); CLEAR(oper2); PushInt(result); }
int parse(const char* file, program_t* p) { int r = 0; FILE* fp = NULL; prog = p; prog->file = strdup(file); assert(prog != NULL); if (file != NULL) { fp = fopen(file, "r"); if (fp == NULL) { fprintf(stderr, "Failed to open %s\n", file); return -1; } } else { fp = stdin; file = "<stdin>"; } r = start_scan(fp, file); if (r < 0) { return r; } init_variant(&value); init_variant(&next_value); next_token = scan_token(&next_value); read_program(); return result; }
void list_publics(int descr, dbref player, int arg[], int argc) { dbref program; if (argc > 1) { notify(player, "I don't understand which program you want to list PUBLIC functions for."); return; } program = (argc == 0) ? PLAYER_CURR_PROG(player) : arg[0]; if (Typeof(program) != TYPE_PROGRAM) { notify(player, "That isn't a program."); return; } if (!(controls(player, program) || Linkable(program))) { notify(player, "That's not a public program."); return; } if (!(PROGRAM_CODE(program))) { if (program == PLAYER_CURR_PROG(player)) { do_compile(descr, OWNER(program), program, 0); } else { struct line *tmpline; tmpline = PROGRAM_FIRST(program); PROGRAM_SET_FIRST(program, (struct line *) read_program(program)); do_compile(descr, OWNER(program), program, 0); free_prog_text(PROGRAM_FIRST(program)); PROGRAM_SET_FIRST(program, tmpline); } if (!PROGRAM_CODE(program)) { notify(player, "Program not compilable."); return; } } do_list_publics(player, program); }
int run(int argc, char** argv) { char* file; cpu_t cpu; int i; int j; int ninstr; unsigned instr; unsigned opcode; unsigned source_reg1; int constant; unsigned dest_reg; int source1; int source2; int dest; unsigned data; bool proceed; bool increment_pc; bool writeback; if (argc > 1) file = argv[1]; else file = "fac.s"; read_program(file, memory, &ninstr); /* First instruction to execute is at address 0. */ cpu.pc = 0; cpu.reg[0] = 0; proceed = true; while (proceed) { /* Fetch next instruction to execute. */ instr = read_memory(memory, cpu.pc); /* Decode the instruction. */ opcode = extract_opcode(instr); source_reg1 = extract_source1(instr); constant = extract_constant(instr); dest_reg = extract_dest(instr); /* Fetch operands. */ source1 = cpu.reg[source_reg1]; source2 = cpu.reg[constant & (NREG-1)]; increment_pc = true; writeback = true; printf("pc = %3d: ", cpu.pc); switch (opcode) { case ADD: puts("ADD"); dest = source1 + source2; break; case ADDI: puts("ADDI"); dest = source1 + constant; break; case SUB: puts("SUB"); dest = source1 - source2; break; case SUBI: puts("SUBI"); dest = source1 - constant; break; case MUL: puts("MUL"); dest = source1 * source2; break; case SGE: puts("SGE"); dest = source1 >= source2; break; case SGT: puts("SGT"); dest = source1 > source2; break; case SEQ: puts("SEQ"); dest = source1 == source2; break; case SEQI: puts("SEQI"); dest = source1 == constant; break; case BT: puts("BT"); writeback = false; if (source1 != 0) { cpu.pc = constant; increment_pc = false; } break; case BF: puts("BF"); writeback = false; if (source1 == 0) { cpu.pc = constant; increment_pc = false; } break; case BA: puts("BA"); writeback = false; increment_pc = false; cpu.pc = constant; break; case LD: puts("LD"); data = read_memory(memory, source1 + constant); dest = data; break; case ST: puts("ST"); data = cpu.reg[dest_reg]; write_memory(memory, source1 + constant, data); writeback = false; break; case CALL: puts("CALL"); increment_pc = false; dest = cpu.pc + 1; dest_reg = 31; cpu.pc = constant; break; case JMP: puts("JMP"); increment_pc = false; writeback = false; cpu.pc = source1; break; case HALT: puts("HALT"); increment_pc = false; writeback = false; proceed = false; break; default: error("illegal instruction at pc = %d: opcode = %d\n", cpu.pc, opcode); } if (writeback && dest_reg != 0) cpu.reg[dest_reg] = dest; if (increment_pc) cpu.pc += 1; #ifdef DEBUG i = 0; while (i < NREG) { for (j = 0; j < 4; ++j, ++i) { if (j > 0) printf("| "); printf("R%02d = %-12d", i, cpu.reg[i]); } printf("\n"); } #endif } i = 0; while (i < NREG) { for (j = 0; j < 4; ++j, ++i) { if (j > 0) printf("| "); printf("R%02d = %-12d", i, cpu.reg[i]); } printf("\n"); } return 0; }
void match_and_list(int descr, dbref player, const char *name, char *linespec) { dbref thing; char *p; char *q; int range[2]; int argc; struct match_data md; struct line *tmpline; init_match(descr, player, name, TYPE_PROGRAM, &md); match_neighbor(&md); match_possession(&md); match_registered(&md); match_absolute(&md); if ((thing = noisy_match_result(&md)) == NOTHING) return; if (Typeof(thing) != TYPE_PROGRAM) { notify(player, "You can't list anything but a program."); return; } /* if (!(controls(player, thing) || Linkable(thing))) { */ if (!(controls(player, thing) || (FLAGS(thing) & VEHICLE))) { notify(player, "Permission denied. (You don't control the program, and it's not set Viewable)"); return; } if (!*linespec) { range[0] = 1; range[1] = -1; argc = 2; } else { q = p = linespec; while (*p) { while (*p && !isspace(*p)) *q++ = *p++; while (*p && isspace(*++p)) ; } *q = '\0'; argc = 1; if (isdigit(*linespec)) { range[0] = atoi(linespec); while (*linespec && isdigit(*linespec)) linespec++; } else { range[0] = 1; } if (*linespec) { argc = 2; while (*linespec && !isdigit(*linespec)) linespec++; if (*linespec) range[1] = atoi(linespec); else range[1] = -1; } } tmpline = PROGRAM_FIRST(thing); PROGRAM_SET_FIRST(thing, read_program(thing)); do_list(player, thing, range, argc); free_prog_text(PROGRAM_FIRST(thing)); PROGRAM_SET_FIRST(thing, tmpline); return; }
/*! * Options de la ligne de commande : * * <dl> * <dt>-d</dt><dd>mode pas à pas (mise au point)</dd> * * <dt>-f</dt><dd>le programme est dans un fichier binaire ; le nom de ce * fichier doit être fourni également en paramètre de la ligne de * commande ; sans cette option, on exécute un programme de test prédéfini.</dd> * * </dl> */ int main(int argc, char *argv[]) { bool debug = false; bool binfile = false; bool no_exec = false; char *programfile = NULL; if (argc > 1) { for (int iarg = 1; iarg < argc; ++iarg) { if (argv[iarg][0] == '-') switch (argv[iarg][1]) { case 'd': debug = true; break; case 'b': binfile = true; break; case 'l': no_exec = true; break; case 'h': usage(); exit(EXIT_SUCCESS); default: fprintf(stderr, "Unknown option: %s\n", argv[iarg]); usage(); exit(EXIT_FAILURE); } else if (binfile) programfile = argv[iarg]; else fprintf(stderr, "Trailing options ignored...\n"); } } Machine mach; if (!binfile) load_program(&mach, textsize, text, datasize, data, dataend); else read_program(&mach, programfile); printf("\n*** Sauvegarde des programmes et données initiales en format binaire ***\n\n"); dump_memory(&mach); printf("\n*** Machine state before execution ***\n"); print_program(&mach); print_data(&mach); print_cpu(&mach); if (no_exec) return 0; printf("\n*** Execution trace ***\n\n"); simul(&mach, debug); printf("\n*** Machine state after execution ***\n"); print_cpu(&mach); print_data(&mach); if(allocated){ free(mach._text); free(mach._data); } return 0; }
extern int main(int argc, char * argv[]) { NEW(options, o); if (argc == 1) print_arglist(); read_options(o, argc, argv); { symbol * filename = add_s_to_b(0, argv[1]); char * file; symbol * u = get_input(filename, &file); if (u == 0) { fprintf(stderr, "Can't open input %s\n", argv[1]); exit(1); } { struct tokeniser * t = create_tokeniser(u, file); struct analyser * a = create_analyser(t); t->widechars = o->widechars; t->includes = o->includes; a->utf8 = t->utf8 = o->utf8; read_program(a); if (t->error_count > 0) exit(1); if (o->syntax_tree) print_program(a); close_tokeniser(t); if (!o->syntax_tree) { struct generator * g; const char * s = o->output_file; if (!s) { fprintf(stderr, "Please include the -o option\n"); print_arglist(); exit(1); } g = create_generator(a, o); if (o->make_lang == LANG_C || o->make_lang == LANG_CPLUSPLUS) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".h"); o->output_h = get_output(b); b[SIZE(b) - 1] = 'c'; if (o->make_lang == LANG_CPLUSPLUS) { b = add_s_to_b(b, "c"); } o->output_src = get_output(b); lose_b(b); generate_program_c(g); fclose(o->output_src); fclose(o->output_h); } #ifndef DISABLE_JAVA if (o->make_lang == LANG_JAVA) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".java"); o->output_src = get_output(b); lose_b(b); generate_program_java(g); fclose(o->output_src); } #endif #ifndef DISABLE_PYTHON if (o->make_lang == LANG_PYTHON) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".py"); o->output_src = get_output(b); lose_b(b); generate_program_python(g); fclose(o->output_src); } #endif #ifndef DISABLE_JSX if (o->make_lang == LANG_JSX) { symbol * b = add_s_to_b(0, s); b = add_s_to_b(b, ".jsx"); o->output_src = get_output(b); lose_b(b); generate_program_jsx(g); fclose(o->output_src); } #endif close_generator(g); } close_analyser(a); } lose_b(u); lose_b(filename); } { struct include * p = o->includes; while (p) { struct include * q = p->next; lose_b(p->b); FREE(p); p = q; } } FREE(o); if (space_count) fprintf(stderr, "%d blocks unfreed\n", space_count); return 0; }
int main(int argc, char* argv[]) { if (argc != 2) { printf("Bad argument! Just give me a filename of a compiled assembly program.\n"); return -EINVAL; } enable_udiv = 1; FILE* program; if (!(program = fopen(argv[1], "r"))) { printf("Bad argument! File not found.\n"); return -EINVAL; } build_symbol_table(argv[1]); pc = 0x3000; running = 1; read_program(program); int ch; initialize(); while(ch != KEY_F(1)) { ch = getch(); switch (ch) { case KEY_F(2): reset_program(program); break; case KEY_F(3): dbgwin_state = 1; break; case KEY_F(4): break; case KEY_F(5): step_forward(); break; case KEY_F(6): run_program(); break; case KEY_F(7): memwin_state = (memwin_state == 2 ? 0 : 2); mem_cursor = mem_index; break; case KEY_F(8): dbgwin_state = 2; break; case KEY_UP: if (memwin_state == 2) mem_cursor--; break; case KEY_DOWN: if (memwin_state == 2) mem_cursor++; break; case KEY_NPAGE: if (memwin_state == 2) mem_cursor += (LINES-DEBUGWIN_HEIGHT); break; case KEY_PPAGE: if (memwin_state == 2) mem_cursor -= (LINES-DEBUGWIN_HEIGHT); break; case 0xA: if (memwin_state ==2) brk[(unsigned short)mem_cursor] ^= 1; break; } refreshall(); } quit: curs_set(1); endwin(); return 0; }
void main() { Load_dialogs(); read_names(); read_program(); }
/** *** Main() **/ int main(int argc, char* argv[]) { int res, verbose = 0, do_read = 0, do_write=1, do_interactive = 0, vid = FAN_VID, pid = FAN_PID, report_size=FAN_SIZE; int serial = 0; char *name; unsigned char buf[256], program[2 * FAN_STEPS]; #define MAX_STR 255 wchar_t wstr[MAX_STR]; hid_device *handle; int i; #ifdef WIN32 UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); #endif // parse the command-line for(int i=1; i<argc; i++) { if ( !strncmp(argv[i], "--vid=", 6) ) sscanf(argv[i]+6, "%X", &vid); if ( !strncmp(argv[i], "--pid=", 6) ) sscanf(argv[i]+6, "%X", &pid); if ( !strcmp(argv[i], "--verbose") ) verbose = 1; if ( !strcmp(argv[i], "--read") ) do_read = 1; if ( !strcmp(argv[i], "--help") ) { printf("fanbot: control fanbot via USB HID communication\n" "kekbot.org - rev 1.0 - " __DATE__ " " __TIME__ "\n" "USE: \n" " fanbot [options] [data]\n" " --vid=0xABCD VID to use (default=0x%4.4X)\n" " --pid=0xABCD PID to use (default=0x%4.4X)\n" " --verbose Show more information\n", FAN_VID, FAN_PID, FAN_SIZE ); exit(1); } } // Wait for connection while( 1 ) { if ( verbose ) printf("Wait for connection...\n"); handle = hid_open(vid, pid, NULL); if ( handle ) break; // we have a connection Sleep(500); // usleep(1000*100); } hid_flush(handle); // Read serial# and name buf[1] = 0; res = hid_read(handle, buf, sizeof(buf)); memcpy(&serial, &buf[8], sizeof(serial) ); name = (char*)&buf[12]; printf("CONNECT %X %s\n", serial, name); memset(buf, 0, sizeof(buf)); read_program(handle, program); print_program(program); if ( verbose ) { // Read the Manufacturer String wstr[0] = 0x0000; res = hid_get_manufacturer_string(handle, wstr, MAX_STR); if (res < 0) printf("Unable to read manufacturer string\n"); else printf("Manufacturer String: %ls\n", wstr); // Read the Product String wstr[0] = 0x0000; res = hid_get_product_string(handle, wstr, MAX_STR); if (res < 0) printf("Unable to read product string\n"); else printf("Product String: %ls\n", wstr); // Read the Serial Number String wstr[0] = 0x0000; res = hid_get_serial_number_string(handle, wstr, MAX_STR); if (res < 0) printf("Unable to read serial number string\n"); else printf("Serial Number String: (%d) %ls", wstr[0], wstr); printf("\n"); // Read Indexed String 1 wstr[0] = 0x0000; res = hid_get_indexed_string(handle, 1, wstr, MAX_STR); if (res < 0) printf("Unable to read indexed string 1\n"); else printf("Indexed String 1: %ls\n", wstr); } #define BEGIN() pch = strtok (str,",. ") #define NEXT() pch = strtok (NULL,",. ") #define COMMAND(s) (!strncmp(pch, s, sizeof(s)-1)) while ( 1 ) { char str[MAX_STR], *pch; fgets(str , MAX_STR-1, stdin); if ( strlen(str) < 1 ) continue; BEGIN(); if ( COMMAND("SET") ) { int leds=0, s1=0, s2=0; if ( (NEXT()) != NULL ) sscanf(pch, "%d", &leds); if ( (NEXT()) != NULL ) sscanf(pch, "%d", &s1); if ( (NEXT()) != NULL ) sscanf(pch, "%d", &s2); buf[1] = CMD_SET; buf[2] = leds; buf[3] = s1; buf[4] = s2; res = hid_write(handle, buf, report_size); } else if ( COMMAND("PLAY") ) { int n = 1; buf[1] = CMD_PLAY; if ( (NEXT()) != NULL ) sscanf(pch, "%d", &n); buf[2] = n; res = hid_write(handle, buf, report_size); } else if ( COMMAND("PROGRAM") ) { int i = 2, val = 0; memset(buf,0,sizeof(buf)); buf[1] = CMD_PROGRAM; while ( (NEXT()) != NULL ) { sscanf(pch, "%d", &val); buf[i++] = val; } res = hid_write(handle, buf, report_size); } else if ( COMMAND("NAME") ) { buf[1] = CMD_NAME; memset(&buf[2], 0, 32); for(i=0; i<32 && str[i+5] != 0 && str[i+5] != '\n' && str[i+5] != '\r'; i++) buf[i+2] = (unsigned char) str[i+5]; res = hid_write(handle, buf, report_size); } else if ( COMMAND("STOP") ) { buf[1] = CMD_STOP; res = hid_write(handle, buf, report_size); } else if ( COMMAND("READ") ) // read memory content { res = read_program(handle, program); if ( res < 0 ) break; print_program(program); } else if ( COMMAND("QUIT") ) { break; } else buf[1] = CMD_NONE; if (res < 0) { printf("ERROR: Unable to write(), '%ls'\n", hid_error(handle)); exit(1); } } printf("DISCONNECT\n"); hid_close(handle); hid_exit();/* Free static HIDAPI objects. */ return res; }
struct inst * interp_loop(dbref player, dbref program, struct frame *fr, int rettyp) { register struct inst *pc; register int atop; register struct inst *arg; register struct inst *temp1; register struct inst *temp2; register struct stack_addr *sys; register int instr_count; register int stop; int i = 0, tmp, writeonly, mlev; static struct inst retval; char dbuf[BUFFER_LEN]; int instno_debug_line = get_primitive("debug_line"); fr->level = ++interp_depth; /* increment interp level */ /* load everything into local stuff */ pc = fr->pc; atop = fr->argument.top; stop = fr->system.top; arg = fr->argument.st; sys = fr->system.st; writeonly = fr->writeonly; already_created = 0; fr->brkpt.isread = 0; if (!pc) { struct line *tmpline; tmpline = PROGRAM_FIRST(program); PROGRAM_SET_FIRST(program, (struct line *) read_program(program)); do_compile(-1, OWNER(program), program, 0); free_prog_text(PROGRAM_FIRST(program)); PROGRAM_SET_FIRST(program, tmpline); pc = fr->pc = PROGRAM_START(program); if (!pc) { abort_loop_hard("Program not compilable. Cannot run.", NULL, NULL); } PROGRAM_INC_PROF_USES(program); PROGRAM_INC_INSTANCES(program); } ts_useobject(program); err = 0; instr_count = 0; mlev = ProgMLevel(program); gettimeofday(&fr->proftime, NULL); /* This is the 'natural' way to exit a function */ while (stop) { /* Abort program if player/thing running it is recycled */ if ((player < 0) || (player >= db_top) || ((Typeof(player) != TYPE_PLAYER) && (Typeof(player) != TYPE_THING))) { reload(fr, atop, stop); prog_clean(fr); interp_depth--; calc_profile_timing(program,fr); return NULL; } fr->instcnt++; instr_count++; if ((fr->multitask == PREEMPT) || (FLAGS(program) & BUILDER)) { if (mlev == 4) { if (tp_max_ml4_preempt_count) { if (instr_count >= tp_max_ml4_preempt_count) abort_loop_hard("Maximum preempt instruction count exceeded", NULL, NULL); } else instr_count = 0; } else { /* else make sure that the program doesn't run too long */ if (instr_count >= tp_max_instr_count) abort_loop_hard("Maximum preempt instruction count exceeded", NULL, NULL); } } else { /* if in FOREGROUND or BACKGROUND mode, '0 sleep' every so often. */ if ((fr->instcnt > tp_instr_slice * 4) && (instr_count >= tp_instr_slice)) { fr->pc = pc; reload(fr, atop, stop); PLAYER_SET_BLOCK(player, (!fr->been_background)); add_muf_delay_event(0, fr->descr, player, NOTHING, NOTHING, program, fr, (fr->multitask == FOREGROUND) ? "FOREGROUND" : "BACKGROUND"); interp_depth--; calc_profile_timing(program,fr); return NULL; } } if (((FLAGS(program) & ZOMBIE) || fr->brkpt.force_debugging) && !fr->been_background && controls(player, program) ) { fr->brkpt.debugging = 1; } else { fr->brkpt.debugging = 0; } if (FLAGS(program) & DARK || (fr->brkpt.debugging && fr->brkpt.showstack && !fr->brkpt.bypass)) { if ((pc->type != PROG_PRIMITIVE) || (pc->data.number != instno_debug_line)) { char *m = debug_inst(fr, 0, pc, fr->pid, arg, dbuf, sizeof(dbuf), atop, program); notify_nolisten(player, m, 1); } } if (fr->brkpt.debugging) { short breakflag = 0; if (stop == 1 && !fr->brkpt.bypass && pc->type == PROG_PRIMITIVE && pc->data.number == IN_RET ) { /* Program is about to EXIT */ notify_nolisten(player, "Program is about to EXIT.", 1); breakflag = 1; } else if (fr->brkpt.count) { for (i = 0; i < fr->brkpt.count; i++) { if ((!fr->brkpt.pc[i] || pc == fr->brkpt.pc[i]) && /* pc matches */ (fr->brkpt.line[i] == -1 || (fr->brkpt.lastline != pc->line && fr->brkpt.line[i] == pc->line)) && /* line matches */ (fr->brkpt.level[i] == -1 || stop <= fr->brkpt.level[i]) && /* level matches */ (fr->brkpt.prog[i] == NOTHING || fr->brkpt.prog[i] == program) && /* program matches */ (fr->brkpt.linecount[i] == -2 || (fr->brkpt.lastline != pc->line && fr->brkpt.linecount[i]-- <= 0)) && /* line count matches */ (fr->brkpt.pccount[i] == -2 || (fr->brkpt.lastpc != pc && fr->brkpt.pccount[i]-- <= 0)) /* pc count matches */ ) { if (fr->brkpt.bypass) { if (fr->brkpt.pccount[i] == -1) fr->brkpt.pccount[i] = 0; if (fr->brkpt.linecount[i] == -1) fr->brkpt.linecount[i] = 0; } else { breakflag = 1; break; } } } } if (breakflag) { char *m; char buf[BUFFER_LEN]; if (fr->brkpt.dosyspop) { program = sys[--stop].progref; pc = sys[stop].offset; } add_muf_read_event(fr->descr, player, program, fr); reload(fr, atop, stop); fr->pc = pc; fr->brkpt.isread = 0; fr->brkpt.breaknum = i; fr->brkpt.lastlisted = 0; fr->brkpt.bypass = 0; fr->brkpt.dosyspop = 0; PLAYER_SET_CURR_PROG(player, program); PLAYER_SET_BLOCK(player, 0); interp_depth--; if (!fr->brkpt.showstack) { m = debug_inst(fr, 0, pc, fr->pid, arg, dbuf, sizeof(dbuf), atop, program); notify_nolisten(player, m, 1); } if (pc <= PROGRAM_CODE(program) || (pc - 1)->line != pc->line) { list_proglines(player, program, fr, pc->line, 0); } else { m = show_line_prims(fr, program, pc, 15, 1); snprintf(buf, sizeof(buf), " %s", m); notify_nolisten(player, buf, 1); } calc_profile_timing(program,fr); return NULL; } fr->brkpt.lastline = pc->line; fr->brkpt.lastpc = pc; fr->brkpt.bypass = 0; } if (mlev < 3) { if (fr->instcnt > (tp_max_instr_count * ((mlev == 2) ? 4 : 1))) abort_loop_hard("Maximum total instruction count exceeded.", NULL, NULL); } switch (pc->type) { case PROG_INTEGER: case PROG_FLOAT: case PROG_ADD: case PROG_OBJECT: case PROG_VAR: case PROG_LVAR: case PROG_SVAR: case PROG_STRING: case PROG_LOCK: case PROG_MARK: case PROG_ARRAY: if (atop >= STACK_SIZE) abort_loop("Stack overflow.", NULL, NULL); copyinst(pc, arg + atop); pc++; atop++; break; case PROG_LVAR_AT: case PROG_LVAR_AT_CLEAR: { struct inst *tmp; struct localvars *lv; if (atop >= STACK_SIZE) abort_loop("Stack overflow.", NULL, NULL); if (pc->data.number >= MAX_VAR || pc->data.number < 0) abort_loop("Scoped variable number out of range.", NULL, NULL); lv = localvars_get(fr, program); tmp = &(lv->lvars[pc->data.number]); copyinst(tmp, arg + atop); if (pc->type == PROG_LVAR_AT_CLEAR) { CLEAR(tmp); tmp->type = PROG_INTEGER; tmp->data.number = 0; } pc++; atop++; } break; case PROG_LVAR_BANG: { struct inst *the_var; struct localvars *lv; if (atop < 1) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); if (pc->data.number >= MAX_VAR || pc->data.number < 0) abort_loop("Scoped variable number out of range.", NULL, NULL); lv = localvars_get(fr, program); the_var = &(lv->lvars[pc->data.number]); CLEAR(the_var); temp1 = arg + --atop; *the_var = *temp1; pc++; } break; case PROG_SVAR_AT: case PROG_SVAR_AT_CLEAR: { struct inst *tmp; if (atop >= STACK_SIZE) abort_loop("Stack overflow.", NULL, NULL); tmp = scopedvar_get(fr, 0, pc->data.number); if (!tmp) abort_loop("Scoped variable number out of range.", NULL, NULL); copyinst(tmp, arg + atop); if (pc->type == PROG_SVAR_AT_CLEAR) { CLEAR(tmp); tmp->type = PROG_INTEGER; tmp->data.number = 0; } pc++; atop++; } break; case PROG_SVAR_BANG: { struct inst *the_var; if (atop < 1) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); the_var = scopedvar_get(fr, 0, pc->data.number); if (!the_var) abort_loop("Scoped variable number out of range.", NULL, NULL); CLEAR(the_var); temp1 = arg + --atop; *the_var = *temp1; pc++; } break; case PROG_FUNCTION: { int i = pc->data.mufproc->args; if (atop < i) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < i) abort_loop("Stack protection fault.", NULL, NULL); if (fr->skip_declare) fr->skip_declare = 0; else scopedvar_addlevel(fr, pc, pc->data.mufproc->vars); while (i-->0) { struct inst *tmp; temp1 = arg + --atop; tmp = scopedvar_get(fr, 0, i); if (!tmp) abort_loop_hard("Internal error: Scoped variable number out of range in FUNCTION init.", temp1, NULL); CLEAR(tmp); copyinst(temp1, tmp); CLEAR(temp1); } pc++; } break; case PROG_IF: if (atop < 1) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (false_inst(temp1)) pc = pc->data.call; else pc++; CLEAR(temp1); break; case PROG_EXEC: if (stop >= STACK_SIZE) abort_loop("System Stack Overflow", NULL, NULL); sys[stop].progref = program; sys[stop++].offset = pc + 1; pc = pc->data.call; fr->skip_declare = 0; /* Make sure we DON'T skip var decls */ break; case PROG_JMP: /* Don't need to worry about skipping scoped var decls here. */ /* JMP to a function header can only happen in IN_JMP */ pc = pc->data.call; break; case PROG_TRY: if (atop < 1) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp1->type != PROG_INTEGER || temp1->data.number < 0) abort_loop("Argument is not a positive integer.", temp1, NULL); if (fr->trys.top && atop - fr->trys.st->depth < temp1->data.number) abort_loop("Stack protection fault.", NULL, NULL); if (temp1->data.number > atop) abort_loop("Stack Underflow.", temp1, NULL); fr->trys.top++; fr->trys.st = push_try(fr->trys.st); fr->trys.st->depth = atop - temp1->data.number; fr->trys.st->call_level = stop; fr->trys.st->for_count = 0; fr->trys.st->addr = pc->data.call; pc++; CLEAR(temp1); break; case PROG_PRIMITIVE: /* * All pc modifiers and stuff like that should stay here, * everything else call with an independent dispatcher. */ switch (pc->data.number) { case IN_JMP: if (atop < 1) abort_loop("Stack underflow. Missing address.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp1->type != PROG_ADD) abort_loop("Argument is not an address.", temp1, NULL); if (temp1->data.addr->progref >= db_top || temp1->data.addr->progref < 0 || (Typeof(temp1->data.addr->progref) != TYPE_PROGRAM)) abort_loop_hard("Internal error. Invalid address.", temp1, NULL); if (program != temp1->data.addr->progref) { abort_loop("Destination outside current program.", temp1, NULL); } if (temp1->data.addr->data->type == PROG_FUNCTION) { fr->skip_declare = 1; } pc = temp1->data.addr->data; CLEAR(temp1); break; case IN_EXECUTE: if (atop < 1) abort_loop("Stack Underflow. Missing address.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp1->type != PROG_ADD) abort_loop("Argument is not an address.", temp1, NULL); if (temp1->data.addr->progref >= db_top || temp1->data.addr->progref < 0 || (Typeof(temp1->data.addr->progref) != TYPE_PROGRAM)) abort_loop_hard("Internal error. Invalid address.", temp1, NULL); if (stop >= STACK_SIZE) abort_loop("System Stack Overflow", temp1, NULL); sys[stop].progref = program; sys[stop++].offset = pc + 1; if (program != temp1->data.addr->progref) { program = temp1->data.addr->progref; fr->caller.st[++fr->caller.top] = program; mlev = ProgMLevel(program); PROGRAM_INC_INSTANCES(program); } pc = temp1->data.addr->data; CLEAR(temp1); break; case IN_CALL: if (atop < 1) abort_loop("Stack Underflow. Missing dbref argument.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; temp2 = 0; if (temp1->type != PROG_OBJECT) { temp2 = temp1; if (atop < 1) abort_loop("Stack Underflow. Missing dbref of func.", temp1, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp2->type != PROG_STRING) abort_loop("Public Func. name string required. (2)", temp1, temp2); if (!temp2->data.string) abort_loop("Null string not allowed. (2)", temp1, temp2); } if (temp1->type != PROG_OBJECT) abort_loop("Dbref required. (1)", temp1, temp2); if (!valid_object(temp1) || Typeof(temp1->data.objref) != TYPE_PROGRAM) abort_loop("Invalid object.", temp1, temp2); if (!(PROGRAM_CODE(temp1->data.objref))) { struct line *tmpline; tmpline = PROGRAM_FIRST(temp1->data.objref); PROGRAM_SET_FIRST(temp1->data.objref, (struct line *) read_program(temp1->data.objref)); do_compile(-1, OWNER(temp1->data.objref), temp1->data.objref, 0); free_prog_text(PROGRAM_FIRST(temp1->data.objref)); PROGRAM_SET_FIRST(temp1->data.objref, tmpline); if (!(PROGRAM_CODE(temp1->data.objref))) abort_loop("Program not compilable.", temp1, temp2); } if (ProgMLevel(temp1->data.objref) == 0) abort_loop("Permission denied", temp1, temp2); if (mlev < 4 && OWNER(temp1->data.objref) != ProgUID && !Linkable(temp1->data.objref)) abort_loop("Permission denied", temp1, temp2); if (stop >= STACK_SIZE) abort_loop("System Stack Overflow", temp1, temp2); sys[stop].progref = program; sys[stop].offset = pc + 1; if (!temp2) { pc = PROGRAM_START(temp1->data.objref); } else { struct publics *pbs; int tmpint; pbs = PROGRAM_PUBS(temp1->data.objref); while (pbs) { tmpint = string_compare(temp2->data.string->data, pbs->subname); if (!tmpint) break; pbs = pbs->next; } if (!pbs) abort_loop("PUBLIC or WIZCALL function not found. (2)", temp2, temp2); if (mlev < pbs->mlev) abort_loop("Insufficient permissions to call WIZCALL function. (2)", temp2, temp2); pc = pbs->addr.ptr; } stop++; if (temp1->data.objref != program) { calc_profile_timing(program,fr); gettimeofday(&fr->proftime, NULL); program = temp1->data.objref; fr->caller.st[++fr->caller.top] = program; PROGRAM_INC_INSTANCES(program); mlev = ProgMLevel(program); } PROGRAM_INC_PROF_USES(program); ts_useobject(program); CLEAR(temp1); if (temp2) CLEAR(temp2); break; case IN_RET: if (stop > 1 && program != sys[stop - 1].progref) { if (sys[stop - 1].progref >= db_top || sys[stop - 1].progref < 0 || (Typeof(sys[stop - 1].progref) != TYPE_PROGRAM)) abort_loop_hard("Internal error. Invalid address.", NULL, NULL); calc_profile_timing(program,fr); gettimeofday(&fr->proftime, NULL); PROGRAM_DEC_INSTANCES(program); program = sys[stop - 1].progref; mlev = ProgMLevel(program); fr->caller.top--; } scopedvar_poplevel(fr); pc = sys[--stop].offset; break; case IN_CATCH: case IN_CATCH_DETAILED: { int depth; if (!(fr->trys.top)) abort_loop_hard("Internal error. TRY stack underflow.", NULL, NULL); depth = fr->trys.st->depth; while (atop > depth) { temp1 = arg + --atop; CLEAR(temp1); } while (fr->trys.st->for_count-->0) { CLEAR(&fr->fors.st->cur); CLEAR(&fr->fors.st->end); fr->fors.top--; fr->fors.st = pop_for(fr->fors.st); } fr->trys.top--; fr->trys.st = pop_try(fr->trys.st); if (pc->data.number == IN_CATCH) { /* IN_CATCH */ if (fr->errorstr) { arg[atop].type = PROG_STRING; arg[atop++].data.string = alloc_prog_string(fr->errorstr); free(fr->errorstr); fr->errorstr = NULL; } else { arg[atop].type = PROG_STRING; arg[atop++].data.string = NULL; } if (fr->errorinst) { free(fr->errorinst); fr->errorinst = NULL; } } else { /* IN_CATCH_DETAILED */ stk_array *nu = new_array_dictionary(); if (fr->errorstr) { array_set_strkey_strval(&nu, "error", fr->errorstr); free(fr->errorstr); fr->errorstr = NULL; } if (fr->errorinst) { array_set_strkey_strval(&nu, "instr", fr->errorinst); free(fr->errorinst); fr->errorinst = NULL; } array_set_strkey_intval(&nu, "line", fr->errorline); array_set_strkey_refval(&nu, "program", fr->errorprog); arg[atop].type = PROG_ARRAY; arg[atop++].data.array = nu; } reload(fr, atop, stop); } pc++; break; case IN_EVENT_WAITFOR: if (atop < 1) abort_loop("Stack Underflow. Missing eventID list array argument.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp1->type != PROG_ARRAY) abort_loop("EventID string list array expected.", temp1, NULL); if (temp1->data.array && temp1->data.array->type != ARRAY_PACKED) abort_loop("Argument must be a list array of eventid strings.", temp1, NULL); if (!array_is_homogenous(temp1->data.array, PROG_STRING)) abort_loop("Argument must be a list array of eventid strings.", temp1, NULL); fr->pc = pc + 1; reload(fr, atop, stop); { int i, outcount; int count = array_count(temp1->data.array); char** events = (char**)malloc(count * sizeof(char**)); for (outcount = i = 0; i < count; i++) { char *val = array_get_intkey_strval(temp1->data.array, i); if (val != NULL) { int found = 0; int j; for (j = 0; j < outcount; j++) { if (!strcmp(events[j], val)) { found = 1; break; } } if (!found) { events[outcount++] = val; } } } muf_event_register_specific(player, program, fr, outcount, events); free(events); } PLAYER_SET_BLOCK(player, (!fr->been_background)); CLEAR(temp1); interp_depth--; calc_profile_timing(program,fr); return NULL; /* NOTREACHED */ break; case IN_READ: if (writeonly) abort_loop("Program is write-only.", NULL, NULL); if (fr->multitask == BACKGROUND) abort_loop("BACKGROUND programs are write only.", NULL, NULL); reload(fr, atop, stop); fr->brkpt.isread = 1; fr->pc = pc + 1; PLAYER_SET_CURR_PROG(player, program); PLAYER_SET_BLOCK(player, 0); add_muf_read_event(fr->descr, player, program, fr); interp_depth--; calc_profile_timing(program,fr); return NULL; /* NOTREACHED */ break; case IN_SLEEP: if (atop < 1) abort_loop("Stack Underflow.", NULL, NULL); if (fr->trys.top && atop - fr->trys.st->depth < 1) abort_loop("Stack protection fault.", NULL, NULL); temp1 = arg + --atop; if (temp1->type != PROG_INTEGER) abort_loop("Invalid argument type.", temp1, NULL); fr->pc = pc + 1; reload(fr, atop, stop); if (temp1->data.number < 0) abort_loop("Timetravel beyond scope of muf.", temp1, NULL); add_muf_delay_event(temp1->data.number, fr->descr, player, NOTHING, NOTHING, program, fr, "SLEEPING"); PLAYER_SET_BLOCK(player, (!fr->been_background)); interp_depth--; calc_profile_timing(program,fr); return NULL; /* NOTREACHED */ break; default: nargs = 0; reload(fr, atop, stop); tmp = atop; prim_func[pc->data.number - 1] (player, program, mlev, pc, arg, &tmp, fr); atop = tmp; pc++; break; } /* switch */ break; case PROG_CLEARED: log_status("WARNING: attempt to execute instruction cleared by %s:%hd in program %d", (char*)pc->data.addr, pc->line, program); pc = NULL; abort_loop_hard("Program internal error. Program erroneously freed from memory.", NULL, NULL); default: pc = NULL; abort_loop_hard("Program internal error. Unknown instruction type.", NULL, NULL); } /* switch */ if (err) { if (err != ERROR_DIE_NOW && fr->trys.top) { while (fr->trys.st->call_level < stop) { if (stop > 1 && program != sys[stop - 1].progref) { if (sys[stop - 1].progref >= db_top || sys[stop - 1].progref < 0 || (Typeof(sys[stop - 1].progref) != TYPE_PROGRAM)) abort_loop_hard("Internal error. Invalid address.", NULL, NULL); calc_profile_timing(program,fr); gettimeofday(&fr->proftime, NULL); PROGRAM_DEC_INSTANCES(program); program = sys[stop - 1].progref; mlev = ProgMLevel(program); fr->caller.top--; } scopedvar_poplevel(fr); stop--; } pc = fr->trys.st->addr; err = 0; } else { reload(fr, atop, stop); prog_clean(fr); PLAYER_SET_BLOCK(player, 0); interp_depth--; calc_profile_timing(program,fr); return NULL; } } } /* while */ PLAYER_SET_BLOCK(player, 0); if (atop) { struct inst *rv; if (rettyp) { copyinst(arg + atop - 1, &retval); rv = &retval; } else { if (!false_inst(arg + atop - 1)) { rv = (struct inst *) 1; } else { rv = NULL; } } reload(fr, atop, stop); prog_clean(fr); interp_depth--; calc_profile_timing(program,fr); return rv; } reload(fr, atop, stop); prog_clean(fr); interp_depth--; calc_profile_timing(program,fr); return NULL; }
LG_HPROGRAM lg_read_program(void* buffer, int size) { return trapWithRetval( [buffer,size](){ return read_program(buffer, size); }, nullptr ); }