Hello, Guest the thread was called226 times and contains 2 replays

last post from Snoopy at the

BASIC 10 - Use of various banks for variables

  • Tonight I'd played again a little bit with the possibilities of BASIC 10 (C65 mode). This time I'd focused on the usage of various banks for the BASIC 10 variables. :search:

    Normally the variables are stored in bank 1 while the BASIC 10 text is stored in bank 0 (starts at $2000):

    (just a quick drawing from me)

    But I have found an address to tell the C65/MEGA65 to use another bank for the variables instead of bank 1. It's address $85 (133 dec) in C65 mode (named "var_bank" at page 3 of the current version (2020/11/09) of the "C65 memory map"). And I wanted to see how and if it works.

    Let us start:

    PRINT PEEK(133) shows you the current (and default) value "1" for the var_bank.

    With POKE 133,4 you tell BASIC 10 that it should use bank 4 for the variables from now on.

    Let us define a test variable, e.g. A$ = "TEST - BANK 4" and show it with PRINT A$. Okay, you will see: TEST - BANK 4. :)

    Now switch back to bank 1 for var use with POKE 133,1 and let us see the variable with PRINT A$. And you get ... an empty string.

    With the use of the build-in monitor we can search for the stored value of A$ in bank 4:

    MONITOR and then H 40000 4FFFF 'TEST (search in complete bank 4 for the entry "TEST*").

    It's found at address $7FF1 of bank 4:

    If you had switch to bank 1 with POKE 133,1 you can define also a string A$, e.g. A$ = "TEST - BANK 1". If you now print the string you get a result which depends on the selected var_bank:

    I wrote a simple BASIC 10 demo program to demonstrate the various bank use with bank 1, 4 and 5:

    Here's a quick draw to demonstrate the relationship between the value of address $85 (133 dec) and the various bank use for the variables:

    Attention: :achtung

    Be aware that a var_bank switch applies to all current used BASIC 10 variables. This means that you can't access a variable in e.g. bank 4 while having switched to bank 1. E.g.: Variable A$ in bank 1 is a different one than A$ in bank 4, although it has the same name! You always have to switch to the "right" bank in which your wanted variable is stored before you can access it.

    I have tested it (with version "911001" of the C65 ROM) with the Xemu emulator (xmega65) and with the Nexys board, so I suppose it also works with the DevKit or a MEGA65 prototype.

    I have attached the demo program as a zipped D81 image, if you want to play around for yourself. :loet

  • This is very interesting., So you can store the variables in a different bank than your main Basic PRG.

    Hmm....is it possible to hand-over the content of a variable from one bank to another ?

    i.e. If A$ in Bank 1 = "AAA" then A$ in Bank 2 ="AAA"...

    or completely different stuff like:

    10 poke 133,2 : A$ ="too young"

    20 poke 133,3 : A$="old enough"

    30 input "How old are you";x

    40 if x < 18 then a =2

    50 if x > 18 then a =3

    60 poke 133,a .Print A$ : goto 30

    does this also works with DIM ? i.e. A$(10) ? Hmmm need to test it.

    Thanks Snoopy nice find !!!

  • This will work, if you use bank 4 and 5 instead of 2 and 3. Bank 2 and 3 are used as ROM, so you can't write into it.

    You have to be very careful, because the bank switch apllies really all current used variables.

    This example wouldn't work:

    It starts with the (default) variables in bank 1. Line 20 should change the bank to 4 if "I" is greater than 5.

    After switching to bank 4 the program doesn't know the variable "I" anymore and so the "NEXT" command in line 40 produces an error "?NEXT WITHOUT FOR ERROR".

    You have to work with it in a very disciplined manner for not losing important variables into a "wrong" bank! ;)