Thu, 10 Feb 2011 01:09:42 +0000
make it possible to eject the floppy disc (use F11!)
src/main.c | file | annotate | diff | revisions | |
src/state.h | file | annotate | diff | revisions |
1.1 --- a/src/main.c Thu Feb 10 01:09:04 2011 +0000 1.2 +++ b/src/main.c Thu Feb 10 01:09:42 2011 +0000 1.3 @@ -133,6 +133,23 @@ 1.4 return true; 1.5 case SDL_KEYDOWN: 1.6 switch (event.key.keysym.sym) { 1.7 + case SDLK_F11: 1.8 + if (state.fdc_disc) { 1.9 + wd2797_unload(&state.fdc_ctx); 1.10 + fclose(state.fdc_disc); 1.11 + state.fdc_disc = NULL; 1.12 + fprintf(stderr, "Disc image unloaded.\n"); 1.13 + } else { 1.14 + state.fdc_disc = fopen("discim", "rb"); 1.15 + if (!state.fdc_disc) { 1.16 + fprintf(stderr, "ERROR loading disc image 'discim'.\n"); 1.17 + state.fdc_disc = NULL; 1.18 + } else { 1.19 + wd2797_load(&state.fdc_ctx, state.fdc_disc, 512, 10, 2); 1.20 + fprintf(stderr, "Disc image loaded.\n"); 1.21 + } 1.22 + } 1.23 + break; 1.24 case SDLK_F12: 1.25 if (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT)) 1.26 // ALT-F12 pressed; exit emulator 1.27 @@ -197,12 +214,12 @@ 1.28 SDL_WM_SetCaption("FreeBee 3B1 emulator", "FreeBee"); 1.29 1.30 // Load a disc image 1.31 - FILE *disc = fopen("discim", "rb"); 1.32 - if (!disc) { 1.33 + state.fdc_disc = fopen("discim", "rb"); 1.34 + if (!state.fdc_disc) { 1.35 fprintf(stderr, "ERROR loading disc image 'discim'.\n"); 1.36 return -4; 1.37 } 1.38 - wd2797_load(&state.fdc_ctx, disc, 512, 10, 2); 1.39 + wd2797_load(&state.fdc_ctx, state.fdc_disc, 512, 10, 2); 1.40 1.41 /*** 1.42 * The 3B1 CPU runs at 10MHz, with DMA running at 1MHz and video refreshing at 1.43 @@ -379,7 +396,7 @@ 1.44 1.45 // Release the disc image 1.46 wd2797_unload(&state.fdc_ctx); 1.47 - fclose(disc); 1.48 + fclose(state.fdc_disc); 1.49 1.50 return 0; 1.51 }
2.1 --- a/src/state.h Thu Feb 10 01:09:04 2011 +0000 2.2 +++ b/src/state.h Thu Feb 10 01:09:42 2011 +0000 2.3 @@ -71,6 +71,8 @@ 2.4 2.5 /// Floppy disc controller context 2.6 WD2797_CTX fdc_ctx; 2.7 + /// Current disc image file 2.8 + FILE *fdc_disc; 2.9 2.10 /// Keyboard controller context 2.11 KEYBOARD_STATE kbd;