Skip to content

Commit

Permalink
Initializes vmm_draw (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Jul 30, 2024
1 parent 52d1a72 commit 8621f8b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ struct RustError *update_firmware(const char *root,
void *cx,
void (*status)(const char*, uint64_t, uint64_t, void*));

struct Vmm *vmm_new(struct RustError **err);
struct Vmm *vmm_new(size_t screen, struct RustError **err);

void vmm_free(struct Vmm *vmm);

struct RustError *vmm_run(struct Vmm *vmm, const char *kernel);

struct RustError *vmm_draw(struct Vmm *vmm);

void vmm_logs(const struct Vmm *vmm, void *cx, void (*cb)(uint8_t, const char*, size_t, void*));

#if defined(__linux__)
Expand Down
7 changes: 6 additions & 1 deletion src/core/src/vmm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ELF_MACHINE: u16 = 62;
const ELF_MACHINE: u16 = 183;

#[no_mangle]
pub unsafe extern "C" fn vmm_new(err: *mut *mut RustError) -> *mut Vmm {
pub unsafe extern "C" fn vmm_new(screen: usize, err: *mut *mut RustError) -> *mut Vmm {
// Setup RAM.
let ram = match Ram::new() {
Ok(v) => Arc::new(v),
Expand Down Expand Up @@ -273,6 +273,11 @@ pub unsafe extern "C" fn vmm_run(vmm: *mut Vmm, kernel: *const c_char) -> *mut R
null_mut()
}

#[no_mangle]
pub unsafe extern "C" fn vmm_draw(vmm: *mut Vmm) -> *mut RustError {
null_mut()
}

#[no_mangle]
pub unsafe extern "C" fn vmm_logs(
vmm: *const Vmm,
Expand Down
33 changes: 32 additions & 1 deletion src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ MainWindow::MainWindow() :
// Screen.
m_screen = new Screen();

connect(m_screen, &Screen::updateRequestReceived, this, &MainWindow::updateScreen);

m_main->addWidget(createWindowContainer(m_screen));

// Show the window.
Expand Down Expand Up @@ -298,7 +300,7 @@ void MainWindow::startKernel()
Rust<RustError> error;
Rust<Vmm> vmm;

vmm = vmm_new(&error);
vmm = vmm_new(m_screen->winId(), &error);

if (!vmm) {
QMessageBox::critical(
Expand All @@ -320,7 +322,36 @@ void MainWindow::startKernel()
}

m_kernel = std::move(vmm);

// Swap launch settings with the screen and start drawing loop.
m_main->setCurrentIndex(1);
m_screen->requestUpdate();
}

void MainWindow::updateScreen()
{
// Do nothing if the kernel is not running.
if (!m_kernel) {
return;
}

// Draw the screen.
Rust<RustError> error;

error = vmm_draw(m_kernel);

if (error) {
m_kernel.free();

QMessageBox::critical(
this,
"Error",
QString("Couldn't draw the screen: %1").arg(error_message(error)));
return;
}

// Queue next update.
m_screen->requestUpdate();
}

bool MainWindow::loadGame(const QString &gameId)
Expand Down
1 change: 1 addition & 0 deletions src/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private slots:
void reportIssue();
void aboutObliteration();
void startKernel();
void updateScreen();

private:
bool loadGame(const QString &gameId);
Expand Down
9 changes: 9 additions & 0 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ Screen::Screen()
Screen::~Screen()
{
}

bool Screen::event(QEvent *ev)
{
if (ev->type() == QEvent::UpdateRequest) {
emit updateRequestReceived();
}

return QWindow::event(ev);
}
5 changes: 5 additions & 0 deletions src/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#include <QWindow>

class Screen final : public QWindow {
Q_OBJECT
public:
Screen();
~Screen() override;
signals:
void updateRequestReceived();
protected:
bool event(QEvent *ev) override;
};

0 comments on commit 8621f8b

Please sign in to comment.