How can we represent both positive and negative numbers in binary?
Two's Complement
How many bits is the GBA Architecture?
32 bits
What is a struct?
Chunks of memory that can contain multiple different types with ability to typedef it.
What are two things we can do with pointers? (And what do they do?)
Reference (access address in memory) and Dereference (access data at that memory address)
True or False: C is an Object-Oriented Language?
FALSE
Find both the One's and Two's Complement of this binary number:
10101100
One's Comp: 01010011
Two's Comp: 01010100
How does the GBA read bits? (Think endianness)
Little Endian --> LSb first (right to left)
What does RAM stand for? What does ROM stand for?
RAM = Random Access Memory
ROM = Read Only Memory
Arrays decay into ________ when passed into a function
Pointers
How can we make a basic state machine with three states (start, game, end), and what does this look like?
typedef enum STATE {
start,
game,
end
} state;
What is the result of this binary operation?
01110101 ^ 10111011
11001110
REG_DISPCTL --> 0x04000000
VideoBuffer --> 0x06000000
Create a struct for a bottle object that has members color (an unsigned short), label (an integer), and plasticType (a char).
typedef struct BOTTLE {
unsigned short color;
int label;
char plasticType;
} bottle;
What does the arrow operator do in C?
Allows us to access the members of a struct it is pointing at an dereference them
Using this struct, create a pool of 10 TAs and check to make initialize them all by setting their active property.
typedef struct TA {
char firstInitial;
int gradeYear;
int active;
} TA;
TA teachingAssistants[10];
for (TA t: teachingAssistants) {
t.active = 1;
}
Convert this hexadecimal number to binary and octal:
0x7FA2
Binary: 0111 1111 1010 0010
Octal: 77642
What are the three main components of the Von Neumann Architecture?
ALU, Control Unit, Memory that interacts with the CPU
How much space does this struct take in memory?
struct bin {
int number;
char x;
short y;
short z;
}
The actual data memory takes 10 bytes, but 12 bytes are "allocated."
Initialize an integer pointer called ptr that points to memory address 0x060000C8. Then change the value of that pointer to store 15 at that memory address.
int* ptr = 0x060000C8;
*ptr = 15;
Explain the difference between functions and macros, and provide an example of each.
Functions: uses call stack and is assembled as part of compilation.
Example: void updateGame();
Macro: uses direct text replacement for code readability --> no callstack --> preprocessor
Example: #define REG_BUTTONS 0x04000130
Find the result of this bitwise operation:
((0x7BE4 << 4) + (0x832B | 0xEF21))
11010110101101011
The leftmost 1 is a result of carrying a 1 through the addition.
Explain the importance of the VCount register on the GBA and why we have to reference it so often. (3 reasons)
Allows us to keep track of the scanline
Gives us a time period and abaility to use waitForVBlank() BEFORE we draw!
Prevents flicker
Write the collision() function between structs of type chair with members x, y, width, and height (all non0-negative integers). Do not assume the struct objects are predefined.
(I will write this on the board)
What is wrong with this swap function?
void swap(int* a, int* b) {
int* temp = a;
a = *b;
*b = temp;
}
By making temp a pointer, we are pointing to the pointer a, not its value, so we are unable to access the value at a currently. When we go to put the value of b in into temp, the value of a will be lost, since we don't actually swap the value.
Create the drawString() function in C. This function should take in four parameters (x, y, a char pointer, and a color). Assume the drawChar() function is correctly implemented, and characters in the string should be placed 6 pixels apart.
void drawString(int x, int y, char* str, u16 color) {
while (*str) {
drawChar(x, y, *str, color);
str++;
x+=6;
}
}