feat: pilote remanié VGA ok en mode texte

This commit is contained in:
Nicolas Hordé 2018-10-13 11:25:55 +02:00
parent 016b972d97
commit 605953aa3b
9 changed files with 183 additions and 96 deletions

View File

@ -8,8 +8,6 @@ typedef struct vertex2d{
u32 y; u32 y;
} vertex2d __attribute__ ((packed)); } vertex2d __attribute__ ((packed));
void writepxl (u16 x, u16 y, u32 c);
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color);
void linev(vertex2d *A, vertex2d *B, u8 color); void linev(vertex2d *A, vertex2d *B, u8 color);
void hline(u32 x1, u32 x2, u32 y, u8 color); void hline(u32 x1, u32 x2, u32 y, u8 color);
void trianglefilled(vertex2d *A, vertex2d *B, vertex2d *C, u8 color); void trianglefilled(vertex2d *A, vertex2d *B, vertex2d *C, u8 color);

View File

@ -122,6 +122,29 @@
#define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) ) #define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) )
#define movsb(src,dst,count) \
asm volatile ("cld;rep movsb"::"S" (src), "D" (dst), "c" (count));
#define movsw(src,dst,count) \
asm volatile ("cld;rep movsw"::"S" (src), "D" (dst), "c" (count));
#define movsd(src,dst,count) \
asm volatile ("cld;rep movsd"::"S" (src), "D" (dst), "c" (count));
#define stosb(pattern,dst,count) \
asm volatile ("cld;rep stosb"::"c" (count), "D" (dst), "a" (pattern));
#define stosw(pattern,dst,count) \
asm volatile ("cld;rep stosw"::"a" (pattern), "c" (count), "D" (dst));
#define stosd(pattern,dst,count) \
asm volatile ("cld;rep stosd"::"a" (pattern), "c" (count), "D" (dst));
#define rol(addr) \
asm volatile ("rolb %0":"=m" (addr):);
#define ror(addr) \
asm volatile ("rorb %0":"=m" (addr):);
/******************************************************************************/ /******************************************************************************/
#define outb(port,value) \ #define outb(port,value) \

View File

@ -7,24 +7,6 @@
#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*/
#define movsb(src,dst,count) \
asm volatile ("cld;rep movsb"::"S" (src), "D" (dst), "c" (count));
#define movsw(src,dst,count) \
asm volatile ("cld;rep movsw"::"S" (src), "D" (dst), "c" (count));
#define movsd(src,dst,count) \
asm volatile ("cld;rep movsd"::"S" (src), "D" (dst), "c" (count));
#define stosb(pattern,dst,count) \
asm volatile ("cld;rep stosb"::"c" (count), "D" (dst), "a" (pattern));
#define stosw(pattern,dst,count) \
asm volatile ("cld;rep stosw"::"a" (pattern), "c" (count), "D" (dst));
#define stosd(pattern,dst,count) \
asm volatile ("cld;rep stosd"::"a" (pattern), "c" (count), "D" (dst));
/* Registres VGAs */ /* Registres VGAs */
@ -116,9 +98,9 @@ u8 VGA_setvideo_mode (u8 mode);
u8 *VGA_getvideo_drivername (void); u8 *VGA_getvideo_drivername (void);
u8 *VGA_getvideo_capabilities (void); u8 *VGA_getvideo_capabilities (void);
videoinfos *VGA_getvideo_info (void); videoinfos *VGA_getvideo_info (void);
u32 VGA_mem_to_video (void *src,u32 dst, u32 size, u8 realsize, bool increment_src); u32 VGA_mem_to_video (void *src,u32 dst, u32 size, bool increment_src);
u32 VGA_video_to_mem (u32 src,void *dst, u32 size, u8 realsize); u32 VGA_video_to_mem (u32 src,void *dst, u32 size);
u32 VGA_video_to_video (u32 src,u32 dst, u32 size, u8 realsize); u32 VGA_video_to_video (u32 src,u32 dst, u32 size);
void VGA_wait_vretrace (void); void VGA_wait_vretrace (void);
void VGA_wait_hretrace (void); void VGA_wait_hretrace (void);
void VGA_page_set (u8 page); void VGA_page_set (u8 page);

View File

