<commit_before>#include "video-glsl.h"

#include "gba-io.h"

#include <string.h>

#define UNIFORM_LOCATION(UNIFORM) (glGetUniformLocation(glslRenderer->program, UNIFORM))

static const GLfloat _vertices[4] = {
	-1, 0,
	1, 0
};

static const GLchar* _fragmentShader =
	"#extension GL_EXT_gpu_shader4 : enable\n"
	"varying float x;\n"
	"uniform float y;\n"
	"uniform sampler2D vram;\n"
	"uniform int dispcnt;\n"
	"uniform int bg0cnt;\n"
	"uniform int bg1cnt;\n"
	"uniform int bg2cnt;\n"
	"uniform int bg3cnt;\n"
	"uniform int bg0hofs;\n"
	"uniform int bg0vofs;\n"
	"uniform int bg1hofs;\n"
	"uniform int bg1vofs;\n"
	"uniform int bg2hofs;\n"
	"uniform int bg2vofs;\n"
	"uniform int bg3hofs;\n"
	"uniform int bg3vofs;\n"
	"#define VRAM_INDEX(i) (vec2(mod(float(i), 512.0) / 511.0, (160.0 + floor(float(i) / 512.0)) / 255.0))\n"
	"#define DESERIALIZE(vec) int(dot(vec4(63488.0, 1984.0, 62.0, 1.0), vec))\n"

	"vec4 backgroundMode0(int bgcnt, int hofs, int vofs) {\n"
	"	int charBase = ((bgcnt / 4) & 3) * 8192;\n"
	"	int screenBase = ((bgcnt / 256) & 0x1F) * 1024;\n"
	"	int localX = hofs + int(x);\n"
	"	int localY = vofs + int(y);\n"
	"	int xBase = localX & 0xF8;\n"
	"	int yBase = localY & 0xF8;\n"
	"	screenBase = screenBase + (xBase / 8) + (yBase * 4);\n"
	"	int mapData = DESERIALIZE(texture2D(vram, VRAM_INDEX(screenBase)));\n"
	"	charBase = charBase + ((mapData & 0x3FF) * 16) + (localX & 0x4) / 4 + (localY & 0x7) * 2;\n"
	"	int tileData = DESERIALIZE(texture2D(vram, VRAM_INDEX(charBase)));\n"
	"	tileData = ((tileData >> ((localX & 3) * 4)) & 0xF);\n"
	"	if (tileData == 0) {\n"
	"		return vec4(0, 0, 0, 0);\n"
	"   }\n"
	"	return texture2D(vram, vec2(float(tileData + (mapData / 4096) * 16) / 512.0, y / 256.0));\n"
	"}\n"

	"void runPriority(int priority, inout vec4 color) {\n"
	"	if (color.a > 0.0) {\n"
	"		return;\n"
	"	}\n"
	"	if ((dispcnt & 0x100) != 0 && (bg0cnt & 0x3) == priority) {\n"
	"		color = backgroundMode0(bg0cnt, bg0hofs, bg0vofs);\n"
	"	}\n"
	"	if (color.a > 0.0) {\n"
	"		return;\n"
	"	}\n"
	"	if ((dispcnt & 0x200) != 0 && (bg1cnt & 0x3) == priority) {\n"<commit_msg>Fix x indexing into VRAM<commit_after>#include "video-glsl.h"

#include "gba-io.h"

#include <string.h>

#define UNIFORM_LOCATION(UNIFORM) (glGetUniformLocation(glslRenderer->program, UNIFORM))

static const GLfloat _vertices[4] = {
	-1, 0,
	1, 0
};

static const GLchar* _fragmentShader =
	"#extension GL_EXT_gpu_shader4 : enable\n"
	"varying float x;\n"
	"uniform float y;\n"
	"uniform sampler2D vram;\n"
	"uniform int dispcnt;\n"
	"uniform int bg0cnt;\n"
	"uniform int bg1cnt;\n"
	"uniform int bg2cnt;\n"
	"uniform int bg3cnt;\n"
	"uniform int bg0hofs;\n"
	"uniform int bg0vofs;\n"
	"uniform int bg1hofs;\n"
	"uniform int bg1vofs;\n"
	"uniform int bg2hofs;\n"
	"uniform int bg2vofs;\n"
	"uniform int bg3hofs;\n"
	"uniform int bg3vofs;\n"
	"#define VRAM_INDEX(i) (vec2(mod(float(i + 1), 512.0) / 512.0 - 1.0 / 1024.0, (160.0 + floor(float(i) / 512.0)) / 255.0))\n"
	"#define DESERIALIZE(vec) int(dot(vec4(63488.0, 1984.0, 62.0, 1.0), vec))\n"

	"vec4 backgroundMode0(int bgcnt, int hofs, int vofs) {\n"
	"	int charBase = ((bgcnt / 4) & 3) * 8192;\n"
	"	int screenBase = ((bgcnt / 256) & 0x1F) * 1024;\n"
	"	int localX = hofs + int(x);\n"
	"	int localY = vofs + int(y);\n"
	"	int xBase = localX & 0xF8;\n"
	"	int yBase = localY & 0xF8;\n"
	"	screenBase = screenBase + (xBase / 8) + (yBase * 4);\n"
	"	int mapData = DESERIALIZE(texture2D(vram, VRAM_INDEX(screenBase)));\n"
	"	charBase = charBase + ((mapData & 0x3FF) * 16) + (localX & 0x4) / 4 + (localY & 0x7) * 2;\n"
	"	int tileData = DESERIALIZE(texture2D(vram, VRAM_INDEX(charBase)));\n"
	"	tileData = ((tileData >> ((localX & 3) * 4)) & 0xF);\n"
	"	if (tileData == 0) {\n"
	"		return vec4(0, 0, 0, 0);\n"
	"   }\n"
	"	return texture2D(vram, vec2(float(tileData + (mapData / 4096) * 16) / 512.0, y / 256.0));\n"
	"}\n"

	"void runPriority(int priority, inout vec4 color) {\n"
	"	if (color.a > 0.0) {\n"
	"		return;\n"
	"	}\n"
	"	if ((dispcnt & 0x100) != 0 && (bg0cnt & 0x3) == priority) {\n"
	"		color = backgroundMode0(bg0cnt, bg0hofs, bg0vofs);\n"
	"	}\n"
	"	if (color.a > 0.0) {\n"
	"		return;\n"
	"	}\n"
	"	if ((dispcnt & 0x200) != 0 && (bg1cnt & 0x3) == priority) {\n"
{'fraction_non_alphanumeric': 0.20572916666666666, 'fraction_numerical': 0.06912878787878787, 'mean_word_length': 3.647964796479648, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4764195', 'n_tokens_mistral': 2172, 'n_tokens_neox': 1965, 'n_words': 438}