forgot about the non-zero base of the conventional memory selector in CWSDPMI...
[retrobench] / src / dos / gfx.c
index f7276af..ef05921 100644 (file)
@@ -7,6 +7,11 @@
 #include "vga.h"
 #include "util.h"
 
+#ifdef __DJGPP__
+#define VMEM_PTR       ((void*)(0xa0000 + __djgpp_conventional_base))
+#else
+#define VMEM_PTR       ((void*)0xa0000)
+#endif
 
 #define SAME_BPP(a, b) \
        ((a) == (b) || ((a) == 16 && (b) == 15) || ((a) == 15 && (b) == 16) || \
@@ -110,7 +115,6 @@ int init_video(void)
 void cleanup_video(void)
 {
        free(vmodes);
-       vmodes = 0;
 }
 
 struct video_mode *video_modes(void)
@@ -187,7 +191,7 @@ void *set_video_mode(int idx, int nbuf)
        }
 
        /* unmap previous video memory mapping, if there was one (switching modes) */
-       if(vpgaddr[0] && vpgaddr[0] != (void*)0xa0000) {
+       if(vpgaddr[0] && vpgaddr[0] != VMEM_PTR) {
                dpmi_munmap(vpgaddr[0]);
                vpgaddr[0] = vpgaddr[1] = 0;
        }
@@ -230,7 +234,7 @@ void *set_video_mode(int idx, int nbuf)
                }
 
        } else {
-               vpgaddr[0] = (void*)0xa0000;
+               vpgaddr[0] = VMEM_PTR;
                vpgaddr[1] = 0;
 
                blit_frame = blit_frame_banked;
@@ -247,7 +251,7 @@ 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);
+               printf("granularity: %dk (step: %d)\n", vm->win_gran, vm->win_64k_step);
        }
 
        /* allocate main memory framebuffer */
@@ -265,7 +269,7 @@ void *set_video_mode(int idx, int nbuf)
 int set_text_mode(void)
 {
        /* unmap previous video memory mapping, if there was one (switching modes) */
-       if(vpgaddr[0] && vpgaddr[0] != (void*)0xa0000) {
+       if(vpgaddr[0] && vpgaddr[0] != VMEM_PTR) {
                dpmi_munmap(vpgaddr[0]);
                vpgaddr[0] = vpgaddr[1] = 0;
        }
@@ -298,8 +302,7 @@ static void blit_frame_lfb(void *pixels, int vsync)
 
 static void blit_frame_banked(void *pixels, int vsync)
 {
-       int offs;
-       unsigned int pending;
+       int sz, offs, pending;
        unsigned char *pptr = pixels;
 
        if(vsync) wait_vsync();
@@ -308,10 +311,11 @@ static void blit_frame_banked(void *pixels, int vsync)
        offs = 0;
        pending = pgsize;
        while(pending > 0) {
-               //memcpy64((void*)0xa0000, pptr, 16384);
-               memcpy((void*)0xa0000, pptr, 65536);
-               pptr += 65536;
-               pending -= 65536;
+               sz = pending > 65536 ? 65536 : pending;
+               /*memcpy64(VMEM_PTR, pptr, sz >> 3);*/
+               memcpy(VMEM_PTR, pptr, sz);
+               pptr += sz;
+               pending -= sz;
                offs += curmode->win_64k_step;
                vbe_setwin(0, offs);
        }