feat: gestion pilotes video, compilation ok, reste à implanter fonctions essentielles

This commit is contained in:
Nicolas Hordé 2018-10-12 22:31:34 +02:00
parent 86c4e4550e
commit 1e77ba8c3f
11 changed files with 292 additions and 276 deletions

View File

@ -2,7 +2,7 @@ target remote localhost:1234
set disassembly-flavor intel
set architecture i386
symbol-file ./system/system.sys
break system.c:59
break main
cont
clear system.c:59
clear main
display/20i $pc

View File

@ -24,16 +24,6 @@
asm volatile ("movl %%esp,%%eax;": "=a" (_v)); \
_v; \
})
u32 ss;
u32 gs;
u32 fs;
u32 es;
u32 ds;
u32 eip;
u32 cs;
#define dumpcpu() asm("\
mov $0x6666666, %%eax \n \

View File

@ -2,28 +2,29 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "types.h"
#include "video.h"
#define TEXTSCREEN 0xB8000 /* debut de la memoire video texte*/
#define GRPHSCREEN 0xA0000 /* debut de la memoire video graphique*/
/* Registres VGAs */
#define sequencer 0x3c4
#define misc_write 0x3c2
#define misc_read 0x3cc
#define ccrt 0x3D4
#define attribs 0x3c0
#define graphics 0x3ce
#define state 0x3da
#define SEQUENCER 0x3c4
#define MISC_WRITE 0x3c2
#define MISC_READ 0x3cc
#define CCRT 0x3D4
#define ATTRIBS 0x3c0
#define GRAPHICS 0x3ce
#define STATE 0x3da
/* Taille d'un plan de bit */
#define planesize 0x10000
#define PLANESIZE 0x10000
/* Registres VGA */
typedef struct misc_regs {
u8 Miscellaneous_Output_Register;
} misc_reg __attribute__ ((packed));
} misc_regs __attribute__ ((packed));
typedef struct sequencer_regs {
u8 Reset_Register;
@ -31,7 +32,7 @@ typedef struct sequencer_regs {
u8 Map_Mask_Register;
u8 Character_Map_Select_Register;
u8 Sequencer_Memory_Mode_Register;
} sequencer_reg __attribute__ ((packed));
} sequencer_regs __attribute__ ((packed));
typedef struct crtc_regs {
u8 Horizontal_Total_Register;
@ -74,7 +75,7 @@ typedef struct graphics_regs {
} graphics_regs __attribute__ ((packed));
typedef struct attributs_regs {
u8 Palette Registers[16];
u8 Palette_Registers[16];
u8 Attribute_Mode_Control_Register;
u8 Overscan_Color_Register;
u8 Color_Plane_Enable_Register;
@ -112,3 +113,28 @@ void VGA_font1_set (u8 num);
void VGA_font2_set (u8 num);
void VGA_blink_enable (void);
void VGA_blink_disable (void);
static videofonction fonctions =
{
&VGA_detect_hardware,
&VGA_setvideo_mode,
&VGA_getvideo_drivername,
&VGA_getvideo_capabilities,
&VGA_getvideo_info,
&VGA_mem_to_video,
&VGA_video_to_mem,
&VGA_video_to_video,
&VGA_wait_vretrace,
&VGA_wait_hretrace,
&VGA_page_set,
&VGA_page_show,
&VGA_page_split,
&VGA_cursor_enable,
&VGA_cursor_disable,
&VGA_cursor_set,
&VGA_font_load,
&VGA_font1_set,
&VGA_font2_set,
&VGA_blink_enable,
&VGA_blink_disable
};

View File

@ -2,26 +2,15 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#ifndef VIDEO
# define VIDEO
#include "stdarg.h"
#define maxdrivers 10
typedef struct drivers {
u8* nom;
videofonction* pointer;
}
typedef struct capabilities {
u8 modenumber;
u16 width;
u16 height;
bool graphic;
u8 depth;
u8 refresh;
}
typedef struct videoinfos {
u8 currentmode
u8 currentmode;
u16 currentwidth;
u16 currentheight;
u8 currentdepth;
@ -40,6 +29,45 @@ typedef struct videoinfos {
u32 baseaddress;
} videoinfos __attribute__ ((packed));
typedef struct videofonction {
u8 *(*detect_hardware)();
u8 (*setvideo_mode) ();
u8 *(*getvideo_drivername) ();
u8 *(*getvideo_capabilities) ();
videoinfos *(*getvideo_info) ();
u32 (*mem_to_video) ();
u32 (*video_to_mem) ();
u32 (*video_to_video) ();
void (*wait_vretrace) ();
void (*wait_hretrace) ();
void (*page_set) ();
void (*page_show) ();
void (*page_split) ();
void (*cursor_enable) ();
void (*cursor_disable) ();
void (*cursor_set) ();
u32 (*font_load) ();
void (*font1_set) ();
void (*font2_set) ();
void (*blink_enable) ();
void (*blink_disable) ();
} videofonction __attribute__ ((packed));
typedef struct drivers {
u8* nom;
videofonction* pointer;
} drivers __attribute__ ((packed));
typedef struct capabilities {
u8 modenumber;
u16 width;
u16 height;
bool graphic;
u8 depth;
u8 refresh;
} capabilities __attribute__ ((packed));
typedef struct console {
u8 attrib;
s16 cursX;
@ -51,30 +79,6 @@ typedef struct console {
u8 page;
} console __attribute__ ((packed));
typedef struct videofonction {
u8 *(*detect_hardware) (void);
u8 (*setvideo_mode) (u8 mode);
u8 *(*getvideo_drivername) (void);
u8 *(*getvideo_capabilities) (void);
videoinfos *(*getvideo_info) (void);
u32 (*mem_to_video) (void *src,u32 dst, u32 size, bool increment_src);
u32 (*video_to_mem) (u32 src,void *dst, u32 size);
u32 (*video_to_video) (u32 src,u32 dst, u32 size);
void (*wait_vretrace) (void);
void (*wait_hretrace) (void);
void (*page_set) (u8 page);
void (*page_show) (u8 page);
void (*page_split) (u16 y);
void (*cursor_enable) (void);
void (*cursor_disable) (void);
void (*cursor_set) (u16 x,u16 y);
u32 (*font_load) (u8 * def, u8 size, u8 font);
void (*font1_set) (u8 num);
void (*font2_set) (u8 num);
void (*blink_enable) (void);
void (*blink_disable) (void);
} videofonction __attribute__ ((packed));
/* Fonctions de bas niveau */
void fill(u8 attrib);
void scroll (u8 lines, u8 attrib);
@ -111,6 +115,7 @@ void apply_bestdriver(void);
void apply_nextdriver(void);
void apply_driver(u8* name);
void apply_nextvideomode(void);
void initvideo(void);
/* Fonctions du pilote */
u8 *(*detect_hardware) (void);
@ -134,3 +139,5 @@ void (*font1_set) (u8 num);
void (*font2_set) (u8 num);
void (*blink_enable) (void);
void (*blink_disable) (void);
#endif

View File

@ -151,3 +151,10 @@ void triangle(vertex2d * AA, vertex2d * BB, vertex2d * CC, u8 color)
line(BB->x, BB->y, CC->x, CC->y, color);
line(CC->x, CC->y, AA->x, AA->y, color);
}
/******************************************************************************/
/* Affiche un pixel à l'écran */
void writepxl (u16 x, u16 y, u32 c)
{
}

View File

@ -4,9 +4,7 @@
/* definition des registres de la carte VGA pour differents modes */
#define nbmodes 9
static capabilities vgacapabilities[nbmodes] = {
static capabilities vgacapabilities[] = {
{0x00, 80, 25,false, 4, 0},
{0x01, 80, 50,false, 4, 0},
{0x80,640,480,true , 1, 0},
@ -20,7 +18,7 @@ static capabilities vgacapabilities[nbmodes] = {
};
static vgamode modes[nbmodes] = {
static vgamode modes[] = {
/*80*25 16 couleurs mode 0x00 */
{{0x67},

View File

@ -113,9 +113,9 @@ void mouse(void)
if (mousey >= 65535) {
mousey = 65535;
}
u16 newx = (u32) mousex * getxres() / 65536;
u16 newy = (u32) mousey * getyres() / 65536;
videoinfos *vinfo=getvideo_info();
u16 newx = (u32) mousex * vinfo->currentwidth / 65536;
u16 newy = (u32) mousey * vinfo->currentheight / 65536;
// Retrieve mouse button status from packet
mousebut1 = mpacket[0] & 1;

View File

@ -365,7 +365,7 @@ int mode(u8* commandline)
}
strgetitem(commandline, &arg, ' ', 1);
argint=strtoint(&arg);
setvmode(argint);
setvideo_mode(argint);
return 0;
}
@ -394,7 +394,7 @@ int rebootnow()
int test2d()
{
setvmode(0x89);
setvideo_mode(0x87);
fill(0x00);
struct vertex2d a, b, c;
randomize();

240
lib/vga.c
View File

@ -12,36 +12,11 @@
static videoinfos infos;
static videofonction fonctions =
{
VGA_detect_hardware;
VGA_setvideo_mode;
VGA_getvideo_drivername;
VGA_getvideo_capabilities;
VGA_getvideo_info;
VGA_mem_to_video;
VGA_video_to_mem;
VGA_video_to_video;
VGA_wait_vretrace;
VGA_wait_hretrace;
VGA_page_set;
VGA_page_show;
VGA_page_split;
VGA_cursor_enable;
VGA_cursor_disable;
VGA_cursor_set;
VGA_font_load;
VGA_font1_set;
VGA_font2_set;
VGA_blink_enable;
VGA_blink_disable;
}
/*******************************************************************************/
/* Detecte si le hardware est disponible, return NULL ou pointeur sur le type de pilote */
u8 *VGA_detect_hardware {
return "LEGACY",
};
u8 *VGA_detect_hardware(void) {
return "LEGACY";
}
/*******************************************************************************/
/* Renvoie l'adresse du segment video */
@ -49,11 +24,11 @@ u8 *VGA_detect_hardware {
u32 getbase(void)
{
u32 base;
/*outb(graphics, 6);
base = inb(graphics + 1);
/*outb(GRAPHICS, 6);
base = inb(GRAPHICS + 1);
base >>= 2;
base &= 3;*/
base = modes[infos.currentmode].graphics.Miscellaneous_Graphics_Register;
base = modes[infos.currentmode].graphic.Miscellaneous_Graphics_Register;
switch (base) {
case 0:
case 1:
@ -74,13 +49,14 @@ u32 getbase(void)
/* ERR 0 aucune
/* ERR 1 mode non existant */
u32 VGA_setvideo_mode(u8 mode)
u8 VGA_setvideo_mode(u8 mode)
{
u32 index;
u32 index=0;
while(vgacapabilities[index].modenumber!=0xFF) {
if (vgacapabilities[index].modenumber==mode) {
infos.currentmode=vgacapabilities[index].modenumber;
break;
}
index++;
}
if (infos.currentmode!=mode)
@ -98,60 +74,60 @@ u32 VGA_setvideo_mode(u8 mode)
infos.isblinking=false;
infos.iscursorvisible=false;
if (infos.isgraphic) {
loadfont(font8x8, 8, 1);
loadfont(font8x16, 16, 0);
switch (infos.depth) {
switch (infos.currentdepth) {
case 1:
/* mode N&B */
infos.currentpitch = infos.width;
infos.currentpitch = infos.currentwidth;
break;
case 2:
/* mode 4 couleurs */
infos.currentpitch = (infos.width << 1);
infos.currentpitch = (infos.currentwidth << 1);
break;
case 4:
/* mode 16 couleurs */
infos.currentpitch = infos.width;
infos.currentpitch = infos.currentwidth;
break;
case 8:
/* mode 256 couleurs */
if (modes[index].sequencer.Sequencer_Memory_Mode_Register == 0x0E) {
/* mode chainé (plus rapide mais limité en mémoire) */
infos.currentpitch = (infos.width << 3);
infos.currentpitch = (infos.currentwidth << 3);
} else {
/* mode non chainé */
infos.currentpitch = (infos.width << 1);
infos.currentpitch = (infos.currentwidth << 1);
}
break;
default:
break;
}
infos.pagesize = ((infos.height * infos.currentpitch) << 3);
infos.pagesize = ((infos.currentheight * infos.currentpitch) << 3);
}
else {
infos.currentpitch= infos.width * 2;
infos.pagesize=infos.height * infos.currentpitch;
VGA_font_load(font8x8, 8, 1);
VGA_font_load(font8x16, 16, 0);
infos.currentpitch= infos.currentwidth * 2;
infos.pagesize=infos.currentheight * infos.currentpitch;
}
infos.pagesnumber=(planesize / infos.currentpitch);
infos.baseaddress=(modes[index].ccrt.Cursor_Location_High_Register << 8) + modes[index].ccrt.Cursor_Location_Low_Register + getbase();
infos.pagesnumber=(PLANESIZE / infos.currentpitch);
infos.baseaddress=(modes[index].ctrc.Cursor_Location_High_Register << 8) + modes[index].ctrc.Cursor_Location_Low_Register + getbase();
/* Initialise les registre "divers" */
outb(misc, modes[index].misc);
outb(MISC_WRITE, modes[index].misc);
/* Initialise les registre d'etat */
outb(state, 0x00);
outb(STATE, 0x00);
/* Initialise le séquenceur */
outreg(sequencer, modes[index].sequencer, 5);
outreg(SEQUENCER, modes[index].sequencer, 5);
/* Debloque le verouillage des registres controleur CRT */
outb(ccrt, 0x11);
outb(ccrt + 1, 0x0E);
outb(CCRT, 0x11);
outb(CCRT + 1, 0x0E);
/* Initialise le controleur CRT */
outreg(ccrt, ctrc, 25);
outreg(CCRT, modes[index].ctrc, 25);
/* Initialise le controleur graphique */
outreg(graphics, modes[index].graphic, 9);
inb(state);
outreg(GRAPHICS, modes[index].graphic, 9);
inb(STATE);
/* Initialise le controleur d'attributs */
outregsame(attribs, modes[index].attributs, 21);
inb(state);
outb(attribs, 0x20);
outregsame(ATTRIBS, modes[index].attribut, 21);
inb(STATE);
outb(ATTRIBS, 0x20);
/* Initialise l'adresse des procedures de gestion graphique et les differentes
variables en fonction de la profondeur et du mode */
return 0;
@ -173,7 +149,7 @@ u8 *VGA_getvideo_capabilities (void) {
/*******************************************************************************/
/* Renvoie un pointeur sur l'état courant de la carte */
videoinfos *VGA_getvideo_info (void) {
return infos;
return &infos;
}
/*******************************************************************************/
@ -211,10 +187,10 @@ void VGA_page_show(u8 page)
if (page < infos.pagesnumber) {
u16 addr;
addr = page * infos.pagesize / 2;
outb(ccrt, 0x0C);
outb(ccrt + 1, (addr >> 8));
outb(ccrt, 0x0D);
outb(ccrt + 1, (addr & 0xFF));
outb(CCRT, 0x0C);
outb(CCRT + 1, (addr >> 8));
outb(CCRT, 0x0D);
outb(CCRT + 1, (addr & 0xFF));
infos.currentshowedpage = page;
}
}
@ -228,38 +204,38 @@ void VGA_page_split(u16 y)
{
if (y!=0) {
u16 addr;
if (graphic == 0)
if (!infos.isgraphic)
addr = (y << 3);
else
addr = y;
/* line compare pour ligne atteinte */
outb(ccrt, 0x18);
outb(ccrt + 1, (addr & 0xFF));
outb(CCRT, 0x18);
outb(CCRT + 1, (addr & 0xFF));
/* overflow pour le bit 8 */
outb(ccrt, 0x07);
outb(ccrt + 1, (inb(ccrt + 1) & ~16) | ((addr >> 4) & 16));
outb(CCRT, 0x07);
outb(CCRT + 1, (inb(CCRT + 1) & ~16) | ((addr >> 4) & 16));
/* Maximum Scan Line pour le bit 9 */
outb(ccrt, 0x09);
outb(ccrt + 1, (inb(ccrt + 1) & ~64) | ((addr >> 3) & 64));
outb(CCRT, 0x09);
outb(CCRT + 1, (inb(CCRT + 1) & ~64) | ((addr >> 3) & 64));
splitY = y;
}
else
{
/* line compare pour ligne atteinte */
outb(ccrt, 0x18);
outb(ccrt + 1, 0);
outb(CCRT, 0x18);
outb(CCRT + 1, 0);
/* overflow pour le bit 8 */
outb(ccrt, 0x07);
outb(ccrt + 1, inb(ccrt + 1) & ~16);
outb(CCRT, 0x07);
outb(CCRT + 1, inb(CCRT + 1) & ~16);
/* Maximum Scan Line pour le bit 9 */
outb(ccrt, 0x09);
outb(ccrt + 1, inb(ccrt + 1) & ~64);
outb(CCRT, 0x09);
outb(CCRT + 1, inb(CCRT + 1) & ~64);
splitY = 0;
}
}
@ -269,7 +245,7 @@ void VGA_page_split(u16 y)
void VGA_wait_vretrace(void)
{
while ((inb(state) & 8) == 0) ;
while ((inb(STATE) & 8) == 0) ;
}
/*******************************************************************************/
@ -277,7 +253,7 @@ void VGA_wait_vretrace(void)
void VGA_wait_hretrace(void)
{
while ((inb(state) & 1) == 0) ;
while ((inb(STATE) & 1) == 0) ;
}
/*******************************************************************************/
@ -287,9 +263,9 @@ void VGA_cursor_enable(void)
{
u8 curs;
/* active le curseur hardware */
outb(ccrt, 10);
curs = inb(ccrt + 1) & ~32;
outb(ccrt + 1, curs);
outb(CCRT, 10);
curs = inb(CCRT + 1) & ~32;
outb(CCRT + 1, curs);
infos.isgraphic=true;
}
@ -300,9 +276,9 @@ void VGA_cursor_disable(void)
{
u8 curs;
/* Desactive le curseur hardware */
outb(ccrt, 10);
curs = inb(ccrt + 1) | 32;
outb(ccrt + 1, curs);
outb(CCRT, 10);
curs = inb(CCRT + 1) | 32;
outb(CCRT + 1, curs);
infos.isgraphic=false;
}
@ -315,11 +291,11 @@ void useplane(u8 plan)
plan &= 3;
mask = 1 << plan;
/* choisi le plan de lecture */
outb(graphics, 4);
outb(graphics + 1, plan);
outb(GRAPHICS, 4);
outb(GRAPHICS + 1, plan);
/* choisi le plan d'ecriture */
outb(sequencer, 2);
outb(sequencer + 1, mask);
outb(SEQUENCER, 2);
outb(SEQUENCER + 1, mask);
}
/*******************************************************************************/
@ -329,15 +305,15 @@ void VGA_cursor_set(u16 x, u16 y)
{
u16 pos;
if (splitY == 0)
pos = (infos.currentshowedpage * infos.pagesize / 2 + x + y * infos.width);
pos = (infos.currentshowedpage * infos.pagesize / 2 + x + y * infos.currentwidth);
else
pos = (x + y * infos.width);
outb(ccrt, 0x0F);
outb(ccrt + 1, (u8) (pos & 0x00FF));
outb(ccrt, 0x0E);
outb(ccrt + 1, (u8) ((pos & 0xFF00) >> 8));
info.currentcursorX=x;
info.currentcursorY=y;
pos = (x + y * infos.currentwidth);
outb(CCRT, 0x0F);
outb(CCRT + 1, (u8) (pos & 0x00FF));
outb(CCRT, 0x0E);
outb(CCRT + 1, (u8) ((pos & 0xFF00) >> 8));
infos.currentcursorX=x;
infos.currentcursorY=y;
}
/*******************************************************************************/
@ -358,38 +334,38 @@ u32 VGA_font_load(u8 * def, u8 size, u8 font)
else
base = (u8 *) (getbase() + ((((font - 4) << 1) + 1) << 13));
/* sauve les anciens registres */
outb(sequencer, 2);
oldregs[0] = inb(sequencer + 1);
outb(sequencer, 4);
oldregs[1] = inb(sequencer + 1);
outb(SEQUENCER, 2);
oldregs[0] = inb(SEQUENCER + 1);
outb(SEQUENCER, 4);
oldregs[1] = inb(SEQUENCER + 1);
/* Adressage paire/impair desactivé (lineaire) */
outb(sequencer + 1, oldregs[1] | 0x04);
outb(graphics, 4);
oldregs[2] = inb(graphics + 1);
outb(graphics, 5);
oldregs[3] = inb(graphics + 1);
outb(SEQUENCER + 1, oldregs[1] | 0x04);
outb(GRAPHICS, 4);
oldregs[2] = inb(GRAPHICS + 1);
outb(GRAPHICS, 5);
oldregs[3] = inb(GRAPHICS + 1);
/* Adressage paire/impair desactivé (lineaire) */
outb(graphics + 1, oldregs[3] & ~0x10);
outb(graphics, 6);
oldregs[4] = inb(graphics + 1);
outb(GRAPHICS + 1, oldregs[3] & ~0x10);
outb(GRAPHICS, 6);
oldregs[4] = inb(GRAPHICS + 1);
/* Adressage paire/impair desactivé (lineaire) */
outb(graphics + 1, oldregs[4] & ~0x02);
outb(GRAPHICS + 1, oldregs[4] & ~0x02);
/* utilisation du plan N°2 */
useplane(2);
for (i = 0; i < 256; i++) {
memcpy(def, base + i * 32, size, 1);
def += size;
}
outb(sequencer, 2);
outb(sequencer + 1, oldregs[0]);
outb(sequencer, 4);
outb(sequencer + 1, oldregs[1]);
outb(graphics, 4);
outb(graphics + 1, oldregs[2]);
outb(graphics, 5);
outb(graphics + 1, oldregs[3]);
outb(graphics, 6);
outb(graphics + 1, oldregs[4]);
outb(SEQUENCER, 2);
outb(SEQUENCER + 1, oldregs[0]);
outb(SEQUENCER, 4);
outb(SEQUENCER + 1, oldregs[1]);
outb(GRAPHICS, 4);
outb(GRAPHICS + 1, oldregs[2]);
outb(GRAPHICS, 5);
outb(GRAPHICS + 1, oldregs[3]);
outb(GRAPHICS, 6);
outb(GRAPHICS + 1, oldregs[4]);
return 0;
}
@ -399,11 +375,11 @@ u32 VGA_font_load(u8 * def, u8 size, u8 font)
void VGA_font1_set(u8 num)
{
num &= 0x07;
outb(sequencer, 3);
outb(sequencer + 1,
(inb(sequencer + 1) & 0xEC) | ((num & 0x03) +
outb(SEQUENCER, 3);
outb(SEQUENCER + 1,
(inb(SEQUENCER + 1) & 0xEC) | ((num & 0x03) +
((num & 0x04) << 2)));
info.currentfont1=num;
infos.currentfont1=num;
}
/*******************************************************************************/
@ -412,11 +388,11 @@ void VGA_font1_set(u8 num)
void VGA_font2_set(u8 num)
{
num &= 0x07;
outb(sequencer, 3);
outb(sequencer + 1,
(inb(sequencer + 1) & 0xD3) | (((num & 0x03) << 2) +
outb(SEQUENCER, 3);
outb(SEQUENCER + 1,
(inb(SEQUENCER + 1) & 0xD3) | (((num & 0x03) << 2) +
((num & 0x04) << 3)));
info.currentfont2=num;
infos.currentfont2=num;
}
/*******************************************************************************/
@ -424,9 +400,9 @@ void VGA_font2_set(u8 num)
void VGA_blink_enable(void)
{
outb(ccrt, 0x10);
outb(ccrt + 1, (inb(sequencer + 1) | 0x04));
info.isblinking=true;
outb(CCRT, 0x10);
outb(CCRT + 1, (inb(SEQUENCER + 1) | 0x04));
infos.isblinking=true;
}
/*******************************************************************************/
@ -434,9 +410,9 @@ void VGA_blink_enable(void)
void VGA_blink_disable(void)
{
outb(ccrt, 0x10);
outb(ccrt + 1, (inb(sequencer + 1) & ~0x04));
info.isblinking=false;
outb(CCRT, 0x10);
outb(CCRT + 1, (inb(SEQUENCER + 1) & ~0x04));
infos.isblinking=false;
}
/*******************************************************************************/

View File

@ -7,21 +7,16 @@
drivers registred[maxdrivers];
videoinfos *vinfo;
console vc[8] = {
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0}
,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0} ,
{0x07, 0, 0, 0, 0, 0, 0, 0}
};
@ -96,7 +91,7 @@ bool makeansi(u8 c)
fill(vc[usedvc].attrib);
vc[usedvc].cursX = 0;
vc[usedvc].cursY = 0;
gotoscr(0, 0);
cursor_set(0, 0);
vc[usedvc].ansi = 0;
return 1;
}
@ -113,16 +108,16 @@ bool makeansi(u8 c)
if (vc[usedvc].cursY < 0)
vc[usedvc].cursY = 0;
vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
return 1;
}
/* ESC[num1B -- bouge le curseur de num1 vers le bas */
else if (c == 'B') {
vc[usedvc].cursY += vc[usedvc].param1;
if (vc[usedvc].cursY >= getyres() - 1)
vc[usedvc].cursY = getyres();
if (vc[usedvc].cursY >= vinfo->currentheight - 1)
vc[usedvc].cursY = vinfo->currentheight;
vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
return 1;
}
/* ESC[num1D -- bouge le curseur de num1 vers la gauche */
@ -131,16 +126,16 @@ bool makeansi(u8 c)
if (vc[usedvc].cursX < 0)
vc[usedvc].cursX = 0;
vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
return 1;
}
/* ESC[num1C -- bouge le curseur de num1 vers la droite */
else if (c == 'C') {
vc[usedvc].cursX += vc[usedvc].param1;
if (vc[usedvc].cursX >= getxres() - 1)
vc[usedvc].cursX = getxres();
if (vc[usedvc].cursX >= vinfo->currentwidth - 1)
vc[usedvc].cursX = vinfo->currentwidth;
vc[usedvc].ansi = 0;
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
return 1;
}
break;
@ -157,7 +152,7 @@ bool makeansi(u8 c)
/* ESC[num1;num2H ou ESC[num1;num2f-- bouge le curseur en num1,num2 */
else if ((c == 'H') || (c == 'f')) {
/* Remet la position du curseur matériel a num1,num2 */
gotoscr(vc[usedvc].param2, vc[usedvc].param1);
cursor_set(vc[usedvc].param2, vc[usedvc].param1);
/* Remet la position du curseur logiciel a num1,num2 */
vc[usedvc].cursX = vc[usedvc].param2;
vc[usedvc].cursY = vc[usedvc].param1;
@ -195,6 +190,13 @@ bool makeansi(u8 c)
vc[usedvc].ansi = 0;
return 0; /* Ansi fini ;) */
}
void changemode(u8 mode)
{
setvideo_mode(mode);
vinfo=getvideo_info();
}
/*******************************************************************************/
/* Efface la console en cours d'utilisation */
void clearscreen(void)
@ -202,7 +204,7 @@ void clearscreen(void)
fill(0x00);
vc[usedvc].cursX=0;
vc[usedvc].cursY=0;
gotoscr(0,0);
cursor_set(0,0);
}
/*******************************************************************************/
@ -211,9 +213,9 @@ void clearscreen(void)
void changevc(u8 avc)
{
usedvc = avc;
showpage(usedvc);
setpage(usedvc);
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
page_show(usedvc);
page_set(usedvc);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
}
/*******************************************************************************/
@ -221,8 +223,8 @@ void changevc(u8 avc)
void putchar(u8 thechar)
{
showpage(usedvc);
setpage(usedvc);
page_show(usedvc);
page_set(usedvc);
if (makeansi(thechar))
return;
switch (thechar) {
@ -231,7 +233,7 @@ void putchar(u8 thechar)
vc[usedvc].cursY--;
break;
case 0x12:
if (vc[usedvc].cursY < getyres() - 1)
if (vc[usedvc].cursY < vinfo->currentheight - 1)
vc[usedvc].cursY++;
break;
case 0x13:
@ -239,7 +241,7 @@ void putchar(u8 thechar)
vc[usedvc].cursX--;
break;
case 0x14:
if (vc[usedvc].cursX < getxres() - 1)
if (vc[usedvc].cursX < vinfo->currentwidth - 1)
vc[usedvc].cursX++;
break;
case 0x2:
@ -248,15 +250,15 @@ void putchar(u8 thechar)
break;
case 0x3:
vc[usedvc].cursX = 0;
vc[usedvc].cursY = getyres() - 1;
vc[usedvc].cursY = vinfo->currentheight - 1;
break;
case 0x19:
vc[usedvc].cursX = getxres() - 1;
vc[usedvc].cursX = vinfo->currentwidth - 1;
break;
case '\b':
if (vc[usedvc].cursX == 0) {
if (vc[usedvc].cursY > 0) {
vc[usedvc].cursX = getxres() - 1;
vc[usedvc].cursX = vinfo->currentwidth - 1;
vc[usedvc].cursY--;
}
} else {
@ -283,15 +285,15 @@ void putchar(u8 thechar)
}
break;
}
if (vc[usedvc].cursX >= getxres()) {
if (vc[usedvc].cursX >= vinfo->currentwidth) {
vc[usedvc].cursX = 0;
vc[usedvc].cursY++;
}
if (vc[usedvc].cursY >= getyres()) {
if (vc[usedvc].cursY >= vinfo->currentheight) {
scroll(1, vc[usedvc].attrib);
vc[usedvc].cursY = getyres() - 1;
vc[usedvc].cursY = vinfo->currentheight - 1;
}
gotoscr(vc[usedvc].cursX, vc[usedvc].cursY);
cursor_set(vc[usedvc].cursX, vc[usedvc].cursY);
}
/*******************************************************************************/
@ -825,7 +827,7 @@ void initdriver() {
/*******************************************************************************/
/* Enregistre un pilote dans le tableau des pilotes vidéo */
void registerdriver(videofonction *pointer);
void registerdriver(videofonction *pointer)
{
u32 i;
for(i=0;i<maxdrivers;i++)
@ -835,6 +837,7 @@ void registerdriver(videofonction *pointer);
while (registred[i].nom!=NULL && i<maxdrivers)
i++;
registred[i].pointer=pointer;
registred[i].nom=pointer->getvideo_drivername();
}
/*******************************************************************************/
/* Choisi le meilleur driver en terme d'affichage */
@ -844,15 +847,16 @@ void apply_bestdriver(void) {
u8 bestresol=0x0;
u8 bestmode=0x0;
u8* bestdriver=NULL;
capabilities *cap;
while (registred[i].nom!=NULL && i<maxdrivers) {
capabilities cap=registred[i].pointer.getvideo_capabilities();
cap=registred[i].pointer->getvideo_capabilities();
while(cap[j].modenumber!=0xFF) {
if (cap[j].depth>bestdepth && (cap[j].width*cap[j].height)>=bestresol)
{
bestdepth=cap[j].depth;
bestresol=cap[j].width*cap[j].height;
bestmode=cap[j].modenumber;
bestdriver=registred[i].pointer.getvideo_drivername();
bestdriver=registred[i].pointer->getvideo_drivername();
}
j++;
}
@ -864,43 +868,44 @@ void apply_bestdriver(void) {
/*******************************************************************************/
/* Choisi le meilleur driver spécifié par le nom */
void apply_driver(u8* name);
void apply_driver(u8* name)
{
u32 i=0;
while (registred[i].nom!=NULL && i<maxdrivers) {
if (strcmp(name,registred[i].nom)==0) {
detect_hardware=registred[i].pointer.detect_hardware;
setvideo_mode=registred[i].pointer.setvideo_mode;
getvideo_drivername=registred[i].pointer.getvideo_drivername;
getvideo_capabilities=registred[i].pointer.getvideo_capabilities;
getvideo_info=registred[i].pointer.getvideo_info;
mem_to_video=registred[i].pointer.mem_to_video;
video_to_mem=registred[i].pointer.video_to_mem;
video_to_video=registred[i].pointer.video_to_video;
wait_vretrace=registred[i].pointer.wait_vretrace;
wait_hretrace=registred[i].pointer.wait_hretrace;
page_set=registred[i].pointer.page_set;
page_show=registred[i].pointer.page_show;
page_split=registred[i].pointer.page_split;
cursor_enable=registred[i].pointer.cursor_enable;
cursor_disable=registred[i].pointer.cursor_disable;
cursor_set=registred[i].pointer.cursor_set;
font_load=registred[i].pointer.font_load;
font1_set=registred[i].pointer.font1_set;
font2_set=registred[i].pointer.font2_set;
blink_enable=registred[i].pointer.blink_enable;
blink_disable=registred[i].pointer.blink_disable;
detect_hardware=registred[i].pointer->detect_hardware;
setvideo_mode=registred[i].pointer->setvideo_mode;
getvideo_drivername=registred[i].pointer->getvideo_drivername;
getvideo_capabilities=registred[i].pointer->getvideo_capabilities;
getvideo_info=registred[i].pointer->getvideo_info;
mem_to_video=registred[i].pointer->mem_to_video;
video_to_mem=registred[i].pointer->video_to_mem;
video_to_video=registred[i].pointer->video_to_video;
wait_vretrace=registred[i].pointer->wait_vretrace;
wait_hretrace=registred[i].pointer->wait_hretrace;
page_set=registred[i].pointer->page_set;
page_show=registred[i].pointer->page_show;
page_split=registred[i].pointer->page_split;
cursor_enable=registred[i].pointer->cursor_enable;
cursor_disable=registred[i].pointer->cursor_disable;
cursor_set=registred[i].pointer->cursor_set;
font_load=registred[i].pointer->font_load;
font1_set=registred[i].pointer->font1_set;
font2_set=registred[i].pointer->font2_set;
blink_enable=registred[i].pointer->blink_enable;
blink_disable=registred[i].pointer->blink_disable;
setvideo_mode(0x0);
return;
}
i++;
}
setvideo_mode(0x0);
}
/*******************************************************************************/
/* Applique le driver suivant */
void apply_nextdriver(void) {
u32 i=0;
while (registred[i].nom!=NULL && i<maxdrivers) {
while (registred[i].nom!=NULL && i<maxdrivers)
if (strcmp(getvideo_drivername(),registred[i].nom)==0) {
i++;
if (registred[i].nom!=NULL) i=0;
@ -914,9 +919,9 @@ void apply_nextdriver(void) {
/* Applique le mode suivant (le driver suivant si dernier mode) */
void apply_nextvideomode(void) {
capabilities cap=getvideo_capabilities();
videoinfos info=getvideo_info();
u32 mode=info.modenumber;
capabilities *cap=getvideo_capabilities();
videoinfos *info=getvideo_info();
u32 mode=info->currentmode;
u8 index=0;
while(cap[index].modenumber!=0xFF) {
if (cap[index].modenumber==mode) {
@ -931,6 +936,15 @@ void apply_nextvideomode(void) {
}
}
/*******************************************************************************/
/* Initialise la video */
void initvideo(void)
{
initdriver();
registerdriver(&fonctions);
apply_driver("VGA");
}
/*******************************/
void fill(u8 attrib)

View File

@ -46,10 +46,8 @@ void error()
int main(u32 magic, u32 addr)
{
cli();
initdriver();
registerdriver(&fonctions);
apply_driver("VGA");
setvideo_mode(0x02);
initvideo();
changemode(0x02);
/* Efface l'ecran */
print("\033[2J\000");