feat: pilote remanié VGA ok en mode texte
This commit is contained in:
parent
016b972d97
commit
605953aa3b
|
@ -8,8 +8,6 @@ typedef struct vertex2d{
|
|||
u32 y;
|
||||
} 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 hline(u32 x1, u32 x2, u32 y, u8 color);
|
||||
void trianglefilled(vertex2d *A, vertex2d *B, vertex2d *C, u8 color);
|
||||
|
|
|
@ -122,6 +122,29 @@
|
|||
|
||||
#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) \
|
||||
|
|
|
@ -7,24 +7,6 @@
|
|||
#define TEXTSCREEN 0xB8000 /* debut de la memoire video texte*/
|
||||
#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 */
|
||||
|
||||
|
@ -116,9 +98,9 @@ u8 VGA_setvideo_mode (u8 mode);
|
|||
u8 *VGA_getvideo_drivername (void);
|
||||
u8 *VGA_getvideo_capabilities (void);
|
||||
videoinfos *VGA_getvideo_info (void);
|
||||
u32 VGA_mem_to_video (void *src,u32 dst, u32 size, u8 realsize, bool increment_src);
|
||||
u32 VGA_video_to_mem (u32 src,void *dst, u32 size, u8 realsize);
|
||||
u32 VGA_video_to_video (u32 src,u32 dst, u32 size, u8 realsize);
|
||||
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);
|
||||
u32 VGA_video_to_video (u32 src,u32 dst, u32 size);
|
||||
void VGA_wait_vretrace (void);
|
||||
void VGA_wait_hretrace (void);
|
||||
void VGA_page_set (u8 page);
|
||||
|
|
|
@ -88,6 +88,8 @@ void scroll_disable(void);
|
|||
void showchar (u16 coordx, u16 coordy, u8 thechar, u8 attrib);
|
||||
u8 getchar (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 */
|
||||
void changevc(u8 vc);
|
||||
|
@ -124,9 +126,9 @@ 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, u8 realsize, bool increment_src);
|
||||
u32 (*video_to_mem) (u32 src,void *dst, u32 size, u8 realsize);
|
||||
u32 (*video_to_video) (u32 src,u32 dst, u32 size, u8 realsize);
|
||||
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);
|
||||
|
|
18
lib/2d.c
18
lib/2d.c
|
@ -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 */
|
||||
|
||||
|
@ -152,9 +139,4 @@ void triangle(vertex2d * AA, vertex2d * BB, vertex2d * CC, u8 color)
|
|||
line(CC->x, CC->y, AA->x, AA->y, color);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Affiche un pixel à l'écran */
|
||||
void writepxl (u16 x, u16 y, u32 c)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ static vgamode modes[] = {
|
|||
|
||||
/*80*25 16 couleurs mode 0x00 */
|
||||
{{0x67},
|
||||
{0x03, 0x00, 0x03, 0x00, 0x06},
|
||||
{0x03, 0x00, 0x03, 0x00, 0x02},
|
||||
{0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00,
|
||||
0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00,
|
||||
0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF},
|
||||
|
|
34
lib/memory.c
34
lib/memory.c
|
@ -36,10 +36,11 @@ void initpaging(void)
|
|||
|
||||
void memset(void *dst, u8 val, u32 count, u32 size)
|
||||
{
|
||||
u8 * temp;
|
||||
for (temp = (u8 *) dst; count != 0; count--) {
|
||||
temp += size;
|
||||
*temp = val;
|
||||
u8 *d = (u8 *) dst;
|
||||
if (size>0) size--;
|
||||
for (; count != 0; count--) {
|
||||
*(d++) = val;
|
||||
d+=size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,12 +49,12 @@ temp += size;
|
|||
|
||||
void memcpy(void *src, void *dst, u32 count, u32 size)
|
||||
{
|
||||
char *s, *d;
|
||||
u32 i;
|
||||
s = (u8 *) src;
|
||||
d = (u8 *) dst;
|
||||
for (i = 0; i < count; i++) {
|
||||
*(d + i * size) = *(s + i);
|
||||
u8 *s = (u8 *) src;
|
||||
u8 *d = (u8 *) dst;
|
||||
if (size>0) size--;
|
||||
for (; count != 0; count--) {
|
||||
*(d++) = *(s++);
|
||||
d+=size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,13 +63,14 @@ for (i = 0; i < count; i++) {
|
|||
|
||||
u32 memcmp(void *src, void *dst, u32 count, u32 size)
|
||||
{
|
||||
const u8 *mem1 = (const u8 *)src;
|
||||
const u8 *mem2 = (const u8 *)dst;
|
||||
u8 *s = (u8 *) src;
|
||||
u8 *d = (u8 *) dst;
|
||||
if (size>0) size--;
|
||||
for (; count != 0; count--) {
|
||||
if (*mem1 != *mem2)
|
||||
return *mem1 - *mem2;
|
||||
mem1 += size;
|
||||
mem2 += size;
|
||||
if (*(s++) != *(d++))
|
||||
return *d - *s;
|
||||
s+= size;
|
||||
d+= size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
41
lib/vga.c
41
lib/vga.c
|
@ -7,8 +7,6 @@
|
|||
#include "asm.h"
|
||||
#include "types.h"
|
||||
#include "VGA/modes.c"
|
||||
#include "VGA/8x8fnt.c"
|
||||
#include "VGA/8x16fnt.c"
|
||||
|
||||
static videoinfos infos;
|
||||
|
||||
|
@ -110,8 +108,6 @@ u8 VGA_setvideo_mode(u8 mode)
|
|||
infos.pagesize = ((infos.currentheight * infos.currentpitch) << 3);
|
||||
}
|
||||
else {
|
||||
VGA_font_load(font8x8, 8, 1);
|
||||
VGA_font_load(font8x16, 16, 0);
|
||||
infos.currentpitch= infos.currentwidth * 2;
|
||||
infos.pagesize=infos.currentheight * infos.currentpitch;
|
||||
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) */
|
||||
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;
|
||||
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)
|
||||
{
|
||||
u8 tmp=(u8) src;
|
||||
stosb(tmp,realdst,size);
|
||||
memset(realdst,tmp,size,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
memcpy(src,realdst,size,2);
|
||||
}
|
||||
break;
|
||||
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*/
|
||||
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) */
|
||||
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 realsrc=base+src;
|
||||
u32 realdst=base+dst;
|
||||
switch (realsize)
|
||||
{
|
||||
case 8:
|
||||
case 0:
|
||||
if (size%4 == 0)
|
||||
{
|
||||
|
@ -252,8 +273,6 @@ u32 VGA_video_to_video (u32 src,u32 dst, u32 size, u8 realsize)
|
|||
break;
|
||||
case 4:
|
||||
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
|
||||
|
|
115
lib/video.c
115
lib/video.c
|
@ -2,22 +2,25 @@
|
|||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
#include "vga.h"
|
||||
#include "asm.h"
|
||||
#include "video.h"
|
||||
#include "stdarg.h"
|
||||
#include "VGA/8x8fnt.c"
|
||||
#include "VGA/8x16fnt.c"
|
||||
|
||||
static drivers registred[maxdrivers];
|
||||
|
||||
static videoinfos *vinfo;
|
||||
|
||||
static console vc[8] = {
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x00, 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} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true} ,
|
||||
{0x07, 0, 0, 0, 0, 0, 0, 0, true}
|
||||
};
|
||||
|
||||
static u8 usedvc = 0;
|
||||
|
@ -195,6 +198,10 @@ void changemode(u8 mode)
|
|||
{
|
||||
setvideo_mode(mode);
|
||||
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 */
|
||||
|
||||
void initvideo(void)
|
||||
{
|
||||
initdriver();
|
||||
|
@ -945,24 +953,29 @@ void initvideo(void)
|
|||
changemode(0x1);
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
/******************************************************************************/
|
||||
/* Rempli l'écran avec un attribut donné et des espaces vides */
|
||||
|
||||
static u8 space=' ';
|
||||
|
||||
void fill(u8 attrib)
|
||||
{
|
||||
mem_to_video(space ,0,vinfo->pagesize, 0, false);
|
||||
mem_to_video(attrib,1,vinfo->pagesize, 0, false);
|
||||
mem_to_video(space ,0,vinfo->pagesize>>1, 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)
|
||||
{
|
||||
if (vc[usedvc].scroll) {
|
||||
if (!vinfo->isgraphic)
|
||||
{
|
||||
u32 gain=vinfo->currentpitch*lines;
|
||||
video_to_video(gain,0,vinfo->pagesize-gain, 0);
|
||||
mem_to_video(space ,vinfo->pagesize-gain-2,gain, 0, false);
|
||||
mem_to_video(attrib,vinfo->pagesize-gain-1,gain, 0, false);
|
||||
video_to_video(gain,0,vinfo->pagesize-gain);
|
||||
mem_to_video(space ,vinfo->pagesize-gain-2,gain, false);
|
||||
mem_to_video(attrib,vinfo->pagesize-gain-1,gain, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -971,32 +984,98 @@ void scroll (u8 lines, u8 attrib)
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Active le scrolling */
|
||||
|
||||
void scroll_enable(void)
|
||||
{
|
||||
vc[usedvc].scroll=true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Désactive le scrolling */
|
||||
|
||||
void scroll_disable(void)
|
||||
{
|
||||
vc[usedvc].scroll=false;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Affiche un caractère */
|
||||
|
||||
void showchar(u16 coordx, u16 coordy, u8 thechar, u8 attrib)
|
||||
{
|
||||
if (!vinfo->isgraphic)
|
||||
{
|
||||
u32 addr=(coordx<<1)+vinfo->currentpitch*coordy;
|
||||
mem_to_video(thechar,addr , 1, 0, false);
|
||||
mem_to_video(attrib, addr+1, 1, 0, false);
|
||||
mem_to_video(thechar,addr , 1, 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 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 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue