y_debug.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. #if defined _INC_y_debug
  2. #endinput
  3. #endif
  4. #define _INC_y_debug
  5. /**
  6. * <library name="y_debug">
  7. * <section>
  8. * Description
  9. * </section>
  10. * <p>Ensures debug levels are set and defines debug functions.</p>
  11. *
  12. * <p>General debug levels:</p>
  13. *
  14. * <ul>
  15. * <li>-1 - Run-time selected debug level.</li>
  16. * <li>0 - No debug information.</li>
  17. * <li>1 - Callbacks and timers.</li>
  18. * <li>2 - Remote functions.</li>
  19. * <li>3 - Stock functions.</li>
  20. * <li>4 - Static functions.</li>
  21. * <li>5 - Code.</li>
  22. * <li>6 - Loops.</li>
  23. * <li>7 - Extra loop code.</li>
  24. * </ul>
  25. *
  26. * <p>If you use <c>P:0</c> you get an optional debug print controlled by the
  27. * global state <c>ysi_debug</c> - which is either on or off.</p>
  28. * <section>
  29. * Version
  30. * </section>
  31. * 1.0
  32. * <section>
  33. * Functions
  34. * </section>
  35. * <subsection>
  36. * Inline
  37. * </subsection><ul>
  38. * <symbol name="Debug_Code">Runs defined code if a certain level is active.</symbol>
  39. * <symbol name="Debug_Print">Prints the formatted string provided at the given level.</symbol>
  40. * </ul><subsection>
  41. * Stock
  42. * </subsection><ul>
  43. * <symbol name="Debug_PrintArray">Print several items from an array for debugging purposes.</symbol>
  44. * <symbol name="Debug_Enable">Turn on level 0 prints.</symbol>
  45. * <symbol name="Debug_Disable">Turn off level 0 prints.</symbol>
  46. * <symbol name="Debug_Level">Set the debug level when the code is compiled with
  47. * <c>_DEBUG=-1</c>, which means full run-time selection.</symbol>
  48. * </ul><section>
  49. * Definitions
  50. * </section><ul>
  51. * <symbol name="P:&lt;0-6&gt;">Print a message.</symbol>
  52. * <symbol name="P:C">Run debug code.</symbol>
  53. * <symbol name="P:E">Print an error message.</symbol>
  54. * <symbol name="P:W">Print a warning message.</symbol>
  55. * </ul><section>Compile options</section><ul>
  56. * <symbol name="_DEBUG">Debugging level to use.</symbol>
  57. * </ul>
  58. * </library>
  59. *//** *//*
  60. Legal:
  61. Version: MPL 1.1
  62. The contents of this file are subject to the Mozilla Public License Version
  63. 1.1 the "License"; you may not use this file except in compliance with
  64. the License. You may obtain a copy of the License at
  65. http://www.mozilla.org/MPL/
  66. Software distributed under the License is distributed on an "AS IS" basis,
  67. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  68. for the specific language governing rights and limitations under the
  69. License.
  70. The Original Code is the YSI framework.
  71. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  72. Portions created by the Initial Developer are Copyright C 2011
  73. the Initial Developer. All Rights Reserved.
  74. Contributors:
  75. Y_Less
  76. koolk
  77. JoeBullet/Google63
  78. g_aSlice/Slice
  79. Misiur
  80. samphunter
  81. tianmeta
  82. maddinat0r
  83. spacemud
  84. Crayder
  85. Dayvison
  86. Ahmad45123
  87. Zeex
  88. irinel1996
  89. Yiin-
  90. Chaprnks
  91. Konstantinos
  92. Masterchen09
  93. Southclaws
  94. PatchwerkQWER
  95. m0k1
  96. paulommu
  97. udan111
  98. Thanks:
  99. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  100. ZeeX - Very productive conversations.
  101. koolk - IsPlayerinAreaEx code.
  102. TheAlpha - Danish translation.
  103. breadfish - German translation.
  104. Fireburn - Dutch translation.
  105. yom - French translation.
  106. 50p - Polish translation.
  107. Zamaroht - Spanish translation.
  108. Los - Portuguese translation.
  109. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  110. me to strive to better.
  111. Pixels^ - Running XScripters where the idea was born.
  112. Matite - Pestering me to release it and using it.
  113. Very special thanks to:
  114. Thiadmer - PAWN, whose limits continue to amaze me!
  115. Kye/Kalcor - SA:MP.
  116. SA:MP Team past, present and future - SA:MP.
  117. Optional plugins:
  118. Gamer_Z - GPS.
  119. Incognito - Streamer.
  120. Me - sscanf2, fixes2, Whirlpool.
  121. *//*-------------------------------------------------------------------------**/
  122. #include "..\YSI_Internal\y_compilerdata"
  123. #include "..\YSI_Internal\y_globaltags"
  124. #include "..\YSI_Internal\y_version"
  125. #include "..\YSI_Internal\y_funcinc"
  126. #include "..\YSI_Server\y_scriptinit"
  127. #if !defined _DEBUG
  128. #define _DEBUG 0
  129. #endif
  130. stock YSI_gDebugLevel = 0;
  131. #define P:%1(%2); Debug_Print%1(%2);
  132. #define C:%1(%2); Debug_Code%1(%2);
  133. /*-------------------------------------------------------------------------*//**
  134. * <param name="code">Code to run.</param>
  135. * <remarks>
  136. * Code is not a variable, it's a code chunk and may be written as so:
  137. *
  138. * <code>
  139. * Debug_Code1(if (bla == 2) { bla++; printf("%d", bla); });
  140. * </code>
  141. *
  142. * Or:
  143. *
  144. * <code>
  145. * C:1(if (bla == 2) { bla++; printf("%d", bla); });
  146. * </code>
  147. *
  148. * The code must all be on one line to avoid errors.
  149. * This isn't really a function as the first parameter is part of the name.
  150. *
  151. * Only compiles the code when <c>_DEBUG %gt;= 1</c>.
  152. *
  153. * </remarks>
  154. *//*------------------------------------------------------------------------**/
  155. P:D(Debug_Code1(code));
  156. /*-------------------------------------------------------------------------*//**
  157. * <param name="code">Code to run.</param>
  158. * <remarks>
  159. * Code is not a variable, it's a code chunk and may be written as so:
  160. *
  161. * <code>
  162. * Debug_Code2(if (bla == 2) { bla++; printf("%d", bla); });
  163. * </code>
  164. *
  165. * Or:
  166. *
  167. * <code>
  168. * C:2(if (bla == 2) { bla++; printf("%d", bla); });
  169. * </code>
  170. *
  171. * The code must all be on one line to avoid errors.
  172. * This isn't really a function as the first parameter is part of the name.
  173. *
  174. * Only compiles the code when <c>_DEBUG %gt;= 2</c>.
  175. *
  176. * </remarks>
  177. *//*------------------------------------------------------------------------**/
  178. P:D(Debug_Code2(code));
  179. /*-------------------------------------------------------------------------*//**
  180. * <param name="code">Code to run.</param>
  181. * <remarks>
  182. * Code is not a variable, it's a code chunk and may be written as so:
  183. *
  184. * <code>
  185. * Debug_Code3(if (bla == 2) { bla++; printf("%d", bla); });
  186. * </code>
  187. *
  188. * Or:
  189. *
  190. * <code>
  191. * C:3(if (bla == 2) { bla++; printf("%d", bla); });
  192. * </code>
  193. *
  194. * The code must all be on one line to avoid errors.
  195. * This isn't really a function as the first parameter is part of the name.
  196. *
  197. * Only compiles the code when <c>_DEBUG %gt;= 3</c>.
  198. *
  199. * </remarks>
  200. *//*------------------------------------------------------------------------**/
  201. P:D(Debug_Code3(code));
  202. /*-------------------------------------------------------------------------*//**
  203. * <param name="code">Code to run.</param>
  204. * <remarks>
  205. * Code is not a variable, it's a code chunk and may be written as so:
  206. *
  207. * <code>
  208. * Debug_Code4(if (bla == 2) { bla++; printf("%d", bla); });
  209. * </code>
  210. *
  211. * Or:
  212. *
  213. * <code>
  214. * C:4(if (bla == 2) { bla++; printf("%d", bla); });
  215. * </code>
  216. *
  217. * The code must all be on one line to avoid errors.
  218. * This isn't really a function as the first parameter is part of the name.
  219. *
  220. * Only compiles the code when <c>_DEBUG %gt;= 4</c>.
  221. *
  222. * </remarks>
  223. *//*------------------------------------------------------------------------**/
  224. P:D(Debug_Code4(code));
  225. /*-------------------------------------------------------------------------*//**
  226. * <param name="code">Code to run.</param>
  227. * <remarks>
  228. * Code is not a variable, it's a code chunk and may be written as so:
  229. *
  230. * <code>
  231. * Debug_Code5(if (bla == 2) { bla++; printf("%d", bla); });
  232. * </code>
  233. *
  234. * Or:
  235. *
  236. * <code>
  237. * C:5(if (bla == 2) { bla++; printf("%d", bla); });
  238. * </code>
  239. *
  240. * The code must all be on one line to avoid errors.
  241. * This isn't really a function as the first parameter is part of the name.
  242. *
  243. * Only compiles the code when <c>_DEBUG %gt;= 5</c>.
  244. *
  245. * </remarks>
  246. *//*------------------------------------------------------------------------**/
  247. P:D(Debug_Code5(code));
  248. /*-------------------------------------------------------------------------*//**
  249. * <param name="code">Code to run.</param>
  250. * <remarks>
  251. * Code is not a variable, it's a code chunk and may be written as so:
  252. *
  253. * <code>
  254. * Debug_Code6(if (bla == 2) { bla++; printf("%d", bla); });
  255. * </code>
  256. *
  257. * Or:
  258. *
  259. * <code>
  260. * C:6(if (bla == 2) { bla++; printf("%d", bla); });
  261. * </code>
  262. *
  263. * The code must all be on one line to avoid errors.
  264. * This isn't really a function as the first parameter is part of the name.
  265. *
  266. * Only compiles the code when <c>_DEBUG %gt;= 6</c>.
  267. *
  268. * </remarks>
  269. *//*------------------------------------------------------------------------**/
  270. P:D(Debug_Code6(code));
  271. /*-------------------------------------------------------------------------*//**
  272. * <param name="code">Code to run.</param>
  273. * <remarks>
  274. * Code is not a variable, it's a code chunk and may be written as so:
  275. *
  276. * <code>
  277. * Debug_Code7(if (bla == 2) { bla++; printf("%d", bla); });
  278. * </code>
  279. *
  280. * Or:
  281. *
  282. * <code>
  283. * C:7(if (bla == 2) { bla++; printf("%d", bla); });
  284. * </code>
  285. *
  286. * The code must all be on one line to avoid errors.
  287. * This isn't really a function as the first parameter is part of the name.
  288. *
  289. * Only compiles the code when <c>_DEBUG %gt;= 7</c>.
  290. *
  291. * </remarks>
  292. *//*------------------------------------------------------------------------**/
  293. P:D(Debug_Code7(code));
  294. #if _DEBUG == -1
  295. #define Debug_Code1(%1); { if (YSI_gDebugLevel >= 1) { %1 }}
  296. #define Debug_Code2(%1); { if (YSI_gDebugLevel >= 2) { %1 }}
  297. #define Debug_Code3(%1); { if (YSI_gDebugLevel >= 3) { %1 }}
  298. #define Debug_Code4(%1); { if (YSI_gDebugLevel >= 4) { %1 }}
  299. #define Debug_Code5(%1); { if (YSI_gDebugLevel >= 5) { %1 }}
  300. #define Debug_Code6(%1); { if (YSI_gDebugLevel >= 6) { %1 }}
  301. #define Debug_Code7(%1); { if (YSI_gDebugLevel >= 7) { %1 }}
  302. #else
  303. #if _DEBUG >= 1
  304. #define Debug_Code1(%1); %1
  305. #else
  306. #define Debug_Code1(%1);
  307. #endif
  308. #if _DEBUG >= 2
  309. #define Debug_Code2(%1); %1
  310. #else
  311. #define Debug_Code2(%1);
  312. #endif
  313. #if _DEBUG >= 3
  314. #define Debug_Code3(%1); %1
  315. #else
  316. #define Debug_Code3(%1);
  317. #endif
  318. #if _DEBUG >= 4
  319. #define Debug_Code4(%1); %1
  320. #else
  321. #define Debug_Code4(%1);
  322. #endif
  323. #if _DEBUG >= 5
  324. #define Debug_Code5(%1); %1
  325. #else
  326. #define Debug_Code5(%1);
  327. #endif
  328. #if _DEBUG >= 6
  329. #define Debug_Code6(%1); %1
  330. #else
  331. #define Debug_Code6(%1);
  332. #endif
  333. #if _DEBUG >= 7
  334. #define Debug_Code7(%1); %1
  335. #else
  336. #define Debug_Code7(%1);
  337. #endif
  338. #endif
  339. #if _DEBUG != 0
  340. #define Debug_CodeX(%1); %1
  341. #else
  342. #define Debug_CodeX(%1);
  343. #endif
  344. /*-------------------------------------------------------------------------*//**
  345. * <param name="str">Format.</param>
  346. * <param name=""></param>
  347. * <remarks>
  348. * This isn't really a function as the first parameter is part of the name:
  349. *
  350. * <code>
  351. * Debug_Print1("variables: %d, %d", i, j);
  352. * </code>
  353. *
  354. * Or:
  355. *
  356. * <code>
  357. * P:1("variables: %d, %d", i, j);
  358. * </code>
  359. *
  360. * Only prints the data when <c>_DEBUG %gt;= 1</c>.
  361. *
  362. * </remarks>
  363. *//*------------------------------------------------------------------------**/
  364. P:D(Debug_Print1(const str[], GLOBAL_TAG_TYPES:...));
  365. /*-------------------------------------------------------------------------*//**
  366. * <param name="str">Format.</param>
  367. * <param name=""></param>
  368. * <remarks>
  369. * This isn't really a function as the first parameter is part of the name:
  370. *
  371. * <code>
  372. * Debug_Print2("variables: %d, %d", i, j);
  373. * </code>
  374. *
  375. * Or:
  376. *
  377. * <code>
  378. * P:2("variables: %d, %d", i, j);
  379. * </code>
  380. *
  381. * Only prints the data when <c>_DEBUG %gt;= 2</c>.
  382. *
  383. * </remarks>
  384. *//*------------------------------------------------------------------------**/
  385. P:D(Debug_Print2(const str[], GLOBAL_TAG_TYPES:...));
  386. /*-------------------------------------------------------------------------*//**
  387. * <param name="str">Format.</param>
  388. * <param name=""></param>
  389. * <remarks>
  390. * This isn't really a function as the first parameter is part of the name:
  391. *
  392. * <code>
  393. * Debug_Print3("variables: %d, %d", i, j);
  394. * </code>
  395. *
  396. * Or:
  397. *
  398. * <code>
  399. * P:3("variables: %d, %d", i, j);
  400. * </code>
  401. *
  402. * Only prints the data when <c>_DEBUG %gt;= 3</c>.
  403. *
  404. * </remarks>
  405. *//*------------------------------------------------------------------------**/
  406. P:D(Debug_Print3(const str[], GLOBAL_TAG_TYPES:...));
  407. /*-------------------------------------------------------------------------*//**
  408. * <param name="str">Format.</param>
  409. * <param name=""></param>
  410. * <remarks>
  411. * This isn't really a function as the first parameter is part of the name:
  412. *
  413. * <code>
  414. * Debug_Print4("variables: %d, %d", i, j);
  415. * </code>
  416. *
  417. * Or:
  418. *
  419. * <code>
  420. * P:4("variables: %d, %d", i, j);
  421. * </code>
  422. *
  423. * Only prints the data when <c>_DEBUG %gt;= 4</c>.
  424. *
  425. * </remarks>
  426. *//*------------------------------------------------------------------------**/
  427. P:D(Debug_Print4(const str[], GLOBAL_TAG_TYPES:...));
  428. /*-------------------------------------------------------------------------*//**
  429. * <param name="str">Format.</param>
  430. * <param name=""></param>
  431. * <remarks>
  432. * This isn't really a function as the first parameter is part of the name:
  433. *
  434. * <code>
  435. * Debug_Print5("variables: %d, %d", i, j);
  436. * </code>
  437. *
  438. * Or:
  439. *
  440. * <code>
  441. * P:5("variables: %d, %d", i, j);
  442. * </code>
  443. *
  444. * Only prints the data when <c>_DEBUG %gt;= 5</c>.
  445. *
  446. * </remarks>
  447. *//*------------------------------------------------------------------------**/
  448. P:D(Debug_Print5(const str[], GLOBAL_TAG_TYPES:...));
  449. /*-------------------------------------------------------------------------*//**
  450. * <param name="str">Format.</param>
  451. * <param name=""></param>
  452. * <remarks>
  453. * This isn't really a function as the first parameter is part of the name:
  454. *
  455. * <code>
  456. * Debug_Print6("variables: %d, %d", i, j);
  457. * </code>
  458. *
  459. * Or:
  460. *
  461. * <code>
  462. * P:6("variables: %d, %d", i, j);
  463. * </code>
  464. *
  465. * Only prints the data when <c>_DEBUG %gt;= 6</c>.
  466. *
  467. * </remarks>
  468. *//*------------------------------------------------------------------------**/
  469. P:D(Debug_Print6(const str[], GLOBAL_TAG_TYPES:...));
  470. /*-------------------------------------------------------------------------*//**
  471. * <param name="str">Format.</param>
  472. * <param name=""></param>
  473. * <remarks>
  474. * This isn't really a function as the first parameter is part of the name:
  475. *
  476. * <code>
  477. * Debug_Print7("variables: %d, %d", i, j);
  478. * </code>
  479. *
  480. * Or:
  481. *
  482. * <code>
  483. * P:7("variables: %d, %d", i, j);
  484. * </code>
  485. *
  486. * Only prints the data when <c>_DEBUG %gt;= 7</c>.
  487. *
  488. * </remarks>
  489. *//*------------------------------------------------------------------------**/
  490. P:D(Debug_Print7(const str[], GLOBAL_TAG_TYPES:...));
  491. #if _DEBUG == -1
  492. #define Debug_Print1(%1); { if (YSI_gDebugLevel >= 1) printf(%1); }
  493. #define Debug_Print2(%1); { if (YSI_gDebugLevel >= 2) printf(%1); }
  494. #define Debug_Print3(%1); { if (YSI_gDebugLevel >= 3) printf(%1); }
  495. #define Debug_Print4(%1); { if (YSI_gDebugLevel >= 4) printf(%1); }
  496. #define Debug_Print5(%1); { if (YSI_gDebugLevel >= 5) printf(%1); }
  497. #define Debug_Print6(%1); { if (YSI_gDebugLevel >= 6) printf(%1); }
  498. #define Debug_Print7(%1); { if (YSI_gDebugLevel >= 7) printf(%1); }
  499. #else
  500. #if _DEBUG >= 1
  501. #define Debug_Print1(%1); printf(%1);
  502. #else
  503. #define Debug_Print1(%1);
  504. #endif
  505. #if _DEBUG >= 2
  506. #define Debug_Print2(%1); printf(%1);
  507. #else
  508. #define Debug_Print2(%1);
  509. #endif
  510. #if _DEBUG >= 3
  511. #define Debug_Print3(%1); printf(%1);
  512. #else
  513. #define Debug_Print3(%1);
  514. #endif
  515. #if _DEBUG >= 4
  516. #define Debug_Print4(%1); printf(%1);
  517. #else
  518. #define Debug_Print4(%1);
  519. #endif
  520. #if _DEBUG >= 5
  521. #define Debug_Print5(%1); printf(%1);
  522. #else
  523. #define Debug_Print5(%1);
  524. #endif
  525. #if _DEBUG >= 6
  526. #define Debug_Print6(%1); printf(%1);
  527. #else
  528. #define Debug_Print6(%1);
  529. #endif
  530. #if _DEBUG >= 7
  531. #define Debug_Print7(%1); printf(%1);
  532. #else
  533. #define Debug_Print7(%1);
  534. #endif
  535. #endif
  536. #define Debug_PrintE(%1); \
  537. Debug_Print0("\7\7\7*** YSI Error: " #%1);
  538. #define Debug_PrintW(%1); \
  539. Debug_Print0("\7*** YSI Warning: " #%1);
  540. #define Debug_PrintI(%1); \
  541. Debug_Print0("*** YSI Info: " #%1);
  542. #define Debug_PrintF(%1); \
  543. Debug_Print0("\7\7\7\7\7*** YSI Fatal Error: " #%1);
  544. #define Debug_PrintC(%1); \
  545. Debug_CodeX(%1);
  546. /*-------------------------------------------------------------------------*//**
  547. * <param name="format">str.</param>
  548. * <param name=""></param>
  549. * <remarks>
  550. * This isn't really a function as the first parameter is part of the name:
  551. *
  552. * <code>
  553. * Debug_Print0("variables: %d, %d", i, j);
  554. * </code>
  555. *
  556. * Or:
  557. *
  558. * <code>
  559. * P:0("variables: %d, %d", i, j);
  560. * </code>
  561. *
  562. * <c>_DEBUG</c> level 0 prints are ALWAYS compiled, but are runtime switched
  563. * using the automata <c>ysi_debug</c>. When then state is <c>ysi_debug :
  564. * on</c>, the prints are executed. When then state is <c>ysi_debug : off</c>,
  565. * they aren't.
  566. *
  567. * </remarks>
  568. *//*------------------------------------------------------------------------**/
  569. stock Debug_Print0(const str[], GLOBAL_TAG_TYPES:...) <ysi_debug : on>
  570. {
  571. static tmp1, tmp2;
  572. #emit POP.pri
  573. #emit STOR.pri tmp1
  574. #emit POP.alt
  575. #emit STOR.alt tmp2
  576. #emit SYSREQ.C printf
  577. #emit PUSH tmp2
  578. #emit PUSH tmp1
  579. #pragma unused str
  580. return 0;
  581. }
  582. stock Debug_Print0(const str[], GLOBAL_TAG_TYPES:...) <>
  583. {
  584. #pragma unused str
  585. return 0;
  586. }
  587. stock Debug_PrintArray(arr[], size = sizeof (arr))
  588. {
  589. new
  590. str[96];
  591. switch (size)
  592. {
  593. case 0:
  594. str = "<>";
  595. case 1:
  596. format(str, sizeof (str), "<%d>", arr[0]);
  597. case 2:
  598. format(str, sizeof (str), "<%d, %d>", arr[0], arr[1]);
  599. case 3:
  600. format(str, sizeof (str), "<%d, %d, %d>", arr[0], arr[1], arr[2]);
  601. case 4:
  602. format(str, sizeof (str), "<%d, %d, %d, %d>", arr[0], arr[1], arr[2], arr[3]);
  603. case 5:
  604. format(str, sizeof (str), "<%d, %d, %d, %d, %d>", arr[0], arr[1], arr[2], arr[3], arr[4]);
  605. default:
  606. format(str, sizeof (str), "<%d, %d, %d, %d, %d, ... (+ %d)>", arr[0], arr[1], arr[2], arr[3], arr[4], size - 5);
  607. }
  608. return str;
  609. }
  610. /*-------------------------------------------------------------------------*//**
  611. * <remarks>
  612. * Does some strange mangling of <c>YSI_FILTERSCRIPT</c> because at one point I
  613. * found a compiler bug where the first automata in the script could conflict
  614. * with the first variable in the script. I don't know what triggered it, and
  615. * it has never shown up since I messed about with this file to try mangle some
  616. * things. Never the less, if it ever happens again this code might detect it.
  617. *
  618. * Actually, that's less likely now, since that variable is now very unlikely
  619. * to be the first in the script ever.
  620. * </remarks>
  621. *//*------------------------------------------------------------------------**/
  622. public OnScriptInit()
  623. {
  624. Debug_SetState();
  625. new
  626. s;
  627. // Test the ADDRESS of the variable, not the value.
  628. #emit CONST.pri YSI_FILTERSCRIPT
  629. #emit STOR.S.pri s
  630. if (s)
  631. {
  632. //goto Debug_OnScriptInit_no_fault();
  633. #if defined Debug_OnScriptInit
  634. return Debug_OnScriptInit();
  635. #else
  636. return 1;
  637. #endif
  638. }
  639. P:F("YSI_FILTERSCRIPT == 0");
  640. while (s != 10000000) ++s;
  641. #emit CONST.pri 0
  642. #emit SCTRL 6
  643. return 1;
  644. }
  645. /*-------------------------------------------------------------------------*//**
  646. * <transition keep="true" target="ysi_debug : on" source="ysi_debug : "/>
  647. * <remarks>
  648. * Mostly exists to define the full range of <c>ysi_debug</c> states.
  649. * </remarks>
  650. *//*------------------------------------------------------------------------**/
  651. static stock Debug_SetState() <ysi_debug : off>
  652. {
  653. }
  654. static stock Debug_SetState() <>
  655. {
  656. state ysi_debug : on;
  657. }
  658. /*-------------------------------------------------------------------------*//**
  659. * <remarks>
  660. * Turn on level 0 prints.
  661. * </remarks>
  662. *//*------------------------------------------------------------------------**/
  663. stock Debug_Enable()
  664. {
  665. state ysi_debug : on;
  666. }
  667. /*-------------------------------------------------------------------------*//**
  668. * <remarks>
  669. * Turn off level 0 prints.
  670. * </remarks>
  671. *//*------------------------------------------------------------------------**/
  672. stock Debug_Disable()
  673. {
  674. state ysi_debug : off;
  675. }
  676. #undef OnScriptInit
  677. #define OnScriptInit Debug_OnScriptInit
  678. #if defined Debug_OnScriptInit
  679. forward Debug_OnScriptInit();
  680. #endif
  681. /*-------------------------------------------------------------------------*//**
  682. * <remarks>
  683. * Set the debug level when the code is compiled with <c>_DEBUG=-1</c>, which
  684. * means full run-time selection.
  685. * </remarks>
  686. *//*------------------------------------------------------------------------**/
  687. stock Debug_Level(level = -1)
  688. {
  689. if (0 <= level <= 7)
  690. {
  691. YSI_gDebugLevel = level;
  692. }
  693. return YSI_gDebugLevel;
  694. }
  695. #define DebugLevel Debug_Level