// Initialises the range from a unicode range in string form. bool UnicodeRange::Initialise(const String& unicode_range) { // Check for a 'U+' at the start. if (unicode_range.Length() < 2 || unicode_range[0] != 'U' || unicode_range[1] != '+') return false; // Check if there's a '-' sign; if so, we've got a range. String::size_type separator_index = unicode_range.Find("-", 2); if (separator_index != String::npos) { const char* end = unicode_range.CString() + separator_index; min_codepoint = strtoul(unicode_range.CString() + 2, (char **) &end, 16); end = unicode_range.CString() + unicode_range.Length(); max_codepoint = strtoul(unicode_range.CString() + separator_index + 1, (char **) &end, 16); return min_codepoint <= max_codepoint; } // No range! Check if we have any wildcards. String::size_type wildcard_index = unicode_range.Find("?", 2); if (wildcard_index != String::npos) { String range_min(unicode_range.CString() + 2, unicode_range.CString() + wildcard_index); String range_max(range_min); for (String::size_type i = 0; i < unicode_range.Length() - wildcard_index; ++i) { range_min += "0"; range_max += "F"; } const char* end = range_min.CString() + range_min.Length(); min_codepoint = strtoul(range_min.CString(), (char**) &end, 16); end = range_max.CString() + range_max.Length(); max_codepoint = strtoul(range_max.CString(), (char**) &end, 16); return true; } const char* end = unicode_range.CString() + unicode_range.Length(); min_codepoint = strtoul(unicode_range.CString() + 2, (char**) &end, 16); max_codepoint = min_codepoint; return true; }
ssize_t hfs_read_fork(void* buffer, const HFSFork *fork, size_t block_count, size_t start_block) { int loopCounter = 0; // Fail-safe. // Keep the original request around range request = make_range(start_block, block_count); debug("Reading from CNID %u (%d, %d)", fork->cnid, request.start, request.count); // Sanity checks if (request.count < 1) { error("Invalid request size: %u blocks", request.count); return -1; } if ( request.start > fork->totalBlocks ) { error("Request would begin beyond the end of the file (start block: %u; file size: %u blocks.", request.start, fork->totalBlocks); return -1; } if ( range_max(request) >= fork->totalBlocks ) { request.count = fork->totalBlocks - request.start; request.count = MAX(request.count, 1); debug("Trimmed request to (%d, %d) (file only has %d blocks)", request.start, request.count, fork->totalBlocks); } char* read_buffer; INIT_BUFFER(read_buffer, block_count * fork->hfs.block_size); ExtentList *extentList = fork->extents;; // Keep track of what's left to get range remaining = request; while (remaining.count != 0) { if (++loopCounter > 2000) { Extent *extent = NULL; TAILQ_FOREACH(extent, extentList, extents) { printf("%10zd: %10zd %10zd\n", extent->logicalStart, extent->startBlock, extent->blockCount); } PrintExtentList(extentList, fork->totalBlocks); critical("We're stuck in a read loop: request (%zd, %zd); remaining (%zd, %zd)", request.start, request.count, remaining.start, remaining.count); }
int DInputPad::TokenIn(uint8_t *buf, int len) { int range = range_max(mType); // Setting to unpressed ZeroMemory(&mWheelData, sizeof(wheel_data_t)); mWheelData.steering = range >> 1; mWheelData.clutch = 0xFF; mWheelData.throttle = 0xFF; mWheelData.brake = 0xFF; mWheelData.hatswitch = 0x8; //TODO Atleast GT4 detects DFP then if(sendCrap) { pad_copy_data(mType, buf, mWheelData); sendCrap = false; return len; } PollDevices(); //Allow in both ports but warn in configure dialog that only one DX wheel is supported for now //if(idx == 0){ //mWheelData.steering = 8191 + (int)(GetControl(STEERING, false)* 8191.0f) ; if(calibrating){ //Alternate full extents if (alternate)calidata--; else calidata++; if(calidata>range-1 || calidata < 1) alternate = !alternate; //invert mWheelData.steering = calidata; //pass fake //breakout after 11 seconds if(GetTickCount()-calibrationtime > 11000){ calibrating = false; mWheelData.steering = range >> 1; } }else{
static int usb_pad_poll(PADState *ps, uint8_t *buf, int buflen) { LinuxPADState *s = (LinuxPADState*)ps; uint8_t idx = 1 - s->padState.port; ssize_t len; if(idx > 1) return 0; //invalid port int range = range_max(idx); if(sendCrap) { // Setting to unpressed memset(&wheel_data, 0, sizeof(wheel_data_t)); wheel_data.axis_x = range >> 1; wheel_data.axis_y = 0xFF; wheel_data.axis_z = 0xFF; wheel_data.axis_rz = 0xFF; wheel_data.hatswitch = 0x8; pad_copy_data(idx, buf, wheel_data); sendCrap = false; return len; } // Events are raised if state changes, so keep old generic_data intact //memset(&wheel_data, 0, sizeof(wheel_data_t)); struct js_event event; int wtype = conf.WheelType[idx]; //Non-blocking read sets len to -1 and errno to EAGAIN if no new data //TODO what happens when emulator is paused? while((len = read(s->fd, &event, sizeof(event))) > -1) { //Dbg("Read js len: %d %d\n", len, errno); if (len == sizeof(event)) { // ok if (event.type & JS_EVENT_AXIS) { //Dbg("Axis: %d, %d\n", event.number, event.value); switch(s->axismap[event.number]) { case ABS_X: wheel_data.axis_x = NORM(event.value, range); break; case ABS_Y: wheel_data.axis_y = NORM(event.value, 0xFF); break; case ABS_Z: wheel_data.axis_z = NORM(event.value, 0xFF); break; //case ABS_RX: wheel_data.axis_rx = NORM(event.value, 0xFF); break; //case ABS_RY: wheel_data.axis_ry = NORM(event.value, 0xFF); break; case ABS_RZ: wheel_data.axis_rz = NORM(event.value, 0xFF); break; //FIXME hatswitch mapping //TODO Ignoring diagonal directions case ABS_HAT0X: case ABS_HAT1X: if(event.value < 0 ) //left usually wheel_data.hatswitch = PAD_HAT_W; else if(event.value > 0 ) //right wheel_data.hatswitch = PAD_HAT_E; else wheel_data.hatswitch = PAD_HAT_COUNT; break; case ABS_HAT0Y: case ABS_HAT1Y: if(event.value < 0 ) //up usually wheel_data.hatswitch = PAD_HAT_N; else if(event.value > 0 ) //down wheel_data.hatswitch = PAD_HAT_S; else wheel_data.hatswitch = PAD_HAT_COUNT; break; default: break; } } else if (event.type & JS_EVENT_BUTTON) { //Dbg("Button: %d, %d\n", event.number, event.value); //TODO can have 12 bits for buttons? if(event.number < 10) { //FIXME bit juggling if(event.value) wheel_data.buttons |= 1 << event.number; //on else wheel_data.buttons &= ~(1 << event.number); //off } } } else { Dbg("usb_pad_poll: unknown read error\n"); break; } } //Dbg("call pad_copy_data\n"); pad_copy_data(idx, buf, wheel_data); return buflen; }
static void * combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_shaders, struct pipe_context *pipe, struct pipe_shader_state *shader) { VGboolean declare_input = VG_FALSE; VGint start_const = -1, end_const = 0; VGint start_temp = -1, end_temp = 0; VGint start_sampler = -1, end_sampler = 0; VGint i, current_shader = 0; VGint num_consts, num_temps, num_samplers; struct ureg_program *ureg; struct ureg_src in[2]; struct ureg_src *sampler = NULL; struct ureg_src *constant = NULL; struct ureg_dst out, *temp = NULL; void *p = NULL; for (i = 0; i < num_shaders; ++i) { if (shaders[i]->num_consts) start_const = range_min(start_const, shaders[i]->start_const); if (shaders[i]->num_temps) start_temp = range_min(start_temp, shaders[i]->start_temp); if (shaders[i]->num_samplers) start_sampler = range_min(start_sampler, shaders[i]->start_sampler); end_const = range_max(end_const, shaders[i]->start_const + shaders[i]->num_consts); end_temp = range_max(end_temp, shaders[i]->start_temp + shaders[i]->num_temps); end_sampler = range_max(end_sampler, shaders[i]->start_sampler + shaders[i]->num_samplers); if (shaders[i]->needs_position) declare_input = VG_TRUE; } /* if they're still unitialized, initialize them */ if (start_const < 0) start_const = 0; if (start_temp < 0) start_temp = 0; if (start_sampler < 0) start_sampler = 0; num_consts = end_const - start_const; num_temps = end_temp - start_temp; num_samplers = end_sampler - start_sampler; ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); if (!ureg) return NULL; if (declare_input) { in[0] = ureg_DECL_fs_input(ureg, TGSI_SEMANTIC_POSITION, 0, TGSI_INTERPOLATE_LINEAR); in[1] = ureg_DECL_fs_input(ureg, TGSI_SEMANTIC_GENERIC, 0, TGSI_INTERPOLATE_PERSPECTIVE); } /* we always have a color output */ out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); if (num_consts >= 1) { constant = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_const); for (i = start_const; i < end_const; i++) { constant[i] = ureg_DECL_constant(ureg, i); } } if (num_temps >= 1) { temp = (struct ureg_dst *) malloc(sizeof(struct ureg_dst) * end_temp); for (i = start_temp; i < end_temp; i++) { temp[i] = ureg_DECL_temporary(ureg); } } if (num_samplers >= 1) { sampler = (struct ureg_src *) malloc(sizeof(struct ureg_src) * end_sampler); for (i = start_sampler; i < end_sampler; i++) { sampler[i] = ureg_DECL_sampler(ureg, i); } } while (current_shader < num_shaders) { if ((current_shader + 1) == num_shaders) { shaders[current_shader]->func(ureg, &out, in, sampler, temp, constant); } else { shaders[current_shader]->func(ureg, &temp[0], in, sampler, temp, constant); } current_shader++; } ureg_END(ureg); shader->tokens = ureg_finalize(ureg); if(!shader->tokens) return NULL; p = pipe->create_fs_state(pipe, shader); ureg_destroy(ureg); if (num_temps >= 1) { for (i = start_temp; i < end_temp; i++) { ureg_release_temporary(ureg, temp[i]); } } if (temp) free(temp); if (constant) free(constant); if (sampler) free(sampler); return p; }