Collision Maps & Affine Sprites
Interrupts, Timers, Digital Sound
Function Pointers & Mechanics
The Other DMA & Data Structures
OOP & Assembly
100

Which attribute of the GBA sprite is used for Affine Sprites?

Attribute 3 --> FILL

100

Which DMA channel(s) are used for digital sound?

1 & 2
100

Which (Assembly) register is the link register, and what does it do?

R14; stores the return address when a function is called

100

What is the 2nd DMA we talked about called? What does it do?

Dynamic Memory Allocation. It allows us to create areas of memory using the heap for allocation.

100

Is C an object-oriented language? What can we use in C to create "objects" and mimic OOP properties?

No, C is NOT an object-oriented language. We can use structs to create objects with OOP properties.

200

How do we export a collision map from usenti?

8 bpp bitmap

200

How do you pause digital sounds? How do you stop them?

Pausing - just turn the timer off.

Stopping - count vBlanks from a start, stop when (vBlankCount - start >= duration)

200

What are 2 differences between functions and function pointers?

Functions are addresses, while function pointers are pointers that store/point to those addresses.

Size - functions don't have a size, while function pointers are 4 bytes (like all pointers).

Functions can't be reassigned but function pointers can.

200

At worst case, what can a BST become?

A ordered linked list (if all of the left nodes are NULL)


200

(Write) Name 2 basic instructions for ARM assembly and their syntax. Name 2 instructions used for conditionals in ARM assembly.

basic --> add, sub, ldr, str, etc

conditional --> le, lt, gt, ge, etc

300

(Write) write the colorAt function for a collision map that is called collisionMapBitmap. You can assume this is already exported for you and that the background size is 512x512.

inline unsigned char colorAt(int x, int y) {
    return ((unsigned char*)
CollisionMapBitmap) [OFFSET(x, y, 512)];
}

300

What is the difference between a hardware and a software interrupt? Which one do we use & when can we use it?

Software interrupts are initiated in software, whereas hardware interrupts are triggered when a hardware event occurs. We use hardware interrupts when timers go off, buttons are pressed, DMA finishes, scanline is reached, etc.

300

You cannot use a function pointer with this type of function because it requires a concrete address, not a runtime address.

Inline Function (Function pointers require functions to have addressable code)

300

What does malloc do? What does free do (and what does it NOT do)? What does realloc do?

Malloc allocates some amount of memory for usage. Free deallocates memory (marks it as available) but does NOT clear it. Realloc allocates new memory, copies over what was stored in the original memory, and frees the original memory.

300

What is inheritance? What is polymorphism?

Inheritance is an OOP mechanism where a new class (subclass/child) derives properties and behaviors from an existing class (superclass/parent), promoting code reuse. 

Polymorphism allows objects of different subclasses to be treated as a common superclass type, enabling them to execute unique, overridden methods through a single interface, providing flexibility

400

(Write) What does the OAM affine matrix look like? Define a struct that could be used to hold the correct information.

struct OAM_AFFINE_MATRIX {
    u16 fill0[3];
    short a;
    u16 fill1[3];
    short b;
    u16 fill2[3];
    short c;
    u16 fill3[3];
    short d;
} ALIGN(4) OBJ_AFFINE;

400

What are all of the relevant steps to export music from audacity to be able to play it on the GBA?

1. import track

2. mix stereo down to mono (one track)

3. change sample rate from 44k to 11k

4. export as 8-bit unsigned pcm

5. take .wav file and use wav2c to get it into program

400

(Write) Draw the stack frames for this program:
void bar() {}
void foo() {
    bar();
}
int main() {
   foo();
}

top of stack --> stack pointer
---------------------------------
bar() stack frame
---------------------------------
foo() stack frame
---------------------------------
main stack frame

400

If we had a BST that is well balanced, when searching for a particular value, what is the time complexity of this tree? What is the worst case time complexity?

Well-balanced --> O(log(n))

Worst case --> O(n)

400

What is the value stored at memory address 0x0600100 after these operations? This memory address's value is 256 and is stored in register r1.
ld r2, [r1]
add r2, r2, #100
lsl r2, r2, #2
str [r1], r2

1424

500

(Write) Write complex movement for a character on a background that is 512x512. You can assume you can use relevant macros such as MAPHEIGHT and MAPWIDTH are created for you, but you must handle creation of relevant surrogate variables (hOff + vOff). Sprite animation is handled as well, so relevant functions can be called.

(recitation slides)

500

(Write) Write an interrupt handler for playing digital sounds on the GBA.

void interruptHandler() {
   REG_IME = 0;
   if (REG_IF & IRQ_VBLANK) {
       if (soundA.isPlaying) {
            soundA.vBlankCount++;
            if (soundA.vBlankCount >=
                 soundA.durationInVBlanks) {
                 if (soundA.looping) {
                      playSoundA(soundA.data, soundA.dataLength, soundA.looping);
                  } else {
                      stopSoundA();
                  }
             }
        }
   }
    REG_IF = REG_IF;
    REG_IME = 1;
}

500

(Write) What is stack smashing and how does it work? Draw a visual representation of a buffer overflow to show how data contents can be overwritten for malicious purposes.

Stack smashing is a type of buffer overflow vulnerability that occurs when a program writes more data to a stack-allocated buffer than it can hold, overwriting adjacent memory. Drawing in lecture 21, slides 40-41.

500

(Write) Write a function to add a node to a BST. You can assume that the BST struct and all relevant members are initialized.

See Lecture 22, slide 11

500

(Write) Write a loop in arm assembly that looks at register r4's value, which begins at 2, and loops until its value is >= 14. Each time the program loops, it should add 2 to r4.

(see recitation slide)