forked from alanswx/Screenshot_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
67 lines (56 loc) · 1.56 KB
/
main.c
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
/*
Copyright 2019 alanswx
with help from the MiSTer contributors including Grabulosaure
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sched.h>
#include <inttypes.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "lodepng.h"
#include "mister_scalar.h"
const char *version = "$VER:ScreenShot" VDATE;
#define BASEADDR 536870912
unsigned char buffer[2048*3*1024];
void mister_scalar_free(mister_scalar *);
int main(int argc, char *argv[])
{
char filename[4096];
strcpy(filename,"MiSTer_screenshot.png");
if (argc > 1)
{
fprintf(stderr,"output name: %s\n", argv[1]);
strcpy(filename,argv[1]);
}
mister_scalar *ms=mister_scalar_init();
if (ms==NULL)
{
fprintf(stderr,"some problem with the mister scalar, maybe this core doesn't support it\n");
exit(1);
}
fprintf(stderr,"\nScreenshot code by alanswx\n\n");
fprintf(stderr,"Version %s\n\n", version + 5);
unsigned char *outputbuf = calloc(ms->width*ms->height*3,1);
mister_scalar_read(ms,outputbuf);
unsigned error;
if (!strcmp("-",filename))
{
unsigned char *buf;
unsigned int outsize;
error = lodepng_encode24(&buf,&outsize,outputbuf,ms->width,ms->height);
fwrite(buf,outsize,1,stdout);
}
else
error = lodepng_encode24_file(filename, outputbuf, ms->width, ms->height);
if(error) fprintf(stderr,"error %u: %s\n", error, lodepng_error_text(error));
free(outputbuf);
mister_scalar_free(ms);
if (error)
return 1;
else
return 0;
}