Added simple assertions to help bug tracking
[fw/sdcc] / as / mcs51 / lkihx.c
index 77d7b9acac7881c085de6f95d32dea3b692d02ea..461d56799f74290d5ac477691043d1b44e8968ad 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <alloc.h>
 #include "aslink.h"
 
 /*)Module      lkihx.c
  *     in the standard Intel Hex format.
  *
  *     local variables:
- *             addr_t  chksum          byte checksum
+ *             Addr_T  chksum          byte checksum
  *
  *     global variables:
  *             int     hilo            byte order
  *             FILE *  ofp             output file handle
  *             int     rtcnt           count of data words
  *             int     rtflg[]         output the data flag
- *             addr_t  rtval[]         relocated data
+ *             Addr_T  rtval[]         relocated data
  *
  *     functions called:
  *             int     fprintf()       c_library
 VOID
 ihx(i)
 {
-       register addr_t chksum;
-
+       register Addr_T chksum;
+       int byte, bytes, address=0;
        if (i) {
                if (hilo == 0) {
                        chksum = rtval[0];
@@ -118,16 +117,35 @@ ihx(i)
                                chksum++;
                }
                fprintf(ofp, ":%02X", chksum);
+               // how much bytes?
+               for (i=0, bytes=0; i<rtcnt; i++) {
+                 if (rtflg[i]) {
+                   bytes++;
+                 }
+               }
+               byte=0;
                for (i = 0; i < rtcnt ; i++) {
-                       if (rtflg[i]) {
-                               fprintf(ofp, "%02X", rtval[i]);
-                               chksum += rtval[i];
-                       }
-                       if (i == 1) {
-                               fprintf(ofp, "00");
-                       }
+                 if (rtflg[i]) {
+                   switch (byte) {
+                   case 0: 
+                     address=rtval[0]<<8; 
+                     break;
+                   case 1: 
+                     address+=rtval[1]; 
+                     if ((address+bytes)>0xffff) {
+                       fprintf (stderr, "64k boundary cross at %04x\n", address);
+                     }
+                     break;
+                   }
+                   fprintf(ofp, "%02X", rtval[i]);
+                   chksum += rtval[i];
+                   byte++;
+                 }
+                 if (i == 1) {
+                   fprintf(ofp, "00");
+                 }
                }
-               fprintf(ofp, "%02X\n", (-chksum) & 0xff);
+               fprintf(ofp, "%02X\n", (0-chksum) & 0xff);
        } else {
                fprintf(ofp, ":00000001FF\n");
        }
@@ -135,13 +153,13 @@ ihx(i)
 
 /*)Function    ihxEntendedLinearAddress(i)
  *
- *             addr_t  i               16 bit extended linear address.
+ *             Addr_T  i               16 bit extended linear address.
  *
  *     The function ihxEntendedLinearAddress() writes an extended
  *     linear address record (type 04) to the output file.
  *
  *     local variables:
- *             addr_t  chksum          byte checksum
+ *             Addr_T  chksum          byte checksum
  *
  *     global variables:
  *             FILE *  ofp             output file handle
@@ -153,9 +171,9 @@ ihx(i)
  *             The data is output to the file defined by ofp.
  */
 VOID
-ihxEntendedLinearAddress(addr_t a)
+ihxEntendedLinearAddress(Addr_T a)
 {
-    addr_t     chksum;
+    Addr_T     chksum;
   
     /* The checksum is the complement of the bytes in the
      * record: the 2 is record length, 4 is the extended linear
@@ -163,5 +181,5 @@ ihxEntendedLinearAddress(addr_t a)
      */ 
     chksum = 2 + 4 + (a & 0xff) + ((a >> 8) & 0xff);    
     
-    fprintf(ofp, ":02000004%04X%02X\n", a & 0xffff, (-chksum) & 0xff);
-}
\ No newline at end of file
+    fprintf(ofp, ":02000004%04X%02X\n", a & 0xffff, (0-chksum) & 0xff);
+}