Skip to content
Snippets Groups Projects
Commit 386f9240 authored by Stephen D's avatar Stephen D
Browse files

Colours are correct on any video card I think

parent 3a5132fc
No related branches found
No related tags found
No related merge requests found
......@@ -21,24 +21,27 @@ int get_offset_col(int offset);
* Public Kernel API functions *
**********************************************************/
void putpixel(int x, int y, int r, int b, int g) {
void putpixel(int x, int y, u32 fg) {
unsigned where = x*COLOR_BITS/8 + y*SCN_PITCH; //TODO: Should come from above function
u8 *screen = (u8*) VIDEO_ADDRESS;
screen[where] = b; // BLUE
screen[where + 1] = g; // GREEN
screen[where + 2] = r; // RED
//TODO: Is there a way to set these all at once?
for (int j = 0; j < COLOR_BITS/8; j++) {
screen[where + j] = (fg >> j*8) & 255;
}
}
void fillrect(int x, int y, unsigned char r, unsigned char g, unsigned char b, int w, int h) {
void fillrect(int x, int y, u32 fg, int w, int h) {
unsigned where = x*COLOR_BITS/8 + y*SCN_PITCH;
u8 *screen = (u8*) VIDEO_ADDRESS;
int i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
screen[where + j*COLOR_BITS/8] = b;
screen[where + j*COLOR_BITS/8 + 1] = g;
screen[where + j*COLOR_BITS/8 + 2] = r;
//TODO: Is there a way to set these all at once?
for (int k = 0; k < COLOR_BITS/8; k++) {
screen[where + (int)(j*COLOR_BITS/8) + k] = (fg >> k*8) & 255;
}
}
where += SCN_PITCH;
}
......@@ -48,6 +51,20 @@ void scroll_up(u8 lines) { //NOTE: Does not clear the bottom lines!
memory_copy((u8 *)(VIDEO_ADDRESS + lines * SCN_PITCH), (u8 *)VIDEO_ADDRESS, (SCN_HEIGHT - lines) * SCN_PITCH);
}
u32 color_to_pixel(Color_t color)
{
//32bpp max
//Scale the values properly
u8 r = color.r * ((1 << ADV_VBE_INFO->red_mask) - 1) / 255;
u8 g = color.g * ((1 << ADV_VBE_INFO->green_mask) - 1) / 255;
u8 b = color.b * ((1 << ADV_VBE_INFO->blue_mask) - 1) / 255;
return (b << ADV_VBE_INFO->blue_position) +
(g << ADV_VBE_INFO->green_position) +
(r << ADV_VBE_INFO->red_position);
}
/**********************************************************
* Private kernel functions *
**********************************************************/
......@@ -84,11 +101,11 @@ void set_cursor_offset(int offset) {
}
void setup_video() {
struct vbe_mode_info_structure *vbe_info = (struct vbe_mode_info_structure *)0x7e00;
struct vbe_mode_info_structure *vbe_info = (struct vbe_mode_info_structure *)0x7e00;
ADV_VBE_INFO = vbe_info;
VIDEO_ADDRESS = vbe_info->framebuffer;
COLOR_BITS = vbe_info->bpp;
SCN_WIDTH = vbe_info->width;
SCN_HEIGHT = vbe_info->height;
SCN_PITCH = vbe_info->pitch;
VIDEO_ADDRESS = vbe_info->framebuffer;
COLOR_BITS = vbe_info->bpp;
SCN_WIDTH = vbe_info->width;
SCN_HEIGHT = vbe_info->height;
SCN_PITCH = vbe_info->pitch;
}
......@@ -2,6 +2,7 @@
#define SCREEN_H
#include "../cpu/types.h"
#include "../util/types.h"
/* Screen i/o ports */
#define REG_SCREEN_CTRL 0x3d4
......@@ -52,10 +53,11 @@ struct vbe_mode_info_structure {
struct vbe_mode_info_structure *ADV_VBE_INFO;
/* Public kernel API */
void putpixel(int x, int y, int r, int g, int b); // 0-255 for each
void fillrect(int x, int y, unsigned char r, unsigned char g, unsigned char b, int w, int h);
void putpixel(int x, int y, u32 fg);
void fillrect(int x, int y, u32 fg, int w, int h);
void setup_video();
void scroll_up(u8 lines);
u32 color_to_pixel(Color_t color);
u8 COLOR_BITS;
u16 SCN_WIDTH;
......
......@@ -62,16 +62,21 @@ void generate_fractal(u16 x, u16 y, u16 w, u16 h) {
Zrt = Zr * Zr + Cr - (Zi * Zi);
Zi = 2 * Zi * Zr + Ci;
Zr = Zrt;
//if(Q_rsqrt(Zr * Zr + Zi * Zi) > 2) { //Divergent
if(Zr * Zr + Zi * Zi > 4 || Zr * Zr + Zi * Zi < -4) {
putpixel(x + i, y + j, (numIterations * 10), (numIterations * 30), (numIterations * 50));
painted = 1;
break;
if(Zr * Zr + Zi * Zi > 4 || Zr * Zr + Zi * Zi < -4) //Divergent
{
Color_t p;
p.r = numIterations * 10;
p.g = numIterations * 30;
p.b = numIterations * 50;
putpixel(x + i, y + j, color_to_pixel(p));
painted = 1;
break;
}
}
if (painted == 0) {
putpixel(x + i, y + j, 0, 0, 0);
}
}
}
}
if (painted == 0) {
putpixel(x + i, y + j, 0);
}
}
}
}
#include "texteditor.h"
#include "../util/terminal.h"
#include "../libc/string.h"
#include "../drivers/screen.h"
void gen_padding(char *menu) {
print("=");
......@@ -13,12 +14,12 @@ void gen_padding(char *menu) {
println("=");
}
void gen_menu(char *menu) {
gen_padding(menu);
print("|");
print(menu);
println("|");
gen_padding(menu);
void gen_menu() {
//Top bar
Color_t red;
red.r = 255;
fillrect(0, 0, color_to_pixel(red), SCN_WIDTH, 9);
print("File Edit Exit");
}
void editor() {
......@@ -26,5 +27,5 @@ void editor() {
clear_screen();
//Menu setup
gen_menu("File|Edit");
gen_menu();
}
#include "font.h"
#include "../drivers/screen.h"
#include "../libc/string.h"
#include "../util/types.h"
u16 characters[26 * 8 + 31 * 8 + 16*8] = {
24,24,0,24,60,60,126,126,
......@@ -78,13 +79,13 @@ u16 characters[26 * 8 + 31 * 8 + 16*8] = {
6,6,6,6,6,0,6,6
};
void draw_char(int x, int y, char c) {
void draw_char(int x, int y, char c, u32 fg) {
unsigned where = x*COLOR_BITS/8 + y*SCN_PITCH;
u8 *screen = (u8 *) VIDEO_ADDRESS;
if (c == 124) { //Custom code for |
for(int r = 0; r < 8; r++) {//Rows
putpixel(x + 3, y - r, 255, 255, 255); //TODO: CHANGE THIS
putpixel(x + 4, y - r, 255, 255, 255); //TODO: CHANGE THIS
putpixel(x + 3, y - r, fg); //TODO: CHANGE THIS
putpixel(x + 4, y - r, fg); //TODO: CHANGE THIS
}
}
else {
......@@ -97,10 +98,10 @@ void draw_char(int x, int y, char c) {
uint16 row = characters[c * 8 + r];
for (int i = 0; i < 8; i++) {
if (row&(1 << i)) {
screen[where + (int)(i*COLOR_BITS/8)] = 255;
screen[where + (int)(i*COLOR_BITS/8) + 1] = 255;
screen[where + (int)(i*COLOR_BITS/8) + 2] = 255;
//TODO: Is there a way to set these all at once?
for (int j = 0; j < COLOR_BITS/8; j++) {
screen[where + (int)(i*COLOR_BITS/8) + j] = (fg >> j*8) & 255;
}
}
}
where -= SCN_PITCH;
......@@ -108,10 +109,10 @@ void draw_char(int x, int y, char c) {
}
}
void print_at(int x, int y, char *c) {
void print_at(int x, int y, char *c, u32 fg) {
int i = 0;
while (c[i] != 0) {
draw_char(x + i * 8, y, c[i]);
draw_char(x + i * 8, y, c[i], fg);
i++;
}
}
......@@ -119,5 +120,9 @@ void print_at(int x, int y, char *c) {
//X is where the middle character goes
void print_centered(int scn_width, int y, char *c) {
int x_left = (scn_width - (strlen(c) * 8)) / 2;
print_at(x_left, y, c);
Color_t fg;
fg.r = 255;
fg.g = 0;
fg.b = 0;
print_at(x_left, y, c, color_to_pixel(fg));
}
#ifndef font
#define font
void draw_char(int x, int y, char c);
void print_at(int x, int y, char *c);
void print_centered(int scn_width, int y, char *c);
#define font
#include "types.h"
void draw_char(int x, int y, char c, u32 fg);
void print_at(int x, int y, char *c, u32 fg);
void print_centered(int scn_width, int y, char *c);
#endif
......@@ -6,14 +6,16 @@
int offset_x = 0;
int offset_y = 8; //Higher numbers really means lower on screen
int bg[3] = {0, 0, 0};
u32 bg;
u32 fg;
void newline() {
offset_x = 0;
offset_y += char_height;
if (offset_y >= SCN_HEIGHT) {
scroll_up(char_height);
fillrect(0, SCN_HEIGHT - char_height, bg[0], bg[1], bg[2], SCN_WIDTH, char_height); //Clear last line
fillrect(0, SCN_HEIGHT - char_height, bg, SCN_WIDTH, char_height); //Clear last line
offset_y -= char_height;
}
}
......@@ -30,7 +32,7 @@ void print(char *c) {
if (offset_x + 8 > SCN_WIDTH) {
newline();
}
draw_char(offset_x, offset_y, c[i]);
draw_char(offset_x, offset_y, c[i], fg);
offset_x += 8;
}
i++;
......@@ -48,19 +50,28 @@ void delete_last() {
offset_x = SCN_WIDTH - 8;
offset_y -= char_height;
}
fillrect(offset_x, offset_y - 11, bg[0], bg[1], bg[2], 8, char_height);
fillrect(offset_x, offset_y - 11, bg, 8, char_height);
}
void clear_screen() {
fillrect(0, 0, bg[0], bg[1], bg[2], SCN_WIDTH, SCN_HEIGHT); //Background
fillrect(0, 0, bg, SCN_WIDTH, SCN_HEIGHT); //Background
offset_x = 0;
offset_y = 8;
}
void set_background(int r, int g, int b) {
bg[0] = r;
bg[1] = g;
bg[2] = b;
Color_t bg_c;
bg_c.r = r;
bg_c.g = g;
bg_c.b = b;
bg = color_to_pixel(bg_c);
//Tmp
Color_t fg_c;
fg_c.r = 0;
fg_c.g = 0xcc;
fg_c.b = 0;
fg = color_to_pixel(fg_c);
}
void set_offset(int x, int y) {
......
#include "types.h"
#include "../cpu/types.h"
#ifndef HLTYPES
#define HLTYPES
#include "../cpu/types.h"
//Holds high level types. Will possibly move this into the low level types file.
typedef struct Color
{
u8 r, g, b;
} Color_t;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment