15#include "CoreObject.h"
20template <
int len>
class PETName : CoreObject {
33 static u8 petscii2printable(u8 c, u8 subst)
35 if (c >= 0x20 && c <= 0x7E)
return c;
39 static u8 ascii2pet(u8 asciichar)
41 if (asciichar == 0x00)
return 0x00;
43 asciichar = (u8)std::toupper(asciichar);
44 return asciichar >= 0x20 && asciichar <= 0x5D ? asciichar :
' ';
47 PETName(
const u8 *_pet, u8 _pad = 0xA0) : pad(_pad)
51 memset(pet, pad,
sizeof(pet));
52 memset(asc, 0x0,
sizeof(asc));
54 for (
int i = 0; i < len && _pet[i] != pad; i++) {
56 asc[i] = petscii2printable(_pet[i],
'_');
61 PETName(
const char *_str, u8 _pad = 0xA0) : pad(_pad)
65 memset(pet, pad,
sizeof(pet));
66 memset(asc, 0x0,
sizeof(asc));
68 for (
int i = 0; i < len && _str[i] != 0x00; i++) {
71 pet[i] = ascii2pet(_str[i]);
75 PETName(
string str) : PETName(str.c_str()) { }
77 void setPad(u8 _pad) {
79 for (
int i = 0; i < len; i++) {
80 if (pet[i] == pad) pet[i] = _pad;
85 const char *objectName()
const override {
return "PETName"; }
87 bool operator== (PETName &rhs)
91 while (pet[i] != pad || rhs.pet[i] != pad) {
92 if (pet[i] != rhs.pet[i])
return false;
98 PETName<len> stripped(u8 c)
100 PETName<len> name = *
this;
102 auto length = isize(strlen(name.asc));
103 for (isize i = length; i > 0 && name.asc[i - 1] == c; i--) {
106 name.pet[i - 1] = 0xA0;
112 void write(u8 *p, isize length)
115 assert(length <= len);
117 for (isize i = 0; i < length; i++) p[i] = pet[i];
120 void write(u8 *p) { write(p, len); }
122 const char *c_str() {
return asc; }
123 string str() {
return string(asc); }
VirtualC64 project namespace.
Definition CmdQueue.cpp:16