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 uint32_t vramVersion;
24 uint8_t vramClean;
25 uint8_t paletteId;
26 uint8_t activePalette;
27 uint8_t padding;
28};
29
30struct mTileCache {
31 uint16_t* cache;
32 struct mTileCacheEntry* status;
33 uint32_t* globalPaletteVersion[2];
34
35 int activePalette;
36 unsigned entries;
37 unsigned count;
38 unsigned entriesPerTile;
39 unsigned bpp;
40
41 uint16_t* vram;
42 uint16_t* palette;
43 uint16_t temporaryTile[64];
44
45 mTileCacheConfiguration config;
46 mTileCacheSystemInfo sysConfig;
47};
48
49void mTileCacheInit(struct mTileCache* cache);
50void mTileCacheDeinit(struct mTileCache* cache);
51void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config);
52void mTileCacheConfigureSystem(struct mTileCache* cache, mTileCacheSystemInfo config);
53void mTileCacheWriteVRAM(struct mTileCache* cache, uint32_t address);
54void mTileCacheWritePalette(struct mTileCache* cache, uint32_t address);
55void mTileCacheSetPalette(struct mTileCache* cache, int palette);
56
57const uint16_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId);
58const uint16_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId);
59
60#endif