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 disassembly-flavor intel
set architecture i386 set architecture i386
symbol-file ./system/system.sys symbol-file ./system/system.sys
break system.c:59 break main
cont cont
clear system.c:59 clear main
display/20i $pc display/20i $pc

View File

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

View File

@ -2,28 +2,29 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "types.h" #include "types.h"
#include "video.h"
#define TEXTSCREEN 0xB8000 /* debut de la memoire video texte*/ #define TEXTSCREEN 0xB8000 /* debut de la memoire video texte*/
#define GRPHSCREEN 0xA0000 /* debut de la memoire video graphique*/ #define GRPHSCREEN 0xA0000 /* debut de la memoire video graphique*/
/* Registres VGAs */ /* Registres VGAs */
#define sequencer 0x3c4 #define SEQUENCER 0x3c4
#define misc_write 0x3c2 #define MISC_WRITE 0x3c2
#define misc_read 0x3cc #define MISC_READ 0x3cc
#define ccrt 0x3D4 #define CCRT 0x3D4
#define attribs 0x3c0 #define ATTRIBS 0x3c0
#define graphics 0x3ce #define GRAPHICS 0x3ce
#define state 0x3da #define STATE 0x3da
/* Taille d'un plan de bit */ /* Taille d'un plan de bit */
#define planesize 0x10000 #define PLANESIZE 0x10000
/* Registres VGA */ /* Registres VGA */
typedef struct misc_regs { typedef struct misc_regs {
u8 Miscellaneous_Output_Register; u8 Miscellaneous_Output_Register;
} misc_reg __attribute__ ((packed)); } misc_regs __attribute__ ((packed));
typedef struct sequencer_regs { typedef struct sequencer_regs {
u8 Reset_Register; u8 Reset_Register;
@ -31,7 +32,7 @@ typedef struct sequencer_regs {
u8 Map_Mask_Register; u8 Map_Mask_Register;
u8 Character_Map_Select_Register; u8 Character_Map_Select_Register;
u8 Sequencer_Memory_Mode_Register; u8 Sequencer_Memory_Mode_Register;
} sequencer_reg __attribute__ ((packed)); } sequencer_regs __attribute__ ((packed));
typedef struct crtc_regs { typedef struct crtc_regs {
u8 Horizontal_Total_Register; u8 Horizontal_Total_Register;
@ -74,7 +75,7 @@ typedef struct graphics_regs {
} graphics_regs __attribute__ ((packed)); } graphics_regs __attribute__ ((packed));
typedef struct attributs_regs { typedef struct attributs_regs {
u8 Palette Registers[16]; u8 Palette_Registers[16];
u8 Attribute_Mode_Control_Register; u8 Attribute_Mode_Control_Register;
u8 Overscan_Color_Register; u8 Overscan_Color_Register;
u8 Color_Plane_Enable_Register; u8 Color_Plane_Enable_Register;
@ -112,3 +113,28 @@ void VGA_font1_set (u8 num);
void VGA_font2_set (u8 num); void VGA_font2_set (u8 num);
void VGA_blink_enable (void); void VGA_blink_enable (void);
void VGA_blink_disable (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 */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#ifndef VIDEO
# define VIDEO
#include "stdarg.h" #include "stdarg.h"
#define maxdrivers 10 #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 { typedef struct videoinfos {
u8 currentmode u8 currentmode;
u16 currentwidth; u16 currentwidth;
u16 currentheight; u16 currentheight;
u8 currentdepth; u8 currentdepth;
@ -40,6 +29,45 @@ typedef struct videoinfos {
u32 baseaddress; u32 baseaddress;
} videoinfos __attribute__ ((packed)); } 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 { typedef struct console {
u8 attrib; u8 attrib;
s16 cursX; s16 cursX;
@ -51,30 +79,6 @@ typedef struct console {
u8 page; u8 page;
} console __attribute__ ((packed)); } 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 */ /* Fonctions de bas niveau */
void fill(u8 attrib); void fill(u8 attrib);
void scroll (u8 lines, u8 attrib); void scroll (u8 lines, u8 attrib);
@ -111,6 +115,7 @@ void apply_bestdriver(void);
void apply_nextdriver(void); void apply_nextdriver(void);
void apply_driver(u8* name); void apply_driver(u8* name);
void apply_nextvideomode(void); void apply_nextvideomode(void);
void initvideo(void);
/* Fonctions du pilote */ /* Fonctions du pilote */
u8 *(*detect_hardware) (void); u8 *(*detect_hardware) (void);
@ -134,3 +139,5 @@ void (*font1_set) (u8 num);
void (*font2_set) (u8 num); void (*font2_set) (u8 num);
void (*blink_enable) (void); void (*blink_enable) (void);
void (*blink_disable) (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(BB->x, BB->y, CC->x, CC->y, color);
line(CC->x, CC->y, AA->x, AA->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 */ /* definition des registres de la carte VGA pour differents modes */
#define nbmodes 9 static capabilities vgacapabilities[] = {
static capabilities vgacapabilities[nbmodes] = {
{0x00, 80, 25,false, 4, 0}, {0x00, 80, 25,false, 4, 0},
{0x01, 80, 50,false, 4, 0}, {0x01, 80, 50,false, 4, 0},
{0x80,640,480,true , 1, 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 */ /*80*25 16 couleurs mode 0x00 */
{{0x67}, {{0x67},

View File

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

View File

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

240
lib/vga.c
View File

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

View File

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

View File

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