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

Subversion Repositories Aquarius

[/] [Aquarius/] [trunk/] [fpga/] [genram.c] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 thorn_aitc
/*=======================================================================*/
2
/* Generate RAM Initialize file for Xilinx Block RAM (16KB)              */
3
/*-----------------------------------------------------------------------*/
4
/* Rev.1 January 21,2003 by Thorn Aitch : prototype                      */
5
/* Rev.2 April   30,2003 by Thorn Aitch : 8KB -> 16KB                    */
6
/*                                                                       */
7
/*    Usage:                                                             */
8
/*    genram [filename]                                                  */
9
/*        [filename] : (Input ) Binary File Name of Motolora S-Format.   */
10
/*        ram.dat    : (Output) Constraints Data (Append it to *.ucf.)   */
11
/*=======================================================================*/
12
 
13
#include <stdio.h>
14
#include <string.h>
15
#include <malloc.h>
16
#include <stdlib.h>
17
 
18
#define RAMSIZE 16384 /* unit : byte */
19
#define MAXLINE 1000
20
#define MAXWORD 100
21
 
22
 
23
/*=============*/
24
/* main routine*/
25
/*=============*/
26
int main(int argc, char *argv[])
27
{
28
        FILE    *memFp;
29
        FILE    *ramFp;
30
        char    memLine[MAXLINE];
31
        char    hex[MAXWORD];
32
        char    *pMemLine, *pHex, *SkipSpace();
33
        int     i, j, errStx, recType, numCode;
34
        unsigned long ram[RAMSIZE];
35
        unsigned long addr;
36
        unsigned long data;
37
 
38
        if (argc != 2)
39
        {
40
 
41
                printf("\n");
42
                printf("====================================================\n");
43
                printf("==== Generate RAM Initialize Data from S-Format ====\n");
44
                printf("====================================================\n");
45
                printf("[Command Usage]\n");
46
                printf("    genram [filename]\n");
47
                printf("\n");
48
                printf("        [filename] : (input ) Binary File Name of Motorola S-Format.\n");
49
        printf("        ram.dat    : (Output) Constraints Data (Append it to *.ucf.)\n");
50
                printf("\n");
51
                return(1);
52
        }
53
 
54
        /*------------------*/
55
        /* initialize ram[] */
56
        /*------------------*/
57
        for (i = 0 ; i < RAMSIZE ; i++)
58
        {
59
                ram[i] = 255; /* init values are all FF */
60
        }
61
 
62
        /*-----------------------------*/
63
        /* read s-format file to rom[] */
64
        /*-----------------------------*/
65
        if ((memFp = fopen(argv[1], "r")) == NULL)
66
        {
67
                printf("ERROR:cant open the file.\n");
68
                return(2);
69
        }
70
        errStx = 0;
71
        pHex = hex;
72
        while (fgets(memLine, MAXLINE, memFp) != NULL)
73
        {
74
                pMemLine = memLine;
75
                pMemLine = SkipSpace(pMemLine);
76
 
77
                if (*pMemLine++ != 'S') /* start mark ? */
78
                {
79
                        errStx = 1;
80
                        break;
81
                }
82
 
83
                if ((*pMemLine == '0') || (*pMemLine == '5')) continue; /* if comment ? */
84
 
85
                if (*pMemLine == '1') recType = 1;                                              /* record type */
86
                else if (*pMemLine == '2') recType = 2;
87
                else if (*pMemLine == '3') recType = 3;
88
                else if (*pMemLine == '7') break;
89
                else if (*pMemLine == '8') break;
90
                else if (*pMemLine == '9') break;
91
                else
92
                {
93
                errStx = 1;
94
                break;
95
                }
96
                pMemLine++;
97
 
98
                pHex = strncpy(pHex,pMemLine,2);                                /* the number of code */
99
                pMemLine = pMemLine + 2;
100
                *(pHex + 2) = '\0';
101
                if ((ChkHex(pHex) == 0) || (sscanf(pHex,"%X",&numCode) == EOF))
102
                {
103
                        errStx = 1;
104
                        break;
105
                }
106
 
107
                if (recType == 1)                                                               /* load address */
108
                {
109
                        pHex = strncpy(pHex,pMemLine,4);
110
                        pMemLine = pMemLine + 4;
111
                        numCode = numCode - 2;
112
                        *(pHex + 4) = '\0';
113
                        if (strlen(pHex) != 4)
114
                        {
115
                                errStx = 1;
116
                                break;
117
                        }
118
                }
119
                if (recType == 2)
120
                {
121
                        pHex = strncpy(pHex,pMemLine,6);
122
                        pMemLine = pMemLine + 6;
123
                        numCode = numCode - 3;
124
                        *(pHex + 6) = '\0';
125
                        if (strlen(pHex) != 6)
126
                        {
127
                                errStx = 1;
128
                                break;
129
                        }
130
                }
131
                if (recType == 3)
132
                {
133
                        pHex = strncpy(pHex,pMemLine,8);
134
                        pMemLine = pMemLine + 8;
135
                        numCode = numCode - 4;
136
                        *(pHex + 8) = '\0';
137
                        if (strlen(pHex) != 8)
138
                        {
139
                                errStx = 1;
140
                                break;
141
                        }
142
                }
143
 
144
                if ((ChkHex(pHex) == 0) || (sscanf(pHex,"%lX",&addr) == EOF))
145
                {
146
                        errStx = 1;
147
                        break;
148
                }
149
 
150
                for (i = 0 ; i < numCode - 1 ; i++)                              /* code */
151
                {
152
                        pHex = strncpy(pHex,pMemLine,2);
153
                        pMemLine = pMemLine + 2;
154
                        *(pHex + 2) = '\0';
155
                        if (strlen(pHex) != 2)
156
                        {
157
                                errStx = 1;
158
                                break;
159
                        }
160
                        if ((ChkHex(pHex) == 0) || (sscanf(pHex,"%X",&data) == EOF))
161
                        {
162
                                errStx = 1;
163
                                break;
164
                        }
165
                        if (addr <= RAMSIZE)
166
                        {
167
                                ram[addr] = data;
168
                                addr++;
169
                        }
170
                        else
171
                        {
172
                                errStx = 2;
173
                                break;
174
                        }
175
                }
176
                if (errStx != 0) break;
177
        }
178
 
179
        if (errStx == 1)
180
        {
181
                printf("ERROR:syntax error in object file.\n");
182
                return(2);
183
        }
184
        if (errStx == 2)
185
        {
186
                printf("ERROR:rom address out of range.\n");
187
                return(2);
188
        }
189
        if (fclose(memFp) == EOF)
190
        {
191
                printf("ERROR:file close error.\n");
192
                return(2);
193
        }
194
 
195
        /*-------------------*/
196
        /* open ram.dat file */
197
        /*-------------------*/
198
        if ((ramFp = fopen("ram.dat", "w")) == NULL)
199
        {
200
                printf("ERROR:cant open ram.dat.\n");
201
                return(3);
202
        }
203
 
204
    /*-------------------------------*/
205
    /* RAM0HH : HH lane of 0000-07FF */
206
    /*-------------------------------*/
207
    for (i = 0x00 ; i < 0x10 ; i++)
208
    {
209
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM0HH_inst_ramb_0\" INIT_%02X = ", i);
210
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
211
        {
212
            fprintf(ramFp, "%02X", ram[j+0]);
213
        }
214
        fprintf(ramFp, ";\n");
215
    }
216
 
217
    /*-------------------------------*/
218
    /* RAM0HL : HL lane of 0000-07FF */
219
    /*-------------------------------*/
220
    for (i = 0x00 ; i < 0x10 ; i++)
221
    {
222
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM0HL_inst_ramb_0\" INIT_%02X = ", i);
223
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
224
        {
225
            fprintf(ramFp, "%02X", ram[j+1]);
226
        }
227
        fprintf(ramFp, ";\n");
228
    }
229
 
230
    /*-------------------------------*/
231
    /* RAM0LH : LH lane of 0000-07FF */
232
    /*-------------------------------*/
233
    for (i = 0x00 ; i < 0x10 ; i++)
234
    {
235
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM0LH_inst_ramb_0\" INIT_%02X = ", i);
236
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
237
        {
238
            fprintf(ramFp, "%02X", ram[j+2]);
239
        }
240
        fprintf(ramFp, ";\n");
241
    }
242
 
243
    /*-------------------------------*/
244
    /* RAM0LL : LL lane of 0000-07FF */
245
    /*-------------------------------*/
246
    for (i = 0x00 ; i < 0x10 ; i++)
247
    {
248
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM0LL_inst_ramb_0\" INIT_%02X = ", i);
249
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
250
        {
251
            fprintf(ramFp, "%02X", ram[j+3]);
252
        }
