home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / archiver / peek_221.arj / SETCMODE.C < prev    next >
C/C++ Source or Header  |  1992-03-30  |  4KB  |  209 lines

  1. #include "peeker.h"
  2. #include "timers.h"
  3.  
  4. int _fastcall    _wherex (void);
  5. int _fastcall    _wherey (void);
  6. void _fastcall   _sleep (int secs);
  7. void _fastcall   cursor (int x, int y);
  8. void _fastcall   curr_cursor (int *x, int *y);
  9. char * _fastcall avatar2ansi (int avatarcode);
  10. char * _fastcall assign (char *d,char *a);
  11. char * _fastcall add_backslash (char *d);
  12. void _fastcall   stat_line (void);
  13. void _fastcall   time_line (void);
  14. ulong _fastcall  getxbbstime(void);
  15. int cdecl dprintf (int x,int y,char attr,char *string,...);
  16. int _fastcall dputs (int x,int y,char attr,char *string);
  17.  
  18. extern void _fastcall (*pause_mtask)(void);
  19. int _fastcall ansi_out(char *str);
  20.  
  21. extern char graphics;
  22. extern char username[36];
  23. extern unsigned int  timelimit;
  24.  
  25.  
  26.  
  27. int _fastcall
  28. _wherex (void)
  29. {
  30.  
  31.   _AX = 0x0300;
  32.   _BX = 0;
  33.   geninterrupt(16);
  34.   return _DL;
  35. }
  36.  
  37.  
  38.  
  39. int _fastcall
  40. _wherey (void)
  41. {
  42.  
  43.   _AX = 0x0300;
  44.   _BX = 0;
  45.   geninterrupt(16);
  46.   return _DH;
  47. }
  48.  
  49.  
  50.  
  51. void _fastcall
  52. _sleep (int secs)
  53. {                               /* snooze a while */
  54.  
  55.   clock_t         t1;
  56.  
  57.  
  58.   t1 = clock () + ((clock_t) secs * (clock_t) CLOCKS_PER_SEC);
  59.   while (clock () < t1)
  60.     (*pause_mtask)();
  61. }
  62.  
  63.  
  64. /* Position cursor */
  65.  
  66. void _fastcall cursor (int x, int y) {
  67.  
  68.   pos_hardcursor(x,y);
  69. }
  70.  
  71.  
  72. /* Return cursor position */
  73.  
  74. void _fastcall curr_cursor (int *x, int *y) {
  75.  
  76.   _AX = 0x0300;
  77.   _BX = 0;
  78.   geninterrupt(0x10);
  79.   *x = _DL;
  80.   *y = _DH;
  81. }
  82.  
  83.  
  84. static int av_trans[] = {0,4,2,6,1,5,3,7};
  85.  
  86.  
  87. char * _fastcall avatar2ansi (int avatarcode) {
  88.  
  89.   int foreg;
  90.   int backg;
  91.   static char temp[13];
  92.   static char ansi[21];
  93.  
  94.  
  95.   if(!graphics) return "";
  96.  
  97.   avatarcode &= 255;    /* 127 to strip high bit */
  98.   strcpy(ansi,"\x1b[");
  99.   backg = (avatarcode & (64 | 32 | 16)) / 16;
  100.   foreg = (avatarcode & (4 | 2 | 1));
  101.   if (avatarcode & 8) {
  102.       strcat(ansi,"0;1;");
  103.   }
  104.   else strcat(ansi,"0;");
  105.  
  106.   sprintf(temp,"%d",av_trans[foreg]);
  107.  
  108.   if (!backg) {
  109.       strcat(ansi,"3");
  110.       strcat(ansi,temp);
  111.   }
  112.   else {
  113.       strcat(ansi,"3");
  114.       strcat(ansi,temp);
  115.       strcat(ansi,";4");
  116.       sprintf(temp,"%d",av_trans[backg]);
  117.       strcat(ansi,temp);
  118.   }
  119.   strcat(ansi,"m");
  120.   return ansi;
  121. }
  122.  
  123.  
  124. char * _fastcall assign (char *d,char *a) {
  125.  
  126.   char *b;
  127.  
  128.  
  129.   if(d) free(d);
  130.   b = strdup(a);
  131.   if(!b) {
  132.     ansi_out("\r\n\04Out of memory\r\n");
  133.     exit(1);
  134.   }
  135.   return b;
  136. }
  137.  
  138.  
  139. char * _fastcall add_backslash (char *d) {
  140.  
  141.   char *t;
  142.  
  143.  
  144.   if(!d) return d;
  145.   t = malloc(strlen(d) + 2);
  146.   if(t) {
  147.     sprintf(t,"%s\\",d);
  148.     free(d);
  149.     return t;
  150.   }
  151.   else {
  152.     ansi_out("\r\n\04Out of memory\r\n");
  153.     exit(1);
  154.   }
  155. }
  156.  
  157.  
  158.  
  159. void _fastcall stat_line (void) {
  160.  
  161.   int oldx,oldy;
  162.  
  163.  
  164.   curr_cursor(&oldx,&oldy);
  165.   dprintf(0,realmaxy - 1,7 * 16," (XBBS) Peeker 2.21 \04 %-58.58s",username);
  166.   time_line();
  167.   cursor(oldx,oldy);
  168. }
  169.  
  170.  
  171. void _fastcall time_line (void) {
  172.  
  173.   dprintf(realmaxx - 11,realmaxy - 1,7 * 16,
  174.     "\04 %3ld mins",((long)timelimit - (getxbbstime() / 60L)));
  175. }
  176.  
  177.  
  178.  
  179. int cdecl dprintf (int x,int y,char attr,char *string,...) {
  180.  
  181.   char buffer[134];
  182.   va_list ap;
  183.  
  184.   va_start(ap,string);
  185.   vsprintf(buffer,string,ap);
  186.   va_end(ap);
  187.  
  188.   return dputs(x,y,attr,buffer);
  189. }
  190.  
  191.  
  192. int _fastcall dputs (int x,int y,char attr,char *string) {
  193.  
  194.   char *b = string;
  195.   int oldx,oldy;
  196.  
  197.   if(b) {
  198.     curr_cursor(&oldx,&oldy);
  199.     while(*b) {
  200.       put_char(*b,attr,x,y);
  201.       b++;
  202.       x++;
  203.     }
  204.     cursor(oldx,oldy);
  205.     return ((int)b - (int)string);
  206.   }
  207.   return -1;
  208. }
  209.