static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) { SDL_MintAudio_device = this; /* Check audio capabilities */ if (Mint_CheckAudio(this, spec)==-1) { return -1; } SDL_CalculateAudioSpec(spec); /* Allocate memory for audio buffers in DMA-able RAM */ DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); if (SDL_MintAudio_audiobuf[0]==NULL) { SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); return (-1); } SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; SDL_MintAudio_numbuf=0; SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); SDL_MintAudio_audiosize = spec->size; SDL_MintAudio_mutex = 0; DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); SDL_MintAudio_CheckFpu(); /* Setup audio hardware */ Mint_InitAudio(this, spec); return(1); /* We don't use threaded audio */ }
static int Mint_OpenAudio(_THIS, SDL_AudioSpec *spec) { SDL_MintAudio_device = this; if (Mint_CheckAudio(this, spec)==-1) { return -1; } SDL_CalculateAudioSpec(spec); DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size)); SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size *2, MX_STRAM); if (SDL_MintAudio_audiobuf[0]==NULL) { SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer"); return (-1); } SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ; SDL_MintAudio_numbuf=0; SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2); SDL_MintAudio_audiosize = spec->size; SDL_MintAudio_mutex = 0; DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); SDL_MintAudio_CheckFpu(); Mint_InitAudio(this, spec); return(1); }
static int MINTSTFA_OpenDevice(_THIS, const char *devname, int iscapture) { SDL_MintAudio_device = this; /* Check audio capabilities */ if (MINTSTFA_CheckAudio(this) == -1) { return 0; } /* Initialize all variables that we clean on shutdown */ this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { SDL_OutOfMemory(); return 0; } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_CalculateAudioSpec(&this->spec); /* Allocate memory for audio buffers in DMA-able RAM */ DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size)); SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM); if (SDL_MintAudio_audiobuf[0] == NULL) { SDL_OutOfMemory(); SDL_free(this->hidden); this->hidden = NULL; return 0; } SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size; SDL_MintAudio_numbuf = 0; SDL_memset(SDL_MintAudio_audiobuf[0], this->spec.silence, this->spec.size * 2); SDL_MintAudio_audiosize = this->spec.size; SDL_MintAudio_mutex = 0; DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n", SDL_MintAudio_audiobuf[0])); DEBUG_PRINT((DEBUG_NAME "buffer 1 at 0x%08x\n", SDL_MintAudio_audiobuf[1])); SDL_MintAudio_CheckFpu(); /* Setup audio hardware */ MINTSTFA_InitAudio(this); return 1; /* good to go. */ }
SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int maxwidth, maxheight; Uint32 modeflags, screensize; SDL_bool use_shadow; GEM_FreeBuffers(this); /*--- Verify if asked mode can be used ---*/ if (flags & SDL_FULLSCREEN) { maxwidth=VDI_w; maxheight=VDI_h; } else { /* Windowed mode */ maxwidth=GEM_desk_w; maxheight=GEM_desk_h; } if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) { SDL_SetError("Couldn't find requested mode in list"); return(NULL); } /*--- Allocate the new pixel format for the screen ---*/ if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) { SDL_SetError("Couldn't allocate new pixel format for requested mode"); return(NULL); } /*--- Allocate shadow buffer if needed ---*/ use_shadow=SDL_FALSE; if (flags & SDL_FULLSCREEN) { if (!VDI_screen) { /* No access to real framebuffer, use shadow surface */ use_shadow=SDL_TRUE; } else { if (VDI_format==VDI_FORMAT_INTER) { /* Real framebuffer, interleaved bitplanes, use shadow surface */ use_shadow=SDL_TRUE; } else if (flags & SDL_DOUBLEBUF) { /* Real framebuffer, double-buffered, use shadow surface */ use_shadow=SDL_TRUE; modeflags |= SDL_DOUBLEBUF; } } } else { /* Windowed mode, always with shadow surface */ use_shadow=SDL_TRUE; } if (use_shadow) { screensize = width * height * VDI_pixelsize; GEM_buffer = Atari_SysMalloc(screensize, MX_PREFTTRAM); if (GEM_buffer==NULL) { fprintf(stderr,"Unable to allocate shadow buffer\n"); return NULL; } memset(GEM_buffer, 0, screensize); } /*--- Initialize screen ---*/ modeflags = 0; if (VDI_bpp == 8) { modeflags |= SDL_HWPALETTE; } if (flags & SDL_FULLSCREEN) { GEM_LockScreen(this); GEM_ClearScreen(this); modeflags |= SDL_FULLSCREEN; if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow) { modeflags |= SDL_HWSURFACE; } else { modeflags |= SDL_SWSURFACE; } } else { int posx,posy; short x2,y2,w2,h2; GEM_UnlockScreen(this); /* Center our window */ posx = GEM_desk_x; posy = GEM_desk_y; if (width<GEM_desk_w) posx += (GEM_desk_w - width) >> 1; if (height<GEM_desk_h) posy += (GEM_desk_h - height) >> 1; /* Calculate our window size and position */ if (!(flags & SDL_NOFRAME)) { GEM_win_type=NAME|MOVER|CLOSER|SMALLER; if (flags & SDL_RESIZABLE) { GEM_win_type |= FULLER|SIZER; modeflags |= SDL_RESIZABLE; } } else { GEM_win_type=0; modeflags |= SDL_NOFRAME; } if (!wind_calc(0, GEM_win_type, posx, posy, width, height, &x2, &y2, &w2, &h2)) { GEM_FreeBuffers(this); fprintf(stderr,"Can not calculate window attributes\n"); return NULL; } /* Create window */ GEM_handle=wind_create(GEM_win_type, x2, y2, w2, h2); if (GEM_handle<0) { GEM_FreeBuffers(this); fprintf(stderr,"Can not create window\n"); return NULL; } /* Setup window name */ wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); /* Open the window */ wind_open(GEM_handle,x2,y2,w2,h2); modeflags |= SDL_SWSURFACE; } /* Set up the new mode framebuffer */ current->flags = modeflags; current->w = width; current->h = height; if (use_shadow) { current->pixels = GEM_buffer; current->pitch = width * (VDI_bpp >> 3); } else {
int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i, menubar_size; short work_in[12], work_out[272], dummy; /* Open AES (Application Environment Services) */ if (appl_init() == -1) { fprintf(stderr,"Can not open AES\n"); return 1; } /* Read version and features */ GEM_version = aes_global[0]; if (GEM_version >= 0x0410) { short ap_gout[4], errorcode; GEM_wfeatures=0; errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]); if (errorcode==0) { GEM_wfeatures=ap_gout[0]; } } /* Ask VDI physical workstation handle opened by AES */ VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy); if (VDI_handle<1) { fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle); return 1; } /* Open virtual VDI workstation */ work_in[0]=Getrez()+2; for(i = 1; i < 10; i++) work_in[i] = 1; work_in[10] = 2; v_opnvwk(work_in, &VDI_handle, work_out); if (VDI_handle == 0) { fprintf(stderr,"Can not open VDI virtual workstation\n"); return 1; } /* Read fullscreen size */ VDI_w = work_out[0] + 1; VDI_h = work_out[1] + 1; /* Read desktop size and position */ if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) { fprintf(stderr,"Can not read desktop properties\n"); return 1; } /* Read bit depth */ vq_extnd(VDI_handle, 1, work_out); VDI_bpp = work_out[4]; VDI_oldnumcolors=0; switch(VDI_bpp) { case 8: VDI_pixelsize=1; break; case 15: case 16: VDI_pixelsize=2; break; case 24: VDI_pixelsize=3; break; case 32: VDI_pixelsize=4; break; default: fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp); return 1; } /* Setup hardware -> VDI palette mapping */ for(i = 16; i < 255; i++) { vdi_index[i] = i; } vdi_index[255] = 1; /* Save current palette */ if (VDI_bpp>8) { VDI_oldnumcolors=1<<8; } else { VDI_oldnumcolors=1<<VDI_bpp; } for(i = 0; i < VDI_oldnumcolors; i++) { short rgb[3]; vq_color(VDI_handle, i, 0, rgb); VDI_oldpalette[i][0] = rgb[0]; VDI_oldpalette[i][1] = rgb[1]; VDI_oldpalette[i][2] = rgb[2]; } VDI_setpalette = GEM_SetNewPalette; SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette)); /* Setup screen info */ GEM_title_name = empty_name; GEM_icon_name = empty_name; GEM_handle = -1; GEM_locked = SDL_FALSE; GEM_win_fulled = SDL_FALSE; GEM_fullscreen = SDL_FALSE; GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */ VDI_screen = NULL; VDI_pitch = VDI_w * VDI_pixelsize; VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK); VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0; VDI_ReadExtInfo(this, work_out); #ifdef DEBUG_VIDEO_GEM printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch); printf("sdl:video:gem: format=%d\n", VDI_format); printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask ); #endif /* Setup destination mfdb */ VDI_dst_mfdb.fd_addr = NULL; /* Determine the current screen size */ this->info.current_w = VDI_w; this->info.current_h = VDI_h; /* Determine the screen depth */ /* we change this during the SDL_SetVideoMode implementation... */ vformat->BitsPerPixel = VDI_bpp; /* Set mouse cursor to arrow */ graf_mouse(ARROW, NULL); GEM_cursor = NULL; /* Init chunky to planar routine */ SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; /* Setup VDI fill functions */ vsf_color(VDI_handle,0); vsf_interior(VDI_handle,1); vsf_perimeter(VDI_handle,0); /* Menu bar save buffer */ menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize; GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM); /* Fill video modes list */ SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect)); SDL_modelist[0]->x = 0; SDL_modelist[0]->y = 0; SDL_modelist[0]->w = VDI_w; SDL_modelist[0]->h = VDI_h; SDL_modelist[1] = NULL; #if SDL_VIDEO_OPENGL SDL_AtariGL_InitPointers(this); #endif this->info.wm_available = 1; /* We're done! */ return(0); }
static void Mint_CheckExternalClock(_THIS) { #define SIZE_BUF_CLOCK_MEASURE (44100/10) char *buffer; int i, j; if ((cookie_snd & SND_DSP)==0) { return; } buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); if (buffer==NULL) { DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); return; } SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); Buffoper(0); Settracks(0,0); Setmontracks(0); Setmode(MONO8); Jdisint(MFP_TIMERA); for (i=0; i<2; i++) { Gpio(GPIO_SET,7); Gpio(GPIO_WRITE,2+i); Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); Jenabint(MFP_TIMERA); SDL_MintAudio_clocktics = 0; Buffoper(SB_PLA_ENA); usleep(110000); if((Buffoper(-1) & 1)==0) { if (SDL_MintAudio_clocktics) { unsigned long khz; khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); if(khz==44) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i); } } else if (khz==48) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i); } } } else { DEBUG_PRINT((DEBUG_NAME "No measure\n")); } } else { DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); } Buffoper(0); Jdisint(MFP_TIMERA); } Mfree(buffer); }
int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat) { int i, menubar_size; short work_in[12], work_out[272], dummy; if (appl_init() == -1) { fprintf(stderr,"Can not open AES\n"); return 1; } GEM_version = aes_global[0]; if (GEM_version >= 0x0410) { short ap_gout[4], errorcode; GEM_wfeatures=0; errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]); if (errorcode==0) { GEM_wfeatures=ap_gout[0]; } } VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy); if (VDI_handle<1) { fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle); return 1; } work_in[0]=Getrez()+2; for(i = 1; i < 10; i++) work_in[i] = 1; work_in[10] = 2; v_opnvwk(work_in, &VDI_handle, work_out); if (VDI_handle == 0) { fprintf(stderr,"Can not open VDI virtual workstation\n"); return 1; } VDI_w = work_out[0] + 1; VDI_h = work_out[1] + 1; if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) { fprintf(stderr,"Can not read desktop properties\n"); return 1; } vq_extnd(VDI_handle, 1, work_out); VDI_bpp = work_out[4]; VDI_oldnumcolors=0; switch(VDI_bpp) { case 8: VDI_pixelsize=1; break; case 15: case 16: VDI_pixelsize=2; break; case 24: VDI_pixelsize=3; break; case 32: VDI_pixelsize=4; break; default: fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp); return 1; } for(i = 16; i < 255; i++) { vdi_index[i] = i; } vdi_index[255] = 1; if (VDI_bpp>8) { VDI_oldnumcolors=1<<8; } else { VDI_oldnumcolors=1<<VDI_bpp; } for(i = 0; i < VDI_oldnumcolors; i++) { short rgb[3]; vq_color(VDI_handle, i, 0, rgb); VDI_oldpalette[i][0] = rgb[0]; VDI_oldpalette[i][1] = rgb[1]; VDI_oldpalette[i][2] = rgb[2]; } VDI_setpalette = GEM_SetNewPalette; SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette)); GEM_title_name = empty_name; GEM_icon_name = empty_name; GEM_handle = -1; GEM_locked = SDL_FALSE; GEM_win_fulled = SDL_FALSE; GEM_fullscreen = SDL_FALSE; GEM_lock_redraw = SDL_TRUE; VDI_screen = NULL; VDI_pitch = VDI_w * VDI_pixelsize; VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK); VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0; VDI_ReadExtInfo(this, work_out); #ifdef DEBUG_VIDEO_GEM printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch); printf("sdl:video:gem: format=%d\n", VDI_format); printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask ); #endif VDI_dst_mfdb.fd_addr = NULL; this->info.current_w = VDI_w; this->info.current_h = VDI_h; vformat->BitsPerPixel = VDI_bpp; graf_mouse(ARROW, NULL); GEM_cursor = NULL; SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; vsf_color(VDI_handle,0); vsf_interior(VDI_handle,1); vsf_perimeter(VDI_handle,0); menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize; GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM); SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect)); SDL_modelist[0]->x = 0; SDL_modelist[0]->y = 0; SDL_modelist[0]->w = VDI_w; SDL_modelist[0]->h = VDI_h; SDL_modelist[1] = NULL; #if SDL_VIDEO_OPENGL SDL_AtariGL_InitPointers(this); #endif this->info.wm_available = 1; return(0); }
static void Mint_CheckExternalClock(_THIS) { #define SIZE_BUF_CLOCK_MEASURE (44100/10) unsigned long cookie_snd; char *buffer; int i, j; /* DSP present with its GPIO port ? */ if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) { return; } if ((cookie_snd & SND_DSP)==0) { return; } buffer = Atari_SysMalloc(SIZE_BUF_CLOCK_MEASURE, MX_STRAM); if (buffer==NULL) { DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n")); return; } SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE); Buffoper(0); Settracks(0,0); Setmontracks(0); Setmode(MONO8); Jdisint(MFP_TIMERA); for (i=0; i<2; i++) { Gpio(GPIO_SET,7); /* DSP port gpio outputs */ Gpio(GPIO_WRITE,2+i); /* 22.5792/24.576 MHz for 44.1/48KHz */ Devconnect2(DMAPLAY, DAC, CLKEXT, CLK50K); /* Matrix and clock source */ Setbuffer(0, buffer, buffer + SIZE_BUF_CLOCK_MEASURE); /* Set buffer */ Xbtimer(XB_TIMERA, 5, 38, SDL_MintAudio_XbiosInterruptMeasureClock); /* delay mode timer A, prediv /64, 1KHz */ Jenabint(MFP_TIMERA); SDL_MintAudio_clocktics = 0; Buffoper(SB_PLA_ENA); usleep(110000); if((Buffoper(-1) & 1)==0) { if (SDL_MintAudio_clocktics) { unsigned long khz; khz = ((SIZE_BUF_CLOCK_MEASURE/SDL_MintAudio_clocktics) +1) & 0xFFFFFFFE; DEBUG_PRINT((DEBUG_NAME "measure %d: freq=%lu KHz\n", i+1, khz)); if(khz==44) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_44K, (1<<j)-1, 2+i); } } else if (khz==48) { for (j=1; j<4; j++) { SDL_MintAudio_AddFrequency(this, MASTERCLOCK_48K/(MASTERPREDIV_FALCON*(1<<j)), MASTERCLOCK_48K, (1<<j)-1, 2+i); } } } else { DEBUG_PRINT((DEBUG_NAME "No measure\n")); } } else { DEBUG_PRINT((DEBUG_NAME "No SDMA clock\n")); } Buffoper(0); /* stop */ Jdisint(MFP_TIMERA); /* Uninstall interrupt */ } Mfree(buffer); }