home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / pc_hw / mono / mono.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-08  |  1.2 KB  |  66 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <sys/mono.h>
  5. #include <libc/farptrgs.h>
  6. #include <go32.h>
  7.  
  8. static int initted = 0;
  9.  
  10. #define TOPROW 5*160
  11. #define BOTROW 20*160
  12. #define LIN(r,c) (0xb0000 + (r)*160 + (c)*2)
  13.  
  14. static int ofs=0;
  15.  
  16. void _mono_clear(void)
  17. {
  18.   for (ofs=TOPROW; ofs<BOTROW; ofs += 2)
  19.     _farpokew(_dos_ds, 0xb0000+ofs, 0x0720);
  20.   ofs = TOPROW;
  21.   initted = 1;
  22. }
  23.  
  24. void _mono_putc(int ch)
  25. {
  26.   if (!initted)
  27.     _mono_clear();
  28.   if (ofs >= BOTROW)
  29.   {
  30.     int i;
  31.     for (i=TOPROW; i<BOTROW-160; i+=2)
  32.       _farpokew(_dos_ds, 0xb0000+i, _farpeekw(_dos_ds, 0xb0000+i+160));
  33.     for (; i<BOTROW; i+=2)
  34.       _farpokew(_dos_ds, 0xb0000+i, 0x0720);
  35.     ofs -= 160;
  36.   }
  37.   switch (ch)
  38.   {
  39.   case '\n':
  40.     ofs += 160;
  41.     break;
  42.   case '\r':
  43.     ofs -= ofs % 160;
  44.     break;
  45.   case '\b':
  46.     ofs -= 2;
  47.     break;
  48.   default:
  49.     _farpokew(_dos_ds, 0xb0000+ofs, 0x0700 | (ch & 0xff));
  50.     ofs += 2;
  51.     break;
  52.   }
  53. }
  54.  
  55. void _mono_printf(const char *fmt, ...)
  56. {
  57.   int i;
  58.   char buf[1000];
  59.   va_list a = 0;
  60.   va_start(a, fmt);
  61.   vsprintf(buf, fmt, a);
  62.   for (i=0; buf[i]; i++)
  63.     _mono_putc(buf[i]);
  64.   va_end(a);
  65. }
  66.