News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

read from binary file

Started by moha1, April 12, 2014, 06:37:22 AM

Previous topic - Next topic

moha1

I've also tried to only read it once,outside the counter and it hasn't worked

dedndave

well - the value at offset 0 in your emu8086.io file is 0, if that tells you anything   :P
i have another emu8086.io file here that is 201 bytes in size, and has 0C2h in the first byte

in the .DATA section
dwFileCounter dd 1
the first time WM_TIMER is received, it will cause an initial file read because 1 will become 0

in the WM_TIMER code
    dec     dwFileCounter
    .if ZERO?
        mov     dwFileCounter,2000  ;with a 30 mS timer elapse, update once every minute
        call    GetFileByte
        .if !eax
            INVOKE  Beep,800,100    ;beep at 800 Hz for 100 mS if error reading file
        .endif
    .endif

dedndave

i updated the GetFileByte routine previously posted
these are the lines that changed
        sub     eax,INVALID_HANDLE_VALUE
        jz      Exit00

        add     eax,INVALID_HANDLE_VALUE
        mov     hFile,eax

jj2007

Wasteful, Dave :eusa_naughty:

if INVALID_HANDLE_VALUE eq -1
   inc eax
   jz Exit00   ; 4 bytes

   dec eax
  else
   sub eax, INVALID_HANDLE_VALUE
   jz Exit00   ; 8 bytes

   add eax, INVALID_HANDLE_VALUE
  endif

moha1

I've done all you have said and made all the necesary changes that you told me,but when we put the call proc ,my image dissapears:(.
It's the same problem.There are no errors but if i let the call getfilebyte there my image won't apear.I'm stuck:(
Here is my program with the updates.In also modifyed my emu 8086 file,and the number at the first port is 155 now.
I don't have any ideeas what the problem can be:(

MichaelW

In my test, using your files, the problem was not the calls to GetFileByte but an endless loop in your WM_TIMER handler. Try enabling the calls to GetFileByte and commenting out the "jne et". I suggest you clean up your logic and your code. Before you go to the trouble of using a debugger to find the problem, you could try linking your app as a console app and adding code to display whatever you need to see on the console. I prefer to use the printf macro for this, for example:

    CALL GetFileByte
    pushad
    printf("EAX:%d\n",eax)
    popad


    mov al,byte ptr Buffer
    pushad
    ; printf expects 32 or 64-bit integers:
    movzx eax, al
    printf("AL:%d\n",eax)
    popad

    add com,1
    pushad
    movzx eax, com
    printf("com:%d\n",eax)
    popad


EAX:1
AL:155
com:2



Well Microsoft, here's another nice mess you've gotten us into.

dedndave

also - you can speed up the GetFileByte process......

open the file in WM_CREATE code and store the handle
i like to use GetFileAttr to get the file size and verify the file exists - optional
if there is an error, MessageBox and exit with EAX = -1 to exit without creating the window

in the WM_TIMER code, SetFilePointer to 0 and use ReadFile to read 1 byte

in the WM_DESTROY handler, INVOKE CloseHandle,hFile

moha1

You were right,it worked because i used a while loop instead of comparing and jumping to et label.
The thing is that i don't understand why with jne doesn't work and with a while loop it worked?
I must mention that using both methods,the fan was doing exactly the same thing,but when the getfilebyte was called,with jne not commented my image was disapearing and when i used while loop,with the same code it worked.
I was only comparing com variable with al,a register in wich i put the buffer vaiable.I did this thing because cmp does not allow memory,memory,it can allow memory,registerso i've put it in al.
Then i was adding using FPU the number of times it was in Buffer,that was read from the file.
With the while loop i've done the same thing but i havn't used any jump,can you tell me why it happened like this?

THANKS

MichaelW

#23
To know what is happening in the loop you need some way to monitor the values of the loop variables. By displaying the values of AL and com inside the loop I can see that the loop is running 155 times each time the timer fires with the call to GetFileByte enabled, and 7 times with the call to GetFileByte disabled. On each loop the value in xmm3 is being doubled. If I change the code to add 1.0 to the value in xmm3 on each loop, instead of doubling it:

      add com,1
      ;addss xmm3,xmm3
      .data
          xxx REAL4 1.0
      .code
      addss xmm3,xxx


Then the fan displays OK with the call to GetFileByte enabled.
Well Microsoft, here's another nice mess you've gotten us into.

moha1

#24
It is OK because I have defined my buffer at the begginig being 7 but the thing in using cmp com,al and jmp makes my image to disappear,obviously it s an endless loop but the code is the same when I m doing it with while and works , I m just doing while com<al and then the code is the same and I don't understantand why because my cmp , jump is making the same thing that while loop does

KeepingRealBusy

Knowing nothing about the code, but just reading the descriptions of the problem you have (works if using while but not with cmp jxx), I can only assume that your cmp jmp code is interpreting the results incorrectly, i.e., you are making a signed comparison and jumping on an assumed  unsigned result, or  you are making an unsigned comparison and jumping on an assumed  signed result. Read the documentation about ja (jump if above - unsigned) and jg (jump if greater - signed).

Dave.

FORTRANS

Hi,

   As Dave says, you may have a wrong conditional jump.  Put
.XLIST before including the INCLUDE files.  And put a .LIST directive
after the include files, and generate a listing of both programs so
you can see what changes in teh generated code.  You can put
the .XLIST and .LIST just around the code in question, if you think
that is easier.

Regards,

Steve N.