summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-02-14 02:00:05 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-02-14 02:00:05 (GMT)
commit32f2b42c5055e0783ad3c076a1bdb9d6abcb5b28 (patch)
treec0734c342b7dc8cdb09f09d8df9db786b95a32db /meme
parent55c2f01bd436cd4186646d9c1e25b11d066f08ad (diff)
downloadmisc-32f2b42c5055e0783ad3c076a1bdb9d6abcb5b28.zip
misc-32f2b42c5055e0783ad3c076a1bdb9d6abcb5b28.tar.gz
misc-32f2b42c5055e0783ad3c076a1bdb9d6abcb5b28.tar.bz2
meme/screen.h, screen.c: copy over from anelok/sim/
Diffstat (limited to 'meme')
-rw-r--r--meme/screen.c61
-rw-r--r--meme/screen.h24
2 files changed, 85 insertions, 0 deletions
diff --git a/meme/screen.c b/meme/screen.c
new file mode 100644
index 0000000..c1b0f99
--- /dev/null
+++ b/meme/screen.c
@@ -0,0 +1,61 @@
+/*
+ * screen.c - Screen dump
+ *
+ * Written 2015 by Werner Almesberger
+ * Copyright 2015 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "sim.h"
+#include "screen.h"
+
+
+#define BASE_NAME "anelok-sim-"
+
+
+const char *screen_dump_name = NULL;
+
+
+void dump_screen_file(const char *name)
+{
+ if (SDL_SaveBMP(surf, name)) {
+ fprintf(stderr, "SDL_SaveBMP: %s\n", SDL_GetError());
+ exit(1);
+ }
+ fprintf(stderr, "Screen dump to %s\n", name);
+}
+
+
+static void dump_screen_unique(void)
+{
+ char tmp[sizeof(BASE_NAME) + 4 + 4];
+ int n;
+
+ for (n = 0; n <= 9999; n++) {
+ snprintf(tmp, sizeof(tmp), BASE_NAME "%04d.bmp", n);
+ if (access(tmp, R_OK)) {
+ dump_screen_file(tmp);
+ return;
+ }
+ }
+ fprintf(stderr, "dump_screen: no available name\n");
+ exit(1);
+}
+
+
+void dump_screen(void)
+{
+ if (screen_dump_name)
+ dump_screen_file(screen_dump_name);
+ else
+ dump_screen_unique();
+}
diff --git a/meme/screen.h b/meme/screen.h
new file mode 100644
index 0000000..9bfe845
--- /dev/null
+++ b/meme/screen.h
@@ -0,0 +1,24 @@
+/*
+ * screen.h - Screen dump
+ *
+ * Written 2015 by Werner Almesberger
+ * Copyright 2015 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef SCREEN_H
+#define SCREEN_H
+
+
+extern const char *screen_dump_name;
+
+
+void dump_screen_file(const char *name);
+void dump_screen(void);
+
+#endif /* !SCREEN_H */