How to Test Mouse Buttons in Assembler

All 680x0 related coding posts in this section please.

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

rockyone
Captain Atari
Captain Atari
Posts: 301
Joined: Thu Jan 20, 2011 8:47 pm
Contact:

How to Test Mouse Buttons in Assembler

Postby rockyone » Mon May 08, 2017 4:17 am

How to do this test in assembler ?
As I still have not found, I retrieve the mouse address in the database.

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2759
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby AtariZoll » Mon May 08, 2017 6:38 am

There is no separated/specific mouse address. You can test it at low level by accessing ACIA for IKBD chip - address is $FFFC02. There is protocol for sending information about any change at mouse - movement, button press and release. First goes header, then status bytes. All it is well described in Atari ProfiBuch for instance.
Easier will be using BIOS function 11 Kbshift .
English language is like bad boss on workplace: it expecting from you to strictly follow all, numerous rules, but self bending rules as much likes :mrgreen:

rockyone
Captain Atari
Captain Atari
Posts: 301
Joined: Thu Jan 20, 2011 8:47 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby rockyone » Mon May 08, 2017 8:10 am

Bios 11 returns the state of the keyboard, not the mouse buttons ???

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2759
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby AtariZoll » Mon May 08, 2017 10:19 am

rockyone wrote:Bios 11 returns the state of the keyboard, not the mouse buttons ???

Well, that's is what Atari ProfiBuch says. Maybe that works only in mouse keycode mode.
May use AES call GRAF_MKSTATE (AES 79). There is VDI call too, but only for left button.
Here can DL test program with ASM source: http://atari.8bitchip.info/astopensw.php
Mouse and joystick tester.
English language is like bad boss on workplace: it expecting from you to strictly follow all, numerous rules, but self bending rules as much likes :mrgreen:

seedy1812
Atari User
Atari User
Posts: 33
Joined: Tue May 18, 2010 2:04 pm

Re: How to Test Mouse Buttons in Assembler

Postby seedy1812 » Mon May 08, 2017 10:59 am

You can use Line A to get mouse buttons. Intitialise the table using $A000 and you get back the address of the table. MOUSE_BT which has the offset -596 ( word ) should contain a bitmap of the current mouse buttons

rockyone
Captain Atari
Captain Atari
Posts: 301
Joined: Thu Jan 20, 2011 8:47 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby rockyone » Mon May 08, 2017 3:31 pm

I tested at a low level, but I bug the mouse every time ......

thank you for your answers,
I had not thought about line A

The test I do currently works well, but well it's to find out ... :coffe:
move.w 4(sp), a0,.....VARPTR (MOUSEBUT) +6
tst.b 1(a0)
beq.s no_button

czietz
Hardware Guru
Hardware Guru
Posts: 443
Joined: Tue May 24, 2016 6:47 pm

Re: How to Test Mouse Buttons in Assembler

Postby czietz » Mon May 08, 2017 4:10 pm

rockyone wrote:Bios 11 returns the state of the keyboard, not the mouse buttons ???


I think that even it doesn't say so explicitly in ...

http://toshyp.atari.org/en/About_the_BIOS.html#Kbshift

... these bits only reflect the status of the mouse buttons emulated by Alt+Insert and Alt+ClrHome:

Bit Meaning
[...]
5 Right mouse button
6 Left mouse button
Last edited by czietz on Mon May 08, 2017 4:20 pm, edited 1 time in total.

czietz
Hardware Guru
Hardware Guru
Posts: 443
Joined: Tue May 24, 2016 6:47 pm

Re: How to Test Mouse Buttons in Assembler

Postby czietz » Mon May 08, 2017 4:19 pm

.

rockyone
Captain Atari
Captain Atari
Posts: 301
Joined: Thu Jan 20, 2011 8:47 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby rockyone » Mon May 08, 2017 4:26 pm

czietz wrote:... these bits only reflect the status of the mouse buttons emulated by Alt+Insert and Alt+ClrHome:


Of course, the simulation of the buttons by the keyboard works well as well

User avatar
Greenious
Hardware Guru
Hardware Guru
Posts: 1160
Joined: Sat Apr 24, 2004 5:39 pm
Location: Sweden

Re: How to Test Mouse Buttons in Assembler

Postby Greenious » Mon May 08, 2017 5:16 pm

rockyone wrote:How to do this test in assembler ?
As I still have not found, I retrieve the mouse address in the database.


I did write a mouse/keyboard routine in assembler once. Pity I have no access to my sources or I would give it to you.

