Various programming tricks for the vic-20.

This is a compilation of various programming tricks, many originally posted on the vic-20 forum 'Denial'. Most of them comes from the Disk util cartridge project.

Get address of Basic string from Machine Language

(Tip by Björg Stojalowski)

How to get the address of a basic string and use this address from ML to tranfer data between Basic and ML:

From Basic:

  SYS R,A$

Your ML code at address "R":

  jsr $CEFD  ;CHKCOM
  jsr $CD9E  ;FRMEVL
  jsr $D6A3  ;GETSTR - Pointer to string in $22/$23
 (pha        ;StrLen in A)
Another way to do similar things is posted by Anders Carlsson here.

A good thing to know is that a string either is located in the string memory area or in the program itself. For example:

0 A$="HELLO" : REM This string uses the program's memory. If you change it from ML, then the program itself will be changed.

1 A$=A$+" THERE" : REM Now the string has been modified and will after this have it's own memory.

So if you just want to transfer stuff from ML to Basic and not the other way around, then here is a third way (my own tip): You could start your program with for example 0 A$="spacespacespace". Then look at the basic start address (43/44). Add a few bytes, and then store your data there from ML and you will have it in A$ in Basic.

Start a basic program from ML

(Tip by Anders Carlsson)

$C533: Rebuild Basic text link pointers (tip by Daniel Kahlin). This would rarely be used unless you are moving a Basic program within memory.
$C659: Reset execution to start of program and perform CLR (set pointers to variables).
$C7AE: Handle next Basic statement from current position. Not really the entry point for RUN ($C871), but it works..

Storing non-basic data at the end of a basic program

(My own tip)

If you have a ML routine or something else you want to store together with your basic program, then here is a neat way of doing it.

  • Load your basic program.
  • Look at the program end position (45,46)
  • Put your data at this position (with a monitor for example)
  • Save the whole thing from $1001 (or $1201) to the end of your extra data.
  • Exit the monitor and reload the file you just saved ,8

    Now to the neat thing. After this you can do any normal basic editing to the program (add, remove lines, edit, run, save etc) and the extra data will still be there and safe! It's start position will move, but that's all. So to access the data from basic, look at pos (45,46) which now is the end of the extra data, and then subtract the lengt of the data and you will get it's start pos.

    The data could for example be a relocatable ML routine. To do that, just don't use any direct addresses to things inside the routine. For example, instead of JMP, use CLC followed by BCC.

    The only thing I have come across that destroys the data (removes it) is Programmer's Aid's FIND command. But RENUMBER works fine!!!

    I used this technique in my Vic Menu program.

    LOCATE

    (Tip by Leif Bloomquist)

    On modern basic languages, you can use the LOCATE command to place the cursor somewhere on the screen. CBM Basic V2 only has TAB() and SPC() that can move the cursor sideways. But how do you put the cursor on a specific row? This is how:

    POKE 214,R:PRINT

    That's it. The extra print is needed for the trick to work, so you use it for example like this:
    POKE214,10:PRINT:PRINTSPC(8);"HELLO"

    Your trick?

    If you have another nice trick, then please post it on the vic-20 forum 'Denial' in the programming section. The more people who knows these tricks - the more new vic-20 programs are you likely to get!!!

    Good luck!

    Anders Persson
    http://www.boray.se


    Back