English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 27 September 2011, 20:03   #1
Jekot
 
Posts: n/a
Mouse control

Hello all, please help me. I want use Mouse in my programm on assembler.
How can i do it? I anderstand how click mouse buttom, but I not anderstand how trace mouse way. Assembler code please, if this not problem. I use Devpack on my Amiga1200+MTec1230+8MbFast. Maby use OS library? Coding for WB.
Senks. For give my English.
 
Old 28 September 2011, 10:34   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,552
You should read JOY0DAT ($dff00a, for the mouse on the first port) during the VERTB interrupt. Bit 8-15 represent the vertical count and bit 7-0 the horizontal count.

Always save the value from the previous VERTB, so you can calculate the differences. Also note that there will frequently be overruns in the 8-bit counters. For example a previous value of $10 and a current value of $20 show you a delta-x (or delta-y) of 16 ($10). But a previous value of $f8 and a current value of $08 will indicate the same distance, which the mouse has been travelled.
phx is offline  
Old 28 September 2011, 19:11   #3
Jekot
 
Posts: n/a
Big sanx for a your anseware.
I anderstand all, but have other dificult....

I do that:

mouse:
movem.l d0-d7/a0-a6,-(SP)
loop:
jsr Draw ;draw border of menu

move.w $dff00a,d0 ; read mose port data
move.l d0,d1
jsr Pause ;pause for pause
lsr.w #8,d1 ;shift on 8-bit
andi.l #$ff,d0 ;d0-x coordinat
andi.l #$ff,d1 ;d1-y coordinat
lea.l mousex,a1 ;save in mousex
move.l d0,(a1) ;do
lea.l mousey,a1 ;save in mousey
move.l d1,(a1) ;d1
cmp #0,d1 ;compare resultat
bne.s temp_0 ;and go to other code
etc......

This code move border of menu in 3 row. Start,Option,Exit.
But its no good.
Have errors in calculate the differences and move border(mouse) no stability.

Haw can i get start position (0,0) and haw can i use interrupt.
If you not dificult, please print me code

Sorry on the my English
 
Old 29 September 2011, 10:11   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,552
You need to install a Level3 interrupt handler for reading the new mouse counters during the vertical blanking interrupt. This way you can update your mouse position using the movement deltas 50 or 60 times per second.

Either use the appropriate exec.library functions to install a new VERTB interrupt server with AddIntServer(), or if you feel like taking over the whole system you should write your interrupt handler's address to VectorBase+$6c (VectorBase is 0 on 68000). This is the Level 3 interrupt vector, which handles Copper, VERTB and Blitter Interrupts. We are only interested in VERTB and ignore the other two:

Code:
lev3_int:
        movem.l d0-d1,-(sp)
        moveq   #$20,d0   
        and.w   $dff01e,d0
        beq     lev3_done
vertb_int:
        move.w  $dff00a,d1
        move.w  d1,d0
        sub.b   oldhorizcnt,d0
        ext.w   d0
        add.w   d0,mouse_x
        move.b  d1,oldhorizcnt
        lsr.w   #8,d1
        move.b  oldvertcnt,d0
        move.b  d1,oldvertcnt
        sub.b   d0,d1
        ext.w   d1
        add.w   d1,mouse_y
lev3_done:
        movem.l (sp)+,d0-d1   
        move.w  #$0070,$dff09c
        nop
        rte

mouse_x:
        ds.w    1
mouse_y:
        ds.w    1
oldhorizcnt:
        ds.b    1
oldvertcnt:
        ds.b    1
During the interrupt the mouse movement deltas are calculated and added to the current position. In your main program you can directly read mouse_x and mouse_y at any time.

To initialize your mouse request you should do the following:
Code:
; set the starting mouse position (for example 0,0)
        move.w  #0,mouse_x
        move.w  #0,mouse_y

; initialize the old counters, so the mouse will not jump on first movement
        move.w  $dff00a,d0
        move.b  d0,oldhorizcnt
        lsr.w   #8,d0
        move.b  d0,oldvertcnt
phx is offline  
Old 29 September 2011, 10:31   #5
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,575
Quote:
Coding for WB
IDCMP messages or input.device. Do not access hardware directly. Check Rom kernel manuals and other documentation for example in eab fileserver.
Toni Wilen is offline  
Old 29 September 2011, 10:50   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,552
Quote:
Originally Posted by Jekot View Post
Maby use OS library? Coding for WB.
Sorry, I missed that. When coding for WB you will want to avoid any direct hardware access.

In this case you could open input.device and install an input handler at a high priority, so you can process all mouse events before WB is getting them.

Example code for opening the device and installing the handler (just a draft):
Code:
  if (inputport = CreatePort(NULL,0)) {
    if (input = (struct IOStdReq *)
                 CreateExtIO(inputport,sizeof(struct IOStdReq))) {
      if (InputIntData = AllocMem(sizeof(struct InputIntDat),
                                   MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
        if (!(input_dev = OpenDevice("input.device",0,
                                     (struct IORequest *)input,0))) {
          InputHandler.is_Node.ln_Type = NT_INTERRUPT;
          InputHandler.is_Node.ln_Pri = 100;
          InputHandler.is_Data = InputIntData;
          InputHandler.is_Code = (void(*)())InputIntCode;
          input->io_Data = (void *)&InputHandler;
          input->io_Command = IND_ADDHANDLER;
          DoIO((struct IORequest *)input);
Your handler is called IntputIntCode, and the data structure, which you can use to save your mouse position (also buttons and other stuff), is called InputIntData.

The handler code, including button handling, could look like this:
Code:
        include "exec/types.i"
        include "devices/inputevent.i"
...
        xdef    _InputIntCode
_InputIntCode:
        move.l  a0,-(sp)
.loop:
        cmp.b   #IECLASS_RAWMOUSE,ie_Class(a0)
        bne     .next
        move.w  ie_Code(a0),d0
        btst    #7,d0
        bne.b   .up
        cmp.w   #IECODE_LBUTTON,d0
        beq.b   .lmb_down   
        cmp.w   #IECODE_MBUTTON,d0
        beq.b   .mmb_down
        cmp.w   #IECODE_RBUTTON,d0
        beq.b   .rmb_down
        bra.b   .move
.up:
        and.w   #$007f,d0
        cmp.w   #IECODE_LBUTTON,d0
        beq.b   .lmb_up
        cmp.w   #IECODE_MBUTTON,d0
        beq.b   .mmb_up
        cmp.w   #IECODE_RBUTTON,d0
        beq.b   .rmb_up
        bra.b   .move  
.lmb_down:
        move.l  #-1,iid_LeftButtonDown(a1)
        clr.l   iid_LeftButtonUp(a1)
        bra.b   .move
.mmb_down:
        move.l  #-1,iid_MidButtonDown(a1)
        clr.l   iid_MidButtonUp(a1)
        bra.b   .move
.rmb_down:
        move.l  #-1,iid_RightButtonDown(a1)
        clr.l   iid_RightButtonUp(a1)
        bra.b   .move
.lmb_up:
        move.l  #-1,iid_LeftButtonUp(a1)
        clr.l   iid_LeftButtonDown(a1)  
        bra.b   .move
.mmb_up:
        move.l  #-1,iid_MidButtonUp(a1)
        clr.l   iid_MidButtonDown(a1)  
        bra.b   .move
.rmb_up:
        move.l  #-1,iid_RightButtonUp(a1)
        clr.l   iid_RightButtonDown(a1)  
.move:
        move.w  ie_X(a0),d0
        muls    d1,d0
        move.l  d0,iid_MouseX(a1)
        move.w  ie_Y(a0),d0
        muls    d1,d0
        move.l  d0,iid_MouseY(a1)
.next:
        move.l  ie_NextEvent(a0),d0
        move.l  d0,a0
        bne     .loop
        move.l  (sp)+,d0
        rts
The InputIntData structure, which can be used by the application, looks like this:
Code:
        STRUCTURE       InputIntDat,0
        ULONG           iid_LeftButtonDown 
        ULONG           iid_MidButtonDown  
        ULONG           iid_RightButtonDown
        ULONG           iid_LeftButtonUp 
        ULONG           iid_MidButtonUp  
        ULONG           iid_RightButtonUp
        ULONG           iid_MouseX
        ULONG           iid_MouseY
        ULONG           iid_MouseSpeed
You can use iid_MouseSpeed to accelerate movements.
Depending on the type of your WB-application there might be even simpler solutions. E.g. via an IntuiMessage or reading MouseX and MouseY from your current Window. The shown input handler code would be used for an OS-friendly game, which needs full mouse control.
phx is offline  
Old 29 September 2011, 14:34   #7
Jekot
 
Posts: n/a
Big sanx. I sink use gadget in Intuition. Function gadget Followmouse.

Last edited by Jekot; 29 September 2011 at 15:10.
 
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Control amiga mouse with PC keyboard geecab support.WinUAE 2 16 August 2011 19:41
who knows good mouse control shmups? Falcon Flight Retrogaming General Discussion 13 29 December 2009 09:55
Using gamepad to control mouse buehlert support.WinUAE 4 25 January 2009 13:52
Worms DC control keys/mouse Boot_WB support.Games 9 16 July 2008 03:24
mouse control Marcuz request.UAE Wishlist 3 15 October 2004 13:22

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:01.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07828 seconds with 13 queries