mirror of
https://github.com/markdavidlong/AppleSAWS.git
synced 2026-04-21 11:16:33 +00:00
Broke character set classes into their own files
This commit is contained in:
+4
-2
@@ -112,7 +112,8 @@ set(SOURCES
|
||||
src/ui/widgets/NotesDialog.cxx
|
||||
src/ui/widgets/StartupDialog.cxx
|
||||
src/util/AppleString.cxx
|
||||
src/util/CharSet.cxx
|
||||
src/util/CharacterSet.cxx
|
||||
src/util/CharSetCharacter.cxx
|
||||
src/util/OpCodes.cxx
|
||||
)
|
||||
|
||||
@@ -180,7 +181,8 @@ set(HEADERS
|
||||
src/ui/widgets/StartupDialog.h
|
||||
src/util/AppleColors.h
|
||||
src/util/AppleString.h
|
||||
src/util/CharSet.h
|
||||
src/util/CharacterSet.h
|
||||
src/util/CharSetCharacter.h
|
||||
src/util/OpCodes.h
|
||||
src/util/Util.h
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "CharSet.h"
|
||||
#include "CharacterSet.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "CharSet.h"
|
||||
#include "CharSetCharacter.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QColor>
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "CharSet.h"
|
||||
|
||||
|
||||
CharSetCharacter::CharSetCharacter(quint8 asciival, QByteArray bytes)
|
||||
{
|
||||
setAsciiVal(asciival);
|
||||
setData(bytes);
|
||||
}
|
||||
|
||||
void CharSetCharacter::setData(QByteArray bytes)
|
||||
{
|
||||
bytes.resize(8);
|
||||
m_data = bytes;
|
||||
}
|
||||
|
||||
void CharSetCharacter::setData(quint8 b0, quint8 b1,
|
||||
quint8 b2, quint8 b3,
|
||||
quint8 b4, quint8 b5,
|
||||
quint8 b6, quint8 b7)
|
||||
{
|
||||
QByteArray data;
|
||||
data.append(b0);
|
||||
data.append(b1);
|
||||
data.append(b2);
|
||||
data.append(b3);
|
||||
data.append(b4);
|
||||
data.append(b5);
|
||||
data.append(b6);
|
||||
data.append(b7);
|
||||
|
||||
setData(data);
|
||||
}
|
||||
|
||||
void CharacterSet::buildSetFromSetBlob(QByteArray data)
|
||||
{
|
||||
if (data.size() != 768) {
|
||||
qWarning("Unexpected character set size: %d (not 768). Resizing.",(qint32)data.size());
|
||||
data.resize(768);
|
||||
}
|
||||
int val = 32;
|
||||
for (int idx = 0; idx < 768; idx+=8)
|
||||
{
|
||||
QByteArray ch = data.mid(idx,8);
|
||||
|
||||
CharSetCharacter csc = CharSetCharacter(val,ch);
|
||||
m_charmap.insert(val,csc);
|
||||
val++;
|
||||
}
|
||||
}
|
||||
|
||||
QList<CharSetCharacter> CharacterSet::allCharacters() const
|
||||
{
|
||||
return m_charmap.values();
|
||||
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
class CharSetCharacter
|
||||
{
|
||||
public:
|
||||
CharSetCharacter(quint8 asciival = 0, QByteArray bytes = QByteArray());
|
||||
void setAsciiVal(quint8 val) { m_asciival = val; }
|
||||
quint8 asciiVal() const { return m_asciival; }
|
||||
|
||||
void setData(QByteArray bytes);
|
||||
void setData(quint8 b0 = 0, quint8 b1 = 0, quint8 b2 = 0, quint8 b3 = 0,
|
||||
quint8 b4 = 0, quint8 b5 = 0, quint8 b6 = 0, quint8 b7 = 0);
|
||||
QByteArray data() const { return m_data; }
|
||||
|
||||
private:
|
||||
quint8 m_asciival;
|
||||
QByteArray m_data;
|
||||
};
|
||||
|
||||
|
||||
class CharacterSet
|
||||
{
|
||||
public:
|
||||
void buildSetFromSetBlob(QByteArray data);
|
||||
CharSetCharacter operator[](int asciival) const { return m_charmap[asciival]; }
|
||||
QList<CharSetCharacter> allCharacters() const;
|
||||
bool contains(int asciival) { return m_charmap.keys().contains(asciival); }
|
||||
|
||||
private:
|
||||
QMap<int, CharSetCharacter> m_charmap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file CharSetCharacter.cxx
|
||||
* @brief Implementation of CharSetCharacter class
|
||||
*/
|
||||
|
||||
#include "CharSetCharacter.h"
|
||||
|
||||
CharSetCharacter::CharSetCharacter(quint8 asciival, QByteArray bytes) noexcept
|
||||
: m_asciival(asciival)
|
||||
{
|
||||
setData(bytes);
|
||||
}
|
||||
|
||||
void CharSetCharacter::setData(QByteArray bytes)
|
||||
{
|
||||
bytes.resize(8);
|
||||
m_data = bytes;
|
||||
}
|
||||
|
||||
void CharSetCharacter::setData(quint8 b0, quint8 b1,
|
||||
quint8 b2, quint8 b3,
|
||||
quint8 b4, quint8 b5,
|
||||
quint8 b6, quint8 b7)
|
||||
{
|
||||
QByteArray data;
|
||||
data.reserve(8);
|
||||
data.append(b0);
|
||||
data.append(b1);
|
||||
data.append(b2);
|
||||
data.append(b3);
|
||||
data.append(b4);
|
||||
data.append(b5);
|
||||
data.append(b6);
|
||||
data.append(b7);
|
||||
|
||||
setData(data);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file CharSetCharacter.h
|
||||
* @brief Individual character definition for Apple II character sets
|
||||
*
|
||||
* This file contains the CharSetCharacter class which represents a single
|
||||
* character in an Apple II character set with its ASCII value and bitmap data.
|
||||
*
|
||||
* @author AppleSAWS Development Team
|
||||
* @date 2024
|
||||
*/
|
||||
|
||||
#ifndef CHARSETCHARACTER_H
|
||||
#define CHARSETCHARACTER_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QtGlobal>
|
||||
|
||||
/**
|
||||
* @class CharSetCharacter
|
||||
* @brief Represents a single character in an Apple II character set
|
||||
*
|
||||
* Each CharSetCharacter contains an ASCII value and 8 bytes of bitmap data
|
||||
* that define how the character appears on screen. The bitmap data represents
|
||||
* an 8x8 pixel character where each byte defines one row of pixels.
|
||||
*/
|
||||
class CharSetCharacter final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct character with ASCII value and bitmap data
|
||||
* @param asciival ASCII value for this character (default: 0)
|
||||
* @param bytes Bitmap data for character display (default: empty)
|
||||
*/
|
||||
explicit CharSetCharacter(quint8 asciival = 0, QByteArray bytes = QByteArray()) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CharSetCharacter() = default;
|
||||
|
||||
// Rule of 5: Copy operations
|
||||
CharSetCharacter(const CharSetCharacter&) = default;
|
||||
CharSetCharacter& operator=(const CharSetCharacter&) = default;
|
||||
|
||||
// Rule of 5: Move operations
|
||||
CharSetCharacter(CharSetCharacter&&) noexcept = default;
|
||||
CharSetCharacter& operator=(CharSetCharacter&&) noexcept = default;
|
||||
|
||||
/**
|
||||
* @brief Set the ASCII value for this character
|
||||
* @param val ASCII value to set
|
||||
*/
|
||||
void setAsciiVal(quint8 val) noexcept { m_asciival = val; }
|
||||
|
||||
/**
|
||||
* @brief Get the ASCII value for this character
|
||||
* @return ASCII value of this character
|
||||
*/
|
||||
[[nodiscard]] quint8 asciiVal() const noexcept { return m_asciival; }
|
||||
|
||||
/**
|
||||
* @brief Set character bitmap data from byte array
|
||||
* @param bytes Bitmap data (will be resized to 8 bytes if needed)
|
||||
*/
|
||||
void setData(QByteArray bytes);
|
||||
|
||||
/**
|
||||
* @brief Set character bitmap data from individual bytes
|
||||
* @param b0 Row 0 bitmap data (default: 0)
|
||||
* @param b1 Row 1 bitmap data (default: 0)
|
||||
* @param b2 Row 2 bitmap data (default: 0)
|
||||
* @param b3 Row 3 bitmap data (default: 0)
|
||||
* @param b4 Row 4 bitmap data (default: 0)
|
||||
* @param b5 Row 5 bitmap data (default: 0)
|
||||
* @param b6 Row 6 bitmap data (default: 0)
|
||||
* @param b7 Row 7 bitmap data (default: 0)
|
||||
*/
|
||||
void setData(quint8 b0 = 0, quint8 b1 = 0, quint8 b2 = 0, quint8 b3 = 0,
|
||||
quint8 b4 = 0, quint8 b5 = 0, quint8 b6 = 0, quint8 b7 = 0);
|
||||
|
||||
/**
|
||||
* @brief Get the character bitmap data
|
||||
* @return 8-byte array containing character bitmap data
|
||||
*/
|
||||
[[nodiscard]] QByteArray data() const noexcept { return m_data; }
|
||||
|
||||
private:
|
||||
/// ASCII value for this character
|
||||
quint8 m_asciival{0};
|
||||
|
||||
/// 8-byte bitmap data defining character appearance
|
||||
QByteArray m_data;
|
||||
};
|
||||
|
||||
#endif // CHARSETCHARACTER_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file CharacterSet.cxx
|
||||
* @brief Implementation of CharacterSet class
|
||||
*/
|
||||
|
||||
#include "CharacterSet.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
void CharacterSet::buildSetFromSetBlob(QByteArray data)
|
||||
{
|
||||
constexpr int ExpectedSize = 768;
|
||||
constexpr int StartAscii = 32;
|
||||
constexpr int BytesPerChar = 8;
|
||||
|
||||
if (data.size() != ExpectedSize) {
|
||||
qWarning("Unexpected character set size: %d (not %d). Resizing.",
|
||||
static_cast<int>(data.size()), ExpectedSize);
|
||||
data.resize(ExpectedSize);
|
||||
}
|
||||
|
||||
int val = StartAscii;
|
||||
for (int idx = 0; idx < ExpectedSize; idx += BytesPerChar)
|
||||
{
|
||||
const QByteArray ch = data.mid(idx, BytesPerChar);
|
||||
const CharSetCharacter csc(static_cast<quint8>(val), ch);
|
||||
m_charmap.insert(val, csc);
|
||||
++val;
|
||||
}
|
||||
}
|
||||
|
||||
QList<CharSetCharacter> CharacterSet::allCharacters() const
|
||||
{
|
||||
return m_charmap.values();
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @file CharacterSet.h
|
||||
* @brief Character set handling for Apple II character display
|
||||
*
|
||||
* This file contains the CharacterSet class which manages collections of
|
||||
* CharSetCharacter objects for Apple II character set display.
|
||||
*
|
||||
* @author AppleSAWS Development Team
|
||||
* @date 2024
|
||||
*/
|
||||
|
||||
#ifndef CHARACTERSET_H
|
||||
#define CHARACTERSET_H
|
||||
|
||||
#include "CharSetCharacter.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
/**
|
||||
* @class CharacterSet
|
||||
* @brief Manages a collection of Apple II character set characters
|
||||
*
|
||||
* The CharacterSet class provides functionality to manage and access
|
||||
* character definitions for Apple II character sets, including building
|
||||
* character sets from binary data and providing access to individual
|
||||
* characters.
|
||||
*/
|
||||
class CharacterSet final
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
CharacterSet() = default;
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CharacterSet() = default;
|
||||
|
||||
// Rule of 5: Copy operations
|
||||
CharacterSet(const CharacterSet&) = default;
|
||||
CharacterSet& operator=(const CharacterSet&) = default;
|
||||
|
||||
// Rule of 5: Move operations
|
||||
CharacterSet(CharacterSet&&) noexcept = default;
|
||||
CharacterSet& operator=(CharacterSet&&) noexcept = default;
|
||||
|
||||
/**
|
||||
* @brief Build character set from binary data blob
|
||||
* @param data Binary data containing character definitions (expected size: 768 bytes)
|
||||
*
|
||||
* The data should contain 96 characters (ASCII 32-127) with 8 bytes per character.
|
||||
* If the data size is not 768 bytes, it will be resized and a warning issued.
|
||||
*/
|
||||
void buildSetFromSetBlob(QByteArray data);
|
||||
|
||||
/**
|
||||
* @brief Access character by ASCII value
|
||||
* @param asciival The ASCII value of the character
|
||||
* @return The CharSetCharacter for the given ASCII value
|
||||
*/
|
||||
[[nodiscard]] CharSetCharacter operator[](int asciival) const { return m_charmap[asciival]; }
|
||||
|
||||
/**
|
||||
* @brief Get all characters in the set
|
||||
* @return List of all CharSetCharacter objects in the set
|
||||
*/
|
||||
[[nodiscard]] QList<CharSetCharacter> allCharacters() const;
|
||||
|
||||
/**
|
||||
* @brief Check if character exists in the set
|
||||
* @param asciival The ASCII value to check
|
||||
* @return true if character exists, false otherwise
|
||||
*/
|
||||
[[nodiscard]] bool contains(int asciival) const noexcept { return m_charmap.contains(asciival); }
|
||||
|
||||
private:
|
||||
/// Map of ASCII values to character definitions
|
||||
QMap<int, CharSetCharacter> m_charmap;
|
||||
};
|
||||
|
||||
#endif // CHARACTERSET_H
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user