home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / NETWORK / TEL23SRC.ZIP / RG / RG9.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-25  |  6.5 KB  |  338 lines

  1. /*
  2. *
  3. *  rg9.c by Aaron Contorer for NCSA
  4. *
  5. *  graphics routines for drawing on Number Nine card
  6. *  Input coordinate space = 0..4095 by 0..4095
  7. *  MUST BE COMPILED WITH LARGE MEMORY MODEL!
  8. *  RG9 = routines callable from outside
  9. *  NO9 = routines for internal use only
  10. *
  11. */
  12.  
  13. #include <stdio.h>    /* used for debugging only */
  14. #include <stdlib.h>
  15. #include <dos.h>    /* used for NO9 init call */
  16. #if defined(MSC) && !defined(__TURBOC__)
  17. #include <memory.h>
  18. #endif
  19. #ifdef MEMORY_DEBUG
  20. #include "memdebug.h"
  21. #endif
  22. #include "externs.h"
  23.  
  24. #define TRUE 1
  25. #define FALSE 0
  26. #define INXMAX 4096
  27. #define INXSHIFT 12
  28. #define INYMAX 4096
  29. #define INYSHIFT 12
  30. #define MAGNIFY 1000
  31. #define SCRNXHI 511
  32. #define SCRNYHI 479
  33. #define MAXWIN 32        /* max. number of windows */
  34. #define NO9xmax 512     /* max. number of pixels in the x direction */
  35. #define NO9ymax 480        /* max. number of pixels in the y direction */
  36.  
  37. static int NO9active;        /* number of currently NO9active window */
  38. static char *NO9ram;
  39. static int *NO9bank;         /* bank control registers */
  40. static unsigned char power2[8]={1,2,4,8,16,32,64,128};
  41. static char *NO9name="Number Nine, 512 x 480";
  42. static void clrbuf(unsigned int bank);
  43.  
  44. /* Current status of an NO9 window */
  45. struct NO9WIN 
  46. {
  47.     char inuse;                             /* true if window in use */
  48.     int pencolor, rotation, size;
  49.     int winbot,winleft,wintall,winwide;        /* position of the window in virtual space */
  50. };
  51.  
  52. static struct NO9WIN NO9win[MAXWIN];
  53.  
  54. void NO9setup()            /* prepare variables for use in other functions */
  55. {
  56. #if defined(MSC) && !defined(__TURBOC__)
  57.     FP_SEG(NO9ram) = 0xA000;  FP_OFF(NO9ram) = 0;
  58.     FP_SEG(NO9bank) = 0xC070;  FP_OFF(NO9bank) = 5;
  59. #else
  60.     NO9ram=(char *)0xA0000;
  61.     NO9bank=(int *)0xC0705;
  62. #endif
  63. }
  64.  
  65. static void clrbuf(bank)
  66. unsigned int bank;
  67. {
  68.     *NO9bank=bank;
  69.     memset(NO9ram,0,0xFFFF);
  70.     NO9ram[0xFFFF]=0;
  71. }
  72.  
  73. void RG9gmode()            /* go into NO9 graphics mode -- not yet implemented */
  74. {
  75.     clrbuf(0x0000);
  76.     clrbuf(0x00ff);
  77.     clrbuf(0xff00);
  78.     clrbuf(0xffff);
  79. }
  80.  
  81. void RG9tmode()            /* go into NO9 text mode -- not supported */
  82. { }
  83.  
  84. void RG9drawline(w,x0,y0,x1,y1)
  85. int w,x0,y0,x1,y1;        /* draw a line from (x0,y0) to (x1,y1) */
  86.                         /* uses Bresenham's Line Algorithm */
  87. {
  88.     int x,y,dx,dy,d,temp,
  89.     dx2,dy2,            /* 2dx and 2dy */
  90.     direction;        /* +1 or -1, used for slope */
  91.     char transpose;    /* true if switching x and y for vertical-ish line */
  92.  
  93.     if(w!=NO9active) 
  94.         return;
  95.     x0=(int)(((long)x0*NO9xmax)>>INXSHIFT);
  96.     y0=NO9ymax-1-(int)(((long)y0*NO9ymax)>>INYSHIFT);
  97.     x1=(int)(((long)x1*NO9xmax)>>INXSHIFT);
  98.     y1=NO9ymax-1-(int)(((long)y1*NO9ymax)>>INYSHIFT);
  99.     if(abs(y1-y0)>abs(x1-x0)) {                /* transpose vertical-ish to horizontal-ish */
  100.         temp=x1;
  101.         x1=y1; 
  102.         y1=temp;
  103.         temp=x0; 
  104.         x0=y0;     
  105.         y0=temp;
  106.         transpose=TRUE;
  107.       } 
  108.     else 
  109.         transpose=FALSE;                
  110.     if(x1<x0){                        /* make sure line is left to right */
  111.         temp=x1; 
  112.         x1=x0; 
  113.         x0=temp; 
  114.         temp=y1; 
  115.         y1=y0; 
  116.         y0=temp;
  117.       }        
  118. /* SPECIAL CASE: 1 POINT */
  119.     if(x1==x0&&y1==y0) { 
  120.         NO9point(x1,y1);
  121.         return;
  122.       }        
  123. /* ANY LINE > 1 POINT */
  124.     x=x0;
  125.     y=y0;
  126.     dx=x1-x0;
  127.     if(y1>=y0) {
  128.         dy=y1-y0;
  129.         direction=1;
  130.       } 
  131.     else {
  132.         dy=y0-y1;
  133.         direction=-1;
  134.       }
  135.     dx2=dx<<1;
  136.     dy2=dy<<1;
  137.     d=(dy<<1)-dx;
  138.     if(transpose) {        /* CASE OF VERTICALISH (TRANSPOSED) LINES */
  139.         while(x<=x1) {
  140.             if(y>=0&&y<NO9xmax&&x>=0&&x<NO9ymax)
  141.                 NO9point(y,x);
  142.             while(d>=0) {
  143.                 y+=direction;
  144.                 d-=dx2;
  145.               }
  146.             d+=dy2;
  147.             x++;
  148.           } 
  149.       } 
  150.     else {            /* CASE OF HORIZONTALISH LINES */
  151.         while(x<=x1) {
  152.             if(x>=0&&x<NO9xmax&&y>=0&&y<NO9ymax)
  153.                 NO9point(x,y);
  154.             while(d>=0) {
  155.                 y+=direction;
  156.                 d-=dx2;
  157.               }
  158.             d+=dy2;
  159.             x++;
  160.           }
  161.       }                 /* end horizontalish */
  162. }                     /* end NO9rasline() */
  163.  
  164. void RG9clrscr(w)
  165. int w;
  166. /* 
  167.     Clear the screen.
  168. */
  169. {
  170.     if(w==NO9active) {
  171.         NO9setup();
  172.         RG9gmode();
  173.       }
  174. }
  175.  
  176. int RG9newwin()
  177. /* 
  178.     Set up a new window; return its number.
  179.     Returns -1 if cannot create window.
  180. */
  181. {
  182.     int w=0;
  183.  
  184.     while(w<MAXWIN && NO9win[w].inuse) 
  185.         w++;
  186.     if(w==MAXWIN) 
  187.         return(-1);             /* no windows available */
  188.     NO9win[w].pencolor=7;
  189.     NO9win[w].winbot=0;
  190.     NO9win[w].wintall=3120;
  191.     NO9win[w].winleft=0;
  192.     NO9win[w].winwide=4096;
  193.     NO9win[w].inuse=TRUE;
  194.     return(w);
  195. }
  196.  
  197. void RG9close(w)
  198. int w;
  199. {
  200.     if(NO9active==w) {
  201.         RG9clrscr(w);
  202.         NO9active=-1;
  203.       }
  204.     NO9win[w].inuse=FALSE;
  205. }
  206.  
  207. void NO9point(x,y)
  208. int x,y;
  209. /*
  210.     set point at real pixel x,y
  211. */
  212. {
  213.     unsigned int bank,loc;
  214.  
  215.     y+=16;                     /* map 480 lines onto 512 lines */
  216.     if(y&256) 
  217.         bank=0xff00;
  218.     else
  219.          bank=0;
  220.     if(y&128)
  221.         bank|=0x00ff;
  222.     *NO9bank=bank;        
  223.     loc=((y&0x7f)<<9)+x;
  224.     NO9ram[loc]=255;         /* only drawing in color 255 */
  225. }
  226.  
  227. void RG9point(w,x,y)
  228. int w,x,y;
  229. /* set pixel at location (x,y) -- no range checking performed */
  230. {
  231.     int x2,y2;                 /* on-screen coordinates */
  232.  
  233.     if(w==NO9active) {
  234.         x2=(int)(((long)x*NO9xmax)>>INXSHIFT);
  235.         y2=SCRNYHI-(int)(((long)y*NO9ymax)>>INYSHIFT);
  236.         NO9point(x2,y2);
  237.       }
  238. }  
  239.  
  240. void RG9pagedone(w)
  241. int w;
  242. /*
  243.     Do whatever has to be done when the drawing is all done.
  244.     (For printers, that means eject page.)
  245. */
  246. {
  247.     /* do nothing for NO9 */
  248.     w=w;
  249. }
  250.  
  251. void RG9dataline(w,data,count)
  252. int w,count;
  253. char *data;
  254. /*
  255.     Copy 'count' bytes of data to screen starting at current
  256.     cursor location.
  257. */
  258. {
  259.     /* Function not supported yet. */
  260.     w=w;
  261.     data=data;
  262.     count=count;
  263. }
  264.  
  265. void RG9pencolor(w,color)
  266. int w,color;
  267. /*
  268.     Change pen color to the specified color.
  269. */
  270. {
  271.     /* Function not supported yet. */
  272.     w=w;
  273.     color=color;
  274. }
  275.  
  276. void RG9charmode(int w,int rotation,int size)
  277. /*
  278.     Set description of future device-supported graphtext.
  279.     Rotation=quadrant.
  280. */
  281. {
  282.     /* No rotatable device-supported graphtext is available on NO9. */
  283.     w=w;
  284.     rotation=rotation;
  285.     size=size;
  286. }
  287.  
  288.  
  289. /* Not yet supported: */
  290. void RG9showcur() {}
  291. void RG9lockcur() {}
  292. void RG9hidecur() {}
  293.  
  294. void RG9bell(w)
  295. int w;        /* Ring bell in window w */
  296. {
  297.     if(w==NO9active) 
  298.         putchar(7);
  299. }
  300.  
  301. char *RG9devname()        /* return name of device that this RG supports */
  302. {
  303.     return(NO9name);
  304. }
  305.  
  306. void RG9init()                /* initialize all RG9 variables */
  307. {
  308.     int i;
  309.     NO9setup();
  310.     for(i=0; i<MAXWIN; i++) {
  311.         NO9win[i].inuse=FALSE;
  312.       }
  313.     NO9active=-1;
  314. }
  315.  
  316. void RG9uncover(w)
  317. int w;
  318. /*
  319.     Make this window visible, hiding all others.
  320.     Caller should follow this with clrscr and redraw to show the current
  321.     contents of the window.
  322. */
  323. {
  324.     NO9active=w;
  325. }
  326.  
  327. void RG9info(int w,int a,int b,int c,int d,int v) {
  328. /* Needed for possible future functionality */
  329.  
  330.     w=w;
  331.     a=a;
  332.     b=b;
  333.     c=c;
  334.     d=d;
  335.     v=v;
  336.     }
  337.