more commands
This commit is contained in:
		
							parent
							
								
									2165629bef
								
							
						
					
					
						commit
						4f0eca3ea0
					
				
					 9 changed files with 489 additions and 78 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
use crate::{heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use crate::{heap_drop, heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    Bitmap, BitmapCommand, CompressionCode, Origin, Packet, TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -44,6 +44,18 @@ pub unsafe extern "C" fn sp_cmd_bitmap_into_packet(
 | 
			
		|||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_clone(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) -> NonNull<BitmapCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { command.as_ref().clone() })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_free(command: NonNull<BitmapCommand>) {
 | 
			
		||||
    unsafe { heap_drop(command) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Returns a pointer to the provided `BitmapCommand`.
 | 
			
		||||
///
 | 
			
		||||
/// # Safety
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
use crate::{heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use crate::{heap_drop, heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
 | 
			
		||||
    Packet, TypedCommand,
 | 
			
		||||
| 
						 | 
				
			
			@ -46,6 +46,18 @@ pub unsafe extern "C" fn sp_cmd_bitvec_into_packet(
 | 
			
		|||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_clone(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> NonNull<BitVecCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { command.as_ref().clone() })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
 | 
			
		||||
    unsafe { heap_drop(command) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
| 
						 | 
				
			
			@ -63,6 +75,7 @@ pub unsafe extern "C" fn sp_cmd_bitvec_set(
 | 
			
		|||
        command.as_mut().bitvec = heap_remove(bitvec);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_offset(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										95
									
								
								src/commands/brightness_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								src/commands/brightness_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,95 @@
 | 
			
		|||
use crate::{heap_drop, heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BitmapCommand, BrightnessGrid, BrightnessGridCommand, Origin, Packet,
 | 
			
		||||
    TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_new(
 | 
			
		||||
    grid: NonNull<BrightnessGrid>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) -> NonNull<BrightnessGridCommand> {
 | 
			
		||||
    heap_move_nonnull(BrightnessGridCommand {
 | 
			
		||||
        grid: unsafe { heap_remove(grid) },
 | 
			
		||||
        origin: Origin::new(origin_x, origin_y),
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_from_grid(
 | 
			
		||||
    grid: NonNull<BrightnessGrid>,
 | 
			
		||||
) -> NonNull<BrightnessGridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(grid) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_into_typed(
 | 
			
		||||
    command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
) -> NonNull<TypedCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(command) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_into_packet(
 | 
			
		||||
    command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
) -> *mut Packet {
 | 
			
		||||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_clone(
 | 
			
		||||
    command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
) -> NonNull<BrightnessGridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { command.as_ref().clone() })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_free(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe { heap_drop(command) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Moves the provided bitmap to be contained in the command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_set(
 | 
			
		||||
    mut command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
    grid: NonNull<BrightnessGrid>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().grid = heap_remove(grid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_get(
 | 
			
		||||
    mut command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
) -> *mut BrightnessGrid {
 | 
			
		||||
    &mut unsafe { command.as_mut() }.grid
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_get_origin(
 | 
			
		||||
    command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
    origin_x: NonNull<usize>,
 | 
			
		||||
    origin_y: NonNull<usize>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        let origin = &command.as_ref().origin;
 | 
			
		||||
        *origin_x.as_ptr() = origin.x;
 | 
			
		||||
        *origin_y.as_ptr() = origin.y;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_set_origin(
 | 
			
		||||
    mut command: NonNull<BrightnessGridCommand>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().origin = Origin::new(origin_x, origin_y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										94
									
								
								src/commands/char_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/commands/char_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,94 @@
 | 
			
		|||
use crate::{heap_drop, heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BitmapCommand, CharGrid, CharGridCommand, Origin, Packet, TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_new(
 | 
			
		||||
    grid: NonNull<CharGrid>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) -> NonNull<CharGridCommand> {
 | 
			
		||||
    heap_move_nonnull(CharGridCommand {
 | 
			
		||||
        grid: unsafe { heap_remove(grid) },
 | 
			
		||||
        origin: Origin::new(origin_x, origin_y),
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_from_grid(
 | 
			
		||||
    grid: NonNull<CharGrid>,
 | 
			
		||||
) -> NonNull<CharGridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(grid) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_into_typed(
 | 
			
		||||
    command: NonNull<CharGridCommand>,
 | 
			
		||||
) -> NonNull<TypedCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(command) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_into_packet(
 | 
			
		||||
    command: NonNull<CharGridCommand>,
 | 
			
		||||
) -> *mut Packet {
 | 
			
		||||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_clone(
 | 
			
		||||
    command: NonNull<CharGridCommand>,
 | 
			
		||||
) -> NonNull<CharGridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { command.as_ref().clone() })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_free(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe { heap_drop(command) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Moves the provided bitmap to be contained in the command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_set(
 | 
			
		||||
    mut command: NonNull<CharGridCommand>,
 | 
			
		||||
    grid: NonNull<CharGrid>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().grid = heap_remove(grid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_get(
 | 
			
		||||
    mut command: NonNull<CharGridCommand>,
 | 
			
		||||
) -> *mut CharGrid {
 | 
			
		||||
    &mut unsafe { command.as_mut() }.grid
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_get_origin(
 | 
			
		||||
    command: NonNull<CharGridCommand>,
 | 
			
		||||
    origin_x: NonNull<usize>,
 | 
			
		||||
    origin_y: NonNull<usize>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        let origin = &command.as_ref().origin;
 | 
			
		||||
        *origin_x.as_ptr() = origin.x;
 | 
			
		||||
        *origin_y.as_ptr() = origin.y;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_char_grid_set_origin(
 | 
			
		||||
    mut command: NonNull<CharGridCommand>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().origin = Origin::new(origin_x, origin_y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										94
									
								
								src/commands/cp437_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/commands/cp437_grid_command.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,94 @@
 | 
			
		|||
use crate::{heap_drop, heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BitmapCommand, Cp437Grid, Cp437GridCommand, Origin, Packet, TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_new(
 | 
			
		||||
    grid: NonNull<Cp437Grid>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) -> NonNull<Cp437GridCommand> {
 | 
			
		||||
    heap_move_nonnull(Cp437GridCommand {
 | 
			
		||||
        grid: unsafe { heap_remove(grid) },
 | 
			
		||||
        origin: Origin::new(origin_x, origin_y),
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_from_grid(
 | 
			
		||||
    grid: NonNull<Cp437Grid>,
 | 
			
		||||
) -> NonNull<Cp437GridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(grid) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_into_typed(
 | 
			
		||||
    command: NonNull<Cp437GridCommand>,
 | 
			
		||||
) -> NonNull<TypedCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(command) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_into_packet(
 | 
			
		||||
    command: NonNull<Cp437GridCommand>,
 | 
			
		||||
) -> *mut Packet {
 | 
			
		||||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_clone(
 | 
			
		||||
    command: NonNull<Cp437GridCommand>,
 | 
			
		||||
) -> NonNull<Cp437GridCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { command.as_ref().clone() })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_free(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe { heap_drop(command) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Moves the provided bitmap to be contained in the command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_set(
 | 
			
		||||
    mut command: NonNull<Cp437GridCommand>,
 | 
			
		||||
    grid: NonNull<Cp437Grid>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().grid = heap_remove(grid);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_get(
 | 
			
		||||
    mut command: NonNull<Cp437GridCommand>,
 | 
			
		||||
) -> *mut Cp437Grid {
 | 
			
		||||
    &mut unsafe { command.as_mut() }.grid
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_get_origin(
 | 
			
		||||
    command: NonNull<Cp437GridCommand>,
 | 
			
		||||
    origin_x: NonNull<usize>,
 | 
			
		||||
    origin_y: NonNull<usize>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        let origin = &command.as_ref().origin;
 | 
			
		||||
        *origin_x.as_ptr() = origin.x;
 | 
			
		||||
        *origin_y.as_ptr() = origin.y;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_set_origin(
 | 
			
		||||
    mut command: NonNull<Cp437GridCommand>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().origin = Origin::new(origin_x, origin_y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,2 +1,5 @@
 | 
			
		|||
mod bitmap_command;
 | 
			
		||||
mod bitvec_command;
 | 
			
		||||
mod brightness_grid_command;
 | 
			
		||||
mod char_grid_command;
 | 
			
		||||
mod cp437_grid_command;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue