flat assembler
Message board for the users of flat assembler.

Index > Windows > What's the quickest way to pause a Windows console program?

Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2
I want a way to get a Windows console program to pause until the user presses
a key.

For example,in DOS you would do

mov ah,8
int $21

and then it would resume whenever you press a key.

I know you can use messagebox but I don't want an annoying box just for a pause.

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 27 Jan 2007, 08:31
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Here is my source that uses a messagebox to pause.
I hope there's a better way.

Code:
format pe console
include 'win32ax.inc'
start:

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [h0],eax

mov [b+$20],$D
mov [b+$21],$A

mov [v],0
p0:

mov eax,[v]
mov ebx,$20
p1:

dec ebx
mov [b+ebx],$30
shr eax,1
adc [b+ebx],0
cmp ebx,0
jne p1

invoke  WriteConsole,[h0],b,$22,r0,0

invoke  MessageBox,HWND_DESKTOP,"press a key to see the next number","pause",MB_OK

inc [v]

cmp [v],0
jne p0

invoke  ExitProcess,0

.end start

b rb $22
v rd 1
h0 rd 1
r0 rd 1

    
Post 27 Jan 2007, 08:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
1. be sure you have nothing in read buffer
2. SetConsoleMode - disable ENABLE_LINE_INPUT and ENABLE_ECHO_INPUT flag.
3. read 1 byte from console
Post 27 Jan 2007, 08:40
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Here's the function I use, you should have crtdll.dll in your dll imports.
Code:
proc WaitKey
     cinvoke printf, <10,13,"[Press ESC or SPACE to continue]",10,13>

     .repeat
             invoke  Sleep, 10
             invoke  GetAsyncKeyState, VK_ESCAPE
             push    eax
             invoke  GetAsyncKeyState, VK_SPACE
             pop     ecx
             or      eax, ecx
             and     eax, $8000
     .until  eax <> NULL
     return
endp    

[EDIT] You also need to use the include 'WIN32AXP.INC' or 'WIN32WXP.INC'
Post 27 Jan 2007, 22:03
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:08; edited 1 time in total
Post 28 Jan 2007, 02:11
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Quote:

1. be sure you have nothing in read buffer
2. SetConsoleMode - disable ENABLE_LINE_INPUT and ENABLE_ECHO_INPUT flag.
3. read 1 byte from console


How do I do read 1 byte? I'll have to look into this stuff.

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 28 Jan 2007, 23:44
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
How do I do read 1 byte? I'll have to look into this stuff.
ReadFile or ReadConsole... both would work.
Post 28 Jan 2007, 23:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
but I had to reserve more data as a buffer to hold the bytes read and
the number of bytes read.

So is it true that messagebox is the only way to pause using only 1 line of code?

I tried the Sleep call but it always needs a time interval.

I don't want to include any more files. Having to include win32ax.inc
was bad enough. I already have the program in DOS that does everything
and it doesn't need any includes.

The reason I made the Windows version is because it's the perfect thing
to use cheatengine on and change the value while it's in RAM.

Just a fun thing I do.

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 29 Jan 2007, 00:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
So is it true that messagebox is the only way to pause using only 1 line of code?

you can't call mesagebox using one line of assembly code. Maybe one line of macro usage, but such line can do ANYTHING.

you need to reserve only one byte buffer to read one byte, and few bytes doesn't matter to anyone anyway
Post 29 Jan 2007, 01:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
Quote:
I don't want to include any more files. Having to include win32ax.inc
was bad enough. I already have the program in DOS that does everything
and it doesn't need any includes.

2, I think that trying to avoid include files is very foolish, especially with Windows programming. If you do that then your code will soon become an unreadable buggy mess, even to yourself after a period of time. By the way, Tomaz's win32ax file itself includes a bunch of other files. This approach simplifies the primary source code line length but permits many other files to be included. This is also a form of coding design, structure and organisation, together with procedures and macros, that are essential aspects of programming, assembly or otherwise. Even for small programs in my opinion. Wink

Chris
Post 29 Jan 2007, 05:23
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Quote:
you need to reserve only one byte buffer to read one byte, and few bytes doesn't matter to anyone anyway


It matters to me. That's enough.

And I know that 1 line of assembly code wouldn't pause it.

Also,I'm not against include files really,but I dislike the Windows API .

I have written plenty of DOS programs and I'm just very upset at
Windows EXEs as they aren't tiny like DOS COM files.

I only do Windows console programs if I have a special need for them.

Seriously,all I have ever used my assembly programs is to output integers
in binary. I have a routine that I wrote for DOS that outputs EAX!

Code:
putbineax:
pusha
mov di,biteax
mov cx,$20
converteax:
rol eax,1
push eax
and eax,1
or eax,$30
stosb
pop eax
loop converteax
mov ah,$9
mov dx,biteax
int $21
popa
ret
biteax db '????????????????????????????????',$0D,$0A,$24
    


When I "call putbineax" it does my routine to output all bits of EAX.
Extremely useful for my numerous binary counting programs!

When somebody makes a Windows EXE under 256 bytes(decimal) then
I'll be interested!

I only do my crazy DOS ASM for the speed.
I can actually use PHP if I want something easier.

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 04 Feb 2007, 05:10
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
I have written plenty of DOS programs and I'm just very upset at
Windows EXEs as they aren't tiny like DOS COM files.


Back to DOS ? Wink

Quote:
When somebody makes a Windows EXE under 256 bytes(decimal) then
I'll be interested!


Quote:
I don't want to include any more files. Having to include win32ax.inc
was bad enough.


http://board.flatassembler.net/topic.php?t=5616 (<<--1 KB)

Hint: reports on Vista size vary from cca 3 GB to 10 GB ... does it matter or not Laughing Laughing

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 04 Feb 2007, 07:39
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
2 wrote:

I only do my crazy DOS ASM for the speed.


Heh, 16bit code running in NTVDM with DOS interrupts emulated on the native windows API? Speed? *grin*
Post 04 Feb 2007, 22:34
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
2: also the size of you executable files doesn't matter at all in DOS, as long as it fits in memory ( <400KB always), and it doesn't execute any other apps. Then, all the remaining memory is used by your application, regardless of how big it is.

Even the size on disk is aligned to cluster size
Post 04 Feb 2007, 23:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
vid wrote:
Even the size on disk is aligned to cluster size


Hey, I agree, size ain't everything (for DOS, use aPACK or UPX or 624), but cluster size is less relevant if you use an executable archiver like ARK to combine all your little .COM utils.
Post 05 Feb 2007, 18:52
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.