X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Fdos%2Fgfx.c;fp=src%2Fdos%2Fgfx.c;h=b55b4e6b3f28b7ad94400e35e00658537654f491;hp=0000000000000000000000000000000000000000;hb=b82bab85314bbc57d1c542d4d6687de0cd75c375;hpb=acf706a52fdef3bea3f4ae07b7797395f854c11e diff --git a/src/dos/gfx.c b/src/dos/gfx.c new file mode 100644 index 0000000..b55b4e6 --- /dev/null +++ b/src/dos/gfx.c @@ -0,0 +1,121 @@ +#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)) + +static int vbe_init_ver; +static struct vbe_info vbe; +static int mode, pgsize, fbsize; +static struct vbe_mode_info mode_info; + +static void *vpgaddr[2]; +static int fbidx; + +static int init_vbe(void) +{ + if(vbe_info(&vbe) == -1) { + return -1; + } + + vbe_print_info(stdout, &vbe); + fflush(stdout); + + vbe_init_ver = VBE_VER_MAJOR(vbe.ver); + return 0; +} + +void *set_video_mode(int xsz, int ysz, int bpp) +{ + int i, nmodes; + int best_match_mode = -1; + struct vbe_mode_info minf; + + if(!vbe_init_ver) { + if(init_vbe() == -1) { + fprintf(stderr, "failed to initialize VBE\n"); + return 0; + } + if(vbe_init_ver < 2) { + fprintf(stderr, "VBE >= 2.0 required\n"); + return 0; + } + } + + mode = -1; + + for(i=0; i 1) { + vpgaddr[1] = (char*)vpgaddr[0] + pgsize; + fbidx = 1; + page_flip(FLIP_NOW); /* start with the second page visible */ + } else { + fbidx = 0; + vpgaddr[1] = 0; + } + + return vpgaddr[0]; +} + +int set_text_mode(void) +{ + vga_setmode(3); + return 0; +} + +void *page_flip(int vsync) +{ + if(!vpgaddr[1]) { + /* page flipping not supported */ + return vpgaddr[0]; + } + + vbe_swap(fbidx ? pgsize : 0, vsync ? VBE_SWAP_VBLANK : VBE_SWAP_NOW); + fbidx = (fbidx + 1) & 1; + + return vpgaddr[fbidx]; +}