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

Subversion Repositories marca

[/] [marca/] [trunk/] [spar/] [output.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jeunes2
/* This file is part of the assembler "spar" for marca.
2
   Copyright (C) 2007 Wolfgang Puffitsch
3
 
4
   This program is free software; you can redistribute it and/or modify it
5
   under the terms of the GNU Library General Public License as published
6
   by the Free Software Foundation; either version 2, or (at your option)
7
   any later version.
8
 
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
13
 
14
   You should have received a copy of the GNU Library General Public
15
   License along with this program; if not, write to the Free Software
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
17
 
18
#include <stdint.h>
19
#include <stdio.h>
20
#include <stdlib.h>
21
 
22
#include "spar.h"
23
#include "ui.h"
24
#include "output.h"
25
#include "segtab.h"
26
#include "code.h"
27
 
28
char *itob(uint32_t val, uint8_t width)
29
{
30
  char *retval = xmalloc(width+1);
31
  retval[width] = '\0';
32
  while (width-- > 0)
33
    {
34
      retval[width] = (val & 1) ? '1' : '0';
35
      val >>= 1;
36
    }
37
  return retval;
38
}
39
 
40
void print_download(FILE *f, FILE *r0, FILE *r1)
41
{
42
  struct seg *seg = get_current_seg();
43
  uint32_t pos;
44
 
45
  if (!nostart)
46
    {
47
      fprintf(f, "%c%c", 'U', '\n');
48
    }
49
  for (pos = 0; pos < seg->pos; pos++)
50
    {
51
      uint16_t data = get_code(seg, pos);
52
      fprintf(f, "%c%c%c%c%c%c",
53
              (uint8_t)((pos >> 8) & 0xFF),
54
              (uint8_t)(pos & 0xFF),
55
              0,
56
              (uint8_t)((data >> 8) & 0xFF),
57
              (uint8_t)(data & 0xFF),
58
              '\n');
59
    }
60
  for ( ; pos < codesize; pos++)
61
    {
62
      fprintf(f, "%c%c%c%c%c%c",
63
              (uint8_t)((pos >> 8) & 0xFF),
64
              (uint8_t)(pos & 0xFF),
65
              0,
66
              (uint8_t)((filler >> 8) & 0xFF),
67
              (uint8_t)(filler & 0xFF),
68
              '\n');
69
    }
70
  if (!noend)
71
    {
72
      fprintf(f, "%c%c%c", 0x55, 0xFF, 1);
73
    }
74
}
75
 
76
void print_intel(FILE *f, FILE *r0, FILE *r1)
77
{
78
  struct seg *seg;
79
  uint32_t pos;
80
 
81
  /* instructions */
82
  seg = get_seg(SEG_PILE);
83
  for (pos = 0; pos < seg->pos; pos++)
84
    {
85
      uint16_t data = get_code(seg, pos);
86
      uint8_t chksum = -(2 + ((pos >> 8) & 0xFF) + (pos & 0xFF)
87
                         + ((data >> 8) & 0xFF) + (data & 0xFF));
88
      fprintf(f, ":%02x%04x%02x%04x%02x%c",
89
              2, (uint16_t)pos, 0, data, chksum, '\n');
90
    }
91
  for ( ; pos < codesize; pos++)
92
    {
93
      uint8_t chksum = -(2 + ((pos >> 8) & 0xFF) + (pos & 0xFF)
94
                         + ((filler >> 8) & 0xFF) + (filler & 0xFF));
95
      fprintf(f, ":%02x%04x%02x%04x%02x%c",
96
              2, (uint16_t)pos, 0, filler, chksum, '\n');
97
    }
98
  fprintf(f, ":00000001ff\n");
99
 
100
  /* even ROM adresses */
101
  seg = get_seg(SEG_DATA);
102
  for (pos = 0; pos < seg->pos; pos+=2)
103
    {
104
      uint16_t data = get_code(seg, pos);
105
      uint8_t chksum = -(1 + ((pos/2 >> 8) & 0xFF) + (pos/2 & 0xFF)
106
                         + (data & 0xFF));
107
      fprintf(r0, ":%02x%04x%02x%02x%02x%c",
108
              1, (uint16_t)pos/2, 0, data & 0xFF, chksum, '\n');
109
    }
110
  for ( ; pos < romsize; pos+=2)
111
    {
112
      uint8_t chksum = -(1 + ((pos/2 >> 8) & 0xFF) + (pos/2 & 0xFF)
113
                         + (filler & 0xFF));
114
      fprintf(r0, ":%02x%04x%02x%02x%02x%c",
115
              1, (uint16_t)pos/2, 0, filler & 0xFF, chksum, '\n');
116
    }
117
  fprintf(r0, ":00000001ff\n");
118
 
119
  /* odd ROM adresses */
120
  seg = get_seg(SEG_DATA);
121
  for (pos = 1; pos < seg->pos; pos+=2)
122
    {
123
      uint16_t data = get_code(seg, pos);
124
      uint8_t chksum = -(1 + ((pos/2 >> 8) & 0xFF) + (pos/2 & 0xFF)
125
                         + (data & 0xFF));
126
      fprintf(r1, ":%02x%04x%02x%02x%02x%c",
127
              1, (uint16_t)pos/2, 0, data & 0xFF, chksum, '\n');
128
    }
129
  for ( ; pos < romsize; pos+=2)
130
    {
131
      uint8_t chksum = -(1 + ((pos/2 >> 8) & 0xFF) + (pos/2 & 0xFF)
132
                         + ((filler >> 8) & 0xFF) + (filler & 0xFF));
133
      fprintf(r1, ":%02x%04x%02x%02x%02x%c",
134
              1, (uint16_t)pos/2, 0, filler & 0xFF, chksum, '\n');
135
    }
136
  fprintf(r1, ":00000001ff\n");
137
}
138
 
