[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem s intuitionem



A vubec...ja bych na to stejne pak zapomel, tak ten source
nahodim hned :-)

Timhle to nahodis

  CALLEXEC CreateMsgPort
  move.l  d0,MsgPort

  lea  InputName,a0
  lea  InputIORequest,a1
  move.l  d0,MN_REPLYPORT(a1)
  moveq  #0,d0
  moveq  #0,d1
  CALLEXEC OpenDevice

  lea  IOInterrupt,a0
  move.l  #InputHandler,IS_CODE(a0)
  move.b  #NT_DEVICE,LN_TYPE(a0)
  move.b  #127,LN_PRI(a0)
  move.l  #InHandlerName,LN_NAME(a0)
  lea  InputIORequest,a1
  move.w  #IND_ADDHANDLER,IO_COMMAND(a1)
  move.l  a0,IO_DATA(a1)
  CALLEXEC DoIO

a timhle si to po sobe uklidis:
  lea  InputIORequest,a1
  move.w  #IND_REMHANDLER,IO_COMMAND(a1)
  move.l  #IOInterrupt,IO_DATA(a1)
  CALLEXEC DoIO

move.l  MsgPort,a0
  CALLEXEC DeleteMsgPort

  lea  InputIORequest,a1
  CALLEXEC CloseDevice

IOInterrupt ds.b  IS_SIZE
MsgPort  ds.l  1
InputIORequest ds.b  IOSTD_SIZE
InputName dc.b  'input.device',0
InHandlerName dc.b  'Input handler',0
InterruptName dc.b  'Interrupt',0

InputHandler je adresa funkce, ktera je volana.
Priklad:

;------------------------------------------------
InputHandler movem.l  d1/a1-a2,-(sp)

  move.l  IntBase,a1
  move.l  ib_ActiveWindow(a1),d0
  cmp.l  WindowPtr,d0
  bne  .LastEvent

  move.l  a0,a1
  sub.l  a2,a2

.NextEvent move.b  ie_Class(a1),d0
  and.b  #IECLASS_RAWKEY,d0
  beq  .NoKeyEvent

  move.w  ie_Code(a1),d0
  and.w  #$00ff,d0
  bclr  #IECODEB_UP_PREFIX,d0
  beq.s  .SetKey

  tst.b  (HoldKeyboard,d0.w)
  bne  .ReplyKey
  clr.b  (Keyboard,d0.w)
  bra.s  .ReplyKey
.SetKey  st  (Keyboard,d0.w)
.ReplyKey move.w  ie_Qualifier(a1),d0
  and.w  #(1<<IEQUALIFIERB_LCOMMAND)!(1<<IEQUALIFIERB_RCOMMAND),d0
  beq  .NoKeyEvent

  move.w  ie_Code(a1),d0
  and.w  #$7f,d0
  cmp.b  #M,d0
  beq.s  .NoKeyEvent
  cmp.b  #N,d0
  bne  .KillEvent

.NoKeyEvent move.b  ie_Class(a1),d0
  and.b  #IECLASS_RAWMOUSE,d0
  beq.s  .NoMouseEvent

  move.w  ie_Code(a1),d0
  cmp.b  #IECODE_NOBUTTON,d0
  beq.s  .KillEvent

  moveq  #0,d1
  bclr  #IECODEB_UP_PREFIX,d0
  bne.s  .ClrButton
  moveq  #-1,d1
.ClrButton cmp.b  #IECODE_LBUTTON,d0
  bne.s  .NoLeftButton
  move.b  d1,LMB
  bra.s  .NoMouseEvent
.NoLeftButton cmp.b  #IECODE_RBUTTON,d0
  bne.s  .NoMouseEvent
  move.b  d1,RMB

.NoMouseEvent bra.s  .DoneEvent

.KillEvent move.l  a2,d0
  beq.s  .NoEvents
  move.l  (a1),(a2)


.DoneEvent tst.l  (a1)
  beq.s  .LastEvent
  move.l  a1,a2
  move.l  (a1),a1
  bra  .NextEvent

.LastEvent movem.l  (sp)+,d1/a1-a2
  move.l  a0,d0
  rts

.NoEvents movem.l  (sp)+,d1/a1-a2
  moveq  #0,d0
  rts

A pokud to chces v Cecku, tak:

struct MsgPort *EventMsgPort;
struct IOStdReq *EventIORequest;
struct Interrupt EventInter={NULL,NULL,NT_DEVICE,127,"Revenge
eventhandler",NULL,NULL};
int EventEnable;

int AddEventHandler()
{
 EventMsgPort=NULL;
 EventIORequest=NULL;

 if((EventMsgPort=CreateMsgPort()))
 if((EventIORequest=CreateIORequest(EventMsgPort,sizeof(struct IOStdReq))))


  if(!OpenDevice("input.device",0,(struct IORequest *)EventIORequest,0))
  {
   StopEventHandler();

   EventInter.is_Code=(void (*)())&EventInterrupt;

   EventIORequest->io_Command=IND_ADDHANDLER;
   EventIORequest->io_Data=&EventInter;
   DoIO((struct IORequest *)EventIORequest);

   return TRUE;
  }
 } else return FALSE;
}

void RemoveEventHandler()
{
 if(EventIORequest)
 {
  EventIORequest->io_Command=IND_REMHANDLER;
  DoIO((struct IORequest *)EventIORequest);

  CloseDevice((struct IORequest *)EventIORequest);
  DeleteIORequest(EventIORequest);
  if(EventMsgPort)
   DeleteMsgPort(EventMsgPort);
 }
}

struct InputEvent *EventInterrupt(register __a0 struct InputEvent *ie,
          register __a1 void *data)
{
struct InputEvent *e;
struct Screen *sc;
int code,npcode;
int down,lock;

 lock=LockIBase(0);
 sc=((struct IntuitionBase *)IntuitionBase)->ActiveScreen;
 UnlockIBase(lock);

 if(EventEnable && sc==DisplayScreen)
 {
  e=ie;

  while(e)


   code=e->ie_Code;
   npcode=code&~IECODE_UP_PREFIX;

   if(code&IECODE_UP_PREFIX)
    down=0x00;
   else
    down=0xff;

   switch((int)e->ie_Class)
   {
    case IECLASS_RAWKEY:

     if(!down)
     {
      if(!KeyHold[npcode])
       KeyMap[npcode]=0x00;
     }
     else KeyMap[npcode]=0xff;
    break;

    case IECLASS_RAWMOUSE:
     MouseX=e->ie_X;
     MouseY=e->ie_Y;

     if(npcode==IECODE_LBUTTON)
      LMB=down;
     if(npcode==IECODE_MBUTTON)
      MMB=down;
     if(npcode==IECODE_RBUTTON)
      RMB=down;
    break;

   }
   e=e->ie_NextEvent;
  }
 }
 return ie;
}


Pripadne tekute odmeny za ochotu mi muzes posilat na obvyklou adresu ;))))


    cau, Fido