Snippets

ScorpionIlluminati Mouse Code WIP

Created by ScorpionIlluminati last modified
MouseInit:
    move.w %00111100, pad_data_a                                               ; init controller 1 data
    move.w %00111100, pad_data_b                                               ; init controller 2 data
    move.w %00111100, pad_ctrl_a                                               ; init controller 1
    move.w %00111100, pad_ctrl_b                                               ; init controller 2
    rts


; *************************************************************
; Read the Mouse
; a0 controller port address
; a1 address to mouse strobe table
; a2 address to mouse header table
; d0 loop counter
; d1 mouse data
; d2 mouse header data
; d3 scatch 
; *************************************************************
ReadMouseA:
    lea pad_data_a, a0                                                         ; controller 1 data
    lea MouseStrobe, a1                                                        ; strobe data
    lea MouseHeader, a2                                                        ; header to make sure mouse in plugged in
    move.b #9, d0                                                              ; loop 9 times, the number of strobes required to get all the data
    move.w #0, d1                                                              ; mouse data goes here clear
@ReadMouseLoop:
    move.b (a1)+, d3                                                           ; move mouse strobe into scratch
    move.b d3, a0                                                              ; strobe the controller port
    move a0, d1                                                                ; store mouse data
    cmp.b #7, d0                                                               ; has the first 3 stobes completed already?
    blt.s @MouseHeaderDone                                                     ; if this has skip the checks
    move.b (a2), d2                                                            ; move the header into d2
    andi.b %00001111, d1                                                       ; clear high bits
    cmp.b d2, d1                                                               ; compare header with mouse data
    bne @MouseLoopExit                                                         ; if they don't match, something has gone wrong bail out
    move.b #0x0, d1                                                            ; the header info isn't useful to us so clear it's bits
@MouseHeaderDone:
    cmp.b #6, d0                                                               ; are we on the 4th strobe?
    bne.s @MouseCheckForOverflowDone                                           ; if not skip the check for overflow
    btst.l #$02, d1                                                            ; if the bit is set an x overflow has occurred and something is wrong
    beq @MouseLoopExit                                                         ; so bail out
    btst.l #$03, d1                                                            ; if the bit is set an y overflow has occurred and something is wrong
    beq @MouseLoopExit                                                         ; so bail out
@MouseCheckForOverflowDone
    lsl.l #04, d1                                                              ; shift 4 bits to the left
    bne @ReadMouseLoop                                                         ; loop until all the mouse data is read
@MouseLoopExit:
    rts

ReadMouseB:
    rts

MouseStrobe:
    dc.b %00010100                                                             ; $20
    dc.b %00000000                                                             ; $00
    dc.b %00010100                                                             ; $20
    dc.b %00000000                                                             ; $00
    dc.b %00010100                                                             ; $20
    dc.b %00000000                                                             ; $00
    dc.b %00010100                                                             ; $20
    dc.b %00000000                                                             ; $00
    dc.b %00010100                                                             ; $20

MouseHeader:
    dc.b %00001011                                                             ; first read
    dc.b %00001111                                                             ; second read
    dc.b %00001111                                                             ; third read

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.