Пример #1
0
int main(void) {
  char *line;

  printf("\n\nECO32 Machine Monitor 1.0\n\n");
  initInstrTable();
  cpuSetPC(0xC0000000);
  
  // mgeisse
  execCommand("boot 0");
  
  while (1) {
    line = getLine("ECO32 > ");
    addHist(line);
    execCommand(line);
  }
  return 0;
}
Пример #2
0
void tileMap::pickRow(unsigned amount,int type,int method){
	if(type<0){
		type=menuPopupArray(hueLblSel,hueTooltip,0,hueChoices);
		if(type<0)
			return;
	}
	if(method<0){
		method=menuPopupArray(hueMethodLbl,hueMethodTooltip,0,hueMethodChoices);
		if(method<0)
			return;
	}
	pushTilemapAll(true);
	double divide=(double)amount;//convert to double
	uint32_t x,y;
	double maxPal=divide;
	double divBy;
	unsigned addBy;
	if((currentProject->gameSystem==NES)&&(currentProject->subSystem&NES2x2)){
		divBy=256.0;//8*8*2*2
		addBy=2;
	}else{
		divBy=64.0;//8*8
		addBy=1;
	}
	uint32_t*hist,sz,stretch,maxh,minh;
	if(method){
		stretch=method&1;
		method=(method+1)>>1;
		if(type>=6)
			sz=2000;
		else
			sz=1000;
		hist=(uint32_t*)calloc(sz,sizeof(uint32_t));
		if(stretch){
			for (y=0;y<mapSizeHA;y+=addBy){
				for (x=0;x<mapSizeW;x+=addBy){
					if((currentProject->gameSystem==NES)&&(currentProject->subSystem&NES2x2)){
						addHist(get_tile(x,y),type,hist,sz);
						addHist(get_tile(x+1,y),type,hist,sz);
						addHist(get_tile(x,y+1),type,hist,sz);
						addHist(get_tile(x+1,y+1),type,hist,sz);
					}else
						addHist(get_tile(x,y),type,hist,sz);
				}
			}
			uint32_t*histp=hist;
			while(!(*histp++));//At least one entry in the array will contain a nonzero value
			minh=(histp-hist);
			--minh;
			histp=hist+sz-1;
			while(!(*histp--));
			maxh=(histp-hist);
			maxh+=2;
			printf("Histogram stretched to [%d,%d)\n",minh,maxh);
		}else{
			minh=0;
			maxh=sz;
		}
	}
	for (y=0;y<mapSizeHA;y+=addBy){
		for (x=0;x<mapSizeW;x+=addBy){
			if(method){
				std::fill(hist,hist+sz,0);
				if((currentProject->gameSystem==NES)&&(currentProject->subSystem&NES2x2)){
					addHist(get_tile(x,y),type,hist,sz);
					addHist(get_tile(x+1,y),type,hist,sz);
					addHist(get_tile(x,y+1),type,hist,sz);
					addHist(get_tile(x+1,y+1),type,hist,sz);
				}else
					addHist(get_tile(x,y),type,hist,sz);
				//Find min and max of the histogram
				uint32_t*histp;
				unsigned divH=(maxh-minh)/amount;
				if(!divH)
					divH=1;
				if(method==2){
					uint32_t maxv,i,ent;
					histp=hist+minh;
					for(i=maxv=ent=0;i<maxh;++i){
						if(maxv<*histp){
							maxv=*histp;
							ent=i;
						}
						++histp;
					}
					set_pal_row(x,y,ent/divH);
				}else if(method==1){
					uint32_t*sums=(uint32_t*)alloca(amount*sizeof(uint32_t)),i,maxv,ent;
					histp=hist+minh;
					std::fill(sums,sums+amount,0);
					for(i=ent=0;i<maxh;++i)
						sums[i/divH]+=*histp++;
					maxv=sums[0];
					for(i=1;i<amount;++i){
						if(maxv<sums[i]){
							maxv=sums[i];
							ent=i;
						}
					}
					set_pal_row(x,y,ent);
				}
			}else{
				double hh;
				if((currentProject->gameSystem==NES)&&(currentProject->subSystem&NES2x2)){
					hh=getHH(get_tile(x,y),type);
					hh+=getHH(get_tile(x+1,y),type);
					hh+=getHH(get_tile(x,y+1),type);
					hh+=getHH(get_tile(x+1,y+1),type);
				}else
					hh=getHH(get_tile(x,y),type);
				hh/=divBy/divide;
				if (hh >= maxPal){
					printf("hh >= %f %f %d\n",maxPal,hh,(int)hh);
					hh=divide-0.5;
				}
				set_pal_row(x,y,hh);
			}
		}
	}
	if(method)
		free(hist);
}
Пример #3
0
int main(void)
{
    pid_t pid;
    char inputBuffer[MAX_LINE];      /* buffer to hold the command entered */
    int background;              /* equals 1 if a command is followed by '&' */
    char *args[(MAX_LINE/2)+1];  /* command line (of 80) has max of 40 arguments*/

    //setting up signal handler
    struct sigaction handler;
    handler.sa_handler = handle_SIGQUIT;
    handler.sa_flags = SA_RESTART;
    sigaction(SIGQUIT, &handler, NULL);

    printf("Welcome to amshell. My pid is %d\n", getpid());
    while (1){            /* Program terminates normally inside setup */
       background = 0;
       char *foo;
       //print prompt and run setup function
       printf("amshell[%d]:\n",commandCount + 1);
       setup(inputBuffer,args,&background);       /* get next command */
       
       //add command to history array and increment command count
       addHist(args);
       commandCount++;

       //case when user wants to use yell function
       //goes through user entered string and capitalizes each char
       if(strcmp(args[0],"yell") == 0){
	 int i = 1;
	 while(args[i] != NULL){
	   char *a = args[i];
	   int j = 0;
	   while(a[j] != '\0'){
	     printf("%c",toupper(a[j]));
	     j++;
	   }
	   printf(" ");
	   i++;
	   if(args[i] == NULL) printf("\n");
	 }

       }
       //case where user wishes to exit, prints statistics
       else if(strcmp(args[0],"exit") == 0){
	 char command[50] = "ps -p ";
	 int a = getpid();
	 char b[15];
	 sprintf(b,"%d",a);
	 strcat(command,b);
	 strcat(command," -o pid,ppid,pcpu,pmem,etime,user,command");
	 system(command);

	 exit(0);
       }
       //if args[0] is "r", we know they wish to repeat
       else if(strcmp(args[0], "r") == 0){
	 if(args[1] == NULL){//tells us r is only argument, repeat most recent
	   printf("%s\n",histArr[1]);
	   char temporary[10];
	   char temp2[10];
	   strncpy(temporary,histArr[1],4);
	   temporary[strlen(temporary)] = 0;//take substring of history array
	   if(strcmp(temporary, "yell") == 0){
	     //if it's yell, copy what user wishes to yell and
             //yell same way we did previously
	     strncpy(temp2,histArr[1] + 5, strlen(histArr[1]));
	     int j = 0;
	     while(temp2[j] != '\0'){
	       printf("%c",toupper(temp2[j]));
	       j++;
	     }
	     printf("\n");
             //overrite history array with command we repeated
	     strcpy(histArr[0],histArr[1]);
	   }
	   else{//otherwise simply run command
	   system(histArr[1]);
	   strcpy(histArr[0],histArr[1]);//overrite history array with most recent
	   }
	 }
	 else {//case where user wishes to repeat certain command
	   int i = atoi(args[1]);
	   char temporary[10];
	   char temp2[10];
	   int length = commandCount - i;
	   printf("%s\n",histArr[length]);
	   strncpy(temporary,histArr[length],4);
	   temporary[strlen(temporary)] = 0;//take substring of history array
	   //to see if it's "yell"
	   
	   if(strcmp(temporary, "yell") == 0){
	     //if it's yell, copy what user wishes to yell and
             //yell same way we did previously
	     strncpy(temp2,histArr[length] + 5, strlen(histArr[length]));
	     int j = 0;
	     while(temp2[j] != '\0'){
	       printf("%c",toupper(temp2[j]));
	       j++;
	    }
	     printf("\n");
             //overrite history array with command we repeated
	     strcpy(histArr[0],histArr[length]);
	   }
	   else{
             //if we aren't repeating yell, simply run command again
	     system(histArr[commandCount - i]);
	     strcpy(histArr[0],histArr[length]);//overrite history array
	   }
	 }
       }
       else{//otherwise run command using fork method
	 pid = fork();
	 if (pid < 0){//fork failure
	   fprintf(stderr, "Fork Failed");
	   return 1;
	 }
	 else if (pid == 0){//child process
	   execvp(args[0],args);//runs command
	 }
	 else{//parent
	   int status;
	   //check if we are running in background
	   if (background == 1) foo = "TRUE"; else foo = "FALSE";
	   printf("[Child pid = %d, background = %s]\n",pid,foo);
	   if(background == 0){
	     waitpid(pid, &status, 0);//function to wait for child
	     printf("Child process complete\n");
	   }
	 }
       }
    }
}