Browse Source

Last irixxxx's GG support/fixes.

root 2 years ago
parent
commit
24603d1ef4

+ 1 - 1
package

@@ -28,7 +28,7 @@ esac
 
 print '[Desktop Entry]
 Name=Mega Drive
-Comment=MS/MD/MCD/32X emulator
+Comment=SMS/GG/MD/MCD/32X emulator
 Exec=picodrive.sh %f
 Icon=picodrive
 Categories=emulators;

+ 1 - 0
pico/cart.c

@@ -243,6 +243,7 @@ zip_failed:
     file->param = cso;
     file->size  = cso->header.total_bytes;
     file->type  = PMT_CSO;
+    strncpy(file->ext, ext, sizeof(file->ext) - 1);
     return file;
 
 cso_failed:

+ 3 - 2
pico/media.c

@@ -259,7 +259,6 @@ enum media_type_e PicoLoadMedia(const char *filename,
   }
 
   ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoIn.AHW & PAHW_SMS) ? 1 : 0);
-  pm_close(rom);
   if (ret != 0) {
     if      (ret == 2) lprintf("Out of memory\n");
     else if (ret == 3) lprintf("Read failed\n");
@@ -299,7 +298,7 @@ enum media_type_e PicoLoadMedia(const char *filename,
 
   // simple test for GG. Do this here since m.hardware is nulled in Insert
   if (PicoIn.AHW & PAHW_SMS) {
-    if (strstr(filename,".gg")) {
+    if (!strcmp(rom->ext,"gg")) {
       Pico.m.hardware |= 0x1;
       lprintf("detected GG ROM\n");
     } else
@@ -322,6 +321,8 @@ enum media_type_e PicoLoadMedia(const char *filename,
     PicoSetInputDevice(0, PICO_INPUT_PAD_6BTN);
 
 out:
+  if (rom)
+    pm_close(rom);
   if (rom_data)
     free(rom_data);
   return media_type;

+ 4 - 5
pico/mode4.c

@@ -199,8 +199,6 @@ static void DrawStripLowM4(const u16 *nametab, int cells_dx, int tilex_ty)
     unsigned code;
 
     code = nametab[tilex_ty& 0x1f];
-    if (code & 0x1000) // priority high?
-      continue;
 
     if (code != oldcode) {
       oldcode = code;
@@ -328,7 +326,7 @@ static void DrawDisplayM4(int scanline)
       DrawStripHighM4(nametab , dx | ( cells    << 16), tilex  | (ty  << 16));
   }
 
-  if (pv->reg[0] & 0x20) {
+  if ((pv->reg[0] & 0x20) && (Pico.m.hardware & 0x3) != 3) {
     // first column masked with background, caculate offset to start of line
     dx = (dx&~0x1f) / 4;
     ty = 0xe0e0e0e0; // really (pv->reg[7]&0x3f) * 0x01010101, but the looks...
@@ -566,7 +564,7 @@ void PicoFrameStartSMS(void)
     columns = 320;
   } else
     coffs = PicoIn.opt & POPT_DIS_32C_BORDER ? 0:(320-columns)/2;
-  line_offset = (PicoIn.opt & POPT_ALT_RENDERER ? coffs : 0);
+  line_offset = (FinalizeLineSMS == NULL ? coffs : 0);
 
   if (FinalizeLineSMS == FinalizeLineRGB555SMS)
     line_offset = 0 /* done in FinalizeLine */;
@@ -672,7 +670,8 @@ void PicoDrawSetOutputSMS(pdso_t which)
   {
     case PDF_8BIT:   FinalizeLineSMS = FinalizeLine8bitSMS; break;
     case PDF_RGB555: FinalizeLineSMS = FinalizeLineRGB555SMS; break;
-    default:         FinalizeLineSMS = NULL;
+    // there's no fast renderer yet, just treat it like PDF_8BIT
+    default:         FinalizeLineSMS = FinalizeLine8bitSMS;
                      PicoDrawSetInternalBuf(Pico.est.Draw2FB, 328); break;
   }
   rendstatus_old = -1;

+ 10 - 0
pico/sms.c

@@ -323,6 +323,7 @@ void PicoResetMS(void)
 void PicoPowerMS(void)
 {
   int s, tmp;
+  unsigned tmr;
 
   memset(&PicoMem,0,sizeof(PicoMem));
   memset(&Pico.video,0,sizeof(Pico.video));
@@ -339,6 +340,15 @@ void PicoPowerMS(void)
   tmp = 1 << s;
   bank_mask = (tmp - 1) >> 14;
 
+  // check if the ROM header contains more system information to detect GG
+  for (tmr = 0x2000; tmr < 0xbfff && tmr <= Pico.romsize; tmr *= 2) {
+    if (!memcmp(Pico.rom + tmr-16, "TMR SEGA", 8)) {
+      if (Pico.rom[tmr-1] >= 0x50 && Pico.rom[tmr-1] < 0x80)
+        Pico.m.hardware |= 0x1;
+      break;
+    }
+  }
+
   PicoReset();
 }
 

+ 19 - 18
platform/common/arm_utils.s

@@ -9,10 +9,10 @@
 .text
 .align 4
 
-@ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0
-@ to      00000000 rrr00000 ggg00000 bbb00000 ...
+@ Convert 0000bbbb ggggrrrr 0000bbbb ggggrrrr
+@ to      00000000 rrrr0000 gggg0000 bbbb0000 ...
 
-@ lr =  0x00e000e0, out: r3=lower_pix, r2=higher_pix; trashes rin
+@ lr =  0x00f000f0, out: r3=lower_pix, r2=higher_pix; trashes rin
 .macro convRGB32_2 rin sh=0
     and     r2,  lr, \rin, lsr #4 @ blue
     and     r3,  \rin, lr
@@ -25,13 +25,13 @@
     mov     r3,  r3,  ror #17             @ shadow mode
 .elseif \sh == 2
     adds    r3,  r3,  #0x40000000         @ green
-    orrcs   r3,  r3,  #0xe0000000
+    orrcs   r3,  r3,  lr, lsl #24
     mov     r3,  r3,  ror #8
     adds    r3,  r3,  #0x40000000
-    orrcs   r3,  r3,  #0xe0000000
+    orrcs   r3,  r3,  lr, lsl #24
     mov     r3,  r3,  ror #16
     adds    r3,  r3,  #0x40000000
-    orrcs   r3,  r3,  #0xe0000000
+    orrcs   r3,  r3,  lr, lsl #24
     mov     r3,  r3,  ror #24
 .else
     mov     r3,  r3,  ror #16             @ r3=low
@@ -47,13 +47,13 @@
 .elseif \sh == 2
     mov     r2,  r2,  ror #8
     adds    r2,  r2,  #0x40000000         @ blue
-    orrcs   r2,  r2,  #0xe0000000
+    orrcs   r2,  r2,  lr, lsl #24
     mov     r2,  r2,  ror #8
     adds    r2,  r2,  #0x40000000
-    orrcs   r2,  r2,  #0xe0000000
+    orrcs   r2,  r2,  lr, lsl #24
     mov     r2,  r2,  ror #8
     adds    r2,  r2,  #0x40000000
-    orrcs   r2,  r2,  #0xe0000000
+    orrcs   r2,  r2,  lr, lsl #24
     mov     r2,  r2,  ror #8
 .endif
 
@@ -68,17 +68,17 @@ bgr444_to_rgb32:
     stmfd   sp!, {r4-r7,lr}
 
     mov     r12, #0x40>>3 @ repeats
-    mov     lr, #0x00e00000
-    orr     lr, lr, #0x00e0
+    mov     lr, #0x00f00000
+    orr     lr, lr, #0x00f0
 
 .loopRGB32:
-    subs    r12, r12, #1
-
     ldmia    r1!, {r4-r7}
     convRGB32_2 r4
     convRGB32_2 r5
     convRGB32_2 r6
     convRGB32_2 r7
+
+    subs    r12, r12, #1
     bgt     .loopRGB32
 
     ldmfd   sp!, {r4-r7,pc}
@@ -91,24 +91,25 @@ bgr444_to_rgb32_sh:
 
     mov     r12, #0x40>>3 @ repeats
     add     r0, r0, #0x40*4
-    mov     lr, #0x00e00000
-    orr     lr, lr, #0x00e0
+    mov     lr, #0x00f00000
+    orr     lr, lr, #0x00f0
 
 .loopRGB32sh:
-    subs    r12, r12, #1
-
     ldmia    r1!, {r4-r7}
     convRGB32_2 r4, 2
     convRGB32_2 r5, 2
     convRGB32_2 r6, 2
     convRGB32_2 r7, 2
+
+    subs    r12, r12, #1
     bgt     .loopRGB32sh
 
     mov     r12, #0x40>>3 @ repeats
     sub     r1, r1, #0x40*2
+    and     lr, lr, lr, lsl #1  @ kill LSB for correct shadow colors
 
 .loopRGB32hi:
-     ldmia    r1!, {r4-r7}
+    ldmia    r1!, {r4-r7}
     convRGB32_2 r4, 1
     convRGB32_2 r5, 1
     convRGB32_2 r6, 1

+ 6 - 5
platform/gp2x/emu.c

@@ -83,6 +83,10 @@ void pemu_validate_config(void)
 
 static int get_renderer(void)
 {
+	if (doing_bg_frame)
+		return RT_16BIT;
+	if ((PicoIn.AHW & PAHW_SMS) && currentConfig.renderer == RT_8BIT_FAST)
+		return RT_8BIT_ACC;	// 8bpp fast is not there (yet?)
 	if (PicoIn.AHW & PAHW_32X)
 		return currentConfig.renderer32x;
 	else
@@ -391,7 +395,7 @@ void plat_video_flip(void)
 		stride *= 2;
 	// the fast renderer has overlap areas and can't directly render to
 	// screen buffers. Its output is copied to screen in finalize_frame
-	if (currentConfig.renderer != RT_8BIT_FAST || (PicoIn.AHW & PAHW_32X))
+	if (get_renderer() != RT_8BIT_FAST || (PicoIn.AHW & PAHW_32X))
 		PicoDrawSetOutBuf(g_screen_ptr, stride);
 }
 
@@ -476,9 +480,6 @@ static void vid_reset_mode(void)
 	int gp2x_mode = 16;
 	int renderer = get_renderer();
 
-	if (doing_bg_frame)
-		renderer = RT_16BIT;
-
 	PicoIn.opt &= ~POPT_ALT_RENDERER;
 	emu_scan_begin = NULL;
 	emu_scan_end = NULL;
@@ -554,7 +555,7 @@ static void vid_reset_mode(void)
 	if (currentConfig.scaling == EOPT_SCALE_SW) {
 		PicoIn.opt |= POPT_EN_SOFTSCALE;
 		PicoIn.filter = EOPT_FILTER_BILINEAR2;
-	} else if (currentConfig.scaling == EOPT_SCALE_HW && is_16bit_mode())
+	} else if (currentConfig.scaling == EOPT_SCALE_HW)
 		// hw scaling, render without any padding
 		PicoIn.opt |= POPT_DIS_32C_BORDER;
 

+ 12 - 11
platform/libretro/libretro.c

@@ -105,7 +105,7 @@ static int vout_16bit = 1;
 static int vout_format = PDF_RGB555;
 static void *vout_buf;
 static int vout_width, vout_height, vout_offset;
-static float user_vout_width = 0.0;
+static float vout_aspect = 0.0;
 
 #if defined(RENDER_GSKIT_PS2)
 #define VOUT_8BIT_WIDTH 328
@@ -752,6 +752,7 @@ void retro_get_system_info(struct retro_system_info *info)
 
 void retro_get_system_av_info(struct retro_system_av_info *info)
 {
+   int common_height;
    float common_width;
 
    memset(info, 0, sizeof(*info));
@@ -763,10 +764,11 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
    info->geometry.max_height   = vout_height;
 
    common_width = vout_width;
-   if (user_vout_width != 0)
-      common_width = user_vout_width;
+   common_height = vout_height >= 192 && vout_height <= 224 ? 224 : vout_height;
+   if (vout_aspect != 0)
+      common_width = vout_aspect * common_height;
 
-   info->geometry.aspect_ratio = common_width / vout_height;
+   info->geometry.aspect_ratio = common_width / common_height;
 }
 
 /* savestates */
@@ -1431,7 +1433,7 @@ static void update_variables(bool first_run)
 {
    struct retro_variable var;
    int OldPicoRegionOverride;
-   float old_user_vout_width;
+   float old_vout_aspect;
    unsigned old_frameskip_type;
    int old_vout_format;
    double new_sound_rate;
@@ -1490,20 +1492,19 @@ static void update_variables(bool first_run)
       PsndRerate(1);
    }
 
-   old_user_vout_width = user_vout_width;
+   old_vout_aspect = vout_aspect;
    var.value = NULL;
    var.key = "picodrive_aspect";
    if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
-      int height = vout_height >= 192 && vout_height <= 224 ? 224 : vout_height;
       if (strcmp(var.value, "4/3") == 0)
-         user_vout_width = VOUT_4_3 * height;
+         vout_aspect = VOUT_4_3;
       else if (strcmp(var.value, "CRT") == 0)
-         user_vout_width = VOUT_CRT * height;
+         vout_aspect = VOUT_CRT;
       else
-         user_vout_width = VOUT_PAR * height;
+         vout_aspect = VOUT_PAR;
    }
 
-   if (user_vout_width != old_user_vout_width)
+   if (vout_aspect != old_vout_aspect)
    {
       // Update the geometry
       struct retro_system_av_info av_info;

+ 1 - 1
platform/opendingux/data/default.gcw0.desktop

@@ -6,4 +6,4 @@ Exec=PicoDrive %f
 Icon=megadrive
 Terminal=false
 Categories=emulators;
-MimeType=.md;.smd;.bin;.sms;.cue;.chd;.32x;.zip;.7z
+MimeType=.md;.smd;.bin;.sms;.gg;.cue;.chd;.32x;.zip;.7z

+ 1 - 1
platform/opendingux/data/default.retrofw.desktop

@@ -6,7 +6,7 @@ Icon=megadrive
 Categories=emulators;
 X-OD-Manual=
 X-OD-Selector=
-X-OD-Filter=.md,.smd,.bin,.sms,.cue,.chd,.32x,.zip,.7z
+X-OD-Filter=.md,.smd,.bin,.sms,.gg,.cue,.chd,.32x,.zip,.7z
 Terminal=true
 Type=Application
 StartupNotify=true