コード例 #1
0
ファイル: client.c プロジェクト: adc/TEXTserver
int handle_input(struct plyr *p){
    int z;
        
    z = read_byte(p->fd);

    if(z == -1){
      return 1;
    }

      
    if(z == 0 || z == 1) return 0;
    p->lastinput = time(NULL);

    printf("user input: @ (%d,%d) = %d\n",p->x,p->y,z);
   
    if(z == 0x1b){
      handle_escapes(p);
    }
    else if(z == 253U)
    {
      read_byte(p->fd); //3
    }
    else if(z == 255U){
      read_byte(p->fd); //1
      dump_world(p);
    } else if(z == 126 || z == 127)
    {
      move_left(p);
      set_byte(p, ' ');
      CHARAT(p,p->x,p->y) = ' ';
    }
    else if(z == 13)
    {
      move_down(p);
    } else if(z == 10){
     
    } else {
      set_byte(p, z);
      move_right(p);
    }

  return 0;    
}
コード例 #2
0
ファイル: cvt_packet_17.c プロジェクト: likev/CodeOrpgPub
void packet_17(char *buffer,int *offset,int *flag) {
    /* display information contained within packet 17 */
    short spare,boxes,rows,numbytes;
    int i,j;
    int k;
    unsigned char run;
    unsigned char level;

    printf("Packet 17: Digital Precipitation Data Array Packet\n");
    spare=read_half(buffer,offset);
    spare=read_half(buffer,offset);
    boxes=read_half(buffer,offset);
    printf("Number of LFM Boxes in Row = %hd\n",boxes );
    rows=read_half(buffer,offset);
    printf("Number of Rows = %hd\n",rows);

    for(i=0; i<rows; i++) {
        numbytes=read_half(buffer,offset);
        printf("Number of Bytes in Row %d = %hd\n",i+1,numbytes);

        k=0;

        for(j=0; j<numbytes/2; j++) {
            run = (unsigned char) read_byte(buffer,offset);
            level = (unsigned char) read_byte(buffer,offset);
            /*  report pre-build 8 byte swap error */
            if((i==0) && (j==0) && (run==255))
                printf("Linux DPA Error, the Run and Level values are reversed in packet 17.\n");
            printf("Run(%03hd) Level(%03hd)  ", run, level);
            if(k==2) {
                printf("\n");
                k=0;
            } else {
                k++;
            }
        }
        printf("\n");
    }

    printf("\n");
    printf("Message 17 Complete\n");

}
コード例 #3
0
ファイル: memory.c プロジェクト: atamariya/naken_asm
unsigned char memory_read(struct _asm_context *asm_context, uint32_t address)
{
  if (address >= asm_context->memory.size)
  {
    printf("Warning: Data read address %d overran %d byte boundary at %s:%d\n", address, asm_context->memory.size, asm_context->filename, asm_context->line);
    return 0;
  }

  return read_byte(&asm_context->memory, address);
}
コード例 #4
0
ファイル: eeprom.cpp プロジェクト: WHCS-UCF/AVR-Base-Station
EEPROM_MAP_END

#define EEPROM_MAP_SIZE (sizeof(eeprom_map)/sizeof(*eeprom_map))

bool EEPROM::hasCalibration()
{
  int16_t read = read_byte(EEPROM_CAL_PROG);

  return read == 1;
}
コード例 #5
0
ファイル: arith16.c プロジェクト: redacted-moose/Gem
void ADD_SP_r8(struct machine_t *gem) {
    struct cpu_t *cpu = gem->cpu;
	word before = cpu->sp;
	cpu->sp += read_byte(gem, cpu->pc);
	cpu->pc++;
	cpu->z = 0;
	cpu->n = 0;
	cpu->hc = ((before & 0x0FFF) > (cpu->hl & 0x0FFF))? 1 : 0;
	cpu->ca = (before > cpu->hl)? 1 : 0;
}
コード例 #6
0
ファイル: stream.hpp プロジェクト: JRetza/hawktracer
 bool read_value(uint8_t& value)
 {
     int v = read_byte();
     if (v < 0)
     {
         return false;
     }
     value = (uint8_t)v;
     return true;
 }
