Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
Language: Cpp
Standard: c++17
BasedOnStyle: LLVM

# Line length
ColumnLimit: 120

# Indentation
IndentWidth: 4
UseTab: Never
IndentCaseLabels: true
IndentPPDirectives: AfterHash

# Spacing
SpaceBeforeParens: ControlStatements
SpaceAfterCStyleCast: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpaceBeforeAssignmentOperators: true

# Pointers and references
PointerAlignment: Left

# Braces
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false

# Function definitions
AllowShortFunctionsOnASingleLine: None
SeparateDefinitionBlocks: Always
AllowShortBlocksOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true

# Constructor/Destructor
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
Cpp11BracedListStyle: true

# Operators
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true

# Includes
SortIncludes: true
IncludeBlocks: Preserve

# Comments
ReflowComments: true

# Other
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignTrailingComments: true

AccessModifierOffset: -2
CompactNamespaces: false
FixNamespaceComments: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
45 changes: 45 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
# Clang-tidy configuration for Z80 emulator project
Checks: |
-*,
readability-*,
performance-*,
modernize-*,
bugprone-*,
clang-diagnostic-*,
cppcoreguidelines-*,
google-*,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-reinterpret-cast,
-google-readability-function-size,
-google-runtime-references,
-modernize-use-trailing-return-type,
-cppcoreguidelines-pro-bounds-constant-array-index,
-readability-function-cognitive-complexity,
-readability-function-size

WarningsAsErrors: ''

# Configure individual checks
CheckOptions:
- key: 'readability-function-cognitive-complexity.Threshold'
value: '25'
- key: 'readability-function-size.StatementThreshold'
value: '800'
- key: 'readability-identifier-length.MinimumVariableNameLength'
value: '2'
- key: 'readability-identifier-length.MinimumParameterNameLength'
value: '2'
- key: 'readability-identifier-length.MinimumLoopCounterNameLength'
value: '1'
- key: 'readability-line-length.LineLength'
value: '120'
- key: 'bugprone-easily-swappable-parameters.MinimumLength'
value: '3'

HeaderFilterRegex: '.*'
InheritParentConfig: true
70 changes: 70 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
FROM ubuntu:22.04

# Install build dependencies
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
cmake \
make \
git \
curl \
ca-certificates \
xz-utils \
sudo \
g++ \
gcc \
qemu-user-static \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Download and install ARM GNU toolchain for Raspberry Pi 4
# Detect architecture and download appropriate toolchain
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then \
TOOLCHAIN_URL="https://armkeil.blob.core.windows.net/developer/files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-aarch64-aarch64-none-linux-gnu.tar.xz"; \
else \
TOOLCHAIN_URL="https://armkeil.blob.core.windows.net/developer/files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz"; \
fi && \
curl -L "$TOOLCHAIN_URL" -o /tmp/arm-toolchain.tar.xz && \
mkdir -p /opt/arm-toolchain && \
tar -xf /tmp/arm-toolchain.tar.xz -C /opt/arm-toolchain --strip-components=1 && \
rm /tmp/arm-toolchain.tar.xz

# Add toolchain to PATH
ENV PATH="/opt/arm-toolchain/bin:${PATH}"

# Create a non-root user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Create CMake toolchain file for ARM64 cross-compilation (Raspberry Pi 4)
RUN echo 'set(CMAKE_SYSTEM_NAME Linux)\n\
set(CMAKE_SYSTEM_PROCESSOR aarch64)\n\
\n\
set(CMAKE_C_COMPILER aarch64-none-linux-gnu-gcc)\n\
set(CMAKE_CXX_COMPILER aarch64-none-linux-gnu-g++)\n\
\n\
# Optimize for Raspberry Pi 4 (Cortex-A72)\n\
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-a72 -mtune=cortex-a72")\n\
set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-a72 -mtune=cortex-a72")\n\
\n\
# Static link all libraries for tests (to run with QEMU)\n\
# For production builds on the target, remove -static flag\n\
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")\n\
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-static-libstdc++ -static-libgcc")\n\
\n\
set(CMAKE_FIND_ROOT_PATH /opt/arm-toolchain/aarch64-none-linux-gnu)\n\
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n\
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)\n\
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)\n\
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)\n\
\n\
# Use QEMU for running cross-compiled tests\n\
set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-aarch64-static)\n' > /opt/toolchain-aarch64.cmake

USER $USERNAME
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Z80 C++ ARM64 Cross-Compilation",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"twxs.cmake"
],
"settings": {
"cmake.configureArgs": [
"-DCMAKE_TOOLCHAIN_FILE=/opt/toolchain-aarch64.cmake"
]
}
}
},
"postCreateCommand": "sudo bash -c 'echo \"#!/bin/bash\" > /usr/local/bin/cmake-rpi && echo \"cmake -DCMAKE_TOOLCHAIN_FILE=/opt/toolchain-aarch64.cmake \\\"\\$@\\\"\" >> /usr/local/bin/cmake-rpi && chmod +x /usr/local/bin/cmake-rpi' && echo 'ARM64 cross-compilation environment ready. Use: cmake-rpi .. (or cmake -DCMAKE_TOOLCHAIN_FILE=/opt/toolchain-aarch64.cmake ..)'",
"remoteUser": "vscode"
}
39 changes: 39 additions & 0 deletions .github/workflows/build-and-test-with-cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: Build and Test with CMake

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure -V
68 changes: 68 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Code Quality

on: [push, pull_request]

jobs:
formatting:
name: Check Code Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install clang-format
run: sudo apt-get install -y clang-format

- name: Check formatting
run: |
files=$(find include tests -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.tpp" \))
for file in $files; do
clang-format --dry-run -Werror "$file" || exit 1
done
echo "All files are properly formatted!"

static-analysis:
name: Static Analysis with clang-tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy cmake build-essential

- name: Build with compile_commands.json
run: |
mkdir -p build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make

- name: Run clang-tidy
run: |
cd build
files=$(find ../tests -type f -name "*.cpp")
clang-tidy -p . $files

build:
name: Build Project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential

- name: Build
run: |
mkdir -p build
cd build
cmake ..
make -j4

- name: Run tests
run: |
cd build
ctest --output-on-failure
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
build*/
cmake-build*/
.vscode/
# Editor and OS files
.cache/
.idea/
example/z80sim
.vscode/
.DS_Store

# Build directories
build*/

# Test ROMs
tests/roms/*
tests/roms/*.tap
Loading