Load cartridge
This commit is contained in:
parent
2f31756be8
commit
d197159f5a
|
@ -67,6 +67,8 @@ let get_RAM_size = function
|
||||||
|
|
||||||
|
|
||||||
let read_cartridge file =
|
let read_cartridge file =
|
||||||
|
Printf.printf "Read cartridge: %s" file;
|
||||||
|
print_newline ();
|
||||||
try
|
try
|
||||||
let ic = open_in_bin file in
|
let ic = open_in_bin file in
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
let () =
|
let () =
|
||||||
Callback.register "oboy_name" Version.name;
|
Callback.register "oboy_name" Version.name;
|
||||||
Callback.register "oboy_version" Version.version;
|
Callback.register "oboy_version" Version.version;
|
||||||
|
Callback.register "oboy_load" State.load_cartridge;
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
(* State of the world, contains all the required information at any point *)
|
(* State of the world, contains all the required information at any point *)
|
||||||
type t = {
|
type t = {
|
||||||
cartridge : option Cartridge.t;
|
mutable cartridge : Cartridge.t option;
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Global reference *)
|
(* Global reference *)
|
||||||
let state = ref {
|
let state = ref {
|
||||||
cartridge = None
|
cartridge = None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let load_cartridge file =
|
||||||
|
let cartridge = Cartridge.read_cartridge file in
|
||||||
|
!state.cartridge <- cartridge;
|
||||||
|
match cartridge with
|
||||||
|
| Some _ -> true
|
||||||
|
| None -> false
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import QtQuick 2.4
|
import QtQuick 2.4
|
||||||
import QtQuick.Window 2.0
|
import QtQuick.Window 2.0
|
||||||
import com.oboy.oboy 1.0
|
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: window
|
id: window
|
||||||
|
@ -12,10 +11,6 @@ Window {
|
||||||
maximumHeight: height
|
maximumHeight: height
|
||||||
minimumHeight: height
|
minimumHeight: height
|
||||||
|
|
||||||
OBoy {
|
|
||||||
id: oboy
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: name
|
id: name
|
||||||
text: oboy.name
|
text: oboy.name
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import QtQuick 2.5
|
import QtQuick 2.5
|
||||||
import QtQuick.Controls 1.4
|
import QtQuick.Controls 1.4
|
||||||
import QtQuick.Dialogs 1.2
|
import QtQuick.Dialogs 1.2
|
||||||
|
import com.oboy.oboy 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: root
|
id: root
|
||||||
|
@ -49,6 +50,10 @@ ApplicationWindow {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OBoy {
|
||||||
|
id: oboy
|
||||||
|
}
|
||||||
|
|
||||||
MainForm {
|
MainForm {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
openButton.onClicked: fileDialog.open()
|
openButton.onClicked: fileDialog.open()
|
||||||
|
@ -70,7 +75,8 @@ ApplicationWindow {
|
||||||
title: "Please choose a file"
|
title: "Please choose a file"
|
||||||
folder: shortcuts.home
|
folder: shortcuts.home
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
console.log("You chose: " + fileDialog.fileUrls)
|
console.log("You chose: " + fileDialog.fileUrl)
|
||||||
|
oboy.load(fileDialog.fileUrl)
|
||||||
}
|
}
|
||||||
onRejected: {
|
onRejected: {
|
||||||
console.log("Canceled")
|
console.log("Canceled")
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#include <caml/mlvalues.h>
|
#include <caml/mlvalues.h>
|
||||||
#include <caml/callback.h>
|
#include <caml/callback.h>
|
||||||
|
#include <caml/alloc.h>
|
||||||
|
#include <caml/misc.h>
|
||||||
|
#include <caml/osdeps.h>
|
||||||
|
|
||||||
OBoy::OBoy(QObject *parent) : QObject(parent)
|
OBoy::OBoy(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -29,3 +32,19 @@ QString OBoy::version() const
|
||||||
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
const char *str = String_val(caml_callback(*closure_f, Val_unit));
|
||||||
return QString(str);
|
return QString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OBoy::load(const QString &path)
|
||||||
|
{
|
||||||
|
value * closure_f = caml_named_value("oboy_load");
|
||||||
|
if (closure_f == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString truncated(path);
|
||||||
|
truncated.remove(0, 7); // remove file://
|
||||||
|
QByteArray ba = truncated.toLocal8Bit();
|
||||||
|
value ocaml_path = caml_copy_string_of_os(ba.data());
|
||||||
|
|
||||||
|
const bool success = Bool_val(caml_callback(*closure_f, ocaml_path));
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
class OBoy : public QObject
|
class OBoy : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString name READ name)
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
Q_PROPERTY(QString version READ version)
|
Q_PROPERTY(QString version READ version CONSTANT)
|
||||||
public:
|
public:
|
||||||
explicit OBoy(QObject *parent = nullptr);
|
explicit OBoy(QObject *parent = nullptr);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QString version() const;
|
QString version() const;
|
||||||
|
Q_INVOKABLE bool load(const QString &path);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue