bool Playstation3USBController::parse(uint8_t* data, int len, XboxGenericMsg* msg_out) { if (static_cast<size_t>(len) >= sizeof(msg_out->ps3usb)) { msg_out->type = XBOX_MSG_PS3USB; memcpy(&msg_out->ps3usb, data, sizeof(msg_out->ps3usb)); bitswap(msg_out->ps3usb.accl_x); bitswap(msg_out->ps3usb.accl_y); bitswap(msg_out->ps3usb.accl_z); bitswap(msg_out->ps3usb.rot_z); if (false) { log_debug(boost::format("X:%5d Y:%5d Z:%5d RZ:%5d\n") % (static_cast<int>(msg_out->ps3usb.accl_x) - 512) % (static_cast<int>(msg_out->ps3usb.accl_y) - 512) % (static_cast<int>(msg_out->ps3usb.accl_z) - 512) % (static_cast<int>(msg_out->ps3usb.rot_z))); } if (false) { // values are normalized to 1g (-116 is force by gravity) log_debug(boost::format("X:%6.3f Y:%6.3f Z:%6.3f RZ:%6.3f\n") % ((static_cast<int>(msg_out->ps3usb.accl_x) - 512) / 116.0f) % ((static_cast<int>(msg_out->ps3usb.accl_y) - 512) / 116.0f) % ((static_cast<int>(msg_out->ps3usb.accl_z) - 512) / 116.0f) % ((static_cast<int>(msg_out->ps3usb.rot_z) - 5))); } if (false) { std::ostringstream str; str << len << ": "; for(int i = 0; i < len; ++i) { str << boost::format("%02x ") % static_cast<int>(data[i]); } str << std::endl; log_debug(str.str()); } return true; } else { return false; } }
static int set_mcs (char *name, struct ifreq *ifr, int sock, int bitrate, char *filename) { struct yamdrv_ioctl_mcs yammcs; FILE *fptr; int nb, i, type, pos; char buf[256]; yammcs.bitrate = bitrate; fptr = fopen (filename, "r"); if (fptr == NULL) { fprintf (stderr, "%s: file %s not found\n", name, filename); return -1; } pos = 0; while (fgets (buf, sizeof (buf), fptr)) { nb = in2hex (buf + 1); type = in2hex (buf + 7); if (type != 0) continue; for (i = 0; i < nb; i++) { if (pos == YAM_FPGA_SIZE) { fclose (fptr); printf ("fpga bytes are more than %d in %s mcs file\n", YAM_FPGA_SIZE, filename); return -1; } yammcs.bits[pos++] = bitswap (in2hex (buf + 9 + i * 2)); } } fclose (fptr); if (pos != YAM_FPGA_SIZE) { printf ("fpga bytes are not %d in %s mcs file\n", YAM_FPGA_SIZE, filename); return -1; } ifr->ifr_data = (caddr_t) & yammcs; yammcs.cmd = SIOCYAMSMCS; if (ioctl (sock, SIOCDEVPRIVATE, ifr) == -1) { fprintf (stderr, "%s: Error %s (%i), cannot ioctl SIOCYAMSMCS on %s\n", name, strerror (errno), errno, ifr->ifr_name); return -1; } printf ("mcs file %s loaded for bitrate %d\n\n", filename, yammcs.bitrate); return 0; }
/* Receive one block with DMA and bitswap it (chasing bitswap). */ static int receive_block(unsigned char *inbuf, long timeout) { unsigned long buf_end; if (poll_byte(timeout) != DT_START_BLOCK) { write_transfer(dummy, 1); return -1; /* not start of data */ } while (!(SSR1 & SCI_TEND)); /* wait for end of transfer */ SCR1 = 0; /* disable serial */ SSR1 = 0; /* clear all flags */ /* setup DMA channel 0 */ CHCR0 = 0; /* disable */ SAR0 = RDR1_ADDR; DAR0 = (unsigned long) inbuf; DTCR0 = BLOCK_SIZE; CHCR0 = 0x4601; /* fixed source address, RXI1, enable */ DMAOR = 0x0001; SCR1 = (SCI_RE|SCI_RIE); /* kick off DMA */ /* DMA receives 2 bytes more than DTCR2, but the last 2 bytes are not * stored. The first extra byte is available from RDR1 after the DMA ends, * the second one is lost because of the SCI overrun. However, this * behaviour conveniently discards the crc. */ yield(); /* be nice */ /* Bitswap received data, chasing the DMA pointer */ buf_end = (unsigned long)inbuf + BLOCK_SIZE; do { /* Call bitswap whenever (a multiple of) 8 bytes are * available (value optimised by experimentation). */ int swap_now = (DAR0 - (unsigned long)inbuf) & ~0x00000007; if (swap_now) { bitswap(inbuf, swap_now); inbuf += swap_now; } } while ((unsigned long)inbuf < buf_end); while (!(CHCR0 & 0x0002)); /* wait for end of DMA */ while (!(SSR1 & SCI_ORER)); /* wait for the trailing bytes */ SCR1 = 0; serial_mode = SER_DISABLED; write_transfer(dummy, 1); /* send trailer */ last_disk_activity = current_tick; return 0; }
/* Prepare a block for sending by copying it to the next write buffer * and bitswapping it. */ static void send_block_prepare(void) { unsigned char *dest; current_buffer ^= 1; /* toggle buffer */ dest = write_buffer[current_buffer] + 2; memcpy(dest, send_block_addr, BLOCK_SIZE); bitswap(dest, BLOCK_SIZE); send_block_addr += BLOCK_SIZE; }
static uint32_t sm_lcd_transfer(SSISlave *dev, uint32_t data) { lcd_state *s = FROM_SSI_SLAVE(lcd_state, dev); /* XXX QEMU's SPI infrastructure is implicitly MSB-first */ data = bitswap(data); switch(s->state) { case COMMAND: data &= 0xfd; /* Mask VCOM bit */ switch(data) { case 0x01: /* Write Line */ s->state = LINENO; break; case 0x04: /* Clear Screen */ memset(s->framebuffer, 0, sizeof(*s->framebuffer)); s->redraw = true; break; case 0x00: /* Toggle VCOM */ break; default: /* Simulate confused display controller. */ memset(s->framebuffer, 0x55, sizeof(*s->framebuffer)); s->redraw = true; break; } break; case LINENO: if (data == 0) { s->state = COMMAND; } else { s->fbindex = (data - 1) * NUM_COL_BYTES; s->state = DATA; } break; case DATA: s->framebuffer[s->fbindex++] = data; if (s->fbindex % NUM_COL_BYTES == 0) { s->state = TRAILER; } break; case TRAILER: if (data != 0) { qemu_log_mask(LOG_GUEST_ERROR, "ls013 memory lcd received non-zero data in TRAILER\n"); } s->state = LINENO; s->redraw = true; break; } return 0; }