]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
loadi seems to work now. hexrel-5
authorLeo C <erbl259-lmu@yahoo.de>
Thu, 23 Apr 2015 00:28:53 +0000 (02:28 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Thu, 23 Apr 2015 00:28:53 +0000 (02:28 +0200)
avr/cmd_loadihex.c
include/common.h

index 01fb6b0bea8c32a99b9bbbfb5f92e164611f826d..debccd7253ae5066d7941cfe558093833708a664 100644 (file)
@@ -12,7 +12,7 @@
 #include "command.h"
 #include "con-utils.h"
 #include "z80-if.h"
-//#include "debug.h"
+#include "debug.h"
 
 
 uint32_t detect_ramsize(void)
@@ -43,14 +43,6 @@ uint32_t detect_ramsize(void)
        return addr;
 }
 
-static uint32_t min(uint32_t a, uint32_t b)
-{
-       if (a < b)
-               return a;
-       return b;
-}
-
-
 typedef enum {
        IHX_OK,
        IHX_BROKEN,
@@ -93,74 +85,6 @@ int get_hexbyte(void) {
        return -1;
 }
 
-#if 0
-
-static
-ihex_t ihex_get_record() {
-
-       int i;
-       uint8_t sum, c;
-       ihex_t rec = { IHX_BROKEN, 0, 0, 0, 0 };
-
-
-       while ((c = my_getchar(0)) != ':')
-               if (c == 0x03)
-                       return rec;
-
-       if ((i = get_hexbyte()) < 0)            /* Start code */
-                       return rec;
-       sum = i;
-       rec.len = i;
-       if ((i = get_hexbyte()) < 0)            /* Byte Count */
-                       return rec;
-       sum += i;
-       rec.address = i * 256;
-       if ((i = get_hexbyte()) < 0)            /* Address */
-                       return rec;
-       sum += i;
-       rec.address += i;
-       if ((i = get_hexbyte()) < 0)            /* Record type */
-               return rec;
-       sum += i;
-       rec.type = i;
-
-       if (rec.len) {                                          /* Record Data */
-               uint8_t *p;     int k;
-               if ((rec.data = malloc(rec.len)) == 0)
-                       return rec;
-
-               for (p=rec.data, k=rec.len; k; k--) {
-                       if ((i = get_hexbyte()) < 0)
-                               break;
-                       sum += i;
-                       *p++ = i;
-               }
-
-               if (k) {
-                       free(rec.data); rec.data = 0;
-                       return rec;
-               }
-       }
-
-       i = get_hexbyte();                              /* Check sum */
-
-       if (i >= 0) {
-               sum += i;
-               if (sum == 0)
-                       rec.status = IHX_OK;
-               else
-                       rec.status = IHX_CHKSUMERR;
-       }
-
-       if (rec.status != IHX_OK) {
-               free(rec.data);
-               rec.data = 0;
-       }
-
-       return rec;
-}
-
-#else
 
 static
 int ihex_get_record(ihex_t *rec) {
@@ -220,7 +144,6 @@ int ihex_get_record(ihex_t *rec) {
        return rec->len;
 }
 
-#endif
 
 command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
@@ -235,9 +158,6 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
        (void) cmdtp; (void) flag;
 
 
-       printf_P(PSTR("RAM Size: 0x%.5lX\n"), address_max);
-
-
        if (argc > 1)
                offset = strtol(argv[1], NULL, 16);
 
@@ -254,9 +174,8 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
                                if (addr+rec.len > address_high)
                                        address_high = addr + rec.len;
 
-
-printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n"),
-               address_low, address_high, address_max, addr, rec.len);
+//                             debug("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d\n",
+//                                     address_low, address_high, address_max, addr, rec.len);
 
                                if (addr < address_max) {
                                        uint32_t tmplen = address_max - addr;
@@ -280,7 +199,7 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d
                        break;
 #endif
                case 2: /* Extended Segment Address Record */
-                       base_address = ((rec.data[0] << 8) + rec.data[1]) << 4;
+                       base_address = (uint32_t)((rec.data[0] << 8) + rec.data[1]) << 4;
                        break;
 
                case 4: /* Extended Linear Address Record */
@@ -306,15 +225,15 @@ printf_P(PSTR("low: 0x%.5lX, high: 0x%.5lX, max: 0x%.5lX, addr: 0x%.5lX, len: %d
        }
 
        printf_P(PSTR("Data loaded: "));
-       if (address_low >= min(address_high, address_max))
+       if (address_low >= MIN(address_high, address_max))
                printf_P(PSTR("None.\n"));
        else
                printf_P(PSTR("low: 0x%.5lX high: 0x%.5lX\n"), address_low,
-                               min(address_high, address_max) - 1);
+                               MIN(address_high, address_max) - 1);
 
        if (address_high > address_max)
                printf_P(PSTR("Data above highest RAM address "
-                       "(Range 0x%.5lX...0x%.5lX) ignored!\n"), address_max, address_high - 1);
+                       "(in range 0x%.5lX - 0x%.5lX) ignored!\n"), address_max, address_high - 1);
 
        return rcode;
 }
index cfbbae5c1fc1cf3185f18e67bb9983667d7f9080..10c4417d8b0c147de15a20e142a81fb93265a9d6 100644 (file)
@@ -52,6 +52,12 @@ struct bits {
 #define FSTR(X) ((const FLASH char[]) { X } )
 #define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))
 
+#define MIN(a,b)    ({ typeof (a) _a = (a);                                    \
+                                               typeof (b) _b = (b);                                   \
+                                               _a < _b ? _a : _b; })
+#define MAX(a,b)    ({ typeof (a) _a = (a);                                    \
+                                               typeof (b) _b = (b);                                   \
+                                               _a > _b ? _a : _b; })
 
 #ifdef __AVR__
 #define Stat GPIOR0