correct window size in banked vbe, and added doublebuffered test master
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 26 Jun 2023 16:54:53 +0000 (19:54 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 26 Jun 2023 16:54:53 +0000 (19:54 +0300)
drv_vbe.c
main.c
vidsys.c
vidsys.h

index d639417..e09ca4d 100644 (file)
--- a/drv_vbe.c
+++ b/drv_vbe.c
@@ -356,14 +356,16 @@ static void blitfb_lfb(void *fb, int pitch)
 
 static void blitfb_banked(void *fb, int pitch)
 {
-       int sz, offs, pending;
+       int sz, offs, pending, winsz;
        unsigned char *pptr = fb;
 
+       winsz = cur_mi->win_size << 10;
+
        /* assume initial window offset at 0 */
        offs = 0;
        pending = cur_pgsize;
        while(pending > 0) {
-               sz = pending > 65536 ? 65536 : pending;
+               sz = pending > winsz ? winsz : pending;
                memcpy((void*)0xa0000, pptr, sz);
                pptr += sz;
                pending -= sz;
diff --git a/main.c b/main.c
index 476baa7..a087561 100644 (file)
--- a/main.c
+++ b/main.c
@@ -5,14 +5,17 @@
 #include "vidsys.h"
 
 void test8bpp(void);
+void testrgb(void);
 
 struct vid_modeinfo *vm;
-void *vmem;
+void *vmem, *framebuf;
+int doublebuf;
 
 static const char *usage_fmt = "Usage %s: [options]\n"
        "Options:      \n"
        " -s <XxY>: video resolution\n"
-       " -b <bpp>: color depth\n";
+       " -b <bpp>: color depth\n"
+       " -d: double buffer\n";
 
 int main(int argc, char **argv)
 {
@@ -41,6 +44,11 @@ invalopt:            fprintf(stderr, "invalid option: %s\n", argv[i]);
                                        fprintf(stderr, "invalid color depth: %s\n", argv[i]);
                                        return 1;
                                }
+                               break;
+
+                       case 'd':
+                               doublebuf = 1;
+                               break;
 
                        case 'h':
                                printf(usage_fmt, argv[0]);
@@ -67,19 +75,22 @@ invalopt:           fprintf(stderr, "invalid option: %s\n", argv[i]);
                fprintf(stderr, "failed to find video mode: %dx%d %dbpp\n", xres, yres, bpp);
                return 1;
        }
+       vm = vid_modeinfo(mode);
+
+       if(!(framebuf = malloc(vm->pitch * vm->width))) {
+               fprintf(stderr, "failed to allocate main memory framebuffer\n");
+               return 1;
+       }
+
        if(!(vmem = vid_setmode(mode))) {
                fprintf(stderr, "failed to set video mode %04x\n", mode);
                return 1;
        }
-       vm = vid_modeinfo(mode);
 
-       switch(vm->bpp) {
-       case 8:
+       if(vm->bpp == 8) {
                test8bpp();
-               break;
-
-       default:
-               break;
+       } else {
+               testrgb();
        }
 
        for(;;) {
@@ -119,27 +130,110 @@ void test8bpp(void)
        }
        vid_setpal(0, 256, cmap);
 
-       if(vid_islinear()) {
-               winsz = INT_MAX;
+       if(doublebuf) {
+               fb = framebuf;
+               for(i=0; i<vm->height; i++) {
+                       for(j=0; j<vm->width; j++) {
+                               *fb++ = i ^ j;
+                       }
+               }
+               vid_blitfb(framebuf, 0);
        } else {
-               winsz = 65536;
-               winpos = 0;
-               vid_setwin(0, 0);
+               if(vid_islinear()) {
+                       winsz = INT_MAX;
+               } else {
+                       winsz = vm->win_size << 10;
+                       winpos = 0;
+                       vid_setwin(0, 0);
+               }
+               winleft = winsz;
+               fb = vmem;
+
+               vid_vsync();
+
+               for(i=0; i<vm->height; i++) {
+                       for(j=0; j<vm->width; j++) {
+                               if(winleft-- <= 0) {
+                                       winpos += vm->win_step;
+                                       vid_setwin(0, winpos);
+                                       winleft = winsz;
+                                       fb = vmem;
+                               }
+                               *fb++ = i ^ j;
+                       }
+               }
        }
-       winleft = winsz;
-       fb = vmem;
+}
 
-       vid_vsync();
+void testrgb(void)
+{
+       int i, j, r, g, b;
+       unsigned char *fb24;
+       uint16_t *fb16;
+       uint32_t *fb32;
+       uint32_t pcol;
+       int winsz, winleft, winpos;
+
+       if(!doublebuf) {
+               if(vid_islinear()) {
+                       winsz = INT_MAX;
+               } else {
+                       winsz = vm->win_size << 10;
+                       winpos = 0;
+                       vid_setwin(0, 0);
+               }
+               winleft = winsz;
+               fb24 = vmem;
+               fb32 = vmem;
+               fb16 = vmem;
+
+               vid_vsync();
+       } else {
+               fb24 = framebuf;
+               fb32 = framebuf;
+               fb16 = framebuf;
+       }
 
        for(i=0; i<vm->height; i++) {
                for(j=0; j<vm->width; j++) {
-                       if(winleft-- <= 0) {
-                               winpos += vm->win_step;
-                               vid_setwin(0, winpos);
-                               winleft = winsz;
-                               fb = vmem;
+                       if(!doublebuf) {
+                               if(winleft <= 0) {
+                                       winpos += vm->win_step;
+                                       vid_setwin(0, winpos);
+                                       winleft = winsz;
+                                       fb24 = vmem;
+                                       fb16 = vmem;
+                                       fb32 = vmem;
+                               }
+                               winleft -= (vm->bpp + 7) >> 3;
+                       }
+                       r = (i ^ j) >> 1;
+                       g = i ^ j;
+                       b = (i ^ j) << 1;
+                       vm->ops.pack(&pcol, r, g, b);
+
+                       switch(vm->bpp) {
+                       case 15:
+                       case 16:
+                               *fb16++ = pcol;
+                               break;
+
+                       case 24:
+                               fb24[0] = r;
+                               fb24[1] = g;
+                               fb24[2] = b;
+                               fb24 += 3;
+                               break;
+
+                       case 32:
+                               *fb32++ = pcol;
+                               break;
                        }
-                       *fb++ = i ^ j;
                }
        }
+
+       if(doublebuf) {
+               vid_vsync();
+               vid_blitfb(framebuf, 0);
+       }
 }
index 427dbb5..3a88f9c 100644 (file)
--- a/vidsys.c
+++ b/vidsys.c
@@ -195,7 +195,10 @@ void vid_getpal(int idx, int count, struct vid_color *col)
        cur_mode->ops.getpal(idx, count, col);
 }
 
-void vid_blitfb(void *fb, int vsync)
+void vid_blitfb(void *fb, int pitch)
 {
-       cur_mode->ops.blitfb(fb, vsync);
+       if(pitch <= 0) {
+               pitch = cur_mode->pitch;
+       }
+       cur_mode->ops.blitfb(fb, pitch);
 }
index cd2cfec..f019cac 100644 (file)
--- a/vidsys.h
+++ b/vidsys.h
@@ -72,6 +72,6 @@ int vid_isbanked(void);
 void vid_setpal(int idx, int count, const struct vid_color *col);
 void vid_getpal(int idx, int count, struct vid_color *col);
 
-void vid_blitfb(void *fb, int vsync);
+void vid_blitfb(void *fb, int pitch);
 
 #endif /* VIDSYS_VIDEO_H_ */