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

6502 assembly to load a basic program?

22 views
Skip to first unread message

xlar54

unread,
Nov 27, 2009, 1:32:09 PM11/27/09
to
Trying to find some code that will load and execute a basic program,
but from assembly. Can someone help point me in a good direction?
Basically the equivalent of :

LOAD "someprog",8
RUN

Preferably the routine would do a ,8 or a ,8,1 (binary). Im thinking
it would be easier to use built in Kernal routines if possible.

Bill Garber

unread,
Nov 27, 2009, 1:45:35 PM11/27/09
to

"xlar54" <scott....@gmail.com> wrote in message news:dc3e3cc2-f9d7-4f66...@k17g2000yqh.googlegroups.com...

Once again I will declare that I'm not as familiar with CBM as I could be,
but, it makes sense to me that you need to be in the BASIC Interpreter in
order to run a BASIC program, which would take you out of your ML program.
Therefore, IMO, it wouldn't be possible to do what you are asking.

Also, I've never seen it done. Usually ML programs are run from within a
BASIC program, then RTI brings you back to BASIC. I might be wrong about
the RTI command. It could be RTS.

Bill Garber


commodorejohn

unread,
Nov 27, 2009, 2:22:00 PM11/27/09
to
I'm not sure why you'd want to do this, but loading the program is as
simple as setting the filename and device number with the secondary
address set to 0 and calling the Kernal LOAD routine. I'm not sure how
to jump into the BASIC program, but take a look through the PRG or
Mapping the Commodore 64 and scrutinize the BASIC ROM section; that
should give you some clues.

jirvine

unread,
Nov 27, 2009, 2:28:08 PM11/27/09
to

Yes use the Kernal load routine to load the program, but remember to
set the end of program pointers so the variables don't destroy the
program after its running. Then call the basic run routine. I will
leave it to you to find these addresses in the programmers reference
guide.

Jouni Nordlund

unread,
Nov 27, 2009, 3:34:03 PM11/27/09
to

I remember 'hacking' some programs that show (at least) one
"Cracker-intro" and almost every intro code ended with these lines

JSR $A659
JMP $A7AE

Another trick I remember is the UNNEW code for C64:

POKE 2050,1:SYS42291:POKE45,PEEK(34):POKE46,PEEK(35):CLR

Hope this helps...

--
Jouni Nordlund


Leif Bloomquist

unread,
Nov 27, 2009, 4:19:35 PM11/27/09
to
"Bill Garber" <Ask_for_...@address.com> wrote in message
news:OsadnSMy_LNYg43W...@giganews.com...

> Once again I will declare that I'm not as familiar with CBM as I could be,
> but, it makes sense to me that you need to be in the BASIC Interpreter in
> order to run a BASIC program, which would take you out of your ML program.

Not at all, since BASIC itself is written in ML, you can call and use any of
the BASIC routines from within ML. I don't know the C64 addresses, but for
the VIC 20 you simply do:

JMP $C7AE

to start the current BASIC program. You might even be able to call RUN
directly ($C871).

Although it's probably more prudent to do:

JSR $C659 ; CLR
JSR $c533 ; Relinks BASIC Program from and to any address...
JMP $C7AE ; RUN

You're right though, getting back *into* your ML program would be tricky -
probably require the BASIC program to do a SYS. It would be interesting to
to do a JSR $C7AE and see if what happens when the program ends.

-Leif


Jonno Downes

unread,
Nov 27, 2009, 10:13:09 PM11/27/09
to

I have some code that downloads a program via tftp, then checks
whether the first 2 bytes are $801 (i.e. the BASIC load address) and
if it is, jumps into BASIC via this:

jsr $e453 ;set BASIC vectors
jsr $e3bf ;initialize BASIC
jsr $a86e
jsr $a533 ; re-bind BASIC lines
ldx $22 ;load end-of-BASIC pointer (lo byte)
ldy $23 ;load end-of-BASIC pointer (hi byte)
stx $2d ;save end-of-BASIC pointer (lo byte)
sty $2e ;save end-of-BASIC pointer (hi byte)
jsr $a659 ; CLR (reset variables)
jmp $a7ae ; jump to BASIC interpreter loop

I seem to remember a fair bit of trial and error based on suggestions
I'd found via google (and old postings to this group) so I don't claim
to fully understand everything going on there but this particular
incantation is what works for me. This code resides in an 'autostart'
cartridge image, meaning BASIC has not been initialised prior to
execution of the above.

Regards

Jonno

Steve Douglas

unread,
Dec 3, 2009, 3:34:38 PM12/3/09
to

"xlar54" <scott....@gmail.com> wrote in message
news:dc3e3cc2-f9d7-4f66...@k17g2000yqh.googlegroups.com...

I haven't programmed this stuff in years but it is certainly do-able. Use
the Kernal routines. As I recall you have to adjust the end of program
pointers afterwards (else all the variable declarations in the BASIC program
will overwrite the program itself). To run the BASIC code after will require
a jump to the interpreter. Some other stuff probably needs to be done to set
the current line, etc. If you trace the code for doing a "LOAD/RUN" it
should have most of it.

Steve


0 new messages