cleanup
diff --git a/ecp5/gfx.cc b/ecp5/gfx.cc
index 23053b3..a06cbef 100644
--- a/ecp5/gfx.cc
+++ b/ecp5/gfx.cc
@@ -451,17 +451,68 @@
     }
 }
 
+void straightLine(std::vector<GraphicElement> &g, GraphicElement &el,int x, int y, WireId src, IdString src_type, GfxTileWireId src_id,WireId dst, IdString dst_type, GfxTileWireId dst_id)
+{
+    setSource(el,x,y,src,src_type,src_id);
+    setDestination(el,x,y,dst,dst_type,dst_id);
+    g.push_back(el);
+}
+
+void toSameSideHor(std::vector<GraphicElement> &g, GraphicElement &el,int x, int y, WireId src, IdString src_type, GfxTileWireId src_id,WireId dst, IdString dst_type, GfxTileWireId dst_id, GraphicElement::style_t style, int idx)
+{
+    int sign = (src_type==dst_type) ? 1 : -1;
+    setSource(el,x,y,src,src_type,src_id);
+    el.x2 = el.x1;
+    el.y2 = y + switchbox_y1 + (switchbox_y2-switchbox_y1)/2 + sign * 0.0017f*idx;
+    g.push_back(el);
+    
+    GraphicElement el2;    
+    el2.type = GraphicElement::TYPE_ARROW;
+    el2.style = style;
+
+    setDestination(el2,x,y,dst,dst_type,dst_id);
+    
+    el.x1 = el2.x2;
+    el.y1 = el.y2;
+    g.push_back(el);
+
+    el2.x1 = el.x1;
+    el2.y1 = el.y1;
+    g.push_back(el2);
+}
+
+void toSameSideVer(std::vector<GraphicElement> &g, GraphicElement &el,int x, int y, WireId src, IdString src_type, GfxTileWireId src_id,WireId dst, IdString dst_type, GfxTileWireId dst_id, GraphicElement::style_t style, int idx)
+{
+    int sign = (src_type==dst_type) ? 1 : -1;
+    setSource(el,x,y,src,src_type,src_id);
+    el.x2 = x + switchbox_x1 + (switchbox_x2-switchbox_x1)/2 + sign * 0.0017f*idx;
+    el.y2 = el.y1;
+    g.push_back(el);
+    
+    GraphicElement el2;    
+    el2.type = GraphicElement::TYPE_ARROW;
+    el2.style = style;
+
+    setDestination(el2,x,y,dst,dst_type,dst_id);
+    
+    el.x1 = el.x2;
+    el.y1 = el2.y2;
+    g.push_back(el);
+
+    el2.x1 = el.x1;
+    el2.y1 = el.y1;
+    g.push_back(el2);
+}
+
 void gfxTilePip(std::vector<GraphicElement> &g, int x, int y, int w, int h, WireId src, IdString src_type, GfxTileWireId src_id, WireId dst, IdString dst_type, GfxTileWireId dst_id, GraphicElement::style_t style)
 {    
     GraphicElement el;
-    el.type = GraphicElement::TYPE_LINE;
+    el.type = GraphicElement::TYPE_ARROW;
     el.style = style;
 
     if (src_type == id_WIRE_TYPE_H06 && dst_type == id_WIRE_TYPE_V06) {
-        setSource(el,x,y,src,src_type,src_id);
-        setDestination(el,x,y,dst,dst_type,dst_id);
-        g.push_back(el);
-    } 
+        straightLine(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id);
+    }
     if (src_type == id_WIRE_TYPE_H01 && dst_type == id_WIRE_TYPE_V06) {
         if (src_id <= TILE_WIRE_H01E0101) {
 
@@ -487,185 +538,38 @@
         }
     }      
     if (src_type == id_WIRE_TYPE_V02 && dst_type == id_WIRE_TYPE_V06) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = x + switchbox_x1 + (switchbox_x2-switchbox_x1)/2 + 0.0017f*(src_id - TILE_WIRE_V02N0701);
-        el.y2 = el.y1;
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el.x2;
-        el.y1 = el2.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }            
+        toSameSideVer(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_V02N0701);
+    }
     if (src_type == id_WIRE_TYPE_V06 && dst_type == id_WIRE_TYPE_V02) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = x + switchbox_x1 + (switchbox_x2-switchbox_x1)/2 + 0.0017f*(src_id - TILE_WIRE_V06N0303);
