fix: ajout detection PCI & correction video.c : fonction line & hline

This commit is contained in:
Nicolas Hordé 2018-11-08 22:12:51 +01:00
parent 35ae3559db
commit 42f87229ad
8 changed files with 182 additions and 18 deletions

View File

@ -166,14 +166,14 @@
u16 _v; \ u16 _v; \
asm volatile ("inw %%dx,%%ax" : "=a" (_v) : "d"(port)); \ asm volatile ("inw %%dx,%%ax" : "=a" (_v) : "d"(port)); \
_v; \ _v; \
} })
#define ind(port) ({ \ #define ind(port) ({ \
u32 _v; \ u32 _v; \
asm volatile ("inl %%dx,%%eax" : "=a" (_v) : "d"(port)); \ asm volatile ("inl %%dx,%%eax" : "=a" (_v) : "d"(port)); \
_v; \ _v; \
} })
/******************************************************************************/ /******************************************************************************/

14
include/pci.h Executable file
View File

@ -0,0 +1,14 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
typedef struct pcidev {
union {
struct {
u16 vendor;
u16 device;
};
u32 dword;
};
} pcidev __attribute__ ((packed));

View File

@ -27,3 +27,4 @@ int bpclr(u8* commandline);
int sfont(u8* commandline); int sfont(u8* commandline);
int help(); int help();
int logo(); int logo();
int detectpci();

View File

@ -11,8 +11,8 @@
#define MAXFONTS 10 #define MAXFONTS 10
typedef struct vertex2d{ typedef struct vertex2d{
u16 x; s16 x;
u16 y; s16 y;
} vertex2d __attribute__ ((packed)); } vertex2d __attribute__ ((packed));
typedef struct rgbcolor { typedef struct rgbcolor {
@ -107,9 +107,9 @@ 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 v_writepxl (vertex2d *A, u32 color); void v_writepxl (vertex2d *A, u32 color);
void writepxl (u16 x, u16 y, u32 color); void writepxl (s16 x, s16 y, u32 color);
void line(u32 x1, u32 y1, u32 x2, u32 y2, u32 color); void line(s16 x1, s16 y1, s16 x2, s16 y2, u32 color);
void hline(u16 x1, u16 x2, u16 y, u32 color); void hline(s16 x1, s16 x2, s16 y, u32 color);
void changemode(u8 mode); void changemode(u8 mode);
u32 egatorgb(u8 ega); u32 egatorgb(u8 ega);
u8 egatovga(u8 ega); u8 egatovga(u8 ega);

View File

@ -74,8 +74,8 @@ void cube(model3d *model, vector4 *origin, u16 size)
model->facelist[4].V2=1; model->facelist[4].V2=1;
model->facelist[4].V3=5; model->facelist[4].V3=5;
model->facelist[5].V1=0; model->facelist[5].V1=0;
model->facelist[5].V2=4; model->facelist[5].V2=1;
model->facelist[5].V3=5; model->facelist[5].V3=4;
model->facelist[6].V1=0; model->facelist[6].V1=0;
model->facelist[6].V2=0; model->facelist[6].V2=0;
model->facelist[6].V3=0; model->facelist[6].V3=0;

53
lib/pci.c Executable file
View File

@ -0,0 +1,53 @@
/*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */
#include "asm.h"
#include "types.h"
#include "pci.h"
#define MAX_BUS_SCAN 256
#define MAX_DEVICE_SCAN 32
#define MAX_FUNCTION_SCAN 8
/*******************************************************************************/
/* Detecte s */
pcidev getPCIinfo(const u8 bus, const u8 dev, const u8 function)
{
pcidev result;
const u32 registry = 0;
u32 addr = (0x80000000|(bus << 16)|(dev << 11)|(function << 8)|(registry & 0xFC));
outd(0xCF8, addr);
result.dword = ind(0xCFC);
if (result.dword == 0xFFFFFFFF)
result.dword = 0x0;
return result;
}
/*******************************************************************************/
/* Scan le bus PCI et affiche les périphériques */
void scanPCI(void)
{
u32 i, bus, device, function;
pcidev result;
i = 0;
for (bus=0; bus<MAX_BUS_SCAN; ++bus)
for (device=0; device<MAX_DEVICE_SCAN; ++device)
for (function=0; function<MAX_FUNCTION_SCAN; ++function)
{
result = getPCIinfo(bus, device, function);
if (result.dword)
printf("%d) Bus: 0x%x, Device: 0x%x. Function: 0x%x (0x%hx:0x%hx)\r\n",
++i, bus, device, function, result.vendor, result.device);
}
return;
}
/*******************************************************************************/

View File

@ -38,6 +38,7 @@ static command commands[] = {
{"logo" , "", &logo}, {"logo" , "", &logo},
{"font" , "", &sfont}, {"font" , "", &sfont},
{"test3d" , "", &test3d}, {"test3d" , "", &test3d},
{"detectpci" , "", &detectpci},
}; };
/*******************************************************************************/ /*******************************************************************************/
@ -77,6 +78,12 @@ int test(void)
return; return;
} }
/*******************************************************************************/
/* Affiche les périphériques PCI */
int detectpci()
{
scanPCI();
}
/*******************************************************************************/ /*******************************************************************************/
/* Change la police courante */ /* Change la police courante */
@ -429,6 +436,8 @@ int test3d()
print("Mode graphique necessaire afin de lancer ce programme\r\n"); print("Mode graphique necessaire afin de lancer ce programme\r\n");
return 1; return 1;
} }
line(-100,-50,1800,200,egatorgb(4));
waitascii();
model3d model; model3d model;
float factor=100.0f; float factor=100.0f;
type3D type=TYPE3D_POINTS; type3D type=TYPE3D_POINTS;

