ADD: Экспериментальная поддержка прямого доступа к видеопамяти

CHG: Исправлены настройки конфигурации RELEASE
This commit is contained in:
freebipman 2020-08-01 20:20:45 +10:00
parent 39014d3427
commit ad003776ae
8 changed files with 120 additions and 2 deletions

View File

@ -32,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -55,6 +56,7 @@
<ItemGroup>
<Compile Include="BitReader.cs" />
<Compile Include="ColorArray.cs" />
<Compile Include="ColorIndexEnum.cs" />
<Compile Include="DisplayNameAttribute.cs" />
<Compile Include="ColorSelectionForm.cs">
<SubType>Form</SubType>

View 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,
}
}

View File

@ -29,5 +29,8 @@
public const string TEXT_OUT_CENTER = "text_out_center";
public const string TEXT_WIDTH = "text_width";
public const string VIBRATE = "vibrate";
// special emulator functions
public const string SHARED_MEMORY_ENABLED = "__shared_memory_enabled__";
}
}

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
@ -13,6 +14,7 @@ namespace BipEmulator.Host
{
public partial class MainForm : Form, IMessageFilter
{
const int VIDEO_MEMORY_SIZE = 15488;
/// <summary>
/// Функция обратного вызова
/// </summary>
@ -29,6 +31,11 @@ namespace BipEmulator.Host
private IntPtr _hrmDataPointer = IntPtr.Zero;
private bool _useSharedVideoMemory;
MemoryMappedFile _sharedMemoryFile;
MemoryMappedViewStream _sharedMemoryViewStream;
private byte[] _videoMemory = new byte[VIDEO_MEMORY_SIZE];
public MainForm()
{
InitializeComponent();
@ -134,7 +141,15 @@ namespace BipEmulator.Host
return ucScreen.GetTextWidth(args[1].ToString());
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]);
if (ucScreen.InvokeRequired)
{
try
@ -303,6 +318,10 @@ namespace BipEmulator.Host
}
return (int)locale;
case FunctionNames.SHARED_MEMORY_ENABLED:
_useSharedVideoMemory = OpenFileMapping();
return _useSharedVideoMemory ? 1 : 0;
// заглушки
case FunctionNames.VIBRATE:
@ -321,6 +340,21 @@ namespace BipEmulator.Host
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()
{
foreach (LocaleEnum locale in Enum.GetValues(typeof(LocaleEnum)))

View File

@ -35,6 +35,7 @@ namespace BipEmulator.Host
_ftMaker = new FtMaker(_ftFile);
}
protected override void OnSizeChanged(EventArgs e)
{
Width = SIZE;
@ -177,5 +178,43 @@ namespace BipEmulator.Host
{
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();
}
}
}

View File

@ -99,8 +99,9 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>

View File

@ -239,6 +239,10 @@ const char* SETTINGS_FILE = "settings.bin";
static struct regmenu_* _stored_reg_menu;
static struct global_app_data_t* global_app_data;
HANDLE _shared_memory_handle = nullptr;
void* _shared_memory_buffer = nullptr;
int main_proxy()
{
// ýìóëèðóåì ïåðâè÷íûé çàïóñê
@ -590,3 +594,20 @@ void vTaskDelay(int 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;
}

View File

@ -17,6 +17,7 @@
#define abssub(x,y) ((x) > (y) ? (x)-(y) : (y)-(x))
#endif
#define VIDEO_MEMORY_SIZE 15488
#define NULL ((void*)0)
@ -198,6 +199,9 @@ typedef struct {
#define NOTIFY_TYPE_LOW_BAT 42
// óêàçàòåëü íà ïàìÿòü ýêðàíà
void* get_ptr_screen_memory();
unsigned char get_var_menu_overlay();
int vibrate(int count, int on_ms, int off_ms);