all repos — mgba @ 488decf83a8ff476830f8afa7b68bbd898a04a03

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/log.h>
 14#include <mgba/core/timing.h>
 15#include <mgba/internal/gba/video.h>
 16
 17mLOG_DECLARE_CATEGORY(DS_VIDEO);
 18
 19enum {
 20	DS_VIDEO_HORIZONTAL_PIXELS = 256,
 21	DS_VIDEO_HBLANK_PIXELS = 99,
 22	DS7_VIDEO_HBLANK_LENGTH = 1613,
 23	DS9_VIDEO_HBLANK_LENGTH = 1606,
 24	DS_VIDEO_HORIZONTAL_LENGTH = (DS_VIDEO_HORIZONTAL_PIXELS + DS_VIDEO_HBLANK_PIXELS) * 6,
 25
 26	DS_VIDEO_VERTICAL_PIXELS = 192,
 27	DS_VIDEO_VBLANK_PIXELS = 71,
 28	DS_VIDEO_VERTICAL_TOTAL_PIXELS = DS_VIDEO_VERTICAL_PIXELS + DS_VIDEO_VBLANK_PIXELS,
 29
 30	DS_VIDEO_TOTAL_LENGTH = DS_VIDEO_HORIZONTAL_LENGTH * DS_VIDEO_VERTICAL_TOTAL_PIXELS,
 31};
 32
 33union DSOAM {
 34	union GBAOAM oam[2];
 35	uint16_t raw[1024];
 36};
 37
 38DECL_BITFIELD(DSRegisterDISPCNT, uint32_t);
 39DECL_BITS(DSRegisterDISPCNT, Mode, 0, 3);
 40DECL_BIT(DSRegisterDISPCNT, 3D, 3);
 41DECL_BIT(DSRegisterDISPCNT, TileObjMapping, 4);
 42DECL_BIT(DSRegisterDISPCNT, BitmapObj2D, 5);
 43DECL_BIT(DSRegisterDISPCNT, BitmapObjMapping, 6);
 44DECL_BIT(DSRegisterDISPCNT, ForcedBlank, 7);
 45DECL_BIT(DSRegisterDISPCNT, Bg0Enable, 8);
 46DECL_BIT(DSRegisterDISPCNT, Bg1Enable, 9);
 47DECL_BIT(DSRegisterDISPCNT, Bg2Enable, 10);
 48DECL_BIT(DSRegisterDISPCNT, Bg3Enable, 11);
 49DECL_BIT(DSRegisterDISPCNT, ObjEnable, 12);
 50DECL_BIT(DSRegisterDISPCNT, Win0Enable, 13);
 51DECL_BIT(DSRegisterDISPCNT, Win1Enable, 14);
 52DECL_BIT(DSRegisterDISPCNT, ObjwinEnable, 15);
 53DECL_BITS(DSRegisterDISPCNT, DispMode, 16, 2);
 54DECL_BITS(DSRegisterDISPCNT, VRAMBlock, 18, 2);
 55// TODO
 56
 57struct DSVideoRenderer {
 58	void (*init)(struct DSVideoRenderer* renderer);
 59	void (*reset)(struct DSVideoRenderer* renderer);
 60	void (*deinit)(struct DSVideoRenderer* renderer);
 61
 62	uint16_t (*writeVideoRegister)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 63	void (*writePalette)(struct DSVideoRenderer* renderer, uint32_t address, uint16_t value);
 64	void (*writeOAM)(struct DSVideoRenderer* renderer, uint32_t oam);
 65	void (*drawScanline)(struct DSVideoRenderer* renderer, int y);
 66	void (*finishFrame)(struct DSVideoRenderer* renderer);
 67
 68	void (*getPixels)(struct DSVideoRenderer* renderer, size_t* stride, const void** pixels);
 69	void (*putPixels)(struct DSVideoRenderer* renderer, size_t stride, const void* pixels);
 70
 71	uint16_t* palette;
 72	uint16_t* vram;
 73	uint16_t* vramABG[32];
 74	uint16_t* vramAOBJ[32];
 75	uint16_t* vramBBG[32];
 76	uint16_t* vramBOBJ[32];
 77	union DSOAM* oam;
 78};
 79
 80struct DS;
 81struct DSVideo {
 82	struct DS* p;
 83	struct DSVideoRenderer* renderer;
 84	struct mTimingEvent event7;
 85	struct mTimingEvent event9;
 86
 87	// VCOUNT
 88	int vcount;
 89
 90	uint16_t palette[1024];
 91	uint16_t* vram;
 92	uint16_t* vramABG[32];
 93	uint16_t* vramAOBJ[32];
 94	uint16_t* vramBBG[32];
 95	uint16_t* vramBOBJ[32];
 96	union DSOAM oam;
 97
 98	int32_t frameCounter;
 99	int frameskip;
100	int frameskipCounter;
101};
102
103void DSVideoInit(struct DSVideo* video);
104void DSVideoReset(struct DSVideo* video);
105void DSVideoDeinit(struct DSVideo* video);
106void DSVideoAssociateRenderer(struct DSVideo* video, struct DSVideoRenderer* renderer);
107
108struct DSCommon;
109void DSVideoWriteDISPSTAT(struct DSCommon* dscore, uint16_t value);
110
111struct DSMemory;
112void DSVideoConfigureVRAM(struct DS* ds, int index, uint8_t value);
113
114CXX_GUARD_START
115
116#endif