Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C64 BASIC V2 extensions?

277 views
Skip to first unread message

Harry Potter

unread,
Dec 5, 2013, 10:23:14 AM12/5/13
to
I am thinking about using cc65 to extend the c64's BASIC. It would be nearly impossible to do this in C, so I'll use assembler macros and labels instead. At the very least, I need information on the C64 BASIC ROM and the kernel start-up process. Any links?

ep...@juno.com

unread,
Dec 5, 2013, 11:40:13 AM12/5/13
to
On Thursday, December 5, 2013 10:23:14 AM UTC-5, Harry Potter wrote:
> I am thinking about using cc65 to extend the c64's BASIC. It would be nearly impossible to do this in C, so I'll use assembler macros and labels instead. At the very least, I need information on the C64 BASIC ROM and the kernel start-up process. Any links?

I know of two main ways to extend interpreted MS-Basic for the 65xx family. One is to CALL (or SYS on CBM) a ML routine at a known address. This routine then uses internal ROM routines. To look at the tokenized text in the code stream following the CALL (or SYS).
I don't remember if the Vic-20 or C-64 has a LINE INPUT routine. The problem with INPUT X$ is that the read terminates with a comma in the input text. Once the ML routine is installed, you would use it with a SYS address,X$. The routine would look
something like this (sorry, the symbol names are Apple 2).

JSR CHKCOM
JSR PRTRGET
move some registers to zero page
JSR INLIN
some more register stuff
JSR SAVED
...
RTS

In order to understand what is going you have to understand that MS-Basic has something called a TXTPTR (text pointer) that points to what BASIC is currently trying to interpret. CHKCOM makes sure that TXTPRT is pointing to a comma, else syntax error. PRTGET fetches a pointer to the memory used by variable X$. INLIN reads data into the input buffer. SAVED converts that off to a string variable. (and lots of other internal stuff...)

A more primitive way is to hook a lower level routine in BASIC called CHRGET. This routine is what BASIC uses to fetch the next (tokenized) character in either the program or in text input from the keyboard. AFAIK on CBM, this routine can be re-vectored to call a user routine, then if nothing of interest is found, to rejoin the normal ROM routine.

There are two spiral bound books that document the KERNAL and ROMs in great detail for the C64. Sorry, I don't remember their titles (maybe by Sheldon Leemon??)

HTH

--- e


Harry Potter

unread,
Dec 5, 2013, 12:13:37 PM12/5/13
to
On Thursday, December 5, 2013 11:40:13 AM UTC-5, ep...@juno.com wrote:
> I know of two main ways to extend interpreted MS-Basic for the 65xx family. One is to CALL (or SYS on CBM) a ML routine at a known address. This routine then uses internal ROM routines. To look at the tokenized text in the code stream following the CALL (or SYS).
>
I already know of this. I'd rather do this from a ROM cartridge, but I want to make available an extension written in assembler, loaded in and called via a SYS command for other users who want to extend C64 BASIC.

> I don't remember if the Vic-20 or C-64 has a LINE INPUT routine. The problem with INPUT X$ is that the read terminates with a comma in the input text. Once the ML routine is installed, you would use it with a SYS address,X$. The routine would look

That's good, but I'd rather *extend* the BASIC language, i.e. add commands, functions and support.

> In order to understand what is going you have to understand that MS-Basic has something called a TXTPTR (text pointer) that points to what BASIC is currently trying to interpret. CHKCOM makes sure that TXTPRT is pointing to a comma, else syntax error. PRTGET fetches a pointer to the memory used by variable X$. INLIN reads data into the input buffer. SAVED converts that off to a string variable. (and lots of other internal stuff...)
>
I understand about TXTPTR and CHRGET/CHRGOT but want a full tutorial on the subject. I have a C64 ROM map, but it doesn't show how to use the routines, nor does it display the information in a useful format.

> A more primitive way is to hook a lower level routine in BASIC called CHRGET. This routine is what BASIC uses to fetch the next (tokenized) character in either the program or in text input from the keyboard. AFAIK on CBM, this routine can be re-vectored to call a user routine, then if nothing of interest is found, to rejoin the normal ROM routine.
>
Could be useful, but I'd rather not.

> There are two spiral bound books that document the KERNAL and ROMs in great detail for the C64. Sorry, I don't remember their titles (maybe by Sheldon Leemon??)
>
Any resources online?

ep...@juno.com

unread,
Dec 5, 2013, 1:04:08 PM12/5/13
to
On Thursday, December 5, 2013 12:13:37 PM UTC-5, Harry Potter wrote:
> Any resources online?

http://www.zimmers.net/cbmpics/cbm/c64/c64prg.txt {Prog Ref Guide]
http://unusedino.de/ec64/technical/project64/mapping_c64.html [Leemon]
http://www.commodore.ca/commodore-manuals/
http://www.bombjack.org/commodore/books.htm

IMO one of the best things written on the subject was for the Apple2. Crossley's "Applesoft Internal Entry Points" that appeared in v1n1 of "Apple Orchard". It was so good that I used it to disassemble some of the internals of the routines of the original MS-BASIC for the Altair. (Yes that was 8080....).

The PRG and Mapping the C-64 were AFAIR, seriously good.

Harry Potter

unread,
Dec 5, 2013, 1:12:27 PM12/5/13
to
I found some interesting stuff. Thank you! :)

lawle...@gmail.com

unread,
Dec 12, 2013, 2:30:24 PM12/12/13
to
Harry,

I responded to a post in comp.sys.cbm in 2005 about adding new commands to BASIC with the following information:

(quote)

Take a look at the following electronic copies of The Transactor
magazine articles from the funet mirror site:

Transactor vol 5 issue 5 pp. 30-35 ( "Introducing TransBASIC" )

Transactor vol 5 issue 6 pp. 19-21 ( "TransBASIC Installment #2" )

( Also from v5 issue 6, pp. 22-25 ( "A New Wedge for the Commodore 64
... Add commands by trapping syntax errors." Neat technique! )

Transactor vol 6 issue 1 pp. 14-19 ( "TransBASIC Installment #3" )

Transactor vol 7 issue 1 pp. 54-57 ( "Adding Functions to BASIC" )

Transactor vol 7 issue 1 pp. 58-62 ( "Command Wedge ... Modifying
BASIC's Commands" )

The Transactor mirror site is at:

http://www.funet.fi/pub/cbm/magazines/transactor/index.html

There are many more installments to TransBASIC that you can look
through as well.

Personally, I thought the technique used in Compute!'s "SuperBASIC"
was kind of cool. ( The copied ROM to RAM, re-vectored the
often-unused STOP command to tokenize/detokenize as the "[" character
and then processed 4-character graphics commands after seeing the "["
).

(endquote)

Also, you might check out Stephen Judd's BLARG graphics command extensions for the C64. You can go to the Fridge site and do a find on the Word BLARG ...(see C=Hacking e-mag issues #9 and #11 ).

http://www.ffd2.com/fridge/

Harry Potter

unread,
Dec 13, 2013, 9:06:11 AM12/13/13
to
On Thursday, December 12, 2013 2:30:24 PM UTC-5, lawle...@gmail.com wrote:
> Harry,
>
> I responded to a post in comp.sys.cbm in 2005 about adding new commands to BASIC with the following information:
>
> Take a look at the following electronic copies of The Transactor
> magazine articles from the funet mirror site:
>
> The Transactor mirror site is at:
>
> http://www.funet.fi/pub/cbm/magazines/transactor/index.html
>
Okay.

> There are many more installments to TransBASIC that you can look
> through as well.
>
> Personally, I thought the technique used in Compute!'s "SuperBASIC"
> was kind of cool. ( The copied ROM to RAM, re-vectored the
> often-unused STOP command to tokenize/detokenize as the "[" character
> and then processed 4-character graphics commands after seeing the "["
> ).

That's cool. :)

> Also, you might check out Stephen Judd's BLARG graphics command extensions for the C64. You can go to the Fridge site and do a find on the Word BLARG ...(see C=Hacking e-mag issues #9 and #11 ).
>
> http://www.ffd2.com/fridge/

Okay.

Harry Potter

unread,
Dec 13, 2013, 11:49:27 AM12/13/13
to
On Thursday, December 5, 2013 1:04:08 PM UTC-5, ep...@juno.com wrote:
> http://www.commodore.ca/commodore-manuals/
>
This site has a lot of damaged files on it. However, the following site seems to work:

> http://www.bombjack.org/commodore/books.htm
>
> IMO one of the best things written on the subject was for the Apple2. Crossley's "Applesoft Internal Entry Points" that appeared in v1n1 of "Apple Orchard". It was so good that I used it to disassemble some of the internals of the routines of the original MS-BASIC for the Altair. (Yes that was 8080....).
>
I, too, am interested in Apple 2 programming. Unfortunately, I had virtually no experience with it. :(

> The PRG and Mapping the C-64 were AFAIR, seriously good.

I have the PRG. Where can I find the latter?

ep...@juno.com

unread,
Dec 16, 2013, 2:31:56 PM12/16/13
to
See the links in a previous message. It is there in text form.
0 new messages