2 Copyright © 1995-97, The AROS Development Team. All rights reserved.
5 Desc: Demo for the console.device
8 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/dos.h>
11 #include <dos/dosextens.h>
13 #include <intuition/intuition.h>
14 #include <devices/conunit.h>
19 #include <aros/debug.h>
21 struct IntuitionBase
*IntuitionBase
;
23 struct MsgPort
*con_mp
;
24 struct IORequest
*con_io
;
26 struct Window
*window
;
28 #define ioStd(x) ((struct IOStdReq *)x)
30 #define TESTSTR "Test"
34 VOID
HandleEvents(struct Window
*);
39 int main(int argc
, char **argv
)
44 D(bug("Opening CON:\n"));
46 fh
= Open("CON:", MODE_NEWFILE
);
52 D(bug("Console file opened\n"));
53 for (i
= 0; i
< 100; i
++)
55 ret
= FPuts(fh
, "Test\n");
56 D(bug("Got ret %ld\n", ret
));
68 ioStd(con_io
)->io_Command
= CMD_WRITE
;
69 ioStd(con_io
)->io_Data
= TESTSTR
;
70 ioStd(con_io
)->io_Length
= -1L;
72 D(bug("Doing IO on console req %p\n", con_io
));
75 D(bug("IO on console req done\n"));
89 IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 37);
92 con_mp
= CreateMsgPort();
95 con_io
= CreateIORequest(con_mp
, sizeof (struct IOStdReq
));
99 window
= OpenWindowTags(NULL
,
102 WA_SmartRefresh
, TRUE
,
104 WA_Title
, (IPTR
)"Console demo",
105 WA_IDCMP
, IDCMP_REFRESHWINDOW
|IDCMP_RAWKEY
,
110 ioStd(con_io
)->io_Data
= (APTR
)window
;
111 ioStd(con_io
)->io_Length
= sizeof (struct Window
);
113 if (0 == OpenDevice("console.device", CONU_STANDARD
, con_io
, 0))
115 D(bug("Console device successfully opened\n"));
121 DeleteIORequest(con_io
);
123 DeleteMsgPort(con_mp
);
125 CloseLibrary((struct Library
*)IntuitionBase
);
138 DeleteIORequest(con_io
);
139 DeleteMsgPort(con_mp
);
141 CloseLibrary((struct Library
*)IntuitionBase
);
149 VOID
HandleEvents(struct Window
*win
)
151 struct IntuiMessage
*imsg
;
152 struct MsgPort
*port
= win
->UserPort
;
153 BOOL terminated
= FALSE
;
157 if ((imsg
= (struct IntuiMessage
*)GetMsg(port
)) != NULL
)
163 case IDCMP_REFRESHWINDOW
:
165 EndRefresh(win
, TRUE
);
172 } /* switch (imsg->Class) */
173 ReplyMsg((struct Message
*)imsg
);
176 } /* if ((imsg = GetMsg(port)) != NULL) */
179 Wait(1L << port
->mp_SigBit
);
181 } /* while (!terminated) */
184 } /* HandleEvents() */