コード例 #7
0
void BIOSCALL int70_function(pusha_regs_t regs, uint16_t ds, uint16_t es, iret_addr_t iret_addr)
{
    // INT 70h: IRQ 8 - CMOS RTC interrupt from periodic or alarm modes
    uint8_t   registerB = 0, registerC = 0;

    // Check which modes are enabled and have occurred.
    registerB = inb_cmos( 0xB );
    registerC = inb_cmos( 0xC );

    if( ( registerB & 0x60 ) != 0 ) {
        if( ( registerC & 0x20 ) != 0 ) {
            // Handle Alarm Interrupt.
            int_enable();
            call_int_4a();
            int_disable();
        }
        if( ( registerC & 0x40 ) != 0 ) {
            // Handle Periodic Interrupt.

            if( read_byte( 0x40, 0xA0 ) != 0 ) {
                // Wait Interval (Int 15, AH=83) active.
                uint32_t    time;

                time = read_dword( 0x40, 0x9C );  // Time left in microseconds.
                if( time < 0x3D1 ) {
                    // Done waiting.
                    uint16_t    segment, offset;

                    segment = read_word( 0x40, 0x98 );
                    offset  = read_word( 0x40, 0x9A );
                    write_byte( 0x40, 0xA0, 0 );  // Turn of status byte.
                    outb_cmos( 0xB, registerB & 0x37 ); // Clear the Periodic Interrupt.
                    write_byte( segment, offset, read_byte(segment, offset) | 0x80 );  // Write to specified flag byte.
                } else {
                    // Continue waiting.
                    time -= 0x3D1;
                    write_dword( 0x40, 0x9C, time );
                }
            }
        }
    }
    eoi_both_pics();
}
コード例 #8
0
ファイル: sht75.c プロジェクト: ch3paz/uC-mega32-fancontrol
/* Reads the status register with checksum (8-bit) */
char ShtReadStatus(unsigned char *p_value, int datapin){
	unsigned char error=0;
	/* unsigned char checksum=0; */ /* Don't see the need of this yet */

	transstart(datapin); 			/* Transmission start */
	error = write_byte(STATUS_REG_R, datapin); 	/* Send command to sensor */
	*p_value = read_byte(datapin); 	/* Read status register (8-bit) */
	/* checksum = read_byte(); */	/* Read checksum (8-bit) */
	return error; 	/* error=1 in case of no response form the sensor */
}
コード例 #9
0
ファイル: pdfimage.c プロジェクト: fourmond/tioga
/* Reads until the next tag, and returns its code */
static int read_next_tag(FILE * file, int *eof)
{
  int c;
  *eof = 0;

  /* Discard non 0xFF bytes */
  do {
    c = read_byte(file, eof);
    if(*eof)
      return 0xFF;
  } while(c != 0xFF);

  do {
    c = read_byte(file, eof);
    if(*eof)
      return 0xFF;
  } while (c == 0xFF);
  return c;
}
コード例 #10
0
ファイル: ffi.c プロジェクト: clj/kroc_scons
/* Copy a block of memory from the Transterpreter's possibly-virtual memory
   space into real memory. */
static void memcpy_from_tvm (BYTEPTR from, void *to, int size) {
	uint8_t *real_to = (uint8_t *) to;

	while (size > 0) {
		*real_to = read_byte (from);
		from = byteptr_plus (from, 1);
		++real_to;
		--size;
	}
}
コード例 #11
0
ファイル: Stream.cpp プロジェクト: mkotsbak/librcf-cpp
 void IStream::end()
 {
     Byte8 byte;
     read_byte(byte);
     if (byte != End)
     {
         RCF::Exception e(RCF::_SfError_DataFormat(), "no end symbol");
         RCF_THROW(e)(byte);
     }
 }
コード例 #12
0
ファイル: elf-eh-frame.c プロジェクト: Wonseok/okl4_3.0
static bfd_boolean
skip_leb128 (bfd_byte **iter, bfd_byte *end)
{
  unsigned char byte;
  do
    if (!read_byte (iter, end, &byte))
      return FALSE;
  while (byte & 0x80);
  return TRUE;
}
コード例 #13
0
ファイル: enc-tiff.c プロジェクト: joffrey-bion/jpeg-codec
uint32_t read_4bytes_endian(uint32_t *cpt, FILE *f,uint8_t Endian)
{
	if ( Endian == 0 ) { // BigEndian
		uint32_t oct1 = 0;
		uint32_t oct2 = 0;
		oct1 = read_2bytes_endian(cpt,f,Endian);
		oct2 = read_2bytes_endian(cpt,f,Endian);
		return (oct1 << 16) + oct2;
	} else if ( Endian == 1 ) { // LittleEndian
		uint8_t oct1,oct2,oct3,oct4;
		oct1 =read_byte(cpt,f);
		oct2 =read_byte(cpt,f);
		oct3 =read_byte(cpt,f);
		oct4 =read_byte(cpt,f);
		return (oct4 << 24) + (oct3 << 16) + (oct2 << 8) + oct1;
	}
	return 0;

}
コード例 #14
0
ファイル: enc-tiff.c プロジェクト: joffrey-bion/jpeg-codec
uint16_t read_2bytes_endian(uint32_t *cpt, FILE *f, uint8_t Endian)

{
	if ( Endian == 0 ) { // BigEndian
		uint16_t oct1 = 0;
		uint16_t oct2 = 0;
		oct1 = read_byte(cpt,f);
		oct2 = read_byte(cpt,f);
		return (oct1 << 8) + oct2;
	} else if ( Endian == 1 ) { // LittleEndian
		uint16_t oct1 = 0;
		uint16_t oct2 = 0;
		oct1 = read_byte(cpt,f);
		oct2 = read_byte(cpt,f);
		return (oct2 << 8) + oct1;
	}
	return 0;

}
コード例 #15
0
/**
 * @brief Reads MCT marker.
 *
 * @param buffer
 * @param img
*/ 
void read_mct_marker(type_buffer *buffer, type_image *img) {
	int marker;
	int length;
	uint16_t Smct;
	uint8_t type;
	int i;

	/* Read MCT Marker */
	marker = read_buffer(buffer, 2);
	if(marker != MCT)
	{
		println_var(INFO, "Error: Expected MCT marker instead of %x", marker);
	}

	length = read_buffer(buffer, 4)-5;

	/* Read Smct */
	Smct = read_byte(buffer);
	
	type = (Smct&(3<<4))>>4;

	type_mct* old_mcts = img->mct_data->mcts[type];
	img->mct_data->mcts[type] = (type_mct*)realloc(img->mct_data->mcts[type], sizeof(type_mct) * (++img->mct_data->mcts_count[type]));
	type_mct* mct = &img->mct_data->mcts[type][img->mct_data->mcts_count[type]-1];
	
	if(img->mct_data->mcts[type] == NULL) {
		img->mct_data->mcts[type] = old_mcts;
		--img->mct_data->mcts_count[type];
		println_var(INFO, "Error: Memory reallocation failed! Ignoring MCT with Smct %u Skipping data", Smct);
		for(i=0; i<length-1; ++i) {
			read_byte(buffer);
		}
	} else {
		mct->index = Smct&0x0F;
		mct->type = type;
		mct->element_type = (Smct&(3<<6))>>6;
		mct->length = length/(1<<mct->element_type);
		mct->data = (uint8_t*)malloc(length);
		for(i=0; i<length; ++i) {
			mct->data[i] = read_byte(buffer);
		}
	}
}
コード例 #16
0
ファイル: auth.c プロジェクト: cfrodca/tiva-ssh
/**
 * Parse username and password
 */
