tpr.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. tpr handling routines adapted from tprbuilder
  4. Copyright (C) 2002 Romain Liévin
  5. Copyright (C) 2002-2006 Kevin Kofler
  6. Copyright (C) 2006 Joey Adams
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software Foundation,
  17. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #pragma once
  20. class KUrl;
  21. #include <QString>
  22. #include <QStringList>
  23. #include <QByteArray>
  24. #include <Q3ValueVector>
  25. #include <QPair>
  26. #include <QTextCodec>
  27. /*Structure definitions from tprbuilder source; slightly modified
  28. to work under C++
  29. */
  30. typedef unsigned char Boolean;
  31. /* global enumerations */
  32. enum SectionType_ { SECTION_NONE, SECTION_SETTINGS, SECTION_LIBOPTS,
  33. SECTION_FILEEDIT, SECTION_FILES };
  34. typedef enum SectionType_ SectionType;
  35. /* definitions */
  36. typedef struct tprsettings tprSettings;
  37. struct tprsettings
  38. {
  39. tprsettings() : archive(0),pack(0),debug_info(0),std_lib(1),
  40. use_data_var(0),copy_data_var(1),copy_data_var_arc(1),
  41. optimize_nops(1),optimize_returns(1),optimize_branches(1),
  42. optimize_moves(1),optimize_tests(1),optimize_calcs(1),
  43. remove_unused(1),outputbin(0),fargo(0),flash_os(0),
  44. cut_ranges(1),reorder_sections(1),merge_constants(1),
  45. initialize_bss(1),
  46. cc_switches("-Os -Wall -W -Wwrite-strings -ffunction-sections -fdata-sections"),
  47. as_switches(""),
  48. a68k_switches("-g -t")
  49. {}
  50. Boolean archive; // we want to build an archive
  51. Boolean pack; // we want to pack the executable
  52. Boolean debug_info; // pass -g option to tigcc
  53. Boolean std_lib; // link against tigcc.a
  54. Boolean use_data_var;
  55. Boolean copy_data_var;
  56. Boolean copy_data_var_arc;
  57. Boolean optimize_nops;
  58. Boolean optimize_returns;
  59. Boolean optimize_branches;
  60. Boolean optimize_moves;
  61. Boolean optimize_tests;
  62. Boolean optimize_calcs;
  63. Boolean remove_unused;
  64. Boolean outputbin;
  65. Boolean fargo;
  66. Boolean flash_os;
  67. Boolean cut_ranges;
  68. Boolean reorder_sections;
  69. Boolean merge_constants;
  70. Boolean initialize_bss;
  71. QString pack_name;
  72. QString cc_switches;
  73. QString as_switches;
  74. QString a68k_switches;
  75. QString cmd_line;
  76. QString post_build;
  77. QString data_var;
  78. };
  79. enum tprreloctypes {
  80. RT_NONE, // None (BSS, data var)
  81. RT_DIRECT, // Direct (ROM_CALLs)
  82. RT_AMS, // AMS (relocs)
  83. RT_PRECOMP, // ROM_CALLs only: Precomputed (Optimized)
  84. RT_KERNEL, // Kernel
  85. RT_COMPRESSED, // Compressed
  86. RT_MLINK, // MLink
  87. RT_FLINE // ROM_CALLs only: F-Line
  88. };
  89. typedef enum tprreloctypes tprRelocType;
  90. typedef struct tprlibopts tprLibOpts;
  91. struct tprlibopts
  92. {
  93. tprlibopts() : use_ti89(1),use_ti92p(1),use_v200(1),opt_calc_consts(0),
  94. use_kernel(0),use_preos(0),use_minams(1),
  95. unofficial_os(0),use_fline_jumps(0),use_4b_fline_jumps(0),
  96. use_internal_fline_emu(0),use_return_value(0),
  97. enable_error_return(0),save_screen(1),opt_rom_calls(0),
  98. minams(100),reloc_format(RT_AMS),rom_call_format(RT_DIRECT),
  99. bss_ref_format(RT_KERNEL),data_ref_format(RT_KERNEL)
  100. {}
  101. Boolean use_ti89;
  102. Boolean use_ti92p;
  103. Boolean use_v200;
  104. Boolean opt_calc_consts;
  105. Boolean use_kernel;
  106. Boolean use_preos;
  107. Boolean use_minams;
  108. Boolean unofficial_os;
  109. Boolean use_fline_jumps;
  110. Boolean use_4b_fline_jumps;
  111. Boolean use_internal_fline_emu;
  112. Boolean use_return_value;
  113. Boolean enable_error_return;
  114. Boolean save_screen;
  115. Boolean opt_rom_calls;
  116. int minams;
  117. tprRelocType reloc_format;
  118. tprRelocType rom_call_format;
  119. tprRelocType bss_ref_format;
  120. tprRelocType data_ref_format;
  121. };
  122. typedef struct
  123. {
  124. QStringList path;
  125. QStringList folder;
  126. } TPRFileList;
  127. typedef struct
  128. {
  129. QString prj_name;
  130. QString open_file;
  131. tprSettings settings;
  132. tprLibOpts libopts;
  133. TPRFileList h_files;
  134. TPRFileList c_files;
  135. TPRFileList s_files;
  136. TPRFileList asm_files;
  137. TPRFileList o_files;
  138. TPRFileList a_files;
  139. TPRFileList txt_files;
  140. TPRFileList oth_files;
  141. TPRFileList quill_files;
  142. } TPRDataStruct;
  143. enum {PATH_ERROR,PATH_NOTFOUND,PATH_FILE,PATH_FOLDER}; //return types for getPathType
  144. typedef Q3ValueVector<QPair<unsigned,unsigned> > LineStartList;
  145. const char *smartAscii(const QString &s);
  146. void newSettings(tprSettings *settings,tprLibOpts *libopts);
  147. int loadTPR(const QString &fileName,TPRDataStruct *dest);
  148. QString loadFileText(const char *fileName);
  149. int peekFirstChar(const char *fileName);
  150. int saveTPR(const QString &fileName,TPRDataStruct *src);
  151. void mkdir_multi(const char *fileName);
  152. int saveAndSplitFileText(const char *fileName, const QString &fileText,
  153. bool split, bool addCLineDirective,
  154. bool addASMLineDirective, const QString &origFileName,
  155. LineStartList *pLineStartList);
  156. void kurlNewFileName(KUrl &dir,const QString &newFileName);
  157. int checkFileName(const QString &fileName,const QStringList &fileNameList);
  158. int copyFile(const char *src, const char *dest);
  159. bool moveFile(const QString &src, const QString &dest);
  160. int insertName(const char *src, const char *dest, const char *name);
  161. int getPathType(const QString &thePath);
  162. QStringList process_libopts(void);
  163. QStringList process_settings(const QString &prjNameUnicode,
  164. QByteArray &projectName, QByteArray &dataVarName,
  165. QByteArray &packFolder, QByteArray &packName);
  166. class TiconvTextCodec : public QTextCodec {
  167. public:
  168. static TiconvTextCodec *instance;
  169. TiconvTextCodec() : QTextCodec() {instance=this;}
  170. virtual QByteArray name() const {return "TI-89";}
  171. virtual int mibEnum() const {return 0x71C0;}
  172. protected:
  173. virtual QByteArray convertFromUnicode(const QChar *input, int number, ConverterState *state) const;
  174. virtual QString convertToUnicode(const char *chars, int len, ConverterState *state) const;
  175. };