External;

{
	ConsoleIO.p

	This file implements all the normal console.device stuff for
dealing with windows.  The first set of routines is standard Amiga stuff,
culled from the ROM Kernel Manual.  The last few routines partially mimic
similar routines from Turbo Pascal.  See ConsoleTest.p for an example of
using these routines.
}


{$I "Include/Exec.i"}
{$I "Include/Ports.i"}
{$I "Include/ExecIO.i"}

Procedure ConPutChar(Request : IOStdReqPtr; Character : Char);
var
    Error : Integer;
begin
    Request^.ioReq.ioCommand := CMD_WRITE;
    Request^.ioData := Adr(Character);
    Request^.ioLength := 1;
    Error := DoIO(IORequestPtr(Request));
end;

Procedure ConWrite(Request : IOStdReqPtr; Str : String; length : Integer);
var
   Error : Integer;
begin
    Request^.ioReq.ioCommand := CMD_WRITE;
    Request^.ioData := Str;
    Request^.ioLength := Length;
    Error := DoIO(IORequestPtr(Request));
end;

Procedure ConPutStr(Request : IOStdReqPtr; Str : String);
var
    Error : Integer;
begin
    Request^.ioReq.ioCommand := CMD_WRITE;
    Request^.ioData := Str;
    Request^.ioLength := -1;
    Error := DoIO(IORequestPtr(Request));
end;

Procedure QueueRead(Request : IOStdReqPtr; Where : String);
begin
    Request^.ioReq.ioCommand := CMD_READ;
    Request^.ioData := Where;
    Request^.ioLength := 1;
    SendIO(IORequestPtr(Request));
end;

Function ConGetChar(consolePort : MsgPortPtr; Request : IOStdReqPtr;
			WhereTo : String) : Char;
var
    Temp : Char;
    TempMsg : MessagePtr;
begin
    if GetMsg(consolePort) = Nil then begin
	TempMsg := WaitPort(consolePort);
	TempMsg := GetMsg(consolePort);
    end;
    Temp := WhereTo^;
    QueueRead(Request, WhereTo);
    ConGetChar := Temp;
end;
