libwwc.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "wonx_configure.h"
  7. #include "wonx_include/libwwc.h"
  8. #include "WonX.h"
  9. /*****************************************************************************/
  10. /* 互換関数の定義 */
  11. /*****************************************************************************/
  12. /*
  13. * void * でデータを渡す関数は,型を間違えるバグが入る可能性があるので,
  14. * void * を適切な型に置き換えてある.
  15. */
  16. /*
  17. * Xサーバとの同期の整合性がとれなくなるなどの問題が考えられるので,
  18. * 互換関数の内部は UNIXTimer_Pause(), UNIXTimer_Unpause() でくくり,
  19. * タイマ割り込みを一時停止して処理を行う.また,unpause するまえに,
  20. * かならず sync するようにする.
  21. */
  22. /*
  23. * タイマの一時停止の2重解除の問題が出てくるので,
  24. * 互換関数から互換関数を呼んではいけない.
  25. * (一時停止はネストされるが,いちおう)
  26. * 似たような処理をする関数の場合は,必ず static な別関数に処理をまとめ,
  27. * そっちを呼び出すようにすること.
  28. * 引数の表示の問題もあるしね.
  29. */
  30. unsigned int wwc_set_color_mode(unsigned int mode)
  31. {
  32. WWDisplay ww_display;
  33. unsigned int ret;
  34. if (!WonX_IsCreated()) WonX_Create();
  35. /* タイマを一時停止する */
  36. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  37. printf("call : wwc_set_color_mode() : mode = 0x%04x\n", (int)mode);
  38. fflush(stdout);
  39. switch (mode) {
  40. case COLOR_MODE_GRAYSCALE :
  41. case COLOR_MODE_4COLOR :
  42. case COLOR_MODE_16COLOR :
  43. case COLOR_MODE_16PACKED :
  44. break;
  45. default :
  46. WonX_Error("wwc_set_color_mode", "unknown color mode.");
  47. }
  48. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  49. ret = WWDisplay_SetColorMode(ww_display, mode);
  50. /* 次回の描画時には,全描画する */
  51. WWLCDPanel_SetAllDraw(WWDisplay_GetLCDPanel(ww_display));
  52. WonXDisplay_Flush(WonX_GetWonXDisplay());
  53. printf("call : wwc_set_color_mode() : return value = 0x%04x\n", (int)ret);
  54. fflush(stdout);
  55. /* タイマをもとに戻す */
  56. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  57. return (ret);
  58. }
  59. unsigned int wwc_get_color_mode(void)
  60. {
  61. WWDisplay ww_display;
  62. unsigned int ret;
  63. if (!WonX_IsCreated()) WonX_Create();
  64. /* タイマを一時停止する */
  65. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  66. printf("call : wwc_get_color_mode() : \n"); fflush(stdout);
  67. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  68. ret = WWDisplay_GetColorMode(ww_display);
  69. WonXDisplay_Sync(WonX_GetWonXDisplay());
  70. printf("call : wwc_get_color_mode() : return value = 0x%04x\n", (int)ret);
  71. fflush(stdout);
  72. /* タイマをもとに戻す */
  73. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  74. return (ret);
  75. }
  76. void wwc_palette_set_color(unsigned int palette_num, unsigned int color_num, unsigned int rgb)
  77. {
  78. WWDisplay ww_display;
  79. WWPalette ww_palette;
  80. unsigned short int red, green, blue;
  81. if (!WonX_IsCreated()) WonX_Create();
  82. /* タイマを一時停止する */
  83. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  84. printf("call : wwc_palette_set_color() : palette_num = %u, color_num = %u, rgb = 0x%04x\n",
  85. (int)palette_num, (int)color_num, (int)rgb);
  86. fflush(stdout);
  87. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  88. ww_palette = WWDisplay_GetPalette(ww_display, palette_num);
  89. red = (rgb >> 8) & 0x0f;
  90. green = (rgb >> 4) & 0x0f;
  91. blue = (rgb >> 0) & 0x0f;
  92. WWPalette_SetRed( ww_palette, color_num, red );
  93. WWPalette_SetGreen(ww_palette, color_num, green);
  94. WWPalette_SetBlue( ww_palette, color_num, blue );
  95. WonXDisplay_Flush(WonX_GetWonXDisplay());
  96. printf("call : wwc_palette_set_color() : return value = none\n");
  97. fflush(stdout);
  98. /* タイマをもとに戻す */
  99. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  100. return;
  101. }
  102. unsigned int wwc_palette_get_color(unsigned int palette_num, unsigned int color_num)
  103. {
  104. WWDisplay ww_display;
  105. WWPalette ww_palette;
  106. unsigned short int red, green, blue;
  107. unsigned short int ret;
  108. if (!WonX_IsCreated()) WonX_Create();
  109. /* タイマを一時停止する */
  110. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  111. printf("call : wwc_palette_get_color() : palette_num = %u, color_num = %u\n",
  112. (int)palette_num, (int)color_num);
  113. fflush(stdout);
  114. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  115. ww_palette = WWDisplay_GetPalette(ww_display, palette_num);
  116. red = WWPalette_GetRed( ww_palette, color_num);
  117. green = WWPalette_GetGreen(ww_palette, color_num);
  118. blue = WWPalette_GetBlue( ww_palette, color_num);
  119. ret = (red << 8) | (green << 4) | (blue << 0);
  120. WonXDisplay_Sync(WonX_GetWonXDisplay());
  121. printf("call : wwc_palette_get_color() : return value = 0x%04x\n", (int)ret);
  122. fflush(stdout);
  123. /* タイマをもとに戻す */
  124. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  125. return (ret);
  126. }
  127. void wwc_font_set_colordata(unsigned int number, unsigned int count, unsigned char * data)
  128. {
  129. WWCharacter ww_character;
  130. WWDisplay ww_display;
  131. int i, j, n;
  132. if (!WonX_IsCreated()) WonX_Create();
  133. /* タイマを一時停止する */
  134. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  135. printf("call : wwc_font_set_colordata() : number = %u, count = %u, data = %p\n",
  136. (int)number, (int)count, (void *)data);
  137. fflush(stdout);
  138. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  139. n = 0;
  140. for (i = 0; i < count; i++) {
  141. ww_character = WWDisplay_GetCharacter(ww_display, number + i);
  142. for (j = 0; j < 32; j++) {
  143. WWCharacter_SetBitmap(ww_character, j, data[n]);
  144. n++;
  145. }
  146. }
  147. WonXDisplay_Flush(WonX_GetWonXDisplay());
  148. printf("call : wwc_font_set_colordata() : return value = none\n");
  149. fflush(stdout);
  150. /* タイマをもとに戻す */
  151. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  152. return;
  153. }
  154. void wwc_font_get_colordata(unsigned int number, unsigned int count, unsigned char * data)
  155. {
  156. WWCharacter ww_character;
  157. WWDisplay ww_display;
  158. int i, j, n;
  159. if (!WonX_IsCreated()) WonX_Create();
  160. /* タイマを一時停止する */
  161. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  162. printf("call : wwc_font_get_colordata() : number = %u, count = %u, data = %p\n",
  163. (int)number, (int)count, (void *)data);
  164. fflush(stdout);
  165. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  166. n = 0;
  167. for (i = 0; i < count; i++) {
  168. ww_character = WWDisplay_GetCharacter(ww_display, number + i);
  169. for (j = 0; j < 32; j++) {
  170. data[n] = WWCharacter_GetBitmap(ww_character, j);
  171. n++;
  172. }
  173. }
  174. WonXDisplay_Sync(WonX_GetWonXDisplay());
  175. printf("call : wwc_font_get_colordata() : return value = none\n");
  176. fflush(stdout);
  177. /* タイマをもとに戻す */
  178. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  179. return;
  180. }
  181. unsigned int wwc_get_hardarch(void)
  182. {
  183. WWDisplay ww_display;
  184. unsigned int ret;
  185. if (!WonX_IsCreated()) WonX_Create();
  186. /* タイマを一時停止する */
  187. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  188. printf("call : wwc_get_hardarch() : \n"); fflush(stdout);
  189. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  190. ret = WONX_DEFAULT_ARCH;
  191. WonXDisplay_Sync(WonX_GetWonXDisplay());
  192. printf("call : wwc_get_hardarch() : return value = %u\n", (int)ret);
  193. fflush(stdout);
  194. /* タイマをもとに戻す */
  195. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  196. return (ret);
  197. }
  198. void wwc_clear_font(void)
  199. {
  200. WWDisplay ww_display;
  201. WWCharacter ww_character;
  202. int i;
  203. if (!WonX_IsCreated()) WonX_Create();
  204. /* タイマを一時停止する */
  205. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  206. printf("call : wwc_clear_font() : \n");
  207. fflush(stdout);
  208. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  209. for (i = 0; i < 512; i++) {
  210. ww_character = WWDisplay_GetCharacter(ww_display, i);
  211. WWCharacter_ClearAllPixels(ww_character);
  212. }
  213. WonXDisplay_Flush(WonX_GetWonXDisplay());
  214. printf("call : wwc_clear_font() : return value = none\n");
  215. fflush(stdout);
  216. /* タイマをもとに戻す */
  217. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  218. return;
  219. }
  220. /*****************************************************************************/
  221. /* ここまで */
  222. /*****************************************************************************/
  223. /*****************************************************************************/
  224. /* End of File. */
  225. /*****************************************************************************/