diff --git a/src/codegen_new/codegen_backend_x86-64_ops.c b/src/codegen_new/codegen_backend_x86-64_ops.c index 1569e693c..9ac8d2474 100644 --- a/src/codegen_new/codegen_backend_x86-64_ops.c +++ b/src/codegen_new/codegen_backend_x86-64_ops.c @@ -786,7 +786,7 @@ host_x86_MOV32_REG_ABS(codeblock_t *block, int dst_reg, void *p) codegen_addquad(block, (uintptr_t) p); codegen_addbyte3(block, 0x41, 0x8b, 0x01 | ((dst_reg & 7) << 3)); /*MOV dst_reg, [R9]*/ } else { - fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIX64 ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram); + fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIXPTR ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram); codegen_alloc_bytes(block, 6); codegen_addbyte(block, 0x8b); /*MOV [p], src_reg*/ codegen_addbyte(block, 0x05 | ((dst_reg & 7) << 3)); diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index b6f5f593c..47f3e7f5c 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -381,7 +381,7 @@ typedef struct { MMX_REG MM[8]; #ifdef USE_NEW_DYNAREC -# if defined(__APPLE__) && defined(__aarch64__) +# if (defined(__APPLE__) && defined(__aarch64__)) || defined(__aarch64__) uint64_t old_fp_control; uint64_t new_fp_control; # else diff --git a/src/cpu/softfloat3e/s_shiftRightJam256M.c b/src/cpu/softfloat3e/s_shiftRightJam256M.c index 654e01234..c92204c4d 100644 --- a/src/cpu/softfloat3e/s_shiftRightJam256M.c +++ b/src/cpu/softfloat3e/s_shiftRightJam256M.c @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ +#include #include #include "primitiveTypes.h" @@ -64,7 +65,7 @@ void softfloat_shiftRightJam256M(const uint64_t *aPtr, uint32_t dist, uint64_t * { uint64_t wordJam; uint32_t wordDist; - uint64_t *ptr; + uint64_t *ptr = NULL; uint8_t i, innerDist; wordJam = 0; @@ -89,7 +90,7 @@ void softfloat_shiftRightJam256M(const uint64_t *aPtr, uint32_t dist, uint64_t * aPtr, innerDist, zPtr + indexMultiwordLoBut(4, wordDist) - ); + ); if (! wordDist) goto wordJam; } else { aPtr += indexWordLo(4 - wordDist); diff --git a/src/device/isarom.c b/src/device/isarom.c index f742a9eae..cdf5a61c6 100644 --- a/src/device/isarom.c +++ b/src/device/isarom.c @@ -156,7 +156,7 @@ isarom_init(const device_t *info) snprintf(dev->socket[i].nvr_path, sizeof(dev->socket[i].nvr_path), "isarom_%i_%i.nvr", dev->inst, i + 1); FILE *fp = nvr_fopen(dev->socket[i].nvr_path, "rb"); if (fp != NULL) { - fread(dev->socket[i].rom.rom, 1, dev->socket[i].size, fp); + (void) !fread(dev->socket[i].rom.rom, 1, dev->socket[i].size, fp); fclose(fp); isarom_log("isarom[%u]: loaded %zu bytes from %s\n", dev->inst, read_bytes, dev->socket[i].nvr_path); } else diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index 1c8e2c8da..9a122f595 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -154,7 +154,7 @@ xtide_init(const device_t *info) sprintf(xtide->nvr_path, "xtide_%i.nvr", device_get_instance()); FILE *fp = nvr_fopen(xtide->nvr_path, "rb"); if (fp != NULL) { - fread(xtide->bios_rom.rom, 1, 0x2000, fp); + (void) !fread(xtide->bios_rom.rom, 1, 0x2000, fp); fclose(fp); } } diff --git a/src/qt/dummy_cdrom_ioctl.c b/src/qt/dummy_cdrom_ioctl.c index bddfabb5b..8dffc6758 100644 --- a/src/qt/dummy_cdrom_ioctl.c +++ b/src/qt/dummy_cdrom_ioctl.c @@ -162,6 +162,7 @@ ioctl_is_empty(const void *local) return 1; } +#if 0 static int ioctl_ext_medium_changed(UNUSED(void *local)) { @@ -174,6 +175,7 @@ ioctl_ext_medium_changed(UNUSED(void *local)) return ret; } +#endif static void ioctl_close(void *local) diff --git a/src/qt/qt_downloader.hpp b/src/qt/qt_downloader.hpp index 0bd3f1fee..2164ba59c 100644 --- a/src/qt/qt_downloader.hpp +++ b/src/qt/qt_downloader.hpp @@ -24,7 +24,7 @@ #include -class Downloader : public QObject { +class Downloader final : public QObject { Q_OBJECT public: enum class DownloadLocation { diff --git a/src/qt/qt_glsl_parser.cpp b/src/qt/qt_glsl_parser.cpp index 9efeb430b..934dd2052 100644 --- a/src/qt/qt_glsl_parser.cpp +++ b/src/qt/qt_glsl_parser.cpp @@ -69,13 +69,12 @@ static inline int wx_config_has_entry(void *config, const char *name) { return i static inline void wx_config_free(void *config) { ini_close(config); }; static int endswith(const char *str, const char *ext) { - int i; const char *p; int elen = strlen(ext); int slen = strlen(str); if (slen >= elen) { p = &str[slen - elen]; - for (i = 0; i < elen; ++i) { + for (int i = 0; i < elen; ++i) { if (tolower(p[i]) != tolower(ext[i])) return 0; } @@ -118,12 +117,18 @@ static char *load_file(const char *fn) { char *data = (char*)malloc(fsize + 1); - (void) fread(data, fsize, 1, fp); - fclose(fp); + size_t read_bytes = fread(data, fsize, 1, fp); + if (read_bytes != 1) { + fclose(fp); + free(data); + return nullptr; + } else { + fclose(fp); - data[fsize] = 0; + data[fsize] = 0; - return data; + return data; + } } static void strip_lines(const char *program, const char *starts_with) { @@ -147,17 +152,15 @@ static void strip_defines(const char *program) { } static int has_parameter(glslp_t *glsl, char *id) { - int i; - for (i = 0; i < glsl->num_parameters; ++i) + for (int i = 0; i < glsl->num_parameters; ++i) if (!strcmp(glsl->parameters[i].id, id)) return 1; return 0; } static int get_parameters(glslp_t *glsl) { - int i; struct parameter p; - for (i = 0; i < glsl->num_shaders; ++i) { + for (int i = 0; i < glsl->num_shaders; ++i) { size_t size = 0; char* line = NULL; struct shader *shader = &glsl->shaders[i]; @@ -197,8 +200,7 @@ static int get_parameters(glslp_t *glsl) { } static struct parameter *get_parameter(glslp_t *glslp, const char *id) { - int i; - for (i = 0; i < glslp->num_parameters; ++i) { + for (int i = 0; i < glslp->num_parameters; ++i) { if (!strcmp(glslp->parameters[i].id, id)) { return &glslp->parameters[i]; } @@ -207,8 +209,7 @@ static struct parameter *get_parameter(glslp_t *glslp, const char *id) { } static glslp_t *glsl_parse(const char *f) { - glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); - memset(glslp, 0, sizeof(glslp_t)); + glslp_t *glslp = (glslp_t*) calloc(1, sizeof(glslp_t)); glslp->num_shaders = 1; struct shader *shader = &glslp->shaders[0]; strcpy(shader->shader_fn, f); @@ -233,7 +234,9 @@ extern "C" { void get_glslp_name(const char *f, char *s, int size) { safe_strncpy(s, path_get_filename((char *)f), size); } glslp_t *glslp_parse(const char *f) { - int i, j, len, sublen; + int j; + int len; + int sublen; char s[513], t[513], z[540]; memset(s, 0, sizeof(s)); @@ -247,8 +250,7 @@ glslp_t *glslp_parse(const char *f) { return 0; } - glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); - memset(glslp, 0, sizeof(glslp_t)); + glslp_t *glslp = (glslp_t*) calloc(1, sizeof(glslp_t)); get_glslp_name(f, glslp->name, sizeof(glslp->name)); @@ -256,7 +258,7 @@ glslp_t *glslp_parse(const char *f) { wx_config_get_bool(cfg, "filter_linear0", &glslp->input_filter_linear, -1); - for (i = 0; i < glslp->num_shaders; ++i) { + for (int i = 0; i < glslp->num_shaders; ++i) { struct shader *shader = &glslp->shaders[i]; snprintf(s, sizeof(s) - 1, "shader%d", i); @@ -267,12 +269,31 @@ glslp_t *glslp_parse(const char *f) { } strcpy(s, f); *path_get_filename(s) = 0; - snprintf(shader->shader_fn, sizeof(shader->shader_fn) - 1, "%s%s", s, t); + + size_t max_len = sizeof(shader->shader_fn); + size_t s_len = strlen(s); + + if (s_len >= max_len) { + // s alone fills or overflows the buffer, truncate and null-terminate + size_t copy_len = max_len - 1 < s_len ? max_len - 1 : s_len; + memcpy(shader->shader_fn, s, copy_len); + shader->shader_fn[copy_len] = '\0'; + } else { + // Copy s fully + memcpy(shader->shader_fn, s, s_len); + // Copy as much of t as fits after s + size_t avail = max_len - 1 - s_len; // space left for t + null terminator + // Copy as much of t as fits into the remaining space + memcpy(shader->shader_fn + s_len, t, avail); + // Null-terminate + shader->shader_fn[s_len + avail] = '\0'; + } + shader->shader_program = load_file(shader->shader_fn); if (!shader->shader_program) { - fprintf(stderr, "GLSLP Error: Could not load shader %s\n", shader->shader_fn); - glslp_free(glslp); - return 0; + fprintf(stderr, "GLSLP Error: Could not load shader %s\n", shader->shader_fn); + glslp_free(glslp); + return 0; } strip_parameters(shader->shader_program); strip_defines(shader->shader_program); @@ -327,7 +348,7 @@ glslp_t *glslp_parse(const char *f) { len = strlen(t); j = 0; sublen = 0; - for (i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { if (t[i] == ';' || i == len - 1) { sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; safe_strncpy(s, t + j, sublen); @@ -361,7 +382,7 @@ glslp_t *glslp_parse(const char *f) { len = strlen(t); j = 0; sublen = 0; - for (i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { if (t[i] == ';' || i == len - 1) { sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; safe_strncpy(s, t + j, sublen); @@ -382,8 +403,7 @@ glslp_t *glslp_parse(const char *f) { } void glslp_free(glslp_t *p) { - int i; - for (i = 0; i < p->num_shaders; ++i) + for (int i = 0; i < p->num_shaders; ++i) if (p->shaders[i].shader_program) free(p->shaders[i].shader_program); free(p); @@ -391,10 +411,9 @@ void glslp_free(glslp_t *p) { void glslp_read_shader_config(glslp_t *shader) { char s[512]; - int i; char *name = shader->name; - sprintf(s, "GL3 Shaders - %s", name); - for (i = 0; i < shader->num_parameters; ++i) { + snprintf(s, sizeof(s) -1, "GL3 Shaders - %s", name); + for (int i = 0; i < shader->num_parameters; ++i) { struct parameter *param = &shader->parameters[i]; param->value = config_get_double(s, param->id, param->default_value); } @@ -402,12 +421,11 @@ void glslp_read_shader_config(glslp_t *shader) { void glslp_write_shader_config(glslp_t *shader) { char s[512]; - int i; char *name = shader->name; startblit(); - sprintf(s, "GL3 Shaders - %s", name); - for (i = 0; i < shader->num_parameters; ++i) { + snprintf(s, sizeof(s) - 1, "GL3 Shaders - %s", name); + for (int i = 0; i < shader->num_parameters; ++i) { struct parameter *param = &shader->parameters[i]; config_set_double(s, param->id, param->value); } diff --git a/src/qt/qt_keybind.hpp b/src/qt/qt_keybind.hpp index 393ee0f5c..25f4a9168 100644 --- a/src/qt/qt_keybind.hpp +++ b/src/qt/qt_keybind.hpp @@ -26,8 +26,8 @@ public: private: Ui::KeyBinder *ui; - bool eventFilter(QObject *obj, QEvent *event); - void showEvent( QShowEvent* event ); + bool eventFilter(QObject *obj, QEvent *event) override; + void showEvent( QShowEvent* event ) override; }; #endif // QT_KeyBinder_HPP diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 9ca2d887e..f1fa5eecf 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -303,27 +303,27 @@ OpenGLRenderer::find_uniforms(struct glsl_shader *glsl, int num_pass) u->orig.texture_size = get_uniform(p, "OrigTextureSize"); for (i = 0; i < glsl->num_passes; ++i) { - sprintf(s, "Pass%dTexture", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dTexture", (i + 1)); u->pass[i].texture = get_uniform(p, s); - sprintf(s, "Pass%dInputSize", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dInputSize", (i + 1)); u->pass[i].input_size = get_uniform(p, s); - sprintf(s, "Pass%dTextureSize", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dTextureSize", (i + 1)); u->pass[i].texture_size = get_uniform(p, s); - sprintf(s, "PassPrev%dTexture", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dTexture", num_pass - i); u->prev_pass[i].texture = get_uniform(p, s); - sprintf(s, "PassPrev%dInputSize", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dInputSize", num_pass - i); u->prev_pass[i].input_size = get_uniform(p, s); - sprintf(s, "PassPrev%dTextureSize", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dTextureSize", num_pass - i); u->prev_pass[i].texture_size = get_uniform(p, s); } u->prev[0].texture = get_uniform(p, "PrevTexture"); u->prev[0].tex_coord = get_attrib(p, "PrevTexCoord"); for (i = 1; i < MAX_PREV; ++i) { - sprintf(s, "Prev%dTexture", i); + snprintf(s, sizeof(s) -1, "Prev%dTexture", i); u->prev[i].texture = get_uniform(p, s); - sprintf(s, "Prev%dTexCoord", i); + snprintf(s, sizeof(s) -1, "Prev%dTexCoord", i); u->prev[i].tex_coord = get_attrib(p, s); } for (i = 0; i < MAX_PREV; ++i) @@ -434,23 +434,21 @@ OpenGLRenderer::delete_prev(struct shader_prev *prev) void OpenGLRenderer::delete_shader(struct glsl_shader *glsl) { - int i; - for (i = 0; i < glsl->num_passes; ++i) + for (int i = 0; i < glsl->num_passes; ++i) delete_pass(&glsl->passes[i]); if (glsl->has_prev) { delete_pass(&glsl->prev_scene); - for (i = 0; i < MAX_PREV; ++i) + for (int i = 0; i < MAX_PREV; ++i) delete_prev(&glsl->prev[i]); } - for (i = 0; i < glsl->num_lut_textures; ++i) + for (int i = 0; i < glsl->num_lut_textures; ++i) delete_texture(&glsl->lut_textures[i].texture); } void OpenGLRenderer::delete_glsl(glsl_t *glsl) { - int i; - for (i = 0; i < glsl->num_shaders; ++i) + for (int i = 0; i < glsl->num_shaders; ++i) delete_shader(&glsl->shaders[i]); delete_pass(&glsl->scene); delete_pass(&glsl->fs_color); @@ -622,7 +620,6 @@ load_texture(const char *f, struct shader_texture *tex) glsl_t * OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) { - int i, j; glslp_t *p = glslp_parse(f); if (p) { @@ -639,10 +636,10 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) gshader->num_lut_textures = p->num_textures; - for (i = 0; i < p->num_textures; ++i) { + for (int i = 0; i < p->num_textures; ++i) { struct texture *texture = &p->textures[i]; - sprintf(file, "%s%s", path, texture->path); + snprintf(file, sizeof(file) - 1, "%s%s", path, texture->path); struct shader_lut_texture *tex = &gshader->lut_textures[i]; strcpy(tex->name, texture->name); @@ -681,18 +678,18 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) gshader->input_filter_linear = p->input_filter_linear; gshader->num_parameters = p->num_parameters; - for (j = 0; j < gshader->num_parameters; ++j) + for (int j = 0; j < gshader->num_parameters; ++j) memcpy(&gshader->parameters[j], &p->parameters[j], sizeof(struct shader_parameter)); gshader->num_passes = p->num_shaders; - for (i = 0; i < p->num_shaders; ++i) { + for (int i = 0; i < p->num_shaders; ++i) { struct shader *shader = &p->shaders[i]; struct shader_pass *pass = &gshader->passes[i]; strcpy(pass->alias, shader->alias); if (!strlen(pass->alias)) - sprintf(pass->alias, "Pass %u", (i + 1)); + snprintf(pass->alias, sizeof(pass->alias) - 1, "Pass %u", (i + 1)); ogl3_log("Creating pass %u (%s)\n", (i + 1), pass->alias); ogl3_log("Loading shader %s...\n", shader->shader_fn); @@ -726,7 +723,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (num_shader == glsl->num_shaders - 1) { pass->fbo.id = -1; - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] != SCALE_SOURCE || pass->scale.value[j] != 1) { setup_fbo(shader, &pass->fbo); break; @@ -755,7 +752,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (gshader->has_prev) { struct shader scene_shader_conf; memset(&scene_shader_conf, 0, sizeof(struct shader)); - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { setup_fbo(&scene_shader_conf, &gshader->prev[i].fbo); } } @@ -772,7 +769,6 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) glsl_t * OpenGLRenderer::load_shaders(int num, char shaders[MAX_USER_SHADERS][512]) { - int i; glsl_t *glsl; glsl = (glsl_t *) malloc(sizeof(glsl_t)); @@ -780,7 +776,7 @@ OpenGLRenderer::load_shaders(int num, char shaders[MAX_USER_SHADERS][512]) glsl->num_shaders = num; int failed = 0; - for (i = num - 1; i >= 0; --i) { + for (int i = num - 1; i >= 0; --i) { const char *f = shaders[i]; if (f && strlen(f)) { if (!load_glslp(glsl, i, f)) { @@ -800,13 +796,12 @@ void OpenGLRenderer::read_shader_config() { char s[512]; - int i, j; - for (i = 0; i < active_shader->num_shaders; ++i) { + for (int i = 0; i < active_shader->num_shaders; ++i) { struct glsl_shader *shader = &active_shader->shaders[i]; char *name = shader->name; - sprintf(s, "GL3 Shaders - %s", name); + snprintf(s, sizeof(s) -1, "GL3 Shaders - %s", name); // shader->shader_refresh_rate = config_get_float(CFG_MACHINE, s, "shader_refresh_rate", -1); - for (j = 0; j < shader->num_parameters; ++j) { + for (int j = 0; j < shader->num_parameters; ++j) { struct shader_parameter *param = &shader->parameters[j]; param->value = config_get_double(s, param->id, param->default_value); } @@ -1233,7 +1228,6 @@ OpenGLRenderer::resizeEvent(QResizeEvent *event) void OpenGLRenderer::render_pass(struct render_data *data) { - int i; GLuint texture_unit = 0; // ogl3_log("pass %d: %gx%g, %gx%g -> %gx%g, %gx%g, %gx%g\n", num_pass, pass->state.input_size[0], @@ -1278,7 +1272,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (data->shader) { /* parameters */ - for (i = 0; i < data->shader->num_parameters; ++i) + for (int i = 0; i < data->shader->num_parameters; ++i) if (u->parameters[i] >= 0) glw.glUniform1f(u->parameters[i], data->shader->parameters[i].value); @@ -1296,7 +1290,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (u->orig.texture_size >= 0) glw.glUniform2fv(u->orig.texture_size, 1, orig->state.input_texture_size); - for (i = 0; i < data->pass; ++i) { + for (int i = 0; i < data->pass; ++i) { if (u->pass[i].texture >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, passes[i].fbo.texture.id); @@ -1323,7 +1317,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (data->shader->has_prev) { /* loop through each previous frame */ - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { if (u->prev[i].texture >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, data->shader->prev[i].fbo.texture.id); @@ -1340,7 +1334,7 @@ OpenGLRenderer::render_pass(struct render_data *data) } } - for (i = 0; i < data->shader->num_lut_textures; ++i) { + for (int i = 0; i < data->shader->num_lut_textures; ++i) { if (u->lut_textures[i] >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, data->shader->lut_textures[i].texture.id); @@ -1364,7 +1358,7 @@ OpenGLRenderer::render_pass(struct render_data *data) glw.glDisableVertexAttribArray(data->shader_pass->uniforms.color); if (data->shader && data->shader->has_prev) { - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { if (u->prev[i].tex_coord >= 0) glw.glDisableVertexAttribArray(u->prev[i].tex_coord); } @@ -1401,10 +1395,11 @@ OpenGLRenderer::render() if (notReady()) return; - int s, i, j; - struct { - uint32_t x, y, w, h; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; } window_rect; window_rect.x = destination.x(); @@ -1434,7 +1429,10 @@ OpenGLRenderer::render() struct shader_pass *pass = &active_shader->scene; struct { - uint32_t x, y, w, h; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; } rect; rect.x = 0; rect.y = 0; @@ -1496,20 +1494,20 @@ OpenGLRenderer::render() struct shader_pass *orig = &active_shader->scene; struct shader_pass *input = &active_shader->scene; - for (s = 0; s < active_shader->num_shaders; ++s) { + for (int s = 0; s < active_shader->num_shaders; ++s) { struct glsl_shader *shader = &active_shader->shaders[s]; int frame_count = frameCounter; /* loop through each pass */ - for (i = 0; i < shader->num_passes; ++i) { + for (int i = 0; i < shader->num_passes; ++i) { bool resetFiltering = false; struct shader_pass *pass = &shader->passes[i]; memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] == SCALE_VIEWPORT) pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; else if (pass->scale.mode[j] == SCALE_ABSOLUTE) @@ -1640,7 +1638,7 @@ OpenGLRenderer::render() memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] == SCALE_VIEWPORT) pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; else if (pass->scale.mode[j] == SCALE_ABSOLUTE) diff --git a/src/qt/qt_updatedetails.cpp b/src/qt/qt_updatedetails.cpp index 1328da732..1d6846dd6 100644 --- a/src/qt/qt_updatedetails.cpp +++ b/src/qt/qt_updatedetails.cpp @@ -46,7 +46,7 @@ UpdateDetails(const UpdateCheck::UpdateResult &updateResult, QWidget *parent) : const auto downloadButton = new QPushButton(tr("Visit download page")); ui->buttonBox->addButton(downloadButton, QDialogButtonBox::AcceptRole); // Override accepted to mean "I want to visit the download page" - connect(ui->buttonBox, &QDialogButtonBox::accepted, [this, updateResult] { + connect(ui->buttonBox, &QDialogButtonBox::accepted, [updateResult] { visitDownloadPage(updateResult.channel); }); const auto logo = QPixmap(":/assets/86box.png").scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); diff --git a/src/qt/qt_vmmanager_main.cpp b/src/qt/qt_vmmanager_main.cpp index 8c83b549f..88b9456cc 100644 --- a/src/qt/qt_vmmanager_main.cpp +++ b/src/qt/qt_vmmanager_main.cpp @@ -62,7 +62,7 @@ VMManagerMain::VMManagerMain(QWidget *parent) : QAction openSystemFolderAction(tr("Open folder")); contextMenu.addAction(&openSystemFolderAction); - connect(&openSystemFolderAction, &QAction::triggered, [this, indexAt] { + connect(&openSystemFolderAction, &QAction::triggered, [indexAt] { if (const auto configDir = indexAt.data(VMManagerModel::Roles::ConfigDir).toString(); !configDir.isEmpty()) { QDir dir(configDir); if (!dir.exists()) @@ -78,7 +78,7 @@ VMManagerMain::VMManagerMain(QWidget *parent) : QAction setSystemIcon(tr("Set icon")); contextMenu.addAction(&setSystemIcon); - connect(&setSystemIcon, &QAction::triggered, [this, indexAt] { + connect(&setSystemIcon, &QAction::triggered, [this] { IconSelectionDialog dialog(":/systemicons/"); if(dialog.exec() == QDialog::Accepted) { const QString iconName = dialog.getSelectedIconName(); diff --git a/src/qt/win_serial_passthrough.c b/src/qt/win_serial_passthrough.c index 725dc096f..4ea6a1875 100644 --- a/src/qt/win_serial_passthrough.c +++ b/src/qt/win_serial_passthrough.c @@ -193,7 +193,11 @@ static int connect_named_pipe_client(serial_passthrough_t *dev) { char ascii_pipe_name[1024] = { 0 }; - strncpy(ascii_pipe_name, dev->named_pipe, sizeof(ascii_pipe_name) - 1); + size_t len = strlen(dev->named_pipe); + if ((len + 1) >= sizeof(ascii_pipe_name)) + memcpy(ascii_pipe_name, dev->named_pipe, sizeof(ascii_pipe_name)); + else + memcpy(ascii_pipe_name, dev->named_pipe, len + 1); HANDLE hPipe = CreateFileA( ascii_pipe_name, // pipe name diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 9201c4ec8..6f90bac18 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -50,12 +50,6 @@ static struct zwp_relative_pointer_v1_listener rel_listener = { rel_mouse_event }; -static struct zwp_keyboard_shortcuts_inhibitor_v1_listener kbd_listener -{ - [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {}, - [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {} -}; - static void display_handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) diff --git a/src/unix/dummy_cdrom_ioctl.c b/src/unix/dummy_cdrom_ioctl.c index bddfabb5b..8dffc6758 100644 --- a/src/unix/dummy_cdrom_ioctl.c +++ b/src/unix/dummy_cdrom_ioctl.c @@ -162,6 +162,7 @@ ioctl_is_empty(const void *local) return 1; } +#if 0 static int ioctl_ext_medium_changed(UNUSED(void *local)) { @@ -174,6 +175,7 @@ ioctl_ext_medium_changed(UNUSED(void *local)) return ret; } +#endif static void ioctl_close(void *local) diff --git a/src/unix/unix.c b/src/unix/unix.c index 2e92a90d3..2bbbda067 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -208,22 +208,33 @@ dynld_module(const char *name, dllimp_t *table) return modhandle; } +#define TMPFILE_BUFSIZE 1024 // Assumed max buffer size void plat_tempfile(char *bufp, char *prefix, char *suffix) { struct tm *calendertime; struct timeval t; time_t curtime; + size_t used = 0; if (prefix != NULL) - sprintf(bufp, "%s-", prefix); - else - strcpy(bufp, ""); + used = snprintf(bufp, TMPFILE_BUFSIZE, "%s-", prefix); + else if (TMPFILE_BUFSIZE > 0) + bufp[0] = '\0'; + gettimeofday(&t, NULL); curtime = time(NULL); calendertime = localtime(&curtime); - sprintf(&bufp[strlen(bufp)], "%d%02d%02d-%02d%02d%02d-%03ld%s", calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, t.tv_usec / 1000, suffix); + + if (used < TMPFILE_BUFSIZE) { + snprintf(bufp + used, TMPFILE_BUFSIZE - used, + "%d%02d%02d-%02d%02d%02d-%03" PRId32 "%s", + calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, + calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, + (int32_t)(t.tv_usec / 1000), suffix); + } } +#undef TMPFILE_BUFSIZE int plat_getcwd(char *bufp, int max) @@ -783,65 +794,83 @@ plat_pause(int p) } } +#define TMP_PATH_BUFSIZE 1024 void plat_init_rom_paths(void) { #ifndef __APPLE__ - if (getenv("XDG_DATA_HOME")) { - char xdg_rom_path[1024] = { 0 }; - - strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); - path_slash(xdg_rom_path); - strncat(xdg_rom_path, "86Box/", 1023); - - if (!plat_dir_check(xdg_rom_path)) + const char *xdg_data_home = getenv("XDG_DATA_HOME"); + if (xdg_data_home) { + char xdg_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(xdg_rom_path, sizeof(xdg_rom_path), "%s/", xdg_data_home); + if (used < sizeof(xdg_rom_path)) + used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "86Box/"); + if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path)) plat_dir_create(xdg_rom_path); - strcat(xdg_rom_path, "roms/"); - - if (!plat_dir_check(xdg_rom_path)) + if (used < sizeof(xdg_rom_path)) + used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "roms/"); + if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path)) plat_dir_create(xdg_rom_path); - rom_add_path(xdg_rom_path); + if (used < sizeof(xdg_rom_path)) + rom_add_path(xdg_rom_path); } else { - char home_rom_path[1024] = { 0 }; - - snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - strcat(home_rom_path, "roms/"); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - rom_add_path(home_rom_path); - } - if (getenv("XDG_DATA_DIRS")) { - char *xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS")); - char *xdg_rom_paths_orig = xdg_rom_paths; - char *cur_xdg_rom_path = NULL; - - if (xdg_rom_paths) { - while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { - xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; - } - while ((cur_xdg_rom_path = local_strsep(&xdg_rom_paths, ":")) != NULL) { - char real_xdg_rom_path[1024] = { '\0' }; - strcat(real_xdg_rom_path, cur_xdg_rom_path); - path_slash(real_xdg_rom_path); - strcat(real_xdg_rom_path, "86Box/roms/"); - rom_add_path(real_xdg_rom_path); - } + const char *home = getenv("HOME"); + if (!home) { + struct passwd *pw = getpwuid(getuid()); + if (pw) + home = pw->pw_dir; + } + + if (home) { + char home_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(home_rom_path, sizeof(home_rom_path), + "%s/.local/share/86Box/", home); + if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + if (used < sizeof(home_rom_path)) + used += snprintf(home_rom_path + used, + sizeof(home_rom_path) - used, "roms/"); + if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + if (used < sizeof(home_rom_path)) + rom_add_path(home_rom_path); + } + } + + const char *xdg_data_dirs = getenv("XDG_DATA_DIRS"); + if (xdg_data_dirs) { + char *xdg_rom_paths = strdup(xdg_data_dirs); + if (xdg_rom_paths) { + // Trim trailing colons + size_t len = strlen(xdg_rom_paths); + while (len > 0 && xdg_rom_paths[len - 1] == ':') + xdg_rom_paths[--len] = '\0'; + + char *saveptr = NULL; + char *cur_xdg = strtok_r(xdg_rom_paths, ":", &saveptr); + while (cur_xdg) { + char real_xdg_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(real_xdg_rom_path, + sizeof(real_xdg_rom_path), + "%s/86Box/roms/", cur_xdg); + if (used < sizeof(real_xdg_rom_path)) + rom_add_path(real_xdg_rom_path); + cur_xdg = strtok_r(NULL, ":", &saveptr); + } + + free(xdg_rom_paths); } - free(xdg_rom_paths_orig); } else { rom_add_path("/usr/local/share/86Box/roms/"); rom_add_path("/usr/share/86Box/roms/"); } #else - char default_rom_path[1024] = { '\0' }; + char default_rom_path[TMP_PATH_BUFSIZE] = {0}; getDefaultROMPath(default_rom_path); rom_add_path(default_rom_path); #endif } +#undef TMP_PATH_BUFSIZE void plat_get_global_config_dir(char *outbuf, const uint8_t len) diff --git a/src/video/vid_jega.c b/src/video/vid_jega.c index f49c92e64..eafdceb9c 100644 --- a/src/video/vid_jega.c +++ b/src/video/vid_jega.c @@ -123,7 +123,7 @@ typedef struct jega_t { int start_scan_lower; int start_scan_upper; int start_scan_count; - uint8_t * vram; + uint8_t *vram; uint8_t jfont_sbcs_19[SBCS19_FILESIZE]; /* 8 x 19 font */ uint8_t jfont_dbcs_16[DBCS16_FILESIZE]; /* 16 x 16 font. Use dbcs_read/write to access it. */ } jega_t; @@ -134,30 +134,30 @@ static void jega_recalctimings(void *priv); #define FONTX_LEN_FN 8 typedef struct { - char id[FONTX_LEN_ID]; - char name[FONTX_LEN_FN]; - uint8_t width; - uint8_t height; - uint8_t type; + char id[FONTX_LEN_ID]; + char name[FONTX_LEN_FN]; + uint8_t width; + uint8_t height; + uint8_t type; } fontx_h; typedef struct { - uint16_t start; - uint16_t end; + uint16_t start; + uint16_t end; } fontx_tbl; -extern uint32_t pallook16[256]; -extern uint32_t pallook64[256]; -static bool is_SJIS_1(uint8_t chr) { return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); } -static bool is_SJIS_2(uint8_t chr) { return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); } +extern uint32_t pallook16[256]; +extern uint32_t pallook64[256]; +static bool is_SJIS_1(uint8_t chr) { return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); } +static bool is_SJIS_2(uint8_t chr) { return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); } -static uint8_t jega_in(uint16_t addr, void *priv); +static uint8_t jega_in(uint16_t addr, void *priv); static uint16_t SJIS_to_SEQ(uint16_t sjis) { uint32_t chr1 = (sjis >> 8) & 0xff; - uint32_t chr2 = sjis & 0xff; + uint32_t chr2 = sjis & 0xff; if (!is_SJIS_1(chr1) || !is_SJIS_2(chr2)) return INVALIDACCESS16; @@ -179,8 +179,8 @@ SJIS_to_SEQ(uint16_t sjis) static uint8_t dbcs_read(uint16_t sjis, int index, void *priv) { - jega_t *jega = (jega_t *) priv; - int seq = SJIS_to_SEQ(sjis); + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); if ((seq >= DBCS16_CHARS) || (index >= 32)) return INVALIDACCESS8; return jega->jfont_dbcs_16[seq * 32 + index]; @@ -188,8 +188,8 @@ dbcs_read(uint16_t sjis, int index, void *priv) { static void dbcs_write(uint16_t sjis, int index, uint8_t val, void *priv) { - jega_t *jega = (jega_t *) priv; - int seq = SJIS_to_SEQ(sjis); + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); if ((seq >= DBCS16_CHARS) || (index >= 32)) return; jega->jfont_dbcs_16[seq * 32 + index] = val; @@ -199,38 +199,38 @@ dbcs_write(uint16_t sjis, int index, uint8_t val, void *priv) { void jega_render_text(void *priv) { - jega_t * jega = (jega_t *) priv; + jega_t *jega = (jega_t *) priv; #ifdef USE_DOUBLE_WIDTH_AND_LINE_CHARS - uint8_t * seqregs = jega->is_vga ? jega->vga.svga.seqregs : + uint8_t *seqregs = jega->is_vga ? jega->vga.svga.seqregs : jega->ega.seqregs; - uint8_t * attrregs = jega->is_vga ? jega->vga.svga.attrregs : + uint8_t *attrregs = jega->is_vga ? jega->vga.svga.attrregs : jega->ega.attrregs; #endif - uint8_t * crtc = jega->is_vga ? jega->vga.svga.crtc : + uint8_t *crtc = jega->is_vga ? jega->vga.svga.crtc : jega->ega.crtc; - uint8_t * vram = jega->is_vga ? jega->vga.svga.vram : + uint8_t *vram = jega->is_vga ? jega->vga.svga.vram : jega->ega.vram; - int * firstline_draw = jega->is_vga ? &jega->vga.svga.firstline_draw : + int *firstline_draw = jega->is_vga ? &jega->vga.svga.firstline_draw : &jega->ega.firstline_draw; - int * lastline_draw = jega->is_vga ? &jega->vga.svga.lastline_draw : + int *lastline_draw = jega->is_vga ? &jega->vga.svga.lastline_draw : &jega->ega.lastline_draw; - int * displine = jega->is_vga ? &jega->vga.svga.displine : + int *displine = jega->is_vga ? &jega->vga.svga.displine : &jega->ega.displine; - int * fullchange = jega->is_vga ? &jega->vga.svga.fullchange : + int *fullchange = jega->is_vga ? &jega->vga.svga.fullchange : &jega->ega.fullchange; - int * blink = jega->is_vga ? &jega->vga.svga.blink : + int *blink = jega->is_vga ? &jega->vga.svga.blink : &jega->ega.blink; - int * x_add = jega->is_vga ? &jega->vga.svga.x_add : + int *x_add = jega->is_vga ? &jega->vga.svga.x_add : &jega->ega.x_add; - int * y_add = jega->is_vga ? &jega->vga.svga.y_add : + int *y_add = jega->is_vga ? &jega->vga.svga.y_add : &jega->ega.y_add; - int * sc = jega->is_vga ? &jega->vga.svga.scanline : + int *sc = jega->is_vga ? &jega->vga.svga.scanline : &jega->ega.scanline; - int * hdisp = jega->is_vga ? &jega->vga.svga.hdisp : + int *hdisp = jega->is_vga ? &jega->vga.svga.hdisp : &jega->ega.hdisp; - int * scrollcache = jega->is_vga ? &jega->vga.svga.scrollcache : + int *scrollcache = jega->is_vga ? &jega->vga.svga.scrollcache : &jega->ega.scrollcache; - uint32_t *memaddr = jega->is_vga ? &jega->vga.svga.memaddr : + uint32_t *memaddr = jega->is_vga ? &jega->vga.svga.memaddr : &jega->ega.memaddr; uint8_t mask = jega->is_vga ? jega->vga.svga.dac_mask : 0xff; @@ -255,7 +255,7 @@ jega_render_text(void *priv) uint32_t attr_basic = 0; uint32_t chr_first; int fg = 0; - int bg; + int bg = 0; for (int x = 0; x < (*hdisp + *scrollcache); x += charwidth) { uint32_t addr = 0; @@ -391,9 +391,9 @@ jega_render_text(void *priv) for (int xx = 0; xx < charwidth; xx++) p[xx] = (dat & (0x80 >> xx)) ? fg : bg; - if (attr_basic & 0x20) { /* vertical line */ + if (attr_basic & 0x20) /* vertical line */ p[0] = fg; - } + if ((*sc == jega->regs[RPULP]) && (attr_basic & 0x10)) { /* underline */ for (int xx = 0; xx < charwidth; xx++) p[xx] = fg; @@ -655,11 +655,11 @@ jega_in(uint16_t addr, void *priv) static int getfontx2header(FILE *fp, fontx_h *header) { - fread(header->id, FONTX_LEN_ID, 1, fp); - if (strncmp(header->id, "FONTX2", FONTX_LEN_ID) != 0) { + (void) !fread(header->id, FONTX_LEN_ID, 1, fp); + if (strncmp(header->id, "FONTX2", FONTX_LEN_ID) != 0) return 1; - } - fread(header->name, FONTX_LEN_FN, 1, fp); + + (void) !fread(header->name, FONTX_LEN_FN, 1, fp); header->width = (uint8_t) getc(fp); header->height = (uint8_t) getc(fp); header->type = (uint8_t) getc(fp); @@ -669,9 +669,8 @@ getfontx2header(FILE *fp, fontx_h *header) static uint16_t chrtosht(FILE *fp) { - uint16_t i, j; - i = (uint16_t) getc(fp); - j = (uint16_t) getc(fp) << 8; + uint16_t i = (uint16_t) getc(fp); + uint16_t j = (uint16_t) getc(fp) << 8; return (i | j); } @@ -695,7 +694,6 @@ LoadFontxFile(const char *fn, void *priv) uint16_t scode; uint8_t size; uint8_t buf; - int line; jega_t *jega = (jega_t *) priv; FILE *fp = rom_fopen(fn, "rb"); jega_log("JEGA: Loading font\n"); @@ -718,10 +716,10 @@ LoadFontxFile(const char *fn, void *priv) for (code = ftbl[i].start; code <= ftbl[i].end; code++) { scode = SJIS_to_SEQ(code); if (scode != INVALIDACCESS16) { - for (line = 0; line < 16; line++) { - fread(&buf, sizeof(uint8_t), 1, fp); + for (uint8_t line = 0; line < 16; line++) { + (void) !fread(&buf, sizeof(uint8_t), 1, fp); jega->jfont_dbcs_16[(int) (scode * 32) + line] = buf; - fread(&buf, sizeof(uint8_t), 1, fp); + (void) !fread(&buf, sizeof(uint8_t), 1, fp); jega->jfont_dbcs_16[(int) (scode * 32) + line + 16] = buf; } } else { @@ -735,9 +733,9 @@ LoadFontxFile(const char *fn, void *priv) return 1; } } else { - if (fhead.width == 8 && fhead.height == 19) { - fread(jega->jfont_sbcs_19, sizeof(uint8_t), SBCS19_FILESIZE, fp); - } else { + if (fhead.width == 8 && fhead.height == 19) + (void) !fread(jega->jfont_sbcs_19, sizeof(uint8_t), SBCS19_FILESIZE, fp); + else { fclose(fp); jega_log("JEGA: Width or height of SBCS font doesn't match.\n"); return 1; @@ -768,7 +766,7 @@ jega_commoninit(const device_t *info, void *priv, int vga) jega->pallook = jega->vga.svga.pallook; io_sethandler(0x03c0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); } else { - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); } @@ -821,40 +819,44 @@ jega_close(void *priv) { jega_t *jega = (jega_t *) priv; #ifdef ENABLE_JEGA_LOG - FILE *f; - // f = fopen("jega_font16.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->jfont_dbcs_16, DBCS16_FILESIZE, 1, f); - // fclose(f); - // } - // f = fopen("jega_font19.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->jfont_sbcs_19, SBCS19_FILESIZE, 1, f); - // fclose(f); - // } - f = fopen("jega_regs.txt", "wb"); - if (f != NULL) { - for (int i = 0; i < 49; i++) - fprintf(f, "Regs %02X: %4X\n", i, jega->regs[i]); - for (int i = 0; i < 32; i++) - fprintf(f, "Attr %02X: %4X\n", i, jega->attrregs[i]); - for (int i = 0; i < 16; i++) - fprintf(f, "JEGAPal %02X: %4X\n", i, jega->egapal[i]); - for (int i = 0; i < 16; i++) - fprintf(f, "EGAPal %02X: %4X\n", i, jega->ega.egapal[i]); - for (int i = 0; i < 64; i++) - fprintf(f, "RealPal %02X: %4X\n", i, jega->pallook[i]); + FILE *fp; +#if 0 + fp = fopen("jega_font16.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->jfont_dbcs_16, DBCS16_FILESIZE, 1, fp); fclose(f); } - // f = fopen("ega_vram.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->ega.vram, 256 * 1024, 1, f); - // fclose(f); - // } - f = fopen("ram_bda.dmp", "wb"); + fp = fopen("jega_font19.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->jfont_sbcs_19, SBCS19_FILESIZE, 1, fp); + fclose(fp); + } +#endif + f = fopen("jega_regs.txt", "wb"); if (f != NULL) { - fwrite(&ram[0x0], 0x500, 1, f); - fclose(f); + for (uint8_t i = 0; i < 49; i++) + fprintf(fp, "Regs %02X: %4X\n", i, jega->regs[i]); + for (uint8_t i = 0; i < 32; i++) + fprintf(fp, "Attr %02X: %4X\n", i, jega->attrregs[i]); + for (uint8_t i = 0; i < 16; i++) + fprintf(fp, "JEGAPal %02X: %4X\n", i, jega->egapal[i]); + for (uint8_t i = 0; i < 16; i++) + fprintf(fp, "EGAPal %02X: %4X\n", i, jega->ega.egapal[i]); + for (uint8_t i = 0; i < 64; i++) + fprintf(fp, "RealPal %02X: %4X\n", i, jega->pallook[i]); + fclose(fp); + } +#if 0 + fp = fopen("ega_vram.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->ega.vram, 256 * 1024, 1, fp); + fclose(fp); + } +#endif + fp = fopen("ram_bda.dmp", "wb"); + if (fp != NULL) { + fwrite(&ram[0x0], 0x500, 1, fp); + fclose(fp); } pclog("jeclosed %04X:%04X DS %04X\n", cs >> 4, cpu_state.pc, DS); #endif @@ -974,7 +976,7 @@ if386_p6x_write(uint16_t port, uint8_t val, void *priv) p65[p65idx] = val; if (p65idx == 0x03) { if (val & 0x04) { /* Color monitor */ - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); pallook16[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); @@ -983,7 +985,7 @@ if386_p6x_write(uint16_t port, uint8_t val, void *priv) pallook16[c] = makecol32(0xaa, 0x55, 0); } } else { /* Monochrome LCD */ - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int cval = 0; #ifdef SIMPLE_BW if (c & 0x0f)