Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / universesim / src / video.c
diff --git a/research/transmission_spectroscopy/universesim/src/video.c b/research/transmission_spectroscopy/universesim/src/video.c
new file mode 100644 (file)
index 0000000..ceafc82
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ */
+#include <video.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <zlib.h>
+
+#define DUMP_FRAMES    0
+
+#define USE_SDL        1
+#define USE_ACESS      0
+
+#if USE_SDL
+# include <SDL/SDL.h>
+
+// === GLOBALS ===
+ int   giFrameNum = 0;
+#if DUMP_FRAMES
+gzFile *gVideoFile = NULL;
+#endif
+SDL_Surface    *gScreen;
+
+// === CODE ===
+void Video_SetResolution(int Width, int Height)
+{
+       if(!gScreen) {
+               SDL_Init(SDL_INIT_VIDEO);
+               atexit(SDL_Quit);
+       }
+       else {
+               SDL_FreeSurface(gScreen);
+       }
+       
+       gScreen = SDL_SetVideoMode(Width, Height, 32, SDL_DOUBLEBUF);
+       
+       #if DUMP_FRAMES
+       if(gVideoFile)  gzclose(gVideoFile);
+       
+       gVideoFile = gzopen("universe.mv", "wb");
+       gzwrite(gVideoFile, &gScreen->pitch, 2);
+       gzwrite(gVideoFile, &gScreen->h, 2);
+       #endif
+}
+
+void Video_SetName(const char *Format, ...)
+{
+       char    buf[1024];
+       va_list args;
+       va_start(args, Format);
+       vsprintf(buf, Format, args);
+       SDL_WM_SetCaption(buf, "Universe Simulator");
+       va_end(args);
+}
+
+void Video_PSet(int X, int Y, uint8_t R, uint8_t G, uint8_t B)
+{
+       uint8_t *buf = gScreen->pixels;
+       
+       buf[Y*gScreen->pitch + X*4] = B;
+       buf[Y*gScreen->pitch + X*4+1] = G;
+       buf[Y*gScreen->pitch + X*4+2] = R;
+       buf[Y*gScreen->pitch + X*4+3] = 0;
+}
+
+void Video_Flip(void)
+{
+       #if DUMP_FRAMES
+       gzwrite(gVideoFile, gScreen->pixels, gScreen->pitch*gScreen->h);
+       #endif
+       
+       SDL_Flip(gScreen);
+}
+
+void *Thread_Create(void *Function, void *Argument)
+{
+       return SDL_CreateThread(Function, Argument);
+}
+
+void Thread_Yield(void)
+{
+       SDL_Delay(0);
+}
+       
+
+#elif USE_ACESS
+# error "TODO - Acess FB Output"
+#endif

UCC git Repository :: git.ucc.asn.au