diff --git a/pltfiles/das-dot.plt b/pltfiles/das-dot.plt
new file mode 100644
index 0000000..2cf5bf8
--- /dev/null
+++ b/pltfiles/das-dot.plt
@@ -0,0 +1 @@
+5|%[5h'A4t(F4`)L3l*Q2x+W2d,\1p.B0|/G0h0M/t1R/`2X.l3]-x5C-d6H,p7N+|8S+h9Y*t:^*`<D5|$V)l$V)l$B)l<D*`$L*`$V*t$L*t$V+h$L+h$V+|$L+|$V,p$B,p<D-d$L-d$V-x$L-x$V.l$L.l$V/`$L/`$V/t$B/t<D0h$L0h$V0|$L0|$V1p$L1p$V2d$L2d$V2x$B2x<D3l$L3l$V4`$L4`$V4t$L4t$V5h$L5h$V5|$B5|<D)l$V)l<D(x$V5|$V)b%[)l%[)b'A)l'A)b(F)l(F)b)L)l)L(x*Q5|*Q)b+W)l+W)b,\)l,\)b.B)l.B)b/G)l/G(x0M5|0M)b1R)l1R)b2X)l2X)b3])l3])b5C)l5C(x6H5|6H)b7N)l7N)b8S)l8S)b9Y)l9Y)b:^)l:^(x<D5|<D(c$Q0(c*L5(c0A10(c5\15(c;X20)e#Q0,i#Q5/m#C102q#C155u#C206p&HEXAMPLE OF HARDWARE DASHED AND DOTTED LINES$v&\NORMAL VECTORS$v$V$v&Ha*`%[*t'A+h(F+|)L,p*Q-d+W-x,\.l.B/`/G/t0M0h1R0|2X1p3]2d5C2x6H3l7N4`8S4t9Y5h:^5|<D#d$V#d&H
#d&\CLOSE DOTSb*`%[*~'A+|(F-n)L/`*Q0h+W0|,\1p.B2d/G2n0M2x1R2n2X2d3]1p5C0|6H0h7N/`8S-n9Y+|:^*~<D$v.B$v/T
$v0HDOT-DASHc/j%[/t'A0h(F0r)L1`*Q1f+W1i,\1h.B1f/G0|0M0r1R0h2X/`3].b5C-n6H-d7N,t8S,p9Y,n:^,l<D#d.B#d/T
#d0HSHORT DASHESd1p%[0|'A/t(F-x)L,f*Q+h+W*~,\*|.B+`/G+h0M+r1R,t2X-x3]/`5C0h6H0|7N1f8S1p9Y2d:^2x<D$v6P$v8B
$v8VLONG DASHES


diff --git a/pltfiles/ekg.plt b/pltfiles/ekg.plt
deleted file mode 100644
index b385869..0000000
--- a/pltfiles/ekg.plt
+++ /dev/null
@@ -1 +0,0 @@
-� á ÁŸŠŠŠŠŠŠŠŸ£{ DDÅHÉÊúK{ÌMNÏPÑÒSÔUV×ØYZÛú\{ÝÞÞú!ÀABÃDÅÆGHÉÊKÌùMNÏPÑÒSÔxUVù×ØxYZùÛx\ÝÞùÞù"ÀxABùÃDÅÆGHÉxÊKÌMNùÏPÑÒSÔUV×ØYZÛ\ÝÞÞù£ÀúAùBÃDúÅÆùGHúÉÊK{ÌüMN}ÏPüÑÒ{SüÔUV×ØYZúÛ\ÝÞùÞù$ÀABÃDÅxÆwGõHÉúÊ$cKðÌ~M¥ëNtÏóPäÑ$rÒáS£xÔõUwVx×ØYZÛw\ÝöÞwÞö¥ÀABÃDÅÆGHÉÊKÌMNõÏPÑÒSÔUV×ØYZÛ\ÝÞtÞt¦ÀõAtBÃDÅÆGHÉÊKÌMõNtÏPõÑÒSöÔUwV×xØYùZÛ\ÝúÞ{Þ{'ÀABÃDÅÆüG{HÉúÊKÌMùNÏPÑÒSÔUV×ØxYZÛ\ùÝÞúÞú(ÀùABÃDÅÆGHÉxÊKÌMNwÏöYZÛ\ÝÞÞö©ÀABõÃDÅÆGHÉÊKÌöMNÏPõÑöÒSÔUV×õØYöZõÛ\ÝÞÞõªÀABÃDÅtÆõGHtÉÊõKÌMNÏPÑÒöSwÔUVx×ØwYZöÛw\xÝÞÞx+ÀwAöBÃDÅõÆtGHÉÊKÌMNrÏqPrÑõÒ~S$jÔxU¥eVî×Ø`Y$îZ£}Ût\qÝóÞtÞt¬ÀABóÃrDÅÆGqHrÉÊKÌqMNrÏqPÑrÒSqÔUV×ØYZÛð\ÝÞÞð-ÀABqÃDÅÆGðHÉÊKÌMNÏqPðÑÒSÔqUV×ØYZrÛ\ÝóÞÞó.ÀtABõÃDöÅÆwGHÉÊNÏPöÑÒõSÔUV×tØYZõÛ\ÝöÞõÞõ¯ÀAtBÃDÅÆGHõÉÊKÌtMõNtÏPóÑtÒSÔUV×ØYZÛ\ÝóÞÞó0ÀABÃDÅÆGHrÉÊóKÌMNtÏPóÑÒSÔUV×ØtYZÛ\ÝóÞtÞt±ÀABóÃtDóÅtÆGHÉõÊtKÌMõNÏöPÑÒõSÔUV×öØwYxZÛ\ÝwÞxÞù²ÀAxBÃDwÅöÆGHÉÊKõÌMNÏPÑtÒóStÔwU$`Vl×úØ¥çYqZóÛf\$tÝâÞ£õÞð3ÀoAqBrÃóDõÅÆGtHóÉÊtKÌMNÏPÑÒSÔUV×ØóYZtÛ\ÝóÞÞt´ÀABÃDÅÆóGHtÉÊKóÌMNÏtPÑÒSÔUV×ØYõZÛ\öÝwÞxÞx5ÀwAxBÃwDxÅùÆGHúÉÊKÌMNÏùPÑÒSÔUV×ØxYZùÛ\xÝÞÞù6ÀxABÃùDÅÆGúHùÉÊKúÌMùNÏPÑÒSÔxUV×ùØxYZÛ\ùÝxÞÞx·ÀABÃDÅÆGHÉÊKÌùMNxÏPÑÒSÔùUV×xØYZùÛx\ÝùÞÞx¸ÀùABxÃDÅùÆGHÉÊKÌMúNÏPùÑÒúSÔUV×ØY{ZüÛ\}ÝÞÞ}9ÀüA{BüÃ}DüÅÆG{HÉúÊKÌMNùÏPÑÒSÔxUöV×ùØ$áYlZúÛ¥ç\rÝõÞiÞ$x:ÀeA£xBrÃóDtÅõÆöGwHxÉwÊöKÌMõNÏPÑöÒõSÔUV×tØYZÛ\ÝÞÞó»ÀABtÃóDÅÆGHrÉÊóKrÌMNÏPÑÒSÔUV×ØYZÛ\ÝÞóÞó<ÀABtÃDõÅÆöGwHÉÊKxÌMwNÏxPÑÒSÔUVw×ØYZÛ\ÝÞÞw½ÀABÃDÅÆGöHwÉÊKÌMNöÏPÑwÒSöÔUwVö×ØYZÛõ\ÝÞÞõ¾ÀABÃDtÅõÆGHÉÊKÌtMNõÏPtÑÒSÔUV×ØYZÛ\ÝÞÞt?ÀAóBÃDÅÆGHÉrÊKóÌMNrÏPóÑÒSÔUV×ØYZÛ\tÝ–+ú DDÅÆGwHÉúÊKÌMNÏùPÑxÒùSúÔUxV×ùØYúZÛ\xÝùÞúÞ{!ÀAúBùÃúDÅùÆG{HüÉ{ÊKüÌMúNÏPÑ{ÒSÔüU{V×üØúYZ{Û\üÝÞ{Þ{"ÀüAB{ÃDÅúÆG{HÉÊúKÌüMNÏ{PüÑÒ{SÔUüV×{ØYZúÛ\üÝÞÞü£À{ABüÃ{DxÅÆGHwÉÊùKúÌMxNwÏxPÑùÒxSwÔxUöVw×xØYùZúÛ{\Ý}Þ~Þ}$ÀüABÃD}ÅÆGH{ÉöÊoKeÌªüMqNçÏëP+eÑðÒtSwÔxUùVx×ùØ{Y}ZÛšÿ\~ÝšÿÞÞ~¥ÀšÿA¬`BÃ+šÿD¬`ÅÆGHÉÊKÌMNÏ+šÿPÑ~ÒšÿS¬`ÔU+šÿV×¬`Ø+šÿYZ¬`Û+šÿ\~ÝšÿÞ¬`Þ`¦À+šÿA~B¬`ÃD+~Å}ÆšÿGH~ÉÊKÌMN}ÏPÑüÒ}S~Ô}UüV×Ø{YZÛ\ÝúÞÞ{'ÀúAB{ÃDÅúÆGHÉÊK{ÌüM{NÏúPùÑÒúSÔUùV×ØúY{ZÛú\ùÝÞÞ{(ÀAúBÃDÅÆGùHÉxÊùK{ÌMúNÏPÑÒ{SÔUVú×ØY{ZÛ\ùÝÞúÞú©ÀùABúÃDÅÆGHÉÊ{KÌúMùNÏúPÑÒùSxÔùUV×úØùYZúÛ\ùÝxÞùÞúªÀ{AúBÃùDúÅùÆxGùHÉÊxKÌMöNõÏöPÑõÒSwÔUxVö×ØõYwZÛö\wÝÞöÞö+ÀABwÃDÅúÆ{GúHÉÊùKúÌM{NúÏPxÑõÒíSäÔªúUqVi×çØšÿY+íZrÛ\tÝõÞwÞö¬ÀAxBùÃ{DÅüÆG}HÉÊKÌüM{NüÏP{ÑüÒ}SüÔ}UüV}×{ØYüZÛ}\üÝ}ÞÞü-À}AB~Ã}DüÅ{ÆGxHúÉüÊ}K~ÌüMúN{ÏùPúÑ{ÒSÔUúV×xØùYúZwÛ\xÝwÞõÞw.ÀxAöBwÃõDÅöÆõGtHÉöÊKtÌMõNÏöPtÑÒõStÔUõVt×õØtYZõÛó\ÝÞtÞó¯ÀABõÃóDqÅrÆóGöHõÉrÊóKÌõMtNÏPÑõÒSóÔqUóVt×öØYZõÛö\õÝöÞóÞó0ÀAõBöÃDwÅöÆtGoHqÉtÊöKwÌtMõNwÏPtÑöÒõSxÔUwVö×õØwYõZóÛù\ÝwÞõÞt±ÀwA{BùÃDöÅxÆwGHÉtÊöKwÌMxN{ÏùPöÑtÒóSÔoUrVx×ØwYóZõÛ\ÝqÞÞr²ÀóAtBõÃtDóÅtÆwGxHÉùÊxKùÌMxNwÏõPöÑÒxSùÔwUîVe×ªüØóYèZeÛú\+jÝíÞîÞo3ÀrAðBrÃõDöÅÆwGxHwÉÊKÌùMúNÏùPúÑÒxSÔúUùVx×ØùYZxÛù\ÝxÞúÞù´ÀúAxBùÃúDxÅùÆúGùHÉÊ{KúÌwMNúÏùPxÑùÒxSwÔxUõVt×wØúYxZwÛ\öÝÞxÞõ5ÀAöBõÃtDõÅóÆtGõHóÉrÊóKrÌõMtNõÏóPtÑõÒóSrÔóUtVó×rØóYrZÛõ\ÝqÞrÞr6ÀqArBóÃrDÅóÆqGóHÉrÊóKqÌrMtNõÏóPrÑtÒSóÔtUqVr×õØrYqZóÛt\óÝÞÞr·ÀóAtBÃóDrÅtÆõGHóÉÊKtÌMNÏõPóÑrÒSÔõUVt×õØtYõZÛt\ÝóÞtÞõ¸ÀtAóBtÃõDtÅÆõGHtÉóÊtKÌóMtNõÏPtÑÒrSÔUqVð×qØðYqZrÛ\ðÝrÞÞð9ÀqAoBÃðDqÅÆðGqHóÉqÊrKtÌxMwNÏtPwÑxÒõSöÔõUV×tØðYeZªxÛî\cÝ`ÞwÞ+è:ÀlAóBrÃqDóÅrÆqGHöÉúÊùKüÌùMxNÏúPxÑwÒöSxÔ~UúVx×ùØYxZ}Û\üÝùÞxÞú»ÀüAxBÃüD}ÅüÆùGúH}É{ÊüKùÌwMùN{ÏúPùÑ}Ò{SùÔ{UúVù×ØúYZùÛx\öÝõÞúÞx<ÀAõBùÃúDÅxÆwGHtÉöÊKÌwMNöÏPwÑöÒõSÔUwVx×wØöYwZÛõ\ÝÞùÞù½ÀwABöÃõDwÅxÆwGõHwÉxÊKwÌõMtNóÏwPùÑwÒSxÔUVõ×ØwYöZõÛx\ùÝÞxÞx¾ÀùAwBtÃöDùÅÆGúHÉùÊõKöÌúMNxÏwPöÑùÒ{SùÔxUùV×xØùYZwÛ\úÝxÞöÞù?ÀúAxBÃùDÅxÆwGHÉxÊùKúÌwMNúÏùPxÑùÒxSÔwUxVw×õØtYZrÛó\wÝxÞÞÞ–3ù DDÅÆGúHùÉÊúKÌùMúNÏPÑÒSÔUV×ØYZÛ\ÝùÞÞù!ÀABÃDÅÆGHÉÊKÌMxNÏùPxÑÒSÔUV×ØYZÛ\ÝÞÞx"ÀABÃDÅÆGHÉÊKÌMNÏPÑÒSÔUV×ØYZÛ\ÝÞÞx£ÀAùBÃúDÅ{ÆGHÉÊKÌúMùNxÏwPöÑõÒöSÔõUtV×õØöYwZùÛ\xÝÞÞx$ÀùABÃúDÅÆüGšÿH´cÉjÊwK5âÌèMiNcÏ´óP3üÑiÒ²ùSóÔùU3`Vè×oØtYwZxÛ\ÝÞÞx¥ÀùABxÃDÅùÆGHÉÊKÌMNÏPÑÒSÔUVú×ØùYúZÛ\ÝÞÞ{¦ÀúA{BÃDÅÆüGHÉÊK}ÌMüN}ÏPÑÒSÔUüV}×ØYZÛ\ÝüÞÞü'ÀABÃD{ÅÆGHÉÊKÌMNÏPÑÒSÔUV×ØYZÛ\üÝ{ÞÞ{(ÀABÃúDÅÆGHÉÊKùÌMúNùÏPÑÒSxÔUV×ØYZÛ\wÝÞxÞw©ÀABÃDÅÆGHÉÊKÌMöNwÏPÑöÒwSÔUöV×wØYZÛ\ÝöÞÞwªÀABÃDÅÆöGwHÉÊKxÌMùNÏúPÑùÒSÔxUwVö×õØtYZÛ\óÝÞrÞó+ÀtAõBöÃDÅÆõGöHÉwÊKöÌwMNùÏüPšÿÑ´eÒrS~Ô5äUçVc×´tØ3{YçZ²wÛð\óÝ{Þ3cÞj¬ÀîArBóÃtDÅÆGõHÉÊKÌMNÏPÑÒöSÔUV×ØõYZÛ\ÝÞÞõ-ÀAöBõÃDöÅõÆGHöÉÊKÌMNÏwPÑÒSÔxUV×ØYZÛ\ÝÞÞx.ÀABÃwDÅÆGHÉÊKÌöMNÏPÑÒSÔõUV×tØYõZÛ\ÝÞÞõ¯ÀAöBÃõDÅÆGHÉÊKÌMNÏtPÑóÒtSóÔUV×ØYZrÛó\ÝrÞqÞr0ÀABqÃDrÅÆqGrHÉqÊKÌMNrÏPÑÒSÔUVq×ØYZrÛ\ÝÞÞr±ÀAqBrÃDqÅrÆGqHÉÊKÌMrNóÏPÑtÒSÔóUtVó×ØrYqZðÛ\oÝîÞoÞî²ÀíAlBíÃoDðÅqÆrGqHðÉoÊðKÌqMðNqÏPÑóÒöSüÔ´áUlVx×5`ØcY´šÿZrÛ3{\èÝ²wÞíÞí3ÀtAüB3áÃçDëÅîÆoGîHoÉÊKÌMðNÏoPÑðÒSÔoUV×ØYðZÛo\ÝðÞÞð´ÀoABÃðDoÅÆGHÉÊðKÌMNÏPÑÒSqÔUV×ØYZÛ\ÝÞÞr5ÀAqBrÃDÅÆóGHÉrÊKÌMNÏPÑÒqSÔrUqV×ØYZÛ\ÝÞÞq6ÀArBÃqDÅÆGHÉrÊKqÌMNÏðPqÑÒðSÔUV×ØYZÛo\ÝÞðÞo·ÀABðÃoDÅÆGHÉÊKÌMNÏPÑÒðSÔoUVð×ØYoZÛ\ðÝoÞðÞð¸ÀABÃDÅÆGHqÉðÊKÌMNoÏðPÑqÒSÔrUV×ØYZÛq\ðÝoÞîÞî9ÀíAîBÃlDÅíÆîGoHqÉÊKðÌMqNÏPÑrÒSÔóUwV{×´`ØëYxZ5`Ûc\`Ý´tÞ3~Þj:À²ùAîBoÃöD}Å3cÆiGíHoÉðÊqKÌMNrÏPÑÒSóÔUrVó×ØYZÛ\ÝÞÞó»ÀABÃtDÅÆGHÉÊKõÌMNöÏPÑÒSÔwUV×ØxYZÛw\xÝÞÞx<ÀAùBÃxDùÅÆGHÉÊKÌMNÏPÑÒxSÔUV×ØwYxZÛw\ÝxÞÞx½ÀABÃDÅÆùGHÉxÊùKÌxMNÏPÑÒSÔwUV×ØYZÛ\ÝöÞÞö¾ÀABÃDÅÆGHÉÊKÌMNõÏPöÑÒõSÔUöVõ×ØYZÛ\ÝöÞõÞõ?ÀAöBÃõDÅÆGHÉÊKÌMNöÏPõÑÒSÔöUVw×ØYZÛ\ÝöÞÞÞ–¯x¦ÊŸÔÅKÔÒÏNÉØ Ô´00² GÒAPHÉÃ ÃÏMPUÔÅÒ ÔÅÒMÉNAÌ¯â¦ÊŸAND ´60± HAÒD ÃÏPY UNÉÔ.l¦ÊŸ              VAD GÒAPHÉÃ ÅDÉÔÏÒ-ö¦ÊŸŸ�
\ No newline at end of file
diff --git a/tek4010 b/tek4010
index 820ba7d..21ed4d7 100755
Binary files a/tek4010 and b/tek4010 differ
diff --git a/tek4010.c b/tek4010.c
old mode 100644
new mode 100755
index bedff76..f4d1c9d
--- a/tek4010.c
+++ b/tek4010.c
@@ -25,7 +25,7 @@
  */
  
 #define DEBUG 0                 // print debug info
-#define DEBUGMAX 100          // maximum number of bytes to process in debug mode
+#define DEBUGMAX 0              // exit after DEBUGMAX chars, 0 means no exit
 
 #define REFRESH_INTERVAL 30     // time in msec between refresh events
 
@@ -65,6 +65,10 @@ int isBrightSpot = 0;                   // set if there is currently a bright sp
 int count = 0;
 static int x0,y0,x2,y2,xh,xl,yh,yl,xy4014;
 
+enum LineType {SOLID,DOTTED,DOTDASH,SHORTDASH,LONGDASH};
+enum LineType ltype;
+double dashset[] = {2,6,2,2,6,3,3,3,6,6};
+
 static int plotPointMode = 0;           // plot point mode
 static int writeThroughMode = 0;        // write through mode
 static int debugCount = 0;
@@ -146,7 +150,7 @@ int isInput()
         ioctl(getDataPipe[0], FIONREAD, &bytesWaiting);
         if (DEBUG) {
                 debugCount++;
-                if (debugCount > DEBUGMAX) return 0;
+                if (DEBUGMAX && (debugCount > DEBUGMAX)) return 0;
         }
         if (bytesWaiting == 0) {
                 // reset the baud rate counter
@@ -340,7 +344,7 @@ void tek4010_init(int argc, char* argv[])
         setbuf(putKeys,0);
         
         mSeconds();             // initialize the timer
-        u100ResetSeconds(1);                
+        u100ResetSeconds(1);                        
 }
 
 int tek4010_on_timer_event()
@@ -425,6 +429,7 @@ void clearPersistent(cairo_t *cr, cairo_t *cr2)
         cairo_paint(cr2);
         isBrightSpot = 1;
         plotPointMode = 0;
+        ltype = SOLID;  
 }
 
 void clearSecond(cairo_t *cr2)
@@ -436,9 +441,40 @@ void clearSecond(cairo_t *cr2)
         cairo_set_operator(cr2, CAIRO_OPERATOR_OVER);
 }
 
+void tek4010_line_type(cairo_t *cr, cairo_t *cr2, enum LineType ln)
+{
+    int ndash,ndx;
+    double ofs = 0.5;
+
+    switch (ln) {
+    case SOLID:
+        ndx = 0;
+        ndash = 0;
+        break;
+    case DOTTED:
+        ndx = 0;
+        ndash = 2;
+        break;
+    case DOTDASH:
+        ndx = 2;
+        ndash = 4;
+        break;
+    case LONGDASH:
+        ndx = 8;
+        ndash = 2;
+        break;
+    case SHORTDASH:
+        ndx = 6;
+        ndash = 2;
+        break;
+    }
+    cairo_set_dash (cr,&dashset[ndx],ndash,ofs);
+    cairo_set_dash (cr2,&dashset[ndx],ndash,ofs);
+}
+
 void drawVector(cairo_t *cr, cairo_t *cr2,int x0,int y0,int x2,int y2)
 {
-        // printf("write-through-mode=%d\n", writeThroughMode);
+        if (DEBUG) printf("******************************************** Drawing to (%d,%d)\n",x2,y2);
         if (writeThroughMode) {
                 cairo_set_line_width (cr2, 1);
                 cairo_set_source_rgb(cr2, 0.0, 1.0, 0.0);
@@ -448,6 +484,7 @@ void drawVector(cairo_t *cr, cairo_t *cr2,int x0,int y0,int x2,int y2)
         }
         
         else {
+                tek4010_line_type(cr, cr2, ltype);
                 cairo_move_to(cr, x0, windowHeight - y0);
                 cairo_line_to(cr, x2, windowHeight - y2);
                 cairo_stroke (cr);
@@ -477,6 +514,66 @@ void drawVector(cairo_t *cr, cairo_t *cr2,int x0,int y0,int x2,int y2)
         isBrightSpot = 1; // also to be set if writeThroughMode
 }
 
+int escapeCodeHandler(cairo_t *cr, cairo_t *cr2, int todo, int ch)
+// handle escape sequencies
+// returns todo to allow changes to todo
+{
+        if (DEBUG) printf("Escape mode, ch=%02X\n",ch);
+        switch (ch) {
+                case 12:
+                        if (DEBUG) printf("Form feed, clear screen\n");
+                        clearPersistent(cr,cr2);
+                        mode = 0;
+                        break;
+                case '[':   
+                        // a second escape code follows, do not reset mode
+                        break;
+                                         
+                // start of ignoring ANSI escape sequencies, could be improved (but the Tek4010 couldn't do this either!)
+                case '0':
+                case '1':
+                case '2':
+                case '3':
+                case '4':
+                case '5':
+                case '6':
+                case '7':
+                case '8':
+                case '9':       break;
+                case ';':       mode = 31; break;
+                case ']':       break;
+                case 'm':       mode = 0; break;
+                
+                // end of ignoring ANSI escape sequencies
+
+                case '`': ltype = SOLID;    writeThroughMode = 0; mode = 0; break;
+                case 'a': ltype = DOTTED;   writeThroughMode = 0; mode = 0; break;
+                case 'b': ltype = DOTDASH;  writeThroughMode = 0; mode = 0; break;
+                case 'c': ltype = SHORTDASH;writeThroughMode = 0; mode = 0; break;
+                case 'd': ltype = LONGDASH; writeThroughMode = 0; mode = 0; break;
+                case 'e': ltype = SOLID;    writeThroughMode = 0; mode = 0; break;
+                case 'f': ltype = SOLID;    writeThroughMode = 0; mode = 0; break;
+                case 'h': ltype = SOLID;    writeThroughMode = 0; mode = 0; break; 
+                                    
+                // todo is set here to zero to achieve some synchronization with screen refresh cycle
+                case 'p': ltype = SOLID;    writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 'q': ltype = DOTTED;   writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 'r': ltype = DOTDASH;  writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 's': ltype = SHORTDASH;writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 't': ltype = LONGDASH; writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 'u': ltype = SOLID;    writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 'v': ltype = SOLID;    writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break;
+                case 'w': ltype = SOLID;    writeThroughMode = 1; mode = 101; showCursor = 0; todo = 0; break; 
+                        
+                default: 
+                        printf("Escape code %02X not implemented\n",ch);
+                        mode = 0;
+                        break;                                               
+        } 
+        return todo;   
+        
+}
+
 void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
 // draw onto the main window using cairo
 // width is the actual width of the main window
@@ -500,8 +597,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                 first = 0;
                 
                 if (windowWidth == 1024) efactor = 0.0;
-                else efactor = windowWidth / 1024.0;
-                
+                else efactor = windowWidth / 1024.0;              
         }
         
         long startPaintTime = mSeconds(); // start to measure time for this draw operation
@@ -534,6 +630,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
         }
         
         if (plotPointMode) todo = 4 * TODO;
+        else if (writeThroughMode) todo = 8 * todo;
         else todo = TODO;
         
         do {
@@ -557,6 +654,10 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                         if ((ch>='0') && (ch<='9')) mode = 30;
                 }
                 
+                if (ch == 27) {  // escape code
+                        mode = 30; return; 
+                }
+                
                 int tag = (ch >> 5) & 3;
                                 
                 if ((mode >= 1) && (mode <= 8)) {
@@ -623,7 +724,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                         }
                         else {
                                 if (ch == 29) mode = 1; // group separator
-                                else if (DEBUG) printf("Plot mode, unknown char %d, plotPointMode = %d\n",ch,plotPointMode);
+                                else printf("Plot mode, unknown char %d, plotPointMode = %d\n",ch,plotPointMode);
                                 return;
                         }
                                 
@@ -739,68 +840,18 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                                 mode = 5;
                                 
                                 break;
-                        case 30:                // handle escape sequencies
-                                if (DEBUG) printf("Escape mode, ch=%02X\n",ch);
-                                switch (ch) {
-                                    case 12:
-                                         if (DEBUG) printf("Form feed, clear screen\n");
-                                         clearPersistent(cr,cr2);
-                                         mode = 0;
-                                         break;
-                                    case '[': // a second escape code follows, do not reset mode
-                                         break;
-                                         
-// start of ignoring ANSI escape sequencies, could be improved (but the Tek4010 couldn't do this either!)
-                                    case '0':
-                                    case '1':
-                                    case '2':
-                                    case '3':
-                                    case '4':
-                                    case '5':
-                                    case '6':
-                                    case '7':
-                                    case '8':
-                                    case '9': break;
-                                    case ';': mode = 31; break;
-                                    case ']': break;
-                                    case 'm': mode = 0; break;
-// end of ignoring ANSI escape sequencies
-
-                                    case '`':
-                                    case 'a':
-                                    case 'b':
-                                    case 'c':
-                                    case 'd':
-                                    case 'e':
-                                    case 'f':
-                                    case 'h': writeThroughMode = 0;
-                                              if (DEBUG) printf("normal-mode activated\n");
-                                              break;
-                                    
-                                    case 'p':
-                                    case 'q':
-                                    case 'r':
-                                    case 's':
-                                    case 't':
-                                    case 'u':
-                                    case 'v':
-                                    case 'w': writeThroughMode = 1;
-                                              if (DEBUG) printf("write-through-mode activated\n");
-                                              mode = 101;  // ignore until group separator, not yet implemented
-                                              break;
-                                    default: 
-                                         if (DEBUG) printf("Escape code %d not implemented\n",ch);
-                                         mode = 0;
-                                         break;                                               
-                                }
-                                break;
+                        case 30: 
+                                todo = escapeCodeHandler(cr, cr2, todo, ch);
+                                break;               
                         case 40: // used to ignore certain 4014 sequencies
                                 if (ch == 31) mode = 0;  // leave this mode
                                 break;
-                        case 101: if (DEBUG) printf("Ignore until group separator, ch = %02x\n", ch);
+                        case 101: 
+                                if (DEBUG) printf("Ignore until group separator, ch = %02x\n", ch);
                                 if (ch == 29) mode = 1;
                                 break;
-                        default: switch (ch) {
+                        default: 
+                                switch (ch) {
                                 case 0:     break;
                                 case 7:     // bell function, delay 0.1 sec
                                             // cannot delay if bright spot is on, needs to be turned off first
@@ -824,7 +875,7 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                                             if (y0 < 4) {
                                                 y0 = windowHeight - vDotsPerChar;
                                                 if (leftmargin) leftmargin = 0;
-                                                else leftmargin = windowHeight / 2;
+                                                else leftmargin = windowWidth / 2;
                                             }
                                             if (!argRaw) x0 = leftmargin;
                                             break;
@@ -834,10 +885,10 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
                                 case 13:    // return
                                             mode = 0; x0 = leftmargin;
                                             break;
-                                case 27:    // escape
-                                            mode = 30;
-                                            // printf("Starting escape mode\n");
-                                            break;
+//                                case 27:    // escape
+//                                            mode = 30;
+//                                            // printf("Starting escape mode\n");
+//                                            break;
                                 case 28:    // file separator
                                             if (DEBUG) printf("Point plot mode\n");
                                             mode = 5;
