src/gba/supervisor/rr.h (view raw)
1/* Copyright (c) 2013-2015 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 GBA_RR_H
7#define GBA_RR_H
8
9#include "util/common.h"
10
11struct GBA;
12struct VDir;
13struct VFile;
14
15enum GBARRInitFrom {
16 INIT_EX_NIHILO = 0,
17 INIT_FROM_SAVEGAME = 1,
18 INIT_FROM_SAVESTATE = 2,
19 INIT_FROM_BOTH = 3,
20};
21
22enum GBARRTag {
23 // Playback tags
24 TAG_INVALID = 0x00,
25 TAG_INPUT = 0x01,
26 TAG_FRAME = 0x02,
27 TAG_LAG = 0x03,
28
29 // Stream chunking tags
30 TAG_BEGIN = 0x10,
31 TAG_END = 0x11,
32 TAG_PREVIOUSLY = 0x12,
33 TAG_NEXT_TIME = 0x13,
34 TAG_MAX_STREAM = 0x14,
35
36 // Recording information tags
37 TAG_FRAME_COUNT = 0x20,
38 TAG_LAG_COUNT = 0x21,
39 TAG_RR_COUNT = 0x22,
40 TAG_INIT = 0x24,
41 TAG_INIT_EX_NIHILO = 0x24 | INIT_EX_NIHILO,
42 TAG_INIT_FROM_SAVEGAME = 0x24 | INIT_FROM_SAVEGAME,
43 TAG_INIT_FROM_SAVESTATE = 0x24 | INIT_FROM_SAVESTATE,
44 TAG_INIT_FROM_BOTH = 0x24 | INIT_FROM_BOTH,
45
46 // User metadata tags
47 TAG_AUTHOR = 0x30,
48 TAG_COMMENT = 0x31,
49
50 TAG_EOF = INT_MAX
51};
52
53struct GBARRContext {
54 // Playback state
55 bool isPlaying;
56 bool autorecord;
57
58 // Recording state
59 bool isRecording;
60 bool inputThisFrame;
61
62 // Metadata
63 uint32_t frames;
64 uint32_t lagFrames;
65 uint32_t streamId;
66
67 uint32_t maxStreamId;
68 off_t maxStreamIdOffset;
69
70 enum GBARRInitFrom initFrom;
71 off_t initFromOffset;
72
73 uint32_t rrCount;
74 off_t rrCountOffset;
75
76 struct VFile* savedata;
77
78 // Streaming state
79 struct VDir* streamDir;
80 struct VFile* metadataFile;
81 struct VFile* movieStream;
82 uint16_t currentInput;
83 enum GBARRTag peekedTag;
84 uint32_t nextTime;
85 uint32_t previously;
86};
87
88void GBARRContextCreate(struct GBA*);
89void GBARRContextDestroy(struct GBA*);
90void GBARRSaveState(struct GBA*);
91void GBARRLoadState(struct GBA*);
92
93bool GBARRInitStream(struct GBARRContext*, struct VDir*);
94bool GBARRReinitStream(struct GBARRContext*, enum GBARRInitFrom);
95bool GBARRLoadStream(struct GBARRContext*, uint32_t streamId);
96bool GBARRIncrementStream(struct GBARRContext*, bool recursive);
97bool GBARRFinishSegment(struct GBARRContext*);
98bool GBARRSkipSegment(struct GBARRContext*);
99bool GBARRMarkRerecord(struct GBARRContext*);
100
101bool GBARRStartPlaying(struct GBARRContext*, bool autorecord);
102void GBARRStopPlaying(struct GBARRContext*);
103bool GBARRStartRecording(struct GBARRContext*);
104void GBARRStopRecording(struct GBARRContext*);
105
106bool GBARRIsPlaying(struct GBARRContext*);
107bool GBARRIsRecording(struct GBARRContext*);
108
109void GBARRNextFrame(struct GBARRContext*);
110void GBARRLogInput(struct GBARRContext*, uint16_t input);
111uint16_t GBARRQueryInput(struct GBARRContext*);
112
113#endif