Byte Ptrs and ... stuff... I want to know. =]

BlitzMax Forums/BlitzMax Beginners Area/Byte Ptrs and ... stuff... I want to know. =]

Hotcakes(Posted 2004) [#1]
OK, I have an area of memory located at Somewhere:Byte Ptr which is, say, Ratherlong:Int bytes long ;] I seem to be able to fill out the memory at Somewhere by doing a lot of this:

Somewhere:+Rand(256)

I don't understand how it works, it just seems to work ;] But I can't be sure until I view the contents of this buffer and I have -no- idea how to do that. If someone could give me a little For loop that basically read each byte and printed it out or something that would be dandy, thanks =]

Oh and yes, I've read the docs, but my eyes glazed over half way thru =]


Bot Builder(Posted 2004) [#2]
I *think* its something like:

For i=0 to 256
 Print Somewhere[i]
Next


Assuming Somewhere is a pointer


ImaginaryHuman(Posted 2004) [#3]
That works? You access pointers as if they are arrays, with an index?

I would've suggested doing a simple loop to plot 1 pixel sequentially accross the screen for each byte, maybe in shades of gray or something depending on the byte content, but now I'm thinking I don't know how you can access memory. you used to be able to PeekByte() but now it seems this is intimately tied in with having to use banks. So maybe you should make your memory buffer a bank so that you can use that.


Hotcakes(Posted 2004) [#4]
I have been thinking of that, but I'd rather avoid it if I can. I'll try bot builders suggestion. =]

The main reason I want this is because I'm not sure how variables are being stored in the TSound.sample:Byte Ptr reference, or how they are being used by freeaudio... I have an 8 bit sample loaded in, but the original source was signed and I'm not sure the translation to unsigned I'm doing is right, or even if that's what freeaudio is expecting. So I'll probably get to a point where I figure out how to read this data back in, and then start up another thread asking what freeaudio is expecting with a SF_MONO8 sample =]


Bot Builder(Posted 2004) [#5]
Angel - Yep. It's pretty odd. Personally, I think that for pointers we should just have a "Ptr" type, and then access the value of the pointer with various commands, kinda like file reading. In some cases its rather convenient, but you dont have implicit casting of pointer types. If I wanted to read a float instead of a int from a memory location, I'd have to explicitly cast it to a different type, which is ridiculous.

Riot - Yeah,should be simply reading from MyBytePointer[0] through MyBytePointer[length-1].


Hotcakes(Posted 2004) [#6]
Well that seems easy enough. Thanks bot bot.