Commit 48150c3a authored by Joshua Barretto's avatar Joshua Barretto

Minor changes

parent 2eb62bdf
......@@ -45,9 +45,6 @@ namespace tupai
void set_virtualtty(virtualtty* vtty);
void write_char(char c);
};
void console_init_global();
safeptr<console> console_get_global();
}
#endif
......@@ -17,8 +17,8 @@
* along with Tupai. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TUPAI_GFX_BMPHEADER_HPP
#define TUPAI_GFX_BMPHEADER_HPP
#ifndef TUPAI_GFX_BMP_HPP
#define TUPAI_GFX_BMP_HPP
// Tupai
#include <tupai/type.hpp>
......
......@@ -40,12 +40,12 @@ namespace tupai
color sample_at(uint16 x, uint16 y) { return this->pixels[this->width * y + x]; }
void blit(buffer& other, uint16 tgt_x = 0, uint16 tgt_y = 0, uint16 w = 0, uint16 h = 0, uint16 src_x = 0, uint16 src_y = 0);
void blit(buffer& other, uint16 tgt_x = 0, uint16 tgt_y = 0, uint16 w = 0, uint16 h = 0, uint16 src_x = 0, uint16 src_y = 0, color blend_col = color(255, 255, 255, 255));
void mirror_horizontal();
void mirror_vertical();
};
buffer buffer_create(uint16 width, uint16 height);
buffer buffer_create(uint16 width, uint16 height, color col = color(0, 0, 0, 0));
}
}
......
......@@ -41,10 +41,20 @@ namespace tupai
this->value = (r << 24) | (g << 16) | (b << 8) | a;
}
byte r() { return (this->value >> 24) & 0xFF; }
byte g() { return (this->value >> 16) & 0xFF; }
byte b() { return (this->value >> 8) & 0xFF; }
byte a() { return (this->value >> 0) & 0xFF; }
byte r() const { return (this->value >> 24) & 0xFF; }
byte g() const { return (this->value >> 16) & 0xFF; }
byte b() const { return (this->value >> 8) & 0xFF; }
byte a() const { return (this->value >> 0) & 0xFF; }
color operator*(const color& other)
{
return color(
(this->r() * other.r()) >> 8,
(this->g() * other.g()) >> 8,
(this->b() * other.b()) >> 8,
(this->a() * other.a()) >> 8
);
}
} __attribute((packed));
static __attribute__ ((unused)) color merge_color(color lo, color hi)
......
/*
* file : psf.hpp
*
* This file is part of Tupai.
*
* Tupai is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tupai is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tupai. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TUPAI_GFX_PSF_HPP
#define TUPAI_GFX_PSF_HPP
// Tupai
#include <tupai/type.hpp>
#include <tupai/gfx/buffer.hpp>
#include <tupai/util/vector.hpp>
namespace tupai
{
namespace gfx
{
struct psf
{
util::vector<buffer> charbuffs;
psf()
{
for (int i = 0; i < 16; i ++)
this->charbuffs.push(buffer_create(8, 16, color(255, 255, 255, 255)));
}
const buffer& get_charbuff(char c)
{
return this->charbuffs[0];
}
};
bmp bmp_from(ptr_t header);
}
}
#endif
......@@ -33,7 +33,6 @@ namespace tupai
void pit_init();
void pit_enable();
void pit_set_rate(uint16 rate);
void pit_set_tick_func(void (*func)(cpu_pushal, cpu_int));
}
#endif
......@@ -222,26 +222,4 @@ namespace tupai
if (rehandle)
this->write_char(c);
}
// Global console
console global_console;
bool global_console_initiated = false;
void console_init_global()
{
#if defined(SYSTEM_ARCH_i686)
virtualtty* vga_vtty = x86_family::vga_get_virtualtty().val();
global_console.set_virtualtty(vga_vtty);
#endif
global_console_initiated = true;
}
safeptr<console> console_get_global()
{
if (!global_console_initiated)
return safeptr<console>(nullptr, false);
return safeptr<console>(&global_console, true);
}
}
......@@ -25,7 +25,7 @@ namespace tupai
{
namespace gfx
{
void buffer::blit(buffer& other, uint16 tgt_x, uint16 tgt_y, uint16 w, uint16 h, uint16 src_x, uint16 src_y)
void buffer::blit(buffer& other, uint16 tgt_x, uint16 tgt_y, uint16 w, uint16 h, uint16 src_x, uint16 src_y, color blend_col)
{
uint32 skip = this->width;
......@@ -37,7 +37,7 @@ namespace tupai
for (uint16 line_count = 0; line_count < height; line_count ++)
{
for (uint16 col_count = 0; col_count < width; col_count ++)
this->pixels[tgt_line + col_count] = merge_color(this->pixels[tgt_line + col_count], other.pixels[src_line + col_count]).value;//other.pixels[src_line + col_count];
this->pixels[tgt_line + col_count] = merge_color(color(this->pixels[tgt_line + col_count]), color(other.pixels[src_line + col_count]) * blend_col).value;//other.pixels[src_line + col_count];
tgt_line += skip;
src_line += other.width;
......@@ -70,7 +70,7 @@ namespace tupai
}
}
buffer buffer_create(uint16 width, uint16 height)
buffer buffer_create(uint16 width, uint16 height, color col)
{
buffer nbuffer;
......@@ -79,6 +79,9 @@ namespace tupai
nbuffer.pixels = util::alloc<color>(nbuffer.width * nbuffer.height).val();
for (umem i = 0; i < nbuffer.width * nbuffer.height; i ++)
nbuffer.pixels[i] = col;
return nbuffer;
}
}
......
......@@ -39,8 +39,6 @@ namespace tupai
volatile counter_t pit_count = 0;
volatile uint16 pit_rate = 0;
void (*pit_tick_func)(cpu_pushal, cpu_int) = nullptr;
// PIT interrupt handler
extern "C" void pit_irq_handler();
//asm volatile ("pit_irq_handler: \n call pit_irq_handler_main \n iret");
......@@ -81,18 +79,12 @@ namespace tupai
port_out8(PIT_DATA_CH0_PORT, (div >> 8) & 0xFF); // MSB
}
void pit_set_tick_func(void (*func)(cpu_pushal, cpu_int))
{
pit_tick_func = func;
}
extern "C" void pit_irq_handler_main(cpu_pushal state_pushal, cpu_int state_int)
{
interrupt_ack(IDT_REMAP_OFFSET + 0x0);
pit_count += 1000000 / pit_rate;
if (pit_tick_func != nullptr)
pit_tick_func(state_pushal, state_int);
task_save_state(state_pushal, state_int);
}
}
......@@ -36,7 +36,6 @@
// --- CONSOLE & I/O ---
#include <tupai/tty.hpp>
#include <tupai/console.hpp>
#include <tupai/kshell.hpp>
// --- FILESYSTEM ---
......@@ -83,7 +82,7 @@ namespace tupai
// Serial debug
#if defined(CFG_ENABLE_SERIAL_DEBUG)
serial_init();
startup_print_unit_init("Serial");
startup_print_unit_init("serial");
serial_open(1);
startup_print_unit_init("COM1 debugging");
#endif
......@@ -91,20 +90,20 @@ namespace tupai
// Memory management unit
memory_init();
startup_print_unit_init("Memory");
startup_print_unit_init("memory");
memory_enforce();
startup_print_unit_init("Memory enforcement");
startup_print_unit_init("memory enforcement");
#if defined(SYSTEM_ARCH_i686)
// Paging
paging_init();
startup_print_unit_init("Paging structure");
startup_print_unit_init("paging structure");
paging_enable();
startup_print_unit_init("Paging");
startup_print_unit_init("paging");
// Dynamic memory pool
mempool_init((ubyte*)mempool_begin, mempool_size, 1024); // Blocks of 1K
startup_print_unit_init("Dynamic memory pool");
startup_print_unit_init("dynamic memory pool");
// GDT
gdt_init();
......@@ -126,48 +125,41 @@ namespace tupai
startup_print_unit_init("VGA driver");
#endif
// Console
console_init_global();
startup_print_unit_init("Kernel console");
// TTY
tty_init();
startup_print_unit_init("Kernel TTY");
startup_print_unit_init("TTY");
// Now we have a TTY up and ready!
#if defined(SYSTEM_ARCH_i686)
// PIT
pit_init();
startup_print_unit_init("PIT");
startup_print_unit_init("timer");
// Keyboard
kbd_init();
startup_print_unit_init("Keyboard");
startup_print_unit_init("keyboard");
// Serial
serial_init();
startup_print_unit_init("Serial");
startup_print_unit_init("serial");
#endif
// Syscall procedure
syscall_init();
startup_print_unit_init("Syscall routine");
startup_print_unit_init("syscall routine");
// Kernel multi-tasking
task_init();
startup_print_unit_init("Task scheduler");
startup_print_unit_init("task scheduler");
// Filesystems and I/O
fs::fs_init();
startup_print_unit_init("Filesystem");
startup_print_unit_init("filesystem");
// System interfaces
sys::random_init();
// End of boot procedure
klog_init("Boot procedure complete");
// Enable various systems
interrupt_enable();
pit_enable();
......
......@@ -332,7 +332,7 @@ namespace tupai
void mempool_init(void* ptr, umem size, umem blocksize)
{
mempool_init_impl(ptr, size, blocksize);
mempool_init_impl(ptr, size, 32);
}
void* mempool_alloc(umem n, const char* callee)
......
......@@ -21,10 +21,6 @@
#include <tupai/task.hpp>
#include <tupai/generic/ringbuff.hpp>
#if defined(SYSTEM_ARCH_i686)
#include <tupai/i686/pit.hpp>
#endif
#include <tupai/util/conv.hpp>
namespace tupai
......@@ -45,7 +41,6 @@ namespace tupai
void task_init()
{
tasks.init(64);
//pit_set_tick_func(task_save_state);
}
void task_enable_scheduler(bool enable)
......
......@@ -26,17 +26,23 @@
#if defined(SYSTEM_ARCH_i686)
#include <tupai/i686/serial.hpp>
#include <tupai/x86_family/vga.hpp>
#endif
namespace tupai
{
safeptr<console> g_console;
virtualtty g_virtualtty;
console g_console;
util::mutex tty_mutex;
void tty_init()
{
// Find the global console
g_console = console_get_global();
// Set the global console's virtualtty
#if defined(SYSTEM_ARCH_i686)
virtualtty* vga_vtty = x86_family::vga_get_virtualtty().val();
g_console.set_virtualtty(vga_vtty);
#endif
tty_clear();
}
......@@ -44,8 +50,7 @@ namespace tupai
void tty_write(char c)
{
// If it's an invalid pointer, don't do anything
if (g_console.is_valid())
g_console.val()->write_char(c);
g_console.write_char(c);
#if defined(SYSTEM_ARCH_i686)
#if defined(CFG_ENABLE_SERIAL_DEBUG)
......
......@@ -32,8 +32,6 @@
#include <tupai/kdebug.hpp>
//#define DOUBLE_BUFFERED 0
namespace tupai
{
namespace x86_family
......@@ -48,11 +46,6 @@ namespace tupai
static inline uint32 color_blend(uint32 lower, uint32 higher);
static void blit_character(uint32 c, uint16 x, uint16 y, uint32 fg_color, uint32 bg_color, uint8 alpha = 180);
struct bmp_header // TODO : this
{
};
struct psf2_header
{
// Magic heaader data
......@@ -181,9 +174,9 @@ namespace tupai
// Load wallpaper
wallpaper_buffer = gfx::bmp_from(&_binary_wallpaper_bmp_start).to_buffer();
gfx::buffer test_buffer = gfx::bmp_from(&_binary_test_bmp_start).to_buffer();
wallpaper_buffer.blit(test_buffer, 100, 300);
wallpaper_buffer.blit(test_buffer, 200, 400, 150, 180);
//gfx::buffer test_buffer = gfx::bmp_from(&_binary_test_bmp_start).to_buffer();
//wallpaper_buffer.blit(test_buffer, 100, 300);
//wallpaper_buffer.blit(test_buffer, 200, 400, 150, 180);
// If the video mode is textmode, we need to adjust the framebuffer address since we're in the higher half
if (config.fb_type == vga_config::framebuffer_type::RGB)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment