void GLSLProgram::compileShader(const std::string& filePath, GLuint id) { std::ifstream vertexFile(filePath); if (vertexFile.fail()) { perror(filePath.c_str()); fatalError("Failed to open " + filePath); } std::string fileContents = ""; std::string line; while (std::getline(vertexFile, line)) { fileContents += line + "\n"; } vertexFile.close(); const char* contentsPtr = fileContents.c_str(); glShaderSource(id, 1, &contentsPtr, nullptr); glCompileShader(id); GLint isCompiled = 0; glGetShaderiv(id, GL_COMPILE_STATUS, &isCompiled); if (isCompiled == GL_FALSE) { GLint maxLength = 0; glGetShaderiv(id, GL_INFO_LOG_LENGTH, &maxLength); std::vector<GLchar> errorLog(maxLength); glGetShaderInfoLog(id, maxLength, &maxLength, &errorLog[0]); glDeleteShader(id); std::printf("%s\n", &errorLog[0]); fatalError("Shader" + filePath + " failed to compile."); } }
void enumDisplayMonitors(DeviceInfo displays[], int& displayCounter) { ::Display* dpy = XOpenDisplay(NULL); if (dpy == NULL) { fatalError("Could not open display"); return; } int eventBase; int errorBase; if (XineramaQueryExtension(dpy, &eventBase, &errorBase)) { if (XineramaIsActive(dpy)) { int heads = 0; XineramaScreenInfo* queried = XineramaQueryScreens(dpy, &heads); for (int head = 0; head < heads; ++head) { ++displayCounter; XineramaScreenInfo& info = queried[head]; //log(Info, "Head %i: %ix%i @%i;%i", head + 1, info.width, info.height, info.x_org, info.y_org); DeviceInfo& di = displays[displayCounter]; di.isAvailable = true; di.x = info.x_org; di.y = info.y_org; di.width = info.width; di.height = info.height; // TODO (DK) // -is this always correct? if i switch screens on deb8/jessie with gnome it works ok // -what about other *nix or window managers? di.isPrimary = displayCounter == 0; // TODO (DK) // -this doesn't work yet, whatever is configured as primary is the first screen returned, // not what shows up in the config tool as [1], [2], ... // -and info.screen_number just seems to be useless (0 for first returned, 1 for next, ...) di.number = info.screen_number + 1; } XFree(queried); } else { log(Warning, "Xinerama is not active"); } } else { log(Warning, "Xinerama extension is not installed"); } }
GLTexture ImageLoader::loadPNG(std::string filePath) { GLTexture texture = {}; std::vector<unsigned char> in; std::vector<unsigned char> out; unsigned long width, height; if (IOManager::readFileToBuffer(filePath, in) == false) { fatalError("Failed to load PNG file to buffer!"); } int errorCode = decodePNG(out, width, height, &(in[0]), in.size()); if(errorCode != 0) { fatalError("decodePNG failed with error " + errorCode); } glGenTextures(1, &(texture.id)); glBindTexture(GL_TEXTURE_2D, texture.id); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &(out[0])); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); texture.width = width; texture.height = height; return texture; }
/** * @brief Tests the behavior of malloc() when 0 is passed as the size. * @return 1 on success, 0 on error. */ static int mallocZeroTest(void) { char *p = malloc(0); const char *breakVal = sbrk(0); if (breakVal == (char *) -1) fatalError("sbrk()"); if ((p != NULL) && ((p + MANAGED_SIZE < breakVal + STRUCT_SIZE) || (p >= breakVal))) { puts("Zurueckgelieferter Zeiger ist ungueltig!"); return 0; } free(p); return 1; }
void initialiseOpenGL(){ //initialize GLEW so we can access the modern OpenGL (1.4+) features GLenum err=glewInit(); if(GLEW_OK!=err){ fatalError((const char *)glewGetErrorString(err)); } // set up defaults for OpengGL glClearDepth(1.f);//far depth for HSR glClearColor(0.1f, 0.4f, 0.1f, 1.f); //initial background color glEnable(GL_DEPTH_TEST); //turn on depth testing, Enable Z-buffer read and write }
static void kb_loadKernelKeyMap(_self) { int map; debugf("loading kernel keymap\n"); if (!(self->keyMaps= (unsigned short **)calloc(MAX_NR_KEYMAPS, sizeof(unsigned short *)))) outOfMemory(); for (map= 0; map < MAX_NR_KEYMAPS; ++map) { struct kbentry kb; int key; kb.kb_index= 0; kb.kb_table= map; if (ioctl(self->fd, KDGKBENT, (unsigned long)&kb)) fatalError("KDGKBENT"); if (K_NOSUCHMAP == kb.kb_value) continue; if (!(self->keyMaps[map]= (unsigned short *)calloc(NR_KEYS, sizeof(unsigned short)))) outOfMemory(); for (key= 0; key < NR_KEYS; ++key) { kb.kb_index= key; if (ioctl(self->fd, KDGKBENT, (unsigned long)&kb)) fatalError("KDGKBENT"); self->keyMaps[map][key]= kb.kb_value; } } debugf("kernel keymap loaded\n"); }
const void Cpu::executeJmpOp(const uInt op){ #if DEBUGLEVEL > 2 printf("J-op\n"); #endif switch (GET_OPCODE(op)){ case OPCODE_JAL: mips->r[31] = mips->pc; case OPCODE_J: mips->pc = (mips->pc & 0xf0000000) | GET_JADDR(op); break; default: fatalError("Unknown J-op instruction\n"); } };
GLuint loadShader(GLenum type, const std::string& path) { std::vector<GLchar> buffer; std::ifstream file (path); if (!file.is_open()) { fatalError("Failed to open shader '" + path +"'."); } GLint file_length = 0; file.seekg(0, std::ios::end); file_length = file.tellg(); file.seekg(0, std::ios::beg); buffer.resize(file_length); file.read(buffer.data(), file_length); const GLchar* source = buffer.data(); GLuint shader = glCreateShader(type); glShaderSource(shader, 1, &source, &file_length); glCompileShader(shader); int success = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { int log_length; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length); buffer.resize(log_length); glGetShaderInfoLog(shader, log_length, nullptr, buffer.data()); std::string info_log (buffer.data(), log_length); std::cerr << info_log; fatalError("Failed to compile shader '" + path +"'."); } return shader; }
CoreEngine::GLTexture CoreEngine::ImageLoader::loadPNG(const std::string& filePath) { GLTexture texture = {}; //init everything to zero std::vector<unsigned char> in; std::vector<unsigned char> out; unsigned long width, height; if (!IOManager::readFileToBuffer(filePath, in)) { fatalError("Failed to load PNG file to buffer"); } int errorCode = decodePNG(out, width, height, &in[0], in.size()); if (errorCode) { fatalError("Decode PNG failed with error: " + std::to_string(errorCode)); } //generate the pointer to the id of the texture glGenTextures(1, &texture.id); glBindTexture(GL_TEXTURE_2D, texture.id); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &out[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); texture.width = width; texture.height = height; return texture; }
bool RtspStreamWorker::findStreamInfo(AVFormatContext* context, AVDictionary* options) { AVDictionary **streamOptions = createStreamsOptions(context, options); startInterruptableOperation(20); int errorCode = avformat_find_stream_info(context, streamOptions); destroyStreamOptions(context, streamOptions); if (errorCode < 0) { emit fatalError(QString::fromLatin1("Find stream error: %1").arg(errorMessageFromCode(errorCode))); return false; } return true; }
void appendBytes ( fudge_byte * * target, fudge_i32 * targetsize, const fudge_byte * source, fudge_i32 sourcesize ) { if ( *targetsize ) { /* Target array exists: create a new one large enough for the current data and the new data, then copy across the current data. */ fudge_byte * current = *target; if ( ! ( *target = ( fudge_byte * ) malloc ( sourcesize + *targetsize ) ) ) fatalError ( "Unable to extend memory for file input array" ); memcpy ( *target, current, *targetsize ); free ( current ); } else { /* Target array doesn't exist: create one large enough for the new data */ if ( ! ( *target = ( fudge_byte * ) malloc ( sourcesize ) ) ) fatalError ( "Unable to allocate memory for file input array" ); } /* Append the new data */ memcpy ( *target + *targetsize, source, sourcesize ); *targetsize += sourcesize; }
BaseSequences_t * loadBaseSequences(char * gfilePtr) { // Get an integer pointer to the header information. UINT * gheadPtr = (UINT *) gfilePtr; // Check for expected header information. int versionNumber = gheadPtr[1]; if (gheadPtr[0] != nib2marker || (versionNumber != 1 && versionNumber != 2)) { fatalError("Input nib2 file bad header format."); } // Determine which file version we are dealing with. int BSBlockSize = 12; if (versionNumber == 2) { BSBlockSize = 16; } // Get the number of base sequences. int baseSeqCount = gheadPtr[3]; // Make the return value. BaseSequences_t * BSs = makeBaseSequences(baseSeqCount); // Get a pointer to the start of the base array. BSs->basePtr = gfilePtr + gheadPtr[2]; // Now get the start of the sequence name block. // TODO This calculation should take into account any masked blocks. char * nameStart = gfilePtr + nib2HeaderSize + (BSBlockSize * baseSeqCount) + MSHeaderSize + gheadPtr[nib2HeaderSize/4 + BSBlockSize/4 * baseSeqCount] * MSBlockSize; // Read in the Base Sequences data structure. gheadPtr += 4; UINT totalBaseCount = 0; for (int i=0; i<baseSeqCount; i++) { BaseSequence_t * BS = makeBaseSequence(); BS->startingOffset = gheadPtr[0]; BS->length = gheadPtr[1]; totalBaseCount += BS->length; if (versionNumber == 1) { UINT nameInfo = gheadPtr[2]; BS->name = nameStart + (uint16_t)(nameInfo >> 16); BS->nameLen = nameInfo & (uint16_t)0xFFFF; gheadPtr += 3; } else {
// Memory that is auto-reclaimed across FFI calls char *R_alloc(size_t n, int size) { void *p = R_chk_calloc(n, size); if (tMemTableIndex >= tMemTableLength) { int newLength = 2 * tMemTableLength; void *newtMemTable = malloc(sizeof(void*) * newLength); if (newtMemTable == NULL) { fatalError("malloc failure"); } memcpy(newtMemTable, tMemTable, tMemTableLength * sizeof(void*)); free(tMemTable); tMemTable = newtMemTable; tMemTableLength = newLength; } tMemTable[tMemTableIndex] = p; return (char*) p; }
/* ** Read the entire content of a file into memory */ static char *readFile(const char *zFilename){ FILE *in = fopen(zFilename, "rb"); long sz; char *z; if( in==0 ){ fatalError("cannot open \"%s\" for reading", zFilename); } fseek(in, 0, SEEK_END); sz = ftell(in); rewind(in); z = sqlite3_malloc( sz+1 ); sz = (long)fread(z, 1, sz, in); z[sz] = 0; fclose(in); return z; }
/* ** Prepare an SQL statement. Issue a fatal error if unable. */ static sqlite3_stmt *prepareSql(const char *zFormat, ...){ va_list ap; char *zSql; int rc; sqlite3_stmt *pStmt = 0; va_start(ap, zFormat); zSql = sqlite3_vmprintf(zFormat, ap); va_end(ap); rc = sqlite3_prepare_v2(g.db, zSql, -1, &pStmt, 0); if( rc!=SQLITE_OK ){ sqlite3_finalize(pStmt); fatalError("%s\n%s\n", sqlite3_errmsg(g.db), zSql); } sqlite3_free(zSql); return pStmt; }
void mergesort(ElementType A[], int N) { Resource_logSpace(SPACE_ELEMENT_INT); ElementType *TmpArray; //1 TmpArray = malloc(N * sizeof(ElementType)); Resource_logSpace(N * sizeof(ElementType)); if (TmpArray != NULL) { //1 MSort(A, TmpArray, 0, N - 1); free(TmpArray); //1 Resource_logTime(1); Resource_logSpace(-N * sizeof(ElementType)); } else fatalError( "No space for tmp array!!!" ); Resource_logTime(4); Resource_logSpace(-SPACE_ELEMENT_INT); }
void XTandemInfileXMLHandler::endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) { String tag_close = String(sm_.convert(qname)).trim(); if (tag_.back() != tag_close) { fatalError(LOAD, "Invalid closing/opening tag sequence. Unexpected tag '</ " + tag_close + ">'!"); } if (tag_.back() == "note") { notes_.push_back(actual_note_); // prepare for new note actual_note_ = XTandemInfileNote(); } tag_.pop_back(); }
bool RtspStreamWorker::openInput(AVFormatContext **context, AVDictionary *options) { AVDictionary *optionsCopy = 0; av_dict_copy(&optionsCopy, options, 0); startInterruptableOperation(20); int errorCode = avformat_open_input(context, qPrintable(m_url.toString()), NULL, &optionsCopy); av_dict_free(&optionsCopy); if (errorCode < 0) { emit fatalError(QString::fromLatin1("Open error: %1").arg(errorMessageFromCode(errorCode))); return false; } return true; }
Level::Level(std::string path) : completed_(false), died_(false), path_(path), alarmTriggered_(true), started_(false), musicTimer_() { buffer_.loadFromFile("assets/drone/drone.wav"); music_.openFromFile("assets/music/BOGO.wav"); reverseMusic_.openFromFile("assets/music/BOGOReverse.wav"); if (!lightShader_.loadFromFile("shaders/light.frag", sf::Shader::Fragment)) fatalError("Failed to load light shader\n"); //sound_.setLoop(true); sound_.setAttenuation(1); loadMapData(path); player_ = new Player(playerSpawnPoint_); //drone_ = new Drone({ sf::Vector2f(500,500), sf::Vector2f(10000, 1000) , sf::Vector2f(500,500), sf::Vector2f(1000, 10000)}); }
void NetDemo::readMessageBody(buf_t *netbuffer, uint32_t len) { char *msgdata = new char[len]; size_t cnt = fread(msgdata, 1, len, demofp); if (cnt < len) { delete[] msgdata; fatalError("Can not read netdemo message."); return; } // ensure netbuffer has enough free space to hold this packet if (netbuffer->maxsize() - netbuffer->size() < len) { netbuffer->resize(len + netbuffer->size() + 1, false); } netbuffer->WriteChunk(msgdata, len); delete [] msgdata; if (!connected) { int type = MSG_ReadLong(); if (type == CHALLENGE) { CL_PrepareConnect(); } else if (type == 0) { CL_Connect(); } } else { last_received = gametic; noservermsgs = false; // Since packets are captured after the header is read, we do not // have to read the packet header CL_ParseCommands(); CL_SaveCmd(); if (gametic - last_received > 65) { noservermsgs = true; } } }
bool GLSLProgram::linkShaders() { //Vertex and fragment shaders are successfully compiled //Now it's time to link them together into a program (_programID) //First: attach our shaders to our program glAttachShader(_programID, _vertexShaderID); glAttachShader(_programID, _fragmentShaderID); //Link our program glLinkProgram(_programID); //Note the different functions here: glGetProgram* instead of glGetShader* GLint isLinked = 0; glGetProgramiv(_programID, GL_LINK_STATUS, (int*)&isLinked); if (isLinked == GL_FALSE) { GLint maxLength = 0; glGetProgramiv(_programID, GL_INFO_LOG_LENGTH, &maxLength); //The maxLength includes the NULL char std::vector<GLchar> infoLog(maxLength); glGetProgramInfoLog(_programID, maxLength, &maxLength, &infoLog[0]); //We dont need the program anymore glDeleteProgram(_programID); //Don't be leaking shaders glDetachShader(_programID, _vertexShaderID); glDetachShader(_programID, _fragmentShaderID); glDeleteShader(_vertexShaderID); glDeleteShader(_fragmentShaderID); //Use the info log to show error std::printf("%s\n", &(infoLog[0])); fatalError("Shaders could not be linked"); return false; } //Don't be leaking shaders,always dettach after link glDetachShader(_programID, _vertexShaderID); glDetachShader(_programID, _fragmentShaderID); glDeleteShader(_vertexShaderID); glDeleteShader(_fragmentShaderID); return true; }
void GLSLProgram::linkShaders() { //Vertex and fragment shaders are successfully compiled. //Now time to link them together into a program. //Get a program object. _programID = glCreateProgram(); //Attach our shaders to our program glAttachShader(_programID, _vertexShaderID); glAttachShader(_programID, _fragmentShaderID); //Link our program glLinkProgram(_programID); //Note the different functions here: glGetProgram* instead of glGetShader*. GLint isLinked = 0; glGetProgramiv(_programID, GL_LINK_STATUS, (int *)&isLinked); if (isLinked == GL_FALSE) { GLint maxLength = 0; glGetProgramiv(_programID, GL_INFO_LOG_LENGTH, &maxLength); //The maxLength includes the NULL character std::vector<char> infoLog(maxLength); glGetProgramInfoLog(_programID, maxLength, &maxLength, &infoLog[0]); //We don't need the program anymore. glDeleteProgram(_programID); //Don't leak shaders either. glDeleteShader(_vertexShaderID); glDeleteShader(_fragmentShaderID); //Use the infoLog as you see fit. std::printf("%s\n", &(infoLog[0])); fatalError("Shaders failed to link"); } //Always detach shaders after a successful link. glDetachShader(_programID, _vertexShaderID); glDetachShader(_programID, _fragmentShaderID); //Don't leak shaders either. glDeleteShader(_vertexShaderID); glDeleteShader(_fragmentShaderID); }
CTrajectoryMethod * CTrajectoryMethod::createMethod(CCopasiMethod::SubType subType) { CTrajectoryMethod * pMethod = NULL; switch (subType) { case unset: case deterministic: pMethod = new CLsodaMethod(); break; case stochastic: pMethod = new CStochNextReactionMethod(); break; case directMethod: pMethod = new CStochDirectMethod(); break; case tauLeap: pMethod = new CTauLeapMethod(); break; case adaptiveSA: pMethod = new CTrajAdaptiveSA(); break; case hybrid: pMethod = CHybridMethod::createHybridMethod(); break; case hybridLSODA: pMethod = CHybridMethodLSODA::createHybridMethodLSODA(); break; case DsaLsodar: pMethod = new CTrajectoryMethodDsaLsodar(); break; default: fatalError(); break; } return pMethod; }
/* ** Rebuild the database file. ** ** (1) Remove duplicate entries ** (2) Put all entries in order ** (3) Vacuum */ static void rebuild_database(sqlite3 *db){ int rc; rc = sqlite3_exec(db, "BEGIN;\n" "CREATE TEMP TABLE dbx AS SELECT DISTINCT dbcontent FROM db;\n" "DELETE FROM db;\n" "INSERT INTO db(dbid, dbcontent) SELECT NULL, dbcontent FROM dbx ORDER BY 2;\n" "DROP TABLE dbx;\n" "CREATE TEMP TABLE sx AS SELECT DISTINCT sqltext FROM xsql;\n" "DELETE FROM xsql;\n" "INSERT INTO xsql(sqlid,sqltext) SELECT NULL, sqltext FROM sx ORDER BY 2;\n" "DROP TABLE sx;\n" "COMMIT;\n" "PRAGMA page_size=1024;\n" "VACUUM;\n", 0, 0, 0); if( rc ) fatalError("cannot rebuild: %s", sqlite3_errmsg(db)); }
void loadFile ( fudge_byte * * bytes, fudge_i32 * numbytes, const char * filename ) { FILE * file; fudge_byte buffer [ 1024 ]; /* Load in the file in 1K blocks */ if ( ! ( file = fopen ( filename, "rb" ) ) ) fatalError ( "Failed to open input file" ); *numbytes = 0; while ( ! feof ( file ) ) { fudge_i32 bytesread = fread ( buffer, 1, sizeof ( buffer ), file ); if ( bytesread ) appendBytes ( bytes, numbytes, buffer, bytesread ); } fclose ( file ); }
/* readString (len) --> ptr to string ** ** Read "len" chartacters from the BLITZ DISK file. Allocate memory; ** store the characters, and return a pointer to the memory. */ char * readString (int len) { int i; char * str = (char *) calloc (1, len+1); char * next = str; while (len) { errno = 0; i = fread (next, 1, 1, diskFile); if (i != 1) { if (errno) perror ("Error reading from BLITZ DISK file"); fatalError ("Problems reading from BLITZ DISK file"); } len--; next++; } *next = '\0'; return str; }
/* ** Interpret zArg as an integer value, possibly with suffixes. */ static int integerValue(const char *zArg) { sqlite3_int64 v = 0; static const struct { char *zSuffix; int iMult; } aMult[] = { { "KiB", 1024 }, { "MiB", 1024*1024 }, { "GiB", 1024*1024*1024 }, { "KB", 1000 }, { "MB", 1000000 }, { "GB", 1000000000 }, { "K", 1000 }, { "M", 1000000 }, { "G", 1000000000 }, }; int i; int isNeg = 0; if( zArg[0]=='-' ) { isNeg = 1; zArg++; } else if( zArg[0]=='+' ) { zArg++; } if( zArg[0]=='0' && zArg[1]=='x' ) { int x; zArg += 2; while( (x = hexDigitValue(zArg[0]))>=0 ) { v = (v<<4) + x; zArg++; } } else { while( ISDIGIT(zArg[0]) ) { v = v*10 + zArg[0] - '0'; zArg++; } } for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++) { if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ) { v *= aMult[i].iMult; break; } } if( v>0x7fffffff ) fatalError("parameter too large - max 2147483648"); return (int)(isNeg? -v : v); }
void CModelMerging::simpleCall(std::vector< std::string > & /* toKey */, std::vector< std::string > & objectKey) { if (!mpModel) { fatalError(); } size_t i, j, imax = mpModel->getMetabolites().size(); CMetab * metab; CMetab * metab1; CMetab* tmp; std::string empty = ""; for (i = 0; i < imax; ++i) { metab = &mpModel->getMetabolites()[i]; for (j = 0; j < imax; ++j) { if (objectKey[i] != "") { tmp = &mpModel->getMetabolites()[j]; if (tmp->getKey() == objectKey[i]) { metab1 = tmp; } } } if (! mergeMetabolites(metab->getKey(), objectKey[i])) { CCopasiMessage(CCopasiMessage::ERROR, MCModelMerging + 2, metab1->getObjectName().c_str(), metab->getObjectName().c_str()); return; } } for (i = 0; i < imax; ++i) { if (objectKey[i] != empty) mpModel->removeMetabolite(objectKey[i] , false); } mpModel->compileIfNecessary(NULL); }
/* ** Erase all information in the virtual file system. */ static void reformatVfs(void){ int i; for(i=0; i<MX_FILE; i++){ if( g.aFile[i].sz<0 ) continue; if( g.aFile[i].zFilename ){ free(g.aFile[i].zFilename); g.aFile[i].zFilename = 0; } if( g.aFile[i].nRef>0 ){ fatalError("file %d still open. nRef=%d", i, g.aFile[i].nRef); } g.aFile[i].sz = -1; free(g.aFile[i].a); g.aFile[i].a = 0; g.aFile[i].nRef = 0; } }
void cmd_mem(char const line[512], Memory& mem){ uInt val = 0xdeadbeef; uInt addr = 0xc001d00d; const int result = sscanf(line, "m %8x = %8x", &addr, &val); if (result == EOF || result < 1){ COMMAND_SYNTAX(); return; } // address must be aligned if (addr & 0x3) fatalError("Address for m command misaligned, ignoring\n"); if (result == 2) mem.set<uInt>(addr, val); else printf("%.8X\n", mem.get<uInt>(addr)); };