Re: [cc65] Calling another program: exec() ?

From: Oliver Schmidt <ol.sc1web.de>
Date: 2011-02-10 12:56:09
Hi,

The other day submitted a first version of exec() for the Apple II.

Maybe I'm bothering you with too obvious things or maybe there are
better ways to do it, but anyway I wanted to provide some details on
my implementation that are not actually related to the Apple II that
may be useful for other targets.

There are several targets that need a small loader stub to be placed
somewhere safe which is than jumped to in order to load the new
program. However we surely don't want to introduced yet another linker
segment for that purpose ;-) On the other hand it is likely that one
needs absolute references into that loader stub. My solution goes like
this, using a JSR just as a simple example for an absolute reference:

====================

        .code

_exec:
        ...
        ; set up loader stub
        ldx    #size - 1
:       lda    source,x
        sta    target,x
        dex
        bpl	:-
        ...
        jmp    target

        .rodata

; the loader stub entry point
source:
        ...
        jsr    mysub
        ...
        jmp    <new program>

; the loader stub subroutine
mysub = * - source + target
        ...
        rts

size = * - source
target = $300

====================

A final remark: If the "safe place" is i.e. $300-$380 than it might be
a good idea to place the loader stub at the end of that area to
increase the likelyhood of not interfering with another user of the
same area. With the approach above that is very simple. Just replace

target = $300

with

target = $380 - size

Regards,
Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Feb 10 12:56:18 2011

This archive was generated by hypermail 2.1.8 : 2011-02-10 12:56:21 CET