@ -88,6 +88,8 @@ void scroll_disable(void);
void showchar (u16 coordx, u16 coordy, u8 thechar, u8 attrib); void showchar (u16 coordx, u16 coordy, u8 thechar, u8 attrib);
u8 getchar (u16 coordx, u16 coordy); u8 getchar (u16 coordx, u16 coordy);
u8 getattrib (u16 coordx, u16 coordy); u8 getattrib (u16 coordx, u16 coordy);
void writepxl (u16 x, u16 y, u32 color);
void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color);
/* Fonctions de console */ /* Fonctions de console */
void changevc(u8 vc); void changevc(u8 vc);
@ -124,9 +126,9 @@ u8 (*setvideo_mode) (u8 mode);
u8 *(*getvideo_drivername) (void); u8 *(*getvideo_drivername) (void);
u8 *(*getvideo_capabilities) (void); u8 *(*getvideo_capabilities) (void);
videoinfos *(*getvideo_info) (void); videoinfos *(*getvideo_info) (void);
u32 (*mem_to_video) (void *src,u32 dst, u32 size, u8 realsize, bool increment_src); u32 (*mem_to_video) (void *src,u32 dst, u32 size, bool increment_src);
u32 (*video_to_mem) (u32 src,void *dst, u32 size, u8 realsize); u32 (*video_to_mem) (u32 src,void *dst, u32 size);
u32 (*video_to_video) (u32 src,u32 dst, u32 size, u8 realsize); u32 (*video_to_video) (u32 src,u32 dst, u32 size);
void (*wait_vretrace) (void); void (*wait_vretrace) (void);
void (*wait_hretrace) (void); void (*wait_hretrace) (void);
void (*page_set) (u8 page); void (*page_set) (u8 page);

View File

