Frankie Posted April 4, 2011 Share Posted April 4, 2011 I have just recently come back to some of my basic programs I did on my Atari a lifetime ago. Is there a faster way to initialize an array? I have a double indexed array that holds integers. map(36,36). Right now I initialize it with a nested for loop. It takes forever! Does anyone know of a site that might have useful machine-language routines I could use for stuff like this? My 6502 is really rusty.. Frank Quote Link to comment Share on other sites More sharing options...
Rybags Posted April 4, 2011 Share Posted April 4, 2011 Kind of a bummer that even numeric arrays don't get initialized. This might work. Put in a subroutine that's called right at the start of the program before anything else is declared, since it needs to do the CLR to free up the memory again: 1000 F=FRE(0)-400:DIM Z$(F):F$(1)=CHR$(0):F$(F-1,F-1)=" " 1010 F$(2)=F$:CLR:RETURN That uses the "fill string" technique to initialize most of the free RAM to zeros. That should translate to zero values once you go ahead and DIM your numeric arrays. Quote Link to comment Share on other sites More sharing options...
popmilo Posted April 4, 2011 Share Posted April 4, 2011 (edited) I have just recently come back to some of my basic programs I did on my Atari a lifetime ago. Is there a faster way to initialize an array? I have a double indexed array that holds integers. map(36,36). Right now I initialize it with a nested for loop. It takes forever! Does anyone know of a site that might have useful machine-language routines I could use for stuff like this? My 6502 is really rusty.. Frank What if you would change from numeric values to strings ? Something like: Initialize big string: DIM MAP$(36*36) FOR I=0 TO 35 MAP$(36*I+1,36*I+1+35)="000000000000000000000000000000000000" NEXT I Atari's string arrays work differently than in other basics so you would have to use STRING$(beginning_index,end_index) format. Since you need only one byte (I guess ?), when you want a value from X,Y: I=Y*36+X+1 C$=MAP$(I,I) If you need a numeric value just use ASC(MAP$(I,I)) ps. I almost always used this method for maps in basic. That way you could just build map as strings in DATA statements and see on screen how the map looks. Basically, you get a free map editor DATA "00000000000000" DATA "0 0" DATA "0 O O 0" DATA "0 0" DATA "0 . . 0" DATA "0 -- 0" DATA "0 0" DATA "00000000000000" Edited April 4, 2011 by popmilo Quote Link to comment Share on other sites More sharing options...
Rybags Posted April 4, 2011 Share Posted April 4, 2011 Strings can only have 1 dimension. Plus you have the limitation of only 8 bit values per element. But still, much less memory hungry than numeric arrays. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted April 4, 2011 Share Posted April 4, 2011 (edited) A dirty workaround is to clear display list execution with POKE 559,0, and turning it back on with POKE 559,34. That will speed up initialization by as much as a third. Edited April 4, 2011 by Nukey Shay Quote Link to comment Share on other sites More sharing options...
Rybags Posted April 4, 2011 Share Posted April 4, 2011 Using the string-clear method, speed becomes a non-issue. BASIC itself will initialize 20,000 bytes in a fraction of a second. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted April 4, 2011 Share Posted April 4, 2011 The mention of a nested FOR-NEXT loop leads me to believe that not all elements are zero for his purpose, tho. The speedy string clear exploit is useful for repeating data tho, yeah. BTW CHR$(0) is a heart, not a space. Quote Link to comment Share on other sites More sharing options...
Frankie Posted April 4, 2011 Author Share Posted April 4, 2011 Kind of a bummer that even numeric arrays don't get initialized. This might work. Put in a subroutine that's called right at the start of the program before anything else is declared, since it needs to do the CLR to free up the memory again: 1000 F=FRE(0)-400:DIM Z$(F):F$(1)=CHR$(0):F$(F-1,F-1)=" " 1010 F$(2)=F$:CLR:RETURN That uses the "fill string" technique to initialize most of the free RAM to zeros. That should translate to zero values once you go ahead and DIM your numeric arrays. Thanks! This worked great. (p.s. you switched from Z$ to F$, but I got the idea) Quote Link to comment Share on other sites More sharing options...
Rybags Posted April 4, 2011 Share Posted April 4, 2011 Cool. The last character @ (F-1,F-1) isn't important since it gets wiped anyway. You just need to do that to establish the length of the string otherwise the fill doesn't complete. Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted April 8, 2011 Share Posted April 8, 2011 You could take the plunge and run your existing programs under Turbo Basic - I used it for my last game Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.