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. /*****************************************************************************/