From: John Tsiombikas Date: Sat, 27 Aug 2016 03:03:21 +0000 (+0300) Subject: FBSCALE in SDL backend X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=ecc362e702b77d5c1334656e6f4dc9b17abcb767 FBSCALE in SDL backend --- diff --git a/README.md b/README.md new file mode 100644 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 index 4562318..0000000 --- a/README.txt +++ /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! diff --git a/src/demo.c b/src/demo.c index 4bd02c7..fe0c2c4 100644 --- a/src/demo.c +++ b/src/demo.c @@ -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; diff --git a/src/demo.h b/src/demo.h index e31d596..a022275 100644 --- a/src/demo.h +++ b/src/demo.h @@ -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); diff --git a/src/sdl/main.c b/src/sdl/main.c index 38822f3..0abb3e3 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -1,5 +1,6 @@ #include #include +#include #include #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