News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Examples for Win64 Iczelion tutorial

Started by Mikl__, April 30, 2015, 03:14:46 PM

Previous topic - Next topic

Mikl__

Win x64 Tutorial #38c: Processing of mouse messages
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
buffersize = 100
.code
WinMain proc
local BUFF[buffersize]:byte   
local hIn:qword
local hOut:qword
local result:qword
local MOUSE_KEY:INPUT_RECORD
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO

push rbp
mov ebp,esp
sub esp,(28h+3*8+buffersize+sizeof INPUT_RECORD+\
        sizeof SMALL_RECT+sizeof CONSOLE_CURSOR_INFO+15)and(-16)

call FreeConsole
        call AllocConsole
        mov ecx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov ecx,eax ;hOut
call GetLargestConsoleWindowSize
; rax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize ;establish the new size of console window
mov ecx,offset NameConsole
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
lea edx,cci ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
        mov qword ptr [rsp+20h],0
lea r9d,result ;&result
        mov r8d,sizeof Str1
mov edx,offset Str1     
mov rcx,hOut
        call WriteConsole
        mov edx,0B000Bh ;Y=11 X=0
        mov rcx,hOut
        call SetConsoleCursorPosition
        mov qword ptr [rsp+20h],0
        lea r9d,result
        mov r8d,sizeof Str2
        mov edx,offset Str2
        mov rcx,hOut
        call WriteConsole
@@:     mov edx,0A0009h ;Y=10 X=0
        mov rcx,hOut
        call SetConsoleCursorPosition
lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
lea edx,MOUSE_KEY
cmp [rdx+INPUT_RECORD.EventType],MOUSE_EVENT
jne LOO1
xor eax,eax
mov ax,[rdx+INPUT_RECORD.MouseEvent.dwMousePosition.y]
mov [rsp+28h],rax
        mov ax,[rdx+INPUT_RECORD.MouseEvent.dwMousePosition.x]
        mov [rsp+20h],rax
        mov r8d,[rdx+INPUT_RECORD.MouseEvent.dwButtonState]
cmp r8d,4
sbb ecx,ecx
and r8d,ecx
mov edx,offset fmt
lea ecx,BUFF
call wsprintf
mov qword ptr [rsp+20h],0
        lea r9d,result
        mov r8d,eax
lea edx,BUFF
        mov rcx,hOut
        call WriteConsole
jmp @b
LOO1:   lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
        call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
NameConsole db 'Processing of mouse messages',0
fmt db 'Button state: %u, X: %u, Y: %u',0
Str1 db 'For exit press ESC or CTRL+C'
Str2 db 'No clicks = 0',0Dh,0Ah,\
'          Left click = 1',0Dh,0Ah,\
'         Right click = 2',0Dh,0Ah,\
'Left and Right click = 3',0
end

Mikl__

Win x64 Tutorial #38d: Installation of color of symbols and background of the text of the  console application (yet another variant)
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
includelib msvcrt.lib
MAXSCREENX = 80
MAXSCREENY = 25
LEFT    = 8
TOP    = 4
buffersize = 100
.code
WinMain proc
local BUFF[buffersize]:byte   
local hIn:qword
local hOut:qword
local result:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD
local color:dword
local count:dword
local coord:COORD

        push rbp
mov ebp,esp
sub esp,(30h+3*8+2*4+buffersize+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+COORD+15)and(-16)

        call FreeConsole
        call AllocConsole
        mov rcx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov rcx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov ecx,eax;hOut ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ;hConsoleOutput
call SetConsoleScreenBufferSize ;establish the new size of a window of the console
mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
        mov qword ptr [rsp+20h],0
lea r9d,result ;&result
        mov r8d,sizeof Str2
mov edx,offset Str2     
mov rcx,hOut
        call WriteConsole
        mov count,0Fh
mov coord,10000h ; X=0 Y=1
@0:     mov color,0Fh
@@:     mov edx,coord
        mov rcx,hOut
        call SetConsoleCursorPosition
; To establish color and a background of the text of the console
        ; 4-7 bits - background color
        ; 0-3 bits - text color
        ; other bits aren't used
mov edx,color
mov rcx,hOut
        call SetConsoleTextAttribute
        mov qword ptr [rsp+20h],0
        lea r9d,result
        mov r8d,1
mov edx,offset Str3
        mov rcx,hOut
        call WriteConsole
        inc color
inc coord.x
cmp coord.x,MAXSCREENX
jb @b
dec count
mov eax,count
mov color,eax
inc coord.y
        mov coord.x,0
cmp coord.y,MAXSCREENY-1
jnz @b
;------------------------------------------------------------------
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
        call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Installation of color of symbols and background of the text of the  console application',0
Str2 db 'For exit press ESC or CTRL+C or CTRL+Break'
Str3 db 'o'
end

Mikl__

Win x64 Tutorial #38e: Simple  console application (yet another variant)
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc

MAXSCREENX = 80
MAXSCREENY = 25
buffersize = 200

.code
WinMain proc
local coord:COORD
local hOut:qword
local hIn:qword
local BUFF[buffersize]:byte
local ConsoleWindow:SMALL_RECT
local result:qword
local dwLength:dword
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(28h+3*8+4+buffersize+sizeof INPUT_RECORD+sizeof COORD+\
        sizeof SMALL_RECT+sizeof CONSOLE_CURSOR_INFO+15)and(-16)

        xor ebx,ebx
        call FreeConsole ; release the existing console
        call AllocConsole ; create the console
        mov ecx,STD_INPUT_HANDLE
call GetStdHandle ; receive handle for a input
mov hIn,rax
mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle ; receive handle for a output
        mov hOut,rax
        mov ecx,eax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo
;------------------------------------------------------------------
mov edx,MAXSCREENY*10000h+MAXSCREENX; dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize ; establish the new size of console window
mov ecx,offset NameConsole
call SetConsoleTitle ; definition of a title bar
;------------------------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,BUFF
mov r8d,sizeof Str1
mov edx,offset Str1
mov rcx,hOut ; hConsoleOutput
call WriteConsole ; display a line of symbols
;hide cursor----------------------------------------
lea edx,cci ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
lea edx,cci ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
;demonstration of positioning of the cursor
        mov coord,10000h ;y=1 x=0
@@: movzx r9d,coord.y
movzx r8d,coord.x
mov edx,offset fmt1
lea ecx,BUFF
call sprintf
mov dwLength,eax
mov edx,coord
mov rcx,hOut
        call SetConsoleCursorPosition ; establish a cursor position
        mov [rsp+20h],rbx
lea r9d,result
        mov r8d,dwLength
lea edx,BUFF
mov rcx,hOut
        call WriteConsole ; display a line of symbols
        add coord,10005h ; x = x + 5  y = y + 1
cmp coord.y,10
jb @b
; change of color of symbols
mov edx,0C0000h ; coord
mov rcx,hOut
call SetConsoleCursorPosition ; establish a cursor position
mov edx,FOREGROUND_BLUE or BACKGROUND_GREEN
mov rcx,hOut
call SetConsoleTextAttribute ; set color attributes of the output text
mov [rsp+20h],rbx
lea r9d,result
mov r8d,sizeof Str3
mov edx,offset Str3
mov rcx,hOut
call WriteConsole ; display a line of symbols
mov edx,FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED
mov rcx,hOut
call SetConsoleTextAttribute ; set color attributes of the output text
mov edx,0E0000h ; coord
mov rcx,hOut
call SetConsoleCursorPosition ; establish a cursor position

mov [rsp+20h],rbx
lea r9d,result
mov r8d,sizeof Str4
mov edx,offset Str4
mov rcx,hOut
call WriteConsole ; display a line of symbols
; reading the entered line       
mov [rsp+20h],rbx
lea r9d,result
mov r8d,80
lea edx,BUFF
mov rcx,hIn
        call ReadConsole ; wait for input of a line of symbols
mov rax,result
lea esi,BUFF
mov byte ptr [rax+rsi-2],0 ; 2 symbols CR and LF
; remove ASCII code of the entered symbols
xor eax,eax
mov dwLength,eax
@@: lodsb
or eax,eax
jz @f
mov edx,eax
mov ecx,offset fmt2
call printf
add dwLength,eax
jmp @b
@@: mov ecx,dwLength
neg ecx
mov [rsp+20h],rbx
lea r9d,result
mov r8d,ecx ; length of the removed line
lea edx,BUFF
mov rcx,hOut
call WriteConsole
; it is possible to use the functions printf, gets, etc.
mov ecx,offset Str5
call printf
lea ecx,BUFF
call gets
lea edx,BUFF
mov ecx,offset fmt3
call printf
mov ecx,offset Str2
call printf
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
        call FreeConsole;закрываем консоль
