native.h
native.h
CPP1/* Copyright Statement:2 *3 * (C) 2021-2025 Cubios Inc. All rights reserved.4 */56#pragma once7#include <stdint.h>8#include "native_access.h"9#include "native_defines.h"1011typedef uint32_t u32_t;12typedef int32_t i32_t;1314namespace Cubios {1516 union __attribute__((packed)) AppVersion_t {17 uint32_t full;18 struct {19 uint16_t patch : 16;20 uint8_t minor : 4;21 uint8_t major : 4;22 uint8_t reserved: 8;23 };24};2526typedef int32_t soundID_t;27typedef int32_t spriteID_t;28struct TOPOLOGY_faceletInfo_t {29 int32_t module;30 int32_t screen;31 int32_t connected;32};3334struct TOPOLOGY_place_t {35 int32_t face;36 int32_t position;37};3839struct TOPOLOGY_twistInfo_t {40 int32_t screen;41 int32_t count;42 int32_t direction;43};4445enum TOPOLOGY_twist_t {46 TWIST_UNINDENTIFIED = 0,47 TWIST_LEFT,48 TWIST_RIGHT,49 TWIST_DOUBLE,50 TWIST_MAX,51};5253enum TOPOLOGY_orientation_mode_t {54 ORIENTATION_MODE_MENU = 0,55 ORIENTATION_MODE_GRAVITY,56 ORIENTATION_MODE_SPLASH,57 ORIENTATION_MODE_MAX,58};5960enum text_align_t{61 TEXT_ALIGN_CENTER,62 TEXT_ALIGN_TOP_CENTER,63 TEXT_ALIGN_BOTTOM_CENTER,64 TEXT_ALIGN_LEFT_CORNER,65 TEXT_ALIGN_LEFT_TOP_CORNER,66 TEXT_ALIGN_LEFT_BOTTOM_CORNER,67 TEXT_ALIGN_RIGHT_CORNER,68 TEXT_ALIGN_RIGHT_TOP_CORNER,69 TEXT_ALIGN_RIGHT_BOTTOM_CORNER70};7172enum TOPOLOGY_orientation_t{73 ORIENTATION_UP = 0,74 ORIENTATION_DOWN,75 ORIENTATION_FRONT,76 ORIENTATION_BACK,77 ORIENTATION_LEFT,78 ORIENTATION_RIGHT,79 ORIENTATION_MAX,80};8182enum TOPOLOGY_neighbor_t{83 NEIGHBOR_SELF = 0,84 NEIGHBOR_LEFT,85 NEIGHBOR_DIAGONAL,86 NEIGHBOR_TOP,87 NEIGHBOR_RIGHT,88 NEIGHBOR_BOTTOM,89 NEIGHBOR_MAX,90};9192struct LB_info_t {93 int32_t boardCount;94 int32_t selfPosition;95 int32_t selfScore;96 int32_t wholeUserListCount;97};9899struct GFX_Particle_t {100 int32_t ttl;101 int32_t vx;102 int32_t vy;103 int32_t ax;104 int32_t ay;105 int32_t explosion;106 int32_t velocity;107 int32_t duration;108 int32_t frequency;109 int32_t max;110 int32_t loop;111 uint32_t time;112};113114enum GFX_mirror_t {115 MIRROR_BLANK = 0,116 MIRROR_X,117 MIRROR_Y,118 MIRROR_XY,119};120121enum GFX_PixelFormat_t {122 FORMAT_RGB565 = 0,123 FORMAT_ARGB6666,124 FORMAT_ARGB8888,125};126127WASM_IMPORT("sendPacket") i32_t sendPacket(u32_t type, uint8_t* pkt, u32_t size);128WASM_IMPORT("recvPacket") i32_t recvPacket(u32_t size, uint32_t* type, uint8_t* pkt);129WASM_IMPORT("getTime") i32_t getTime();130WASM_IMPORT("getUserName") i32_t getUserName(uint8_t* buffer, u32_t bufSize);131WASM_IMPORT("toggleDebugInfo") i32_t toggleDebugInfo();132WASM_IMPORT("saveState") i32_t saveState(void* data, u32_t size);133WASM_IMPORT("loadState") i32_t loadState(u32_t* id, void* data, u32_t size);134WASM_IMPORT("random") i32_t random(u32_t min, u32_t max);135WASM_IMPORT("getAppVersion") i32_t getAppVersion(Cubios::AppVersion_t *version);136WASM_IMPORT("LOG") i32_t LOG(uint8_t level, const char* text);137WASM_IMPORT("getTap") i32_t getTap();138WASM_IMPORT("sendBleData") i32_t sendBleData(u32_t type, uint8_t* pkt, u32_t size);139WASM_IMPORT("recvBleData") i32_t recvBleData(uint8_t* pkt, u32_t size);140141WASM_IMPORT("TOPOLOGY_getAdjacentFacelet") i32_t TOPOLOGY_getAdjacentFacelet(u32_t module, u32_t screen, u32_t direction, Cubios::TOPOLOGY_faceletInfo_t* result);142WASM_IMPORT("TOPOLOGY_getFacelet") i32_t TOPOLOGY_getFacelet(u32_t face, u32_t position, Cubios::TOPOLOGY_orientation_mode_t mode, Cubios::TOPOLOGY_faceletInfo_t* result);143WASM_IMPORT("TOPOLOGY_getPlace") i32_t TOPOLOGY_getPlace(u32_t module, u32_t screen, Cubios::TOPOLOGY_orientation_mode_t mode, Cubios::TOPOLOGY_place_t* result);144WASM_IMPORT("TOPOLOGY_getOppositeFacelet") i32_t TOPOLOGY_getOppositeFacelet(u32_t module, u32_t screen, Cubios::TOPOLOGY_faceletInfo_t* result);145WASM_IMPORT("TOPOLOGY_getAngle") i32_t TOPOLOGY_getAngle(u32_t module, u32_t screen, Cubios::TOPOLOGY_orientation_mode_t mode);146WASM_IMPORT("TOPOLOGY_getFaceletOrientation") i32_t TOPOLOGY_getFaceletOrientation(u32_t module, u32_t screen);147WASM_IMPORT("TOPOLOGY_getPlaceOrientation") i32_t TOPOLOGY_getPlaceOrientation(u32_t face, u32_t position);148WASM_IMPORT("TOPOLOGY_getFace") i32_t TOPOLOGY_getFace(u32_t orientation);149WASM_IMPORT("TOPOLOGY_isAssembled") i32_t TOPOLOGY_isAssembled();150WASM_IMPORT("TOPOLOGY_getTwist") i32_t TOPOLOGY_getTwist(Cubios::TOPOLOGY_twistInfo_t* twist);151152WASM_IMPORT("LB_getInfo") i32_t LB_getInfo(Cubios::LB_info_t* info);153WASM_IMPORT("LB_getScore") i32_t LB_getScore(uint8_t* leadTableBin, u32_t bufSize);154155WASM_IMPORT("MS_getFaceAccelX") i32_t MS_getFaceAccelX(u32_t display);156WASM_IMPORT("MS_getFaceAccelY") i32_t MS_getFaceAccelY(u32_t display);157WASM_IMPORT("MS_getFaceAccelZ") i32_t MS_getFaceAccelZ(u32_t display);158WASM_IMPORT("MS_getFaceGyroX") i32_t MS_getFaceGyroX(u32_t display);159WASM_IMPORT("MS_getFaceGyroY") i32_t MS_getFaceGyroY(u32_t display);160WASM_IMPORT("MS_getFaceGyroZ")i32_t MS_getFaceGyroZ(u32_t display);161162WASM_IMPORT("GFX_getAssetId") i32_t GFX_getAssetId(const char* spriteName);163WASM_IMPORT("GFX_clear") i32_t GFX_clear(u32_t color);164WASM_IMPORT("GFX_drawText") i32_t GFX_drawText(i32_t x, i32_t y, u32_t scale, u32_t angle, u32_t align, u32_t color, const char* text);165WASM_IMPORT("GFX_drawPoint") i32_t GFX_drawPoint(i32_t x, i32_t y, u32_t color);166WASM_IMPORT("GFX_drawCircle") i32_t GFX_drawCircle(u32_t x, u32_t y, u32_t radius, u32_t width, u32_t color);167WASM_IMPORT("GFX_drawSolidCircle") i32_t GFX_drawSolidCircle(u32_t x, u32_t y, u32_t radius, u32_t color); // DEPRECATED: use fill shader intead168WASM_IMPORT("GFX_drawArc") i32_t GFX_drawArc(i32_t x, i32_t y, u32_t radius, u32_t width, u32_t angle0, u32_t angle1, u32_t color);169WASM_IMPORT("GFX_drawSector") i32_t GFX_drawSector(i32_t x, i32_t y, u32_t radius, u32_t angle0, u32_t angle1, u32_t color);170WASM_IMPORT("GFX_drawLine") i32_t GFX_drawLine(i32_t x0, i32_t y0, i32_t x1, i32_t y1, u32_t thickness, u32_t color);171WASM_IMPORT("GFX_drawRectangle") i32_t GFX_drawRectangle(i32_t x, i32_t y, i32_t w, i32_t h, u32_t color);172WASM_IMPORT("GFX_bakeImage") i32_t GFX_bakeImage(spriteID_t id, u32_t width, u32_t height, GFX_PixelFormat_t format, u32_t overwrite);173WASM_IMPORT("GFX_setRenderTarget") i32_t GFX_setRenderTarget(u32_t display);174WASM_IMPORT("GFX_drawImage") i32_t GFX_drawImage(spriteID_t id, i32_t x, i32_t y, u32_t opacity, u32_t colorKey, u32_t scale_x, u32_t scale_y, u32_t angle, u32_t mirror);175WASM_IMPORT("GFX_drawBakedImage") i32_t GFX_drawBakedImage(i32_t x, i32_t y, u32_t opacity, u32_t colorKey, u32_t scale_x, u32_t scale_y, u32_t angle, u32_t mirror, spriteID_t id);176WASM_IMPORT("GFX_drawQrCode") i32_t GFX_drawQRCode(i32_t x, i32_t y, u32_t size, u32_t color0, u32_t color1, u32_t angle, u32_t id, const char *text);177WASM_IMPORT("GFX_render") i32_t GFX_render();178WASM_IMPORT("GFX_clearCache") i32_t GFX_clearCache();179WASM_IMPORT("GFX_removeBakedImage") i32_t GFX_removeBakedImage(spriteID_t id);180WASM_IMPORT("GFX_cacheImages") i32_t GFX_cacheImages(spriteID_t* spriteIDs, u32_t count);181WASM_IMPORT("GFX_setFpsWindow") i32_t GFX_setFpsWindow(u32_t size);182WASM_IMPORT("GFX_getAssetsCount") i32_t GFX_getAssetsCount();183WASM_IMPORT("GFX_setFillShader") i32_t GFX_setFillShader(u32_t color);184WASM_IMPORT("GFX_setLinearGradientShader") i32_t GFX_setLinearGradientShader(u32_t x0, u32_t y0, u32_t x1, u32_t y1, u32_t color0, u32_t color1);185WASM_IMPORT("GFX_setRadialGradientShader") i32_t GFX_setRadialGradientShader(u32_t x0, u32_t y0, u32_t radius, u32_t color0, u32_t color1);186WASM_IMPORT("GFX_removeShader") i32_t GFX_removeShader();187188WASM_IMPORT("GFX_drawSubImage") i32_t GFX_drawSubImage(spriteID_t id,i32_t x,i32_t y,u32_t rect_x,u32_t rect_y,u32_t rect_w,u32_t rect_h,u32_t opacity,u32_t colorKey,u32_t scale_x, u32_t scale_y,u32_t angle, u32_t mirror);189190WASM_IMPORT("SND_getAssetId") i32_t SND_getAssetId(const char* soundName);191WASM_IMPORT("SND_play") i32_t SND_play(soundID_t soundID, u32_t volume);192WASM_IMPORT("SND_cacheSounds") i32_t SND_cacheSounds(soundID_t* soundIDs, u32_t count);193WASM_IMPORT("SND_isPlaying") i32_t SND_isPlaying();194WASM_IMPORT("SND_stop") i32_t SND_stop();195WASM_IMPORT("SND_getAssetsCount") i32_t SND_getAssetsCount();196197WASM_IMPORT("EVENT_getList") i32_t EVENT_getList();198199200extern uint32_t cubeN;201202static const uint8_t NET_BROADCAST = 0xFF;203204enum uartID_t {205 UART0 = 0,206 UART1,207 UART2208};209210enum eventMask_t {211 WASM_EVENT_ON_NET_UART0_RX = (1 << 0),212 WASM_EVENT_ON_NET_UART1_RX = (1 << 1),213 WASM_EVENT_ON_NET_UART2_RX = (1 << 2),214 WASM_EVENT_ON_PHYSICAL_TICK = (1 << 3),215 WASM_EVENT_ON_CLOSE = (1 << 4),216 WASM_EVENT_ON_TWIST = (1 << 5),217 WASM_EVENT_ON_PAT = (1 << 6),218 WASM_EVENT_ON_CFG_DATA = (1 << 7),219 WASM_EVENT_ON_UART_RX = (1 << 8),220};221222enum LogLevel_t {223 LOG_LVL_ASSERT,224 LOG_LVL_ERROR,225 LOG_LVL_WARN,226 LOG_LVL_INFO,227 ELOG_LVL_DEBUG,228 LOG_LVL_VERBOSE229};230231void log(uint8_t logLvl, const char *format, ...);232233#define LOG_a(...) Cubios::log(Cubios::LOG_LVL_ASSERT, __VA_ARGS__)234#define LOG_e(...) Cubios::log(Cubios::LOG_LVL_ERROR, __VA_ARGS__)235#define LOG_w(...) Cubios::log(Cubios::LOG_LVL_WARN, __VA_ARGS__)236#define LOG_i(...) Cubios::log(Cubios::LOG_LVL_INFO, __VA_ARGS__)237#define LOG_d(...) Cubios::log(Cubios::ELOG_LVL_DEBUG, __VA_ARGS__)238#define LOG_v(...) Cubios::log(Cubios::LOG_LVL_VERBOSE, __VA_ARGS__)239240}241242
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.