News:

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

I don't know as asking this. (IN LPT)

Started by IAO, April 14, 2006, 08:40:31 PM

Previous topic - Next topic

IAO

Hi to all. Remember my english is poor.
I don't know as asking this.  But I will attempt it.
This program is mine. This program is not a work of the school.
Please understand me.  Don't make my work.
If you know some example or guide, help me.( Some thing to help me.)
If it is a wrong post.  Gentlemen moderators, please close it.

-First:
In my program everything works well.
When I execute the program, this shows me the value written in the LPT.
But: 
For a new value, I should execute the program again. ( It is not good )
The program should make it automatic. (Shows the value written in the LPT.)
I imagine that I need something as this: Private Sub Timer1_Timer()  <---VB


.386
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive

include PortMon.inc

.code

start:
   invoke  LoadDLL,hLib         ;Load .Dll (Inpout32)
   invoke   GetModuleHandle,NULL
   mov   hInstance,eax
   invoke   InitCommonControls
   invoke   DialogBoxParam,hInstance,IDD_MAIN,NULL,addr DlgProc,NULL
   invoke  FreeLibrary,hLib   
   invoke   ExitProcess,0

;########################################################################

DlgProc   proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
   mov   eax,uMsg
   ;initialization here
   .if   eax==WM_INITDIALOG

      ;->This is to the Icono.   
      invoke LoadIcon,hInstance,200
        mov hIcon, eax
        invoke SendMessage,hWin,WM_SETICON,1,hIcon
      ;-<

      ;Put all Check Box Unchecked      (Parece que no hacen falta)       
      invoke CheckDlgButton,hWin,IDC_RBN1,BST_UNCHECKED
      invoke CheckDlgButton,hWin,IDC_RBN2,BST_UNCHECKED
      ;mov bValue1,0

      ;Esto es para el BitMap (.BMP) del Led gris.
      invoke BitmapFromResource,hInstance,IDR_JPG
      mov   hBmp,eax
      mov Carry,eax
      invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG2,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG3,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG4,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG5,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG6,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG7,STM_SETIMAGE,IMAGE_BITMAP,hBmp
      invoke SendDlgItemMessage,hWin,IDC_IMG8,STM_SETIMAGE,IMAGE_BITMAP,hBmp

      ;Para Encender los Led's Rojos de "Salida Puerto".
      invoke BitmapFromResource,hInstance,IDR_JPG1
      mov   hBmp1,eax


;########################################################################

         invoke P_In,1024    ;In from LPT Port.
         mov hProbe,eax

;=====================================================================
Entrada:
         .IF hProbe & 01h ;1 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 01h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif

         .IF hProbe & 02h ;2 Decimal
         invoke SendDlgItemMessage,hWin,IDC_IMG2,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 02h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG2,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif

         .IF hProbe & 04h ;4 Decimal
         invoke SendDlgItemMessage,hWin,IDC_IMG3,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 04h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG3,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif
   
         .IF hProbe & 08h ;8 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG4,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 08h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG4,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif

         .IF hProbe & 10h ;16 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG5,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 10h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG5,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif
         
         .IF hProbe & 20h ;32 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG6,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 20h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG6,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif
         
         .IF hProbe & 40h ;64 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG7,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 40h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG7,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif

         .IF hProbe & 80h ;128 Decimal
             invoke SendDlgItemMessage,hWin,IDC_IMG8,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
         .endif
         .IF hProbe & 80h && 0h
         invoke SendDlgItemMessage,hWin,IDC_IMG8,STM_SETIMAGE,IMAGE_BITMAP,hBmp
         .endif

;=======================================================================
   .elseif   eax==WM_COMMAND
      mov edx,wParam
      movzx eax,dx
      shr edx,16
      .if edx==BN_CLICKED
         .if eax==1
            mov eax,0
            invoke P_out1,1024,ecx
            ;Procedimiento para Inicializar Led y CheckBox.
            invoke ClearAll,hWin
            
         .elseif eax==IDCANCEL
            invoke   SendMessage,hWin,WM_CLOSE,NULL,NULL
         .endif
      .endif
   .elseif   eax==WM_CLOSE
      invoke   EndDialog,hWin,0
   .else
      mov   eax,FALSE
      ret
   .endif
   mov   eax,TRUE
   ret
DlgProc endp


To explain this is complex for me.   I hope you understand me.
Don't make me the code. Only guide me.  Allow me to break, my brain.
Throw me a banana shell, to break more my brain. One or Two banana shell, please don't abuse. :wink

In VB I made it last year.  In 3 days I made this program.
But I want to make it in MASM32.  In 2 weeks, I am not able to advance more.

VB Code:
Private Sub Timer1_Timer()
If Option2.Value = True Then

    Dim Bit(0 To 7)  As Integer
    Dim Ciclo As Integer
    Dim m As Integer

    m = Inp(&H378)

    If m > 127 Then Bit(7) = 0: m = m - 128 Else Bit(7) = 1 '0 'Invertido
    If m > 63 Then Bit(6) = 0: m = m - 64 Else Bit(6) = 1
    If m > 31 Then Bit(5) = 0: m = m - 32 Else Bit(5) = 1
    If m > 15 Then Bit(4) = 0: m = m - 16 Else Bit(4) = 1
    If m > 7 Then Bit(3) = 0: m = m - 8 Else Bit(3) = 1
    If m > 3 Then Bit(2) = 0: m = m - 4 Else Bit(2) = 1
    If m > 1 Then Bit(1) = 0: m = m - 2 Else Bit(1) = 1
    If m > 0 Then Bit(0) = 0: m = m - 1 Else Bit(0) = 1

        'Controla los Led's de estado.
        For Ciclo = 0 To 7
        If Bit(Ciclo) = 0 Then _
        Led(Ciclo).Picture = LoadPicture(App.Path + "\LV.BMP") _
        Else Led(Ciclo).Picture = LoadPicture(App.Path + "\LG.BMP")
        Next Ciclo
       
