Add memory to state
This commit is contained in:
parent
690df0321f
commit
3b9085545b
|
@ -2,4 +2,4 @@ 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;
|
Callback.register "oboy_load" State.load_cartridge;
|
||||||
Callback.register "oboy_bg_map" Memory.background_map;
|
Callback.register "oboy_bg_map" (Memory.background_map !State.state.memory);
|
||||||
|
|
|
@ -109,12 +109,13 @@ let update_timers mem cycles =
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let background_map () =
|
let background_map mem n =
|
||||||
let bg_map = Array2.create Bigarray.int8_unsigned Bigarray.c_layout 8 8 in
|
let bg_map = Array2.create Bigarray.int8_unsigned Bigarray.c_layout 8 8 in
|
||||||
Array2.fill bg_map 0;
|
Array2.fill bg_map 0;
|
||||||
for j = 0 to (Array2.dim2 bg_map) - 1 do
|
for j = 0 to (Array2.dim2 bg_map) - 1 do
|
||||||
for i = 0 to (Array2.dim1 bg_map) - 1 do
|
for i = 0 to (Array2.dim1 bg_map) - 1 do
|
||||||
bg_map.{i, j} <- (i + j * Array2.dim1 bg_map) mod 4
|
(* bg_map.{i, j} <- (i + j * Array2.dim1 bg_map) mod 4 *)
|
||||||
|
bg_map.{i, j} <- n
|
||||||
done
|
done
|
||||||
done;
|
done;
|
||||||
bg_map
|
bg_map
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
(* 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 = {
|
||||||
mutable cartridge : Cartridge.t option;
|
mutable cartridge : Cartridge.t option;
|
||||||
|
mutable memory : Memory.t option
|
||||||
}
|
}
|
||||||
|
|
||||||
(* Global reference *)
|
(* Global reference *)
|
||||||
let state = ref {
|
let state = ref {
|
||||||
cartridge = None
|
cartridge = None;
|
||||||
|
memory = None
|
||||||
}
|
}
|
||||||
|
|
||||||
let load_cartridge file =
|
let load_cartridge file =
|
||||||
let cartridge = Cartridge.read_cartridge file in
|
let cartridge = Cartridge.read_cartridge file in
|
||||||
!state.cartridge <- cartridge;
|
|
||||||
match cartridge with
|
match cartridge with
|
||||||
| Some c -> Cartridge.print_info c; true
|
| Some c -> begin
|
||||||
|
let memory = Memory.init c in
|
||||||
|
!state.cartridge <- cartridge;
|
||||||
|
!state.memory <- Some memory;
|
||||||
|
Cartridge.print_info c
|
||||||
|
end; true
|
||||||
| None -> false
|
| None -> false
|
||||||
|
|
|
@ -88,9 +88,11 @@ bool OBoy::loaded() const
|
||||||
return _loaded;
|
return _loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage OBoy::backgroundMap() const
|
QImage OBoy::backgroundMap(int index) const
|
||||||
{
|
{
|
||||||
CAMLparam0();
|
CAMLparam0();
|
||||||
|
CAMLlocal1(ocaml_index);
|
||||||
|
ocaml_index = index;
|
||||||
|
|
||||||
static value * closure_f = fetch_caml_callback("oboy_bg_map");
|
static value * closure_f = fetch_caml_callback("oboy_bg_map");
|
||||||
if (closure_f == nullptr) {
|
if (closure_f == nullptr) {
|
||||||
|
@ -98,7 +100,7 @@ QImage OBoy::backgroundMap() const
|
||||||
return QImage(0, 0, QImage::Format_Indexed8);
|
return QImage(0, 0, QImage::Format_Indexed8);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto bg_array = Caml_ba_array_val(caml_callback(*closure_f, Val_unit));
|
const auto bg_array = Caml_ba_array_val(caml_callback(*closure_f, Val_int(ocaml_index)));
|
||||||
const auto bg_raw_data = static_cast<caml_ba_uint8 *>(bg_array->data);
|
const auto bg_raw_data = static_cast<caml_ba_uint8 *>(bg_array->data);
|
||||||
|
|
||||||
Q_ASSERT(bg_array->num_dims == 2);
|
Q_ASSERT(bg_array->num_dims == 2);
|
||||||
|
|
|
@ -10,7 +10,6 @@ class OBoy : public QObject
|
||||||
Q_PROPERTY(QString name READ name CONSTANT)
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
Q_PROPERTY(QString version READ version CONSTANT)
|
Q_PROPERTY(QString version READ version CONSTANT)
|
||||||
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
|
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
|
||||||
Q_PROPERTY(QImage backgroundMap READ backgroundMap CONSTANT)
|
|
||||||
public:
|
public:
|
||||||
explicit OBoy(QObject *parent = nullptr);
|
explicit OBoy(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ public:
|
||||||
QString version() const;
|
QString version() const;
|
||||||
bool loaded() const;
|
bool loaded() const;
|
||||||
Q_INVOKABLE bool load(const QString &path);
|
Q_INVOKABLE bool load(const QString &path);
|
||||||
QImage backgroundMap() const;
|
QImage backgroundMap(int index) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadedChanged(bool loaded);
|
void loadedChanged(bool loaded);
|
||||||
|
|
|
@ -17,6 +17,6 @@ QImage OImageProvider::requestImage(const QString &id, QSize *size, const QSize
|
||||||
}
|
}
|
||||||
Q_ASSERT(oboy->loaded());
|
Q_ASSERT(oboy->loaded());
|
||||||
|
|
||||||
QImage img = oboy->backgroundMap();
|
QImage img = oboy->backgroundMap(0);
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue