home *** CD-ROM | disk | FTP | other *** search
- 10 #include <stdio.h>
- 20 #include <conio.h>
- 30 #include <dos.h>
- 40 #include <h_graph2.h>
- 50 #include <mouse.h>
- 60
- 70 int m_init(buttons)
- 80 int *buttons;
- 90 {
- 100 union REGS reg;
- 110 reg.x.ax=0;
- 120 int86(0x33,®,®);
- 130 *buttons=reg.x.bx;
- 140 return(reg.x.ax);
- 150 }
- 160
- 170 void m_cursor(on)
- 180 int on;
- 190 {
- 200 union REGS reg;
- 210 reg.x.ax=((on)?1:2);
- 220 int86(0x33,®,®);
- 230 }
- 240
- 250 int m_status(hpos,vpos)
- 260 int *hpos,*vpos;
- 270 {
- 280 union REGS regs;
- 290 regs.x.ax=3 ;
- 300 int86(0x33,®s,®s);
- 310 *hpos=regs.x.cx;
- 320 *vpos=regs.x.dx;
- 330 return regs.x.bx;
- 340 }
- 350
- 360 void m_move(hpos,vpos)
- 370 int hpos,vpos;
- 380 {
- 390 union REGS regs;
- 400 regs.x.ax=4;
- 410 regs.x.cx=hpos;
- 420 regs.x.dx=vpos;
- 430 int86(0x33,®s,®s);
- 440 }
- 450
- 460 void m_limit(hmin,vmin,hmax,vmax)
- 470 int hmin,hmax,vmin,vmax;
- 480 {
- 490 union REGS regs;
- 500 regs.x.ax=7;
- 510 regs.x.cx=hmin;
- 520 regs.x.dx=hmax;
- 530 int86(0x33,®s,®s);
- 540 regs.x.ax=8;
- 550 regs.x.cx=vmin;
- 560 regs.x.dx=vmax;
- 570 int86(0x33,®s,®s);
- 580 }
- 590
- 600 void m_shape(seg,offset)
- 610 int seg,*offset;
- 620 {
- 630 union REGS regs;
- 640 struct SREGS sregs;
- 650 regs.x.ax=9;
- 660 regs.x.bx=*(offset+32); /* horiz HOTSPOT in cursor mask */
- 670 regs.x.cx=*(offset+33); /* vert HOTSPOT in cursor mask */
- 680 regs.x.dx=offset; /* first 16 ints are the AND mask */
- 690 sregs.es=seg; /* next 16 ints are the XOR mask */
- 700 int86x(0x33,®s,®s,&sregs);
- 710 }
- 720
- 730
- 740 int h_isherc()
- 750 {
- 760 union REGS reg;
- 770 char save_byte;
- 780 extern char far *h_p;
- 790 reg.h.ah=15;
- 800 int86(16,®,®);
- 810 if(reg.h.al!=7) return(-1);
- 820 save_byte=*(h_p+65535);
- 830 h_p=H_MEMLOC;
- 840 *(h_p+65535)=170;
- 850 if(*(h_p+65535)!=170) return(1);
- 860 *(h_p+65535)=85;
- 870 if(*(h_p+65535)!=85) return(1);
- 880 *(h_p+65535)=save_byte;
- 890 return(0);
- 900 }
- 910
- 920 int h_init(mode)
- 930 int mode;
- 940 {
- 950 extern int h_vpage,h_apage,h_xpos,h_ypos;
- 960 extern int h_pmode,h_vmode,h_color,h_start;
- 970 extern int h_xmax,h_xmin,h_ymax,h_ymin;
- 980 extern char far *h_p;
- 990 static char text[]={97,80,82,15,25,6,25,25,2,13,11,12,0,0,0,0};
- 1000 static char graph[]={53,45,46,7,91,2,87,87,2,3,0,0,0,0,0,0};
- 1010 char *ptr;
- 1020 unsigned i;
- 1030 union REGS reg;
- 1040 outp(MODEPORT,((h_vmode==99)?2:0));
- 1050 ptr=((mode==99)?graph:text);
- 1060 reg.h.ah=0;
- 1070 reg.h.al=((mode==99)?6:7);
- 1080 int86(0x10,®,®);
- 1090 outp(MODEPORT,((mode==99)?2:0));
- 1100 for(i=0;i<16;i++)
- 1110 {
- 1120 outp(ADDRPORT,i);
- 1130 outp(DATAPORT,*(ptr+i));
- 1140 }
- 1150 h_vpage=h_apage=h_xmin=h_ymin=h_ypos=h_xpos=h_pmode=h_start=0;
- 1160 h_vmode=((mode==99)?99:7);
- 1170 h_xmax=719;
- 1180 h_ymax=347;
- 1190 if(mode==99)
- 1200 {
- 1210 h_mempse(h_p,0,65535);
- 1220 }
- 1230 h_color=1;
- 1240 outp(MODEPORT,((mode==99)?10:8));
- 1250 return(h_vmode);
- 1260 }
- 1270
- 1280
- 1290 int h_setvpage(page)
- 1300 int page;
- 1310 {
- 1320 extern int h_vpage;
- 1330 extern int h_vmode;
- 1340 int old_page;
- 1350 if(h_vmode==99)
- 1360 {
- 1370 outp(MODEPORT,10+((page==1)?128:0));
- 1380 }
- 1390 old_page=h_vpage;
- 1400 h_vpage=page;
- 1410 return(old_page);
- 1420 }
- 1430
- 1440
- 1450 void h_onoff(on)
- 1460 int on;
- 1470 {
- 1480 extern int h_vmode;
- 1490 extern int h_vpage;
- 1500 outp(MODEPORT,((on)?8:0)+((h_vpage==1)?128:0)+((h_vmode==99)?2:0));
- 1510 }
- 1520
- 1530 void h_drawc(letter,alf_ptr)
- 1540 char letter;
- 1550 char *alf_ptr;
- 1560 {
- 1570 extern int h_xpos;
- 1580 extern int h_ypos;
- 1590 extern int h_xmin;
- 1600 extern int h_ymin;
- 1610 extern int h_xmax;
- 1620 extern int h_ymax;
- 1630 extern int h_pmode;
- 1640 extern int h_color;
- 1650 extern char far *h_p;
- 1660 int delta_x,delta_y,height,width,start,stop;
- 1670 int i,offset,byte_loc,x1,y1,start_loc,stop_loc,edge_loc;
- 1680 char andmask1,andmask2,this_byte,last_bit;
- 1690 delta_y=(int)(*alf_ptr);
- 1700 delta_x=(int)(*(alf_ptr+1));
- 1710 if(delta_y & 128) delta_y=(delta_y & ~128)*-1;
- 1720 if(delta_x & 128) delta_x=(delta_x & ~128)*-1;
- 1730 height=(int)*(alf_ptr+2);
- 1740 width=(int)*(alf_ptr+3);
- 1750 start=(int)*(alf_ptr+4);
- 1760 stop=(int)*(alf_ptr+5);
- 1770 if(h_xpos+width<h_xmin || h_xpos>=h_xmax || h_ypos+height<h_ymin || h_ypos>h_ymax)
- 1780 {
- 1790 h_xpos+=(int)delta_x;
- 1800 h_ypos+=(int)delta_y;
- 1810 return;
- 1820 }
- 1830 else
- 1840 {
- 1850 offset=h_xpos & 7;
- 1860 andmask1=(char)(255<<(8-offset));
- 1870 andmask2=255>>(offset+((width==8)?0:1));
- 1880 if(h_xpos>=h_xmin && h_xpos+width<=h_xmax);
- 1890 else
- 1900 {
- 1910 if(h_xpos<=h_xmax-width)
- 1920 {
- 1930 start_loc=((h_xpos+16)>>3)-2;
- 1940 edge_loc=h_xmin>>3;
- 1950 if(start_loc==edge_loc)
- 1960 {
- 1970 andmask1|=(char)(255<<(8-(h_xmin & 7)));
- 1980 }
- 1990 else
- 2000 {
- 2010 andmask1=255;
- 2020 andmask2|=(char)(255<<(8-(h_xmin & 7)));
- 2030 }
- 2040 }
- 2050 else
- 2060 {
- 2070 stop_loc=(h_xpos+8)>>3;
- 2080 edge_loc=h_xmax>>3;
- 2090 if(stop_loc==edge_loc)
- 2100 {
- 2110 andmask2|=255>>(h_xmax & 7);
- 2120 }
- 2130 else
- 2140 {
- 2150 andmask2=255;
- 2160 andmask1|=255>>(h_xmax & 7);
- 2170 }
- 2180 }
- 2190 }
- 2200 }
- 2210 h_p=H_MEMLOC;
- 2220 x1=h_xpos;
- 2230 switch(h_pmode)
- 2240 {
- 2250 case H_PSET:
- 2260 for(i=0;i<height;i++)
- 2270 {
- 2280 this_byte=*(alf_ptr+6+((int)(letter)*14)+i);
- 2290 last_bit=0;
- 2300 y1=h_ypos+i;
- 2310 if(y1>=h_ymin && y1<h_ymax)
- 2320 {
- 2330 byte_loc=H_FORMULA;
- 2340 *(h_p+byte_loc)=(*(h_p+byte_loc) & andmask1) | (char)((this_byte>>offset));
- 2350 if(width==9)
- 2360 {
- 2370 if(letter>start && letter<stop)
- 2380 {
- 2390 last_bit=this_byte & 1;
- 2400 }
- 2410 *(h_p+ ++byte_loc)=(*(h_p+byte_loc) & andmask2) | ((char)(this_byte<<(8-offset))) | ((char)(last_bit<<(7-offset)));
- 2420 }
- 2430 else
- 2440 {
- 2450 *(h_p+ ++byte_loc)=(*(h_p+byte_loc) & andmask2) | ((char)(this_byte<<(8-offset)));
- 2460 }
- 2470 }
- 2480 }
- 2490 break;
- 2500 case H_OR:
- 2510 for(i=0;i<height;i++)
- 2520 {
- 2530 this_byte=*(alf_ptr+6+((int)(letter)*14)+i);
- 2540 last_bit=0;
- 2550 y1=h_ypos+i;
- 2560 if(y1>=h_ymin && y1<h_ymax)
- 2570 {
- 2580 byte_loc=H_FORMULA;
- 2590 *(h_p+byte_loc)=*(h_p+byte_loc) | (char)((this_byte>>offset));
- 2600 if(width==9)
- 2610 {
- 2620 if(letter>start && letter<stop)
- 2630 {
- 2640 last_bit=this_byte & 1;
- 2650 }
- 2660 *(h_p+ ++byte_loc)=*(h_p+byte_loc) | ((char)(this_byte<<(8-offset))) | ((char)(last_bit<<(7-offset)));
- 2670 }
- 2680 else
- 2690 {
- 2700 *(h_p+ ++byte_loc)=*(h_p+byte_loc) | ((char)(this_byte<<(8-offset)));
- 2710 }
- 2720 }
- 2730 }
- 2740 break;
- 2750 case H_XOR:
- 2760 for(i=0;i<height;i++)
- 2770 {
- 2780 this_byte=*(alf_ptr+6+((int)(letter)*14)+i);
- 2790 last_bit=0;
- 2800 y1=h_ypos+i;
- 2810 if(y1>=h_ymin && y1<h_ymax)
- 2820 {
- 2830 byte_loc=H_FORMULA;
- 2840 *(h_p+byte_loc)=*(h_p+byte_loc) ^ (char)((this_byte>>offset));
- 2850 if(width==9)
- 2860 {
- 2870 if(letter>start && letter<stop)
- 2880 {
- 2890 last_bit=this_byte & 1;
- 2900 }
- 2910 *(h_p+ ++byte_loc)=*(h_p+byte_loc) ^ ((char)(this_byte<<(8-offset))) | ((char)(last_bit<<(7-offset)));
- 2920 }
- 2930 else
- 2940 {
- 2950 *(h_p+ ++byte_loc)=*(h_p+byte_loc) ^ ((char)(this_byte<<(8-offset)));
- 2960 }
- 2970 }
- 2980 }
- 2990 break;
- 3000 }
- 3010 h_xpos+=(int)delta_x;
- 3020 h_ypos+=(int)delta_y;
- 3030 }
- 3040
- 3050 int h_loadfont(fname,alphaptr)
- 3060 char *fname;
- 3070 char *alphaptr;
- 3080 {
- 3090 FILE *fptr;
- 3100 char *alpha;
- 3110 fptr=fopen(fname,"rb");
- 3120 if(fptr==0) return(-1);
- 3130 fread(alphaptr,1,3590,fptr);
- 3140 fclose(fptr);
- 3150 return(0);
- 3160 }
- 3170
- 3180 void h_boxfill(x2,y2,tile)
- 3190 int x2,y2;
- 3200 char *tile;
- 3210 {
- 3220 extern int h_xmin,h_xmax,h_ymin,h_ymax,h_pmode,h_xpos,h_ypos;
- 3230 extern char far *h_p;
- 3240 int i,x1,y1,byte_loc,whole_bytes;
- 3250 char save_byte,andmask1,andmask2,temp_byte;
- 3260 h_p=H_MEMLOC;
- 3270 if(h_xpos>h_xmax || h_ypos>h_ymax || x2<h_xmin || y2<h_ymin) return;
- 3280 x1=((h_xpos>h_xmin)?h_xpos:h_xmin);
- 3290 x2=((x2<h_xmax)?x2++:h_xmax);
- 3300 y1=((h_ypos>h_ymin)?h_ypos:h_ymin);
- 3310 y2=((y2<h_ymax)?y2:h_ymax);
- 3320 andmask1=(char)(255<<(8-(x1 & 7)));
- 3330 andmask2=(char)(255>>((x2 & 7)+1));
- 3340 whole_bytes=((x2>>3)-(x1>>3))-1;
- 3350 switch(h_pmode)
- 3360 {
- 3370 case H_PSET:
- 3380 for(;y1<=y2;y1++)
- 3390 {
- 3400 save_byte=*(tile+(y1 & 7));
- 3410 byte_loc=H_FORMULA;
- 3420 if(whole_bytes>=0)
- 3430 {
- 3440 *(h_p+byte_loc)=(*(h_p+byte_loc) & andmask1) | (save_byte & (~andmask1));
- 3450 if(whole_bytes)
- 3460 {
- 3470 h_mempse((h_p+byte_loc+1),save_byte,whole_bytes);
- 3480 byte_loc+=whole_bytes;
- 3490 }
- 3500 *(h_p+ ++byte_loc)=(*(h_p+byte_loc) & andmask2) | (save_byte & (~andmask2));
- 3510 }
- 3520 else
- 3530 {
- 3540 *(h_p+byte_loc)=(*(h_p+byte_loc) & (andmask1 ^ andmask2)) | (save_byte & ~andmask1 & ~andmask2);
- 3550 }
- 3560 }
- 3570 break;
- 3580 case H_OR:
- 3590 for(;y1<=y2;y1++)
- 3600 {
- 3610 save_byte=*(tile+(y1 & 7));
- 3620 byte_loc=H_FORMULA;
- 3630 if(whole_bytes>=0)
- 3640 {
- 3650 *(h_p+byte_loc)|=save_byte & (~andmask1);
- 3660 if(whole_bytes)
- 3670 {
- 3680 h_memor(h_p+byte_loc+1,save_byte,whole_bytes);
- 3690 byte_loc+=whole_bytes;
- 3700 }
- 3710 *(h_p+ ++byte_loc)|=save_byte & (~andmask2);
- 3720 }
- 3730 else
- 3740 {
- 3750 *(h_p+byte_loc)|=save_byte & ~andmask1 & ~andmask2;
- 3760 }
- 3770 }
- 3780 break;
- 3790 case H_AND:
- 3800 for(;y1<=y2;y1++)
- 3810 {
- 3820 save_byte=*(tile+(y1 & 7));
- 3830 byte_loc=H_FORMULA;
- 3840 if(whole_bytes>=0)
- 3850 {
- 3860 temp_byte=andmask1 | (save_byte & (~andmask1));
- 3870 *(h_p+byte_loc)&=temp_byte;
- 3880 if(whole_bytes)
- 3890 {
- 3900 h_memand(h_p+byte_loc+1,save_byte,whole_bytes);
- 3910 byte_loc+=whole_bytes;
- 3920 }
- 3930 temp_byte=andmask2 | (save_byte & (~andmask2));
- 3940 *(h_p+ ++byte_loc)&=temp_byte;
- 3950 }
- 3960 else
- 3970 {
- 3980 *(h_p+byte_loc)&=save_byte & ~andmask1 & ~andmask2;
- 3990 }
- 4000 }
- 4010 break;
- 4020 case H_XOR:
- 4030 for(;y1<=y2;y1++)
- 4040 {
- 4050 save_byte=*(tile+(y1 & 7));
- 4060 byte_loc=H_FORMULA;
- 4070 if(whole_bytes>=0)
- 4080 {
- 4090 *(h_p+byte_loc)^=save_byte & (~andmask1);
- 4100 if(whole_bytes)
- 4110 {
- 4120 h_memxor(h_p+byte_loc+1,save_byte,whole_bytes);
- 4130 byte_loc+=whole_bytes;
- 4140 }
- 4150 *(h_p+ ++byte_loc)^=save_byte & (~andmask2);
- 4160 }
- 4170 else
- 4180 {
- 4190 *(h_p+byte_loc)^=save_byte & ~andmask1 & ~andmask2;
- 4200 }
- 4210 }
- 4220 break;
- 4230 }
- 4240 }
- 4250
- 4260 int h_moveto(x1,y1)
- 4270 int x1,y1;
- 4280 {
- 4290 extern int h_xmin,h_xmax,h_ymin,h_ymax,h_xpos,h_ypos;
- 4300 h_xpos=x1;
- 4310 h_ypos=y1;
- 4320 if(x1<=h_xmax && x1>=h_xmin && y1>=h_ymin && y1<=h_ymax) return 0;
- 4330 else return 1;
- 4340 }
- 4350
- 4360 void h_box(x2,y2,tile)
- 4370 int x2,y2;
- 4380 char *tile;
- 4390 {
- 4400 int x1,y1;
- 4410 extern int h_xpos,h_ypos;
- 4420 x1=h_xpos;
- 4430 y1=h_ypos;
- 4440 h_moveto(x1,y1);
- 4450 h_boxfill(x2,y1,tile);
- 4460 h_moveto(x2,y1);
- 4470 h_boxfill(x2,y2,tile);
- 4480 h_moveto(x1,y2);
- 4490 h_boxfill(x2,y2,tile);
- 4500 h_moveto(x1,y1);
- 4510 h_boxfill(x1,y2,tile);
- 4520 }
- 4530
- 4540 int h_setpmode(newpmode)
- 4550 int newpmode;
- 4560 {
- 4570 int savemode;
- 4580 extern int h_pmode;
- 4590 savemode=h_pmode;
- 4600 h_pmode=newpmode;
- 4610 return savemode;
- 4620 }
- 4630
- 4640 void h_clrw(tile)
- 4650 char *tile;
- 4660 {
- 4670 int savex,savey,savepmode;
- 4680 extern int h_xpos,h_ypos,h_pmode;
- 4690 savepmode=h_pmode;
- 4700 savex=h_xpos;
- 4710 savey=h_ypos;
- 4720 h_moveto(0,0);
- 4730 h_setpmode(H_PSET);
- 4740 h_boxfill(719,347,tile);
- 4750 h_setpmode(savepmode);
- 4760 h_moveto(savex,savey);
- 4770 }
- 4780
- 4790 void h_explode(tile)
- 4800 char *tile;
- 4810 {
- 4820 double i;
- 4830 int halfx,halfy,totalx,totaly;
- 4840 extern int h_xmin,h_xmax,h_ymin,h_ymax;
- 4850 halfx=h_xmin+((h_xmax-h_xmin)>>1);
- 4860 halfy=h_ymin+((h_ymax-h_ymin)>>1);
- 4870 totalx=h_xmax-h_xmin;
- 4880 totaly=h_ymax-h_ymin;
- 4890 for(i=.01;i<1.01;i+=.025)
- 4900 {
- 4910 h_moveto((int)(halfx-(totalx*i)/2),(int)(halfy-(totaly*i)/2));
- 4920 h_boxfill((int)(halfx+(totalx*i)/2),(int)(halfy+(totaly*i)/2),tile);
- 4930 }
- 4940 h_clrw(tile);
- 4950 }
- 4960
- 4970 void h_draws(string,alphabet)
- 4980 char *string;
- 4990 char *alphabet;
- 5000 {
- 5010 int length,i;
- 5020 length=strlen(string);
- 5030 for(i=0;i<length;i++)
- 5040 {
- 5050 h_drawc(*(string+i),alphabet);
- 5060 }
- 5070 }
- 5080
- 5090 void h_patterns()
- 5100 {
- 5110 extern char lgrey[],dgrey[],fore[],back[],nlines[],nstripes[],nrhatch[];
- 5120 extern char nlhatch[],wlines[],wstripes[],wrhatch[],wlhatch[];
- 5130 h_boxfill(179,115,fore);
- 5140 h_moveto(180,0);
- 5150 h_boxfill(359,115,lgrey);
- 5160 h_moveto(360,0);
- 5170 h_boxfill(539,115,nlines);
- 5180 h_moveto(540,0);
- 5190 h_boxfill(719,115,nstripes);
- 5200 h_moveto(0,116);
- 5210 h_boxfill(179,231,nrhatch);
- 5220 h_moveto(180,116);
- 5230 h_boxfill(359,231,nlhatch);
- 5240 h_moveto(360,116);
- 5250 h_boxfill(539,231,wlines);
- 5260 h_moveto(540,116);
- 5270 h_boxfill(719,231,wstripes);
- 5280 h_moveto(0,232);
- 5290 h_boxfill(179,347,wrhatch);
- 5300 h_moveto(180,232);
- 5310 h_boxfill(359,347,wlhatch);
- 5320 h_moveto(360,232);
- 5330 h_boxfill(539,347,dgrey);
- 5340 h_moveto(540,232);
- 5350 h_boxfill(719,347,wrhatch);
- 5360 h_setpmode(H_OR);
- 5370 h_boxfill(719,347,wlhatch);
- 5380 h_setpmode(H_PSET);
- 5390 }
- 5400 20
- 5410
- 5420
- 5430
- 5440