From 5dd3f5c15d983011dc00426a0e8b3e86b8a805d2 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Mon, 27 Dec 2021 18:42:56 +0100 Subject: [PATCH] digital wave graphs, handle multiple sweep dc simulations --- src/callback.c | 176 +++++++++++---------- src/draw.c | 137 ++++++++++------- xschem_library/examples/LCC_instances.sch | 38 ++--- xschem_library/rom8k/rom8k.sch | 179 ++++++++-------------- 4 files changed, 266 insertions(+), 264 deletions(-) diff --git a/src/callback.c b/src/callback.c index 1c1fbfe6..097736d3 100644 --- a/src/callback.c +++ b/src/callback.c @@ -21,12 +21,13 @@ */ #include "xschem.h" -static int waves_selected() +static int waves_selected(int state) { int n, c, i; int is_inside = 0; xRect *r; rebuild_selected_array(); + if(state & Mod1Mask) return 0; if(xctx->ui_state & (STARTMOVE | STARTCOPY) ) return 0; if(!(xctx->ui_state & SELECTION) || !xctx->lastsel) return 0; for(i=0; ilastsel; i++) { @@ -165,6 +166,7 @@ void start_wire(double mx, double my) #define G_Y(y) (((y) - dy) / cy) static int waves_callback(int event, int mx, int my, KeySym key, int button, int aux, int state) { + int digital = 0; double wx1 = -2e-6; double wy1 = -1; double wx2 = 8e-6; @@ -233,6 +235,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int } } + /* lock x-axis to working graph when movint/zooming multiple graphs */ val = get_tok_value(xctx->rect[GRIDLAYER][xctx->graph_master].prop_ptr,"x1",0); if(val[0]) wx1 = atof(val); val = get_tok_value(xctx->rect[GRIDLAYER][xctx->graph_master].prop_ptr,"x2",0); @@ -256,7 +259,8 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int val = get_tok_value(r->prop_ptr,"dataset",0); if(val[0]) dataset = atoi(val); if(dataset >= xctx->datasets) dataset = xctx->datasets - 1; - /* lock x-axis to working graph when movint/zooming multiple graphs */ + val = get_tok_value(r->prop_ptr,"digital",0); + if(val[0]) digital = atof(val); calc_graph_area(GRIDLAYER, n, &x1, &y1, &x2, &y2, &marginx, &marginy); /* cache coefficients for faster graph coord transformations */ cx = (x2 - x1) / (wx2 - wx1); @@ -267,7 +271,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int if(event == MotionNotify && (state & Button1Mask) && !xctx->graph_bottom) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { delta = (wy2 - wy1) / divy; delta_threshold = 0.05; if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(cy * delta) * delta_threshold) { @@ -277,6 +281,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1424, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1425, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } } else { @@ -289,18 +294,18 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1410, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1411, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } } if(i >= xctx->lastsel -1) { /* update saved mouse position after processing all graphs */ xctx->mx_double_save = xctx->mousex_snap; xctx->my_double_save = xctx->mousey_snap; } - need_redraw = 1; } else if((button == Button5 && state == 0)) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { delta = (wy2 - wy1) / divy; delta_threshold = 1.0; yy1 = wy1 + delta * delta_threshold; @@ -309,6 +314,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1420, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1421, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { delta = (wx2 - wx1) / divx; @@ -319,14 +325,14 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1428, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1429, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(key == XK_Left) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { double m = G_Y(xctx->mousey); double a = m - wy1; double b = wy2 -m; @@ -338,6 +344,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1451, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1448, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { delta = (wx2 - wx1) / divx; @@ -348,14 +355,14 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1395, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1396, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(button == Button4 && state == 0) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { delta = (wy2 - wy1) / divy; delta_threshold = 1.0; yy1 = wy1 - delta * delta_threshold; @@ -364,6 +371,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1416, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1417, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { delta = (wx2 - wx1) / divx; @@ -374,14 +382,14 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1397, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1398, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(key == XK_Right) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { double m = G_Y(xctx->mousey); double a = m - wy1; double b = wy2 -m; @@ -393,6 +401,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1433, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1439, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { delta = (wx2 - wx1) / divx; @@ -403,12 +412,12 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1430, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1431, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(button == Button5 && state == ShiftMask) { if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { double m = G_Y(xctx->mousey); double a = m - wy1; double b = wy2 -m; @@ -420,6 +429,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1447, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1436, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { double m = G_X(xctx->mousex); @@ -433,14 +443,14 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1399, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1400, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(key == XK_Down) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { delta = (wy2 - wy1) / divy; delta_threshold = 1.0; yy1 = wy1 - delta * delta_threshold; @@ -449,6 +459,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1434, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1435, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { double m = G_X(xctx->mousex); @@ -462,12 +473,12 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1418, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1432, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(button == Button4 && state == ShiftMask) { if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { double m = G_Y(xctx->mousey); double a = m - wy1; double b = wy2 -m; @@ -479,6 +490,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1419, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1444, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { double m = G_X(xctx->mousex); @@ -492,14 +504,14 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1449, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1450, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(key == XK_Up) { double delta; if(xctx->graph_left) { - if(n == xctx->graph_master) { + if(!digital && n == xctx->graph_master) { delta = (wy2 - wy1) / divy; delta_threshold = 1.0; yy1 = wy1 + delta * delta_threshold; @@ -508,6 +520,7 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1437, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); my_snprintf(s, S(s), "%g", yy2); my_strdup(1438, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } } else { double m = G_X(xctx->mousex); @@ -521,65 +534,70 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup(1445, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); my_snprintf(s, S(s), "%g", xx2); my_strdup(1446, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - need_redraw = 1; } else if(key == 'f') { - if(xctx->graph_left) { - if(xctx->values) { - int i, j; - double v; - double min=0.0, max=0.0; - int first = 1; - char *saven, *nptr, *ntok, *node = NULL;; - my_strdup2(1426, &node, get_tok_value(r->prop_ptr,"node",0)); - nptr = node; - while( (ntok = my_strtok_r(nptr, "\n\t ", &saven)) ) { - nptr = NULL; - j = get_raw_index(ntok); - if(j >= 0) { - for(i = 0; i < xctx->npoints[dataset]; i++) { - v = get_raw_value(dataset, j, i); - if(first || v < min) {min = v; first = 0;} - if(first || v > max) {max = v; first = 0;} - } + if(xctx->values) { + if(xctx->graph_left) { + if(!digital) { + int i, j; + double v; + double min=0.0, max=0.0; + int first = 1; + char *saven, *nptr, *ntok, *node = NULL;; + my_strdup2(1426, &node, get_tok_value(r->prop_ptr,"node",0)); + nptr = node; + while( (ntok = my_strtok_r(nptr, "\n\t ", &saven)) ) { + nptr = NULL; + j = get_raw_index(ntok); + if(j >= 0) { + for(i = 0; i < xctx->npoints[dataset]; i++) { + v = get_raw_value(dataset, j, i); + if(first || v < min) {min = v; first = 0;} + if(first || v > max) {max = v; first = 0;} + } + } } + if(max == min) max += 0.01; + min = floor_to_n_digits(min, 2); + max = ceil_to_n_digits(max, 2); + my_free(1427, &node); + my_snprintf(s, S(s), "%g", min); + my_strdup(1422, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); + my_snprintf(s, S(s), "%g", max); + my_strdup(1423, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + need_redraw = 1; } - if(max == min) max += 0.01; - min = floor_to_n_digits(min, 2); - max = ceil_to_n_digits(max, 2); - my_free(1427, &node); - my_snprintf(s, S(s), "%g", min); - my_strdup(1422, &r->prop_ptr, subst_token(r->prop_ptr, "y1", s)); - my_snprintf(s, S(s), "%g", max); - my_strdup(1423, &r->prop_ptr, subst_token(r->prop_ptr, "y2", s)); + } else { + xx1 = get_raw_value(dataset, 0, 0); + xx2 = get_raw_value(dataset, 0, xctx->npoints[dataset] -1); + my_snprintf(s, S(s), "%g", xx1); + my_strdup(1409, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); + my_snprintf(s, S(s), "%g", xx2); + my_strdup(1412, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; } - } else { - xx1 = get_raw_value(dataset, 0, 0); - xx2 = get_raw_value(dataset, 0, xctx->npoints[dataset] -1); - my_snprintf(s, S(s), "%g", xx1); - my_strdup(1409, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); - my_snprintf(s, S(s), "%g", xx2); - my_strdup(1412, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); } - need_redraw = 1; } else if( event == MotionNotify && (state & Button1Mask) && xctx->graph_bottom ) { double wwx1, wwx2, p, delta, ccx, ddx; - delta = wx2 - wx1; - wwx1 = get_raw_value(dataset, 0, 0); - wwx2 = get_raw_value(dataset, 0, xctx->npoints[dataset] - 1); - ccx = (x2 - x1) / (wwx2 - wwx1); - ddx = x1 - wwx1 * ccx; - p = (xctx->mousex_snap - ddx) / ccx; - xx1 = p - delta / 2.0; - xx2 = p + delta / 2.0; - my_snprintf(s, S(s), "%g", xx1); - my_strdup(1442, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); - my_snprintf(s, S(s), "%g", xx2); - my_strdup(1443, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); - need_redraw = 1; + if(xctx->values) { + delta = wx2 - wx1; + wwx1 = get_raw_value(dataset, 0, 0); + wwx2 = get_raw_value(dataset, 0, xctx->npoints[dataset] - 1); + ccx = (x2 - x1) / (wwx2 - wwx1); + ddx = x1 - wwx1 * ccx; + p = (xctx->mousex_snap - ddx) / ccx; + xx1 = p - delta / 2.0; + xx2 = p + delta / 2.0; + my_snprintf(s, S(s), "%g", xx1); + my_strdup(1442, &r->prop_ptr, subst_token(r->prop_ptr, "x1", s)); + my_snprintf(s, S(s), "%g", xx2); + my_strdup(1443, &r->prop_ptr, subst_token(r->prop_ptr, "x2", s)); + need_redraw = 1; + } } else if(event == ButtonRelease && button != Button3) { xctx->ui_state &= ~GRAPHPAN; @@ -748,7 +766,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, break; case MotionNotify: - if( waves_selected()) { + if( waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1180,7 +1198,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key==XK_Right) /* left */ { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1191,7 +1209,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key==XK_Left) /* right */ { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1202,7 +1220,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key==XK_Down) /* down */ { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1213,7 +1231,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key==XK_Up) /* up */ { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1956,7 +1974,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } if(key=='f' && state == 0 ) /* full zoom */ { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -1980,7 +1998,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, break; case ButtonPress: /* end operation */ dbg(1, "callback(): ButtonPress ui_state=%ld state=%d\n",xctx->ui_state,state); - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -2120,21 +2138,21 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } } else if(button==Button5 && state == 0 ) { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } view_unzoom(CADZOOMSTEP); } else if(button==Button4 && state == 0 ) { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } view_zoom(CADZOOMSTEP); } else if(button==Button4 && (state & ShiftMask) && !(state & Button2Mask)) { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -2143,7 +2161,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, redraw_w_a_l_r_p_rubbers(); } else if(button==Button5 && (state & ShiftMask) && !(state & Button2Mask)) { - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } @@ -2365,7 +2383,7 @@ int callback(const char *winpath, int event, int mx, int my, KeySym key, } /* button==Button1 */ break; case ButtonRelease: - if(waves_selected()) { + if(waves_selected(state)) { waves_callback(event, mx, my, key, button, aux, state); break; } diff --git a/src/draw.c b/src/draw.c index a146e6df..342897db 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1695,7 +1695,7 @@ void calc_graph_area(int c, int i, double *x1, double *y1,double *x2,double *y2, /* calculate graph bounding box (container - margin) * This is the box where plot is done */ - *x1 = rx1 + *marginx; + *x1 = rx1 + *marginx + 40; *x2 = rx2 - *marginx/1.8; *y1 = ry1 + *marginy; tmp = *marginy < 30 ? 30 : *marginy; @@ -1786,13 +1786,32 @@ int schematic_waves_loaded(void) /* #define W_Y(y) (y2 - (y2 - y1) / (wy2 - wy1) * ((y) - wy1)) */ #define W_X(x) (cx * (x) + dx) #define W_Y(y) (cy * (y) + dy) + +static void get_y_points(int v, int first, int last, double cy, double dy, double *yarr, + int digital, int wcnt, int n_nodes, double ydelta) +{ + int p; + double yy; + int poly_npoints = 0; + for(p = first ; p < last; p++) { + yy = xctx->values[v][p]; + if(digital) { + yy = ydelta * wcnt / n_nodes + yy / n_nodes/1.5; + } + /* Build poly y array. Translate from graph coordinates to {x1,y1} - {x2, y2} world. */ + yarr[poly_npoints] = W_Y(yy); + poly_npoints++; + } +} + void draw_graph(int c, int i, int flags) { /* container box */ - double rx1, ry1, rx2, ry2, rw; + double rx1, ry1, rx2, ry2, rw/*, rh */; /* graph box (smaller due to margins) */ double x1, y1, x2, y2, w, h; /* graph coordinate, some defaults */ + double digital = 0; double wx1 = -2e-6; double wy1 = -1; double wx2 = 8e-6; @@ -1833,11 +1852,7 @@ void draw_graph(int c, int i, int flags) rx2 = r->x2; ry2 = r->y2; rw = (rx2 - rx1); - - /* set margins */ - calc_graph_area(c, i, &x1, &y1, &x2, &y2, &marginx, &marginy); - w = (x2 - x1); - h = (y2 - y1); + /* rh = (ry2 -ry1); */ /* get variables to plot, x/y range, grid info etc */ val = get_tok_value(r->prop_ptr,"unitx",0); unitx_suffix = val[0]; @@ -1861,10 +1876,16 @@ void draw_graph(int c, int i, int flags) if(val[0]) wx2 = atof(val); val = get_tok_value(r->prop_ptr,"y2",0); if(val[0]) wy2 = atof(val); + val = get_tok_value(r->prop_ptr,"digital",0); + if(val[0]) digital = atoi(val); /* plot single dataset */ val = get_tok_value(r->prop_ptr,"dataset",0); if(val[0]) dataset = atoi(val); if(dataset >= xctx->datasets) dataset = xctx->datasets - 1; + /* set margins */ + calc_graph_area(c, i, &x1, &y1, &x2, &y2, &marginx, &marginy); + w = (x2 - x1); + h = (y2 - y1); /* cache coefficients for faster graph coord transformations */ cx = (x2 - x1) / (wx2 - wx1); dx = x1 - wx1 * cx; @@ -1889,6 +1910,7 @@ void draw_graph(int c, int i, int flags) if(tmp < txtsizex) txtsizex = tmp; txtsizelab = marginy / 110; + if(digital) txtsizelab /= 1.3; /* background */ filledrect(0, NOW, rx1, ry1, rx2, ry2); @@ -1919,23 +1941,25 @@ void draw_graph(int c, int i, int flags) drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(wy2), W_X(wx1), W_Y(wy1), 0); drawline(GRIDLAYER, ADD, W_X(wx2), W_Y(wy2), W_X(wx2), W_Y(wy1), 0); /* horizontal grid lines */ - deltay = axis_increment(wy1, wy2, divy); - starty = axis_start(wy1, deltay, divy); - for(j = -1;; j++) { /* start one interval before to allow sub grids at beginning */ - wy = starty + j * deltay; - if(subdivy > 0) for(k = 1; k <=subdivy; k++) { - double subwy = wy + k * deltay / (subdivy + 1); - if(!axis_within_range(subwy, wy1, wy2)) continue; - if(axis_end(subwy, deltay, wy2)) break; - drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(subwy), W_X(wx2), W_Y(subwy), dash_sizex); + if(!digital) { + deltay = axis_increment(wy1, wy2, divy); + starty = axis_start(wy1, deltay, divy); + for(j = -1;; j++) { /* start one interval before to allow sub grids at beginning */ + wy = starty + j * deltay; + if(subdivy > 0) for(k = 1; k <=subdivy; k++) { + double subwy = wy + k * deltay / (subdivy + 1); + if(!axis_within_range(subwy, wy1, wy2)) continue; + if(axis_end(subwy, deltay, wy2)) break; + drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(subwy), W_X(wx2), W_Y(subwy), dash_sizex); + } + if(!axis_within_range(wy, wy1, wy2)) continue; + if(axis_end(wy, deltay, wy2)) break; + drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(wy), W_X(wx2), W_Y(wy), dash_sizex); + drawline(GRIDLAYER, ADD, W_X(wx1)-4, W_Y(wy), W_X(wx1), W_Y(wy), 0); /* axis marks */ + /* Y-axis labels */ + my_snprintf(lab, S(lab), "%g", wy * unity); + draw_string(3, NOW, lab, 0, 1, 0, 1, x1 - 2 - 30 * txtsizey, W_Y(wy), txtsizey, txtsizey); } - if(!axis_within_range(wy, wy1, wy2)) continue; - if(axis_end(wy, deltay, wy2)) break; - drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(wy), W_X(wx2), W_Y(wy), dash_sizex); - drawline(GRIDLAYER, ADD, W_X(wx1)-4, W_Y(wy), W_X(wx1), W_Y(wy), 0); /* axis marks */ - /* Y-axis labels */ - my_snprintf(lab, S(lab), "%g", wy * unity); - draw_string(3, NOW, lab, 0, 1, 0, 1, x1 - 2 - 30 * txtsizey, W_Y(wy), txtsizey, txtsizey); } /* first and last horizontal box delimiters */ drawline(GRIDLAYER, ADD, W_X(wx1), W_Y(wy1), W_X(wx2), W_Y(wy1), 0); @@ -1978,25 +2002,31 @@ void draw_graph(int c, int i, int flags) /* draw node labels in graph */ if(unity != 1.0) my_snprintf(tmpstr, S(tmpstr), "%s[%c]", ntok, unity_suffix); else my_snprintf(tmpstr, S(tmpstr), "%s", ntok); - draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0, rx1 + rw/n_nodes * wcnt, ry1, txtsizelab, txtsizelab); - /* clipping everything outside graph area */ + if(digital) { + draw_string(wave_color, NOW, tmpstr, 0, 1, 0, 1, + x1 - 2 - 30 * txtsizelab, + W_Y((wy2 - wy1) * ((double)wcnt + 0.5) / n_nodes ), + txtsizelab, txtsizelab); + } else { + draw_string(wave_color, NOW, tmpstr, 0, 0, 0, 0, rx1 + rw / n_nodes * wcnt, ry1, txtsizelab, txtsizelab); + } /* quickly find index number of ntok variable to be plotted */ entry = int_hash_lookup(xctx->raw_table, ntok, 0, XLOOKUP); if(xctx->values && entry) { int p, dset, ofs; int poly_npoints; int v; - int first, last; - double xx, yy; + int first; + double xx; double start; double end; double *xarr = NULL, *yarr = NULL; + /* clipping everything outside graph area */ bbox(START, 0.0, 0.0, 0.0, 0.0); bbox(ADD,x1, y1, x2, y2); bbox(SET, 0.0, 0.0, 0.0, 0.0); - ofs = 0; v = entry->value; start = (wx1 <= wx2) ? wx1 : wx2; @@ -2004,39 +2034,38 @@ void draw_graph(int c, int i, int flags) /* loop through all datasets found in raw file */ for(dset = 0 ; dset < xctx->datasets; dset++) { if(dataset == -1 || dset == dataset) { + double prev_x; first = -1; - last = 0; poly_npoints = 0; my_realloc(1401, &xarr, xctx->npoints[dset] * sizeof(double)); my_realloc(1402, &yarr, xctx->npoints[dset] * sizeof(double)); - /* skip if nothing in viewport */ - if(xctx->values[sweep_idx][ofs + xctx->npoints[dset] -1] > start) { - /* Process "npoints" simulation items - * p loop split repeated 2 timed (for xx and yy points) to preserve cache locality */ - for(p = ofs ; p < ofs + xctx->npoints[dset]; p++) { - xx = xctx->values[sweep_idx][p]; - if(xx > end) { - break; - } - if(xx >= start) { - if(first == -1) first = p; - /* Build poly x array. Translate from graph coordinates to {x1,y1} - {x2, y2} world. */ - xarr[poly_npoints] = W_X(xx); - poly_npoints++; + /* Process "npoints" simulation items + * p loop split repeated 2 timed (for x and y points) to preserve cache locality */ + for(p = ofs ; p < ofs + xctx->npoints[dset]; p++) { + xx = xctx->values[sweep_idx][p]; + if(xx > end || (sweep_idx == 0 && (p > ofs && fabs(xx) < fabs(prev_x))) ) { + if(first != -1) { + /* get y-axis points */ + get_y_points(v, first, p, cy, dy, yarr, digital, wcnt, n_nodes, wy2 - wy1); + /* plot data */ + drawpolygon(wave_color, 0, xarr, yarr, poly_npoints, 0, 0); + poly_npoints = 0; + first = -1; } } - last = p; - if(first != -1) { - poly_npoints = 0; - for(p = first ; p < last; p++) { - yy = xctx->values[v][p]; - /* Build poly y array. Translate from graph coordinates to {x1,y1} - {x2, y2} world. */ - yarr[poly_npoints] = W_Y(yy); - poly_npoints++; - } - /* plot data */ - drawpolygon(wave_color, 0, xarr, yarr, poly_npoints, 0, 0); + if(xx >= start && xx <= end) { + if(first == -1) first = p; + /* Build poly x array. Translate from graph coordinates to {x1,y1} - {x2, y2} world. */ + xarr[poly_npoints] = W_X(xx); + poly_npoints++; } + prev_x = xx; + } + if(first != -1) { + /* get y-axis points */ + get_y_points(v, first, p, cy, dy, yarr, digital, wcnt, n_nodes, wy2 - wy1); + /* plot data */ + drawpolygon(wave_color, 0, xarr, yarr, poly_npoints, 0, 0); } } /* if(dataset == -1 || dset == dataset) */ diff --git a/xschem_library/examples/LCC_instances.sch b/xschem_library/examples/LCC_instances.sch index 406332f3..2c358dca 100644 --- a/xschem_library/examples/LCC_instances.sch +++ b/xschem_library/examples/LCC_instances.sch @@ -20,26 +20,26 @@ L 4 1420 -730 1440 -750 {dash=3} L 4 1420 -770 1420 -730 {dash=3} L 4 1420 -770 1440 -750 {dash=3} L 4 1300 -750 1420 -750 {dash=3} -B 2 10 -930 480 -680 {flags=1 -y1 = 0 -y2 = 3 +B 2 830 -490 1300 -280 {flags=1 +y1 = -0.0578106 +y2 = 3.04806 divy = 6 -x1=0 -x2=3 -divx=6 -node="v(z) v(a)" -color="6 8" -sweep="v(a) v(z)"} -B 2 860 -470 1330 -260 {flags=1 -y1 = 0 -y2 = 3 -divy = 6 -x1=0 -x2=3 +x1=0.0194063 +x2=3.15766 divx=6 node="v(a) v(zz) v(zzz)" color="4 6 8" sweep="v(a)"} +B 2 30 -930 500 -720 {flags=1 +y1 = -0.0578106 +y2 = 3.04806 +divy = 6 +x1=-0.0714119 +x2=3.06686 +divx=6 +node="v(a) v(z)" +color="4 6 8" +sweep="v(z) v(a)"} P 4 5 560 -700 560 -510 1350 -510 1350 -700 560 -700 {dash=3} P 4 5 770 -920 770 -730 1300 -730 1300 -920 770 -920 {dash=3} T {These 2 instances are equivalent} 290 -280 0 0 0.4 0.4 {} @@ -73,10 +73,12 @@ C {lab_pin.sym} 50 -110 0 0 {name=p5 lab=0} C {code_shown.sym} 580 -150 0 0 {name=STIMULI only_toplevel=true tclcommand="xschem edit_vi_prop" -value=" -.dc v1 0 3 0.01 +value=".control +dc v1 0 3 0.001 * .tran 10n 10u uic -.save all +save all +write LCC_instances.raw +.endc "} C {code.sym} 760 -170 0 0 {name=MODEL only_toplevel="true" diff --git a/xschem_library/rom8k/rom8k.sch b/xschem_library/rom8k/rom8k.sch index 71850c43..1c96bb18 100644 --- a/xschem_library/rom8k/rom8k.sch +++ b/xschem_library/rom8k/rom8k.sch @@ -27,120 +27,73 @@ L 8 1150 -160 1180 -160 {} L 8 1180 -160 1180 -120 {} L 8 1180 -120 1300 -120 {} L 8 820 -120 950 -120 {} -B 2 1860 -890 3010 -810 {flags=1 -y1 = 0 -y2 = 1 +B 2 1840 -360 2890 -280 {flags=1 +y1 = -0.0039 +y2 = 0.87 divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 +x1=1.28096e-07 +x2=1.98813e-07 divx=10 node=" v(ldbl[0]) v(ldbl[16]) v(ldbl[32]) v(ldbl[1]) v(ldbl[17]) v(ldbl[33]) v(ldbl[2]) v(ldbl[18]) v(ldbl[34]) " color="8 9 10 11 12 13 14 15 16 17 18" unitx=n} -B 2 1860 -810 3010 -730 {flags=1 -y1 = 0 +B 2 1840 -920 2890 -710 {flags=1 +digital=0 +y1 = -0.00091 y2 = 1.5 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node=" -v(ldl1x[0]) v(ldl1x[1]) v(ldl1x[2]) v(ldl1x[3]) -" -color="6 7 8 9 10 11 12 13" unitx=n} -B 2 1860 -1180 3010 -970 {flags=1 -y1 = -0.251577 -y2 = 1.74839 divy = 4 -x1=1.25059e-07 -x2=1.84194e-07 +x1=1.28096e-07 +x2=1.98813e-07 divx=10 subdivx=4 node="v(ldcp) v(ldyms[4]) v(ldyms[5]) v(ldyms[6]) v(ldyms[7])" color="6 12 13 14 15" unitx=n} -B 2 1860 -490 3010 -410 {flags=1 -y1 = -0.1 +B 2 1840 -280 2890 -120 {flags=1 +y1 = -0.0072 y2 = 1.6 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(ldprech)" -color=4 unitx=n subdivy=2} -B 2 1860 -410 3010 -330 {flags=1 -y1 = 0 -y2 = 1.5 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(lden) v(ldcp)" -color=12\\ 18 unitx=n subdivy=2} -B 2 1860 -730 3010 -570 {flags=1 -y1 = -0.16335 -y2 = 1.6335 divy = 3 subdivy=1 subdivx = 4 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 +x1=1.28096e-07 +x2=1.98813e-07 divx=10 node=" v(ldcp) v(ldwl[0]) v(ldwl[1]) v(ldwl[2]) v(ldwl[3]) v(ldwl[4]) v(ldwl[5]) v(ldwl[6]) v(ldwl[16]) v(ldwl[7]) v(ldwl[8]) v(ldwl[9])" -color="12 15 16 17 18 19 20 21 11 7 4 8 9" +xcolor="12 15 16 17 18 19 20 21 11 7 4 8 9" +color="4 5" unitx=n } -B 2 1860 -330 3010 -250 {flags=1 -y1 = 0 -y2 = 1 +B 2 1840 -120 2890 -40 {flags=1 +y1 = -0.021 +y2 = 0.9 divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 +x1=1.28096e-07 +x2=1.98813e-07 divx=10 node="v(ldymsref)" color=3 unitx=n subdivy=4} -B 2 1860 -250 3010 -170 {flags=1 +B 2 1840 -710 2890 -360 {flags=1 +digital=1 y1 = 0 y2 = 1.5 divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(lden)" -color=4 unitx=n subdivy=2} -B 2 1860 -170 3010 -90 {flags=1 -y1 = 0 -y2 = 1.5 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(lden) v(ldprech)" -color=12\\ 16 unitx=n subdivy=2} -B 2 1860 -90 3010 -10 {flags=1 -y1 = 0 -y2 = 1.5 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(lden) v(ldcp)" -color=12\\ 5 unitx=n subdivy=2} -B 2 1860 -570 3010 -490 {flags=1 -y1 = 0 -y2 = 1.5 -divy = 1 -subdivy=2 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(ldl1x[1])" -color=4 unitx=n} -B 2 1860 -970 3010 -890 {flags=1 -y1 = 0 -y2 = 1.5 -divy = 1 -x1=1.25059e-07 -x2=1.84194e-07 divx=10 -node="v(lden) v(ldprech)" -color=4\\ 6 unitx=n} +x1=1.28096e-07 +x2=1.98813e-07 divx=10 +node="v(ldcp) v(lden) v(ldprech) +--- +v(ldl1x[0]) v(ldl1x[1]) v(ldl1x[2]) v(ldl1x[3]) +v(ldl1x[4]) v(ldl1x[5]) v(ldl1x[6]) v(ldl1x[7]) +--- +v(ldy1[0]) v(ldy1[1]) v(ldy1[2]) v(ldy1[3]) +" +color=4 +xcolor="5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 3 4 5 6" + unitx=n +} B 7 950 -250 980 -80 {} B 7 1150 -250 1180 -80 {} B 21 10 -970 240 -750 {} @@ -158,12 +111,12 @@ N 150 -420 150 -400 {lab=vss} N 10 -270 10 -250 {lab=vss} N 10 -580 10 -560 {lab=vss} N 10 -420 10 -400 {lab=vss} -N 1720 -350 1720 -330 {lab=vss} -N 1720 -530 1720 -510 {lab=vss} -N 1540 -350 1540 -330 {lab=vss} -N 1540 -530 1540 -510 {lab=vss} -N 1720 -180 1720 -160 {lab=vss} -N 1540 -180 1540 -160 {lab=vss} +N 1710 -350 1710 -330 {lab=vss} +N 1710 -530 1710 -510 {lab=vss} +N 1530 -350 1530 -330 {lab=vss} +N 1530 -530 1530 -510 {lab=vss} +N 1710 -180 1710 -160 {lab=vss} +N 1530 -180 1530 -160 {lab=vss} C {title.sym} 170 0 0 0 {name=l3 author="Stefan Schippers"} C {code.sym} 590 -160 0 0 {name=STIMULI value=" .options SCALE=0.10 @@ -284,36 +237,36 @@ C {rom2_col_prech.sym} 1190 -990 0 0 {name=xcpr[256:0]} C {lab_pin.sym} 1340 -1000 0 1 {name=p20 lab=LDBL[255:0],LDBLREF} C {lab_pin.sym} 1040 -1000 0 0 {name=p1 lab=LDCP_COL_B} C {lab_pin.sym} 1040 -980 0 0 {name=p38 lab=vss} -C {lab_pin.sym} 1720 -410 0 1 {name=p47 lab=LDPRECH} -C {lab_pin.sym} 1720 -330 0 1 {name=p52 lab=vss} -C {capa.sym} 1720 -380 0 0 {name=c0 m=1 value=66f} -C {lab_pin.sym} 1720 -590 0 1 {name=p55 lab=LDSAL} -C {lab_pin.sym} 1720 -510 0 1 {name=p58 lab=vss} -C {capa.sym} 1720 -560 0 0 {name=c6 m=1 value=34f} -C {lab_pin.sym} 1540 -410 0 1 {name=p59 lab=LDCP_ROWDEC} -C {lab_pin.sym} 1540 -330 0 1 {name=p60 lab=vss} -C {capa.sym} 1540 -380 0 0 {name=c7 m=1 value=280f} -C {lab_pin.sym} 1540 -590 0 1 {name=p64 lab=LDCP_SA} -C {lab_pin.sym} 1540 -510 0 1 {name=p65 lab=vss} -C {capa.sym} 1540 -560 0 0 {name=c8 m=1 value=44f} -C {lab_pin.sym} 1720 -240 0 1 {name=p15 lab=LDCP_COL_B} -C {lab_pin.sym} 1720 -160 0 1 {name=p24 lab=vss} -C {capa.sym} 1720 -210 0 0 {name=c9 m=1 value=63f} -C {lab_pin.sym} 1540 -240 0 1 {name=p43 lab=LDCP_ADDLAT_B} -C {lab_pin.sym} 1540 -160 0 1 {name=p66 lab=vss} -C {capa.sym} 1540 -210 0 0 {name=c10 m=1 value=12f} +C {lab_pin.sym} 1710 -410 0 1 {name=p47 lab=LDPRECH} +C {lab_pin.sym} 1710 -330 0 1 {name=p52 lab=vss} +C {capa.sym} 1710 -380 0 0 {name=c0 m=1 value=66f} +C {lab_pin.sym} 1710 -590 0 1 {name=p55 lab=LDSAL} +C {lab_pin.sym} 1710 -510 0 1 {name=p58 lab=vss} +C {capa.sym} 1710 -560 0 0 {name=c6 m=1 value=34f} +C {lab_pin.sym} 1530 -410 0 1 {name=p59 lab=LDCP_ROWDEC} +C {lab_pin.sym} 1530 -330 0 1 {name=p60 lab=vss} +C {capa.sym} 1530 -380 0 0 {name=c7 m=1 value=280f} +C {lab_pin.sym} 1530 -590 0 1 {name=p64 lab=LDCP_SA} +C {lab_pin.sym} 1530 -510 0 1 {name=p65 lab=vss} +C {capa.sym} 1530 -560 0 0 {name=c8 m=1 value=44f} +C {lab_pin.sym} 1710 -240 0 1 {name=p15 lab=LDCP_COL_B} +C {lab_pin.sym} 1710 -160 0 1 {name=p24 lab=vss} +C {capa.sym} 1710 -210 0 0 {name=c9 m=1 value=63f} +C {lab_pin.sym} 1530 -240 0 1 {name=p43 lab=LDCP_ADDLAT_B} +C {lab_pin.sym} 1530 -160 0 1 {name=p66 lab=vss} +C {capa.sym} 1530 -210 0 0 {name=c10 m=1 value=12f} C {spice_probe.sym} 710 -450 2 1 {name=p125 analysis=tran} C {spice_probe.sym} 150 -640 0 0 {name=p69 analysis=tran} C {spice_probe.sym} 10 -640 0 0 {name=p70 analysis=tran} C {spice_probe.sym} 10 -480 0 0 {name=p73 analysis=tran} C {spice_probe.sym} 150 -480 0 0 {name=p74 analysis=tran} C {spice_probe.sym} 10 -330 0 0 {name=p75 analysis=tran} -C {spice_probe.sym} 1540 -590 0 0 {name=p76 analysis=tran} -C {spice_probe.sym} 1540 -410 0 0 {name=p83 analysis=tran} -C {spice_probe.sym} 1540 -240 0 0 {name=p84 analysis=tran} -C {spice_probe.sym} 1720 -240 0 0 {name=p85 analysis=tran} -C {spice_probe.sym} 1720 -410 0 0 {name=p86 analysis=tran} -C {spice_probe.sym} 1720 -590 0 0 {name=p87 analysis=tran} +C {spice_probe.sym} 1530 -590 0 0 {name=p76 analysis=tran} +C {spice_probe.sym} 1530 -410 0 0 {name=p83 analysis=tran} +C {spice_probe.sym} 1530 -240 0 0 {name=p84 analysis=tran} +C {spice_probe.sym} 1710 -240 0 0 {name=p85 analysis=tran} +C {spice_probe.sym} 1710 -410 0 0 {name=p86 analysis=tran} +C {spice_probe.sym} 1710 -590 0 0 {name=p87 analysis=tran} C {spice_probe.sym} 1340 -300 2 1 {name=p88 analysis=tran} C {spice_probe.sym} 1340 -530 0 0 {name=p89 analysis=tran} C {spice_probe.sym} 1340 -620 0 0 {name=p90 analysis=tran}