예제 #1
0
파일: devuart.c 프로젝트: 8l/inferno
static int
uartstat(Chan *c, uchar *dp, int n)
{
	if(NETTYPE(c->qid.path) == Ndataqid)
		setlength(NETID(c->qid.path));
	return devstat(c, dp, n, uartdir, ndir, devgen);
}
예제 #2
0
int32 psf_command(int32 command, int32 parameter)
{
    union cpuinfo mipsinfo;
    uint32 lengthMS, fadeMS;

    switch (command)
    {
    case COMMAND_RESTART:
        SPUclose();

        memcpy(psx_ram, initial_ram, 2*1024*1024);
        memcpy(psx_scratch, initial_scratch, 0x400);

        mips_init();
        mips_reset(NULL);
        psx_hw_init();
        SPUinit();
        SPUopen();

        lengthMS = psfTimeToMS(c->inf_length);
        fadeMS = psfTimeToMS(c->inf_fade);

        if (lengthMS == 0)
        {
            lengthMS = ~0;
        }
        setlength(lengthMS, fadeMS);

        mipsinfo.i = initialPC;
        mips_set_info(CPUINFO_INT_PC, &mipsinfo);
        mipsinfo.i = initialSP;
        mips_set_info(CPUINFO_INT_REGISTER + MIPS_R29, &mipsinfo);
        mips_set_info(CPUINFO_INT_REGISTER + MIPS_R30, &mipsinfo);
        mipsinfo.i = initialGP;
        mips_set_info(CPUINFO_INT_REGISTER + MIPS_R28, &mipsinfo);

        mips_execute(5000);

        return AO_SUCCESS;

    }
    return AO_FAIL;
}
예제 #3
0
파일: devuart.c 프로젝트: 8l/inferno
static long
uartread(Chan *c, void *buf, long n, vlong offset)
{
	Uart *p;

	if(c->qid.type & QTDIR){
		setlength(-1);
		return devdirread(c, buf, n, uartdir, ndir, devgen);
	}

	p = uart[NETID(c->qid.path)];
	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
		return qread(p->iq, buf, n);
	case Nctlqid:
		return readnum(offset, buf, n, NETID(c->qid.path), NUMSIZE);
	case Nstatqid:
		return uartstatus(c, p, buf, n, offset);
	}

	return 0;
}
예제 #4
0
파일: Misc.c 프로젝트: mistydemeo/modizer
PSFINFO *sexy_memload(char *addr, int size)
{
	PSFINFO *ret;

        psxInit();
        psxReset();

        sexySPUinit();
        sexySPUopen();

	if(!(ret=memLoadPSF(addr,size,0,0)))
	{
	 psxShutdown();
	 return(0);
	}

	// Taken from aosdk's eng_psf.c file ...
	// patch illegal Chocobo Dungeon 2 code - CaitSith2 put a jump in the delay slot from a BNE
	// and rely on Highly Experimental's buggy-ass CPU to rescue them.  Verified on real hardware
	// that the initial code is wrong.
	if (ret->game) {
		if (!strcmp(ret->game, "Chocobo Dungeon 2")) {
			if (psxMu32(0xbc090) == (0x0802f040))
			{
			 psxMemWrite32(0xbc090, 0);
			 psxMemWrite32(0xbc094, 0x0802f040);
			 psxMemWrite32(0xbc098, 0);
			}
		}
	}
    
	if(ret->stop==~0) ret->fade=0; // Infinity+anything is still infinity...or is it?
	setlength(ret->stop,ret->fade);
	ret->length=ret->stop+ret->fade;

        return(ret);
}
예제 #5
0
파일: str.cpp 프로젝트: Dastrius/oink-stack
string::string(char const *src, int length, SmbaseStringFunc)
{
  s=emptyString;
  setlength(length);       // setlength already has the +1; sets final NUL
  memcpy(s, src, length);
}
예제 #6
0
int32_t spx_start(uint8_t *buffer, uint32_t length)
{
	int i;
	uint16_t reg;

	if (strncmp((char *)buffer, "SPU", 3) && strncmp((char *)buffer, "SPX", 3))
	{
		return AO_FAIL;
	}

	start_of_file = buffer;

	SPUinit();
	SPUopen();
	setlength(~0, 0);

	// upload the SPU RAM image
	SPUinjectRAMImage((unsigned short *)&buffer[0]);

	// apply the register image
	for (i = 0; i < 512; i += 2)
	{
		reg = buffer[0x80000+i] | buffer[0x80000+i+1]<<8;

		SPUwriteRegister((i/2)+0x1f801c00, reg);
	}

	old_fmt = 1;

	if ((buffer[0x80200] != 0x44) || (buffer[0x80201] != 0xac) || (buffer[0x80202] != 0x00) || (buffer[0x80203] != 0x00))
	{
		old_fmt = 0;
	}

	if (old_fmt)
	{
		num_events = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24;

		if (((num_events * 12) + 0x80208) > length)
		{
			old_fmt = 0;
		}
		else
		{
			cur_tick = 0;
		}
	}

	if (!old_fmt)
	{
		end_tick = buffer[0x80200] | buffer[0x80201]<<8 | buffer[0x80202]<<16 | buffer[0x80203]<<24;
		cur_tick = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24;
		next_tick = cur_tick;
	}

	song_ptr = &buffer[0x80208];
	cur_event = 0;

	strncpy((char *)&buffer[4], name, 128);
	strncpy((char *)&buffer[0x44], song, 128);
	strncpy((char *)&buffer[0x84], company, 128);

	return AO_SUCCESS;
}
예제 #7
0
/* ARGSUSED */
static void do_nonl_proc(Widget w, XtPointer client_data, XtPointer call_data)
{
    int i, npts = 0, info;
    double delx, *xfit, *y, *yfit;
    int nsteps = (int) client_data;
    
    set_wait_cursor();
    curset = nlsetno = GetSelectedSet(nonl_set_item);
    if (curset == SET_SELECT_ERROR) {
    	errmsg("No set selected");
    	unset_wait_cursor();
    	return;
    }
    
    nonl_opts.tolerance = atof((char *) xv_getstr(nonl_tol_item));
    nonl_opts.parnum = GetChoice(nonl_nparm_item);
    strcpy(nonl_opts.formula, (char *) xv_getstr(nonl_formula_item));
    for (i = 0; i < nonl_opts.parnum; i++) {
	strcpy(buf, (char *) xv_getstr(nonl_value_item[i]));
	if (sscanf(buf, "%lf", &nonl_parms[i].value) != 1) {
	    errmsg("Invalid input in parameter field");
	    unset_wait_cursor();
	    return;
	}
	
	nonl_parms[i].constr = XmToggleButtonGetState(nonl_constr_item[i]);
	if (nonl_parms[i].constr) {
	    strcpy(buf, (char *) xv_getstr(nonl_lowb_item[i]));
	    if (sscanf(buf, "%lf", &nonl_parms[i].min) != 1) {
	    	errmsg("Invalid input in low-bound field");
	    	unset_wait_cursor();
	    	return;
	    }
	    strcpy(buf, (char *) xv_getstr(nonl_uppb_item[i]));
	    if (sscanf(buf, "%lf", &nonl_parms[i].max) != 1) {
	    	errmsg("Invalid input in upper-bound field");
	    	unset_wait_cursor();
	    	return;
	    }
	    if ((nonl_parms[i].value < nonl_parms[i].min) || (nonl_parms[i].value > nonl_parms[i].max)) {
	    	errmsg("Initial values must be within bounds");
	    	unset_wait_cursor();
	    	return;
	    }
	}
    }
    
    nonl_prefs.autoload = XmToggleButtonGetState(nonl_autol_item);
    for (i = 0; i < 3; i++) {
        if (XmToggleButtonGetState(nonl_load_item[i])) {
            nonl_prefs.load = i;
            break;
        }
    }
    
    if (nonl_prefs.load == LOAD_FUNCTION) {
        strcpy(buf, (char *) xv_getstr(nonl_start_item));
	if (sscanf(buf, "%lf", &nonl_prefs.start) != 1) {
	    errmsg("Invalid input in start field");
	    unset_wait_cursor();
	    return;
	}
	strcpy(buf, (char *) xv_getstr(nonl_stop_item));
	if (sscanf(buf, "%lf", &nonl_prefs.stop) != 1) {
	    errmsg("Invalid input in stop field");
	    unset_wait_cursor();
	    return;
	}
	strcpy(buf, (char *) xv_getstr(nonl_npts_item));
	if (sscanf(buf, "%d", &nonl_prefs.npoints) != 1) {
	    errmsg("Invalid input in start field");
	    unset_wait_cursor();
	    return;
	}
    }
    
    if (nsteps) { /* we are asked to fit */
    	sprintf(buf, "Fitting with formula: %s\n", nonl_opts.formula);
    	stufftext(buf, 0);
    	sprintf(buf, "Initial guesses:\n");
    	stufftext(buf, 0);
    	for (i = 0; i < nonl_opts.parnum; i++) {
	    sprintf(buf, "\ta%1d = %g\n", i, nonl_parms[i].value);
	    stufftext(buf, 0);
    	}
    	sprintf(buf, "Tolerance = %g\n", nonl_opts.tolerance);
    	stufftext(buf, 0);

/*
 * The fit itself!
 */    	

    	info = do_nonlfit(cg, nlsetno, nsteps);
    	if (info == -1) {
	    errmsg("Memory allocation error in do_nonlfit()");  
	    unset_wait_cursor();
	    return;  	
    	}
   	    	
    	for (i = 0; i < nonl_opts.parnum; i++) {
	    sprintf(buf, "%g", nonl_parms[i].value);
	    xv_setstr(nonl_value_item[i], buf);
    	}

    	if ((info > 0 && info < 4) || (info == 5)) {
	    sprintf(buf, "Computed values:\n");
	    stufftext(buf, 0);
	    for (i = 0; i < nonl_opts.parnum; i++) {
		sprintf(buf, "\ta%1d = %g\n", i, nonl_parms[i].value);
		stufftext(buf, 0);
	    }
    	}


    	if (info >= 0 && info <= 7) {
    	    char *s;
    	    switch (info) {
    	    case 0:
    		s = "Improper input parameters.\n";
    		break;
    	    case 1:
    		s = "Relative error in the sum of squares is at most tol.\n";
    		break;
    	    case 2:
    		s = "Relative error between A and the solution is at most tol.\n";
    		break;
    	    case 3:
    		s = "Relative error in the sum of squares and A and the solution is at most tol.\n";
    		break;
    	    case 4:
    		s = "Fvec is orthogonal to the columns of the jacobian to machine precision.\n";
    		break;
    	    case 5:
    		s = "\n";
    		break;
    	    case 6:
    		s = "Tol is too small. No further reduction in the sum of squares is possible.\n";
    		break;
    	    case 7:
    		s = "Tol is too small. No further improvement in the approximate solution A is possible.\n";
    		break;
    	    default:
    		s = "\n";
    		errmsg("Internal error in do_nonl_proc(), please report");
    		break;
    	    }
    	    stufftext(s, 0);
    	    stufftext("\n", 0);
    	}
    } /* endif (nsteps) */

/*
 * Select & activate a set to load results to
 */    
    if (!nsteps || nonl_prefs.autoload) {
    	/* check if the set is already allocated */
    	if ((nlloadset == -1) || (nlloadset == nlsetno) || !getsetlength(cg, nlloadset)) {
    	    nlloadset = nextset(cg);
    	    if (nlloadset == -1) {
    	      errmsg("No more sets!");
    	      unset_wait_cursor();
    	      return;
    	    } else {
    		activateset(cg, nlloadset);
    		setlength(cg, nlloadset, 1);
    	    }
    	}
    	    	
    	switch (nonl_prefs.load) {
    	case LOAD_VALUES:
    	  sprintf(buf, "Evaluating fitted values and loading result to set %d:\n", nlloadset);
    	  stufftext(buf, 0);
    	  npts = getsetlength(cg, nlsetno);
    	  setlength(cg, nlloadset, npts);
    	  copycol2(cg, nlsetno, cg, nlloadset, 0);
    	  break;
    	case LOAD_RESIDUALS:
    	  sprintf(buf, "Evaluating fitted values and loading residuals to set %d:\n", nlloadset);
    	  stufftext(buf, 0);
    	  npts = getsetlength(cg, nlsetno);
    	  setlength(cg, nlloadset, npts);
    	  copycol2(cg, nlsetno, cg, nlloadset, 0);
    	  break;
    	case LOAD_FUNCTION:
    	  sprintf(buf, "Computing fitting function and loading result to set %d:\n", nlloadset);
    	  stufftext(buf, 0);
    	  
    	  npts  = nonl_prefs.npoints;
    	  if (npts <= 1) {
    	      errmsg("Number of points must be > 1");
    	      unset_wait_cursor();
    	      return;
    	  }
    	  
    	  setlength(cg, nlloadset, npts);
    	  
    	  delx = (nonl_prefs.stop - nonl_prefs.start)/(npts - 1);
    	  xfit = getx(cg, nlloadset);
	  for (i = 0; i < npts; i++) {
	      xfit[i] = nonl_prefs.start + i * delx;
	  }
    	  break;
    	}
    	
    	setcomment(cg, nlloadset, nonl_opts.formula);
    	
    	do_compute(nlloadset, 0, cg, nonl_opts.formula);
    	
    	if (nonl_prefs.load == LOAD_RESIDUALS) { /* load residuals */
    	    y = gety(cg, nlsetno);
    	    yfit = gety(cg, nlloadset);
    	    for (i = 0; i < npts; i++) {
	      yfit[i] -= y[i];
	    }
    	}
    	
    	update_set_lists(cg);
    	drawgraph();
    }
    unset_wait_cursor();
}
예제 #8
0
int32 psf_start(uint8 *buffer, uint32 length)
{
    uint8 *file, *lib_decoded, *lib_raw_file, *alib_decoded;
    uint32 offset, plength, PC, SP, GP, lengthMS, fadeMS;
    uint64 file_len, lib_len, lib_raw_length, alib_len;
    corlett_t *lib;
    int i;
    union cpuinfo mipsinfo;

    // clear PSX work RAM before we start scribbling in it
    memset(psx_ram, 0, 2*1024*1024);

//	printf("Length = %d\n", length);

    // Decode the current GSF
    if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS)
    {
        return AO_FAIL;
    }

//	printf("file_len %d reserve %d\n", file_len, c->res_size);

    // check for PSX EXE signature
    if (strncmp((char *)file, "PS-X EXE", 8))
    {
        return AO_FAIL;
    }

#if DEBUG_LOADER
    offset = file[0x18] | file[0x19]<<8 | file[0x1a]<<16 | file[0x1b]<<24;
    printf("Text section start: %x\n", offset);
    offset = file[0x1c] | file[0x1d]<<8 | file[0x1e]<<16 | file[0x1f]<<24;
    printf("Text section size: %x\n", offset);
    printf("Region: [%s]\n", &file[0x4c]);
    printf("refresh: [%s]\n", c->inf_refresh);
#endif

    if (c->inf_refresh[0] == '5')
    {
        psf_refresh = 50;
    }
    if (c->inf_refresh[0] == '6')
    {
        psf_refresh = 60;
    }

    PC = file[0x10] | file[0x11]<<8 | file[0x12]<<16 | file[0x13]<<24;
    GP = file[0x14] | file[0x15]<<8 | file[0x16]<<16 | file[0x17]<<24;
    SP = file[0x30] | file[0x31]<<8 | file[0x32]<<16 | file[0x33]<<24;

#if DEBUG_LOADER
    printf("Top level: PC %x GP %x SP %x\n", PC, GP, SP);
