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
8 changes: 8 additions & 0 deletions .github/scripts/build-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e
cmake -B build-cmake -G Ninja
cmake --build build-cmake || {
echo "=== build failed, listing generated shared assets for diagnosis ==="
ls -la build-cmake/ngdevkit-assets || true
exit 1
}
90 changes: 90 additions & 0 deletions .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ jobs:
- name: Build examples
run: ./.github/scripts/build.sh

linux-cmake:
name: "Linux CMake build"
runs-on: ubuntu-slim
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Launchpad PPA
id: launchpad_ppa
run: |
sudo add-apt-repository -y ppa:dciabrin/ngdevkit
sudo apt-get update -y
toolchain_version=$(sudo apt-cache policy ngdevkit-toolchain | awk '/Candidate:/ {print $2}')
arch=$(dpkg --print-architecture)
echo "toolchain_deb=ngdevkit-toolchain_${toolchain_version}_${arch}.deb" >> "$GITHUB_OUTPUT"

- name: Cache ngdevkit-toolchain package
uses: actions/cache@v5
with:
path: /tmp/${{ steps.launchpad_ppa.outputs.toolchain_deb }}
key: ${{ steps.launchpad_ppa.outputs.toolchain_deb }}

- name: Prepare cached dependency
run: |
if [ ! -f /tmp/${{ steps.launchpad_ppa.outputs.toolchain_deb }} ]; then
cd /tmp && sudo apt-get download ngdevkit-toolchain
fi
sudo cp /tmp/${{ steps.launchpad_ppa.outputs.toolchain_deb }} /var/cache/apt/archives

- name: Install dependencies
run: |
sudo apt-get install -y ngdevkit ngdevkit-gngeo
sudo apt-get install -y pkg-config cmake ninja-build imagemagick sox libsox-fmt-mp3

- name: Build examples
run: ./.github/scripts/build-cmake.sh

win:
name: "Windows native MSYS2 build"
runs-on: windows-latest
Expand Down Expand Up @@ -77,6 +114,39 @@ jobs:
- name: Build examples
run: ./.github/scripts/build.sh

win-cmake:
name: "Windows native MSYS2 CMake build"
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
install:
git zip pactoys
mingw-w64-ucrt-x86_64-pkg-config
mingw-w64-ucrt-x86_64-python
mingw-w64-ucrt-x86_64-python-pillow
mingw-w64-ucrt-x86_64-python-ruamel-yaml

- name: Install ngdevkit dependencies
run: |
echo -e "[ngdevkit]\nSigLevel = Optional TrustAll\nServer = https://dciabrin.net/msys2-ngdevkit/\$arch" >> /etc/pacman.conf
pacman -Sy
pacboy -S --noconfirm ngdevkit:u ngdevkit-gngeo:u toolchain:u zlib:u sox:u imagemagick:u cmake:u ninja:u

- name: Build examples
run: ./.github/scripts/build-cmake.sh

macos:
name: "macOS build"
runs-on: macos-15
Expand All @@ -87,8 +157,28 @@ jobs:
- name: Dependencies
run: |
brew tap dciabrin/ngdevkit
brew trust dciabrin/ngdevkit
brew install automake zip pkg-config
brew install ngdevkit ngdevkit-gngeo imagemagick sox glew make

- name: Build examples
run: ./.github/scripts/build.sh

macos-cmake:
name: "macOS CMake build"
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Dependencies
run: |
brew tap dciabrin/ngdevkit
brew trust dciabrin/ngdevkit
brew install cmake ninja pkg-config
brew install ngdevkit ngdevkit-gngeo imagemagick sox glew

- name: Build examples
run: |
export PATH=$HOMEBREW_PREFIX/opt/python3/bin:$PATH
./.github/scripts/build-cmake.sh
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ assets/
assets/*.wav
.prebuild

# cmake build directories and local presets
build-cmake*/
CMakeUserPresets.json

# generated ROM file
*.zip

Expand Down
44 changes: 44 additions & 0 deletions 00-template/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2026 Florian Loitsch
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

# This is the CMake counterpart of the template's Makefile. The helper
# functions used below are defined in cmake/NGDevKit.cmake.

# program ROM: your main program.
# List your sources below; they are compiled into an ELF binary that
# becomes the content of the program ROM (PROM1).
# Default compile flags can be replaced per target with CFLAGS, and
# linker flags added with LINK_OPTIONS.
ngdevkit_elf(00-template-rom
SOURCES main.c
)

# The cartridge: all the ROM chips, the cartridge zip, the emulator
# hash files, plus run targets (00-template-gngeo, 00-template-mame, ...).
#
# By default:
# . the fixed tiles ROM (SROM) holds latin fonts for printing text
# . the sprite ROM (CROM1/CROM2) holds the ngdevkit logo shown
# during the attract mode
# . the sound driver ROM (MROM) holds ngdevkit's base sound driver
# . the sample ROM (VROM) is empty
# Override them with the SROM, CROM1/CROM2, SOUND_DRIVER and VROM
# arguments; see the other examples for how to convert your own assets.
ngdevkit_cartridge(
GAMEROM ngdevkit
TITLE "ngdevkit template ROM"
ELF 00-template-rom
)
25 changes: 25 additions & 0 deletions 01-helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2026 Florian Loitsch
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

ngdevkit_elf(01-helloworld-rom
SOURCES main.c
)

ngdevkit_cartridge(
GAMEROM 01_helloworld
TITLE "Simple hello world"
ELF 01-helloworld-rom
)
36 changes: 36 additions & 0 deletions 02-sprite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2026 Florian Loitsch
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

# this example displays the ngdevkit logo as a movable sprite, so it
# embeds a full (unclipped) conversion of the shared logo image
set(logo ${CMAKE_CURRENT_BINARY_DIR}/gen/assets/logo.gif)
add_custom_command(OUTPUT ${logo}
COMMAND ${CMAKE_COMMAND} -E copy ${NGDK_LOGO_GIF} ${logo}
DEPENDS ${NGDK_LOGO_GIF}
VERBATIM)
ngdevkit_sprite_tiles(LOGO_C1 LOGO_C2 ${logo})

ngdevkit_elf(02-sprite-rom
SOURCES main.c
)

ngdevkit_cartridge(
GAMEROM 02_sprite
TITLE "Setting up a sprite"
ELF 02-sprite-rom
CROM1 ${NGDK_BASE_CROM_C1} ${LOGO_C1}
CROM2 ${NGDK_BASE_CROM_C2} ${LOGO_C2}
)
55 changes: 55 additions & 0 deletions 03-sprite-animation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2026 Florian Loitsch
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

set(gen ${CMAKE_CURRENT_BINARY_DIR}/gen)
set(gfx ${CMAKE_CURRENT_SOURCE_DIR}/setup/prepare-hero/gfx)

# the original files for this demo need to get their transparent color fixed
foreach(anim IN ITEMS idle walk)
add_custom_command(OUTPUT ${gen}/${anim}.gif
COMMAND ${NGDK_SH} -c "cp '${gfx}/spr_m_traveler_${anim}_anim.gif' '${gen}/${anim}.gif' && printf '\\xff\\x00\\xff' | dd of='${gen}/${anim}.gif' bs=1 seek=13 count=3 conv=notrunc status=none"
DEPENDS ${gfx}/spr_m_traveler_${anim}_anim.gif
COMMENT "Preparing ${anim}.gif"
VERBATIM)
endforeach()

# we want all the sprites to share the same palette, so for simplicity
# in this demo we merge all the frames into a single file with imagemagick
add_custom_command(OUTPUT ${gen}/assets/all.gif
COMMAND ${NGDK_CONVERT} ${gen}/idle.gif ${gen}/walk.gif -coalesce -append
+repage "xc:#ff00ff[64x1024!]" -compose dstover -compose dstover
-fill "#00ffff" -opaque "#000100" -fill "#00ffff" -opaque "#000000"
-fill "#181818" -opaque "#00ffff" -fill "#000000" -opaque "#ff00ff"
-composite ${gen}/assets/all.gif
DEPENDS ${gen}/idle.gif ${gen}/walk.gif
COMMENT "Merging animation frames into all.gif"
VERBATIM)

ngdevkit_sprite_tiles(ALL_C1 ALL_C2 ${gen}/assets/all.gif)
ngdevkit_palette(ALL_PAL ${gen}/assets/all.gif)

ngdevkit_elf(03-sprite-animation-rom
SOURCES main.c
GENERATED ${ALL_PAL}
)

ngdevkit_cartridge(
GAMEROM 03_sprite_anim
TITLE "Sprite animation"
ELF 03-sprite-animation-rom
CROM1 ${NGDK_BASE_CROM_C1} ${ALL_C1}
CROM2 ${NGDK_BASE_CROM_C2} ${ALL_C2}
)
44 changes: 44 additions & 0 deletions 04-palette/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2026 Florian Loitsch
# This file is part of ngdevkit
#
# ngdevkit is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# ngdevkit 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ngdevkit. If not, see <http://www.gnu.org/licenses/>.

set(gen ${CMAKE_CURRENT_BINARY_DIR}/gen)

# palette data for all the gradients displayed by the example
add_custom_command(OUTPUT ${gen}/gradients.pal
COMMAND ${NGDK_SH} -c "'${NGDK_PYTHON}' '${CMAKE_CURRENT_SOURCE_DIR}/mk-gradients.py' > '${gen}/gradients.pal'"
DEPENDS mk-gradients.py
COMMENT "Generating gradients.pal"
VERBATIM)

# a gradient image, converted to fixed tiles to visualize the palettes
add_custom_command(OUTPUT ${gen}/assets/gradient.gif
COMMAND ${NGDK_CONVERT} -size 16x1 gradient:black-white -scale 800%
${gen}/assets/gradient.gif
COMMENT "Generating gradient.gif"
VERBATIM)
ngdevkit_fix_tiles(GRADIENT_FIX ${gen}/assets/gradient.gif)

ngdevkit_elf(04-palette-rom
SOURCES main.c
GENERATED ${gen}/gradients.pal
)

ngdevkit_cartridge(
GAMEROM 04_palette
TITLE "Palette test"
ELF 04-palette-rom
SROM ${NGDK_BASE_SROM_FIX} ${GRADIENT_FIX}
)
Loading