Mike wrote:Now that we've got the solution, we only need a problem.
... or not a problem perhaps, but at least a workable example.
Here's a small routine that installs an interrupt server to change $900F (combined background and border colour) every 1/60 second. The original was placed at $033C, but now, for some reason, we'd like to have it at $1800: (download
example.prg). Do a LOAD"...",8,1 and try out with SYS828 to see what it does. After we have started up MINIMON (or another monitor), let's take a look at the program!
When this routine is supposed to go to $1800, we need another 16 bit value put into the interrupt vector at $0314, obviously ...
... but besides this, we're quite lucky: no jumps to relocate - but wait! What's with that BIT instruction at $034B?
The absolute operand of the BIT instruction is read off by two LDA instructions that provide low- and high-byte for the IRQ vector!
This looks like someone wanted to assist the relocator.
Here, the BIT instruction is just a placeholder for the IRQ vector address, and when the relocator encounters it, that address will also be corrected! This would not work if the IRQ vector value had been placed into immediate operands of the two LDA instructions,
which is a common reason relocators fail.
That being noticed, proceed! (download
relocate.prg)
The monitor Transfer command
T 033C 0353 1800 makes a copy of the code at the new place. With D, we inspect the copy and see that the instructions at $1801, $1807 and $180F still point to the original addresses. Now we provide the relocator with a
pointer to the begin of the moved code, $1800, which is put into $55/$56.
In the same fashion, we instruct the relocator to stop at $1818 (
limit address put into $57/$58). All 16 bit operands between $033C (
start address, put into $59/$5A) and strictly less than $0354 (
end address, put into $5B/$5C) are supposed to be adjusted ... by $14C4 = $1800 - $033C! Therefore, we put $14C4 as
offset into $5D/$5E, start the relocator with
G 02A1 ...
... inspect the copy once again with
D 1800 1817 and see the instructions at $1801, $1807 and $180F now have their operands corrected: the two LDAs read the IRQ vector address off the BIT instruction at $180F, and its operand correctly points to the INC $900F at $1812.
We delete the original code with
F 033C 0353 00 and exit to BASIC with the
X command.
SYS6144 runs the relocated IRQ routine.
P.S. It's quite instructive to compare this method with the approach taken in the thread '
IRQ Installer'.