-append support (Blue Swirl)
[qemu] / hw / cuda.c
index 8194016..b196862 100644 (file)
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -87,6 +87,9 @@
 #define CUDA_TIMER_FREQ (4700000 / 6)
 #define CUDA_ADB_POLL_FREQ 50
 
+/* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
+#define RTC_OFFSET                      2082844800
+
 typedef struct CUDATimer {
     unsigned int latch;
     uint16_t counter_value; /* counter value at load time */
@@ -461,17 +464,7 @@ static void cuda_send_packet_to_host(CUDAState *s,
     cuda_update_irq(s);
 }
 
-void adb_send_packet(ADBBusState *bus, const uint8_t *buf, int len)
-{
-    CUDAState *s = &cuda_state;
-    uint8_t data[16];
-
-    memcpy(data + 1, buf, len);
-    data[0] = ADB_PACKET;
-    cuda_send_packet_to_host(s, data, len + 1);
-}
-
-void cuda_adb_poll(void *opaque)
+static void cuda_adb_poll(void *opaque)
 {
     CUDAState *s = opaque;
     uint8_t obuf[ADB_MAX_OUT_LEN + 2];
@@ -513,7 +506,7 @@ static void cuda_receive_packet(CUDAState *s,
         break;
     case CUDA_GET_TIME:
         /* XXX: add time support ? */
-        ti = time(NULL);
+        ti = time(NULL) + RTC_OFFSET;
         obuf[0] = CUDA_PACKET;
         obuf[1] = 0;
         obuf[2] = 0;
@@ -532,6 +525,12 @@ static void cuda_receive_packet(CUDAState *s,
         obuf[1] = 0;
         cuda_send_packet_to_host(s, obuf, 2);
         break;
+    case CUDA_POWERDOWN:
+        obuf[0] = CUDA_PACKET;
+        obuf[1] = 0;
+        cuda_send_packet_to_host(s, obuf, 2);
+       qemu_system_shutdown_request();
+       break;
     default:
         break;
     }
@@ -555,13 +554,14 @@ static void cuda_receive_packet_from_host(CUDAState *s,
             uint8_t obuf[ADB_MAX_OUT_LEN + 2];
             int olen;
             olen = adb_request(&adb_bus, obuf + 2, data + 1, len - 1);
-            if (olen != 0) {
+            if (olen > 0) {
                 obuf[0] = ADB_PACKET;
                 obuf[1] = 0x00;
             } else {
-                /* empty reply */
+                /* error */
                 obuf[0] = ADB_PACKET;
-                obuf[1] = 0x02;
+                obuf[1] = -olen;
+                olen = 0;
             }
             cuda_send_packet_to_host(s, obuf, olen + 2);
         }