trunk/src/tools/jedutil.c
| r18414 | r18415 | |
| 102 | 102 | #include <ctype.h> |
| 103 | 103 | #include "corestr.h" |
| 104 | 104 | #include "jedparse.h" |
| 105 | #include "plaparse.h" |
| 105 | 106 | |
| 106 | 107 | |
| 107 | 108 | |
| r18414 | r18415 | |
| 954 | 955 | |
| 955 | 956 | |
| 956 | 957 | /*------------------------------------------------- |
| 958 | is_pla_file - test if the file extension is |
| 959 | that of a Berkeley standard PLA file |
| 960 | -------------------------------------------------*/ |
| 961 | |
| 962 | static 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 | /*------------------------------------------------- |
| 957 | 978 | find_pal_data - finds the data associated |
| 958 | 979 | with a pal name |
| 959 | 980 | -------------------------------------------------*/ |
| r18414 | r18415 | |
| 2540 | 2561 | { |
| 2541 | 2562 | fprintf(stderr, |
| 2542 | 2563 | "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" |
| 2545 | 2567 | " jedutil -view <source.jed> <pal name> -- dump JED logic equations\n" |
| 2546 | 2568 | " jedutil -view <source.bin> <pal name> -- dump binary logic equations\n" |
| 2547 | 2569 | " jedutil -viewlist -- view list of supported devices\n" |
| r18414 | r18415 | |
| 2559 | 2581 | static int command_convert(int argc, char *argv[]) |
| 2560 | 2582 | { |
| 2561 | 2583 | const char *srcfile, *dstfile; |
| 2562 | | int src_is_jed, dst_is_jed; |
| 2584 | int src_is_jed, src_is_pla, dst_is_jed; |
| 2563 | 2585 | int numfuses = 0; |
| 2564 | 2586 | jed_data jed; |
| 2565 | 2587 | int err; |
| r18414 | r18415 | |
| 2578 | 2600 | /* does the source end in '.jed'? */ |
| 2579 | 2601 | src_is_jed = is_jed_file(srcfile); |
| 2580 | 2602 | |
| 2603 | /* does the source end in '.pla'? */ |
| 2604 | src_is_pla = is_pla_file(srcfile); |
| 2605 | |
| 2581 | 2606 | /* does the destination end in '.jed'? */ |
| 2582 | 2607 | dst_is_jed = is_jed_file(dstfile); |
| 2583 | 2608 | |
| 2584 | 2609 | /* 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) |
| 2586 | 2611 | { |
| 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"); |
| 2588 | 2613 | return 1; |
| 2589 | 2614 | } |
| 2590 | 2615 | if (src_is_jed && dst_is_jed) |
| r18414 | r18415 | |
| 2598 | 2623 | if (err != 0) |
| 2599 | 2624 | return 1; |
| 2600 | 2625 | |
| 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) |
| 2603 | 2628 | { |
| 2604 | 2629 | printf("Converting '%s' to binary form '%s'\n", srcfile, dstfile); |
| 2605 | 2630 | |
| 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 | |
| 2608 | 2637 | switch (err) |
| 2609 | 2638 | { |
| 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; |
| 2611 | 2640 | case JEDERR_BAD_XMIT_SUM: fprintf(stderr, "Fatal error: Bad transmission checksum\n"); return 1; |
| 2612 | 2641 | case JEDERR_BAD_FUSE_SUM: fprintf(stderr, "Fatal error: Bad fusemap checksum\n"); return 1; |
| 2613 | 2642 | } |
trunk/src/lib/util/plaparse.c
| r0 | r18415 | |
| 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 | |
| 61 | struct 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 | |
| 78 | static 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 | |
| 89 | static 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 | |
| 116 | static 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 | |
| 229 | int 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
| r0 | r18415 | |
| 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 */ |
| 52 | int pla_parse(const void *data, size_t length, jed_data *result); |
| 53 | |
| 54 | |
| 55 | |
| 56 | #endif /* __PLAPARSE_H__ */ |