ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Archives :: News :: Feature: Two-Dimensional BASIC Scrolling

Feature: Two-Dimensional BASIC Scrolling
Posted by Nick on 8 March 2000, 01:23 GMT

Brandon Green of SiCoDe Software is the first person to take the mic in this feature concerning two-dimensional scrolling in a BASIC program. Hopefully it can teach you a thing or two about BASIC programming and how strings work.


SiCoDe Software has recently discovered a method to scroll the entire screen at four frames per second. One example of this technology is the TI-83 BASIC game Frogger. The method envolves using a seldom exploited function called a string. [Strings are frequently used in BASIC programs, just not in this specific way. -ed.]
A tutorial of how we did it follows:


ADVANCeD.BASiC Tutorial:
Scrolling the Entire Screen From Left To Right


Part 1: Strings Make it Possible

String?

Suprisingly enough, perhaps one of the most advanced functions of the TI-83 is also the least known. For those of you who dont know a string is used to store a, well, string of charachter data. It is very similar to lists, and with the many advanced string operations you can mainpulate it just as you would a list.
A string can be any length, it can be infinitely long, or when you run out of memory. As every one knows, when you use the Disp command and you try to disp a message that is wider than the screen you get those annoying little dots(...) and it cuts it off. However, when you use the Output( command to output a string, it automatically wraps the message in the string to the next line. This will come in very handy down below.

String Operations

Since string operations arent well known, I will list them here. All these operations can be found in the catalog on your calculator: [note that all these operations can be found in your manual:), if you have any syntax questions, consult your manual, believe it or not, you can learn something from reading a book]

->-(storing into a string)
In order to put a message into a string you put what you want to input in quotes, like so: "STRINGS ARE FUN!"->Str1. You could then do a Disp Str1, and STRINGS ARE FUN! would be put on the homescreen. You can also do Input Str1 and then whatever the user typed in would be stored into the string.

+-(concatenation)
Suppose you had , "HELLO_"->Str1, and , "BOB"->Str2. If you wanted to add these together to create Str3, "HELLO_BOB", you would just type in: Str1+Str2->Str3.

Length(string)

If you had a string and you wanted to know how many charachters were in "HELLO BOB", then you would type Length(Str3) and it would return a 9. You could store this number into a variable for later use by Length(Str3)->S.



Sub(string,begin,length)- This is used if you want to take just a part of a string and store it into another string.
For example:
"ABCDEFGHIJKLM"->Str1
Sub(Str1,4,3)->Str2
Disp Str2
[displays]
DEF

This is a way to substract parts from a string. You'll understand more after you read the rest of the tutorial.

Part 2: Moving the String

Scrolling

The basic idea of scrolling is that you have a 'map' that is bigger than the screen. You can then move the point that the screen is centered on to see different parts of the 'map'. By moving the point the screen is centered on over and over 1, you generate the illusions that the 'map' is scrolling by on the screen. Here is an example program that will scroll a string across the screen:
This is written with the TI-82/83/83+ in mind, if your screen is not 16 charachters wide, you will have to change the code.


1:ClrHome
2:"THIS_STRING_IS_MORE_THAN_16_CHARACTERS_LONG."->Str1
3:"________________"+Str1-
>Str1 //16
spaces long
4:For(a,1,45)
5:Output(1,1,sub(str1,a,16)
6:End

2: Sets the 'map'(in this case its just a one dimensional 'map') into string 1;
3: Since we want to scroll the entire string ALL the way across the string, we have to add this. If we didn't when the for loop got to 30, it would try to take the next 16 charachters to output, but it isn't 46 characters long, so we would get an error. This prevents that.
4: This is the loop that keeps track of the point at which the screen is looking at the 'map'.
5: What makes this fast and possible is that it outputs everything in one output statement, it takes the position of the screen on the 'map', gets the next 16 characters, and outputs them.
6: Ends for loop.

As you can see, there is no need to clear the first line because the output statement overwrites it , with a space, every time. By using this same principle you can scroll the entire screen. Here is some sample code I came up with. I didn't provide documentation so you'll have to figure it out on your own.

ClrHome
"*_+_*++*_+_*++*_+_*++*_+_*++*_+_*++*_+_*++*"->Str1
"________________"->Str2 //16 spaces long
6->A
While 1
0->K
While not(getKey
End
(Ans=26)-(Ans=24)+A->A
If A>27:A-1->A
If A<1:A+1->A
sub(Str1,A,16)+Str2->Str3
Output(1,1,Str3+Str3+Str3+Str3
End

As you can see, with this you can move the entire screen at about 3-4 FPS! This is an incredible speed in a basic program.

Don't forget that it auto-wraps the string to the next line when you use strings, this is what is makes it so fast, you output the entire screen in one statement!

For some reason there seem to be no basic games out there that use this technology effectively. Perhaps no knew about it. But dont worry, SiCoDe is working on some very impressive side scrollers... Check the site in the next few months (2/2000 to 5/2000) to get the side scroller when it is released.

Part 3: Conditionals and Strings

Let's say you were working on a game - a frogger game - and you already know how to scroll the cars across the screen. So if you put in the loop where you could control a character, and you had one whole list outputed to the screeen. Then you check to see if the character hit something by:

If (sub(Str1,(16(y-1))+x,1))!="_" //for those nonC++ programmers, != means does not equal
disp " you hit something!"

The (16(y-1))+x converts the two coordinates of the charachter to a position along the screen, it follows this pattern:


1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 row 1
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 row 2
33,34,35,36,37,38,39,40,41,42,43,45,46,47,48,49 row 3
....
113,114,...,128 row 8

(Each number represents a character position along the screen.)

This formula would only work if your string was outputed at 1,1. But it would be easy to change the formula to whatever you wanted.

In this way you could have hit detection using strings. And here is a sample program so that you can understand this better. Note that this is not optimised or anything, I threw it together in 3 minutes, so yes, it could be made a heck of a lot better.

"_____(---)__(++)_____(**)__(---)___(///////)__(----)_____(+++)"->Str1 //you could put
//any string here that is more than 20 characters long
"________________"->Str2 //16 spaces
5->X:8->Y
1->P:1->H
length(Str1)-16->L
While H
Output(Y,X,"*"
sub(Str1,A,16)->Str3
Str2+Str3+Str2+Str3+Str2+Str3+Str3+Str2->Str4
Output(1,1,Str4
getKey->K
If K:Then
(K=26)-(K=24)+X->X
(K=34)-(K=25)+Y->Y
End
If (sub(Str4,(16(Y-1))+X,1))!="_" //does not equal a space
0->H
A+1->A
If A=L
1->A
End
Output(Y,X,"X"

There is also a 2-D scrolling engine which SiCoDe has invented. You can expect more advanced scrolling games from SiCoDe in the future.

 


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: Two-Dimensional BASIC Scrolling
Hieu-Trung Le  Account Info
(Web Page)

WOW. Great job Brandon. I guess I can learn a lot from you!!

=) Good luck on your future programs

     8 March 2000, 02:04 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
Horse_Power Account Info

SiCoDe will be realesing War soon that gets 6fps and is great fun. Everyone with 83 should try it too when it comes out.

     8 March 2000, 02:54 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
Horse_Power Account Info

oh yeah, and connect 4 with comp A.I. is out in Basic now at sicode.ticalc.org. It has one more feature than Asm's connect 4 with A.I. because the comp talks you. It thinks really fast too, just like .5 sec slower than Asms but uses up much more mem:(. It uses like 4-5k or something. And the idea was not based off Asm's for those of you who call me unoriginal. I actually programmed it a long long time ago before Asm's came out and recently joined sicode and made a new one with better graphics.

     8 March 2000, 03:12 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
amicek  Account Info
(Web Page)

Hey Nick! I was talking to you on ICQ but ran out of time; here is that idea that I had:

When a large amount of people respond to a news article, the page takes a long time to load. I have noticed you have set up the page to load the logo and main nav and then the rest of the page using <!-- these things --> - that is a good idea; so could you set it up so you can have <!-- first comment block --> so it loads the comments in fairly small blocks - I dont' know if this is a feasible idea using cgi, but it would allow people to read comments while the page was loading. Under preferences, the person could set their connection speed and you could set the length of the comment "blocks" accordingly - the only possible problem i could see would be - a.)it wouldn't work or b.)implementation using cgi would be difficult or impossible. For example, if someone had a 14400 connection, you could set the comment block length to 5 comments, etc. So it would load five comments, and the person could read the comments while the next five were loading. Tell me what you think!

amicek

     8 March 2000, 04:23 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
Nick Disabato  Account Info
(Web Page)

That sounds like a good idea. Chris and Phil are currently working on news system improvements, so contact them.
I just *report* the news :)

--BlueCalx

PS: That's smack@ticalc.org and pgenera@ticalc.org, in that order.

     8 March 2000, 04:47 GMT


News!
jamin  Account Info

Nick just *creates* the news :)

Side scrolling: This is also useful for text viewers. I have made several homework notepads using the string command. Tragically, they and several other great 83 basic programs were viciously deleted many eons ago.

     8 March 2000, 20:37 GMT


Re: News!
David Hall  Account Info
(Web Page)

> Nick just *creates* the news :)

Hah! I knew he made it all up! Your secret is out, Nick :)

     9 March 2000, 20:42 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
TheMaker

When I try to run this program I get a "INVALID DIM" error. I checked the code over again and I still get a problem. Please Help

     8 March 2000, 22:32 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
dark~helmet  Account Info

