/* getgfxmembase.c - get base address of the default pubscreen
 * Written by Harry Sintonen <sintonen@iki.fi>. Public Domain.
 *
 * Compile: gcc -O2 getgfxmembase.c -o getgfxmembase
 *
 * NOTE: The returned address should give some idea of where the
 * graphics memory of the system is located. With real CyberGraphX
 * systems the returned address often is the base of the graphics
 * memory. However, this might not always be the case. With
 * CyberGraphX you might want to try ShowCgxConfig DEBUG instead.
 * It will return the memory base in BoardBase=$xxxxxxxx.
 *
 */

#include <cybergraphx/cybergraphics.h>

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/cybergraphics.h>

int main(void)
{
  struct Library *CyberGfxBase;

  CyberGfxBase = OpenLibrary("cybergraphics.library", 40);
  if (CyberGfxBase)
  {
    struct Library *IntuitionBase;

    IntuitionBase = OpenLibrary("intuition.library", 37);
    if (IntuitionBase)
    {
      struct Screen *scr;

      scr = LockPubScreen(NULL);
      if (scr)
      {
        if (GetCyberMapAttr(scr->RastPort.BitMap, CYBRMATTR_ISCYBERGFX))
        {
          ULONG base = 0;
          APTR lock;
          struct TagItem tags[2];
          tags[0].ti_Tag  = LBMI_BASEADDRESS;
          tags[0].ti_Data = (ULONG) &base;
          tags[1].ti_Tag  = TAG_DONE;
          lock = LockBitMapTagList(scr->RastPort.BitMap, tags);
          if (lock)
          {
            UnLockBitMap(lock);
            Printf("default pubscreen bitmap memory base 0x%lx\n", base);
          }
          else
            PutStr("could not lock the screen bitmap\n");
        }
        else
          PutStr("the default pubscreen is not cygergraphx\n");

        UnlockPubScreen(NULL, scr);
      }
      else
        PutStr("could not lock the default pubscreen\n");

      CloseLibrary(IntuitionBase);
    }
    else
      PutStr("requires intuition.library V37 or later\n");

    CloseLibrary(CyberGfxBase);
  }
  else
    PutStr("requires cybegraphics.library V40 or later\n");

  return 0;
}