mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Made screen.h more generic, instead of just assuming 1920x1080 32bpp mode
This commit is contained in:
+27
-14
@@ -6,6 +6,8 @@
|
|||||||
#define MODE_INFO_BLOCK 0x5000
|
#define MODE_INFO_BLOCK 0x5000
|
||||||
#define BG_COLOR 0xff010b17
|
#define BG_COLOR 0xff010b17
|
||||||
#define FG_COLOR 0xffebddf4
|
#define FG_COLOR 0xffebddf4
|
||||||
|
#define CHAR_WIDTH 8
|
||||||
|
#define CHAR_HEIGHT 16
|
||||||
|
|
||||||
typedef struct modeInfoBlock_s {
|
typedef struct modeInfoBlock_s {
|
||||||
// Required by all VBE revisions
|
// Required by all VBE revisions
|
||||||
@@ -74,23 +76,29 @@ static char* font = (char*)0x6000;
|
|||||||
static struct cursor_s cursor = { 0, 0 };
|
static struct cursor_s cursor = { 0, 0 };
|
||||||
static modeInfoBlock_t* gfxMode = (modeInfoBlock_t*)MODE_INFO_BLOCK;
|
static modeInfoBlock_t* gfxMode = (modeInfoBlock_t*)MODE_INFO_BLOCK;
|
||||||
|
|
||||||
// TODO: Probably make the font bigger in a better way, but this works for now
|
uint32_t bgColor = BG_COLOR;
|
||||||
|
uint32_t fgColor = FG_COLOR;
|
||||||
|
|
||||||
void putcAt(unsigned char c, uint32_t x, uint32_t y) {
|
void putcAt(unsigned char c, uint32_t x, uint32_t y) {
|
||||||
uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr;
|
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
|
||||||
uint32_t offset = (gfxMode->xRes * y * 16 + x * 8) * 2;
|
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;
|
||||||
|
uint32_t offset = (gfxMode->xRes * y * CHAR_HEIGHT + x * CHAR_WIDTH) * bytesPerPx;
|
||||||
|
|
||||||
char* bitmap = &font[((c % 128) - 1) * 16];
|
char* bitmap = &font[((c % 128) - 1) * 16];
|
||||||
for (uint8_t i = 0; i < 32; i++) { // Rows (16*2 since we draw font 2x larger)
|
for (uint8_t i = 0; i < CHAR_HEIGHT; i++) { // Rows
|
||||||
char bitmapRow = bitmap[i/2]; // Idk if this should work, because i'm scared of division
|
char bitmapRow = bitmap[i];
|
||||||
|
|
||||||
for (uint8_t j = 0; j < 16; j++) { // Cols (8*2 same as rows)
|
for (uint8_t j = 0; j < CHAR_WIDTH * bytesPerPx; ++j) { // Cols
|
||||||
vidmem[offset + j] = (bitmapRow & 0x80) ? FG_COLOR : BG_COLOR;
|
uint32_t color = (bitmapRow & 0x80) ? fgColor : bgColor;
|
||||||
if (j % 2) {
|
uint8_t byte = j % bytesPerPx;
|
||||||
|
vidmem[offset + j] = (uint8_t)(color >> (8 * byte));
|
||||||
|
|
||||||
|
if (byte == bytesPerPx - 1) {
|
||||||
bitmapRow = bitmapRow << 1;
|
bitmapRow = bitmapRow << 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += gfxMode->xRes;
|
offset += gfxMode->linearBytesPerScanline; // gfxMode->xRes * bytesPerPx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,13 +130,18 @@ void print(const char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Optimize this, it is VERY slow
|
||||||
void clear() {
|
void clear() {
|
||||||
uint32_t* vidmem = (uint32_t*)gfxMode->physicalBasePtr;
|
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
|
||||||
|
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i < gfxMode->xRes * gfxMode->yRes) {
|
uint8_t j = 0;
|
||||||
vidmem[i] = BG_COLOR; // #1f2937
|
while (i < gfxMode->xRes * gfxMode->yRes) { // Loop through all pixels
|
||||||
i++;
|
vidmem[i * bytesPerPx + j] = (uint8_t)(bgColor >> (j*8));
|
||||||
|
|
||||||
|
j = (j + 1) % bytesPerPx;
|
||||||
|
if (!j) { i++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.x = 0;
|
cursor.x = 0;
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ void main() {
|
|||||||
print("kern.\n\n");
|
print("kern.\n\n");
|
||||||
|
|
||||||
diskRead(5, 1, filetable); // Read the filetable and store it in memory
|
diskRead(5, 1, filetable); // Read the filetable and store it in memory
|
||||||
|
|
||||||
// Run Interactive Shell Program
|
// Run Interactive Shell Program
|
||||||
// TODO: Make it in another file
|
// TODO: Make it in another file
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
- [ ] Variable text size :)
|
- [ ] Variable text size :)
|
||||||
- [ ] Make output overflow go to next line
|
- [ ] Make output overflow go to next line
|
||||||
- [ ] More fonts
|
- [ ] More fonts
|
||||||
|
- [x] Generic screen.h stuff (don't assume 1920x1080 32bpp)
|
||||||
|
- [ ]
|
||||||
- [x] Graphics
|
- [x] Graphics
|
||||||
- [?] Enter/exit a "graphics" mode (idk if we need this)
|
- [?] Enter/exit a "graphics" mode (idk if we need this)
|
||||||
- [x] Pixel drawing
|
- [x] Pixel drawing
|
||||||
@@ -68,6 +70,7 @@
|
|||||||
- [ ] Malloc()
|
- [ ] Malloc()
|
||||||
- [ ] Free()
|
- [ ] Free()
|
||||||
- [ ] Shell
|
- [ ] Shell
|
||||||
|
- [ ] Separate file/program
|
||||||
- [ ] ';' separated commands
|
- [ ] ';' separated commands
|
||||||
- [ ] I/O Redirection with '<' '>'
|
- [ ] I/O Redirection with '<' '>'
|
||||||
- [ ] Commands
|
- [ ] Commands
|
||||||
@@ -111,4 +114,8 @@
|
|||||||
- [ ] Standard libs
|
- [ ] Standard libs
|
||||||
- [ ] Finish all todos
|
- [ ] Finish all todos
|
||||||
- [ ] Refactoring!!!
|
- [ ] Refactoring!!!
|
||||||
|
- [ ] Can it run DOOM?
|
||||||
|
- [ ] Games
|
||||||
|
- [ ] Minesweeper
|
||||||
|
- [ ] Solitaire
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user