253
        fprintf(ramFp, ";\n");
254
    }
255
 
256
    /*-------------------------------*/
257
    /* RAM1HH : HH lane of 0800-0FFF */
258
    /*-------------------------------*/
259
    for (i = 0x00 ; i < 0x10 ; i++)
260
    {
261
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM1HH_inst_ramb_0\" INIT_%02X = ", i);
262
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
263
        {
264
            fprintf(ramFp, "%02X", ram[0x0800+j+0]);
265
        }
266
        fprintf(ramFp, ";\n");
267
    }
268
 
269
    /*-------------------------------*/
270
    /* RAM1HL : HL lane of 0800-0FFF */
271
    /*-------------------------------*/
272
    for (i = 0x00 ; i < 0x10 ; i++)
273
    {
274
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM1HL_inst_ramb_0\" INIT_%02X = ", i);
275
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
276
        {
277
            fprintf(ramFp, "%02X", ram[0x0800+j+1]);
278
        }
279
        fprintf(ramFp, ";\n");
280
    }
281
 
282
    /*-------------------------------*/
283
    /* RAM1LH : LH lane of 0800-0FFF */
284
    /*-------------------------------*/
285
    for (i = 0x00 ; i < 0x10 ; i++)
286
    {
287
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM1LH_inst_ramb_0\" INIT_%02X = ", i);
288
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
289
        {
290
            fprintf(ramFp, "%02X", ram[0x0800+j+2]);
291
        }
292
        fprintf(ramFp, ";\n");
293
    }
294
 
295
    /*-------------------------------*/
296
    /* RAM1LL : LL lane of 0800-0FFF */
297
    /*-------------------------------*/
298
    for (i = 0x00 ; i < 0x10 ; i++)
299
    {
300
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM1LL_inst_ramb_0\" INIT_%02X = ", i);
301
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
302
        {
303
            fprintf(ramFp, "%02X", ram[0x0800+j+3]);
304
        }
305
        fprintf(ramFp, ";\n");
306
    }
307
 
308
    /*-------------------------------*/
309
    /* RAM2HH : HH lane of 1000-17FF */
310
    /*-------------------------------*/
311
    for (i = 0x00 ; i < 0x10 ; i++)
312
    {
313
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM2HH_inst_ramb_0\" INIT_%02X = ", i);
314
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
315
        {
316
            fprintf(ramFp, "%02X", ram[0x1000+j+0]);
317
        }
318
        fprintf(ramFp, ";\n");
319
    }
320
 
321
    /*-------------------------------*/
322
    /* RAM2HL : HL lane of 1000-17FF */
323
    /*-------------------------------*/
324
    for (i = 0x00 ; i < 0x10 ; i++)
325
    {
326
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM2HL_inst_ramb_0\" INIT_%02X = ", i);
327
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
328
        {
329
            fprintf(ramFp, "%02X", ram[0x1000+j+1]);
330
        }
331
        fprintf(ramFp, ";\n");
