FBSCALE in SDL backend
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 27 Aug 2016 03:03:21 +0000 (06:03 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sat, 27 Aug 2016 03:03:21 +0000 (06:03 +0300)
README.md [new file with mode: 0644]
README.txt [deleted file]
src/demo.c
src/demo.h
src/sdl/main.c

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..4804bd7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,35 @@
+Building and running on DOS
+---------------------------
+Make sure you have Watcom or OpenWatcom installed, and the appropriate env-vars
+set (the watcom installer automatically adds them to autoexec.bat by default).
+
+Run wmake to build. Needs dos4gw.exe in current dir.
+
+The demo requires VESA Bios Extensions (VBE) 2.0. If your graphics card doesn't
+support VBE 2.0 or greater, then make sure to run the `univbe` TSR first, or
+the demo will fail to find a usable LFB video mode.
+
+
+Cross-compile on GNU/Linux
+--------------------------
+source owdev script with contents (change WATCOM var as necessary):
+
+  export WATCOM=$HOME/devel/ow
+  export PATH=$WATCOM/binl:$PATH
+  export INCLUDE=$WATCOM/h:$INCLUDE
+
+Run wmake to build. Needs dos4gw.exe and wstub.exe in current dir or PATH
+
+Simply running ./demo.exe might invoke magic of the ancients to start wine,
+which will in turn start dosbox, which will execute the DOS binary! If the gods
+are slumbering in valhalla, just typing `dosbox demo.exe` should do the trick.
+
+
+SDL backend
+-----------
+Run make to build (assuming make on your system is GNU make).
+
+The SDL backend will scale the framebuffer up, by the factor specified in the
+`FBSCALE` environment variable. So run the demo as: `FBSCALE=3 ./demo` for
+a 3x scale factor, or just export the `FBSCALE` env var in the shell you are
+going to use for running the demo. The default scale factor is 2x.
diff --git a/README.txt b/README.txt
deleted file mode 100644 (file)
index 4562318..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-Cross-compile on GNU/Linux
---------------------------
-
-source owdev file with contents (change WATCOM var as necessary):
-
-  export WATCOM=$HOME/devel/ow
-  export PATH=$WATCOM/binl:$PATH
-  export INCLUDE=$WATCOM/h:$INCLUDE
-
-Run wmake to build. Needs dos4gw.exe and wstub.exe in current dir or PATH
-
-Simply running ./demo.exe will invoke magic of the ancients to start wine,
-which will in turn start dosbox, which will execute the DOS binary!
index 4bd02c7..fe0c2c4 100644 (file)
@@ -9,7 +9,7 @@
 int fb_width = 320;
 int fb_height = 240;
 int fb_bpp = 16;
-unsigned char *fb_pixels;
+void *fb_pixels;
 unsigned long time_msec;
 
 static unsigned long nframes;
index e31d596..a022275 100644 (file)
@@ -2,7 +2,7 @@
 #define DEMO_H_
 
 extern int fb_width, fb_height, fb_bpp;
-extern unsigned char *fb_pixels;
+extern void *fb_pixels;
 extern unsigned long time_msec;
 
 int demo_init(int argc, char **argv);
index 38822f3..0abb3e3 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <SDL/SDL.h>
 #include "demo.h"
 
@@ -9,19 +10,42 @@ static int quit;
 static long start_time;
 static SDL_Surface *fbsurf;
 
+static int fbscale = 2;
+static int xsz, ysz;
+
 int main(int argc, char **argv)
 {
+       int s, i, j;
+       char *env;
+       unsigned short *sptr, *dptr;
        unsigned int sdl_flags = SDL_SWSURFACE;
 
+       if((env = getenv("FBSCALE")) && (s = atoi(env))) {
+               fbscale = s;
+               printf("Framebuffer scaling x%d\n", fbscale);
+       }
+
+       xsz = fb_width * fbscale;
+       ysz = fb_height * fbscale;
+
+       if(!(fb_pixels = malloc(fb_width * fb_height * fb_bpp / CHAR_BIT))) {
+               fprintf(stderr, "failed to allocate virtual framebuffer\n");
+               return 1;
+       }
+
        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
-       if(!(fbsurf = SDL_SetVideoMode(fb_width, fb_height, fb_bpp, sdl_flags))) {
+       if(!(fbsurf = SDL_SetVideoMode(xsz, ysz, fb_bpp, sdl_flags))) {
                fprintf(stderr, "failed to set video mode %dx%d %dbpp\n", fb_width, fb_height, fb_bpp);
+               free(fb_pixels);
+               SDL_Quit();
                return 1;
        }
-       SDL_WM_SetCaption("dosdemo SDLemu", 0);
+       SDL_WM_SetCaption("dosdemo/SDL", 0);
 
        time_msec = 0;
        if(demo_init(argc, argv) == -1) {
+               free(fb_pixels);
+               SDL_Quit();
                return 1;
        }
        start_time = SDL_GetTicks();
@@ -34,12 +58,28 @@ int main(int argc, char **argv)
                }
 
                time_msec = SDL_GetTicks() - start_time;
+               demo_draw();
+
                if(SDL_MUSTLOCK(fbsurf)) {
                        SDL_LockSurface(fbsurf);
                }
-               fb_pixels = fbsurf->pixels;
 
-               demo_draw();
+               sptr = fb_pixels;
+               dptr = fbsurf->pixels;
+               for(i=0; i<fb_height; i++) {
+                       for(j=0; j<fb_width; j++) {
+                               int x, y;
+                               unsigned short pixel = *sptr++;
+
+                               for(y=0; y<fbscale; y++) {
+                                       for(x=0; x<fbscale; x++) {
+                                               dptr[y * xsz + x] = pixel;
+                                       }
+                               }
+                               dptr += fbscale;
+                       }
+                       dptr += xsz * (fbscale - 1);
+               }
 
                if(SDL_MUSTLOCK(fbsurf)) {
                        SDL_UnlockSurface(fbsurf);