#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/displayinfo.h>
#include <dos/dos.h>
#include <dos/rdargs.h>
#include <utility/hooks.h>
#include <libraries/asl.h>
#include <stdio.h>

#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/asl_protos.h>
#include <clib/alib_protos.h>

#include <pragma/dos_lib.h>
#include <pragma/exec_lib.h>
#include <pragma/intuition_lib.h>
#include <pragma/asl_lib.h>


/*****************************************************************************/


extern struct Library *SysBase;
extern struct Library *DOSBase;
       struct Library *GfxBase;
       struct Library *IntuitionBase;
       struct Library *GadToolsBase;
       struct Library *UtilityBase;
       struct Library *AslBase;


/*****************************************************************************/


VOID main(VOID)
{
struct FileRequester       *fr;
struct FontRequester       *fo;
struct ScreenModeRequester *smr;
struct Hook                 modehook;
struct DisplayMode          dmode;
struct DimensionInfo       *di;
struct List                 list;
BOOL                        going;

    /* open all basic libraries in case we need 'em later */
    IntuitionBase = OpenLibrary("intuition.library", 37);
    GfxBase       = OpenLibrary("graphics.library", 37);
    GadToolsBase  = OpenLibrary("gadtools.library", 37);
    UtilityBase   = OpenLibrary("utility.library", 37);
    AslBase       = OpenLibrary("asl.library", 38);

    /* check if we got everything we need */
    if (IntuitionBase && GfxBase && GadToolsBase && UtilityBase && AslBase)
    {
        going = TRUE;

        if (going)
        {
            /* bring up a plain file requester */
            if (fr = ( struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
                                         TAG_DONE))
            {
                going = AslRequest(fr,NULL);

                printf("Drawer: [%s]\nFile  : [%s]\n", fr->fr_Drawer, fr->fr_File);

                FreeAslRequest(fr);
            }
        }

        if (going)
        {
            /* bring up a directory requester */
            if (fr = ( struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
                                         ASLFR_DrawersOnly, TRUE,
                                         TAG_DONE))
            {
                going = AslRequest(fr,NULL);

                printf("Drawer: [%s]\n", fr->fr_Drawer);

                FreeAslRequest(fr);
            }
        }

        if (going)
        {
            /* bring up a save mode requester with a pattern gadget, and custom
             * text for the positive and negative action gadgets
             */
            if (fr = ( struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
                                         ASLFR_DoPatterns,   TRUE,
                                         ASLFR_DoSaveMode,   TRUE,
                                         ASLFR_PositiveText, "Save Me, Please!",
                                         ASLFR_NegativeText, "I'm Not Ready",
                                         TAG_DONE))
            {
                going = AslRequest(fr,NULL);

                printf("Drawer: [%s]\nFile  : [%s]\n", fr->fr_Drawer, fr->fr_File);

                FreeAslRequest(fr);
            }
        }

        if (going)
        {
            /* bring up a plain font requester */
            if (fo = ( struct FontRequester *)AllocAslRequestTags(ASL_FontRequest,
                                         TAG_DONE))
            {
                going = AslRequest(fo,NULL);

                printf("Font: [%s]\nSize: %ld\n", fo->fo_Attr.ta_Name,fo->fo_Attr.ta_YSize);

                FreeAslRequest(fo);
            }
        }

        if (going)
        {
            /* bring up a font requester which allows style selections */
            if (fo = ( struct FontRequester *)AllocAslRequestTags(ASL_FontRequest,
                                         ASLFO_DoStyle,    TRUE,
                                         TAG_DONE))
            {
                going = AslRequest(fo,NULL);

                printf("Font : [%s]\nSize : %ld\nStyle: %lx\n", fo->fo_Attr.ta_Name,fo->fo_Attr.ta_YSize,fo->fo_Attr.ta_Style);

                FreeAslRequest(fo);
            }
        }

        if (going)
        {
            /* bring up a font requester with a front pen selector */
            if (fo = ( struct FontRequester *)AllocAslRequestTags(ASL_FontRequest,
                                         ASLFO_DoFrontPen, TRUE,
                                         TAG_DONE))
            {
                going = AslRequest(fo,NULL);

                printf("Font     : [%s]\nSize     : %ld\nFront Pen: %lx\n", fo->fo_Attr.ta_Name,fo->fo_Attr.ta_YSize,fo->fo_FrontPen);

                FreeAslRequest(fo);
            }
        }

        if (going)
        {
            /* bring up a font requester with front and back pen selectors,
             * and drawing mode selector
             */
            if (fo = ( struct FontRequester *)AllocAslRequestTags(ASL_FontRequest,
                                         ASLFO_DoFrontPen, TRUE,
                                         ASLFO_DoBackPen,  TRUE,
                                         ASLFO_DoDrawMode, TRUE,
                                         TAG_DONE))
            {
                going = AslRequest(fo,NULL);

                FreeAslRequest(fo);
            }
        }

        if (going)
        {
            /* bring up a font requester with everything in it */
            if (fo = ( struct FontRequester *)AllocAslRequestTags(ASL_FontRequest,
                                         ASLFO_DoStyle,    TRUE,
                                         ASLFO_DoFrontPen, TRUE,
                                         ASLFO_DoBackPen,  TRUE,
                                         ASLFO_DoDrawMode, TRUE,
                                         TAG_DONE))
            {
                going = AslRequest(fo,NULL);

                FreeAslRequest(fo);
            }
        }

        if (going)
        {
            /* bring up a plain screen mode requester */
            if (smr = ( struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
                                          TAG_DONE))
            {
                going = AslRequest(smr,NULL);

                printf("DisplayID: [$%08lx]\n",smr->sm_DisplayID);

                FreeAslRequest(smr);
            }
        }

        if (going)
        {
            if (smr = ( struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
                                          ASLSM_DoWidth,        FALSE,
                                          ASLSM_DoHeight,       FALSE,
                                          ASLSM_DoDepth,        TRUE,
                                          ASLSM_DoAutoScroll,   FALSE,
                                          ASLSM_DoOverscanType, TRUE,
                                          TAG_DONE))
            {
                going = AslRequest(smr,NULL);

                FreeAslRequest(smr);
            }
        }

        if (going)
        {
            /* bring up a screen mode requester with more gadgets, that shows
             * every mode available, except dual playfield modes
             */
            if (smr = ( struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
                                          ASLSM_DoWidth,        TRUE,
                                          ASLSM_DoHeight,       TRUE,
                                          ASLSM_DoDepth,        TRUE,
                                          ASLSM_DoAutoScroll,   FALSE,
                                          ASLSM_DoOverscanType, FALSE,
                                          ASLSM_PropertyFlags,  0,
                                          ASLSM_PropertyMask,   DIPF_IS_DUALPF | DIPF_IS_PF2PRI,
                                          TAG_DONE))
            {
                going = AslRequest(smr,NULL);

                FreeAslRequest(smr);
            }
        }
    }

    if (IntuitionBase)  /* this will be always true when under >= V37 */
    {
        CloseLibrary(AslBase);
        CloseLibrary(UtilityBase);
        CloseLibrary(GadToolsBase);
        CloseLibrary(GfxBase);
        CloseLibrary(IntuitionBase);
    }
}
