Color video works!!!!!!!!!!!!!!!!!!!

This commit is contained in:
Gvidas Juknevičius 2024-09-03 16:03:07 +03:00
parent 08b2d22662
commit 4349fe9c6e
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
5 changed files with 26 additions and 17 deletions

View File

@ -131,7 +131,7 @@ case $1 in
build_dev
;;
run-qemu-gdb)
build
build_dev
run_qemu_gdb
;;
*)

View File

@ -42,7 +42,7 @@ extern "C" fn kmain(mb2p: *const BootInformationHeader) -> ! {
let vc = std::vga::video::VideoControler::new(mb2p);
// vc.set_px(0, 0, Color::new(0xFF, 0xFF, 0x0));
// vc.fill_screen(Color::new(0xFF, 0x0, 0x0));
vc.fill_screen(Color::new(0xFF, 0x0, 0x66));
log::info!("end of work");
loop {

View File

@ -152,7 +152,7 @@ impl MemInfo<'_> {
let mb_end = boot_info.end_address();
let vv_info = boot_info.framebuffer_tag().unwrap().unwrap();
let vv_start = vv_info.address();
let vv_size = vv_info.width() * vv_info.height();
let vv_size = vv_info.pitch() * vv_info.height();
//log::debug!("Kernel: start: 0x{:x} sz: 0x{:x}", mi.kernel_start, mi.kernel_end - mi.kernel_start);
//log::debug!("Multiboot: start: 0x{:x} sz: 0x{:x}", mi.mb_start, mi.mb_end - mi.mb_start);

View File

@ -206,12 +206,14 @@ pub fn remap_the_kernel<A>(allocator: &mut A, mem_info: &MemInfo) -> ActivePageT
}
}
let vga_text_buffer_frame = Frame::containing_address(0xb8000);
let vga_video_buffer_frame_start = Frame::containing_address(mem_info.vga_vide_start);
let vga_video_buffer_frame_end = Frame::containing_address((mem_info.vga_vide_start + mem_info.vga_vide_size*3));
for frame in Frame::range_inclusive(vga_video_buffer_frame_start, vga_video_buffer_frame_end) {
mapper.identity_map(frame, EntryFlags::PRESENT | EntryFlags::WRITABLE, allocator);
}
mapper.identity_map(vga_text_buffer_frame, EntryFlags::WRITABLE, allocator);
let vga_video_buffer_frame_start = Frame::containing_address(mem_info.vga_vide_start);
let vga_video_buffer_frame_end = Frame::containing_address(mem_info.vga_vide_start + (mem_info.vga_vide_size*4));
for frame in Frame::range_inclusive(vga_video_buffer_frame_start, vga_video_buffer_frame_end) {
mapper.identity_map(frame, EntryFlags::WRITABLE | EntryFlags::WRITE_THROUGH, allocator);
}
let multiboot_start = Frame::containing_address(mem_info.boot_info.start_address());
let multiboot_end = Frame::containing_address(mem_info.boot_info.end_address() - 1);
for frame in Frame::range_inclusive(multiboot_start, multiboot_end) {

View File

@ -28,7 +28,9 @@ pub struct VideoControler{
g_ofs: u8,
b_ofs: u8,
buf_addr: u64,
pitch: usize,
size: Vector2<usize>,
bpp: u8
}
impl VideoControler {
@ -38,32 +40,37 @@ impl VideoControler {
let FramebufferType::RGB { red, green, blue } = fbt.buffer_type().unwrap() else {
panic!();
};
assert!(red.size == green.size && green.size == blue.size);
log::info!("VGA VIDEO adddr: {:x}", fbt.address());
log::info!("VGA VIDEO FB TYPE: {:?}", fbt.buffer_type());
log::info!("VGA VIDEO addr: {:x}", fbt.address());
log::info!("{fbt:#?}");
Self {
component_size: red.size,
r_ofs: red.position,
g_ofs: green.position,
b_ofs: blue.position,
buf_addr: fbt.address(),
size: Vector2::new(fbt.width() as usize, fbt.height() as usize)
size: Vector2::new(fbt.width() as usize, fbt.height() as usize),
pitch: fbt.pitch() as usize,
bpp: fbt.bpp(),
}
}
pub fn set_px(&self, x: usize, y: usize, c: Color) {
assert!(x <= self.size.x && y <= self.size.x);
let ptr = self.buf_addr as *mut () as *mut u8;
let px = ptr.wrapping_add(x * self.size.x + y);
let px = ptr.wrapping_add((self.bpp / 8) as usize * x + self.pitch * y);
unsafe {
*px.wrapping_add((self.r_ofs % 8) as usize) = c.r;
*px.wrapping_add((self.g_ofs % 8) as usize) = c.g;
*px.wrapping_add((self.b_ofs % 8) as usize) = c.b;
*px.wrapping_add((self.r_ofs / 8) as usize) = c.r;
*px.wrapping_add((self.g_ofs / 8) as usize) = c.g;
*px.wrapping_add((self.b_ofs / 8) as usize) = c.b;
}
}
pub fn fill_screen(&self, c: Color) {
for x in 0..100 {
for y in 0..100 {
for x in 0..self.size.x {
for y in 0..self.size.y {
self.set_px(x, y, c);
}
}