~sergio-br2/vbam/fixes_have-svg-icons

« back to all changes in this revision

Viewing changes to src/sdl/SDL.cpp

  • Committer: mudlord
  • Date: 2008-01-17 04:51:34 UTC
  • Revision ID: svn-v4:a31d4220-a93d-0410-bf67-fe4944624d44:trunk:309
Numerous Linux updates:
- OpenGL : fixed texture size to be exclusively a power of 2
- OpenGL : Clear the screen on init
- OpenGL : Set fullscreen resolution to the resolution of the desktop
- Changed the executable name to vbam to avoid conflict with the original VBA
- Added a basic install target to the makefile
- Fixed .gz archives loading when using fex_mini (thanks to tttttttttanaka)
- Added debian packaging informations

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <string.h>
23
23
#include <sys/types.h>
24
24
#include <sys/stat.h>
 
25
#include <cmath>
25
26
#ifdef __APPLE__
26
27
    #include <OpenGL/glu.h>
27
28
    #include <OpenGL/glext.h>
120
121
int srcHeight = 0;
121
122
int destWidth = 0;
122
123
int destHeight = 0;
 
124
int desktopWidth = 0;
 
125
int desktopHeight = 0;
123
126
 
124
127
int sensorX = 2047;
125
128
int sensorY = 2047;
147
150
u32 systemColorMap32[0x10000];
148
151
u16 systemColorMap16[0x10000];
149
152
u16 systemGbPalette[24];
150
 
void (*filterFunction)(u8*,u32,u8*,u8*,u32,int,int) = NULL;
 
153
FilterFunc filterFunction = NULL;
151
154
void (*ifbFunction)(u8*,u32,int,int) = NULL;
152
155
int ifbType = 0;
153
156
char filename[2048];
154
157
char ipsname[2048];
155
158
char biosFileName[2048];
 
159
char gbBiosFileName[2048];
156
160
char captureDir[2048];
157
161
char saveDir[2048];
158
162
char batteryDir[2048];
412
416
#ifdef _WIN32
413
417
#define PATH_SEP ";"
414
418
#define FILE_SEP '\\'
415
 
#define EXE_NAME "VisualBoyAdvance-SDL.exe"
 
419
#define EXE_NAME "vbam.exe"
416
420
#else // ! _WIN32
417
421
#define PATH_SEP ":"
418
422
#define FILE_SEP '/'
419
 
#define EXE_NAME "VisualBoyAdvance"
 
423
#define EXE_NAME "vbam"
420
424
#endif // ! _WIN32
421
425
 
422
426
  fprintf(stderr, "Searching for file %s\n", name);
652
656
      skipBios = sdlFromHex(value) ? true : false;
653
657
    } else if(!strcmp(key, "biosFile")) {
654
658
      strcpy(biosFileName, value);
 
659
    } else if(!strcmp(key, "gbBiosFile")) {
 
660
      strcpy(gbBiosFileName, value);
655
661
    } else if(!strcmp(key, "filter")) {
656
662
      filter = sdlFromHex(value);
657
663
      if(filter < 0 || filter > 17)
790
796
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
791
797
                  openGL == 2 ? GL_LINEAR : GL_NEAREST);
792
798
 
793
 
  textureSize = 256 * filter_enlarge;
 
799
  // Calculate texture size as a the smallest working power of two
 
800
  float n1 = log10((float)destWidth ) / log10( 2.0f);
 
801
  float n2 = log10((float)destHeight ) / log10( 2.0f);
 
802
  float n = (n1 > n2)? n1 : n2;
 
803
 
 
804
    // round up
 
805
  if (((float)((int)n)) != n)
 
806
    n = ((float)((int)n)) + 1.0f;
 
807
 
 
808
  textureSize = (int)pow(2.0f, n);
 
809
 
794
810
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSize, textureSize, 0,
795
811
               GL_BGRA, GL_UNSIGNED_BYTE, NULL);
 
812
 
 
813
  glClearColor(0.0,0.0,0.0,1.0);
 
814
  glClear( GL_COLOR_BUFFER_BIT );
796
815
}
797
816
 
798
817
void sdlReadPreferences()
998
1017
    systemScreenMessage("Loaded battery");
999
1018
}
1000
1019
 
 
1020
void sdlReadDesktopVideoMode() {
 
1021
  const SDL_VideoInfo* vInfo = SDL_GetVideoInfo();
 
1022
  desktopWidth = vInfo->current_w;
 
1023
  desktopHeight = vInfo->current_h;
 
1024
}
 
1025
 
1001
1026
void sdlInitVideo() {
1002
1027
  int flags;
 
1028
  int screenWidth;
 
1029
  int screenHeight;
1003
1030
 
1004
1031
  filter_enlarge = getFilterEnlargeFactor((Filter)filter);
1005
1032
  destWidth = filter_enlarge * srcWidth;
1012
1039
  } else
1013
1040
    flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
1014
1041
 
1015
 
  surface = SDL_SetVideoMode(destWidth, destHeight, 0, flags);
 
