OpenCores
URL https://opencores.org/ocsvn/kiss-board/kiss-board/trunk

Subversion Repositories kiss-board

[/] [kiss-board/] [tags/] [initial/] [kiss-board_soc/] [sw/] [utils/] [bin2srec.c] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 fukuchi
#include <stdio.h>
2
#include <stdlib.h>
3
 
4
#define SMARK "S214"
5
#define SADDR 0x000000
6
#define INIT_ADDR 0x100100
7
#define SCHKSUM 0xff
8
 
9
int main(int argc, char **argv)
10
{
11
 
12
        FILE  *fd;
13
        int c, j;
14
        unsigned long addr = INIT_ADDR;
15
        unsigned char chksum;
16
 
17
        if(argc < 2) {
18
                fprintf(stderr,"no input file specified\n");
19
                exit(1);
20
        }
21
        if(argc > 2) {
22
                fprintf(stderr,"too many input files (more than one) specified\n");
23
                exit(1);
24
        }
25
 
26
        fd = fopen( argv[1], "r" );
27
        if (fd == NULL) {
28
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
29
                exit(1);
30
        }
31
 
32
        while (!feof(fd)) {
33
                j = 0;
34
                chksum = SCHKSUM;
35
                printf("%s%.6lx", SMARK, addr);
36
                while (j < 16) {
37
                        c = fgetc(fd);
38
                        if (c == EOF) {
39
                                c = 0;
40
                        }
41
                        printf("%.2x", c);
42
                        chksum -= c;
43
                        j++;
44
                }
45
 
46
                chksum -= addr & 0xff;
47
                chksum -= (addr >> 8) & 0xff;
48
                chksum -= (addr >> 16) & 0xff;
49
                chksum -= 0x14;
50
                printf("%.2x\r\n", chksum);
51
                addr += 16;
52
        }
53
        return 0;
54
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.