View File

@ -660,11 +660,29 @@ void showchar(u16 coordx, u16 coordy, u8 thechar, u8 attrib)
/******************************************************************************/ /******************************************************************************/
/* Affiche une ligne horizontale entre les points spécifiés */ /* Affiche une ligne horizontale entre les points spécifiés */
void hline(u16 x1, u16 x2, u16 y, u32 color) void hline(s16 x1, s16 x2, s16 y, u32 color)
{ {
if (vinfo->isgraphic) if (vinfo->isgraphic)
{ {
if (x2 > x1) if (x1<0)
{
if (x2<0)
return;
x1=0;
}
else if (x1>vinfo->currentwidth)
x1=vinfo->currentwidth-1;
if (x2<0)
x2=0;
else if (x2>vinfo->currentwidth)
{
if (x1>vinfo->currentwidth)
return;
x2=vinfo->currentwidth-1;
}
if (x1>vinfo->currentwidth)
x1=vinfo->currentwidth-1;
if (x2 > x1)
mem_to_video(color,(vinfo->currentdepth>>3)*x1+vinfo->currentpitch*y,x2-x1,false); mem_to_video(color,(vinfo->currentdepth>>3)*x1+vinfo->currentpitch*y,x2-x1,false);
else else
mem_to_video(color,(vinfo->currentdepth>>3)*x2+vinfo->currentpitch*y,x1-x2,false); mem_to_video(color,(vinfo->currentdepth>>3)*x2+vinfo->currentpitch*y,x1-x2,false);
@ -680,12 +698,15 @@ void v_writepxl(vertex2d *A, u32 color)
writepxl(A->x, A->y, color); writepxl(A->x, A->y, color);
} }
void writepxl(u16 x, u16 y, u32 color) void writepxl(s16 x, s16 y, u32 color)
{ {
if (vinfo->isgraphic) if (vinfo->isgraphic)
{ {
u32 addr=(vinfo->currentdepth>>3)*x+vinfo->currentpitch*y; if (x>0 && y>0 && x<vinfo->currentwidth && y<vinfo->currentheight)
mem_to_video(color,addr,1,false); {
u32 addr=(vinfo->currentdepth>>3)*x+vinfo->currentpitch*y;
mem_to_video(color,addr,1,false);
}
} }
} }
@ -697,13 +718,79 @@ void v_line(vertex2d *A, vertex2d *B, u32 color)
line(A->x, A->y, B->x, B->y, color); line(A->x, A->y, B->x, B->y, color);
} }
void line(u32 x1, u32 y1, u32 x2, u32 y2, u32 color) void line(s16 x1, s16 y1, s16 x2, s16 y2, u32 color)
{ {
s32 dx, dy, sdx, sdy; s16 dx, dy, sdx, sdy;
u32 i, dxabs, dyabs, x, y, px, py; float a, b;
s16 i, dxabs, dyabs, x, y, px, py;
dx = x2 - x1; /* distance horizontale de la line */ dx = x2 - x1; /* distance horizontale de la line */
dy = y2 - y1; /* distance verticale de la line * */ dy = y2 - y1; /* distance verticale de la line */
if (x1<0)
{
a = 1.0f * dy / dx;
b = y1 - a*x1;
x1 = 0;
y1 = b;
if (x2<0)
return;
}
else if (x2<0)
{
a = 1.0f * dy / dx;
b = y2 - a*x2;
x2 = 0;
y2 = b;
}
if (y1<0)
{
a = 1.0f * dy / dx;
b = y1 - a*x1;
y1 = 0;
x1 = - b / a;
if (y2<0)
return;
}
else if (y2<0)
{
a = 1.0f * dy / dx;
b = y2 - a*x2;
y2 = 0;
x2 = - b / a;
}
if (x1>vinfo->currentwidth)
{
a = 1.0f * dy / dx;
b = y1 - a*x1;
x1 = vinfo->currentwidth-1;
y1 = a*x1+b;
if (x2>vinfo->currentwidth)
return;
}
else if (x2>vinfo->currentwidth)
{
a = 1.0f * dy / dx;
b = y2 - a*x2;
x2 = vinfo->currentwidth-1;
y2 = a*x2+b;
}
if (y1>vinfo->currentheight)
{
a = 1.0f * dy / dx;
b = y1 - a*x1;
y1 = vinfo->currentheight-1;
x1 = (y1 - b) / a;
if (y2>vinfo->currentheight)
return;
}
else if (y2>vinfo->currentheight)
{
a = 1.0f * dy / dx;
b = y2 - a*x2;
y2 = vinfo->currentheight-1;
x2 = (y2 - b) / a;
}
dxabs = abs(dx); dxabs = abs(dx);
dyabs = abs(dy); dyabs = abs(dy);
sdx = sgn(dx); sdx = sgn(dx);