From: John Tsiombikas Date: Sat, 14 Dec 2019 05:51:54 +0000 (+0200) Subject: fixed the physical to virtual translation issues with DJGPP, watcom just X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=102f82ec5a8128cb076371aa3d9821e684b94380 fixed the physical to virtual translation issues with DJGPP, watcom just doesn't work at the moment, and seems like it hasn't worked for a while and went unnoticed? ... oh well --- diff --git a/Makefile.dj b/Makefile.dj index a687012..fe89fcf 100644 --- a/Makefile.dj +++ b/Makefile.dj @@ -12,7 +12,7 @@ else endif inc = -Isrc -Isrc/dos -Ilibs -Ilibs/imago/src -Ilibs/anim/src -Ilibs/mikmod/include -opt = -O3 -ffast-math -fno-strict-aliasing +#opt = -O3 -ffast-math -fno-strict-aliasing dbg = -g warn = -pedantic -Wall -Wno-unused-function -Wno-unused-variable diff --git a/src/dos/cdpmi.h b/src/dos/cdpmi.h index 92bc5b3..71138b6 100644 --- a/src/dos/cdpmi.h +++ b/src/dos/cdpmi.h @@ -3,7 +3,17 @@ #ifdef __DJGPP__ #include -#endif +#include + +#define virt_to_phys(v) ((v) + __djgpp_base_address) +#define phys_to_virt(p) ((p) - __djgpp_base_address) + +#else /* not djgpp (basically watcom) */ + +#define virt_to_phys(v) (v) +#define phys_to_virt(p) (p) + +#endif /* __DJGPP__ */ #include "inttypes.h" #include "util.h" diff --git a/src/dos/gfx.c b/src/dos/gfx.c index 8818ab9..bc763d3 100644 --- a/src/dos/gfx.c +++ b/src/dos/gfx.c @@ -1,16 +1,10 @@ #include +#include #include "gfx.h" #include "vbe.h" #include "vga.h" #include "cdpmi.h" -#ifdef __DJGPP__ -#include -#define REALPTR(s, o) (void*)(((uint32_t)(s) << 4) - __djgpp_base_address + ((uint32_t)(o))) -#else -#define REALPTR(s, o) (void*)(((uint32_t)(s) << 4) + ((uint32_t)(o))) -#endif - #define SAME_BPP(a, b) \ ((a) == (b) || ((a) == 16 && (b) == 15) || ((a) == 15 && (b) == 16) || \ ((a) == 32 && (b) == 24) || ((a) == 24 && (b) == 32)) diff --git a/src/dos/main.c b/src/dos/main.c index aed12e9..70ea449 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -15,6 +15,7 @@ #include "cfgopt.h" #include "logger.h" #include "tinyfps.h" +#include "cdpmi.h" #undef NOKEYB @@ -31,6 +32,10 @@ static quat_t rot = {0, 0, 0, 1}; int main(int argc, char **argv) { +#ifdef __DJGPP__ + __djgpp_nearptr_enable(); +#endif + fbsize = fb_width * fb_height * fb_bpp / 8; init_logger("demo.log"); diff --git a/src/dos/vbe.c b/src/dos/vbe.c index fd894fe..3ada182 100644 --- a/src/dos/vbe.c +++ b/src/dos/vbe.c @@ -16,7 +16,7 @@ } else { \ paddr = ((uint32_t)pseg << 4) + poffs; \ } \ - (ptr) = (void*)paddr; \ + (ptr) = (void*)phys_to_virt(paddr); \ } while(0) /* hijack the "VESA" sig field, to pre-cache number of modes */ @@ -40,7 +40,7 @@ int vbe_info(struct vbe_info *info) if(!(seg = dpmi_alloc(sizeof *info / 16, &sel))) { return -1; } - lowbuf = (void*)((uint32_t)seg << 4); + lowbuf = (void*)phys_to_virt((uint32_t)seg << 4); memcpy(lowbuf, "VBE2", 4); @@ -107,7 +107,7 @@ int vbe_mode_info(int mode, struct vbe_mode_info *minf) if(!(seg = dpmi_alloc(sizeof *minf / 16, &sel))) { return -1; } - lowbuf = (void*)((uint32_t)seg << 4); + lowbuf = (void*)phys_to_virt((uint32_t)seg << 4); regs.eax = 0x4f01; regs.ecx = mode; @@ -238,7 +238,7 @@ int vbe_setmode_crtc(uint16_t mode, struct vbe_crtc_info *crtc) if(!(seg = dpmi_alloc((sizeof *crtc + 15) / 16, &sel))) { return -1; } - lowbuf = (void*)((uint32_t)seg << 4); + lowbuf = (void*)phys_to_virt((uint32_t)seg << 4); memcpy(lowbuf, crtc, sizeof *crtc); @@ -293,7 +293,7 @@ int vbe_save(void *stbuf, int sz, unsigned int flags) if(!(seg = dpmi_alloc((sz + 15) / 16, &sel))) { return -1; } - lowbuf = (void*)((uint32_t)seg << 4); + lowbuf = (void*)phys_to_virt((uint32_t)seg << 4); regs.eax = 0x4f04; regs.edx = 1; /* save */ @@ -319,7 +319,7 @@ int vbe_restore(void *stbuf, int sz, unsigned int flags) if(!(seg = dpmi_alloc((sz + 15) / 16, &sel))) { return -1; } - lowbuf = (void*)((uint32_t)seg << 4); + lowbuf = (void*)phys_to_virt((uint32_t)seg << 4); memcpy(lowbuf, stbuf, sz);