TGC Codebase Backup



Get a negative value from a WORD. by RonsWare

21st Apr 2012 10:39
Summary

The function below gets a' negative value like -512 from a WORD. This function is written thank's to the help of WLGfx. He is the best.



Description

I am working on a map editor voor WAD files.
These WAD are used bij DOOM1 , DOOM2 sort of games.
I do this to learn how ID software made it's WAD file directory structure.

I needed a way to get the correct value's of coord's from the WAD file.
The coord's are stored in 16 bits (2 bytes).

But the only variable that can work with negative numbers is a INTEGER.
Coord's can be 500 but also -500

This function convert a 16 bits value from a WORD to a correct 32 bits negative value.

This function is written thank's to the help of WLGfx.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Thanks to WLGfx this function is written.

global outint as integer

x1  = 0xfe00   ` -512     First x,y coord.
y1  = 0x0060   `   96
x2  = 0xffe0   `  -32     Second x,y coord.
y2  = 0x0060   `   96

print x1       ` Before.
print y1
print x2
print y2


MakeInt16( x1 )
x1 = outint

MakeInt16( y1 )
y1 = outint

MakeInt16( x2 )
x2 = outint

MakeInt16( y2 )
y2 = outint

print x1     ` After.
print y1
print x2
print y2


do
loop
end

function MakeInt16( inword as word )
if (inword and 0x8000)
    outint = inword or 0xffff0000
else
    outint=inword
endif
endfunction