Skip to content

Commit

Permalink
Add random line drawing to vidtest
Browse files Browse the repository at this point in the history
  • Loading branch information
thejpster committed Dec 30, 2024
1 parent 6bc14f7 commit 0cd6824
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions utilities/snake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl App {
self.clear_screen();
self.title_screen();

let mut seed: u16 = 0x4f34;
let mut seed: u32 = 0x4f34;

'outer: loop {
'inner: loop {
Expand Down Expand Up @@ -419,8 +419,8 @@ impl Game {
loop {
// This isn't equally distributed. I don't really care.
let pos = console::Position {
row: (neotron_sdk::rand() % self.height as u16) as u8,
col: (neotron_sdk::rand() % self.width as u16) as u8,
row: neotron_sdk::random_in(0..self.height as u32) as u8,
col: neotron_sdk::random_in(0..self.width as u32) as u8,
};
if self.board.is_empty(pos) {
return pos;
Expand Down
43 changes: 43 additions & 0 deletions utilities/vidtest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub fn main() -> i32 {
if let Err(e) = radial(&handle, mode) {
_ = writeln!(stdout, "Draw failure on radial: {:?}", e);
}
if let Err(e) = random_lines(&handle, mode) {
_ = writeln!(stdout, "Draw failure on random_lines: {:?}", e);
}
}

0
Expand Down Expand Up @@ -243,6 +246,46 @@ fn radial(
Ok(())
}

/// plots some random lines, with all the colours
fn random_lines(
handle: &neotron_sdk::File,
mode: neotron_sdk::VideoMode,
) -> Result<(), neotron_sdk::Error> {
neotron_sdk::srand(1);

unsafe { handle.ioctl(neotron_sdk::ioctls::gfx::COMMAND_CLEAR_SCREEN, 0) }?;
let width_range = 0..mode.horizontal_pixels() as u32;
let height_range = 0..mode.vertical_lines() as u32;

while !kbhit() {
let x0 = neotron_sdk::random_in(width_range.clone());
let x1 = neotron_sdk::random_in(width_range.clone());
let y0 = neotron_sdk::random_in(height_range.clone());
let y1 = neotron_sdk::random_in(height_range.clone());
let colour = neotron_sdk::random_in(0..(1 << 24));
unsafe {
handle.ioctl(
neotron_sdk::ioctls::gfx::COMMAND_MOVE_CURSOR,
neotron_sdk::ioctls::gfx::move_cursor_value(x0 as u16, y0 as u16),
)
}?;
unsafe {
handle.ioctl(
neotron_sdk::ioctls::gfx::COMMAND_DRAW_LINE,
neotron_sdk::ioctls::gfx::draw_line_value(x1 as u16, y1 as u16, colour),
)
}?;
}

Ok(())
}

fn kbhit() -> bool {
let stdin = neotron_sdk::stdin();
let mut buffer = [0u8; 1];
stdin.read(&mut buffer) != Ok(0)
}

fn wait_for_key() {
let stdin = neotron_sdk::stdin();
let mut buffer = [0u8; 1];
Expand Down

0 comments on commit 0cd6824

Please sign in to comment.