%option "-low"
@16_E30000 %integer %array colour map(0:255)

%constant %integer mouse left=1, mouse middle=2, mouse right=4

@16_7F400 %short %integer mouse x
@16_7F402 %short %integer mouse y

%integerfn mouse buttons
%constinteger flip = mouseleft+mouseright, mask = flip+mousemiddle
@16_7F45B %byte %integer duartinp
%integer b
  b = duartinp>>1&mask
  %result = b %if b&flip=0 %or b&flip=flip
  %result = b!!flip
%end

%dynamic %volatile %integer %function %spec rel mouse x %c
                               %alias "FRED_GRAPHICS_MOUSEX"
%dynamic %volatile %integer %function %spec rel mouse y %c
                               %alias "FRED_GRAPHICS_MOUSEY"
{ Returns the relative change in the mouse position since last call. }

%dynamic %volatile %integer %function %spec mouse but %c
                               %alias "FRED_GRAPHICS_MOUSEB"

%dynamic %routine %spec vline %alias "FRED_GRAPHICS_VLINE" (%integer x, y0, y1)
{ Draws vertical line from (x, y0) to (x, y1). }

%dynamic %routine %spec hline %alias "FRED_GRAPHICS_HLINE" (%integer x0, x1, y)
{ Draws horizontal line from (x0, y) to (x1, y). }

%dynamic %routine %spec offset %alias "FRED_GRAPHICS_OFFSET" (%integer x, y)
{ Sets display area so that screen origin is at (x&(\15), y) within framestore. }

%dynamic %routine %spec colour %alias "FRED_GRAPHICS_COLOUR" (%integer colour)
{ Sets colour for drawing to 'colour'. }

%dynamic %routine %spec enable %alias "FRED_GRAPHICS_ENABLE" (%integer planes)
{ Allows writing to planes that have bits in 'planes' 1, disables other planes. }

%dynamic %routine %spec update colour map %alias "FRED_GRAPHICS_UPCMAP" %c
                                                 (%half %integer %name new map)
{ Writes 256 new half word entries into the colour map from an address }
{ starting with new map                                                }


%dynamic %routine %spec clear %alias "FRED_GRAPHICS_CLEAR"
{ Sets whole of framestore to colour 0.                           }
{ The currently selected colour and enabled palnes are unaltered. }

%dynamic %routine %spec half clear %alias "FRED_GRAPHICS_HCLEAR" (%integer h)
{ Clears half the frame store for fast animation                  }
{ If h = 0 the box (0, 0), (687, 511) is cleared                  }
{ If h = 1 the box (0, 512), (687, 1023) is cleared               }
{ The currently selected colour and enabled planes are unaltered. }

%dynamic %routine %spec line %alias "FRED_GRAPHICS_LINE" %c
                                                       (%integer x0, y0, x1, y1)
{ Draws arbitrary line from (x0, y0) to (x1, y1). }

%dynamic %routine %spec fill %alias "FRED_GRAPHICS_FILL" %c
                                                       (%integer x0, y0, x1, y1)
{ Draws filled orthogonal box with diagonal corners at (x0, y0, x1, y1). }

%dynamic %routine %spec col fill %alias "FRED_GRAPHICS_CFILL" %c
                            (%integer x0, y0, x1, y1, %byte %integer %name b)

%dynamic %routine %spec triangle %alias "FRED_GRAPHICS_TRIANGLE" %c
                                               (%integer x0, y0, x1, y1, x2, y2)
{ Draws filled triangle with vertices at (x0, y0), (x1, y1), (x2, y2). }

%dynamic %routine %spec trapeze %alias "FRED_GRAPHICS_TRAPEZE" %c
                                           (%integer x00, x01, y0, x10, x11, y1)
{ Draws a filled trapezium with vertices     }
{ (x00, y0), (x01, y0), (x10, y1), (x11, y1). }

%dynamic %routine %spec disc %alias "FRED_GRAPHICS_DISC" (%integer x, y, r)
{ Draws a filled circle of radius r and centre (x, y). }

%dynamic %routine %spec ring %alias "FRED_GRAPHICS_RING" (%integer x, y, r)
{ Draws the outline of a circle of radius r and centre (x, y). }

%dynamic %routine %spec plot %alias "FRED_GRAPHICS_PLOT" (%integer x, y)
{ Draws a single pixel at (x, y). }

