From 744abda24f31cfb27529676e01d55141f8346f7e Mon Sep 17 00:00:00 2001
From: Oliver Schmidt 
Date: Sat, 1 Jun 2013 00:53:17 +0200
Subject: [PATCH] Added library reference mouse_libref to MOU interface.
---
 asminc/mouse-kernel.inc       |  3 ++-
 libsrc/apple2/libref.s        |  3 ++-
 libsrc/apple2/mou/a2.stdmou.s |  5 ++++-
 libsrc/c128/libref.s          |  3 ++-
 libsrc/c128/mou/c128-1351.s   |  6 +++++-
 libsrc/c128/mou/c128-joy.s    |  6 +++++-
 libsrc/c128/mou/c128-pot.s    |  6 +++++-
 libsrc/c64/libref.s           |  3 ++-
 libsrc/c64/mou/c64-1351.s     |  6 +++++-
 libsrc/c64/mou/c64-joy.s      |  6 +++++-
 libsrc/c64/mou/c64-pot.s      |  6 +++++-
 libsrc/mouse/mouse-kernel.s   | 11 ++++++++++-
 12 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/asminc/mouse-kernel.inc b/asminc/mouse-kernel.inc
index 24a9f7632..9db47fcb8 100644
--- a/asminc/mouse-kernel.inc
+++ b/asminc/mouse-kernel.inc
@@ -56,6 +56,7 @@
 .struct MOUSE_HDR
         ID              .byte   3       ; Contains 0x6D, 0x6F, 0x75 ("mou")
         VERSION         .byte   1       ; Interface version
+        LIBREF          .addr           ; Library reference
         JUMPTAB         .struct
             INSTALL     .addr
             UNINSTALL   .addr
@@ -96,7 +97,7 @@
 ;------------------------------------------------------------------------------
 ; The mouse API version, stored in MOUSE_HDR::VERSION
 
-MOUSE_API_VERSION       = $02
+MOUSE_API_VERSION       = $03
 
 ;------------------------------------------------------------------------------
 ; Bitmapped mouse driver flags, stored in MOUSE_HDR::FLAGS.
diff --git a/libsrc/apple2/libref.s b/libsrc/apple2/libref.s
index 933eb5911..09bdb057c 100644
--- a/libsrc/apple2/libref.s
+++ b/libsrc/apple2/libref.s
@@ -2,8 +2,9 @@
 ; Oliver Schmidt, 2013-05-31
 ;
 
-        .export         em_libref, joy_libref
+        .export         em_libref, joy_libref, mouse_libref
         .import         _exit
 
 em_libref       := _exit
 joy_libref      := _exit
+mouse_libref    := _exit
diff --git a/libsrc/apple2/mou/a2.stdmou.s b/libsrc/apple2/mou/a2.stdmou.s
index 30ef85c54..8414cde36 100644
--- a/libsrc/apple2/mou/a2.stdmou.s
+++ b/libsrc/apple2/mou/a2.stdmou.s
@@ -34,7 +34,10 @@ status          := $0778
         .byte   $6D, $6F, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-        ; Jump table.
+        ; Library reference
+        .addr   $0000
+
+        ; Jump table
         .addr   INSTALL
         .addr   UNINSTALL
         .addr   HIDE
diff --git a/libsrc/c128/libref.s b/libsrc/c128/libref.s
index 933eb5911..09bdb057c 100644
--- a/libsrc/c128/libref.s
+++ b/libsrc/c128/libref.s
@@ -2,8 +2,9 @@
 ; Oliver Schmidt, 2013-05-31
 ;
 
-        .export         em_libref, joy_libref
+        .export         em_libref, joy_libref, mouse_libref
         .import         _exit
 
 em_libref       := _exit
 joy_libref      := _exit
+mouse_libref    := _exit
diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s
index f7c74d3cb..f2a71647c 100644
--- a/libsrc/c128/mou/c128-1351.s
+++ b/libsrc/c128/mou/c128-1351.s
@@ -23,7 +23,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/c128/mou/c128-joy.s b/libsrc/c128/mou/c128-joy.s
index 3ac7b5ee3..8c3bd779d 100644
--- a/libsrc/c128/mou/c128-joy.s
+++ b/libsrc/c128/mou/c128-joy.s
@@ -22,7 +22,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/c128/mou/c128-pot.s b/libsrc/c128/mou/c128-pot.s
index 2713e3f4f..ab6922896 100644
--- a/libsrc/c128/mou/c128-pot.s
+++ b/libsrc/c128/mou/c128-pot.s
@@ -23,7 +23,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/c64/libref.s b/libsrc/c64/libref.s
index 933eb5911..09bdb057c 100644
--- a/libsrc/c64/libref.s
+++ b/libsrc/c64/libref.s
@@ -2,8 +2,9 @@
 ; Oliver Schmidt, 2013-05-31
 ;
 
-        .export         em_libref, joy_libref
+        .export         em_libref, joy_libref, mouse_libref
         .import         _exit
 
 em_libref       := _exit
 joy_libref      := _exit
+mouse_libref    := _exit
diff --git a/libsrc/c64/mou/c64-1351.s b/libsrc/c64/mou/c64-1351.s
index 7ffc0510e..ec053b0b2 100644
--- a/libsrc/c64/mou/c64-1351.s
+++ b/libsrc/c64/mou/c64-1351.s
@@ -42,7 +42,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/c64/mou/c64-joy.s b/libsrc/c64/mou/c64-joy.s
index 8390aa37d..05f0ce50e 100644
--- a/libsrc/c64/mou/c64-joy.s
+++ b/libsrc/c64/mou/c64-joy.s
@@ -41,7 +41,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/c64/mou/c64-pot.s b/libsrc/c64/mou/c64-pot.s
index 8ee0266e7..3eb977477 100644
--- a/libsrc/c64/mou/c64-pot.s
+++ b/libsrc/c64/mou/c64-pot.s
@@ -23,7 +23,11 @@ HEADER:
         .byte   $6d, $6f, $75           ; "mou"
         .byte   MOUSE_API_VERSION       ; Mouse driver API version number
 
-; Jump table.
+; Library reference
+
+        .addr   $0000
+
+; Jump table
 
         .addr   INSTALL
         .addr   UNINSTALL
diff --git a/libsrc/mouse/mouse-kernel.s b/libsrc/mouse/mouse-kernel.s
index 598b61ea2..2fa5b5e2d 100644
--- a/libsrc/mouse/mouse-kernel.s
+++ b/libsrc/mouse/mouse-kernel.s
@@ -4,7 +4,7 @@
 ; Common functions of the mouse driver API.
 ;
 
-        .import         return0, popsreg, incsp2
+        .import         return0, popsreg, incsp2, mouse_libref
         .importzp       sreg, ptr1, tmp1, tmp2
         .interruptor    mouse_irq               ; Export as IRQ handler
 
@@ -64,6 +64,15 @@ _mouse_install:
         dey
         bpl     @L0
 
+; Set the library reference
+
+        ldy     #MOUSE_HDR::LIBREF
+        lda     #mouse_libref
+        sta     (ptr1),y
+
 ; Reset flags
 
         lda     #1
-- 
2.39.5