/****************************************************************************** * * project name: S1P8 * initial date: 11/04/2001 * author: thomas.nussbaumer@gmx.net * description: Scrolling functions for up,down,left and right * * compile with: tigcc -O2 -fomit-frame-pointer scroll.c -Wall -w * * $Id: scroll.c,v 1.1 2001/04/11 23:12:40 Thomas Nussbaumer Exp $ * *******************************************************************************/ #define SAVE_SCREEN // restore screen after program quits #include /*---------------------------------------------------------------------------*/ /* global variables */ /*---------------------------------------------------------------------------*/ short _ti89; // needed to produce ti89 code short _ti92plus; // needed to produce ti92plus code //============================================================================= // scrolls a specific number of lines of a LCD buffer (240x128) 1 column to the // left (lines are 30 bytes long) ... // // NOTE: given buffer have to start on an even address otherwise function will // crash !!! //============================================================================= void ScrollLeft(unsigned short* buffer,unsigned short lines) { register short* tmpbuffer = buffer; register short tmplines = lines; tmpbuffer += (tmplines<<4) - (tmplines); tmplines--; asm volatile ( "0: and.b #0xee,%%ccr roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0) roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0) roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0);roxl.w -(%0) dbra %1,0b" : "=a" (tmpbuffer), "=d" (tmplines) : "0" (tmpbuffer), "1" (tmplines)); } //============================================================================= // scrolls a specific number of lines of a LCD buffer (240x128) 1 column to the // right (lines are 30 bytes long) ... // // NOTE: given buffer have to start on an even address otherwise function will // crash !!! //============================================================================= void ScrollRight(unsigned short* buffer,unsigned short lines) { register short* tmpbuffer = buffer; register short tmplines = lines; tmplines--; asm volatile ( "0: and.b #0xee,%%ccr roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+; roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+; roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+;roxr.w (%0)+ dbra %1,0b" : "=a" (tmpbuffer), "=d" (tmplines) : "0" (tmpbuffer), "1" (tmplines)); } //============================================================================= // scrolls a specific number of lines of a LCD buffer (240x128) 1 line // upwards (lines are 30 bytes long) ... // // NOTE: given buffer have to start on an even address otherwise function will // crash !!! //============================================================================= void ScrollUp(unsigned short* buffer,unsigned short lines) { register short* dest = buffer; register short* src = dest + 15; register short tmplines = lines; tmplines-=2; asm volatile ( "0: move.l (%0)+,(%1)+;move.l (%0)+,(%1)+;move.l (%0)+,(%1)+ move.l (%0)+,(%1)+;move.l (%0)+,(%1)+;move.l (%0)+,(%1)+ move.l (%0)+,(%1)+;move.w (%0)+,(%1)+ dbra %2,0b clr.l (%1)+;clr.l (%1)+;clr.l (%1)+;clr.l (%1)+ clr.l (%1)+;clr.l (%1)+;clr.l (%1)+;clr.w (%1)+" : "=a" (src), "=a" (dest), "=d" (tmplines) : "0" (src), "1" (dest), "2" (tmplines)); } //============================================================================= // scrolls a specific number of lines of a LCD buffer (240x128) 1 line // downwards (lines are 30 bytes long) ... // // NOTE: given buffer have to start on an even address otherwise function will // crash !!! //============================================================================= void ScrollDown(unsigned short* buffer,unsigned short lines) { register short* dest = buffer; register short* src; register short tmplines = lines; dest += (tmplines<<4) - (tmplines); src = dest - 15; tmplines -= 2; asm volatile ( "0: move.l -(%0),-(%1);move.l -(%0),-(%1);move.l -(%0),-(%1) move.l -(%0),-(%1);move.l -(%0),-(%1);move.l -(%0),-(%1) move.l -(%0),-(%1);move.w -(%0),-(%1) dbra %2,0b clr.l -(%1);clr.l -(%1);clr.l -(%1);clr.l -(%1) clr.l -(%1);clr.l -(%1);clr.l -(%1);clr.w -(%1)" : "=a" (src), "=a" (dest), "=d" (tmplines) : "0" (src), "1" (dest), "2" (tmplines)); } //============================================================================= // simple demo program which demonstrates an earthquake effect // // can you screenshot this effect ??? ;-) //============================================================================= void _main(void) { short lines = (TI89) ? 100 : 128; short old_random = 0; short new_random; do { old_random = new_random; do { new_random = random(4); } while (new_random == old_random); //--------------------------------------------------------------------- // if/else if/else chain produces smaller code than case !! //--------------------------------------------------------------------- if (!new_random) ScrollLeft(LCD_MEM,lines); else if (new_random==1) ScrollRight(LCD_MEM,lines); else if (new_random==2) ScrollUp(LCD_MEM,lines); else ScrollDown(LCD_MEM,lines); } while (!kbhit()); ngetchx(); // fetch pressed key ... } //############################################################################# // Revision History //############################################################################# // // $Log: scroll.c,v $ // Revision 1.1 2001/04/11 23:12:40 Thomas Nussbaumer // initial version // //