Skip to content

Commit

Permalink
Add WebAssembly target
Browse files Browse the repository at this point in the history
  • Loading branch information
vpyk committed Jul 18, 2024
1 parent 7fdb4cd commit b816fae
Show file tree
Hide file tree
Showing 29 changed files with 1,897 additions and 241 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/obj
/obj*
/bin
/src/*.layout
/src/*.depend
/src/*.pro.user*
*.o
/Emu80
/Emu80lite
/build
/build*
.qmake.stash
Makefile
47 changes: 47 additions & 0 deletions Makefile.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
EMCC = emcc
SRC_DIR = src
OBJ_DIR = obj_wasm
BUILD_DIR = build_wasm
OUTPUT = emuframe

.PHONY: all

SOURCES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/sdl/*.cpp) \
$(wildcard $(SRC_DIR)/lite/*.cpp) $(wildcard $(SRC_DIR)/wasm/*.cpp)
SOURCES := $(filter-out $(SRC_DIR)/sdl/sdlPalFile.cpp, $(SOURCES))

TARGETS := $(BUILD_DIR)/$(OUTPUT).js $(BUILD_DIR)/$(OUTPUT).wasm

PRE_JS := $(SRC_DIR)/wasm/prejs.js
SRC_WEB_FILES := index.html emu80.js emuframe.html dummyframe.html const.js emu80.css readme.txt

EMFLAGS := -c -g2 -O3 -std=c++11 -DPAL_SDL -DPAL_LITE -DPAL_WASM -sUSE_SDL=2
LDFLAGS := -sUSE_SDL=2 -sFETCH=1 -sASYNCIFY=1 -sEXPORTED_RUNTIME_METHODS=ccall --pre-js $(PRE_JS)

OBJECTS := $(patsubst $(SRC_DIR)/%,$(OBJ_DIR)/%,$(SOURCES:.cpp=.o))
DEPENDS := $(patsubst $(SRC_DIR)/%,$(OBJ_DIR)/%,$(SOURCES:.cpp=.d))

SRC_WEB_FILES := $(foreach file,$(SRC_WEB_FILES),$(SRC_DIR)/wasm/web/$(file))
WEB_FILES := $(foreach file,$(SRC_WEB_FILES),$(BUILD_DIR)/$(file))

all: $(TARGETS) $(WEB_FILES)

$(TARGETS): $(OBJECTS)
@mkdir -p $(dir $@)
$(EMCC) $(OBJECTS) $(LDFLAGS) -o $(BUILD_DIR)/$(OUTPUT).js

$(OBJECTS): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.d
$(EMCC) $(EMFLAGS) $< -o $@

$(DEPENDS): $(OBJ_DIR)/%.d: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(EMCC) -MM -MP -MT"$(@:.d=.o)" $(EMFLAGS) $< > $@

$(WEB_FILES): $(SRC_WEB_FILES)
@mkdir -p $(dir $@)
cp -f $(SRC_WEB_FILES) $(BUILD_DIR)

clean:
-rm -f $(OBJECTS) $(DEPENDS) $(TARGETS) $(WEB_FILES)

-include $(DEPENDS)
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ For license info, see the file "COPYING.txt"
* Обсуждение на форуме nedopc.org: [http://www.nedopc.org/forum/viewtopic.php?f=43&t=17234](http://www.nedopc.org/forum/viewtopic.php?f=43&t=17234)

## Версии
Эмулятор может быть собран в одной из трех версий:
Эмулятор может быть собран в одной из версий:

* **Qt-версия** (рекомендуется). Обладает дружественным интерфейсом, некоторые возможности присутствуют только в этой версии.
* **SDL/wx-версия**. Менее требовательна к аппаратной части. Рекомендуется при наличии проблем с Qt-версией.
* **Lite-версия**. В данной версии отстутствует пользовательский интерфейс, управление может осуществляться с помощью командной строки и конфигурационных файлов.
* **WebAssembly-версия**. Предназначена для запуска в браузере и использования на web-сайтах

## Сборка и установка под Linux:

Expand Down Expand Up @@ -57,3 +58,15 @@ For license info, see the file "COPYING.txt"
## Сборка под Windows

Для сборки под Windows могут быть использованы файлы проектов `src/Emu80qt.pro` для среды разработки Qt Creator и `src/Emu80.cbp` для среды разработки Code::Blocks.

## Сборка WebAssembly-версии

#### Требования и зависимости:
* Emscripten (остальные зависимости будут загружены автоматически)

#### Порядок компиляции:
git clone https://github.com/vpyk/emu80v4.git
cd emu80v4
make -f Makefile.wasm

Результирующие файлы будут находиться в директории wasm_build. Пояснения по использованию - в файле wasm_build/readme.txt
467 changes: 258 additions & 209 deletions doc/Emu80 v4 Manual.rtf

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/EmuCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ unsigned emuGetEmulationSpeedFactor()
{
return g_emulation->getPausedState() ? 0 : g_emulation->getSpeedUpFactor();
}


// Turns off fullscreen mode (for wasm version)
void emuExitFullscreenMode(PalWindow* wnd)
{
static_cast<EmuWindow*>(wnd)->setFullScreen(false);
}
2 changes: 2 additions & 0 deletions src/EmuCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ const std::vector<PlatformInfo>* emuGetPlatforms();
void emuSelectPlatform(const std::string& platform);
unsigned emuGetEmulationSpeedFactor();

void emuExitFullscreenMode(PalWindow* wnd);

#endif // EMUCALLS_H
8 changes: 6 additions & 2 deletions src/Globals.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Emu80 v. 4.x
* © Viktor Pykhonin <pyk@mail.ru>, 2016-2018
* © Viktor Pykhonin <pyk@mail.ru>, 2016-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,7 +26,11 @@
#elif defined PAL_WX
#define TARGET ""
#else
#define TARGET "/lite"
#ifdef PAL_WASM
#define TARGET "/wasm"
#else
#define TARGET "/lite"
#endif
#endif

#define VERSION VER_STR TARGET
Expand Down
6 changes: 5 additions & 1 deletion src/Pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include "lite/litePal.h"
#endif // PAL_LITE

#ifdef PAL_QT
#ifdef PAL_WASM
#include "wasm/wasmPal.h"
#endif // PAL_WASM

#ifdef PAL_QT
#ifdef __WIN32__
#define EXE_NAME "Emu80qt.exe"
#else
Expand Down
10 changes: 7 additions & 3 deletions src/PalFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Emu80 v. 4.x
* © Viktor Pykhonin <pyk@mail.ru>, 2017
* © Viktor Pykhonin <pyk@mail.ru>, 2017-2024
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,13 @@


#ifdef PAL_QT
#include "qt/qtPalFile.h"
#include "qt/qtPalFile.h"
#endif // PAL_QT

#ifdef PAL_SDL
#include "sdl/sdlPalFile.h"
#ifndef PAL_WASM
#include "sdl/sdlPalFile.h"
#else
#include "wasm/wasmPalFile.h"
#endif // !PAL_WASM
#endif // PAL_SDL
2 changes: 2 additions & 0 deletions src/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ void Platform::draw()

void Platform::showDebugger()
{
#ifndef PAL_WASM
if (m_cpu->getType() == Cpu::CPU_8080 || m_cpu->getType() == Cpu::CPU_Z80) {
if (!m_dbgWindow) {
m_dbgWindow = new DebugWindow(this);
Expand All @@ -417,6 +418,7 @@ void Platform::showDebugger()
}
m_dbgWindow->startDebug();
}
#endif
}


Expand Down
8 changes: 5 additions & 3 deletions src/lite/litePal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ void palGetDirContent(const string& dir, list<PalFileInfo*>& fileList)

#else

#ifndef PAL_WASM
std::string palOpenFileDialog(std::string, std::string, bool, PalWindow*) {
return "";
}

void palUpdateConfig() {
}
#endif //!PAL_WASM

void palGetDirContent(const string& dir, list<PalFileInfo*>& fileList)
{
DIR* pDir;
Expand Down Expand Up @@ -216,9 +221,6 @@ void palSetRunFileName(std::string) {
void palShowConfigWindow(int) {
}

void palUpdateConfig() {
}

void palAddTabToConfigWindow(int, std::string) {
}

Expand Down
4 changes: 3 additions & 1 deletion src/lite/litePal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@

class PalWindow;

#ifndef PAL_WASM
std::string palOpenFileDialog(std::string title, std::string filter, bool write, PalWindow* window = nullptr);
void palUpdateConfig();
#endif //!PAL_WASM

bool palChoosePlatform(std::vector<PlatformInfo>& pi, int& pos, bool& newWnd, bool setDef = false, PalWindow* wnd = nullptr);
bool palChooseConfiguration(std::string platformName, PalWindow* wnd);
void palSetRunFileName(std::string runFileName);
void palShowConfigWindow(int curTabId = 0);
void palUpdateConfig();
void palGetPalDefines(std::list<std::string>& difineList);
void palGetPlatformDefines(std::string platformName, std::map<std::string, std::string>& definesMap);

Expand Down
Loading

0 comments on commit b816fae

Please sign in to comment.