// Simple infinite horizontal scroller. // Press Left/Right to speedup/slowdown change direction etc. // Just an experimental demo made available to illustrate the technique. // by James Shaughnessy james@manc.u-net.com // http://www.netyaroze-europe.com/~shaughnj #define MAXSPEED 50 // Max scroll speed pixels/frame #include #include #include "pad.h" extern DISPENV GsDISPENV; void DrawPicture(); main() { u_long PadStatus = 0; RECT left, right; short offset = 0, inc = 0; // Setup graphics PAL SetVideoMode(MODE_PAL); GsInitGraph(320, 256, 4, 0, 0); GsDISPENV.screen.y = 20; GsDISPENV.screen.h = 256; GsDefDispBuff(0, 0, 0, 0); PadInit(); DrawPicture(); // Permanently set variables left.x = 0; left.y = 256; left.h = 256; right.y = 256; right.h = 256; while(1) { PadStatus = PadRead(); // Quit if both Select and Start pressed if (PadStatus & PAD1select && PadStatus & PAD1start) break; if (PadStatus & PAD1Lleft) if (inc > -MAXSPEED) inc--; if (PadStatus & PAD1Lright) if (inc < MAXSPEED) inc++; // Set rects left.w = offset; right.x = offset; right.w = 320 - offset; // Wait for a vertical blank VSync(0); // Copy virtual screen parts to visible area MoveImage(&right, 0, 0); if (offset) // Only if non-zero; avoids MoveImage(&left, 320 - offset, 0); // zero width rect copy DrawSync(0); GsSwapDispBuff(); // Increment offset (scroll!) and set to legal value offset += inc; if (offset >= 320) offset -= 320; else if (offset < 0) offset += 320; } ResetGraph(0); } // Draw a picture on the screen // (50 Random rectangles) void DrawPicture() { RECT scr; // Virtual screen RECT box; int i; scr.x = 0; scr.y = 256; scr.w = 320; scr.h = 256; ClearImage(&scr, 0, 0, 0); for (i=0; i < 50; i++) { box.x = rand()%290 + scr.x; box.y = rand()%226 + scr.y; box.w = 10 + rand()%30; box.h = 10 + rand()%30; ClearImage(&box, rand()%256, rand()%256, rand()%256); } } // ****** PAD routines ****** // low-level pad buffers: never need to touch volatile u_char *bb0, *bb1; // call once only in program initialisation void PadInit (void) { GetPadBuf(&bb0, &bb1); } // call once per VSync(0) // puts controller pad status into unsigned long integer // please refer to the manuals if you want explanation // of the internals of this function u_long PadRead(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); }