<commit_before>import * as fs from 'fs-extra'

export type ConsoleType = 'dmg' | 'sgb' | 'mgb' | 'mgl' | 'sgb2' | 'cgb' | 'agb' | 'ags' | 'gbs' | 'oxy'

export const consoles: ConsoleType[] = ['dmg', 'sgb', 'mgb', 'mgl', 'sgb2', 'cgb', 'agb', 'ags', 'gbs', 'oxy']

export interface ConsoleConfig {
  name: string
}

export const consoleCfgs: Record<ConsoleType, ConsoleConfig> = {
  dmg: { name: 'Game Boy' },
  sgb: { name: 'Super Game Boy' },
  mgb: { name: 'Game Boy Pocket' },
  mgl: { name: 'Game Boy Light' },
  sgb2: { name: 'Super Game Boy 2' },
  cgb: { name: 'Game Boy Color' },
  agb: { name: 'Game Boy Advance' },
  ags: { name: 'Game Boy Advance SP' },
  gbs: { name: 'Game Boy Player' },
  oxy: { name: 'Game Boy Micro' },
}

export interface CartLayout {
  chips: CartChip[]
}

export interface CartChip {
  designator: string
  name: string
  key:
    | 'rom'
    | 'mapper'
    | 'ram'
    | 'ram_protector'
    | 'u4'
    | 'u5'
    | 'line_decoder'
    | 'flash'
    | 'accelerometer'
    | 'eeprom'
    | 'rom2'
    | 'crystal'
}

export type CartLayoutId =
  | 'rom'
  | 'rom_mapper'
  | 'rom_mapper_ram'
  | 'rom_mapper_ram_xtal'
  | 'mbc2'
  | 'mbc6'
  | 'mbc7'
  | 'type_15'
  | 'huc3'
  | 'tama'

export const gameLayouts: Record<CartLayoutId, CartLayout> = {
  rom: {
    chips: [{ designator: 'U1', name: 'ROM', key: 'rom' }],
  },
  rom_mapper: {
    chips: [{ designator: 'U1', name: 'ROM', key: 'rom' }, { designator: 'U2', name: 'Mapper', key: 'mapper' }],
  },
  rom_mapper_ram: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  rom_mapper_ram_xtal: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'X1', name: 'Crystal', key: 'crystal' },
    ],
  },
  mbc2: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  mbc6: {
    chips: [
      { designator: 'U1', name: 'Mapper', key: 'mapper' },
      { designator: 'U2', name: 'ROM', key: 'rom' },
      { designator: 'U3', name: 'Flash', key: 'flash' },
      { designator: 'U4', name: 'RAM', key: 'ram' },
      { designator: 'U5', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  mbc7: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'EEPROM', key: 'eeprom' },
      { designator: 'U4', name: 'Accelerometer', key: 'accelerometer' },
    ],
  },
  type_15: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'U5', name: 'ROM 2', key: 'rom2' },
      { designator: 'U6', name: 'Line Decoder', key: 'line_decoder' },
    ],
  },
  huc3: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'U5', name: '????', key: 'u5' },
      { designator: 'X1', name: 'Crystal', key: 'crystal' },
    ],
  },
  tama: {<commit_msg>Identify HuC-3 hex inverter<commit_after>import * as fs from 'fs-extra'

export type ConsoleType = 'dmg' | 'sgb' | 'mgb' | 'mgl' | 'sgb2' | 'cgb' | 'agb' | 'ags' | 'gbs' | 'oxy'

export const consoles: ConsoleType[] = ['dmg', 'sgb', 'mgb', 'mgl', 'sgb2', 'cgb', 'agb', 'ags', 'gbs', 'oxy']

export interface ConsoleConfig {
  name: string
}

export const consoleCfgs: Record<ConsoleType, ConsoleConfig> = {
  dmg: { name: 'Game Boy' },
  sgb: { name: 'Super Game Boy' },
  mgb: { name: 'Game Boy Pocket' },
  mgl: { name: 'Game Boy Light' },
  sgb2: { name: 'Super Game Boy 2' },
  cgb: { name: 'Game Boy Color' },
  agb: { name: 'Game Boy Advance' },
  ags: { name: 'Game Boy Advance SP' },
  gbs: { name: 'Game Boy Player' },
  oxy: { name: 'Game Boy Micro' },
}

export interface CartLayout {
  chips: CartChip[]
}

export interface CartChip {
  designator: string
  name: string
  key:
    | 'rom'
    | 'mapper'
    | 'ram'
    | 'ram_protector'
    | 'u4'
    | 'u5'
    | 'line_decoder'
    | 'flash'
    | 'accelerometer'
    | 'eeprom'
    | 'rom2'
    | 'crystal'
}

export type CartLayoutId =
  | 'rom'
  | 'rom_mapper'
  | 'rom_mapper_ram'
  | 'rom_mapper_ram_xtal'
  | 'mbc2'
  | 'mbc6'
  | 'mbc7'
  | 'type_15'
  | 'huc3'
  | 'tama'

export const gameLayouts: Record<CartLayoutId, CartLayout> = {
  rom: {
    chips: [{ designator: 'U1', name: 'ROM', key: 'rom' }],
  },
  rom_mapper: {
    chips: [{ designator: 'U1', name: 'ROM', key: 'rom' }, { designator: 'U2', name: 'Mapper', key: 'mapper' }],
  },
  rom_mapper_ram: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  rom_mapper_ram_xtal: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'X1', name: 'Crystal', key: 'crystal' },
    ],
  },
  mbc2: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  mbc6: {
    chips: [
      { designator: 'U1', name: 'Mapper', key: 'mapper' },
      { designator: 'U2', name: 'ROM', key: 'rom' },
      { designator: 'U3', name: 'Flash', key: 'flash' },
      { designator: 'U4', name: 'RAM', key: 'ram' },
      { designator: 'U5', name: 'RAM protector', key: 'ram_protector' },
    ],
  },
  mbc7: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'EEPROM', key: 'eeprom' },
      { designator: 'U4', name: 'Accelerometer', key: 'accelerometer' },
    ],
  },
  type_15: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'U5', name: 'ROM 2', key: 'rom2' },
      { designator: 'U6', name: 'Line Decoder', key: 'line_decoder' },
    ],
  },
  huc3: {
    chips: [
      { designator: 'U1', name: 'ROM', key: 'rom' },
      { designator: 'U2', name: 'Mapper', key: 'mapper' },
      { designator: 'U3', name: 'RAM', key: 'ram' },
      { designator: 'U4', name: 'RAM protector', key: 'ram_protector' },
      { designator: 'U5', name: 'Hex inverter', key: 'u5' },
      { designator: 'X1', name: 'Crystal', key: 'crystal' },
    ],
  },
  tama: {
{'fraction_non_alphanumeric': 0.2154396186440678, 'fraction_numerical': 0.015492584745762712, 'mean_word_length': 2.937956204379562, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1819820', 'n_tokens_mistral': 3106, 'n_tokens_neox': 3046, 'n_words': 761}