]> git.sur5r.net Git - cc65/blobdiff - libsrc/apple2/apple2-stdmou.s
Dito for the enhanced apple2
[cc65] / libsrc / apple2 / apple2-stdmou.s
index f8a04c9e19c2063ae93f8b0745fa14429d58391e..0cedfcac4e475b5372242dc1048af9cd91164ebc 100644 (file)
@@ -6,6 +6,7 @@
 
        .include        "zeropage.inc"
        .include        "mouse-kernel.inc"
+       .include        "apple2.inc"
 
 ; ------------------------------------------------------------------------
 
@@ -46,6 +47,9 @@ status                := $0778
        .addr   IOCTL
        .addr   IRQ
 
+        ; Mouse driver flags
+        .byte   MOUSE_FLAG_EARLY_IRQ
+
        ; Callback table, set by the kernel before INSTALL is called
 CHIDE: jmp     $0000                   ; Hide the cursor
 CSHOW: jmp     $0000                   ; Show the cursor
@@ -55,10 +59,11 @@ CMOVEY: jmp $0000                   ; Move the cursor to Y coord
 ; ------------------------------------------------------------------------
 
        .bss
-       
+
+info:  .tag    MOUSE_INFO
 slot:  .res    1
 visible:.res   1
-               
+
 ; ------------------------------------------------------------------------
 
        .rodata
@@ -78,10 +83,6 @@ size = * - values
 ; ------------------------------------------------------------------------
 
        .data
-       
-info:  .word   279 / 2         ; MOUSE_INFO::MOUSE_POS::XCOORD
-       .word   191 / 2         ; MOUSE_INFO::MOUSE_POS::YCOORD
-       .byte   %00000000       ; MOUSE_INFO::BUTTONS
 
 firmware:
        ; Lookup and patch firmware address lobyte
@@ -95,7 +96,7 @@ xparam: ldx   #$FF            ; Patched at runtime
 yparam: ldy    #$FF            ; Patched at runtime
 
 jump:  jmp     $FFFF           ; Patched at runtime
-       
+
 ; ------------------------------------------------------------------------
 
        .code
@@ -127,15 +128,16 @@ next:     inc     ptr1+1
        bne     next
        dex
        bpl     :-
-       
+
        ; Get and patch firmware address hibyte
        lda     ptr1+1
        sta     lookup+2
        sta     xparam+1
        sta     jump+2
-       
+
        ; Convert to and save slot number
        and     #$0F
+       sei
        sta     slot
 
        ; Convert to and patch I/O register index
@@ -144,21 +146,24 @@ next:     inc     ptr1+1
        asl
        asl
        sta     yparam+1
-
-       ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
-       ; "Disable interrupts when calling any mouse routine."
-       sei
+       
+       ; The AppleMouse II Card needs the ROM switched in
+       ; to be able to detect an Apple //e and use RDVBL
+       bit     $C082
 
        ; Reset mouse hardware
        ldx     #INITMOUSE
        jsr     firmware
+       
+       ; Switch in LC bank 2 for R/O
+       bit     $C080
 
        ; Turn mouse on
        lda     #%00000001
        ldx     #SETMOUSE
        jsr     firmware
 
-       ; Set initial mouse clamps      
+       ; Set initial mouse clamps
        lda     #<279
        ldx     #>279
        sta     pos2_lo
@@ -189,6 +194,9 @@ next:       inc     ptr1+1
        ldx     #POSMOUSE
        jsr     firmware
 
+       ; Update cursor
+       jsr     update
+
        ; Turn VBL interrupt on
        lda     #%00001001
        ldx     #SETMOUSE
@@ -206,7 +214,7 @@ UNINSTALL:
        ; Hide cursor
        sei
        jsr     CHIDE
-       
+
        ; Turn mouse off
        lda     #%00000000
        ldx     #SETMOUSE
@@ -252,7 +260,7 @@ BOX:
        ldx     #$01            ; Set y clamps
        ldy     #$00            ; Start at top of stack
        jsr     :+
-       
+
        ldx     #$00            ; Set x clamps
        ldy     #$00            ; Start at top of stack
 
@@ -307,7 +315,7 @@ MOVE:
 
        ; Update cursor
        jsr     update
-       
+
        ldx     #POSMOUSE
        bne     common          ; Branch always
 
@@ -345,18 +353,22 @@ IOCTL:
        lda     #<MOUSE_ERR_INV_IOCTL
        ldx     #>MOUSE_ERR_INV_IOCTL
        rts
-       
+
 ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
 ; registers are already saved, no parameters are passed, but the carry flag
 ; is clear on entry. The routine must return with carry set if the interrupt
 ; was handled, otherwise with carry clear.
 IRQ:
+       ; Check for installed mouse
+       lda     slot
+       beq     done
+
        ; Check for mouse interrupt
        ldx     #SERVEMOUSE
        jsr     firmware
        bcc     :+
        clc                     ; Interrupt not handled
-       rts
+done:  rts
 
 :      ldx     #READMOUSE
        jsr     firmware
@@ -365,7 +377,7 @@ IRQ:
        ldy     slot
        lda     status,y
        tax                     ; Save status
-       
+
        ; Extract button down values
        asl                     ;  C = Button 0 is currently down
        and     #%00100000      ; !Z = Button 1 is currently down
@@ -376,7 +388,7 @@ IRQ:
 :      bcc     :+
        ora     #MOUSE_BTN_LEFT
 :      sta     info + MOUSE_INFO::BUTTONS
-       
+
        ; Check for mouse movement
        txa                     ; Restore status
        and     #%00100000      ; X or Y changed since last READMOUSE
@@ -384,7 +396,7 @@ IRQ:
 
        ; Remove the cursor at the old position
 update:        jsr     CHIDE
-       
+
        ; Get and set the new X position
        ldy     slot
        lda     pos1_lo,y
@@ -392,7 +404,7 @@ update:     jsr     CHIDE
        sta     info + MOUSE_POS::XCOORD
        stx     info + MOUSE_POS::XCOORD+1
        jsr     CMOVEX
-       
+
        ; Get and set the new Y position
        ldy     slot
        lda     pos2_lo,y