feat: ajout de nombreuses fonctionnalité pour l'affichage en mode texte

This commit is contained in:
Nicolas Hordé 2007-04-02 13:01:09 +00:00
parent e129e59eeb
commit 7349aa3ebb
1 changed files with 126 additions and 58 deletions

View File

@ -1,9 +1,10 @@
#include "vga.h" #include "vga.h"
#include "string.h" #include "memory.h"
#include "port.h"
#include "asm.h" #include "asm.h"
#include "modes.c" #include "modes.c"
#include "8x8fnt.c" #include "fonts.c"
#define sequencer 0x3c4 #define sequencer 0x3c4
#define misc 0x3c2 #define misc 0x3c2
@ -12,77 +13,144 @@
#define graphics 0x3ce #define graphics 0x3ce
#define state 0x3da #define state 0x3da
static u16 resX,resY,cursX,cursY; /* resolution x,y en caractères et position du curseur */ static u16 resX,resY,cursX,cursY; /* resolution x,y en caractères et position du curseur */
static u16 pages,pagesize,activepage; /* nombre de pages disponibles et taille d'une page */ static u16 pages,pagesize,activepage,showedpage;/* nombre de pages disponibles et taille d'une page ansi que la page active et affiché en cours*/
static u8 vmode; /* mode en cours d'utilisation */ static u8 vmode=0xFF; /* mode en cours d'utilisation */
static u16 basemem; /* debut de la mémoire vidéo */ static u32 basemem; /* debut de la mémoire vidéo */
static bool scrolling,graphic; /* Activation du défilement, Flag du mode graphique */ static bool scrolling,graphic; /* Activation du défilement, Flag du mode graphique */
static u8 font; /* n° font actuelle */
void showchar (u8 thechar)
void print (u8* string)
{ {
u8 *source,*screen; u8 *screen;
source = string; screen = (u8 *)basemem+activepage*pagesize+2*(cursX+cursY*resX);
screen = (u8 *)TEXTSCREEN; *screen = thechar;
while(*source!=0x00) *(++screen) = 0x07;
if (cursX++>=resX)
{ {
*screen = *source; cursX=0;
screen+=2; cursY++;
source++;
} }
gotoscreen(cursX,cursY);
} }
void cls (void) void print (char* string)
{ {
memset((u8 *)TEXTSCREEN,0x20,(80*25*2),2); u8 *source;
source = string;
while(*source!=0x00) showchar (*source++);
} }
void showhex (u8 src)
{
static u8 hexadigit[16] = "0123456789ABCDEF";
showchar(hexadigit[(src&0xF0)>>4]);
showchar(hexadigit[src&0x0F]);
}
void clearscreen (void)
{
gotoscreen(0,0);
memset((u8 *)(basemem+activepage*pagesize),0,2*(resY*resX),1);
}
void gotoscreen(u16 x,u16 y)
{
u16 pos;
pos=(cursX+cursY*resX)/2;
cursX=x;
cursY=y;
outb(ccrt,0x0E);
outb(ccrt+1,(u8)(pos&0x00FF));
outb(ccrt,0x0D);
outb(ccrt+1,(u8)((pos&0xFF00)>>8));
}
void fillscreen (u8 color)
{
memset((u8 *)(basemem+activepage*pagesize+1),color,resY*resX,2);
}
void loadfont(u8 num,u8 *font,u8 size)
{
u16 seqinit[4] = { 0x0100, 0x0402, 0x0704, 0x0300 },
graphinit[3] = { 0x0204, 0x0005, 0x0006 },
seqend [4] = { 0x0100, 0x0302, 0x0304, 0x0300 },
graphend[3] = { 0x0004, 0x1005, 0x0E06 };
u8 *dest,*src;
u8 i;
dest=(u8 *)GRPHSCREEN;
src=font;
initreg(sequencer,(u8 *)seqinit ,4);
initreg(graphics ,(u8 *)graphinit,3);
if (num>3)
dest+= (((num-4)<<1)+1)<<13;
else
dest+=num<<14;
for(i=0;i<250;i++)
{
memcpy(dest,src,size);
src+=size;
dest+=size;
memset(dest,0,(32-size),1);
dest+=(32-size);
}
initreg(sequencer,(u8 *)seqend ,4);
initreg(graphics ,(u8 *)graphend,3);
}
u8 getfont(u8 num)
{
return font;
}
void setfont(u8 num)
{
font=num&0x07;
outb(sequencer,3);
outb(sequencer+1,num&0x03+(num&(0x04)<<2));
}
u16 setvmode(u8 choosedmode) u16 setvmode(u8 choosedmode)
{ {
u8 *def,i,mode; u8 *def,mode;
mode=(choosedmode&0x7F);
mode=choosedmode&0x7F; if (vmode==0xFF)
{
loadfont(1 ,(u8 *)font8x8, 8);
}
if (choosedmode>0x7F) if (choosedmode>0x7F)
{ {
if (mode>maxgraphmode) return 1; /* mode inexistant */ if (mode>=maxgraphmode) return 1; /* mode inexistant */
def=(u8 *)&graphmodes[mode]; def=(u8 *)&graphmodes[mode];
graphic=true; graphic=true;
} }
else else
{ {
if (mode>maxtextmode) return 1; /* mode inexistant */ if (mode>=maxtextmode) return 1; /* mode inexistant */
def=(u8 *)&textmodes[mode]; def=(u8 *)&textmodes[mode];
graphic=false; graphic=false;
} }
outb(misc,*def++); outb(misc,def[0]);
outb(state,*def++); outb(state,def[1]);
for(i=0;i<5;i++) outreg(sequencer,&def[2],5);
{
outb(sequencer,i);
outb(sequencer+1,*def++);
}
outb(ccrt,0x11); outb(ccrt,0x11);
outb(ccrt+1,0x0E); outb(ccrt+1,0x0E);
for(i=0;i<25;i++) outreg(ccrt,&def[7],25);
{ outreg(graphics,&def[32],9);
outb(ccrt,i);
outb(ccrt+1,*def++);
}
for(i=0;i<9;i++)
{
outb(graphics,i);
outb(graphics+1,*def++);
}
inb(state);
for(i=0;i<21;i++)
{
inb(attribs);
outb(attribs,i);
outb(attribs,*def++);
}
inb(state); inb(state);
outregsame(attribs,&def[41],21);
outb(attribs,0x20); outb(attribs,0x20);
resX=def[63];
resY=def[64];
cursX=0;
cursY=0;
pagesize=2*resX*resY;
activepage=0;
vmode=mode;
pages=32768/pagesize;
basemem=(def[21]<<8)+def[22]+TEXTSCREEN;
return 0; return 0;
} }