Skip to content

Commit

Permalink
Now works with rustc 0.13.0-nightly 2015-01-02. Based on pull request h…
Browse files Browse the repository at this point in the history
…aileys#25 and issue haileys#26 from the main repository.
  • Loading branch information
thesam committed Jan 4, 2015
1 parent 36f2f07 commit 82901db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LD=i386-elf-ld
LD=ld
RUSTC=rustc
NASM=nasm
QEMU=qemu-system-i386
Expand All @@ -10,7 +10,7 @@ all: floppy.img
.PHONY: clean run

.rs.o:
$(RUSTC) -O --target i386-intel-linux --crate-type lib -o $@ --emit obj $<
$(RUSTC) -O --target i686-unknown-linux-gnu --crate-type lib -o $@ --emit obj $<

.asm.o:
$(NASM) -f elf32 -o $@ $<
Expand Down
32 changes: 24 additions & 8 deletions main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#![no_std]
#![allow(ctypes)]

#![feature(lang_items)]
#[lang="sized"]
trait Sized {}

#[lang="copy"]
trait Copy {}

impl Copy for Color {
}

enum Color {
Black = 0,
Blue = 1,
Expand Down Expand Up @@ -34,9 +44,9 @@ impl IntRange {
fn next(&mut self) -> Option<int> {
if self.cur < self.max {
self.cur += 1;
Some(self.cur - 1)
Option::Some(self.cur - 1)
} else {
None
Option::None
}
}
}
Expand All @@ -46,15 +56,21 @@ fn range(lo: int, hi: int) -> IntRange {
}

fn clear_screen(background: Color) {
for i in range(0, 80 * 25) {
unsafe {
*((0xb8000 + i * 2) as *mut u16) = (background as u16) << 12;
}
}
let mut r = range(0, 80 * 25);
loop {
match r.next() {
Option::Some(x) => {
unsafe {
*((0xb8000 + x * 2) as *mut u16) = (background as u16) << 12;
}
},
Option::None =>{break}
}
}
}

#[no_mangle]
#[no_split_stack]
pub fn main() {
clear_screen(LightRed);
clear_screen(Color::LightRed);
}

0 comments on commit 82901db

Please sign in to comment.