Page 1 of 1
need help with array of pointers with Stef's gcc
Posted: Tue Dec 14, 2010 4:04 pm
by powerofrecall
Okay, so something I'm putting together is using the C language TFM replayer to play some songs. I've been able to incbin the tfc files with inline asm and that works fine, but I want to put each song pointer into an array of pointers so I can play the tunes sequentially.
static const u8 *songs[] = {
song1,
song2,
song3,
etc
};
tfm_play(songs[0]);
Even as 'static' I'm getting a linker error. I know that because of the limitation of sections you can't initialize global variables with a value, so the reason isn't completely lost on me, but I figured that as static const it would compile into the ROM as a pointer table. If I'm not mistaken, if I move this into say, main() the pointer array will be loaded into RAM, right? Which seems kind of wasteful.
Is there any way of doing this (I don't particularly want to play with the linker script, I'd probably break it)?
Posted: Tue Dec 14, 2010 5:10 pm
by bastien
hi,
i have also a prob with TFM.
here is my structure:
Code: Select all
const u16 death_size=1669;
const u8 death_data[1669]={
0x54,0x46,0x4d,0x63,0x6f ......
Code: Select all
tfc_init(death_data);
tfc_play(death_data);
setVBlankCallback(tfc_frame);
all of my sound works fine with Kmods , Kega but with my megacart in the RH the sound is completly bugged....
Posted: Tue Dec 14, 2010 5:34 pm
by Shiru
bastien wrote:all of my sound works fine with Kmods , Kega but with my megacart in the RH the sound is completly bugged....
Are you sure that Z80 does not run some driver which access to YM2612? Stef's devkit has one, maybe access conflict does not happen on emulators by some reason (conflict is when players on different sides expects that certain YM2612 register is selected, but other side selected other register).
Posted: Tue Dec 14, 2010 5:38 pm
by powerofrecall
Maybe I can help. What does your ym2612wr() function look like?
If you're not waiting on the 2612's A0 register my understanding is you'll get weird corrupted sound because the writes are happening too fast.
I stole/adapted some code from Shiru's Uwol game, it seems to make a better example than what comes with TFM anyway.
Code: Select all
void ym2612wr(u8 reg,u8 val,u8 bank)
{
volatile u16 *pz;
volatile u8 *pw,*pa,*pd;
pz=(u16*)Z80_HALT;
*pz=0x100;
pw=(u8*)YM2612_A0;
if(!bank)
{
pa=(u8*)YM2612_A0;
pd=(u8*)YM2612_D0;
}
else
{
pa=(u8*)YM2612_A1;
pd=(u8*)YM2612_D1;
}
while(*pw&0x80);
*pa=reg;
while(*pw&0x80);
*pd=val;
*pz=0;
}
Notice the while loops at the bottom waiting on that register
Posted: Tue Dec 14, 2010 5:43 pm
by powerofrecall
Shiru wrote:
Are you sure that Z80 does not run some driver which access to YM2612? Stef's devkit has one, maybe access conflict does not happen on emulators by some reason (conflict is when players on different sides expects that certain YM2612 register is selected, but other side selected other register).
Or this, stef's kit by default has z80 drivers I think. I don't know because I've basically been using the library in a copy/paste fashion

Re: need help with array of pointers with Stef's gcc
Posted: Tue Dec 14, 2010 6:24 pm
by Stef
powerofrecall wrote:Okay, so something I'm putting together is using the C language TFM replayer to play some songs. I've been able to incbin the tfc files with inline asm and that works fine, but I want to put each song pointer into an array of pointers so I can play the tunes sequentially.
static const u8 *songs[] = {
song1,
song2,
song3,
etc
};
tfm_play(songs[0]);
Even as 'static' I'm getting a linker error. I know that because of the limitation of sections you can't initialize global variables with a value, so the reason isn't completely lost on me, but I figured that as static const it would compile into the ROM as a pointer table. If I'm not mistaken, if I move this into say, main() the pointer array will be loaded into RAM, right? Which seems kind of wasteful.
Is there any way of doing this (I don't particularly want to play with the linker script, I'd probably break it)?
I had a similar problem, if all your data is "const" there is no good reason to not store all them in rom section *but* for some reasons GCC doesn't always handle that correctly... I believe it's due to the C syntax which sometime left some ambiguities (const u8 **data; --> "can't say which part is const").
You can fix that by using typedef, i had to do this myself :
Code: Select all
typedef u8* pu8;
const pu8 songs[] = {
song1,
song2,
song3,
etc
};
should fix your problem as this resolve the ambiguity about "const" part...
Posted: Tue Dec 14, 2010 6:26 pm
by Stef
powerofrecall wrote:
Or this, stef's kit by default has z80 drivers I think. I don't know because I've basically been using the library in a copy/paste fashion

Oh tfc player is 68k based ? i though it was a z80 driver so yep, maybe the default loaded Z80 driver is conflicting but that should cause troubles on emulators too... the YM2612 busy flag is also a very possible cause.
Posted: Tue Dec 14, 2010 6:45 pm
by Shiru
There are both assembly Z80 and C M68K versions. One that bastien reffering to is M68K. Problem with Z80 version is that your music data have to be aligned on 32K, so it better suits for assembly programs, where you control how data is located in ROM. M68K version does not have this limitation, but it is slower, of course.
Posted: Tue Dec 14, 2010 6:45 pm
by powerofrecall
Thanks Stef, that works brilliantly!
Posted: Tue Dec 14, 2010 6:57 pm
by Stef
Shiru wrote:There are both assembly Z80 and C M68K versions. One that bastien reffering to is M68K. Problem with Z80 version is that your music data have to be aligned on 32K, so it better suits for assembly programs, where you control how data is located in ROM. M68K version does not have this limitation, but it is slower, of course.
32k, z80 bank alignment

I created a binToS tool which can align binary data and output them as .s and .h file, easily usable in C sources. I needed that for Z80 deving too... is the source of your z80 driver available somewhere ? can i eventually include it in my library ?
Posted: Tue Dec 14, 2010 7:23 pm
by Shiru
Source code of all the replayers is included into TFM MM
package (/replayers/ directory). You can do anything you want with it.
Posted: Tue Dec 14, 2010 8:43 pm
by Stef
Shiru wrote:Source code of all the replayers is included into TFM MM
package (/replayers/ directory). You can do anything you want with it.
I already had it but i probably already forgotten that driver source was included, Thanks
