Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run no-OO linter
- name: Run forbidden tokens linter
run: |
bash tools/check_no_oo.sh shared
bash tools/check_forbidden_tokens.sh shared
File renamed without changes.
84 changes: 54 additions & 30 deletions linux/makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
APP_NAME = Kiwi8

# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to unknown
# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to develop
VERSION ?= $(GITHUB_REF_NAME)
ifeq ($(VERSION),)
VERSION = develop
endif

# Use SUB_VERSION if set, otherwise fall back to GITHUB_SHA, then default to unknown
SUB_VERSION ?= $(GITHUB_SHA)
ifeq ($(SUB_VERSION),)
SUB_VERSION = unknown
endif

APP_EXE = $(APP_NAME)

CC = g++
CFLAGS = -std=c++17 -Wall -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"'
LFLAGS = -Wl,-rpath,'$$ORIGIN'
CC = gcc
CXX = g++
CFLAGS = -std=gnu11
CPPFLAGS = -Wall \
-MMD \
-MP \
-DAPP_NAME='"$(APP_NAME)"' \
-DVERSION='"$(VERSION)"' \
-DSUB_VERSION='"$(SUB_VERSION)"'

CXXFLAGS = -std=gnu++11

INCLUDE_DIRS = -I../shared \
-I../external/sdl/build/include/ \
-I../external/imgui/ \
-I../external/stb/ \
-I../external/lekkit/

LDFLAGS = -L../external/sdl/build/lib \
-lSDL2-2.0 \
-lGL \
-lm \
-ldl \
-lpthread \
-Wl,-rpath,'$$ORIGIN'

# Use pkg-config to get GTK3 and audio backend flags
GTK3_CFLAGS = $(shell pkg-config --cflags gtk+-3.0)
Expand All @@ -31,32 +54,30 @@ PIPEWIRE_LIBS = $(shell pkg-config --libs libpipewire-0.3)
JACK_CFLAGS = $(shell pkg-config --cflags jack)
JACK_LIBS = $(shell pkg-config --libs jack)

CFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS)
CPPFLAGS += $(GTK3_CFLAGS) $(ALSA_CFLAGS) $(PULSE_CFLAGS) $(PIPEWIRE_CFLAGS) $(JACK_CFLAGS)
LDFLAGS += $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS)

INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/
LIBS = -L../external/sdl/build/lib -lSDL2-2.0 -lGL $(GTK3_LIBS) $(ALSA_LIBS) $(PULSE_LIBS) $(PIPEWIRE_LIBS) $(JACK_LIBS) $(ESD_LIBS) $(SNDIO_LIBS) -lm -ldl -lpthread

# SDL dependency files
SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.so.0

# Generated headers
LICENSE_HEADER = ../shared/license.h
BOOTROM_HEADER = ../shared/bootrom.h
BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8

# Source files
CORE_SRCS = ../shared/audio.cc ../shared/chip8.cc ../shared/display.cc ../shared/gui.cc \
../shared/input.cc ../shared/main.cc \
../shared/toast.cc ../shared/open_file_dialog.cc ../shared/profiles.cc
IMGUI_SRCS = ../external/imgui/imgui.cpp ../external/imgui/imgui_draw.cpp ../external/imgui/imgui_impl_sdl.cpp
LINUX_SRCS = src/file_dialog.cc
SHA256_SRC = ../external/lekkit/sha256.cc

# Object files (convert source paths to .o in current directory)
OBJS = $(notdir $(CORE_SRCS:.cc=.o)) \
$(notdir $(IMGUI_SRCS:.cpp=.o)) \
$(notdir $(LINUX_SRCS:.cc=.o)) \
$(notdir $(SHA256_SRC:.cc=.o))
OBJS = audio.o \
chip8.o \
display.o \
gui.o \
input.o \
main.o \
toast.o \
open_file_dialog.o \
profiles.o \
imgui.o \
imgui_draw.o \
imgui_impl_sdl.o \
sha256.o

DEPS = $(OBJS:.o=.d)

PROFILES_INI = ../shared/profiles.ini
Expand All @@ -66,7 +87,7 @@ PROFILES_INI = ../shared/profiles.ini

.DEFAULT_GOAL := all

all: debug/profiles.ini debug/$(APP_EXE) release/profiles. release/$(APP_EXE)
all: debug/profiles.ini debug/$(APP_EXE) release/profiles.ini release/$(APP_EXE)

# Build SDL (force rebuild with: make sdl)
sdl:
Expand All @@ -86,16 +107,19 @@ $(BOOTROM_HEADER): $(BOOTROM_SOURCE)

# Pattern rules for incremental compilation
%.o: src/%.cc
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/imgui/%.cpp
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/lekkit/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/lekkit/%.cc
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
%.o: ../shared/%.c $(LICENSE_HEADER) $(BOOTROM_HEADER)
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER)
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

