Index: boxsym-rnd/7400.sg =================================================================== --- boxsym-rnd/7400.sg (nonexistent) +++ boxsym-rnd/7400.sg (revision 2756) @@ -0,0 +1,38 @@ +begin slot power + shape box + begin pin Vcc + num 14 + loc top + end pin + begin pin gnd + num 7 + loc bottom + end pin +end slot + + +begin slot logic + shape box right=halfcirc + + begin pin A + num 1:4:9:12 + loc left + dir in + end pin + + begin pin B + num 2:5:10:13 + loc left + dir in + end pin + + begin pin Z + num 3:6:8:11 + loc right + dir out + invcirc + end pin + + pinalign right center +end slot + Index: boxsym-rnd/common.awk =================================================================== --- boxsym-rnd/common.awk (nonexistent) +++ boxsym-rnd/common.awk (revision 2756) @@ -0,0 +1,8 @@ +BEGIN { + debug=0 + stderr="/dev/stderr" +} + +function min(a, b) { return a < b ? a : b } +function max(a, b) { return a > b ? a : b } +function dbg(s) { if(debug) print s > stderr } Index: boxsym-rnd/draw.awk =================================================================== --- boxsym-rnd/draw.awk (nonexistent) +++ boxsym-rnd/draw.awk (revision 2756) @@ -0,0 +1,54 @@ +BEGIN { + # given in xschem coords: + grid=40 + pinsize=5 + + # given in grid coords: + border=0.5 + pinlen=0.5 +} + +function pinbox(x, y, name, type, dir, pinnum, extra_attr ,attr) +{ + attr = "{name=" name + if (type != "") + attr = attr " type=" type + if (dir != "") + attr = attr " dir=" dir + if (pinnum != "") + attr = attr " pinnumber=" pinnum + if (extra_attr != "") + attr = attr " " extra_attr + attr = attr "}" + print "B 5", x*grid-pinsize, y*grid-pinsize, x*grid+pinsize, y*grid+pinsize, attr > ofn +} + +function line(x1, y1, x2, y2, extra_attr) +{ + print "L 4", x1*grid, y1*grid, x2*grid, y2*grid, "{" extra_attr "}" > ofn +} + +function text(x, y, str, rot, mir, hor, sizex, sizey, extra_attr) +{ + if (sizex == "") sizex = def_text_size + if (sizey == "") sizey = def_text_size + print "T {" str "}", x*grid, y*grid, int(rot), int(mir), sizex, sizey, "{" extra_attr "}" > ofn +} + +function header() +{ + print "v {xschem version=symgen-1.0 file_version=1.1}" > ofn +} + +### high level file output ### +function draw_box(w, h, border, shape) +{ + if ((shape ~ "^box") || (shape == "")) { + line(0-border, 0-border, w+border, 0-border); # top + line(0-border, 0-border, 0-border, h+border); # left + line(w+border, 0-border, w+border, h+border); # right + line(0-border, h+border, w+border, h+border); # bottom + } + else + print "Error: can not draw box of unknown shape " shape +} Index: boxsym-rnd/generator.awk =================================================================== --- boxsym-rnd/generator.awk (nonexistent) +++ boxsym-rnd/generator.awk (revision 2756) @@ -0,0 +1,152 @@ +function count_pins(slot, loc, expand_slot, n,cnt, pin, cinc, TMP) +{ + cnt = 0 + + if (slot == "") { # all slots + for(n = 0; n < nslots; n++) + cnt += count_pins(SLOTS[n], loc, expand_slot) + return cnt; + } + + for(n = 0; n < SLOT[slot, "npins"]; n++) { + pin = PINS[slot, n] + if (PIN[pin, "loc"] == loc) { + if (expand_slot) + cinc = split(PIN[pin, "num"], TMP, "[:]") + else + cinc = 1 + cnt += cinc + } + } + return cnt +} + +function draw_pin(pin, ST, slotidx, SLT ,x2,y2,pname) +{ + x2 = ST["x"] + pinlen*ST["px"] + y2 = ST["y"] + pinlen*ST["py"] + line(ST["x"], ST["y"], x2, y2) + pname = pin + sub(/^.*::/,"", pname) + dbg("draw_pin(): pname=" pname) + if(slotidx != "") { + dbg("draw_pin(): " pin " slotidx=" slotidx " " PIN[pin, "loc"] " " PIN[pin, "dir"] " " SLT[slotidx]) + # function pinbox(x, y, name, type, dir, pinnum, extra_attr) + pinbox(x2, y2, pname, "", PIN[pin, "dir"], SLT[slotidx], "") + } else { + dbg("draw_pin(): " pin " " PIN[pin, "loc"] " " PIN[pin, "dir"] " " PIN[pin, "num"]) + pinbox(x2, y2, pname, "", PIN[pin, "dir"], PIN[pin, "num"], "") + } +} + +# draw pins of a given slot:loc, with first pin touching the box at x0;y0 +# px and py are x and y dir for the pin line, stx and sty are stepping to +# the next coord. State is stored in ST +function draw_pins(slot, ALIGN, loc, x0, y0, px, py, stx, sty ,ST,n,v,i) +{ + if (slot == "") { # all slots + for(n = 0; n < nslots; n++) + draw_pins(SLOTS[n], ALIGN, loc, x0, y0, px, py, stx, sty, ST) + return + } + + if (ST["x"] == "") ST["x"] = x0 + ALIGN[loc, "x0"] + if (ST["y"] == "") ST["y"] = y0 + ALIGN[loc, "y0"] + ST["px"] = px + ST["py"] = py + for(n = 0; n < SLOT[slot, "npins"]; n++) { + pin = PINS[slot, n] + if (PIN[pin, "loc"] == loc) { + if (ALIGN["cfg", "expand_slot"]) { + v = split(PIN[pin, "num"], A, "[:]") + for(i = 1; i <= v; i++) { + draw_pin(pin, ST, i, A) + ST["x"] += stx + ST["y"] += sty + } + } + else { + draw_pin(pin, ST, "", A) + ST["x"] += stx + ST["y"] += sty + } + } + } +} + +function draw_all_pin(sn, ALIGN, bw, bh) +{ + bw = ALIGN["box","width"] + bh = ALIGN["box","height"] + # x0 y0 px py stx sty + draw_pins(sn, ALIGN, "left", -border, 0, -1, +0, +0, +1) + draw_pins(sn, ALIGN, "right", bw+border, 0, +1, +0, +0, +1) + draw_pins(sn, ALIGN, "top", border, -border, +0, -1, +1, +0) + draw_pins(sn, ALIGN, "bottom", border, bh+border, +0, +1, +1, +0) +} + +function align_calc(ALIGN, loc, boxloc, target_field, how ,diff) +{ + diff = ALIGN["box",boxloc] - ALIGN[loc,"count"] + 1 + if (how == "center") + ALIGN[loc, target_field] = diff/2 + else if ((how == "begin") || (how == "")) + ALIGN[loc, target_field] = 0 + else if (how == "end") + ALIGN[loc, target_field] = diff + else + print "Invalid alignment: " how > stderr +} + +function align_pins(sn, ALIGN) +{ + ALIGN["top","count"] = count_pins(sn, "top", ALIGN["cfg", "expand_slot"]) + ALIGN["bottom","count"] =count_pins(sn, "bottom", ALIGN["cfg", "expand_slot"]) + ALIGN["left","count"] = count_pins(sn, "left", ALIGN["cfg", "expand_slot"]) + ALIGN["right","count"] = count_pins(sn, "right", ALIGN["cfg", "expand_slot"]) + + ALIGN["box","width"] = max(max(ALIGN["top","count"], ALIGN["bottom","count"]), 1)-1 + ALIGN["box","height"] = max(max(ALIGN["left","count"], ALIGN["right","count"]), 1)-1 + + align_calc(ALIGN, "left", "height", "y0", SLOT[sn, "pinalign", "left"]) + align_calc(ALIGN, "right", "height", "y0", SLOT[sn, "pinalign", "right"]) + align_calc(ALIGN, "top", "width", "x0", SLOT[sn, "pinalign", "top"]) + align_calc(ALIGN, "bottom", "width", "x0", SLOT[sn, "pinalign", "bottom"]) +} + +function gen_monolith( ALIGN) +{ + ofn=basename ".sym" + ALIGN["cfg", "expand_slot"] = 1 + align_pins("", ALIGN) + header() + draw_box(ALIGN["box","width"], ALIGN["box","height"], border, "") + draw_all_pin("", ALIGN, 1) + ofn="" +} + +function gen_slot(sn ,ALIGN) +{ + ofn=basename "_" sn ".sym" + ALIGN["cfg", "expand_slot"] = 0 + align_pins(sn, ALIGN) + header() + draw_box(ALIGN["box","width"], ALIGN["box","height"], border, "") + draw_all_pin(sn, ALIGN, 0) + ofn="" +} + +function gen_slots( n) +{ + for(n = 0; n < nslots; n++) { + dbg("gen_slots(): n=" n) + gen_slot(SLOTS[n]) + } +} + + +END { + gen_monolith() + dbg("---------") + gen_slots() +} Index: boxsym-rnd/parser.awk =================================================================== --- boxsym-rnd/parser.awk (nonexistent) +++ boxsym-rnd/parser.awk (revision 2756) @@ -0,0 +1,97 @@ +BEGIN { + nslots=0 +} + +# return $0 in a string with $1 removed +function del1( tmp) +{ + tmp = $0 + sub("^[ \t]*[^ \t]*[ \t]*", "", tmp) + return tmp +} + +function add_pin() +{ + PINS[slot, SLOT[slot, "npins"]] = pin + SLOT[slot, "npins"]++ + pin = "" + return 0 +} + +function add_slot() +{ + SLOTS[nslots] = slot + nslots++ + slot = "" + return 0 +} + +function parse_pin() +{ + pin=slot "::" $3 + dbg("parse_pin(): pin=" pin) + while(getline == 1) { + if ((/^[ \t]*#/) || (NF == 0)) continue + if (($1 == "end") && ($2 == "pin")) + return add_pin() + if ($1 == "end") { + print "Invalid end - expected slot end in line", NR > stderr + exit 1 + } + if (($1 == "num") || ($1 == "loc") || ($1 == "dir")) + PIN[pin, $1] = del1($0) + else if ($1 == "invcirc") + PIN[pin, $1] = 1 + else { + print "Invalid pin command in line", NR > stderr + exit 1 + } + } +} + +# recurse parsing anything (except slots) - expects $0 is the "begin" line +function parse_any() +{ + if ($2 == "pin") + return parse_pin() + + print "Invalid begin in line", NR > stderr + exit 1 +} + + +# recurse parsing a slot - expects $0 is the "begin" line +function parse_slot() +{ + slot=$3 + SLOT[slot, "npins"] = 0 + while(getline == 1) { + if ((/^[ \t]*#/) || (NF == 0)) continue + if (($1 == "end") && ($2 == "slot")) + return add_slot() + if ($1 == "end") { + print "Invalid end - expected slot end in line", NR > stderr + exit 1 + } + if ($1 == "shape") + SLOT[slot, "shape"] = del1($0) + else if ($1 == "pinalign") + SLOT[slot, "pinalign", $2] = $3 + else if ($1 == "begin") + parse_any() + else { + print "Invalid slot command in line", NR > stderr + exit 1 + } + } + print "Premature end of file while reading slot in line", NR > stderr + exit 1 +} + +(NR == 1) { + basename=FILENAME + sub("[.][^.]*$", "", basename) +} + +/begin slot/ { parse_slot() } +($1 == "pinalign") { SLOT["", "pinalign", $2] = $3 } Index: boxsym-rnd/symgen.sh =================================================================== --- boxsym-rnd/symgen.sh (nonexistent) +++ boxsym-rnd/symgen.sh (revision 2756) @@ -0,0 +1,18 @@ +#!/bin/sh + +if test -z "$1" +then + echo "Need an input file name" >&2 + exit 1 +fi + +if test -f draw.awk -a -f generator.awk +then + # running from source + LIBDIR=. +else + # running the installed version + LIBDIR=/usr/lib/symgen +fi + +awk -f common.awk -f draw.awk -f parser.awk -f generator.awk $1 Property changes on: boxsym-rnd/symgen.sh ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property