OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [tools/] [amber-ascii-mem.c] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 csantifort
/*----------------------------------------------------------------
2
//                                                              //
3
//  amber-mem-ascii                                             //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Take a string of ascii and converts it to mem               //
10
//                                                              //
11
//  Author(s):                                                  //
12
//      - Conor Santifort, csantifort.amber@gmail.com           //
13
//                                                              //
14
//////////////////////////////////////////////////////////////////
15
//                                                              //
16
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
17
//                                                              //
18
// This source file may be used and distributed without         //
19
// restriction provided that this copyright statement is not    //
20
// removed from the file and that any derivative work contains  //
21
// the original copyright notice and the associated disclaimer. //
22
//                                                              //
23
// This source file is free software; you can redistribute it   //
24
// and/or modify it under the terms of the GNU Lesser General   //
25
// Public License as published by the Free Software Foundation; //
26
// either version 2.1 of the License, or (at your option) any   //
27
// later version.                                               //
28
//                                                              //
29
// This source is distributed in the hope that it will be       //
30
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
31
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
32
// PURPOSE.  See the GNU Lesser General Public License for more //
33
// details.                                                     //
34
//                                                              //
35
// You should have received a copy of the GNU Lesser General    //
36
// Public License along with this source; if not, download it   //
37
// from http://www.opencores.org/lgpl.shtml                     //
38
//                                                              //
39
----------------------------------------------------------------*/
40
 
41
 
42
#include <stdio.h>
43
#include <stdlib.h> 
44
 
45
int conv_hstring ( char *string, unsigned int * addr)
46
{
47
    int pos = 0;
48
    *addr = 0;
49
 
50
    while (((string[pos] >= '0' && string[pos] <= '9') ||
51
           (string[pos] >= 'a' && string[pos] <= 'f')) && pos < 9) {
52
        if (string[pos] >= '0' && string[pos] <= '9')
53
            *addr =  (*addr << 4) + ( string[pos++] - '0' );
54
        else
55
            *addr =  (*addr << 4) + ( string[pos++] - 'a' ) + 10;
56
        }
57
 
58
    return pos;
59
}
60
 
61
 
62
int main (int argc, char **argv)
63
{
64
    FILE *input_file;
65
    int i;
66
    int bytes_read;
67
    size_t nbytes = 100;
68
    char *line_buffer;
69
 
70
    char s_number[12];
71
    unsigned int number;
72
 
73
    input_file = stdin;
74
 
75
    /* Get the mem starting address */
76
    if ( !conv_hstring(argv[1], &number) )
77
        {
78
        fprintf(stderr,"ERROR: conv_hstring error in jumps file, number, with i = %d\n", i);
79
        return 1;
80
        }
81
 
82
    if (input_file==NULL)
83
        {
84
        printf("Input file open failed\n");
85
        return 1;
86
        }
87
 
88
 
89
    /* Read the input file into a structure */
90
    /* reads a line */
91
    line_buffer  = (char *) malloc (nbytes + 1);
92
 
93
    i = 0;
94
    if (bytes_read = getline (&line_buffer, &nbytes, input_file))
95
        {
96
        while (bytes_read-1 > i) {
97
            printf("@%08x ", number+i);
98
 
99
            if (bytes_read-2 == i)
100
                printf("000000%02x\n",
101
                        line_buffer[i]);
102
            if (bytes_read-3 == i)
103
                printf("0000%02x%02x\n",
104
                        line_buffer[i+1], line_buffer[i]);
105
            if (bytes_read-4 == i)
106
                printf("00%02x%02x%02x\n",
107
                        line_buffer[i+2], line_buffer[i+1], line_buffer[i]);
108
            if (bytes_read-5 == i){
109
                printf("%02x%02x%02x%02x\n",
110
                        line_buffer[i+3], line_buffer[i+2], line_buffer[i+1], line_buffer[i]);
111
                printf("@%08x 00000000\n",
112
                        number+i+4, line_buffer[i+3], line_buffer[i+2], line_buffer[i+1], line_buffer[i]);
113
                }
114
            if (bytes_read-5 > i)
115
                printf("%02x%02x%02x%02x\n",
116
                        line_buffer[i+3], line_buffer[i+2], line_buffer[i+1], line_buffer[i]);
117
            i+=4;
118
            }
119
        }
120
 
121
    fclose(input_file);
122
}
123
 
124
 

powered by: WebSVN 2.1.0

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