<commit_before>#include <stdio.h>
#include <strings.h>
#include <time.h>
#include <sys/time.h>

#include "fsd.h"
#include "diskstore.h"

/*
Header:
=======
Identifier: "FSD"  string literal 3 bytes
   Creator:        5 bytes; date of creation/author
     Title:        Character string (unlimited length; may contain any but null)
 Title_End: 0x00   byte literal 1 byte
    Num_Tr: xx     1 byte, number of tracks

For each track
==============
   track_num: 1 byte
     num_sec: 1 byte (00 == unformated)

    readable: 1 byte (00 == unreadable, ff ==readable) **ONLY IF FORMATTED**

   If readable:
     For each sector
     ===============
           Track_ID: 1 byte
        Head_number: 1 byte
          Sector_ID: 1 byte
      reported_size: 1 byte (2^{7+x}; 0 ==>128, 1 ==> 256, 2==>512, 3==>1024 etc)
          real_size: 1 byte (2^{7+x})
         error_code: 1 byte (0==No Error, &20==Deleted Data; &0E = Data CRC Error)
               data: <real_size> bytes
   Note that error_code matches the OSWORD &7F result byte

   If track unreadable:
           Track_ID: 1 byte
        Head_number: 1 byte
          Sector_ID: 1 byte
      reported_size: 1 byte

Decoding of the "creator" 5 byte field:
=======================================
   (byte1 byte2 byte3 byte4 byte5)

       Date_DD = (byte1 AND &F8)/8
       Date_MM = (byte3 AND &0F)
     Date_YYYY = (byte1 AND &07)*256+byte2
    Creator_ID = (byte3 AND &F0)/16
   Release_num = ((byte5 AND &C0)/64)*256 + byte4
*/

void fsd_write(FILE *fsdfile, const unsigned char tracks)
{
  unsigned char buffer[10];
  unsigned char curtrack, cursector;
  unsigned char numsectors;
  Disk_Sector *sec;

  struct tm tim;
  struct timeval tv;

  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, &tim);

  // Write the header
  fwrite("FSD", 1, 3, fsdfile);

  buffer[0]=(tim.tm_mday<<3)|(((tim.tm_year+1900)&0x700)>>8);
  buffer[1]=(tim.tm_year+1900)&0xff;
  buffer[2]=(FSD_CREATORID<<4)|((tim.tm_mon+1)&0x0f);
  buffer[3]=0;
  buffer[4]=0;
  fwrite(buffer, 1, 5, fsdfile);
<commit_msg>Added caveat that storage for year only goes up to 2047<commit_after>#include <stdio.h>
#include <strings.h>
#include <time.h>
#include <sys/time.h>

#include "fsd.h"
#include "diskstore.h"

/*
Header:
=======
Identifier: "FSD"  string literal 3 bytes
   Creator:        5 bytes; date of creation/author
     Title:        Character string (unlimited length; may contain any but null)
 Title_End: 0x00   byte literal 1 byte
    Num_Tr: xx     1 byte, number of tracks

For each track
==============
   track_num: 1 byte
     num_sec: 1 byte (00 == unformated)

    readable: 1 byte (00 == unreadable, ff ==readable) **ONLY IF FORMATTED**

   If readable:
     For each sector
     ===============
           Track_ID: 1 byte
        Head_number: 1 byte
          Sector_ID: 1 byte
      reported_size: 1 byte (2^{7+x}; 0 ==>128, 1 ==> 256, 2==>512, 3==>1024 etc)
          real_size: 1 byte (2^{7+x})
         error_code: 1 byte (0==No Error, &20==Deleted Data; &0E = Data CRC Error)
               data: <real_size> bytes
   Note that error_code matches the OSWORD &7F result byte

   If track unreadable:
           Track_ID: 1 byte
        Head_number: 1 byte
          Sector_ID: 1 byte
      reported_size: 1 byte

Decoding of the "creator" 5 byte field:
=======================================
   (byte1 byte2 byte3 byte4 byte5)

       Date_DD = (byte1 AND &F8)/8
       Date_MM = (byte3 AND &0F)
     Date_YYYY = (byte1 AND &07)*256+byte2 ** ONLY SUPPORTS YEARS UP TO 2047 **
    Creator_ID = (byte3 AND &F0)/16
   Release_num = ((byte5 AND &C0)/64)*256 + byte4
*/

void fsd_write(FILE *fsdfile, const unsigned char tracks)
{
  unsigned char buffer[10];
  unsigned char curtrack, cursector;
  unsigned char numsectors;
  Disk_Sector *sec;

  struct tm tim;
  struct timeval tv;

  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, &tim);

  // Write the header
  fwrite("FSD", 1, 3, fsdfile);

  buffer[0]=(tim.tm_mday<<3)|(((tim.tm_year+1900)&0x700)>>8);
  buffer[1]=(tim.tm_year+1900)&0xff;
  buffer[2]=(FSD_CREATORID<<4)|((tim.tm_mon+1)&0x0f);
  buffer[3]=0;
  buffer[4]=0;
  fwrite(buffer, 1, 5, fsdfile);

{'fraction_non_alphanumeric': 0.1572493387833614, 'fraction_numerical': 0.05578264005770618, 'mean_word_length': 3.122893954410307, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5027794', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1473, 'n_words': 444}