[comp.sys.cbm] HELP: Assembly - Address Maintenance for code overlaying

lockemer@iccgcc.decnet.ab.com (12/11/90)

I am writing a program in assembly which will need to load different sections
of code into the same areas of memory. These sections will have multiple
routines in them. Does anyone have any suggestions/tricks/tips on how to access
the routines from the main code (such as using labels somehow) so that I do not
have to manually keep track of where each routine ends up any time it is
reassembled? I am writing this on a 128 using MERLIN 128. A related question is
how do I do the same thing if I want to have routines in other bank
configurations? Thanks...

Todd Lockemer

rknop@nntp-server.caltech.edu (Robert Andrew Knop) (12/11/90)

lockemer@iccgcc.decnet.ab.com writes:

>I am writing a program in assembly which will need to load different sections
>of code into the same areas of memory. These sections will have multiple
>routines in them. Does anyone have any suggestions... on how to access
>the routines from the main code (such as using labels somehow) so... I do not
>have to manually keep track of where each routine ends up any time it is
>reassembled? I am writing this on a 128 using MERLIN 128.

You could always use the GEOS/VLIR trick, which is include a jump table at the
beginning of the overlay module (the section of code that has multiple sets
of routines loaded into it).  For example, if you had three routines, the
beginning of the overlay module would look like

Overlay_start:
               jmp  routine1
               jmp  routine2
               jmp  routine3

Then, whenever you want to access these routines from your main code (the
code that is always memory resident), you would put in a statment like

   jsr Overlay_Start+(n-1)*3

where n is the number of the routine (1, 2, or 3).  As long as every overlay
module starts at the same place in memory (the location Overlay_Start), and
as long as you don't change that location, you can move the routnes in the
overlay module around, and only need to recompile that module; recompiling
that module will create the correct jump table, but the location of the jump
table is the same, so that no changes need to be made to the routine that
accesses the jump table.

-Rob Knop
rknop@juliet.caltech.edu

nrossi@jarthur.Claremont.EDU (Nick Rossi) (12/11/90)

In article <2373.27637c31@iccgcc.decnet.ab.com> lockemer@iccgcc.decnet.ab.com writes:
>I am writing a program in assembly which will need to load different sections
>of code into the same areas of memory. These sections will have multiple
>routines in them. Does anyone have any suggestions/tricks/tips on how to access
>the routines from the main code (such as using labels somehow) so that I do not
>have to manually keep track of where each routine ends up any time it is
>reassembled? I am writing this on a 128 using MERLIN 128. A related question is
>how do I do the same thing if I want to have routines in other bank
>configurations? Thanks...
>
>Todd Lockemer


The standard way to do this is to include a jump table at the start of the
memory area where your routines are located.  Then, all of your calls to the
machine language from basic will be offsets from the start of the memory
area in multiples of three bytes.  I always define a variable like ML to
equal the start of the memory area (such as ML = 49152), and then the calls
to routines become SYSML, SYSML+3, SYSML+6, SYSML+9, etc.

-----------------------------------------------
Nick Rossi, '93     | "That's nasty, Wyatt..."
Harvey Mudd College | "That's Chet, Gary!"
-----------------------------------------------

sd05@terre.DMI.USherb.CA (Sylvain Tremblay / Eric Trepanier) (12/18/90)

In article <2373.27637c31@iccgcc.decnet.ab.com> lockemer@iccgcc.decnet.ab.com writes:
>I am writing a program in assembly which will need to load different sections
>of code into the same areas of memory. These sections will have multiple
>routines in them. Does anyone have any suggestions/tricks/tips on how to
>access the routines from the main code (such as using labels somehow) so that
>I do not have to manually keep track of where each routine ends up any time it
>is reassembled? I am writing this on a 128 using MERLIN 128. A related
>question is how do I do the same thing if I want to have routines in other
>bank configurations? Thanks...
>
>Todd Lockemer


Merlin is great for this kind of stuff!  The best way to do it is to put your
main "chunck" of source listing in a file named something like "main_code".
Then you write a different source code section for each overlay module.  These
files could be "overlay_code.x" where x = 1,2,3,4,...  Each of the files would
start with a ORG XXXX statement and end with a SAV statement.  Then you would
have one "project" file which would simply include all the files required for
assembly.  This project file would look like this:


>	    use	    "macros.l"
>	    use	    "symbols.l"
>	    use	    "main_code.s"
>	    use	    "overlay_code_1.s"
>	    use	    "overlay_code_2.s"
>	    use	    "overlay_code_3.s"


The macros.l file is your macro library, the symbols.l file is your symbol
library and the main code would look like this:

>	    org	    $2000	; Start address of main module
>	    ...
>	    jsr	    GetOverlay1	; Bring in Overlay 1 module in memory
>	    jsr	    Function1	; Call a function from overlay 1
>	    ...
>	    jsr	    GetOverlay2	; Bring in Overlay 2 module in memory
>	    jsr	    Function2	; Call a function from overlay 2
>	    ...
>	    jsr	    GetOverlay3	; Bring in Overlay 3 module in memory
>	    jsr	    Function3	; Call a function from overlay 3
>	    ...
>	    sav	    "main_code"

Finally, each overlay code would look like this:

>	    org	    $4000	; Overlay modules start address
>	    ...
>FunctionX  ...			; Function (1,2,3) start address
>	    rts
>	    sav	    "overlay_code_X"

Ideally, these overlay modules would be copied in a REU and swapped in an out
of it for maximum speed!  It can be done very easilly.  The "GetOverlayX"
routine wouldn't need more than 20 instructions or so.

The best way to jump to routines located in different memory banks is through
the JMPFAR and JSRFAR routines from the Kernal.  If you have the C128
Programmer's Reference Guide or the C128 Internals book from Abacus, you've
got all the information you need to use these simple routines.

Hope this was helpful!

Eric Trepanier

-- 
+-----------------------------------------------------------------///------+
|  Sylvain Tremblay        INTERNET: sd05@terre.USherb.CA    __  ///   /|  |
|  Eric Trepanier               CIS: 71640,666               \\\///  #  |  |
|  Sherbrooke, Qc, Can          TEL: (819) 820-0976           \XX/     _|_ |

sha@kolvi.hut.fi (Seppo J. Halme) (12/25/90)

Seppo J. Halme
 sha!kolvi.hut.fi



--------------------------  ------------------   ! 
Seppo J. Halme           ! ! = ====!!  ====== !  ! Have a good day!
sha@kolvi.hut.fi         ! !   !!  !!    !!   !  !
Tietoliikennelaboratorio ! !   !!  ====  !!   !  !