/* Process a z80 maskable interrupt */ void z80_interrupt() { WORD inttemp; if(IFF1) { z80.halted=0; IFF1=IFF2=0; PUSH16(PCL,PCH); switch(IM) { case 0: PC = 0x0038; tstates+=12; break; case 1: PC = 0x0038; tstates+=13; break; case 2: inttemp=(0x100*I)+0xff; PCL = readbyte(inttemp++); PCH = readbyte(inttemp); tstates+=19; break; default: fprintf(stderr,"Unknown interrupt mode %d\n",IM); exit(1); } } }
void zx8301_device::draw_line_mode8(bitmap_t *bitmap, int y, UINT16 da) { int x = 0; for (int word = 0; word < 64; word++) { UINT8 byte_high = readbyte(da++); UINT8 byte_low = readbyte(da++); for (int pixel = 0; pixel < 4; pixel++) { int red = BIT(byte_low, 7); int green = BIT(byte_high, 7); int blue = BIT(byte_low, 6); int flash = BIT(byte_high, 6); int color = (green << 2) | (red << 1) | blue; if (flash && m_flash) { color = 0; } *BITMAP_ADDR16(bitmap, y, x++) = color; *BITMAP_ADDR16(bitmap, y, x++) = color; byte_high <<= 2; byte_low <<= 2; } } }
void zx8301_device::draw_line_mode8(bitmap_rgb32 &bitmap, int y, UINT16 da) { int x = 0; for (int word = 0; word < 64; word++) { UINT8 byte_high = readbyte(da++); UINT8 byte_low = readbyte(da++); for (int pixel = 0; pixel < 4; pixel++) { int red = BIT(byte_low, 7); int green = BIT(byte_high, 7); int blue = BIT(byte_low, 6); int flash = BIT(byte_high, 6); int color = (green << 2) | (red << 1) | blue; if (flash && m_flash) { color = 0; } bitmap.pix32(y, x++) = PALETTE[color]; bitmap.pix32(y, x++) = PALETTE[color]; byte_high <<= 2; byte_low <<= 2; } } }
static int hx8352_val_get_value(void *data, u64 *val) { unsigned byte=mDevID+RS(1)+RW(1); CS(0); writebyte(byte); byte = readbyte(); //dummy byte = readbyte(); CS(1); *val = byte; printk("[LCDC] reg 0x%X=0x%x\n", regval, (unsigned)*val); return 0; }
static unsigned readreg(unsigned reg) { unsigned byte=mDevID+RS(1)+RW(1); WriteCommand(reg); mdelay(10); CS(0); writebyte(byte); byte = readbyte(); //dummy byte = readbyte(); CS(1); return byte; }
static int marker(Header *h) { int c; while((c=readbyte(h)) == 0) fprint(2, "ReadJPG: skipping zero byte at offset %lld\n", Boffset(h->fd)); if(c != 0xFF) jpgerror(h, "ReadJPG: expecting marker; found 0x%x at offset %lld\n", c, Boffset(h->fd)); while(c == 0xFF) c = readbyte(h); return c; }
/* Process a z80 maskable interrupt */ int z80_interrupt( void ) { /* An interrupt will occur if IFF1 is set and the /INT line hasn't gone high again. On a Timex machine, we also need the SCLD's INTDISABLE to be clear */ if( IFF1 && tstates < machine_current->timings.interrupt_length && !scld_last_dec.name.intdisable ) { /* If interrupts have just been enabled, don't accept the interrupt now, but check after the next instruction has been executed */ if( tstates == z80.interrupts_enabled_at ) { event_add( tstates + 1, z80_interrupt_event ); return 0; } if( z80.halted ) { PC++; z80.halted = 0; } IFF1=IFF2=0; writebyte( --SP, PCH ); writebyte( --SP, PCL ); R++; rzx_instructions_offset--; switch(IM) { case 0: PC = 0x0038; tstates += 7; break; case 1: PC = 0x0038; tstates += 7; break; case 2: { libspectrum_word inttemp=(0x100*I)+0xff; PCL = readbyte(inttemp++); PCH = readbyte(inttemp); tstates += 7; break; } default: ui_error( UI_ERROR_ERROR, "Unknown interrupt mode %d", IM ); fuse_abort(); } return 1; /* Accepted an interrupt */ } else { return 0; /* Did not accept an interrupt */ } }
static int decodegifblock(int handle, char *buf, int width, int height, char bits, gifblockstruct *gb){ short bits2; short codesize; short codesize2; short nextcode; short thiscode; short oldtoken; short currentcode; short oldcode; short bitsleft; short blocksize; int line = 0; int byte = gb->left; int pass = 0; char *p; char *q; char b[255]; char *u; char *linebuffer; static char firstcodestack[4096]; static char lastcodestack[4096]; static short codestack[4096]; static short wordmasktable[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff }; static short inctable[] = { 8, 8, 4, 2, 0 }; static short startable[] = { 0, 4, 2, 1, 0 }; p = q = b; bitsleft = 8; if (bits < 2 || bits > 8) return 0; // Bad symbol bits2 = 1 << bits; nextcode = bits2 + 2; codesize2 = 1 << (codesize = bits + 1); oldcode = oldtoken = NO_CODE; linebuffer = buf + (gb->top * width); // loop until something breaks for(;;){ if(bitsleft == 8){ if(++p >= q && (((blocksize = readbyte(handle)) < 1) || (q=(p=b) + readpackfile(handle, b, blocksize)) < (b+blocksize))){ return 0; // Unexpected EOF } bitsleft = 0; } thiscode = *p; if((currentcode=(codesize+bitsleft)) <= 8){ *p >>= codesize; bitsleft = currentcode; } else{ if(++p >= q && (((blocksize = readbyte(handle)) < 1) ||
static void save_data( HWND hwndDlg, LONG user_data ) { struct binary_info *info = ( struct binary_info * ) user_data; long start, length; size_t i; libspectrum_byte *buffer; TCHAR *temp_buffer; size_t temp_buffer_len; int error; errno = 0; temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH, WM_GETTEXTLENGTH, 0, 0 ); temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) ); SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_LENGTH, WM_GETTEXT, temp_buffer_len + 1, ( LPARAM ) temp_buffer ); length = _tcstol( temp_buffer, NULL, 10 ); free( temp_buffer ); if( errno || length < 1 || length > 0x10000 ) { ui_error( UI_ERROR_ERROR, "Length must be between 1 and 65536" ); return; } buffer = malloc( length * sizeof( libspectrum_byte ) ); if( !buffer ) { ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ ); return; } errno = 0; temp_buffer_len = SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START, WM_GETTEXTLENGTH, 0, 0 ); temp_buffer = malloc( sizeof( TCHAR ) * ( temp_buffer_len + 1 ) ); SendDlgItemMessage( hwndDlg, IDC_BINARY_EDIT_START, WM_GETTEXT, temp_buffer_len + 1, ( LPARAM ) temp_buffer ); start = _tcstol( temp_buffer, NULL, 10 ); free( temp_buffer ); if( errno || start < 0 || start > 0xffff ) { ui_error( UI_ERROR_ERROR, "Start must be between 0 and 65535" ); return; } if( start + length > 0x10000 ) { ui_error( UI_ERROR_ERROR, "Block ends after address 65535" ); return; } for( i = 0; i < length; i++ ) buffer[ i ] = readbyte( start + i ); error = utils_write_file( info->filename, buffer, length ); if( error ) { free( buffer ); return; } free( buffer ); EndDialog( hwndDlg, 0 ); }
static void handle_gfx_control(anigif_info *info, int n) { int len; int skip; unsigned char buf[4]; // Handle all contained blocks while((len = readbyte(info->info[n].handle)) != 0) { skip = len - 4; if(len > 4) { len = 4; } readpackfile(info->info[n].handle, buf, len); if(skip > 0) { seekpackfile(info->info[n].handle, skip, SEEK_CUR); } if(buf[0] & 1) { info->info[n].transparent = buf[3]; } info->info[n].lastdelay = (buf[2] << 8) | buf[1]; // disposal = (buf[0]>>2) & 7; // inputflag = (buf[0]>>1) & 1; } }
unsigned short readword(FILE * in) { unsigned short value; value=readbyte(in); #ifdef __LITLE__ value=value+(readbyte(in)<<8); #else value=(value<<8)+readbyte(in); #endif return (value); }
unsigned char OSSMidiIn::getmidibyte(){ unsigned char b; do { b=readbyte(); } while (b==0xfe);//drops the Active Sense Messages return(b); };
static void passgifblock(int handle) { int len; // Skip all contained blocks while((len = readbyte(handle)) != 0) seekpackfile(handle, len, SEEK_CUR); }
static int vendercheck(void) { int nv, save, ret; ret = 0; save = isa_port_base; isa_port_base = SENS2_IO_PORT; nv = readbyte(WINBD_VENDID) & 0xFF; if (nv == 0xA3) { writebyte(WINBD_VENDEX, 0x80); nv = readbyte(WINBD_VENDID) & 0xFF; if (nv == 0x5C) ret = 1; } isa_port_base = save; return ret; }
int main(void) { unsigned char a=0; int state = 0; iopl(3); while(1) { a=readbyte(); switch (a){ case 0xf0: switch (state){ case 1: printf("1 was pressed\n"); state = 0; break; case 2: printf("2 was pressed\n"); state = 0; break; case 3: printf("3 was pressed\n"); state = 0; break; case 4: printf("4 was pressed\n"); state =0; break; default: break; } break; case 0x70: state =1; //printf("1 was pressed\n"); break; case 0xb0: state =2; //printf("2 was pressed\n"); break; case 0xd0: state =3; //printf("3 was pressed\n"); break; case 0xe0: state = 4; //printf("A was pressed\n"); break; default: break; } usleep(100000); } return 0; }
static void passgifblock(anigif_info *info, int n) { int len; // Skip all contained blocks while((len = readbyte(info->info[n].handle)) != 0) { seekpackfile(info->info[n].handle, len, SEEK_CUR); } }
//Handle a command as received from GDB. static int ATTR_GDBFN gdbHandleCommand(unsigned char *cmd, int len) { //Handle a command int i, j, k; unsigned char *data=cmd+1; if (cmd[0]=='g') { //send all registers to gdb gdbPacketStart(); gdbPacketHex(iswap(gdbstub_savedRegs.a0), 32); gdbPacketHex(iswap(gdbstub_savedRegs.a1), 32); for (i=2; i<16; i++) gdbPacketHex(iswap(gdbstub_savedRegs.a[i-2]), 32); gdbPacketHex(iswap(gdbstub_savedRegs.pc), 32); gdbPacketHex(iswap(gdbstub_savedRegs.sar), 32); gdbPacketHex(iswap(gdbstub_savedRegs.litbase), 32); gdbPacketHex(iswap(gdbstub_savedRegs.sr176), 32); gdbPacketHex(0, 32); gdbPacketHex(iswap(gdbstub_savedRegs.ps), 32); gdbPacketEnd(); } else if (cmd[0]=='G') { //receive content for all registers from gdb gdbstub_savedRegs.a0=iswap(gdbGetHexVal(&data, 32)); gdbstub_savedRegs.a1=iswap(gdbGetHexVal(&data, 32)); for (i=2; i<16; i++) gdbstub_savedRegs.a[i-2]=iswap(gdbGetHexVal(&data, 32)); gdbstub_savedRegs.pc=iswap(gdbGetHexVal(&data, 32)); gdbstub_savedRegs.sar=iswap(gdbGetHexVal(&data, 32)); gdbstub_savedRegs.litbase=iswap(gdbGetHexVal(&data, 32)); gdbstub_savedRegs.sr176=iswap(gdbGetHexVal(&data, 32)); gdbGetHexVal(&data, 32); gdbstub_savedRegs.ps=iswap(gdbGetHexVal(&data, 32)); gdbPacketStart(); gdbPacketStr("OK"); gdbPacketEnd(); } else if (cmd[0]=='m') { //read memory to gdb i=gdbGetHexVal(&data, -1); data++; j=gdbGetHexVal(&data, -1); gdbPacketStart(); for (k=0; k<j; k++) { gdbPacketHex(readbyte(i++), 8); } gdbPacketEnd(); } else if (cmd[0]=='M') { //write memory from gdb i=gdbGetHexVal(&data, -1); //addr data++; //skip , j=gdbGetHexVal(&data, -1); //length data++; //skip : if (validWrAddr(i) && validWrAddr(i+j)) { for (k=0; k<j; k++) { writeByte(i, gdbGetHexVal(&data, 8)); i++; } //Make sure caches are up-to-date. Procedure according to Xtensa ISA document, ISYNC inst desc. asm volatile("ISYNC\nISYNC\n"); gdbPacketStart(); gdbPacketStr("OK"); gdbPacketEnd(); } else {
void zx8301_device::draw_line_mode4(bitmap_t *bitmap, int y, UINT16 da) { int x = 0; for (int word = 0; word < 64; word++) { UINT8 byte_high = readbyte(da++); UINT8 byte_low = readbyte(da++); for (int pixel = 0; pixel < 8; pixel++) { int red = BIT(byte_low, 7); int green = BIT(byte_high, 7); int color = (green << 1) | red; *BITMAP_ADDR16(bitmap, y, x++) = ZX8301_COLOR_MODE4[color]; byte_high <<= 1; byte_low <<= 1; } } }
static void getfilename(int fd, char *name) { char ch; int ret; /* Skip over spaces */ do { ret = readbyte(fd, &ch); } while (ch == ' ' && ret == 1); /* Concatenate the filename */ while (ret == 1 && ch > ' ') { *name++ = ch; ret = readbyte(fd, &ch); } *name++ = 0; }
boolean ServoShield2::start(void) { Wire.begin(); writebyte(MODE1REG, 0x0); uint8_t mode1regvalue = readbyte(MODE1REG); uint8_t newregvalue = (mode1regvalue & 0x7F) | 0x10; writebyte(MODE1REG, newregvalue); writebyte(PRE_SCALEREG, prescale); writebyte(MODE1REG, mode1regvalue); delay(5); writebyte(MODE1REG, mode1regvalue | 0x80); return true; }
void zx8301_device::draw_line_mode4(bitmap_rgb32 &bitmap, int y, UINT16 da) { int x = 0; for (int word = 0; word < 64; word++) { UINT8 byte_high = readbyte(da++); UINT8 byte_low = readbyte(da++); for (int pixel = 0; pixel < 8; pixel++) { int red = BIT(byte_low, 7); int green = BIT(byte_high, 7); int color = (green << 1) | red; bitmap.pix32(y, x++) = PALETTE[ZX8301_COLOR_MODE4[color]]; byte_high <<= 1; byte_low <<= 1; } } }
int scanhead (FILE * infile, int * image_width, int * image_height) { int marker=0; int dummy=0; if ( getc(infile) != 0xFF || getc(infile) != 0xD8 ) { return 0; } for (;;) { int discarded_bytes=0; readbyte(marker,infile); while (marker != 0xFF) { discarded_bytes++; readbyte(marker,infile); } do readbyte(marker,infile); while (marker == 0xFF); if (discarded_bytes != 0) return 0; switch (marker) { case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC5: case 0xC6: case 0xC7: case 0xC9: case 0xCA: case 0xCB: case 0xCD: case 0xCE: case 0xCF: { readword(dummy,infile); /* usual parameter length count */ readbyte(dummy,infile); readword((*image_height),infile); readword((*image_width),infile); readbyte(dummy,infile); return 1; break; } case 0xDA: case 0xD9: return 0; default: { int length; readword(length,infile); if (length < 2) return 0; length -= 2; while (length > 0) { readbyte(dummy, infile); length--; } // end of while } // end of default break; } // end of switch } // end of for } // end of scanhead
static int trap_load_block( libspectrum_tape_rom_block *block ) { libspectrum_byte parity, *data; int loading, i; /* If the block's too short, give up and go home (with carry reset to indicate error */ if( block->length < DE ) { F = ( F & ~FLAG_C ); return 0; } data = block->data; parity = *data; /* If the flag byte (stored in A') does not match, reset carry and return */ if( *data++ != A_ ) { F = ( F & ~FLAG_C ); return 0; } /* Loading or verifying determined by the carry flag of F' */ loading = ( F_ & FLAG_C ); if( loading ) { for( i=0; i<DE; i++ ) { writebyte( IX+i, *data ); parity ^= *data++; } } else { /* verifying */ for( i=0; i<DE; i++) { parity ^= *data; if( *data++ != readbyte(IX+i) ) { F = ( F & ~FLAG_C ); return 0; } } } /* If the parity byte does not match, reset carry and return */ if( *data++ != parity ) { F = ( F & ~FLAG_C ); return 0; } /* Else return with carry set */ F |= FLAG_C; return 0; }
void sed1330_device::draw_graphics_scanline(bitmap_ind16 &bitmap, const rectangle &cliprect, int y, UINT16 va) { int sx, x; for (sx = 0; sx < m_cr; sx++) { UINT8 data = readbyte(va++); for (x = 0; x < m_fx; x++) { bitmap.pix16(y, (sx * m_fx) + x) = BIT(data, 7); data <<= 1; } } }
unsigned char read_add(unsigned char address)//向地址读一个字节数据 { unsigned char date; start(); writebyte(0xa0);//A0,A1,A2接地,AT24C02芯片地址为1010,送控制字为1010A2A1A0R/~W respons(); writebyte(address); respons(); start(); writebyte(0xa1);//A0,A1,A2接地,AT24C02芯片地址为1010,送控制字为1010A2A1A0R/~W respons(); date = readbyte(); stop(); return date; }
size_t read(int fd, void *ptr, size_t len) { int i; if ( fd != 0 ) { /* It's not the write descriptor */ return -1; } for ( i = 0; i < len ; i++ ) { if ( ( ptr[i] = readbyte(fd) ) == -1 ) { return i; } } return i; }
/******************************************************************************* * function: readdata * Read block of data from given i/o pathes (with timeout) * parameters: * x xmodem handle * bufsize receiver buffer size * checksum accumulated crc * return: data byte or TIMEOUT ******************************************************************************/ static int readdata(xmodem_t *x, int bufsize, int *checksum) { int c; /* character being processed */ unsigned short chksm; /* working copy of checksum */ int j; /* loop index */ chksm = 0; for (j = 0; j < bufsize; j++) { if ((c = readbyte(x->fd, 1)) == TIMEOUT) { /* 1s timeout */ return TIMEOUT; } x->buf[j] = c & 0xff; if (x->crcmode) /* CRC */ chksm = (chksm << B) ^ crctab[(chksm >> (W - B)) ^ c]; else /* checksum */ chksm = ((chksm + c) & 0xff); }
/* Test #5 */ void test_5 (void) { byte data[200]; int n_data = 0; int n_b_seq_1 = sizeof(b_seq_1)/sizeof(b_seq_1[0]); FILE *f; create_byte_file ("test5.txt", b_seq_1, n_b_seq_1); f = fopen("test5.txt", "rb"); if (f == NULL) error("Could not read test5.txt!"); while (n_data < 200) { long b = readbyte(f); if (b < 0) break; data[n_data++] = (byte)b; } fclose(f); compare_byte_seqs(data, n_data, b_seq_1, n_b_seq_1); }
static void gifextension(int handle) { int function; // Get extension function code function = readbyte(handle); // Note: function may be repeated multiple times (size, data, size, data) switch (function) { case 0xF9: // Graphic control handle_gfx_control(handle); return; default: // 0x01 = text // 0xFF = app. extension // 0xFE = comment passgifblock(handle); return; } }
DWORD KInputFile::readdword(void) { DWORD *prslt; char temp[4]; if (m_buflen < m_bufpos + 4 ) { for (int i=0; i<4; i++) temp[i] = readbyte(); prslt = (DWORD *)temp; } else { prslt = (DWORD *) (& m_buffer[m_bufpos]); m_bufpos+= 4; } return *prslt; }