1042
  if (fullscreen && openGL) {
 
1043
    screenWidth = desktopWidth;
 
1044
    screenHeight = desktopHeight;
 
1045
  } else {
 
1046
    screenWidth = destWidth;
 
1047
    screenHeight = destHeight;
 
1048
  }
 
1049
  
 
1050
  surface = SDL_SetVideoMode(screenWidth, screenHeight, 0, flags);
1016
1051
 
1017
1052
  if(surface == NULL) {
1018
1053
    systemMessage(0, "Failed to set video mode");
1020
1055
    exit(-1);
1021
1056
  }
1022
1057
 
1023
 
  if(openGL) {
1024
 
    free(filterPix);
1025
 
    filterPix = (u8 *)calloc(1, 4 * destWidth * destHeight);
1026
 
    sdlOpenGLInit(destWidth, destHeight);
1027
 
  }
1028
 
 
1029
1058
  systemRedShift = sdlCalculateShift(surface->format->Rmask);
1030
1059
  systemGreenShift = sdlCalculateShift(surface->format->Gmask);
1031
1060
  systemBlueShift = sdlCalculateShift(surface->format->Bmask);
1040
1069
    else
1041
1070
      srcPitch = srcWidth*3;
1042
1071
  }
 
1072
 
 
1073
  if(openGL) {
 
1074
    free(filterPix);
 
1075
    filterPix = (u8 *)calloc(1, (systemColorDepth >> 3) * destWidth * destHeight);
 
1076
    sdlOpenGLInit(screenWidth, screenHeight);
 
1077
  }
 
1078
 
1043
1079
}
1044
1080
 
1045
1081
#define MOD_KEYS    (KMOD_CTRL|KMOD_SHIFT|KMOD_ALT|KMOD_META)
1573
1609
 
1574
1610
int main(int argc, char **argv)
1575
1611
{
1576
 
  fprintf(stderr, "VisualBoyAdvance version %s [SDL]\n", VERSION);
 
1612
  fprintf(stderr, "VBA-M version %s [SDL]\n", VERSION);
1577
1613
 
1578
1614
  arg0 = argv[0];
1579
1615
 
1821
1857
 
1822
1858
        // used for the handling of the gb Boot Rom
1823
1859
        if (gbHardware & 5)
1824
 
        {
1825
 
                            char tempName[0x800];
1826
 
                            strcpy(tempName, arg0);
1827
 
                            char *p = strrchr(tempName, '\\');
1828
 
                            if(p) { *p = 0x00; }
1829
 
                            strcat(tempName, "\\DMG_ROM.bin");
1830
 
          fprintf(stderr, "%s\n", tempName);
1831
 
                            gbCPUInit(tempName, useBios);
1832
 
        }
1833
 
        else useBios = false;
 
1860
          gbCPUInit(gbBiosFileName, useBios);
1834
1861
 
1835
1862
        gbReset();
1836
1863
        cartridgeType = IMAGE_GB;
1937
1964
    srcHeight = 240;
1938
1965
  }
1939
1966
 
 
1967
  sdlReadDesktopVideoMode();
 
1968
 
1940
1969
  sdlInitVideo();
1941
1970
 
1942
1971
  filterFunction = initFilter((Filter)filter, systemColorDepth, srcWidth);
2565
2594
 
2566
2595
void systemGbBorderOn()
2567
2596
{
2568
 
  long flags;
2569
2597
  srcWidth = 256;
2570
2598
  srcHeight = 224;
2571
2599
  gbBorderLineSkip = 256;
2575
2603
  sdlInitVideo();
2576
2604
 
2577
2605
  filterFunction = initFilter((Filter)filter, systemColorDepth, srcWidth);
2578
 
 
2579
 
  if(systemColorDepth == 16) {
2580
 
    if(sdlCalculateMaskWidth(surface->format->Gmask) == 6) {
2581
 
      RGB_LOW_BITS_MASK = 0x821;
2582
 
    } else {
2583
 
      RGB_LOW_BITS_MASK = 0x421;
2584
 
    }
2585
 
    if(cartridgeType == 2) {
2586
 
      for(int i = 0; i < 0x10000; i++) {
2587
 
        systemColorMap16[i] = (((i >> 1) & 0x1f) << systemBlueShift) |
2588
 
          (((i & 0x7c0) >> 6) << systemGreenShift) |
2589
 
          (((i & 0xf800) >> 11) << systemRedShift);
2590
 
      }
2591
 
    } else {
2592
 
      for(int i = 0; i < 0x10000; i++) {
2593
 
        systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
2594
 
          (((i & 0x3e0) >> 5) << systemGreenShift) |
2595
 
          (((i & 0x7c00) >> 10) << systemBlueShift);
2596
 
      }
2597
 
    }
2598
 
  } else {
2599
 
    RGB_LOW_BITS_MASK = 0x010101;
2600
 
    for(int i = 0; i < 0x10000; i++) {
2601
 
      systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
2602
 
        (((i & 0x3e0) >> 5) << systemGreenShift) |
2603
 
        (((i & 0x7c00) >> 10) << systemBlueShift);
2604
 
    }
2605
 
  }
2606
2606
}