Ejemplo n.º 1
0
static bool simulator_view(WINDOW *out, WINDOW *state, struct program *program,
                           enum STATE *current_state)
{
        int input;
        static int timeout = 0;

        set_state(current_state);

        while (1) {
                wtimeout(state, timeout);
                input = wgetch(status);

                if (program->simulator.memory[program->simulator.PC].isBreakpoint) {
                        popup_window("Breakpoint hit!", 0, true);
                        program->simulator.isPaused = true;
                        program->simulator.memory[program->simulator.PC]
                                .isBreakpoint = false;
                }

                if (QUIT == input) {
                        return false;
                } else if (GOBACK == input) {
                        *current_state = MAIN;
                        program->simulator.isPaused = true;
                        return true;
                } else if (PAUSE == input) {
                        program->simulator.isPaused = !program->simulator.isPaused;
                } else if (START == input || RUN == input) {
                        program->simulator.isPaused = program->simulator.isHalted;
                } else if (RESTART == input) {
                        memPopulated = -1;
                        init_machine(program);
                        wclear(out);
                        wrefresh(out);
                } else if (STEP_NEXT == input) {
                        executeNext(&(program->simulator), output);
                        program->simulator.isPaused = true;
                        printState(&(program->simulator), state);
                } else if (CONTINUE == input) {
                        memPopulated = -1;
                        init_machine(program);
                } else if (CONTINUE_RUN == input) {
                        memPopulated = -1;
                        init_machine(program);
                        program->simulator.isPaused = false;
                }

                if (!program->simulator.isPaused && !program->simulator.isHalted) {
                        executeNext(&(program->simulator), out);
                        timeout = 0;
                } else {
                        set_state(current_state);
                        printState(&(program->simulator), state);
                        timeout = -1;
                        generateContext(context, program, 0, program->simulator.PC);
                }
        }
}
Ejemplo n.º 2
0
static bool main_view(WINDOW *state, enum STATE *current_state,
                      struct program *program)
{
        int input;

        while (1) {
                set_state(current_state);
                input = wgetch(state);
                if (QUIT == input) {
                        return false;
                } else if (LOGDUMP == input) {
                        if (logDump(program)) {
                                return false;
                        }
                } else if (SIMVIEW == input) {
                        *current_state = SIM;
                        return true;
                } else if (MEMVIEW == input) {
                        *current_state = MEM;
                        return true;
                } else if (FILESEL == input) {
                        prompt((char const *) NULL, "Enter the .obj file: ",
                                program->objectfile);
                        if (init_machine(program)) {
                                return false;
                        }
                }
        }
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
  FILE *parFile = fopen(GCODE_PARAMETER_STORE, "r");
  FILE *inputFile = (argc > 1 ? fopen(argv[1], "r") : stdin);
  char line[0xFF];

  init_parameters(parFile);
  init_machine(NULL);
  init_stacks(NULL);
  init_tools(NULL);
  init_input(inputFile);
  //TODO: align API, add done_gcode_state().
  init_gcode_state(NULL);
  init_cycles(NULL);
  //TODO: align API, make it take a pointer to init data.
  init_queue();
  init_checker(NULL);

  while(machine_running() && gcode_running() && fetch_line_input(line)) {
    if(gcode_check(line)) update_gcode_state(line);
    move_machine_queue();
  }
  /* Flush movement queue */
  while(move_machine_queue());

  done_checker();
  done_queue();
  done_cycles();
  done_input();
  done_tools();
  done_stacks();
  done_machine();
  done_parameters();

  return 0;
}
Ejemplo n.º 4
0
/**
 * Execute the current ATI shader program, operating on the given span.
 */
void
_swrast_exec_fragment_shader(struct gl_context * ctx, SWspan *span)
{
   const struct ati_fragment_shader *shader = ctx->ATIFragmentShader.Current;
   struct atifs_machine machine;
   GLuint i;

   /* incoming colors should be floats */
   ASSERT(span->array->ChanType == GL_FLOAT);

   for (i = 0; i < span->end; i++) {
      if (span->array->mask[i]) {
	 init_machine(ctx, &machine, shader, span, i);

	 execute_shader(ctx, shader, &machine, span, i);

         /* store result color */
	 {
	    const GLfloat *colOut = machine.Registers[0];
            /*fprintf(stderr,"outputs %f %f %f %f\n",
              colOut[0], colOut[1], colOut[2], colOut[3]); */
            COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], colOut);
	 }
      }
   }
}
Ejemplo n.º 5
0
int
main(int argc, char *argv[])
{
  char *input; /* input filename (program to run) */

  progname=argv[0];
  input=parse_command_line(argc, argv); /* parse options, get input filename */
  init_machine(); /* initialize machine */
  load_imem(input); /* load the instructions */

  if( interactive ) {
    printf("pendvm %s -- matt debergalis <*****@*****.**>\n",VERSION);
    loop(); /* never returns */

  } else {
    int result=step_processor(-1); /* just go on until halt */
    
    if( !result ) return 0; /* all was good */
    
    /* something went wrong - give 'coredump' and exit */

    printf("\n"); /* already printed error message */
    com_reg(NULL, 0); /* this is wrong... */
    display_state();
    printf("\n");

    return 1;
  }
}
Ejemplo n.º 6
0
int main(int argc,char **argv)
{
	int i,list,log,success;

	list = 0;
        for (i = 1;i < argc;i++)
        {
                if (stricmp(argv[i],"-list") == 0)
                        list = 1;
        }

	if (list)
	{
                printf("\nMAME currently supports the following games:\n\n");
		i = 0;
		while (drivers[i])
		{
			printf("%10s",drivers[i]->name);
			i++;
                        if (!(i % 7)) printf("\n");
		}
                if (i % 7) printf("\n");
                printf("\nTotal games supported: %4d\n", i);
		return 0;
	}

	success = 1;

	log = 0;
	for (i = 1;i < argc;i++)
	{
		if (stricmp(argv[i],"-log") == 0)
			log = 1;
	}

	if (log) errorlog = fopen("error.log","wa");

	if (init_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME,argc,argv) == 0)
	{
		if (osd_init(argc,argv) == 0)
		{
			if (run_machine(argc > 1 && argv[1][0] != '-' ? argv[1] : DEFAULT_NAME) == 0)
				success = 0;
			else printf("Unable to start emulation\n");

			osd_exit();
		}
		else printf("Unable to initialize system\n");

		shutdown_machine();
	}
	else printf("Unable to initialize machine emulation\n");

	if (errorlog) fclose(errorlog);

	return success;
}
Ejemplo n.º 7
0
void AgiEngine::initialize() {
	memset(&opt, 0, sizeof(struct agi_options));
	opt.gamerun = GAMERUN_RUNGAME;
	opt.hires = true;

	// TODO: Some sound emulation modes do not fit our current music
	//       drivers, and I'm not sure what they are. For now, they might
	//       as well be called "PC Speaker" and "Not PC Speaker".

	switch (MidiDriver::detectMusicDriver(MDT_PCSPK)) {
	case MD_PCSPK:
		opt.soundemu = SOUND_EMU_PC;
		break;
	default:
		opt.soundemu = SOUND_EMU_NONE;
		break;
	}

	if (ConfMan.hasKey("render_mode"))
		opt.renderMode = Common::parseRenderMode(ConfMan.get("render_mode").c_str());

	_console = new Console(this);

	init_machine();

	game.color_fg = 15;
	game.color_bg = 0;

	*game.name = 0;

	game.sbuf = (uint8 *) calloc(_WIDTH, _HEIGHT);
	game.hires = (uint8 *) calloc(_WIDTH * 2, _HEIGHT);

	_sprites = new SpritesMan;
	_text = new TextMan;
	init_video();

	tick_timer = 0;
	_timer->installTimerProc(agi_timer_function_low, 10 * 1000, NULL);

	game.ver = -1;		/* Don't display the conf file warning */

	debugC(2, kDebugLevelMain, "Detect game");
	if (agi_detect_game() == err_OK) {
		game.state = STATE_LOADED;
		debugC(2, kDebugLevelMain, "game loaded");
	} else {
		report("Could not open AGI game");
	}

	debugC(2, kDebugLevelMain, "Init sound");
	init_sound();
	g_agi_music = new AGIMusic(_mixer);
}
Ejemplo n.º 8
0
/**
 * Run fragment program on the pixels in span from 'start' to 'end' - 1.
 */
static void
run_program(struct gl_context *ctx, SWspan *span, GLuint start, GLuint end)
{
   SWcontext *swrast = SWRAST_CONTEXT(ctx);
   const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
   const GLbitfield64 outputsWritten = program->Base.OutputsWritten;
   struct gl_program_machine *machine = &swrast->FragProgMachine;
   GLuint i;

   for (i = start; i < end; i++) {
      if (span->array->mask[i]) {
         init_machine(ctx, machine, program, span, i);

         if (_mesa_execute_program(ctx, &program->Base, machine)) {

            /* Store result color */
	    if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_COLOR)) {
               COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i],
                       machine->Outputs[FRAG_RESULT_COLOR]);
            }
            else {
               /* Multiple drawbuffers / render targets
                * Note that colors beyond 0 and 1 will overwrite other
                * attributes, such as FOGC, TEX0, TEX1, etc.  That's OK.
                */
               GLuint buf;
               for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) {
                  if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DATA0 + buf)) {
                     COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0 + buf][i],
                             machine->Outputs[FRAG_RESULT_DATA0 + buf]);
                  }
               }
            }

            /* Store result depth/z */
            if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
               const GLfloat depth = machine->Outputs[FRAG_RESULT_DEPTH][2];
               if (depth <= 0.0)
                  span->array->z[i] = 0;
               else if (depth >= 1.0)
                  span->array->z[i] = ctx->DrawBuffer->_DepthMax;
               else
                  span->array->z[i] =
                     (GLuint) (depth * ctx->DrawBuffer->_DepthMaxF + 0.5F);
            }
         }
         else {
            /* killed fragment */
            span->array->mask[i] = GL_FALSE;
            span->writeAll = GL_FALSE;
         }
      }
   }
}
Ejemplo n.º 9
0
int main(void)
{
    init_environment();
    MACHINE *mach = make_machine();
    for (int i = 0; i < 23; i++)
        printf("ins %d: %08x\n", i, factorial_ins[i]);
    printf("\n");
    init_machine(mach);
    load_memory(factorial_ins, 100, mach, 0);
    run_machine(mach);
    
    free_machine(mach);
    return 0;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: Nemh/chip8
int main()
{
	char filename[50] = {'\0'};
	//fileBrowser(filename, (unsigned char*)"*.lua", (unsigned char*)"*.lc", (unsigned char*)"*.txt", "Title"); //*.lua, *.lc, *.txt: filetypes to filter; "Title": small text to show in blue on the top left corner  
	Exec_info exec_info = {0,0,0};
	int key = 0, debug = 0, handle_program, i=0;
	char pc_s[10];
	Bdisp_AllClr_VRAM();

	srand(time_getTicks());

	init_gui();
	init_machine();
	while(1) {
		handle_program = gui(exec_info);
		if(handle_program > 0) {
			init_machine();
			load_game(handle_program);
			exec_info = play_game();
		} else {
			while(i < 10) {
				nio_DrawConsole(&c1);
				GetKey(&key);
				i++;
			}
			i=0;
		}
	}

	nio_CleanUp(&c1);

	while(1) {
		GetKey(&key);
	}
	return 1;
}
Ejemplo n.º 11
0
extern "C" void
init_ex1(SuifEnv *suif_env)
{
    static bool init_done = false;

    if (init_done)
	return;
    init_done = true;

    ModuleSubSystem *mSubSystem = suif_env->get_module_subsystem();
    mSubSystem->register_module(new Ex1SuifPass(suif_env));

    // initialize the libraries required by this OPI pass
    init_suifpasses(suif_env);
    init_machine(suif_env);
}
Ejemplo n.º 12
0
extern "C" void
init_m2a(SuifEnv *suif_env)
{
    static bool init_done = false;

    if (init_done)
	return;
    init_done = true;

    ModuleSubSystem *mSubSystem = suif_env->get_module_subsystem();
    mSubSystem->register_module(new M2aSuifPass(suif_env));

    init_suifpasses(suif_env);
    init_machine(suif_env);
    init_suifvm(suif_env);
}
Ejemplo n.º 13
0
bool Emulator_Init()
{
    LOG_DBG("Emulator_Init()\n");
    config_default();
    init_machine();

    int size = cart.romsize;
    cart.romsize = 0;
    struct stat st;
    stat(current_rom, &st);
    reloadrom(st.st_size, current_rom);

    mode_switch = MODE_EMULATION;

    emulator_loaded = true;
    need_load_rom = false;
    return 1;
}
Ejemplo n.º 14
0
void startMachine(struct program *program)
{
        initscr();
        atexit(exit_handle);

        raw();
        curs_set(0);
        noecho();
        cbreak();
        start_color();
        init_pair(1, COLOR_RED, COLOR_BLACK);

        MESSAGE_HEIGHT = 5;
        MESSAGE_WIDTH = COLS / 2;

        status = newwin(6, COLS, 1, 0);
        output = newwin((LINES - 6) / 3, COLS, 7, 0);
        context = newwin(2 * (LINES - 6) / 3, COLS, (LINES - 6) / 3 + 7, 0);

        box(status, 0, 0);
        box(context, 0, 0);

        keypad(context, 1);

        scrollok(output, 1);

        if (NULL == program->objectfile) {
                program->objectfile = malloc(sizeof(char) * (size_t) MESSAGE_WIDTH);
                prompt(NULL, "Enter the .obj file: ", program->objectfile);
        }

        program->simulator = init_state;

        if (!init_machine(program)) {
                run_machine(program);
        }

        delwin(status);
        delwin(output);
        delwin(context);
        endwin();
}
Ejemplo n.º 15
0
/**
 * Execute the current fragment program, operating on the given span.
 */
void
_swrast_exec_fragment_shader(GLcontext * ctx, struct sw_span *span)
{
   const struct ati_fragment_shader *shader = ctx->ATIFragmentShader.Current;
   GLuint i;

   ctx->_CurrentProgram = GL_FRAGMENT_SHADER_ATI;

   for (i = 0; i < span->end; i++) {
      if (span->array->mask[i]) {
	 init_machine(ctx, &ctx->ATIFragmentShader.Machine,
		      ctx->ATIFragmentShader.Current, span, i);

	 if (execute_shader(ctx, shader, ~0,
			    &ctx->ATIFragmentShader.Machine, span, i)) {
	    span->array->mask[i] = GL_FALSE;
	 }

	 {
	    const GLfloat *colOut =
	       ctx->ATIFragmentShader.Machine.Registers[0];

	    /*fprintf(stderr,"outputs %f %f %f %f\n", colOut[0], colOut[1], colOut[2], colOut[3]); */
	    UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][RCOMP], colOut[0]);
	    UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][GCOMP], colOut[1]);
	    UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][BCOMP], colOut[2]);
	    UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], colOut[3]);
	 }
      }

   }


   ctx->_CurrentProgram = 0;

}
Ejemplo n.º 16
0
int main (int argc, char *argv[])
{
	int ec;

	MaxApplZone ();

	game.clock_enabled = FALSE;
	game.state = STATE_INIT;

	init_machine (argc, argv);

	game.color_fg = 15;
	game.color_bg = 0;

	if ((game.sbuf = calloc (_WIDTH, _HEIGHT)) == NULL) {
		ec = err_NotEnoughMemory;
		goto bail_out;
	}
#ifdef USE_HIRES
	if ((game.hires = calloc (_WIDTH * 2, _HEIGHT)) == NULL) {
		ec = err_NotEnoughMemory;
		goto bail_out_2;
	};
	opt.hires = 1;
#endif

	if (init_sprites () != err_OK) {
		ec = err_NotEnoughMemory;
		goto bail_out_3;
	}

	if (init_video () != err_OK) {
		ec = err_Unk;
		goto bail_out_4;
	}

	console_init ();
	report ("--- Starting console ---\n\n");

	_D ("Init sound");
	init_sound ();

	game.ver = -1;		/* Disable conf file warning */

	report (" \nSarien " VERSION " is ready.\n");
	if (game.state < STATE_LOADED) {
       		console_prompt ();
		do { main_cycle (); } while (game.state < STATE_RUNNING);
		if (game.ver < 0)
			game.ver = 0;	/* Enable conf file warning */
	}

	ec = run_game ();

	deinit_sound ();
	deinit_video ();

bail_out_4:
	deinit_sprites ();
bail_out_3:
#ifdef USE_HIRES
	free (game.hires);
#endif
bail_out_2:
	free (game.sbuf);
bail_out:
	if (ec == err_OK || ec == err_DoNothing) {
		deinit_machine ();
		exit (ec);
	}

	deinit_machine ();

	return ec;
}
Ejemplo n.º 17
0
int run_game(int game)
{
	callback_item *cb;
	int error = 0;

	/* start in the "pre-init phase" */
	current_phase = MAME_PHASE_PREINIT;

/* AdvanceMAME: Disable validity checks */
#if 0
	/* perform validity checks before anything else */
	if (mame_validitychecks(game) != 0)
		return 1;
#endif

	/* loop across multiple hard resets */
	exit_pending = FALSE;
	while (error == 0 && !exit_pending)
	{
		/* use setjmp/longjmp for deep error recovery */
		fatal_error_jmpbuf_valid = TRUE;
		error = setjmp(fatal_error_jmpbuf);
		if (error == 0)
		{
			int settingsloaded;

			/* move to the init phase */
			current_phase = MAME_PHASE_INIT;

			/* start tracking resources for real */
			begin_resource_tracking();

			/* if we have a logfile, set up the callback */
			logerror_callback_list = NULL;
			if (options.logfile)
				add_logerror_callback(logfile_callback);

			/* create the Machine structure and driver */
			create_machine(game);

			/* then finish setting up our local machine */
			init_machine();

			/* load the configuration settings and NVRAM */
			settingsloaded = config_load_settings();
			nvram_load();

			/* initialize the UI and display the startup screens */
			if (ui_init(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo) != 0)
				fatalerror("User cancelled");

			/* ensure we don't show the opening screens on a reset */
			options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE;

			/* start resource tracking; note that soft_reset assumes it can */
			/* call end_resource_tracking followed by begin_resource_tracking */
			/* to clear out resources allocated between resets */
			begin_resource_tracking();

			/* perform a soft reset -- this takes us to the running phase */
			soft_reset(0);

			/* run the CPUs until a reset or exit */
			hard_reset_pending = FALSE;
			while ((!hard_reset_pending && !exit_pending) || saveload_pending_file != NULL)
			{
				profiler_mark(PROFILER_EXTRA);

				/* execute CPUs if not paused */
				if (!mame_paused)
					cpuexec_timeslice();

				/* otherwise, just pump video updates through */
				else
				{
					updatescreen();
					reset_partial_updates();
				}

				/* handle save/load */
				if (saveload_schedule_callback)
					(*saveload_schedule_callback)();

				profiler_mark(PROFILER_END);
			}

			/* and out via the exit phase */
			current_phase = MAME_PHASE_EXIT;

			/* stop tracking resources at this level */
			end_resource_tracking();

			/* save the NVRAM and configuration */
			nvram_save();
			config_save_settings();
		}
		fatal_error_jmpbuf_valid = FALSE;

		/* call all exit callbacks registered */
		for (cb = exit_callback_list; cb; cb = cb->next)
			(*cb->func.exit)();

		/* close all inner resource tracking */
		while (resource_tracking_tag != 0)
			end_resource_tracking();

		/* free our callback lists */
		free_callback_list(&exit_callback_list);
		free_callback_list(&reset_callback_list);
		free_callback_list(&pause_callback_list);
	}

	/* return an error */
	return error;
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
int
states_main( int argc, char ** argv )
{
    struct args args;
    int fd;

    if ( parse_args( argc, argv, &args ) < 0 )
    {
        fprintf( stderr, "usage:\n"
                 "stategen file.st -b -h file.H -c file.C [-s file2.C]\n"
                 "    file.st  : input file\n"
                 "    -b       : emit base class\n"
                 "    file.H   : header file\n"
                 "    file.C   : implementation\n"
                 "    file2.C  : skeleton implementation\n" );
        return( 1 );
    }

    close( 0 );
    close( 1 );

    if ( open( args.inputfile, O_RDONLY ) < 0 )
    {
        fprintf( stderr, "unable to open input file: %s\n",
                 strerror( errno ));
        exit( 1 );
    }

    init_machine( &args );
    yyparse();

    fprintf( stderr,
             "*** used %d bytes of memory in %d parse entries\n",
             machine.bytes_allocated, machine.entries );

    if ( args.headerfile )
    {
        fprintf( stderr, "*** producing header file %s\n", args.headerfile );
        unlink( args.headerfile );
        open( args.headerfile, O_CREAT | O_WRONLY, 0644 );
        dump_machine( DUMP_HEADER );
        fflush( stdout );
        close( 1 );
    }

    if ( args.implfile )
    {
        fprintf( stderr, "*** producing implementation file %s\n",
                 args.implfile );
        unlink( args.implfile );
        open( args.implfile, O_CREAT | O_WRONLY, 0644 );
        dump_machine( DUMP_CODE );
        fflush( stdout );
        close( 1 );
    }

    if ( args.skelfile )
    {
        fprintf( stderr, "*** producing skeleton file %s\n", args.skelfile );
        unlink( args.skelfile );
        open( args.skelfile, O_CREAT | O_WRONLY, 0644 );
        dump_machine( DUMP_SKELETON );
        fflush( stdout );
        close( 1 );
    }

    destroy_machine();

    if ( args.emit_base_class )
    {
        fprintf( stderr, "*** producing state machine base header\n" );
        unlink( "pk_state_machine_base.H" );
        fd = open( "pk_state_machine_base.H", O_CREAT | O_WRONLY, 0644 );
        if (write( fd, baseclassH, strlen( baseclassH )) < 0)
            fprintf(stderr, "write base class H failed\n");
        close( fd );

        fprintf( stderr, "*** producing state machine base impl\n" );
        unlink( "pk_state_machine_base.C" );
        fd = open( "pk_state_machine_base.C", O_CREAT | O_WRONLY, 0644 );
        if (write( fd, baseclassC, strlen( baseclassC )) < 0)
            fprintf(stderr, "write base class C failed\n");
        close( fd );
    }

    return 0;
}
Ejemplo n.º 20
0
/**
 * This function executes vertex programs
 */
static GLboolean
run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct vp_stage_data *store = VP_STAGE_DATA(stage);
   struct vertex_buffer *VB = &tnl->vb;
   struct gl_vertex_program *program = ctx->VertexProgram._Current;
   struct gl_program_machine *machine = &store->machine;
   GLuint outputs[VARYING_SLOT_MAX], numOutputs;
   GLuint i, j;

   if (!program)
      return GL_TRUE;

   /* ARB program or vertex shader */
   _mesa_load_state_parameters(ctx, program->Base.Parameters);

   /* make list of outputs to save some time below */
   numOutputs = 0;
   for (i = 0; i < VARYING_SLOT_MAX; i++) {
      if (program->Base.OutputsWritten & BITFIELD64_BIT(i)) {
         outputs[numOutputs++] = i;
      }
   }

   /* Allocate result vectors.  We delay this until now to avoid allocating
    * memory that would never be used if we don't run the software tnl pipeline.
    */
   if (!store->results[0].storage) {
      for (i = 0; i < VARYING_SLOT_MAX; i++) {
         assert(!store->results[i].storage);
         _mesa_vector4f_alloc( &store->results[i], 0, VB->Size, 32 );
         store->results[i].size = 4;
      }
   }

   map_textures(ctx, program);

   for (i = 0; i < VB->Count; i++) {
      GLuint attr;

      init_machine(ctx, machine, tnl->CurInstance);

#if 0
      printf("Input  %d: %f, %f, %f, %f\n", i,
             VB->AttribPtr[0]->data[i][0],
             VB->AttribPtr[0]->data[i][1],
             VB->AttribPtr[0]->data[i][2],
             VB->AttribPtr[0]->data[i][3]);
      printf("   color: %f, %f, %f, %f\n",
             VB->AttribPtr[3]->data[i][0],
             VB->AttribPtr[3]->data[i][1],
             VB->AttribPtr[3]->data[i][2],
             VB->AttribPtr[3]->data[i][3]);
      printf("  normal: %f, %f, %f, %f\n",
             VB->AttribPtr[2]->data[i][0],
             VB->AttribPtr[2]->data[i][1],
             VB->AttribPtr[2]->data[i][2],
             VB->AttribPtr[2]->data[i][3]);
#endif

      /* the vertex array case */
      for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
	 if (program->Base.InputsRead & BITFIELD64_BIT(attr)) {
	    const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data;
	    const GLuint size = VB->AttribPtr[attr]->size;
	    const GLuint stride = VB->AttribPtr[attr]->stride;
	    const GLfloat *data = (GLfloat *) (ptr + stride * i);
#ifdef NAN_CHECK
            check_float(data[0]);
            check_float(data[1]);
            check_float(data[2]);
            check_float(data[3]);
#endif
	    COPY_CLEAN_4V(machine->VertAttribs[attr], size, data);
	 }
      }

      /* execute the program */
      _mesa_execute_program(ctx, &program->Base, machine);

      /* copy the output registers into the VB->attribs arrays */
      for (j = 0; j < numOutputs; j++) {
         const GLuint attr = outputs[j];
#ifdef NAN_CHECK
         check_float(machine->Outputs[attr][0]);
         check_float(machine->Outputs[attr][1]);
         check_float(machine->Outputs[attr][2]);
         check_float(machine->Outputs[attr][3]);
#endif
         COPY_4V(store->results[attr].data[i], machine->Outputs[attr]);
      }

      /* FOGC is a special case.  Fragment shader expects (f,0,0,1) */
      if (program->Base.OutputsWritten & BITFIELD64_BIT(VARYING_SLOT_FOGC)) {
         store->results[VARYING_SLOT_FOGC].data[i][1] = 0.0;
         store->results[VARYING_SLOT_FOGC].data[i][2] = 0.0;
         store->results[VARYING_SLOT_FOGC].data[i][3] = 1.0;
      }
#ifdef NAN_CHECK
      ASSERT(machine->Outputs[0][3] != 0.0F);
#endif
#if 0
      printf("HPOS: %f %f %f %f\n",
             machine->Outputs[0][0], 
             machine->Outputs[0][1], 
             machine->Outputs[0][2], 
             machine->Outputs[0][3]);
#endif
   }

   unmap_textures(ctx, program);

   if (program->IsPositionInvariant) {
      /* We need the exact same transform as in the fixed function path here
       * to guarantee invariance, depending on compiler optimization flags
       * results could be different otherwise.
       */
      VB->ClipPtr = TransformRaw( &store->results[0],
				  &ctx->_ModelProjectMatrix,
				  VB->AttribPtr[0] );

      /* Drivers expect this to be clean to element 4...
       */
      switch (VB->ClipPtr->size) {
      case 1:
	 /* impossible */
      case 2:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 );
	 /* fall-through */
      case 3:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 );
	 /* fall-through */
      case 4:
	 break;
      }
   }
   else {
      /* Setup the VB pointers so that the next pipeline stages get
       * their data from the right place (the program output arrays).
       */
      VB->ClipPtr = &store->results[VARYING_SLOT_POS];
      VB->ClipPtr->size = 4;
      VB->ClipPtr->count = VB->Count;
   }

   VB->AttribPtr[VERT_ATTRIB_COLOR0] = &store->results[VARYING_SLOT_COL0];
   VB->AttribPtr[VERT_ATTRIB_COLOR1] = &store->results[VARYING_SLOT_COL1];
   VB->AttribPtr[VERT_ATTRIB_FOG] = &store->results[VARYING_SLOT_FOGC];
   VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->results[VARYING_SLOT_PSIZ];
   VB->BackfaceColorPtr = &store->results[VARYING_SLOT_BFC0];
   VB->BackfaceSecondaryColorPtr = &store->results[VARYING_SLOT_BFC1];

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]
         = &store->results[VARYING_SLOT_TEX0 + i];
   }

   for (i = 0; i < ctx->Const.MaxVarying; i++) {
      if (program->Base.OutputsWritten & BITFIELD64_BIT(VARYING_SLOT_VAR0 + i)) {
         /* Note: varying results get put into the generic attributes */
	 VB->AttribPtr[VERT_ATTRIB_GENERIC0+i]
            = &store->results[VARYING_SLOT_VAR0 + i];
      }
   }


   /* Perform NDC and cliptest operations:
    */
   return do_ndc_cliptest(ctx, store);
}
Ejemplo n.º 21
0
int main (int argc, char *argv[])
{
#ifdef HW_RVL
  /* initialize DVDX */
  DI_Init();
#endif

  /* initialize hardware */
  gx_video_Init();
  gx_input_Init();
#ifdef HW_DOL
  DVD_Init ();
  dvd_drive_detect();
#endif

  /* initialize FAT devices */
  if (fatInitDefault())
  {
    /* check for default directories */
    DIR_ITER *dir = NULL;

    /* base directory */
    char pathname[MAXPATHLEN];
    sprintf (pathname, DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* SRAM & Savestate files directory */ 
    sprintf (pathname, "%s/saves",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* Snapshot files directory */ 
    sprintf (pathname, "%s/snaps",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);

    /* Cheat files directory */ 
    sprintf (pathname, "%s/cheats",DEFAULT_PATH);
    dir = diropen(pathname);
    if (dir == NULL) mkdir(pathname,S_IRWXU);
    else dirclose(dir);
  }

  /* initialize sound engine */
  gx_audio_Init();

  /* initialize core engine */
  legal();
  config_default();
  history_default();
  init_machine();

  /* run any injected rom */
  if (cart.romsize)
  {
    ARAMFetch((char *)cart.rom, (void *)0x8000, cart.romsize);
    reloadrom (cart.romsize,"INJECT.bin");
    gx_video_Start();
    gx_audio_Start();
    frameticker = 1;
  }
  else
  {
    /* Main Menu */
    ConfigRequested = 1;
  }

  /* initialize GUI engine */
  GUI_Initialize();

#ifdef HW_RVL
  /* Power button callback */
  SYS_SetPowerCallback(Power_Off);
#endif

  /* main emulation loop */
  while (1)
  {
    /* Main Menu request */
    if (ConfigRequested)
    {
      /* stop video & audio */
      gx_audio_Stop();
      gx_video_Stop();

      /* show menu */
      MainMenu ();
      ConfigRequested = 0;

      /* start video & audio */
      gx_audio_Start();
      gx_video_Start();
      frameticker = 1;
    }

    if (frameticker > 1)
    {
      /* skip frame */
      system_frame(1);
      --frameticker;
    }
    else
    {
      while (frameticker < 1)
        usleep(10);

      /* render frame */
      system_frame(0);
      --frameticker;

      /* update video */
      gx_video_Update();
    }

    /* update audio */
    gx_audio_Update();
  }

  return 0;
}
Ejemplo n.º 22
0
int 
main(int argc, char **argv)
{
    extern int game_is_being_shut_down;
    char *p;
    int i = 0;
    struct svalue *ret;
    extern struct svalue catch_value;
    extern void init_cfuns(void);
    struct gdexception exception_frame;

    (void)setlinebuf(stdout);

    parse_args(argc, argv);
    
    const0.type = T_NUMBER; const0.u.number = 0;
    const1.type = T_NUMBER; const1.u.number = 1;
    constempty.type = T_FUNCTION; constempty.u.func = &funcempty;
    funcempty.funtype = FUN_EMPTY;
    catch_value = const0;
    
    /*
     * Check that the definition of EXTRACT_UCHAR() is correct.
     */
    p = (char *)&i;
    *p = -10;
    if (EXTRACT_UCHAR(p) != 0x100 - 10)
    {
	(void)fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n");
	exit(1);
    }
    set_current_time();

#ifdef PROFILE_LPC
    set_profile_timebase(60.0); /* One minute */
#endif

#if RESERVED_SIZE > 0
    reserved_area = malloc(RESERVED_SIZE);
#endif

    init_random();
    init_tasks();
    query_load_av();
    init_num_args();
    init_machine();
    init_cfuns();
    init_hash();

    /*
     * Set up the signal handling.
     */
    init_signals();

    if (chdir(mudlib_path) == -1) {
        (void)fprintf(stderr, "Bad mudlib directory: %s\n", MUD_LIB);
	exit(1);
    }

    if (setjmp(exception_frame.e_context))
    {
	clear_state();
	add_message("Anomaly in the fabric of world space.\n");
    } 
    else
    {
	exception_frame.e_exception = NULL;
	exception_frame.e_catch = 0;
	exception = &exception_frame;
	auto_ob = 0;
	master_ob = 0;
	
	if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL)
	{
	    add_ref(auto_ob, "main");
	    auto_ob->prog->flags |= PRAGMA_RESIDENT;
	}

	get_simul_efun();
	master_ob = load_object("secure/master", 1, 0, 0);
	if (master_ob)
	{
	    /*
	     * Make sure master_ob is never made a dangling pointer.
	     * Look at apply_master_ob() for more details.
	     */
	    add_ref(master_ob, "main");
	    master_ob->prog->flags |= PRAGMA_RESIDENT;
            resolve_master_fkntab();
	    create_object(master_ob);
            load_parse_information();
	    clear_state();
	}
    }
    exception = NULL;
    if (auto_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/auto must be loadable.\n");
	exit(1);
    }
    if (master_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/master must be loadable.\n");
	exit(1);
    }
    set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0));
    
    {
	struct svalue* ret1;

	ret1 = apply_master_ob(M_PREDEF_DEFINES, 0);
	if (ret1 && ret1->type == T_POINTER)
	{
	    int ii;

	    for (ii = 0; ii < ret1->u.vec->size; ii++)
		if (ret1->u.vec->item[ii].type == T_STRING)
		{
                    add_pre_define(ret1->u.vec->item[ii].u.string);
		}
	}
    }

    if (flag != NULL)
    {
        printf("Applying driver flag: %s\n", flag);
        push_string(flag, STRING_MSTRING);
        (void)apply_master_ob(M_FLAG, 1);

        if (game_is_being_shut_down)
        {
            (void)fprintf(stderr, "Shutdown by master object.\n");
            exit(0);
        }
    }

    /*
     * See to it that the mud name is always defined in compiled files
     */
    ret = apply_master_ob(M_GET_MUD_NAME, 0);

    if (ret && ret->type == T_STRING)
    {
	struct lpc_predef_s *tmp;
		
	tmp = (struct lpc_predef_s *)
	    xalloc(sizeof(struct lpc_predef_s));
	if (!tmp) 
	    fatal("xalloc failed\n");
	tmp->flag = string_copy(ret->u.string);
	tmp->next = lpc_predefs;
	lpc_predefs = tmp;
    }

    ret = apply_master_ob(M_GET_VBFC_OBJECT, 0);
    if (ret && ret->type == T_OBJECT)
    {
	vbfc_object = ret->u.ob;
	INCREF(vbfc_object->ref);
    }
    else
	vbfc_object = 0;

    if (game_is_being_shut_down)
	exit(1);

    init_call_out();
    preload_objects(e_flag);
    (void)apply_master_ob(M_FINAL_BOOT, 0);
    
    mainloop();

    return 0;
}
Ejemplo n.º 23
0
int run_game(int game)
{
	int err;

	/* copy some settings into easier-to-handle variables */
	record     = options.record;
	playback   = options.playback;
	mame_debug = options.mame_debug;

	Machine->gamedrv = gamedrv = drivers[game];
	Machine->drv = drv = gamedrv->drv;

	/* copy configuration */
	if (options.color_depth == 16 ||
			(options.color_depth != 8 && (Machine->gamedrv->flags & GAME_REQUIRES_16BIT)))
		Machine->color_depth = 16;
	else
		Machine->color_depth = 8;

	//if (options.vector_width == 0) options.vector_width = 640;
	//if (options.vector_height == 0) options.vector_height = 480;
	if (options.vector_width == 0) options.vector_width = 320;
	if (options.vector_height == 0) options.vector_height = 240;

	Machine->sample_rate = options.samplerate;

	/* get orientation right */
	Machine->orientation = gamedrv->flags & ORIENTATION_MASK;
	Machine->ui_orientation = ROT0;
	if (options.norotate)
		Machine->orientation = ROT0;
	if (options.ror)
	{
		/* if only one of the components is inverted, switch them */
		if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->orientation ^= ROT180;

		Machine->orientation ^= ROT90;

		/* if only one of the components is inverted, switch them */
		if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->ui_orientation ^= ROT180;

		Machine->ui_orientation ^= ROT90;
	}
	if (options.rol)
	{
		/* if only one of the components is inverted, switch them */
		if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->orientation ^= ROT180;

		Machine->orientation ^= ROT270;

		/* if only one of the components is inverted, switch them */
		if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->ui_orientation ^= ROT180;

		Machine->ui_orientation ^= ROT270;
	}
	if (options.flipx)
	{
		Machine->orientation ^= ORIENTATION_FLIP_X;
		Machine->ui_orientation ^= ORIENTATION_FLIP_X;
	}
	if (options.flipy)
	{
		Machine->orientation ^= ORIENTATION_FLIP_Y;
		Machine->ui_orientation ^= ORIENTATION_FLIP_Y;
	}

	set_pixel_functions();

	/* Do the work*/
	err = 1;
	bailing = 0;

	#ifdef MESS
	if (get_filenames())
		return err;
	#endif

	if (osd_init() == 0)
	{
		if (init_machine() == 0)
		{
			if (run_machine() == 0)
				err = 0;
			else if (!bailing)
			{
				bailing = 1;
				printf("Unable to start machine emulation\n");
			}

			shutdown_machine();
		}
		else if (!bailing)
		{
			bailing = 1;
			printf("Unable to initialize machine emulation\n");
		}

		osd_exit();
	}
	else if (!bailing)
	{
		bailing = 1;
		printf ("Unable to initialize system\n");
	}

	return err;
}
Ejemplo n.º 24
0
int main (int argc, char *argv[])
{
#ifdef HW_RVL
  /* initialize DVD device */
  DI_Init();
#endif

  u16 usBetweenFrames;
  long long now, prev;
  
  /* Initialize OGC subsystems */
  ogc_video__init();
  ogc_input__init();
  ogc_audio__init();

#ifdef HW_DOL
  /* Initialize GC DVD interface */
  DVD_Init ();
  dvd_drive_detect();
#endif

#ifdef HW_RVL
  /* Power Button callback */
  SYS_SetPowerCallback(Power_Off);
#endif

  /* Initialize FAT Interface */
  if (fatInitDefault() == true)
  {
    fat_enabled = 1;
  }

  /* Default Config */
  legal();
  set_option_defaults ();
  config_load();
#ifdef HW_RVL
  /* Load SMB Settings */
  loadSettings();
#endif

  /* Restore Recent Files list */
  set_history_defaults();
  history_load();

  /* Initialize Virtual Machine */
  init_machine ();

  /* Show Menu */
  MainMenu();
  ConfigRequested = 0;

  /* Initialize Frame timings */
  frameticker = 0;
  usBetweenFrames = sms.display ? 20000 : 16666;
  prev = gettime();

  /* Emulation Loop */
  while (1)
  {
    /* update inputs */
    ogc_input__update();

    /* Frame synchronization */
    if (gc_pal != sms.display)
    {
      /* use timers */
      now = gettime();
      if (diff_usec(prev, now) > usBetweenFrames)
      {
        /* Frame skipping */
        prev = now;
        system_frame(1);
      }
      else
      {
        /* Delay */
        while (diff_usec(prev, now) < usBetweenFrames) now = gettime();

        /* Render Frame */
        prev = now;
        system_frame(0);
      }
    }
    else
    {
      /* use VSync */
      if (frameticker > 1)
      {
        /* Frame skipping */
        frameticker--;
        system_frame (1);
      }
      else
      {
        /* Delay */
        while (!frameticker) usleep(10);  
        
        system_frame (0);
      }

      frameticker--;
    }

    /* update video & audio */
    ogc_video__update();
    ogc_audio__update();

    /* Check for Menu request */
    if (ConfigRequested)
    {
      /* reset AUDIO */
      ogc_audio__reset();

      /* go to menu */
      MainMenu ();
      ConfigRequested = 0;
      ogc_video__reset();

      /* reset frame timings */
      frameticker = 0;
      usBetweenFrames = sms.display ? 20000 : 16666;
      prev = gettime();
    }
  }
  return 0;
}
Ejemplo n.º 25
0
int 
main(int argc, char **argv)
{
    extern int game_is_being_shut_down;
    int i, new_mudlib = 0;
    char *p;
    struct svalue *ret;
    extern struct svalue catch_value;
    extern void init_cfuns(void);
    struct gdexception exception_frame;

    (void)setlinebuf(stdout);

    const0.type = T_NUMBER; const0.u.number = 0;
    const1.type = T_NUMBER; const1.u.number = 1;
    constempty.type = T_FUNCTION; constempty.u.func = &funcempty;
    funcempty.funtype = FUN_EMPTY;
    catch_value = const0;
    
    /*
     * Check that the definition of EXTRACT_UCHAR() is correct.
     */
    p = (char *)&i;
    *p = -10;
    if (EXTRACT_UCHAR(p) != 0x100 - 10)
    {
	(void)fprintf(stderr, "Bad definition of EXTRACT_UCHAR() in config.h.\n");
	exit(1);
    }
    set_current_time();
#ifdef PROFILE_LPC
    set_profile_timebase(60.0); /* One minute */
#endif

#ifdef DRAND48
    srand48((long)current_time);
#else
#ifdef RANDOM
    srandom(current_time);
#else
#error No random generator specified!\n
#endif /* RANDOM */
#endif /* DRAND48 */

#if RESERVED_SIZE > 0
    reserved_area = malloc(RESERVED_SIZE);
#endif
    init_tasks();
    query_load_av();
    init_num_args();
    init_machine();
    init_cfuns();

    /*
     * Set up the signal handling.
     */
    init_signals();

    /*
     * The flags are parsed twice !
     * The first time, we only search for the -m flag, which specifies
     * another mudlib, and the D-flags, so that they will be available
     * when compiling master.c.
     */
    for (i = 1; i < argc; i++)
    {
	if (atoi(argv[i]))
	    port_number = atoi(argv[i]);
	else if (argv[i][0] != '-')
	    continue;
	switch(argv[i][1])
	{
	case 'D':
	    if (argv[i][2]) { /* Amylaar : allow flags to be passed down to
				 the LPC preprocessor */
		struct lpc_predef_s *tmp;
		
		tmp = (struct lpc_predef_s *)
		    xalloc(sizeof(struct lpc_predef_s));
		if (!tmp)
		    fatal("xalloc failed\n");
		tmp->flag = string_copy(argv[i]+2);
		tmp->next = lpc_predefs;
		lpc_predefs = tmp;
		continue;
	    }
	    (void)fprintf(stderr, "Illegal flag syntax: %s\n", argv[i]);
	    exit(1);
	    /* NOTREACHED */
	case 'N':
	    no_ip_demon++; continue;
	case 'm':
	    if (chdir(argv[i]+2) == -1)
	    {
	        (void)fprintf(stderr, "Bad mudlib directory: %s\n", argv[i]+2);
		exit(1);
	    }
	    new_mudlib = 1;
	    break;
	}
    }

    if (!new_mudlib && chdir(MUD_LIB) == -1) {
        (void)fprintf(stderr, "Bad mudlib directory: %s\n", MUD_LIB);
	exit(1);
    }

    if (setjmp(exception_frame.e_context))
    {
	clear_state();
	add_message("Anomaly in the fabric of world space.\n");
    } 
    else
    {
	exception_frame.e_exception = NULL;
	exception_frame.e_catch = 0;
	exception = &exception_frame;
	auto_ob = 0;
	master_ob = 0;
	
	if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL)
	{
	    add_ref(auto_ob, "main");
	    auto_ob->prog->flags |= PRAGMA_RESIDENT;
	}

	get_simul_efun();
	master_ob = load_object("secure/master", 1, 0, 0);
	if (master_ob)
	{
	    /*
	     * Make sure master_ob is never made a dangling pointer.
	     * Look at apply_master_ob() for more details.
	     */
	    add_ref(master_ob, "main");
	    master_ob->prog->flags |= PRAGMA_RESIDENT;
            resolve_master_fkntab();
	    create_object(master_ob);
            load_parse_information();
	    clear_state();
	}
    }
    exception = NULL;
    if (auto_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/auto must be loadable.\n");
	exit(1);
    }
    if (master_ob == 0) 
    {
	(void)fprintf(stderr, "The file secure/master must be loadable.\n");
	exit(1);
    }
    set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0));
    {
	struct svalue* ret1;

	ret1 = apply_master_ob(M_PREDEF_DEFINES, 0);
	if (ret1 && ret1->type == T_POINTER)
	{
	    int ii;
	    struct lpc_predef_s *tmp;

	    for (ii = 0; ii < ret1->u.vec->size; ii++)
		if (ret1->u.vec->item[ii].type == T_STRING)
		{
		    tmp = (struct lpc_predef_s *)
			xalloc(sizeof(struct lpc_predef_s));
		    tmp->flag = string_copy(ret1->u.vec->item[ii].u.string);
		    tmp->next = lpc_predefs;
		    lpc_predefs = tmp;
		}
	}
    }
    for (i = 1; i < argc; i++)
    {
	if (atoi(argv[i]))
	    ;
	else if (argv[i][0] != '-')
	{
	    (void)fprintf(stderr, "Bad argument %s\n", argv[i]);
	    exit(1);
	}
	else 
	{
	    /*
	     * Look at flags. -m has already been tested.
	     */
	    switch(argv[i][1])
	    {
	    case 'f':
		push_string(argv[i]+2, STRING_MSTRING);
		(void)apply_master_ob(M_FLAG, 1);
		if (game_is_being_shut_down)
		{
		    (void)fprintf(stderr, "Shutdown by master object.\n");
		    exit(0);
		}
		continue;
	    case 'e':
		e_flag++; continue;
	    case 'O':
		warnobsoleteflag++; continue;
	    case 'D':
		continue;
	    case 'N':
		continue;
	    case 'm':
		continue;
	    case 'd':
		d_flag = atoi(argv[i] + 2);
		continue;
	    case 'c':
		comp_flag++; continue;
	    case 'l':
		unlimited++;
		continue;
	    case 't':
		t_flag++; continue;
	    case 'S':
		s_flag++; 
		mudstatus_set(1, -1, -1); /* Statistics, default limits */
		continue;
	    case 'u':
#ifdef CATCH_UDP_PORT
		udp_port = atoi (&argv[i][2]);
#endif
		continue;
	    case 'p':
#ifdef SERVICE_PORT
		service_port = atoi (&argv[i][2]);
#endif
		continue;
	    case 'y':
#ifdef YYDEBUG
		yydebug = 1;
#endif
		continue;
	    default:
		(void)fprintf(stderr, "Unknown flag: %s\n", argv[i]);
		exit(1);
	    }
	}
    }

    /*
     * See to it that the mud name is always defined in compiled files
     */
    ret = apply_master_ob(M_GET_MUD_NAME, 0);

    if (ret && ret->type == T_STRING)
    {
	struct lpc_predef_s *tmp;
		
	tmp = (struct lpc_predef_s *)
	    xalloc(sizeof(struct lpc_predef_s));
	if (!tmp) 
	    fatal("xalloc failed\n");
	tmp->flag = string_copy(ret->u.string);
	tmp->next = lpc_predefs;
	lpc_predefs = tmp;
    }

    ret = apply_master_ob(M_GET_VBFC_OBJECT, 0);
    if (ret && ret->type == T_OBJECT)
    {
	vbfc_object = ret->u.ob;
	INCREF(vbfc_object->ref);
    }
    else
	vbfc_object = 0;

    if (game_is_being_shut_down)
	exit(1);

    if (!t_flag)
	init_call_out();

    preload_objects(e_flag);
    (void)apply_master_ob(M_FINAL_BOOT, 0);
    

    mainloop();
    /* backend(); */

    return 0;
}
Ejemplo n.º 26
0
int run_game(int game)
{
	running_machine *machine;
	int error = MAMERR_NONE;
	mame_private *mame;
	callback_item *cb;

	/* create the machine structure and driver */
	machine = create_machine(game);
	mame = machine->mame_data;

	/* looooong term: remove this */
	Machine = machine;

	/* start in the "pre-init phase" */
	mame->current_phase = MAME_PHASE_PREINIT;

	/* perform validity checks before anything else */
	if (mame_validitychecks(game) != 0)
		return MAMERR_FAILED_VALIDITY;

	/* loop across multiple hard resets */
	mame->exit_pending = FALSE;
	while (error == 0 && !mame->exit_pending)
	{
		init_resource_tracking();
		add_free_resources_callback(timer_free);
		add_free_resources_callback(state_save_free);

		/* use setjmp/longjmp for deep error recovery */
		mame->fatal_error_jmpbuf_valid = TRUE;
		error = setjmp(mame->fatal_error_jmpbuf);
		if (error == 0)
		{
			int settingsloaded;

			/* move to the init phase */
			mame->current_phase = MAME_PHASE_INIT;

			/* start tracking resources for real */
			begin_resource_tracking();

			/* if we have a logfile, set up the callback */
			mame->logerror_callback_list = NULL;
			if (options.logfile)
				add_logerror_callback(machine, logfile_callback);

			/* then finish setting up our local machine */
			init_machine(machine);

			/* load the configuration settings and NVRAM */
			settingsloaded = config_load_settings();
			nvram_load();

			/* display the startup screens */
			ui_display_startup_screens(!settingsloaded && !options.skip_disclaimer, !options.skip_warnings, !options.skip_gameinfo);

			/* ensure we don't show the opening screens on a reset */
			options.skip_disclaimer = options.skip_warnings = options.skip_gameinfo = TRUE;

			/* start resource tracking; note that soft_reset assumes it can */
			/* call end_resource_tracking followed by begin_resource_tracking */
			/* to clear out resources allocated between resets */
			begin_resource_tracking();

			/* perform a soft reset -- this takes us to the running phase */
			soft_reset(0);

			/* run the CPUs until a reset or exit */
			mame->hard_reset_pending = FALSE;
			while ((!mame->hard_reset_pending && !mame->exit_pending) || mame->saveload_pending_file != NULL)
			{
				profiler_mark(PROFILER_EXTRA);

				/* execute CPUs if not paused */
				if (!mame->paused)
					cpuexec_timeslice();

				/* otherwise, just pump video updates through */
				else
					video_frame_update();

				/* handle save/load */
				if (mame->saveload_schedule_callback)
					(*mame->saveload_schedule_callback)(machine);

				profiler_mark(PROFILER_END);
			}

			/* and out via the exit phase */
			mame->current_phase = MAME_PHASE_EXIT;

			/* stop tracking resources at this level */
			end_resource_tracking();

			/* save the NVRAM and configuration */
			nvram_save();
			config_save_settings();
		}
		mame->fatal_error_jmpbuf_valid = FALSE;

		/* call all exit callbacks registered */
		for (cb = mame->exit_callback_list; cb; cb = cb->next)
			(*cb->func.exit)(machine);

		/* close all inner resource tracking */
		exit_resource_tracking();

		/* free our callback lists */
		free_callback_list(&mame->exit_callback_list);
		free_callback_list(&mame->reset_callback_list);
		free_callback_list(&mame->pause_callback_list);
	}

	/* destroy the machine */
	destroy_machine(machine);

	/* return an error */
	return error;
}
Ejemplo n.º 27
0
/**
 * This function executes vertex programs
 */
static GLboolean
run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct vp_stage_data *store = VP_STAGE_DATA(stage);
   struct vertex_buffer *VB = &tnl->vb;
   struct gl_vertex_program *program = ctx->VertexProgram._Current;
   struct gl_program_machine machine;
   GLuint outputs[VERT_RESULT_MAX], numOutputs;
   GLuint i, j;

   if (!program)
      return GL_TRUE;

   if (program->IsNVProgram) {
      _mesa_load_tracked_matrices(ctx);
   }
   else {
      /* ARB program or vertex shader */
      _mesa_load_state_parameters(ctx, program->Base.Parameters);
   }

   numOutputs = 0;
   for (i = 0; i < VERT_RESULT_MAX; i++) {
      if (program->Base.OutputsWritten & (1 << i)) {
         outputs[numOutputs++] = i;
      }
   }

   for (i = 0; i < VB->Count; i++) {
      GLuint attr;

      init_machine(ctx, &machine);

#if 0
      printf("Input  %d: %f, %f, %f, %f\n", i,
             VB->AttribPtr[0]->data[i][0],
             VB->AttribPtr[0]->data[i][1],
             VB->AttribPtr[0]->data[i][2],
             VB->AttribPtr[0]->data[i][3]);
      printf("   color: %f, %f, %f, %f\n",
             VB->AttribPtr[3]->data[i][0],
             VB->AttribPtr[3]->data[i][1],
             VB->AttribPtr[3]->data[i][2],
             VB->AttribPtr[3]->data[i][3]);
      printf("  normal: %f, %f, %f, %f\n",
             VB->AttribPtr[2]->data[i][0],
             VB->AttribPtr[2]->data[i][1],
             VB->AttribPtr[2]->data[i][2],
             VB->AttribPtr[2]->data[i][3]);
#endif

      /* the vertex array case */
      for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
	 if (program->Base.InputsRead & (1 << attr)) {
	    const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data;
	    const GLuint size = VB->AttribPtr[attr]->size;
	    const GLuint stride = VB->AttribPtr[attr]->stride;
	    const GLfloat *data = (GLfloat *) (ptr + stride * i);
	    COPY_CLEAN_4V(machine.VertAttribs[attr], size, data);
	 }
      }

      /* execute the program */
      _mesa_execute_program(ctx, &program->Base, &machine);

      /* copy the output registers into the VB->attribs arrays */
      for (j = 0; j < numOutputs; j++) {
         const GLuint attr = outputs[j];
         COPY_4V(store->results[attr].data[i], machine.Outputs[attr]);
      }
