Feature: TI-86 Assembly Smooth Scrolling
Posted by Nick on 19 April 2000, 00:05 GMT
Mike Bronzell has written our next feature: a tutorial on scrolling the screen to the left and right in assembly. Smooth Scrolling On The TI-86 by Michael Bronzell vbwatch04@yahoo.com This is a very basic tutorial that should help you get started on smooth HORIZONTAL scrolling for the Ti-86. The idea is basically the same for most of the calcs, so it wont be hard to rewrite this for your own calc if it's not an 86. First we need to know how the screen is stored in bytes. The whole screen uses 1024 bytes to save it in memory. That is 16 bytes per row. How do i get 16? ok, every byte has 8 bits all which are 1's and 0's (on and off). so every 8 pixels on the screen are 1 byte.(128pixels / 8bits = 16bytes!). Ok, that was easy. Now the idea behind smooth scrolling is we are gonna take each row and rotate all the pixels either left or right using the rr or rl command, these are explained in detail later. Then we move to the next byte on screen and shift them too. Commands you NEED to know: rr - rotate right, it will put bit 0 into the carry flag then this will rotate all bits in the byte to the right then bit 0 goes into the carry flag. Graphical Example: This is our byte in Video Memory: 1 1 0 1 1 1 1 1 Ok, now we will rotate this using rr. rr (hl) Now our byte looks like this: x 1 1 0 1 1 1 1 Okay what happened? all bits got shifted to the right, the (x) means that and bit 0 that got cut off is now put into the carry flag. rl - rotate left, will put bit 7 into the carry flag then will rotate all bits in a byte to the left and place the carry flag into bit 0. This is our byte in video memory: 1 1 0 1 1 1 1 1 Ok, now we will rotate our byte using rl. rl (hl) Now our byte looks like this: 1 0 1 1 1 1 1 x As you can see, all the bits were moved 1 bit to the left and the (x) is where the carry flag will be put in. How to scroll the screen LEFT: Ok, first we are gonna make a routine to scroll the screen left. This is *very* easy to do. What were gonna do is start at the upper right corner of the display at row 0. Then, we keep rotating bytes on that row to the left until we have rotated all 16 bytes; then go to the next row and do the same. The routine: scroll_left: ; calling this routine will scroll the whole screen to the left by 1 pixel ld hl,0 ;load our start point of video memory into hl ld c,64 ;this is how many rows to scroll the screen. For example if you wanted to ;scroll only the top half of the screen, just put ld c,32 scroll3: ld b,4 ;This is used for our djnz loop, we need it to loop four times because in our ;routine we only shift 4 bytes. That means to rotate all 16 bytes in a ; row we need do this routine 4 times before going to the next line. or a ;this will reset the carry flag everytime we start a new row. If you ; didnt reset the carry flag then you would have the screen wrap around the ;end, try not using it to see what i mean. scroll2: dec hl ;dec value in hl by 1 byte rl (hl) ;rotate that byte to the left dec hl ; .... rl (hl) ; .... dec hl ; .... rl (hl) ; .... dec hl ; .... rl (hl) ; .... djnz scroll2 ; check if b=0, if its not, decrease b and goto scroll2 dec c ; decrease value of c. C is used to determine how many rows we have to do ; still. jr nz,scroll3 ; if c does not equal 0 then goto scroll3(which will ;start rotating the next line) ret ;return Okay, that wasnt too hard now was it? Now we will try and rotate it to the right. How to scroll the screen to the Right: Scrolling the screen to the right is almost the same as scrolling to the left except we have to change a few things. When we scroll to the right we will start at the upperleft corner of the LCD instead, and we will use rr's instead of rl's. We also do inc hl instead of dec hl because we are starting from the left and working our way to the right. scroll_right: ; calling this routine will scroll the whole screen to the right by 1 pixel ld hl,$fc00 ;load our start point of video memory into hl. $fc00 is the ; beginning of video memory. ld c,64 ;this is how many rows to scroll the screen. For example if you wanted to ;scroll only the top half of the screen, just put ld c,32 scrollright3: ld b,4 ;This is used for our djnz loop, we need it to loop four times because in our ;routine we only shift 4 bytes. That means to rotate all 16 bytes in a ; row we need do this routine 4 times before going to the next line. or a ;this will reset the carry flag everytime we start a new row. If you ; didnt reset the carry flag then you would have the screen wrap around the ;end, try not using it to see what i mean. scrollright2: rr (hl) ;rotate that byte to the left inc hl ;inc value in hl by 1 byte rr (hl) ; .... inc hl ; .... rr (hl) ; .... inc hl ; .... rr (hl) ; .... inc hl ; .... djnz scrollright2 ; check if b=0, if its not, decrease b and goto scrollright2 dec c ; decrease value of c. C is used to determine how many rows we have to do ; still. jr nz,scrollright3 ; if c does not equal 0 then goto scroll3(which will ;start rotating the next line) ret ;return Conclusion - Scrolling the screen isn't too hard. If you wanted to implement this to scroll a tilemap, all you would have to do is us an offset value for the first tile and everytime you scroll the screen just use the offset to find where to draw the last column of tiles to the right of the screen (or to the left). If you need any more help, just email me at vbwatch04@yahoo.com and i will try and help you as soon as i can.
|
|
|
The comments below are written by ticalc.org visitors. Their views are not necessarily those of ticalc.org, and ticalc.org takes no responsibility for their content.
|
|
Re: Feature: TI-86 Assembly Smooth Scrolling
|
Sean Barnes
|
This is great. I understand paged tilemaps, and have been interested in learning how to do scrolling tilemaps. Thanks!
-Sean
|
|
19 April 2000, 00:27 GMT
|
|
Re: Feature: TI-86 Assembly Smooth Scrolling
|
James!
|
What would you do if you wanted to scroll the screen more than one pixel? Would you use this routine multiple times? Or is there a faster way to do it?
|
|
19 April 2000, 00:30 GMT
|
|
Re: Feature: TI-86 Assembly Smooth Scrolling
|
DWedit
(Web Page)
|
Could this be easily changed for the 82/83/83+?
|
|
19 April 2000, 00:35 GMT
|
|
Re: Feature: TI-86 Assembly Smooth Scrolling
|
David Phillips
(Web Page)
|
The method shown in the article is inefficient. It is usually advantageous to unroll the loop 16 times, thus eliminating the inner loop entirely.
|
|
19 April 2000, 08:44 GMT
|
|
1 2
You can change the number of comments per page in Account Preferences.
|