Arm2D_Window.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "Arm2D_Window.h"
  2. #include "Arm2D_Background.h"
  3. #include "Arm2D_ElementList.h"
  4. #include "Arm2D_Tile.h"
  5. #include "Arm2D_common.h"
  6. #include "arm_2d.h"
  7. #include "arm_2d_helper.h"
  8. #include "pikaScript.h"
  9. pika_arm2d_globals_t pika_arm2d_globals;
  10. arm_2d_helper_pfb_t s_tPFBHelper;
  11. int32_t __Arm2D_platform_drawRegin(uint32_t x,
  12. uint32_t y,
  13. uint32_t width,
  14. uint32_t height,
  15. const uint8_t* bitmap);
  16. static void __pfb_render_handler(void* pTarget,
  17. const arm_2d_pfb_t* ptPFB,
  18. bool bIsNewFrame) {
  19. const arm_2d_tile_t* pfb_tile = &(ptPFB->tTile);
  20. ARM_2D_UNUSED(pTarget);
  21. ARM_2D_UNUSED(bIsNewFrame);
  22. __Arm2D_platform_drawRegin(
  23. pfb_tile->tRegion.tLocation.iX, pfb_tile->tRegion.tLocation.iY,
  24. pfb_tile->tRegion.tSize.iWidth, pfb_tile->tRegion.tSize.iHeight,
  25. pfb_tile->pchBuffer);
  26. arm_2d_helper_pfb_report_rendering_complete(&s_tPFBHelper,
  27. (arm_2d_pfb_t*)ptPFB);
  28. }
  29. static void Arm2D_callback_update(void) {
  30. PikaObj* self = pika_arm2d_globals.pika_windows_object;
  31. if (obj_getInt(self, "callback_exist") == 1) {
  32. PikaObj* __frameBuffer = obj_getPtr(self, "__frameBuffer");
  33. obj_setStruct(__frameBuffer, "_self", *pika_arm2d_globals.pfb_tile_now);
  34. obj_setInt(self, "__isNewFrame", pika_arm2d_globals.pfb_is_new_frame);
  35. /* clang-format off */
  36. PIKA_PYTHON(
  37. __callback(__frameBuffer, __isNewFrame)
  38. )
  39. /* clang-format on */
  40. const uint8_t bytes[] = {
  41. 0x0c, 0x00, 0x00, 0x00,/* instruct array size */
  42. 0x10, 0x81, 0x01, 0x00, 0x10, 0x01, 0x0f, 0x00, 0x00, 0x02, 0x1c,
  43. 0x00,
  44. /* instruct array */
  45. 0x27, 0x00, 0x00, 0x00,/* const pool size */
  46. 0x00, 0x5f, 0x5f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x42, 0x75, 0x66,
  47. 0x66, 0x65, 0x72, 0x00, 0x5f, 0x5f, 0x69, 0x73, 0x4e, 0x65, 0x77,
  48. 0x46, 0x72, 0x61, 0x6d, 0x65, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c,
  49. 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x00, /* const pool */
  50. };
  51. pikaVM_runByteCode(self, (uint8_t*)bytes);
  52. }
  53. }
  54. static arm_fsm_rt_t pika_pfb_drow_window_hanlder(
  55. void* pTarget,
  56. const arm_2d_tile_t* frameBuffer,
  57. bool isNewFrame) {
  58. ARM_2D_UNUSED(pTarget);
  59. pika_arm2d_globals.pfb_tile_now = (arm_2d_tile_t*)frameBuffer;
  60. pika_arm2d_globals.pfb_is_new_frame = isNewFrame;
  61. PikaObj* background = pika_arm2d_globals.pika_background_object;
  62. PikaObj* elems = pika_arm2d_globals.pika_elems_object;
  63. Arm2D_BackGround_update(background);
  64. Arm2D_ElementList_update(elems);
  65. Arm2D_callback_update();
  66. return arm_fsm_rt_cpl;
  67. }
  68. void pika_arm2d_init(void) {
  69. arm_irq_safe {
  70. arm_2d_init();
  71. }
  72. //! initialise FPB helper
  73. if (ARM_2D_HELPER_PFB_INIT(
  74. &s_tPFBHelper, //!< FPB Helper object
  75. ARM2D_LCD_WIDTH, //!< screen width
  76. ARM2D_LCD_HEIGHT, //!< screen height
  77. uint16_t, //!< colour date type
  78. ARM2D_PFB_BLOCK_WIDTH, //!< PFB block width
  79. ARM2D_PFB_BLOCK_HEIGHT, //!< PFB block height
  80. 1, //!< number of PFB in the PFB pool
  81. {
  82. .evtOnLowLevelRendering =
  83. {
  84. //! callback for low level rendering
  85. .fnHandler = &__pfb_render_handler,
  86. },
  87. .evtOnDrawing =
  88. {
  89. //! callback for drawing GUI
  90. .fnHandler = &pika_pfb_drow_window_hanlder,
  91. },
  92. }) < 0) {
  93. //! error detected
  94. assert(false);
  95. }
  96. }
  97. void Arm2D_Window___init__(PikaObj* self) {
  98. obj_setInt(self, "callback_exist", 0);
  99. PikaObj* __frameBuffer = newNormalObj(New_Arm2D_Tile);
  100. obj_setPtr(self, "__frameBuffer", __frameBuffer);
  101. pika_arm2d_globals.pika_windows_object = self;
  102. pika_arm2d_globals.pika_elems_object = obj_getObj(self, "elems");
  103. pika_arm2d_globals.pika_background_object = obj_getObj(self, "background");
  104. pika_arm2d_globals.dirty_region_list = NULL;
  105. }
  106. void Arm2D_Window_addCallBack(PikaObj* self, Arg* callback) {
  107. obj_setInt(self, "callback_exist", 1);
  108. obj_setArg(self, "__callback", callback);
  109. }