@ -57,19 +57,6 @@ void line(u32 x1, u32 y1, u32 x2, u32 y2, u8 color)
} }
} }
/******************************************************************************/
/* Affiche une ligne horizontale entre les points spécifiés */
void hline(u32 x1, u32 x2, u32 y, u8 color)
{
if (x2 > x1)
for (; x1 <= x2; x1++)
writepxl(x1, y, color);
else
for (; x2 <= x1; x2++)
writepxl(x2, y, color);
}
/******************************************************************************/ /******************************************************************************/
/* Affiche un triangle rempli entre les points spécifiés */ /* Affiche un triangle rempli entre les points spécifiés */
@ -152,9 +139,4 @@ void triangle(vertex2d * AA, vertex2d * BB, vertex2d * CC, u8 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

@ -22,7 +22,7 @@ static vgamode modes[] = {
/*80*25 16 couleurs mode 0x00 */ /*80*25 16 couleurs mode 0x00 */
{{0x67}, {{0x67},
{0x03, 0x00, 0x03, 0x00, 0x06}, {0x03, 0x00, 0x03, 0x00, 0x02},
{0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, {0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF}, 0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF},

View File

@ -36,10 +36,11 @@ void initpaging(void)
void memset(void *dst, u8 val, u32 count, u32 size) void memset(void *dst, u8 val, u32 count, u32 size)
{ {
u8 * temp; u8 *d = (u8 *) dst;
for (temp = (u8 *) dst; count != 0; count--) { if (size>0) size--;
temp += size; for (; count != 0; count--) {
*temp = val; *(d++) = val;
d+=size;
} }
} }
@ -48,12 +49,12 @@ temp += size;
void memcpy(void *src, void *dst, u32 count, u32 size) void memcpy(void *src, void *dst, u32 count, u32 size)
{ {
char *s, *d; u8 *s = (u8 *) src;
u32 i; u8 *d = (u8 *) dst;
s = (u8 *) src; if (size>0) size--;
d = (u8 *) dst; for (; count != 0; count--) {
for (i = 0; i < count; i++) { *(d++) = *(s++);
*(d + i * size) = *(s + i); d+=size;
} }
} }
@ -62,13 +63,14 @@ for (i = 0; i < count; i++) {
u32 memcmp(void *src, void *dst, u32 count, u32 size) u32 memcmp(void *src, void *dst, u32 count, u32 size)
{ {
const u8 *mem1 = (const u8 *)src; u8 *s = (u8 *) src;
const u8 *mem2 = (const u8 *)dst; u8 *d = (u8 *) dst;
if (size>0) size--;
for (; count != 0; count--) { for (; count != 0; count--) {
if (*mem1 != *mem2) if (*(s++) != *(d++))
return *mem1 - *mem2; return *d - *s;
mem1 += size; s+= size;
mem2 += size; d+= size;
} }
} }

View File

@ -7,8 +7,6 @@
#include "asm.h" #include "asm.h"
#include "types.h" #include "types.h"
#include "VGA/modes.c" #include "VGA/modes.c"
#include "VGA/8x8fnt.c"
#include "VGA/8x16fnt.c"
static videoinfos infos; static videoinfos infos;
@ -110,8 +108,6 @@ u8 VGA_setvideo_mode(u8 mode)
infos.pagesize = ((infos.currentheight * infos.currentpitch) << 3); infos.pagesize = ((infos.currentheight * infos.currentpitch) << 3);
} }
else { else {
VGA_font_load(font8x8, 8, 1);
VGA_font_load(font8x16, 16, 0);
infos.currentpitch= infos.currentwidth * 2; infos.currentpitch= infos.currentwidth * 2;
infos.pagesize=infos.currentheight * infos.currentpitch; infos.pagesize=infos.currentheight * infos.currentpitch;
realsize=0; realsize=0;
@ -162,7 +158,7 @@ videoinfos *VGA_getvideo_info (void) {
/*******************************************************************************/ /*******************************************************************************/
/* Effecture un mouvement de la mémoire centrale vers la mémoire video (linéarisée) */ /* Effecture un mouvement de la mémoire centrale vers la mémoire video (linéarisée) */
u32 VGA_mem_to_video (void *src,u32 dst, u32 size, u8 realsize, bool increment_src) { u32 VGA_mem_to_video (void *src,u32 dst, u32 size, bool increment_src) {
u32 realdst=infos.baseaddress + infos.currentactivepage * infos.pagesize+dst; u32 realdst=infos.baseaddress + infos.currentactivepage * infos.pagesize+dst;
switch (realsize) switch (realsize)
{ {
@ -170,11 +166,11 @@ u32 VGA_mem_to_video (void *src,u32 dst, u32 size, u8 realsize, bool increment_s
if (!increment_src) if (!increment_src)
{ {
u8 tmp=(u8) src; u8 tmp=(u8) src;
stosb(tmp,realdst,size); memset(realdst,tmp,size,2);
} }
else else
{ {
memcpy(src,realdst,size,2);
} }
break; break;
case 1: case 1:
@ -217,19 +213,44 @@ u32 VGA_mem_to_video (void *src,u32 dst, u32 size, u8 realsize, bool increment_s
/*******************************************************************************/ /*******************************************************************************/
/* Effecture un mouvement de la mémoire video (linéarisée) vers la mémoire centrale*/ /* Effecture un mouvement de la mémoire video (linéarisée) vers la mémoire centrale*/
u32 VGA_video_to_mem (u32 src,void *dst, u32 size, u8 realsize) { u32 VGA_video_to_mem (u32 src,void *dst, u32 size)
{
u32 realsrc=infos.baseaddress + infos.currentactivepage * infos.pagesize+src;
switch (realsize)
{
case 0:
memcpy(realsrc,dst,size,2);
break;
case 1:
break;
case 2:
break;
case 4:
break;
case 8:
break;
case 9:
break;
}
} }
/*******************************************************************************/ /*******************************************************************************/
/* Effecture un mouvement de la mémoire video (linéarisé) vers la mémoire vidéo (linéarisée) */ /* Effecture un mouvement de la mémoire video (linéarisé) vers la mémoire vidéo (linéarisée) */
u32 VGA_video_to_video (u32 src,u32 dst, u32 size, u8 realsize) u32 VGA_video_to_video (u32 src,u32 dst, u32 size)
{ {
u32 base=infos.baseaddress + infos.currentactivepage * infos.pagesize; u32 base=infos.baseaddress + infos.currentactivepage * infos.pagesize;
u32 realsrc=base+src; u32 realsrc=base+src;
u32 realdst=base+dst; u32 realdst=base+dst;
switch (realsize) switch (realsize)
{ {
case 8:
case 0: case 0:
if (size%4 == 0) if (size%4 == 0)
{ {
@ -252,8 +273,6 @@ u32 VGA_video_to_video (u32 src,u32 dst, u32 size, u8 realsize)
break; break;
case 4: case 4:
break;
case 8:
break; break;
case 9: case 9:

View File

@ -2,22 +2,25 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "vga.h" #include "vga.h"
#include "asm.h"
#include "video.h" #include "video.h"
#include "stdarg.h" #include "stdarg.h"
#include "VGA/8x8fnt.c"
#include "VGA/8x16fnt.c"
static drivers registred[maxdrivers]; static drivers registred[maxdrivers];
static videoinfos *vinfo; static videoinfos *vinfo;
static console vc[8] = { static console vc[8] = {
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} , {0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
{0x00, 0, 0, 0, 0, 0, 0, 0, true} {0x07, 0, 0, 0, 0, 0, 0, 0, true}
}; };
static u8 usedvc = 0; static u8 usedvc = 0;
@ -195,6 +198,10 @@ void changemode(u8 mode)
{ {
setvideo_mode(mode); setvideo_mode(mode);
vinfo=getvideo_info(); vinfo=getvideo_info();
if (!vinfo->isgraphic) {
font_load(font8x8, 8, 1);
font_load(font8x16, 16, 0);
}
} }
/*******************************************************************************/ /*******************************************************************************/
@ -937,6 +944,7 @@ void apply_nextvideomode(void) {
/*******************************************************************************/ /*******************************************************************************/
/* Initialise la video */ /* Initialise la video */
void initvideo(void) void initvideo(void)
{ {
initdriver(); initdriver();
@ -945,24 +953,29 @@ void initvideo(void)
changemode(0x1); changemode(0x1);
} }
/*******************************/ /******************************************************************************/
/* Rempli l'écran avec un attribut donné et des espaces vides */
static u8 space=' '; static u8 space=' ';
void fill(u8 attrib) void fill(u8 attrib)
{ {
mem_to_video(space ,0,vinfo->pagesize, 0, false); mem_to_video(space ,0,vinfo->pagesize>>1, false);
mem_to_video(attrib,1,vinfo->pagesize, 0, false); mem_to_video(attrib,1,vinfo->pagesize>>1, false);
} }
/******************************************************************************/
/* Défile l'écran de N ligne si le scrolling est activé */
void scroll (u8 lines, u8 attrib) void scroll (u8 lines, u8 attrib)
{ {
if (vc[usedvc].scroll) { if (vc[usedvc].scroll) {
if (!vinfo->isgraphic) if (!vinfo->isgraphic)
{ {
u32 gain=vinfo->currentpitch*lines; u32 gain=vinfo->currentpitch*lines;
video_to_video(gain,0,vinfo->pagesize-gain, 0); video_to_video(gain,0,vinfo->pagesize-gain);
mem_to_video(space ,vinfo->pagesize-gain-2,gain, 0, false); mem_to_video(space ,vinfo->pagesize-gain-2,gain, false);
mem_to_video(attrib,vinfo->pagesize-gain-1,gain, 0, false); mem_to_video(attrib,vinfo->pagesize-gain-1,gain, false);
} }
} }
else else
@ -971,32 +984,98 @@ void scroll (u8 lines, u8 attrib)
} }
} }
/******************************************************************************/
/* Active le scrolling */
void scroll_enable(void) void scroll_enable(void)
{ {
vc[usedvc].scroll=true; vc[usedvc].scroll=true;
} }
/******************************************************************************/
/* Désactive le scrolling */
void scroll_disable(void) void scroll_disable(void)
{ {
vc[usedvc].scroll=false; vc[usedvc].scroll=false;
} }
/******************************************************************************/
/* Affiche un caractère */
void showchar(u16 coordx, u16 coordy, u8 thechar, u8 attrib) void showchar(u16 coordx, u16 coordy, u8 thechar, u8 attrib)
{ {
if (!vinfo->isgraphic) if (!vinfo->isgraphic)
{ {
u32 addr=(coordx<<1)+vinfo->currentpitch*coordy; u32 addr=(coordx<<1)+vinfo->currentpitch*coordy;
mem_to_video(thechar,addr , 1, 0, false); mem_to_video(thechar,addr , 1, false);
mem_to_video(attrib, addr+1, 1, 0, false); mem_to_video(attrib, addr+1, 1, false);
}
else
{
u8 x, y, pattern, set;
for (y = 0; y < 8; y++)
{
pattern = font8x8[thechar<<3 + y];
for (x = 0; x < 8; x++) {
rol(pattern);
//set = ((pattern >> (7 - x)) & 0x1);
if (pattern & 0x1 == 0)
writepxl(coordx << 3 + x, coordy << 3 + y, ((attrib & 0xF0) >> 8) * set);
else
writepxl(coordx << 3 + x, coordy << 3 + y, (attrib & 0x0F) * set);
} }
} }
}
}
/******************************************************************************/
/* Retourne le caractère du mode texte aux coordonnées spécifiées */
u8 getchar (u16 coordx, u16 coordy) u8 getchar (u16 coordx, u16 coordy)
{ {
u8 thechar=0;
if (!vinfo->isgraphic)
{
u32 addr=(coordx<<1)+vinfo->currentpitch*coordy;
video_to_mem(addr,&thechar,1);
} }
return thechar;
}
/******************************************************************************/
/* Retourne l'attribut du mode texte aux coordonnées spécifiées */
u8 getattrib (u16 coordx, u16 coordy) u8 getattrib (u16 coordx, u16 coordy)
{ {
u8 attrib=0;
if (!vinfo->isgraphic)
{
u32 addr=(coordx<<1)+vinfo->currentpitch*coordy;
video_to_mem(addr+1,&attrib,1);
} }
return attrib;
}
/******************************************************************************/
/* Affiche une ligne horizontale entre les points spécifiés */
void hline(u32 x1, u32 x2, u32 y, u8 color)
{
if (x2 > x1)
mem_to_video(color,x1,x2-x1,false);
else
mem_to_video(color,x2,x2-x1,false);
}
/******************************************************************************/
/* Affiche un pixel à l'écran */
void writepxl (u16 x, u16 y, u32 color)
{
u32 addr=x+vinfo->currentheight*y;
mem_to_video(color,addr,1,false);
}