int wait_for(Filter *f,unsigned what, unsigned level) { unsigned int b; b=inputByte(); while(((1<<what)&b)!=(level<<what)) { if(filterYield(f)) return 1;//has to reset b=inputByte(); } return 0; }
int handleStateChange(BFState * interp,char command){ switch(command){ case '>': incrementDataPointer(interp); break; case '<': decrementDataPointer(interp); break; case '+': incrementCurrentByte(interp); break; case '-': decrementCurrentByte(interp); break; case '.': outputByte(interp); break; case ',': inputByte(interp); break; case '[': case ']': return 1; default: return 2; } return 0; }
/* asynchronous read processing (without any protocol) */ LOCAL W textRead(void) { W c; while ((c = inputByte(0)) < 0); return (c == CTLC || c == CAN) ? E_CANCEL : c; }
static int wait_for_start_bit(Rs232Filter *f) { unsigned int b; if(f->usart) { do { if(wait_for_edge(&f->f,f->clk,(f->edge^f->inv)&1)) return 1; b=inputByte(); }while(((b>>f->dta)^(f->inv>>1))&1); return 0; } else return wait_for_edge(&f->f,f->dta,(f->inv>>1)&1);
void main(){ //Control LEDs P1_5=0x00; P1_4=0x00; P1_3=0x00; P1_2=0x00; P1_1=0x00; P1_0=0xff; // Ready Status //Byte LEDs P0_0 = 0x00; P0_1 = 0x00; P0_2 = 0x00; P0_3 = 0x00; P0_4 = 0x00; P0_5 = 0x00; P0_6 = 0x00; P0_7 = 0x00; while(1){ if(P3_3 == 0x00 && byteLock <= 2){ currentKey = 1; inputByte(); }else if(P3_4 == 0x00 && byteLock <= 2){ currentKey = 0; inputByte(); }else if(P3_6 == 0x00 && byteCount >= 8){ byteCount = 10; //Enter P1_1=0xff; // busy status on if(P1_2==0x00){ P1_2=0xff; // byte A ready byteLock = 1; resetCount(); }else if(byteLock==1){ P1_3=0xff; // byte B ready byteLock = 2; resetCount(); }else if(byteLock==2){ P1_4=0xff; // byte C ready resetCount(); } }else if(P3_5 == 0x00 && byteCount == 0){ inputByte(); }else{ P1_1=0x00; // busy status off db = 0; } } }
/* XMODEM read processing */ LOCAL W xmodemRead(void) { W i, c, ctlch; UB cksum; if (blkptr < blksz) return blkbuf[blkptr++]; c = 0; ctlch = ACK; if (blkno++ == 0) { /* only for the initial packet transfer */ outputByte(NAK); c = inputByte(SOH1_TMO); ctlch = -1; } for (;;) { // receiving block for (i = 0;;) { if (ctlch >= 0) { // ack/beginning character is transmitted outputByte(ctlch); // leading letter in the ack is extracted c = inputByte(SOH_TMO); } ctlch = NAK; if (c == SOH) {blksz = BLK_SZ; break;} if (c == STX) {blksz = XBLK_SZ; break;} if (c == CAN || c == CTLC) { // cancel transfer // Is CAN followed by another CAN? c = inputByte(IDLE_TMO); if (c < 0 || c == CAN || c == CTLC) return E_CANCEL; } else if (c == EOT) { // end of transmission outputByte(ACK); return E_END; } purgeInput(); // skip data if (++i >= MAX_RETRY) return E_XMODEM; } // read a block number & check if ((i = inputByte(RECV_TMO)) < 0) continue; if ((c = inputByte(RECV_TMO)) < 0) continue; if (i + c != 0xff) continue; if (i != (blkno & 0xff)) { if (i != ((blkno - 1) & 0xff)) return E_XMODEM; // skip if the previous block is read ctlch = ACK; } // read the block itself for (cksum = 0, i = 0; i < blksz; i++) { if ((c = inputByte(RECV_TMO)) < 0) break; cksum += (blkbuf[i] = c); } if (c < 0) continue; // validate checksum if (inputByte(RECV_TMO) == cksum && ctlch != ACK) break; } blkptr = 0; return blkbuf[blkptr++]; }
/* skip until there is no more input */ LOCAL void purgeInput(void) { while (inputByte(IDLE_TMO) >= 0); }