Skip to content

Commit

Permalink
Implemented system memory
Browse files Browse the repository at this point in the history
  • Loading branch information
egordorichev committed Apr 13, 2022
1 parent 729b47f commit 7bcf78b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion include/pemsa/pemsa_emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "pemsa/util/pemsa_util.hpp"
#include "lua.h"

#define PEMSA_MODULE_COUNT 6
#define PEMSA_MODULE_COUNT 7

class PemsaEmulator {
public:
Expand All @@ -27,8 +27,12 @@ class PemsaEmulator {
PemsaInputModule* getInputModule();
PemsaCartridgeModule* getCartridgeModule();
PemsaMemoryModule* getMemoryModule();
PemsaMemoryModule* getActualMemoryModule();
PemsaMemoryModule* getSystemMemoryModule();
PemsaDrawStateModule* getDrawStateModule();

void setMemoryModule(PemsaMemoryModule* module);

void stop();
private:
PemsaModule* modules[PEMSA_MODULE_COUNT];
Expand All @@ -38,8 +42,11 @@ class PemsaEmulator {
PemsaInputModule* inputModule;
PemsaCartridgeModule* cartridgeModule;
PemsaMemoryModule* memoryModule;
PemsaMemoryModule* systemMemoryModule;
PemsaDrawStateModule* drawStateModule;

PemsaMemoryModule* currentMemoryModule;

bool* running;
};

Expand Down
2 changes: 2 additions & 0 deletions src/pemsa/cart/pemsa_cartridge_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ void PemsaCartridgeModule::stop() {
}

void PemsaCartridgeModule::waitForNextFrame() {
this->emulator->setMemoryModule(this->emulator->getSystemMemoryModule());
this->callIfExists("__update_menu");
this->emulator->setMemoryModule(this->emulator->getActualMemoryModule());

this->waiting = true;
std::unique_lock<std::mutex> uniqueLock(this->mutex);
Expand Down
1 change: 1 addition & 0 deletions src/pemsa/cart/pemsa_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ local __menu_on=false
local __menu_functions={}
local __favorite=false
function __update_menu()
cls(15)
if not btnp(6) and not __menu_on then return end
local __menu_options={}
Expand Down
2 changes: 2 additions & 0 deletions src/pemsa/memory/pemsa_draw_state_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void PemsaDrawStateModule::reset() {

ram[PEMSA_RAM_DRAW_COLOR] = 6;
ram[PEMSA_RAM_DRAW_MODE] = 0;

// TODO: reset PEMSA_RAM_FILL_PATTERN?
}

bool PemsaDrawStateModule::isTransparent(int color) {
Expand Down
24 changes: 23 additions & 1 deletion src/pemsa/pemsa_emulator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "pemsa/pemsa_emulator.hpp"
#include "pemsa/util/pemsa_font.hpp"

#include <cstring>

PemsaEmulator::PemsaEmulator(PemsaGraphicsBackend *graphics, PemsaAudioBackend *audio, PemsaInputBackend *input, bool* running, bool enableSplash) {
this->running = running;
pemsa_setup_font();
Expand All @@ -13,8 +15,16 @@ PemsaEmulator::PemsaEmulator(PemsaGraphicsBackend *graphics, PemsaAudioBackend *
this->modules[1] = (PemsaModule*) (this->audioModule = new PemsaAudioModule(this, audio));
this->modules[2] = (PemsaModule*) (this->inputModule = new PemsaInputModule(this, input));
this->modules[3] = (PemsaModule*) (this->cartridgeModule = new PemsaCartridgeModule(this, enableSplash));
this->modules[4] = (PemsaModule*) (this->memoryModule = new PemsaMemoryModule(this));
this->modules[4] = (PemsaModule*) (this->memoryModule = this->currentMemoryModule = new PemsaMemoryModule(this));
this->modules[5] = (PemsaModule*) (this->drawStateModule = new PemsaDrawStateModule(this));
this->modules[6] = (PemsaModule*) (this->systemMemoryModule = new PemsaMemoryModule(this));

this->currentMemoryModule = this->systemMemoryModule;
this->drawStateModule->reset();
this->currentMemoryModule = this->memoryModule;

// Clear the system screen with pink (color 15), so that it is transparent
memset(this->systemMemoryModule->ram + PEMSA_RAM_SCREEN, (15 << 4) + 15, 0x2000);
}

PemsaEmulator::~PemsaEmulator() {
Expand Down Expand Up @@ -49,13 +59,25 @@ PemsaCartridgeModule *PemsaEmulator::getCartridgeModule() {
}

PemsaMemoryModule *PemsaEmulator::getMemoryModule() {
return this->currentMemoryModule;
}

PemsaMemoryModule *PemsaEmulator::getActualMemoryModule() {
return this->memoryModule;
}

PemsaMemoryModule *PemsaEmulator::getSystemMemoryModule() {
return this->systemMemoryModule;
}

PemsaDrawStateModule *PemsaEmulator::getDrawStateModule() {
return this->drawStateModule;
}

void PemsaEmulator::setMemoryModule(PemsaMemoryModule* module) {
this->currentMemoryModule = module;
}

void PemsaEmulator::reset() {
for (int i = 0; i < PEMSA_MODULE_COUNT; i++) {
this->modules[i]->reset();
Expand Down

0 comments on commit 7bcf78b

Please sign in to comment.