Skip to content

Commit

Permalink
Merge branch 'main' into arrow_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Nov 9, 2024
2 parents 269f258 + aa96535 commit c323158
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README-pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ x86_64 System Operacyjny (kernel) zrobiony od zera w Assembly & Rust
## Budowa ze źródła na Linuxie
### Główny Kernel
**Wymagania:**
- System kontroli wersji[Git] (https://git-scm.com)
- System kontroli wersji [Git](https://git-scm.com)
- [Rust toolchain](https://www.rust-lang.org/tools/install)

**Kroki:**
Expand Down
3 changes: 1 addition & 2 deletions kernel/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ fn cc(_args: Vec<&str>) -> i32 {
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
the Free Software Foundation,version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand Down
24 changes: 24 additions & 0 deletions kernel/src/vga_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ pub struct Writer {
}

impl Writer {
fn update_cursor(&mut self) {
let pos = (BUFFER_HEIGHT - 1) * BUFFER_WIDTH + self.column_position;
unsafe {
let mut port = x86_64::instructions::port::Port::new(0x3D4);
port.write(0x0F_u8);
let mut data_port = x86_64::instructions::port::Port::new(0x3D5);
data_port.write((pos & 0xFF) as u8);
port.write(0x0E_u8);
data_port.write(((pos >> 8) & 0xFF) as u8);
}
self.buffer.chars[BUFFER_HEIGHT - 1][self.column_position].write(ScreenChar {
ascii_character: b' ',
color_code: self.color_code,
});
}

pub fn write_byte(&mut self, byte: u8) {
match byte {
b'\n' => self.new_line(),
Expand All @@ -149,6 +165,10 @@ impl Writer {
color_code,
});
self.column_position += 1;

if self.column_position < BUFFER_WIDTH {
self.update_cursor();
}
}
}
}
Expand All @@ -171,6 +191,7 @@ impl Writer {
}
self.clear_row(BUFFER_HEIGHT - 1);
self.column_position = 0;
self.update_cursor();
}

fn clear_row(&mut self, row: usize) {
Expand All @@ -188,6 +209,7 @@ impl Writer {
self.clear_row(row);
}
self.column_position = 0;
self.update_cursor();
}

pub fn change_color(&mut self, fgc: Color, bgc: Color) {
Expand All @@ -204,9 +226,11 @@ impl Writer {

pub fn decrement_column_position(&mut self) {
self.column_position -= 1;
self.update_cursor();
}
pub fn increment_column_position(&mut self) {
self.column_position += 1;
self.update_cursor();
}
pub fn get_column_position(&mut self) -> usize {
self.column_position
Expand Down

0 comments on commit c323158

Please sign in to comment.