Bug fixes; get mouse working.

Fix bug in post causing PIC2 to not be initialized properly.
Only run ata_detect if CONFIG_ATA enabled.
Improve debugging aids - introduce debug_isr(); move DEBUGF to each file.
Enable mouse by default.
Fix bug in floppy causing extra test of PORT_FD_STATUS on recalibrate.
Always disable/enable kbd in handle_09 event.
diff --git a/src/ata.c b/src/ata.c
index 47d893f..440feab 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -926,5 +926,4 @@
     // FIXME : should use bios=cmos|auto|disable bits
     // FIXME : should know about translation bits
     // FIXME : move hard_drive_post here
-
 }
diff --git a/src/boot.c b/src/boot.c
index 19a4929..1ab9423 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -183,7 +183,8 @@
 void VISIBLE
 begin_boot()
 {
-    ata_detect();
+    if (CONFIG_ATA)
+        ata_detect();
     irq_enable();
     struct bregs br;
     memset(&br, 0, sizeof(br));
diff --git a/src/clock.c b/src/clock.c
index 6895876..a8c1d2e 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -10,6 +10,9 @@
 #include "disk.h" // floppy_tick
 #include "cmos.h" // inb_cmos
 
+#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
+#define DEBUGF(fmt, args...)
+
 static void
 init_rtc()
 {
@@ -257,7 +260,7 @@
 void VISIBLE
 handle_08(struct bregs *regs)
 {
-//    debug_enter(regs);
+//    debug_isr(regs);
 
     floppy_tick();
 
@@ -338,7 +341,7 @@
 void VISIBLE
 handle_70(struct bregs *regs)
 {
-    debug_enter(regs);
+    debug_isr(regs);
 
     // Check which modes are enabled and have occurred.
     u8 registerB = inb_cmos(CMOS_STATUS_B);
diff --git a/src/config.h b/src/config.h
index a440201..a984e5c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -3,10 +3,11 @@
 // Configuration definitions.
 
 #define CONFIG_FLOPPY_SUPPORT 1
-#define CONFIG_PS2_MOUSE 0
+#define CONFIG_PS2_MOUSE 1
 #define CONFIG_ATA 1
 #define CONFIG_KBD_CALL_INT15_4F 1
 #define CONFIG_ELTORITO_BOOT 0
+
 #define CONFIG_MAX_ATA_INTERFACES 4
 #define CONFIG_MAX_ATA_DEVICES  (CONFIG_MAX_ATA_INTERFACES*2)
 
diff --git a/src/disk.c b/src/disk.c
index f7497c7..8c84508 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -651,7 +651,7 @@
 void VISIBLE
 handle_76(struct bregs *regs)
 {
-    debug_enter(regs);
+    debug_isr(regs);
     SET_BDA(floppy_harddisk_info, 0xff);
     eoi_both_pics();
 }
diff --git a/src/floppy.c b/src/floppy.c
index 9131d98..5a7513b 100644
--- a/src/floppy.c
+++ b/src/floppy.c
@@ -12,6 +12,9 @@
 #include "util.h" // irq_disable
 #include "cmos.h" // inb_cmos
 
+#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
+#define DEBUGF(fmt, args...)
+
 #define BX_FLOPPY_ON_CNT 37   /* 2 seconds */
 
 // New diskette parameter table adding 3 parameters from IBM
@@ -149,9 +152,6 @@
     v &= ~FRS_TIMEOUT;
     SET_BDA(floppy_recalibration_status, v);
 
-    if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
-        BX_PANIC("int13_diskette: ctrl not ready\n");
-
     return 0;
 }
 
@@ -201,6 +201,10 @@
     if (ret)
         return ret;
 
+    // check port 3f4 for accessibility to status bytes
+    if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
+        BX_PANIC("int13_diskette: ctrl not ready\n");
+
     // read 7 return status bytes from controller
     u8 i;
     for (i=0; i<7; i++) {
@@ -347,6 +351,7 @@
 {
     // see if drive exists
     if (drive > 1 || !get_drive_type(drive)) {
+        // XXX - return type doesn't match
         floppy_fail(regs, DISK_RET_ETIMEOUT);
         return 1;
     }
@@ -712,7 +717,7 @@
 void VISIBLE
 handle_0e(struct bregs *regs)
 {
-    //debug_enter(regs);
+    //debug_isr(regs);
     if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0) {
         outb(0x08, PORT_FD_DATA); // sense interrupt status
         while ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
diff --git a/src/kbd.c b/src/kbd.c
index 498f08c..e1f01a5 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -544,15 +544,15 @@
 void VISIBLE
 handle_09(struct bregs *regs)
 {
-//    debug_enter(regs);
-
-    outb(0x0b, PORT_PIC1);
-    if ((inb(PORT_PIC1) & 0x02) == 0)
-        return;
+    //debug_isr(regs);
 
     // disable keyboard
     outb(0xad, PORT_PS2_STATUS);
 
+    outb(0x0b, PORT_PIC1);
+    if ((inb(PORT_PIC1) & 0x02) == 0)
+        goto done;
+
     // read key from keyboard controller
     u8 key = inb(PORT_PS2_DATA);
     irq_enable();
@@ -564,7 +564,7 @@
         tr.ah = 0x4f;
         tr.flags = F_CF;
         call16_int(0x15, &tr);
-        if (!tr.flags & F_CF)
+        if (!(tr.flags & F_CF))
             goto done;
         key = tr.al;
     }
diff --git a/src/mouse.c b/src/mouse.c
index e3c1789..fd46219 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -191,7 +191,6 @@
     //      1 =  50 dpi, 2 counts per millimeter
     //      2 = 100 dpi, 4 counts per millimeter
     //      3 = 200 dpi, 8 counts per millimeter
-    bprintf(0, "ebda_seg=%x\n", GET_BDA(ebda_seg));
     u8 comm_byte = inhibit_mouse_int_and_events(); // disable IRQ12 and packets
     if (regs->bh >= 4) {
         handle_ret(regs, RET_EUNSUPPORTED);
@@ -235,7 +234,6 @@
         handle_ret(regs, RET_EINTERFACE);
         return;
     }
-    bprintf(0, "ebda_seg=%x\n", GET_BDA(ebda_seg));
     SET_EBDA(mouse_flag1, 0x00);
     SET_EBDA(mouse_flag2, regs->bh);
 
@@ -340,7 +338,7 @@
 void
 handle_15c2(struct bregs *regs)
 {
-    debug_stub(regs);
+    //debug_stub(regs);
 
     if (! CONFIG_PS2_MOUSE) {
         handle_ret(regs, RET_EUNSUPPORTED);
@@ -417,7 +415,7 @@
 void VISIBLE
 handle_74(struct bregs *regs)
 {
-    debug_enter(regs);
+    //debug_isr(regs);
 
     irq_enable();
     int74_function();
diff --git a/src/output.c b/src/output.c
index 43eb128..0dcd20d 100644
--- a/src/output.c
+++ b/src/output.c
@@ -167,6 +167,13 @@
             , regs->ip, regs->cs, regs->flags);
 }
 
+void
+__debug_isr(const char *fname, struct bregs *regs)
+{
+    puts_cs(0, fname);
+    putc(0, '\n');
+}
+
 // Function called on handler startup.
 void
 __debug_enter(const char *fname, struct bregs *regs)
diff --git a/src/post.c b/src/post.c
index 0af8c0c..4a87eca 100644
--- a/src/post.c
+++ b/src/post.c
@@ -317,7 +317,7 @@
 pic_setup()
 {
     outb(0x11, PORT_PIC1);
-    outb(0x11, PORT_PIC2_DATA);
+    outb(0x11, PORT_PIC2);
     outb(0x08, PORT_PIC1_DATA);
     outb(0x70, PORT_PIC2_DATA);
     outb(0x04, PORT_PIC1_DATA);
diff --git a/src/system.c b/src/system.c
index 310a17e..e09797b 100644
--- a/src/system.c
+++ b/src/system.c
@@ -471,7 +471,7 @@
 void VISIBLE
 handle_nmi(struct bregs *regs)
 {
-    debug_enter(regs);
+    debug_isr(regs);
     // XXX
 }
 
@@ -479,7 +479,7 @@
 void VISIBLE
 handle_75(struct bregs *regs)
 {
-    debug_enter(regs);
+    debug_isr(regs);
 
     // clear irq13
     outb(0, PORT_MATH_CLEAR);
diff --git a/src/util.h b/src/util.h
index b858e8c..29446b3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -37,7 +37,6 @@
     asm volatile("nop");
 }
 
-#define DEBUGF(fmt, args...) bprintf(0, fmt , ##args)
 #define BX_PANIC(fmt, args...) bprintf(0, fmt , ##args)
 #define BX_INFO(fmt, args...) bprintf(0, fmt , ##args)
 
@@ -104,12 +103,15 @@
 void __debug_enter(const char *fname, struct bregs *regs);
 void __debug_exit(const char *fname, struct bregs *regs);
 void __debug_stub(const char *fname, struct bregs *regs);
+void __debug_isr(const char *fname, struct bregs *regs);
 #define debug_enter(regs) \
     __debug_enter(__func__, regs)
 #define debug_exit(regs) \
     __debug_exit(__func__, regs)
 #define debug_stub(regs) \
     __debug_stub(__func__, regs)
+#define debug_isr(regs) \
+    __debug_isr(__func__, regs)
 #define printf(fmt, args...)                     \
     bprintf(1, fmt , ##args )