Jump to content
IGNORED

PROGRAM size optimization


Opry99er

Recommended Posts

In TI BASIC, would the following examples take up the same space?

 

10000 DATA 32,90,50,300,21,3,5,"CHICKEN"

 

And

 

10000 DATA 32,90,50

10010 DATA 300,21,3,5

10020 "CHICKEN"

 

I am working on a new TI BASIC game and I am initializing level data and game instructions via DATA statements. Currently I am using RESTORE statements to get to the various DATA lines needed by each segment of the game code, but I could eliminate a bunch of RESTORE statements if I organized my DATA differently.

 

I am not hurting for program space right now, but I am not done. Currently I am at 4.4K.

 

How much space, theoretically, would it save to eliminate multiple DATA lines and RESTOREs?

 

I am just not sure how BASIC accepts these statements internally.

Link to comment
Share on other sites

You'll save the memory on the line numbers + the memory for the tokens for the DATA statement. Also, "CHICKEN" needs a DATA statement in the initial code.

 

I did some indexing in Bloxo-TI-z for the level skip feature I had built in. I don't remember what specifically I did, but it was reasonably fast such that it didn't bother me....

Link to comment
Share on other sites

In TI BASIC, would the following examples take up the same space?

 

10000 DATA 32,90,50,300,21,3,5,"CHICKEN"

 

And

 

10000 DATA 32,90,50

10010 DATA 300,21,3,5

10020 "CHICKEN"

 

I am working on a new TI BASIC game and I am initializing level data and game instructions via DATA statements. Currently I am using RESTORE statements to get to the various DATA lines needed by each segment of the game code, but I could eliminate a bunch of RESTORE statements if I organized my DATA differently.

 

I am not hurting for program space right now, but I am not done. Currently I am at 4.4K.

 

How much space, theoretically, would it save to eliminate multiple DATA lines and RESTOREs?

 

I am just not sure how BASIC accepts these statements internally.

I don't really know how TI BASIC would do this but on Microsoft BASIC...

 

This would require 16 bits for the line number (2 bytes), 1 byte for the token representing DATA, and the rest would be stored as ASCII or 30 bytes and I can't remember if there is a zero terminating the line or a line length for 1 more byte?

10000 DATA 32,90,50,300,21,3,5,"CHICKEN"

 

This would require 16 bits * 3 for the line numbers (6 bytes), You are missing a DATA statement before "CHICKEN" so should require 3 bytes for the tokens for DATA, and the rest of the characters are stored as ASCII so 30 more bytes. Then you have the line length or line terminator for each line which are each probably a byte so + 3 bytes.

10000 DATA 32,90,50

10010 DATA 300,21,3,5

10020 "CHICKEN"

  • Like 1
Link to comment
Share on other sites

NEW
10000 DATA 32,90,50,300,21,3,5,"CHICKEN"

8330: Pointer to start line list

37A6: 27 10 37 AB 2D 93 C8 02 '.7.-...
37AE: 33 32 B3 C8 02 39 30 B3 32...90.
37B6: C8 02 35 30 B3 C8 03 33 ..50...3
37BE: 30 30 B3 C8 02 32 31 B3 00...21.
37C6: C8 01 33 B3 C8 01 35 B3 ..3...5.
37CE: C7 07 43 48 49 43 4B 45 ..CHICKE
37D6: 4E 00 AA 3F FF 11 03 00 N..?....

27 10 = The line number itself (10000)
37 AB = Pointer to start of program line
2D = Length of program line
93 = DATA
C8 = String
02 = Length of string
33 32 = 32
B3 = ,
C8 = String
02 = Length of string
etc.
C7 = String in quotes
07 = Length
43 48 49 43 4B 45 4E = CHICKEN
00 = End of string

It takes 50 bytes.

NEW
10000 DATA 32,90,50
10010 DATA 300,21,3,5
10020 "CHICKEN"

8330: Pointer to start line list

