pikapython/package/Arm2D/Arm2D_Window.c

123 lines
4.4 KiB
C
Raw Normal View History

2021-11-02 22:58:30 +08:00
#include "Arm2D_Window.h"
#include "Arm2D_Background.h"
#include "Arm2D_ElementList.h"
2022-09-07 22:08:35 +08:00
#include "Arm2D_Tile.h"
2021-11-03 20:11:31 +08:00
#include "Arm2D_common.h"
2021-11-02 22:58:30 +08:00
#include "arm_2d.h"
#include "arm_2d_helper.h"
#include "pikaScript.h"
2022-09-07 22:08:35 +08:00
pika_arm2d_globals_t pika_arm2d_globals;
2022-09-07 15:17:39 +08:00
arm_2d_helper_pfb_t s_tPFBHelper;
2021-11-02 22:58:30 +08:00
2022-09-07 22:08:35 +08:00
int32_t __Arm2D_platform_drawRegin(uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height,
const uint8_t* bitmap);
static void __pfb_render_handler(void* pTarget,
const arm_2d_pfb_t* ptPFB,
bool bIsNewFrame) {
2021-11-03 20:11:31 +08:00
const arm_2d_tile_t* pfb_tile = &(ptPFB->tTile);
2021-11-02 22:58:30 +08:00
2021-11-03 20:11:31 +08:00
ARM_2D_UNUSED(pTarget);
ARM_2D_UNUSED(bIsNewFrame);
2021-11-02 22:58:30 +08:00
2021-11-20 20:23:11 +08:00
__Arm2D_platform_drawRegin(
pfb_tile->tRegion.tLocation.iX, pfb_tile->tRegion.tLocation.iY,
pfb_tile->tRegion.tSize.iWidth, pfb_tile->tRegion.tSize.iHeight,
pfb_tile->pchBuffer);
2021-11-02 22:58:30 +08:00
2021-11-03 20:11:31 +08:00
arm_2d_helper_pfb_report_rendering_complete(&s_tPFBHelper,
(arm_2d_pfb_t*)ptPFB);
2021-11-02 22:58:30 +08:00
}
2022-09-07 22:08:35 +08:00
static void Arm2D_callback_update(void) {
PikaObj* self = pika_arm2d_globals.pika_windows_object;
if (obj_getInt(self, "callback_exist") == 1) {
PikaObj* __frameBuffer = obj_getPtr(self, "__frameBuffer");
obj_setStruct(__frameBuffer, "_self", *pika_arm2d_globals.pfb_tile_now);
obj_setInt(self, "__isNewFrame", pika_arm2d_globals.pfb_is_new_frame);
/* clang-format off */
PIKA_PYTHON(
__callback(__frameBuffer, __isNewFrame)
)
/* clang-format on */
const uint8_t bytes[] = {
0x0c, 0x00, /* instruct array size */
0x10, 0x81, 0x01, 0x00, 0x10, 0x01, 0x0f, 0x00, 0x00, 0x02, 0x1c,
0x00,
/* instruct array */
0x27, 0x00, /* const pool size */
0x00, 0x5f, 0x5f, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x42, 0x75, 0x66,
0x66, 0x65, 0x72, 0x00, 0x5f, 0x5f, 0x69, 0x73, 0x4e, 0x65, 0x77,
0x46, 0x72, 0x61, 0x6d, 0x65, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c,
0x6c, 0x62, 0x61, 0x63, 0x6b, 0x00, /* const pool */
};
pikaVM_runByteCode(self, (uint8_t*)bytes);
}
}
static arm_fsm_rt_t pika_pfb_drow_window_hanlder(
void* pTarget,
const arm_2d_tile_t* frameBuffer,
bool isNewFrame) {
2021-11-03 20:11:31 +08:00
ARM_2D_UNUSED(pTarget);
2021-11-02 22:58:30 +08:00
2022-09-07 22:08:35 +08:00
pika_arm2d_globals.pfb_tile_now = (arm_2d_tile_t*)frameBuffer;
pika_arm2d_globals.pfb_is_new_frame = isNewFrame;
PikaObj* background = pika_arm2d_globals.pika_background_object;
PikaObj* elems = pika_arm2d_globals.pika_elems_object;
2021-11-03 20:11:31 +08:00
Arm2D_BackGround_update(background);
Arm2D_ElementList_update(elems);
2022-09-07 22:08:35 +08:00
Arm2D_callback_update();
2021-11-03 20:11:31 +08:00
return arm_fsm_rt_cpl;
2021-11-02 22:58:30 +08:00
}
void pika_arm2d_init(void) {
2022-09-07 22:08:35 +08:00
arm_irq_safe {
arm_2d_init();
}
2021-11-03 20:11:31 +08:00
//! initialise FPB helper
if (ARM_2D_HELPER_PFB_INIT(
2022-09-07 22:08:35 +08:00
&s_tPFBHelper, //!< FPB Helper object
ARM2D_LCD_WIDTH, //!< screen width
ARM2D_LCD_HEIGHT, //!< screen height
uint16_t, //!< colour date type
ARM2D_PFB_BLOCK_WIDTH, //!< PFB block width
ARM2D_PFB_BLOCK_HEIGHT, //!< PFB block height
2022-09-07 22:08:35 +08:00
1, //!< number of PFB in the PFB pool
2021-11-03 20:11:31 +08:00
{
.evtOnLowLevelRendering =
{
//! callback for low level rendering
.fnHandler = &__pfb_render_handler,
},
.evtOnDrawing =
{
//! callback for drawing GUI
.fnHandler = &pika_pfb_drow_window_hanlder,
},
}) < 0) {
//! error detected
assert(false);
}
2021-11-02 22:58:30 +08:00
}
2022-09-07 01:14:27 +08:00
void Arm2D_Window___init__(PikaObj* self) {
2022-09-07 22:08:35 +08:00
obj_setInt(self, "callback_exist", 0);
PikaObj* __frameBuffer = newNormalObj(New_Arm2D_Tile);
obj_setPtr(self, "__frameBuffer", __frameBuffer);
pika_arm2d_globals.pika_windows_object = self;
pika_arm2d_globals.pika_elems_object = obj_getObj(self, "elems");
pika_arm2d_globals.pika_background_object = obj_getObj(self, "background");
pika_arm2d_globals.dirty_region_list = NULL;
}
void Arm2D_Window_addCallBack(PikaObj* self, Arg* callback) {
obj_setInt(self, "callback_exist", 1);
obj_setArg(self, "__callback", callback);
2021-11-02 22:58:30 +08:00
}