supergrafx_rust/cards.rs
1//! Which card images are SuperGrafx cards. **Not from the reference**: supergrafx-python is
2//! handed a card by its caller. A host that takes any HuCard image (a browser page) needs to
3//! know which machine to build, and a HuCard has no header that says.
4//!
5//! Five cards were sold for the SuperGrafx alone; they are named here by the SHA-1 of the image
6//! (without a copier header), the user's library as measured, nothing of the images themselves.
7//! Dumps of them carry the extension `.sgx`. The two PC Engine cards with extra SuperGrafx
8//! graphics (Darius Plus, Darius Alpha) are not listed: they are PC Engine cards, run on the
9//! plain board, and nothing here was measured on them.
10
11use pcengine_rust::cards::strip_copier_header;
12use sha1::{Digest, Sha1};
13
14/// (SHA-1 of the image, title) of the five SuperGrafx cards.
15pub const SUPERGRAFX_CARDS: [(&str, &str); 5] = [
16 (
17 "66873b0e0cc699aa75daf06a3f74c0508037e605",
18 "1941 - Counter Attack",
19 ),
20 ("d876248ee1b80ad11633fd4be8aa21a187b52193", "Aldynes"),
21 ("edc8f7d2233c92ebd309ac804527c461851a4b63", "Battle Ace"),
22 ("cab9e4a1a8b6da07cc2c5cc35949928199a417ee", "Daimakaimura"),
23 (
24 "5ed16565753c902e14da9a0c5361ef01fa74463b",
25 "Madou King Granzort",
26 ),
27];
28
29/// The title of the SuperGrafx card this image is, if it is one of the five.
30pub fn supergrafx_title(image: &[u8]) -> Option<&'static str> {
31 let digest: String = Sha1::digest(strip_copier_header(image))
32 .iter()
33 .map(|byte| format!("{byte:02x}"))
34 .collect();
35 SUPERGRAFX_CARDS
36 .iter()
37 .find(|(sha1, _)| *sha1 == digest)
38 .map(|(_, title)| *title)
39}
40
41/// Should a host build a SuperGrafx for this card? Yes for one of the five known images, and
42/// for a file the user names `.sgx` (another dump or a translation of one, a homebrew card).
43pub fn is_supergrafx_card(image: &[u8], file_name: Option<&str>) -> bool {
44 let named = file_name.is_some_and(|name| name.to_ascii_lowercase().ends_with(".sgx"));
45 named || supergrafx_title(image).is_some()
46}