Skip to content

Commit b607382

Browse files
committed
adding files
1 parent 763d63f commit b607382

File tree

6 files changed

+60
-5
lines changed

6 files changed

+60
-5
lines changed

arch/i386/vga.c

+37-3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ static void set_curmode(enum VGA_Mode m) {
104104
hbuf = getbuf();
105105
}
106106

107+
inline static size_t compute_scraddr(uint16_t x, uint16_t y) {
108+
return y * curmode.pitch + x * curmode.depth;
109+
}
110+
107111
int vga_init(void) {
108112
set_curmode(VGA_80x25_TM);
109113
hbuf = (uint8_t*)0xb8000;
@@ -177,7 +181,7 @@ void ascii_blit_buf(uint8_t* buf, uint16_t x, uint16_t y, unsigned char ch, cons
177181
const size_t addr = (yc * h + y0) * (w * 16) + (xc * w + x0);
178182
const uint8_t byte = font->bitmap[addr / 8 + 1];
179183
const bool val = byte & (0x80 >> (addr & 7));
180-
const size_t scraddr = (y0 + y) * curmode.pitch + ((x0 + x) * curmode.depth);
184+
const size_t scraddr = compute_scraddr(x0 + x, y0 + y);
181185
buf[scraddr] = val ? fgc : bgc;
182186
}
183187
}
@@ -198,8 +202,38 @@ void vga_fill_rect_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_
198202
void vga_fill_rect_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc) {
199203
for (uint16_t y0 = 0; y0 < h; ++y0) {
200204
for (uint16_t x0 = 0; x0 < w; ++x0) {
201-
const size_t pos = (y + y0) * curmode.pitch + ((x + x0) * curmode.depth);
202-
buf[pos] = cc;
205+
buf[compute_scraddr(x0 + x, y0 + y)] = cc;
206+
}
207+
}
208+
}
209+
static uint8_t read_px(uint16_t x, uint16_t y) {
210+
return buffer[y * curmode.pitch + x * curmode.depth];
211+
}
212+
void vga_blit_transparent(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels) {
213+
const uint16_t p = w;
214+
if (x + w >= curmode.width) w = curmode.width - x;
215+
if (y + h >= curmode.height) h = curmode.height - y;
216+
uint8_t* buf = buffering ? buffer : hbuf;
217+
const uint8_t* px = (const uint8_t*)pixels;
218+
for (uint16_t y0 = 0; y0 < h; ++y0) {
219+
for (uint16_t x0 = 0; x0 < w; ++x0) {
220+
const uint8_t val = px[y0 * p + x0];
221+
if (val != 0xff) buf[compute_scraddr(x0 + x, y0 + y)] = val;
203222
}
204223
}
224+
}
225+
void vga_blit_sprite(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fgc, const void* pixels) {
226+
const uint16_t p = w;
227+
if (x + w >= curmode.width) w = curmode.width - x;
228+
if (y + h >= curmode.height) h = curmode.height - y;
229+
const uint8_t* px = (const uint8_t*)pixels;
230+
uint8_t* buf = buffering ? buffer : hbuf;
231+
for (uint16_t y0 = 0; y0 < h; ++y0) {
232+
for (uint16_t x0 = 0; x0 < w; ++x0) {
233+
const size_t saddr = y0 * p + x0;
234+
const bool val = px[saddr / 8] & (0x80 >> (saddr & 7));
235+
if (val) buf[compute_scraddr(x0 + x, y0 + y)] = fgc;
236+
}
237+
}
238+
205239
}

benos.iso

6 KB
Binary file not shown.

include/arch/i386/vga.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ void vga_blit_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
3939
void vga_blit(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);
4040
void vga_blit_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);
4141

42+
void vga_blit_transparent(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const void* pixels);
43+
void vga_blit_sprite(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fgc, const void* pixels);
44+
4245
void vga_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);
4346
void vga_fill_rect_direct(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);
4447
void vga_fill_rect_buf(uint8_t* buf, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t cc);

iso/boot/grub/grub.cfg

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set timeout=0
2+
set default=0
3+
4+
5+
menuentry "BenOS" {
6+
multiboot /boot/kernel.bin
7+
}

kernel.bin

6.93 KB
Binary file not shown.

kernel/kernel.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ void no_task_handler(void) {
8686
#include "string.h"
8787
#include "ascii.h"
8888

89+
static uint8_t cursor_bitmap[8] = {
90+
0b11111111,
91+
0b11111111,
92+
0b11110000,
93+
0b11110000,
94+
0b11001100,
95+
0b11001100,
96+
0b11000011,
97+
0b11000011,
98+
};
8999
static void vga_updater() {
90100
static uint8_t surface[80 * 50];
91101
static uint8_t fgc = 0xf, bgc = 0x0;
@@ -131,7 +141,8 @@ static void vga_updater() {
131141
vga_fill_rect(x * 4, y * 4, 4, 4, surface[y * 80 + x]);
132142
}
133143
}
134-
ascii_blit(mouse->posx, mouse->posy, 'A', &ascii8, fgc, 0x00);
144+
vga_blit_sprite(mouse->posx, mouse->posy, 8, 8, fgc, cursor_bitmap);
145+
//ascii_blit(mouse->posx, mouse->posy, 'A', &ascii8, fgc, 0x00);
135146
vga_render();
136147
}
137148
}
@@ -147,4 +158,4 @@ static void ktest() {
147158
//taskmgr_add(taskmgr_create_task(task1));
148159
//taskmgr_add(taskmgr_create_task(task2));
149160
taskmgr_add(taskmgr_create_task(vga_updater));
150-
}
161+
}

0 commit comments

Comments
 (0)