cubios.rs
cubios.rs
RUST1#[allow(dead_code)]2pub static mut CUBE_N: u32 = 0;345#[allow(dead_code)]6#[repr(C)]7pub enum UartId {8 Uart0 = 0,9 Uart1,10 Uart211}1213pub type SoundId = cty::uint32_t;14pub type SpriteId = cty::uint32_t;1516#[allow(dead_code)]17#[repr(C)]18pub struct TopologyFaceletInfo {19 pub module: cty::int32_t,20 pub screen: cty::int32_t,21 pub connected: cty::int32_t,22}2324#[allow(dead_code)]25#[repr(C)]26pub struct TopologyPlace {27 pub face: cty::int32_t,28 pub position: cty::int32_t,29}3031#[allow(dead_code)]32#[repr(C)]33#[derive(Debug, Clone, Copy)]34pub enum TopologyNeighbour {35 None = 0,36 Left,37 Diagonal,38 Top,39 Right,40 Bottom,41}4243#[allow(dead_code)]44#[repr(C)]45pub struct TopologyTwistInfo {46 pub screen: cty::int32_t,47 pub count: cty::int32_t,48 pub direction: cty::int32_t,49}5051#[allow(dead_code)]52#[repr(C)]53pub enum TopologyOrientation {54 Menu = 0,55 Gravity,56 Splash,57 Max,58}5960#[allow(dead_code)]61#[repr(C)]62pub enum TextAlign{63 Center = 0,64 TopCenter,65 BottomCenter,66 LeftCorner,67 LeftTopCorner,68 LeftBottomCorner,69 RightCorner,70 RightTopCorner,71 RightBottomCorner,72}7374#[allow(dead_code)]75#[repr(C)]76#[derive(PartialEq)]77pub enum TopologyLocation {78 Up = 0,79 Down,80 Front,81 Back,82 Left,83 Right,84 Max,85}8687#[allow(dead_code)]88#[repr(C)]89pub struct LbInfo {90 pub board_count: cty::int32_t,91 pub self_position: cty::int32_t,92 pub self_achivement: cty::int32_t,93 pub whole_user_list_count: cty::int32_t,94}9596#[allow(dead_code)]97#[repr(C)]98pub struct GfxParticle {99 pub ttl: cty::int32_t,100 pub vx: cty::int32_t,101 pub vy: cty::int32_t,102 pub ax: cty::int32_t,103 pub ay: cty::int32_t,104 pub explosion: cty::int32_t,105 pub velocity: cty::int32_t,106 pub duration: cty::int32_t,107 pub frequency: cty::int32_t,108 pub max: cty::int32_t,109 pub r#loop: cty::int32_t,110 pub time: cty::int32_t,111}112113#[allow(dead_code)]114static NET_BROADCAST: u32 = 0xFF;115116#[allow(dead_code)]117#[repr(C)]118pub enum LogLevel {119 Assert,120 Error,121 Warn,122 Info,123 Debug,124 Verbose125}126127extern "C" {128 fn sendMessage(line: cty::uint32_t, dest: cty::uint32_t, pkt: *const cty::uint8_t, size: cty::uint32_t) -> cty::int32_t;129 fn recvMessage(line: cty::uint32_t, size: cty::uint32_t, pktInfo: *mut cty::uint32_t, pkt: *mut u8, rxSize: *mut cty::uint32_t) -> cty::int32_t;130 fn getTime() -> cty::int32_t;131 fn getUserName(buffer: *mut cty::uint8_t, bufSize: cty::uint32_t) -> cty::int32_t;132 fn toggleDebugInfo() -> cty::int32_t;133 fn saveState(data: *const cty::uint8_t, size: cty::uint32_t) -> cty::int32_t;134 fn loadState(data: *mut cty::uint8_t, size: cty::uint32_t) -> cty::int32_t;135 fn random(min: cty::uint32_t, max: cty::uint32_t) -> cty::int32_t;136 fn LOG(level: cty::uint8_t, text: *const cty::c_char) -> cty::int32_t;137 fn getTap() -> cty::int32_t;138139 fn EVENT_getList() -> cty::int32_t;140141 fn GFX_getAssetId(spriteName: *const cty::c_char) -> cty::int32_t;142 fn GFX_clear(color: cty::uint32_t) -> cty::int32_t;143 fn GFX_drawText(x: cty::uint32_t, y: cty::uint32_t, scale: cty::uint32_t, angle: cty::uint32_t, align: cty::uint32_t, color: cty::uint32_t, text: *const cty::c_char) -> cty::int32_t;144 fn GFX_drawPoint(x: cty::int32_t, y: cty::int32_t, color: cty::uint32_t) -> cty::int32_t;145 fn GFX_drawCircle(x: cty::int32_t, y: cty::int32_t, radius: cty::uint32_t, width: cty::uint32_t, color: cty::uint32_t) -> cty::int32_t;146 fn GFX_drawSolidCircle(x: cty::int32_t, y: cty::int32_t, radius: cty::uint32_t, color: cty::uint32_t) -> cty::int32_t;147 fn GFX_drawArc(x: cty::int32_t, y: cty::int32_t, radius: cty::uint32_t, width: cty::uint32_t, angle0: cty::uint32_t , angle1: cty::uint32_t, color: cty::uint32_t) -> cty::int32_t;148 fn GFX_drawSector(x: cty::int32_t, y: cty::int32_t, radius: cty::uint32_t, angle0: cty::uint32_t, angle1: cty::uint32_t, color: cty::uint32_t) -> cty::int32_t;149 fn GFX_drawLine(x0: cty::int32_t, y0: cty::int32_t, x1: cty::int32_t, y1: cty::int32_t, thickness: cty::uint32_t, color: cty::uint32_t) -> cty::int32_t;150 fn GFX_drawRectangle(x: cty::int32_t, y: cty::int32_t, w: cty::int32_t, h: cty::int32_t, color: cty::uint32_t) -> cty::int32_t;151 fn GFX_bakeImage(id: SpriteId, width: cty::uint32_t , height: cty::uint32_t, replace: cty::uint32_t, overwrite: cty::uint32_t) -> cty::int32_t;152 fn GFX_setRenderTarget(display: cty::uint32_t) -> cty::int32_t;153 fn GFX_drawImage(id: SpriteId, x: cty::int32_t, y: cty::int32_t, alpha: cty::uint32_t, color: cty::uint32_t, scale_x: cty::uint32_t, scale_y: cty::uint32_t, angle: cty::uint32_t, mirror: cty::uint32_t) -> cty::int32_t;154 fn GFX_drawBakedImage(x: cty::int32_t, y: cty::int32_t, color: cty::uint32_t, alpha: cty::uint32_t, scale_x: cty::uint32_t, scale_y: cty::uint32_t, angle: cty::uint32_t, mirror: cty::uint32_t, id: SpriteId) -> cty::int32_t;155 fn GFX_drawParticles(x: cty::int32_t, y: cty::int32_t, color: cty::uint32_t, alpha: cty::uint32_t, angle: cty::uint32_t, id: SpriteId, particle: *const GfxParticle) -> cty::int32_t;156 fn GFX_render() -> cty::int32_t;157 fn GFX_clearCache() -> cty::int32_t;158 fn GFX_cacheImages(spriteIDs: *const SpriteId, count: cty::uint32_t) -> cty::int32_t;159160 fn TOPOLOGY_getAdjacentFacelet(module: cty::uint32_t, screen: cty::uint32_t, direction: TopologyNeighbour, result: *mut TopologyFaceletInfo) -> cty::int32_t;161 fn TOPOLOGY_getFacelet(face: cty::uint32_t, position: cty::uint32_t, mode: TopologyOrientation, result: *mut TopologyFaceletInfo) -> cty::int32_t;162 fn TOPOLOGY_getPlace(module: cty::uint32_t, screen: cty::uint32_t, mode: TopologyOrientation, result: *mut TopologyPlace) -> cty::int32_t;163 fn TOPOLOGY_getOppositeFacelet(module: cty::uint32_t, screen: cty::uint32_t, result: *mut TopologyFaceletInfo) -> cty::int32_t;164 fn TOPOLOGY_getAngle(module: cty::uint32_t, screen: cty::uint32_t, mode: TopologyOrientation) -> cty::int32_t;165 fn TOPOLOGY_getFaceletOrientation(module: cty::uint32_t, screen: cty::uint32_t) -> cty::int32_t;166 fn TOPOLOGY_getPlaceOrientation(face: cty::uint32_t, position: cty::uint32_t) -> cty::int32_t;167 fn TOPOLOGY_getFace(orientation: cty::uint32_t) -> cty::int32_t;168 fn TOPOLOGY_isAssembled() -> cty::int32_t;169 fn TOPOLOGY_getTwist(twist: *mut TopologyTwistInfo) -> cty::int32_t;170 fn TopologyDebugGetFace(module: cty::uint32_t, screen: cty::uint32_t) -> cty::int32_t;171 fn TopologyDebugGetPosition(module: cty::uint32_t, screen: cty::uint32_t) -> cty::int32_t;172 fn TopologyDebugGetHorizontal() -> cty::int32_t;173174 fn LB_getInfo(info: *mut LbInfo) -> cty::int32_t;175 fn LB_getScore(leadTableBin: *mut cty::uint8_t, bufSize: cty::uint32_t) -> cty::int32_t;176177 fn MS_getFaceAccelX(display: cty::uint32_t) -> cty::int32_t;178 fn MS_getFaceAccelY(display: cty::uint32_t) -> cty::int32_t;179 fn MS_getFaceAccelZ(display: cty::uint32_t) -> cty::int32_t;180 fn MS_getFaceGyroX(display: cty::uint32_t) -> cty::int32_t;181 fn MS_getFaceGyroY(display: cty::uint32_t) -> cty::int32_t;182 fn MS_getFaceGyroZ(display: cty::uint32_t) -> cty::int32_t;183184 fn SND_getAssetId(soundName: *const cty::c_char) -> cty::int32_t;185 fn SND_play(soundID: SoundId, volume: cty::uint32_t) -> cty::int32_t;186 fn SND_cacheSounds(soundIDs: *const SoundId, count: cty::uint32_t) -> cty::int32_t;187}188189pub fn on_init(cid: u32) {190 unsafe {191 CUBE_N = cid;192 }193}194195#[allow(dead_code)]196pub mod gfx {197 use std::ffi::CString;198199 pub fn get_asset_id(sprite_name: &str) -> i32 {200 let c_str = CString::new(sprite_name).unwrap();201 return unsafe { super::GFX_getAssetId(c_str.as_ptr() as *const cty::c_char) };202 }203204 pub fn clear(color: u32) -> i32 {205 return unsafe { super::GFX_clear(color) };206 }207208 pub fn draw_text(x: u32, y: u32, scale: u32, angle: u32, align: super::TextAlign, color: u32, text: &str) -> i32 {209 let c_str = CString::new(text).unwrap();210 return unsafe { super::GFX_drawText(x, y, scale, angle, align as u32, color, c_str.as_ptr() as *const cty::c_char) };211 }212213 pub fn draw_point(x: i32, y: i32, color: u32) -> i32 {214 return unsafe { super::GFX_drawPoint(x, y, color) };215 }216217 pub fn draw_circle(x: i32, y: i32, radius: u32, width: u32, color: u32) -> i32 {218 return unsafe { super::GFX_drawCircle(x, y, radius, width, color) };219 }220221 pub fn draw_solid_circle(x: i32, y: i32, radius: u32, color: u32) -> i32 {222 return unsafe { super::GFX_drawSolidCircle(x, y, radius, color) };223 }224225 pub fn draw_arc(x: i32, y: i32, radius: u32, width: u32, angle0: u32, angle1: u32, color: u32) -> i32 {226 return unsafe { super::GFX_drawArc(x, y, radius, width, angle0, angle1, color) };227 }228229 pub fn draw_sector(x: i32, y: i32, radius: u32, angle0: u32, angle1: u32, color: u32) -> i32 {230 return unsafe { super::GFX_drawSector(x, y, radius, angle0, angle1, color) };231 }232233 pub fn draw_line(x0: i32, y0: i32, x1: i32, y1: i32, thickness: u32, color: u32) -> i32 {234 return unsafe { super::GFX_drawLine(x0, y0, x1, y1, thickness, color) };235 }236237 pub fn draw_rectangle(x: i32, y: i32, w: i32, h: i32, color: u32) -> i32 {238 return unsafe { super::GFX_drawRectangle(x, y, w, h, color) };239 }240241 pub fn bake_image(id: super::SpriteId, width: u32 , height: u32, replace: u32, overwrite: u32) -> i32 {242 return unsafe { super::GFX_bakeImage(id, width, height, replace, overwrite) };243 }244245 pub fn set_render_target(display: u8) -> i32 {246 return unsafe { super::GFX_setRenderTarget(display as u32) };247 }248249 pub fn draw_image(id: super::SpriteId, x: i32, y: i32, color: u32, alpha: u32, scale_x: u32, scale_y: u32, angle: u32, mirror: u32) -> i32 {250 return unsafe { super::GFX_drawImage(id, x, y, alpha, color, scale_x, scale_y, angle, mirror) };251 }252253 pub fn draw_baked_image(x: i32, y: i32, color: u32, alpha: u32, scale_x: u32, scale_y: u32, angle: u32, mirror: u32, id: super::SpriteId) -> i32 {254 return unsafe { super::GFX_drawBakedImage(x, y, color, alpha, scale_x, scale_y, angle, mirror, id) };255 }256257 pub fn draw_particles(x: i32, y: i32, color: u32, alpha: u32, angle: u32, id: super::SpriteId, particle: *const super::GfxParticle) -> i32 {258 return unsafe { super::GFX_drawParticles(x, y, color, alpha, angle, id, particle) };259 }260261 pub fn render() -> i32 {262 return unsafe { super::GFX_render() };263 }264265 pub fn clear_cache() -> i32 {266 return unsafe { super::GFX_clearCache() };267 }268269 pub fn cache_images(sprite_ids: &[super::SpriteId]) -> i32 {270 return unsafe { super::GFX_cacheImages(sprite_ids.as_ptr(), sprite_ids.len() as u32) };271 }272}273274#[allow(dead_code)]275pub mod topology {276 const REVERSED_FACES: [u32; 6] = [3, 5, 4, 0, 2, 1];277278 pub fn get_cuben() -> u32 {279 unsafe {280 super::CUBE_N281 }282 }283284 pub fn get_adjacent_facelet(module: u32, screen: u32, direction: super::TopologyNeighbour, result: *mut super::TopologyFaceletInfo) -> i32 {285 return unsafe { super::TOPOLOGY_getAdjacentFacelet(module, screen, direction, result) };286 }287288 pub fn get_reversed_face(face: u32) -> Option<u32> {289 REVERSED_FACES.get(face as usize).cloned()290 }291292 pub fn get_facelet(face: u32, position: u32, mode: super::TopologyOrientation, result: *mut super::TopologyFaceletInfo) -> i32 {293 return unsafe { super::TOPOLOGY_getFacelet(face, position, mode, result) };294 }295296 pub fn get_place(module: u32, screen: u32, mode: super::TopologyOrientation, result: *mut super::TopologyPlace) -> i32 {297 return unsafe { super::TOPOLOGY_getPlace(module, screen, mode, result) };298 }299300 pub fn get_opposite_facelet(module: u32, screen: u32, result: *mut super::TopologyFaceletInfo) -> i32 {301 return unsafe { super::TOPOLOGY_getOppositeFacelet(module, screen, result) };302 }303304 pub fn get_angle(module: u32, screen: u32, mode: super::TopologyOrientation) -> i32 {305 return unsafe { super::TOPOLOGY_getAngle(module, screen, mode) };306 }307308 pub fn get_facelet_orientation(module: u32, screen: u32) -> i32 {309 return unsafe { super::TOPOLOGY_getFaceletOrientation(module, screen) };310 }311312 pub fn get_place_orientation(face: u32, position: u32) -> i32 {313 return unsafe { super::TOPOLOGY_getPlaceOrientation(face, position) };314 }315316 pub fn get_face(orientation: u32) -> i32 {317 return unsafe { super::TOPOLOGY_getFace(orientation) };318 }319320 pub fn is_assembled() -> i32 {321 return unsafe { super::TOPOLOGY_isAssembled() };322 }323324 pub fn get_twist(twist: *mut super::TopologyTwistInfo) -> i32 {325 return unsafe { super::TOPOLOGY_getTwist(twist) };326 }327328 pub fn debug_get_face(module: u32, screen: u32) -> i32 {329 return unsafe { super::TopologyDebugGetFace(module, screen) };330 }331332 pub fn debug_get_position(module: u32, screen: u32) -> i32 {333 return unsafe { super::TopologyDebugGetPosition(module, screen) };334 }335336 fn debug_get_horizontal() -> i32 {337 return unsafe { super::TopologyDebugGetHorizontal() };338 }339}340341#[allow(dead_code)]342pub mod comm {343 use std::ffi::CString;344345 pub fn send_message(line: u32, pkt: *const u8, size: u32) -> i32 {346 return unsafe { super::sendMessage(line, super::NET_BROADCAST, pkt, size) };347 }348349 pub fn recv_message(line: u32, size: u32, pkt_info: *mut u32, pkt: *mut u8, rx_size: *mut u32) -> i32 {350 return unsafe { super::recvMessage(line, size, pkt_info, pkt, rx_size) };351 }352353 pub fn get_time() -> i32 {354 return unsafe { super::getTime() };355 }356357 pub fn get_user_name(buffer: &mut [u8]) -> i32 {358 return unsafe { super::getUserName(buffer.as_mut_ptr(), buffer.len() as u32) };359 }360361 pub fn toggle_debug_info() -> i32 {362 return unsafe { super::toggleDebugInfo() };363 }364365 pub fn save_state(data: &[u8]) -> i32 {366 return unsafe { super::saveState(data.as_ptr(), data.len() as u32) };367 }368369 pub fn load_state(data: &mut [u8]) -> i32 {370 return unsafe { super::loadState(data.as_mut_ptr(), data.len() as u32) };371 }372373 pub fn random(min: u32, max: u32) -> i32 {374 return unsafe { super::random(min, max) };375 }376377 pub fn log_a( text: &str) -> i32 {378 let c_str = CString::new(text).unwrap();379 return unsafe { super::LOG(super::LogLevel::Assert as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };380 }381382 pub fn log_e(text: &str) -> i32 {383 let c_str = CString::new(text).unwrap();384 return unsafe { super::LOG(super::LogLevel::Error as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };385 }386 pub fn log_w(text: &str) -> i32 {387 let c_str = CString::new(text).unwrap();388 return unsafe { super::LOG(super::LogLevel::Warn as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };389 }390391 pub fn log_i(text: &str) -> i32 {392 let c_str = CString::new(text).unwrap();393 return unsafe { super::LOG(super::LogLevel::Info as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };394 }395396 pub fn log_d(text: &str) -> i32 {397 let c_str = CString::new(text).unwrap();398 return unsafe { super::LOG(super::LogLevel::Debug as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };399 }400401 pub fn log_v(text: &str) -> i32 {402 let c_str = CString::new(text).unwrap();403 return unsafe { super::LOG(super::LogLevel::Verbose as cty::uint8_t, c_str.as_ptr() as *const cty::uint8_t) };404 }405406 pub fn get_tap() -> i32 {407 return unsafe { super::getTap() };408 }409}410411#[allow(dead_code)]412pub mod lb {413 pub fn get_info(info: *mut super::LbInfo) -> i32 {414 return unsafe { super::LB_getInfo(info) };415 }416417 pub fn get_score(lead_table_bin: &mut [u8]) -> i32 {418 return unsafe { super::LB_getScore(lead_table_bin.as_mut_ptr(), lead_table_bin.len() as u32) };419 }420}421422#[allow(dead_code)]423pub mod ms {424 pub fn get_face_accel_x(display: u32) -> i32 {425 return unsafe { super::MS_getFaceAccelX(display) };426 }427428 pub fn get_face_accel_y(display: u32) -> i32 {429 return unsafe { super::MS_getFaceAccelY(display) };430 }431432 pub fn get_face_accel_z(display: u32) -> i32 {433 return unsafe { super::MS_getFaceAccelZ(display) };434 }435436 pub fn get_face_gyro_x(display: u32) -> i32 {437 return unsafe { super::MS_getFaceGyroX(display) };438 }439440 pub fn get_face_gyro_y(display: u32) -> i32 {441 return unsafe { super::MS_getFaceGyroY(display) };442 }443444 pub fn get_face_gyro_z(display: u32) -> i32 {445 return unsafe { super::MS_getFaceGyroZ(display) };446 }447}448449#[allow(dead_code)]450pub mod snd {451 use std::ffi::CString;452453 pub fn get_asset_id(sound_name: &str) -> i32 {454 let c_str = CString::new(sound_name).unwrap();455 return unsafe { super::SND_getAssetId(c_str.as_ptr() as *const cty::c_char) };456 }457458 pub fn play(sound_id: super::SoundId, volume: u32) -> i32 {459 return unsafe { super::SND_play(sound_id, volume) };460 }461462 pub fn cache_sounds(sound_ids: &[super::SoundId]) -> i32 {463 return unsafe { super::SND_cacheSounds(sound_ids.as_ptr(), sound_ids.len() as u32) };464 }465}466467#[allow(dead_code)]468pub mod event {469 #[allow(non_camel_case_types)]470 pub enum Event {471 ON_NET_UART0_RX = 1 << 0,472 ON_NET_UART1_RX = 1 << 1,473 ON_NET_UART2_RX = 1 << 2,474 ON_PHYSICAL_TICK = 1 << 3,475 ON_CLOSE = 1 << 4,476 ON_TWIST = 1 << 5,477 ON_PAT = 1 << 6,478 ON_CFG_DATA = (1 << 7),479 ON_UART_RX = (1 << 8),480 }481482 pub fn get_list() -> cty::int32_t {483 return unsafe { super::EVENT_getList() };484 }485}486487
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.