all repos — mgba @ bec2757dbf0ddb3d28d09353d2cc4a7aea716103

mGBA Game Boy Advance Emulator

include/mgba/core/map-cache.h (view raw)

 1/* Copyright (c) 2013-2017 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_MAP_CACHE_H
 7#define M_MAP_CACHE_H
 8
 9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/interface.h>
14#include <mgba/core/tile-cache.h>
15
16DECL_BITFIELD(mMapCacheConfiguration, uint32_t);
17DECL_BIT(mMapCacheConfiguration, ShouldStore, 0);
18
19DECL_BITFIELD(mMapCacheSystemInfo, uint32_t);
20DECL_BITS(mMapCacheSystemInfo, PaletteBPP, 0, 2);
21DECL_BITS(mMapCacheSystemInfo, PaletteCount, 2, 4);
22DECL_BITS(mMapCacheSystemInfo, TilesWide, 8, 4);
23DECL_BITS(mMapCacheSystemInfo, TilesHigh, 12, 4);
24DECL_BITS(mMapCacheSystemInfo, MacroTileSize, 16, 7);
25DECL_BITS(mMapCacheSystemInfo, MapAlign, 23, 2);
26
27DECL_BITFIELD(mMapCacheEntryFlags, uint16_t);
28DECL_BITS(mMapCacheEntryFlags, PaletteId, 0, 4);
29DECL_BIT(mMapCacheEntryFlags, VramClean, 4);
30DECL_BIT(mMapCacheEntryFlags, HMirror, 5);
31DECL_BIT(mMapCacheEntryFlags, VMirror, 6);
32DECL_BITS(mMapCacheEntryFlags, Mirror, 5, 2);
33
34struct mMapCacheEntry {
35	uint32_t vramVersion;
36	uint16_t tileId;
37	mMapCacheEntryFlags flags;
38	struct mTileCacheEntry tileStatus[16];
39};
40
41struct mTileCache;
42struct mTileCacheEntry;
43struct mMapCache {
44	color_t* cache;
45	struct mTileCache* tileCache;
46	struct mMapCacheEntry* status;
47
48	uint8_t* vram;
49
50	uint32_t mapStart;
51	uint32_t mapSize;
52
53	uint32_t tileStart;
54
55	mMapCacheConfiguration config;
56	mMapCacheSystemInfo sysConfig;
57
58	void (*mapParser)(struct mMapCache*, struct mMapCacheEntry* entry, void* vram);
59	void* context;
60};
61
62void mMapCacheInit(struct mMapCache* cache);
63void mMapCacheDeinit(struct mMapCache* cache);
64void mMapCacheConfigure(struct mMapCache* cache, mMapCacheConfiguration config);
65void mMapCacheConfigureSystem(struct mMapCache* cache, mMapCacheSystemInfo config);
66void mMapCacheConfigureMap(struct mMapCache* cache, uint32_t mapStart);
67void mMapCacheWriteVRAM(struct mMapCache* cache, uint32_t address);
68
69uint32_t mMapCacheTileId(struct mMapCache* cache, unsigned x, unsigned y);
70
71bool mMapCacheCheckTile(struct mMapCache* cache, const struct mMapCacheEntry* entry, unsigned x, unsigned y);
72void mMapCacheCleanTile(struct mMapCache* cache, struct mMapCacheEntry* entry, unsigned x, unsigned y);
73
74void mMapCacheCleanRow(struct mMapCache* cache, unsigned y);
75const color_t* mMapCacheGetRow(struct mMapCache* cache, unsigned y);
76
77CXX_GUARD_END
78
79#endif