#endif

    // Get the library file, if any
    if (c->lib[0] != 0)
    {
        uint64 tmp_length;

#if DEBUG_LOADER
        printf("Loading library: %s\n", c->lib);
#endif
        if (ao_get_lib(c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS)
        {
            return AO_FAIL;
        }
        lib_raw_length = tmp_length;

        if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS)
        {
            free(lib_raw_file);
            return AO_FAIL;
        }

        // Free up raw file
        free(lib_raw_file);

        if (strncmp((char *)lib_decoded, "PS-X EXE", 8))
        {
            printf("Major error!  PSF was OK, but referenced library is not!\n");
            free(lib);
            return AO_FAIL;
        }

#if DEBUG_LOADER
        offset = lib_decoded[0x18] | lib_decoded[0x19]<<8 | lib_decoded[0x1a]<<16 | lib_decoded[0x1b]<<24;
        printf("Text section start: %x\n", offset);
        offset = lib_decoded[0x1c] | lib_decoded[0x1d]<<8 | lib_decoded[0x1e]<<16 | lib_decoded[0x1f]<<24;
        printf("Text section size: %x\n", offset);
        printf("Region: [%s]\n", &lib_decoded[0x4c]);
        printf("refresh: [%s]\n", lib->inf_refresh);
#endif

        // if the original file had no refresh tag, give the lib a shot
        if (psf_refresh == -1)
        {
            if (lib->inf_refresh[0] == '5')
            {
                psf_refresh = 50;
            }
            if (lib->inf_refresh[0] == '6')
            {
                psf_refresh = 60;
            }
        }

        PC = lib_decoded[0x10] | lib_decoded[0x11]<<8 | lib_decoded[0x12]<<16 | lib_decoded[0x13]<<24;
        GP = lib_decoded[0x14] | lib_decoded[0x15]<<8 | lib_decoded[0x16]<<16 | lib_decoded[0x17]<<24;
        SP = lib_decoded[0x30] | lib_decoded[0x31]<<8 | lib_decoded[0x32]<<16 | lib_decoded[0x33]<<24;

#if DEBUG_LOADER
        printf("Library: PC %x GP %x SP %x\n", PC, GP, SP);
#endif

        // now patch the file into RAM
        offset = lib_decoded[0x18] | lib_decoded[0x19]<<8 | lib_decoded[0x1a]<<16 | lib_decoded[0x1b]<<24;
        offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
        plength = lib_decoded[0x1c] | lib_decoded[0x1d]<<8 | lib_decoded[0x1e]<<16 | lib_decoded[0x1f]<<24;
#if DEBUG_LOADER
        printf("library offset: %x plength: %d\n", offset, plength);
#endif
        memcpy(&psx_ram[offset/4], lib_decoded+2048, plength);

        // Dispose the corlett structure for the lib - we don't use it
        free(lib);
    }

    // now patch the main file into RAM OVER the libraries (but not the aux lib)
    offset = file[0x18] | file[0x19]<<8 | file[0x1a]<<16 | file[0x1b]<<24;
    offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
    plength = file[0x1c] | file[0x1d]<<8 | file[0x1e]<<16 | file[0x1f]<<24;

    // Philosoma has an illegal "plength".  *sigh*
    if (plength > (file_len-2048))
    {
        plength = file_len-2048;
    }
    memcpy(&psx_ram[offset/4], file+2048, plength);

    // load any auxiliary libraries now
    for (i = 0; i < 8; i++)
    {
        if (c->libaux[i][0] != 0)
        {
            uint64 tmp_length;

#if DEBUG_LOADER
            printf("Loading aux library: %s\n", c->libaux[i]);
#endif

            if (ao_get_lib(c->libaux[i], &lib_raw_file, &tmp_length) != AO_SUCCESS)
            {
                return AO_FAIL;
            }
            lib_raw_length = tmp_length;

            if (corlett_decode(lib_raw_file, lib_raw_length, &alib_decoded, &alib_len, &lib) != AO_SUCCESS)
            {
                free(lib_raw_file);
                return AO_FAIL;
            }

            // Free up raw file
            free(lib_raw_file);

            if (strncmp((char *)alib_decoded, "PS-X EXE", 8))
            {
                printf("Major error!  PSF was OK, but referenced library is not!\n");
                free(lib);
                return AO_FAIL;
            }

#if DEBUG_LOADER
            offset = alib_decoded[0x18] | alib_decoded[0x19]<<8 | alib_decoded[0x1a]<<16 | alib_decoded[0x1b]<<24;
            printf("Text section start: %x\n", offset);
            offset = alib_decoded[0x1c] | alib_decoded[0x1d]<<8 | alib_decoded[0x1e]<<16 | alib_decoded[0x1f]<<24;
            printf("Text section size: %x\n", offset);
            printf("Region: [%s]\n", &alib_decoded[0x4c]);
#endif

            // now patch the file into RAM
            offset = alib_decoded[0x18] | alib_decoded[0x19]<<8 | alib_decoded[0x1a]<<16 | alib_decoded[0x1b]<<24;
            offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
            plength = alib_decoded[0x1c] | alib_decoded[0x1d]<<8 | alib_decoded[0x1e]<<16 | alib_decoded[0x1f]<<24;
            memcpy(&psx_ram[offset/4], alib_decoded+2048, plength);

            // Dispose the corlett structure for the lib - we don't use it
            free(lib);
        }
    }

    free(file);
//	free(lib_decoded);

    // Finally, set psfby tag
    strcpy(psfby, "n/a");
    if (c)
    {
        int i;
        for (i = 0; i < MAX_UNKNOWN_TAGS; i++)
        {
            if (!strcasecmp(c->tag_name[i], "psfby"))
                strcpy(psfby, c->tag_data[i]);
        }
    }

    mips_init();
    mips_reset(NULL);

    // set the initial PC, SP, GP
#if DEBUG_LOADER
    printf("Initial PC %x, GP %x, SP %x\n", PC, GP, SP);
    printf("Refresh = %d\n", psf_refresh);
#endif
    mipsinfo.i = PC;
    mips_set_info(CPUINFO_INT_PC, &mipsinfo);

    // set some reasonable default for the stack
    if (SP == 0)
    {
        SP = 0x801fff00;
    }

    mipsinfo.i = SP;
    mips_set_info(CPUINFO_INT_REGISTER + MIPS_R29, &mipsinfo);
    mips_set_info(CPUINFO_INT_REGISTER + MIPS_R30, &mipsinfo);

    mipsinfo.i = GP;
    mips_set_info(CPUINFO_INT_REGISTER + MIPS_R28, &mipsinfo);

#if DEBUG_LOADER && 1
    {
        FILE *f;

        f = fopen("psxram.bin", "wb");
        fwrite(psx_ram, 2*1024*1024, 1, f);
        fclose(f);
    }
