Adds sample rust program

This commit is contained in:
2025-11-15 02:11:00 +01:00
parent ae0e33132e
commit 674c399ef6
4 changed files with 100 additions and 84 deletions

View File

@@ -4,87 +4,39 @@
use core::arch::asm;
use fpga_lib::{
interface::{Buttons, Leds},
panic_handler,
register::X31,
vga::{BLUE, FONT_WIDTH, GREEN, RED, VGA, WHITE},
vga::{BLACK, BLUE, FONT_WIDTH, GREEN, RED, VGA, WHITE},
};
panic_handler! {}
#[inline(never)]
pub fn magic(x: &mut u16, y: &mut u16, z: &mut bool, i: u16, j: u16)
{
if *x > i && *y < 198 && *z
{
unsafe { VGA::write_pixel_unsafe(i, j, GREEN) };
}
else
{
unsafe { VGA::write_pixel_unsafe(i, j, RED) };
}
//*x += 1;
*y -= 1;
}
#[unsafe(no_mangle)]
pub extern "C" fn main() -> !
{
let mut x = core::hint::black_box(100u16);
let mut y = core::hint::black_box(192);
let mut z = core::hint::black_box(true);
let x = core::hint::black_box(&mut x);
let y = core::hint::black_box(&mut y);
let z = core::hint::black_box(&mut z);
for i in 0..(*x)
{
magic(x, y, z, i, i);
}
// if (c as u8 > b'~') || ((c as u8) < b' ')
// {
// X31::write_const::<0x01>();
// }
// else
// {
// X31::write_const::<0xFFFFFFFFFFFFFFFF>();
// };
//
// if (c as u8 > b'~') || ((c as u8) < b' ')
// {
// X31::write_const::<0x01>();
// }
// else
// {
// X31::write_const::<0xFFFFFFFFFFFFFFFF>();
// };
// for i in 0..100
// {
// unsafe { VGA::write_pixel_unsafe(i, i, WHITE) };
// }
//
// let mut a = core::hint::black_box(true);
// let mut x = core::hint::black_box(121);
// let mut y = core::hint::black_box(221);
// for i in 0..100
// {
// if i < x && i < y && a
// {
// unsafe {
// //VGA::write_pixel_unsafe(i, i, WHITE);
// }
// }
// }
// let mut a = core::hint::black_box(true);
// if a
// {
// X31::write_const::<0xdead1ffffffff>();
// }
loop
{}
{
unsafe {
VGA::draw_string(10, 10, "Running RUST !", GREEN);
VGA::draw_string(10, 23, "LedIp state :", RED);
for i in 0..4
{
VGA::draw_char(10 + i * 16, 46, 'B', RED);
VGA::draw_char(16 + i * 16, 46, (b'0' + i as u8) as char, RED);
if Buttons::get_button(i as u8)
{
Leds::set_led(i as u8, true);
VGA::draw_char_bg(10 + i * 16, 59, '1', GREEN, BLACK);
}
else
{
Leds::set_led(i as u8, false);
VGA::draw_char_bg(10 + i * 16, 59, '0', RED, BLACK);
}
}
}
}
}