make it possible to eject the floppy disc (use F11!)

Thu, 10 Feb 2011 01:09:42 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Thu, 10 Feb 2011 01:09:42 +0000
changeset 95
6e01339b218d
parent 94
80872ecf64fa
child 96
45ae4c97155b

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