Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <termios.h>
- /***************************************************************************/
- #include "settings.h"
- #include "lib_colors.h"
- /**t************************************************************************/
- struct lib_strings_colorRGB {
- unsigned char r;
- unsigned char g;
- unsigned char b;
- unsigned char t;
- };
- /**e************************************************************************/
- struct lib_strings_colorRGB lib_strings_ink;
- struct lib_strings_colorRGB lib_strings_paper;
- /***************************************************************************/
- static unsigned char memory[LINE_SIZE*LINE_NUM];
- static unsigned int cursor;
- /***************************************************************************/
- void putcharS( char ch )
- {
- if (ch<' ') ch='#';
- putchar( ch );
- return;
- }
- /**h*************************************************************************/
- extern int lib_screen_init()
- {
- static struct termios old, current;
- tcgetattr(0, &old); /* grab old terminal i/o settings */
- current = old; /* make new settings same as old settings */
- current.c_lflag &= ~ICANON; /* disable buffered i/o */
- current.c_lflag &= ~ECHO; /* set no echo mode */
- tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */
- return 0;
- }
- /**h************************************************************************/
- extern int lib_screen_cls()
- {
- printf("\033[8;%i;%it",LINE_NUM,LINE_SIZE);
- printf("\033[2J");
- for(int i=0;i<LINE_SIZE*LINE_NUM;i++)
- {
- memory[i]=' ';
- }
- cursor=0;
- lib_strings_ink=lib_colors_main_ink;
- lib_strings_paper=lib_colors_main_backgrownd;
- return 0;
- }
- /**h************************************************************************/
- extern int lib_screen_cursor( int x, int y )
- {
- cursor=y*LINE_SIZE+x;
- return cursor;
- }
- /**h************************************************************************/
- extern int lib_screen_curGet( )
- {
- return cursor;
- }
- /**h************************************************************************/
- extern void lib_screen_curSet( int cur)
- {
- cursor=cur;
- return;
- }
- /**h************************************************************************/
- extern unsigned char * lib_screen_ptr( int x, int y )
- {
- return &memory[y*LINE_SIZE+x];
- }
- /**h************************************************************************/
- extern unsigned char lib_screen_get( int x, int y )
- {
- return memory[y*LINE_SIZE+x];
- }
- /**h************************************************************************/
- extern int lib_screen_print( int n,unsigned char *str )
- {
- printf("\033[%i;%iH",cursor / LINE_SIZE+1, cursor % LINE_SIZE+1);
- printf("\033[38;2;%i;%i;%im",lib_strings_ink.r,lib_strings_ink.g,lib_strings_ink.b);
- printf("\033[48;2;%i;%i;%im",lib_strings_paper.r,lib_strings_paper.g,lib_strings_paper.b);
- for(int i=0;i<n;i++)
- {
- putcharS(memory[cursor]=str[i]);
- cursor++;
- if (cursor>LINE_SIZE*LINE_NUM)
- {
- cursor=0;
- }
- }
- return cursor;
- }
- /**h************************************************************************/
- extern int lib_screen_printC( int n,unsigned char ch )
- {
- printf("\033[%i;%iH",cursor / LINE_SIZE+1, cursor % LINE_SIZE+1);
- printf("\033[38;2;%i;%i;%im",lib_strings_ink.r,lib_strings_ink.g,lib_strings_ink.b);
- printf("\033[48;2;%i;%i;%im",lib_strings_paper.r,lib_strings_paper.g,lib_strings_paper.b);
- for(int i=0;i<n;i++)
- {
- putcharS(memory[cursor]=ch);
- cursor++;
- if (cursor>LINE_SIZE*LINE_NUM)
- {
- cursor=0;
- }
- }
- return cursor;
- }
- /***************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement