Jump to content
IGNORED

Help with understand basic example


Recommended Posts

Hello,

 

Out of curiosity I wanted to see how oldschool Basic programming looked like. I don't understand in this example two things - why TOP is decreased by 4 - I know it lowers top of memory that is available for Basic program but why 4 - what measurement is this. And another thing why some peeks and pokes are multiplied  by 256 and in 170 line it's divided by 256.

 

90 REM * REDEFINE $ CHARACTER
100 TOP=PEEK(106)-4
110 POKE 106,TOP
120 GRAPHICS 0
130 CHARGO=TOP*256
132 CHARFROM=PEEK(756)*256
135 PRINT "Moving the character set. Hold on •• "
140 FOR PLACE=0 TO 1023
150 POKE CHARGO+PLACE,PEEK(CHARFROM+PLACE)
160 NEXT PLACE
170 POKE 756,CHARG0/256
180 FOR 1=0 TO 7
182 READ A:POKE CHARGO+I+(4*8),A
184 NEXT I
186 PRINT "OUR NEW CHARACTER .•.•.••. "
188 PRINT "$ $ $ $ $ $"
190 PRINT "NOT BAD!"
192 END
200 DATA 0,0,126,66,90,66,126,0 

 

Link to comment
Share on other sites

13 minutes ago, Materion said:

Hello,

 

Out of curiosity I wanted to see how oldschool Basic programming looked like. I don't understand in this example two things - why TOP is decreased by 4 - I know it lowers top of memory that is available for Basic program but why 4 - what measurement is this. And another thing why some peeks and pokes are multiplied  by 256 and in 170 line it's divided by 256.

 


90 REM * REDEFINE $ CHARACTER
100 TOP=PEEK(106)-4
110 POKE 106,TOP
120 GRAPHICS 0
130 CHARGO=TOP*256
132 CHARFROM=PEEK(756)*256
135 PRINT "Moving the character set. Hold on •• "
140 FOR PLACE=0 TO 1023
150 POKE CHARGO+PLACE,PEEK(CHARFROM+PLACE)
160 NEXT PLACE
170 POKE 756,CHARG0/256
180 FOR 1=0 TO 7
182 READ A:POKE CHARGO+I+(4*8),A
184 NEXT I
186 PRINT "OUR NEW CHARACTER .•.•.••. "
188 PRINT "$ $ $ $ $ $"
190 PRINT "NOT BAD!"
192 END
200 DATA 0,0,126,66,90,66,126,0 

 

 

They a moving memory down 4 pages (256 bytes) so 1 KB. Which is also the size of a character set.

 

So it looks like it makes room for a new character set, by moving the TOP down 4 pages.  And then copies the current character set in the new area and the replaces one of the characters. From the context is looks like it replaces the '$'.

 

Edited by Gibstov
typo
  • Like 2
Link to comment
Share on other sites

To add a little complication to Gibstov's explanation :)

 

Pointers in memory can use either 2 bytes or 1 byte.  Using 2 bytes gives precision but requires an extra memory (valuable stuff in 8 bit computers) .

 

2 byte pointers using a 6502 cpu use little endian, which means the first byte is the least significant byte, aka LSB or LO byte (akin to units in decimal) and the 2nd byte is the most significant, aka MSB or HI byte (akin to the tens column in decimal).

 

This means in order to get a 16bit number we take 2 bytes, multiply the 2nd byte by 256 then add the first.  In basic this generally looks like:

 

a=peek(88)+peek(89)*256

 

If this was the decimal 26 it would be like:

 

a=6+2*10

 

With a single byte storing the decimal 0-255 then using LSB+MSB*256 we can get a number range between 0-65535.

 

 

Some pointers, like the one pointing to the character set (location 756), only use a single byte.  Because of this they can only point to the start of a page of memory, which is a 256 byte block of memory.

 

As for line 170.  He does CHARG0/256 but earlier in the code he did CHARG0=TOP*256, so he could have just used TOP instead of CHARG0/256.  Either way he's drop the top of memory down by 4 pages (1024 bytes or 1k) which means the OS won't touch it and he can safetly store some data there eg. a character set.

 

I hope this is understandable, and not just the ramblings of an old man 4 ciders into an 80s playlist.

 

 

 

  • Like 2
Link to comment
Share on other sites

Thanks @Preppie for easy explanation now I get it ;). So value under TOP=PEEK(106) is number of page that top of memory is ? As we subtract 4 of it (what means 4 pages 256 bytes each) so it stores page number of top of memory? Geeez, learning to program even in Basic is hard xD. Would be great if discord about Atari programming exist. Would be much easier to quick ask some noob questions instead of spamming on this forum :D.

Edited by Materion
Link to comment
Share on other sites

Yeah, location 106 points to the top of memory.  The OS can use memory up to the the top.  So if you want to some safe space to store data you can bring the top of memory down by poking a smaller number into 106 and the OS will ignore that part of memory.

 

TOP memory is usualy brought down in chunks of 1k (4pages, top-4) because some some data such as characters sets or PM graphics need to start at 1k boundries or you get some weird results.

Link to comment
Share on other sites

16 minutes ago, Preppie said:

PM graphics need to start at 1k boundries or you get some weird results.

For single line resolution PM graphics it needs to be on a 2K boundary, strangely I was just looking at a program I wrote

way back, I found some code that didn't seem to make sense, I set up PM graphics on a 2K boundary, then used the same

page to open a Graphic 0 screen, I ran the code and it seemed to work, then I realised the first 768 bytes of PM are not

used and I wasn't using Missiles, so 1024 bytes free, plenty for Graphics 0 and it's DL to sit in.

 

Must admit I'm actually starting to get impressed with some of the code in this program :) wish I could remember what

I was on when I wrote it.?

  • Haha 1
Link to comment
Share on other sites



106              6A              RAMTOP

     RAM size, defined by powerup as passed from TRAMSZ (location
     6), given in the total number of available pages (one page equals
     256 bytes, so PEEK(106) * 256 will tell you where the Atari thinks
     the last usable address --byte-- of RAM is). MEMIOP (741,
     742; $2E5. $2E6) may not extend below this value. In a 48K Atari,
     RAMTOP is initialized to 160 ($A0), which points to location
     40960 ($A000). The user's highest address will be one byte less
     than this value.

 

From https://www.atariarchives.org/mapping/memorymap.php#106

Lots of other stuff in there to look up if you wonder about peeks and pokes.

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