Does the basic interpreter eat up my bytes?

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
aitsch
Vic 20 Amateur
Posts: 51
Joined: Sun Mar 08, 2020 12:54 pm
Location: Germany NS

Does the basic interpreter eat up my bytes?

Post by aitsch »

for a basic project i move the character memory to $1c00 and place my 8 custom character directly behind the screen (7680 - 64).
the basic code can have all bytes before my 8 characters.

for a while the programm runs ok but after a while my characters are changing step by step.
there is no POKE command which could change the memory and the program always pass through the same basic lines.
after the unwanted character change i stopped the code and run "PRINT FRE(I)". it prints out nearly 200 bytes of free memory so my understanding is, there is enough free memory for variables and buffering and ... .
i cannot find any reason of this behavior in my code so i suspect the basic interpreter use the last bytes downwards for whatever.

i'm not really a basic expert. can i prevent this changes or do i pass the limit?
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Does the basic interpreter eat up my bytes?

Post by Mike »

This is the string heap growing from top of memory which overwrites your (currently unprotected) character data.

I'm sorry, but this is really basic (in the actual sense of fundamental, not the language's name errorneously written in lower case) knowledge when you go about redefining characters!

With POKE55,...:POKE56,...:CLR as first commands in your BASIC program you can protect a portion of RAM from use by the BASIC interpreter.

Edit: On the unexpanded VIC-20, the default values for 55/56 are 0 and 30, respectively, with the screen at $1E00. Normally, user defined characters are placed before the screen, somewhere in the range 7168..7679 (i.e. $1C00..$1DFF), and 55/56 are defined so both screen and UDGs are protected. Is there any specific reason you move the screen to $1C00?


BTW, if you see anything in other programs that also changes ZP addresses 51 and 52 along with 55 and 56, this is a fine example of cargo-cult programming. 51 and 52 are internal pointers into the string heap and are already taken care of by the CLR command.
User avatar
beamrider
Vic 20 Scientist
Posts: 1452
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Does the basic interpreter eat up my bytes?

Post by beamrider »

Mike wrote: Fri Jan 21, 2022 9:54 am .............this is a fine example of cargo-cult programming. 51 and 52 are.................
Learn something new every day.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Does the basic interpreter eat up my bytes?

Post by Mike »

beamrider wrote:Learn something new every day.
About the 'concept' of cargo-cult programming? A quick peek into Wikipedia should sort this out. ;)

Just POKEing to 55/56 without CLR does not suffice. In that case the internal work pointers to the bottom of the string heap at 51/52 are not notified of the change in 55/56 and the strings will continue to eat into the user defined graphics. What is peculiar about this is, this behaviour only occurs upon the first run of the program that changed 55/56! Afterwards, everything works as expected! Subsequent RUN commands correct 51/52 to be in line with 55/56 as CLR is a side effect of their action.

People then probably found by chance that POKEing 51/52 to the same values as 55/56 had the desired effect to inhibit the overwriting of character data even upon the first run of the program, but did not fully understand why.

I found dozens of examples of this in type-in programs, sometimes even with one or two extra bytes reserved (i.e. POKE55,254:POKE56,27:POKE51,254:POKE52,27 at worst). 55/56 actually point to the first address not used by the BASIC interpreter. The default PEEK(55)=0, PEEK(56)=30 for unexpanded (or +3K) protects the screen at 7680 - and 30*256 is 7680!

Now, instead of copying the values of 55/56 into 51/52, a simple CLR after the POKEs to 55/56 does quite the same job. It reliably protects the RAM for those user defined graphics even on the first run of the program. In my type-in collection I went into some lengths to correct all those wrong and/or redundant POKEs.

At last, sometimes you find programs that do a POKE56,... and CLR but no POKE55,... . That again is no good idea: the value in 55 is not necessarily 0 even after power-on! Just mount the Super Expander cartridge for a counter example.
User avatar
aitsch
Vic 20 Amateur
Posts: 51
Joined: Sun Mar 08, 2020 12:54 pm
Location: Germany NS

Re: Does the basic interpreter eat up my bytes?

Post by aitsch »

Hi Mike,

thanks for your help.
Mike wrote: Fri Jan 21, 2022 9:54 am ...
I'm sorry, but this is really basic (in the actual sense of fundamental, not the language's name errorneously written in lower case) knowledge when you go about redefining characters!
...
I'm also sorry about my fundamental knowledge basic gaps but that is the reason why i ask here :roll: .

let me explain:

i got my first computer (the vic-20 aka vc-20) when i was 12 in 1985. my biggest wish was to program games but i had no like minded person for programming or computer technics. i had to figure out all by myself. i had no clue about bytes, computer chips, memory management, zeropage, the kernel etc. and much of this is unfortunately still the case today.
all my friends are only interested in collecting and playing games. i learned basic with the enclosed vic-20 compendium and some magazines i had no additional books or sources. one or two years later i swapped to the c64. here i "learned" to change the character set. i not really leared why the code changes the character set. i copied the code lines from my "tips and tricks"-book and defined my own characters and the rest of the code. these programs were probably not large enough that it was necessary to relocate the storage end.

at the end of the 80ties i stopped all my commodore activities. So my basic knowledge is insufficient and nearly 35 years old.

in 2019 i've started to learn 6502 assembly and joined back in the commodore community. the most i know about commodore computers today i've leared the last 2-3 years (and a lot i learned from you). but i have to share my free time with family, friends and my routine duties.

if someone like you had lived in the neighborhood back then, maybe everything would be different today.

so please understand that i am asking this kind of questions here :wink:

(In diesem Sinne: Ich werde dir auch zukünftig noch mächtig auf die Nerven gehen :twisted: )
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Does the basic interpreter eat up my bytes?

Post by Mike »

aitsch wrote:let me explain: [...] i got my first computer (the vic-20 aka vc-20) when i was 12 in 1985. [...] at the end of the 80ties i stopped all my commodore activities. So my basic knowledge is insufficient and nearly 35 years old.
Actually our background is not that dissimilar.

I got my (also) VC-20 as Xmas present in 1983 when I was 11, with no prior programming knowledge. Until 1991, when I progressed through the C116 and C128, I had learned BASIC and 6502 machine language but also had my first exposure to PCs. In 1991, I continued my programming activities on the Acorn Archimedes series.

However, around 1993 I also was quite lucky to have a mentor who taught me important things about programming if I ever was to pursue a career in that field (design and documentation of programs, in particular). He was quite exact and to the point when something I discussed with him was not quite up to his standards, so to speak. Maybe something of this shines through when people ask about things here I think is common knowledge, or at least has been discussed here not too long ago, see here: viewtopic.php?t=10252&start=2&hilit=UDG* (from November last year).
in 2019 i've started to learn 6502 assembly and joined back in the commodore community. the most i know about commodore computers today i've leared the last 2-3 years (and a lot i learned from you).
Maybe that's the biggest difference: around 2003 PCs just had become fast enough to make emulation a feasible thing and so my interest in the VIC-20 was revived. And then, in 2004, I joined Denial and have been a regular since then ...
but i have to share my free time with family, friends and my routine duties.
... as my spare time allows. Even if some people here think otherwise. ;)
(In diesem Sinne: Ich werde dir auch zukünftig noch mächtig auf die Nerven gehen :twisted: )
Auf ein Bier! :D

Du hast PN.
Post Reply