int SNESpad::buttons(void) { int ret = 0; byte i; strobe(); for (i = 0; i < 16; i++) { ret |= shiftin() << i; } return ~ret; }
byte NESpad::buttons(void) { byte ret = 0; byte i; strobe(); for (i = 0; i < 8; i++) { ret |= shiftin() << i; } return ~ret; }
Sensor::PollState Sensor::Poll() { int l; static unsigned char buf[15]; while (fDevice->available()) { l= shiftin(buf, 15, fDevice->readByte()); switch(l) { case -1: return kPollError; case 0: Parse((char*)buf); } } return kPollSuccess; }
/* ------------------------------------------------------------------- run -- */ int SPECTACLE_BASE :: run() { if (first_time) { /* create segmented input buffer */ int num_segments = (window_len / RTBUFSAMPS) + 2; int extrasamps = RTBUFSAMPS - framesToRun(); if (extrasamps) num_segments++; int inbuf_samps = num_segments * RTBUFSAMPS * inputChannels(); inbuf = new float [inbuf_samps]; for (int i = 0; i < inbuf_samps; i++) inbuf[i] = 0.0; /* Read ptr chases write ptr by <window_len>. Set read ptr to a position <window_len> frames from right end of input buffer. Set write ptr to beginning of buffer, or, if framesToRun() is not the same as the RTcmix buffer size, set it so that the next run invocation after this one will find the write ptr at the start of the second buffer segment. */ inbuf_readptr = inbuf + (inbuf_samps - (window_len * inputChannels())); inbuf_startptr = inbuf + (extrasamps * inputChannels()); inbuf_writeptr = inbuf_startptr; inbuf_endptr = inbuf + inbuf_samps; int outbuf_samps = num_segments * RTBUFSAMPS * outputChannels(); outbuf = new float [outbuf_samps]; for (int i = 0; i < outbuf_samps; i++) outbuf[i] = 0.0; outbuf_readptr = outbuf + (outbuf_samps - (framesToRun() * outputChannels())); outbuf_writeptr = outbuf_readptr; outbuf_endptr = outbuf + outbuf_samps; first_time = 0; DPRINT3("framesToRun()=%d, extrasamps=%d, num_segments=%d\n", framesToRun(), extrasamps, num_segments); DPRINT3("inbuf_samps=%d, inbuf_readptr=%p, inbuf_writeptr=%p\n", inbuf_samps, inbuf_readptr, inbuf_writeptr); DPRINT3("outbuf_samps=%d, outbuf_readptr=%p, outbuf_writeptr=%p\n", outbuf_samps, outbuf_readptr, outbuf_writeptr); } const int insamps = framesToRun() * inputChannels(); if (currentFrame() < total_insamps) rtgetin(inbuf_writeptr, this, insamps); int iterations = framesToRun() / decimation; if (framesToRun() < RTBUFSAMPS) iterations++; DPRINT1("iterations=%d\n", iterations); for (int i = 0; i < iterations; i++) { if (currentFrame() < input_end_frame) { DPRINT1("taking input...cursamp=%d\n", currentFrame()); shiftin(); fold(currentFrame()); JGrfft(fft_buf, half_fft_len, FORWARD); leanconvert(); } else flush_dry_delay(); modify_analysis(); leanunconvert(); JGrfft(fft_buf, half_fft_len, INVERSE); overlapadd(currentFrame()); shiftout(); increment(decimation); } if (currentFrame() < input_end_frame) { inbuf_writeptr += insamps; if (inbuf_writeptr >= inbuf_endptr) inbuf_writeptr = inbuf; } rtbaddout(outbuf_readptr, framesToRun()); outbuf_readptr += framesToRun() * outputChannels(); if (outbuf_readptr >= outbuf_endptr) outbuf_readptr = outbuf; return framesToRun(); }
int PVOC::run() { #ifdef debug printf("PVOC::run\n\n"); #endif // This runs the engine forward until the first buffer of output data is ready (see PVOC::shiftout()). // This compensates for the group delay of the windowed output. int outFramesNeeded = framesToRun(); if (_cachedOutFrames) { int toCopy = min(_cachedOutFrames, outFramesNeeded); if (toCopy >= 0) { #ifdef debug printf("\twriting %d of %d leftover frames from _outbuf at offset %d to rtbaddout\n", toCopy, _cachedOutFrames, _outReadOffset); #endif rtbaddout(&_outbuf[_outReadOffset], toCopy); increment(toCopy); _outReadOffset += toCopy; assert(_outReadOffset <= _outWriteOffset); if (_outReadOffset == _outWriteOffset) _outReadOffset = _outWriteOffset = 0; #ifdef debug printf("\t_outbuf read offset %d, write offset %d\n", _outReadOffset, _outWriteOffset); #endif outFramesNeeded -= toCopy; _cachedOutFrames -= toCopy; } } while (outFramesNeeded > 0) { #ifdef debug printf("\ttop of loop: needed=%d _in=%d _on=%d Nw=%d\n", outFramesNeeded, _in, _on, Nw); #endif /* * analysis: input D samples; window, fold and rotate input * samples into FFT buffer; take FFT; and convert to * amplitude-frequency (phase vocoder) form */ shiftin( _pvInput, Nw, D); /* * increment times */ _in += D; _on += I; if ( Np ) { ::vvmult( winput, Hwin, _pvInput, Nw ); lpcoef[0] = ::lpa( winput, Nw, lpcoef, Np ); /* printf("%.3g/", lpcoef[0] ); */ } ::fold( _pvInput, Wanal, Nw, _fftBuf, N, _in ); ::rfft( _fftBuf, N2, FORWARD ); convert( _fftBuf, channel, N2, D, R ); // if ( I == 0 ) { // if ( Np ) // fwrite( lpcoef, sizeof(float), Np+1, stdout ); // fwrite( channel, sizeof(float), N+2, stdout ); // fflush( stdout ); // /* printf("\n" ); // continue; // } /* * at this point channel[2*i] contains amplitude data and * channel[2*i+1] contains frequency data (in Hz) for phase * vocoder channels i = 0, 1, ... N/2; the center frequency * associated with each channel is i*f, where f is the * fundamental frequency of analysis R/N; any desired spectral * modifications can be made at this point: pitch modifications * are generally well suited to oscillator bank resynthesis, * while time modifications are generally well (and more * efficiently) suited to overlap-add resynthesis */ if (_pvFilter) { _pvFilter->run(channel, N2); } if ( obank ) { /* * oscillator bank resynthesis */ oscbank( channel, N2, lpcoef, Np, R, Nw, I, P, _pvOutput ); #if defined(debug) && 0 printf("osc output (first 16):\n"); for (int x=0; x<16; ++x) printf("%g ",_pvOutput[x]); printf("\n"); #endif shiftout( _pvOutput, Nw, I, _on+Nw-I); } else { /* * overlap-add resynthesis */ unconvert( channel, _fftBuf, N2, I, R ); ::rfft( _fftBuf, N2, INVERSE ); ::overlapadd( _fftBuf, N, Wsyn, _pvOutput, Nw, _on ); // I samples written into _outbuf shiftout( _pvOutput, Nw, I, _on); } // Handle case where last synthesized block extended beyond outFramesNeeded int framesToOutput = ::min(outFramesNeeded, I); #ifdef debug printf("\tbottom of loop. framesToOutput: %d\n", framesToOutput); #endif int framesAvailable = _outWriteOffset - _outReadOffset; framesToOutput = ::min(framesToOutput, framesAvailable); if (framesToOutput > 0) { #ifdef debug printf("\twriting %d frames from offset %d to rtbaddout\n", framesToOutput, _outReadOffset); #endif rtbaddout(&_outbuf[_outReadOffset], framesToOutput); increment(framesToOutput); _outReadOffset += framesToOutput; if (_outReadOffset == _outWriteOffset) _outReadOffset = _outWriteOffset = 0; } _cachedOutFrames = _outWriteOffset - _outReadOffset; #ifdef debug if (_cachedOutFrames > 0) { printf("\tsaving %d samples left over\n", _cachedOutFrames); } printf("\toutbuf read offset %d, write offset %d\n\n", _outReadOffset, _outWriteOffset); #endif outFramesNeeded -= framesToOutput; } /* while (outFramesNeeded > 0) */ return framesToRun(); }
int main(int argc, char *argv[]) { FILE *pass1, *pass2; struct symbol *symb; int r,i,pci,sf; unsigned int start,end; fx = stdout;/*select terminal*/ cmdline(argc, argv); if(a_input) { f1=fopen(a_input, "rb"); if(f1==NULL) { msg(0, "Error: Cannot open %s: %s\n", a_input, strerror(errno)); exit(1); } } else { msg(0, "Error: No input file specified\n"); exit(1); } if(a_syminput) { r=symbol_load_file(a_syminput, 0); if(r) { exit(1); } } if(a_symoutput) { f2=fopen(a_symoutput, "w"); if(f2==NULL) { msg(0, "Error: Cannot create %s: %s\n", a_symoutput, strerror(errno)); exit(1); } } if(a_output==NULL) { f3=stdout; } else { f3=fopen(a_output, "w"); if(f3==NULL) { msg(0, "Error: Cannot create %s: %s\n", a_output, strerror(errno)); exit(1); } } start=a_org; end=a_org+file_len(a_input); if(end==start) { msg(0, "Error: Empty input file\n"); exit(1); } if(end>0x10000) { msg(0, "Error: Binary data outside 16-bit address space\n"); exit(1); } msg(1, "Disassembling binary data at 0x%04x - 0x%04x\n", start, end); block_init(start, end); if(a_blockfile) { r=block_load_file(a_blockfile); if(r) { exit(1); } } /* Temporary files to redirect pass1 and pass2 output. * * This is just a dirty hack to remove a lot of console output on * first two passes by diz80() */ pass1=tmpfile(); if(pass1==NULL) { msg(0, "Error: Cannot create temporary file: %s\n", strerror(errno)); exit(1); } pass2=tmpfile(); if(pass2==NULL) { msg(0, "Error: Cannot create temporary file: %s\n", strerror(errno)); exit(1); } /**************************pass 1*******************************/ /*In pass 1 addresses are calculated, arguments are stored in table*/ msg(1, "Starting pass 1\n"); pass=1; fx=pass1; pc=start; blk_reset(); do { for(i=0;i<T_SIZE;i++) shiftin(); while(1) { pci=disassemble(); if(pci==0) break; FP(fx,"\t\t;%04x",pc); FP(fx,"\n"); for(i=0;i<pci;i++) shiftin(); pc+=pci; } } while(blk_iterate()); /******************************pass 2******************************/ /* In pass 2 a check is made if all arguments stored in the table that are within code area range correspond to instruction addresses. If they do not correspond, they must be changed to the instruction address just before that + offset (could be self modifiing code) */ msg(1, "Starting pass 2\n"); pass=2; fx=pass2; pc=start; blk_reset(); do { for(i=0;i<T_SIZE;i++) shiftin(); while(1) { pci=disassemble(); if(pci==0) break; if(a_labels) { symbol_setlabel(pc,pci); } FP(fx,"\n"); for(i=0;i<pci;i++) shiftin(); pc+=pci; } } while(blk_iterate()); /* remove symbols from the symbol table that: * 1) were added automatically * 2) are not labels */ if(a_labels) { symbol_remove_nonlabels(); } if(f2) { msg(2, "Writing symbol file\n"); symbol_export(f2); fclose(f2); } /***************************pass 3*********************************/ /* In pass 3 the instruction length is again calculated, the instruction start addresses are calculated, these are looked up in the table to see if they correspond to any argument, if they correspond a label is printed before the instruction, made of lxxx where xxx is the hex address of the instruction. */ msg(1, "Starting pass 3\n"); msg(2, "Writing assembly file\n"); pass=3; fx=f3; pc=start; blk_reset(); FP(fx,"; %s\n", PACKAGE_STRING); FP(fx,"; command line:"); for(i=0;i<argc;i++) FP(fx," %s", argv[i]); FP(fx,"\n"); FP(fx,"\n\torg\t0%04xh\n",pc); /* Print required definitions for symbols that are not labels into the * assembly file so that it assembles even when symbol file is not * included */ symbol_export_nonlabels(fx); FP(fx,"\n"); /* Ugly but simplest way do get rid of double label prints at * block boundaries */ sf=1; do { for(i=0;i<T_SIZE;i++) shiftin(); while(1) { /* print a label, if one exists at this address */ if(a_labels && sf) { symb=NULL; while(1) { symb=symbol_find_next(pc, symb); if(symb==NULL) break; if(symb->comment!=NULL) { FP(fx, "%s", symb->comment); } FP(fx,"%s:\n",symb->name); } } sf=1; /* print assembly instruction */ pci=disassemble(); if(pci==0) break; /* current address */ if(a_address||a_source) { FP(fx,"\t\t;%04x",pc); } if(a_source) { /* binary in hex... */ FP(fx,"\t"); for(i=0;i<pci;i++) { FP(fx,"%02x ",t[i]); } /* ...and ASCII */ FP(fx,"\t"); for(i=0;i<pci;i++) { if((t[i] >= 32) && (t[i] < 128)) { FP(fx,"%c ",t[i]); } else { FP(fx,". "); } } }/*end if a_source*/ FP(fx,"\n"); for(i=0;i<pci;i++) shiftin(); pc+=pci; } sf=0; } while(blk_iterate()); fclose(f1); if(a_zilog) { FP(fx,"\n\tend\n"); } if(f_z80) { msg(0, "Warning: Code might not be 8080 compatible!\n"); } if(f_smc) { msg(0, "Warning: Self modifying code detected!\n"); } if(a_output) { fclose(f3); } exit(0); }/*end main*/
void do_mct(char *amode, int akeysz, int numkeys, unsigned char *akey,unsigned char *ivec, int dir, unsigned char *text, int len, FILE *rfp) { int i,imode; unsigned char nk[4*8]; /* longest key+8 */ unsigned char text0[8]; for (imode=0 ; imode < 6 ; ++imode) if(!strcmp(amode,t_mode[imode])) break; if (imode == 6) { printf("Unrecognized mode: %s\n", amode); EXIT(1); } for(i=0 ; i < 400 ; ++i) { int j; int n; EVP_CIPHER_CTX ctx; int kp=akeysz/64; unsigned char old_iv[8]; fprintf(rfp,"\nCOUNT = %d\n",i); if(kp == 1) OutputValue("KEY",akey,8,rfp,0); else for(n=0 ; n < kp ; ++n) { fprintf(rfp,"KEY%d",n+1); OutputValue("",akey+n*8,8,rfp,0); } if(imode != ECB) OutputValue("IV",ivec,8,rfp,0); OutputValue(t_tag[dir^1],text,len,rfp,imode == CFB1); /* compensate for endianness */ if(imode == CFB1) text[0]<<=7; memcpy(text0,text,8); for(j=0 ; j < 10000 ; ++j) { unsigned char old_text[8]; memcpy(old_text,text,8); if(j == 0) { memcpy(old_iv,ivec,8); DESTest(&ctx,amode,akeysz,akey,ivec,dir,text,text,len); } else { memcpy(old_iv,ctx.iv,8); EVP_Cipher(&ctx,text,text,len); } if(j == 9999) { OutputValue(t_tag[dir],text,len,rfp,imode == CFB1); /* memcpy(ivec,text,8); */ } /* DebugValue("iv",ctx.iv,8); */ /* accumulate material for the next key */ shiftin(nk,text,Sizes[imode]); /* DebugValue("nk",nk,24);*/ if((dir && (imode == CFB1 || imode == CFB8 || imode == CFB64 || imode == CBC)) || imode == OFB) memcpy(text,old_iv,8); if(!dir && (imode == CFB1 || imode == CFB8 || imode == CFB64)) { /* the test specifies using the output of the raw DES operation which we don't have, so reconstruct it... */ for(n=0 ; n < 8 ; ++n) text[n]^=old_text[n]; } } for(n=0 ; n < 8 ; ++n) akey[n]^=nk[16+n]; for(n=0 ; n < 8 ; ++n) akey[8+n]^=nk[8+n]; for(n=0 ; n < 8 ; ++n) akey[16+n]^=nk[n]; if(numkeys < 3) memcpy(&akey[2*8],akey,8); if(numkeys < 2) memcpy(&akey[8],akey,8); DES_set_odd_parity((DES_cblock *)akey); DES_set_odd_parity((DES_cblock *)(akey+8)); DES_set_odd_parity((DES_cblock *)(akey+16)); memcpy(ivec,ctx.iv,8); /* pointless exercise - the final text doesn't depend on the initial text in OFB mode, so who cares what it is? (Who designed these tests?) */ if(imode == OFB) for(n=0 ; n < 8 ; ++n) text[n]=text0[n]^old_iv[n]; } }