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

Subversion Repositories System09

[/] [System09/] [trunk/] [Tools/] [as09/] [util.c] - Blame information for rev 74

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

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

powered by: WebSVN 2.1.0

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