00001
00005 #include "routix/system.h"
00006 #include <routix/kstdio.h>
00007 #include <drivers/video.h>
00008
00009 #define VIDEO (0xb8000)
00010
00011 #define TAB_SPACES 4
00012
00013 unsigned char *pos = (unsigned char *) VIDEO;
00014 unsigned char cursor_caracteristicas = 2;
00015
00016 #define VIDEO_LAST_LINE 3840
00017
00018 #define nextpos(pos) if ( (pos+=2) > (unsigned char *) VIDEO+4000 ) { \
00019 scroll_up(); \
00020 pos = (unsigned char *) (VIDEO + VIDEO_LAST_LINE); \
00021 }
00022
00023
00024
00025 int putchar ( int a )
00026 {
00027
00028
00029
00030 if ( a == '\n' ) {
00031 int frac;
00032 int newpos;
00033 frac = (int) (pos-VIDEO)/160;
00034 newpos = (VIDEO+160*(frac+1));
00035 if ( newpos >= VIDEO+4000 ) {
00036 scroll_up();
00037 pos = (unsigned char *) ( VIDEO + VIDEO_LAST_LINE );
00038 }
00039 else
00040 pos=(unsigned char *) newpos;
00041 }
00042 else if ( a == '\t' ) {
00043 int i;
00044 for (i=0; i<4; i++ )
00045
00046 nextpos(pos);
00047 }
00048 else if ( a == '\b' ) {
00049 pos-=2;
00050 *pos=' ';
00051 *(pos+1) = cursor_caracteristicas;
00052 }
00053
00054 else {
00055 *pos = (unsigned char) a;
00056 *(pos+1) = cursor_caracteristicas;
00057
00058 nextpos(pos);
00059 }
00060
00061
00062
00063 refresh_cursor( ((pos - (unsigned char *)VIDEO) /2) );
00064
00065
00066 return a;
00067 }
00068
00069
00070
00071
00072 int puts ( const char *s )
00073 {
00074 int cantidad=0;
00075
00076 while ( *s ) {
00077 putchar(*s++);
00078 cantidad++;
00079 }
00080
00081 return cantidad;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 void clrscr (void)
00104 {
00105 int i;
00106 unsigned char *ptr;
00107
00108 ptr = (unsigned char *) VIDEO;
00109
00110 for (i=0; i<4000; i+=2 ) {
00111 *(ptr+i) = ' ';
00112 *(ptr+i+1) = 2;
00113 }
00114
00115 pos = (unsigned char *) VIDEO;
00116 }
00117
00118 void scroll_up ( void )
00119 {
00120 unsigned char *inicio =(unsigned char *) VIDEO + 160;
00121 unsigned char *destino=(unsigned char *) VIDEO;
00122 int count;
00123
00124 cli();
00125
00126 __asm__ __volatile__ ("cld ; rep ; movsw" : : "c" (VIDEO_LAST_LINE), "S" (inicio) , "D" (destino));
00127
00128
00129
00130
00131
00132
00133
00134 destino += VIDEO_LAST_LINE;
00135 for ( count=0; count < 80; count ++ ) {
00136 *destino++ = ' ';
00137 *destino++ = cursor_caracteristicas;
00138 }
00139
00140 sti();
00141 }
00142
00143
00144
00145
00146 unsigned char *gotoxy ( int fila, int columna)
00147 {
00148 if ( (fila > 25) || (columna > 80) ) { return NULL; }
00149 pos = (unsigned char *) (VIDEO + (fila-1)*2*80+2*(columna-1) );
00150 return pos;
00151 }
00152
00153
00154
00155
00156