void vbo_init(void) { #ifdef EMSCRIPTEN struct retro_variable var = { "mupen64-vcache-vbo", "enabled" }; #else struct retro_variable var = { "mupen64-vcache-vbo", 0 }; #endif vbuf_use_vbo = false; vbuf_length = 0; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) vbuf_use_vbo = (strcmp(var.value, "enabled") == 0); if (vbuf_use_vbo) { glGenBuffers(1, &vbuf_vbo); if (!vbuf_vbo) { log_cb(RETRO_LOG_ERROR, "Failed to create the VBO."); vbuf_use_vbo = false; } else log_cb(RETRO_LOG_INFO, "Vertex cache VBO enabled.\n"); } }
void Config_LoadConfig(void) { FILE *f; char line[4096]; // default configuration Config_SetDefault(); // __LIBRETRO__: Get screen size config.screen.width = screen_width; config.screen.height = screen_height; // read configuration const char *filename = ConfigGetSharedDataFilepath("gles2n64.conf"); f = fopen(filename, "r"); if (!f) { if (log_cb) { log_cb(RETRO_LOG_WARN, "[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) ); log_cb(RETRO_LOG_WARN, "[gles2N64]: Attempting to write new Config \n"); } Config_WriteConfig(filename); } else { if (log_cb) log_cb(RETRO_LOG_INFO, "[gles2n64]: Loading Config from %s \n", filename); while (!feof( f )) { char *val; fgets( line, 4096, f ); if (line[0] == '#' || line[0] == '\n') continue; val = strchr( line, '=' ); if (!val) continue; *val++ = '\0'; Config_SetOption(line,val); } if (config.version < CONFIG_VERSION) { if (log_cb) log_cb(RETRO_LOG_WARN, "[gles2N64]: Wrong config version, rewriting config with defaults\n"); Config_SetDefault(); Config_WriteConfig(filename); } fclose(f); } }
static void output_heka(lsb_heka_message *msg) { static char header[14] = "\x1e\x00\x08"; // up to 10 varint bytes and a \x1f int hlen = lsb_pb_output_varint(header + 3, msg->raw.len) + 1; header[1] = (char)hlen; header[hlen + 2] = '\x1f'; if (fwrite(header, hlen + 3, 1, stdout) != 1) { log_cb(NULL, NULL, 0, "error outputting header"); exit(1); } if (fwrite(msg->raw.s, msg->raw.len, 1, stdout) != 1) { log_cb(NULL, NULL, 0, "error outputting message"); exit(1); } return; }
int cpuintrf_init(void) { int cputype; /* verify the order of entries in the cpuintrf[] array */ for (cputype = 0; cputype < CPU_COUNT; cputype++) { /* make sure the index in the array matches the current index */ if (cpuintrf[cputype].cpu_num != cputype) { log_cb(RETRO_LOG_ERROR, LOGPRE "CPU #%d [%s] wrong ID %d: check enum CPU_... in src/cpuintrf.h!\n", cputype, cputype_name(cputype), cpuintrf[cputype].cpu_num); exit(1); } /* also reset the active CPU context info */ cpu_active_context[cputype] = -1; } /* zap the CPU data structure */ memset(cpu, 0, sizeof(cpu)); totalcpu = 0; cpu_dasm_override = NULL; /* reset the context stack */ memset(cpu_context_stack, -1, sizeof(cpu_context_stack)); cpu_context_stack_ptr = 0; /* nothing active, nothing executing */ activecpu = -1; executingcpu = -1; return 0; }
static void add_tex(unsigned int id) { texlist *aux = list; texlist *aux2; if (list == NULL || id < list->id) { nbTex++; list = (texlist*)malloc(sizeof(texlist)); list->next = aux; list->id = id; #ifdef LOG_TEXTUREMEM goto addtex_log; #else return; #endif } while (aux->next && aux->next->id < id) aux = aux->next; // ZIGGY added this test so that add_tex now accept re-adding an existing texture if (aux->next && aux->next->id == id) return; nbTex++; aux2 = aux->next; aux->next = (texlist*)malloc(sizeof(texlist)); aux->next->id = id; aux->next->next = aux2; #ifdef LOG_TEXTUREMEM addtex_log: if (log_cb) log_cb(RETRO_LOG_DEBUG, "ADDTEX nbtex is now %d (%06x)\n", nbTex, id); #endif }
static void move_to_offset(FILE *fh, int num) { char buf[2][BUFSIZ]; memset(buf, 0, sizeof(buf)); char *cur = buf[0]; char *prev = buf[1]; char *tmp; fseek(fh, 0, SEEK_END); long len = ftell(fh); if (len < 0) { log_cb(NULL, NULL, 0, "ftell failed"); } size_t consume = len > BUFSIZ ? BUFSIZ : len; size_t pos = len - consume; while (consume > 0) { if (fseek(fh, pos, SEEK_SET)) { log_cb(NULL, NULL, 0, "fseek failed (reading)"); break; } if (fread(cur, consume, 1, fh) != 1) { log_cb(NULL, NULL, 0, "fread failed"); break; } int loc = find_header(cur, consume, prev, num); if (loc >= 0) { if (fseek(fh, -(consume - loc) , SEEK_CUR)) { log_cb(NULL, NULL, 0, "fseek failed (find position)"); } return; } if (pos >= consume) { pos -= consume; } else { consume = pos; pos = 0; } tmp = cur; cur = prev; prev = tmp; } fseek(fh, 0, SEEK_SET); }
int ui_error_specific(ui_error_level severity, const char *message) { switch (severity) { case UI_ERROR_INFO: log_cb(RETRO_LOG_INFO, "%s\n", message); break; case UI_ERROR_WARNING: log_cb(RETRO_LOG_WARN, "%s\n", message); break; case UI_ERROR_ERROR: log_cb(RETRO_LOG_ERROR, "%s\n", message); break; } return fuse_ui_error_specific(severity, message); }
void FindBestDepthBias(void) { const char *renderer = NULL; #if defined(__LIBRETRO__) // TODO: How to calculate this? if (biasFound) return; renderer = (const char*)glGetString(GL_RENDERER); if (log_cb) log_cb(RETRO_LOG_INFO, "GL_RENDERER: %s\n", renderer); biasFound = true; #else #if 0 float f, bestz = 0.25f; int x; if (biasFactor) return; biasFactor = 64.0f; // default value glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); glEnable(GL_POLYGON_OFFSET_FILL); glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); glColor4ub(255,255,255,255); glDepthMask(GL_TRUE); for (x=0, f=1.0f; f<=65536.0f; x+=4, f*=2.0f) { float z; glPolygonOffset(0, f); glBegin(GL_TRIANGLE_STRIP); glVertex3f(float(x+4 - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); glVertex3f(float(x - widtho)/(width/2), float(0 - heighto)/(height/2), 0.5); glVertex3f(float(x+4 - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); glVertex3f(float(x - widtho)/(width/2), float(4 - heighto)/(height/2), 0.5); glEnd(); glReadPixels(x+2, 2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); z -= 0.75f + 8e-6f; if (z<0.0f) z = -z; if (z > 0.01f) continue; if (z < bestz) { bestz = z; biasFactor = f; } //printf("f %g z %g\n", f, z); } //printf(" --> bias factor %g\n", biasFactor); glPopAttrib(); #endif #endif }
void url_cb(enum url_status status, const void* result, void* usrdata) { char buffer[1024]; switch(status) { case URL_STATUS_FINISH: { const url_cb_finish* fin = (const url_cb_finish*)result; sprintf(buffer, "FINISH result[%d]", fin->result); log_cb(EVENT_LOG_DEBUG, "url_cb", buffer); } break; case URL_STATUS_DATA: { const url_cb_data* da = (const url_cb_data*)result; sprintf(buffer, "DATA [%d*%d=%d][%.*s]", da->size, da->nmemb, da->size*da->nmemb, 512, (const char*)da->ptr); log_cb(EVENT_LOG_DEBUG, "url_cb", buffer); } break; case URL_STATUS_PROGRESS: { const url_cb_prog* prog = (const url_cb_prog*)result; sprintf(buffer, "Progress: download[%f/%f] upload[%f/%f]", prog->dnow, prog->dtotal, prog->unow, prog->utotal); log_cb(EVENT_LOG_DEBUG, "url_cb", buffer); } break; case URL_STATUS_ERROR: case URL_STATUS_FAIL: default: sprintf(buffer, "status[%d]", status); log_cb(EVENT_LOG_DEBUG, "url_cb", buffer); break; } }
inline Func symbol(const std::string& sym) { std::map<std::string, retro_proc_address_t>& map = symbol_map(); retro_proc_address_t func = map[sym]; if (!func) { func = get_symbol(sym); if (!func && log_cb) log_cb(RETRO_LOG_ERROR, "Didn't find GL symbol: %s\n", sym.c_str()); } return reinterpret_cast<Func>(func); }
// This is an ugly hack so that we can have the frontend manage snapshots for us int fuse_write_snapshot(const char *filename, const unsigned char *buffer, size_t length) { log_cb(RETRO_LOG_DEBUG, "%s(\"%s\", %p, %lu)\n", __FUNCTION__, filename, buffer, length); snapshot_buffer = malloc(length); if (snapshot_buffer) { memcpy(snapshot_buffer, buffer, length); snapshot_size = length; return 0; } return 1; }
int compat_file_exists(const char *path) { log_cb(RETRO_LOG_INFO, "Checking if \"%s\" exists\n", path); int exists = 0; compat_fd fd = compat_file_open(path, 0); if (fd != COMPAT_FILE_OPEN_FAILED) { compat_file_close(fd); exists = 1; } return exists; }
GLuint get_tex_id(unsigned int id) { texlist *entry = NULL; HASH_FIND_INT(list, &id, entry); if (entry) return entry->tex_id; #ifdef LOG_TEXTUREMEM /* TODO - change - use glitch logger */ if (log_cb) log_cb(RETRO_LOG_ERROR, "get_tex_id for %08x failed!\n", id); #endif return 0; }
void vbo_buffer_data(void *data, size_t size) { if (vbuf_vbo) { if (size > vbuf_vbo_size) { glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW); if (size > VERTEX_BUFFER_SIZE) log_cb(RETRO_LOG_INFO, "Extending vertex cache VBO.\n"); vbuf_vbo_size = size; } else glBufferSubData(GL_ARRAY_BUFFER, 0, size, data); } }
void Config_WriteConfig(const char *filename) { int i; config.version = CONFIG_VERSION; FILE* f = fopen(filename, "w"); if (!f && log_cb) log_cb(RETRO_LOG_ERROR, "Could Not Open %s for writing\n", filename); for(i = 0; i < configOptionsSize; i++) { Option *o = &configOptions[i]; fprintf(f, "%s", o->name); // __LIBRETRO__: Fix warning if (o->data) fprintf(f,"=%i", *(o->data)); fprintf(f, "\n"); } fclose(f); }
void Config_SetOption(char* line, char* val) { int i; for(i = 0; i < configOptionsSize; i++) { Option *o = &configOptions[i]; if (strcasecmp(line, o->name) == 0) { if (o->data) { int v = atoi(val); *(o->data) = v; if (log_cb) log_cb(RETRO_LOG_INFO, "Config Option: %s = %i\n", o->name, v); } break; } } }
void add_tex(unsigned int id) { texlist *entry = NULL; HASH_FIND_INT(list, &id, entry); if (entry) return; entry = (texlist*)malloc(sizeof(texlist)); entry->id = id; glGenTextures(1, &entry->tex_id); HASH_ADD_INT(list, id, entry); #ifdef LOG_TEXTUREMEM /* TODO - change - use glitch logger */ if (log_cb) log_cb(RETRO_LOG_DEBUG, "ADDTEX nbtex is now %d (%06x)\n", HASH_COUNT(list), id); #endif }
static size_t read_file(FILE *fh, lsb_input_buffer *ib) { size_t need; if (ib->msglen) { need = ib->msglen + (size_t)ib->buf[ib->scanpos + 1] + LSB_HDR_FRAME_SIZE - (ib->readpos - ib->scanpos); } else { need = ib->scanpos + ib->size - ib->readpos; } if (lsb_expand_input_buffer(ib, need)) { log_cb(NULL, NULL, 0, "buffer reallocation failed"); exit(EXIT_FAILURE); } size_t nread = fread(ib->buf + ib->readpos, 1, ib->size - ib->readpos, fh); ib->readpos += nread; return nread; }
static void remove_tex(unsigned int idmin, unsigned int idmax) { unsigned int *t; int n = 0; texlist *aux = list; int sz = nbTex; if (aux == NULL) return; t = (unsigned int*)malloc(sz * sizeof(int)); while (aux && aux->id >= idmin && aux->id < idmax) { if (n >= sz) t = (unsigned int *) realloc(t, ++sz*sizeof(int)); t[n++] = aux->id; aux = aux->next; free(list); list = aux; nbTex--; } while (aux && aux->next) { if (aux->next->id >= idmin && aux->next->id < idmax) { texlist *aux2 = aux->next->next; if (n >= sz) t = (unsigned int *) realloc(t, ++sz*sizeof(int)); t[n++] = aux->next->id; free(aux->next); aux->next = aux2; nbTex--; } aux = aux->next; } glDeleteTextures(n, t); free(t); #ifdef LOG_TEXTUREMEM if (log_cb) log_cb(RETRO_LOG_DEBUG, "RMVTEX nbtex is now %d (%06x - %06x)\n", nbTex, idmin, idmax); #endif }
void remove_tex(unsigned int idmin, unsigned int idmax) { unsigned int n = 0; texlist *current, *tmp; GLuint *t = (GLuint*)malloc(HASH_COUNT(list) * sizeof(GLuint)); HASH_ITER(hh, list, current, tmp) { if (current->id >= idmin && current->id < idmax) { t[n++] = current->tex_id; HASH_DEL(list, current); free(current); } } glDeleteTextures(n, t); free(t); #ifdef LOG_TEXTUREMEM if (log_cb) log_cb(RETRO_LOG_DEBUG, "RMVTEX nbtex is now %d (%06x - %06x)\n", HASH_COUNT(list), idmin, idmax); #endif }
void Config_LoadRomConfig(unsigned char* header) { char line[4096]; int i; // get the name of the ROM for (i = 0; i < 20; i++) config.romName[i] = header[0x20+i]; config.romName[20] = '\0'; while (config.romName[strlen(config.romName)-1] == ' ') { config.romName[strlen(config.romName)-1] = '\0'; } switch(header[0x3e]) { // PAL codes case 0x44: case 0x46: case 0x49: case 0x50: case 0x53: case 0x55: case 0x58: case 0x59: config.romPAL = true; break; // NTSC codes case 0x37: case 0x41: case 0x45: case 0x4a: config.romPAL = false; break; // Fallback for unknown codes default: config.romPAL = false; } if (log_cb) log_cb(RETRO_LOG_INFO, "Rom is %s\n", config.romPAL ? "PAL" : "NTSC"); const char *filename = ConfigGetSharedDataFilepath("gles2n64rom.conf"); FILE *f = fopen(filename,"r"); if (!f) { if (log_cb) log_cb(RETRO_LOG_INFO, "Could not find %s Rom settings file, using global.\n", filename); return; } else { if (log_cb) log_cb(RETRO_LOG_INFO, "[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName); bool isRom = false; while (!feof(f)) { fgets(line, 4096, f); if (line[0] == '\n') continue; if (strncmp(line,"rom name=", 9) == 0) { //Depending on the editor, end lines could be terminated by "LF" or "CRLF" char* lf = strchr(line, '\n'); //Line Feed char* cr = strchr(line, '\r'); //Carriage Return if (lf) *lf='\0'; if (cr) *cr='\0'; isRom = (strcasecmp(config.romName, line+9) == 0); } else { if (isRom) { char* val = strchr(line, '='); if (!val) continue; *val++ = '\0'; Config_SetOption(line,val); if (log_cb) log_cb(RETRO_LOG_INFO, "%s = %s", line, val); } } } } fclose(f); }
bool NFCNet::Log( int severity, const char *msg ) { log_cb(severity, msg); return true; }
compat_fd compat_file_open(const char *path, int write) { if (write) { log_cb(RETRO_LOG_ERROR, "Cannot open \"%s\" for writing\n", path); return COMPAT_FILE_OPEN_FAILED; } compat_fd_internal *fd = (compat_fd_internal*)malloc(sizeof(compat_fd_internal)); if (!fd) { log_cb(RETRO_LOG_ERROR, "Out of memory while opening \"%s\"\n", path); return COMPAT_FILE_OPEN_FAILED; } const entry_t* entry = find_entry(path); if (entry != NULL) { fd->ptr = (const char*)entry->ptr; fd->length = fd->remain = entry->size; log_cb(RETRO_LOG_INFO, "Opened \"%s\" from memory\n", path); return (compat_fd)fd; } log_cb(RETRO_LOG_INFO, "Could not find file \"%s\", trying file system\n", path); const char *sys; if (!env_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &sys) || !sys) { log_cb(RETRO_LOG_ERROR, "Error getting the system folder while opening \"%s\"\n", path); free(fd); return COMPAT_FILE_OPEN_FAILED; } char system[MAX_PATH_LEN]; strncpy(system, sys, MAX_PATH_LEN); system[MAX_PATH_LEN - 1] = 0; strncat(system, "/fuse", MAX_PATH_LEN); system[MAX_PATH_LEN - 1] = 0; strncat(system, path, MAX_PATH_LEN); system[MAX_PATH_LEN - 1] = 0; log_cb(RETRO_LOG_INFO, "Trying to open \"%s\" from the file system\n", system); FILE* file = fopen(system, "rb"); if (!file) { log_cb(RETRO_LOG_ERROR, "Could not find file \"%s\" on the file system\n", system); free(fd); return COMPAT_FILE_OPEN_FAILED; } long size; if (fseek(file, 0, SEEK_END) != 0 || (size = ftell(file)) < 0 || fseek(file, 0, SEEK_SET) != 0) { log_cb(RETRO_LOG_ERROR, "Could not determine size of \"%s\"\n", system); fclose(file); free(fd); return COMPAT_FILE_OPEN_FAILED; } void* ptr = malloc(size); if (!ptr) { log_cb(RETRO_LOG_ERROR, "Out of memory while opening \"%s\"\n", system); fclose(file); free(fd); return COMPAT_FILE_OPEN_FAILED; } if (fread(ptr, 1, size, file) != size) { log_cb(RETRO_LOG_ERROR, "Error reading from \"%s\"\n", system); free(ptr); fclose(file); free(fd); return COMPAT_FILE_OPEN_FAILED; } fclose(file); fd->ptr = (const char*)ptr; fd->length = fd->remain = size; log_cb(RETRO_LOG_INFO, "Opened \"%s\" from the file system\n", system); return (compat_fd)fd; }
int main(int argc, char **argv) { bool argerr = false; bool follow = false; bool use_stdin = false; long num = -1; char *matcher = "TRUE"; char *filename = NULL; output_function ofn = output_text; int c; while ((c = getopt(argc, argv, "tchfn:m:")) != -1) { switch (c) { case 't': ofn = output_text; break; case 'c': ofn = NULL; break; case 'h': ofn = output_heka; break; case 'f': follow = true; break; case 'n': num = strtol(optarg, NULL, 10); if (num < 0) argerr = true; break; case 'm': matcher = optarg; break; default: argerr = true; break; } } if (argc - optind == 1) { filename = argv[optind]; use_stdin = strcmp("-", filename) == 0; } else { argerr = true; } if (argerr) { log_cb(NULL, NULL, 0, "usage: %s [-t|-c|-h] [-m message_matcher] [-f] [-n #] <FILE>\n" "description:\n" " -t output the messages in text format (default)\n" " -c only output the message count\n" " -h output the messages as a Heka protobuf stream\n" " -f output appended data as the file grows\n" " -n output the last # of messages (simple header check so not " "100%% accurate)\n" " -m message_matcher expression (default \"TRUE\")\n" " FILE name of the file to cat or '-' for stdin\n" "notes:\n" " All output is written to stdout and all log/error messages are " "written to stderr.\n", argv[0]); return EXIT_FAILURE; } lsb_message_matcher *mm = lsb_create_message_matcher(matcher); if (!mm) { log_cb(NULL, NULL, 0, "invalid message matcher: %s", matcher); return EXIT_FAILURE; } FILE *fh = stdin; if (!use_stdin) { fh = fopen(filename, "r"); if (!fh) { log_cb(NULL, NULL, 0, "error opening: %s", filename); return EXIT_FAILURE; } if (num >= 0) { move_to_offset(fh, num); } } size_t discarded_bytes; size_t bytes_read = 0; size_t pcnt = 0; size_t mcnt = 0; lsb_input_buffer ib; lsb_init_input_buffer(&ib, 1024 * 1024 * 1024); lsb_heka_message msg; lsb_init_heka_message(&msg, 8); do { if (lsb_find_heka_message(&msg, &ib, true, &discarded_bytes, &logger)) { if (lsb_eval_message_matcher(mm, &msg)) { if (ofn) { ofn(&msg); } ++mcnt; } ++pcnt; } else { bytes_read = read_file(fh, &ib); } if (bytes_read == 0 && follow && !use_stdin) { sleep(1); } } while (bytes_read > 0 || follow); lsb_free_heka_message(&msg); lsb_free_input_buffer(&ib); lsb_destroy_message_matcher(mm); if (!use_stdin) { fclose(fh); } if (ofn) { log_cb(NULL, NULL, 0, "Processed: %zu, matched: %zu messages\n", pcnt, mcnt); } else { printf("Processed: %zu, matched: %zu messages\n", pcnt, mcnt); } }
void evhttp_log_cb(int level, const char* msg) { log_cb(level, "evhttp_client", msg); }
void libevent_log_cb(int level, const char* msg) { log_cb(level, "libevent", msg); }