1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2010 Ales Hvezda
4 ;;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 (use-modules (ice-9 optargs))
22 ;; --------------------------------------------------------------------------
24 ;; protelII netlist format specific functions go here
27 ;; [ -- element for list of components
31 ;; FOOTPRINT attrbute.
34 ;; If VALUE attribute exists, output VALUE attribute.
35 ;; Otherwise, output DEVICE attrbute.
36 ;; (This covers the case of ICs, which usually carry their part no (e.g. uA741) in the DEVICE attribute.)
89 ;; ... other components ...
91 ;; ( -- element for list of nets
93 ;; PART-PIN# VALUE-PINNAME PINTYPE -- use PASSIVE for PINTYPE
94 ;; ...more connections...
99 ;; { -- element for net option list
115 ;; ...more net options...
119 ;; We redefine the newline function, because this file format requires
120 ;; Windows-style "\r\n" line endings rather than Unix-style "\n"
122 (define* (newline #:optional port)
123 (display "\r\n" (or port (current-output-port))))
128 (define protelII:write-top-header
130 (display "PROTEL NETLIST 2.0" p)
134 ;; header for components section
136 (define protelII:start-components
139 ;; no header for components
142 ;; footer for components section
144 (define protelII:end-components
149 ;; header for renamed section
151 (define protelII:start-renamed-nets
156 ;; footer for renamed section
158 (define protelII:end-renamed-nets
163 ;; header for nets section
165 (define protelII:start-nets
170 ;; footer for net section
172 (define protelII:end-nets
177 ;; Top level component writing
179 (define protelII:components
182 (let ((package (car ls)))
186 (display "DESIGNATOR" port)
188 (display package port)
190 (display "FOOTPRINT" port)
192 (display (gnetlist:get-package-attribute package "footprint") port)
194 (display "PARTTYPE" port)
196 (let ((value (get-value package))) ;; This change by SDB on 10.12.2003.
197 (if (string-ci=? value "unknown")
198 (display (get-device package) port)
203 (display "DESCRIPTION" port)
205 (display (get-device package) port)
207 (display "Part Field 1" port)
211 (display "Part Field 2" port)
215 (display "Part Field 3" port)
219 (display "Part Field 4" port)
223 (display "Part Field 5" port)
227 (display "Part Field 6" port)
231 (display "Part Field 7" port)
235 (display "Part Field 8" port)
239 (display "Part Field 9" port)
243 (display "Part Field 10" port)
247 (display "Part Field 11" port)
251 (display "Part Field 12" port)
255 (display "Part Field 13" port)
259 (display "Part Field 14" port)
263 (display "Part Field 15" port)
267 (display "Part Field 16" port)
271 (display "LIBRARYFIELD1" port)
275 (display "LIBRARYFIELD2" port)
279 (display "LIBRARYFIELD3" port)
283 (display "LIBRARYFIELD4" port)
287 (display "LIBRARYFIELD5" port)
291 (display "LIBRARYFIELD6" port)
295 (display "LIBRARYFIELD7" port)
299 (display "LIBRARYFIELD8" port)
305 (protelII:components port (cdr ls)))))))
308 ;; renamed nets writing
310 (define protelII:renamed-nets
313 (let ((renamed-pair (car ls)))
315 ;;; (display renamed-pair) (newline)
316 ;;; (display (car renamed-pair) port)
317 ;;; (display " -> " port)
318 ;;; (display (car (cdr renamed-pair)) port)
321 (protelII:renamed-nets port (cdr ls)))))))
324 ;; Display the individual net connections
326 (define protelII:display-connections
328 (if (not (null? nets))
330 (let ((package (car (car nets))))
331 (display package port)
332 (write-char #\- port)
333 (display (car (cdr (car nets))) port)
335 (display (get-device package) port)
337 (display (car (cdr (car nets))) port)
338 (display " PASSIVE" port))
339 (if (not (null? (cdr nets)))
342 (protelII:display-connections (cdr nets) port)))))
347 (define protelII:display-name-nets
350 (protelII:display-connections nets port)
351 (write-char #\space port)
355 ;; Write netname : uref pin, uref pin, ...
357 (define protelII:write-net
358 (lambda (port netnames)
359 (if (not (null? netnames))
360 (let ((netname (car netnames)))
364 (display netname port)
366 (protelII:display-name-nets port (gnetlist:get-all-connections netname))
369 (protelII:write-net port (cdr netnames)))))))
372 ;; Write the net part of the gEDA format
374 (define protelII:nets
376 (let ((all-uniq-nets (gnetlist:get-all-unique-nets "dummy")))
377 (protelII:write-net port all-uniq-nets))))
379 ;;; Highest level function
380 ;;; Write my special testing netlist format
383 (lambda (output-filename)
384 (let ((port (open-output-file output-filename)))
386 ;;; (gnetlist:set-netlist-mode "gEDA") No longer needed
387 (protelII:write-top-header port)
388 (protelII:start-components port)
389 (protelII:components port packages)
390 (protelII:end-components port)
391 (protelII:start-renamed-nets port)
392 (protelII:renamed-nets port (gnetlist:get-renamed-nets "dummy"))
393 (protelII:end-renamed-nets port)
394 (protelII:start-nets port)
396 (protelII:end-nets port))
397 (close-output-port port))))
400 ;; gEDA's native test netlist format specific functions ends
402 ;; --------------------------------------------------------------------------