static void read_buffer(input_stream *inp, char **buffer, size_t *length) { *length = next_byte(inp); *buffer = gpr_malloc(*length); for (size_t i = 0; i < *length; i++) { (*buffer)[i] = (char)next_byte(inp); } }
static uint32_t read_uint22(input_stream *inp) { uint8_t b = next_byte(inp); uint32_t x = b & 0x7f; if (b & 0x80) { x <<= 7; b = next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x <<= 8; x |= next_byte(inp); } } return x; }
int sdmmc_write_multiple_blocks(uint32_t address, uint32_t n_blocks, uint8_t (*next_byte)()) { int result; int i; if ((result = sdmmc_cmd(25, block_addressing ? address : address << 9)) < 0) { cs_high(); return result; } spi(0xff); // initiate write while (n_blocks--) { spi(0xfc); // data token for (i = 0; i < 512; i++) { // sector data spi(next_byte()); } spi(0xff); // CRC spi(0xff); result = spi(0xff); // data response if ((result & 0x1f) != 0x05) { cs_high(); return result; } i = 0; do { // wait while card is busy if (++i == 131072) { cs_high(); return -10; } } while (spi(0xff) != 0xff); } return sdmmc_stop_transmission(); }
void ext_op() { Byte op = next_byte(); //printf("%02X", op); (*ext_ops[op])(); }
// --- static AVP_dword DATA_PARAM DATA_Get( Serialize* sz, AVP_Data* dad, AVP_Data** out ) { AVP_byte key_byte; AVP_Property prop; AVP_Data* add; AVP_dword total = sz->tsize; if ( get_byte( sz, &key_byte) != sizeof(key_byte) ) return 0; if ( key_byte & ~(PUT_VAL_PROP|PUT_CHILD_DATA|PUT_NEXT_DATA) ) { _RPT0( _CRT_ASSERT, "Bad stream" ); return 0; } if ( get_avp_property( sz, &prop) != sizeof(prop) ) return 0; *out = (AVP_Data*)DATA_Add( DATA_HANDLE(dad), 0, PROP_ID(&prop), 0, 0 ); if ( *out ) { AVP_Property pr; AVP_dword id; if ( (key_byte&PUT_VAL_PROP) && !PROP_Get(sz,&(*out)->value.data) ) return 0; if ( get_avp_property( sz, &pr) != sizeof(pr) ) return 0; id = PROP_ID(&pr); while( id != AVP_PID_END ) { AVP_Property* ptr = (AVP_Property*)DATA_Add_Prop( DATA_HANDLE(*out), 0, id, 0, 0 ); if ( !ptr ) return 0; if ( !PROP_Get(sz,ptr) ) return 0; if ( get_avp_property( sz, &pr) != sizeof(pr) ) return 0; id = PROP_ID(&pr); } } if ( (key_byte & PUT_CHILD_DATA) && (!DATA_Get(sz,*out,&add)) ) return 0; if ( key_byte & PUT_NEXT_DATA ) { AVP_byte end; while( next_byte(sz) != AVP_NEXT_END ) { if ( !DATA_Get(sz,dad,&add) ) return 0; } get_byte( sz, &end ); } return sz->tsize - total; }
static grpc_channel_args *read_args(input_stream *inp) { size_t n = next_byte(inp); grpc_arg *args = gpr_malloc(sizeof(*args) * n); for (size_t i = 0; i < n; i++) { bool is_string = next_byte(inp) & 1; args[i].type = is_string ? GRPC_ARG_STRING : GRPC_ARG_INTEGER; args[i].key = read_string(inp); if (is_string) { args[i].value.string = read_string(inp); } else { args[i].value.integer = read_int(inp); } } grpc_channel_args *a = gpr_malloc(sizeof(*a)); a->args = args; a->num_args = n; return a; }
unsigned char next_char() { while(1) { unsigned char c = next_byte(); if(c == 0x2a + 0x80 || c == 0x36 + 0x80) { shift = 0; } else if(c == 0x2a || c == 0x36) { shift = 1; } else if(c == 0x1c || c == 0x0e || (c < 0x80 && table[c])) { return c; } } }
static uint32_t read_uint32(input_stream *inp) { uint8_t b = next_byte(inp); uint32_t x = b & 0x7f; if (b & 0x80) { x <<= 7; b = next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x <<= 7; b = next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x <<= 7; b = next_byte(inp); x |= b & 0x7f; if (b & 0x80) { x = (x << 4) | (next_byte(inp) & 0x0f); } } } } return x; }
boolean JSON::Lexer::end_of_array() { unsigned int c = peek_byte(); while (isspace(c)) { next_byte(); c = peek_byte(); } if (c == ']') return true; return false; }
static char *read_string(input_stream *inp) { char *str = NULL; size_t cap = 0; size_t sz = 0; char c; do { if (cap == sz) { cap = GPR_MAX(3 * cap / 2, cap + 8); str = gpr_realloc(str, cap); } c = (char)next_byte(inp); str[sz++] = c; } while (c != 0); return str; }
static void read_metadata(input_stream *inp, size_t *count, grpc_metadata **metadata, call_state *cs) { *count = next_byte(inp); *metadata = gpr_malloc(*count * sizeof(**metadata)); memset(*metadata, 0, *count * sizeof(**metadata)); for (size_t i = 0; i < *count; i++) { (*metadata)[i].key = read_string(inp); read_buffer(inp, (char **)&(*metadata)[i].value, &(*metadata)[i].value_length); (*metadata)[i].flags = read_uint32(inp); add_to_free(cs, (void *)(*metadata)[i].key); add_to_free(cs, (void *)(*metadata)[i].value); } add_to_free(cs, *metadata); }
Json_Token JSON::Lexer::get_token() { unsigned int c = peek_byte(); while (isspace(c)) { next_byte(); c = peek_byte(); } switch (c) { case ':': next_byte(); return Colon_token; case ',': next_byte(); return Comma_token; case '{': next_byte(); return Object_start_token; case '}': next_byte(); return Object_stop_token; case '[': next_byte(); return Array_start_token; case ']': next_byte(); return Array_stop_token; case '"': return get_string(); case '-': case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return get_number(c); default: return get_special(c); } }
Json_Token JSON::Lexer::get_string() { next_byte(); token_src = src; token_len = 0; while (length > 0) { --length; if (*src++ == '"') return String_token; ++token_len; } return Error_token; }
Json_Token JSON::Lexer::get_string() { next_byte(); token_src = (char *)src; token_len = 0; while (length > 0) { --length; if (Strings::get_char(src++) == '"') return String_token; ++token_len; } Serial.println(F("Missing trailing quote mark")); return Error_token; }
Instruction CPU::next_instruction() { char off; Instruction next; next.opcode = next_byte(); int extra_cycles = 0; next.op = ops[next.opcode]; switch (next.op.addr_mode) { case IMM: next.operand = next_byte(); next.args[0] = next.operand; next.arglen = 1; break; case ZP: next.addr = next_byte(); next.operand = get_mem(next.addr); next.args[0] = next.addr; next.arglen = 1; break; case ZP_ST: next.addr = next_byte(); next.args[0] = next.addr; next.arglen = 1; break; case ABS: next.addr = next_word(); next.operand = get_mem(next.addr); next.args[0] = next.addr & 0xff; next.args[1] = (next.addr & 0xff00) >> 8; next.arglen = 2; break; case ABS_ST: next.addr = next_word(); next.args[0] = next.addr & 0xff; next.args[1] = (next.addr & 0xff00) >> 8; next.arglen = 2; break; case ABSI: next.i_addr = next_word(); next.addr = get_mem(next.i_addr) + (get_mem(((next.i_addr+1) & 0xff) | (next.i_addr & 0xff00)) << 8); next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case ABSY: next.i_addr = next_word(); next.addr = (next.i_addr + y) & 0xffff; next.operand = get_mem((next.i_addr&0xff00)|(next.addr&0xff)); if(!next.op.store) { if((next.i_addr & 0xff00) != (next.addr & 0xff00) || next.op.extra_page_cross == 0) { next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } } next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case ABSX: next.i_addr = next_word(); next.addr = (next.i_addr + x) & 0xffff; next.operand = get_mem((next.i_addr&0xff00)|(next.addr&0xff)); if(!next.op.store) { if((next.i_addr & 0xff00) != (next.addr & 0xff00) || next.op.extra_page_cross == 0) { next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } } next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case REL: off = next_byte(); next.addr = off + pc; next.args[0] = off; next.arglen = 1; break; case IXID: next.args[0] = next_byte(); get_mem(next.args[0]); //dummy next.i_addr = (next.args[0] + x) & 0xff; next.addr = (get_mem(next.i_addr) + (get_mem((next.i_addr+1) & 0xff) << 8)); if(!next.op.store) { next.operand = get_mem(next.addr); } next.arglen = 1; break; case IDIX: next.i_addr = next_byte(); next.addr = (get_mem(next.i_addr) + (get_mem((next.i_addr+1)&0xff)<<8)) + y; next.addr &= 0xffff; //fetch from same page next.operand = get_mem(((next.addr-y)&0xff00)|(next.addr&0xff)); if(((next.addr & 0xff00) != ((next.addr - y) & 0xff00) || next.op.extra_page_cross == 0) && !next.op.store) { //fetch correct address next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } next.args[0] = next.i_addr; next.arglen = 1; break; case ZPX: next.i_addr = next_byte(); get_mem(next.i_addr); //dummy next.addr = (next.i_addr + x) & 0xff; if(!next.op.store) { next.operand = get_mem(next.addr); } next.args[0] = next.i_addr; next.arglen = 1; break; case ZPY: next.i_addr = next_byte(); get_mem(next.i_addr); //dummy next.addr = (next.i_addr + y) & 0xff; if(!next.op.store) { next.operand = get_mem(next.addr); } next.args[0] = next.i_addr; next.arglen = 1; break; case IMP: case A: get_mem(pc+1); //dummy read break; default: next.arglen = 0; break; } next.extra_cycles = extra_cycles; return next; }
word CPU::next_word() { return next_byte() | (next_byte() << 8); }
/* perform the actual conversion from png to gba formats */ void png2gba(FILE* in, FILE* out, char* name, int palette, int tileize, char* colorkey) { /* load the image */ struct Image* image = read_png(in); /* write preamble stuff */ fprintf(out, "/* %s.h\n * generated by png2gba program */\n\n", name); fprintf(out, "#define %s_width %d\n", name, image->w); fprintf(out, "#define %s_height %d\n\n", name, image->h); if (palette) { fprintf(out, "const unsigned char %s_data [] = {\n", name); } else { fprintf(out, "const unsigned short %s_data [] = {\n", name); } /* the palette stores up to PALETTE_SIZE colors */ unsigned short color_palette[PALETTE_SIZE]; /* palette sub 0 is reserved for transparent color */ unsigned char palette_size = 1; /* clear the palette */ memset(color_palette, 0, PALETTE_SIZE * sizeof(unsigned short)); /* insert the transparent color */ unsigned short ckey = hex24_to_15(colorkey); color_palette[0] = ckey; /* loop through the pixel data */ unsigned char red, green, blue; int colors_this_line = 0; png_byte* ptr; while ((ptr = next_byte(image, tileize))) { red = ptr[0]; green = ptr[1]; blue = ptr[2]; /* convert to 16-bit color */ unsigned short color = (blue >> 3) << 10; color += (green >> 3) << 5; color += (red >> 3); /* print leading space if first of line */ if (colors_this_line == 0) { fprintf(out, " "); } /* print color directly, or palette index */ if (!palette) { fprintf(out, "0x%04X", color); } else { unsigned char index = insert_palette(color, color_palette, &palette_size); fprintf(out, "0x%02X", index); } fprintf(out, ", "); /* increment colors on line unless too many */ colors_this_line++; if ((palette && colors_this_line >= MAX_ROW8) || (!palette && colors_this_line >= MAX_ROW16)) { fprintf(out, "\n"); colors_this_line = 0; } } /* write postamble stuff */ fprintf(out, "\n};\n\n"); /* write the palette if needed */ if (palette) { int colors_this_line = 0; fprintf(out, "const unsigned short %s_palette [] = {\n", name); int i; for (i = 0; i < PALETTE_SIZE; i++) { if (colors_this_line == 0) { fprintf(out, " "); } fprintf(out, "0x%04x", color_palette[i]); if (i != (PALETTE_SIZE - 1)) { fprintf(out, ", "); } colors_this_line++; if (colors_this_line > 8) { fprintf(out, "\n"); colors_this_line = 0; } } fprintf(out, "\n};\n\n"); } /* close up, we're done */ fclose(out); }
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_test_only_set_metadata_hash_seed(0); if (squelch) gpr_set_log_function(dont_log); input_stream inp = {data, data + size}; grpc_resolve_address = my_resolve_address; grpc_tcp_client_connect_impl = my_tcp_client_connect; gpr_now_impl = now_impl; grpc_init(); GPR_ASSERT(g_channel == NULL); GPR_ASSERT(g_server == NULL); bool server_shutdown = false; int pending_server_shutdowns = 0; int pending_channel_watches = 0; int pending_pings = 0; g_active_call = new_call(NULL, ROOT); grpc_completion_queue *cq = grpc_completion_queue_create(NULL); while (!is_eof(&inp) || g_channel != NULL || g_server != NULL || pending_channel_watches > 0 || pending_pings > 0 || g_active_call->type != ROOT || g_active_call->next != g_active_call) { if (is_eof(&inp)) { if (g_channel != NULL) { grpc_channel_destroy(g_channel); g_channel = NULL; } if (g_server != NULL) { if (!server_shutdown) { grpc_server_shutdown_and_notify( g_server, cq, create_validator(assert_success_and_decrement, &pending_server_shutdowns)); server_shutdown = true; pending_server_shutdowns++; } else if (pending_server_shutdowns == 0) { grpc_server_destroy(g_server); g_server = NULL; } } call_state *s = g_active_call; do { if (s->type != PENDING_SERVER && s->call != NULL) { s = destroy_call(s); } else { s = s->next; } } while (s != g_active_call); g_now = gpr_time_add(g_now, gpr_time_from_seconds(1, GPR_TIMESPAN)); } switch (next_byte(&inp)) { // terminate on bad bytes default: end(&inp); break; // tickle completion queue case 0: { grpc_event ev = grpc_completion_queue_next( cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL); switch (ev.type) { case GRPC_OP_COMPLETE: { validator *v = ev.tag; v->validate(v->arg, ev.success); gpr_free(v); break; } case GRPC_QUEUE_TIMEOUT: break; case GRPC_QUEUE_SHUTDOWN: abort(); break; } break; } // increment global time case 1: { g_now = gpr_time_add( g_now, gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN)); break; } // create an insecure channel case 2: { if (g_channel == NULL) { char *target = read_string(&inp); char *target_uri; gpr_asprintf(&target_uri, "dns:%s", target); grpc_channel_args *args = read_args(&inp); g_channel = grpc_insecure_channel_create(target_uri, args, NULL); GPR_ASSERT(g_channel != NULL); grpc_channel_args_destroy(args); gpr_free(target_uri); gpr_free(target); } else { end(&inp); } break; } // destroy a channel case 3: { if (g_channel != NULL) { grpc_channel_destroy(g_channel); g_channel = NULL; } else { end(&inp); } break; } // bring up a server case 4: { if (g_server == NULL) { grpc_channel_args *args = read_args(&inp); g_server = grpc_server_create(args, NULL); GPR_ASSERT(g_server != NULL); grpc_channel_args_destroy(args); grpc_server_register_completion_queue(g_server, cq, NULL); grpc_server_start(g_server); server_shutdown = false; GPR_ASSERT(pending_server_shutdowns == 0); } else { end(&inp); } } // begin server shutdown case 5: { if (g_server != NULL) { grpc_server_shutdown_and_notify( g_server, cq, create_validator(assert_success_and_decrement, &pending_server_shutdowns)); pending_server_shutdowns++; server_shutdown = true; } else { end(&inp); } break; } // cancel all calls if shutdown case 6: { if (g_server != NULL && server_shutdown) { grpc_server_cancel_all_calls(g_server); } else { end(&inp); } break; } // destroy server case 7: { if (g_server != NULL && server_shutdown && pending_server_shutdowns == 0) { grpc_server_destroy(g_server); g_server = NULL; } else { end(&inp); } break; } // check connectivity case 8: { if (g_channel != NULL) { uint8_t try_to_connect = next_byte(&inp); if (try_to_connect == 0 || try_to_connect == 1) { grpc_channel_check_connectivity_state(g_channel, try_to_connect); } else { end(&inp); } } else { end(&inp); } break; } // watch connectivity case 9: { if (g_channel != NULL) { grpc_connectivity_state st = grpc_channel_check_connectivity_state(g_channel, 0); if (st != GRPC_CHANNEL_FATAL_FAILURE) { gpr_timespec deadline = gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN)); grpc_channel_watch_connectivity_state( g_channel, st, deadline, cq, create_validator(validate_connectivity_watch, make_connectivity_watch( deadline, &pending_channel_watches))); pending_channel_watches++; } } else { end(&inp); } break; } // create a call case 10: { bool ok = true; if (g_channel == NULL) ok = false; grpc_call *parent_call = NULL; if (g_active_call->type != ROOT) { if (g_active_call->call == NULL || g_active_call->type == CLIENT) { end(&inp); break; } parent_call = g_active_call->call; } uint32_t propagation_mask = read_uint32(&inp); char *method = read_string(&inp); char *host = read_string(&inp); gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN)); if (ok) { call_state *cs = new_call(g_active_call, CLIENT); cs->call = grpc_channel_create_call(g_channel, parent_call, propagation_mask, cq, method, host, deadline, NULL); } else { end(&inp); } gpr_free(method); gpr_free(host); break; } // switch the 'current' call case 11: { g_active_call = g_active_call->next; break; } // queue some ops on a call case 12: { if (g_active_call->type == PENDING_SERVER || g_active_call->type == ROOT || g_active_call->call == NULL) { end(&inp); break; } size_t num_ops = next_byte(&inp); if (num_ops > 6) { end(&inp); break; } grpc_op *ops = gpr_malloc(sizeof(grpc_op) * num_ops); bool ok = true; size_t i; grpc_op *op; for (i = 0; i < num_ops; i++) { op = &ops[i]; switch (next_byte(&inp)) { default: /* invalid value */ op->op = (grpc_op_type)-1; ok = false; break; case GRPC_OP_SEND_INITIAL_METADATA: op->op = GRPC_OP_SEND_INITIAL_METADATA; read_metadata(&inp, &op->data.send_initial_metadata.count, &op->data.send_initial_metadata.metadata, g_active_call); break; case GRPC_OP_SEND_MESSAGE: op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message = read_message(&inp); break; case GRPC_OP_SEND_CLOSE_FROM_CLIENT: op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; break; case GRPC_OP_SEND_STATUS_FROM_SERVER: op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; read_metadata( &inp, &op->data.send_status_from_server.trailing_metadata_count, &op->data.send_status_from_server.trailing_metadata, g_active_call); op->data.send_status_from_server.status = next_byte(&inp); op->data.send_status_from_server.status_details = read_string(&inp); break; case GRPC_OP_RECV_INITIAL_METADATA: op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &g_active_call->recv_initial_metadata; break; case GRPC_OP_RECV_MESSAGE: op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &g_active_call->recv_message; break; case GRPC_OP_RECV_STATUS_ON_CLIENT: op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.status = &g_active_call->status; op->data.recv_status_on_client.trailing_metadata = &g_active_call->recv_trailing_metadata; op->data.recv_status_on_client.status_details = &g_active_call->recv_status_details; op->data.recv_status_on_client.status_details_capacity = &g_active_call->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &g_active_call->cancelled; break; } op->reserved = NULL; op->flags = read_uint32(&inp); } if (ok) { validator *v = create_validator(finished_batch, g_active_call); g_active_call->pending_ops++; grpc_call_error error = grpc_call_start_batch(g_active_call->call, ops, num_ops, v, NULL); if (error != GRPC_CALL_OK) { v->validate(v->arg, false); gpr_free(v); } } else { end(&inp); } for (i = 0; i < num_ops; i++) { op = &ops[i]; switch (op->op) { case GRPC_OP_SEND_INITIAL_METADATA: break; case GRPC_OP_SEND_MESSAGE: grpc_byte_buffer_destroy(op->data.send_message); break; case GRPC_OP_SEND_STATUS_FROM_SERVER: gpr_free((void *)op->data.send_status_from_server.status_details); break; case GRPC_OP_SEND_CLOSE_FROM_CLIENT: case GRPC_OP_RECV_INITIAL_METADATA: case GRPC_OP_RECV_MESSAGE: case GRPC_OP_RECV_STATUS_ON_CLIENT: case GRPC_OP_RECV_CLOSE_ON_SERVER: break; } } gpr_free(ops); break; } // cancel current call case 13: { if (g_active_call->type != ROOT && g_active_call->call != NULL) { grpc_call_cancel(g_active_call->call, NULL); } else { end(&inp); } break; } // get a calls peer case 14: { if (g_active_call->type != ROOT && g_active_call->call != NULL) { free_non_null(grpc_call_get_peer(g_active_call->call)); } else { end(&inp); } break; } // get a channels target case 15: { if (g_channel != NULL) { free_non_null(grpc_channel_get_target(g_channel)); } else { end(&inp); } break; } // send a ping on a channel case 16: { if (g_channel != NULL) { pending_pings++; grpc_channel_ping(g_channel, cq, create_validator(decrement, &pending_pings), NULL); } else { end(&inp); } break; } // enable a tracer case 17: { char *tracer = read_string(&inp); grpc_tracer_set_enabled(tracer, 1); gpr_free(tracer); break; } // disable a tracer case 18: { char *tracer = read_string(&inp); grpc_tracer_set_enabled(tracer, 0); gpr_free(tracer); break; } // request a server call case 19: { if (g_server == NULL) { end(&inp); break; } call_state *cs = new_call(g_active_call, PENDING_SERVER); cs->pending_ops++; validator *v = create_validator(finished_request_call, cs); grpc_call_error error = grpc_server_request_call(g_server, &cs->call, &cs->call_details, &cs->recv_initial_metadata, cq, cq, v); if (error != GRPC_CALL_OK) { v->validate(v->arg, false); gpr_free(v); } break; } // destroy a call case 20: { if (g_active_call->type != ROOT && g_active_call->type != PENDING_SERVER && g_active_call->call != NULL) { destroy_call(g_active_call); } else { end(&inp); } break; } } } GPR_ASSERT(g_channel == NULL); GPR_ASSERT(g_server == NULL); GPR_ASSERT(g_active_call->type == ROOT); GPR_ASSERT(g_active_call->next == g_active_call); gpr_free(g_active_call); grpc_completion_queue_shutdown(cq); GPR_ASSERT( grpc_completion_queue_next(cq, gpr_inf_past(GPR_CLOCK_REALTIME), NULL) .type == GRPC_QUEUE_SHUTDOWN); grpc_completion_queue_destroy(cq); grpc_shutdown(); return 0; }
// signed and unsigned integers, and floats Json_Token JSON::Lexer::get_number(unsigned int c) { boolean negative = false; boolean real = false; int d = 0, e = 0; token_src = src; token_len = 0; if (c == '-') { negative = true; next_byte(); c = peek_byte(); } if (c == '.') { next_byte(); real = true; c = peek_byte(); } while (isdigit(c)) { ++d; next_byte(); c = peek_byte(); } if (c == '.') { next_byte(); real = true; c = peek_byte(); } while (isdigit(c)) { ++d; next_byte(); c = peek_byte(); } if (c == 'e' || c == 'E') { if (!d) return Error_token; next_byte(); real = true; c = peek_byte(); } if (c == '-') { next_byte(); c = peek_byte(); } while (isdigit(c)) { ++e; next_byte(); c = peek_byte(); } if (! (d|e)) return Error_token; if (real) { sscanf((const char *)token_src, "%f", &float_num); return Float_token; } if (negative) { sscanf((const char *)token_src, "%d", &signed_num); return Signed_token; } sscanf((const char *)token_src, "%u", &unsigned_num); return Unsigned_token; }
void z80_doframe() { uint32_t frame_time = z80.clock.m + 17556; uint32_t sdl_frame_ticks = SDL_GetTicks() + 1000 / (CLOCK_SPEED / (17556 * 4)); do { if (z80.halt) { z80.regs.m = 4; } else { Byte op = next_byte(); //printf("%02X", op); (*ops[op])(); } z80.clock.m += z80.regs.m; timer_update(z80.regs.m); gpu_step(z80.regs.m); if (z80.regs.ime && mmu.ienable) { z80.halt = 0; Byte ifired = mmu.ienable & mmu.iflag; if (ifired & INT_VBLANK) { //printf("INT_VBLANK\n"); mmu.iflag &= ~INT_VBLANK; interrupt(RST40); } else if (ifired & INT_LCD_STAT) { //printf("INT_LCD_STAT\n"); mmu.iflag &= ~INT_LCD_STAT; interrupt(RST48); } else if (ifired & INT_TIMER) { //printf("INT_TIMER\n"); mmu.iflag &= ~INT_TIMER; interrupt(RST50); } else if (ifired & INT_SERIAL) { //printf("INT_SERIAL\n"); mmu.iflag &= ~INT_SERIAL; interrupt(RST58); } else if (ifired & INT_JOYPAD) { //printf("INT_JOYPAD\n"); mmu.iflag &= ~INT_JOYPAD; interrupt(RST60); } } //printf("AF=%04X ", AF); //printf("BC=%04X ", BC); //printf("DE=%04X ", DE); //printf("HL=%04X ", HL); //printf("PC=%04X ", PC); //printf("SP=%04X ", SP); //printf("T=%d\n", z80.clock.m); } while (z80.clock.m < frame_time); uint32_t sdl_cur_ticks = SDL_GetTicks(); if (sdl_cur_ticks < sdl_frame_ticks) { SDL_Delay(sdl_frame_ticks - sdl_cur_ticks); } }