diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 66bf841..a8e6767 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ fox32.html fox32.wasm fox32.js fox32.data + +**/result +.direnv/ diff --git a/Makefile b/Makefile index 8d171be..218a602 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,9 @@ -TARGET = linux -ifeq ($(TARGET),linux) -# default is used for CC -SDL2_CONFIG = sdl2-config +SDL2_CONFIG ?= sdl2-config +FOX32ROM_IN ?= fox32.rom + +FOX32ROM_OUT = fox32rom.h CFLAGS += -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags` LDFLAGS += `$(SDL2_CONFIG) --libs` -else -ifeq ($(TARGET),mingw) -CC = x86_64-w64-mingw32-gcc -CFLAGS += -g -Ofast -std=c99 -Wall -Wextra -DWINDOWS -LDFLAGS += -lmingw32 -lSDL2main -lSDL2 -TARGET_FILE_EXTENSION = .exe -else -ifeq ($(TARGET),wasm) -CC = emcc -CFLAGS += -O3 -std=c99 -Wall -Wextra -LDFLAGS += -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img -TARGET_EXTRADEPS = fox32os.img -TARGET_FILE_EXTENSION = .html -else -$(error unknown TARGET) -endif -endif -endif CFILES = src/main.c \ src/bus.c \ @@ -37,20 +19,19 @@ CFILES = src/main.c \ OBJS = $(addsuffix .o, $(basename $(CFILES))) .PHONY: all -all: fox32$(TARGET_FILE_EXTENSION) - -FOX32ROM_IN = fox32.rom -FOX32ROM_OUT = fox32rom.h +all: fox32 $(FOX32ROM_OUT): $(FOX32ROM_IN) - xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT) + cp $(FOX32ROM_IN) fox32.rom + xxd -i fox32.rom $(FOX32ROM_OUT) + rm -f fox32.rom sed -i -e 's/fox32_rom/fox32rom/' $(FOX32ROM_OUT) -fox32$(TARGET_FILE_EXTENSION): $(TARGET_EXTRADEPS) $(OBJS) +fox32: $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) %.o: %.c $(FOX32ROM_OUT) $(CC) -o $@ -c $< $(CFLAGS) clean: - rm -rf fox32 fox32.exe fox32.wasm fox32.html fox32.data fox32.js fox32rom.h $(OBJS) + rm -rf fox32 $(FOX32ROM_OUT) $(OBJS) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a10594e --- /dev/null +++ b/flake.lock @@ -0,0 +1,528 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_5": { + "inputs": { + "systems": "systems_5" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_6": { + "inputs": { + "systems": "systems_6" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_7": { + "inputs": { + "systems": "systems_7" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_8": { + "inputs": { + "systems": "systems_8" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "fox32asm": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1707042298, + "narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=", + "ref": "refs/heads/main", + "rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4", + "revCount": 68, + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + } + }, + "fox32asm_2": { + "inputs": { + "flake-utils": "flake-utils_5", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1707042298, + "narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=", + "ref": "refs/heads/main", + "rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4", + "revCount": 68, + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + } + }, + "fox32asm_3": { + "inputs": { + "flake-utils": "flake-utils_8", + "nixpkgs": "nixpkgs_6" + }, + "locked": { + "lastModified": 1707042298, + "narHash": "sha256-3sAOFd6y7Qrd/FTO/w+G4VfZeaScAoZFKY4IiVd8cqo=", + "ref": "refs/heads/main", + "rev": "4d8d3d1c48852f35031de2a37bc32766da2833f4", + "revCount": 68, + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32asm" + } + }, + "fox32os": { + "inputs": { + "flake-utils": "flake-utils_2", + "fox32asm": "fox32asm", + "fox32rom": "fox32rom", + "foxtools": "foxtools", + "nixpkgs": "nixpkgs_5" + }, + "locked": { + "lastModified": 1707047316, + "narHash": "sha256-bLXyUp8d1mOO5fa9ubjcP7fItfe+9PNPOATJ5nDAhrg=", + "ref": "refs/heads/main", + "rev": "1a89d1e48e22fa95d85c6575853b4f88f64e26aa", + "revCount": 211, + "type": "git", + "url": "https://githug.xyz/xenia/fox32os" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32os" + } + }, + "fox32rom": { + "inputs": { + "flake-utils": "flake-utils_4", + "fox32asm": "fox32asm_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1706972604, + "narHash": "sha256-r5R3aoFtrctpPoQIE3ynLet9L34WUFlj2PRSKRgQAYg=", + "ref": "refs/heads/main", + "rev": "f4a7e18b2803ff65eb4182a248028bef6cda7546", + "revCount": 181, + "type": "git", + "url": "https://githug.xyz/xenia/fox32rom" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32rom" + } + }, + "fox32rom_2": { + "inputs": { + "flake-utils": "flake-utils_7", + "fox32asm": "fox32asm_3", + "nixpkgs": "nixpkgs_7" + }, + "locked": { + "lastModified": 1706972604, + "narHash": "sha256-r5R3aoFtrctpPoQIE3ynLet9L34WUFlj2PRSKRgQAYg=", + "ref": "refs/heads/main", + "rev": "f4a7e18b2803ff65eb4182a248028bef6cda7546", + "revCount": 181, + "type": "git", + "url": "https://githug.xyz/xenia/fox32rom" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox32rom" + } + }, + "foxtools": { + "inputs": { + "flake-utils": "flake-utils_6", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1707042981, + "narHash": "sha256-RJwtT0BUBM0XlpzUymrwvI5JAsP1drjggIjDJcnWq8o=", + "ref": "refs/heads/main", + "rev": "f690eb07c46d59c9430bc004f72f6fba271e2415", + "revCount": 43, + "type": "git", + "url": "https://githug.xyz/xenia/fox-tools" + }, + "original": { + "type": "git", + "url": "https://githug.xyz/xenia/fox-tools" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_5": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_6": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_7": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_8": { + "locked": { + "lastModified": 1697009197, + "narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "fox32os": "fox32os", + "fox32rom": "fox32rom_2", + "nixpkgs": "nixpkgs_8" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_6": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_7": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_8": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6e170fb --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + description = "fox32 emulator"; + + inputs = { + fox32rom.url = "git+https://githug.xyz/xenia/fox32rom"; + fox32os.url = "git+https://githug.xyz/xenia/fox32os"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, fox32rom, fox32os, flake-utils }: + flake-utils.lib.eachDefaultSystem (sys: + let pkgs = import nixpkgs { system = sys; }; + rom = fox32rom.packages.${sys}.fox32rom; + deps = [ pkgs.SDL2.dev pkgs.xxd ]; + os = fox32os.packages.${sys}.fox32os; + + fox32 = pkgs.stdenv.mkDerivation { + name = "fox32"; + src = ./.; + buildInputs = deps; + + FOX32ROM_IN = "${rom}/bin/fox32.rom"; + installPhase = '' + mkdir -p $out/bin + cp fox32 $out/bin/fox32 + ''; + }; + + fox32-with-os = pkgs.writeScriptBin "fox32-with-os" ''cp ${os}/bin/fox32os.img /tmp/fox32os.img && chmod u+w /tmp/fox32os.img && ${fox32}/bin/fox32 --disk /tmp/fox32os.img''; + + in rec { + packages.fox32 = fox32; + packages.fox32-with-os = fox32-with-os; + packages.default = fox32; + + devShells.default = pkgs.mkShell { + packages = deps; + shellHook = '' + export FOX32ROM_IN="${rom}/bin/fox32.rom" + ''; + }; + } + ); +}