I wanted to include sampled sounds into my game and while I managed to do so, I encountered a little stylistic issue:
Since FamiTone requires the samples to be at ROM address $C000..$FFC0, in 64-byte steps, I originally intended to do a separate segment for it, with an alignment to ensure the correct location:
And then I would have done this in Assembly:
But the problem is: When FamiTone creates the Assembly file and the DMC file out of the FamiTracker text export, then the code for the samples includes this:
FT_DPCM_PTR is a value that is calculated out of FT_DPCM_OFF. But if FT_DPCM_OFF is set to a value that isn't known at compile time, but only gets set at link time (in our case __SAMPLES_LOAD__), then the compiler gives a range error.
If I use a fixed value, then everything works file:
But there are two issues with it:
Firstly, the address value is written in two different locations, i.e. we have a redundancy.
Secondly:
If I still want to be able to use all of my ROM space, I would have to put the samples at the end. And whenever a sample changes in my FamiTracker file, I would have to manually check its size, then subtract the size from $FFFA (the VECTORS address), then align it with $40 and put this value into my config file and my code manually.
Which is not very elegant.
Due to the config file, I never had to worry about absolute addresses. Changing details in songs or sound effects never had any influence on my code. But now, whenever I change a sample, I would have to alter values in my source code.
Is there any solution to this?
Since FamiTone requires the samples to be at ROM address $C000..$FFC0, in 64-byte steps, I originally intended to do a separate segment for it, with an alignment to ensure the correct location:
Code:
RODATA: load = PRG_ROM, type = ro;
SAMPLES: load = PRG_ROM, type = ro, align = $0040, define = yes;
VECTORS: load = PRG_ROM, type = ro, start = $FFFA;
SAMPLES: load = PRG_ROM, type = ro, align = $0040, define = yes;
VECTORS: load = PRG_ROM, type = ro, start = $FFFA;
And then I would have done this in Assembly:
Code:
.import __SAMPLES_LOAD__
FT_DPCM_OFF = __SAMPLES_LOAD__
; That's the constant that tells FamiTone where to look for the samples
.segment "SAMPLES"
.incbin "Music.dmc"
FT_DPCM_OFF = __SAMPLES_LOAD__
; That's the constant that tells FamiTone where to look for the samples
.segment "SAMPLES"
.incbin "Music.dmc"
But the problem is: When FamiTone creates the Assembly file and the DMC file out of the FamiTracker text export, then the code for the samples includes this:
Code:
@samples:
.byte $00+FT_DPCM_PTR,$00,$00 ;1
.byte $00+FT_DPCM_PTR,$00,$00 ;2
; ...
.byte $00+FT_DPCM_PTR,$58,$08 ;25
; ...
.byte $00+FT_DPCM_PTR,$00,$00 ;1
.byte $00+FT_DPCM_PTR,$00,$00 ;2
; ...
.byte $00+FT_DPCM_PTR,$58,$08 ;25
; ...
FT_DPCM_PTR is a value that is calculated out of FT_DPCM_OFF. But if FT_DPCM_OFF is set to a value that isn't known at compile time, but only gets set at link time (in our case __SAMPLES_LOAD__), then the compiler gives a range error.
If I use a fixed value, then everything works file:
Code:
SAMPLES: load = PRG_ROM, type = ro, start = $F800;
Code:
FT_DPCM_OFF = $F800
But there are two issues with it:
Firstly, the address value is written in two different locations, i.e. we have a redundancy.
Secondly:
If I still want to be able to use all of my ROM space, I would have to put the samples at the end. And whenever a sample changes in my FamiTracker file, I would have to manually check its size, then subtract the size from $FFFA (the VECTORS address), then align it with $40 and put this value into my config file and my code manually.
Which is not very elegant.
Due to the config file, I never had to worry about absolute addresses. Changing details in songs or sound effects never had any influence on my code. But now, whenever I change a sample, I would have to alter values in my source code.
Is there any solution to this?