Skip to content

Commit

Permalink
WIP: Basic wasm platform support
Browse files Browse the repository at this point in the history
Based on Adriweb's patch, but avoiding the QML file dialog.

CONFIG += ltcg causes the "-s X" options to be merged to a single "-s",
breaking build.
  • Loading branch information
Vogtinator committed Dec 29, 2022
1 parent ad55306 commit 708be5c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 38 deletions.
2 changes: 1 addition & 1 deletion core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {
#endif

// Can also be set manually
#if !defined(__i386__) && !defined(__x86_64__) && !(defined(__arm__) && !defined(__thumb__)) && !(defined(__aarch64__))
#if !defined(__i386__) && !defined(__x86_64__) && !(defined(__arm__) && !defined(__thumb__)) && !(defined(__aarch64__)) && !defined(NO_TRANSLATION)
#define NO_TRANSLATION
#endif

Expand Down
12 changes: 9 additions & 3 deletions firebird.pro
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ unix: !android {

QMAKE_CFLAGS += -g -std=gnu11 -Wall -Wextra
QMAKE_CXXFLAGS += -g -Wall -Wextra -D QT_NO_CAST_FROM_ASCII
LIBS += -lz
wasm {
QMAKE_CFLAGS += -s USE_ZLIB
QMAKE_CXXFLAGS += -s USE_ZLIB
QMAKE_LFLAGS += -s USE_ZLIB
} else: LIBS += -lz

# Override bad default options to enable better optimizations
QMAKE_CFLAGS_RELEASE = -O3 -DNDEBUG
Expand All @@ -53,7 +57,9 @@ QMAKE_CXXFLAGS_RELEASE = -O3 -DNDEBUG
# with Qt's -reduce-relocations option (QTBUG-86173).
# MinGW fails with
# lto1.exe: internal compiler error: in gen_subprogram_die, at dwarf2out.c:22668
!clang | !if(linux|freebsd): !win32: CONFIG += ltcg
# wasm makes qmake misbehave: the various "-s FOO" options get their "-s" merged
# into a single one.
!clang | !if(linux|freebsd|wasm): !win32: CONFIG += ltcg

# noexecstack is not supported by MinGW's as
!win32 {
Expand All @@ -79,7 +85,7 @@ android {
QMAKE_LFLAGS += -Wl,-Bsymbolic
}

ios|android: DEFINES += MOBILE_UI
ios|android|wasm: DEFINES += MOBILE_UI

ios {
DEFINES += IS_IOS_BUILD
Expand Down
80 changes: 46 additions & 34 deletions qml/ConfigPageKits.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ ColumnLayout {

GridLayout {
anchors.fill: parent
columns: (width < 550 || Qt.platform.os === "android") ? 2 : 4
columns: (width < 550 || Qt.platform.os === "android") ? 3 : 6

FBLabel {
Layout.columnSpan: parent.columns
Layout.fillWidth: true
color: "red"
visible: boot1Edit.filePath == "" || flashEdit.filePath == ""
visible: kitList.currentItem.myData.boot1 === "" || kitList.currentItem.myData.flash === ""
wrapMode: Text.WordWrap
text: qsTr("You need to specify files for Boot1 and Flash")
}
Expand All @@ -50,6 +50,7 @@ ColumnLayout {
TextField {
id: nameEdit
placeholderText: qsTr("Name")
Layout.columnSpan: 2
Layout.fillWidth: true

text: kitList.currentItem.myData.name
Expand All @@ -65,57 +66,68 @@ ColumnLayout {
elide: Text.ElideMiddle
}

FileSelect {
id: boot1Edit
FBLabel {
property string filePath: kitList.currentItem.myData.boot1
elide: "ElideRight"

Layout.fillWidth: true
filePath: kitList.currentItem.myData.boot1
onFilePathChanged: {
if(filePath !== kitList.currentItem.myData.boot1)
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.Boot1Role);
filePath = Qt.binding(function() { return kitList.currentItem.myData.boot1; });
}
// Allow the label to shrink below its implicitWidth.
// Without this, the layout doesn't allow it to go smaller...
Layout.preferredWidth: 100

font.italic: filePath === ""
text: filePath === "" ? qsTr("(none)") : Emu.basename(filePath)
}

IconButton {
icon: "qrc:/icons/resources/icons/document-edit.png"
onClicked: Emu.loadFile(kitList.currentIndex, KitModel.Boot1Role)
}

FBLabel {
text: qsTr("Flash:")
elide: Text.ElideMiddle
}

FileSelect {
id: flashEdit
FBLabel {
property string filePath: kitList.currentItem.myData.flash
elide: "ElideRight"

Layout.fillWidth: true
filePath: kitList.currentItem.myData.flash
onFilePathChanged: {
if(filePath !== kitList.currentItem.myData.flash)
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; });
}
showCreateButton: true
onCreate: flashDialog.visible = true
// Allow the label to shrink below its implicitWidth.
// Without this, the layout doesn't allow it to go smaller...
Layout.preferredWidth: 100

font.italic: filePath === ""
text: filePath === "" ? qsTr("(none)") : Emu.basename(filePath)
}

FlashDialog {
id: flashDialog
onFlashCreated: {
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
}
IconButton {
icon: "qrc:/icons/resources/icons/document-edit.png"
onClicked: Emu.loadFile(kitList.currentIndex, KitModel.FlashRole)
}

FBLabel {
text: qsTr("Snapshot:")
elide: Text.ElideMiddle
}

FileSelect {
id: snapshotEdit
FBLabel {
property string filePath: kitList.currentItem.myData.snapshot
elide: "ElideRight"

Layout.fillWidth: true
selectExisting: false
filePath: kitList.currentItem.myData.snapshot
onFilePathChanged: {
if(filePath !== kitList.currentItem.myData.snapshot)
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.SnapshotRole);
filePath = Qt.binding(function() { return kitList.currentItem.myData.snapshot; });
}
// Allow the label to shrink below its implicitWidth.
// Without this, the layout doesn't allow it to go smaller...
Layout.preferredWidth: 100

font.italic: filePath === ""
text: filePath === "" ? qsTr("(none)") : Emu.basename(filePath)
}

IconButton {
icon: "qrc:/icons/resources/icons/document-edit.png"
onClicked: Emu.loadFile(kitList.currentIndex, KitModel.SnapshotRole)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions qml/Firebird/UIComponents/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Firebird.UIComponents
PageDelegate 1.0 PageDelegate.qml
PageList 1.0 PageList.qml
ConfigPages 1.0 ConfigPages.qml
IconButton 1.0 IconButton.qml
KitList 1.0 KitList.qml
FBLabel 1.0 FBLabel.qml
FileSelect 1.0 FileSelect.qml
Expand Down
10 changes: 10 additions & 0 deletions qml/MobileUIDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ Rectangle {
}

onClicked: {
// Different behaviour on WASM: Do not save the flash,
// only save snapshots. Create a new file if none configured yet.
if(Qt.platform.os === "wasm") {
if(!Emu.saveSnapshot())
saveFailedDialog.visible = true;

closeDrawer();
return;
}

var flash_path = Emu.getFlashPath();
var snap_path = Emu.getSnapshotPath();

Expand Down
41 changes: 41 additions & 0 deletions qmlbridge.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cassert>
#include <unistd.h>

#include <QFileDialog>
#include <QUrl>

#include "emuthread.h"
Expand Down Expand Up @@ -409,6 +410,46 @@ QString QMLBridge::osDescription(QString path)
return QString::fromStdString(version);
}

void QMLBridge::loadFile(int index, int role)
{
QFileDialog::getOpenFileContent(QStringLiteral("File%1 (*.*)").arg(role), [=](const QString &, const QByteArray &fileContent) {
int kitId = kit_model.getDataRow(index, KitModel::IDRole).toInt();
QString path = QStringLiteral("/tmp/kit%1-%2").arg(kitId).arg(role);
QFile file(path);
if (file.open(QFile::WriteOnly)) {
file.write(fileContent);
file.close();
kit_model.setDataRow(index, path, role);
}
});
}

bool QMLBridge::saveSnapshot()
{
const int kitIndex = kit_model.indexForID(current_kit_id);
QString filename = kit_model.getDataRow(kitIndex, KitModel::SnapshotRole).toString();
// If the kit doesn't have a snapshot file assigned, do it now
if(filename.isEmpty()) {
// Same algorithm as above
filename = QStringLiteral("/tmp/kit%1-%2").arg(current_kit_id).arg(KitModel::SnapshotRole);
kit_model.setDataRow(kitIndex, filename, KitModel::SnapshotRole);
}

// Write the snapshot to the file
if(!emu_suspend(filename.toUtf8().constData()))
return false;

// Read in all the data (again)
QFile snapshotFile(filename);
if(!snapshotFile.open(QIODevice::ReadOnly))
return false;

auto snapshotData = snapshotFile.readAll();
QFileDialog::saveFileContent(snapshotData, QStringLiteral("%1-snapshot.img").arg(kit_model.getDataRow(kitIndex, KitModel::NameRole).toString()));

return true;
}

void QMLBridge::setActive(bool b)
{
if(is_active == b)
Expand Down
3 changes: 3 additions & 0 deletions qmlbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class QMLBridge : public QObject
Q_INVOKABLE QString manufDescription(QString path);
Q_INVOKABLE QString osDescription(QString path);

Q_INVOKABLE void loadFile(int index, int role);
Q_INVOKABLE bool saveSnapshot();

Q_INVOKABLE bool saveDialogSupported();

void setActive(bool b);
Expand Down

0 comments on commit 708be5c

Please sign in to comment.