#!/usr/bin/env python
# -*- coding: utf-8 -*-

# functions.py

# Copyright 2009 Diego Hansen Hahn (DiegoHH) <diegohh90@hotmail.com> 

# LaZyGBA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.

# LaZyGBA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with LaZyGBA. If not, see <http://www.gnu.org/licenses/>.

def WORD(str):
	high = (str >> 8) & 0xFF
	low = str & 0xFF
	return chr(low) + chr(high)

def DWORD(str):
	high = (long(str) >> 16) & 0x7FFF
	low = long(str) & 0xFFFF
	return WORD(low) + WORD(high)
	
def ToINT(str):
	int = 0
	for x in str:
		int = (int << 8) | ord(x)
	return int
	
def FromDWORD(int):
	return (FromWORD(int & 0xFFFF) | FromWORD(int >> 16)) & 0xFFFFFFFF

def FromWORD(int):	
	return ((int << 8) | (int >> 8)) & 0xFFFF	