{"id":297446,"date":"2020-01-21T15:00:21","date_gmt":"2020-01-21T15:00:21","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297446"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297446","title":{"rendered":"\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438\u0433\u0440\u0443 \u043d\u0430 C# \u0432 MS-DOS"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484854\/\">\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u043b\u043e, \u0447\u0442\u043e \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c 64-\u0431\u0438\u0442\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u043d\u0430 C# \u043f\u043e\u0434 MS-DOS. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d4a\/67c\/7c9\/d4a67c7c9bdca5399adfeca43df14531.gif\"><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u0434 Windows \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<ol>\n<li>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0434\u043b\u044f DOS, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u00ab\u0414\u0430\u043d\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 DOS\u00bb<\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Portable_Executable\">\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 Windows<\/li>\n<\/ol>\n<p>  \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0432\u0441\u0435 .exe-\u0444\u0430\u0439\u043b\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438 \u0434\u043b\u044f DOS, \u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e. \u0418 \u0432\u043e\u0442 \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u044f \u043d\u0430\u0448\u0435\u043b \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 Github, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0437\u0432\u0435\u0437\u0434, \u0447\u0435\u043c \u0443 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c:<\/p>\n<p>  <a href=\"https:\/\/github.com\/Baron-von-Riedesel\/Dos64-stub\">github.com\/Baron-von-Riedesel\/Dos64-stub<\/a><\/p>\n<p>  Dos64-stub \u2014 \u044d\u0442\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u00ab\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043f\u043e\u0434 DOS\u00bb \u043d\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 Windows-\u0441\u0435\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u00ab\u0442\u0435\u043b\u0435\u043f\u043e\u0440\u0442\u0430\u0446\u0438\u044e\u00bb \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 21 \u0432\u0435\u043a. \u041f\u043e\u0434 \u00ab\u0442\u0435\u043b\u0435\u043f\u043e\u0440\u0442\u0430\u0446\u0438\u0435\u0439\u00bb \u044f \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432 64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c (\u00ablong\u00bb).<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0432\u0437\u044f\u043b \u0441\u0432\u043e\u044e \u0438\u0433\u0440\u0443 \u00ab\u0417\u043c\u0435\u0439\u043a\u0430\u00bb \u043f\u043e\u0434 Windows, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0443\u0436\u0430\u043b \u0434\u043e 8 \u043a\u0431 \u0431\u0435\u0437 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/p>\n<div class=\"oembed\">\n<blockquote class=\"twitter-tweet\" data-lang=\"en_US\">\n<p lang=\"en\" dir=\"ltr\">For my next trick, I&#39;m going to build a 65 MB self-contained game in C# and shrink it to 8 kB (still 100% self-contained): <a href=\"https:\/\/t.co\/ykhOjSoa3u\">https:\/\/t.co\/ykhOjSoa3u<\/a> <a href=\"https:\/\/t.co\/tblEAM3HsO\">pic.twitter.com\/tblEAM3HsO<\/a><\/p>\n<p>&mdash; Michal Strehovsk\u00fd (@MStrehovsky) <a href=\"https:\/\/twitter.com\/MStrehovsky\/status\/1213034748848807937?ref_src=twsrc%5Etfw\">January 3, 2020<\/a><\/p><\/blockquote>\n<p> <script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script> <\/div>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 DOS \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b Windows API, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u043e\u0439 \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b \u0441\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c. \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0435\u043f\u0435\u0440\u044c <code>Environment.TickCount<\/code>:<\/p>\n<pre><code class=\"cs\">public static unsafe long TickCount64 {     [MethodImpl(MethodImplOptions.NoInlining)]     get     {         \/\/ \u0427\u0438\u0442\u0430\u0435\u043c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 BIOS - \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0439 1AH.         \/\/ \u0414\u0430, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e \u043d\u0435\u043a\u043e\u043c\u0443 &quot;\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c\u0443&quot; \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e.         \/\/ \u041e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 BIOS - \u044d\u0442\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430,         \/\/ \u043a\u043e\u0442\u043e\u0440\u0443\u044e BIOS \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430.         \/\/ \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434 DOS \u043c\u043e\u0433\u0443\u0442 \u0435\u0435 \u0447\u0438\u0442\u0430\u0442\u044c.         \/\/ \u041f\u043e \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e 0x46C \u043b\u0435\u0436\u0438\u0442 \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430\u0445 \u043f\u043e 55\u043c\u0441.         uint timerTicks = * (uint *) 0x46C;         return (long) timerTicks * 55;     } } <\/code><\/pre>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0438\u043a\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>Thread.Sleep<\/code>:<\/p>\n<pre><code class=\"cs\">public static unsafe void Sleep(int delayMs) { \t\/\/ \u041f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u043d\u0430 \u0441\u0442\u0435\u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442\u043e\u0432: 0xF4 0xC3         \/\/ \u042d\u0442\u0438 \u0431\u0430\u0439\u0442\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c: \t\/\/ \t\/\/ hlt \t\/\/ ret \t \tushort hlt = 0xc3f4; \tlong expected = Environment.TickCount64 + delayMs; \twhile(Environment.TickCount64 &lt; expected) \t{ \t\t\/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u043d\u0430 \u0441\u0442\u0435\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0435\u043d\u0430\u0434\u043e\u043b\u0433\u043e \t\t\/\/ \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \t\t\/\/ (\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0438\u043a\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u044b\u0434\u0430\u044e\u0442 \u0432 \u0443\u0433\u043b\u0443)  \t\tClassConstructorRunner.Call&lt;int&gt;(new IntPtr(&hlt;)); \t} } <\/code><\/pre>\n<p>  \u0410 \u043f\u043e\u0442\u043e\u043c \u0438 <code>Console.WriteLine<\/code>:<\/p>\n<pre><code class=\"cs\">public static unsafe void Write(char c) {     byte* biosDataArea = (byte*)0x400; \t     \/\/ \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430\u0447\u0430\u043b\u043e VRAM, \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 BIOS     byte* vram = (byte*)0xB8000;     if(*(biosDataArea + 0x63) == 0xB4)         vram = (byte*)0xB0000; \t\t     \/\/ \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b     vram += * (ushort*)(biosDataArea + 0x4E);      \/\/ \u0422\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u044e\u043d\u0438\u043a\u043e\u0434\u0430 \u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0445\u0430\u0440\u0434\u0432\u0430\u0440\u043d\u043e\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 IBM     byte b = c switch     {         '\u2502' =&gt; (byte)0xB3,         '\u250c' =&gt; (byte)0xDA,         '\u2510' =&gt; (byte)0xBF,         '\u2500' =&gt; (byte)0xC4,         '\u2514' =&gt; (byte)0xC0,         '\u2518' =&gt; (byte)0xD9,         _ =&gt; (byte)c,     };      \/\/ TODO: \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0438\u0437 BIOS     vram[(s_cursorY * 80 * 2) + (s_cursorX * 2)] = b;     vram[(s_cursorY * 80 * 2) + (s_cursorX * 2) + 1] = (byte)s_consoleAttribute; \t     \/\/ TODO: \u0441\u043a\u0440\u043e\u043b\u043b\u0438\u0442\u044c \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443?     s_cursorX++; } <\/code><\/pre>\n<p>  \u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e: \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 C# -&gt; \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 CoreRT AOT -&gt; \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a. \u041c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Dos64-stub \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/334\/a8f\/1d7\/334a8f1d70d4edbe611b3e345f6fcc77.png\"><\/p>\n<p>  <a href=\"https:\/\/github.com\/MichalStrehovsky\/SeeSharpSnake\/pull\/5\">\u0410 \u0432\u043e\u0442 \u0438 \u0432\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0443\u043b\u043b-\u0440\u0435\u043a\u0432\u0435\u0441\u0442\u0430<\/a>.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/484854\/\"> https:\/\/habr.com\/ru\/post\/484854\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484854\/\">\u041c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u043b\u043e, \u0447\u0442\u043e \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c 64-\u0431\u0438\u0442\u043d\u0443\u044e \u0438\u0433\u0440\u0443 \u043d\u0430 C# \u043f\u043e\u0434 MS-DOS. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d4a\/67c\/7c9\/d4a67c7c9bdca5399adfeca43df14531.gif\">  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297446","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297446"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297446\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}