This source file includes following definitions.
- trk
- trk_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <unistd.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <stdlib.h>
27
28 #include "dps8.h"
29 #include "tracker.h"
30
31 int brkbrk (int32_t arg, const char * buf);
32 #ifdef TESTING
33 void hdbgPrint (void);
34 #endif
35
36 static int fd;
37 static bool writing;
38 static bool tracking = false;
39
40 void trk (unsigned long long cycleCnt, uint16_t segno, uint32_t ic, uint64_t opcode)
41 {
42 if (! tracking)
43 return;
44 if (writing)
45 {
46 write (fd, & segno, sizeof (segno));
47 write (fd, & ic, sizeof (ic));
48 write (fd, & opcode, sizeof (opcode));
49 return;
50 }
51 uint16_t psegno;
52 uint32_t pic;
53 uint64_t popcode;
54 read (fd, & psegno, sizeof (segno));
55 read (fd, & pic, sizeof (ic));
56 read (fd, & popcode, sizeof (opcode));
57 if (segno != psegno ||
58 ic != pic ||
59 opcode != popcode)
60 {
61 fprintf (stderr, "\r\n[%llu]\r\n",
62 (unsigned long long int)cycleCnt);
63 fprintf (stderr, "expected: %05o:%06o %012llo\r\n", psegno, pic,
64 (unsigned long long int)popcode);
65 fprintf (stderr, "got: %05o:%06o %012llo\r\n", segno, ic,
66 (unsigned long long int)opcode);
67 #ifdef TESTING
68 hdbgPrint ();
69 #endif
70 brkbrk (0, "");
71 exit (1);
72 }
73 }
74
75 void trk_init (bool write)
76 {
77 if (write)
78 {
79 fd = open ("track.dat", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
80 }
81 else
82 {
83 fd = open ("track.dat", O_RDONLY, 0);
84 }
85 if (fd == -1)
86 {
87 perror ("trk_init");
88 exit (1);
89 }
90 writing = write;
91 tracking = true;
92 }