home *** CD-ROM | disk | FTP | other *** search
-
- (( This is C'ing Figure 1 -- Check For Hercules Card ))
-
- #define STATUS 0x3ba
-
- herc() /** courtesy of Hercules Corp. */
- {
- char test;
- unsigned i;
-
- test = inb(STATUS) & 0x80;
- for(i=0;i<0x8000;i++) if( (inb(STATUS) & 0x80) != test ) return 1;
- /* it's graphics!! */
- return 0; /* no retrace bit change, no herc card */
- }
-
- **********************************************
-
- (( This is C'ing Figure 2 -- Getting A Hercules Card In & Out Of
- Graphics Mode ))
-
-
- #define INDEX 0x3b4 /* index register for herc adapter */
- #define MODE 0x3b8 /* mode control adapter */
- #define CONFIG 0x3bf /* configuration switch */
- #define TEXT 0x29 /* text setting for mode control */
- /* This could be 0x28, but 0x29 keeps mono card from self-destructing
- if you accidentally call the wrong video card */
- h_tograph()
- {
- outb(3,CONFIG); /* set to full screen buffer=both pages activated */
- outb(CON | 2,MODE); /* set to graphics mode */
- crtout(0,0x35);
- crtout(1,0x2d);
- crtout(2,0x2e);
- crtout(3,0x7);
- crtout(4,0x5b);
- crtout(5,0x2);
- crtout(6,0x57);
- crtout(7,0x57);
- crtout(8,0x2);
- crtout(9,0x3);
- crtout(10,0x0);
- crtout(11,0x0);
- crtout(12,0x0);
- crtout(13,0x0);
- crtout(14,0x0);
- crtout(15,0x0);
- crtout(16,0x0);
- crtout(17,0x0);
- }
- /************/
- h_fromgraph()
- {
- outb(CON,MODE); /* text mode */
- outb(0,CONFIG); /* cancel paging */
- crtout(0,0x61);
- crtout(1,0x50);
- crtout(2,0x52);
- crtout(3,0xf);
- crtout(4,0x19);
- crtout(5,0x6);
- crtout(6,0x19);
- crtout(7,0x19);
- crtout(8,0x2);
- crtout(9,0xd);
- crtout(10,0xb);
- crtout(11,0xc);
- crtout(12,0x0);
- crtout(13,0x0);
- crtout(14,0x0);
- crtout(15,0x0);
- crtout(16,0x0);
- crtout(17,0x0);
- }
- /***************/
- crtout(reg,val)
- char reg,val;
- {
- outw(reg+0x100*val,INDEX);
-
- ****************************************************************************
-
-
- (( This is C'ing Figure 3 -- Draw Your Own Sine Wave ))
-
-
- #include <regs.h> /* for interrupt calling */
- #define pi 3.1416
- unsigned scrseg;
- double x_ratio,y_ratio;
- struct regs rr;
- char *cptr;
-
- main()
- {
- unsigned i,j,*intptr,x_count,y_count,mid_x,mid_y,scrsize;
- char *hold;
-
- interrupt(0x11,&rr); /* use int 11h to find text mode */
- scrseg = ( (rr.ax >> 4) & 3 == 3) ? 0xb000 : 0xb800;
- if( (scrseg == 0xb000) && !herc() ) exit(); /* exit if no graphics */
- if(scrseg==0xb000){
- x_count=720;
- y_count=348;
- scrsize=0x8000;
- }
- else{
- x_count=640;
- y_count=200;
- scrsize=0x4000;
- }
- mid_x = x_count/2; /* mid screen */
- mid_y = y_count/2;
- y_ratio= 2.6667/y_count;
- x_ratio = 2*pi/x_count; /* one cycle of sine */
- hold=malloc(0x8000); /* allocate and clear buffer */
- memset(hold,0,0x8000);
- for(i=0,cptr=hold;i<x_count;i++){
- pixel(i,mid_y-sineconv(i-mid_x)); /* origin at mid screeen */
- pixel(i,mid_y); /* draw in y-axis */
- }
- for(i=0;i<y_count;i++) pixel(mid_x,i); /* draw in x-axis */
- if(scrseg==0xb000) h_tograph(); else c_tograph(); /* to graph mode*/
- poke(scrseg,0,hold,scrsize); /* send buffer to screen memory */
- getchar();
- if(scrseg==0xb000) h_fromgraph(); else c_fromgraph();
- clr('s'); /* clear screen routine */
- }
- /*****************/
- sineconv(x)
- int x;
- {
- double sin();
-
- return (int) (sin((x)*x_ratio)/y_ratio);
- } /* using a cast to truncate floating point */
- /*****************/
- pixel(x,y)
- int x,y;
- {
- unsigned offset;
-
- offset=(scrseg==0xb000) ? 0x2000*(y&3) + 90*(y>>2) + (x>>3)
- : 0x2000*(y&1) + 80*(y>>1) + (x>>3);
- cptr[offset] |= 0x80 >> (x&7); /* cptr points to base of buffer */
- } /* or-ing pixel position with the graphics screen byte */
- /****************/
- c_tograph()
- {
- rr.ax=6; /* go to high resolution mode*/
- interrupt(0x10,&rr);
- }
- /********************/
- c_fromgraph()
- {
- rr.ax=3; /* back to text mode */
- interrupt(0x10,&rr);
- }
- /********************/
- ....AND INCLUDE THE CODE FROM THE OTHER FIGURES
-