379B: 27 24 37 A8 27 1A 37 B3 '$7.'.7.
37A3: 27 10 37 C8 0A C7 07 43 '.7....C
37AB: 48 49 43 4B 45 4E 00 14 HICKEN..
37B3: 93 C8 03 33 30 30 B3 C8 ...300..
37BB: 02 32 31 B3 C8 01 33 B3 .21...3.
37C3: C8 01 35 00 10 93 C8 02 ..5.....
37CB: 33 32 B3 C8 02 39 30 B3 32...90.
37D3: C8 02 35 30 00 AA 3F FF ..50..?.

27 24 = The line number itself (10020)
37 A8 = Pointer to start of program line
27 1A = The line number itself (10010)
37 B3 = Pointer to start of program line
27 10 = The line number itself (10000)
37 C8 = Pointer to start of program line
0A = Length of program line
C7 = String in quotes <<< Should have the DATA statement in front as mentioned
07 = Length
43 48 49 43 4B 45 4E = CHICKEN
00 = End of string
14 = Length of program line
93 = DATA
C8 = String
03 = Length of string
33 30 30 = 300
B3 = ,
C8 = String
02 = Length of string
etc.

It takes 61 bytes.
Link to comment
Share on other sites

Ah, the next line pointers. I'd forgotten about that. Even Microsoft BASIC has that. I'd need to look to see if it uses anything else.

<edit>
35 for the first one and 38 for the 2nd in Microsoft BASIC.
Lines are terminated with a zero and the pointer to the next line is the first thing stored for each line.
So...
Pointer to next line

line number

tokenized line data (just ASCII after then DATA token).

zero terminator

Edited by JamesD
  • Like 1
Link to comment
Share on other sites

Wikipedia says that TI Basic was developed under contract to Microsoft by Bob Wallace and Bob Greenberg. And since TI Basic is written in GPL, then Microsoft had to know a thing or two about GPL. GPL resembles Assembly so I think it's not out of the question that early intentions may have been a CPU upfront or later that would run GPL directly. But wouldn't that rule out the cheap, slow and proprietary GROM ? Was GROM actually cheap with the extra auto-incremental fetching ?

 

:)

Edited by sometimes99er
Link to comment
Share on other sites

go to http://nivelleringslikaren.eu/ti994a_basic/

 

check debug upload/download

 

enter your test data line. click download. you will now see how the line is tokenized.

 

for each line number you save, you save 6 bytes.

2 line nr

2 ptr to line data

1 length of line data

1 zero at end of line data

 

the DATA token is replaced with a comma, so no savings there.

Edited by Fredrik Öhrström
  • Like 1
Link to comment
Share on other sites

 

NEW
10000 DATA 32,90,50,300,21,3,5,"CHICKEN"

8330: Pointer to start line list

37A6: 27 10 37 AB 2D 93 C8 02 '.7.-...
37AE: 33 32 B3 C8 02 39 30 B3 32...90.
37B6: C8 02 35 30 B3 C8 03 33 ..50...3
37BE: 30 30 B3 C8 02 32 31 B3 00...21.
37C6: C8 01 33 B3 C8 01 35 B3 ..3...5.
37CE: C7 07 43 48 49 43 4B 45 ..CHICKE
37D6: 4E 00 AA 3F FF 11 03 00 N..?....

27 10 = The line number itself (10000)
37 AB = Pointer to start of program line
2D    = Length of program line
93    = DATA
C8    = String
02    = Length of string
33 32 = 32
B3    = ,
C8    = String
02    = Length of string
etc.
C7    = String in quotes
07    = Length
43 48 49 43 4B 45 4E = CHICKEN
00    = End of string

It takes 50 bytes.

NEW
10000 DATA 32,90,50
10010 DATA 300,21,3,5
10020 "CHICKEN"

8330: Pointer to start line list

