File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ void initialize(chip8 *chip) {
6060char c ;
6161int 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" );
6464scanf ("%c" , & c );
6565
6666while (loop ) {
@@ -73,6 +73,9 @@ void initialize(chip8 *chip) {
7373file_name = "PONG.bin" ;
7474loop = 0 ;
7575break ;
76+ case '3' :
77+ printf ("Exiting emulator...\n" );
78+ exit (0 );
7679default :
7780break ;
7881}
@@ -94,7 +97,6 @@ int load_file(char *file_name, unsigned char *buffer) {
9497int file_size ;
9598
9699// open file stream in binary read-only mode
97- // return error if file is too large or cannot be found
98100file = fopen (file_name , "rb" );
99101if (file == NULL ) { printf ("File not found.\n" ); return -1 ; }
100102else {
@@ -104,7 +106,9 @@ int load_file(char *file_name, unsigned char *buffer) {
104106printf ("ROM size: %d\n" , file_size );
105107rewind (file );
106108
109+ // return error if file is too large or cannot be found
107110if (file_size > MAX_FILE_SIZE ) { printf ("File is too large to load.\n" ); return -1 ; }
111+
108112// read program into memory
109113fread (buffer , 1 , file_size , file );
110114return 0 ;
Original file line number Diff line number Diff line change @@ -53,17 +53,17 @@ int main(int argc, char *argv[]) {
5353
5454// initialize orthographic 2D view, among other things
5555initGL ();
56+
57+ // handle key presses and releases
58+ glutKeyboardFunc (handle_key_press );
59+ glutKeyboardUpFunc (handle_key_release );
5660
5761// GLUT draw function
5862glutDisplayFunc (render );
5963
6064// GLUT idle function, causes screen to redraw
6165glutIdleFunc (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
6868glutMainLoop ();
6969
You can’t perform that action at this time.
0 commit comments