Compare commits

...

4 Commits

Author SHA1 Message Date
9c09fe7cec init: add a check_magic function 2022-10-31 14:34:32 +01:00
9902506264 video: Add a Color enum to make it easier to work with colors 2022-10-31 14:34:09 +01:00
ab4d34ecdb Add Cargo.lock to gitignore 2022-10-31 14:33:37 +01:00
c167b7a247 remove .clang-format 2022-10-31 14:33:19 +01:00
5 changed files with 46 additions and 22 deletions

View File

@ -1,12 +0,0 @@
---
BasedOnStyle: Microsoft
CompactNamespaces: 'false'
FixNamespaceComments: 'false'
NamespaceIndentation: All
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: 'true'
PointerAlignment: Left

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ Luna.iso
toolchain/ toolchain/
.vscode/ .vscode/
initrd/boot/ initrd/boot/
moon/target/** moon/target/**
**/Cargo.lock

7
moon/src/init.rs Normal file
View File

@ -0,0 +1,7 @@
use crate::bootboot::{BOOTBOOT, BOOTBOOT_MAGIC};
use crate::util::get_bootboot;
pub fn check_magic() -> () {
let boot: BOOTBOOT = get_bootboot();
assert_eq!(boot.magic, BOOTBOOT_MAGIC[..4]);
}

View File

@ -5,9 +5,13 @@ mod video;
mod bootboot; mod bootboot;
mod panic; mod panic;
mod util; mod util;
mod init;
use video::Color;
#[no_mangle] #[no_mangle]
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
video::clear(0xffffffff); init::check_magic();
video::clear(Color::White);
loop {} loop {}
} }

View File

@ -1,27 +1,51 @@
#![allow(dead_code)]
use crate::bootboot::{BOOTBOOT, BOOTBOOT_FB}; use crate::bootboot::{BOOTBOOT, BOOTBOOT_FB};
use crate::util::get_bootboot; use crate::util::get_bootboot;
use BOOTBOOT_FB as FB; use BOOTBOOT_FB as FB;
pub fn put_pixel(x: u32, y: u32, color: u32) -> () { #[allow(dead_code)]
let boot: BOOTBOOT = get_bootboot(); #[derive(Debug, Clone, Copy, PartialEq, Eq)]
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64; #[repr(u32)]
unsafe { *(ptr as *mut u32) = color }; pub enum Color {
Black = 0x00000000,
Blue = 0xff0000ff,
Green = 0xff00ff00,
Cyan = 0xff00ffff,
Red = 0xffff0000,
Magenta = 0xffff00ff,
Brown = 0xff231709,
LightGray = 0xffb9b8b5,
DarkGray = 0xff808080,
LightBlue = 0xff317ecc,
LightGreen = 0xff6aab8e,
LightCyan = 0xffe0ffff,
LightRed = 0xffff7377,
Pink = 0xffffc0cb,
Yellow = 0xffffff00,
White = 0xffffffff,
} }
pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: u32) -> () { pub fn put_pixel(x: u32, y: u32, color: Color) -> () {
let boot: BOOTBOOT = get_bootboot();
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64;
unsafe { *(ptr as *mut u32) = color as u32 };
}
pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: Color) -> () {
let boot: BOOTBOOT = get_bootboot(); let boot: BOOTBOOT = get_bootboot();
for i in y..(y + height) for i in y..(y + height)
{ {
let addr: u64 = FB + (boot.fb_scanline * i) as u64 + (x * 4) as u64; let addr: u64 = FB + (boot.fb_scanline * i) as u64 + (x * 4) as u64;
for ptr in (addr..(addr + (width*4) as u64)).step_by(4) for ptr in (addr..(addr + (width*4) as u64)).step_by(4)
{ {
unsafe { *(ptr as *mut u32) = color }; unsafe { *(ptr as *mut u32) = color as u32 };
} }
} }
} }
pub fn clear(color: u32) -> () { pub fn clear(color: Color) -> () {
let boot: BOOTBOOT = get_bootboot(); let boot: BOOTBOOT = get_bootboot();
draw_rect(0, 0, boot.fb_width, boot.fb_height, color) draw_rect(0, 0, boot.fb_width, boot.fb_height, color)
} }