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
GForce

Could someone explain why Mike first loads hl with 0... how does that make hl point to memory address that is to be modifyied in the scrolling left example?

     20 April 2000, 01:05 GMT


Re: Re: Feature: TI-86 Assembly Smooth Scrolling
rabidcow
(Web Page)

this is mostly a guess, but 0 is just after the last byte in video memory.
since you're going backwards for that one (that is the one going backwards, right?), you need to start at the end($0000) instead of the beginning($fc00)

     20 April 2000, 08:45 GMT

TI-83 Assembly Smooth Scrolling?
DWedit  Account Info
(Web Page)

Is this the correct code for a TI83(+)?

scroll_left:
ld hl,graph_mem+767
ld b,64
scroll2:
or a
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
dec hl
rl (hl)
djnz scroll2
ret


scroll_right:
ld hl,graph_mem
ld b,64
scrollright2:
or a
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
rr (hl)
inc hl
djnz scrollright2
ret

Well... is it correct?

     21 April 2000, 03:29 GMT


Re: TI-83 Assembly Smooth Scrolling?
Reno  Account Info

woah, I'm no expert at assembly or anything, and I don't even code for the 83, but that does NOT look too efficient :P

     21 April 2000, 06:19 GMT


Re: Re: TI-83 Assembly Smooth Scrolling?
David Phillips  Account Info
(Web Page)

You say you don't code, especially assembly, yet you make an assumption about how efficient it is? That is actually the most efficient way (at least naively) to scroll a bit buffer on the Z80. And, yes, that is correct code for the 82/83/83+.

     21 April 2000, 06:56 GMT

Re: Re: Re: TI-83 Assembly Smooth Scrolling?
Jonah Cohen  Account Info
(Web Page)

Well it's efficient in speed, but he might have been referring to size. Even a basic programmer can recognize that the same two lines of assembly code repeated twelve times in a row could easily be stuck in a loop, which would save space.

     21 April 2000, 16:51 GMT

Re: Re: Re: TI-83 Assembly Smooth Scrolling?
Reno  Account Info

actually, I never said i don't code assembler; I merely said I'm no expert at it. Just yesterday I actually finished making my own version of the PutSprite routine (for the 86; it's just something I figured I needed to understand), so I'm merely a novice, not a newbie. That code just repeats 12 pairs of lines; unless there's a reason I am blind to, I see no reason it cannot be put in a loop...

     21 April 2000, 22:55 GMT


Re: Re: Re: Re: TI-83 Assembly Smooth Scrolling?
pcflyer1  Account Info
(Web Page)

It could be put into a loop. That would make the code smaller, but also a bit slower. The repeated jumping in the loop would cause the code to run a little slower than just repeating the instructions 12 times. It just depends on which way you look at it. If you want more efficient size, use a loop. If it's execution speed you want, then repeat the instructions without a loop.

     22 April 2000, 22:08 GMT


Re: Re: Re: TI-83 Assembly Smooth Scrolling?
Jason Schoenfelder  Account Info

I don't mean to nitpick or anything, but the scroll-left routine is slightly wrong. The first line of code should read "ld hl,graph_mem+768", not 767. Or you could keep it as 767 and reverse the "dec hl \ rl (hl)" lines. Otherwise, you'll scroll the screen stored at (graph_mem-1).

     24 April 2000, 12:13 GMT

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

How do you draw what appears after you scroll?

     21 April 2000, 03:33 GMT

OK! I NEED TO KNOW SOMTHING!
shadowlord_IV

Would anyone please please please please please do an assembly tutorial like this for the 89? I must be blind for not seeing one...

     21 April 2000, 19:18 GMT

Re: Feature: TI-86 Assembly Smooth Scrolling
MathJMendl
(Web Page)

good job

     26 April 2000, 05:15 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