/**
   VGA 320*200, 256 Color Graphic Macro
**/


extern  unsigned char far *_ADD[200] ;
extern  unsigned int  far  _SEG[200],*_PSEG ;
extern  unsigned int  far  _PSE[][200] ;

/**
   Packed Mode Graphic Macro
**/

#define setP(X,Y,C)          (*(_ADD[(Y)]+(X)) = (C))
#define barL(X,Y,XL,YL,C)    imgFill(_SEG[(Y)],(X),320,(XL),(YL),(C))
#define bar2(X1,Y1,X2,Y2,C)  imgFill(_SEG[(Y1)],(X1),320,(X2)-(X1)+1,(Y2)-(Y1)+1,(C))
#define ClrScr(C)            imgHFill(0xa000,0,0xfa00,(C))
#define lineHL(X,Y,L,C)      imgHFill(_SEG[(Y)],(X),(L),(C))
#define lineH2(X1,Y,X2,C)    imgHFill(_SEG[(Y)],(X),(X2)-(X1)+1,(C))
#define lineVL(X,Y,L,C)      imgVFill(_SEG[(Y)],(X),320,(L),(C))
#define lineV2(X,Y1,Y2,C)    imgVFill(_SEG[(Y1)],(X),320,(Y2)-(Y1)+1,(C))
#define viewPage(P)          setStAdd((P)*0x4000)
#define putSpr0(X,Y,P,C,R)   sprCp(FP_SEG(P),FP_OFF(P),C,C,R,_SEG[Y],X,320)
#define putSpr1(X,Y,P,C,R)   sprCpMir(FP_SEG(P),FP_OFF(P),C,C,R,_SEG[Y],X,320)
#define putSpr2(X,Y,P,C,R)   sprCpUD(FP_SEG(P),FP_OFF(P),C,C,R,_SEG[Y],X,320)
#define putSpr3(X,Y,P,C,R)   sprCpMirUD(FP_SEG(P),FP_OFF(P),C,C,R,_SEG[Y],X,320)

/**
   Plane Mode Graphic Marco
**/

#define psetP(X,Y,C)         pBytePut(_PSEG[(Y)],(X),(C))
#define pBarL(X,Y,XL,YL,C)   pImgFill(_PSEG[(Y)],(X),80,(XL)+(X)-1,(YL),(C))
#define pBar2(X1,Y1,X2,Y2,C) pImgFill(_PSEG[(Y1)],(X1),80,(X2),(Y2)-(Y1)+1,(C))
#define pLineHL(X,Y,L,C)     pImgFill(_PSEG[(Y)],(X),(X)+(L)-1,(C))
#define pLineH2(X1,Y,X2,C)   pImgFill(_PSEG[(Y)],(X1),(X2),(C))
#define pLineVL(X,Y,L,C)     pImgVFill(_PSEG[(Y)],(X),80,(L),(C))
#define pLineV2(X,Y1,Y2,C)   pImgVFill(_PSEG[(Y1)],(X),80,(Y2)-(Y1)+1,(C))
#define pClrScr(C)           imgHFill(_PSEG[0],0,0x4000,(C)) ;
#define page2PageCp(S,D)     writeMode(1) ; pImgCpLU(_PSE[(S)][0],0,80,80,200,_PSE[(D)][0],0,80) ;
#define pPutSpr0(X,Y,P,C,R)  psprCp(FP_SEG(P),FP_OFF(P),C,C,R,_PSEG[Y],X,80)
#define pPutSpr1(X,Y,P,C,R)  psprCpMir(FP_SEG(P),FP_OFF(P),C,C,R,_PSEG[Y],X,80)
#define pPutSpr2(X,Y,P,C,R)  psprCpUD(FP_SEG(P),FP_OFF(P),C,C,R,_PSEG[Y],X,80)
#define pPutSpr3(X,Y,P,C,R)  psprCpMirUD(FP_SEG(P),FP_OFF(P),C,C,R,_PSEG[Y],X,80)

#define planeWrite1          planeMode() ; writeMode(1) ;
#define planeWrite0          planeMode() ; writeMode(0) ;
#define packWrite1           packMode()  ; writeMode(1) ;
#define packWrite0           packMode()  ; writeMode(0) ;