332
    }
333
 
334
    /*-------------------------------*/
335
    /* RAM2LH : LH lane of 1000-17FF */
336
    /*-------------------------------*/
337
    for (i = 0x00 ; i < 0x10 ; i++)
338
    {
339
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM2LH_inst_ramb_0\" INIT_%02X = ", i);
340
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
341
        {
342
            fprintf(ramFp, "%02X", ram[0x1000+j+2]);
343
        }
344
        fprintf(ramFp, ";\n");
345
    }
346
 
347
    /*-------------------------------*/
348
    /* RAM2LL : LL lane of 1000-17FF */
349
    /*-------------------------------*/
350
    for (i = 0x00 ; i < 0x10 ; i++)
351
    {
352
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM2LL_inst_ramb_0\" INIT_%02X = ", i);
353
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
354
        {
355
            fprintf(ramFp, "%02X", ram[0x1000+j+3]);
356
        }
357
        fprintf(ramFp, ";\n");
358
    }
359
 
360
    /*-------------------------------*/
361
    /* RAM3HH : HH lane of 1800-1FFF */
362
    /*-------------------------------*/
363
    for (i = 0x00 ; i < 0x10 ; i++)
364
    {
365
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM3HH_inst_ramb_0\" INIT_%02X = ", i);
366
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
367
        {
368
            fprintf(ramFp, "%02X", ram[0x1800+j+0]);
369
        }
370
        fprintf(ramFp, ";\n");
371
    }
372
 
373
    /*-------------------------------*/
374
    /* RAM3HL : HL lane of 1800-1FFF */
375
    /*-------------------------------*/
376
    for (i = 0x00 ; i < 0x10 ; i++)
377
    {
378
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM3HL_inst_ramb_0\" INIT_%02X = ", i);
379
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
380
        {
381
            fprintf(ramFp, "%02X", ram[0x1800+j+1]);
382
        }
383
        fprintf(ramFp, ";\n");
384
    }
385
 
386
    /*-------------------------------*/
387
    /* RAM3LH : LH lane of 1800-1FFF */
388
    /*-------------------------------*/
389
    for (i = 0x00 ; i < 0x10 ; i++)
390
    {
391
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM3LH_inst_ramb_0\" INIT_%02X = ", i);
392
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
393
        {
394
            fprintf(ramFp, "%02X", ram[0x1800+j+2]);
395
        }
396
        fprintf(ramFp, ";\n");
397
    }
398
 
399
    /*-------------------------------*/
400
    /* RAM3LL : LL lane of 1800-1FFF */
401
    /*-------------------------------*/
402
    for (i = 0x00 ; i < 0x10 ; i++)
403
    {
404
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM3LL_inst_ramb_0\" INIT_%02X = ", i);
405
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
406
        {
407
            fprintf(ramFp, "%02X", ram[0x1800+j+3]);
408
        }
409
        fprintf(ramFp, ";\n");
410
    }
411
 
412
    /*-------------------------------*/
413
    /* RAM4HH : HH lane of 2000-27FF */
414
    /*-------------------------------*/
415
    for (i = 0x00 ; i < 0x10 ; i++)
416
    {
417
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM4HH_inst_ramb_0\" INIT_%02X = ", i);
418
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
419
        {
420
            fprintf(ramFp, "%02X", ram[0x2000+j+0]);
421
        }
422
        fprintf(ramFp, ";\n");
423
    }
424
 
425
    /*-------------------------------*/
426
    /* RAM4HL : HL lane of 2000-27FF */
427
    /*-------------------------------*/
428
    for (i = 0x00 ; i < 0x10 ; i++)
429
    {
430
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM4HL_inst_ramb_0\" INIT_%02X = ", i);
431
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
432
        {
433
            fprintf(ramFp, "%02X", ram[0x2000+j+1]);
434
        }
435
        fprintf(ramFp, ";\n");
436
    }
437
 
438
    /*-------------------------------*/
