/* Read data starting at address 'addr' (not including the 'write' bit). * Returns 0 on success, 1 on failure. Stops quietly if 'addr' goes out of * bounds. */ void fpga_read (uint8_t addr_hi, uint8_t addr_lo, uint8_t *data, uint8_t n) { uint8_t i = 0; if (addr_hi & 0x80) return; pnCSFPGA(PORT) = 0; /* Transmit the address */ SPDR = addr_hi | 0x80; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); SPDR = addr_lo; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); /* Dummy pause */ SPDR = 0; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); for (i = 0; i < n; ++i) { SPDR = 0; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); data[i] = SPDR; } pnCSFPGA(PORT) = 1; }
//--------------------------------------------------------------------------------- void image8to16trans(sImage* img, u8 transparentColor) { //--------------------------------------------------------------------------------- int i; u8 c; sassert(img->bpp == 8, "image must be 8 bpp"); sassert(img->palette != NULL, "image must have a palette set"); u16* temp = (u16*)malloc(img->height*img->width*2); for(i = 0; i < img->height * img->width; i++) { c = img->image.data8[i]; if(c != transparentColor) temp[i] = img->palette[c] | (1<<15); else temp[i] = img->palette[c]; } free (img->image.data8); free (img->palette); img->palette = NULL; img->bpp = 16; img->image.data16 = temp; }
/* Write data starting at address 'addr' (not including the 'write' bit). * Returns 0 on success, 1 on failure. Stops quietly if 'addr' goes out of * bounds. */ void fpga_write (uint8_t addr_hi, uint8_t addr_lo, const uint8_t *data, uint8_t n) { uint8_t i = 0; if (addr_hi & 0x80) return; pnCSFPGA(PORT) = 0; /* Transmit the address */ SPDR = addr_hi; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); SPDR = addr_lo; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); for (i = 0; i < n; ++i) { SPDR = data[i]; while (!(SPSR & 1<<SPIF)); sassert (!(SPSR & 1<<WCOL)); } pnCSFPGA(PORT) = 1; }
//# CALibrate1:OFFSET ident(1) //# CALibrate2:OFFSET ident(2) void ch_calN_offset (bool arg_valid, uint8_t ident) { (void) arg_valid; inst_t *inst; if (arg_valid) { if (ident == 1) { INST_1.offset = CMD_ARG_NUM; } else if (ident == 2) { INST_2.offset = CMD_ARG_NUM; } else { sassert (0); return; } } else { if (ident == 1) { inst = &INST_1; } else if (ident == 2) { inst = &INST_2; } else { sassert (0); return; } inst_cal_offset (inst, true); } }
void loadFile(const char* filename, u8 * data, uint32 len) { { struct stat results; stat(filename, &results);// == 0 file_size = results.st_size; if(file_size >= 1024*1024*2) { char tmp[128]; siprintf(tmp,"Error!\n File is too large to load.\n Please don't be stupid.\n" "File: %s",filename); sassert(file_size < 1024*1024*2,"Error!\n File is too large to load.\n Please use segment loader.\n"); } } FILE * fp = fopen(filename,"rb"); if(fp == NULL) { char tmp[128]; siprintf(tmp,"File failed to load!\nFile: %s",filename); sassert(fp != NULL,tmp); } uint32 toRead = file_size; if(len < file_size) toRead = len; size_t sz = fread(data,1,toRead,fp); sassert(sz == toRead,"Reading Failed!"); fclose(fp); }
int before_block_exec(CPUState *env, TranslationBlock *tb) { uint64_t count = rr_get_guest_instr_count(); if (!snipping && count+tb->icount > start_count) { sassert((oldlog = fopen(rr_nondet_log->name, "r")), 8); sassert(fread(&orig_last_prog_point, sizeof(RR_prog_point), 1, oldlog) == 1, 9); printf("Original ending prog point: "); rr_spit_prog_point(orig_last_prog_point); actual_start_count = count; printf("Saving snapshot at instr count %lu...\n", count); // Force running state global_state_store_running(); printf("writing snapshot:\t%s\n", snp_name); QIOChannelFile* ioc = qio_channel_file_new_path(snp_name, O_WRONLY | O_CREAT, 0660, NULL); QEMUFile* snp = qemu_fopen_channel_output(QIO_CHANNEL(ioc)); qemu_savevm_state(snp, NULL); qemu_fclose(snp); printf("Beginning cut-and-paste process at prog point:\n"); rr_spit_prog_point(rr_prog_point()); printf("Writing entries to %s...\n", nondet_name); newlog = fopen(nondet_name, "w"); sassert(newlog, 10); // We'll fix this up later. RR_prog_point prog_point = {0}; fwrite(&prog_point.guest_instr_count, sizeof(prog_point.guest_instr_count), 1, newlog); fseek(oldlog, ftell(rr_nondet_log->fp), SEEK_SET); // If there are items in the queue, then start copying the log // from there RR_log_entry *item = rr_get_queue_head(); if (item != NULL) fseek(oldlog, item->header.file_pos, SEEK_SET); while (prog_point.guest_instr_count < end_count && !feof(oldlog)) { prog_point = copy_entry(); } if (!feof(oldlog)) { // prog_point is the first one AFTER what we want printf("Reached end of old nondet log.\n"); } else { printf("Past desired ending point for log.\n"); } snipping = true; printf("Continuing with replay.\n"); } if (snipping && !done && count > end_count) { end_snip(); rr_end_replay_requested = 1; } return 0; }
StreamWriter::StreamWriter(Stream* stream) : TextWriter(null) { sassert(stream != null, String::Format("stream; %s", FrameworkResources::ArgumentNull_Generic)); sassert(stream->CanWrite(), FrameworkResources::NotSupported_UnwritableStream); Init(stream, DefaultBufferSize); }
void scaleAdd(int dest, int const(&c)[3], int scale, int add) { entries[dest].r = (add + c[0] * scale) / 64; entries[dest].g = (add + c[1] * scale) / 64; entries[dest].b = (add + c[2] * scale) / 64; sassert(entries[dest].r < 64); sassert(entries[dest].g < 64); sassert(entries[dest].b < 64); }
void test_sparse_used() { uint b = 14; Hyperloglog *hll = create_hll(b, 0); sassert(hll->sparsed_used == 0); free(hll); hll = create_hll(b, 1); sassert(1 == hll->sparsed_used); sassert(0 == hll->last_index); sassert(1024 == hll->max_values); free(hll); }
StreamWriter::StreamWriter(Stream* stream, const int bufferSize) : TextWriter(null) { sassert(stream != null, "stream cannot be null."); sassert(stream->CanWrite(), FrameworkResources::NotSupported_UnwritableStream); sassert(!(bufferSize < 0), "bufferSize must be non-negative."); Init(stream, bufferSize); }
void logc(char c) { if(!reqPorts) { /* request io-ports for qemu and bochs */ sassert(reqport(0xe9) >= 0); sassert(reqport(0x3f8) >= 0); sassert(reqport(0x3fd) >= 0); reqPorts = true; } while((inbyte(0x3f8 + 5) & 0x20) == 0) ; outbyte(0x3f8,c); }
void test_estimate_cardinality() { uint b = 10; Hyperloglog *hll = mock_hll(b); sassert(3 == estimate_cardinality(hll)); hll->M[54] = 20; sassert(4 == estimate_cardinality(hll)); for (int i = 100; i < 150; i++) { hll->M[i] = i % 20; } sassert(52 == estimate_cardinality(hll)); free(hll); }
int before_block_exec(CPUState *env, TranslationBlock *tb) { uint64_t count = rr_prog_point.guest_instr_count; if (!snipping && count+tb->num_guest_insns > start_count) { sassert((oldlog = fopen(rr_nondet_log->name, "r"))); sassert(fread(&orig_last_prog_point, sizeof(RR_prog_point), 1, oldlog) == 1); printf("Original ending prog point: "); rr_spit_prog_point(orig_last_prog_point); actual_start_count = count; printf("Saving snapshot at instr count %lu...\n", count); do_savevm_rr(get_monitor(), snp_name); printf("Beginning cut-and-paste process at prog point:\n"); rr_spit_prog_point(rr_prog_point); printf("Writing entries to %s...\n", nondet_name); newlog = fopen(nondet_name, "w"); sassert(newlog); // We'll fix this up later. RR_prog_point prog_point = {0, 0, 0}; fwrite(&prog_point, sizeof(RR_prog_point), 1, newlog); fseek(oldlog, ftell(rr_nondet_log->fp), SEEK_SET); RR_log_entry *item = rr_get_queue_head(); while (item != NULL && item->header.prog_point.guest_instr_count < end_count) { write_entry(item); item = item->next; } while (prog_point.guest_instr_count < end_count && !feof(oldlog)) { prog_point = copy_entry(); } if (!feof(oldlog)) { // prog_point is the first one AFTER what we want printf("Reached end of old nondet log.\n"); } else { printf("Past desired ending point for log.\n"); } snipping = true; printf("Continuing with replay.\n"); } if (snipping && !done && count > end_count) { end_snip(); init_timer_alarm(); rr_do_end_replay(0); } return 0; }
void test_sparse_estimate_cardinality() { uint b = 10; Hyperloglog *hll = mock_sparse_hll(b); sassert(3 == estimate_cardinality(hll)); update_sparse_list(hll, 54, 20); sassert(4 == estimate_cardinality(hll)); for (int i = 100; i < 150; i++) { update_sparse_list(hll, i, i % 20); } sassert(52 == estimate_cardinality(hll)); free(hll); }
void remove(SpecKeyT const& k) { T* idx = lookup(k); if(idx) { sassert(idx->is_filled()); idx->make_deleted(); sassert(!idx->is_filled()); --elems; ++deleted; maybe_shrink(); } }
int dcontext_prepare(struct dcontext *dctx) { sassert(dctx); sassert(dctx->d_savefile); CURL *c = dctx->d_handle = curl_easy_init(); curl_easy_reset(c); curl_easy_setopt(c, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, 10L); curl_easy_setopt(c, CURLOPT_FILETIME, 1L); curl_easy_setopt(c, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(c, CURLOPT_LOW_SPEED_LIMIT, 1024L); curl_easy_setopt(c, CURLOPT_LOW_SPEED_TIME, 10L); curl_easy_setopt(c, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); curl_easy_setopt(c, CURLOPT_URL, dctx->d_url); curl_easy_setopt(c, CURLOPT_ERRORBUFFER, &dctx->d_ebuffer[0]); /* no progress for now */ curl_easy_setopt(c, CURLOPT_NOPROGRESS, 1L); #if 0 curl_easy_setopt(c, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(c, CURLOPT_PROGRESSFUNCTION, dcontext_progress_func); curl_easy_setopt(c, CURLOPT_PROGRESSDATA, dctx); #endif /* no header function for now */ #if 0 curl_easy_setopt(c, CURLOPT_HEADERFUNCTION, dcontext_header_func); curl_easy_setopt(c, CURLOPT_WRITEHEADER, dctx); #endif if ((dctx->d_savefp = fopen(dctx->d_savefile, "wb")) == NULL) { goto error; } curl_easy_setopt(c, CURLOPT_WRITEDATA, dctx->d_savefp); return 0; error: fprintf(stderr, "failed: %s\n", strerror(errno)); return -1; }
ExecuteStatus basic_performer(STATE, Task* task, Message& msg) { Symbol* original_name = msg.name; if(!GlobalCacheResolver::resolve(state, msg)) { msg.method_missing = true; msg.name = G(sym_method_missing); msg.priv = true; // lets us look for method_missing anywhere sassert(GlobalCacheResolver::resolve(state, msg)); } // Populate for mono! msg.send_site->module(state, msg.module); msg.send_site->method(state, msg.method); msg.send_site->recv_class(state, msg.lookup_from); msg.send_site->method_missing = msg.method_missing; if(unlikely(msg.method_missing)) { msg.unshift_argument(state, original_name); msg.send_site->performer = mono_mm_performer; } else { msg.send_site->performer = mono_performer; } return msg.method->execute(state, task, msg); }
void decompressStream(const void* data, void* dst, DecompressType type, getByteCallback readCB, getHeaderCallback getHeaderCB) { #ifdef ARM9 sassert(type != LZ77 && type != RLE, "LZ77 and RLE do not support streaming, use Vram versions"); #endif TDecompressionStream decompresStream = { getHeaderCB, 0, readCB }; switch(type) { case LZ77Vram: swiDecompressLZSSVram((void*)data, (void*)dst, 0, &decompresStream); break; case HUFF: swiDecompressHuffman((void*)data, (void*)dst, 0, &decompresStream); break; case RLEVram: swiDecompressRLEVram((void*)data, (void*)dst, 0, &decompresStream); break; default: break; } }
void Hand::reinsert(const Card& c){ sassert(_lastremoved != -1, "Attempting invalid reinsert"); insert(_lastremoved, c); //_lastremoved = -1; }
bool try_insert(T const& v) { std::size_t h = Hash::operator()(v.key()); std::size_t step = 1; do { T& slot = t[h % tsize]; if(!slot.is_filled()) { if(!slot.is_empty()) --deleted; ++elems; slot = v; sassert(slot.is_filled()); return true; } h += step; step += 2; } while(step < 1024); return false; }
StreamWriter::StreamWriter(const String& path) : TextWriter(null) { sassert(path != null, FrameworkResources::ArgumentNull_Path); Stream* stream = CreateFile(path, true); Init(stream, 0x400); }
Display::Display(bool screen_, unsigned char x_, unsigned char y_, unsigned char w_, unsigned char h_) : _screen(screen_), _x(x_), _y(y_), _w(w_), _h(h_), _dirty(true), _enabled(false){ dprint("New Display"); _instances = linkedlistAdd(_instances ? &_instances : NULL, reinterpret_cast<void*>(this)); // ERROR sassert(_instances != NULL, "Insufficient memory for LinkedList"); }
StorageContainer* StorageDevice::OpenContainer(const String& titleName) { sassert(!String::IsNullOrEmpty(titleName), "titleName cannot be null."); // TODO: implement //return new StorageContainer(this, titleName, _deviceIndex, _playerIndex); }
int main() { /** ** The idea is to add one (or more) counter(s) for each loop ** which are (lexicographically) strictly decreasing at each loop iteration ** and then check if their value is bounded from below. **/ int x = nd(); // -- the value of the counter gives a ranking function; // -- in this case the ranking function is a constant int c = 4; while (x >= 0) { // -- the ranking function is strictly decreasing c = c - 1; // -- the ranking function is lower bounded by zero sassert(c >= 0); x = - 2 * x + 10; } return 0; }
/***************************************************************************** * Instrument state: waiting to start */ static void st_wait_to_start (inst_t *inst) { if (!(inst->enabled && inst->running)) { /* Do nothing; we haven't been told to start yet. */ return; } /* Acquisition has been triggered. Load the control flags into * the FPGA and start. */ inst->running_setting = inst->next_setting; switch (inst->running_setting.meas_mode) { case MEAS_DIRECT: _inst_send_gatetime (inst); _inst_send_flags_direct (inst); _inst_send_trigger (inst); break; case MEAS_RECIP: _inst_send_flags_recip (inst); _inst_send_trigger (inst); break; default: sassert (0); /* Invalid acquisition type */ } inst->state = ACQUIRING; }
SpriteScraperRect *HwSpriteScraper::allocRect(OamState *oam) { /* * Look for a free sprite rect */ for (int i=0; i < NUM_SPRITES; i++) { SpriteScraperRect *rect = &rects[i]; if (rect->buffer == NULL) { rect->oam = oam; rect->buffer = oamAllocateGfx(oam, SpriteSize_64x64, SpriteColorFormat_16Color); /* * Do one full clear/render cycle before showing a frame. * Until that cycle is finished, we'll show a blank sprite. */ rect->live = true; rect->livePrev = false; dmaFillHalfWords(0, rect->buffer, rect->width * rect->height / 2); return rect; } } sassert(false, "Out of SpriteScraperRects"); return NULL; }
//# CALibrate1:OFFSET? ident(0x10) //# CALibrate1:SCALE2? ident(0x11) //# CALibrate1:SCALE10? ident(0x12) //# CALibrate2:OFFSET? ident(0x20) //# CALibrate2:SCALE2? ident(0x21) //# CALibrate2:SCALE10? ident(0x22) void ch_calN_P (bool arg_valid, uint8_t ident) { (void) arg_valid; int64_t response; if (ident == 0x10) { response = INST_1.offset; } else if (ident == 0x11) { response = INST_1.scale_2x; } else if (ident == 0x12) { response = INST_1.scale_10x; } else if (ident == 0x20) { response = INST_2.offset; } else if (ident == 0x21) { response = INST_2.scale_2x; } else if (ident == 0x22) { response = INST_2.scale_10x; } else { sassert (0); return; } char buffer[21]; u64toa ((uint64_t) response, buffer); fputs (buffer, user_stdout); fputc ('\n', user_stdout); }
void PutBytes(byte *dst, byte src[], int start_index, int count) { sassert(src != null, String::Format("src; %s", FrameworkResources::ArgumentNull_Generic)); sassert(dst != null, String::Format("dst; %s", FrameworkResources::ArgumentNull_Generic)); /*if (start_index < 0 || (start_index > Array::Length(src) - 1)) { #if DEBUG printf("ARGUMENT_OUT_OF_RANGE in function %s, at line %i in file %s, argument \"%s\": %s\n", __FUNCTION__, __LINE__, __FILE__, "startIndex", "Index was out of range. Must be non-negative and less than the size of the collection."); #endif return; }*/ for (int i = 0; i < count; i++) dst[i] = src[i + start_index]; }
static bucket_data_mem* create_from(uint8_t const* b, uint8_t const* e, std::size_t cap_init) { std::size_t s = e - b; sassert(cap_init >= s); bucket_data_mem* ret = create(cap_init, s); std::memcpy(ret->data, b, s); return ret; }
StreamWriter::StreamWriter(const String& path, const bool append, const int bufferSize) : TextWriter(null) { sassert(path != null, FrameworkResources::ArgumentNull_Path); Stream* stream = CreateFile(path, append); Init(stream, bufferSize); }