Exemplo n.º 1
0
Arquivo: main.c Projeto: pavelfryz/fit
int main(int argc, char *argv[])
{
    SDL_Event       event;

    /* nacteni modelu */
    polymodel = modLoad((argc == 2) ? argv[1] : DEFAULT_MODEL);
    IZG_CHECK(polymodel, "Failed to read input model");

    /* vytvoreni SW rendereru */
#ifdef USE_STUDENT_RENDERER
    renderer = studrenCreate();
#else
    renderer = renCreate();
#endif /* USE_STUDENT_RENDERER */

    /* pocatecni velikost bufferu */
    renderer->createBuffersFunc(renderer, DEFAULT_WIDTH, DEFAULT_HEIGHT);

    /* inicializace SDL knihovny */
    if( SDL_Init(SDL_INIT_VIDEO) == -1 )
    {
        IZG_SDL_ERROR("Could not initialize SDL library");
    }

    /* nasteveni okna */
    SDL_WM_SetCaption(PROGRAM_TITLE, 0);

    /* screen */
    screen = SDL_SetVideoMode(DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);

    /* enable Unicode translation */
    SDL_EnableUNICODE(1);

    /* kreslime dokud nenarazime na SDL_QUIT event */
    while( !quit )
    {
        /* vycteni udalosti */
        while( SDL_PollEvent(&event) )
        {
            switch( event.type )
            {
                /* udalost klavesnice */
                case SDL_KEYDOWN:
                    onKeyboard(&event.key);
                    break;

                /* zmena velikosti okna */
                case SDL_VIDEORESIZE:
                    onResize(&event.resize);
                    break;

                /* udalost mysi */
                case SDL_MOUSEMOTION:
                    onMouseMotion(&event.motion);
                    break;

                /* SDL_QUIT event */
                case SDL_QUIT:
                    quit = 1;
                    break;

                default:
                    break;
            }
        }

        /* vykresleni pres SDL knihovnu */
        draw();
    }

    /* ukonceni SDL */
    SDL_FreeSurface(screen);

    /* shutdown all SDL subsystems */
    SDL_Quit();

    /* zrusime co jsme vytvorili a ukoncime program */
    modRelease(&polymodel);
    renderer->releaseFunc(&renderer);

    return 0;
}
Exemplo n.º 2
0
int initialize(void)
{
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */
  int key;

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
  FILE *f;
#endif

/* Set up the host environment of COMMAND.COM */
	atexit(exitfct);

	if(modAttach()) {		/* Attach to any already loaded module */
		/* successfully attached --> no further processing of
			command line required as this instance was respawned by
			Stub module --> restore session */
		sessionLoad();
		return E_None;
	}

	/* Prepare creating a new instance of FreeCOM */
	/* Install the dummy handlers of CRITER and ^Break Catcher */
	/* Though if the modules are already loaded, they are used right now */
	modPreload();		/* activate dummies unless already attached */

  /* Some elder DOSs may not pass an initialzied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = NULL;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));

		/* Maybe an anchessor has an absolute path */
	sessionInherit();

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == NULL) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
  if((f = fopen(logFilename, "at")) == NULL) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
    exit(125);
  }

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
#endif

  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, NULL);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = NULL;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = NULL;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = NULL;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = NULL;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {                   /* change TTY as early as possible so the caller gets
                                   the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
    puts("You must specify the complete path to " COM_NAME);
    puts("as the first argument of COMMAND,");
    puts("for instance: C:\\FDOS");
    return E_Useage;
  }

  /* First of all, set up the environment */
    /* If a new valid size is specified, use that */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if(newEnvSize > 16 && newEnvSize < 32767)
    env_setsize(0, newEnvSize);

  /* Otherwise the path is placed into the environment */
  if (chgEnv("COMSPEC", ComPath)) {
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if (chgEnv("COMSPEC", ComPath))
    error_env_var("COMSPEC");
  }

  /* Install the resident portion(s)
  	Now that the name of the executeable is known, they can be found
  	definitely */
 	modLoad(); 		/* Load any module unless already attached to */
 	if(!modAttach()) {	/* Attach to the loaded modules */
 		error_missing_modules();
 		return E_Exit;
 	}


  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
  if (!canexit)
  {
    char *autoexec;

    autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

    showinfo = 0;
    short_version();

    /* JP: changed so that if autoexec does not exist, then don't ask
       to trace or bypass.
     */
    if (exist(autoexec))
    {
      printf("\nPress F8 for trace mode, or F5 to bypass %s... ", autoexec);
      key = WaitForFkeys();
      putchar('\n');

      if (key == KEY_F8)
      {
        tracemode = 1;
      }

      if (key == KEY_F5)
      {
        printf("Bypassing %s\n", autoexec);
      }
      else
        process_input(1, autoexec);
    }
    else
    {
      if(user_autoexec)
        printf("%s not found.\n", autoexec);
#ifdef INCLUDE_CMD_DATE
      cmd_date(NULL);
#endif
#ifdef INCLUDE_CMD_TIME
      cmd_time(NULL);
#endif
    }

    free(user_autoexec);
  }
  else
  {
    assert(user_autoexec == NULL);
  }

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
    putchar('\n');
    showcmds(NULL);
    putchar('\n');
  }

  return E_None;
}
Exemplo n.º 3
0
void initialise(SceSize args, void *argp)
{
	struct ConfigContext ctx;
	const char *init_dir = "host0:/";
	int (*g_sceUmdActivate)(int, const char *);
	int argc;
	char *argv[MAX_ARGS];

	memset(&g_context, 0, sizeof(g_context));
	map_firmwarerev();
	exceptionInit();
	g_context.thevent = -1;
	parse_sceargs(args, argp, &argc, argv);

	if(argc > 0)
	{
		char *lastdir;

		g_context.bootfile = argv[0];
		lastdir = strrchr(argv[0], '/');
		if(lastdir != NULL)
		{
			memcpy(g_context.bootpath, argv[0], lastdir - argv[0] + 1);
		}
	}

	configLoad(g_context.bootpath, &ctx);

	if(ctx.pid)
	{
		g_context.pid = ctx.pid;
	}
	else
	{
		g_context.pid = HOSTFSDRIVER_PID;
	}

	ttyInit();
	init_usbhost(g_context.bootpath);

#if _PSP_FW_VERSION >= 200
	if(argc > 1)
	{
		init_dir = argv[1];
	}
#else
	{
		struct SavedContext *save = (struct SavedContext *) SAVED_ADDR;
		if(save->magic == SAVED_MAGIC)
		{
			init_dir = save->currdir;
			save->magic = 0;
			g_context.rebootkey = save->rebootkey;
		}
	}
#endif

	if(shellInit(init_dir) < 0)
	{
		sceKernelExitGame();
	}

	g_sceUmdActivate = (void*) libsFindExportByNid(refer_module_by_name("sceUmd_driver", NULL), 
			"sceUmdUser", 0xC6183D47);
	if(g_sceUmdActivate)
	{
		g_sceUmdActivate(1, "disc0:");
	}

	/* Hook sceKernelExitGame */
	apiHookByNid(refer_module_by_name("sceLoadExec", NULL), "LoadExecForUser", 0x05572A5F, exit_reset);

	unload_loader();

	psplinkPatchException();

	if(ctx.enableuser)
	{
		load_psplink_user(g_context.bootpath);
	}

	g_context.resetonexit = ctx.resetonexit;

	sceKernelRegisterDebugPutchar(NULL);
	enable_kprintf(1);
	debugHwInit();
	modLoad(g_context.bootpath);
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    SDL_Event       event;
    SDL_TimerID     timer = 0;

    /* nacteni modelu */
    polymodel = modLoad((argc == 2) ? argv[1] : DEFAULT_MODEL);
    IZG_CHECK(polymodel, "Failed to read input model");

    /* vytvoreni default SW rendereru */
#ifdef USE_STUDENT_RENDERER
    renderer = studrenCreate();
#else
    renderer = renCreate();
#endif /* USE_STUDENT_RENDERER */

    /* pocatecni velikost bufferu */
    renderer->createBuffersFunc(renderer, DEFAULT_WIDTH, DEFAULT_HEIGHT);

    /* inicializace SDL knihovny */
    if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1 )
    {
        IZG_SDL_ERROR("Could not initialize SDL library");
    }

    /* nastaveni titulku okna */
#ifdef USE_STUDENT_RENDERER
    SDL_WM_SetCaption(PROGRAM_TITLE_STUDENT, 0);
#else
    SDL_WM_SetCaption(PROGRAM_TITLE, 0);
#endif // USE_STUDENT_RENDERER

    /* screen */
    screen = SDL_SetVideoMode(DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);

    /* enable Unicode translation */
    SDL_EnableUNICODE(1);

    /* dalsi inicializace */
    onInit(renderer, polymodel);

    /* nastavime timer, ktery bude volat zadanou callback fci */
    timer = SDL_AddTimer(TIMER_INTERVAL, timerCallback, NULL);

    /* kreslime dokud nenarazime na SDL_QUIT event */
    while( !quit )
    {
        /* vycteni udalosti */
        while( SDL_PollEvent(&event) )
        {
            switch( event.type )
            {
                /* udalost klavesnice */
                case SDL_KEYDOWN:
                    onKeyboard(&event.key);
                    break;

                /* zmena velikosti okna */
                case SDL_VIDEORESIZE:
                    onResize(&event.resize);
                    break;

                /* udalost mysi - pohyb */
                case SDL_MOUSEMOTION:
                    onMouseMotion(&event.motion);
                    break;

                /* udalost mysi - tlacitka */
                case SDL_MOUSEBUTTONDOWN:
                case SDL_MOUSEBUTTONUP:
                    onMouseButton(&event.button);
                    break;

                /* tiknuti timeru */
                case SDL_USEREVENT:
                    if( event.user.code == IZG_TIMER_EVENT )
                    {
                        onTimer((int)SDL_GetTicks());
                    }
                    break;

                /* SDL_QUIT event */
                case SDL_QUIT:
                    quit = 1;
                    break;

                default:
                    break;
            }
        }

        /* vykresleni pres SDL knihovnu */
        draw();
    }

    /* ukonceni timeru */
    SDL_RemoveTimer(timer);

    /* ukonceni SDL */
    SDL_FreeSurface(screen);

    /* shutdown all SDL subsystems */
    SDL_Quit();

    /* zrusime co jsme vytvorili a ukoncime program */
    modRelease(&polymodel);
    renderer->releaseFunc(&renderer);

    return 0;
}