home *** CD-ROM | disk | FTP | other *** search
- #include <intuition/intuition.h>
- #include <devices/console.h>
- #include <functions.h>
-
- #include "consolefun.h"
-
- long OpenConsole(writereq, readreq, window)
- struct IOStdReq *writereq;
- struct IOStdReq *readreq;
- struct Window *window;
- {
- long error;
-
- writereq->io_Data = (APTR) window;
- writereq->io_Length = sizeof(struct Window);
- error = OpenDevice("console.device",0,(struct IORequest*)writereq,0);
- readreq->io_Device = writereq->io_Device;
- readreq->io_Unit = writereq->io_Unit;
- return error;
- }
-
- void CloseConsole(writereq)
- struct IOStdReq *writereq;
- {
- CloseDevice((struct IORequest*)writereq);
- }
-
- /* Output a single character to a specified console */
- void ConPutChar(struct IOStdReq *writereq, char character)
- {
- writereq->io_Command = CMD_WRITE;
- writereq->io_Data = (APTR)&character;
- writereq->io_Length = 1;
- DoIO((struct IORequest*)writereq);
- }
-
- /* Output a stream of known length to a console */
- void ConWrite(struct IOStdReq *writereq, char *string, long length)
- {
- writereq->io_Command = CMD_WRITE;
- writereq->io_Data = (APTR)string;
- writereq->io_Length = length;
- DoIO((struct IORequest*)writereq);
- }
-
- /* output a NULL-terminated string of characters to a console */
- void ConPuts(struct IOStdReq *writereq, char *string)
- {
- writereq->io_Command = CMD_WRITE;
- writereq->io_Data = (APTR)string;
- writereq->io_Length = -1; /* this means print till terminator null */
- DoIO((struct IORequest*)writereq);
- }
-
-
- /* Queue up a read request to console, passing it pointer
- * to a buffer into which it can read the character
- */
- void QueueRead(struct IOStdReq *readreq, char *whereto)
- {
- readreq->io_Command = CMD_READ;
- readreq->io_Data = (APTR)whereto;
- readreq->io_Length = 1;
- SendIO((struct IORequest*)readreq);
- }
-
- /* check if a character has been received
- * if none, return -1
- */
- long ConMayGetChar(struct MsgPort *msgport, char *whereto)
- {
- register temp;
- struct IOStdReq *readreq;
-
- if(!(readreq = (struct IOStdReq *)GetMsg(msgport))) return -1;
- temp = *whereto;
- QueueRead(readreq, whereto);
- return temp;
- }
-
- /* wait for a character */
- char ConGetChar(struct MsgPort *msgport, char *whereto)
- {
- register temp;
- struct IOStdReq *readreq;
-
- WaitPort(msgport);
- readreq = (struct IOStdReq *)GetMsg(msgport);
- temp = *whereto;
- QueueRead(readreq, whereto);
- return temp;
- }
-