1 /*****************************************************************************/
5 /* Data output routines */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 static unsigned GetSpan (attr_t Style)
53 /* Get the number of bytes for a given style */
55 /* Get the number of bytes still available */
56 unsigned RemainingBytes = GetRemainingBytes ();
58 /* Count how many bytes are available. This number is limited by the
59 * number of remaining bytes, a label, or the end of the given Style
63 while (Count < RemainingBytes) {
64 if (MustDefLabel(PC+Count) || GetStyleAttr (PC+Count) != Style) {
70 /* Return the number of bytes */
76 static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (unsigned))
77 /* Output a table of bytes */
81 /* Count how many bytes may be output. */
82 unsigned Count = GetSpan (Style);
84 /* If the count is less than the member size, print a row of Count data
85 * bytes. We assume here that there is no member with a size that is less
88 if (Count < MemberSize) {
93 /* Make Count an even number of multiples of MemberSize */
94 Count &= ~(MemberSize-1);
96 /* Output as many data bytes lines as needed */
98 while (BytesLeft > 0) {
100 /* Calculate the number of bytes for the next line */
101 unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;
103 /* Output a line with these bytes */
111 /* If the next line is not the same style, add a separator */
112 if (CodeLeft() && GetStyleAttr (PC) != Style) {
116 /* Return the number of bytes output */
122 unsigned ByteTable (void)
123 /* Output a table of bytes */
125 /* Call the low level function */
126 return DoTable (atByteTab, 1, DataByteLine);
131 unsigned WordTable (void)
132 /* Output a table of words */
134 /* Call the low level function */
135 return DoTable (atWordTab, 2, DataWordLine);
140 unsigned DWordTable (void)
141 /* Output a table of double words */
143 /* Call the low level function */
144 return DoTable (atDWordTab, 4, DataDWordLine);
149 unsigned AddrTable (void)
150 /* Output a table of addresses */
154 /* Count how many bytes may be output. */
155 unsigned Count = GetSpan (atAddrTab);
157 /* Handle Count == 1 ### */
162 /* Make the given number even */
165 /* Output as many data bytes lines as needed. For addresses, each line
166 * will hold just one address.
169 while (BytesLeft > 0) {
171 /* Get the address */
172 unsigned Addr = GetCodeWord (PC);
174 /* In pass 1, define a label, in pass 2 output the line */
176 if (!HaveLabel (Addr)) {
177 AddLabel (Addr, atIntLabel, MakeLabelName (Addr));
180 const char* Label = GetLabel (Addr);
182 /* OOPS! Should not happen */
183 Internal ("OOPS - Label for address %04X disappeard!", Addr);
188 Output ("%s", Label);
198 /* If the next line is not a byte table line, add a separator */
199 if (CodeLeft() && GetStyleAttr (PC) != atAddrTab) {
203 /* Return the number of bytes output */
209 unsigned RtsTable (void)
210 /* Output a table of RTS addresses (address - 1) */
214 /* Count how many bytes may be output. */
215 unsigned Count = GetSpan (atRtsTab);
217 /* Need to handle Count == 1 here!!! ### */
219 /* Make the given number even */
222 /* Output as many data bytes lines as needed. For addresses, each line
223 * will hold just one address.
226 while (BytesLeft > 0) {
228 /* Get the address */
229 unsigned Addr = GetCodeWord (PC) + 1;
231 /* In pass 1, define a label, in pass 2 output the line */
233 if (!HaveLabel (Addr)) {
234 AddLabel (Addr, atIntLabel, MakeLabelName (Addr));
237 const char* Label = GetLabel (Addr);
239 /* OOPS! Should not happen */
240 Internal ("OOPS - Label for address %04X disappeard!", Addr);
245 Output ("%s-1", Label);
255 /* If the next line is not a byte table line, add a separator */
256 if (CodeLeft() && GetStyleAttr (PC) != atRtsTab) {
260 /* Return the number of bytes output */
266 unsigned TextTable (void)
267 /* Output a table of text messages */
269 /* Count how many bytes may be output. */
270 unsigned ByteCount = GetSpan (atTextTab);
272 /* Output as many data bytes lines as needed. */
273 unsigned BytesLeft = ByteCount;
274 while (BytesLeft > 0) {
278 /* Count the number of characters that can be output as such */
280 while (Count < BytesLeft && Count < BytesPerLine*4-1) {
281 unsigned char C = GetCodeByte (PC + Count);
282 if (C >= 0x20 && C <= 0x7E && C != '\"') {
289 /* If we have text, output it */
296 for (I = 0; I < Count; ++I) {
297 Output ("%c", GetCodeByte (PC+I));
302 unsigned Chunk = CBytes;
303 if (Chunk > BytesPerLine) {
304 Chunk = BytesPerLine;
306 LineComment (PC, Chunk);
314 /* Count the number of bytes that must be output as bytes */
316 while (Count < BytesLeft && Count < BytesPerLine) {
317 unsigned char C = GetCodeByte (PC + Count);
318 if (C < 0x20 || C > 0x7E || C == '\"') {
325 /* If we have raw output bytes, print them */
327 DataByteLine (Count);
334 /* If the next line is not a byte table line, add a separator */
335 if (CodeLeft() && GetStyleAttr (PC) != atTextTab) {
339 /* Return the number of bytes output */