Skip to content

Commit f4e2c70

Browse files
committed
Add line drawing ioctls.
1 parent 49509fc commit f4e2c70

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/ioctls/gfx.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// The corresponding value is the fill colour, which is taken modulo the number of on-screen colours.
66
pub const COMMAND_CLEAR_SCREEN: u64 = 0;
77

8-
/// Plot a chunky pixel
8+
/// Plot a chunky pixel (and move the cursor).
99
///
1010
/// The command contains [ x | y | mode | colour ].
1111
///
@@ -29,16 +29,52 @@ pub const COMMAND_CHUNKY_PLOT: u64 = 1;
2929
/// Use [`change_mode_value`] to construct a value.
3030
pub const COMMAND_CHANGE_MODE: u64 = 2;
3131

32-
/// Calculate a 64-bit value argument for a gfx ioctl
32+
/// Move the cursor
33+
///
34+
/// The command contains [ x | y | <padding> ].
35+
///
36+
/// The graphics handle maintains a virtual cursor position. This is used for
37+
/// plotting lines for example - you move the cursor to one end of the line, and
38+
/// then issue a LINE_DRAW ioctl containing the other end of the line. This saves
39+
/// having to try and pass two sets of co-ordinates within one ioctl.
40+
///
41+
/// Use [`move_cursor_value`] to construct a value.
42+
pub const COMMAND_MOVE_CURSOR: u64 = 3;
43+
44+
/// Draw a line
45+
///
46+
/// The command contains [ x | y | mode | colour ].
47+
///
48+
/// * `x` is 16 bits and marks the final horizontal position (0 is left)
49+
/// * `y` is 16 bits and marks the final vertical position (0 is top)
50+
/// * `mode` is 8 bits and is currently ignored
51+
/// * `colour` is 24 bits, and is taken modulo the number of on-screen colours
52+
///
53+
/// The start position is the cursor position. The cursor is updated to the final position.
54+
///
55+
/// Use [`draw_line_value`] to construct a value.
56+
pub const COMMAND_DRAW_LINE: u64 = 4;
57+
58+
/// Calculate a 64-bit value argument for the [`COMMAND_CHUNKY_PLOT`] gfx ioctl
3359
pub fn chunky_plot_value(x: u16, y: u16, colour: u32) -> u64 {
3460
(x as u64) << 48 | (y as u64) << 32 | (colour & 0xFFFFFF) as u64
3561
}
3662

37-
/// Calculate a 64-bit value argument for a gfx ioctl
63+
/// Calculate a 64-bit value argument for the [`COMMAND_CHANGE_MODE`] gfx ioctl
3864
pub fn change_mode_value(mode: crate::VideoMode, fb_ptr: *mut u32) -> u64 {
3965
let fb_ptr = fb_ptr as usize as u64;
4066
let mode = mode.as_u8() as u64;
4167
mode << 32 | fb_ptr
4268
}
4369

70+
/// Calculate a 64-bit value argument for the [`COMMAND_MOVE_CURSOR`] gfx ioctl
71+
pub fn move_cursor_value(x: u16, y: u16) -> u64 {
72+
(x as u64) << 48 | (y as u64) << 32
73+
}
74+
75+
/// Calculate a 64-bit value argument for the [`COMMAND_DRAW_LINE`] gfx ioctl
76+
pub fn draw_line_value(end_x: u16, end_y: u16, colour: u32) -> u64 {
77+
(end_x as u64) << 48 | (end_y as u64) << 32 | (colour & 0xFFFFFF) as u64
78+
}
79+
4480
// End of file

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use neotron_ffi::{FfiBuffer, FfiByteSlice, FfiString};
2727

2828
pub use neotron_api::{file::Flags, path, Api, Error};
2929

30-
pub use neotron_common_bios::video::Mode as VideoMode;
30+
pub use neotron_common_bios::video::{Format as VideoFormat, Mode as VideoMode};
3131

3232
use neotron_api as api;
3333

0 commit comments

Comments
 (0)