# HG changeset patch # User Matti Hamalainen # Date 1363654051 -7200 # Node ID b4c72c135f5b618aafe81f320e868f7b5390d0c6 # Parent 62b5f87ebb2a785c218fed72534475ba336eac05 Add a dmlib-based recording patch for archival purposes. diff -r 62b5f87ebb2a -r b4c72c135f5b recording.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/recording.patch Tue Mar 19 02:47:31 2013 +0200 @@ -0,0 +1,192 @@ +diff -r 62b5f87ebb2a 3x666.c +--- a/3x666.c Tue Mar 19 02:46:34 2013 +0200 ++++ b/3x666.c Tue Mar 19 02:46:50 2013 +0200 +@@ -7,6 +7,19 @@ + #include "config.h" + #include "3xfont.h" + ++//#define RECORD 1 ++#define RECORD_FPS 50 ++#define RECORD_AUDIO_FILE "audio.wav" ++#define RECORD_VIDEO_FILE "%05d.png" ++ ++ ++#ifdef RECORD ++#include ++#include "dmlib.h" ++#include "dmwav.h" ++#include "libgfx.h" ++ ++#else + + #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) + typedef enum { FALSE = 0, TRUE = 1 } BOOL; +@@ -20,6 +33,8 @@ + # endif + #endif + ++#endif ++ + + struct + { +@@ -51,6 +66,7 @@ + void setpal(void); + + ++#ifndef RECORD + + static void dmPrintVA(int level, const char *fmt, va_list ap) + { +@@ -98,6 +114,7 @@ + dmErrorVA(fmt, ap); + va_end(ap); + } ++#endif + + + static int engineGetTick() +@@ -964,10 +981,12 @@ + engine.optAfmt.callback = engineAudioCallback; + + // Initialize SDL audio ++#ifndef RECORD + if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) + { + dmError("Couldn't open SDL audio: %s\n", SDL_GetError()); + } ++#endif + + // Initialize SDL video + if (!engineInitializeVideo()) +@@ -989,13 +1008,53 @@ + + // Start audio, enter main loop + dmPrint(0, "We are go.\n"); ++#ifdef RECORD ++ DMImage image; ++ DMImageSpec imageSpec = ++{ ++ .scale = 1, ++ .nplanes = 4, ++ .interleave = FALSE, ++ .paletted = FALSE, ++ .format = DM_IFMT_RGB, ++}; ++ int audioSize = 0, audioBufSize = sizeof(Sint16) * (engine.optAfmt.freq / RECORD_FPS) * engine.optAfmt.channels; ++ Uint8 *audioBuf = malloc(audioBufSize); ++ FILE *audioFile = NULL; ++ char videoFilename[64]; ++ engine.startTime = 0; ++ ++ image.width = engine.screen->w; ++ image.height = engine.screen->h; ++ image.pitch = engine.screen->pitch; ++ image.ncolors = 256; ++ image.constpal = TRUE; ++ image.pal = (DMColor *) engine.screen->format->palette->colors; ++ image.data = engine.screen->pixels; ++ ++ ++ // Open output file(s) ++ if ((audioFile = fopen(RECORD_AUDIO_FILE, "wb")) == NULL) ++ { ++ dmError("Error opening output file '%s'. (%s)\n", RECORD_AUDIO_FILE, strerror(errno)); ++ goto error_exit; ++ } ++ ++ // Write initial header ++ dmWriteWAVHeader(audioFile, 16, engine.optAfmt.freq, engine.optAfmt.channels, 1024); ++ ++#else + SDL_LockAudio(); + SDL_PauseAudio(0); + SDL_UnlockAudio(); + engine.startTime = SDL_GetTicks(); ++#endif + + while (!engine.exitFlag) + { ++#ifdef RECORD ++ engine.frameTime += 1000 / RECORD_FPS; ++#else + // Handle SDL events + while (SDL_PollEvent(&engine.event)) + switch (engine.event.type) +@@ -1036,8 +1095,9 @@ + break; + } + ++ engine.frameTime = SDL_GetTicks(); ++#endif + // Draw frame +- engine.frameTime = SDL_GetTicks(); + int qt = engineGetTick(&engine); + + if (SDL_MUSTLOCK(engine.screen) != 0 && SDL_LockSurface(engine.screen) != 0) +@@ -1154,13 +1214,25 @@ + n /= 10; + } + +- // Flip screen, increase frame count, wait ++#ifdef RECORD ++ // Dump frame to file ++ snprintf(videoFilename, sizeof(videoFilename), RECORD_VIDEO_FILE, engine.frameCount); ++ dmWritePNGImage(videoFilename, &image, &imageSpec); ++ ++ // Render audio to another ++ engineAudioCallback(NULL, audioBuf, audioBufSize); ++ audioSize += fwrite(audioBuf, sizeof(Uint8), audioBufSize, audioFile); ++#endif ++ + if (SDL_MUSTLOCK(engine.screen) != 0) + SDL_UnlockSurface(engine.screen); + ++ // Flip screen, increase frame count, wait + engine.frameCount++; + SDL_Flip(engine.screen); ++#ifndef RECORD + SDL_Delay(20); ++#endif + } + + error_exit: +@@ -1176,9 +1248,26 @@ + if (engine.screen) + SDL_FreeSurface(engine.screen); + ++#ifdef RECORD ++ if (audioFile != NULL) ++ { ++ // Write the correct WAV header ++ if (fseek(audioFile, 0L, SEEK_SET) != 0) ++ { ++ dmError("Error rewinding to header position!\n"); ++ return 9; ++ } ++ ++ dmWriteWAVHeader(audioFile, 16, engine.optAfmt.freq, engine.optAfmt.channels, audioSize / sizeof(Sint16)); ++ ++ // Done! ++ fclose(audioFile); ++ } ++#else + SDL_LockAudio(); + SDL_PauseAudio(1); + SDL_UnlockAudio(); ++#endif + + audio_close(); + +diff -r 62b5f87ebb2a Makefile.gen +--- a/Makefile.gen Tue Mar 19 02:46:34 2013 +0200 ++++ b/Makefile.gen Tue Mar 19 02:46:50 2013 +0200 +@@ -26,6 +26,8 @@ + $(OBJPATH)3x666.o: 3x666.c config.h 3xfont.h + $(CC) $(CFLAGS) -c -o $@ $< $(SDL_CFLAGS) -Idmlib/ + ++$(BINPATH)3x666$(EXEEXT): $(OBJPATH)3x666.o dmlib/unix/dmwav.o dmlib/unix/dmfile.o dmlib/unix/dmlib.o dmlib/unix/libgfx.o dmlib/unix/dmbstr.o ++ $(CC) -o $@ $+ $(LDFLAGS) $(SDL_LDFLAGS) -lpng + + + ###