TICT TUTORIAL SERIES 1 - Part VIII | (c) TI-Chess Team 2001 |
Fast Scrolling Up,Down,Left And Right |
This tutorial presents "ready-to-use" TIGCC inline ASM routines to scroll a specific number of lines of a screenbuffer (240x128) up, down, left and right. The routines are compatible with TI-89 and TI-92+ calculators without any modifications.
File scroll.c demonstrates the usage of these routines by moving the screen content randomly in one of the 4 directions (Looks like an earthquake is going on and it's really hard to "screenshot" this effect ;-)
Well, scrolling lines up and down is quite simple on a TI-89/92+ calculator. It's just a matter of copying the content of a complete lines. A possible implementation to scroll a specific number of lines one line up may look like this:
void ScrollUpPseudoCode(unsigned char* buffer, short nr_lines) { unsigned char* dest = buffer; unsigned char* src = dest+30; // one line below dest short act_line; short i; //----------------------------------------------- // move nr_lines upwards ... //----------------------------------------------- for (act_line=0;act_line<nr_lines-1;act_line++) { for (i=0;i<30;i++) *dest++ = *src++; // copy a complete line ... } //----------------------------------------------- // clear last line //----------------------------------------------- for (i=0;i<30;i++) *dest++ = 0; }Scrolling down can be implemented similar. Of course, the above presented routine is not as fast as possible. Using two loops and copying only single bytes instead of long words is very inefficiently. Using memcpy() instead of the inner loop is also very inefficiently. The overhead of the function call would completely out-weight the speed gain of memcpy()!
How to implement up and down scrolling efficiently by using inline ASM can be found in file scroll.c (ScrollUp() and ScrollDown()). If you don't know 68k Assembly it doesn't really matter. Just copy-and-paste the code into your sourcecode and use it ;-)
NOTE: For speedup reasons the used buffer has to start on an even memory address otherwise the routines will crash!
Scrolling left and right on a TI-89 or TI-92+ calculator is much more complicated. Due to the fact that each byte of the screenbuffer contains 8 pixels the buffer content cannot be just copied, but each byte have to be modified. A possible implementation to scroll a specific number of lines one column to the right may look like this:
void ScrollRightPseudoCode(unsigned char* buffer, short nr_lines) { short act_line; short i; unsigned char value; unsigned char carry; //----------------------------------------------- // move nr_lines upwards ... //----------------------------------------------- for (act_line=0;act_line<nr_lines;act_line++) { carry = 0; for (i=0;i<30;i++) { value = (*buffer >> 1) | carry; if (*buffer & 0x01) carry = 0x80; else carry = 0x00; *buffer++ = value; } } }As you can see from the above code scrolling right is much more effort than up and down scrolling. Getting the most right pixel of a byte which have to move to the next byte's most left position cannot be implemented in a fast way with standard C. But the 68k processor supports ASM instructions which can process this "rotating with carry" in one step. A fast implementation using again inline ASM can be found in scroll.c (ScrollLeft() and ScrollRight).
NOTE: For speedup reasons the used buffer has to start on an even memory address otherwise the routines will crash!
Check the TICT HQ Website at http://tict.ticalc.org for more tutorials and software.More useful tips, tricks and hints can be found at our Messageboard at: http://pub26.ezboard.com/btichessteamhq.
Suggestions, bug reports and similar are VERY welcome (use our Messageboard for this!!).
Like Xavier from the Doors Team I like it to get postcards from all over the world. If you want to thank me, just send me a postcard with greetings on it. Thats enough.
My snail mail address is:Thomas Nussbaumer Heinrichstrasse 112a A-8010 Graz Austria... and please: no mail bombs if one of my programs had crashed your calculator!
This program may be distributed by any other website for non-commercial use only.
DISTRIBUTIONS ON ANY OTHER MEDIUM (Disc,CD-ROM,DVD etc.) are PROHIBITED without separate allowance of the author.
The author makes no representations or warranties about the suitability of the software and/or the data files, either express or implied. The author shall not be liable for any damages suffered as a result of using or distributing this software and/or data files.
You are free to re-use any part of the sourcecode in your products as long as you give credits including a reference to the TICT-HQ (http://tict.ticalc.org/).