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_version" Version.version;
|
||||
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
|
||||
|
||||
let background_map () =
|
||||
let background_map mem n =
|
||||
let bg_map = Array2.create Bigarray.int8_unsigned Bigarray.c_layout 8 8 in
|
||||
Array2.fill bg_map 0;
|
||||
for j = 0 to (Array2.dim2 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;
|
||||
bg_map
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
(* State of the world, contains all the required information at any point *)
|
||||
type t = {
|
||||
mutable cartridge : Cartridge.t option;
|
||||
mutable memory : Memory.t option
|
||||
}
|
||||
|
||||
(* Global reference *)
|
||||
let state = ref {
|
||||
cartridge = None
|
||||
cartridge = None;
|
||||
memory = None
|
||||
}
|
||||
|
||||
let load_cartridge file =
|
||||
let cartridge = Cartridge.read_cartridge file in
|
||||
!state.cartridge <- cartridge;
|
||||
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
|
||||
|
|
|
@ -88,9 +88,11 @@ bool OBoy::loaded() const
|
|||
return _loaded;
|
||||
}
|
||||
|
||||
QImage OBoy::backgroundMap() const
|
||||
QImage OBoy::backgroundMap(int index) const
|
||||
{
|
||||
CAMLparam0();
|
||||
CAMLlocal1(ocaml_index);
|
||||
ocaml_index = index;
|
||||
|
||||
static value * closure_f = fetch_caml_callback("oboy_bg_map");
|
||||
if (closure_f == nullptr) {
|
||||
|
@ -98,7 +100,7 @@ QImage OBoy::backgroundMap() const
|
|||
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);
|
||||
|
||||
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 version READ version CONSTANT)
|
||||
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
|
||||
Q_PROPERTY(QImage backgroundMap READ backgroundMap CONSTANT)
|
||||
public:
|
||||
explicit OBoy(QObject *parent = nullptr);
|
||||
|
||||
|
@ -18,7 +17,7 @@ public:
|
|||
QString version() const;
|
||||
bool loaded() const;
|
||||
Q_INVOKABLE bool load(const QString &path);
|
||||
QImage backgroundMap() const;
|
||||
QImage backgroundMap(int index) const;
|
||||
|
||||
signals:
|
||||
void loadedChanged(bool loaded);
|
||||
|
|
|
@ -17,6 +17,6 @@ QImage OImageProvider::requestImage(const QString &id, QSize *size, const QSize
|
|||
}
|
||||
Q_ASSERT(oboy->loaded());
|
||||
|
||||
QImage img = oboy->backgroundMap();
|
||||
QImage img = oboy->backgroundMap(0);
|
||||
return img;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue