gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Alternate execution of code

#26576 - DiscoStew - Mon Sep 20, 2004 4:24 am

I plan to take a bunch of C functions I made, and wrap them together into a library. Some of the functions use DMA3, which isn't so bad except for this instance. In another project, I plan to use this library and AAS together. Now AAS includes a DoDMA3 function that is a bit necessary for people not doing the single stmia instruction. Now, I'd like to link that function into my library so that it uses that if the AAS library is also in the project, or not use it if it isn't.

My idea was to check for the symbol __AAS__ (since the AAS.h file defines it) to see if the library was also being used, like such...
Code:
#ifdef __AAS__
#include "AAS.h"
#endif

..and in situations where I would use DMA3, I'd do this...
Code:
#ifdef __AAS__
AAS_DoWork(....function parameters....);
#else
{....whatever I plan to do with DMA3......}
#endif


Now this was just an idea so that my library could be compatible with AAS, but my method isn't working. Perhaps someone out there knows what I am trying to do, and could help me with this problem. Any help would be appreciated.
_________________
DS - It's all about DiscoStew

#26578 - Krakken - Mon Sep 20, 2004 7:43 am

That's exactly what I did when I used AAS and it seemed to work fine for me. What isn't working? DMA doesn't work when AAS is used? Does it work when it's not?

Also, make sure you're not including AAS when you're not using it.

NOTE:
I just looked again at your code and you have this:

#ifdef __AAS__
#include "AAS.h"
#endif

If __AAS__ is defined in AAS.h then that will never be true. as your checking before you even define it.

#26579 - DiscoStew - Mon Sep 20, 2004 8:19 am

Krakken wrote:
If __AAS__ is defined in AAS.h then that will never be true. as your checking before you even define it.


Hmmmm, why didn't I see of that before? Perhaps instead of trying to include the header over again, I should just use the prototype for AAS_DoDMA3. My code if kinda screwed up at the moment, as I was trying to just get the AAS portion of the code working, and it is late, so I will try sometime during the day tomorrow.
_________________
DS - It's all about DiscoStew

#26580 - MumblyJoe - Mon Sep 20, 2004 8:38 am

Hmmm, I would suggest, although I havent tried this, that if you have the same syntax as another function (such as the bios CPUSet) for your dma3 copy, and you have a general header for your library, and want to include it after the AAS header...

Code:
#ifdef __AAS__
#define DMA3Copy CPUSet
#endif


It's a bit of a nasty hack, but it means you wouldn't have to put #ifdef's all through your code. A more elegant way might be with function pointers etc but thats up to you.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#26588 - LOst? - Mon Sep 20, 2004 4:19 pm

I'm using #ifdef too, and I tried something like this:
Code:

#ifdef BLA1 || BLA2

It doesn't work :(
How do you do something like this?

#26589 - poslundc - Mon Sep 20, 2004 4:37 pm

Try

Code:
#if defined(BLA1) || defined(BLA2)
     ...
#endif


Dan.

#26590 - Lord Graga - Mon Sep 20, 2004 4:37 pm

MumblyJoe wrote:
Code:
#ifdef __AAS__
#define DMA3Copy CPUSet
#endif

Very nasty because CPUSet doesn't have quite the same functions as DMA.

Lost(R):

Just do this:
Code:
#ifdef BLA1
//do it!
#endif
#ifdef BLA2
//do it again! :P
#endif



:P

#26591 - jd - Mon Sep 20, 2004 4:38 pm

Quote:

I plan to take a bunch of C functions I made, and wrap them together into a library. Some of the functions use DMA3, which isn't so bad except for this instance. In another project, I plan to use this library and AAS together. Now AAS includes a DoDMA3 function that is a bit necessary for people not doing the single stmia instruction. Now, I'd like to link that function into my library so that it uses that if the AAS library is also in the project, or not use it if it isn't.


Perhaps it would be easier to implement your own version of AAS_DoDMA3 and just use that in your code instead? That way it would work whether or not it was linked to AAS. In case it helps, the code for AAS_DoDMA3 is very simple:

Code:

AAS_DoDMA3:
   mov r3,#0x04000000
   add r3,r3,#0xd4
   stmia r3,{r0-r2}
   bx lr


Just change the name to DoDMA3 or something similar and then use that in your code instead.

#26593 - LOst? - Mon Sep 20, 2004 6:00 pm

poslundc wrote:
Try

Code:
#if defined(BLA1) || defined(BLA2)
     ...
#endif


Dan.

Cool!

#26594 - DiscoStew - Mon Sep 20, 2004 6:17 pm

Thanks for all the suggestions, but from what I see, I'm going to go with jd's version. Not only will it make my library compatible with AAS, but I could use this for any other DMA3 operations that I plan to do. thx again you all. Now I just need to try that when I get home today.
_________________
DS - It's all about DiscoStew