forked from snes9xgit/snes9x
-
Notifications
You must be signed in to change notification settings - Fork 15
/
logger.cpp
98 lines (81 loc) · 1.87 KB
/
logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include "snes9x.h"
#include "movie.h"
#include "logger.h"
static int resetno = 0;
static int framecounter = 0;
static FILE *video = NULL;
static FILE *audio = NULL;
void S9xResetLogger (void)
{
if (!Settings.DumpStreams)
return;
char buffer[128];
S9xCloseLogger();
framecounter = 0;
sprintf(buffer, "videostream%d.dat", resetno);
video = fopen(buffer, "wb");
if (!video)
{
printf("Opening %s failed. Logging cancelled.\n", buffer);
return;
}
sprintf(buffer, "audiostream%d.dat", resetno);
audio = fopen(buffer, "wb");
if (!audio)
{
printf("Opening %s failed. Logging cancelled.\n", buffer);
fclose(video);
return;
}
resetno++;
}
void S9xCloseLogger (void)
{
if (video)
{
fclose(video);
video = NULL;
}
if (audio)
{
fclose(audio);
audio = NULL;
}
}
void S9xVideoLogger (void *pixels, int width, int height, int depth, int bytes_per_line)
{
int fc = S9xMovieGetFrameCounter();
if (fc > 0)
framecounter = fc;
else
framecounter++;
if (video)
{
char *data = (char *) pixels;
for (int i = 0; i < height; i++)
{
if (!fwrite(data + i * bytes_per_line, depth, width, video))
printf ("Error writing video data.\n");
}
fflush(video);
fflush(audio);
if (Settings.DumpStreamsMaxFrames > 0 && framecounter >= Settings.DumpStreamsMaxFrames)
{
printf("Logging ended.\n");
S9xCloseLogger();
}
}
}
void S9xAudioLogger (void *samples, int length)
{
if (audio)
{
if (!fwrite(samples, 1, length, audio))
printf ("Error writing audio data.\n");
}
}