ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Archives :: News :: Feature: TI-86 Assembly Smooth Scrolling

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  Account Info

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: Re: Feature: TI-86 Assembly Smooth Scrolling
timcl  Account Info

I agree. A great, yet simple tutorial. Good work!
PS: Thanks to the person above for not boasting about having the first comment!

     20 April 2000, 19:58 GMT

Re: Feature: TI-86 Assembly Smooth Scrolling
James!  Account Info

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: Re: Feature: TI-86 Assembly Smooth Scrolling
Cullen Logan  Account Info
(Web Page)

Excellent! This feature is awesome. I think it would be cool if you would expand upon it to show how one would scroll using a large map. Because that concept can be a bit harder to understand. I know I wouldnt be able to write the feature b/c I cant teach worth crap. Thanks for the good lesson! Also mayeb you could show how to do vertical scrolling as well....although its easier.
Thanks,
Cullen Logan

     19 April 2000, 04:51 GMT


Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Chris  Account Info
(Web Page)

<grin> Good frief, scrolling vertically is a breather, think about it for a sec. You only need to scroll one row down that means the only thing you actually have to do is copy bytes as in

ld hl, <Source> + 16
ld de, <Source>
ld bc, 1024 / 8 - 16
ldir
.

That's to scroll up of course.

     19 April 2000, 05:39 GMT


Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
DWedit  Account Info
(Web Page)

1) What's with the / 8?

2) Are these correct TI83 routines:

ScrollUp:
_ ld hl, graph_mem + 12
_ ld de, graph_mem
_ ld bc, 768 - 12
_ ldir
_ ret

ScrollDown:
_ ld hl, graph_mem
_ ld de, graph_mem + 12
_ ld bc, 768 - 12
_ ldir
_ ret

     21 April 2000, 08:18 GMT


Re: Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Kouri  Account Info
(Web Page)

ScrollDown:
ld hl,graph_mem+755
ld de,graph_mem+767
ld bc,768-12
lddr
ret

     21 April 2000, 19:48 GMT


Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Jason Schoenfelder  Account Info

In most cases, you would have to run the routine multiple times.

To scroll 4 pixels, you can use RRD/RLD, and for multiples of 8 pixels, you can of course use LDIR/LDDR.

     24 April 2000, 12:06 GMT

Re: Feature: TI-86 Assembly Smooth Scrolling
James abba shalaka Rubingh  Account Info
(Web Page)

This is choice

     19 April 2000, 00:33 GMT


Re: Re: Feature: TI-86 Assembly Smooth Scrolling
amicek  Account Info
(Web Page)

Choice is a cool word. Thank you for using it.

amicek

     19 April 2000, 03:19 GMT


Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Nick Disabato  Account Info
(Web Page)

Only when used as an adjective, though.

--BlueCalx

     19 April 2000, 03:28 GMT


Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
JaggedFlame

Yeah, I guess it's a good choice then... :-P

     19 April 2000, 23:26 GMT


Re: Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Cassady Roop  Account Info
(Web Page)

Bah! Now you're using it as a noun! What is this world coming to...

     25 April 2000, 22:17 GMT

Re: Feature: TI-86 Assembly Smooth Scrolling
DWedit  Account Info
(Web Page)

Could this be easily changed for the 82/83/83+?

     19 April 2000, 00:35 GMT


Re: Re: Feature: TI-86 Assembly Smooth Scrolling
David Phillips  Account Info
(Web Page)

It would be exactly the same for the 85. For the 82/83, you only need to shift 12 bytes, not 16. And you will have to modify a working buffer, and use a routine (probably built into the shell) to dump the buffer to the display controller.

     19 April 2000, 11:17 GMT


Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Jared B  Account Info
(Web Page)

Where can I find out what address in memory to use for the TI-83+. It would be the same as the TI-83, right? I read on the Texas Instruments web site that the only way do display something on the screen of a TI-83 is to go through the LCD driver. Is that true?

Thanks

     19 April 2000, 13:30 GMT


Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
DWedit  Account Info
(Web Page)

Quoted from ION.INC:

plotsscreen= 9340h ;(this is for 83+, or just use plotsscreen, graph_mem, gbuf... they're the same ram)


The only way to copy to the screen is through the LDC driver, but that's what ionFastCopy/_grbufcpy_v does.

     19 April 2000, 23:19 GMT

Re: Feature: TI-86 Assembly Smooth Scrolling
David Phillips  Account Info
(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


Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Scott Noveck  Account Info
(Web Page)

methinks this method is really inefficient for scrolling more than two pixels - I'll borrow a few quotes from Jonah from my ICQ log:

bit offsets - how to shift
0 - no shifting
1 - shift right
2 - shift right twice
3 - chunk and shift left
4 - chunk
5 - chunk and shift right
6 - copy next byte and shift left twice
7 - copy next byte and shift left

"chunk" is basically an extremely quick way to shift 4 bits, originally meant for BCD number:

RRD Instruction
Rotate Right Digit
Rotates data in 4-bit chunks (one BCD digit) to the right between the accumulator (register A) and the address pointed to by HL.
The lower nibble of A is moved to the higher nibble of (HL), the higher nibble of (HL) is moved to the lower nibble of (HL), and the lower nibble of (HL) is moved to the lower nibble of A. The higher nibble of A is unchanged.

     19 April 2000, 17:46 GMT

Don't forget RLD!
Jonah Cohen  Account Info
(Web Page)

RLD Instruction
Rotate Left Digit
Rotates data in 4-bit chunks (one BCD digit) to the left between the accumulator (register A) and the address pointed to by HL.
The lower nibble of (HL) is moved to the higher nibble of (HL), the higher nibble of (HL) is moved to the lower nibble of A, and the lower nibble of A is moved to the lower nibble of (HL). The higher nibble of A is unchanged.

:P

     20 April 2000, 17:58 GMT


Re: Don't forget RLD!
Ciaran McCreesh  Account Info
(Web Page)

He he. Why not copy out of some reeeeeely thick Zilog book, that will look even better :)

Ciaran

     20 April 2000, 20:01 GMT


Re: Re: Don't forget RLD!
David Phillips  Account Info
(Web Page)

Or quote straight from the Assembly Studio 86 help file that Jeremy made and don't even give credit...

     21 April 2000, 06:46 GMT


Re: Re: Re: Don't forget RLD!
Ciaran McCreesh  Account Info
(Web Page)

Yeah, I noticed that. I hate people who quote without mentioning it.

Ciaran

     21 April 2000, 20:27 GMT


Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Chris  Account Info
(Web Page)

Count your cycles. If you were to convert such a routine to assembly, it w2ould be slower then an unrolled loop. jumps are shitty slow!

     21 April 2000, 05:41 GMT

Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Scott Noveck  Account Info
(Web Page)

ok, go ahead and try and write something that scrolls merely by shift one pixel at a time, several times in a row. I don't know what you're smoking, but that would be too slow to be efficient in many games. This method was used in the new peaworm for the 86 and works very, very quickly

     22 April 2000, 17:22 GMT


Re: Re: Re: Re: Feature: TI-86 Assembly Smooth Scrolling
Jonah Cohen  Account Info
(Web Page)

The most time this implementation could possibly take is the equivalent of two shifts, since a chunk takes roughly the same amount of time as a shift. And I would have to say that shifting twice is a heckuva lot faster than shifting 7 times, which you'd have to do otherwise.

     23 April 2000, 04:08 GMT

1  2  

You can change the number of comments per page in Account Preferences.

  Copyright © 1996-2012, the ticalc.org project. All rights reserved. | Contact Us | Disclaimer