WonXSystem.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. ww_timer = WWTimer_Create(1, WONX_VBLANK_INTERVAL);
  72. if (ww_timer == NULL)
  73. WonX_Error("WonXSystem_Create", "Cannot create WonderWitch VBlank timer.");
  74. WonXSystem_SetWWVBlankTimer(wonx_system, ww_timer);
  75. ww_timer = WWTimer_Create(0, WONX_VBLANK_INTERVAL);
  76. if (ww_timer == NULL)
  77. WonX_Error("WonXSystem_Create",
  78. "Cannot create WonderWitch VBlank count up timer.");
  79. WonXSystem_SetWWVBlankCountUpTimer(wonx_system, ww_timer);
  80. ww_timer = WWTimer_Create(0, WONX_HBLANK_INTERVAL);
  81. if (ww_timer == NULL)
  82. WonX_Error("WonXSystem_Create",
  83. "Cannot create WonderWitch HBlank count up timer.");
  84. WonXSystem_SetWWHBlankCountUpTimer(wonx_system, ww_timer);
  85. WWTimer_Reset(WonXSystem_GetWWVBlankTimer( wonx_system));
  86. WWTimer_Reset(WonXSystem_GetWWVBlankCountUpTimer(wonx_system));
  87. WWTimer_Reset(WonXSystem_GetWWHBlankCountUpTimer(wonx_system));
  88. WWTimer_ON( WonXSystem_GetWWVBlankTimer( wonx_system));
  89. WWTimer_OFF(WonXSystem_GetWWVBlankCountUpTimer(wonx_system));
  90. WWTimer_OFF(WonXSystem_GetWWHBlankCountUpTimer(wonx_system));
  91. unix_timer = UNIXTimer_Create(1, WONX_TIMER_INTERVAL, wonx_system,
  92. (UNIXTimerCallBack)WonXTimer_Callback);
  93. if (unix_timer == NULL)
  94. WonX_Error("WonXSystem_Create", "Cannot create UNIX timer.");
  95. WonXSystem_SetUNIXTimer(wonx_system, unix_timer);
  96. UNIXTimer_ON(unix_timer);
  97. return (wonx_system);
  98. }
  99. WonXSystem WonXSystem_Destroy(WonXSystem wonx_system)
  100. {
  101. WWInterrupt wi;
  102. WWTimer wt;
  103. UNIXTimer unix_timer;
  104. if (wonx_system == NULL)
  105. WonX_Error("WonXSystem_Destroy", "Object is not created.");
  106. unix_timer = WonXSystem_GetUNIXTimer(wonx_system);
  107. if (unix_timer)
  108. UNIXTimer_OFF(unix_timer);
  109. wt = WonXSystem_GetWWVBlankTimer(wonx_system);
  110. if (wt) WWTimer_OFF(wt);
  111. wt = WonXSystem_GetWWVBlankCountUpTimer(wonx_system);
  112. if (wt) WWTimer_OFF(wt);
  113. wt = WonXSystem_GetWWHBlankCountUpTimer(wonx_system);
  114. if (wt) WWTimer_OFF(wt);
  115. if (unix_timer)
  116. WonXSystem_SetUNIXTimer(wonx_system, UNIXTimer_Destroy(unix_timer));
  117. wt = WonXSystem_GetWWVBlankTimer(wonx_system);
  118. if (wt) WonXSystem_SetWWVBlankTimer(wonx_system, WWTimer_Destroy(wt));
  119. wt = WonXSystem_GetWWVBlankCountUpTimer(wonx_system);
  120. if (wt) WonXSystem_SetWWVBlankCountUpTimer(wonx_system, WWTimer_Destroy(wt));
  121. wt = WonXSystem_GetWWHBlankCountUpTimer(wonx_system);
  122. if (wt) WonXSystem_SetWWHBlankCountUpTimer(wonx_system, WWTimer_Destroy(wt));
  123. wi = WonXSystem_GetWWInterrupt(wonx_system);
  124. if (wi) WonXSystem_SetWWInterrupt(wonx_system, WWInterrupt_Destroy(wi));
  125. free(wonx_system);
  126. return (NULL);
  127. }
  128. /*****************************************************************************/
  129. /* ここまで */
  130. /*****************************************************************************/
  131. /*****************************************************************************/
  132. /* End of File. */
  133. /*****************************************************************************/