Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Using all 8 bytes.

Author
Message
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 21st Mar 2010 03:12 Edited at: 21st Mar 2010 07:17
####EDIT####
Wow i feel REALLY stupid. I put 'Using all 8 bytes' in the title. Hahahaha!

Throughout these forums everyone (including me) has said that it is impossible to use the last byte in a dword because all variables are integers.

When used in dbc the value 0xFFFFFFFF comes out as -1, but the bits are all still set! So it can't be used for number operations, but anything you can still use it for. For instance alpha blending. the colores are still stored correctly. Try this code.



4278190080 is the value of the most significant bit of a dword so oring it will set the msb to 1. The hex prints FFFFFFFF which shows the bits are still set correctly.

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 23rd Mar 2010 21:23 Edited at: 29th Mar 2010 17:31
Quote: "Throughout these forums everyone (including me) has said that it is impossible to use the last byte in a dword because all variables are integers.
"

I don't know if that's what everybody has been saying, I think it's more along the lines of integers being signed and therefore the last bit of the last byte controls negative or positive. The integers in DBC are still 32 bit which means they use 4 bytes. Because a DWORD implies an unsigned integer, DBC only recognizes a signed integer and therefore converts the value to negative when bit 31 is set. In the case of a DWORD in a memblock, one can't directly write a 4 byte DWORD to a memblock if the last bit is on. That will make the number negative and DBC will only treat a DWORD as positive. However, you can write 4 bytes 1 at a time to a memblock and therefore set the last bit indirectly.

Quote: "When used in dbc the value 0xFFFFFFFF comes out as -1, but the bits are all still set! So it can't be used for number operations, but anything you can still use it for. For instance alpha blending. the colores are still stored correctly. Try this code."

While the value of the alpha byte can be queried, it doesn't effect the transparency of images in DBC. You can load in an image with an alpha value but the image will still be solid.

Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 26th Mar 2010 05:20
Oh ok. That wasn't the impression i got from people. Once again, i have been proven wrong

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Mar 2010 05:35 Edited at: 29th Mar 2010 19:53
I wouldn't say you are wrong. I think that maybe many explanations might not be clear. I know mine are pretty clunky sometimes! I think you have some great ideas and have unlocked some pretty intersting stuff in DBC like the whole thing with string pointers and such.

In regards to the alpha channel, since you've proven that it can be set, that means an image or a bitmap can be saved with the alpha channel in tact.



Enjoy your day.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Mar 2010 16:28
Quote: "In the case of a DWORD in a memblock, one can't directly write a 4 byte DWORD to a memblock. However, you can write 4 bytes 1 at a time."


Have you tested that you can't?
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Mar 2010 17:18 Edited at: 29th Mar 2010 17:29
Quote: "Quote: "In the case of a DWORD in a memblock, one can't directly write a 4 byte DWORD to a memblock. However, you can write 4 bytes 1 at a time."

Have you tested that you can't?"

Yes, but let me clarify, in the case of
Quote: "When used in dbc the value 0xFFFFFFFF comes out as -1, but the bits are all still set! So it can't be used for number operations, but anything you can still use it for"

you can't write a DWORD of 4 bytes to a memblock when bit 31 is set because the DBC expects the DWORD to be unsigned and DBC's integers are signed. If you keep the values up to (2^31)-1 then all 4 bytes can be written as a DWORD to the memblock.

ex:

will cause an error


will work fine without setting bit 31 (though it is 4 bytes long)

And if we want to do it indirectly, we can write 4 bytes of value 255 to the memblock which will set bit 31 and read back the full DWORD as -1

It's quirky that DBC will read back the DWORD with all bits set but it won't write it.

Sorry that I wasn't clear. I'll change it above so others aren't confused.

Enjoy your day.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Mar 2010 19:43
Ah I see. That's odd.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Apr 2010 05:04
@Caleb1994

This bit of code you wrote:



gave me an idea. Since writing a signed integer to a memblock is not really supported by DBC native commands, I've come up with a way instead of writing 4 separate bytes to a memblock 1 at a time, it can be broken up into a 3 byte dword and a byte - allowing any integer to be written to a memblock without too much overhead:



Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 7th Apr 2010 03:57
Looks great! Although I think it should be write_memblok_uint or uinteger or dword. Just saying integer would imply signed. Other then that it looks great!

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Apr 2010 08:33
It is signed. You can write signed integers to the memblock with the function.

Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Apr 2010 07:00
Whoops. I was on a ipod touch and didn't read your post correctly, plus i have been away from dbc for a while and forgot that dbc lacked SIGNED integer support not UNSIGNED for memblocks. lol Sorry for the misunderstanding

New Site! Check it out \/

Login to post a reply

Server time is: 2024-04-20 03:57:32
Your offset time is: 2024-04-20 03:57:32