🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #4274

Re: Self Modifying Code!

#4274
From: Jean-Michel Forgeas
Date: Fri, 06 Jul 1990 18:47
54 lines
1719 bytes
In article <293@smosjc.UUCP> brett@smosjc.UUCP (Brett Coon) writes:
>Is there an acceptable means to write self-modifying code on the Amiga?
>
>[...]  My current plan is to select one of a few possible
>versions of the code at the beginning, and then patch the code to use the
>appropriate version.

You have at least one other solution: use vectors.

struct FuncNeeded {
    void (*func1)();
    void (*func2)();
    };
struct FuncNeeded Version1 = { Func1_1, Func1_2 };
struct FuncNeeded Version2 = { Func2_1, Func2_2 };
struct FuncNeeded *Version;

init()
{
    Version = (TheVersionYouWant ? &Version1 : &Version2 )
}

program()
{
    ...
    (*(Version->func1))();
    ...
    retcode = (int*) (*(Version->func2))();
    ...
}

> It would be done once, during initialization, so
>performance at this point is entirely unimportant.

It could be coded in asm like:

init:
    ...
    lea     Version1,a5     use a base register
    rts

program:
    ...
    move.l  func2vectoroffset(a5),a0
    jsr     (a0)
    ...
    rts

--
                                            \___/
Jean-Michel Forgeas                          \-/
cbmvax!cbmbsw!cbmsup!cbmfra!swinjm!forgeas    |    The Software Winery
                                             -^-
                                 And, where is the universe ?
Technical Details
Message-ID: <forgeas.1377@swinjm.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!bu.edu!orc!oliveb!amiga!cbmvax!cbmehq!cbmfra!swinjm!forgeas
References: <293@smosjc.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!bu.edu!orc!oliveb!amiga!cbmvax!cbmehq!cbmfra!swinjm!forgeas
From: forgeas@swinjm.UUCP (Jean-Michel Forgeas)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Self Modifying Code!
Message-ID: <forgeas.1377@swinjm.UUCP>
Date: 6 Jul 90 18:47:53 GMT
References: <293@smosjc.UUCP>
Lines: 55