1.1 diff -r acea4b2f396f -r 4c85846b09cd src/main.c 1.2 --- a/src/main.c Thu Dec 08 23:44:19 2011 +0000 1.3 +++ b/src/main.c Sat Nov 17 19:13:08 2012 +0000 1.4 @@ -19,6 +19,26 @@ 1.5 exit(EXIT_FAILURE); 1.6 } 1.7 1.8 +static int load_fd() 1.9 +{ 1.10 + 1.11 + int writeable = 1; 1.12 + state.fdc_disc = fopen("discim", "r+b"); 1.13 + if (!state.fdc_disc){ 1.14 + writeable = 0; 1.15 + state.fdc_disc = fopen("discim", "rb"); 1.16 + } 1.17 + if (!state.fdc_disc){ 1.18 + fprintf(stderr, "ERROR loading disc image 'discim'.\n"); 1.19 + state.fdc_disc = NULL; 1.20 + return (0); 1.21 + }else{ 1.22 + wd2797_load(&state.fdc_ctx, state.fdc_disc, 512, 10, 2, writeable); 1.23 + fprintf(stderr, "Disc image loaded.\n"); 1.24 + return (1); 1.25 + } 1.26 +} 1.27 + 1.28 /** 1.29 * @brief Set the pixel at (x, y) to the given value 1.30 * @note The surface must be locked before calling this! 1.31 @@ -140,14 +160,7 @@ 1.32 state.fdc_disc = NULL; 1.33 fprintf(stderr, "Disc image unloaded.\n"); 1.34 } else { 1.35 - state.fdc_disc = fopen("discim", "rb"); 1.36 - if (!state.fdc_disc) { 1.37 - fprintf(stderr, "ERROR loading disc image 'discim'.\n"); 1.38 - state.fdc_disc = NULL; 1.39 - } else { 1.40 - wd2797_load(&state.fdc_ctx, state.fdc_disc, 512, 10, 2); 1.41 - fprintf(stderr, "Disc image loaded.\n"); 1.42 - } 1.43 + load_fd(); 1.44 } 1.45 break; 1.46 case SDLK_F12: 1.47 @@ -214,12 +227,7 @@ 1.48 SDL_WM_SetCaption("FreeBee 3B1 emulator", "FreeBee"); 1.49 1.50 // Load a disc image 1.51 - state.fdc_disc = fopen("discim", "rb"); 1.52 - if (!state.fdc_disc) { 1.53 - fprintf(stderr, "ERROR loading disc image 'discim'.\n"); 1.54 - return -4; 1.55 - } 1.56 - wd2797_load(&state.fdc_ctx, state.fdc_disc, 512, 10, 2); 1.57 + load_fd(); 1.58 1.59 /*** 1.60 * The 3B1 CPU runs at 10MHz, with DMA running at 1MHz and video refreshing at 1.61 @@ -345,8 +353,11 @@ 1.62 // state.dma_count = 0; 1.63 state.dmaen = false; 1.64 } 1.65 + }else if (wd2797_get_drq(&state.fdc_ctx)){ 1.66 + wd2797_dma_miss(&state.fdc_ctx); 1.67 } 1.68 1.69 + 1.70 // Any interrupts? --> TODO: masking 1.71 /* if (!lastirq_fdc) { 1.72 if (wd2797_get_irq(&state.fdc_ctx)) { 1.73 @@ -354,12 +365,13 @@ 1.74 m68k_set_irq(2); 1.75 } 1.76 */ 1.77 - if (keyboard_get_irq(&state.kbd)) { 1.78 + if (wd2797_get_irq(&state.fdc_ctx)){ 1.79 + m68k_set_irq(2); 1.80 + }else if (keyboard_get_irq(&state.kbd)) { 1.81 m68k_set_irq(3); 1.82 } else { 1.83 - lastirq_fdc = wd2797_get_irq(&state.fdc_ctx); 1.84 // if (!state.timer_asserted){ 1.85 -// m68k_set_irq(0); 1.86 + m68k_set_irq(0); 1.87 // } 1.88 } 1.89