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
11CXX_GUARD_START
12
13DECL_BITFIELD(mTileCacheConfiguration, uint32_t);
14DECL_BIT(mTileCacheConfiguration, ShouldStore, 0);
15
16DECL_BITFIELD(mTileCacheSystemInfo, uint32_t);
17DECL_BITS(mTileCacheSystemInfo, Palette0BPP, 0, 2);
18DECL_BITS(mTileCacheSystemInfo, Palette0Count, 2, 4);
19DECL_BITS(mTileCacheSystemInfo, Palette1BPP, 8, 2);
20DECL_BITS(mTileCacheSystemInfo, Palette1Count, 10, 4);
21DECL_BITS(mTileCacheSystemInfo, MaxTiles, 16, 13);
22
23struct mTileCacheEntry {
24 uint32_t paletteVersion;
25 uint32_t vramVersion;
26 uint8_t vramClean;
27 uint8_t paletteId;
28 uint8_t activePalette;
29 uint8_t padding;
30};
31
32struct mTileCache {
33 uint16_t* cache;
34 struct mTileCacheEntry* status;
35 uint32_t* globalPaletteVersion[2];
36
37 int activePalette;
38 unsigned entries;
39 unsigned count;
40 unsigned entriesPerTile;
41 unsigned bpp;
42
43 uint16_t* vram;
44 uint16_t* palette;
45 uint16_t temporaryTile[64];
46
47 mTileCacheConfiguration config;
48 mTileCacheSystemInfo sysConfig;
49};
50
51void mTileCacheInit(struct mTileCache* cache);
52void mTileCacheDeinit(struct mTileCache* cache);
53void mTileCacheConfigure(struct mTileCache* cache, mTileCacheConfiguration config);
54void mTileCacheConfigureSystem(struct mTileCache* cache, mTileCacheSystemInfo config);
55void mTileCacheWriteVRAM(struct mTileCache* cache, uint32_t address);
56void mTileCacheWritePalette(struct mTileCache* cache, uint32_t address);
57void mTileCacheSetPalette(struct mTileCache* cache, int palette);
58
59const uint16_t* mTileCacheGetTile(struct mTileCache* cache, unsigned tileId, unsigned paletteId);
60const uint16_t* mTileCacheGetTileIfDirty(struct mTileCache* cache, struct mTileCacheEntry* entry, unsigned tileId, unsigned paletteId);
61
62CXX_GUARD_END
63
64#endif