139
void print_mif(FILE *f, FILE *r0, FILE *r1)
140
{
141
  struct seg *seg;
142
  uint32_t pos;
143
 
144
  /* instructions */
145
  seg = get_seg(SEG_PILE);
146
 
147
  fprintf(f, "DEPTH=%lu;\n", codesize);
148
  fprintf(f, "WIDTH=16;\n");
149
  fprintf(f, "ADDRESS_RADIX=HEX;\n");
150
  fprintf(f, "DATA_RADIX=BIN;\n\n");
151
  fprintf(f, "CONTENT\nBEGIN\n\n");
152
 
153
  fprintf(f, "%% Assembly output\t%%\n");
154
 
155
  for (pos = 0; pos < seg->pos; pos++)
156
    {
157
      uint16_t data = get_code(seg, pos);
158
      fprintf(f, "%4x:\t%s;\t%% %s\t%%\n", (uint16_t)pos,
159
              itob(data, 16), get_listing(seg, pos));
160
    }
161
 
162
  if (seg->pos < codesize)
163
    {
164
      fprintf(f, "\n[%4x..%4x]:\t%s;\t%% Filler\t%%\n",
165
              (uint16_t)seg->pos, (uint16_t)(codesize-1),
166
              itob(filler, 16));
167
    }
168
 
169
  fprintf(f, "\nEND;\n");
170
 
171
  /* even ROM addresses */
172
  seg = get_seg(SEG_DATA);
173
 
174
  fprintf(r0, "DEPTH=%lu;\n", romsize/2);
175
  fprintf(r0, "WIDTH=8;\n");
176
  fprintf(r0, "ADDRESS_RADIX=HEX;\n");
177
  fprintf(r0, "DATA_RADIX=BIN;\n\n");
178
  fprintf(r0, "CONTENT\nBEGIN\n\n");
179
 
180
  fprintf(r0, "%% Assembly output\t%%\n");
181
 
182
  for (pos = 0; pos < seg->pos; pos += 2)
183
    {
184
      uint16_t data = get_code(seg, pos);
185
      fprintf(r0, "%4x:\t%s;\t%% %s\t%%\n", (uint16_t)pos/2,
186
              itob(data, 8), get_listing(seg, pos));
187
    }
188
 
189
  if (seg->pos < romsize)
190
    {
191
      fprintf(r0, "\n[%4x..%4x]:\t%s;\t%% Filler\t%%\n",
192
              (uint16_t)seg->pos/2, (uint16_t)(romsize/2-1),
193
              itob(filler, 8));
194
    }
195
 
196
  fprintf(r0, "\nEND;\n");
197
 
198
  /* odd ROM addresses */
199
  seg = get_seg(SEG_DATA);
200
 
201
  fprintf(r1, "DEPTH=%lu;\n", romsize/2);
202
  fprintf(r1, "WIDTH=8;\n");
203
  fprintf(r1, "ADDRESS_RADIX=HEX;\n");
204
  fprintf(r1, "DATA_RADIX=BIN;\n\n");
205
  fprintf(r1, "CONTENT\nBEGIN\n\n");
206
 
207
  fprintf(r1, "%% Assembly output\t%%\n");
208
 
209
  for (pos = 1; pos < seg->pos; pos += 2)
210
    {
211
      uint16_t data = get_code(seg, pos);
212
      fprintf(r1, "%4x:\t%s;\t%% %s\t%%\n", (uint16_t)pos/2,
213
              itob(data, 8), get_listing(seg, pos));
214
    }
215
 
216
  if (seg->pos < romsize)
217
    {
218
      fprintf(r1, "\n[%4x..%4x]:\t%s;\t%% Filler\t%%\n",
219
              (uint16_t)seg->pos/2, (uint16_t)(romsize/2-1),
220
              itob(filler, 8));
221
    }
222
 
223
  fprintf(r1, "\nEND;\n");
224
}

powered by: WebSVN 2.1.0

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