ld65 doesn't re-order anything. It will all go into the output in the order of memory regions, then segments within those memory regions, then in the order of linked files, then in the order within the file.
However, there's probably a few more options available to you to help manage this.
If the tables aren't more than 128 bytes in size, you might try a smaller align (e.g. 8 or 16 or 32) that demands less padding.
Another way to do this is create one aligned segment, use .align on the first block, but then just put asserts on everything that follows instead of aligning each one. That way the linker will give an error whenever a page crossing is created, and you can manually add padding, or find useful material to use in the padded space.
This is a trial-and-error approach, but by keeping all the stuff that needs to be aligned together and separate, I have found that the amount of times this kind of thing needs to be manually re-padded are usually very few. The advantage is that with fewer things using an explicit .align, a lot of stuff like this can more efficiently fit into the middle of a page.
Something like this:
Code: Select all
.segment "ALIGNED"
.align 256
block1: ...
.segment "CODE"
... ; this code can be modified without worrying about disturbing the aligned stuff
.segment "ALIGNED"
block2: ...
.assert (>*)=(>block2), error, "block2 page crossing"
; with the assert, it doesn't really matter where block2 starts, as long as it's anywhere within the page
.segment "CODE"
...
.segment "ALIGNED"
; maybe block3 ended up asserting at first, so we manually pad by relocating some other code/data here
...
.align 256 ; automatically pad the remaining bytes to re-align
block3: ...
.assert (>*)=(>block3), error, "block3 page crossing"
.segment "CODE"
...
.segment "ALIGNED"
; for aligned code, usually necessary for timing page crossings, often the affected branches only span a few bytes.
; in cases like this, often the branches are fine, or only need a tiny amount of padding to find a suitable place for the code.
.res 3 ; manually pad by 3 bytes
func1:
ldx #55
:
asl
dex
beq :-
.assert (>*)=(>:-), error, "page crossing"
rts