Browse Source

1.45a Pico win32, code move

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@457 be3aeb3a-fb24-0410-a615-afba39da0efa
notaz 16 years ago
parent
commit
4609d0cdb8

+ 5 - 5
Pico/Pico.c

@@ -541,15 +541,15 @@ void PicoFrameDrawOnly(void)
   for (y=0;y<224;y++) PicoLine(y);
 }
 
-int PicoGetStat(pstat_t which)
+void PicoGetInternal(pint_t which, pint_ret_t *r)
 {
   switch (which)
   {
-    case PS_PAL:       return Pico.m.pal;
-    case PS_40_CELL:   return Pico.video.reg[12]&1;
-    case PS_240_LINES: return Pico.m.pal && (Pico.video.reg[1]&8);
+    case PI_ROM:         r->vptr = Pico.rom; break;
+    case PI_ISPAL:       r->vint = Pico.m.pal; break;
+    case PI_IS40_CELL:   r->vint = Pico.video.reg[12]&1; break;
+    case PI_IS240_LINES: r->vint = Pico.m.pal && (Pico.video.reg[1]&8); break;
   }
-  return 0;
 }
 
 // callback to output message from emu

+ 3 - 2
Pico/Pico.h

@@ -67,8 +67,9 @@ void PicoFrameDrawOnly(void);
 extern int PicoPad[2]; // Joypads, format is MXYZ SACB RLDU
 extern void (*PicoWriteSound)(int len); // called once per frame at the best time to send sound buffer (PsndOut) to hardware
 extern void (*PicoMessage)(const char *msg); // callback to output text message from emu
-typedef enum { PS_PAL, PS_40_CELL, PS_240_LINES } pstat_t;
-int  PicoGetStat(pstat_t which);
+typedef enum { PI_ROM, PI_ISPAL, PI_IS40_CELL, PI_IS240_LINES } pint_t;
+typedef union { int vint; void *vptr; } pint_ret_t;
+void PicoGetInternal(pint_t which, pint_ret_t *ret);
 
 // cd/Pico.c
 extern void (*PicoMCDopenTray)(void);

+ 80 - 51
platform/common/config.c

@@ -3,12 +3,18 @@
  * (c)
  */
 
+#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include "config.h"
+#include "lprintf.h"
+
+static char *mystrip(char *str);
+
+#ifndef _MSC_VER
+
 #include "menu.h"
 #include "emu.h"
-#include "lprintf.h"
 #include <Pico/Pico.h>
 
 extern menu_entry opt_entries[];
@@ -45,24 +51,6 @@ static const int *cfg_opt_counts[] =
 #define NL "\r\n"
 
 
-static char *mystrip(char *str)
-{
-	int i, len;
-
-	len = strlen(str);
-	for (i = 0; i < len; i++)
-		if (str[i] != ' ') break;
-	if (i > 0) memmove(str, str + i, len - i + 1);
-
-	len = strlen(str);
-	for (i = len - 1; i >= 0; i--)
-		if (str[i] != ' ') break;
-	str[i+1] = 0;
-
-	return str;
-}
-
-
 static int seek_sect(FILE *f, const char *section)
 {
 	char line[128], *tmp;
@@ -807,12 +795,11 @@ int config_havesect(const char *fname, const char *section)
 	return ret;
 }
 
