This file should not be needed anymore
[fw/sdcc] / as / mcs51 / lks19.c
1 /* lks19.c */
2
3 /*
4  * (C) Copyright 1989-1995
5  * All Rights Reserved
6  *
7  * Alan R. Baldwin
8  * 721 Berkeley St.
9  * Kent, Ohio  44240
10  */
11
12 #include <stdio.h>
13 #include <string.h>
14 //#if !defined(_MSC_VER)
15 //#include <alloc.h>
16 //#endif
17 #include "aslink.h"
18
19 /*)Module       lks19.c
20  *
21  *      The module lks19.c contains the function to
22  *      output the relocated object code in the
23  *      Motorola S19 format.
24  *
25  *      lks19.c contains the following function:
26  *              VOID    s19(i)
27  *
28  *      lks19.c contains no local variables.
29  */
30
31 /*)S19 Format
32  *      Record Type Field    -  This  field  signifies  the  start  of a
33  *                              record and  identifies  the  the  record
34  *                              type as follows:  
35  *
36  *                                  Ascii S1 - Data Record 
37  *                                  Ascii S9 - End of File Record 
38  *
39  *      Record Length Field  -  This  field  specifies the record length
40  *                              which includes the  address,  data,  and
41  *                              checksum   fields.   The  8  bit  record
42  *                              length value is converted to  two  ascii
43  *                              characters, high digit first.  
44  *
45  *      Load Address Field   -  This  field  consists  of the four ascii
46  *                              characters which result from  converting
47  *                              the  the  binary value of the address in
48  *                              which to begin loading this record.  The
49  *                              order is as follows:  
50  *
51  *                                  High digit of high byte of address. 
52  *                                  Low digit of high byte of address.  
53  *                                  High digit of low byte of address.  
54  *                                  Low digit of low byte of address.  
55  *
56  *                              In an End of File record this field con-
57  *                              sists of either four ascii zeros or  the
58  *                              program  entry  address.   Currently the
59  *                              entry address option is not supported.  
60  *
61  *      Data Field           -  This  field consists of the actual data,
62  *                              converted to two ascii characters,  high
63  *                              digit first.  There are no data bytes in
64  *                              the End of File record.  
65  *
66  *      Checksum Field       -  The  checksum  field is the 8 bit binary
67  *                              sum of the record length field, the load
68  *                              address field, and the data field.  This
69  *                              sum is then  complemented  (1's  comple-
70  *                              ment)   and   converted   to  two  ascii
71  *                              characters, high digit first.  
72  */
73
74 /*)Function     s19(i)
75  *
76  *              int     i               0 - process data
77  *                                      1 - end of data
78  *
79  *      The function s19() outputs the relocated data
80  *      in the standard Motorola S19 format.
81  *
82  *      local variables:
83  *              Addr_T  chksum          byte checksum
84  *
85  *      global variables:
86  *              int     hilo            byte order
87  *              FILE *  ofp             output file handle
88  *              int     rtcnt           count of data words
89  *              int     rtflg[]         output the data flag
90  *              Addr_T  rtval[]         relocated data
91  *
92  *      functions called:
93  *              int     fprintf()       c_library
94  *
95  *      side effects:
96  *              The data is output to the file defined by ofp.
97  */
98
99 VOID
100 s19(i)
101 {
102         register Addr_T chksum;
103
104         if (i) {
105                 if (hilo == 0) {
106                         chksum = rtval[0];
107                         rtval[0] = rtval[1];
108                         rtval[1] = chksum;
109                 }
110                 for (i = 0, chksum = 1; i < rtcnt; i++) {
111                         if (rtflg[i])
112                                 chksum++;
113                 }
114                 fprintf(ofp, "S1%02X", chksum);
115                 for (i = 0; i < rtcnt ; i++) {
116                         if (rtflg[i]) {
117                                 fprintf(ofp, "%02X", rtval[i]);
118                                 chksum += rtval[i];
119                         }
120                 }
121                 fprintf(ofp, "%02X\n", (-chksum-1) & 0xff);
122         } else {
123                 fprintf(ofp, "S9030000FC\n");
124         }
125 }