xor ecx,ecx
        call ExitProcess
WinMain endp
NameConsole db 'Simple example of console',0
Str1 db 'This is sample output string',13,10
Str2 db 'For exit from program press ESC or CTRL+C or CTRL+Break',0
Str3 db 'This is Blue text on Green background'
Str4 db 'Enter a line of symbols and you can to see ASCII-code of symbols: ',0Dh,0Ah
Str5 db 0Dh,0Ah,'This is a test. Enter another string: ',0Dh,0Ah,0
fmt1 db "Text position X=%d, Y=%d",0
fmt2 db "%X ",0
fmt3 db "%s",0Dh,0Ah,0
end

Mikl__

Win x64 Tutorial #38f: Progress bar in console
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
colors1 = 159
colors2 = 249
.code
WinMain proc
local hIn:qword
local hOut:qword
local result:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local CSBI:CONSOLE_SCREEN_BUFFER_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(28h+3*8+sizeof SMALL_RECT+sizeof INPUT_RECORD+\
        sizeof CONSOLE_CURSOR_INFO+sizeof CONSOLE_SCREEN_BUFFER_INFO+15)and(-16)

        xor ebx,ebx
call FreeConsole
        call AllocConsole
        mov rcx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov rcx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov ecx,eax;hOut ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
; ConsoleWindow.Left = ConsoleWindow.Top = 0
mov dword ptr [r8+SMALL_RECT.Left],ebx

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ;hConsoleOutput
call SetConsoleScreenBufferSize ;establish the new size of a window of the console
mov ecx,offset ConsoleName
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci         ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci         ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
        mov [rsp+20h],rbx
lea r9d,result                     ;&result
        mov r8d,sizeof Str2
mov edx,offset Str2     
mov rcx,hOut
        call WriteConsole
;Get Console Info
;with Get CursorPosition Start
lea edx,CSBI
mov rcx,hOut
call GetConsoleScreenBufferInfo
;Loop of bar 0 - 100
;Write procent char (only one time)
mov procentbar[27], '%'
;Write ascii procent
@0: mov dl,10
mov eax,procent
div dl
add ax,'00'
mov word ptr procentbar[24], ax
cmp al,3Ah
jnz @f
        mov word ptr procentbar[23],'01'
@@: ;Set CursorPosition Start
mov eax,CSBI.dwCursorPosition
mov edx, eax
mov rcx,hOut
call SetConsoleCursorPosition
;Set Color1
mov edx, colors1
        mov rcx,hOut
call SetConsoleTextAttribute
;Write proportial part
mov [rsp+20h],rbx
mov r9d,offset n
mov r8d,procent
shr r8d,1
mov edx,offset procentbar
mov rcx,hOut
call WriteFile
;Set Color2
mov edx, colors2
mov rcx,hOut
call SetConsoleTextAttribute
;Write proportial part end
mov edx,procent
shr edx,1
mov r8d,50
sub r8d,edx
add edx,offset procentbar
mov [rsp+20h],rbx
mov r9d,offset n
mov rcx,hOut
call WriteFile
;Wait for slow speed
mov ecx,procent
shr ecx,2
add ecx,80
call Sleep
;Add procent
inc procent
cmp procent,101
jb @0
;Set Text Color on default
movzx edx,CSBI.wAttributes
mov rcx,hOut
call SetConsoleTextAttribute

@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
        call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
ConsoleName db 'Progress bar in console',0
Str2 db 'For exit press ESC or CTRL+C or CTRL+Break',13,10,10,32
procentbar db 50 dup (32),0,0
procent dd 0
n dd 0
end

Mikl__

#124
Win x64 Tutorial #38g: Console application animation
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
includelib winmm.lib
include winmm.inc
const1    = 68 ; width and height of Earth picture
MAXSCREENX = 80
MAXSCREENY = 25
.code
WinMain proc
local result:qword
local hIn:qword
local IDtimer:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD


        push rbp
mov ebp,esp
sub esp,(28h+3*8+sizeof INPUT_RECORD+\
        sizeof SMALL_RECT+sizeof CONSOLE_CURSOR_INFO+15)and(-16)

xor ebx,ebx
        call FreeConsole ;release the existing console
        call AllocConsole ;create the console
mov ecx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax                        ; receive handle for a input
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax                       ; receive handle for a output
        mov ecx,eax ;hOut
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov dword ptr [r8+SMALL_RECT.Left],ebx
;ConsoleWindow.Left = ConsoleWindow.Top = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX; dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize ; establish the new size of console window

        xor edx,edx
mov ecx,offset ClassConsole
call FindWindow
mov hWnd,rax
mov rcx,rax
call GetDC
mov hDC,rax
        xor ecx,ecx
call CreateSolidBrush
mov BlackBrush,rax
mov rdx,rax ;keep a black brush in a context
mov rcx,hDC
call SelectObject
        ;load the picture
mov qword ptr [rsp+28h],LR_LOADFROMFILE
mov [rsp+20h],rbx
xor r9d,r9d
xor r8d,r8d
mov edx,offset bmp
        mov ecx,400000h
        call LoadImage
mov hBit,rax

       
mov ecx,offset NameConsole
call SetConsoleTitle ;definition of a title bar

        mov qword ptr [rsp+20h],TIME_PERIODIC
        xor r9d,r9d
