need help with array of pointers with Stef's gcc
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 237
- Joined: Fri Apr 17, 2009 7:35 pm
- Location: USA
need help with array of pointers with Stef's gcc
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)?
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)?
my album - last thursday died last week
-
- Very interested
- Posts: 208
- Joined: Mon Jun 25, 2007 7:19 pm
- Location: Besançon,France
- Contact:
hi,
i have also a prob with TFM.
here is my structure:
all of my sound works fine with Kmods , Kega but with my megacart in the RH the sound is completly bugged....
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);
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).bastien wrote:all of my sound works fine with Kmods , Kega but with my megacart in the RH the sound is completly bugged....
-
- Very interested
- Posts: 237
- Joined: Fri Apr 17, 2009 7:35 pm
- Location: USA
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.
Notice the while loops at the bottom waiting on that register
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;
}
my album - last thursday died last week
-
- Very interested
- Posts: 237
- Joined: Fri Apr 17, 2009 7:35 pm
- Location: USA
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 fashionShiru 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).

my album - last thursday died last week
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: need help with array of pointers with Stef's gcc
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").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)?
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
};
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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.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
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.
Last edited by Shiru on Tue Dec 14, 2010 6:47 pm, edited 1 time in total.
-
- Very interested
- Posts: 237
- Joined: Fri Apr 17, 2009 7:35 pm
- Location: USA
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
32k, z80 bank alignmentShiru 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.

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 ?
Source code of all the replayers is included into TFM MM package (/replayers/ directory). You can do anything you want with it.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
I already had it but i probably already forgotten that driver source was included, ThanksShiru wrote:Source code of all the replayers is included into TFM MM package (/replayers/ directory). You can do anything you want with it.
