Ejemplo n.º 1
0
void server_procedure(struct command_line_args *object)
{
	struct packet *p;
	My402ListElem *elem = NULL;
	struct timespec tim;
	double time;
	long time_diff_in_nsec;
	int i = 0;
	while( i < object->no_of_packets && !EndServerThread) 
	{
		pthread_mutex_lock(&token_bucket);
		while(My402ListEmpty(&Q2PacketList)&&!EndServerThread)
			pthread_cond_wait(&is_q2_empty,&token_bucket);

		if(EndServerThread == 1)
		{
			pthread_mutex_unlock(&token_bucket);
			break;
		}

		elem = My402ListFirst(&Q2PacketList);
		if(elem == NULL)
		{
			pthread_mutex_unlock(&token_bucket);
			break;
		}
		p = (struct packet *)elem->obj;
		My402ListUnlink(&Q2PacketList, elem);

		pthread_mutex_unlock(&token_bucket);
	
		gettimeofday(&(p->Q2leaves), NULL);
		time = (TIME_IN_USEC(p->Q2leaves) - TIME_IN_USEC(GlobalStartTime))/1000;
		p->time_in_Q2 = (TIME_IN_USEC(p->Q2leaves) - TIME_IN_USEC(p->Q2timestamp))/1000;

		LOG(stdout, "%012.3fms: p%d begin service at S, time in Q2 = %.3fms\n",time,p->packet_id,p->time_in_Q2);
 
		time_diff_in_nsec = (long)((((p->precise_packet_service_time)/1000) - (p->service_time/1000))*1000000000L);
		tim.tv_sec = (p->service_time)/1000;
		tim.tv_nsec = time_diff_in_nsec;
	
		nanosleep(&tim, NULL);
	
		gettimeofday(&(p->Leaves_server), NULL);
		time = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(GlobalStartTime))/1000;
		p->time_in_system = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(p->Arrival_timestamp))/1000;
		p->precise_packet_service_time = (TIME_IN_USEC(p->Leaves_server) - TIME_IN_USEC(p->Q2leaves))/1000;
		LOG(stdout, "%012.3fms: p%d departs from S, service time = %.3fms, time in system = %.3fms\n",time,p->packet_id,p->precise_packet_service_time,p->time_in_system);
		completed_packets ++;
		calculate_stats(p);
		if((packet_count == object->no_of_packets) &&(completed_packets == (packet_count-discarded_packets)) && My402ListEmpty(&Q2PacketList))
		{
			EndServerThread = 1;
			pthread_cond_signal(&is_q2_empty);
		}
		i++;
	}
	pthread_exit(NULL);
	
}
Ejemplo n.º 2
0
int atarisys2_interrupt (void)
{
    int i;

	/* set the 32V timer */
	timer_set (TIME_IN_USEC (Machine->drv->vblank_duration), 0, atarisys2_32v_interrupt);
	timer_set (TIME_IN_USEC (Machine->drv->vblank_duration), 0, atarisys2_video_update);

	/* update the pedals once per frame */
    for (i = 0; i < pedal_count; i++)
	{
		if (readinputport (3 + i) & 0x80)
		{
			pedal_value[i] += 64;
			if (pedal_value[i] > 0xff) pedal_value[i] = 0xff;
		}
		else
		{
			pedal_value[i] -= 64;
			if (pedal_value[i] < 0) pedal_value[i] = 0;
		}
	}

	/* VBLANK is 3 */
	if (!irq_hold3 && (READ_WORD (&atarisys2_interrupt_enable[0]) & 8))
	{
		irq_hold3 = 1;
		return 3;
	}
	else
		return ignore_interrupt ();
}
Ejemplo n.º 3
0
static WRITE16_HANDLER( hypr_subcpu_control_w )
{
	int pc = activecpu_get_pc();

	if (data & 0x01)
	{
		if (!subcpu_resetline)
		{
			if (pc != 0x95f2)
			{
				cpunum_set_input_line(1, INPUT_LINE_RESET, ASSERT_LINE);
				subcpu_resetline = 1;
			} else {
				cpunum_set_input_line(1, INPUT_LINE_HALT, ASSERT_LINE);
				subcpu_resetline = -1;
			}
		}
	} else {
		if (subcpu_resetline == 1 && (data != 0x0c))
		{
			cpunum_set_input_line(1, INPUT_LINE_RESET, CLEAR_LINE);
			subcpu_resetline = 0;
			if (pc == 0xbb0 || pc == 0x9d30 || pc == 0xb19c)
				cpu_spinuntil_time(TIME_IN_USEC(15000));		/* sync semaphore */
		}
		else if (subcpu_resetline == -1)
		{
			cpunum_set_input_line(1, INPUT_LINE_HALT, CLEAR_LINE);
			subcpu_resetline = 0;
		}
	}
}
Ejemplo n.º 4
0
static void via_irq(int state)
{
	/* Kaos sits in a tight loop polling the VIA irq flags register, but that register is
       cleared by the irq handler. Therefore, I wait a bit before triggering the irq to
       leave time for the program to see the flag change. */
	timer_set(TIME_IN_USEC(50), state, via_irq_delayed);
}
Ejemplo n.º 5
0
void digdug_customio_w(int offset,int data)
{
if (errorlog && data != 0x10 && data != 0x71) fprintf(errorlog,"%04x: custom IO command %02x\n",cpu_get_pc(),data);

	customio_command = data;

	switch (data)
	{
		case 0x10:
			if (nmi_timer) timer_remove (nmi_timer);
			nmi_timer = 0;
			return;

		case 0xa1:	/* go into switch mode */
			mode = 1;
			break;

		case 0xc1:
		case 0xe1:	/* go into credit mode */
			mode = 0;
			break;

		case 0xb1:	/* status? */
			credits = 0;	/* this is a good time to reset the credits counter */
			break;
	}

	nmi_timer = timer_pulse (TIME_IN_USEC (50), 0, digdug_nmi_generate);
}
Ejemplo n.º 6
0
static void coco_fdc_callback(int event)
{
	switch(event) {
	case WD179X_IRQ_CLR:
		intrq_state = CLEAR_LINE;
		cpunum_set_input_line(0, INPUT_LINE_NMI, CLEAR_LINE);
		break;

	case WD179X_IRQ_SET:
		intrq_state = ASSERT_LINE;
		CLEAR_COCO_HALTENABLE;
		coco_set_halt_line(CLEAR_LINE);
		if( COCO_NMIENABLE )
			timer_set( TIME_IN_USEC(0), 0, raise_nmi);
		else
			cpunum_set_input_line(0, INPUT_LINE_NMI, CLEAR_LINE);
		break;

	case WD179X_DRQ_CLR:
		drq_state = CLEAR_LINE;
		if( COCO_HALTENABLE )
			timer_set( TIME_IN_CYCLES(7,0), 0, raise_halt);
		else
			coco_set_halt_line(CLEAR_LINE);
		break;
	case WD179X_DRQ_SET:
		drq_state = ASSERT_LINE;
		coco_set_halt_line(CLEAR_LINE);
		break;
	}
}
Ejemplo n.º 7
0
void gottlieb_speech_w(int offset, int data)
{
	data ^= 255;

	/* generate a NMI after a while to make the CPU continue to send data */
	timer_set(TIME_IN_USEC(50),0,gottlieb_nmi_generate);
}
Ejemplo n.º 8
0
void centronics_write_handshake(int nr, int data, int mask)
{
	CENTRONICS *This=cent+nr;
	
	int neu=(data&mask)|(This->control&(~mask));
	
	if (neu & CENTRONICS_NO_RESET)
	{
		if ( !(This->control&CENTRONICS_STROBE) && (neu&CENTRONICS_STROBE) )
		{
			printer_output(image_from_devtype_and_index(IO_PRINTER, nr), This->data);
			
			/* setup timer for data acknowledge */

			/* set mask for data that has changed */
			This->new_control_mask = CENTRONICS_ACKNOWLEDGE;
			/* set data that has changed */
			This->new_control_data = CENTRONICS_ACKNOWLEDGE;

			/* setup a new timer */
			timer_adjust(This->timer, TIME_IN_USEC(1), nr, 0);
		}
	}
	This->control=neu;
}
Ejemplo n.º 9
0
static void cpu_vblankcallback(int param)
{
	int cpunum;

   if (vblank_countdown == 1)
      vblank = 1;

	/* loop over CPUs */
	for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
	{
		/* if the interrupt multiplier is valid */
		if (cpu[cpunum].vblankint_multiplier != -1)
		{
			/* decrement; if we hit zero, generate the interrupt and reset the countdown */
			if (!--cpu[cpunum].vblankint_countdown)
			{
				/* a param of -1 means don't call any callbacks */
				if (param != -1)
				{
					/* if the CPU has a VBLANK handler, call it */
					if (Machine->drv->cpu[cpunum].vblank_interrupt && cpu_getstatus(cpunum))
					{
						cpuintrf_push_context(cpunum);
						(*Machine->drv->cpu[cpunum].vblank_interrupt)();
						cpuintrf_pop_context();
					}

					/* update the counters */
					cpu[cpunum].iloops--;
				}

				/* reset the countdown and timer */
				cpu[cpunum].vblankint_countdown = cpu[cpunum].vblankint_multiplier;
				timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0);
			}
		}

		/* else reset the VBLANK timer if this is going to be a real VBLANK */
		else if (vblank_countdown == 1)
			timer_adjust(cpu[cpunum].vblankint_timer, TIME_NEVER, 0, 0);
	}

	/* is it a real VBLANK? */
	if (!--vblank_countdown)
	{
		/* do we update the screen now? */
		if (!(Machine->drv->video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
			time_to_quit = updatescreen();

		/* Set the timer to update the screen */
		timer_set(TIME_IN_USEC(Machine->drv->vblank_duration), 0, cpu_updatecallback);

		/* reset the globals */
		cpu_vblankreset();

		/* reset the counter */
		vblank_countdown = vblank_multiplier;
	}
}
Ejemplo n.º 10
0
static void set_coco_dskreg(int data)
{
	UINT8 drive = 0;
	UINT8 head = 0;
	int motor_mask = 0;

	LOG(("set_coco_dskreg(): %c%c%c%c%c%c%c%c ($%02x)\n",
									data & 0x80 ? 'H' : 'h',
									data & 0x40 ? '3' : '.',
									data & 0x20 ? 'D' : 'S',
									data & 0x10 ? 'P' : 'p',
									data & 0x08 ? 'M' : 'm',
									data & 0x04 ? '2' : '.',
									data & 0x02 ? '1' : '.',
									data & 0x01 ? '0' : '.',
								data ));

		/* An email from John Kowalski informed me that if the DS3 is
		 * high, and one of the other drive bits is selected (DS0-DS2), then the
		 * second side of DS0, DS1, or DS2 is selected.  If multiple bits are
		 * selected in other situations, then both drives are selected, and any
		 * read signals get yucky.
		 */

		motor_mask = 0x08;

		if (data & 0x04)
			drive = 2;
		else if (data & 0x02)
			drive = 1;
		else if (data & 0x01)
			drive = 0;
		else if (data & 0x40)
			drive = 3;
		else
			motor_mask = 0;

		head = ((data & 0x40) && (drive != 3)) ? 1 : 0;

	dskreg = data;

	if( COCO_HALTENABLE && (drq_state == CLEAR_LINE) )
		timer_set( TIME_IN_CYCLES(7,0), 0, raise_halt);
	else
		coco_set_halt_line(CLEAR_LINE);

	if( COCO_NMIENABLE  && (intrq_state == ASSERT_LINE) )
	{
		CLEAR_COCO_HALTENABLE;
		coco_set_halt_line(CLEAR_LINE);
		timer_set( TIME_IN_USEC(0), 0, raise_nmi);
	}
	else
		cpunum_set_input_line(0, INPUT_LINE_NMI, CLEAR_LINE);

	wd179x_set_drive(drive);
	wd179x_set_side(head);
	wd179x_set_density( (dskreg & 0x20) ? DEN_MFM_LO : DEN_FM_LO );
}
Ejemplo n.º 11
0
static void josvolly_8741_do(int num)
{
	if( (i8741[num].sts & 0x02) )
	{
		/* transmit data */
		timer_set (TIME_IN_USEC(1),num,josvolly_8741_tx);
	}
}
Ejemplo n.º 12
0
int foodf_interrupt (void)
{
	/* INT 2 once per frame in addition to... */
	if (cpu_getiloops () == 0)
		timer_set (TIME_IN_USEC (100), 0, foodf_delayed_interrupt);

	/* INT 1 on the 32V signal */
	return 1;
}
Ejemplo n.º 13
0
static void delayed_sound_w(int param)
{
	main_to_sound_data = param;
	main_to_sound_ready = 1;
	cpu_triggerint(1);

	/* use a timer to make long transfers faster */
	timer_set(TIME_IN_USEC(50), 0, 0);
}
Ejemplo n.º 14
0
static WRITE16_HANDLER( othunder_lightgun_w )
{
	/* A write starts the A/D conversion. An interrupt will be triggered when
       the conversion is complete.
       The ADC60808 clock is 512kHz. Conversion takes between 0 and 8 clock
       cycles, so would end in a maximum of 15.625us. We'll use 10. */

	timer_set(TIME_IN_USEC(10),0, ad_interrupt);
}
Ejemplo n.º 15
0
static WRITE_HANDLER( xain_sharedram_w )
{
	/* locations 003d and 003e are used as a semaphores between CPU A and B, */
	/* so let's resync every time they are changed to avoid deadlocks */
	if ((offset == 0x003d || offset == 0x003e)
			&& xain_sharedram[offset] != data)
		cpu_boost_interleave(0, TIME_IN_USEC(20));
	xain_sharedram[offset] = data;
}
Ejemplo n.º 16
0
static void apple1_dsp_ready_start(int dummy)
{
	/* When the display asserts \RDA to signal it is ready, it
	   triggers a 74123 one-shot to send a 3.5-usec low pulse to PIA
	   input CB1.  The end of this pulse will tell the PIA that the
	   display is ready for another write. */
	pia_set_input_cb1(0, 0);
	timer_set(TIME_IN_USEC(3.5), 0, apple1_dsp_ready_end);
}
Ejemplo n.º 17
0
void cpu_compute_scanline_timing(void)
{
	if (Machine->drv->vblank_duration)
		scanline_period = (refresh_period - TIME_IN_USEC(Machine->drv->vblank_duration)) /
				(double)(Machine->drv->default_visible_area.max_y - Machine->drv->default_visible_area.min_y + 1);
	else
		scanline_period = refresh_period / (double)Machine->drv->screen_height;
	scanline_period_inv = 1.0 / scanline_period;
}
Ejemplo n.º 18
0
static WRITE16_HANDLER( roldf_sh_irqtrigger_w )
{
    if (ACCESSING_LSB) {
        soundlatch_w(0,data & 0xff);
        cpunum_set_input_line(1,0,HOLD_LINE);
    }

    // give the z80 time to see it
    cpu_spinuntil_time(TIME_IN_USEC(40));
}
Ejemplo n.º 19
0
static WRITE16_HANDLER( fuuki16_sound_command_w )
{
	if (ACCESSING_LSB)
	{
		soundlatch_w(0,data & 0xff);
		cpunum_set_input_line(1, INPUT_LINE_NMI, PULSE_LINE);
//		cpu_spinuntil_time(TIME_IN_USEC(50));	// Allow the other CPU to reply
		cpu_boost_interleave(0, TIME_IN_USEC(50)); // Fixes glitching in rasters
	}
}
Ejemplo n.º 20
0
static MACHINE_RESET( super8 )
{
	/* reset PIO */
	z80pio_init(0, &z80pio_intf);
	z80pio_reset(0);
	keyboard_scan();
	/* enable ROM in base >0000, and re-enable RAM shortly thereafter */
	memory_set_bankptr(1, memory_region(REGION_CPU1) + 0xC000);
	timer_set(TIME_IN_USEC(10), 0, reset_timer_callback);
}
Ejemplo n.º 21
0
void Create_Attacker_List(char *router_ip, char *attacker_ip, char * victim_ip)
{

	struct attacker_list *p;
	struct router_list *p_routerlist, *new_routerlist;
	if(routerAttackerHead == NULL)
	{
		routerAttackerHead = create_attackerlist_node(router_ip, attacker_ip, victim_ip);
	}

	else
	{
		p = routerAttackerHead;
		while(p != NULL)
		{
			if(strncmp(p->attacker_ip_addr, attacker_ip, MAXIPADDRLEN) == 0)
			{
				p_routerlist = p->routerhead;
				while(p_routerlist != NULL)
				{
					if(strncmp(p_routerlist->router_ip, router_ip, MAXIPADDRLEN) == 0)
					{
						p_routerlist->frequency++;
						goto end;
					}
					p_routerlist = p_routerlist->next;
				}
				if(p_routerlist == NULL)
				{
					new_routerlist = (struct router_list *)malloc(sizeof(struct router_list));
					memset(new_routerlist, '\0', sizeof(struct router_list));
					strncpy(new_routerlist->router_ip, router_ip, strlen(router_ip));
					new_routerlist->frequency = 1;
					new_routerlist->next = p->routerhead;
					p->routerhead = new_routerlist;
					p->no_of_routers++;
					struct timeval curtime;
					gettimeofday(&curtime, NULL);
					LOG(fp_log, LOGL, "%f %s distance", SEC(TIME_IN_USEC(curtime)), router_ip);
					goto end;
				}
			}
			p = p->next;	
		}
		end:	
		if(p == NULL)
		{
			p = create_attackerlist_node(router_ip, attacker_ip, victim_ip);
			p->next = routerAttackerHead;
			routerAttackerHead = p;
		}
	}
	

}
Ejemplo n.º 22
0
static void psx_pad_ack( int n_port )
{
	if( m_pad[ n_port ].n_state != PAD_STATE_IDLE )
	{
		psx_sio_input( 0, PSX_SIO_IN_DSR, m_pad[ n_port ].b_ack * PSX_SIO_IN_DSR );
		if( !m_pad[ n_port ].b_ack )
		{
			m_pad[ n_port ].b_ack = 1;
			timer_set( TIME_IN_USEC( 2 ), n_port, psx_pad_ack );
		}
	}
}
Ejemplo n.º 23
0
static void sound_command_w(int data)
{
	exidy440_sound_command = data;
	exidy440_sound_command_ack = 0;
	cpunum_set_input_line(1, INPUT_LINE_IRQ1, ASSERT_LINE);

	/* It is important that the sound cpu ACKs the sound command
       quickly. Otherwise the main CPU gives up with sound. Boosting
       the interleave for a while helps. */

	cpu_boost_interleave(0, TIME_IN_USEC(100));
}
Ejemplo n.º 24
0
static void delayed_gamma_w(int data)
{
    /* mark the data received */
    gamma_rcvd = 0;
    alpha_xmtd = 1;
    alpha_data = data;

    /* signal with an NMI pulse */
    cpunum_set_input_line(1, INPUT_LINE_NMI, PULSE_LINE);

    /* the sound CPU needs to reply in 250microseconds (according to Neil Bradley) */
    timer_set(TIME_IN_USEC(250), 0, 0);
}
Ejemplo n.º 25
0
static INTERRUPT_GEN( simpsons_irq )
{
	if (K053246_is_IRQ_enabled())
	{
		simpsons_objdma();

		// 32+256us delay at 8MHz dotclock; artificially shortened since actual V-blank length is unknown
		timer_set(TIME_IN_USEC(30), 0, dmaend_callback);
	}

	if (K052109_is_IRQ_enabled())
		cpunum_set_input_line(0, KONAMI_IRQ_LINE, HOLD_LINE);
}
Ejemplo n.º 26
0
static WRITE8_HANDLER( qixmcu_coinctrl_w )
{
	if (data & 0x04)
	{
		cpunum_set_input_line(3, M6809_IRQ_LINE, ASSERT_LINE);
		/* temporarily boost the interleave to sync things up */
		/* note: I'm using 50 because 30 is not enough for space dungeon at game over */
		cpu_boost_interleave(0, TIME_IN_USEC(50));
	}
	else
		cpunum_set_input_line(3, M6809_IRQ_LINE, CLEAR_LINE);

	/* this is a callback called by pia_0_w(), so I don't need to synchronize */
	/* the CPUs - they have already been synchronized by qix_pia_0_w() */
	qix_coinctrl = data;
}
Ejemplo n.º 27
0
static INTERRUPT_GEN( gijoe_interrupt )
{
	// global interrupt masking (*this game only)
	if (!K056832_is_IRQ_enabled(0)) return;

	if (K053246_is_IRQ_enabled())
	{
		gijoe_objdma();

		// 42.7us(clr) + 341.3us(xfer) delay at 6Mhz dotclock
		timer_adjust(dmadelay_timer, TIME_IN_USEC(JOE_DMADELAY), 0, 0);
	}

	// trigger V-blank interrupt
	if (cur_control2 & 0x0080)
		cpunum_set_input_line(0, 5, HOLD_LINE);
}
Ejemplo n.º 28
0
static void read_next_sector(struct ide_state *ide)
{
	/* mark ourselves busy */
	ide->status |= IDE_STATUS_BUSY;

	if (ide->command == IDE_COMMAND_READ_MULTIPLE_BLOCK)
	{
		if (ide->sectors_until_int != 1)
			/* make ready now */
			read_sector_done(ide - idestate);
		else
			/* just set a timer */
			timer_set(TIME_IN_USEC(1), ide - idestate, read_sector_done);
	}
	else
		/* just set a timer */
		timer_set(TIME_PER_SECTOR, ide - idestate, read_sector_done);
}
Ejemplo n.º 29
0
void send_start_marking_msg(char *router_ip, int tcpport)
{
	int fd;
	struct sockaddr_in router_addr;
	struct hostent *router_ip_addr;
	struct in_addr * address;
	struct timeval curtime;
	socklen_t alen = sizeof(struct sockaddr_in);
	
	char my_message[BUFSIZE];
	memset(my_message, 0, BUFSIZE);
	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
	{ 
		LOG(stderr, ERROR, "cannot create socket"); 
	}

	memset((char*)&router_addr, 0, sizeof(struct sockaddr_in)); 
	router_addr.sin_family = AF_INET; 
	router_addr.sin_port = htons(tcpport); 
	router_ip_addr = gethostbyname(router_ip);
	address = (struct in_addr *)router_ip_addr->h_addr;

	router_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*address));
	
	if (connect(fd, (struct sockaddr *)&router_addr, alen) == -1) {
		close(fd);
		perror("TCP connection error");
		exit(0);
	}

	snprintf(my_message,BUFSIZE,"startMarking %s",router_ip);
	if(write(fd, my_message, BUFSIZE) < 0) 
	{
		close(fd);
		perror("Endhost: Error in write() for victim client");
		exit(0);
	}
	LOG(stdout, LOGL, "EndHost: StartMarking message is sent to Router(IP: %s, TCP: %d)",router_ip, tcpport);
	gettimeofday(&curtime, NULL);	
	LOG(fp_log, LOGL, "%f startMarking %s \'%s\'", SEC(TIME_IN_USEC(curtime)), router_ip,  my_message);
	close(fd);

}
Ejemplo n.º 30
0
struct attacker_list *create_attackerlist_node(char *router_ip_addr, char *attacker_ip_addr, char *victim_ip_addr)
{
	struct attacker_list *newNode = (struct attacker_list *)malloc(sizeof(struct attacker_list));
	memset(newNode->attacker_ip_addr,'\0',MAXIPADDRLEN);
	memset(newNode->victim_ip_addr,'\0',MAXIPADDRLEN);
	strncpy(newNode->attacker_ip_addr, attacker_ip_addr, strlen(attacker_ip_addr)); 
	strncpy(newNode->victim_ip_addr, victim_ip_addr, strlen(victim_ip_addr)); 
	newNode->routerhead = (struct router_list *)malloc(sizeof(struct router_list));
	memset(newNode->routerhead,'\0',sizeof(struct router_list));
	strncpy(newNode->routerhead->router_ip, router_ip_addr, strlen(router_ip_addr));
	
	struct timeval curtime;
	gettimeofday(&curtime, NULL);
	LOG(fp_log, LOGL, "%f %s distance", SEC(TIME_IN_USEC(curtime)), router_ip_addr);
	newNode->routerhead->frequency = 1;
	newNode->routerhead->next = NULL;
	newNode->no_of_routers = 1;
	newNode->next = NULL; 
	return newNode;
}