mov r8d,offset TIME
xor edx,edx
mov ecx,100
call timeSetEvent
mov IDTimer,rax
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea edx,MOUSE_KEY
cmp [rdx+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rdx+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rdx+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b

mov rcx,BlackBrush
call DeleteObject ;delete a black brush
mov rcx,hBit
call DeleteObject ;delete drawing

mov rdx,hDC
mov rcx,hWnd
call ReleaseDC ;free hDC
mov rcx,IDTimer
call timeKillEvent
call FreeConsole ;close console
xor ecx,ecx
call ExitProcess

WinMain endp
TIME proc
local memDC:qword
local result:qword

        push rbp
mov ebp,esp
sub esp,(2*8+48h+15)and(-16)
        xor edx,edx ;Y=0 X=0
        mov rcx,hOut
        call SetConsoleCursorPosition
mov qword ptr [rsp+20h],0
lea r9d,result                  ;quantity of the removed symbols
        mov r8d,sizeof STR1
mov edx,offset STR1
mov rcx,hOut
call WriteConsole ;output of a line of symbols to the screen
@@: mov rcx,hDC
call CreateCompatibleDC ;create compatible DC
mov memDC,rax
mov rdx,hBit
mov rcx,rax
call SelectObject
mov eax,Y
add eax,const1+1
mov qword ptr [rsp+20h],rax
        mov r9d,X
add r9d,const1+1
mov r8d,Y
dec r8d
mov edx,X
dec edx
mov rcx,hDC ;remove a black circle to erase the previous image
call Ellipse
cmp X,640-const1 ;check that the planet is in console limits
jna @f ;otherwise change the direction of the movement
        neg deltaX
@@: cmp Y,300-const1
jna @f
        neg deltaY
@@: mov eax,deltaX
add X,eax  ;change planet coordinates
mov eax,deltaY
add Y,eax
        mov qword ptr [rsp+40h],SRCCOPY ;dwRaster
mov qword ptr [rsp+38h],0    ;SourceY
        mov qword ptr [rsp+30h],0    ;SourceX
mov rax,memDC  ;hSource
        mov [rsp+28h],rax
mov r9d,const1    ;Width
mov [rsp+20h],r9 ;const1=height
mov r8d,Y
mov edx,X
mov rcx,hDC    ;hDest
call BitBlt ;display the image
mov rcx,memDC
call DeleteDC ;release the DC memories
leave
retn
TIME endp
.data
bmp db 'Images/Earth.bmp',0
ClassConsole db 'ConsoleWindowClass',0
STR1 db 'For exit from program press ESC or CTRL+C or CTRL+Break'
NameConsole db 'Console application animation',0
hOut dq ?
hWnd dq ?
hDC dq ?
BlackBrush dq ?
hBit dq ?
deltaX dd 10
deltaY dd 2
X         dd 0
Y dd 0
IDTimer dq ?
end

Mikl__

Burdensome silence... Is really examples don't work?

TWell

Problems with headers again: :(
Assembling: c12.asm
c12.asm(19) : error A2006:undefined symbol : INPUT_RECORD

Mikl__

#127
Hi, Tim!
There is kernel32.inc in tut38b.zip attached file. Structure INPUT_RECORD is same in win32 and win64.
The structures used in the 38th tutorial
COORD STRUCT
  x  WORD      ?
  y  WORD      ?
COORD ENDS

SMALL_RECT STRUCT
  Left      WORD      ?
  Top       WORD      ?
  Right     WORD      ?
  Bottom    WORD      ?
SMALL_RECT ENDS

CHARTYPE UNION
UnicodeChar    WORD ?
AsciiChar      db ?
CHARTYPE ENDS

CHAR_INFO STRUCT
  Char          CHARTYPE <>
  Attributes    WORD      ?
CHAR_INFO ENDS

CONSOLE_SCREEN_BUFFER_INFO STRUCT
  dwSize                COORD <>
  dwCursorPosition      COORD <>
  wAttributes           WORD      ?
  srWindow              SMALL_RECT <>
  dwMaximumWindowSize   COORD <>
CONSOLE_SCREEN_BUFFER_INFO ENDS

CONSOLE_CURSOR_INFO STRUCT
  dwSize    DWORD      ?
  bVisible  DWORD      ?
CONSOLE_CURSOR_INFO ENDS

MOUSE_EVENT_RECORD STRUCT
  dwMousePosition       COORD <>
  dwButtonState         DWORD      ?
  dwControlKeyState     DWORD      ?
  dwEventFlags          DWORD      ?
MOUSE_EVENT_RECORD ENDS

KEY_EVENT_RECORD STRUCT
  bKeyDown          DWORD ?
  wRepeatCount      WORD ?
  wVirtualKeyCode   WORD ?
  wVirtualScanCode  WORD ?
  UNION
    UnicodeChar     WORD ?
    AsciiChar       BYTE ?
  ENDS
  dwControlKeyState DWORD ?
KEY_EVENT_RECORD ENDS

MENU_EVENT_RECORD STRUCT
  dwCommandId  DWORD      ?
MENU_EVENT_RECORD ENDS

FOCUS_EVENT_RECORD STRUCT
  bSetFocus  DWORD      ?
FOCUS_EVENT_RECORD ENDS

WINDOW_BUFFER_SIZE_RECORD STRUCT
  dwSize  COORD <>
WINDOW_BUFFER_SIZE_RECORD ENDS

INPUT_RECORD STRUCT
  EventType             WORD ?
  two_byte_alignment    WORD ?
  UNION
    KeyEvent                KEY_EVENT_RECORD            <>
    MouseEvent              MOUSE_EVENT_RECORD          <>
    WindowBufferSizeEvent   WINDOW_BUFFER_SIZE_RECORD   <>
    MenuEvent               MENU_EVENT_RECORD           <>
    FocusEvent              FOCUS_EVENT_RECORD          <>
  ENDS
INPUT_RECORD ENDS

TouEnMasm


Those structures are described for Windows 10 and earlier in wincon.sdk.
http://masm32.com/board/index.php?topic=563.msg4563#msg4563
defaut alignment,8 or QWORD
Quote
Include winapifamily.SDK
;/*++ BUILD Version: 0002    // Increment this if a change has global effects
;Copyright (c) Microsoft Corporation. All rights reserved.
;Module Name:
;    wincon.h
;Abstract:
;    This module contains the public data structures, data types,
;    and procedures exported by the NT console subsystem.
;Created:
;    26-Oct-1990
;Revision History:
;--*/
IFNDEF _WINCON_
_WINCON_   equ   
;ECHO   once
IFDEF __cplusplus
ENDIF
IF  _MSC_VER GE 1200
;ECHO   warning(push)
;ECHO   warning(disable:4820) ; padding added after data member
ENDIF
IFNDEF NOGDI
Include wingdi.SDK
ENDIF
;ECHO   region Application Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP OR  WINAPI_PARTITION_SYSTEM)

COORD   STRUCT DEFALIGNMASM
   X WORD ?
   Y WORD ?
COORD      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)

SMALL_RECT   STRUCT DEFALIGNMASM
   Left WORD ?
   Top WORD ?
   Right WORD ?
   Bottom WORD ?
SMALL_RECT      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
;ECHO   region Application Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP OR  WINAPI_PARTITION_SYSTEM)

KEY_EVENT_RECORD   STRUCT DEFALIGNMASM
   bKeyDown DWORD ?
   wRepeatCount WORD ?
   wVirtualKeyCode WORD ?
   wVirtualScanCode WORD ?
   union   uChar
   UnicodeChar WORD ?
   AsciiChar BYTE ?
   ENDS
   dwControlKeyState DWORD ?
KEY_EVENT_RECORD      ENDS


;
; ControlKeyState flags
;
RIGHT_ALT_PRESSED   equ   < 00001h>
LEFT_ALT_PRESSED   equ   < 00002h>
RIGHT_CTRL_PRESSED   equ   < 00004h>
LEFT_CTRL_PRESSED   equ   < 00008h>
SHIFT_PRESSED   equ   < 00010h>
NUMLOCK_ON   equ   < 00020h>
SCROLLLOCK_ON   equ   < 00040h>
CAPSLOCK_ON   equ   < 00080h>
ENHANCED_KEY   equ   < 00100h>
NLS_DBCSCHAR   equ   < 000010000h>
NLS_ALPHANUMERIC   equ   < 000000000h>
NLS_KATAKANA   equ   < 000020000h>
NLS_HIRAGANA   equ   < 000040000h>
NLS_ROMAN   equ   < 000400000h>
NLS_IME_CONVERSION   equ   < 000800000h>
NLS_IME_DISABLE   equ   < 020000000h>

MOUSE_EVENT_RECORD   STRUCT DEFALIGNMASM
   dwMousePosition COORD <>
   dwButtonState DWORD ?
   dwControlKeyState DWORD ?
   dwEventFlags DWORD ?
MOUSE_EVENT_RECORD      ENDS


;
; ButtonState flags
;
FROM_LEFT_1ST_BUTTON_PRESSED   equ   < 00001h>
RIGHTMOST_BUTTON_PRESSED   equ   < 00002h>
FROM_LEFT_2ND_BUTTON_PRESSED   equ   < 00004h>
FROM_LEFT_3RD_BUTTON_PRESSED   equ   < 00008h>
FROM_LEFT_4TH_BUTTON_PRESSED   equ   < 00010h>
;
; EventFlags
;
MOUSE_MOVED   equ   < 00001h>
DOUBLE_CLICK   equ   < 00002h>
MOUSE_WHEELED   equ   < 00004h>
IF ( _WIN32_WINNT GE 00600h)
MOUSE_HWHEELED   equ   < 00008h>
ENDIF ;/* _WIN32_WINNT >= 0x0600 */

WINDOW_BUFFER_SIZE_RECORD   STRUCT DEFALIGNMASM
   dwSize COORD <>
WINDOW_BUFFER_SIZE_RECORD      ENDS



MENU_EVENT_RECORD   STRUCT DEFALIGNMASM
   dwCommandId DWORD ?
MENU_EVENT_RECORD      ENDS



FOCUS_EVENT_RECORD   STRUCT DEFALIGNMASM
   bSetFocus DWORD ?
FOCUS_EVENT_RECORD      ENDS



INPUT_RECORD   STRUCT DEFALIGNMASM
   EventType WORD ?
   union   Event
   KeyEvent KEY_EVENT_RECORD <>
   MouseEvent MOUSE_EVENT_RECORD <>
   WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <>
   MenuEvent MENU_EVENT_RECORD <>
   FocusEvent FOCUS_EVENT_RECORD <>
   ENDS
INPUT_RECORD      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
;
;  EventType flags:
;
KEY_EVENT   equ   < 00001h>
MOUSE_EVENT   equ   < 00002h>
WINDOW_BUFFER_SIZE_EVENT   equ   < 00004h>
MENU_EVENT   equ   < 00008h>
FOCUS_EVENT   equ   < 00010h>
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)

CHAR_INFO   STRUCT DEFALIGNMASM
   union   Char
   UnicodeChar WORD ?
   AsciiChar BYTE ?
   ENDS
   Attributes WORD ?
