Skip to content

Commit 3066034

Browse files
committed
formatting
1 parent 8930e5f commit 3066034

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

chip8.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void initialize(chip8 *chip) {
6060
char c;
6161
int loop = 1;
6262

63-
printf("Please select a game from the list.\n1.TETRIS\n2.PONG\n");
63+
printf("Please select a game from the list (enter a number).\n1.TETRIS\n2.PONG\n3.EXIT\n");
6464
scanf("%c", &c);
6565

6666
while (loop) {
@@ -73,6 +73,9 @@ void initialize(chip8 *chip) {
7373
file_name = "PONG.bin";
7474
loop = 0;
7575
break;
76+
case '3':
77+
printf("Exiting emulator...\n");
78+
exit(0);
7679
default:
7780
break;
7881
}
@@ -94,7 +97,6 @@ int load_file(char *file_name, unsigned char *buffer) {
9497
int file_size;
9598

9699
// open file stream in binary read-only mode
97-
// return error if file is too large or cannot be found
98100
file = fopen(file_name, "rb");
99101
if (file == NULL) { printf("File not found.\n"); return -1; }
100102
else {
@@ -104,7 +106,9 @@ int load_file(char *file_name, unsigned char *buffer) {
104106
printf("ROM size: %d\n", file_size);
105107
rewind(file);
106108

109+
// return error if file is too large or cannot be found
107110
if (file_size > MAX_FILE_SIZE) { printf("File is too large to load.\n"); return -1; }
111+
108112
// read program into memory
109113
fread(buffer, 1, file_size, file);
110114
return 0;

emulator

0 Bytes
Binary file not shown.

emulator.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ int main(int argc, char *argv[]) {
5353

5454
// initialize orthographic 2D view, among other things
5555
initGL();
56+
57+
// handle key presses and releases
58+
glutKeyboardFunc(handle_key_press);
59+
glutKeyboardUpFunc(handle_key_release);
5660

5761
// GLUT draw function
5862
glutDisplayFunc(render);
5963

6064
// GLUT idle function, causes screen to redraw
6165
glutIdleFunc(idle);
6266

63-
// handles key presses and releases
64-
glutKeyboardFunc(handle_key_press);
65-
glutKeyboardUpFunc(handle_key_release);
66-
6767
// main loop, all events processed here
6868
glutMainLoop();
6969

0 commit comments

Comments
 (0)