<html>
<body>
  <div id="body" style="background-color:#ffffff;" >
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head" style="border-bottom-width:1px;border-bottom-style:solid;" ><td class="headtd" style="padding:0;padding-top:.2em;" colspan="4">Commit in <b><tt>lxdream/src</tt></b></td></tr>
<tr><td><tt><a href="#file1">asic.c</a></tt></td><td id="added" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ddffdd;" align="right">+18</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-6</td><td class="headtd2" style="padding-left:.3em;padding-right:.3em;" nowrap="nowrap">d93175c36387 -> 377077d10d62</td></tr>
<tr class="alt" style=";" ><td><tt>maple/<a href="#file2">maple.c</a></tt></td><td id="addedalt" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ccf7cc;" align="right">+17</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-3</td><td class="headtd2" style="padding-left:.3em;padding-right:.3em;" nowrap="nowrap">d93175c36387 -> 377077d10d62</td></tr>
<tr><td></td><td id="added" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ddffdd;" align="right">+35</td><td id="removed" class="headtd2" style="padding-left:.3em;padding-right:.3em; background-color:#ffdddd;" align="right">-9</td><td></td></tr>
</table>
<small id="info" style="color: #888888;" >2 modified files</small><br />
<div class="tasklist" style="padding:4px;border:1px dashed #000000;margin-top:1em;" ><ul>
<li><a href="#task1">FIXME: Determine how long maple IO really takes to process, </a></li>
</ul></div>
<pre class="comment" style="white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd;" >
Add a 200us delay time for Maple requests, to avoid problems with games that
continually poll maple.

Patch by guinux, thanks!
</pre>
<hr /><a name="file1" /><div class="file" style="border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;" >
<span class="pathname" style="font-family:monospace; float:right;" >lxdream/src</span><br />
<div class="fileheader" style="margin-bottom:.5em;" ><big><b>asic.c</b></big> <small id="info" style="color: #888888;" >d93175c36387 -> 377077d10d62</small></div>
<pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >--- lxdream/src/asic.c
+++ lxdream/src/asic.c
@@ -21,6 +21,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
 #include <assert.h>
 #include <stdlib.h>
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+#include "eventq.h"
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > #include "dream.h"
 #include "mem.h"
 #include "sh4/intc.h"
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -416,6 +417,22 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     MMIO_WRITE( ASIC, SORTDMACTL, 0 );
 }
 
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+void maple_set_dma_state( uint32_t val )
+{
+    gboolean in_transfer = MMIO_READ( ASIC, MAPLE_STATE ) & 1;
+    gboolean transfer_requested = val & 1;
+    if( !in_transfer && transfer_requested ) {
+        /* Initiate new DMA transfer */
+        uint32_t maple_addr = MMIO_READ( ASIC, MAPLE_DMA) &0x1FFFFFE0;
+        maple_handle_buffer( maple_addr );
+    }
+    else if ( in_transfer && !transfer_requested ) {
+        /* Cancel current DMA transfer */
+        event_cancel( EVENT_MAPLE_DMA );
+    }
+    MMIO_WRITE( ASIC, MAPLE_STATE, val );
+}
+
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > gboolean asic_enable_ide_interface( gboolean enable )
 {
     gboolean oldval = idereg.interface_enabled;
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -494,12 +511,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >         }
         break;
     case MAPLE_STATE:
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-        MMIO_WRITE( ASIC, reg, val );
-        if( val & 1 ) {
-            uint32_t maple_addr = MMIO_READ( ASIC, MAPLE_DMA) &0x1FFFFFE0;
-            maple_handle_buffer( maple_addr );
-            MMIO_WRITE( ASIC, reg, 0 );
-        }
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+        maple_set_dma_state( val );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >         break;
     case PVRDMADEST:
         MMIO_WRITE( ASIC, reg, (val & 0x03FFFFE0) | 0x10000000 );
</pre></div>
<hr /><a name="file2" /><div class="file" style="border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;" >
<span class="pathname" style="font-family:monospace; float:right;" >lxdream/src/maple</span><br />
<div class="fileheader" style="margin-bottom:.5em;" ><big><b>maple.c</b></big> <small id="info" style="color: #888888;" >d93175c36387 -> 377077d10d62</small></div>
<pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >--- lxdream/src/maple/maple.c
+++ lxdream/src/maple/maple.c
@@ -19,6 +19,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > 
 #include <assert.h>
 #include <glib/gstrfuncs.h>
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+#include "eventq.h"
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > #include "dream.h"
 #include "mem.h"
 #include "asic.h"
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -32,9 +33,18 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > struct maple_device_class *maple_device_classes[] = { 
         &controller_class, &keyboard_class, &lightgun_class, &mouse_class, &vmu_class, NULL };
 
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+/**
+ * Fire interrupt to notify the completion of DMA transfer
+ */
+static void maple_event_handler( int eventid )
+{
+    MMIO_WRITE( ASIC, MAPLE_STATE, 0 );
+    asic_event( EVENT_MAPLE_DMA );
+}
+
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > void maple_init( void )
 {
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+    register_event_callback( EVENT_MAPLE_DMA, maple_event_handler );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" > }
 
 maple_device_t maple_new_device( const gchar *name )
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -130,7 +140,11 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >                     dev->start_gun(dev);
                     return; // Pending
                 } else {
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-                    asic_event( EVENT_MAPLE_DMA );
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" ><a name="task1" />+                    /* <span class="task" style="background-color:#ffff00;" >FIXME</span>: Determine how long maple IO really takes to process, 
+                     * which is probably a function of the number of requests.
+                     * For now, just use 0.2ms as a reasonable value.
+                     */
+                    event_schedule( EVENT_MAPLE_DMA, 200000 );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >                     return;
                 }
             case 7: /* skip */
</pre><pre class="diff" style="margin:0;" ><small id="info" style="color: #888888;" >@@ -299,7 +313,7 @@
</small></pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >             buf += 12 + (length<<2);
             address += 12 + (length<<2);
         }
</pre><pre id="removed" class="diff" style="margin:0; background-color:#ffdddd;" >-        asic_event( EVENT_MAPLE_DMA );
</pre><pre id="added" class="diff" style="margin:0; background-color:#ddffdd;" >+        event_schedule( EVENT_MAPLE_DMA, 200000 );
</pre><pre id="context" class="diff" style="margin:0; background-color:#eeeeee;" >     }
 }
 
</pre></div>
<center><small>Chaos Theory</small></center>
</div></body></html>