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-util/circle-buffer.h>
14
15#define mVL_MAX_CHANNELS 32
16
17enum mVideoLoggerDirtyType {
18 DIRTY_DUMMY = 0,
19 DIRTY_FLUSH,
20 DIRTY_SCANLINE,
21 DIRTY_REGISTER,
22 DIRTY_OAM,
23 DIRTY_PALETTE,
24 DIRTY_VRAM,
25 DIRTY_FRAME,
26 DIRTY_RANGE,
27 DIRTY_BUFFER,
28};
29
30struct mVideoLoggerDirtyInfo {
31 enum mVideoLoggerDirtyType type;
32 uint32_t address;
33 uint32_t value;
34 uint32_t value2;
35};
36
37struct VFile;
38struct mVideoLogger {
39 bool (*writeData)(struct mVideoLogger* logger, const void* data, size_t length);
40 bool (*readData)(struct mVideoLogger* logger, void* data, size_t length, bool block);
41 void* dataContext;
42
43 bool block;
44 void (*init)(struct mVideoLogger*);
45 void (*deinit)(struct mVideoLogger*);
46 void (*reset)(struct mVideoLogger*);
47
48 void (*lock)(struct mVideoLogger*);
49 void (*unlock)(struct mVideoLogger*);
50 void (*wait)(struct mVideoLogger*);
51 void (*wake)(struct mVideoLogger*, int y);
52 void* context;
53
54 bool (*parsePacket)(struct mVideoLogger* logger, const struct mVideoLoggerDirtyInfo* packet);
55 uint16_t* (*vramBlock)(struct mVideoLogger* logger, uint32_t address);
56
57 size_t vramSize;
58 size_t oamSize;
59 size_t paletteSize;
60
61 uint32_t* vramDirtyBitmap;
62 uint32_t* oamDirtyBitmap;
63
64 uint16_t* vram;
65 uint16_t* oam;
66 uint16_t* palette;
67};
68
69void mVideoLoggerRendererCreate(struct mVideoLogger* logger, bool readonly);
70void mVideoLoggerRendererInit(struct mVideoLogger* logger);
71void mVideoLoggerRendererDeinit(struct mVideoLogger* logger);
72void mVideoLoggerRendererReset(struct mVideoLogger* logger);
73
74void mVideoLoggerRendererWriteVideoRegister(struct mVideoLogger* logger, uint32_t address, uint16_t value);
75void mVideoLoggerRendererWriteVRAM(struct mVideoLogger* logger, uint32_t address);
76void mVideoLoggerRendererWritePalette(struct mVideoLogger* logger, uint32_t address, uint16_t value);
77void mVideoLoggerRendererWriteOAM(struct mVideoLogger* logger, uint32_t address, uint16_t value);
78
79void mVideoLoggerWriteBuffer(struct mVideoLogger* logger, uint32_t bufferId, uint32_t offset, uint32_t length, const void* data);
80
81void mVideoLoggerRendererDrawScanline(struct mVideoLogger* logger, int y);
82void mVideoLoggerRendererDrawRange(struct mVideoLogger* logger, int startX, int endX, int y);
83void mVideoLoggerRendererFlush(struct mVideoLogger* logger);
84void mVideoLoggerRendererFinishFrame(struct mVideoLogger* logger);
85
86bool mVideoLoggerRendererRun(struct mVideoLogger* logger, bool block);
87
88struct mVideoLogContext;
89void mVideoLoggerAttachChannel(struct mVideoLogger* logger, struct mVideoLogContext* context, size_t channelId);
90
91struct mCore;
92struct mVideoLogContext* mVideoLogContextCreate(struct mCore* core);
93
94void mVideoLogContextSetOutput(struct mVideoLogContext*, struct VFile*);
95void mVideoLogContextWriteHeader(struct mVideoLogContext*, struct mCore* core);
96
97bool mVideoLogContextLoad(struct mVideoLogContext*, struct VFile*);
98void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext*);
99
100void mVideoLogContextRewind(struct mVideoLogContext*, struct mCore*);
101void* mVideoLogContextInitialState(struct mVideoLogContext*, size_t* size);
102
103int mVideoLoggerAddChannel(struct mVideoLogContext*);
104
105struct mCore* mVideoLogCoreFind(struct VFile*);
106
107CXX_GUARD_END
108
109#endif