I got that at first too but if you store 1 to A at the beginning of the program it will work

     9 March 2000, 01:07 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
TheMaker

now it works I can't read

     8 March 2000, 22:50 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Didn't they teach you that at school? :)
Do you mean it scrolls too fast or it doesn't work?

     9 March 2000, 20:10 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Kim  Account Info

Heres a tip... insert a few cos( with a number (anynumber at the end) in the for( end statement. the more cos( there are, the more the program slows down.

     16 March 2000, 01:46 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
CrazyBillyO  Account Info
(Web Page)

This is all great, but what we really need here is some asm 68k tutorials and techniques. Like how to open and read strings (and open and read other files for that matter) in assembly code. That would be just nifty skippy.

     9 March 2000, 03:49 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Uh, doesn't the ASM guru at DimTI have stuff like that?

     9 March 2000, 20:07 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath

No, ASMguru is Z80 ASM, not 68k. But they're both an 8, a number with a loop in it, and a letter...

Also, you can get ASMguru at ticalc.org, too... I would suggest that you say you can get it at the site you're posting at, just as sort of a common sense thing... And I think I uses ellipses (or whatever... that "..." thing) way too much...

     11 March 2000, 19:02 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Well sooh-ree :)

a) I didn't know ASM Guru was only Z80 (maybe it should be Z80 Guru then...)
b) I CERTAINLY didn't know TiCalc.org had nicked it from DimTI. So how was I to know they did?

And those "..." things... ellipses?

     11 March 2000, 21:44 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath

Wow. That's great... Using strings takes up a lot more space than using lists, which is what I usually do...

Also, kind of on topic, I submitted a feature a while ago about programming on calc, but it wasn't that informative, it mainly just said that it was possible... if anybody from ticalc sees this (actually, even if they don't) I'll probably submit a slightly more informative (meaning about 5 times as long, and 6-7 times more info) in a week or two...

     11 March 2000, 19:06 GMT

Re: Re: Feature: Two-Dimensional BASIC Scrolling
grinik  Account Info

What about programming on calc? You make it sound like something special. That's all I do since I don't have my computer to program on at school, which is where I do a lot of my programming.

     11 March 2000, 22:52 GMT

Re: Re: Feature: Two-Dimensional BASIC Scrolling
4_Of_11

they dont
each element in a string takes up 1 byte
each element in a list takes up 11 bytes(22 if complex)

while the display engine might be longer, strings are a much more efficient storage space.

the only draw back is it can conflict with other programs more because of the limited amount of strings.

     12 March 2000, 05:05 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Reno  Account Info

this would probably work better on the 86; it doesn't have a string limit (except the limit of 1-8, case-sensitive letter+number names you can come up with)

     12 March 2000, 16:28 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath

Okay... um, sorry everybody, I think I just kind of, um, stopped thinking when I wrote this... Here's what I meant:

Wow. That's great... Using strings takes up a lot *less* space than using lists, which is what I usually do...

Also, kind of on topic, I submitted a feature a while ago about programming *ASM* on calc, but it wasn't that informative, it mainly just said that it was possible... if anybody from ticalc sees this (actually, even if they don't) I'll probably submit a slightly more informative (meaning about 5 times as long, and 6-7 times more info) in a week or two...

     12 March 2000, 16:43 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Jeff Meister  Account Info

I never thought about writing an article about this, but...

From here on I'm assuming you were talking about a calculator that doesn't have an on-calc assembly compiler that some programming genius created for it. I'll use the 83, cuz I was messing with it one day and I learned a little about it.

You can't _really_ type in the assembly language we all know on-calc. But, you can, if you're crazy enough, type in hexadecimal.

A couple things I learned when messing with hex code:

CD means call.

C9 means ret.

When calling something, you put it after the CD, with the bytes swapped. If you ever looked at ASMGuru, in one of the first tutorials there was a program that did absolutely nothing but clear the screen. The author showed you a view of the program as if it were opened on-calc. It looked like this:

CD5547C9
End
0000
End

The End 0000 End stuff just means that it's an asm program. The CD means call, and C9 means ret, like I said earlier. But one day I was looking through ti83asm.inc, and I saw:

_clrLCDFull equ 4755h

So the 5547 in the program is the romcall _clrLCDFull, with the bytes swapped!

Of course no one is crazy enough to program an actual, useful asm program, on-calc, in hex code. But using this info, and exploring through it a bit more than I did, couldn't someone create a program that does all the hex dirty work for you, and you program with pre-defined romcalls? It would be just like an include file, except on-calc with a user-friendly program attached. Either that, or someone could just create a really really really huge printable include file-type document that pretty much tells you the hex code for every romcall and command you would ever use.

Ok, I think it's about time I shut up.

- Jeff

     12 March 2000, 20:14 GMT

Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
tassadar25 Account Info
(Web Page)

