root/src/dps8/tracker.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. trk
  2. trk_init

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 0d484872-f630-11ec-b82e-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2013-2019 Charles Anthony
   9  * Copyright (c) 2021-2023 The DPS8M Development Team
  10  *
  11  * All rights reserved.
  12  *
  13  * This software is made available under the terms of the ICU
  14  * License, version 1.8.1 or later.  For more details, see the
  15  * LICENSE.md file at the top-level directory of this distribution.
  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 /* ifdef TESTING */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 /* ifdef TESTING */
  70         brkbrk (0, "");
  71         exit (1);
  72       }
  73   }
  74 
  75 void trk_init (bool write)
     /* [previous][next][first][last][top][bottom][index][help] */
  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   }

/* [previous][next][first][last][top][bottom][index][help] */