HAM Documentation

Home · Downloads · Your Account · Submit News

Documentation Homepage HAMLib reference Back to HAM Homepage |

## Macro Introduction

What Macros are:
  Macros are a nice way of hiding complexity in a program, much like function calls. Unlike functions, however, the "code" inside a Macro gets pasted into your source wherever the Macro appears. This usually has the benefit of saving a function call, which can save you some CPU time for small operations. While there are some disadvantages and flexibility issues with Macros generally, it prooved to be a good core system to build GBA applications in a readable fashion.

A small example:
  Suppose you have a picture in the background, and you want to use the mosaic (enlarge pixel) hardware effect of the GBA whenever you press the A button. In direct C, this would look like:

    if(~(*(volatile unsigned short *)(0x04000130) & 0x0001))
            {
                *(volatile unsigned short *) 0x0400004C = 2 | (2<<4) |(0<<8) |(0<<12)
            }

Using HAM macros, the very same task looks like this:

    if(F_CTRLINPUT_A_PRESSED)
            {
                M_MOSAIC_SET(2,2,0,0);
            }

I think the advantage is obvious.

Now, what macros are there, and how can I find what I need quickly? Read on in the next topic to learn about the different Macro Types in HAM. It is also a good idea to just try the Macros, or look how they are used in sample sources. All Macro definitions are documented (almost hehe) and can be found in include/mygba.h.

Documentation Homepage | HAMLib reference | Back to HAM Homepage
documentation created with Doxygen