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(mBitmapCacheSet, struct mBitmapCache);
10DEFINE_VECTOR(mTileCacheSet, struct mTileCache);
11
12void mCacheSetInit(struct mCacheSet* cache, size_t nMaps, size_t nBitmaps, size_t nTiles) {
13 mMapCacheSetInit(&cache->maps, nMaps);
14 mMapCacheSetResize(&cache->maps, nMaps);
15 mBitmapCacheSetInit(&cache->bitmaps, nBitmaps);
16 mBitmapCacheSetResize(&cache->bitmaps, nBitmaps);
17 mTileCacheSetInit(&cache->tiles, nTiles);
18 mTileCacheSetResize(&cache->tiles, nTiles);
19
20 size_t i;
21 for (i = 0; i < nMaps; ++i) {
22 mMapCacheInit(mMapCacheSetGetPointer(&cache->maps, i));
23 }
24 for (i = 0; i < nBitmaps; ++i) {
25 mBitmapCacheInit(mBitmapCacheSetGetPointer(&cache->bitmaps, i));
26 }
27 for (i = 0; i < nTiles; ++i) {
28 mTileCacheInit(mTileCacheSetGetPointer(&cache->tiles, i));
29 }
30}
31
32void mCacheSetDeinit(struct mCacheSet* cache) {
33 size_t i;
34 for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
35 mMapCacheDeinit(mMapCacheSetGetPointer(&cache->maps, i));
36 }
37 for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
38 mBitmapCacheDeinit(mBitmapCacheSetGetPointer(&cache->bitmaps, i));
39 }
40 for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
41 mTileCacheDeinit(mTileCacheSetGetPointer(&cache->tiles, i));
42 }
43}
44
45void mCacheSetAssignVRAM(struct mCacheSet* cache, void* vram) {
46 size_t i;
47 for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
48 mMapCacheSetGetPointer(&cache->maps, i)->vram = vram;
49 }
50 for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
51 mBitmapCacheSetGetPointer(&cache->bitmaps, i)->vram = vram;
52 }
53 for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
54 struct mTileCache* tileCache = mTileCacheSetGetPointer(&cache->tiles, i);
55 tileCache->vram = (void*) ((uintptr_t) vram + tileCache->tileBase);
56 }
57}
58
59void mCacheSetWriteVRAM(struct mCacheSet* cache, uint32_t address) {
60 size_t i;
61 for (i = 0; i < mMapCacheSetSize(&cache->maps); ++i) {
62 mMapCacheWriteVRAM(mMapCacheSetGetPointer(&cache->maps, i), address);
63 }
64 for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
65 mBitmapCacheWriteVRAM(mBitmapCacheSetGetPointer(&cache->bitmaps, i), address);
66 }
67 for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
68 mTileCacheWriteVRAM(mTileCacheSetGetPointer(&cache->tiles, i), address);
69 }
70}
71
72void mCacheSetWritePalette(struct mCacheSet* cache, uint32_t entry, color_t color) {
73 size_t i;
74 for (i = 0; i < mBitmapCacheSetSize(&cache->bitmaps); ++i) {
75 mBitmapCacheWritePalette(mBitmapCacheSetGetPointer(&cache->bitmaps, i), entry, color);
76 }
77 for (i = 0; i < mTileCacheSetSize(&cache->tiles); ++i) {
78 mTileCacheWritePalette(mTileCacheSetGetPointer(&cache->tiles, i), entry, color);
79 }
80}