#commodore #c64 #cbm

bin+lib petscii

String library for Commodore PETSCII

3 unstable releases

0.2.1 Oct 13, 2023
0.2.0 Oct 13, 2023
0.1.0 Oct 13, 2023

#206 in Emulators

Custom license

33KB
603 lines

petscii

Support library for Commodore PETSCII strings.

Examples

Produce Unicode strings from raw data

let data = [b'A', b'B', b'C'];
let petscii = petscii::PetsciiString::from(&data);
assert_eq!("ABC", petscii.to_string());

Produce C64 binary correct sequences from strings

let petscii = petscii::PetsciiString::try_from("ANSWER IS 42").unwrap();

// truncate case:
let data_trunc: petscii::Result<[u8; 7]> = petscii.clone().try_into();
assert!(data_trunc.is_err());

// extended buffer case (beware of Commodore's NO_BREAK_SPACE filling):
let data_ext: [u8; 16] = petscii.clone().try_into().unwrap();
assert_eq!(
    format!("{}", petscii::PetsciiString::from(&data_ext)),
    "ANSWER IS 42\u{a0}\u{a0}\u{a0}\u{a0}"
);

Beware that the From<[u8]> implementation silently drops non-printables. If that is not what you want, use TryFrom:

let petscii = petscii::encode("Answer is 42");
assert_eq!(*petscii, [b'A', b' ', b' ', b'4', b'2']);
let fpetscii = petscii::try_encode("Answer is 42");
assert!(fpetscii.is_err());

Dependencies

~0.6–1.1MB
~24K SLoC