#endif

    psx_hw_init();
    SPUinit();
    SPUopen();

    lengthMS = psfTimeToMS(c->inf_length);
    fadeMS = psfTimeToMS(c->inf_fade);

#if DEBUG_LOADER
    printf("length %d fade %d\n", lengthMS, fadeMS);
#endif

    if (lengthMS == 0)
    {
        lengthMS = ~0;
    }

    setlength(lengthMS, fadeMS);

    // patch illegal Chocobo Dungeon 2 code - CaitSith2 put a jump in the delay slot from a BNE
    // and rely on Highly Experimental's buggy-ass CPU to rescue them.  Verified on real hardware
    // that the initial code is wrong.
    if (c->inf_game)
    {
        if (!strcmp(c->inf_game, "Chocobo Dungeon 2"))
        {
            if (psx_ram[0xbc090/4] == LE32(0x0802f040))
            {
                psx_ram[0xbc090/4] = LE32(0);
                psx_ram[0xbc094/4] = LE32(0x0802f040);
                psx_ram[0xbc098/4] = LE32(0);
            }
        }
    }

//	psx_ram[0x118b8/4] = LE32(0);	// crash 2 hack

    // backup the initial state for restart
    memcpy(initial_ram, psx_ram, 2*1024*1024);
    memcpy(initial_scratch, psx_scratch, 0x400);
    initialPC = PC;
    initialGP = GP;
    initialSP = SP;

    mips_execute(5000);

    return AO_SUCCESS;
}