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