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