#include	<stdio.h>
#include	<math.h>
#include	<dos.h>

struct FIXED {
	unsigned	major,minor;
};

struct OVALSECTOR {
	unsigned	type;
	int		cx,cy,dx,nul1,nul2,dy;
	struct FIXED	strd,edrd;
	unsigned char	sctrmode,reserve;
};

extern	unsigned	char	gds_fshift;
extern	unsigned	gds_wrkoff;
extern	unsigned	gds_wrkseg;

int	g_oval_sector(int x,int y,int rx,int ry,double start,double end)
{
	union REGS	reg;
	struct SREGS	seg;
	double	iwork,fwork;
	struct {
		unsigned	len;
		struct OVALSECTOR	sctr;
	}	gdata;

	segread(&seg);
	reg.h.ah=gds_fshift+0x0f;
	reg.x.di=(unsigned)&gdata;
	seg.ds=seg.ss;
	gdata.len=24;
	gdata.sctr.type=0x4276;
	gdata.sctr.cx=x;
	gdata.sctr.cy=y;
	gdata.sctr.dx=rx;
	gdata.sctr.nul1=0;
	gdata.sctr.nul2=0;
	gdata.sctr.dy=ry;
	if(start>=0){
		fwork=modf(start,&iwork);
		gdata.sctr.strd.major=0;
	}
	else{
		fwork=fabs(start);
		fwork=modf(fwork,&iwork);
		gdata.sctr.strd.major=0x8000;
	}
	gdata.sctr.strd.major+=(unsigned)iwork;
	gdata.sctr.strd.minor=(unsigned)(fwork*65536.0);
	if(end>=0){
		fwork=modf(end,&iwork);
		gdata.sctr.edrd.major=0;
	}
	else{
		fwork=fabs(end);
		fwork=modf(fwork,&iwork);
		gdata.sctr.edrd.major=0x8000;
	}
	gdata.sctr.edrd.major+=(unsigned)iwork;
	gdata.sctr.edrd.minor=(unsigned)(fwork*65536.0);
	gdata.sctr.sctrmode=0;
	gdata.sctr.reserve=0;
	reg.x.bx=gds_wrkoff;
	seg.es=gds_wrkseg;
	int86x(0x92,&reg,&reg,&seg);
	return (int)reg.h.ah;
}
