flat assembler
Message board for the users of flat assembler.

Index > Windows > help please

Author
Thread Post new topic Reply to topic
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
hi, im trying to create a console-like thing and this is all i hav so far:
Code:
include '%fasminc%/win32ax.inc'

.data

  inchar     DB ?
  numwritten DD ?
  numread    DD ?
  outhandle  DD ?
  inhandle   DD ?
  string1    DB "Welcome to a console!"
  string2    DB "console-"

.code

  start:
        invoke  AllocConsole
        invoke  GetStdHandle,STD_OUTPUT_HANDLE
        mov [outhandle],eax
        invoke  GetStdHandle,STD_INPUT_HANDLE
        mov [inhandle],eax
        invoke  WriteConsole,[outhandle],string1,24,numwritten,0
        invoke  WriteConsole,[outhandle],string2,8,numwritten,0
        invoke  ReadConsole,[inhandle],inchar,1,numread,0
        invoke  ExitProcess,0
.end start  
    


im a beginner though, and i learned this from a tutorial(more like an example) but i dont understand much of it, and i cant get the "console-" thing to move down a line. i could not find out how it knows that when u press the enter button to exit, i mean how it know that its the enter button, and i wanted to change that to like esc or somthin like that. i might just be being a uber-noob, but thanks if you can help!

/Dreamz
Post 10 Apr 2009, 12:27
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Try this:
Code:
string2    DB "console-",13,10
...
        invoke  WriteConsole,[outhandle],string2,10,numwritten,0    
Note the addition of "13" carriage-return and "10" line-feed.

When you read characters from the input buffer it is up to your code to test for whatever exit conditions you need.
Post 10 Apr 2009, 12:36
View user's profile Send private message Visit poster's website Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
thank you sooooooo much!
Post 10 Apr 2009, 12:40
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:52; edited 1 time in total
Post 10 Apr 2009, 12:48
View user's profile Send private message Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
kk, thanks
o and how do you exactly, say if press "b" then it closes, how would you do that?

thanks
Post 10 Apr 2009, 16:51
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:52; edited 1 time in total
Post 10 Apr 2009, 17:16
View user's profile Send private message Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
sry to bother you again but could you giv a short code example?
Post 10 Apr 2009, 21:53
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Code:
format PE console
entry start

include 'c:/program files/fasmw16738/include/win32ax.inc'

section '.data' data readable writeable

    g_prompt  db 'Input some characters, b <enter> to quit.',0x0D,0x0A
    g_prompt.length = $ - g_prompt
    g_written rd 1
    g_read    rd 1
    g_stdin   rd 1
    g_stdout  rd 1
    g_input   rb 1

section '.code' code readable executable

    start:
        invoke AllocConsole
        invoke GetStdHandle,STD_INPUT_HANDLE
        mov    [g_stdin],eax
        invoke GetStdHandle,STD_OUTPUT_HANDLE
        mov    [g_stdout],eax
        invoke WriteConsole,[g_stdout],g_prompt,g_prompt.length,g_written,NULL
    mloop:
        invoke ReadConsole,[g_stdin],g_input,1,g_read,NULL
        cmp    [g_input],'b'
        jne    mloop
    quit:
        invoke FreeConsole
        invoke ExitProcess,0x00

section '.idata' import data readable

    library kernel32,'kernel32.dll'

    include 'c:/program files/fasmw16738/include/api/kernel32.inc'
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.


Last edited by bitshifter on 10 Apr 2009, 23:36; edited 1 time in total
Post 10 Apr 2009, 22:49
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
asmcoder wrote:
when you press b, system send WM_KEYDOWN to application window on wich u have focus.
When window recive this msg, it can do whatever it want.

This is true for a normal windows app with a message pump and handling procedure, but with console app windows hides this from us.
So Dreamz, you can ignore this, since it does not apply to your app.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 10 Apr 2009, 22:55
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Code:
.data
    hIn                dd  ?
    EventCount         dd  ?
    NumRead            dd  ?
    EventBuffer        db  16 dup 0

.code
main:
    invoke GetStdHandle, STD_INPUT_HANDLE
    ; error?
    mov [hIn], eax
@@:
    invoke Sleep, 1
    invoke GetNumberOfConsoleInputEvents, [hIn], EventCount
    test eax, eax
    je @B
    invoke ReadConsoleInput, [hIn], EventBuffer, 1, NumRead
    ; error?
    cmp word [EventBuffer], 1      ; is a keyboard event ?
    jne @B
    cmp byte [EventBuffer+4], 1    ; is a keypress ?
    jne @B

    ; [EventBuffer+14] = ASCII character or zero (no ASCII key pressed)
    ; [EventBuffer+12] = control keys

    


You can find small examples about console event handling here Dreamz, in C language but helpful.
Post 11 Apr 2009, 00:40
View user's profile Send private message Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
thanks!
Post 11 Apr 2009, 12:54
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
Dreamz



Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
sry for dble post, but thanks soo much again, this forum is soooo helpful and welcoming, so much better than all the others i hav visited
Post 11 Apr 2009, 15:20
View user's profile Send private message Send e-mail 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. Also on YouTube, Twitter.

Website powered by rwasa.