+; Copy the flags byte. It is located directly behind the jump vectors, so Y
+; is already correct when we come here. To save code, we use copyjv - crude
+; but effective.
+
+ jsr copyjv
+
+; Copy the callback vectors into the driver space
+
+ jsr popsreg
+ ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1)
+ sty tmp2
+ ldy #.sizeof(MOUSE_CALLBACKS)-1
+ sty tmp1
+
+@L2: jsr copycb
+ ldy tmp1
+ jsr copycb
+ dec tmp2 ; Skip opcode byte
+ ldy tmp1
+ bpl @L2
+
+; Install the IRQ vector if the driver needs it
+
+ bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ
+ bvc @L3 ; Jump if no interrupts at this time
+ jsr install_irq ; Activate IRQ routine
+
+; Call driver install routine and check for errors
+
+@L3: jsr mouse_install
+ tay ; Test error code
+ bne uninstall_irq ; Jump on error
+
+; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be
+; careful not to use A/X since these registers contain the error code from
+; INSTALL.