<commit_before>void runkernel();

int main() {
	runkernel();
}

int div(int a, int b) {
  int quot;
  int q;
  int c;
  quot = 0;
  while (a >= b) {
    c = b;
    q = 1;
    do {
      c <<= 1;
      q <<= 1;
    } while (c <= a && c < 8192);
    c >>= 1;
    q >>= 1;
    a -= c;
    quot += q;
  }
  return quot;
}

int mod(int a, int b) {
  int c;
  while (a >= b) {
    c = b;
    do {
      c <<= 1;
    } while (c <= a && c < 8192);
    c >>= 1;
    a -= c;
  }
  return a;
}

void printChar(char c) {
  interrupt(0x10, 0x0E00 + c, 0, 0, 0);
}

void printString(char *str) {
  int i;
  for (i = 0; str[i]; i++)
    printChar(str[i]);
}

void readSector(char *buffer, int sector) {
  interrupt(0x13, 0x0201, buffer, ((div(sector, 36) << 8) | mod(sector, 18)) + 1, (div(sector, 18) & 1) << 8);
}

int fileGetSector(char *buffer, int file, int *sector) {
  /* TODO: Make this not suck as much (currently it does two reads sometimes, which could theoretically be helped) */
  int indexFlags;
  char buf[512];
  int i;
  int index;
  readSector(buf, file);
  indexFlags = ((buf[0] & 0x80) >> 6) + ((buf[1] & 0x80) >> 7);
  if (indexFlags == 0) {
    /* Unindexed file */
    if (*sector)
      return 1; /* EOF */
    for (i = 0; i < 504; i++) {
      buffer[i] = buf[i+8];
    }
    for (; i < 512; i++)
      buffer[i] = 0;
  } else if (indexFlags == 1) {
    /* Singly indexed file */
    if (*sector < 0 || *sector >= 336)
      return 1; /* EOF */
    if ((*sector) & 1) {
      index = ((buf[9+3*(*sector >> 1)] & 0x0F) << 8) + buf[10+3*(*sector >> 1)];
    } else {
      index = (buf[8+3*(*sector >> 1)] << 4) + ((buf[9+3*(*sector >> 1)] & 0xF0) >> 4);
    }
    if (!index)
      return 1; /* EOF */
    readSector(buffer, index);
  } else {
    return 2; /* Unsupported indexing mode */
  }
  *sector++;
  return 0;
}

int handleInterrupt21() {
  /* Placeholder */
}

int handleTimerInterrupt() {
  /* Placeholder */
}

void runkernel() {
  char buf[512];
  int sec;
  int n;
  sec = 0;
  n = fileGetSector(buf, 17, &sec);
  printString(buf);
  while (1) continue;
}<commit_msg>Kernel now attempts to traverse the directory structure for the shell and ... do nothing with it<commit_after>void runkernel();

int main() {
	runkernel();
  while (1) continue;
}

int div(int a, int b) {
  int quot;
  int q;
  int c;
  quot = 0;
  while (a >= b) {
    c = b;
    q = 1;
    do {
      c <<= 1;
      q <<= 1;
    } while (c <= a && c < 8192);
    c >>= 1;
    q >>= 1;
    a -= c;
    quot += q;
  }
  return quot;
}

int mod(int a, int b) {
  int c;
  while (a >= b) {
    c = b;
    do {
      c <<= 1;
    } while (c <= a && c < 8192);
    c >>= 1;
    a -= c;
  }
  return a;
}

void printChar(char c) {
  interrupt(0x10, 0x0E00 + c, 0, 0, 0);
}

void printString(char *str) {
  int i;
  for (i = 0; str[i]; i++)
    printChar(str[i]);
}

void readSector(char *buffer, int sector) {
  interrupt(0x13, 0x0201, buffer, ((div(sector, 36) << 8) | mod(sector, 18)) + 1, (div(sector, 18) & 1) << 8);
}

int fileGetSector(char *buffer, int file, int *sector) {
  /* TODO: Make this not suck as much (currently it does two reads sometimes, which could theoretically be helped) */
  int indexFlags;
  char buf[512];
  int i;
  int index;
  readSector(buf, file);
  indexFlags = ((buf[0] & 0x80) >> 6) + ((buf[1] & 0x80) >> 7);
  if (indexFlags == 0) {
    /* Unindexed file */
    if (*sector)
      return 1; /* EOF */
    for (i = 0; i < 504; i++) {
      buffer[i] = buf[i+8];
    }
    for (; i < 512; i++)
      buffer[i] = 0;
  } else if (indexFlags == 1) {
    /* Singly indexed file */
    if (*sector < 0 || *sector >= 336)
      return 1; /* EOF */
    if ((*sector) & 1) {
      index = ((buf[9+3*(*sector >> 1)] & 0x0F) << 8) + buf[10+3*(*sector >> 1)];
    } else {
      index = (buf[8+3*(*sector >> 1)] << 4) + ((buf[9+3*(*sector >> 1)] & 0xF0) >> 4);
    }
    if (!index)
      return 1; /* EOF */
    readSector(buffer, index);
  } else {
    return 2; /* Unsupported indexing mode */
  }
  *sector++;
  return 0;
}

int getRoot() {
  return 16;
}

int findInDirectory(int directory, char *name) {
  /* TODO: Extend this to directories with index mode 1 */
  /* TODO: Actually check that it's a directory */
  char name2[8];
  char buf[512];
  char first[512];
  int i;
  int offset;
  int index;
  int sector;
  int found;
  sector = 0;
  for (i = 0; i < 8 && name[i]; i++)
    name2[i] = name[i];
  for (; i < 8; i++)
    name2[i] = '\0';
  fileGetSector(buf, directory, &sector);
  for (offset = 0; offset < 512; offset += 2) {
    index = (buf[offset+1] << 8) + buf[offset];
    if (!index)
      break;
    readSector(first, index);
    found = 1;
    for (i = 0; i < 8; i++) {
      if ((first[i] & 0x7F) != name2[i])
        found = 0;
    }
    if (found)
      return index;
  }
  return -1;
}

int handleInterrupt21() {
  /* Placeholder */
}

int handleTimerInterrupt() {
  /* Placeholder */
}

void runkernel() {
  int sec;
  sec = 16;
  sec = findInDirectory(sec, "bin");
  if (sec == -1) {
    printString("Error: no bin directory!");
    return;
  }
  sec = findInDirectory(sec, "wsh");
  if (sec == -1) {
    printString("Error: no shell executable!");
    return;
  }
  printString("TODO: Actually run the shell!");
}
{'fraction_non_alphanumeric': 0.1933764750666159, 'fraction_numerical': 0.04701180053292729, 'mean_word_length': 2.317550505050505, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, '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': '1704015', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2077, 'n_words': 628}