/* kernLdr_print.c - This file is a part of NutsOS * * NutsOS * Copyright (C) 2013 Free Software Foundation, Inc. * * NutsOS is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * NutsOS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with NutsOS; If not, see . * * Valentin Verdier */ #include "kernLdr.h" #define DEFAULT_COLOR 0x0F char color = (char) DEFAULT_COLOR; void scrollup(int lines) { char* vid; char* offset; for(vid = (char*) VIDEO_ADDR; vid < (char*) VIDEO_END_OFFSET; vid += 2) { offset = (char*) (vid + lines * 160); if(offset < (char*) VIDEO_END_OFFSET) { vid[0] = offset[0]; vid[1] = offset[1]; } else { vid[0] = 0; vid[1] = color; } } pos_y -= lines; if(pos_y < 0) { pos_y = 0; } } void write_char(char c_ascii) { char* vid; vid = (char*) (VIDEO_ADDR + pos_y * 160 + pos_x * 2); switch(c_ascii) { case 0: break; case 8: vid[-2] = 0; vid[-1] = color; pos_x--; break; case 10: // Ligne suivante pos_x = 0; pos_y++; break; case 13: // Retour debut de ligne pos_x = 0; break; default: vid[0] = c_ascii; vid[1] = color; pos_x++; break; } if(pos_x > 79) { pos_x = 0; pos_y++; } if(pos_y > 24) { scrollup(1); } if(posX < 0) { posX = 79; posY--; } if(posY < 0) { posX = 0; posY = 0; } if(enable_cursor) { move_cursor(pos_x, pos_y); } } static void print_dec(unsigned int a, char color) { char str[11]; int_to_str(a, str, 10); unsigned int i; for(i = 0; str[i] != 0; i++) { write_char(str[i]); } } static void print_hex(unsigned int a, char color) { char str[9]; int_to_str(a, str, 16); unsigned int i; for(i = 0; str[i] != 0; i++) { write_char(str[i]); } } static void print_bin(unsigned int a, char color) { char str[33]; int_to_str(a, str, 2); unsigned int i; for(i = 0; str[i] != 0; i++) { write_char(str[i]); } } void print(char *str, ...) { va_list arg; va_start(arg, str); while(str[0] != 0) { if(str[0] == '%') { if(str[1] == 'd') { print_dec(va_arg(arg, T_dword), color); str += 2; } else if(str[1] == 'x') { print_hex(va_arg(arg, T_dword), color); str += 2; } else if(str[1] == 'b') { print_bin(va_arg(arg, T_dword), color); str += 2; } else if(str[1] == 's') { print(va_arg(arg, char*), color); str += 2; } else if(str[1] == 'C') { } else { write_char(*str, color); str++; } } else { write_char(*str, color); str++; } } va_end(arg); } void clear() { char* vid; for(vid = (char*) VIDEO_ADDR; vid <= (char*) VIDEO_END_OFFSET; vid += 2) { vid[0] = 0; vid[1] = ; } } void show_cursor() { enable_cursor = 1; move_cursor(pos_x, pos_y); } void hide_cursor() { enable_cursor = 0; move_cursor(-1, -1); } void move_cursor(char x, char y) { T_word c_pos = (T_word) (y * 80 + x); _out(0x3D4, 0x0F); _out(0x3D5, (T_byte) cpos); _out(0x3D4, 0x0E); _out(0x3D5, (T_byte) (cpos >> 8)); }