Author Topic: The console way...  (Read 375 times)

felipe

  • Member
  • ***
  • Posts: 340
  • assemble the unassembled.
The console way...
« on: June 07, 2017, 02:47:20 PM »
This is just a toy program, but i want to share it here so i can receive (if any get bother) any kind of feedback... :biggrin:
What i found funny is that the program will respond only to a carriage return (even ignores ctrl+c).
Sorry if i didn't commented the code, but it's too late here and i got to sleep now. But it's a toy program so of course, you don't need such thing  :biggrin:

Code: [Select]
.386
.model  flat,stdcall
option  casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib

.data?
hConsoleOutput  dd  ?
hConsoleInput   dd  ?
NumberOfCharsWritten  dd  ?
NumberOfCharsRead   dd  ?


.data
BufferOut    db  "Hello Masm32 sdk forum!",0dh,0ah
BufferIn    db  " "


.code
start:
    invoke  GetStdHandle,STD_OUTPUT_HANDLE
    mov     hConsoleOutput,eax
    invoke  WriteConsole,hConsoleOutput,offset BufferOut,sizeof BufferOut,offset NumberOfCharsWritten,NULL
    invoke  GetStdHandle,STD_INPUT_HANDLE
    mov     hConsoleInput,eax
    invoke  SetConsoleMode,hConsoleInput,ENABLE_LINE_INPUT
    invoke  ReadConsole,hConsoleInput,offset BufferIn,sizeof BufferIn,offset NumberOfCharsRead,NULL
    invoke  ExitProcess,0
    end     start
Felipe.

jj2007

  • Member
  • *****
  • Posts: 7627
  • Assembler is fun ;-)
    • MasmBasic
Re: The console way...
« Reply #1 on: June 07, 2017, 06:42:48 PM »
What i found funny is that the program will respond only to a carriage return (even ignores ctrl+c).

Why is that funny? You explicitly asked for it, see ENABLE_LINE_INPUT :P

P.S.: In contrast, C getchar() is really a misnomer:
Code: [Select]
#include <conio.h>
#pragma comment(linker, "/subsystem:console" )
int main(int argc, char* argv[]) {
  printf("Hit any char:");
  getchar(); // not 'any char' - it works with exactly one key...
}

felipe

  • Member
  • ***
  • Posts: 340
  • assemble the unassembled.
Re: The console way...
« Reply #2 on: June 07, 2017, 11:30:23 PM »
What i found funny is that the program will respond only to a carriage return (even ignores ctrl+c).

Why is that funny? You explicitly asked for it, see ENABLE_LINE_INPUT :P


I know that. I thought was fun because it reminds me an old DOS function that do the same, but makes a beep when you type a key that is not the carriage return key.  :biggrin:
Felipe.

felipe

  • Member
  • ***
  • Posts: 340
  • assemble the unassembled.
Re: The console way...
« Reply #3 on: June 07, 2017, 11:54:07 PM »
Btw, thanks for your reply JJ.  :icon14:
Felipe.