379B: 27 24 37 A8 27 1A 37 B3 '$7.'.7.
37A3: 27 10 37 C8 0A C7 07 43 '.7....C
37AB: 48 49 43 4B 45 4E 00 14 HICKEN..
37B3: 93 C8 03 33 30 30 B3 C8 ...300..
37BB: 02 32 31 B3 C8 01 33 B3 .21...3.
37C3: C8 01 35 00 10 93 C8 02 ..5.....
37CB: 33 32 B3 C8 02 39 30 B3 32...90.
37D3: C8 02 35 30 00 AA 3F FF ..50..?.

27 24 = The line number itself (10020)
37 A8 = Pointer to start of program line
27 1A = The line number itself (10010)
37 B3 = Pointer to start of program line
27 10 = The line number itself (10000)
37 C8 = Pointer to start of program line
0A    = Length of program line
C7    = String in quotes <<< Should have the DATA statement in front as mentioned
07    = Length
43 48 49 43 4B 45 4E = CHICKEN
00    = End of string
14    = Length of program line
93    = DATA
C8    = String
03    = Length of string
33 30 30 = 300
B3    = ,
C8    = String
02    = Length of string
etc.

It takes 61 bytes.

 

That is precisely what I was looking for, THANKS!!!

 

Of course the code I posted was BS, just example filler.... The program I am working with has significantly more lines of DATA, so restructuring should be a priority before I get any deeper.

 

BTW, this program I am working on may very well be the greatest single piece of software ever written on any platform across the entire history of computing.

 

:lol:

  • Like 1
Link to comment
Share on other sites

Wikipedia says that TI Basic was developed under contract to Microsoft by Bob Wallace and Bob Greenberg. And since TI Basic is written in GPL, then Microsoft had to know a thing or two about GPL. GPL resembles Assembly so I think it's not out of the question that early intentions may have been a CPU upfront or later that would run GPL directly. But wouldn't that rule out the cheap, slow and proprietary GROM ? Was GROM actually cheap with the extra auto-incremental fetching ?

 

:)

 

Nobody seems to know for certain, but Microsoft was well known for developing many of their programs on emulators that they wrote before even seeing the hardware. The nature of GPL would make it really hard for silicon to execute it, as such I'm personally convinced that Microsoft may have written or at least designed GPL just to have an abstraction for a machine that was undergoing major design revisions so they could finish their contract on time.

 

I'd love to know the official word though. :)

  • Like 3
Link to comment
Share on other sites

go to http://nivelleringslikaren.eu/ti994a_basic/

 

check debug upload/download

 

enter your test data line. click download. you will now see how the line is tokenized.

 

for each line number you save, you save 6 bytes.

2 line nr

2 ptr to line data

1 length of line data

1 zero at end of line data

 

the DATA token is replaced with a comma, so no savings there.

 

 

 

 

Say, is this website a legitimate way to load BASIC programs via the cassette port?? It sure seems to be. Somehow I had not heard of this.

 

It is really quite fascinating. :) I am going to try it out once I get the appropriate cable. :)

Link to comment
Share on other sites

^^wow, it is so much more!!! What a cool tool!

 

I could not get the download to work as you suggested, but this tool gives me many many ideas.... I do not understand everything it does, but I can tell an incredible amount of care and work went into it.

 

I look forward to exploring it more in the upcoming days.

Link to comment
Share on other sites

Thanks! :-D I re-implemented a basic to binary tokenizer by trial and error. The TI does the ascii to tokens conversion completely different of course, but it seems to give the same result on all my test cases. You can download a source archive, look under ABOUT. Its basic.php in the archive that does it.

 

The TI tokenizer has a line length limit due to the crunch buffer. Nu such limit exists here, in fact you can create very very long DATA lines for TI-basic, much longer than 255 bytes, because the TI interpreter does not care about the line length byte, it only looks at the zero terminator byte.

 

 

 

^^wow, it is so much more!!! What a cool tool!

I could not get the download to work as you suggested, but this tool gives me many many ideas.... I do not understand everything it does, but I can tell an incredible amount of care and work went into it.

I look forward to exploring it more in the upcoming days.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...