home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / povosk.lzh / osk.c next >
Text File  |  1993-02-01  |  3KB  |  133 lines

  1. /* OSK.c This is where machine specific Graphics routines go */
  2. /*       And any missing LIB functions */
  3.  
  4. #include <stdio.h>
  5. #include "frame.h"
  6.  
  7. extern int errno;
  8.  
  9. #ifndef TRUE
  10. #define TRUE    1
  11. #define FALSE   0
  12. #endif
  13.  
  14. #define STDIN   0
  15. #define STDOUT  1
  16. #define STDERR  2
  17.  
  18. #define fix24(r,g,b) ((r & 0xe0) | ((g & 0xe0) >> 3) | (b >> 6))
  19.  
  20. static int wpath;
  21. static int fx, fy;
  22. static int have_screen = FALSE;
  23.  
  24. void osk_init_pvray ()
  25. {
  26. }
  27.  
  28. void display_finished ()
  29. {
  30.     char ch;
  31. #ifdef KWINDOWS
  32.     if (have_screen) {
  33.         Bell(wpath);
  34.         while(_gs_rdy(wpath) > 0)
  35.             read(wpath,&ch,1);
  36.         read(wpath,&ch,1);
  37.     }
  38. #endif
  39. }
  40.  
  41. void display_init (xsize, ysize)
  42. int xsize, ysize;
  43. {
  44. #ifdef KWINDOWS    
  45.     fx = xsize;
  46.     fy = ysize;
  47.  
  48.     if ((wpath = open("/w",0x03)) == -1) {
  49.         printf("Error #%0.3d - Can't open /w",errno);
  50.         return;
  51.     }
  52.  
  53.     if (DWSet(wpath,3,0,0,40,25,0,0,0) == -1) {
  54.         printf("Error #%0.3d - Can't DWSet /w",errno);
  55.         close(wpath);
  56.         return;
  57.     }
  58.  
  59.     Clear(wpath);
  60.     ScaleSw(wpath,0);
  61.     SetDPtr(wpath,0,0);
  62.     CurOff(wpath);
  63.     Select(wpath);
  64.     
  65.     have_screen = TRUE;
  66. #endif
  67. }
  68.  
  69. void display_close ()
  70. {
  71. #ifdef KWINDOWS
  72.     if (have_screen) {
  73.         Select(STDOUT);
  74.         close(wpath);
  75.     }
  76. #endif
  77. }
  78.  
  79. void display_plot (x, y, Red, Green, Blue)
  80. int x, y;
  81. unsigned char Red, Green, Blue;
  82. {
  83. #ifdef KWINDOWS
  84.     int rx, ry;
  85.  
  86.     if (have_screen) {   
  87.         rx = (fx < 320) ? x : ( x * fx ) / 320;
  88.         ry = (fy < 200) ? y : ( y * fy ) / 200;
  89.  
  90.         FColor(wpath,fix24(Red,Green,Blue));
  91.         RPoint(wpath,rx,ry);
  92.     }
  93. #endif
  94. }
  95.  
  96.  
  97. int stricmp(s,t)
  98. register char *s, *t;
  99. {
  100.     while (toupper(*s) == toupper(*t++)) if (!*s++) return 0;
  101.     return(toupper(s[0]) - toupper(t[-1]));
  102. }
  103.  
  104.  
  105. /* fmod.c - floating point modulus routine by Mike Haaland
  106.  *
  107.  * #: 26583 S1/C Column
  108.  *     12-Nov-90  07:30:29
  109.  * Sb: #26581-fmod() help!
  110.  * Fm: Pete Becker (Borland) 76117,3675
  111.  * To: Mike Haaland 72300,1433
  112.  *
  113.  * Mike,
  114.  *       The % operator is only defined for integers, which is why you need
  115.  * a function to do the floating point analog of it.  If you think about what
  116.  * the modulus is, you shouldn't have much trouble writing a comparable
  117.  * function for floats.  The explanation of fmod() in the TC++ manual says
  118.  * it's "the remainder f, where x = ay + f, for some integer a and 0 <= f <
  119.  * y".  But note that it returns 0 where y is 0. 
  120.  * 
  121.  */
  122.  
  123. double fmod(x,y)
  124. double x, y;
  125. {
  126.     double m;
  127.     if (y == 0.0)
  128.         return (0.0);
  129.     
  130.     m = x - (y * floor(x/y));
  131.     return (m);
  132. }
  133.