all repos — mgba @ 0a4b47cccfcbbe60a8af3616ff930b09b50b9682

mGBA Game Boy Advance Emulator

include/mgba/internal/ds/video.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 DS_VIDEO_H
  7#define DS_VIDEO_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/interface.h>
 14#include <mgba/core/log.h>
 15#include <mgba/core/timing.h>
 16#include <mgba/internal/gba/video.h>
 17
 18mLOG_DECLARE_CATEGORY(DS_VIDEO);
 19
 20enum {
 21	DS_VIDEO_HORIZONTAL_PIXELS = 256,
 22	DS_VIDEO_HBLANK_PIXELS = 99,
 23	DS7_VIDEO_HBLANK_LENGTH = 1613,
 24	DS9_VIDEO_HBLANK_LENGTH = 1606,
 25	DS_VIDEO_HORIZONTAL_LENGTH = (DS_VIDEO_HORIZONTAL_PIXELS + DS_VIDEO_HBLANK_PIXELS) * 6,
 26
 27	DS_VIDEO_VERTICAL_PIXELS = 192,
 28	DS_VIDEO_VBLANK_PIXELS = 71,
 29	DS_VIDEO_VERTICAL_TOTAL_PIXELS = DS_VIDEO_VERTICAL_PIXELS + DS_VIDEO_VBLANK_PIXELS,
 30
 31	DS_VIDEO_TOTAL_LENGTH = DS_VIDEO_HORIZONTAL_LENGTH * DS_VIDEO_VERTICAL_TOTAL_PIXELS,
 32};
 33
 34union DSOAM {
 35	union GBAOAM oam[2];
 36	uint16_t raw[1024];
 37};
 38
 39DECL_BITFIELD(DSRegisterDISPCNT, uint32_t);
 40DECL_BITS(DSRegisterDISPCNT, Mode, 0, 3);
 41DECL_BIT(DSRegisterDISPCNT, 3D, 3);
 42DECL_BIT(DSRegisterDISPCNT, TileObjMapping, 4);
 43DECL_BIT(DSRegisterDISPCNT, BitmapObj2D, 5);
 44DECL_BIT(DSRegisterDISPCNT, BitmapObjMapping, 6);
 45DECL_BIT(DSRegisterDISPCNT, ForcedBlank, 7);
 46DECL_BIT(DSRegisterDISPCNT, Bg0Enable, 8);
 47DECL_BIT(DSRegisterDISPCNT, Bg1Enable, 9);
 48DECL_BIT(DSRegisterDISPCNT, Bg2Enable, 10);
 49DECL_BIT(DSRegisterDISPCNT, Bg3Enable, 11);
 50DECL_BIT(DSRegisterDISPCNT, ObjEnable, 12);
 51DECL_BIT(DSRegisterDISPCNT, Win0Enable, 13);
 52DECL_BIT(DSRegisterDISPCNT, Win1Enable, 14);
 53DECL_BIT(DSRegisterDISPCNT, ObjwinEnable, 15);
 54DECL_BITS(DSRegisterDISPCNT, DispMode, 16, 2);
 55DECL_BITS(DSRegisterDISPCNT, VRAMBlock, 18, 2);
 56DECL_BITS(DSRegisterDISPCNT, TileBoundary, 20, 2);
 57// TODO
 58DECL_BITS(DSRegisterDISPCNT, CharBase, 24, 3);
 59DECL_BITS(DSRegisterDISPCNT, ScreenBase, 27, 3);
 60// TODO
 61DECL_BIT(DSRegisterDISPCNT, BgExtPalette, 30);
 62DECL_BIT(DSRegisterDISPCNT, ObjExtPalette, 31);
 63
 64DECL_BITFIELD(DSRegisterDISPCAPCNT, uint32_t);
 65DECL_BITS(DSRegisterDISPCAPCNT, EVA, 0, 4);
 66DECL_BITS(DSRegisterDISPCAPCNT, EVB, 8, 4);
 67DECL_BITS(DSRegisterDISPCAPCNT, WriteBlock, 16, 2);
 68DECL_BITS(DSRegisterDISPCAPCNT, WriteOffset, 18, 2);
 69DECL_BITS(DSRegisterDISPCAPCNT, CaptureSize, 20, 2);
 70DECL_BIT(DSRegisterDISPCAPCNT, SourceA, 24);
 71DECL_BIT(DSRegisterDISPCAPCNT, SourceB, 25);
 72DECL_BITS(DSRegisterDISPCAPCNT, ReadOffset, 26, 2);
 73DECL_BITS(DSRegisterDISPCAPCNT, CaptureSource, 29, 2);
 74DECL_BIT(DSRegisterDISPCAPCNT, Enable, 31);
 75
 76DECL_BITFIELD(DSRegisterPOWCNT1, uint16_t);
 77// TODO
 78DECL_BIT(DSRegisterPOWCNT1, Swap, 15);
 79
 80DECL_BIT(GBARegisterBGCNT, ExtendedMode0, 2);
 81DECL_BIT(GBARegisterBGCNT, ExtendedMode1, 7);
 82DECL_BIT(GBARegisterBGCNT, ExtPaletteSlot, 13);
 83
 84DECL_BITFIELD(DSRegisterMASTER_BRIGHT, uint16_t);
 85DECL_BITS(DSRegisterMASTER_BRIGHT, Y, 0, 5);
 86DECL_BITS(DSRegisterMASTER_BRIGHT, Mode, 14, 2);
 87
 88struct DSGX;
 89struct DSVideoRenderer {
 90	void (*init)(struct DSVideoRenderer* renderer);
 91	void (*reset)(struct DSVideoRenderer* renderer);
 92	void (*deinit)(struct DSVideoRenderer* renderer);
 93
 94	uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 95	void (*writePalette)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 96	void (*writeOAM)(struct DSVideoRenderer* renderer, uint32_t oam);
 97	void (*invalidateExtPal)(struct DSVideoRenderer* renderer, bool obj, bool engB, int slot);
 98	void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
 99	void (*drawScanlineDirectly)(struct DSVideoRenderer* renderer, int y, color_t* scanline);
100	void (*finishFrame)(struct DSVideoRenderer* renderer);
101
102	void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
103	void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
104
105	uint16_t* palette;
106	uint16_t* vram;
107	uint16_t* vramABG[32];
108	uint16_t* vramAOBJ[32];
109	uint16_t* vramABGExtPal[4];
110	uint16_t* vramAOBJExtPal;
111	uint16_t* vramBBG[32];
112	uint16_t* vramBOBJ[32];
113	uint16_t* vramBBGExtPal[4];
114	uint16_t* vramBOBJExtPal;
115	union DSOAM* oam;
116	struct DSGX* gx;
117};
118
119struct DS;
120struct DSVideo {
121	struct DS* p;
122	struct DSVideoRenderer* renderer;
123	struct mTimingEvent event7;
124	struct mTimingEvent event9;
125
126	int vcount;
127	bool inCapture;
128
129	uint16_t palette[1024];
130	uint16_t* vram;
131	uint16_t* vramABG[32];
132	uint16_t* vramAOBJ[32];
133	uint16_t* vramABGExtPal[4];
134	uint16_t* vramAOBJExtPal;
135	uint16_t* vramBBG[32];
136	uint16_t* vramBOBJ[32];
137	uint16_t* vramBBGExtPal[4];
138	uint16_t* vramBOBJExtPal;
139	union DSOAM oam;
140
141	int32_t frameCounter;
142	int frameskip;
143	int frameskipCounter;
144};
145
146void DSVideoInit(struct DSVideo* video);
147void DSVideoReset(struct DSVideo* video);
148void DSVideoDeinit(struct DSVideo* video);
149void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
150
151struct DSCommon;
152void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
153
154struct DSMemory;
155void DSVideoConfigureVRAM(struct DS* ds, int index, uint8_t value, uint8_t oldValue);
156
157CXX_GUARD_START
158
159#endif