main.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * GTC source file explorer
  3. */
  4. #if defined(_89)||defined(_92)
  5. #define BATCH_COMPILE
  6. #endif
  7. #define TITLEBAR
  8. //#define OPTIMIZE_ROM_CALLS
  9. //#define USE_KERNEL
  10. #define ONE_CALC
  11. #ifndef USE_KERNEL
  12. #define SAVE_SCREEN
  13. #endif
  14. #ifdef BATCH_COMPILE
  15. #define RELEASE
  16. #else
  17. //#define RELEASE
  18. /*#define _ONE_CALC_ONLY
  19. #define _92_ONLY*/
  20. #define PEDROM
  21. //#define _89
  22. #endif
  23. #if defined(_89)&&defined(_92)
  24. #error oops, both models specified...
  25. #endif
  26. #ifdef _89
  27. #define USE_TI89
  28. #define X 160
  29. #define Y 100
  30. #define q89(x,y) (x)
  31. #else
  32. #define USE_TI92PLUS
  33. #define USE_V200
  34. #define X 240
  35. #define Y 128
  36. #define q89(x,y) (y)
  37. #endif
  38. #ifdef RELEASE
  39. #define NDEBUG
  40. #endif
  41. #ifndef PEDROM
  42. #define MIN_AMS 205
  43. #else
  44. #define MIN_AMS 101
  45. #endif
  46. #include <tigcclib.h>
  47. //#include <kernel.h>
  48. #include <extgraph.h>
  49. #define GTC_IDE
  50. typedef unsigned long TI_LONG;
  51. typedef unsigned short TI_SHORT;
  52. #ifdef USE_ABSOLUTE_PATHS
  53. #include "E:\Paul\89\_Projex\GtC\pch.h"
  54. #include "E:\Paul\89\Ti-GCC\Projects\Gt-Dev\apphdr.h"
  55. #include "E:\Paul\89\Ti-GCC\Projects\Gt-Dev\SecureComm.h"
  56. #include "E:\Paul\89\Ti-GCC\Projects\Gt-Dev\Plugins.h"
  57. #else
  58. #include "pch.h"
  59. #include "gtdev-apphdr.h"
  60. #include "gtdev-securecomm.h"
  61. #include "gtdev-plugins.h"
  62. #endif
  63. /*#undef ST_flags
  64. #define ST_flags _ROM_CALL_443
  65. extern unsigned long ST_flags;*/
  66. void *kbdq=0;
  67. //#define ST_flags (*(unsigned long *)_rom_call_addr(443))
  68. //#define ST_flagsL ((unsigned int)ST_flags)
  69. #ifndef PEDROM
  70. #define ST_flagsL (*(unsigned int *)(_rom_call_addr(443)+2))
  71. #else
  72. unsigned int ST_flagsL=0;
  73. #endif
  74. char sUnpackBuf[500];
  75. #ifndef ONE_CALC
  76. int calc=0;
  77. void init_calc() {
  78. calc=CALCULATOR;
  79. }
  80. #endif
  81. #undef CALCULATOR
  82. #ifdef _89
  83. #define CALCULATOR 0
  84. #define _89_92(x,y) (x)
  85. #else
  86. #define CALCULATOR 1
  87. #define _89_92(x,y) (y)
  88. #endif
  89. #define HD2
  90. #include "Util.h"
  91. #include "PchUtil.h"
  92. #include "Display.h"
  93. #include "Edit.h"
  94. #include "Handlers.h"
  95. #include "EditUI.h"
  96. #include "Plugins.h"
  97. #include "Editor.h"
  98. #include "autoint_fix.h"
  99. char _ti89[0],_ti92plus[0];
  100. void memquit() {
  101. ST_helpMsg("Not enough memory!");
  102. ngetchx();
  103. }
  104. #if 0
  105. void _main(void) {
  106. ESI ap;
  107. char *fold=(char *)$(source);
  108. // int X=LCD_WIDTH,Y=LCD_HEIGHT;
  109. char *port;
  110. char b[50];
  111. int key,sel=0;
  112. if (AMS_1xx) {
  113. ST_showHelp("Works only on AMS 2.0x");
  114. ngetchx();
  115. return;
  116. }
  117. kbdq=kbd_queue();
  118. #ifndef ONE_CALC
  119. init_calc();
  120. #endif
  121. /*#undef AMS_2xx
  122. #define AMS_2xx 1
  123. if (AMS_2xx) ST_flags &= ~(0x100000);*/
  124. InitArgPtr(ap);
  125. if (GetArgType(ap) == STR_TAG) {
  126. fold=(char *)GetSymstrArg(ap);
  127. }
  128. if (GetArgType(ap) != END_TAG) {
  129. ST_helpMsg("Syntax: explore(\"folder\")");
  130. ngetchx();
  131. return;
  132. }
  133. if (!SymFindHome(fold).folder) {
  134. int ok=1; char c,*p=fold;
  135. while ((c=*--p)) if (!(c=='_' || c>='a' || c<='z' || c>='0' || c<='9')) ok=0;
  136. if (ok)
  137. ok=FolderAdd(fold);
  138. if (!ok) {
  139. ST_helpMsg("Invalid folder name");
  140. ngetchx();
  141. return;
  142. }
  143. }
  144. if (!(port=malloc(LCD_SIZE))) { memquit(); return; }
  145. do {
  146. char *data=malloc(400*9);
  147. SYM_ENTRY *SymPtr;
  148. int but[5];
  149. int n=0,i,st,M;
  150. void __attribute__((stkparm)) Button(int i,char *t) {
  151. int x=i*32; char b[100];
  152. but[i]=1;
  153. sprintf(b,"F%d %s",i+1,t);
  154. DrawLine(x+2,Y-9,x+31-2,Y-9,A_NORMAL);
  155. DrawLine(x,Y-7,x,Y-1,A_NORMAL);
  156. DrawLine(x+31,Y-7,x+31,Y-1,A_NORMAL);
  157. DrawPix(x+1,Y-8,A_NORMAL);
  158. DrawPix(x+31-1,Y-8,A_NORMAL);
  159. DrawStr(x+2,Y-7,b,A_NORMAL);
  160. }
  161. if (!data) { memquit(); break; }
  162. #define name(x) data+((x)+((x)<<3))
  163. SymPtr = SymFindFirst(fold,1);
  164. while (SymPtr) {
  165. if (SymPtr->handle) {
  166. unsigned int *p=HLock(SymPtr->handle);
  167. if (((unsigned char *)p)[*p+1]==TEXT_TAG)
  168. strcpy(name(n), SymPtr->name), n++;
  169. HeapUnlock(SymPtr->handle);
  170. }
  171. SymPtr = SymFindNext();
  172. }
  173. PortSet(port,239,127);
  174. ClrScr();
  175. DrawLine(1,0,X-2,0,A_NORMAL);
  176. DrawLine(0,Y-1,X-1,Y-1,A_NORMAL);
  177. DrawLine(0,1,0,Y-1,A_NORMAL);
  178. DrawLine(X-1,1,X-1,Y-1,A_NORMAL);
  179. memset(but,0,5*2);
  180. FontSetSys(0);
  181. Button(0,"New");
  182. if (n) {
  183. Button(1,"Setup");
  184. Button(2,"Build");
  185. Button(3,"Run");
  186. }
  187. Button(4,"About");
  188. /* 89 : 11 files / 92+/V200 : 14 files */
  189. FontSetSys(1);
  190. M=CALCULATOR?14:11;
  191. st=sel-(M+1)/2;
  192. if (st>n-M) st=n-M;
  193. if (st<0) st=0;
  194. for (i=0;i<M;i++) {
  195. if (st+i>=n) break;
  196. if (i==sel-st) {
  197. SCR_RECT rect={{3,(i<<3)+1,X-3,(i<<3)+9}};
  198. ScrRectFill(&rect,ScrRect,A_NORMAL);
  199. }
  200. DrawStr(3,(i<<3)+2,name(st+i),A_XOR);
  201. }
  202. PortRestore();
  203. LCD_restore(port);
  204. key=ngetchx();
  205. if (key==(int)KEY_UP) sel--;
  206. else if (key==(int)KEY_DOWN) sel++;
  207. else if ((i=key-KEY_F1)>=0 && i<5 && but[i]) {
  208. if (i==0) {
  209. char buffer[21] = {0};
  210. HANDLE handle = DialogNewSimple (140, 55);
  211. DialogAddTitle(handle, "NEW PROJECT", BT_OK, BT_CANCEL);
  212. DialogAddText(handle, 3, 20, "Follow the steps to create a new program");
  213. DialogAddRequest(handle, 3, 30, "Program name :", 6, 20, 14);
  214. DialogAddText(handle, 3, 40, "Program type :");
  215. if (DialogDo(handle, CENTER, CENTER, buffer, NULL) == KEY_ENTER)
  216. DlgMessage("GREETINGS", buffer, BT_OK, BT_NONE);
  217. } else if (i==4) {
  218. ST_flags &= ~(0x100000);
  219. DlgMessage("ABOUT GTC",
  220. "\n GTC C Compiler & IDE\n\n(c) 2001-2002 by Paul Froissart\n",
  221. BT_OK,BT_NONE);
  222. ST_flags |= 0x100000;
  223. }
  224. } else if (key==KEY_ENTER) {
  225. char *p=fold;
  226. while (*--p);
  227. *b=0;
  228. sprintf(b+1,"%s\\%s",p+1,name(sel));
  229. free(port);
  230. Edit(b+1+strlen(b+1),b+1+strlen(p+1)+1);
  231. port=malloc(LCD_SIZE);
  232. }
  233. if (sel>=n) sel-=n;
  234. if (sel<0) sel+=n;
  235. free(data);
  236. } while (key!=264);
  237. free(port);
  238. // if (AMS_2xx) ST_flags |= 0x100000;
  239. }
  240. #else
  241. void _main(void) {
  242. #ifndef PEDROM
  243. if (AMS_1xx) {
  244. ST_helpMsg("Please upgrade to AMS 2.0x");
  245. ngetchx();
  246. return;
  247. }
  248. #endif
  249. kbdq=kbd_queue();
  250. #ifndef ONE_CALC
  251. init_calc();
  252. #endif
  253. ESI ap;
  254. char cfold[20]; strcpy(cfold,"source");
  255. InitArgPtr(ap);
  256. if (GetArgType(ap) == STR_TAG) {
  257. strcpy(cfold,GetStrnArg(ap));
  258. }
  259. FixAutoint();
  260. while (1) {
  261. Port=malloc(LCD_SIZE);
  262. if (!Port) return;
  263. PortSet(Port,239,127);
  264. ClrScr();
  265. XP_C *xc=XpLoadFat(cfold);
  266. if (!xc) break;
  267. XP_S *xs=XpLoop(xc,8,std_callback,NULL);
  268. if (!xs) { free(xc); break; }
  269. char file[20]; strcpy(file,(char *)xs->d);
  270. while (xs->t!=1) xs--;
  271. char fold[20]; strcpy(fold,(char *)xs->d);
  272. strcpy(cfold,fold);
  273. free(xc);
  274. PortRestore();
  275. free(Port);
  276. #if 0
  277. char b[100];
  278. *b=0;
  279. sprintf(b+1,"%s\\%s",fold,file);
  280. Edit(b+1+strlen(b+1),file);
  281. #else
  282. char path[8+1+8+1];
  283. sprintf(path,"%.8s\\%.8s",fold,file);
  284. Edit(path);
  285. #endif
  286. }
  287. RestoreAutoint();
  288. PortRestore();
  289. free(Port);
  290. }
  291. #endif