Home CPSC 305

GBA Input

 

Objective

To get practice writing, compiling and running GBA programs, and learn how to test for button input.
 

Button Input

Button input on the GBA is handled with a memory register located at address 0x04000130. The register is 16 bits long, but only has 10 important bits: one for each of the GBA's 10 buttons:

The bits are 1 when the button is unpressed, and 0 when the button is pressed.

To check for user input, you need to read the value of the button register, then test the bit(s) you are interested in.


 

Task

For this lab, you will write a GBA program which will display a screen filled with a random color. When the 'A' button is pressed, it will replace the random color with a new random color.

Start with the hello.c program we looked at in class. First make sure that you can compile and run that program using these instructions.

Next, change the program so that it chooses a random color value and fills the entire screen with it. You can use the rand() function from stdlib.h for this purpose. rand returns a random 32-bit number. You can set your color to 16 bits of this, and get a random color value.

Next, change the main function so that inside of the infinite loop, it tests if the 'A' button is pressed and, if so, chooses a new random color and fills the screen with that instead.

Check with the emulator you are using to see which key maps to the 'A' button.

rand() will always give you the same sequence of random numbers, so your program will use the same colors each time you run it, which is OK.


 

Submitting

When you are done, please submit the C code under the assignment in Canvas.

Copyright © 2024 Ian Finlayson | Licensed under a Creative Commons BY-NC-SA 4.0 License.