CHAR_INFO      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
;
; Attributes flags:
;
FOREGROUND_BLUE   equ   < 00001h>
FOREGROUND_GREEN   equ   < 00002h>
FOREGROUND_RED   equ   < 00004h>
FOREGROUND_INTENSITY   equ   < 00008h>
BACKGROUND_BLUE   equ   < 00010h>
BACKGROUND_GREEN   equ   < 00020h>
BACKGROUND_RED   equ   < 00040h>
BACKGROUND_INTENSITY   equ   < 00080h>
COMMON_LVB_LEADING_BYTE   equ   < 00100h>
COMMON_LVB_TRAILING_BYTE   equ   < 00200h>
COMMON_LVB_GRID_HORIZONTAL   equ   < 00400h>
COMMON_LVB_GRID_LVERTICAL   equ   < 00800h>
COMMON_LVB_GRID_RVERTICAL   equ   < 01000h>
COMMON_LVB_REVERSE_VIDEO   equ   < 04000h>
COMMON_LVB_UNDERSCORE   equ   < 08000h>
COMMON_LVB_SBCSDBCS   equ   < 00300h>
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)

CONSOLE_SCREEN_BUFFER_INFO   STRUCT DEFALIGNMASM
   dwSize COORD <>
   dwCursorPosition COORD <>
   wAttributes WORD ?
   srWindow SMALL_RECT <>
   dwMaximumWindowSize COORD <>
CONSOLE_SCREEN_BUFFER_INFO      ENDS



CONSOLE_SCREEN_BUFFER_INFOEX   STRUCT DEFALIGNMASM
   cbSize DWORD ?
   dwSize COORD <>
   dwCursorPosition COORD <>
   wAttributes WORD ?
   srWindow SMALL_RECT <>
   dwMaximumWindowSize COORD <>
   wPopupAttributes WORD ?
   bFullscreenSupported DWORD ?
   ColorTable COLORREF 16 dup (?)
CONSOLE_SCREEN_BUFFER_INFOEX      ENDS



CONSOLE_CURSOR_INFO   STRUCT DEFALIGNMASM
   dwSize DWORD ?
   bVisible DWORD ?
CONSOLE_CURSOR_INFO      ENDS



CONSOLE_FONT_INFO   STRUCT DEFALIGNMASM
   nFont DWORD ?
   dwFontSize COORD <>
CONSOLE_FONT_INFO      ENDS


IFNDEF NOGDI

CONSOLE_FONT_INFOEX   STRUCT DEFALIGNMASM
   cbSize DWORD ?
   nFont DWORD ?
   dwFontSize COORD <>
   FontFamily DWORD ?
   FontWeight DWORD ?
   FaceName WORD LF_FACESIZE dup (?)
CONSOLE_FONT_INFOEX      ENDS


ENDIF
HISTORY_NO_DUP_FLAG   equ   < 01h>

CONSOLE_HISTORY_INFO   STRUCT DEFALIGNMASM
   cbSize DWORD ?
   HistoryBufferSize DWORD ?
   NumberOfHistoryBuffers DWORD ?
   dwFlags DWORD ?
CONSOLE_HISTORY_INFO      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
IF ( _WIN32_WINNT GE 00500h)
;ECHO   region Desktop Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

CONSOLE_SELECTION_INFO   STRUCT DEFALIGNMASM
   dwFlags DWORD ?
   dwSelectionAnchor COORD <>
   srSelection SMALL_RECT <>
CONSOLE_SELECTION_INFO      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
;ECHO   endregion
;
; Selection flags
;
CONSOLE_NO_SELECTION   equ   < 00000h>
CONSOLE_SELECTION_IN_PROGRESS   equ   < 00001h>
CONSOLE_SELECTION_NOT_EMPTY   equ   < 00002h>
CONSOLE_MOUSE_SELECTION   equ   < 00004h>
CONSOLE_MOUSE_DOWN   equ   < 00008h>
ENDIF ;/* _WIN32_WINNT >= 0x0500 */
;ECHO   region Application Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP OR  WINAPI_PARTITION_SYSTEM)
;
; typedef for ctrl-c handler routines
;
ZPHANDLER_ROUTINE TYPEDEF PROTO CtrlType:DWORD

ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
CTRL_C_EVENT   equ   < 0>
CTRL_BREAK_EVENT   equ   < 1>
CTRL_CLOSE_EVENT   equ   < 2>
; 3 is reserved!
; 4 is reserved!
CTRL_LOGOFF_EVENT   equ   < 5>
CTRL_SHUTDOWN_EVENT   equ   < 6>
;
;  Input Mode flags:
;
ENABLE_PROCESSED_INPUT   equ   < 00001h>
ENABLE_LINE_INPUT   equ   < 00002h>
ENABLE_ECHO_INPUT   equ   < 00004h>
ENABLE_WINDOW_INPUT   equ   < 00008h>
ENABLE_MOUSE_INPUT   equ   < 00010h>
ENABLE_INSERT_MODE   equ   < 00020h>
ENABLE_QUICK_EDIT_MODE   equ   < 00040h>
ENABLE_EXTENDED_FLAGS   equ   < 00080h>
ENABLE_AUTO_POSITION   equ   < 00100h>
;
; Output Mode flags:
;
ENABLE_PROCESSED_OUTPUT   equ   < 00001h>
ENABLE_WRAP_AT_EOL_OUTPUT   equ   < 00002h>
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)
;
; direct API definitions.
;
;API
PeekConsoleInputW PROTO hConsoleInput:HANDLE ,lpBuffer:XMASM ,nLength:DWORD ,lpNumberOfEventsRead:XMASM
IFDEF UNICODE
PeekConsoleInput   equ   < PeekConsoleInputW>
ENDIF
;API
WriteConsoleInputA PROTO hConsoleInput:HANDLE ,lpBuffer:XMASM ,nLength:DWORD ,lpNumberOfEventsWritten:XMASM
;API
WriteConsoleInputW PROTO hConsoleInput:HANDLE ,lpBuffer:XMASM ,nLength:DWORD ,lpNumberOfEventsWritten:XMASM
IFDEF UNICODE
WriteConsoleInput   equ   < WriteConsoleInputW>
ELSE
WriteConsoleInput   equ   < WriteConsoleInputA>
ENDIF ; !UNICODE
;API
ReadConsoleOutputA PROTO hConsoleOutput:HANDLE ,lpBuffer:XMASM ,dwBufferSize:COORD ,dwBufferCoord:COORD ,lpReadRegion:XMASM
;API
ReadConsoleOutputW PROTO hConsoleOutput:HANDLE ,lpBuffer:XMASM ,dwBufferSize:COORD ,dwBufferCoord:COORD ,lpReadRegion:XMASM
IFDEF UNICODE
ReadConsoleOutput   equ   < ReadConsoleOutputW>
ELSE
ReadConsoleOutput   equ   < ReadConsoleOutputA>
ENDIF ; !UNICODE
;API
WriteConsoleOutputA PROTO hConsoleOutput:HANDLE ,lpBuffer:XMASM ,dwBufferSize:COORD ,dwBufferCoord:COORD ,lpWriteRegion:XMASM
;API
WriteConsoleOutputW PROTO hConsoleOutput:HANDLE ,lpBuffer:XMASM ,dwBufferSize:COORD ,dwBufferCoord:COORD ,lpWriteRegion:XMASM
IFDEF UNICODE
WriteConsoleOutput   equ   < WriteConsoleOutputW>
ELSE
WriteConsoleOutput   equ   < WriteConsoleOutputA>
ENDIF ; !UNICODE
;API
ReadConsoleOutputCharacterA PROTO hConsoleOutput:HANDLE ,lpCharacter:XMASM ,nLength:DWORD ,dwReadCoord:COORD ,lpNumberOfCharsRead:XMASM
;API
ReadConsoleOutputCharacterW PROTO hConsoleOutput:HANDLE ,lpCharacter:XMASM ,nLength:DWORD ,dwReadCoord:COORD ,lpNumberOfCharsRead:XMASM
IFDEF UNICODE
ReadConsoleOutputCharacter   equ   < ReadConsoleOutputCharacterW>
ELSE
ReadConsoleOutputCharacter   equ   < ReadConsoleOutputCharacterA>
ENDIF ; !UNICODE
;API
ReadConsoleOutputAttribute PROTO hConsoleOutput:HANDLE ,lpAttribute:XMASM ,nLength:DWORD ,dwReadCoord:COORD ,lpNumberOfAttrsRead:XMASM
;API
WriteConsoleOutputCharacterA PROTO hConsoleOutput:HANDLE ,lpCharacter:XMASM ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfCharsWritten:XMASM
;API
WriteConsoleOutputCharacterW PROTO hConsoleOutput:HANDLE ,lpCharacter:XMASM ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfCharsWritten:XMASM
IFDEF UNICODE
WriteConsoleOutputCharacter   equ   < WriteConsoleOutputCharacterW>
ELSE
WriteConsoleOutputCharacter   equ   < WriteConsoleOutputCharacterA>
ENDIF ; !UNICODE
;API
WriteConsoleOutputAttribute PROTO hConsoleOutput:HANDLE ,lpAttribute:XMASM ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfAttrsWritten:XMASM
;API
FillConsoleOutputCharacterA PROTO hConsoleOutput:HANDLE ,cCharacter:DWORD ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfCharsWritten:XMASM
;API
FillConsoleOutputCharacterW PROTO hConsoleOutput:HANDLE ,cCharacter:DWORD ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfCharsWritten:XMASM
IFDEF UNICODE
FillConsoleOutputCharacter   equ   < FillConsoleOutputCharacterW>
ELSE
FillConsoleOutputCharacter   equ   < FillConsoleOutputCharacterA>
ENDIF ; !UNICODE
;API
FillConsoleOutputAttribute PROTO hConsoleOutput:HANDLE ,wAttribute:DWORD ,nLength:DWORD ,dwWriteCoord:COORD ,lpNumberOfAttrsWritten:XMASM
CONSOLE_REAL_OUTPUT_HANDLE   equ   < LongToHandle( - 2)>
CONSOLE_REAL_INPUT_HANDLE   equ   < LongToHandle( - 3)>
;API
GetConsoleScreenBufferInfo PROTO hConsoleOutput:HANDLE ,lpConsoleScreenBufferInfo:XMASM
;API
GetConsoleScreenBufferInfoEx PROTO hConsoleOutput:HANDLE ,lpConsoleScreenBufferInfoEx:XMASM
;API
SetConsoleScreenBufferInfoEx PROTO hConsoleOutput:HANDLE ,lpConsoleScreenBufferInfoEx:XMASM
;API
GetLargestConsoleWindowSize PROTO hConsoleOutput:HANDLE
;API
GetConsoleCursorInfo PROTO hConsoleOutput:HANDLE ,lpConsoleCursorInfo:XMASM
ENDIF ; WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
;ECHO   endregion
;ECHO   region Desktop Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
IF ( _WIN32_WINNT GE 00500h)
;API
GetCurrentConsoleFont PROTO hConsoleOutput:HANDLE ,bMaximumWindow:DWORD ,lpConsoleCurrentFont:XMASM
IFNDEF NOGDI
;API
GetCurrentConsoleFontEx PROTO hConsoleOutput:HANDLE ,bMaximumWindow:DWORD ,lpConsoleCurrentFontEx:XMASM
;API
SetCurrentConsoleFontEx PROTO hConsoleOutput:HANDLE ,bMaximumWindow:DWORD ,lpConsoleCurrentFontEx:XMASM
ENDIF
;API
GetConsoleHistoryInfo PROTO lpConsoleHistoryInfo:XMASM
;API
SetConsoleHistoryInfo PROTO lpConsoleHistoryInfo:XMASM
;API
GetConsoleFontSize PROTO hConsoleOutput:HANDLE ,nFont:DWORD
;API
GetConsoleSelectionInfo PROTO lpConsoleSelectionInfo:XMASM
ENDIF ;/* _WIN32_WINNT >= 0x0500 */
;API
GetNumberOfConsoleMouseButtons PROTO lpNumberOfMouseButtons:XMASM
ENDIF ; WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
;ECHO   endregion
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)
;API
SetConsoleActiveScreenBuffer PROTO hConsoleOutput:HANDLE
;API
FlushConsoleInputBuffer PROTO hConsoleInput:HANDLE
;API
SetConsoleScreenBufferSize PROTO hConsoleOutput:HANDLE ,dwSize:COORD
;API
SetConsoleCursorPosition PROTO hConsoleOutput:HANDLE ,dwCursorPosition:COORD
;API
SetConsoleCursorInfo PROTO hConsoleOutput:HANDLE ,lpConsoleCursorInfo:XMASM
;API
ScrollConsoleScreenBufferA PROTO hConsoleOutput:HANDLE ,lpScrollRectangle:XMASM ,lpClipRectangle:XMASM ,dwDestinationOrigin:COORD ,lpFill:XMASM
;API
ScrollConsoleScreenBufferW PROTO hConsoleOutput:HANDLE ,lpScrollRectangle:XMASM ,lpClipRectangle:XMASM ,dwDestinationOrigin:COORD ,lpFill:XMASM
IFDEF UNICODE
ScrollConsoleScreenBuffer   equ   < ScrollConsoleScreenBufferW>
ELSE
ScrollConsoleScreenBuffer   equ   < ScrollConsoleScreenBufferA>
ENDIF ; !UNICODE
;API
SetConsoleWindowInfo PROTO hConsoleOutput:HANDLE ,bAbsolute:DWORD ,lpConsoleWindow:XMASM
;API
SetConsoleTextAttribute PROTO hConsoleOutput:HANDLE ,wAttributes:DWORD
;API
GenerateConsoleCtrlEvent PROTO dwCtrlEvent:DWORD ,dwProcessGroupId:DWORD
;API
FreeConsole PROTO 
IF ( _WIN32_WINNT GE 00500h)
;API
AttachConsole PROTO dwProcessId:DWORD
ATTACH_PARENT_PROCESS   equ   <  - 1>
ENDIF ;/* _WIN32_WINNT >= 0x0500 */
;API
GetConsoleTitleA PROTO lpConsoleTitle:XMASM ,nSize:DWORD
;API
GetConsoleTitleW PROTO lpConsoleTitle:XMASM ,nSize:DWORD
IFDEF UNICODE
GetConsoleTitle   equ   < GetConsoleTitleW>
ELSE
GetConsoleTitle   equ   < GetConsoleTitleA>
ENDIF ; !UNICODE
ENDIF ; WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
;ECHO   endregion
;ECHO   region Desktop Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
IF ( _WIN32_WINNT GE 00600h)
;API
GetConsoleOriginalTitleA PROTO lpConsoleTitle:XMASM ,nSize:DWORD
;API
GetConsoleOriginalTitleW PROTO lpConsoleTitle:XMASM ,nSize:DWORD
IFDEF UNICODE
GetConsoleOriginalTitle   equ   < GetConsoleOriginalTitleW>
ELSE
GetConsoleOriginalTitle   equ   < GetConsoleOriginalTitleA>
ENDIF ; !UNICODE
ENDIF ;/* _WIN32_WINNT >= 0x0600 */
ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
;ECHO   endregion
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)
;API
SetConsoleTitleA PROTO lpConsoleTitle:XMASM
;API
SetConsoleTitleW PROTO lpConsoleTitle:XMASM
IFDEF UNICODE
SetConsoleTitle   equ   < SetConsoleTitleW>
ELSE
SetConsoleTitle   equ   < SetConsoleTitleA>
ENDIF ; !UNICODE
ENDIF ; WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
;ECHO   endregion
;ECHO   region Application Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP OR  WINAPI_PARTITION_SYSTEM)

CONSOLE_READCONSOLE_CONTROL   STRUCT DEFALIGNMASM
   nLength DWORD ?
   nInitialChars DWORD ?
   dwCtrlWakeupMask DWORD ?
   dwControlKeyState DWORD ?
CONSOLE_READCONSOLE_CONTROL      ENDS


ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
;ECHO   endregion
CONSOLE_TEXTMODE_BUFFER   equ   < 1>
IFNDEF NOAPISET
Include consoleapi.SDK
ENDIF
;ECHO   region Desktop Family or OneCore Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP OR  WINAPI_PARTITION_SYSTEM)
;API
CreateConsoleScreenBuffer PROTO dwDesiredAccess:DWORD ,dwShareMode:DWORD ,lpSecurityAttributes:XMASM ,dwFlags:DWORD ,lpScreenBufferData:XMASM
;API
SetConsoleCP PROTO wCodePageID:DWORD
;API
SetConsoleOutputCP PROTO wCodePageID:DWORD
ENDIF ; WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
;ECHO   endregion
;ECHO   region Desktop Family
IF  WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
IF ( _WIN32_WINNT GE 00500h)
CONSOLE_FULLSCREEN   equ   < 1>
CONSOLE_FULLSCREEN_HARDWARE   equ   < 2>
;API
GetConsoleDisplayMode PROTO lpModeFlags:XMASM
CONSOLE_FULLSCREEN_MODE   equ   < 1>
CONSOLE_WINDOWED_MODE   equ   < 2>
;API
SetConsoleDisplayMode PROTO hConsoleOutput:HANDLE ,dwFlags:DWORD ,lpNewScreenBufferDimensions:XMASM
;API
GetConsoleWindow PROTO 
ENDIF ;/* _WIN32_WINNT >= 0x0500 */
IF ( _WIN32_WINNT GE 00501h)
;API
GetConsoleProcessList PROTO lpdwProcessList:XMASM ,dwProcessCount:DWORD
;
; Aliasing apis.
;
;API
AddConsoleAliasA PROTO Source:XMASM ,Target:XMASM ,ExeName:XMASM
;API
AddConsoleAliasW PROTO Source:XMASM ,Target:XMASM ,ExeName:XMASM
IFDEF UNICODE
AddConsoleAlias   equ   < AddConsoleAliasW>
ELSE
AddConsoleAlias   equ   < AddConsoleAliasA>
ENDIF ; !UNICODE
;API
GetConsoleAliasA PROTO Source:XMASM ,TargetBuffer:XMASM ,TargetBufferLength:DWORD ,ExeName:XMASM
;API
GetConsoleAliasW PROTO Source:XMASM ,TargetBuffer:XMASM ,TargetBufferLength:DWORD ,ExeName:XMASM
IFDEF UNICODE
GetConsoleAlias   equ   < GetConsoleAliasW>
ELSE
GetConsoleAlias   equ   < GetConsoleAliasA>
ENDIF ; !UNICODE
;API
GetConsoleAliasesLengthA PROTO ExeName:XMASM
;API
GetConsoleAliasesLengthW PROTO ExeName:XMASM
IFDEF UNICODE
GetConsoleAliasesLength   equ   < GetConsoleAliasesLengthW>
ELSE
GetConsoleAliasesLength   equ   < GetConsoleAliasesLengthA>
ENDIF ; !UNICODE
;API
GetConsoleAliasExesLengthA PROTO 
;API
GetConsoleAliasExesLengthW PROTO 
IFDEF UNICODE
GetConsoleAliasExesLength   equ   < GetConsoleAliasExesLengthW>
ELSE
GetConsoleAliasExesLength   equ   < GetConsoleAliasExesLengthA>
ENDIF ; !UNICODE
;API
GetConsoleAliasesA PROTO AliasBuffer:XMASM ,AliasBufferLength:DWORD ,ExeName:XMASM
;API
GetConsoleAliasesW PROTO AliasBuffer:XMASM ,AliasBufferLength:DWORD ,ExeName:XMASM
IFDEF UNICODE
GetConsoleAliases   equ   < GetConsoleAliasesW>
ELSE
GetConsoleAliases   equ   < GetConsoleAliasesA>
ENDIF ; !UNICODE
;API
GetConsoleAliasExesA PROTO ExeNameBuffer:XMASM ,ExeNameBufferLength:DWORD
;API
GetConsoleAliasExesW PROTO ExeNameBuffer:XMASM ,ExeNameBufferLength:DWORD
IFDEF UNICODE
GetConsoleAliasExes   equ   < GetConsoleAliasExesW>
ELSE
GetConsoleAliasExes   equ   < GetConsoleAliasExesA>
ENDIF ; !UNICODE
ENDIF ;/* _WIN32_WINNT >= 0x0501 */
ENDIF ;/* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
;ECHO   endregion
IF  _MSC_VER GE 1200
;ECHO   warning(pop)
ENDIF
IFDEF __cplusplus
ENDIF
ENDIF ; _WINCON_


;+ IF > endif  Décompte des if: 0

Fa is a musical note to play with CL

Mikl__


Mikl__

#130
Win x64 Tutorial #38g: Output to the console of text file contents. First variant.
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local result:qword
local FileSize:qword
local hMem:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(38h+6*8+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

        xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov rcx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov rcx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov ecx,eax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8+SMALL_RECT.Left],0
mov [r8+SMALL_RECT.Top],0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename    ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz  EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
mov rdx,rax
mov ecx,GMEM_FIXED or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
mov rdx,rax ;hMem
mov rcx,hFile
call ReadFile ;to read in the buffer
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
        mov rdx,hMem
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,hFile
call CloseHandle ;to close the file
mov rcx,hMem
call GlobalFree
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,result
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT:   call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Output to the console of text file contents. First variant.',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c08.asm'
end

Mikl__

Win x64 Tutorial #38i: Output to the console of text file contents. Second variant.
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /SECTION:.text,W ^
/BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local result:qword
local FileSize:qword
local hMem:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(38h+6*8+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

        xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filenameIn   ;file name
call CreateFile
        mov hIn,rax                 ; hConsoleInput
        mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filenameOut  ;file name
call CreateFile
        mov hOut,rax
        mov rcx,rax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov dword ptr [r8+SMALL_RECT],ebx
; lpConsoleWindow.Left = 0 lpConsoleWindow.Top = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov ecx,offset ConsoleTitle
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename    ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz  EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
mov rdx,rax
mov ecx,GMEM_FIXED or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
mov rdx,rax ;hMem
mov rcx,hFile
call ReadFile ;to read in the buffer
mov [rsp+20h],rbx
lea r9d,result
mov r8,FileSize
        mov rdx,hMem
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,hMem
call GlobalFree
mov rcx,hFile
call CloseHandle ;to close the file
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,result
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@:     lea r9d,result
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT:   call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
ConsoleTitle db 'Output to the console of text file contents. Second variant.',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c09.asm',0
filenameOut db 'CONOUT$',0
filenameIn db 'CONIN$',0
end

Mikl__

Win x64 Tutorial #38j
Memory Management, File I/O, GlobalAlloc/Lock/Unlock and GlobalFree
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local szReadWrite:qword
local FileSize:qword
local hMem:qword
local pMem:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(38h+7*8+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

        xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov ecx,STD_INPUT_HANDLE
call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
call GetStdHandle
        mov hOut,rax
        mov ecx,eax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8],ebx
; lpConsoleWindow.Left = 0 lpConsoleWindow.Top = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename    ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz  EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
mov rdx,rax
mov ecx,GMEM_MOVEABLE or GMEM_ZEROINIT
call GlobalAlloc
mov hMem,rax
        mov rcx,rax
call GlobalLock
mov pMem,rax
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8,FileSize
mov rdx,rax ;pMem
mov rcx,hFile
call ReadFile ;to read in the buffer
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8,FileSize
        mov rdx,pMem
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,hFile
call CloseHandle ;to close the file
        mov rcx,pMem
call GlobalUnlock
mov rcx,hMem
call GlobalFree
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@:     lea r9d,szReadWrite
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT:   call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Memory Management, File I/O, GlobalAlloc/Lock/Unlock and GlobalFree',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c16.asm',0
end
Memory Management, File I/O, GetProcessHeap, HeapAlloc and HeapFree
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
MEM_SIZE   = 65535
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local szReadWrite:qword
local FileSize:qword
local hHeap:qword
local pMem:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(38h+7*8+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

        xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov ecx,STD_INPUT_HANDLE
call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
call GetStdHandle
        mov hOut,rax
        mov ecx,eax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8],ebx
; lpConsoleWindow.Left = 0 lpConsoleWindow.Top = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename    ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz  EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
call GetProcessHeap
mov hHeap,rax
        mov r8d,MEM_SIZE
mov edx,HEAP_ZERO_MEMORY
mov rcx,rax
call HeapAlloc
mov pMem,rax
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8,FileSize
mov rdx,rax ;pMem
mov rcx,hFile
call ReadFile ;to read in the buffer
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8,FileSize
        mov rdx,pMem
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,hFile
call CloseHandle ;to close the file
        mov r8,pMem
        xor edx,edx
mov rcx,hHeap
call HeapFree
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@:     lea r9d,szReadWrite
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT:   call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Memory Management, File I/O, GetProcessHeap, HeapAlloc and HeapFree',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c17.asm',0
end
Memory Mapped File
asm-fileinclude win64a.inc
MAXSCREENX = 80
MAXSCREENY = 25
MEM_SIZE   = 65535
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local szReadWrite:qword
local FileSize:qword
local hMapping:qword
local pMapping:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD

        push rbp
mov ebp,esp
sub esp,(38h+7*8+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

        xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov ecx,STD_INPUT_HANDLE
call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
call GetStdHandle
        mov hOut,rax
        mov ecx,eax ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow ; lpConsoleWindow
mov [r8],ebx
; lpConsoleWindow.Left = 0 lpConsoleWindow.Top = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci          ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci          ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],ebx;FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+30h],rbx ;it has to be equal to zero
mov [rsp+28h],rbx ;attribute of the file (if we create it)
mov qword ptr [rsp+20h],OPEN_EXISTING;how to open the file
xor r8d,r8d ;mode of the general access
xor r9d,r9d ;the index on security attr
mov edx,GENERIC_READ or GENERIC_WRITE;access mode
mov ecx,offset filename    ;file name
call CreateFile ;to open the file
inc eax;cmp eax,-1
jz  EXIT
dec eax
mov hFile,rax
xor edx,edx ;0
mov rcx,rax ;hFile
call GetFileSize
mov FileSize,rax
;creation in memory of object "a file projection"
        mov [rsp+28h],rbx
        mov [rsp+20h],rbx
xor r9d,r9d
mov r8d,PAGE_READWRITE
xor edx,edx ;0
mov rcx,hFile
call CreateFileMapping
mov hMapping,rax
;display of a projection of the file to address space of process
        mov [rsp+20h],rbx
xor r9d,r9d
        xor r8d,r8d
mov edx,FILE_MAP_WRITE
mov rcx,rax
call MapViewOfFile
mov pMapping,rax
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8,FileSize
        mov rdx,rax ;pMapping
mov rcx,hOut
call WriteConsole ;to bring buffer contents to the console
mov rcx,pMapping
call UnmapViewOfFile
mov rcx,pMapping
call CloseHandle ;to close the file
        mov rcx,hMapping
call CloseHandle
;--------------------------------------------------------
mov [rsp+20h],rbx
lea r9d,szReadWrite
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
@@:     lea r9d,szReadWrite
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
EXIT:   call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp
Str1 db 'Memory Mapped File',0
Str2 db 0Dh,0Ah,'For exit press ESC or CTRL+C or CTRL+Break'
filename db 'c18.asm',0
end

Mikl__

#133
Win x64 Tutorial #38k: Binary clock
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 50
MAXSCREENY = 15
MAX_STACK  = 1000h
BLACK    = 0
BLUE    = 1
GREEN    = 2
CYAN    = 3
RED    = 4
PURPLE    = 5
YELLOW    = 6
SYSTEM    = 7
GREY    = 8
BRIGHTBLUE = 9
BRIGHTGREEN  = 10
BRIGHTCYAN = 11
BRIGHTRED  = 12
BRIGHTPURPLE = 13
BRIGHTYELLOW = 14
WHITE    = 15
LEFT    = 4
TOP    = 4
W    = 3
.code
WinMain proc
local hIn:qword
local szReadWrite:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD
local stm:SYSTEMTIME

        push rbp
mov ebp,esp
sub esp,(28h+2*8+sizeof INPUT_RECORD+\
        sizeof SMALL_RECT+sizeof CONSOLE_CURSOR_INFO+\
sizeof SYSTEMTIME+15)and(-16)

xor ebx,ebx
        call FreeConsole
        call AllocConsole
call GetProcessHeap
mov hHeap,rax
mov r8d,4*MAX_STACK ; dwBytes
mov edx,HEAP_ZERO_MEMORY; dwFlags
mov rcx,rax ; hHeap
call HeapAlloc
mov lpStack,rax

        mov ecx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov rcx,rax;hOut ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow        ; lpConsoleWindow
mov [r8],ebx
; ConsoleWindow.Left = 0 ConsoleWindow.Top  = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo

mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize;establish the new size of a window of the console

mov ecx,offset Str1
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci                 ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
lea edx,cci                 ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
mov [rsp+20h],rbx ;0
lea r9d,szReadWrite
mov r8d,sizeof Str2
mov edx,offset Str2
mov rcx,hOut
call WriteConsole ;to bring Str2 to the console
;--------------------------------------------------------
; Run until Esc is pressed
main_loop:mov ecx,10 ; dwMilliseconds
call Sleep
lea ecx,stm
call GetLocalTime
;Hour------------------------------------------
mov Y,TOP
mov X,LEFT+W+1
        test stm.wHour,10000y
jz @f
bts color,7
@@: call set
        test stm.wHour,1000y
jz @f
bts color,7
@@: call set
test stm.wHour,100y
jz @f
bts color,7
@@: call set
test stm.wHour,10y
jz @f
bts color,7
@@: call set
test stm.wHour,1
jz @f
bts color,7
@@: call set
;Minute-----------------------------------------
mov X,LEFT
add Y,W
test stm.wMinute,100000y
jz @f
bts color,7
@@: call set
test stm.wMinute,10000y
jz @f
bts color,7
@@:     call set
test stm.wMinute,1000y
jz @f
bts color,7
@@: call set
test stm.wMinute,100y
jz @f
bts color,7
@@: call set
test stm.wMinute,10y
jz @f
bts color,7
@@: call set
test stm.wMinute,1
jz @f
bts color,7
@@: call set
;Second-----------------------------------
        add Y,W
mov X,LEFT
test stm.wSecond,100000y
jz @f
bts color,7
@@: call set
test stm.wSecond,10000y
jz @f
bts color,7
@@: call set
test stm.wSecond,1000y
jz @f
bts color,7
@@: call set
test stm.wSecond,100y
jz @f
bts color,7
@@: call set
test stm.wSecond,10y
jz @f
bts color,7
@@: call set
test stm.wSecond,1y
jz @f
bts color,7
@@: call set
;--------------------------------------
        mov ecx,VK_ESCAPE ; vKey
call GetAsyncKeyState
; Determine whether a key is up or down
test eax, 8000h
jz main_loop
EXIT:   mov rcx,hOut ; hObject
call CloseHandle
mov rcx,hIn ; hObject
call CloseHandle
call FreeConsole
xor ecx,ecx
        call ExitProcess
WinMain endp

set proc
local Csbi:CONSOLE_SCREEN_BUFFER_INFO

push rbp
mov ebp,esp
sub esp,(20h+sizeof CONSOLE_SCREEN_BUFFER_INFO+15)and(-16)

lea edx, Csbi        ; lpConsoleScreenBufferInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleScreenBufferInfo

movzx edx, Csbi.wAttributes
mov ecx,edx
shr edx, 4
mov BGCOL, edx
and ecx, 0Fh
mov FGCOL, ecx
cmp color, -1
jle @f
mov edx, color
and edx, 0FFh
mov ecx, edx
shl edx, 4
or edx, ecx        ; wAttributes
mov rcx,hOut ; hConsoleOutput
call SetConsoleTextAttribute
@@: mov edx,Y
mov ecx,X
call draw
btr color, 7
add X,W+1
leave
retn
set endp
;-------------------------------------------------------
draw proc x:qword, y:qword

local Csbi:CONSOLE_SCREEN_BUFFER_INFO

push rbp
mov ebp,esp
sub esp,(28h+sizeof CONSOLE_SCREEN_BUFFER_INFO+15)and(-16)
mov x,rcx
mov y,rdx

lea edx,Csbi        ; lpConsoleScreenBufferInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleScreenBufferInfo

mov rdx,y
mov rcx,x
call save
mov rax, dwStackTop
mov rcx, lpStack
mov edi, [rcx+rax*4]
mov ecx,W*(W-1)

@@: mov ax, Csbi.wAttributes
shl eax,16
mov ax,20h
stosd
loop @b
mov rdx,y
mov rcx,x
call load
leave
retn
draw endp
;--------------------------------------------------
load proc x:qword, y:qword

local lpBuffer:qword
local lpWriteRegion:SMALL_RECT

push rbp
mov ebp,esp
sub esp,(30h+8+sizeof SMALL_RECT+15)and(-16)
mov x,rcx
mov y,rdx

mov dx,word ptr x
mov lpWriteRegion.Left, dx
add dx,W-1
mov lpWriteRegion.Right,dx ;cols+x-1
mov dx,word ptr y
mov lpWriteRegion.Top, dx
add dx,W-2
mov lpWriteRegion.Bottom,dx ;rows+y-1
mov rcx, dwStackTop
mov rax, lpStack
dec dwStackTop
mov edx,[rax+rcx*4]
mov [rax+rcx*4],ebx ;0
mov lpBuffer,rdx
lea ecx, lpWriteRegion
mov [rsp+20h],rcx ; lpWriteRegion
xor r9d,r9d ; dwBufferCoord = 0
mov r8d,(W-1)*10000h+W ; dwBufferSize
;mov edx ; lpBuffer
mov rcx,hOut ; hConsoleOutput
call WriteConsoleOutput
mov r8,lpBuffer ; lpMem
xor edx,edx ; dwFlags = 0
mov rcx,hHeap ; hHeap
call HeapFree
leave
retn
load endp
;-----------------------------------------------------------
save proc x:qword, y:qword

local lpBuffer:qword
local lpReadRegion:SMALL_RECT

push rbp
mov ebp,esp
sub esp,(28h+8+sizeof SMALL_RECT+15)and(-16)
mov x,rcx
mov y,rdx

mov dx,word ptr x
mov lpReadRegion.Left,dx
add dx,(W-1)
mov lpReadRegion.Right,dx
mov dx,word ptr y
mov lpReadRegion.Top,dx
add dx,(W-2)
mov lpReadRegion.Bottom,dx
mov r8d,4*W*(W-1)+260 ; dwBytes
mov edx,HEAP_ZERO_MEMORY; dwFlags
mov rcx,hHeap ; hHeap
call HeapAlloc
mov lpBuffer,rax
lea edx,lpReadRegion
mov [rsp+20h],rdx ; lpReadRegion
xor r9d,r9d ; dwBufferCoord = 0
mov r8d,(W-1)*10000h+W ; dwBufferSize
mov rdx,rax ; lpBuffer
mov rcx,hOut ; hConsoleOutput
call ReadConsoleOutput
inc dwStackTop
mov rax, lpStack
mov rcx, dwStackTop
mov rdx, lpBuffer
mov [rax+rcx*4],edx
@@: leave
retn
save endp
Str1 db 'Binary clock',0
Str2 db 'For exit press ESC or CTRL+C or CTRL+Break',13,10,10,10,\
5 dup(20h),'32  16  8   4   2   1',13,10,\
30 dup(20h),'Hours',13,10,10,10,30 dup(20h),'Minutes',13,10,10,10,30 \
dup(20h),'Seconds'
hOut dq ?
X dd ?
Y dd ?
BGCOL dd ?
FGCOL dd ?
color dd RED
dwStackTop dq -1
lpStack dq ?
hHeap dq ?
end

Mikl__

#134
Win x64 Tutorial #38l: Master Boot Record
The CreateFile function can open not only files, but also disk devices. For opening of the first disk of the computer is used the name "\\.\PhysicalDrive0", for opening of the logical section "C:" is used name "\\.\C:". After opening of the device it is possible to use the functions ReadFile and WriteFile, that is to read and write directly to clusters and sectors of a disk. The function DeviceIOControl allows to obtain static information on a disk or to execute formatting of a disk. The program allows to read the Master Boot Record of a disk. When opening the device "\\.\PhysicalDrive0" the Master Boot Record of a disk is in the beginning of the hypothetical file.
bat-filecls
set masm64_path=\masm64\
set filename=%1
del %filename%.exe
%masm64_path%bin\ml64 /Cp /c /I"%masm64_path%Include" %filename%.asm || exit
%masm64_path%bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"%masm64_path%Lib" ^
/entry:WinMain %filename%.obj /LARGEADDRESSAWARE:NO ^
/ALIGN:16 /BASE:0x400000 /STUB:%masm64_path%\bin\stubby.exe || exit
del %filename%.obj
asm-fileinclude win64a.inc
MAXSCREENX = 49
MAXSCREENY = 36
.code
WinMain proc
local hIn:qword
local hOut:qword
local hFile:qword
local szReadWrite:qword
local FileSize:qword
local ConsoleWindow:SMALL_RECT
local cci:CONSOLE_CURSOR_INFO
local MOUSE_KEY:INPUT_RECORD
local i:dword
local buffer1[512+3]:byte
local buffer2[3*512]:byte
local buffer3:qword

        push rbp
mov ebp,esp
sub esp,(38h+6*8+4+515+3*512+sizeof SMALL_RECT+\
        sizeof CONSOLE_CURSOR_INFO+INPUT_RECORD+15)and(-16)

xor ebx,ebx
        call FreeConsole
        call AllocConsole
        mov ecx,STD_INPUT_HANDLE
        call GetStdHandle
        mov hIn,rax
        mov ecx,STD_OUTPUT_HANDLE
        call GetStdHandle
        mov hOut,rax
        mov rcx,rax;hOut ; hConsoleOutput
call GetLargestConsoleWindowSize
; eax return in 31-16 bits: dwCoord.y
;               15-00 bits: dwCoord.x

        lea r8d,ConsoleWindow       ; lpConsoleWindow
mov [r8],ebx
; ConsoleWindow.Left = 0 ConsoleWindow.Top  = 0

sub ax, MAXSCREENX
sbb edx, edx
and ax, dx
add ax, MAXSCREENX-1
mov [r8+SMALL_RECT.Right],ax

shr eax, 16
sub eax, MAXSCREENY
sbb edx, edx
and eax, edx
add eax, MAXSCREENY-1
mov [r8+SMALL_RECT.Bottom],ax

mov edx,TRUE ; bAbsolute
mov rcx,hOut ; hConsoleOutput
call SetConsoleWindowInfo
                                       
mov edx,MAXSCREENY*10000h+MAXSCREENX;dwCoord
mov rcx,hOut ; hConsoleOutput
call SetConsoleScreenBufferSize;establish the new size of a window of the console

mov ecx,offset Str0
call SetConsoleTitle
;hide cursor----------------------------------------
lea edx,cci                 ; lpConsoleCursorInfo
mov rcx,hOut ; hConsoleOutput
call GetConsoleCursorInfo
        lea edx,cci                 ; lpConsoleCursorInfo
mov [rdx+CONSOLE_CURSOR_INFO.bVisible],FALSE
mov rcx,hOut ; hConsoleOutput
call SetConsoleCursorInfo
;------------------------------------------------------
;open physical drive
mov [rsp+30h],rbx ;it has to be equal 0
mov [rsp+28h],rbx ;attribute of the file (if create it)
mov qword ptr [rsp+20h],OPEN_EXISTING ;how to open
xor r9d,r9d;0 ;the pointer on security attr
mov r8d,FILE_SHARE_WRITE ;mode of the general access
mov edx,GENERIC_READ ;access mode
mov ecx,offset filename ;file name
call CreateFile ;open file
inc eax ;eax == INVALID_HANDLE_VALUE ?
jz EXIT
dec eax
mov hFile,rax
;alignment on limit of the double word
lea eax,buffer1
add eax,3
and eax,-4
mov buffer3,rax
;read from Partition Table
mov [rsp+20h],rbx ;0
lea r9d,szReadWrite
mov r8d,512
        mov rdx,rax ;pMem2
mov rcx,hFile
call ReadFile
;-------------------------------------------
lea edi,buffer2
mov esi,offset Str2
mov ecx,sizeof Str2
rep movsb

mov rsi,buffer3
mov FileSize,sizeof Str2
mov i,ebx
@@: lodsq
bswap rax
mov r9d,eax
mov [rsp+20h],r9
shr rax,32
        mov r9d,eax
lodsq
bswap rax
mov edx,eax
mov [rsp+30h],rdx
shr rax,32
mov [rsp+28h],rax
mov r8d,i
mov edx,offset fmt
mov rcx,rdi
call wsprintf
add edi,eax
add FileSize,rax
inc i
cmp i,512/16
jb @b
mov esi,offset Str1
mov ecx,sizeof Str1
rep movsb
        add FileSize,sizeof Str1
;to bring buffer contents to the console
mov [rsp+20h],rbx ;0
lea r9d,szReadWrite
mov r8,FileSize
lea edx,buffer2
mov rcx,hOut
call WriteConsole
;close handle and file----------------------
        mov rcx,hFile
call CloseHandle ; close file
mov rcx,hOut ; hObject
call CloseHandle     ; close file
;--------------------------------------------------------
@@:     lea r9d,szReadWrite
mov r8d,1
lea edx,MOUSE_KEY
mov rcx,hIn
call ReadConsoleInput
        lea eax,MOUSE_KEY
cmp [rax+INPUT_RECORD.EventType],MOUSE_EVENT
je @b
cmp [rax+INPUT_RECORD.EventType],KEY_EVENT
jne @b
cmp [rax+INPUT_RECORD.KeyEvent.wVirtualKeyCode],VK_ESCAPE
jne @b
;---------------------------------------------------------
EXIT:   mov rcx,hIn ; hObject
call CloseHandle
call FreeConsole
mov ecx,ecx
        call ExitProcess
WinMain endp
fmt db ' %.04X0 ',0BAh,' %.08X %.08X ',0B3h,' %.08X %.08X ',0BAh,0Dh,0Ah,0
Str0 db 'Master Boot Record',0
Str1 db 7 dup(20h),0C8h,19 dup (0CDh),0CFh,19 dup (0CDh),0BCh,13,10,\
'For exit press ESC or CTRL+C or CTRL+Break'
;имя устройства (первый диск)
filename db "\\.\PhysicalDrive0",0
Str2 db 10 dup(20h),'0 1 2 3  4 5 6 7    8 9 A B  C D E F',0Dh,0Ah,\
7 dup(20h),0C9h,19 dup (0CDh),0D1h,19 dup (0CDh),0BBh,0Dh,0Ah
end