flat assembler
Message board for the users of flat assembler.
Index
> Windows > Windows Console API Functions and Console Buffer |
Author |
|
Nyatta 01 May 2019, 13:04
Hello all,
I'm fairly new to assembly programming and have only dabbled here and there over the past 5-6 years. I understand the basic-basics, so please bear with me. That aside, I've been attempting to invoke console API functions the past few days with limited success - specifically SetConsoleWindowInfo and SetConsoleScreenBufferSize in an attempt to remove the scroll bar from the console window in order to display and repeatedly update a neat block of text. I'd also ran into unexpected behavior attempting to move the cursor with SetConsoleCursorPosition where I'd had to assign COORD as a quad value instead of the documented word value. The only way I'd been able to pass the value correctly has been as a hex quad whereas two decimals would be optimal. These are the pages I'd been using for reference: https://docs.microsoft.com/en-us/windows/console/setconsolewindowinfo https://docs.microsoft.com/en-us/windows/console/setconsolescreenbuffersize https://docs.microsoft.com/en-us/windows/console/setconsolecursorposition My code is as follows: Code: format PE64 GUI 5.0 include 'win64ax.inc' .code start: invoke AllocConsole invoke GetStdHandle, STD_OUTPUT_HANDLE ;Get Console Output Handle mov [console], EAX ;Store Handle invoke GetConsoleWindow, 0 ;Get Window Handle mov [window], EAX ;Store invoke WriteConsole, [console], buffer, 9600, 0 ;Write Stored Message to Output Buffer invoke SetConsoleCursorPosition, [console], 0 ;Set Cursor to Top to Scroll Up invoke SetConsoleCursorPosition, [console], 0x0028003C ;Center Cursor in Console invoke SetConsoleScreenBufferSize, [console], [scale] ;Adjust buffer size? invoke SetConsoleWindowInfo, [console], 1, scale ;Adjustment 2? invoke Sleep,-1 ;Remain Open .end start .data console dd 0 window dd 0 scale dd 0x00007D50 buffer db 9600 dup (" ") ;Placeholder Any suggestions or obvious errors? |
|||
01 May 2019, 13:04 |
|
Nyatta 01 May 2019, 20:42
Code: mov ax, [curposy] shl eax, 16 add ax, [curposx] invoke SetConsoleCursorPosition, [console], eax Awesome, thank you! A questions regarding that: is there any way to calculate the result of that algorithm upon compilation in order to bake it in as an immediate value and a stored value? Terminology/Vocabulary has been a killer for my Google queries. Something like: Code: x dw 40 y dw 60 xy dd y shl 16 + x Edit: I was under the impression that by defining two values side-by-side, say two word values, I could simply call the first value as a double to retrieve both. Upon compilation are the sections in my code block that attempt to access that data being set to only access a word as part of the opcode itself due to the value being defined as a word within my data section? Is there a way to define I am retrieving a double from a word stored in the data block? |
|||
01 May 2019, 20:42 |
|
Ali.Z 02 May 2019, 00:11
to simplify things, and an aim for a better readability use structures.
Code: .code ; ... mov [crd.x],28h mov [crd.y],3Ch invoke SetConsoleCursorPosition,[console],[crd] ; ... .data crd COORD define coord struct anywhere, like so: Code: struct COORD x dw ? y dw ? ends _________________ Asm For Wise Humans |
|||
02 May 2019, 00:11 |
|
Nyatta 03 May 2019, 20:44
Ah, that's great to know!
I'm employed that as follows: Code: format PE64 GUI 5.0 include 'win64ax.inc' .code start: invoke AllocConsole invoke GetStdHandle, STD_OUTPUT_HANDLE mov [console], EAX invoke GetConsoleWindow, 0 mov [window], EAX invoke WriteConsole, [console], buffer, 9600, 0 invoke SetConsoleCursorPosition, [console], 0 mov EAX, [curs] invoke SetConsoleCursorPosition, [console], EAX invoke Sleep,-1 .end start .data struct COORD y dw 3Ch x dw 28h ends curs COORD console dd 0 window dd 0 buffer db 9600 dup (" ") My next question, I read the structure above as defining two words, whereas before I defined a single word containing the data of the two doubles... What is the structure actually doing between defining it an moving it into a register? Assigning x and y as doubles results in only the x coordinate being entered when the coordinate is stored this way. |
|||
03 May 2019, 20:44 |
|
revolution 04 May 2019, 02:47
To make your COORD structure more flexible you can try this:
Code: struct COORD y dw ? x dw ? ends curs COORD 40, 60 curs2 COORD 30, 70 Code: curs rd 0 curs.y dw 60 curs.x dw 40 curs2 rd 0 curs2.y dw 70 curs2.x dw 30 Code: mov eax,[curs] invoke function, [curs2] mov bx,[curs2.y] |
|||
04 May 2019, 02:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.