Starting from:

$34.99

CS2261 Lab 10-Interrupts Solution


Provided Files
● Makefile
● print.c, print.h ● mode0.c, mode0.h
● sprites.c, sprites.h
● gba.c, gba.h
● Spritesheet.c, spritesheet.h
● start.c, start.h
● danceBG.c, danceBG.h
● Dance.c, dance.h
Files to Edit/Add
● .vscode
○ tasks.json ● Main.c

Instructions
The goal of this lab is to build a two state program with an animation that tracks vBlanks and user button inputs using interrupts.
TODO 1 – Setup Start State Interrupts
Set up interrupts for the start state.
TODO 1.0
● In main.c inside of the setupStartInterrupts function, disable interrupts by setting REG_IME, the “master switch,” to zero.
TODO 1.1
● In main.c inside of the setupStartInterrupts function, enable button interrupts by setting REG_IE, the “circuit breaker.”
TODO 1.2
● In main.c inside of the setupStartInterrupts function, set the interrupt handler to the startInterruptHandler setting REG_INTERRUPT, the “outlet.”
TODO 1.3
● In main.c inside of the setupStartInterrupts function, set the button interrupts controller to be enabled and watch for START presses by setting REG_KEYCNT.
TODO 1.4
● In main.c inside of the setupStartInterrupts function, re-enable interrupts by setting REG_IME, the “master switch.”
TODO 1.5
● In main.c inside of the startInterruptHandler function, disable interrupts by setting REG_IME, the “master switch.”
TODO 1.6
● In main.c inside of the startInterruptHandler function, check if the interrupt was a button interrupt by checking the value of REG_IF.
TODO 1.7
● In main.c inside of the startInterruptHandler function, set switchToDance to 1 in the case that the start button was pressed.
TODO 1.8
● In main.c inside of the startInterruptHandler function, tell the GBA the interrupt was handled by setting REG_IF.
TODO 1.9
● In main.c inside of the startInterruptHandler function, re-enable interrupts by setting REG_IME, the “master switch.”
TODO 1.10
● In main.c inside of the goToStart function, call setupStartInterrupts.
Build and run. You should see a very beautifully drawn and detailed start screen, and when you press start, the screen should transition to a stage.
TODO 2 – Setup Dance State Interrupts
Setup interrupts for the dancestate
TODO 2.0
● In main.c inside of the setupDanceInterrupts function, disable interrupts by setting REG_IME, the “master switch,” to zero.
TODO 2.1
● In main.c inside of the setupDanceInterrupts function, enable vBlank and button interrupts by setting REG_IE, the “circuit breaker.”
TODO 2.2
● In main.c inside of the setupDanceInterrupts function, set the interrupt handler to the danceInterruptHandler setting REG_INTERRUPT, the “outlet.”
TODO 2.3
● In main.c inside of the setupDanceInterrupts function, set the display interrupts controller to enable vBlank interrupts by setting REG_DIPSTAT.
● In main.c inside of the setupDanceInterrupts function, set the key interrupts controller to enable button interrupts, watching for the SELECT button, by setting REG_KEYCNT.
TODO 2.4
● In main.c inside of the setupDanceInterrupts function, re-enable interrupts by setting REG_IME, the “master switch.”
TODO 2.5
● In main.c inside of the danceInterruptHandler function, disable interrupts by setting REG_IME, the “master switch.”
TODO 2.6
● In main.c inside of the danceInterruptHandler function, check if the interrupt was a button interrupt or a vBlank interrupt by checking the value of REG_IF.
TODO 2.7
● In main.c inside of the danceInterruptHandler function, set the paused flag to !paused in the case that the start button was pressed.
● In main.c inside of the danceInterruptHandler, if the paused flag is false, and a vBlank interrupt has occurred, call dance().
TODO 2.8
● In main.c inside of the danceInterruptHandler function, tell the GBA the interrupt was handled by setting REG_IF.
TODO 2.9
● In main.c inside of the danceInterruptHandler function, re-enable interrupts by setting REG_IME, the “master switch.”
TODO 2.10
● In main.c inside of the goToDance function, call setupDanceInterrupts.
Build and run. You should now be able to watch the stick figure on the stage dance, and interrupt his dancing by holding the SELECT key.

You will know your lab runs correctly if:
● You can move from the start state to the dance state by pressing START
● You can see an animated stick figure in the dance state ● You can pause the animation by holding SELECT

Submission Instructions:
Ensure that cleaning and building/running your project still gives the expected results. Please reference the last page of previous assignments for instructions on how to perform a "clean" command.
Zip up your entire project folder, including all source files, the Makefile, and everything produced during compilation (including the .gba file). Submit this zip on Canvas. Name your submission LabXX_LastnameFirstname, for example:
“Lab10_HenryStickmin.zip”
It is your responsibility to ensure that all the appropriate files have been submitted, and that your submitted zip can be opened and everything cleans, builds, and runs as expected.

More products