%dynamic %routine %spec paint %alias "FRED_GRAPHICS_PAINT" %c
                     (%integer %name s, %integer x0, y0, x1, y1, offset, stride)

%dynamic %routine %spec textat %alias "FRED_GRAPHICS_TEXTAT" (%integer x,y)
{ Sets the position for drawing text to (x, y). }

%dynamic %routine %spec readfont %alias "FRED_GRAPHICS_READFONT" %c
                                        (%string(255) file, %integer %name font)
{ Reads pre-processed font from 'file' and returns }
{ heap address as integer in 'font'.               }

%dynamic %routine %spec showsymbol %alias "FRED_GRAPHICS_SHOWSYM" %c
                                                                    (%integer k)
{ Draws character 'k' in currently selected font     }
{ at currently selected screen position.             }
{ As a result the text screen position is updated so }
{ that subsequent showsymbol and showstring calls    }
{ draw beyond the character.                         }

%dynamic %routine %spec showstring %alias "FRED_GRAPHICS_SHOWSTR" %c
                                                                (%string(255) s)
{ Draws characters in 's' in currently selected font }
{ starting at currently selected screen position.    }
{ As a result the text screen position is updated so }
{ that subsequent show symbol and showstring calls   }
{ draw beyond the string.                            }

%dynamic %routine %spec font %alias "FRED_GRAPHICS_FONT" (%integer f)
{ Selects font used by subsequent calls to showsymbol and show string. }
{ 'f' is the integer address returned by 'readfont', above.            }
{ If 'f' is 0 the default Visual 200 font is selected.                 }

%dynamic %volatile %integer %function %spec font height %alias "FRED_GRAPHICS_FONTHT"
%dynamic %volatile %integer %function %spec font depth %alias "FRED_GRAPHICS_FONTDP"
%dynamic %volatile %integer %function %spec max font width %c
                                             %alias "FRED_GRAPHICS_FONTWX"
%dynamic %volatile %integer %function %spec min font width %c
                                             %alias "FRED_GRAPHICS_FONTWN"
%dynamic %volatile %integer %function %spec string width %c
                        %alias "FRED_GRAPHICS_STRNGW" (%string(255) s)

%dynamic %volatile %integer %function %spec char height %c
                        %alias "FRED_GRAPHICS_CHARHT" (%integer c)
%dynamic %volatile %integer %function %spec char depth %c
                        %alias "FRED_GRAPHICS_CHARDP" (%integer c)
%dynamic %volatile %integer %function %spec char width %c
                        %alias "FRED_GRAPHICS_CHARWD" (%integer c)

%dynamic %volatile %integer %function %spec text x pos %c
                        %alias "FRED_GRAPHICS_XPOS"
%dynamic %volatile %integer %function %spec text y pos %c
                        %alias "FRED_GRAPHICS_YPOS"

%dynamic %routine %spec poly %alias "FRED_GRAPHICS_POLY" (%integer x, y)
{ Defines a single vertex of (x, y) for subsequent call to closepoly.  }

%dynamic %routine %spec closepoly %alias "FRED_GRAPHICS_CLOSEPOLY"
{ Draws a filled polygon with vertices defined by prior calls of poly.  }
{ As a result all previous vertex definitions are lost and furthe calls }
{ to poly specify vertices for the next polygon to be drawn.            }

%constant %integer black=0, red=1, green=2, blue=4
%constant %integer yellow=red+green, magenta=red+blue, cyan=blue+green
%constant %integer white=red+green+blue

%dynamic %routine %spec show i %alias "FRED_GRAPHICS_SHOWI" (%integer n,p)
%dynamic %routine %spec show r %alias "FRED_GRAPHICS_SHOWR" (%real x, %integer n,m)
%dynamic %routine %spec show f %alias "FRED_GRAPHICS_SHOWF" (%real x, %integer n)
%dynamic %routine %spec shex1 %alias "FRED_GRAPHICS_SHEX1" (%integer x)
%dynamic %routine %spec shex2 %alias "FRED_GRAPHICS_SHEX2" (%integer x)
%dynamic %routine %spec shex4 %alias "FRED_GRAPHICS_SHEX4" (%integer x)
%dynamic %routine %spec shex %alias "FRED_GRAPHICS_SHEX" (%integer x)

%end %of %file
