prism2.device: Compiler delint
[AROS.git] / workbench / demos / consoledemo.c
blob3031fd9e471d33e306869b6bbe44ec83153e4038
1 /*
2 Copyright © 1995-97, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo for the console.device
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <proto/intuition.h>
10 #include <proto/dos.h>
11 #include <dos/dosextens.h>
12 #include <exec/io.h>
13 #include <intuition/intuition.h>
14 #include <devices/conunit.h>
17 #define SDEBUG 1
18 #define DEBUG 1
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"
32 BOOL Init();
33 VOID Cleanup();
34 VOID HandleEvents(struct Window *);
36 /*************
37 ** main() **
38 *************/
39 int main(int argc, char **argv)
41 BPTR fh;
42 SDInit();
44 D(bug("Opening CON:\n"));
46 fh = Open("CON:", MODE_NEWFILE);
47 if (fh)
49 LONG ret;
50 ULONG i;
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));
57 Flush(fh);
60 Close(fh);
63 return 0;
66 if (Init())
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));
73 DoIO(con_io);
75 D(bug("IO on console req done\n"));
77 HandleEvents(window);
79 Cleanup();
81 return (0);
84 /*************
85 ** Init() **
86 *************/
87 BOOL Init()
89 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
90 if (IntuitionBase)
92 con_mp = CreateMsgPort();
93 if (con_mp)
95 con_io = CreateIORequest(con_mp, sizeof (struct IOStdReq));
96 if (con_io)
99 window = OpenWindowTags(NULL,
100 WA_Width, 400,
101 WA_Height, 300,
102 WA_SmartRefresh, TRUE,
103 WA_DragBar, TRUE,
104 WA_Title, (IPTR)"Console demo",
105 WA_IDCMP, IDCMP_REFRESHWINDOW|IDCMP_RAWKEY,
106 TAG_DONE);
108 if (window)
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"));
116 return (TRUE);
119 CloseWindow(window);
121 DeleteIORequest(con_io);
123 DeleteMsgPort(con_mp);
125 CloseLibrary((struct Library *)IntuitionBase);
128 return (FALSE);
131 /****************
132 ** Cleanup() **
133 ****************/
134 VOID Cleanup()
136 CloseDevice(con_io);
137 CloseWindow(window);
138 DeleteIORequest(con_io);
139 DeleteMsgPort(con_mp);
141 CloseLibrary((struct Library *)IntuitionBase);
146 /*******************
147 ** HandleEvents **
148 *******************/
149 VOID HandleEvents(struct Window *win)
151 struct IntuiMessage *imsg;
152 struct MsgPort *port = win->UserPort;
153 BOOL terminated = FALSE;
155 while (!terminated)
157 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
160 switch (imsg->Class)
163 case IDCMP_REFRESHWINDOW:
164 BeginRefresh(win);
165 EndRefresh(win, TRUE);
166 break;
168 case IDCMP_RAWKEY:
169 terminated = TRUE;
170 break;
172 } /* switch (imsg->Class) */
173 ReplyMsg((struct Message *)imsg);
176 } /* if ((imsg = GetMsg(port)) != NULL) */
177 else
179 Wait(1L << port->mp_SigBit);
181 } /* while (!terminated) */
183 return;
184 } /* HandleEvents() */