X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdos%2Fgfx.c;h=c9a153deec4580d8cd12f45d9aa86cafadf4218c;hb=02e7611eefd46380cbce65ace9da8399c27e78e8;hp=b4e4add842b8b74672624a1e2c0b4973bd29af45;hpb=cfe889ac035848dbe4c3a89afb7c8c37a574163e;p=eradicate diff --git a/src/dos/gfx.c b/src/dos/gfx.c index b4e4add..c9a153d 100644 --- a/src/dos/gfx.c +++ b/src/dos/gfx.c @@ -1,5 +1,7 @@ #include #include +#include +#include "cdpmi.h" #include "gfx.h" #include "vbe.h" #include "vga.h" @@ -8,6 +10,10 @@ ((a) == (b) || ((a) == 16 && (b) == 15) || ((a) == 15 && (b) == 16) || \ ((a) == 32 && (b) == 24) || ((a) == 24 && (b) == 32)) +void (*blit_frame)(void*, int); + +static void blit_frame_lfb(void *pixels, int vsync); +static void blit_frame_banked(void *pixels, int vsync); static uint32_t calc_mask(int sz, int pos); static struct video_mode *vmodes; @@ -19,9 +25,10 @@ static struct vbe_info vbe; /* current mode */ static struct video_mode *curmode; static void *vpgaddr[2]; -static int fbidx; +static int frontidx, backidx; static int pgcount, pgsize, fbsize; + int init_video(void) { int i, num, max_modes; @@ -34,7 +41,7 @@ int init_video(void) vbe_print_info(stdout, &vbe); num_vmodes = 0; - max_modes = 4; /* TODO change */ + max_modes = 64; if(!(vmodes = malloc(max_modes * sizeof *vmodes))) { fprintf(stderr, "failed to allocate video modes list\n"); return -1; @@ -65,6 +72,7 @@ int init_video(void) vmptr->xsz = minf.xres; vmptr->ysz = minf.yres; vmptr->bpp = minf.bpp; + vmptr->pitch = minf.scanline_bytes; if(minf.mem_model == VBE_TYPE_DIRECT) { vmptr->rbits = minf.rsize; vmptr->gbits = minf.gsize; @@ -76,6 +84,15 @@ int init_video(void) vmptr->gmask = calc_mask(minf.gsize, minf.gpos); vmptr->bmask = calc_mask(minf.bsize, minf.bpos); } + if(minf.attr & VBE_ATTR_LFB) { + vmptr->fb_addr = minf.fb_addr; + } else { + vmptr->bank_size = (uint32_t)minf.bank_size * 1024; + if(!vmptr->bank_size) { + vmptr->bank_size = 65536; + } + } + vmptr->max_pages = minf.num_img_pages; printf("%04x: ", vbe.modes[i]); vbe_print_mode_info(stdout, &minf); @@ -137,11 +154,11 @@ int find_video_mode(int mode) void *set_video_mode(int idx, int nbuf) { unsigned int mode; - struct vbe_mode_info minf; struct video_mode *vm = vmodes + idx; printf("setting video mode %x (%dx%d %d bpp)\n", (unsigned int)vm->mode, vm->xsz, vm->ysz, vm->bpp); + fflush(stdout); mode = vm->mode | VBE_MODE_LFB; if(vbe_setmode(mode) == -1) { @@ -153,25 +170,43 @@ void *set_video_mode(int idx, int nbuf) printf("Warning: failed to get a linear framebuffer. falling back to banked mode\n"); } - vbe_mode_info(mode, &minf); - curmode = vm; if(nbuf < 1) nbuf = 1; if(nbuf > 2) nbuf = 2; - pgcount = nbuf > minf.num_img_pages ? minf.num_img_pages : nbuf; - pgsize = (vm->xsz * vm->bpp / 8) * vm->ysz; + pgcount = nbuf > vm->max_pages ? vm->max_pages : nbuf; + pgsize = vm->ysz * vm->pitch; fbsize = pgcount * pgsize; - vpgaddr[0] = (void*)dpmi_mmap(minf.fb_addr, fbsize); - memset(vpgaddr[0], 0xaa, fbsize); + printf("pgcount: %d, pgsize: %d, fbsize: %d\n", pgcount, pgsize, fbsize); + printf("phys addr: %p\n", (void*)vm->fb_addr); + fflush(stdout); + + if(vm->fb_addr) { + vpgaddr[0] = (void*)dpmi_mmap(vm->fb_addr, fbsize); + if(!vpgaddr[0]) { + fprintf(stderr, "failed to map framebuffer (phys: %lx, size: %d)\n", + (unsigned long)vm->fb_addr, fbsize); + set_text_mode(); + return 0; + } + memset(vpgaddr[0], 0xaa, pgsize); + + if(pgcount > 1) { + vpgaddr[1] = (char*)vpgaddr[0] + pgsize; + backidx = 1; + page_flip(FLIP_NOW); /* start with the second page visible */ + } else { + frontidx = backidx = 0; + vpgaddr[1] = 0; + } + + blit_frame = blit_frame_lfb; - if(pgcount > 1) { - vpgaddr[1] = (char*)vpgaddr[0] + pgsize; - fbidx = 1; - page_flip(FLIP_NOW); /* start with the second page visible */ } else { - fbidx = 0; + vpgaddr[0] = (void*)0xa0000; vpgaddr[1] = 0; + + blit_frame = blit_frame_banked; } return vpgaddr[0]; } @@ -190,10 +225,40 @@ void *page_flip(int vsync) return vpgaddr[0]; } - vbe_swap(fbidx ? pgsize : 0, vsync ? VBE_SWAP_VBLANK : VBE_SWAP_NOW); - fbidx = (fbidx + 1) & 1; + vbe_swap(backidx ? pgsize : 0, vsync ? VBE_SWAP_VBLANK : VBE_SWAP_NOW); + frontidx = backidx; + backidx = (backidx + 1) & 1; + + return vpgaddr[backidx]; +} + + +static void blit_frame_lfb(void *pixels, int vsync) +{ + if(vsync) wait_vsync(); + memcpy(vpgaddr[frontidx], pixels, pgsize); +} + +static void blit_frame_banked(void *pixels, int vsync) +{ + int i, sz, offs; + unsigned int pending; + unsigned char *pptr = pixels; + + if(vsync) wait_vsync(); + + /* assume initial window offset at 0 */ + offs = 0; + pending = pgsize; + while(pending > 0) { + sz = pending > curmode->bank_size ? curmode->bank_size : pending; + memcpy((void*)0xa0000, pptr, sz); + pptr += sz; + pending -= sz; + vbe_setwin(0, ++offs); + } - return vpgaddr[fbidx]; + vbe_setwin(0, 0); } static uint32_t calc_mask(int sz, int pos)