all repos — mgba @ fc3e47a4bab1465b91e7368c6396b222f65f51cb

mGBA Game Boy Advance Emulator

include/mgba/feature/video-logger.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 VIDEO_LOGGER_H
  7#define VIDEO_LOGGER_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/core/core.h>
 14
 15#include <mgba-util/circle-buffer.h>
 16
 17#define mVL_MAX_CHANNELS 32
 18
 19enum mVideoLoggerDirtyType {
 20	DIRTY_DUMMY = 0,
 21	DIRTY_FLUSH,
 22	DIRTY_SCANLINE,
 23	DIRTY_REGISTER,
 24	DIRTY_OAM,
 25	DIRTY_PALETTE,
 26	DIRTY_VRAM,
 27	DIRTY_FRAME,
 28	DIRTY_RANGE,
 29	DIRTY_BUFFER,
 30};
 31
 32enum mVideoLoggerEvent {
 33	LOGGER_EVENT_NONE = 0,
 34	LOGGER_EVENT_INIT,
 35	LOGGER_EVENT_DEINIT,
 36	LOGGER_EVENT_RESET,
 37	LOGGER_EVENT_GET_PIXELS,
 38};
 39
 40enum mVideoLoggerInjectionPoint {
 41	LOGGER_INJECTION_IMMEDIATE = 0,
 42	LOGGER_INJECTION_FIRST_SCANLINE,
 43};
 44
 45struct mVideoLoggerDirtyInfo {
 46	enum mVideoLoggerDirtyType type;
 47	uint32_t address;
 48	uint32_t value;
 49	uint32_t value2;
 50};
 51
 52struct VFile;
 53struct mVideoLogger {
 54	bool (*writeData)(struct mVideoLogger* logger, const void* data, size_t length);
 55	bool (*readData)(struct mVideoLogger* logger, void* data, size_t length, bool block);
 56	void (*postEvent)(struct mVideoLogger* logger, enum mVideoLoggerEvent event);
 57	void* dataContext;
 58
 59	bool block;
 60	bool waitOnFlush;
 61	void (*init)(struct mVideoLogger*);
 62	void (*deinit)(struct mVideoLogger*);
 63	void (*reset)(struct mVideoLogger*);
 64
 65	void (*lock)(struct mVideoLogger*);
 66	void (*unlock)(struct mVideoLogger*);
 67	void (*wait)(struct mVideoLogger*);
 68	void (*wake)(struct mVideoLogger*, int y);
 69	void* context;
 70
 71	bool (*parsePacket)(struct mVideoLogger* logger, const struct mVideoLoggerDirtyInfo* packet);
 72	void (*handleEvent)(struct mVideoLogger* logger, enum mVideoLoggerEvent event);
 73	uint16_t* (*vramBlock)(struct mVideoLogger* logger, uint32_t address);
 74
 75	size_t vramSize;
 76	size_t oamSize;
 77	size_t paletteSize;
 78
 79	uint32_t* vramDirtyBitmap;
 80	uint32_t* oamDirtyBitmap;
 81
 82	uint16_t* vram;
 83	uint16_t* oam;
 84	uint16_t* palette;
 85
 86	const void* pixelBuffer;
 87	size_t pixelStride;
 88};
 89
 90void mVideoLoggerRendererCreate(struct mVideoLogger* logger, bool readonly);
 91void mVideoLoggerRendererInit(struct mVideoLogger* logger);
 92void mVideoLoggerRendererDeinit(struct mVideoLogger* logger);
 93void mVideoLoggerRendererReset(struct mVideoLogger* logger);
 94
 95void mVideoLoggerRendererWriteVideoRegister(struct mVideoLogger* logger, uint32_t address, uint16_t value);
 96void mVideoLoggerRendererWriteVRAM(struct mVideoLogger* logger, uint32_t address);
 97void mVideoLoggerRendererWritePalette(struct mVideoLogger* logger, uint32_t address, uint16_t value);
 98void mVideoLoggerRendererWriteOAM(struct mVideoLogger* logger, uint32_t address, uint16_t value);
 99
100void mVideoLoggerWriteBuffer(struct mVideoLogger* logger, uint32_t bufferId, uint32_t offset, uint32_t length, const void* data);
101
102void mVideoLoggerRendererDrawScanline(struct mVideoLogger* logger, int y);
103void mVideoLoggerRendererDrawRange(struct mVideoLogger* logger, int startX, int endX, int y);
104void mVideoLoggerRendererFlush(struct mVideoLogger* logger);
105void mVideoLoggerRendererFinishFrame(struct mVideoLogger* logger);
106
107bool mVideoLoggerRendererRun(struct mVideoLogger* logger, bool block);
108bool mVideoLoggerRendererRunInjected(struct mVideoLogger* logger);
109
110struct mVideoLogContext;
111void mVideoLoggerAttachChannel(struct mVideoLogger* logger, struct mVideoLogContext* context, size_t channelId);
112
113struct mCore;
114struct mVideoLogContext* mVideoLogContextCreate(struct mCore* core);
115
116void mVideoLogContextSetCompression(struct mVideoLogContext*, bool enable);
117void mVideoLogContextSetOutput(struct mVideoLogContext*, struct VFile*);
118void mVideoLogContextWriteHeader(struct mVideoLogContext*, struct mCore* core);
119
120bool mVideoLogContextLoad(struct mVideoLogContext*, struct VFile*);
121void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext*, bool closeVF);
122
123void mVideoLogContextRewind(struct mVideoLogContext*, struct mCore*);
124void* mVideoLogContextInitialState(struct mVideoLogContext*, size_t* size);
125
126int mVideoLoggerAddChannel(struct mVideoLogContext*);
127
128void mVideoLoggerInjectionPoint(struct mVideoLogger* logger, enum mVideoLoggerInjectionPoint);
129void mVideoLoggerIgnoreAfterInjection(struct mVideoLogger* logger, uint32_t mask);
130void mVideoLoggerInjectVideoRegister(struct mVideoLogger* logger, uint32_t address, uint16_t value);
131void mVideoLoggerInjectPalette(struct mVideoLogger* logger, uint32_t address, uint16_t value);
132void mVideoLoggerInjectOAM(struct mVideoLogger* logger, uint32_t address, uint16_t value);
133
134enum mPlatform mVideoLogIsCompatible(struct VFile*);
135struct mCore* mVideoLogCoreFind(struct VFile*);
136
137CXX_GUARD_END
138
139#endif