@ -1,12 +1,10 @@
# include "conio.h"
# include <string.h>
# include <redbus.h>
# include <console.h>
# define redbus 0x0300
int conid = 0x01 ;
Console * con = ( Console * ) redbus ;
//Slow, find how str function does it and apply to whole string at once?
//Technically could be void, but with returning string allows you to use it easy.
char * strinv ( char str [ ] ) {
int i ;
for ( i = 0 ; i < strlen ( str ) ; i + + ) {
@ -14,10 +12,10 @@ char * strinv(char str[]) {
}
return str ;
}
//This is currently unable to screenwrap. Improve in the future.
void conprint ( char * str , int x , int y ) {
rb_map_device ( conid ) ;
con - > line = y ;
con - > line = y % 50 ;
memcpy ( con - > display + x , str , strlen ( str ) ) ;
}
@ -35,21 +33,82 @@ struct cursor_pos {
} ;
void set_cursor_pos ( int x , int y ) {
rb_map_device ( conid ) ;
con - > cursor_x = x ;
con - > cursor_y = y ;
}
struct cursor_pos get_cursor_pos ( ) {
struct cursor_pos cursor ;
rb_map_device ( conid ) ;
cursor . x = con - > cursor_x ;
cursor . y = con - > cursor_y ;
return cursor ;
}
void set_cursor_mode ( int mode ) {
rb_map_device ( conid ) ;
con - > cursor_mode = mode ;
}
int get_cursor_mode ( ) {
rb_map_device ( conid ) ;
return con - > cursor_mode ;
}
void conclear ( ) {
rb_map_device ( conid ) ;
blit ( 1 , ' ' , ( char ) 0xBD , 0 , 0 , 80 , 50 ) ;
set_cursor_pos ( 0 , 0 ) ;
}
void blit ( char command , char x , char y , char xo , char yo , char w , char h ) {
con - > blit_start_x = x ;
con - > blit_start_y = y ;
con - > blit_offset_x = xo ;
con - > blit_offset_y = yo ;
con - > blit_width = w ;
con - > blit_height = h ;
con - > blit_mode = command ;
while ( con - > blit_mode ! = 0 ) ; //WAI
}
# define LF 13
# define BSP 8
char * read_keyboard ( ) {
int pos = 0 ;
char buf [ 128 ] ;
int breakpoint = 1 ;
int cursorp ;
rb_map_device ( conid ) ;
memset ( buf , 0 , 128 ) ;
cursorp = con - > cursor_x ;
con - > line = con - > cursor_y ;
while ( breakpoint ) {
while ( con - > kb_pos ! = con - > kb_start & & breakpoint ) {
switch ( con - > kb_key ) {
case LF :
fill ( ' ' , cursorp , con - > cursor_y , con - > cursor_x , 1 ) ;
con - > cursor_x = cursorp ;
breakpoint = 0 ;
con - > kb_start + + ;
break ;
case BSP :
con - > kb_pos - - ;
con - > cursor_x - - ;
pos - - ;
buf [ pos ] = ' ' ;
con - > display [ con - > cursor_x ] = ' ' ;
break ;
default :
buf [ pos ] = con - > kb_key ;
con - > display [ con - > cursor_x ] = con - > kb_key ;
con - > cursor_x + + ;
con - > kb_start + + ;
pos + + ;
break ;
}
}
}
return buf ;
}