debug/profiles.ini: $(PROFILES_INI)
mkdir -p debug
Expand All @@ -109,13 +133,13 @@ release/profiles.ini: $(PROFILES_INI)
debug/$(APP_EXE): $(SDL_LIB) $(OBJS)
mkdir -p debug
cp $(SDL_LIB) debug/libSDL2-2.0.so.0
$(CC) $(CFLAGS) -g $(INCS) $(LIBDIRS) $(OBJS) -o $@ $(LIBS) $(LFLAGS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS)

# release executable
release/$(APP_EXE): $(SDL_LIB) $(OBJS)
mkdir -p release
cp $(SDL_LIB) release/libSDL2-2.0.so.0
$(CC) $(CFLAGS) $(INCS) $(LIBDIRS) $(OBJS) -o $@ $(LIBS) $(LFLAGS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS)

run-debug: debug/$(APP_EXE)
./debug/$(APP_EXE)
Expand Down
9 changes: 0 additions & 9 deletions linux/src/file_dialog.h

This file was deleted.

13 changes: 12 additions & 1 deletion linux/src/file_dialog.cc → linux/src/open_file_dialog.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "file_dialog.h"
#include "open_file_dialog.h"
#include <gtk/gtk.h>
#include <cstring>
#include <vector>
#include <string>

std::vector<std::string> open_file_dialog(const std::string &title, const std::string &defaultDir, const std::vector<std::string> &filterExtensions) {
std::vector<std::string> result;
Expand Down Expand Up @@ -65,3 +67,12 @@ std::vector<std::string> open_file_dialog(const std::string &title, const std::s

return result;
}

int open_file_dialog(char *rom_name) {
std::vector<std::string> fileTypes = {"ch8", "CH8", "chip-8", "CHIP-8", "Chip-8"};
const char* defaultDir = ""; // unify behavior: let OS choose last-used/home
std::vector<std::string> files = open_file_dialog("Chip8", defaultDir, fileTypes);
if (files.empty()) return 1;
snprintf(rom_name, 256, "%s", files[0].c_str());
return 0;
}
74 changes: 47 additions & 27 deletions macos/makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
APP_NAME = Kiwi8

# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to unknown
# Use VERSION if set, otherwise fall back to GITHUB_REF_NAME, then default to develop
VERSION ?= $(GITHUB_REF_NAME)
ifeq ($(VERSION),)
VERSION = develop
endif

# Use SUB_VERSION if set, otherwise fall back to GITHUB_SHA, then default to unknown
SUB_VERSION ?= $(GITHUB_SHA)
ifeq ($(SUB_VERSION),)
SUB_VERSION = unknown
Expand All @@ -15,33 +16,49 @@ APP_MANIFEST = src/Info.plist
APP_BUNDLE = $(APP_NAME).app
APP_EXE = $(APP_NAME)

CC = clang++
CFLAGS = -std=c++17 -Wall -mmacosx-version-min=11.0 -MMD -MP -DAPP_NAME='"$(APP_NAME)"' -DVERSION='"$(VERSION)"' -DSUB_VERSION='"$(SUB_VERSION)"'
LFLAGS = -mmacosx-version-min=11.0
INCS = -I../external/sdl/build/include/ -I../external/imgui/ -I../external/stb/ -I../external/lekkit/
LIBS = -L../external/sdl/build/lib/ -lSDL2-2.0.0 -framework Cocoa -framework OpenGL
CC = clang
CXX = clang++
CFLAGS = -std=c11
CPPFLAGS = -Wall \
-mmacosx-version-min=11.0 \
-MMD -MP -DAPP_NAME='"$(APP_NAME)"' \
-DVERSION='"$(VERSION)"' \
-DSUB_VERSION='"$(SUB_VERSION)"'

CXXFLAGS = -std=c++11
INCLUDE_DIRS = -I../shared \
-I../external/sdl/build/include/ \
-I../external/imgui/ \
-I../external/stb/ \
-I../external/lekkit/

LDFLAGS = -mmacosx-version-min=11.0 \
-L../external/sdl/build/lib/ \
-lSDL2-2.0.0 \
-framework Cocoa \
-framework OpenGL

# SDL dependency files
SDL_LIB = ../external/sdl/build/lib/libSDL2-2.0.0.dylib

# Generated headers
LICENSE_HEADER = ../shared/license.h
BOOTROM_HEADER = ../shared/bootrom.h
BOOTROM_SOURCE = ../roms/Kiwi8_logo_2.ch8

# Source files
CORE_SRCS = ../shared/audio.cc ../shared/chip8.cc ../shared/display.cc ../shared/gui.cc \
../shared/input.cc ../shared/main.cc \
../shared/toast.cc ../shared/open_file_dialog.cc ../shared/profiles.cc
IMGUI_SRCS = ../external/imgui/imgui.cpp ../external/imgui/imgui_draw.cpp ../external/imgui/imgui_impl_sdl.cpp
SHA256_SRC = ../external/lekkit/sha256.cc
MACOS_SRCS = src/file_dialog.mm

# Object files (convert source paths to .o in current directory)
OBJS = $(notdir $(CORE_SRCS:.cc=.o)) \
$(notdir $(IMGUI_SRCS:.cpp=.o)) \
$(notdir $(MACOS_SRCS:.mm=.o)) \
$(notdir $(SHA256_SRC:.cc=.o))
OBJS = audio.o \
chip8.o \
display.o \
gui.o \
input.o \
main.o \
toast.o \
open_file_dialog.o \
profiles.o \
imgui.o \
imgui_draw.o \
imgui_impl_sdl.o \
sha256.o

DEPS = $(OBJS:.o=.d)

PROFILES_INI = ../shared/profiles.ini
Expand Down Expand Up @@ -75,16 +92,19 @@ $(APP_MANIFEST): $(APP_MANIFEST).in

# Pattern rules for incremental compilation
%.o: src/%.mm
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/imgui/%.cpp
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/lekkit/%.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../external/lekkit/%.cc
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
%.o: ../shared/%.c $(LICENSE_HEADER) $(BOOTROM_HEADER)
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

%.o: ../shared/%.cc $(LICENSE_HEADER) $(BOOTROM_HEADER)
$(CC) $(CFLAGS) $(INCS) -c $< -o $@
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) -c $< -o $@

debug/profiles.ini: $(PROFILES_INI)
mkdir -p debug
Expand All @@ -98,7 +118,7 @@ release/$(APP_BUNDLE)/Contents/Resources/profiles.ini: $(PROFILES_INI)
debug/$(APP_EXE): $(SDL_LIB) $(OBJS)
mkdir -p debug
cp $(SDL_LIB) debug/libSDL2-2.0.0.dylib
$(CC) $(CFLAGS) -g $(LIBS) $(INCS) $(OBJS) -o $@ $(LFLAGS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -g $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS)

# Set the dylib's install name to be relative to the bundle
install_name_tool -id @executable_path/libSDL2-2.0.0.dylib debug/libSDL2-2.0.0.dylib
Expand All @@ -109,7 +129,7 @@ debug/$(APP_EXE): $(SDL_LIB) $(OBJS)
# release executable (inside .app bundle)
release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE): $(SDL_LIB) $(OBJS)
mkdir -p release/$(APP_BUNDLE)/Contents/MacOS
$(CC) $(CFLAGS) $(LIBS) $(INCS) $(OBJS) -o $@ $(LFLAGS)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(OBJS) -o $@ $(LDFLAGS)

# Fix executable's reference to SDL (from @rpath to bundle-relative path)
install_name_tool -change @rpath/libSDL2-2.0.0.dylib @executable_path/../Frameworks/libSDL2-2.0.0.dylib release/$(APP_BUNDLE)/Contents/MacOS/$(APP_EXE)
Expand Down
9 changes: 0 additions & 9 deletions macos/src/file_dialog.h

This file was deleted.

12 changes: 11 additions & 1 deletion macos/src/file_dialog.mm → macos/src/open_file_dialog.mm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#import "file_dialog.h"
#import "open_file_dialog.h"
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include <string>
#include <vector>
#include <cstdio>

std::vector<std::string>open_file_dialog(
char const * const aTitle ,
Expand Down Expand Up @@ -41,3 +42,12 @@
}
return fileList;
}

int open_file_dialog(char *rom_name) {
std::vector<std::string> fileTypes = {"ch8", "CH8", "chip-8", "CHIP-8", "Chip-8"};
const char* defaultDir = ""; // unify behavior: let OS choose last-used/home
std::vector<std::string> files = open_file_dialog("Chip8", defaultDir, fileTypes);
if (files.empty()) return 1;
snprintf(rom_name, 256, "%s", files[0].c_str());
return 0;
}
4 changes: 2 additions & 2 deletions shared/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# shared

All the code in here *should* be platform independent or
should at least be able to compile on both macOS and Windows.
Platform specific code can be found in the "windows/src", "macos/src" and "linux/src" directories.
should at least be able to compile on Windows, MacOS, and Linux.
Platform specific code can be found in their corresponding top-level directories.
File renamed without changes.
12 changes: 12 additions & 0 deletions shared/audio.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#ifndef AUDIO_H
#define AUDIO_H

#ifdef __cplusplus
extern "C" {
#endif

#include <SDL2/SDL.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#define TAU (2.0 * M_PI)
#define AMPLITUDE 28000 // Max amplitude for signed 16-bit
#define SAMPLE_RATE 48000
Expand All @@ -25,4 +33,8 @@ extern struct audio audio;
void audio_destroy(void);
int audio_init(void);

#ifdef __cplusplus
}
#endif

#endif // AUDIO_H
Loading
Loading