End If
End Sub

;__________________________________________________________

Second:
Some person could write me with words this.  I need to make a comment.
.IF hProbe & 01h && 0h  <---------------This only.
invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp
.endif
I imagine something like that:  If the bit 1 of hProbe (is equal or has)  to 0. (I am not sure).


Thank you, for your patience.

Bye ('_').

"There is no way to peace. Peace is the way."    Mahatma Gandhi

MichaelW

Hi IAO,

I don't understand everything you are doing here, but I think I can answer your two questions.

For the second question, the statement:

.IF hProbe & 128 && 0

Will always return zero because && is a logical operator. For this code:

.IF hProbe & 128 && 0
  mov   hProbe, 1
.ENDIF

MASM produces this:

00401000 F7050430400080000000   test    dword ptr [403004h],80h
0040100A 740C                   jz      loc_00401018
0040100C EB0A                   jmp     loc_00401018
0040100E C7050430400001000000   mov     dword ptr [403004h],1
00401018                    loc_00401018:

As you can see, the mov  hProbe, 1 will never execute.

I think something like this will work OK:

.IF hProbe & 128
.ELSE
  mov   hProbe, 1
.ENDIF


00401018 F7050430400080000000   test    dword ptr [403004h],80h
00401022 7402                   jz      loc_00401026
00401024 EB0A                   jmp     loc_00401030
00401026                    loc_00401026:
00401026 C7050430400001000000   mov     dword ptr [403004h],1
00401030                    loc_00401030:


For the first question, you should be able to create a timer when you receive the WM_INITDIALOG message, and read the port value, update the display, etc, from the timer procedure.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    DlgProc   PROTO :DWORD,:DWORD,:DWORD,:DWORD
    TimerProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

    .data
        hInstance   dd 0
        hProbe      dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .IF hProbe & 128 && 0
      mov   hProbe, 1
    .ENDIF

    .IF hProbe & 128
    .ELSE
      mov   hProbe, 1
    .ENDIF

    mov hInstance, rv(GetModuleHandle,NULL)
    call Main
    invoke ExitProcess, eax
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
Main proc
    Dialog "TEST","MS Sans Serif",8,WS_OVERLAPPEDWINDOW,1,5,5,80,60,1024
    DlgButton "OK",WS_TABSTOP or BS_DEFPUSHBUTTON,25,42,30,10,IDOK
    CallModalDialog hInstance,0,DlgProc,NULL
    ret
Main endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
    .IF uMsg == WM_INITDIALOG
      invoke SetTimer,hWin,1,1000,ADDR TimerProc
    .ELSEIF uMsg == WM_CLOSE
       invoke KillTimer,hWin,1
       invoke EndDialog, hWin, 0
    .ENDIF
    return 0
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
TimerProc proc hwnd:DWORD,uMsg:DWORD,idEvent:DWORD,dwTime:DWORD
    MsgBox 0,"timer","timer",0
    ret
TimerProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


MSDN: SetTimer


eschew obfuscation

IAO

#2
Hi to all. Remember my english is poor.

Hi , dear MichaelW.
You always say:  I don't understand everything you are doing here.
But I think that you know well. :clap:

The second question you did not understand it.
I proved with test, cmp, bt. But program worked with this:

.IF hProbe & 80h ;128 Decimal
invoke SendDlgItemMessage,hWin,IDC_IMG8,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
.endif
.IF hProbe & 80h && 0h
invoke SendDlgItemMessage,hWin,IDC_IMG8,STM_SETIMAGE,IMAGE_BITMAP,hBmp
.endif


Within the Timer procedure, did not work. But already I modified it.
.IF Val_In & 01h ;1 Decimal
invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp1
.ELSE
invoke SendDlgItemMessage,hWin,IDC_IMG1,STM_SETIMAGE,IMAGE_BITMAP,hBmp
.endif


With your aid it was easier. I took two hours in finalizing it.

I told myself. I should not exalt people.  They can be offended.
I lied me.  I swear you, I cannot control myself. I cann't do it,  I cannot control myself.
I will carve in marble your face.  And I will put it in the Mount Olympus.
So that you are near the gods: Zeus, Jupiter, Mars, Aphrodite, Athenea and others.
And your name will be written together with the other gods. In several languages.
Michael, Miguel, Mike, Miguelangelo, etc.

Very poetic.   :dance:
You are a magic magnificent magistrate. You are Asm++ Bible.    Thanks * millions.

Mr. Mark Jones:
Please, don't write its inventions here. Because I cannot stop the laugh.
---------------------------------------------------------------------------------------------------


Here I send program in .zip. Tested in Win98 and WinXP.
The program had a problem in Win2k and WinXP. It was corrected.

Thanks you, for your patience.


Bye ('_').

[attachment deleted by admin]
"There is no way to peace. Peace is the way."    Mahatma Gandhi