Jump to content
IGNORED

Basic help


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by popmilo
Link to comment
Share on other sites

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)

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...