static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface) { vga_setdisplaystart(flip_offset[flip_page]); flip_page=!flip_page; surface->pixels=flip_address[flip_page]; vga_waitretrace(); return(0); }
void demo1(void) { int x, y; int targetx, targety; int pageoffset[3] = { 0, 320 * 240 / 4, 2 * 320 * 240 / 4 }; int writepage; int count, startclock; /* Window coordinate initially at center. */ x = VWIDTH / 2 - WINWIDTH / 2; y = VHEIGHT / 2 - WINHEIGHT / 2; targetx = x; targety = y; /* Page flipping initialization. */ vga_setdisplaystart(0); /* Display page 0, write to page 1. */ writepage = 1; count = 0; startclock = clock(); for (;;) { /* Copy window to screen. */ vga_copytoplanar256(vbuf + y * WIDTH + x, WIDTH, pageoffset[writepage], 80, WINWIDTH, WINHEIGHT); /* Flip pages. */ vga_setdisplaystart(pageoffset[writepage] * 4); #ifndef TRIPLEBUFFERING /* Conventional double-buffering (page-flipping). */ vga_waitretrace(); writepage ^= 1; #else /* Triple buffering; no need to wait for vertical retrace. */ writepage = (writepage + 1) % 3; #endif if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (VWIDTH - WINWIDTH); targety = rand() % (VHEIGHT - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > VWIDTH - WINWIDTH) x = VWIDTH - WINWIDTH; if (y < 0) y = 0; if (y > VHEIGHT - WINHEIGHT) y = VHEIGHT - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 1: frame rate %ld\n", count * CLOCKS_PER_SEC / (clock() - startclock)); }
void demo2(void) { int x, y; int targetx, targety; int vwidth, vheight; int count, startclock; /* Make sure window fits in video memory. */ vwidth = VWIDTH; if (vwidth > 640) vwidth = 640; vheight = VHEIGHT; if (vheight > 400) vheight = 400; vga_setlogicalwidth(vwidth); /* Copy virtual screen to logical screen in video memory. */ vga_copytoplanar256(vbuf, VWIDTH, 0, vwidth / 4, vwidth, VHEIGHT); /* Window coordinates initially at center. */ x = vwidth / 2 - WINWIDTH / 2; y = vheight / 2 - WINHEIGHT / 2; targetx = x; targety = y; count = 0; startclock = clock(); for (;;) { /* Set video memory window. */ vga_setdisplaystart((y * vwidth / 4) * 4 + x); vga_waitretrace(); if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (vwidth - WINWIDTH); targety = rand() % (vheight - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > vwidth - WINWIDTH) x = vwidth - WINWIDTH; if (y < 0) y = 0; if (y > vheight - WINHEIGHT) y = vheight - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 2: frame rate %ld\n", count*CLOCKS_PER_SEC /(clock() - startclock)); }