home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / msdos / microcrn / issue_34.arc / C34.FIG next >
Encoding:
Text File  |  1987-01-07  |  4.0 KB  |  163 lines

  1.  
  2. (( This is C'ing Figure 1 -- Check For Hercules Card ))
  3.  
  4. #define STATUS 0x3ba
  5.  
  6. herc()       /** courtesy of Hercules Corp. */
  7. {
  8.     char test;
  9.     unsigned i;
  10.  
  11.     test = inb(STATUS) & 0x80;
  12.     for(i=0;i<0x8000;i++) if( (inb(STATUS) & 0x80) != test )  return 1;
  13.             /* it's graphics!! */
  14.     return 0;    /* no retrace bit change, no herc card */
  15. }
  16.  
  17. **********************************************
  18.  
  19. (( This is C'ing Figure 2 -- Getting A Hercules Card In & Out Of 
  20. Graphics Mode ))
  21.  
  22.  
  23. #define INDEX 0x3b4    /* index register for herc adapter */
  24. #define MODE 0x3b8    /* mode control adapter */
  25. #define CONFIG 0x3bf  /* configuration switch */
  26. #define TEXT 0x29     /* text setting for mode control */
  27.   /* This could be 0x28, but 0x29 keeps mono card from self-destructing
  28.       if you accidentally call the wrong video card */
  29. h_tograph()
  30. {
  31.   outb(3,CONFIG);     /* set to full screen buffer=both pages activated */
  32.   outb(CON | 2,MODE); /* set to graphics mode */
  33.   crtout(0,0x35);
  34.   crtout(1,0x2d);
  35.   crtout(2,0x2e);
  36.   crtout(3,0x7);
  37.   crtout(4,0x5b);
  38.   crtout(5,0x2);
  39.   crtout(6,0x57);
  40.   crtout(7,0x57);
  41.   crtout(8,0x2);
  42.   crtout(9,0x3);
  43.   crtout(10,0x0);
  44.   crtout(11,0x0);
  45.   crtout(12,0x0);
  46.   crtout(13,0x0);
  47.   crtout(14,0x0);
  48.   crtout(15,0x0);
  49.   crtout(16,0x0);
  50.   crtout(17,0x0);
  51. }
  52. /************/
  53. h_fromgraph()
  54. {
  55.   outb(CON,MODE);   /* text mode */
  56.   outb(0,CONFIG);   /* cancel paging */
  57.   crtout(0,0x61);
  58.   crtout(1,0x50);
  59.   crtout(2,0x52);
  60.   crtout(3,0xf);
  61.   crtout(4,0x19);
  62.   crtout(5,0x6);
  63.   crtout(6,0x19);
  64.   crtout(7,0x19);
  65.   crtout(8,0x2);
  66.   crtout(9,0xd);
  67.   crtout(10,0xb);
  68.   crtout(11,0xc);
  69.   crtout(12,0x0);
  70.   crtout(13,0x0);
  71.   crtout(14,0x0);
  72.   crtout(15,0x0);
  73.   crtout(16,0x0);
  74.   crtout(17,0x0);
  75. }
  76. /***************/
  77. crtout(reg,val)
  78.   char reg,val;
  79. {
  80.  outw(reg+0x100*val,INDEX);
  81.  
  82. ****************************************************************************
  83.  
  84.  
  85. (( This is C'ing Figure 3 -- Draw Your Own Sine Wave ))
  86.  
  87.  
  88. #include <regs.h> /* for interrupt calling */
  89. #define pi 3.1416
  90. unsigned scrseg;
  91. double x_ratio,y_ratio;
  92. struct regs rr;
  93. char *cptr;
  94.  
  95. main()
  96. {
  97.  unsigned i,j,*intptr,x_count,y_count,mid_x,mid_y,scrsize;
  98.  char *hold;
  99.  
  100.  interrupt(0x11,&rr);   /* use int 11h to find text mode */
  101.  scrseg = ( (rr.ax >> 4) & 3 == 3) ? 0xb000 : 0xb800;
  102.  if( (scrseg == 0xb000) && !herc() ) exit(); /* exit if no graphics */
  103.  if(scrseg==0xb000){
  104.    x_count=720;
  105.    y_count=348;
  106.    scrsize=0x8000;
  107.    }
  108.   else{
  109.    x_count=640;
  110.    y_count=200;
  111.    scrsize=0x4000;
  112.    }
  113.   mid_x = x_count/2;      /* mid screen */
  114.   mid_y = y_count/2;
  115.   y_ratio= 2.6667/y_count;
  116.   x_ratio = 2*pi/x_count; /* one cycle of sine */
  117.   hold=malloc(0x8000);   /* allocate and clear buffer */
  118.   memset(hold,0,0x8000);
  119.   for(i=0,cptr=hold;i<x_count;i++){
  120.     pixel(i,mid_y-sineconv(i-mid_x));  /* origin at  mid screeen */
  121.     pixel(i,mid_y);         /* draw in y-axis */
  122.     }
  123.   for(i=0;i<y_count;i++) pixel(mid_x,i);   /* draw in x-axis */
  124.   if(scrseg==0xb000)  h_tograph(); else c_tograph(); /* to graph mode*/
  125.   poke(scrseg,0,hold,scrsize);  /* send buffer to screen memory */
  126.   getchar();
  127.   if(scrseg==0xb000) h_fromgraph(); else c_fromgraph();
  128.   clr('s');               /* clear screen routine */
  129. }
  130. /*****************/
  131. sineconv(x)
  132.  int x;
  133. {
  134.    double sin();
  135.  
  136.    return  (int) (sin((x)*x_ratio)/y_ratio);
  137. }      /* using a cast to truncate floating point */
  138. /*****************/
  139. pixel(x,y)
  140.  int x,y;
  141. {
  142.  unsigned offset;
  143.  
  144.  offset=(scrseg==0xb000) ? 0x2000*(y&3) + 90*(y>>2) + (x>>3)
  145.     : 0x2000*(y&1) + 80*(y>>1) + (x>>3);
  146.  cptr[offset] |= 0x80 >> (x&7); /* cptr points to base of buffer */
  147. }  /* or-ing pixel position with the graphics screen byte */
  148. /****************/
  149. c_tograph()
  150. {
  151.  rr.ax=6;       /* go to high resolution mode*/
  152.  interrupt(0x10,&rr);
  153. }
  154. /********************/
  155. c_fromgraph()
  156. {
  157.  rr.ax=3;         /* back to text mode */
  158.  interrupt(0x10,&rr);
  159. }
  160. /********************/
  161.  ....AND INCLUDE THE CODE FROM THE OTHER FIGURES
  162.  
  163.