libwwc.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "wonx_configure.h"
  7. #include "wonx/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. /*
  128. * data は long int × 8 で 32 バイト.
  129. */
  130. void wwc_font_set_colordata(unsigned int number, unsigned int count,
  131. unsigned long int * data)
  132. {
  133. WWCharacter ww_character;
  134. WWDisplay ww_display;
  135. int i, j, n;
  136. if (!WonX_IsCreated()) WonX_Create();
  137. /* タイマを一時停止する */
  138. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  139. printf("call : wwc_font_set_colordata() : number = %u, count = %u, data = %p\n",
  140. (int)number, (int)count, (void *)data);
  141. fflush(stdout);
  142. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  143. n = 0;
  144. for (i = 0; i < count; i++) {
  145. ww_character = WWDisplay_GetCharacter(ww_display, number + i);
  146. for (j = 0; j < 8; j++) {
  147. WWCharacter_SetBitmapAsLongInt(ww_character, j, data[n]);
  148. n++;
  149. }
  150. }
  151. WonXDisplay_Flush(WonX_GetWonXDisplay());
  152. printf("call : wwc_font_set_colordata() : return value = none\n");
  153. fflush(stdout);
  154. /* タイマをもとに戻す */
  155. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  156. return;
  157. }
  158. /*
  159. * data は long int × 8 で 32 バイト.
  160. */
  161. void wwc_font_get_colordata(unsigned int number, unsigned int count,
  162. unsigned long int * data)
  163. {
  164. WWCharacter ww_character;
  165. WWDisplay ww_display;
  166. int i, j, n;
  167. if (!WonX_IsCreated()) WonX_Create();
  168. /* タイマを一時停止する */
  169. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  170. printf("call : wwc_font_get_colordata() : number = %u, count = %u, data = %p\n",
  171. (int)number, (int)count, (void *)data);
  172. fflush(stdout);
  173. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  174. n = 0;
  175. for (i = 0; i < count; i++) {
  176. ww_character = WWDisplay_GetCharacter(ww_display, number + i);
  177. for (j = 0; j < 8; j++) {
  178. data[n] = WWCharacter_GetBitmapAsLongInt(ww_character, j);
  179. n++;
  180. }
  181. }
  182. WonXDisplay_Sync(WonX_GetWonXDisplay());
  183. printf("call : wwc_font_get_colordata() : return value = none\n");
  184. fflush(stdout);
  185. /* タイマをもとに戻す */
  186. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  187. return;
  188. }
  189. unsigned int wwc_get_hardarch(void)
  190. {
  191. WWDisplay ww_display;
  192. unsigned int ret;
  193. if (!WonX_IsCreated()) WonX_Create();
  194. /* タイマを一時停止する */
  195. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  196. printf("call : wwc_get_hardarch() : \n"); fflush(stdout);
  197. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  198. ret = WONX_DEFAULT_ARCH;
  199. WonXDisplay_Sync(WonX_GetWonXDisplay());
  200. printf("call : wwc_get_hardarch() : return value = %u\n", (int)ret);
  201. fflush(stdout);
  202. /* タイマをもとに戻す */
  203. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  204. return (ret);
  205. }
  206. void wwc_clear_font(void)
  207. {
  208. WWDisplay ww_display;
  209. WWCharacter ww_character;
  210. int i;
  211. if (!WonX_IsCreated()) WonX_Create();
  212. /* タイマを一時停止する */
  213. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  214. printf("call : wwc_clear_font() : \n");
  215. fflush(stdout);
  216. ww_display = WonXDisplay_GetWWDisplay(WonX_GetWonXDisplay());
  217. for (i = 0; i < 512; i++) {
  218. ww_character = WWDisplay_GetCharacter(ww_display, i);
  219. WWCharacter_ClearAllPixels(ww_character);
  220. }
  221. WonXDisplay_Flush(WonX_GetWonXDisplay());
  222. printf("call : wwc_clear_font() : return value = none\n");
  223. fflush(stdout);
  224. /* タイマをもとに戻す */
  225. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  226. return;
  227. }
  228. /*****************************************************************************/
  229. /* ここまで */
  230. /*****************************************************************************/
  231. /*****************************************************************************/
  232. /* End of File. */
  233. /*****************************************************************************/