PageRenderTime 35ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/analyzer/deltaT.c

https://gitlab.com/fossht/irsim-9.7
C | 253 lines | 204 code | 36 blank | 13 comment | 33 complexity | 4fd91a0c83d31fa87b92a8bb87f34685 MD5 | raw file
  1. /*
  2. * *********************************************************************
  3. * * Copyright (C) 1988, 1990 Stanford University. *
  4. * * Permission to use, copy, modify, and distribute this *
  5. * * software and its documentation for any purpose and without *
  6. * * fee is hereby granted, provided that the above copyright *
  7. * * notice appear in all copies. Stanford University *
  8. * * makes no representations about the suitability of this *
  9. * * software for any purpose. It is provided "as is" without *
  10. * * express or implied warranty. Export of this software outside *
  11. * * of the United States of America may require an export license. *
  12. * *********************************************************************
  13. */
  14. #include "ana.h"
  15. #include "ana_glob.h"
  16. #include "graphics.h"
  17. private TimeType FindPreviousEdge( t, tm, edgeH )
  18. Trptr t;
  19. register TimeType tm;
  20. hptr *edgeH;
  21. {
  22. register hptr h;
  23. register int val;
  24. register TimeType edgeT;
  25. edgeT = tims.start;
  26. *edgeH = NULL;
  27. if( IsVector( t ) )
  28. {
  29. register int i;
  30. for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  31. {
  32. h = t->cache[i].wind;
  33. val = h->val;
  34. while( h->time <= tm )
  35. {
  36. if( val != h->val )
  37. {
  38. val = h->val;
  39. if( h->time > edgeT )
  40. edgeT = h->time;
  41. }
  42. NEXTH( h, h );
  43. }
  44. }
  45. }
  46. else
  47. {
  48. h = t->cache[0].wind;
  49. val = h->val;
  50. while( h->time <= tm )
  51. {
  52. if( val != h->val )
  53. {
  54. val = h->val;
  55. edgeT = h->time;
  56. *edgeH = h;
  57. }
  58. NEXTH( h, h );
  59. }
  60. }
  61. return( edgeT );
  62. }
  63. private TimeType FindNextEdge( t, tm, edgeH )
  64. Trptr t;
  65. register TimeType tm;
  66. hptr *edgeH;
  67. {
  68. register hptr h, p;
  69. register int val;
  70. register TimeType edgeT, endT;
  71. endT = edgeT = min( tims.end, tims.last );
  72. *edgeH = NULL;
  73. if( IsVector( t ) )
  74. {
  75. register int i;
  76. for( i = t->n.vec->nbits - 1; i >= 0; i-- )
  77. {
  78. p = h = t->cache[i].wind;
  79. while( h->time <= tm )
  80. {
  81. p = h;
  82. NEXTH( h, h );
  83. }
  84. val = p->val;
  85. while( h->time <= endT )
  86. {
  87. if( val != h->val )
  88. {
  89. if( h->time < edgeT )
  90. edgeT = h->time;
  91. break;
  92. }
  93. NEXTH( h, h );
  94. }
  95. }
  96. }
  97. else
  98. {
  99. p = h = t->cache[0].wind;
  100. while( h->time <= tm )
  101. {
  102. p = h;
  103. NEXTH( h, h );
  104. }
  105. val = p->val;
  106. while( h->time <= endT )
  107. {
  108. if( val != h->val )
  109. {
  110. edgeT = h->time;
  111. *edgeH = h;
  112. break;
  113. }
  114. NEXTH( h, h );
  115. }
  116. }
  117. return( edgeT );
  118. }
  119. private void WaitForRelease()
  120. {
  121. XEvent e;
  122. GrabMouse( window, ButtonPressMask | ButtonReleaseMask, None );
  123. do
  124. XNextEvent( display, &e );
  125. while( e.type != ButtonRelease );
  126. XUngrabPointer( display, CurrentTime );
  127. }
  128. private Trptr t1;
  129. private Coord x1;
  130. private TimeType time1;
  131. private void SetEdge2();
  132. private void Terminate( cancel )
  133. int cancel;
  134. {
  135. if( cancel )
  136. PRINT( "(canceled: click on a trace)" );
  137. SendEventTo( NULL );
  138. XDefineCursor( display, window, cursors.deflt );
  139. RestoreScroll();
  140. }
  141. private void SetEdge1( ev )
  142. XButtonEvent *ev;
  143. {
  144. TimeType tm;
  145. hptr h;
  146. if( ev == NULL )
  147. {
  148. Terminate( FALSE );
  149. return;
  150. }
  151. if( ev->type != ButtonPress )
  152. return;
  153. t1 = GetYTrace( ev->y );
  154. tm = XToTime( ev->x );
  155. if( t1 == NULL or tm < 0 )
  156. {
  157. Terminate( TRUE );
  158. return;
  159. }
  160. time1 = FindPreviousEdge( t1, tm, &h );
  161. x1 = TimeToX( time1 );
  162. PRINTF( "%.2f", d2ns( time1 ) );
  163. if( h != NULL )
  164. PRINTF( " [%.2f, %.2f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );
  165. FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.hilite );
  166. WaitForRelease();
  167. FillAREA( window, x1 - 1, t1->top, 3, t1->bot - t1->top + 1, gcs.unhilite);
  168. PRINT( " | t2 = " );
  169. XDefineCursor( display, window, cursors.right );
  170. SendEventTo( SetEdge2 );
  171. }
  172. private void SetEdge2( ev )
  173. XKeyEvent *ev;
  174. {
  175. TimeType time2, diff;
  176. Trptr t2;
  177. Coord x2, y1, y2;
  178. hptr h;
  179. if( ev == NULL )
  180. {
  181. Terminate( FALSE );
  182. return;
  183. }
  184. if( ev->type != ButtonPress )
  185. return;
  186. t2 = GetYTrace( ev->y );
  187. time2 = XToTime( ev->x );
  188. if( t2 == NULL or time2 < 0 )
  189. {
  190. Terminate( TRUE );
  191. return;
  192. }
  193. time2 = FindNextEdge( t2, time2, &h );
  194. x2 = TimeToX( time2 );
  195. if( time2 < time1 )
  196. diff = time1 - time2;
  197. else
  198. diff = time2 - time1;
  199. PRINTF( "%.2f", d2ns( time2 ) );
  200. if( h != NULL )
  201. PRINTF( " [%.2f, %.2f]", d2ns( h->t.r.delay ), d2ns( h->t.r.rtime ) );
  202. PRINTF( " | diff = %.2f", d2ns( diff ) );
  203. y1 = (t1->top + t1->bot) / 2;
  204. y2 = (t2->top + t2->bot) / 2;
  205. XDrawLine( display, window, gcs.hilite, x1, y1, x2, y2 );
  206. WaitForRelease();
  207. XDrawLine( display, window, gcs.unhilite, x1, y1, x2, y2 );
  208. Terminate( FALSE );
  209. }
  210. public void DeltaT( s )
  211. char *s; /* menu string => ignore it */
  212. {
  213. PRINT( "\nt1 = " );
  214. SendEventTo( SetEdge1 );
  215. XDefineCursor( display, window, cursors.left );
  216. DisableScroll();
  217. }