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

Subversion Repositories System09

[/] [System09/] [rev_86/] [Tools/] [as09/] [util.c] - Blame information for rev 116

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

Line No. Rev Author Line
1 83 davidgb
/*
2
 *      fatal --- fatal error handler
3
 */
4
fatal(str)
5
char    *str;
6
{
7
 printf("%s\n",str);
8
 
9
#ifdef IBM      /* changed ver TER_2.0 */
10
 exit(-1);
11
#else
12
 exit(10);      /* Amiga & UNIX prefer positive numbers for error
13
                        minimal error is 10 (no system prob) */
14
#endif
15
}
16
 
17
/*
18
 *      error --- error in a line
19
 *                      print line number and error
20
 */
21
error(str)
22
char    *str;
23
{
24
/* if(N_files > 1)      commented out test for N_files in rel TER_2.0
25
                        because a single command line source file
26
                        (which is what N_files counts) can have multiple
27
                        include source files. */
28
 printf("%s\n",str);
29
}
30
/*
31
 *      warn --- trivial error in a line
32
 *                      print line number and error
33
 */
34
warn(str)
35
char    *str;
36
{
37
/* if(N_files > 1)      commented out in rel TER_2.0 same reason as above */
38
 printf("%s, line no.",Argv[Cfn]);      /* current file name */
39
 printf("%d: ",Line_num);       /* current line number */
40
 printf("Warning --- %s\n",str);
41
 Page_lines++;
42
}
43
 
44
 
45
/*
46
 *      delim --- check if character is a delimiter
47
 */
48
delim(c)
49
char    c;
50
{
51
 if( any(c," \t\n"))
52
  return(YES);
53
 return(NO);
54
}
55
 
56
/*
57
 *      skip_white --- move pointer to next non-whitespace char
58
 */
59
char *skip_white(ptr)
60
char    *ptr;
61
{
62
 while(*ptr==BLANK || *ptr==TAB)
63
  ptr++;
64
 return(ptr);
65
}
66
 
67
/*
68
 *      eword --- emit a word to code file
69
 */
70
eword(wd)
71
int     wd;
72
{
73
 emit(hibyte(wd));
74
 emit(lobyte(wd));
75
}
76
 
77
/*
78
 *      emit --- emit a byte to code file
79
 */
80
emit(byte)
81
{
82
#ifdef DEBUG
83
 printf("%2x @ %4x\n",byte,Pc);
84
#endif
85
 if(Pass==1){
86
  Pc++;
87
  return(YES);
88
  }
89
 if(P_total < P_LIMIT)
90
  P_bytes[P_total++] = byte;
91
 E_bytes[E_total++] = byte;
92
 Pc++;
93
 if(E_total == E_LIMIT)
94
  f_record();
95
}
96
 
97
/*
98
 *      f_record --- flush record out in `S1' format
99
 */
100
void f_record() /* made void for ANSI C compat ver TER_2.0 6/18/89 */
101
{
102
 int     i;
103
 int     chksum;
104
 
105
 if(Pass == 1)
106
  return;
107
 if(E_total==0){
108
  E_pc = Pc;
109
  return;
110
  }
111
 F_total += E_total;    /* total bytes in file ver (TER)2.01 19 Jun 89 */
112
 chksum =  E_total+3;    /* total bytes in this record */
113
 chksum += lobyte(E_pc);
114
 chksum += E_pc>>8;
115
 fprintf(Objfil,"S1");   /* record header preamble */
116
 hexout(E_total+3);      /* byte count +3 */
117
 hexout(E_pc>>8);        /* high byte of PC */
118
 hexout(lobyte(E_pc)); /* low byte of PC */
119
 for(i=0;i<E_total;i++){
120
  chksum += lobyte(E_bytes[i]);
121
  hexout(lobyte(E_bytes[i])); /* data byte */
122
  }
123
 chksum =~ chksum;       /* one's complement */
124
 hexout(lobyte(chksum)); /* checksum */
125
 if (CRflag == 1)       /* test for CRflag added ver TER_1.1 */
126
  fprintf(Objfil,"%c\n",CR);  /* print in IBM format for some PROM boxes */
127
 else
128
  fprintf(Objfil,"\n"); /* this is original statement */
129
 E_pc = Pc;
130
 E_total = 0;
131
}
132
 
133
char    *hexstr = { "0123456789ABCDEF" } ;
134
 
135
hexout(byte)
136
int     byte;
137
{
138
 
139
 byte = lobyte(byte);
140
 fprintf(Objfil,"%c%c",hexstr[byte>>4],hexstr[byte&017]);
141
}
142
 
143
/*
144
 *      print_line --- pretty print input line
145
 */
146
print_line()
147
{
148
 int     i;
149
 register char *ptr;
150
 
151
        printf ("%04d ",Line_num);
152
 if(P_total || P_force)
153
        printf("%04X",Old_pc);
154
 else
155
        printf("    ");
156
 
157
 for(i=0;i<P_total && i<6;i++)
158
        printf(" %02X",lobyte(P_bytes[i]));
159
 for(;i<6;i++)
160
  printf("   ");
161
 printf("  ");
162
 
163
 if(Cflag){
164
  if(Cycles)
165
   printf("[%2d ] ",Cycles);
166
  else
167
   printf("      ");
168
  }
169
 ptr = Line;
170
 while( *ptr != '\n' )   /* just echo the line back out */
171
  putchar(*ptr++);
172
 for(;i<P_total;i++){
173
  if( i%6 == 0 )
174
         printf("\n         ");               /* force data alignment DWC 1-5-92 */
175
        printf(" %02X",lobyte(P_bytes[i]));
176
  }
177
 if (Pflag50 && (++Page_lines>=50))     /* form feed if flag set */
178
         NewPage();                     /* ver (TER) 2.02 19 Jun 89 */
179
 
180
 if (Pflag75 && (++Page_lines>=75))     /* form feed if flag set */
181
         NewPage();                     /* ver (DWC) 2.10 8 Oct 2001 */
182
 
183
 
184
printf("\n");
185
}
186
 
187
/*
188
 *      any --- does str contain c?
189
 */
190
any(c,str)
191
char    c;
192
char    *str;
193
{
194
 while(*str != EOS)
195
  if(*str++ == c)
196
   return(YES);
197
 return(NO);
198
}
199
 
200
/*
201
 *      mapdn --- convert A-Z to a-z
202
 */
203
char mapdn(c)
204
char c;
205
{
206
 if( c >= 'A' && c <= 'Z')
207
  return((char)(c+040)); /* cast value to char for ANSI C, ver TER_2.0 */
208
 return(c);
209
}
210
 
211
/*
212
 *      lobyte --- return low byte of an int
213
 */
214
lobyte(i)
215
int i;
216
{
217
 return(i&0xFF);
218
}
219
/*
220
 *      hibyte --- return high byte of an int
221
 */
222
hibyte(i)
223
int i;
224
{
225
 return((i>>8)&0xFF);
226
}
227
 
228
/*
229
 *      head --- is str2 the head of str1?
230
 */
231
head(str1,str2)
232
char *str1,*str2;
233
{
234
 while( *str1 != EOS && *str2 != EOS){
235
  if( *str1 != *str2 )break;
236
  str1++;
237
  str2++;
238
  }
239
 if(*str1 == *str2)return(YES);
240
 if(*str2==EOS)
241
  if( any(*str1," \t\n,+-];*") )return(YES);
242
 return(NO);
243
}
244
 
245
/*
246
 *      alpha --- is character a legal letter
247
 */
248
alpha(c)
249
char c;
250
{
251
 if( c<= 'z' && c>= 'a' )return(YES);
252
 if( c<= 'Z' && c>= 'A' )return(YES);
253
 if( c== '_' )return(YES);
254
 if( c== '.' )return(YES);
255
 return(NO);
256
}
257
/*
258
 *      alphan --- is character a legal letter or digit
259
 */
260
alphan(c)
261
char c;
262
{
263
 if( alpha(c) )return(YES);
264
 if( c<= '9' && c>= '0' )return(YES);
265
 if( c == '$' )return(YES);      /* allow imbedded $ */
266
 if( c == '@' )return(YES);     /* allow imbedded @, added ver TER_2.0
267
                                   added to permit redefinable variables */
268
 return(NO);
269
}
270
 
