解决ColecoVision问题,解决GameGear分辨率问题

This commit is contained in:
sin365 2025-03-31 14:06:38 +08:00
parent bedbc4daa1
commit 68151f3433
24 changed files with 35 additions and 511 deletions

View File

@ -5,6 +5,7 @@ using Essgee.Emulation.Configuration;
using Essgee.Emulation.CPU;
using Essgee.Emulation.Video;
using Essgee.EventArguments;
using Essgee.Metadata;
using Essgee.Utilities;
using System;
using System.Collections.Generic;
@ -182,7 +183,10 @@ namespace Essgee.Emulation.Machines
private void LoadBios()
{
var (type, bootstrapRomData) = CartridgeLoader.Load(configuration.BiosRom, "ColecoVision BIOS");
//var (type, bootstrapRomData) = CartridgeLoader.Load(configuration.BiosRom, "ColecoVision BIOS");
//直接加载BootStrap
GameMetadataHandler.instance.gameMetaReources.GetDatBytes("Bootstrap/[BIOS] ColecoVision (USA, Europe).col", out byte[] bootstrapRomData);
bios = new ColecoCartridge(bootstrapRomData.Length, 0);
bios.LoadRom(bootstrapRomData);
}

View File

@ -51,19 +51,11 @@ namespace Essgee.Emulation.Video
//GCHandle? lasyRenderHandle;
protected override void PrepareRenderScreen()
{
//// 固定数组,防止垃圾回收器移动它
//var bitmapcolorRect_handle = GCHandle.Alloc(outputFramebuffer.Clone() as byte[], GCHandleType.Pinned);
//// 获取数组的指针
//IntPtr mFrameDataPtr = bitmapcolorRect_handle.AddrOfPinnedObject();
var eventArgs = RenderScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines, outputFramebuffer_Ptr);
//var eventArgs = RenderScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines, outputFramebuffer_Ptr);
//这里要改成viewport的中间区域的分辨率
var eventArgs = RenderScreenEventArgs.Create(Viewport.Width, Viewport.Height, outputFramebuffer_Ptr);
OnRenderScreen(eventArgs);
eventArgs.Release();
//if (lasyRenderHandle != null)
// lasyRenderHandle.Value.Free();
//lasyRenderHandle = bitmapcolorRect_handle;
//OnRenderScreen(new RenderScreenEventArgs(Viewport.Width, Viewport.Height, outputFramebuffer.Clone() as byte[]));
}
private bool ModifyAndVerifyCoordinates(ref int x, ref int y)

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using UnityEngine.Timeline;
namespace Essgee.Metadata
{
@ -20,10 +19,11 @@ namespace Essgee.Metadata
public class GameMetadataHandler
{
public static GameMetadataHandler instance;
//static string datDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "No-Intro");
//static string metadataDatabaseFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "MetadataDatabase.json");
IGameMetaReources gameMetaReources;
public IGameMetaReources gameMetaReources;
//readonly Dictionary<string, DatFile> datFiles;
readonly List<CartridgeJSON> cartMetadataDatabase;
@ -32,6 +32,7 @@ namespace Essgee.Metadata
public GameMetadataHandler(IGameMetaReources metaresources)
{
instance = this;
gameMetaReources = metaresources;
//if (!gameMetaReources.GetCartMetadataDatabase(out string loadedData))
@ -357,6 +358,12 @@ namespace Essgee.Metadata
////EssgeeLogger.EnqueueMessageSuccess($"Metadata initialized; {NumKnownGames} game(s) known across {NumKnownSystems} system(s).");
}
~GameMetadataHandler()
{
if(instance == this)
instance = null;
}
public GameMetadata GetGameMetadata(string datFilename, string romFilename, uint romCrc32, int romSize)
{
/* Sanity checks */

View File

@ -1,178 +0,0 @@
using System;
namespace Essgee.Utilities.XInput
{
public class Controller
{
XInputState inputStatesCurrent, inputStatesPrev;
bool timedVibrationEnabled;
DateTime vibrationStopTime;
public bool IsConnected { get; private set; }
public int UserIndex { get; private set; }
public Controller(int index)
{
inputStatesCurrent = inputStatesPrev = new XInputState();
timedVibrationEnabled = false;
vibrationStopTime = DateTime.Now;
IsConnected = false;
UserIndex = index;
}
public void Update()
{
XInputState newInputState = new XInputState();
Errors result = (Errors)NativeMethods.GetState(UserIndex, ref newInputState);
if (result == Errors.Success)
{
IsConnected = true;
inputStatesPrev = inputStatesCurrent;
inputStatesCurrent = newInputState;
if ((inputStatesCurrent.Gamepad.sThumbLX < XInputGamepad.LeftThumbDeadzone && inputStatesCurrent.Gamepad.sThumbLX > -XInputGamepad.LeftThumbDeadzone) &&
(inputStatesCurrent.Gamepad.sThumbLY < XInputGamepad.LeftThumbDeadzone && inputStatesCurrent.Gamepad.sThumbLY > -XInputGamepad.LeftThumbDeadzone))
{
inputStatesCurrent.Gamepad.sThumbLX = inputStatesCurrent.Gamepad.sThumbLY = 0;
}
if ((inputStatesCurrent.Gamepad.sThumbRX < XInputGamepad.RightThumbDeadzone && inputStatesCurrent.Gamepad.sThumbRX > -XInputGamepad.RightThumbDeadzone) &&
(inputStatesCurrent.Gamepad.sThumbRY < XInputGamepad.RightThumbDeadzone && inputStatesCurrent.Gamepad.sThumbRY > -XInputGamepad.RightThumbDeadzone))
{
inputStatesCurrent.Gamepad.sThumbRX = inputStatesCurrent.Gamepad.sThumbRY = 0;
}
if (inputStatesCurrent.Gamepad.bLeftTrigger < XInputGamepad.TriggerThreshold) inputStatesCurrent.Gamepad.bLeftTrigger = 0;
if (inputStatesCurrent.Gamepad.bRightTrigger < XInputGamepad.TriggerThreshold) inputStatesCurrent.Gamepad.bRightTrigger = 0;
if (timedVibrationEnabled && DateTime.Now >= vibrationStopTime)
{
timedVibrationEnabled = false;
Vibrate(0.0f, 0.0f);
}
}
else if (result == Errors.DeviceNotConnected)
{
IsConnected = false;
}
else
throw new Exception(string.Format("Error code {0}", (int)result));
}
//public ControllerState GetControllerState()
//{
// return new ControllerState
// {
// Buttons = inputStatesCurrent.Gamepad.Buttons,
// LeftThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbLX / 32768.0f, inputStatesCurrent.Gamepad.sThumbLY / 32768.0f),
// RightThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbRX / 32768.0f, inputStatesCurrent.Gamepad.sThumbRY / 32768.0f),
// LeftTrigger = (inputStatesCurrent.Gamepad.bLeftTrigger / 255.0f),
// RightTrigger = (inputStatesCurrent.Gamepad.bRightTrigger / 255.0f)
// };
//}
public bool IsDPadUpPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.DPadUp);
}
public bool IsDPadDownPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.DPadDown);
}
public bool IsDPadLeftPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.DPadLeft);
}
public bool IsDPadRightPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.DPadRight);
}
public bool IsStartPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.Start);
}
public bool IsBackPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.Back);
}
public bool IsLeftThumbPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.LeftThumb);
}
public bool IsRightThumbPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.RightThumb);
}
public bool IsLeftShoulderPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.LeftShoulder);
}
public bool IsRightShoulderPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.RightShoulder);
}
public bool IsAPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.A);
}
public bool IsBPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.B);
}
public bool IsXPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.X);
}
public bool IsYPressed()
{
return inputStatesCurrent.Gamepad.Buttons.HasFlag(Buttons.Y);
}
public void Vibrate(float leftMotor, float rightMotor)
{
XInputVibration vibrationState = new XInputVibration();
vibrationState.wLeftMotorSpeed = (ushort)(leftMotor * 65535.0f);
vibrationState.wRightMotorSpeed = (ushort)(rightMotor * 65535.0f);
NativeMethods.SetState(UserIndex, ref vibrationState);
}
public void Vibrate(float leftMotor, float rightMotor, TimeSpan duration)
{
Vibrate(leftMotor, rightMotor);
vibrationStopTime = DateTime.Now.Add(duration);
timedVibrationEnabled = true;
}
}
public class ThumbstickPosition
{
public float X { get; private set; }
public float Y { get; private set; }
public ThumbstickPosition(float x, float y)
{
X = x;
Y = y;
}
public override string ToString()
{
return string.Format(System.Globalization.CultureInfo.InvariantCulture, "({0}, {1})", X, Y);
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 208c78465e149914e92390762f768a04

View File

@ -1,30 +0,0 @@
using System;
namespace Essgee.Utilities.XInput
{
public static class ControllerManager
{
const int maxControllers = 4;
static Controller[] controllers;
static ControllerManager()
{
controllers = new Controller[maxControllers];
for (int i = 0; i < controllers.Length; i++)
controllers[i] = new Controller(i);
}
public static Controller GetController(int index)
{
if (index < 0 || index >= maxControllers) throw new Exception("Controller index out of range");
return controllers[index];
}
public static void Update()
{
for (int i = 0; i < controllers.Length; i++)
controllers[i].Update();
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: d3b109e035af2d0488fee85624c9a90b

View File

@ -1,116 +0,0 @@
//namespace Essgee.Utilities.XInput
//{
// public class ControllerState
// {
// public Buttons Buttons { get; set; }
// public ThumbstickPosition LeftThumbstick { get; set; }
// public ThumbstickPosition RightThumbstick { get; set; }
// public float LeftTrigger { get; set; }
// public float RightTrigger { get; set; }
// public bool IsConnected { get; set; }
// public int UserIndex { get; set; }
// public ControllerState()
// {
// Buttons = Buttons.None;
// LeftThumbstick = new ThumbstickPosition(0.0f, 0.0f);
// RightThumbstick = new ThumbstickPosition(0.0f, 0.0f);
// LeftTrigger = 0.0f;
// RightTrigger = 0.0f;
// IsConnected = false;
// UserIndex = -1;
// }
// public bool IsAnyUpDirectionPressed()
// {
// return IsDPadUpPressed() || LeftThumbstick.Y > 0.5f;
// }
// public bool IsAnyDownDirectionPressed()
// {
// return IsDPadDownPressed() || LeftThumbstick.Y < -0.5f;
// }
// public bool IsAnyLeftDirectionPressed()
// {
// return IsDPadLeftPressed() || LeftThumbstick.X < -0.5f;
// }
// public bool IsAnyRightDirectionPressed()
// {
// return IsDPadRightPressed() || LeftThumbstick.X > 0.5f;
// }
// public bool IsDPadUpPressed()
// {
// return Buttons.HasFlag(Buttons.DPadUp);
// }
// public bool IsDPadDownPressed()
// {
// return Buttons.HasFlag(Buttons.DPadDown);
// }
// public bool IsDPadLeftPressed()
// {
// return Buttons.HasFlag(Buttons.DPadLeft);
// }
// public bool IsDPadRightPressed()
// {
// return Buttons.HasFlag(Buttons.DPadRight);
// }
// public bool IsStartPressed()
// {
// return Buttons.HasFlag(Buttons.Start);
// }
// public bool IsBackPressed()
// {
// return Buttons.HasFlag(Buttons.Back);
// }
// public bool IsLeftThumbPressed()
// {
// return Buttons.HasFlag(Buttons.LeftThumb);
// }
// public bool IsRightThumbPressed()
// {
// return Buttons.HasFlag(Buttons.RightThumb);
// }
// public bool IsLeftShoulderPressed()
// {
// return Buttons.HasFlag(Buttons.LeftShoulder);
// }
// public bool IsRightShoulderPressed()
// {
// return Buttons.HasFlag(Buttons.RightShoulder);
// }
// public bool IsAPressed()
// {
// return Buttons.HasFlag(Buttons.A);
// }
// public bool IsBPressed()
// {
// return Buttons.HasFlag(Buttons.B);
// }
// public bool IsXPressed()
// {
// return Buttons.HasFlag(Buttons.X);
// }
// public bool IsYPressed()
// {
// return Buttons.HasFlag(Buttons.Y);
// }
// }
//}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 62cf2ece5ee5c44458ac5646bb2f8af8

View File

@ -1,25 +0,0 @@
using System.Runtime.InteropServices;
namespace Essgee.Utilities.XInput
{
static class NativeMethods
{
const string dllName = "xinput9_1_0.dll";
public const int FlagGamepad = 0x00000001;
[DllImport(dllName, EntryPoint = "XInputGetState")]
public static extern int GetState(int dwUserIndex, ref XInputState pState);
[DllImport(dllName, EntryPoint = "XInputSetState")]
public static extern int SetState(int dwUserIndex, ref XInputVibration pVibration);
[DllImport(dllName, EntryPoint = "XInputGetCapabilities")]
public static extern int GetCapabilities(int dwUserIndex, int dwFlags, ref XInputCapabilities pCapabilities);
}
public enum Errors
{
Success = 0x00000000,
BadArguments = 0x000000A0,
DeviceNotConnected = 0x0000048F
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 2f4639905082c50448ca8a1477b55057

View File

@ -1,47 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Essgee.Utilities.XInput
{
/* https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_capabilities%28v=vs.85%29.aspx */
[StructLayout(LayoutKind.Explicit)]
public struct XInputCapabilities
{
[FieldOffset(0)]
byte type;
[FieldOffset(1)]
byte subType;
[FieldOffset(2)]
ushort flags;
[FieldOffset(4)]
public XInputGamepad Gamepad;
[FieldOffset(16)]
public XInputVibration Vibration;
public DeviceType Type { get { return (DeviceType)type; } }
public DeviceSubType SubType { get { return (DeviceSubType)subType; } }
public DeviceFlags Flags { get { return (DeviceFlags)flags; } }
}
public enum DeviceType
{
Gamepad = 0x01
}
public enum DeviceSubType
{
Gamepad = 0x01,
Wheel = 0x02,
ArcadeStick = 0x03,
FlightStick = 0x04,
DancePad = 0x05,
Guitar = 0x06,
DrumKit = 0x08
}
[Flags]
public enum DeviceFlags
{
VoiceSupported = 0x0004
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 400677b412126194caf14f5d627b34a2

View File

@ -1,51 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Essgee.Utilities.XInput
{
/* https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_gamepad%28v=vs.85%29.aspx */
[StructLayout(LayoutKind.Explicit)]
public struct XInputGamepad
{
[FieldOffset(0)]
ushort wButtons;
[FieldOffset(2)]
public byte bLeftTrigger;
[FieldOffset(3)]
public byte bRightTrigger;
[FieldOffset(4)]
public short sThumbLX;
[FieldOffset(6)]
public short sThumbLY;
[FieldOffset(8)]
public short sThumbRX;
[FieldOffset(10)]
public short sThumbRY;
public const int LeftThumbDeadzone = 7849;
public const int RightThumbDeadzone = 8689;
public const int TriggerThreshold = 30;
public Buttons Buttons { get { return (Buttons)wButtons; } }
}
[Flags]
public enum Buttons
{
None = 0x0000,
DPadUp = 0x0001,
DPadDown = 0x0002,
DPadLeft = 0x0004,
DPadRight = 0x0008,
Start = 0x0010,
Back = 0x0020,
LeftThumb = 0x0040,
RightThumb = 0x0080,
LeftShoulder = 0x0100,
RightShoulder = 0x0200,
A = 0x1000,
B = 0x2000,
X = 0x4000,
Y = 0x8000
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: dee5c4630dd189049abf4d41bd4348d8

View File

@ -1,14 +0,0 @@
using System.Runtime.InteropServices;
namespace Essgee.Utilities.XInput
{
/* https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_state%28v=vs.85%29.aspx */
[StructLayout(LayoutKind.Explicit)]
public struct XInputState
{
[FieldOffset(0)]
public uint dwPacketNumber;
[FieldOffset(4)]
public XInputGamepad Gamepad;
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: b18170cd37fc33d4ba897ffbe7198deb

View File

@ -1,14 +0,0 @@
using System.Runtime.InteropServices;
namespace Essgee.Utilities.XInput
{
/* https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_vibration%28v=vs.85%29.aspx */
[StructLayout(LayoutKind.Explicit)]
public struct XInputVibration
{
[FieldOffset(0)]
public ushort wLeftMotorSpeed;
[FieldOffset(2)]
public ushort wRightMotorSpeed;
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 66e6171736477a944b9299a66469f407

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 37b3e1d7093e0f545807ab54c1209c8b
guid: ca91f4d917d2a354b97e24c5a2ce35b4
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: efcafc093c10d4b46823dab15640a334
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,7 +6,6 @@ using Essgee.Exceptions;
using Essgee.Extensions;
using Essgee.Metadata;
using Essgee.Utilities;
using Essgee.Utilities.XInput;
using System;
using System.Collections.Generic;
using System.IO;
@ -50,7 +49,8 @@ public class Essgeeinit : MonoBehaviour
//LoadAndRunCartridge("G:/Phantasy Star (USA, Europe) (Rev A).zip");
//LoadAndRunCartridge("G:/Ninja_Gaiden_(UE)_type_A_[!].sms");
//LoadAndRunCartridge("G:/SML2.gb");
LoadAndRunCartridge("G:/BaiduNetdiskDownload/밍艱濫쫠-촬묵깡考濫[숌]錦攣경1.11.gbc");
LoadAndRunCartridge("G:/SonicTheHedgehog(Japan).zip");
//LoadAndRunCartridge("G:/BaiduNetdiskDownload/밍艱濫쫠-촬묵깡考濫[숌]錦攣경1.11.gbc");
}
void OnDisable()
@ -601,7 +601,7 @@ public class Essgeeinit : MonoBehaviour
graphicsHandler.SubmitVideo(e.Width, e.Height, e.FrameDataPtr, 0);
// TODO: create emulation "EndOfFrame" event for this?
ControllerManager.Update();
//ControllerManager.Update();
//});
}
@ -697,8 +697,8 @@ public class Essgeeinit : MonoBehaviour
private void EmulatorHandler_EnableRumble(object sender, EventArgs e)
{
if (EmuStandInfo.Configuration.EnableXInput && EmuStandInfo.Configuration.EnableRumble)
ControllerManager.GetController(0).Vibrate(0.0f, 0.5f, TimeSpan.FromSeconds(0.1f));
//if (EmuStandInfo.Configuration.EnableXInput && EmuStandInfo.Configuration.EnableRumble)
// ControllerManager.GetController(0).Vibrate(0.0f, 0.5f, TimeSpan.FromSeconds(0.1f));
}
private void EmulatorHandler_PauseChanged(object sender, EventArgs e)

View File

@ -98,6 +98,11 @@ public class UEGVideoPlayer : MonoBehaviour
mWidth = width;
mHeight = height;
bHadData = true;
}
if (mWidth != width && mHeight != height)
{
}
//Debug.Log($"frame_number -> {frame_number}");
}