PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/ewi4000spatch.cpp

http://ewitool.googlecode.com/
C++ | 85 lines | 44 code | 14 blank | 27 comment | 5 complexity | 8597c3bacec1ad027e93d59c5a507a7a MD5 | raw file
 1/***************************************************************************
 2 *   Copyright (C) 2008 by Steve Merrony   *
 3 *   steve@brahma   *
 4 *                                                                         *
 5 *   This program is free software; you can redistribute it and/or modify  *
 6 *   it under the terms of the GNU General Public License as published by  *
 7 *   the Free Software Foundation; either version 3 of the License, or     *
 8 *   (at your option) any later version.                                   *
 9 *                                                                         *
10 *   This program is distributed in the hope that it will be useful,       *
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13 *   GNU General Public License for more details.                          *
14 *                                                                         *
15 *   You should have received a copy of the GNU General Public License     *
16 *   along with this program; if not, write to the                         *
17 *   Free Software Foundation, Inc.,                                       *
18 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19 ***************************************************************************/
20#include "ewi4000spatch.h"
21
22ewi4000sPatch::ewi4000sPatch()
23{
24}
25
26
27ewi4000sPatch::~ewi4000sPatch()
28{
29}
30
31QString ewi4000sPatch::toQString( char *rawName ) {
32	// utility function to get a nicely formatted patch name
33	QString sname = rawName;
34	sname.truncate( EWI_PATCHNAME_LENGTH );
35	return sname.trimmed();
36}
37
38/**
39 * Returns a human-readable Hex interpretation of the passed patch.
40 * @param bin_patch 
41 * @param with_spaces 
42 * @return 
43 */
44QString ewi4000sPatch::hexify( char *bin_patch, bool with_spaces ) {
45	
46	QString hex_patch = "";
47	QString format;
48	int dlen;
49	
50	if (with_spaces) {
51		format = "%1 ";
52		dlen = 3;
53	}
54	else {
55		format = "%1";
56		dlen = 2;
57	}
58	for ( int i = 0; i < EWI_PATCH_LENGTH; i++ ) {
59		hex_patch += QString( format ).arg( (uint) bin_patch[i], 2, 16, QChar( '0' ) ).right( dlen );
60	}
61	//cout << "Hexified patch: " << qPrintable( hex_patch ) << endl;
62	return hex_patch;
63}
64
65
66patch_t ewi4000sPatch::dehexify( QString hex_patch, bool with_spaces ) {
67	
68	patch_t dehexed;
69	QString onebyte;
70	bool ok;
71	int  bwidth;
72	
73	if (with_spaces)
74		bwidth = 3;
75	else
76		bwidth = 2;
77	
78	for ( int i = 0; i < EWI_PATCH_LENGTH; i++ ) {
79		onebyte = hex_patch.mid( i * bwidth, 2 );
80		dehexed.whole_patch[i] = onebyte.toInt( &ok, 16 );
81	}
82	
83	return dehexed;
84}
85