Code :
* Description : Mouse read and Output Window size demo
* Displays mouse coordinates, mouse button states,
* double click and keyboard keys Shift, Alt and Ctrl.
* Draws a green crosshair at mouse position.
* Pressing '1', '2', or '3' changes screen size.
*
* Trap #15 Task 60 Enable/Disable mouse IRQ
* An IRQ is created when a mouse button is pressed,
* released or moved in the output window.
* D1.W High Byte = IRQ level (1-7), 0 to turn off
* D1.W Low Byte = Mouse event that triggers IRQ:
* Bit2 = Move, Bit1 = Button Up, Bit0 = Button Down
* (Example D1.W = $0103, Enable mouse IRQ level 1 for Move, Button Up and Button Down)
* (Example D1.W - $0002, Disable mouse IRQ for Button Up)
*
* Trap #15 Task 61 reads mouse
* D1.B = 00 to read current state of mouse
* = 01 to read mouse up state
* = 02 to read mouse down state
* The mouse data is contained in the following registers
* D0 as bits = Ctrl, Alt, Shift, Double, Middle, Right, Left
* Left is Bit0, Right is Bit 1 etc.
* 1 = true, 0 = false
* Shift, Alt, Ctrl represent the state of the corresponding keys.
* D1.L = 16 bits Y, 16 bits X in pixel coordinates. (0,0 is top left)
*
* Trap #15 Task 33 - Get/Set Output Window Size
* D1.L High 16 bits = Width in pixels, min = 640
* Low 16 bits = Height in pixels, min = 480
* D1.L = 0, get current window size as
* High 16 bits = Width
* Low 16 bits = Height
*
*-----------------------------------------------------------
ORG $1000
start
; Initialize IRQ vectors
move.l #mouseDownIRQ,$64 ; IRQ1
move.l #mouseUpIRQ,$68 ; IRQ2
move.l #mouseMoveIRQ,$6C ; IRQ3
andi.w #$00,SR ; put CPU in User mode
move.w #$0101,d1 ; IRQ1 for mouse down
jsr MOUSE_IRQ
move.w #$0202,d1 ; IRQ2 for mouse up
jsr MOUSE_IRQ
move.w #$0304,d1 ; IRQ3 for mouse move
jsr MOUSE_IRQ
move.l #(800<<16+600),d1 ; 800 x 600
jsr RESOLUTION
jsr heading
*---- main program loop ----
loop nop
move.b #7,d0 ; check for pending key press
trap #15
if.b d1 <ne> #0 then.s ; if key is ready
jsr SAISCAR ; read key
if.b d1 <eq> #'1' then.s ; if '1' pressed
move.l #(640<<16+480),d1 ; 640 x 480
jsr RESOLUTION
endi
if.b d1 <eq> #'2' then.s ; if '2' pressed
move.l #(800<<16+600),d1 ; 800 x 600
jsr RESOLUTION
endi
if.b d1 <eq> #'3' then.s ; if '3' pressed
move.l #(1024<<16+768),d1 ; 1024 x 768
jsr RESOLUTION
endi
endi
nop
bra loop
* IRQ handlers
; mouse down handler
mouseDownIRQ
movem.l d0-d1,-(a7)
jsr heading
move.b #61,d0 ; read mouse
move.b #2,d1 ; mouse down state
trap #15
jsr showMouseData
movem.l (a7)+,d0-d1
rte
; mouse up handler
mouseUpIRQ
movem.l d0-d1,-(a7)
jsr heading
move.b #61,d0 ; read mouse
move.b #1,d1 ; mouse up state
trap #15
jsr showMouseData
movem.l (a7)+,d0-d1
rte
; mouse move handler
mouseMoveIRQ
movem.l d0-d1,-(a7)
jsr heading
move.b #61,d0 ; read mouse
move.b #0,d1 ; current mouse state
trap #15
jsr showMouseData
movem.l (a7)+,d0-d1
rte
MOUSE_IRQ
MOVE.B #60,D0
TRAP #15
RTS