From: notaz Date: Sun, 7 Sep 2014 18:55:24 +0000 (+0300) Subject: add progress bar X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6a44ec7c9f805fad62b78ade9340e1adab72f4a;p=saturn.git add progress bar this thing is slow.. --- diff --git a/datalink.c b/datalink.c index 94e2c6e..a2bdc70 100644 --- a/datalink.c +++ b/datalink.c @@ -41,6 +41,7 @@ #define BAUD_RATE 375000 #define MAX_DATA_SIZE 191 +#define PROGRESS_STEP (4 * 1024) static int setup(int fd) { @@ -96,6 +97,25 @@ static int setup(int fd) return 0; } +static void print_progress(int done, int total) +{ + int i, step; + + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); /* 20 */ + printf("\b\b\b\b\b\b"); + printf("%06x/%06x |", done, total); + + step = total / 20; + for (i = step; i <= total; i += step) + printf("%c", done >= i ? '=' : '-'); + printf("| %3d%%", done * 100 / total); + fflush(stdout); + + if (done == total) + printf("\n"); +} + static void dump_pkt(const uint8_t *buf, size_t size, const char *msg) { size_t i; @@ -207,6 +227,8 @@ static int recv_pkt(int fd, uint8_t cmd, uint32_t addr, static int do_rx(int fd, uint32_t addr, void *buf, size_t size) { + size_t size_total = size; + int progress_bytes = 0; char *cbuf = buf; int ret; int len; @@ -247,6 +269,12 @@ static int do_rx(int fd, uint32_t addr, void *buf, size_t size) addr += len; cbuf += len; size -= len; + + progress_bytes -= len; + if (progress_bytes <= 0 || size == 0) { + print_progress(size_total - size, size_total); + progress_bytes = PROGRESS_STEP; + } } return 0; @@ -254,6 +282,8 @@ static int do_rx(int fd, uint32_t addr, void *buf, size_t size) static int do_tx(int fd, uint32_t addr, void *buf, size_t size, int exe) { + int progress_bytes = 0; + size_t size_total = size; size_t size_last = size; uint32_t addr_last = addr; char *cbuf = buf; @@ -284,6 +314,13 @@ static int do_tx(int fd, uint32_t addr, void *buf, size_t size, int exe) addr += len; cbuf += len; size -= len; + + progress_bytes -= len; + if (progress_bytes <= 0) { + print_progress(size_total - size - size_last, + size_total); + progress_bytes = PROGRESS_STEP; + } } } @@ -298,6 +335,8 @@ static int do_tx(int fd, uint32_t addr, void *buf, size_t size, int exe) if (ret != 0) return ret; + print_progress(size_total, size_total); + return 0; } @@ -310,7 +349,18 @@ static void usage(const char *argv0) " tx [x]\n" " can be \"/hd/\" for a hexdump\n" " x instructs to execute uploaded data\n" - " for tx, size 0 asks to use filesize\n", argv0); + " for tx, size 0 asks to use filesize\n\n" + "useful regions (addr size):\n" + " 0x00000000 0x080000 - BIOS\n" + " 0x00180000 0x010000 - Backup-RAM\n" + " 0x00200000 0x100000 - Work-RAM-L\n" + " 0x05a00000 0x080000 - 68000-RAM\n" + " 0x05c00000 0x080000 - VDP1-VRAM\n" + " 0x05c80000 0x040000 - VDP1-FB\n" + " 0x05e00000 0x080000 - VDP2-VRAM\n" + " 0x05f00000 0x001000 - VDP2-CRAM\n" + " 0x06000000 0x100000 - Work-RAM-H\n" + , argv0); exit(1); }