mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
refactoring: moved DummyOp to its own c# file
This commit is contained in:
parent
61461620a8
commit
5f9010f0bc
3 changed files with 48 additions and 42 deletions
47
source/HelloWorldAssembler/DummyOp.cs
Normal file
47
source/HelloWorldAssembler/DummyOp.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace HelloWorldAssembler {
|
||||
public class DummyOp: Indy.IL2CPU.IL.X86.Op {
|
||||
public override void Assemble(Mono.Cecil.Cil.Instruction aInstruction) {
|
||||
Invoke("GetModuleHandle", 0);
|
||||
Move("[wc.hInstance]", "eax");
|
||||
Invoke("LoadIcon", 0, "IDI_APPLICATION");
|
||||
Move("[wc.hIcon]", "eax");
|
||||
Invoke("LoadCursor", 0, "IDC_ARROW");
|
||||
Move("[wc.hCursor]", "eax");
|
||||
Invoke("RegisterClass", "wc");
|
||||
Test("eax", "eax");
|
||||
JumpIfZero("error");
|
||||
Invoke("CreateWindowEx", 0, "_class", "_title", "WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU", 128, 128, 256, 192, "NULL", "NULL", "[wc.hInstance]", "NULL");
|
||||
Test("eax", "eax");
|
||||
JumpIfZero("error");
|
||||
Label("msg_loop");
|
||||
Invoke("GetMessage", "msg", "NULL", 0, 0);
|
||||
Compare("eax", "1");
|
||||
JumpIfGreater("end_loop");
|
||||
JumpIfNotZero("msg_loop");
|
||||
Invoke("TranslateMessage", "msg");
|
||||
Invoke("DispatchMessage", "msg");
|
||||
JumpAlways("msg_loop");
|
||||
Label("error");
|
||||
Invoke("MessageBox", "NULL", "_error", "NULL", "MB_ICONERROR+MB_OK");
|
||||
Label("end_loop");
|
||||
Invoke("ExitProcess", "[msg.wParam]");
|
||||
Literal("proc WindowProc hwnd,wmsg,wparam,lparam");
|
||||
Push("ebx", "esi", "edi");
|
||||
Compare("[wmsg]", "WM_DESTROY");
|
||||
JumpIfEquals(".wmdestroy");
|
||||
Label(".defwndproc");
|
||||
Invoke("DefWindowProc", "[hwnd]", "[wmsg]", "[wparam]", "[lparam]");
|
||||
JumpAlways(".finish");
|
||||
Label(".wmdestroy");
|
||||
Invoke("PostQuitMessage", "0");
|
||||
Xor("eax", "eax");
|
||||
Label(".finish");
|
||||
Pop("edi", "esi", "ebx");
|
||||
Ret();
|
||||
Literal("endp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DummyOp.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -6,48 +6,6 @@ using X86 = Indy.IL2CPU.Assembler.X86;
|
|||
using Indy.IL2CPU.Assembler.X86;
|
||||
|
||||
namespace HelloWorldAssembler {
|
||||
public class DummyOp: Indy.IL2CPU.IL.X86.Op {
|
||||
public override void Assemble(Mono.Cecil.Cil.Instruction aInstruction) {
|
||||
Invoke("GetModuleHandle", 0);
|
||||
Move("[wc.hInstance]", "eax");
|
||||
Invoke("LoadIcon", 0, "IDI_APPLICATION");
|
||||
Move("[wc.hIcon]", "eax");
|
||||
Invoke("LoadCursor", 0, "IDC_ARROW");
|
||||
Move("[wc.hCursor]", "eax");
|
||||
Invoke("RegisterClass", "wc");
|
||||
Test("eax", "eax");
|
||||
JumpIfZero("error");
|
||||
Invoke("CreateWindowEx", 0, "_class", "_title", "WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU", 128, 128, 256, 192, "NULL", "NULL", "[wc.hInstance]", "NULL");
|
||||
Test("eax", "eax");
|
||||
JumpIfZero("error");
|
||||
Label("msg_loop");
|
||||
Invoke("GetMessage", "msg", "NULL", 0, 0);
|
||||
Compare("eax", "1");
|
||||
JumpIfGreater("end_loop");
|
||||
JumpIfNotZero("msg_loop");
|
||||
Invoke("TranslateMessage", "msg");
|
||||
Invoke("DispatchMessage", "msg");
|
||||
JumpAlways("msg_loop");
|
||||
Label("error");
|
||||
Invoke("MessageBox", "NULL", "_error", "NULL", "MB_ICONERROR+MB_OK");
|
||||
Label("end_loop");
|
||||
Invoke("ExitProcess", "[msg.wParam]");
|
||||
Literal("proc WindowProc hwnd,wmsg,wparam,lparam");
|
||||
Push("ebx", "esi", "edi");
|
||||
Compare("[wmsg]", "WM_DESTROY");
|
||||
JumpIfEquals(".wmdestroy");
|
||||
Label(".defwndproc");
|
||||
Invoke("DefWindowProc", "[hwnd]", "[wmsg]", "[wparam]", "[lparam]");
|
||||
JumpAlways(".finish");
|
||||
Label(".wmdestroy");
|
||||
Invoke("PostQuitMessage", "0");
|
||||
Xor("eax", "eax");
|
||||
Label(".finish");
|
||||
Pop("edi", "esi", "ebx");
|
||||
Ret();
|
||||
Literal("endp");
|
||||
}
|
||||
}
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
using (StreamWriter xSW = new StreamWriter("out.asm")) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue