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 void (*init)(struct mVideoLogger*);
61 void (*deinit)(struct mVideoLogger*);
62 void (*reset)(struct mVideoLogger*);
63
64 void (*lock)(struct mVideoLogger*);
65 void (*unlock)(struct mVideoLogger*);
66 void (*wait)(struct mVideoLogger*);
67 void (*wake)(struct mVideoLogger*, int y);
68 void* context;
69
70 bool (*parsePacket)(struct mVideoLogger* logger, const struct mVideoLoggerDirtyInfo* packet);
71 void (*handleEvent)(struct mVideoLogger* logger, enum mVideoLoggerEvent event);
72 uint16_t* (*vramBlock)(struct mVideoLogger* logger, uint32_t address);
73
74 size_t vramSize;
75 size_t oamSize;
76 size_t paletteSize;
77
78 uint32_t* vramDirtyBitmap;
79 uint32_t* oamDirtyBitmap;
80
81 uint16_t* vram;
82 uint16_t* oam;
83 uint16_t* palette;
84
85 const void* pixelBuffer;
86 size_t pixelStride;
87};
88
89void mVideoLoggerRendererCreate(struct mVideoLogger* logger, bool readonly);
90void mVideoLoggerRendererInit(struct mVideoLogger* logger);
91void mVideoLoggerRendererDeinit(struct mVideoLogger* logger);
92void mVideoLoggerRendererReset(struct mVideoLogger* logger);
93
94void mVideoLoggerRendererWriteVideoRegister(struct mVideoLogger* logger, uint32_t address, uint16_t value);
95void mVideoLoggerRendererWriteVRAM(struct mVideoLogger* logger, uint32_t address);
96void mVideoLoggerRendererWritePalette(struct mVideoLogger* logger, uint32_t address, uint16_t value);
97void mVideoLoggerRendererWriteOAM(struct mVideoLogger* logger, uint32_t address, uint16_t value);
98
99void mVideoLoggerWriteBuffer(struct mVideoLogger* logger, uint32_t bufferId, uint32_t offset, uint32_t length, const void* data);
100
101void mVideoLoggerRendererDrawScanline(struct mVideoLogger* logger, int y);
102void mVideoLoggerRendererDrawRange(struct mVideoLogger* logger, int startX, int endX, int y);
103void mVideoLoggerRendererFlush(struct mVideoLogger* logger);
104void mVideoLoggerRendererFinishFrame(struct mVideoLogger* logger);
105
106bool mVideoLoggerRendererRun(struct mVideoLogger* logger, bool block);
107bool mVideoLoggerRendererRunInjected(struct mVideoLogger* logger);
108
109struct mVideoLogContext;
110void mVideoLoggerAttachChannel(struct mVideoLogger* logger, struct mVideoLogContext* context, size_t channelId);
111
112struct mCore;
113struct mVideoLogContext* mVideoLogContextCreate(struct mCore* core);
114
115void mVideoLogContextSetCompression(struct mVideoLogContext*, bool enable);
116void mVideoLogContextSetOutput(struct mVideoLogContext*, struct VFile*);
117void mVideoLogContextWriteHeader(struct mVideoLogContext*, struct mCore* core);
118
119bool mVideoLogContextLoad(struct mVideoLogContext*, struct VFile*);
120void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext*, bool closeVF);
121
122void mVideoLogContextRewind(struct mVideoLogContext*, struct mCore*);
123void* mVideoLogContextInitialState(struct mVideoLogContext*, size_t* size);
124
125int mVideoLoggerAddChannel(struct mVideoLogContext*);
126
127void mVideoLoggerInjectionPoint(struct mVideoLogger* logger, enum mVideoLoggerInjectionPoint);
128void mVideoLoggerIgnoreAfterInjection(struct mVideoLogger* logger, uint32_t mask);
129void mVideoLoggerInjectVideoRegister(struct mVideoLogger* logger, uint32_t address, uint16_t value);
130void mVideoLoggerInjectPalette(struct mVideoLogger* logger, uint32_t address, uint16_t value);
131void mVideoLoggerInjectOAM(struct mVideoLogger* logger, uint32_t address, uint16_t value);
132
133enum mPlatform mVideoLogIsCompatible(struct VFile*);
134struct mCore* mVideoLogCoreFind(struct VFile*);
135
136CXX_GUARD_END
137
138#endif