From 8b08e899b6ffcfd2d1b31790de5b3a4412cde64c Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 20 Jun 2023 18:29:18 +0300 Subject: [PATCH] fixed logging and more --- .gitignore | 4 +++ src/app.c | 4 +-- src/cpuid.c | 17 +++++---- src/dos/gfx.c | 67 ++++++++++++++++-------------------- src/dos/vbe.c | 106 ++++++++++++++++++++++++++++----------------------------- src/logger.c | 24 ++----------- src/options.c | 3 +- src/scr_mod.c | 4 +++ src/texture.c | 2 +- 9 files changed, 108 insertions(+), 123 deletions(-) diff --git a/.gitignore b/.gitignore index be7677e..9158346 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.LIB retroray *.cfg +*.conf data/ *.exe config.mk @@ -21,3 +22,6 @@ config.mk *.LNK *.map *.MAP +*.LOG +*.zip +core diff --git a/src/app.c b/src/app.c index 87f3a10..25baebb 100644 --- a/src/app.c +++ b/src/app.c @@ -67,7 +67,7 @@ int app_init(void) static rtk_draw_ops guigfx = {gui_fill, gui_blit, gui_drawtext, gui_textrect}; #if !defined(NDEBUG) && defined(DBG_FPEXCEPT) - printf("floating point exceptions enabled\n"); + infomsg("floating point exceptions enabled\n"); enable_fpexcept(); #endif @@ -164,7 +164,7 @@ void app_reshape(int x, int y) int numpix = x * y; int prev_numpix = win_width * win_height; - printf("reshape(%d, %d)\n", x, y); + dbgmsg("reshape(%d, %d)\n", x, y); if(!framebuf || numpix > prev_numpix) { void *tmp; diff --git a/src/cpuid.c b/src/cpuid.c index 9f1693d..798fce5 100644 --- a/src/cpuid.c +++ b/src/cpuid.c @@ -1,6 +1,7 @@ #include #include #include "cpuid.h" +#include "logger.h" static const char *cpuname(struct cpuid_info *cpu); static const char *cpuvendor(struct cpuid_info *cpu); @@ -21,30 +22,32 @@ void print_cpuid(struct cpuid_info *cpu) "?", "pcid", "dca", "sse41", "sse42", "x2apic", "movbe", "popcnt", "?", "aes", "xsave", "osxsave", "avx", "f16c", "rdrand", "?"}; - printf("CPU: %s - %s\n", cpuvendor(cpu), cpuname(cpu)); - printf("features:\n "); + infomsg("CPU: %s - %s\n", cpuvendor(cpu), cpuname(cpu)); + infomsg("features:\n "); col = 3; for(i=0; i<32; i++) { if(cpu->feat & (1 << i)) { len = strlen(featstr[i]) + 1; if(col + len >= 80) { - fputs("\n ", stdout); + infomsg("\n "); col = 3; } - col += printf(" %s", featstr[i]); + infomsg(" %s", featstr[i]); + col += strlen(featstr[i]) + 1; } } for(i=0; i<32; i++) { if(cpu->feat2 & (1 << i)) { len = strlen(feat2str[i]) + 1; if(col + len >= 80) { - fputs("\n ", stdout); + infomsg("\n "); col = 3; } - col += printf(" %s", feat2str[i]); + infomsg(" %s", feat2str[i]); + col += strlen(feat2str[i]) + 1; } } - putchar('\n'); + infomsg("\n"); } static const char *fam4_models[16] = { diff --git a/src/dos/gfx.c b/src/dos/gfx.c index 90085ec..ed171e8 100644 --- a/src/dos/gfx.c +++ b/src/dos/gfx.c @@ -9,6 +9,7 @@ #include "vga.h" #include "util.h" #include "cpuid.h" +#include "logger.h" #ifdef __DJGPP__ #define VMEM_PTR ((void*)(0xa0000 + __djgpp_conventional_base)) @@ -49,7 +50,7 @@ int init_video(void) struct video_mode *vmptr; if(vbe_info(&vbe) == -1) { - fprintf(stderr, "failed to retrieve VBE information\n"); + errormsg("failed to retrieve VBE information\n"); return -1; } vbe_print_info(stdout, &vbe); @@ -57,7 +58,7 @@ int init_video(void) num_vmodes = 0; max_modes = 64; if(!(vmodes = malloc(max_modes * sizeof *vmodes))) { - fprintf(stderr, "failed to allocate video modes list\n"); + errormsg("failed to allocate video modes list\n"); return -1; } @@ -72,7 +73,7 @@ int init_video(void) if(num_vmodes >= max_modes) { int newmax = max_modes ? (max_modes << 1) : 16; if(!(vmptr = realloc(vmodes, newmax * sizeof *vmodes))) { - fprintf(stderr, "failed to grow video mode list (%d)\n", newmax); + errormsg("failed to grow video mode list (%d)\n", newmax); free(vmodes); return -1; } @@ -105,10 +106,10 @@ int init_video(void) vmptr->max_pages = minf.num_img_pages; vmptr->win_gran = minf.win_gran; - printf("%04x: ", vbe.modes[i]); + infomsg("%04x: ", vbe.modes[i]); vbe_print_mode_info(stdout, &minf); } - fflush(stdout); + /*fflush(stdout);*/ vbe_init_ver = VBE_VER_MAJOR(vbe.ver); return 0; @@ -152,7 +153,7 @@ int match_video_mode(int xsz, int ysz, int bpp) } if(best == -1) { - fprintf(stderr, "failed to find video mode %dx%d %d bpp)\n", xsz, ysz, bpp); + errormsg("failed to find video mode %dx%d %d bpp)\n", xsz, ysz, bpp); return -1; } return best; @@ -177,18 +178,18 @@ void *set_video_mode(int idx, int nbuf) if(curmode == vm) return vpgaddr[0]; - printf("setting video mode %x (%dx%d %d bpp)\n", (unsigned int)vm->mode, + infomsg("setting video mode %x (%dx%d %d bpp)\n", (unsigned int)vm->mode, vm->xsz, vm->ysz, vm->bpp); - fflush(stdout); + /*fflush(stdout);*/ mode = vm->mode | VBE_MODE_LFB; if(vbe_setmode(mode) == -1) { + infomsg("Warning: failed to get a linear framebuffer. falling back to banked mode\n"); mode = vm->mode; if(vbe_setmode(mode) == -1) { - fprintf(stderr, "failed to set video mode %x\n", (unsigned int)vm->mode); + errormsg("failed to set video mode %x\n", (unsigned int)vm->mode); return 0; } - printf("Warning: failed to get a linear framebuffer. falling back to banked mode\n"); } /* unmap previous video memory mapping, if there was one (switching modes) */ @@ -205,20 +206,20 @@ void *set_video_mode(int idx, int nbuf) fbsize = pgcount * pgsize; if(vm->bpp > 8) { - printf("rgb mask: %x %x %x\n", (unsigned int)vm->rmask, + infomsg("rgb mask: %x %x %x\n", (unsigned int)vm->rmask, (unsigned int)vm->gmask, (unsigned int)vm->bmask); - printf("rgb shift: %d %d %d\n", vm->rshift, vm->gshift, vm->bshift); + infomsg("rgb shift: %d %d %d\n", vm->rshift, vm->gshift, vm->bshift); } - printf("pgcount: %d, pgsize: %d, fbsize: %d\n", pgcount, pgsize, fbsize); + infomsg("pgcount: %d, pgsize: %d, fbsize: %d\n", pgcount, pgsize, fbsize); if(vm->fb_addr) { - printf("phys addr: %p\n", (void*)vm->fb_addr); + infomsg("phys addr: %p\n", (void*)vm->fb_addr); } - fflush(stdout); + /*fflush(stdout);*/ if(vm->fb_addr) { vpgaddr[0] = (void*)dpmi_mmap(vm->fb_addr, fbsize); if(!vpgaddr[0]) { - fprintf(stderr, "failed to map framebuffer (phys: %lx, size: %d)\n", + errormsg("failed to map framebuffer (phys: %lx, size: %d)\n", (unsigned long)vm->fb_addr, fbsize); set_text_mode(); return 0; @@ -242,7 +243,7 @@ void *set_video_mode(int idx, int nbuf) if(CPU_HAVE_MTRR) { int cpl = get_cpl(); if(cpl > 0) { - fprintf(stderr, "Can't set framebuffer range to write-combining, running in ring %d\n", cpl); + errormsg("Can't set framebuffer range to write-combining, running in ring %d\n", cpl); } else { uint32_t len = (uint32_t)vbe.vmem_blk << 16; @@ -251,7 +252,7 @@ void *set_video_mode(int idx, int nbuf) * mtrr */ if(!len || len > 0x10000000) { - printf("reported vmem too large or overflowed, using fbsize for wrcomb setup\n"); + infomsg("reported vmem too large or overflowed, using fbsize for wrcomb setup\n"); len = fbsize; } print_mtrr(); @@ -277,20 +278,10 @@ void *set_video_mode(int idx, int nbuf) vm->win_64k_step = 1 << vm->win_gran_shift; } - printf("granularity: %dk (step: %d)\n", vm->win_gran, vm->win_64k_step); + infomsg("granularity: %dk (step: %d)\n", vm->win_gran, vm->win_64k_step); } - /* allocate main memory framebuffer */ - /* - if(demo_resizefb(vm->xsz, vm->ysz, vm->bpp) == -1) { - fprintf(stderr, "failed to allocate %dx%d (%d bpp) framebuffer\n", vm->xsz, - vm->ysz, vm->bpp); - set_text_mode(); - return 0; - } - */ - - fflush(stdout); + /*fflush(stdout);*/ return vpgaddr[0]; } @@ -426,7 +417,7 @@ static void enable_wrcomb(uint32_t addr, int len) uint32_t def, mask; if(len <= 0 || (addr | (uint32_t)len) & 0xfff) { - fprintf(stderr, "failed to enable write combining, unaligned range: %p/%x\n", + errormsg("failed to enable write combining, unaligned range: %p/%x\n", (void*)addr, (unsigned int)len); return; } @@ -434,10 +425,10 @@ static void enable_wrcomb(uint32_t addr, int len) get_msr(MSR_MTRRCAP, &rlow, &rhigh); num_ranges = rlow & 0xff; - printf("enable_wrcomb: addr=%p len=%x\n", (void*)addr, (unsigned int)len); + infomsg("enable_wrcomb: addr=%p len=%x\n", (void*)addr, (unsigned int)len); if(!(rlow & MTRRCAP_HAVE_WC)) { - fprintf(stderr, "failed to enable write combining, processor doesn't support it\n"); + errormsg("failed to enable write combining, processor doesn't support it\n"); return; } @@ -446,7 +437,7 @@ static void enable_wrcomb(uint32_t addr, int len) } if((mtrr = alloc_mtrr(num_ranges)) == -1) { - fprintf(stderr, "failed to enable write combining, no free MTRRs\n"); + errormsg("failed to enable write combining, no free MTRRs\n"); return; } @@ -458,7 +449,7 @@ static void enable_wrcomb(uint32_t addr, int len) mask |= mask >> 16; mask = ~mask & 0xfffff000; - printf(" ... mask: %08x\n", (unsigned int)mask); + infomsg(" ... mask: %08x\n", (unsigned int)mask); _disable(); get_msr(MSR_MTRRDEFTYPE, &def, &rhigh); @@ -494,12 +485,12 @@ static void print_mtrr(void) get_msr(MSR_MTRRMASK(i), &mask, &rhigh); if(mask & MTRRMASK_VALID) { - printf("mtrr%d: base %p, mask %08x type %s\n", i, (void*)(base & 0xfffff000), + infomsg("mtrr%d: base %p, mask %08x type %s\n", i, (void*)(base & 0xfffff000), (unsigned int)(mask & 0xfffff000), mtrr_type_name(base & 0xff)); } else { - printf("mtrr%d unused (%08x/%08x)\n", i, (unsigned int)base, + infomsg("mtrr%d unused (%08x/%08x)\n", i, (unsigned int)base, (unsigned int)mask); } } - fflush(stdout); + /*fflush(stdout);*/ } diff --git a/src/dos/vbe.c b/src/dos/vbe.c index cb37ca1..021a40f 100644 --- a/src/dos/vbe.c +++ b/src/dos/vbe.c @@ -4,6 +4,7 @@ #include #include "vbe.h" #include "cdpmi.h" +#include "logger.h" #define FIXPTR(ptr) \ @@ -26,7 +27,6 @@ static int cur_pitch; /* TODO update cur_pitch on mode-change and on setscanlen */ - int vbe_info(struct vbe_info *info) { void *lowbuf; @@ -50,7 +50,7 @@ int vbe_info(struct vbe_info *info) dpmi_int(0x10, ®s); if((regs.eax & 0xffff) != 0x4f) { - fprintf(stderr, "vbe_get_info (4f00) failed\n"); + errormsg("vbe_get_info (4f00) failed\n"); dpmi_free(sel); return -1; } @@ -130,7 +130,7 @@ int vbe_mode_info(int mode, struct vbe_mode_info *minf) dpmi_int(0x10, ®s); if((regs.eax & 0xffff) != 0x4f) { - fprintf(stderr, "vbe_mode_info (4f01) failed\n"); + errormsg("vbe_mode_info (4f01) failed\n"); dpmi_free(sel); return -1; } @@ -142,90 +142,90 @@ int vbe_mode_info(int mode, struct vbe_mode_info *minf) void vbe_print_info(FILE *fp, struct vbe_info *vinf) { - fprintf(fp, "vbe version: %u.%u\n", VBE_VER_MAJOR(vinf->ver), VBE_VER_MINOR(vinf->ver)); + infomsg("vbe version: %u.%u\n", VBE_VER_MAJOR(vinf->ver), VBE_VER_MINOR(vinf->ver)); if(VBE_VER_MAJOR(vinf->ver) >= 2) { - fprintf(fp, "%s - %s (%s)\n", vinf->vendor, vinf->product, vinf->revstr); + infomsg("%s - %s (%s)\n", vinf->vendor, vinf->product, vinf->revstr); if(vinf->caps & VBE_ACCEL) { - fprintf(fp, "vbe/af %d.%d\n", VBE_VER_MAJOR(vinf->accel_ver), VBE_VER_MINOR(vinf->accel_ver)); + infomsg("vbe/af %d.%d\n", VBE_VER_MAJOR(vinf->accel_ver), VBE_VER_MINOR(vinf->accel_ver)); } } else { - fprintf(fp, "oem: %s\n", vinf->oem_name); + infomsg("oem: %s\n", vinf->oem_name); } - fprintf(fp, "video memory: %dkb\n", vinf->vmem_blk * 64); + infomsg("video memory: %dkb\n", vinf->vmem_blk * 64); if(vinf->caps) { - fprintf(fp, "caps:"); - if(vinf->caps & VBE_8BIT_DAC) fprintf(fp, " dac8"); - if(vinf->caps & VBE_NON_VGA) fprintf(fp, " non-vga"); - if(vinf->caps & VBE_DAC_BLANK) fprintf(fp, " dac-blank"); - if(vinf->caps & VBE_ACCEL) fprintf(fp, " af"); - if(vinf->caps & VBE_MUSTLOCK) fprintf(fp, " af-lock"); - if(vinf->caps & VBE_HWCURSOR) fprintf(fp, " af-curs"); - if(vinf->caps & VBE_HWCLIP) fprintf(fp, " af-clip"); - if(vinf->caps & VBE_TRANSP_BLT) fprintf(fp, " af-tblt"); - fprintf(fp, "\n"); - } - - fprintf(fp, "%d video modes available\n", NMODES(vinf)); + infomsg("caps:"); + if(vinf->caps & VBE_8BIT_DAC) infomsg(" dac8"); + if(vinf->caps & VBE_NON_VGA) infomsg(" non-vga"); + if(vinf->caps & VBE_DAC_BLANK) infomsg(" dac-blank"); + if(vinf->caps & VBE_ACCEL) infomsg(" af"); + if(vinf->caps & VBE_MUSTLOCK) infomsg(" af-lock"); + if(vinf->caps & VBE_HWCURSOR) infomsg(" af-curs"); + if(vinf->caps & VBE_HWCLIP) infomsg(" af-clip"); + if(vinf->caps & VBE_TRANSP_BLT) infomsg(" af-tblt"); + infomsg("\n"); + } + + infomsg("%d video modes available\n", NMODES(vinf)); if(vinf->caps & VBE_ACCEL) { - fprintf(fp, "%d accelerated (VBE/AF) modes available\n", NACCMODES(vinf)); + infomsg("%d accelerated (VBE/AF) modes available\n", NACCMODES(vinf)); } - fflush(fp); + /*fflush(fp);*/ } void vbe_print_mode_info(FILE *fp, struct vbe_mode_info *minf) { - fprintf(fp, "%dx%d %dbpp", minf->xres, minf->yres, minf->bpp); + infomsg("%dx%d %dbpp", minf->xres, minf->yres, minf->bpp); switch(minf->mem_model) { case VBE_TYPE_DIRECT: - fprintf(fp, " (rgb"); + infomsg(" (rgb"); if(0) { case VBE_TYPE_YUV: - fprintf(fp, " (yuv"); + infomsg(" (yuv"); } - fprintf(fp, " %d%d%d)", minf->rsize, minf->gsize, minf->bsize); + infomsg(" %d%d%d)", minf->rsize, minf->gsize, minf->bsize); break; case VBE_TYPE_PLANAR: - fprintf(fp, " (%d planes)", minf->num_planes); + infomsg(" (%d planes)", minf->num_planes); break; case VBE_TYPE_PACKED: - fprintf(fp, " (packed)"); + infomsg(" (packed)"); break; case VBE_TYPE_TEXT: - fprintf(fp, " (%dx%d cells)", minf->xcharsz, minf->ycharsz); + infomsg(" (%dx%d cells)", minf->xcharsz, minf->ycharsz); break; case VBE_TYPE_CGA: - fprintf(fp, " (CGA)"); + infomsg(" (CGA)"); break; case VBE_TYPE_UNCHAIN: - fprintf(fp, " (unchained-%d)", minf->num_planes); + infomsg(" (unchained-%d)", minf->num_planes); break; } - fprintf(fp, " %dpg", minf->num_img_pages); + infomsg(" %dpg", minf->num_img_pages); if(minf->attr & VBE_ATTR_LFB) { - fprintf(fp, " lfb@%lx", (unsigned long)minf->fb_addr); + infomsg(" lfb@%lx", (unsigned long)minf->fb_addr); } else { - fprintf(fp, " (%dk gran)", (int)minf->win_gran); - } - - fprintf(fp, " ["); - if(minf->attr & VBE_ATTR_AVAIL) fprintf(fp, " avail"); - if(minf->attr & VBE_ATTR_OPTINFO) fprintf(fp, " opt"); - if(minf->attr & VBE_ATTR_TTY) fprintf(fp, " tty"); - if(minf->attr & VBE_ATTR_COLOR) fprintf(fp, " color"); - if(minf->attr & VBE_ATTR_GFX) fprintf(fp, " gfx"); - if(minf->attr & VBE_ATTR_NOTVGA) fprintf(fp, " non-vga"); - if(minf->attr & VBE_ATTR_BANKED) fprintf(fp, " banked"); - if(minf->attr & VBE_ATTR_LFB) fprintf(fp, " lfb"); - if(minf->attr & VBE_ATTR_DBLSCAN) fprintf(fp, " dblscan"); - if(minf->attr & VBE_ATTR_ILACE) fprintf(fp, " ilace"); - if(minf->attr & VBE_ATTR_TRIPLEBUF) fprintf(fp, " trplbuf"); - if(minf->attr & VBE_ATTR_STEREO) fprintf(fp, " stereo"); - if(minf->attr & VBE_ATTR_STEREO_2FB) fprintf(fp, " stdual"); - fprintf(fp, " ]\n"); - fflush(fp); + infomsg(" (%dk gran)", (int)minf->win_gran); + } + + infomsg(" ["); + if(minf->attr & VBE_ATTR_AVAIL) infomsg(" avail"); + if(minf->attr & VBE_ATTR_OPTINFO) infomsg(" opt"); + if(minf->attr & VBE_ATTR_TTY) infomsg(" tty"); + if(minf->attr & VBE_ATTR_COLOR) infomsg(" color"); + if(minf->attr & VBE_ATTR_GFX) infomsg(" gfx"); + if(minf->attr & VBE_ATTR_NOTVGA) infomsg(" non-vga"); + if(minf->attr & VBE_ATTR_BANKED) infomsg(" banked"); + if(minf->attr & VBE_ATTR_LFB) infomsg(" lfb"); + if(minf->attr & VBE_ATTR_DBLSCAN) infomsg(" dblscan"); + if(minf->attr & VBE_ATTR_ILACE) infomsg(" ilace"); + if(minf->attr & VBE_ATTR_TRIPLEBUF) infomsg(" trplbuf"); + if(minf->attr & VBE_ATTR_STEREO) infomsg(" stereo"); + if(minf->attr & VBE_ATTR_STEREO_2FB) infomsg(" stdual"); + infomsg(" ]\n"); + /*fflush(fp);*/ } int vbe_setmode(uint16_t mode) diff --git a/src/logger.c b/src/logger.c index 68178d3..dd52cc6 100644 --- a/src/logger.c +++ b/src/logger.c @@ -155,28 +155,10 @@ int add_log_callback(void (*cbfunc)(const char*, void*), void *cls) static void logmsg(int type, const char *fmt, va_list ap) { - static char *buf; - static int bufsz; - int i, ret, newsz; - char *tmp; - - while((ret = vsnprintf(buf, bufsz, fmt, ap)) > bufsz || ret < 0) { - if(ret > bufsz) { - newsz = ret + 1; - } else { - newsz = bufsz ? bufsz * 2 : 256; - } - if(!(tmp = realloc(buf, newsz))) { - if(buf) { - buf[bufsz - 1] = 0; - } - break; - } - buf = tmp; - bufsz = newsz; - } + static char buf[2048]; + int i; - if(!buf) return; + vsnprintf(buf, sizeof buf, fmt, ap); for(i=0; i. #include #include "options.h" #include "treestor.h" +#include "logger.h" #define DEF_XRES 640 #define DEF_YRES 480 @@ -43,7 +44,7 @@ int load_options(const char *fname) if(!(cfg = ts_load(fname))) { return -1; } - printf("loaded config: %s\n", fname); + infomsg("loaded config: %s\n", fname); opt.xres = ts_lookup_int(cfg, "options.video.xres", DEF_XRES); opt.yres = ts_lookup_int(cfg, "options.video.yres", DEF_YRES); diff --git a/src/scr_mod.c b/src/scr_mod.c index d3cbb40..0dee3a1 100644 --- a/src/scr_mod.c +++ b/src/scr_mod.c @@ -350,6 +350,10 @@ static void mdl_keyb(int key, int press) act_settool(TOOL_SCALE); break; + case KEY_F6: + act_settool(TOOL_REND_AREA); + break; + case KEY_DEL: act_rmobj(); break; diff --git a/src/texture.c b/src/texture.c index 93d4b2f..87ec0a0 100644 --- a/src/texture.c +++ b/src/texture.c @@ -29,7 +29,7 @@ static cgm_vec3 lookup_fbm3d(const struct texture *btex, const struct rayhit *hi static cgm_vec3 lookup_marble2d(const struct texture *btex, const struct rayhit *hit); static cgm_vec3 lookup_marble3d(const struct texture *btex, const struct rayhit *hit); -static const cgm_vec3 (*lookup[])(const struct texture*, const struct rayhit*) = { +static cgm_vec3 (*lookup[])(const struct texture*, const struct rayhit*) = { lookup_pixmap, lookup_chess, lookup_fbm2d, -- 1.7.10.4