sys_console.c
资源名称:tizos.rar [点击查看]
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:3k
源码类别:
操作系统开发
开发平台:
C/C++
- #include <devices/sys_console.h>
- struct Text_Console Sys_Console_Text;
- struct Text_Console* test_ret_print() {
- return &Sys_Console_Text;
- }
- void system_console_command(unsigned long cmd, void* param) ;
- void sys_console_configure_text(struct Screen_Mode* scr);
- //void sys_console_print_text (struct Text_Console* scr,char* string)
- void __init_device init_system_console (struct device* dev) {
- kprint ("Registered System Device: ");
- kprint (dev->name);
- kprint (" n");
- dev->command=(void*)&system_console_command;
- /* Poso a 0,0 les coordenades de la consola */
- Sys_Console_Text.Act_Column=0;
- Sys_Console_Text.Act_Row=30;
- }
- void system_console_command(unsigned long cmd, void* param) {
- struct Screen_Mode* reg_scr;
- switch (cmd) {
- case SYS_CONSOLE_REGISTER_VIDEO_DEVICE:
- /* Param ha de ser struct device */
- kprint ("SYS-Console Video Device Registered: ");
- Sys_Console_Text.Video_Device=(struct device*)param;
- kprint (Sys_Console_Text.Video_Device->name);
- reg_scr=(struct Screen_Mode*)kmalloc(sizeof(struct Screen_Mode));
- Sys_Console_Text.Video_Device->command(GET_SCREEN_MODE,reg_scr);
- kprint (" Configured as FB: n");
- char text[50];
- snprintf(text,"x: %dpx, y: %dpx, bpp:%dn",reg_scr->XRes,reg_scr->YRes,reg_scr->BitsPerPixel);
- kprint (text);
- sys_console_configure_text(reg_scr);
- kprint ("CACA");
- // act_print(2);
- break;
- }
- }
- void sys_console_print_text (struct Text_Console* scr,char* string) {
- struct xy_str out;
- //char *str=string;
- char* str=(char *)kmalloc(sizeof(char)*255);
- strcpy(str,string);
- int i=0;
- while (str[i]!=' ' && i < scr->columns-scr->Act_Column) {
- switch (str[i]) {
- case 'n':
- str[i]=' ';
- out.X=scr->Act_Column*Sys_Console_Text.Font_Width;
- out.Y=scr->Act_Row*Sys_Console_Text.Font_Height;
- out.str=str;
- scr->Video_Device->command(XY_PRINT_STR,&out);
- scr->Act_Column=0;
- scr->Act_Row++;
- str=str+i+1 ;
- i=-1;
- break;
- }
- i++;
- }
- out.X=scr->Act_Column*Sys_Console_Text.Font_Width;
- out.Y=scr->Act_Row*Sys_Console_Text.Font_Height;
- out.str=str;
- scr->Video_Device->command(XY_PRINT_STR,&out);
- scr->Act_Column+=i;
- }
- void sys_console_configure_text(struct Screen_Mode* scr) {
- //Sys_Console_Text.Font_Width=scr->XCharSize;
- //Sys_Console_Text.Font_Height=scr->YCharSize;
- Sys_Console_Text.Font_Width=SYS_C_FONT_WIDTH;
- Sys_Console_Text.Font_Height=SYS_C_FONT_HEIGHT;
- Sys_Console_Text.rows=scr->YRes/Sys_Console_Text.Font_Height;
- Sys_Console_Text.columns=scr->XRes/Sys_Console_Text.Font_Width;
- /* Espai per el buffer de text de la consola */
- Sys_Console_Text.Text_buffer=(char*)kmalloc(sizeof(char)*Sys_Console_Text.rows*Sys_Console_Text.columns);
- /* DEBUG INFO */
- kprint ("SYS_CONSOLE (Text Console) ");
- char text[50];
- snprintf(text,"XCharSize: %dpx, YCharSize: %dpx, Rows:%d, Cols:%dn",
- Sys_Console_Text.Font_Width,Sys_Console_Text.Font_Height,Sys_Console_Text.rows,Sys_Console_Text.columns);
- kprint (text);
- }