all repos — mgba @ 19a42a387a4a9316e5626c8079bed4d989d9c3ac

mGBA Game Boy Advance Emulator

src/core/cache-set.c (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#include <mgba/core/cache-set.h>
 7
 8DEFINE_VECTOR(mMapCacheSet, struct mMapCache);
 9DEFINE_VECTOR(mTileCacheSet, struct mTileCache);
10
11void mCacheSetInit(struct mCacheSet* cache, size_t nMaps, size_t nTiles) {
12	mMapCacheSetInit(&cache->maps, nMaps);
13	mMapCacheSetResize(&cache->maps, nMaps);
14	mTileCacheSetInit(&cache->tiles, nTiles);
15	mTileCacheSetResize(&cache->tiles, nTiles);
16
17	size_t i;
18	for (i = 0; i < nMaps; ++i) {
19		mMapCacheInit(mMapCacheSetGetPointer(&cache->maps, i));
20	}
21	for (i = 0; i < nTiles; ++i) {
22		mTileCacheInit(mTileCacheSetGetPointer(&cache->tiles, i));
23	}
24}
25
26void mCacheSetDeinit(struct mCacheSet* cache) {
27	size_t i;
28	for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
29		mMapCacheDeinit(mMapCacheSetGetPointer(&cache->maps, i));
30	}
31	for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
32		mTileCacheDeinit(mTileCacheSetGetPointer(&cache->tiles, i));
33	}
34}
35
36void mCacheSetAssignVRAM(struct mCacheSet* cache, void* vram) {
37	size_t i;
38	for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
39		mMapCacheSetGetPointer(&cache->maps, i)->vram = vram;
40	}
41	for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
42		struct mTileCache* tileCache = mTileCacheSetGetPointer(&cache->tiles, i);
43		tileCache->vram = (void*) ((uintptr_t) vram + tileCache->tileBase);
44	}
45}
46
47void mCacheSetWriteVRAM(struct mCacheSet* cache, uint32_t address) {
48	size_t i;
49	for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
50		mMapCacheWriteVRAM(mMapCacheSetGetPointer(&cache->maps, i), address);
51	}
52	for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
53		mTileCacheWriteVRAM(mTileCacheSetGetPointer(&cache->tiles, i), address);
54	}
55}
56
57void mCacheSetWritePalette(struct mCacheSet* cache, uint32_t entry, color_t color) {
58	size_t i;
59	for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
60		mTileCacheWritePalette(mTileCacheSetGetPointer(&cache->tiles, i), entry, color);
61	}
62}