#if 0
      printf("HPOS: %f %f %f %f\n",
             machine.Outputs[0][0], 
             machine.Outputs[0][1], 
             machine.Outputs[0][2], 
             machine.Outputs[0][3]);
#endif
   }

   /* Fixup fog and point size results if needed */
   if (program->IsNVProgram) {
      if (ctx->Fog.Enabled &&
          (program->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) == 0) {
         for (i = 0; i < VB->Count; i++) {
            store->results[VERT_RESULT_FOGC].data[i][0] = 1.0;
         }
      }

      if (ctx->VertexProgram.PointSizeEnabled &&
          (program->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) == 0) {
         for (i = 0; i < VB->Count; i++) {
            store->results[VERT_RESULT_PSIZ].data[i][0] = ctx->Point.Size;
         }
      }
   }

   /* Setup the VB pointers so that the next pipeline stages get
    * their data from the right place (the program output arrays).
    */
   VB->ClipPtr = &store->results[VERT_RESULT_HPOS];
   VB->ClipPtr->size = 4;
   VB->ClipPtr->count = VB->Count;
   VB->ColorPtr[0] = &store->results[VERT_RESULT_COL0];
   VB->ColorPtr[1] = &store->results[VERT_RESULT_BFC0];
   VB->SecondaryColorPtr[0] = &store->results[VERT_RESULT_COL1];
   VB->SecondaryColorPtr[1] = &store->results[VERT_RESULT_BFC1];
   VB->FogCoordPtr = &store->results[VERT_RESULT_FOGC];

   VB->AttribPtr[VERT_ATTRIB_COLOR0] = &store->results[VERT_RESULT_COL0];
   VB->AttribPtr[VERT_ATTRIB_COLOR1] = &store->results[VERT_RESULT_COL1];
   VB->AttribPtr[VERT_ATTRIB_FOG] = &store->results[VERT_RESULT_FOGC];
   VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->results[VERT_RESULT_PSIZ];

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      VB->TexCoordPtr[i] = 
      VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]
         = &store->results[VERT_RESULT_TEX0 + i];
   }

   for (i = 0; i < ctx->Const.MaxVarying; i++) {
      if (program->Base.OutputsWritten & (1 << (VERT_RESULT_VAR0 + i))) {
         /* Note: varying results get put into the generic attributes */
	 VB->AttribPtr[VERT_ATTRIB_GENERIC0+i]
            = &store->results[VERT_RESULT_VAR0 + i];
      }
   }

   /* Cliptest and perspective divide.  Clip functions must clear
    * the clipmask.
    */
   store->ormask = 0;
   store->andmask = CLIP_FRUSTUM_BITS;

   if (tnl->NeedNdcCoords) {
      VB->NdcPtr =
         _mesa_clip_tab[VB->ClipPtr->size]( VB->ClipPtr,
                                            &store->ndcCoords,
                                            store->clipmask,
                                            &store->ormask,
                                            &store->andmask );
   }
   else {
      VB->NdcPtr = NULL;
      _mesa_clip_np_tab[VB->ClipPtr->size]( VB->ClipPtr,
                                            NULL,
                                            store->clipmask,
                                            &store->ormask,
                                            &store->andmask );
   }

   if (store->andmask)  /* All vertices are outside the frustum */
      return GL_FALSE;


   /* This is where we'd do clip testing against the user-defined
    * clipping planes, but they're not supported by vertex programs.
    */

   VB->ClipOrMask = store->ormask;
   VB->ClipMask = store->clipmask;

   return GL_TRUE;
}
Ejemplo n.º 28
0
/***************************************************************************
 *  M A I N
 *
 ***************************************************************************/