-
 int config_readsect(const char *fname, const char *section)
 {
-	char line[128], *var, *val, *tmp;
-	int len, i, ret;
+	char line[128], *var, *val;
 	FILE *f;
+	int ret;
 
 	f = fopen(fname, "r");
 	if (f == NULL) return -1;
@@ -831,35 +818,9 @@ int config_readsect(const char *fname, const char *section)
 
 	while (!feof(f))
 	{
-		tmp = fgets(line, sizeof(line), f);
-		if (tmp == NULL) break;
-
-		if (line[0] == '[') break; // other section
-
-		// strip comments, linefeed, spaces..
-		len = strlen(line);
-		for (i = 0; i < len; i++)
-			if (line[i] == '#' || line[i] == '\r' || line[i] == '\n') { line[i] = 0; break; }
-		mystrip(line);
-		len = strlen(line);
-		if (len <= 0) continue;
-
-		// get var and val
-		for (i = 0; i < len; i++)
-			if (line[i] == '=') break;
-		if (i >= len || strchr(&line[i+1], '=') != NULL) {
-			lprintf("config_readsect: can't parse: %s\n", line);
-			continue;
-		}
-		line[i] = 0;
-		var = line;
-		val = &line[i+1];
-		mystrip(var);
-		mystrip(val);
-		if (strlen(var) == 0 || (strlen(val) == 0 && strncasecmp(var, "bind", 4) != 0)) {
-			lprintf("config_readsect: something's empty: \"%s\" = \"%s\"\n", var, val);
-			continue;
-		}
+		ret = config_get_var_val(f, line, sizeof(line), &var, &val);
+		if (ret ==  0) break;
+		if (ret == -1) continue;
 
 		parse(var, val);
 	}
@@ -868,3 +829,71 @@ int config_readsect(const char *fname, const char *section)
 	return 0;
 }
 
+#endif // _MSC_VER
+
+static char *mystrip(char *str)
+{
+	int i, len;
+
+	len = strlen(str);
+	for (i = 0; i < len; i++)
+		if (str[i] != ' ') break;
+	if (i > 0) memmove(str, str + i, len - i + 1);
+
+	len = strlen(str);
+	for (i = len - 1; i >= 0; i--)
+		if (str[i] != ' ') break;
+	str[i+1] = 0;
+
+	return str;
+}
+
+/* returns:
+ *  0 - EOF, end
+ *  1 - parsed ok
+ * -1 - failed to parse line
+ */
+int config_get_var_val(void *file, char *line, int lsize, char **rvar, char **rval)
+{
+	char *var, *val, *tmp;
+	FILE *f = file;
+	int len, i;
+
+	tmp = fgets(line, lsize, f);
+	if (tmp == NULL) return 0;
+
+	if (line[0] == '[') return 0; // other section
+
+	// strip comments, linefeed, spaces..
+	len = strlen(line);
+	for (i = 0; i < len; i++)
+		if (line[i] == '#' || line[i] == '\r' || line[i] == '\n') { line[i] = 0; break; }
+	mystrip(line);
+	len = strlen(line);
+	if (len <= 0) return -1;;
+
+	// get var and val
+	for (i = 0; i < len; i++)
+		if (line[i] == '=') break;
+	if (i >= len || strchr(&line[i+1], '=') != NULL) {
+		lprintf("config_readsect: can't parse: %s\n", line);
+		return -1;
+	}
+	line[i] = 0;
+	var = line;
+	val = &line[i+1];
+	mystrip(var);
+	mystrip(val);
+
+#ifndef _MSC_VER
+	if (strlen(var) == 0 || (strlen(val) == 0 && strncasecmp(var, "bind", 4) != 0)) {
+		lprintf("config_readsect: something's empty: \"%s\" = \"%s\"\n", var, val);
+		return -1;;
+	}
+#endif
+
+	*rvar = var;
+	*rval = val;
+	return 1;
+}
+

+ 10 - 0
platform/common/config.h

@@ -1,6 +1,16 @@
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 int config_writesect(const char *fname, const char *section);
 int config_writelrom(const char *fname);
 int config_readsect(const char *fname, const char *section);
 int config_readlrom(const char *fname);
 int config_havesect(const char *fname, const char *section);
+int config_get_var_val(void *file, char *line, int lsize, char **rvar, char **rval);
+
+#ifdef __cplusplus
+}
+#endif
 

+ 3 - 2
platform/win32/GenaDrive/Loop.cpp

