Advertisement
Guest User

Rustboot Modified

a guest
Feb 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.06 KB | None | 0 0
  1. #![feature(no_std)]
  2. #![no_std]
  3. #![allow(ctypes)]
  4.  
  5. enum Color {
  6.     Black      = 0,
  7.     Blue       = 1,
  8.     Green      = 2,
  9.     Cyan       = 3,
  10.     Red        = 4,
  11.     Pink       = 5,
  12.     Brown      = 6,
  13.     LightGray  = 7,
  14.     DarkGray   = 8,
  15.     LightBlue  = 9,
  16.     LightGreen = 10,
  17.     LightCyan  = 11,
  18.     LightRed   = 12,
  19.     LightPink  = 13,
  20.     Yellow     = 14,
  21.     White      = 15,
  22. }
  23.  
  24. enum Option<T> {
  25.     None,
  26.     Some(T)
  27. }
  28.  
  29. struct IntRange {
  30.     cur: i32,
  31.     max: i32
  32. }
  33.  
  34. impl IntRange {
  35.     fn next(&mut self) -> Option<i32> {
  36.         if self.cur < self.max {
  37.             self.cur += 1;
  38.             Option::Some(self.cur - 1)
  39.         } else {
  40.             Option::None
  41.         }
  42.     }
  43. }
  44.  
  45. fn range(lo: i32, hi: i32) -> IntRange {
  46.     IntRange { cur: lo, max: hi }
  47. }
  48.  
  49. fn clear_screen(background: Color) {
  50.     for i in range(0, 80 * 25) {
  51.         unsafe {
  52.             *((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
  53.         }
  54.     }
  55. }
  56.  
  57. #[no_mangle]
  58. pub fn main() {
  59.     clear_screen(Color::LightRed);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement