# HG changeset patch # User Matti Hamalainen # Date 1363648805 -7200 # Node ID 03ef1b48e3807f203044a30611a9291cc9abd048 # Parent 3b0b5d73829e921cfde4a8ded578fb017680146f Cleanups. diff -r 3b0b5d73829e -r 03ef1b48e380 3x666.c --- a/3x666.c Tue Mar 19 01:17:54 2013 +0200 +++ b/3x666.c Tue Mar 19 01:20:05 2013 +0200 @@ -51,19 +51,8 @@ void setpal(void); -static inline int dmClamp(const int v, const int min, const int max) -{ - return (v < min ? min : (v > max ? max : v)); -} - -static int engineGetTick() -{ - return ((engine.frameTime - engine.startTime) * SET_DEMOHZ) / 1000; -} - - -void dmPrintVA(const char *fmt, va_list ap) +static void dmPrintVA(int level, const char *fmt, va_list ap) { #ifdef __WIN32 (void) fmt; @@ -74,7 +63,7 @@ } -void dmPrint(const char *fmt, ...) +static void dmPrint(int level, const char *fmt, ...) { #ifdef __WIN32 (void) fmt; @@ -82,12 +71,18 @@ va_list ap; va_start(ap, fmt); - dmPrintVA(fmt, ap); + dmPrintVA(level, fmt, ap); va_end(ap); #endif } +static inline int dmClamp(const int v, const int min, const int max) +{ + return (v < min ? min : (v > max ? max : v)); +} + + void dmErrorVA(const char *fmt, va_list ap) { fprintf(stderr, SET_PROG_NAME ": "); @@ -105,6 +100,12 @@ } +static int engineGetTick() +{ + return ((engine.frameTime - engine.startTime) * SET_DEMOHZ) / 1000; +} + + static BOOL engineInitializeVideo() { SDL_FreeSurface(engine.screen); @@ -451,7 +452,7 @@ int o = 0, oo = 0; float a = 0, da = 386 / (float) drumlgt, dda = da / (float) drumlgt; - dmPrint("aCtIvATiNg 303 eMuLAtOR\n"); + dmPrint(0, "aCtIvATiNg 303 eMuLAtOR\n"); for (i = drumlgt; i; i--) { @@ -585,11 +586,15 @@ static void engineAudioCallback(void *userdata, Uint8 *stream, int len) { (void) userdata; + // We inherently assume mono here, as the audio code is not // capable of producing stereo anyway (for now, at least.) int i, need = len / sizeof(Sint16); -#if 0 +// fprintf(stderr, "%p : %p @ %d -> %d\n", userdata, stream, len, need); +// fflush(stderr); + +#if 1 // The audio rendering handling is a bit silly due to the way // the original code works (assumes that it can always render // a certain amount/duration of data, instead of being given @@ -597,7 +602,7 @@ if (need >= engine.mixBufSize) need = engine.mixBufSize; - while (engine.mixFill < need && engine.mixFill < engine.mixBufSize) + while (engine.mixFill < need) { int got = engineRenderAudio(engine.mixBuf + engine.mixFill); engine.mixFill += got; @@ -934,7 +939,7 @@ memset(&engine, 0, sizeof(engine)); - dmPrint( + dmPrint(0, SET_PROG_NAME " by Ocsa (PWP) (c) 1998\n" "libSDL port by ccr/TNSP^PWP (c) 2013\n"); @@ -943,7 +948,7 @@ // Initialize SDL components - dmPrint("Engine initializing ..\n"); + dmPrint(0, "Engine initializing ..\n"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { dmError("Could not initialize SDL: %s\n", SDL_GetError()); @@ -1160,8 +1165,8 @@ error_exit: // Shutdown - dmPrint("Shutting down.\n"); - dmPrint("%d frames in %d ms, %1.2f fps\n", + dmPrint(0, "Shutting down.\n"); + dmPrint(1, "%d frames in %d ms, %1.2f fps\n", engine.frameCount, engine.frameTime - engine.startTime, (float) (engine.frameCount * 1000.0f) / (float) (engine.frameTime - engine.startTime)