mirror of
https://github.com/freebip/BipEmulator.git
synced 2025-05-18 17:36:32 +03:00
ADD: Экспериментальная поддержка прямого доступа к видеопамяти
CHG: Исправлены настройки конфигурации RELEASE
This commit is contained in:
parent
39014d3427
commit
ad003776ae
@ -32,6 +32,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
@ -55,6 +56,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="BitReader.cs" />
|
<Compile Include="BitReader.cs" />
|
||||||
<Compile Include="ColorArray.cs" />
|
<Compile Include="ColorArray.cs" />
|
||||||
|
<Compile Include="ColorIndexEnum.cs" />
|
||||||
<Compile Include="DisplayNameAttribute.cs" />
|
<Compile Include="DisplayNameAttribute.cs" />
|
||||||
<Compile Include="ColorSelectionForm.cs">
|
<Compile Include="ColorSelectionForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
14
src/BipEmulator.Host/ColorIndexEnum.cs
Normal file
14
src/BipEmulator.Host/ColorIndexEnum.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace BipEmulator.Host
|
||||||
|
{
|
||||||
|
public enum ColorIndexEnum
|
||||||
|
{
|
||||||
|
Black = 0,
|
||||||
|
Blue = 1,
|
||||||
|
Green = 2,
|
||||||
|
Aqua = 3,
|
||||||
|
Red = 4,
|
||||||
|
Purple = 5,
|
||||||
|
Yellow = 6,
|
||||||
|
White = 7,
|
||||||
|
}
|
||||||
|
}
|
@ -29,5 +29,8 @@
|
|||||||
public const string TEXT_OUT_CENTER = "text_out_center";
|
public const string TEXT_OUT_CENTER = "text_out_center";
|
||||||
public const string TEXT_WIDTH = "text_width";
|
public const string TEXT_WIDTH = "text_width";
|
||||||
public const string VIBRATE = "vibrate";
|
public const string VIBRATE = "vibrate";
|
||||||
|
|
||||||
|
// special emulator functions
|
||||||
|
public const string SHARED_MEMORY_ENABLED = "__shared_memory_enabled__";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.MemoryMappedFiles;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -13,6 +14,7 @@ namespace BipEmulator.Host
|
|||||||
{
|
{
|
||||||
public partial class MainForm : Form, IMessageFilter
|
public partial class MainForm : Form, IMessageFilter
|
||||||
{
|
{
|
||||||
|
const int VIDEO_MEMORY_SIZE = 15488;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Функция обратного вызова
|
/// Функция обратного вызова
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -29,6 +31,11 @@ namespace BipEmulator.Host
|
|||||||
|
|
||||||
private IntPtr _hrmDataPointer = IntPtr.Zero;
|
private IntPtr _hrmDataPointer = IntPtr.Zero;
|
||||||
|
|
||||||
|
private bool _useSharedVideoMemory;
|
||||||
|
MemoryMappedFile _sharedMemoryFile;
|
||||||
|
MemoryMappedViewStream _sharedMemoryViewStream;
|
||||||
|
private byte[] _videoMemory = new byte[VIDEO_MEMORY_SIZE];
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -134,7 +141,15 @@ namespace BipEmulator.Host
|
|||||||
return ucScreen.GetTextWidth(args[1].ToString());
|
return ucScreen.GetTextWidth(args[1].ToString());
|
||||||
|
|
||||||
case FunctionNames.REPAINT_SCREEN_LINES:
|
case FunctionNames.REPAINT_SCREEN_LINES:
|
||||||
|
|
||||||
|
if (_useSharedVideoMemory)
|
||||||
|
{
|
||||||
|
_sharedMemoryViewStream.Position = 0;
|
||||||
|
_sharedMemoryViewStream.Read(_videoMemory, 0, 15488);
|
||||||
|
ucScreen.SetVideoData(_videoMemory);
|
||||||
|
}
|
||||||
ucScreen.RepaintScreenLines((int)args[1], (int)args[2]);
|
ucScreen.RepaintScreenLines((int)args[1], (int)args[2]);
|
||||||
|
|
||||||
if (ucScreen.InvokeRequired)
|
if (ucScreen.InvokeRequired)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -303,6 +318,10 @@ namespace BipEmulator.Host
|
|||||||
}
|
}
|
||||||
return (int)locale;
|
return (int)locale;
|
||||||
|
|
||||||
|
case FunctionNames.SHARED_MEMORY_ENABLED:
|
||||||
|
_useSharedVideoMemory = OpenFileMapping();
|
||||||
|
return _useSharedVideoMemory ? 1 : 0;
|
||||||
|
|
||||||
// заглушки
|
// заглушки
|
||||||
|
|
||||||
case FunctionNames.VIBRATE:
|
case FunctionNames.VIBRATE:
|
||||||
@ -321,6 +340,21 @@ namespace BipEmulator.Host
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool OpenFileMapping()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_sharedMemoryFile = MemoryMappedFile.OpenExisting("meme", MemoryMappedFileRights.ReadWrite);
|
||||||
|
_sharedMemoryViewStream = _sharedMemoryFile.CreateViewStream();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private LocaleEnum GetCurrentLocale()
|
private LocaleEnum GetCurrentLocale()
|
||||||
{
|
{
|
||||||
foreach (LocaleEnum locale in Enum.GetValues(typeof(LocaleEnum)))
|
foreach (LocaleEnum locale in Enum.GetValues(typeof(LocaleEnum)))
|
||||||
|
@ -35,6 +35,7 @@ namespace BipEmulator.Host
|
|||||||
_ftMaker = new FtMaker(_ftFile);
|
_ftMaker = new FtMaker(_ftFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void OnSizeChanged(EventArgs e)
|
protected override void OnSizeChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
Width = SIZE;
|
Width = SIZE;
|
||||||
@ -177,5 +178,43 @@ namespace BipEmulator.Host
|
|||||||
{
|
{
|
||||||
return Color.FromArgb(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff);
|
return Color.FromArgb(value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Color GetColorByIndex(int index)
|
||||||
|
{
|
||||||
|
switch((ColorIndexEnum)index)
|
||||||
|
{
|
||||||
|
case ColorIndexEnum.Black:
|
||||||
|
return Colors.Black;
|
||||||
|
case ColorIndexEnum.Blue:
|
||||||
|
return Colors.Blue;
|
||||||
|
case ColorIndexEnum.Green:
|
||||||
|
return Colors.Green;
|
||||||
|
case ColorIndexEnum.Aqua:
|
||||||
|
return Colors.Aqua;
|
||||||
|
case ColorIndexEnum.Purple:
|
||||||
|
return Colors.Purple;
|
||||||
|
case ColorIndexEnum.Red:
|
||||||
|
return Colors.Red;
|
||||||
|
case ColorIndexEnum.Yellow:
|
||||||
|
return Colors.Yellow;
|
||||||
|
default:
|
||||||
|
return Colors.Black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void SetVideoData(byte[] videoMemory)
|
||||||
|
{
|
||||||
|
var shadow = new FastBitmap(_shadowImage);
|
||||||
|
shadow.Lock();
|
||||||
|
var offset = 0;
|
||||||
|
for(var y=0;y<SIZE;y++)
|
||||||
|
for(var x=0;x<SIZE;x+=2)
|
||||||
|
{
|
||||||
|
shadow.SetPixel(x, y, GetColorByIndex(videoMemory[offset] >> 4));
|
||||||
|
shadow.SetPixel(x+1, y, GetColorByIndex(videoMemory[offset] & 0xf));
|
||||||
|
offset++;
|
||||||
|
}
|
||||||
|
shadow.Unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,9 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>
|
||||||
|
</PrecompiledHeaderFile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -239,6 +239,10 @@ const char* SETTINGS_FILE = "settings.bin";
|
|||||||
static struct regmenu_* _stored_reg_menu;
|
static struct regmenu_* _stored_reg_menu;
|
||||||
static struct global_app_data_t* global_app_data;
|
static struct global_app_data_t* global_app_data;
|
||||||
|
|
||||||
|
HANDLE _shared_memory_handle = nullptr;
|
||||||
|
void* _shared_memory_buffer = nullptr;
|
||||||
|
|
||||||
|
|
||||||
int main_proxy()
|
int main_proxy()
|
||||||
{
|
{
|
||||||
// ýìóëèðóåì ïåðâè÷íûé çàïóñê
|
// ýìóëèðóåì ïåðâè÷íûé çàïóñê
|
||||||
@ -590,3 +594,20 @@ void vTaskDelay(int delay_ms)
|
|||||||
System::Threading::Tasks::Task::Delay(delay_ms);
|
System::Threading::Tasks::Task::Delay(delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* get_ptr_screen_memory()
|
||||||
|
{
|
||||||
|
if (_shared_memory_handle == nullptr)
|
||||||
|
{
|
||||||
|
_shared_memory_handle = CreateFileMapping((HANDLE)INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, VIDEO_MEMORY_SIZE, L"meme");
|
||||||
|
if (_shared_memory_handle != nullptr)
|
||||||
|
_shared_memory_buffer = MapViewOfFile(_shared_memory_handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, VIDEO_MEMORY_SIZE);
|
||||||
|
|
||||||
|
if (_shared_memory_buffer != nullptr)
|
||||||
|
{
|
||||||
|
int res = BipEmulatorProxy::ProxyLib::CallbackInt("__shared_memory_enabled__");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _shared_memory_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define abssub(x,y) ((x) > (y) ? (x)-(y) : (y)-(x))
|
#define abssub(x,y) ((x) > (y) ? (x)-(y) : (y)-(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define VIDEO_MEMORY_SIZE 15488
|
||||||
|
|
||||||
#define NULL ((void*)0)
|
#define NULL ((void*)0)
|
||||||
|
|
||||||
@ -198,6 +199,9 @@ typedef struct {
|
|||||||
#define NOTIFY_TYPE_LOW_BAT 42
|
#define NOTIFY_TYPE_LOW_BAT 42
|
||||||
|
|
||||||
|
|
||||||
|
// óêàçàòåëü íà ïàìÿòü ýêðàíà
|
||||||
|
void* get_ptr_screen_memory();
|
||||||
|
|
||||||
unsigned char get_var_menu_overlay();
|
unsigned char get_var_menu_overlay();
|
||||||
|
|
||||||
int vibrate(int count, int on_ms, int off_ms);
|
int vibrate(int count, int on_ms, int off_ms);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user