id
int64
0
755k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
65
repo_stars
int64
100
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
9 values
repo_extraction_date
stringclasses
92 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
753,634
constexp.h
copperspice_doxypress/src/constexp.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef CONSTEXP_H #define CONSTEXP_H #include <cppvalue.h> #include <QString> extern bool parseconstexp(const QString &fileName, int line, const QString &s); extern int constexpYYparse(); extern int constexpYYdebug; extern QString g_strToken; extern CPPValue g_resultValue; extern QString g_constExpFileName; extern int g_constExpLineNr; #endif
1,132
C++
.h
29
37.862069
79
0.696721
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,640
reflist.h
copperspice_doxypress/src/reflist.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef REFLIST_H #define REFLIST_H #include <sortedlist.h> #include <QHash> #include <QList> class Definition; // struct represents an item in the list of references. struct RefItem { RefItem() : scope(nullptr) { } bool operator==(const RefItem &other) const { return (text == other.text && listAnchor == other.listAnchor && prefix == other.prefix && name == other.name && title == other.title && args == other.args && scope == other.scope); } QString text; //!< text of the item. QString listAnchor; //!< anchor in the list QString prefix; //!< type prefix for the name QString name; //!< name of the entity containing the reference QString title; //!< display name of the entity QString args; //!< optional arguments for the entity (if function) QSharedPointer<Definition> scope; // scope to use for references }; /** List of cross-referenced items * * This class represents a list of items that are put * at a certain point in the documentation by some special command * and are collected in a list. The items cross-reference the * documentation and the list. * * Examples are the todo list, the test list and the bug list, * introduced by the \\todo, \\test, and \\bug commands respectively. */ class RefList { public: RefList() : m_dictIterator(m_dict) {} RefList(const QString &listName, const QString &pageTitle, const QString &secTitle); int addRefItem(); RefItem *getRefItem(int todoItemId); RefItem *getFirstRefItem(); RefItem *getNextRefItem(); QString listName() const; QString fileName() const; QString pageTitle() const; QString sectionTitle() const; void insertIntoList(const QString &key, RefItem *item); bool isEnabled() const; void generatePage(); private: int m_id; QString m_listName; QString m_fileName; QString m_pageTitle; QString m_secTitle; QMap<QString, QList<RefItem>> m_itemMap; QHash<long, RefItem *> m_dict; QHashIterator<long, RefItem *> m_dictIterator; }; #endif
2,899
C++
.h
79
33.620253
104
0.674768
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,644
perlmodgen.h
copperspice_doxypress/src/perlmodgen.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef PERLMODGEN_H #define PERLMODGEN_H #include <QString> extern void setPerlModDoxyfile(const QString &); extern void generatePerl_output(); #endif
930
C++
.h
23
39.26087
74
0.673311
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,653
conceptdef.h
copperspice_doxypress/src/conceptdef.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef CONCEPTDEF_H #define CONCEPTDEF_H #include <arguments.h> #include <definition.h> #include <filedef.h> class OutputList; class ConceptDef : public Definition { public: ConceptDef(const QString &defFileName, int defLine, int defColumn, const QString &fullName, const QString &tag = QString(), const QString &tagFileName = QString()); ~ConceptDef(); QString anchor() const override { return QString(); } QString conceptDecl() const; const ArgumentList &getTemplateArgumentList() const; DefType definitionType() const override { return TypeConcept; } QSharedPointer<FileDef> getFileDef() const { return m_fileDef; } const IncludeInfo &getIncludeInfo() const { return m_incInfo; } const QString &getInitializer() const { return m_initializer; } QString getOutputFileBase() const override; bool isLinkable() const override { return isLinkableInProject() || isReference(); } bool isLinkableInProject() const override { return ! isReference(); } void setFileDef(QSharedPointer<FileDef> fd) { m_fileDef = fd; } void setMemberGroupId(int id) { m_groupId = id; } void setInitializer(const QString &str) { m_initializer = str; } void setTemplateArgumentList(const ArgumentList &al); QString title() const { return m_title; } void setIncludeFile(QSharedPointer<FileDef> fd, const QString &incName, bool local, bool force); void writeDeclarationLink(OutputList &ol, bool &found, const QString &header, bool localNames); void writeMoreLink(OutputList &ol, const QString &anchor); /* void setLocalToc(const LocalToc &tl); LocalToc localToc() const { return m_localToc; } void writeTagFile(QTextStream &); */ QString displayName(bool = true) const override { return ! m_title.isEmpty() ? m_title : Definition::name(); } void writeDocumentation(OutputList &ol); void writeTagFile(QTextStream &tagFile); void findSectionsInDocumentation(); bool hasDetailedDescription() const; private: void writeBriefDescription(OutputList &ol); void writeAuthorSection(OutputList &ol); void writeIncludeFiles(OutputList &ol); void writeDetailedDescription(OutputList &ol, const QString &title, const QString &anchor); void writeDetailedDocumentationBody(OutputList &ol); QString m_fileName; QString m_title; QString m_initializer; int m_groupId; // Template arguments for this concept ArgumentList m_templateArgs; QSharedPointer<FileDef> m_fileDef; // Include information about the header file IncludeInfo m_incInfo; // LocalToc m_localToc; }; #endif
3,683
C++
.h
101
30.673267
102
0.6708
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,654
htmldocvisitor.h
copperspice_doxypress/src/htmldocvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef HTMLDOCVISITOR_H #define HTMLDOCVISITOR_H #include <docvisitor.h> #include <QStack> #include <QTextStream> class CodeGenerator; class Definition; class DocNode; class MemberDef; /*! @brief Concrete visitor implementation for HTML output. */ class HtmlDocVisitor : public DocVisitor { public: HtmlDocVisitor(QTextStream &t, CodeGenerator &ci, QSharedPointer<Definition> ctx); // visitor functions for leaf nodes void visit(DocWord *) override; void visit(DocLinkedWord *) override; void visit(DocWhiteSpace *) override; void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *) override; void visit(DocLineBreak *) override; void visit(DocHorRuler *) override; void visit(DocStyleChange *) override; void visit(DocVerbatim *) override; void visit(DocAnchor *) override; void visit(DocInclude *) override; void visit(DocIncOperator *) override; void visit(DocFormula *) override; void visit(DocIndexEntry *) override; void visit(DocSimpleSectSep *) override; void visit(DocCite *) override; // visitor functions for compound nodes void visitPre(DocAutoList *) override; void visitPost(DocAutoList *) override; void visitPre(DocAutoListItem *) override; void visitPost(DocAutoListItem *) override; void visitPre(DocPara *) override; void visitPost(DocPara *) override; void visitPre(DocRoot *) override; void visitPost(DocRoot *) override; void visitPre(DocSimpleSect *) override; void visitPost(DocSimpleSect *) override; void visitPre(DocTitle *) override; void visitPost(DocTitle *) override; void visitPre(DocSimpleList *) override; void visitPost(DocSimpleList *) override; void visitPre(DocSimpleListItem *) override; void visitPost(DocSimpleListItem *) override; void visitPre(DocSection *) override; void visitPost(DocSection *) override; void visitPre(DocHtmlList *) override; void visitPost(DocHtmlList *) override; void visitPre(DocHtmlListItem *) override; void visitPost(DocHtmlListItem *) override; void visitPre(DocHtmlDescList *) override; void visitPost(DocHtmlDescList *) override; void visitPre(DocHtmlDescTitle *) override; void visitPost(DocHtmlDescTitle *) override; void visitPre(DocHtmlDescData *) override; void visitPost(DocHtmlDescData *) override; void visitPre(DocHtmlTable *) override; void visitPost(DocHtmlTable *) override; void visitPre(DocHtmlRow *) override; void visitPost(DocHtmlRow *) override; void visitPre(DocHtmlCell *) override; void visitPost(DocHtmlCell *) override; void visitPre(DocHtmlCaption *) override; void visitPost(DocHtmlCaption *) override; void visitPre(DocInternal *) override; void visitPost(DocInternal *) override; void visitPre(DocHRef *) override; void visitPost(DocHRef *) override; void visitPre(DocHtmlHeader *) override; void visitPost(DocHtmlHeader *) override; void visitPre(DocImage *) override; void visitPost(DocImage *) override; void visitPre(DocDotFile *) override; void visitPost(DocDotFile *) override; void visitPre(DocMscFile *) override; void visitPost(DocMscFile *) override; void visitPre(DocDiaFile *) override; void visitPost(DocDiaFile *) override; void visitPre(DocLink *) override; void visitPost(DocLink *) override; void visitPre(DocRef *) override; void visitPost(DocRef *) override; void visitPre(DocSecRefItem *) override; void visitPost(DocSecRefItem *) override; void visitPre(DocSecRefList *) override; void visitPost(DocSecRefList *) override; void visitPre(DocParamSect *) override; void visitPost(DocParamSect *) override; void visitPre(DocParamList *) override; void visitPost(DocParamList *) override; void visitPre(DocXRefItem *) override; void visitPost(DocXRefItem *) override; void visitPre(DocInternalRef *) override; void visitPost(DocInternalRef *) override; void visitPre(DocCopy *) override; void visitPost(DocCopy *) override; void visitPre(DocText *) override; void visitPost(DocText *) override; void visitPre(DocHtmlBlockQuote *) override; void visitPost(DocHtmlBlockQuote *) override; void visitPre(DocParBlock *) override; void visitPost(DocParBlock *) override; private: void filter(const QString &str); void filterQuotedCdataAttr(const QString &str); void startLink(const QString &ref, const QString &file, const QString &relPath, const QString &anchor, const QString &tooltip = QString()); void endLink(); void writeDotFile(const QString &fileName, const QString &relPath, const QString &context); void writeMscFile(const QString &fileName, const QString &relPath, const QString &context); void writeDiaFile(const QString &fileName, const QString &relPath, const QString &context); void writePlantUMLFile(const QString &fileName, const QString &relPath, const QString &context); void pushEnabled(); void popEnabled(); void forceEndParagraph(DocNode *n); void forceStartParagraph(DocNode *n); QTextStream &m_t; CodeGenerator &m_ci; bool m_insidePre; bool m_hide; QStack<bool> m_enabled; QSharedPointer<Definition> m_ctx; QString m_langExt; }; #endif
6,058
C++
.h
147
37.632653
105
0.743168
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,655
emoji_entity.h
copperspice_doxypress/src/emoji_entity.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef EMOJI_ENTITY_H #define EMOJI_ENTITY_H #include <QHash> #include <QFile> #include <QTextStream> class EmojiEntityMapper { public: static EmojiEntityMapper *instance(); static void deleteInstance(); QString name(int index) const; QString unicode(int index) const; void writeEmojiFile(QFile &file); int symbol2index(const QString &symName) const; private: EmojiEntityMapper(); ~EmojiEntityMapper(); static EmojiEntityMapper *s_instance; QHash<QString, int> m_name2sym; }; #endif
1,314
C++
.h
38
32.263158
74
0.683215
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,662
rtfdocvisitor.h
copperspice_doxypress/src/rtfdocvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef RTFDOCVISITOR_H #define RTFDOCVISITOR_H #include <docvisitor.h> #include <QStack> #include <QTextStream> class CodeGenerator; /*! @brief Concrete visitor implementation for RTF output. */ class RTFDocVisitor : public DocVisitor { public: RTFDocVisitor(QTextStream &t, CodeGenerator &ci, const QString &langExt); // visitor functions for leaf nodes void visit(DocWord *) override; void visit(DocLinkedWord *) override; void visit(DocWhiteSpace *) override; void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *) override; void visit(DocLineBreak *) override; void visit(DocHorRuler *) override; void visit(DocStyleChange *) override; void visit(DocVerbatim *) override; void visit(DocAnchor *) override; void visit(DocInclude *) override; void visit(DocIncOperator *) override; void visit(DocFormula *) override; void visit(DocIndexEntry *) override; void visit(DocSimpleSectSep *) override; void visit(DocCite *) override; // visitor functions for compound nodes void visitPre(DocAutoList *) override; void visitPost(DocAutoList *) override; void visitPre(DocAutoListItem *) override; void visitPost(DocAutoListItem *) override; void visitPre(DocPara *) override; void visitPost(DocPara *) override; void visitPre(DocRoot *) override; void visitPost(DocRoot *) override; void visitPre(DocSimpleSect *) override; void visitPost(DocSimpleSect *) override; void visitPre(DocTitle *) override; void visitPost(DocTitle *) override; void visitPre(DocSimpleList *) override; void visitPost(DocSimpleList *) override; void visitPre(DocSimpleListItem *) override; void visitPost(DocSimpleListItem *) override; void visitPre(DocSection *s) override; void visitPost(DocSection *) override; void visitPre(DocHtmlList *s) override; void visitPost(DocHtmlList *s) override; void visitPre(DocHtmlListItem *) override; void visitPost(DocHtmlListItem *) override; //void visitPre(DocHtmlPre *); //void visitPost(DocHtmlPre *); void visitPre(DocHtmlDescList *) override; void visitPost(DocHtmlDescList *) override; void visitPre(DocHtmlDescTitle *) override; void visitPost(DocHtmlDescTitle *) override; void visitPre(DocHtmlDescData *) override; void visitPost(DocHtmlDescData *) override; void visitPre(DocHtmlTable *t) override; void visitPost(DocHtmlTable *t) override; void visitPre(DocHtmlCaption *) override; void visitPost(DocHtmlCaption *) override; void visitPre(DocHtmlRow *) override; void visitPost(DocHtmlRow *) override; void visitPre(DocHtmlCell *) override; void visitPost(DocHtmlCell *) override; void visitPre(DocInternal *) override; void visitPost(DocInternal *) override; void visitPre(DocHRef *) override; void visitPost(DocHRef *) override; void visitPre(DocHtmlHeader *) override; void visitPost(DocHtmlHeader *) override; void visitPre(DocImage *) override; void visitPost(DocImage *) override; void visitPre(DocDotFile *) override; void visitPost(DocDotFile *) override; void visitPre(DocMscFile *) override; void visitPost(DocMscFile *) override; void visitPre(DocDiaFile *) override; void visitPost(DocDiaFile *) override; void visitPre(DocLink *) override; void visitPost(DocLink *) override; void visitPre(DocRef *ref) override; void visitPost(DocRef *) override; void visitPre(DocSecRefItem *) override; void visitPost(DocSecRefItem *) override; void visitPre(DocSecRefList *) override; void visitPost(DocSecRefList *) override; void visitPre(DocParamSect *) override; void visitPost(DocParamSect *) override; void visitPre(DocParamList *) override; void visitPost(DocParamList *) override; void visitPre(DocXRefItem *) override; void visitPost(DocXRefItem *) override; void visitPre(DocInternalRef *) override; void visitPost(DocInternalRef *) override; void visitPre(DocCopy *) override; void visitPost(DocCopy *) override; void visitPre(DocText *) override; void visitPost(DocText *) override; void visitPre(DocHtmlBlockQuote *) override; void visitPost(DocHtmlBlockQuote *) override; void visitPre(DocParBlock *) override; void visitPost(DocParBlock *) override; private: void filter(const QString &str, bool verbatim = false); void startLink(const QString &ref, const QString &file, const QString &anchor); void endLink(const QString &ref); QString getStyle(const QString &name); void incIndentLevel(); void decIndentLevel(); void pushEnabled(); void popEnabled(); void includePicturePreRTF(const QString &name, const bool isTypeRTF, const bool hasCaption, bool inlineImage = false); void includePicturePostRTF(const bool isTypeRTF, const bool hasCaption, bool inlineImage = false); void writeDotFile(const QString &fileName, const bool hasCaption); void writeDotFile(DocDotFile *); void writeMscFile(const QString &fileName, const bool hasCaption); void writeMscFile(DocMscFile *); void writeDiaFile(DocDiaFile *); void writePlantUMLFile(const QString &fileName, const bool hasCaption); QTextStream &m_t; CodeGenerator &m_ci; bool m_insidePre; bool m_hide; int m_indentLevel; QStack<bool> m_enabled; bool m_lastIsPara; QString m_langExt; }; #endif
6,166
C++
.h
150
37.573333
121
0.743414
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,665
docbookvisitor.h
copperspice_doxypress/src/docbookvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef DOCBOOKVISITOR_H #define DOCBOOKVISITOR_H #include <docparser.h> #include <docvisitor.h> #include <QStack> #include <QTextStream> class CodeGenerator; /*! @brief Concrete visitor implementation for Docbook output. */ class DocbookDocVisitor : public DocVisitor { public: DocbookDocVisitor(QTextStream &t, CodeGenerator &ci); ~DocbookDocVisitor(); void visit(DocWord *) override; void visit(DocLinkedWord *) override; void visit(DocWhiteSpace *) override; void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *) override; void visit(DocLineBreak *) override; void visit(DocHorRuler *) override; void visit(DocStyleChange *) override; void visit(DocVerbatim *) override; void visit(DocAnchor *) override; void visit(DocInclude *) override; void visit(DocIncOperator *) override; void visit(DocFormula *) override; void visit(DocIndexEntry *) override; void visit(DocSimpleSectSep *) override; void visit(DocCite *) override; // visitor functions for compound nodes void visitPre(DocAutoList *) override; void visitPost(DocAutoList *) override; void visitPre(DocAutoListItem *) override; void visitPost(DocAutoListItem *) override; void visitPre(DocPara *) override; void visitPost(DocPara *) override; void visitPre(DocRoot *) override; void visitPost(DocRoot *) override; void visitPre(DocSimpleSect *) override; void visitPost(DocSimpleSect *) override; void visitPre(DocTitle *) override; void visitPost(DocTitle *) override; void visitPre(DocSimpleList *) override; void visitPost(DocSimpleList *) override; void visitPre(DocSimpleListItem *) override; void visitPost(DocSimpleListItem *) override; void visitPre(DocSection *) override; void visitPost(DocSection *) override; void visitPre(DocHtmlList *) override; void visitPost(DocHtmlList *) override; void visitPre(DocHtmlListItem *) override; void visitPost(DocHtmlListItem *) override; //void visitPre(DocHtmlPre *) ; //void visitPost(DocHtmlPre *); void visitPre(DocHtmlDescList *) override; void visitPost(DocHtmlDescList *) override; void visitPre(DocHtmlDescTitle *) override; void visitPost(DocHtmlDescTitle *) override; void visitPre(DocHtmlDescData *) override; void visitPost(DocHtmlDescData *) override; void visitPre(DocHtmlTable *) override; void visitPost(DocHtmlTable *) override; void visitPre(DocHtmlRow *) override; void visitPost(DocHtmlRow *) override; void visitPre(DocHtmlCell *) override; void visitPost(DocHtmlCell *) override; void visitPre(DocHtmlCaption *) override; void visitPost(DocHtmlCaption *) override; void visitPre(DocInternal *) override; void visitPost(DocInternal *) override; void visitPre(DocHRef *) override; void visitPost(DocHRef *) override; void visitPre(DocHtmlHeader *) override; void visitPost(DocHtmlHeader *) override; void visitPre(DocImage *) override; void visitPost(DocImage *) override; void visitPre(DocDotFile *) override; void visitPost(DocDotFile *) override; void visitPre(DocMscFile *) override; void visitPost(DocMscFile *) override; void visitPre(DocDiaFile *) override; void visitPost(DocDiaFile *) override; void visitPre(DocLink *) override; void visitPost(DocLink *) override; void visitPre(DocRef *) override; void visitPost(DocRef *) override; void visitPre(DocSecRefItem *) override; void visitPost(DocSecRefItem *) override; void visitPre(DocSecRefList *) override; void visitPost(DocSecRefList *) override; //void visitPre(DocLanguage *); //void visitPost(DocLanguage *); void visitPre(DocParamSect *) override; void visitPost(DocParamSect *) override; void visitPre(DocParamList *) override; void visitPost(DocParamList *) override; void visitPre(DocXRefItem *) override; void visitPost(DocXRefItem *) override; void visitPre(DocInternalRef *) override; void visitPost(DocInternalRef *) override; void visitPre(DocCopy *) override; void visitPost(DocCopy *) override; void visitPre(DocText *) override; void visitPost(DocText *) override; void visitPre(DocHtmlBlockQuote *) override; void visitPost(DocHtmlBlockQuote *) override; void visitPre(DocParBlock *) override; void visitPost(DocParBlock *) override; private: void filter(const QString &str); void startLink(const QString &file, const QString &anchor); void endLink(); void pushEnabled(); void popEnabled(); void startMscFile(const QString &fileName, const QString &width, const QString &height, bool hasCaption, const QList<DocNode *> &children); void endMscFile(bool hasCaption); void startDiaFile(const QString &fileName, const QString &width, const QString &height, bool hasCaption, const QList<DocNode *> &children); void endDiaFile(bool hasCaption); void startDotFile(const QString &fileName, const QString &width, const QString &height, bool hasCaption, const QList<DocNode *> &children); void endDotFile(bool hasCaption); void writeDotFile(const QString &fileName, DocVerbatim *s); void writeMscFile(const QString &fileName, DocVerbatim *s); void writeDiaFile(const QString &fileName, DocVerbatim *s); void writePlantUMLFile(const QString &fileName, DocVerbatim *s); void visitPreStart(QTextStream &t, const QList<DocNode *> &children, bool hasCaption, const QString &name, const QString &width, const QString &height, bool inlineImage = false); void visitPostEnd(QTextStream &t, bool hasCaption, bool inlineImage = false); void visitCaption(const QList<DocNode *> &children); QTextStream &m_t; CodeGenerator &m_ci; bool m_insidePre; bool m_hide; int m_colCnt; QStack<bool> m_enabled; QStack<bool> m_bodySet; QString m_langExt; }; #endif
6,705
C++
.h
159
38.333333
110
0.737237
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,666
portable.h
copperspice_doxypress/src/portable.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef PORTABLE_H #define PORTABLE_H #include <QGlobal> #include <QString> #include <sys/types.h> #include <stdio.h> #if defined(_WIN32) using portable_off_t = __int64; #else using portable_off_t = off_t; #endif QString portable_commandExtension(); int portable_system(const QString &command, const QString &args, bool commandHasConsole = true); void portable_sleep(int ms); uint portable_pid(); char portable_pathListSeparator(); QString portable_getenv(const QString &variable); void portable_setenv(const QString &variable, const QString &value); void portable_unsetenv(const QString &variable); portable_off_t portable_fseek(FILE *f, portable_off_t offset, int whence); portable_off_t portable_ftell(FILE *f); void portable_sysTimerStart(); void portable_sysTimerStop(); double portable_getSysElapsedTime(); Qt::CaseSensitivity portable_fileSystemIsCaseSensitive(); #endif
1,773
C++
.h
43
39.837209
107
0.681792
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,670
entry.h
copperspice_doxypress/src/entry.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef ENTRY_H #define ENTRY_H #include <arguments.h> #include <doxy_shared.h> #include <section.h> #include <types.h> #include <QFlatMap> #include <QString> #include <QVector> #include <bitset> class FileDef; struct ListItemInfo; // stores information about an inheritance relationship struct BaseInfo { BaseInfo(const QString &n, Protection p, Specifier v) : name(n), prot(p), virt(v) { } QString name; // name of the base class Protection prot; // inheritance type Specifier virt; // virtualness }; // store information about the tag file for an entry struct TagInfo { bool isEmpty() const { if (tag_Name.isEmpty() && tag_FileName.isEmpty() && tag_Anchor.isEmpty()) { return true; } else { return false; } } void clear() { tag_Name = QString(); tag_FileName = QString(); tag_Anchor = QString(); } QString tag_Name; QString tag_FileName; QString tag_Anchor; }; // used in m_entryMap enum class EntryKey { File_Name, // file name this entry was extracted from Brief_Docs, // brief description (doc block) Brief_File, // file in which the brief desc. was found Main_Docs, // documentation block (partly parsed) doc MainDocs_File, // file in which the documentation was found docFile Inbody_Docs, // documentation inside the body of a function inbodyDocs Inbody_File, // file in which the body doc was found inbodyFile Class_Name, // name of the class in which documents are found inside Include_File, // include file (2nd arg of \\class, must be unique) Include_Name, // include name (3rd arg of \\class) Source_Text, // the program text m_program Clang_Id, // libclang id Member_Type, // member type type Member_Args, // member argument string args Member_Bitfields, // member's bit fields bitfields Requires_Clause, // template requires clause Constraint, // concept constraint Exception_Spec, // throw specification exception Related_Class, // related class (doc block) relates Initial_Value, // initial value (for variables) Initializer // copperspice properties Read_Property, Write_Property, Reset_Property, Notify_Property, Revision_Property, Designable_Property, Scriptable_Property, Stored_Property, User_Property }; // store information about an entity found in the source code class Entry : public EnableSharedFromThis { public: // supported entry types enum Sections { CLASS_SEC = 0x00000001, NAMESPACE_SEC = 0x00000010, CONCEPT_SEC = 0x00000020, COMPOUND_MASK = CLASS_SEC, SCOPE_MASK = COMPOUND_MASK | NAMESPACE_SEC, CLASSDOC_SEC = 0x00000020, STRUCTDOC_SEC = 0x00000040, UNIONDOC_SEC = 0x00000080, EXCEPTIONDOC_SEC = 0x00000100, INTERFACEDOC_SEC = 0x00000200, PROTOCOLDOC_SEC = 0x00000400, CATEGORYDOC_SEC = 0x00000800, SERVICEDOC_SEC = 0x00001000, SINGLETONDOC_SEC = 0x00002000, COMPOUNDDOC_MASK = CLASSDOC_SEC | STRUCTDOC_SEC | UNIONDOC_SEC | EXCEPTIONDOC_SEC | INTERFACEDOC_SEC | PROTOCOLDOC_SEC | CATEGORYDOC_SEC | SERVICEDOC_SEC | SINGLETONDOC_SEC, SOURCE_SEC = 0x00004000, HEADER_SEC = 0x00008000, FILE_MASK = SOURCE_SEC | HEADER_SEC, CONCEPTDOC_SEC = 0x00100000, DEFINEDOC_SEC = 0x00200000, DIRDOC_SEC = 0x00300000, ENUMDOC_SEC = 0x00400000, FILEDOC_SEC = 0x00500000, GROUPDOC_SEC = 0x00600000, MAINPAGEDOC_SEC = 0x00700000, MEMBERDOC_SEC = 0x00800000, NAMESPACEDOC_SEC = 0x00900000, OVERLOADDOC_SEC = 0x00a00000, PACKAGEDOC_SEC = 0x00b00000, PAGEDOC_SEC = 0x00c00000, VARIABLEDOC_SEC = 0x00d00000, DEFINE_SEC = 0x00e00000, ENUM_SEC = 0x00f00000, EMPTY_SEC = 0x01000000, EXAMPLE_SEC = 0x02000000, FUNCTION_SEC = 0x03000000, INCLUDE_SEC = 0x04000000, MEMBERGRP_SEC = 0x05000000, OBJCIMPL_SEC = 0x06000000, PACKAGE_SEC = 0x07000000, TYPEDEF_SEC = 0x08000000, USINGDECL_SEC = 0x09000000, USINGDIR_SEC = 0x0a000000, VARIABLE_SEC = 0x0b000000, EXPORTED_INTERFACE_SEC = 0x0c000000, INCLUDED_SERVICE_SEC = 0x0d000000, EXAMPLE_LINENO_SEC = 0x0e000000, }; enum Virtue { // class specifiers AbstractClass, Exception, Generic, Interface, Protocol, Ref, SealedClass, Struct, EnumStruct, Template, Union, Value, Category, Enum, // Java-style enums Service, // UNO IDL Singleton, // UNO IDL ForwardDecl, // method properties for CopperSpice Readable, Writable, Reset, Notify, Revision, Designable, Scriptable, Stored, User, Constant, Final_Property, Assign, // member specifiers Deprecated, PrivateGettable, // C# private getter ProtectedGettable, // C# protected getter PrivateSettable, // C# private setter ProtectedSettable, // C# protected setter // attributes NoDiscard, NoReturn, // BypassUndocWarn, Inline, Final, Explicit, Mutable, Settable, Gettable, Abstract, Addable, Removable, Raisable, Override, New, Sealed, Initonly, Optional, Required, NonAtomic, Copy, Retain, Strong, Weak, Unretained, Alias, ConstExpr, Default, Delete, NoExcept, Attribute, // UNO IDL attribute Property, // UNO IDL property Readonly, // on UNO IDL attribute or property Bound, // on UNO IDL attribute or property Constrained, // on UNO IDL property Transient, // on UNO IDL property MaybeVoid, // on UNO IDL property MaybeDefault, // on UNO IDL property MaybeAmbiguous, // on UNO IDL property Published, // UNO IDL keyword LastVirtue = Published }; // group types for docs enum GroupDocType { GROUPDOC_NORMAL, // defgroup GROUPDOC_ADD, // addtogroup GROUPDOC_WEAK // weakgroup }; class Traits { public: Traits & operator|=(const Traits &other) { this->m_flags |= other.m_flags; return *this; } QByteArray toQByteArray() const { return m_flags.to_string().c_str(); } static Traits fromQByteArray(const QByteArray &data) { Traits retval; retval.m_flags = std::bitset<Virtue::LastVirtue> { data.constData() }; return retval; } void clear() { m_flags.reset(); } bool hasTrait(Entry::Virtue data) const { return m_flags[data]; } void setTrait(Entry::Virtue data, bool value = true) { m_flags[data] = value; } bool onlyHasTrait(Entry::Virtue data) const { return m_flags[data] && m_flags.count() == 1; } private: std::bitset<Virtue::LastVirtue> m_flags; }; Entry(); Entry(const Entry &); ~Entry(); void addSpecialListItem(const QString &listName, int index); void createNavigationIndex(QSharedPointer<FileDef> fd); // returns the list of children for this Entry const QVector<QSharedPointer<Entry>> &children() const { return m_sublist; } QSharedPointer<FileDef> fileDef() const { return m_fileDef; } void setFileDef(QSharedPointer<FileDef> fd) { m_fileDef = fd; } // returns the parent for this Entry or null_ptr if this entry has no parent QSharedPointer<Entry> parent() const { return m_parent.toStrongRef(); } void setParent(QSharedPointer<Entry> parent) { m_parent = parent; } void setSection(int tmpSection) { section = tmpSection; } // ** sub entries // adds entry E as a child to this entry void addSubEntry (QSharedPointer<Entry> e); // Removes entry E from the list of children void removeSubEntry(QSharedPointer<Entry> e); // restore the state of this Entry to the default value when constructed void reset(); // ** methdods for EnteryKey flatMap QString getData(EntryKey key) const { return m_entryMap.value(key); } void setData(EntryKey key, QString data) { if (! data.isEmpty() || m_entryMap.contains(key)) { m_entryMap.insert(key, data); } } void appendData(EntryKey key, QString data) { auto iter = m_entryMap.find(key); if (iter == m_entryMap.end()) { m_entryMap.insert(key, data); } else { iter.value() += data; } } void prependData(EntryKey key, QString data) { auto iter = m_entryMap.find(key); if (iter == m_entryMap.end()) { m_entryMap.insert(key, data); } else { iter.value().prepend(data); } } TagInfo m_tagInfo; // tag file info ArgumentList argList; // member arguments as a list ArgumentList typeConstr; // where clause (C#) for type constraints RelatesType relatesType; // how relates is handled Specifier virt; // virtualness of the entry Protection protection; // class protection MethodType mtype; // signal, slot, (dcop) method, or property GroupDocType groupDocType; SrcLangExt m_srcLang; // programming language in which this entry was found Traits m_traits; int section; // entry type (see Sections); int initLines; // define/variable initializer lines to show bool referencedByRelation; // do we need to show the referenced by relation? bool referencesRelation; // do we need to show the references relation? int docLine; // line number at which the documentation was found int briefLine; // line number at which the brief desc. was found int inbodyLine; // line number at which the body doc was found int startBodyLine; // line number of the definition in the source int endBodyLine; // line number where the definition ends int mGrpId; // member group id int startLine; // start line of entry in the source int startColumn; // start column of entry in the source LocalToc localToc; bool m_static; // static bool explicitExternal; // explicitly defined as external bool proto; // prototype bool subGrouping; // automatically group class members bool callGraph; // do we need to draw the call graph bool callerGraph; // do we need to draw the caller graph bool hidden; // does this represent an entity that is hidden from the output bool artificial; // artificially introduced item QString m_entryName; // entry name QVector<ArgumentList> m_templateArgLists; // template argument declarations QVector<BaseInfo> extends; // list of base classes QVector<Grouping> m_groups; // list of groups this entry belongs to QVector<SectionInfo> m_anchors; // list of anchors defined in this entry QVector<ListItemInfo> m_specialLists; // special lists (test/todo/bug/deprecated/..) // return command name used to define GROUPDOC_SEC QString groupDocCmd() const { switch ( groupDocType ) { case GROUPDOC_NORMAL: return QString("\\defgroup"); case GROUPDOC_ADD: return QString("\\addtogroup"); case GROUPDOC_WEAK: return QString("\\weakgroup"); default: return QString("unknown group command"); } } Grouping::GroupPri_t groupingPri() const { if ( section != GROUPDOC_SEC ) { return Grouping::GROUPING_LOWEST; } switch ( groupDocType ) { case GROUPDOC_NORMAL: return Grouping::GROUPING_AUTO_DEF; case GROUPDOC_ADD: return Grouping::GROUPING_AUTO_ADD; case GROUPDOC_WEAK: return Grouping::GROUPING_AUTO_WEAK; default: return Grouping::GROUPING_LOWEST; } } // from old miniEntry QSharedPointer<Entry> entry() { QSharedPointer<Entry> self = sharedFrom(this); return self; } private: Entry &operator=(const Entry &); QFlatMap<EntryKey, QString> m_entryMap; // contains details about this entry QWeakPointer<Entry> m_parent; // parent node in the tree QVector<QSharedPointer<Entry>> m_sublist; // entries which are children QSharedPointer<FileDef> m_fileDef; // file associated with the entry }; #endif
14,917
C++
.h
397
31.423174
101
0.584963
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,671
doxy_setup.h
copperspice_doxypress/src/doxy_setup.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef DOXY_SETUP_H #define DOXY_SETUP_H #include <QFile> #include <QString> #include <QStringList> struct CommandLine { QString dateTimeStr; QString configName; QString layoutName; QString debugLabel; QString formatName; QString rtfExt; QString rtfStyle; QString htmlHead; QString htmlFoot; QString htmlStyle; QString latexHead; QString latexFoot; QString latexStyle; bool generateLayout = false; bool generateDoxy = true; }; void initDoxyPress(); CommandLine parseCommandLine(QStringList argList); void readConfiguration(struct CommandLine cmdArgs); void checkConfiguration(); void adjustConfiguration(); void searchInputFiles(); void processFiles(); void generateOutput(); void shutDownDoxyPress(); void initDefaultLangMapping(); void initUserLangMapping(); void addCodeOnlyMappings(); bool openOutputFile(const QString &outFile, QFile &f); bool updateLanguageMapping(const QString &extension, const QString &parser, bool userParser = false); #endif
1,792
C++
.h
54
31.037037
101
0.733295
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,673
parse_lib_tooling.h
copperspice_doxypress/src/parse_lib_tooling.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef PARSE_LIB_TOOLING_H #define PARSE_LIB_TOOLING_H #include <entry.h> #include <QSharedPointer> #include <clang/AST/ASTConsumer.h> #include <clang/AST/RecursiveASTVisitor.h> #include <clang/Frontend/CompilerInstance.h> #include <clang/Frontend/FrontendActions.h> #include <clang/Index/USRGeneration.h> #include <clang/Tooling/CommonOptionsParser.h> #include <clang/Tooling/Tooling.h> extern QSharedPointer<Entry> s_current_root; extern QMap<QString, QSharedPointer<Entry>> s_entryMap; class DoxyFrontEnd : public clang::ASTFrontendAction { public: std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance &compiler, llvm::StringRef file) override; }; #endif
1,491
C++
.h
37
38.405405
94
0.714088
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,677
msc.h
copperspice_doxypress/src/msc.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef MSC_H #define MSC_H #include <QString> #include <QTextStream> enum MscOutputFormat { MSC_BITMAP, MSC_EPS, MSC_SVG }; void writeMscGraphFromFile(const QString &inFile, const QString &outDir, const QString &outFile, MscOutputFormat format); QString getMscImageMapFromFile(const QString &nFile, const QString &outDir, const QString &relPath, const QString &contxt); void writeMscImageMapFromFile(QTextStream &t, const QString &inFile, const QString &outDir, const QString &relPath, const QString &baseName, const QString &context, MscOutputFormat format ); #endif
1,378
C++
.h
33
39.69697
115
0.703815
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,679
dia.h
copperspice_doxypress/src/dia.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef DIA_H #define DIA_H #include <QString> enum DiaOutputFormat { DIA_BITMAP, DIA_EPS }; void writeDiaGraphFromFile(const QString &inFile, const QString &outDir, const QString &outFile, DiaOutputFormat format); #endif
1,014
C++
.h
27
35.888889
74
0.673802
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,680
rtfstyle.h
copperspice_doxypress/src/rtfstyle.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef RTFSTYLE_H #define RTFSTYLE_H #include <QHash> #include <QRegularExpression> #include <QString> // used for table column width calculation static constexpr const int rtf_pageWidth = 8748; extern QString rtf_title; extern QString rtf_subject; extern QString rtf_comments; extern QString rtf_company; extern QString rtf_logoFilename; extern QString rtf_author; extern QString rtf_manager; extern QString rtf_documentType; extern QString rtf_documentId; extern QString rtf_keywords; struct RTFListItemInfo { bool isEnum; int number; }; const int rtf_maxIndentLevels = 10; extern RTFListItemInfo rtf_listItemInfo[rtf_maxIndentLevels]; struct Rtf_Style_Default { Rtf_Style_Default(const char *x1, const char *x2, const char *x3) { style_name = QString::fromLatin1(x1); style_reference = QString::fromLatin1(x2); style_definition = QString::fromLatin1(x3); } QString style_name; QString style_reference; QString style_definition; }; extern char rtf_Style_Reset[]; extern Rtf_Style_Default rtf_Style_Default[]; struct StyleData { // elements of this type are stored in dictionary Rtf_Style // to define a tag in the header reference + definition is required // to use a tag in the body of the document only reference is required unsigned int m_index; // index in style-sheet, i.e. number in s-clause QString m_reference; // everything required to apply the style QString m_definition; // additional tags like \snext and style name StyleData(const QString &reference, const QString &definition); StyleData(); ~StyleData(); bool setStyle(const QString &s, const QString &styleName); }; extern QHash<QString, StyleData> rtf_Style; void loadExtensions(const QString &name); void loadStylesheet(const QString &name, QHash<QString, StyleData> &dict); #endif
2,648
C++
.h
68
36.632353
81
0.725781
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,682
xmldocvisitor.h
copperspice_doxypress/src/xmldocvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef XMLDOCVISITOR_H #define XMLDOCVISITOR_H #include <docvisitor.h> #include <QByteArray> #include <QStack> #include <QTextStream> class CodeGenerator; class XmlDocVisitor : public DocVisitor { public: XmlDocVisitor(QTextStream &t, CodeGenerator &ci); //-------------------------------------- // visitor functions for leaf nodes //-------------------------------------- void visit(DocWord *) override; void visit(DocLinkedWord *) override; void visit(DocWhiteSpace *) override; void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *) override; void visit(DocLineBreak *) override; void visit(DocHorRuler *) override; void visit(DocStyleChange *) override; void visit(DocVerbatim *) override; void visit(DocAnchor *) override; void visit(DocInclude *) override; void visit(DocIncOperator *) override; void visit(DocFormula *) override; void visit(DocIndexEntry *) override; void visit(DocSimpleSectSep *) override; void visit(DocCite *) override; // visitor functions for compound nodes void visitPre(DocAutoList *) override; void visitPost(DocAutoList *) override; void visitPre(DocAutoListItem *) override; void visitPost(DocAutoListItem *) override; void visitPre(DocPara *) override; void visitPost(DocPara *) override; void visitPre(DocRoot *) override; void visitPost(DocRoot *) override; void visitPre(DocSimpleSect *) override; void visitPost(DocSimpleSect *) override; void visitPre(DocTitle *) override; void visitPost(DocTitle *) override; void visitPre(DocSimpleList *) override; void visitPost(DocSimpleList *) override; void visitPre(DocSimpleListItem *) override; void visitPost(DocSimpleListItem *) override; void visitPre(DocSection *) override; void visitPost(DocSection *) override; void visitPre(DocHtmlList *) override; void visitPost(DocHtmlList *) override; void visitPre(DocHtmlListItem *) override; void visitPost(DocHtmlListItem *) override; //void visitPre(DocHtmlPre *); //void visitPost(DocHtmlPre *); void visitPre(DocHtmlDescList *) override; void visitPost(DocHtmlDescList *) override; void visitPre(DocHtmlDescTitle *) override; void visitPost(DocHtmlDescTitle *) override; void visitPre(DocHtmlDescData *) override; void visitPost(DocHtmlDescData *) override; void visitPre(DocHtmlTable *) override; void visitPost(DocHtmlTable *) override; void visitPre(DocHtmlRow *) override; void visitPost(DocHtmlRow *) override; void visitPre(DocHtmlCell *) override; void visitPost(DocHtmlCell *) override; void visitPre(DocHtmlCaption *) override; void visitPost(DocHtmlCaption *) override; void visitPre(DocInternal *) override; void visitPost(DocInternal *) override; void visitPre(DocHRef *) override; void visitPost(DocHRef *) override; void visitPre(DocHtmlHeader *) override; void visitPost(DocHtmlHeader *) override; void visitPre(DocImage *) override; void visitPost(DocImage *) override; void visitPre(DocDotFile *) override; void visitPost(DocDotFile *) override; void visitPre(DocMscFile *) override; void visitPost(DocMscFile *) override; void visitPre(DocDiaFile *) override; void visitPost(DocDiaFile *) override; void visitPre(DocLink *) override; void visitPost(DocLink *) override; void visitPre(DocRef *) override; void visitPost(DocRef *) override; void visitPre(DocSecRefItem *) override; void visitPost(DocSecRefItem *) override; void visitPre(DocSecRefList *) override; void visitPost(DocSecRefList *) override; //void visitPre(DocLanguage *); //void visitPost(DocLanguage *); void visitPre(DocParamSect *) override; void visitPost(DocParamSect *) override; void visitPre(DocParamList *) override; void visitPost(DocParamList *) override; void visitPre(DocXRefItem *) override; void visitPost(DocXRefItem *) override; void visitPre(DocInternalRef *) override; void visitPost(DocInternalRef *) override; void visitPre(DocCopy *) override; void visitPost(DocCopy *) override; void visitPre(DocText *) override; void visitPost(DocText *) override; void visitPre(DocHtmlBlockQuote *) override; void visitPost(DocHtmlBlockQuote *) override; void visitPre(DocParBlock *) override; void visitPost(DocParBlock *) override; private: void filter(const QString &str); void startLink(const QString &ref, const QString &file, const QString &anchor); void endLink(); void pushEnabled(); void popEnabled(); QTextStream &m_t; CodeGenerator &m_ci; bool m_insidePre; bool m_hide; QStack<bool> m_enabled; QString m_langExt; }; #endif
5,529
C++
.h
141
35.695035
82
0.72541
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,683
code_xml.h
copperspice_doxypress/src/code_xml.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef CODE_XML_H #define CODE_XML_H #include <QByteArray> #include <QSharedPointer> #include <types.h> class CodeGenerator; class FileDef; class MemberDef; class Definition; void parseXmlCode(CodeGenerator &, const QString &, const QString &, SrcLangExt lang, bool isExample, const QString &exName, QSharedPointer<FileDef> fd, int startLine, int endLine, bool inlineFragment, QSharedPointer<MemberDef> memberDef, bool showLineNumbers, QSharedPointer<Definition> searchCtx, bool collectXRefs); void resetXmlCodeParserState(); #endif
1,347
C++
.h
31
41.193548
132
0.701299
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,685
cite.h
copperspice_doxypress/src/cite.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef CITE_H #define CITE_H #include <QHash> #include <QTextStream> /// String constants for citations struct CiteConsts { static const QString fileName; static const QString anchorPrefix; }; // This class provides access do the database of bibliographic references through the bibtex backend. class CiteDict { public: CiteDict(); /** Insert a citation identified by \a label into the database */ void insert(const QString &label); /** Return the citation info for a given label */ QString find(const QString &label) const; /** Generate the citations page */ void generatePage() const; /** clears the hash */ void clear(); /** return true if there are no citations */ bool isEmpty() const; /* writes the latex code for the bibliography section to text stream */ void writeLatexBibliography(QTextStream &t); private: mutable QMap<QString, QString> m_entries; QString m_baseFileName; }; #endif
1,740
C++
.h
48
33.791667
101
0.692857
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,686
types.h
copperspice_doxypress/src/types.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TYPES_H #define TYPES_H #include <QString> /** Protection level of members */ enum Protection { Public, Protected, Private, Package }; /** Virtualness of a member */ enum Specifier { Normal, Virtual, Pure }; /** Reference qualifier for a method */ enum RefType { NoRef, LValueRef, RValueRef }; /** Kind of member */ enum class MethodType { Method, Signal, Slot, DCOP, Property, Event }; /** Type of member relation */ enum RelatesType { Simple, Duplicate, MemberOf }; /** Kind of member relationship */ enum Relationship { Member, Related, Foreign, Friend }; /** Language as given by extension */ enum SrcLangExt { SrcLangExt_Unknown = 0x00000, SrcLangExt_IDL = 0x00008, SrcLangExt_Java = 0x00010, SrcLangExt_CSharp = 0x00020, SrcLangExt_D = 0x00040, SrcLangExt_PHP = 0x00080, SrcLangExt_ObjC = 0x00100, SrcLangExt_Cpp = 0x00200, SrcLangExt_JS = 0x00400, SrcLangExt_Python = 0x00800, SrcLangExt_Fortran = 0x01000, SrcLangExt_XML = 0x04000, SrcLangExt_Tcl = 0x08000, SrcLangExt_Markdown = 0x10000, SrcLangExt_Make = 0x20000, SrcLangExt_Docs = 0x40000, }; // various compound types enum class CompoundType { Class, // Entry::CLASS_SEC, Struct, // Entry::STRUCT_SEC, Union, // Entry::UNION_SEC, Interface, // Entry::INTERFACE_SEC, Protocol, // Entry::PROTOCOL_SEC, Category, // Entry::CATEGORY_SEC, Exception, // Entry::EXCEPTION_SEC Service, // Entry::CLASS_SEC Singleton, // Entry::CLASS_SEC }; /** Grouping info */ struct Grouping { /** Grouping priority */ enum GroupPri_t { GROUPING_LOWEST, GROUPING_AUTO_WEAK = GROUPING_LOWEST, // membership in group was defined via \@weakgroup GROUPING_AUTO_ADD, // membership in group was defined via \@add[to]group GROUPING_AUTO_DEF, // membership in group was defined via \@defgroup GROUPING_AUTO_HIGHEST = GROUPING_AUTO_DEF, GROUPING_INGROUP, // membership in group was defined by \@ingroup GROUPING_HIGHEST = GROUPING_INGROUP }; static QString getGroupPriName( GroupPri_t priority ) { switch ( priority ) { case GROUPING_AUTO_WEAK: return QString("@weakgroup"); case GROUPING_AUTO_ADD: return QString("@addtogroup"); case GROUPING_AUTO_DEF: return QString("@defgroup"); case GROUPING_INGROUP: return QString("@ingroup"); } return QString("Unknown Group Command"); } Grouping( const QString &gn, GroupPri_t p ) : groupname(gn), pri(p) {} Grouping( const Grouping &g ) : groupname(g.groupname), pri(g.pri) {} QString groupname; // name of the group GroupPri_t pri; // priority of this definition }; struct ListItemInfo { QString type; int itemId; }; enum MemberListType { MemberListType_detailedLists = 0x1000, MemberListType_declarationLists = 0x2000, MemberListType_documentationLists = 0x4000, MemberListType_pubMethods = 0, MemberListType_proMethods = 1, MemberListType_pacMethods = 2, MemberListType_priMethods = 3, MemberListType_pubStaticMethods = 4, MemberListType_proStaticMethods = 5, MemberListType_pacStaticMethods = 6, MemberListType_priStaticMethods = 7, MemberListType_pubSignals = 8, MemberListType_proSignals = 9, MemberListType_priSignals = 10, MemberListType_pubSlots = 11, MemberListType_proSlots = 12, MemberListType_priSlots = 13, MemberListType_pubAttribs = 14, MemberListType_proAttribs = 15, MemberListType_pacAttribs = 16, MemberListType_priAttribs = 17, MemberListType_pubStaticAttribs = 18, MemberListType_proStaticAttribs = 19, MemberListType_pacStaticAttribs = 20, MemberListType_priStaticAttribs = 21, MemberListType_pubTypes = 22, MemberListType_proTypes = 23, MemberListType_pacTypes = 24, MemberListType_priTypes = 25, MemberListType_pubTypedefs = 26, MemberListType_proTypedefs = 27, MemberListType_pacTypedefs = 28, MemberListType_priTypedefs = 29, MemberListType_services = 30, MemberListType_interfaces = 31, MemberListType_properties = 32, MemberListType_events = 33, MemberListType_friends = 34, MemberListType_related = 35, MemberListType_dcopMethods = 36, MemberListType_typedefMembers = 37 + MemberListType_detailedLists, MemberListType_enumMembers = 38 + MemberListType_detailedLists, MemberListType_enumValMembers = 39 + MemberListType_detailedLists, MemberListType_functionMembers = 40 + MemberListType_detailedLists, MemberListType_relatedMembers = 41 + MemberListType_detailedLists, MemberListType_variableMembers = 42 + MemberListType_detailedLists, MemberListType_propertyMembers = 43 + MemberListType_detailedLists, MemberListType_eventMembers = 44 + MemberListType_detailedLists, MemberListType_constructors = 45 + MemberListType_detailedLists, MemberListType_allMembersList = 46, // MemberListType_decDefineMembers = 47 + MemberListType_declarationLists, MemberListType_decProtoMembers = 48 + MemberListType_declarationLists, MemberListType_decTypedefMembers = 49 + MemberListType_declarationLists, MemberListType_decEnumMembers = 50 + MemberListType_declarationLists, MemberListType_decFuncMembers = 51 + MemberListType_declarationLists, MemberListType_decVarMembers = 52 + MemberListType_declarationLists, MemberListType_decEnumValMembers = 53 + MemberListType_declarationLists, MemberListType_decPubSlotMembers = 54 + MemberListType_declarationLists, MemberListType_decProSlotMembers = 55 + MemberListType_declarationLists, MemberListType_decPriSlotMembers = 56 + MemberListType_declarationLists, MemberListType_decPubSignalMembers = 57 + MemberListType_declarationLists, MemberListType_decProSignalMembers = 58 + MemberListType_declarationLists, MemberListType_decPriSignalMembers = 59 + MemberListType_declarationLists, MemberListType_decEventMembers = 60 + MemberListType_declarationLists, MemberListType_decFriendMembers = 61 + MemberListType_declarationLists, MemberListType_decPropMembers = 62 + MemberListType_declarationLists, // MemberListType_docDefineMembers = 63 + MemberListType_documentationLists, MemberListType_docProtoMembers = 64 + MemberListType_documentationLists, MemberListType_docTypedefMembers = 65 + MemberListType_documentationLists, MemberListType_docEnumMembers = 66 + MemberListType_documentationLists, MemberListType_docFuncMembers = 67 + MemberListType_documentationLists, MemberListType_docVarMembers = 68 + MemberListType_documentationLists, MemberListType_docEnumValMembers = 69 + MemberListType_documentationLists, MemberListType_docPubSlotMembers = 70 + MemberListType_documentationLists, MemberListType_docProSlotMembers = 71 + MemberListType_documentationLists, MemberListType_docPriSlotMembers = 72 + MemberListType_documentationLists, MemberListType_docPubSignalMembers = 73 + MemberListType_documentationLists, MemberListType_docProSignalMembers = 74 + MemberListType_documentationLists, MemberListType_docPriSignalMembers = 75 + MemberListType_documentationLists, MemberListType_docEventMembers = 76 + MemberListType_documentationLists, MemberListType_docFriendMembers = 77 + MemberListType_documentationLists, MemberListType_docPropMembers = 78 + MemberListType_documentationLists, MemberListType_redefinedBy = 79, MemberListType_enumFields = 80, MemberListType_memberGroup = 81, // or the detailed section on the class page MemberListType_interfaceMembers = 82 + MemberListType_detailedLists, MemberListType_serviceMembers = 83 + MemberListType_detailedLists, }; enum class MemberDefType { Define, Function, Variable, Typedef, Enumeration, EnumValue, Interface, Service, Signal, Slot, DCOP, Property, Event }; enum FortranFormat { FortranFormat_Unknown, FortranFormat_Free, FortranFormat_Fixed }; class LocalToc { public: enum Type { None = 0, // initial value Html = 0, // also to be used as bit position in mask (1 << Html) Latex = 1, Xml = 2, Docbook = 3, numTocTypes = 4 // number of enum values }; LocalToc() : m_mask(None) { memset(m_level, 0, sizeof(m_level)); } void enableHtml(int level) { m_mask |= (1 << Html); m_level[Html] = level; } void enableLatex(int level) { m_mask |= (1 << Latex); m_level[Latex] = level; } void enableXml(int level) { m_mask |= (1 << Xml); m_level[Xml] = level; } void enableDocbook(int level) { m_mask |= (1 << Docbook); m_level[Docbook] = level; } bool isHtmlEnabled() const { return (m_mask & (1 << Html)) != 0; } bool isLatexEnabled() const { return (m_mask & (1 << Latex)) != 0; } bool isXmlEnabled() const { return (m_mask & (1 << Xml)) != 0; } bool isDocbookEnabled() const { return (m_mask & (1 << Docbook)) != 0; } bool nothingEnabled() const { return m_mask == None; } int htmlLevel() const { return m_level[Html]; } int latexLevel() const { return m_level[Latex]; } int xmlLevel() const { return m_level[Xml]; } int docbookLevel() const { return m_level[Docbook]; } int mask() const { return m_mask; } private: int m_mask; int m_level[numTocTypes]; }; #endif
11,277
C++
.h
272
37.25
103
0.655616
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,691
xmlgen.h
copperspice_doxypress/src/xmlgen.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef XMLGEN_H #define XMLGEN_H #include <outputgen.h> class XMLCodeGenerator : public CodeGenerator { public: XMLCodeGenerator(QTextStream &t) : m_t(t), m_lineNumber(-1), m_isMemberRef(false), m_col(0), m_insideCodeLine(false), m_normalHLNeedStartTag(true), m_insideSpecialHL(false) { } virtual ~XMLCodeGenerator() { } void codify(const QString &text) override; void writeCodeLink(const QString &ref, const QString &file, const QString &anchor, const QString &name, const QString &tooltip) override; void writeTooltip(const QString &, const DocLinkInfo &, const QString &, const QString &, const SourceLinkInfo &, const SourceLinkInfo &) override; void startCodeLine(bool) override; void endCodeLine() override; void startFontClass(const QString &colorClass) override ; void endFontClass() override; void writeCodeAnchor(const QString &) override; void writeLineNumber(const QString &extRef, const QString &compId, const QString &anchorId, int l) override; void setCurrentDoc(QSharedPointer<Definition> def, const QString &, bool) override { (void) def; } void addWord(const QString &, bool) override { } void startCodeFragment(const QString &) override; void endCodeFragment(const QString &) override; void finish(); private: QTextStream &m_t; QString m_refId; QString m_external; int m_lineNumber; bool m_isMemberRef; int m_col; bool m_insideCodeLine; bool m_normalHLNeedStartTag; bool m_insideSpecialHL; }; void generateXML_output(); #endif
2,386
C++
.h
60
36.033333
111
0.69948
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,694
commentcnv.h
copperspice_doxypress/src/commentcnv.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef COMMENTCNV_H #define COMMENTCNV_H #include <QString> extern QString convertCppComments(const QString &inBuf, const QString &fileName); #endif
929
C++
.h
22
41
81
0.674058
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,695
language.h
copperspice_doxypress/src/language.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef LANGUAGE_H #define LANGUAGE_H #include <translator.h> #include <translator_cs.h> // using the CS i18n system extern Translator_Cs translator_Cs; extern Translator *theTranslator; // can be removed when theTranslator is changed QString getLanguage(); // place holder for a position in a list, used in translators inline QString generateMarker(int id) { QString retval = QString::number(id); retval.prepend('@'); return retval; } #endif
1,238
C++
.h
33
36.030303
86
0.690317
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,698
code_cstyle_internal.h
copperspice_doxypress/src/code_cstyle_internal.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #include <classdef.h> #include <stringmap.h> struct CallContext { QString name; QString type; QSharedPointer<Definition> d; }; /*! Represents a stack of variable to class mappings as found in the code. * Each scope is enclosed in pushScope() and popScope() calls. * Variables are added by calling addVariables() and you can search * for variables using findVariable(). */ class VariableContext { public: static QSharedPointer<ClassDef> dummyContext(); VariableContext() { } virtual ~VariableContext() { } void pushScope() { m_scopes.append(new StringMap<QSharedPointer<ClassDef>>); } void popScope() { if (m_scopes.count() > 0) { m_scopes.removeAt(m_scopes.count() - 1); } } void clear() { m_scopes.clear(); m_globalScope.clear(); } void clearExceptGlobal() { m_scopes.clear(); } void addVariable(const QString &type, const QString &name); QSharedPointer<ClassDef> findVariable(const QString &name); int count() const { return m_scopes.count(); } private: StringMap<QSharedPointer<ClassDef>> m_globalScope; QList<StringMap<QSharedPointer<ClassDef>> *> m_scopes; };
2,025
C++
.h
64
27.921875
75
0.660982
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,707
textdocvisitor.h
copperspice_doxypress/src/textdocvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TEXTDOCVISITOR_H #define TEXTDOCVISITOR_H #include <docparser.h> #include <docvisitor.h> #include <QByteArray> #include <QStack> #include <QTextStream> /*! @brief Concrete visitor implementation for TEXT output. */ class TextDocVisitor : public DocVisitor { public: TextDocVisitor(QTextStream &t) : DocVisitor(DocVisitor_Text), m_t(t) {} // visitor functions for leaf nodes void visit(DocWord *w) override { filter(w->word()); } void visit(DocLinkedWord *w) override { filter(w->word()); } void visit(DocWhiteSpace *) override { m_t << " "; } void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *u) override { filter(u->url()); } void visit(DocLineBreak *) override { m_t << " "; } void visit(DocHorRuler *) override {} void visit(DocStyleChange *) override {} void visit(DocVerbatim *s) override{ filter(s->text()); } void visit(DocAnchor *) override {} void visit(DocInclude *) override {} void visit(DocIncOperator *) override {} void visit(DocFormula *) override {} void visit(DocIndexEntry *) override {} void visit(DocSimpleSectSep *) override {} void visit(DocCite *) override {} // visitor functions for compound nodes void visitPre(DocAutoList *) override {} void visitPost(DocAutoList *) override {} void visitPre(DocAutoListItem *) override {} void visitPost(DocAutoListItem *) override {} void visitPre(DocPara *) override {} void visitPost(DocPara *) override {} void visitPre(DocRoot *) override {} void visitPost(DocRoot *) override {} void visitPre(DocSimpleSect *) override {} void visitPost(DocSimpleSect *) override {} void visitPre(DocTitle *) override {} void visitPost(DocTitle *) override {} void visitPre(DocSimpleList *) override {} void visitPost(DocSimpleList *) override {} void visitPre(DocSimpleListItem *) override {} void visitPost(DocSimpleListItem *) override {} void visitPre(DocSection *) override {} void visitPost(DocSection *) override {} void visitPre(DocHtmlList *) override {} void visitPost(DocHtmlList *) override {} void visitPre(DocHtmlListItem *) override {} void visitPost(DocHtmlListItem *) override {} void visitPre(DocHtmlDescList *) override {} void visitPost(DocHtmlDescList *) override {} void visitPre(DocHtmlDescTitle *) override {} void visitPost(DocHtmlDescTitle *) override {} void visitPre(DocHtmlDescData *) override {} void visitPost(DocHtmlDescData *) override {} void visitPre(DocHtmlTable *) override {} void visitPost(DocHtmlTable *) override {} void visitPre(DocHtmlRow *) override {} void visitPost(DocHtmlRow *) override {} void visitPre(DocHtmlCell *) override {} void visitPost(DocHtmlCell *) override {} void visitPre(DocHtmlCaption *) override {} void visitPost(DocHtmlCaption *) override {} void visitPre(DocInternal *) override {} void visitPost(DocInternal *) override {} void visitPre(DocHRef *) override {} void visitPost(DocHRef *) override {} void visitPre(DocHtmlHeader *) override {} void visitPost(DocHtmlHeader *) override {} void visitPre(DocImage *) override {} void visitPost(DocImage *) override {} void visitPre(DocDotFile *) override {} void visitPost(DocDotFile *) override {} void visitPre(DocMscFile *) override {} void visitPost(DocMscFile *) override {} void visitPre(DocDiaFile *) override {} void visitPost(DocDiaFile *) override {} void visitPre(DocLink *) override {} void visitPost(DocLink *) override {} void visitPre(DocRef *) override {} void visitPost(DocRef *) override {} void visitPre(DocSecRefItem *) override {} void visitPost(DocSecRefItem *) override {} void visitPre(DocSecRefList *) override {} void visitPost(DocSecRefList *) override {} void visitPre(DocParamSect *) override {} void visitPost(DocParamSect *) override {} void visitPre(DocParamList *) override {} void visitPost(DocParamList *) override {} void visitPre(DocXRefItem *) override {} void visitPost(DocXRefItem *) override {} void visitPre(DocInternalRef *) override {} void visitPost(DocInternalRef *) override {} void visitPre(DocCopy *) override {} void visitPost(DocCopy *) override {} void visitPre(DocText *) override {} void visitPost(DocText *) override {} void visitPre(DocHtmlBlockQuote *) override {} void visitPost(DocHtmlBlockQuote *) override {} void visitPre(DocParBlock *) override {} void visitPost(DocParBlock *) override {} private: void filter(const QString &str); QTextStream &m_t; }; #endif
5,472
C++
.h
139
35.76259
74
0.703857
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,709
declinfo.h
copperspice_doxypress/src/declinfo.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef DECLINFO_H #define DECLINFO_H #include <types.h> #include <QString> #include <stdio.h> extern void parseFuncDecl(const QString &decl, SrcLangExt lang, QString &clName, QString &type, QString &name, QString &args, QString &funcTempList, QString &exceptions); #endif
1,070
C++
.h
25
40.88
95
0.670192
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,712
cmdmapper.h
copperspice_doxypress/src/cmdmapper.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef CMDMAPPER_H #define CMDMAPPER_H #include <QHash> struct CommandMap; const int SIMPLESECT_BIT = 0x1000; enum CommandType { CMD_UNKNOWN = 0, CMD_ADDINDEX = 1, CMD_AMP = 2, CMD_ANCHOR = 3, CMD_ANCHORNAME = 4, // cs CMD_AT = 5, CMD_ATTENTION = 6 | SIMPLESECT_BIT, CMD_AUTHOR = 7 | SIMPLESECT_BIT, CMD_AUTHORS = 8 | SIMPLESECT_BIT, CMD_BOLD = 9, CMD_BSLASH = 10, CMD_BYPASSUNDOCWARN = 11, CMD_CITE = 12, CMD_CODE = 13, CMD_COPYBRIEF = 14, CMD_COPYDETAILS = 15, CMD_COPYDOC = 16, CMD_COPYRIGHT = 17 | SIMPLESECT_BIT, CMD_DATE = 18 | SIMPLESECT_BIT, CMD_DBONLY = 19, CMD_DCOLON = 20, CMD_DIAFILE = 21, CMD_DOCBOOKINCLUDE = 22, CMD_DOLLAR = 23, CMD_DONTINCLUDE = 24, CMD_DOT = 25, CMD_DOTFILE = 26, CMD_EMOJI = 27, CMD_EMPHASIS = 28, CMD_ENDCODE = 29, CMD_ENDDBONLY = 30, CMD_ENDDOT = 31, CMD_ENDHTMLONLY = 32, CMD_ENDINTERNAL = 33, CMD_ENDLATEXONLY = 34, CMD_ENDLINK = 35, CMD_ENDMANONLY = 36, CMD_ENDMSC = 37, CMD_ENDPARBLOCK = 38, CMD_ENDRTFONLY = 39, CMD_ENDSECREFLIST = 40, CMD_ENDUML = 41, CMD_ENDVERBATIM = 42, CMD_ENDXMLONLY = 43, CMD_EQUAL = 44, CMD_EXCEPTION = 45 | SIMPLESECT_BIT, CMD_FORMULA = 46, CMD_GREATER = 47, CMD_HASH = 48, CMD_HTMLINCLUDE = 49, CMD_HTMLONLY = 50, CMD_IMAGE = 51, CMD_INCLUDE = 52, CMD_INCLUDEDOC = 53, CMD_INCWITHLINES = 54, CMD_INHERITDOC = 55, CMD_INTERNAL = 56, CMD_INTERNALREF = 57, CMD_INVARIANT = 58 | SIMPLESECT_BIT, CMD_JAVALINK = 59, CMD_LATEXINCLUDE = 60, CMD_LATEXONLY = 61, CMD_LESS = 62, CMD_LI = 63, CMD_LINE = 64, CMD_LINEBREAK = 65, CMD_LINK = 66, CMD_MANINCLUDE = 67, CMD_MANONLY = 68, CMD_MDASH = 69, CMD_MINUS = 70, CMD_MSC = 71, CMD_MSCFILE = 72, CMD_NDASH = 73, CMD_NOTE = 74 | SIMPLESECT_BIT, CMD_PAR = 75 | SIMPLESECT_BIT, CMD_PARAGRAPH = 76, CMD_PARAM = 77 | SIMPLESECT_BIT, CMD_PARBLOCK = 78, CMD_PERCENT = 79, CMD_PIPE = 80, CMD_PLUS = 81, CMD_POST = 82 | SIMPLESECT_BIT, CMD_PRE = 83 | SIMPLESECT_BIT, CMD_PUNT = 84, CMD_QUOTE = 85, CMD_REF = 86, CMD_REMARK = 87 | SIMPLESECT_BIT, CMD_RETURN = 88 | SIMPLESECT_BIT, CMD_RETVAL = 89 | SIMPLESECT_BIT, CMD_RTFINCLUDE = 90, CMD_RTFONLY = 91, CMD_SA = 92 | SIMPLESECT_BIT, CMD_SECREFITEM = 93, CMD_SECREFLIST = 94, CMD_SECTION = 95, CMD_SETSCOPE = 96, CMD_SINCE = 97 | SIMPLESECT_BIT, CMD_SKIP = 98, CMD_SKIPLINE = 99, CMD_SNIPPET = 100, CMD_SNIPPETDOC = 101, CMD_SNIPWITHLINES = 102, CMD_SORTID = 103, // cs CMD_STARTCODE = 104, CMD_STARTUML = 105, CMD_SUBPAGE = 106, CMD_SUBSECTION = 107, CMD_SUBSUBSECTION = 108, CMD_TPARAM = 109 | SIMPLESECT_BIT, CMD_UNTIL = 110, CMD_VERBATIM = 111, CMD_VERBINCLUDE = 112, CMD_VERSION = 113 | SIMPLESECT_BIT, CMD_WARNING = 114 | SIMPLESECT_BIT, CMD_XMLINCLUDE = 115, CMD_XMLONLY = 116, CMD_XREFITEM = 117 | SIMPLESECT_BIT, CMD_FORCE_OUTPUT = 118, // cs }; enum HtmlTagType { HTML_UNKNOWN = 0, HTML_A = 1, HTML_BLOCKQUOTE = 2, HTML_BOLD = 3, HTML_BR = 4, HTML_CAPTION = 5, HTML_CENTER = 6, HTML_CITE = 7, HTML_CODE = 8, HTML_DD = 9, HTML_DEL = 10, HTML_DETAILS = 11, HTML_DIV = 12, HTML_DL = 13, HTML_DT = 14, HTML_EMPHASIS = 15, HTML_H1 = 16, HTML_H2 = 17, HTML_H3 = 18, HTML_H4 = 19, HTML_H5 = 20, HTML_H6 = 21, HTML_HR = 22, HTML_IMG = 23, HTML_INS = 24, HTML_LI = 25, HTML_OL = 26, HTML_P = 27, HTML_PRE = 28, HTML_S = 29, HTML_SMALL = 30, HTML_SPAN = 31, HTML_STRIKE = 32, HTML_SUB = 33, HTML_SUP = 34, HTML_TABLE = 35, HTML_TD = 36, HTML_TH = 37, HTML_TR = 38, HTML_UL = 39, HTML_UNDERLINE = 40, XML_CmdMask = 0x100, XML_C = XML_CmdMask + 0, XML_CODE = XML_CmdMask + 1, XML_DESCRIPTION = XML_CmdMask + 2, XML_EXAMPLE = XML_CmdMask + 3, XML_EXCEPTION = XML_CmdMask + 4, XML_INCLUDE = XML_CmdMask + 5, XML_ITEM = XML_CmdMask + 6, XML_LIST = XML_CmdMask + 7, XML_LISTHEADER = XML_CmdMask + 8, XML_PARA = XML_CmdMask + 9, XML_PARAM = XML_CmdMask + 10, XML_PARAMREF = XML_CmdMask + 11, XML_PERMISSION = XML_CmdMask + 12, XML_REMARKS = XML_CmdMask + 13, XML_RETURNS = XML_CmdMask + 14, XML_SEE = XML_CmdMask + 15, XML_SEEALSO = XML_CmdMask + 16, XML_SUMMARY = XML_CmdMask + 17, XML_TERM = XML_CmdMask + 18, XML_TYPEPARAM = XML_CmdMask + 19, XML_TYPEPARAMREF = XML_CmdMask + 20, XML_VALUE = XML_CmdMask + 21, XML_INHERITDOC = XML_CmdMask + 22 }; /** Class representing a mapping from command names to command IDs. */ class Mapper { public: Mapper(const CommandMap *cm, bool caseSensitive); int map(const QString &n); QString map(const int n); private: QHash<QString, int> m_map; bool m_cs; }; /** Class representing a namespace for the HTML command mappers. */ struct Mappers { static void freeMappers(); static Mapper *cmdMapper; static Mapper *htmlTagMapper; }; #endif
7,199
C++
.h
228
27.982456
74
0.51236
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,713
translator_cs.h
copperspice_doxypress/src/translator_cs.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TRANSLATOR_CS_H #define TRANSLATOR_CS_H #include <config.h> #include <translator.h> QString generateMarker(int id); class Translator_Cs : public Translator { public: /*! Used to get the LaTeX command(s) for the language support. * This method should return a string with commands that switch LaTeX to the desired language. * * <pre>"\\usepackage[german]{babel}\n" * </pre> * * <pre>"\\usepackage{polski}\n" * "\\usepackage[latin2]{inputenc}\n" * "\\usepackage[T1]{fontenc}\n" * </pre> * * English LaTeX does not use these commands, return an empty string */ QString latexLanguageSupportCommand() override { QString retval = QCoreApplication::translate("latexSupport", "remove-value"); if (retval == "remove-value") { retval = QString(); } return retval; } QString trLanguageId() override { return QCoreApplication::translate("doxy-text", "ISO639 language code"); } /*! used in the compound documentation before a list of related functions. */ QString trRelatedFunctions() override { return QCoreApplication::translate("doxy-text", "Related Functions"); } /*! subscript for the related functions. */ QString trRelatedSubscript() override { return QCoreApplication::translate("doxy-text", "These are not member functions"); } /*! header that is put before the detailed description of files, classes and namespaces. */ QString trDetailedDescription() override { return QCoreApplication::translate("doxy-text", "Detailed Description"); } /*! header that is put before the list of typedefs. */ QString trMemberTypedefDocumentation() override { return QCoreApplication::translate("doxy-text", "Member Typedef Documentation"); } /*! header that is put before the list of enumerations. */ QString trMemberEnumerationDocumentation() override { return QCoreApplication::translate("doxy-text", "Member Enumeration Documentation"); } /*! header that is put before the list of member functions. */ QString trMemberFunctionDocumentation() override { return QCoreApplication::translate("doxy-text", "Member Function Documentation"); } /*! header that is put before the list of member attributes. */ QString trMemberDataDocumentation() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Field Documentation"); } else { return QCoreApplication::translate("doxy-text", "Member Data Documentation"); } } /*! this is the text of a link put after brief descriptions. */ QString trMore() override { return QCoreApplication::translate("doxy-text", "More...");; } /*! put in the class documentation */ QString trListOfAllMembers() override { return QCoreApplication::translate("doxy-text", "List of all members"); } /*! title of the "list of all members" page of a class */ QString trMemberList() override { return QCoreApplication::translate("doxy-text", "Member List"); } /*! first part of a sentence that is followed by a class name */ QString trThisIsTheListOfAllMembers() override { return QCoreApplication::translate("doxy-text", "This is the complete list of members for "); } /*! remainder of the sentence after the class name */ QString trIncludingInheritedMembers() override { return QCoreApplication::translate("doxy-text", ", including all inherited members."); } /*! the author sections at the bottom of man pages, s is the project name. */ QString trGeneratedAutomatically(const QString &s) override { if (! s.isEmpty() ) { return QCoreApplication::translate("doxy-text", "Generated automatically by DoxyPress for %1 from the source code.").formatArg(s); } else { return QCoreApplication::translate("doxy-text", "Generated automatically by DoxyPress from the source code."); } } /*! put after an enum name in the list of all members */ QString trEnumName() override { return QCoreApplication::translate("doxy-text", "enum name");; } /*! put after an enum value in the list of all members */ QString trEnumValue() override { return QCoreApplication::translate("doxy-text", "enum value"); } /*! put after an undocumented member in the list of all members */ QString trDefinedIn() override { return QCoreApplication::translate("doxy-text", "defined in"); } /*! This is put above each page as a link to the list of all groups of * compounds or files (see the \\group command). */ QString trModules() override { return QCoreApplication::translate("doxy-text", "Modules", "trModules"); } /*! put above each page as a link to the class hierarchy */ QString trClassHierarchy() override { return QCoreApplication::translate("doxy-text", "Class Hierarchy"); } /*! put above each page as a link to the list of annotated classes */ QString trCompoundList() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Structures", "trCompoundList"); } else { return QCoreApplication::translate("doxy-text", "Class List", "trCompoundList"); } } /*! This is put above each page as a link to the list of documented files */ QString trFileList() override { return QCoreApplication::translate("doxy-text", "File List"); } /*! This is put above each page as a link to all members of compounds. */ QString trCompoundMembers() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Fields", "trCompoundMembers"); } else { return QCoreApplication::translate("doxy-text", "Class Members", "trCompoundMembers"); } } /*! This is put above each page as a link to all members of files. */ QString trFileMembers() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Globals", "trFileMembers"); } else { return QCoreApplication::translate("doxy-text", "File Members", "trFileMembers"); } } /*! This is put above each page as a link to all related pages. */ QString trRelatedPages() override { return QCoreApplication::translate("doxy-text", "Related Pages"); } /*! This is put above each page as a link to file source. */ QString trFileSource() override { return QCoreApplication::translate("doxy-text", "File Source"); } /*! This is put above each page as a link to all examples. */ QString trExamples() override { return QCoreApplication::translate("doxy-text", "Examples"); } /*! This is put above each page as a link to the search engine. */ QString trSearch() override { return QCoreApplication::translate("doxy-text", "Search"); } /*! This is an introduction to the class hierarchy. */ QString trClassHierarchyDescription() override { return QCoreApplication::translate("doxy-text", "This inheritance list is sorted roughly, " "but not completely, alphabetically:"); } /*! This is an introduction to the list with all files. */ QString trFileListDescription(bool extractAll) override { if (extractAll) { return QCoreApplication::translate("doxy-text", "Here is a list of all files with brief " "descriptions:"); } else { return QCoreApplication::translate("doxy-text", "Here is a list of all documented files " "with brief descriptions:"); } } /*! This is an introduction to the annotated compound list. */ QString trCompoundListDescription() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Here are the data structures with brief descriptions:"); } else { return QCoreApplication::translate("doxy-text", "Here are the classes, structs, " "unions and interfaces with brief descriptions:"); } } /*! This is an introduction to the page with all class members. */ QString trCompoundMembersDescription(bool extractAll) override { QString result; if (extractAll) { if (Config::getBool("optimize-c")) { result = QCoreApplication::translate("doxy-text", "Here is a list of all struct and union " "fields with links to the structures/unions they belong to:"); } else { result = QCoreApplication::translate("doxy-text", "Here is a list of all class members " "with links to the classes they belong to:"); } } else { if (Config::getBool("optimize-c")) { result = QCoreApplication::translate("doxy-text", "Here is a list of all documented struct " "and union fields with links to the struct/union documentation for each field:"); } else { result = QCoreApplication::translate("doxy-text", "Here is a list of all documented " "class members with links to the class documentation for each member:"); } } return result; } /*! This is an introduction to the page with all file members. */ QString trFileMembersDescription(bool extractAll) override { QString result; if (extractAll) { if (Config::getBool("optimize-c")) { result = QCoreApplication::translate("doxy-text", "Here is a list of all functions, variables, " "defines, enums, and typedefs with links to the files they belong to:"); } else { result = QCoreApplication::translate("doxy-text", "Here is a list of all documented file members " "with links to the files they belong to:"); } } else { if (Config::getBool("optimize-c")) { result = QCoreApplication::translate("doxy-text", "Here is a list of all functions, variables, defines, " "enums, and typedefs with links to the documentation:"); } else { result = QCoreApplication::translate("doxy-text", "Here is a list of all documented file members with " "links to the documentation:"); } } return result; } /*! This is an introduction to the page with the list of all file source */ QString trFileSourceDescription() override { return QCoreApplication::translate("doxy-text", "Here is a list of all source code files with brief descriptions:"); } /*! This is an introduction to the page with the list of all examples */ QString trExamplesDescription() override { return QCoreApplication::translate("doxy-text", "Here is a list of all examples:"); } /*! This is an introduction to the page with the list of related pages */ QString trRelatedPagesDescription() override { return QCoreApplication::translate("doxy-text", "Here is a list of all related documentation pages:"); } /*! This is an introduction to the page with the list of class/file groups */ QString trModulesDescription() override { return QCoreApplication::translate("doxy-text", "Here is a list of all modules:"); } /*! This is an introduction for concepts */ QString trConcepts() override { return QCoreApplication::translate("doxy-text", "Concepts"); } /*! This is the definition of a concept */ QString trConceptDefinition() override { return QCoreApplication::translate("doxy-text", "Concept Definition"); } /*! This is an introduction to the page with the list of concepts */ QString trConceptList() override { return QCoreApplication::translate("doxy-text", "Concept List"); } /*! This is an introduction to the page with the list of class/file groups */ QString trConceptListDescription() override { return QCoreApplication::translate("doxy-text", "Here is a list of all concepts with brief descriptions:"); } // index titles (the project name is prepended for these) /*! This is used in HTML as the title of index.html. */ QString trDocumentation() override { return QCoreApplication::translate("doxy-text", "Documentation"); } /*! This is used in LaTeX as the title of the chapter with the index of all groups. */ QString trModuleIndex() override { return QCoreApplication::translate("doxy-text", "Module Index", "trModuleIndex"); } /*! This is used in LaTeX as the title of the chapter with the class hierarchy. */ QString trHierarchicalIndex() override { return QCoreApplication::translate("doxy-text", "Hierarchical Index"); } /*! This is used in LaTeX as the title of the chapter with the annotated compound index. */ QString trCompoundIndex() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Structure Index"); } else { return QCoreApplication::translate("doxy-text", "Class Index"); } } /*! used in LaTeX as the title of the chapter with the list of all files. */ QString trFileIndex() override { return QCoreApplication::translate("doxy-text", "File Index"); } /*! used in LaTeX as the title of the chapter containing the documentation of all groups. */ QString trModuleDocumentation() override { return QCoreApplication::translate("doxy-text", "Module Documentation"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all classes, structs and unions. */ QString trClassDocumentation() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Structure Documentation"); } else { return QCoreApplication::translate("doxy-text", "Class Documentation"); } } QString trConceptDocumentation() override { return QCoreApplication::translate("doxy-text", "Concept Documentation"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all files. */ QString trFileDocumentation() override { return QCoreApplication::translate("doxy-text", "File Documentation"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all examples. */ QString trExampleDocumentation() override { return QCoreApplication::translate("doxy-text", "Example Documentation"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all related pages. */ QString trPageDocumentation() override { return QCoreApplication::translate("doxy-text", "Page Documentation"); } /*! This is used in LaTeX as the title of the document */ QString trReferenceManual() override { return QCoreApplication::translate("doxy-text", "Reference Manual"); } /*! This is used in the documentation of a file as a header before the * list of defines */ QString trDefines() override { return QCoreApplication::translate("doxy-text", "Macros"); } // QString trPublicTypedefs() override { return QCoreApplication::translate("doxy-text", "Public Typedefs"); } QString trProtectedTypedefs() override { return QCoreApplication::translate("doxy-text", "Protected Typedefs"); } QString trPackageTypedefs() override { return QCoreApplication::translate("doxy-text", "Package Typedefs"); } QString trPrivateTypedefs() override { return QCoreApplication::translate("doxy-text", "Private Typedefs"); } // QString trPublicTypes() override { return QCoreApplication::translate("doxy-text", "Public Types"); } QString trProtectedTypes() override { return QCoreApplication::translate("doxy-text", "Protected Types"); } QString trPackageTypes() override { return QCoreApplication::translate("doxy-text", "Package Types"); } QString trPrivateTypes() override { return QCoreApplication::translate("doxy-text", "Private Types"); } /*! used in the documentation of a file as a header before the list of typedefs */ QString trTypedefs() override { return QCoreApplication::translate("doxy-text", "Typedefs"); } /*! used in the documentation of a file as a header before the list of enumerations */ QString trEnumerations() override { return QCoreApplication::translate("doxy-text", "Enums"); } /*! used in the documentation of a file as a header before the list of (global) functions */ QString trFunctions() override { return QCoreApplication::translate("doxy-text", "Functions"); } /*! used in the documentation of a file as a header before the list of (global) variables */ QString trVariables() override { return QCoreApplication::translate("doxy-text", "Variables"); } /*! This is used in the documentation of a file as a header before the * list of (global) variables */ QString trEnumerationValues() override { return QCoreApplication::translate("doxy-text", "Enum Values"); } /*! This is used in the documentation of a file before the list of * documentation blocks for defines */ QString trDefineDocumentation() override { return QCoreApplication::translate("doxy-text", "Macro Definition Documentation"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for typedefs */ QString trTypedefDocumentation() override { return QCoreApplication::translate("doxy-text", "Typedef Documentation"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for enumeration types */ QString trEnumerationTypeDocumentation() override { return QCoreApplication::translate("doxy-text", "Enumeration Type Documentation"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for functions */ QString trFunctionDocumentation() override { return QCoreApplication::translate("doxy-text", "Function Documentation"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for variables */ QString trVariableDocumentation() override { return QCoreApplication::translate("doxy-text", "Variable Documentation"); } /*! This is used in the documentation of a file/namespace/group before * the list of links to documented compounds */ QString trCompounds() override { static bool optimizeC = Config::getBool("optimize-c"); if (optimizeC) { return QCoreApplication::translate("doxy-text", "Data Structures", "trCompounds"); } else { return QCoreApplication::translate("doxy-text", "Classes", "trCompounds"); } } /*! This is used in the standard footer of each page and indicates when * the page was generated */ QString trGeneratedAt(const QString &date, const QString &projName) override { if (projName.isEmpty()) { return QCoreApplication::translate("doxy-text", "Generated on %1 &nbsp; by").formatArg(date); } else { return QCoreApplication::translate("doxy-text", "Generated on %1 for %2 &nbsp; by").formatArg(date).formatArg(projName); } } /*! this text is put before a class diagram */ QString trClassDiagram(const QString &clName) override { return QCoreApplication::translate("doxy-text", "Inheritance diagram for %1:").formatArg(clName); } /*! this text is generated when the \\internal command is used. */ QString trForInternalUseOnly() override { return QCoreApplication::translate("doxy-text", "For internal use only."); } /*! this text is generated when the \\warning command is used. */ QString trWarning() override { return QCoreApplication::translate("doxy-text", "Warning"); } /*! this text is generated when the \\version command is used. */ QString trVersion() override { return QCoreApplication::translate("doxy-text", "Version"); } /*! this text is generated when the \\date command is used. */ QString trDate() override { return QCoreApplication::translate("doxy-text", "Date"); } /*! this text is generated when the \\return command is used. */ QString trReturns() override { return QCoreApplication::translate("doxy-text", "Returns"); } /*! this text is generated when the \\sa command is used. */ QString trSeeAlso() override { return QCoreApplication::translate("doxy-text", "See also"); } /*! this text is generated when the \\param command is used. */ QString trParameters() override { return QCoreApplication::translate("doxy-text", "Parameters"); } /*! this text is generated when the \\exception command is used. */ QString trExceptions() override { return QCoreApplication::translate("doxy-text", "Exceptions"); } /*! this text is used in the title page of a LaTeX document. */ QString trGeneratedBy() override { return QCoreApplication::translate("doxy-text", "Generated by"); } /*! used as the title of page containing all the index of all namespaces. */ QString trNamespaceList() override { return QCoreApplication::translate("doxy-text", "Namespace List"); } /*! used as an introduction to the namespace list */ QString trNamespacesListDescription(bool extractAll) override { if (extractAll) { return QCoreApplication::translate("doxy-text", "Here is a list of all namespaces with " "brief descriptions:"); } else { return QCoreApplication::translate("doxy-text", "Here is a list of all documented namespaces " "with brief descriptions:"); } } /*! used in the class documentation as a header before the list of all * friends of a class */ QString trFriends() override { return QCoreApplication::translate("doxy-text", "Friends"); } /*! used in the class documentation as a header before the list of all * related classes */ QString trRelatedFunctionDocumentation() override { return QCoreApplication::translate("doxy-text", "Friends And Related Function Documentation"); } /*! used as the title of the HTML page of a class/struct/union */ QString trCompoundReference(const QString &clName, enum CompoundType compType, bool isTemplate) override { QString result; switch (compType) { case CompoundType::Class: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Class Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Class Reference").formatArg(clName); } break; case CompoundType::Struct: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Struct Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Struct Reference").formatArg(clName); } break; case CompoundType::Union: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Union Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Union Reference").formatArg(clName); } break; case CompoundType::Interface: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Interface Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Interface Reference").formatArg(clName); } break; case CompoundType::Protocol: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Protocol Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Protocol Reference").formatArg(clName); } break; case CompoundType::Category: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Category Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Category Reference").formatArg(clName); } break; case CompoundType::Exception: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Exception Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Exception Reference").formatArg(clName); } break; default: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Reference").formatArg(clName); } break; } return result; } /*! used as the title of the HTML page of a file */ QString trFileReference(const QString &fileName) override { return QCoreApplication::translate("doxy-text", "%1 File Reference").formatArg(fileName); } /*! used as the title of the HTML page of a namespace */ QString trNamespaceReference(const QString &name) override { return QCoreApplication::translate("doxy-text", "%1 Namespace Reference").formatArg(name); } QString trPublicMembers() override { return QCoreApplication::translate("doxy-text", "Public Member Functions"); } QString trPublicSignals() override { return QCoreApplication::translate("doxy-text", "Public Signals"); } QString trProtectedSignals() override { return QCoreApplication::translate("doxy-text", "Protected Signals"); } QString trPrivateSignals() override { return QCoreApplication::translate("doxy-text", "Private Signals"); } QString trStaticPublicMembers() override { return QCoreApplication::translate("doxy-text", "Static Public Member Functions"); } QString trProtectedMembers() override { return QCoreApplication::translate("doxy-text", "Protected Member Functions"); } QString trPublicSlots() override { return QCoreApplication::translate("doxy-text", "Public Slots"); } QString trProtectedSlots() override { return QCoreApplication::translate("doxy-text", "Protected Slots"); } QString trStaticProtectedMembers() override { return QCoreApplication::translate("doxy-text", "Static Protected Member Functions"); } QString trPrivateMembers() override { return QCoreApplication::translate("doxy-text", "Private Member Functions"); } QString trPrivateSlots() override { return QCoreApplication::translate("doxy-text", "Private Slots"); } QString trStaticPrivateMembers() override { return QCoreApplication::translate("doxy-text", "Static Private Member Functions"); } // returns a comma-separated list of items, use generateMarker(x) to indicate where item x should be put QString trWriteList(int numEntries) override { QString result; for (int i = 0; i < numEntries; i++) { // generate placeholders for the class links, entry i in the list result += generateMarker(i); // order is left to right, @0, @1, @2, and @3 if (i != numEntries - 1) { // add separator between values result += ", "; } } return result; } // used in class docs to produce a list of base classes, if class diagrams are disabled. QString trInheritsList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Inherits %1").formatArg(trWriteList(numEntries)); } /*! used in class docs to produce a list of super classes, * if class diagrams are disabled. */ QString trInheritedByList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Inherited by %1").formatArg( trWriteList(numEntries)); } // used in member docs to produce a list of members that are hidden by this one QString trReimplementedFromList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Reimplemented from %1").formatArg( trWriteList(numEntries)); } // used in member docs to produce a list of all member that overwrite the implementation of this member QString trReimplementedInList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Reimplemented in %1").formatArg( trWriteList(numEntries)); } /*! This is put above each page as a link to all members of namespaces. */ QString trNamespaceMembers() override { return QCoreApplication::translate("doxy-text", "Namespace Members"); } /*! This is an introduction to the page with all namespace members */ QString trNamespaceMemberDescription(bool extractAll) override { if (extractAll) { return QCoreApplication::translate("doxy-text", "Here is a list of all namespace members with links " "to the namespace documentation for each member:"); } else { return QCoreApplication::translate("doxy-text", "Here is a list of all documented namespace members " "with links to the namespaces they belong to:"); } } /*! This is used in LaTeX as the title of the chapter with the * index of all namespaces. */ QString trNamespaceIndex() override { return QCoreApplication::translate("doxy-text", "Namespace Index"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all namespaces. */ QString trNamespaceDocumentation() override { return QCoreApplication::translate("doxy-text", "Namespace Documentation"); } /*! This is used in the documentation before the list of all * namespaces in a file. */ QString trNamespaces() override { return QCoreApplication::translate("doxy-text", "Namespaces", "trNamespaces"); } /*! This is put at the bottom of a class documentation page and is * followed by a list of files that were used to generate the page. */ QString trGeneratedFromFiles(enum CompoundType compType, bool single) override { QString result; switch (compType) { case CompoundType::Class: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this class " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this class " " was generated from the following files:"); } break; case CompoundType::Struct: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this struct " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this struct " " was generated from the following files:"); } break; case CompoundType::Union: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this union " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this union " " was generated from the following files:"); } break; case CompoundType::Interface: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this interface " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this interface " " was generated from the following files:"); } break; case CompoundType::Protocol: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this protocol " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this protocol " " was generated from the following files:"); } break; case CompoundType::Category: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this category " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this category " " was generated from the following files:"); } break; case CompoundType::Exception: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this exception" " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this exception" " was generated from the following files:"); } break; default: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this " " was generated from the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this " " was generated from the following files:"); } break; } return result; } /*! This is used as the heading text for the retval command. */ QString trReturnValues() override { return QCoreApplication::translate("doxy-text", "Return Values"); } /*! This is in the (quick) index as a link to the main page (index.html) */ QString trMainPage() override { return QCoreApplication::translate("doxy-text", "Main Page"); } /*! This is used in references to page that are put in the LaTeX * documentation. It should be an abbreviation of the word page. */ QString trPageAbbreviation() override { return QCoreApplication::translate("doxy-text", "p,"); } QString trDefinedAtLineInSourceFile() override { return QCoreApplication::translate("doxy-text", "Definition at line @0 of file @1."); } QString trDefinedInSourceFile() override { return QCoreApplication::translate("doxy-text", "Definition in file @0."); } QString trDeprecated() override { return QCoreApplication::translate("doxy-text", "Deprecated"); } /*! this text is put before a collaboration diagram */ QString trCollaborationDiagram(const QString &clName) override { return QCoreApplication::translate("doxy-text", "Collaboration diagram for %1:").formatArg(clName); } /*! this text is put before an include dependency graph */ QString trInclDepGraph(const QString &fName) override { return QCoreApplication::translate("doxy-text", "Include dependency graph for %1:").formatArg(fName); } /*! header that is put before the list of constructor/destructors. */ QString trConstructorDocumentation() override { return QCoreApplication::translate("doxy-text", "Constructor & Destructor Documentation"); } /*! Used in the file documentation to point to the corresponding sources. */ QString trGotoSourceCode() override { return QCoreApplication::translate("doxy-text", "Go to the source code of this file."); } /*! Used in the file sources to point to the corresponding documentation. */ QString trGotoDocumentation() override { return QCoreApplication::translate("doxy-text", "Go to the documentation of this file."); } /*! Text for the \\pre command */ QString trPrecondition() override { return QCoreApplication::translate("doxy-text", "Precondition"); } /*! Text for the \\post command */ QString trPostcondition() override { return QCoreApplication::translate("doxy-text", "Postcondition"); } /*! Text for the \\invariant command */ QString trInvariant() override { return QCoreApplication::translate("doxy-text", "Invariant"); } /*! Text shown before a multi-line variable/enum initialization */ QString trInitialValue() override { return QCoreApplication::translate("doxy-text", "Initial value:"); } /*! Text used the source code in the file index */ QString trCode() override { return QCoreApplication::translate("doxy-text", "code"); } QString trGraphicalHierarchy() override { return QCoreApplication::translate("doxy-text", "Graphical Class Hierarchy"); } QString trGotoGraphicalHierarchy() override { return QCoreApplication::translate("doxy-text", "Go to the graphical class hierarchy"); } QString trGotoTextualHierarchy() override { return QCoreApplication::translate("doxy-text", "Go to the textual class hierarchy"); } QString trPageIndex() override { return QCoreApplication::translate("doxy-text", "Page Index"); } QString trNote() override { return QCoreApplication::translate("doxy-text", "Note"); } QString trPublicAttribs() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Fields", "trPublicAttribs"); } else { return QCoreApplication::translate("doxy-text", "Public Attributes" , "trPublicAttribs"); } } QString trStaticPublicAttribs() override { return QCoreApplication::translate("doxy-text", "Static Public Attributes"); } QString trProtectedAttribs() override { return QCoreApplication::translate("doxy-text", "Protected Attributes"); } QString trStaticProtectedAttribs() override { return QCoreApplication::translate("doxy-text", "Static Protected Attributes"); } QString trPrivateAttribs() override { return QCoreApplication::translate("doxy-text", "Private Attributes"); } QString trStaticPrivateAttribs() override { return QCoreApplication::translate("doxy-text", "Static Private Attributes"); } /*! Used as a marker that is put before a \\todo item */ QString trTodo() override { return QCoreApplication::translate("doxy-text", "Todo"); } /*! Used as the header of the todo list */ QString trTodoList() override { return QCoreApplication::translate("doxy-text", "Todo List"); } QString trReferencedBy() override { return QCoreApplication::translate("doxy-text", "Referenced by"); } QString trRemarks() override { return QCoreApplication::translate("doxy-text", "Remarks"); } QString trAttention() override { return QCoreApplication::translate("doxy-text", "Attention"); } QString trInclByDepGraph() override { return QCoreApplication::translate("doxy-text", "This graph shows which files " "directly or indirectly include this file"); } QString trSince() override { return QCoreApplication::translate("doxy-text", "Since"); } /*! title of the graph legend page */ QString trLegendTitle() override { return QCoreApplication::translate("doxy-text", "Graph Legend"); } /*! page explaining how the dot graph's should be interpreted * The %A in the translated text are to prevent link to classes called "A". */ QString trLegendDocs(const QString &dotFormat) override { return QCoreApplication::translate("doxy-text", "Dot Graph legend source code").formatArg(dotFormat); } /*! text for the link to the legend page */ QString trLegend() override { return QCoreApplication::translate("doxy-text", "legend"); } /*! Used as a marker that is put before a test item */ QString trTest() override { return QCoreApplication::translate("doxy-text", "Test"); } /*! Used as the header of the test list */ QString trTestList() override { return QCoreApplication::translate("doxy-text", "Test List"); } /*! Used as a section header for IDL properties */ QString trProperties() override { return QCoreApplication::translate("doxy-text", "Properties"); } /*! Used as a section header for IDL property documentation */ QString trPropertyDocumentation() override { return QCoreApplication::translate("doxy-text", "Property Documentation"); } /*! Used for Java classes in the summary section of Java packages */ QString trClasses() override { if (Config::getBool("optimize-c")) { return QCoreApplication::translate("doxy-text", "Data Structures", "trClasses"); } else { return QCoreApplication::translate("doxy-text", "Classes", "trClasses"); } } /*! Used as the title of a Java package */ QString trPackage(const QString &name) override { return QCoreApplication::translate("doxy-text", "Package %1").formatArg(name); } /*! Title of the package index page */ QString trPackageList() override { return QCoreApplication::translate("doxy-text", "Package List"); } /*! The description of the package index page */ QString trPackagesListDescription() override { return QCoreApplication::translate("doxy-text", "Here are the packages with " "brief descriptions (if available):"); } /*! The link name in the Quick links header for each page */ QString trPackages() override { return QCoreApplication::translate("doxy-text", "Packages"); } /*! Text shown before a multi-line define */ QString trDefineValue() override { return QCoreApplication::translate("doxy-text", "Value:"); } /*! Used as a marker that is put before a \\bug item */ QString trBug() override { return QCoreApplication::translate("doxy-text", "Bug"); } /*! Used as the header of the bug list */ QString trBugList() override { return QCoreApplication::translate("doxy-text", "Bug List"); } /*! Used as ansi cpg for RTF file * * The following table shows the correlation of Charset name, Charset Value and * <pre> * Codepage number: * Charset Name Charset Value(hex) Codepage number * ------------------------------------------------------ * DEFAULT_CHARSET 1 (x01) * SYMBOL_CHARSET 2 (x02) * OEM_CHARSET 255 (xFF) * ANSI_CHARSET 0 (x00) 1252 * RUSSIAN_CHARSET 204 (xCC) 1251 * EE_CHARSET 238 (xEE) 1250 * GREEK_CHARSET 161 (xA1) 1253 * TURKISH_CHARSET 162 (xA2) 1254 * BALTIC_CHARSET 186 (xBA) 1257 * HEBREW_CHARSET 177 (xB1) 1255 * ARABIC _CHARSET 178 (xB2) 1256 * SHIFTJIS_CHARSET 128 (x80) 932 * HANGEUL_CHARSET 129 (x81) 949 * GB2313_CHARSET 134 (x86) 936 * CHINESEBIG5_CHARSET 136 (x88) 950 * </pre> * */ QString trRTFansicp() override { return QCoreApplication::translate("doxy-rtf", "1252", "trRTFansicp"); } /*! Used as ansicpg for RTF fcharset * \see trRTFansicp() for a table of possible values. */ QString trRTFCharSet() override { return QCoreApplication::translate("doxy-rtf", "0", "trRTFCharSet"); } /*! Used as header RTF general index */ QString trRTFGeneralIndex() override { return QCoreApplication::translate("doxy-text", "Index"); } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names of the category. */ QString trClass(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Class", "trClass"); } else { return QCoreApplication::translate("doxy-text", "Classes", "trClass"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "class", "trClass"); } else { return QCoreApplication::translate("doxy-text", "classes", "trClass"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trFile(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "File"); } else { return QCoreApplication::translate("doxy-text", "Files"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "file"); } else { return QCoreApplication::translate("doxy-text", "files"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trNamespace(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Namespace", "trNamespace"); } else { return QCoreApplication::translate("doxy-text", "Namespaces", "trNamespace"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "namespace", "trNamespace"); } else { return QCoreApplication::translate("doxy-text", "namespaces", "trNamespace"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names of the category. */ QString trGroup(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Module", "trGroup"); } else { return QCoreApplication::translate("doxy-text", "Modules", "trGroup"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "module", "trGroup"); } else { return QCoreApplication::translate("doxy-text", "modules", "trGroup"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names of the category. */ QString trPage(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Page"); } else { return QCoreApplication::translate("doxy-text", "Pages"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "page"); } else { return QCoreApplication::translate("doxy-text", "pages"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trMember(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Member"); } else { return QCoreApplication::translate("doxy-text", "Members"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "member"); } else { return QCoreApplication::translate("doxy-text", "members"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trGlobal(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Global", "trGlobal"); } else { return QCoreApplication::translate("doxy-text", "Globals", "trGlobal"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "global", "trGlobal"); } else { return QCoreApplication::translate("doxy-text", "globals", "trGlobal"); } } } /*! This text is generated when the \\author command is used and * for the author section in man pages. */ QString trAuthor(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Author", "trAuthor"); } else { return QCoreApplication::translate("doxy-text", "Authors", "trAuthor");; } } else { if (singular) { return QCoreApplication::translate("doxy-text", "author", "trAuthor"); } else { return QCoreApplication::translate("doxy-text", "authors", "trAuthor"); } } } // this text is put before the list of members referenced by a member QString trReferences() override { return QCoreApplication::translate("doxy-text", "References"); } // used in member documentation to produce a list of members which are implemented by this one QString trImplementedFromList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Implements %1").formatArg(trWriteList(numEntries)); } // used in member documentation to produce a list of all members which implement this abstract member QString trImplementedInList(int numEntries) override { return QCoreApplication::translate("doxy-text", "Implemented in %1").formatArg(trWriteList(numEntries)); } // used in RTF documentation as a heading for the Table of Contents QString trRTFTableOfContents() override { return QCoreApplication::translate("doxy-text", "Table of Contents"); } // Used as the header of the list of item that have been flagged deprecated QString trDeprecatedList() override { return QCoreApplication::translate("doxy-text", "Deprecated List"); } // Used as a header for declaration section of the events found in a C# program QString trEvents() override { return QCoreApplication::translate("doxy-text", "Events"); } /*! Header used for the documentation section of a class' events. */ QString trEventDocumentation() override { return QCoreApplication::translate("doxy-text", "Event Documentation"); } /*! Used as a heading for a list of Java class functions with package * scope. */ QString trPackageMembers() override { return QCoreApplication::translate("doxy-text", "Package Functions"); } /*! Used as a heading for a list of static Java class functions with * package scope. */ QString trStaticPackageMembers() override { return QCoreApplication::translate("doxy-text", "Static Package Functions"); } /*! Used as a heading for a list of Java class variables with package * scope. */ QString trPackageAttribs() override { return QCoreApplication::translate("doxy-text", "Package Attributes"); } /*! Used as a heading for a list of static Java class variables with * package scope. */ QString trStaticPackageAttribs() override { return QCoreApplication::translate("doxy-text", "Static Package Attributes"); } /*! Used in the quick index of a class/file/namespace member list page * to link to the unfiltered list of all members. */ QString trAll() override { return QCoreApplication::translate("doxy-text", "All"); } /*! Put in front of the call graph for a function. */ QString trCallGraph() override { return QCoreApplication::translate("doxy-text", "Here is the call graph for this function:"); } /*! This string is used as the title for the page listing the search * results. */ QString trSearchResultsTitle() override { return QCoreApplication::translate("doxy-text", "Search Results"); } /*! This string is put just before listing the search results. The * text can be different depending on the number of documents found. * Inside the text you can put the special marker $num to insert * the number representing the actual number of search results. * The @a numDocuments parameter can be either 0, 1 or 2, where the * value 2 represents 2 or more matches. HTML markup is allowed inside * the returned string. */ QString trSearchResults(int numDocuments) override { if (numDocuments == 0) { return QCoreApplication::translate("doxy-text", "Sorry, no documents matching your query."); } else if (numDocuments == 1) { return QCoreApplication::translate("doxy-text", "Found <b>1</b> document matching your query."); } else { return QCoreApplication::translate("doxy-text", "Found <b>$num</b> documents matching your query. " "Showing best matches first."); } } /*! This string is put before the list of matched words, for each search * result. What follows is the list of words that matched the query. */ QString trSearchMatches() override { return QCoreApplication::translate("doxy-text", "Matches:"); } /*! This is used in HTML as the title of page with source code for file filename */ QString trSourceFile(const QString &filename) override { return QCoreApplication::translate("doxy-text", "%1 Source File").formatArg(filename); } /*! This is used as the name of the chapter containing the directory * hierarchy. */ QString trDirIndex() override { return QCoreApplication::translate("doxy-text", "Directory Hierarchy"); } /*! This is used as the name of the chapter containing the documentation * of the directories. */ QString trDirDocumentation() override { return QCoreApplication::translate("doxy-text", "Directory Documentation"); } /*! This is used as the title of the directory index and also in the * Quick links of an HTML page, to link to the directory hierarchy. */ QString trDirectories() override { return QCoreApplication::translate("doxy-text", "Directories"); } /*! This returns a sentences that introduces the directory hierarchy. * and the fact that it is sorted alphabetically per level */ QString trDirDescription() override { return QCoreApplication::translate("doxy-text", "This directory hierarchy is sorted roughly, " "but not completely, alphabetically:"); } /*! This returns the title of a directory page. The name of the directory is passed via dirName. */ QString trDirReference(const QString &dirName) override { return QCoreApplication::translate("doxy-text", "%1 Directory Reference").formatArg(dirName); } /*! returns the word directory with or without starting capital letter, in sigular or plural form. */ QString trDir(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Directory"); } else { return QCoreApplication::translate("doxy-text", "Directories"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "directory"); } else { return QCoreApplication::translate("doxy-text", "directories"); } } } /*! This text is added to the documentation when the \\overload command * is used for a overloaded function. */ QString trOverloadText() override { return QCoreApplication::translate("doxy-text", "This is an overloaded method or function provided for " "convenience. It differs from the other overloads only in the argument(s)."); } /*! This is used to introduce a caller (or called-by) graph */ QString trCallerGraph() override { return QCoreApplication::translate("doxy-text", "Here is the caller graph for this function:"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for enumeration values */ QString trEnumerationValueDocumentation() override { return QCoreApplication::translate("doxy-text", "Enumerator Documentation"); } /*! header that is put before the list of member subprograms (Fortran). */ QString trMemberFunctionDocumentationFortran() override { return QCoreApplication::translate("doxy-text", "Member Function/Subroutine Documentation"); } /*! This is put above each page as a link to the list of annotated data types (Fortran). */ QString trCompoundListFortran() override { return QCoreApplication::translate("doxy-text", "Data Types List"); } /*! This is put above each page as a link to all members of compounds (Fortran). */ QString trCompoundMembersFortran() override { return QCoreApplication::translate("doxy-text", "Data Fields", "trCompoundMembersFortran"); } /*! This is an introduction to the annotated compound list (Fortran). */ QString trCompoundListDescriptionFortran() override { return QCoreApplication::translate("doxy-text", "Here are the data types with brief descriptions:"); } /*! This is an introduction to the page with all data types (Fortran). */ QString trCompoundMembersDescriptionFortran(bool extractAll) override { QString result; if (extractAll) { result = QCoreApplication::translate("doxy-text", "Here is a list of all data types " "members with links to the data types they belong to:"); } else { result = QCoreApplication::translate("doxy-text", "Here is a list of all documented " "data types members with links to the data structure documentation for each member:"); } return result; } /*! This is used in LaTeX as the title of the chapter with the * annotated compound index (Fortran). */ QString trCompoundIndexFortran() override { return QCoreApplication::translate("doxy-text", "Data Type Index"); } /*! This is used in LaTeX as the title of the chapter containing * the documentation of all data types (Fortran). */ QString trTypeDocumentation() override { return QCoreApplication::translate("doxy-text", "Data Type Documentation"); } /*! This is used in the documentation of a file as a header before the * list of (global) subprograms (Fortran). */ QString trSubprograms() override { return QCoreApplication::translate("doxy-text", "Functions/Subroutines"); } /*! This is used in the documentation of a file/namespace before the list * of documentation blocks for subprograms (Fortran) */ QString trSubprogramDocumentation() override { return QCoreApplication::translate("doxy-text", "Function/Subroutine Documentation"); } /*! This is used in the documentation of a file/namespace/group before * the list of links to documented compounds (Fortran) */ QString trDataTypes() override { return QCoreApplication::translate("doxy-text", "Data Types"); } /*! used as the title of page containing all the index of all modules (Fortran). */ QString trModulesList() override { return QCoreApplication::translate("doxy-text", "Modules List"); } /*! used as an introduction to the modules list (Fortran) */ QString trModulesListDescription(bool extractAll) override { if (extractAll) { return QCoreApplication::translate("doxy-text", "Here is a list of all modules with brief descriptions:"); } else { return QCoreApplication::translate("doxy-text", "Here is a list of all documented modules with brief descriptions:"); } } /*! used as the title of the HTML page of a module/type (Fortran) */ QString trCompoundReferenceFortran(const QString &clName, enum CompoundType compType,bool isTemplate) override { QString result; switch (compType) { case CompoundType::Class: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Module Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Module Reference").formatArg(clName); } break; case CompoundType::Struct: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Type Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Type Reference").formatArg(clName); } break; case CompoundType::Union: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Union Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Union Reference").formatArg(clName); } break; case CompoundType::Interface: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Interface Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Interface Reference").formatArg(clName); } break; case CompoundType::Protocol: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Protocol Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Protocol Reference").formatArg(clName); } break; case CompoundType::Category: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Category Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Category Reference").formatArg(clName); } break; case CompoundType::Exception: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Exception Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Exception Reference").formatArg(clName); } break; default: if (isTemplate) { result = QCoreApplication::translate("doxy-text", "%1 Template Reference").formatArg(clName); } else { result = QCoreApplication::translate("doxy-text", "%1 Reference").formatArg(clName); } break; } return result; } /*! used as the title of the HTML page of a module (Fortran) */ QString trModuleReference(const QString &namespaceName) override { return QCoreApplication::translate("doxy-text", "%1 Module Reference").formatArg(namespaceName); } /*! This is put above each page as a link to all members of modules. (Fortran) */ QString trModuleMembers() override { return QCoreApplication::translate("doxy-text", "Module Members"); } /*! This is an introduction to the page with all modules members (Fortran) */ QString trModulesMemberDescription(bool extractAll) override { if (extractAll) { return QCoreApplication::translate("doxy-text", "Here is a list of all module members with links " "to the module documentation for each member:"); } else { return QCoreApplication::translate("doxy-text", "Here is a list of all documented module members " "with links to the modules they belong to:"); } } /*! This is used in LaTeX as the title of the chapter with the * index of all modules (Fortran). */ QString trModulesIndex() override { return QCoreApplication::translate("doxy-text", "Modules Index", "trModulesIndex"); } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names of the category. */ QString trModule(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Module", "trModule"); } else { return QCoreApplication::translate("doxy-text", "Modules", "trModule"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "module", "trModule"); } else { return QCoreApplication::translate("doxy-text", "modules", "trModule"); } } } /*! This is put at the bottom of a module documentation page and is * followed by a list of files that were used to generate the page. */ QString trGeneratedFromFilesFortran(enum CompoundType compType, bool single) override { QString result; switch (compType) { case CompoundType::Class: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this module was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this module was generated from " "the following files:"); } break; case CompoundType::Struct: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this type was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this type was generated from " "the following files:"); } break; case CompoundType::Union: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this union was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this union was generated from " "the following files:"); } break; case CompoundType::Interface: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this interface was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this interface was generated from " "the following files:"); } break; case CompoundType::Protocol: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this protocol was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this protocol was generated from " "the following files:"); } break; case CompoundType::Category: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this category was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this category was generated from " "the following files:"); } break; case CompoundType::Exception: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this exception was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this exception was generated from " "the following files:"); } break; default: if (single) { result = QCoreApplication::translate("doxy-text", "The documentation for this was generated from " "the following file:"); } else { result = QCoreApplication::translate("doxy-text", "The documentation for this was generated from " "the following files:"); } break; } return result; } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trType(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Type"); } else { return QCoreApplication::translate("doxy-text", "Types"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "type"); } else { return QCoreApplication::translate("doxy-text", "types"); } } } /*! This is used for translation of the word that will possibly * be followed by a single name or by a list of names * of the category. */ QString trSubprogram(bool first_capital, bool singular) override { if (first_capital) { if (singular) { return QCoreApplication::translate("doxy-text", "Subprogram"); } else { return QCoreApplication::translate("doxy-text", "Subprograms"); } } else { if (singular) { return QCoreApplication::translate("doxy-text", "subprogram"); } else { return QCoreApplication::translate("doxy-text", "subprograms"); } } } /*! C# Type Constraint list */ QString trTypeConstraints() override { return QCoreApplication::translate("doxy-text", "Type Constraints"); } /*! directory relation for name */ QString trDirRelation(const QString &name) override { return QCoreApplication::translate("doxy-text", "%1 Relation").formatArg(name); } /*! Loading message shown when loading search results */ QString trLoading() override { return QCoreApplication::translate("doxy-text", "Loading..."); } /*! Label used for search results in the global namespace */ QString trGlobalNamespace() override { return QCoreApplication::translate("doxy-text", "Global Namespace"); } /*! Message shown while searching */ QString trSearching() override { return QCoreApplication::translate("doxy-text", "Searching..."); } /*! Text shown when no search results are found */ QString trNoMatches() override { return QCoreApplication::translate("doxy-text", "No Matches"); } /*! when clicking a directory dependency label, a page with a * table is shown. The heading for the first column mentions the * source file that has a relation to another file. */ QString trFileIn(const QString &name) override { return QCoreApplication::translate("doxy-text", "File in %1").formatArg(name); } /*! when clicking a directory dependency label, a page with a * table is shown. The heading for the second column mentions the * destination file that is included. */ QString trIncludesFileIn(const QString &name) override { return QCoreApplication::translate("doxy-text", "Includes file in %1").formatArg(name); } /*! Header for the page with bibliographic citations */ QString trCiteReferences() override { return QCoreApplication::translate("doxy-text", "Bibliography"); } /*! Text for copyright paragraph */ QString trCopyright() override { return QCoreApplication::translate("doxy-text", "Copyright"); } /*! Header for the graph showing the directory dependencies */ QString trDirDepGraph(const QString &name) override { return QCoreApplication::translate("doxy-text", "Directory dependency graph for %1:").formatArg(name); } /*! Detail level selector shown for hierarchical indices */ QString trDetailLevel() override { return QCoreApplication::translate("doxy-text", "detail level"); } /*! Section header for list of template parameters */ QString trTemplateParameters() override { return QCoreApplication::translate("doxy-text", "Template Parameters"); } /*! Used in dot graph when UML_LOOK is enabled and there are many fields */ QString trAndMore(const QString &number) override { return QCoreApplication::translate("doxy-text", "and %1 more...").formatArg(number); } /*! Used file list for a Java enum */ QString trEnumGeneratedFromFiles(bool single) override { if (single) { return QCoreApplication::translate("doxy-text", "The documentation for this enum was generated " "from the following file:"); } else { return QCoreApplication::translate("doxy-text", "The documentation for this enum was generated " " from the following files:"); } } /*! Header of a Java enum page (Java enums are represented as classes). */ QString trEnumReference(const QString &name) override { return QCoreApplication::translate("doxy-text", "%1 Enum Reference").formatArg(name); } /*! Used for a section containing inherited members */ QString trInheritedFrom(const QString &members, const QString &what) override { return QCoreApplication::translate("doxy-text", "%1 inherited from %2").formatArg(members).formatArg(what); } /*! Header of the sections with inherited members specific for the base class(es) */ QString trAdditionalInheritedMembers() override { return QCoreApplication::translate("doxy-text", "Additional Inherited Members"); } /*! Used as a tooltip for the toggle button that appears in the * navigation tree in the HTML output when GENERATE_TREEVIEW is * enabled. This tooltip explains the meaning of the button. */ QString trPanelSyncTooltip(bool enable) override { if (enable) { return QCoreApplication::translate("doxy-text", "click to enable panel synchronization"); } else { return QCoreApplication::translate("doxy-text", "click to disable panel synchronization"); } } /*! Used in a method of an Objective-C class that is declared in a * a category. Note that the @1 marker is required and is replaced * by a link. */ QString trProvidedByCategory() override { return QCoreApplication::translate("doxy-text", "Provided by category @0."); } /*! Used in a method of an Objective-C category that extends a class. * Note that the @1 marker is required and is replaced by a link to * the class method. */ QString trExtendsClass() override { return QCoreApplication::translate("doxy-text", "Extends class @0"); } /*! header of a list of class methods in Objective-C. * similar to static public member functions in C++. */ QString trClassMethods() override { return QCoreApplication::translate("doxy-text", "Class Methods"); } /*! header of a list of instance methods in Objective-C. * similar to public member functions in C++. */ QString trInstanceMethods() override { return QCoreApplication::translate("doxy-text", "Instance Methods"); } /*! Used as the header of the member functions of an Objective-C class. */ QString trMethodDocumentation() override { return QCoreApplication::translate("doxy-text", "Method Documentation"); } /** old style UNO IDL services: implemented interfaces */ QString trInterfaces() override { return QCoreApplication::translate("doxy-text", "Exported Interfaces"); } /** old style UNO IDL services: inherited services */ QString trServices() override { return QCoreApplication::translate("doxy-text", "Included Services"); } /** UNO IDL constant groups */ QString trConstantGroups() override { return QCoreApplication::translate("doxy-text", "Constant Groups"); } /** UNO IDL constant groups */ QString trConstantGroupReference(const QString &namespaceName) override { return QCoreApplication::translate("doxy-text", "%1 Constant Group Reference").formatArg(namespaceName); } /** UNO IDL service page title */ QString trServiceReference(const QString &sName) override { return QCoreApplication::translate("doxy-text", "%1 Service Reference").formatArg(sName); } /** UNO IDL singleton page title */ QString trSingletonReference(const QString &sName) override { return QCoreApplication::translate("doxy-text", "%1 Singleton Reference").formatArg(sName); } /** UNO IDL service page */ QString trServiceGeneratedFromFiles(bool single) override { if (single) { return QCoreApplication::translate("doxy-text", "The documentation for this service " "was generated from the following file:"); } else { return QCoreApplication::translate("doxy-text", "The documentation for this service " "was generated from the following files:"); } } /** UNO IDL singleton page */ QString trSingletonGeneratedFromFiles(bool single) override { if (single) { return QCoreApplication::translate("doxy-text", "The documentation for this singleton " "was generated from the following file:"); } else { return QCoreApplication::translate("doxy-text", "The documentation for this singleton " "was generated from the following files:"); } } }; #endif
80,114
C++
.h
1,754
38.235462
139
0.656376
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,716
pre.h
copperspice_doxypress/src/pre.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef PRE_H #define PRE_H #include <QString> void initPreprocessor(); void removePreProcessor(); void addSearchDir(const QString &dir); QString preprocessFile(const QString &fileName, const QString &input); void preFreeScanner(); #endif
1,017
C++
.h
26
37.961538
74
0.683891
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,717
rtfgen.h
copperspice_doxypress/src/rtfgen.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef RTFGEN_H #define RTFGEN_H #include <outputgen.h> #include <QFile> /** Generator for RTF output. */ class RTFGenerator : public OutputGenerator { public: RTFGenerator(); void init(); static void writeStyleSheetFile(QFile &f); static void writeExtensionsFile(QFile &file); void enable() override { if (! genStack.isEmpty()) { active = genStack.top(); } else { active = true; } } void disable() override { active = false; } void enableIf(OutputType o) override { if (o == RTF) { enable(); } } void disableIf(OutputType o) override { if (o == RTF) { disable(); } } void disableIfNot(OutputType o) override { if (o != RTF) { disable(); } } bool isEnabled(OutputType o) override { return (o == RTF && active); } OutputGenerator *get(OutputType o) override { return (o == RTF) ? this : nullptr; } void writeDoc(DocNode *, QSharedPointer<Definition> ctx, QSharedPointer<MemberDef> md) override; void startFile(const QString &name, const QString &manName, const QString &title) override; void writeSearchInfo() override {} void writeFooter(const QString &) override {} void endFile() override; void clearBuffer(); void startIndexSection(IndexSections) override; void endIndexSection(IndexSections) override; void writePageLink(const QString &, bool) override; void startProjectNumber() override; void endProjectNumber() override; void writeStyleInfo(int part) override; void startTitleHead(const QString &) override; void startTitle() override; void endTitleHead(const QString &, const QString &name) override; void endTitle() override {} void newParagraph(); void startParagraph(const QString &className) override; void endParagraph() override; void writeString(const QString &text) override; void startIndexListItem() override; void endIndexListItem() override; void startIndexList() override; void endIndexList() override; void startIndexKey() override; void endIndexKey() override; void startIndexValue(bool) override; void endIndexValue(const QString &, bool) override; void startItemList() override; void endItemList() override; void startIndexItem(const QString &ref, const QString &file) override; void endIndexItem(const QString &ref, const QString &file) override; void docify(const QString &text) override; void codify(const QString &text) override; void writeObjectLink(const QString &ref, const QString &file, const QString &anchor, const QString &name) override; void writeCodeLink(const QString &ref, const QString &file, const QString &anchor, const QString &name, const QString &tooltip) override; void writeTooltip(const QString &, const DocLinkInfo &, const QString &, const QString &, const SourceLinkInfo &, const SourceLinkInfo & ) override {} void startTextLink(const QString &f, const QString &anchor) override; void endTextLink() override; void startHtmlLink(const QString &url) override; void endHtmlLink() override; void startTypewriter() override { m_textStream << "{\\f2 "; } void endTypewriter() override { m_textStream << "}"; } void startGroupHeader(int) override; void endGroupHeader(int) override; void startItemListItem() override; void endItemListItem() override; void startMemberSections() override { } void endMemberSections() override { } void startHeaderSection() override { } void endHeaderSection() override { } void startMemberHeader(const QString &, int) override { startGroupHeader(false); } void endMemberHeader() override { endGroupHeader(false); } void startMemberSubtitle() override; void endMemberSubtitle() override; void startMemberDocList() override {} void endMemberDocList() override {} void startMemberList() override; void endMemberList() override; void startInlineHeader() override; void endInlineHeader() override; void startAnonTypeScope(int) override {} void endAnonTypeScope(int) override {} void startMemberItem(const QString &, int, const QString &, bool deprecated = false) override; void endMemberItem() override; void startMemberTemplateParams() override {} void endMemberTemplateParams(const QString &, const QString &) override {} void insertMemberAlign(bool) override {} void insertMemberAlignLeft(int, bool) override {} void writeRuler() override { rtfwriteRuler_thin(); } void writeAnchor(const QString &fileName, const QString &name) override; void startCodeFragment(const QString &style) override; void endCodeFragment(const QString &style) override; void writeLineNumber(const QString &, const QString &fileName, const QString &, int line) override; void startCodeLine(bool) override; void endCodeLine() override; void startEmphasis() override { m_textStream << "{\\i "; } void endEmphasis() override { m_textStream << "}"; } void startBold() override { m_textStream << "{\\b "; } void endBold() override { m_textStream << "}"; } void startDescription() override; void endDescription() override; void startDescItem() override; void endDescItem() override; void lineBreak(const QString &style = QString()) override; void startMemberDoc(const QString &clName, const QString &memName, const QString &anchor, const QString &title, int memCount, int memTotal, bool showInline) override; void endMemberDoc(bool) override; void startDoxyAnchor(const QString &, const QString &, const QString &, const QString &, const QString &) override; void endDoxyAnchor(const QString &, const QString &) override; void writeChar(char c) override; void writeLatexSpacing() override {}; void writeStartAnnoItem(const QString &type, const QString &file, const QString &path, const QString &name) override; void writeEndAnnoItem(const QString &name) override; void startSubsection() override; void endSubsection() override; void startSubsubsection() override; void endSubsubsection() override; void startCenter() override { m_textStream << "{\\qc" << endl; } void endCenter() override { m_textStream << "}"; } void startSmall() override { m_textStream << "{\\sub "; } void endSmall() override { m_textStream << "}"; } void startMemberDescription(const QString &, const QString &, bool) override; void endMemberDescription() override; void startMemberDeclaration() override {} void endMemberDeclaration(const QString &, const QString &) override {} void writeInheritedSectionTitle(const QString &, const QString &, const QString &, const QString &, const QString &, const QString &) override {} void startDescList(SectionTypes); void startSimpleSect(SectionTypes, const QString &, const QString &, const QString &) override; void endSimpleSect() override; void startParamList(ParamListTypes, const QString &) override; void endParamList() override; //void writeDescItem(); void startDescForItem() override; void endDescForItem() override; void startSection(const QString &, const QString &, SectionInfo::SectionType) override; void endSection(const QString &, SectionInfo::SectionType) override; void addIndexItemName(const QString &, const QString &) override; void startIndent() override; void endIndent() override; void writeSynopsis() override {} void startClassDiagram() override; void endClassDiagram(const ClassDiagram &, const QString &filename, const QString &name) override; void startPageRef() override; void endPageRef(const QString &, const QString &) override; void startQuickIndices() override {} void endQuickIndices() override {} void writeSplitBar(const QString &) override {} void writeNavigationPath(const QString &) override {} void writeLogo() override {} void writeQuickLinks(bool, HighlightedItem, const QString &) override {} void writeSummaryLink(const QString &, const QString &, const QString &, bool) override {} void startContents() override {} void endContents() override {} void writeNonBreakableSpace(int) override; void startEnumTable() override; void endEnumTable() override; void startDescTable(const QString &title) override; void endDescTable() override; void startDescTableRow() override; void endDescTableRow() override; void startDescTableTitle() override; void endDescTableTitle() override; void startDescTableData() override; void endDescTableData() override; void startDotGraph() override; void endDotGraph(const DotClassGraph &) override; void startInclDepGraph() override; void endInclDepGraph(const DotInclDepGraph &) override; void startGroupCollaboration() override; void endGroupCollaboration(const DotGroupCollaboration &g) override; void startCallGraph() override; void endCallGraph(const DotCallGraph &) override; void startDirDepGraph() override; void endDirDepGraph(const DotDirDeps &g) override; void writeGraphicalHierarchy(const DotGfxHierarchyTable &) override { } void startMemberGroupHeader(bool) override; void endMemberGroupHeader() override; void startMemberGroupDocs() override; void endMemberGroupDocs() override; void startMemberGroup() override; void endMemberGroup(bool) override; void startTextBlock(bool dense) override; void endTextBlock(bool) override; void lastIndexPage() override; void startMemberDocPrefixItem() override {} void endMemberDocPrefixItem() override {} void startMemberDocName(bool) override {} void endMemberDocName() override {} void startParameterType(bool, const QString &) override; void endParameterType() override; void startParameterName(bool) override {} void endParameterName(bool, bool, bool) override{} void startParameterList(bool) override {} void endParameterList() override {} void exceptionEntry(const QString &, bool) override; void startConstraintList(const QString &) override; void startConstraintParam() override; void endConstraintParam() override; void startConstraintType() override; void endConstraintType() override; void startConstraintDocs() override; void endConstraintDocs() override; void endConstraintList() override; void startMemberDocSimple(bool isEnum) override; void endMemberDocSimple(bool isEnum) override; void startInlineMemberType() override; void endInlineMemberType() override; void startInlineMemberName() override; void endInlineMemberName() override; void startInlineMemberDoc() override; void endInlineMemberDoc() override; void startLabels() override; void writeLabel(const QString &l, bool isLast) override; void endLabels() override; void startFontClass(const QString &) override; void endFontClass() override; void writeCodeAnchor(const QString &) override {} void setCurrentDoc(QSharedPointer<Definition> def, const QString &, bool) override { (void) def; } void addWord(const QString &word, bool hiPriority) override { (void) word; (void) hiPriority; } static bool preProcessFileInplace(const QString &path, const QString &name); private: RTFGenerator(const RTFGenerator &); RTFGenerator &operator=(const RTFGenerator &); QString rtf_BList_DepthStyle(); QString rtf_CList_DepthStyle(); QString rtf_EList_DepthStyle(); QString rtf_LCList_DepthStyle(); QString rtf_DList_DepthStyle(); QString rtf_Code_DepthStyle(); void incrementIndentLevel(); void decrementIndentLevel(); void beginRTFDocument(); void beginRTFChapter(); void beginRTFSection(); void rtfwriteRuler_doubleline(); void rtfwriteRuler_emboss(); void rtfwriteRuler_thick(); void rtfwriteRuler_thin(); void writeRTFReference(const QString &label); bool m_prettyCode; bool m_bstartedBody; // has startbody been called yet bool m_omitParagraph; // should the next paragraph command be ignored bool m_doxyCodeLineOpen; int m_col; int m_numCols; // number of columns in a table int m_listLevel; // RTF does not really have a additive indent, manually set list level QString relPath; QString m_sourceFileName; }; #endif
13,377
C++
.h
325
36.563077
120
0.725143
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,721
logos.h
copperspice_doxypress/src/logos.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef LOGOS_H #define LOGOS_H #include <QString> extern void writeLogo(const QString &dir); extern void writeSearchButton(const QString &dir); extern void writeDoxFont(const QString &dir); extern void removeDoxFont(const QString &dir); #endif
1,023
C++
.h
25
39.76
74
0.685111
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,722
mandocvisitor.h
copperspice_doxypress/src/mandocvisitor.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef MANDOCVISITOR_H #define MANDOCVISITOR_H #include <docvisitor.h> #include <QStack> #include <QTextStream> class CodeGenerator; /*! @brief Concrete visitor implementation for LaTeX output. */ class ManDocVisitor : public DocVisitor { public: ManDocVisitor(QTextStream &t, CodeGenerator &ci, const QString &langExt); // visitor functions for leaf nodes void visit(DocWord *) override; void visit(DocLinkedWord *) override; void visit(DocWhiteSpace *) override; void visit(DocSymbol *) override; void visit(DocEmoji *) override; void visit(DocURL *) override; void visit(DocLineBreak *) override; void visit(DocHorRuler *) override; void visit(DocStyleChange *) override; void visit(DocVerbatim *) override; void visit(DocAnchor *) override; void visit(DocInclude *) override; void visit(DocIncOperator *) override; void visit(DocFormula *) override; void visit(DocIndexEntry *) override; void visit(DocSimpleSectSep *) override; void visit(DocCite *) override; // visitor functions for compound nodes void visitPre(DocAutoList *) override; void visitPost(DocAutoList *) override; void visitPre(DocAutoListItem *) override; void visitPost(DocAutoListItem *) override; void visitPre(DocPara *) override; void visitPost(DocPara *) override; void visitPre(DocRoot *) override; void visitPost(DocRoot *) override; void visitPre(DocSimpleSect *) override; void visitPost(DocSimpleSect *) override; void visitPre(DocTitle *) override; void visitPost(DocTitle *) override; void visitPre(DocSimpleList *) override; void visitPost(DocSimpleList *) override; void visitPre(DocSimpleListItem *) override; void visitPost(DocSimpleListItem *) override; void visitPre(DocSection *s) override; void visitPost(DocSection *) override; void visitPre(DocHtmlList *s) override; void visitPost(DocHtmlList *s) override; void visitPre(DocHtmlListItem *) override; void visitPost(DocHtmlListItem *) override; //void visitPre(DocHtmlPre *); //void visitPost(DocHtmlPre *); void visitPre(DocHtmlDescList *) override; void visitPost(DocHtmlDescList *) override; void visitPre(DocHtmlDescTitle *) override; void visitPost(DocHtmlDescTitle *) override; void visitPre(DocHtmlDescData *) override; void visitPost(DocHtmlDescData *) override; void visitPre(DocHtmlTable *t) override; void visitPost(DocHtmlTable *t) override; void visitPre(DocHtmlCaption *) override; void visitPost(DocHtmlCaption *) override; void visitPre(DocHtmlRow *) override; void visitPost(DocHtmlRow *) override; void visitPre(DocHtmlCell *) override; void visitPost(DocHtmlCell *) override; void visitPre(DocInternal *) override; void visitPost(DocInternal *) override; void visitPre(DocHRef *) override; void visitPost(DocHRef *) override; void visitPre(DocHtmlHeader *) override; void visitPost(DocHtmlHeader *) override; void visitPre(DocImage *) override; void visitPost(DocImage *) override; void visitPre(DocDotFile *) override; void visitPost(DocDotFile *) override; void visitPre(DocMscFile *) override; void visitPost(DocMscFile *) override; void visitPre(DocDiaFile *) override; void visitPost(DocDiaFile *) override; void visitPre(DocLink *lnk) override; void visitPost(DocLink *) override; void visitPre(DocRef *ref) override; void visitPost(DocRef *) override; void visitPre(DocSecRefItem *) override; void visitPost(DocSecRefItem *) override; void visitPre(DocSecRefList *) override; void visitPost(DocSecRefList *) override; //void visitPre(DocLanguage *); //void visitPost(DocLanguage *); void visitPre(DocParamSect *) override; void visitPost(DocParamSect *) override; void visitPre(DocParamList *) override; void visitPost(DocParamList *) override; void visitPre(DocXRefItem *) override; void visitPost(DocXRefItem *) override; void visitPre(DocInternalRef *) override; void visitPost(DocInternalRef *) override; void visitPre(DocCopy *) override; void visitPost(DocCopy *) override; void visitPre(DocText *) override; void visitPost(DocText *) override; void visitPre(DocHtmlBlockQuote *) override; void visitPost(DocHtmlBlockQuote *) override; void visitPre(DocParBlock *) override; void visitPost(DocParBlock *) override; private: void filter(const QString &str); void pushEnabled(); void popEnabled(); QTextStream &m_t; CodeGenerator &m_ci; bool m_insidePre; bool m_hide; bool m_firstCol; int m_indent; QStack<bool> m_enabled; QString m_langExt; }; #endif
5,465
C++
.h
139
35.81295
76
0.735821
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,724
example.h
copperspice_doxypress/src/example.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef EXAMPLE_H #define EXAMPLE_H #include <QString> /** Data associated with an example. */ struct Example { QString anchor; QString name; QString file; }; #endif
953
C++
.h
27
33.814815
74
0.660521
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,733
a_define.h
copperspice_doxypress/src/a_define.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * Copyright (c) 1997-2014 Dimitri van Heesch * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef A_DEFINE_H #define A_DEFINE_H #include <QHash> class FileDef; /** A class representing a macro definition. */ class A_Define { public: A_Define(); A_Define(const A_Define &d) = delete; A_Define(A_Define &&d) = delete; A_Define &operator=(const A_Define &d) = delete; A_Define &operator=(A_Define &&d) = delete; bool hasDocumentation(); QString m_name; QString m_definition; QString m_fileName; QString doc; QString brief; QString args; QString anchor; QSharedPointer<FileDef> fileDef; int lineNr; int columnNr; int nargs; bool undef; bool varArgs; bool isPredefined; bool nonRecursive; }; /** An unsorted dictionary of A_Define objects. */ using DefineDict = QHash<QString, QSharedPointer<A_Define>>; // only used in pre.cpp (lex code) #endif
1,618
C++
.h
50
29.8
100
0.669241
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,737
enum.h
copperspice_doxypress/test_build/input_test/commands/enum.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ /// Class documentation is from the DoxyPress documentation class test_Enum { public: enum fruit { pear, orange }; /*! Another enum, with inline docs */ enum veggies { celery, /*!< docs for value one */ carrot /*!< docs for value two */ }; /// Documentation for the Cajun Spices enum enum class CajunSpices { hungarian_paprika, hot_paprika, oregano, thyme }; /// Documentation for the Moroccan Spices enum enum class MoroccanSpices { allspice, cinnamon, ginger, red_pepper, ///< Using New Mexico red peppers gives a better flavor thyme }; }; /*! \class test_Enum * The class description. */ /*! \enum test_Enum::fruit * A description of the fruit enum. */ /*! \var test_Enum::fruit test_Enum::pear * Description of the first fruit which is a pear. */ /*! \var test_Enum::CajunSpices test_Enum::thyme * Use dried thyme */ /*! \var test_Enum::MoroccanSpices test_Enum::MoroccanSpices::thyme * Use French thyme if available */ /*! \var test_Enum::MoroccanSpices test_Enum::MoroccanSpices::thyme * MORE Docs for Thyme */ /*! \var test_Enum::MoroccanSpices thyme * Use French thyme - Syntax not allow (A) */ /*! \var test_Enum thyme * Use French thyme - Syntax not allow (B) */
2,060
C++
.h
67
27.61194
77
0.65213
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,738
test_cmd.h
copperspice_doxypress/test_build/input_test/commands/test_cmd.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ /** * @file test_cmd.h * @author Barbara Geller * @date March 14 2017 * @brief This file contains samples of DoxyPress commands. * * \version 1.2.3.4 * \copyright GNU Public License * * \example test_cmd_example.h * */ /** Documentation for test_Commands goes here */ class test_Commands { private: int size; };
1,055
C++
.h
34
29.617647
74
0.660433
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,739
version.h
copperspice_doxypress/test_build/input_test/api/version.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef VERSION_H #define VERSION_H namespace my_library { namespace v1 { /// Documentation for function my_library::v1::seed. If no docs are desired for /// the older version, just leave off this comment. void seed(int value) { // does nothing } } inline namespace v2 { /// Documentation for function my_library::v2::seed. This method is located inside an inline namespace. void seed(int value) { // does nothing } } }
1,229
C++
.h
36
30.916667
109
0.638119
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,741
qstring8.h
copperspice_doxypress/test_build/input_test/api/qstring8.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef QSTRING8_H #define QSTRING8_H #include <cs_string.h> #include <qglobal.h> class QString8 { public: QString8() = default; QString8(const QString8 &other) = delete; QString8(QString8 &&other) = default; QString8::QString8 ( QChar32 c ); // methods void clear(); bool endsWith(const QString8 &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; bool isEmpty() const; QString8 left(size_type numOfChars) const; QString8 leftJustified(size_type width, QChar32 fill = UCHAR(' '), bool trunc = false) const; bool startsWith(const QString8 &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; void truncate(size_type length); // operators QString8 &operator=(const QString8 &other) = default; QString8 &operator=(QString8 && other) = default; QString8 &operator=(QChar32 c); QString8 &operator+=(QChar32 c); QString8 &operator+=(QChar32::SpecialCharacter c); QString8 &operator+= (const QString8 & other); QChar32 operator[](size_type index) const; // test for nested class class EmptyClass{ }; }; #endif
1,894
C++
.h
47
36.06383
99
0.660656
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,743
qmap.h
copperspice_doxypress/test_build/input_test/api/qmap.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef QMAP_H #define QMAP_H #include <qglobal.h> #include <qstring8.h> #include <map> template <typename Key, typename Val, typename C> class QMap { public: QMap() = default; QMap(const QMap<Key, Val, C> &other) = default; QMap(QMap<Key, Val, C> &&other) = default; explicit QMap(const std::map<Key, Val, C> &other) : m_data(other) {} ~QMap() = default; // methods void clear() { m_data.clear(); } bool contains(const Key &key) const { return m_data.find(key) != m_data.end(); } private: std::map<Key, Val, C> m_data; }; #endif
1,374
C++
.h
42
29.095238
74
0.610144
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,744
qglobal.h
copperspice_doxypress/test_build/input_test/api/qglobal.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef QGLOBAL_H #define QGLOBAL_H #define Q_CORE_EXPORT #define Q_INLINE_TEMPLATE inline #define Q_REQUIRED_RESULT #endif
857
C++
.h
22
37.863636
74
0.661465
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,745
file_floor_two.h
copperspice_doxypress/test_build/input_test/api/level_2/file_floor_two.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef Floor_Two_H #define Floor_Two_H class FloorTwo { public: int dummy; } #endif
827
C++
.h
24
32.916667
74
0.64375
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,746
file_floor_three.h
copperspice_doxypress/test_build/input_test/api/level_2/level_3/file_floor_three.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef Floor_Three_H #define Floor_Three_H class FloorThree { public: int dummy; } #endif
833
C++
.h
24
33.166667
74
0.646402
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,749
test_group3.h
copperspice_doxypress/test_build/input_test/extended/test_group3.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef INCLUDED_MYCLASS #define INCLUDED_MYCLASS class test_Group3 { public: /** comment A */ std::string getSomething_A(void) const; /** comment C */ bool isEnglish_C(void) const; /** * This is the comment for setX_NoGrouping. * @param bmyflag This method should not be part of group two */ void setX_NoGrouping(const bool bmyflag); void setSomethingElse_D(SomethingElse *somethingElse) { } SomethingElse * getSomethingElse_B(void) const { return 0; } /** @name Group 1 * The following one method is in group one */ ///@{ virtual void setStatusFlag (const std::string &f); ///@} /** @name Group 2 * The following four methods are in group two */ ///@{ ClassOne& toString(ClassOne &c) const; const ClassTwo& getClassTwo(void) const; void updateClassThree(const ClassThree *object) {} void getStuff(ClassFour &four, ClassFive *five) const; ///@} }; #endif
1,784
C++
.h
49
31.428571
74
0.622029
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,751
test_brief.h
copperspice_doxypress/test_build/input_test/extended/test_brief.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ class test_Brief { public: test_Brief(); void myMethod1(); void myMethod2(); };
831
C++
.h
23
34.173913
74
0.629492
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,752
test_parameters.h
copperspice_doxypress/test_build/input_test/extended/test_parameters.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef test_Parameters_h #define test_Parameters_h /** \class test_Parameters * \brief This is the brief description for the class test_Parameters. */ class test_Parameters { public: /** * Returns TRUE if blah * @param param1 the date to check * @param param2 the param2 string * @param param3 the param3 object * @param param4 the param4 details * @param param5 the param5 information. * @param param6 the param6 documentation * @return Returns TRUE if blah * * Pure-virtual method used to blah */ virtual RWBoolean doWork(const RWDate &param1, const RWCString &param2, const RWCString *param3, const RWBoolean param4, const RWBoolean param5, const RWBoolean param6) const = 0; }; #endif
1,502
C++
.h
40
34.5
100
0.671929
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,753
user_a.h
copperspice_doxypress/test_build/input_test/extended/user_a.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef INCLUDE_USER_DUPLICATE #define INCLUDE_USER_DUPLICATE #include <exception> /** * @class user_duplicate * * @brief Some simple brief notation for user_a file * */ class user_duplicate { public: friend class lime; friend class lemon; class std::exception someMethod(); }; #endif
1,044
C++
.h
33
29.727273
74
0.66137
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,754
test_generic.h
copperspice_doxypress/test_build/input_test/extended/test_generic.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TEST_GENERIC_H #define USER_GENERIC_H /// docs for test_slot class test_Slot { public: CS_SLOT_1(Public, inline const QMap<QString, bool> &serviceOwner(const QString & name) const) CS_SLOT_2(serviceOwner) CS_SLOT_1(Public, inline void setOffset(qreal dx)) CS_SLOT_2(setXOffset) inline QString color(); const int &shape(); }; inline void test_Slot::setOffset(qreal dx) { int foo; foo = 1 + 1; } inline QString color() { return "blue"; } #endif
1,234
C++
.h
39
29.25641
99
0.655172
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,758
test_return.h
copperspice_doxypress/test_build/input_test/extended/test_return.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TEST_RETURN_H #define TEST_RETURN_H class test_ReturnType { using iterator = void *; using const_iterator = const void *; public: iterator begin() { return m_data.begin(); } const_iterator begin() const { return m_data.begin(); } void return_IsVoid(); bool return_IsBool(); }; #endif
1,097
C++
.h
33
30.181818
74
0.624174
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,759
test_ssl_dup_enum.h
copperspice_doxypress/test_build/input_test/extended/test_ssl_dup_enum.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef QSSL_DUP_ENUM_H #define QSSL_DUP_ENUM_H namespace QSsl_DupEnum { enum KeyType { PrivateKey, PublicKey }; enum KeyAlgorithm_NotADup { Rsa, Dsa }; }; #endif
935
C++
.h
29
29.793103
74
0.636667
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,760
test_endif.h
copperspice_doxypress/test_build/input_test/extended/test_endif.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef TEST_ENDIF_H #define TEST_ENDIF_H /// test for warning requarding the comment after the endif class test_Endif { /* comment one */ #if test #endif /// internal comment two /// more things to document }; #endif // comment after the end of the header file (does this cause a problem? Unable to repeat)
1,070
C++
.h
27
37.777778
101
0.655072
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,761
test_undoc_warning.h
copperspice_doxypress/test_build/input_test/extended/test_undoc_warning.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef INCLUDE_USER_UNDOC_PARAM #define INCLUDE_USER_UNDOC_PARAM /** @brief User requested test for undocumented parameter warning */ class user_undoc_param { public: /** * Return TRUE if something. * The whatjamacallit is specified somehow. * * @param[in] pObject the object * @param[in] name the name * @param[in] date the start date to query * @return TRUE if something, FALSE otherwise */ RWBoolean do_something(const SomeClass* pObject, const RWCString& name, int date); }; #endif
1,260
C++
.h
34
34.764706
85
0.668847
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,762
test_cmd_example.h
copperspice_doxypress/test_build/examples/test_cmd_example.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ class test_Cmd_Example { public: QString plantName; bool flowers; int size; };
829
C++
.h
23
34.130435
74
0.635236
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,763
function.h
copperspice_doxypress/test_build/input_clang/function.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef FUNCTION_H #define FUNCTION_H /** \file function.h \brief Brief description for this function header file Detailed documentation for a file command which contains one free function. */ /// A free function which appears after a file command, show this brief void myFunction(); #endif
1,036
C++
.h
25
39.84
79
0.677291
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,764
kitchen.h
copperspice_doxypress/test_build/input_clang/kitchen.h
/************************************************************************ * * Copyright (c) 2014-2024 Barbara Geller & Ansel Sermersheim * * DoxyPress is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * DoxyPress is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Documents produced by DoxyPress are derivative works derived from the * input used in their production; they are not affected by this license. * *************************************************************************/ #ifndef KITCHEN_H #define KITCHEN_H /* Following lines are includes */ #include <string> #include <utility> #include <variant> #include <vector> #include <QObject> #include <QString> /// This is brief documentation for max variable which is a define #define MAX 100 /*! Here we have detailed comment, macro will be expanded to return the smaller value which is either A or B */ #define MIN(a, b) ((a < b ) ? (a) : (b)) /// This is brief for a multi line macro #define MultiLines \ do { \ } while (false) /// document a preprocessor directive, docs missing as they should be #ifdef __linux #define BUILD_LINUX #endif /// global vector to track number age limit of each event std::vector<int> globalVector; /// Brief documentation, comment is located next to the forward declaration class Clang_gameSports; bool isTrailOpen(std::string name) { // comment in the body of a function bool retval = true; if (name == "Bear Mountain") { retval = false; } return retval; } /// Brief docs for isWaterSport method. This will start the detailed documentation for the templated /// function. The method waterSport must be defined for each T. template <typename T> bool isWaterSport() { return T::waterSport(); } class Clang_gameBase { public: virtual void gameRequirements(); }; //! Documentation for a concept (brief) //! Documentation for a concept (full description). Refer to CS_Moveable for a longer description. template <typename T1, class T2> concept CS_IsClass = std::is_class_v<T1>; /// Brief documentation for a moveable concept. template <typename U> concept CS_Moveable = std::is_move_constructible_v<U>; /// This is a class to test functionality for C++20 template <typename X> requires requires (X tmp) { tmp + tmp; } class Concept_Test { public: /// Template using a hand written concept template <CS_Moveable T> T moveMe_1(T varA); /// Template method with a requires clause template <typename T, typename U> requires CS_Moveable<T> && CS_Moveable<U> T moveMe_2(U varA); /// Requires clause is located at the end of the declaration template <typename T, typename U> T moveMe_3(U varA) requires CS_Moveable<T> && CS_Moveable<U>; /// Template using a hand written concept template <typename T> void makeFood(T varB); /// form (a) one for nodiscard [[nodiscard]] int thing_a1(bool varC); /// form (a) two for noreturn double thing_a2 [[noreturn]] (bool varD); /// form (a) three attribute deprecated [[deprecated]] void thing_a3 (bool varE); /** form (b) one for nodiscard */ [[nodiscard]] int thing_b1(bool varC); /** form (b) two for noreturn */ double thing_b2 [[noreturn]] (bool varD); /** form (b) three attribute deprecated */ [[deprecated]] void thing_b3 (bool varE); /*! form (c) one for nodiscard */ [[nodiscard]] int thing_c1(bool varC); /*! form (c) two for noreturn */ double thing_c2 [[noreturn]] (bool varD); /*! (form (c) three attribute deprecated */ [[deprecated]] void thing_c4 (bool varE); //! form (d) one for nodiscard [[nodiscard]] int thing_d1(bool varC); //! form (d) two for noreturn double thing_d2 [[noreturn]] (bool varD); //! corm (c) three attribute deprecated [[deprecated]] void thing_d4 (bool varE); }; /// This is the detailed documentation for class Clang_gameSports, located above the class declaration. class Clang_gameSports : public Clang_gameBase { public: Clang_gameSports() = delete; explicit Clang_gameSports(int whichGame); Clang_gameSports(const Clang_gameSports &) = default; ///< Comment for a defaulted copy constructor Clang_gameSports(Clang_gameSports &&) = default; ///< Comment for a defaulted move constructor /// Comment about destructor ~Clang_gameSports(); Clang_gameSports &operator=(const Clang_gameSports &); ///< Comment for a copy assignment Clang_gameSports &operator=(Clang_gameSports &&); ///< Comment for a move assignment /// Documentation for a nested class class gameSolo { public: std::string name; // This struct is a nested inside a class then inside another class struct gameSoloNested { bool isValidGame; }; }; /** (C-1) comment before method, two stars */ void gameRequirements() override; friend int kayakCapacity(int len, int width, const std::string &model); friend class AfterParty; friend struct Clang_struct_abstract; float bikeSpeed(long bVar) &&; /**< (C-2) comment with two stars */ volatile int boatType(std::string &&var); /*!< (C-3) comment with one star and one exclamation */ const std::string horseBreed(int); ///< (C-4) comment with three slashes and a less than void fencing(int (*funcVar)(bool)) const; //!< (C-5) comment two slashes and one exclamation /// (C-6) comment with three slashes, before the method void volleyball(const double var1 = 10.9, const int var2 = 15 > sizeof(int) ? 3 + 5 : false); void volleyball(float var1[5][7], float var2[9]); void swim(int (Clang_gameSports::*dataVar)() const); virtual void playChess() final; virtual void playCheckers() = 0; inline void addEvent(int value) noexcept { numEvents += value; } /// This is the brief comment for method firstTime /** This is the detailed comment for method firstTime. More docs for the detailed. */ static int firstTime(); /// This is a member of the current class. It also has a detailed description. bool isSportOutside; /// With extract all turned on the enums will show in a table with no documentation enum class Locations { Denver, Aspen, Boulder }; /// Document the eventType enum (brief). This should be the main docs for eventType. enum eventType { Summer, ///< comment for the summer Winter ///< comment for the winter }; /// documentation for templated method template<class T, class U = std::string, typename ...Vs> std::string eventSeating(T data, int var, U string) noexcept(std::is_nothrow_move_constructible<T>::value); typedef int myInt;; ///< Documentation for a typedef (myInt expression has two semicolons) // Docs here are just in case the two semicolons mess up parsing void dummy(); using myBool = bool; ///< These are sample docs for a using. // C++14 syntax auto hiking() { ///< Return type of this method is auto which should be deduced as an int. return 42; } // C++17 syntax char32_t myLetter(); ///< New syntaxa as of C++17 // (C-7) comment with two slashes, should be ignored /// (C-8) comment with three slashes, should be ignored as it does not apply to anything protected: float poolLength(); float poolDepth(); double poolHeated(std::string id) volatile; mutable int maxPlayers; private: auto drugTesting(std::vector<int>) -> bool; static bool playersGender; int numEvents; int villageStores[42][17][8]; // C++17 syntax static inline int trail_Length = 27; ///< Can we have an inline variable? std::variant<int, bool, float> someSize; ///< Declaration for a variant. This data type is part of C++17 static const constexpr auto somePair = std::pair(8, 17); ///< Declare a pair without having to specify the data types }; /// Documentation for a normal templated class template<class T> class Clang_eventScoring { public: bool isTimedEvent; bool isScoredEvent; }; /// Documentation for a partially specialized templated class template<class T> class Clang_eventScoring<T *> { public: /// Documentation for a templated method of a partially specialized class template<typename ...Us> std::string eventPlanning(T data, Us... Vs); }; /// Documentation for a fully specialized templated class template< > class Clang_eventScoring<bool> { public: /// documentation for the bool version, which is a fully specialized templated class int maxTwoPlayers(); }; /// Documentation for a class which inherits from a templated class class Clang_eventTimed : public Clang_eventScoring<int> { public: constexpr int max() const volatile { return MAX; } ///< comment for constexpr double maxTime; }; struct Clang_struct_abstract { bool isBallRequired; int numberOfPlayers; }; /// Documentation for a struct using final struct Clang_structFields final : Clang_struct_abstract { bool isGrassy; /// nested structure comment struct structFieldSize { int length; int width; }; }; /// Simple union union Clang_team_union { float timeMark; std::string raceName; }; /// Comment for a namespace namespace ns_clangTest { /// %Afterparty is a class to test documenting macros. class AfterParty : public QObject { /// macro expansion documentation CS_OBJECT(AfterParty) /* CS_PROPERTY_READ(title, getTitle) CS_PROPERTY_WRITE(title, setTitle) CS_PROPERTY_RESET(title, resetTitle) CS_PROPERTY_NOTIFY(title, titleChanged) CS_PROPERTY_REVISION(title, 31415) CS_PROPERTY_DESIGNABLE(title, true) CS_PROPERTY_SCRIPTABLE(title, isScriptTitle() ) CS_PROPERTY_STORED(title, m_title.isEmpty() ) CS_PROPERTY_USER(title, 10 > 100) CS_PROPERTY_CONSTANT(title) CS_PROPERTY_FINAL(title) CS_ENUM(Spices) // registration is only required if the enum is used in a property or a signal CS_REGISTER_ENUM( enum Shapes { square, triangle, circle, trapezoid, diamond=0x10 }; ) CS_SIGNAL_1(Public, void titleChanged(QString title)) CS_SIGNAL_2(titleChanged, title) */ public: AfterParty() = default; ///< Defaulted constructor documentation. /// Information about the spices enum. enum Spices { mint, basil, Salt, Pepper =100, cloves }; /// Used to get the current title. QString getTitle() const { return m_title; } /// Used to set the title void setTitle(QString data) { m_title = data; } private: QString m_title; }; } /// Brief for the free function (one). /// Documentation for a free function ONE void some1_FreeFunction(); /// Brief for the free function (two). /// Documentation for a free function TWO void some2_FreeFunction(); /*! \concept CS_Moveable \brief This is second (brief) comment for the CS_Moveable concept. The full documentation for the CS_Moveable concept is located in the external docs. Continued information to show more details about this concept. \sa Clang_eventTimed */ #endif
11,961
C++
.h
301
34.976744
127
0.662507
copperspice/doxypress
148
14
22
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,765
main.cpp
ColinPitrat_caprice32/main.cpp
#include "cap32.h" int main(int argc, char **argv) { return cap32_main(argc, argv); }
89
C++
.cpp
5
16.2
32
0.698795
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,766
CapriceDevTools.cpp
ColinPitrat_caprice32/test/CapriceDevTools.cpp
#include <gtest/gtest.h> #include <gmock/gmock.h> #include "SDL.h" #include "CapriceDevTools.h" #include "cap32.h" extern t_CPC CPC; using namespace wGui; class CapriceDevToolsTest : public testing::Test { public: CapriceDevToolsTest() : app(/*pWindow=*/nullptr) {} void SetUp() { CPC.resources_path = "resources"; app.Init(); CRect rect; surface = SDL_CreateRGBSurface(/*flags=*/0,/*width=*/10,/*height=*/10,/*depth=*/32,0,0,0,0); view = new CView(app, surface, surface, rect); cdt = new CapriceDevTools(rect, /*pParent=*/view, /*pFontEngine=*/nullptr, /*devtools=*/nullptr); } void TearDown() { delete cdt; delete view; SDL_FreeSurface(surface); } protected: CApplication app; SDL_Surface *surface; CView *view; CapriceDevTools *cdt; }; namespace wGui { bool operator==(const SListItem& l, const SListItem& r) { return l.sItemText == r.sItemText; } std::ostream& operator<<(std::ostream& os, const SListItem& item) { os << item.sItemText; return os; } } TEST_F(CapriceDevToolsTest, AsmSearchEmpty) { std::vector<SListItem> items = {}; cdt->SetDisassembly(items); cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::Start, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::Start, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); } TEST_F(CapriceDevToolsTest, AsmSearchNoMatch) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("nope, still no match"), SListItem("don't count on it!"), }; cdt->SetDisassembly(items); cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::Start, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::Start, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre()); } TEST_F(CapriceDevToolsTest, AsmSearchForwardFromPosIncluded) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too but we shouldn't reach it"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); } TEST_F(CapriceDevToolsTest, AsmSearchForwardFromPosExcluded) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("this text too"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("another text"))); } TEST_F(CapriceDevToolsTest, AsmSearchForwardFromStart) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::Start, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); // Search with position excluded to advance cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("this text too"))); // Check that "From start" actually restart from the start cdt->AsmSearch(SearchFrom::Start, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); cdt->AsmSearch(SearchFrom::Start, SearchDir::Forward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); } TEST_F(CapriceDevToolsTest, AsmSearchBackwardFromPosIncluded) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too but we shouldn't reach it"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); cdt->AsmSearch(SearchFrom::PositionIncluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); } TEST_F(CapriceDevToolsTest, AsmSearchBackwardFromPosExcluded) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("another text"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("this text too"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("but this text does"))); } TEST_F(CapriceDevToolsTest, AsmSearchBackwardFromStart) { std::vector<SListItem> items = { SListItem("this doesn't match"), SListItem("neither does this"), SListItem("but this text does"), SListItem("this text too"), SListItem("another text"), SListItem("still more text"), }; cdt->SetDisassembly(items); // We normally start with nothing selected. // We search text repeatedly. As we look with current position included, we // should always end-up at the same place. cdt->SetAssemblySearch("text"); cdt->AsmSearch(SearchFrom::Start, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); // Search with position excluded to advance cdt->AsmSearch(SearchFrom::PositionExcluded, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("another text"))); // Check that "From start" actually restart from the start (well, the end here as we're searching backward) cdt->AsmSearch(SearchFrom::Start, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); cdt->AsmSearch(SearchFrom::Start, SearchDir::Backward); EXPECT_THAT(cdt->GetSelectedAssembly(), testing::ElementsAre(SListItem("still more text"))); }
10,290
C++
.cpp
226
41.955752
109
0.744251
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,767
green_palette.cpp
ColinPitrat_caprice32/test/green_palette.cpp
#include <gtest/gtest.h> #include "cap32.h" TEST(GreenPalette, ValuesMatchFormula) { double precision = 0.0001; double G_LUMA_R = 0.2427; double G_LUMA_G = 0.6380; double G_LUMA_B = 0.1293; double G_LUMA_BASE = 0.071; double G_LUMA_COEF = 0.100; double G_LUMA_PRIM = 0.050; //test the new libretro palette (mode 1) double *green_palette = video_get_green_palette(1); for (int color = 0; color < 32; color++) { double *colours_rgb = video_get_rgb_color(color); double r = colours_rgb[0]; double g = colours_rgb[1]; double b = colours_rgb[2]; double green_luma = ((G_LUMA_R * r) + (G_LUMA_G * g) + (G_LUMA_B * b)); green_luma += (G_LUMA_BASE + G_LUMA_PRIM - (G_LUMA_COEF * green_luma)); EXPECT_NEAR(green_luma, green_palette[color], precision) << "green_luma value differs for " << color << "."; } }
879
C++
.cpp
24
32.625
74
0.627358
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,768
slothandler.cpp
ColinPitrat_caprice32/test/slothandler.cpp
#include <gtest/gtest.h> #include "cap32.h" #include "slotshandler.h" #include <string> TEST(SlotHandlerTest, fillSlotsNoArg) { std::vector<std::string> slot_list; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneLocalDskFile) { std::vector<std::string> slot_list = { "./test.dsk"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("./test.dsk", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsTwoDskFiles) { std::vector<std::string> slot_list = { "/tmp/foo.dsk", "/var/bar.dsk"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("/tmp/foo.dsk", CPC.drvA_file); ASSERT_EQ("/var/bar.dsk", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneLocalCdtFile) { std::vector<std::string> slot_list = { "./test.cdt"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("./test.cdt", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneLocalVocFile) { std::vector<std::string> slot_list = { "./test.voc"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("./test.voc", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneLocalSnaFile) { std::vector<std::string> slot_list = { "./test.sna"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("./test.sna", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneCprFile) { std::vector<std::string> slot_list = { "./test.cpr"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("./test.cpr", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneZippedCprFile) { std::vector<std::string> slot_list = { "test/cartridge/testplus.zip"}; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("test/cartridge/testplus.zip", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsOneFileOfEachKind) { std::vector<std::string> slot_list = { "/tmp/foo.dsk", "/var/bar.cdt", "/usr/test.sna", "/home/cart.cpr" }; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("/home/cart.cpr", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("/tmp/foo.dsk", CPC.drvA_file); ASSERT_EQ("", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("/var/bar.cdt", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("/usr/test.sna", CPC.snap_file); } TEST(SlotHandlerTest, fillSlotsManyFilesOfEachKind) { std::vector<std::string> slot_list = { "rom/system.cpr", "/tmp/foo.dsk", "/var/test.dsk", "/tmp/other.dsk", "/var/bar.cdt", "/tmp/test.voc", "/usr/test.sna", "/tmp/other.sna", "test/test.cpr" }; t_CPC CPC; fillSlots(slot_list, CPC); ASSERT_EQ("", CPC.cart_path); ASSERT_EQ("rom/system.cpr", CPC.cart_file); ASSERT_EQ("", CPC.dsk_path); ASSERT_EQ("/tmp/foo.dsk", CPC.drvA_file); ASSERT_EQ("/var/test.dsk", CPC.drvB_file); ASSERT_EQ("", CPC.tape_path); ASSERT_EQ("/var/bar.cdt", CPC.tape_file); ASSERT_EQ("", CPC.snap_path); ASSERT_EQ("/usr/test.sna", CPC.snap_file); } TEST(SlotHandlerTest, serializeDiskFormat) { t_disk_format fmt; fmt.label = "test"; fmt.tracks = 42; fmt.sides = 2; fmt.sectors = 4; fmt.sector_size = 1; fmt.gap3_length = 82; fmt.filler_byte = 229; fmt.sector_ids[0][0] = 193; fmt.sector_ids[0][1] = 198; fmt.sector_ids[0][2] = 194; fmt.sector_ids[0][3] = 199; fmt.sector_ids[1][0] = 195; fmt.sector_ids[1][1] = 200; fmt.sector_ids[1][2] = 196; fmt.sector_ids[1][3] = 201; auto result = serializeDiskFormat(fmt); ASSERT_EQ("test,42,2,4,1,82,229,193,198,194,199,195,200,196,201", result); } TEST(SlotHandlerTest, serializeUnnamedDiskFormatReturnsEmptyString) { t_disk_format fmt; fmt.tracks = 42; fmt.sides = 2; fmt.sectors = 4; fmt.sector_size = 1; fmt.gap3_length = 82; fmt.filler_byte = 229; fmt.sector_ids[0][0] = 193; fmt.sector_ids[0][1] = 198; fmt.sector_ids[0][2] = 194; fmt.sector_ids[0][3] = 199; fmt.sector_ids[1][0] = 195; fmt.sector_ids[1][1] = 200; fmt.sector_ids[1][2] = 196; fmt.sector_ids[1][3] = 201; auto result = serializeDiskFormat(fmt); ASSERT_EQ("", result); }
6,016
C++
.cpp
195
28.061538
196
0.654099
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,769
phazer.cpp
ColinPitrat_caprice32/test/phazer.cpp
#include <gtest/gtest.h> #include "phazer.h" TEST(PhazerTest, Next) { PhazerType none(PhazerType::None); PhazerType trojan(PhazerType::TrojanLightPhazer); ASSERT_EQ(PhazerType::AmstradMagnumPhaser, none.Next()); ASSERT_EQ(PhazerType::None, trojan.Next()); } TEST(PhazerTest, operator_bool) { ASSERT_FALSE(PhazerType(PhazerType::None)); ASSERT_TRUE(PhazerType(PhazerType::AmstradMagnumPhaser)); ASSERT_TRUE(PhazerType(PhazerType::TrojanLightPhazer)); } TEST(PhazerTest, ToString) { ASSERT_EQ("off", PhazerType(PhazerType::None).ToString()); ASSERT_EQ("Amstrad Magnum Phaser", PhazerType(PhazerType::AmstradMagnumPhaser).ToString()); ASSERT_EQ("Trojan Light Phazer", PhazerType(PhazerType::TrojanLightPhazer).ToString()); }
747
C++
.cpp
21
33.380952
93
0.782247
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,770
cartridge.cpp
ColinPitrat_caprice32/test/cartridge.cpp
#include <gtest/gtest.h> #include "cartridge.h" #include "types.h" #include "errors.h" extern byte* pbGPBuffer; extern byte* pbCartridgeImage; class Cartridge : public testing::Test { public: void SetUp() { // attempt to allocate the general purpose buffer pbGPBuffer = new byte [128*1024]; ASSERT_NE(nullptr, pbGPBuffer); } void TearDown() { delete[] pbGPBuffer; } }; TEST_F(Cartridge, CprLoadOnNonExistingFileReturnsError) { int rc = cpr_load("test/cartridge/non_existent.cpr"); ASSERT_EQ(ERR_FILE_NOT_FOUND, rc); } TEST_F(Cartridge, CprLoadOnEmptyCPRFileReturnsError) { int rc = cpr_load("test/cartridge/invalid_empty.cpr"); ASSERT_EQ(ERR_CPR_INVALID, rc); } TEST_F(Cartridge, CprLoadOnNonRIFFFileReturnsError) { int rc = cpr_load("test/cartridge/invalid_noriff.cpr"); ASSERT_EQ(ERR_CPR_INVALID, rc); } TEST_F(Cartridge, CprLoadOnNonAMSFileReturnsError) { int rc = cpr_load("test/cartridge/invalid_noams.cpr"); ASSERT_EQ(ERR_CPR_INVALID, rc); } TEST_F(Cartridge, CprLoadOnDummyCPRFile) { int rc = cpr_load("test/cartridge/dummy.cpr"); ASSERT_EQ(0, rc); ASSERT_EQ('t', pbCartridgeImage[0]); ASSERT_EQ('e', pbCartridgeImage[1]); ASSERT_EQ('s', pbCartridgeImage[2]); ASSERT_EQ('t', pbCartridgeImage[3]); for (int i = 4; i < 512*1024; i++) { ASSERT_EQ('\0', pbCartridgeImage[i]) << "with i = " << i; } } TEST_F(Cartridge, CprLoadOnSystemCPRFile) { int rc = cpr_load("rom/system.cpr"); ASSERT_EQ(0, rc); // Check the first byte of each page ASSERT_EQ('\x01', pbCartridgeImage[0]); //ASSERT_EQ('\x80', pbCartridgeImage[16*1024]); ASSERT_EQ('\x3a', pbCartridgeImage[32*1024]); ASSERT_EQ('\x01', pbCartridgeImage[48*1024]); //ASSERT_EQ('\xf3', pbCartridgeImage[64*1024]); ASSERT_EQ('\x21', pbCartridgeImage[80*1024]); ASSERT_EQ('\x60', pbCartridgeImage[96*1024]); //ASSERT_EQ('\x80', pbCartridgeImage[112*1024]); for (int i = 128*1024; i < 512*1024; i++) { ASSERT_EQ('\0', pbCartridgeImage[i]) << "with i = " << i; } }
2,091
C++
.cpp
66
28
63
0.675622
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,771
keyboard.cpp
ColinPitrat_caprice32/test/keyboard.cpp
#include <gtest/gtest.h> #include <filesystem> #include "keyboard.h" TEST(KeyboardTest, parseAllLayoutFiles) { InputMapper mapper(/*CPC=*/nullptr); for (const auto & entry : std::filesystem::directory_iterator("./resources")) { auto path = entry.path().string(); if (path.substr(path.length()-4, 4) == ".map") { EXPECT_TRUE(mapper.load_layout(path)) << "Error parsing " << path; } } }
412
C++
.cpp
14
26.5
79
0.667506
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,772
CapriceLoadSave.cpp
ColinPitrat_caprice32/test/CapriceLoadSave.cpp
#include <gtest/gtest.h> #include "SDL.h" #include "CapriceGuiView.h" #include "CapriceLoadSave.h" #include "cap32.h" #include <string> extern t_CPC CPC; using namespace wGui; class CapriceLoadSaveTest : public testing::Test { public: CapriceLoadSaveTest() : app(/*pWindow=*/nullptr) {} void SetUp() { CPC.resources_path = "resources"; app.Init(); CRect rect; surface = SDL_CreateRGBSurface(/*flags=*/0,/*width=*/10,/*height=*/10,/*depth=*/32,0,0,0,0); view = new CapriceGuiView(app, surface, surface, rect); cls = new CapriceLoadSave(CRect(), /*pParent=*/view, /*pFontEngine=*/nullptr); } void TearDown() { delete cls; delete view; SDL_FreeSurface(surface); } void SetFileSpec(const std::list<std::string> &fileSpec) { cls->m_fileSpec = fileSpec; } protected: CApplication app; CapriceLoadSave *cls; CapriceGuiView *view; SDL_Surface *surface; }; TEST_F(CapriceLoadSaveTest, MatchCurrentFileSpecReturnsFalseIfExtensionListIsEmpty) { std::list<std::string> fileSpec; SetFileSpec(fileSpec); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.zip")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.dsk")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test")); ASSERT_FALSE(cls->MatchCurrentFileSpec("")); } TEST_F(CapriceLoadSaveTest, MatchCurrentFileSpecReturnsTrueIffExtensionInExtensionList) { std::list<std::string> fileSpec = { ".zip", ".dsk" }; SetFileSpec(fileSpec); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.zip")); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.dsk")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.cpr")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.voc")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test")); ASSERT_FALSE(cls->MatchCurrentFileSpec("zip")); ASSERT_FALSE(cls->MatchCurrentFileSpec("")); } TEST_F(CapriceLoadSaveTest, MatchCurrentFileSpecSupportsVariousExtensionSizes) { std::list<std::string> fileSpec = { ".tar.gz", ".c", "nodot" }; SetFileSpec(fileSpec); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.tar.gz")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.gz")); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.c")); ASSERT_FALSE(cls->MatchCurrentFileSpec("test.cpp")); ASSERT_TRUE(cls->MatchCurrentFileSpec("nodot")); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.nodot")); ASSERT_FALSE(cls->MatchCurrentFileSpec("dot")); } TEST_F(CapriceLoadSaveTest, MatchCurrentFileSpecIsCaseInsensitive) { std::list<std::string> fileSpec = { ".dsk" }; SetFileSpec(fileSpec); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.dsk")); ASSERT_TRUE(cls->MatchCurrentFileSpec("TEST.DSK")); ASSERT_TRUE(cls->MatchCurrentFileSpec("test.DsK")); }
2,722
C++
.cpp
73
33.794521
98
0.729586
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,773
video.cpp
ColinPitrat_caprice32/test/video.cpp
#include <gtest/gtest.h> #include "video.h" #include "cap32.h" extern SDL_Surface* pub; extern SDL_Surface* scaled; namespace { class ComputeRectsTest : public testing::Test { public: // Verifies that src corresponds to the whole screen void ExpectFullSrc(bool half_pixels) { EXPECT_EQ(src.x, 0); EXPECT_EQ(src.y, 0); if (half_pixels) { EXPECT_EQ(src.w, CPC_VISIBLE_SCR_WIDTH); // The -4 corresponds to the 'src->h-=2*2' in video.cpp when dh <= 0 EXPECT_EQ(src.h, CPC_VISIBLE_SCR_HEIGHT-4); } else { EXPECT_EQ(src.w, CPC_VISIBLE_SCR_WIDTH*2); // The -4 corresponds to the 'src->h-=2*2' in video.cpp when dh <= 0 EXPECT_EQ(src.h, CPC_VISIBLE_SCR_HEIGHT*2-4); } } // Verifies that a rectangle corresponds to the whole surface void ExpectRectMatchesSurface(SDL_Rect *r, SDL_Surface *s) { EXPECT_EQ(r->x, 0); EXPECT_EQ(r->y, 0); EXPECT_EQ(r->w, s->w); EXPECT_EQ(r->h, s->h); } // Verifies that a rectangle fits in the corresponding surface void ExpectRectInSurface(SDL_Rect *r, SDL_Surface *s) { EXPECT_LE(r->x + r->w, s->w); EXPECT_LE(r->y + r->h, s->h); } // Verifies that src scaled by a factor 2 fits in dst void ExpectSrcFitsInDst() { EXPECT_LE(src.w*2, dst.w); EXPECT_LE(src.h*2, dst.h); } // Some checks that should be valid for any call. void ExpectValid() { ExpectRectInSurface(&src, pub); ExpectRectInSurface(&dst, scaled); ExpectSrcFitsInDst(); } SDL_Surface* CreateSurface(int width, int height) { // BPP shouldn't influence this method. Anyway, it is currently called only by filters that support only 16bpp. return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 16, 0, 0, 0, 0); } SDL_Rect src, dst; }; TEST_F(ComputeRectsTest, DefaultSizeHalfPixels) { pub = CreateSurface(CPC_VISIBLE_SCR_WIDTH, CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH, 2*CPC_VISIBLE_SCR_HEIGHT); Uint8 half_pixels = 1; compute_rects_for_tests(&src, &dst, half_pixels); ExpectFullSrc(half_pixels); ExpectRectMatchesSurface(&dst, scaled); ExpectValid(); } TEST_F(ComputeRectsTest, BiggerVidHalfPixels) { for (auto offset : { 1, 2, 3, 10, 17, 50, 100, 101 }) { pub = CreateSurface(CPC_VISIBLE_SCR_WIDTH, CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH + offset, 2*CPC_VISIBLE_SCR_HEIGHT + offset); Uint8 half_pixels = 1; compute_rects_for_tests(&src, &dst, half_pixels); ExpectFullSrc(half_pixels); EXPECT_EQ(dst.x, offset/2); EXPECT_EQ(dst.y, offset/2); EXPECT_EQ(dst.w, 2*CPC_VISIBLE_SCR_WIDTH); EXPECT_EQ(dst.h, 2*CPC_VISIBLE_SCR_HEIGHT); ExpectValid(); } } TEST_F(ComputeRectsTest, BiggerPubHalfPixels) { for (auto offset : { 1, 2, 3, 10, 17, 50, 100, 101, CPC_VISIBLE_SCR_WIDTH, CPC_VISIBLE_SCR_WIDTH+10 }) { pub = CreateSurface(CPC_VISIBLE_SCR_WIDTH, CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH - offset, 2*CPC_VISIBLE_SCR_HEIGHT - offset); Uint8 half_pixels = 1; compute_rects_for_tests(&src, &dst, half_pixels); EXPECT_EQ(src.x, (offset+1)/4); EXPECT_EQ(src.y, (offset+1)/4); EXPECT_EQ(src.w, CPC_VISIBLE_SCR_WIDTH - (offset+1)/2); // TODO: There is obviously a problem if offset/2 < 4 compared to when offset = 0 (where we have -4 here) EXPECT_EQ(src.h, CPC_VISIBLE_SCR_HEIGHT - (offset+1)/2); ExpectRectMatchesSurface(&dst, scaled); ExpectValid(); } } TEST_F(ComputeRectsTest, DefaultSize) { pub = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH, 2*CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(4*CPC_VISIBLE_SCR_WIDTH, 4*CPC_VISIBLE_SCR_HEIGHT); Uint8 half_pixels = 0; compute_rects_for_tests(&src, &dst, half_pixels); ExpectFullSrc(half_pixels); ExpectRectMatchesSurface(&dst, scaled); ExpectValid(); } TEST_F(ComputeRectsTest, BiggerVid) { for (auto offset : { 1, 2, 3, 10, 17, 50, 100, 101 }) { pub = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH, 2*CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(4*CPC_VISIBLE_SCR_WIDTH + offset, 4*CPC_VISIBLE_SCR_HEIGHT + offset); Uint8 half_pixels = 0; compute_rects_for_tests(&src, &dst, half_pixels); ExpectFullSrc(half_pixels); EXPECT_EQ(dst.x, offset/2); EXPECT_EQ(dst.y, offset/2); EXPECT_EQ(dst.w, 4*CPC_VISIBLE_SCR_WIDTH); EXPECT_EQ(dst.h, 4*CPC_VISIBLE_SCR_HEIGHT); ExpectValid(); } } TEST_F(ComputeRectsTest, BiggerPub) { for (auto offset : { 1, 2, 3, 10, 17, 50, 100, 101, CPC_VISIBLE_SCR_WIDTH, CPC_VISIBLE_SCR_WIDTH+10 }) { pub = CreateSurface(2*CPC_VISIBLE_SCR_WIDTH, 2*CPC_VISIBLE_SCR_HEIGHT); scaled = CreateSurface(4*CPC_VISIBLE_SCR_WIDTH - offset, 4*CPC_VISIBLE_SCR_HEIGHT - offset); Uint8 half_pixels = 1; compute_rects_for_tests(&src, &dst, half_pixels); EXPECT_EQ(src.x, (offset+1)/4); EXPECT_EQ(src.y, (offset+1)/4); EXPECT_EQ(src.w, 2*CPC_VISIBLE_SCR_WIDTH - (offset+1)/2); // TODO: There is obviously a problem if offset/2 < 4 compared to when offset = 0 (where we have -4 here) EXPECT_EQ(src.h, 2*CPC_VISIBLE_SCR_HEIGHT - (offset+1)/2); ExpectRectMatchesSurface(&dst, scaled); ExpectValid(); } } }
5,316
C++
.cpp
142
32.950704
117
0.671265
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,774
zip.cpp
ColinPitrat_caprice32/test/zip.cpp
#include <gtest/gtest.h> #include "zip.h" #include "errors.h" /* * These tests are not really unit tests as they use files that can be found * in test/zip/ * The files content are the following: * - test1.zip * - README.txt * - empty.dsk * - hello.dsk */ TEST(Zip, DirOnFileWithNoMatchingEntry) { zip::t_zip_info file_infos; file_infos.filename = "test/zip/test1.zip"; file_infos.extensions = ".zzz"; int rc = zip::dir(&file_infos); // Returns ERR_FILE_EMPTY_ZIP although zip file is not really empty, // it just has no matching file ASSERT_EQ(ERR_FILE_EMPTY_ZIP, rc); ASSERT_EQ(0, file_infos.filesOffsets.size()); } TEST(Zip, DirOnFileWithOneExtensionAndMultipleEntries) { zip::t_zip_info file_infos; file_infos.filename = "test/zip/test1.zip"; file_infos.extensions = ".dsk"; int rc = zip::dir(&file_infos); ASSERT_EQ(0, rc); ASSERT_EQ(2, file_infos.filesOffsets.size()); ASSERT_EQ("disk/empty.dsk", file_infos.filesOffsets[0].first); ASSERT_EQ(119, file_infos.filesOffsets[0].second); ASSERT_EQ("disk/hello.dsk", file_infos.filesOffsets[1].first); ASSERT_EQ(1918, file_infos.filesOffsets[1].second); } TEST(Zip, DirOnFileWithMultipleExtensions) { zip::t_zip_info file_infos; file_infos.filename = "test/zip/test1.zip"; file_infos.extensions = ".dsk.txt"; int rc = zip::dir(&file_infos); ASSERT_EQ(0, rc); ASSERT_EQ(3, file_infos.filesOffsets.size()); ASSERT_EQ("README.txt", file_infos.filesOffsets[0].first); ASSERT_EQ("disk/empty.dsk", file_infos.filesOffsets[1].first); ASSERT_EQ("disk/hello.dsk", file_infos.filesOffsets[2].first); } TEST(Zip, ExtractOnFileWithMultipleEntries) { FILE *file; // Retrieve offset zip::t_zip_info file_infos; file_infos.filename = "test/zip/test1.zip"; file_infos.extensions = ".txt"; int rc = zip::dir(&file_infos); ASSERT_EQ(0, rc); rc = zip::extract(file_infos, &file); ASSERT_EQ(0, rc); ASSERT_NE(nullptr, file); char buffer[256]; size_t r = fread(buffer, 1, 256, file); buffer[r] = 0; ASSERT_STREQ("This file is a sample zip file used by Caprice32 tests.\n", buffer); ASSERT_EQ(0, fclose(file)); }
2,158
C++
.cpp
66
30.106061
84
0.705147
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,775
symfile.cpp
ColinPitrat_caprice32/test/symfile.cpp
#include <gtest/gtest.h> #include "symfile.h" #include <fstream> #include <iostream> #include <map> #include <string> class SymfileTest : public testing::Test { public: void TearDown() { for(auto f : tmpFilenames_) { ASSERT_EQ(0, unlink(f.c_str())); } } protected: std::string createTmpFile() { char tmpFilename[] = "test/.cap32_tmp_XXXXXX"; int fd = mkstemp(tmpFilename); if (fd <= 0) return ""; close(fd); tmpFilenames_.push_back(tmpFilename); return tmpFilename; } std::string readWholeFile(const std::string& filename) { std::ifstream is(filename); if (is.bad()) return "**bad stream after open**"; if (is.fail()) return "**fail stream after open**"; is.seekg(0, is.end); int length = is.tellg(); is.seekg(0, is.beg); char * buffer = new char [length+1]; is.read(buffer, length); if (is.bad()) return "**bad stream after read**"; // For some reason, the stream from the tmp file is failed after read on Windows // It seems that length has an invalid value. if (is.fail()) length = is.gcount(); buffer[length] = 0; is.close(); return std::string(buffer, length); } std::vector<std::string> tmpFilenames_; }; TEST_F(SymfileTest, parseSymfile) { Symfile symfile("test/symfile/example.sym"); std::vector<word> expected_breakpoints = {0x4042}; std::vector<word> expected_entrypoints = {0x1729}; std::map<word, std::string> expected_symbols = { {0x4005, "hello_world"}, {0x4012, "foo_bar"}, }; ASSERT_EQ(expected_breakpoints, symfile.Breakpoints()); ASSERT_EQ(expected_entrypoints, symfile.Entrypoints()); ASSERT_EQ(expected_symbols, symfile.Symbols()); } TEST_F(SymfileTest, saveSymfile) { Symfile symfile; symfile.addBreakpoint(0x1234); symfile.addBreakpoint(0x1235); symfile.addEntrypoint(0x2345); symfile.addEntrypoint(0x2346); symfile.addSymbol(0x3456, "foobar"); symfile.addSymbol(0x3457, "foobaz"); auto filename = createTmpFile(); ASSERT_FALSE(filename.empty()); symfile.SaveTo(filename); auto got = readWholeFile(filename); auto want = readWholeFile("test/symfile/expected.sym"); ASSERT_EQ(got, want); }
2,267
C++
.cpp
75
25.813333
86
0.665903
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,776
z80_disassembly.cpp
ColinPitrat_caprice32/test/z80_disassembly.cpp
#include <gtest/gtest.h> #include "z80_disassembly.h" #include "cap32.h" #include "z80_macros.h" extern byte *membank_read[4]; extern t_CPC CPC; namespace { TEST(DisassembledLine, Comparisons) { DisassembledLine l1(1, 0, "nop"); DisassembledLine l1_identical(1, 0, "nop"); DisassembledLine l1bis(1, 0xc9, "ret"); DisassembledLine l2(2, 0x1802, "jr 2", 4); DisassembledLine l3(3, 0xc9, "ret"); EXPECT_TRUE(l1 < l2); EXPECT_TRUE(l2 < l3); EXPECT_TRUE(l1 < l3); EXPECT_FALSE(l1 < l1bis); EXPECT_FALSE(l1 == l1bis); EXPECT_TRUE(l1 == l1_identical); } TEST(Z80DisassemblyTest, DisassembleNOPRET) { byte membank0[2] = {0, 0xc9}; CPC.resources_path = "resources"; membank_read[0] = membank0; auto code = disassemble({0}); DisassembledCode want; want.lines.emplace(0, 0, "nop"); want.lines.emplace(1, 0xc9, "ret"); EXPECT_EQ(want.lines, code.lines); } TEST(Z80DisassemblyTest, DisassembleDecALoop) { byte membank0[10] = { 0x00, 0x00, 0x00, 0x3E, 0x10, 0x3D, 0xC2, 0x5, 0x0, 0xC9 }; CPC.resources_path = "resources"; membank_read[0] = membank0; auto code = disassemble({3}); DisassembledCode want; want.lines.emplace(3, 0x3E10, "ld a,$10"); want.lines.emplace(5, 0x3D, "dec a"); want.lines.emplace(6, 0xC20500, "jp nz,$0005"); want.lines.emplace(9, 0xC9, "ret"); EXPECT_EQ(want.lines, code.lines); } TEST(Z80DisassemblyTest, SqrtRoutine) { byte membank0[16] = { 0x21, 0x64, 0x00, 0x11, 0x01, 0x00, 0xAF, 0x3D, 0xED, 0x52, 0x13, 0x13, 0x3C, 0x30, 0xF9, 0xC9 }; CPC.resources_path = "resources"; membank_read[0] = membank0; auto code = disassemble({0}); DisassembledCode want; want.lines.emplace(0, 0x216400, "ld hl,$0064"); want.lines.emplace(3, 0x110100, "ld de,$0001"); want.lines.emplace(6, 0xAF, "xor a"); want.lines.emplace(7, 0x3D, "dec a"); want.lines.emplace(8, 0xED52, "sbc hl,de"); want.lines.emplace(10, 0x13, "inc de"); want.lines.emplace(11, 0x13, "inc de"); want.lines.emplace(12, 0x3C, "inc a"); want.lines.emplace(13, 0x30F9, "jr nc,$f9 ; $0008"); want.lines.emplace(15, 0xC9, "ret"); EXPECT_EQ(want.lines, code.lines); } TEST(Z80DisassemblyTest, DisassembleOne) { byte membank0[16] = { 0x21, 0x64, 0x00, 0x11, 0x01, 0x00, 0xAF, 0x3D, 0xED, 0x52, 0x13, 0x13, 0x3C, 0x30, 0xF9, 0xC9 }; CPC.resources_path = "resources"; membank_read[0] = membank0; std::vector<dword> unused_entry_points; DisassembledCode unused_code; auto line = disassemble_one(10, unused_code, unused_entry_points); EXPECT_EQ(DisassembledLine(10, 0x13, "inc de"), line); line = disassemble_one(13, unused_code, unused_entry_points); EXPECT_EQ(DisassembledLine(13, 0x30F9, "jr nc,$f9 ; $0008"), line); } TEST(Z80DisassemblyTest, LineAt) { byte membank0[16] = { 0x21, 0x64, 0x00, 0x11, 0x01, 0x00, 0xAF, 0x3D, 0xED, 0x52, 0x13, 0x13, 0x3C, 0x30, 0xF9, 0xC9 }; CPC.resources_path = "resources"; membank_read[0] = membank0; auto code = disassemble({0}); EXPECT_FALSE(code.LineAt(9).has_value()); EXPECT_TRUE(code.LineAt(10).has_value()); EXPECT_EQ(DisassembledLine(10, 0x13, "inc de"), code.LineAt(10).value()); } }
3,140
C++
.cpp
88
32.954545
121
0.695235
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,777
fileutils.cpp
ColinPitrat_caprice32/test/fileutils.cpp
#include <gtest/gtest.h> #include "fileutils.h" #include <string> TEST(FileUtils, Listdirectory) { std::string directory = "test/zip"; std::vector<std::string> result = listDirectory(directory); ASSERT_EQ(1, result.size()); } TEST(FileUtils, ListdirectoryMatchingExtension) { std::string directory = "test/zip"; std::vector<std::string> result = listDirectoryExt(directory, "zip"); ASSERT_EQ(1, result.size()); } TEST(FileUtils, ListdirectoryNonMatchingExtension) { std::string directory = "test/zip"; std::vector<std::string> result = listDirectoryExt(directory, "zup"); ASSERT_EQ(0, result.size()); }
636
C++
.cpp
21
27.714286
71
0.741667
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,778
crtc.cpp
ColinPitrat_caprice32/test/crtc.cpp
#include <gtest/gtest.h> #include "crtc.h" class CrtcTest : public testing::Test { public: private: }; TEST_F(CrtcTest, ShiftLittleEndianDwordTriplet) { dword val; val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 0); EXPECT_EQ(0x01020304, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 1); EXPECT_EQ(0x02030489, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 2); EXPECT_EQ(0x030489AB, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 3); EXPECT_EQ(0x0489ABCD, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 4); EXPECT_EQ(0x89ABCDEF, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 5); EXPECT_EQ(0xABCDEF01, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 6); EXPECT_EQ(0xCDEF0123, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 7); EXPECT_EQ(0xEF012345, val); val = shiftLittleEndianDwordTriplet(0x01234567, 0x89ABCDEF, 0x01020304, 8); EXPECT_EQ(0x01234567, val); }
1,169
C++
.cpp
28
38.357143
78
0.773087
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,779
asic.cpp
ColinPitrat_caprice32/test/asic.cpp
#include <gtest/gtest.h> #include "asic.h" #include "cap32.h" #include <vector> extern byte *membank_config[8][4]; extern byte *membank_write[4]; extern t_GateArray GateArray; namespace { class AsicTest : public testing::Test { public: AsicTest() : lockSeq({0x00, 0xff, 0x77, 0xb3, 0x51, 0xa8, 0xd4, 0x62, 0x39, 0x9c, 0x46, 0x2b, 0x15, 0x8a, 0xcd}) { asic.locked = true; asic.lockSeqPos = 0; } protected: const std::vector<byte> lockSeq; }; // About unlock sequence ... // // testplus.cpr unlock with: // AA 00 FF 77 B3 51 A8 D4 62 39 9C 46 2B 15 8A CD EE FF // and lock with: // AA 00 FF 77 B3 51 A8 D4 62 39 9C 46 2B 15 8A CD EE A5 // // But Arnold5 specs says the unlock sequence ends at CD // http://www.cpcwiki.eu/index.php/Arnold_V_Specs_Revised#Locking_of_enhanced_features // and older specs says the unlock sequence ends at EE // http://www.cpcwiki.eu/index.php/Arnold_V_specs#Locking_of_enhanced_features // In all cases, the lock sequence is the same with the last byte having any value except the one it has in the unlock sequence // All cartridges tested unlock with: // FF 00 FF 77 B3 51 A8 D4 62 39 9C 46 2B 15 8A CD EE // Klax alternates between: // FF 00 FF 77 B3 51 A8 D4 62 39 9C 46 2B 15 8A CD EE // And: // FF 00 FF 77 B3 51 A8 D4 62 39 9C 46 2B 15 8A CD FF // But making the latter unlock the asic make the game bug (loop on welcome screen) TEST_F(AsicTest, UnlockAsic) { ASSERT_TRUE(asic.locked); // Sequence must start with a non null asic_poke_lock_sequence(0x01); for(const auto& val : lockSeq) { asic_poke_lock_sequence(val); } // Only unlock once sequence is complete ASSERT_TRUE(asic.locked); // And end with any value asic_poke_lock_sequence(0x01); ASSERT_FALSE(asic.locked); } TEST_F(AsicTest, UnlockAsicDoesntUnlockIfNoNonNullByteBeforeSeq) { ASSERT_TRUE(asic.locked); asic_poke_lock_sequence(0x00); for(const auto& val : lockSeq) { asic_poke_lock_sequence(val); } asic_poke_lock_sequence(0x01); ASSERT_TRUE(asic.locked); } TEST_F(AsicTest, RelockAsicIfLockSeqReplayedExceptForLastByte) { ASSERT_TRUE(asic.locked); asic_poke_lock_sequence(0x01); for(const auto& val : lockSeq) { asic_poke_lock_sequence(val); } asic_poke_lock_sequence(0x01); ASSERT_FALSE(asic.locked); asic_poke_lock_sequence(0x01); for(const auto& val : lockSeq) { if(val == 0xcd) { // Only unlock once sequence is complete ASSERT_FALSE(asic.locked); asic_poke_lock_sequence(0x0b); } else { asic_poke_lock_sequence(val); } } ASSERT_TRUE(asic.locked); } TEST_F(AsicTest, UnlockWithRepetitionOfFirstTwoBytesOfSequence) { ASSERT_TRUE(asic.locked); // This is what Dick Tracy cartridge does // (Crazy Cars II also but it checks that the unlock is properly done and retries) asic_poke_lock_sequence(0x00); asic_poke_lock_sequence(0xff); for(const auto& val : lockSeq) { asic_poke_lock_sequence(val); } ASSERT_TRUE(asic.locked); asic_poke_lock_sequence(0xee); ASSERT_FALSE(asic.locked); } TEST_F(AsicTest, SetDMAControlAndStatusRegister) { asic_register_page_write(0x6C0F, 1); EXPECT_TRUE(asic.dma.ch[0].enabled); EXPECT_FALSE(asic.dma.ch[1].enabled); EXPECT_FALSE(asic.dma.ch[2].enabled); asic_register_page_write(0x6C0F, 2); EXPECT_FALSE(asic.dma.ch[0].enabled); EXPECT_TRUE(asic.dma.ch[1].enabled); EXPECT_FALSE(asic.dma.ch[2].enabled); asic_register_page_write(0x6C0F, 3); EXPECT_TRUE(asic.dma.ch[0].enabled); EXPECT_TRUE(asic.dma.ch[1].enabled); EXPECT_FALSE(asic.dma.ch[2].enabled); asic_register_page_write(0x6C0F, 0x4); EXPECT_FALSE(asic.dma.ch[0].enabled); EXPECT_FALSE(asic.dma.ch[1].enabled); EXPECT_TRUE(asic.dma.ch[2].enabled); } TEST_F(AsicTest, AsicReset) { asic.locked = false; asic.hscroll = 1; asic.vscroll = 2; asic.dma.ch[0].source_address = 0x1234; asic.dma.ch[0].loop_address = 0x1234; asic.dma.ch[0].prescaler = 42; asic.dma.ch[0].enabled = true; asic.dma.ch[0].interrupt = true; asic.dma.ch[0].pause_ticks = 42; asic.dma.ch[0].tick_cycles = 42; asic.dma.ch[0].loops = 42; asic_reset(); ASSERT_TRUE(asic.locked); ASSERT_EQ(0, asic.hscroll); ASSERT_EQ(0, asic.vscroll); ASSERT_EQ(0, asic.dma.ch[0].source_address); ASSERT_EQ(0, asic.dma.ch[0].loop_address); ASSERT_EQ(0, asic.dma.ch[0].prescaler); ASSERT_FALSE(asic.dma.ch[0].enabled); ASSERT_FALSE(asic.dma.ch[0].interrupt); ASSERT_EQ(0, asic.dma.ch[0].pause_ticks); ASSERT_EQ(0, asic.dma.ch[0].tick_cycles); ASSERT_EQ(0, asic.dma.ch[0].loops); // D0 of IVR is set to 1 at reset says Arnold 5 specs ASSERT_TRUE((asic.interrupt_vector & 1) == 1); } TEST_F(AsicTest, AsicDMACycleWriteBackDCSR) { std::vector<byte> membank0 = { 0x00, 0x00}; std::vector<byte> membank1(0x3000, 0); membank_config[0][0] = &membank0[0]; membank_write[1] = &membank1[0]; GateArray.RAM_config = 0; asic_reset(); asic.dma.ch[0].enabled = true; asic.dma.ch[0].source_address = 0x0; EXPECT_EQ(0, *(membank_write[1] + 0x2c00)); EXPECT_EQ(0, *(membank_write[1] + 0x2c0f)); asic_dma_cycle(); EXPECT_EQ(2, *(membank_write[1] + 0x2c00)); EXPECT_EQ(1, *(membank_write[1] + 0x2c0f)); } }
5,300
C++
.cpp
161
29.559006
127
0.696982
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,780
configuration.cpp
ColinPitrat_caprice32/test/configuration.cpp
#include <gtest/gtest.h> #include "cap32.h" #include "slotshandler.h" #include "configuration.h" #include <stdlib.h> #include <unistd.h> #include <fstream> #include <cstring> #include <errno.h> #include <string> // TODO(cpitrat): Cleaner way to handle this extern char chAppPath[_MAX_PATH + 1]; // TODO(cpitrat): Make this a list or vector in t_CPC extern t_disk_format disk_format[8]; class ConfigurationTest : public testing::Test { public: void SetUp() {} void TearDown() { for(auto f : tmpFilenames_) { ASSERT_EQ(0, unlink(f.c_str())); } } const std::string getTmpFilename(unsigned int idx) { while (tmpFilenames_.size() <= idx) { std::string fn; createTmpFile(fn); tmpFilenames_.push_back(fn); } return tmpFilenames_[idx]; } protected: std::vector<std::string> tmpFilenames_; config::Config configuration_; private: void createTmpFile(std::string &filename) { char tmpFilename[] = "test/.cap32_tmp_XXXXXX"; int fd = mkstemp(tmpFilename); ASSERT_GE(fd, 0); close(fd); filename = tmpFilename; } }; // "Integrated" tests (on a real file) TEST_F(ConfigurationTest, parseFileAndSaveBack) { std::ofstream configFile(getTmpFilename(0)); configFile << "# A comment in top\n" << "[system] # A comment at the end of the line\n" << "model=42\n" << "# This is an unused param:\n" << "unused=1\n" << "# Here is an empty line:\n" << "\n" << "resources_path=./resources\n" << "\n" << "[video]\n" << "resources_path=./toto\n" << "model = 8\n" << "[input]\n" << "resources_path=./directory with spaces\n" << "[sound]\n" << "enabled=1"; configFile.close(); configuration_.parseFile(getTmpFilename(0)); ASSERT_EQ(42, configuration_.getIntValue("system", "model", 0)); ASSERT_EQ(8, configuration_.getIntValue("video", "model", 0)); ASSERT_EQ(10, configuration_.getIntValue("sound", "model", 10)); ASSERT_EQ("./resources", configuration_.getStringValue("system", "resources_path", "none")); ASSERT_EQ("./toto", configuration_.getStringValue("video", "resources_path", "none")); ASSERT_EQ("./directory with spaces", configuration_.getStringValue("input", "resources_path", "none")); ASSERT_EQ("./default", configuration_.getStringValue("sound", "resources_path", "./default")); configuration_.saveToFile(getTmpFilename(1)); config::Config otherConfig; otherConfig.parseFile(getTmpFilename(1)); ASSERT_EQ(42, otherConfig.getIntValue("system", "model", 0)); ASSERT_EQ(8, otherConfig.getIntValue("video", "model", 0)); ASSERT_EQ(10, otherConfig.getIntValue("sound", "model", 10)); ASSERT_EQ("./resources", otherConfig.getStringValue("system", "resources_path", "none")); ASSERT_EQ("./toto", otherConfig.getStringValue("video", "resources_path", "none")); ASSERT_EQ("./directory with spaces", otherConfig.getStringValue("input", "resources_path", "none")); ASSERT_EQ("./default", otherConfig.getStringValue("sound", "resources_path", "./default")); } TEST_F(ConfigurationTest, parseFileDoesntExist) { configuration_.parseFile("/a/non/existing/file"); } TEST_F(ConfigurationTest, saveToFileAndMore) { std::string initalConfig = "# A comment in top\n" "[system] # A comment at the end of the line\n" "model=42\n"; std::string expectedConfig = "[system]\n" "model=42\n"; configuration_.parseString(initalConfig); configuration_.saveToFile(getTmpFilename(0)); std::ifstream ifs(getTmpFilename(0)); std::stringstream buffer; buffer << ifs.rdbuf(); ASSERT_EQ(expectedConfig, buffer.str()); } TEST_F(ConfigurationTest, saveToNonWritableFile) { // Make a non-writable config file auto configFileName = getTmpFilename(0); ASSERT_EQ(0, chmod(configFileName.c_str(), S_IRUSR|S_IRGRP|S_IROTH)); std::string initalConfig = "[system]\nmodel=42\n"; configuration_.parseString(initalConfig); EXPECT_FALSE(configuration_.saveToFile(getTmpFilename(0))); // This works when the file is writable ASSERT_EQ(0, chmod(configFileName.c_str(), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)); EXPECT_TRUE(configuration_.saveToFile(getTmpFilename(0))); } // TODO(cpitrat): test about every value in conf ? TEST_F(ConfigurationTest, loadConfigurationWithValidContent) { std::ofstream configFile(getTmpFilename(0)); configFile << "[system]\n" << "model=1\n" << "jumpers=30\n" << "ram_size=128\n" << "speed=32\n" << "printer=1\n" << "resources_path=./resources\n" << "[file]\n" << "fmt02=Test disk format,40,1,9,2,82,229,193,198,194,199,195,200,196,201,197\n" ; configFile.close(); t_CPC CPC[2]; loadConfiguration(CPC[0], getTmpFilename(0)); saveConfiguration(CPC[0], getTmpFilename(1)); loadConfiguration(CPC[1], getTmpFilename(1)); for(int i = 0; i < 2; ++i) { ASSERT_EQ(1, CPC[i].model) << "with i = " << i; ASSERT_EQ(30, CPC[i].jumpers) << "with i = " << i; ASSERT_EQ(128, CPC[i].ram_size) << "with i = " << i; ASSERT_EQ(32, CPC[i].speed) << "with i = " << i; ASSERT_EQ(1, CPC[i].limit_speed) << "with i = " << i; ASSERT_EQ(1, CPC[i].printer) << "with i = " << i; ASSERT_EQ("./resources", std::string(CPC[i].resources_path)) << "with i = " << i; // TODO(cpitrat): move disk_format array in t_CPC ASSERT_EQ("Test disk format", disk_format[2].label); ASSERT_EQ(40, disk_format[0].tracks); ASSERT_EQ(1, disk_format[0].sides); ASSERT_EQ(9, disk_format[0].sectors); ASSERT_EQ(2, disk_format[0].sector_size); ASSERT_EQ(82, disk_format[0].gap3_length); ASSERT_EQ(229, disk_format[0].filler_byte); ASSERT_EQ(193, disk_format[0].sector_ids[0][0]); ASSERT_EQ(198, disk_format[0].sector_ids[0][1]); ASSERT_EQ(194, disk_format[0].sector_ids[0][2]); ASSERT_EQ(199, disk_format[0].sector_ids[0][3]); ASSERT_EQ(195, disk_format[0].sector_ids[0][4]); ASSERT_EQ(200, disk_format[0].sector_ids[0][5]); ASSERT_EQ(196, disk_format[0].sector_ids[0][6]); ASSERT_EQ(201, disk_format[0].sector_ids[0][7]); ASSERT_EQ(197, disk_format[0].sector_ids[0][8]); } } // TODO(cpitrat): test about every value in conf ? TEST_F(ConfigurationTest, loadConfigurationWithInvalidValues) { std::ofstream configFile(getTmpFilename(0)); configFile << "[system]\n" << "model=4\n" // model should be <= 3 - default to 2 << "jumpers=255\n" // jumpers is & with 0x1e == 30 << "ram_size=704\n" // max ram size is 576 - moreover it's & with 704 << "speed=64\n" // max speed is 32 - will default to 4 << "printer=2\n" // printer should be 0 or 1 - it's & with 1 << "resources_path=\n" ; configFile.close(); ASSERT_NE(nullptr, getcwd(chAppPath, sizeof(chAppPath)-1)) << "getcwd error: " << strerror(errno); t_CPC CPC; loadConfiguration(CPC, getTmpFilename(0)); ASSERT_EQ(2, CPC.model); ASSERT_EQ(30, CPC.jumpers); ASSERT_EQ(576, CPC.ram_size); ASSERT_EQ(4, CPC.speed); ASSERT_EQ(1, CPC.limit_speed); ASSERT_EQ(0, CPC.printer); ASSERT_EQ(std::string(chAppPath) + "/resources", std::string(CPC.resources_path)); } // Real unit tests TEST_F(ConfigurationTest, hasValueReturnsFalseOnNonExistingSystem) { ASSERT_FALSE(config::hasValue(configuration_.getConfigMapForTests(), "system", "model")); } TEST_F(ConfigurationTest, hasValueReturnsFalseOnNonExistingKey) { std::string config = "[system]\nmodel=42"; configuration_.parseString(config); ASSERT_FALSE(config::hasValue(configuration_.getConfigMapForTests(), "system", "something")); } TEST_F(ConfigurationTest, hasValueReturnsTrueOnExistingKey) { std::string config = "[system]\nmodel=42"; configuration_.parseString(config); ASSERT_TRUE(config::hasValue(configuration_.getConfigMapForTests(), "system", "model")); } TEST_F(ConfigurationTest, getIntOnEmptyConfigReturnsDefault) { ASSERT_EQ(0, configuration_.getIntValue("system", "model", 0)); ASSERT_EQ(18, configuration_.getIntValue("system", "model", 18)); } TEST_F(ConfigurationTest, getIntOnParsedStringConfigReturnsParsedValue) { std::string config = "[system]\nmodel=42"; configuration_.parseString(config); ASSERT_EQ(42, configuration_.getIntValue("system", "model", 0)); } TEST_F(ConfigurationTest, getIntWithValueInMultipleSectionsReturnsTheRightOne) { std::string config = "[system]\nmodel=42\n[video]\nmodel=17"; configuration_.parseString(config); ASSERT_EQ(42, configuration_.getIntValue("system", "model", 0)); ASSERT_EQ(17, configuration_.getIntValue("video", "model", 0)); } TEST_F(ConfigurationTest, getStringOnEmptyConfigReturnsDefault) { ASSERT_EQ("/path/by/default", configuration_.getStringValue("system", "path", "/path/by/default")); ASSERT_EQ("/other/path/by/default", configuration_.getStringValue("system", "path", "/other/path/by/default")); } TEST_F(ConfigurationTest, getStringOnParsedStringConfigReturnsParsedValue) { std::string config = "[system]\npath=/path/defined"; configuration_.parseString(config); ASSERT_EQ("/path/defined", configuration_.getStringValue("system", "path", "/path/by/default")); } TEST_F(ConfigurationTest, getStringWithValueInMultipleSectionsReturnsTheRightOne) { std::string config = "[system]\npath=/path/system\n[video]\npath=/path/video"; configuration_.parseString(config); ASSERT_EQ("/path/system", configuration_.getStringValue("system", "path", "/path/by/default")); ASSERT_EQ("/path/video", configuration_.getStringValue("video", "path", "/path/by/default")); } TEST_F(ConfigurationTest, setStringValueModifiesValue) { std::string config = "[system]\npath=/path/original"; configuration_.parseString(config); ASSERT_EQ("/path/original", configuration_.getStringValue("system", "path", "/path/default")); configuration_.setStringValue("system", "path", "/path/modified"); ASSERT_EQ("/path/modified", configuration_.getStringValue("system", "path", "/path/default")); } TEST_F(ConfigurationTest, setIntValueModifiesValue) { std::string config = "[system]\nmodel=17"; configuration_.parseString(config); ASSERT_EQ(17, configuration_.getIntValue("system", "model", 0)); configuration_.setIntValue("system", "model", 42); ASSERT_EQ(42, configuration_.getIntValue("system", "model", 0)); } TEST_F(ConfigurationTest, toStreamDumpsConfig) { std::string config = "[system]\nmodel=1\n"; configuration_.parseString(config); std::ostringstream oss; configuration_.toStream(oss); ASSERT_EQ(config, oss.str()); } TEST_F(ConfigurationTest, parseDiskFormatValid2sides4sectors) { std::string diskFormat("DSK format label,42,2,4,1,82,229,1,2,3,4,5,6,7,8"); auto df = parseDiskFormat(diskFormat); auto dfString = serializeDiskFormat(df); ASSERT_EQ("DSK format label", df.label); ASSERT_EQ(42, df.tracks); ASSERT_EQ(2, df.sides); ASSERT_EQ(4, df.sectors); ASSERT_EQ(1, df.sector_size); ASSERT_EQ(82, df.gap3_length); ASSERT_EQ(229, df.filler_byte); ASSERT_EQ(1, df.sector_ids[0][0]); ASSERT_EQ(2, df.sector_ids[0][1]); ASSERT_EQ(3, df.sector_ids[0][2]); ASSERT_EQ(4, df.sector_ids[0][3]); ASSERT_EQ(5, df.sector_ids[1][0]); ASSERT_EQ(6, df.sector_ids[1][1]); ASSERT_EQ(7, df.sector_ids[1][2]); ASSERT_EQ(8, df.sector_ids[1][3]); ASSERT_EQ(diskFormat, dfString); } TEST_F(ConfigurationTest, parseDiskFormatValid1side5sectors) { std::string diskFormat("DSK format label,17,1,5,2,31,119,1,2,3,4,5"); auto df = parseDiskFormat(diskFormat); auto dfString = serializeDiskFormat(df); ASSERT_EQ("DSK format label", df.label); ASSERT_EQ(17, df.tracks); ASSERT_EQ(1, df.sides); ASSERT_EQ(5, df.sectors); ASSERT_EQ(2, df.sector_size); ASSERT_EQ(31, df.gap3_length); ASSERT_EQ(119, df.filler_byte); ASSERT_EQ(1, df.sector_ids[0][0]); ASSERT_EQ(2, df.sector_ids[0][1]); ASSERT_EQ(3, df.sector_ids[0][2]); ASSERT_EQ(4, df.sector_ids[0][3]); ASSERT_EQ(5, df.sector_ids[0][4]); ASSERT_EQ(diskFormat, dfString); } // TODO(cpitrat): Clarify why it behaves like this. // This test validates existing behaviour. The reason why missing sector is accepted // and why its default value is the sector's index + 1 is a mystery to me. TEST_F(ConfigurationTest, parseDiskFormatValidMissingSectors) { std::string diskFormat("DSK format label,17,2,4,2,31,119,9,10"); auto df = parseDiskFormat(diskFormat); auto dfString = serializeDiskFormat(df); ASSERT_EQ("DSK format label", df.label); ASSERT_EQ(17, df.tracks); ASSERT_EQ(2, df.sides); ASSERT_EQ(4, df.sectors); ASSERT_EQ(2, df.sector_size); ASSERT_EQ(31, df.gap3_length); ASSERT_EQ(119, df.filler_byte); ASSERT_EQ(9, df.sector_ids[0][0]); ASSERT_EQ(10, df.sector_ids[0][1]); ASSERT_EQ(3, df.sector_ids[0][2]); ASSERT_EQ(4, df.sector_ids[0][3]); ASSERT_EQ(1, df.sector_ids[1][0]); ASSERT_EQ(2, df.sector_ids[1][1]); ASSERT_EQ(3, df.sector_ids[1][2]); ASSERT_EQ(4, df.sector_ids[1][3]); ASSERT_EQ(diskFormat + ",3,4,1,2,3,4", dfString); // Description is completed with missing sectors }
13,358
C++
.cpp
332
35.879518
113
0.676407
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,781
z80.cpp
ColinPitrat_caprice32/test/z80.cpp
#include <gtest/gtest.h> #include "z80.h" #include "cap32.h" #include "z80_macros.h" extern byte *membank_read[4]; extern t_z80regs z80; namespace { class Z80Test : public testing::Test { public: static void SetUpTestCase() { z80_init_tables(); } }; TEST_F(Z80Test, ExecuteNOP) { byte membank0[1] = {0}; // TODO: Move cycle count to z80 //iCycleCount = 0; _R = 0; _PC = 0; membank_read[0] = membank0; z80_execute_instruction(); //EXPECT_EQ(4, iCycleCount); EXPECT_EQ(1, _PC); EXPECT_EQ(1, _R); } TEST_F(Z80Test, DecALoop) { // 3E 10 = ld a, 0x10 // 3D = dec a (<= loop) // C2 02 00 = jp nz, 0x0002 (=> loop) byte membank0[6] = { 0x3E, 0x10, 0x3D, 0xC2, 0x2, 0x0 }; // TODO: Move cycle count to z80 //iCycleCount = 0; _R = 0; _PC = 0; membank_read[0] = membank0; // ld a, 0x10 z80_execute_instruction(); for(int i = 0x10; i > 0; i--) { EXPECT_EQ(2, _PC); EXPECT_EQ(i, _A); // dec a z80_execute_instruction(); EXPECT_EQ(i-1, _A); EXPECT_EQ(3, _PC); // jp nz, 0x0002 z80_execute_instruction(); } EXPECT_EQ(0, _A); EXPECT_EQ(6, _PC); EXPECT_EQ(33, _R); } TEST_F(Z80Test, SqrtRoutine) { // Routine to compute SQRT of HL in A // 21 64 00 = ld hl, 100 // 11 01 00 = ld de, 1 // AF = xor a // 3D = dec a // ED 52 = sbc hl, de (<= sqrt_loop) // 13 = inc de // 13 = inc de // 3C = inc a // 30 F9 = jr nc,-5 (=> sqrt_loop) byte membank0[15] = { 0x21, 0x64, 0x00, 0x11, 0x01, 0x00, 0xAF, 0x3D, 0xED, 0x52, 0x13, 0x13, 0x3C, 0x30, 0xF9 }; // TODO: Move cycle count to z80 //iCycleCount = 0; _R = 0; _PC = 0; membank_read[0] = membank0; z80_execute_instruction(); EXPECT_EQ(0, _H); EXPECT_EQ(100, _L); z80_execute_instruction(); EXPECT_EQ(0, _D); EXPECT_EQ(1, _E); z80_execute_instruction(); EXPECT_EQ(0, _A); z80_execute_instruction(); EXPECT_EQ(0xFF, _A); while(_PC != 15) { z80_execute_instruction(); } EXPECT_EQ(10, _A); } }
2,039
C++
.cpp
88
20.136364
115
0.584798
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,782
disk.cpp
ColinPitrat_caprice32/test/disk.cpp
#include <gtest/gtest.h> #include "disk.h" namespace { class SectorReadTest : public testing::Test { public: SectorReadTest() { data[0] = 1; data[512] = 2; sector.setData(data); } protected: t_sector sector; unsigned char data[1024] = {0}; }; TEST_F(SectorReadTest, NormalSector) { sector.setSizes(1024, 1024); unsigned char* read1 = sector.getDataForRead(); unsigned char* read2 = sector.getDataForRead(); ASSERT_EQ(1, read1[0]); ASSERT_EQ(1, read2[0]); } TEST_F(SectorReadTest, WeakSector) { sector.setSizes(512, 1024); unsigned char* read1 = sector.getDataForRead(); unsigned char* read2 = sector.getDataForRead(); // There's no reason to force a given order as long as 2 consecutive reads return 2 different versions ASSERT_NE(read1[0], read2[0]); // And the value is one of the 2 provided ASSERT_TRUE(read1[0] == 1 || read1[0] == 2); ASSERT_TRUE(read2[0] == 1 || read2[0] == 2); } TEST_F(SectorReadTest, LongSector) { // Should work just as a normal sector of size 512 sector.setSizes(1024, 512); unsigned char* read1 = sector.getDataForRead(); unsigned char* read2 = sector.getDataForRead(); ASSERT_EQ(1, read1[0]); ASSERT_EQ(1, read2[0]); ASSERT_EQ(512, sector.getTotalSize()); } }
1,285
C++
.cpp
47
24.297872
104
0.694444
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,783
wg_application.cpp
ColinPitrat_caprice32/test/wg_application.cpp
#include <gtest/gtest.h> #include "wg_error.h" #include "wg_application.h" #include "cap32.h" #include <string> extern t_CPC CPC; TEST(CApplicationTest, InitThrowExceptionWhenFailToFindResources) { wGui::CApplication app(/*pWindow=*/nullptr); CPC.resources_path = "does_not_exist"; try { app.Init(); FAIL() << "CApplication::Init() with unexisting resource path didn't throw an exception"; } catch(wGui::Wg_Ex_App& e) { // We don't care which file is not found, the important part is that the // message mention the failing path std::string expected("File not found: does_not_exist"); ASSERT_EQ(expected, e.std_what().substr(0, expected.size())); } catch(...) { FAIL() << "CApplication::Init() with unexisting resource path threw an unexpected exception"; } }
805
C++
.cpp
22
33.545455
97
0.709512
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,784
psg.cpp
ColinPitrat_caprice32/test/psg.cpp
#include <gtest/gtest.h> #include "cap32.h" #include "types.h" // Validate that alignment is correct between bytes & words structs (cf issue #104) TEST(PsgTest, RegisterAYAlignment) { t_PSG psg; psg.RegisterAY.TonALo = 3; psg.RegisterAY.TonAHi = 5; EXPECT_EQ(*reinterpret_cast<word *>(&psg.RegisterAY.TonALo), psg.RegisterAY.TonA); psg.RegisterAY.TonBLo = 3; psg.RegisterAY.TonBHi = 5; EXPECT_EQ(*reinterpret_cast<word *>(&psg.RegisterAY.TonBLo), psg.RegisterAY.TonB); psg.RegisterAY.TonCLo = 3; psg.RegisterAY.TonCHi = 5; EXPECT_EQ(*reinterpret_cast<word *>(&psg.RegisterAY.TonCLo), psg.RegisterAY.TonC); psg.RegisterAY.EnvelopeLo = 3; psg.RegisterAY.EnvelopeHi = 5; EXPECT_EQ(*reinterpret_cast<word *>(&psg.RegisterAY.EnvelopeLo), psg.RegisterAY.Envelope); }
802
C++
.cpp
20
37.05
93
0.734615
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,785
InputMapper.cpp
ColinPitrat_caprice32/test/InputMapper.cpp
#include <gtest/gtest.h> #include "cap32.h" #include "keyboard.h" #include <string> extern t_CPC CPC; class InputMapperTest : public testing::Test { public: void SetUp() { CPC.resources_path = "resources"; CPC.InputMapper = new InputMapper(&CPC); CPC.InputMapper->init(); } }; TEST_F(InputMapperTest, StringToEventsSimpleString) { CPC.kbd_layout ="keymap_us.map"; CPC.keyboard = 0; CPC.InputMapper->init(); std::string input = "cat"; auto tmp = CPC.InputMapper->StringToEvents(input); std::vector<SDL_Event> result(tmp.begin(), tmp.end()); ASSERT_EQ(6, result.size()); // Result must be an alternance of key down / key up for(int i = 0; i < 3; ++i) { ASSERT_EQ(SDL_KEYDOWN, result[2*i].key.type); ASSERT_EQ(SDL_PRESSED, result[2*i].key.state); ASSERT_EQ(SDL_KEYUP, result[2*i+1].key.type); ASSERT_EQ(SDL_RELEASED, result[2*i+1].key.state); } // Only keys without modifier for(int i = 0; i < 6; ++i) { ASSERT_EQ(KMOD_NONE, result[i].key.keysym.mod); } // Keys correspond to the input string ASSERT_EQ(SDLK_c, result[0].key.keysym.sym); ASSERT_EQ(SDLK_c, result[1].key.keysym.sym); ASSERT_EQ(SDLK_a, result[2].key.keysym.sym); ASSERT_EQ(SDLK_a, result[3].key.keysym.sym); ASSERT_EQ(SDLK_t, result[4].key.keysym.sym); ASSERT_EQ(SDLK_t, result[5].key.keysym.sym); } TEST_F(InputMapperTest, StringToEventsWithEscapedChar) { CPC.kbd_layout ="keymap_us.map"; CPC.keyboard = 0; CPC.InputMapper->init(); std::string input = "run\"s\btest\n"; auto tmp = CPC.InputMapper->StringToEvents(input); std::vector<SDL_Event> result(tmp.begin(), tmp.end()); ASSERT_EQ(22, result.size()); ASSERT_EQ(SDLK_n, result[5].key.keysym.sym); // On US keyboard, " is on ' key with shift pressed ASSERT_EQ(SDLK_QUOTE, result[6].key.keysym.sym); ASSERT_EQ(SDLK_s, result[9].key.keysym.sym); ASSERT_EQ(SDLK_BACKSPACE, result[10].key.keysym.sym); ASSERT_EQ(SDLK_t, result[19].key.keysym.sym); ASSERT_EQ(SDLK_RETURN, result[20].key.keysym.sym); } TEST_F(InputMapperTest, StringToEventsWithSpecialChar) { CPC.kbd_layout ="keymap_us.map"; CPC.keyboard = 0; CPC.InputMapper->init(); std::string input = "\a"; input += CPC_ESC; auto tmp = CPC.InputMapper->StringToEvents(input); std::vector<SDL_Event> result(tmp.begin(), tmp.end()); ASSERT_EQ(2, result.size()); // First key event is pressing ESCAPE ASSERT_EQ(SDLK_ESCAPE, result[0].key.keysym.sym); ASSERT_EQ(KMOD_NONE, result[0].key.keysym.mod); ASSERT_EQ(SDL_KEYDOWN, result[0].key.type); ASSERT_EQ(SDL_PRESSED, result[0].key.state); // Second key event is releasing ESCAPE ASSERT_EQ(SDLK_ESCAPE, result[0].key.keysym.sym); ASSERT_EQ(KMOD_NONE, result[1].key.keysym.mod); ASSERT_EQ(SDL_KEYUP, result[1].key.type); ASSERT_EQ(SDL_RELEASED, result[1].key.state); } TEST_F(InputMapperTest, Keymapping) { SDL_Keysym keysym; CPC.kbd_layout ="keymap_us.map"; CPC.keyboard = 0; CPC.InputMapper->init(); // Exclaim keysym.sym = SDLK_1; keysym.mod = KMOD_LSHIFT; ASSERT_EQ(0x80 | MOD_CPC_SHIFT, CPC.InputMapper->CPCscancodeFromKeysym(keysym)); CPC.kbd_layout ="keymap_uk_linux.map"; CPC.keyboard = 0; CPC.InputMapper->init(); // Pound keysym.sym = SDLK_3; keysym.mod = KMOD_RSHIFT; ASSERT_EQ(0x30 | MOD_CPC_SHIFT, CPC.InputMapper->CPCscancodeFromKeysym(keysym)); CPC.kbd_layout ="keymap_fr_win.map"; CPC.keyboard = 1; CPC.InputMapper->init(); // E acute keysym.sym = SDLK_2; keysym.mod = KMOD_NONE; ASSERT_EQ(0x81, CPC.InputMapper->CPCscancodeFromKeysym(keysym)); CPC.kbd_layout ="keymap_es_linux.map"; CPC.keyboard = 2; CPC.InputMapper->init(); // N Tilde keysym.sym = 241; // Magic value for the non-existent SDLK_nTILDE keysym.mod = KMOD_LSHIFT; ASSERT_EQ(0x35 | MOD_CPC_SHIFT, CPC.InputMapper->CPCscancodeFromKeysym(keysym)); }
3,872
C++
.cpp
111
31.81982
82
0.700482
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,786
stringutils.cpp
ColinPitrat_caprice32/test/stringutils.cpp
#include <gtest/gtest.h> #include "stringutils.h" #include <string> TEST(StringUtils, SplitOnEmptyStringReturnsEmptyVector) { std::string toSplit = ""; std::vector<std::string> result = stringutils::split(toSplit, ','); ASSERT_EQ(0, result.size()); } TEST(StringUtils, SplitOnStringWithoutDelimiterReturnsOneElement) { std::string toSplit = "a string;without comma."; std::vector<std::string> result = stringutils::split(toSplit, ','); ASSERT_EQ(1, result.size()); ASSERT_EQ(toSplit, result[0]); } TEST(StringUtils, SplitOnComma) { std::string toSplit = "value1,value2,value3"; std::vector<std::string> result = stringutils::split(toSplit, ','); ASSERT_EQ(3, result.size()); ASSERT_EQ("value1", result[0]); ASSERT_EQ("value2", result[1]); ASSERT_EQ("value3", result[2]); } TEST(StringUtils, SplitOnColon) { std::string toSplit = "v1:v2:v3:v4:v5"; std::vector<std::string> result = stringutils::split(toSplit, ':'); ASSERT_EQ(5, result.size()); ASSERT_EQ("v1", result[0]); ASSERT_EQ("v2", result[1]); ASSERT_EQ("v3", result[2]); ASSERT_EQ("v4", result[3]); ASSERT_EQ("v5", result[4]); } TEST(StringUtils, SplitWithEmpty) { std::string toSplit = "value1,,value3"; std::vector<std::string> result = stringutils::split(toSplit, ','); ASSERT_EQ(3, result.size()); ASSERT_EQ("value1", result[0]); ASSERT_EQ("", result[1]); ASSERT_EQ("value3", result[2]); } TEST(StringUtils, SplitWithEmptyIgnore) { std::string toSplit = "value1,,value3"; std::vector<std::string> result = stringutils::split(toSplit, ',', /*ignore_empty=*/true); ASSERT_EQ(2, result.size()); ASSERT_EQ("value1", result[0]); ASSERT_EQ("value3", result[1]); } TEST(StringUtils, TrimCharNotPresentInString) { std::string toTrim = "a test string"; auto result = stringutils::trim(toTrim, '"'); ASSERT_EQ(toTrim, result); } TEST(StringUtils, TrimCharPresentInMiddleOfStringOnly) { std::string toTrim = "a test string"; auto result = stringutils::trim(toTrim, ' '); ASSERT_EQ(toTrim, result); } TEST(StringUtils, TrimCharAtBeginningOfString) { std::string toTrim = "--a test string"; auto result = stringutils::trim(toTrim, '-'); ASSERT_EQ("a test string", result); } TEST(StringUtils, TrimCharAtEndOfString) { std::string toTrim = "a test string--"; auto result = stringutils::trim(toTrim, '-'); ASSERT_EQ("a test string", result); } TEST(StringUtils, TrimCharOccuringMultipleTimesInString) { std::string toTrim = "\"a \"test\" string\""; auto result = stringutils::trim(toTrim, '"'); ASSERT_EQ("a \"test\" string", result); } TEST(StringUtils, TrimStringWithOnlyOneCharAndTwoDelimitors) { std::string toTrim = "\"a\""; auto result = stringutils::trim(toTrim, '"'); ASSERT_EQ("a", result); } TEST(StringUtils, TrimStringWithOnlyTwoDelimitors) { std::string toTrim = "\"\""; auto result = stringutils::trim(toTrim, '"'); ASSERT_EQ("", result); } TEST(StringUtils, TrimStringWithOnlyOneDelimitor) { std::string toTrim = "\""; auto result = stringutils::trim(toTrim, '"'); ASSERT_EQ("", result); } TEST(StringUtils, LowerOnEmptyString) { std::string toLower = ""; auto result = stringutils::lower(toLower); ASSERT_EQ("", result); } TEST(StringUtils, LowerOnUpperCaseString) { std::string toLower = "ABCDEF"; auto result = stringutils::lower(toLower); ASSERT_EQ("abcdef", result); } TEST(StringUtils, LowerOnLowerCaseString) { std::string toLower = "ghijkl"; auto result = stringutils::lower(toLower); ASSERT_EQ("ghijkl", result); } TEST(StringUtils, UpperOnEmptyString) { std::string toUpper = ""; auto result = stringutils::upper(toUpper); ASSERT_EQ("", result); } TEST(StringUtils, UpperOnUpperCaseString) { std::string toUpper = "ABCDEF"; auto result = stringutils::upper(toUpper); ASSERT_EQ("ABCDEF", result); } TEST(StringUtils, UpperOnLowerCaseString) { std::string toUpper = "ghijkl"; auto result = stringutils::upper(toUpper); ASSERT_EQ("GHIJKL", result); } TEST(StringUtils, Replace) { ASSERT_EQ("NothingToReplace", stringutils::replace("NothingToReplace", "NotFound", "Something")); ASSERT_EQ("SomethingToReplace", stringutils::replace("SomethingFoo", "Foo", "ToReplace")); ASSERT_EQ("ReplaceOnlyOnce", stringutils::replace("ReplaceOnceOnce", "Once", "Only")); ASSERT_EQ("EmptySearch", stringutils::replace("Search", "", "Empty")); ASSERT_EQ("EmptyReplace", stringutils::replace("EmptyReplaceWorks", "Works", "")); ASSERT_EQ("", stringutils::replace("", "EmptyString", "Nothing")); } TEST(StringUtils, SplitPathOnUnix) { std::string path = "/usr/bin/cap32"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("/usr/bin/", dirname); ASSERT_EQ("cap32", filename); } TEST(StringUtils, SplitPathOnUnixWithExtension) { std::string path = "/home/user/caprice32/disk/test.dsk"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("/home/user/caprice32/disk/", dirname); ASSERT_EQ("test.dsk", filename); } TEST(StringUtils, SplitPathOnUnixWithSpaces) { std::string path = "/home/user name/caprice32/disk/test disk.dsk"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("/home/user name/caprice32/disk/", dirname); ASSERT_EQ("test disk.dsk", filename); } TEST(StringUtils, SplitPathOnUnixWithBackslash) { std::string path = "/home/user\\ name/caprice32/disk/test\\ disk.dsk"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("/home/user\\ name/caprice32/disk/", dirname); ASSERT_EQ("test\\ disk.dsk", filename); } TEST(StringUtils, SplitPathWithoutDelimiter) { std::string path = "filename"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("./", dirname); ASSERT_EQ("filename", filename); } TEST(StringUtils, SplitPathOnWindows) { std::string path = "C:\\Users\\username\\caprice32\\disk\\test.dsk"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("C:\\Users\\username\\caprice32\\disk\\", dirname); ASSERT_EQ("test.dsk", filename); } // This basically doesn't work but it's how it used to be implemented // It should be OK as long as people don't mix slash and backslashes // TODO(cpitrat): Could be nice (and easy) to fix though. TEST(StringUtils, SplitInvalidPathOnWindowsWithSlash) { std::string path = "C:\\Users\\username\\caprice32/disk\\test.dsk"; std::string dirname, filename; stringutils::splitPath(path, dirname, filename); ASSERT_EQ("C:\\Users\\username\\caprice32/", dirname); ASSERT_EQ("disk\\test.dsk", filename); }
6,742
C++
.cpp
205
30.360976
99
0.719554
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,787
argparse.cpp
ColinPitrat_caprice32/test/argparse.cpp
#include <gtest/gtest.h> #include "cap32.h" #include "argparse.h" #include "keyboard.h" #include <string> TEST(ArgParseTest, parseArgsNoArg) { const char *argv[] = {"./cap32"}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(1, const_cast<char **>(argv), slot_list, args); ASSERT_EQ(0, slot_list.size()); } TEST(ArgParseTest, parseArgsOneArg) { const char *argv[] = {"./cap32", "./foo.dsk"}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(2, const_cast<char **>(argv), slot_list, args); ASSERT_EQ(1, slot_list.size()); ASSERT_EQ("./foo.dsk", slot_list.at(0)); } TEST(ArgParseTest, parseArgsSeveralArgs) { const char *argv[] = {"./cap32", "./foo.dsk", "bar.zip", "0", "__"}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(5, const_cast<char **>(argv), slot_list, args); ASSERT_EQ(4, slot_list.size()); for (int i=1; i < 5; i++) ASSERT_EQ(argv[i], slot_list.at(i-1)); } TEST(argParseTest, cfgFileArgsSwitch) { const char *argv[] = {"./caprice32", "--cfg_file=/home/caprice32/cap32.cfg"}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(2, const_cast<char **>(argv), slot_list, args); ASSERT_EQ("/home/caprice32/cap32.cfg", args.cfgFilePath); } TEST(argParseTest, cfgOverrideValid) { const char *argv[] = {"./caprice32", "--override=system.model=3", "--override=control.kbd_layout=keymap_us.map", "--override=no.value="}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(4, const_cast<char **>(argv), slot_list, args); ASSERT_EQ("3", args.cfgOverrides["system"]["model"]); ASSERT_EQ("keymap_us.map", args.cfgOverrides["control"]["kbd_layout"]); ASSERT_EQ("", args.cfgOverrides["no"]["value"]); } TEST(argParseTest, cfgOverrideInvalid) { const char *argv[] = {"./caprice32", "--override=no.value", "--override=nosection=3", "--override=emptyitem.=3", "--override=.emptysection=3", "--override==nokey"}; CapriceArgs args; std::vector<std::string> slot_list; parseArguments(6, const_cast<char **>(argv), slot_list, args); ASSERT_TRUE(args.cfgOverrides.empty()); } TEST(argParseTest, replaceCap32KeysNoKeyword) { std::string command = "print \"Hello, world !\""; ASSERT_EQ(command, replaceCap32Keys(command)); } TEST(argParseTest, replaceCap32KeysKeywords) { // expected // Which is: "print \"Hello, world !\"\f\b\f\0" // replaceCap32Keys(command) // Which is: "print \"Hello, world !\"\f\t\f\0" std::string command = "print \"Hello, world !\"CAP32_SCRNSHOTCAP32_EXIT"; std::string expected = "print \"Hello, world !\"\f\x9\f"; expected += '\0'; ASSERT_EQ(expected, replaceCap32Keys(command)); } TEST(argParseTest, replaceCap32KeysRepeatedKeywords) { std::string command = "print \"Hello\"CAP32_SCRNSHOT ; print \",\" ; CAP32_SCRNSHOT ; print \"world !\" ; CAP32_SCRNSHOT"; std::string expected = "print \"Hello\"\f\x9 ; print \",\" ; \f\x9 ; print \"world !\" ; \f\x9"; ASSERT_EQ(expected, replaceCap32Keys(command)); }
3,078
C++
.cpp
80
35.55
167
0.675067
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,788
phazer.cpp
ColinPitrat_caprice32/src/phazer.cpp
#include "phazer.h" std::string PhazerType::ToString() { switch(value) { case None: return "off"; case AmstradMagnumPhaser: return "Amstrad Magnum Phaser"; case TrojanLightPhazer: return "Trojan Light Phazer"; default: return "Unimplemented"; } } PhazerType PhazerType::Next() { auto new_value = value + 1; if (new_value == LastPhazerType) { return PhazerType(None); } return PhazerType(Value(new_value)); }
446
C++
.cpp
20
19.4
61
0.712264
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,789
cartridge.cpp
ColinPitrat_caprice32/src/cartridge.cpp
#include "cartridge.h" #include "types.h" #include "errors.h" #include "log.h" #include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <memory> #include <string> const uint32_t CARTRIDGE_NB_PAGES = 32; const uint32_t CARTRIDGE_PAGE_SIZE = 16*1024; const uint32_t CARTRIDGE_MAX_SIZE = CARTRIDGE_NB_PAGES*CARTRIDGE_PAGE_SIZE; std::unique_ptr<byte[]> pbCartridgeImage = nullptr; byte *pbCartridgePages[CARTRIDGE_NB_PAGES] = { nullptr }; extern byte* pbROMlo; void cpr_eject () { pbCartridgeImage = nullptr; for(auto &page : pbCartridgePages) { page = nullptr; } } int cartridge_init() { pbCartridgeImage.reset(new byte [CARTRIDGE_MAX_SIZE]); // attempt to allocate the general purpose buffer for(uint32_t i = 0; i < CARTRIDGE_NB_PAGES; ++i) { pbCartridgePages[i] = &pbCartridgeImage[i*CARTRIDGE_PAGE_SIZE]; } return 0; } int cpr_load (const std::string &filename) { LOG_DEBUG("cpr_load " << filename); FILE *pfile; if ((pfile = fopen(filename.c_str(), "rb")) == nullptr) { LOG_DEBUG("File not found: " << filename); return ERR_FILE_NOT_FOUND; } int iRetCode = cpr_load(pfile); fclose(pfile); return iRetCode; } uint32_t extractChunkSize(byte *pChunk) { return static_cast<uint32_t>(pChunk[4]) + (static_cast<uint32_t>(pChunk[5]) << 8) + (static_cast<uint32_t>(pChunk[6]) << 16) + (static_cast<uint32_t>(pChunk[7]) << 24); } int cpr_load (FILE *pfile) { const int CPR_HEADER_SIZE = 12; const int CPR_CHUNK_ID_SIZE = 4; const int CPR_CHUNK_HEADER_SIZE = 8; cpr_eject(); int rc = cartridge_init(); if (rc != 0) { return rc; } std::unique_ptr<byte[]> tmpBuffer(new byte[CARTRIDGE_MAX_SIZE]); byte *pbTmpBuffer = tmpBuffer.get(); // Check RIFF header if(fread(pbTmpBuffer, CPR_HEADER_SIZE, 1, pfile) != 1) { // read RIFF header LOG_DEBUG("Cartridge file less than " << CPR_HEADER_SIZE << " bytes long !"); return ERR_CPR_INVALID; } if (memcmp(pbTmpBuffer, "RIFF", 4) != 0) { // RIFF file LOG_DEBUG("Cartridge file is not a RIFF file"); return ERR_CPR_INVALID; } if (memcmp(pbTmpBuffer + 8, "AMS!", 4) != 0) { // CPR file LOG_DEBUG("Cartridge file is not a CPR file"); return ERR_CPR_INVALID; } uint32_t totalSize = extractChunkSize(pbTmpBuffer); LOG_DEBUG("CPR size: " << totalSize) // Extract all chunks uint32_t offset = CPR_HEADER_SIZE; uint32_t cartridgeOffset = 0; while(offset < totalSize) { if(fread(pbTmpBuffer, CPR_CHUNK_HEADER_SIZE, 1, pfile) != 1) { // read chunk header LOG_DEBUG("Failed reading chunk header"); return ERR_CPR_INVALID; } offset += CPR_CHUNK_HEADER_SIZE; byte chunkId[CPR_CHUNK_ID_SIZE+1]; memcpy(chunkId, pbTmpBuffer, CPR_CHUNK_ID_SIZE); chunkId[CPR_CHUNK_ID_SIZE] = '\0'; uint32_t chunkSize = extractChunkSize(pbTmpBuffer); LOG_DEBUG("Chunk '" << chunkId << "' at offset " << offset << " of size " << chunkSize); // Normal chunk size is 16kB // If smaller, it must be filled with 0 up to this limit // If bigger, what is after must be ignored uint32_t chunkKept = std::min(chunkSize, CARTRIDGE_PAGE_SIZE); // If chunk size is not even, there's a pad byte at the end of it if (chunkKept % 2 != 0) { chunkKept++; } // A chunk can be empty (observed on some CPR files) if(chunkKept > 0) { if(fread(&pbCartridgeImage[cartridgeOffset], chunkKept, 1, pfile) != 1) { // read chunk content LOG_DEBUG("Failed reading chunk content"); return ERR_CPR_INVALID; } if(chunkKept < CARTRIDGE_PAGE_SIZE) { // TODO: use the chunkId to identify the cartridge page to set (cbXX with XX between 00 and 31) // This would require intializing the whole to 0 before instead of filling what remains at the end // Not sure if there are some CPR with unordered pages but this seems to be allowed in theory memset(&pbCartridgeImage[cartridgeOffset+chunkKept], 0, CARTRIDGE_PAGE_SIZE-chunkKept); } else if(chunkKept < chunkSize) { LOG_DEBUG("This chunk is bigger than the max allowed size !!!"); if(fread(pbTmpBuffer, chunkSize-chunkKept, 1, pfile) != 1) { // read excessive chunk content LOG_DEBUG("Failed reading chunk content"); return ERR_CPR_INVALID; } } cartridgeOffset += CARTRIDGE_PAGE_SIZE; offset += chunkSize; } } LOG_DEBUG("Final offset: " << offset); LOG_DEBUG("Final cartridge offset: " << cartridgeOffset); memset(&pbCartridgeImage[cartridgeOffset], 0, CARTRIDGE_MAX_SIZE-cartridgeOffset); pbROMlo = &pbCartridgeImage[0]; return 0; }
4,851
C++
.cpp
127
32.645669
110
0.647759
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,790
keyboard.cpp
ColinPitrat_caprice32/src/keyboard.cpp
#include "keyboard.h" #include <iostream> #include <fstream> #include <map> #include <set> #include <string> #include "cap32.h" #include "fileutils.h" #include "log.h" extern byte bit_values[8]; extern t_CPC CPC; const CPCScancode InputMapper::cpc_kbd[CPC_KEYBOARD_NUM][CPC_KEY_NUM] = { { // original CPC keyboard 0x40, // CPC_0 0x80, // CPC_1 0x81, // CPC_2 0x71, // CPC_3 0x70, // CPC_4 0x61, // CPC_5 0x60, // CPC_6 0x51, // CPC_7 0x50, // CPC_8 0x41, // CPC_9 0x85 | MOD_CPC_SHIFT, // CPC_A 0x66 | MOD_CPC_SHIFT, // CPC_B 0x76 | MOD_CPC_SHIFT, // CPC_C 0x75 | MOD_CPC_SHIFT, // CPC_D 0x72 | MOD_CPC_SHIFT, // CPC_E 0x65 | MOD_CPC_SHIFT, // CPC_F 0x64 | MOD_CPC_SHIFT, // CPC_G 0x54 | MOD_CPC_SHIFT, // CPC_H 0x43 | MOD_CPC_SHIFT, // CPC_I 0x55 | MOD_CPC_SHIFT, // CPC_J 0x45 | MOD_CPC_SHIFT, // CPC_K 0x44 | MOD_CPC_SHIFT, // CPC_L 0x46 | MOD_CPC_SHIFT, // CPC_M 0x56 | MOD_CPC_SHIFT, // CPC_N 0x42 | MOD_CPC_SHIFT, // CPC_O 0x33 | MOD_CPC_SHIFT, // CPC_P 0x83 | MOD_CPC_SHIFT, // CPC_Q 0x62 | MOD_CPC_SHIFT, // CPC_R 0x74 | MOD_CPC_SHIFT, // CPC_S 0x63 | MOD_CPC_SHIFT, // CPC_T 0x52 | MOD_CPC_SHIFT, // CPC_U 0x67 | MOD_CPC_SHIFT, // CPC_V 0x73 | MOD_CPC_SHIFT, // CPC_W 0x77 | MOD_CPC_SHIFT, // CPC_X 0x53 | MOD_CPC_SHIFT, // CPC_Y 0x87 | MOD_CPC_SHIFT, // CPC_Z 0x85, // CPC_a 0x66, // CPC_b 0x76, // CPC_c 0x75, // CPC_d 0x72, // CPC_e 0x65, // CPC_f 0x64, // CPC_g 0x54, // CPC_h 0x43, // CPC_i 0x55, // CPC_j 0x45, // CPC_k 0x44, // CPC_l 0x46, // CPC_m 0x56, // CPC_n 0x42, // CPC_o 0x33, // CPC_p 0x83, // CPC_q 0x62, // CPC_r 0x74, // CPC_s 0x63, // CPC_t 0x52, // CPC_u 0x67, // CPC_v 0x73, // CPC_w 0x77, // CPC_x 0x53, // CPC_y 0x87, // CPC_z 0x85 | MOD_CPC_CTRL, // CPC_CTRL_a 0x66 | MOD_CPC_CTRL, // CPC_CTRL_b 0x76 | MOD_CPC_CTRL, // CPC_CTRL_c 0x75 | MOD_CPC_CTRL, // CPC_CTRL_d 0x72 | MOD_CPC_CTRL, // CPC_CTRL_e 0x65 | MOD_CPC_CTRL, // CPC_CTRL_f 0x64 | MOD_CPC_CTRL, // CPC_CTRL_g 0x54 | MOD_CPC_CTRL, // CPC_CTRL_h 0x43 | MOD_CPC_CTRL, // CPC_CTRL_i 0x55 | MOD_CPC_CTRL, // CPC_CTRL_j 0x45 | MOD_CPC_CTRL, // CPC_CTRL_k 0x44 | MOD_CPC_CTRL, // CPC_CTRL_l 0x46 | MOD_CPC_CTRL, // CPC_CTRL_m 0x56 | MOD_CPC_CTRL, // CPC_CTRL_n 0x42 | MOD_CPC_CTRL, // CPC_CTRL_o 0x33 | MOD_CPC_CTRL, // CPC_CTRL_p 0x83 | MOD_CPC_CTRL, // CPC_CTRL_q 0x62 | MOD_CPC_CTRL, // CPC_CTRL_r 0x74 | MOD_CPC_CTRL, // CPC_CTRL_s 0x63 | MOD_CPC_CTRL, // CPC_CTRL_t 0x52 | MOD_CPC_CTRL, // CPC_CTRL_u 0x67 | MOD_CPC_CTRL, // CPC_CTRL_v 0x73 | MOD_CPC_CTRL, // CPC_CTRL_w 0x77 | MOD_CPC_CTRL, // CPC_CTRL_x 0x53 | MOD_CPC_CTRL, // CPC_CTRL_y 0x87 | MOD_CPC_CTRL, // CPC_CTRL_z 0x40 | MOD_CPC_CTRL, // CPC_CTRL_0 0x80 | MOD_CPC_CTRL, // CPC_CTRL_1 0x81 | MOD_CPC_CTRL, // CPC_CTRL_2 0x71 | MOD_CPC_CTRL, // CPC_CTRL_3 0x70 | MOD_CPC_CTRL, // CPC_CTRL_4 0x61 | MOD_CPC_CTRL, // CPC_CTRL_5 0x60 | MOD_CPC_CTRL, // CPC_CTRL_6 0x51 | MOD_CPC_CTRL, // CPC_CTRL_7 0x50 | MOD_CPC_CTRL, // CPC_CTRL_8 0x41 | MOD_CPC_CTRL, // CPC_CTRL_9 0x00 | MOD_CPC_CTRL, // CPC_CTRL_UP 0x02 | MOD_CPC_CTRL, // CPC_CTRL_DOWN 0x10 | MOD_CPC_CTRL, // CPC_CTRL_LEFT 0x01 | MOD_CPC_CTRL, // CPC_CTRL_RIGHT 0x60 | MOD_CPC_SHIFT, // CPC_AMPERSAND 0x35 | MOD_CPC_SHIFT, // CPC_ASTERISK 0x32, // CPC_AT 0x26 | MOD_CPC_SHIFT, // CPC_BACKQUOTE 0x26, // CPC_BACKSLASH 0x86, // CPC_CAPSLOCK 0x20, // CPC_CLR 0x35, // CPC_COLON 0x47, // CPC_COMMA 0x27, // CPC_CONTROL 0x11, // CPC_COPY 0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN 0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT 0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT 0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP 0x02, // CPC_CUR_DOWN 0x10, // CPC_CUR_LEFT 0x01, // CPC_CUR_RIGHT 0x00, // CPC_CUR_UP 0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL 0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN 0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN 0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL 0x81 | MOD_CPC_SHIFT, // CPC_DBLQUOTE 0x97, // CPC_DEL 0x70 | MOD_CPC_SHIFT, // CPC_DOLLAR 0x06, // CPC_ENTER 0x31 | MOD_CPC_SHIFT, // CPC_EQUAL 0x82, // CPC_ESC 0x80 | MOD_CPC_SHIFT, // CPC_EXCLAMATN 0x17, // CPC_F0 0x15, // CPC_F1 0x16, // CPC_F2 0x05, // CPC_F3 0x24, // CPC_F4 0x14, // CPC_F5 0x04, // CPC_F6 0x12, // CPC_F7 0x13, // CPC_F8 0x03, // CPC_F9 0x17 | MOD_CPC_CTRL, // CPC_CTRL_F0 0x15 | MOD_CPC_CTRL, // CPC_CTRL_F1 0x16 | MOD_CPC_CTRL, // CPC_CTRL_F2 0x05 | MOD_CPC_CTRL, // CPC_CTRL_F3 0x24 | MOD_CPC_CTRL, // CPC_CTRL_F4 0x14 | MOD_CPC_CTRL, // CPC_CTRL_F5 0x04 | MOD_CPC_CTRL, // CPC_CTRL_F6 0x12 | MOD_CPC_CTRL, // CPC_CTRL_F7 0x13 | MOD_CPC_CTRL, // CPC_CTRL_F8 0x03 | MOD_CPC_CTRL, // CPC_CTRL_F9 0x17 | MOD_CPC_SHIFT, // CPC_SHIFT_F0 0x15 | MOD_CPC_SHIFT, // CPC_SHIFT_F1 0x16 | MOD_CPC_SHIFT, // CPC_SHIFT_F2 0x05 | MOD_CPC_SHIFT, // CPC_SHIFT_F3 0x24 | MOD_CPC_SHIFT, // CPC_SHIFT_F4 0x14 | MOD_CPC_SHIFT, // CPC_SHIFT_F5 0x04 | MOD_CPC_SHIFT, // CPC_SHIFT_F6 0x12 | MOD_CPC_SHIFT, // CPC_SHIFT_F7 0x13 | MOD_CPC_SHIFT, // CPC_SHIFT_F8 0x03 | MOD_CPC_SHIFT, // CPC_SHIFT_F9 0x07, // CPC_FPERIOD 0x37 | MOD_CPC_SHIFT, // CPC_GREATER 0x71 | MOD_CPC_SHIFT, // CPC_HASH 0x21, // CPC_LBRACKET 0x21 | MOD_CPC_SHIFT, // CPC_LCBRACE 0x50 | MOD_CPC_SHIFT, // CPC_LEFTPAREN 0x47 | MOD_CPC_SHIFT, // CPC_LESS 0x25, // CPC_LSHIFT 0x31, // CPC_MINUS 0x61 | MOD_CPC_SHIFT, // CPC_PERCENT 0x37, // CPC_PERIOD 0x32 | MOD_CPC_SHIFT, // CPC_PIPE 0x34 | MOD_CPC_SHIFT, // CPC_PLUS 0x30 | MOD_CPC_SHIFT, // CPC_POUND 0x30, // CPC_POWER 0x36 | MOD_CPC_SHIFT, // CPC_QUESTION 0x51 | MOD_CPC_SHIFT, // CPC_QUOTE 0x23, // CPC_RBRACKET 0x23 | MOD_CPC_SHIFT, // CPC_RCBRACE 0x22, // CPC_RETURN 0x41 | MOD_CPC_SHIFT, // CPC_RIGHTPAREN 0x25, // CPC_RSHIFT 0x34, // CPC_SEMICOLON 0x36, // CPC_SLASH 0x57, // CPC_SPACE 0x84, // CPC_TAB 0x40 | MOD_CPC_SHIFT, // CPC_UNDERSCORE 0x90, // CPC_J0_UP 0x91, // CPC_J0_DOWN 0x92, // CPC_J0_LEFT 0x93, // CPC_J0_RIGHT 0x94, // CPC_J0_FIRE1 0x95, // CPC_J0_FIRE2 0x60, // CPC_J1_UP 0x61, // CPC_J1_DOWN 0x62, // CPC_J1_LEFT 0x63, // CPC_J1_RIGHT 0x64, // CPC_J1_FIRE1 0x65, // CPC_J1_FIRE2 0xff, // CPC_ES_NTILDE 0xff, // CPC_ES_nTILDE 0xff, // CPC_ES_PESETA 0xff, // CPC_FR_eACUTE 0xff, // CPC_FR_eGRAVE 0xff, // CPC_FR_cCEDIL 0xff, // CPC_FR_aGRAVE 0xff, // CPC_FR_uGRAVE }, { // French CPC keyboard 0x40 | MOD_CPC_SHIFT, // CPC_0 0x80 | MOD_CPC_SHIFT, // CPC_1 0x81 | MOD_CPC_SHIFT, // CPC_2 0x71 | MOD_CPC_SHIFT, // CPC_3 0x70 | MOD_CPC_SHIFT, // CPC_4 0x61 | MOD_CPC_SHIFT, // CPC_5 0x60 | MOD_CPC_SHIFT, // CPC_6 0x51 | MOD_CPC_SHIFT, // CPC_7 0x50 | MOD_CPC_SHIFT, // CPC_8 0x41 | MOD_CPC_SHIFT, // CPC_9 0x83 | MOD_CPC_SHIFT, // CPC_A 0x66 | MOD_CPC_SHIFT, // CPC_B 0x76 | MOD_CPC_SHIFT, // CPC_C 0x75 | MOD_CPC_SHIFT, // CPC_D 0x72 | MOD_CPC_SHIFT, // CPC_E 0x65 | MOD_CPC_SHIFT, // CPC_F 0x64 | MOD_CPC_SHIFT, // CPC_G 0x54 | MOD_CPC_SHIFT, // CPC_H 0x43 | MOD_CPC_SHIFT, // CPC_I 0x55 | MOD_CPC_SHIFT, // CPC_J 0x45 | MOD_CPC_SHIFT, // CPC_K 0x44 | MOD_CPC_SHIFT, // CPC_L 0x35 | MOD_CPC_SHIFT, // CPC_M 0x56 | MOD_CPC_SHIFT, // CPC_N 0x42 | MOD_CPC_SHIFT, // CPC_O 0x33 | MOD_CPC_SHIFT, // CPC_P 0x85 | MOD_CPC_SHIFT, // CPC_Q 0x62 | MOD_CPC_SHIFT, // CPC_R 0x74 | MOD_CPC_SHIFT, // CPC_S 0x63 | MOD_CPC_SHIFT, // CPC_T 0x52 | MOD_CPC_SHIFT, // CPC_U 0x67 | MOD_CPC_SHIFT, // CPC_V 0x87 | MOD_CPC_SHIFT, // CPC_W 0x77 | MOD_CPC_SHIFT, // CPC_X 0x53 | MOD_CPC_SHIFT, // CPC_Y 0x73 | MOD_CPC_SHIFT, // CPC_Z 0x83, // CPC_a 0x66, // CPC_b 0x76, // CPC_c 0x75, // CPC_d 0x72, // CPC_e 0x65, // CPC_f 0x64, // CPC_g 0x54, // CPC_h 0x43, // CPC_i 0x55, // CPC_j 0x45, // CPC_k 0x44, // CPC_l 0x35, // CPC_m 0x56, // CPC_n 0x42, // CPC_o 0x33, // CPC_p 0x85, // CPC_q 0x62, // CPC_r 0x74, // CPC_s 0x63, // CPC_t 0x52, // CPC_u 0x67, // CPC_v 0x87, // CPC_w 0x77, // CPC_x 0x53, // CPC_y 0x73, // CPC_z 0x83 | MOD_CPC_CTRL, // CPC_CTRL_a 0x66 | MOD_CPC_CTRL, // CPC_CTRL_b 0x76 | MOD_CPC_CTRL, // CPC_CTRL_c 0x75 | MOD_CPC_CTRL, // CPC_CTRL_d 0x72 | MOD_CPC_CTRL, // CPC_CTRL_e 0x65 | MOD_CPC_CTRL, // CPC_CTRL_f 0x64 | MOD_CPC_CTRL, // CPC_CTRL_g 0x54 | MOD_CPC_CTRL, // CPC_CTRL_h 0x43 | MOD_CPC_CTRL, // CPC_CTRL_i 0x55 | MOD_CPC_CTRL, // CPC_CTRL_j 0x45 | MOD_CPC_CTRL, // CPC_CTRL_k 0x44 | MOD_CPC_CTRL, // CPC_CTRL_l 0x35 | MOD_CPC_CTRL, // CPC_CTRL_m 0x56 | MOD_CPC_CTRL, // CPC_CTRL_n 0x42 | MOD_CPC_CTRL, // CPC_CTRL_o 0x33 | MOD_CPC_CTRL, // CPC_CTRL_p 0x85 | MOD_CPC_CTRL, // CPC_CTRL_q 0x62 | MOD_CPC_CTRL, // CPC_CTRL_r 0x74 | MOD_CPC_CTRL, // CPC_CTRL_s 0x63 | MOD_CPC_CTRL, // CPC_CTRL_t 0x52 | MOD_CPC_CTRL, // CPC_CTRL_u 0x67 | MOD_CPC_CTRL, // CPC_CTRL_v 0x87 | MOD_CPC_CTRL, // CPC_CTRL_w 0x77 | MOD_CPC_CTRL, // CPC_CTRL_x 0x53 | MOD_CPC_CTRL, // CPC_CTRL_y 0x73 | MOD_CPC_CTRL, // CPC_CTRL_z 0x40 | MOD_CPC_CTRL, // CPC_CTRL_0 0x80 | MOD_CPC_CTRL, // CPC_CTRL_1 0x81 | MOD_CPC_CTRL, // CPC_CTRL_2 0x71 | MOD_CPC_CTRL, // CPC_CTRL_3 0x70 | MOD_CPC_CTRL, // CPC_CTRL_4 0x61 | MOD_CPC_CTRL, // CPC_CTRL_5 0x60 | MOD_CPC_CTRL, // CPC_CTRL_6 0x51 | MOD_CPC_CTRL, // CPC_CTRL_7 0x50 | MOD_CPC_CTRL, // CPC_CTRL_8 0x41 | MOD_CPC_CTRL, // CPC_CTRL_9 0x00 | MOD_CPC_CTRL, // CPC_CTRL_UP 0x02 | MOD_CPC_CTRL, // CPC_CTRL_DOWN 0x10 | MOD_CPC_CTRL, // CPC_CTRL_LEFT 0x01 | MOD_CPC_CTRL, // CPC_CTRL_RIGHT 0x80, // CPC_AMPERSAND 0x21, // CPC_ASTERISK 0x26 | MOD_CPC_SHIFT, // CPC_AT 0xff, // CPC_BACKQUOTE 0x26 | MOD_CPC_CTRL, // CPC_BACKSLASH 0x86, // CPC_CAPSLOCK 0x20, // CPC_CLR 0x37, // CPC_COLON 0x46, // CPC_COMMA 0x27, // CPC_CONTROL 0x11, // CPC_COPY 0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN 0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT 0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT 0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP 0x02, // CPC_CUR_DOWN 0x10, // CPC_CUR_LEFT 0x01, // CPC_CUR_RIGHT 0x00, // CPC_CUR_UP 0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL 0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN 0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN 0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL 0x71, // CPC_DBLQUOTE 0x97, // CPC_DEL 0x26, // CPC_DOLLAR 0x06, // CPC_ENTER 0x36, // CPC_EQUAL 0x82, // CPC_ESC 0x50, // CPC_EXCLAMATN 0x17, // CPC_F0 0x15, // CPC_F1 0x16, // CPC_F2 0x05, // CPC_F3 0x24, // CPC_F4 0x14, // CPC_F5 0x04, // CPC_F6 0x12, // CPC_F7 0x13, // CPC_F8 0x03, // CPC_F9 0x17 | MOD_CPC_CTRL, // CPC_CTRL_F0 0x15 | MOD_CPC_CTRL, // CPC_CTRL_F1 0x16 | MOD_CPC_CTRL, // CPC_CTRL_F2 0x05 | MOD_CPC_CTRL, // CPC_CTRL_F3 0x24 | MOD_CPC_CTRL, // CPC_CTRL_F4 0x14 | MOD_CPC_CTRL, // CPC_CTRL_F5 0x04 | MOD_CPC_CTRL, // CPC_CTRL_F6 0x12 | MOD_CPC_CTRL, // CPC_CTRL_F7 0x13 | MOD_CPC_CTRL, // CPC_CTRL_F8 0x03 | MOD_CPC_CTRL, // CPC_CTRL_F9 0x17 | MOD_CPC_SHIFT, // CPC_SHIFT_F0 0x15 | MOD_CPC_SHIFT, // CPC_SHIFT_F1 0x16 | MOD_CPC_SHIFT, // CPC_SHIFT_F2 0x05 | MOD_CPC_SHIFT, // CPC_SHIFT_F3 0x24 | MOD_CPC_SHIFT, // CPC_SHIFT_F4 0x14 | MOD_CPC_SHIFT, // CPC_SHIFT_F5 0x04 | MOD_CPC_SHIFT, // CPC_SHIFT_F6 0x12 | MOD_CPC_SHIFT, // CPC_SHIFT_F7 0x13 | MOD_CPC_SHIFT, // CPC_SHIFT_F8 0x03 | MOD_CPC_SHIFT, // CPC_SHIFT_F9 0x07, // CPC_FPERIOD 0x23 | MOD_CPC_SHIFT, // CPC_GREATER 0x23, // CPC_HASH 0x31 | MOD_CPC_SHIFT, // CPC_LBRACKET 0xff, // CPC_LCBRACE 0x61, // CPC_LEFTPAREN 0x21 | MOD_CPC_SHIFT, // CPC_LESS 0x25, // CPC_LSHIFT 0x30, // CPC_MINUS 0x34 | MOD_CPC_SHIFT, // CPC_PERCENT 0x47 | MOD_CPC_SHIFT, // CPC_PERIOD 0x32 | MOD_CPC_SHIFT, // CPC_PIPE 0x36 | MOD_CPC_SHIFT, // CPC_PLUS 0xff, // CPC_POUND 0x32, // CPC_POWER 0x46 | MOD_CPC_SHIFT, // CPC_QUESTION 0x70, // CPC_QUOTE 0x60, // CPC_RBRACKET 0xff, // CPC_RCBRACE 0x22, // CPC_RETURN 0x31, // CPC_RIGHTPAREN 0x25, // CPC_RSHIFT 0x47, // CPC_SEMICOLON 0x37 | MOD_CPC_SHIFT, // CPC_SLASH 0x57, // CPC_SPACE 0x84, // CPC_TAB 0x30 | MOD_CPC_SHIFT, // CPC_UNDERSCORE 0x90, // CPC_J0_UP 0x91, // CPC_J0_DOWN 0x92, // CPC_J0_LEFT 0x93, // CPC_J0_RIGHT 0x94, // CPC_J0_FIRE1 0x95, // CPC_J0_FIRE2 0x60, // CPC_J1_UP 0x61, // CPC_J1_DOWN 0x62, // CPC_J1_LEFT 0x63, // CPC_J1_RIGHT 0x64, // CPC_J1_FIRE1 0x65, // CPC_J1_FIRE2 0xff, // CPC_ES_NTILDE 0xff, // CPC_ES_nTILDE 0xff, // CPC_ES_PESETA 0x81, // CPC_FR_eACUTE 0x51, // CPC_FR_eGRAVE 0x41, // CPC_FR_cCEDIL 0x40, // CPC_FR_aGRAVE 0x34, // CPC_FR_uGRAVE }, { // Spanish CPC keyboard 0x40, // CPC_0 0x80, // CPC_1 0x81, // CPC_2 0x71, // CPC_3 0x70, // CPC_4 0x61, // CPC_5 0x60, // CPC_6 0x51, // CPC_7 0x50, // CPC_8 0x41, // CPC_9 0x85 | MOD_CPC_SHIFT, // CPC_A 0x66 | MOD_CPC_SHIFT, // CPC_B 0x76 | MOD_CPC_SHIFT, // CPC_C 0x75 | MOD_CPC_SHIFT, // CPC_D 0x72 | MOD_CPC_SHIFT, // CPC_E 0x65 | MOD_CPC_SHIFT, // CPC_F 0x64 | MOD_CPC_SHIFT, // CPC_G 0x54 | MOD_CPC_SHIFT, // CPC_H 0x43 | MOD_CPC_SHIFT, // CPC_I 0x55 | MOD_CPC_SHIFT, // CPC_J 0x45 | MOD_CPC_SHIFT, // CPC_K 0x44 | MOD_CPC_SHIFT, // CPC_L 0x46 | MOD_CPC_SHIFT, // CPC_M 0x56 | MOD_CPC_SHIFT, // CPC_N 0x42 | MOD_CPC_SHIFT, // CPC_O 0x33 | MOD_CPC_SHIFT, // CPC_P 0x83 | MOD_CPC_SHIFT, // CPC_Q 0x62 | MOD_CPC_SHIFT, // CPC_R 0x74 | MOD_CPC_SHIFT, // CPC_S 0x63 | MOD_CPC_SHIFT, // CPC_T 0x52 | MOD_CPC_SHIFT, // CPC_U 0x67 | MOD_CPC_SHIFT, // CPC_V 0x73 | MOD_CPC_SHIFT, // CPC_W 0x77 | MOD_CPC_SHIFT, // CPC_X 0x53 | MOD_CPC_SHIFT, // CPC_Y 0x87 | MOD_CPC_SHIFT, // CPC_Z 0x85, // CPC_a 0x66, // CPC_b 0x76, // CPC_c 0x75, // CPC_d 0x72, // CPC_e 0x65, // CPC_f 0x64, // CPC_g 0x54, // CPC_h 0x43, // CPC_i 0x55, // CPC_j 0x45, // CPC_k 0x44, // CPC_l 0x46, // CPC_m 0x56, // CPC_n 0x42, // CPC_o 0x33, // CPC_p 0x83, // CPC_q 0x62, // CPC_r 0x74, // CPC_s 0x63, // CPC_t 0x52, // CPC_u 0x67, // CPC_v 0x73, // CPC_w 0x77, // CPC_x 0x53, // CPC_y 0x87, // CPC_z 0x85 | MOD_CPC_CTRL, // CPC_CTRL_a 0x66 | MOD_CPC_CTRL, // CPC_CTRL_b 0x76 | MOD_CPC_CTRL, // CPC_CTRL_c 0x75 | MOD_CPC_CTRL, // CPC_CTRL_d 0x72 | MOD_CPC_CTRL, // CPC_CTRL_e 0x65 | MOD_CPC_CTRL, // CPC_CTRL_f 0x64 | MOD_CPC_CTRL, // CPC_CTRL_g 0x54 | MOD_CPC_CTRL, // CPC_CTRL_h 0x43 | MOD_CPC_CTRL, // CPC_CTRL_i 0x55 | MOD_CPC_CTRL, // CPC_CTRL_j 0x45 | MOD_CPC_CTRL, // CPC_CTRL_k 0x44 | MOD_CPC_CTRL, // CPC_CTRL_l 0x46 | MOD_CPC_CTRL, // CPC_CTRL_m 0x56 | MOD_CPC_CTRL, // CPC_CTRL_n 0x42 | MOD_CPC_CTRL, // CPC_CTRL_o 0x33 | MOD_CPC_CTRL, // CPC_CTRL_p 0x83 | MOD_CPC_CTRL, // CPC_CTRL_q 0x62 | MOD_CPC_CTRL, // CPC_CTRL_r 0x74 | MOD_CPC_CTRL, // CPC_CTRL_s 0x63 | MOD_CPC_CTRL, // CPC_CTRL_t 0x52 | MOD_CPC_CTRL, // CPC_CTRL_u 0x67 | MOD_CPC_CTRL, // CPC_CTRL_v 0x73 | MOD_CPC_CTRL, // CPC_CTRL_w 0x77 | MOD_CPC_CTRL, // CPC_CTRL_x 0x53 | MOD_CPC_CTRL, // CPC_CTRL_y 0x87 | MOD_CPC_CTRL, // CPC_CTRL_z 0x40 | MOD_CPC_CTRL, // CPC_CTRL_0 0x80 | MOD_CPC_CTRL, // CPC_CTRL_1 0x81 | MOD_CPC_CTRL, // CPC_CTRL_2 0x71 | MOD_CPC_CTRL, // CPC_CTRL_3 0x70 | MOD_CPC_CTRL, // CPC_CTRL_4 0x61 | MOD_CPC_CTRL, // CPC_CTRL_5 0x60 | MOD_CPC_CTRL, // CPC_CTRL_6 0x51 | MOD_CPC_CTRL, // CPC_CTRL_7 0x50 | MOD_CPC_CTRL, // CPC_CTRL_8 0x41 | MOD_CPC_CTRL, // CPC_CTRL_9 0x00 | MOD_CPC_CTRL, // CPC_CTRL_UP 0x02 | MOD_CPC_CTRL, // CPC_CTRL_DOWN 0x10 | MOD_CPC_CTRL, // CPC_CTRL_LEFT 0x01 | MOD_CPC_CTRL, // CPC_CTRL_RIGHT 0x60 | MOD_CPC_SHIFT, // CPC_AMPERSAND 0x21 | MOD_CPC_SHIFT, // CPC_ASTERISK 0x32, // CPC_AT 0x26 | MOD_CPC_SHIFT, // CPC_BACKQUOTE 0x26, // CPC_BACKSLASH 0x86, // CPC_CAPSLOCK 0x20, // CPC_CLR 0x34 | MOD_CPC_SHIFT, // CPC_COLON 0x47, // CPC_COMMA 0x27, // CPC_CONTROL 0x11, // CPC_COPY 0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN 0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT 0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT 0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP 0x02, // CPC_CUR_DOWN 0x10, // CPC_CUR_LEFT 0x01, // CPC_CUR_RIGHT 0x00, // CPC_CUR_UP 0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL 0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN 0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN 0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL 0x81 | MOD_CPC_SHIFT, // CPC_DBLQUOTE 0x97, // CPC_DEL 0x70 | MOD_CPC_SHIFT, // CPC_DOLLAR 0x06, // CPC_ENTER 0x31 | MOD_CPC_SHIFT, // CPC_EQUAL 0x82, // CPC_ESC 0x80 | MOD_CPC_SHIFT, // CPC_EXCLAMATN 0x17, // CPC_F0 0x15, // CPC_F1 0x16, // CPC_F2 0x05, // CPC_F3 0x24, // CPC_F4 0x14, // CPC_F5 0x04, // CPC_F6 0x12, // CPC_F7 0x13, // CPC_F8 0x03, // CPC_F9 0x17 | MOD_CPC_CTRL, // CPC_CTRL_F0 0x15 | MOD_CPC_CTRL, // CPC_CTRL_F1 0x16 | MOD_CPC_CTRL, // CPC_CTRL_F2 0x05 | MOD_CPC_CTRL, // CPC_CTRL_F3 0x24 | MOD_CPC_CTRL, // CPC_CTRL_F4 0x14 | MOD_CPC_CTRL, // CPC_CTRL_F5 0x04 | MOD_CPC_CTRL, // CPC_CTRL_F6 0x12 | MOD_CPC_CTRL, // CPC_CTRL_F7 0x13 | MOD_CPC_CTRL, // CPC_CTRL_F8 0x03 | MOD_CPC_CTRL, // CPC_CTRL_F9 0x17 | MOD_CPC_SHIFT, // CPC_SHIFT_F0 0x15 | MOD_CPC_SHIFT, // CPC_SHIFT_F1 0x16 | MOD_CPC_SHIFT, // CPC_SHIFT_F2 0x05 | MOD_CPC_SHIFT, // CPC_SHIFT_F3 0x24 | MOD_CPC_SHIFT, // CPC_SHIFT_F4 0x14 | MOD_CPC_SHIFT, // CPC_SHIFT_F5 0x04 | MOD_CPC_SHIFT, // CPC_SHIFT_F6 0x12 | MOD_CPC_SHIFT, // CPC_SHIFT_F7 0x13 | MOD_CPC_SHIFT, // CPC_SHIFT_F8 0x03 | MOD_CPC_SHIFT, // CPC_SHIFT_F9 0x07, // CPC_FPERIOD 0x37 | MOD_CPC_SHIFT, // CPC_GREATER 0x71 | MOD_CPC_SHIFT, // CPC_HASH 0x21, // CPC_LBRACKET 0xff, // CPC_LCBRACE 0x50 | MOD_CPC_SHIFT, // CPC_LEFTPAREN 0x47 | MOD_CPC_SHIFT, // CPC_LESS 0x25, // CPC_LSHIFT 0x31, // CPC_MINUS 0x61 | MOD_CPC_SHIFT, // CPC_PERCENT 0x37, // CPC_PERIOD 0x32 | MOD_CPC_SHIFT, // CPC_PIPE 0x23 | MOD_CPC_SHIFT, // CPC_PLUS 0xff, // CPC_POUND 0x30, // CPC_POWER 0x36 | MOD_CPC_SHIFT, // CPC_QUESTION 0x51 | MOD_CPC_SHIFT, // CPC_QUOTE 0x23, // CPC_RBRACKET 0xff, // CPC_RCBRACE 0x22, // CPC_RETURN 0x41 | MOD_CPC_SHIFT, // CPC_RIGHTPAREN 0x25, // CPC_RSHIFT 0x34, // CPC_SEMICOLON 0x36, // CPC_SLASH 0x57, // CPC_SPACE 0x84, // CPC_TAB 0x40 | MOD_CPC_SHIFT, // CPC_UNDERSCORE 0x90, // CPC_J0_UP 0x91, // CPC_J0_DOWN 0x92, // CPC_J0_LEFT 0x93, // CPC_J0_RIGHT 0x94, // CPC_J0_FIRE1 0x95, // CPC_J0_FIRE2 0x60, // CPC_J1_UP 0x61, // CPC_J1_DOWN 0x62, // CPC_J1_LEFT 0x63, // CPC_J1_RIGHT 0x64, // CPC_J1_FIRE1 0x65, // CPC_J1_FIRE2 0x35 | MOD_CPC_SHIFT, // CPC_ES_NTILDE 0x35, // CPC_ES_nTILDE 0x30 | MOD_CPC_SHIFT, // CPC_ES_PESETA 0xff, // CPC_FR_eACUTE 0xff, // CPC_FR_eGRAVE 0xff, // CPC_FR_cCEDIL 0xff, // CPC_FR_aGRAVE 0xff, // CPC_FR_uGRAVE } }; const std::map<const char, const CPC_KEYS> InputMapper::CPCkeysFromChars = { // Char to CPC keyboard translation // TODO(sebhz): Need to map non ASCII chars present on the CPC keyboard - maybe by using their ISO-8859-1 code { '&', CPC_AMPERSAND }, { '#', CPC_HASH }, { '"', CPC_DBLQUOTE }, { '\'', CPC_QUOTE }, { '(', CPC_LEFTPAREN }, { '-', CPC_MINUS }, { '_', CPC_UNDERSCORE }, { ')', CPC_RIGHTPAREN }, { '=', CPC_EQUAL }, { '*', CPC_ASTERISK }, { ',', CPC_COMMA }, { ';', CPC_SEMICOLON }, { ':', CPC_COLON }, { '!', CPC_EXCLAMATN }, { '$', CPC_DOLLAR }, { 'a', CPC_a }, { 'b', CPC_b }, { 'c', CPC_c }, { 'd', CPC_d }, { 'e', CPC_e }, { 'f', CPC_f }, { 'g', CPC_g }, { 'h', CPC_h }, { 'i', CPC_i }, { 'j', CPC_j }, { 'k', CPC_k }, { 'l', CPC_l }, { 'm', CPC_m }, { 'n', CPC_n }, { 'o', CPC_o }, { 'p', CPC_p }, { 'q', CPC_q }, { 'r', CPC_r }, { 's', CPC_s }, { 't', CPC_t }, { 'u', CPC_u }, { 'v', CPC_v }, { 'w', CPC_w }, { 'x', CPC_x }, { 'y', CPC_y }, { 'z', CPC_z }, { 'A', CPC_A }, { 'B', CPC_B }, { 'C', CPC_C }, { 'D', CPC_D }, { 'E', CPC_E }, { 'F', CPC_F }, { 'G', CPC_G }, { 'H', CPC_H }, { 'I', CPC_I }, { 'J', CPC_J }, { 'K', CPC_K }, { 'L', CPC_L }, { 'M', CPC_M }, { 'N', CPC_N }, { 'O', CPC_O }, { 'P', CPC_P }, { 'Q', CPC_Q }, { 'R', CPC_R }, { 'S', CPC_S }, { 'T', CPC_T }, { 'U', CPC_U }, { 'V', CPC_V }, { 'W', CPC_W }, { 'X', CPC_X }, { 'Y', CPC_Y }, { 'Z', CPC_Z }, { '0', CPC_0 }, { '1', CPC_1 }, { '2', CPC_2 }, { '3', CPC_3 }, { '4', CPC_4 }, { '5', CPC_5 }, { '6', CPC_6 }, { '7', CPC_7 }, { '8', CPC_8 }, { '9', CPC_9 }, { '|', CPC_PIPE }, { '?', CPC_QUESTION}, { '.', CPC_PERIOD }, { '/', CPC_SLASH }, { ' ', CPC_SPACE }, { '\n', CPC_RETURN }, { '+', CPC_PLUS }, { '%', CPC_PERCENT }, { '<', CPC_LESS }, { '>', CPC_GREATER }, { '[', CPC_LBRACKET }, { ']', CPC_RBRACKET }, { '{', CPC_LCBRACE }, { '}', CPC_RCBRACE }, { '\\', CPC_BACKSLASH }, { '\b', CPC_DEL }, { '`', CPC_BACKQUOTE }, // Not (yet?) on virtual keyboard { '@', CPC_AT }, { '^', CPC_POWER }, // Control keys (CPC_CTRL_a to CPC_CTRL_9) are not ont the virtual keyboard (yet?) //{ '~', {0, KMOD_NONE} } // should be pound but it's not part of base ascii (it's in extended ASCII) }; std::map<CapriceKey, PCKey> InputMapper::SDLkeysymFromCPCkeys_us = { { CPC_0, SDLK_0 }, { CPC_1, SDLK_1 }, { CPC_2, SDLK_2 }, { CPC_3, SDLK_3 }, { CPC_4, SDLK_4 }, { CPC_5, SDLK_5 }, { CPC_6, SDLK_6 }, { CPC_7, SDLK_7 }, { CPC_8, SDLK_8 }, { CPC_9, SDLK_9 }, { CPC_A, SDLK_a | MOD_PC_SHIFT }, { CPC_B, SDLK_b | MOD_PC_SHIFT }, { CPC_C, SDLK_c | MOD_PC_SHIFT }, { CPC_D, SDLK_d | MOD_PC_SHIFT }, { CPC_E, SDLK_e | MOD_PC_SHIFT }, { CPC_F, SDLK_f | MOD_PC_SHIFT }, { CPC_G, SDLK_g | MOD_PC_SHIFT }, { CPC_H, SDLK_h | MOD_PC_SHIFT }, { CPC_I, SDLK_i | MOD_PC_SHIFT }, { CPC_J, SDLK_j | MOD_PC_SHIFT }, { CPC_K, SDLK_k | MOD_PC_SHIFT }, { CPC_L, SDLK_l | MOD_PC_SHIFT }, { CPC_M, SDLK_m | MOD_PC_SHIFT }, { CPC_N, SDLK_n | MOD_PC_SHIFT }, { CPC_O, SDLK_o | MOD_PC_SHIFT }, { CPC_P, SDLK_p | MOD_PC_SHIFT }, { CPC_Q, SDLK_q | MOD_PC_SHIFT }, { CPC_R, SDLK_r | MOD_PC_SHIFT }, { CPC_S, SDLK_s | MOD_PC_SHIFT }, { CPC_T, SDLK_t | MOD_PC_SHIFT }, { CPC_U, SDLK_u | MOD_PC_SHIFT }, { CPC_V, SDLK_v | MOD_PC_SHIFT }, { CPC_W, SDLK_w | MOD_PC_SHIFT }, { CPC_X, SDLK_x | MOD_PC_SHIFT }, { CPC_Y, SDLK_y | MOD_PC_SHIFT }, { CPC_Z, SDLK_z | MOD_PC_SHIFT }, { CPC_a, SDLK_a }, { CPC_b, SDLK_b }, { CPC_c, SDLK_c }, { CPC_d, SDLK_d }, { CPC_e, SDLK_e }, { CPC_f, SDLK_f }, { CPC_g, SDLK_g }, { CPC_h, SDLK_h }, { CPC_i, SDLK_i }, { CPC_j, SDLK_j }, { CPC_k, SDLK_k }, { CPC_l, SDLK_l }, { CPC_m, SDLK_m }, { CPC_n, SDLK_n }, { CPC_o, SDLK_o }, { CPC_p, SDLK_p }, { CPC_q, SDLK_q }, { CPC_r, SDLK_r }, { CPC_s, SDLK_s }, { CPC_t, SDLK_t }, { CPC_u, SDLK_u }, { CPC_v, SDLK_v }, { CPC_w, SDLK_w }, { CPC_x, SDLK_x }, { CPC_y, SDLK_y }, { CPC_z, SDLK_z }, { CPC_CTRL_a, SDLK_a | MOD_PC_CTRL }, { CPC_CTRL_b, SDLK_b | MOD_PC_CTRL }, { CPC_CTRL_c, SDLK_c | MOD_PC_CTRL }, { CPC_CTRL_d, SDLK_d | MOD_PC_CTRL }, { CPC_CTRL_e, SDLK_e | MOD_PC_CTRL }, { CPC_CTRL_f, SDLK_f | MOD_PC_CTRL }, { CPC_CTRL_g, SDLK_g | MOD_PC_CTRL }, { CPC_CTRL_h, SDLK_h | MOD_PC_CTRL }, { CPC_CTRL_i, SDLK_i | MOD_PC_CTRL }, { CPC_CTRL_j, SDLK_j | MOD_PC_CTRL }, { CPC_CTRL_k, SDLK_k | MOD_PC_CTRL }, { CPC_CTRL_l, SDLK_l | MOD_PC_CTRL }, { CPC_CTRL_m, SDLK_m | MOD_PC_CTRL }, { CPC_CTRL_n, SDLK_n | MOD_PC_CTRL }, { CPC_CTRL_o, SDLK_o | MOD_PC_CTRL }, { CPC_CTRL_p, SDLK_p | MOD_PC_CTRL }, { CPC_CTRL_q, SDLK_q | MOD_PC_CTRL }, { CPC_CTRL_r, SDLK_r | MOD_PC_CTRL }, { CPC_CTRL_s, SDLK_s | MOD_PC_CTRL }, { CPC_CTRL_t, SDLK_t | MOD_PC_CTRL }, { CPC_CTRL_u, SDLK_u | MOD_PC_CTRL }, { CPC_CTRL_v, SDLK_v | MOD_PC_CTRL }, { CPC_CTRL_w, SDLK_w | MOD_PC_CTRL }, { CPC_CTRL_x, SDLK_x | MOD_PC_CTRL }, { CPC_CTRL_y, SDLK_y | MOD_PC_CTRL }, { CPC_CTRL_z, SDLK_z | MOD_PC_CTRL }, { CPC_CTRL_0, SDLK_0 | MOD_PC_CTRL }, { CPC_CTRL_1, SDLK_1 | MOD_PC_CTRL }, { CPC_CTRL_2, SDLK_2 | MOD_PC_CTRL }, { CPC_CTRL_3, SDLK_3 | MOD_PC_CTRL }, { CPC_CTRL_4, SDLK_4 | MOD_PC_CTRL }, { CPC_CTRL_5, SDLK_5 | MOD_PC_CTRL }, { CPC_CTRL_6, SDLK_6 | MOD_PC_CTRL }, { CPC_CTRL_7, SDLK_7 | MOD_PC_CTRL }, { CPC_CTRL_8, SDLK_8 | MOD_PC_CTRL }, { CPC_CTRL_9, SDLK_9 | MOD_PC_CTRL }, { CPC_CTRL_UP, SDLK_UP | MOD_PC_CTRL }, { CPC_CTRL_DOWN, SDLK_DOWN | MOD_PC_CTRL }, { CPC_CTRL_LEFT, SDLK_LEFT | MOD_PC_CTRL }, { CPC_CTRL_RIGHT, SDLK_RIGHT | MOD_PC_CTRL }, { CPC_AMPERSAND, SDLK_7 | MOD_PC_SHIFT }, { CPC_ASTERISK, SDLK_8 | MOD_PC_SHIFT }, { CPC_AT, SDLK_2 | MOD_PC_SHIFT }, { CPC_BACKQUOTE, SDLK_BACKQUOTE }, { CPC_BACKSLASH, SDLK_BACKSLASH }, { CPC_CAPSLOCK, SDLK_CAPSLOCK }, { CPC_CLR, SDLK_DELETE }, { CPC_COLON, SDLK_SEMICOLON | MOD_PC_SHIFT }, { CPC_COMMA, SDLK_COMMA }, { CPC_CONTROL, SDLK_LCTRL }, { CPC_COPY, SDLK_LALT }, { CPC_CPY_DOWN, SDLK_DOWN | MOD_PC_SHIFT }, { CPC_CPY_LEFT, SDLK_LEFT | MOD_PC_SHIFT }, { CPC_CPY_RIGHT, SDLK_RIGHT | MOD_PC_SHIFT }, { CPC_CPY_UP, SDLK_UP | MOD_PC_SHIFT }, { CPC_CUR_DOWN, SDLK_DOWN }, { CPC_CUR_LEFT, SDLK_LEFT }, { CPC_CUR_RIGHT, SDLK_RIGHT }, { CPC_CUR_UP, SDLK_UP }, { CPC_CUR_HOMELN, SDLK_HOME }, { CPC_CUR_ENDLN, SDLK_END }, { CPC_CUR_HOMEBL, SDLK_HOME | MOD_PC_CTRL }, { CPC_CUR_ENDBL, SDLK_END | MOD_PC_CTRL }, { CPC_DBLQUOTE, SDLK_QUOTE | MOD_PC_SHIFT }, { CPC_DEL, SDLK_BACKSPACE }, { CPC_DOLLAR, SDLK_4 | MOD_PC_SHIFT }, { CPC_ENTER, SDLK_KP_ENTER }, { CPC_EQUAL, SDLK_EQUALS }, { CPC_ESC, SDLK_ESCAPE }, { CPC_EXCLAMATN, SDLK_1 | MOD_PC_SHIFT }, { CPC_F0, SDLK_KP_0 }, { CPC_F1, SDLK_KP_1 }, { CPC_F2, SDLK_KP_2 }, { CPC_F3, SDLK_KP_3 }, { CPC_F4, SDLK_KP_4 }, { CPC_F5, SDLK_KP_5 }, { CPC_F6, SDLK_KP_6 }, { CPC_F7, SDLK_KP_7 }, { CPC_F8, SDLK_KP_8 }, { CPC_F9, SDLK_KP_9 }, { CPC_CTRL_F0, SDLK_KP_0 | MOD_PC_CTRL }, { CPC_CTRL_F1, SDLK_KP_1 | MOD_PC_CTRL }, { CPC_CTRL_F2, SDLK_KP_2 | MOD_PC_CTRL }, { CPC_CTRL_F3, SDLK_KP_3 | MOD_PC_CTRL }, { CPC_CTRL_F4, SDLK_KP_4 | MOD_PC_CTRL }, { CPC_CTRL_F5, SDLK_KP_5 | MOD_PC_CTRL }, { CPC_CTRL_F6, SDLK_KP_6 | MOD_PC_CTRL }, { CPC_CTRL_F7, SDLK_KP_7 | MOD_PC_CTRL }, { CPC_CTRL_F8, SDLK_KP_8 | MOD_PC_CTRL }, { CPC_CTRL_F9, SDLK_KP_9 | MOD_PC_CTRL }, { CPC_SHIFT_F0, SDLK_KP_0 | MOD_PC_SHIFT }, { CPC_SHIFT_F1, SDLK_KP_1 | MOD_PC_SHIFT }, { CPC_SHIFT_F2, SDLK_KP_2 | MOD_PC_SHIFT }, { CPC_SHIFT_F3, SDLK_KP_3 | MOD_PC_SHIFT }, { CPC_SHIFT_F4, SDLK_KP_4 | MOD_PC_SHIFT }, { CPC_SHIFT_F5, SDLK_KP_5 | MOD_PC_SHIFT }, { CPC_SHIFT_F6, SDLK_KP_6 | MOD_PC_SHIFT }, { CPC_SHIFT_F7, SDLK_KP_7 | MOD_PC_SHIFT }, { CPC_SHIFT_F8, SDLK_KP_8 | MOD_PC_SHIFT }, { CPC_SHIFT_F9, SDLK_KP_9 | MOD_PC_SHIFT }, { CPC_FPERIOD, SDLK_KP_PERIOD }, { CPC_GREATER, SDLK_PERIOD | MOD_PC_SHIFT }, { CPC_HASH, SDLK_3 | MOD_PC_SHIFT }, { CPC_LBRACKET, SDLK_LEFTBRACKET }, { CPC_LCBRACE, SDLK_LEFTBRACKET | MOD_PC_SHIFT }, { CPC_LEFTPAREN, SDLK_9 | MOD_PC_SHIFT }, { CPC_LESS, SDLK_COMMA | MOD_PC_SHIFT }, { CPC_LSHIFT, SDLK_LSHIFT }, { CPC_MINUS, SDLK_MINUS }, { CPC_PERCENT, SDLK_5 | MOD_PC_SHIFT }, { CPC_PERIOD, SDLK_PERIOD }, { CPC_PIPE, SDLK_BACKSLASH | MOD_PC_SHIFT }, { CPC_PLUS, SDLK_EQUALS | MOD_PC_SHIFT }, { CPC_POUND, 0 }, { CPC_POWER, SDLK_6 | MOD_PC_SHIFT }, { CPC_QUESTION, SDLK_SLASH | MOD_PC_SHIFT }, { CPC_QUOTE, SDLK_QUOTE }, { CPC_RBRACKET, SDLK_RIGHTBRACKET }, { CPC_RCBRACE, SDLK_RIGHTBRACKET | MOD_PC_SHIFT }, { CPC_RETURN, SDLK_RETURN }, { CPC_RIGHTPAREN, SDLK_0 | MOD_PC_SHIFT }, { CPC_RSHIFT, SDLK_RSHIFT }, { CPC_SEMICOLON, SDLK_SEMICOLON }, { CPC_SLASH, SDLK_SLASH }, { CPC_SPACE, SDLK_SPACE }, { CPC_TAB, SDLK_TAB }, { CPC_UNDERSCORE, SDLK_MINUS | MOD_PC_SHIFT }, { CAP32_GUI, SDLK_F1}, { CAP32_VKBD, SDLK_F1 | MOD_PC_SHIFT }, { CAP32_FULLSCRN, SDLK_F2 }, { CAP32_DEVTOOLS, SDLK_F2 | MOD_PC_SHIFT }, { CAP32_SCRNSHOT, SDLK_F3 }, { CAP32_SNAPSHOT, SDLK_F3 | MOD_PC_SHIFT }, { CAP32_LD_SNAP, SDLK_F4 | MOD_PC_SHIFT }, { CAP32_RESET, SDLK_F5 }, { CAP32_MF2STOP, SDLK_F6 }, { CAP32_JOY, SDLK_F7 }, { CAP32_PHAZER, SDLK_F7 | MOD_PC_SHIFT }, { CAP32_FPS, SDLK_F8 }, { CAP32_SPEED, SDLK_F9 }, { CAP32_EXIT, SDLK_F10 }, { CAP32_PASTE, SDLK_F11 }, { CAP32_DEBUG, SDLK_F12 }, { CAP32_TAPEPLAY, SDLK_F4 }, { CAP32_DELAY, SDLK_PAUSE }, { CAP32_WAITBREAK, SDLK_PAUSE | MOD_PC_SHIFT } }; const std::map<const std::string, const CapriceKey> InputMapper::CPCkeysFromStrings = { {"CPC_0", CPC_0}, {"CPC_1", CPC_1}, {"CPC_2", CPC_2}, {"CPC_3", CPC_3}, {"CPC_4", CPC_4}, {"CPC_5", CPC_5}, {"CPC_6", CPC_6}, {"CPC_7", CPC_7}, {"CPC_8", CPC_8}, {"CPC_9", CPC_9}, {"CPC_A", CPC_A}, {"CPC_B", CPC_B}, {"CPC_C", CPC_C}, {"CPC_D", CPC_D}, {"CPC_E", CPC_E}, {"CPC_F", CPC_F}, {"CPC_G", CPC_G}, {"CPC_H", CPC_H}, {"CPC_I", CPC_I}, {"CPC_J", CPC_J}, {"CPC_K", CPC_K}, {"CPC_L", CPC_L}, {"CPC_M", CPC_M}, {"CPC_N", CPC_N}, {"CPC_O", CPC_O}, {"CPC_P", CPC_P}, {"CPC_Q", CPC_Q}, {"CPC_R", CPC_R}, {"CPC_S", CPC_S}, {"CPC_T", CPC_T}, {"CPC_U", CPC_U}, {"CPC_V", CPC_V}, {"CPC_W", CPC_W}, {"CPC_X", CPC_X}, {"CPC_Y", CPC_Y}, {"CPC_Z", CPC_Z}, {"CPC_a", CPC_a}, {"CPC_b", CPC_b}, {"CPC_c", CPC_c}, {"CPC_d", CPC_d}, {"CPC_e", CPC_e}, {"CPC_f", CPC_f}, {"CPC_g", CPC_g}, {"CPC_h", CPC_h}, {"CPC_i", CPC_i}, {"CPC_j", CPC_j}, {"CPC_k", CPC_k}, {"CPC_l", CPC_l}, {"CPC_m", CPC_m}, {"CPC_n", CPC_n}, {"CPC_o", CPC_o}, {"CPC_p", CPC_p}, {"CPC_q", CPC_q}, {"CPC_r", CPC_r}, {"CPC_s", CPC_s}, {"CPC_t", CPC_t}, {"CPC_u", CPC_u}, {"CPC_v", CPC_v}, {"CPC_w", CPC_w}, {"CPC_x", CPC_x}, {"CPC_y", CPC_y}, {"CPC_z", CPC_z}, {"CPC_CTRL_a", CPC_CTRL_a}, {"CPC_CTRL_b", CPC_CTRL_b}, {"CPC_CTRL_c", CPC_CTRL_c}, {"CPC_CTRL_d", CPC_CTRL_d}, {"CPC_CTRL_e", CPC_CTRL_e}, {"CPC_CTRL_f", CPC_CTRL_f}, {"CPC_CTRL_g", CPC_CTRL_g}, {"CPC_CTRL_h", CPC_CTRL_h}, {"CPC_CTRL_i", CPC_CTRL_i}, {"CPC_CTRL_j", CPC_CTRL_j}, {"CPC_CTRL_k", CPC_CTRL_k}, {"CPC_CTRL_l", CPC_CTRL_l}, {"CPC_CTRL_m", CPC_CTRL_m}, {"CPC_CTRL_n", CPC_CTRL_n}, {"CPC_CTRL_o", CPC_CTRL_o}, {"CPC_CTRL_p", CPC_CTRL_p}, {"CPC_CTRL_q", CPC_CTRL_q}, {"CPC_CTRL_r", CPC_CTRL_r}, {"CPC_CTRL_s", CPC_CTRL_s}, {"CPC_CTRL_t", CPC_CTRL_t}, {"CPC_CTRL_u", CPC_CTRL_u}, {"CPC_CTRL_v", CPC_CTRL_v}, {"CPC_CTRL_w", CPC_CTRL_w}, {"CPC_CTRL_x", CPC_CTRL_x}, {"CPC_CTRL_y", CPC_CTRL_y}, {"CPC_CTRL_z", CPC_CTRL_z}, {"CPC_CTRL_0", CPC_CTRL_0}, {"CPC_CTRL_1", CPC_CTRL_1}, {"CPC_CTRL_2", CPC_CTRL_2}, {"CPC_CTRL_3", CPC_CTRL_3}, {"CPC_CTRL_4", CPC_CTRL_4}, {"CPC_CTRL_5", CPC_CTRL_5}, {"CPC_CTRL_6", CPC_CTRL_6}, {"CPC_CTRL_7", CPC_CTRL_7}, {"CPC_CTRL_8", CPC_CTRL_8}, {"CPC_CTRL_9", CPC_CTRL_9}, {"CPC_CTRL_UP", CPC_CTRL_UP}, {"CPC_CTRL_DOWN", CPC_CTRL_DOWN}, {"CPC_CTRL_LEFT", CPC_CTRL_LEFT}, {"CPC_CTRL_RIGHT", CPC_CTRL_RIGHT}, {"CPC_AMPERSAND", CPC_AMPERSAND}, {"CPC_ASTERISK", CPC_ASTERISK}, {"CPC_AT", CPC_AT}, {"CPC_BACKQUOTE", CPC_BACKQUOTE}, {"CPC_BACKSLASH", CPC_BACKSLASH}, {"CPC_CAPSLOCK", CPC_CAPSLOCK}, {"CPC_CLR", CPC_CLR}, {"CPC_COLON", CPC_COLON}, {"CPC_COMMA", CPC_COMMA}, {"CPC_CONTROL", CPC_CONTROL}, {"CPC_COPY", CPC_COPY}, {"CPC_CPY_DOWN", CPC_CPY_DOWN}, {"CPC_CPY_LEFT", CPC_CPY_LEFT}, {"CPC_CPY_RIGHT", CPC_CPY_RIGHT}, {"CPC_CPY_UP", CPC_CPY_UP}, {"CPC_CUR_DOWN", CPC_CUR_DOWN}, {"CPC_CUR_LEFT", CPC_CUR_LEFT}, {"CPC_CUR_RIGHT", CPC_CUR_RIGHT}, {"CPC_CUR_UP", CPC_CUR_UP}, {"CPC_CUR_ENDBL", CPC_CUR_ENDBL}, {"CPC_CUR_HOMELN", CPC_CUR_HOMELN}, {"CPC_CUR_ENDLN", CPC_CUR_ENDLN}, {"CPC_CUR_HOMEBL", CPC_CUR_HOMEBL}, {"CPC_DBLQUOTE", CPC_DBLQUOTE}, {"CPC_DEL", CPC_DEL}, {"CPC_DOLLAR", CPC_DOLLAR}, {"CPC_ENTER", CPC_ENTER}, {"CPC_EQUAL", CPC_EQUAL}, {"CPC_ESC", CPC_ESC}, {"CPC_EXCLAMATN", CPC_EXCLAMATN}, {"CPC_F0", CPC_F0}, {"CPC_F1", CPC_F1}, {"CPC_F2", CPC_F2}, {"CPC_F3", CPC_F3}, {"CPC_F4", CPC_F4}, {"CPC_F5", CPC_F5}, {"CPC_F6", CPC_F6}, {"CPC_F7", CPC_F7}, {"CPC_F8", CPC_F8}, {"CPC_F9", CPC_F9}, {"CPC_CTRL_F0", CPC_CTRL_F0}, {"CPC_CTRL_F1", CPC_CTRL_F1}, {"CPC_CTRL_F2", CPC_CTRL_F2}, {"CPC_CTRL_F3", CPC_CTRL_F3}, {"CPC_CTRL_F4", CPC_CTRL_F4}, {"CPC_CTRL_F5", CPC_CTRL_F5}, {"CPC_CTRL_F6", CPC_CTRL_F6}, {"CPC_CTRL_F7", CPC_CTRL_F7}, {"CPC_CTRL_F8", CPC_CTRL_F8}, {"CPC_CTRL_F9", CPC_CTRL_F9}, {"CPC_SHIFT_F0", CPC_SHIFT_F0}, {"CPC_SHIFT_F1", CPC_SHIFT_F1}, {"CPC_SHIFT_F2", CPC_SHIFT_F2}, {"CPC_SHIFT_F3", CPC_SHIFT_F3}, {"CPC_SHIFT_F4", CPC_SHIFT_F4}, {"CPC_SHIFT_F5", CPC_SHIFT_F5}, {"CPC_SHIFT_F6", CPC_SHIFT_F6}, {"CPC_SHIFT_F7", CPC_SHIFT_F7}, {"CPC_SHIFT_F8", CPC_SHIFT_F8}, {"CPC_SHIFT_F9", CPC_SHIFT_F9}, {"CPC_FPERIOD", CPC_FPERIOD}, {"CPC_GREATER", CPC_GREATER}, {"CPC_HASH", CPC_HASH}, {"CPC_LBRACKET", CPC_LBRACKET}, {"CPC_LCBRACE", CPC_LCBRACE}, {"CPC_LEFTPAREN", CPC_LEFTPAREN}, {"CPC_LESS", CPC_LESS}, {"CPC_LSHIFT", CPC_LSHIFT}, {"CPC_MINUS", CPC_MINUS}, {"CPC_PERCENT", CPC_PERCENT}, {"CPC_PERIOD", CPC_PERIOD}, {"CPC_PIPE", CPC_PIPE}, {"CPC_PLUS", CPC_PLUS}, {"CPC_POUND", CPC_POUND}, {"CPC_POWER", CPC_POWER}, {"CPC_QUESTION", CPC_QUESTION}, {"CPC_QUOTE", CPC_QUOTE}, {"CPC_RBRACKET", CPC_RBRACKET}, {"CPC_RCBRACE", CPC_RCBRACE}, {"CPC_RETURN", CPC_RETURN}, {"CPC_RIGHTPAREN", CPC_RIGHTPAREN}, {"CPC_RSHIFT", CPC_RSHIFT}, {"CPC_SEMICOLON", CPC_SEMICOLON}, {"CPC_SLASH", CPC_SLASH}, {"CPC_SPACE", CPC_SPACE}, {"CPC_TAB", CPC_TAB}, {"CPC_UNDERSCORE", CPC_UNDERSCORE}, {"CPC_J0_UP", CPC_J0_UP}, {"CPC_J0_DOWN", CPC_J0_DOWN}, {"CPC_J0_LEFT", CPC_J0_LEFT}, {"CPC_J0_RIGHT", CPC_J0_RIGHT}, {"CPC_J0_FIRE1", CPC_J0_FIRE1}, {"CPC_J0_FIRE2", CPC_J0_FIRE2}, {"CPC_J1_UP", CPC_J1_UP}, {"CPC_J1_DOWN", CPC_J1_DOWN}, {"CPC_J1_LEFT", CPC_J1_LEFT}, {"CPC_J1_RIGHT", CPC_J1_RIGHT}, {"CPC_J1_FIRE1", CPC_J1_FIRE1}, {"CPC_J1_FIRE2", CPC_J1_FIRE2}, {"CPC_ES_NTILDE", CPC_ES_NTILDE}, {"CPC_ES_nTILDE", CPC_ES_nTILDE}, {"CPC_ES_PESETA", CPC_ES_PESETA}, {"CPC_FR_eACUTE", CPC_FR_eACUTE}, {"CPC_FR_eGRAVE", CPC_FR_eGRAVE}, {"CPC_FR_cCEDIL", CPC_FR_cCEDIL}, {"CPC_FR_aGRAVE", CPC_FR_aGRAVE}, {"CPC_FR_uGRAVE", CPC_FR_uGRAVE}, {"CAP32_EXIT", CAP32_EXIT}, {"CAP32_PASTE", CAP32_PASTE}, {"CAP32_FPS", CAP32_FPS}, {"CAP32_FULLSCRN", CAP32_FULLSCRN}, {"CAP32_GUI", CAP32_GUI}, {"CAP32_VKBD", CAP32_VKBD}, {"CAP32_JOY", CAP32_JOY}, {"CAP32_PHAZER", CAP32_PHAZER}, {"CAP32_MF2STOP", CAP32_MF2STOP}, {"CAP32_RESET", CAP32_RESET}, {"CAP32_SCRNSHOT", CAP32_SCRNSHOT}, {"CAP32_SNAPSHOT", CAP32_SNAPSHOT}, {"CAP32_LD_SNAP", CAP32_LD_SNAP}, {"CAP32_SPEED", CAP32_SPEED}, {"CAP32_TAPEPLAY", CAP32_TAPEPLAY}, {"CAP32_DEBUG", CAP32_DEBUG}, {"CAP32_DELAY", CAP32_DELAY}, {"CAP32_DEVTOOLS", CAP32_DEVTOOLS}, {"CAP32_WAITBREAK", CAP32_WAITBREAK}, }; const std::map<const std::string, const PCKey> InputMapper::SDLkeysFromStrings = { /*@{*/ /** @name ASCII mapped keysyms */ { "SDLK_BACKSPACE", SDLK_BACKSPACE}, { "SDLK_TAB", SDLK_TAB}, { "SDLK_CLEAR", SDLK_CLEAR}, { "SDLK_RETURN", SDLK_RETURN}, { "SDLK_PAUSE", SDLK_PAUSE}, { "SDLK_ESCAPE", SDLK_ESCAPE}, { "SDLK_SPACE", SDLK_SPACE}, { "SDLK_EXCLAIM", SDLK_EXCLAIM}, { "SDLK_QUOTEDBL", SDLK_QUOTEDBL}, { "SDLK_HASH", SDLK_HASH}, { "SDLK_DOLLAR", SDLK_DOLLAR}, { "SDLK_AMPERSAND", SDLK_AMPERSAND}, { "SDLK_QUOTE", SDLK_QUOTE}, { "SDLK_LEFTPAREN", SDLK_LEFTPAREN}, { "SDLK_RIGHTPAREN", SDLK_RIGHTPAREN}, { "SDLK_ASTERISK", SDLK_ASTERISK}, { "SDLK_PLUS", SDLK_PLUS}, { "SDLK_COMMA", SDLK_COMMA}, { "SDLK_MINUS", SDLK_MINUS}, { "SDLK_PERIOD", SDLK_PERIOD}, { "SDLK_SLASH", SDLK_SLASH}, { "SDLK_0", SDLK_0}, { "SDLK_1", SDLK_1}, { "SDLK_2", SDLK_2}, { "SDLK_3", SDLK_3}, { "SDLK_4", SDLK_4}, { "SDLK_5", SDLK_5}, { "SDLK_6", SDLK_6}, { "SDLK_7", SDLK_7}, { "SDLK_8", SDLK_8}, { "SDLK_9", SDLK_9}, { "SDLK_COLON", SDLK_COLON}, { "SDLK_SEMICOLON", SDLK_SEMICOLON}, { "SDLK_LESS", SDLK_LESS}, { "SDLK_EQUALS", SDLK_EQUALS}, { "SDLK_GREATER", SDLK_GREATER}, { "SDLK_QUESTION", SDLK_QUESTION}, { "SDLK_AT", SDLK_AT}, { "SDLK_LEFTBRACKET", SDLK_LEFTBRACKET}, { "SDLK_BACKSLASH", SDLK_BACKSLASH}, { "SDLK_RIGHTBRACKET", SDLK_RIGHTBRACKET}, { "SDLK_CARET", SDLK_CARET}, { "SDLK_UNDERSCORE", SDLK_UNDERSCORE}, { "SDLK_BACKQUOTE", SDLK_BACKQUOTE}, { "SDLK_a", SDLK_a}, { "SDLK_b", SDLK_b}, { "SDLK_c", SDLK_c}, { "SDLK_d", SDLK_d}, { "SDLK_e", SDLK_e}, { "SDLK_f", SDLK_f}, { "SDLK_g", SDLK_g}, { "SDLK_h", SDLK_h}, { "SDLK_i", SDLK_i}, { "SDLK_j", SDLK_j}, { "SDLK_k", SDLK_k}, { "SDLK_l", SDLK_l}, { "SDLK_m", SDLK_m}, { "SDLK_n", SDLK_n}, { "SDLK_o", SDLK_o}, { "SDLK_p", SDLK_p}, { "SDLK_q", SDLK_q}, { "SDLK_r", SDLK_r}, { "SDLK_s", SDLK_s}, { "SDLK_t", SDLK_t}, { "SDLK_u", SDLK_u}, { "SDLK_v", SDLK_v}, { "SDLK_w", SDLK_w}, { "SDLK_x", SDLK_x}, { "SDLK_y", SDLK_y}, { "SDLK_z", SDLK_z}, { "SDLK_DELETE", SDLK_DELETE}, { "SDLK_PERCENT", SDLK_PERCENT}, /*@}*/ /** @name Numeric keypad */ /*@{*/ { "SDLK_KP_0", SDLK_KP_0}, { "SDLK_KP_1", SDLK_KP_1}, { "SDLK_KP_2", SDLK_KP_2}, { "SDLK_KP_3", SDLK_KP_3}, { "SDLK_KP_4", SDLK_KP_4}, { "SDLK_KP_5", SDLK_KP_5}, { "SDLK_KP_6", SDLK_KP_6}, { "SDLK_KP_7", SDLK_KP_7}, { "SDLK_KP_8", SDLK_KP_8}, { "SDLK_KP_9", SDLK_KP_9}, { "SDLK_KP_PERIOD", SDLK_KP_PERIOD}, { "SDLK_KP_DIVIDE", SDLK_KP_DIVIDE}, { "SDLK_KP_MULTIPLY", SDLK_KP_MULTIPLY}, { "SDLK_KP_MINUS", SDLK_KP_MINUS}, { "SDLK_KP_PLUS", SDLK_KP_PLUS}, { "SDLK_KP_ENTER", SDLK_KP_ENTER}, { "SDLK_KP_EQUALS", SDLK_KP_EQUALS}, /*@}*/ /** @name Arrows + Home/End pad */ /*@{*/ { "SDLK_UP", SDLK_UP}, { "SDLK_DOWN", SDLK_DOWN}, { "SDLK_RIGHT", SDLK_RIGHT}, { "SDLK_LEFT", SDLK_LEFT}, { "SDLK_INSERT", SDLK_INSERT}, { "SDLK_HOME", SDLK_HOME}, { "SDLK_END", SDLK_END}, { "SDLK_PAGEUP", SDLK_PAGEUP}, { "SDLK_PAGEDOWN", SDLK_PAGEDOWN}, /*@}*/ /** @name Function keys */ /*@{*/ { "SDLK_F1", SDLK_F1}, { "SDLK_F2", SDLK_F2}, { "SDLK_F3", SDLK_F3}, { "SDLK_F4", SDLK_F4}, { "SDLK_F5", SDLK_F5}, { "SDLK_F6", SDLK_F6}, { "SDLK_F7", SDLK_F7}, { "SDLK_F8", SDLK_F8}, { "SDLK_F9", SDLK_F9}, { "SDLK_F10", SDLK_F10}, { "SDLK_F11", SDLK_F11}, { "SDLK_F12", SDLK_F12}, { "SDLK_F13", SDLK_F13}, { "SDLK_F14", SDLK_F14}, { "SDLK_F15", SDLK_F15}, /*@}*/ /** @name Key state modifier keys */ /*@{*/ { "SDLK_NUMLOCKCLEAR", SDLK_NUMLOCKCLEAR}, { "SDLK_CAPSLOCK", SDLK_CAPSLOCK}, { "SDLK_SCROLLLOCK", SDLK_SCROLLLOCK}, { "SDLK_RSHIFT", SDLK_RSHIFT}, { "SDLK_LSHIFT", SDLK_LSHIFT}, { "SDLK_RCTRL", SDLK_RCTRL}, { "SDLK_LCTRL", SDLK_LCTRL}, { "SDLK_RALT", SDLK_RALT}, { "SDLK_LALT", SDLK_LALT}, { "SDLK_LGUI", SDLK_LGUI}, /**< Left "Windows" key */ { "SDLK_RGUI", SDLK_RGUI}, /**< Right "Windows" key */ { "SDLK_MODE", SDLK_MODE}, /**< "Alt Gr" key */ { "SDLK_APPLICATION", SDLK_APPLICATION}, /**< Multi-key compose key */ /*@}*/ /** @name Miscellaneous function keys */ /*@{*/ { "SDLK_HELP", SDLK_HELP}, { "SDLK_PRINTSCREEN", SDLK_PRINTSCREEN}, { "SDLK_SYSREQ", SDLK_SYSREQ}, { "SDLK_PAUSE", SDLK_PAUSE}, { "SDLK_MENU", SDLK_MENU}, { "SDLK_POWER", SDLK_POWER}, /**< Power Macintosh power key */ { "SDLK_UNDO", SDLK_UNDO}, /**< Atari keyboard has Undo */ /*@}*/ /*@{*/ /** @name Fake SDL keycodes */ { "SDLK_nTILDE", 241}, { "SDLK_uGRAVE", 249}, { "SDLK_cCEDIL", 231}, { "SDLK_CIRC", 0x40000000}, { "SDLK_ESZETT", 223}, { "SDLK_DEGREE", 186}, { "SDLK_INV_QUESTION", 161}, /*@}*/ { "MOD_PC_SHIFT", MOD_PC_SHIFT}, { "MOD_PC_CTRL", MOD_PC_CTRL}, // MODE is AltGr or right Alt { "MOD_PC_MODE", MOD_PC_MODE}, // Alt key is mapped to COPY, ignore it as a modifier //{ "MOD_PC_ALT", MOD_PC_ALT} }; // Format of a line: CPC_xxx\tSDLK_xxx\tMODIFIER // Last field is optional LineParsingResult InputMapper::process_cfg_line(char *line) { LineParsingResult result; char *pch = strtok(line, "\t"); if (pch == nullptr || pch[0] == '#') return result; if (CPCkeysFromStrings.count(pch) == 0) { LOG_ERROR("Unknown CPC key " << pch << " found in mapping file. Ignoring it."); result.valid = false; return result; } for (unsigned int field=0; field < 3; field++) { switch (field) { case 0: result.cpc_key = CPCkeysFromStrings.at(pch); result.cpc_key_name += pch; break; case 1: case 2: if (SDLkeysFromStrings.count(pch) == 0) { LOG_ERROR("Unknown SDL key or modifier " << pch << " found in mapping file. Ignoring it."); result.valid = false; return result; } result.sdl_key |= SDLkeysFromStrings.at(pch); if (field > 1) result.sdl_key_name += " "; result.sdl_key_name += pch; break; default: break; } pch = strtok(nullptr, "\t"); if (pch == nullptr) break; } result.contains_mapping = true; SDLkeysymFromCPCkeys[result.cpc_key] = result.sdl_key; return result; } #define MAX_LINE_LENGTH 80 bool InputMapper::load_layout(const std::string& filename) { std::filebuf fb; char line[MAX_LINE_LENGTH]; // sufficient for now ! TODO(sebhz): proper malloc'ing etc... bool valid = true; if (is_directory(filename) || (fb.open(filename, std::ios::in) == nullptr)) { SDLkeysymFromCPCkeys = SDLkeysymFromCPCkeys_us; } else { std::istream is(&fb); std::set<CapriceKey> mapped_cpc_keys; std::set<PCKey> mapped_sdl_keys; while (is.good()) { is.getline(line, MAX_LINE_LENGTH); // This triggers the error even if the line just fits, but relying on failbit doesn't work (it's set also at EOF) so that will have to do. if (strlen(line) >= MAX_LINE_LENGTH-1) { LOG_ERROR("Mapping '" << filename << "' contains a line longer than " << MAX_LINE_LENGTH << " char, this is invalid: '" << line << "'"); valid = false; } auto parsed_line = process_cfg_line(line); valid &= parsed_line.valid; if (!parsed_line.contains_mapping) continue; // Verify that each CPC key is mapped only once if (mapped_cpc_keys.count(parsed_line.cpc_key) != 0) { LOG_ERROR("Mapping '" << filename << "' contains a CPC key multiple times: " << parsed_line.cpc_key_name); valid = false; } mapped_cpc_keys.insert(parsed_line.cpc_key); // And that no SDL key combination is mapped to 2 different CPC keys if (mapped_sdl_keys.count(parsed_line.sdl_key) != 0) { LOG_ERROR("Mapping '" << filename << "' contains a SDL key multiple times: " << parsed_line.sdl_key_name); valid = false; } mapped_sdl_keys.insert(parsed_line.sdl_key); } fb.close(); } return valid; } void InputMapper::init() { // Ensure we're starting from a fresh state SDLkeysymFromCPCkeys.clear(); CPCkeysFromSDLkeysym.clear(); SDLkeysFromChars.clear(); std::string layout_file = CPC->resources_path + "/" + CPC->kbd_layout; load_layout(layout_file); for (const auto &mapping : SDLkeysymFromCPCkeys) { CPCkeysFromSDLkeysym[mapping.second] = mapping.first; } for (const auto &mapping : CPCkeysFromChars) { if (SDLkeysymFromCPCkeys.count(mapping.second) != 0) { PCKey sdl_moddedkey = SDLkeysymFromCPCkeys[mapping.second]; SDLkeysFromChars[mapping.first] = std::make_pair(static_cast<SDL_Keycode>(sdl_moddedkey & BITMASK_NOMOD), static_cast<SDL_Keymod>(sdl_moddedkey >> BITSHIFT_MOD)); } } } CPCScancode InputMapper::CPCscancodeFromCPCkey(CPC_KEYS cpc_key) { return cpc_kbd[CPC->keyboard][cpc_key]; } CPCScancode InputMapper::CPCscancodeFromKeysym(SDL_Keysym keysym) { PCKey sdl_key = keysym.sym; if (keysym.mod & KMOD_SHIFT) sdl_key |= MOD_PC_SHIFT; if (keysym.mod & KMOD_CTRL) sdl_key |= MOD_PC_CTRL; // Map right alt to Mode (AltGr). Not clear what determines whether SDL2 uses one or the other and if both can happen together. if (keysym.mod & (KMOD_MODE | KMOD_RALT)) sdl_key |= MOD_PC_MODE; // Not mapping KMOD_LALT, the key itself is mapped to CPC_COPY. // Ignore sticky modifiers (MOD_PC_NUM and MOD_PC_CAPS) auto cpc_key = CPCkeysFromSDLkeysym.find(sdl_key); // TODO(sebhz) magic numbers are bad. Get rid of the 0xff. if (cpc_key == CPCkeysFromSDLkeysym.end()) return 0xff; if (cpc_key->second & MOD_EMU_KEY) return cpc_key->second; return cpc_kbd[CPC->keyboard][cpc_key->second]; } CapriceKey InputMapper::CPCkeyFromKeysym(SDL_Keysym keysym) { PCKey sdl_key = keysym.sym; if (keysym.mod & KMOD_SHIFT) sdl_key |= MOD_PC_SHIFT; if (keysym.mod & KMOD_CTRL) sdl_key |= MOD_PC_CTRL; // Map right alt to Mode (AltGr). Not clear what determines whether SDL2 uses one or the other and if both can happen together. if (keysym.mod & (KMOD_MODE | KMOD_RALT)) sdl_key |= MOD_PC_MODE; // Not mapping KMOD_LALT, the key itself is mapped to CPC_COPY. // Ignore sticky modifiers (MOD_PC_NUM and MOD_PC_CAPS) auto cpc_key = CPCkeysFromSDLkeysym.find(sdl_key); // TODO(sebhz) magic numbers are bad. Get rid of the 0xff. if (cpc_key == CPCkeysFromSDLkeysym.end()) return 0xff; return cpc_key->second; } std::string InputMapper::CPCkeyToString(const CapriceKey cpc_key) { if (cpc_key == 0xff) return "UNKNOWN"; for (const auto &[str, keycode] : CPCkeysFromStrings) { if (cpc_key == keycode) { return str; } } return "UNMAPPED(" + std::to_string(cpc_key) + ")"; } std::list<SDL_Event> InputMapper::StringToEvents(std::string toTranslate) { std::list<SDL_Event> result; bool escaped = false; bool cap32_cmd = false; std::map<CapriceKey, PCKey>::iterator sdl_keysym; for (auto c : toTranslate) { if (c == '\a') { // Escape prefix: next char is a special one escaped = true; continue; } if (c == '\f') { // Emulator special command cap32_cmd = true; continue; } SDL_Event key; if (escaped || cap32_cmd) { int keycode = static_cast<unsigned char>(c); if (cap32_cmd) { keycode += MOD_EMU_KEY; } // Lookup the SDL key corresponding to this emulator command sdl_keysym = SDLkeysymFromCPCkeys.find(keycode); if (sdl_keysym != SDLkeysymFromCPCkeys.end()) { key.key.keysym.sym = static_cast<SDL_Keycode>(sdl_keysym->second & BITMASK_NOMOD); key.key.keysym.mod = static_cast<SDL_Keymod>(sdl_keysym->second >> BITSHIFT_MOD); } escaped = false; cap32_cmd = false; } else { // key.key.keysym.scancode = ; key.key.keysym.sym = SDLkeysFromChars[c].first; key.key.keysym.mod = SDLkeysFromChars[c].second; // key.key.keysym.unicode = c; } key.key.type = SDL_KEYDOWN; key.key.state = SDL_PRESSED; result.push_back(key); key.key.type = SDL_KEYUP; key.key.state = SDL_RELEASED; result.push_back(key); } return result; } void InputMapper::set_joystick_emulation() { // CPC joy key, CPC original key static int joy_layout[12][2] = { { CPC_J0_UP, CPC_CUR_UP }, { CPC_J0_DOWN, CPC_CUR_DOWN }, { CPC_J0_LEFT, CPC_CUR_LEFT }, { CPC_J0_RIGHT, CPC_CUR_RIGHT }, { CPC_J0_FIRE1, CPC_z }, { CPC_J0_FIRE2, CPC_x }, { CPC_J1_UP, 0 }, { CPC_J1_DOWN, 0 }, { CPC_J1_LEFT, 0 }, { CPC_J1_RIGHT, 0 }, { CPC_J1_FIRE1, 0 }, { CPC_J1_FIRE2, 0 } }; for (int n = 0; n < 6; n++) { int cpc_idx = joy_layout[n][1]; // get the CPC key to change the assignment for if (cpc_idx) { PCKey pc_idx = SDLkeysymFromCPCkeys[cpc_idx]; // SDL key corresponding to the CPC key to remap if (CPC->joystick_emulation) { CPCkeysFromSDLkeysym[pc_idx] = joy_layout[n][0]; } else { CPCkeysFromSDLkeysym[pc_idx] = cpc_idx; } } } } CPCScancode InputMapper::CPCscancodeFromJoystickButton(SDL_JoyButtonEvent jbutton) { CPCScancode cpc_key(0xff); switch(jbutton.button) { case 0: switch(jbutton.which) { case 0: cpc_key = cpc_kbd[CPC->keyboard][CPC_J0_FIRE1]; break; case 1: cpc_key = cpc_kbd[CPC->keyboard][CPC_J1_FIRE1]; break; } break; case 1: switch(jbutton.which) { case 0: cpc_key = cpc_kbd[CPC->keyboard][CPC_J0_FIRE2]; break; case 1: cpc_key = cpc_kbd[CPC->keyboard][CPC_J1_FIRE2]; break; } break; default: break; } return cpc_key; } void InputMapper::CPCscancodeFromJoystickAxis(SDL_JoyAxisEvent jaxis, CPCScancode *cpc_key, bool &release) { switch(jaxis.axis) { case 0: case 2: switch(jaxis.which) { case 0: if(jaxis.value < -JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_LEFT]; } else if(jaxis.value > JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_RIGHT]; } else { // release both LEFT and RIGHT cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_LEFT]; cpc_key[1] = cpc_kbd[CPC->keyboard][CPC_J0_RIGHT]; release = true; } break; case 1: if(jaxis.value < -JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_LEFT]; } else if(jaxis.value > JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_RIGHT]; } else { // release both LEFT and RIGHT cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_LEFT]; cpc_key[1] = cpc_kbd[CPC->keyboard][CPC_J1_RIGHT]; release = true; } break; } break; case 1: case 3: switch(jaxis.which) { case 0: if(jaxis.value < -JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_UP]; } else if(jaxis.value > JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_DOWN]; } else { // release both UP and DOWN cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J0_UP]; cpc_key[1] = cpc_kbd[CPC->keyboard][CPC_J0_DOWN]; release = true; } break; case 1: if(jaxis.value < -JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_UP]; } else if(jaxis.value > JOYSTICK_AXIS_THRESHOLD) { cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_DOWN]; } else { // release both UP and DOWN cpc_key[0] = cpc_kbd[CPC->keyboard][CPC_J1_UP]; cpc_key[1] = cpc_kbd[CPC->keyboard][CPC_J1_DOWN]; release = true; } break; } break; } } InputMapper::InputMapper(t_CPC *CPC): CPC(CPC) { } void applyKeypress(CPCScancode cpc_key, byte keyboard_matrix[], bool pressed) { if ((!CPC.paused) && (static_cast<byte>(cpc_key) != 0xff)) { if (pressed) { keyboard_matrix[static_cast<byte>(cpc_key) >> 4] &= ~bit_values[static_cast<byte>(cpc_key) & 7]; // key is being held down if (cpc_key & MOD_CPC_SHIFT) { // CPC SHIFT key required? keyboard_matrix[0x25 >> 4] &= ~bit_values[0x25 & 7]; // key needs to be SHIFTed } else { keyboard_matrix[0x25 >> 4] |= bit_values[0x25 & 7]; // make sure key is unSHIFTed } if (cpc_key & MOD_CPC_CTRL) { // CPC CONTROL key required? keyboard_matrix[0x27 >> 4] &= ~bit_values[0x27 & 7]; // CONTROL key is held down } else { keyboard_matrix[0x27 >> 4] |= bit_values[0x27 & 7]; // make sure CONTROL key is released } } else { keyboard_matrix[static_cast<byte>(cpc_key) >> 4] |= bit_values[static_cast<byte>(cpc_key) & 7]; // key has been released keyboard_matrix[0x25 >> 4] |= bit_values[0x25 & 7]; // make sure key is unSHIFTed keyboard_matrix[0x27 >> 4] |= bit_values[0x27 & 7]; // make sure CONTROL key is not held down } } }
63,092
C++
.cpp
1,685
32.544807
168
0.48465
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,791
ipf.cpp
ColinPitrat_caprice32/src/ipf.cpp
// IPF disk image support (http://www.softpres.org/) // Contributed by softpres.org #ifdef WITH_IPF #ifdef WINDOWS #include <windows.h> #else #include <dlfcn.h> #endif #include "cap32.h" #include "disk.h" #include "errors.h" #include "fileutils.h" #include "memutils.h" #include "ipf.h" #include "log.h" #include "slotshandler.h" #include <string> #include <memory> extern t_CPC CPC; // Track decoding variables static bool fWrapped; static unsigned int uPos, uLastPos, uDecoded; static byte bLastData; static int nDataClock; static byte abDecoded[0x200000]; // 2MB static word s_wCRC; static struct CapsTrackInfoT1 cti; static dword dwLockFlags = DI_LOCK_UPDATEFD|DI_LOCK_TYPE; // Declare here all the CAPS functions we will need to import. // This is not very elegant but we do not want to use a lib wrapper // to keep things simpler. static CapsLong (*_CAPSInit)(void); static CapsLong (*_CAPSExit)(void); static CapsLong (*_CAPSAddImage)(void); static CapsLong (*_CAPSRemImage)(CapsLong); static CapsLong (*_CAPSLockImage)(CapsLong, char *); static CapsLong (*_CAPSUnlockImage)(CapsLong); static CapsLong (*_CAPSGetImageInfo)(struct CapsImageInfo *, CapsLong id); static CapsLong (*_CAPSLockTrack)(void *, CapsLong, CapsULong, CapsULong, CapsULong); static CapsLong (*_CAPSUnlockTrack)(CapsLong, CapsULong, CapsULong); static CapsLong (*_CAPSGetVersionInfo)(void *, CapsULong); #ifdef WINDOWS static HMODULE handle; #else static void *handle; #endif static int unload_caps_library(void) { #ifdef WINDOWS if (!FreeLibrary(handle)) return ERR_IPF_DYNLIB_LOAD; return 0; #else if (dlclose(handle) != 0) return ERR_IPF_DYNLIB_LOAD; return 0; #endif } static int load_caps_library(void) { #ifdef WINDOWS handle = LoadLibrary("CAPSImg.dll"); if (!handle) { LOG_ERROR("CAPSImg.dll is required for IPF support"); return ERR_IPF_DYNLIB_LOAD; } else { _CAPSInit = reinterpret_cast<CapsLong (*)(void)>(GetProcAddress(handle, "CAPSInit")); if (_CAPSInit == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSExit = reinterpret_cast<CapsLong (*)(void)>(GetProcAddress(handle, "CAPSExit")); if (_CAPSExit == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSAddImage = reinterpret_cast<CapsLong (*)(void)>(GetProcAddress(handle, "CAPSAddImage")); if (_CAPSAddImage == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSRemImage = reinterpret_cast<CapsLong (*)(CapsLong)>(GetProcAddress(handle, "CAPSRemImage")); if (_CAPSRemImage == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSLockImage = reinterpret_cast<CapsLong (*)(CapsLong, char *)>(GetProcAddress(handle, "CAPSLockImage")); if (_CAPSLockImage == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSUnlockImage = reinterpret_cast<CapsLong (*)(CapsLong)>(GetProcAddress(handle, "CAPSUnlockImage")); if (_CAPSUnlockImage == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSGetImageInfo = reinterpret_cast<CapsLong (*)(struct CapsImageInfo *, CapsLong)>(GetProcAddress(handle, "CAPSGetImageInfo")); if (_CAPSGetImageInfo == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSLockTrack = reinterpret_cast<CapsLong (*)(void *, CapsLong, CapsULong, CapsULong, CapsULong)>(GetProcAddress(handle, "CAPSLockTrack")); if (_CAPSLockTrack == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSUnlockTrack = reinterpret_cast<CapsLong (*)(CapsLong, CapsULong, CapsULong)>(GetProcAddress(handle, "CAPSUnlockTrack")); if (_CAPSUnlockTrack == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSGetVersionInfo = reinterpret_cast<CapsLong (*)(void *, CapsULong)>(GetProcAddress(handle, "CAPSGetVersionInfo")); if (_CAPSGetVersionInfo == NULL) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } return 0; } #else handle = dlopen("libcapsimage.so.4", RTLD_LAZY); if (!handle) { LOG_ERROR("Cannot open libcapsimage.so.4 needed for IPF support"); return ERR_IPF_DYNLIB_LOAD; } dlerror(); _CAPSInit = reinterpret_cast<CapsLong (*)(void)>(dlsym(handle, "CAPSInit")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSExit = reinterpret_cast<CapsLong (*)(void)>(dlsym(handle, "CAPSExit")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSAddImage = reinterpret_cast<CapsLong (*)(void)>(dlsym(handle, "CAPSAddImage")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSRemImage = reinterpret_cast<CapsLong (*)(CapsLong)>(dlsym(handle, "CAPSRemImage")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSLockImage = reinterpret_cast<CapsLong (*)(CapsLong, char *)>(dlsym(handle, "CAPSLockImage")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSUnlockImage = reinterpret_cast<CapsLong (*)(CapsLong)>(dlsym(handle, "CAPSUnlockImage")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSGetImageInfo = reinterpret_cast<CapsLong (*)(struct CapsImageInfo *, CapsLong)>(dlsym(handle, "CAPSGetImageInfo")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSLockTrack = reinterpret_cast<CapsLong (*)(void *, CapsLong, CapsULong, CapsULong, CapsULong)>(dlsym(handle, "CAPSLockTrack")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSUnlockTrack = reinterpret_cast<CapsLong (*)(CapsLong, CapsULong, CapsULong)>(dlsym(handle, "CAPSUnlockTrack")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } _CAPSGetVersionInfo = reinterpret_cast<CapsLong (*)(void *, CapsULong)>(dlsym(handle, "CAPSGetVersionInfo")); if (dlerror()) { unload_caps_library(); return ERR_IPF_DYNLIB_LOAD; } return 0; #endif } // CRC-16 CCITT, for track level header and data checksums static void Crc (byte b_) { static word awCRC[256]; if (!awCRC[1]) { for (int i = 0 ; i < 256 ; i++) { word w = i << 8; for (int j = 0 ; j < 8 ; j++) w = (w << 1) ^ ((w & 0x8000) ? 0x1021 : 0); awCRC[i] = w; } } s_wCRC = (s_wCRC << 8) ^ awCRC[((s_wCRC >> 8) ^ b_) & 0xff]; } // Read an MFM byte from the track static byte ReadByte () { byte b; // Convert bit position to byte offset+shift, and advance by 8 MFM bits unsigned int uOffset = uPos >> 3, uShift = uPos & 7; uPos += 8; // Byte-aligned? if (!uShift) b = cti.trackbuf[uOffset]; else b = (cti.trackbuf[uOffset] << uShift) | (cti.trackbuf[uOffset+1] >> (8 - uShift)); // Track wrapped? if (uPos >= cti.tracklen) { // Add the remaining bits from the start of the track (assumes cti.tracklen >= 8) unsigned int uWrapBits = uPos - cti.tracklen; b &= ~(((1 << uWrapBits)) - 1); b |= cti.trackbuf[0] >> (8 - uWrapBits); uPos -= cti.tracklen; fWrapped = true; } return b; } // Read an MFM word from the track static word ReadWord () { uLastPos = uPos; // Read 16 bits of interleaved MFM clock and data bits byte b1 = ReadByte(), b2 = ReadByte(); // Extract the clock bits byte bClock =((b1 << 0) & 0x80) | ((b1 << 1) & 0x40) | ((b1 << 2) & 0x20) | ((b1 << 3) & 0x10) | ((b2 >> 4) & 0x08) | ((b2 >> 3) & 0x04) | ((b2 >> 2) & 0x02) | ((b2 >> 1) & 0x01); // Extract the data bits byte bData = ((b1 << 1) & 0x80) | ((b1 << 2) & 0x40) | ((b1 << 3) & 0x20) | ((b1 << 4) & 0x10) | ((b2 >> 3) & 0x08) | ((b2 >> 2) & 0x04) | ((b2 >> 1) & 0x02) | ((b2 >> 0) & 0x01); // Calculate the expected clock bits for the data byte byte bGoodClock = 0; if (!(bData & 0x80) && !(bLastData & 1)) bGoodClock |= 0x80; if (!(bData & 0xc0)) bGoodClock |= 0x40; if (!(bData & 0x60)) bGoodClock |= 0x20; if (!(bData & 0x30)) bGoodClock |= 0x10; if (!(bData & 0x18)) bGoodClock |= 0x08; if (!(bData & 0x0c)) bGoodClock |= 0x04; if (!(bData & 0x06)) bGoodClock |= 0x02; if (!(bData & 0x03)) bGoodClock |= 0x01; // Determine the actual clock difference, needed to recognise address marks bClock ^= bGoodClock; // Store the decoded data for easier sector data extraction abDecoded[uDecoded++] = bLastData = bData; // Return a word containing the separated clock and data bytes return (bClock << 8) | bData; } // Read a data byte, discarding the clock bits static byte ReadDataByte() { return ReadWord() & 0xff; } // Process the MFM track data to extract sector headers and data fields static void ReadTrack (t_track *pt_) { t_sector *ps = nullptr; unsigned int uHeaderOffset = 0; // Initialise scanning state uPos = uDecoded = 0; fWrapped = false; bLastData = 0x00; nDataClock = 0; // Return if no track data or if updating and track not flakey if (!cti.tracklen) return; else if (pt_->data && !(cti.type & CTIT_FLAG_FLAKEY)) return; // Loop until end of track, completing sectors that spanning the track wrapping point while (!fWrapped || ps) { byte bAM; // Continue iff we find 3xA1 with missing clock bits if (ReadWord() != 0x04a1) { uPos -= 15; uDecoded--; continue; } // advance by 1 bit on mismatches, discard decoded byte if (ReadWord() != 0x04a1) continue; if (ReadWord() != 0x04a1) continue; // CRC 3xA1 + address mark s_wCRC = 0xcdb4; Crc(bAM = ReadDataByte()); switch (bAM) { case 0xfe: // id address mark { // Check we've room for another sector if (pt_->sectors >= DSK_SECTORMAX) continue; // Allocate new sector ps = &pt_->sector[pt_->sectors++]; // Read ID header and CRC Crc(ps->CHRN[0] = ReadDataByte()); Crc(ps->CHRN[1] = ReadDataByte()); Crc(ps->CHRN[2] = ReadDataByte()); Crc(ps->CHRN[3] = ReadDataByte()); Crc(ReadDataByte()); Crc(ReadDataByte()); // If the header CRC is bad we ignore it if (s_wCRC) { pt_->sectors--; ps = nullptr; continue; } // Remember the track position of the header uHeaderOffset = uLastPos; continue; } case 0xfb: case 0xfa: // data address mark (+alt) case 0xf8: case 0xf9: // data address mark with control mark (+alt) { // Remember where the data started and the wrap status unsigned int uDataPos = uPos; bool fDataWrapped = fWrapped; // Ignore the data field if there's no associated header if (!ps) continue; // Check the byte distance between header and data fields unsigned int uOffset = (uLastPos - uHeaderOffset) >> 4; // If it's too close or too far, the data isn't accessible if (uOffset < 32 || uOffset >= 64) { ps->flags[1] &= ~0x01; // no data ps = nullptr; continue; } // Flag the control mark if the DAM indicates one if (bAM == 0xf8 || bAM == 0xf9) ps->flags[1] |= 0x40; // Set the data position in the buffer and sector size ps->setData(abDecoded + uDecoded); unsigned int sector_size = (ps->CHRN[3] <= 7) ? (128 << ps->CHRN[3]) : 0x8000; ps->setSizes(sector_size, sector_size); // Decode and CRC the data field for (unsigned int u = 0 ; u < ps->getTotalSize() ; u++) Crc(ReadDataByte()); // Include data CRC bytes Crc(ReadDataByte()); Crc(ReadDataByte()); // Bad CRC? if (s_wCRC) { // Flag a data CRC error ps->flags[0] |= 0x20; ps->flags[1] |= 0x20; } // To allow for read-track protections, overread the first data field to 4K if (pt_->sectors == 1 && ps->getTotalSize() < 4096) { for (unsigned int u = 0 ; u < (4096 - ps->getTotalSize()) ; u++) Crc(ReadDataByte()); } // Sector complete ps = nullptr; // Step back up to just after the data position to check for more address marks // as sectors could be overlapping uPos = uDataPos; fWrapped = fDataWrapped; continue; } } } // Data buffer not allocated yet? if (!pt_->data) { // Allocate enough for the full decoded size, allowing for expanded overlapping sectors std::shared_ptr<byte[]> datamng = std::shared_ptr<byte[]>(new byte[uDecoded]); memcpy(pt_->data = datamng.get(), abDecoded, pt_->size = uDecoded); auto offset = (pt_->data-abDecoded); // Set the sector data pointers for the new buffer for (unsigned int u = 0 ; u < pt_->sectors ; u++) pt_->sector[u].setData(pt_->sector[u].getDataForWrite()+offset); } } // Track hook, called each disk rotation to allow flakey data to be updated void ipf_track_hook (t_drive *drive) { byte cyl = drive->current_track, head = drive->current_side; long id = drive->ipf_id; // Re-lock and update the track (note: don't use CAPSUnlockTrack() first as it resets the flakey data RNG!) cti.type = 1; if (_CAPSLockTrack(reinterpret_cast<CapsTrackInfo*>(&cti), id, cyl, head, dwLockFlags) == imgeOk) { t_track *pt = &drive->track[cyl][head]; if (!cti.tracklen) memset(pt, 0, sizeof(*pt)); else { // Convert track length to bits if supported if (!(dwLockFlags & DI_LOCK_TRKBIT)) cti.tracklen <<= 3; ReadTrack(pt); } } } // Eject hook, for additional disk image clean-up void ipf_eject_hook (t_drive *drive) { long id = drive->ipf_id; _CAPSUnlockImage(id); _CAPSRemImage(id); _CAPSExit(); unload_caps_library(); drive->altered = false; // discard modifications drive->eject_hook = nullptr; } int ipf_load (FILE *pfileIn, t_drive *drive) { // IPF library needs a filename to be provided so we have to create a new temporary file. // This file is not deleted. // TODO(cpitrat): register the file for cleanup somewhere (e.g: at caprice exit) FILE *pfileOut = nullptr; char *tmpFilePath = nullptr; std::vector<std::string> prefixes = { "/tmp", "." }; for (const auto &prefix : prefixes) { tmpFilePath = tempnam(prefix.c_str(), ".cap32_tmp_"); if (tmpFilePath == nullptr) { LOG_ERROR("Couldn't load IPF file: Couldn't generate temporary file name: " << strerror(errno)); return ERR_DSK_INVALID; // couldn't create output file } LOG_DEBUG("Using temporary file: " << tmpFilePath); pfileOut = fopen(tmpFilePath, "w+b"); if (pfileOut != nullptr) { break; } } if (!file_copy(pfileIn, pfileOut)) { LOG_ERROR("Error while copying file"); return ERR_DSK_INVALID; } if (fclose(pfileOut) != 0) { LOG_ERROR("Error while closing temporary file"); return ERR_DSK_INVALID; } return ipf_load(tmpFilePath, drive); } // Attempt to load the supplied file as an IPF disk image int ipf_load (const std::string &filename, t_drive *drive) { char sz[4]; long id = -1; struct CapsImageInfo cii; struct CapsVersionInfo vi = { 0, 0, 0, 0 }; dsk_eject(drive); FILE *f = fopen(filename.c_str(), "rb"); if (!f) { LOG_ERROR("Couldn't open file: " << filename); return ERR_DSK_INVALID; } auto closure = [&]() { fclose(f); }; memutils::scope_exit<decltype(closure)> cs(closure); // Check for IPF file signature if (!fread(sz, 4, 1, f) || memcmp(sz, "CAPS", sizeof(sz))) { LOG_ERROR("Wrong IPF header in: " << filename); return ERR_DSK_INVALID; } // Ensure the SPS library is present before we try to use the delay-load calls int sts = load_caps_library(); if (sts) return sts; // Check that the DLL supports the CapsTrackInfoT1 structure we need if (_CAPSGetVersionInfo(&vi, 0) != imgeOk || vi.release < 4) // compatible DLL? { LOG_ERROR("IPF shared library is too old. Requiring version >=4. Please upgrade it"); return ERR_DSK_INVALID; } // Use bit lengths if available dwLockFlags |= vi.flag & (DI_LOCK_OVLBIT|DI_LOCK_TRKBIT); // Initialise the library if (_CAPSInit() != imgeOk) { LOG_ERROR("IPF shared library initialisation failed!"); return ERR_DSK_INVALID; } // Create a new image container id = _CAPSAddImage(); // Attach the IPF file to the container if (_CAPSLockImage(id, const_cast<char*>(filename.c_str())) != imgeOk) { _CAPSRemImage(id); _CAPSExit(); unload_caps_library(); LOG_ERROR("Couldn't lock image: " << filename); return ERR_DSK_INVALID; } // Get details about the contents of the image if (_CAPSGetImageInfo(&cii, id) != imgeOk) { _CAPSRemImage(id); _CAPSExit(); unload_caps_library(); LOG_ERROR("Couldn't get image info: " << filename); return ERR_DSK_INVALID; } // Set up the internal drive details drive->tracks = cii.maxcylinder+1; drive->sides = cii.maxhead; drive->altered = false; drive->track_hook = ipf_track_hook; drive->eject_hook = ipf_eject_hook; // Load all tracks from the image for (byte cyl = static_cast<byte>(cii.mincylinder); cyl <= cii.maxcylinder ; cyl++) { for (byte head = static_cast<byte>(cii.minhead); head <= cii.maxhead ; head++) { cti.type = 1; if (_CAPSLockTrack(reinterpret_cast<CapsTrackInfo*>(&cti), id, cyl, head, dwLockFlags) != imgeOk) { LOG_ERROR("Failed to lock IPF track, please upgrade IPF shared library."); _CAPSUnlockImage(id); _CAPSRemImage(id); _CAPSExit(); unload_caps_library(); return ERR_DSK_INVALID; } t_track *pt = &drive->track[cyl][head]; if (!cti.tracklen) memset(pt, 0, sizeof(*pt)); else ReadTrack(pt); _CAPSUnlockTrack(id, cyl, head); } } // Store the IPF id for later use drive->ipf_id = id; return 0; } #endif
17,839
C++
.cpp
467
33.640257
144
0.651246
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,792
glfuncs.cpp
ColinPitrat_caprice32/src/glfuncs.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "glfuncs.h" #include <cstdio> #ifdef HAVE_GL #define GL_FUNC(ret,func,params) ptr##func e##func=nullptr; #define GL_FUNC_OPTIONAL(ret,func,params) ptr##func e##func=nullptr; #include "glfunclist.h" #undef GL_FUNC #undef GL_FUNC_OPTIONAL #define GL_FUNC(ret,func,params) \ do { \ e##func = reinterpret_cast<ptr##func>(SDL_GL_GetProcAddress(#func)); \ if ( ! e##func ) { \ printf("Unable to load GL function %s\n", #func); \ return(1); \ } \ } while ( 0 ); #define GL_FUNC_OPTIONAL(ret,func,params) \ do { \ e##func = reinterpret_cast<ptr##func>(SDL_GL_GetProcAddress(#func)); \ } while ( 0 ); int init_glfuncs() { #include "glfunclist.h" return 0; } #undef GL_FUNC #undef GL_FUNC_OPTIONAL #endif
1,504
C++
.cpp
42
33.285714
72
0.733103
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,793
video.cpp
ColinPitrat_caprice32/src/video.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* This file includes video filters from the SMS Plus/SDL sega master system emulator : (c) Copyright Gregory Montoir http://membres.lycos.fr/cyxdown/smssdl/ */ /* This file includes video filters from MAME (Multiple Arcade Machine Emulator) : (c) Copyright The MAME Team http://www.mame.net/ */ #include "video.h" #include "cap32.h" #include "log.h" #include "glfuncs.h" #ifdef HAVE_GL #include "SDL_opengl.h" #endif #include <math.h> #include <memory> #include <iostream> SDL_Window* mainSDLWindow = nullptr; SDL_Renderer* renderer = nullptr; SDL_Texture* texture = nullptr; SDL_GLContext glcontext; // the video surface ready to display SDL_Surface* vid = nullptr; // the video surface scaled with same format as pub SDL_Surface* scaled = nullptr; // the video surface shown by the plugin to the application SDL_Surface* pub = nullptr; extern t_CPC CPC; #ifndef min #define min(a,b) ((a)<(b) ? (a) : (b)) #endif #ifndef max #define max(a,b) ((a)>(b) ? (a) : (b)) #endif // checks for an OpenGL extension #ifdef HAVE_GL static bool have_gl_extension (const char *nom_ext) { const char *ext; ext = reinterpret_cast<const char *> (eglGetString (GL_EXTENSIONS)); const char *f; if (ext == nullptr) return false; f = ext + strlen (ext); while (ext < f) { unsigned int n = strcspn (ext, " "); if ((strlen (nom_ext) == n) && (strncmp (nom_ext, ext, n) == 0)) return true; ext += (n + 1); } return false; } #endif // Returns a bpp compatible with the renderer int renderer_bpp(SDL_Renderer *sdl_renderer) { SDL_RendererInfo infos; SDL_GetRendererInfo(sdl_renderer, &infos); return SDL_BITSPERPIXEL(infos.texture_formats[0]); } // TODO: Cleanup sw_scaling if really not needed void compute_scale(video_plugin* t, int w, int h) { int win_width, win_height; SDL_GetWindowSize(mainSDLWindow, &win_width, &win_height); if (CPC.scr_preserve_aspect_ratio != 0) { float win_x_scale, win_y_scale; win_x_scale = w/static_cast<float>(win_width); win_y_scale = h/static_cast<float>(win_height); float scale = max(win_x_scale, win_y_scale); t->width=w/scale; t->height=h/scale; float x_offset = 0.5*(win_width-t->width); float y_offset = 0.5*(win_height-t->height); t->x_offset=x_offset; t->y_offset=y_offset; t->x_scale=scale; t->y_scale=scale; } else { t->x_offset=0; t->y_offset=0; t->x_scale=w/static_cast<float>(win_width); t->y_scale=h/static_cast<float>(win_height); t->width = win_width; t->height = win_height; } } /* ------------------------------------------------------------------------------------ */ /* Half size video plugin ------------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ SDL_Surface* direct_init(video_plugin* t, int scale, bool fs) { SDL_CreateWindowAndRenderer(CPC_VISIBLE_SCR_WIDTH*scale, CPC_VISIBLE_SCR_HEIGHT*scale, (fs?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN), &mainSDLWindow, &renderer); if (!mainSDLWindow || !renderer) return nullptr; SDL_SetWindowTitle(mainSDLWindow, "Caprice32 " VERSION_STRING); int surface_width, surface_height; if (scale > 1) { t->half_pixels = 0; surface_width = CPC_VISIBLE_SCR_WIDTH * 2; surface_height = CPC_VISIBLE_SCR_HEIGHT * 2; } else { t->half_pixels = 1; surface_width = CPC_VISIBLE_SCR_WIDTH; surface_height = CPC_VISIBLE_SCR_HEIGHT; } vid = SDL_CreateRGBSurface(0, surface_width, surface_height, renderer_bpp(renderer), 0, 0, 0, 0); if (!vid) return nullptr; texture = SDL_CreateTextureFromSurface(renderer, vid); if (!texture) return nullptr; SDL_FillRect(vid, nullptr, SDL_MapRGB(vid->format,0,0,0)); compute_scale(t, surface_width, surface_height); return vid; } void direct_setpal(SDL_Color* c) { SDL_SetPaletteColors(vid->format->palette, c, 0, 32); } void direct_flip(video_plugin* t) { SDL_UpdateTexture(texture, nullptr, vid->pixels, vid->pitch); SDL_RenderClear(renderer); if (CPC.scr_preserve_aspect_ratio != 0) { SDL_Rect dest_rect = { t->x_offset, t->y_offset, t->width, t->height }; SDL_RenderCopy(renderer, texture, nullptr, &dest_rect); } else { SDL_RenderCopy(renderer, texture, nullptr, nullptr); } SDL_RenderPresent(renderer); } void direct_close() { if (texture) SDL_DestroyTexture(texture); if (vid) SDL_FreeSurface(vid); if (renderer) SDL_DestroyRenderer(renderer); if (mainSDLWindow) SDL_DestroyWindow(mainSDLWindow); } #ifdef HAVE_GL /* ------------------------------------------------------------------------------------ */ /* OpenGL scaling video plugin -------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ static int tex_x,tex_y; static GLuint screen_texnum,modulate_texnum; static int gl_scanlines; SDL_Surface* glscale_init(video_plugin* t, int scale, bool fs) { #ifdef _WIN32 const char *gl_library = "OpenGL32.DLL"; #else const char *gl_library = "libGL.so.1"; #endif gl_scanlines=CPC.scr_oglscanlines; SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (SDL_GL_LoadLibrary(gl_library)<0) { fprintf(stderr,"Unable to dynamically open GL lib : %s\n",SDL_GetError()); return nullptr; } int width = CPC_VISIBLE_SCR_WIDTH*scale; int height = CPC_VISIBLE_SCR_HEIGHT*scale; SDL_CreateWindowAndRenderer(width, height, (fs?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN) | SDL_WINDOW_OPENGL, &mainSDLWindow, &renderer); if (!mainSDLWindow || !renderer) return nullptr; if (fs) { SDL_DisplayMode display; SDL_GetCurrentDisplayMode(0, &display); width = display.w; height = display.h; } vid = SDL_CreateRGBSurface(0, width, height, renderer_bpp(renderer), 0, 0, 0, 0); if (!vid) return nullptr; glcontext = SDL_GL_CreateContext(mainSDLWindow); if (init_glfuncs()!=0) { fprintf(stderr, "Cannot init OpenGL functions: %s\n", SDL_GetError()); return nullptr; } int major, minor; const char *version; version = reinterpret_cast<const char *>(eglGetString(GL_VERSION)); if (sscanf(version, "%d.%d", &major, &minor) != 2) { fprintf(stderr, "Unable to get OpenGL version: got %s.\n", version); return nullptr; } GLint max_texsize; eglGetIntegerv(GL_MAX_TEXTURE_SIZE,&max_texsize); if (max_texsize<1024) { printf("Your OpenGL implementation doesn't support 1024x1024 textures: max size = %d\n", max_texsize); t->half_pixels = 1; } if (max_texsize<512) { fprintf(stderr, "Your OpenGL implementation doesn't support 512x512 textures\n"); return nullptr; } unsigned int original_width, original_height, tex_size; if (t->half_pixels) { tex_size = 512; original_width = CPC_VISIBLE_SCR_WIDTH; original_height = CPC_VISIBLE_SCR_HEIGHT; } else { tex_size = 1024; original_width = CPC_VISIBLE_SCR_WIDTH * 2; original_height = CPC_VISIBLE_SCR_HEIGHT * 2; } compute_scale(t, original_width, original_height); // We have to react differently to the bpp parameter than with software rendering // Here are the rules : // for 8bpp OpenGL, we need the GL_EXT_paletted_texture extension // for 16bpp OpenGL, we need OpenGL 1.2+ // for 24bpp reversed OpenGL, we need OpenGL 1.2+ std::vector<int> candidates_bpp{32, 24, 16, 8}; int surface_bpp = 0; for (int try_bpp : candidates_bpp) { switch(try_bpp) { case 8: surface_bpp = (have_gl_extension("GL_EXT_paletted_texture"))?8:0; break; case 15: case 16: surface_bpp = ((major>1)||(major == 1 && minor >= 2))?16:0; break; case 24: case 32: default: surface_bpp = ((major>1)||(major == 1 && minor >= 2))?24:0; break; } if (surface_bpp == 0) { fprintf(stderr, "Your OpenGL implementation doesn't support %dbpp textures\n", try_bpp); } else { break; } } if (surface_bpp == 0) { fprintf(stderr, "FATAL: Couldn't find a supported OpenGL color depth.\n"); return nullptr; } eglDisable(GL_FOG); eglDisable(GL_LIGHTING); eglDisable(GL_CULL_FACE); eglDisable(GL_DEPTH_TEST); eglDisable(GL_BLEND); eglDisable(GL_NORMALIZE); eglDisable(GL_ALPHA_TEST); eglEnable(GL_TEXTURE_2D); eglBlendFunc (GL_SRC_ALPHA, GL_ONE); eglGenTextures(1,&screen_texnum); eglBindTexture(GL_TEXTURE_2D,screen_texnum); eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, CPC.scr_oglfilter?GL_LINEAR:GL_NEAREST); eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, CPC.scr_oglfilter?GL_LINEAR:GL_NEAREST); tex_x=tex_size; tex_y=tex_size; switch(surface_bpp) { case 24: eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,tex_x,tex_y, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); break; case 16: eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB5,tex_x,tex_y, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); break; case 8: eglTexImage2D(GL_TEXTURE_2D, 0,GL_COLOR_INDEX8_EXT,tex_x,tex_y, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, nullptr); break; } if (gl_scanlines!=0) { Uint8 texmod; texmod=(100-gl_scanlines)*255/100; eglGenTextures(1,&modulate_texnum); eglBindTexture(GL_TEXTURE_2D,modulate_texnum); eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, CPC.scr_oglfilter?GL_LINEAR:GL_NEAREST); eglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, CPC.scr_oglfilter?GL_LINEAR:GL_NEAREST); Uint8 modulate_texture[]={ 255,255,255, 0,0,0}; modulate_texture[3]=texmod; modulate_texture[4]=texmod; modulate_texture[5]=texmod; eglTexImage2D(GL_TEXTURE_2D, 0,GL_RGB8,1,2, 0,GL_RGB,GL_UNSIGNED_BYTE, modulate_texture); } if (CPC.scr_preserve_aspect_ratio) { eglViewport(t->x_offset, t->y_offset, t->width, t->height); } else { eglViewport(0, 0, width, height); } eglMatrixMode(GL_PROJECTION); eglLoadIdentity(); eglOrtho(0, width, height, 0, -1.0, 1.0); eglMatrixMode(GL_MODELVIEW); eglLoadIdentity(); pub=SDL_CreateRGBSurface(0, original_width, original_height, surface_bpp, 0, 0, 0, 0); return pub; } void glscale_setpal(SDL_Color* c) { SDL_SetPaletteColors(pub->format->palette, c, 0, 32); if (pub->format->palette) { std::unique_ptr<Uint8[]> pal = std::make_unique<Uint8[]>(256*3); for(int i=0;i<256;i++) { pal[3*i ] = pub->format->palette->colors[i].r; pal[3*i+1] = pub->format->palette->colors[i].g; pal[3*i+2] = pub->format->palette->colors[i].b; } eglBindTexture(GL_TEXTURE_2D,screen_texnum); eglColorTableEXT(GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,pal.get()); } } void glscale_flip(video_plugin* t __attribute__((unused))) { eglDisable(GL_BLEND); eglClearColor(0,0,0,1); eglClear(GL_COLOR_BUFFER_BIT); if (gl_scanlines!=0) { eglActiveTextureARB(GL_TEXTURE1_ARB); eglEnable(GL_TEXTURE_2D); eglBindTexture(GL_TEXTURE_2D,modulate_texnum); eglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); eglColor4f(1.0,1.0,1.0,1.0); eglActiveTextureARB(GL_TEXTURE0_ARB); } eglEnable(GL_TEXTURE_2D); eglBindTexture(GL_TEXTURE_2D,screen_texnum); if (CPC.scr_remanency && !CPC.scr_gui_is_currently_on) { /* draw again using the old texture */ eglBegin(GL_QUADS); eglColor4f(1.0,1.0,1.0,1.0); eglTexCoord2f(0.f, 0.f); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.f, 0.f); eglVertex2i(0, 0); eglTexCoord2f(0.f, static_cast<float>(pub->h)/tex_y); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.f, vid->h/2); eglVertex2i(0, vid->h); eglTexCoord2f(static_cast<float>(pub->w)/tex_x, static_cast<float>(pub->h)/tex_y); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,vid->w, vid->h/2); eglVertex2i(vid->w, vid->h); eglTexCoord2f(static_cast<float>(pub->w)/tex_x, 0.f); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,vid->w, 0); eglVertex2i(vid->w, 0); eglEnd(); /* enable blending for the subsequent pass */ eglEnable(GL_BLEND); eglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* upload the texture */ switch(pub->format->BitsPerPixel) { case 24: eglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pub->w, pub->h, GL_BGR,GL_UNSIGNED_BYTE, pub->pixels); break; case 16: eglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pub->w, pub->h, GL_RGB,GL_UNSIGNED_SHORT_5_6_5, pub->pixels); break; case 8: eglTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, pub->w,pub->h, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, pub->pixels); break; } /* draw ! */ eglBegin(GL_QUADS); eglColor4f(1.0,1.0,1.0,0.5); eglTexCoord2f(0.f, 0.f); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.f, 0.f); eglVertex2i(0, 0); eglTexCoord2f(0.f, static_cast<float>(pub->h)/tex_y); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.f, vid->h/2); eglVertex2i(0, vid->h); eglTexCoord2f(static_cast<float>(pub->w)/tex_x, static_cast<float>(pub->h)/tex_y); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,vid->w, vid->h/2); eglVertex2i(vid->w, vid->h); eglTexCoord2f(static_cast<float>(pub->w)/tex_x, 0.f); if (gl_scanlines!=0) eglMultiTexCoord2fARB(GL_TEXTURE1_ARB,vid->w, 0); eglVertex2i(vid->w, 0); eglEnd(); SDL_GL_SwapWindow(mainSDLWindow); } void glscale_close() { direct_close(); SDL_FreeSurface(pub); pub = nullptr; } #endif // HAVE_GL /* ------------------------------------------------------------------------------------ */ /* Common 2x software scaling code ---------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ /* Computes the clipping of pub and scaled surfaces and put the result in src and dst accordingly. * * This provides the rectangles to clip to obtain a centered doubled CPC display * in the middle of the dst surface if it fits * * dst is the screen * src is the internal window * * Only exposed for testing purposes. Shouldn't be used outside of video.cpp */ static void compute_rects(SDL_Rect* src, SDL_Rect* dst, Uint8 half_pixels) { int surface_width = CPC_VISIBLE_SCR_WIDTH*4; int surface_height = CPC_VISIBLE_SCR_HEIGHT*4; if (half_pixels) { surface_width = CPC_VISIBLE_SCR_WIDTH*2; surface_height = CPC_VISIBLE_SCR_HEIGHT*2; } /* initialise the source rect to full source */ src->x=0; src->y=0; src->w=pub->w; src->h=pub->h; dst->x=(scaled->w-surface_width)/2, dst->y=(scaled->h-surface_height)/2; dst->w=scaled->w; dst->h=scaled->h; int dw=src->w*2-dst->w; /* the src width is too big */ if (dw>0) { // To ensure src is not bigger than dst for odd widths. dw += 1; src->w-=dw/2; src->x+=dw/4; dst->x=0; dst->w=scaled->w; } else { dst->w=surface_width; } int dh=src->h*2-dst->h; /* the src height is too big */ if (dh>0) { // To ensure src is not bigger than dst for odd heights. dh += 1; src->h-=dh/2; src->y+=dh/4; dst->y=0; dst->h=scaled->h; } else { // Without this -=, the bottom of the screen has line with random pixels. // With this, they are black instead which is slightly better. // Investigating where this comes from and how to avoid it would be nice! src->h-=2*2; dst->h=surface_height; } } void compute_rects_for_tests(SDL_Rect* src, SDL_Rect* dst, Uint8 half_pixels) { compute_rects(src, dst, half_pixels); } SDL_Surface* swscale_init(video_plugin* t, int scale, bool fs) { SDL_CreateWindowAndRenderer(CPC_VISIBLE_SCR_WIDTH*scale, CPC_VISIBLE_SCR_HEIGHT*scale, (fs?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN), &mainSDLWindow, &renderer); if (!mainSDLWindow || !renderer) return nullptr; SDL_SetWindowTitle(mainSDLWindow, "Caprice32 " VERSION_STRING); int surface_width, surface_height; if (scale < 4) { t->half_pixels = 1; surface_width = CPC_VISIBLE_SCR_WIDTH; surface_height = CPC_VISIBLE_SCR_HEIGHT; } else { t->half_pixels = 0; surface_width = CPC_VISIBLE_SCR_WIDTH * 2; surface_height = CPC_VISIBLE_SCR_HEIGHT * 2; } vid = SDL_CreateRGBSurface(0, surface_width*2, surface_height*2, renderer_bpp(renderer), 0, 0, 0, 0); if (!vid) return nullptr; texture = SDL_CreateTextureFromSurface(renderer, vid); if (!texture) return nullptr; scaled = SDL_CreateRGBSurface(0, surface_width*2, surface_height*2, 16, 0, 0, 0, 0); if (!scaled) return nullptr; if (scaled->format->BitsPerPixel!=16) { LOG_ERROR(t->name << ": SDL didn't return a 16 bpp surface but a " << static_cast<int>(scaled->format->BitsPerPixel) << " bpp one."); return nullptr; } SDL_FillRect(vid, nullptr, SDL_MapRGB(vid->format,0,0,0)); compute_scale(t, surface_width, surface_height); pub = SDL_CreateRGBSurface(0, surface_width, surface_height, 16, 0, 0, 0, 0); if (pub->format->BitsPerPixel!=16) { LOG_ERROR(t->name << ": SDL didn't return a 16 bpp surface but a " << static_cast<int>(pub->format->BitsPerPixel) << " bpp one."); return nullptr; } return pub; } // Common code to all software plugin to display the vid surface after it's been computed. void swscale_blit(video_plugin* t) { // Blit to convert from 16bpp to pixel format compatible with renderer. SDL_BlitSurface(scaled, nullptr, vid, nullptr); SDL_UpdateTexture(texture, nullptr, vid->pixels, vid->pitch); SDL_RenderClear(renderer); if (CPC.scr_preserve_aspect_ratio != 0) { SDL_Rect dest_rect = { t->x_offset, t->y_offset, t->width, t->height }; SDL_RenderCopy(renderer, texture, nullptr, &dest_rect); } else { SDL_RenderCopy(renderer, texture, nullptr, nullptr); } SDL_RenderPresent(renderer); } void swscale_setpal(SDL_Color* c) { SDL_SetPaletteColors(scaled->format->palette, c, 0, 32); SDL_SetPaletteColors(pub->format->palette, c, 0, 32); } void swscale_close() { direct_close(); SDL_FreeSurface(pub); pub = nullptr; } /* ------------------------------------------------------------------------------------ */ /* Super eagle video plugin ----------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ /* 2X SAI Filter */ static Uint32 colorMask = 0xF7DEF7DE; static Uint32 lowPixelMask = 0x08210821; static Uint32 qcolorMask = 0xE79CE79C; static Uint32 qlowpixelMask = 0x18631863; static Uint32 redblueMask = 0xF81F; static Uint32 greenMask = 0x7E0; __inline__ int GetResult1 (Uint32 A, Uint32 B, Uint32 C, Uint32 D) { int x = 0; int y = 0; int r = 0; if (A == C) x += 1; else if (B == C) y += 1; if (A == D) x += 1; else if (B == D) y += 1; if (x <= 1) r += 1; if (y <= 1) r -= 1; return r; } __inline__ int GetResult2 (Uint32 A, Uint32 B, Uint32 C, Uint32 D) { int x = 0; int y = 0; int r = 0; if (A == C) x += 1; else if (B == C) y += 1; if (A == D) x += 1; else if (B == D) y += 1; if (x <= 1) r -= 1; if (y <= 1) r += 1; return r; } __inline__ int GetResult (Uint32 A, Uint32 B, Uint32 C, Uint32 D) { int x = 0; int y = 0; int r = 0; if (A == C) x += 1; else if (B == C) y += 1; if (A == D) x += 1; else if (B == D) y += 1; if (x <= 1) r += 1; if (y <= 1) r -= 1; return r; } __inline__ Uint32 INTERPOLATE (Uint32 A, Uint32 B) { if (A != B) { return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask)); } return A; } __inline__ Uint32 Q_INTERPOLATE (Uint32 A, Uint32 B, Uint32 C, Uint32 D) { Uint32 x = ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2); Uint32 y = (A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask); y = (y >> 2) & qlowpixelMask; return x + y; } void filter_supereagle(Uint8 *srcPtr, Uint32 srcPitch, /* Uint8 *deltaPtr, */ Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { Uint8 *dP; Uint16 *bP; Uint32 inc_bP; Uint32 finish; Uint32 Nextline = srcPitch >> 1; inc_bP = 1; for (; height ; height--) { bP = reinterpret_cast<Uint16 *>(srcPtr); dP = dstPtr; for (finish = width; finish; finish -= inc_bP) { Uint32 color4, color5, color6; Uint32 color1, color2, color3; Uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; Uint32 product1a, product1b, product2a, product2b; colorB1 = *(bP - Nextline); colorB2 = *(bP - Nextline + 1); color4 = *(bP - 1); color5 = *(bP); color6 = *(bP + 1); colorS2 = *(bP + 2); color1 = *(bP + Nextline - 1); color2 = *(bP + Nextline); color3 = *(bP + Nextline + 1); colorS1 = *(bP + Nextline + 2); colorA1 = *(bP + Nextline + Nextline); colorA2 = *(bP + Nextline + Nextline + 1); // -------------------------------------- if (color2 == color6 && color5 != color3) { product1b = product2a = color2; if ((color1 == color2) || (color6 == colorB2)) { product1a = INTERPOLATE (color2, color5); product1a = INTERPOLATE (color2, product1a); // product1a = color2; } else { product1a = INTERPOLATE (color5, color6); } if ((color6 == colorS2) || (color2 == colorA1)) { product2b = INTERPOLATE (color2, color3); product2b = INTERPOLATE (color2, product2b); // product2b = color2; } else { product2b = INTERPOLATE (color2, color3); } } else if (color5 == color3 && color2 != color6) { product2b = product1a = color5; if ((colorB1 == color5) || (color3 == colorS1)) { product1b = INTERPOLATE (color5, color6); product1b = INTERPOLATE (color5, product1b); // product1b = color5; } else { product1b = INTERPOLATE (color5, color6); } if ((color3 == colorA2) || (color4 == color5)) { product2a = INTERPOLATE (color5, color2); product2a = INTERPOLATE (color5, product2a); // product2a = color5; } else { product2a = INTERPOLATE (color2, color3); } } else if (color5 == color3 && color2 == color6) { int r = 0; r += GetResult (color6, color5, color1, colorA1); r += GetResult (color6, color5, color4, colorB1); r += GetResult (color6, color5, colorA2, colorS1); r += GetResult (color6, color5, colorB2, colorS2); if (r > 0) { product1b = product2a = color2; product1a = product2b = INTERPOLATE (color5, color6); } else if (r < 0) { product2b = product1a = color5; product1b = product2a = INTERPOLATE (color5, color6); } else { product2b = product1a = color5; product1b = product2a = color2; } } else { product2b = product1a = INTERPOLATE (color2, color6); product2b = Q_INTERPOLATE (color3, color3, color3, product2b); product1a = Q_INTERPOLATE (color5, color5, color5, product1a); product2a = product1b = INTERPOLATE (color5, color3); product2a = Q_INTERPOLATE (color2, color2, color2, product2a); product1b = Q_INTERPOLATE (color6, color6, color6, product1b); // product1a = color5; // product1b = color6; // product2a = color2; // product2b = color3; } #if SDL_BYTEORDER == SDL_LIL_ENDIAN product1a = product1a | (product1b << 16); product2a = product2a | (product2b << 16); #else product1a = (product1a << 16) | product1b; product2a = (product2a << 16) | product2b; #endif *(reinterpret_cast<Uint32 *>(dP)) = product1a; *(reinterpret_cast<Uint32 *>(dP + dstPitch)) = product2a; bP += inc_bP; dP += sizeof (Uint32); } // end of for ( finish= width etc..) srcPtr += srcPitch; dstPtr += dstPitch * 2; } // endof: for (height; height; height--) } void seagle_flip(video_plugin* t) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_supereagle(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* Scale2x video plugin --------------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ void filter_scale2x(Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(short); short *p = reinterpret_cast<short *>(srcPtr); unsigned int nextlineDst = dstPitch / sizeof(short); short *q = reinterpret_cast<short *>(dstPtr); while(height--) { int i = 0, j = 0; for(i = 0; i < width; ++i, j += 2) { short B = *(p + i - nextlineSrc); short D = *(p + i - 1); short E = *(p + i); short F = *(p + i + 1); short H = *(p + i + nextlineSrc); *(q + j) = D == B && B != F && D != H ? D : E; *(q + j + 1) = B == F && B != D && F != H ? F : E; *(q + j + nextlineDst) = D == H && D != B && H != F ? D : E; *(q + j + nextlineDst + 1) = H == F && D != H && B != F ? F : E; } p += nextlineSrc; q += nextlineDst << 1; } } void scale2x_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_scale2x(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* ascale2x video plugin --------------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ void filter_ascale2x (Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { Uint8 *dP; Uint16 *bP; Uint32 inc_bP; Uint32 finish; Uint32 Nextline = srcPitch >> 1; inc_bP = 1; for (; height; height--) { bP = reinterpret_cast<Uint16 *>(srcPtr); dP = dstPtr; for (finish = width; finish; finish -= inc_bP) { Uint32 colorA, colorB; Uint32 colorC, colorD, colorE, colorF, colorG, colorH, colorI, colorJ, colorK, colorL, colorM, colorN, colorO; Uint32 product, product1, product2; //--------------------------------------- // Map of the pixels: I|E F|J // G|A B|K // H|C D|L // M|N O|P colorI = *(bP - Nextline - 1); colorE = *(bP - Nextline); colorF = *(bP - Nextline + 1); colorJ = *(bP - Nextline + 2); colorG = *(bP - 1); colorA = *(bP); colorB = *(bP + 1); colorK = *(bP + 2); colorH = *(bP + Nextline - 1); colorC = *(bP + Nextline); colorD = *(bP + Nextline + 1); colorL = *(bP + Nextline + 2); colorM = *(bP + Nextline + Nextline - 1); colorN = *(bP + Nextline + Nextline); colorO = *(bP + Nextline + Nextline + 1); if ((colorA == colorD) && (colorB != colorC)) { if (((colorA == colorE) && (colorB == colorL)) || ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))) { product = colorA; } else { product = INTERPOLATE (colorA, colorB); } if (((colorA == colorG) && (colorC == colorO)) || ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))) { product1 = colorA; } else { product1 = INTERPOLATE (colorA, colorC); } product2 = colorA; } else if ((colorB == colorC) && (colorA != colorD)) { if (((colorB == colorF) && (colorA == colorH)) || ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))) { product = colorB; } else { product = INTERPOLATE (colorA, colorB); } if (((colorC == colorH) && (colorA == colorF)) || ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))) { product1 = colorC; } else { product1 = INTERPOLATE (colorA, colorC); } product2 = colorB; } else if ((colorA == colorD) && (colorB == colorC)) { if (colorA == colorB) { product = colorA; product1 = colorA; product2 = colorA; } else { int r = 0; product1 = INTERPOLATE (colorA, colorC); product = INTERPOLATE (colorA, colorB); r += GetResult1 (colorA, colorB, colorG, colorE); r += GetResult2 (colorB, colorA, colorK, colorF); r += GetResult2 (colorB, colorA, colorH, colorN); r += GetResult1 (colorA, colorB, colorL, colorO); if (r > 0) product2 = colorA; else if (r < 0) product2 = colorB; else { product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD); } } } else { product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD); if ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) { product = colorA; } else if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) { product = colorB; } else { product = INTERPOLATE (colorA, colorB); } if ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) { product1 = colorA; } else if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) { product1 = colorC; } else { product1 = INTERPOLATE (colorA, colorC); } } #if SDL_BYTEORDER == SDL_LIL_ENDIAN product = colorA | (product << 16); product1 = product1 | (product2 << 16); #else product = (colorA << 16) | product; product1 = (product1 << 16) | product2; #endif *(reinterpret_cast<Uint32 *>(dP)) = product; *(reinterpret_cast<Uint32 *>(dP + dstPitch)) = product1; bP += inc_bP; dP += sizeof (Uint32); } // end of for ( finish= width etc..) srcPtr += srcPitch; dstPtr += dstPitch * 2; } // endof: for (height; height; height--) } void ascale2x_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_ascale2x(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* tv2x video plugin ------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */ void filter_tv2x(Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(Uint16); Uint16 *p = reinterpret_cast<Uint16 *>(srcPtr); unsigned int nextlineDst = dstPitch / sizeof(Uint16); Uint16 *q = reinterpret_cast<Uint16 *>(dstPtr); while(height--) { int i = 0, j = 0; for(; i < width; ++i, j += 2) { Uint16 p1 = *(p + i); Uint32 pi; pi = (((p1 & redblueMask) * 7) >> 3) & redblueMask; pi |= (((p1 & greenMask) * 7) >> 3) & greenMask; *(q + j) = p1; *(q + j + 1) = p1; *(q + j + nextlineDst) = pi; *(q + j + nextlineDst + 1) = pi; } p += nextlineSrc; q += nextlineDst << 1; } } void tv2x_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_tv2x(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* Software bilinear video plugin ----------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ void filter_bilinear(Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(Uint16); Uint16 *p = reinterpret_cast<Uint16 *>(srcPtr); unsigned int nextlineDst = dstPitch / sizeof(Uint16); Uint16 *q = reinterpret_cast<Uint16 *>(dstPtr); while(height--) { int i, ii; for(i = 0, ii = 0; i < width; ++i, ii += 2) { Uint16 A = *(p + i); Uint16 B = *(p + i + 1); Uint16 C = *(p + i + nextlineSrc); Uint16 D = *(p + i + nextlineSrc + 1); *(q + ii) = A; *(q + ii + 1) = INTERPOLATE(A, B); *(q + ii + nextlineDst) = INTERPOLATE(A, C); *(q + ii + nextlineDst + 1) = Q_INTERPOLATE(A, B, C, D); } p += nextlineSrc; q += nextlineDst << 1; } } void swbilin_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_bilinear(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* Software bicubic video plugin ------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */ #define BLUE_MASK565 0x001F001F #define RED_MASK565 0xF800F800 #define GREEN_MASK565 0x07E007E0 #define BLUE_MASK555 0x001F001F #define RED_MASK555 0x7C007C00 #define GREEN_MASK555 0x03E003E0 __inline__ static void MULT(Uint16 c, float* r, float* g, float* b, float alpha) { *r += alpha * ((c & RED_MASK565 ) >> 11); *g += alpha * ((c & GREEN_MASK565) >> 5); *b += alpha * ((c & BLUE_MASK565 ) >> 0); } __inline__ static Uint16 MAKE_RGB565(float r, float g, float b) { return (((static_cast<Uint8>(r)) << 11) & RED_MASK565 ) | (((static_cast<Uint8>(g)) << 5) & GREEN_MASK565) | (((static_cast<Uint8>(b)) << 0) & BLUE_MASK565 ); } __inline__ float CUBIC_WEIGHT(float x) { // P(x) = { x, x>0 | 0, x<=0 } // P(x + 2) ^ 3 - 4 * P(x + 1) ^ 3 + 6 * P(x) ^ 3 - 4 * P(x - 1) ^ 3 double r = 0.; if(x + 2 > 0) r += pow(x + 2, 3); if(x + 1 > 0) r += -4 * pow(x + 1, 3); if(x > 0) r += 6 * pow(x , 3); if(x - 1 > 0) r += -4 * pow(x - 1, 3); return static_cast<float>(r) / 6; } void filter_bicubic(Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(Uint16); Uint16 *p = reinterpret_cast<Uint16 *>(srcPtr); unsigned int nextlineDst = dstPitch / sizeof(Uint16); Uint16 *q = reinterpret_cast<Uint16 *>(dstPtr); int dx = width << 1, dy = height << 1; float fsx = static_cast<float>(width) / dx; float fsy = static_cast<float>(height) / dy; float v = 0.0f; int j = 0; for(; j < dy; ++j) { float u = 0.0f; int iv = static_cast<int>(v); float decy = v - iv; int i = 0; for(; i < dx; ++i) { int iu = static_cast<int>(u); float decx = u - iu; float r, g, b; int m; r = g = b = 0.; for(m = -1; m <= 2; ++m) { float r1 = CUBIC_WEIGHT(decy - m); int n; for(n = -1; n <= 2; ++n) { float r2 = CUBIC_WEIGHT(n - decx); Uint16* pIn = p + (iu + n) + (iv + m) * static_cast<int>(nextlineSrc); MULT(*pIn, &r, &g, &b, r1 * r2); } } *(q + i) = MAKE_RGB565(r, g, b); u += fsx; } q += nextlineDst; v += fsy; } } void swbicub_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_bicubic(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* Dot matrix video plugin ------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */ static Uint16 DOT_16(Uint16 c, int j, int i) { static constexpr Uint16 dotmatrix[16] = { 0x01E0, 0x0007, 0x3800, 0x0000, 0x39E7, 0x0000, 0x39E7, 0x0000, 0x3800, 0x0000, 0x01E0, 0x0007, 0x39E7, 0x0000, 0x39E7, 0x0000 }; return c - ((c >> 2) & *(dotmatrix + ((j & 3) << 2) + (i & 3))); } void filter_dotmatrix(Uint8 *srcPtr, Uint32 srcPitch, Uint8 *dstPtr, Uint32 dstPitch, int width, int height) { unsigned int nextlineSrc = srcPitch / sizeof(Uint16); Uint16 *p = reinterpret_cast<Uint16 *>(srcPtr); unsigned int nextlineDst = dstPitch / sizeof(Uint16); Uint16 *q = reinterpret_cast<Uint16 *>(dstPtr); int i, ii, j, jj; for(j = 0, jj = 0; j < height; ++j, jj += 2) { for(i = 0, ii = 0; i < width; ++i, ii += 2) { Uint16 c = *(p + i); *(q + ii) = DOT_16(c, jj, ii); *(q + ii + 1) = DOT_16(c, jj, ii + 1); *(q + ii + nextlineDst) = DOT_16(c, jj + 1, ii); *(q + ii + nextlineDst + 1) = DOT_16(c, jj + 1, ii + 1); } p += nextlineSrc; q += nextlineDst << 1; } } void dotmat_flip(video_plugin* t __attribute__((unused))) { if (SDL_MUSTLOCK(scaled)) SDL_LockSurface(scaled); SDL_Rect src; SDL_Rect dst; compute_rects(&src,&dst,t->half_pixels); filter_dotmatrix(static_cast<Uint8*>(pub->pixels) + (2*src.x+src.y*pub->pitch) + (pub->pitch), pub->pitch, static_cast<Uint8*>(scaled->pixels) + (2*dst.x+dst.y*scaled->pitch), scaled->pitch, src.w, src.h); if (SDL_MUSTLOCK(scaled)) SDL_UnlockSurface(scaled); swscale_blit(t); } /* ------------------------------------------------------------------------------------ */ /* End of video plugins --------------------------------------------------------------- */ /* ------------------------------------------------------------------------------------ */ std::vector<video_plugin> video_plugin_list = { // Hardware flip version are the same as software ones since switch to SDL2. Kept for compatibility of config, would be nice to not display them in the UI. /* Name Hidden Init func Palette func Flip func Close func Half size X, Y offsets X, Y scale width, height */ {"Direct", false, direct_init, direct_setpal, direct_flip, direct_close, 1, 0, 0, 0, 0, 0, 0 }, {"Direct double", true, direct_init, direct_setpal, direct_flip, direct_close, 0, 0, 0, 0, 0, 0, 0 }, {"Half size", true, direct_init, direct_setpal, direct_flip, direct_close, 1, 0, 0, 0, 0, 0, 0 }, {"Double size", true, direct_init, direct_setpal, direct_flip, direct_close, 0, 0, 0, 0, 0, 0, 0 }, {"Super eagle", false, swscale_init, swscale_setpal, seagle_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"Scale2x", false, swscale_init, swscale_setpal, scale2x_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"Advanced Scale2x", false, swscale_init, swscale_setpal, ascale2x_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"TV 2x", false, swscale_init, swscale_setpal, tv2x_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"Software bilinear", false, swscale_init, swscale_setpal, swbilin_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"Software bicubic", false, swscale_init, swscale_setpal, swbicub_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, {"Dot matrix", false, swscale_init, swscale_setpal, dotmat_flip, swscale_close, 1, 0, 0, 0, 0, 0, 0 }, #ifdef HAVE_GL {"OpenGL scaling", false, glscale_init, glscale_setpal, glscale_flip, glscale_close, 0, 0, 0, 0, 0, 0, 0 }, #endif };
43,861
C++
.cpp
1,250
30.14
169
0.56318
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,794
zip.cpp
ColinPitrat_caprice32/src/zip.cpp
#include "zip.h" #include <cstring> #include <strings.h> #include <zlib.h> #include <errno.h> #include <cstdio> #include <string> #include "errors.h" #include "log.h" #include "memutils.h" // TODO(cpitrat): refactoring namespace zip { int dir (t_zip_info *zi) { FILE *pfileObject; byte pbGPBuffer[32768]; int n; long lFilePosition = 0; dword dwCentralDirPosition, dwNextEntry; word wCentralDirEntries, wCentralDirSize, wFilenameLength; byte *pbPtr; dword dwOffset; if ((pfileObject = fopen(zi->filename.c_str(), "rb")) == nullptr) { LOG_ERROR("File not found or not readable: " << zi->filename); return ERR_FILE_NOT_FOUND; } wCentralDirEntries = 0; wCentralDirSize = 0; dwCentralDirPosition = 0; auto closure = [&]() { fclose(pfileObject); }; memutils::scope_exit<decltype(closure)> cs(closure); do { lFilePosition -= 256; // move backwards through ZIP file if (fseek(pfileObject, lFilePosition, SEEK_END) != 0) { LOG_ERROR("Couldn't read zip file: " << zi->filename); return ERR_FILE_BAD_ZIP; // exit if loading of data chunck failed }; if (fread(pbGPBuffer, 256, 1, pfileObject) == 0) { LOG_ERROR("Couldn't read zip file: " << zi->filename); return ERR_FILE_BAD_ZIP; // exit if loading of data chunck failed } pbPtr = pbGPBuffer + (256 - 22); // pointer to end of central directory (under ideal conditions) while (pbPtr != static_cast<byte *>(pbGPBuffer)) { if (*reinterpret_cast<dword *>(pbPtr) == 0x06054b50) { // check for end of central directory signature wCentralDirEntries = *reinterpret_cast<word *>(pbPtr + 10); wCentralDirSize = *reinterpret_cast<word *>(pbPtr + 12); dwCentralDirPosition = *reinterpret_cast<dword *>(pbPtr + 16); break; } pbPtr--; // move backwards through buffer } } while (wCentralDirEntries == 0); if (wCentralDirSize == 0) { LOG_ERROR("Couldn't read zip file (no central directory): " << zi->filename); return ERR_FILE_BAD_ZIP; // exit if no central directory was found } if (fseek(pfileObject, dwCentralDirPosition, SEEK_SET) != 0) { LOG_ERROR("Couldn't read zip file: " << zi->filename); return ERR_FILE_BAD_ZIP; // exit if seeking to the central directory failed }; if (fread(pbGPBuffer, wCentralDirSize, 1, pfileObject) == 0) { LOG_ERROR("Couldn't read zip file: " << zi->filename); return ERR_FILE_BAD_ZIP; // exit if reading the central directory failed } pbPtr = pbGPBuffer; for (n = wCentralDirEntries; n; n--) { wFilenameLength = *reinterpret_cast<word *>(pbPtr + 28); dwOffset = *reinterpret_cast<dword *>(pbPtr + 42); dwNextEntry = wFilenameLength + *reinterpret_cast<word *>(pbPtr + 30) + *reinterpret_cast<word *>(pbPtr + 32); pbPtr += 46; const char *pchThisExtension = zi->extensions.c_str(); while (*pchThisExtension != '\0') { // loop for all extensions to be checked if (strncasecmp(reinterpret_cast<char*>(pbPtr) + (wFilenameLength - 4), pchThisExtension, 4) == 0) { std::string filename(reinterpret_cast<char*>(pbPtr), wFilenameLength); zi->filesOffsets.emplace_back(filename, dwOffset); zi->dwOffset = dwOffset; break; } pchThisExtension += 4; // advance to next extension } pbPtr += dwNextEntry; } if (zi->filesOffsets.empty()) { // no files found? LOG_ERROR("Empty zip file: " << zi->filename); return ERR_FILE_EMPTY_ZIP; } return 0; // operation completed successfully } int extract(const t_zip_info& zi, FILE **pfileOut) { int iStatus; unsigned int iCount; byte pbGPBuffer[32768]; dword dwSize; byte *pbInputBuffer, *pbOutputBuffer; FILE *pfileIn; z_stream z; dword dwOffset = zi.dwOffset; #ifdef WINDOWS // Windows version of tmpfile is broken by design as it tries to create the temporary file in the root directory. // The "official" recommendation is to use the yet borken tempnam/fopen combination. // https://msdn.microsoft.com/en-us/library/x8x7sakw.aspx char *tmpFilePath = tempnam(".", "cap32_tmp_"); if (tmpFilePath == nullptr) { LOG_ERROR("Couldn't unzip file: Couldn't generate temporary file name: " << strerror(errno)); return ERR_FILE_UNZIP_FAILED; // couldn't create output file } LOG_DEBUG("Using temporary file: " << tmpFilePath); *pfileOut = fopen(tmpFilePath, "w+b"); #else *pfileOut = tmpfile(); #endif if (*pfileOut == nullptr) { LOG_ERROR("Couldn't unzip file: Couldn't create temporary file: " << strerror(errno)); return ERR_FILE_UNZIP_FAILED; // couldn't create output file } pfileIn = fopen(zi.filename.c_str(), "rb"); // open ZIP file for reading if (pfileIn == nullptr) { LOG_ERROR("Couldn't open zip file for reading: " << zi.filename); fclose(*pfileOut); return ERR_FILE_UNZIP_FAILED; // couldn't open input file } auto closure = [&]() { fclose(pfileIn); }; memutils::scope_exit<decltype(closure)> cs(closure); if (fseek(pfileIn, dwOffset, SEEK_SET) != 0) { // move file pointer to beginning of data block LOG_ERROR("Couldn't read zip file: " << zi.filename); fclose(*pfileOut); return ERR_FILE_UNZIP_FAILED; }; size_t rc; if((rc = fread(pbGPBuffer, 30, 1, pfileIn)) != 1) { // read local header LOG_ERROR("Couldn't read zip file: " << zi.filename); fclose(*pfileOut); return ERR_FILE_UNZIP_FAILED; } dwSize = *reinterpret_cast<dword *>(pbGPBuffer + 18); // length of compressed data dwOffset += 30 + *reinterpret_cast<word *>(pbGPBuffer + 26) + *reinterpret_cast<word *>(pbGPBuffer + 28); if (fseek(pfileIn, dwOffset, SEEK_SET) != 0) { // move file pointer to start of compressed data LOG_ERROR("Couldn't read zip file: " << zi.filename); fclose(*pfileOut); return ERR_FILE_UNZIP_FAILED; } pbInputBuffer = pbGPBuffer; // space for compressed data chunck pbOutputBuffer = pbInputBuffer + 16384; // space for uncompressed data chunck z.zalloc = nullptr; z.zfree = nullptr; z.opaque = nullptr; iStatus = inflateInit2(&z, -MAX_WBITS); // init zlib stream (no header) do { z.next_in = pbInputBuffer; if (dwSize > 16384) { // limit input size to max 16K or remaining bytes z.avail_in = 16384; } else { z.avail_in = dwSize; } z.avail_in = fread(pbInputBuffer, 1, z.avail_in, pfileIn); // load compressed data chunck from ZIP file while ((z.avail_in) && (iStatus == Z_OK)) { // loop until all data has been processed z.next_out = pbOutputBuffer; z.avail_out = 16384; iStatus = inflate(&z, Z_NO_FLUSH); // decompress data iCount = 16384 - z.avail_out; if (iCount) { // save data to file if some is available if (fwrite(pbOutputBuffer, iCount, 1, *pfileOut) != 1) { LOG_ERROR("Couldn't unzip file: Couldn't write to output file:"); fclose(*pfileOut); return ERR_FILE_UNZIP_FAILED; } } } dwSize -= 16384; // advance to next chunck } while ((dwSize > 0) && (iStatus == Z_OK)) ; // loop until done if (iStatus != Z_STREAM_END) { LOG_ERROR("Couldn't unzip file: " << zi.filename << " (" << iStatus << ")"); return ERR_FILE_UNZIP_FAILED; // abort on error } iStatus = inflateEnd(&z); // clean up fseek(*pfileOut, 0, SEEK_SET); return 0; // data was successfully decompressed } }
7,675
C++
.cpp
181
36.342541
117
0.638466
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,795
fdc.cpp
ColinPitrat_caprice32/src/fdc.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Nec uPD765A Floppy Disk Controller emulation (c) Copyright 1997-2003 Ulrich Doewich */ #include "cap32.h" #include "disk.h" #include "z80.h" extern t_CPC CPC; extern t_FDC FDC; extern t_z80regs z80; extern byte *pbGPBuffer; #ifdef DEBUG_FDC extern FILE *pfoDebug; dword dwBytesTransferred = 0; #endif #define CMD_CODE 0 #define CMD_UNIT 1 #define CMD_C 2 #define CMD_H 3 #define CMD_R 4 #define CMD_N 5 #define CMD_EOT 6 #define CMD_GPL 7 #define CMD_DTL 8 #define CMD_STP 8 #define RES_ST0 0 #define RES_ST1 1 #define RES_ST2 2 #define RES_C 3 #define RES_H 4 #define RES_R 5 #define RES_N 6 #define OVERRUN_TIMEOUT (128*4) #define INITIAL_TIMEOUT (OVERRUN_TIMEOUT*4) void fdc_specify(); void fdc_drvstat(); void fdc_recalib(); void fdc_intstat(); void fdc_seek(); void fdc_readtrk(); void fdc_write(); void fdc_read(); void fdc_readID(); void fdc_writeID(); void fdc_scan(); void fdc_scanlo(); void fdc_scanhi(); typedef struct fdc_cmd_table_def { int cmd; int cmd_length; int res_length; int cmd_direction; void (*cmd_handler)(); } fdc_cmd_table_def; #define MAX_CMD_COUNT 15 fdc_cmd_table_def fdc_cmd_table[MAX_CMD_COUNT] = { /* syntax is: command code, number of bytes for command, number of bytes for result, direction, pointer to command handler */ {0x03, 3, 0, FDC_TO_CPU, fdc_specify}, // specify {0x04, 2, 1, FDC_TO_CPU, fdc_drvstat}, // sense device status {0x07, 2, 0, FDC_TO_CPU, fdc_recalib}, // recalibrate {0x08, 1, 2, FDC_TO_CPU, fdc_intstat}, // sense interrupt status {0x0f, 3, 0, FDC_TO_CPU, fdc_seek}, // seek {0x42, 9, 7, FDC_TO_CPU, fdc_readtrk}, // read diagnostic {0x45, 9, 7, CPU_TO_FDC, fdc_write}, // write data {0x46, 9, 7, FDC_TO_CPU, fdc_read}, // read data {0x49, 9, 7, CPU_TO_FDC, fdc_write}, // write deleted data {0x4a, 2, 7, FDC_TO_CPU, fdc_readID}, // read id {0x4c, 9, 7, FDC_TO_CPU, fdc_read}, // read deleted data {0x4d, 6, 7, CPU_TO_FDC, fdc_writeID}, // write id {0x51, 9, 7, CPU_TO_FDC, fdc_scan}, // scan equal {0x59, 9, 7, CPU_TO_FDC, fdc_scan}, // scan low or equal {0x5d, 9, 7, CPU_TO_FDC, fdc_scan}, // scan high or equal }; extern t_drive driveA; extern t_drive driveB; t_drive *active_drive; // reference to the currently selected drive t_track *active_track; // reference to the currently selected track, of the active_drive dword read_status_delay = 0; #define LOAD_RESULT_WITH_STATUS \ FDC.result[RES_ST0] |= 0x40; /* AT */ \ FDC.result[RES_ST1] |= 0x80; /* End of Cylinder */ \ if (FDC.command[CMD_CODE] != 0x42) { /* continue only if not a read track command */ \ if ((FDC.result[RES_ST1] & 0x7f) || (FDC.result[RES_ST2] & 0x7f)) { /* any 'error bits' set? */ \ FDC.result[RES_ST1] &= 0x7f; /* mask out End of Cylinder */ \ if ((FDC.result[RES_ST1] & 0x20) || (FDC.result[RES_ST2] & 0x20)) { /* DE and/or DD? */ \ FDC.result[RES_ST2] &= 0xbf; /* mask out Control Mark */ \ } \ else if (FDC.result[RES_ST2] & 0x40) { /* Control Mark? */ \ FDC.result[RES_ST0] &= 0x3f; /* mask out AT */ \ FDC.result[RES_ST1] &= 0x7f; /* mask out End of Cylinder */ \ } \ } \ } #define LOAD_RESULT_WITH_CHRN \ FDC.result[RES_C] = FDC.command[CMD_C]; /* load result with current CHRN values */ \ FDC.result[RES_H] = FDC.command[CMD_H]; \ FDC.result[RES_R] = FDC.command[CMD_R]; \ FDC.result[RES_N] = FDC.command[CMD_N]; void check_unit() { switch (FDC.command[CMD_UNIT] & 1) // check unit selection bits of active command { case 0: // target for command is drive A active_drive = &driveA; break; case 1: // target for command is drive B active_drive = &driveB; break; } } int init_status_regs() { byte val; memset(&FDC.result, 0, sizeof(FDC.result)); // clear result codes buffer val = FDC.command[CMD_UNIT] & 7; // keep head and unit of command if ((active_drive->tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x48; // Abnormal Termination + Not Ready } FDC.result[RES_ST0] = val; // write ST0 to result codes buffer return (val & 8); // return value indicates whether drive is ready (0) or not (8) } t_sector *find_sector(byte *requested_CHRN) { int loop_count; dword idx; t_sector *sector; sector = nullptr; // return value indicates 'sector not found' by default loop_count = 0; // detection of index hole counter idx = active_drive->current_sector; // get the active sector index do { if (!(memcmp(&active_track->sector[idx].CHRN, requested_CHRN, 4))) { // sector matches requested ID? sector = &active_track->sector[idx]; // return value points to sector information if ((sector->flags[0] & 0x20) || (sector->flags[1] & 0x20)) { // any Data Errors? if (active_drive->random_DEs) { // simulate 'random' DEs? FDC.flags |= RNDDE_flag; } } FDC.result[RES_ST2] &= ~(0x02 | 0x10); // remove possible Bad Cylinder + No Cylinder flags break; } byte cylinder = active_track->sector[idx].CHRN[0]; // extract C if (cylinder == 0xff) { FDC.result[RES_ST2] |= 0x02; // Bad Cylinder } else if (cylinder != FDC.command[CMD_C]) { // does not match requested C? FDC.result[RES_ST2] |= 0x10; // No Cylinder } idx++; // increase sector table index if (idx >= active_track->sectors) { // index beyond number of sectors for this track? idx = 0; // reset index loop_count++; // increase 'index hole' count } } while (loop_count < 2); // loop until sector is found, or index hole has passed twice if (FDC.result[RES_ST2] & 0x02) { // Bad Cylinder set? FDC.result[RES_ST2] &= ~0x10; // remove possible No Cylinder flag } if (loop_count && active_drive->track_hook) // track looped and hook available? active_drive->track_hook(active_drive); // update flakey data active_drive->current_sector = idx; // update sector table index for active drive return sector; } inline void cmd_write() { t_sector *sector; sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found int sector_size; sector->flags[0] = 0; // clear ST1 for this sector if (FDC.command[CMD_CODE] == 0x45) { // write data command? sector->flags[1] = 0; // clear ST2 } else { // write deleted data sector->flags[1] = 0x40; // set Control Mark } if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer // Note: do not handle writing to weak sectors (would need to write to all of them ?) FDC.buffer_ptr = sector->getDataForWrite(); // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } inline void cmd_read() { t_sector *sector; loop: sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found FDC.result[RES_ST1] = sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] = sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if (FDC.command[CMD_CODE] == 0x4c) { // read deleted data command? FDC.result[RES_ST2] ^= 0x40; // invert Control Mark } if ((FDC.flags & SKIP_flag) && (FDC.result[RES_ST2] &= 0x40)) { // skip sector? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // continue looking? FDC.command[CMD_R]++; // advance to next sector goto loop; } else { // no data to transfer -> no execution phase LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // sector data is to be transferred int sector_size; if (FDC.result[RES_ST2] &= 0x40) { // does the sector have an AM opposite of what we want? FDC.command[CMD_EOT] = FDC.command[CMD_R]; // execution ends on this sector } if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->getDataForRead(); // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } inline void cmd_readtrk() { int sector_size; t_sector *sector; sector = &active_track->sector[active_drive->current_sector]; if (memcmp(&sector->CHRN, &FDC.command[CMD_C], 4)) { // sector does not match requested ID? FDC.result[RES_ST1] |= 0x04; // No Data } FDC.result[RES_ST2] &= 0xbf; // clear Control Mark, if it was set FDC.result[RES_ST1] |= sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] |= sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if (FDC.command[CMD_N] == 0) { // use DTL for length? sector_size = FDC.command[CMD_DTL]; // size of sector is defined by DTL value if (sector_size > 0x80) { sector_size = 0x80; // max DTL value is 128 } } else { sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value } FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->getDataForRead(); // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } inline void cmd_scan() { t_sector *sector; loop: sector = find_sector(&FDC.command[CMD_C]); // locate the requested sector on the current track if (sector) { // sector found FDC.result[RES_ST1] = sector->flags[0] & 0x25; // copy ST1 to result, ignoring unused bits FDC.result[RES_ST2] = sector->flags[1] & 0x61; // copy ST2 to result, ignoring unused bits if ((FDC.flags & SKIP_flag) && (FDC.result[RES_ST2] &= 0x40)) { // skip sector? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // continue looking? FDC.command[CMD_R] += FDC.command[CMD_STP]; // advance to next sector goto loop; } else { // no data to transfer -> no execution phase LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // sector data is to be transferred int sector_size; if (FDC.result[RES_ST2] &= 0x40) { // does the sector have an AM opposite of what we want? FDC.command[CMD_EOT] = FDC.command[CMD_R]; // execution ends on this sector } sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value FDC.buffer_count = sector_size; // init number of bytes to transfer FDC.buffer_ptr = sector->getDataForRead(); // pointer to sector data FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data FDC.flags &= ~SCANFAILED_flag; // reset scan failed flag FDC.result[RES_ST2] |= 0x08; // assume data matches: set Scan Equal Hit FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // sector not found FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x04; // No Data LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_write_data(byte val) { int idx; #ifdef DEBUG_FDC if (FDC.phase == CMD_PHASE) { if (FDC.byte_count) { fprintf(pfoDebug, "%02x ", val); } else { fprintf(pfoDebug, "\n%02x: ", val); } } #endif switch (FDC.phase) { case CMD_PHASE: // in command phase? if (FDC.byte_count) { // receiving command parameters? FDC.command[FDC.byte_count++] = val; // copy to buffer if (FDC.byte_count == FDC.cmd_length) { // received all command bytes? FDC.byte_count = 0; // clear byte counter FDC.phase = EXEC_PHASE; // switch to execution phase FDC.cmd_handler(); } } else { // first command byte received if (val & 0x20) { // skip DAM or DDAM? FDC.flags |= SKIP_flag; // DAM/DDAM will be skipped val &= ~0x20; // reset skip bit in command byte } else { FDC.flags &= ~SKIP_flag; // make sure skip inidicator is off } for (idx = 0; idx < MAX_CMD_COUNT; idx++) { // loop through all known FDC commands if (fdc_cmd_table[idx].cmd == val) { // do we have a match? break; } } if (idx != MAX_CMD_COUNT) { // valid command received FDC.cmd_length = fdc_cmd_table[idx].cmd_length; // command length in bytes FDC.res_length = fdc_cmd_table[idx].res_length; // result length in bytes FDC.cmd_direction = fdc_cmd_table[idx].cmd_direction; // direction is CPU to FDC, or FDC to CPU FDC.cmd_handler = fdc_cmd_table[idx].cmd_handler; // pointer to command handler FDC.command[FDC.byte_count++] = val; // copy command code to buffer if (FDC.byte_count == FDC.cmd_length) { // already received all command bytes? FDC.byte_count = 0; // clear byte counter FDC.phase = EXEC_PHASE; // switch to execution phase FDC.cmd_handler(); } } else { // unknown command received FDC.result[0] = 0x80; // indicate invalid command FDC.res_length = 1; FDC.phase = RESULT_PHASE; // switch to result phase } } break; case EXEC_PHASE: // in execution phase? if (FDC.cmd_direction == CPU_TO_FDC) { // proper direction? FDC.timeout = OVERRUN_TIMEOUT; if ((FDC.flags & SCAN_flag)) { // processing any of the scan commands? if (val != 0xff) { // no comparison on CPU byte = 0xff switch((FDC.command[CMD_CODE] & 0x1f)) { case 0x51: // scan equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit FDC.flags |= SCANFAILED_flag; } break; case 0x59: // scan low or equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit } if (val > *FDC.buffer_ptr) { FDC.flags |= SCANFAILED_flag; } break; case 0x5d: // scan high or equal if (val != *FDC.buffer_ptr) { FDC.result[RES_ST2] &= 0xf7; // reset Scan Equal Hit } if (val < *FDC.buffer_ptr) { FDC.flags |= SCANFAILED_flag; } break; } } FDC.buffer_ptr++; // advance sector data pointer } else { *FDC.buffer_ptr++ = val; // write byte to sector } if (FDC.buffer_ptr > FDC.buffer_endptr) { FDC.buffer_ptr = active_track->data; // wrap around } if (--FDC.buffer_count == 0) { // processed all data? if ((FDC.flags & SCAN_flag)) { // processing any of the scan commands? if ((FDC.flags & SCANFAILED_flag) && (FDC.command[CMD_R] != FDC.command[CMD_EOT])) { FDC.command[CMD_R] += FDC.command[CMD_STP]; // advance to next sector cmd_scan(); } else { if ((FDC.flags & SCANFAILED_flag)) { FDC.result[RES_ST2] |= 0x04; // Scan Not Satisfied } LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else if (FDC.command[CMD_CODE] == 0x4d) { // write ID command? dword sector_size, track_size; byte *pbPtr, *pbDataPtr; if (active_track->sectors != 0) { // track is formatted? delete [] active_track->data; // dealloc memory for old track data } sector_size = 128 << FDC.command[CMD_C]; // determine number of bytes from N value if (((sector_size + 62 + FDC.command[CMD_R]) * FDC.command[CMD_H]) > CPC.max_tracksize) { // track size exceeds maximum? active_track->sectors = 0; // 'unformat' track } else { int sector; track_size = sector_size * FDC.command[CMD_H]; active_track->sectors = FDC.command[CMD_H]; active_track->data = new byte[track_size]; // attempt to allocate the required memory pbDataPtr = active_track->data; pbPtr = pbGPBuffer; for (sector = 0; sector < FDC.command[CMD_H]; sector++) { memcpy(active_track->sector[sector].CHRN, pbPtr, 4); // copy CHRN memset(active_track->sector[sector].flags, 0, 2); // clear ST1 & ST2 active_track->sector[sector].setData(pbDataPtr); // store pointer to sector data pbDataPtr += sector_size; pbPtr += 4; } memset(active_track->data, FDC.command[CMD_N], track_size); // fill track data with specified byte value } pbPtr = pbGPBuffer + ((FDC.command[CMD_H]-1) * 4); // pointer to the last CHRN passed to writeID memcpy(&FDC.result[RES_C], pbPtr, 4); // copy sector's CHRN to result buffer FDC.result[RES_N] = FDC.command[CMD_C]; // overwrite with the N value from the writeID command active_drive->altered = true; // indicate that the image has been modified FDC.phase = RESULT_PHASE; // switch to result phase } else if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // haven't reached End of Track? FDC.command[CMD_R]++; // advance to next sector cmd_write(); } else { active_drive->altered = true; // indicate that the image has been modified FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x80; // End of Cylinder LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } } break; } } byte fdc_read_status() { byte val; val = 0x80; // data register ready if (FDC.phase == EXEC_PHASE) { // in execution phase? if (read_status_delay) { val = 0x10; // FDC is busy read_status_delay--; } else { val |= 0x30; // FDC is executing & busy } if (FDC.cmd_direction == FDC_TO_CPU) { val |= 0x40; // FDC is sending data to the CPU } } else if (FDC.phase == RESULT_PHASE) { // in result phase? val |= 0x50; // FDC is sending data to the CPU, and is busy } else { // in command phase if (FDC.byte_count) { // receiving command parameters? val |= 0x10; // FDC is busy } } return val; } byte fdc_read_data() { byte val; val = 0xff; // default value switch (FDC.phase) { case EXEC_PHASE: // in execution phase? if (FDC.cmd_direction == FDC_TO_CPU) { // proper direction? FDC.timeout = OVERRUN_TIMEOUT; val = *FDC.buffer_ptr++; // read byte from current sector #ifdef DEBUG_FDC if (!(FDC.flags & OVERRUN_flag)) { dwBytesTransferred++; } #endif if (FDC.buffer_ptr >= FDC.buffer_endptr) { FDC.buffer_ptr = active_track->data; // wrap around } if (!(--FDC.buffer_count)) { // completed the data transfer? if (FDC.flags & RNDDE_flag) { // simulate random Data Errors? // ***! random DE handling } active_drive->current_sector++; // increase sector index if (FDC.flags & OVERRUN_flag) { // overrun condition detected? FDC.flags &= ~OVERRUN_flag; FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x10; // Overrun LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else { if (FDC.command[CMD_CODE] == 0x42) { // read track command? if ((--FDC.command[CMD_EOT])) { // continue reading sectors? if (active_drive->current_sector >= active_track->sectors) { // index beyond number of sectors for this track? active_drive->current_sector = 0; // reset index if (active_drive->track_hook) active_drive->track_hook(active_drive); // update flakey data } FDC.command[CMD_R]++; // advance to next sector cmd_readtrk(); } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // normal read (deleted) data command if (!((FDC.result[RES_ST1] & 0x31) || (FDC.result[RES_ST2] & 0x21))) { // no error bits set? if (FDC.command[CMD_R] != FDC.command[CMD_EOT]) { // haven't reached End of Track? FDC.command[CMD_R]++; // advance to next sector cmd_read(); } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { LOAD_RESULT_WITH_STATUS LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } } } } break; case RESULT_PHASE: // in result phase? val = FDC.result[FDC.byte_count++]; // copy value from buffer #ifdef DEBUG_FDC if (dwBytesTransferred) { fprintf(pfoDebug, "{%d} ", dwBytesTransferred); dwBytesTransferred = 0; } fprintf(pfoDebug, "[%02x] ", val); #endif if (FDC.byte_count == FDC.res_length) { // sent all result bytes? FDC.flags &= ~SCAN_flag; // reset scan command flag FDC.byte_count = 0; // clear byte counter FDC.phase = CMD_PHASE; // switch to command phase FDC.led = 0; // turn the drive LED off } break; } return val; } void fdc_specify() { FDC.phase = CMD_PHASE; // switch back to command phase (fdc_specify has no result phase!) } void fdc_drvstat() { byte val; check_unit(); // switch to target drive val = FDC.command[CMD_UNIT] & 7; // keep head and unit of command if ((active_drive->write_protected) || (active_drive->tracks == 0)) { // write protected, or disk missing? val |= 0x48; // set Write Protect + Two Sided (?) } if ((active_drive->tracks) && (FDC.motor)) { val |= 0x20; // set Ready } if (active_drive->current_track == 0) { // drive head is over track 0? val |= 0x10; // set Track 0 } FDC.result[RES_ST0] = val; FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_recalib() { FDC.command[CMD_C] = 0; // seek to track 0 fdc_seek(); } void fdc_intstat() { byte val; val = FDC.result[RES_ST0] & 0xf8; // clear Head Address and Unit bits if (FDC.flags & SEEKDRVA_flag) { // seek completed on drive A? val |= 0x20; // set Seek End FDC.flags &= ~(SEEKDRVA_flag | STATUSDRVA_flag); // clear seek done and status change flags FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveA.current_track; } else if (FDC.flags & SEEKDRVB_flag) { // seek completed on drive B? val |= 0x21; // set Seek End FDC.flags &= ~(SEEKDRVB_flag | STATUSDRVB_flag); // clear seek done and status change flags FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveB.current_track; } else if (FDC.flags & STATUSDRVA_flag) { // has the status of drive A changed? val = 0xc0; // status change if ((driveA.tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x08; // not ready } FDC.flags &= ~STATUSDRVA_flag; // clear status change flag FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveA.current_track; } else if (FDC.flags & STATUSDRVB_flag) { // has the status of drive B changed? val = 0xc1; // status change if ((driveB.tracks == 0) || (!FDC.motor)) { // no DSK in the drive, or drive motor is turned off? val |= 0x08; // not ready } FDC.flags &= ~STATUSDRVB_flag; // clear status change flag FDC.result[RES_ST0] = val; FDC.result[RES_ST1] = driveB.current_track; } else { val = 0x80; // Invalid Command FDC.result[RES_ST0] = val; FDC.res_length = 1; } FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_seek() { check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_track = FDC.command[CMD_C]; if (active_drive->current_track >= DSK_TRACKMAX) { // beyond valid range? active_drive->current_track = DSK_TRACKMAX-1; // limit to maximum } } FDC.flags |= (FDC.command[CMD_UNIT] & 1) ? SEEKDRVB_flag : SEEKDRVA_flag; // signal completion of seek operation FDC.phase = CMD_PHASE; // switch back to command phase (fdc_seek has no result phase!) } void fdc_readtrk() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? FDC.command[CMD_R] = 1; // set sector ID to 1 active_drive->current_sector = 0; // reset sector table index if (active_drive->track_hook) active_drive->track_hook(active_drive); // update flakey data cmd_readtrk(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_write() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_drive->write_protected) { // is write protect tab set? FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x02; // Not Writable LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else if (active_track->sectors != 0) { // track is formatted? active_drive->altered = true; cmd_write(); } else { // unformatted track active_drive->altered = true; FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_read() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? cmd_read(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_readID() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? dword idx; idx = active_drive->current_sector; // get the active sector index if (idx >= active_track->sectors) { // index beyond number of sectors for this track? idx = 0; // reset index if (active_drive->track_hook) // hook available? active_drive->track_hook(active_drive); // update flakey data } memcpy(&FDC.result[RES_C], &active_track->sector[idx].CHRN, 4); // copy sector's CHRN to result buffer active_drive->current_sector = idx + 1; // update sector table index for active drive } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN } } FDC.phase = RESULT_PHASE; // switch to result phase } void fdc_writeID() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_drive->write_protected) { // is write protect tab set? FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x02; // Not Writable LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } else { active_drive->altered = true; FDC.buffer_count = FDC.command[CMD_H] << 2; // number of sectors * 4 = number of bytes still outstanding FDC.buffer_ptr = pbGPBuffer; // buffer to temporarily hold the track format FDC.buffer_endptr = pbGPBuffer + FDC.buffer_count; FDC.timeout = INITIAL_TIMEOUT; read_status_delay = 1; } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } void fdc_scan() { FDC.led = 1; // turn the drive LED on check_unit(); // switch to target drive if (init_status_regs() == 0) { // drive Ready? active_drive->current_side = (FDC.command[CMD_UNIT] & 4) >> 2; // extract target side dword side = active_drive->sides ? active_drive->current_side : 0; // single sided drives only acccess side 1 if ((active_drive->flipped)) { // did the user request to access the "other" side? side = side ? 0 : 1; // reverse the side to access } active_track = &active_drive->track[active_drive->current_track][side]; if (active_track->sectors != 0) { // track is formatted? if (FDC.command[CMD_STP] > 2) { FDC.command[CMD_STP] = 2; // step can only be 1 or 2 } FDC.flags |= SCAN_flag; // scan command active cmd_scan(); } else { // unformatted track FDC.result[RES_ST0] |= 0x40; // AT FDC.result[RES_ST1] |= 0x01; // Missing AM LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } } else { // drive was not ready LOAD_RESULT_WITH_CHRN FDC.phase = RESULT_PHASE; // switch to result phase } }
37,103
C++
.cpp
860
34.031395
138
0.571915
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,796
symfile.cpp
ColinPitrat_caprice32/src/symfile.cpp
#include "symfile.h" #include <fstream> #include <iomanip> #include <string> #include "stringutils.h" #include "log.h" Symfile::Symfile(const std::string& filename) { std::ifstream infile(filename); std::string line; while (std::getline(infile, line)) { // Remove any comment line = stringutils::trim(line.substr(0, line.find(';')), ' '); auto elems = stringutils::split(line, ' ', /*ignore_empty=*/true); if (elems.empty()) continue; if (elems[0] == "al") { if (elems.size() < 3 || elems[1][0] != '$' || elems[2][0] != '.') { LOG_ERROR("Invalid `al` entry in " << filename << ": " << line); continue; } word addr = std::stol(elems[1].substr(1), nullptr, 16); addSymbol(addr, elems[2].substr(1)); } if (elems[0] == "b" or elems[0] == "break") { if (elems.size() < 2 || elems[1][0] != '$') { LOG_ERROR("Invalid `al` entry in " << filename << ": " << line); continue; } word addr = std::stol(elems[1].substr(1), nullptr, 16); addBreakpoint(addr); } if (elems[0] == "d") { if (elems.size() < 2 || elems[1][0] != '$') { LOG_ERROR("Invalid `al` entry in " << filename << ": " << line); continue; } word addr = std::stol(elems[1].substr(1), nullptr, 16); addEntrypoint(addr); } } } bool Symfile::SaveTo(const std::string& filename) { std::ofstream outfile; outfile.open(filename, std::ios_base::trunc); outfile << "; labels" << std::endl; for (const auto& [addr, sym] : symbols) { outfile << "al $" << std::hex << std::setw(4) << std::setfill('0') << addr << " ." << sym << std::endl; } outfile << "; breakpoints" << std::endl; for (auto addr : breakpoints) { outfile << "b $" << std::hex << std::setw(4) << std::setfill('0') << addr << std::endl; } outfile << "; entrypoints" << std::endl; for (auto addr : entrypoints) { outfile << "d $" << std::hex << std::setw(4) << std::setfill('0') << addr << std::endl; } outfile.close(); return true; } void Symfile::addBreakpoint(word addr) { breakpoints.push_back(addr); } void Symfile::addEntrypoint(word addr) { entrypoints.push_back(addr); } void Symfile::addSymbol(word addr, const std::string& symbol) { symbols[addr] = symbol; }
2,302
C++
.cpp
76
26.315789
108
0.574324
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,797
z80_disassembly.cpp
ColinPitrat_caprice32/src/z80_disassembly.cpp
#include "z80_disassembly.h" #include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <sstream> #include <string> #include "z80.h" #include "cap32.h" #include "log.h" extern t_z80regs z80; #include "z80_macros.h" extern t_CPC CPC; OpCode::OpCode(int value, int length, int argsize, std::string instruction) : value_(value), length_(length), argsize_(argsize), instruction_(std::move(instruction)) {} uint64_t DisassembledCode::hash() const { uint64_t h = 0; int i = 0; for (const auto& line : lines) { h += i * (line.address_ + line.opcode_); i += 1; } return h; } std::optional<DisassembledLine> DisassembledCode::LineAt(word address) const { for (const auto& l : lines) { if (l.address_ == address) { return l; } } return {}; } std::ostream& operator<<(std::ostream& os, const DisassembledLine& line) { os << std::setfill('0') << std::setw(4) << std::hex << line.address_ << ": "; os << std::setfill(' ') << std::setw(8) << line.opcode_ << " " << line.instruction_; return os; } std::ostream& operator<<(std::ostream& os, const DisassembledCode& code) { for (const auto& line : code.lines) { os << line << std::endl; } return os; } DisassembledLine::DisassembledLine(word address, uint64_t opcode, std::string&& instruction, int64_t ref_address) : address_(address), opcode_(opcode), instruction_(instruction) { if (ref_address >= 0) { ref_address_ = ref_address; std::ostringstream oss; oss << "$" << std::hex << std::setw(4) << std::setfill('0') << ref_address; ref_address_string_ = oss.str(); } } int DisassembledLine::Size() const { if (opcode_ < 0x100) return 1; if (opcode_ < 0x10000) return 2; if (opcode_ < 0x1000000) return 3; if (opcode_ < 0x100000000) return 4; if (opcode_ < 0x10000000000) return 5; if (opcode_ < 0x1000000000000) return 6; if (opcode_ < 0x100000000000000) return 7; return 8; } bool operator<(const DisassembledLine& l, const DisassembledLine& r) { return l.address_ < r.address_; } bool operator==(const DisassembledLine& l, const DisassembledLine& r) { return l.address_ == r.address_ && l.opcode_ == r.opcode_ && l.instruction_ == r.instruction_; } std::map<int, OpCode> load_opcodes_table() { std::map<int, OpCode> opcode_to_instruction; std::ifstream infile(CPC.resources_path + "/z80_opcodes.txt"); if (!infile.good()) { LOG_ERROR("Error opening " << CPC.resources_path << "/z80_opcodes.txt"); } std::string line; while (std::getline(infile, line)) { auto delimiter = line.find(':'); std::string opcode = line.substr(0, delimiter); // -2 for the 0x prefix, divide by 2 to get number of bytes int opcode_length = (opcode.length() - 2) / 2; int opcode_value = std::stol(opcode, nullptr, 0); std::string instruction = line.substr(delimiter+1); int nbargs = std::count(instruction.begin(), instruction.end(), '*'); opcode_to_instruction[opcode_value] = OpCode(opcode_value, opcode_length, nbargs, instruction); //std::cout << opcode << "(" << std::hex << opcode_value << "): " << instruction << std::endl; } return opcode_to_instruction; } void add_if_new(word address, const DisassembledCode& result, std::vector<dword>& to_disassemble_from, const std::string& why, word from) { DisassembledLine fakeLine(address, 0, ""); if (result.lines.count(fakeLine) == 0) { to_disassemble_from.push_back(address); LOG_VERBOSE("Adding " << std::hex << address << " from " << why << " at " << from); } } void append_address(std::string& instruction, word address) { std::ostringstream oss; oss << " ; $" << std::hex << std::setw(4) << std::setfill('0') << address; instruction += oss.str(); } DisassembledLine disassemble_one(dword start_address, DisassembledCode& result, std::vector<dword>& called_points) { static auto opcode_to_instructions = load_opcodes_table(); uint64_t opcode = 0; word pos = start_address; for (int bytes_read = 0; bytes_read < 3; bytes_read++) { int64_t ref_address = -1; opcode = (opcode << 8) + z80_read_mem(pos++); //std::cout << "Looking for opcode " << std::hex << opcode << std::endl; if (opcode_to_instructions.find(opcode) != opcode_to_instructions.end()) { auto instr = opcode_to_instructions[opcode]; std::string instruction = instr.instruction_; if (instruction.find("**") != std::string::npos) { int op = z80_read_mem(pos++); opcode = (opcode << 8) + op; int second_byte = z80_read_mem(pos++); op += (second_byte << 8); opcode = (opcode << 8) + second_byte; std::ostringstream oss; oss << "$" << std::hex << std::setw(4) << std::setfill('0') << op; instruction.replace(instruction.find("**"), 2, oss.str()); if (instruction.rfind("call", 0) == 0 || instruction.rfind("jp", 0) == 0) { add_if_new(op, result, called_points, instruction, start_address); ref_address = op; } } while (instruction.find('*') != std::string::npos) { auto op = z80_read_mem(pos++); opcode = (opcode << 8) + op; std::ostringstream oss; oss << "$" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(op); instruction.replace(instruction.find('*'), 1, oss.str()); if (instruction.rfind("jr", 0) == 0 || instruction.rfind("djnz", 0) == 0) { word address = pos + static_cast<int8_t>(op); append_address(instruction, address); add_if_new(address, result, called_points, instruction, start_address); ref_address = address; } if (instruction.rfind("rst", 0) == 0) { // RST instruction is of the form rst xxh where xx can be 00, 08, // 10, 18, 20, 28, 30 or 38 word address = std::stol(instruction.substr(4,2), nullptr, 16); append_address(instruction, address); add_if_new(address, result, called_points, instruction, start_address); ref_address = address; } } // TODO: Detect inconsistencies (overlapping instructions). This // requires checking the instructions before and after the newly // emplaced one. return DisassembledLine(start_address, opcode, std::move(instruction), ref_address); } } LOG_VERBOSE("No opcode found at " << std::hex << start_address << " for " << opcode << " from " << start_address); uint64_t value = z80_read_mem(start_address); std::ostringstream oss; oss << "db $" << std::hex << value; return DisassembledLine(start_address, value, oss.str()); } // We use a dword for pos to allow to check if we're reaching the end of the memory void disassemble_from(dword pos, DisassembledCode& result, std::vector<dword>& to_disassemble_from) { while (pos <= 0xFFFF) { auto line = disassemble_one(pos, result, to_disassemble_from); pos += line.Size(); result.lines.insert(line); if (line.instruction_ == "ret") return; } } // Ideas: // - Disassemble starting at PC // - Recursively: // - Follow: // - jp, call (absolutes) // - jr, djnz (relatives) // - rst (one byte corresponding to LSB, HSB = 0) // - Stop on ret (but not conditional ones), reti, retn (and more?) // - Also disassemble starting at a given entry point // - Detect inconsistencies // - When inserting an instruction, verify it doesn't overlap with the one before or after // - On inconsistency with already disassembled code: // - From PC, it's probably a bug in the disassembler? // - From entry point, it's probably a bad entry point? DisassembledCode disassemble(const std::vector<word>& entry_points) { DisassembledCode code; std::vector<dword> to_disassemble_from(entry_points.begin(), entry_points.end()); //to_disassemble_from.push_back(_PC); while (!to_disassemble_from.empty()) { auto next_pos = to_disassemble_from.back(); to_disassemble_from.pop_back(); disassemble_from(next_pos, code, to_disassemble_from); } return code; }
8,087
C++
.cpp
206
35.169903
137
0.64412
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
753,798
fileutils.cpp
ColinPitrat_caprice32/src/fileutils.cpp
// Caprice 32 // File IO functions #include <dirent.h> #include <string> #include <vector> #include <algorithm> #include <stdio.h> #include <sys/stat.h> #include <unistd.h> #include <ctime> int file_size (int fd) { struct stat s; if (!fstat(fd, &s)) { return s.st_size; } return 0; } bool file_copy(FILE *in, FILE *out) { size_t read; char buffer[1024]; while((read = fread(buffer, 1, 1024, in)) > 0) { if (fwrite(buffer, 1, read, out) != read) { break; } } return !(ferror(in) || ferror(out)); } bool is_directory(std::string filepath) { struct stat _stat; return ( (stat(filepath.c_str(), &_stat) == 0) && (S_ISDIR(_stat.st_mode)) ); } // Returns a vector containing the names of the files in the specified directory std::vector<std::string> listDirectory(std::string &directory) { std::vector<std::string> s; if (directory[directory.size() - 1] != '/') { directory += "/"; } DIR* pDir; struct dirent *pent; pDir = opendir(directory.c_str()); if (!pDir){ printf ("opendir(%s) failed; terminating\n", directory.c_str()); return s; } while ((pent = readdir(pDir))){ std::string fileName = std::string(pent->d_name); if (fileName != ".." and fileName != ".") { s.push_back(fileName); } } closedir(pDir); sort(s.begin(), s.end()); // sort elements return s; } // Returns a vector containing the names of the files having extension "ext" in // the specified directory std::vector<std::string> listDirectoryExt(std::string &directory, const std::string &ext) { std::vector<std::string> allFiles = listDirectory(directory); std::vector<std::string> matchingFiles; std::string extension; for (const auto& fileName : allFiles) { extension = fileName.substr(fileName.find_last_of('.') + 1); if (ext == extension) { matchingFiles.push_back(fileName); } } return matchingFiles; } #define TIME_STRING_MAX_LENGTH 80 std::string getDateString() { char dateString[TIME_STRING_MAX_LENGTH]; // Should be more than enough time_t t = std::time(nullptr); if (std::strftime(dateString, sizeof(dateString), "%Y%m%d_%H%M%S", std::localtime(&t))) { return std::string(dateString); } return "unknown_date"; }
2,284
C++
.cpp
77
26.077922
91
0.649203
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,799
cap32.cpp
ColinPitrat_caprice32/src/cap32.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2005 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <algorithm> #include <iostream> #include <sstream> #include <chrono> #include <string> #include <thread> #include <filesystem> #include "SDL.h" #include "cap32.h" #include "crtc.h" #include "devtools.h" #include "disk.h" #include "tape.h" #include "video.h" #include "z80.h" #include "configuration.h" #include "memutils.h" #include "stringutils.h" #include "zip.h" #include "keyboard.h" #include "cartridge.h" #include "asic.h" #include "argparse.h" #include "slotshandler.h" #include "fileutils.h" #include <errno.h> #include <cstring> #include "wg_error.h" #include "CapriceGui.h" #include "CapriceGuiView.h" #include "CapriceVKeyboardView.h" #include "CapriceLeavingWithoutSavingView.h" #include "errors.h" #include "log.h" #include "savepng.h" #define MAX_LINE_LEN 256 #define MAX_NB_JOYSTICKS 2 #define POLL_INTERVAL_MS 1 #ifndef DESTDIR #define DESTDIR "" #endif extern byte bTapeLevel; extern t_z80regs z80; extern std::vector<Breakpoint> breakpoints; extern dword *ScanPos; extern dword *ScanStart; extern word MaxVSync; extern t_flags1 flags1; extern t_new_dt new_dt; extern t_disk_format disk_format[]; extern byte* pbCartridgePages[]; extern SDL_Window* mainSDLWindow; SDL_AudioDeviceID audio_device_id = 0; SDL_Surface *back_surface = nullptr; video_plugin* vid_plugin; SDL_Joystick* joysticks[MAX_NB_JOYSTICKS]; std::list<DevTools> devtools; dword dwTicks, dwTicksOffset, dwTicksTarget, dwTicksTargetFPS; dword dwFPS, dwFrameCount; dword dwXScale, dwYScale; dword dwSndBufferCopied; dword osd_timing; std::string osd_message; std::string lastSavedSnapshot; dword dwBreakPoint, dwTrace, dwMF2ExitAddr; dword dwMF2Flags = 0; std::unique_ptr<byte[]> pbSndBuffer; byte *pbGPBuffer = nullptr; byte *pbSndBufferEnd = nullptr; byte *pbSndStream = nullptr; byte *membank_read[4], *membank_write[4], *memmap_ROM[256]; byte *pbRAM = nullptr; byte *pbRAMbuffer = nullptr; byte *pbROM = nullptr; byte *pbROMlo = nullptr; byte *pbROMhi = nullptr; byte *pbExpansionROM = nullptr; byte *pbMF2ROMbackup = nullptr; byte *pbMF2ROM = nullptr; byte *pbTapeImage = nullptr; byte keyboard_matrix[16]; std::list<SDL_Event> virtualKeyboardEvents; dword nextVirtualEventFrameCount, dwFrameCountOverall = 0; dword breakPointsToSkipBeforeProceedingWithVirtualEvents = 0; t_MemBankConfig membank_config; FILE *pfileObject; FILE *pfoPrinter; #ifdef DEBUG dword dwDebugFlag = 0; FILE *pfoDebug = nullptr; #endif #define MAX_FREQ_ENTRIES 5 dword freq_table[MAX_FREQ_ENTRIES] = { 11025, 22050, 44100, 48000, 96000 }; #include "font.h" void set_osd_message(const std::string& message) { osd_timing = SDL_GetTicks() + 1000; osd_message = " " + message; } double colours_rgb[32][3] = { { 0.5, 0.5, 0.5 }, { 0.5, 0.5, 0.5 },{ 0.0, 1.0, 0.5 }, { 1.0, 1.0, 0.5 }, { 0.0, 0.0, 0.5 }, { 1.0, 0.0, 0.5 },{ 0.0, 0.5, 0.5 }, { 1.0, 0.5, 0.5 }, { 1.0, 0.0, 0.5 }, { 1.0, 1.0, 0.5 },{ 1.0, 1.0, 0.0 }, { 1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0 }, { 1.0, 0.0, 1.0 },{ 1.0, 0.5, 0.0 }, { 1.0, 0.5, 1.0 }, { 0.0, 0.0, 0.5 }, { 0.0, 1.0, 0.5 },{ 0.0, 1.0, 0.0 }, { 0.0, 1.0, 1.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 },{ 0.0, 0.5, 0.0 }, { 0.0, 0.5, 1.0 }, { 0.5, 0.0, 0.5 }, { 0.5, 1.0, 0.5 },{ 0.5, 1.0, 0.0 }, { 0.5, 1.0, 1.0 }, { 0.5, 0.0, 0.0 }, { 0.5, 0.0, 1.0 },{ 0.5, 0.5, 0.0 }, { 0.5, 0.5, 1.0 } }; // original RGB color to GREEN LUMA converted by Ulrich Doewich // unknown formula. double colours_green_classic[32] = { 0.5647, 0.5647, 0.7529, 0.9412, 0.1882, 0.3765, 0.4706, 0.6588, 0.3765, 0.9412, 0.9098, 0.9725, 0.3451, 0.4078, 0.6275, 0.6902, 0.1882, 0.7529, 0.7216, 0.7843, 0.1569, 0.2196, 0.4392, 0.5020, 0.2824, 0.8471, 0.8157, 0.8784, 0.2510, 0.3137, 0.5333, 0.5961 }; // added by a proposal from libretro project, // see https://github.com/ColinPitrat/caprice32/issues/135 double colours_green_libretro[32] = { 0.5755, 0.5755, 0.7534, 0.9718, 0.1792, 0.3976, 0.4663, 0.6847, 0.3976, 0.9718, 0.9136, 1.0300, 0.3394, 0.4558, 0.6265, 0.7429, 0.1792, 0.7534, 0.6952, 0.8116, 0.1210, 0.2374, 0.4081, 0.5245, 0.2884, 0.8626, 0.8044, 0.9208, 0.2302, 0.3466, 0.5173, 0.6337 }; // interface to use the palette also from tests double *video_get_green_palette(int mode) { if (!mode) return colours_green_classic; return colours_green_libretro; } double *video_get_rgb_color(int color) { return colours_rgb[color]; } SDL_Color colours[32]; byte bit_values[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; #define MAX_ROM_MODS 2 #include "rom_mods.h" char chAppPath[_MAX_PATH + 1]; std::filesystem::path binPath; // Where the binary is char chROMSelected[_MAX_PATH + 1]; std::string chROMFile[4] = { "cpc464.rom", "cpc664.rom", "cpc6128.rom", "system.cpr" }; t_CPC CPC; t_CRTC CRTC; t_FDC FDC; t_GateArray GateArray; t_PPI PPI; t_PSG PSG; t_VDU VDU; t_drive driveA; t_drive driveB; #define psg_write \ { \ byte control = PSG.control & 0xc0; /* isolate PSG control bits */ \ if (control == 0xc0) { /* latch address? */ \ PSG.reg_select = psg_data; /* select new PSG register */ \ } else if (control == 0x80) { /* write? */ \ if (PSG.reg_select < 16) { /* valid register? */ \ SetAYRegister(PSG.reg_select, psg_data); \ } \ } \ } enum ApplicationWindowState { Minimized, // application window has been iconified Restored, // application window has been restored GainedFocus, // application window got input focus LostFocus // application window lost input focus } _appWindowState; CapriceArgs args; void ga_init_banking (t_MemBankConfig& membank_config, unsigned char RAM_bank) { byte *romb0, *romb1, *romb2, *romb3, *romb4, *romb5, *romb6, *romb7; byte *pbRAMbank; romb0 = pbRAM; romb1 = pbRAM + 1*16384; romb2 = pbRAM + 2*16384; romb3 = pbRAM + 3*16384; pbRAMbank = pbRAM + ((RAM_bank + 1) * 65536); romb4 = pbRAMbank; romb5 = pbRAMbank + 1*16384; romb6 = pbRAMbank + 2*16384; romb7 = pbRAMbank + 3*16384; membank_config[0][0] = romb0; membank_config[0][1] = romb1; membank_config[0][2] = romb2; membank_config[0][3] = romb3; membank_config[1][0] = romb0; membank_config[1][1] = romb1; membank_config[1][2] = romb2; membank_config[1][3] = romb7; membank_config[2][0] = romb4; membank_config[2][1] = romb5; membank_config[2][2] = romb6; membank_config[2][3] = romb7; membank_config[3][0] = romb0; membank_config[3][1] = romb3; membank_config[3][2] = romb2; membank_config[3][3] = romb7; membank_config[4][0] = romb0; membank_config[4][1] = romb4; membank_config[4][2] = romb2; membank_config[4][3] = romb3; membank_config[5][0] = romb0; membank_config[5][1] = romb5; membank_config[5][2] = romb2; membank_config[5][3] = romb3; membank_config[6][0] = romb0; membank_config[6][1] = romb6; membank_config[6][2] = romb2; membank_config[6][3] = romb3; membank_config[7][0] = romb0; membank_config[7][1] = romb7; membank_config[7][2] = romb2; membank_config[7][3] = romb3; } void ga_memory_manager () { dword mem_bank; if (CPC.ram_size == 64) { // 64KB of RAM? mem_bank = 0; // no expansion memory GateArray.RAM_config = 0; // the only valid configuration is 0 } else { mem_bank = (GateArray.RAM_config >> 3) & 7; // extract expansion memory bank if (((mem_bank+2)*64) > CPC.ram_size) { // selection is beyond available memory? mem_bank = 0; // force default mapping } } if (mem_bank != GateArray.RAM_bank) { // requested bank is different from the active one? GateArray.RAM_bank = mem_bank; ga_init_banking(membank_config, GateArray.RAM_bank); } for (int n = 0; n < 4; n++) { // remap active memory banks membank_read[n] = membank_config[GateArray.RAM_config & 7][n]; membank_write[n] = membank_config[GateArray.RAM_config & 7][n]; } if (!(GateArray.ROM_config & 0x04)) { // lower ROM is enabled? if (dwMF2Flags & MF2_ACTIVE) { // is the Multiface 2 paged in? // TODO: I think this is why the MF2 doesn't work properly: // ROM should be loaded R/O at 0x0000-0x1FFF (i.e not loaded in membank_write ?) // Writes should probably be disabled in membank_write (pointing to a dummy buffer, but not MF2 ROM ?) // MF2 also has a RAM (8kB) that should be loaded as R/W at 0x2000-0x3FFF membank_read[GateArray.lower_ROM_bank] = pbMF2ROM; membank_write[GateArray.lower_ROM_bank] = pbMF2ROM; } else { membank_read[GateArray.lower_ROM_bank] = pbROMlo; // 'page in' lower ROM } } if (CPC.model > 2 && GateArray.registerPageOn) { membank_read[1] = pbRegisterPage; membank_write[1] = pbRegisterPage; } if (!(GateArray.ROM_config & 0x08)) { // upper/expansion ROM is enabled? membank_read[3] = pbExpansionROM; // 'page in' upper/expansion ROM } } byte z80_IN_handler (reg_pair port) { byte ret_val; ret_val = 0xff; // default return value // CRTC ----------------------------------------------------------------------- if (!(port.b.h & 0x40)) { // CRTC chip select? if ((port.b.h & 3) == 3) { // read CRTC register? if ((CRTC.reg_select > 11) && (CRTC.reg_select < 18)) { // valid range? ret_val = CRTC.registers[CRTC.reg_select]; } else { ret_val = 0; // write only registers return 0 } } } // PPI ------------------------------------------------------------------------ else if (!(port.b.h & 0x08)) { // PPI chip select? byte ppi_port = port.b.h & 3; switch (ppi_port) { case 0: // read from port A? if (PPI.control & 0x10) { // port A set to input? if ((PSG.control & 0xc0) == 0x40) { // PSG control set to read? if (PSG.reg_select < 16) { // within valid range? if (PSG.reg_select == 14) { // PSG port A? if (!(PSG.RegisterAY.Index[7] & 0x40)) { // port A in input mode? ret_val = keyboard_matrix[CPC.keyboard_line & 0x0f]; // read keyboard matrix node status } else { ret_val = PSG.RegisterAY.Index[14] & (keyboard_matrix[CPC.keyboard_line & 0x0f]); // return last value w/ logic AND of input } LOG_DEBUG("PPI read from portA (keyboard_line): " << CPC.keyboard_line << " - " << static_cast<int>(ret_val)); } else if (PSG.reg_select == 15) { // PSG port B? if ((PSG.RegisterAY.Index[7] & 0x80)) { // port B in output mode? ret_val = PSG.RegisterAY.Index[15]; // return stored value LOG_DEBUG("PPI read from portA (PSG portB): " << CPC.keyboard_line << " - " << static_cast<int>(ret_val)); } } else { ret_val = PSG.RegisterAY.Index[PSG.reg_select]; // read PSG register LOG_DEBUG("PPI read from portA (registers): " << CPC.keyboard_line << " - " << static_cast<int>(ret_val)); } } } } else { ret_val = PPI.portA; // return last programmed value LOG_DEBUG("PPI read from portA (last value): " << CPC.keyboard_line << " - " << static_cast<int>(ret_val)); } break; case 1: // read from port B? // 6128+: always use port B as input as this fixes Tintin on the moon. // This should always be the case anyway but do not activate it for other model for now, let's validate it before. // TODO: verify with CPC (non-plus) if we go in the else in some cases if (CPC.model > 2 || PPI.control & 2) { // port B set to input? LOG_DEBUG("PPI read from portB: bTapeLevel=" << static_cast<int>(bTapeLevel) << ", CPC.printer=" << CPC.printer << ", CPC.jumpers=" << CPC.jumpers << ", CRTC.flag_invsync=" << CRTC.flag_invsync) ret_val = bTapeLevel | // tape level when reading (CPC.printer ? 0 : 0x40) | // ready line of connected printer (CPC.jumpers & 0x7f) | // manufacturer + 50Hz (CRTC.flag_invsync ? 1 : 0); // VSYNC status } else { LOG_DEBUG("PPI read from portB: " << static_cast<int>(PPI.portB)) ret_val = PPI.portB; // return last programmed value } break; case 2: // read from port C? byte direction = PPI.control & 9; // isolate port C directions ret_val = PPI.portC; // default to last programmed value if (direction) { // either half set to input? if (direction & 8) { // upper half set to input? ret_val &= 0x0f; // blank out upper half byte val = PPI.portC & 0xc0; // isolate PSG control bits if (val == 0xc0) { // PSG specify register? val = 0x80; // change to PSG write register } ret_val |= val | 0x20; // casette write data is always set if (CPC.tape_motor) { ret_val |= 0x10; // set the bit if the tape motor is running } LOG_DEBUG("PPI read from portC (upper half): " << static_cast<int>(ret_val)); } if (!(direction & 1)) { // lower half set to output? ret_val |= 0x0f; // invalid - set all bits LOG_DEBUG("PPI read from portC (lower half): " << static_cast<int>(ret_val)); } } LOG_DEBUG("PPI read from portC: " << static_cast<int>(ret_val)); break; } } // ---------------------------------------------------------------------------- else if (!(port.b.h & 0x04)) { // external peripheral? if ((port.b.h == 0xfb) && (!(port.b.l & 0x80))) { // FDC? if (!(port.b.l & 0x01)) { // FDC status register? ret_val = fdc_read_status(); } else { // FDC data register ret_val = fdc_read_data(); } } } LOG_DEBUG("IN on port " << std::hex << static_cast<int>(port.w.l) << ", ret_val=" << static_cast<int>(ret_val) << std::dec); return ret_val; } void z80_OUT_handler (reg_pair port, byte val) { LOG_DEBUG("OUT on port " << std::hex << static_cast<int>(port.w.l) << ", val=" << static_cast<int>(val) << std::dec); // Amstrad Magnum Phazer if ((port.b.h == 0xfb) && (port.b.l == 0xfe)) { // When the phazer is not pressed, the CRTC is constantly refreshing R16 & R17: // https://www.cpcwiki.eu/index.php/Amstrad_Magnum_Phaser if (!CPC.phazer_pressed) CRTC.registers[17] += 1; } // Gate Array ----------------------------------------------------------------- if ((port.b.h & 0xc0) == 0x40) { // GA chip select? switch (val >> 6) { case 0: // select pen #ifdef DEBUG_GA if (dwDebugFlag) { fprintf(pfoDebug, "pen 0x%02x\r\n", val); } #endif GateArray.pen = val & 0x10 ? 0x10 : val & 0x0f; // if bit 5 is set, pen indexes the border colour LOG_DEBUG("Set pen value to " << static_cast<int>(GateArray.pen)); if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x03fcf) = val; } break; case 1: // set colour #ifdef DEBUG_GA if (dwDebugFlag) { fprintf(pfoDebug, "clr 0x%02x\r\n", val); } #endif { byte colour = val & 0x1f; // isolate colour value LOG_DEBUG("Set ink value " << static_cast<int>(GateArray.pen) << " to " << static_cast<int>(colour)); GateArray.ink_values[GateArray.pen] = colour; GateArray.palette[GateArray.pen] = SDL_MapRGB(back_surface->format, colours[colour].r, colours[colour].g, colours[colour].b); if (GateArray.pen < 2) { byte r = (static_cast<dword>(colours[GateArray.ink_values[0]].r) + static_cast<dword>(colours[GateArray.ink_values[1]].r)) >> 1; byte g = (static_cast<dword>(colours[GateArray.ink_values[0]].g) + static_cast<dword>(colours[GateArray.ink_values[1]].g)) >> 1; byte b = (static_cast<dword>(colours[GateArray.ink_values[0]].b) + static_cast<dword>(colours[GateArray.ink_values[1]].b)) >> 1; GateArray.palette[33] = SDL_MapRGB(back_surface->format, r, g, b); // update the mode 2 'anti-aliasing' colour } // TODO: update pbRegisterPage } if (CPC.mf2) { // MF2 enabled? int iPen = *(pbMF2ROM + 0x03fcf); *(pbMF2ROM + (0x03f90 | ((iPen & 0x10) << 2) | (iPen & 0x0f))) = val; } break; case 2: // set mode if (!asic.locked && (val & 0x20)) { // 6128+ RMR2 register int membank = (val >> 3) & 3; if (membank == 3) { // Map register page at 0x4000 LOG_DEBUG("Register page on"); GateArray.registerPageOn = true; membank = 0; } else { LOG_DEBUG("Register page off"); GateArray.registerPageOn = false; } int page = (val & 0x7); LOG_DEBUG("RMR2: Low bank rom = 0x" << std::hex << (4*membank) << std::dec << "000 - page " << page); GateArray.lower_ROM_bank = membank; pbROMlo = pbCartridgePages[page]; ga_memory_manager(); } else { #ifdef DEBUG_GA if (dwDebugFlag) { fprintf(pfoDebug, "rom 0x%02x\r\n", val); } #endif LOG_DEBUG("MRER: ROM config = " << std::hex << static_cast<int>(val) << std::dec << " - mode=" << static_cast<int>(val & 0x03)); GateArray.ROM_config = val; GateArray.requested_scr_mode = val & 0x03; // request a new CPC screen mode ga_memory_manager(); if (val & 0x10) { // delay Z80 interrupt? z80.int_pending = 0; // clear pending interrupts GateArray.sl_count = 0; // reset GA scanline counter } if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x03fef) = val; } } break; case 3: // Reading https://www.cpcwiki.eu/index.php/Gate_Array // suggests this should set memory configuration but actually this is contradicted by: // - http://cpctech.cpc-live.com/docs/rampage.html // - https://www.cpcwiki.eu/index.php/I/O_Port_Summary // - https://www.cpcwiki.eu/index.php/Default_I/O_Port_Summary // which tell that this is controlled by address at %0xxxxxxx xxxxxxxx // so this is handled separately below break; } } // Memory configuration ------------------------------------------------------- if (!(port.b.h & 0x80) && (val & 0xc0) == 0xc0) { #ifdef DEBUG_GA if (dwDebugFlag) { fprintf(pfoDebug, "mem 0x%02x\r\n", val); } #endif LOG_DEBUG("RAM config: " << std::hex << static_cast<int>(val) << std::dec); GateArray.RAM_config = val; ga_memory_manager(); if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x03fff) = val; } } // CRTC ----------------------------------------------------------------------- if (!(port.b.h & 0x40)) { // CRTC chip select? byte crtc_port = port.b.h & 3; if (crtc_port == 0) { // CRTC register select? // 6128+: this is where we detect the ASIC (un)locking sequence if (CPC.model > 2) { asic_poke_lock_sequence(val); } CRTC.reg_select = val; if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x03cff) = val; } } else if (crtc_port == 1) { // CRTC write data? if (CRTC.reg_select < 16) { // only registers 0 - 15 can be written to LOG_DEBUG("CRTC write to register " << static_cast<int>(CRTC.reg_select) << ": " << static_cast<int>(val)); switch (CRTC.reg_select) { case 0: // horizontal total CRTC.registers[0] = val; break; case 1: // horizontal displayed CRTC.registers[1] = val; update_skew(); break; case 2: // horizontal sync position CRTC.registers[2] = val; break; case 3: // sync width CRTC.registers[3] = val; CRTC.hsw = val & 0x0f; // isolate horizontal sync width CRTC.vsw = val >> 4; // isolate vertical sync width break; case 4: // vertical total CRTC.registers[4] = val & 0x7f; if (CRTC.CharInstMR == CharMR2) { if (CRTC.line_count == CRTC.registers[4]) { // matches vertical total? if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? CRTC.flag_startvta = 1; } } } break; case 5: // vertical total adjust CRTC.registers[5] = val & 0x1f; break; case 6: // vertical displayed CRTC.registers[6] = val & 0x7f; if (CRTC.line_count == CRTC.registers[6]) { // matches vertical displayed? new_dt.NewDISPTIMG = 0; } break; case 7: // vertical sync position CRTC.registers[7] = val & 0x7f; { dword temp = 0; if (CRTC.line_count == CRTC.registers[7]) { // matches vertical sync position? temp++; if (CRTC.r7match != temp) { CRTC.r7match = temp; if (CRTC.char_count >= 2) { CRTC.flag_resvsync = 0; if (!CRTC.flag_invsync) { CRTC.vsw_count = 0; CRTC.flag_invsync = 1; flags1.monVSYNC = 26; GateArray.hs_count = 2; // GA delays its VSYNC by two CRTC HSYNCs } } } } else { CRTC.r7match = 0; } } break; case 8: // interlace and skew CRTC.registers[8] = val; update_skew(); break; case 9: // maximum raster count CRTC.registers[9] = val & 0x1f; { dword temp = 0; if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? temp = 1; CRTC.flag_resscan = 1; // request a raster counter reset } if (CRTC.r9match != temp) { CRTC.r9match = temp; if (temp) { CRTC.CharInstMR = CharMR1; } } if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? if (CRTC.char_count == CRTC.registers[1]) { CRTC.next_addr = CRTC.addr + CRTC.char_count; } if (CRTC.char_count == CRTC.registers[0]) { // matches horizontal total? CRTC.flag_reschar = 1; // request a line count update } if (!CRTC.flag_startvta) { CRTC.flag_resscan = 1; } } else { if (!CRTC.flag_invta) { // not in vertical total adjust? CRTC.flag_resscan = 0; } } } break; case 10: // cursor start raster CRTC.registers[10] = val & 0x7f; break; case 11: // cursor end raster CRTC.registers[11] = val & 0x1f; break; case 12: // start address high byte CRTC.registers[12] = val & 0x3f; CRTC.requested_addr = CRTC.registers[13] + (CRTC.registers[12] << 8); break; case 13: // start address low byte CRTC.registers[13] = val; CRTC.requested_addr = CRTC.registers[13] + (CRTC.registers[12] << 8); break; case 14: // cursor address high byte CRTC.registers[14] = val & 0x3f; break; case 15: // cursor address low byte CRTC.registers[15] = val; break; } } if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + (0x03db0 | (*(pbMF2ROM + 0x03cff) & 0x0f))) = val; } #ifdef DEBUG_CRTC if (dwDebugFlag) { fprintf(pfoDebug, "%02x = %02x\r\n", CRTC.reg_select, val); } #endif } } // ROM select ----------------------------------------------------------------- if (!(port.b.h & 0x20)) { // ROM select? if (CPC.model <= 2) { GateArray.upper_ROM = val; pbExpansionROM = memmap_ROM[val]; if (pbExpansionROM == nullptr) { // selected expansion ROM not present? pbExpansionROM = pbROMhi; // revert to BASIC ROM } } else { uint32_t page = 1; // Default to basic page LOG_DEBUG("ROM select: " << static_cast<int>(val)); if (val == 7) { page = 3; } else if (val >= 128) { page = val & 31; } GateArray.upper_ROM = page; pbExpansionROM = pbCartridgePages[page]; } if (!(GateArray.ROM_config & 0x08)) { // upper/expansion ROM is enabled? membank_read[3] = pbExpansionROM; // 'page in' upper/expansion ROM } if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x03aac) = val; } } // printer port --------------------------------------------------------------- if (!(port.b.h & 0x10)) { // printer port? CPC.printer_port = val ^ 0x80; // invert bit 7 if (pfoPrinter) { if (!(CPC.printer_port & 0x80)) { // only grab data bytes; ignore the strobe signal fputc(CPC.printer_port, pfoPrinter); // capture printer output to file fflush(pfoPrinter); } } } // PPI ------------------------------------------------------------------------ if (!(port.b.h & 0x08)) { // PPI chip select? switch (port.b.h & 3) { case 0: // write to port A? LOG_DEBUG("PPI write to portA: " << static_cast<int>(val)); PPI.portA = val; if (!(PPI.control & 0x10)) { // port A set to output? LOG_DEBUG("PPI write to portA (PSG): " << static_cast<int>(val)); byte psg_data = val; psg_write } break; case 1: // write to port B? LOG_DEBUG("PPI write to portB (upper half): " << static_cast<int>(val)); PPI.portB = val; break; case 2: // write to port C? LOG_DEBUG("PPI write to portC: " << static_cast<int>(val)); PPI.portC = val; if (!(PPI.control & 1)) { // output lower half? LOG_DEBUG("PPI write to portC (keyboard_line): " << static_cast<int>(val)); CPC.keyboard_line = val; } if (!(PPI.control & 8)) { // output upper half? LOG_DEBUG("PPI write to portC (upper half): " << static_cast<int>(val)); CPC.tape_motor = val & 0x10; // update tape motor control PSG.control = val; // change PSG control byte psg_data = PPI.portA; psg_write } break; case 3: // modify PPI control if (val & 0x80) { // change PPI configuration LOG_DEBUG("PPI.control " << static_cast<int>(PPI.control) << " => " << static_cast<int>(val)); PPI.control = val; // update control byte PPI.portA = 0; // clear data for all ports PPI.portB = 0; PPI.portC = 0; } else { // bit manipulation of port C data LOG_DEBUG("PPI.portC update: " << static_cast<int>(val)); byte bit = (val >> 1) & 7; // isolate bit to set if (val & 1) { // set bit? PPI.portC |= bit_values[bit]; // set requested bit } else { PPI.portC &= ~(bit_values[bit]); // reset requested bit } if (!(PPI.control & 1)) { // output lower half? LOG_DEBUG("PPI.portC update (keyboard_line): " << static_cast<int>(PPI.portC)); CPC.keyboard_line = PPI.portC; } if (!(PPI.control & 8)) { // output upper half? LOG_DEBUG("PPI.portC update (upper half): " << static_cast<int>(PPI.portC)); CPC.tape_motor = PPI.portC & 0x10; PSG.control = PPI.portC; // change PSG control byte psg_data = PPI.portA; psg_write } } if (CPC.mf2) { // MF2 enabled? *(pbMF2ROM + 0x037ff) = val; } break; } } // FDC ------------------------------------------------------------------------ if ((port.b.h == 0xfa) && (!(port.b.l & 0x80))) { // floppy motor control? LOG_DEBUG("FDC motor control access: " << static_cast<int>(port.b.l) << " - " << static_cast<int>(val)); FDC.motor = val & 0x01; #ifdef DEBUG_FDC fputs(FDC.motor ? "\r\n--- motor on" : "\r\n--- motor off", pfoDebug); #endif FDC.flags |= STATUSDRVA_flag | STATUSDRVB_flag; } else if ((port.b.h == 0xfb) && (!(port.b.l & 0x80))) { // FDC data register? fdc_write_data(val); } // MF2 ------------------------------------------------------------------------ else if ((CPC.mf2) && (port.b.h == 0xfe)) { // Multiface 2? if ((port.b.l == 0xe8) && (!(dwMF2Flags & MF2_INVISIBLE))) { // page in MF2 ROM? dwMF2Flags |= MF2_ACTIVE; ga_memory_manager(); } else if (port.b.l == 0xea) { // page out MF2 ROM? dwMF2Flags &= ~MF2_ACTIVE; ga_memory_manager(); } } } void print (byte *pbAddr, const char *pchStr, bool bolColour) { int iLen, iIdx; dword dwColour; word wColour; byte bRow, bColour; byte *pbLine, *pbPixel; iLen = strlen(pchStr); // number of characters to process switch (CPC.scr_bpp) { case 32: dwColour = bolColour ? 0xffffffff : 0; for (int n = 0; n < iLen; n++) { iIdx = static_cast<int>(pchStr[n]); // get the ASCII value if ((iIdx < FNT_MIN_CHAR) || (iIdx > FNT_MAX_CHAR)) { // limit it to the range of chars in the font iIdx = FNT_BAD_CHAR; } iIdx -= FNT_MIN_CHAR; // zero base the index pbLine = pbAddr; // keep a reference to the current screen position for (int iRow = 0; iRow < FNT_CHAR_HEIGHT; iRow++) { // loop for all rows in the font character pbPixel = pbLine; bRow = bFont[iIdx]; // get the bitmap information for one row for (int iCol = 0; iCol < FNT_CHAR_WIDTH; iCol++) { // loop for all columns in the font character if (bRow & 0x80) { // is the bit set? *(reinterpret_cast<dword*>(pbPixel)) = dwColour; // draw the character pixel *(reinterpret_cast<dword*>(pbPixel+CPC.scr_bps)) = dwColour; // draw the second line in case dwYScale == 2 (will be overwritten by shadow otherwise) *(reinterpret_cast<dword*>(pbPixel)+1) = 0; // draw the "shadow" on the right *(reinterpret_cast<dword*>(pbPixel+CPC.scr_bps)+1) = 0; // second line of shadow on the right *(reinterpret_cast<dword*>(pbPixel+CPC.scr_line_offs)) = 0; // shadow on the line below *(reinterpret_cast<dword*>(pbPixel+CPC.scr_line_offs)+1) = 0; // shadow below & on the right } pbPixel += 4; // update the screen position bRow <<= 1; // advance to the next bit } pbLine += CPC.scr_line_offs; // advance to next screen line iIdx += FNT_CHARS; // advance to next row in font data } pbAddr += FNT_CHAR_WIDTH*4; // set screen address to next character position } break; case 24: dwColour = bolColour ? 0x00ffffff : 0; for (int n = 0; n < iLen; n++) { iIdx = static_cast<int>(pchStr[n]); // get the ASCII value if ((iIdx < FNT_MIN_CHAR) || (iIdx > FNT_MAX_CHAR)) { // limit it to the range of chars in the font iIdx = FNT_BAD_CHAR; } iIdx -= FNT_MIN_CHAR; // zero base the index pbLine = pbAddr; // keep a reference to the current screen position for (int iRow = 0; iRow < FNT_CHAR_HEIGHT; iRow++) { // loop for all rows in the font character pbPixel = pbLine; bRow = bFont[iIdx]; // get the bitmap information for one row for (int iCol = 0; iCol < FNT_CHAR_WIDTH; iCol++) { // loop for all columns in the font character if (bRow & 0x80) { // is the bit set? *(reinterpret_cast<dword *>(pbPixel)) = dwColour; // draw the character pixel *(reinterpret_cast<dword *>(pbPixel+CPC.scr_bps)) = dwColour; // draw the second line in case dwYScale == 2 (will be overwritten by shadow otherwise) *(reinterpret_cast<dword *>(pbPixel+1)) = 0; // draw the "shadow" on the right *(reinterpret_cast<dword *>(pbPixel+CPC.scr_bps)+1) = 0; // second line of shadow on the right *(reinterpret_cast<dword *>(pbPixel+CPC.scr_line_offs)) = 0; // shadow on the line below *(reinterpret_cast<dword *>(pbPixel+CPC.scr_line_offs)+1) = 0; // shadow below & on the right } pbPixel += 3; // update the screen position bRow <<= 1; // advance to the next bit } pbLine += CPC.scr_line_offs; // advance to next screen line iIdx += FNT_CHARS; // advance to next row in font data } pbAddr += FNT_CHAR_WIDTH*3; // set screen address to next character position } break; case 15: case 16: wColour = bolColour ? 0xffff : 0; for (int n = 0; n < iLen; n++) { iIdx = static_cast<int>(pchStr[n]); // get the ASCII value if ((iIdx < FNT_MIN_CHAR) || (iIdx > FNT_MAX_CHAR)) { // limit it to the range of chars in the font iIdx = FNT_BAD_CHAR; } iIdx -= FNT_MIN_CHAR; // zero base the index pbLine = pbAddr; // keep a reference to the current screen position for (int iRow = 0; iRow < FNT_CHAR_HEIGHT; iRow++) { // loop for all rows in the font character pbPixel = pbLine; bRow = bFont[iIdx]; // get the bitmap information for one row for (int iCol = 0; iCol < FNT_CHAR_WIDTH; iCol++) { // loop for all columns in the font character if (bRow & 0x80) { // is the bit set? *(reinterpret_cast<word *>(pbPixel)) = wColour; // draw the character pixel *(reinterpret_cast<word *>(pbPixel+CPC.scr_bps)) = wColour; // draw the second line in case dwYScale == 2 (will be overwritten by shadow otherwise) *(reinterpret_cast<word *>(pbPixel)+1) = 0; // draw the "shadow" on the right *(reinterpret_cast<word *>(pbPixel+CPC.scr_bps)+1) = 0; // second line of shadow on the right *(reinterpret_cast<word *>(pbPixel+CPC.scr_line_offs)) = 0; // shadow on the line below *(reinterpret_cast<word *>(pbPixel+CPC.scr_line_offs)+1) = 0; // shadow below & on the right } pbPixel += 2; // update the screen position bRow <<= 1; // advance to the next bit } pbLine += CPC.scr_line_offs; // advance to next screen line iIdx += FNT_CHARS; // advance to next row in font data } pbAddr += FNT_CHAR_WIDTH*2; // set screen address to next character position } break; case 8: bColour = bolColour ? SDL_MapRGB(back_surface->format,255,255,255) : SDL_MapRGB(back_surface->format,0,0,0); for (int n = 0; n < iLen; n++) { iIdx = static_cast<int>(pchStr[n]); // get the ASCII value if ((iIdx < FNT_MIN_CHAR) || (iIdx > FNT_MAX_CHAR)) { // limit it to the range of chars in the font iIdx = FNT_BAD_CHAR; } iIdx -= FNT_MIN_CHAR; // zero base the index pbLine = pbAddr; // keep a reference to the current screen position for (int iRow = 0; iRow < FNT_CHAR_HEIGHT; iRow++) { // loop for all rows in the font character pbPixel = pbLine; bRow = bFont[iIdx]; // get the bitmap information for one row for (int iCol = 0; iCol < FNT_CHAR_WIDTH; iCol++) { // loop for all columns in the font character if (bRow & 0x80) { // is the bit set? *pbPixel = bColour; // draw the character pixel *(pbPixel+CPC.scr_bps) = bColour; // draw the second line in case dwYScale == 2 (will be overwritten by shadow otherwise) *(pbPixel+1) = 0; // draw the "shadow" on the right *(pbPixel+CPC.scr_bps) = 0; // second line of shadow on the right *(pbPixel+CPC.scr_line_offs) = 0; // shadow on the line below *(pbPixel+CPC.scr_line_offs+1) = 0; // shadow below & on the right } pbPixel++; // update the screen position bRow <<= 1; // advance to the next bit } pbLine += CPC.scr_line_offs; // advance to next screen line iIdx += FNT_CHARS; // advance to next row in font data } pbAddr += FNT_CHAR_WIDTH; // set screen address to next character position } break; } } int emulator_patch_ROM () { byte *pbPtr; if(CPC.model <= 2) { // Normal CPC range std::string romFilename = CPC.rom_path + "/" + chROMFile[CPC.model]; if ((pfileObject = fopen(romFilename.c_str(), "rb")) != nullptr) { // load CPC OS + Basic if(fread(pbROM, 2*16384, 1, pfileObject) != 1) { fclose(pfileObject); LOG_ERROR("Couldn't read ROM file '" << romFilename << "'"); return ERR_NOT_A_CPC_ROM; } pbROMlo = pbROM; fclose(pfileObject); } else { LOG_ERROR("Couldn't open ROM file '" << romFilename << "'"); return ERR_CPC_ROM_MISSING; } } else { // Plus range if (pbCartridgePages[0] != nullptr) { pbROMlo = pbCartridgePages[0]; } } // Patch ROM for non-english keyboards if (CPC.keyboard) { pbPtr = pbROMlo; switch(CPC.model) { case 0: // 464 pbPtr += 0x1d69; // location of the keyboard translation table break; case 1: // 664 case 2: // 6128 pbPtr += 0x1eef; // location of the keyboard translation table break; case 3: // 6128+ if(CPC.cart_file == CPC.rom_path + "/" + chROMFile[3]) { // Only patch system cartridge - we don't want to break another one by messing with it pbPtr += 0x1eef; // location of the keyboard translation table } break; } if (pbPtr != pbROMlo) { memcpy(pbPtr, cpc_keytrans[CPC.keyboard-1], 240); // patch the CPC OS ROM with the chosen keyboard layout pbPtr = pbROMlo + 0x3800; memcpy(pbPtr, cpc_charset[CPC.keyboard-1], 2048); // add the corresponding character set } } return 0; } void emulator_reset () { if (CPC.model > 2) { if (pbCartridgePages[0] != nullptr) { pbROMlo = pbCartridgePages[0]; } } // ASIC asic_reset(); video_set_palette(); // Z80 z80_reset(); // CPC CPC.cycle_count = CYCLE_COUNT_INIT; memset(keyboard_matrix, 0xff, sizeof(keyboard_matrix)); // clear CPC keyboard matrix CPC.tape_motor = 0; CPC.tape_play_button = 0; CPC.printer_port = 0xff; // VDU memset(&VDU, 0, sizeof(VDU)); // clear VDU data structure VDU.flag_drawing = 1; // CRTC crtc_reset(); // Gate Array memset(&GateArray, 0, sizeof(GateArray)); // clear GA data structure GateArray.scr_mode = GateArray.requested_scr_mode = 1; // set to mode 1 GateArray.registerPageOn = false; GateArray.lower_ROM_bank = 0; ga_init_banking(membank_config, GateArray.RAM_bank); // PPI memset(&PPI, 0, sizeof(PPI)); // clear PPI data structure // PSG PSG.control = 0; ResetAYChipEmulation(); // FDC memset(&FDC, 0, sizeof(FDC)); // clear FDC data structure FDC.phase = CMD_PHASE; FDC.flags = STATUSDRVA_flag | STATUSDRVB_flag; // memory memset(pbRAM, 0, CPC.ram_size*1024); // clear all memory used for CPC RAM if (pbMF2ROM) { memset(pbMF2ROM+8192, 0, 8192); // clear the MF2's RAM area } for (int n = 0; n < 4; n++) { // initialize active read/write bank configuration membank_read[n] = membank_config[0][n]; membank_write[n] = membank_config[0][n]; } membank_read[0] = pbROMlo; // 'page in' lower ROM membank_read[3] = pbROMhi; // 'page in' upper ROM // Multiface 2 dwMF2Flags = 0; dwMF2ExitAddr = 0xffffffff; // clear MF2 return address if ((pbMF2ROM) && (pbMF2ROMbackup)) { memcpy(pbMF2ROM, pbMF2ROMbackup, 8192); // copy the MF2 ROM to its proper place } } int input_init () { CPC.InputMapper->init(); CPC.InputMapper->set_joystick_emulation(); return 0; } int emulator_init () { if (input_init()) { fprintf(stderr, "input_init() failed. Aborting.\n"); exit(-1); } // Cartridge must be loaded before init as ROM needs to be present. cartridge_load(); int iErr, iRomNum; byte *pchRomData; pbGPBuffer = new byte [128*1024]; // attempt to allocate the general purpose buffer pbRAMbuffer = new byte [CPC.ram_size*1024 + 1]; // allocate memory for desired amount of RAM // Ensure 1 byte is available before pbRAM as prerender_normal*_plus can read it pbRAM = pbRAMbuffer + 1; pbROM = new byte [32*1024]; // allocate memory for 32K of ROM pbRegisterPage = new byte [16*1024]; pbROMlo = pbROM; pbROMhi = pbExpansionROM = pbROM + 16384; memset(memmap_ROM, 0, sizeof(memmap_ROM[0]) * 256); // clear the expansion ROM map ga_init_banking(membank_config, GateArray.RAM_bank); // init the CPC memory banking map if ((iErr = emulator_patch_ROM())) { LOG_ERROR("Failed patching the ROM"); return iErr; } for (iRomNum = 0; iRomNum < 16; iRomNum++) { // loop for ROMs 0-15 if (!CPC.rom_file[iRomNum].empty()) { // is a ROM image specified for this slot? std::string rom_file = CPC.rom_file[iRomNum]; if (rom_file == "DEFAULT") { // On 464, there's no AMSDOS by default. // We still allow users to override this if they want. // More details: https://github.com/ColinPitrat/caprice32/issues/227 if (CPC.model == 0) continue; rom_file = "amsdos.rom"; } pchRomData = new byte [16384]; // allocate 16K memset(pchRomData, 0, 16384); // clear memory std::string romFilename = CPC.rom_path + "/" + rom_file; if ((pfileObject = fopen(romFilename.c_str(), "rb")) != nullptr) { // attempt to open the ROM image if(fread(pchRomData, 128, 1, pfileObject) != 1) { // read 128 bytes of ROM data fclose(pfileObject); return ERR_NOT_A_CPC_ROM; } word checksum = 0; for (int n = 0; n < 0x43; n++) { checksum += pchRomData[n]; } // Check for Graduate Software ROM structure termination with $ in the header word gradcheck = 0; for (int n = 0; n < 0x43; n++) { if(pchRomData[n]==0x24) { gradcheck = 1; } } if((pchRomData[0x38]==0xc9) && (gradcheck==1)) { // extra validation step ensure 0x38 has 0xc9 if a $ terminated string was in the header gradcheck = 1; } else { gradcheck = 0; // reset flag is there was a $ was found, but offset 0x38 wasn't 0xc9 } // end of Graduate accessory ROM checks if (checksum == ((pchRomData[0x43] << 8) + pchRomData[0x44])) { // if the checksum matches, we got us an AMSDOS header if(fread(pchRomData, 128, 1, pfileObject) != 1) { // skip it fclose(pfileObject); return ERR_NOT_A_CPC_ROM; } } if (!(pchRomData[0] & 0xfc)) { // is it a valid CPC ROM image (0 = forground, 1 = background, 2 = extension)? if(fread(pchRomData+128, 16384-128, 1, pfileObject) != 1) { // read the rest of the ROM file fclose(pfileObject); return ERR_NOT_A_CPC_ROM; } memmap_ROM[iRomNum] = pchRomData; // update the ROM map } else if ((pchRomData[0] == 0x47) && (gradcheck==1)) { // Is it a Graduate CPM Accessory Rom? (ID="G") // Graduate Software Accessory Roms use a non standard format. Only the first byte is validated, and as long as // it's a "G" and terminated with a "$" it'll try to use it. // See https://www.cpcwiki.eu/index.php/Graduate_Software#Structure_of_a_utility_ROM for more details. if(fread(pchRomData+128, 16384-128, 1, pfileObject) != 1) { // read the rest of the ROM file fclose(pfileObject); return ERR_NOT_A_CPC_ROM; } memmap_ROM[iRomNum] = pchRomData; // update the ROM map } else { // not a valid ROM file fprintf(stderr, "ERROR: %s is not a CPC ROM file - clearing ROM slot %d.\n", rom_file.c_str(), iRomNum); delete [] pchRomData; // free memory on error CPC.rom_file[iRomNum] = ""; } fclose(pfileObject); } else { // file not found fprintf(stderr, "ERROR: The %s file is missing - clearing ROM slot %d.\n", rom_file.c_str(), iRomNum); delete [] pchRomData; // free memory on error CPC.rom_file[iRomNum] = ""; } } } if (CPC.mf2) { // Multiface 2 enabled? if (!pbMF2ROM) { pbMF2ROM = new byte [16384]; // allocate the space needed for the Multiface 2: 8K ROM + 8K RAM pbMF2ROMbackup = new byte [8192]; // allocate the space needed for the backup of the MF2 ROM memset(pbMF2ROM, 0, 16384); // clear memory std::string romFilename = CPC.rom_path + "/" + CPC.rom_mf2; bool MF2error = false; if ((pfileObject = fopen(romFilename.c_str(), "rb")) != nullptr) { // attempt to open the ROM image if((fread(pbMF2ROMbackup, 8192, 1, pfileObject) != 1) || (memcmp(pbMF2ROMbackup+0x0d32, "MULTIFACE 2", 11) != 0)) { // does it have the required signature? fprintf(stderr, "ERROR: The file selected as the MF2 ROM is either corrupt or invalid.\n"); MF2error = true; } fclose(pfileObject); } else { // error opening file fprintf(stderr, "ERROR: The file selected as the MF2 ROM (%s) couldn't be opened.\n", romFilename.c_str()); MF2error = true; } if(MF2error) { delete [] pbMF2ROMbackup; delete [] pbMF2ROM; pbMF2ROM = nullptr; pbMF2ROMbackup = nullptr; CPC.rom_mf2 = ""; CPC.mf2 = 0; // disable MF2 support } } } emulator_reset(); CPC.paused = false; return 0; } void emulator_shutdown () { int iRomNum; delete [] pbMF2ROMbackup; delete [] pbMF2ROM; pbMF2ROM = nullptr; pbMF2ROMbackup = nullptr; for (iRomNum = 2; iRomNum < 16; iRomNum++) // loop for ROMs 2-15 { if (memmap_ROM[iRomNum] != nullptr) // was a ROM assigned to this slot? delete [] memmap_ROM[iRomNum]; // if so, release the associated memory } delete [] pbROM; delete [] pbRAMbuffer; delete [] pbGPBuffer; } void bin_load (const std::string& filename, const size_t offset) { LOG_INFO("Load " << filename << " in memory at offset 0x" << std::hex << offset); FILE *file; if ((file = fopen(filename.c_str(), "rb")) == nullptr) { LOG_ERROR("File not found: " << filename); return; } auto closure = [&]() { fclose(file); }; memutils::scope_exit<decltype(closure)> cs(closure); // TODO: when C++20, can become a one liner expression. size_t ram_size = 0XFFFF; // TODO: Find a way to have the real RAM size size_t max_size = ram_size - offset; size_t read = fread(&pbRAM[offset], 1, max_size, file); if (!feof(file)) { LOG_ERROR("Bin file too big to fit in memory"); return; } if (ferror(file)) { LOG_ERROR("Error reading the bin file: " << ferror(file)); return; } if (read == 0) { LOG_ERROR("Empty bin file"); return; } // Jump at the beginning of the program z80.PC.w.l = offset; // Setup the stack the way it would be if we had launch it with run" z80_write_mem(--z80.SP.w.l, 0x0); z80_write_mem(--z80.SP.w.l, 0x98); z80_write_mem(--z80.SP.w.l, 0x7f); z80_write_mem(--z80.SP.w.l, 0x89); z80_write_mem(--z80.SP.w.l, 0xb9); z80_write_mem(--z80.SP.w.l, 0xa2); } int printer_start () { if (!pfoPrinter) { if(!(pfoPrinter = fopen(CPC.printer_file.c_str(), "wb"))) { return 0; // failed to open/create file } } return 1; // ready to capture printer output } void printer_stop () { if (pfoPrinter) { fclose(pfoPrinter); } pfoPrinter = nullptr; } void audio_update (void *userdata __attribute__((unused)), byte *stream, int len) { memcpy(stream, pbSndBuffer.get(), len); dwSndBufferCopied = 1; } int audio_align_samples (int given) { int actual = 1; while (actual < given) { actual <<= 1; } return actual; // return the closest match as 2^n } int audio_init () { SDL_AudioSpec desired, obtained; if (!CPC.snd_enabled) { return 0; } desired.freq = freq_table[CPC.snd_playback_rate]; desired.format = CPC.snd_bits ? AUDIO_S16LSB : AUDIO_S8; desired.channels = CPC.snd_stereo+1; desired.samples = audio_align_samples(desired.freq * FRAME_PERIOD_MS / 1000); desired.callback = audio_update; desired.userdata = nullptr; for (int i = 0; i < SDL_GetNumAudioDevices(0); i++) { LOG_VERBOSE("Audio: device " << i << ": " << SDL_GetAudioDeviceName(i, 0)); } audio_device_id = SDL_OpenAudioDevice(nullptr, 0, &desired, &obtained, 0 /* no change allowed */); if (audio_device_id == 0) { LOG_ERROR("Could not open audio: " << SDL_GetError()); return 1; } SDL_PauseAudioDevice(audio_device_id, 0); LOG_VERBOSE("Audio: Desired: Freq: " << desired.freq << ", Format: " << desired.format << ", Channels: " << desired.channels << ", Samples: " << desired.samples); LOG_VERBOSE("Audio: Obtained: Freq: " << obtained.freq << ", Format: " << obtained.format << ", Channels: " << obtained.channels << ", Samples: " << obtained.samples); CPC.snd_buffersize = obtained.size; // size is samples * channels * bytes per sample (1 or 2) pbSndBuffer = std::make_unique<byte[]>(CPC.snd_buffersize); // allocate the sound data buffer pbSndBufferEnd = pbSndBuffer.get() + CPC.snd_buffersize; memset(pbSndBuffer.get(), 0, CPC.snd_buffersize); CPC.snd_bufferptr = pbSndBuffer.get(); // init write cursor InitAY(); for (int n = 0; n < 16; n++) { SetAYRegister(n, PSG.RegisterAY.Index[n]); // init sound emulation with valid values } return 0; } void audio_shutdown () { SDL_CloseAudioDevice(audio_device_id); audio_device_id = 0; } void audio_pause () { if (CPC.snd_enabled) { SDL_PauseAudio(1); } } void audio_resume () { if (CPC.snd_enabled) { SDL_PauseAudio(0); } } void cpc_pause() { audio_pause(); CPC.paused = true; } void cpc_resume() { CPC.paused = false; audio_resume(); } int video_set_palette () { if (!CPC.scr_tube) { for (int n = 0; n < 32; n++) { dword red = static_cast<dword>(colours_rgb[n][0] * (CPC.scr_intensity / 10.0) * 255); if (red > 255) { // limit to the maximum red = 255; } dword green = static_cast<dword>(colours_rgb[n][1] * (CPC.scr_intensity / 10.0) * 255); if (green > 255) { green = 255; } dword blue = static_cast<dword>(colours_rgb[n][2] * (CPC.scr_intensity / 10.0) * 255); if (blue > 255) { blue = 255; } colours[n].r = red; colours[n].g = green; colours[n].b = blue; } } else { for (int n = 0; n < 32; n++) { double *colours_green = video_get_green_palette(CPC.scr_green_mode); dword green = static_cast<dword>(colours_green[n] * (CPC.scr_intensity / 10.0) * 255); if (green > 255) { green = 255; } dword blue = static_cast<dword>(0.01 * CPC.scr_green_blue_percent * colours_green[n] * (CPC.scr_intensity / 10.0) * 255); // unlikely, but we care though if (blue > 255) { blue = 255; } colours[n].r = 0; colours[n].g = green; colours[n].b = blue; } } vid_plugin->set_palette(colours); for (int n = 0; n < 17; n++) { // loop for all colours + border int i=GateArray.ink_values[n]; GateArray.palette[n] = SDL_MapRGB(back_surface->format,colours[i].r,colours[i].g,colours[i].b); } return 0; } void video_set_style () { if (vid_plugin->half_pixels) { dwXScale = 1; dwYScale = 1; } else { dwXScale = 2; dwYScale = 2; } CPC.dwYScale = dwYScale; switch (dwXScale) { case 1: if (CPC.model > 2) { CPC.scr_prerendernorm = prerender_normal_half_plus; } else { CPC.scr_prerendernorm = prerender_normal_half; } CPC.scr_prerenderbord = prerender_border_half; CPC.scr_prerendersync = prerender_sync_half; break; case 2: if (CPC.model > 2) { CPC.scr_prerendernorm = prerender_normal_plus; } else { CPC.scr_prerendernorm = prerender_normal; } CPC.scr_prerenderbord = prerender_border; CPC.scr_prerendersync = prerender_sync; break; } switch(CPC.scr_bpp) { case 32: switch(dwYScale) { case 1: CPC.scr_render = render32bpp; break; case 2: CPC.scr_render = render32bpp_doubleY; break; } break; case 24: switch(dwYScale) { case 1: CPC.scr_render = render24bpp; break; case 2: CPC.scr_render = render24bpp_doubleY; break; } break; case 16: case 15: switch(dwYScale) { case 1: CPC.scr_render = render16bpp; break; case 2: CPC.scr_render = render16bpp_doubleY; break; } break; case 8: switch(dwYScale) { case 1: CPC.scr_render = render8bpp; break; case 2: CPC.scr_render = render8bpp_doubleY; break; } break; } } void mouse_init () { // hide the mouse cursor unless we emulate phazer ShowCursor(CPC.phazer_emulation); } int video_init () { vid_plugin=&video_plugin_list[CPC.scr_style]; LOG_DEBUG("video_init: vid_plugin = " << vid_plugin->name) back_surface=vid_plugin->init(vid_plugin, CPC.scr_scale, CPC.scr_window==0); if (!back_surface) { // attempt to set the required video mode LOG_ERROR("Could not set requested video mode: " << SDL_GetError()); return ERR_VIDEO_SET_MODE; } CPC.scr_bpp = back_surface->format->BitsPerPixel; // bit depth of the surface video_set_style(); // select rendering style int iErrCode = video_set_palette(); // init CPC colours if (iErrCode) { return iErrCode; } CPC.scr_bps = back_surface->pitch; // rendered screen line length in bytes CPC.scr_line_offs = CPC.scr_bps * dwYScale; CPC.scr_pos = CPC.scr_base = static_cast<byte *>(back_surface->pixels); // memory address of back buffer CPC.scr_gui_is_currently_on = false; crtc_init(); return 0; } void video_shutdown () { vid_plugin->close(); } void video_display () { vid_plugin->flip(vid_plugin); } int joysticks_init () { if(CPC.joysticks == 0) { return 0; } if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Failed to initialize joystick subsystem. Error: %s\n", SDL_GetError()); return ERR_JOYSTICKS_INIT; } int nbJoysticks = SDL_NumJoysticks(); if (nbJoysticks < 0) { fprintf(stderr, "Failed to count joysticks. Error: %s\n", SDL_GetError()); return ERR_JOYSTICKS_INIT; } if (nbJoysticks == 0) { fprintf(stderr, "No joystick found.\n"); return ERR_JOYSTICKS_INIT; } if (SDL_JoystickEventState(SDL_ENABLE) != 1) { fprintf(stderr, "Failed to activate joystick events. Error: %s\n", SDL_GetError()); return ERR_JOYSTICKS_INIT; } if(nbJoysticks > MAX_NB_JOYSTICKS) { nbJoysticks = MAX_NB_JOYSTICKS; } for(int i = 0; i < MAX_NB_JOYSTICKS; i++) { if(i < nbJoysticks) { joysticks[i] = SDL_JoystickOpen(i); if(joysticks[i] == nullptr) { fprintf(stderr, "Failed to open joystick %d. Error: %s\n", i, SDL_GetError()); //return ERR_JOYSTICKS_INIT; } } else { joysticks[i] = nullptr; } } return 0; } void joysticks_shutdown () { /* This cores for an unknown reason - anyway, SDL_QuitSubSystem will do the job for(int i = 0; i < MAX_NB_JOYSTICKS; i++) { if(joysticks[i] != nullptr) { SDL_JoystickClose(joysticks[i]); } } */ SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } void update_timings() { dwTicksOffset = static_cast<int>(FRAME_PERIOD_MS / (CPC.speed/CPC_BASE_FREQUENCY_MHZ)); dwTicksTarget = SDL_GetTicks(); dwTicksTargetFPS = dwTicksTarget; dwTicksTarget += dwTicksOffset; // These are only used for frames timing if sound is disabled. Otherwise timing is controlled by the PSG. LOG_VERBOSE("Timing: First frame at " << dwTicksTargetFPS << " - next frame in " << dwTicksOffset << " ( " << FRAME_PERIOD_MS << "/(" << CPC.speed << "/" << CPC_BASE_FREQUENCY_MHZ << ") ) at " << dwTicksTarget); } // Recalculate emulation speed (to verify, seems to work reasonably well) void update_cpc_speed() { update_timings(); InitAY(); } std::string getConfigurationFilename(bool forWrite) { int mode = R_OK | ( F_OK * forWrite ); const char* PATH_OK = ""; std::vector<std::pair<const char*, std::string>> configPaths = { { PATH_OK, args.cfgFilePath}, // First look in any user supplied configuration file path { chAppPath, "/cap32.cfg" }, // If not found, cap32.cfg in the same directory as the executable { getenv("XDG_CONFIG_HOME"), "/cap32.cfg" }, { getenv("HOME"), "/.config/cap32.cfg" }, { getenv("HOME"), "/.cap32.cfg" }, { DESTDIR, "/etc/cap32.cfg" }, { binPath.string().c_str(), "/../Resources/cap32.cfg" }, // To find the configuration from the bundle on MacOS }; for(const auto& p: configPaths){ // Skip paths using getenv if it returned NULL (i.e environment variable not defined) if (!p.first) continue; std::string s = std::string(p.first) + p.second; if (access(s.c_str(), mode) == 0) { std::cout << "Using configuration file" << (forWrite ? " to save" : "") << ": " << s << std::endl; // Dirty hack for MacOS Bundle to work: change dir to the bin dir // cap32.cfg is edited to have relative paths from the bin dir if (p.second == "/../Resources/cap32.cfg") { std::filesystem::current_path(binPath); } return s; } } std::cout << "No valid configuration file found, using empty config." << std::endl; return ""; } void loadConfiguration (t_CPC &CPC, const std::string& configFilename) { config::Config conf; conf.parseFile(configFilename); conf.setOverrides(args.cfgOverrides); std::string appPath = chAppPath; CPC.model = conf.getIntValue("system", "model", 2); // CPC 6128 if (CPC.model > 3) { CPC.model = 2; } CPC.jumpers = conf.getIntValue("system", "jumpers", 0x1e) & 0x1e; // OEM is Amstrad, video refresh is 50Hz CPC.ram_size = conf.getIntValue("system", "ram_size", 128) & 0x02c0; // 128KB RAM if (CPC.ram_size > 576) { CPC.ram_size = 576; } else if ((CPC.model >= 2) && (CPC.ram_size < 128)) { CPC.ram_size = 128; // minimum RAM size for CPC 6128 is 128KB } CPC.speed = conf.getIntValue("system", "speed", DEF_SPEED_SETTING); // original CPC speed if ((CPC.speed < MIN_SPEED_SETTING) || (CPC.speed > MAX_SPEED_SETTING)) { CPC.speed = DEF_SPEED_SETTING; } CPC.limit_speed = conf.getIntValue("system", "limit_speed", 1) & 1; CPC.auto_pause = conf.getIntValue("system", "auto_pause", 1) & 1; CPC.boot_time = conf.getIntValue("system", "boot_time", 5); CPC.printer = conf.getIntValue("system", "printer", 0) & 1; CPC.mf2 = conf.getIntValue("system", "mf2", 0) & 1; CPC.keyboard = conf.getIntValue("system", "keyboard", 0); if (CPC.keyboard > MAX_ROM_MODS) { CPC.keyboard = 0; } CPC.joystick_emulation = conf.getIntValue("system", "joystick_emulation", 0) & 1; CPC.joysticks = conf.getIntValue("system", "joysticks", 1) & 1; CPC.joystick_menu_button = conf.getIntValue("system", "joystick_menu_button", 9) - 1; CPC.joystick_vkeyboard_button = conf.getIntValue("system", "joystick_vkeyboard_button", 10) - 1; CPC.resources_path = conf.getStringValue("system", "resources_path", appPath + "/resources"); CPC.devtools_scale = conf.getIntValue("devtools", "scale", 1); CPC.scr_scale = conf.getIntValue("video", "scr_scale", 2); CPC.scr_preserve_aspect_ratio = conf.getIntValue("video", "scr_preserve_aspect_ratio", 1); CPC.scr_style = conf.getIntValue("video", "scr_style", 1); if (CPC.scr_style >= video_plugin_list.size()) { CPC.scr_style = DEFAULT_VIDEO_PLUGIN; LOG_ERROR("Unsupported video plugin specified - defaulting to plugin " << video_plugin_list[DEFAULT_VIDEO_PLUGIN].name); } CPC.scr_oglfilter = conf.getIntValue("video", "scr_oglfilter", 1) & 1; CPC.scr_oglscanlines = conf.getIntValue("video", "scr_oglscanlines", 30); if (CPC.scr_oglscanlines > 100) { CPC.scr_oglscanlines = 30; } CPC.scr_led = conf.getIntValue("video", "scr_led", 1) & 1; CPC.scr_fps = conf.getIntValue("video", "scr_fps", 0) & 1; CPC.scr_tube = conf.getIntValue("video", "scr_tube", 0) & 1; CPC.scr_intensity = conf.getIntValue("video", "scr_intensity", 10); CPC.scr_remanency = conf.getIntValue("video", "scr_remanency", 0) & 1; if ((CPC.scr_intensity < 5) || (CPC.scr_intensity > 15)) { CPC.scr_intensity = 10; } CPC.scr_window = conf.getIntValue("video", "scr_window", 1) & 1; CPC.scr_green_mode = conf.getIntValue("video", "scr_green_mode", 0) & 1; CPC.scr_green_blue_percent = conf.getIntValue("video", "scr_green_blue_percent", 0); CPC.snd_enabled = conf.getIntValue("sound", "enabled", 1) & 1; CPC.snd_playback_rate = conf.getIntValue("sound", "playback_rate", 2); if (CPC.snd_playback_rate > (MAX_FREQ_ENTRIES-1)) { CPC.snd_playback_rate = 2; } CPC.snd_bits = conf.getIntValue("sound", "bits", 1) & 1; CPC.snd_stereo = conf.getIntValue("sound", "stereo", 1) & 1; CPC.snd_volume = conf.getIntValue("sound", "volume", 80); if (CPC.snd_volume > 100) { CPC.snd_volume = 80; } CPC.snd_pp_device = conf.getIntValue("sound", "pp_device", 0) & 1; CPC.kbd_layout = conf.getStringValue("control", "kbd_layout", "keymap_us.map"); CPC.max_tracksize = conf.getIntValue("file", "max_track_size", 6144-154); CPC.current_snap_path = CPC.snap_path = conf.getStringValue("file", "snap_path", appPath + "/snap/"); CPC.current_cart_path = CPC.cart_path = conf.getStringValue("file", "cart_path", appPath + "/cart/"); CPC.current_dsk_path = CPC.dsk_path = conf.getStringValue("file", "dsk_path", appPath + "/disk/"); CPC.current_tape_path = CPC.tape_path = conf.getStringValue("file", "tape_path", appPath + "/tape/"); int iFmt = FIRST_CUSTOM_DISK_FORMAT; for (int i = iFmt; i < MAX_DISK_FORMAT; i++) { // loop through all user definable disk formats char chFmtId[14]; sprintf(chFmtId, "fmt%02d", i); // build format ID std::string formatString = conf.getStringValue("file", chFmtId, ""); disk_format[iFmt] = parseDiskFormat(formatString); if (!disk_format[iFmt].label.empty()) { // found format definition for this slot? iFmt++; // entry is valid } } CPC.printer_file = conf.getStringValue("file", "printer_file", appPath + "/printer.dat"); CPC.sdump_dir = conf.getStringValue("file", "sdump_dir", appPath + "/screenshots"); CPC.rom_path = conf.getStringValue("rom", "rom_path", appPath + "/rom/"); for (int iRomNum = 0; iRomNum < 16; iRomNum++) { // loop for ROMs 0-15 char chRomId[14]; sprintf(chRomId, "slot%02d", iRomNum); // build ROM ID CPC.rom_file[iRomNum] = conf.getStringValue("rom", chRomId, ""); } CPC.rom_mf2 = conf.getStringValue("rom", "rom_mf2", ""); CPC.cart_file = CPC.rom_path + "/system.cpr"; // Only default path defined. Needed for CPC6128+ } bool saveConfiguration (t_CPC &CPC, const std::string& configFilename) { config::Config conf; conf.setIntValue("system", "model", CPC.model); conf.setIntValue("system", "jumpers", CPC.jumpers); conf.setIntValue("system", "ram_size", CPC.ram_size); // 128KB RAM conf.setIntValue("system", "limit_speed", CPC.limit_speed); conf.setIntValue("system", "speed", CPC.speed); // original CPC speed conf.setIntValue("system", "auto_pause", CPC.auto_pause); conf.setIntValue("system", "printer", CPC.printer); conf.setIntValue("system", "mf2", CPC.mf2); conf.setIntValue("system", "keyboard", CPC.keyboard); conf.setIntValue("system", "boot_time", CPC.boot_time); conf.setIntValue("system", "joystick_emulation", CPC.joystick_emulation); conf.setIntValue("system", "joysticks", CPC.joysticks); conf.setIntValue("system", "joystick_menu_button", CPC.joystick_menu_button + 1); conf.setIntValue("system", "joystick_vkeyboard_button", CPC.joystick_vkeyboard_button + 1); conf.setStringValue("system", "resources_path", CPC.resources_path); conf.setIntValue("video", "scr_scale", CPC.scr_scale); conf.setIntValue("video", "scr_preserve_aspect_ratio", CPC.scr_preserve_aspect_ratio); conf.setIntValue("video", "scr_style", CPC.scr_style); conf.setIntValue("video", "scr_oglfilter", CPC.scr_oglfilter); conf.setIntValue("video", "scr_oglscanlines", CPC.scr_oglscanlines); conf.setIntValue("video", "scr_led", CPC.scr_led); conf.setIntValue("video", "scr_fps", CPC.scr_fps); conf.setIntValue("video", "scr_tube", CPC.scr_tube); conf.setIntValue("video", "scr_intensity", CPC.scr_intensity); conf.setIntValue("video", "scr_remanency", CPC.scr_remanency); conf.setIntValue("video", "scr_window", CPC.scr_window); conf.setIntValue("devtools", "scale", CPC.devtools_scale); conf.setIntValue("video", "scr_green_mode", CPC.scr_green_mode); conf.setIntValue("video", "scr_green_blue_percent", CPC.scr_green_blue_percent); conf.setIntValue("sound", "enabled", CPC.snd_enabled); conf.setIntValue("sound", "playback_rate", CPC.snd_playback_rate); conf.setIntValue("sound", "bits", CPC.snd_bits); conf.setIntValue("sound", "stereo", CPC.snd_stereo); conf.setIntValue("sound", "volume", CPC.snd_volume); conf.setIntValue("sound", "pp_device", CPC.snd_pp_device); conf.setStringValue("control", "kbd_layout", CPC.kbd_layout); conf.setIntValue("file", "max_track_size", CPC.max_tracksize); conf.setStringValue("file", "snap_path", CPC.snap_path); conf.setStringValue("file", "cart_path", CPC.cart_path); conf.setStringValue("file", "dsk_path", CPC.dsk_path); conf.setStringValue("file", "tape_path", CPC.tape_path); for (int iFmt = FIRST_CUSTOM_DISK_FORMAT; iFmt < MAX_DISK_FORMAT; iFmt++) { // loop through all user definable disk formats char chFmtId[14]; sprintf(chFmtId, "fmt%02d", iFmt); // build format ID conf.setStringValue("file", chFmtId, serializeDiskFormat(disk_format[iFmt])); } conf.setStringValue("file", "printer_file", CPC.printer_file); conf.setStringValue("file", "sdump_dir", CPC.sdump_dir); conf.setStringValue("rom", "rom_path", CPC.rom_path); for (int iRomNum = 0; iRomNum < 16; iRomNum++) { // loop for ROMs 0-15 char chRomId[14]; sprintf(chRomId, "slot%02d", iRomNum); // build ROM ID conf.setStringValue("rom", chRomId, CPC.rom_file[iRomNum]); } conf.setStringValue("rom", "rom_mf2", CPC.rom_mf2); return conf.saveToFile(configFilename); } // As long as a GUI is enabled, we must show the cursor. // Because we can activate multiple GUIs at a time, we need to keep track of how // many times we've been asked to show or hide cursor. void ShowCursor(bool show) { static int shows_count = 1; if (show) { shows_count++; } else { shows_count--; } if (shows_count < 0) shows_count = 0; if (shows_count > 0) { SDL_ShowCursor(SDL_ENABLE); } else { SDL_ShowCursor(SDL_DISABLE); } } SDL_Surface* prepareShowUI() { audio_pause(); CPC.scr_gui_is_currently_on = true; ShowCursor(true); // guiBackSurface will allow the GUI to capture the current frame SDL_Surface* guiBackSurface(SDL_CreateRGBSurface(0, back_surface->w, back_surface->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000)); SDL_BlitSurface(back_surface, nullptr, guiBackSurface, nullptr); return guiBackSurface; } void cleanupShowUI(SDL_Surface* guiBackSurface) { SDL_FreeSurface(guiBackSurface); // Clear SDL surface: SDL_FillRect(back_surface, nullptr, SDL_MapRGB(back_surface->format, 0, 0, 0)); ShowCursor(false); CPC.scr_gui_is_currently_on = false; audio_resume(); } bool userConfirmsQuitWithoutSaving() { auto guiBackSurface = prepareShowUI(); bool confirmed = false; // Show warning try { CapriceGui capriceGui(mainSDLWindow, /*bInMainView=*/true); capriceGui.Init(); CapriceLeavingWithoutSavingView capriceLeavingWarning(capriceGui, back_surface, guiBackSurface, CRect(0, 0, back_surface->w, back_surface->h)); capriceGui.Exec(); confirmed = capriceLeavingWarning.Confirmed(); } catch(wGui::Wg_Ex_App& e) { // TODO: improve: this is pretty silent if people don't look at the console std::cout << "Failed displaying the leaving without saving dialog: " << e.what() << std::endl; } cleanupShowUI(guiBackSurface); return confirmed; } void showVKeyboard() { auto guiBackSurface = prepareShowUI(); // Activate virtual keyboard try { CapriceGui capriceGui(mainSDLWindow, /*bInMainView=*/true); capriceGui.Init(); CapriceVKeyboardView capriceVKeyboardView(capriceGui, back_surface, guiBackSurface, CRect(0, 0, back_surface->w, back_surface->h)); capriceGui.Exec(); auto newEvents = capriceVKeyboardView.GetEvents(); virtualKeyboardEvents.splice(virtualKeyboardEvents.end(), newEvents); nextVirtualEventFrameCount = dwFrameCountOverall; } catch(wGui::Wg_Ex_App& e) { // TODO: improve: this is pretty silent if people don't look at the console std::cout << "Failed displaying the virtual keyboard: " << e.what() << std::endl; } cleanupShowUI(guiBackSurface); } void showGui() { auto guiBackSurface = prepareShowUI(); try { CapriceGui capriceGui(mainSDLWindow, /*bInMainView=*/true); capriceGui.Init(); CapriceGuiView capriceGuiView(capriceGui, back_surface, guiBackSurface, CRect(0, 0, back_surface->w, back_surface->h)); capriceGui.Exec(); // TODO: Something like that to replace Exec and allow DevTools to be used // while Menu is displayed. /* while (capriceGui.IsRunning()) { SDL_Event event; while (SDL_PollEvent(&event)) { if (devtools.IsActive() && devtools.PassEvent(event)) { continue; } capriceGui->ProcessEvent(event, &capriceGuiView); } if (devtools.IsActive()) { devtools.Update(); } capriceGui->Update(&capriceGuiView); SDL_Delay(5); } */ } catch(wGui::Wg_Ex_App& e) { // TODO: improve: this is pretty silent if people don't look at the console std::cout << "Failed displaying the GUI: " << e.what() << std::endl; } cleanupShowUI(guiBackSurface); } // TODO: Dedupe with the version in CapriceDevTools // TODO: Support watchpoints too void loadBreakpoints() { if (args.symFilePath.empty()) return; Symfile symfile(args.symFilePath); for (auto breakpoint : symfile.Breakpoints()) { if (std::find_if(breakpoints.begin(), breakpoints.end(), [&](const auto& bp) { return bp.address == breakpoint; } ) != breakpoints.end()) continue; breakpoints.emplace_back(breakpoint); } } bool showDevTools() { Uint32 flags = SDL_GetWindowFlags(mainSDLWindow); // DevTools don't behave very well in fullscreen mode, so just disallow it // It's still possible to use it in fullscreen with multiscreen by starting it // when in windowed mode, moving the window on a different screen and // switching to fullscreen after. if ((flags & SDL_WINDOW_FULLSCREEN) || (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)) { set_osd_message("Dev tools not available in fullscreen"); return false; } devtools.emplace_back(); if (!devtools.back().Activate(CPC.devtools_scale)) { LOG_ERROR("Failed to activate developers tools"); } if (!args.symFilePath.empty()) devtools.back().LoadSymbols(args.symFilePath); return true; } void dumpScreen() { std::string dir = CPC.sdump_dir; if (!is_directory(dir)) { LOG_ERROR("Unable to find or open directory " + CPC.sdump_dir + " when trying to take a screenshot. Defaulting to current directory.") dir = "."; } std::string dumpFile = "screenshot_" + getDateString() + ".png"; std::string dumpPath = dir + "/" + dumpFile; LOG_INFO("Dumping screen to " + dumpPath); if (SDL_SavePNG(back_surface, dumpPath)) { LOG_ERROR("Could not write screenshot file to " + dumpPath); } else { set_osd_message("Captured " + dumpFile); } } // Very similar to screenshot, but difficult to factorize :-) void dumpSnapshot() { std::string dir = CPC.snap_path; if (!is_directory(dir)) { LOG_ERROR("Unable to find or open directory " + CPC.snap_path + " when trying to take a machine snapshot. Defaulting to current directory.") dir = "."; } std::string dumpFile = "snapshot_" + getDateString() + ".sna"; std::string dumpPath = dir + "/" + dumpFile; LOG_INFO("Dumping machine snapshot to " + dumpPath); if (snapshot_save(dumpPath)) { LOG_ERROR("Could not write machine snapshot to " + dumpPath); } else { set_osd_message("Snapshotted " + dumpFile); } lastSavedSnapshot = dumpPath; } void loadSnapshot() { if (lastSavedSnapshot.empty()) return; LOG_INFO("Loading snapshot from " + lastSavedSnapshot); if (snapshot_load(lastSavedSnapshot)) { LOG_ERROR("Could not load machine snapshot from " + lastSavedSnapshot); } else { std::string dirname, filename; stringutils::splitPath(lastSavedSnapshot, dirname, filename); set_osd_message("Restored " + filename); } } bool driveAltered() { return driveA.altered || driveB.altered; } void doCleanUp () { printer_stop(); emulator_shutdown(); dsk_eject(&driveA); dsk_eject(&driveB); tape_eject(); joysticks_shutdown(); audio_shutdown(); video_shutdown(); #ifdef DEBUG if(pfoDebug) { fclose(pfoDebug); } #endif SDL_Quit(); } void cleanExit(int returnCode, bool askIfUnsaved) { if (askIfUnsaved && driveAltered() && !userConfirmsQuitWithoutSaving()) { return; } for (auto& devtool : devtools) { devtool.Deactivate(); } doCleanUp(); exit(returnCode); } // TODO(SDL2): Remove these 2 maps once not needed to debug keymaps anymore #include <map> std::map<SDL_Keycode, std::string> keycode_names = { {SDLK_UNKNOWN, "SDLK_UNKNOWN"}, {SDLK_RETURN, "SDLK_RETURN"}, {SDLK_ESCAPE, "SDLK_ESCAPE"}, {SDLK_BACKSPACE, "SDLK_BACKSPACE"}, {SDLK_TAB, "SDLK_TAB"}, {SDLK_SPACE, "SDLK_SPACE"}, {SDLK_EXCLAIM, "SDLK_EXCLAIM"}, {SDLK_QUOTEDBL, "SDLK_QUOTEDBL"}, {SDLK_HASH, "SDLK_HASH"}, {SDLK_PERCENT, "SDLK_PERCENT"}, {SDLK_DOLLAR, "SDLK_DOLLAR"}, {SDLK_AMPERSAND, "SDLK_AMPERSAND"}, {SDLK_QUOTE, "SDLK_QUOTE"}, {SDLK_LEFTPAREN, "SDLK_LEFTPAREN"}, {SDLK_RIGHTPAREN, "SDLK_RIGHTPAREN"}, {SDLK_ASTERISK, "SDLK_ASTERISK"}, {SDLK_PLUS, "SDLK_PLUS"}, {SDLK_COMMA, "SDLK_COMMA"}, {SDLK_MINUS, "SDLK_MINUS"}, {SDLK_PERIOD, "SDLK_PERIOD"}, {SDLK_SLASH, "SDLK_SLASH"}, {SDLK_0, "SDLK_0"}, {SDLK_1, "SDLK_1"}, {SDLK_2, "SDLK_2"}, {SDLK_3, "SDLK_3"}, {SDLK_4, "SDLK_4"}, {SDLK_5, "SDLK_5"}, {SDLK_6, "SDLK_6"}, {SDLK_7, "SDLK_7"}, {SDLK_8, "SDLK_8"}, {SDLK_9, "SDLK_9"}, {SDLK_COLON, "SDLK_COLON"}, {SDLK_SEMICOLON, "SDLK_SEMICOLON"}, {SDLK_LESS, "SDLK_LESS"}, {SDLK_EQUALS, "SDLK_EQUALS"}, {SDLK_GREATER, "SDLK_GREATER"}, {SDLK_QUESTION, "SDLK_QUESTION"}, {SDLK_AT, "SDLK_AT"}, {SDLK_LEFTBRACKET, "SDLK_LEFTBRACKET"}, {SDLK_BACKSLASH, "SDLK_BACKSLASH"}, {SDLK_RIGHTBRACKET, "SDLK_RIGHTBRACKET"}, {SDLK_CARET, "SDLK_CARET"}, {SDLK_UNDERSCORE, "SDLK_UNDERSCORE"}, {SDLK_BACKQUOTE, "SDLK_BACKQUOTE"}, {SDLK_a, "SDLK_a"}, {SDLK_b, "SDLK_b"}, {SDLK_c, "SDLK_c"}, {SDLK_d, "SDLK_d"}, {SDLK_e, "SDLK_e"}, {SDLK_f, "SDLK_f"}, {SDLK_g, "SDLK_g"}, {SDLK_h, "SDLK_h"}, {SDLK_i, "SDLK_i"}, {SDLK_j, "SDLK_j"}, {SDLK_k, "SDLK_k"}, {SDLK_l, "SDLK_l"}, {SDLK_m, "SDLK_m"}, {SDLK_n, "SDLK_n"}, {SDLK_o, "SDLK_o"}, {SDLK_p, "SDLK_p"}, {SDLK_q, "SDLK_q"}, {SDLK_r, "SDLK_r"}, {SDLK_s, "SDLK_s"}, {SDLK_t, "SDLK_t"}, {SDLK_u, "SDLK_u"}, {SDLK_v, "SDLK_v"}, {SDLK_w, "SDLK_w"}, {SDLK_x, "SDLK_x"}, {SDLK_y, "SDLK_y"}, {SDLK_z, "SDLK_z"}, {SDLK_CAPSLOCK, "SDLK_CAPSLOCK"}, {SDLK_F1, "SDLK_F1"}, {SDLK_F2, "SDLK_F2"}, {SDLK_F3, "SDLK_F3"}, {SDLK_F4, "SDLK_F4"}, {SDLK_F5, "SDLK_F5"}, {SDLK_F6, "SDLK_F6"}, {SDLK_F7, "SDLK_F7"}, {SDLK_F8, "SDLK_F8"}, {SDLK_F9, "SDLK_F9"}, {SDLK_F10, "SDLK_F10"}, {SDLK_F11, "SDLK_F11"}, {SDLK_F12, "SDLK_F12"}, {SDLK_PRINTSCREEN, "SDLK_PRINTSCREEN"}, {SDLK_SCROLLLOCK, "SDLK_SCROLLLOCK"}, {SDLK_PAUSE, "SDLK_PAUSE"}, {SDLK_INSERT, "SDLK_INSERT"}, {SDLK_HOME, "SDLK_HOME"}, {SDLK_PAGEUP, "SDLK_PAGEUP"}, {SDLK_DELETE, "SDLK_DELETE"}, {SDLK_END, "SDLK_END"}, {SDLK_PAGEDOWN, "SDLK_PAGEDOWN"}, {SDLK_RIGHT, "SDLK_RIGHT"}, {SDLK_LEFT, "SDLK_LEFT"}, {SDLK_DOWN, "SDLK_DOWN"}, {SDLK_UP, "SDLK_UP"}, {SDLK_NUMLOCKCLEAR, "SDLK_NUMLOCKCLEAR"}, {SDLK_KP_DIVIDE, "SDLK_KP_DIVIDE"}, {SDLK_KP_MULTIPLY, "SDLK_KP_MULTIPLY"}, {SDLK_KP_MINUS, "SDLK_KP_MINUS"}, {SDLK_KP_PLUS, "SDLK_KP_PLUS"}, {SDLK_KP_ENTER, "SDLK_KP_ENTER"}, {SDLK_KP_1, "SDLK_KP_1"}, {SDLK_KP_2, "SDLK_KP_2"}, {SDLK_KP_3, "SDLK_KP_3"}, {SDLK_KP_4, "SDLK_KP_4"}, {SDLK_KP_5, "SDLK_KP_5"}, {SDLK_KP_6, "SDLK_KP_6"}, {SDLK_KP_7, "SDLK_KP_7"}, {SDLK_KP_8, "SDLK_KP_8"}, {SDLK_KP_9, "SDLK_KP_9"}, {SDLK_KP_0, "SDLK_KP_0"}, {SDLK_KP_PERIOD, "SDLK_KP_PERIOD"}, {SDLK_APPLICATION, "SDLK_APPLICATION"}, {SDLK_POWER, "SDLK_POWER"}, {SDLK_KP_EQUALS, "SDLK_KP_EQUALS"}, {SDLK_F13, "SDLK_F13"}, {SDLK_F14, "SDLK_F14"}, {SDLK_F15, "SDLK_F15"}, {SDLK_F16, "SDLK_F16"}, {SDLK_F17, "SDLK_F17"}, {SDLK_F18, "SDLK_F18"}, {SDLK_F19, "SDLK_F19"}, {SDLK_F20, "SDLK_F20"}, {SDLK_F21, "SDLK_F21"}, {SDLK_F22, "SDLK_F22"}, {SDLK_F23, "SDLK_F23"}, {SDLK_F24, "SDLK_F24"}, {SDLK_EXECUTE, "SDLK_EXECUTE"}, {SDLK_HELP, "SDLK_HELP"}, {SDLK_MENU, "SDLK_MENU"}, {SDLK_SELECT, "SDLK_SELECT"}, {SDLK_STOP, "SDLK_STOP"}, {SDLK_AGAIN, "SDLK_AGAIN"}, {SDLK_UNDO, "SDLK_UNDO"}, {SDLK_CUT, "SDLK_CUT"}, {SDLK_COPY, "SDLK_COPY"}, {SDLK_PASTE, "SDLK_PASTE"}, {SDLK_FIND, "SDLK_FIND"}, {SDLK_MUTE, "SDLK_MUTE"}, {SDLK_VOLUMEUP, "SDLK_VOLUMEUP"}, {SDLK_VOLUMEDOWN, "SDLK_VOLUMEDOWN"}, {SDLK_KP_COMMA, "SDLK_KP_COMMA"}, {SDLK_KP_EQUALSAS400, "SDLK_KP_EQUALSAS400"}, {SDLK_ALTERASE, "SDLK_ALTERASE"}, {SDLK_SYSREQ, "SDLK_SYSREQ"}, {SDLK_CANCEL, "SDLK_CANCEL"}, {SDLK_CLEAR, "SDLK_CLEAR"}, {SDLK_PRIOR, "SDLK_PRIOR"}, {SDLK_RETURN2, "SDLK_RETURN2"}, {SDLK_SEPARATOR, "SDLK_SEPARATOR"}, {SDLK_OUT, "SDLK_OUT"}, {SDLK_OPER, "SDLK_OPER"}, {SDLK_CLEARAGAIN, "SDLK_CLEARAGAIN"}, {SDLK_CRSEL, "SDLK_CRSEL"}, {SDLK_EXSEL, "SDLK_EXSEL"}, {SDLK_KP_00, "SDLK_KP_00"}, {SDLK_KP_000, "SDLK_KP_000"}, {SDLK_THOUSANDSSEPARATOR, "SDLK_THOUSANDSSEPARATOR"}, {SDLK_DECIMALSEPARATOR, "SDLK_DECIMALSEPARATOR"}, {SDLK_CURRENCYUNIT, "SDLK_CURRENCYUNIT"}, {SDLK_CURRENCYSUBUNIT, "SDLK_CURRENCYSUBUNIT"}, {SDLK_KP_LEFTPAREN, "SDLK_KP_LEFTPAREN"}, {SDLK_KP_RIGHTPAREN, "SDLK_KP_RIGHTPAREN"}, {SDLK_KP_LEFTBRACE, "SDLK_KP_LEFTBRACE"}, {SDLK_KP_RIGHTBRACE, "SDLK_KP_RIGHTBRACE"}, {SDLK_KP_TAB, "SDLK_KP_TAB"}, {SDLK_KP_BACKSPACE, "SDLK_KP_BACKSPACE"}, {SDLK_KP_A, "SDLK_KP_A"}, {SDLK_KP_B, "SDLK_KP_B"}, {SDLK_KP_C, "SDLK_KP_C"}, {SDLK_KP_D, "SDLK_KP_D"}, {SDLK_KP_E, "SDLK_KP_E"}, {SDLK_KP_F, "SDLK_KP_F"}, {SDLK_KP_XOR, "SDLK_KP_XOR"}, {SDLK_KP_POWER, "SDLK_KP_POWER"}, {SDLK_KP_PERCENT, "SDLK_KP_PERCENT"}, {SDLK_KP_LESS, "SDLK_KP_LESS"}, {SDLK_KP_GREATER, "SDLK_KP_GREATER"}, {SDLK_KP_AMPERSAND, "SDLK_KP_AMPERSAND"}, {SDLK_KP_DBLAMPERSAND, "SDLK_KP_DBLAMPERSAND"}, {SDLK_KP_VERTICALBAR, "SDLK_KP_VERTICALBAR"}, {SDLK_KP_DBLVERTICALBAR, "SDLK_KP_DBLVERTICALBAR"}, {SDLK_KP_COLON, "SDLK_KP_COLON"}, {SDLK_KP_HASH, "SDLK_KP_HASH"}, {SDLK_KP_SPACE, "SDLK_KP_SPACE"}, {SDLK_KP_AT, "SDLK_KP_AT"}, {SDLK_KP_EXCLAM, "SDLK_KP_EXCLAM"}, {SDLK_KP_MEMSTORE, "SDLK_KP_MEMSTORE"}, {SDLK_KP_MEMRECALL, "SDLK_KP_MEMRECALL"}, {SDLK_KP_MEMCLEAR, "SDLK_KP_MEMCLEAR"}, {SDLK_KP_MEMADD, "SDLK_KP_MEMADD"}, {SDLK_KP_MEMSUBTRACT, "SDLK_KP_MEMSUBTRACT"}, {SDLK_KP_MEMMULTIPLY, "SDLK_KP_MEMMULTIPLY"}, {SDLK_KP_MEMDIVIDE, "SDLK_KP_MEMDIVIDE"}, {SDLK_KP_PLUSMINUS, "SDLK_KP_PLUSMINUS"}, {SDLK_KP_CLEAR, "SDLK_KP_CLEAR"}, {SDLK_KP_CLEARENTRY, "SDLK_KP_CLEARENTRY"}, {SDLK_KP_BINARY, "SDLK_KP_BINARY"}, {SDLK_KP_OCTAL, "SDLK_KP_OCTAL"}, {SDLK_KP_DECIMAL, "SDLK_KP_DECIMAL"}, {SDLK_KP_HEXADECIMAL, "SDLK_KP_HEXADECIMAL"}, {SDLK_LCTRL, "SDLK_LCTRL"}, {SDLK_LSHIFT, "SDLK_LSHIFT"}, {SDLK_LALT, "SDLK_LALT"}, {SDLK_LGUI, "SDLK_LGUI"}, {SDLK_RCTRL, "SDLK_RCTRL"}, {SDLK_RSHIFT, "SDLK_RSHIFT"}, {SDLK_RALT, "SDLK_RALT"}, {SDLK_RGUI, "SDLK_RGUI"}, {SDLK_MODE, "SDLK_MODE"}, {SDLK_AUDIONEXT, "SDLK_AUDIONEXT"}, {SDLK_AUDIOPREV, "SDLK_AUDIOPREV"}, {SDLK_AUDIOSTOP, "SDLK_AUDIOSTOP"}, {SDLK_AUDIOPLAY, "SDLK_AUDIOPLAY"}, {SDLK_AUDIOMUTE, "SDLK_AUDIOMUTE"}, {SDLK_MEDIASELECT, "SDLK_MEDIASELECT"}, {SDLK_WWW, "SDLK_WWW"}, {SDLK_MAIL, "SDLK_MAIL"}, {SDLK_CALCULATOR, "SDLK_CALCULATOR"}, {SDLK_COMPUTER, "SDLK_COMPUTER"}, {SDLK_AC_SEARCH, "SDLK_AC_SEARCH"}, {SDLK_AC_HOME, "SDLK_AC_HOME"}, {SDLK_AC_BACK, "SDLK_AC_BACK"}, {SDLK_AC_FORWARD, "SDLK_AC_FORWARD"}, {SDLK_AC_STOP, "SDLK_AC_STOP"}, {SDLK_AC_REFRESH, "SDLK_AC_REFRESH"}, {SDLK_AC_BOOKMARKS, "SDLK_AC_BOOKMARKS"}, {SDLK_BRIGHTNESSDOWN, "SDLK_BRIGHTNESSDOWN"}, {SDLK_BRIGHTNESSUP, "SDLK_BRIGHTNESSUP"}, {SDLK_DISPLAYSWITCH, "SDLK_DISPLAYSWITCH"}, {SDLK_KBDILLUMTOGGLE, "SDLK_KBDILLUMTOGGLE"}, {SDLK_KBDILLUMDOWN, "SDLK_KBDILLUMDOWN"}, {SDLK_KBDILLUMUP, "SDLK_KBDILLUMUP"}, {SDLK_EJECT, "SDLK_EJECT"}, {SDLK_SLEEP, "SDLK_SLEEP"}, #if SDL_VERSION_ATLEAST(2, 0, 6) {SDLK_APP1, "SDLK_APP1"}, {SDLK_APP2, "SDLK_APP2"}, {SDLK_AUDIOREWIND, "SDLK_AUDIOREWIND"}, {SDLK_AUDIOFASTFORWARD, "SDLK_AUDIOFASTFORWARD"}, #endif }; std::map<SDL_Scancode, std::string> scancode_names = { {SDL_SCANCODE_UNKNOWN, "SDL_SCANCODE_UNKNOWN"}, {SDL_SCANCODE_A, "SDL_SCANCODE_A"}, {SDL_SCANCODE_B, "SDL_SCANCODE_B"}, {SDL_SCANCODE_C, "SDL_SCANCODE_C"}, {SDL_SCANCODE_D, "SDL_SCANCODE_D"}, {SDL_SCANCODE_E, "SDL_SCANCODE_E"}, {SDL_SCANCODE_F, "SDL_SCANCODE_F"}, {SDL_SCANCODE_G, "SDL_SCANCODE_G"}, {SDL_SCANCODE_H, "SDL_SCANCODE_H"}, {SDL_SCANCODE_I, "SDL_SCANCODE_I"}, {SDL_SCANCODE_J, "SDL_SCANCODE_J"}, {SDL_SCANCODE_K, "SDL_SCANCODE_K"}, {SDL_SCANCODE_L, "SDL_SCANCODE_L"}, {SDL_SCANCODE_M, "SDL_SCANCODE_M"}, {SDL_SCANCODE_N, "SDL_SCANCODE_N"}, {SDL_SCANCODE_O, "SDL_SCANCODE_O"}, {SDL_SCANCODE_P, "SDL_SCANCODE_P"}, {SDL_SCANCODE_Q, "SDL_SCANCODE_Q"}, {SDL_SCANCODE_R, "SDL_SCANCODE_R"}, {SDL_SCANCODE_S, "SDL_SCANCODE_S"}, {SDL_SCANCODE_T, "SDL_SCANCODE_T"}, {SDL_SCANCODE_U, "SDL_SCANCODE_U"}, {SDL_SCANCODE_V, "SDL_SCANCODE_V"}, {SDL_SCANCODE_W, "SDL_SCANCODE_W"}, {SDL_SCANCODE_X, "SDL_SCANCODE_X"}, {SDL_SCANCODE_Y, "SDL_SCANCODE_Y"}, {SDL_SCANCODE_Z, "SDL_SCANCODE_Z"}, {SDL_SCANCODE_1, "SDL_SCANCODE_1"}, {SDL_SCANCODE_2, "SDL_SCANCODE_2"}, {SDL_SCANCODE_3, "SDL_SCANCODE_3"}, {SDL_SCANCODE_4, "SDL_SCANCODE_4"}, {SDL_SCANCODE_5, "SDL_SCANCODE_5"}, {SDL_SCANCODE_6, "SDL_SCANCODE_6"}, {SDL_SCANCODE_7, "SDL_SCANCODE_7"}, {SDL_SCANCODE_8, "SDL_SCANCODE_8"}, {SDL_SCANCODE_9, "SDL_SCANCODE_9"}, {SDL_SCANCODE_0, "SDL_SCANCODE_0"}, {SDL_SCANCODE_RETURN, "SDL_SCANCODE_RETURN"}, {SDL_SCANCODE_ESCAPE, "SDL_SCANCODE_ESCAPE"}, {SDL_SCANCODE_BACKSPACE, "SDL_SCANCODE_BACKSPACE"}, {SDL_SCANCODE_TAB, "SDL_SCANCODE_TAB"}, {SDL_SCANCODE_SPACE, "SDL_SCANCODE_SPACE"}, {SDL_SCANCODE_MINUS, "SDL_SCANCODE_MINUS"}, {SDL_SCANCODE_EQUALS, "SDL_SCANCODE_EQUALS"}, {SDL_SCANCODE_LEFTBRACKET, "SDL_SCANCODE_LEFTBRACKET"}, {SDL_SCANCODE_RIGHTBRACKET, "SDL_SCANCODE_RIGHTBRACKET"}, {SDL_SCANCODE_BACKSLASH, "SDL_SCANCODE_BACKSLASH"}, {SDL_SCANCODE_NONUSHASH, "SDL_SCANCODE_NONUSHASH"}, {SDL_SCANCODE_SEMICOLON, "SDL_SCANCODE_SEMICOLON"}, {SDL_SCANCODE_APOSTROPHE, "SDL_SCANCODE_APOSTROPHE"}, {SDL_SCANCODE_GRAVE, "SDL_SCANCODE_GRAVE"}, {SDL_SCANCODE_COMMA, "SDL_SCANCODE_COMMA"}, {SDL_SCANCODE_PERIOD, "SDL_SCANCODE_PERIOD"}, {SDL_SCANCODE_SLASH, "SDL_SCANCODE_SLASH"}, {SDL_SCANCODE_CAPSLOCK, "SDL_SCANCODE_CAPSLOCK"}, {SDL_SCANCODE_F1, "SDL_SCANCODE_F1"}, {SDL_SCANCODE_F2, "SDL_SCANCODE_F2"}, {SDL_SCANCODE_F3, "SDL_SCANCODE_F3"}, {SDL_SCANCODE_F4, "SDL_SCANCODE_F4"}, {SDL_SCANCODE_F5, "SDL_SCANCODE_F5"}, {SDL_SCANCODE_F6, "SDL_SCANCODE_F6"}, {SDL_SCANCODE_F7, "SDL_SCANCODE_F7"}, {SDL_SCANCODE_F8, "SDL_SCANCODE_F8"}, {SDL_SCANCODE_F9, "SDL_SCANCODE_F9"}, {SDL_SCANCODE_F10, "SDL_SCANCODE_F10"}, {SDL_SCANCODE_F11, "SDL_SCANCODE_F11"}, {SDL_SCANCODE_F12, "SDL_SCANCODE_F12"}, {SDL_SCANCODE_PRINTSCREEN, "SDL_SCANCODE_PRINTSCREEN"}, {SDL_SCANCODE_SCROLLLOCK, "SDL_SCANCODE_SCROLLLOCK"}, {SDL_SCANCODE_PAUSE, "SDL_SCANCODE_PAUSE"}, {SDL_SCANCODE_INSERT, "SDL_SCANCODE_INSERT"}, {SDL_SCANCODE_HOME, "SDL_SCANCODE_HOME"}, {SDL_SCANCODE_PAGEUP, "SDL_SCANCODE_PAGEUP"}, {SDL_SCANCODE_DELETE, "SDL_SCANCODE_DELETE"}, {SDL_SCANCODE_END, "SDL_SCANCODE_END"}, {SDL_SCANCODE_PAGEDOWN, "SDL_SCANCODE_PAGEDOWN"}, {SDL_SCANCODE_RIGHT, "SDL_SCANCODE_RIGHT"}, {SDL_SCANCODE_LEFT, "SDL_SCANCODE_LEFT"}, {SDL_SCANCODE_DOWN, "SDL_SCANCODE_DOWN"}, {SDL_SCANCODE_UP, "SDL_SCANCODE_UP"}, {SDL_SCANCODE_NUMLOCKCLEAR, "SDL_SCANCODE_NUMLOCKCLEAR"}, {SDL_SCANCODE_KP_DIVIDE, "SDL_SCANCODE_KP_DIVIDE"}, {SDL_SCANCODE_KP_MULTIPLY, "SDL_SCANCODE_KP_MULTIPLY"}, {SDL_SCANCODE_KP_MINUS, "SDL_SCANCODE_KP_MINUS"}, {SDL_SCANCODE_KP_PLUS, "SDL_SCANCODE_KP_PLUS"}, {SDL_SCANCODE_KP_ENTER, "SDL_SCANCODE_KP_ENTER"}, {SDL_SCANCODE_KP_1, "SDL_SCANCODE_KP_1"}, {SDL_SCANCODE_KP_2, "SDL_SCANCODE_KP_2"}, {SDL_SCANCODE_KP_3, "SDL_SCANCODE_KP_3"}, {SDL_SCANCODE_KP_4, "SDL_SCANCODE_KP_4"}, {SDL_SCANCODE_KP_5, "SDL_SCANCODE_KP_5"}, {SDL_SCANCODE_KP_6, "SDL_SCANCODE_KP_6"}, {SDL_SCANCODE_KP_7, "SDL_SCANCODE_KP_7"}, {SDL_SCANCODE_KP_8, "SDL_SCANCODE_KP_8"}, {SDL_SCANCODE_KP_9, "SDL_SCANCODE_KP_9"}, {SDL_SCANCODE_KP_0, "SDL_SCANCODE_KP_0"}, {SDL_SCANCODE_KP_PERIOD, "SDL_SCANCODE_KP_PERIOD"}, {SDL_SCANCODE_NONUSBACKSLASH, "SDL_SCANCODE_NONUSBACKSLASH"}, {SDL_SCANCODE_APPLICATION, "SDL_SCANCODE_APPLICATION"}, {SDL_SCANCODE_POWER, "SDL_SCANCODE_POWER"}, {SDL_SCANCODE_KP_EQUALS, "SDL_SCANCODE_KP_EQUALS"}, {SDL_SCANCODE_F13, "SDL_SCANCODE_F13"}, {SDL_SCANCODE_F14, "SDL_SCANCODE_F14"}, {SDL_SCANCODE_F15, "SDL_SCANCODE_F15"}, {SDL_SCANCODE_F16, "SDL_SCANCODE_F16"}, {SDL_SCANCODE_F17, "SDL_SCANCODE_F17"}, {SDL_SCANCODE_F18, "SDL_SCANCODE_F18"}, {SDL_SCANCODE_F19, "SDL_SCANCODE_F19"}, {SDL_SCANCODE_F20, "SDL_SCANCODE_F20"}, {SDL_SCANCODE_F21, "SDL_SCANCODE_F21"}, {SDL_SCANCODE_F22, "SDL_SCANCODE_F22"}, {SDL_SCANCODE_F23, "SDL_SCANCODE_F23"}, {SDL_SCANCODE_F24, "SDL_SCANCODE_F24"}, {SDL_SCANCODE_EXECUTE, "SDL_SCANCODE_EXECUTE"}, {SDL_SCANCODE_HELP, "SDL_SCANCODE_HELP"}, {SDL_SCANCODE_MENU, "SDL_SCANCODE_MENU"}, {SDL_SCANCODE_SELECT, "SDL_SCANCODE_SELECT"}, {SDL_SCANCODE_STOP, "SDL_SCANCODE_STOP"}, {SDL_SCANCODE_AGAIN, "SDL_SCANCODE_AGAIN"}, {SDL_SCANCODE_UNDO, "SDL_SCANCODE_UNDO"}, {SDL_SCANCODE_CUT, "SDL_SCANCODE_CUT"}, {SDL_SCANCODE_COPY, "SDL_SCANCODE_COPY"}, {SDL_SCANCODE_PASTE, "SDL_SCANCODE_PASTE"}, {SDL_SCANCODE_FIND, "SDL_SCANCODE_FIND"}, {SDL_SCANCODE_MUTE, "SDL_SCANCODE_MUTE"}, {SDL_SCANCODE_VOLUMEUP, "SDL_SCANCODE_VOLUMEUP"}, {SDL_SCANCODE_VOLUMEDOWN, "SDL_SCANCODE_VOLUMEDOWN"}, /* {SDL_SCANCODE_LOCKINGCAPSLOCK, "SDL_SCANCODE_LOCKINGCAPSLOCK"}, */ /* {SDL_SCANCODE_LOCKINGNUMLOCK, "SDL_SCANCODE_LOCKINGNUMLOCK"}, */ /* {SDL_SCANCODE_LOCKINGSCROLLLOCK, "SDL_SCANCODE_LOCKINGSCROLLLOCK"}, */ {SDL_SCANCODE_KP_COMMA, "SDL_SCANCODE_KP_COMMA"}, {SDL_SCANCODE_KP_EQUALSAS400, "SDL_SCANCODE_KP_EQUALSAS400"}, {SDL_SCANCODE_INTERNATIONAL1, "SDL_SCANCODE_INTERNATIONAL1"}, {SDL_SCANCODE_INTERNATIONAL2, "SDL_SCANCODE_INTERNATIONAL2"}, {SDL_SCANCODE_INTERNATIONAL3, "SDL_SCANCODE_INTERNATIONAL3"}, {SDL_SCANCODE_INTERNATIONAL4, "SDL_SCANCODE_INTERNATIONAL4"}, {SDL_SCANCODE_INTERNATIONAL5, "SDL_SCANCODE_INTERNATIONAL5"}, {SDL_SCANCODE_INTERNATIONAL6, "SDL_SCANCODE_INTERNATIONAL6"}, {SDL_SCANCODE_INTERNATIONAL7, "SDL_SCANCODE_INTERNATIONAL7"}, {SDL_SCANCODE_INTERNATIONAL8, "SDL_SCANCODE_INTERNATIONAL8"}, {SDL_SCANCODE_INTERNATIONAL9, "SDL_SCANCODE_INTERNATIONAL9"}, {SDL_SCANCODE_LANG1, "SDL_SCANCODE_LANG1"}, {SDL_SCANCODE_LANG2, "SDL_SCANCODE_LANG2"}, {SDL_SCANCODE_LANG3, "SDL_SCANCODE_LANG3"}, {SDL_SCANCODE_LANG4, "SDL_SCANCODE_LANG4"}, {SDL_SCANCODE_LANG5, "SDL_SCANCODE_LANG5"}, {SDL_SCANCODE_LANG6, "SDL_SCANCODE_LANG6"}, {SDL_SCANCODE_LANG7, "SDL_SCANCODE_LANG7"}, {SDL_SCANCODE_LANG8, "SDL_SCANCODE_LANG8"}, {SDL_SCANCODE_LANG9, "SDL_SCANCODE_LANG9"}, {SDL_SCANCODE_ALTERASE, "SDL_SCANCODE_ALTERASE"}, {SDL_SCANCODE_SYSREQ, "SDL_SCANCODE_SYSREQ"}, {SDL_SCANCODE_CANCEL, "SDL_SCANCODE_CANCEL"}, {SDL_SCANCODE_CLEAR, "SDL_SCANCODE_CLEAR"}, {SDL_SCANCODE_PRIOR, "SDL_SCANCODE_PRIOR"}, {SDL_SCANCODE_RETURN2, "SDL_SCANCODE_RETURN2"}, {SDL_SCANCODE_SEPARATOR, "SDL_SCANCODE_SEPARATOR"}, {SDL_SCANCODE_OUT, "SDL_SCANCODE_OUT"}, {SDL_SCANCODE_OPER, "SDL_SCANCODE_OPER"}, {SDL_SCANCODE_CLEARAGAIN, "SDL_SCANCODE_CLEARAGAIN"}, {SDL_SCANCODE_CRSEL, "SDL_SCANCODE_CRSEL"}, {SDL_SCANCODE_EXSEL, "SDL_SCANCODE_EXSEL"}, {SDL_SCANCODE_KP_00, "SDL_SCANCODE_KP_00"}, {SDL_SCANCODE_KP_000, "SDL_SCANCODE_KP_000"}, {SDL_SCANCODE_THOUSANDSSEPARATOR, "SDL_SCANCODE_THOUSANDSSEPARATOR"}, {SDL_SCANCODE_DECIMALSEPARATOR, "SDL_SCANCODE_DECIMALSEPARATOR"}, {SDL_SCANCODE_CURRENCYUNIT, "SDL_SCANCODE_CURRENCYUNIT"}, {SDL_SCANCODE_CURRENCYSUBUNIT, "SDL_SCANCODE_CURRENCYSUBUNIT"}, {SDL_SCANCODE_KP_LEFTPAREN, "SDL_SCANCODE_KP_LEFTPAREN"}, {SDL_SCANCODE_KP_RIGHTPAREN, "SDL_SCANCODE_KP_RIGHTPAREN"}, {SDL_SCANCODE_KP_LEFTBRACE, "SDL_SCANCODE_KP_LEFTBRACE"}, {SDL_SCANCODE_KP_RIGHTBRACE, "SDL_SCANCODE_KP_RIGHTBRACE"}, {SDL_SCANCODE_KP_TAB, "SDL_SCANCODE_KP_TAB"}, {SDL_SCANCODE_KP_BACKSPACE, "SDL_SCANCODE_KP_BACKSPACE"}, {SDL_SCANCODE_KP_A, "SDL_SCANCODE_KP_A"}, {SDL_SCANCODE_KP_B, "SDL_SCANCODE_KP_B"}, {SDL_SCANCODE_KP_C, "SDL_SCANCODE_KP_C"}, {SDL_SCANCODE_KP_D, "SDL_SCANCODE_KP_D"}, {SDL_SCANCODE_KP_E, "SDL_SCANCODE_KP_E"}, {SDL_SCANCODE_KP_F, "SDL_SCANCODE_KP_F"}, {SDL_SCANCODE_KP_XOR, "SDL_SCANCODE_KP_XOR"}, {SDL_SCANCODE_KP_POWER, "SDL_SCANCODE_KP_POWER"}, {SDL_SCANCODE_KP_PERCENT, "SDL_SCANCODE_KP_PERCENT"}, {SDL_SCANCODE_KP_LESS, "SDL_SCANCODE_KP_LESS"}, {SDL_SCANCODE_KP_GREATER, "SDL_SCANCODE_KP_GREATER"}, {SDL_SCANCODE_KP_AMPERSAND, "SDL_SCANCODE_KP_AMPERSAND"}, {SDL_SCANCODE_KP_DBLAMPERSAND, "SDL_SCANCODE_KP_DBLAMPERSAND"}, {SDL_SCANCODE_KP_VERTICALBAR, "SDL_SCANCODE_KP_VERTICALBAR"}, {SDL_SCANCODE_KP_DBLVERTICALBAR, "SDL_SCANCODE_KP_DBLVERTICALBAR"}, {SDL_SCANCODE_KP_COLON, "SDL_SCANCODE_KP_COLON"}, {SDL_SCANCODE_KP_HASH, "SDL_SCANCODE_KP_HASH"}, {SDL_SCANCODE_KP_SPACE, "SDL_SCANCODE_KP_SPACE"}, {SDL_SCANCODE_KP_AT, "SDL_SCANCODE_KP_AT"}, {SDL_SCANCODE_KP_EXCLAM, "SDL_SCANCODE_KP_EXCLAM"}, {SDL_SCANCODE_KP_MEMSTORE, "SDL_SCANCODE_KP_MEMSTORE"}, {SDL_SCANCODE_KP_MEMRECALL, "SDL_SCANCODE_KP_MEMRECALL"}, {SDL_SCANCODE_KP_MEMCLEAR, "SDL_SCANCODE_KP_MEMCLEAR"}, {SDL_SCANCODE_KP_MEMADD, "SDL_SCANCODE_KP_MEMADD"}, {SDL_SCANCODE_KP_MEMSUBTRACT, "SDL_SCANCODE_KP_MEMSUBTRACT"}, {SDL_SCANCODE_KP_MEMMULTIPLY, "SDL_SCANCODE_KP_MEMMULTIPLY"}, {SDL_SCANCODE_KP_MEMDIVIDE, "SDL_SCANCODE_KP_MEMDIVIDE"}, {SDL_SCANCODE_KP_PLUSMINUS, "SDL_SCANCODE_KP_PLUSMINUS"}, {SDL_SCANCODE_KP_CLEAR, "SDL_SCANCODE_KP_CLEAR"}, {SDL_SCANCODE_KP_CLEARENTRY, "SDL_SCANCODE_KP_CLEARENTRY"}, {SDL_SCANCODE_KP_BINARY, "SDL_SCANCODE_KP_BINARY"}, {SDL_SCANCODE_KP_OCTAL, "SDL_SCANCODE_KP_OCTAL"}, {SDL_SCANCODE_KP_DECIMAL, "SDL_SCANCODE_KP_DECIMAL"}, {SDL_SCANCODE_KP_HEXADECIMAL, "SDL_SCANCODE_KP_HEXADECIMAL"}, {SDL_SCANCODE_LCTRL, "SDL_SCANCODE_LCTRL"}, {SDL_SCANCODE_LSHIFT, "SDL_SCANCODE_LSHIFT"}, {SDL_SCANCODE_LALT, "SDL_SCANCODE_LALT"}, {SDL_SCANCODE_LGUI, "SDL_SCANCODE_LGUI"}, {SDL_SCANCODE_RCTRL, "SDL_SCANCODE_RCTRL"}, {SDL_SCANCODE_RSHIFT, "SDL_SCANCODE_RSHIFT"}, {SDL_SCANCODE_RALT, "SDL_SCANCODE_RALT"}, {SDL_SCANCODE_RGUI, "SDL_SCANCODE_RGUI"}, {SDL_SCANCODE_MODE, "SDL_SCANCODE_MODE"}, {SDL_SCANCODE_AUDIONEXT, "SDL_SCANCODE_AUDIONEXT"}, {SDL_SCANCODE_AUDIOPREV, "SDL_SCANCODE_AUDIOPREV"}, {SDL_SCANCODE_AUDIOSTOP, "SDL_SCANCODE_AUDIOSTOP"}, {SDL_SCANCODE_AUDIOPLAY, "SDL_SCANCODE_AUDIOPLAY"}, {SDL_SCANCODE_AUDIOMUTE, "SDL_SCANCODE_AUDIOMUTE"}, {SDL_SCANCODE_MEDIASELECT, "SDL_SCANCODE_MEDIASELECT"}, {SDL_SCANCODE_WWW, "SDL_SCANCODE_WWW"}, {SDL_SCANCODE_MAIL, "SDL_SCANCODE_MAIL"}, {SDL_SCANCODE_CALCULATOR, "SDL_SCANCODE_CALCULATOR"}, {SDL_SCANCODE_COMPUTER, "SDL_SCANCODE_COMPUTER"}, {SDL_SCANCODE_AC_SEARCH, "SDL_SCANCODE_AC_SEARCH"}, {SDL_SCANCODE_AC_HOME, "SDL_SCANCODE_AC_HOME"}, {SDL_SCANCODE_AC_BACK, "SDL_SCANCODE_AC_BACK"}, {SDL_SCANCODE_AC_FORWARD, "SDL_SCANCODE_AC_FORWARD"}, {SDL_SCANCODE_AC_STOP, "SDL_SCANCODE_AC_STOP"}, {SDL_SCANCODE_AC_REFRESH, "SDL_SCANCODE_AC_REFRESH"}, {SDL_SCANCODE_AC_BOOKMARKS, "SDL_SCANCODE_AC_BOOKMARKS"}, {SDL_SCANCODE_BRIGHTNESSDOWN, "SDL_SCANCODE_BRIGHTNESSDOWN"}, {SDL_SCANCODE_BRIGHTNESSUP, "SDL_SCANCODE_BRIGHTNESSUP"}, {SDL_SCANCODE_DISPLAYSWITCH, "SDL_SCANCODE_DISPLAYSWITCH"}, {SDL_SCANCODE_KBDILLUMTOGGLE, "SDL_SCANCODE_KBDILLUMTOGGLE"}, {SDL_SCANCODE_KBDILLUMDOWN, "SDL_SCANCODE_KBDILLUMDOWN"}, {SDL_SCANCODE_KBDILLUMUP, "SDL_SCANCODE_KBDILLUMUP"}, {SDL_SCANCODE_EJECT, "SDL_SCANCODE_EJECT"}, {SDL_SCANCODE_SLEEP, "SDL_SCANCODE_SLEEP"}, {SDL_SCANCODE_APP1, "SDL_SCANCODE_APP1"}, {SDL_SCANCODE_APP2, "SDL_SCANCODE_APP2"}, #if SDL_VERSION_ATLEAST(2, 0, 6) {SDL_SCANCODE_AUDIOREWIND, "SDL_SCANCODE_AUDIOREWIND"}, {SDL_SCANCODE_AUDIOFASTFORWARD, "SDL_SCANCODE_AUDIOFASTFORWARD"}, #endif {SDL_NUM_SCANCODES, "SDL_NUM_SCANCODES"}, }; int cap32_main (int argc, char **argv) { int iExitCondition; bool take_screenshot = false; bool bin_loaded = false; SDL_Event event; std::vector<std::string> slot_list; try { binPath = std::filesystem::absolute(std::filesystem::path(argv[0]).parent_path()); } catch(...) { // Dirty fallback in case the executable is found in the path. // binPath is only use for bundles anyway, where this is not the case. binPath = std::filesystem::absolute("."); } parseArguments(argc, argv, slot_list, args); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0) { // initialize SDL fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); exit(-1); } #ifndef APP_PATH if(getcwd(chAppPath, sizeof(chAppPath)-1) == nullptr) { fprintf(stderr, "getcwd failed: %s\n", strerror(errno)); cleanExit(-1); } #else strncpy(chAppPath,APP_PATH,_MAX_PATH); #endif loadConfiguration(CPC, getConfigurationFilename()); // retrieve the emulator configuration if (CPC.printer) { if (!printer_start()) { // start capturing printer output, if enabled CPC.printer = 0; } } z80_init_tables(); // init Z80 emulation if (video_init()) { fprintf(stderr, "video_init() failed. Aborting.\n"); cleanExit(-1); } mouse_init(); if (audio_init()) { fprintf(stderr, "audio_init() failed. Disabling sound.\n"); // TODO(cpitrat): Do not set this to 0 when audio_init fail as this affect // configuration when saving from GUI. Rather use some other indicator to // know whether snd_bufferptr is usable or not. // To test it, set SDL_AUDIODRIVER=dsp or some other unsupported value. CPC.snd_enabled = 0; // disable sound emulation } if (joysticks_init()) { fprintf(stderr, "joysticks_init() failed. Joysticks won't work.\n"); } #ifdef DEBUG pfoDebug = fopen("./debug.txt", "wt"); #endif // Extract files to be loaded from the command line args fillSlots(slot_list, CPC); // Must be done before emulator_init() CPC.InputMapper = new InputMapper(&CPC); // emulator_init must be called before loading files as they require // pbGPBuffer to be initialized. if (emulator_init()) { fprintf(stderr, "emulator_init() failed. Aborting.\n"); cleanExit(-1); } // Really load the various drives, if needed loadSlots(); // Fill the buffer with autocmd if provided virtualKeyboardEvents = CPC.InputMapper->StringToEvents(args.autocmd); // Give some time to the CPC to start before sending any command nextVirtualEventFrameCount = dwFrameCountOverall + CPC.boot_time; // ---------------------------------------------------------------------------- update_timings(); audio_resume(); loadBreakpoints(); iExitCondition = EC_FRAME_COMPLETE; while (true) { // We can only load bin files after the CPC finished the init if (!bin_loaded && dwFrameCountOverall > CPC.boot_time) { bin_loaded = true; if (!args.binFile.empty()) bin_load(args.binFile, args.binOffset); } if(!virtualKeyboardEvents.empty() && (nextVirtualEventFrameCount < dwFrameCountOverall) && (breakPointsToSkipBeforeProceedingWithVirtualEvents == 0)) { auto nextVirtualEvent = &virtualKeyboardEvents.front(); SDL_PushEvent(nextVirtualEvent); auto keysym = nextVirtualEvent->key.keysym; auto evtype = nextVirtualEvent->key.type; LOG_DEBUG("Inserted virtual event keysym=" << int(keysym.sym) << " (" << evtype << ")"); CPCScancode scancode = CPC.InputMapper->CPCscancodeFromKeysym(keysym); if (!(scancode & MOD_EMU_KEY)) { LOG_DEBUG("The virtual event is a keypress (not a command), so introduce a pause."); // Setting nextVirtualEventFrameCount below guarantees to // immediately break the loop enclosing this code and wait // at least one frame. nextVirtualEventFrameCount = dwFrameCountOverall + ((evtype == SDL_KEYDOWN || evtype == SDL_KEYUP)?1:0); // The extra delay in case of SDL_KEYDOWN is to keep the // key pressed long enough. If we don't do this, the CPC // firmware debouncer eats repeated characters. } virtualKeyboardEvents.pop_front(); } if (!devtools.empty()) { devtools.remove_if([](DevTools& d) { return !d.IsActive(); }); // Ensure execution is resumed when all devtools are closed if (devtools.empty()) CPC.paused = false; for (auto& devtool : devtools) devtool.PreUpdate(); for (auto& devtool : devtools) devtool.PostUpdate(); } while (SDL_PollEvent(&event)) { bool processed = false; if (!devtools.empty()) { devtools.remove_if([](DevTools& d) { return !d.IsActive(); }); // Ensure execution is resumed when all devtools are closed if (devtools.empty()) CPC.paused = false; for (auto& devtool : devtools) { if (devtool.PassEvent(event)) { processed = true; break; } } } if (processed) continue; switch (event.type) { case SDL_KEYDOWN: { CPCScancode scancode = CPC.InputMapper->CPCscancodeFromKeysym(event.key.keysym); LOG_VERBOSE("Keyboard: pressed: " << SDL_GetKeyName(event.key.keysym.sym) << " - keycode: " << keycode_names[event.key.keysym.sym] << " (" << event.key.keysym.sym << ") - scancode: " << scancode_names[event.key.keysym.scancode] << " (" << event.key.keysym.scancode << ") - CPC key: " << CPC.InputMapper->CPCkeyToString(CPC.InputMapper->CPCkeyFromKeysym(event.key.keysym)) << " - CPC scancode: " << scancode); if (!(scancode & MOD_EMU_KEY)) { applyKeypress(scancode, keyboard_matrix, true); } } break; case SDL_KEYUP: { CPCScancode scancode = CPC.InputMapper->CPCscancodeFromKeysym(event.key.keysym); if (!(scancode & MOD_EMU_KEY)) { applyKeypress(scancode, keyboard_matrix, false); } else { // process emulator specific keys switch (scancode) { case CAP32_GUI: { showGui(); break; } case CAP32_VKBD: { showVKeyboard(); break; } case CAP32_DEVTOOLS: { showDevTools(); break; } case CAP32_FULLSCRN: audio_pause(); SDL_Delay(20); video_shutdown(); CPC.scr_window = CPC.scr_window ? 0 : 1; if (video_init()) { fprintf(stderr, "video_init() failed. Aborting.\n"); cleanExit(-1); } audio_resume(); break; case CAP32_SCRNSHOT: // Delay taking the screenshot to ensure the frame is complete. take_screenshot = true; break; case CAP32_DELAY: // Reuse boot_time as it is a reasonable wait time for Plus transition between the F1/F2 nag screen and the command line. // TODO: Support an argument to CAP32_DELAY in autocmd instead. LOG_VERBOSE("Take into account CAP32_DELAY"); nextVirtualEventFrameCount = dwFrameCountOverall + CPC.boot_time; break; case CAP32_WAITBREAK: breakPointsToSkipBeforeProceedingWithVirtualEvents++; LOG_INFO("Will skip " << breakPointsToSkipBeforeProceedingWithVirtualEvents << " before processing more virtual events."); LOG_VERBOSE("Setting z80.break_point=0 (was " << z80.break_point << ")."); z80.break_point = 0; // set break point to address 0. FIXME would be interesting to change this via a parameter of CAP32_WAITBREAK on command line. break; case CAP32_SNAPSHOT: dumpSnapshot(); break; case CAP32_LD_SNAP: loadSnapshot(); break; case CAP32_TAPEPLAY: LOG_VERBOSE("Request to play tape"); Tape_Rewind(); if (pbTapeImage) { if (CPC.tape_play_button) { LOG_VERBOSE("Play button released"); CPC.tape_play_button = 0; } else { LOG_VERBOSE("Play button pushed"); CPC.tape_play_button = 0x10; } } set_osd_message(std::string("Play tape: ") + (CPC.tape_play_button ? "on" : "off")); break; case CAP32_MF2STOP: if(CPC.mf2 && !(dwMF2Flags & MF2_ACTIVE)) { reg_pair port; // Set mode to activate ROM_config //port.b.h = 0x40; //z80_OUT_handler(port, 128); // Attempt to load MF2 in lower ROM (can fail if lower ROM is not active) port.b.h = 0xfe; port.b.l = 0xe8; dwMF2Flags &= ~MF2_INVISIBLE; z80_OUT_handler(port, 0); // Stop execution if load succeeded if(dwMF2Flags & MF2_ACTIVE) { z80_mf2stop(); } } break; case CAP32_RESET: LOG_VERBOSE("User requested emulator reset"); emulator_reset(); break; case CAP32_JOY: CPC.joystick_emulation = CPC.joystick_emulation ? 0 : 1; CPC.InputMapper->set_joystick_emulation(); set_osd_message(std::string("Joystick emulation: ") + (CPC.joystick_emulation ? "on" : "off")); break; case CAP32_PHAZER: CPC.phazer_emulation = CPC.phazer_emulation.Next(); if (!CPC.phazer_emulation) CPC.phazer_pressed = false; mouse_init(); set_osd_message(std::string("Phazer emulation: ") + CPC.phazer_emulation.ToString()); break; case CAP32_PASTE: set_osd_message("Pasting..."); { auto content = std::string(SDL_GetClipboardText()); LOG_VERBOSE("Pasting '" << content << "'"); auto newEvents = CPC.InputMapper->StringToEvents(content); virtualKeyboardEvents.splice(virtualKeyboardEvents.end(), newEvents); nextVirtualEventFrameCount = dwFrameCountOverall; break; } case CAP32_EXIT: cleanExit (0); break; case CAP32_FPS: CPC.scr_fps = CPC.scr_fps ? 0 : 1; // toggle fps display on or off set_osd_message(std::string("Performances info: ") + (CPC.scr_fps ? "on" : "off")); break; case CAP32_SPEED: CPC.limit_speed = CPC.limit_speed ? 0 : 1; set_osd_message(std::string("Limit speed: ") + (CPC.limit_speed ? "on" : "off")); break; case CAP32_DEBUG: log_verbose = !log_verbose; #ifdef DEBUG dwDebugFlag = dwDebugFlag ? 0 : 1; #endif #ifdef DEBUG_CRTC if (dwDebugFlag) { for (int n = 0; n < 14; n++) { fprintf(pfoDebug, "%02x = %02x\r\n", n, CRTC.registers[n]); } } #endif set_osd_message(std::string("Debug mode: ") + (log_verbose ? "on" : "off")); break; } } } break; case SDL_JOYBUTTONDOWN: { CPCScancode scancode = CPC.InputMapper->CPCscancodeFromJoystickButton(event.jbutton); if (scancode == 0xff) { if (event.jbutton.button == CPC.joystick_menu_button) { showGui(); } if (event.jbutton.button == CPC.joystick_vkeyboard_button) { showVKeyboard(); } } applyKeypress(scancode, keyboard_matrix, true); } break; case SDL_JOYBUTTONUP: { CPCScancode scancode = CPC.InputMapper->CPCscancodeFromJoystickButton(event.jbutton); applyKeypress(scancode, keyboard_matrix, false); } break; case SDL_JOYAXISMOTION: { CPCScancode scancodes[2] = {0xff, 0xff}; bool release = false; CPC.InputMapper->CPCscancodeFromJoystickAxis(event.jaxis, scancodes, release); applyKeypress(scancodes[0], keyboard_matrix, !release); if (release && scancodes[0] != 0xff) { applyKeypress(scancodes[1], keyboard_matrix, !release); } } break; case SDL_MOUSEMOTION: { CPC.phazer_x = (event.motion.x-vid_plugin->x_offset) * vid_plugin->x_scale; CPC.phazer_y = (event.motion.y-vid_plugin->y_offset) * vid_plugin->y_scale; } break; case SDL_MOUSEBUTTONDOWN: { if (CPC.phazer_emulation) { // Trojan Light Phazer uses Joystick Fire for the trigger button: // https://www.cpcwiki.eu/index.php/Trojan_Light_Phazer if (CPC.phazer_emulation == PhazerType::TrojanLightPhazer) { auto scancode = CPC.InputMapper->CPCscancodeFromCPCkey(CPC_J0_FIRE1); applyKeypress(scancode, keyboard_matrix, true); } CPC.phazer_pressed = true; } } break; case SDL_MOUSEBUTTONUP: { if (CPC.phazer_emulation) { if (CPC.phazer_emulation == PhazerType::TrojanLightPhazer) { auto scancode = CPC.InputMapper->CPCscancodeFromCPCkey(CPC_J0_FIRE1); applyKeypress(scancode, keyboard_matrix, false); } CPC.phazer_pressed = false; } } break; // TODO: What if we were paused because of other reason than losing focus and then only lost focus // the right thing to do here is to restore focus but keep paused... implementing this require // keeping track of pause source, which will be a pain. case SDL_WINDOWEVENT: switch (event.window.event) { #if SDL_VERSION_ATLEAST(2, 0, 5) case SDL_WINDOWEVENT_TAKE_FOCUS: #endif case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_ENTER: if (CPC.auto_pause) { cpc_resume(); } break; case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_MINIMIZED: if (CPC.auto_pause) { cpc_pause(); } break; } break; case SDL_QUIT: cleanExit(0); } } if (!CPC.paused) { // run the emulation, as long as the user doesn't pause it dwTicks = SDL_GetTicks(); if (dwTicks >= dwTicksTargetFPS) { // update FPS counter? dwFPS = dwFrameCount; dwFrameCount = 0; dwTicksTargetFPS = dwTicks + 1000; // prep counter for the next run } if (CPC.limit_speed) { // limit to original CPC speed? if (CPC.snd_enabled) { if (iExitCondition == EC_SOUND_BUFFER) { // Emulation filled a sound buffer. if (!dwSndBufferCopied) { continue; // delay emulation until our audio callback copied and played the buffer } dwSndBufferCopied = 0; } } else if (iExitCondition == EC_CYCLE_COUNT) { dwTicks = SDL_GetTicks(); if (dwTicks < dwTicksTarget) { // limit speed ? if (dwTicksTarget - dwTicks > POLL_INTERVAL_MS) { // No need to burn cycles if next event is far away std::this_thread::sleep_for(std::chrono::milliseconds(POLL_INTERVAL_MS)); } continue; // delay emulation } dwTicksTarget = dwTicks + dwTicksOffset; // prep counter for the next run } } dword dwOffset = CPC.scr_pos - CPC.scr_base; // offset in current surface row if (VDU.scrln > 0) { CPC.scr_base = static_cast<byte *>(back_surface->pixels) + (VDU.scrln * CPC.scr_line_offs); // determine current position } else { CPC.scr_base = static_cast<byte *>(back_surface->pixels); // reset to surface start } CPC.scr_pos = CPC.scr_base + dwOffset; // update current rendering position iExitCondition = z80_execute(); // run the emulation until an exit condition is met if (iExitCondition == EC_BREAKPOINT) { if (z80.breakpoint_reached || z80.watchpoint_reached) { // This is a breakpoint from DevTools or symbol file if (devtools.empty()) { if (showDevTools()) CPC.paused = true; } } else { // This is an old flavour breakpoint // We have to clear breakpoint to let the z80 emulator move on. z80.break_point = 0xffffffff; // clear break point z80.trace = 1; // make sure we'll be here to rearm break point at the next z80 instruction. if (breakPointsToSkipBeforeProceedingWithVirtualEvents>0) { breakPointsToSkipBeforeProceedingWithVirtualEvents--; LOG_DEBUG("Decremented breakpoint skip counter to " << breakPointsToSkipBeforeProceedingWithVirtualEvents); } } } else { if (z80.break_point == 0xffffffff) { // TODO(cpcitor) clean up 0xffffffff into a value like Z80_BREAKPOINT_NONE LOG_DEBUG("Rearming EC_BREAKPOINT."); z80.break_point = 0; // set break point for next time } } if (iExitCondition == EC_FRAME_COMPLETE) { // emulation finished rendering a complete frame? dwFrameCountOverall++; dwFrameCount++; if (SDL_GetTicks() < osd_timing) { print(static_cast<byte *>(back_surface->pixels) + CPC.scr_line_offs, osd_message.c_str(), true); } else if (CPC.scr_fps) { char chStr[15]; sprintf(chStr, "%3dFPS %3d%%", static_cast<int>(dwFPS), static_cast<int>(dwFPS) * 100 / (1000 / static_cast<int>(FRAME_PERIOD_MS))); print(static_cast<byte *>(back_surface->pixels) + CPC.scr_line_offs, chStr, true); // display the frames per second counter } asic_draw_sprites(); video_display(); // update PC display if (take_screenshot) { dumpScreen(); take_screenshot = false; } } } else { // We are paused. No need to burn CPU cycles std::this_thread::sleep_for(std::chrono::milliseconds(POLL_INTERVAL_MS)); } } return 0; }
122,285
C++
.cpp
2,844
33.962025
426
0.574401
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,800
crtc.cpp
ColinPitrat_caprice32/src/crtc.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Hitachi HD6845S CRT Controller (CRTC Type 0) emulation based on the CRTC emulation of WinAPE32 v2.0a5b by Richard Wilson */ #include <math.h> #include "cap32.h" #include "crtc.h" #include "z80.h" #include "log.h" #include "asic.h" extern t_CPC CPC; extern t_CRTC CRTC; extern t_GateArray GateArray; extern t_VDU VDU; extern t_z80regs z80; extern dword dwXScale; extern byte *pbRAM; #ifdef DEBUG_CRTC extern dword dwDebugFlag; extern FILE *pfoDebug; #endif #define MAX_SYNC_DEC 80 #define MAX_SYNC_INC 80 #define MAX_DRAWN 270 // Max displayed scan line (+1) #define MIN_VHOLD 250 #define MAX_VHOLD 380 #define MID_VHOLD 295 #define MIN_VHOLD_RANGE 46 #define MAX_VHOLD_RANGE 74 t_flags1 flags1; t_new_dt new_dt; dword LastPreRend; word MinVSync, MaxVSync; int iMonHSPeakPos, iMonHSStartPos, iMonHSEndPos, iMonHSPeakToStart, iMonHSStartToPeak, iMonHSEndToPeak, iMonHSPeakToEnd; int HorzPos, MonHSYNC, MonFreeSync; int HSyncDuration, MinHSync, MaxHSync; int HadP; byte PosShift, HorzChar, HorzMax; dword *ModeMaps[4]; dword *ModeMap; byte HorzPix[49]; byte RendBuff[800]; byte *RendWid, *RendOut; dword *RendStart, *RendPos; word MAXlate[0x7400]; void (*PreRender)(); // Version 2 translation tables - static dword M0Map[0x200] = { 0x00000000,0x00000000,0x00000000,0x08080808,0x08080808,0x00000000,0x08080808,0x08080808, 0x00000000,0x02020202,0x00000000,0x0A0A0A0A,0x08080808,0x02020202,0x08080808,0x0A0A0A0A, 0x02020202,0x00000000,0x02020202,0x08080808,0x0A0A0A0A,0x00000000,0x0A0A0A0A,0x08080808, 0x02020202,0x02020202,0x02020202,0x0A0A0A0A,0x0A0A0A0A,0x02020202,0x0A0A0A0A,0x0A0A0A0A, 0x00000000,0x04040404,0x00000000,0x0C0C0C0C,0x08080808,0x04040404,0x08080808,0x0C0C0C0C, 0x00000000,0x06060606,0x00000000,0x0E0E0E0E,0x08080808,0x06060606,0x08080808,0x0E0E0E0E, 0x02020202,0x04040404,0x02020202,0x0C0C0C0C,0x0A0A0A0A,0x04040404,0x0A0A0A0A,0x0C0C0C0C, 0x02020202,0x06060606,0x02020202,0x0E0E0E0E,0x0A0A0A0A,0x06060606,0x0A0A0A0A,0x0E0E0E0E, 0x04040404,0x00000000,0x04040404,0x08080808,0x0C0C0C0C,0x00000000,0x0C0C0C0C,0x08080808, 0x04040404,0x02020202,0x04040404,0x0A0A0A0A,0x0C0C0C0C,0x02020202,0x0C0C0C0C,0x0A0A0A0A, 0x06060606,0x00000000,0x06060606,0x08080808,0x0E0E0E0E,0x00000000,0x0E0E0E0E,0x08080808, 0x06060606,0x02020202,0x06060606,0x0A0A0A0A,0x0E0E0E0E,0x02020202,0x0E0E0E0E,0x0A0A0A0A, 0x04040404,0x04040404,0x04040404,0x0C0C0C0C,0x0C0C0C0C,0x04040404,0x0C0C0C0C,0x0C0C0C0C, 0x04040404,0x06060606,0x04040404,0x0E0E0E0E,0x0C0C0C0C,0x06060606,0x0C0C0C0C,0x0E0E0E0E, 0x06060606,0x04040404,0x06060606,0x0C0C0C0C,0x0E0E0E0E,0x04040404,0x0E0E0E0E,0x0C0C0C0C, 0x06060606,0x06060606,0x06060606,0x0E0E0E0E,0x0E0E0E0E,0x06060606,0x0E0E0E0E,0x0E0E0E0E, 0x00000000,0x01010101,0x00000000,0x09090909,0x08080808,0x01010101,0x08080808,0x09090909, 0x00000000,0x03030303,0x00000000,0x0B0B0B0B,0x08080808,0x03030303,0x08080808,0x0B0B0B0B, 0x02020202,0x01010101,0x02020202,0x09090909,0x0A0A0A0A,0x01010101,0x0A0A0A0A,0x09090909, 0x02020202,0x03030303,0x02020202,0x0B0B0B0B,0x0A0A0A0A,0x03030303,0x0A0A0A0A,0x0B0B0B0B, 0x00000000,0x05050505,0x00000000,0x0D0D0D0D,0x08080808,0x05050505,0x08080808,0x0D0D0D0D, 0x00000000,0x07070707,0x00000000,0x0F0F0F0F,0x08080808,0x07070707,0x08080808,0x0F0F0F0F, 0x02020202,0x05050505,0x02020202,0x0D0D0D0D,0x0A0A0A0A,0x05050505,0x0A0A0A0A,0x0D0D0D0D, 0x02020202,0x07070707,0x02020202,0x0F0F0F0F,0x0A0A0A0A,0x07070707,0x0A0A0A0A,0x0F0F0F0F, 0x04040404,0x01010101,0x04040404,0x09090909,0x0C0C0C0C,0x01010101,0x0C0C0C0C,0x09090909, 0x04040404,0x03030303,0x04040404,0x0B0B0B0B,0x0C0C0C0C,0x03030303,0x0C0C0C0C,0x0B0B0B0B, 0x06060606,0x01010101,0x06060606,0x09090909,0x0E0E0E0E,0x01010101,0x0E0E0E0E,0x09090909, 0x06060606,0x03030303,0x06060606,0x0B0B0B0B,0x0E0E0E0E,0x03030303,0x0E0E0E0E,0x0B0B0B0B, 0x04040404,0x05050505,0x04040404,0x0D0D0D0D,0x0C0C0C0C,0x05050505,0x0C0C0C0C,0x0D0D0D0D, 0x04040404,0x07070707,0x04040404,0x0F0F0F0F,0x0C0C0C0C,0x07070707,0x0C0C0C0C,0x0F0F0F0F, 0x06060606,0x05050505,0x06060606,0x0D0D0D0D,0x0E0E0E0E,0x05050505,0x0E0E0E0E,0x0D0D0D0D, 0x06060606,0x07070707,0x06060606,0x0F0F0F0F,0x0E0E0E0E,0x07070707,0x0E0E0E0E,0x0F0F0F0F, 0x01010101,0x00000000,0x01010101,0x08080808,0x09090909,0x00000000,0x09090909,0x08080808, 0x01010101,0x02020202,0x01010101,0x0A0A0A0A,0x09090909,0x02020202,0x09090909,0x0A0A0A0A, 0x03030303,0x00000000,0x03030303,0x08080808,0x0B0B0B0B,0x00000000,0x0B0B0B0B,0x08080808, 0x03030303,0x02020202,0x03030303,0x0A0A0A0A,0x0B0B0B0B,0x02020202,0x0B0B0B0B,0x0A0A0A0A, 0x01010101,0x04040404,0x01010101,0x0C0C0C0C,0x09090909,0x04040404,0x09090909,0x0C0C0C0C, 0x01010101,0x06060606,0x01010101,0x0E0E0E0E,0x09090909,0x06060606,0x09090909,0x0E0E0E0E, 0x03030303,0x04040404,0x03030303,0x0C0C0C0C,0x0B0B0B0B,0x04040404,0x0B0B0B0B,0x0C0C0C0C, 0x03030303,0x06060606,0x03030303,0x0E0E0E0E,0x0B0B0B0B,0x06060606,0x0B0B0B0B,0x0E0E0E0E, 0x05050505,0x00000000,0x05050505,0x08080808,0x0D0D0D0D,0x00000000,0x0D0D0D0D,0x08080808, 0x05050505,0x02020202,0x05050505,0x0A0A0A0A,0x0D0D0D0D,0x02020202,0x0D0D0D0D,0x0A0A0A0A, 0x07070707,0x00000000,0x07070707,0x08080808,0x0F0F0F0F,0x00000000,0x0F0F0F0F,0x08080808, 0x07070707,0x02020202,0x07070707,0x0A0A0A0A,0x0F0F0F0F,0x02020202,0x0F0F0F0F,0x0A0A0A0A, 0x05050505,0x04040404,0x05050505,0x0C0C0C0C,0x0D0D0D0D,0x04040404,0x0D0D0D0D,0x0C0C0C0C, 0x05050505,0x06060606,0x05050505,0x0E0E0E0E,0x0D0D0D0D,0x06060606,0x0D0D0D0D,0x0E0E0E0E, 0x07070707,0x04040404,0x07070707,0x0C0C0C0C,0x0F0F0F0F,0x04040404,0x0F0F0F0F,0x0C0C0C0C, 0x07070707,0x06060606,0x07070707,0x0E0E0E0E,0x0F0F0F0F,0x06060606,0x0F0F0F0F,0x0E0E0E0E, 0x01010101,0x01010101,0x01010101,0x09090909,0x09090909,0x01010101,0x09090909,0x09090909, 0x01010101,0x03030303,0x01010101,0x0B0B0B0B,0x09090909,0x03030303,0x09090909,0x0B0B0B0B, 0x03030303,0x01010101,0x03030303,0x09090909,0x0B0B0B0B,0x01010101,0x0B0B0B0B,0x09090909, 0x03030303,0x03030303,0x03030303,0x0B0B0B0B,0x0B0B0B0B,0x03030303,0x0B0B0B0B,0x0B0B0B0B, 0x01010101,0x05050505,0x01010101,0x0D0D0D0D,0x09090909,0x05050505,0x09090909,0x0D0D0D0D, 0x01010101,0x07070707,0x01010101,0x0F0F0F0F,0x09090909,0x07070707,0x09090909,0x0F0F0F0F, 0x03030303,0x05050505,0x03030303,0x0D0D0D0D,0x0B0B0B0B,0x05050505,0x0B0B0B0B,0x0D0D0D0D, 0x03030303,0x07070707,0x03030303,0x0F0F0F0F,0x0B0B0B0B,0x07070707,0x0B0B0B0B,0x0F0F0F0F, 0x05050505,0x01010101,0x05050505,0x09090909,0x0D0D0D0D,0x01010101,0x0D0D0D0D,0x09090909, 0x05050505,0x03030303,0x05050505,0x0B0B0B0B,0x0D0D0D0D,0x03030303,0x0D0D0D0D,0x0B0B0B0B, 0x07070707,0x01010101,0x07070707,0x09090909,0x0F0F0F0F,0x01010101,0x0F0F0F0F,0x09090909, 0x07070707,0x03030303,0x07070707,0x0B0B0B0B,0x0F0F0F0F,0x03030303,0x0F0F0F0F,0x0B0B0B0B, 0x05050505,0x05050505,0x05050505,0x0D0D0D0D,0x0D0D0D0D,0x05050505,0x0D0D0D0D,0x0D0D0D0D, 0x05050505,0x07070707,0x05050505,0x0F0F0F0F,0x0D0D0D0D,0x07070707,0x0D0D0D0D,0x0F0F0F0F, 0x07070707,0x05050505,0x07070707,0x0D0D0D0D,0x0F0F0F0F,0x05050505,0x0F0F0F0F,0x0D0D0D0D, 0x07070707,0x07070707,0x07070707,0x0F0F0F0F,0x0F0F0F0F,0x07070707,0x0F0F0F0F,0x0F0F0F0F }; dword M1Map[0x200] = { 0x00000000,0x00000000,0x00000000,0x02020000,0x00000000,0x00000202,0x00000000,0x02020202, 0x02020000,0x00000000,0x02020000,0x02020000,0x02020000,0x00000202,0x02020000,0x02020202, 0x00000202,0x00000000,0x00000202,0x02020000,0x00000202,0x00000202,0x00000202,0x02020202, 0x02020202,0x00000000,0x02020202,0x02020000,0x02020202,0x00000202,0x02020202,0x02020202, 0x00000000,0x01010000,0x00000000,0x03030000,0x00000000,0x01010202,0x00000000,0x03030202, 0x02020000,0x01010000,0x02020000,0x03030000,0x02020000,0x01010202,0x02020000,0x03030202, 0x00000202,0x01010000,0x00000202,0x03030000,0x00000202,0x01010202,0x00000202,0x03030202, 0x02020202,0x01010000,0x02020202,0x03030000,0x02020202,0x01010202,0x02020202,0x03030202, 0x00000000,0x00000101,0x00000000,0x02020101,0x00000000,0x00000303,0x00000000,0x02020303, 0x02020000,0x00000101,0x02020000,0x02020101,0x02020000,0x00000303,0x02020000,0x02020303, 0x00000202,0x00000101,0x00000202,0x02020101,0x00000202,0x00000303,0x00000202,0x02020303, 0x02020202,0x00000101,0x02020202,0x02020101,0x02020202,0x00000303,0x02020202,0x02020303, 0x00000000,0x01010101,0x00000000,0x03030101,0x00000000,0x01010303,0x00000000,0x03030303, 0x02020000,0x01010101,0x02020000,0x03030101,0x02020000,0x01010303,0x02020000,0x03030303, 0x00000202,0x01010101,0x00000202,0x03030101,0x00000202,0x01010303,0x00000202,0x03030303, 0x02020202,0x01010101,0x02020202,0x03030101,0x02020202,0x01010303,0x02020202,0x03030303, 0x01010000,0x00000000,0x01010000,0x02020000,0x01010000,0x00000202,0x01010000,0x02020202, 0x03030000,0x00000000,0x03030000,0x02020000,0x03030000,0x00000202,0x03030000,0x02020202, 0x01010202,0x00000000,0x01010202,0x02020000,0x01010202,0x00000202,0x01010202,0x02020202, 0x03030202,0x00000000,0x03030202,0x02020000,0x03030202,0x00000202,0x03030202,0x02020202, 0x01010000,0x01010000,0x01010000,0x03030000,0x01010000,0x01010202,0x01010000,0x03030202, 0x03030000,0x01010000,0x03030000,0x03030000,0x03030000,0x01010202,0x03030000,0x03030202, 0x01010202,0x01010000,0x01010202,0x03030000,0x01010202,0x01010202,0x01010202,0x03030202, 0x03030202,0x01010000,0x03030202,0x03030000,0x03030202,0x01010202,0x03030202,0x03030202, 0x01010000,0x00000101,0x01010000,0x02020101,0x01010000,0x00000303,0x01010000,0x02020303, 0x03030000,0x00000101,0x03030000,0x02020101,0x03030000,0x00000303,0x03030000,0x02020303, 0x01010202,0x00000101,0x01010202,0x02020101,0x01010202,0x00000303,0x01010202,0x02020303, 0x03030202,0x00000101,0x03030202,0x02020101,0x03030202,0x00000303,0x03030202,0x02020303, 0x01010000,0x01010101,0x01010000,0x03030101,0x01010000,0x01010303,0x01010000,0x03030303, 0x03030000,0x01010101,0x03030000,0x03030101,0x03030000,0x01010303,0x03030000,0x03030303, 0x01010202,0x01010101,0x01010202,0x03030101,0x01010202,0x01010303,0x01010202,0x03030303, 0x03030202,0x01010101,0x03030202,0x03030101,0x03030202,0x01010303,0x03030202,0x03030303, 0x00000101,0x00000000,0x00000101,0x02020000,0x00000101,0x00000202,0x00000101,0x02020202, 0x02020101,0x00000000,0x02020101,0x02020000,0x02020101,0x00000202,0x02020101,0x02020202, 0x00000303,0x00000000,0x00000303,0x02020000,0x00000303,0x00000202,0x00000303,0x02020202, 0x02020303,0x00000000,0x02020303,0x02020000,0x02020303,0x00000202,0x02020303,0x02020202, 0x00000101,0x01010000,0x00000101,0x03030000,0x00000101,0x01010202,0x00000101,0x03030202, 0x02020101,0x01010000,0x02020101,0x03030000,0x02020101,0x01010202,0x02020101,0x03030202, 0x00000303,0x01010000,0x00000303,0x03030000,0x00000303,0x01010202,0x00000303,0x03030202, 0x02020303,0x01010000,0x02020303,0x03030000,0x02020303,0x01010202,0x02020303,0x03030202, 0x00000101,0x00000101,0x00000101,0x02020101,0x00000101,0x00000303,0x00000101,0x02020303, 0x02020101,0x00000101,0x02020101,0x02020101,0x02020101,0x00000303,0x02020101,0x02020303, 0x00000303,0x00000101,0x00000303,0x02020101,0x00000303,0x00000303,0x00000303,0x02020303, 0x02020303,0x00000101,0x02020303,0x02020101,0x02020303,0x00000303,0x02020303,0x02020303, 0x00000101,0x01010101,0x00000101,0x03030101,0x00000101,0x01010303,0x00000101,0x03030303, 0x02020101,0x01010101,0x02020101,0x03030101,0x02020101,0x01010303,0x02020101,0x03030303, 0x00000303,0x01010101,0x00000303,0x03030101,0x00000303,0x01010303,0x00000303,0x03030303, 0x02020303,0x01010101,0x02020303,0x03030101,0x02020303,0x01010303,0x02020303,0x03030303, 0x01010101,0x00000000,0x01010101,0x02020000,0x01010101,0x00000202,0x01010101,0x02020202, 0x03030101,0x00000000,0x03030101,0x02020000,0x03030101,0x00000202,0x03030101,0x02020202, 0x01010303,0x00000000,0x01010303,0x02020000,0x01010303,0x00000202,0x01010303,0x02020202, 0x03030303,0x00000000,0x03030303,0x02020000,0x03030303,0x00000202,0x03030303,0x02020202, 0x01010101,0x01010000,0x01010101,0x03030000,0x01010101,0x01010202,0x01010101,0x03030202, 0x03030101,0x01010000,0x03030101,0x03030000,0x03030101,0x01010202,0x03030101,0x03030202, 0x01010303,0x01010000,0x01010303,0x03030000,0x01010303,0x01010202,0x01010303,0x03030202, 0x03030303,0x01010000,0x03030303,0x03030000,0x03030303,0x01010202,0x03030303,0x03030202, 0x01010101,0x00000101,0x01010101,0x02020101,0x01010101,0x00000303,0x01010101,0x02020303, 0x03030101,0x00000101,0x03030101,0x02020101,0x03030101,0x00000303,0x03030101,0x02020303, 0x01010303,0x00000101,0x01010303,0x02020101,0x01010303,0x00000303,0x01010303,0x02020303, 0x03030303,0x00000101,0x03030303,0x02020101,0x03030303,0x00000303,0x03030303,0x02020303, 0x01010101,0x01010101,0x01010101,0x03030101,0x01010101,0x01010303,0x01010101,0x03030303, 0x03030101,0x01010101,0x03030101,0x03030101,0x03030101,0x01010303,0x03030101,0x03030303, 0x01010303,0x01010101,0x01010303,0x03030101,0x01010303,0x01010303,0x01010303,0x03030303, 0x03030303,0x01010101,0x03030303,0x03030101,0x03030303,0x01010303,0x03030303,0x03030303 }; dword M2Map[0x200] = { 0x00000000,0x00000000,0x00000000,0x01000000,0x00000000,0x00010000,0x00000000,0x01010000, 0x00000000,0x00000100,0x00000000,0x01000100,0x00000000,0x00010100,0x00000000,0x01010100, 0x00000000,0x00000001,0x00000000,0x01000001,0x00000000,0x00010001,0x00000000,0x01010001, 0x00000000,0x00000101,0x00000000,0x01000101,0x00000000,0x00010101,0x00000000,0x01010101, 0x01000000,0x00000000,0x01000000,0x01000000,0x01000000,0x00010000,0x01000000,0x01010000, 0x01000000,0x00000100,0x01000000,0x01000100,0x01000000,0x00010100,0x01000000,0x01010100, 0x01000000,0x00000001,0x01000000,0x01000001,0x01000000,0x00010001,0x01000000,0x01010001, 0x01000000,0x00000101,0x01000000,0x01000101,0x01000000,0x00010101,0x01000000,0x01010101, 0x00010000,0x00000000,0x00010000,0x01000000,0x00010000,0x00010000,0x00010000,0x01010000, 0x00010000,0x00000100,0x00010000,0x01000100,0x00010000,0x00010100,0x00010000,0x01010100, 0x00010000,0x00000001,0x00010000,0x01000001,0x00010000,0x00010001,0x00010000,0x01010001, 0x00010000,0x00000101,0x00010000,0x01000101,0x00010000,0x00010101,0x00010000,0x01010101, 0x01010000,0x00000000,0x01010000,0x01000000,0x01010000,0x00010000,0x01010000,0x01010000, 0x01010000,0x00000100,0x01010000,0x01000100,0x01010000,0x00010100,0x01010000,0x01010100, 0x01010000,0x00000001,0x01010000,0x01000001,0x01010000,0x00010001,0x01010000,0x01010001, 0x01010000,0x00000101,0x01010000,0x01000101,0x01010000,0x00010101,0x01010000,0x01010101, 0x00000100,0x00000000,0x00000100,0x01000000,0x00000100,0x00010000,0x00000100,0x01010000, 0x00000100,0x00000100,0x00000100,0x01000100,0x00000100,0x00010100,0x00000100,0x01010100, 0x00000100,0x00000001,0x00000100,0x01000001,0x00000100,0x00010001,0x00000100,0x01010001, 0x00000100,0x00000101,0x00000100,0x01000101,0x00000100,0x00010101,0x00000100,0x01010101, 0x01000100,0x00000000,0x01000100,0x01000000,0x01000100,0x00010000,0x01000100,0x01010000, 0x01000100,0x00000100,0x01000100,0x01000100,0x01000100,0x00010100,0x01000100,0x01010100, 0x01000100,0x00000001,0x01000100,0x01000001,0x01000100,0x00010001,0x01000100,0x01010001, 0x01000100,0x00000101,0x01000100,0x01000101,0x01000100,0x00010101,0x01000100,0x01010101, 0x00010100,0x00000000,0x00010100,0x01000000,0x00010100,0x00010000,0x00010100,0x01010000, 0x00010100,0x00000100,0x00010100,0x01000100,0x00010100,0x00010100,0x00010100,0x01010100, 0x00010100,0x00000001,0x00010100,0x01000001,0x00010100,0x00010001,0x00010100,0x01010001, 0x00010100,0x00000101,0x00010100,0x01000101,0x00010100,0x00010101,0x00010100,0x01010101, 0x01010100,0x00000000,0x01010100,0x01000000,0x01010100,0x00010000,0x01010100,0x01010000, 0x01010100,0x00000100,0x01010100,0x01000100,0x01010100,0x00010100,0x01010100,0x01010100, 0x01010100,0x00000001,0x01010100,0x01000001,0x01010100,0x00010001,0x01010100,0x01010001, 0x01010100,0x00000101,0x01010100,0x01000101,0x01010100,0x00010101,0x01010100,0x01010101, 0x00000001,0x00000000,0x00000001,0x01000000,0x00000001,0x00010000,0x00000001,0x01010000, 0x00000001,0x00000100,0x00000001,0x01000100,0x00000001,0x00010100,0x00000001,0x01010100, 0x00000001,0x00000001,0x00000001,0x01000001,0x00000001,0x00010001,0x00000001,0x01010001, 0x00000001,0x00000101,0x00000001,0x01000101,0x00000001,0x00010101,0x00000001,0x01010101, 0x01000001,0x00000000,0x01000001,0x01000000,0x01000001,0x00010000,0x01000001,0x01010000, 0x01000001,0x00000100,0x01000001,0x01000100,0x01000001,0x00010100,0x01000001,0x01010100, 0x01000001,0x00000001,0x01000001,0x01000001,0x01000001,0x00010001,0x01000001,0x01010001, 0x01000001,0x00000101,0x01000001,0x01000101,0x01000001,0x00010101,0x01000001,0x01010101, 0x00010001,0x00000000,0x00010001,0x01000000,0x00010001,0x00010000,0x00010001,0x01010000, 0x00010001,0x00000100,0x00010001,0x01000100,0x00010001,0x00010100,0x00010001,0x01010100, 0x00010001,0x00000001,0x00010001,0x01000001,0x00010001,0x00010001,0x00010001,0x01010001, 0x00010001,0x00000101,0x00010001,0x01000101,0x00010001,0x00010101,0x00010001,0x01010101, 0x01010001,0x00000000,0x01010001,0x01000000,0x01010001,0x00010000,0x01010001,0x01010000, 0x01010001,0x00000100,0x01010001,0x01000100,0x01010001,0x00010100,0x01010001,0x01010100, 0x01010001,0x00000001,0x01010001,0x01000001,0x01010001,0x00010001,0x01010001,0x01010001, 0x01010001,0x00000101,0x01010001,0x01000101,0x01010001,0x00010101,0x01010001,0x01010101, 0x00000101,0x00000000,0x00000101,0x01000000,0x00000101,0x00010000,0x00000101,0x01010000, 0x00000101,0x00000100,0x00000101,0x01000100,0x00000101,0x00010100,0x00000101,0x01010100, 0x00000101,0x00000001,0x00000101,0x01000001,0x00000101,0x00010001,0x00000101,0x01010001, 0x00000101,0x00000101,0x00000101,0x01000101,0x00000101,0x00010101,0x00000101,0x01010101, 0x01000101,0x00000000,0x01000101,0x01000000,0x01000101,0x00010000,0x01000101,0x01010000, 0x01000101,0x00000100,0x01000101,0x01000100,0x01000101,0x00010100,0x01000101,0x01010100, 0x01000101,0x00000001,0x01000101,0x01000001,0x01000101,0x00010001,0x01000101,0x01010001, 0x01000101,0x00000101,0x01000101,0x01000101,0x01000101,0x00010101,0x01000101,0x01010101, 0x00010101,0x00000000,0x00010101,0x01000000,0x00010101,0x00010000,0x00010101,0x01010000, 0x00010101,0x00000100,0x00010101,0x01000100,0x00010101,0x00010100,0x00010101,0x01010100, 0x00010101,0x00000001,0x00010101,0x01000001,0x00010101,0x00010001,0x00010101,0x01010001, 0x00010101,0x00000101,0x00010101,0x01000101,0x00010101,0x00010101,0x00010101,0x01010101, 0x01010101,0x00000000,0x01010101,0x01000000,0x01010101,0x00010000,0x01010101,0x01010000, 0x01010101,0x00000100,0x01010101,0x01000100,0x01010101,0x00010100,0x01010101,0x01010100, 0x01010101,0x00000001,0x01010101,0x01000001,0x01010101,0x00010001,0x01010101,0x01010001, 0x01010101,0x00000101,0x01010101,0x01000101,0x01010101,0x00010101,0x01010101,0x01010101 }; dword M3Map[0x200] = { 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202, 0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000, 0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202, 0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000, 0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202, 0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000, 0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202, 0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000,0x02020202,0x00000000, 0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101, 0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303, 0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101, 0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303, 0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101, 0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303, 0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101, 0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303, 0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101, 0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303, 0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101, 0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303, 0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101, 0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303, 0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101, 0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303, 0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000, 0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202, 0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000, 0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202, 0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000, 0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202, 0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000, 0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202, 0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000, 0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202, 0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000, 0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202, 0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000,0x01010101,0x00000000, 0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202,0x01010101,0x02020202, 0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000,0x03030303,0x00000000, 0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202,0x03030303,0x02020202, 0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101, 0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303, 0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101, 0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101, 0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303, 0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101, 0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101, 0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303, 0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101, 0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101,0x01010101, 0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303, 0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101,0x03030303,0x01010101, 0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303,0x03030303 }; dword M0hMap[0x100] = { 0x00000000,0x08080000,0x00000808,0x08080808,0x02020000,0x0A0A0000,0x02020808,0x0A0A0808, 0x00000202,0x08080202,0x00000A0A,0x08080A0A,0x02020202,0x0A0A0202,0x02020A0A,0x0A0A0A0A, 0x04040000,0x0C0C0000,0x04040808,0x0C0C0808,0x06060000,0x0E0E0000,0x06060808,0x0E0E0808, 0x04040202,0x0C0C0202,0x04040A0A,0x0C0C0A0A,0x06060202,0x0E0E0202,0x06060A0A,0x0E0E0A0A, 0x00000404,0x08080404,0x00000C0C,0x08080C0C,0x02020404,0x0A0A0404,0x02020C0C,0x0A0A0C0C, 0x00000606,0x08080606,0x00000E0E,0x08080E0E,0x02020606,0x0A0A0606,0x02020E0E,0x0A0A0E0E, 0x04040404,0x0C0C0404,0x04040C0C,0x0C0C0C0C,0x06060404,0x0E0E0404,0x06060C0C,0x0E0E0C0C, 0x04040606,0x0C0C0606,0x04040E0E,0x0C0C0E0E,0x06060606,0x0E0E0606,0x06060E0E,0x0E0E0E0E, 0x01010000,0x09090000,0x01010808,0x09090808,0x03030000,0x0B0B0000,0x03030808,0x0B0B0808, 0x01010202,0x09090202,0x01010A0A,0x09090A0A,0x03030202,0x0B0B0202,0x03030A0A,0x0B0B0A0A, 0x05050000,0x0D0D0000,0x05050808,0x0D0D0808,0x07070000,0x0F0F0000,0x07070808,0x0F0F0808, 0x05050202,0x0D0D0202,0x05050A0A,0x0D0D0A0A,0x07070202,0x0F0F0202,0x07070A0A,0x0F0F0A0A, 0x01010404,0x09090404,0x01010C0C,0x09090C0C,0x03030404,0x0B0B0404,0x03030C0C,0x0B0B0C0C, 0x01010606,0x09090606,0x01010E0E,0x09090E0E,0x03030606,0x0B0B0606,0x03030E0E,0x0B0B0E0E, 0x05050404,0x0D0D0404,0x05050C0C,0x0D0D0C0C,0x07070404,0x0F0F0404,0x07070C0C,0x0F0F0C0C, 0x05050606,0x0D0D0606,0x05050E0E,0x0D0D0E0E,0x07070606,0x0F0F0606,0x07070E0E,0x0F0F0E0E, 0x00000101,0x08080101,0x00000909,0x08080909,0x02020101,0x0A0A0101,0x02020909,0x0A0A0909, 0x00000303,0x08080303,0x00000B0B,0x08080B0B,0x02020303,0x0A0A0303,0x02020B0B,0x0A0A0B0B, 0x04040101,0x0C0C0101,0x04040909,0x0C0C0909,0x06060101,0x0E0E0101,0x06060909,0x0E0E0909, 0x04040303,0x0C0C0303,0x04040B0B,0x0C0C0B0B,0x06060303,0x0E0E0303,0x06060B0B,0x0E0E0B0B, 0x00000505,0x08080505,0x00000D0D,0x08080D0D,0x02020505,0x0A0A0505,0x02020D0D,0x0A0A0D0D, 0x00000707,0x08080707,0x00000F0F,0x08080F0F,0x02020707,0x0A0A0707,0x02020F0F,0x0A0A0F0F, 0x04040505,0x0C0C0505,0x04040D0D,0x0C0C0D0D,0x06060505,0x0E0E0505,0x06060D0D,0x0E0E0D0D, 0x04040707,0x0C0C0707,0x04040F0F,0x0C0C0F0F,0x06060707,0x0E0E0707,0x06060F0F,0x0E0E0F0F, 0x01010101,0x09090101,0x01010909,0x09090909,0x03030101,0x0B0B0101,0x03030909,0x0B0B0909, 0x01010303,0x09090303,0x01010B0B,0x09090B0B,0x03030303,0x0B0B0303,0x03030B0B,0x0B0B0B0B, 0x05050101,0x0D0D0101,0x05050909,0x0D0D0909,0x07070101,0x0F0F0101,0x07070909,0x0F0F0909, 0x05050303,0x0D0D0303,0x05050B0B,0x0D0D0B0B,0x07070303,0x0F0F0303,0x07070B0B,0x0F0F0B0B, 0x01010505,0x09090505,0x01010D0D,0x09090D0D,0x03030505,0x0B0B0505,0x03030D0D,0x0B0B0D0D, 0x01010707,0x09090707,0x01010F0F,0x09090F0F,0x03030707,0x0B0B0707,0x03030F0F,0x0B0B0F0F, 0x05050505,0x0D0D0505,0x05050D0D,0x0D0D0D0D,0x07070505,0x0F0F0505,0x07070D0D,0x0F0F0D0D, 0x05050707,0x0D0D0707,0x05050F0F,0x0D0D0F0F,0x07070707,0x0F0F0707,0x07070F0F,0x0F0F0F0F }; dword M1hMap[0x100] = { 0x00000000,0x02000000,0x00020000,0x02020000,0x00000200,0x02000200,0x00020200,0x02020200, 0x00000002,0x02000002,0x00020002,0x02020002,0x00000202,0x02000202,0x00020202,0x02020202, 0x01000000,0x03000000,0x01020000,0x03020000,0x01000200,0x03000200,0x01020200,0x03020200, 0x01000002,0x03000002,0x01020002,0x03020002,0x01000202,0x03000202,0x01020202,0x03020202, 0x00010000,0x02010000,0x00030000,0x02030000,0x00010200,0x02010200,0x00030200,0x02030200, 0x00010002,0x02010002,0x00030002,0x02030002,0x00010202,0x02010202,0x00030202,0x02030202, 0x01010000,0x03010000,0x01030000,0x03030000,0x01010200,0x03010200,0x01030200,0x03030200, 0x01010002,0x03010002,0x01030002,0x03030002,0x01010202,0x03010202,0x01030202,0x03030202, 0x00000100,0x02000100,0x00020100,0x02020100,0x00000300,0x02000300,0x00020300,0x02020300, 0x00000102,0x02000102,0x00020102,0x02020102,0x00000302,0x02000302,0x00020302,0x02020302, 0x01000100,0x03000100,0x01020100,0x03020100,0x01000300,0x03000300,0x01020300,0x03020300, 0x01000102,0x03000102,0x01020102,0x03020102,0x01000302,0x03000302,0x01020302,0x03020302, 0x00010100,0x02010100,0x00030100,0x02030100,0x00010300,0x02010300,0x00030300,0x02030300, 0x00010102,0x02010102,0x00030102,0x02030102,0x00010302,0x02010302,0x00030302,0x02030302, 0x01010100,0x03010100,0x01030100,0x03030100,0x01010300,0x03010300,0x01030300,0x03030300, 0x01010102,0x03010102,0x01030102,0x03030102,0x01010302,0x03010302,0x01030302,0x03030302, 0x00000001,0x02000001,0x00020001,0x02020001,0x00000201,0x02000201,0x00020201,0x02020201, 0x00000003,0x02000003,0x00020003,0x02020003,0x00000203,0x02000203,0x00020203,0x02020203, 0x01000001,0x03000001,0x01020001,0x03020001,0x01000201,0x03000201,0x01020201,0x03020201, 0x01000003,0x03000003,0x01020003,0x03020003,0x01000203,0x03000203,0x01020203,0x03020203, 0x00010001,0x02010001,0x00030001,0x02030001,0x00010201,0x02010201,0x00030201,0x02030201, 0x00010003,0x02010003,0x00030003,0x02030003,0x00010203,0x02010203,0x00030203,0x02030203, 0x01010001,0x03010001,0x01030001,0x03030001,0x01010201,0x03010201,0x01030201,0x03030201, 0x01010003,0x03010003,0x01030003,0x03030003,0x01010203,0x03010203,0x01030203,0x03030203, 0x00000101,0x02000101,0x00020101,0x02020101,0x00000301,0x02000301,0x00020301,0x02020301, 0x00000103,0x02000103,0x00020103,0x02020103,0x00000303,0x02000303,0x00020303,0x02020303, 0x01000101,0x03000101,0x01020101,0x03020101,0x01000301,0x03000301,0x01020301,0x03020301, 0x01000103,0x03000103,0x01020103,0x03020103,0x01000303,0x03000303,0x01020303,0x03020303, 0x00010101,0x02010101,0x00030101,0x02030101,0x00010301,0x02010301,0x00030301,0x02030301, 0x00010103,0x02010103,0x00030103,0x02030103,0x00010303,0x02010303,0x00030303,0x02030303, 0x01010101,0x03010101,0x01030101,0x03030101,0x01010301,0x03010301,0x01030301,0x03030301, 0x01010103,0x03010103,0x01030103,0x03030103,0x01010303,0x03010303,0x01030303,0x03030303 }; // 0x21 = 33 is the anti-aliasing color for mode 2 in halved resolution dword M2hMap[0x100] = { 0x00000000,0x21000000,0x21000000,0x01000000,0x00210000,0x21210000,0x21210000,0x01210000, 0x00210000,0x21210000,0x21210000,0x01210000,0x00010000,0x21010000,0x21010000,0x01010000, 0x00002100,0x21002100,0x21002100,0x01002100,0x00212100,0x21212100,0x21212100,0x01212100, 0x00212100,0x21212100,0x21212100,0x01212100,0x00012100,0x21012100,0x21012100,0x01012100, 0x00002100,0x21002100,0x21002100,0x01002100,0x00212100,0x21212100,0x21212100,0x01212100, 0x00212100,0x21212100,0x21212100,0x01212100,0x00012100,0x21012100,0x21012100,0x01012100, 0x00000100,0x21000100,0x21000100,0x01000100,0x00210100,0x21210100,0x21210100,0x01210100, 0x00210100,0x21210100,0x21210100,0x01210100,0x00010100,0x21010100,0x21010100,0x01010100, 0x00000021,0x21000021,0x21000021,0x01000021,0x00210021,0x21210021,0x21210021,0x01210021, 0x00210021,0x21210021,0x21210021,0x01210021,0x00010021,0x21010021,0x21010021,0x01010021, 0x00002121,0x21002121,0x21002121,0x01002121,0x00212121,0x21212121,0x21212121,0x01212121, 0x00212121,0x21212121,0x21212121,0x01212121,0x00012121,0x21012121,0x21012121,0x01012121, 0x00002121,0x21002121,0x21002121,0x01002121,0x00212121,0x21212121,0x21212121,0x01212121, 0x00212121,0x21212121,0x21212121,0x01212121,0x00012121,0x21012121,0x21012121,0x01012121, 0x00000121,0x21000121,0x21000121,0x01000121,0x00210121,0x21210121,0x21210121,0x01210121, 0x00210121,0x21210121,0x21210121,0x01210121,0x00010121,0x21010121,0x21010121,0x01010121, 0x00000021,0x21000021,0x21000021,0x01000021,0x00210021,0x21210021,0x21210021,0x01210021, 0x00210021,0x21210021,0x21210021,0x01210021,0x00010021,0x21010021,0x21010021,0x01010021, 0x00002121,0x21002121,0x21002121,0x01002121,0x00212121,0x21212121,0x21212121,0x01212121, 0x00212121,0x21212121,0x21212121,0x01212121,0x00012121,0x21012121,0x21012121,0x01012121, 0x00002121,0x21002121,0x21002121,0x01002121,0x00212121,0x21212121,0x21212121,0x01212121, 0x00212121,0x21212121,0x21212121,0x01212121,0x00012121,0x21012121,0x21012121,0x01012121, 0x00000121,0x21000121,0x21000121,0x01000121,0x00210121,0x21210121,0x21210121,0x01210121, 0x00210121,0x21210121,0x21210121,0x01210121,0x00010121,0x21010121,0x21010121,0x01010121, 0x00000001,0x21000001,0x21000001,0x01000001,0x00210001,0x21210001,0x21210001,0x01210001, 0x00210001,0x21210001,0x21210001,0x01210001,0x00010001,0x21010001,0x21010001,0x01010001, 0x00002101,0x21002101,0x21002101,0x01002101,0x00212101,0x21212101,0x21212101,0x01212101, 0x00212101,0x21212101,0x21212101,0x01212101,0x00012101,0x21012101,0x21012101,0x01012101, 0x00002101,0x21002101,0x21002101,0x01002101,0x00212101,0x21212101,0x21212101,0x01212101, 0x00212101,0x21212101,0x21212101,0x01212101,0x00012101,0x21012101,0x21012101,0x01012101, 0x00000101,0x21000101,0x21000101,0x01000101,0x00210101,0x21210101,0x21210101,0x01210101, 0x00210101,0x21210101,0x21210101,0x01210101,0x00010101,0x21010101,0x21010101,0x01010101 }; dword M3hMap[0x100] = { 0x00000000,0x00000000,0x00000000,0x00000000,0x02020000,0x02020000,0x02020000,0x02020000, 0x00000202,0x00000202,0x00000202,0x00000202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x02020000,0x02020000,0x02020000,0x02020000, 0x00000202,0x00000202,0x00000202,0x00000202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x02020000,0x02020000,0x02020000,0x02020000, 0x00000202,0x00000202,0x00000202,0x00000202,0x02020202,0x02020202,0x02020202,0x02020202, 0x00000000,0x00000000,0x00000000,0x00000000,0x02020000,0x02020000,0x02020000,0x02020000, 0x00000202,0x00000202,0x00000202,0x00000202,0x02020202,0x02020202,0x02020202,0x02020202, 0x01010000,0x01010000,0x01010000,0x01010000,0x03030000,0x03030000,0x03030000,0x03030000, 0x01010202,0x01010202,0x01010202,0x01010202,0x03030202,0x03030202,0x03030202,0x03030202, 0x01010000,0x01010000,0x01010000,0x01010000,0x03030000,0x03030000,0x03030000,0x03030000, 0x01010202,0x01010202,0x01010202,0x01010202,0x03030202,0x03030202,0x03030202,0x03030202, 0x01010000,0x01010000,0x01010000,0x01010000,0x03030000,0x03030000,0x03030000,0x03030000, 0x01010202,0x01010202,0x01010202,0x01010202,0x03030202,0x03030202,0x03030202,0x03030202, 0x01010000,0x01010000,0x01010000,0x01010000,0x03030000,0x03030000,0x03030000,0x03030000, 0x01010202,0x01010202,0x01010202,0x01010202,0x03030202,0x03030202,0x03030202,0x03030202, 0x00000101,0x00000101,0x00000101,0x00000101,0x02020101,0x02020101,0x02020101,0x02020101, 0x00000303,0x00000303,0x00000303,0x00000303,0x02020303,0x02020303,0x02020303,0x02020303, 0x00000101,0x00000101,0x00000101,0x00000101,0x02020101,0x02020101,0x02020101,0x02020101, 0x00000303,0x00000303,0x00000303,0x00000303,0x02020303,0x02020303,0x02020303,0x02020303, 0x00000101,0x00000101,0x00000101,0x00000101,0x02020101,0x02020101,0x02020101,0x02020101, 0x00000303,0x00000303,0x00000303,0x00000303,0x02020303,0x02020303,0x02020303,0x02020303, 0x00000101,0x00000101,0x00000101,0x00000101,0x02020101,0x02020101,0x02020101,0x02020101, 0x00000303,0x00000303,0x00000303,0x00000303,0x02020303,0x02020303,0x02020303,0x02020303, 0x01010101,0x01010101,0x01010101,0x01010101,0x03030101,0x03030101,0x03030101,0x03030101, 0x01010303,0x01010303,0x01010303,0x01010303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x03030101,0x03030101,0x03030101,0x03030101, 0x01010303,0x01010303,0x01010303,0x01010303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x03030101,0x03030101,0x03030101,0x03030101, 0x01010303,0x01010303,0x01010303,0x01010303,0x03030303,0x03030303,0x03030303,0x03030303, 0x01010101,0x01010101,0x01010101,0x01010101,0x03030101,0x03030101,0x03030101,0x03030101, 0x01010303,0x01010303,0x01010303,0x01010303,0x03030303,0x03030303,0x03030303,0x03030303 }; void update_skew() { new_dt.NewHDSPTIMG |= 0x02; // enable horizontal DISPTMG by default dword skew = (CRTC.registers[8] >> 4) & 3; // isolate the display skew if (skew == 3) { // disable output? new_dt.NewHDSPTIMG &= 0xfd; // disable horizontal DISPTMG } else { CRTC.hstart = skew; // position at which horizontal display starts CRTC.hend = CRTC.hstart + CRTC.registers[1]; // position at which it ends } if(asic.extend_border) { CRTC.hstart++; } } inline void change_mode() { if (CRTC.flag_hadhsync) { // have we had an HSYNC on this scan line? CRTC.flag_hadhsync = 0; GateArray.scr_mode = GateArray.requested_scr_mode; // execute mode change ModeMap = ModeMaps[GateArray.scr_mode]; // update ModeMap pointer } } inline void end_vdu_hsync() { int temp; CRTC.flag_inmonhsync = 0; iMonHSPeakToEnd = iMonHSPeakPos; if (HadP) { HadP = 0; if (iMonHSPeakPos >= iMonHSStartPos) { temp = iMonHSEndPos - HSyncDuration; if (temp < MonFreeSync) { if (MonFreeSync != MinHSync) { MonFreeSync--; } } else if (temp > MonFreeSync) { if (MonFreeSync != MaxHSync) { MonFreeSync++; } } temp = iMonHSPeakToEnd - iMonHSEndToPeak; if (temp < 0) { temp = -temp; if (temp > iMonHSStartPos) { temp = iMonHSStartPos; } temp >>= 3; if (!temp) { temp++; } if (temp > MAX_SYNC_INC) { temp = MAX_SYNC_INC; } MonHSYNC = MonFreeSync + temp; if (MonHSYNC > MaxHSync) { MonHSYNC = MaxHSync; } } else { if (temp > iMonHSStartPos) { temp = iMonHSStartPos; } temp >>= 3; if (!temp) { temp++; } if (temp > MAX_SYNC_DEC) { temp = MAX_SYNC_DEC; } MonHSYNC = MonFreeSync - temp; if (MonHSYNC < MinHSync) { MonHSYNC = MinHSync; } } } else { temp = iMonHSStartToPeak - iMonHSPeakToEnd; if (!temp) { MonHSYNC = MonFreeSync; } else if (temp < 0) { temp = -temp; if (temp > iMonHSStartPos) { temp = iMonHSStartPos; } temp >>= 3; if (!temp) { temp++; } if (temp > MAX_SYNC_INC) { temp = MAX_SYNC_INC; } MonHSYNC = MonFreeSync + temp; if (MonHSYNC > MaxHSync) { MonHSYNC = MaxHSync; } } else if (temp > 0) { if (temp > iMonHSStartPos) { temp = iMonHSStartPos; } temp >>= 3; if (!temp) { temp++; } if (temp > MAX_SYNC_DEC) { temp = MAX_SYNC_DEC; } MonHSYNC = MonFreeSync - temp; if (MonHSYNC < MinHSync) { MonHSYNC = MinHSync; } } } } iMonHSEndPos = 0; } inline void match_line_count() { if (CRTC.line_count == CRTC.registers[6]) { // matches vertical displayed? new_dt.NewDISPTIMG = 0; // disable vertical DISPTMG } if (CRTC.line_count == CRTC.registers[7]) { // matches vertical sync position? if (CRTC.last_hend >= 2) { // line length was at least 2 chars? if (!CRTC.r7match) { CRTC.flag_resvsync = 0; if (!CRTC.flag_invsync) { // not in VSYNC? CRTC.vsw_count = 0; // reset vertical sync width counter CRTC.flag_invsync = 1; // enter VSYNC flags1.monVSYNC = 26; // enter vertical blanking period for 26 scanlines GateArray.hs_count = 2; // GA delays its VSYNC by two CRTC HSYNCs } } } CRTC.r7match = 1; } else { CRTC.r7match = 0; } } inline void reload_addr() { if (CRTC.line_count == 0) { // has line count been reset? new_dt.NewDISPTIMG = 0xff; // enable vertical DISPTMG CRTC.addr = CRTC.next_addr = CRTC.requested_addr; // load with screen start address } match_line_count(); } inline void restart_frame() { CRTC.flag_invta = 0; CRTC.flag_resframe = 0; CRTC.flag_resscan = 0; CRTC.flag_reschar = 0; CRTC.raster_count = 0; // reset raster line counter CRTC.scr_base = 0; CRTC.line_count = 0; // reset character line counter CRTC.sl_count = 0; // reset scan line counter reload_addr(); } inline void match_hsw() { if (CRTC.hsw_count == CRTC.hsw) { // matches horizontal sync width? GateArray.sl_count++; // update GA scan line counter if (GateArray.sl_count == 52) { // trigger interrupt? if (CRTC.interrupt_sl == 0) { z80.int_pending = 1; // queue Z80 interrupt } GateArray.sl_count = 0; // clear counter } else if (CRTC.sl_count == CRTC.interrupt_sl && CRTC.interrupt_sl != 0) { z80.int_pending = 1; } if (GateArray.hs_count) { // delaying on VSYNC? GateArray.hs_count--; if (!GateArray.hs_count) { if (GateArray.sl_count >= 32 && CRTC.interrupt_sl == 0) { // counter above save margin? z80.int_pending = 1; // queue interrupt } GateArray.sl_count = 0; // clear counter } } flags1.inHSYNC = 0; // turn HSYNC off if (flags1.monVSYNC) { // in vertical blanking period? flags1.monVSYNC--; // update counter } change_mode(); // process possible mode change if (CRTC.flag_inmonhsync) { // monitor HSYNC still active? end_vdu_hsync(); } } else { CRTC.hsw_count++; // update counter CRTC.hsw_count &= 15; // limit to 4 bits if (CRTC.hsw_count == 3) { // ready to start monitor HSYNC? CRTC.flag_inmonhsync = 1; // enter monitor HSYNC iMonHSStartPos = 0; iMonHSPeakToStart = iMonHSPeakPos; asic_dma_cycle(); } else if (CRTC.hsw_count == 7) { // reached GA HSYNC output cutoff? change_mode(); end_vdu_hsync(); } } } void NoChar() { // nothing to do } void CharSL2() { CRTC.reg5 = CRTC.registers[5]; CRTC.CharInstSL = NoChar; } void CharSL1() { CRTC.CharInstSL = CharSL2; } void CharMR2() { if (CRTC.flag_startvta) { // starting vertical total adjust? if (CRTC.line_count == CRTC.registers[4]) { // matches vertical total? if (CRTC.registers[5] == 0) { // no vertical total adjust? CRTC.flag_resnext = 1; // request a frame restart } } } CRTC.CharInstMR = NoChar; } void CharMR1() { if ((CRTC.raster_count == CRTC.registers[9]) && (CRTC.line_count == CRTC.registers[4])) { CRTC.flag_invta = 0; CRTC.flag_startvta = 1; // request start of vertical total adjust } else { CRTC.flag_startvta = 0; // not yet at end of frame } CRTC.CharInstMR = CharMR2; } void frame_finished() { /* if (VDU.scrln < MAX_DRAWN) { // monitor line below maximum visible? int cnt = (MAX_DRAWN - VDU.scrln) << 1; // number of lines remaining to be drawn dword *addr = CPC.scr_base; while (cnt--) { dword *tmp_addr = addr; for (int n = CPC.scr_bpp * 24; n; n--) { *tmp_addr++ = 0; // clear old surface contents } addr += CPC.scr_bps; // advance surface pointer } } */ VDU.frame_completed = 1; // emulation loop exit condition met VDU.scrln = -(((VDU.scanline - MIN_VHOLD) + 1) >> 1); VDU.scanline = 0; VDU.flag_drawing = 0; } void prerender_border() { dword dwVal = 0x10101010; *RendPos = dwVal; *(RendPos + 1) = dwVal; *(RendPos + 2) = dwVal; *(RendPos + 3) = dwVal; RendPos += 4; } void prerender_border_half() { dword dwVal = 0x10101010; *RendPos = dwVal; *(RendPos + 1) = dwVal; RendPos += 2; } void prerender_sync() { dword dwVal = 0x11111111; *RendPos = dwVal; *(RendPos + 1) = dwVal; *(RendPos + 2) = dwVal; *(RendPos + 3) = dwVal; RendPos += 4; } void prerender_sync_half() { dword dwVal = 0x11111111; *RendPos = dwVal; *(RendPos + 1) = dwVal; RendPos += 2; } static inline byte getRAMByte(int video_address) { return *(pbRAM + video_address); } dword shiftLittleEndianDwordTriplet(dword val1, dword val2, dword val3, unsigned int byteShift) { if (byteShift == 0) { return val3; } if (byteShift == 4) { return val2; } if (byteShift >= 8) { return val1; } if (byteShift < 4) { int bitShift = 8 * byteShift; return (val3 << bitShift) | (val2 >> (32 - bitShift)); } int bitShift = 8 * (byteShift - 4); return (val2 << bitShift) | (val1 >> (32 - bitShift)); } void prerender_normal() { byte bVidMem = getRAMByte(CRTC.next_address); *RendPos = *(ModeMap + (bVidMem * 2)); *(RendPos + 1) = *(ModeMap + (bVidMem * 2) + 1); bVidMem = getRAMByte(CRTC.next_address + 1); *(RendPos + 2) = *(ModeMap + (bVidMem * 2)); *(RendPos + 3) = *(ModeMap + (bVidMem * 2) + 1); RendPos += 4; } void prerender_normal_plus() { unsigned int byteOffset = asic.hscroll / 8; unsigned int byteShift = asic.hscroll % 8; unsigned int next_address = CRTC.next_address; if(asic.vscroll) { if (CRTC.raster_count + asic.vscroll <= CRTC.registers[9]) { next_address += asic.vscroll * 0x0800; } else { next_address += 80; next_address -= ((CRTC.registers[9] + 1 - asic.vscroll) * 0x0800); } } byte bVidMem1 = getRAMByte(next_address - byteOffset - 1); byte bVidMem2 = getRAMByte(next_address - byteOffset); dword val1, val2, val3, val4; val1 = *(ModeMap + (bVidMem1 * 2)); val2 = *(ModeMap + (bVidMem1 * 2) + 1); val3 = *(ModeMap + (bVidMem2 * 2)); val4 = *(ModeMap + (bVidMem2 * 2) + 1); *RendPos = shiftLittleEndianDwordTriplet(val1, val2, val3, byteShift); *(RendPos + 1) = shiftLittleEndianDwordTriplet(val2, val3, val4, byteShift); bVidMem1 = getRAMByte(next_address - byteOffset + 1); val1 = *(ModeMap + (bVidMem2 * 2)); val2 = *(ModeMap + (bVidMem2 * 2) + 1); val3 = *(ModeMap + (bVidMem1 * 2)); val4 = *(ModeMap + (bVidMem1 * 2) + 1); *(RendPos + 2) = shiftLittleEndianDwordTriplet(val1, val2, val3, byteShift); *(RendPos + 3) = shiftLittleEndianDwordTriplet(val2, val3, val4, byteShift); RendPos += 4; } void prerender_normal_half() { byte bVidMem = getRAMByte(CRTC.next_address); *RendPos = *(ModeMap + bVidMem); bVidMem = getRAMByte(CRTC.next_address + 1); *(RendPos + 1) = *(ModeMap + bVidMem); RendPos += 2; } void prerender_normal_half_plus() { unsigned int byteOffset = (asic.hscroll / 2) / 4; unsigned int byteShift = ((asic.hscroll / 2) % 4); unsigned int next_address = CRTC.next_address; if(asic.vscroll) { if (CRTC.raster_count + asic.vscroll <= CRTC.registers[9]) { next_address += asic.vscroll * 0x0800; } else { next_address += 80; next_address -= ((CRTC.registers[9] + 1 - asic.vscroll) * 0x0800); } } byte bVidMem1 = getRAMByte(next_address - byteOffset - 1); byte bVidMem2 = getRAMByte(next_address - byteOffset); dword val1, val2; val1 = *(ModeMap + bVidMem1); val2 = *(ModeMap + bVidMem2); *RendPos = shiftLittleEndianDwordTriplet(0, val1, val2, byteShift); bVidMem1 = getRAMByte(next_address - byteOffset + 1); val1 = *(ModeMap + bVidMem2); val2 = *(ModeMap + bVidMem1); *(RendPos + 1) = shiftLittleEndianDwordTriplet(0, val1, val2, byteShift); RendPos += 2; } void set_prerender() { LastPreRend = flags1.combined; if (LastPreRend == 0x03ff0000) { PreRender = CPC.scr_prerendernorm; } else { if (!static_cast<word>(LastPreRend)) { PreRender = CPC.scr_prerenderbord; } else { PreRender = CPC.scr_prerendersync; } } } unsigned int getPixel() { return GateArray.palette[*RendOut++]; } void render8bpp() { byte bCount = *RendWid++; while (bCount--) { byte val = getPixel(); *CPC.scr_pos++ = val; } } void render8bpp_doubleY() { byte bCount = *RendWid++; while (bCount--) { byte val = getPixel(); *(CPC.scr_pos + CPC.scr_bps) = val; *CPC.scr_pos++ = val; } } void render16bpp() { byte bCount = *RendWid++; while (bCount--) { word val = getPixel(); *reinterpret_cast<word*>(CPC.scr_pos) = val; CPC.scr_pos += 2; } } void render16bpp_doubleY() { byte bCount = *RendWid++; while (bCount--) { word val = getPixel(); *reinterpret_cast<word*>(CPC.scr_pos) = val; *(reinterpret_cast<word*>(CPC.scr_pos + CPC.scr_bps)) = val; CPC.scr_pos += 2; } } void render24bpp() { byte bCount = *RendWid++; while (bCount--) { dword val = getPixel(); *reinterpret_cast<word *>(CPC.scr_pos) = static_cast<word>(val); *(CPC.scr_pos + 2) = static_cast<byte>(val >> 16); CPC.scr_pos += 3; } } void render24bpp_doubleY() { byte bCount = *RendWid++; while (bCount--) { dword val = getPixel(); *reinterpret_cast<word *>(CPC.scr_pos + CPC.scr_bps) = static_cast<word>(val); *reinterpret_cast<word *>(CPC.scr_pos) = static_cast<word>(val); val >>= 16; CPC.scr_pos += 2; *(CPC.scr_pos + CPC.scr_bps) = static_cast<byte>(val); *(CPC.scr_pos) = static_cast<byte>(val); CPC.scr_pos++; } } void render32bpp() { byte bCount = *RendWid++; while (bCount--) { dword val = getPixel(); *reinterpret_cast<dword*>(CPC.scr_pos) = val; CPC.scr_pos += 4; } } void render32bpp_doubleY() { byte bCount = *RendWid++; while (bCount--) { dword val = getPixel(); *reinterpret_cast<dword*>(CPC.scr_pos) = val; *(reinterpret_cast<dword*>(CPC.scr_pos + CPC.scr_bps)) = val; CPC.scr_pos += 4; } } void crtc_cycle(int repeat_count) { while (repeat_count) { if (VDU.flag_drawing) { // are we within the rendering area? if (HorzChar < HorzMax) { // below horizontal cut-off? if (flags1.combined != LastPreRend) { set_prerender(); // change pre-renderer if necessary } PreRender(); // translate CPC video memory bytes to entries referencing the palette CPC.scr_render(); // render to the video surface at the current bit depth } } // https://www.cpcwiki.eu/index.php/Amstrad_Magnum_Phaser#Technical // If the trigger of the phazer is released, the CRTC continuously updates R16 and R17 (handled in OUT handler). // If the trigger is pressed, it only updates it when the phazer receives light from the screen. if (CPC.phazer_pressed) { unsigned int x = ((CPC.scr_pos - CPC.scr_base) * 8) / CPC.scr_bpp; unsigned int y = VDU.scrln*CPC.dwYScale; // Why the +4? I have absolutely no idea, but this works. Without it, the position is shifted // slightly to the left. auto address = CRTC.addr + CRTC.char_count + 4; if (CPC.phazer_x >= x && CPC.phazer_x < x + 16 && CPC.phazer_y >= y && CPC.phazer_y < y + 2) { CRTC.registers[16] = address >> 8; CRTC.registers[17] = address & 0xFF; } } CRTC.next_address = MAXlate[(CRTC.addr + CRTC.char_count) & 0x73ff] | CRTC.scr_base; // next address for PreRender flags1.dt.combined = new_dt.combined; // update the DISPTMG flags #ifdef DEBUG_CRTC if (dwDebugFlag) { char str[16]; char on[] = "vhDDHVMa"; char off[] = "........"; if (CRTC.flag_invsync) { str[0] = on[0]; } else { str[0] = off[0]; } if (flags1.inHSYNC) { str[1] = on[1]; } else { str[1] = off[1]; } if (flags1.dt.HDSPTIMG & 1) { str[2] = on[2]; } else { str[2] = off[2]; } if (flags1.dt.DISPTIMG) { str[3] = on[3]; } else { str[3] = off[3]; } if (CRTC.flag_newscan) { str[4] = on[4]; } else { str[4] = off[4]; } if (CRTC.flag_resframe) { str[5] = on[5]; } else { str[5] = off[5]; } if (CRTC.flag_resscan) { str[6] = on[6]; } else { str[6] = off[6]; } if (CRTC.flag_invta) { str[7] = on[7]; } else { str[7] = off[7]; } str[8] = '\0'; fprintf(pfoDebug, "%04X | CC:%2X RC:%2X LC:%2X - HSWC:%2X VSWC:%2X - %s %c %2X mhs%04X mfs%04X s%04X p%04X e%04X p%04X c%d\r\n", CRTC.next_address, CRTC.char_count, CRTC.raster_count, CRTC.line_count, CRTC.hsw_count, CRTC.vsw_count, str, z80.int_pending ? 'I' : '.', GateArray.sl_count, MonHSYNC, MonFreeSync, iMonHSStartPos, iMonHSPeakPos, iMonHSEndPos, HorzPos, HorzChar); } #endif iMonHSStartPos += 0x100; iMonHSEndPos += 0x100; iMonHSPeakPos += 0x100; HorzPos += 0x100; HorzChar++; if (HorzPos >= MonHSYNC) { if (VDU.flag_drawing) { CPC.scr_base += CPC.scr_line_offs; // advance surface pointer to next row } HadP = 1; iMonHSPeakPos = HorzPos - MonHSYNC; iMonHSStartToPeak = iMonHSStartPos - iMonHSPeakPos; iMonHSEndToPeak = iMonHSEndPos - iMonHSPeakPos; HorzPos = iMonHSPeakPos - HSyncDuration; HorzChar = HorzPos >> 8; dword val = (HorzPos & 0xf0) >> PosShift; if (!val) { HorzMax = 48; HorzPix[0] = HorzPix[1]; RendPos = RendStart; HorzChar--; } else { RendPos = reinterpret_cast<dword *>(&RendBuff[val]); int tmp = reinterpret_cast<byte *>(RendStart) - reinterpret_cast<byte *>(RendPos); HorzPix[48] = static_cast<byte>(tmp); HorzPix[0] = HorzPix[1] - static_cast<byte>(tmp); HorzMax = 49; } RendOut = reinterpret_cast<byte *>(RendStart); RendWid = &HorzPix[0]; CPC.scr_pos = CPC.scr_base; VDU.scrln++; VDU.scanline++; if (static_cast<dword>(VDU.scrln) >= MAX_DRAWN) { VDU.flag_drawing = 0; } else { VDU.flag_drawing = 1; } } // ---------------------------------------------------------------------------- if (CRTC.char_count == CRTC.registers[0]) { // matches horizontal total? CRTC.last_hend = CRTC.char_count; // preserve current line length in chars CRTC.flag_newscan = 1; // request starting a new scan line CRTC.char_count = 0; // reset the horizontal character count } else { CRTC.char_count++; // update counter CRTC.char_count &= 255; // limit to 8 bits } if (CRTC.char_count == CRTC.registers[0]) { // matches horizontal total? if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? CRTC.flag_reschar = 1; // request a line count update } else { CRTC.flag_reschar = 0; // still within the current character line } if (CRTC.flag_resnext) { // ready to restart frame? CRTC.flag_resnext = 0; CRTC.flag_resframe = 1; // request a frame restart } if (CRTC.flag_startvta) { // ready to start vertical total adjust? CRTC.flag_startvta = 0; CRTC.flag_invta = 1; // entering vertical total adjust } if (CRTC.flag_invta) { // in vertical total adjust? if ((CRTC.raster_count == CRTC.registers[9]) && (CRTC.line_count == CRTC.registers[4])) { CRTC.flag_resscan = 1; // raster counter only resets once at start of vta } else { CRTC.flag_resscan = 0; // raster counter keeps increasing while in vta } } } if (CRTC.char_count == CRTC.registers[1]) { // matches horizontal displayed? if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? CRTC.next_addr = CRTC.addr + CRTC.char_count; } } if (!flags1.inHSYNC) { // not in HSYNC? if (CRTC.char_count == CRTC.registers[2]) { // matches horizontal sync position? flags1.inHSYNC = 0xff; // turn HSYNC on CRTC.flag_hadhsync = 1; // prevent GA from processing more than one HSYNC per scan line CRTC.hsw_count = 0; // initialize horizontal sync width counter match_hsw(); } } else { match_hsw(); } CRTC.CharInstSL(); // if necessary, process vertical total delay CRTC.CharInstMR(); // if necessary, process maximum raster count delay if (CRTC.flag_newscan) { // scanline change requested? CRTC.flag_newscan = 0; if (CRTC.split_sl && CRTC.sl_count == CRTC.split_sl) { CRTC.next_addr = CRTC.split_addr; } CRTC.addr = CRTC.next_addr; CRTC.sl_count++; if (CRTC.flag_invsync) { // VSYNC active? CRTC.vsw_count++; // update counter CRTC.vsw_count &= 15; // limit to 4 bits if (CRTC.vsw_count == CRTC.vsw) { // matches vertical sync width? CRTC.vsw_count = 0; // reset counter CRTC.flag_resvsync = 1; // request VSYNC reset } } if (CRTC.flag_resframe) { // frame restart requested? restart_frame(); } else { if (CRTC.flag_resscan) { // raster counter reset requested? CRTC.flag_resscan = 0; CRTC.raster_count = 0; // reset counter CRTC.scr_base = 0; } else { CRTC.raster_count++; // update counter CRTC.raster_count &= 31; // limit to 5 bits if (!CRTC.raster_count) { // did the counter wrap around? match_line_count(); } CRTC.scr_base = (CRTC.scr_base + 0x0800) & 0x3800; } } CRTC.CharInstSL = CharSL1; dword temp = 0; if (CRTC.raster_count == CRTC.registers[9]) { // matches maximum raster address? temp = 1; CRTC.flag_resscan = 1; // request a raster counter reset } if (CRTC.r9match != temp) { CRTC.r9match = temp; } if (temp) { CRTC.CharInstMR = CharMR1; } if (CRTC.flag_invta) { // in vertical total adjust? if (CRTC.raster_count == CRTC.reg5) { // matches vertical total adjust? restart_frame(); if (CRTC.registers[9] == 0) { // maximum raster address is zero? CRTC.flag_resscan = 1; // request a raster counter reset } } } if (CRTC.flag_reschar) { // line count update requested? CRTC.line_count++; // update counter CRTC.line_count &= 127; // limit to 7 bits reload_addr(); } if (CRTC.flag_invsync) { // in VSYNC? if (CRTC.flag_resvsync) { // end of VSYNC? CRTC.flag_invsync = 0; // turn VSYNC off CRTC.flag_resvsync = 0; if (VDU.scanline == MaxVSync) { // above maximum scanline count? frame_finished(); } } else { if (VDU.scanline > MinVSync) { // above minimum scanline count? frame_finished(); } } } else if (VDU.scanline == MaxVSync) { // above maximum scanline count? frame_finished(); } } if (CRTC.char_count == CRTC.hstart) { // leaving border area? new_dt.NewHDSPTIMG |= 0x01; } if (CRTC.char_count == CRTC.hend) { // entering border area? new_dt.NewHDSPTIMG &= 0xfe; } // ---------------------------------------------------------------------------- repeat_count--; } } void crtc_init() { if (dwXScale == 1) { ModeMaps[0] = M0hMap; ModeMaps[1] = M1hMap; ModeMaps[2] = M2hMap; ModeMaps[3] = M3hMap; } else { ModeMaps[0] = M0Map; ModeMaps[1] = M1Map; ModeMaps[2] = M2Map; ModeMaps[3] = M3Map; } ModeMap = ModeMaps[0]; for (int l = 0; l < 0x7400; l++) { int j = l << 1; // actual address MAXlate[l] = (j & 0x7FE) | ((j & 0x6000) << 1); } int Wid; if (dwXScale == 1) { Wid = 8; PosShift = 5; } else { Wid = 16; PosShift = 4; } for (int i = 0; i < 48; i++) { HorzPix[i] = Wid; } HorzPix[48] = 0; RendStart = reinterpret_cast<dword *>(&RendBuff[Wid]); } void crtc_reset() { memset(&CRTC, 0, sizeof(CRTC)); // clear CRTC data structure CRTC.registers[0] = 0x3f; CRTC.registers[2] = 0x2e; CRTC.registers[3] = 0x8e; RendPos = reinterpret_cast<dword *>(&RendBuff[0]); RendOut = reinterpret_cast<byte *>(RendStart); RendWid = &HorzPix[0]; HorzPos = 0x500; HorzChar = 0x04; HorzMax = 48; HSyncDuration = 0xA00; MinHSync = 0x4000 - HSyncDuration - 257; MaxHSync = 0x4000 - HSyncDuration + 257; MonHSYNC = 0x4000 - HSyncDuration; MonFreeSync = MonHSYNC; flags1.monVSYNC = 0; flags1.dt.DISPTIMG = 0xff; flags1.dt.HDSPTIMG = 0x03; new_dt.NewDISPTIMG = 0xff; new_dt.NewHDSPTIMG = 0x03; CRTC.CharInstSL = NoChar; CRTC.CharInstMR = NoChar; CRTC.split_addr = 0; CRTC.split_sl = 0; CRTC.sl_count = 0; CRTC.interrupt_sl = 0; MinVSync = MID_VHOLD; MaxVSync = MinVSync + MIN_VHOLD_RANGE + static_cast<int>(ceil(static_cast<float>((MinVSync - MIN_VHOLD) * (MAX_VHOLD_RANGE - MIN_VHOLD_RANGE) / (MAX_VHOLD - MIN_VHOLD)))); }
64,015
C++
.cpp
1,261
44.518636
139
0.741769
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,801
asic.cpp
ColinPitrat_caprice32/src/asic.cpp
#include "asic.h" #include "log.h" #include "cap32.h" #include "SDL.h" #include "crtc.h" byte *pbRegisterPage; extern SDL_Color colours[32]; extern t_GateArray GateArray; extern t_CRTC CRTC; extern t_CPC CPC; extern t_PSG PSG; extern SDL_Surface *back_surface; extern dword dwXScale; extern byte *membank_config[8][4]; extern byte *membank_write[4]; asic_t asic; double asic_colours[32][3]; void asic_reset() { asic.locked = true; asic.extend_border = false; asic.hscroll = 0; asic.vscroll = 0; for(int i = 0; i < 16; i++) { asic.sprites_x[i] = asic.sprites_y[i] = asic.sprites_mag_x[i] = asic.sprites_mag_y[i] = 0; for(int j = 0; j < 16; j++) { for(int k = 0; k < 16; k++) { asic.sprites[i][j][k] = 0; } } } asic.raster_interrupt = false; asic.interrupt_vector = 1; for(auto &channel : asic.dma.ch) { channel.source_address = 0; channel.loop_address = 0; channel.prescaler = 0; channel.enabled = false; channel.interrupt = false; channel.pause_ticks = 0; channel.tick_cycles = 0; channel.loops = 0; } } void asic_poke_lock_sequence(byte val) { static constexpr byte lockSeq[] = { 0x00, 0x00, 0xff, 0x77, 0xb3, 0x51, 0xa8, 0xd4, 0x62, 0x39, 0x9c, 0x46, 0x2b, 0x15, 0x8a, 0xcd }; static constexpr int lockSeqLength = sizeof(lockSeq)/sizeof(lockSeq[0]); LOG_DEBUG("ASIC poked with val=" << std::hex << static_cast<int>(val) << std::dec << " lockPos = " << asic.lockSeqPos); // Lock sequence can only start after a non zero value if (asic.lockSeqPos == 0) { if (val > 0) { asic.lockSeqPos = 1; } } else { if(asic.lockSeqPos < lockSeqLength) { if (val == lockSeq[asic.lockSeqPos]) { asic.lockSeqPos++; } else { asic.lockSeqPos++; // If the lock sequence is matched except for the last byte, it means lock if (asic.lockSeqPos == lockSeqLength) { LOG_DEBUG("ASIC locked"); asic.locked = true; } if (val == 0) { // We're now waiting for 0xFF asic.lockSeqPos = 2; } else { // We had a non 0, we're now waiting for 0 asic.lockSeqPos = 1; } } } else { // Full sequence matched and an additional value was written, it means unlock if (asic.lockSeqPos == lockSeqLength) { LOG_DEBUG("ASIC unlocked"); asic.locked = false; asic.lockSeqPos = (val == 0) ? 0 : 1; } } } } static inline unsigned short decode_magnification(byte val) { byte mag = (val & 0x3); if (mag == 3) mag = 4; return mag; } void asic_dma_cycle() { // Use the DMA info to feed PSG from RAM: // Read one 16bits instruction for each enabled channel X at each scan line and execute it. // More precisely: after leading edge of HSYNC, one dead cycle followed by a fetch cycle for each active channel (enabled and not executing a pause) followed by an execution cycle for each active channel. // All instructions last 1 cycle except LOAD that lasts 8 (up to 10 if CPU is also accessing the PSG). // - LOAD R,DD will write DD to PSG.RegisterAY.Index[R] - The ASIC should actually be blocking the CPU if it tries to access the PSG, to determine if it's important to emulate. // - PAUSE N set a counter to wait N*(chX.prescaler+1) cycles // - REPEAT NNN keep address of loop start (next instruction) and a counter of loops // - NOP does nothing // - LOOP jump to address of loop stat if counter of loops is >0 and decrement it (yes, code is actually executed NNN+1 times) // - INT generates an interruption for chX by setting chX.interrupt to true (code for CPU to detect it must also be done !) // - STOP set chX.enabled to false ? (still increment address for when processing will restart) // The last 4 can be OR-ed to be combined // The two first bits of the address give the page to read from byte dcsr = 0; bool dcsr_changed = false; for(int c = 0; c < NB_DMA_CHANNELS; c++) { dma_channel &channel = asic.dma.ch[c]; if(!channel.enabled) continue; if(channel.pause_ticks > 0) { // PAUSE on-going if(channel.tick_cycles < channel.prescaler) { channel.tick_cycles++; continue; } channel.tick_cycles = 0; channel.pause_ticks--; continue; } int bank = ((channel.source_address & 0xC000) >> 14); int addr = (channel.source_address & 0x3FFF); word instruction = 0; instruction |= membank_config[GateArray.RAM_config & 7][bank][addr]; instruction |= membank_config[GateArray.RAM_config & 7][bank][addr+1] << 8; LOG_DEBUG("DMA [" << c << "] instruction " << std::hex << instruction << " from " << channel.source_address << std::dec); int opcode = ((instruction & 0x7000) >> 12); if (opcode == 0) { // LOAD int R = ((instruction & 0x0F00) >> 8); byte val = (instruction & 0x00FF); SetAYRegister(R, val); LOG_DEBUG("DMA [" << c << "] load " << std::hex << static_cast<int>(val) << " in register " << R << std::dec); } else { if (opcode & 0x01) { // PAUSE channel.pause_ticks = (instruction) & 0x0FFF; channel.tick_cycles = 0; LOG_DEBUG("DMA [" << c << "] pause " << channel.pause_ticks << "*" << static_cast<int>(channel.prescaler) << " cycles"); } if (opcode & 0x02) { // REPEAT channel.loops = (instruction) & 0x0FFF; channel.loop_address = channel.source_address; LOG_DEBUG("DMA [" << c << "] repeat " << channel.loops); } if (opcode & 0x04) { // NOP, LOOP, INT, STOP if(instruction & 0x0001) { // LOOP if(channel.loops > 0) { channel.source_address = channel.loop_address; LOG_DEBUG("DMA [" << c << "] loop"); } } if(instruction & 0x0010) { // INT channel.interrupt = true; LOG_DEBUG("DMA [" << c << "] interrupt"); } if(instruction & 0x0020) { // STOP channel.enabled = false; LOG_DEBUG("DMA [" << c << "] stop"); } } } channel.source_address += 2; // TODO: cleaner way to modify back the register value here ... { word addr = 0x6C00 + (c << 2); *(membank_write[addr >> 14] + (addr & 0x3fff)) = static_cast<byte>(channel.source_address & 0xFF); addr++; *(membank_write[addr >> 14] + (addr & 0x3fff)) = static_cast<byte>((channel.source_address & 0xFF00) >> 8); /* Useless ? addr++; *(membank_write[addr >> 14] + (addr & 0x3fff)) = channel.prescaler; */ if (channel.enabled) { dcsr |= (0x1 << c); dcsr_changed = true; } if (channel.interrupt) { dcsr |= (0x40 >> c); dcsr_changed = true; } } } // TODO: ... and here // Run RAM test of testplus.cpr when touching this (this is not a guarantee that this is correct but at least it's a guarantee that it's less wrong ! cf issue #40) if (dcsr_changed) { word addr = 0x6C0F; *(membank_write[addr >> 14] + (addr & 0x3fff)) = dcsr; } } // Return true if byte should be written in memory bool asic_register_page_write(word addr, byte val) { if (addr < 0x4000 || addr > 0x7FFF) { return true; } LOG_DEBUG("ASIC register page write: addr=" << std::hex << addr << ", val=" << static_cast<int>(val) << std::dec); // TODO:double check the writes (more cases with mirroring / write only ?) if (addr >= 0x4000 && addr < 0x5000) { int id = ((addr & 0xF00) >> 8); int y = ((addr & 0xF0) >> 4); int x = (addr & 0xF); byte color = (val & 0xF); if(color > 0) { color += 16; } asic.sprites[id][x][y] = color; //LOG_DEBUG("Received sprite data for sprite " << id << ": x=" << x << ", y=" << y << ", color=" << static_cast<int>(val)); } else if (addr >= 0x6000 && addr < 0x607D) { int id = ((addr - 0x6000) >> 3); int type = (addr & 0x7); switch (type) { case 0: // X position asic.sprites_x[id] = (asic.sprites_x[id] & 0xFF00) | val; //LOG_DEBUG("Received sprite X for sprite " << id << " x=" << asic.sprites_x[id]); // Mirrored in RAM image 4 bytes after pbRegisterPage[(addr & 0x3FFF) + 4] = val; break; case 1: // X position asic.sprites_x[id] = (asic.sprites_x[id] & 0x00FF) | (val << 8); //LOG_DEBUG("Received sprite X for sprite " << id << " x=" << asic.sprites_x[id]); // Mirrored in RAM image 4 bytes after pbRegisterPage[(addr & 0x3FFF) + 4] = val; break; case 2: // Y position asic.sprites_y[id] = ((asic.sprites_y[id] & 0xFF00) | val); //LOG_DEBUG("Received sprite Y for sprite " << id << " y=" << asic.sprites_y[id]); // Mirrored in RAM image 4 bytes after pbRegisterPage[(addr & 0x3FFF) + 4] = val; break; case 3: // Y position asic.sprites_y[id] = ((asic.sprites_y[id] & 0x00FF) | (val << 8)); //LOG_DEBUG("Received sprite Y for sprite " << id << " y=" << asic.sprites_y[id]); // Affect RAM image // Mirrored in RAM image 4 bytes after pbRegisterPage[(addr & 0x3FFF) + 4] = val; break; case 4: // Magnification asic.sprites_mag_x[id] = decode_magnification(val >> 2); asic.sprites_mag_y[id] = decode_magnification(val); //LOG_DEBUG("Received sprite magnification for sprite " << id << " mx=" << asic.sprites_mag_x[id] << ", my=" << asic.sprites_mag_y[id]); // Write-only: does not affect pbRegisterPage return false; default: LOG_DEBUG("Received sprite operation of unsupported type: " << type << " addr=" << std::hex << addr << " - val=" << static_cast<int>(val) << std::dec); break; } } else if (addr >= 0x6400 && addr < 0x6440) { int colour = (addr & 0x3F) >> 1; if ((addr % 2) == 1) { double green = static_cast<double>(val & 0x0F)/16; //LOG_DEBUG("Received color operation: color " << colour << " has green = " << green); asic_colours[colour][1] = green; pbRegisterPage[(addr & 0x3FFF)] = (val & 0x0F); // TODO: find a cleaner way to do this - this is a copy paste from "Set ink value" in cap32.cpp } else { double red = static_cast<double>((val & 0xF0) >> 4)/16; double blue = static_cast<double>(val & 0x0F)/16; //LOG_DEBUG("Received color operation: color " << colour << " has red = " << red << " and blue = " << blue); asic_colours[colour][0] = red; asic_colours[colour][2] = blue; pbRegisterPage[(addr & 0x3FFF)] = val; } // TODO: deduplicate with code in video_set_palette + make it work in monochrome dword red = static_cast<dword>(asic_colours[colour][0] * (CPC.scr_intensity / 10.0) * 255); if (red > 255) { // limit to the maximum red = 255; } dword green = static_cast<dword>(asic_colours[colour][1] * (CPC.scr_intensity / 10.0) * 255); if (green > 255) { green = 255; } dword blue = static_cast<dword>(asic_colours[colour][2] * (CPC.scr_intensity / 10.0) * 255); if (blue > 255) { blue = 255; } GateArray.palette[colour] = SDL_MapRGB(back_surface->format, red, green, blue); /* if (colour < 2) { byte r = (static_cast<dword>(colours[GateArray.ink_values[0]].r) + static_cast<dword>(colours[GateArray.ink_values[1]].r)) >> 1; byte g = (static_cast<dword>(colours[GateArray.ink_values[0]].g) + static_cast<dword>(colours[GateArray.ink_values[1]].g)) >> 1; byte b = (static_cast<dword>(colours[GateArray.ink_values[0]].b) + static_cast<dword>(colours[GateArray.ink_values[1]].b)) >> 1; GateArray.palette[33] = SDL_MapRGB(back_surface->format, r, g, b); // update the mode 2 'anti-aliasing' colour } */ return false; } else if (addr >= 0x6800 && addr < 0x6806) { if (addr == 0x6800) { LOG_DEBUG("Received programmable raster interrupt scan line: " << static_cast<int>(val)); CRTC.interrupt_sl = val; } else if (addr == 0x6801) { LOG_DEBUG("Received scan line for split: " << static_cast<int>(val)); CRTC.split_sl = val; } else if (addr == 0x6802) { CRTC.split_addr &= 0x00FF; CRTC.split_addr |= (val << 8); LOG_DEBUG("Received address for split: " << std::hex << CRTC.split_addr << std::dec); } else if (addr == 0x6803) { CRTC.split_addr &= 0x3F00; CRTC.split_addr |= val; LOG_DEBUG("Received address for split: " << std::hex << CRTC.split_addr << std::dec); } else if (addr == 0x6804) { asic.hscroll = (val & 0xf); asic.vscroll = ((val >> 4) & 0x7); asic.extend_border = (val >> 7); LOG_DEBUG("Received soft scroll control: " << static_cast<int>(val) << ": dx=" << asic.hscroll << ", dy=" << asic.vscroll << ", border=" << asic.extend_border); update_skew(); } else if (addr == 0x6805) { LOG_DEBUG("[UNSUPPORTED] Received interrupt vector: " << static_cast<int>(val)); asic.interrupt_vector = val & 0xF8; // TODO: Write this part !!! (Interrupt service part from http://www.cpcwiki.eu/index.php/Arnold_V_Specs_Revised) } } else if (addr >= 0x6808 && addr < 0x6810) { LOG_DEBUG("[UNSUPPORTED] Received analog input stuff"); } else if (addr >= 0x6C00 && addr < 0x6C0B) { int c = ((addr & 0xc) >> 2); LOG_DEBUG("Received DMA source address: " << std::hex << addr << " (channel " << c << ") " << static_cast<int>(val) << std::dec); dma_channel *channel = nullptr; channel = &asic.dma.ch[c]; switch(addr & 0x3) { case 0: channel->source_address &= 0xFF00; // least significant bit is ignored (address are word-aligned) channel->source_address |= (val & 0xFE); break; case 1: channel->source_address &= 0x00FF; channel->source_address |= (val << 8); break; case 2: channel->prescaler = val; break; default: // unused break; } } else if (addr == 0x6C0F) { LOG_DEBUG("Received DMA control register: " << std::hex << static_cast<int>(val) << std::dec); for (int c = 0; c < NB_DMA_CHANNELS; c++) { asic.dma.ch[c].enabled = (val & (0x1 << c)); LOG_DEBUG("DMA channel " << c << (asic.dma.ch[c].enabled ? " enabled" : " disabled")) } } else { LOG_DEBUG("Received unused write at " << std::hex << addr << " - val: " << static_cast<int>(val) << std::dec); } return true; } void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = static_cast<Uint8 *>(surface->pixels) + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *reinterpret_cast<Uint16 *>(p) = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *reinterpret_cast<Uint32 *>(p) = pixel; break; } } // TODO: all this could be replaced by pre-computed SDL sprites void asic_draw_sprites() { // TODO: this should be affected by other CRTC.registers (reg2 for borderWidth ?, reg1 for screenWidth ? reg6 for screenHeight ?) const int borderWidth = 64 + (asic.extend_border ? 16 : 0); const int borderHeight = 40 + 8*(30 - CRTC.registers[7]); const int screenWidth = 640 + borderWidth; const int screenHeight = 200 + borderHeight; // For each sprite for(int i = 15; i >= 0; i--) { int sx = asic.sprites_x[i]; int mx = asic.sprites_mag_x[i]; // If some part of the sprite is visible (horizontal check) if(mx > 0 && (sx + 64*mx) >= borderWidth && sx <= screenWidth) { int sy = asic.sprites_y[i]; int my = asic.sprites_mag_y[i]; // If some part of the sprite is visible (vertical check) if(my > 0 && (sy + 64*my) >= borderHeight && sy <= screenHeight) { sx += borderWidth; sy += borderHeight; // For each column of the sprite for(int x = 0; x < 16; x++) { if(sx + (x*mx) <= borderWidth) { continue; } if(sx + (x*mx) >= screenWidth) { break; } // For each line of the sprite for(int y = 0; y < 16; y++) { if(sy + (y*my) <= borderHeight) { continue; } if(sy + (y*my) >= screenHeight) { break; } // Draw pixel byte p = asic.sprites[i][x][y]; if(p) { Uint32 pixel = GateArray.palette[p]; for(int dx = 0; dx < mx; dx++) { for(int dy = 0; dy < my * static_cast<int>(dwXScale); dy++) { putpixel(back_surface, (sx+(x*mx)+dx) * dwXScale / 2, (sy+(y*my)) * dwXScale + dy, pixel); } } } } } } } } }
17,909
C++
.cpp
424
34.068396
206
0.554302
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,802
configuration.cpp
ColinPitrat_caprice32/src/configuration.cpp
#include "configuration.h" #include "log.h" #include <sstream> #include <cstring> #include <fstream> #include <iostream> #include <string> namespace config { bool hasValue(const ConfigMap& config, const std::string& section, const std::string& key) { if(config.find(section) != config.end()) { auto configSection = config.at(section); if(configSection.find(key) != configSection.end()) { return true; } } return false; } std::istream& Config::parseStream(std::istream& configStream) { std::streamsize maxSize = 256; char chLine[maxSize]; std::string section; while(configStream.good()) { configStream.getline(chLine, maxSize); if(chLine[0] == '[') // check if there's a section key { char *pchToken = strtok(chLine, "[]"); if(pchToken != nullptr) { section = pchToken; } } else { char *pchToken = strtok(chLine, "\t =\n\r"); // check if it has a key=value pair if((pchToken != nullptr) && (pchToken[0] != '#')) { std::string key = pchToken; char* pchPtr = strtok(nullptr, "\t=#\n\r"); // get the value if it matches our key if (pchPtr != nullptr) { std::string value = pchPtr; config_[section][key] = value; } } } } return configStream; }; void Config::parseString(const std::string& configString) { std::istringstream configStream(configString); parseStream(configStream); }; void Config::parseFile(const std::string& configFilename) { std::ifstream configStream(configFilename); parseStream(configStream); configStream.close(); }; std::ostream& Config::toStream(std::ostream& out) const { for(const auto& section : config_) { out << "[" << section.first << "]" << std::endl; for(const auto& keyval : section.second) { out << keyval.first << "=" << keyval.second << std::endl; } } return out; } bool Config::saveToFile(const std::string& configFilename) const { std::ofstream configStream(configFilename); toStream(configStream); configStream.close(); bool success = configStream.good(); if (!success) { LOG_ERROR("Couldn't save configuration to '" << configFilename << "'. Is the file writable?"); } return success; } void Config::setOverrides(const ConfigMap& overrides) { overrides_ = overrides; } int Config::getIntValue(const std::string& section, const std::string& key, const int defaultValue) const { if(hasValue(overrides_, section, key)) { return atoi(overrides_.at(section).at(key).c_str()); } if(hasValue(config_, section, key)) { return atoi(config_.at(section).at(key).c_str()); } return defaultValue; } std::string Config::getStringValue(const std::string& section, const std::string& key, const std::string& defaultValue) const { if(hasValue(overrides_, section, key)) { return std::string(overrides_.at(section).at(key)); } if(hasValue(config_, section, key)) { return std::string(config_.at(section).at(key)); } return defaultValue; } void Config::setStringValue(const std::string& section, const std::string& key, const std::string& value) { overrides_[section][key] = value; config_[section][key] = value; } void Config::setIntValue(const std::string& section, const std::string& key, const int value) { std::ostringstream oss; oss << value; overrides_[section][key] = oss.str(); config_[section][key] = oss.str(); } ConfigMap Config::getConfigMapForTests() const { return config_; } }
3,745
C++
.cpp
130
23.669231
127
0.632251
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,803
z80.cpp
ColinPitrat_caprice32/src/z80.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Zilog Z80A Microprocessor emulation (c) Copyright 1997-2003 Ulrich Doewich code portions and ideas taken from the Z80 emulations by: Juergen Buchmueller (MAME Z80 core v3.3) Marat Fayzullin and my own Z80 x86 assembly code (Caprice32 up to version 2.00b2) */ #include "cap32.h" #include "disk.h" #include "tape.h" #include "z80.h" #include "asic.h" #include "log.h" #include <algorithm> #include <vector> #include <iomanip> #include "z80_macros.h" extern t_CPC CPC; extern t_FDC FDC; extern t_GateArray GateArray; extern t_PSG PSG; extern t_VDU VDU; extern byte *pbTapeImage; extern dword dwMF2Flags; extern dword dwMF2ExitAddr; extern int iTapeCycleCount; #ifdef DEBUG_Z80 extern FILE *pfoDebug; unsigned int dbg_z80_lastPC, dbg_z80_diff; #endif enum opcodes { nop, ld_bc_word, ld_mbc_a, inc_bc, inc_b, dec_b, ld_b_byte, rlca, ex_af_af, add_hl_bc, ld_a_mbc, dec_bc, inc_c, dec_c, ld_c_byte, rrca, djnz, ld_de_word, ld_mde_a, inc_de, inc_d, dec_d, ld_d_byte, rla, jr, add_hl_de, ld_a_mde, dec_de, inc_e, dec_e, ld_e_byte, rra, jr_nz, ld_hl_word, ld_mword_hl, inc_hl, inc_h, dec_h, ld_h_byte, daa, jr_z, add_hl_hl, ld_hl_mword, dec_hl, inc_l, dec_l, ld_l_byte, cpl, jr_nc, ld_sp_word, ld_mword_a, inc_sp, inc_mhl, dec_mhl, ld_mhl_byte, scf, jr_c, add_hl_sp, ld_a_mword, dec_sp, inc_a, dec_a, ld_a_byte, ccf, ld_b_b, ld_b_c, ld_b_d, ld_b_e, ld_b_h, ld_b_l, ld_b_mhl, ld_b_a, ld_c_b, ld_c_c, ld_c_d, ld_c_e, ld_c_h, ld_c_l, ld_c_mhl, ld_c_a, ld_d_b, ld_d_c, ld_d_d, ld_d_e, ld_d_h, ld_d_l, ld_d_mhl, ld_d_a, ld_e_b, ld_e_c, ld_e_d, ld_e_e, ld_e_h, ld_e_l, ld_e_mhl, ld_e_a, ld_h_b, ld_h_c, ld_h_d, ld_h_e, ld_h_h, ld_h_l, ld_h_mhl, ld_h_a, ld_l_b, ld_l_c, ld_l_d, ld_l_e, ld_l_h, ld_l_l, ld_l_mhl, ld_l_a, ld_mhl_b, ld_mhl_c, ld_mhl_d, ld_mhl_e, ld_mhl_h, ld_mhl_l, halt, ld_mhl_a, ld_a_b, ld_a_c, ld_a_d, ld_a_e, ld_a_h, ld_a_l, ld_a_mhl, ld_a_a, add_b, add_c, add_d, add_e, add_h, add_l, add_mhl, add_a, adc_b, adc_c, adc_d, adc_e, adc_h, adc_l, adc_mhl, adc_a, sub_b, sub_c, sub_d, sub_e, sub_h, sub_l, sub_mhl, sub_a, sbc_b, sbc_c, sbc_d, sbc_e, sbc_h, sbc_l, sbc_mhl, sbc_a, and_b, and_c, and_d, and_e, and_h, and_l, and_mhl, and_a, xor_b, xor_c, xor_d, xor_e, xor_h, xor_l, xor_mhl, xor_a, or_b, or_c, or_d, or_e, or_h, or_l, or_mhl, or_a, cp_b, cp_c, cp_d, cp_e, cp_h, cp_l, cp_mhl, cp_a, ret_nz, pop_bc, jp_nz, jp, call_nz, push_bc, add_byte, rst00, ret_z, ret, jp_z, pfx_cb, call_z, call, adc_byte, rst08, ret_nc, pop_de, jp_nc, outa, call_nc, push_de, sub_byte, rst10, ret_c, exx, jp_c, ina, call_c, pfx_dd, sbc_byte, rst18, ret_po, pop_hl, jp_po, ex_msp_hl, call_po, push_hl, and_byte, rst20, ret_pe, ld_pc_hl, jp_pe, ex_de_hl, call_pe, pfx_ed, xor_byte, rst28, ret_p, pop_af, jp_p, di, call_p, push_af, or_byte, rst30, ret_m, ld_sp_hl, jp_m, ei, call_m, pfx_fd, cp_byte, rst38 }; enum CBcodes { rlc_b, rlc_c, rlc_d, rlc_e, rlc_h, rlc_l, rlc_mhl, rlc_a, rrc_b, rrc_c, rrc_d, rrc_e, rrc_h, rrc_l, rrc_mhl, rrc_a, rl_b, rl_c, rl_d, rl_e, rl_h, rl_l, rl_mhl, rl_a, rr_b, rr_c, rr_d, rr_e, rr_h, rr_l, rr_mhl, rr_a, sla_b, sla_c, sla_d, sla_e, sla_h, sla_l, sla_mhl, sla_a, sra_b, sra_c, sra_d, sra_e, sra_h, sra_l, sra_mhl, sra_a, sll_b, sll_c, sll_d, sll_e, sll_h, sll_l, sll_mhl, sll_a, srl_b, srl_c, srl_d, srl_e, srl_h, srl_l, srl_mhl, srl_a, bit0_b, bit0_c, bit0_d, bit0_e, bit0_h, bit0_l, bit0_mhl, bit0_a, bit1_b, bit1_c, bit1_d, bit1_e, bit1_h, bit1_l, bit1_mhl, bit1_a, bit2_b, bit2_c, bit2_d, bit2_e, bit2_h, bit2_l, bit2_mhl, bit2_a, bit3_b, bit3_c, bit3_d, bit3_e, bit3_h, bit3_l, bit3_mhl, bit3_a, bit4_b, bit4_c, bit4_d, bit4_e, bit4_h, bit4_l, bit4_mhl, bit4_a, bit5_b, bit5_c, bit5_d, bit5_e, bit5_h, bit5_l, bit5_mhl, bit5_a, bit6_b, bit6_c, bit6_d, bit6_e, bit6_h, bit6_l, bit6_mhl, bit6_a, bit7_b, bit7_c, bit7_d, bit7_e, bit7_h, bit7_l, bit7_mhl, bit7_a, res0_b, res0_c, res0_d, res0_e, res0_h, res0_l, res0_mhl, res0_a, res1_b, res1_c, res1_d, res1_e, res1_h, res1_l, res1_mhl, res1_a, res2_b, res2_c, res2_d, res2_e, res2_h, res2_l, res2_mhl, res2_a, res3_b, res3_c, res3_d, res3_e, res3_h, res3_l, res3_mhl, res3_a, res4_b, res4_c, res4_d, res4_e, res4_h, res4_l, res4_mhl, res4_a, res5_b, res5_c, res5_d, res5_e, res5_h, res5_l, res5_mhl, res5_a, res6_b, res6_c, res6_d, res6_e, res6_h, res6_l, res6_mhl, res6_a, res7_b, res7_c, res7_d, res7_e, res7_h, res7_l, res7_mhl, res7_a, set0_b, set0_c, set0_d, set0_e, set0_h, set0_l, set0_mhl, set0_a, set1_b, set1_c, set1_d, set1_e, set1_h, set1_l, set1_mhl, set1_a, set2_b, set2_c, set2_d, set2_e, set2_h, set2_l, set2_mhl, set2_a, set3_b, set3_c, set3_d, set3_e, set3_h, set3_l, set3_mhl, set3_a, set4_b, set4_c, set4_d, set4_e, set4_h, set4_l, set4_mhl, set4_a, set5_b, set5_c, set5_d, set5_e, set5_h, set5_l, set5_mhl, set5_a, set6_b, set6_c, set6_d, set6_e, set6_h, set6_l, set6_mhl, set6_a, set7_b, set7_c, set7_d, set7_e, set7_h, set7_l, set7_mhl, set7_a }; enum EDcodes { ed_00, ed_01, ed_02, ed_03, ed_04, ed_05, ed_06, ed_07, ed_08, ed_09, ed_0a, ed_0b, ed_0c, ed_0d, ed_0e, ed_0f, ed_10, ed_11, ed_12, ed_13, ed_14, ed_15, ed_16, ed_17, ed_18, ed_19, ed_1a, ed_1b, ed_1c, ed_1d, ed_1e, ed_1f, ed_20, ed_21, ed_22, ed_23, ed_24, ed_25, ed_26, ed_27, ed_28, ed_29, ed_2a, ed_2b, ed_2c, ed_2d, ed_2e, ed_2f, ed_30, ed_31, ed_32, ed_33, ed_34, ed_35, ed_36, ed_37, ed_38, ed_39, ed_3a, ed_3b, ed_3c, ed_3d, ed_3e, ed_3f, in_b_c, out_c_b, sbc_hl_bc, ld_EDmword_bc, neg, retn, im_0, ld_i_a, in_c_c, out_c_c, adc_hl_bc, ld_EDbc_mword, neg_1, reti, im_0_1, ld_r_a, in_d_c, out_c_d, sbc_hl_de, ld_EDmword_de, neg_2, retn_1, im_1, ld_a_i, in_e_c, out_c_e, adc_hl_de, ld_EDde_mword, neg_3, reti_1, im_2, ld_a_r, in_h_c, out_c_h, sbc_hl_hl, ld_EDmword_hl, neg_4, retn_2, im_0_2, rrd, in_l_c, out_c_l, adc_hl_hl, ld_EDhl_mword, neg_5, reti_2, im_0_3, rld, in_0_c, out_c_0, sbc_hl_sp, ld_EDmword_sp, neg_6, retn_3, im_1_1, ed_77, in_a_c, out_c_a, adc_hl_sp, ld_EDsp_mword, neg_7, reti_3, im_2_1, ed_7f, ed_80, ed_81, ed_82, ed_83, ed_84, ed_85, ed_86, ed_87, ed_88, ed_89, ed_8a, ed_8b, ed_8c, ed_8d, ed_8e, ed_8f, ed_90, ed_91, ed_92, ed_93, ed_94, ed_95, ed_96, ed_97, ed_98, ed_99, ed_9a, ed_9b, ed_9c, ed_9d, ed_9e, ed_9f, ldi, cpi, ini, outi, ed_a4, ed_a5, ed_a6, ed_a7, ldd, cpd, ind, outd, ed_ac, ed_ad, ed_ae, ed_af, ldir, cpir, inir, otir, ed_b4, ed_b5, ed_b6, ed_b7, lddr, cpdr, indr, otdr, ed_bc, ed_bd, ed_be, ed_bf, ed_c0, ed_c1, ed_c2, ed_c3, ed_c4, ed_c5, ed_c6, ed_c7, ed_c8, ed_c9, ed_ca, ed_cb, ed_cc, ed_cd, ed_ce, ed_cf, ed_d0, ed_d1, ed_d2, ed_d3, ed_d4, ed_d5, ed_d6, ed_d7, ed_d8, ed_d9, ed_da, ed_db, ed_dc, ed_dd, ed_de, ed_df, ed_e0, ed_e1, ed_e2, ed_e3, ed_e4, ed_e5, ed_e6, ed_e7, ed_e8, ed_e9, ed_ea, ed_eb, ed_ec, ed_ed, ed_ee, ed_ef, ed_f0, ed_f1, ed_f2, ed_f3, ed_f4, ed_f5, ed_f6, ed_f7, ed_f8, ed_f9, ed_fa, ed_fb, ed_fc, ed_fd, ed_fe, ed_ff }; t_z80regs z80; std::vector<Breakpoint> breakpoints; std::vector<Watchpoint> watchpoints; int iCycleCount, iWSAdjust; static byte SZ[256]; // zero and sign flags static byte SZ_BIT[256]; // zero, sign and parity/overflow (=zero) flags for BIT opcode static byte SZP[256]; // zero, sign and parity flags static byte SZHV_inc[256]; // zero, sign, half carry and overflow flags INC r8 static byte SZHV_dec[256]; // zero, sign, half carry and overflow flags DEC r8 #include "z80daa.h" static byte irep_tmp1[4][4] = { {0, 0, 1, 0}, {0, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 0} }; /* tmp1 value for ind/indr/outd/otdr for [C.1-0][io.1-0] */ static byte drep_tmp1[4][4] = { {0, 1, 0, 0}, {1, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 1} }; /* tmp2 value for all in/out repeated opcodes for B.7-0 */ static byte breg_tmp2[256] = { 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1 }; #define Oa 8 #define Oa_ 4 #define Ia 12 #define Ia_ 0 static byte cc_op[256] = { 4, 12, 8, 8, 4, 4, 8, 4, 4, 12, 8, 8, 4, 4, 8, 4, 12, 12, 8, 8, 4, 4, 8, 4, 12, 12, 8, 8, 4, 4, 8, 4, 8, 12, 20, 8, 4, 4, 8, 4, 8, 12, 20, 8, 4, 4, 8, 4, 8, 12, 16, 8, 12, 12, 12, 4, 8, 12, 16, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 8, 8, 8, 8, 8, 8, 4, 8, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 8, 12, 12, 12, 12, 16, 8, 16, 8, 12, 12, 4, 12, 20, 8, 16, 8, 12, 12, Oa, 12, 16, 8, 16, 8, 4, 12, Ia, 12, 4, 8, 16, 8, 12, 12, 24, 12, 16, 8, 16, 8, 4, 12, 4, 12, 4, 8, 16, 8, 12, 12, 4, 12, 16, 8, 16, 8, 8, 12, 4, 12, 4, 8, 16 }; static byte cc_cb[256] = { 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4, 4, 4, 4, 4, 4, 4, 12, 4 }; #define Ox 8 #define Ox_ 4 #define Oy 12 #define Oy_ 4 #define Ix 12 #define Ix_ 0 #define Iy 16 #define Iy_ 0 static byte cc_ed[256] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, Ix, Ox, 12, 20, 4, 12, 4, 8, Ix, Ox, 12, 20, 4, 12, 4, 8, Ix, Ox, 12, 20, 4, 12, 4, 8, Ix, Ox, 12, 20, 4, 12, 4, 8, Ix, Ox, 12, 20, 4, 12, 4, 16, Ix, Ox, 12, 20, 4, 12, 4, 16, Ix, Ox, 12, 20, 4, 12, 4, 4, Ix, Ox, 12, 20, 4, 12, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 16, 12, Iy, Oy, 4, 4, 4, 4, 16, 12, Iy, Oy, 4, 4, 4, 4, 16, 12, Iy, Oy, 4, 4, 4, 4, 16, 12, Iy, Oy, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; static byte cc_xy[256] = { 4, 12, 8, 8, 4, 4, 8, 4, 4, 12, 8, 8, 4, 4, 8, 4, 12, 12, 8, 8, 4, 4, 8, 4, 12, 12, 8, 8, 4, 4, 8, 4, 8, 12, 20, 8, 4, 4, 8, 4, 8, 12, 20, 8, 4, 4, 8, 4, 8, 12, 16, 8, 20, 20, 20, 4, 8, 12, 16, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 16, 16, 16, 16, 16, 16, 4, 16, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 4, 4, 4, 4, 4, 4, 16, 4, 8, 12, 12, 12, 12, 16, 8, 16, 8, 12, 12, 4, 12, 20, 8, 16, 8, 12, 12, Oa, 12, 16, 8, 16, 8, 4, 12, Ia, 12, 4, 8, 16, 8, 12, 12, 24, 12, 16, 8, 16, 8, 4, 12, 4, 12, 4, 8, 16, 8, 12, 12, 4, 12, 16, 8, 16, 8, 8, 12, 4, 12, 4, 8, 16 }; static byte cc_xycb[256] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; static byte cc_ex[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 4, 4, 0, 0, 0, 0, 4, 8, 4, 4, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0 }; extern byte *membank_read[4], *membank_write[4]; inline byte read_mem_no_watchpoint(word addr) { return (*(membank_read[addr >> 14] + (addr & 0x3fff))); // returns a byte from a 16KB memory bank } inline byte read_mem(word addr) { if (!watchpoints.empty()) { if (std::any_of(watchpoints.begin(), watchpoints.end(), [&](const auto& w) { return w.address == addr && (w.type & READ); })) { z80.watchpoint_reached = 1; } } return read_mem_no_watchpoint(addr); } inline void write_mem_no_watchpoint(word addr, byte val) { *(membank_write[addr >> 14] + (addr & 0x3fff)) = val; // writes a byte to a 16KB memory bank } inline void write_mem(word addr, byte val) { if (!watchpoints.empty()) { if (std::any_of(watchpoints.begin(), watchpoints.end(), [&](const auto& w) { return w.address == addr && (w.type & WRITE); })) { z80.watchpoint_reached = 1; } } if (GateArray.registerPageOn) { //LOG_DEBUG("Pass write to ASIC: " << static_cast<int>(val) << " at " << addr); if(!asic_register_page_write(addr, val)) return; } //LOG_DEBUG("Write " << static_cast<int>(val) << " at " << addr); write_mem_no_watchpoint(addr, val); } byte z80_read_mem(word addr) { return read_mem_no_watchpoint(addr); } void z80_write_mem(word addr, byte val) { write_mem_no_watchpoint(addr, val); } #define z80_wait_states \ { \ if (iCycleCount) { \ crtc_cycle(iCycleCount >> 2); \ if (CPC.snd_enabled) { \ PSG.cycle_count.high += iCycleCount; \ if (PSG.cycle_count.high >= CPC.snd_cycle_count_init.high) { \ PSG.cycle_count.both -= CPC.snd_cycle_count_init.both; \ PSG.Synthesizer(); \ } \ } \ if (FDC.phase == EXEC_PHASE) { \ FDC.timeout -= iCycleCount; \ if (FDC.timeout <= 0) { \ FDC.flags |= OVERRUN_flag; \ if (FDC.cmd_direction == FDC_TO_CPU) { \ fdc_read_data(); \ } \ else { \ fdc_write_data(0xff); \ } \ } \ } \ if ((CPC.tape_motor) && (CPC.tape_play_button)) { \ iTapeCycleCount -= iCycleCount; \ if (iTapeCycleCount <= 0) { \ Tape_UpdateLevel(); \ } \ } \ CPC.cycle_count -= iCycleCount; \ } \ } #define ADC(value) \ { \ unsigned val = value; \ unsigned res = _A + val + (_F & Cflag); \ _F = SZ[res & 0xff] | ((res >> 8) & Cflag) | ((_A ^ res ^ val) & Hflag) | \ (((val ^ _A ^ 0x80) & (val ^ res) & 0x80) >> 5); \ _A = res; \ } #define ADD(value) \ { \ unsigned val = value; \ unsigned res = _A + val; \ _F = SZ[static_cast<byte>(res)] | ((res >> 8) & Cflag) | ((_A ^ res ^ val) & Hflag) | \ (((val ^ _A ^ 0x80) & (val ^ res) & 0x80) >> 5); \ _A = static_cast<byte>(res); \ } #define ADD16(dest, src) \ { \ dword res = z80.dest.d + z80.src.d; \ _F = (_F & (Sflag | Zflag | Vflag)) | (((z80.dest.d ^ res ^ z80.src.d) >> 8) & Hflag) | \ ((res >> 16) & Cflag) | ((res >> 8) & Xflags); \ z80.dest.w.l = static_cast<word>(res); \ } #define AND(val) \ { \ _A &= (val); \ _F = SZP[_A] | Hflag; \ } #define CALL \ { \ if (z80.step_out) { \ z80.step_out_addresses.push_back(_PC+2); \ } \ reg_pair dest; \ dest.b.l = read_mem(_PC++); /* subroutine address low byte */ \ dest.b.h = read_mem(_PC++); /* subroutine address high byte */ \ write_mem(--_SP, z80.PC.b.h); /* store high byte of current PC */ \ write_mem(--_SP, z80.PC.b.l); /* store low byte of current PC */ \ _PC = dest.w.l; /* continue execution at subroutine */ \ } #define CP(value) \ { \ unsigned val = value; \ unsigned res = _A - val; \ _F = (SZ[res & 0xff] & (Sflag | Zflag)) | (val & Xflags) | ((res >> 8) & Cflag) | Nflag | ((_A ^ res ^ val) & Hflag) | \ ((((val ^ _A) & (_A ^ res)) >> 5) & Vflag); \ } #define DAA \ { \ int idx = _A; \ if(_F & Cflag) \ idx |= 0x100; \ if(_F & Hflag) \ idx |= 0x200; \ if(_F & Nflag) \ idx |= 0x400; \ _AF = DAATable[idx]; \ } #define DEC(reg) \ { \ (reg)--; \ _F = (_F & Cflag) | SZHV_dec[reg]; \ } #define JR \ { \ signed char offset; \ offset = static_cast<signed char>(read_mem(_PC)); /* grab signed jump offset */ \ _PC += offset + 1; /* add offset & correct PC */ \ } #define EXX \ { \ reg_pair temp; \ temp = z80.BCx; \ z80.BCx = z80.BC; \ z80.BC = temp; \ temp = z80.DEx; \ z80.DEx = z80.DE; \ z80.DE = temp; \ temp = z80.HLx; \ z80.HLx = z80.HL; \ z80.HL = temp; \ } #define EX(op1, op2) \ { \ reg_pair temp; \ temp = (op1); \ (op1) = (op2); \ (op2) = temp; \ } #define EX_SP(reg) \ { \ reg_pair temp; \ temp.b.l = read_mem(_SP++); \ temp.b.h = read_mem(_SP); \ write_mem(_SP--, z80.reg.b.h); \ write_mem(_SP, z80.reg.b.l); \ z80.reg.w.l = temp.w.l; \ } #define INC(reg) \ { \ (reg)++; \ _F = (_F & Cflag) | SZHV_inc[reg]; \ } #define JP \ { \ reg_pair addr; \ addr.b.l = read_mem(_PC++); \ addr.b.h = read_mem(_PC); \ _PC = addr.w.l; \ } #define LD16_MEM(reg) \ { \ reg_pair addr; \ addr.b.l = read_mem(_PC++); \ addr.b.h = read_mem(_PC++); \ z80.reg.b.l = read_mem(addr.w.l); \ z80.reg.b.h = read_mem(addr.w.l+1); \ } #define LDMEM_16(reg) \ { \ reg_pair addr; \ addr.b.l = read_mem(_PC++); \ addr.b.h = read_mem(_PC++); \ write_mem(addr.w.l, z80.reg.b.l); \ write_mem(addr.w.l+1, z80.reg.b.h); \ } #define OR(val) \ { \ _A |= (val); \ _F = SZP[_A]; \ } #define POP(reg) \ { \ z80.reg.b.l = read_mem(_SP++); \ z80.reg.b.h = read_mem(_SP++); \ } #define PUSH(reg) \ { \ write_mem(--_SP, z80.reg.b.h); \ write_mem(--_SP, z80.reg.b.l); \ } #define RET \ { \ z80.PC.b.l = read_mem(_SP++); \ z80.PC.b.h = read_mem(_SP++); \ if (z80.step_out) { \ if (z80.step_out_addresses.empty()) { \ z80.step_out = 0; \ z80.step_in = 2; \ } \ /* If the address is not in step_out_addresses, it doesn't come from a call */ \ else if (z80.step_out_addresses.back() == z80.PC.w.l) { \ z80.step_out_addresses.pop_back(); \ } \ } \ } #define RLA \ { \ byte res = (_A << 1) | (_F & Cflag); \ byte carry = (_A & 0x80) ? Cflag : 0; \ _F = (_F & (Sflag | Zflag | Pflag)) | carry | (res & Xflags); \ _A = res; \ } #define RLCA \ { \ _A = (_A << 1) | (_A >> 7); \ _F = (_F & (Sflag | Zflag | Pflag)) | (_A & (Xflags | Cflag)); \ } #define RRA \ { \ byte res = (_A >> 1) | (_F << 7); \ byte carry = (_A & 0x01) ? Cflag : 0; \ _F = (_F & (Sflag | Zflag | Pflag)) | carry | (res & Xflags); \ _A = res; \ } #define RRCA \ { \ _F = (_F & (Sflag | Zflag | Pflag)) | (_A & Cflag); \ _A = (_A >> 1) | (_A << 7); \ _F |= (_A & Xflags); \ } #define RST(addr) \ { \ if (z80.step_out) { \ z80.step_out_addresses.push_back(_PC+2); \ } \ write_mem(--_SP, z80.PC.b.h); /* store high byte of current PC */ \ write_mem(--_SP, z80.PC.b.l); /* store low byte of current PC */ \ _PC = addr; /* continue execution at restart address */ \ } #define SBC(value) \ { \ unsigned val = value; \ unsigned res = _A - val - (_F & Cflag); \ _F = SZ[res & 0xff] | ((res >> 8) & Cflag) | Nflag | ((_A ^ res ^ val) & Hflag) | \ (((val ^ _A) & (_A ^ res) & 0x80) >> 5); \ _A = res; \ } #define SUB(value) \ { \ unsigned val = value; \ unsigned res = _A - val; \ _F = SZ[res & 0xff] | ((res >> 8) & Cflag) | Nflag | ((_A ^ res ^ val) & Hflag) | \ (((val ^ _A) & (_A ^ res) & 0x80) >> 5); \ _A = res; \ } #define XOR(val) \ { \ _A ^= (val); \ _F = SZP[_A]; \ } #define BIT(bit, reg) \ (_F = (_F & Cflag) | Hflag | SZ_BIT[(reg) & (1 << (bit))]) #define BIT_XY BIT inline byte RES(byte bit, byte val) { return val & ~(1 << bit); } inline byte RLC(byte val) { unsigned res = val; unsigned carry = (res & 0x80) ? Cflag : 0; res = ((res << 1) | (res >> 7)) & 0xff; _F = SZP[res] | carry; return res; } inline byte RL(byte val) { unsigned res = val; unsigned carry = (res & 0x80) ? Cflag : 0; res = ((res << 1) | (_F & Cflag)) & 0xff; _F = SZP[res] | carry; return res; } inline byte RRC(byte val) { unsigned res = val; unsigned carry = (res & 0x01) ? Cflag : 0; res = ((res >> 1) | (res << 7)) & 0xff; _F = SZP[res] | carry; return res; } inline byte RR(byte val) { unsigned res = val; unsigned carry = (res & 0x01) ? Cflag : 0; res = ((res >> 1) | (_F << 7)) & 0xff; _F = SZP[res] | carry; return res; } inline byte SET(byte bit, byte val) { return val | (1 << bit); } inline byte SLA(byte val) { unsigned res = val; unsigned carry = (res & 0x80) ? Cflag : 0; res = (res << 1) & 0xff; _F = SZP[res] | carry; return res; } inline byte SLL(byte val) { unsigned res = val; unsigned carry = (res & 0x80) ? Cflag : 0; res = ((res << 1) | 0x01) & 0xff; _F = SZP[res] | carry; return res; } inline byte SRA(byte val) { unsigned res = val; unsigned carry = (res & 0x01) ? Cflag : 0; res = ((res >> 1) | (res & 0x80)) & 0xff; _F = SZP[res] | carry; return res; } inline byte SRL(byte val) { unsigned res = val; unsigned carry = (res & 0x01) ? Cflag : 0; res = (res >> 1) & 0xff; _F = SZP[res] | carry; return res; } #define ADC16(reg) \ { \ dword res = _HLdword + z80.reg.d + (_F & Cflag); \ _F = (((_HLdword ^ res ^ z80.reg.d) >> 8) & Hflag) | \ ((res >> 16) & Cflag) | \ ((res >> 8) & (Sflag | Xflags)) | \ ((res & 0xffff) ? 0 : Zflag) | \ (((z80.reg.d ^ _HLdword ^ 0x8000) & (z80.reg.d ^ res) & 0x8000) >> 13); \ _HL = static_cast<word>(res); \ } #define CPD \ { \ byte val = read_mem(_HL); \ byte res = _A - val; \ _HL--; \ _BC--; \ _F = (_F & Cflag) | (SZ[res] & ~Xflags) | ((_A ^ val ^ res) & Hflag) | Nflag; \ if(_F & Hflag) res -= 1; \ if(res & 0x02) _F |= 0x20; \ if(res & 0x08) _F |= 0x08; \ if(_BC) _F |= Vflag; \ } #define CPDR \ CPD; \ if(_BC && !(_F & Zflag)) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ iWSAdjust++; \ } #define CPI \ { \ byte val = read_mem(_HL); \ byte res = _A - val; \ _HL++; \ _BC--; \ _F = (_F & Cflag) | (SZ[res] & ~Xflags) | ((_A ^ val ^ res) & Hflag) | Nflag; \ if(_F & Hflag) res -= 1; \ if(res & 0x02) _F |= 0x20; \ if(res & 0x08) _F |= 0x08; \ if(_BC) _F |= Vflag; \ } #define CPIR \ CPI; \ if(_BC && !(_F & Zflag)) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ iWSAdjust++; \ } #define IND \ { \ byte io = z80_IN_handler(z80.BC); \ _B--; \ write_mem(_HL, io); \ _HL--; \ _F = SZ[_B]; \ if(io & Sflag) _F |= Nflag; \ if((((_C - 1) & 0xff) + io) & 0x100) _F |= Hflag | Cflag; \ if((drep_tmp1[_C & 3][io & 3] ^ breg_tmp2[_B] ^ (_C >> 2) ^ (io >> 2)) & 1) \ _F |= Pflag; \ } #define INDR \ IND; \ if(_B) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define INI \ { \ byte io = z80_IN_handler(z80.BC); \ _B--; \ write_mem(_HL, io); \ _HL++; \ _F = SZ[_B]; \ if(io & Sflag) _F |= Nflag; \ if((((_C + 1) & 0xff) + io) & 0x100) _F |= Hflag | Cflag; \ if((irep_tmp1[_C & 3][io & 3] ^ breg_tmp2[_B] ^ (_C >> 2) ^ (io >> 2)) & 1) \ _F |= Pflag; \ } #define INIR \ INI; \ if(_B) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define LDD \ { \ byte io = read_mem(_HL); \ write_mem(_DE, io); \ _F &= Sflag | Zflag | Cflag; \ if((_A + io) & 0x02) _F |= 0x20; \ if((_A + io) & 0x08) _F |= 0x08; \ _HL--; \ _DE--; \ _BC--; \ if(_BC) _F |= Vflag; \ } #define LDDR \ LDD; \ if(_BC) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define LDI \ { \ byte io = read_mem(_HL); \ write_mem(_DE, io); \ _F &= Sflag | Zflag | Cflag; \ if((_A + io) & 0x02) _F |= 0x20; \ if((_A + io) & 0x08) _F |= 0x08; \ _HL++; \ _DE++; \ _BC--; \ if(_BC) _F |= Vflag; \ } #define LDIR \ LDI; \ if(_BC) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define NEG \ { \ byte value = _A; \ _A = 0; \ SUB(value); \ } #define OUTD \ { \ byte io = read_mem(_HL); \ _B--; \ z80_OUT_handler(z80.BC, io); \ _HL--; \ _F = SZ[_B]; \ if(io & Sflag) _F |= Nflag; \ if((((_C - 1) & 0xff) + io) & 0x100) _F |= Hflag | Cflag; \ if((drep_tmp1[_C & 3][io & 3] ^ breg_tmp2[_B] ^ (_C >> 2) ^ (io >> 2)) & 1) \ _F |= Pflag; \ } #define OTDR \ OUTD; \ if(_B) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define OUTI \ { \ byte io = read_mem(_HL); \ _B--; \ z80_OUT_handler(z80.BC, io); \ _HL++; \ _F = SZ[_B]; \ if(io & Sflag) _F |= Nflag; \ if((((_C + 1) & 0xff) + io) & 0x100) _F |= Hflag | Cflag; \ if((irep_tmp1[_C & 3][io & 3] ^ breg_tmp2[_B] ^ (_C >> 2) ^ (io >> 2)) & 1) \ _F |= Pflag; \ } #define OTIR \ OUTI; \ if(_B) \ { \ iCycleCount += cc_ex[bOpCode]; \ _PC -= 2; \ } #define RLD \ { \ byte n = read_mem(_HL); \ write_mem(_HL, (n << 4) | (_A & 0x0f)); \ _A = (_A & 0xf0) | (n >> 4); \ _F = (_F & Cflag) | SZP[_A]; \ } #define RRD \ { \ byte n = read_mem(_HL); \ write_mem(_HL, (n >> 4) | (_A << 4)); \ _A = (_A & 0xf0) | (n & 0x0f); \ _F = (_F & Cflag) | SZP[_A]; \ } #define SBC16(reg) \ { \ dword res = _HLdword - z80.reg.d - (_F & Cflag); \ _F = (((_HLdword ^ res ^ z80.reg.d) >> 8) & Hflag) | Nflag | \ ((res >> 16) & Cflag) | \ ((res >> 8) & (Sflag | Xflags)) | \ ((res & 0xffff) ? 0 : Zflag) | \ (((z80.reg.d ^ _HLdword) & (_HLdword ^ res) &0x8000) >> 13); \ _HL = static_cast<word>(res); \ } #define z80_int_handler \ { \ /*LOG_DEBUG("Interrupt handler " << static_cast<int>(_IFF1));*/ \ if (_IFF1) { /* process interrupts? */ \ _R++; \ _IFF1 = _IFF2 = 0; /* clear interrupt flip-flops */ \ z80.int_pending = 0; \ GateArray.sl_count &= 0x1f; /* clear bit 5 of GA scanline counter */ \ if (_HALT) { /* HALT instruction active? */ \ _HALT = 0; /* exit HALT 'loop' */ \ _PC++; /* correct PC */ \ } \ LOG_DEBUG("Interrupt mode " << static_cast<int>(_IM)); \ if (_IM < 2) { /* interrupt mode 0 or 1? (IM0 = IM1 on the CPC) */ \ iCycleCount = 20; \ if (iWSAdjust) { \ iCycleCount -= 4; \ } \ RST(0x0038); \ z80_wait_states \ } \ else { /* interrupt mode 2 */ \ reg_pair addr; \ iCycleCount = 28; /* was 76 */ \ if (iWSAdjust) { \ iCycleCount -= 4; \ } \ if (z80.step_out) { \ z80.step_out_addresses.push_back(_PC+2); \ } \ write_mem(--_SP, z80.PC.b.h); /* store high byte of current PC */ \ write_mem(--_SP, z80.PC.b.l); /* store low byte of current PC */ \ addr.b.l = 0xff; /* assemble pointer */ \ addr.b.h = _I; \ z80.PC.b.l = read_mem(addr.w.l); /* retrieve low byte of vector */ \ z80.PC.b.h = read_mem(addr.w.l+1); /* retrieve high byte of vector */ \ z80_wait_states \ } \ } \ } void z80_reset() { z80 = t_z80regs(); _IX = _IY = 0xffff; // IX and IY are FFFF after a reset! _F = Zflag; // set zero flag z80.break_point = 0xffffffff; // clear break point } void z80_init_tables() { int i, p; for (i = 0; i < 256; i++) { p = 0; if(i & 0x01) ++p; if(i & 0x02) ++p; if(i & 0x04) ++p; if(i & 0x08) ++p; if(i & 0x10) ++p; if(i & 0x20) ++p; if(i & 0x40) ++p; if(i & 0x80) ++p; SZ[i] = i ? i & Sflag : Zflag; SZ[i] |= (i & Xflags); SZ_BIT[i] = i ? i & Sflag : Zflag | Pflag; SZ_BIT[i] |= (i & Xflags); SZP[i] = SZ[i] | ((p & 1) ? 0 : Pflag); SZHV_inc[i] = SZ[i]; if(i == 0x80) SZHV_inc[i] |= Vflag; if((i & 0x0f) == 0x00) SZHV_inc[i] |= Hflag; SZHV_dec[i] = SZ[i] | Nflag; if(i == 0x7f) SZHV_dec[i] |= Vflag; if((i & 0x0f) == 0x0f) SZHV_dec[i] |= Hflag; } } void z80_mf2stop() { _R++; _IFF1 = 0; z80.EI_issued = 0; iCycleCount = 20; if (iWSAdjust) { iCycleCount -= 4; } dwMF2ExitAddr = _PCdword; RST(0x0066); // MF2 stop button causes a Z80 NMI z80_wait_states dwMF2Flags = MF2_ACTIVE | MF2_RUNNING; } int z80_execute() { z80.watchpoint_reached = 0; z80.breakpoint_reached = 0; while (_PCdword != z80.break_point) { // loop until break point #ifdef DEBUG_Z80 dbg_z80_diff = abs(dbg_z80_lastPC - _PC); if (dbg_z80_diff > 0x100) { fprintf(pfoDebug, "\n%04x ", _PC); } // else { // fprintf(pfoDebug, "%04x ", _PC); // } dbg_z80_lastPC = _PC; #endif if (dwMF2Flags & MF2_RUNNING) { if (_PCdword == dwMF2ExitAddr) { // have we returned from the MF2? dwMF2Flags = MF2_INVISIBLE; // clear running flag and make the MF2 'invisible' } } z80_execute_instruction(); z80_wait_states if (z80.EI_issued) { // EI 'delay' in effect? if (--z80.EI_issued == 0) { _IFF1 = _IFF2 = Pflag; // set interrupt flip-flops if (z80.int_pending) { z80_int_handler } } } else if (z80.int_pending) { // any interrupts pending? z80_int_handler } iWSAdjust = 0; if (VDU.frame_completed) { // video emulation finished building frame? VDU.frame_completed = 0; return EC_FRAME_COMPLETE; // exit emulation loop } if (PSG.buffer_full) { // sound emulation finished filling a buffer? PSG.buffer_full = 0; return EC_SOUND_BUFFER; // exit emulation loop } if (CPC.cycle_count <= 0) { // emulation loop ran for one frame? CPC.cycle_count += CYCLE_COUNT_INIT; return EC_CYCLE_COUNT; // exit emulation loop } // TODO: Measure impact. If important, create templated version of // z80_execute, read_mem, write_mem ... if (!breakpoints.empty()) { if ((z80.breakpoint_reached = std::any_of(breakpoints.begin(), breakpoints.end(), [&](const auto& b) { return b.address == _PC; }))) break; } if (z80.watchpoint_reached) break; if (z80.step_in) { z80.step_in++; break; } if (z80.trace) { // tracing instructions? z80.trace = 0; // reset trace condition return EC_TRACE; // exit emulation loop } } return EC_BREAKPOINT; } void z80_execute_instruction() { byte bOpCode = read_mem(_PC++); iCycleCount = cc_op[bOpCode]; _R++; switch(bOpCode) { case adc_a: ADC(_A); break; case adc_b: ADC(_B); break; case adc_byte: ADC(read_mem(_PC++)); break; case adc_c: ADC(_C); break; case adc_d: ADC(_D); break; case adc_e: ADC(_E); break; case adc_h: ADC(_H); break; case adc_l: ADC(_L); break; case adc_mhl: ADC(read_mem(_HL)); break; case add_a: ADD(_A); break; case add_b: ADD(_B); break; case add_byte: ADD(read_mem(_PC++)); break; case add_c: ADD(_C); break; case add_d: ADD(_D); break; case add_e: ADD(_E); break; case add_h: ADD(_H); break; case add_hl_bc: ADD16(HL, BC); break; case add_hl_de: ADD16(HL, DE); break; case add_hl_hl: ADD16(HL, HL); break; case add_hl_sp: ADD16(HL, SP); break; case add_l: ADD(_L); break; case add_mhl: ADD(read_mem(_HL)); break; case and_a: AND(_A); break; case and_b: AND(_B); break; case and_byte: AND(read_mem(_PC++)); break; case and_c: AND(_C); break; case and_d: AND(_D); break; case and_e: AND(_E); break; case and_h: AND(_H); break; case and_l: AND(_L); break; case and_mhl: AND(read_mem(_HL)); break; case call: CALL; break; case call_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case ccf: _F = ((_F & (Sflag | Zflag | Pflag | Cflag)) | ((_F & CF) << 4) | (_A & Xflags)) ^ CF; break; case cpl: _A ^= 0xff; _F = (_F & (Sflag | Zflag | Pflag | Cflag)) | Hflag | Nflag | (_A & Xflags); break; case cp_a: CP(_A); break; case cp_b: CP(_B); break; case cp_byte: CP(read_mem(_PC++)); break; case cp_c: CP(_C); break; case cp_d: CP(_D); break; case cp_e: CP(_E); break; case cp_h: CP(_H); break; case cp_l: CP(_L); break; case cp_mhl: CP(read_mem(_HL)); break; case daa: DAA; break; case dec_a: DEC(_A); break; case dec_b: DEC(_B); break; case dec_bc: _BC--; iWSAdjust++; break; case dec_c: DEC(_C); break; case dec_d: DEC(_D); break; case dec_de: _DE--; iWSAdjust++; break; case dec_e: DEC(_E); break; case dec_h: DEC(_H); break; case dec_hl: _HL--; iWSAdjust++; break; case dec_l: DEC(_L); break; case dec_mhl: { byte b = read_mem(_HL); DEC(b); write_mem(_HL, b); } break; case dec_sp: _SP--; iWSAdjust++; break; case di: _IFF1 = _IFF2 = 0; z80.EI_issued = 0; break; case djnz: if (--_B) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; } break; case ei: z80.EI_issued = 2; break; case exx: EXX; break; case ex_af_af: EX(z80.AF, z80.AFx); break; case ex_de_hl: EX(z80.DE, z80.HL); break; case ex_msp_hl: EX_SP(HL); iWSAdjust++; break; case halt: _HALT = 1; _PC--; break; case ina: { z80_wait_states iCycleCount = Ia_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; _A = z80_IN_handler(p); } break; case inc_a: INC(_A); break; case inc_b: INC(_B); break; case inc_bc: _BC++; iWSAdjust++; break; case inc_c: INC(_C); break; case inc_d: INC(_D); break; case inc_de: _DE++; iWSAdjust++; break; case inc_e: INC(_E); break; case inc_h: INC(_H); break; case inc_hl: _HL++; iWSAdjust++; break; case inc_l: INC(_L); break; case inc_mhl: { byte b = read_mem(_HL); INC(b); write_mem(_HL, b); } break; case inc_sp: _SP++; iWSAdjust++; break; case jp: JP; break; case jp_c: if (_F & Cflag) { JP } else { _PC += 2; }; break; case jp_m: if (_F & Sflag) { JP } else { _PC += 2; }; break; case jp_nc: if (!(_F & Cflag)) { JP } else { _PC += 2; }; break; case jp_nz: if (!(_F & Zflag)) { JP } else { _PC += 2; }; break; case jp_p: if (!(_F & Sflag)) { JP } else { _PC += 2; }; break; case jp_pe: if (_F & Pflag) { JP } else { _PC += 2; }; break; case jp_po: if (!(_F & Pflag)) { JP } else { _PC += 2; }; break; case jp_z: if (_F & Zflag) { JP } else { _PC += 2; }; break; case jr: JR; break; case jr_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case ld_a_a: break; case ld_a_b: _A = _B; break; case ld_a_byte: _A = read_mem(_PC++); break; case ld_a_c: _A = _C; break; case ld_a_d: _A = _D; break; case ld_a_e: _A = _E; break; case ld_a_h: _A = _H; break; case ld_a_l: _A = _L; break; case ld_a_mbc: _A = read_mem(_BC); break; case ld_a_mde: _A = read_mem(_DE); break; case ld_a_mhl: _A = read_mem(_HL); break; case ld_a_mword: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); _A = read_mem(addr.w.l); } break; case ld_bc_word: z80.BC.b.l = read_mem(_PC++); z80.BC.b.h = read_mem(_PC++); break; case ld_b_a: _B = _A; break; case ld_b_b: break; case ld_b_byte: _B = read_mem(_PC++); break; case ld_b_c: _B = _C; break; case ld_b_d: _B = _D; break; case ld_b_e: _B = _E; break; case ld_b_h: _B = _H; break; case ld_b_l: _B = _L; break; case ld_b_mhl: _B = read_mem(_HL); break; case ld_c_a: _C = _A; break; case ld_c_b: _C = _B; break; case ld_c_byte: _C = read_mem(_PC++); break; case ld_c_c: break; case ld_c_d: _C = _D; break; case ld_c_e: _C = _E; break; case ld_c_h: _C = _H; break; case ld_c_l: _C = _L; break; case ld_c_mhl: _C = read_mem(_HL); break; case ld_de_word: z80.DE.b.l = read_mem(_PC++); z80.DE.b.h = read_mem(_PC++); break; case ld_d_a: _D = _A; break; case ld_d_b: _D = _B; break; case ld_d_byte: _D = read_mem(_PC++); break; case ld_d_c: _D = _C; break; case ld_d_d: break; case ld_d_e: _D = _E; break; case ld_d_h: _D = _H; break; case ld_d_l: _D = _L; break; case ld_d_mhl: _D = read_mem(_HL); break; case ld_e_a: _E = _A; break; case ld_e_b: _E = _B; break; case ld_e_byte: _E = read_mem(_PC++); break; case ld_e_c: _E = _C; break; case ld_e_d: _E = _D; break; case ld_e_e: break; case ld_e_h: _E = _H; break; case ld_e_l: _E = _L; break; case ld_e_mhl: _E = read_mem(_HL); break; case ld_hl_mword: LD16_MEM(HL); break; case ld_hl_word: z80.HL.b.l = read_mem(_PC++); z80.HL.b.h = read_mem(_PC++); break; case ld_h_a: _H = _A; break; case ld_h_b: _H = _B; break; case ld_h_byte: _H = read_mem(_PC++); break; case ld_h_c: _H = _C; break; case ld_h_d: _H = _D; break; case ld_h_e: _H = _E; break; case ld_h_h: break; case ld_h_l: _H = _L; break; case ld_h_mhl: _H = read_mem(_HL); break; case ld_l_a: _L = _A; break; case ld_l_b: _L = _B; break; case ld_l_byte: _L = read_mem(_PC++); break; case ld_l_c: _L = _C; break; case ld_l_d: _L = _D; break; case ld_l_e: _L = _E; break; case ld_l_h: _L = _H; break; case ld_l_l: break; case ld_l_mhl: _L = read_mem(_HL); break; case ld_mbc_a: write_mem(_BC, _A); break; case ld_mde_a: write_mem(_DE, _A); break; case ld_mhl_a: write_mem(_HL, _A); break; case ld_mhl_b: write_mem(_HL, _B); break; case ld_mhl_byte: { byte b = read_mem(_PC++); write_mem(_HL, b); } break; case ld_mhl_c: write_mem(_HL, _C); break; case ld_mhl_d: write_mem(_HL, _D); break; case ld_mhl_e: write_mem(_HL, _E); break; case ld_mhl_h: write_mem(_HL, _H); break; case ld_mhl_l: write_mem(_HL, _L); break; case ld_mword_a: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); write_mem(addr.w.l, _A); } break; case ld_mword_hl: LDMEM_16(HL); break; case ld_pc_hl: _PC = _HL; break; case ld_sp_hl: _SP = _HL; iWSAdjust++; break; case ld_sp_word: z80.SP.b.l = read_mem(_PC++); z80.SP.b.h = read_mem(_PC++); break; case nop: break; case or_a: OR(_A); break; case or_b: OR(_B); break; case or_byte: OR(read_mem(_PC++)); break; case or_c: OR(_C); break; case or_d: OR(_D); break; case or_e: OR(_E); break; case or_h: OR(_H); break; case or_l: OR(_L); break; case or_mhl: OR(read_mem(_HL)); break; case outa: { z80_wait_states iCycleCount = Oa_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; z80_OUT_handler(p, _A); } break; case pfx_cb: z80_execute_pfx_cb_instruction(); break; case pfx_dd: z80_execute_pfx_dd_instruction(); break; case pfx_ed: z80_execute_pfx_ed_instruction(); break; case pfx_fd: z80_execute_pfx_fd_instruction(); break; case pop_af: POP(AF); break; case pop_bc: POP(BC); break; case pop_de: POP(DE); break; case pop_hl: POP(HL); break; case push_af: PUSH(AF); break; case push_bc: PUSH(BC); break; case push_de: PUSH(DE); break; case push_hl: PUSH(HL); break; case ret: RET; break; case ret_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case rla: RLA; break; case rlca: RLCA; break; case rra: RRA; break; case rrca: RRCA; break; case rst00: RST(0x0000); break; case rst08: RST(0x0008); break; case rst10: RST(0x0010); break; case rst18: RST(0x0018); break; case rst20: RST(0x0020); break; case rst28: RST(0x0028); break; case rst30: RST(0x0030); break; case rst38: RST(0x0038); break; case sbc_a: SBC(_A); break; case sbc_b: SBC(_B); break; case sbc_byte: SBC(read_mem(_PC++)); break; case sbc_c: SBC(_C); break; case sbc_d: SBC(_D); break; case sbc_e: SBC(_E); break; case sbc_h: SBC(_H); break; case sbc_l: SBC(_L); break; case sbc_mhl: SBC(read_mem(_HL)); break; case scf: _F = (_F & (Sflag | Zflag | Pflag)) | Cflag | (_A & Xflags); break; case sub_a: SUB(_A); break; case sub_b: SUB(_B); break; case sub_byte: SUB(read_mem(_PC++)); break; case sub_c: SUB(_C); break; case sub_d: SUB(_D); break; case sub_e: SUB(_E); break; case sub_h: SUB(_H); break; case sub_l: SUB(_L); break; case sub_mhl: SUB(read_mem(_HL)); break; case xor_a: XOR(_A); break; case xor_b: XOR(_B); break; case xor_byte: XOR(read_mem(_PC++)); break; case xor_c: XOR(_C); break; case xor_d: XOR(_D); break; case xor_e: XOR(_E); break; case xor_h: XOR(_H); break; case xor_l: XOR(_L); break; case xor_mhl: XOR(read_mem(_HL)); break; } } void z80_execute_pfx_cb_instruction() { byte bOpCode; bOpCode = read_mem(_PC++); iCycleCount += cc_cb[bOpCode]; _R++; switch(bOpCode) { case bit0_a: BIT(0, _A); break; case bit0_b: BIT(0, _B); break; case bit0_c: BIT(0, _C); break; case bit0_d: BIT(0, _D); break; case bit0_e: BIT(0, _E); break; case bit0_h: BIT(0, _H); break; case bit0_l: BIT(0, _L); break; case bit0_mhl: BIT(0, read_mem(_HL)); break; case bit1_a: BIT(1, _A); break; case bit1_b: BIT(1, _B); break; case bit1_c: BIT(1, _C); break; case bit1_d: BIT(1, _D); break; case bit1_e: BIT(1, _E); break; case bit1_h: BIT(1, _H); break; case bit1_l: BIT(1, _L); break; case bit1_mhl: BIT(1, read_mem(_HL)); break; case bit2_a: BIT(2, _A); break; case bit2_b: BIT(2, _B); break; case bit2_c: BIT(2, _C); break; case bit2_d: BIT(2, _D); break; case bit2_e: BIT(2, _E); break; case bit2_h: BIT(2, _H); break; case bit2_l: BIT(2, _L); break; case bit2_mhl: BIT(2, read_mem(_HL)); break; case bit3_a: BIT(3, _A); break; case bit3_b: BIT(3, _B); break; case bit3_c: BIT(3, _C); break; case bit3_d: BIT(3, _D); break; case bit3_e: BIT(3, _E); break; case bit3_h: BIT(3, _H); break; case bit3_l: BIT(3, _L); break; case bit3_mhl: BIT(3, read_mem(_HL)); break; case bit4_a: BIT(4, _A); break; case bit4_b: BIT(4, _B); break; case bit4_c: BIT(4, _C); break; case bit4_d: BIT(4, _D); break; case bit4_e: BIT(4, _E); break; case bit4_h: BIT(4, _H); break; case bit4_l: BIT(4, _L); break; case bit4_mhl: BIT(4, read_mem(_HL)); break; case bit5_a: BIT(5, _A); break; case bit5_b: BIT(5, _B); break; case bit5_c: BIT(5, _C); break; case bit5_d: BIT(5, _D); break; case bit5_e: BIT(5, _E); break; case bit5_h: BIT(5, _H); break; case bit5_l: BIT(5, _L); break; case bit5_mhl: BIT(5, read_mem(_HL)); break; case bit6_a: BIT(6, _A); break; case bit6_b: BIT(6, _B); break; case bit6_c: BIT(6, _C); break; case bit6_d: BIT(6, _D); break; case bit6_e: BIT(6, _E); break; case bit6_h: BIT(6, _H); break; case bit6_l: BIT(6, _L); break; case bit6_mhl: BIT(6, read_mem(_HL)); break; case bit7_a: BIT(7, _A); break; case bit7_b: BIT(7, _B); break; case bit7_c: BIT(7, _C); break; case bit7_d: BIT(7, _D); break; case bit7_e: BIT(7, _E); break; case bit7_h: BIT(7, _H); break; case bit7_l: BIT(7, _L); break; case bit7_mhl: BIT(7, read_mem(_HL)); break; case res0_a: _A = RES(0, _A); break; case res0_b: _B = RES(0, _B); break; case res0_c: _C = RES(0, _C); break; case res0_d: _D = RES(0, _D); break; case res0_e: _E = RES(0, _E); break; case res0_h: _H = RES(0, _H); break; case res0_l: _L = RES(0, _L); break; case res0_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(0, b)); } break; case res1_a: _A = RES(1, _A); break; case res1_b: _B = RES(1, _B); break; case res1_c: _C = RES(1, _C); break; case res1_d: _D = RES(1, _D); break; case res1_e: _E = RES(1, _E); break; case res1_h: _H = RES(1, _H); break; case res1_l: _L = RES(1, _L); break; case res1_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(1, b)); } break; case res2_a: _A = RES(2, _A); break; case res2_b: _B = RES(2, _B); break; case res2_c: _C = RES(2, _C); break; case res2_d: _D = RES(2, _D); break; case res2_e: _E = RES(2, _E); break; case res2_h: _H = RES(2, _H); break; case res2_l: _L = RES(2, _L); break; case res2_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(2, b)); } break; case res3_a: _A = RES(3, _A); break; case res3_b: _B = RES(3, _B); break; case res3_c: _C = RES(3, _C); break; case res3_d: _D = RES(3, _D); break; case res3_e: _E = RES(3, _E); break; case res3_h: _H = RES(3, _H); break; case res3_l: _L = RES(3, _L); break; case res3_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(3, b)); } break; case res4_a: _A = RES(4, _A); break; case res4_b: _B = RES(4, _B); break; case res4_c: _C = RES(4, _C); break; case res4_d: _D = RES(4, _D); break; case res4_e: _E = RES(4, _E); break; case res4_h: _H = RES(4, _H); break; case res4_l: _L = RES(4, _L); break; case res4_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(4, b)); } break; case res5_a: _A = RES(5, _A); break; case res5_b: _B = RES(5, _B); break; case res5_c: _C = RES(5, _C); break; case res5_d: _D = RES(5, _D); break; case res5_e: _E = RES(5, _E); break; case res5_h: _H = RES(5, _H); break; case res5_l: _L = RES(5, _L); break; case res5_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(5, b)); } break; case res6_a: _A = RES(6, _A); break; case res6_b: _B = RES(6, _B); break; case res6_c: _C = RES(6, _C); break; case res6_d: _D = RES(6, _D); break; case res6_e: _E = RES(6, _E); break; case res6_h: _H = RES(6, _H); break; case res6_l: _L = RES(6, _L); break; case res6_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(6, b)); } break; case res7_a: _A = RES(7, _A); break; case res7_b: _B = RES(7, _B); break; case res7_c: _C = RES(7, _C); break; case res7_d: _D = RES(7, _D); break; case res7_e: _E = RES(7, _E); break; case res7_h: _H = RES(7, _H); break; case res7_l: _L = RES(7, _L); break; case res7_mhl: { byte b = read_mem(_HL); write_mem(_HL, RES(7, b)); } break; case rlc_a: _A = RLC(_A); break; case rlc_b: _B = RLC(_B); break; case rlc_c: _C = RLC(_C); break; case rlc_d: _D = RLC(_D); break; case rlc_e: _E = RLC(_E); break; case rlc_h: _H = RLC(_H); break; case rlc_l: _L = RLC(_L); break; case rlc_mhl: { byte b = read_mem(_HL); write_mem(_HL, RLC(b)); } break; case rl_a: _A = RL(_A); break; case rl_b: _B = RL(_B); break; case rl_c: _C = RL(_C); break; case rl_d: _D = RL(_D); break; case rl_e: _E = RL(_E); break; case rl_h: _H = RL(_H); break; case rl_l: _L = RL(_L); break; case rl_mhl: { byte b = read_mem(_HL); write_mem(_HL, RL(b)); } break; case rrc_a: _A = RRC(_A); break; case rrc_b: _B = RRC(_B); break; case rrc_c: _C = RRC(_C); break; case rrc_d: _D = RRC(_D); break; case rrc_e: _E = RRC(_E); break; case rrc_h: _H = RRC(_H); break; case rrc_l: _L = RRC(_L); break; case rrc_mhl: { byte b = read_mem(_HL); write_mem(_HL, RRC(b)); } break; case rr_a: _A = RR(_A); break; case rr_b: _B = RR(_B); break; case rr_c: _C = RR(_C); break; case rr_d: _D = RR(_D); break; case rr_e: _E = RR(_E); break; case rr_h: _H = RR(_H); break; case rr_l: _L = RR(_L); break; case rr_mhl: { byte b = read_mem(_HL); write_mem(_HL, RR(b)); } break; case set0_a: _A = SET(0, _A); break; case set0_b: _B = SET(0, _B); break; case set0_c: _C = SET(0, _C); break; case set0_d: _D = SET(0, _D); break; case set0_e: _E = SET(0, _E); break; case set0_h: _H = SET(0, _H); break; case set0_l: _L = SET(0, _L); break; case set0_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(0, b)); } break; case set1_a: _A = SET(1, _A); break; case set1_b: _B = SET(1, _B); break; case set1_c: _C = SET(1, _C); break; case set1_d: _D = SET(1, _D); break; case set1_e: _E = SET(1, _E); break; case set1_h: _H = SET(1, _H); break; case set1_l: _L = SET(1, _L); break; case set1_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(1, b)); } break; case set2_a: _A = SET(2, _A); break; case set2_b: _B = SET(2, _B); break; case set2_c: _C = SET(2, _C); break; case set2_d: _D = SET(2, _D); break; case set2_e: _E = SET(2, _E); break; case set2_h: _H = SET(2, _H); break; case set2_l: _L = SET(2, _L); break; case set2_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(2, b)); } break; case set3_a: _A = SET(3, _A); break; case set3_b: _B = SET(3, _B); break; case set3_c: _C = SET(3, _C); break; case set3_d: _D = SET(3, _D); break; case set3_e: _E = SET(3, _E); break; case set3_h: _H = SET(3, _H); break; case set3_l: _L = SET(3, _L); break; case set3_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(3, b)); } break; case set4_a: _A = SET(4, _A); break; case set4_b: _B = SET(4, _B); break; case set4_c: _C = SET(4, _C); break; case set4_d: _D = SET(4, _D); break; case set4_e: _E = SET(4, _E); break; case set4_h: _H = SET(4, _H); break; case set4_l: _L = SET(4, _L); break; case set4_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(4, b)); } break; case set5_a: _A = SET(5, _A); break; case set5_b: _B = SET(5, _B); break; case set5_c: _C = SET(5, _C); break; case set5_d: _D = SET(5, _D); break; case set5_e: _E = SET(5, _E); break; case set5_h: _H = SET(5, _H); break; case set5_l: _L = SET(5, _L); break; case set5_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(5, b)); } break; case set6_a: _A = SET(6, _A); break; case set6_b: _B = SET(6, _B); break; case set6_c: _C = SET(6, _C); break; case set6_d: _D = SET(6, _D); break; case set6_e: _E = SET(6, _E); break; case set6_h: _H = SET(6, _H); break; case set6_l: _L = SET(6, _L); break; case set6_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(6, b)); } break; case set7_a: _A = SET(7, _A); break; case set7_b: _B = SET(7, _B); break; case set7_c: _C = SET(7, _C); break; case set7_d: _D = SET(7, _D); break; case set7_e: _E = SET(7, _E); break; case set7_h: _H = SET(7, _H); break; case set7_l: _L = SET(7, _L); break; case set7_mhl: { byte b = read_mem(_HL); write_mem(_HL, SET(7, b)); } break; case sla_a: _A = SLA(_A); break; case sla_b: _B = SLA(_B); break; case sla_c: _C = SLA(_C); break; case sla_d: _D = SLA(_D); break; case sla_e: _E = SLA(_E); break; case sla_h: _H = SLA(_H); break; case sla_l: _L = SLA(_L); break; case sla_mhl: { byte b = read_mem(_HL); write_mem(_HL, SLA(b)); } break; case sll_a: _A = SLL(_A); break; case sll_b: _B = SLL(_B); break; case sll_c: _C = SLL(_C); break; case sll_d: _D = SLL(_D); break; case sll_e: _E = SLL(_E); break; case sll_h: _H = SLL(_H); break; case sll_l: _L = SLL(_L); break; case sll_mhl: { byte b = read_mem(_HL); write_mem(_HL, SLL(b)); } break; case sra_a: _A = SRA(_A); break; case sra_b: _B = SRA(_B); break; case sra_c: _C = SRA(_C); break; case sra_d: _D = SRA(_D); break; case sra_e: _E = SRA(_E); break; case sra_h: _H = SRA(_H); break; case sra_l: _L = SRA(_L); break; case sra_mhl: { byte b = read_mem(_HL); write_mem(_HL, SRA(b)); } break; case srl_a: _A = SRL(_A); break; case srl_b: _B = SRL(_B); break; case srl_c: _C = SRL(_C); break; case srl_d: _D = SRL(_D); break; case srl_e: _E = SRL(_E); break; case srl_h: _H = SRL(_H); break; case srl_l: _L = SRL(_L); break; case srl_mhl: { byte b = read_mem(_HL); write_mem(_HL, SRL(b)); } break; } } void z80_execute_pfx_dd_instruction() { byte bOpCode; bOpCode = read_mem(_PC++); iCycleCount += cc_xy[bOpCode]; _R++; switch(bOpCode) { case adc_a: ADC(_A); break; case adc_b: ADC(_B); break; case adc_byte: ADC(read_mem(_PC++)); break; case adc_c: ADC(_C); break; case adc_d: ADC(_D); break; case adc_e: ADC(_E); break; case adc_h: ADC(_IXh); break; case adc_l: ADC(_IXl); break; case adc_mhl: { signed char o = read_mem(_PC++); ADC(read_mem(_IX+o)); } break; case add_a: ADD(_A); break; case add_b: ADD(_B); break; case add_byte: ADD(read_mem(_PC++)); break; case add_c: ADD(_C); break; case add_d: ADD(_D); break; case add_e: ADD(_E); break; case add_h: ADD(_IXh); break; case add_hl_bc: ADD16(IX, BC); break; case add_hl_de: ADD16(IX, DE); break; case add_hl_hl: ADD16(IX, IX); break; case add_hl_sp: ADD16(IX, SP); break; case add_l: ADD(_IXl); break; case add_mhl: { signed char o = read_mem(_PC++); ADD(read_mem(_IX+o)); } break; case and_a: AND(_A); break; case and_b: AND(_B); break; case and_byte: AND(read_mem(_PC++)); break; case and_c: AND(_C); break; case and_d: AND(_D); break; case and_e: AND(_E); break; case and_h: AND(_IXh); break; case and_l: AND(_IXl); break; case and_mhl: { signed char o = read_mem(_PC++); AND(read_mem(_IX+o)); } break; case call: CALL; break; case call_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case ccf: _F = ((_F & (Sflag | Zflag | Pflag | Cflag)) | ((_F & CF) << 4) | (_A & Xflags)) ^ CF; break; case cpl: _A ^= 0xff; _F = (_F & (Sflag | Zflag | Pflag | Cflag)) | Hflag | Nflag | (_A & Xflags); break; case cp_a: CP(_A); break; case cp_b: CP(_B); break; case cp_byte: CP(read_mem(_PC++)); break; case cp_c: CP(_C); break; case cp_d: CP(_D); break; case cp_e: CP(_E); break; case cp_h: CP(_IXh); break; case cp_l: CP(_IXl); break; case cp_mhl: { signed char o = read_mem(_PC++); CP(read_mem(_IX+o)); } break; case daa: DAA; break; case dec_a: DEC(_A); break; case dec_b: DEC(_B); break; case dec_bc: _BC--; iWSAdjust++; break; case dec_c: DEC(_C); break; case dec_d: DEC(_D); break; case dec_de: _DE--; iWSAdjust++; break; case dec_e: DEC(_E); break; case dec_h: DEC(_IXh); break; case dec_hl: _IX--; iWSAdjust++; break; case dec_l: DEC(_IXl); break; case dec_mhl: { signed char o = read_mem(_PC++); byte b = read_mem(_IX+o); DEC(b); write_mem(_IX+o, b); } break; case dec_sp: _SP--; iWSAdjust++; break; case di: _IFF1 = _IFF2 = 0; z80.EI_issued = 0; break; case djnz: if (--_B) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; } break; case ei: z80.EI_issued = 2; break; case exx: EXX; break; case ex_af_af: EX(z80.AF, z80.AFx); break; case ex_de_hl: EX(z80.DE, z80.HL); break; case ex_msp_hl: EX_SP(IX); iWSAdjust++; break; case halt: _HALT = 1; _PC--; break; case ina: { z80_wait_states iCycleCount = Ia_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; _A = z80_IN_handler(p); } break; case inc_a: INC(_A); break; case inc_b: INC(_B); break; case inc_bc: _BC++; iWSAdjust++; break; case inc_c: INC(_C); break; case inc_d: INC(_D); break; case inc_de: _DE++; iWSAdjust++; break; case inc_e: INC(_E); break; case inc_h: INC(_IXh); break; case inc_hl: _IX++; iWSAdjust++; break; case inc_l: INC(_IXl); break; case inc_mhl: { signed char o = read_mem(_PC++); byte b = read_mem(_IX+o); INC(b); write_mem(_IX+o, b); } break; case inc_sp: _SP++; iWSAdjust++; break; case jp: JP; break; case jp_c: if (_F & Cflag) { JP } else { _PC += 2; }; break; case jp_m: if (_F & Sflag) { JP } else { _PC += 2; }; break; case jp_nc: if (!(_F & Cflag)) { JP } else { _PC += 2; }; break; case jp_nz: if (!(_F & Zflag)) { JP } else { _PC += 2; }; break; case jp_p: if (!(_F & Sflag)) { JP } else { _PC += 2; }; break; case jp_pe: if (_F & Pflag) { JP } else { _PC += 2; }; break; case jp_po: if (!(_F & Pflag)) { JP } else { _PC += 2; }; break; case jp_z: if (_F & Zflag) { JP } else { _PC += 2; }; break; case jr: JR; break; case jr_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case ld_a_a: break; case ld_a_b: _A = _B; break; case ld_a_byte: _A = read_mem(_PC++); break; case ld_a_c: _A = _C; break; case ld_a_d: _A = _D; break; case ld_a_e: _A = _E; break; case ld_a_h: _A = _IXh; break; case ld_a_l: _A = _IXl; break; case ld_a_mbc: _A = read_mem(_BC); break; case ld_a_mde: _A = read_mem(_DE); break; case ld_a_mhl: { signed char o = read_mem(_PC++); _A = read_mem(_IX+o); } break; case ld_a_mword: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); _A = read_mem(addr.w.l); } break; case ld_bc_word: z80.BC.b.l = read_mem(_PC++); z80.BC.b.h = read_mem(_PC++); break; case ld_b_a: _B = _A; break; case ld_b_b: break; case ld_b_byte: _B = read_mem(_PC++); break; case ld_b_c: _B = _C; break; case ld_b_d: _B = _D; break; case ld_b_e: _B = _E; break; case ld_b_h: _B = _IXh; break; case ld_b_l: _B = _IXl; break; case ld_b_mhl: { signed char o = read_mem(_PC++); _B = read_mem(_IX+o); } break; case ld_c_a: _C = _A; break; case ld_c_b: _C = _B; break; case ld_c_byte: _C = read_mem(_PC++); break; case ld_c_c: break; case ld_c_d: _C = _D; break; case ld_c_e: _C = _E; break; case ld_c_h: _C = _IXh; break; case ld_c_l: _C = _IXl; break; case ld_c_mhl: { signed char o = read_mem(_PC++); _C = read_mem(_IX+o); } break; case ld_de_word: z80.DE.b.l = read_mem(_PC++); z80.DE.b.h = read_mem(_PC++); break; case ld_d_a: _D = _A; break; case ld_d_b: _D = _B; break; case ld_d_byte: _D = read_mem(_PC++); break; case ld_d_c: _D = _C; break; case ld_d_d: break; case ld_d_e: _D = _E; break; case ld_d_h: _D = _IXh; break; case ld_d_l: _D = _IXl; break; case ld_d_mhl: { signed char o = read_mem(_PC++); _D = read_mem(_IX+o); } break; case ld_e_a: _E = _A; break; case ld_e_b: _E = _B; break; case ld_e_byte: _E = read_mem(_PC++); break; case ld_e_c: _E = _C; break; case ld_e_d: _E = _D; break; case ld_e_e: break; case ld_e_h: _E = _IXh; break; case ld_e_l: _E = _IXl; break; case ld_e_mhl: { signed char o = read_mem(_PC++); _E = read_mem(_IX+o); } break; case ld_hl_mword: LD16_MEM(IX); break; case ld_hl_word: z80.IX.b.l = read_mem(_PC++); z80.IX.b.h = read_mem(_PC++); break; case ld_h_a: _IXh = _A; break; case ld_h_b: _IXh = _B; break; case ld_h_byte: _IXh = read_mem(_PC++); break; case ld_h_c: _IXh = _C; break; case ld_h_d: _IXh = _D; break; case ld_h_e: _IXh = _E; break; case ld_h_h: break; case ld_h_l: _IXh = _IXl; break; case ld_h_mhl: { signed char o = read_mem(_PC++); _H = read_mem(_IX+o); } break; case ld_l_a: _IXl = _A; break; case ld_l_b: _IXl = _B; break; case ld_l_byte: _IXl = read_mem(_PC++); break; case ld_l_c: _IXl = _C; break; case ld_l_d: _IXl = _D; break; case ld_l_e: _IXl = _E; break; case ld_l_h: _IXl = _IXh; break; case ld_l_l: break; case ld_l_mhl: { signed char o = read_mem(_PC++); _L = read_mem(_IX+o); } break; case ld_mbc_a: write_mem(_BC, _A); break; case ld_mde_a: write_mem(_DE, _A); break; case ld_mhl_a: { signed char o = read_mem(_PC++); write_mem(_IX+o, _A); } break; case ld_mhl_b: { signed char o = read_mem(_PC++); write_mem(_IX+o, _B); } break; case ld_mhl_byte: { signed char o = read_mem(_PC++); byte b = read_mem(_PC++); write_mem(_IX+o, b); } break; case ld_mhl_c: { signed char o = read_mem(_PC++); write_mem(_IX+o, _C); } break; case ld_mhl_d: { signed char o = read_mem(_PC++); write_mem(_IX+o, _D); } break; case ld_mhl_e: { signed char o = read_mem(_PC++); write_mem(_IX+o, _E); } break; case ld_mhl_h: { signed char o = read_mem(_PC++); write_mem(_IX+o, _H); } break; case ld_mhl_l: { signed char o = read_mem(_PC++); write_mem(_IX+o, _L); } break; case ld_mword_a: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); write_mem(addr.w.l, _A); } break; case ld_mword_hl: LDMEM_16(IX); break; case ld_pc_hl: _PC = _IX; break; case ld_sp_hl: _SP = _IX; iWSAdjust++; break; case ld_sp_word: z80.SP.b.l = read_mem(_PC++); z80.SP.b.h = read_mem(_PC++); break; case nop: break; case or_a: OR(_A); break; case or_b: OR(_B); break; case or_byte: OR(read_mem(_PC++)); break; case or_c: OR(_C); break; case or_d: OR(_D); break; case or_e: OR(_E); break; case or_h: OR(_IXh); break; case or_l: OR(_IXl); break; case or_mhl: { signed char o = read_mem(_PC++); OR(read_mem(_IX+o)); } break; case outa: { z80_wait_states iCycleCount = Oa_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; z80_OUT_handler(p, _A); } break; case pfx_cb: z80_execute_pfx_ddcb_instruction(); break; case pfx_dd: z80_execute_pfx_dd_instruction(); break; case pfx_ed: z80_execute_pfx_ed_instruction(); break; case pfx_fd: z80_execute_pfx_fd_instruction(); break; case pop_af: POP(AF); break; case pop_bc: POP(BC); break; case pop_de: POP(DE); break; case pop_hl: POP(IX); break; case push_af: PUSH(AF); break; case push_bc: PUSH(BC); break; case push_de: PUSH(DE); break; case push_hl: PUSH(IX); break; case ret: RET; break; case ret_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case rla: RLA; break; case rlca: RLCA; break; case rra: RRA; break; case rrca: RRCA; break; case rst00: RST(0x0000); break; case rst08: RST(0x0008); break; case rst10: RST(0x0010); break; case rst18: RST(0x0018); break; case rst20: RST(0x0020); break; case rst28: RST(0x0028); break; case rst30: RST(0x0030); break; case rst38: RST(0x0038); break; case sbc_a: SBC(_A); break; case sbc_b: SBC(_B); break; case sbc_byte: SBC(read_mem(_PC++)); break; case sbc_c: SBC(_C); break; case sbc_d: SBC(_D); break; case sbc_e: SBC(_E); break; case sbc_h: SBC(_IXh); break; case sbc_l: SBC(_IXl); break; case sbc_mhl: { signed char o = read_mem(_PC++); SBC(read_mem(_IX+o)); } break; case scf: _F = (_F & (Sflag | Zflag | Pflag)) | Cflag | (_A & Xflags); break; case sub_a: SUB(_A); break; case sub_b: SUB(_B); break; case sub_byte: SUB(read_mem(_PC++)); break; case sub_c: SUB(_C); break; case sub_d: SUB(_D); break; case sub_e: SUB(_E); break; case sub_h: SUB(_IXh); break; case sub_l: SUB(_IXl); break; case sub_mhl: { signed char o = read_mem(_PC++); SUB(read_mem(_IX+o)); } break; case xor_a: XOR(_A); break; case xor_b: XOR(_B); break; case xor_byte: XOR(read_mem(_PC++)); break; case xor_c: XOR(_C); break; case xor_d: XOR(_D); break; case xor_e: XOR(_E); break; case xor_h: XOR(_IXh); break; case xor_l: XOR(_IXl); break; case xor_mhl: { signed char o = read_mem(_PC++); XOR(read_mem(_IX+o)); } break; } } void z80_execute_pfx_ddcb_instruction() { signed char o; byte bOpCode; o = read_mem(_PC++); // offset bOpCode = read_mem(_PC++); iCycleCount += cc_xycb[bOpCode]; switch(bOpCode) { case bit0_a: BIT_XY(0, read_mem(_IX+o)); break; case bit0_b: BIT_XY(0, read_mem(_IX+o)); break; case bit0_c: BIT_XY(0, read_mem(_IX+o)); break; case bit0_d: BIT_XY(0, read_mem(_IX+o)); break; case bit0_e: BIT_XY(0, read_mem(_IX+o)); break; case bit0_h: BIT_XY(0, read_mem(_IX+o)); break; case bit0_l: BIT_XY(0, read_mem(_IX+o)); break; case bit0_mhl: BIT_XY(0, read_mem(_IX+o)); break; case bit1_a: BIT_XY(1, read_mem(_IX+o)); break; case bit1_b: BIT_XY(1, read_mem(_IX+o)); break; case bit1_c: BIT_XY(1, read_mem(_IX+o)); break; case bit1_d: BIT_XY(1, read_mem(_IX+o)); break; case bit1_e: BIT_XY(1, read_mem(_IX+o)); break; case bit1_h: BIT_XY(1, read_mem(_IX+o)); break; case bit1_l: BIT_XY(1, read_mem(_IX+o)); break; case bit1_mhl: BIT_XY(1, read_mem(_IX+o)); break; case bit2_a: BIT_XY(2, read_mem(_IX+o)); break; case bit2_b: BIT_XY(2, read_mem(_IX+o)); break; case bit2_c: BIT_XY(2, read_mem(_IX+o)); break; case bit2_d: BIT_XY(2, read_mem(_IX+o)); break; case bit2_e: BIT_XY(2, read_mem(_IX+o)); break; case bit2_h: BIT_XY(2, read_mem(_IX+o)); break; case bit2_l: BIT_XY(2, read_mem(_IX+o)); break; case bit2_mhl: BIT_XY(2, read_mem(_IX+o)); break; case bit3_a: BIT_XY(3, read_mem(_IX+o)); break; case bit3_b: BIT_XY(3, read_mem(_IX+o)); break; case bit3_c: BIT_XY(3, read_mem(_IX+o)); break; case bit3_d: BIT_XY(3, read_mem(_IX+o)); break; case bit3_e: BIT_XY(3, read_mem(_IX+o)); break; case bit3_h: BIT_XY(3, read_mem(_IX+o)); break; case bit3_l: BIT_XY(3, read_mem(_IX+o)); break; case bit3_mhl: BIT_XY(3, read_mem(_IX+o)); break; case bit4_a: BIT_XY(4, read_mem(_IX+o)); break; case bit4_b: BIT_XY(4, read_mem(_IX+o)); break; case bit4_c: BIT_XY(4, read_mem(_IX+o)); break; case bit4_d: BIT_XY(4, read_mem(_IX+o)); break; case bit4_e: BIT_XY(4, read_mem(_IX+o)); break; case bit4_h: BIT_XY(4, read_mem(_IX+o)); break; case bit4_l: BIT_XY(4, read_mem(_IX+o)); break; case bit4_mhl: BIT_XY(4, read_mem(_IX+o)); break; case bit5_a: BIT_XY(5, read_mem(_IX+o)); break; case bit5_b: BIT_XY(5, read_mem(_IX+o)); break; case bit5_c: BIT_XY(5, read_mem(_IX+o)); break; case bit5_d: BIT_XY(5, read_mem(_IX+o)); break; case bit5_e: BIT_XY(5, read_mem(_IX+o)); break; case bit5_h: BIT_XY(5, read_mem(_IX+o)); break; case bit5_l: BIT_XY(5, read_mem(_IX+o)); break; case bit5_mhl: BIT_XY(5, read_mem(_IX+o)); break; case bit6_a: BIT_XY(6, read_mem(_IX+o)); break; case bit6_b: BIT_XY(6, read_mem(_IX+o)); break; case bit6_c: BIT_XY(6, read_mem(_IX+o)); break; case bit6_d: BIT_XY(6, read_mem(_IX+o)); break; case bit6_e: BIT_XY(6, read_mem(_IX+o)); break; case bit6_h: BIT_XY(6, read_mem(_IX+o)); break; case bit6_l: BIT_XY(6, read_mem(_IX+o)); break; case bit6_mhl: BIT_XY(6, read_mem(_IX+o)); break; case bit7_a: BIT_XY(7, read_mem(_IX+o)); break; case bit7_b: BIT_XY(7, read_mem(_IX+o)); break; case bit7_c: BIT_XY(7, read_mem(_IX+o)); break; case bit7_d: BIT_XY(7, read_mem(_IX+o)); break; case bit7_e: BIT_XY(7, read_mem(_IX+o)); break; case bit7_h: BIT_XY(7, read_mem(_IX+o)); break; case bit7_l: BIT_XY(7, read_mem(_IX+o)); break; case bit7_mhl: BIT_XY(7, read_mem(_IX+o)); break; case res0_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(0, _A)); break; case res0_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(0, _B)); break; case res0_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(0, _C)); break; case res0_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(0, _D)); break; case res0_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(0, _E)); break; case res0_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(0, _H)); break; case res0_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(0, _L)); break; case res0_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(0, b)); } break; case res1_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(1, _A)); break; case res1_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(1, _B)); break; case res1_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(1, _C)); break; case res1_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(1, _D)); break; case res1_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(1, _E)); break; case res1_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(1, _H)); break; case res1_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(1, _L)); break; case res1_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(1, b)); } break; case res2_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(2, _A)); break; case res2_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(2, _B)); break; case res2_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(2, _C)); break; case res2_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(2, _D)); break; case res2_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(2, _E)); break; case res2_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(2, _H)); break; case res2_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(2, _L)); break; case res2_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(2, b)); } break; case res3_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(3, _A)); break; case res3_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(3, _B)); break; case res3_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(3, _C)); break; case res3_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(3, _D)); break; case res3_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(3, _E)); break; case res3_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(3, _H)); break; case res3_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(3, _L)); break; case res3_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(3, b)); } break; case res4_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(4, _A)); break; case res4_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(4, _B)); break; case res4_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(4, _C)); break; case res4_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(4, _D)); break; case res4_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(4, _E)); break; case res4_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(4, _H)); break; case res4_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(4, _L)); break; case res4_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(4, b)); } break; case res5_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(5, _A)); break; case res5_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(5, _B)); break; case res5_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(5, _C)); break; case res5_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(5, _D)); break; case res5_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(5, _E)); break; case res5_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(5, _H)); break; case res5_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(5, _L)); break; case res5_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(5, b)); } break; case res6_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(6, _A)); break; case res6_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(6, _B)); break; case res6_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(6, _C)); break; case res6_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(6, _D)); break; case res6_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(6, _E)); break; case res6_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(6, _H)); break; case res6_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(6, _L)); break; case res6_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(6, b)); } break; case res7_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = RES(7, _A)); break; case res7_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = RES(7, _B)); break; case res7_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = RES(7, _C)); break; case res7_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = RES(7, _D)); break; case res7_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = RES(7, _E)); break; case res7_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = RES(7, _H)); break; case res7_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = RES(7, _L)); break; case res7_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RES(7, b)); } break; case rlc_a: _A = read_mem(_IX+o); _A = RLC(_A); write_mem(_IX+o, _A); break; case rlc_b: _B = read_mem(_IX+o); _B = RLC(_B); write_mem(_IX+o, _B); break; case rlc_c: _C = read_mem(_IX+o); _C = RLC(_C); write_mem(_IX+o, _C); break; case rlc_d: _D = read_mem(_IX+o); _D = RLC(_D); write_mem(_IX+o, _D); break; case rlc_e: _E = read_mem(_IX+o); _E = RLC(_E); write_mem(_IX+o, _E); break; case rlc_h: _H = read_mem(_IX+o); _H = RLC(_H); write_mem(_IX+o, _H); break; case rlc_l: _L = read_mem(_IX+o); _L = RLC(_L); write_mem(_IX+o, _L); break; case rlc_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RLC(b)); } break; case rl_a: _A = read_mem(_IX+o); _A = RL(_A); write_mem(_IX+o, _A); break; case rl_b: _B = read_mem(_IX+o); _B = RL(_B); write_mem(_IX+o, _B); break; case rl_c: _C = read_mem(_IX+o); _C = RL(_C); write_mem(_IX+o, _C); break; case rl_d: _D = read_mem(_IX+o); _D = RL(_D); write_mem(_IX+o, _D); break; case rl_e: _E = read_mem(_IX+o); _E = RL(_E); write_mem(_IX+o, _E); break; case rl_h: _H = read_mem(_IX+o); _H = RL(_H); write_mem(_IX+o, _H); break; case rl_l: _L = read_mem(_IX+o); _L = RL(_L); write_mem(_IX+o, _L); break; case rl_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RL(b)); } break; case rrc_a: _A = read_mem(_IX+o); _A = RRC(_A); write_mem(_IX+o, _A); break; case rrc_b: _B = read_mem(_IX+o); _B = RRC(_B); write_mem(_IX+o, _B); break; case rrc_c: _C = read_mem(_IX+o); _C = RRC(_C); write_mem(_IX+o, _C); break; case rrc_d: _D = read_mem(_IX+o); _D = RRC(_D); write_mem(_IX+o, _D); break; case rrc_e: _E = read_mem(_IX+o); _E = RRC(_E); write_mem(_IX+o, _E); break; case rrc_h: _H = read_mem(_IX+o); _H = RRC(_H); write_mem(_IX+o, _H); break; case rrc_l: _L = read_mem(_IX+o); _L = RRC(_L); write_mem(_IX+o, _L); break; case rrc_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RRC(b)); } break; case rr_a: _A = read_mem(_IX+o); _A = RR(_A); write_mem(_IX+o, _A); break; case rr_b: _B = read_mem(_IX+o); _B = RR(_B); write_mem(_IX+o, _B); break; case rr_c: _C = read_mem(_IX+o); _C = RR(_C); write_mem(_IX+o, _C); break; case rr_d: _D = read_mem(_IX+o); _D = RR(_D); write_mem(_IX+o, _D); break; case rr_e: _E = read_mem(_IX+o); _E = RR(_E); write_mem(_IX+o, _E); break; case rr_h: _H = read_mem(_IX+o); _H = RR(_H); write_mem(_IX+o, _H); break; case rr_l: _L = read_mem(_IX+o); _L = RR(_L); write_mem(_IX+o, _L); break; case rr_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, RR(b)); } break; case set0_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(0, _A)); break; case set0_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(0, _B)); break; case set0_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(0, _C)); break; case set0_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(0, _D)); break; case set0_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(0, _E)); break; case set0_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(0, _H)); break; case set0_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(0, _L)); break; case set0_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(0, b)); } break; case set1_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(1, _A)); break; case set1_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(1, _B)); break; case set1_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(1, _C)); break; case set1_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(1, _D)); break; case set1_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(1, _E)); break; case set1_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(1, _H)); break; case set1_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(1, _L)); break; case set1_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(1, b)); } break; case set2_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(2, _A)); break; case set2_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(2, _B)); break; case set2_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(2, _C)); break; case set2_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(2, _D)); break; case set2_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(2, _E)); break; case set2_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(2, _H)); break; case set2_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(2, _L)); break; case set2_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(2, b)); } break; case set3_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(3, _A)); break; case set3_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(3, _B)); break; case set3_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(3, _C)); break; case set3_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(3, _D)); break; case set3_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(3, _E)); break; case set3_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(3, _H)); break; case set3_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(3, _L)); break; case set3_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(3, b)); } break; case set4_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(4, _A)); break; case set4_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(4, _B)); break; case set4_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(4, _C)); break; case set4_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(4, _D)); break; case set4_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(4, _E)); break; case set4_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(4, _H)); break; case set4_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(4, _L)); break; case set4_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(4, b)); } break; case set5_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(5, _A)); break; case set5_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(5, _B)); break; case set5_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(5, _C)); break; case set5_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(5, _D)); break; case set5_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(5, _E)); break; case set5_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(5, _H)); break; case set5_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(5, _L)); break; case set5_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(5, b)); } break; case set6_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(6, _A)); break; case set6_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(6, _B)); break; case set6_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(6, _C)); break; case set6_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(6, _D)); break; case set6_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(6, _E)); break; case set6_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(6, _H)); break; case set6_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(6, _L)); break; case set6_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(6, b)); } break; case set7_a: _A = read_mem(_IX+o); write_mem(_IX+o, _A = SET(7, _A)); break; case set7_b: _B = read_mem(_IX+o); write_mem(_IX+o, _B = SET(7, _B)); break; case set7_c: _C = read_mem(_IX+o); write_mem(_IX+o, _C = SET(7, _C)); break; case set7_d: _D = read_mem(_IX+o); write_mem(_IX+o, _D = SET(7, _D)); break; case set7_e: _E = read_mem(_IX+o); write_mem(_IX+o, _E = SET(7, _E)); break; case set7_h: _H = read_mem(_IX+o); write_mem(_IX+o, _H = SET(7, _H)); break; case set7_l: _L = read_mem(_IX+o); write_mem(_IX+o, _L = SET(7, _L)); break; case set7_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SET(7, b)); } break; case sla_a: _A = read_mem(_IX+o); _A = SLA(_A); write_mem(_IX+o, _A); break; case sla_b: _B = read_mem(_IX+o); _B = SLA(_B); write_mem(_IX+o, _B); break; case sla_c: _C = read_mem(_IX+o); _C = SLA(_C); write_mem(_IX+o, _C); break; case sla_d: _D = read_mem(_IX+o); _D = SLA(_D); write_mem(_IX+o, _D); break; case sla_e: _E = read_mem(_IX+o); _E = SLA(_E); write_mem(_IX+o, _E); break; case sla_h: _H = read_mem(_IX+o); _H = SLA(_H); write_mem(_IX+o, _H); break; case sla_l: _L = read_mem(_IX+o); _L = SLA(_L); write_mem(_IX+o, _L); break; case sla_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SLA(b)); } break; case sll_a: _A = read_mem(_IX+o); _A = SLL(_A); write_mem(_IX+o, _A); break; case sll_b: _B = read_mem(_IX+o); _B = SLL(_B); write_mem(_IX+o, _B); break; case sll_c: _C = read_mem(_IX+o); _C = SLL(_C); write_mem(_IX+o, _C); break; case sll_d: _D = read_mem(_IX+o); _D = SLL(_D); write_mem(_IX+o, _D); break; case sll_e: _E = read_mem(_IX+o); _E = SLL(_E); write_mem(_IX+o, _E); break; case sll_h: _H = read_mem(_IX+o); _H = SLL(_H); write_mem(_IX+o, _H); break; case sll_l: _L = read_mem(_IX+o); _L = SLL(_L); write_mem(_IX+o, _L); break; case sll_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SLL(b)); } break; case sra_a: _A = read_mem(_IX+o); _A = SRA(_A); write_mem(_IX+o, _A); break; case sra_b: _B = read_mem(_IX+o); _B = SRA(_B); write_mem(_IX+o, _B); break; case sra_c: _C = read_mem(_IX+o); _C = SRA(_C); write_mem(_IX+o, _C); break; case sra_d: _D = read_mem(_IX+o); _D = SRA(_D); write_mem(_IX+o, _D); break; case sra_e: _E = read_mem(_IX+o); _E = SRA(_E); write_mem(_IX+o, _E); break; case sra_h: _H = read_mem(_IX+o); _H = SRA(_H); write_mem(_IX+o, _H); break; case sra_l: _L = read_mem(_IX+o); _L = SRA(_L); write_mem(_IX+o, _L); break; case sra_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SRA(b)); } break; case srl_a: _A = read_mem(_IX+o); _A = SRL(_A); write_mem(_IX+o, _A); break; case srl_b: _B = read_mem(_IX+o); _B = SRL(_B); write_mem(_IX+o, _B); break; case srl_c: _C = read_mem(_IX+o); _C = SRL(_C); write_mem(_IX+o, _C); break; case srl_d: _D = read_mem(_IX+o); _D = SRL(_D); write_mem(_IX+o, _D); break; case srl_e: _E = read_mem(_IX+o); _E = SRL(_E); write_mem(_IX+o, _E); break; case srl_h: _H = read_mem(_IX+o); _H = SRL(_H); write_mem(_IX+o, _H); break; case srl_l: _L = read_mem(_IX+o); _L = SRL(_L); write_mem(_IX+o, _L); break; case srl_mhl: { byte b = read_mem(_IX+o); write_mem(_IX+o, SRL(b)); } break; } } void z80_execute_pfx_ed_instruction() { byte bOpCode; bOpCode = read_mem(_PC++); iCycleCount += cc_ed[bOpCode]; _R++; switch(bOpCode) { case adc_hl_bc: ADC16(BC); break; case adc_hl_de: ADC16(DE); break; case adc_hl_hl: ADC16(HL); break; case adc_hl_sp: ADC16(SP); break; case cpd: CPD; break; case cpdr: CPDR; break; case cpi: CPI; break; case cpir: CPIR; break; case ed_00: break; case ed_01: break; case ed_02: break; case ed_03: break; case ed_04: break; case ed_05: break; case ed_06: break; case ed_07: break; case ed_08: break; case ed_09: break; case ed_0a: break; case ed_0b: break; case ed_0c: break; case ed_0d: break; case ed_0e: break; case ed_0f: break; case ed_10: break; case ed_11: break; case ed_12: break; case ed_13: break; case ed_14: break; case ed_15: break; case ed_16: break; case ed_17: break; case ed_18: break; case ed_19: break; case ed_1a: break; case ed_1b: break; case ed_1c: break; case ed_1d: break; case ed_1e: break; case ed_1f: break; case ed_20: break; case ed_21: break; case ed_22: break; case ed_23: break; case ed_24: break; case ed_25: break; case ed_26: break; case ed_27: break; case ed_28: break; case ed_29: break; case ed_2a: break; case ed_2b: break; case ed_2c: break; case ed_2d: break; case ed_2e: break; case ed_2f: break; case ed_30: break; case ed_31: break; case ed_32: break; case ed_33: break; case ed_34: break; case ed_35: break; case ed_36: break; case ed_37: break; case ed_38: break; case ed_39: break; case ed_3a: break; case ed_3b: break; case ed_3c: break; case ed_3d: break; case ed_3e: break; case ed_3f: break; case ed_77: break; case ed_7f: break; case ed_80: break; case ed_81: break; case ed_82: break; case ed_83: break; case ed_84: break; case ed_85: break; case ed_86: break; case ed_87: break; case ed_88: break; case ed_89: break; case ed_8a: break; case ed_8b: break; case ed_8c: break; case ed_8d: break; case ed_8e: break; case ed_8f: break; case ed_90: break; case ed_91: break; case ed_92: break; case ed_93: break; case ed_94: break; case ed_95: break; case ed_96: break; case ed_97: break; case ed_98: break; case ed_99: break; case ed_9a: break; case ed_9b: break; case ed_9c: break; case ed_9d: break; case ed_9e: break; case ed_9f: break; case ed_a4: break; case ed_a5: break; case ed_a6: break; case ed_a7: break; case ed_ac: break; case ed_ad: break; case ed_ae: break; case ed_af: break; case ed_b4: break; case ed_b5: break; case ed_b6: break; case ed_b7: break; case ed_bc: break; case ed_bd: break; case ed_be: break; case ed_bf: break; case ed_c0: break; case ed_c1: break; case ed_c2: break; case ed_c3: break; case ed_c4: break; case ed_c5: break; case ed_c6: break; case ed_c7: break; case ed_c8: break; case ed_c9: break; case ed_ca: break; case ed_cb: break; case ed_cc: break; case ed_cd: break; case ed_ce: break; case ed_cf: break; case ed_d0: break; case ed_d1: break; case ed_d2: break; case ed_d3: break; case ed_d4: break; case ed_d5: break; case ed_d6: break; case ed_d7: break; case ed_d8: break; case ed_d9: break; case ed_da: break; case ed_db: break; case ed_dc: break; case ed_dd: break; case ed_de: break; case ed_df: break; case ed_e0: break; case ed_e1: break; case ed_e2: break; case ed_e3: break; case ed_e4: break; case ed_e5: break; case ed_e6: break; case ed_e7: break; case ed_e8: break; case ed_e9: break; case ed_ea: break; case ed_eb: break; case ed_ec: break; case ed_ed: break; case ed_ee: break; case ed_ef: break; case ed_f0: break; case ed_f1: break; case ed_f2: break; case ed_f3: break; case ed_f4: break; case ed_f5: break; case ed_f6: break; case ed_f7: break; case ed_f8: break; case ed_f9: break; case ed_fa: break; case ed_fb: break; case ed_fc: break; case ed_fd: break; case ed_fe: break; case ed_ff: break; case im_0: _IM = 0; break; case im_0_1: _IM = 0; break; case im_0_2: _IM = 0; break; case im_0_3: _IM = 0; break; case im_1: _IM = 1; break; case im_1_1: _IM = 1; break; case im_2: _IM = 2; break; case im_2_1: _IM = 2; break; case ind: { z80_wait_states iCycleCount = Iy_;} IND; break; case indr: { z80_wait_states iCycleCount = Iy_;} INDR; break; case ini: { z80_wait_states iCycleCount = Iy_;} INI; break; case inir: { z80_wait_states iCycleCount = Iy_;} INIR; break; case in_0_c: { z80_wait_states iCycleCount = Ix_;} { byte res = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[res]; } break; case in_a_c: { z80_wait_states iCycleCount = Ix_;} _A = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_A]; break; case in_b_c: { z80_wait_states iCycleCount = Ix_;} _B = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_B]; break; case in_c_c: { z80_wait_states iCycleCount = Ix_;} _C = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_C]; break; case in_d_c: { z80_wait_states iCycleCount = Ix_;} _D = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_D]; break; case in_e_c: { z80_wait_states iCycleCount = Ix_;} _E = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_E]; break; case in_h_c: { z80_wait_states iCycleCount = Ix_;} _H = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_H]; break; case in_l_c: { z80_wait_states iCycleCount = Ix_;} _L = z80_IN_handler(z80.BC); _F = (_F & Cflag) | SZP[_L]; break; case ldd: LDD; iWSAdjust++; break; case lddr: LDDR; iWSAdjust++; break; case ldi: LDI; iWSAdjust++; break; case ldir: LDIR; iWSAdjust++; break; case ld_a_i: _A = _I; _F = (_F & Cflag) | SZ[_A] | _IFF2; iWSAdjust++; break; case ld_a_r: _A = (_R & 0x7f) | _Rb7; _F = (_F & Cflag) | SZ[_A] | _IFF2; iWSAdjust++; break; case ld_EDbc_mword: LD16_MEM(BC); break; case ld_EDde_mword: LD16_MEM(DE); break; case ld_EDhl_mword: LD16_MEM(HL); break; case ld_EDmword_bc: LDMEM_16(BC); break; case ld_EDmword_de: LDMEM_16(DE); break; case ld_EDmword_hl: LDMEM_16(HL); break; case ld_EDmword_sp: LDMEM_16(SP); break; case ld_EDsp_mword: LD16_MEM(SP); break; case ld_i_a: _I = _A; iWSAdjust++; break; case ld_r_a: _R = _A; _Rb7 = _A & 0x80; iWSAdjust++; break; case neg: NEG; break; case neg_1: NEG; break; case neg_2: NEG; break; case neg_3: NEG; break; case neg_4: NEG; break; case neg_5: NEG; break; case neg_6: NEG; break; case neg_7: NEG; break; case otdr: { z80_wait_states iCycleCount = Oy_;} OTDR; break; case otir: { z80_wait_states iCycleCount = Oy_;} OTIR; break; case outd: { z80_wait_states iCycleCount = Oy_;} OUTD; break; case outi: { z80_wait_states iCycleCount = Oy_;} OUTI; break; case out_c_0: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, 0); break; case out_c_a: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _A); break; case out_c_b: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _B); break; case out_c_c: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _C); break; case out_c_d: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _D); break; case out_c_e: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _E); break; case out_c_h: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _H); break; case out_c_l: { z80_wait_states iCycleCount = Ox_;} z80_OUT_handler(z80.BC, _L); break; case reti: _IFF1 = _IFF2; RET; break; case reti_1: _IFF1 = _IFF2; RET; break; case reti_2: _IFF1 = _IFF2; RET; break; case reti_3: _IFF1 = _IFF2; RET; break; case retn: _IFF1 = _IFF2; RET; break; case retn_1: _IFF1 = _IFF2; RET; break; case retn_2: _IFF1 = _IFF2; RET; break; case retn_3: _IFF1 = _IFF2; RET; break; case rld: RLD; break; case rrd: RRD; break; case sbc_hl_bc: SBC16(BC); break; case sbc_hl_de: SBC16(DE); break; case sbc_hl_hl: SBC16(HL); break; case sbc_hl_sp: SBC16(SP); break; } } void z80_execute_pfx_fd_instruction() { byte bOpCode; bOpCode = read_mem(_PC++); iCycleCount += cc_xy[bOpCode]; _R++; switch(bOpCode) { case adc_a: ADC(_A); break; case adc_b: ADC(_B); break; case adc_byte: ADC(read_mem(_PC++)); break; case adc_c: ADC(_C); break; case adc_d: ADC(_D); break; case adc_e: ADC(_E); break; case adc_h: ADC(_IYh); break; case adc_l: ADC(_IYl); break; case adc_mhl: { signed char o = read_mem(_PC++); ADC(read_mem(_IY+o)); } break; case add_a: ADD(_A); break; case add_b: ADD(_B); break; case add_byte: ADD(read_mem(_PC++)); break; case add_c: ADD(_C); break; case add_d: ADD(_D); break; case add_e: ADD(_E); break; case add_h: ADD(_IYh); break; case add_hl_bc: ADD16(IY, BC); break; case add_hl_de: ADD16(IY, DE); break; case add_hl_hl: ADD16(IY, IY); break; case add_hl_sp: ADD16(IY, SP); break; case add_l: ADD(_IYl); break; case add_mhl: { signed char o = read_mem(_PC++); ADD(read_mem(_IY+o)); } break; case and_a: AND(_A); break; case and_b: AND(_B); break; case and_byte: AND(read_mem(_PC++)); break; case and_c: AND(_C); break; case and_d: AND(_D); break; case and_e: AND(_E); break; case and_h: AND(_IYh); break; case and_l: AND(_IYl); break; case and_mhl: { signed char o = read_mem(_PC++); AND(read_mem(_IY+o)); } break; case call: CALL; break; case call_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case call_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; CALL } else { _PC += 2; } break; case ccf: _F = ((_F & (Sflag | Zflag | Pflag | Cflag)) | ((_F & CF) << 4) | (_A & Xflags)) ^ CF; break; case cpl: _A ^= 0xff; _F = (_F & (Sflag | Zflag | Pflag | Cflag)) | Hflag | Nflag | (_A & Xflags); break; case cp_a: CP(_A); break; case cp_b: CP(_B); break; case cp_byte: CP(read_mem(_PC++)); break; case cp_c: CP(_C); break; case cp_d: CP(_D); break; case cp_e: CP(_E); break; case cp_h: CP(_IYh); break; case cp_l: CP(_IYl); break; case cp_mhl: { signed char o = read_mem(_PC++); CP(read_mem(_IY+o)); } break; case daa: DAA; break; case dec_a: DEC(_A); break; case dec_b: DEC(_B); break; case dec_bc: _BC--; iWSAdjust++; break; case dec_c: DEC(_C); break; case dec_d: DEC(_D); break; case dec_de: _DE--; iWSAdjust++; break; case dec_e: DEC(_E); break; case dec_h: DEC(_IYh); break; case dec_hl: _IY--; iWSAdjust++; break; case dec_l: DEC(_IYl); break; case dec_mhl: { signed char o = read_mem(_PC++); byte b = read_mem(_IY+o); DEC(b); write_mem(_IY+o, b); } break; case dec_sp: _SP--; iWSAdjust++; break; case di: _IFF1 = _IFF2 = 0; z80.EI_issued = 0; break; case djnz: if (--_B) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; } break; case ei: z80.EI_issued = 2; break; case exx: EXX; break; case ex_af_af: EX(z80.AF, z80.AFx); break; case ex_de_hl: EX(z80.DE, z80.HL); break; case ex_msp_hl: EX_SP(IY); iWSAdjust++; break; case halt: _HALT = 1; _PC--; break; case ina: { z80_wait_states iCycleCount = Ia_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; _A = z80_IN_handler(p); } break; case inc_a: INC(_A); break; case inc_b: INC(_B); break; case inc_bc: _BC++; iWSAdjust++; break; case inc_c: INC(_C); break; case inc_d: INC(_D); break; case inc_de: _DE++; iWSAdjust++; break; case inc_e: INC(_E); break; case inc_h: INC(_IYh); break; case inc_hl: _IY++; iWSAdjust++; break; case inc_l: INC(_IYl); break; case inc_mhl: { signed char o = read_mem(_PC++); byte b = read_mem(_IY+o); INC(b); write_mem(_IY+o, b); } break; case inc_sp: _SP++; iWSAdjust++; break; case jp: JP; break; case jp_c: if (_F & Cflag) { JP } else { _PC += 2; }; break; case jp_m: if (_F & Sflag) { JP } else { _PC += 2; }; break; case jp_nc: if (!(_F & Cflag)) { JP } else { _PC += 2; }; break; case jp_nz: if (!(_F & Zflag)) { JP } else { _PC += 2; }; break; case jp_p: if (!(_F & Sflag)) { JP } else { _PC += 2; }; break; case jp_pe: if (_F & Pflag) { JP } else { _PC += 2; }; break; case jp_po: if (!(_F & Pflag)) { JP } else { _PC += 2; }; break; case jp_z: if (_F & Zflag) { JP } else { _PC += 2; }; break; case jr: JR; break; case jr_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case jr_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; JR } else { _PC++; }; break; case ld_a_a: break; case ld_a_b: _A = _B; break; case ld_a_byte: _A = read_mem(_PC++); break; case ld_a_c: _A = _C; break; case ld_a_d: _A = _D; break; case ld_a_e: _A = _E; break; case ld_a_h: _A = _IYh; break; case ld_a_l: _A = _IYl; break; case ld_a_mbc: _A = read_mem(_BC); break; case ld_a_mde: _A = read_mem(_DE); break; case ld_a_mhl: { signed char o = read_mem(_PC++); _A = read_mem(_IY+o); } break; case ld_a_mword: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); _A = read_mem(addr.w.l); } break; case ld_bc_word: z80.BC.b.l = read_mem(_PC++); z80.BC.b.h = read_mem(_PC++); break; case ld_b_a: _B = _A; break; case ld_b_b: break; case ld_b_byte: _B = read_mem(_PC++); break; case ld_b_c: _B = _C; break; case ld_b_d: _B = _D; break; case ld_b_e: _B = _E; break; case ld_b_h: _B = _IYh; break; case ld_b_l: _B = _IYl; break; case ld_b_mhl: { signed char o = read_mem(_PC++); _B = read_mem(_IY+o); } break; case ld_c_a: _C = _A; break; case ld_c_b: _C = _B; break; case ld_c_byte: _C = read_mem(_PC++); break; case ld_c_c: break; case ld_c_d: _C = _D; break; case ld_c_e: _C = _E; break; case ld_c_h: _C = _IYh; break; case ld_c_l: _C = _IYl; break; case ld_c_mhl: { signed char o = read_mem(_PC++); _C = read_mem(_IY+o); } break; case ld_de_word: z80.DE.b.l = read_mem(_PC++); z80.DE.b.h = read_mem(_PC++); break; case ld_d_a: _D = _A; break; case ld_d_b: _D = _B; break; case ld_d_byte: _D = read_mem(_PC++); break; case ld_d_c: _D = _C; break; case ld_d_d: break; case ld_d_e: _D = _E; break; case ld_d_h: _D = _IYh; break; case ld_d_l: _D = _IYl; break; case ld_d_mhl: { signed char o = read_mem(_PC++); _D = read_mem(_IY+o); } break; case ld_e_a: _E = _A; break; case ld_e_b: _E = _B; break; case ld_e_byte: _E = read_mem(_PC++); break; case ld_e_c: _E = _C; break; case ld_e_d: _E = _D; break; case ld_e_e: break; case ld_e_h: _E = _IYh; break; case ld_e_l: _E = _IYl; break; case ld_e_mhl: { signed char o = read_mem(_PC++); _E = read_mem(_IY+o); } break; case ld_hl_mword: LD16_MEM(IY); break; case ld_hl_word: z80.IY.b.l = read_mem(_PC++); z80.IY.b.h = read_mem(_PC++); break; case ld_h_a: _IYh = _A; break; case ld_h_b: _IYh = _B; break; case ld_h_byte: _IYh = read_mem(_PC++); break; case ld_h_c: _IYh = _C; break; case ld_h_d: _IYh = _D; break; case ld_h_e: _IYh = _E; break; case ld_h_h: break; case ld_h_l: _IYh = _IYl; break; case ld_h_mhl: { signed char o = read_mem(_PC++); _H = read_mem(_IY+o); } break; case ld_l_a: _IYl = _A; break; case ld_l_b: _IYl = _B; break; case ld_l_byte: _IYl = read_mem(_PC++); break; case ld_l_c: _IYl = _C; break; case ld_l_d: _IYl = _D; break; case ld_l_e: _IYl = _E; break; case ld_l_h: _IYl = _IYh; break; case ld_l_l: break; case ld_l_mhl: { signed char o = read_mem(_PC++); _L = read_mem(_IY+o); } break; case ld_mbc_a: write_mem(_BC, _A); break; case ld_mde_a: write_mem(_DE, _A); break; case ld_mhl_a: { signed char o = read_mem(_PC++); write_mem(_IY+o, _A); } break; case ld_mhl_b: { signed char o = read_mem(_PC++); write_mem(_IY+o, _B); } break; case ld_mhl_byte: { signed char o = read_mem(_PC++); byte b = read_mem(_PC++); write_mem(_IY+o, b); } break; case ld_mhl_c: { signed char o = read_mem(_PC++); write_mem(_IY+o, _C); } break; case ld_mhl_d: { signed char o = read_mem(_PC++); write_mem(_IY+o, _D); } break; case ld_mhl_e: { signed char o = read_mem(_PC++); write_mem(_IY+o, _E); } break; case ld_mhl_h: { signed char o = read_mem(_PC++); write_mem(_IY+o, _H); } break; case ld_mhl_l: { signed char o = read_mem(_PC++); write_mem(_IY+o, _L); } break; case ld_mword_a: { reg_pair addr; addr.b.l = read_mem(_PC++); addr.b.h = read_mem(_PC++); write_mem(addr.w.l, _A); } break; case ld_mword_hl: LDMEM_16(IY); break; case ld_pc_hl: _PC = _IY; break; case ld_sp_hl: _SP = _IY; iWSAdjust++; break; case ld_sp_word: z80.SP.b.l = read_mem(_PC++); z80.SP.b.h = read_mem(_PC++); break; case nop: break; case or_a: OR(_A); break; case or_b: OR(_B); break; case or_byte: OR(read_mem(_PC++)); break; case or_c: OR(_C); break; case or_d: OR(_D); break; case or_e: OR(_E); break; case or_h: OR(_IYh); break; case or_l: OR(_IYl); break; case or_mhl: { signed char o = read_mem(_PC++); OR(read_mem(_IY+o)); } break; case outa: { z80_wait_states iCycleCount = Oa_;} { reg_pair p; p.b.l = read_mem(_PC++); p.b.h = _A; z80_OUT_handler(p, _A); } break; case pfx_cb: z80_execute_pfx_fdcb_instruction(); break; case pfx_dd: z80_execute_pfx_dd_instruction(); break; case pfx_ed: z80_execute_pfx_ed_instruction(); break; case pfx_fd: z80_execute_pfx_fd_instruction(); break; case pop_af: POP(AF); break; case pop_bc: POP(BC); break; case pop_de: POP(DE); break; case pop_hl: POP(IY); break; case push_af: PUSH(AF); break; case push_bc: PUSH(BC); break; case push_de: PUSH(DE); break; case push_hl: PUSH(IY); break; case ret: RET; break; case ret_c: if (_F & Cflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_m: if (_F & Sflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nc: if (!(_F & Cflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_nz: if (!(_F & Zflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_p: if (!(_F & Sflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_pe: if (_F & Pflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_po: if (!(_F & Pflag)) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case ret_z: if (_F & Zflag) { iCycleCount += cc_ex[bOpCode]; RET } else { iWSAdjust++; } ; break; case rla: RLA; break; case rlca: RLCA; break; case rra: RRA; break; case rrca: RRCA; break; case rst00: RST(0x0000); break; case rst08: RST(0x0008); break; case rst10: RST(0x0010); break; case rst18: RST(0x0018); break; case rst20: RST(0x0020); break; case rst28: RST(0x0028); break; case rst30: RST(0x0030); break; case rst38: RST(0x0038); break; case sbc_a: SBC(_A); break; case sbc_b: SBC(_B); break; case sbc_byte: SBC(read_mem(_PC++)); break; case sbc_c: SBC(_C); break; case sbc_d: SBC(_D); break; case sbc_e: SBC(_E); break; case sbc_h: SBC(_IYh); break; case sbc_l: SBC(_IYl); break; case sbc_mhl: { signed char o = read_mem(_PC++); SBC(read_mem(_IY+o)); } break; case scf: _F = (_F & (Sflag | Zflag | Pflag)) | Cflag | (_A & Xflags); break; case sub_a: SUB(_A); break; case sub_b: SUB(_B); break; case sub_byte: SUB(read_mem(_PC++)); break; case sub_c: SUB(_C); break; case sub_d: SUB(_D); break; case sub_e: SUB(_E); break; case sub_h: SUB(_IYh); break; case sub_l: SUB(_IYl); break; case sub_mhl: { signed char o = read_mem(_PC++); SUB(read_mem(_IY+o)); } break; case xor_a: XOR(_A); break; case xor_b: XOR(_B); break; case xor_byte: XOR(read_mem(_PC++)); break; case xor_c: XOR(_C); break; case xor_d: XOR(_D); break; case xor_e: XOR(_E); break; case xor_h: XOR(_IYh); break; case xor_l: XOR(_IYl); break; case xor_mhl: { signed char o = read_mem(_PC++); XOR(read_mem(_IY+o)); } break; } } void z80_execute_pfx_fdcb_instruction() { signed char o; byte bOpCode; o = read_mem(_PC++); // offset bOpCode = read_mem(_PC++); iCycleCount += cc_xycb[bOpCode]; switch(bOpCode) { case bit0_a: BIT_XY(0, read_mem(_IY+o)); break; case bit0_b: BIT_XY(0, read_mem(_IY+o)); break; case bit0_c: BIT_XY(0, read_mem(_IY+o)); break; case bit0_d: BIT_XY(0, read_mem(_IY+o)); break; case bit0_e: BIT_XY(0, read_mem(_IY+o)); break; case bit0_h: BIT_XY(0, read_mem(_IY+o)); break; case bit0_l: BIT_XY(0, read_mem(_IY+o)); break; case bit0_mhl: BIT_XY(0, read_mem(_IY+o)); break; case bit1_a: BIT_XY(1, read_mem(_IY+o)); break; case bit1_b: BIT_XY(1, read_mem(_IY+o)); break; case bit1_c: BIT_XY(1, read_mem(_IY+o)); break; case bit1_d: BIT_XY(1, read_mem(_IY+o)); break; case bit1_e: BIT_XY(1, read_mem(_IY+o)); break; case bit1_h: BIT_XY(1, read_mem(_IY+o)); break; case bit1_l: BIT_XY(1, read_mem(_IY+o)); break; case bit1_mhl: BIT_XY(1, read_mem(_IY+o)); break; case bit2_a: BIT_XY(2, read_mem(_IY+o)); break; case bit2_b: BIT_XY(2, read_mem(_IY+o)); break; case bit2_c: BIT_XY(2, read_mem(_IY+o)); break; case bit2_d: BIT_XY(2, read_mem(_IY+o)); break; case bit2_e: BIT_XY(2, read_mem(_IY+o)); break; case bit2_h: BIT_XY(2, read_mem(_IY+o)); break; case bit2_l: BIT_XY(2, read_mem(_IY+o)); break; case bit2_mhl: BIT_XY(2, read_mem(_IY+o)); break; case bit3_a: BIT_XY(3, read_mem(_IY+o)); break; case bit3_b: BIT_XY(3, read_mem(_IY+o)); break; case bit3_c: BIT_XY(3, read_mem(_IY+o)); break; case bit3_d: BIT_XY(3, read_mem(_IY+o)); break; case bit3_e: BIT_XY(3, read_mem(_IY+o)); break; case bit3_h: BIT_XY(3, read_mem(_IY+o)); break; case bit3_l: BIT_XY(3, read_mem(_IY+o)); break; case bit3_mhl: BIT_XY(3, read_mem(_IY+o)); break; case bit4_a: BIT_XY(4, read_mem(_IY+o)); break; case bit4_b: BIT_XY(4, read_mem(_IY+o)); break; case bit4_c: BIT_XY(4, read_mem(_IY+o)); break; case bit4_d: BIT_XY(4, read_mem(_IY+o)); break; case bit4_e: BIT_XY(4, read_mem(_IY+o)); break; case bit4_h: BIT_XY(4, read_mem(_IY+o)); break; case bit4_l: BIT_XY(4, read_mem(_IY+o)); break; case bit4_mhl: BIT_XY(4, read_mem(_IY+o)); break; case bit5_a: BIT_XY(5, read_mem(_IY+o)); break; case bit5_b: BIT_XY(5, read_mem(_IY+o)); break; case bit5_c: BIT_XY(5, read_mem(_IY+o)); break; case bit5_d: BIT_XY(5, read_mem(_IY+o)); break; case bit5_e: BIT_XY(5, read_mem(_IY+o)); break; case bit5_h: BIT_XY(5, read_mem(_IY+o)); break; case bit5_l: BIT_XY(5, read_mem(_IY+o)); break; case bit5_mhl: BIT_XY(5, read_mem(_IY+o)); break; case bit6_a: BIT_XY(6, read_mem(_IY+o)); break; case bit6_b: BIT_XY(6, read_mem(_IY+o)); break; case bit6_c: BIT_XY(6, read_mem(_IY+o)); break; case bit6_d: BIT_XY(6, read_mem(_IY+o)); break; case bit6_e: BIT_XY(6, read_mem(_IY+o)); break; case bit6_h: BIT_XY(6, read_mem(_IY+o)); break; case bit6_l: BIT_XY(6, read_mem(_IY+o)); break; case bit6_mhl: BIT_XY(6, read_mem(_IY+o)); break; case bit7_a: BIT_XY(7, read_mem(_IY+o)); break; case bit7_b: BIT_XY(7, read_mem(_IY+o)); break; case bit7_c: BIT_XY(7, read_mem(_IY+o)); break; case bit7_d: BIT_XY(7, read_mem(_IY+o)); break; case bit7_e: BIT_XY(7, read_mem(_IY+o)); break; case bit7_h: BIT_XY(7, read_mem(_IY+o)); break; case bit7_l: BIT_XY(7, read_mem(_IY+o)); break; case bit7_mhl: BIT_XY(7, read_mem(_IY+o)); break; case res0_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(0, _A)); break; case res0_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(0, _B)); break; case res0_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(0, _C)); break; case res0_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(0, _D)); break; case res0_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(0, _E)); break; case res0_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(0, _H)); break; case res0_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(0, _L)); break; case res0_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(0, b)); } break; case res1_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(1, _A)); break; case res1_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(1, _B)); break; case res1_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(1, _C)); break; case res1_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(1, _D)); break; case res1_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(1, _E)); break; case res1_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(1, _H)); break; case res1_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(1, _L)); break; case res1_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(1, b)); } break; case res2_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(2, _A)); break; case res2_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(2, _B)); break; case res2_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(2, _C)); break; case res2_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(2, _D)); break; case res2_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(2, _E)); break; case res2_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(2, _H)); break; case res2_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(2, _L)); break; case res2_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(2, b)); } break; case res3_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(3, _A)); break; case res3_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(3, _B)); break; case res3_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(3, _C)); break; case res3_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(3, _D)); break; case res3_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(3, _E)); break; case res3_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(3, _H)); break; case res3_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(3, _L)); break; case res3_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(3, b)); } break; case res4_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(4, _A)); break; case res4_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(4, _B)); break; case res4_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(4, _C)); break; case res4_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(4, _D)); break; case res4_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(4, _E)); break; case res4_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(4, _H)); break; case res4_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(4, _L)); break; case res4_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(4, b)); } break; case res5_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(5, _A)); break; case res5_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(5, _B)); break; case res5_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(5, _C)); break; case res5_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(5, _D)); break; case res5_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(5, _E)); break; case res5_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(5, _H)); break; case res5_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(5, _L)); break; case res5_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(5, b)); } break; case res6_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(6, _A)); break; case res6_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(6, _B)); break; case res6_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(6, _C)); break; case res6_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(6, _D)); break; case res6_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(6, _E)); break; case res6_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(6, _H)); break; case res6_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(6, _L)); break; case res6_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(6, b)); } break; case res7_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = RES(7, _A)); break; case res7_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = RES(7, _B)); break; case res7_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = RES(7, _C)); break; case res7_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = RES(7, _D)); break; case res7_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = RES(7, _E)); break; case res7_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = RES(7, _H)); break; case res7_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = RES(7, _L)); break; case res7_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RES(7, b)); } break; case rlc_a: _A = read_mem(_IY+o); _A = RLC(_A); write_mem(_IY+o, _A); break; case rlc_b: _B = read_mem(_IY+o); _B = RLC(_B); write_mem(_IY+o, _B); break; case rlc_c: _C = read_mem(_IY+o); _C = RLC(_C); write_mem(_IY+o, _C); break; case rlc_d: _D = read_mem(_IY+o); _D = RLC(_D); write_mem(_IY+o, _D); break; case rlc_e: _E = read_mem(_IY+o); _E = RLC(_E); write_mem(_IY+o, _E); break; case rlc_h: _H = read_mem(_IY+o); _H = RLC(_H); write_mem(_IY+o, _H); break; case rlc_l: _L = read_mem(_IY+o); _L = RLC(_L); write_mem(_IY+o, _L); break; case rlc_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RLC(b)); } break; case rl_a: _A = read_mem(_IY+o); _A = RL(_A); write_mem(_IY+o, _A); break; case rl_b: _B = read_mem(_IY+o); _B = RL(_B); write_mem(_IY+o, _B); break; case rl_c: _C = read_mem(_IY+o); _C = RL(_C); write_mem(_IY+o, _C); break; case rl_d: _D = read_mem(_IY+o); _D = RL(_D); write_mem(_IY+o, _D); break; case rl_e: _E = read_mem(_IY+o); _E = RL(_E); write_mem(_IY+o, _E); break; case rl_h: _H = read_mem(_IY+o); _H = RL(_H); write_mem(_IY+o, _H); break; case rl_l: _L = read_mem(_IY+o); _L = RL(_L); write_mem(_IY+o, _L); break; case rl_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RL(b)); } break; case rrc_a: _A = read_mem(_IY+o); _A = RRC(_A); write_mem(_IY+o, _A); break; case rrc_b: _B = read_mem(_IY+o); _B = RRC(_B); write_mem(_IY+o, _B); break; case rrc_c: _C = read_mem(_IY+o); _C = RRC(_C); write_mem(_IY+o, _C); break; case rrc_d: _D = read_mem(_IY+o); _D = RRC(_D); write_mem(_IY+o, _D); break; case rrc_e: _E = read_mem(_IY+o); _E = RRC(_E); write_mem(_IY+o, _E); break; case rrc_h: _H = read_mem(_IY+o); _H = RRC(_H); write_mem(_IY+o, _H); break; case rrc_l: _L = read_mem(_IY+o); _L = RRC(_L); write_mem(_IY+o, _L); break; case rrc_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RRC(b)); } break; case rr_a: _A = read_mem(_IY+o); _A = RR(_A); write_mem(_IY+o, _A); break; case rr_b: _B = read_mem(_IY+o); _B = RR(_B); write_mem(_IY+o, _B); break; case rr_c: _C = read_mem(_IY+o); _C = RR(_C); write_mem(_IY+o, _C); break; case rr_d: _D = read_mem(_IY+o); _D = RR(_D); write_mem(_IY+o, _D); break; case rr_e: _E = read_mem(_IY+o); _E = RR(_E); write_mem(_IY+o, _E); break; case rr_h: _H = read_mem(_IY+o); _H = RR(_H); write_mem(_IY+o, _H); break; case rr_l: _L = read_mem(_IY+o); _L = RR(_L); write_mem(_IY+o, _L); break; case rr_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, RR(b)); } break; case set0_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(0, _A)); break; case set0_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(0, _B)); break; case set0_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(0, _C)); break; case set0_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(0, _D)); break; case set0_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(0, _E)); break; case set0_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(0, _H)); break; case set0_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(0, _L)); break; case set0_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(0, b)); } break; case set1_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(1, _A)); break; case set1_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(1, _B)); break; case set1_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(1, _C)); break; case set1_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(1, _D)); break; case set1_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(1, _E)); break; case set1_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(1, _H)); break; case set1_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(1, _L)); break; case set1_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(1, b)); } break; case set2_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(2, _A)); break; case set2_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(2, _B)); break; case set2_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(2, _C)); break; case set2_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(2, _D)); break; case set2_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(2, _E)); break; case set2_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(2, _H)); break; case set2_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(2, _L)); break; case set2_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(2, b)); } break; case set3_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(3, _A)); break; case set3_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(3, _B)); break; case set3_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(3, _C)); break; case set3_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(3, _D)); break; case set3_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(3, _E)); break; case set3_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(3, _H)); break; case set3_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(3, _L)); break; case set3_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(3, b)); } break; case set4_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(4, _A)); break; case set4_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(4, _B)); break; case set4_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(4, _C)); break; case set4_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(4, _D)); break; case set4_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(4, _E)); break; case set4_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(4, _H)); break; case set4_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(4, _L)); break; case set4_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(4, b)); } break; case set5_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(5, _A)); break; case set5_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(5, _B)); break; case set5_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(5, _C)); break; case set5_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(5, _D)); break; case set5_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(5, _E)); break; case set5_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(5, _H)); break; case set5_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(5, _L)); break; case set5_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(5, b)); } break; case set6_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(6, _A)); break; case set6_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(6, _B)); break; case set6_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(6, _C)); break; case set6_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(6, _D)); break; case set6_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(6, _E)); break; case set6_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(6, _H)); break; case set6_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(6, _L)); break; case set6_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(6, b)); } break; case set7_a: _A = read_mem(_IY+o); write_mem(_IY+o, _A = SET(7, _A)); break; case set7_b: _B = read_mem(_IY+o); write_mem(_IY+o, _B = SET(7, _B)); break; case set7_c: _C = read_mem(_IY+o); write_mem(_IY+o, _C = SET(7, _C)); break; case set7_d: _D = read_mem(_IY+o); write_mem(_IY+o, _D = SET(7, _D)); break; case set7_e: _E = read_mem(_IY+o); write_mem(_IY+o, _E = SET(7, _E)); break; case set7_h: _H = read_mem(_IY+o); write_mem(_IY+o, _H = SET(7, _H)); break; case set7_l: _L = read_mem(_IY+o); write_mem(_IY+o, _L = SET(7, _L)); break; case set7_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SET(7, b)); } break; case sla_a: _A = read_mem(_IY+o); _A = SLA(_A); write_mem(_IY+o, _A); break; case sla_b: _B = read_mem(_IY+o); _B = SLA(_B); write_mem(_IY+o, _B); break; case sla_c: _C = read_mem(_IY+o); _C = SLA(_C); write_mem(_IY+o, _C); break; case sla_d: _D = read_mem(_IY+o); _D = SLA(_D); write_mem(_IY+o, _D); break; case sla_e: _E = read_mem(_IY+o); _E = SLA(_E); write_mem(_IY+o, _E); break; case sla_h: _H = read_mem(_IY+o); _H = SLA(_H); write_mem(_IY+o, _H); break; case sla_l: _L = read_mem(_IY+o); _L = SLA(_L); write_mem(_IY+o, _L); break; case sla_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SLA(b)); } break; case sll_a: _A = read_mem(_IY+o); _A = SLL(_A); write_mem(_IY+o, _A); break; case sll_b: _B = read_mem(_IY+o); _B = SLL(_B); write_mem(_IY+o, _B); break; case sll_c: _C = read_mem(_IY+o); _C = SLL(_C); write_mem(_IY+o, _C); break; case sll_d: _D = read_mem(_IY+o); _D = SLL(_D); write_mem(_IY+o, _D); break; case sll_e: _E = read_mem(_IY+o); _E = SLL(_E); write_mem(_IY+o, _E); break; case sll_h: _H = read_mem(_IY+o); _H = SLL(_H); write_mem(_IY+o, _H); break; case sll_l: _L = read_mem(_IY+o); _L = SLL(_L); write_mem(_IY+o, _L); break; case sll_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SLL(b)); } break; case sra_a: _A = read_mem(_IY+o); _A = SRA(_A); write_mem(_IY+o, _A); break; case sra_b: _B = read_mem(_IY+o); _B = SRA(_B); write_mem(_IY+o, _B); break; case sra_c: _C = read_mem(_IY+o); _C = SRA(_C); write_mem(_IY+o, _C); break; case sra_d: _D = read_mem(_IY+o); _D = SRA(_D); write_mem(_IY+o, _D); break; case sra_e: _E = read_mem(_IY+o); _E = SRA(_E); write_mem(_IY+o, _E); break; case sra_h: _H = read_mem(_IY+o); _H = SRA(_H); write_mem(_IY+o, _H); break; case sra_l: _L = read_mem(_IY+o); _L = SRA(_L); write_mem(_IY+o, _L); break; case sra_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SRA(b)); } break; case srl_a: _A = read_mem(_IY+o); _A = SRL(_A); write_mem(_IY+o, _A); break; case srl_b: _B = read_mem(_IY+o); _B = SRL(_B); write_mem(_IY+o, _B); break; case srl_c: _C = read_mem(_IY+o); _C = SRL(_C); write_mem(_IY+o, _C); break; case srl_d: _D = read_mem(_IY+o); _D = SRL(_D); write_mem(_IY+o, _D); break; case srl_e: _E = read_mem(_IY+o); _E = SRL(_E); write_mem(_IY+o, _E); break; case srl_h: _H = read_mem(_IY+o); _H = SRL(_H); write_mem(_IY+o, _H); break; case srl_l: _L = read_mem(_IY+o); _L = SRL(_L); write_mem(_IY+o, _L); break; case srl_mhl: { byte b = read_mem(_IY+o); write_mem(_IY+o, SRL(b)); } break; } }
144,549
C++
.cpp
2,853
44.442692
148
0.481688
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,804
disk.cpp
ColinPitrat_caprice32/src/disk.cpp
#include "disk.h" #include <sstream> #include <string> #include "log.h" std::string chrn_to_string(unsigned char* chrn) { std::ostringstream oss; oss << static_cast<int>(chrn[0]) << "-" << static_cast<int>(chrn[1]) << "-" << static_cast<int>(chrn[2]) << "-" << static_cast<int>(chrn[3]); return oss.str(); } void t_sector::setSizes(unsigned int size, unsigned int total_size) { size_ = size; total_size_ = total_size; weak_read_version_ = 0; weak_versions_ = 1; if (size_ > 0 && size_ <= total_size_) weak_versions_ = total_size_ / size_; LOG_DEBUG("weak_versions_ = " << weak_versions_ << " for " << chrn_to_string(CHRN)); }
661
C++
.cpp
20
30.3
86
0.625786
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,805
savepng.cpp
ColinPitrat_caprice32/src/savepng.cpp
/* * SDL_SavePNG -- libpng-based SDL_Surface writer. * * This code is free software, available under zlib/libpng license. * http://www.libpng.org/pub/png/src/libpng-LICENSE.txt * Code was copied and slightly adapted from driedfruit savepng. * See https://github.com/driedfruit/SDL_SavePNG */ #include <SDL.h> #include <png.h> #include <cstdint> #include <string> #include <memory> #define SUCCESS 0 #define ERROR (-1) #define USE_ROW_POINTERS #if SDL_BYTEORDER == SDL_BIG_ENDIAN #define rmask 0xFF000000 #define gmask 0x00FF0000 #define bmask 0x0000FF00 #define amask 0x000000FF #else #define rmask 0x000000FF #define gmask 0x0000FF00 #define bmask 0x00FF0000 #define amask 0xFF000000 #endif // MinGW is unhappy with PRIxPTR on win64, we have to override it. // https://stackoverflow.com/questions/14071713/what-is-wrong-with-printfllx // https://github.com/dosbox-staging/dosbox-staging/issues/64 #if defined(__MINGW64__) && !defined(__clang__) #undef PRIxPTR #define PRIxPTR "I64x" #endif /* libpng callbacks */ static void png_error_SDL(png_structp ctx, png_const_charp str) { SDL_SetError("libpng: %s (ctx is %" PRIxPTR ")\n", str, reinterpret_cast<std::uintptr_t>(ctx)); } static void png_write_SDL(png_structp png_ptr, png_bytep data, png_size_t length) { SDL_RWops *rw = static_cast<SDL_RWops*>(png_get_io_ptr(png_ptr)); SDL_RWwrite(rw, data, sizeof(png_byte), length); } SDL_Surface *SDL_PNGFormatAlpha(SDL_Surface *src) { SDL_Surface *surf; SDL_Rect rect = { 0, 0, 0, 0 }; /* Convert 32bpp alpha-less image to 24bpp alpha-less image */ rect.w = src->w; rect.h = src->h; surf = SDL_CreateRGBSurface(0, src->w, src->h, 24, rmask, gmask, bmask, 0); SDL_LowerBlit(src, &rect, surf, &rect); return surf; } int SDL_SavePNG(SDL_Surface *src, const std::string& file) { /* Initialize and do basic error checking */ if (!src) { SDL_SetError("Argument 1 to SDL_SavePNG_RW can't be NULL, expecting SDL_Surface*\n"); return (ERROR); } SDL_Surface *surface = SDL_PNGFormatAlpha(src); if (!src) { return (ERROR); } SDL_RWops *dst = SDL_RWFromFile(file.c_str(), "wb"); if (!dst) { SDL_SetError("Failed to open file for writing: %s\n", file.c_str()); SDL_FreeSurface(surface); return (ERROR); } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, png_error_SDL, nullptr); /* err_ptr, err_fn, warn_fn */ if (!png_ptr) { SDL_SetError("Unable to png_create_write_struct on %s\n", PNG_LIBPNG_VER_STRING); SDL_RWclose(dst); SDL_FreeSurface(surface); return (ERROR); } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { SDL_SetError("Unable to png_create_info_struct\n"); png_destroy_write_struct(&png_ptr, nullptr); SDL_RWclose(dst); SDL_FreeSurface(surface); return (ERROR); } if (setjmp(png_jmpbuf(png_ptr))) /* All other errors, see also "png_error_SDL" */ { png_destroy_write_struct(&png_ptr, &info_ptr); SDL_RWclose(dst); SDL_FreeSurface(surface); return (ERROR); } int i, colortype; /* Setup our RWops writer */ png_set_write_fn(png_ptr, dst, png_write_SDL, nullptr); /* w_ptr, write_fn, flush_fn */ SDL_Palette *pal; /* Prepare chunks */ colortype = PNG_COLOR_MASK_COLOR; if (surface->format->BytesPerPixel > 0 && surface->format->BytesPerPixel <= 8 && (pal = surface->format->palette)) { colortype |= PNG_COLOR_MASK_PALETTE; std::unique_ptr<png_color[]> pal_ptr = std::make_unique<png_color[]>(pal->ncolors); for (i = 0; i < pal->ncolors; i++) { pal_ptr[i].red = pal->colors[i].r; pal_ptr[i].green = pal->colors[i].g; pal_ptr[i].blue = pal->colors[i].b; } png_set_PLTE(png_ptr, info_ptr, pal_ptr.get(), pal->ncolors); } else if (surface->format->BytesPerPixel > 3 || surface->format->Amask) colortype |= PNG_COLOR_MASK_ALPHA; png_set_IHDR(png_ptr, info_ptr, surface->w, surface->h, 8, colortype, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); // png_set_packing(png_ptr); /* Allow BGR surfaces */ if (surface->format->Rmask == bmask && surface->format->Gmask == gmask && surface->format->Bmask == rmask) png_set_bgr(png_ptr); /* Write everything */ png_write_info(png_ptr, info_ptr); #ifdef USE_ROW_POINTERS std::unique_ptr<png_bytep[]> row_pointers = std::make_unique<png_bytep[]>(surface->h); for (i = 0; i < surface->h; i++) row_pointers[i] = static_cast<png_bytep>(static_cast<void*>(static_cast<char*>(surface->pixels) + i * surface->pitch)); png_write_image(png_ptr, row_pointers.get()); #else for (i = 0; i < surface->h; i++) png_write_row(png_ptr, (png_bytep)(Uint8*)surface->pixels + i * surface->pitch); #endif png_write_end(png_ptr, info_ptr); /* Done */ png_destroy_write_struct(&png_ptr, &info_ptr); SDL_RWclose(dst); SDL_FreeSurface(surface); return (SUCCESS); }
4,959
C++
.cpp
146
30.869863
135
0.681211
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,806
tape.cpp
ColinPitrat_caprice32/src/tape.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* CDT tape image emulation (c) Copyright 2002,2003 Ulrich Doewich */ #include "cap32.h" #include "tape.h" #include "z80.h" #define TAPE_PILOT_STAGE 1 #define TAPE_SYNC_STAGE 2 #define TAPE_DATA_STAGE 3 #define TAPE_SAMPLE_DATA_STAGE 4 #define TAPE_PAUSE_STAGE 5 #define TAPE_END 6 #define CYCLE_SCALE ((40 << 16) / 35) //#define CYCLE_SCALE ((3993600 / 3500000) * 65536) #define CYCLE_ADJUST(p) ((static_cast<dword>(p) * CYCLE_SCALE) >> 16) #define MS_TO_CYCLES(p) (static_cast<dword>(p) * 4000) //#define MS_TO_CYCLES(p) ((dword)(p) * 3994) extern byte *pbTapeImage; extern byte *pbTapeImageEnd; extern t_CPC CPC; #ifdef DEBUG_TAPE extern FILE *pfoDebug; #endif byte bTapeLevel; byte bTapeData; byte *pbTapeBlock; byte *pbTapeBlockData; word *pwTapePulseTable; word *pwTapePulseTableEnd; word *pwTapePulseTablePtr; word wCycleTable[2]; int iTapeCycleCount; dword dwTapePulseCycles; dword dwTapeZeroPulseCycles; dword dwTapeOnePulseCycles; dword dwTapeStage = TAPE_END; dword dwTapePulseCount; dword dwTapeDataCount; dword dwTapeBitsToShift; void Tape_GetCycleCount() { dwTapePulseCycles = CYCLE_ADJUST(*pwTapePulseTablePtr++); if (pwTapePulseTablePtr >= pwTapePulseTableEnd) { pwTapePulseTablePtr = pwTapePulseTable; } } void Tape_SwitchLevel() { if (bTapeLevel == TAPE_LEVEL_LOW) { bTapeLevel = TAPE_LEVEL_HIGH; // reverse the level } else { bTapeLevel = TAPE_LEVEL_LOW; // reverse the level } } int Tape_ReadDataBit() { if (dwTapeDataCount) { if (!dwTapeBitsToShift) { bTapeData = *pbTapeBlockData; // get the next data byte pbTapeBlockData++; dwTapeBitsToShift = 8; #ifdef DEBUG_TAPE fprintf(pfoDebug, ">>> 0x%02x\r\n", (byte)bTapeData); #endif } byte bBit = bTapeData & 0x80; bTapeData <<= 1; dwTapeBitsToShift--; dwTapeDataCount--; if (bBit) { dwTapePulseCycles = dwTapeOnePulseCycles; } else { dwTapePulseCycles = dwTapeZeroPulseCycles; } dwTapePulseCount = 2; // two pulses = one bit return 1; } return 0; // no more data } int Tape_ReadSampleDataBit() { if (dwTapeDataCount) { if (!dwTapeBitsToShift) { bTapeData = *pbTapeBlockData; // get the next data byte pbTapeBlockData++; dwTapeBitsToShift = 8; } byte bBit = bTapeData & 0x80; bTapeData <<= 1; dwTapeBitsToShift--; dwTapeDataCount--; if (bBit) { bTapeLevel = TAPE_LEVEL_HIGH; // set high level } else { bTapeLevel = TAPE_LEVEL_LOW; // set low level } iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; } return 0; // no more data } int Tape_GetNextBlock() { while (pbTapeBlock < pbTapeImageEnd) { // loop until a valid block is found #ifdef DEBUG_TAPE fprintf(pfoDebug, "--- New Block\r\n%02x\r\n", *pbTapeBlock); #endif switch (*pbTapeBlock) { case 0x10: // standard speed data block dwTapeStage = TAPE_PILOT_STAGE; // block starts with a pilot tone #ifdef DEBUG_TAPE fputs("--- PILOT\r\n", pfoDebug); #endif dwTapePulseCycles = CYCLE_ADJUST(2168); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level dwTapePulseCount = 3220; #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; case 0x11: // turbo loading data block dwTapeStage = TAPE_PILOT_STAGE; // block starts with a pilot tone #ifdef DEBUG_TAPE fputs("--- PILOT\r\n", pfoDebug); #endif dwTapePulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01)); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level dwTapePulseCount = *reinterpret_cast<word *>(pbTapeBlock+0x01+0x0a); #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; case 0x12: // pure tone dwTapeStage = TAPE_PILOT_STAGE; // block starts with a pilot tone #ifdef DEBUG_TAPE fputs("--- TONE\r\n", pfoDebug); #endif dwTapePulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01)); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level dwTapePulseCount = *reinterpret_cast<word *>(pbTapeBlock+0x01+0x02); #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; case 0x13: // sequence of pulses of different length dwTapeStage = TAPE_SYNC_STAGE; #ifdef DEBUG_TAPE fputs("--- PULSE SEQ\r\n", pfoDebug); #endif dwTapePulseCount = *(pbTapeBlock+0x01); pwTapePulseTable = pwTapePulseTablePtr = reinterpret_cast<word *>(pbTapeBlock+0x01+0x01); pwTapePulseTableEnd = pwTapePulseTable + dwTapePulseCount; Tape_GetCycleCount(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; case 0x14: // pure data block dwTapeStage = TAPE_DATA_STAGE; #ifdef DEBUG_TAPE fputs("--- DATA\r\n", pfoDebug); #endif dwTapeZeroPulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01)); // pulse length for a zero bit dwTapeOnePulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x02)); // pulse length for a one bit dwTapeDataCount = ((*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x07) & 0x00ffffff) - 1) << 3; // (byte count - 1) * 8 bits dwTapeDataCount += *(pbTapeBlock+0x01+0x04); // add the number of bits in the last data byte pbTapeBlockData = pbTapeBlock+0x01+0x0a; // pointer to the tape data dwTapeBitsToShift = 0; Tape_ReadDataBit(); // get the first bit of the first data byte iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; case 0x15: // direct recording dwTapeStage = TAPE_SAMPLE_DATA_STAGE; #ifdef DEBUG_TAPE fputs("--- SAMPLE DATA\r\n", pfoDebug); #endif dwTapePulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01)); // number of T states per sample dwTapeDataCount = ((*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x05) & 0x00ffffff) - 1) << 3; // (byte count - 1) * 8 bits dwTapeDataCount += *(pbTapeBlock+0x01+0x04); // add the number of bits in the last data byte pbTapeBlockData = pbTapeBlock+0x01+0x08; // pointer to the tape data dwTapeBitsToShift = 0; Tape_ReadSampleDataBit(); // get the first bit of the first data byte return 1; case 0x20: // pause if (*reinterpret_cast<word *>(pbTapeBlock+0x01)) { // was a pause requested? dwTapeStage = TAPE_PAUSE_STAGE; #ifdef DEBUG_TAPE fputs("--- PAUSE\r\n", pfoDebug); #endif dwTapePulseCycles = MS_TO_CYCLES(1); // start with a 1ms level opposite to the one last played iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level dwTapePulseCycles = MS_TO_CYCLES(*reinterpret_cast<word *>(pbTapeBlock+0x01) - 1); // get the actual pause length dwTapePulseCount = 2; // just one pulse #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif return 1; } else { pbTapeBlock += 2 + 1; // skip block if pause length is 0 } break; case 0x21: // group start pbTapeBlock += *(pbTapeBlock+0x01) + 1 + 1; // nothing to do, skip the block break; case 0x22: // group end pbTapeBlock += 1; // nothing to do, skip the block break; case 0x30: // text description pbTapeBlock += *(pbTapeBlock+0x01) + 1 + 1; // nothing to do, skip the block break; case 0x31: // message block pbTapeBlock += *(pbTapeBlock+0x01+0x01) + 2 + 1; // nothing to do, skip the block break; case 0x32: // archive info pbTapeBlock += *reinterpret_cast<word *>(pbTapeBlock+0x01) + 2 + 1; // nothing to do, skip the block break; case 0x33: // hardware type pbTapeBlock += (*(pbTapeBlock+0x01) * 3) + 1 + 1; // nothing to do, skip the block break; case 0x34: // emulation info pbTapeBlock += 8 + 1; // nothing to do, skip the block break; case 0x35: // custom info block pbTapeBlock += *reinterpret_cast<dword *>(pbTapeBlock+0x01+0x10) + 0x14 + 1; // nothing to do, skip the block break; case 0x40: // snapshot block pbTapeBlock += (*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x01) & 0x00ffffff) + 0x04 + 1; // nothing to do, skip the block break; case 0x5A: // another tzx/cdt file pbTapeBlock += 9 + 1; // nothing to do, skip the block break; default: // "extension rule" pbTapeBlock += *reinterpret_cast<dword *>(pbTapeBlock+0x01) + 4 + 1; // nothing to do, skip the block } } return 0; // we've reached the end of the image } void Tape_BlockDone() { if (pbTapeBlock < pbTapeImageEnd) { switch (*pbTapeBlock) { case 0x10: // standard speed data block pbTapeBlock += *reinterpret_cast<word *>(pbTapeBlock+0x01+0x02) + 0x04 + 1; break; case 0x11: // turbo loading data block pbTapeBlock += (*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x0f) & 0x00ffffff) + 0x12 + 1; break; case 0x12: // pure tone pbTapeBlock += 4 + 1; break; case 0x13: // sequence of pulses of different length pbTapeBlock += *(pbTapeBlock+0x01) * 2 + 1 + 1; break; case 0x14: // pure data block pbTapeBlock += (*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x07) & 0x00ffffff) + 0x0a + 1; break; case 0x15: // direct recording pbTapeBlock += (*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x05) & 0x00ffffff) + 0x08 + 1; break; case 0x20: // pause pbTapeBlock += 2 + 1; break; } if (!Tape_GetNextBlock()) { dwTapeStage = TAPE_END; CPC.tape_play_button = 0; } } } void Tape_UpdateLevel() { switch (dwTapeStage) { case TAPE_PILOT_STAGE: Tape_SwitchLevel(); dwTapePulseCount--; if (dwTapePulseCount > 0) { // is the pilot tone still playing? iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif } else { // finished with the pilot tone switch (*pbTapeBlock) { case 0x10: // standard speed data block dwTapeStage = TAPE_SYNC_STAGE; #ifdef DEBUG_TAPE fputs("--- SYNC\r\n", pfoDebug); #endif wCycleTable[0] = 667; wCycleTable[1] = 735; pwTapePulseTable = pwTapePulseTablePtr = &wCycleTable[0]; pwTapePulseTableEnd = &wCycleTable[2]; Tape_GetCycleCount(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCount = 2; break; case 0x11: // turbo loading data block dwTapeStage = TAPE_SYNC_STAGE; #ifdef DEBUG_TAPE fputs("--- SYNC\r\n", pfoDebug); #endif pwTapePulseTable = pwTapePulseTablePtr = reinterpret_cast<word *>(pbTapeBlock+0x01+0x02); pwTapePulseTableEnd = reinterpret_cast<word *>(pbTapeBlock+0x01+0x06); Tape_GetCycleCount(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCount = 2; break; case 0x12: // pure tone Tape_BlockDone(); break; } } break; case TAPE_SYNC_STAGE: Tape_SwitchLevel(); dwTapePulseCount--; if (dwTapePulseCount > 0) { Tape_GetCycleCount(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif } else { switch (*pbTapeBlock) { case 0x10: // standard speed data block dwTapeStage = TAPE_DATA_STAGE; #ifdef DEBUG_TAPE fputs("--- DATA\r\n", pfoDebug); #endif dwTapeZeroPulseCycles = CYCLE_ADJUST(855); // pulse length for a zero bit dwTapeOnePulseCycles = CYCLE_ADJUST(1710); // pulse length for a one bit dwTapeDataCount = *reinterpret_cast<word *>(pbTapeBlock+0x01+0x02) << 3; // byte count * 8 bits; pbTapeBlockData = pbTapeBlock+0x01+0x04; // pointer to the tape data dwTapeBitsToShift = 0; Tape_ReadDataBit(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif break; case 0x11: // turbo loading data block dwTapeStage = TAPE_DATA_STAGE; #ifdef DEBUG_TAPE fputs("--- DATA\r\n", pfoDebug); #endif dwTapeZeroPulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x06)); // pulse length for a zero bit dwTapeOnePulseCycles = CYCLE_ADJUST(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x08)); // pulse length for a one bit dwTapeDataCount = ((*reinterpret_cast<dword *>(pbTapeBlock+0x01+0x0f) & 0x00ffffff) - 1) << 3; // (byte count - 1) * 8 bits; dwTapeDataCount += *(pbTapeBlock+0x01+0x0c); // add the number of bits in the last data byte pbTapeBlockData = pbTapeBlock+0x01+0x12; // pointer to the tape data dwTapeBitsToShift = 0; Tape_ReadDataBit(); iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif break; case 0x13: // sequence of pulses of different length Tape_BlockDone(); break; } } break; case TAPE_DATA_STAGE: Tape_SwitchLevel(); dwTapePulseCount--; if (dwTapePulseCount > 0) { iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif } else { if (Tape_ReadDataBit()) { iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif } else { switch (*pbTapeBlock) { case 0x10: // standard speed data block if (*reinterpret_cast<word *>(pbTapeBlock+0x01)) { // was a pause requested? dwTapeStage = TAPE_PAUSE_STAGE; #ifdef DEBUG_TAPE fputs("--- PAUSE\r\n", pfoDebug); #endif dwTapePulseCycles = MS_TO_CYCLES(1); // start with a 1ms level opposite to the one last played iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCycles = MS_TO_CYCLES(*reinterpret_cast<word *>(pbTapeBlock+0x01) - 1); // pause in ms dwTapePulseCount = 2; // just one pulse } else { Tape_BlockDone(); } break; case 0x11: // turbo loading data block if (*reinterpret_cast<word *>(pbTapeBlock+0x01+0x0d)) { // was a pause requested? dwTapeStage = TAPE_PAUSE_STAGE; #ifdef DEBUG_TAPE fputs("--- PAUSE\r\n", pfoDebug); #endif dwTapePulseCycles = MS_TO_CYCLES(1); // start with a 1ms level opposite to the one last played iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCycles = MS_TO_CYCLES(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x0d) - 1); // pause in ms dwTapePulseCount = 2; // just one pulse } else { Tape_BlockDone(); } break; case 0x14: // pure data block if (*reinterpret_cast<word *>(pbTapeBlock+0x01+0x05)) { // was a pause requested? dwTapeStage = TAPE_PAUSE_STAGE; #ifdef DEBUG_TAPE fputs("--- PAUSE\r\n", pfoDebug); #endif dwTapePulseCycles = MS_TO_CYCLES(1); // start with a 1ms level opposite to the one last played iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCycles = MS_TO_CYCLES(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x05) - 1); // pause in ms dwTapePulseCount = 2; // just one pulse } else { Tape_BlockDone(); } break; default: Tape_BlockDone(); } } } break; case TAPE_SAMPLE_DATA_STAGE: if (!Tape_ReadSampleDataBit()) { if (*reinterpret_cast<word *>(pbTapeBlock+0x01+0x02)) { // was a pause requested? dwTapeStage = TAPE_PAUSE_STAGE; #ifdef DEBUG_TAPE fputs("--- PAUSE\r\n", pfoDebug); #endif dwTapePulseCycles = MS_TO_CYCLES(1); // start with a 1ms level opposite to the one last played iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif dwTapePulseCycles = MS_TO_CYCLES(*reinterpret_cast<word *>(pbTapeBlock+0x01+0x02) - 1); // pause in ms dwTapePulseCount = 2; // just one pulse } else { Tape_BlockDone(); } } break; case TAPE_PAUSE_STAGE: bTapeLevel = TAPE_LEVEL_LOW; dwTapePulseCount--; if (dwTapePulseCount > 0) { iTapeCycleCount += static_cast<int>(dwTapePulseCycles); // set cycle count for current level #ifdef DEBUG_TAPE fprintf(pfoDebug, "%c %d\r\n",(bTapeLevel == TAPE_LEVEL_HIGH ? 'H':'L'), iTapeCycleCount); #endif } else { Tape_BlockDone(); } break; case TAPE_END: CPC.tape_play_button = 0; break; } } void Tape_Rewind() { pbTapeBlock = pbTapeImage; bTapeLevel = TAPE_LEVEL_LOW; iTapeCycleCount = 0; CPC.tape_play_button = 0; Tape_GetNextBlock(); }
23,589
C++
.cpp
522
32.994253
142
0.561094
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,807
slotshandler.cpp
ColinPitrat_caprice32/src/slotshandler.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2005 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <iostream> #include <sstream> #include <string> #include "cap32.h" #include "disk.h" #include "slotshandler.h" #include "ipf.h" #include "errors.h" #include "cartridge.h" #include "log.h" #include "fileutils.h" #include "stringutils.h" #include "tape.h" #include "z80.h" #include "zip.h" extern t_CPC CPC; extern t_CRTC CRTC; extern t_FDC FDC; extern t_VDU VDU; extern t_GateArray GateArray; extern t_PPI PPI; extern t_PSG PSG; extern t_drive driveA; extern t_drive driveB; extern t_z80regs z80; extern byte bit_values[8]; extern t_flags1 flags1; extern word MaxVSync; extern byte *pbROM; extern std::string chROMFile[]; byte *pbTapeImageEnd = nullptr; extern byte *pbTapeImage; extern byte *pbGPBuffer; extern byte *pbRAM; extern byte *pbRAMbuffer; extern FILE *pfileObject; struct file_loader { DRIVE drive; std::string extension; int (*load_from_filename)(const std::string& filename); int (*load_from_file)(FILE *file); }; file_loader files_loader_list[] = { { DSK_A, ".dsk", [](const std::string& filename) -> int { return dsk_load(filename, &driveA); }, [](FILE* file) -> int { return dsk_load(file, &driveA); } }, { DSK_B, ".dsk", [](const std::string& filename) -> int { return dsk_load(filename, &driveB); }, [](FILE* file) -> int { return dsk_load(file, &driveB); } }, #ifdef WITH_IPF { DSK_A, ".ipf", [](const std::string& filename) -> int { return ipf_load(filename, &driveA); }, [](FILE* file) -> int { return ipf_load(file, &driveA); } }, { DSK_B, ".ipf", [](const std::string& filename) -> int { return ipf_load(filename, &driveB); }, [](FILE* file) -> int { return ipf_load(file, &driveB); } }, #endif { OTHER, ".sna", &snapshot_load, &snapshot_load }, { OTHER, ".cdt", &tape_insert, &tape_insert }, { OTHER, ".voc", &tape_insert, &tape_insert }, { OTHER, ".cpr", &cartridge_load, &cartridge_load }, }; t_disk_format disk_format[MAX_DISK_FORMAT] = { { "178K Data Format", 40, 1, 9, 2, 0x52, 0xe5, {{ 0xc1, 0xc6, 0xc2, 0xc7, 0xc3, 0xc8, 0xc4, 0xc9, 0xc5 }} }, { "169K Vendor Format", 40, 1, 9, 2, 0x52, 0xe5, {{ 0x41, 0x46, 0x42, 0x47, 0x43, 0x48, 0x44, 0x49, 0x45 }} } }; inline bool fillSlot(std::string &filevar, bool &processedvar, const std::string& fullpath, const std::string& extension, const std::string& type_ext, const std::string& type_desc) { if ((!processedvar) && (extension == type_ext)) { LOG_VERBOSE("Loading " << type_desc << " file: " << fullpath); filevar = fullpath; processedvar = true; return true; } return false; } // Parses a list of files and fill in the relevant CPC fields // according to what is found. // All we do here is fill the proper xxx_file entry. void fillSlots (std::vector<std::string> slot_list, t_CPC& CPC) { bool have_DSKA = false; bool have_DSKB = false; bool have_SNA = false; bool have_TAP = false; bool have_CPR = false; for (const auto& slot : slot_list) { // loop for all command line arguments LOG_DEBUG("Handling arg " << slot); std::string fullpath = stringutils::trim(slot, '"'); // remove quotes if arguments quoted if (fullpath.length() > 5) { // minumum for a valid filename int pos = fullpath.length() - 4; std::string extension = stringutils::lower(fullpath.substr(pos)); if (extension == ".zip") { // are we dealing with a zip archive? zip::t_zip_info zip_info; zip_info.filename = fullpath; zip_info.extensions = ".dsk.sna.cdt.voc.cpr.ipf"; if (zip::dir(&zip_info)) { continue; // error or nothing relevant found } std::string filename = zip_info.filesOffsets[0].first; pos = filename.length() - 4; extension = filename.substr(pos); // grab the extension } if (fillSlot(CPC.drvA_file, have_DSKA, fullpath, extension, ".dsk", "drive A disk")) continue; if (fillSlot(CPC.drvA_file, have_DSKA, fullpath, extension, ".ipf", "drive A disk (IPF)")) continue; if (fillSlot(CPC.drvB_file, have_DSKB, fullpath, extension, ".dsk", "drive B disk")) continue; if (fillSlot(CPC.drvB_file, have_DSKB, fullpath, extension, ".ipf", "drive B disk (IPF)")) continue; if (fillSlot(CPC.snap_file, have_SNA, fullpath, extension, ".sna", "CPC state snapshot")) continue; if (fillSlot(CPC.tape_file, have_TAP, fullpath, extension, ".cdt", "tape (CDT)")) continue; if (fillSlot(CPC.tape_file, have_TAP, fullpath, extension, ".voc", "tape (VOC)")) continue; if (fillSlot(CPC.cart_file, have_CPR, fullpath, extension, ".cpr", "cartridge")) continue; } } } void loadSlots() { memset(&driveA, 0, sizeof(t_drive)); // clear disk drive A data structure file_load(CPC.drvA_file, DSK_A); memset(&driveB, 0, sizeof(t_drive)); // clear disk drive B data structure file_load(CPC.drvB_file, DSK_B); file_load(CPC.tape_file, OTHER); file_load(CPC.snap_file, OTHER); // Cartridge was loaded by emulator_init if needed } // Extract 'filename' from 'zipfile'. Filename must end with one of the extensions listed in 'ext'. // FILE handle returned must be closed once finished with. // nullptr is returned if file couldn't be extracted for any reason. FILE *extractFile(const std::string& zipfile, const std::string& filename, const std::string& ext) { zip::t_zip_info zip_info; zip_info.filename = zipfile; zip_info.extensions = ext; if (!zip::dir(&zip_info)) { // parse the zip for relevant files for (const auto& fn : zip_info.filesOffsets) { if (!strcasecmp(filename.c_str(), fn.first.c_str())) { // do we have a match? FILE *file = nullptr; zip_info.dwOffset = fn.second; // get the offset into the zip archive if (!zip::extract(zip_info, &file)) { return file; } } } } return nullptr; } t_disk_format parseDiskFormat(const std::string& format) { t_disk_format result; dword dwVal; std::vector<std::string> tokens = stringutils::split(format, ','); if (tokens.size() < 7) { // Minimum number of values required return result; } dwVal = strtoul(tokens[1].c_str(), nullptr, 0); if ((dwVal < 1) || (dwVal > DSK_TRACKMAX)) { // invalid value? return result; } result.tracks = dwVal; dwVal = strtoul(tokens[2].c_str(), nullptr, 0); if ((dwVal < 1) || (dwVal > DSK_SIDEMAX)) { // invalid value? return result; } result.sides = dwVal; dwVal = strtoul(tokens[3].c_str(), nullptr, 0); if ((dwVal < 1) || (dwVal > DSK_SECTORMAX)) { // invalid value? return result; } result.sectors = dwVal; dwVal = strtoul(tokens[4].c_str(), nullptr, 0); if ((dwVal < 1) || (dwVal > 6)) { // invalid value? return result; } result.sector_size = dwVal; dwVal = strtoul(tokens[5].c_str(), nullptr, 0); if ((dwVal < 1) || (dwVal > 255)) { // invalid value? return result; } result.gap3_length = dwVal; dwVal = strtoul(tokens[6].c_str(), nullptr, 0); result.filler_byte = static_cast<byte>(dwVal); unsigned int i = 7; for (int iSide = 0; iSide < static_cast<int>(result.sides); iSide++) { for (int iSector = 0; iSector < static_cast<int>(result.sectors); iSector++) { if (i >= tokens.size()) { // value missing? dwVal = iSector+1; } else { dwVal = strtoul(tokens[i++].c_str(), nullptr, 0); } result.sector_ids[iSide][iSector] = static_cast<byte>(dwVal); } } // Fill the label only if the disk format is valid result.label = tokens[0]; return result; } std::string serializeDiskFormat(const t_disk_format& format) { std::ostringstream oss; if (!format.label.empty()) { oss << format.label << ","; oss << format.tracks << ","; oss << format.sides << ","; oss << format.sectors << ","; oss << format.sector_size << ","; oss << format.gap3_length << ","; oss << static_cast<unsigned int>(format.filler_byte); for (int iSide = 0; iSide < static_cast<int>(format.sides); iSide++) { for (int iSector = 0; iSector < static_cast<int>(format.sectors); iSector++) { oss << "," << static_cast<unsigned int>(format.sector_ids[iSide][iSector]); } } } return oss.str(); } int snapshot_save (const std::string &filename) { t_SNA_header sh; dword dwFlags; memset(&sh, 0, sizeof(sh)); memcpy(sh.id, "MV - SNA", sizeof(sh.id)); sh.version = 3; // Z80 sh.AF[1] = z80.AF.b.h; sh.AF[0] = z80.AF.b.l; sh.BC[1] = z80.BC.b.h; sh.BC[0] = z80.BC.b.l; sh.DE[1] = z80.DE.b.h; sh.DE[0] = z80.DE.b.l; sh.HL[1] = z80.HL.b.h; sh.HL[0] = z80.HL.b.l; sh.R = (z80.R & 0x7f) | (z80.Rb7 & 0x80); sh.I = z80.I; if (z80.IFF1) sh.IFF0 = 1; if (z80.IFF2) sh.IFF1 = 1; sh.IX[1] = z80.IX.b.h; sh.IX[0] = z80.IX.b.l; sh.IY[1] = z80.IY.b.h; sh.IY[0] = z80.IY.b.l; sh.SP[1] = z80.SP.b.h; sh.SP[0] = z80.SP.b.l; sh.PC[1] = z80.PC.b.h; sh.PC[0] = z80.PC.b.l; sh.IM = z80.IM; sh.AFx[1] = z80.AFx.b.h; sh.AFx[0] = z80.AFx.b.l; sh.BCx[1] = z80.BCx.b.h; sh.BCx[0] = z80.BCx.b.l; sh.DEx[1] = z80.DEx.b.h; sh.DEx[0] = z80.DEx.b.l; sh.HLx[1] = z80.HLx.b.h; sh.HLx[0] = z80.HLx.b.l; // Gate Array sh.ga_pen = GateArray.pen; for (int n = 0; n < 17; n++) { // loop for all colours + border sh.ga_ink_values[n] = GateArray.ink_values[n]; } sh.ga_ROM_config = GateArray.ROM_config; sh.ga_RAM_config = GateArray.RAM_config; // CRTC sh.crtc_reg_select = CRTC.reg_select; for (int n = 0; n < 18; n++) { // loop for all CRTC registers sh.crtc_registers[n] = CRTC.registers[n]; } // ROM select sh.upper_ROM = GateArray.upper_ROM; // PPI sh.ppi_A = PPI.portA; sh.ppi_B = PPI.portB; sh.ppi_C = PPI.portC; sh.ppi_control = PPI.control; // PSG sh.psg_reg_select = PSG.reg_select; for (int n = 0; n < 16; n++) { // loop for all PSG registers sh.psg_registers[n] = PSG.RegisterAY.Index[n]; } sh.ram_size[0] = CPC.ram_size & 0xff; sh.ram_size[1] = (CPC.ram_size >> 8) & 0xff; // version 2 info sh.cpc_model = CPC.model; // version 3 info sh.fdc_motor = FDC.motor; sh.drvA_current_track = driveA.current_track; sh.drvB_current_track = driveB.current_track; sh.printer_data = CPC.printer_port ^ 0x80; // invert bit 7 again sh.psg_env_step = PSG.AmplitudeEnv >> 1; // divide by 2 to bring it into the 0 - 15 range if (PSG.FirstPeriod) { switch (PSG.RegisterAY.EnvType) { case 0: case 1: case 2: case 3: case 8: case 9: case 10: case 11: sh.psg_env_direction = 0xff; // down break; case 4: case 5: case 6: case 7: case 12: case 13: case 14: case 15: sh.psg_env_direction = 0x01; // up break; } } else { switch (PSG.RegisterAY.EnvType) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 9: case 11: case 13: case 15: sh.psg_env_direction = 0x00; // hold break; case 8: case 14: sh.psg_env_direction = 0xff; // down break; case 10: case 12: sh.psg_env_direction = 0x01; // up break; } } sh.crtc_addr[0] = CRTC.addr & 0xff; sh.crtc_addr[1] = (CRTC.addr >> 8) & 0xff; sh.crtc_scanline[0] = VDU.scanline & 0xff; sh.crtc_scanline[1] = (VDU.scanline >> 8) & 0xff; sh.crtc_char_count[0] = CRTC.char_count; sh.crtc_line_count = CRTC.line_count; sh.crtc_raster_count = CRTC.raster_count; sh.crtc_hsw_count = CRTC.hsw_count; sh.crtc_vsw_count = CRTC.vsw_count; dwFlags = 0; if (CRTC.flag_invsync) { // vsync active? dwFlags |= 1; } if (flags1.inHSYNC) { // hsync active? dwFlags |= 2; } if (CRTC.flag_invta) { // in vertical total adjust? dwFlags |= 0x80; } sh.crtc_flags[0] = dwFlags & 0xff; sh.crtc_flags[1] = (dwFlags >> 8) & 0xff; sh.ga_int_delay = GateArray.hs_count; sh.ga_sl_count = GateArray.sl_count; sh.z80_int_pending = z80.int_pending; if ((pfileObject = fopen(filename.c_str(), "wb")) != nullptr) { if (fwrite(&sh, sizeof(sh), 1, pfileObject) != 1) { // write snapshot header fclose(pfileObject); return ERR_SNA_WRITE; } if (fwrite(pbRAM, CPC.ram_size*1024, 1, pfileObject) != 1) { // write memory contents to snapshot file fclose(pfileObject); return ERR_SNA_WRITE; } fclose(pfileObject); } else { return ERR_SNA_WRITE; } return 0; } void dsk_eject (t_drive *drive) { dword track, side; if (drive->eject_hook) drive->eject_hook(drive); // additional cleanup for (track = 0; track < DSK_TRACKMAX; track++) { // loop for all tracks for (side = 0; side < DSK_SIDEMAX; side++) { // loop for all sides delete [] drive->track[track][side].data; // release memory allocated for this track } } dword dwTemp = drive->current_track; // save the drive head position memset(drive, 0, sizeof(t_drive)); // clear drive info structure drive->current_track = dwTemp; } int dsk_load (FILE *pfile, t_drive *drive) { LOG_DEBUG("Loading disk"); dword dwTrackSize, track, side, sector, dwSectorSize, dwSectors; byte *pbPtr, *pbDataPtr, *pbTempPtr, *pbTrackSizeTable; if(fread(pbGPBuffer, 0x100, 1, pfile) != 1) { // read DSK header LOG_ERROR("Couldn't read DSK header"); return ERR_DSK_INVALID; } pbPtr = pbGPBuffer; if (memcmp(pbPtr, "MV - CPC", 8) == 0) { // normal DSK image? LOG_DEBUG("Loading normal disk"); drive->tracks = *(pbPtr + 0x30); // grab number of tracks if (drive->tracks > DSK_TRACKMAX) { // compare against upper limit drive->tracks = DSK_TRACKMAX; // limit to maximum } drive->sides = *(pbPtr + 0x31); // grab number of sides if (drive->sides > DSK_SIDEMAX) { // abort if more than maximum LOG_ERROR("DSK header has " << drive->sides << " sides, expected " << DSK_SIDEMAX << " or less"); dsk_eject(drive); return ERR_DSK_SIDES; } dwTrackSize = (*(pbPtr + 0x32) + (*(pbPtr + 0x33) << 8)) - 0x100; // determine track size in bytes, minus track header drive->sides--; // zero base number of sides for (track = 0; track < drive->tracks; track++) { // loop for all tracks for (side = 0; side <= drive->sides; side++) { // loop for all sides if(fread(pbGPBuffer+0x100, 0x100, 1, pfile) != 1) { // read track header LOG_ERROR("Couldn't read DSK track header for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } pbPtr = pbGPBuffer + 0x100; if (memcmp(pbPtr, "Track-Info", 10) != 0) { // abort if ID does not match LOG_ERROR("Corrupted DSK track header for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } dwSectorSize = 0x80 << *(pbPtr + 0x14); // determine sector size in bytes dwSectors = *(pbPtr + 0x15); // grab number of sectors if (dwSectors > DSK_SECTORMAX) { // abort if sector count greater than maximum LOG_ERROR("DSK track with " << dwSectors << " sectors, expected " << DSK_SECTORMAX << "or less"); dsk_eject(drive); return ERR_DSK_SECTORS; } drive->track[track][side].sectors = dwSectors; // store sector count drive->track[track][side].size = dwTrackSize; // store track size drive->track[track][side].data = new byte[dwTrackSize]; // attempt to allocate the required memory pbDataPtr = drive->track[track][side].data; // pointer to start of memory buffer pbTempPtr = pbDataPtr; // keep a pointer to the beginning of the buffer for the current track for (sector = 0; sector < dwSectors; sector++) { // loop for all sectors memcpy(drive->track[track][side].sector[sector].CHRN, (pbPtr + 0x18), 4); // copy CHRN memcpy(drive->track[track][side].sector[sector].flags, (pbPtr + 0x1c), 2); // copy ST1 & ST2 drive->track[track][side].sector[sector].setSizes(dwSectorSize, dwSectorSize); drive->track[track][side].sector[sector].setData(pbDataPtr); // store pointer to sector data pbDataPtr += dwSectorSize; pbPtr += 8; } if (dwTrackSize > 0 && !fread(pbTempPtr, dwTrackSize, 1, pfile)) { // read entire track data in one go LOG_ERROR("Couldn't read track data for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } } } drive->altered = false; // disk is as yet unmodified } else { if (memcmp(pbPtr, "EXTENDED", 8) == 0) { // extended DSK image? LOG_DEBUG("Loading extended disk"); drive->tracks = *(pbPtr + 0x30); // number of tracks LOG_DEBUG("with " << drive->tracks << " tracks"); if (drive->tracks > DSK_TRACKMAX) { // limit to maximum possible drive->tracks = DSK_TRACKMAX; } drive->random_DEs = *(pbPtr + 0x31) & 0x80; // simulate random Data Errors? drive->sides = *(pbPtr + 0x31) & 3; // number of sides LOG_DEBUG("with " << drive->sides << " sides"); if (drive->sides > DSK_SIDEMAX) { // abort if more than maximum LOG_ERROR("DSK header has " << drive->sides << " sides, expected " << DSK_SIDEMAX << " or less"); dsk_eject(drive); return ERR_DSK_SIDES; } pbTrackSizeTable = pbPtr + 0x34; // pointer to track size table in DSK header drive->sides--; // zero base number of sides for (track = 0; track < drive->tracks; track++) { // loop for all tracks for (side = 0; side <= drive->sides; side++) { // loop for all sides dwTrackSize = (*pbTrackSizeTable++ << 8); // track size in bytes LOG_DEBUG("Track " << track << ", side " << side << ", size " << dwTrackSize); if (dwTrackSize != 0) { // only process if track contains data dwTrackSize -= 0x100; // compensate for track header if(fread(pbGPBuffer+0x100, 0x100, 1, pfile) != 1) { // read track header LOG_ERROR("Couldn't read DSK track header for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } pbPtr = pbGPBuffer + 0x100; if (memcmp(pbPtr, "Track-Info", 10) != 0) { // valid track header? LOG_ERROR("Corrupted DSK track header for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } dwSectors = *(pbPtr + 0x15); // number of sectors for this track LOG_DEBUG("with " << dwSectors << " sectors"); if (dwSectors > DSK_SECTORMAX) { // abort if sector count greater than maximum LOG_ERROR("DSK track with " << dwSectors << " sectors, expected " << DSK_SECTORMAX << "or less"); dsk_eject(drive); return ERR_DSK_SECTORS; } drive->track[track][side].sectors = dwSectors; // store sector count drive->track[track][side].size = dwTrackSize; // store track size drive->track[track][side].data = new byte[dwTrackSize]; // attempt to allocate the required memory pbDataPtr = drive->track[track][side].data; // pointer to start of memory buffer pbTempPtr = pbDataPtr; // keep a pointer to the beginning of the buffer for the current track pbPtr += 0x18; for (sector = 0; sector < dwSectors; sector++) { // loop for all sectors memcpy(drive->track[track][side].sector[sector].CHRN, pbPtr, 4); // copy CHRN memcpy(drive->track[track][side].sector[sector].flags, (pbPtr + 0x04), 2); // copy ST1 & ST2 dword dwRealSize = 0x80 << *(pbPtr+0x03); dwSectorSize = *(pbPtr + 0x6) + (*(pbPtr + 0x7) << 8); // sector size in bytes drive->track[track][side].sector[sector].setSizes(dwRealSize, dwSectorSize); drive->track[track][side].sector[sector].setData(pbDataPtr); // store pointer to sector data pbDataPtr += dwSectorSize; pbPtr += 8; LOG_DEBUG("Sector " << sector << " size: " << dwSectorSize << " real size: " << dwRealSize << " CHRN: " << chrn_to_string(drive->track[track][side].sector[sector].CHRN)); } if (dwTrackSize > 0 && !fread(pbTempPtr, dwTrackSize, 1, pfile)) { // read entire track data in one go LOG_ERROR("Couldn't read track data for track " << track << " side " << side); dsk_eject(drive); return ERR_DSK_INVALID; } } else { LOG_DEBUG("empty track"); memset(&drive->track[track][side], 0, sizeof(t_track)); // track not formatted } } } drive->altered = false; // disk is as yet unmodified } else { LOG_ERROR("Unknown DSK type"); dsk_eject(drive); return ERR_DSK_INVALID; // file could not be identified as a valid DSK } } return 0; } int dsk_load (const std::string &filename, t_drive *drive) { int iRetCode = 0; LOG_DEBUG("Loading disk: " << filename); dsk_eject(drive); if ((pfileObject = fopen(filename.c_str(), "rb")) != nullptr) { iRetCode = dsk_load(pfileObject, drive); fclose(pfileObject); } else { LOG_ERROR("File not found: " << filename); iRetCode = ERR_FILE_NOT_FOUND; } if (iRetCode != 0) { // on error, 'eject' disk from drive dsk_eject(drive); } return iRetCode; } int dsk_save (const std::string &filename, t_drive *drive) { t_DSK_header dh; t_track_header th; dword track, side, pos, sector; if ((pfileObject = fopen(filename.c_str(), "wb")) != nullptr) { memset(&dh, 0, sizeof(dh)); memcpy(dh.id, "EXTENDED CPC DSK File\r\nDisk-Info\r\n", sizeof(dh.id)); strncpy(dh.unused1, "Caprice32\r\n", sizeof(dh.unused1)); dh.tracks = drive->tracks; dh.sides = (drive->sides+1) | (drive->random_DEs); // correct side count and indicate random DEs, if necessary pos = 0; for (track = 0; track < drive->tracks; track++) { // loop for all tracks for (side = 0; side <= drive->sides; side++) { // loop for all sides if (drive->track[track][side].size) { // track is formatted? dh.track_size[pos] = (drive->track[track][side].size + 0x100) >> 8; // track size + header in bytes } pos++; } } if (!fwrite(&dh, sizeof(dh), 1, pfileObject)) { // write header to file fclose(pfileObject); return ERR_DSK_WRITE; } memset(&th, 0, sizeof(th)); memcpy(th.id, "Track-Info\r\n", sizeof(th.id)); for (track = 0; track < drive->tracks; track++) { // loop for all tracks for (side = 0; side <= drive->sides; side++) { // loop for all sides if (drive->track[track][side].size) { // track is formatted? th.track = track; th.side = side; th.bps = 2; th.sectors = drive->track[track][side].sectors; th.gap3 = 0x4e; th.filler = 0xe5; for (sector = 0; sector < th.sectors; sector++) { memcpy(&th.sector[sector][0], drive->track[track][side].sector[sector].CHRN, 4); // copy CHRN memcpy(&th.sector[sector][4], drive->track[track][side].sector[sector].flags, 2); // copy ST1 & ST2 th.sector[sector][6] = drive->track[track][side].sector[sector].getTotalSize() & 0xff; th.sector[sector][7] = (drive->track[track][side].sector[sector].getTotalSize() >> 8) & 0xff; // sector size in bytes } if (!fwrite(&th, sizeof(th), 1, pfileObject)) { // write track header fclose(pfileObject); return ERR_DSK_WRITE; } if (!fwrite(drive->track[track][side].data, drive->track[track][side].size, 1, pfileObject)) { // write track data fclose(pfileObject); return ERR_DSK_WRITE; } } } } drive->altered = false; // Drive is not modified anymore fclose(pfileObject); } else { return ERR_DSK_WRITE; // write attempt failed } return 0; } int dsk_format (t_drive *drive, int iFormat) { int iRetCode = 0; drive->tracks = disk_format[iFormat].tracks; if (drive->tracks > DSK_TRACKMAX) { // compare against upper limit drive->tracks = DSK_TRACKMAX; // limit to maximum } drive->sides = disk_format[iFormat].sides; if (drive->sides > DSK_SIDEMAX) { // abort if more than maximum iRetCode = ERR_DSK_SIDES; goto exit; } drive->sides--; // zero base number of sides for (dword track = 0; track < drive->tracks; track++) { // loop for all tracks for (dword side = 0; side <= drive->sides; side++) { // loop for all sides dword dwSectorSize = 0x80 << disk_format[iFormat].sector_size; // determine sector size in bytes dword dwSectors = disk_format[iFormat].sectors; if (dwSectors > DSK_SECTORMAX) { // abort if sector count greater than maximum iRetCode = ERR_DSK_SECTORS; goto exit; } dword dwTrackSize = dwSectorSize * dwSectors; // determine track size in bytes, minus track header drive->track[track][side].sectors = dwSectors; // store sector count drive->track[track][side].size = dwTrackSize; // store track size drive->track[track][side].data = new byte[dwTrackSize]; // attempt to allocate the required memory byte *pbDataPtr = drive->track[track][side].data; // pointer to start of memory buffer byte *pbTempPtr = pbDataPtr; // keep a pointer to the beginning of the buffer for the current track byte CHRN[4]; CHRN[0] = static_cast<byte>(track); CHRN[1] = static_cast<byte>(side); CHRN[3] = static_cast<byte>(disk_format[iFormat].sector_size); for (dword sector = 0; sector < dwSectors; sector++) { // loop for all sectors CHRN[2] = disk_format[iFormat].sector_ids[side][sector]; memcpy(drive->track[track][side].sector[sector].CHRN, CHRN, 4); // copy CHRN drive->track[track][side].sector[sector].setSizes(dwSectorSize, dwSectorSize); drive->track[track][side].sector[sector].setData(pbDataPtr); // store pointer to sector data pbDataPtr += dwSectorSize; } memset(pbTempPtr, disk_format[iFormat].filler_byte, dwTrackSize); } } drive->altered = true; // flag disk as having been modified exit: if (iRetCode != 0) { // on error, 'eject' disk from drive dsk_eject(drive); } return iRetCode; } void tape_eject () { delete [] pbTapeImage; pbTapeImage = nullptr; } int snapshot_load (FILE *pfile) { int n; dword dwSnapSize, dwModel, dwFlags; byte val; reg_pair port; t_SNA_header sh; memset(&sh, 0, sizeof(sh)); if(fread(&sh, sizeof(sh), 1, pfile) != 1) { // read snapshot header return ERR_SNA_INVALID; } if (memcmp(sh.id, "MV - SNA", 8) != 0) { // valid SNApshot image? return ERR_SNA_INVALID; } dwSnapSize = sh.ram_size[0] + (sh.ram_size[1] * 256); // memory dump size dwSnapSize &= ~0x3f; // limit to multiples of 64 if (!dwSnapSize) { return ERR_SNA_SIZE; } if (dwSnapSize > CPC.ram_size) { // memory dump size differs from current RAM size? byte *pbTemp; pbTemp = new byte [dwSnapSize*1024 + 1]; delete [] pbRAMbuffer; CPC.ram_size = dwSnapSize; pbRAMbuffer = pbTemp; // Ensure 1 byte is available before pbRAM as prerender_normal*_plus can read it pbRAM = pbRAMbuffer + 1; } emulator_reset(); n = fread(pbRAM, dwSnapSize*1024, 1, pfile); // read memory dump into CPC RAM if (!n) { emulator_reset(); return ERR_SNA_INVALID; } // Z80 z80.AF.b.h = sh.AF[1]; z80.AF.b.l = sh.AF[0]; z80.BC.b.h = sh.BC[1]; z80.BC.b.l = sh.BC[0]; z80.DE.b.h = sh.DE[1]; z80.DE.b.l = sh.DE[0]; z80.HL.b.h = sh.HL[1]; z80.HL.b.l = sh.HL[0]; z80.R = sh.R & 0x7f; z80.Rb7 = sh.R & 0x80; // bit 7 of R z80.I = sh.I; if (sh.IFF0) z80.IFF1 = Pflag; if (sh.IFF1) z80.IFF2 = Pflag; z80.IX.b.h = sh.IX[1]; z80.IX.b.l = sh.IX[0]; z80.IY.b.h = sh.IY[1]; z80.IY.b.l = sh.IY[0]; z80.SP.b.h = sh.SP[1]; z80.SP.b.l = sh.SP[0]; z80.PC.b.h = sh.PC[1]; z80.PC.b.l = sh.PC[0]; z80.IM = sh.IM; // interrupt mode z80.AFx.b.h = sh.AFx[1]; z80.AFx.b.l = sh.AFx[0]; z80.BCx.b.h = sh.BCx[1]; z80.BCx.b.l = sh.BCx[0]; z80.DEx.b.h = sh.DEx[1]; z80.DEx.b.l = sh.DEx[0]; z80.HLx.b.h = sh.HLx[1]; z80.HLx.b.l = sh.HLx[0]; // Gate Array port.b.h = 0x7f; for (n = 0; n < 17; n++) { // loop for all colours + border GateArray.pen = n; val = sh.ga_ink_values[n]; // GA palette entry z80_OUT_handler(port, val | (1<<6)); } val = sh.ga_pen; // GA pen z80_OUT_handler(port, (val & 0x3f)); val = sh.ga_ROM_config; // GA ROM configuration z80_OUT_handler(port, (val & 0x3f) | (2<<6)); val = sh.ga_RAM_config; // GA RAM configuration z80_OUT_handler(port, (val & 0x3f) | (3<<6)); // CRTC port.b.h = 0xbd; for (n = 0; n < 18; n++) { // loop for all CRTC registers val = sh.crtc_registers[n]; CRTC.reg_select = n; z80_OUT_handler(port, val); } port.b.h = 0xbc; val = sh.crtc_reg_select; // CRTC register select z80_OUT_handler(port, val); // ROM select port.b.h = 0xdf; val = sh.upper_ROM; // upper ROM number z80_OUT_handler(port, val); // PPI port.b.h = 0xf4; // port A z80_OUT_handler(port, sh.ppi_A); port.b.h = 0xf5; // port B z80_OUT_handler(port, sh.ppi_B); port.b.h = 0xf6; // port C z80_OUT_handler(port, sh.ppi_C); port.b.h = 0xf7; // control z80_OUT_handler(port, sh.ppi_control); // PSG PSG.control = PPI.portC; PSG.reg_select = sh.psg_reg_select; for (n = 0; n < 16; n++) { // loop for all PSG registers SetAYRegister(n, sh.psg_registers[n]); } if (sh.version > 1) { // does the snapshot have version 2 data? dwModel = sh.cpc_model; // determine the model it was saved for if (dwModel != CPC.model) { // different from what we're currently running? if (dwModel > 3) { // not one of the known models? emulator_reset(); return ERR_SNA_CPC_TYPE; } std::string romFilename = CPC.rom_path + "/" + chROMFile[dwModel]; if ((pfileObject = fopen(romFilename.c_str(), "rb")) != nullptr) { n = fread(pbROM, 2*16384, 1, pfileObject); fclose(pfileObject); if (!n) { emulator_reset(); return ERR_CPC_ROM_MISSING; } CPC.model = dwModel; } else { // ROM image load failed emulator_reset(); return ERR_CPC_ROM_MISSING; } } } if (sh.version > 2) { // does the snapshot have version 3 data? FDC.motor = sh.fdc_motor; driveA.current_track = sh.drvA_current_track; driveB.current_track = sh.drvB_current_track; CPC.printer_port = sh.printer_data ^ 0x80; // invert bit 7 again PSG.AmplitudeEnv = sh.psg_env_step << 1; // multiply by 2 to bring it into the 0 - 30 range PSG.FirstPeriod = false; if (sh.psg_env_direction == 0x01) { // up switch (PSG.RegisterAY.EnvType) { case 4: case 5: case 6: case 7: case 13: case 14: case 15: PSG.FirstPeriod = true; break; } } else if (sh.psg_env_direction == 0xff) { // down switch (PSG.RegisterAY.EnvType) { case 0: case 1: case 2: case 3: case 9: case 10: case 11: PSG.FirstPeriod = true; break; } } CRTC.addr = sh.crtc_addr[0] + (sh.crtc_addr[1] * 256); VDU.scanline = sh.crtc_scanline[0] + (sh.crtc_scanline[1] * 256); if (VDU.scanline > MaxVSync) { VDU.scanline = MaxVSync; // limit to max value } CRTC.char_count = sh.crtc_char_count[0]; CRTC.line_count = sh.crtc_line_count & 127; CRTC.raster_count = sh.crtc_raster_count & 31; CRTC.hsw_count = sh.crtc_hsw_count & 15; CRTC.vsw_count = sh.crtc_vsw_count & 15; dwFlags = sh.crtc_flags[0] + (sh.crtc_flags[1] * 256); CRTC.flag_invsync = dwFlags & 1 ? 1 : 0; // vsync active? if (dwFlags & 2) { // hsync active? flags1.inHSYNC = 0xff; CRTC.flag_hadhsync = 1; if ((CRTC.hsw_count >= 3) && (CRTC.hsw_count < 7)) { CRTC.flag_inmonhsync = 1; } } CRTC.flag_invta = dwFlags & 0x80 ? 1 : 0; // in vertical total adjust? GateArray.hs_count = sh.ga_int_delay & 3; GateArray.sl_count = sh.ga_sl_count; z80.int_pending = sh.z80_int_pending; } return 0; } int snapshot_load (const std::string &filename) { if ((pfileObject = fopen(filename.c_str(), "rb")) != nullptr) { return snapshot_load(pfileObject); } return ERR_FILE_NOT_FOUND; } int tape_insert (FILE *pfile) { tape_eject(); if(fread(pbGPBuffer, 10, 1, pfile) != 1) { // read beginning of header return ERR_TAP_INVALID; } // Reset so that the next method can recheck the header fseek(pfile, 0, SEEK_SET); byte *pbPtr = pbGPBuffer; if (memcmp(pbPtr, "ZXTape!\032", 8) == 0) { // CDT file? LOG_DEBUG("tape_insert CDT file"); return tape_insert_cdt(pfile); } if (memcmp(pbPtr, "Creative", 8) == 0) { // VOC file ? LOG_DEBUG("tape_insert VOC file"); return tape_insert_voc(pfile); } // Unknown file LOG_DEBUG("tape_insert unknown file"); return ERR_TAP_INVALID; } int tape_insert (const std::string &filename) { LOG_DEBUG("tape_insert " << filename); FILE *pfile; if ((pfile = fopen(filename.c_str(), "rb")) == nullptr) { return ERR_FILE_NOT_FOUND; } int iRetCode = tape_insert(pfile); fclose(pfile); return iRetCode; } int tape_insert_cdt (FILE *pfile) { long lFileSize; int iBlockLength; byte bID; byte *pbPtr, *pbBlock; if(fread(pbGPBuffer, 10, 1, pfile) != 1) { // read CDT header LOG_DEBUG("Couldn't read CDT header"); return ERR_TAP_INVALID; } pbPtr = pbGPBuffer; if (memcmp(pbPtr, "ZXTape!\032", 8) != 0) { // valid CDT file? LOG_DEBUG("Invalid CDT header '" << pbPtr << "'"); return ERR_TAP_INVALID; } if (*(pbPtr + 0x08) != 1) { // major version must be 1 LOG_DEBUG("Invalid CDT major version"); return ERR_TAP_INVALID; } lFileSize = file_size(fileno(pfile)) - 0x0a; if (lFileSize <= 0) { // the tape image should have at least one block... LOG_DEBUG("Invalid CDT file size"); return ERR_TAP_INVALID; } pbTapeImage = new byte[lFileSize+6]; *pbTapeImage = 0x20; // start off with a pause block *reinterpret_cast<word *>(pbTapeImage+1) = 2000; // set the length to 2 seconds if(fread(pbTapeImage+3, lFileSize, 1, pfile) != 1) { // append the entire CDT file LOG_DEBUG("Couldn't read CDT file"); return ERR_TAP_INVALID; } *(pbTapeImage+lFileSize+3) = 0x20; // end with a pause block *reinterpret_cast<word *>(pbTapeImage+lFileSize+3+1) = 2000; // set the length to 2 seconds #ifdef DEBUG_TAPE fputs("--- New Tape\r\n", pfoDebug); #endif pbTapeImageEnd = pbTapeImage + lFileSize+6; pbBlock = pbTapeImage; bool bolGotDataBlock = false; while (pbBlock < pbTapeImageEnd) { bID = *pbBlock++; switch(bID) { case 0x10: // standard speed data block iBlockLength = *reinterpret_cast<word *>(pbBlock+2) + 4; bolGotDataBlock = true; break; case 0x11: // turbo loading data block iBlockLength = (*reinterpret_cast<dword *>(pbBlock+0x0f) & 0x00ffffff) + 0x12; bolGotDataBlock = true; break; case 0x12: // pure tone iBlockLength = 4; bolGotDataBlock = true; break; case 0x13: // sequence of pulses of different length iBlockLength = *pbBlock * 2 + 1; bolGotDataBlock = true; break; case 0x14: // pure data block iBlockLength = (*reinterpret_cast<dword *>(pbBlock+0x07) & 0x00ffffff) + 0x0a; bolGotDataBlock = true; break; case 0x15: // direct recording iBlockLength = (*reinterpret_cast<dword *>(pbBlock+0x05) & 0x00ffffff) + 0x08; bolGotDataBlock = true; break; case 0x20: // pause if ((!bolGotDataBlock) && (pbBlock != pbTapeImage+1)) { *reinterpret_cast<word *>(pbBlock) = 0; // remove any pauses (execept ours) before the data starts } iBlockLength = 2; break; case 0x21: // group start iBlockLength = *pbBlock + 1; break; case 0x22: // group end iBlockLength = 0; break; case 0x23: // jump to block LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = 2; break; case 0x24: // loop start LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = 2; break; case 0x25: // loop end LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = 0; break; case 0x26: // call sequence LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = (*reinterpret_cast<word *>(pbBlock) * 2) + 2; break; case 0x27: // return from sequence LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = 0; break; case 0x28: // select block LOG_DEBUG("Couldn't load CDT file: unsupported " << bID); return ERR_TAP_UNSUPPORTED; iBlockLength = *reinterpret_cast<word *>(pbBlock) + 2; break; case 0x30: // text description iBlockLength = *pbBlock + 1; break; case 0x31: // message block iBlockLength = *(pbBlock+1) + 2; break; case 0x32: // archive info iBlockLength = *reinterpret_cast<word *>(pbBlock) + 2; break; case 0x33: // hardware type iBlockLength = (*pbBlock * 3) + 1; break; case 0x34: // emulation info iBlockLength = 8; break; case 0x35: // custom info block iBlockLength = *reinterpret_cast<dword *>(pbBlock+0x10) + 0x14; break; case 0x40: // snapshot block iBlockLength = (*reinterpret_cast<dword *>(pbBlock+0x01) & 0x00ffffff) + 0x04; break; case 0x5A: // another tzx/cdt file iBlockLength = 9; break; default: // "extension rule" iBlockLength = *reinterpret_cast<dword *>(pbBlock) + 4; } #ifdef DEBUG_TAPE fprintf(pfoDebug, "%02x %d\r\n", bID, iBlockLength); #endif pbBlock += iBlockLength; } if (pbBlock != pbTapeImageEnd) { LOG_DEBUG("CDT file error: Didn't reach end of tape"); tape_eject(); return ERR_TAP_INVALID; } Tape_Rewind(); return 0; } int tape_insert_voc (FILE *pfile) { long lFileSize, lOffset, lInitialOffset, lSampleLength; int iBlockLength; byte *pbPtr, *pbTapeImagePtr, *pbVocDataBlock, *pbVocDataBlockPtr; bool bolDone; tape_eject(); if(fread(pbGPBuffer, 26, 1, pfile) != 1) { // read VOC header return ERR_TAP_BAD_VOC; } pbPtr = pbGPBuffer; if (memcmp(pbPtr, "Creative Voice File\032", 20) != 0) { // valid VOC file? return ERR_TAP_BAD_VOC; } lOffset = lInitialOffset = *reinterpret_cast<word *>(pbPtr + 0x14); lFileSize = file_size(fileno(pfile)); if ((lFileSize-26) <= 0) { // should have at least one block... return ERR_TAP_BAD_VOC; } #ifdef DEBUG_TAPE fputs("--- New Tape\r\n", pfoDebug); #endif iBlockLength = 0; lSampleLength = 0; byte bSampleRate = 0; bolDone = false; while ((!bolDone) && (lOffset < lFileSize)) { fseek(pfile, lOffset, SEEK_SET); if(fread(pbPtr, 16, 1, pfile) != 1) { // read block ID + size return ERR_TAP_BAD_VOC; } #ifdef DEBUG_TAPE fprintf(pfoDebug, "%02x %d\r\n", *pbPtr, *(dword *)(pbPtr+0x01) & 0x00ffffff); #endif switch(*pbPtr) { case 0x0: // terminator bolDone = true; break; case 0x1: // sound data iBlockLength = (*reinterpret_cast<dword *>(pbPtr+0x01) & 0x00ffffff) + 4; lSampleLength += iBlockLength - 6; if ((bSampleRate) && (bSampleRate != *(pbPtr+0x04))) { // no change in sample rate allowed return ERR_TAP_BAD_VOC; } bSampleRate = *(pbPtr+0x04); if (*(pbPtr+0x05) != 0) { // must be 8 bits wide return ERR_TAP_BAD_VOC; } break; case 0x2: // sound continue iBlockLength = (*reinterpret_cast<dword *>(pbPtr+0x01) & 0x00ffffff) + 4; lSampleLength += iBlockLength - 4; break; case 0x3: // silence iBlockLength = 4; lSampleLength += *reinterpret_cast<word *>(pbPtr+0x01) + 1; if ((bSampleRate) && (bSampleRate != *(pbPtr+0x03))) { // no change in sample rate allowed return ERR_TAP_BAD_VOC; } bSampleRate = *(pbPtr+0x03); break; case 0x4: // marker iBlockLength = 3; break; case 0x5: // ascii iBlockLength = (*reinterpret_cast<dword *>(pbPtr+0x01) & 0x00ffffff) + 4; break; default: return ERR_TAP_BAD_VOC; } lOffset += iBlockLength; } #ifdef DEBUG_TAPE fprintf(pfoDebug, "--- %ld bytes\r\n", lSampleLength); #endif dword dwTapePulseCycles = 3500000L / (1000000L / (256 - bSampleRate)); // length of one pulse in ZX Spectrum T states dword dwCompressedSize = lSampleLength >> 3; // 8x data reduction if (dwCompressedSize > 0x00ffffff) { // we only support one direct recording block right now return ERR_TAP_BAD_VOC; } pbTapeImage = new byte[dwCompressedSize+1+8+6]; *pbTapeImage = 0x20; // start off with a pause block *reinterpret_cast<word *>(pbTapeImage+1) = 2000; // set the length to 2 seconds *(pbTapeImage+3) = 0x15; // direct recording block *reinterpret_cast<word *>(pbTapeImage+4) = static_cast<word>(dwTapePulseCycles); // number of T states per sample *reinterpret_cast<word *>(pbTapeImage+6) = 0; // pause after block *(pbTapeImage+8) = lSampleLength & 7 ? lSampleLength & 7 : 8; // bits used in last byte *reinterpret_cast<dword *>(pbTapeImage+9) = dwCompressedSize & 0x00ffffff; // data length pbTapeImagePtr = pbTapeImage + 12; lOffset = lInitialOffset; bolDone = false; dword dwBit = 8; byte bByte = 0; while ((!bolDone) && (lOffset < lFileSize)) { fseek(pfile, lOffset, SEEK_SET); if(fread(pbPtr, 1, 1, pfile) != 1) { // read block ID return ERR_TAP_BAD_VOC; } switch(*pbPtr) { case 0x0: // terminator bolDone = true; break; case 0x1: // sound data if(fread(pbPtr, 3+2, 1, pfile) != 1) { // get block size and sound info return ERR_TAP_BAD_VOC; } iBlockLength = (*reinterpret_cast<dword *>(pbPtr) & 0x00ffffff) + 4; lSampleLength = iBlockLength - 6; pbVocDataBlock = new byte[lSampleLength]; if(fread(pbVocDataBlock, lSampleLength, 1, pfile) != 1) { return ERR_TAP_BAD_VOC; } pbVocDataBlockPtr = pbVocDataBlock; for (int iBytePos = 0; iBytePos < lSampleLength; iBytePos++) { byte bVocSample = *pbVocDataBlockPtr++; dwBit--; if (bVocSample > VOC_THRESHOLD) { bByte |= bit_values[dwBit]; } if (!dwBit) { // got all 8 bits? *pbTapeImagePtr++ = bByte; dwBit = 8; bByte = 0; } } delete [] pbVocDataBlock; break; case 0x2: // sound continue if(fread(pbPtr, 3, 1, pfile) != 1) { // get block size return ERR_TAP_BAD_VOC; } iBlockLength = (*reinterpret_cast<dword *>(pbPtr) & 0x00ffffff) + 4; lSampleLength = iBlockLength - 4; pbVocDataBlock = new byte[lSampleLength]; if(fread(pbVocDataBlock, lSampleLength, 1, pfile) != 1) { return ERR_TAP_BAD_VOC; } pbVocDataBlockPtr = pbVocDataBlock; for (int iBytePos = 0; iBytePos < lSampleLength; iBytePos++) { byte bVocSample = *pbVocDataBlockPtr++; dwBit--; if (bVocSample > VOC_THRESHOLD) { bByte |= bit_values[dwBit]; } if (!dwBit) { // got all 8 bits? *pbTapeImagePtr++ = bByte; dwBit = 8; bByte = 0; } } delete [] pbVocDataBlock; break; case 0x3: // silence iBlockLength = 4; lSampleLength = *reinterpret_cast<word *>(pbPtr) + 1; for (int iBytePos = 0; iBytePos < lSampleLength; iBytePos++) { dwBit--; if (!dwBit) { // got all 8 bits? *pbTapeImagePtr++ = bByte; dwBit = 8; bByte = 0; } } break; case 0x4: // marker iBlockLength = 3; break; case 0x5: // ascii iBlockLength = (*reinterpret_cast<dword *>(pbPtr) & 0x00ffffff) + 4; break; } lOffset += iBlockLength; } *pbTapeImagePtr = 0x20; // end with a pause block *reinterpret_cast<word *>(pbTapeImagePtr+1) = 2000; // set the length to 2 seconds pbTapeImageEnd = pbTapeImagePtr + 3; Tape_Rewind(); return 0; } void cartridge_load () { if (CPC.model >= 3) { if (file_load(CPC.cart_file, OTHER)) { fprintf(stderr, "Load of cartridge failed. Aborting.\n"); cleanExit(-1); } } } int cartridge_load (const std::string& filepath) { if (CPC.model >= 3) { return cpr_load(filepath); } return ERR_FILE_UNSUPPORTED; } int cartridge_load (FILE *file) { if (CPC.model >= 3) { return cpr_load(file); } return ERR_FILE_UNSUPPORTED; } // Still some duplication there... but it cannot really be helped int file_load(const std::string& filepath, const DRIVE drive) { if (filepath.length() < 4) return ERR_FILE_UNSUPPORTED; int pos = filepath.length() - 4; std::string extension = stringutils::lower(filepath.substr(pos)); FILE *file = nullptr; if (extension == ".zip") { zip::t_zip_info zip_info; zip_info.filename = filepath; zip_info.extensions = ".dsk.sna.cdt.voc.cpr.ipf"; if (zip::dir(&zip_info)) { // error or nothing relevant found LOG_ERROR("Error opening or parsing zip file " << filepath); return ERR_FILE_UNZIP_FAILED; } std::string filename = zip_info.filesOffsets[0].first; pos = filename.length() - 4; extension = stringutils::lower(filename.substr(pos)); // grab the extension in lowercases LOG_DEBUG("Extracting " << filepath << ", " << filename << ", " << extension); file = extractFile(filepath, filename, extension); } for(const auto& loader : files_loader_list) { if (drive == loader.drive && extension == loader.extension) { if (file) { return loader.load_from_file(file); } return loader.load_from_filename(filepath); } } LOG_ERROR("File format unsupported for " << filepath); return ERR_FILE_UNSUPPORTED; }
49,541
C++
.cpp
1,306
30.956355
184
0.591557
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,808
devtools.cpp
ColinPitrat_caprice32/src/devtools.cpp
#include "devtools.h" #include <string> #include "log.h" #include "video.h" #include "wg_error.h" bool DevTools::Activate(int scale) { ShowCursor(true); try { // TODO: This position only makes sense for me. Ideally we would probably want to find where current window is, find display size and place // the window where there's the most space available. On the other hand, getting display size is not very reliable on multi-screen setups under linux ... window = SDL_CreateWindow("Caprice32 - Developers' tools", 100, 100, DEVTOOLS_WIDTH*scale, DEVTOOLS_HEIGHT*scale, SDL_WINDOW_SHOWN); renderer = SDL_CreateRenderer(window, -1, 0); if (!window || !renderer) { Deactivate(); return false; } surface = SDL_CreateRGBSurface(0, DEVTOOLS_WIDTH, DEVTOOLS_HEIGHT, renderer_bpp(renderer), 0, 0, 0, 0); if (!surface) { Deactivate(); return false; } texture = SDL_CreateTextureFromSurface(renderer, surface); if (!texture) { Deactivate(); return false; } SDL_FillRect(surface, nullptr, SDL_MapRGB(surface->format, 0, 0, 0)); capriceGui = std::make_unique<CapriceGui>(window, /*bInMainView=*/false, scale); capriceGui->Init(); devToolsView = std::make_unique<CapriceDevToolsView>(*capriceGui, surface, renderer, texture, wGui::CRect(0, 0, DEVTOOLS_WIDTH, DEVTOOLS_HEIGHT), this); } catch(wGui::Wg_Ex_App& e) { // TODO: improve: this is pretty silent if people don't look at the console LOG_ERROR("Failed displaying developer's tools: " << e.what()); } active = true; return true; } void DevTools::Deactivate() { ShowCursor(false); devToolsView = nullptr; capriceGui = nullptr; if (texture) SDL_DestroyTexture(texture); if (surface) SDL_FreeSurface(surface); if (renderer) SDL_DestroyRenderer(renderer); if (window) SDL_DestroyWindow(window); texture = nullptr; surface = nullptr; renderer = nullptr; window = nullptr; active = false; } void DevTools::LoadSymbols(const std::string& filename) { devToolsView->LoadSymbols(filename); } void DevTools::PreUpdate() { devToolsView->PreUpdate(); } void DevTools::PostUpdate() { devToolsView->PostUpdate(); capriceGui->Update(); } bool DevTools::PassEvent(SDL_Event& event) { return capriceGui->ProcessEvent(event); }
2,266
C++
.cpp
55
38.072727
157
0.72323
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,809
psg.cpp
ColinPitrat_caprice32/src/psg.cpp
/* Caprice32 - Amstrad CPC Emulator (c) Copyright 1997-2004 Ulrich Doewich This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* General Instruments AY-3-8912 Programable Sound Generator converted from the AY Emulator project by Sergey Vladimirovich Bulba based on Version 2.7 beta 3 */ #include <math.h> #include <memory> #include "cap32.h" #include "z80.h" #include "log.h" extern t_CPC CPC; extern t_PSG PSG; extern dword freq_table[]; extern std::unique_ptr<byte[]> pbSndBuffer; extern byte *pbSndBufferEnd; extern byte bTapeLevel; #define TAPE_VOLUME 32 // Amplitude table (c)Hacker KAY word Amplitudes_AY[16] = { 0, 836, 1212, 1773, 2619, 3875, 5397, 8823, 10392, 16706, 23339, 29292, 36969, 46421, 55195, 65535 }; int Level_PP[256]; union TLoopCount { struct { dword Lo; dword Hi; }; int64_t Re; } LoopCount; int64_t LoopCountInit; bool Ton_EnA, Ton_EnB, Ton_EnC, Noise_EnA, Noise_EnB, Noise_EnC; bool Envelope_EnA, Envelope_EnB, Envelope_EnC; void (*Case_EnvType)(); union TCounter { struct { word Lo; word Hi; }; dword Re; }; TCounter Ton_Counter_A, Ton_Counter_B, Ton_Counter_C, Noise_Counter; union TNoise { struct { word Low; word Val; }; dword Seed; } Noise; union TEnvelopeCounter { struct { dword Lo; dword Hi; }; int64_t Re; } Envelope_Counter; byte Ton_A, Ton_B, Ton_C; int Level_AR[32], Level_AL[32], Level_BR[32], Level_BL[32], Level_CR[32], Level_CL[32]; int LevelTape; byte Index_AL, Index_AR, Index_BL, Index_BR, Index_CL, Index_CR; int PreAmp, PreAmpMax; int Left_Chan, Right_Chan; inline void SetMixerRegister(byte Value) { PSG.RegisterAY.Mixer = Value; Ton_EnA = !(Value & 1); Noise_EnA = !(Value & 8); Ton_EnB = !(Value & 2); Noise_EnB = !(Value & 16); Ton_EnC = !(Value & 4); Noise_EnC = !(Value & 32); } inline void SetAmplA(byte Value) { PSG.RegisterAY.AmplitudeA = Value; Envelope_EnA = !(Value & 16); } inline void SetAmplB(byte Value) { PSG.RegisterAY.AmplitudeB = Value; Envelope_EnB = !(Value & 16); } inline void SetAmplC(byte Value) { PSG.RegisterAY.AmplitudeC = Value; Envelope_EnC = !(Value & 16); } void Case_EnvType_0_3__9() { if (PSG.FirstPeriod) { PSG.AmplitudeEnv--; if (!PSG.AmplitudeEnv) { PSG.FirstPeriod = false; } } } void Case_EnvType_4_7__15() { if (PSG.FirstPeriod) { PSG.AmplitudeEnv++; if (PSG.AmplitudeEnv == 32) { PSG.FirstPeriod = false; PSG.AmplitudeEnv = 0; } } } void Case_EnvType_8() { PSG.AmplitudeEnv = (PSG.AmplitudeEnv - 1) & 31; } void Case_EnvType_10() { if (PSG.FirstPeriod) { PSG.AmplitudeEnv--; if (PSG.AmplitudeEnv == -1) { PSG.FirstPeriod = false; PSG.AmplitudeEnv = 0; } } else { PSG.AmplitudeEnv++; if (PSG.AmplitudeEnv == 32) { PSG.FirstPeriod = true; PSG.AmplitudeEnv = 31; } } } void Case_EnvType_11() { if (PSG.FirstPeriod) { PSG.AmplitudeEnv--; if (PSG.AmplitudeEnv == -1) { PSG.FirstPeriod = false; PSG.AmplitudeEnv = 31; } } } void Case_EnvType_12() { PSG.AmplitudeEnv = (PSG.AmplitudeEnv + 1) & 31; } void Case_EnvType_13() { if (PSG.FirstPeriod) { PSG.AmplitudeEnv++; if (PSG.AmplitudeEnv == 32) { PSG.FirstPeriod = false; PSG.AmplitudeEnv = 31; } } } void Case_EnvType_14() { if (!PSG.FirstPeriod) { PSG.AmplitudeEnv--; if (PSG.AmplitudeEnv == -1) { PSG.FirstPeriod = true; PSG.AmplitudeEnv = 0; } } else { PSG.AmplitudeEnv++; if (PSG.AmplitudeEnv == 32) { PSG.FirstPeriod = false; PSG.AmplitudeEnv = 31; } } } inline void SetEnvelopeRegister(byte Value) { Envelope_Counter.Hi = 0; PSG.FirstPeriod = true; if (!(Value & 4)) { PSG.AmplitudeEnv = 32; } else { PSG.AmplitudeEnv = -1; } PSG.RegisterAY.EnvType = Value; switch (Value) { case 0: case 1: case 2: case 3: case 9: Case_EnvType = Case_EnvType_0_3__9; break; case 4: case 5: case 6: case 7: case 15: Case_EnvType = Case_EnvType_4_7__15; break; case 8: Case_EnvType = Case_EnvType_8; break; case 10: Case_EnvType = Case_EnvType_10; break; case 11: Case_EnvType = Case_EnvType_11; break; case 12: Case_EnvType = Case_EnvType_12; break; case 13: Case_EnvType = Case_EnvType_13; break; case 14: Case_EnvType = Case_EnvType_14; break; } } void SetAYRegister(int Num, byte Value) { switch(Num) { case 13: SetEnvelopeRegister(Value & 15); break; case 1: case 3: case 5: PSG.RegisterAY.Index[Num] = Value & 15; break; case 6: PSG.RegisterAY.Noise = Value & 31; break; case 7: SetMixerRegister(Value & 63); break; case 8: SetAmplA(Value & 31); break; case 9: SetAmplB(Value & 31); break; case 10: SetAmplC(Value & 31); break; case 0: case 2: case 4: case 11: case 12: PSG.RegisterAY.Index[Num] = Value; break; } } inline void Synthesizer_Logic_Q() { Ton_Counter_A.Hi++; if (Ton_Counter_A.Hi >= PSG.RegisterAY.TonA) { Ton_Counter_A.Hi = 0; Ton_A ^= 1; } Ton_Counter_B.Hi++; if (Ton_Counter_B.Hi >= PSG.RegisterAY.TonB) { Ton_Counter_B.Hi = 0; Ton_B ^= 1; } Ton_Counter_C.Hi++; if (Ton_Counter_C.Hi >= PSG.RegisterAY.TonC) { Ton_Counter_C.Hi = 0; Ton_C ^= 1; } Noise_Counter.Hi++; if ((!(Noise_Counter.Hi & 1)) && (Noise_Counter.Hi >= (PSG.RegisterAY.Noise << 1))) { Noise_Counter.Hi = 0; Noise.Seed = (((((Noise.Seed >> 13) ^ (Noise.Seed >> 16)) & 1) ^ 1) | Noise.Seed << 1) & 0x1ffff; } if (!Envelope_Counter.Hi) { Case_EnvType(); } Envelope_Counter.Hi++; if (Envelope_Counter.Hi >= PSG.RegisterAY.Envelope) { Envelope_Counter.Hi = 0; } } inline void Synthesizer_Mixer_Q() { int LevL, LevR, k; LevL = bTapeLevel ? LevelTape : 0; // start with the tape signal if (CPC.snd_pp_device) { LevL += Level_PP[CPC.printer_port]; } LevR = LevL; if (Ton_EnA) { if ((!Envelope_EnA) || (PSG.RegisterAY.TonA > 4)) { k = Ton_A; } else { k = 1; } } else { k = 1; } if (Noise_EnA) { k &= Noise.Val; } if (k) { if (Envelope_EnA) { LevL += Level_AL[PSG.RegisterAY.AmplitudeA * 2 + 1]; LevR += Level_AR[PSG.RegisterAY.AmplitudeA * 2 + 1]; } else { LevL += Level_AL[PSG.AmplitudeEnv]; LevR += Level_AR[PSG.AmplitudeEnv]; } } if (Ton_EnB) { if ((!Envelope_EnB) || (PSG.RegisterAY.TonB > 4)) { k = Ton_B; } else { k = 1; } } else { k = 1; } if (Noise_EnB) { k &= Noise.Val; } if (k) { if (Envelope_EnB) { LevL += Level_BL[PSG.RegisterAY.AmplitudeB * 2 + 1]; LevR += Level_BR[PSG.RegisterAY.AmplitudeB * 2 + 1]; } else { LevL += Level_BL[PSG.AmplitudeEnv]; LevR += Level_BR[PSG.AmplitudeEnv]; } } if (Ton_EnC) { if ((!Envelope_EnC) || (PSG.RegisterAY.TonC > 4)) { k = Ton_C; } else { k = 1; } } else { k = 1; } if (Noise_EnC) { k &= Noise.Val; } if (k) { if (Envelope_EnC) { LevL += Level_CL[PSG.RegisterAY.AmplitudeC * 2 + 1]; LevR += Level_CR[PSG.RegisterAY.AmplitudeC * 2 + 1]; } else { LevL += Level_CL[PSG.AmplitudeEnv]; LevR += Level_CR[PSG.AmplitudeEnv]; } } Left_Chan += LevL; Right_Chan += LevR; } void Synthesizer_Stereo16() { int Tick_Counter = 0; while (LoopCount.Hi) { Synthesizer_Logic_Q(); Synthesizer_Mixer_Q(); Tick_Counter++; LoopCount.Hi--; } LoopCount.Re += LoopCountInit; reg_pair val; val.w.l = Left_Chan / Tick_Counter; val.w.h = Right_Chan / Tick_Counter; *reinterpret_cast<dword *>(CPC.snd_bufferptr) = val.d; // write to mixing buffer CPC.snd_bufferptr += 4; Left_Chan = 0; Right_Chan = Left_Chan; if (CPC.snd_bufferptr >= pbSndBufferEnd) { CPC.snd_bufferptr = pbSndBuffer.get(); PSG.buffer_full = 1; } } void Synthesizer_Stereo8() { int Tick_Counter = 0; while (LoopCount.Hi) { Synthesizer_Logic_Q(); Synthesizer_Mixer_Q(); Tick_Counter++; LoopCount.Hi--; } LoopCount.Re += LoopCountInit; reg_pair val; val.b.l = 128 + Left_Chan / Tick_Counter; val.b.h = 128 + Right_Chan / Tick_Counter; *reinterpret_cast<word *>(CPC.snd_bufferptr) = val.w.l; // write to mixing buffer CPC.snd_bufferptr += 2; Left_Chan = 0; Right_Chan = Left_Chan; if (CPC.snd_bufferptr >= pbSndBufferEnd) { CPC.snd_bufferptr = pbSndBuffer.get(); PSG.buffer_full = 1; } } inline void Synthesizer_Mixer_Q_Mono() { int Lev, k; Lev = bTapeLevel ? LevelTape : 0; // start with the tape signal if (CPC.snd_pp_device) { Lev += Level_PP[CPC.printer_port]; } if (Ton_EnA) { if ((!Envelope_EnA) || (PSG.RegisterAY.TonA > 4)) { k = Ton_A; } else { k = 1; } } else { k = 1; } if (Noise_EnA) { k &= Noise.Val; } if (k) { if (Envelope_EnA) { Lev += Level_AL[PSG.RegisterAY.AmplitudeA * 2 + 1]; } else { Lev += Level_AL[PSG.AmplitudeEnv]; } } if (Ton_EnB) { if ((!Envelope_EnB) || (PSG.RegisterAY.TonB > 4)) { k = Ton_B; } else { k = 1; } } else { k = 1; } if (Noise_EnB) { k &= Noise.Val; } if (k) { if (Envelope_EnB) { Lev += Level_BL[PSG.RegisterAY.AmplitudeB * 2 + 1]; } else { Lev += Level_BL[PSG.AmplitudeEnv]; } } if (Ton_EnC) { if ((!Envelope_EnC) || (PSG.RegisterAY.TonC > 4)) { k = Ton_C; } else { k = 1; } } else { k = 1; } if (Noise_EnC) { k &= Noise.Val; } if (k) { if (Envelope_EnC) { Lev += Level_CL[PSG.RegisterAY.AmplitudeC * 2 + 1]; } else { Lev += Level_CL[PSG.AmplitudeEnv]; } } Left_Chan += Lev; } void Synthesizer_Mono16() { int Tick_Counter = 0; while (LoopCount.Hi) { Synthesizer_Logic_Q(); Synthesizer_Mixer_Q_Mono(); Tick_Counter++; LoopCount.Hi--; } LoopCount.Re += LoopCountInit; *reinterpret_cast<word *>(CPC.snd_bufferptr) = Left_Chan / Tick_Counter; // write to mixing buffer CPC.snd_bufferptr += 2; Left_Chan = 0; if (CPC.snd_bufferptr >= pbSndBufferEnd) { CPC.snd_bufferptr = pbSndBuffer.get(); PSG.buffer_full = 1; } } void Synthesizer_Mono8() { int Tick_Counter = 0; while (LoopCount.Hi) { Synthesizer_Logic_Q(); Synthesizer_Mixer_Q_Mono(); Tick_Counter++; LoopCount.Hi--; } LoopCount.Re += LoopCountInit; *reinterpret_cast<byte *>(CPC.snd_bufferptr) = 128 + Left_Chan / Tick_Counter; // write to mixing buffer CPC.snd_bufferptr++; Left_Chan = 0; if (CPC.snd_bufferptr >= pbSndBufferEnd) { CPC.snd_bufferptr = pbSndBuffer.get(); PSG.buffer_full = 1; } } void Calculate_Level_Tables() { int i, b, l, r; int Index_A, Index_B, Index_C; double k; Index_A = Index_AL; Index_B = Index_BL; Index_C = Index_CL; l = Index_A + Index_B + Index_C; r = Index_AR + Index_BR + Index_CR; if (CPC.snd_stereo) { if (l < r) { l = r; } } else { l += r; Index_A += Index_AR; Index_B += Index_BR; Index_C += Index_CR; } if (l == 0) { l++; } if (!CPC.snd_bits) { // 8 bits per sample? r = 127; } else { r = 32767; } l = 255 * r / l; for (i = 0; i < 16; i++) { b = static_cast<int>(rint(Index_A / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_AL[i * 2] = b; Level_AL[i * 2 + 1] = b; b = static_cast<int>(rint(Index_AR / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_AR[i * 2] = b; Level_AR[i * 2 + 1] = b; b = static_cast<int>(rint(Index_B / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_BL[i * 2] = b; Level_BL[i * 2 + 1] = b; b = static_cast<int>(rint(Index_BR / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_BR[i * 2] = b; Level_BR[i * 2 + 1] = b; b = static_cast<int>(rint(Index_C / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_CL[i * 2] = b; Level_CL[i * 2 + 1] = b; b = static_cast<int>(rint(Index_CR / 255.0 * Amplitudes_AY[i])); b = static_cast<int>(rint(b / 65535.0 * l)); Level_CR[i * 2] = b; Level_CR[i * 2 + 1] = b; } k = exp(CPC.snd_volume * log(2) / PreAmpMax) - 1; for (i = 0; i < 32; i++) { Level_AL[i] = static_cast<int>(rint(Level_AL[i] * k)); Level_AR[i] = static_cast<int>(rint(Level_AR[i] * k)); Level_BL[i] = static_cast<int>(rint(Level_BL[i] * k)); Level_BR[i] = static_cast<int>(rint(Level_BR[i] * k)); Level_CL[i] = static_cast<int>(rint(Level_CL[i] * k)); Level_CR[i] = static_cast<int>(rint(Level_CR[i] * k)); } if (!CPC.snd_bits) { // 8 bits per sample? LevelTape = -static_cast<int>(rint((TAPE_VOLUME / 2) * k)); } else { LevelTape = -static_cast<int>(rint((TAPE_VOLUME * 128) * k)); } for (i = 0, b = 255; i < 256; i++) { // calculate the 256 levels of the Digiblaster/Soundplayer Level_PP[i] = -static_cast<int>(rint(((b << 8) / 65535.0 * l) * k)); b--; } } void ResetAYChipEmulation() { Ton_Counter_A.Re = 0; Ton_Counter_B.Re = 0; Ton_Counter_C.Re = 0; Noise_Counter.Re = 0; Envelope_Counter.Re = 0; Ton_A = 0; Ton_B = 0; Ton_C = 0; Left_Chan = 0; Right_Chan = 0; Noise.Seed = 0xffff; } void InitAYCounterVars() { CPC.snd_cycle_count_init.both = static_cast<int64_t>(rint((4000000 * ((CPC.speed * 25) / 100.0)) / freq_table[CPC.snd_playback_rate] * 4294967296.0)); // number of Z80 cycles per sample LoopCountInit = static_cast<int64_t>(rint(1000000.0 / (4000000.0 * ((CPC.speed * 25) / 100.0)) / 8.0 * CPC.snd_cycle_count_init.both)); // number of AY counter increments per sample LOG_INFO("Timing: CPC.speed: " << CPC.speed << " - freq: " << freq_table[CPC.snd_playback_rate]); LOG_INFO("Timing: z80 cycles per sample: " << CPC.snd_cycle_count_init.both/4294967296.0 << " - LoopCountInit: " << LoopCountInit/4294967296.0); LoopCount.Re = LoopCountInit; } void InitAY() { Index_AL = 255; Index_AR = 13; Index_BL = 170; Index_BR = 170; Index_CL = 13; Index_CR = 255; PreAmpMax = 100; Calculate_Level_Tables(); InitAYCounterVars(); ResetAYChipEmulation(); if (CPC.snd_stereo) { // stereo mode? if (CPC.snd_bits) { // 16 bits per sample? PSG.Synthesizer = Synthesizer_Stereo16; } else { // 8 bits PSG.Synthesizer = Synthesizer_Stereo8; } } else { // mono if (CPC.snd_bits) { // 16 bits per sample? PSG.Synthesizer = Synthesizer_Mono16; } else { // 8 bits PSG.Synthesizer = Synthesizer_Mono8; } } }
16,582
C++
.cpp
662
19.697885
147
0.570345
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
true
false
false
true
false
false
753,810
stringutils.cpp
ColinPitrat_caprice32/src/stringutils.cpp
#include "stringutils.h" #include <algorithm> #include <cstring> #include <sstream> #include <string> namespace stringutils { std::vector<std::string> split(const std::string& s, char delim, bool ignore_empty) { std::vector<std::string> elems; std::stringstream ss(s); std::string item; while (std::getline(ss, item, delim)) { if (ignore_empty && item.empty()) continue; elems.push_back(item); } return elems; } std::string join(const std::vector<std::string>& v, const std::string& delim) { std::string result; for(auto it = v.begin(); it != v.end(); ++it) { result += *it; if (it != v.end() - 1) result += delim; } return result; } std::string trim(const std::string& s, char c) { auto b = s.begin(); auto e = s.end(); e--; while(*b == c) b++; while(*e == c) e--; if(e++ >= b) return std::string(b, e); return ""; } std::string lower(const std::string& s) { std::string result(s); std::transform(result.begin(), result.end(), result.begin(), ::tolower); return result; } std::string upper(const std::string& s) { std::string result(s); std::transform(result.begin(), result.end(), result.begin(), ::toupper); return result; } std::string replace(std::string s, const std::string& search, const std::string& replace) { auto start_pos = s.find(search); if (start_pos == std::string::npos) return s; return s.replace(start_pos, search.size(), replace); } void splitPath(const std::string& path, std::string& dirname, std::string& filename) { auto delimiter = path.rfind('/'); if(delimiter == std::string::npos) { delimiter = path.rfind('\\'); } if(delimiter != std::string::npos) { delimiter++; dirname = path.substr(0, delimiter); filename = path.substr(delimiter); } else { dirname = "./"; filename = path; } } bool caseInsensitiveCompare(const std::string& str1, const std::string& str2) { return strncasecmp(str1.c_str(), str2.c_str(), std::max(str1.size(), str2.size())) < 0; } }
2,164
C++
.cpp
77
23.467532
91
0.604427
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
753,811
argparse.cpp
ColinPitrat_caprice32/src/argparse.cpp
#include "argparse.h" #include <getopt.h> #include <iostream> #include <fstream> #include <map> #include <string> #include "SDL.h" #include "cap32.h" #include "keyboard.h" #include "stringutils.h" #include "log.h" #include "video.h" #include "glfuncs.h" // For HAVE_GL const struct option long_options[] = { {"autocmd", required_argument, nullptr, 'a'}, {"cfg_file", required_argument, nullptr, 'c'}, {"inject", required_argument, nullptr, 'i'}, {"offset", required_argument, nullptr, 'o'}, {"override", required_argument, nullptr, 'O'}, {"sym_file", required_argument, nullptr, 's'}, {"version", no_argument, nullptr, 'V'}, {"help", no_argument, nullptr, 'h'}, {"verbose", no_argument, nullptr, 'v'}, {nullptr, 0, nullptr, 0}, }; void usage(std::ostream &os, char *progPath, int errcode) { std::string progname, dirname; stringutils::splitPath(progPath, dirname, progname); os << "Usage: " << progname << " [options] <slotfile(s)>\n"; os << "\nSupported options are:\n"; os << " -a/--autocmd=<command>: execute command as soon as the emulator starts.\n"; os << " -c/--cfg_file=<file>: use <file> as the emulator configuration file instead of the default.\n"; os << " -h/--help: shows this help\n"; os << " -i/--inject=<file>: inject a binary in memory after the CPC startup finishes\n"; os << " -o/--offset=<address>: offset at which to inject the binary provided with -i (default: 0x6000)\n"; os << " -O/--override: override an option from the config. Can be repeated. (example: -O system.model=3)\n"; os << " -s/--sym_file=<file>: use <file> as a source of symbols and entry points for disassembling in developers' tools.\n"; os << " -V/--version: outputs version and exit\n"; os << " -v/--verbose: be talkative\n"; os << "\nslotfiles is an optional list of files giving the content of the various CPC ports.\n"; os << "Ports files are identified by their extension. Supported formats are .dsk (disk), .cdt or .voc (tape), .cpr (cartridge), .sna (snapshot), or .zip (archive containing one or more of the supported ports files).\n"; os << "\nExample: " << progname << " sorcery.dsk\n"; os << "\nPress F1 when the emulator is running to show the in-application option menu.\n"; os << "\nSee https://github.com/ColinPitrat/caprice32 or check the man page (man cap32) for more extensive information.\n"; exit(errcode); } std::string cap32_keystroke(CAP32_KEYS key) { return std::string("\f") + char(key); } std::string cpc_keystroke(CPC_KEYS key) { return std::string("\a") + char(key); } std::string replaceCap32Keys(std::string command) { static std::map<std::string, std::string> keyNames = { { "CAP32_EXIT", cap32_keystroke(CAP32_EXIT) }, { "CAP32_FPS", cap32_keystroke(CAP32_FPS) }, { "CAP32_FULLSCRN", cap32_keystroke(CAP32_FULLSCRN) }, { "CAP32_GUI", cap32_keystroke(CAP32_GUI) }, { "CAP32_VKBD", cap32_keystroke(CAP32_VKBD) }, { "CAP32_JOY", cap32_keystroke(CAP32_JOY) }, { "CAP32_PHAZER", cap32_keystroke(CAP32_PHAZER) }, { "CAP32_MF2STOP", cap32_keystroke(CAP32_MF2STOP) }, { "CAP32_RESET", cap32_keystroke(CAP32_RESET) }, { "CAP32_SCRNSHOT", cap32_keystroke(CAP32_SCRNSHOT) }, { "CAP32_SPEED", cap32_keystroke(CAP32_SPEED) }, { "CAP32_TAPEPLAY", cap32_keystroke(CAP32_TAPEPLAY) }, { "CAP32_DEBUG", cap32_keystroke(CAP32_DEBUG) }, { "CAP32_WAITBREAK", cap32_keystroke(CAP32_WAITBREAK) }, { "CAP32_DELAY", cap32_keystroke(CAP32_DELAY) }, { "CAP32_PASTE", cap32_keystroke(CAP32_PASTE) }, { "CAP32_DEVTOOLS", cap32_keystroke(CAP32_DEVTOOLS) }, { "CPC_F1", cpc_keystroke(CPC_F1) }, { "CPC_F2", cpc_keystroke(CPC_F2) }, }; for (const auto& elt : keyNames) { size_t pos; while ((pos = command.find(elt.first)) != std::string::npos) { command.replace(pos, elt.first.size(), elt.second); LOG_VERBOSE("Recognized keyword: " << elt.first); } } return command; } void parseArguments(int argc, char **argv, std::vector<std::string>& slot_list, CapriceArgs& args) { int option_index = 0; int c; optind = 0; // To please test framework, when this function is called multiple times ! while(true) { c = getopt_long (argc, argv, "a:c:hi:o:O:s:vV", long_options, &option_index); // Logs before processing of the -v will not be visible. LOG_DEBUG("Next option: " << c << "(" << static_cast<char>(c) << ")"); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 'a': LOG_VERBOSE("Append to autocmd: " << optarg); args.autocmd += replaceCap32Keys(optarg); args.autocmd += "\n"; break; case 'c': args.cfgFilePath = optarg; break; case 'h': usage(std::cout, argv[0], 0); break; case 'i': args.binFile = optarg; break; case 'o': args.binOffset = std::stol(optarg, nullptr, 0); break; case 'O': { std::string opt(optarg); bool invalid = false; auto key_value_separator = opt.find('='); if (key_value_separator == std::string::npos) invalid = true; std::string key = opt.substr(0, key_value_separator); std::string value = opt.substr(key_value_separator+1); auto section_item_separator = key.find('.'); if (section_item_separator == std::string::npos) invalid = true; std::string section = key.substr(0, section_item_separator); std::string item = key.substr(section_item_separator+1); if (invalid || section.empty() || item.empty()) { LOG_ERROR("Couldn't parse override: '" << opt << "'"); } else { args.cfgOverrides[section][item] = value; LOG_INFO("Override configuration: " << section << "." << item << " = " << value); } break; } case 's': args.symFilePath = optarg; break; case 'v': log_verbose = true; break; case 'V': // Version std::cout << "Caprice32 " << VERSION_STRING; #ifdef HASH std::cout << (std::string(HASH).empty()?"":"-"+std::string(HASH)); #endif std::cout << "\n"; // APP_PATH std::cout << "APP_PATH: "; #ifdef APP_PATH std::cout << APP_PATH; #else std::cout << "Not provided"; #endif std::cout << std::endl; // Flags std::cout << "Compiled with:" #ifdef HAVE_GL << " HAVE_GL" #endif #ifdef DEBUG << " DEBUG" #endif #ifdef WITH_IPF << " WITH_IPF" #endif << "\n"; // Video plugins std::cout << "Number of video plugins available: " << video_plugin_list.size() << std::endl; exit(0); break; case '?': default: usage(std::cerr, argv[0], 1); break; } } /* All remaining command line arguments will go to the slot content list */ slot_list.assign(argv+optind, argv+argc); LOG_DEBUG("slot_list: " << stringutils::join(slot_list, ",")) }
7,582
C++
.cpp
188
32.702128
222
0.571041
ColinPitrat/caprice32
146
32
52
GPL-2.0
9/20/2024, 9:42:21 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false