
/*******************************************************************
 $CRT 02 Jun 1996 : hb

 $AUT Holger Burkarth
 $DAT >>WinCon.c<<   29 Jan 1997    13:29:41 - (C) ProDAD
*******************************************************************/

//##ex mcpp:cppc -gs -o pos:pos/Ex/WinCon p:pLib/StartCode.o p:/pOS_RKRM/pConsole/WinCon.c p:pLib/StdIO.o -l pOSStub -l pOS

/***********************************************************
  pOS programing example - Copyright (C) 1995-97 proDAD

  This code was written as an easy to understand example,
  how to program pOS features. It is provided 'as-is',
  without any express or implied warranty.

  Permission is hereby granted to use, copy and modify
  this source code for any purpose, without fee, subject
  to the following conditions:

    (1) This notice may not be removed or altered from any
        source distribution.

    (2) Altered source versions must be plainly marked as
        such, and must not be misrepresented as being
        the original source code.

    (3) If only executable code is distributed, then the
        accompanying documentation have to state that
        "this software is based in part on examples of
        the pOS developer packet".

    (4) Permission for use of this code is granted only
        if the user accepts full responsibility for any
        undesirable consequences. proDAD accept NO LIABILITY
        for damages of any kind.

  İproDAD
***********************************************************/

/*\
*** Example:
***
\*/


#define __COMPUTER_AMIGA 1
#define NOMYDEBUG

#include "p:pExec/Types.h"
#include "p:pDOS/ArgTags.h"
#include "p:pDOS/DosSig.h"
#include "p:pDOS/DosErrors.h"
#include "p:pDevice/Console.h"
#include "p:pGadget/Gadget.h"
#include "p:pScreen/ScrTags.h"
#include "p:pScreen/Window.h"
#include "p:pScreen/Screen.h"
#include "p:pIntui/IntuMsg.h"
#include "p:pIntui/Tags.h"
#include "p:pIntui/FraClass.h"
#include "p:pProto/pLibExt.h"
#include "p:pProto/pExec2.h"
#include "p:pProto/pDOS2.h"
#include "p:pProto/pIntui2.h"

#ifdef _____ME_____
  #include "grund/inc_string.h"
  #include "grund/inc_stdio.h"
#else
 #ifdef __cplusplus
 extern "C" {
 #endif
  #include <string.h>
  #include <stdio.h>
 #ifdef __cplusplus
 }
 #endif
#endif


const CHAR *HelpText=
""
;

const CHAR *PrgHeader=
"";

const CHAR *PrgVerText=
"$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";


struct pOS_IntuiDevice *gb_IntuiBase;

/*----------------------------------
-----------------------------------*/
#ifdef __cplusplus
extern "C"
#endif

VOID main()
{
  struct pOS_DosArgs* Args;
  UWORD Err=0;
  ULONG Ops[2]={0,0};

  gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);

  Args=pOS_ReadDosArgs(
// 0
"",
Ops,sizeof(Ops)/sizeof(ULONG),

    ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
    ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
    ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
    TAG_END);

  if(Args) {
    struct pOS_Window *Win;
    struct pOS_Screen *Scr;
    struct pOS_ConsoleStdReq *CIO;
    struct pOS_MsgPort ReplyPort;

    pOS_ConstructMsgPort(&ReplyPort);

    if(Scr=pOS_LockPubScreen("Workbench")) {
      Win=pOS_OpenWindow(
          SCRTAG_Title,   (ULONG)"Console-Window",
          SCRTAG_Width,   320,
          SCRTAG_Height,  200,
          SCRTAG_PubName, (ULONG)"Workbench",
          SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
                          WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
          SCRTAG_IDCMP,   IDCMP_CloseWindow,
          TAG_DONE);
      if(Win) {
        if(CIO=(pOS_ConsoleStdReq*)
               pOS_CreateIORequest(&ReplyPort,sizeof(pOS_ConsoleStdReq)))
        {
          struct pOS_ConsoleInitStruct CIS;
          CIS.cis_Window=Win;
          CIS.cis_VPropGad=NULL;
          CIS.cis_Lines=0;

          CIO->cio_Command=CMDCD_InitStruct;
          CIO->cio_Data=(APTR)&CIS;
          pOS_OpenDevice("pconsole.device",0,(pOS_IORequest*)CIO,0,0);
          if(CIO->cio_Error==0) {
            UBYTE Buffer[16];
            CIO->cio_Command=CMD_WRITE;
            CIO->cio_Data=(APTR)"Hallo Welt\n\nBitte Taste drücken...";
            CIO->cio_Length=-1;
            pOS_DoIO((pOS_IORequest*)CIO);

            CIO->cio_Command=CMD_READ;
            CIO->cio_Data=(APTR)Buffer;
            CIO->cio_Length=sizeof(Buffer);
            pOS_DoIO((pOS_IORequest*)CIO);

            printf("ReadSize=%ld %.4h\n",CIO->cio_Actual,Buffer);

//            pOS_WaitPort(Win->win_UserPort);
            pOS_CloseDevice((pOS_IORequest*)CIO);
          }
          pOS_DeleteIORequest((pOS_IORequest*)CIO);
        }
        else printf("no mem\n");
        pOS_CloseWindow(Win);
      }
      else printf("Cannot open window\n");

      pOS_UnlockPubScreen(Scr);
    }
    else printf("Cannot lock PubScreen\n");

    pOS_DestructMsgPort(&ReplyPort);

    pOS_DeleteDosArgs(Args);  /* Args freigeben */
  }
  else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */

  pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);

  pOS_SetShellFail(Err);
}
