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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [Open8 Tools/] [open8_src/] [open8_as/] [listfile.c] - Blame information for rev 242

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

Line No. Rev Author Line
1 178 jshamlet
 
2
#include <ctype.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
 
7
#include "defines.h"
8
 
9
#include "include_file.h"
10
#include "listfile.h"
11
 
12
 
13
extern struct incbin_file_data *incbin_file_data_first, *ifd_tmp;
14
extern struct section_def *sections_first, *sections_last, *sec_tmp, *sec_next;
15
extern struct file_name_info *file_name_info_first, *file_name_info_last, *file_name_info_tmp;
16
extern unsigned char *rom_banks, *rom_banks_usage_table;
17
extern FILE *file_out_ptr;
18
extern char gba_tmp_name[32], *gba_tmp_last_name, tmp[4096];
19
extern int verbose_mode, section_status, cartridgetype, output_format;
20
 
21
 
22
int listfile_collect(void) {
23
 
24
  struct section_def *s;
25
  FILE *f_in;
26
  int add = 0, file_name_id = 0, inz, line_number = 0, command = 0;
27
  char c;
28
 
29
 
30
  s = NULL;
31
 
32
  if ((f_in = fopen(gba_tmp_name, "rb")) == NULL) {
33
    fprintf(stderr, "LISTFILE_COLLECT: Error opening file \"%s\".\n", gba_tmp_name);
34
    return FAILED;
35
  }
36
 
37
  while (fread(&c, 1, 1, f_in) != 0) {
38
    switch (c) {
39
 
40
    case ' ':
41
    case 'E':
42
    case 'P':
43
    case 'p':
44
      continue;
45
 
46
    case 'g':
47
      fscanf(f_in, "%*s ");
48
      continue;
49
    case 'G':
50
      continue;
51
 
52
    case 'A':
53
    case 'S':
54
      if (c == 'A')
55
        fscanf(f_in, "%d %*d", &inz);
56
      else
57
        fscanf(f_in, "%d ", &inz);
58
 
59
      s = sections_first;
60
      while (s->id != inz)
61
        s = s->next;
62
 
63
      add = 0;
64
      command = 0;
65
 
66
      /* allocate the listfile data */
67
      s->listfile_ints = malloc(sizeof(int) * s->listfile_items*2);
68
      s->listfile_cmds = malloc(s->listfile_items);
69
      if (s->listfile_ints == NULL || s->listfile_cmds == NULL) {
70
        fprintf(stderr, "LISTFILE_COLLECT: Out of memory error.\n");
71
        return FAILED;
72
      }
73
 
74
      /* add file name */
75
      s->listfile_cmds[command] = 'f';
76
      s->listfile_ints[command*2 + 0] = file_name_id;
77
      command++;
78
 
79
      continue;
80
 
81
    case 's':
82
      s = NULL;
83
      continue;
84
 
85
    case 'x':
86
      fscanf(f_in, "%d %*d ", &inz);
87
      add += inz;
88
      continue;
89
 
90
    case 'X':
91
      fscanf(f_in, "%d %*d ", &inz);
92
      add += inz << 1;
93
      continue;
94
 
95
#ifdef W65816
96
    case 'z':
97
    case 'q':
98
      fscanf(f_in, "%*s ");
99
      add += 3;
100
      continue;
101
 
102
    case 'T':
103
      fscanf(f_in, "%*d ");
104
      add += 3;
105
      continue;
106
 
107
    case 'b':
108
      fscanf(f_in, "%*d ");
109
      continue;
110
#endif
111
 
112
    case 'R':
113
    case 'Q':
114
    case 'd':
115
    case 'c':
116
      fscanf(f_in, "%*s ");
117
      add++;
118
      continue;
119
 
120
#ifdef W65816
121
    case 'M':
122
#endif
123
    case 'r':
124
      fscanf(f_in, "%*s ");
125
      add += 2;
126
      continue;
127
 
128
    case 'y':
129
    case 'C':
130
      fscanf(f_in, "%*d ");
131
      add += 2;
132
      continue;
133
 
134
    case 'D':
135
      fscanf(f_in, "%*d %*d %*d %d ", &inz);
136
      add += inz;
137
      continue;
138
 
139
    case 'O':
140
      fscanf(f_in, "%*d ");
141
      continue;
142
 
143
    case 'B':
144
      fscanf(f_in, "%*d %*d ");
145
      continue;
146
 
147
    case 'Z':
148
      continue;
149
 
150
    case 'Y':
151
    case 'L':
152
      fscanf(f_in, "%*s ");
153
      continue;
154
 
155
    case 'f':
156
      fscanf(f_in, "%d ", &file_name_id);
157
 
158
      if (s != NULL) {
159
        /* terminate the previous line */
160
        s->listfile_ints[command*2 + 1] = add;
161
        add = 0;
162
 
163
        /* add file name */
164
        s->listfile_cmds[command] = 'f';
165
        s->listfile_ints[command*2 + 0] = file_name_id;
166
        command++;
167
      }
168
      continue;
169
 
170
    case 'k':
171
      fscanf(f_in, "%d ", &line_number);
172
 
173
      if (s != NULL) {
174
        /* terminate the previous line */
175
        s->listfile_ints[command*2 + 1] = add;
176
        add = 0;
177
 
178
        /* add line number */
179
        s->listfile_cmds[command] = 'k';
180
        s->listfile_ints[command*2 + 0] = line_number;
181
        command++;
182
      }
183
      continue;
184
 
185
    default:
186
      fprintf(stderr, "%s: LISTFILE_COLLECT: Unknown internal symbol \"%c\".\n", get_file_name(file_name_id), c);
187
      return FAILED;
188
    }
189
  }
190
 
191
  fclose(f_in);
192
 
193
  return SUCCEEDED;
194
}
195
 
196
 
197
#define WRITEOUT_D fprintf(f, "%c%c%c%c", (d>>24)&0xFF, (d>>16)&0xFF, (d>>8)&0xFF, d&0xFF);
198
 
199
 
200
int listfile_block_write(FILE *f, struct section_def *s) {
201
 
202
  int i, d;
203
 
204
 
205
  if (f == NULL || s == NULL)
206
    return FAILED;
207
 
208
  fprintf(f, "%c", 1);
209
 
210
  d = s->listfile_items;
211
  WRITEOUT_D;
212
 
213
  for (i = 0; i < s->listfile_items; i++) {
214
    fprintf(f, "%c", s->listfile_cmds[i]);
215
    if (s->listfile_cmds[i] == 'k') {
216
      /* next line: line number, line length */
217
      d = s->listfile_ints[i*2 + 0];
218
      WRITEOUT_D;
219
      d = s->listfile_ints[i*2 + 1];
220
      WRITEOUT_D;
221
    }
222
    else if (s->listfile_cmds[i] == 'f') {
223
      /* next file: file name id */
224
      d = s->listfile_ints[i*2 + 0];
225
      WRITEOUT_D;
226
    }
227
    else {
228
      fprintf(stderr, "LISTFILE_BLOCK_WRITE: Unknown command %d.\n", s->listfile_cmds[i]);
229
      return FAILED;
230
    }
231
  }
232
 
233
  return SUCCEEDED;
234
}

powered by: WebSVN 2.1.0

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