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-2024 The DPS8M Development Team
  10  *
  11  * This software is made available under the terms of the ICU License.
  12  * See the LICENSE.md file at the top-level directory of this distribution.
  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 /* if defined(TESTING) */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 /* if defined(TESTING) */
  67         brkbrk (0, "");
  68         exit (1);
  69       }
  70   }
  71 
  72 void trk_init (bool write)
     /* [previous][next][first][last][top][bottom][index][help] */
  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   }

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