From 200d2b598b11b474efee9836b767682d51f6ba45 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 28 May 2011 15:06:46 +0200 Subject: [PATCH] Slight cleanup. --- gfx/shader_cg.c | 36 +++++++++++++++--------------------- gfx/shader_glsl.c | 27 ++++++++++++++------------- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 9d991296c9..bb8a112fdb 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -385,7 +385,7 @@ static bool load_imports(config_file_t *conf) struct snes_tracker_uniform_info info[MAX_VARIABLES]; unsigned info_cnt = 0; - char *id = strtok(imports, ";"); + const char *id = strtok(imports, ";"); while (id && info_cnt < MAX_VARIABLES) { char semantic_buf[64]; @@ -446,40 +446,34 @@ static bool load_imports(config_file_t *conf) goto error; } + int memtype = 0; switch (ram_type) { case SSNES_STATE_WRAM: - if (addr >= 128 * 1024) - { - SSNES_ERR("Address out of range.\n"); - goto error; - } + memtype = SNES_MEMORY_WRAM; break; case SSNES_STATE_APURAM: + memtype = SNES_MEMORY_APURAM; + break; case SSNES_STATE_VRAM: - if (addr >= 64 * 1024) - { - SSNES_ERR("Address out of range.\n"); - goto error; - } + memtype = SNES_MEMORY_VRAM; break; case SSNES_STATE_OAM: - if (addr >= 512 + 32) - { - SSNES_ERR("Address out of range.\n"); - goto error; - } + memtype = SNES_MEMORY_OAM; break; case SSNES_STATE_CGRAM: - if (addr >= 512) - { - SSNES_ERR("Address out of range.\n"); - goto error; - } + memtype = SNES_MEMORY_CGRAM; + break; default: break; } + if (addr >= psnes_get_memory_size(memtype)) + { + SSNES_ERR("Address out of bounds.\n"); + goto error; + } + strlcpy(info[info_cnt].id, id, sizeof(info[info_cnt].id)); info[info_cnt].addr = addr; info[info_cnt].type = tracker_type; diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 22591ef69c..5f27c20c17 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -415,33 +415,34 @@ static bool get_import_value(xmlNodePtr ptr) goto error; } + int memtype = 0; switch (ram_type) { case SSNES_STATE_WRAM: - if (addr >= psnes_get_memory_size(SNES_MEMORY_WRAM)) - goto error; - break; - case SSNES_STATE_VRAM: - if (addr >= psnes_get_memory_size(SNES_MEMORY_VRAM)) - goto error; + memtype = SNES_MEMORY_WRAM; break; case SSNES_STATE_APURAM: - if (addr >= psnes_get_memory_size(SNES_MEMORY_APURAM)) - goto error; + memtype = SNES_MEMORY_APURAM; + break; + case SSNES_STATE_VRAM: + memtype = SNES_MEMORY_VRAM; break; case SSNES_STATE_OAM: - if (addr >= psnes_get_memory_size(SNES_MEMORY_OAM)) - goto error; + memtype = SNES_MEMORY_OAM; break; case SSNES_STATE_CGRAM: - if (addr >= psnes_get_memory_size(SNES_MEMORY_CGRAM)) - goto error; + memtype = SNES_MEMORY_CGRAM; break; - default: break; } + if (addr >= psnes_get_memory_size(memtype)) + { + SSNES_ERR("Address out of bounds.\n"); + goto error; + } + if (strcmp((const char*)semantic, "capture") == 0) tracker_type = SSNES_STATE_CAPTURE; else if (strcmp((const char*)semantic, "capture_previous") == 0)