/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. ewi4000sPatch::ewi4000sPatch()
  22. {
  23. }
  24. ewi4000sPatch::~ewi4000sPatch()
  25. {
  26. }
  27. QString ewi4000sPatch::toQString( char *rawName ) {
  28. // utility function to get a nicely formatted patch name
  29. QString sname = rawName;
  30. sname.truncate( EWI_PATCHNAME_LENGTH );
  31. return sname.trimmed();
  32. }
  33. /**
  34. * Returns a human-readable Hex interpretation of the passed patch.
  35. * @param bin_patch
  36. * @param with_spaces
  37. * @return
  38. */
  39. QString ewi4000sPatch::hexify( char *bin_patch, bool with_spaces ) {
  40. QString hex_patch = "";
  41. QString format;
  42. int dlen;
  43. if (with_spaces) {
  44. format = "%1 ";
  45. dlen = 3;
  46. }
  47. else {
  48. format = "%1";
  49. dlen = 2;
  50. }
  51. for ( int i = 0; i < EWI_PATCH_LENGTH; i++ ) {
  52. hex_patch += QString( format ).arg( (uint) bin_patch[i], 2, 16, QChar( '0' ) ).right( dlen );
  53. }
  54. //cout << "Hexified patch: " << qPrintable( hex_patch ) << endl;
  55. return hex_patch;
  56. }
  57. patch_t ewi4000sPatch::dehexify( QString hex_patch, bool with_spaces ) {
  58. patch_t dehexed;
  59. QString onebyte;
  60. bool ok;
  61. int bwidth;
  62. if (with_spaces)
  63. bwidth = 3;
  64. else
  65. bwidth = 2;
  66. for ( int i = 0; i < EWI_PATCH_LENGTH; i++ ) {
  67. onebyte = hex_patch.mid( i * bwidth, 2 );
  68. dehexed.whole_patch[i] = onebyte.toInt( &ok, 16 );
  69. }
  70. return dehexed;
  71. }