Page 1 of 1

How to read memory ???????

Posted: Wed Jul 02, 2003 10:26 am
by Skipsy
Damn' !!!!!!!! :x I guess I need to upgrade my brain (too)

I am having problem trying to read memory content.
I have loaded a sprite, found the memory address where it is stored
(thks to Fred) but the data I read don't match with the file dump.

Can you see what's wrong with this :

Code: Select all

If LoadSprite(0, "sprites.bmp") = 0
  MessageRequester("Problème","sprites.bmp'",0)
  End
endif
SIZE = FileSize("sprites.bmp") 
;DisplaySprite( 0, 0,100)

StartDrawing( spriteoutput( 0 ) )

ADDRESS.l = DrawingBuffer()

OpenConsole()

for ITER.l = 0 to SIZE 
  DONNEE1.b  = peekb(ADDRESS + ITER )
  printn( hex( DONNEE1 ) )
  CallDebugger
Next
Thank you guys !

Posted: Wed Jul 02, 2003 11:43 am
by jack
the hex function treats numbers as signed numbers,
perhaps this will work

Code: Select all

If LoadSprite(0, "sprites.bmp") = 0 
  MessageRequester("Problème","sprites.bmp'",0) 
  End 
endif 
SIZE = FileSize("sprites.bmp") 
;DisplaySprite( 0, 0,100) 

StartDrawing( spriteoutput( 0 ) ) 

ADDRESS.l = DrawingBuffer() 

OpenConsole() 

for ITER.l = 0 to SIZE 
  DONNEE1.b  = peekb(ADDRESS + ITER ) 
  printn( hex( DONNEE1 )&$ff ) 
  CallDebugger 
Next 
notice that i only added "&$ff" to the print hex statement.
hope this helps.

Posted: Wed Jul 02, 2003 1:33 pm
by Skipsy
Hummmm... Same problem.

I did another test : The sprite I load is a 50x50 black image.
When I open the file with a Hexa editor I can see that it is filled with value
00 (except the BMP header of course).

The program displays data that don't exist in my file :? :?

Posted: Wed Jul 02, 2003 1:48 pm
by Fred
Sprite data isn't a rectangular area. You have to use the 'DrawingBufferPitch()' to see the length of a single pixel line. This is due because of memory alinment, to get maximum performance. Search for this word on the forum, it should have some example which show how manipulate sprite data

Posted: Wed Jul 02, 2003 2:08 pm
by Skipsy
Oh yes, I understand sprites data is not rectangular but I don't really
mind about his form and the length of the line in the buffer... as long as
all data are contiguous :?:

Tell me if I am wrong : I have the address where the sprite data is
stored, I guess I should be able to read all data from the begining to the
end (which is "begining + buffer-length") byte after byte.

Or do you mean data could be "splitted" ?

8O

Posted: Wed Jul 02, 2003 2:22 pm
by Fred
That's wrong. The sprite data is organized line by line:
d: data, which is the width of the sprite (and it depends of the PixelFormat)
x: boundary alinment

ddddddddddddddddddddxxxx
ddddddddddddddddddddxxxx
ddddddddddddddddddddxxxx

so to go from line 1 to line 2

*Buffer+DrawingBufferPitch()

You can't assume than the sprite width is exactly a line in video memory. It can be less, like shown above. This is why the DrawingBufferPitch() command is always needed.

Posted: Wed Jul 02, 2003 3:42 pm
by Skipsy
OK... Too complex for what I want to do :oops:
I just want to read the full BMP, crypt it and save it.

I gonna try with 'File' and 'Memory' instructions.

Thanks all,
:wink:

Posted: Wed Jul 02, 2003 4:05 pm
by LarsG
Why don't you try reading all the data from the file, and crypting that.. then save to a new file?!?! Just an idea though...

Posted: Wed Jul 02, 2003 4:29 pm
by Skipsy
I did it... (a LOT easier) and realized that it does match with I expect
to do.
To summarize : I am writing a game and spent as much time coding than
I spent creating sprites, images etc...
So I'd like to have this files not easy to chnge by anybody.

With that solution I finally have the un-crypted file on the disk. :?

I'd like now to be able to use LoadSprite() to load the crypted file and
un-crypt it in sprite memory.

I am afraid I am back to Fred suggestions :!: :!: