Skip to content

Commit

Permalink
adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
realchonk committed Mar 14, 2020
1 parent 763d63f commit b607382
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
40 changes: 37 additions & 3 deletions arch/i386/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ static void set_curmode(enum VGA_Mode m) {
hbuf = getbuf();
}

inline static size_t compute_scraddr(uint16_t x, uint16_t y) {
return y * curmode.pitch + x * curmode.depth;
}

int vga_init(void) {
set_curmode(VGA_80x25_TM);
hbuf = (uint8_t*)0xb8000;
Expand Down Expand Up @@ -177,7 +181,7 @@ void ascii_blit_buf(uint8_t* buf, uint16_t x, uint16_t y, unsigned char ch, cons
const size_t addr = (yc * h + y0) * (w * 16) + (xc * w + x0);
const uint8_t byte = font->bitmap[addr / 8 + 1];
const bool val = byte & (0x80 >> (addr & 7));
const size_t scraddr = (y0 + y) * curmode.pitch + ((x0 + x) * curmode.depth);
const size_t scraddr = compute_scraddr(x0 + x, y0 + y);
buf[scraddr] = val ? fgc : bgc;
}
}
Expand All @@ -198,8 +202,38 @@ void vga_fill_rect_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_
void vga_fill_rect_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc) {
for (uint16_t y0 = 0; y0 < h; ++y0) {
for (uint16_t x0 = 0; x0 < w; ++x0) {
const size_t pos = (y + y0) * curmode.pitch + ((x + x0) * curmode.depth);
buf[pos] = cc;
buf[compute_scraddr(x0 + x, y0 + y)] = cc;
}
}
}
static uint8_t read_px(uint16_t x, uint16_t y) {
return buffer[y * curmode.pitch + x * curmode.depth];
}
void vga_blit_transparent(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels) {
const uint16_t p = w;
if (x + w >= curmode.width) w = curmode.width - x;
if (y + h >= curmode.height) h = curmode.height - y;
uint8_t* buf = buffering ? buffer : hbuf;
const uint8_t* px = (const uint8_t*)pixels;
for (uint16_t y0 = 0; y0 < h; ++y0) {
for (uint16_t x0 = 0; x0 < w; ++x0) {
const uint8_t val = px[y0 * p + x0];
if (val != 0xff) buf[compute_scraddr(x0 + x, y0 + y)] = val;
}
}
}
void vga_blit_sprite(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fgc, const void* pixels) {
const uint16_t p = w;
if (x + w >= curmode.width) w = curmode.width - x;
if (y + h >= curmode.height) h = curmode.height - y;
const uint8_t* px = (const uint8_t*)pixels;
uint8_t* buf = buffering ? buffer : hbuf;
for (uint16_t y0 = 0; y0 < h; ++y0) {
for (uint16_t x0 = 0; x0 < w; ++x0) {
const size_t saddr = y0 * p + x0;
const bool val = px[saddr / 8] & (0x80 >> (saddr & 7));
if (val) buf[compute_scraddr(x0 + x, y0 + y)] = fgc;
}
}

}
Binary file modified benos.iso
Binary file not shown.
3 changes: 3 additions & 0 deletions include/arch/i386/vga.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void vga_blit_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
void vga_blit(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);
void vga_blit_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);

void vga_blit_transparent(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);
void vga_blit_sprite(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fgc, const void* pixels);

void vga_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);
void vga_fill_rect_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);
void vga_fill_rect_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);
Expand Down
7 changes: 7 additions & 0 deletions iso/boot/grub/grub.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set timeout=0
set default=0


menuentry "BenOS" {
multiboot /boot/kernel.bin
}
Binary file modified kernel.bin
Binary file not shown.
15 changes: 13 additions & 2 deletions kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ void no_task_handler(void) {
#include "string.h"
#include "ascii.h"

static uint8_t cursor_bitmap[8] = {
0b11111111,
0b11111111,
0b11110000,
0b11110000,
0b11001100,
0b11001100,
0b11000011,
0b11000011,
};
static void vga_updater() {
static uint8_t surface[80 * 50];
static uint8_t fgc = 0xf, bgc = 0x0;
Expand Down Expand Up @@ -131,7 +141,8 @@ static void vga_updater() {
vga_fill_rect(x * 4, y * 4, 4, 4, surface[y * 80 + x]);
}
}
ascii_blit(mouse->posx, mouse->posy, 'A', &ascii8, fgc, 0x00);
vga_blit_sprite(mouse->posx, mouse->posy, 8, 8, fgc, cursor_bitmap);
//ascii_blit(mouse->posx, mouse->posy, 'A', &ascii8, fgc, 0x00);
vga_render();
}
}
Expand All @@ -147,4 +158,4 @@ static void ktest() {
//taskmgr_add(taskmgr_create_task(task1));
//taskmgr_add(taskmgr_create_task(task2));
taskmgr_add(taskmgr_create_task(vga_updater));
}
}

0 comments on commit b607382

Please sign in to comment.