// the only difference here is do_yield() call DWORD unsqu_y (BYTE *i_buf,BYTE *o_buf, void* yield_) { const unsigned int bits[16] = { 1<<15, 1<<14, 1<<13, 1<<12, 1<<11, 1<<10, 1<<9, 1<<8, 1<<7, 1<<6, 1<<5, 1<<4, 1<<3, 1<<2, 1<<1, 1<<0 }; DWORD len; DWORD bit; int span; BYTE* s_fp = i_buf; BYTE* o_ptr = o_buf; void* yield = yield_; int y_count = 4; unsigned int s_buf; int s_count = 0; if (0 == yield_) return unsqu(i_buf,o_buf); fillbitbuf(); while(1){ getbit(bit); if(bit) { *o_ptr++=getbyte(); continue; } getbit(bit); if(!bit) { // len 2-5, span 0-ff getbit(bit); if (bit) len=2; else len=0; getbit(bit); if (bit) len++; len += 2; span=getbyte() | 0xffffff00; } else { span=getbyte(); len=getbyte(); span |= ((len & ~0x07)<<5) | 0xffffe000; len = (len & 0x07)+2; if (len==2) { len=getbyte(); if(len==0) break; // end mark of compressed load module if(len==1) continue; // segment change else len++; } do_yield(); } // "for" works better then memcpy for( ;len>0;len--,o_ptr++) *o_ptr=*(o_ptr+span); } return(o_ptr-o_buf); }
/** Prepares a stream for transmission by appending the checksum. */ stream_t * transmit( stream_t *in, stream_t *gen ) { stream_t *out = stream_new(); // Copy in to out for( int i = 0; i < in->pos; i++ ) { add( out, getbit( in, i ) ); } // Add 0's to the input for( int i = 0; i < gen->pos; i++ ) { add( in, 0 ); } // Store the remainder in reg stream_t *reg = shift_stream( in, gen ); // add remainder to the output for( int i = 0; i < gen->pos; i++ ) { add( out, getbit( reg, i ) ); } return( out ); }
/* * Description in header */ void analyze_hms(bucket_t *b, uint8_t *datatype, uint8_t *obuf, uint8_t *oby) { if (IS868MHZ && *datatype == 0 && b->state == STATE_HMS) { input_t in; in.byte = 0; in.bit = 7; in.data = b->data; if(b->byteidx*8 + (7-b->bitidx) < 69) return; // failed uint8_t crc = 0, i = 0; for(i = 0; i < 6; i++) { obuf[i] = getbits(&in, 8, 0); if(parity_even_bit(obuf[i]) != getbit( &in )) return; // failed if(getbit(&in)) return; // failed crc = crc ^ obuf[i]; } *oby = i; // Read crc uint8_t CRC = getbits(&in, 8, 0); if(parity_even_bit(CRC) != getbit(&in)) return; // failed if(crc!=CRC) return; // failes *datatype = TYPE_HMS; return; // OK } }
/** Updates the feedback register for an incoming bit. */ void update( stream_t *reg, stream_t *gen, char bit ) { //stream_print( reg ); printf( " - %d\n", bit ); char feedback = getbit( reg, 0 ); // leftmost bit is the feedback for( int i = 0; i < reg->pos; i++ ) { char cbit = i == reg->pos - 1? bit : getbit( reg, i + 1 ); char choice = getbit( gen, i ); /** The choice is wether or not to XOR. */ if( 0 == choice ) { setbit( reg, i, cbit ); } else if( 1 == choice ) { setbit( reg, i, cbit ^ feedback ); } else { printf( "Error invalid bit for updating register: '%d'\n", choice ); } } }
void decode(void) { unsigned short i, j, k, r, c; getbit_mask = 0; getbit_buf = 0; for (i = 0; i < N - F; i++) buffer[i] = ' '; r = N - F; while(1) { c = getbit(1); if(dec_in_byte_done) break; if (c) { c = getbit(8); if(dec_in_byte_done) break; dec_out_byte(c); buffer[r++] = c; r &= (N - 1); } else { i = getbit(EI); if(dec_in_byte_done) break; j = getbit(EJ); if(dec_in_byte_done) break; for (k = 0; k <= j + 1; k++) { c = buffer[(i + k) & (N - 1)]; dec_out_byte(c); buffer[r++] = c; r &= (N - 1); } } } }
int main(int argc, char *argv[]) { printf("Entering main()\n"); ShadowMap* my_sm = malloc(sizeof(ShadowMap)); shadow_initialize_with_mmap(my_sm); U8 tmp; shadow_set_bits(my_sm, 0, (U8)0xab); getbyte(0,tmp); print(tmp); assert(tmp == (U8)0xab); shadow_set_bits(my_sm, 0x1111, (U8)0xFF); shadow_unmark_bit(my_sm, 0x1111, 4); getbyte(0x1111,tmp); print(tmp); assert(tmp == (U8)0xEF); // TODO: assert getbit (0x1111,4,tmp); assert(tmp == 0); shadow_set_bits(my_sm, 0xBEEF, (U8)0x00); shadow_mark_bit(my_sm, 0xBEEF, 2); getbyte(0xBEEF,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xBEEF,2,tmp); assert(tmp == 1); printf("----\n"); shadow_set_bits(my_sm, 0xAAFF00AA, (U8)0x00); shadow_mark_bit(my_sm, 0xAAFF00AA, 2); getbyte(0xAAFF00AA,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xAAFF00AA,2,tmp); assert(tmp == 1); shadow_destroy_map(my_sm); free(my_sm); printf("Exiting main()\n"); return 0; }
void ChannelRenderArea::generatePainterPath(void) { int current_x, current_y, oldval, newval; int low = this->height() - 2, high = 2, ch = getChannelNumber(); uint64_t ss = getSampleStart(), se = getSampleEnd(); if (sample_buffer == NULL) return; delete painterPath; painterPath = new QPainterPath(); current_x = 0; oldval = getbit(sample_buffer, 0, ch); current_y = (oldval) ? high : low; painterPath->moveTo(current_x, current_y); for (uint64_t i = ss + 1; i < se; ++i) { current_x += 2; newval = getbit(sample_buffer, i, ch); if (oldval != newval) { painterPath->lineTo(current_x, current_y); current_y = (newval) ? high : low; painterPath->lineTo(current_x, current_y); oldval = newval; } } painterPath->lineTo(current_x, current_y); /* Force a redraw. */ this->update(); }
int main(int argc, char *argv[]) { printf("Entering main()\n"); ShadowMap* my_sm = malloc(sizeof(ShadowMap)); my_sm->shadow_bits = 1; my_sm->application_bits = 1; my_sm->num_distinguished = 1; shadow_initialize_map(my_sm); U8 tmp; shadow_set_bits(my_sm, 0, (U8)0xab); getbyte(0,tmp); print(tmp); assert(tmp == (U8)0xab); shadow_set_bits( my_sm, 0x1111, (U8)0xFF); shadow_unmark_bit(my_sm, 0x1111, 4); getbyte(0x1111,tmp); print(tmp); assert(tmp == (U8)0xEF); // TODO: assert getbit (0x1111,4,tmp); assert(tmp == 0); shadow_set_bits( my_sm, 0xBEEF, (U8)0x00); shadow_mark_bit( my_sm, 0xBEEF, 2); getbyte(0xBEEF,tmp); print(tmp); assert(tmp == (U8)0x04); getbit (0xBEEF,2,tmp); assert(tmp == 1); shadow_destroy_map(my_sm); free(my_sm); printf("Exiting main()\n"); return 0; }
void huff_dc_dec (int *retval) { int i, s, l, p, code; l = 1; code = getbit(); while (code > maxcode_dc[l]) { l++; code = (code << 1) + getbit(); } p = valptr_dc[l]; p = p + code - mincode_dc[l]; s = val_dc_lum[p]; *retval = 0; for (i=0; i<s; i++) *retval = (*retval << 1) + getbit(); i = 1 << (s-1); while (*retval < i) { i = (-1 << s) + 1; *retval = *retval + i; } }
// Returns bitmask of buttons pressed uint8_t get_buttons() { uint8_t mask = 0; if (!getbit(PINB, 0)) mask |= LED0; if (!getbit(PINB, 1)) mask |= LED1; if (!getbit(PIND, 7)) mask |= LED2; if (!getbit(PIND, 6)) mask |= LED3; return mask; }
aldl_data_t *aldl_parse_def(aldl_conf_t *aldl, aldl_record_t *r, int n) { /* check for out of range */ if(n < 0 || n > aldl->n_defs - 1) error(1,ERROR_RANGE, "def number %i is out of range",n); aldl_define_t *def = &aldl->def[n]; /* shortcut to definition */ int id = def->packet; /* packet id (array index) */ aldl_packetdef_t *pkt = &aldl->comm->packet[id]; /* ptr to packet */ /* location of actual data byte */ byte *data = pkt->data + def->offset + pkt->offset; /* location for output of data, matches definition array index ... */ aldl_data_t *out = &r->data[n]; /* location for input of data */ unsigned int x; /* convert input bit size into unsigned integer */ switch(def->size) { case 16: /* turn two 8 bit bytes into a 16 bit int */ x = (unsigned int)((*data<<8)|*(data+1)); break; case 8: /* direct conversion */ default: /* no other types supported, default to 8 bit */ x = (unsigned int)*data; } /* apply any math or whatever and output as desired type */ switch(def->type) { case ALDL_INT: out->i = ( (int)x * def->multiplier.i ) + def->adder.i; if(aldl->minmax == 1) { out->i = rf_clamp_int(def->min.i,def->max.i,out->i); } break; case ALDL_FLOAT: out->f = ( (float)x * def->multiplier.f ) + def->adder.f; if(aldl->minmax == 1) { out->f = rf_clamp_float(def->min.f,def->max.f,out->f); } break; case ALDL_BOOL: if(aldl->comm->byteorder == 1) { /* deal with MSB or LSB */ out->i = getbit(x,(7 - def->binary),def->invert); } else { out->i = getbit(x,def->binary,def->invert); } break; default: error(1,ERROR_RANGE,"invalid type spec: %i",def->type); } return out; }
// Print matrix showing amino acid co-occurence until wildcards void chooseWilds_printOccurenceMatrix(struct wild *wilds, uint4 numWilds) { uint4 count, aa1, aa2, code; uint4 counts[encoding_numLetters][encoding_numLetters]; aa1 = 0; while (aa1 < encoding_numLetters) { aa2 = 0; while (aa2 < encoding_numLetters) { counts[aa1][aa2] = 0; aa2++; } aa1++; } count = 0; while (count < numWilds) { code = wilds[count].code; aa1 = 0; while (aa1 < encoding_numLetters) { aa2 = 0; while (aa2 < encoding_numLetters) { if (getbit(code, aa1) && getbit(code, aa2)) { counts[aa1][aa2] += wilds[count].count; } aa2++; } aa1++; } // printf("%d: ", wilds[count].count); // wildcards_printWildcard(wilds[count].code); count++; } aa1 = 0; while (aa1 < encoding_numLetters) { printf("%c ", encoding_getLetter(aa1)); aa2 = 0; while (aa2 < aa1) { printf("%6d ", counts[aa1][aa2]); aa2++; } printf("\n"); aa1++; } printf(" "); aa2 = 0; while (aa2 < encoding_numLetters) { printf(" %c ", encoding_getLetter(aa2)); aa2++; } printf("\n"); }
i64 naive_rmq(bp *b, i64 s, i64 t,i64 opt) { i64 d,i,dm,im; if (opt & OPT_RIGHT) { d = dm = depth(b,t); im = t; i = t-1; while (i >= s) { if (getbit(b->B,i+1)==CP) { d++; if (opt & OPT_MAX) { if (d > dm) { dm = d; im = i; } } } else { d--; if (!(opt & OPT_MAX)) { if (d < dm) { dm = d; im = i; } } } i--; } } else { d = dm = depth(b,s); im = s; i = s+1; while (i <= t) { if (getbit(b->B,i)==OP) { d++; if (opt & OPT_MAX) { if (d > dm) { dm = d; im = i; } } } else { d--; if (!(opt & OPT_MAX)) { if (d < dm) { dm = d; im = i; } } } i++; } } return im; }
void permuteCD(char *c0, char *d0, char **cd){ int i,j; char c[17][4],d[17][4]; for(i=0;i<4;i++){ c[0][i]=c0[i]; d[0][i]=d0[i]; } printf("\n"); for(i=1;i<17;i++){ for(j=0;j<4;j++){ c[i][j]=c[i-1][j]; d[i][j]=d[i-1][j]; } if(i==1 | i==2 | i==9 | i==16){ clrshift(c[i],1); clrshift(d[i],1); } else{ clrshift(c[i],1); clrshift(d[i],1); clrshift(c[i],1); clrshift(d[i],1); } } int x=0; for(i=0;i<17;i++){ unadjustD(d[i]); for(j=0;j<3;j++){ cd[i][j]=c[i][j]; cd[i][j+4]=d[i][j+1]; } } for(i=0;i<17;i++){ for(j=0;j<4;j++){ if(getbit(c[i][3],7-j,8)==1) cd[i][3]=setbit(cd[i][3],7-j,8); else cd[i][3]=clearbit(cd[i][3],7-j,8); if(getbit(d[i][0],j,8)==1) cd[i][3]=setbit(cd[i][3],j,8); else cd[i][3]=clearbit(cd[i][3],j,8); } } for(i=0;i<17;i++){ for(j=0;j<7;j++){ displayIntToBinary(cd[i][j],8); printf(" "); } printf("\n"); } }
_int queryBloatedBloomSortedFilter(_long firstHash, _long secondHash) { fillHashValuesSorted(firstHash,secondHash); if(!getbit(0))return false; if(!getbit(1))return false; if(!getbit(2))return false; if(!getbit(3))return false; return true; }
INT Huffman_FOB_Codec::geti(INT nbb) { INT res = 0; if (_msbf) for (INT i =0; i<nbb ; i++) res = res*2+getbit(); else for (INT i =0; i<nbb ; i++) res = res+(getbit()<<i); return res; }
char getbyte(void) { if (repeat_counter > 0 ) { --repeat_counter; return current_char; } if (getbit()) repeat_counter = 2 + (getbit() << 2) + (getbit() << 1) + getbit() - 1; current_char = '?'; if (getbit()) { if (getbit()) { if (getbit()) { current_char = '&'; // 111, the barrel already in place } else { current_char = '.'; // 110, the place for a barrel } } else { current_char = '*'; // 10, the barrel } } else { if (getbit()) { current_char = 'X'; // 01, the wall } else { current_char = ' '; // 00, an empty space } } return current_char; }
int get_index(ip_t tbl[], int n, u32_t indx[], u32_t value[]) { int i, j, k, ret; //#if DEBUG int s, t; //#endif /* DEBUG */ u32_t mark[MAX_BIT_NUM]; memset(value, 0, sizeof(value)); memset(mark, 0, sizeof(mark)); for (i = 1, ret = 0; i < n; i++) { PRINTF("i = %d: ", i); for (j = 0; j < ret; j++) { PRINTF("value[%d] = lor(%u, getbit(%u, %u))\n", i, value[i], tbl[i], indx[j]); value[i] = lor(value[i], getbit(tbl[i], indx[j])); PRINTF("value[%d] = %u\n", i, value[i]); } PRINTF("not_same() = %d\n", not_same(value[i], value, i)); if (i > 1 && not_same(value[i], value, i)) continue; PRINTF("Index: "); for (s = 0; s < MAX_BIT_NUM; s++) PRINTF("%u ", indx[s]); PRINTF("\nValue: "); for (s = 0; s < n; s++) PRINTF("%u ", value[s]); PRINTF("\nMark: "); for (s = 0; s < MAX_BIT_NUM; s++) PRINTF("%u ", mark[s]); PRINTF("\n"); for (j = 0; j < MAX_BIT_NUM; j++) { if (!mark[j]) { PRINTF("%2d: ", j); for (k = 0; k <= i; k++) { value[k] = lor(value[k], getbit(tbl[k], j)); PRINTF("value[%d] = %u\t", k, value[k]); } PRINTF("\n"); if (not_same(value[i], value, i)) { indx[ret++] = j; mark[j] = 1; break; } else { for (k = 0; k <= i; k++) value[k] >>= 1; } } } PRINTF("%s\n", j == MAX_BIT_NUM ? "Not found" : "found"); }
int main() { uint8_t buf[2]; buf[0] = 0xaa; nemu_assert(getbit(buf, 0) == 0); nemu_assert(getbit(buf, 1) == 1); nemu_assert(getbit(buf, 2) == 0); nemu_assert(getbit(buf, 3) == 1); nemu_assert(getbit(buf, 4) == 0); nemu_assert(getbit(buf, 5) == 1); nemu_assert(getbit(buf, 6) == 0); nemu_assert(getbit(buf, 7) == 1); setbit(buf, 8, 1); setbit(buf, 9, 0); setbit(buf, 10, 1); setbit(buf, 11, 0); setbit(buf, 12, 1); setbit(buf, 13, 0); setbit(buf, 14, 1); setbit(buf, 15, 0); nemu_assert(buf[1] == 0x55); HIT_GOOD_TRAP; return 0; }
u8 DIO_u8ReadPinVal(u8 copy_u8PinIdx,u8* copy_u8PtrToVal) { u8 Local_u8ReturnedVal; u8 Local_u8PortNumber=(u8)(copy_u8PinIdx/DIO_u8PORTSIZE); u8 Local_u8PinNumber=(u8)(copy_u8PinIdx %DIO_u8PORTSIZE); if ((copy_u8PinIdx < DIO_u8PINSNUM) && (getbit(*DIO_u8ArrToDdrsAddress[Local_u8PortNumber],Local_u8PinNumber)==DIO_u8INPUT)) {Local_u8ReturnedVal=u8OK; *copy_u8PtrToVal=getbit(*DIO_u8ArrToPinsAddress[Local_u8PortNumber],Local_u8PinNumber); } else{ Local_u8ReturnedVal=u8ERROR; } return Local_u8ReturnedVal; }
void ldm1_inst(int inst, ARMProc *proc) { int i; LSMAddrResult *result; LSMAddrResult *(*func)(int, ARMProc *); int register_list; int address; int start_address; int end_address; int value; int **reg; if(!check_condition(proc, inst)) return; register_list = getbits(inst, 0, 16); lsm_addr_modes = lsm_addressing_dict(); reg = &proc->r0; for(i = 0; i < LSM_ADDRESSING_NUMBER; i++) { if(test_inst(lsm_addr_modes[i], inst)) { func = lsm_addr_modes[i]->execute; result = (*func)(inst, proc); break; } } start_address = result->start_address; end_address = result->end_address; address = start_address; for(i = 0; i < 15; i++) { if(getbit(register_list, i)) { **(reg + i) = read_mem(proc, address, 4); address += 4; } } if(getbit(register_list, 15)) { value = read_mem(proc, address, 4); *proc->pc = value & 0xFFFFFFFE; address += 4; } if(end_address != address - 4) { fprintf(stderr, "Load memory error"); } }
getbyte() { int decaleur=0,byte=0,i,bit,sum=0; getbit(); while(getbit()==1); for(i=0;i<8;i++) decaleur=(decaleur<<1)|getbit(); for(i=0;i<8;i++) { bit=decaleur&1; decaleur=decaleur>>1; byte=(byte<<1)|bit; sum+=bit; } if ((sum&1)==getbit() && sync_ok) printf("parity error at offset $%x\n",offset); return byte; }
void MPD_CCIT_T6::read(U_INT1 * res) { _line++; _vals = res; Huff_Ccitt_2D_T6::read(_bin); if (_vals) { for (INT i=0 ; i<_tx ; i++) _vals[i] = (_bin[i] ? 0 : _vmax); } _bin[-1] = 0; _bin[_tx] = 0; _bin[_tx+1] = 1; INT a0 = -1; for(;;) { a0 = end_pl_white(a0); if (a0 >= _tx) { return; } while(getbit()) { a0 = get_plage_gray(a0,false); a0 = a0 +get_length(0); } get_plage_gray(a0,false); while (_bin[a0]) a0++; get_plage_gray(a0,true); } }
void Bitslice ( std::vector<hashtype> & hashes, slice_vec & slices ) { const int hashbytes = sizeof(hashtype); const int hashbits = hashbytes * 8; const int slicelen = ((int)hashes.size() + 31) / 32; slices.clear(); slices.resize(hashbits); for(int i = 0; i < (int)slices.size(); i++) { slices[i].resize(slicelen,0); } for(int j = 0; j < hashbits; j++) { void * sliceblob = &(slices[j][0]); for(int i = 0; i < (int)hashes.size(); i++) { int b = getbit(hashes[i],j); setbit(sliceblob,slicelen*4,i,b); } } }
int h01(int bitpos) { if (getbit(bitpos)) return h011(bitpos+1); else return 65+h(bitpos+1); }
int h011(int bitpos) { if (getbit(bitpos)) return 77+h(bitpos+1); else return 84+h(bitpos+1); }
void pll_enable(void) { //Stolen from LCDdirectLVDSv54: //Stolen from threePinIDer109t: //Set Timer1 to use the "asynchronous clock source" (PLL at 64MHz) // With phase-correct PWM (256 steps up, then back down) and CLKDIV1 // this is 64MHz/512=125kHz // The benefit of such high PWM frequency is the low RC values necessary // for filtering to DC. // "To change Timer/Counter1 to the async mode follow this procedure" // 1: Enable the PLL setbit(PLLE, PLLCSR); // 2: Wait 100us for the PLL to stabilize // (can't use dmsWait since the timer updating the dmsCount // hasn't yet been started!) _delay_us(100); // dmsWait(1); // 3: Poll PLOCK until it is set... while(!getbit(PLOCK, PLLCSR)) { asm("nop"); } // 4: Set the PCKE bit to enable async mode setbit(PCKE, PLLCSR); }
void display_character(char acter[], int row, int col) { // i2c_master_setup(); int len = (int) strlen(acter); // check pixel location for (int i = 0; i < len; i++) { // loop through all characters int index = (int) acter[i] - 0x20; // find character in ASCII[][] for (int j = 0; j < 5; j++) { // loop through columns for (int k = 0; k < 8; k++) { // loop through rows int bit = getbit(index,j,k); // return specific bit from char index, j, k if (bit) { printf("0"); // display_pixel_set(k,j,1); } else { printf(" "); // display_pixel_set(k,j,0); } } printf("\n"); } printf("\n\n"); } // display_draw(); }
int h1(bitpos) { if (getbit(bitpos)) return h11(bitpos+1); else return h10(bitpos+1); }
/* otherwise return zero */ int walk(xxfmt *xx) { int col; /* column coordinate */ int row; /* row coordinate */ int ch; /* input character */ int *p,*q,*r; /* pointers to the random walk array */ /* shift random walk pixels one pixel to the left */ col = 0; p = (int *) xx->newwave; q = (int *) xx->newwave + xx->dpywdth - 1; r = (int *) xx->newwave + 1; while (p < q) { *p = *r; /* erase pixel + 1 */ if (*r != xx->middlerow) /* do not erase the middle row */ { XSetForeground(xx->dpy, xx->gc, xx->whiteColor); XDrawPoint(xx->dpy, xx->w, xx->gc, col+1, *r); } /* if not the red line */ /* copy to pixel + 0 */ if (*p != xx->middlerow) /* do not write over the middle row */ { XSetForeground(xx->dpy, xx->gc, xx->blackColor); XDrawPoint(xx->dpy, xx->w, xx->gc, col, *p); } /* if not the red line */ /* point to next pixel, and repeat loop */ col++; p++; r++; } /* for each pixel in the wave */ ch = getbit(); /* read one random bit from stdin */ /* this program is sometimes used to read a finite */ /* irrational number binary expansion */ /* therefore it sometimes reads to end of file */ if (ch == EOF) return(EOF); /* if end of file, go to end of job */ /* if input bit is '1', raise random walk one pixel */ if (ch == '1') { row = *p + 1; if (row > xx->dpyhght) row = xx->dpyhght; *p = row; } /* if input bit == '1' */ /* if input bit is '0', lower random walk one pixel */ else { row = *p - 1; if (row < 0) row = 0; *p = row; } /* else input bit == '0' */ /* write pixel at end of random walk */ XSetForeground(xx->dpy, xx->gc, xx->blackColor); XDrawPoint(xx->dpy, xx->w, xx->gc, col, row); /* re-write middle line in red */ XSetForeground(xx->dpy, xx->gc, xx->red); XDrawLine(xx->dpy, xx->w, xx->gc, 0, xx->middlerow, xx->dpywdth, xx->middlerow); return(0); /* return not-end-of-file */ } /* walk */