commit ede95dc2056d637f4002a2ef7bc1319d766fbaa3 Author: Stanislav N Mikhailov Date: Sun Dec 14 19:18:37 2025 +0300 First window (init commit) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..faea445 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# ---> VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix +*.obj diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6db1228 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,56 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version":"2.0.0", + "tasks":[ + { + "label":"assemble", + "type":"shell", + "args":[ + "/I", + "include", + "/c", + "src/${fileBasenameNoExtension}.asm" + + ], + "command":"ml64.exe", + "problemMatcher":{ + "owner":"nasm", + "fileLocation":["relative","${workspaceFolder}"], + "pattern":{ + "regexp":"^(.*)\\((\\d*)\\)\\s+:?\\s+(error|warning)\\s+([A-z]+\\d+):\\s+(.*)$", + "file":1, + "line":2, + "severity":3, + "code":4, + "message":5, + "loop":true + } + } + }, + { + "label":"link", + "type":"shell", + "args":[ + "/SUBSYSTEM:WINDOWS", + "/MACHINE:X64", + "/ENTRY:entry_point", + "/nologo", + "/LARGEADDRESSAWARE", + "${fileBasenameNoExtension}.obj" + ], + "command":"link.exe", + "dependsOn":"assemble" + }, + { + "label":"execute", + "type":"shell", + "command":"${workspaceFolder}/${fileBasenameNoExtension}.exe", + "group":{ + "kind":"build", + "isDefault":true + }, + "dependsOn":"link" + } + ] +} diff --git a/Mandelbrot.exe b/Mandelbrot.exe new file mode 100644 index 0000000..e18eabf Binary files /dev/null and b/Mandelbrot.exe differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7c9a1f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Cocaine - +A playful name for a low-level replacement for the Caffeine app. It works by calling SetThreadExecutionState +# Кокаин - +Шутливое название для низкоуровневой замены приложения Caffeine. Работает за счёт вызова SetThreadExecutionState + diff --git a/include/template.inc b/include/template.inc new file mode 100644 index 0000000..2b54ba4 --- /dev/null +++ b/include/template.inc @@ -0,0 +1,47 @@ +include /masm64/include64/masm64rt.inc +;______________________Прототипы__________________________ +WinMain proto :HINSTANCE,:HINSTANCE,:LPSTR,:QWORD + +myPaint proto :HWND ;Обработка сообщения WM_PAINT +myDraw proto nSegment:DWORD ;принимаю параметр с колличеством сегментов (в HIWORD) и номером данного сегмента (в LOWORD) +;_______________________________________________________ +.data? +hInstance HINSTANCE ? ; Хэндл нашей пpогpаммы +CommandLine LPSTR ? +BITMAPINFOHEADER STRUCT + biSize DWORD ?; + biWidth LONG ?; + biHeight LONG ?; + biPlanes WORD ?; + biBitCount WORD ?; + biCompression DWORD ?; + biSizeImage DWORD ?; + biXPelsPerMeter LONG ?; + biYPelsPerMeter LONG ?; + biClrUsed DWORD ?; + biClrImportant DWORD ?; +BITMAPINFOHEADER ENDS +RGBQUAD STRUCT + rgbBlue BYTE ? + rgbGreen BYTE ? + rgbRed BYTE ? + rgbReserved BYTE ? +RGBQUAD ENDS +BITMAPINFO STRUCT + bmiHeader BITMAPINFOHEADER <> + bmiColors RGBQUAD <> +BITMAPINFO ENDS + + +;_______________________________________________________ +.data +szClassName db "CocaClass",0 ; Имя нашего класса окна +AppName db "Cocaine - no sleeping on the job!",0 ; Имя нашего окна +ELAPSE_UPDTIMER EQU 20 +IDT_UPDTIMER EQU 111 +wc WNDCLASSEX +bmi BITMAPINFO <> +rc RECT <> + + + diff --git a/src/Mandelbrot.asm b/src/Mandelbrot.asm new file mode 100644 index 0000000..12bdf81 --- /dev/null +++ b/src/Mandelbrot.asm @@ -0,0 +1,76 @@ +include template.inc +.code +entry_point proc + invoke GetModuleHandle, NULL ; Взять хэндл пpогpаммы + mov hInstance,rax ; Под Win32, hmodule==hinstance mov hInstance,eax + invoke GetCommandLine ; Взять командную стpоку. Вы не обязаны + ;вызывать эту функцию ЕСЛИ ваша пpогpамма не обpабатывает командную стpоку. + mov CommandLine,rax + invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT ; вызвать основную функцию + invoke ExitProcess, rax ; Выйти из пpогpаммы. + ; Возвpащаемое значение, помещаемое в eax, беpется из WinMain'а. +entry_point endp +;______________________________________________________________________________________________________________________________________________________________ +WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:QWORD + ; создание локальных пеpеменных в стеке + LOCAL msg:MSG + LOCAL hwnd:HWND + ;регистрация оконного класса + push hInstance + pop wc.hInstance + invoke LoadIcon,NULL,IDI_APPLICATION + mov wc.hIcon,rax + mov wc.hIconSm,rax + invoke LoadCursor,NULL,IDC_ARROW + mov wc.hCursor,rax + invoke RegisterClassEx, addr wc ; pегистpация нашего класса окнаW + invoke CreateWindowEx,NULL,ADDR szClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,282,0,1354,1017,NULL,NULL,hInst,NULL + mov hwnd,rax + invoke ShowWindow,hwnd,CmdShow ; отобpазить наше окно на десктопе (вместо CmdShow можно указать свойство 3 - во весь экран) + invoke UpdateWindow, hwnd ; обновить клиентскую область + .while TRUE ; Enter message loop + invoke GetMessage, ADDR msg,NULL,0,0 + .break .if (rax==0) + invoke TranslateMessage, ADDR msg + invoke DispatchMessage, ADDR msg + .endw + mov rax,msg.wParam ; сохpанение возвpащаемого значения в eax + ret +WinMain endp +;______________________________________________________________________________________________________________________________________________________________ +WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM + LOCAL hDC:HDC + .if uMsg==WM_DESTROY ; если пользователь закpывает окно + invoke PostQuitMessage,NULL ; выходим из пpогpаммы + .elseif uMsg==WM_CREATE + + + + .elseif uMsg==WM_PAINT + invoke myPaint,hWnd + .elseif uMsg==WM_ERASEBKGND + mov rax,TRUE + ret + .else + invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Дефолтная функция обpаботки окна + ret + .endif + xor rax,rax + + ret +WndProc endp +;______________________________________________________________________________________________________________________________________________________________ + +;______________________________________________________________________________________________________________________________________________________________ + +;______________________________________________________________________________________________________________________________________________________________ +myPaint proc hWndPaint:HWND + LOCAL ps:PAINTSTRUCT + invoke BeginPaint,hWndPaint,ptr$(ps) ;тут создаётся контекст устройства окна + + + invoke EndPaint,hWndPaint,ptr$(ps) + ret +myPaint endp + +end