Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AWOLASAP/Operating-System
Browse files Browse the repository at this point in the history
…into master
  • Loading branch information
otisdog8 committed Aug 7, 2020
2 parents d079437 + b472513 commit 6526a23
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 80 deletions.
22 changes: 8 additions & 14 deletions os/src/brainf.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use lazy_static::lazy_static;
use spin::{Mutex};
use crate::vga_buffer::ADVANCED_WRITER;
use vga::colors::Color16;
use alloc::vec::Vec;
use alloc::vec;
use alloc::string::String;
use crate::ustar::USTARFS;
use crate::println;
use crate::keyboard_routing::KEYBOARD_ROUTER;
use crate::timer_routing::TIME_ROUTER;
use x86_64::instructions::interrupts;
use crate::vga_buffer::PrintWriter;
use crate::alloc::string::ToString;
use crate::commands::COMMANDRUNNER;
use alloc::collections::vec_deque::VecDeque;
// This is probably not going to be "real" vi, but enough of a clone to do basic stuff.

const SCREEN_WIDTH: usize = 76;
const SCREEN_HEIGHT: usize = 56;

//
//

pub struct BrainF {
instructions: Vec<u8>,
Expand Down Expand Up @@ -48,7 +42,7 @@ impl BrainF {
}
}

// Exits on
// Exits on
pub fn bf_loop(&mut self) -> bool {
loop {
if let Some(instruction) = self.instructions.get(self.instruction_pointer) {
Expand Down Expand Up @@ -151,7 +145,7 @@ impl BrainF {
self.data.reserve(index - self.data.capacity() + 1);
println!("Successfully");
}
for i in self.data.len()..self.data.capacity() {
for _ in self.data.len()..self.data.capacity() {
self.data.push(0);
}
}
Expand All @@ -165,19 +159,19 @@ impl BrainF {
#[inline]
pub fn set_data_at(&mut self, index: usize, data: u8) {
self.init_to_index(index);
self.data[index] = data;
self.data[index] = data;
}

#[inline]
pub fn inc_data_at(&mut self, index: usize) {
self.init_to_index(index);
self.data[index] += 1;
self.data[index] += 1;
}

#[inline]
pub fn dec_data_at(&mut self, index: usize) {
self.init_to_index(index);
self.data[index] -= 1;
self.data[index] -= 1;
}

#[inline]
Expand Down Expand Up @@ -210,7 +204,7 @@ impl BrainF {
println!("File doesn't exist");

}

}

pub fn init_file(&mut self, file: String, file2: String, id: Option<u64>) {
Expand Down Expand Up @@ -249,7 +243,7 @@ impl BrainF {
//print!("[user@rust {}]# ", USTARFS.lock().cwd(COMMANDRUNNER.lock().dir_id));
});
}

}

lazy_static! {
Expand Down
2 changes: 1 addition & 1 deletion os/src/keyboard_routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use lazy_static::lazy_static;
use crate::vga_buffer::{MODE, WRITER, ADVANCED_WRITER, PrintWriter};
use pc_keyboard::{layouts, DecodedKey, Keyboard, ScancodeSet1, KeyCode};
use spin::Mutex;
use crate::{add_command_buffer, move_command_cursor, end_tet_ost};
use crate::{move_command_cursor, end_tet_ost};
use crate::tetris::TETRIS;
use crate::vi::FAKE_VIM;
use crate::brainf::BRAINF;
Expand Down
29 changes: 1 addition & 28 deletions os/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ fn panic(info: &PanicInfo) -> ! {
os::test_panic_handler(info)
}

async fn async_number() -> u32 {
42
}

async fn example_task() {
let number = async_number().await;
println!("async number: {}", number);
}

// creates the entry point for the application
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! {
Expand Down Expand Up @@ -93,30 +84,12 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
//USTARFS.lock().print_root();
COMMANDRUNNER.lock().init();

//for i in 0..16 {
// let x: u8 = i * 4; //
// println!(" \n{} {} {} {}: {}", x as char, (x + 1) as char, (x + 2) as char, (x + 3) as char, x);
//}

//let mut executor = Executor::new();
//executor.spawn(Task::new(example_task()));
//executor.spawn(Task::new(keyboard::print_keypresses()));
//executor.run();
print!("[user@rust /]# ");
COMMANDRUNNER.lock().prompt_length = 15;
//EXECUTOR.lock().spawn(Task::new(example_task()));
EXECUTOR.lock().spawn(Task::new(keyboard::print_keypresses()));
EXECUTOR.lock().run();
}
//let mut executor = Executor::new();
//executor.spawn(Task::new(example_task()));
//executor.spawn(Task::new(keyboard::print_keypresses()));
//executor.run();
//os::hlt_loop();

//for i in 0..60 {
// println!("{}", i);
//};

// This is an example on how to reactivate text mode and deactivate graphics mode.
// This then changes the background and foreground color.
// MODE.lock().text_init();
Expand Down
8 changes: 4 additions & 4 deletions os/src/tetris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct RenderPiece {

#[derive(Serialize, Deserialize)]
struct HighScoreItem {
scorer: String,
scorer: String,
score: usize,
}

Expand Down Expand Up @@ -507,7 +507,7 @@ impl Tetris {
},

}

}

// Handles serde deseralization
Expand Down Expand Up @@ -568,7 +568,7 @@ impl Tetris {
TIME_ROUTER.lock().mode.terminal = true;
TIME_ROUTER.lock().mode.tetris = false;
ADVANCED_WRITER.lock().wipe_buffer();
println!();
println!();
}
}
}
Expand Down Expand Up @@ -712,7 +712,7 @@ impl Tetris {
}
}
}

});
self.old_rendered_board = composited_board;
let held_piece = self.deserialize_held_piece();
Expand Down
63 changes: 30 additions & 33 deletions os/src/vi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Default for FakeVim {
impl FakeVim {
pub fn new() -> Self {
FakeVim{
data: Vec::new(),
data: Vec::new(),
data_screen_index: 0,
colon_pressed: false,
is_active: false,
Expand Down Expand Up @@ -108,7 +108,7 @@ impl FakeVim {
},
}
}
//Delete
//Delete
// Arrow Keys + vim keys
// Command mode
// Keyboard input
Expand All @@ -117,9 +117,6 @@ impl FakeVim {
pub fn handle_command(&mut self, command: char) {
if command == '\n' {
//Process command
unsafe {

}
for i in self.command_buffer.to_string().as_bytes() {
match *i as char {
'i' => {
Expand Down Expand Up @@ -200,7 +197,7 @@ impl FakeVim {
}

pub fn page_up_half(&mut self) {
for j in 0..(SCREEN_HEIGHT / 2) {
for _ in 0..(SCREEN_HEIGHT / 2) {
if self.data_screen_index > SCREEN_WIDTH {
self.data_screen_index -= SCREEN_WIDTH;
for i in (0..(SCREEN_WIDTH - 1)).rev() {
Expand All @@ -220,7 +217,7 @@ impl FakeVim {
}

pub fn page_up(&mut self) {
for j in 0..SCREEN_HEIGHT {
for _ in 0..SCREEN_HEIGHT {
if self.data_screen_index > SCREEN_WIDTH {
self.data_screen_index -= SCREEN_WIDTH;
for i in (0..(SCREEN_WIDTH - 1)).rev() {
Expand Down Expand Up @@ -265,7 +262,7 @@ impl FakeVim {
}

pub fn page_down_half(&mut self) {
for j in 0..(SCREEN_HEIGHT / 2) {
for _ in 0..(SCREEN_HEIGHT / 2) {
let mut broke = false;
for i in 0..SCREEN_WIDTH {
if let Some(chr) = self.data.get(self.data_screen_index + i) {
Expand All @@ -284,7 +281,7 @@ impl FakeVim {
}

pub fn page_down(&mut self) {
for j in 0..SCREEN_HEIGHT {
for _ in 0..SCREEN_HEIGHT {
let mut broke = false;
for i in 0..SCREEN_WIDTH {
if let Some(chr) = self.data.get(self.data_screen_index + i) {
Expand Down Expand Up @@ -374,9 +371,9 @@ impl FakeVim {

}
}

pub fn render_buffer(&mut self) {
// Use the buffer for diffs, and render directly off the vector
// Use the buffer for diffs, and render directly off the vector
let mut x = 0;
let mut y = 0;
//ADVANCED_WRITER.lock().clear_screen(Color16::Black);
Expand All @@ -386,19 +383,19 @@ impl FakeVim {
if *d == 10 {
self.char_buffer[y][x] = '\n';
ADVANCED_WRITER.lock().draw_char(
(x + 2) * 8,
(y + 2) * 8,
0 as char,
Color16::Black,
(x + 2) * 8,
(y + 2) * 8,
0 as char,
Color16::Black,
Color16::Black,
);
for j in (x + 1)..SCREEN_WIDTH {
if self.char_buffer[y][j] != 0 as char {
ADVANCED_WRITER.lock().draw_char(
(j + 2) * 8,
(y + 2) * 8,
0 as char,
Color16::Black,
(j + 2) * 8,
(y + 2) * 8,
0 as char,
Color16::Black,
Color16::Black,
);
self.char_buffer[y][j] = 0 as char;
Expand All @@ -410,10 +407,10 @@ impl FakeVim {
// Conditional rendering is mostly bugged, we don't care though
else {
ADVANCED_WRITER.lock().draw_char(
(x + 2) * 8,
(y + 2) * 8,
*d as char,
Color16::White,
(x + 2) * 8,
(y + 2) * 8,
*d as char,
Color16::White,
Color16::Black,
);
self.char_buffer[y][x] = *d as char;
Expand All @@ -433,7 +430,7 @@ impl FakeVim {
ADVANCED_WRITER.lock().clear_buffer();
println!("insert");
}



}
Expand All @@ -442,7 +439,7 @@ impl FakeVim {
// Include things like line changing logic
// Insert the character at the cursor (before)

// Use the buffer for diffs, and render directly off the vector
// Use the buffer for diffs, and render directly off the vector
let mut x = 0;
let mut y = 0;
//ADVANCED_WRITER.lock().clear_screen(Color16::Black);
Expand Down Expand Up @@ -492,10 +489,10 @@ impl FakeVim {
interrupts::without_interrupts(|| {
self.blink_on = false;
ADVANCED_WRITER.lock().draw_char(
(self.cursor_x as usize + 2) * 8,
(self.cursor_y as usize + 2) * 8,
self.char_buffer[self.cursor_y as usize][self.cursor_x as usize],
Color16::White,
(self.cursor_x as usize + 2) * 8,
(self.cursor_y as usize + 2) * 8,
self.char_buffer[self.cursor_y as usize][self.cursor_x as usize],
Color16::White,
Color16::Black,
);
});
Expand All @@ -505,10 +502,10 @@ impl FakeVim {
interrupts::without_interrupts(|| {
self.blink_on = true;
ADVANCED_WRITER.lock().draw_char(
(self.cursor_x as usize + 2) * 8,
(self.cursor_y as usize + 2) * 8,
self.char_buffer[self.cursor_y as usize][self.cursor_x as usize],
Color16::White,
(self.cursor_x as usize + 2) * 8,
(self.cursor_y as usize + 2) * 8,
self.char_buffer[self.cursor_y as usize][self.cursor_x as usize],
Color16::White,
Color16::White,
);
});
Expand Down

0 comments on commit 6526a23

Please sign in to comment.