439
    /* RAM4LH : LH lane of 2000-27FF */
440
    /*-------------------------------*/
441
    for (i = 0x00 ; i < 0x10 ; i++)
442
    {
443
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM4LH_inst_ramb_0\" INIT_%02X = ", i);
444
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
445
        {
446
            fprintf(ramFp, "%02X", ram[0x2000+j+2]);
447
        }
448
        fprintf(ramFp, ";\n");
449
    }
450
 
451
    /*-------------------------------*/
452
    /* RAM4LL : LL lane of 2000-27FF */
453
    /*-------------------------------*/
454
    for (i = 0x00 ; i < 0x10 ; i++)
455
    {
456
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM4LL_inst_ramb_0\" INIT_%02X = ", i);
457
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
458
        {
459
            fprintf(ramFp, "%02X", ram[0x2000+j+3]);
460
        }
461
        fprintf(ramFp, ";\n");
462
    }
463
 
464
    /*-------------------------------*/
465
    /* RAM5HH : HH lane of 2800-2FFF */
466
    /*-------------------------------*/
467
    for (i = 0x00 ; i < 0x10 ; i++)
468
    {
469
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM5HH_inst_ramb_0\" INIT_%02X = ", i);
470
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
471
        {
472
            fprintf(ramFp, "%02X", ram[0x2800+j+0]);
473
        }
474
        fprintf(ramFp, ";\n");
475
    }
476
 
477
    /*-------------------------------*/
478
    /* RAM5HL : HL lane of 2800-2FFF */
479
    /*-------------------------------*/
480
    for (i = 0x00 ; i < 0x10 ; i++)
481
    {
482
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM5HL_inst_ramb_0\" INIT_%02X = ", i);
483
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
484
        {
485
            fprintf(ramFp, "%02X", ram[0x2800+j+1]);
486
        }
487
        fprintf(ramFp, ";\n");
488
    }
489
 
490
    /*-------------------------------*/
491
    /* RAM5LH : LH lane of 2800-2FFF */
492
    /*-------------------------------*/
493
    for (i = 0x00 ; i < 0x10 ; i++)
494
    {
495
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM5LH_inst_ramb_0\" INIT_%02X = ", i);
496
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
497
        {
498
            fprintf(ramFp, "%02X", ram[0x2800+j+2]);
499
        }
500
        fprintf(ramFp, ";\n");
501
    }
502
 
503
    /*-------------------------------*/
504
    /* RAM5LL : LL lane of 2800-2FFF */
505
    /*-------------------------------*/
506
    for (i = 0x00 ; i < 0x10 ; i++)
507
    {
508
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM5LL_inst_ramb_0\" INIT_%02X = ", i);
509
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
510
        {
511
            fprintf(ramFp, "%02X", ram[0x2800+j+3]);
512
        }
513
        fprintf(ramFp, ";\n");
514
    }
515
 
516
    /*-------------------------------*/
517
    /* RAM6HH : HH lane of 3000-37FF */
518
    /*-------------------------------*/
519
    for (i = 0x00 ; i < 0x10 ; i++)
520
    {
521
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM6HH_inst_ramb_0\" INIT_%02X = ", i);
522
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
523
        {
524
            fprintf(ramFp, "%02X", ram[0x3000+j+0]);
525
        }
526
        fprintf(ramFp, ";\n");
527
    }
528
 
529
    /*-------------------------------*/
530
    /* RAM6HL : HL lane of 3000-37FF */
531
    /*-------------------------------*/
532
    for (i = 0x00 ; i < 0x10 ; i++)
533
    {
534
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM6HL_inst_ramb_0\" INIT_%02X = ", i);
535
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
536
        {
537
            fprintf(ramFp, "%02X", ram[0x3000+j+1]);
538
        }
539
        fprintf(ramFp, ";\n");
540
    }
541
 
542
    /*-------------------------------*/
543
    /* RAM6LH : LH lane of 3000-37FF */
544
    /*-------------------------------*/
545
    for (i = 0x00 ; i < 0x10 ; i++)
546
    {
547
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM6LH_inst_ramb_0\" INIT_%02X = ", i);
548
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
549
        {
550
            fprintf(ramFp, "%02X", ram[0x3000+j+2]);
551
        }
552
        fprintf(ramFp, ";\n");
553
    }
554
 
555
    /*-------------------------------*/
556
    /* RAM6LL : LL lane of 3000-37FF */
557
    /*-------------------------------*/
558
    for (i = 0x00 ; i < 0x10 ; i++)
559
    {
560
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM6LL_inst_ramb_0\" INIT_%02X = ", i);
561
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
562
        {
563
            fprintf(ramFp, "%02X", ram[0x3000+j+3]);
564
        }
565
        fprintf(ramFp, ";\n");
566
    }
567
 
568
    /*-------------------------------*/
569
    /* RAM7HH : HH lane of 3800-3FFF */
570
    /*-------------------------------*/
571
    for (i = 0x00 ; i < 0x10 ; i++)
572
    {
573
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM7HH_inst_ramb_0\" INIT_%02X = ", i);
574
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
575
        {
576
            fprintf(ramFp, "%02X", ram[0x3800+j+0]);
577
        }
578
        fprintf(ramFp, ";\n");
579
    }
580
 
581
    /*-------------------------------*/
582
    /* RAM7HL : HL lane of 3800-3FFF */
583
    /*-------------------------------*/
584
    for (i = 0x00 ; i < 0x10 ; i++)
585
    {
586
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM7HL_inst_ramb_0\" INIT_%02X = ", i);
587
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
588
        {
589
            fprintf(ramFp, "%02X", ram[0x3800+j+1]);
590
        }
591
        fprintf(ramFp, ";\n");
592
    }
593
 
594
    /*-------------------------------*/
595
    /* RAM7LH : LH lane of 3800-3FFF */
596
    /*-------------------------------*/
597
    for (i = 0x00 ; i < 0x10 ; i++)
598
    {
599
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM7LH_inst_ramb_0\" INIT_%02X = ", i);
600
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
601
        {
602
            fprintf(ramFp, "%02X", ram[0x3800+j+2]);
603
        }
604
        fprintf(ramFp, ";\n");
605
    }
606
 
607
    /*-------------------------------*/
608
    /* RAM7LL : LL lane of 3800-3FFF */
609
    /*-------------------------------*/
610
    for (i = 0x00 ; i < 0x10 ; i++)
611
    {
612
        fprintf(ramFp, "INST \"MEMORY_Mram_RAM7LL_inst_ramb_0\" INIT_%02X = ", i);
613
        for (j = (i+1)*0x80-4 ; j >= i*0x80 ; j = j - 4)
614
        {
615
            fprintf(ramFp, "%02X", ram[0x3800+j+3]);
616
        }
617
        fprintf(ramFp, ";\n");
618
    }
619
 
620
        /*--------------------*/
621
        /* write ram.dat file */
622
        /*--------------------*
623
        if (fclose(ramFp) == EOF)
624
        {
625
                printf("ERROR:file close error.\n");
626
                return(3);
627
        }
628
 
629
        /*-----------------------------------------*/
630
        return(0);
631
}
632
 
633
/*============*/
634
/* skip space */
635
/*============*/
636
char *SkipSpace(pStr)
637
        char    *pStr;
638
{
639
        while(isspace((int) *pStr)) pStr++;
640
        return(pStr);
641
}
642
 
643
/*===========*/
644
/* check hex */
645
/*===========*/
646
int ChkHex(str)
647
        char    *str;
648
{
649
        int             result;
650
 
651
        result = 0;
652
        while(*str != '\0')
653
        {
654
                result = isxdigit(*(str++));
655
                if (result == 0) break;
656
        }
657
        return(result);
658
}
659
 
660
/* end of source file */
661
 
662
 

powered by: WebSVN 2.1.0

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