本文整理汇总了C++中read_word函数的典型用法代码示例。如果您正苦于以下问题:C++ read_word函数的具体用法?C++ read_word怎么用?C++ read_word使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_word函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: seekcompresszip
/* Seek zip->fp to compressed data
return:
==0 success
<0 error
*/
int seekcompresszip(ZIP* zip, struct zipent* ent) {
char buf[ZIPNAME];
long offset;
if (!zip->fp) {
if (!revivezip(zip))
return -1;
}
if (osd_fseek(zip->fp, ent->offset_lcl_hdr_frm_frst_disk, SEEK_SET)!=0) {
errormsg ("Seeking to header", ERROR_CORRUPT, zip->zip);
return -1;
}
if (osd_fread(zip->fp, buf, ZIPNAME)!=ZIPNAME) {
errormsg ("Reading header", ERROR_CORRUPT, zip->zip);
return -1;
}
{
UINT16 filename_length = read_word (buf+ZIPFNLN);
UINT16 extra_field_length = read_word (buf+ZIPXTRALN);
/* calculate offset to data and osd_fseek() there */
offset = ent->offset_lcl_hdr_frm_frst_disk + ZIPNAME + filename_length + extra_field_length;
if (osd_fseek(zip->fp, offset, SEEK_SET) != 0) {
errormsg ("Seeking to compressed data", ERROR_CORRUPT, zip->zip);
return -1;
}
}
return 0;
}
示例2: vbe_biosfn_restore_video_state
void vbe_biosfn_restore_video_state(uint16_t ES, uint16_t BX)
{
uint16_t enable, i;
enable = read_word(ES, BX);
BX += 2;
if (!(enable & VBE_DISPI_ENABLED)) {
outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
outw(VBE_DISPI_IOPORT_DATA, enable);
} else {
outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
BX += 2;
outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
BX += 2;
outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
BX += 2;
outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
outw(VBE_DISPI_IOPORT_DATA, enable);
for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
outw(VBE_DISPI_IOPORT_INDEX, i);
outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
BX += 2;
}
}
}
示例3: read_fat_bs
void read_fat_bs(uint8_t* buf, struct fat_BS* bs) {
memcpy(bs->bootjmp,buf,3);
memcpy(bs->oem_name,buf+3,8);
bs->bytes_per_sector = read_halfword(buf, 11);
bs->sectors_per_cluster = read_byte(buf, 13);
bs->reserved_sector_count = read_halfword(buf, 14);
bs->table_count = read_byte(buf, 16);
bs->root_entry_count = read_halfword(buf, 17);
bs->total_sectors_16 = read_halfword(buf, 19);
bs->media_type = read_byte(buf, 21);
bs->table_size_16 = read_halfword(buf, 22);
bs->sectors_per_track = read_halfword(buf, 24);
bs->head_side_count = read_halfword(buf, 26);
bs->hidden_sector_count = read_word(buf, 28);
bs->total_sectors_32 = read_word(buf, 32);
if (bs->table_size_16==0) {
memcpy(&bs->ext,buf+36,sizeof(struct fat_extBS_32));
} else {
bs->ext.fat16.bios_drive_num = read_byte(buf,36);
bs->ext.fat16.reserved1 = read_byte(buf,37);
bs->ext.fat16.boot_signature = read_byte(buf,38);
bs->ext.fat16.volume_id = read_word(buf,39);
memcpy(&bs->ext.fat16.volume_label,buf+43,11);
memcpy(&bs->ext.fat16.fat_type_label,buf+54,8);
}
}
示例4: reset_registers
static void reset_registers(void) {
uint32_t vectortable = read_word(VECTOR_TABLE_OFFSET);
// R[0..12] = bits(32) UNKNOWN {nop}
SW(&sp_main,read_word(vectortable) & 0xfffffffc);
// sp_process = ((bits(30) UNKNOWN):'00')
SW(&sp_process, SR(&sp_process) & ~0x3);
CORE_reg_write(LR_REG, 0xFFFFFFFF);
uint32_t tmp = read_word(vectortable+4);
bool tbit = tmp & 0x1;
CORE_reg_write(PC_REG, tmp & 0xfffffffe);
if (! (tmp & 0x1) ) {
WARN("Reset vector %08x at %08x invalid\n", tmp, vectortable+4);
CORE_ERR_unpredictable("Thumb bit must be set for M-series\n");
}
// ASPR = bits(32) UNKNOWN {nop}
union ipsr_t ipsr = CORE_ipsr_read();
ipsr.bits.exception = 0;
CORE_ipsr_write(ipsr);
union epsr_t epsr = CORE_epsr_read();
epsr.bits.T = tbit;
epsr.bits.ICI_IT_top = 0;
epsr.bits.ICI_IT_bot = 0;
CORE_epsr_write(epsr);
}
示例5: elf_find_next_higher_section
Elf32_Shdr *
elf_find_next_higher_section(Elf32_Word offset)
{
Elf32_Shdr *section;
Elf32_Shdr *higher;
Elf32_Word sectionsize;
int numsections;
int i = 0;
section = (Elf32_Shdr *)FILE_OFFSET(read_word(elf_header->e_shoff));
sectionsize = read_half(elf_header->e_shentsize);
numsections = read_half(elf_header->e_shnum);
higher = NULL;
for (i=0;i<numsections;i++) {
if (read_word(section->sh_offset) >= offset) {
if (higher == NULL) {
higher = section;
} else if (read_word(section->sh_offset) < read_word(higher->sh_offset)) {
higher = section;
}
}
section = (Elf32_Shdr *)((char *)section + sectionsize);
}
return higher;
}
示例6: enqueue_key
unsigned int enqueue_key(uint8_t scan_code, uint8_t ascii_code)
{
uint16_t buffer_start, buffer_end, buffer_head, buffer_tail, temp_tail;
#if BX_CPU < 2
buffer_start = 0x001E;
buffer_end = 0x003E;
#else
buffer_start = read_word(0x0040, 0x0080);
buffer_end = read_word(0x0040, 0x0082);
#endif
buffer_head = read_word(0x0040, 0x001A);
buffer_tail = read_word(0x0040, 0x001C);
temp_tail = buffer_tail;
buffer_tail += 2;
if (buffer_tail >= buffer_end)
buffer_tail = buffer_start;
if (buffer_tail == buffer_head)
return(0);
write_byte(0x0040, temp_tail, ascii_code);
write_byte(0x0040, temp_tail+1, scan_code);
write_word(0x0040, 0x001C, buffer_tail);
return(1);
}
示例7: emu8k_detect
/* emu8k_detect:
* Locate the EMU8000. This tries to extract the base port from the E section
* of the BLASTER environment variable, and then does some test reads to check
* that there is an EMU8000 there.
*/
int emu8k_detect() {
char *envvar;
if (!(envvar=getenv("BLASTER"))) {
sprintf(allegro_error,"BLASTER environment variable not set");
return 0;
}
_emu8k_baseport=0;
while (*envvar) {
if (*envvar=='E') _emu8k_baseport=strtol(envvar+1,NULL,16);
while ((*envvar!=' ')&&(*envvar!=0)) envvar++;
if (*envvar) envvar++;
}
if (!_emu8k_baseport) {
sprintf(allegro_error,"BLASTER environment variable has no E section");
return 0;
}
sprintf(allegro_error,"AWE32 detection failed on port 0x%04x",_emu8k_baseport);
if ((read_word(7, 0,3)&0x000f)!=0x000c) return 0;
if ((read_word(1,29,1)&0x007e)!=0x0058) return 0;
if ((read_word(1,30,1)&0x0003)!=0x0003) return 0;
*allegro_error=0;
return 1;
}
示例8: get_compressed_data_offset
static zip_error get_compressed_data_offset(zip_file *zip, UINT64 *offset)
{
file_error error;
UINT32 read_length;
/* make sure the file handle is open */
if (zip->file == nullptr)
{
int filerr = osd_open(zip->filename, OPEN_FLAG_READ, &zip->file, &zip->length);
if (filerr != FILERR_NONE)
return ZIPERR_FILE_ERROR;
}
/* now go read the fixed-sized part of the local file header */
error = osd_read(zip->file, zip->buffer, zip->header.local_header_offset, ZIPNAME, &read_length);
if (error != FILERR_NONE || read_length != ZIPNAME)
return (error == FILERR_NONE) ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
/* compute the final offset */
*offset = zip->header.local_header_offset + ZIPNAME;
*offset += read_word(zip->buffer + ZIPFNLN);
*offset += read_word(zip->buffer + ZIPXTRALN);
return ZIPERR_NONE;
}
示例9: opcode_dict_unserialize
void opcode_dict_unserialize(opcode_dict_t od, reader_t r, void* dl_handle) {
long i,j,tot,typtot;
const char* name;
/* read dict header and check it against "DIC" */
name = read_string(r);
assert(!strcmp(name,"DIC"));
/* read number of arrays, check it against OpcodeTypeMax */
typtot = read_word(r);
assert(typtot==OpcodeTypeMax);
/* now for each array */
for(i=0;i<OpcodeTypeMax;i+=1) {
/* read number of records in array */
tot = read_word(r);
/* now for each record */
for(j=0;j<tot;j+=1) {
/* retrieve name */
typtot = read_word(r);
name = read_string(r);
assert(typtot == 1+strlen(name));
opcode_dict_add(od, i, name, opcode_stub_resolve(i,name,dl_handle));
}
/* read END OF RECORD */
typtot = read_word(r);
assert(typtot==0xFFFFFFFF);
}
}
示例10: switch
RegExp::RegExp(char* expression) {
this->operations.reserve(64);
this->transducers.reserve(64);
this->expression = expression;
for (ui i = 0; i < strlen(expression); i++) {
switch(expression[i]) {
case '<': {
char* input = read_word(i);
char* output = read_word(++i);
i+=2;
ui weight = read_number(i);
Monoid monoid(input, output, weight);
this->transducers.push_back(new Transducer(monoid));
}
break;
case '|':
this->operations.push_back(UNION);
break;
case '*':
this->operations.push_back(STAR);
break;
case '.':
this->operations.push_back(CONCAT);
break;
}
}
}
示例11: show_heap
void show_heap(void) {
// TODO: change the code, since i change the heap_tail to one byte after
void* p = heap_head;
DebugStr("-----------------\n");
DebugStr("heap_head = %x, heap size = %u\n",
p, (char*)heap_tail - (char*)heap_head);
DebugStr("-----------------\n");
DebugStr("%x\n", (char*)p + WSIZE);
DebugStr("%x\n", (char*)p + 2 * WSIZE);
DebugStr("-----------------\n");
p = (char*)p + 3 * WSIZE;
assert(p < heap_tail);
while (get_size(p) > 0) {
assert(p < heap_tail);
DebugStr("hdrp:%x val = ", p);
to_hex_str(*(size_t*)p, 1);
DebugStr("size = %u, ALLOC = %d, PREV_ALLOC = %d\n",
get_size(p), !!get_alloc(p), !!get_prev_alloc(p));
void *ftrp = (char*)p + get_size(p) - WSIZE;
DebugStr("ftrp:%x val = ", ftrp);
to_hex_str(*(size_t*)ftrp, 1);
if (!get_alloc(p)) { // if current block is not allocated, header = footer
assert(read_word(p) == read_word(ftrp));
}
DebugStr("-----------------\n");
p += get_size(p);
}
DebugStr("heap_tail = %x\n", p);
DebugStr("-----------------\n");
}
示例12: loadCalibration
void EEPROM::loadCalibration(int16_t * xMin, int16_t * xMax, int16_t * yMin, int16_t * yMax)
{
*xMin = read_word(EEPROM_CAL_XMIN);
*xMax = read_word(EEPROM_CAL_XMAX);
*yMin = read_word(EEPROM_CAL_YMIN);
*yMax = read_word(EEPROM_CAL_YMAX);
}
示例13: elf_find_section_named
Elf32_Shdr *
elf_find_section_named(char *name)
{
Elf32_Shdr *section;
Elf32_Shdr *strtab_section;
Elf32_Word sectionsize;
int numsections;
char *strtab;
int i = 0;
section = (Elf32_Shdr *)FILE_OFFSET(read_word(elf_header->e_shoff));
strtab_section = elf_find_section_num(read_half(elf_header->e_shstrndx));
strtab = (char *)FILE_OFFSET(read_word(strtab_section->sh_offset));
sectionsize = read_half(elf_header->e_shentsize);
numsections = read_half(elf_header->e_shnum);
for (i=0;i<numsections;i++) {
if (strcmp(&strtab[read_word(section->sh_name)], name) == 0) {
return section;
}
section = (Elf32_Shdr *)((char *)section + sectionsize);
}
return NULL;
}
示例14: read_images
/*
* read_images: Reads the images from and mnist image db file and puts the
* images into and array of vectors.
*
* Parameters:
* - train: boolean value, read from training db if 0, test db if 1
*
* Return value:
* - array of vectors containing mnist images
*/
mnist_images_t read_images(uint32_t train)
{
// Set the filename based the mode (train or test)
char *full_path;
if (train) {
full_path = concat_fname(mnist_path, train_image_fname);
} else {
full_path = concat_fname(mnist_path, test_image_fname);
}
// Open the file for reading
char *mode = FILE_MODE;
FILE *fp = Fopen(full_path, mode);
// Read the header of the file
uint8_t header[IMAGE_HEADER_SIZE];
Fread(header, sizeof(uint8_t), IMAGE_HEADER_SIZE, fp);
// Extract size info from mnist db header
uint32_t num_images = read_word(header, NUM_ITEMS_OFFSET);
uint32_t rows = read_word(header, ROW_OFFSET);
uint32_t cols = read_word(header, COL_OFFSET);
uint32_t img_size = rows * cols;
// Create array of mnist image vectors
vector_t *mnist_data = (vector_t*) Calloc(num_images, sizeof(vector_t));
// Populate vectors with one image each
for (uint32_t i = 0; i < num_images; i++) {
mnist_data[i] = Vector((size_t) img_size);
uint8_t *image_bytes = (uint8_t*) Calloc(img_size, sizeof(uint8_t));
uint32_t actual_size;
// Read img_size bytes from the db file into the byte array
if ((actual_size = fread(image_bytes, sizeof(uint8_t), img_size, fp)) < img_size) {
Free(image_bytes);
for (uint32_t i = 0; i < num_images; i++) vector_destroy(mnist_data[i]);
return NULL;
}
// Move 8 bit data to 32 bit integer for more precision
uint32_t *vector_data = (uint32_t*) Calloc(img_size, sizeof(uint32_t));
for (uint32_t j = 0; j < img_size; j++) {
vector_data[j] = (uint32_t) image_bytes[j];
}
mnist_data[i]->data = vector_data;
Free(image_bytes);
}
// Create the mnist_images_t pointer and populate the struct it points to
mnist_images_t mnist_imgs = Mnist_images((size_t) num_images);
mnist_imgs->imgs = mnist_data;
Free(full_path);
Fclose(fp);
return mnist_imgs;
}
示例15: print_bin
print_bin(){
if(dbg.flag != 0)puts("");
return;
printf(" |%04X %04X %04X %04X\n",
read_word(PC-2),
read_word(PC),
read_word(PC+2),
read_word(PC+4));
}