But what I remember is, if you are doing this by directly accessing the hardware, there is a special header coming from the IKBD indicating it's mousedata, followed by movement and/or buttonclicks. Movement can also be defined as either relative or absolute, ie, the movements either is direction/distance, or absolute position, you instruct the IKBD which way you want it.
Updated my guides as of june 28th, 2016. Check'em out and feedback!
viewtopic.php?t=5040

rockyone
Captain Atari
Captain Atari
Posts: 301
Joined: Thu Jan 20, 2011 8:47 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby rockyone » Mon May 08, 2017 8:40 pm

Too bad .. I would see this weekend, I think I had inverted $fc00 and $fc02.
I will also test with line A

joefish
Atari freak
Atari freak
Posts: 62
Joined: Thu Dec 05, 2013 4:15 pm

Re: How to Test Mouse Buttons in Assembler

Postby joefish » Fri May 12, 2017 3:50 pm

I haven't done it in years, but I seem to remember first you register an interrupt routine to respond to a signal from the keyboard chip.
Then you send a BIOS message to tell the keyboard chip to operate the mouse in either 'absolute-position' or 'relative' mode.

To read it, you use another BIOS call to poll the keyboard chip. Then about 5ms later your interrupt routine gets triggered with a report, and it can copy the mouse buttons and position status from a particular address.

I seem to remember you read the joystick(s) the same way. And it's a real nuisance as if you poll the mouse on the 50Hz interrupt, it responds with a high-priority interrupt when the first few lines of the screen are being drawn, which can interfere with your nice pretty raster colours on the line counter interrupt!

You'd have to look up the relevant BIOS calls yourself though.

AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2759
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby AtariZoll » Fri May 12, 2017 5:03 pm

joefish wrote:I haven't done it in years, but I seem to remember first you register an interrupt routine to respond to a signal from the keyboard chip.
Then you send a BIOS message to tell the keyboard chip to operate the mouse in either 'absolute-position' or 'relative' mode.
To read it, you use another BIOS call to poll the keyboard chip. Then about 5ms later your interrupt routine gets triggered with a report, and it can copy the mouse buttons and position status from a particular address.
I seem to remember you read the joystick(s) the same way. And it's a real nuisance as if you poll the mouse on the 50Hz interrupt, it responds with a high-priority interrupt when the first few lines of the screen are being drawn, which can interfere with your nice pretty raster colours on the line counter interrupt!
You'd have to look up the relevant BIOS calls yourself though.


That's only approximately accurate what you write. I can give here complete low level code what works on that base:
1. Setting ACIA MFP interrupt to own code - may with BIOS call or just simple write to $118
2. For relative mode no need to send anything , it's default. And since we talk about buttons, relative or. abs. mode is irrelevant.
3. To poll IKBD chip no need for special call - that's hob of our ACIA interrupt code.
Yes, joystick read is very similar. Actually, all it can be read with same interrupt routine, Together with keyboard read. That's what many SW does.And TOS too.
There is no high priority interrupt for ACIA actually - you can set IR level 7, and it will not interfere. And trigger delay is not 5mS, but whole time needed to read mouse is about it - because it must send 4 bytes in 4 steps for mouse. Datarate is some 7.8 Kbits/sec. So, little more than 1mS for 1 byte.

But much simpler is to do with help of TOS. Like it is done in given src code. (link above)

Code: Select all

Parts of it:


  * Doing mouse pos displaying:
* AES call used
   graf_mkstate   *Get mouse cursor pos and button states
* here will get back all you need, following is only for displaying


   move.w  intout+2(pc),d1   *X pos
   cmp.w  lastx(pc),d1    * Skip if  not moved. otherwise cursor flashes
   beq.s  seeyp
   move.w  d1,lastx
   lea   text9(pc),a1
   bsr  decpri

* Redraw it:
   moveq  #HPOS,d0
   bsr   obdr
 
seeyp  move.w  intout+4(pc),d1   *Y pos
   cmp.w  lasty(pc),d1
   beq.s  drawmbs
   move.w  d1,lasty
   lea   text8(pc),a1
   bsr  decpri

* Redraw it:
   moveq  #VPOS,d0
   bsr   obdr

* Draw mouse button states only when changes:
drawmbs
  move.w  intout+6(pc),d1
  move.w  mouprev(pc),d2
  cmp.b  d1,d2
  beq.s  samemoub