271
/*
272
 * white --- is character whitespace?
273
 */
274
white(c)
275
char c;
276
{
277
 if( c == TAB || c == BLANK || c == '\n' )return(YES);
278
 return(NO);
279
}
280
 
281
/*
282
 * alloc --- allocate memory
283
 */
284
char *
285
alloc(nbytes)
286
int nbytes;
287
{
288
 return(malloc(nbytes));
289
}
290
 
291
/*
292
 * FNameGet --- Find a file name <file> or "file" in the Operand string
293
        added ver TER_2.0 6/17/89
294
        note: this routine will return a file name with white
295
        space if between delimeters.  This is permitted in
296
        AmigaDOS.  Other DOS may hiccup or just use name up to white space
297
 */
298
 
299
int
300
FNameGet(NameString)
301
char *NameString;       /* pointer to output string */
302
{
303
 char *frompoint;       /* pointers to input string, don't bash Operand */
304
 char *topoint;         /* pointer to output string, don't bash NameString */
305
 
306
 frompoint=Operand;     /* include file name is in parsed string Operand */
307
 topoint=NameString;    /* copy of pointer to increment in copying */
308
 if (*frompoint != '<' && *frompoint != '"') return(0); /* bad syntax */
309
 frompoint++;   /* skip < or " */
310
 
311
 while (*frompoint != '>' && *frompoint != '"') /* look for delimeter */
312
  {
313
   if (*frompoint == EOS) return(0);    /* missing delimeter */
314
   *topoint++ = *frompoint++;   /* copy path & file name for DOS */
315
  }
316
 
317
 *topoint=EOS;  /* terminate file name */
318
#ifdef DEBUG2
319
 printf("FNameGet: file name=%s\n",NameString);
320
#endif
321
 return(1);     /* proper syntax anyway */
322
}
323
 
324
/*
325
 * --- strsave()  find a place to save a string & return pointer to it
326
                added ver TER_2.0 6/18/89  function taken from
327
                Kernighan & Ritchie 78
328
 */
329
char *strsave(s)
330
char *s;
331
{
332
 char *p;
333
 
334
 if ((p = alloc(strlen(s)+1)) != NULL)
335
        strcpy(p,s);
336
 return(p);
337
}
338
 
339
/*
340
 * pouterror() ---- print out standard error header
341
                        added rel TER_2.0 6/18/89
342
 */
343
 
344
void pouterror()
345
{
346
    printf("%s, line no. ",Argv[Cfn]);  /* current file name */
347
    printf("%d: ",Line_num);    /* current line number */
348
        /* NOTE: THERE IS NO \n ! Calling procedure supplies suffixing
349
           error message and \n. viz. file pseudo.c procedure do_pseudo
350
           in case INCLUDE. Note also that error count is incremented.  */
351
    Err_count++;
352
    Page_lines++;       /* increment lines per page */
353
}
354
 
355
/*
356
 * New Page() --- form feed a new page, print heading & inc page number
357
                Moved here from do_pseudo (pseudo.c) in ver (TER) 2.02
358
                19 Jun 89 so that can call from print_line() as well
359
                for p50 option.
360
 */
361
 
362
void NewPage()
363
{
364
 Page_lines = 0;        /* ver TER_2.08 so that OPT PAGE works */
365
 printf ("\n\f\n");
366
 printf ("%-10s",Argv[Cfn]);
367
 printf ("                                   ");
368
 printf ("                                   ");
369
 printf ("page %3d\n",Page_num++);
370
}
371
 
372
 
373
/*
374
* LastChar() ----- return a pointer to the last character in a string
375
                Exception: will return garbage if NULL string
376
*/
377
 
378
char *LastChar(strpt)
379
char *strpt;    /* pointer to string to be examined */
380
{
381
 char *c;
382
 
383
 c=strpt;       /* don't zap original */
384
 while (*c != EOS)      /* search for end */
385
        c++;
386
 return(--c);   /* back up one to last character */
387
}

powered by: WebSVN 2.1.0

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