From: Michael Georgoulopoulos Date: Thu, 1 Sep 2016 21:28:54 +0000 (+0300) Subject: Added scrolling X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=commitdiff_plain;h=091dc2d13563f81dd3e5c97a585388fc6682184d Added scrolling --- diff --git a/src/mike.c b/src/mike.c index 719121e..cf1ed73 100644 --- a/src/mike.c +++ b/src/mike.c @@ -9,6 +9,9 @@ #define BG_FILENAME "data/grise.png" +#define MIN_SCROLL 32 +#define MAX_SCROLL (backgroundW - fb_width - MIN_SCROLL) + static int init(void); static void destroy(void); static void start(long trans_time); @@ -51,7 +54,7 @@ static int init(void) static void destroy(void) { - img_free_pixels(background); + //img_free_pixels(background); } static void start(long trans_time) @@ -65,16 +68,17 @@ static void stop(long trans_time) static void draw(void) { - unsigned short *pixels = fb_pixels; - - int j, i; - for (j = 0; j < fb_height; j++) { - for (i = 0; i < fb_width; i++) { - *pixels++ = 0x0000; - } + int scroll = MIN_SCROLL + (MAX_SCROLL - MIN_SCROLL) * mouse_x / fb_width; + unsigned short *dst = fb_pixels; + unsigned short *src = background + 2 * scroll; + int scanline = 0; + + + for (scanline = 0; scanline < fb_height; scanline++) { + memcpy(dst, src, fb_width * 2); + src += backgroundW; + dst += fb_width; } - - memcpy(fb_pixels, background, backgroundW * backgroundH * 2); } /* src and dst can be the same */