static int parse_auth(SSH *ssh) {
	byte *p;
	byte *out;
	byte aux;
	word32 outSz;

	p = ssh->sp.data;

	/* Get username */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_UN_LEN)
		return -1;

	memcpy(ssh->user, out, outSz);
	ssh->user[outSz] = 0;

	/* Get service */
	read_bin(&p, &out, &outSz);

	/* Get method */
	read_bin(&p, &out, &outSz);

	/* Only support password based autentication */
	if (memcmp(out, PASSWORD_STR, strlen(PASSWORD_STR)) != 0) {
		return 1;
	}

	/* Read byte */
	read_byte(&p, &aux);

	/* Get password */
	read_bin(&p, &out, &outSz);

	/* Size valid? */
	if (outSz > MAX_PW_LEN)
		return -1;

	memcpy(ssh->pass, out, outSz);
	ssh->pass[outSz] = 0;

	/* Check username and password */
	if (check_password(ssh->user, ssh->pass) < 0) {
		/* Limit auth attempts */
		if (ssh->authAtt++ > 1) {
			return -1;
		}
		return 1;
	}

	ssh->state = SSH_AUTH;

	return 0;
}
コード例 #17
0
ファイル: ec_lpc.c プロジェクト: lynxis/coreboot-signed
static int google_chromeec_status_check(u16 port, u8 mask, u8 cond)
{
	u8 ec_status = read_byte(port);
	u32 time_count = 0;

	/*
	 * One second is more than plenty for any EC operation to complete
	 * (and the bus accessing/code execution) overhead will make the
	 * timeout even longer.
	 */
#define MAX_EC_TIMEOUT_US 1000000

	while ((ec_status & mask) != cond) {
		udelay(1);
		if (time_count++ == MAX_EC_TIMEOUT_US)
			return -1;
		ec_status = read_byte(port);
	}
	return 0;
}
コード例 #18
0
ファイル: tcp_client.c プロジェクト: martinnagelberg/chatroom
void handle_talk(){

   char mensaje[75];
   BYTE color;

   read_string(client_recv_buffer, mensaje);
   read_byte(client_recv_buffer, &color);

   printf("%s%s%s\n", c_colors[color], mensaje, RESET_COLOR); //colores y eso

}
コード例 #19
0
ファイル: grove_ultrasonic.c プロジェクト: iotmx/iotunitec
int ultrasonicRead(int pin)
{
	int data;
	write_block(uRead_cmd, pin, 0, 0);
	read_byte();
	read_block();
	data = r_buf[1]* 256 + r_buf[2];
	if (data==65535)
		return -1;
	return data;
}
コード例 #20
0
ファイル: device.c プロジェクト: MaG21/wavecom-console
size_t
print_results(struct device *dev)
{
	int             ret;
	fd_set          master;
	size_t          nbytes  =0;
	int16_t         c;
	int16_t         old     =0;
	struct timeval  tv;

	FD_ZERO(&master);
	FD_SET(dev->fd, &master);

	printf("\n");

	/* unset modem mode */
	dev->status = 0;

	while( 1 ) {

		tv.tv_sec   = 0;
		tv.tv_usec  = 805999; /* magic? :P */

		ret = select(dev->fd+1, &master, NULL, NULL, &tv);

		if(ret<=0) { 

			if(ret<0) {
				perror("select()");
				exit(EXIT_FAILURE);
			}

			if(c==' ' && old=='>') {
				printf("\b\b");
				dev->status = MODEM_MODE;
			}

			return nbytes;
		}

		old = c;

		c = read_byte(dev);

		if(c<0) { 
			perror("read_byte()");
			exit(EXIT_FAILURE);
		}

		if(dev->status!=MODEM_MODE)
			putchar(c);
		nbytes++;
	}
}
コード例 #21
0
uint32_t read_buffer(type_buffer *buffer, int n)
{
	int i;
	uint32_t val = 0;

	for(i = n - 1; i >= 0; i--)
	{
		val += read_byte(buffer) << (i << 3);
	}
	return val;
}
コード例 #22
0
ファイル: i2c.cpp プロジェクト: hendrixjl/rPi
uint8_t i2c::query(uint8_t slaveaddr,
                         uint8_t slave_register)
{
    command(slaveaddr, slave_register);
    initiate_read();
    uint8_t b;
    while (!read_byte(b)); // loop until success
    clear_fifo();
    // TODO error conditions?
    return b;
}
コード例 #23
0
ファイル: io.c プロジェクト: davel/nspark
/*
 * read a little-endian 2-byte halfword from the input stream.
 */
