text.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "wonx_include/text.h"
  8. #include "Wonx.h"
  9. #include "WWText.h"
  10. /*****************************************************************************/
  11. /* 互換関数の定義 */
  12. /*****************************************************************************/
  13. /*
  14. * Xサーバとの同期の整合性がとれなくなるなどの問題が考えられるので,
  15. * 互換関数の内部は UNIXTimer_Pause(), UNIXTimer_Unpause() でくくり,
  16. * タイマ割り込みを一時停止して処理を行う.また,unpause するまえに,
  17. * かならず sync するようにする.
  18. */
  19. /*
  20. * タイマの一時停止の2重解除の問題が出てくるので,
  21. * 互換関数から互換関数を呼んではいけない.
  22. * (一時停止はネストされるが,いちおう)
  23. * 似たような処理をする関数の場合は,必ず static な別関数に処理をまとめ,
  24. * そっちを呼び出すようにすること.
  25. * 引数の表示の問題もあるしね.
  26. */
  27. static void _text_window_init(int x, int y, int w, int h, unsigned int base)
  28. {
  29. WWText ww_text;
  30. WWDisplay ww_display;
  31. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  32. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  33. WWText_SetTextWindow(ww_text, x, y, w, h, base, ww_display);
  34. WWScreen_SetRollX(WWText_GetScreen(ww_text), 0);
  35. WWScreen_SetRollY(WWText_GetScreen(ww_text), 0);
  36. return;
  37. }
  38. void text_screen_init(void)
  39. {
  40. WWDisplay ww_display;
  41. WWLCDPanel ww_lcd_panel;
  42. if (!Wonx_IsCreated()) Wonx_Create();
  43. /* タイマを一時停止する */
  44. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  45. printf("call : text_screen_init() : \n");
  46. fflush(stdout);
  47. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  48. ww_lcd_panel = WWDisplay_GetLCDPanel(ww_display);
  49. _text_window_init(0, 0, TEXT_SCREEN_WIDTH, TEXT_SCREEN_HEIGHT, 8);
  50. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  51. printf("call : text_screen_init() : return value = none\n"); fflush(stdout);
  52. /* タイマをもとに戻す */
  53. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  54. return;
  55. }
  56. void text_window_init(int x, int y, int w, int h, unsigned int base)
  57. {
  58. WWDisplay ww_display;
  59. if (!Wonx_IsCreated()) Wonx_Create();
  60. /* タイマを一時停止する */
  61. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  62. printf("call : text_window_init() : x = %d, y = %d, width = %d, height = %d, base = %u\n", x, y, w, h, (int)base);
  63. fflush(stdout);
  64. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  65. _text_window_init(x, y, w, h, base);
  66. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  67. printf("call : text_window_init() : return value = none\n"); fflush(stdout);
  68. /* タイマをもとに戻す */
  69. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  70. return;
  71. }
  72. void text_set_mode(int mode)
  73. {
  74. }
  75. int text_get_mode(void)
  76. {
  77. return (0);
  78. }
  79. static void _text_put_char(int x, int y, unsigned int c)
  80. {
  81. WWText ww_text;
  82. WWDisplay ww_display;
  83. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  84. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  85. WWText_PutCharacter(ww_text, x, y, c, ww_display);
  86. return;
  87. }
  88. void text_put_char(int x, int y, unsigned int c)
  89. {
  90. if (!Wonx_IsCreated()) Wonx_Create();
  91. /* タイマを一時停止する */
  92. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  93. printf("call : text_put_char() : x = %d, y = %d, character = %u\n", x, y, (int)c);
  94. fflush(stdout);
  95. _text_put_char(x, y, c);
  96. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  97. printf("call : text_put_char() : return value = none\n"); fflush(stdout);
  98. /* タイマをもとに戻す */
  99. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  100. return;
  101. }
  102. static int _text_put_string(int x, int y, char * string)
  103. {
  104. int i, len, ret;
  105. WWText ww_text;
  106. WWDisplay ww_display;
  107. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  108. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  109. len = strlen(string);
  110. ret = 0;
  111. for (i = 0; i < len; i++) {
  112. if (WWText_PutCharacter(ww_text, x + i, y, string[i], ww_display) >= 0)
  113. ret++;
  114. }
  115. return (ret);
  116. }
  117. int text_put_string(int x, int y, char * string)
  118. {
  119. int ret;
  120. if (!Wonx_IsCreated()) Wonx_Create();
  121. /* タイマを一時停止する */
  122. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  123. printf("call : text_put_string() : x = %d, y = %d, string = %s\n", x, y, string);
  124. fflush(stdout);
  125. ret = _text_put_string(x, y, string);
  126. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  127. printf("call : text_put_string() : return value = %d\n", ret);
  128. fflush(stdout);
  129. /* タイマをもとに戻す */
  130. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  131. return (ret);
  132. }
  133. int text_put_substring(int x, int y, char * s, int length)
  134. {
  135. int i, ret;
  136. WWText ww_text;
  137. WWDisplay ww_display;
  138. if (!Wonx_IsCreated()) Wonx_Create();
  139. /* タイマを一時停止する */
  140. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  141. printf("call : text_put_substring() : x = %d, y = %d, string = %s, length = %d\n", x, y, s, length);
  142. fflush(stdout);
  143. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  144. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  145. ret = 0;
  146. for (i = 0; i < length; i++) {
  147. if (WWText_PutCharacter(ww_text, x + i, y, s[i], ww_display) >= 0)
  148. ret++;
  149. }
  150. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  151. printf("call : text_put_substring() : return value = %d\n", ret);
  152. fflush(stdout);
  153. /* タイマをもとに戻す */
  154. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  155. return (ret);
  156. }
  157. void text_put_numeric(int x, int y, int length, int format, int number)
  158. {
  159. char buf[20];
  160. char f[20];
  161. if (!Wonx_IsCreated()) Wonx_Create();
  162. /* タイマを一時停止する */
  163. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  164. printf("call : text_put_numeric() : x = %d, y = %d, length = %d, format = %04x, number = %d\n", x, y, length, format, number);
  165. fflush(stdout);
  166. strcpy(f, "%");
  167. if (format & NUM_PADZERO) strcat(f, "0");
  168. sprintf(f + strlen(f), "%d", length);
  169. if (format & NUM_HEXA) strcat(f, "x");
  170. else if (format & NUM_SIGNED) strcat(f, "d");
  171. else strcat(f, "u");
  172. if (format & NUM_ALIGN_LEFT) { /* 未実装 */ }
  173. sprintf(buf, f, number);
  174. _text_put_string(x, y, buf);
  175. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  176. printf("call : text_put_numeric() : return value = none\n");
  177. fflush(stdout);
  178. /* タイマをもとに戻す */
  179. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  180. return;
  181. }
  182. void text_store_numeric(char * buffer, int length, int format, int number)
  183. {
  184. }
  185. void text_fill_char(int x, int y, int length, int c)
  186. {
  187. int i;
  188. if (!Wonx_IsCreated()) Wonx_Create();
  189. /* タイマを一時停止する */
  190. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  191. printf("call : text_fill_char() : x = %d, y = %d, length = %d, character = %d\n", x, y, length, c);
  192. fflush(stdout);
  193. for (i = 0; i < length; i++) {
  194. _text_put_char(x + i, y, c);
  195. }
  196. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  197. printf("call : text_fill_char() : return value = none\n");
  198. fflush(stdout);
  199. /* タイマをもとに戻す */
  200. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  201. return;
  202. }
  203. void text_set_palette(int palette_num)
  204. {
  205. WWText ww_text;
  206. WWDisplay ww_display;
  207. if (!Wonx_IsCreated()) Wonx_Create();
  208. /* タイマを一時停止する */
  209. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  210. printf("call : text_set_palette() : palette = %d\n", palette_num);
  211. fflush(stdout);
  212. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  213. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  214. WWText_SetPalette(ww_text, WWDisplay_GetPalette(ww_display, palette_num));
  215. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  216. printf("call : text_set_palette() : return value = none\n");
  217. fflush(stdout);
  218. /* タイマをもとに戻す */
  219. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  220. return;
  221. }
  222. int text_get_palette(void)
  223. {
  224. WWText ww_text;
  225. int num;
  226. if (!Wonx_IsCreated()) Wonx_Create();
  227. /* タイマを一時停止する */
  228. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  229. printf("call : text_get_palette() : \n");
  230. fflush(stdout);
  231. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  232. num = WWPalette_GetNumber(WWText_GetPalette(ww_text));
  233. WonxDisplay_Sync(Wonx_GetWonxDisplay());
  234. printf("call : text_get_palette() : return value = %d\n", num);
  235. fflush(stdout);
  236. /* タイマをもとに戻す */
  237. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  238. return (num);
  239. }
  240. void text_set_ank_font(int base, int color, int count, void * font)
  241. {
  242. }
  243. void text_set_sjis_font(void * p)
  244. {
  245. }
  246. void text_get_fontdata(int c, void * buffer)
  247. {
  248. }
  249. void text_set_screen(int screen)
  250. {
  251. WWText ww_text;
  252. WWDisplay ww_display;
  253. if (!Wonx_IsCreated()) Wonx_Create();
  254. /* タイマを一時停止する */
  255. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  256. printf("call : text_set_screen() : screen = %d\n", screen);
  257. fflush(stdout);
  258. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  259. ww_display = WonxDisplay_GetWWDisplay(Wonx_GetWonxDisplay());
  260. WWText_SetScreen(ww_text, WWDisplay_GetScreen(ww_display, screen));
  261. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  262. printf("call : text_set_screen() : return value = none\n");
  263. fflush(stdout);
  264. /* タイマをもとに戻す */
  265. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  266. return;
  267. }
  268. int text_get_screen(void)
  269. {
  270. WWText ww_text;
  271. int n;
  272. if (!Wonx_IsCreated()) Wonx_Create();
  273. /* タイマを一時停止する */
  274. UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  275. printf("call : text_get_screen() : \n");
  276. fflush(stdout);
  277. ww_text = WonxText_GetWWText(Wonx_GetWonxText());
  278. n = WWScreen_GetNumber(WWText_GetScreen(ww_text));
  279. WonxDisplay_Flush(Wonx_GetWonxDisplay());
  280. printf("call : text_set_screen() : return value = %d\n", n);
  281. fflush(stdout);
  282. /* タイマをもとに戻す */
  283. UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
  284. return (n);
  285. }
  286. void cursor_display(int flag)
  287. {
  288. }
  289. int cursor_status(void)
  290. {
  291. return (0);
  292. }
  293. void cursor_set_location(int x, int y, int w, int h)
  294. {
  295. }
  296. unsigned long int cursor_get_location(void)
  297. {
  298. return (0);
  299. }
  300. void cursor_set_type(int palette_num, int interval)
  301. {
  302. }
  303. unsigned long int cursor_get_type(void)
  304. {
  305. return (0);
  306. }
  307. int text_printf(int x, int y, const char *format, ...)
  308. {
  309. return (0);
  310. }
  311. /*****************************************************************************/
  312. /* ここまで */
  313. /*****************************************************************************/
  314. /*****************************************************************************/
  315. /* End of File. */
  316. /*****************************************************************************/