The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Trope on September 17, 2005, 04:02:45 PM

Title: Can MASM open a SAFE? Ugh...
Post by: Trope on September 17, 2005, 04:02:45 PM
Ok I am trying to write my first "serious" program. A simple game.

The app has 5 buttons, and simply the user presses buttons trying to guess the safe's combnation.

Here is the logic I used in developing this:

(http://www.shopliquid.com/flow.jpg)

It should be pretty easy, huh? Well not for me.

Here is what I have so far....

My Include File:

uselib   user32
uselib   kernel32

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

IDC_BUTTON1001  equ 1001
IDC_BUTTON1002  equ 1002
IDC_BUTTON1003  equ 1003
IDC_BUTTON1004  equ 1004
IDC_BUTTON1005  equ 1005

.data?
hInstance      dd      ?   ;dd can be written as dword

.data
ComboBuffer      db 255 dup (0)


My ASM program:

.486
.model flat, stdcall
option casemap :none   ; case sensitive

include base.inc

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, 101, 0, ADDR DlgProc, 0
invoke ExitProcess, eax
; -----------------------------------------------------------------------
DlgProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

.if uMsg == WM_COMMAND
; -----------------------------------------------------------------------
; TODO
; -----------------------------------------------------------------------
        .if wParam == IDC_BUTTON1001
       
        push 31h ; Push "1"
        call SendToBuffer

.endif

.elseif uMsg == WM_CLOSE
invoke EndDialog,hWin,0
.endif

xor eax,eax
ret
DlgProc endp


SendToBuffer PROC uses esi edi pszNumber:BYTE

; Get the length of the buffer
invoke lstrlen,addr ComboBuffer

.if eax == 6

; Buffer has 6 characters, so
; call routine to check the combo
call TestCombo
Ret
.endif

; OK ADD TO BUFFER
lea ecx,ComboBuffer
add ecx,eax
mov [ecx],byte ptr pszNumber

invoke MessageBox,0 ,ADDR pszNumber,SADD("hi"),MB_OK
Ret

SendToBuffer endp



TestCombo PROC uses esi edi


; -----------------------------------------------------------------------
; CHECK SEE IF BUFFER HOLDS CORRECT COMBINATION NUMBER
; -----------------------------------------------------------------------

; DOES COMBO = 84621? IF NOT, BEEP AND CLEAR BUFFER
; IF IT DOES, DISPLAY MESSAGEBOX
; TO DO
invoke Beep,100,1000

ret
TestCombo endp


end start




I am getting an error when calling my SendToBuffer  function.

Can anyone help me out? It's frustrating! I think I am on the right track, but who knows.



Title: Re: Can MASM open a SAFE? Ugh...
Post by: AeroASM on September 17, 2005, 04:42:58 PM
Quote from: Trope on September 17, 2005, 04:02:45 PM
I am getting an error when calling my SendToBuffer function.

Did you mean you get an error when compiling your function?

Quote from: Trope on September 17, 2005, 04:02:45 PM
mov [ecx],byte ptr pszNumber

1. This is a mov mem,mem operation which is invalid; do it thorugh a register.
2. You don't need byte ptr because pszNumber is declared as :BYTE
Title: Re: Can MASM open a SAFE? Ugh...
Post by: Trope on September 17, 2005, 06:35:28 PM
yup that is where the problem is:

I have tried:

     push [pszNumber]
     pop  [ecx]

and still not compiling???
Title: Re: Can MASM open a SAFE? Ugh...
Post by: AeroASM on September 17, 2005, 06:59:19 PM
You cannot push a byte, only words and dwords.
Title: Re: Can MASM open a SAFE? Ugh...
Post by: petezl on September 18, 2005, 09:01:47 AM
In a real world there would be a set of numbers in a particular sequence to open the safe but as far as your program is concerned, you are really only testing for a correct button sequence. this would be much easier to accomplish if you used a dword as flag instead of a buffer.
If you are still stuck I'll post a sample!

Peter.
Title: Re: Can MASM open a SAFE? Ugh...
Post by: Trope on September 18, 2005, 01:12:08 PM
i would LOVE an example! I have been trying since yesterday....
Title: Re: Can MASM open a SAFE? Ugh...
Post by: MichaelW on September 18, 2005, 02:47:51 PM
How do you intend to enter the sequence 84621 using 5 buttons?

Title: Re: Can MASM open a SAFE? Ugh...
Post by: Trope on September 18, 2005, 02:51:25 PM
 :bg yeah good catch. typo.
Title: Re: Can MASM open a SAFE? Ugh...
Post by: petezl on September 18, 2005, 07:53:36 PM
This is just one of many ways!

Peter.

[attachment deleted by admin]
Title: Re: Can MASM open a SAFE? Ugh...
Post by: Trope on September 18, 2005, 08:48:36 PM
it is soooo good of you guys to do this, i mean post examples.

i was TRYING to do this. you should see MY source code.... aweful. Looking at yours.... again, it looks so simple.

Thanks alot , I appreciate this.