@@ -56,8 +56,9 @@ static void UpdateSound(int len)
 
 static void PostProcess()
 {
-  static int lock_to_1_1_prev = 0, is_40_prev = 0;
-  int is_40 = PicoGetStat(PS_40_CELL);
+  static int lock_to_1_1_prev = 0, is_40_prev = -1;
+  int is_40;
+  PicoGetInternal(PI_IS40_CELL, (pint_ret_t *)&is_40);
   if (lock_to_1_1)
   {
     if (is_40 != is_40_prev || !lock_to_1_1_prev)

+ 54 - 5
platform/win32/GenaDrive/Main.cpp

@@ -3,6 +3,7 @@
 #include <crtdbg.h>
 #include <commdlg.h>
 #include "../../common/readpng.h"
+#include "../../common/config.h"
 
 char *romname=NULL;
 HWND FrameWnd=NULL;
@@ -17,6 +18,7 @@ static int rom_loaded = 0;
 static HBITMAP ppad_bmp = 0;
 static HBITMAP ppage_bmps[7] = { 0, };
 static char rom_name[0x20*3+1];
+static int main_wnd_as_pad = 0;
 
 static void UpdateRect()
 {
@@ -29,7 +31,7 @@ static void UpdateRect()
 
 static int extract_rom_name(char *dest, const unsigned char *src, int len)
 {
-	char *p = dest, s_old = 0;
+	char *p = dest, s_old = 0x20;
 	int i;
 
 	for (i = len - 1; i >= 0; i--)
@@ -58,6 +60,29 @@ static int extract_rom_name(char *dest, const unsigned char *src, int len)
 	return p - dest;
 }
 
+static void check_name_alias(const char *afname)
+{
+  char buff[256], *var, *val;
+  FILE *f;
+  int ret;
+
+  f = fopen(afname, "r");
+  if (f == NULL) return;
+
+  while (1)
+  {
+    ret = config_get_var_val(f, buff, sizeof(buff), &var, &val);
+    if (ret ==  0) break;
+    if (ret == -1) continue;
+
+    if (strcmp(rom_name, var) == 0) {
+      lprintf("rom aliased: \"%s\" -> \"%s\"\n", rom_name, val);
+      strncpy(rom_name, val, sizeof(rom_name));
+      break;
+    }
+  }
+  fclose(f);
+}
 
 static HBITMAP png2hb(const char *fname, int is_480)
 {
@@ -89,9 +114,12 @@ static HBITMAP png2hb(const char *fname, int is_480)
   return bmp;
 }
 
-static void PrepareForROM(unsigned char *rom_data)
+static void PrepareForROM(void)
 {
+  unsigned char *rom_data = NULL;
   int i, ret, show = PicoAHW & PAHW_PICO;
+  
+  PicoGetInternal(PI_ROM, (pint_ret_t *) &rom_data);
   EnableMenuItem(mmain, 2, MF_BYPOSITION|(show ? MF_ENABLED : MF_GRAYED));
   ShowWindow(PicoPadWnd, show ? SW_SHOWNA : SW_HIDE);
   ShowWindow(PicoSwWnd, show ? SW_SHOWNA : SW_HIDE);
@@ -121,11 +149,19 @@ static void PrepareForROM(unsigned char *rom_data)
       ppad_bmp = png2hb(path, 0);
     }
 
+    strcpy(p, "pico\\alias.txt");
+    check_name_alias(path);
+
     for (i = 0; i < 7; i++) {
       if (ppage_bmps[i] != NULL) DeleteObject(ppage_bmps[i]);
       sprintf(p, "pico\\%s_%i.png", rom_name, i);
       ppage_bmps[i] = png2hb(path, 1);
     }
+    // games usually don't have page 6, so just duplicate page 5.
+    if (ppage_bmps[6] == NULL && ppage_bmps[5] != NULL) {
+      sprintf(p, "pico\\%s_5.png", rom_name);
+      ppage_bmps[6] = png2hb(path, 1);
+    }
   }
 }
 
@@ -173,7 +209,7 @@ static void LoadROM(const char *cmdpath)
   PicoCartUnload();
   PicoCartInsert(rom_data_new, rom_size);
 
-  PrepareForROM(rom_data_new);
+  PrepareForROM();
 
   rom_loaded = 1;
   romname = rompath;
@@ -231,6 +267,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
           ShowWindow((LOWORD(wparam)&1) ? PicoPadWnd : PicoSwWnd, i ? SW_SHOWNA : SW_HIDE);
           CheckMenuItem(mpicohw, LOWORD(wparam), i ? MF_CHECKED : MF_UNCHECKED);
           return 0;
+        case 1212:
+          main_wnd_as_pad = !main_wnd_as_pad;
+          CheckMenuItem(mpicohw, 1212, main_wnd_as_pad ? MF_CHECKED : MF_UNCHECKED);
+          return 0;
         case 1220:
         case 1221:
         case 1222:
@@ -269,6 +309,14 @@ static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
       PicoPicohw.pen_pos[1] |= 0x8000;
       PicoPadAdd = 0;
       break;
+    case WM_LBUTTONDOWN: PicoPadAdd |=  0x20; return 0;
+    case WM_LBUTTONUP:   PicoPadAdd &= ~0x20; return 0;
+    case WM_MOUSEMOVE:
+      if (!main_wnd_as_pad) break;
+      PicoPicohw.pen_pos[0] = 0x03c + (320 * LOWORD(lparam) / (FrameRectMy.right - FrameRectMy.left));
+      PicoPicohw.pen_pos[1] = 0x1fc + (232 * HIWORD(lparam) / (FrameRectMy.bottom - FrameRectMy.top));
+      SetTimer(FrameWnd, 100, 1000, NULL);
+      break;
   }
 
   return DefWindowProc(hwnd,msg,wparam,lparam);
