News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Console Input-Output

Started by RuiLoureiro, March 18, 2005, 03:32:51 PM

Previous topic - Next topic

RuiLoureiro

Hi
     i posted part of this matter in my topic «Window API32 documentation». Here is the file i could not attach there ( it is the first time i attach one file ). I am trying.



[attachment deleted by admin]

pbrennick

RuiLoureiro,
In answer to your question:

Quote
Whats the difference between /SUBSYSTEM:WINDOWS and   /SUBSYSTEM:WINDOWSCE ?
Whats WINDOWSCE ?

Windows CE is a trimmed down version of Windows and is used as the OS for handheld computers.  Since the screen is not standard sized (as a desktop) there needed to be a special set of APIs to handle that.  There are other unique features but we do not need to get into them here.  This is just to answer your question.

Paul

RuiLoureiro

Hi Paul

   Thank you for your reply about the subsystem «windowsCE».

Thank you, indeed.
Rui Loureiro

RuiLoureiro

Hey
   
1.   I want to share my new file cons19.zip, which is a more recent version of cons18.zip.
      In this version we can write and use backspace, left, right key and we can see that KeyDown
      field is the high word.

2.   I modified some instructions and now the INPUT_RECORD structure seems to be:

INPUT_RECORD    STRUCT                         
  EventType         WORD  ?     ; +0       = KEY_EVENT  => key is the case       
                          WORD  ?     ; +2       ????
  KeyDown           WORD  ?     ; +4          pressed = TRUE=1 ; released =FALSE=0
  RepeatCount      WORD  ?     ; +6                   
  VirtualKeyCode    WORD  ?    ; +8
  VirtualScanCode  WORD  ?     ;+10
  CharCode           WORD  ?     ;+12          ????
  AsciiCode           WORD  ?     ;+14          = AsciiCode = low byte
  ControlKeyState  WORD  ?     ;+16          = ControlState
INPUT_RECORD      ENDS         ;+18 bytes    imply each InputRecord = 18 bytes

3.   In conclusion, two questions: Is the documentation correct ? Or are the DLL files correct ?
      What's up ?

4.   All comments are welcome.
     My comments are: How can we program without correct documentation ?
                                How can we program without your help about correct documentation ?
                                ( All of us and all of those things should be correct )
Stay well
My best regards
RuiLoureiro


[attachment deleted by admin]

Mark Jones

Hi RuiLoureiro. :)

By "documentation," are you referring to WIN32.HLP? If so, consider that WIN32.HLP is technically a "C" reference, so there may be some differences (especially in semantics) when using it for MASM programming. Also, I've seen at least four or five differerent versions of WIN32.HLP... the newest being dated 1997/03/14.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Xor Stance

I would have to say the same thing. But because none had time to do a great documentation, I was trying to build one from what I learn.
I see that the TD tutorials are kind like helpful and Iczelion it's the outstanding. Since you already know asm from 8086/80286, you can even
a low-level in 32-bits since it's extended you add a E but I don't know about the extended segments, but it's not like your old days.

Movsd.com > Masmforum webte > Files > TD (Test Department tutorials).

http://webster.cs.ucr.edu/Page_TechDocs/ Officialy Doc by Microsoft but only uses Invoke statements and other things but not the Win32API as
Hutch, Iczelion and others did the job.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmasm/html/vcoriMicrosoftAssemblerMacroLanguage.asp

Here's a library but even though only explains Masm features by default by MS not by the Masm32 package.

.386, .486, .586, .686

Depend on the CPU you might have, check out your
vendor hardware. Or if you want something run at
a decent speed. NOTE: if your hardware doesn't
support it means that you had exceeded the speed
off it, and you need lower it.

Syntax:

.386, .486 , .586 , etc.

include

Use to include the masm INCLUDES and LIBRARIES.


Abbreviation:

.inc : include
.lib : library

Definition:

inc : in an include file, you will always find
a library for a specific syntax and a proper
instruction depending on the program structure,
you're going to build up.

library : contains the complete function of the
include files.


Syntax:

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib


Here's a piece of my doc I was trying to build since Ms hasn't updated to .586, .686, .786 and other. Unless I haven't check in depth 6.15 link
I gave but, there's no programming guide. I can't see Masm without a good doc I decided to build one myself but I had done another thing instead of it, but I will continue it. I plan of an Standard ver of Masm and another from the Masm32 API for 32-bits mostly and 16-bits I want to
implement a higher-level too new APIs as a future preject. HLA has the best documentation for asm in support  low-level 32-bits and high like
stdout, stdin, etc...

http://webster.cs.ucr.edu/

But I think it's still not enough though, I plan to make one even easier.

Luckily I got 2 interested friends who might help me and I'm going to make it a slow timing maybe even take years. Since Masm is evolving and gaining higher-level from Masm32, it will be a good idea to make it even higher.


MichaelW

Rui,

As far as I know the documentation is correct. The problem here is that the system expects the members of the INPUT_RECORD structure to be aligned as they would be by the Microsoft compilers, so your MASM version of the structure must duplicate this alignment.

MSDN: Windows Data Alignment on IPF, x86, and x86-64


; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; Under Windows 2000 and probably XP, to see the mouse events
; you must run the console full screen, or disable QuickEdit
; mode in the console window properties.
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm

    MOUSE_EVENT EQU 2

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .data

        hStdIn    dd 0
        nRead     dd 0

        INPUT_RECORD STRUCT
          EventType WORD ?
          WORD ?                  ; For alignment
          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
        InputRecord INPUT_RECORD <>

    .code

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetStdHandle,STD_INPUT_HANDLE
    mov   hStdIn,eax

    .WHILE InputRecord.KeyEvent.wVirtualKeyCode != VK_ESCAPE

        invoke ReadConsoleInput,hStdIn,ADDR InputRecord,1,ADDR nRead

        movzx  eax,InputRecord.EventType
        Switch eax

            Case KEY_EVENT

                print chr$("bKeyDown ")
                print uhex$(InputRecord.KeyEvent.bKeyDown)
                print chr$(13,10)

                print chr$("wRepeatCount ")
                movzx eax,InputRecord.KeyEvent.wRepeatCount
                print uhex$(eax)
                print chr$(13,10)

                print chr$("wVirtualKeyCode ")
                movzx eax,InputRecord.KeyEvent.wVirtualKeyCode
                print uhex$(eax)
                print chr$(13,10)

                print chr$("wVirtualScanCode ")
                movzx eax,InputRecord.KeyEvent.wVirtualScanCode
                print uhex$(eax)
                print chr$(13,10)

                print chr$("uChar ")
                movzx eax,InputRecord.KeyEvent.uChar
                print uhex$(eax)
                print chr$(13,10,13,10)

            Case MOUSE_EVENT

                print chr$("dwMousePosition.x ")
                movzx eax,InputRecord.MouseEvent.dwMousePosition.x
                print ustr$(eax)
                print chr$(13,10)
     
                print chr$("dwMousePosition.y ")
                movzx eax,InputRecord.MouseEvent.dwMousePosition.y
                print ustr$(eax)
                print chr$(13,10)
     
                print chr$("dwButtonState ")
                print uhex$(InputRecord.MouseEvent.dwButtonState)
                print chr$(13,10)
     
                print chr$("dwControlKeyState ")
                print uhex$(InputRecord.MouseEvent.dwControlKeyState)
                print chr$(13,10)
     
                print chr$("dwEventFlags ")
                print uhex$(InputRecord.MouseEvent.dwEventFlags)
                print chr$(13,10,13,10)

        EndSw
    .ENDW
    exit

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


eschew obfuscation

RuiLoureiro

Hi
   i´m sorry, but i changed from Internet Provider but it lasted for 5 days (18-22\4) !
   I am trying to change again.

Xor Stance, Mark:
                          sorry for this delay. Thank you for your reply.

MichaelW,
                How are you ? I am not sure about your answer. But may be. I have one example to put here but i cannot do with this IP. It is too slow. Thank you for your example. I go to see it.

stay well

AeroASM

Quote from: Xor Stance on April 23, 2005, 12:25:20 AM
I don't know about the extended segments
Because they don't exist  :bg

pbrennick

Rui,
When I assembled and tested cons19.asm, I noticed that all key events are echoed twice to the output console.  Is this on purpose?

Paul

RuiLoureiro

Hi
    pbrennic,
                  i dont know well at this moment. I go to see it better. I shall give you the answer in the next post. ok ? Thank you
.........................................................................................
Another question

1.  I have a table _T where i have an address of a procedure X;

2.  I want that a procedure Y calls the procedure X via table _T.

    How can i do this in MASM ? Is there another solution ?


.data
      _T    dd offset X    ; This is the address of the proc X
            dd ?
.code
;...................
      Y     proc
             mov    ebx, offset _T
             mov    eax, [ebx]

             «Now i want to call EAX = to call X». How ?

             ret
      Y     endp
;....................
      X     proc

            ret
      X     endp


my regards

pbrennick

RuiLoureiro,
Perhaps I am missing something?  I think you answerred your own question in the latest post...

Just do this:

        call    [eax]

hth:
Paul

RuiLoureiro

Hi

Paul,
   Hooo Paul, I think i tried it before but it didnt work in my XP !
   It gives the error A2023:instruction operand must have size. Now, after your answer, i tried :«call  dword ptr [eax]». The procedure is at address 40 1000 and eax=40 1000 but the call goes to 4110 B568 !!! [ Why ??? ]
Next, i tried :«call  dword ptr ds:[eax]». The same happened. Finaly i tried «call dword ptr [ebx - Z]» where ebx is the table address (address of _T )and Z is the relative position where i have the address of procedure X.
   The problem is solved: it works !!!

...............................................................
     About your previous observation, it was a problem related with Input_Record structure control. Now, it is solved. The idea was one key pressed one char printed only. Now, my editor is working correctly. I think.

     I am working on cons25 test example with keyboard, mouse, colour and reading and writing in any place of the screen buffer. It is going well. It is to gain some experience, to write some basic procedures (how to write and organise it better, etc. ) and to learn how the system functions work.

   Thank you, Paul.
..........................................

   Do you know some system procedure to clear the screen buffer in this case ?

Stay well

Nilrem

Not at home, doesn't
cls
work? It's in the macros of masm32 package.

MichaelW

To call EAX, you call EAX :green

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        offset_testproc dd OFFSET testproc
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    mov   ebx,OFFSET offset_testproc
    mov   eax,[ebx]
    call  eax

    mov   eax,input(13,10,"Press enter to exit...")
    exit

testproc proc
    print chr$("testproc")
    ret
testproc endp

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation