#include <math.h>
#include <string.h>
#include <limits.h>
+#include <assert.h>
#include <conio.h>
#include "demo.h"
#include "keyb.h"
#include "cfgopt.h"
#include "logger.h"
#include "tinyfps.h"
+#include "cdpmi.h"
-#define NOKEYB
+#undef NOKEYB
static int handle_sball_event(sball_event *ev);
static void recalc_sball_matrix(float *xform);
int main(int argc, char **argv)
{
- fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT;
+#ifdef __DJGPP__
+ __djgpp_nearptr_enable();
+#endif
+
+ fbsize = fb_width * fb_height * fb_bpp / 8;
init_logger("demo.log");
#endif
if((use_mouse = have_mouse())) {
+ printf("initializing mouse input\n");
set_mouse_limits(0, 0, fb_width, fb_height);
set_mouse(fb_width / 2, fb_height / 2);
}
- if(!(fb_pixels = malloc(fbsize))) {
+ /* allocate a couple extra rows as a guard band, until we fucking fix the rasterizer */
+ if(!(fb_pixels = malloc(fbsize + (fb_width * fb_bpp / 8) * 2))) {
fprintf(stderr, "failed to allocate backbuffer\n");
return 1;
}
+ fb_pixels += fb_width;
- if(!(vmem_front = set_video_mode(fb_width, fb_height, fb_bpp))) {
+ if(!(vmem = set_video_mode(fb_width, fb_height, fb_bpp, 1))) {
return 1;
}
- /* TODO implement multiple video memory pages for flipping */
- vmem_back = vmem_front;
if(demo_init(argc, argv) == -1) {
set_text_mode();
}
if(use_sball && sball_pending()) {
sball_event ev;
- printf("got sball event\n");
while(sball_getevent(&ev)) {
handle_sball_event(&ev);
}
void swap_buffers(void *pixels)
{
- /* TODO implement page flipping */
- if(pixels) {
- if(opt.vsync) {
- wait_vsync();
- }
- drawFps(pixels);
- memcpy(vmem_front, pixels, fbsize);
- } else {
- drawFps(vmem_back);
+ if(!pixels) {
+ pixels = fb_pixels;
+ }
- if(opt.vsync) {
- wait_vsync();
- }
+ /* just memcpy to the front buffer */
+ if(opt.vsync) {
+ wait_vsync();
}
+ drawFps(pixels);
+ memcpy(vmem, pixels, fbsize);
}