WonxSystem.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include "wonx_configure.h"
  5. #include "WonxSystemP.h"
  6. #include "etc.h"
  7. /*****************************************************************************/
  8. /* メンバ関数の定義 */
  9. /*****************************************************************************/
  10. WWInterrupt WonxSystem_GetWWInterrupt(WonxSystem wonx_system)
  11. { return (wonx_system->ww_interrupt); }
  12. WWInterrupt WonxSystem_SetWWInterrupt(WonxSystem wonx_system,
  13. WWInterrupt ww_interrupt)
  14. { return (wonx_system->ww_interrupt = ww_interrupt); }
  15. WWTimer WonxSystem_GetWWTimer(WonxSystem wonx_system, int type)
  16. { return (wonx_system->ww_timer[type]); }
  17. WWTimer WonxSystem_SetWWTimer(WonxSystem wonx_system, int type, WWTimer t)
  18. { return (wonx_system->ww_timer[type] = t); }
  19. WWTimer WonxSystem_GetWWVBlankTimer(WonxSystem wonx_system)
  20. { return (WonxSystem_GetWWTimer(wonx_system, 0)); }
  21. WWTimer WonxSystem_SetWWVBlankTimer(WonxSystem wonx_system, WWTimer t)
  22. { return (WonxSystem_SetWWTimer(wonx_system, 0, t)); }
  23. WWTimer WonxSystem_GetWWVBlankCountUpTimer(WonxSystem wonx_system)
  24. { return (WonxSystem_GetWWTimer(wonx_system, 1)); }
  25. WWTimer WonxSystem_SetWWVBlankCountUpTimer(WonxSystem wonx_system, WWTimer t)
  26. { return (WonxSystem_SetWWTimer(wonx_system, 1, t)); }
  27. WWTimer WonxSystem_GetWWHBlankCountUpTimer(WonxSystem wonx_system)
  28. { return (WonxSystem_GetWWTimer(wonx_system, 2)); }
  29. WWTimer WonxSystem_SetWWHBlankCountUpTimer(WonxSystem wonx_system, WWTimer t)
  30. { return (WonxSystem_SetWWTimer(wonx_system, 2, t)); }
  31. UNIXTimer WonxSystem_GetUNIXTimer(WonxSystem wonx_system)
  32. { return (wonx_system->unix_timer); }
  33. UNIXTimer WonxSystem_SetUNIXTimer(WonxSystem wonx_system,
  34. UNIXTimer unix_timer)
  35. { return (wonx_system->unix_timer = unix_timer); }
  36. static int WonxTimer_Callback(WonxSystem wonx_system)
  37. {
  38. WWTimer ww_timer;
  39. WWInterrupt ww_interrupt;
  40. ww_interrupt = WonxSystem_GetWWInterrupt(wonx_system);
  41. ww_timer = WonxSystem_GetWWVBlankTimer(wonx_system);
  42. if (WWTimer_IsON(ww_timer)) {
  43. if (WWTimer_Count(ww_timer))
  44. WWInterrupt_ExecuteVBlankCallback(ww_interrupt);
  45. }
  46. ww_timer = WonxSystem_GetWWVBlankCountUpTimer(wonx_system);
  47. if (WWTimer_IsON(ww_timer)) {
  48. if (WWTimer_Count(ww_timer))
  49. WWInterrupt_ExecuteTimerCountUpCallback(ww_interrupt);
  50. }
  51. ww_timer = WonxSystem_GetWWHBlankCountUpTimer(wonx_system);
  52. if (WWTimer_IsON(ww_timer)) {
  53. if (WWTimer_Count(ww_timer))
  54. WWInterrupt_ExecuteHBlankCountUpCallback(ww_interrupt);
  55. }
  56. return (0);
  57. }
  58. WonxSystem WonxSystem_Create()
  59. {
  60. WonxSystem wonx_system;
  61. WWInterrupt ww_interrupt;
  62. WWTimer ww_timer;
  63. UNIXTimer unix_timer;
  64. wonx_system = (WonxSystem)malloc(sizeof(_WonxSystem));
  65. if (wonx_system == NULL)
  66. Wonx_Error("WonxSystem_Create", "Cannot allocate memory.");
  67. ww_interrupt = WWInterrupt_Create();
  68. if (ww_interrupt == NULL)
  69. Wonx_Error("WonxSystem_Create", "Cannot create WonderWitch interrupt.");
  70. WonxSystem_SetWWInterrupt(wonx_system, ww_interrupt);
  71. /* VBlank は WONX_VBLANK_INTERVAL * 0.1 秒毎とする */
  72. ww_timer = WWTimer_Create(1, WONX_VBLANK_INTERVAL);
  73. if (ww_timer == NULL)
  74. Wonx_Error("WonxSystem_Create", "Cannot create WonderWitch VBlank timer.");
  75. WonxSystem_SetWWVBlankTimer(wonx_system, ww_timer);
  76. ww_timer = WWTimer_Create(0, WONX_VBLANK_INTERVAL);
  77. if (ww_timer == NULL)
  78. Wonx_Error("WonxSystem_Create",
  79. "Cannot create WonderWitch VBlank count up timer.");
  80. WonxSystem_SetWWVBlankCountUpTimer(wonx_system, ww_timer);
  81. ww_timer = WWTimer_Create(0, WONX_HBLANK_INTERVAL);
  82. if (ww_timer == NULL)
  83. Wonx_Error("WonxSystem_Create",
  84. "Cannot create WonderWitch HBlank count up timer.");
  85. WonxSystem_SetWWHBlankCountUpTimer(wonx_system, ww_timer);
  86. WWTimer_Reset(WonxSystem_GetWWVBlankTimer( wonx_system));
  87. WWTimer_Reset(WonxSystem_GetWWVBlankCountUpTimer(wonx_system));
  88. WWTimer_Reset(WonxSystem_GetWWHBlankCountUpTimer(wonx_system));
  89. WWTimer_ON( WonxSystem_GetWWVBlankTimer( wonx_system));
  90. WWTimer_OFF(WonxSystem_GetWWVBlankCountUpTimer(wonx_system));
  91. WWTimer_OFF(WonxSystem_GetWWHBlankCountUpTimer(wonx_system));
  92. /* タイマのインターバルは,0.1 秒単位とする */
  93. unix_timer = UNIXTimer_Create(1, WONX_TIMER_INTERVAL, wonx_system,
  94. (UNIXTimerCallBack)WonxTimer_Callback);
  95. if (unix_timer == NULL)
  96. Wonx_Error("WonxSystem_Create", "Cannot create UNIX timer.");
  97. WonxSystem_SetUNIXTimer(wonx_system, unix_timer);
  98. UNIXTimer_ON(unix_timer);
  99. return (wonx_system);
  100. }
  101. WonxSystem WonxSystem_Destroy(WonxSystem wonx_system)
  102. {
  103. WWInterrupt wi;
  104. WWTimer wt;
  105. UNIXTimer unix_timer;
  106. if (wonx_system == NULL)
  107. Wonx_Error("WonxSystem_Destroy", "Object is not created.");
  108. unix_timer = WonxSystem_GetUNIXTimer(wonx_system);
  109. if (unix_timer)
  110. UNIXTimer_OFF(unix_timer);
  111. wt = WonxSystem_GetWWVBlankTimer(wonx_system);
  112. if (wt) WWTimer_OFF(wt);
  113. wt = WonxSystem_GetWWVBlankCountUpTimer(wonx_system);
  114. if (wt) WWTimer_OFF(wt);
  115. wt = WonxSystem_GetWWHBlankCountUpTimer(wonx_system);
  116. if (wt) WWTimer_OFF(wt);
  117. if (unix_timer)
  118. WonxSystem_SetUNIXTimer(wonx_system, UNIXTimer_Destroy(unix_timer));
  119. wt = WonxSystem_GetWWVBlankTimer(wonx_system);
  120. if (wt) WonxSystem_SetWWVBlankTimer(wonx_system, WWTimer_Destroy(wt));
  121. wt = WonxSystem_GetWWVBlankCountUpTimer(wonx_system);
  122. if (wt) WonxSystem_SetWWVBlankCountUpTimer(wonx_system, WWTimer_Destroy(wt));
  123. wt = WonxSystem_GetWWHBlankCountUpTimer(wonx_system);
  124. if (wt) WonxSystem_SetWWHBlankCountUpTimer(wonx_system, WWTimer_Destroy(wt));
  125. wi = WonxSystem_GetWWInterrupt(wonx_system);
  126. if (wi) WonxSystem_SetWWInterrupt(wonx_system, WWInterrupt_Destroy(wi));
  127. free(wonx_system);
  128. return (NULL);
  129. }
  130. /*****************************************************************************/
  131. /* ここまで */
  132. /*****************************************************************************/
  133. /*****************************************************************************/
  134. /* End of File. */
  135. /*****************************************************************************/