From 86c4e4550e5dffa0644c99bd53fb225853aa7d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Fri, 12 Oct 2018 20:37:26 +0200 Subject: [PATCH] feat: ajout d'une gestion de pilotes video dans la projection de faire un pilote VBE/VESA --- include/2d.h | 2 +- include/vga.h | 140 ++++++--- include/video.h | 122 +++++++- lib/VGA/modes.c | 278 ++++++----------- lib/interrupts.c | 2 +- lib/keyboard.c | 2 +- lib/vga.c | 725 ++++++++++++++----------------------------- lib/video.c | 152 +++++++++ system/multiboot.asm | 2 +- system/system.c | 5 +- 10 files changed, 694 insertions(+), 736 deletions(-) diff --git a/include/2d.h b/include/2d.h index 2d04380..984a3de 100755 --- a/include/2d.h +++ b/include/2d.h @@ -8,7 +8,7 @@ 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); diff --git a/include/vga.h b/include/vga.h index 7c496cd..f67c3a6 100755 --- a/include/vga.h +++ b/include/vga.h @@ -6,41 +6,109 @@ #define TEXTSCREEN 0xB8000 /* debut de la memoire video texte*/ #define GRPHSCREEN 0xA0000 /* debut de la memoire video graphique*/ -typedef u8 mode_def[64]; +/* Registres VGAs */ +#define sequencer 0x3c4 +#define misc_write 0x3c2 +#define misc_read 0x3cc +#define ccrt 0x3D4 +#define attribs 0x3c0 +#define graphics 0x3ce +#define state 0x3da -u32 setvmode(u8); -u32 loadfont(u8* def,u8 size,u8 font); -void gotoscr(u16 x,u16 y); -void useplane(u8 plan); -u8 getfont(void); -void setfont(u8 num); -void waitvretrace(void); -void waithretrace(void); -void enablecursor(void); -void disablecursor(void); -void enablescroll(void); -void disablescroll(void); -void (*writepxl)(u16 x, u16 y, u32 c); -void (*showchar)(u16 coordx,u16 coordy,u8 thechar,u8 attrib); -void (*fill)(u8 attrib); -void (*scroll)(u8 lines,u8 attrib); -void split(u16 x); -void showpage(u8 page); -u8 getpage(); -void setpage(u8 page); -u16 getnbpages(void); -u16 getyres(void); -u8 getdepth(void); -u16 getxres(void); -u8 getfont2(void); -void enableblink(void); -void disableblink(void); -u8 (*getchar)(u16 coordx,u16 coordy); -u8 (*getattrib)(u16 coordx,u16 coordy); -void outreg(u16 port,u8 *src,u16 num); -void outregsame(u16 port,u8 *src,u16 num); -void inreg(u16 port,u8 *src,u16 num); -void inregsame(u16 port,u8 *src,u16 num); -u8 nextvmode(void); -u8 getvmode(void); +/* Taille d'un plan de bit */ + +#define planesize 0x10000 + +/* Registres VGA */ +typedef struct misc_regs { + u8 Miscellaneous_Output_Register; +} misc_reg __attribute__ ((packed)); + +typedef struct sequencer_regs { + u8 Reset_Register; + u8 Clocking_Mode_Register; + u8 Map_Mask_Register; + u8 Character_Map_Select_Register; + u8 Sequencer_Memory_Mode_Register; +} sequencer_reg __attribute__ ((packed)); + +typedef struct crtc_regs { + u8 Horizontal_Total_Register; + u8 End_Horizontal_Display_Register; + u8 Start_Horizontal_Blanking_Register; + u8 End_Horizontal_Blanking_Register; + u8 Start_Horizontal_Retrace_Register; + u8 End_Horizontal_Retrace_Register; + u8 Vertical_Total_Register; + u8 Overflow_Register; + u8 Preset_Row_Scan_Register; + u8 Maximum_Scan_Line_Register; + u8 Cursor_Start_Register; + u8 Cursor_End_Register; + u8 Start_Address_High_Register; + u8 Start_Address_Low_Register; + u8 Cursor_Location_High_Register; + u8 Cursor_Location_Low_Register; + u8 Vertical_Retrace_Start_Register; + u8 Vertical_Retrace_End_Register; + u8 Vertical_Display_End_Register; + u8 Offset_Register; + u8 Underline_Location_Register; + u8 Start_Vertical_Blanking_Register; + u8 End_Vertical_Blanking; + u8 CRTC_Mode_Control_Register; + u8 Line_Compare_Register; +} crtc_regs __attribute__ ((packed)); + +typedef struct graphics_regs { + u8 Set_Reset_Register; + u8 Enable_Set_Reset_Register; + u8 Color_Compare_Register; + u8 Data_Rotate_Register; + u8 Read_Map_Select_Register; + u8 Graphics_Mode_Register; + u8 Miscellaneous_Graphics_Register; + u8 Color_Dont_Care_Register; + u8 Bit_Mask_Register; +} graphics_regs __attribute__ ((packed)); + +typedef struct attributs_regs { + u8 Palette Registers[16]; + u8 Attribute_Mode_Control_Register; + u8 Overscan_Color_Register; + u8 Color_Plane_Enable_Register; + u8 Horizontal_Pixel_Panning_Register; + u8 Color_Select_Register; +} attributs_regs __attribute__ ((packed)); + +typedef struct vgamode { + misc_regs misc; + sequencer_regs sequencer; + crtc_regs ctrc; + graphics_regs graphic; + attributs_regs attribut; +} vgamode __attribute__ ((packed)); + +/* fonction obligatoires */ +u8 *VGA_detect_hardware (void); +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, 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); +void VGA_page_show (u8 page); +void VGA_page_split (u16 y); +void VGA_cursor_enable (void); +void VGA_cursor_disable (void); +void VGA_cursor_set (u16 x,u16 y); +u32 VGA_font_load (u8 * def, u8 size, u8 font); +void VGA_font1_set (u8 num); +void VGA_font2_set (u8 num); +void VGA_blink_enable (void); +void VGA_blink_disable (void); diff --git a/include/video.h b/include/video.h index 36b5509..e499609 100755 --- a/include/video.h +++ b/include/video.h @@ -4,21 +4,92 @@ #include "stdarg.h" +#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 { + u8 currentmode + u16 currentwidth; + u16 currentheight; + u8 currentdepth; + u8 currentactivepage; + u8 currentshowedpage; + u16 currentcursorX; + u16 currentcursorY; + u8 currentfont1; + u8 currentfont2; + u16 currentpitch; + bool isgraphic; + bool isblinking; + bool iscursorvisible; + u8 pagesnumber; + u32 pagesize; + u32 baseaddress; +} videoinfos __attribute__ ((packed)); + typedef struct console { - u8 attrib; - s16 cursX; - s16 cursY; - u8 ansi; - u8 param1; - u8 param2; - u8 param3; - u8 page; + u8 attrib; + s16 cursX; + s16 cursY; + u8 ansi; + u8 param1; + u8 param2; + u8 param3; + u8 page; } 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)); -void showhex(u8 src); +/* Fonctions de bas niveau */ +void fill(u8 attrib); +void scroll (u8 lines, u8 attrib); +void scroll_enable(void); +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); + +/* Fonctions de console */ +void changevc(u8 vc); void putchar(u8 thechar); void clearscreen(void); + +/* Fonctions de haut niveau */ u32 print(u8* string); u32 printf (const u8 *string, ...); u32 sprintf(u8 *variable, const u8 *string, ...); @@ -26,9 +97,40 @@ u32 snprintf(u8 *variable, u32 maxsize, const u8 *string, ...); u32 vprintf(const u8 * string, va_list args); u32 vsprintf(u8 *variable, const u8 *string, va_list args); u32 vsnprintf(u8 *variable, u32 maxsize, const u8 *string, va_list args); -void changevc(u8 vc); + u8* itoa(u64 num, u8* str, u8 base, u64 dim, u8 achar); u8* sitoa(u64 num, u8 * str, u64 dim); u8* rtoadouble(double num, u8 * str, u8 precisioni , u8 precisionf); u8* rtoasingle(float num, u8 * str, u8 precisioni , u8 precisionf); u32 format(const u8 * string, va_list args, u32 maxsize, u32 (*fonction)(u8* src, u8** dest, u32 len), u8* dest); + +/* Fonction pour gérer le pilote */ +void initdriver(); +void registerdriver(videofonction *pointer); +void apply_bestdriver(void); +void apply_nextdriver(void); +void apply_driver(u8* name); +void apply_nextvideomode(void); + +/* Fonctions du pilote */ +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); diff --git a/lib/VGA/modes.c b/lib/VGA/modes.c index 64b9ffc..42d9f31 100755 --- a/lib/VGA/modes.c +++ b/lib/VGA/modes.c @@ -4,220 +4,120 @@ /* definition des registres de la carte VGA pour differents modes */ -#define maxgraphmode 11 -#define maxtextmode 5 +#define nbmodes 9 -static mode_def textmodes[maxtextmode] = { - - /*40*25 16 couleurs mode 0x00 */ - { - 0x67, - 0x03, 0x08, 0x03, 0x00, 0x02, - 0x2D, 0x27, 0x28, 0x90, 0x2B, 0xA0, 0xBF, 0x1F, 0x00, - 0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x8E, 0x8F, 0x14, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x0C, 0x00, 0x0F, 0x08, 0x00, - 45, 25, 4}, - - /*80*25 16 couleurs mode 0x01 */ - { - 0x67, - 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, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x0C, 0x00, 0x0F, 0x08, 0x00, - 80, 25, 4}, - - /*80*50 16 couleurs mode 0x02 */ - { - 0x63, - 0x03, 0x01, 0x03, 0x05, 0x02, - 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, - 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x0C, 0x00, 0x0F, 0x00, 0x00, - 80, 50, 4}, - - /*100*50 16 couleurs mode 0x03 */ - { - 0x67, - 0x03, 0x01, 0x03, 0x05, 0x02, - 0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xBF, 0x1F, 0x00, - 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x8E, 0x8F, 0x32, 0x1F, 0x96, 0xB9, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x0C, 0x00, 0x0F, 0x00, 0x00, - 100, 50, 4}, - - /*100*60 16 couleurs mode 0x04 */ - { - 0xA7, - 0x03, 0x01, 0x03, 0x05, 0x02, - 0x70, 0x63, 0x64, 0x85, 0x68, 0x84, 0xFF, 0x1F, 0x00, - 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - 0xE7, 0x8E, 0xDF, 0x32, 0x1F, 0xDF, 0xE5, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x0C, 0x00, 0x0F, 0x00, 0x00, - 100, 60, 4} +static capabilities vgacapabilities[nbmodes] = { + {0x00, 80, 25,false, 4, 0}, + {0x01, 80, 50,false, 4, 0}, + {0x80,640,480,true , 1, 0}, + {0x81,320,200,true , 2, 0}, + {0x82,640,480,true , 4, 0}, + {0x83,320,200,true , 8, 0}, + {0x84,320,400,true , 8, 0}, + {0x85,320,480,true , 8, 0}, + {0x86,360,480,true , 8, 0}, + {0xFF,000,000,false, 0, 0}, }; -static mode_def graphmodes[maxgraphmode] = { + +static vgamode modes[nbmodes] = { + + /*80*25 16 couleurs mode 0x00 */ + {{0x67}, + {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}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x08, 0x00}}, + + /*80*50 16 couleurs mode 0x01 */ + {{0x63}, + {0x03, 0x01, 0x03, 0x05, 0x02}, + {0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, + 0x47, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x02, 0x00, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x3F, + 0x0C, 0x00, 0x0F, 0x00, 0x00}}, /*640*480 n&b mode 0x80 */ - { - 0xE3, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, + {{0xE3}, + {0x03, 0x01, 0x0F, 0x00, 0x06}, + {0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x01, 0x00, 0x0F, 0x00, 0x00, - 80, 60, 1}, + 0x01, 0x00, 0x0F, 0x00, 0x00}}, /*320*200 4 couleurs mode 0x81 */ - { - 0x63, - 0x03, 0x09, 0x03, 0x00, 0x02, - 0x2D, 0x27, 0x28, 0x90, 0x2B, 0x80, 0xBF, 0x1F, 0x00, + {{0x63}, + {0x03, 0x09, 0x03, 0x00, 0x02}, + {0x2D, 0x27, 0x28, 0x90, 0x2B, 0x80, 0xBF, 0x1F, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x0E, 0x8F, 0x14, 0x00, 0x96, 0xB9, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0x9C, 0x0E, 0x8F, 0x14, 0x00, 0x96, 0xB9, 0xA3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x01, 0x00, 0x03, 0x00, 0x00, - 40, 25, - }, + 0x01, 0x00, 0x03, 0x00, 0x00}}, /*640*480 16 couleurs mode 0x82 */ - { - 0xE3, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x5F, 0x4F, 0x50, 0x82, 0x53, 0x9F, 0x0B, 0x3E, 0x00, + {{0xE3}, + {0x03, 0x01, 0x0F, 0x00, 0x06}, + {0x5F, 0x4F, 0x50, 0x82, 0x53, 0x9F, 0x0B, 0x3E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xE9, 0x8B, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, + 0xE9, 0x8B, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x01, 0x00, 0x0F, 0x00, 0x00, - 80, 60, 4}, + 0x01, 0x00, 0x0F, 0x00, 0x00}}, - /*720*480 16 couleurs mode 0x83 */ - { - 0xE7, - 0x03, 0x01, 0x08, 0x00, 0x06, - 0x6B, 0x59, 0x5A, 0x82, 0x60, 0x8D, 0x0B, 0x3E, 0x00, - 0x40, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - 0xEA, 0x0C, 0xDF, 0x2D, 0x08, 0xE8, 0x05, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x01, 0x00, 0x0F, 0x00, 0x00, - 90, 60, 4}, - - /*800*600 16 couleurs mode 0x84 */ - { - 0xE7, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x70, 0x63, 0x64, 0x92, 0x65, 0x82, 0x70, 0xF0, 0x00, - 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x5B, 0x8C, 0x57, 0x32, 0x00, 0x58, 0x70, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x3A, 0x3B, - 0x3C, 0x3D, 0x3E, 0x3F, - 0x01, 0x00, 0x0F, 0x00, 0x00, - 100, 75, 4}, - - /*320*200 256 couleurs RAPIDE mode 0x85 */ - { - 0x63, - 0x03, 0x01, 0x0F, 0x00, 0x0E, - 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, + /*320*200 256 couleurs RAPIDE mode 0x83 */ + {{0x63}, + {0x03, 0x01, 0x0F, 0x00, 0x0E}, + {0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 40, 25, 8}, + 0x41, 0x00, 0x0F, 0x00, 0x00}}, - /*320*200 256 couleurs mode 0x86 */ - { - 0x63, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, - 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x0E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 40, 25, 8}, - - /*320*400 256 couleurs mode 0x87 */ - { - 0x63, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, + /*320*400 256 couleurs mode 0x84 */ + {{0x63}, + {0x03, 0x01, 0x0F, 0x00, 0x06}, + {0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x9C, 0x8E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0x9C, 0x8E, 0x8F, 0x28, 0x00, 0x96, 0xB9, 0xE3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 40, 50, 8}, + 0x41, 0x00, 0x0F, 0x00, 0x00}}, - /*320*480 256 couleurs mode 0x88 */ - { - 0xE3, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, + /*320*480 256 couleurs mode 0x85 */ + {{0xE3}, + {0x03, 0x01, 0x0F, 0x00, 0x06}, + {0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xEA, 0xAC, 0xDF, 0x28, 0x00, 0xE7, 0x06, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0xEA, 0xAC, 0xDF, 0x28, 0x00, 0xE7, 0x06, 0xE3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 40, 60, 8}, + 0x41, 0x00, 0x0F, 0x00, 0x00}}, - /*360*480 256 couleurs mode 0x89 */ - { - 0xE7, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x6B, 0x59, 0x5A, 0x8E, 0x5E, 0x8A, 0x0D, 0x3E, 0x00, + /*360*480 256 couleurs mode 0x86 */ + {{0xE7}, + {0x03, 0x01, 0x0F, 0x00, 0x06}, + {0x6B, 0x59, 0x5A, 0x8E, 0x5E, 0x8A, 0x0D, 0x3E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xEA, 0xAC, 0xDF, 0x2D, 0x00, 0xE7, 0x06, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, + 0xEA, 0xAC, 0xDF, 0x2D, 0x00, 0xE7, 0x06, 0xE3, 0xFF}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF}, + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 45, 60, 8}, - - /*400*600 256 couleurs mode 0x8A */ - { - 0xE7, - 0x03, 0x01, 0x0F, 0x00, 0x06, - 0x74, 0x63, 0x64, 0x97, 0x68, 0x95, 0x86, 0xF0, 0x00, - 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x5B, 0x8D, 0x57, 0x32, 0x00, 0x60, 0x80, 0xE3, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F, - 0x41, 0x00, 0x0F, 0x00, 0x00, - 50, 75, 8} + 0x41, 0x00, 0x0F, 0x00, 0x00}}, }; diff --git a/lib/interrupts.c b/lib/interrupts.c index edf3368..0e6497c 100755 --- a/lib/interrupts.c +++ b/lib/interrupts.c @@ -351,7 +351,7 @@ void exception14() cli(); dumpcpu(); save_stack *dump = getESP(); - exception_stack *current = getESP()+36; + exception_stack *current = getESP()+sizeof(save_stack)+100; dump->eip=current->eip; dump->cs=current->cs; dump->oldesp=(current+1); diff --git a/lib/keyboard.c b/lib/keyboard.c index 4d2e7b9..4713ed8 100755 --- a/lib/keyboard.c +++ b/lib/keyboard.c @@ -223,7 +223,7 @@ unsigned convert(u32 keypressed) } else if (key == SCAN_F10) { - nextvmode(); + apply_nextvideomode(); } /* Scroll Lock, Num Lock, and Caps Lock mise a jour des leds */ diff --git a/lib/vga.c b/lib/vga.c index 9d03176..891ebbb 100755 --- a/lib/vga.c +++ b/lib/vga.c @@ -2,6 +2,7 @@ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* */ #include "vga.h" +#include "video.h" #include "memory.h" #include "asm.h" #include "types.h" @@ -9,141 +10,264 @@ #include "VGA/8x8fnt.c" #include "VGA/8x16fnt.c" -/* Registres VGAs */ +static videoinfos infos; -#define sequencer 0x3c4 -#define misc 0x3c2 -#define ccrt 0x3D4 -#define attribs 0x3c0 -#define graphics 0x3ce -#define state 0x3da - -/* Taille d'un plan de bit */ - -#define planesize 0x10000 - -static u16 resX, resY, color, splitY; /* resolution x,y en caractères et profondeur */ - -static u8 pages, activepage, showedpage; /* nombre de pages disponibles N° de la page active */ -static u32 linesize, pagesize; /* Taille d'une ligne et d'une page */ -static u8 vmode = 0xFF; /* mode en cours d'utilisation */ -static u32 basemem; /* Adresse de la mémoire vidéo */ -static bool scrolling, graphic, blink; /* Activation du défilement, Flag du mode graphique */ - -/*******************************************************************************/ -/* Donne la resolution max horizontale */ - -u16 getxres(void) +static videofonction fonctions = { - return resX; + 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; } /*******************************************************************************/ -/* Donne la profondeur en bit */ +/* Detecte si le hardware est disponible, return NULL ou pointeur sur le type de pilote */ +u8 *VGA_detect_hardware { + return "LEGACY", +}; -u8 getdepth(void) +/*******************************************************************************/ +/* Renvoie l'adresse du segment video */ + +u32 getbase(void) { - return color; + u32 base; + /*outb(graphics, 6); + base = inb(graphics + 1); + base >>= 2; + base &= 3;*/ + base = modes[infos.currentmode].graphics.Miscellaneous_Graphics_Register; + switch (base) { + case 0: + case 1: + base = 0xA0000; + break; + case 2: + base = 0xB0000; + break; + case 3: + base = 0xB8000; + break; + } + return base; } /*******************************************************************************/ -/* Donne la resolution max verticale */ +/* Change le mode video courant */ +/* ERR 0 aucune +/* ERR 1 mode non existant */ -u16 getyres(void) +u32 VGA_setvideo_mode(u8 mode) { - return resY - splitY; + u32 index; + while(vgacapabilities[index].modenumber!=0xFF) { + if (vgacapabilities[index].modenumber==mode) { + infos.currentmode=vgacapabilities[index].modenumber; + break; + index++; + } + if (infos.currentmode!=mode) + return 1; + infos.currentwidth=vgacapabilities[index].width; + infos.currentheight=vgacapabilities[index].height; + infos.currentdepth=vgacapabilities[index].depth; + infos.currentactivepage=0; + infos.currentshowedpage=0; + infos.currentcursorX=0; + infos.currentcursorY=0; + infos.currentfont1=0; + infos.currentfont2=0; + infos.isgraphic=vgacapabilities[index].graphic; + infos.isblinking=false; + infos.iscursorvisible=false; + if (infos.isgraphic) { + loadfont(font8x8, 8, 1); + loadfont(font8x16, 16, 0); + switch (infos.depth) { + case 1: + /* mode N&B */ + infos.currentpitch = infos.width; + break; + case 2: + /* mode 4 couleurs */ + infos.currentpitch = (infos.width << 1); + break; + case 4: + /* mode 16 couleurs */ + infos.currentpitch = infos.width; + break; + case 8: + /* mode 256 couleurs */ + if (modes[index].sequencer.Sequencer_Memory_Mode_Register == 0x0E) { + /* mode chainé (plus rapide mais limité en mémoire) */ + infos.currentpitch = (infos.width << 3); + } else { + /* mode non chainé */ + infos.currentpitch = (infos.width << 1); + } + break; + default: + break; + } + infos.pagesize = ((infos.height * infos.currentpitch) << 3); + } + else { + infos.currentpitch= infos.width * 2; + infos.pagesize=infos.height * 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(); + /* Initialise les registre "divers" */ + outb(misc, modes[index].misc); + /* Initialise les registre d'etat */ + outb(state, 0x00); + /* Initialise le séquenceur */ + outreg(sequencer, modes[index].sequencer, 5); + /* Debloque le verouillage des registres controleur CRT */ + outb(ccrt, 0x11); + outb(ccrt + 1, 0x0E); + /* Initialise le controleur CRT */ + outreg(ccrt, ctrc, 25); + /* Initialise le controleur graphique */ + outreg(graphics, modes[index].graphic, 9); + inb(state); + /* Initialise le controleur d'attributs */ + outregsame(attribs, modes[index].attributs, 21); + inb(state); + outb(attribs, 0x20); + /* Initialise l'adresse des procedures de gestion graphique et les differentes + variables en fonction de la profondeur et du mode */ + return 0; } /*******************************************************************************/ -/* Donne le nombre max de page ecran dispo */ +/* Renvoie le nom du driver */ +u8 *VGA_getvideo_drivername (void) { + return "VGA"; +} + +/*******************************************************************************/ +/* Renvoie un pointeur sur la structure des capacités graphiques */ + +u8 *VGA_getvideo_capabilities (void) { + return vgacapabilities; +} + +/*******************************************************************************/ +/* Renvoie un pointeur sur l'état courant de la carte */ +videoinfos *VGA_getvideo_info (void) { + return infos; +} + +/*******************************************************************************/ +/* 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, bool increment_src) { + +} + +/*******************************************************************************/ +/* 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) { + +} + +/*******************************************************************************/ +/* 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) { -u16 getnbpages(void) -{ - return pages; } /*******************************************************************************/ /* Fixe la page ecran de travail */ -void setpage(u8 page) +void VGA_page_set(u8 page) { - if (page < pages) - activepage = page; -} - -/*******************************************************************************/ -/* Recupere la page ecran de travail */ - -u8 getpage(void) -{ - return activepage; + if (page < infos.pagesnumber) + infos.currentactivepage = page; } /*******************************************************************************/ /* Affiche la page ecran specifié */ -void showpage(u8 page) +void VGA_page_show(u8 page) { - if (page < pages) { + if (page < infos.pagesnumber) { u16 addr; - addr = page * pagesize / 2; + addr = page * infos.pagesize / 2; outb(ccrt, 0x0C); outb(ccrt + 1, (addr >> 8)); outb(ccrt, 0x0D); outb(ccrt + 1, (addr & 0xFF)); - showedpage = page; + infos.currentshowedpage = page; } } /*******************************************************************************/ /* Sépare l'écran en 2 a partir de la ligne Y */ -void split(u16 y) +static splitY=0; + +void VGA_page_split(u16 y) { - u16 addr; - if (graphic == 0) - addr = (y << 3); - else - addr = y; - /* line compare pour ligne atteinte */ - outb(ccrt, 0x18); - outb(ccrt + 1, (addr & 0xFF)); - /* overflow pour le bit 8 */ + if (y!=0) { + u16 addr; + if (graphic == 0) + addr = (y << 3); + else + addr = y; + /* line compare pour ligne atteinte */ + outb(ccrt, 0x18); + outb(ccrt + 1, (addr & 0xFF)); + /* overflow pour le bit 8 */ - outb(ccrt, 0x07); - outb(ccrt + 1, (inb(ccrt + 1) & ~16) | ((addr >> 4) & 16)); + outb(ccrt, 0x07); + 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 + 1, (inb(ccrt + 1) & ~64) | ((addr >> 3) & 64)); - splitY = y; -} + outb(ccrt, 0x09); + outb(ccrt + 1, (inb(ccrt + 1) & ~64) | ((addr >> 3) & 64)); + splitY = y; + } + else + { + /* line compare pour ligne atteinte */ + outb(ccrt, 0x18); + outb(ccrt + 1, 0); + /* overflow pour le bit 8 */ -/*******************************************************************************/ -/* Sépare l'écran en 2 a partir de la ligne Y */ + outb(ccrt, 0x07); + outb(ccrt + 1, inb(ccrt + 1) & ~16); -void unsplit(void) -{ - /* line compare pour ligne atteinte */ - outb(ccrt, 0x18); - outb(ccrt + 1, 0); - /* overflow pour le bit 8 */ + /* Maximum Scan Line pour le bit 9 */ - outb(ccrt, 0x07); - outb(ccrt + 1, inb(ccrt + 1) & ~16); - - /* Maximum Scan Line pour le bit 9 */ - - outb(ccrt, 0x09); - outb(ccrt + 1, inb(ccrt + 1) & ~64); - splitY = 0; + outb(ccrt, 0x09); + outb(ccrt + 1, inb(ccrt + 1) & ~64); + splitY = 0; + } } /*******************************************************************************/ /* Attend la retrace verticale */ -void waitvretrace(void) +void VGA_wait_vretrace(void) { while ((inb(state) & 8) == 0) ; } @@ -151,7 +275,7 @@ void waitvretrace(void) /*******************************************************************************/ /* Attend la retrace horizontale */ -void waithretrace(void) +void VGA_wait_hretrace(void) { while ((inb(state) & 1) == 0) ; } @@ -159,42 +283,27 @@ void waithretrace(void) /*******************************************************************************/ /* Active l'affichage du curseur de texte */ -void enablecursor(void) +void VGA_cursor_enable(void) { u8 curs; /* active le curseur hardware */ outb(ccrt, 10); curs = inb(ccrt + 1) & ~32; outb(ccrt + 1, curs); + infos.isgraphic=true; } /*******************************************************************************/ /* Desactive l'affichage du curseur de texte */ -void disablecursor(void) +void VGA_cursor_disable(void) { u8 curs; /* Desactive le curseur hardware */ outb(ccrt, 10); curs = inb(ccrt + 1) | 32; outb(ccrt + 1, curs); -} - -/*******************************************************************************/ -/* Active le scrolling en cas de débordement d'écran */ - -void enablescroll(void) -{ - scrolling = true; -} - -/*******************************************************************************/ - -/* Desactive le scrolling en cas de débordement d'écran */ - -void disablescroll(void) -{ - scrolling = false; + infos.isgraphic=false; } /*******************************************************************************/ @@ -213,387 +322,31 @@ void useplane(u8 plan) outb(sequencer + 1, mask); } -/*******************************************************************************/ -/* Renvoie l'adresse du segment video */ - -u32 getbase(void) -{ - u32 base; - outb(graphics, 6); - base = inb(graphics + 1); - base >>= 2; - base &= 3; - switch (base) { - case 0: - case 1: - base = 0xA0000; - break; - case 2: - base = 0xB0000; - break; - case 3: - base = 0xB8000; - break; - } - return base; -} - -/*******************************************************************************/ -/* efface l'écran */ - -void (*fill) (u8 attrib); - -void fill_text(u8 attrib) -{ - memset((u8 *) (basemem + activepage * pagesize), ' ', pagesize / 2, 2); - memset((u8 *) (basemem + activepage * pagesize + 1), attrib, - pagesize / 2, 2); -} - -void fill_chain(u8 attrib) -{ - memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F, - pagesize, 1); -} - -void fill_unchain(u8 attrib) -{ - int i; - for (i = 0; i < 4; i++) { - useplane(i); - memset((u8 *) (basemem + activepage * pagesize), attrib & 0x0F, - pagesize, 1); - } -} - /*******************************************************************************/ /* fixe la position du curseur texte */ -void gotoscr(u16 x, u16 y) +void VGA_cursor_set(u16 x, u16 y) { u16 pos; if (splitY == 0) - pos = (showedpage * pagesize / 2 + x + y * resX); + pos = (infos.currentshowedpage * infos.pagesize / 2 + x + y * infos.width); else - pos = (x + y * resX); + pos = (x + y * infos.width); outb(ccrt, 0x0F); outb(ccrt + 1, (u8) (pos & 0x00FF)); outb(ccrt, 0x0E); outb(ccrt + 1, (u8) ((pos & 0xFF00) >> 8)); -} - -/*******************************************************************************/ -/* Fait defiler l'ecran de n lignes vers le haut */ - -void (*scroll) (u8 lines, u8 attrib); - -void scroll_unchain(u8 lines, u8 attrib) -{ - if (scrolling) { - u8 i; - for (i = 0; i < 4; i++) { - useplane(i); - memcpy((u8 *) (basemem + activepage * pagesize + - linesize * 8 * lines), (u8 *) basemem, - pagesize - linesize * 8 * lines, 1); - memset((u8 *) (basemem + activepage * pagesize + - pagesize - linesize * 8 * lines), - attrib & 0x0F, linesize * 8 * lines, 1); - } - } -} - -void scroll_chain(u8 lines, u8 attrib) -{ - if (scrolling) { - memcpy((u8 *) basemem + activepage * pagesize + linesize * 8 * lines, - (u8 *) basemem + activepage * pagesize, pagesize - linesize * 8 * lines, 1); - memset((u8 *) (basemem + activepage * pagesize + pagesize - linesize * 8 * lines), attrib & 0x0F, linesize * 8 * lines, 1); - } -} - -void scroll_text(u8 lines, u8 attrib) -{ - if (scrolling) { - memcpy((u8 *) basemem + activepage * pagesize + - linesize * lines, (u8 *) basemem + activepage * pagesize, - pagesize - linesize * lines, 1); - memset((u8 *) (basemem + activepage * pagesize + pagesize - - linesize * lines - 2), ' ', - (linesize * lines) / 2, 2); - memset((u8 *) (basemem + activepage * pagesize + pagesize - - linesize * lines - 1), attrib, - (linesize * lines) / 2, 2); - } -} - -/*******************************************************************************/ -/* Affiche le caractère a l'écran */ - -void (*showchar) (u16 coordx, u16 coordy, u8 thechar, u8 attrib); - -void showchar_graphic(u16 coordx, u16 coordy, u8 thechar, u8 attrib) -{ - u8 x, y, pattern, set; - for (y = 0; y < 8; y++) { - pattern = font8x8[thechar * 8 + y]; - for (x = 0; x < 8; x++) { - set = ((pattern >> (7 - x)) & 0x1); /* mettre un ROL importé depuis asm */ - if (set == 0) - writepxl(coordx * 8 + x, coordy * 8 + y, - ((attrib & 0xF0) >> 8) * set); - else - writepxl(coordx * 8 + x, coordy * 8 + y, - (attrib & 0x0F) * set); - } - } -} - -void showchar_text(u16 coordx, u16 coordy, u8 thechar, u8 attrib) -{ - u8 *screen; - screen = - (u8 *) basemem + activepage * pagesize + 2 * (coordx + - coordy * resX); - *screen = thechar; - *(++screen) = attrib; -} - -/*******************************************************************************/ -/* Recupere le caractère a l'écran */ - -u8(*getchar) (u16 coordx, u16 coordy); - -u8 getchar_text(u16 coordx, u16 coordy) -{ - u8 *screen; - screen = - (u8 *) basemem + activepage * pagesize + 2 * (coordx + - coordy * resX); - return *screen; -} - -/*******************************************************************************/ -/* Recupere les attributs a l'écran */ - -u8(*getattrib) (u16 coordx, u16 coordy); - -u8 getattrib_text(u16 coordx, u16 coordy) -{ - u8 *screen; - screen = - (u8 *) basemem + activepage * pagesize + 2 * (coordx + - coordy * resX) + 1; - return *screen; -} - -/*******************************************************************************/ -/* Ecrit un pixel a l'écran */ - -void (*writepxl) (u16 x, u16 y, u32 c); - -void writepxl_1bit(u16 x, u16 y, u32 c) -{ - u8 *off; - u8 mask; - c = (c & 1) * 0xFF; - off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8); - x = (x & 7) * 1; - mask = 0x80 >> x; - *off = ((*off) & ~mask) | (c & mask); -} - -void writepxl_2bits(u16 x, u16 y, u32 c) -{ - u8 *off; - u8 mask; - c = (c & 3) * 0x55; - off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4); - x = (x & 3) * 2; - mask = 0xC0 >> x; - *off = ((*off) & ~mask) | (c & mask); -} - -void writepxl_4bits(u16 x, u16 y, u32 c) -{ - u8 *off; - u8 mask, p, pmask; - off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 8); - x = (x & 7) * 1; - mask = 0x80 >> x; - pmask = 1; - for (p = 0; p < 4; p++) { - useplane(p); - if (pmask & c) - *off = ((*off) | mask); - else - *off = ((*off) & ~mask); - pmask <<= 1; - } -} - -void writepxl_8bits(u16 x, u16 y, u32 c) -{ - u8 *off; - off = (u8 *) (basemem + activepage * pagesize + linesize * y + x); - *off = c; -} - -void writepxl_8bitsunchain(u16 x, u16 y, u32 c) -{ - u8 *off; - off = (u8 *) (basemem + activepage * pagesize + linesize * y + x / 4); - useplane(x & 3); - *off = c; -} - -/*******************************************************************************/ -/* Met le mode video suivant */ - -u8 nextvmode(void) -{ - u8 mode = getvmode(); - mode++; - if (mode >= 0x80) { - if (mode > maxgraphmode) - mode = 0x0; - } else { - if (mode > maxtextmode) - mode = 0x80; - } - setvmode(mode); - return mode; -} - -/*******************************************************************************/ -/* Change le mode video courant */ - -u32 setvmode(u8 mode) -{ - u8 *def, gmode; - /* Récupere la definition des registres VGA en fonction du mode - graphique : >0x80 - text : 0x00 - 0x7F - */ - if (mode >= 0x80) { - gmode = mode - 0x80; - if (gmode > maxgraphmode) - return 1; /* mode inexistant */ - def = graphmodes[gmode]; - graphic = true; - } else { - if (mode > maxtextmode) - return 1; /* mode inexistant */ - def = textmodes[mode]; - graphic = false; - loadfont(font8x8, 8, 1); - loadfont(font8x16, 16, 0); - } - /* Initialise les registre "divers" */ - outb(misc, def[0]); - /* Initialise les registre d'etat */ - outb(state, 0x00); - /* Initialise le séquenceur */ - outreg(sequencer, &def[1], 5); - /* Debloque le verouillage des registres controleur CRT */ - outb(ccrt, 0x11); - outb(ccrt + 1, 0x0E); - /* Initialise le controleur CRT */ - outreg(ccrt, &def[6], 25); - /* Initialise le controleur graphique */ - outreg(graphics, &def[31], 9); - inb(state); - /* Initialise le controleur d'attributs */ - outregsame(attribs, &def[40], 21); - inb(state); - outb(attribs, 0x20); - /* Récupere depuis la table de définition des mode la résolution et la - profondeur (en bits) */ - resX = def[61]; - resY = def[62]; - color = def[63]; - /* Initialise l'adresse des procedures de gestion graphique et les differentes - variables en fonction de la profondeur et du mode */ - if (!graphic) { - /* mode texte */ - linesize = resX * 2; - writepxl = NULL; /* pas d'affichage de pixels */ - showchar = showchar_text; - scroll = scroll_text; - fill = fill_text; - pagesize = resY * linesize; - getchar = getchar_text; - getattrib = getattrib_text; - } else { - switch (color) { - case 1: - /* mode N&B */ - linesize = resX; - writepxl = writepxl_1bit; - fill = fill_chain; - scroll = scroll_chain; - break; - case 2: - /* mode 4 couleurs */ - linesize = (resX << 1); - writepxl = writepxl_2bits; - fill = fill_chain; - scroll = scroll_chain; - break; - case 4: - /* mode 16 couleurs */ - linesize = resX; - writepxl = writepxl_4bits; - fill = fill_unchain; - scroll = scroll_unchain; - break; - case 8: - /* mode 256 couleurs */ - if (def[5] == 0x0E) { - /* mode chainé (plus rapide mais limité en mémoire) */ - linesize = (resX << 3); - writepxl = writepxl_8bits; - scroll = scroll_chain; - fill = fill_chain; - } else { - /* mode non chainé */ - linesize = (resX << 1); - writepxl = writepxl_8bitsunchain; - scroll = scroll_unchain; - fill = fill_unchain; - } - break; - default: - break; - } - showchar = showchar_graphic; - pagesize = ((resY * linesize) << 3); - } - /* calcul des variables d'état video */ - activepage = 0; - showedpage = 0; - splitY = 0; - vmode = mode; - scrolling = 1; - pages = (planesize / pagesize); - basemem = (def[20] << 8) + def[21] + getbase(); - return 0; -} - -/*******************************************************************************/ -/* Récupère le mode vidéo en cours */ - -u8 getvmode(void) -{ - return vmode; + info.currentcursorX=x; + info.currentcursorY=y; } /*******************************************************************************/ /* Charge une nouvelle police de caractère */ +/* ERR 1 mode graphique activé*/ -u32 loadfont(u8 * def, u8 size, u8 font) +u32 VGA_font_load(u8 * def, u8 size, u8 font) { - if (graphics == 1) + if (infos.isgraphic) return 1; u8 oldregs[5] = { 0, 0, 0, 0, 0 }; u8 *base; @@ -640,70 +393,50 @@ u32 loadfont(u8 * def, u8 size, u8 font) return 0; } -/*******************************************************************************/ -/* Récupere le N° de la police de caractère en cours d'utilisation */ - -u8 getfont(void) -{ - u8 num, tmp; - outb(sequencer, 3); - tmp = inb(sequencer + 1); - num = (tmp & 0x03) | ((tmp & 0x10) >> 2); - return num; -} - -/*******************************************************************************/ -/* Récupere le N° de la police de caractère en cours d'utilisation */ - -u8 getfont2(void) -{ - u8 num, tmp; - outb(sequencer, 3); - tmp = inb(sequencer + 1); - num = ((tmp & 0x0C) >> 2) | ((tmp & 0x20) >> 3); - return num; -} - /*******************************************************************************/ /* Fixe le N° de la police de caractère a utiliser */ -void setfont(u8 num) +void VGA_font1_set(u8 num) { num &= 0x07; outb(sequencer, 3); outb(sequencer + 1, (inb(sequencer + 1) & 0xEC) | ((num & 0x03) + ((num & 0x04) << 2))); + info.currentfont1=num; } /*******************************************************************************/ /* Fixe le N° de la police de caractère a utiliser */ -void setfont2(u8 num) +void VGA_font2_set(u8 num) { num &= 0x07; outb(sequencer, 3); outb(sequencer + 1, (inb(sequencer + 1) & 0xD3) | (((num & 0x03) << 2) + ((num & 0x04) << 3))); + info.currentfont2=num; } /*******************************************************************************/ /* Autorise le clignotement */ -void enableblink(void) +void VGA_blink_enable(void) { outb(ccrt, 0x10); outb(ccrt + 1, (inb(sequencer + 1) | 0x04)); + info.isblinking=true; } /*******************************************************************************/ /* Annule le clignotement */ -void disableblink(void) +void VGA_blink_disable(void) { outb(ccrt, 0x10); outb(ccrt + 1, (inb(sequencer + 1) & ~0x04)); + info.isblinking=false; } /*******************************************************************************/ diff --git a/lib/video.c b/lib/video.c index 755612b..abf47a7 100755 --- a/lib/video.c +++ b/lib/video.c @@ -5,6 +5,8 @@ #include "video.h" #include "stdarg.h" +drivers registred[maxdrivers]; + console vc[8] = { {0x07, 0, 0, 0, 0, 0, 0, 0} , @@ -815,3 +817,153 @@ u8 *sitoa(u64 num, u8 * str, u64 dim) return pointer; } /*******************************************************************************/ +/* initialise le tableau des pilotes vidéo */ +void initdriver() { + for(u32 i=0;ibestdepth && (cap[j].width*cap[j].height)>=bestresol) + { + bestdepth=cap[j].depth; + bestresol=cap[j].width*cap[j].height; + bestmode=cap[j].modenumber; + bestdriver=registred[i].pointer.getvideo_drivername(); + } + j++; + } + i++; + } + if (bestdriver!=NULL) apply_driver(bestdriver); + setvideo_mode(bestmode); +} + +/*******************************************************************************/ +/* Choisi le meilleur driver spécifié par le nom */ +void apply_driver(u8* name); +{ + u32 i=0; + while (registred[i].nom!=NULL && i