CTAOS v1
This commit is contained in:
152
include/console.h
Normal file
152
include/console.h
Normal file
@ -0,0 +1,152 @@
|
||||
#include <system.h>
|
||||
|
||||
#ifndef __CONSOLE_H
|
||||
#define __CONSOLE_H
|
||||
#define _ATTRIB 0x0F
|
||||
|
||||
byte default_background, default_foreground;
|
||||
|
||||
|
||||
// Change cursor position
|
||||
void text_mode_cursor(int x, int y)
|
||||
{
|
||||
unsigned temp = y*current_mode_width + x;
|
||||
|
||||
outportb (0x3D4, 14);
|
||||
outportb (0x3D5, temp >> 8);
|
||||
outportb (0x3D4, 15);
|
||||
outportb (0x3D5, temp);
|
||||
}
|
||||
|
||||
// Set the default colors; max is 0x0F
|
||||
void set_default_colors(byte back, byte fore)
|
||||
{
|
||||
if (back < 0x10) default_background = back;
|
||||
if (fore < 0x10) default_foreground = fore;
|
||||
}
|
||||
|
||||
|
||||
// Clear screen, and set font to default font
|
||||
void clrscr()
|
||||
{
|
||||
byte font = default_foreground | (default_background<<4);
|
||||
int i = 0;
|
||||
for (i = 0; i < current_mode_width*current_mode_height; i++)
|
||||
{ TextVideoRam[2*i] = 0;
|
||||
TextVideoRam[2*i+1] = font;
|
||||
}
|
||||
cursor_x = 0; cursor_y = 0;
|
||||
}
|
||||
|
||||
void scroll(int n)
|
||||
{
|
||||
memcpy(TextVideoRam,
|
||||
TextVideoRam+(current_mode_width*n*2),
|
||||
2*current_mode_width*(current_mode_height - n));
|
||||
|
||||
byte blank = default_foreground | (default_background<<4);
|
||||
|
||||
int i;
|
||||
for (i = current_mode_width*(current_mode_height-n);
|
||||
i < current_mode_width*current_mode_height; i++){
|
||||
TextVideoRam[2*i] = 0;
|
||||
TextVideoRam[2*i+1] = blank;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _endl()
|
||||
{
|
||||
cursor_x = 0;
|
||||
if (++cursor_y >=25) {
|
||||
cursor_y = 24; scroll(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Put character on screen in specified position; can use different font colors
|
||||
void putc_pos_font(int x, int y, char c, byte back, byte fore)
|
||||
{
|
||||
TextVideoRam[2*(y*current_mode_width+x)] = c;
|
||||
TextVideoRam[2*(y*current_mode_width+x)+1] = fore|(back<<4);
|
||||
}
|
||||
// Put character on screen in specified position; use default font colors
|
||||
void putc_pos(int x, int y, char c)
|
||||
{
|
||||
TextVideoRam[2*(y*current_mode_width+x)] = c;
|
||||
}
|
||||
// Put character on screen in the current cursor position; different font colors
|
||||
void putc_font(char c, byte back, byte fore)
|
||||
{
|
||||
if (cursor_x > current_mode_width) _endl();
|
||||
|
||||
if (c == '\n') {_endl(); return;};
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)] = c;
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)+1] = fore|(back<<4);
|
||||
cursor_x++;
|
||||
}
|
||||
// Put character on screen in the current cursor position; default font colors
|
||||
void putc(char c)
|
||||
{
|
||||
if (cursor_x > current_mode_width) _endl();
|
||||
|
||||
if (c == '\n') {_endl(); return;};
|
||||
TextVideoRam[2*(cursor_y*current_mode_width+cursor_x)] = c;
|
||||
cursor_x++;
|
||||
}
|
||||
|
||||
// Put string on screen in specified position; can use different font colors
|
||||
void puts_pos_font(int x, int y, char *str, byte back, byte fore)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_pos_font(x+i, y, str[i], back, fore);
|
||||
|
||||
}
|
||||
|
||||
// Put string on screen in specified position; use default font colors
|
||||
void puts_pos(int x, int y, char *str)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_pos(x+i, y, str[i]);
|
||||
}
|
||||
void puts(char *str)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc(str[i]);
|
||||
}
|
||||
|
||||
void puts_font(char *str, byte back, byte fore)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i] != 0; i++)
|
||||
putc_font(str[i], back, fore);
|
||||
}
|
||||
|
||||
void put_hex(int x, int y, unsigned int alpha)
|
||||
{
|
||||
char hex[] = "0123456789ABCDEF";
|
||||
char nr[9];
|
||||
int i;
|
||||
for (i = 7; i >= 0; i--) {
|
||||
nr[i] = hex[alpha%16];
|
||||
alpha /= 16;
|
||||
}
|
||||
nr[8] = 0;
|
||||
puts_pos(x, y, nr);
|
||||
}
|
||||
|
||||
void put_bin (int x, int y, byte xz)
|
||||
{
|
||||
int i;
|
||||
char arr[9] = {0,0,0,0,0,0,0,0,0};
|
||||
for(i=7; i>=0; i--) {
|
||||
arr[i] = (xz%2) + '0'; xz/=2;
|
||||
}
|
||||
puts_pos (x, y, arr);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
104
include/system.h
Normal file
104
include/system.h
Normal file
@ -0,0 +1,104 @@
|
||||
#ifndef __SYSTEM_H
|
||||
#define __SYSTEM_H
|
||||
|
||||
// Data type declarations
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned short word;
|
||||
typedef unsigned int dword;
|
||||
|
||||
/* This defines what the stack looks like after an ISR was running */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int gs, fs, es, ds; /* pushed the segs last */
|
||||
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */
|
||||
unsigned int int_no, err_code; /* our 'push byte #' and ecodes do this */
|
||||
unsigned int eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */
|
||||
} regs;
|
||||
|
||||
|
||||
byte *TextVideoRam;
|
||||
int cursor_x, cursor_y;
|
||||
int current_mode_width;
|
||||
int current_mode_height;
|
||||
|
||||
// System functions declaration
|
||||
void system_init();
|
||||
void *memcpy(void *dest, const void *src, int count);
|
||||
void *memset(void *dest, char val, int count);
|
||||
unsigned short *memsetw(unsigned short *dest, unsigned short val, int count);
|
||||
int strlen (const char *str);
|
||||
byte inportb (word _port);
|
||||
byte inb (word _port);
|
||||
void outportb (word _port, byte _data);
|
||||
void outb (word _port, byte _data) ;
|
||||
|
||||
// GDT, IDT, ISRs, IRQ functions declarations
|
||||
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
|
||||
void gdt_install();
|
||||
|
||||
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
|
||||
void idt_install();
|
||||
|
||||
void isrs_install();
|
||||
|
||||
void irq_install_handler(int irq, void (*handler)(regs *r));
|
||||
void irq_uninstall_handler(int irq);
|
||||
void irq_install();
|
||||
|
||||
|
||||
// Initialize system
|
||||
|
||||
|
||||
void *memcpy(void *dest, const void *src, int count)
|
||||
{
|
||||
const char *sp = (const char *)src;
|
||||
char *dp = (char *)dest;
|
||||
for(; count != 0; count--) *dp++ = *sp++;
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset(void *dest, char val, int count)
|
||||
{
|
||||
char *temp = (char *)dest;
|
||||
for( ; count != 0; count--) *temp++ = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
unsigned short *memsetw(unsigned short *dest, unsigned short val, int count)
|
||||
{
|
||||
unsigned short *temp = (unsigned short *)dest;
|
||||
for( ; count != 0; count--) *temp++ = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
// strlen -- Get lenght of str
|
||||
int strlen (const char *str)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; str[i]!=0; i++) {}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
byte inportb (word _port) {
|
||||
byte rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
byte inb (word _port) {
|
||||
byte rv;
|
||||
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void outportb (word _port, byte _data) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
void outb (word _port, byte _data) {
|
||||
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user