text.c 11 KB

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