For the 86, there is an asm compiler called ASMIde86. It is just like computer assembly, and you can program asm on your calc, using the include files they provide. You can even put in your own equates into the include files.

P.S. Basmic and the people who created it (SiCoDe) suck horribly.

     12 March 2000, 20:57 GMT

Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

> P.S. Basmic and the people who created it (SiCoDe) suck horribly.

Heh. I remember you getting in touch with us to ask for our support of your "Hybridsoft". Good try, but you should really give evidence before throwing allegations like that...
SiCoDe are developing a universal graphics engine for hybrid basic. I wonder who'll come up with something useful first? Hybridsoft or SiCoDe....

- David Hall
SiCoDe Member

     12 March 2000, 22:51 GMT

Re: Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Reno  Account Info

<Virginian mentality takes over>
dem is fightin werds
</Virginian mentality gone>

bleh, I need to move back to California

     13 March 2000, 00:55 GMT


Re: Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
tassadar25 Account Info
(Web Page)

Believe me, we already got something really cool up our sleeves...we are a new group, just wait till we get organized and we will beat the crap out of you.

     15 March 2000, 14:15 GMT


Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Jeff Meister  Account Info

Exactly, this is what I wish there could be on the 83. That way I could program ASM in class. There's one of these on-calc compiler things for the 89 too right? I remember some news article about one...

Re: P.S. Don't make fun of SiCoDe... those programs are really advanced for BASIC (like the title thingy sez), just because they don't program in ASM doesn't mean they're not good. Think about it... if we all didn't reverse-engineer our calcs and hack assembly code, SiCoDe would be just like all the ASM game gods. They've taken a really crappy (sorry, but it is), limited, and incredibly basic language (it was even created to be easy to use), and made some really great stuff out of it. There's more to BASIC than it seems.
BASIC is only basic because of the people who program it, and these guys take it way beyond all the losers that give BASIC a bad name.

- Jeff

     12 March 2000, 23:31 GMT


Re: Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Thanks :)
Don't worry about him - he's just annoyed that we didn't want to work with Hybridsoft for various reasons.
- David Hall
SiCoDe Member

     13 March 2000, 19:20 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath

>But, you can, if you're crazy enough, type in hexadecimal.
<snip>
>Of course no one is crazy enough to program an
>actual, useful asm program, on-calc, in hex code.

<manianical laughing> You're WRONG! You're all WRONG! I'll show you!

:F3ED562100841101840100013682EDB0214E93
:118282010001EDB03E84ED47ED5E3E01326682
:C908D9
:FDCB1246207C
:3A0A80FE6A30103E74320A803E08D303
:3E01D303E1FB76
:3A6682B72850
:3EFFD3013EFDD301DB01FEFD200BFD
:CB125E28053E05326582
:3EFFD3013EF7D301DB01
:FEBF20053E01326582
:3A6582B7280A3D326582
:20053E0F320080
:3EFFD3013EFDD301DB01
:FEAB20143E00326682
:3EFDD301DB01FED520053E01326682
:C33A00
:End:0000:End

</manianical laughing>
I was sitting in front of the TV one night (yes, I admit it, I do watch TV occasionally), holding my calc (don't ask), and I remembered my friends had been bugging me to make a program to keep jerks at school from clearing their calc's memory. So I made this little program. Instructions:
1.Get the program to your calc
2.Type "send(9prgmNAME", the way to run ASM programs written like this.
3.Press [ln(].
4.Press 2nd-mem.
5.Press [Clear]
6.Press [log(]
7.Press 2nd-mem.
8.Repeat if desired.


>...someone could just create a really really really >huge printable include file-type document that pretty
>much tells you the hex code for every romcall and
>command you would ever use.

Actually, it wouldn't be that long.... I took ti83inc, TI's include file, dropped some of the OP calls, like OP5EXOP6 (I don't see the use in swapping OP5 and OP6, but I kept OP1EXOP2, and some of the others with the lower OP's), and it was only about a page long in size 5 courier new with .7 size line spacing in three columns, and it's a lot more legible than you might think.
And the hex codes for the commands themselves are longer, but there are several patterns that make it much easier. For example, if you assign the values
b = 0 or %000
c = 1 or %001
d = 2 or %010
e = 3 or %011
h = 4 or %100
l = 5 or %101
(hl) = 6 or %110
a = 7 or %111
"ld r,s" where r and s are any two registers becomes
$40+8r+s or %01rrrsss

Right there, you have 64 commands, all in one simple, easy to remember package. And that numbering systym for variables is used in almost every command that requires a register to operate on.

And, after writing several small programs, you will learn to remember many of the more common commands, so now I can generally write a program without any sort of table or anything.




Wow! That was long. Maybe I should just modify this a little, and send it to ticalc.org as that feature I was talking about.

     12 March 2000, 23:24 GMT

1  2  3  

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