home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Recent / util / mouse / WheelBusMouse.lha / wbm.c < prev    next >
C/C++ Source or Header  |  2001-06-03  |  6KB  |  287 lines

  1. /*  This software is distributed under GPL license - see gpl.txt
  2.     This is a part of WheelBusMouse and ps2m packages,
  3.     you can obtain latest versions at Aminet:
  4.  
  5. ftp://ftp.wustl.edu/pub/aminet/util/mouse/WheelBusMouse.lha
  6. ftp://ftp.wustl.edu/pub/aminet/util/mouse/WheelBusMouse.readme
  7.  
  8. ftp://ftp.wustl.edu/pub/aminet/hard/hack/ps2m.lha
  9. ftp://ftp.wustl.edu/pub/aminet/hard/hack/ps2m.readme
  10.  
  11. For any questions: rdc@cyberlan.mtu-net.ru
  12.  
  13. Don't forget to disable startup code! */
  14.  
  15. #include <exec/memory.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/input_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <pragmas/exec_sysbase_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22. #include <pragmas/input_pragmas.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include <dos/dostags.h>
  25.  
  26. #include <devices/input.h>
  27. #include <devices/inputevent.h>
  28. #include "newmouse.h"
  29.  
  30. struct Library *DOSBase, *SysBase, *GfxBase, *InputBase;
  31. struct IOStdReq *req;
  32. struct InputEvent FakeEvent;
  33.  
  34. ULONG code, tPRA, tPOTGOR;
  35.  
  36. #define COORDX *((STRPTR)0xdff00d)
  37. #define COORDY *((STRPTR)0xdff00c)
  38. #define POTGOR *((STRPTR)0xdff016)
  39. #define PRA *((STRPTR)0xbfe001)
  40. #define TEMPLATE "REVERSE/S,REVERSEX=RX/S,REVERSEY=RY/S,LMB/S,MMB/S,RMB/S,JOYFIRE0=JF0/S,JOYFIRE1=JF1/S,JOYFIRE2=JF2/S,CTRL/S,LSHIFT=LSH/S,RSHIFT=RSH/S,LALT/S,RALT/S,LCOMMAND=LCMD/S,RCOMMAND=RCMD/S,LFOURTHBUTTON=LFB/S,RFOURTHBUTTON=RFB/S,PRIORITY/N,QUIET/S"
  41.  
  42. struct {
  43.     ULONG reverse;
  44.     ULONG rx;
  45.     ULONG ry;
  46.     ULONG lmb;
  47.     ULONG mmb;
  48.     ULONG rmb;
  49.     ULONG jf0;
  50.     ULONG jf1;
  51.     ULONG jf2;
  52.     ULONG ctrl;
  53.     ULONG lsh;
  54.     ULONG rsh;
  55.     ULONG lalt;
  56.     ULONG ralt;
  57.     ULONG lcmd;
  58.     ULONG rcmd;
  59.     ULONG lfb;
  60.     ULONG rfb;
  61.     ULONG *pri;
  62.     ULONG quiet;
  63. } arg = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  64.  
  65. void event(LONG);
  66. void eventc(LONG);
  67. void process(void);
  68. void fbutton(void);
  69.  
  70. __saveds main()
  71. {
  72.     SysBase = *((struct Library **)4L);
  73.     if(DOSBase = OpenLibrary("dos.library",0))
  74.     {
  75.         if(GfxBase = OpenLibrary("graphics.library",36))
  76.         {
  77.             struct RDArgs *rda;
  78.             if(rda = ReadArgs(TEMPLATE,(LONG *)&arg,NULL))
  79.             {
  80.                 if(!arg.quiet)
  81.                 {
  82.                     Printf("%s  © Russian Digital Computing\n",6+"$VER: WheelBusMouse 1.4 "__AMIGADATE__);
  83.                 }
  84.                 if(FindTask("WheelBusMouse"))
  85.                 {
  86.                     Printf("%s already installed!\n","WheelBusMouse");
  87.                 }
  88.                 else
  89.                 {
  90.                     if(CreateNewProcTags(NP_Entry,process,NP_Name,"WheelBusMouse",NP_Priority,arg.pri?*arg.pri:0,NULL))
  91.                     {
  92.                         ((struct CommandLineInterface *)((((struct Process *)FindTask(NULL))->pr_CLI)<<2))->cli_Module = NULL;
  93.                         return(0);
  94.                     }
  95.                     if(!arg.quiet)
  96.                     {
  97.                         Printf("Can't create daughter process\n");
  98.                     }
  99.                 }
  100.                 CloseLibrary(GfxBase);
  101.             }
  102.         }
  103.         else
  104.         {
  105.             Write(Output(),"OS 2.0+ required\n",17);
  106.         }
  107.         CloseLibrary(DOSBase);
  108.     }
  109.     return(20);
  110. }
  111.  
  112. void __saveds process(void)
  113. {
  114.     struct MsgPort *replyport;
  115.     if(replyport = CreateMsgPort())
  116.     {
  117.         if(req = CreateIORequest(replyport,sizeof(struct IOStdReq)))
  118.         {
  119.             if(!OpenDevice("input.device",NULL,(struct IORequest *)req,NULL))
  120.             {
  121.                 BYTE LastByteX = COORDX;
  122.                 BYTE LastByteY = COORDY;
  123.                 BYTE LastJA = 0;
  124.                 BYTE LastJP = 0;
  125.                 ULONG qualc = arg.ctrl | arg.lalt | arg.ralt | arg.lsh | arg.rsh | arg.lcmd | arg.rcmd;
  126.                 ULONG qualp = arg.mmb | arg.rmb | arg.jf2 | arg.jf1;
  127.                 ULONG quala = arg.lmb | arg.jf0;
  128.                 ULONG qual = quala | qualp | qualc;
  129.                 InputBase = (struct Library *)req->io_Device;
  130.                 while(!CheckSignal(0xf000))
  131.                 {
  132.                     BYTE CurrByteX = COORDX;
  133.                     BYTE CurrByteY = COORDY;
  134.                     LONG diffx = (BYTE)(CurrByteX - LastByteX);
  135.                     LONG diffy = (BYTE)(CurrByteY - LastByteY);
  136.                     if(arg.lfb)
  137.                     {
  138.                         tPRA = PRA;
  139.                         if((tPRA&128)!=(LastJA&128))
  140.                         {
  141.                             if(!(tPRA&128))
  142.                             {
  143.                                 fbutton();
  144.                             }
  145.                         }
  146.                         LastJA = tPRA;
  147.                     }
  148.                     if(arg.rfb)
  149.                     {
  150.                         tPOTGOR = POTGOR;
  151.                         if((tPOTGOR&128)!=(LastJP&64))
  152.                         {
  153.                             if(!(tPOTGOR&64))
  154.                             {
  155.                                 fbutton();
  156.                             }
  157.                         }
  158.                         LastJP = tPOTGOR;
  159.                     }
  160.                     if(diffx || diffy)
  161.                     {
  162.                         if(arg.reverse)
  163.                         {
  164.                             diffx = -diffx;
  165.                             diffy = -diffy;
  166.                         }
  167.                         if(qual)
  168.                         {
  169.                             ULONG qua = 0;
  170.                             if(qualc)
  171.                             {
  172.                                 UWORD t = PeekQualifier();
  173.                                 if((arg.ctrl&&(t&IEQUALIFIER_CONTROL))||
  174.                                     (arg.lsh&&(t&IEQUALIFIER_LSHIFT))||
  175.                                     (arg.rsh&&(t&IEQUALIFIER_RSHIFT))||
  176.                                     (arg.lcmd&&(t&IEQUALIFIER_LCOMMAND))||
  177.                                     (arg.rcmd&&(t&IEQUALIFIER_RCOMMAND))||
  178.                                     (arg.lalt&&(t&IEQUALIFIER_LALT))||
  179.                                     (arg.ralt&&(t&IEQUALIFIER_RALT)))
  180.                                 {
  181.                                     qua = 1;
  182.                                 }
  183.                             }
  184.                             if(quala)
  185.                             {
  186.                                 if(!arg.lfb)
  187.                                 {
  188.                                     tPRA = PRA;
  189.                                 }
  190.                                 if((arg.lmb&&(!(tPRA&64)))||
  191.                                     (arg.jf0&&(!(tPRA&128))))
  192.                                 {
  193.                                     qua = 1;
  194.                                 }
  195.                             }
  196.                             if(qualp)
  197.                             {
  198.                                 if(!arg.rfb)
  199.                                 {
  200.                                     tPOTGOR = POTGOR;
  201.                                 }
  202.                                 if((arg.mmb&&(!(tPOTGOR&1)))||
  203.                                     (arg.rmb&&(!(tPOTGOR&4)))||
  204.                                     (arg.jf2&&(!(tPOTGOR&16)))||
  205.                                     (arg.jf1&&(!(tPOTGOR&64))))
  206.                                 {
  207.                                     qua = 1;
  208.                                 }
  209.                             }
  210.                             if(qua)
  211.                             {
  212.                                 LONG temp = diffx;
  213.                                 diffx = diffy;
  214.                                 diffy = temp;
  215.                             }
  216.                         }
  217.                         if(diffx)
  218.                         {
  219.                             code = NM_WHEEL_LEFT;
  220.                             if(arg.rx)
  221.                             {
  222.                                 diffx = -diffx;
  223.                             }
  224.                             if(diffx<0)
  225.                             {
  226.                                 code++;
  227.                                 diffx = -diffx;
  228.                             }
  229.                             eventc(diffx);
  230.                         }
  231.                         if(diffy)
  232.                         {
  233.                             code = NM_WHEEL_UP;
  234.                             if(arg.ry)
  235.                             {
  236.                                 diffy = -diffy;
  237.                             }
  238.                             if(diffy<0)
  239.                             {
  240.                                 code++;
  241.                                 diffy = -diffy;
  242.                             }
  243.                             eventc(diffy);
  244.                         }
  245.                         LastByteX=CurrByteX;
  246.                         LastByteY=CurrByteY;
  247.                     }
  248.                     WaitTOF();
  249.                 }
  250.                 CloseDevice((struct IORequest *)req);
  251.             }
  252.             DeleteIORequest(req);
  253.         }
  254.         DeleteMsgPort(replyport);
  255.     }
  256.     CloseLibrary(GfxBase);
  257.     CloseLibrary(DOSBase);
  258. }
  259.  
  260. void fbutton(void)
  261. {
  262.     code = NM_BUTTON_FOURTH;
  263.     event(IECLASS_RAWKEY);
  264.     event(IECLASS_NEWMOUSE);
  265. }
  266.  
  267. void eventc(LONG count)
  268. {
  269.     while(count--)
  270.     {
  271.         event(IECLASS_RAWKEY);
  272.         event(IECLASS_NEWMOUSE);
  273.     }
  274. }
  275.  
  276. void event(LONG class)
  277. {
  278.     FakeEvent.ie_NextEvent = NULL;
  279.     FakeEvent.ie_Class = class;
  280.     FakeEvent.ie_Code = code;
  281.     FakeEvent.ie_Qualifier = NULL;
  282.     req->io_Data = (APTR)&FakeEvent;
  283.     req->io_Length = sizeof(struct InputEvent);
  284.     req->io_Command = IND_WRITEEVENT;
  285.     DoIO((struct IORequest *)req);
  286. }
  287.