Ejemplo n.º 1
0
int main(int argc, char **argv) {
  int32_t ch, index, excl_index;
  const char *name;
  bool load_default, exclusive;

  load_default = true;
  exclusive = false;

  index = 0;
  while (1) {
    if ((ch = getopt_long_only(argc, argv, "", opt_field, &index)) < 0)
      break;
    switch (ch) {
      case OPT_LOG:
        log_load(optarg);
        break;

      case OPT_CONFIG:
        config_load(optarg);
        load_default = false;
        break;

      case OPT_EXCL:
        if (exclusive)
          error("Cannot use --%s with --%s",
              opt_field[index].name,
              opt_field[excl_index].name);
        exclusive = true;
        excl_index = index;

      case OPT_NRML:
        name = opt_field[index].name;
        if (opt_field[index].has_arg)
          config_set(name, optarg);
        else
          config_set(name, "true");
        break;

      case OPT_VERSION:
        version();
        return 1;

      case OPT_HELP:
      default:
        usage();
        return 1;
    }
  }

  if (load_default)
    config_default();

  mt_init();

  store_load();
  bucket_load();
  crypt_load();
  volume_load();
  return 0;
}
Ejemplo n.º 2
0
//Initializes the system
int init()
{
	//Initializes the SDL and exit if there was an error
	if (SDL_Init (SDL_INIT_EVERYTHING) == -1)
		{ return 1; }

	//Initializes the SDL_ttf and exit if there was an error
	if (TTF_Init())
		{ return 3; }

	//Initializes the SDL_mixer and exit if there was an error
	if (Mix_OpenAudio(LC_SOUND_SAMPLERATE, LC_SOUND_FORMAT, LC_SOUND_CHANNELS, LC_SOUND_CHUNKSIZE) == -1)
		{ return 4; }

	//Create the window
	screen = SDL_SetVideoMode (LC_SCREEN_WIDTH, LC_SCREEN_HEIGHT, LC_SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF);

	//Load the necessary files and check for errors
	if (!load_files())
		{ return 5; }

	//Changes the window title
	SDL_WM_SetCaption ("Line Collapser", NULL);

	//If there was an error with the window creation, exits the program
	if (screen == NULL)
		{ return 6; }

	//Start the random number generation function
	mt_init();

	//If everything went fine
	return 0;

}//init()
Ejemplo n.º 3
0
int main(int argc, char* argv[]) {
    int result = parse_cmd_options(argc, argv, &opts);
    int retval;

    if (result != -1)
        return result;

    retval = 0;
    if (argc - optind < 2) {
        /* not enough arguments */
        usage(argv);
        retval = 2;
    } else {
        if (!sscanf(argv[optind], "%ld", &opts.num_samples)) {
            fprintf(stderr, "Format of num_samples parameter is invalid.\n");
            retval = 3;
        } else if (!sscanf(argv[optind+1], "%lg", &opts.gamma)) {
            fprintf(stderr, "Format of gamma parameter is invalid.\n");
            retval = 4;
        } else {
            srand(opts.use_seed ? opts.seed : time(0));
            mt_init(&rng);
            retval = opts.continuous ? sample_continuous() : sample_discrete();
        }
    }

    return retval;
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
void
checkpoint_arch_init(void)
{
  mt_init();
  mt_start(&checkpoint_thread, thread_loop, NULL);

  /*mt_stop(&checkpoint_thread);*/
  /*mt_remove();*/
}
Ejemplo n.º 5
0
void
thread_init()
{
#ifdef USE_OV
    try_ov = ov_init();
#endif
#ifdef USE_MT
    try_mt = mt_init();
#endif
}
Ejemplo n.º 6
0
unsigned int  mt_encrypt(char *pt, unsigned int len, char *ct, unsigned short key)
{
    mt_state state;
    mt_init(&state, key);
    unsigned int i, stream;
    for(i=0; i<len; ++i)
    {
        if(i%4==0)
        {
            stream = mt_get_rand(&state);
        }
        ct[i] = pt[i] ^  ((char *) &stream)[i];
    }
    
}
Ejemplo n.º 7
0
void
checkpoint_arch_init(void)
{
  if(inited) {
    return;
  }

  mt_init();
  mt_start(&checkpoint_thread, checkpoint_thread_loop, NULL);
  inited = 1;

#if CHECKPOINT_ROLLBACK_BUTTON
  process_start(&checkpoint_button_process, NULL);
#endif /* CHECKPOINT_ROLLBACK_BUTTON */

  /*mt_stop(&checkpoint_thread);*/
  /*mt_remove();*/
}
Ejemplo n.º 8
0
PROCESS_THREAD(contiki_stk501_main_init_process, ev, data)
{
  PROCESS_BEGIN();

  /* Network support (uIP) */
  init_net();

  /* Initalize heap allocator */
  mmem_init ();

  /* Code propagator */
  process_start(&codeprop_process, NULL);

  /* Multi-threading support */
#ifdef MT_DEMO
  mt_init ();
#endif

  PROCESS_END();
}
Ejemplo n.º 9
0
int main()
{
//Start video driver (must always be before loading message)
    mm_init();
    pg_init();
    real_init();
    video_init();
    video_setdriver(video_vgatext_getdriver(),0);

//Put loading message
    cli_puts("ArcaneOS Loading...\n");

//Setup kernel
    gdt_init();
    idt_init();
    isr_init();
    irq_init();
    timer_init();
    kb_init();
    ui_init();
    cpuid_init();
    cmos_init();
    rtc_init();
    acpi_init();
    power_init();
    mt_init();
    syscall_init();
    floppy_init();

    __asm__ __volatile__ ("sti");

//Enable ACPI
    acpi_enable();

//Create thread for ui
    mt_create_thread(mt_kernel_process,test,2);

//Endless loop to prevent bugs when all threads are sleeping
    for(;;)
        __asm__ __volatile__ ("hlt");
}
Ejemplo n.º 10
0
Archivo: sos.c Proyecto: ldfaiztt/MSCS
SOS()
{
        readyq = new_dllist();
        mt_init();
        writeok     = mt_sem_create(0);
        writers     = mt_sem_create(1);
        readers     = mt_sem_create(1);
        nelem       = mt_sem_create(0);
        consoleWait = mt_sem_create(0);
        
        wr_iobuf = make_io_buffer(1);
        cr_iobuf = make_io_buffer(256);
        crb_no_chars = 0;
        crb_end = 0; 
        crb_begin = 0;

        curpid = -1;
//      pids = make_rb();
        init_partitions(); 
        DEBUG('e', "pagesize: %d\n", PageSize);

	jrbTree = make_jrb();		// Step 20

	init = new_pcb();		// Step 22
	init->pid = get_new_pid();	// Step 22
   
        cread_vnode = new_vnode();
        cread_vnode->iobuf =cr_iobuf;
        cr_iobuf->nwriters = 1;
        cwrite_vnode = new_vnode();               
        cwrite_vnode->iobuf = wr_iobuf;
        wr_iobuf->nreaders = 1;
        
        start_timer(10);	
	bzero(main_memory, MemorySize);
        mt_create(read_console_io, (void *)cr_iobuf);
        mt_create(write_console_io, (void *)wr_iobuf);
        //mt_create(read_console, NULL);
        mt_create(initialize_user_process, (void *)Argv);
        schedule();
}
Ejemplo n.º 11
0
PROCESS_THREAD(contiki_stk501_main_init_process, ev, data)
{
  PROCESS_BEGIN();

  /* Network support (uIP) */
  init_net();

  /* Initalize heap allocator */
  mmem_init ();

  /* Code propagator */
  /* TODO: The core elfloader-avr.c has 16/32 bit pointer problems so this won't build */
//process_start(&codeprop_process, NULL);

  /* Multi-threading support */
#ifdef MT_DEMO
  mt_init ();
#endif

  PROCESS_END();
}
Ejemplo n.º 12
0
Archivo: main.c Proyecto: ntamas/plfit
int main(int argc, char* argv[]) {
    int result = parse_cmd_options(argc, argv, &opts);
    int i, retval;

    if (result != -1)
        return result;

    srand(opts.use_seed ? opts.seed : ((unsigned int)time(0)));
    mt_init(&rng);

    retval = 0;
    if (optind == argc) {
        /* no more arguments, process stdin */
        process_file(stdin, "-");
    } else {
        for (i = optind; i < argc; i++) {
            FILE* f;
            
            if (argv[i][0] == '-')
                f = stdin;
            else
                f = fopen(argv[i], "r");

            if (!f) {
                perror(argv[i]);
                retval = 2;
                continue;
            }

            process_file(f, argv[i]);
            fclose(f);
        }
    }

    return retval;
}
Ejemplo n.º 13
0
/*! \brief Initialize sipcapture module */
static int mod_init(void) {

	struct ip_addr *ip = NULL;

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats(exports.name, sipcapture_stats)!=0)
	{
		LM_ERR("failed to register core statistics\n");
		return -1;
	}
#endif

	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}
	if(sipcapture_init_rpc()!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	db_url.len = strlen(db_url.s);
	table_name.len = strlen(table_name.s);
	hash_source.len = strlen (hash_source.s);
	mt_mode.len = strlen(mt_mode.s);
	date_column.len = strlen(date_column.s);
	micro_ts_column.len = strlen(micro_ts_column.s);
	method_column.len = strlen(method_column.s); 	
	reply_reason_column.len = strlen(reply_reason_column.s);        
	ruri_column.len = strlen(ruri_column.s);     	
	ruri_user_column.len = strlen(ruri_user_column.s);  
	from_user_column.len = strlen(from_user_column.s);  
	from_tag_column.len = strlen(from_tag_column.s);   
	to_user_column.len = strlen(to_user_column.s);
	pid_user_column.len = strlen(pid_user_column.s);
	contact_user_column.len = strlen(contact_user_column.s);
	auth_user_column.len = strlen(auth_user_column.s);  
	callid_column.len = strlen(callid_column.s);
	via_1_column.len = strlen(via_1_column.s);      
	via_1_branch_column.len = strlen(via_1_branch_column.s); 
	cseq_column.len = strlen(cseq_column.s);     
	diversion_column.len = strlen(diversion_column.s); 
	reason_column.len = strlen(reason_column.s);        
	content_type_column.len = strlen(content_type_column.s);  
	authorization_column.len = strlen(authorization_column.s); 
	user_agent_column.len = strlen(user_agent_column.s);
	source_ip_column.len = strlen(source_ip_column.s);  
	source_port_column.len = strlen(source_port_column.s);	
	dest_ip_column.len = strlen(dest_ip_column.s);
	dest_port_column.len = strlen(dest_port_column.s);		
	contact_ip_column.len = strlen(contact_ip_column.s); 
	contact_port_column.len = strlen(contact_port_column.s);
	orig_ip_column.len = strlen(orig_ip_column.s);      
	orig_port_column.len = strlen(orig_port_column.s);    
	proto_column.len = strlen(proto_column.s); 
	family_column.len = strlen(family_column.s); 
	type_column.len = strlen(type_column.s);  
	rtp_stat_column.len = strlen(rtp_stat_column.s);  
	node_column.len = strlen(node_column.s);  
	msg_column.len = strlen(msg_column.s);   
	capture_node.len = strlen(capture_node.s);     	
	
	if(raw_socket_listen.s) 
		raw_socket_listen.len = strlen(raw_socket_listen.s);     	
	if(raw_interface.s)
		raw_interface.len = strlen(raw_interface.s);     	

	/* Find a database module */
	if (db_bind_mod(&db_url, &db_funcs))
	{
		LM_ERR("unable to bind database module\n");
		return -1;
	}
	if (!DB_CAPABILITY(db_funcs, DB_CAP_INSERT))
	{
		LM_ERR("database modules does not provide all functions needed"
				" by module\n");
		return -1;
	}

	/*Check the table name*/
	if(!table_name.len) {	
		LM_ERR("ERROR: sipcapture: mod_init: table_name is not defined or empty\n");
		return -1;
	}

	if (mt_init () <0)
	{
		return -1;
	}


	if(db_insert_mode) {
                LM_INFO("INFO: sipcapture: mod_init: you have enabled INSERT DELAYED \
                                Make sure your DB can support it\n");
        }

	capture_on_flag = (int*)shm_malloc(sizeof(int));
	if(capture_on_flag==NULL) {
		LM_ERR("no more shm memory left\n");
		return -1;
	}
	
	*capture_on_flag = capture_on;
	
	/* register DGRAM event */
	if(sr_event_register_cb(SREV_NET_DGRAM_IN, hep_msg_received) < 0) {
		LM_ERR("failed to register SREV_NET_DGRAM_IN event\n");
		return -1;		                	
	}

	if(ipip_capture_on && moni_capture_on) {
		LM_ERR("only one RAW mode is supported. Please disable ipip_capture_on or moni_capture_on\n");
		return -1;		                		
	}
	


	/* raw processes for IPIP encapsulation */
	if (ipip_capture_on || moni_capture_on) {
		register_procs(raw_sock_children);
		                		
		if(extract_host_port() && (((ip=str2ip(&raw_socket_listen)) == NULL)
#ifdef  USE_IPV6
		               && ((ip=str2ip6(&raw_socket_listen)) == NULL)
#endif
		         )) 
		{		
			LM_ERR("sipcapture mod_init: bad RAW IP: %.*s\n", raw_socket_listen.len, raw_socket_listen.s); 
			return -1;
		}		
			
        	if(moni_capture_on && !moni_port_start) {
	        	LM_ERR("ERROR:sipcapture:mod_init: Please define port/portrange in 'raw_socket_listen', before \
	        	                        activate monitoring capture\n");
        		return -1;		                		
                }			
Ejemplo n.º 14
0
static void f_accept_with_http_parse(INT32 nargs)
{
    /* From socket.c */
    struct port
    {
        struct fd_callback_box box;
        int my_errno;
        struct svalue accept_callback;
        struct svalue id;
    };
    INT_TYPE ms, dolog;
    INT_TYPE to;
    struct object *port;
    struct svalue *fun, *cb, *program;
    struct cache *c;
    struct args *args = LTHIS;
    get_all_args("accept_http_loop", nargs, "%o%*%*%*%i%i%i", &port, &program,
                 &fun, &cb, &ms, &dolog, &to);
    MEMSET(args, 0, sizeof(struct args));
    if(dolog)
    {
        struct log *log = aap_malloc(sizeof(struct log));
        MEMSET(log, 0, sizeof(struct log));
        mt_init(&log->log_lock);
        args->log = log;
        log->next = aap_first_log;
        aap_first_log = log;
    }
    c = aap_malloc(sizeof(struct cache));
    MEMSET(c, 0, sizeof(struct cache));
    mt_init(&c->mutex);
    c->next = first_cache;
    first_cache = c;
    args->cache = c;
    c->max_size = ms;
    {
        extern struct program *port_program;
        args->fd = ((struct port *)get_storage( port, port_program))->box.fd;
    }
    args->filesystem = NULL;
#ifdef HAVE_TIMEOUTS
    args->timeout = to;
#endif
    assign_svalue_no_free(&args->cb, fun);   /* FIXME: cb isn't freed on exit */
    assign_svalue_no_free(&args->args, cb);

    request_program = program_from_svalue( program );
    if(!request_program)
    {
        free_args(args);
        Pike_error("Invalid request program\n");
    }
    if(!my_callback)
        my_callback = add_backend_callback( finished_p, 0, 0 );

    {
        int i;
        for( i = 0; i<8; i++ )
            th_farm((void (*)(void *))low_accept_loop, (void *)args);
    }
}
Ejemplo n.º 15
0
void HariMain(void)
{
  struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
  g_binfo = binfo;
	struct FIFO32 fifo;
  char s[40];
	int fifobuf[128]; 
	struct TIMER *timer, *timer2, *timer3;
  int mx, my, i;
	int cursor_x, cursor_c;
  unsigned int memtotal;
  struct MOUSE_DEC mdec;
  struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
  struct SHTCTL *shtctl;
  struct SHEET *sht_back, *sht_mouse, *sht_win;
  unsigned char *buf_back, buf_mouse[256], *buf_win;
	static char keytable[0x54] = {
		0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0,
		'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S',
		'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V',
		'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1',
		'2', '3', '0', '.'
	};
	struct TSS32 tss_a, tss_b;
	int task_b_esp;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR*)ADR_GDT;
  init_gdtidt();
  init_pic();
  io_sti(); /* GDT,IDT,PIC*/
  fifo32_init(&fifo, 128, fifobuf);
	
	// timer
	init_pit();
	timer = timer_alloc();
	timer_init(timer, &fifo, 10);
	timer_settime(timer, 1000);
	timer2 = timer_alloc();
	timer_init(timer2, &fifo, 3);
	timer_settime(timer2, 300);
	timer3 = timer_alloc();
	timer_init(timer3, &fifo, 1);
	timer_settime(timer3, 50);	
	
  io_out8(PIC0_IMR, 0xf8); // 11111001,PIC1和IRQ1,
  io_out8(PIC1_IMR, 0xef); // 11101111, IRQ12
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);

  memtotal = memtest(0x00400000, 0xbfffffff);
  memman_init(memman);
  memman_free(memman, 0x00001000, 0x0009e000);
  memman_free(memman, 0x00400000, memtotal - 0x00400000);

  init_palette();
  shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
  sht_back = sheet_alloc(shtctl);
  sht_mouse = sheet_alloc(shtctl);
  sht_win = sheet_alloc(shtctl);
  buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);
  buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52);

  sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1);
  sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
  sheet_setbuf(sht_win, buf_win, 160, 52, -1); /*没有透明色*/
  init_screen8(buf_back, binfo->scrnx, binfo->scrny);

  init_mouse_cursor8(buf_mouse, 99);
  make_window8(buf_win, 160, 52, "counter");
	make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF);
	cursor_x = 8;
	cursor_c = COL8_FFFFFF;
  sheet_slide(sht_back, 0, 0);
  mx = (binfo->scrnx - 16) / 2;
  my = (binfo->scrny - 28 - 16) / 2;
  sheet_slide(sht_mouse, mx, my);
  sheet_slide(sht_win, 80, 72);
  
  sheet_updown(sht_back, 0);
  sheet_updown(sht_win, 1);
  sheet_updown(sht_mouse, 2);

  sprintf(s, "(0x%x, 0x%x)", mx, my);
  putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
  sprintf(s, "memory 0x%xMB, free : 0x%xKB", memtotal / (1024 * 1024), memman_total(memman) / 1024);
  putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s);
  sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48);

	tss_a.ldtr = 0;
	tss_a.iomap = 0x40000000;
	tss_b.ldtr = 0;
	tss_b.iomap = 0x40000000;
	set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32);
	set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32);
	load_tr(3 * 8);
	task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
	*((int *) (task_b_esp + 4)) = (int) sht_back;
	tss_b.eip = (int)&task_b_main - ADR_BOTPAK;
	tss_b.eflags = 0x00000202; /* IF = 1*/
	tss_b.eax = 0;
	tss_b.ecx = 0;
	tss_b.edx = 0;
	tss_b.ebx = 0;
	tss_b.esp = task_b_esp;
	tss_b.ebp = 0;
	tss_b.esi = 0;
	tss_b.edi = 0;
	tss_b.es = 1 * 8;
	tss_b.cs = 2 * 8;
	tss_b.ss = 1 * 8;
	tss_b.ds = 1 * 8;
	tss_b.fs = 1 * 8;
	tss_b.gs = 1 * 8;

	mt_init();

  for(;;) {
     io_cli();
     if(0 == fifo32_status(&fifo)) {
	 	io_sti();
    }else{
		i = fifo32_get(&fifo);
		io_sti();
	 	if (256 <= i && i <= 511) {
     		sprintf(s, "0x%x", i - 256);
			putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 8);
			if (i < 256 + 0x54) {
				if (0 != keytable[i - 256] && cursor_x < 144) {
					s[0] = keytable[i - 256];
					s[1] = 0;	
					putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_C6C6C6, s, 1);
					cursor_x += 8;
				}
			}
			if (i == 256 + 0x0e && cursor_x > 8) { // Backspace
				putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
				cursor_x -= 8;	
			}
			boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
			sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
       	} // if key status 
		else if (512 <= i && i <= 767) {
	 		if (0 != mouse_decode(&mdec, i - 512)) {
	   			sprintf(s, "[lcr 0x%x 0x%x 0x%x]", mdec.buf[0], mdec.buf[1], mdec.buf[2]);
	   			if (0 != (mdec.btn & 0x01)) {
	     			s[1] = 'L';
	   			}
	   			if (0 != (mdec.btn & 0x02)) {
	     			s[3] = 'R';
	   			}
	   			if (0 != (mdec.btn & 0x04)) {
	     			s[2] = 'C';
	   			}
				putfonts8_asc_sht(sht_back, 64, 16, COL8_FFFFFF, COL8_008484, s, 24);
	   			mx += mdec.x;
	   			my += mdec.y;
	   			if (mx < 0) {
	     			mx = 0;
	   			}
	   			if (my < 0) {
	     			my = 0;
	   			}
	   			if (mx > binfo->scrnx - 1) {
	     			mx = binfo->scrnx - 1;
	   			}
	   			if (my > binfo->scrny - 1) {
	     			my = binfo->scrny - 1;
	   			}
	   			sprintf(s, "(0x%x, 0x%x)", mx, my);
				putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 16);
       	   		sheet_slide(sht_mouse, mx, my); /* 显示鼠标 */
				
				// 
				if ((mdec.btn & 0x01) != 0) {
					sheet_slide(sht_win, mx - 80, my - 8);	
				}
	 		} // if mouse decode
	  	} // if 512 767 
		else if (10 == i) {
			putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7);
		} else if (3 == i) {
			putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6);
		} else if (i <= 1) {
			if (0 != i) {
				timer_init(timer3, &fifo, 0); // set to 0
				cursor_c = COL8_000000;
			} else {
				timer_init(timer3, &fifo, 1);
				cursor_c = COL8_FFFFFF;
			}
			boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
			timer_settime(timer3, 50);
			sheet_refresh(sht_back, 8, 96, 16, 112);
		}
	} // else 0 == getstatus fifo 
  } // for

   return;
}
Ejemplo n.º 16
0
static void sampbins(int numbins, int grainsamps)
{
	float **bins;
	int *virgin; /* boolean: this bin written to? */
	float in[2], out[2];
	float fademul;
	int ix;
	int cur = 0; /* current bin (playback) */
	int curtail = 0; /* current bin (playing/fading tail end) */
	int rec = 0; /* current bin (recording) */
	int rectail = 0; /* previous bin (recording tail end) */
	int pos = 0; /* bin pos, in stereo samples */
	const int totalsamps = grainsamps + FADESAMPS;

	if (grainsamps <= FADESAMPS*2)
	{
		fprintf(stderr, "sampbins: grains too short\n");
		exit(EXIT_FAILURE);
	}

	bins = malloc(sizeof *bins * numbins);
	if (bins == NULL) nomem();
	virgin = malloc(sizeof *virgin * numbins);
	if (virgin == NULL) nomem();

	for (ix = 0; ix < numbins; ix++)
	{
		bins[ix] = malloc(sizeof **bins * totalsamps * 2);
		if (bins[ix] == NULL) nomem();
		memset(bins[ix], 0, sizeof **bins * totalsamps * 2);
		virgin[ix] = 1;
	}

	mt_init((unsigned int)time(NULL));
	rec = mt_urand() % numbins;

	while (fread(in, sizeof in[0], 2, stdin) == 2)
	{
		/*
		 * first write output sample. this way if
		 * playing from/recording to the same bin,
		 * it works.
		 */
		out[0] = bins[cur][pos*2];
		out[1] = bins[cur][pos*2+1];
		if (pos < FADESAMPS)
		{
			out[0] += bins[curtail][(grainsamps+pos)*2];
			out[1] += bins[curtail][(grainsamps+pos)*2+1];
		}
		if (fwrite(out, sizeof *out, 2, stdout) < 2)
			return;

		/* record input sample. */
		bins[rec][pos*2] = in[0];
		bins[rec][pos*2+1] = in[1];

		/* record to tail end of previous bin, for fading. */
		if (pos < FADESAMPS)
		{
			bins[rectail][(grainsamps+pos)*2] = in[0];
			bins[rectail][(grainsamps+pos)*2+1] = in[1];
		}

		/*
		 * advance position, fading/going to new bins if
		 * necessary.
		 */
		pos++;
		if (pos == FADESAMPS)
		{
			/*
			 * fade the beginning of this grain
			 * and the end of the previous one
			 * to avoid clicking.
			 */
			for (ix = 0; ix < FADESAMPS; ix++)
			{
				fademul = ix / (float)FADESAMPS;
				bins[rec][ix*2] *= fademul;
				bins[rec][ix*2+1] *= fademul;
				bins[rectail][(totalsamps-ix)*2-2] *= fademul;
				bins[rectail][(totalsamps-ix)*2-1] *= fademul;
			}
			rectail = rec;
			curtail = cur;
		}
		if (pos == grainsamps)
		{
			virgin[rec] = 0;
			rec = mt_urand() % numbins;

			/*
			 * find the next bin that's written,
			 * to play from.
			 */
			do
			{
				cur++;
				if (cur == numbins)
					cur = 0;
			} while (virgin[cur]);

			pos = 0;
		}
	}
}
Ejemplo n.º 17
0
PROCESS_THREAD(udp_client_process, ev, data)
{
    static struct etimer start_timer, send_timer;
    static int flag=1;int i=0;
    static struct mt_thread sending_thread, attackinit_thread;	

    PROCESS_BEGIN();

    SENSORS_ACTIVATE(button_sensor);
    SENSORS_ACTIVATE(radio_sensor);

    set_global_address();

    printf("UDP client process started\n");

    print_local_addresses();

	myip=uip_ds6_get_link_local(ADDR_PREFERRED)->ipaddr;

    /* new connection with remote host */
    client_conn = udp_new(NULL, NULL, NULL);
    if(client_conn == NULL) {
        printf("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(client_conn, UIP_HTONS(10000+(int)myip.u8[15]));

    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),tcpip_handler);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("No UDP broadcast connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
	
    printf("Created a connection with the server ");
    PRINT6ADDR(&client_conn->ripaddr);
    printf(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

    etimer_set(&start_timer, 60 * CLOCK_SECOND);//network setting time
    etimer_set(&send_timer, CLOCK_SECOND * ((int)myip.u8[15]+60+40));//node check/send parent info
    char buf[3]="hi";


    mt_init();
    mt_start(&sending_thread, sendpacket, 0);
    mt_start(&attackinit_thread, attack_init, NULL);	
    while(1) {

        PROCESS_YIELD();

        //NETSTACK_RDC.off(0);
        //NETSTACK_MAC.off(0);
        //NETSTACK_RADIO.off();
        //button_sensor::value(0);

        if(ev==tcpip_event)
        {
			
	    tcpip_handler();	                  
        }
	if(rssi_stored==5)// if got 5 rssi value from parent or child
	{
		monitor=0;
		monitor_target=0;
		for(i=0;i<5;i++)
			printf("Monitered value %d \n",mrssi[i]);
		rssi_stored=0;
	}
        if((ev==sensors_event) && (data == &button_sensor)) {            
	if(attack_flag)      
	{
		printf("Attack deactivated\n");   
		attack_flag=0;
		attacker=0;
		attacker_set=0;
		dis_output(NULL);
	}else {
		printf("Attack activated\n");   
		mt_exec(&attackinit_thread);
	}	
        }
        if((ev==sensors_event) && (data == &radio_sensor))
        {
            printf("Radio value %d",radio_sensor.value(0));
        }
        if(etimer_expired(&send_timer))
	{
		//uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
		//uip_create_unspecified(&client_conn->ripaddr); 
		//if(myip.u8[15]==4)
		//sendpacket(0);
		etimer_set(&send_timer, CLOCK_SECOND*(myip.u8[15]+60));
		if(parent_change)        // send only at parent change event
		{	            
	            if(!attack_flag)	//  this is not attacker and
		    {	
			mt_exec(&sending_thread);
			//sendpacket(0);	//  send nbr info by broadcast 0 for broadcast 
			parent_change=0;
			printf("Thread initiated\n");
		    }
	        }
	}
        if(etimer_expired(&start_timer) && flag==1)
        {
            flag=0;
            send_xy();
	    etimer_set(&start_timer, CLOCK_SECOND*(myip.u8[15]+1));
	    PROCESS_WAIT_UNTIL(etimer_expired(&start_timer));
	    send_broadcast("hi",sizeof("hi"));	
	    sendpacket(1);	// 0 means send by unicast	
	    	
        }
    }

    PROCESS_END();
}
Ejemplo n.º 18
0
void main(){
	struct BOOTINFO *binfo;
	struct FIFO32 fifo;
	binfo = (struct BOOTINFO *) ADR_BOOTINFO;

	char s[MAX_LENGTH];
	char mcursor[256];

	// mouse and keyboard data
	int fifobuf[BUF_LEN];

	struct TIMER *timer, *timer2, *timer3;

	int fifo_data;
	struct MOUSE_DEC mdec;
	int mx,my;

	// memory manager
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	unsigned int memtotal;


	// overlay control
	struct SHTCTL *shtctl;
	struct SHEET *sht_win, *sht_mouse;
	unsigned char *buf_back, buf_mouse[256];
	unsigned char *buf_win;

	// gdt control
	init_gdtidt();
	init_pic();
	init_pit();
	_io_sti();

	// init fifo
	fifo32_init(&fifo, BUF_LEN, fifobuf);

	init_keyboard(&fifo, 256);
	enable_mouse(&fifo, 512, &mdec);

	timer = timer_alloc();
	timer_init(timer, &fifo, 10);
	timer_settime(timer, 1000);


	timer2 = timer_alloc();
	timer_init(timer2, &fifo, 3);
	timer_settime(timer2, 300);
	
	timer3 = timer_alloc();
	timer_init(timer3,&fifo, 1);
	timer_settime(timer3, 50);


	// must after init pit
	// qemu 1000 = 10s
	// bochs 1000 = 1s
	_io_out8(PIC0_IMR,0xf8);
	_io_out8(PIC1_IMR,0xef);

	// mouse and keyboard control

	// memory set
	memtotal = memtest(0x00400000, 0xbfffffff);
	memman_init(memman);
	// this is ERROR!
	// c400 is system
	memman_free(memman, 0x00400000, memtotal - 0x00400000);


	/**************************************************
	 *  screen 
	 *  ----------------------------------------------*/
	// video initialize
	init_palette();

	shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
	sht_back = sheet_alloc(shtctl);			// background sheet
	sht_mouse = sheet_alloc(shtctl);		// mouse sheet
	sht_win = sheet_alloc(shtctl);

	buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);		// background buffer
	buf_win = (unsigned char *) memman_alloc_4k(memman,160*52);


	sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1);	// bind buf
	sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
	sheet_setbuf(sht_win, buf_win, 160, 52, -1);

	init_screen(buf_back, binfo->scrnx, binfo->scrny);	// init color
	init_mouse_cursor8(buf_mouse, 99);
	make_window8(buf_win, 160, 52, "counter");

	// init slide
	sheet_slide(sht_back, 0, 0);


	// initial mouse position
	mx = (binfo->scrnx - 16) / 2; 
	my = (binfo->scrny - 28 - 16) / 2;

	int cursor_x, cursor_c;
	make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF);
	cursor_x = 8;
	cursor_c = COL8_FFFFFF;

	// init mouse slide
	// init position 0,0
	sheet_slide(sht_mouse, mx, my);
	sheet_slide(sht_win,80,72);

	sheet_updown(sht_back, 0);
	sheet_updown(sht_win, 1);
	sheet_updown(sht_mouse, 2);
	/*-------------------------------------------------
	 *  screen 
	 *  ***********************************************/

	/***************  memory info  *********/
	/*  
	itoa(s,memtotal / 1024 /1024,MAX_LENGTH);
	putfont8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s);

	itoa(s,memman_total(memman) / 1024,MAX_LENGTH);
	putfont8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, s);

	sheet_refresh(sht_back, 0, 32, binfo->scrnx, 80);
	*/
	/***************  memory info  *********/

	/*
	 * TSS
	 */
	struct TSS32 tss_a, tss_b;
	tss_a.ldtr = 0;
	tss_a.iomap = 0x40000000;

	tss_b.ldtr = 0;
	tss_b.iomap = 0x40000000;

	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	set_segmdesc(gdt+3, 103, (int) &tss_a, AR_TSS32);
	set_segmdesc(gdt+4, 103, (int) &tss_b, AR_TSS32);

	int task_b_esp;
	// current tr
	_load_tr(3 * 8);

	task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
	tss_b.eip = (int) &task_b_main;
	tss_b.eflags = 0x00000202; /* IF = 1; */
	tss_b.eax = 0;
	tss_b.ecx = 0;
	tss_b.edx = 0;
	tss_b.ebx = 0;
	tss_b.esp = task_b_esp;
	tss_b.ebp = 0;
	tss_b.esi = 0;
	tss_b.edi = 0;
	tss_b.es = 2 * 8;
	tss_b.cs = 1 * 8;
	tss_b.ss = 2 * 8;
	tss_b.ds = 2 * 8;
	tss_b.fs = 2 * 8;
	tss_b.gs = 2 * 8;

		
	int count = 0;
	mt_init();

	for(;;){
		count ++;
		_io_cli();
		if(0 == (fifo32_status(&fifo) )){
			_io_stihlt(); 
			//_io_sti();  // too fast
		}
		else{
			fifo_data = fifo32_get(&fifo);
			_io_sti();
			if(256 <= fifo_data && fifo_data < 512){ // keyboard data
				if(fifo_data < 256 + 0x54){
					if(keytable[fifo_data-256] != 0){
						s[0] = keytable[fifo_data-256];
						s[1] = 0;
						putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF,s, 1);
						cursor_x += 8;		// next pos
					}
					if(fifo_data == 256 + 0x0e && cursor_x >= 8){
						putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF," ", 1);
						cursor_x -= 8;
					}
				//	boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x+7, 43);
				//	sheet_refresh(sht_win, cursor_x, 28, cursor_x+7, 43);
				}
			}
			else if(512 <= fifo_data && fifo_data < 768){ // mouse data
				// fifo_data -= 512; 	//have some error
				if (mouse_decode(&mdec,fifo_data - 512) != 0){
					mx += mdec.x;
					my += mdec.y;
					if(mx < 0){
						mx = 0;
					}
					if(my < 0){
						my = 0;
					}
					if(mx > binfo->scrnx - 1){
						mx = binfo->scrnx -1;
					}
					if(my > binfo->scrny - 1){
						my = binfo->scrny -1;
					}
					sheet_slide(sht_mouse, mx, my);
					if( (mdec.btn & 0x01) != 0 && (mx > sht_win->vx0 && mx < (sht_win->vx0 + sht_win->bxsize)) && ( my > sht_win->vy0 - sht_win->bysize*2 && my < (sht_win->vy0 + sht_win->bysize * 2) ) ){
						sheet_slide(sht_win, mx - 80, my - 8);
					}
				}

			}
			else if( fifo_data == 10){
				putfont8_asc_sht(sht_back, 0, 140, COL8_FFFFFF, COL8_008484,"10[sec]", 7);
				itoa(s,count,MAX_LENGTH);
				putfont8_asc_sht(sht_back, 140, 28, COL8_000000, COL8_C6C6C6, s ,12 );
			}
			else if( fifo_data == 3){
				putfont8_asc_sht(sht_back, 100, 0, COL8_FFFFFF, COL8_008484,"3[sec]", 6);
			}
			else{
			  	if(fifo_data != 0){
					timer_init(timer3, &fifo, 0);
					boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111);
				}
				else{
					timer_init(timer3, &fifo, 1);
					boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111);
				}
				timer_settime(timer3, 50);
				sheet_refresh(sht_back, 8, 96, 16, 112);
			}

		}
	}
}
Ejemplo n.º 19
0
/**
 * メイン関数
 * コマンドライン引数(options):
 *   -n  スクランブルの数(1-10,000)
 *   -t  スクランブルの種類(0:通常 1:コーナーのみ 2:エッジのみ 3:パリティ有り 4:パリティ無し)
 *   -d  スクランブルの長さの最大値
 *   -l  タイムアウト値(秒)
 *   (-s  オプション有りで phase1/2 のセパレータ有り) 今のところ無し
 *   -v  オプション有りで 冗長出力
 *   -f  facelets文字列指定
 *   (-th スレッド数(1-4)) C版では無し
 *   -sd シード値(省略可)
 */
int main(int argc, char *argv[])
{
	// デフォルト値
	// スクランブルの数
	int num_scrambles = 5;
	// スクランブルの種類
	int type = 6;
	// スクランブルの長さの最大値
	int depth = 30;
	// タイムアウト値(ミリ秒)
	time_t limit = 5000;
	// 冗長出力
	int is_verbose = 0;
	// ステータス表示
	int show_status = 1;
	// Facelet文字列
	char facelets[128];
	// スレッド数
	//int num_threads = 2;
	// プログラム開始時間
	time_t tstart = (time_t)-1;
    // シード値
    unsigned long seed = 0;

	int i;

	// コマンドライン引数の処理
	facelets[0] = '\0';
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-n") == 0) {
			num_scrambles = atoi(argv[++i]);
			if (num_scrambles < 1 || 10000 < num_scrambles) {
				fprintf(stderr, "n must be between 1-10000.\n");
				exit(1);
			}
		} else if (strcmp(argv[i], "-t") == 0) {
			type = atoi(argv[++i]);
			if (type < 0 || 6 < type) {
				fprintf(stderr, "t must be between 0-4.\n");
				exit(1);
			}
		} else if (strcmp(argv[i], "-d") == 0) {
			depth = atoi(argv[++i]);
			if (depth < 0) {
				fprintf(stderr, "d must be positive.\n");
				exit(1);
			}
		} else if (strcmp(argv[i], "-l") == 0) {
			limit = (time_t)atoi(argv[++i]);
			if (limit < 0) {
				fprintf(stderr, "l must be positive.\n");
				exit(1);
			}
		}/* else if (args[i].equals("-s")) {
			useSeparator = true;
		}*/ else if (strcmp(argv[i], "-v") == 0) {
			is_verbose = 1;
		} else if (strcmp(argv[i], "-ns") == 0) {
			show_status = 0;
		} else if (strcmp(argv[i], "-f") == 0) {
			strcpy(facelets, argv[++i]);
		/*{ else if (args[i].equals("-th")) {
			numThreads = Integer.parseInt(args[++i]);
			if (numThreads < 1 || 4 < numThreads) {
				System.err.println("th must be between 1-4.");
				System.exit(1);
			}
		}*/
		} else if (strcmp(argv[i], "-sd") == 0) {
			seed = atoi(argv[++i]);
		} else {
			fprintf(stderr, "Bad arguments.\n");
			exit(1);
		}
	}

	// プログラム名表示
	if (is_verbose) {
		printf("** TwophaseDriver in C 0.0.1 **\n");
		// 各パラメータ表示
		printf("num_scrambles=%d\n", num_scrambles);
		printf("type=%d\n", type);
		printf("depth=%d\n", depth);
		printf("limit=%ld\n", (long int)limit);
		printf("is_verbose=%d\n", is_verbose);
		printf("facelets=%s\n", facelets);
	}

	// 計測開始
	if (is_verbose) {
		tstart = clock();
	}

	// 静的データの初期化
	mt_init((unsigned long)time(NULL) + seed);
	cubiecube_init();
	coordcube_init();
    if (facelets[0] != '\0') {
	    num_scrambles = 1;
	}

	// スクランブル生成
	for (i = 0; i < num_scrambles; i++) {
		Search sc;
		char stat[128], result[128], output[256];

		//output[0] = '\0';
		// Facelet文字列指定されていたら
		if (facelets[0] != '\0') {
		    strcpy(stat, facelets);
		}
		// スクランブルタイプによってスクランブルされたキューブの状態を生成する
		else {
			switch (type) {
				case 0: // 通常
					random_cube(stat);
					break;
				case 1: // コーナーのみ
					corner_random_cube(stat);
					break;
				case 2: // エッジのみ
					edge_random_cube(stat);
					break;
				case 3: // パリティ有り
					random_cube_with_parity(stat);
					break;
				case 4: // パリティ無し
					random_cube_with_no_parity(stat);
					break;
				case 5: // YY君が作成してくれたキューブ状態 (test 1)
					yy_cube_test1(stat);
					break;
				case 6: // YY君が作成してくれたキューブ状態 (test 2)
					yy_cube_test2(stat);
					break;
			}
		}

		/*if (is_verbose) {
			printf("[%d] CubeString:\n%s\n", i, stat);
			char cs[64];
			sprintf(cs, "\n[%d] CubeString\n", i);
			output = strcat(output, cs);

			output += "\n" + getName() + ": [" + i + "] CubeString\n";
			output += c.substring(0, 9) + " - ";
			output += c.substring(9, 18) + " - ";
			output += c.substring(18, 27) + " - ";
			output += c.substring(27, 36) + " - ";
			output += c.substring(36, 45) + " - ";
			output += c.substring(45, 54) + "\n";
		}*/
		// 状態を表示
		if (show_status) {
			printf("%s\n", stat);
		}

		// その状態から完成状態までの解法を検索
		// 参考: このメソッドの引数
		//      solution(java.lang.String facelets, int maxDepth, long timeOut, boolean useSeparator)
		//        Computes the solver string for a given cube.
		solution(&sc, stat, depth, limit, 0, result);
		/*if (is_verbose) {
			//output = strcat(output, );
			//output += getName() + ": [" + i + "] Result\n";
			printf("[%d] Result:\n%s\n", i, result);
		}*/
		if (result[0] == 'E') { // if Error
			strcpy(output, result);
		} else {
			reverse_alg(result, output);
		}
		printf("%s\n", output);
	}

	// 実行時間の計算
	if (is_verbose) {
		printf("\n");
		printf("CPU Time (sec): %lf\n", (double)(clock() - tstart) / CLOCKS_PER_SEC);
	}

	return 0;
}
Ejemplo n.º 20
0
static void hw6180_init(void)
{
    log_msg(INFO_MSG, "SYS::init", "Once-only initialization running.\n");

    fault_gen_no_fault = 0;
    sim_vm_parse_addr = parse_addr;
    sim_vm_fprint_addr = fprint_addr;
    sim_vm_cmd = sim_cmds;

    mt_init();
    console_init();
    iom_init();

    // todo: set debug flags for all devices
    // cpu_dev.dctrl = 1;
    // tape_dev.dctrl = 1;

    sim_brk_types = SWMASK('E');    // execution
    sim_brk_types |= SWMASK('M');   // memory read/write
    sim_brk_types |= SWMASK('W');   // memory write
    sim_brk_types |= SWMASK('D');   // auto-display (w/o stopping)
    sim_brk_dflt = SWMASK('E');

    // System-wide options
    memset(&sys_opts, 0, sizeof(sys_opts));
    sys_opts.clock_speed = 250000; // about 1/4 of a MIP
    // Negative times imply instantaneous operation without making
    // use of sim_activate().  Zero times have almost the same
    // result, except that the caller queues an immediate run via
    // sim_activate() and then returns.  The zero wait event(s) will
    // be noticed and handled prior to the next instruction execution.
    sys_opts.iom_times.connect = 3; // 0
    sys_opts.iom_times.chan_activate = -1;  // unimplemented
    sys_opts.mt_times.read = 3; // -1; 100; 1000;
    sys_opts.mt_times.xfer = -1;            // unimplemented
    sys_opts.warn_uninit = 1;
    sys_opts.startup_interrupt = 1;


    // Which controller channel is used for the tape drive would seem to be
    // arbitrary.  However, the T&D tape actually executes an IMW word.
    // Perhaps this is due to a bug elsewhere.  If not, our previous
    // channel choice of 036 caused the instruction word to have an illegal
    // tag.  The IMW at 00214 is 006715/075000 (lda 06715).  GB61 has an
    // example of using channel 14; we'll use that which just happens to
    // leave the 006715 value unchanged
    //
    // Channels range from 1 to 037; the first several channels are
    // reserved.
    sys_opts.tape_chan = 14;        // 12 bits or 6 bits; controller channel

    // Hardware config -- todo - should be based on config cards!
    // BUG/TODO: need to write config deck at 012000 ? Probably not

    // Only one CPU
    memset(&cpu_ports, 0, sizeof(cpu_ports));
    for (unsigned i = 0; i < ARRAY_SIZE(cpu_ports.ports); ++i)
        cpu_ports.ports[i] = -1;

    // CPU Switches
    memset(&switches, 0, sizeof(switches));
    switches.cpu_num = 0;   // CPU 'A' is bootload cpu (init_early_config.pl1)
    // FLT_BASE switches are the 7 MSB of a 12bit addr
    // AN87, 1-41 claims multics requires faults to be at 100o
    switches.FLT_BASE = 2;  // 2<<5 == 0100
    // At one time, it seemed that the diag tape required using different
    // fault base switch settings.  However, that no longer seems to be the case.
    switches.dps8_model = 0;  // Most of our code assumes L68

    // Only one SCU
    memset(&scu, 0, sizeof(scu));
    scu.mode = 1;   // PROGRAM mode
    for (unsigned i = 0; i < ARRAY_SIZE(scu.ports); ++i)
        scu.ports[i].idnum = -1;

    // BUG/TODO: the following belongs in a scu_reset()
    for (unsigned i = 0; i < ARRAY_SIZE(scu.ports); ++i)
        scu.ports[i].is_enabled = 0;
    for (unsigned i = 0; i < ARRAY_SIZE(scu.interrupts); ++i) {
        scu.interrupts[i].mask_assign.unassigned = 1;
        scu.interrupts[i].exec_intr_mask = ~0 & MASKBITS(32);
    }

    // Only two of the four SCU masks are used; these correspond to the "A"
    // and "B" rotary switches
    scu.interrupts[0].avail = 1;
    scu.interrupts[1].avail = 1;

    // Only one IOM
    iom.iom_num = 0;    // IOM "A"

    Mem = malloc(sizeof(*Mem) * MAXMEMSIZE);
    if (Mem == NULL) {
        log_msg(ERR_MSG, "SYS::init", "Cannot allocate memory.\n");
        return;
    }
#if FEAT_MEM_CHECK_UNINIT
    memset(Mem, 0xff, MAXMEMSIZE*sizeof(Mem[0]));
#else
    memset(Mem, 0, MAXMEMSIZE*sizeof(Mem[0]));
#endif

    // CPU port 'a' connected to port '5' of SCU
    // scas_init's call to make_card seems to require that the CPU be connected
    // to SCU port zero.
    // Also, rsw_util$port_info claims base addr is: port-assignment * size/1024
    //int cpu_port = 4;       // CPU port 'd' or 4
    // However, MR12.1 error_msgs.compout says CPUs should be on higher
    // port numbers than IOMs and Bulk Stores
    int cpu_port = 0;       // CPU port 'a' or 0
    cpu_ports.scu_port = 5;
    cpu_ports.ports[cpu_port] = 0;  // CPU connected to SCU "A"
    scu.ports[cpu_ports.scu_port].is_enabled = 1;
    scu.ports[cpu_ports.scu_port].type = ADEV_CPU;
    scu.ports[cpu_ports.scu_port].idnum = switches.cpu_num;
    scu.ports[cpu_ports.scu_port].dev_port = cpu_port;

    // The following should probably be in scu_rest() because mask
    // assignments can be changed by running code
    // GB61, pages 9-1 and A-2: Set Mask A to port that the bootload CPU is
    // connected to; Set Mask B to off
    scu.interrupts[0].mask_assign.unassigned = 0;
    scu.interrupts[0].mask_assign.port = cpu_ports.scu_port;
    scu.interrupts[0].mask_assign.raw = 1 << (8 - cpu_ports.scu_port);

    // IOM port 3 connected to port 1 of bootload SCU
    // Some sources say that we must use the same port (a-h) on the IOM as
    // we used on the CPU.  However, scas_init.pl1 will complain about being
    // unable to setup cyclic port priority if IOMS and CPUS use the same
    // SCU ports.
    int iom_port = 3;   // BUG
    // int iom_port = cpu_port; // required by AM81 and AN70
    iom.scu_port = 1;
    iom.ports[iom_port] = 0;    // port C connected to SCU "A"
    scu.ports[iom.scu_port].is_enabled = 1;
    scu.ports[iom.scu_port].type = ADEV_IOM;
    scu.ports[iom.scu_port].idnum = iom.iom_num;
    scu.ports[iom.scu_port].dev_port = iom_port;

    /* Console */
    sys_opts.opcon_chan = 012; // channels 010 and higher are probed for an operators console
    iom.channels[sys_opts.opcon_chan].type = DEVT_CON;
    iom.channels[sys_opts.opcon_chan].dev = &opcon_dev;

    /* Disk */
    const int disk_chan = 20;
    iom.channels[disk_chan].type = DEVT_DISK;
    iom.channels[disk_chan].dev = &disk_dev;

    /* Tape */
    iom.channels[sys_opts.tape_chan].type = DEVT_TAPE;
    iom.channels[sys_opts.tape_chan].dev = &tape_dev;

    log_msg(INFO_MSG, "SYS::init", "Once-only initialization complete.\n");
    log_msg(INFO_MSG, "SYS::init", "Activity queue has %d entries.\n", sim_qcount());
}
Ejemplo n.º 21
0
Archivo: ransac.c Proyecto: jguinet/s2p
// RANSAC
//
// Given a list of data points, find the parameters of a model that fits to
// those points.  Several models are tried, and the model with the highest
// number of inliers is kept.
//
// A basic idea of this kind of ransac is that a maximum allowed error is fixed
// by hand, and then the inliers of a model are defined as the data points
// which fit the model up to the allowed error.  The RANSAC algorithm randomly
// tries several models and keeps the one with the largest number of inliers.
int ransac(
		// output
		//int *out_ninliers, // number of inliers
		bool *out_mask,    // array mask identifying the inliers
		float *out_model,  // model parameters

		// input data
		float *data,       // array of input data

		// input context
		int datadim,       // dimension of each data point
		int n,             // number of data points
		int modeldim,      // number of model parameters
		ransac_error_evaluation_function *mev,
		ransac_model_generating_function *mgen,
		int nfit,          // data points needed to produce a model

		// input parameters
		int ntrials,       // number of models to try
		int min_inliers,   // minimum allowed number of inliers
		float max_error,   // maximum allowed error

		// decoration
		ransac_model_accepting_function *macc,
		void *usr
		)
{
	fprintf(stderr, "running RANSAC over %d datapoints of dimension %d\n",
			n, datadim);
	fprintf(stderr, "will try to find a model of size %d from %d points\n",
		       	modeldim, nfit);
	fprintf(stderr, "we will make %d trials and keep the best with e<%g\n",
			ntrials, max_error);
	fprintf(stderr, "a model must have more than %d inliers\n",
			min_inliers);


	mt_init((unsigned long int) 0);  // fix seed for the Mersenne Twister PRNG
	int best_ninliers = 0;
	float best_model[modeldim];
	bool *best_mask = xmalloc(n * sizeof*best_mask);
	bool *tmp_mask = xmalloc(n * sizeof*best_mask);

	for (int i = 0; i < ntrials; i++)
	{
		int indices[nfit];
		fill_random_indices(indices, nfit, 0, n);

		float x[nfit*datadim];
		for (int j = 0; j < nfit; j++)
		for (int k = 0; k < datadim; k++)
			x[datadim*j + k] = data[datadim*indices[j] + k];

		float model[modeldim*MAX_MODELS];
		int nm = mgen(model, x, usr);
		if (!nm)
			continue;
		if (macc && !macc(model, usr))
			continue;

		// generally, nm=1
		for (int j = 0; j < nm; j++)
		{
			float *modelj = model + j*modeldim;
			int n_inliers = ransac_trial(tmp_mask, data, modelj,
					max_error, datadim, n, mev, usr);

			if (n_inliers > best_ninliers)
			{
				best_ninliers = n_inliers;
				for(int k = 0; k < modeldim; k++)
					best_model[k] = modelj[k];
				for(int k = 0; k < n; k++)
					best_mask[k] = tmp_mask[k];
			}
		}
	}

	fprintf(stderr, "RANSAC found this best model:");
	for (int i = 0; i < modeldim; i++)
		fprintf(stderr, " %g", best_model[i]);
	fprintf(stderr, "\n");
	if (0) {
		FILE *f = xfopen("/tmp/ramo.txt", "w");
		for (int i = 0; i < modeldim; i++)
			fprintf(f,"%lf%c",best_model[i],i==modeldim-1?'\n':' ');
		xfclose(f);
	}
	//fprintf(stderr, "errors of outliers:");
	//for (int i = 0; i < n; i++)
	//	if (!best_mask[i]) {
	//		float e = mev(best_model, data+i*datadim, usr);
	//		fprintf(stderr, " %g", e);
	//	}
	//fprintf(stderr, "\n");
	//fprintf(stderr, "errors of inliers:");
	//for (int i = 0; i < n; i++)
	//	if (best_mask[i]) {
	//		float e = mev(best_model, data+i*datadim, usr);
	//		fprintf(stderr, " %g", e);
	//	}
	//fprintf(stderr, "\n");
	//fprintf(stderr, "errors of data points:\n");
	//for (int i = 0; i < n; i++) {
	//	float e = mev(best_model, data+i*datadim, usr);
	//	fprintf(stderr, "\t%g\t%s\n", e, best_mask[i]?"GOOD":"bad");
	//}

	int return_value = 0;
	if (best_ninliers >= min_inliers)
	{
		return_value =  best_ninliers;
	} else
		return_value = 0;

	for (int j = 0; j < modeldim; j++)
		if (!isfinite(best_model[j]))
			fail("model_%d not finite", j);

	if (out_model)
		for(int j = 0; j < modeldim; j++)
			out_model[j] = best_model[j];
	if (out_mask)
		for(int j = 0; j < n; j++)
			out_mask[j] = best_mask[j];

	free(best_mask);
	free(tmp_mask);

	return return_value;
}
Ejemplo n.º 22
0
void 
HariMain(void)
{
  boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO;
  fifo32_t fifo;
  int  fifobuf[128];
  char debug_info[64];
  timer_t* timer1;
  timer_t* timer2;
  timer_t* timer3;
  int mouse_x, mouse_y, cursor_x, cursor_c, task_b_esp;
  int data;
  mouse_dec_t mdec;
  unsigned int memory_total;
  mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR;
  layer_mgr_t* layer_mgr;
  layer_t* back_layer;
  layer_t* mouse_layer;
  layer_t* win_layer;
  unsigned char* back_buf;
  unsigned char  mouse_buf[256];
  unsigned char* win_buf;
  static char s_keytable[0x54] = {
    0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
    0,   0,   'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 
    0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 
    0,   '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,   '*', 
    0,   ' ', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 
    0,   '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
  };
  tss32_t tss_a, tss_b;
  segment_descriptor_t* gdt = (segment_descriptor_t*)ADR_GDT;


  init_gdt_idt();
  init_pic();
  io_sti();   /* after initialize IDT/PIC, allow all CPU's interruptors */

  fifo_init(&fifo, fifobuf, 128);
  init_pit(); /* initialize programmable interval timer */
  init_keyboard(&fifo, 256);
  enable_mouse(&fifo, 512, &mdec);
  io_out8(PIC0_IMR, 0xf8);  /* set PIT/PIC1/keyboard permission 11111000 */
  io_out8(PIC1_IMR, 0xef);  /* set mouse permission 11101111 */

  set490(&fifo, 1);
  timer1 = timer_alloc();
  timer_init(timer1, &fifo, 10);
  timer_settimer(timer1, 1000);

  timer2 = timer_alloc();
  timer_init(timer2, &fifo, 3);
  timer_settimer(timer2, 300);

  timer3 = timer_alloc();
  timer_init(timer3, &fifo, 1);
  timer_settimer(timer3, 50);

  memory_total = memory_test(0x00400000, 0xbfffffff);
  mem_mgr_init(mem_mgr);
  mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000);  /*0x00001000~0x0009e000*/
  mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000);

  init_palette();
  layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, 
      binfo->screen_x, binfo->screen_y);
  back_layer = layer_alloc(layer_mgr);
  mouse_layer = layer_alloc(layer_mgr);
  win_layer = layer_alloc(layer_mgr);
  back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 
      binfo->screen_x * binfo->screen_y);
  win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52);
  layer_setbuf(back_layer, back_buf, 
      binfo->screen_x, binfo->screen_y, -1);
  layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99);
  layer_setbuf(win_layer, win_buf, 160, 52, -1);
  init_screen(back_buf, binfo->screen_x, binfo->screen_y);
  init_mouse_cursor8(mouse_buf, 99);
  make_window8(win_buf, 160, 52, "Window");
  make_text8(win_layer, 8, 28, 144, 16, COLOR8_FFFFFF);
  cursor_x = 8;
  cursor_c = COLOR8_FFFFFF;
  layer_slide(back_layer, 0, 0);
  mouse_x = (binfo->screen_x - 16) / 2;
  mouse_y = (binfo->screen_y - 28 - 16) / 2;
  layer_slide(mouse_layer, mouse_x, mouse_y);
  layer_slide(win_layer, 80, 72);
  layer_updown(back_layer, 0);
  layer_updown(win_layer, 1);
  layer_updown(mouse_layer, 2);
  sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
  drawstring_and_refresh(back_layer, 0, 0, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);

  sprintf(debug_info, "memory total: %dMB, free space: %dKB", 
      memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024);
  drawstring_and_refresh(back_layer, 0, 32, 
      COLOR8_FFFFFF, COLOR8_848484, debug_info, 40);


  tss_a.ldtr = 0;
  tss_a.iomap = 0x40000000;
  tss_b.ldtr = 0;
  tss_b.iomap = 0x40000000;
  set_segment_descriptor(gdt + 3, 103, (int)&tss_a, AR_TSS32);
  set_segment_descriptor(gdt + 4, 103, (int)&tss_b, AR_TSS32);
  load_tr(3 * 8);
  task_b_esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8;
  tss_b.eip = (int)&task_b_main;
  tss_b.eflags = 0x00000202;  /* IF = 1 */
  tss_b.eax = 0;
  tss_b.ecx = 0;
  tss_b.edx = 0;
  tss_b.ebx = 0;
  tss_b.esp = task_b_esp;
  tss_b.ebp = 0;
  tss_b.esi = 0;
  tss_b.edi = 0;
  tss_b.es = 1 * 8;
  tss_b.cs = 2 * 8;
  tss_b.ss = 1 * 8;
  tss_b.ds = 1 * 8;
  tss_b.fs = 1 * 8;
  tss_b.gs = 1 * 8;
  *((int*)(task_b_esp + 4)) = (int)back_layer;
  mt_init();

  for ( ; ; ) {
    io_cli();

    if (0 == fifo_size(&fifo))
      io_stihlt();
    else {
      data = fifo_get(&fifo);
      io_sti();

      if (256 <= data && data <= 511) {
        sprintf(debug_info, "%02X", data - 256);
        drawstring_and_refresh(back_layer, 0, 16, 
            COLOR8_FFFFFF, COLOR8_848484, debug_info, 2);

        if (data < (256 + 0x54)) {
          if (0 != s_keytable[data - 256] && cursor_x < 144) {
            /* normal character, show 1 character, move cursor 1 time */
            debug_info[0] = s_keytable[data - 256];
            debug_info[1] = 0;
            drawstring_and_refresh(win_layer, cursor_x, 28, 
                COLOR8_000000, COLOR8_FFFFFF, debug_info, 1);
            cursor_x += 8;
          }
        }
        if ((256 + 0x0e) == data && cursor_x > 8) {
          /* backspace, recover cursor by sapce, move back cursor 1 time */
          drawstring_and_refresh(win_layer, cursor_x, 28, 
              COLOR8_000000, COLOR8_FFFFFF, " ", 1);
          cursor_x -= 8;
        }
        /* show cursor again */
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
      else if (512 <= data && data <= 767) {
        if (0 != mouse_decode(&mdec, data - 512)) {
          /* show all mouse bytes code */
          sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y);
          if (0 != (mdec.state & 0x01)) 
            debug_info[1] = 'L';
          if (0 != (mdec.state & 0x02))
            debug_info[3] = 'R';
          if (0 != (mdec.state & 0x04))
            debug_info[2] = 'C';
          drawstring_and_refresh(back_layer, 32, 16, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 15);

          mouse_x += mdec.x;
          mouse_y += mdec.y;

          if (mouse_x < 0)
            mouse_x = 0;
          if (mouse_y < 0)
            mouse_y = 0;
          if (mouse_x > binfo->screen_x - 1)
            mouse_x = binfo->screen_x - 1;
          if (mouse_y > binfo->screen_y - 1)
            mouse_y = binfo->screen_y - 1;

          sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y);
          drawstring_and_refresh(back_layer, 0, 0, 
              COLOR8_FFFFFF, COLOR8_848484, debug_info, 10);
          layer_slide(mouse_layer, mouse_x, mouse_y);

          if (0 != (mdec.state & 0x01)) {
            /* down left click, move window */
            layer_slide(win_layer, mouse_x - 80, mouse_y - 8);
          }
        }
      }
      else if (10 == data) {
        drawstring_and_refresh(back_layer, 0, 64, 
            COLOR8_FFFFFF, COLOR8_848484, "10[sec]", 7);
      }
      else if (3 == data) {
        drawstring_and_refresh(back_layer, 0, 80, 
            COLOR8_FFFFFF, COLOR8_848484, "03[sec]", 7);
      }
      else if (data <= 1) { /* timer by cursor */
        if (0 != data) {
          timer_init(timer3, &fifo, 0);
          cursor_c = COLOR8_000000;
        }
        else {
          timer_init(timer3, &fifo, 1);
          cursor_c = COLOR8_FFFFFF;
        }
        timer_settimer(timer3, 50);
        fill_box8(win_layer->buf, win_layer->w_size, 
            cursor_c, cursor_x, 28, cursor_x + 7, 43);
        layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44);
      }
    }
  }
}