@@ -319,8 +367,8 @@ static LRESULT CALLBACK PicoSwWndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lp
       if (ppage_bmps[PicoPicohw.page] == NULL)
       {
         SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
-	SetTextColor(hdc, RGB(255, 255, 255));
-	SetBkColor(hdc, RGB(0, 0, 0));
+        SetTextColor(hdc, RGB(255, 255, 255));
+        SetBkColor(hdc, RGB(0, 0, 0));
         TextOut(hdc, 2,  2, "missing PNGs for", 16);
         TextOut(hdc, 2, 18, rom_name, strlen(rom_name));
       }
@@ -427,6 +475,7 @@ static int FrameInit()
   mpicohw = CreateMenu();
   InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1210, "Show &Storyware");
   InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1211, "Show &Drawing pad");
+  InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1212, "&Main window as pad");
   InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
   InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1220, "Title page (&0)");
   InsertMenu(mpicohw, -1, MF_BYPOSITION|MF_STRING, 1221, "Page &1");

+ 1 - 1
platform/win32/GenaDrive/Makefile.vc

@@ -23,7 +23,7 @@ OBJ = Emu.obj Input.obj Main.obj Direct.obj DSound.obj Loop.obj
 # common
 #OBJS += platform\common\emu.obj platform\common\menu.obj platform\common\fonts.obj 
 #		platform\common\mp3_helix.obj
-OBJ = $(OBJ) $(R)platform\common\readpng.obj
+OBJ = $(OBJ) $(R)platform\common\readpng.obj $(R)platform\common\config.obj
 
 # Pico
 OBJ = $(OBJ) $(R)Pico\Area.obj $(R)Pico\Cart.obj $(R)Pico\Memory.obj $(R)Pico\Misc.obj $(R)Pico\Pico.obj $(R)Pico\Sek.obj \

+ 1 - 0
platform/win32/GenaDrive/readme.txt

@@ -21,6 +21,7 @@ Releases
 1.40a - Tasco Deluxe's dithering fix.
 1.40b - Perspective fix thanks to Pierpaolo Prazzoli's info.
 1.45  - Added preliminary Sega Pico emulation.
+1.45a - Few bugfixes and additions.
 
 
 Controls

+ 1 - 1
platform/win32/GenaDrive/version.h

@@ -1,2 +1,2 @@
-#define VERSION "1.45"
+#define VERSION "1.45a"