home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0931.lha
/
Modules
/
InputDevice
/
InputDevice.mod
/
InputDevice.mod
Wrap
Text File
|
1993-12-20
|
5KB
|
245 lines
IMPLEMENTATION MODULE InputDevice;
(* Die Anleitungen und ErlΣuterungen befinden sich im Definitionsfile *)
(* Compiler M2Amiga V4.097d ⌐ 1991 by Andre Wiethoff *)
(*$ StackChk:=FALSE *)
(*$ OverflowChk:=FALSE *)
(*$ NilChk:=FALSE *)
(*$ ReturnChk:=FALSE *)
(*$ Volatile:=FALSE *)
(*$ LargeVars:=FALSE *)
FROM SYSTEM IMPORT ADR,LONGSET,ADDRESS,SETREG,REG;
FROM ExecD IMPORT MsgPortPtr,TaskPtr,MsgPort,Interrupt,reset,clear,
stop,start,quick,IOStdReq;
FROM ExecL IMPORT OpenDevice,AddPort,FindTask,RemPort,CloseDevice,DoIO,
Permit,Forbid;
FROM Input IMPORT inputName,addHandler,remHandler,writeEvent,setThresh,
setPeriod,setMType,setMPort,setMTrig;
FROM InputEvent IMPORT InputEvent,InputEventPtr;
FROM Timer IMPORT TimeVal,IOTimerPtr;
FROM GamePort IMPORT KeySet,GamePortTrigger,Controller;
FROM R IMPORT D0,A0,A1,A4;
VAR task : TaskPtr;
msg : MsgPort;
ioStd : IOStdReq;
ioTimer : IOTimerPtr;
handlerInterrupt : Interrupt;
Handler : PROC;
opened,set : BOOLEAN;
(*$StackChk:=FALSE *)
(*$SaveA4:=TRUE *)
PROCEDURE InputHandler(event{A0} : ADDRESS;
sa4{A1} : ADDRESS);
BEGIN
SETREG(A4,sa4);
inputEvent:=event;
IF inputEvent#NIL THEN
Forbid;
Handler;
Permit;
END;
SETREG(D0,inputEvent);
END InputHandler;
PROCEDURE OpenInput() : BOOLEAN;
BEGIN
IF NOT opened THEN
task:=FindTask(0);
msg.sigTask:=task;
AddPort(ADR(msg));
OpenDevice(ADR(inputName),0,ADR(ioStd),LONGSET{});
ioStd.message.replyPort:=ADR(msg);
ioTimer:=ADR(ioStd);
IF (ioStd.device#NIL) AND (ioStd.error=0) THEN
opened:=TRUE;
ELSE
RemPort(ADR(msg));
END;
END;
RETURN opened;
END OpenInput;
PROCEDURE SetInputHandler(handler : PROC;
pri : SHORTINT);
BEGIN
IF opened THEN
IF set THEN
RemoveInputHandler;
END;
IF handler#NIL THEN
WITH handlerInterrupt DO
data:=REG(A4);
code:=ADR(InputHandler);
node.pri:=pri;
END;
WITH ioStd DO
command:=addHandler;
data:=ADR(handlerInterrupt);
END;
DoIO(ADR(ioStd));
Handler:=handler;
IF ioStd.error=0 THEN
set:=TRUE;
END;
END;
END;
END SetInputHandler;
PROCEDURE RemoveInputHandler;
BEGIN
IF opened AND set THEN
WITH ioStd DO
command:=remHandler;
data:=ADR(handlerInterrupt);
END;
DoIO(ADR(ioStd));
IF ioStd.error=0 THEN
set:=FALSE;
END;
END;
END RemoveInputHandler;
PROCEDURE AddInputEvent(event : InputEvent);
BEGIN
IF opened THEN
WITH ioStd DO
command:=writeEvent;
data:=ADR(event);
length:=SIZE(InputEvent);
flags:=quick;
END;
DoIO(ADR(ioStd));
END;
END AddInputEvent;
PROCEDURE InputCommand(com : InputCommands);
BEGIN
IF opened THEN
WITH ioStd DO
CASE com OF
|ResetDevice : command:=reset;
|ClearBuffer : command:=clear;
|StopDevice : command:=stop;
|RestartDevice : command:=start;
ELSE
END;
END;
DoIO(ADR(ioStd));
END;
END InputCommand;
PROCEDURE SetKeyboard(com : KeyboardOptions;
time : TimeVal);
BEGIN
IF opened THEN
WITH ioStd DO
CASE com OF
|Period : command:=setPeriod;
|Threshhold : command:=setThresh;
ELSE
END;
END;
ioTimer^.time:=time;
DoIO(ADR(ioStd));
END;
END SetKeyboard;
PROCEDURE SetMouseTrigger(keys : KeySet;
timeout : CARDINAL;
xDelta,yDelta : CARDINAL);
VAR gpt : GamePortTrigger;
BEGIN
IF opened THEN
gpt.keys:=keys;
gpt.timeout:=timeout;
gpt.xDelta:=xDelta;
gpt.yDelta:=yDelta;
WITH ioStd DO
command:=setMTrig;
data:=ADR(gpt);
length:=SIZE(GamePortTrigger);
END;
DoIO(ADR(ioStd));
END;
END SetMouseTrigger;
PROCEDURE SetMousePort(port : SHORTCARD);
VAR real : SHORTCARD;
BEGIN
IF opened THEN
real:=port-1;
WITH ioStd DO
command:=setMPort;
data:=ADR(real);
length:=1;
END;
DoIO(ADR(ioStd));
END;
END SetMousePort;
PROCEDURE SetControllerType(type : Controller);
BEGIN
IF opened THEN
WITH ioStd DO
command:=setMType;
data:=ADR(type);
length:=1;
END;
DoIO(ADR(ioStd));
END;
END SetControllerType;
PROCEDURE CloseInput;
BEGIN
IF opened THEN
IF set THEN
RemoveInputHandler;
END;
RemPort(ADR(msg));
CloseDevice(ADR(ioStd));
opened:=FALSE;
END;
END CloseInput;
BEGIN
set:=FALSE;
opened:=FALSE;
CLOSE
CloseInput;
END InputDevice.