-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
platform: support to compile to WebAssembly (#25)
* platform: add support for running the emulator in a web browser * log: init * emulator: support webassembly and desktop * ci: add emscripten
- Loading branch information
Showing
13 changed files
with
170 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# VSCode | ||
# CHIP-8 ROM | ||
rom/ | ||
*.ch8 | ||
|
||
# VSCode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
app = arabica | ||
test = test_$(app) | ||
cc = clang | ||
cxx = clang++ | ||
cc_desktop = clang | ||
cxx_desktop = clang++ | ||
cc_wasm = emcc | ||
cxx_wasm = em++ | ||
src_app = app | ||
src_emulator = arabica | ||
src_test = test | ||
src = $(src_app) $(src_emulator) $(src_test) | ||
dir_build = build | ||
dir_rom = rom | ||
dir_rom = roms | ||
game = Tetris_Fran_Dachille_1991.ch8 | ||
|
||
default: build execute | ||
default: desktop | ||
|
||
fmt: | ||
for dir in $(src); do \ | ||
find $$dir -type f -iname "*.cpp" -o -iname "*.hpp" | xargs clang-format -i -style=file; \ | ||
done | ||
|
||
build: clean | ||
build_desktop: clean | ||
mkdir $(dir_build); | ||
cd $(dir_build); cmake -DCMAKE_C_COMPILER="$(cc)" -DCMAKE_CXX_COMPILER="$(cxx)" -DBUILD_APP=ON -GNinja ..; ninja; | ||
cd $(dir_build); cmake -DCMAKE_C_COMPILER="$(cc_desktop)" -DCMAKE_CXX_COMPILER="$(cxx_desktop)" -DBUILD_DESKTOP=ON -GNinja ..; ninja; | ||
|
||
build_webassembly: clean | ||
mkdir -p $(dir_build) | ||
cd $(dir_build) && cmake -DCMAKE_C_COMPILER="$(cc_wasm)" -DCMAKE_CXX_COMPILER="$(cxx_wasm)" -DBUILD_WASM=ON -GNinja .. && ninja; | ||
|
||
execute: | ||
build_test: clean | ||
mkdir $(dir_build); | ||
cd $(dir_build); cmake -DCMAKE_C_COMPILER="$(cc_desktop)" -DCMAKE_CXX_COMPILER="$(cxx_desktop)" -DBUILD_TEST=ON -GNinja ..; ninja; | ||
|
||
desktop: build_desktop | ||
./$(dir_build)/$(app).out $(dir_rom)/$(game) | ||
|
||
webassembly: build_webassembly kill_webserver | ||
cd build; python3 -m http.server 8080 & | ||
firefox http://localhost:8080/arabica_wasm.html | ||
|
||
test: build_test | ||
./$(test).app | ||
|
||
debug: build_desktop | ||
gdb -x commands.gdb --args ./$(dir_build)/$(app).out $(dir_rom)/$(game).ch8 | ||
|
||
clean: | ||
rm -rf $(dir_build) | ||
|
||
test: clean | ||
mkdir $(dir_build); \ | ||
cd $(dir_build); cmake -DCMAKE_C_COMPILER="$(cc)" -DCMAKE_CXX_COMPILER="$(cxx)" -DBUILD_TEST=ON -GNinja ..; ninja; \ | ||
./$(test).out | ||
fmt: | ||
for dir in $(src); do \ | ||
find $$dir -type f -iname "*.cpp" -o -iname "*.hpp" | xargs clang-format -i -style=file; \ | ||
done | ||
|
||
debug: clean build | ||
gdb -x commands.gdb --args ./$(dir_build)/$(app).out $(dir_rom)/$(game).ch8 | ||
kill_webserver: | ||
pkill -f 8080 | ||
|
||
.PHONY: default fmt build execute clean debug | ||
.PHONY: default build_desktop build_webassembly build_test desktop webassembly test debug clean fmt kill_webserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
#include <arabica/ui/window.hpp> | ||
#include <fmt/core.h> | ||
#include <arabica/log/log.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
#ifdef __EMSCRIPTEN__ | ||
#include <emscripten.h> | ||
#include <emscripten/html5.h> | ||
#include <fstream> | ||
#include <sstream> | ||
#endif | ||
|
||
std::string rom_file(int argc, char* argv[]) { | ||
#ifdef __EMSCRIPTEN__ | ||
const char* const rom = "/roms/Tetris_Fran_Dachille_1991.ch8"; | ||
return rom; | ||
#else | ||
if (argc != 2) { | ||
return 1; | ||
fmt::print("Usage: ./arabica.out rom-file"); | ||
ARABICA_LOG_INFO("Usage: ./arabica.out rom-file\n"); | ||
std::exit(1); | ||
} | ||
arabica::Window window("Arabica Emulator", 640, 320, argv[1]); | ||
return argv[1]; | ||
#endif | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
arabica::Window window("Arabica Emulator", 640, 320, rom_file(argc, argv)); | ||
window.execute(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#define ARABICA_IS_ENABLE_LOG 0 | ||
|
||
#ifdef __EMSCRIPTEN__ | ||
#else | ||
#include <fmt/core.h> | ||
#endif | ||
|
||
#if ARABICA_IS_ENABLE_LOG | ||
#define ARABICA_LOG_INFO(fmt, ...) arabica::log_info(fmt, __VA_ARGS__) | ||
#else | ||
#define ARABICA_LOG_INFO(fmt, ...) | ||
#endif | ||
|
||
namespace arabica { | ||
|
||
template<typename... Args> | ||
inline void log_info(const char* const format, const Args&... args) { | ||
#ifdef __EMSCRIPTEN__ | ||
#else | ||
fmt::print("[emulator log] "); | ||
fmt::print(format, args...); | ||
#endif | ||
} | ||
|
||
} // namespace arabica |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.