/*
** Mirror Demo
** -----------
** Demo of the mirroring effect.  When this effect is combined with a
** decrease in palette values at the same line, you can create the illusion of
** water.
** 
** Use the mouse to move the mirror around. LMB exits.
**
** To compile with SAS/C:
**
**    1> sc Mirror.c link startup=LIB:gms.o data=far
**
*/

#include <proto/games.h>

extern struct GMSBase *GMSBase;
ULONG _XCEXIT = NULL;
ULONG PREFSNAME = DEFAULT;

ULONG WaterPalette[] = {
  0x000000,0x001000,0x706050,0x705040,0x604040,0x403020,0x302020,0x100000,
  0x200000,0x202020,0x707000,0x201010,0x606000,0x002000,0x200000,0x404000,
  0x103000,0x103000,0x104010,0x204010,0x205010,0x205020,0x303030,0x306020,
  0x304040,0x405050,0x606060,0x400000,0x400000,0x500010,0x300000,0x300000
};

ULONG Rasterlist[] = {
  WAITLINE(190),
  MIRROR,
  NEWPALETTE(0,32,WaterPalette),
  RASTEND
};

void main(void)
{
  struct GameScreen *GameScreen;
  struct Picture *MirrorPic;
  ULONG  mouse;
  WORD   maxX,maxY;

  if (MirrorPic = LoadPicFile("GMS:demos/data/PIC.Green",VIDEOMEM|GETPALETTE)) {

     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
        GSA_MemPtr1,MirrorPic->Data,
        GSA_Palette,MirrorPic->Palette,
        GSA_Rasterlist,Rasterlist,
        GSA_ScrWidth,320,
        GSA_ScrHeight,256,
        GSA_PicWidth,MirrorPic->Width,
        GSA_PicHeight,MirrorPic->Height,
        GSA_Planes,MirrorPic->Planes,
        GSA_AmtColours,MirrorPic->AmtColours,
        GSA_Attrib,HSCROLL|VSCROLL,
        GSA_ScrMode,MirrorPic->ScrMode,
        GSA_ScrType,MirrorPic->ScrType,
        TAGEND)) {

       ShowScreen(GameScreen);
       InitJoyPorts();

       maxX = (GameScreen->PicWidth)-(GameScreen->ScrWidth);
       maxY = (GameScreen->PicHeight)-(GameScreen->ScrHeight);

       do {
          mouse = ReadJoyPort(JPORT1,JT_ZBXY);
          GameScreen->PicXOffset += (BYTE)(mouse >> 8);
          GameScreen->PicYOffset += (BYTE)(mouse);
          if (GameScreen->PicXOffset < 0) GameScreen->PicXOffset = 0;
          if (GameScreen->PicXOffset > maxX) GameScreen->PicXOffset = maxX;
          if (GameScreen->PicYOffset < 0) GameScreen->PicYOffset = 0;
          if (GameScreen->PicYOffset > maxY) GameScreen->PicYOffset = maxY;
          MovePicture(GameScreen);
          WaitVBL();
       } while (!(mouse & MB_LMB));

     DeleteScreen(GameScreen);
     }
  FreePic(MirrorPic);
  }
}

