The canonical way to align something in ca65 is to give the segment an
align property (which you've already done), and
then use
.align in the code that fills the segment.
Code:
.align $40
sample: .incbin "whatever.dmc"
At that point there's no need for an assert, unless you think the assembler has a bug in it.
Without using
.align you haven't actually specified a specific location for that code and are relying on the link order. You're
probably only using that segment in one place, and you're
probably making it the first thing in that segment, but if you want to actually tell ca65 where to put the code, that's what
.align is for.
There's actually a valid reason to use
.assert instead of
.align too. The function of
.align is to add any necessary padding to reach the next aligned address (or emit an error if the segment isn't aligned). If you want to specify that nothing extra should be added, and it should only appear where you expect it to be, then
.assert is correct instead.
tokumaru wrote:
being paranoid...
I think asserts are an essential language feature. I put them anywhere I think I might make a mistake. They don't often trigger, but when they do I'm
very glad they're there. The point is to catch yourself when you make an error. It's easy to make mistakes. It's easy to accidentally put an extra byte in a segment. It's easy to accidentally leave out a comma somewhere. It's easy to accidentally type into your text editor when you think you're controlling your game. It's not paranoid to think these things might happen. They do! (This probability is magnified immensely if more than one person is working on the project.)
I don't know what you were doing in your code, maybe you were doing it in places that were totally unnecessary, but the point of asserts is to have
less maintenance by catching errors before they become runtime errors which will take up a lot of debugging time.
You can go further with it, too. The original assert
comes from C and is a runtime check. Even better than a runtime check is an automated
unit testing that runs and tests the code for you, with every build or periodically, etc. How much error-checking code is worth writing depends on the project, but this kind of stuff is often mandatory on large professional projects.
I actually use BRK as a form of runtime assert in my project.
It's caught a number of bugs with a bluescreen of death I stuck in the IRQ handler.
Anyhow, in this particular case the
.assert is actually a
good suggestion. It's actually
more important to put
.align or
.assert next to the actual sample definition in the code than it is to remember to align the segment. The
align property in the segment is useless unless the code gets actually gets generated at the correct place!