#include <limits.h>
#include "vbe.h"
#include "dpmi.h"
-#include "logger.h"
#define REALPTR(s, o) (void*)(((uint32_t)(s) << 4) + (uint32_t)(o))
#define VBEPTR(x) REALPTR(((x) & 0xffff0000) >> 16, (x) & 0xffff)
return 0;
}
- printlog("VBE Version: %x.%x\n", vbe_info->version >> 8, vbe_info->version & 0xff);
+ printf("VBE Version: %x.%x\n", vbe_info->version >> 8, vbe_info->version & 0xff);
if(vbe_info->version < 0x200) {
fprintf(stderr, "This program requires VBE 2.0 or greater. Try running UniVBE\n");
return 0;
}
- printlog("Graphics adapter: %s, %s (%s)\n", VBEPTR(vbe_info->oem_vendor_name_ptr),
+ printf("Graphics adapter: %s, %s (%s)\n", VBEPTR(vbe_info->oem_vendor_name_ptr),
VBEPTR(vbe_info->oem_product_name_ptr), VBEPTR(vbe_info->oem_product_rev_ptr));
- printlog("Video memory: %dkb\n", vbe_info->total_mem << 6);
+ printf("Video memory: %dkb\n", vbe_info->total_mem << 6);
modes = VBEPTR(vbe_info->vid_mode_ptr);
}
/* attempt to set 8 bits of color per component in palettized modes */
/*if(bpp <= 8) {
pal_bits = vbe_set_palette_bits(8);
- printlog("palette bits per color primary: %d\n", pal_bits);
+ printf("palette bits per color primary: %d\n", pal_bits);
}
*/
-/*
-colcycle - color cycling image viewer
-Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
-
-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 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
#include <stdio.h>
-#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
#include "logger.h"
-#define LOGFNAME "demo.log"
-
-static FILE *logfile;
-
-void logger_output(FILE *fp)
+int init_logger(const char *fname)
{
- if(logfile) fclose(logfile);
- logfile = fp;
-}
-
-void printlog(const char *fmt, ...)
-{
- va_list ap;
-
- if(!logfile) {
- if(!(logfile = fopen(LOGFNAME, "w"))) {
- return;
- }
- setvbuf(logfile, 0, _IOLBF, 0);
+ int fd;
+ if((fd = open(fname, O_WRONLY)) == -1) {
+ fprintf(stderr, "init_logger: failed to open %s: %s\n", fname, strerror(errno));
+ return -1;
}
- va_start(ap, fmt);
- vfprintf(logfile, fmt, ap);
- va_end(ap);
+ close(1);
+ close(2);
+ dup(fd);
+ dup(fd);
+ return 0;
}
-/*
-colcycle - color cycling image viewer
-Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
-
-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 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
#ifndef LOGGER_H_
#define LOGGER_H_
-#include <stdio.h>
-
#ifdef __cplusplus
extern "C" {
#endif
-void logger_output(FILE *fp);
-void printlog(const char *fmt, ...);
+int init_logger(const char *fname);
#ifdef __cplusplus
}
#include "mouse.h"
#include "timer.h"
#include "gfx.h"
+#include "logger.h"
static int quit;
static int use_mouse;
{
fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT;
+ init_logger("demo.log");
+
init_timer(100);
kb_init(32);
#include <stdlib.h>
#include "music.h"
#include "mikmod.h"
-#include "logger.h"
static void update_callback(void);
MD_RegisterPlayer(update_callback);
if(!MD_Init()) {
- printlog("mikmod init failed: %s\n", myerr);
+ fprintf(stderr, "mikmod init failed: %s\n", myerr);
return -1;
}
- printlog("using mikmod driver %s\n", md_driver->Name);
- printlog(" %d bits, %s, %s mixing at %d Hz\n", md_mode & DMODE_16BITS ? 16 : 8,
+ printf("using mikmod driver %s\n", md_driver->Name);
+ printf(" %d bits, %s, %s mixing at %d Hz\n", md_mode & DMODE_16BITS ? 16 : 8,
md_mode & DMODE_STEREO ? "stereo" : "mono",
md_mode & DMODE_INTERP ? "interpolated" : "normal",
md_mixfreq);
}
if(!(mod = ML_LoadFN((const signed char*)fname))) {
- printlog("failed to load music: %s: %s\n", fname, myerr);
+ fprintf(stderr, "failed to load music: %s: %s\n", fname, myerr);
return -1;
}
MP_Init(mod);
md_numchn = mod->numchn;
- printlog("opened module %s (%d channels)\n", fname, md_numchn);
+ printf("opened module %s (%d channels)\n", fname, md_numchn);
return 0;
}
void music_close(void)
{
if(mod) {
- printlog("shutting down music playback\n");
+ printf("shutting down music playback\n");
music_stop();
ML_Free(mod);
mod = 0;