CTAOS v5
This commit is contained in:
165
SysCore/video/color/color.c
Normal file
165
SysCore/video/color/color.c
Normal file
@ -0,0 +1,165 @@
|
||||
#include <color.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
RGBColor RGBColors_4bpp[] = {{0, 0, 0}, // 00 Black
|
||||
{0, 0, 127}, // 01 Dark Blue
|
||||
{0, 127, 0}, // 02 Dark Green
|
||||
{0, 127, 127}, // 03 Dark Cyan
|
||||
{127, 0, 0}, // 04 Dark Red
|
||||
{127, 0, 127}, // 05 Dark Magenta
|
||||
{127, 127, 0}, // 06 Dark Yellow
|
||||
{192, 192, 192},// 07 Light Gray
|
||||
{127, 127, 127},// 08 Dark Gray
|
||||
{0, 0, 255}, // 09 Blue
|
||||
{0, 255, 0}, // 10 Green
|
||||
{0, 255, 255}, // 11 Cyan
|
||||
{255, 0, 0}, // 12 Red
|
||||
{255, 0, 255}, // 13 Magenta
|
||||
{255, 255, 0}, // 14 Yellow
|
||||
{255, 255, 255} // 15 White
|
||||
};
|
||||
|
||||
|
||||
RGBColor Convert_1bpp_to_RGB(Color_1Bpp c)
|
||||
{
|
||||
unsigned char t = (c) ? 0xFF : 0x00;
|
||||
RGBColor temp = {t, t, t};
|
||||
return temp;
|
||||
}
|
||||
|
||||
RGBColor Convert_4bpp_to_RGB(Color_4Bpp c)
|
||||
{
|
||||
return RGBColors_4bpp[c];
|
||||
}
|
||||
|
||||
RGBColor Convert_6bpp_to_RGB(Color_6Bpp c)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
R = (unsigned char) ((unsigned)((c & 0x30)>>4) * 255 / 3 );
|
||||
G = (unsigned char) ((unsigned)((c & 0x0C)>>2) * 255 / 3 );
|
||||
B = (unsigned char) ((unsigned) (c & 0x03) * 255 / 3 );
|
||||
RGBColor ret = {R, G, B};
|
||||
return ret;
|
||||
}
|
||||
|
||||
RGBColor Convert_8bpp_to_RGB(Color_8Bpp c)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
R = (unsigned char) ((unsigned)((c & 0xE0)>>5) * 255 / 7 );
|
||||
G = (unsigned char) ((unsigned)((c & 0x1C)>>2) * 255 / 7 );
|
||||
B = (unsigned char) ((unsigned) (c & 0x03) * 255 / 3 );
|
||||
RGBColor ret = {R, G, B};
|
||||
return ret;
|
||||
}
|
||||
|
||||
RGBColor Convert_15bpp_to_RGB(Color_15Bpp c)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
R = (unsigned char) ((unsigned)((c & 0x7C00)>>10) * 255 / 31 );
|
||||
G = (unsigned char) ((unsigned)((c & 0x03E0)>>5) * 255 / 31 );
|
||||
B = (unsigned char) ((unsigned) (c & 0x001F) * 255 / 31 );
|
||||
RGBColor ret = {R, G, B};
|
||||
return ret;
|
||||
}
|
||||
|
||||
RGBColor Convert_16bpp_to_RGB(Color_16Bpp c)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
R = (unsigned char) ((unsigned)((c & 0xF800)>>11) * 255 / 31 );
|
||||
G = (unsigned char) ((unsigned)((c & 0x07E0)>>5) * 255 / 63 );
|
||||
B = (unsigned char) ((unsigned) (c & 0x001F) * 255 / 31 );
|
||||
RGBColor ret = {R, G, B};
|
||||
return ret;
|
||||
}
|
||||
|
||||
RGBColor Convert_18bpp_to_RGB(Color_18Bpp c)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
R = (unsigned char) ((unsigned)(c.R) * 255 / 0x3F );
|
||||
G = (unsigned char) ((unsigned)(c.G) * 255 / 0x3F);
|
||||
B = (unsigned char) ((unsigned)(c.B) * 255 / 0x3F);
|
||||
RGBColor ret = {R, G, B};
|
||||
return ret;
|
||||
}
|
||||
|
||||
RGBColor Convert_24bpp_to_RGB(Color_24Bpp c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
Color_1Bpp Convert_RGB_to_1bpp(RGBColor c)
|
||||
{
|
||||
if (((unsigned)c.R + (unsigned)c.G + (unsigned)c.B) / 3 >= 128) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Color_4Bpp Convert_RGB_to_4bpp(RGBColor c)
|
||||
{
|
||||
int i; int minim = 0xFFFF; int index = 0;
|
||||
int R, G, B;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
R = (int)(c.R) - (int)(RGBColors_4bpp[i].R);
|
||||
G = (int)(c.G) - (int)(RGBColors_4bpp[i].G);
|
||||
B = (int)(c.B) - (int)(RGBColors_4bpp[i].B);
|
||||
|
||||
R = abs(R) + abs(G) + abs(B);
|
||||
if (R <= minim) {
|
||||
minim = R; index = i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
Color_6Bpp Convert_RGB_to_6bpp(RGBColor c)
|
||||
{
|
||||
Color_6Bpp temp = 0; unsigned tmp;
|
||||
tmp = (unsigned)(c.R) * 3 / 255; temp |= (tmp & 0x03) << 4;
|
||||
tmp = (unsigned)(c.G) * 3 / 255; temp |= (tmp & 0x03) << 2;
|
||||
tmp = (unsigned)(c.B) * 3 / 255; temp |= (tmp & 0x03);
|
||||
return temp;
|
||||
}
|
||||
|
||||
Color_8Bpp Convert_RGB_to_8bpp(RGBColor c)
|
||||
{
|
||||
Color_8Bpp temp = 0; unsigned tmp;
|
||||
tmp = (unsigned)(c.R) * 7 / 255; temp |= (tmp & 0x07) << 5;
|
||||
tmp = (unsigned)(c.G) * 7 / 255; temp |= (tmp & 0x07) << 2;
|
||||
tmp = (unsigned)(c.B) * 3 / 255; temp |= (tmp & 0x03);
|
||||
return temp;
|
||||
}
|
||||
|
||||
Color_15Bpp Convert_RGB_to_15bpp(RGBColor c)
|
||||
{
|
||||
Color_15Bpp temp = 0; unsigned tmp;
|
||||
tmp = (unsigned)(c.R) * 0x1F / 255; temp |= (tmp & 0x1F) << 10;
|
||||
tmp = (unsigned)(c.G) * 0x1F / 255; temp |= (tmp & 0x1F) << 5;
|
||||
tmp = (unsigned)(c.B) * 0x1F / 255; temp |= (tmp & 0x1F);
|
||||
return temp;
|
||||
}
|
||||
|
||||
Color_16Bpp Convert_RGB_to_16bpp(RGBColor c)
|
||||
{
|
||||
Color_16Bpp temp = 0; unsigned tmp;
|
||||
tmp = (unsigned)(c.R) * 0x1F / 255; temp |= (tmp & 0x1F) << 11;
|
||||
tmp = (unsigned)(c.G) * 0x3F / 255; temp |= (tmp & 0x3F) << 5;
|
||||
tmp = (unsigned)(c.B) * 0x1F / 255; temp |= (tmp & 0x1F);
|
||||
return temp;
|
||||
}
|
||||
|
||||
Color_18Bpp Convert_RGB_to_18bpp(RGBColor c)
|
||||
{
|
||||
Color_18Bpp temp; unsigned tmp;
|
||||
tmp = (unsigned)(c.R) * 0x3F / 255; temp.R = (unsigned char)tmp;
|
||||
tmp = (unsigned)(c.G) * 0x3F / 255; temp.G = (unsigned char)tmp;
|
||||
tmp = (unsigned)(c.B) * 0x3F / 255; temp.B = (unsigned char)tmp;
|
||||
return temp;
|
||||
}
|
||||
|
||||
Color_24Bpp Convert_RGB_to_24bpp(RGBColor c)
|
||||
{
|
||||
return c;
|
||||
}
|
66
SysCore/video/color/color.h
Normal file
66
SysCore/video/color/color.h
Normal file
@ -0,0 +1,66 @@
|
||||
#ifndef __COLOR__H__
|
||||
#define __COLOR__H__
|
||||
|
||||
/**RGB color structure.*/
|
||||
typedef struct {
|
||||
unsigned char R,G,B;
|
||||
} RGBColor;
|
||||
|
||||
/**\Monochrome (black and white)*/
|
||||
typedef bool Color_1Bpp;
|
||||
|
||||
/**CGA 2 bits per pixel indexed color.\n\n\Notes: Cannot be converted to/from RGB.*/
|
||||
typedef unsigned char Color_2Bpp;
|
||||
|
||||
/**16 color VGA.
|
||||
* \n\n\Format: Uses 1-1-1 bit format, highest bit is intensity.
|
||||
* \n\n\Notes: Unused bits are ignored (should be 0).*/
|
||||
typedef unsigned char Color_4Bpp;
|
||||
|
||||
/**64 color EGA.
|
||||
* \n\n\Format: Uses 2-2-2 bit format.
|
||||
* \n\n\Notes: High 2 bits are ignored (should be 0).*/
|
||||
typedef unsigned char Color_6Bpp;
|
||||
|
||||
/**256 color VGA.
|
||||
* \n\n\Format: Uses 3-3-2 bit format
|
||||
* \n\n\Notes: The palette must be changed before usable.*/
|
||||
typedef unsigned char Color_8Bpp;
|
||||
|
||||
/**SVGA Highcolor palette.
|
||||
* \n\n\Format: Uses 5-5-5 bit format.
|
||||
* \n\n\Notes: Unused high bit is ignored (should be 0).*/
|
||||
typedef unsigned short Color_15Bpp;
|
||||
|
||||
/**SVGA Highcolor palette.
|
||||
* \n\n\Format: Uses 5-6-5 bit format.*/
|
||||
typedef unsigned short Color_16Bpp;
|
||||
|
||||
/**VGA 18-bit RGB
|
||||
* \n\n\Format: Uses the RGBColor structure, with the R, G and B components.
|
||||
* \n\n\Notes: High 2 bits of each component are ignored, should be 0.*/
|
||||
typedef RGBColor Color_18Bpp;
|
||||
|
||||
/**24-bit Truecolor
|
||||
* \n\n\Format: Uses the RGBColor structure, with the R, G and B components.*/
|
||||
typedef RGBColor Color_24Bpp;
|
||||
|
||||
/**Few functions to convert values from one format to another.*/
|
||||
extern RGBColor Convert_1bpp_to_RGB(Color_1Bpp c);
|
||||
extern RGBColor Convert_4bpp_to_RGB(Color_4Bpp c);
|
||||
extern RGBColor Convert_6bpp_to_RGB(Color_6Bpp c);
|
||||
extern RGBColor Convert_8bpp_to_RGB(Color_8Bpp c);
|
||||
extern RGBColor Convert_15bpp_to_RGB(Color_15Bpp c);
|
||||
extern RGBColor Convert_16bpp_to_RGB(Color_16Bpp c);
|
||||
extern RGBColor Convert_18bpp_to_RGB(Color_18Bpp c);
|
||||
extern RGBColor Convert_24bpp_to_RGB(Color_24Bpp c);
|
||||
extern Color_1Bpp Convert_RGB_to_1bpp(RGBColor c);
|
||||
extern Color_4Bpp Convert_RGB_to_4bpp(RGBColor c);
|
||||
extern Color_6Bpp Convert_RGB_to_6bpp(RGBColor c);
|
||||
extern Color_8Bpp Convert_RGB_to_8bpp(RGBColor c);
|
||||
extern Color_15Bpp Convert_RGB_to_15bpp(RGBColor c);
|
||||
extern Color_16Bpp Convert_RGB_to_16bpp(RGBColor c);
|
||||
extern Color_18Bpp Convert_RGB_to_18bpp(RGBColor c);
|
||||
extern Color_24Bpp Convert_RGB_to_24bpp(RGBColor c);
|
||||
|
||||
#endif
|
26
SysCore/video/compile.bat
Normal file
26
SysCore/video/compile.bat
Normal file
@ -0,0 +1,26 @@
|
||||
@echo off
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=..\objects
|
||||
set incpath=../include
|
||||
|
||||
@echo Building Video Drivers...
|
||||
|
||||
del %objpath%\video\vga03h.o
|
||||
|
||||
goto build
|
||||
:error
|
||||
@echo.
|
||||
@echo There have been build errors. Building halted.
|
||||
@pause
|
||||
exit
|
||||
|
||||
:build
|
||||
@echo * Compiling Text Mode 0x03 video driver ...
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/video/vga03h.o vga03h.c
|
||||
|
||||
|
||||
:check
|
||||
if not exist %objpath%\video\vga03h.o goto error
|
37
SysCore/video/vga.h
Normal file
37
SysCore/video/vga.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef __VGA__H__
|
||||
#define __VGA__H__
|
||||
|
||||
typedef struct {
|
||||
enum MODE_TYPES {
|
||||
TextMode = 0,
|
||||
GraphicsMode = 1
|
||||
};
|
||||
/**Defines the mode returned by BIOS int 0x10, ah = 0xF*/
|
||||
unsigned char Mode;
|
||||
/**Text mode or Graphic mode (defined in MODE_TYPES enumeration)*/
|
||||
unsigned char ModeType;
|
||||
|
||||
/**Screen size (characters in text modes, pixels in graphic modes)*/
|
||||
unsigned Width, Height;
|
||||
|
||||
/**Bits per pixel*/
|
||||
unsigned bpp;
|
||||
|
||||
/**Pointer to a function that sets the cursor position*/
|
||||
void (*SetCursor) (int wherex, int wherey);
|
||||
/**Pointer to a function that prints an ascii character in a specified position*/
|
||||
void (*PutChar) (int wherex, int wherey, unsigned char character);
|
||||
/**Pointer to a function that returns the ascii character in the specified position*/
|
||||
unsigned char (*GetChar) (int wherex, int wherey);
|
||||
|
||||
/**Pointer to a function which plots a pixel on the screen. Should be set NULL in text modes.
|
||||
\nColor is a void pointer, to ensure compatibility with different colors.*/
|
||||
void (*PutPixel) (int wherex, int wherey, void* color);
|
||||
|
||||
/**Pointer to a function which returns the color of a pixel on the screen. Should be set NULL in text modes.
|
||||
\nReturn is a void pointer, to ensure compatibility with different colors.*/
|
||||
void* (*GetPixel) (int wherex, int wherey);
|
||||
|
||||
} VideoMode;
|
||||
|
||||
#endif
|
30
SysCore/video/vga03h.c
Normal file
30
SysCore/video/vga03h.c
Normal file
@ -0,0 +1,30 @@
|
||||
//#include "vga.h"
|
||||
#include <conio.h>
|
||||
#include <system.h>
|
||||
|
||||
unsigned char* TextVideoRam = (unsigned char*)0xB8000;
|
||||
|
||||
void vga03h_cursor(int x, int y)
|
||||
{
|
||||
unsigned temp = y*80 + x;
|
||||
|
||||
outportb (0x3D4, 14);
|
||||
outportb (0x3D5, temp >> 8);
|
||||
outportb (0x3D4, 15);
|
||||
outportb (0x3D5, temp);
|
||||
}
|
||||
|
||||
void vga03h_putc (int x, int y, unsigned char c) { TextVideoRam[2*(y*80+x)] = c; }
|
||||
unsigned char vga03h_getc (int x, int y) { return TextVideoRam[2*(y*80+x)]; }
|
||||
void vga03h_putcolor (int x, int y, unsigned char c) { TextVideoRam[2*(y*80+x)+1] = c; }
|
||||
unsigned char vga03h_getcolor (int x, int y) { return TextVideoRam[2*(y*80+x)+1]; }
|
||||
|
||||
void vga03h_install()
|
||||
{
|
||||
ConsoleScreen screen = {
|
||||
80, 25, 0x07, vga03h_cursor, vga03h_putc, vga03h_getc,
|
||||
vga03h_putcolor, vga03h_getcolor};
|
||||
|
||||
ConsoleInstall (screen);
|
||||
clrscr();
|
||||
}
|
7
SysCore/video/vga03h.h
Normal file
7
SysCore/video/vga03h.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef __DEFAULT__TEXT__MODE__H__
|
||||
#define __DEFAULT__TEXT__MODE__H__
|
||||
|
||||
void vga03h_install();
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user