-        el.y2 = el.y1;
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el.x2;
-        el.y1 = el2.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }            
+        toSameSideVer(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_V06N0303);
+    }
     if (src_type == id_WIRE_TYPE_V02 && dst_type == id_WIRE_TYPE_V02) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = x + switchbox_x1 + (switchbox_x2-switchbox_x1)/2 - 0.0017f*(src_id - TILE_WIRE_V02N0701);
-        el.y2 = el.y1;
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el.x2;
-        el.y1 = el2.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }        
+        toSameSideVer(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_V02N0701);
+    }
     if (src_type == id_WIRE_TYPE_V06 && dst_type == id_WIRE_TYPE_V06) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = x + switchbox_x1 + (switchbox_x2-switchbox_x1)/2 + 0.0017f*(src_id - TILE_WIRE_V06N0303);
-        el.y2 = el.y1;
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el.x2;
-        el.y1 = el2.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }          
+        toSameSideVer(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_V06N0303);
+    }
     if (src_type == id_WIRE_TYPE_H02 && dst_type == id_WIRE_TYPE_V02) {
-        setSource(el,x,y,src,src_type,src_id);
-        setDestination(el,x,y,dst,dst_type,dst_id);
-
-        g.push_back(el);
-    }        
+        straightLine(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id);
+    }
     if (src_type == id_WIRE_TYPE_V02 && dst_type == id_WIRE_TYPE_H02) {
-        setSource(el,x,y,src,src_type,src_id);
-        setDestination(el,x,y,dst,dst_type,dst_id);
-
-        g.push_back(el);
-    }   
+        straightLine(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id);
+    }
     if (src_type == id_WIRE_TYPE_V06 && dst_type == id_WIRE_TYPE_H02) {
-        setSource(el,x,y,src,src_type,src_id);
-        setDestination(el,x,y,dst,dst_type,dst_id);
-        g.push_back(el);
-    }    
+        straightLine(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id);
+    }
     if (src_type == id_WIRE_TYPE_H02 && dst_type == id_WIRE_TYPE_H02) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = el.x1;
-        el.y2 = y + switchbox_y1 + (switchbox_y2-switchbox_y1)/2 + 0.0017f*(src_id - TILE_WIRE_H02W0701);
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el2.x2;
-        el.y1 = el.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }        
+        toSameSideHor(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_H02W0701);
+    }
     if (src_type == id_WIRE_TYPE_H02 && dst_type == id_WIRE_TYPE_H06) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = el.x1;
-        el.y2 = y + switchbox_y1 + (switchbox_y2-switchbox_y1)/2 + 0.0017f*(src_id - TILE_WIRE_H02W0701);
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el2.x2;
-        el.y1 = el.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }        
-
+        toSameSideHor(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_H02W0701);
+    }
     if (src_type == id_WIRE_TYPE_H06 && dst_type == id_WIRE_TYPE_H06) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = el.x1;
-        el.y2 = y + switchbox_y1 + (switchbox_y2-switchbox_y1)/2 - 0.0017f*(src_id - TILE_WIRE_H06W0303);
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el2.x2;
-        el.y1 = el.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }        
-
+        toSameSideHor(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_H06W0303);
+    }
     if (src_type == id_WIRE_TYPE_H06 && dst_type == id_WIRE_TYPE_H02) {
-        setSource(el,x,y,src,src_type,src_id);
-        el.x2 = el.x1;
-        el.y2 = y + switchbox_y1 + (switchbox_y2-switchbox_y1)/2 - 0.0017f*(src_id - TILE_WIRE_H06W0303);
-        g.push_back(el);
-        
-        GraphicElement el2;    
-        el2.type = GraphicElement::TYPE_LINE;
-        el2.style = style;
-
-        setDestination(el2,x,y,dst,dst_type,dst_id);
-        
-        el.x1 = el2.x2;
-        el.y1 = el.y2;
-        g.push_back(el);
-
-        el2.x1 = el.x1;
-        el2.y1 = el.y1;
-        g.push_back(el2);
-    }        
-
+        toSameSideHor(g,el,x,y,src,src_type,src_id,dst,dst_type,dst_id,style,src_id - TILE_WIRE_H06W0303);
+    }
 }
 
 NEXTPNR_NAMESPACE_END