all repos — mgba @ d9764e8cea482fead7e1a3376d1007c884ee252b

mGBA Game Boy Advance Emulator

src/core/tile-cache.h (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef M_TILE_CACHE_H
 7#define M_TILE_CACHE_H
 8
 9#include "util/common.h"
10
11DECL_BITFIELD(mTileCacheConfiguration, uint32_t);
12DECL_BIT(mTileCacheConfiguration, ShouldStore, 0);
13
14DECL_BITFIELD(mTileCacheSystemInfo, uint32_t);
15DECL_BITS(mTileCacheSystemInfo, Palette0BPP, 0, 2);
16DECL_BITS(mTileCacheSystemInfo, Palette0Count, 2, 4);
17DECL_BITS(mTileCacheSystemInfo, Palette1BPP, 8, 2);
18DECL_BITS(mTileCacheSystemInfo, Palette1Count, 10, 4);
19DECL_BITS(mTileCacheSystemInfo, MaxTiles, 16, 13);
20
21struct mTileCacheEntry {
22	uint32_t paletteVersion;
23	uint8_t vramClean;
24	uint8_t paletteId;
25	uint8_t activePalette;
26};
27
28struct mTileCache {
29	uint16_t* cache;
30	struct mTileCacheEntry* status;
31	uint32_t* globalPaletteVersion[2];
32
33	int activePalette;
34	unsigned entries;
35	unsigned count;
36	unsigned entriesPerTile;
37	unsigned bpp;
38
39	uint16_t* vram;
40	uint16_t* palette;
41	uint16_t temporaryTile[64];
42
43	mTileCacheConfiguration config;
44	mTileCacheSystemInfo sysConfig;
45};
46
47void mTileCacheInit(struct mTileCache* cache);
48void mTileCacheDeinit(struct mTileCache* cache);
49void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config);
50void mTileCacheConfigureSystem(struct mTileCache* cache, mTileCacheSystemInfo config);
51void mTileCacheWriteVRAM(struct mTileCache* cache, uint32_t address);
52void mTileCacheWritePalette(struct mTileCache* cache, uint32_t address);
53void mTileCacheSetPalette(struct mTileCache* cache, int palette);
54
55const uint16_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId);
56const uint16_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId);
57
58#endif