GB101:Hello Background

From NYC Resistor Wiki
Jump to navigation Jump to search
GB101 Class Notes
  1. Home
  2. Installing Gameboy Development Tools
  3. Introduction to the Gameboy Advance
  4. Hello Background
  5. Working with Palettes
  6. Tiles and Background Maps
  7. Sprites
  8. Scrolling Backgrounds
  9. Collision Detection
  10. Fixed point math
  11. Affine Sprites
  12. Sound
  13. Where do I go from here?


In this example we'll try to get acquainted with the GBA by using simple mode 3 to fill the screen with red pixels. In mode 3 each 16-bit short represents a RGB value. We use the RGB5 macro to convert r,g and b into a 16-bit short. We create a pointer to the video buffer which starts at 0x6000000 and then use a couple of simple loops to set the pixels. Obviously there are more efficient ways...


#include <gba_video.h>
#include <gba_systemcalls.h>

int main(void) {
    // Memory location of video buffer
    unsigned short* VideoBuffer = (unsigned short*)0x6000000; 
    unsigned char x,y;  

    // Turn on mode 3 with background 2
    SetMode(MODE_3 | BG2_ENABLE);   

    // Fill the video buffer with red pixels
    for(x = 0; x < SCREEN_WIDTH; x++)   
        for(y = 0; y < SCREEN_HEIGHT; y++)  
            VideoBuffer [x + y * SCREEN_WIDTH] = RGB5(31,0,0);  

    // Loop indefinitely