Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Hot_Dog on April 17, 2011, 12:38:53 pm

Title: Shifting program locations
Post by: Hot_Dog on April 17, 2011, 12:38:53 pm
Is there a B_CALL routine or a function someone wrote to relocate a program in RAM?

For example, say I have these five variables in RAM:

A  (located at $A000)
C
[D]
RUNNER
DOORS

Is there a routine that exists to move pgrmRUNNER to $A000 while shifting the other variables further down into RAM?

RUNNER
A
C
[D]
DOORS
Title: Re: Shifting program locations
Post by: Hot_Dog on April 17, 2011, 02:33:04 pm
I'll take that as a "no", but it won't be hard to make my own ;D
Title: Re: Shifting program locations
Post by: FloppusMaximus on April 20, 2011, 11:09:02 pm
There isn't a system routine to do that.  There are many third-party routines to do so; that's exactly what shells do. :)

Probably the most popular approach (taken by Ion and many others since) is to copy a block of up to 768 bytes from the start of the program to a temporary buffer (such as saveSScreen), then DelMem those bytes, InsertMem at the desired location, and copy the data from the temporary buffer to the new location.  Then, if the program was larger than 768 bytes, repeat as needed.

Another technique is the one used by Venus (which I belive Kalimero invented); what he does is to repeatedly swap blocks of memory, each time smaller than the last.  It's a beautiful algorithm, and a marvelously simple bit of code, and it's also faster in most cases than the Ion algorithm.  It will leave you scratching your head for a while trying to understand why the code works. :)  And to use it, you also need to know about a couple of undocumented system routines (DelVar3D and DelVar3DC), which you can use to fix up the VAT after moving programs around.