#define setRGB(I,R,G,B)      set1DACR((I),(R),(G),(B))

#define _R7 0xe0
#define _R6 0xc0
#define _R5 0xa0
#define _R4 0x80
#define _R3 0x60
#define _R2 0x40
#define _R1 0x20

#define _G7 0x1c
#define _G6 0x18
#define _G5 0x14
#define _G4 0x10
#define _G3 0x0c
#define _G2 0x08
#define _G1 0x04

#define _B3 0x03
#define _B2 0x02
#define _B1 0x01


int _XL,_YL,_XR,_YR ;           // Clipping Window Variable

vga320Mode()
vgaTextMode()
setStAdd(st)
actPage(int p)
planeMode()
packMode()
writeMode(mode)
cTrpRImg0(x,y,p,xs,ys)
cTrpRImg1(x,y,p,xs,ys)
pPutImgMode(x,y,p,xs,ys,m)
pCTrpRImg0(x,y,p,xs,ys)
pCTrpRImg1(x,y,p,xs,ys)
pCTrpRImg2(x,y,p,xs,ys)
pCTrpRImg3(x,y,p,xs,ys)
pBox2(x1,y1,x2,y2,c)
pBoxL(x,y,xl,yl,c)
imgCpLU(sseg,soff,scs,xs,ys,dseg,doff,dcs)
imgCpRU(sseg,soff,scs,xs,ys,dseg,doff,dcs)
imgCpRD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
imgCpLL(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pimgCpLU(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pimgCpRU(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pimgCpRD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pimgCpLL(sseg,soff,scs,xs,ys,dseg,doff,dcs)
scroll(seg,off,scs,xs,ys,h,v)
imgCpMir(sseg,soff,scs,xs,ys,dseg,doff,dcs)
imgCpMirUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
imgCpUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
sprCp(sseg,soff,scs,xs,ys,dseg,doff,dcs)
sprCpMir(sseg,soff,scs,xs,ys,dseg,doff,dcs)
sprCpMirUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
sprCpUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
bitImgCp(sseg,soff,scb,ys,dseg,doff,dcs,color)
memCp(sseg,soff,l,dseg,doff)
imgFill(seg,off,ics,xs,ys,color)
imgHFill(seg,off,xs,color)
imgVFill(seg,off,ics,ys,color)

pSprCp(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pSprCpUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pSprCpMir(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pSprCpMirUD(sseg,soff,scs,xs,ys,dseg,doff,dcs)
pImgVFill(seg,off,scs,ys,color)
pBytePut(seg,off,color)
pImgHFill(seg,x1,x2,color)
pImgFill(seg,x1,scs,x2,ys,color)
pBitImgCp(sseg,soff,scs,ys,dseg,doff,dcs,color)
fPBitImgCp(sseg,soff,scs,ys,dseg,doff,dcs,color)
get1DACR(i,r,g,b)
getNDACR(s,n,r,g,b)
set1DACR(i,r,g,b)
setNDACR(s,n,r,g,b)
brightCtrl(s,n,r,g,b,factor)
greyCtrl(s,n,r,g,b,factor)
loadTPal(pname)

initImg(img,n)
freeImg(img,n)
loadImg(imgIdFn,img)
loadSpr(sprIdFn,spr,img)
loadImgSpr(IdFn,img,spr)
cTrpSpr0(x,y,spr,img)
cTrpSpr1(x,y,spr,img)
pPutSprMode(x,y,spr,img,m)
pCTrpSpr0(x,y,spr,img)
pCTrpSpr1(x,y,spr,img)
pCTrpSpr2(x,y,spr,img)
pCTrpSpr3(x,y,spr,img)

HCode2Bitmap(f,m,l,bitmap)
HNByteCode(str,han)
oneHNByteCode(str,han,p)
isFChar(char ch)
isMChar(ch1,ch2,o)
isLChar(ch1,ch2,o)
HCharType(char ch)
hText(x,y,str,mode,fc,bc)
pHText(x,y,str,mode,fc,bc)
loadFont(char *fn)
pText(x,y,str,mode,fc,bc)
fPText(x,y,str,mode,fc,bc)
