diff src/win32/GBCheatsDlg.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/GBCheatsDlg.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,1140 @@
     1.4 +// GBCheats.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "GBCheatsDlg.h"
    1.10 +#include "Reg.h"
    1.11 +#include "StringTokenizer.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "Sound.h"
    1.14 +#include "VBA.h"
    1.15 +
    1.16 +#include "../common/CheatSearch.h"
    1.17 +#include "../gb/gbCheats.h"
    1.18 +#include "../gb/gbGlobals.h"
    1.19 +
    1.20 +static inline bool winGbCheatAddVerifyGs(const char *code, const char *desc)
    1.21 +{
    1.22 +	gbAddGsCheat(code, desc);
    1.23 +	return true;
    1.24 +}
    1.25 +
    1.26 +static inline bool winGbCheatAddVerifyGg(const char *code, const char *desc)
    1.27 +{
    1.28 +	gbAddGgCheat(code, desc);
    1.29 +	return true;
    1.30 +}
    1.31 +
    1.32 +////////////////////////////////
    1.33 +
    1.34 +bool winGbCheatReaddress()
    1.35 +{
    1.36 +	if (cheatSearchData.count != 3)
    1.37 +		return false;
    1.38 +
    1.39 +	CheatSearchBlock *block = &cheatSearchData.blocks[0];
    1.40 +	if (gbRamSize > 0)
    1.41 +	{
    1.42 +		if (gbRam)
    1.43 +			block->data = gbRam;
    1.44 +		else
    1.45 +			block->data = &gbMemory[0xa000];
    1.46 +		block->offset = 0xa000;
    1.47 +		block->size  = gbRamSize;
    1.48 +		cheatSearchSetSavedAndBits(block);
    1.49 +	}
    1.50 +	else
    1.51 +	{
    1.52 +		cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
    1.53 +	}
    1.54 +
    1.55 +	block = &cheatSearchData.blocks[1];
    1.56 +	if (gbCgbMode)
    1.57 +	{
    1.58 +		block->data   = &gbMemory[0xc000];
    1.59 +		block->offset = 0xc000;
    1.60 +		block->size   = 0x1000;
    1.61 +		cheatSearchSetSavedAndBits(block);
    1.62 +
    1.63 +		block         = &cheatSearchData.blocks[2];
    1.64 +		block->data   = gbWram;
    1.65 +		block->offset = 0xd000;
    1.66 +		block->size   = 0x8000;
    1.67 +		cheatSearchSetSavedAndBits(block);
    1.68 +	}
    1.69 +	else
    1.70 +	{
    1.71 +		block->data   = &gbMemory[0xc000];
    1.72 +		block->offset = 0xc000;
    1.73 +		block->size   = 0x2000;
    1.74 +		cheatSearchSetSavedAndBits(block);
    1.75 +
    1.76 +		cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
    1.77 +	}
    1.78 +
    1.79 +	cheatSearchData.count = 3;
    1.80 +	return true;
    1.81 +}
    1.82 +
    1.83 +/////////////////////////////////////////////////////////////////////////////
    1.84 +// GBCheatSearch dialog
    1.85 +
    1.86 +GBCheatSearch::GBCheatSearch(CWnd*pParent /*=NULL*/)
    1.87 +	: CDialog(GBCheatSearch::IDD, pParent)
    1.88 +{
    1.89 +	//{{AFX_DATA_INIT(GBCheatSearch)
    1.90 +	searchType   = -1;
    1.91 +	numberType   = -1;
    1.92 +	sizeType     = -1;
    1.93 +	updateValues = FALSE;
    1.94 +	valueType    = -1;
    1.95 +	//}}AFX_DATA_INIT
    1.96 +	data = NULL;
    1.97 +}
    1.98 +
    1.99 +GBCheatSearch::~GBCheatSearch()
   1.100 +{
   1.101 +	if (data)
   1.102 +		free(data);
   1.103 +}
   1.104 +
   1.105 +void GBCheatSearch::DoDataExchange(CDataExchange*pDX)
   1.106 +{
   1.107 +	CDialog::DoDataExchange(pDX);
   1.108 +	//{{AFX_DATA_MAP(GBCheatSearch)
   1.109 +	DDX_Control(pDX, IDC_VALUE, m_value);
   1.110 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
   1.111 +	DDX_Radio(pDX, IDC_EQ, searchType);
   1.112 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
   1.113 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
   1.114 +	DDX_Check(pDX, IDC_UPDATE, updateValues);
   1.115 +	DDX_Radio(pDX, IDC_OLD_VALUE, valueType);
   1.116 +	//}}AFX_DATA_MAP
   1.117 +}
   1.118 +
   1.119 +BEGIN_MESSAGE_MAP(GBCheatSearch, CDialog)
   1.120 +//{{AFX_MSG_MAP(GBCheatSearch)
   1.121 +ON_BN_CLICKED(ID_OK, OnOk)
   1.122 +ON_BN_CLICKED(IDC_ADD_CHEAT, OnAddCheat)
   1.123 +ON_BN_CLICKED(IDC_SEARCH, OnSearch)
   1.124 +ON_BN_CLICKED(IDC_START, OnStart)
   1.125 +ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
   1.126 +ON_NOTIFY(LVN_GETDISPINFO, IDC_CHEAT_LIST, OnGetdispinfoCheatList)
   1.127 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
   1.128 +ON_CONTROL_RANGE(BN_CLICKED, IDC_OLD_VALUE, IDC_SPECIFIC_VALUE, OnValueType)
   1.129 +ON_CONTROL_RANGE(BN_CLICKED, IDC_EQ, IDC_GE, OnSearchType)
   1.130 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
   1.131 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
   1.132 +//}}AFX_MSG_MAP
   1.133 +ON_WM_CLOSE()
   1.134 +ON_BN_CLICKED(IDC_CHEATREFRESHBUTTON, OnBnClickedCheatrefreshbutton)
   1.135 +END_MESSAGE_MAP()
   1.136 +
   1.137 +/////////////////////////////////////////////////////////////////////////////
   1.138 +// GBCheatSearch message handlers
   1.139 +
   1.140 +void GBCheatSearch::OnOk()
   1.141 +{
   1.142 +	if (data)
   1.143 +		free(data);
   1.144 +	data = NULL;
   1.145 +
   1.146 +	if (theApp.modelessCheatDialogIsOpen)
   1.147 +	{
   1.148 +		theApp.modelessCheatDialogIsOpen = false;
   1.149 +		DestroyWindow();
   1.150 +	}
   1.151 +	else
   1.152 +	{
   1.153 +		EndDialog(TRUE);
   1.154 +	}
   1.155 +}
   1.156 +
   1.157 +void GBCheatSearch::OnClose()
   1.158 +{
   1.159 +	CDialog::OnClose();
   1.160 +	if (theApp.modelessCheatDialogIsOpen)
   1.161 +	{
   1.162 +		theApp.modelessCheatDialogIsOpen = false;
   1.163 +		DestroyWindow();
   1.164 +	}
   1.165 +	else
   1.166 +	{
   1.167 +		EndDialog(FALSE);
   1.168 +	}
   1.169 +}
   1.170 +
   1.171 +void GBCheatSearch::OnBnClickedCheatrefreshbutton()
   1.172 +{
   1.173 +	addChanges(false);
   1.174 +}
   1.175 +
   1.176 +void GBCheatSearch::OnAddCheat()
   1.177 +{
   1.178 +	int mark = m_list.GetSelectionMark();
   1.179 +
   1.180 +	if (mark != -1)
   1.181 +	{
   1.182 +		LVITEM item;
   1.183 +		memset(&item, 0, sizeof(item));
   1.184 +		item.mask  = LVIF_PARAM;
   1.185 +		item.iItem = mark;
   1.186 +		if (m_list.GetItem(&item))
   1.187 +		{
   1.188 +			AddGBCheat dlg((u32)item.lParam);
   1.189 +			dlg.DoModal();
   1.190 +		}
   1.191 +	}
   1.192 +}
   1.193 +
   1.194 +void GBCheatSearch::OnSearch()
   1.195 +{
   1.196 +	CString buffer;
   1.197 +	if (valueType == 0)
   1.198 +		cheatSearch(&cheatSearchData,
   1.199 +		            searchType,
   1.200 +		            sizeType,
   1.201 +		            numberType == 0);
   1.202 +	else
   1.203 +	{
   1.204 +		m_value.GetWindowText(buffer);
   1.205 +		if (buffer.IsEmpty())
   1.206 +		{
   1.207 +			systemMessage(IDS_NUMBER_CANNOT_BE_EMPTY, "Number cannot be empty");
   1.208 +			return;
   1.209 +		}
   1.210 +		int value = 0;
   1.211 +		switch (numberType)
   1.212 +		{
   1.213 +		case 0:
   1.214 +			sscanf(buffer, "%d", &value);
   1.215 +			break;
   1.216 +		case 1:
   1.217 +			sscanf(buffer, "%u", &value);
   1.218 +			break;
   1.219 +		default:
   1.220 +			sscanf(buffer, "%x", &value);
   1.221 +		}
   1.222 +		cheatSearchValue(&cheatSearchData,
   1.223 +		                 searchType,
   1.224 +		                 sizeType,
   1.225 +		                 numberType == 0,
   1.226 +		                 value);
   1.227 +	}
   1.228 +
   1.229 +	addChanges(true);
   1.230 +
   1.231 +	if (updateValues)
   1.232 +		cheatSearchUpdateValues(&cheatSearchData);
   1.233 +
   1.234 +	if (theApp.modelessCheatDialogIsOpen)
   1.235 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData, sizeType) == 0 ? FALSE : TRUE);
   1.236 +
   1.237 +	if (0 == cheatSearchGetCount(&cheatSearchData, sizeType))
   1.238 +		OnStart();
   1.239 +}
   1.240 +
   1.241 +void GBCheatSearch::OnStart()
   1.242 +{
   1.243 +	if (cheatSearchData.count == 0)
   1.244 +	{
   1.245 +		CheatSearchBlock *block = &cheatSearchData.blocks[0];
   1.246 +		if (gbRamSize > 0)
   1.247 +		{
   1.248 +			if (gbRam)
   1.249 +				block->data = gbRam;
   1.250 +			else
   1.251 +				block->data = &gbMemory[0xa000];
   1.252 +			block->size  = gbRamSize;
   1.253 +			block->offset = 0xa000;
   1.254 +			block->saved = (u8 *)malloc(gbRamSize);
   1.255 +			block->bits  = (u8 *)malloc(gbRamSize >> 3);
   1.256 +		}
   1.257 +		else
   1.258 +		{
   1.259 +			cheatSearchZeroBlock(&cheatSearchData.blocks[0]);
   1.260 +		}
   1.261 +
   1.262 +		block = &cheatSearchData.blocks[1];
   1.263 +		if (gbCgbMode)
   1.264 +		{
   1.265 +			block->data   = &gbMemory[0xc000];
   1.266 +			block->size   = 0x1000;
   1.267 +			block->offset = 0xc000;
   1.268 +			block->saved  = (u8 *)malloc(0x1000);
   1.269 +			block->bits   = (u8 *)malloc(0x1000 >> 3);
   1.270 +
   1.271 +			block         = &cheatSearchData.blocks[2];
   1.272 +			block->data   = gbWram;
   1.273 +			block->size   = 0x8000;
   1.274 +			block->offset = 0xd000;
   1.275 +			block->saved  = (u8 *)malloc(0x8000);
   1.276 +			block->bits   = (u8 *)malloc(0x8000 >> 3);
   1.277 +		}
   1.278 +		else
   1.279 +		{
   1.280 +			block->data   = &gbMemory[0xc000];
   1.281 +			block->size   = 0x2000;
   1.282 +			block->offset = 0xc000;
   1.283 +			block->saved  = (u8 *)malloc(0x2000);
   1.284 +			block->bits   = (u8 *)malloc(0x2000 >> 3);
   1.285 +
   1.286 +			cheatSearchZeroBlock(&cheatSearchData.blocks[2]);
   1.287 +		}
   1.288 +
   1.289 +		cheatSearchData.count = 3;
   1.290 +	}
   1.291 +
   1.292 +	cheatSearchStart(&cheatSearchData);
   1.293 +	GetDlgItem(IDC_SEARCH)->EnableWindow(TRUE);
   1.294 +
   1.295 +	if (theApp.modelessCheatDialogIsOpen)
   1.296 +	{
   1.297 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
   1.298 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
   1.299 +	}
   1.300 +}
   1.301 +
   1.302 +void GBCheatSearch::OnUpdate()
   1.303 +{
   1.304 +	if (GetDlgItem(IDC_UPDATE)->SendMessage(BM_GETCHECK,
   1.305 +	                                        0,
   1.306 +	                                        0) & BST_CHECKED)
   1.307 +		updateValues = true;
   1.308 +	else
   1.309 +		updateValues = false;
   1.310 +	regSetDwordValue("gbCheatsUpdate", updateValues);
   1.311 +}
   1.312 +
   1.313 +BOOL GBCheatSearch::OnInitDialog()
   1.314 +{
   1.315 +	CDialog::OnInitDialog();
   1.316 +
   1.317 +	CString temp = winResLoadString(IDS_ADDRESS);
   1.318 +
   1.319 +	m_list.InsertColumn(0, temp, LVCFMT_CENTER, 125, 0);
   1.320 +
   1.321 +	temp = winResLoadString(IDS_OLD_VALUE);
   1.322 +	m_list.InsertColumn(1, temp, LVCFMT_CENTER, 125, 1);
   1.323 +
   1.324 +	temp = winResLoadString(IDS_NEW_VALUE);
   1.325 +	m_list.InsertColumn(2, temp, LVCFMT_CENTER, 125, 2);
   1.326 +
   1.327 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
   1.328 +	               TRUE);
   1.329 +
   1.330 +	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);
   1.331 +
   1.332 +	if (!cheatSearchData.count)
   1.333 +	{
   1.334 +		GetDlgItem(IDC_SEARCH)->EnableWindow(FALSE);
   1.335 +		GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(FALSE);
   1.336 +	}
   1.337 +
   1.338 +	valueType = regQueryDwordValue("gbCheatsValueType", 0);
   1.339 +	if (valueType < 0 || valueType > 1)
   1.340 +		valueType = 2;
   1.341 +
   1.342 +	searchType = regQueryDwordValue("gbCheatsSearchType",
   1.343 +	                                SEARCH_EQ);
   1.344 +	if (searchType < 0 || searchType > 5)
   1.345 +		searchType = 0;
   1.346 +
   1.347 +	numberType = regQueryDwordValue("gbCheatsNumberType", 2);
   1.348 +	if (numberType < 0 || numberType > 2)
   1.349 +		numberType = 2;
   1.350 +
   1.351 +	sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
   1.352 +	if (sizeType < 0 || sizeType > 2)
   1.353 +		sizeType = 0;
   1.354 +
   1.355 +	updateValues = regQueryDwordValue("gbCheatsUpdate", 0) ?
   1.356 +	               true : false;
   1.357 +
   1.358 +	UpdateData(FALSE);
   1.359 +
   1.360 +	if (valueType == 0)
   1.361 +		m_value.EnableWindow(FALSE);
   1.362 +
   1.363 +	CenterWindow();
   1.364 +
   1.365 +	if (theApp.modelessCheatDialogIsOpen)
   1.366 +		GetDlgItem(IDC_CHEATREFRESHBUTTON)->ShowWindow(TRUE);
   1.367 +
   1.368 +	if (cheatSearchData.count)
   1.369 +	{
   1.370 +		addChanges(false);
   1.371 +		if (theApp.modelessCheatDialogIsOpen)
   1.372 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(cheatSearchGetCount(&cheatSearchData,
   1.373 +			                                                                     sizeType) == 0 ? FALSE : TRUE);
   1.374 +	}
   1.375 +	else
   1.376 +	{
   1.377 +		if (theApp.modelessCheatDialogIsOpen)
   1.378 +			GetDlgItem(IDC_CHEATREFRESHBUTTON)->EnableWindow(FALSE);
   1.379 +	}
   1.380 +
   1.381 +	return TRUE; // return TRUE unless you set the focus to a control
   1.382 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.383 +}
   1.384 +
   1.385 +void GBCheatSearch::OnGetdispinfoCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.386 +{
   1.387 +	LV_DISPINFO*info = (LV_DISPINFO *)pNMHDR;
   1.388 +	if (info->item.mask & LVIF_TEXT)
   1.389 +	{
   1.390 +		int index = info->item.iItem;
   1.391 +		int col   = info->item.iSubItem;
   1.392 +
   1.393 +		switch (col)
   1.394 +		{
   1.395 +		case 0:
   1.396 +			strcpy(info->item.pszText, data[index].address);
   1.397 +			break;
   1.398 +		case 1:
   1.399 +			strcpy(info->item.pszText, data[index].oldValue);
   1.400 +			break;
   1.401 +		case 2:
   1.402 +			strcpy(info->item.pszText, data[index].newValue);
   1.403 +			break;
   1.404 +		}
   1.405 +	}
   1.406 +	*pResult = TRUE;
   1.407 +}
   1.408 +
   1.409 +void GBCheatSearch::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.410 +{
   1.411 +	GetDlgItem(IDC_ADD_CHEAT)->EnableWindow(m_list.GetSelectionMark() != -1);
   1.412 +}
   1.413 +
   1.414 +int GBCheatSearch::getBank(u16 addr, int j)
   1.415 +{
   1.416 +	switch (addr >> 12)
   1.417 +	{
   1.418 +	case 0x0a:
   1.419 +		return j / 0x2000;
   1.420 +	case 0x0d:
   1.421 +		return j / 0x1000;
   1.422 +	}
   1.423 +	return 0;
   1.424 +}
   1.425 +
   1.426 +void GBCheatSearch::addChange(int index, int bank, u16 address, int offset, u32 oldValue, u32 newValue)
   1.427 +{
   1.428 +	data[index].bank = bank;
   1.429 +	if (bank)
   1.430 +	{
   1.431 +		if (address == 0xa000)
   1.432 +			address |= offset & 0x1fff;
   1.433 +		else
   1.434 +			address |= offset & 0xfff;
   1.435 +	}
   1.436 +	else
   1.437 +		address |= offset;
   1.438 +	data[index].addr = address;
   1.439 +	sprintf(data[index].address, "%02x:%04x", bank, address);
   1.440 +	switch (numberType)
   1.441 +	{
   1.442 +	case 0:
   1.443 +		sprintf(data[index].oldValue, "%d", oldValue);
   1.444 +		sprintf(data[index].newValue, "%d", newValue);
   1.445 +		break;
   1.446 +	case 1:
   1.447 +		sprintf(data[index].oldValue, "%u", oldValue);
   1.448 +		sprintf(data[index].newValue, "%u", newValue);
   1.449 +		break;
   1.450 +	case 2:
   1.451 +		switch (sizeType)
   1.452 +		{
   1.453 +		case 0:
   1.454 +			sprintf(data[index].oldValue, "%02x", oldValue);
   1.455 +			sprintf(data[index].newValue, "%02x", newValue);
   1.456 +			break;
   1.457 +		case 1:
   1.458 +			sprintf(data[index].oldValue, "%04x", oldValue);
   1.459 +			sprintf(data[index].newValue, "%04x", newValue);
   1.460 +			break;
   1.461 +		case 2:
   1.462 +			sprintf(data[index].oldValue, "%08x", oldValue);
   1.463 +			sprintf(data[index].newValue, "%08x", newValue);
   1.464 +			break;
   1.465 +		}
   1.466 +	}
   1.467 +}
   1.468 +
   1.469 +void GBCheatSearch::addChanges(bool showMsg)
   1.470 +{
   1.471 +	int count = cheatSearchGetCount(&cheatSearchData, sizeType);
   1.472 +
   1.473 +	m_list.DeleteAllItems();
   1.474 +
   1.475 +	if (count > 4000)
   1.476 +	{
   1.477 +		if (showMsg)
   1.478 +			systemMessage(
   1.479 +			    IDS_SEARCH_PRODUCED_TOO_MANY,
   1.480 +			    "Search produced %d results.\nThey have been remembered, but are too many to display.\nPlease refine it better by performing additional searches.",
   1.481 +			    count);
   1.482 +		return;
   1.483 +	}
   1.484 +
   1.485 +	if (count == 0)
   1.486 +	{
   1.487 +		if (showMsg)
   1.488 +			systemMessage(IDS_SEARCH_PRODUCED_NO_RESULTS, "Search produced no results");
   1.489 +		return;
   1.490 +	}
   1.491 +
   1.492 +	m_list.SetItemCount(count);
   1.493 +	if (data)
   1.494 +		free(data);
   1.495 +
   1.496 +	data = (WinGbCheatsData *)calloc(count, sizeof(WinGbCheatsData));
   1.497 +
   1.498 +	int inc = 1;
   1.499 +	switch (sizeType)
   1.500 +	{
   1.501 +	case 1:
   1.502 +		inc = 2;
   1.503 +		break;
   1.504 +	case 2:
   1.505 +		inc = 4;
   1.506 +		break;
   1.507 +	}
   1.508 +
   1.509 +	int index = 0;
   1.510 +	if (numberType == 0)
   1.511 +	{
   1.512 +		for (int i = 0; i < cheatSearchData.count; i++)
   1.513 +		{
   1.514 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
   1.515 +
   1.516 +			for (int j = 0; j < block->size; j += inc)
   1.517 +			{
   1.518 +				if (IS_BIT_SET(block->bits, j))
   1.519 +				{
   1.520 +					addChange(index++,
   1.521 +					          getBank(block->offset|j, j),
   1.522 +					          block->offset,
   1.523 +					          j,
   1.524 +					          cheatSearchSignedRead(block->saved,
   1.525 +					                                j,
   1.526 +					                                sizeType),
   1.527 +					          cheatSearchSignedRead(block->data,
   1.528 +					                                j,
   1.529 +					                                sizeType));
   1.530 +				}
   1.531 +			}
   1.532 +		}
   1.533 +	}
   1.534 +	else
   1.535 +	{
   1.536 +		for (int i = 0; i < cheatSearchData.count; i++)
   1.537 +		{
   1.538 +			CheatSearchBlock *block = &cheatSearchData.blocks[i];
   1.539 +
   1.540 +			for (int j = 0; j < block->size; j += inc)
   1.541 +			{
   1.542 +				if (IS_BIT_SET(block->bits, j))
   1.543 +				{
   1.544 +					addChange(index++,
   1.545 +					          getBank(block->offset|j, j),
   1.546 +					          block->offset,
   1.547 +					          j,
   1.548 +					          cheatSearchRead(block->saved,
   1.549 +					                          j,
   1.550 +					                          sizeType),
   1.551 +					          cheatSearchRead(block->data,
   1.552 +					                          j,
   1.553 +					                          sizeType));
   1.554 +				}
   1.555 +			}
   1.556 +		}
   1.557 +	}
   1.558 +
   1.559 +	for (int i = 0; i < count; i++)
   1.560 +	{
   1.561 +		LVITEM item;
   1.562 +
   1.563 +		item.mask     = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
   1.564 +		item.iItem    = i;
   1.565 +		item.iSubItem = 0;
   1.566 +		item.lParam   = data[i].addr|
   1.567 +		                (data[i].bank << 16);
   1.568 +		item.state     = 0;
   1.569 +		item.stateMask = 0;
   1.570 +		item.pszText   = LPSTR_TEXTCALLBACK;
   1.571 +		m_list.InsertItem(&item);
   1.572 +
   1.573 +		m_list.SetItemText(i, 1, LPSTR_TEXTCALLBACK);
   1.574 +		m_list.SetItemText(i, 2, LPSTR_TEXTCALLBACK);
   1.575 +	}
   1.576 +}
   1.577 +
   1.578 +void GBCheatSearch::OnValueType(UINT id)
   1.579 +{
   1.580 +	switch (id)
   1.581 +	{
   1.582 +	case IDC_OLD_VALUE:
   1.583 +		valueType = 0;
   1.584 +		m_value.EnableWindow(FALSE);
   1.585 +		regSetDwordValue("gbCheatsValueType", 0);
   1.586 +		break;
   1.587 +	case IDC_SPECIFIC_VALUE:
   1.588 +		valueType = 1;
   1.589 +		m_value.EnableWindow(TRUE);
   1.590 +		regSetDwordValue("gbCheatsValueType", 1);
   1.591 +		break;
   1.592 +	}
   1.593 +}
   1.594 +
   1.595 +void GBCheatSearch::OnSearchType(UINT id)
   1.596 +{
   1.597 +	switch (id)
   1.598 +	{
   1.599 +	case IDC_EQ:
   1.600 +		searchType = SEARCH_EQ;
   1.601 +		regSetDwordValue("gbCheatsSearchType", 0);
   1.602 +		break;
   1.603 +	case IDC_NE:
   1.604 +		searchType = SEARCH_NE;
   1.605 +		regSetDwordValue("gbCheatsSearchType", 1);
   1.606 +		break;
   1.607 +	case IDC_LT:
   1.608 +		searchType = SEARCH_LT;
   1.609 +		regSetDwordValue("gbCheatsSearchType", 2);
   1.610 +		break;
   1.611 +	case IDC_LE:
   1.612 +		searchType = SEARCH_LE;
   1.613 +		regSetDwordValue("gbCheatsSearchType", 3);
   1.614 +		break;
   1.615 +	case IDC_GT:
   1.616 +		searchType = SEARCH_GT;
   1.617 +		regSetDwordValue("gbCheatsSearchType", 4);
   1.618 +		break;
   1.619 +	case IDC_GE:
   1.620 +		searchType = SEARCH_GE;
   1.621 +		regSetDwordValue("gbCheatsSearchType", 5);
   1.622 +		break;
   1.623 +	}
   1.624 +}
   1.625 +
   1.626 +void GBCheatSearch::OnNumberType(UINT id)
   1.627 +{
   1.628 +	switch (id)
   1.629 +	{
   1.630 +	case IDC_SIGNED:
   1.631 +		numberType = 0;
   1.632 +		regSetDwordValue("gbCheatsNumberType", 0);
   1.633 +		if (m_list.GetItemCount())
   1.634 +		{
   1.635 +			addChanges(false);
   1.636 +		}
   1.637 +		break;
   1.638 +	case IDC_UNSIGNED:
   1.639 +		numberType = 1;
   1.640 +		regSetDwordValue("gbCheatsNumberType", 1);
   1.641 +		if (m_list.GetItemCount())
   1.642 +		{
   1.643 +			addChanges(false);
   1.644 +		}
   1.645 +		break;
   1.646 +	case IDC_HEXADECIMAL:
   1.647 +		numberType = 2;
   1.648 +		regSetDwordValue("gbCheatsNumberType", 2);
   1.649 +		if (m_list.GetItemCount())
   1.650 +		{
   1.651 +			addChanges(false);
   1.652 +		}
   1.653 +		break;
   1.654 +	}
   1.655 +}
   1.656 +
   1.657 +void GBCheatSearch::OnSizeType(UINT id)
   1.658 +{
   1.659 +	switch (id)
   1.660 +	{
   1.661 +	case IDC_SIZE_8:
   1.662 +		sizeType = BITS_8;
   1.663 +		regSetDwordValue("gbCheatsSizeType", 0);
   1.664 +		if (m_list.GetItemCount())
   1.665 +		{
   1.666 +			addChanges(false);
   1.667 +		}
   1.668 +		break;
   1.669 +	case IDC_SIZE_16:
   1.670 +		sizeType = BITS_16;
   1.671 +		regSetDwordValue("gbCheatsSizeType", 1);
   1.672 +		if (m_list.GetItemCount())
   1.673 +		{
   1.674 +			addChanges(false);
   1.675 +		}
   1.676 +		break;
   1.677 +	case IDC_SIZE_32:
   1.678 +		sizeType = BITS_32;
   1.679 +		regSetDwordValue("gbCheatsSizeType", 2);
   1.680 +		if (m_list.GetItemCount())
   1.681 +		{
   1.682 +			addChanges(false);
   1.683 +		}
   1.684 +		break;
   1.685 +	}
   1.686 +}
   1.687 +
   1.688 +/////////////////////////////////////////////////////////////////////////////
   1.689 +// AddGBCheat dialog
   1.690 +
   1.691 +AddGBCheat::AddGBCheat(u32 addr, CWnd*pParent /*=NULL*/)
   1.692 +	: CDialog(AddGBCheat::IDD, pParent)
   1.693 +{
   1.694 +	//{{AFX_DATA_INIT(AddGBCheat)
   1.695 +	numberType = regQueryDwordValue("gbCheatsNumberType", 2);
   1.696 +	if (numberType < 0 || numberType > 2)
   1.697 +		numberType = 2;
   1.698 +	sizeType = regQueryDwordValue("gbCheatsSizeType", 0);
   1.699 +	if (sizeType < 0 || sizeType > 2)
   1.700 +		sizeType = 0;
   1.701 +	//}}AFX_DATA_INIT
   1.702 +	address = addr;
   1.703 +}
   1.704 +
   1.705 +void AddGBCheat::DoDataExchange(CDataExchange*pDX)
   1.706 +{
   1.707 +	CDialog::DoDataExchange(pDX);
   1.708 +	//{{AFX_DATA_MAP(AddGBCheat)
   1.709 +	DDX_Control(pDX, IDC_VALUE, m_value);
   1.710 +	DDX_Control(pDX, IDC_ADDRESS, m_address);
   1.711 +	DDX_Control(pDX, IDC_DESC, m_desc);
   1.712 +	DDX_Radio(pDX, IDC_SIZE_8, sizeType);
   1.713 +	DDX_Radio(pDX, IDC_SIGNED, numberType);
   1.714 +	//}}AFX_DATA_MAP
   1.715 +}
   1.716 +
   1.717 +BEGIN_MESSAGE_MAP(AddGBCheat, CDialog)
   1.718 +//{{AFX_MSG_MAP(AddGBCheat)
   1.719 +ON_BN_CLICKED(ID_OK, OnOk)
   1.720 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
   1.721 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIGNED, IDC_HEXADECIMAL, OnNumberType)
   1.722 +ON_CONTROL_RANGE(BN_CLICKED, IDC_SIZE_8, IDC_SIZE_32, OnSizeType)
   1.723 +//}}AFX_MSG_MAP
   1.724 +END_MESSAGE_MAP()
   1.725 +
   1.726 +/////////////////////////////////////////////////////////////////////////////
   1.727 +// AddGBCheat message handlers
   1.728 +
   1.729 +void AddGBCheat::OnCancel()
   1.730 +{
   1.731 +	EndDialog(FALSE);
   1.732 +}
   1.733 +
   1.734 +void AddGBCheat::OnOk()
   1.735 +{
   1.736 +	// add cheat
   1.737 +	if (addCheat())
   1.738 +	{
   1.739 +		EndDialog(TRUE);
   1.740 +	}
   1.741 +}
   1.742 +
   1.743 +bool AddGBCheat::addCheat()
   1.744 +{
   1.745 +	CString buffer;
   1.746 +	CString code;
   1.747 +
   1.748 +	u32 value;
   1.749 +	m_value.GetWindowText(buffer);
   1.750 +
   1.751 +	if (buffer.IsEmpty())
   1.752 +	{
   1.753 +		systemMessage(IDS_VALUE_CANNOT_BE_EMPTY, "Value cannot be empty");
   1.754 +		return false;
   1.755 +	}
   1.756 +
   1.757 +	switch (numberType)
   1.758 +	{
   1.759 +	case 0:
   1.760 +		sscanf(buffer, "%d", &value);
   1.761 +		break;
   1.762 +	case 1:
   1.763 +		sscanf(buffer, "%u", &value);
   1.764 +		break;
   1.765 +	default:
   1.766 +		sscanf(buffer, "%x", &value);
   1.767 +	}
   1.768 +
   1.769 +	m_desc.GetWindowText(buffer);
   1.770 +
   1.771 +	int bank = (address >> 16);
   1.772 +	address &= 0xFFFF;
   1.773 +
   1.774 +	if (address >= 0xd000)
   1.775 +		bank += 0x90;
   1.776 +	else
   1.777 +		bank = 0x01;
   1.778 +
   1.779 +	switch (sizeType)
   1.780 +	{
   1.781 +	case 0:
   1.782 +		code.Format("%02X%02X%02X%02X", bank, value, address&0xFF, address>>8);
   1.783 +		gbAddGsCheat(code, buffer);
   1.784 +		break;
   1.785 +	case 1:
   1.786 +		code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
   1.787 +		            address>>8);
   1.788 +		gbAddGsCheat(code, buffer);
   1.789 +		address++;
   1.790 +		code.Format("%02X%02X%02X%02X", bank, value>>8, address&0xFF,
   1.791 +		            address>>8);
   1.792 +		gbAddGsCheat(code, buffer);
   1.793 +		break;
   1.794 +	case 2:
   1.795 +		code.Format("%02X%02X%02X%02X", bank, value&0xFF, address&0xFF,
   1.796 +		            address>>8);
   1.797 +		gbAddGsCheat(code, buffer);
   1.798 +		address++;
   1.799 +		code.Format("%02X%02X%02X%02X", bank, (value>>8) & 0xFF, address&0xFF,
   1.800 +		            address>>8);
   1.801 +		gbAddGsCheat(code, buffer);
   1.802 +		address++;
   1.803 +		code.Format("%02X%02X%02X%02X", bank, (value>>16)&0xFF, address&0xFF,
   1.804 +		            address>>8);
   1.805 +		gbAddGsCheat(code, buffer);
   1.806 +		address++;
   1.807 +		code.Format("%02X%02X%02X%02X", bank, value>>24, address&0xFF,
   1.808 +		            address>>8);
   1.809 +		gbAddGsCheat(code, buffer);
   1.810 +		break;
   1.811 +	}
   1.812 +
   1.813 +	return true;
   1.814 +}
   1.815 +
   1.816 +BOOL AddGBCheat::OnInitDialog()
   1.817 +{
   1.818 +	CDialog::OnInitDialog();
   1.819 +
   1.820 +	CString buffer;
   1.821 +	buffer.Format("%02x:%08x", (address>>16), address&0xFFFF);
   1.822 +	m_address.SetWindowText(buffer);
   1.823 +	m_address.EnableWindow(FALSE);
   1.824 +	::SetWindowLong(m_address,
   1.825 +	                GWL_USERDATA,
   1.826 +	                address);
   1.827 +
   1.828 +	UpdateData(FALSE);
   1.829 +
   1.830 +	m_desc.LimitText(32);
   1.831 +
   1.832 +	if (address != 0)
   1.833 +	{
   1.834 +		GetDlgItem(IDC_SIZE_8)->EnableWindow(FALSE);
   1.835 +		GetDlgItem(IDC_SIZE_16)->EnableWindow(FALSE);
   1.836 +		GetDlgItem(IDC_SIZE_32)->EnableWindow(FALSE);
   1.837 +		GetDlgItem(IDC_HEXADECIMAL)->EnableWindow(FALSE);
   1.838 +		GetDlgItem(IDC_UNSIGNED)->EnableWindow(FALSE);
   1.839 +		GetDlgItem(IDC_SIGNED)->EnableWindow(FALSE);
   1.840 +	}
   1.841 +	CenterWindow();
   1.842 +
   1.843 +	return TRUE; // return TRUE unless you set the focus to a control
   1.844 +	             // EXCEPTION: OCX Property Pages should return FALSE
   1.845 +}
   1.846 +
   1.847 +void AddGBCheat::OnNumberType(UINT id)
   1.848 +{
   1.849 +	switch (id)
   1.850 +	{
   1.851 +	case IDC_SIGNED:
   1.852 +		numberType = 0;
   1.853 +		regSetDwordValue("gbCheatsNumberType", 0);
   1.854 +		break;
   1.855 +	case IDC_UNSIGNED:
   1.856 +		numberType = 1;
   1.857 +		regSetDwordValue("gbCheatsNumberType", 1);
   1.858 +		break;
   1.859 +	case IDC_HEXADECIMAL:
   1.860 +		numberType = 2;
   1.861 +		regSetDwordValue("gbCheatsNumberType", 2);
   1.862 +		break;
   1.863 +	}
   1.864 +}
   1.865 +
   1.866 +void AddGBCheat::OnSizeType(UINT id)
   1.867 +{
   1.868 +	switch (id)
   1.869 +	{
   1.870 +	case IDC_SIZE_8:
   1.871 +		sizeType = BITS_8;
   1.872 +		regSetDwordValue("gbCheatsSizeType", 0);
   1.873 +		break;
   1.874 +	case IDC_SIZE_16:
   1.875 +		sizeType = BITS_16;
   1.876 +		regSetDwordValue("gbCheatsSizeType", 1);
   1.877 +		break;
   1.878 +	case IDC_SIZE_32:
   1.879 +		sizeType = BITS_32;
   1.880 +		regSetDwordValue("gbCheatsSizeType", 2);
   1.881 +		break;
   1.882 +	}
   1.883 +}
   1.884 +
   1.885 +/////////////////////////////////////////////////////////////////////////////
   1.886 +// GBCheatList dialog
   1.887 +
   1.888 +GBCheatList::GBCheatList(CWnd*pParent /*=NULL*/)
   1.889 +	: CDialog(GBCheatList::IDD, pParent)
   1.890 +{
   1.891 +	//{{AFX_DATA_INIT(GBCheatList)
   1.892 +	// NOTE: the ClassWizard will add member initialization here
   1.893 +	//}}AFX_DATA_INIT
   1.894 +	duringRefresh = false;
   1.895 +}
   1.896 +
   1.897 +void GBCheatList::DoDataExchange(CDataExchange*pDX)
   1.898 +{
   1.899 +	CDialog::DoDataExchange(pDX);
   1.900 +	//{{AFX_DATA_MAP(GBCheatList)
   1.901 +	DDX_Control(pDX, IDC_CHEAT_LIST, m_list);
   1.902 +	//}}AFX_DATA_MAP
   1.903 +}
   1.904 +
   1.905 +BEGIN_MESSAGE_MAP(GBCheatList, CDialog)
   1.906 +//{{AFX_MSG_MAP(GBCheatList)
   1.907 +ON_BN_CLICKED(ID_OK, OnOk)
   1.908 +ON_BN_CLICKED(IDC_ADD_GG_CHEAT, OnAddGgCheat)
   1.909 +ON_BN_CLICKED(IDC_ADD_GS_CHEAT, OnAddGsCheat)
   1.910 +ON_BN_CLICKED(IDC_ENABLE, OnEnable)
   1.911 +ON_BN_CLICKED(IDC_REMOVE, OnRemove)
   1.912 +ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
   1.913 +ON_NOTIFY(LVN_ITEMCHANGED, IDC_CHEAT_LIST, OnItemchangedCheatList)
   1.914 +//}}AFX_MSG_MAP
   1.915 +END_MESSAGE_MAP()
   1.916 +
   1.917 +/////////////////////////////////////////////////////////////////////////////
   1.918 +// GBCheatList message handlers
   1.919 +
   1.920 +void GBCheatList::OnOk()
   1.921 +{
   1.922 +	EndDialog(TRUE);
   1.923 +}
   1.924 +
   1.925 +void GBCheatList::OnAddGgCheat()
   1.926 +{
   1.927 +	CString   temp = winResLoadString(IDS_ADD_GG_CODE);
   1.928 +	AddGBCode dlg(winGbCheatAddVerifyGg, 11, temp);
   1.929 +	dlg.DoModal();
   1.930 +	refresh();
   1.931 +}
   1.932 +
   1.933 +void GBCheatList::OnAddGsCheat()
   1.934 +{
   1.935 +	CString temp = winResLoadString(IDS_ADD_GS_CODE);
   1.936 +
   1.937 +	AddGBCode dlg(winGbCheatAddVerifyGs, 8, temp);
   1.938 +	dlg.DoModal();
   1.939 +	refresh();
   1.940 +}
   1.941 +
   1.942 +void GBCheatList::OnEnable()
   1.943 +{
   1.944 +	int mark = m_list.GetSelectionMark();
   1.945 +
   1.946 +	if (mark != -1)
   1.947 +	{
   1.948 +		LVITEM item;
   1.949 +		memset(&item, 0, sizeof(item));
   1.950 +		item.mask  = LVIF_PARAM;
   1.951 +		item.iItem = mark;
   1.952 +		if (m_list.GetItem(&item))
   1.953 +		{
   1.954 +			if (gbCheatList[item.lParam].enabled)
   1.955 +				gbCheatDisable(item.lParam);
   1.956 +			else
   1.957 +				gbCheatEnable(item.lParam);
   1.958 +			refresh();
   1.959 +		}
   1.960 +	}
   1.961 +}
   1.962 +
   1.963 +void GBCheatList::OnRemove()
   1.964 +{
   1.965 +	int mark = m_list.GetSelectionMark();
   1.966 +
   1.967 +	if (mark != -1)
   1.968 +	{
   1.969 +		LVITEM item;
   1.970 +		memset(&item, 0, sizeof(item));
   1.971 +		item.mask  = LVIF_PARAM;
   1.972 +		item.iItem = mark;
   1.973 +		if (m_list.GetItem(&item))
   1.974 +		{
   1.975 +			gbCheatRemove(item.lParam);
   1.976 +			refresh();
   1.977 +		}
   1.978 +	}
   1.979 +}
   1.980 +
   1.981 +void GBCheatList::OnRemoveAll()
   1.982 +{
   1.983 +	gbCheatRemoveAll();
   1.984 +	refresh();
   1.985 +}
   1.986 +
   1.987 +void GBCheatList::OnItemchangedCheatList(NMHDR*pNMHDR, LRESULT*pResult)
   1.988 +{
   1.989 +	if (m_list.GetSelectionMark() != -1)
   1.990 +	{
   1.991 +		GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
   1.992 +		GetDlgItem(IDC_ENABLE)->EnableWindow(TRUE);
   1.993 +	}
   1.994 +	else
   1.995 +	{
   1.996 +		GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
   1.997 +		GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
   1.998 +	}
   1.999 +
  1.1000 +	if (!duringRefresh)
  1.1001 +	{
  1.1002 +		LPNMLISTVIEW l = (LPNMLISTVIEW)pNMHDR;
  1.1003 +		if (l->uChanged & LVIF_STATE)
  1.1004 +		{
  1.1005 +			if (((l->uOldState & LVIS_STATEIMAGEMASK)>>12) !=
  1.1006 +			    (((l->uNewState & LVIS_STATEIMAGEMASK)>>12)))
  1.1007 +			{
  1.1008 +				if (m_list.GetCheck(l->iItem))
  1.1009 +					gbCheatEnable(l->lParam);
  1.1010 +				else
  1.1011 +					gbCheatDisable(l->lParam);
  1.1012 +				refresh();
  1.1013 +			}
  1.1014 +		}
  1.1015 +	}
  1.1016 +}
  1.1017 +
  1.1018 +BOOL GBCheatList::OnInitDialog()
  1.1019 +{
  1.1020 +	CDialog::OnInitDialog();
  1.1021 +
  1.1022 +	CString temp = winResLoadString(IDS_CODE);
  1.1023 +	m_list.InsertColumn(0, temp, LVCFMT_LEFT, 120, 0);
  1.1024 +	temp = winResLoadString(IDS_DESCRIPTION);
  1.1025 +	m_list.InsertColumn(1, temp, LVCFMT_LEFT, 200, 1);
  1.1026 +	temp = winResLoadString(IDS_STATUS);
  1.1027 +	m_list.InsertColumn(2, temp, LVCFMT_LEFT, 80, 2);
  1.1028 +
  1.1029 +	m_list.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)),
  1.1030 +	               TRUE);
  1.1031 +
  1.1032 +	m_list.SetExtendedStyle(LVS_EX_CHECKBOXES |
  1.1033 +	                        LVS_EX_FULLROWSELECT);
  1.1034 +
  1.1035 +	refresh();
  1.1036 +	GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
  1.1037 +	GetDlgItem(IDC_ENABLE)->EnableWindow(FALSE);
  1.1038 +	CenterWindow();
  1.1039 +
  1.1040 +	return TRUE; // return TRUE unless you set the focus to a control
  1.1041 +	             // EXCEPTION: OCX Property Pages should return FALSE
  1.1042 +}
  1.1043 +
  1.1044 +void GBCheatList::refresh()
  1.1045 +{
  1.1046 +	duringRefresh = true;
  1.1047 +
  1.1048 +	m_list.DeleteAllItems();
  1.1049 +
  1.1050 +	char buffer[2];
  1.1051 +
  1.1052 +	for (int i = 0; i < gbCheatNumber; i++)
  1.1053 +	{
  1.1054 +		LVITEM item;
  1.1055 +
  1.1056 +		item.mask      = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  1.1057 +		item.iItem     = i;
  1.1058 +		item.iSubItem  = 0;
  1.1059 +		item.lParam    = i;
  1.1060 +		item.state     = 0;
  1.1061 +		item.stateMask = 0;
  1.1062 +		item.pszText   = gbCheatList[i].cheatCode;
  1.1063 +		m_list.InsertItem(&item);
  1.1064 +
  1.1065 +		m_list.SetCheck(i, (gbCheatList[i].enabled ? TRUE : FALSE));
  1.1066 +
  1.1067 +		m_list.SetItemText(i, 1, gbCheatList[i].cheatDesc);
  1.1068 +
  1.1069 +		buffer[0] = (gbCheatList[i].enabled) ? 'E' : 'D';
  1.1070 +		buffer[1] = 0;
  1.1071 +		m_list.SetItemText(i, 2, buffer);
  1.1072 +	}
  1.1073 +	duringRefresh = false;
  1.1074 +}
  1.1075 +
  1.1076 +/////////////////////////////////////////////////////////////////////////////
  1.1077 +// AddGBCode dialog
  1.1078 +
  1.1079 +AddGBCode::AddGBCode(bool(*verify)(const char *, const char *), int len, const char *title, CWnd*pParent /*=NULL*/)
  1.1080 +	: CDialog(AddGBCode::IDD, pParent)
  1.1081 +{
  1.1082 +	//{{AFX_DATA_INIT(AddGBCode)
  1.1083 +	// NOTE: the ClassWizard will add member initialization here
  1.1084 +	//}}AFX_DATA_INIT
  1.1085 +	addVerify = verify;
  1.1086 +	addLength = len;
  1.1087 +	addTitle  = title;
  1.1088 +}
  1.1089 +
  1.1090 +void AddGBCode::DoDataExchange(CDataExchange*pDX)
  1.1091 +{
  1.1092 +	CDialog::DoDataExchange(pDX);
  1.1093 +	//{{AFX_DATA_MAP(AddGBCode)
  1.1094 +	DDX_Control(pDX, IDC_DESC, m_desc);
  1.1095 +	DDX_Control(pDX, IDC_CODE, m_code);
  1.1096 +	//}}AFX_DATA_MAP
  1.1097 +}
  1.1098 +
  1.1099 +BEGIN_MESSAGE_MAP(AddGBCode, CDialog)
  1.1100 +//{{AFX_MSG_MAP(AddGBCode)
  1.1101 +ON_BN_CLICKED(ID_OK, OnOk)
  1.1102 +ON_BN_CLICKED(ID_CANCEL, OnCancel)
  1.1103 +//}}AFX_MSG_MAP
  1.1104 +END_MESSAGE_MAP()
  1.1105 +
  1.1106 +/////////////////////////////////////////////////////////////////////////////
  1.1107 +// AddGBCode message handlers
  1.1108 +
  1.1109 +void AddGBCode::OnOk()
  1.1110 +{
  1.1111 +	CString desc;
  1.1112 +	CString buffer;
  1.1113 +	m_code.GetWindowText(buffer);
  1.1114 +	m_desc.GetWindowText(desc);
  1.1115 +
  1.1116 +	StringTokenizer st(buffer, " \t\n\r");
  1.1117 +	const char *    t = st.next();
  1.1118 +	while (t)
  1.1119 +	{
  1.1120 +		addVerify(t, desc);
  1.1121 +		t = st.next();
  1.1122 +	}
  1.1123 +	EndDialog(TRUE);
  1.1124 +}
  1.1125 +
  1.1126 +void AddGBCode::OnCancel()
  1.1127 +{
  1.1128 +	EndDialog(FALSE);
  1.1129 +}
  1.1130 +
  1.1131 +BOOL AddGBCode::OnInitDialog()
  1.1132 +{
  1.1133 +	CDialog::OnInitDialog();
  1.1134 +
  1.1135 +	m_code.LimitText(1024);
  1.1136 +	m_desc.LimitText(32);
  1.1137 +	SetWindowText(addTitle);
  1.1138 +	CenterWindow();
  1.1139 +
  1.1140 +	return TRUE; // return TRUE unless you set the focus to a control
  1.1141 +	             // EXCEPTION: OCX Property Pages should return FALSE
  1.1142 +}
  1.1143 +