hexed: add jump cmd, refactor transfer
[megadrive.git] / hexed / pc_transfer.c
index 2263a6d..9e2681a 100644 (file)
@@ -1,3 +1,29 @@
+/*
+ * Copyright (c) 2011, GraÅžvydas Ignotas
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the organization nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -131,7 +157,8 @@ static void usage(const char *argv0)
 {
        fprintf(stderr, "usage:\n%s <cmd> [args]\n"
                "\tsend <file> <addr> [size]\n"
-               "\trecv <file> <addr> <size>\n", argv0);
+               "\trecv <file> <addr> <size>\n"
+               "\tjump <addr>\n", argv0);
        exit(1);
 }
 
@@ -209,6 +236,13 @@ int main(int argc, char *argv[])
 
                memset(data, 0, size);
        }
+       else if (strcmp(argv[1], "jump") == 0)
+       {
+               if (argc != 3)
+                       usage(argv[0]);
+
+               addr = atoi_or_die(argv[2]);
+       }
        else
                usage(argv[0]);
 
@@ -227,13 +261,12 @@ int main(int argc, char *argv[])
        if (inb(PORT_STATUS) & 0x40)
                printf("waiting for TH low..\n");
        while (inb(PORT_STATUS) & 0x40)
-               sleep(1);
+               usleep(100000);
 
        outb(0xe0, PORT_CONTROL);
 
        if (strcmp(argv[1], "send") == 0)
        {
-               printf("send %06x %06x\n", addr, size);
                send_cmd(CMD_MD_SEND);
                send_byte((addr >> 16) & 0xff);
                send_byte((addr >>  8) & 0xff);
@@ -277,9 +310,19 @@ int main(int argc, char *argv[])
 
                fwrite(data, 1, size, file);
        }
-       printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
-       printf("%06x/%06x\n", i, size);
-       fclose(file);
+       else if (strcmp(argv[1], "jump") == 0)
+       {
+               send_cmd(CMD_JUMP);
+               send_byte((addr >> 16) & 0xff);
+               send_byte((addr >>  8) & 0xff);
+               send_byte((addr >>  0) & 0xff);
+       }
+
+       if (file != NULL) {
+               printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
+               printf("%06x/%06x\n", i, size);
+               fclose(file);
+       }
 
        /* switch TL back to high, disable outputs */
        outb(0xe0, PORT_CONTROL);