/*
Copyright (C) 2006 Evan Teran
                   eteran@alum.rit.edu

This program 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, or
(at your option) any later version.

This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "State.h"
#include <QString>

//------------------------------------------------------------------------------
// Name: State()
// Desc: constructor
//------------------------------------------------------------------------------
State::State() : ebx(0), ecx(0), edx(0), esi(0), edi(0), ebp(0), eax(0), esp(0),
		_cs(0), _ds(0), _es(0), _fs(0), _gs(0), _ss(0), eip(0), eflags(0), 
		orig_eax(0) {
}

//------------------------------------------------------------------------------
// Name: value(const QString &reg)
// Desc: a function to return the value of a register based on it's name
//------------------------------------------------------------------------------
BaseTypes::reg_t State::value(const QString &reg) const {
	BaseTypes::reg_t ret = 0;

	if(reg == "eax") { ret = eax; }
	else if(reg == "ebx") { ret = ebx; }
	else if(reg == "ecx") { ret = ecx; }
	else if(reg == "edx") { ret = edx; }
	else if(reg == "ebp") { ret = ebp; }
	else if(reg == "esp") { ret = esp; }
	else if(reg == "esi") { ret = esi; }
	else if(reg == "edi") { ret = edi; }
	else if(reg == "eip") { ret = eip; }
	else if(reg == "ax") { ret = eax & 0xffff; }
	else if(reg == "bx") { ret = ebx & 0xffff; }
	else if(reg == "cx") { ret = ecx & 0xffff; }
	else if(reg == "dx") { ret = edx & 0xffff; }
	else if(reg == "bp") { ret = ebp & 0xffff; }
	else if(reg == "sp") { ret = esp & 0xffff; }
	else if(reg == "si") { ret = esi & 0xffff; }
	else if(reg == "di") { ret = edi & 0xffff; }
	else if(reg == "al") { ret = eax & 0xff; }
	else if(reg == "bl") { ret = ebx & 0xff; }
	else if(reg == "cl") { ret = ecx & 0xff; }
	else if(reg == "dl") { ret = edx & 0xff; }
	else if(reg == "ah") { ret = (eax >> 8) & 0xff; }
	else if(reg == "bh") { ret = (ebx >> 8) & 0xff; }
	else if(reg == "ch") { ret = (ecx >> 8) & 0xff; }
	else if(reg == "dh") { ret = (edx >> 8) & 0xff; }

	return ret;
}
