Previous 199869 Revisions Next

r18415 Wednesday 10th October, 2012 at 15:18:42 UTC by Curt Coder
Added experimental support for using Berkeley PLA files as input to jedutil. [Curt Coder]
[src/lib]lib.mak
[src/lib/util]plaparse.c* plaparse.h*
[src/tools]jedutil.c

trunk/src/tools/jedutil.c
r18414r18415
102102#include <ctype.h>
103103#include "corestr.h"
104104#include "jedparse.h"
105#include "plaparse.h"
105106
106107
107108
r18414r18415
954955
955956
956957/*-------------------------------------------------
958    is_pla_file - test if the file extension is
959    that of a Berkeley standard PLA file
960-------------------------------------------------*/
961
962static int is_pla_file(const char *file)
963{
964    int len;
965
966    /* does the source end in '.pla'? */
967    len = strlen(file);
968
969    return (file[len - 4] == '.' &&
970           tolower((UINT8)file[len - 3]) == 'p' &&
971           tolower((UINT8)file[len - 2]) == 'l' &&
972           tolower((UINT8)file[len - 1]) == 'a');
973}
974
975
976
977/*-------------------------------------------------
957978    find_pal_data - finds the data associated
958979    with a pal name
959980-------------------------------------------------*/
r18414r18415
25402561{
25412562   fprintf(stderr,
25422563      "Usage:\n"
2543      "  jedutil -convert <source.jed> <target.bin> [fuses] -- convert JED to binary form\n"
2544      "  jedutil -convert <source.bin> <target.jed> -- convert binary to JED form\n"
2564      "  jedutil -convert <source.jed> <target.bin> [fuses] -- convert JEDEC to binary form\n"
2565        "  jedutil -convert <source.pla> <target.bin> [fuses] -- convert Berkeley standard PLA to binary form\n"
2566      "  jedutil -convert <source.bin> <target.jed> -- convert binary to JEDEC form\n"
25452567        "  jedutil -view <source.jed> <pal name> -- dump JED logic equations\n"
25462568        "  jedutil -view <source.bin> <pal name> -- dump binary logic equations\n"
25472569        "  jedutil -viewlist -- view list of supported devices\n"
r18414r18415
25592581static int command_convert(int argc, char *argv[])
25602582{
25612583    const char *srcfile, *dstfile;
2562   int src_is_jed, dst_is_jed;
2584   int src_is_jed, src_is_pla, dst_is_jed;
25632585   int numfuses = 0;
25642586   jed_data jed;
25652587   int err;
r18414r18415
25782600   /* does the source end in '.jed'? */
25792601   src_is_jed = is_jed_file(srcfile);
25802602
2603    /* does the source end in '.pla'? */
2604    src_is_pla = is_pla_file(srcfile);
2605
25812606   /* does the destination end in '.jed'? */
25822607   dst_is_jed = is_jed_file(dstfile);
25832608
25842609   /* error if neither or both are .jed */
2585   if (!src_is_jed && !dst_is_jed)
2610   if (!src_is_jed && !src_is_pla && !dst_is_jed)
25862611   {
2587      fprintf(stderr, "At least one of the filenames must end in .jed!\n");
2612      fprintf(stderr, "At least one of the filenames must end in .jed or .pla!\n");
25882613      return 1;
25892614   }
25902615   if (src_is_jed && dst_is_jed)
r18414r18415
25982623   if (err != 0)
25992624      return 1;
26002625
2601   /* if the source is JED, convert to binary */
2602   if (src_is_jed)
2626   /* if the source is JED or PLA, convert to binary */
2627   if (src_is_jed || src_is_pla)
26032628   {
26042629      printf("Converting '%s' to binary form '%s'\n", srcfile, dstfile);
26052630
2606      /* read the JEDEC data */
2607      err = jed_parse(srcbuf, srcbuflen, &jed);
2631      /* read the fuse data */
2632        if (src_is_jed)
2633         err = jed_parse(srcbuf, srcbuflen, &jed);
2634        else if (src_is_pla)
2635           err = pla_parse(srcbuf, srcbuflen, &jed);
2636
26082637      switch (err)
26092638      {
2610         case JEDERR_INVALID_DATA:   fprintf(stderr, "Fatal error: Invalid .JED file\n"); return 1;
2639         case JEDERR_INVALID_DATA:   fprintf(stderr, "Fatal error: Invalid source file\n"); return 1;
26112640         case JEDERR_BAD_XMIT_SUM:   fprintf(stderr, "Fatal error: Bad transmission checksum\n"); return 1;
26122641         case JEDERR_BAD_FUSE_SUM:   fprintf(stderr, "Fatal error: Bad fusemap checksum\n"); return 1;
26132642      }
trunk/src/lib/util/plaparse.c
r0r18415
1/***************************************************************************
2
3    plaparse.h
4
5    Parser for Berkeley standard PLA files into raw fusemaps.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <ctype.h>
44#include "jedparse.h"
45#include "plaparse.h"
46
47
48
49/***************************************************************************
50    DEBUGGING
51***************************************************************************/
52
53#define LOG_PARSE      0
54
55
56
57/***************************************************************************
58    TYPE DEFINITIONS
59***************************************************************************/
60
61struct parse_info
62{
63   UINT32   inputs;
64   UINT32   outputs;
65   UINT32   terms;
66};
67
68
69
70/***************************************************************************
71    UTILITIES
72***************************************************************************/
73
74/*-------------------------------------------------
75    iscrlf - is a line feed character
76-------------------------------------------------*/
77
78static int iscrlf(char c)
79{
80   return (c == 13 || c == 10);
81}
82
83
84/*-------------------------------------------------
85    suck_number - read a decimal value from the
86    character stream
87-------------------------------------------------*/
88
89static UINT32 suck_number(const UINT8 **psrc)
90{
91   const UINT8 *src = *psrc;
92   UINT32 value = 0;
93
94   // loop over and accumulate digits
95   while (isdigit(*src))
96   {
97      value = value * 10 + *src - '0';
98      src++;
99   }
100
101   // return a pointer to the string afterwards
102   *psrc = src;
103   return value;
104}
105
106
107
108/***************************************************************************
109    CORE IMPLEMENTATION
110***************************************************************************/
111
112/*-------------------------------------------------
113    process_field - process a single field
114-------------------------------------------------*/
115
116static void process_field(jed_data *data, const UINT8 *cursrc, const UINT8 *srcend, parse_info *pinfo)
117{
118   cursrc++;
119
120   // switch off of the field type
121   switch (*cursrc)
122   {
123      // number of inputs
124      case 'i':
125         cursrc += 2;
126         pinfo->inputs = suck_number(&cursrc);
127         if (LOG_PARSE) printf("Inputs: %u\n", pinfo->inputs);
128         break;
129
130      // number of outputs
131      case 'o':
132         cursrc += 2;
133         pinfo->outputs = suck_number(&cursrc);
134         if (LOG_PARSE) printf("Outputs: %u\n", pinfo->outputs);
135         break;
136
137      // number of product terms
138      case 'p':
139      {
140         cursrc += 2;
141         pinfo->terms = suck_number(&cursrc);
142         if (LOG_PARSE) printf("Terms: %u\n", pinfo->terms);
143
144         UINT32 curfuse = 0;
145         bool outputs = false;
146
147         cursrc++;
148         while (cursrc < srcend && *cursrc != '.')
149         {
150            switch (*cursrc)
151            {
152            case '-':
153               if (!outputs)
154               {
155                  jed_set_fuse(data, curfuse++, 1);
156                  jed_set_fuse(data, curfuse++, 1);
157
158                  if (LOG_PARSE) printf("11");
159               }
160               break;
161
162            case '1':
163               if (outputs)
164               {
165                  jed_set_fuse(data, curfuse++, 0);
166
167                  if (LOG_PARSE) printf("0");
168               }
169               else
170               {
171                  jed_set_fuse(data, curfuse++, 1);
172                  jed_set_fuse(data, curfuse++, 0);
173
174                  if (LOG_PARSE) printf("10");
175               }
176               break;
177
178            case '0':
179               if (outputs)
180               {
181                  jed_set_fuse(data, curfuse++, 1);
182
183                  if (LOG_PARSE) printf("1");
184               }
185               else
186               {
187                  jed_set_fuse(data, curfuse++, 0);
188                  jed_set_fuse(data, curfuse++, 1);
189
190                  if (LOG_PARSE) printf("01");
191               }
192               break;
193
194            case ' ':
195               outputs = true;
196               if (LOG_PARSE) printf(" ");
197               break;
198            }
199
200            if (iscrlf(*cursrc) && outputs)
201            {
202               outputs = false;
203               if (LOG_PARSE) printf("\n");
204            }
205
206            cursrc++;
207         }
208
209         data->numfuses = curfuse;
210         break;
211      }
212
213      // end of file
214      case 'e':
215         printf("End of file\n");
216         break;
217   }
218
219   cursrc++;
220}
221
222
223
224/*-------------------------------------------------
225    pla_parse - parse a Berkeley standard PLA file
226    that has been loaded raw into memory
227-------------------------------------------------*/
228
229int pla_parse(const void *data, size_t length, jed_data *result)
230{
231   const UINT8 *cursrc = (const UINT8 *)data;
232   const UINT8 *srcend = cursrc + length;
233   const UINT8 *scan;
234   parse_info pinfo;
235
236   result->numfuses = 0;
237   memset(result->fusemap, 0x00, sizeof(result->fusemap));
238
239   while (cursrc < srcend)
240   {
241      if (*cursrc == '#')
242      {
243         cursrc++;
244         while (cursrc < srcend && !iscrlf(*cursrc))
245            cursrc++;
246      }
247      else if (*cursrc == '.')
248      {
249         scan = cursrc;
250         while (scan < srcend && !iscrlf(*scan))
251            scan++;
252         if (scan >= srcend)
253            return JEDERR_INVALID_DATA;
254
255         process_field(result, cursrc, srcend, &pinfo);
256
257         cursrc = scan + 1;
258      }
259
260      cursrc++;
261   }
262
263   return JEDERR_NONE;
264}
trunk/src/lib/util/plaparse.h
r0r18415
1/***************************************************************************
2
3    plaparse.h
4
5    Parser for Berkeley standard PLA files into raw fusemaps.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#ifndef __PLAPARSE_H__
41#define __PLAPARSE_H__
42
43#include "osdcore.h"
44
45
46
47/***************************************************************************
48    FUNCTION PROTOTYPES
49***************************************************************************/
50
51/* parse a file (read into memory) into a jed_data structure */
52int pla_parse(const void *data, size_t length, jed_data *result);
53
54
55
56#endif   /* __PLAPARSE_H__ */
trunk/src/lib/lib.mak
r18414r18415
5050   $(LIBOBJ)/util/opresolv.o \
5151   $(LIBOBJ)/util/options.o \
5252   $(LIBOBJ)/util/palette.o \
53   $(LIBOBJ)/util/plaparse.o \
5354   $(LIBOBJ)/util/png.o \
5455   $(LIBOBJ)/util/pool.o \
5556   $(LIBOBJ)/util/sha1.o \

Previous 199869 Revisions Next


© 1997-2024 The MAME Team