<commit_before>#include "demo.h"
#include "demoRunner.h"

#include <nds/arm9/background.h>
#include <nds/arm9/decompress.h>

static size_t fileSize(FILE *fp);

Demo::Demo() {}
Demo::~Demo() {}

void Demo::tick(VramBatcher &batcher) {
	AcceptInput();
	PrepareFrame(batcher);
}

void Demo::setupDefaultBG() {
	setupTilemapBG("P.pal.bin", "P.img.bin", "P.map.bin");
}

void Demo::setupTilemapBG(const char *paletteFile, const char *tileSetFile, const char *tileMapFile) {
	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
	int bgid = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 12, 0);

	loadBGPalette(paletteFile);
	compressedFile2Vram(tileSetFile, bgGetGfxPtr(bgid));
	compressedFile2Vram(tileMapFile, bgGetMapPtr(bgid));

	u32 vMode = MODE_0_2D;
	vMode |= DISPLAY_BG0_ACTIVE;
	REG_DISPCNT = vMode;
}

void Demo::compressedFile2Vram(const char *filename, void *dst) {
	FILE *fp = fopen(filename, "r");

	size_t fSize = fileSize(fp);
	void *compressedFile = malloc(fSize);

	fread(compressedFile, fSize, 1, fp);

	fclose(fp);

	decompress(compressedFile, dst, LZ77Vram);

	free(compressedFile);
}

void Demo::loadBGPalette(const char *paletteFile) {
<commit_msg>Set mode before configuring the background<commit_after>#include "demo.h"
#include "demoRunner.h"

#include <nds/arm9/background.h>
#include <nds/arm9/decompress.h>

static size_t fileSize(FILE *fp);

Demo::Demo() {}
Demo::~Demo() {}

void Demo::tick(VramBatcher &batcher) {
	AcceptInput();
	PrepareFrame(batcher);
}

void Demo::setupDefaultBG() {
	setupTilemapBG("P.pal.bin", "P.img.bin", "P.map.bin");
}

void Demo::setupTilemapBG(const char *paletteFile, const char *tileSetFile, const char *tileMapFile) {
	u32 vMode = MODE_0_2D;
	vMode |= DISPLAY_BG0_ACTIVE;
	REG_DISPCNT = vMode;

	vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
	int bgid = bgInit(0, BgType_Text4bpp, BgSize_T_256x256, 12, 0);

	loadBGPalette(paletteFile);
	compressedFile2Vram(tileSetFile, bgGetGfxPtr(bgid));
	compressedFile2Vram(tileMapFile, bgGetMapPtr(bgid));

}

void Demo::compressedFile2Vram(const char *filename, void *dst) {
	FILE *fp = fopen(filename, "r");

	size_t fSize = fileSize(fp);
	void *compressedFile = malloc(fSize);

	fread(compressedFile, fSize, 1, fp);

	fclose(fp);

	decompress(compressedFile, dst, LZ77Vram);

	free(compressedFile);
}

void Demo::loadBGPalette(const char *paletteFile) {

{'fraction_non_alphanumeric': 0.1446917808219178, 'fraction_numerical': 0.028253424657534245, 'mean_word_length': 6.712871287128713, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7016806', 'n_tokens_mistral': 1004, 'n_tokens_neox': 955, 'n_words': 171}