int main (int argc, char *argv[])
{
 #ifdef HW_RVL
  /* enable 64-byte fetch mode for L2 cache */
  L2Enhance();
  
  /* initialize DI interface */
  DI_UseCache(0);
  DI_Init();

  sprintf(osd_version, "%s (IOS %d)", VERSION, IOS_GetVersion());
#else
  sprintf(osd_version, "%s (GCN)", VERSION);
#endif

  /* initialize video engine */
  gx_video_Init();

#ifndef HW_RVL
  /* initialize DVD interface */
  DVD_Init();
#endif

  /* initialize input engine */
  gx_input_Init();

  /* initialize FAT devices */
  int retry = 0;
  int fatMounted = 0;

  /* try to mount FAT devices during 3 seconds */
  while (!fatMounted && (retry < 12))
  {
    fatMounted = fatInitDefault();
    usleep(250000);
    retry++;
  }

  if (fatMounted)
  {
    /* base directory */
    char pathname[MAXPATHLEN];
    sprintf (pathname, DEFAULT_PATH);
    DIR *dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);

    /* default SRAM & Savestate files directories */ 
    sprintf (pathname, "%s/saves",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/saves/md",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/saves/ms",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/saves/gg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/saves/sg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/saves/cd",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);

    /* default Snapshot files directories */ 
    sprintf (pathname, "%s/snaps",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/snaps/md",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/snaps/ms",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/snaps/gg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/snaps/sg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/snaps/cd",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);

    /* default Cheat files directories */ 
    sprintf (pathname, "%s/cheats",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/cheats/md",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/cheats/ms",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/cheats/gg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/cheats/sg",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
    sprintf (pathname, "%s/cheats/cd",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);

    /* default BIOS ROM files directories */ 
    sprintf (pathname, "%s/bios",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);

    /* default LOCK-ON ROM files directories */ 
    sprintf (pathname, "%s/lock-on",DEFAULT_PATH);
    dir = opendir(pathname);
    if (dir) closedir(dir);
    else mkdir(pathname,S_IRWXU);
  }

  /* initialize sound engine */
  gx_audio_Init();

  /* initialize genesis plus core */
  history_default();
  config_default();
  init_machine();

  /* auto-load last ROM file */
  if (config.autoload)
  {
    SILENT = 1;
    if (OpenDirectory(TYPE_RECENT, -1))
    {
      if (LoadFile(0))
      {
        reloadrom();
        gx_video_Start();
        gx_audio_Start();
        ConfigRequested = 0;
      }
    }
    SILENT = 0;
  }

  /* show disclaimer */
  if (ConfigRequested)
  {
    legal();
  }

#ifdef HW_RVL
  /* power button callback */
  SYS_SetPowerCallback(PowerOff_cb);
#endif

  /* reset button callback */
  SYS_SetResetCallback(Reset_cb);

  /* main emulation loop */
  run_emulation();

  /* we should never return anyway */
  return 0;
}
Ejemplo n.º 29
0
int main(int argc, char *argv[])
{
#ifdef PSL9
	MachineConfig machine;
	char *cacheline0, *cacheline1, *name;
	uint64_t wed;
	unsigned seed;
	int i, quadrant, byte, opt, option_index;
	int response;
	int context, machine_number;

	name = strrchr(argv[0], '/');
	if (name)
		name++;
	else
		name = argv[0];

	static struct option long_options[] = {
		{"help",	no_argument,		0,		'h'},
		{"seed",	required_argument,	0,		's'},
		{NULL, 0, 0, 0}
	};

	option_index = 0;
	seed = time(NULL);
	while ((opt = getopt_long (argc, argv, "hs:",
				   long_options, &option_index)) >= 0) {
		switch (opt)
		{
		case 0:
			break;
		case 's':
			seed = strtoul(optarg, NULL, 0);
			break;
		case 'h':
		default:
			usage(name);
			return 0;
		}
	}

	// Seed random number generator
	srand(seed);
	printf("%s: seed=%d\n", name, seed);

	// find first AFU found
	struct cxl_afu_h *afu_h, *afu_m, *afu_s;
	afu_m = afu_s = NULL;
	
        afu_h = cxl_afu_next(NULL);
	if (!afu_h) {
		fprintf(stderr, "\nNo AFU found!\n\n");
		goto done;
	}
	
        
        // afu master 
	afu_m = cxl_afu_open_h(afu_h, CXL_VIEW_MASTER);
	if (!afu_m) {
		perror("cxl_afu_open_h for master");
		goto done;
	}

	// Set WED to random value
	wed = rand();
	wed <<= 32;
	wed |= rand();

	// Start AFU for master
	printf("Attach AFU master\n");
	if (cxl_afu_attach(afu_m, wed) < 0) {
            perror("FAILED:cxl_afu_attach for master");
		goto done;
        }

	printf("wed = 0x%"PRIx64"\n", wed);

	// Map AFU MMIO registers
	printf("Mapping AFU master registers...\n");
	if ((cxl_mmio_map(afu_m, CXL_MMIO_BIG_ENDIAN)) < 0) {
		perror("cxl_mmio_map for master");
		goto done;

	}
	printf("End AFU master mmio map\n");

	context = cxl_afu_get_process_element(afu_m);

	printf("Master context = %d\n", context);
	// Allocate aligned memory for two cachelines
	if (posix_memalign((void **)&cacheline0, CACHELINE_BYTES, CACHELINE_BYTES) != 0) {
		perror("FAILED:posix_memalign");
		goto done;
	}
	if (posix_memalign((void **)&cacheline1, CACHELINE_BYTES, CACHELINE_BYTES) != 0) {
		perror("FAILED:posix_memalign");
		goto done;
	}

	// Pollute first cacheline with random values
	printf("CACHELINE0 = 0x");
	for (i = 0; i < CACHELINE_BYTES; i++)
	{
		cacheline0[i] = rand();
		printf("%02x", cacheline0[i]);
	}
	printf("\n");
	// Initialize machine configuration
	printf("initialize machine\n");
	init_machine(&machine);
	printf("End init machine\n");

	// Use AFU Machine 0 to read the first cacheline from memory to AFU
	printf("Configure, enable and run machine\n");
	if ((response = config_enable_and_run_machine(afu_m, &machine, 0, context, PSL_COMMAND_XLAT_RD_P0, CACHELINE_BYTES, 0, 0, (uint64_t)cacheline0, CACHELINE_BYTES, DIRECTED_M)) < 0)
	{
		printf("FAILED:config_enable_and_run_machine for master XLAT_RD response = %d\n", response);
		goto done;
	}
	printf("End configure enable and run machine for XLAT_RD\n");
	// Check for valid response
	if (response != PSL_RESPONSE_DONE)
	{
		printf("FAILED: Unexpected response code 0x%x\n", response);
		goto done;
	}

	printf("Completed cacheline read\n");

	// Use AFU Machine 0 to write the data to the second cacheline
	if ((response = config_enable_and_run_machine(afu_m, &machine, 0, context, PSL_COMMAND_XLAT_WR_P0, CACHELINE_BYTES, 0, 0, (uint64_t)cacheline1, CACHELINE_BYTES, DIRECTED_M)) < 0)
	{
		printf("FAILED:config_enable_and_run_machine for master XLAT_WR response = %d\n", response);
		goto done;
	}
	printf("End configure enable and run machine for XLAT WR\n");
	// Check for valid response
	if (response != PSL_RESPONSE_DONE)
	{
		printf("FAILED: Unexpected response code 0x%x\n", response);
		goto done;
	}

	// Test if copy from cacheline0 to cacheline1 was successful
	if (memcmp(cacheline0,cacheline1, CACHELINE_BYTES) != 0) {
		printf("FAILED:memcmp\n");
		for (quadrant = 0; quadrant < 4; quadrant++) {
			printf("DEBUG: Expected  Q%d 0x", quadrant);
			for (byte = 0; byte < CACHELINE_BYTES /4; byte++) {
				printf("%02x", cacheline0[byte+(quadrant*32)]);
			}
			printf("\n");
		}
		for (quadrant = 0; quadrant < 4; quadrant++) {
			printf("DEBUG: Actual  Q%d 0x", quadrant);
			for (byte = 0; byte < CACHELINE_BYTES / 4; byte++) {
				printf("%02x", cacheline1[byte+(quadrant*32)]);
			}
			printf("\n");
		}
		goto done;
	}

	printf("Master AFU: PASSED\n");
        
        // afu slave
        // find next afu
        afu_h = cxl_afu_next(NULL);
	if (!afu_h) {
		fprintf(stderr, "\nNo AFU found!\n\n");
		goto done;
	}
	afu_s = cxl_afu_open_h(afu_h, CXL_VIEW_SLAVE);
	if (!afu_s) {
		perror("cxl_afu_open_h for slave");
		goto done;
	}

	// Set WED to random value
	wed = rand();
	wed <<= 32;
	wed |= rand();
	// Start AFU for slave
	if (cxl_afu_attach(afu_s, wed) < 0) {
            perror("FAILED:cxl_afu_attach for slave");
		goto done;
        }

	// Map AFU MMIO registers
	printf("Mapping AFU slave registers...\n");
	if ((cxl_mmio_map(afu_s, CXL_MMIO_BIG_ENDIAN)) < 0) {
		perror("cxl_mmio_map for slave");
		goto done;
	}
	printf("End AFU slave mmio map\n");

	context = cxl_afu_get_process_element(afu_s);
	printf("Slave context = %d\n", context);

	machine_number = 20;

        // Allocate aligned memory for two cachelines
	if (posix_memalign((void **)&cacheline0, CACHELINE_BYTES, CACHELINE_BYTES) != 0) {
		perror("FAILED:posix_memalign");
		goto done;
	}
	if (posix_memalign((void **)&cacheline1, CACHELINE_BYTES, CACHELINE_BYTES) != 0) {
		perror("FAILED:posix_memalign");
		goto done;
	}

	// Pollute first cacheline with random values
	for (i = 0; i < CACHELINE_BYTES; i++)
		cacheline0[i] = rand();

	// Initialize machine configuration
	//init_machine(&machine);

	// Use AFU Machine 1 to read the first cacheline from memory to AFU
	printf("Start config enable and run machine for slave\n");
	if ((response = config_enable_and_run_machine(afu_s, &machine, machine_number, context, PSL_COMMAND_XLAT_RD_P0, CACHELINE_BYTES, 0, 0, (uint64_t)cacheline0, CACHELINE_BYTES, DIRECTED)) < 0)
	{
		printf("FAILED:config_enable_and_run_machine for slave");
		goto done;
	}
	printf("End config enable and run machine for slave\n");
	// Check for valid response
	if (response != PSL_RESPONSE_DONE)
	{
		printf("FAILED: Unexpected response code 0x%x\n", response);
		goto done;
	}

	printf("Completed cacheline read for slave\n");

	// Use AFU Machine 1 to write the data to the second cacheline
	if ((response = config_enable_and_run_machine(afu_s, &machine, machine_number, context, PSL_COMMAND_XLAT_WR_P0, CACHELINE_BYTES, 0, 0, (uint64_t)cacheline1, CACHELINE_BYTES, DIRECTED)) < 0)
	{
		printf("FAILED:config_enable_and_run_machine for slave");
		goto done;
	}

	// Check for valid response
	if (response != PSL_RESPONSE_DONE)
	{
		printf("FAILED: Unexpected response code 0x%x\n", response);
		goto done;
	}

	// Test if copy from cacheline0 to cacheline1 was successful
	if (memcmp(cacheline0,cacheline1, CACHELINE_BYTES) != 0) {
		printf("FAILED:memcmp\n");
		for (quadrant = 0; quadrant < 4; quadrant++) {
			printf("DEBUG: Expected  Q%d 0x", quadrant);
			for (byte = 0; byte < CACHELINE_BYTES /4; byte++) {
				printf("%02x", cacheline0[byte+(quadrant*32)]);
			}
			printf("\n");
		}
		for (quadrant = 0; quadrant < 4; quadrant++) {
			printf("DEBUG: Actual  Q%d 0x", quadrant);
			for (byte = 0; byte < CACHELINE_BYTES / 4; byte++) {
				printf("%02x", cacheline1[byte+(quadrant*32)]);
			}
			printf("\n");
		}
		goto done;
	}

	printf("Slave AFU: PASSED\n");
        
done:
        // unmap and free slave afu 
        if (afu_s) {
            cxl_mmio_unmap(afu_s);
            cxl_afu_free(afu_s);
        }
        // unmap and free master afu
	if (afu_m) {
		// Unmap AFU MMIO registers
		cxl_mmio_unmap(afu_m);

		// Free AFU
		cxl_afu_free(afu_m);
	}
       
#endif
	return 0;
}
/**
 * This function executes vertex programs
 */
static GLboolean
run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct vp_stage_data *store = VP_STAGE_DATA(stage);
   struct vertex_buffer *VB = &tnl->vb;
   struct gl_vertex_program *program = ctx->VertexProgram._Current;
   struct gl_program_machine machine;
   GLuint outputs[VERT_RESULT_MAX], numOutputs;
   GLuint i, j;

   if (!program)
      return GL_TRUE;

   if (program->IsNVProgram) {
      _mesa_load_tracked_matrices(ctx);
   }
   else {
      /* ARB program or vertex shader */
      _mesa_load_state_parameters(ctx, program->Base.Parameters);
   }

   /* make list of outputs to save some time below */
   numOutputs = 0;
   for (i = 0; i < VERT_RESULT_MAX; i++) {
      if (program->Base.OutputsWritten & (1 << i)) {
         outputs[numOutputs++] = i;
      }
   }

   map_textures(ctx, program);

   for (i = 0; i < VB->Count; i++) {
      GLuint attr;

      init_machine(ctx, &machine);

#if 0
      printf("Input  %d: %f, %f, %f, %f\n", i,
             VB->AttribPtr[0]->data[i][0],
             VB->AttribPtr[0]->data[i][1],
             VB->AttribPtr[0]->data[i][2],
             VB->AttribPtr[0]->data[i][3]);
      printf("   color: %f, %f, %f, %f\n",
             VB->AttribPtr[3]->data[i][0],
             VB->AttribPtr[3]->data[i][1],
             VB->AttribPtr[3]->data[i][2],
             VB->AttribPtr[3]->data[i][3]);
      printf("  normal: %f, %f, %f, %f\n",
             VB->AttribPtr[2]->data[i][0],
             VB->AttribPtr[2]->data[i][1],
             VB->AttribPtr[2]->data[i][2],
             VB->AttribPtr[2]->data[i][3]);
#endif

      /* the vertex array case */
      for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
	 if (program->Base.InputsRead & (1 << attr)) {
	    const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data;
	    const GLuint size = VB->AttribPtr[attr]->size;
	    const GLuint stride = VB->AttribPtr[attr]->stride;
	    const GLfloat *data = (GLfloat *) (ptr + stride * i);
	    COPY_CLEAN_4V(machine.VertAttribs[attr], size, data);
	 }
      }

      /* execute the program */
      _mesa_execute_program(ctx, &program->Base, &machine);

      /* copy the output registers into the VB->attribs arrays */
      for (j = 0; j < numOutputs; j++) {
         const GLuint attr = outputs[j];
         COPY_4V(store->results[attr].data[i], machine.Outputs[attr]);
      }
#if 0
      printf("HPOS: %f %f %f %f\n",
             machine.Outputs[0][0], 
             machine.Outputs[0][1], 
             machine.Outputs[0][2], 
             machine.Outputs[0][3]);
#endif
   }

   unmap_textures(ctx, program);

   /* Fixup fog and point size results if needed */
   if (program->IsNVProgram) {
      if (ctx->Fog.Enabled &&
          (program->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) == 0) {
         for (i = 0; i < VB->Count; i++) {
            store->results[VERT_RESULT_FOGC].data[i][0] = 1.0;
         }
      }

      if (ctx->VertexProgram.PointSizeEnabled &&
          (program->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) == 0) {
         for (i = 0; i < VB->Count; i++) {
            store->results[VERT_RESULT_PSIZ].data[i][0] = ctx->Point.Size;
         }
      }
   }

   if (program->IsPositionInvariant) {
      /* We need the exact same transform as in the fixed function path here
       * to guarantee invariance, depending on compiler optimization flags
       * results could be different otherwise.
       */
      VB->ClipPtr = TransformRaw( &store->results[0],
				  &ctx->_ModelProjectMatrix,
				  VB->AttribPtr[0] );

      /* Drivers expect this to be clean to element 4...
       */
      switch (VB->ClipPtr->size) {
      case 1:
	 /* impossible */
      case 2:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 );
	 /* fall-through */
      case 3:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 );
	 /* fall-through */
      case 4:
	 break;
      }
   }
   else {
      /* Setup the VB pointers so that the next pipeline stages get
       * their data from the right place (the program output arrays).
       */
      VB->ClipPtr = &store->results[VERT_RESULT_HPOS];
      VB->ClipPtr->size = 4;
      VB->ClipPtr->count = VB->Count;
   }

   VB->ColorPtr[0] = &store->results[VERT_RESULT_COL0];
   VB->ColorPtr[1] = &store->results[VERT_RESULT_BFC0];
   VB->SecondaryColorPtr[0] = &store->results[VERT_RESULT_COL1];
   VB->SecondaryColorPtr[1] = &store->results[VERT_RESULT_BFC1];
   VB->FogCoordPtr = &store->results[VERT_RESULT_FOGC];

   VB->AttribPtr[VERT_ATTRIB_COLOR0] = &store->results[VERT_RESULT_COL0];
   VB->AttribPtr[VERT_ATTRIB_COLOR1] = &store->results[VERT_RESULT_COL1];
   VB->AttribPtr[VERT_ATTRIB_FOG] = &store->results[VERT_RESULT_FOGC];
   VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->results[VERT_RESULT_PSIZ];

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      VB->TexCoordPtr[i] = 
      VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]
         = &store->results[VERT_RESULT_TEX0 + i];
   }

   for (i = 0; i < ctx->Const.MaxVarying; i++) {
      if (program->Base.OutputsWritten & (1 << (VERT_RESULT_VAR0 + i))) {
         /* Note: varying results get put into the generic attributes */
	 VB->AttribPtr[VERT_ATTRIB_GENERIC0+i]
            = &store->results[VERT_RESULT_VAR0 + i];
      }
   }


   /* Perform NDC and cliptest operations:
    */
   return do_ndc_cliptest(ctx, store);
}