*****
 
 
* Setting joystick monitoring rutine :

   move.w  #34,-(sp)   *Kbdvbase
   trap   #14
   addq.l    #2,sp   
 
   move.l  d0,a1
   lea 24(a1),a1   * Joystick vector
   move.l  (a1),joymorg  *Save original one (which is just an rts)
   move.l  #moni,(a1)
   ******
   joystol
  move.w  joyc(pc),joyst   *Store latest state

joytex
   rts

joyst  dc.w  0   *Latest joystick state

moni     * Joystick monitoring, very simple:
  * it is at joyvec address set with   XBIOS 34

    addq.l  #1,a0   *a0 is odd
    move.w  (a0),joyc    * first byte is for joy 0, second for joy 1
    rts   



Doing it (mouse read) with Line-A table is simplest way, as some suggested.
English language is like bad boss on workplace: it expecting from you to strictly follow all, numerous rules, but self bending rules as much likes :mrgreen:

User avatar
Greenious
Hardware Guru
Hardware Guru
Posts: 1160
Joined: Sat Apr 24, 2004 5:39 pm
Location: Sweden

Re: How to Test Mouse Buttons in Assembler

Postby Greenious » Fri May 12, 2017 5:28 pm

Atari Compendium, section 5:10
http://dev-docs.atariforge.org/files/Th ... endium.pdf

Every nitty gritty detail you need.
Updated my guides as of june 28th, 2016. Check'em out and feedback!
viewtopic.php?t=5040

User avatar
dhedberg
Atari Super Hero
Atari Super Hero
Posts: 530
Joined: Mon Aug 30, 2010 8:36 am
Contact:

Re: How to Test Mouse Buttons in Assembler

Postby dhedberg » Fri May 12, 2017 6:30 pm

This is probably overkill, but here's my custom ACIA handler. It can be used to read the keyboard, mouse and joysticks. It's pretty well documented. Feel free to use it... or ignore it! :-)

Code: Select all

;==========================================================================================
; Custom ACIA Interrupt Handler v1.3
;==========================================================================================
;
; Custom ACIA handler for MIDI and IKBD. MIDI data is discarded. IKBD data is stored
; in custom data buffers.
;
; Functions:
; ----------------------------------------------------------------------------------------
; installAcia   Installs the custom ACIA interrupt handler. No registers modified.
; uninstallAcia   Uninstalls the custom ACIA interrupt handler and restores the old handler.
;               No registers modified.
; flushIkbd   Removes unread IKBD data from the ACIA. No registers modified.
; flushMidi   Removes unread MIDI data from the ACIA. No registers modified.
;
; Data:
; ----------------------------------------------------------------------------------------
; aciaKeyboardData   128 bytes
;         One byte is used for every key scan code. All bits of a byte are
;         set while the corresponding key is being pressed. Once the key is
;         released, all bits of the byte are cleared again.
; aciaMouseData      2 words + 1 byte
;         First word is the accumulated relative x position of the mouse,
;         second word is the accumulated relative y position. The byte
;         contains the most recent mouse button status, bit 0: left button,
;         bit 1: right button.
; aciaJoystickData   2 bytes
;         First byte is joystick 0 data, second byte is joystick 1 data.
;==========================================================================================
; Author: Daniel Hedberg, daniel.hedberg@gmail.com
; Last Modified: 2014-01-07
;==========================================================================================

   SECTION TEXT

;==========================================================================================
; Function: installAcia
; Installs the custom ACIA interrupt handler.
;
; No registers modified.
;==========================================================================================

installAcia:   movem.l   d0/a0,-(sp)      ; Save registers

      ; Clear keyboard buffer.
      lea   aciaKeyboardData,a0
      moveq   #128/4-1,d0
.clear:      clr.l   (a0)+
      dbf   d0,.clear

      bsr.s   flushAcia      ; Uses registers: d0.b

      ; Save current ACIA interrupt handler and install custom handler.
      move.w   sr,d0
      or.w   #$700,sr      ; Disable all interrupts
      move.l   $118.w,oldAcia      ; Save ACIA interrupt vector
      move.l   #acia,$118.w      ; Set ACIA interrupt vector
      move.w   d0,sr

      movem.l   (sp)+,d0/a0      ; Restore registers
      rts

;==========================================================================================
; Function: uninstallAcia
; Uninstalls the custom ACIA interrupt handler and restores the old handler.
;
; No registers modified.
;==========================================================================================

uninstallAcia:   movem.l   d0,-(sp)      ; Save registers
      move.w   sr,d0
      or.w   #$700,sr      ; Disable all interrupts
      move.l   oldAcia,$118.w      ; Restore ACIA interrupt vector
      move.w   d0,sr

      bsr.s   flushAcia      ; Uses registers: d0.b
      move.l   (sp)+,d0      ; Restore registers
      rts

;==========================================================================================
; Function: flushAcia
; Removes unread MIDI and IKBD data from the ACIA.
;
; Modified registers: d0.b
;==========================================================================================

flushAcia:   move.b   $FFFFFC04.w,d0
      btst   #0,d0
      bne.s   .readMidi
      move.b   #0,$FFFFFC06.w
      bra.s   .flushIkbd
.readMidi:   move.b   $FFFFFC04.w,d0
      bra.s   flushAcia

.flushIkbd:   move.b   $FFFFFC00.w,d0
      btst   #0,d0
      bne.s   .readIkbd
      move.b   #0,$FFFFFC02.w
      rts
.readIkbd:   move.b   $FFFFFC02.w,d0
      bra.s   .flushIkbd

;==========================================================================================
; ISR: ACIA
;
; Custom ACIA interrupt handler (main).
;==========================================================================================

acia:      movem.l   d0-d1/a0,-(sp)      ; Save registers

;------------------------------------------------------------------------------------------
; MIDI HANDLER
;------------------------------------------------------------------------------------------

aciaMidi:   move.b   $FFFFFC04.w,d0
      btst   #7,d0         ; MIDI interrupt request?
      beq.s   aciaIkbd      ; No, check for IKBD interrupt requests

      btst   #4,d0         ; Framing error?
      bne.s   .midiError
      btst   #5,d0          ; Receiver (Rx data register) overrun?
      bne.s   .midiError
      btst   #6,d0         ; Parity error?
      bne.s   .midiError
      btst   #0,d0         ; Receiver (Rx data register) full?
      beq.w   aciaExit      ; No, nothing to read

      move.b   $FFFFFC06.w,d0      ; Read and throw away MIDI data
      bra.w   aciaExit

.midiError:   ; Make sure MIDI Rx data register is empty
      move.b   $FFFFFC04.w,d0
      btst   #0,d0
      beq.w   aciaExit
      move.b   $FFFFFC06.w,d0
      bra.s   .midiError

;------------------------------------------------------------------------------------------
; IKBD HANDLER
;------------------------------------------------------------------------------------------

aciaIkbd:   move.b   $FFFFFC00.w,d0

      btst   #7,d0         ; IKBD interrupt request?
      beq.w   aciaExit      ; No, nothing to do.

      btst   #4,d0         ; Framing error?
      bne.w   aciaIkbdError
      btst   #5,d0         ; Receiver (Rx data register) overrun?
      bne.w   aciaIkbdError
      btst   #6,d0         ; Parity error?
      bne.w   aciaIkbdError
      btst   #0,d0         ; Receiver (Rx data register) full?
      beq.s   aciaExit      ; No, nothing to read

      move.b   $FFFFFC02.w,d0      ; Read IKBD data

      cmp.b   #$F6,d0
      bcs.s   .readKeyboard
      cmp.b   #$FD,d0
        blt.s   .readMouse

.readJoystick:   and.w   #1,d0
      move.w   d0,ikbdIdentifier
      ; Set ACIA interrupt vector to handle joystick data
      move.w   sr,d1
      or.w   #$700,sr      ; Disable all interrupts
      move.l   #aciaJoystick,$118.w   ; Set ACIA interrupt vector
      move.w   d1,sr
      bra.s   aciaExit

.readMouse:   and.b   #%11,d0
      move.b   d0,aciaMouseData+4
      clr.w   ikbdIdentifier
      ; Set ACIA interrupt vector to handle mouse data
      move.w   sr,d1
      or.w   #$700,sr      ; Disable all interrupts
      move.l   #aciaMouse,$118.w   ; Set ACIA interrupt vector
      move.w   d1,sr
      bra.s   aciaExit

.readKeyboard:   btst   #7,d0
      seq   d1
      and.w   #$7F,d0
      lea   aciaKeyboardData,a0
      move.b   d1,(a0,d0.w)

aciaExit:   bclr   #6,$FFFFFA11.w      ; Interrupt not in service
      movem.l   (sp)+,d0-d1/a0      ; Restore registers
      rte

aciaResetAndExit:
      ; Reset ACIA interrupt vector to main ACIA handler before exiting.
      move.w   sr,d1
      or.w   #$700,sr      ; Disable all interrupts
      move.l   #acia,$118.w      ; Set ACIA interrupt vector
      move.w   d1,sr
      bra.s   aciaExit

aciaIkbdError:   ; Reset ACIA interrupt vector to main ACIA handler.
      move.w   sr,d1
      or.w   #$700,sr      ; Disable all interrupts
      move.l   #acia,$118.w      ; Set ACIA interrupt vector
      move.w   d1,sr

      ; Make sure IKBD Rx data register is empty
.emptyRx:   btst   #0,$FFFFFC00.w
      beq.s   aciaExit
      move.b   $FFFFFC02.w,d0
      bra.s   .emptyRx

;==========================================================================================
; ISR: ACIA
;
; Custom ACIA interrupt handler (joystick).
;==========================================================================================

aciaJoystick:   movem.l   d0-d1/a0,-(sp)      ; Save registers

      move.b   $FFFFFC00.w,d0

      btst   #7,d0         ; IKBD interrupt request?
      beq.s   aciaResetAndExit   ; No, reset ACIA interrupt vector and abort

      btst   #4,d0         ; Framing error?
      bne.s   aciaIkbdError
      btst   #5,d0         ; Receiver (Rx data register) overrun?
      bne.s   aciaIkbdError
      btst   #6,d0         ; Parity error?
      bne.s   aciaIkbdError
      btst   #0,d0         ; Receiver (Rx data register) full?
      beq.s   aciaResetAndExit   ; No, reset ACIA interrupt vector and abort

      lea   aciaJoystickData,a0
      move.w   ikbdIdentifier,d0   ; Joystick ID (0 or 1)
      move.b   $FFFFFC02.w,(a0,d0.w)
      bra.s   aciaResetAndExit

;==========================================================================================
; ISR: ACIA
;
; Custom ACIA interrupt handler (mouse).
;==========================================================================================

aciaMouse:   movem.l   d0-d1/a0,-(sp)      ; Save registers

      move.b   $FFFFFC00.w,d0

      btst   #7,d0         ; IKBD interrupt request?
      beq.s   aciaResetAndExit   ; No, reset ACIA interrupt vector and abort

      btst   #4,d0         ; Framing error?
      bne.s   aciaIkbdError
      btst   #5,d0         ; Receiver (Rx data register) overrun?
      bne.s   aciaIkbdError
      btst   #6,d0         ; Parity error?
      bne.s   aciaIkbdError
      btst   #0,d0         ; Receiver (Rx data register) full?
      beq.w   aciaResetAndExit   ; No, reset ACIA interrupt vector and abort

      move.b   $FFFFFC02.w,d0      ; Relative mouse position
      ext.w   d0
      lea   aciaMouseData,a0
      move.w   ikbdIdentifier,d1   ; Mouse axis (0 = x pos, 2 = y pos)
      add.w   d0,(a0,d1.w)

      tst.w   d1         ; More mouse data?
      bne.w   aciaResetAndExit   ; No, reset ACIA interrupt vector and exit
      move.w   #2,ikbdIdentifier   ; Mouse y axis is next
      bra.w   aciaExit

;==========================================================================================
; SECTION DATA AND BSS
;==========================================================================================

;------------------------------------------------------------------------------------------
; IKBD DATA BUFFERS
;------------------------------------------------------------------------------------------

   SECTION BSS

      even

aciaKeyboardData:   ds.b   128      ; Keyboard data

aciaMouseData:      ds.w   1      ; Relative mouse X position
         ds.w   1      ; Relative mouse Y position
         ds.b   1      ; Mouse button status

aciaJoystickData:   ds.b   1      ; Joystick 0 data
         ds.b   1      ; Joystick 1 data

;------------------------------------------------------------------------------------------
; INTERNAL IKBD BUFFER
;------------------------------------------------------------------------------------------

ikbdIdentifier:      ds.w   1

;------------------------------------------------------------------------------------------
; SAVE DATA BUFFERS
;------------------------------------------------------------------------------------------

oldAcia:      ds.l   1

   SECTION TEXT
Daniel, New Beat - http://newbeat.atari.org

seedy1812
Atari User
Atari User
Posts: 33
Joined: Tue May 18, 2010 2:04 pm

Re: How to Test Mouse Buttons in Assembler

Postby seedy1812 » Fri May 12, 2017 6:31 pm

If you look at 5.9 in compendium you can intercept the mouse vector and read the packet yourself ( then pass it onto the OS ).


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 5 guests