/* Huskee PSX game events from usbecd.sys into gamepad.sys */ rc=RxFuncAdd('SysGetMessage','RexxUtil','SysGetMessage') /* set log file name */ ddNameR='xevents.log' /* report xevents.cmd started */ info=' started on <'||date()||'> at <'||time()'>' rc=lineout(ddNameR,info) ; say info /* set device driver names */ ddNameI='$PSX3$' ; ddNameO='GAMEPAD$' /* verify that the direct control driver exists in config.sys */ if stream(ddNameI,'command','query exists') \= '\DEV\' || ddNameI then do info='DEVICE=?:\OS2\BOOT\USBECD.SYS /D:054C:0268:0100 /N:'ddNameI rc=lineout(ddNameR,info) ; say info info='above device driver statement must be present in config.sys' rc=lineout(ddNameR,info) ; say info signal ProcessComplete end /* acquire the direct control driver */ rc=stream(ddNameI,'command','open write') if rc \= 'READY:' then do info=rc||' Device driver '||ddNameI||' currently in use. Please try later.' rc=lineout(ddNameR,info) ; say info signal ProcessComplete end /* verify that the emulate joystick driver exists in config.sys */ if stream(ddNameO,'command','query exists') \= '\DEV\' || ddNameO then do info='DEVICE=?:\OS2\BOOT\GAMEPAD.SYS required in config.sys' rc=lineout(ddNameR,info) ; say info signal ProcessComplete end /* acquire the emulate joystick driver */ rc=stream(ddNameO,'command','open') if rc \= 'READY:' then do info=rc||' Device driver '||ddNameO||' currently in use. Please try later.' rc=lineout(ddNameR,info) ; say info signal ProcessComplete end /* initialize buffer to communicate with usbecd.sys */ oiBuffer = substr(x2c(EC 00 0000 8103 0800),1,16,x2c(EE)) /* intialize buffer to gamepad.sys */ oBuffer = x2c(0000 0000 0000 0000 0000) sBuffer = x2c(0000 0000 0000 0000 0000) /* initialize swap joysticks (axis only) */ oStick = 'AB'x ; nStick = oStick ; sStick = oStick /* catch these here to release the joystick */ signal on error; signal on failure; signal on halt; signal on novalue; signal on syntax; do forever call GetPacket report=c2x(substr(oiBuffer,8+7,1)) select when report=='00' then call PutEvent when report=='EE' then iterate otherwise call Unknown end end /* cleanup */ signal ProcessComplete exit GetPacket: rc=charout(ddNameI,oiBuffer) rc=stream(ddNameI,'description') if rc \= 'READY:' then do /* obtain error message */ parse value rc with sState ':' mNumber if mNumber == 95 /* character i/o call interrupted */ then rc=stream(ddNameI,'command','open') /* retry */ else do /* issue error message */ say SysGetMessage(mNumber,,ddNameI) say 'get gamepad packet failed!' signal ProcessComplete end end return PutEvent: /* swap joysticks axis */ switch = substr(oiBuffer,8+6,1) if (bitand(switch,'10'x) <> '10'x) then sStick = oStick else do /* select button pressed */ nStick = bitxor(sStick,'11'x) if oStick <> nStick then do oStick = nStick info='* select button -> swap joysticks (axis only)' rc=lineout(ddNameR,info) ; say info end return end if oStick == 'AB'x then do Ax = substr(oiBuffer,8+1,1)||x2c(00) Ay = substr(oiBuffer,8+2,1)||x2c(00) Bx = substr(oiBuffer,8+3,1)||x2c(00) By = substr(oiBuffer,8+4,1)||x2c(00) end else do Ax = substr(oiBuffer,8+3,1)||x2c(00) Ay = substr(oiBuffer,8+4,1)||x2c(00) Bx = substr(oiBuffer,8+1,1)||x2c(00) By = substr(oiBuffer,8+2,1)||x2c(00) end button = c2d(substr(oiBuffer,8+5,1)) switch = c2d(substr(oiBuffer,8+6,1)) /* is this code correct? */ if switch > 0 then button = switch if button < 15 then button = d2c(224-16*(button))||x2c(00) else button = d2c(240-16*trunc(button/16))||x2c(00) oBuffer=Ax||Ay||Bx||By||button if sbuffer <> obuffer then do sbuffer = obuffer info='Ax='||c2x(Ax)||', Ay='||c2x(Ay)||', Bx='||c2x(Bx)||', By='||c2x(By)||', Buts='||c2x(button) rc=lineout(ddNameR,info) ; say info /* write this event */ rc=charout(ddNameO,oBuffer) rc=stream(ddNameO,'description') /* check completion code */ if rc \= 'READY:' then do say /* obtain and issue error message */ parse value rc with sState ':' mNumber say SysGetMessage(mNumber,,ddNameO) signal ProcessComplete end end return Unknown: /* show packet */ packet=c2x(substr(oiBuffer,9)) output='Packet='||packet||',Huh?' rc=lineout(ddNameR,output) say output return /* report signal information */ error: failure: halt: novalue: syntax: parse source system invokation filename info=condition('c')||' condition raised at line '||sigl||' of'||'0D0A'x info=info||filename||'0D0A'x||'|'||sourceline(sigl) rc=lineout(ddNameR,info) ; say info ProcessComplete: /* release the emulate mouse driver */ rc=stream(ddNameO,'command','close') /* release the direct control driver */ rc=stream(ddNameI,'command','close') /* report xevents.cmd stopped */ info=' stopped on <'||date()||'> at <'||time()'>' rc=lineout(ddNameR,info) ; say info exit