Halfword
read_halfword(FILE *ifp)
{
	union
	{
		Halfword h;
		Byte b[sizeof(Halfword)];
	}
	ret;

#if defined(NS_LITTLE_ENDIAN)
	if (fread((char *) &ret.h, 1, sizeof(Halfword), ifp)!=sizeof(Halfword)) {
		error("Read error!");
	}
#else
	ret.b[HALFWORD0] = read_byte(ifp);
	ret.b[HALFWORD1] = read_byte(ifp);
#endif
	return (ret.h);
}
コード例 #24
0
int
IOChannel::read_string(char* dst, int max_length){
	int i = 0;
	while(i < max_length){
		dst[i] = read_byte();
		if(dst[i] == '\0') return i;
		i++;
	}
	dst[max_length -1] = '\0';
	return -1;
}
コード例 #25
0
ファイル: adxl345.c プロジェクト: ConSat2/consat2-jobs
int get_data_x(float * result){
  unsigned char data;
  unsigned short raw;
  char negative = 0;
  //read data0 from X-Axis
  if(read_byte(DATAX0, &data) == 0)
    return 0;
 // printf("X-Axis Data0:  %02d\n",data);
  raw = data;

  //read data1 from X-Axis
  if(read_byte(DATAX1, &data) == 0)
    return 0;

 // printf("X-Axis Data1:  %02d -- %02x\n",data, data);
  raw += data<<8;

        *result = convert_to_g(raw);
  return 1;
}
コード例 #26
0
ファイル: stegan.cpp プロジェクト: Alkli/Steganography
std::string read_name(int size, FILE *file_case)
{
   byte c_file_data; 
   std::string name_file;
   for (int i=0; i<size; i++)
   {
      c_file_data = read_byte(file_case);
      name_file += c_file_data;
   }
   return name_file;
}
コード例 #27
0
ファイル: gcr-openpgp.c プロジェクト: SuspiciouSx/gcr
static gboolean
parse_v3_signature (const guchar **at,
                    const guchar *end,
                    GcrOpenpgpParseFlags flags,
                    GPtrArray *records)
{
	guchar keyid[8];
	guint8 sig_type;
	guint8 sig_len;
	guint32 sig_time;
	guint8 key_algo;
	guint8 hash_algo;
	guint16 left_bits;
	GcrRecord *record;
	gchar *value;

	if (!read_byte (at, end, &sig_len) || sig_len != 5)
		return FALSE;

	if (!read_byte (at, end, &sig_type) ||
	    !read_uint32 (at, end, &sig_time) ||
	    !read_bytes (at, end, keyid, 8) ||
	    !read_byte (at, end, &key_algo) ||
	    !read_byte (at, end, &hash_algo) ||
	    !read_uint16 (at, end, &left_bits) ||
	    !skip_signature_mpis (at, end, key_algo))
		return FALSE;

	if (flags & GCR_OPENPGP_PARSE_SIGNATURES) {
		record = _gcr_record_new (GCR_RECORD_SCHEMA_SIG, GCR_RECORD_SIG_MAX, ':');
		_gcr_record_set_uint (record, GCR_RECORD_SIG_ALGO, key_algo);
		value = egg_hex_encode_full (keyid, sizeof (keyid), TRUE, 0, 0);
		_gcr_record_take_raw (record, GCR_RECORD_SIG_KEYID, value);
		_gcr_record_set_ulong (record, GCR_RECORD_SIG_TIMESTAMP, sig_time);
		value = g_strdup_printf ("%02xx", (guint)sig_type);
		_gcr_record_take_raw (record, GCR_RECORD_SIG_CLASS, value);
		g_ptr_array_add (records, record);
	}

	return TRUE;
}
コード例 #28
0
ファイル: nec7210_aux.c プロジェクト: 9072997/wikireader
int nec7210_take_control(gpib_board_t *board, nec7210_private_t *priv, int syncronous)
{
	int i;
	const int timeout = 1000;
	int retval = 0;
	unsigned int adsr_bits = 0;

	if(syncronous)
	{
		write_byte(priv, AUX_TCS, AUXMR);
	}else
		write_byte(priv, AUX_TCA, AUXMR);
	// busy wait until ATN is asserted
	for(i = 0; i < timeout; i++)
	{
		adsr_bits = read_byte(priv, ADSR);
		if((adsr_bits & HR_NATN) == 0)
			break;
		udelay(1);
	}
	// if busy wait has failed, try sleeping
	if( i == timeout )
	{
		for(i = 0; i < HZ; i++)
		{
			set_current_state(TASK_INTERRUPTIBLE);
			if(schedule_timeout(1))
				return -ERESTARTSYS;
			adsr_bits = read_byte(priv, ADSR);
			if((adsr_bits & HR_NATN) == 0)
				break;
		}
		if(i == HZ)
		{
			printk("nec7210: error waiting for ATN\n");
			return -ETIMEDOUT;
		}
	}
	clear_bit( WRITE_READY_BN, &priv->state );
	return retval;
}
コード例 #29
0
ファイル: main.cpp プロジェクト: Eltamih/uvudec
void dump_tree()
{
	uint16_t n_internal_nodes = bitshift_read();

	//Internal node
	if (n_internal_nodes) {
		uint32_t relocation_bitmask;

		//Simply all of the ones with the same prefix
		for (int i = 0; i < n_internal_nodes; ++i) {
			uint32_t n_node_bytes;
			uint32_t cur_relocation_bitmask;
	
			n_node_bytes = read_byte();
			//Only allowed 32 bytes
			if (n_node_bytes > 0x20u)
				err("Too many bytes, leading max 0x20, found 0x%02X\n", n_node_bytes);

			cur_relocation_bitmask = 1 << (n_node_bytes - 1);

			if (n_node_bytes >= 0x10)
				relocation_bitmask = read_relocation_bitmask();
			else
				relocation_bitmask = bitshift_read();

			//Relocations don't appear until the end
			printf_indented("");
			for (uint32_t j = 0; j < n_node_bytes; ++j) {
				if ( cur_relocation_bitmask & relocation_bitmask)
					printf("..");
				else
					printf("%02X", read_byte());
				cur_relocation_bitmask >>= 1;
			}
			printf(":\n");
			inc_indent();
			dump_tree();
			dec_indent();
		}
	//Leaf node
	} else {
コード例 #30
0
ファイル: ec_lpc.c プロジェクト: AdriDlu/coreboot
static int google_chromeec_wait_ready(u16 port)
{
	u8 ec_status = read_byte(port);
	u32 time_count = 0;

	/*
	 * One second is more than plenty for any EC operation to complete
	 * (and the bus accessing/code execution) overhead will make the
	 * timeout even longer.
	 */
#define MAX_EC_TIMEOUT_US 1000000

	while (ec_status &
	       (EC_LPC_CMDR_PENDING | EC_LPC_CMDR_BUSY)) {
		udelay(1);
		if (time_count++ == MAX_EC_TIMEOUT_US)
			return -1;
		ec_status = read_byte(port);
	}
	return 0;
}