Skip to content

Commit

Permalink
Use more nom parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Dec 6, 2024
1 parent 7ecf586 commit ae77168
Show file tree
Hide file tree
Showing 11 changed files with 686 additions and 361 deletions.
84 changes: 42 additions & 42 deletions model/src/config/cartridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use crate::{
parser::{
accelerometer::accelerometer,
crystal_32kihz::crystal_32kihz,
eeprom::eeprom,
eeprom::{eeprom_sop_8_3v3, eeprom_tssop_8_5v},
flash_tsop_i_32_3v3, flash_tsop_i_40_5v, fram_sop_28_3v3, hex_inverter, line_decoder,
mapper,
mask_rom::{
agb_mask_rom_tsop_ii_44, mask_rom_glop_top_28, mask_rom_qfp_44, mask_rom_sop_32,
mask_rom_sop_44_5v, mask_rom_tsop_i_32, mask_rom_tsop_ii_44_5v,
agb_mask_rom_tsop_ii_44_3v3, mask_rom_glop_top_28_5v, mask_rom_qfp_44_5v,
mask_rom_sop_32_5v, mask_rom_sop_44_5v, mask_rom_tsop_i_32_5v, mask_rom_tsop_ii_44_5v,
},
rtc_sop_20, rtc_sop_8,
sram::{sram_sop_28_3v3, sram_sop_28_5v, sram_sop_32_5v, sram_tsop_i_28},
Expand Down Expand Up @@ -179,33 +179,33 @@ impl BoardConfig {
match self {
BoardConfig::AgbArc => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-28 FRAM
D::U2 => part(PartRole::Ram, fram_sop_28_3v3()),
_ => None,
},
BoardConfig::AgbE01 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
_ => None,
},
BoardConfig::AgbE02 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// TSOP-I-32 Flash
D::U2 => part(PartRole::Flash, flash_tsop_i_32_3v3()),
_ => None,
},
BoardConfig::AgbE03 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-8 EEPROM
D::U2 => part(PartRole::Eeprom, eeprom()),
D::U2 => part(PartRole::Eeprom, eeprom_sop_8_3v3()),
_ => None,
},
BoardConfig::AgbE05 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// TSOP-I-32 Flash
D::U2 => part(PartRole::Flash, flash_tsop_i_32_3v3()),
// SOP-8 RTC
Expand All @@ -215,7 +215,7 @@ impl BoardConfig {
},
BoardConfig::AgbE06 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-28 RAM
D::U2 => part(PartRole::Ram, sram_sop_28_3v3()),
// SOP-8 BU9803F
Expand All @@ -224,7 +224,7 @@ impl BoardConfig {
},
BoardConfig::AgbE11 | BoardConfig::AgbY11 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-28 FRAM
D::U2 => part(PartRole::Ram, fram_sop_28_3v3()),
_ => None,
Expand All @@ -233,17 +233,17 @@ impl BoardConfig {
// QFP-32
D::U1 => part(PartRole::Unknown, unknown_chip()),
// TSOP-II-44 ROM
D::U2 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U2 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-8 EEPROM
D::U3 => part(PartRole::Eeprom, eeprom()),
D::U3 => part(PartRole::Eeprom, eeprom_sop_8_3v3()),
D::U4 => part(PartRole::Accelerometer, accelerometer()),
_ => None,
},
BoardConfig::AgbE18 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-8 EEPROM
D::U2 => part(PartRole::Eeprom, eeprom()),
D::U2 => part(PartRole::Eeprom, eeprom_sop_8_3v3()),
// SOP-8 RTC
D::U3 => part(PartRole::Rtc, rtc_sop_8()),
D::U4 => part(PartRole::Unknown, unknown_chip()),
Expand All @@ -253,9 +253,9 @@ impl BoardConfig {
},
BoardConfig::AgbE24 => match designator {
// TSOP-II-44 ROM
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()),
D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44_3v3()),
// SOP-8 EEPROM
D::U2 => part(PartRole::Eeprom, eeprom()),
D::U2 => part(PartRole::Eeprom, eeprom_sop_8_3v3()),
_ => None,
},
BoardConfig::Tama => match designator {
Expand All @@ -274,14 +274,14 @@ impl BoardConfig {
},
BoardConfig::Aaac => match designator {
// glop top ROM, 28 pads
D::U1 => part(PartRole::Rom, mask_rom_glop_top_28()),
D::U1 => part(PartRole::Rom, mask_rom_glop_top_28_5v()),
_ => None,
},
BoardConfig::CgbA32 => match designator {
// QFP-64 MBC6
D::U1 => part(PartRole::Mapper, mapper::mbc6_qfp64()),
// SOP-32 ROM
D::U2 => part(PartRole::Rom, mask_rom_sop_32()),
D::U2 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// TSOP-I-40 Flash
D::U3 => part(PartRole::Flash, flash_tsop_i_40_5v()),
// SOP-28 RAM
Expand All @@ -292,7 +292,7 @@ impl BoardConfig {
},
BoardConfig::DmgA02 => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
// SOP-28 RAM
Expand All @@ -314,7 +314,7 @@ impl BoardConfig {
},
BoardConfig::DmgA04 => match designator {
// TSOP-I-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32()),
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
// SOP-28 RAM
Expand All @@ -326,7 +326,7 @@ impl BoardConfig {
},
BoardConfig::DmgA06 => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
// SOP-28 RAM
Expand All @@ -337,7 +337,7 @@ impl BoardConfig {
},
BoardConfig::DmgA07 => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
_ => None,
Expand Down Expand Up @@ -389,7 +389,7 @@ impl BoardConfig {
},
BoardConfig::DmgA16 => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
// SOP-32 RAM
Expand All @@ -409,9 +409,9 @@ impl BoardConfig {
// QFP-56 MBC7
D::U1 => part(PartRole::Mapper, mapper::mbc7_qfp56()),
// SOP-32 ROM
D::U2 => part(PartRole::Rom, mask_rom_sop_32()),
D::U2 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// TSSOP-8 EEPROM
D::U3 => part(PartRole::Eeprom, eeprom()),
D::U3 => part(PartRole::Eeprom, eeprom_tssop_8_5v()),
// QC-14 accelerometer
D::U4 => part(PartRole::Accelerometer, accelerometer()),
_ => None,
Expand All @@ -422,35 +422,35 @@ impl BoardConfig {
// TSOP-II-44 ROM
D::U2 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()),
// TSSOP-8 EEPROM
D::U3 => part(PartRole::Eeprom, eeprom()),
D::U3 => part(PartRole::Eeprom, eeprom_tssop_8_5v()),
// QC-14 accelerometer
D::U4 => part(PartRole::Accelerometer, accelerometer()),
_ => None,
},
BoardConfig::DmgAaa => match designator {
// QFP-44 ROM
D::U1 => part(PartRole::Rom, mask_rom_qfp_44()),
// QFP-44 ROM, LH53259-compatible pinout
D::U1 => part(PartRole::Rom, mask_rom_qfp_44_5v()),
_ => None,
},
BoardConfig::DmgBba | BoardConfig::DmgBca => match designator {
// QFP-44 ROM
D::U1 => part(PartRole::Rom, mask_rom_qfp_44()),
D::U1 => part(PartRole::Rom, mask_rom_qfp_44_5v()),
// SOP-24 MBC1
D::U2 => part(PartRole::Mapper, mapper::mbc1_sop24()),
_ => None,
},
BoardConfig::DmgBean | BoardConfig::DmgBfan | BoardConfig::DmgMBfan => match designator
{
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// SOP-24 MBC1
D::U2 => part(PartRole::Mapper, mapper::mbc1_sop24()),
_ => None,
},
BoardConfig::DmgDecn | BoardConfig::DmgDedn | BoardConfig::DmgMcDfcn => {
match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// SOP-24 MBC1
D::U2 => part(PartRole::Mapper, mapper::mbc1_sop24()),
// SOP-28 RAM
Expand All @@ -473,7 +473,7 @@ impl BoardConfig {
},
BoardConfig::DmgGdan => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// SOP-28 MBC2
D::U2 => part(PartRole::Mapper, mapper::mbc2_sop28()),
// SOP-8 26A
Expand All @@ -482,7 +482,7 @@ impl BoardConfig {
},
BoardConfig::DmgKecn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC3
D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()),
// SOP-28 RAM
Expand All @@ -494,7 +494,7 @@ impl BoardConfig {
},
BoardConfig::DmgKfcn | BoardConfig::DmgKfdn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC3
D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()),
// SOP-28 RAM
Expand All @@ -518,7 +518,7 @@ impl BoardConfig {
},
BoardConfig::DmgLfdn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC3
D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()),
// SOP-28 RAM
Expand All @@ -529,7 +529,7 @@ impl BoardConfig {
},
BoardConfig::DmgMcSfcn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MMM01
D::U2 => part(PartRole::Mapper, mapper::mmm01_qfp32()),
// SOP-28 RAM
Expand All @@ -552,7 +552,7 @@ impl BoardConfig {
},
BoardConfig::DmgTedn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 HuC-1
D::U2 => part(PartRole::Mapper, mapper::huc1_qfp32()),
// SOP-28 RAM
Expand All @@ -564,7 +564,7 @@ impl BoardConfig {
},
BoardConfig::DmgTfdn => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 HuC-1
D::U2 => part(PartRole::Mapper, mapper::huc1_qfp32()),
// SOP-28 RAM
Expand All @@ -576,7 +576,7 @@ impl BoardConfig {
},
BoardConfig::DmgUedt => match designator {
// TSOP-I-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32()),
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32_5v()),
// QFP-48 HuC-3
D::U2 => part(PartRole::Mapper, mapper::huc3_qfp48()),
// TSOP-I-28 RAM
Expand All @@ -590,7 +590,7 @@ impl BoardConfig {
},
BoardConfig::DmgUfdt => match designator {
// TSOP-I-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32()),
D::U1 => part(PartRole::Rom, mask_rom_tsop_i_32_5v()),
// QFP-48 HuC-3
D::U2 => part(PartRole::Mapper, mapper::huc3_qfp48()),
// TSOP-I-28 RAM
Expand Down Expand Up @@ -618,7 +618,7 @@ impl BoardConfig {
},
BoardConfig::DmgZ02 => match designator {
// SOP-32 ROM
D::U1 => part(PartRole::Rom, mask_rom_sop_32()),
D::U1 => part(PartRole::Rom, mask_rom_sop_32_5v()),
// QFP-32 MBC5
D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()),
// SOP-28 RAM
Expand Down
1 change: 1 addition & 0 deletions model/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod oki;
pub mod oxy_u4;
pub mod oxy_u5;
pub mod rohm;
pub mod samsung;
pub mod sanyo;
pub mod seiko;
pub mod sgb_rom;
Expand Down
8 changes: 6 additions & 2 deletions model/src/parser/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub static LC56: NomParser<Eeprom> = NomParser {
},
};

pub fn eeprom() -> &'static impl LabelParser<Eeprom> {
multi_parser!(Eeprom, &LCS5, &LC56, &rohm::ROHM_9853, &rohm::ROHM_9854)
pub fn eeprom_sop_8_3v3() -> &'static impl LabelParser<Eeprom> {
multi_parser!(Eeprom, &rohm::ROHM_9853, &rohm::ROHM_9854)
}

pub fn eeprom_tssop_8_5v() -> &'static impl LabelParser<Eeprom> {
multi_parser!(Eeprom, &LCS5, &LC56)
}
2 changes: 1 addition & 1 deletion model/src/parser/fujitsu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub static FUJITSU_MASK_ROM: NomParser<MaskRom> = NomParser {
tag("JAPAN "),
alt((dmg_rom_code(), cgb_rom_code())),
char(' '),
uppers(1).and(digits(1)),
alt((tag("D1"), tag("E1"))), // D1 = 2Mbit, E1 = 4Mbit ?
char(' '),
digits(1).and(uppers(1)).and(alnum_uppers(1)),
char(' '),
Expand Down
Loading

0 comments on commit ae77168

Please sign in to comment.