From ad003776ae692e0d156153aa724676817e82eaa5 Mon Sep 17 00:00:00 2001 From: freebipman Date: Sat, 1 Aug 2020 20:20:45 +1000 Subject: [PATCH] =?UTF-8?q?ADD:=20=D0=AD=D0=BA=D1=81=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D1=80=D1=8F=D0=BC=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=83=D0=BF=D0=B0=20=D0=BA=20=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D0=B5=D0=BE=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8=20CHG:=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20RELEASE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BipEmulator.Host/BipEmulator.Host.csproj | 2 + src/BipEmulator.Host/ColorIndexEnum.cs | 14 +++++++ src/BipEmulator.Host/FunctionNames.cs | 3 ++ src/BipEmulator.Host/MainForm.cs | 34 ++++++++++++++++ src/BipEmulator.Host/WatchScreen.cs | 39 +++++++++++++++++++ .../BipEmulator.Proxy.vcxproj | 5 ++- src/BipEmulator.Proxy/ProxyLib.cpp | 21 ++++++++++ src/BipEmulator.Proxy/libbip.h | 4 ++ 8 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/BipEmulator.Host/ColorIndexEnum.cs diff --git a/src/BipEmulator.Host/BipEmulator.Host.csproj b/src/BipEmulator.Host/BipEmulator.Host.csproj index bc21f59..b7b664c 100644 --- a/src/BipEmulator.Host/BipEmulator.Host.csproj +++ b/src/BipEmulator.Host/BipEmulator.Host.csproj @@ -32,6 +32,7 @@ TRACE prompt 4 + true @@ -55,6 +56,7 @@ + Form diff --git a/src/BipEmulator.Host/ColorIndexEnum.cs b/src/BipEmulator.Host/ColorIndexEnum.cs new file mode 100644 index 0000000..75b3f56 --- /dev/null +++ b/src/BipEmulator.Host/ColorIndexEnum.cs @@ -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, + } +} diff --git a/src/BipEmulator.Host/FunctionNames.cs b/src/BipEmulator.Host/FunctionNames.cs index 50c3054..38e2ce4 100644 --- a/src/BipEmulator.Host/FunctionNames.cs +++ b/src/BipEmulator.Host/FunctionNames.cs @@ -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__"; } } diff --git a/src/BipEmulator.Host/MainForm.cs b/src/BipEmulator.Host/MainForm.cs index 3e27179..616c47c 100644 --- a/src/BipEmulator.Host/MainForm.cs +++ b/src/BipEmulator.Host/MainForm.cs @@ -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; /// /// Функция обратного вызова /// @@ -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))) diff --git a/src/BipEmulator.Host/WatchScreen.cs b/src/BipEmulator.Host/WatchScreen.cs index e56e402..2b377f2 100644 --- a/src/BipEmulator.Host/WatchScreen.cs +++ b/src/BipEmulator.Host/WatchScreen.cs @@ -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> 4)); + shadow.SetPixel(x+1, y, GetColorByIndex(videoMemory[offset] & 0xf)); + offset++; + } + shadow.Unlock(); + } } } diff --git a/src/BipEmulator.Proxy/BipEmulator.Proxy.vcxproj b/src/BipEmulator.Proxy/BipEmulator.Proxy.vcxproj index c3ea8a6..bb22a95 100644 --- a/src/BipEmulator.Proxy/BipEmulator.Proxy.vcxproj +++ b/src/BipEmulator.Proxy/BipEmulator.Proxy.vcxproj @@ -99,8 +99,9 @@ - Use - pch.h + NotUsing + + Level3 WIN32;NDEBUG;%(PreprocessorDefinitions) diff --git a/src/BipEmulator.Proxy/ProxyLib.cpp b/src/BipEmulator.Proxy/ProxyLib.cpp index 6f46f56..af173a0 100644 --- a/src/BipEmulator.Proxy/ProxyLib.cpp +++ b/src/BipEmulator.Proxy/ProxyLib.cpp @@ -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; +} + diff --git a/src/BipEmulator.Proxy/libbip.h b/src/BipEmulator.Proxy/libbip.h index da08796..455cf3c 100644 --- a/src/BipEmulator.Proxy/libbip.h +++ b/src/BipEmulator.Proxy/libbip.h @@ -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);