comparison src/video/xbios/SDL_xbios.c @ 4197:1bf6585720e9 SDL-1.2

Use loop to allocate needed buffers, instead of code duplication. Add missing header.
author Patrice Mandin <patmandin@gmail.com>
date Sat, 19 Sep 2009 21:58:59 +0000
parents 13de8ea401db
children 6405314a7c07
comparison
equal deleted inserted replaced
4196:89c7562eae9b 4197:1bf6585720e9
611 611
612 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, 612 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
613 int width, int height, int bpp, Uint32 flags) 613 int width, int height, int bpp, Uint32 flags)
614 { 614 {
615 int mode, new_depth; 615 int mode, new_depth;
616 int i; 616 int i, num_buffers;
617 xbiosmode_t *new_video_mode; 617 xbiosmode_t *new_video_mode;
618 Uint32 new_screen_size; 618 Uint32 new_screen_size;
619 Uint32 modeflags; 619 Uint32 modeflags;
620 620
621 /* Free current buffers */ 621 /* Free current buffers */
668 if (new_video_mode->doubleline) { 668 if (new_video_mode->doubleline) {
669 new_screen_size <<= 1; 669 new_screen_size <<= 1;
670 XBIOS_doubleline = SDL_TRUE; 670 XBIOS_doubleline = SDL_TRUE;
671 } 671 }
672 672
673 XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM); 673 /* Double buffer ? */
674 674 num_buffers = 1;
675 if (XBIOS_screensmem[0]==NULL) {
676 XBIOS_FreeBuffers(this);
677 SDL_SetError("Can not allocate %d KB for frame buffer", new_screen_size>>10);
678 return (NULL);
679 }
680 SDL_memset(XBIOS_screensmem[0], 0, new_screen_size);
681
682 XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
683 675
684 #if SDL_VIDEO_OPENGL 676 #if SDL_VIDEO_OPENGL
685 if (flags & SDL_OPENGL) { 677 if (flags & SDL_OPENGL) {
686 if (this->gl_config.double_buffer) { 678 if (this->gl_config.double_buffer) {
687 flags |= SDL_DOUBLEBUF; 679 flags |= SDL_DOUBLEBUF;
688 } 680 }
689 } 681 }
690 #endif 682 #endif
691
692 /* Double buffer ? */
693 if (flags & SDL_DOUBLEBUF) { 683 if (flags & SDL_DOUBLEBUF) {
694 XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM); 684 num_buffers = 2;
695 685 modeflags |= SDL_DOUBLEBUF;
696 if (XBIOS_screensmem[1]==NULL) { 686 }
687
688 /* Allocate buffers */
689 for (i=0; i<num_buffers; i++) {
690 XBIOS_screensmem[i] = Atari_SysMalloc(new_screen_size, MX_STRAM);
691
692 if (XBIOS_screensmem[i]==NULL) {
697 XBIOS_FreeBuffers(this); 693 XBIOS_FreeBuffers(this);
698 SDL_SetError("Can not allocate %d KB for double buffer", new_screen_size>>10); 694 SDL_SetError("Can not allocate %d KB for buffer %d", new_screen_size>>10, i);
699 return (NULL); 695 return (NULL);
700 } 696 }
701 SDL_memset(XBIOS_screensmem[1], 0, new_screen_size); 697 SDL_memset(XBIOS_screensmem[i], 0, new_screen_size);
702 698
703 XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL); 699 XBIOS_screens[i]=(void *) (( (long) XBIOS_screensmem[i]+256) & 0xFFFFFF00UL);
704 modeflags |= SDL_DOUBLEBUF;
705 } 700 }
706 701
707 /* Allocate the new pixel format for the screen */ 702 /* Allocate the new pixel format for the screen */
708 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) { 703 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
709 XBIOS_FreeBuffers(this); 704 XBIOS_FreeBuffers(this);