Launcher now makes filesystem images but the OS wont execpt them

This commit is contained in:
meepingsnesroms
2019-05-22 18:06:18 -07:00
parent 9b09d19e19
commit c4eec6864b
9 changed files with 103 additions and 67 deletions

View File

@@ -138,48 +138,45 @@ void EmuWrapper::writeOutSaves(){
}
}
uint32_t EmuWrapper::init(const QString& romPath, const QString& bootloaderPath, const QString& ramPath, const QString& sdCardPath, uint32_t features){
uint32_t EmuWrapper::init(const QString& assetPath, const QString& model, const QString& osVersion, uint32_t features){
if(!emuRunning && !emuInited){
//start emu
uint32_t error;
QFile romFile(romPath);
QFile bootloaderFile(bootloaderPath);
QFile romFile(assetPath + "/palmos" + osVersion + "-" + model + ".rom");
QFile bootloaderFile(assetPath + "/bootloader-" + model + ".rom");
QFile ramFile(assetPath + "/userdata-" + model + ".ram");
QFile sdCardFile(assetPath + "/sd-" + model + ".img");
bool hasBootloader = true;
if(!romFile.open(QFile::ReadOnly | QFile::ExistingOnly))
return EMU_ERROR_INVALID_PARAMETER;
if(bootloaderPath != ""){
if(!bootloaderFile.open(QFile::ReadOnly | QFile::ExistingOnly))
return EMU_ERROR_INVALID_PARAMETER;
}
if(!bootloaderFile.open(QFile::ReadOnly | QFile::ExistingOnly))
hasBootloader = false;
error = emulatorInit((uint8_t*)romFile.readAll().data(), romFile.size(), (uint8_t*)bootloaderFile.readAll().data(), bootloaderFile.size(), features);
error = emulatorInit((uint8_t*)romFile.readAll().data(), romFile.size(), hasBootloader ? (uint8_t*)bootloaderFile.readAll().data() : NULL, hasBootloader ? bootloaderFile.size() : 0, features);
if(error == EMU_ERROR_NONE){
QTime now = QTime::currentTime();
emulatorSetRtc(QDate::currentDate().day(), now.hour(), now.minute(), now.second());
if(ramPath != ""){
QFile ramFile(ramPath);
if(ramFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
emulatorLoadRam((uint8_t*)ramFile.readAll().data(), ramFile.size());
ramFile.close();
}
if(ramFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
emulatorLoadRam((uint8_t*)ramFile.readAll().data(), ramFile.size());
ramFile.close();
}
if(sdCardPath != ""){
QFile sdCardFile(sdCardPath);
if(sdCardFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
emulatorInsertSdCard((uint8_t*)sdCardFile.readAll().data(), sdCardFile.size(), NULL);
sdCardFile.close();
}
if(sdCardFile.open(QFile::ReadOnly | QFile::ExistingOnly)){
emulatorInsertSdCard((uint8_t*)sdCardFile.readAll().data(), sdCardFile.size(), NULL);
sdCardFile.close();
}
emuInput = palmInput;
emuRamFilePath = ramPath;
emuSdCardFilePath = sdCardPath;
emuRamFilePath = assetPath + "/userdata-" + model + ".ram";
emuSdCardFilePath = assetPath + "/sd-" + model + ".img";
emuSaveStatePath = assetPath + "/states-" + model + ".states";
//make the place to store the saves
QDir(assetPath + "states-" + model + ".states").mkdir(".");
emuThreadJoin = false;
emuInited = true;
@@ -193,8 +190,7 @@ uint32_t EmuWrapper::init(const QString& romPath, const QString& bootloaderPath,
}
romFile.close();
if(bootloaderPath != "")
bootloaderFile.close();
bootloaderFile.close();
}
return EMU_ERROR_NONE;
@@ -367,6 +363,10 @@ uint32_t EmuWrapper::bootFromFileOrDirectory(const QString& mainPath){
//everything worked, set output save files
emuRamFilePath = mainPath + ".ram";
emuSdCardFilePath = mainPath + ".sd.img";
emuSaveStatePath = mainPath + ".states";
//make the place to store the saves
QDir(mainPath + ".states").mkdir(".");
//need this goto because the emulator must be released before returning
errorOccurred:
@@ -377,10 +377,10 @@ uint32_t EmuWrapper::bootFromFileOrDirectory(const QString& mainPath){
return error;
}
uint32_t EmuWrapper::saveState(const QString& path){
uint32_t EmuWrapper::saveState(const QString& name){
bool wasPaused = isPaused();
uint32_t error = EMU_ERROR_INVALID_PARAMETER;
QFile stateFile(path);
QFile stateFile(emuSaveStatePath + "/" + name + ".state");
if(!wasPaused)
pause();
@@ -403,10 +403,10 @@ uint32_t EmuWrapper::saveState(const QString& path){
return error;
}
uint32_t EmuWrapper::loadState(const QString& path){
uint32_t EmuWrapper::loadState(const QString& name){
bool wasPaused = isPaused();
uint32_t error = EMU_ERROR_INVALID_PARAMETER;
QFile stateFile(path);
QFile stateFile(emuSaveStatePath + "/" + name + ".state");
if(!wasPaused)
pause();

View File

@@ -24,6 +24,7 @@ private:
std::atomic<bool> emuNewFrameReady;
QString emuRamFilePath;
QString emuSdCardFilePath;
QString emuSaveStatePath;
input_t emuInput;
void emuThreadRun();
@@ -44,14 +45,15 @@ public:
EmuWrapper();
~EmuWrapper();
uint32_t init(const QString& romPath, const QString& bootloaderPath = "", const QString& ramPath = "", const QString& sdCardPath = "", uint32_t features = FEATURE_ACCURATE);
uint32_t init(const QString& assetPath, const QString& model, const QString& osVersion, uint32_t features = FEATURE_ACCURATE);
void exit();
void pause();
void resume();
void reset(bool hard);
uint32_t bootFromFileOrDirectory(const QString& mainPath);
uint32_t saveState(const QString& path);
uint32_t loadState(const QString& path);
const QString& getStatePath() const{return emuSaveStatePath;}//needed for looking up state pictures in the GUI
uint32_t saveState(const QString& name);
uint32_t loadState(const QString& name);
bool isInited() const{return emuInited;}
bool isRunning() const{return emuRunning;}
bool isPaused() const{return emuPaused;}

View File

@@ -162,7 +162,6 @@ void MainWindow::createHomeDirectoryTree(const QString& path){
//creates directorys if not present, does nothing if they exist already
homeDir.mkpath(".");
homeDir.mkpath("./saveStates");
homeDir.mkpath("./screenshots");
homeDir.mkpath("./debugDumps");
}
@@ -320,7 +319,7 @@ void MainWindow::on_ctrlBtn_clicked(){
if(!emu.isInited()){
uint32_t enabledFeatures = getEmuFeatureList();
QString sysDir = settings->value("resourceDirectory", "").toString();
uint32_t error = emu.init(sysDir + "/palmos41-en-m515.rom", QFile(sysDir + "/bootloader-en-m515.rom").exists() ? sysDir + "/bootloader-en-m515.rom" : "", sysDir + "/userdata-en-m515.ram", sysDir + "/sd-en-m515.img", enabledFeatures);
uint32_t error = emu.init(sysDir, "en-m515", "41", enabledFeatures);
if(error == EMU_ERROR_NONE){
ui->up->setEnabled(true);
@@ -431,13 +430,24 @@ void MainWindow::on_settings_clicked(){
void MainWindow::on_bootApp_clicked(){
if(emu.isInited()){
QString appDir = QFileDialog::getExistingDirectory(this, "Select Directory", QDir::root().path());
QString appDir;
bool loadedNewApp = false;
bool wasPaused = emu.isPaused();
if(!wasPaused)
emu.pause();
appDir = QFileDialog::getExistingDirectory(this, "Select Directory", QDir::root().path());
if(appDir != ""){
uint32_t error = emu.bootFromFileOrDirectory(appDir);
if(error != EMU_ERROR_NONE)
if(error == EMU_ERROR_NONE)
loadedNewApp = true;
else
popupErrorDialog("Could not load apps, Error:" + QString::number(error));
}
if(!wasPaused || loadedNewApp)
emu.resume();
}
}

View File

@@ -15,7 +15,7 @@
StateManager::StateManager(QWidget* parent) :
QDialog(parent),
ui(new Ui::StateManager){
settings = ((MainWindow*)parent)->settings;
emu = &((MainWindow*)parent)->emu;
//init GUI
ui->setupUi(this);
@@ -39,8 +39,7 @@ bool StateManager::eventFilter(QObject* object, QEvent* event){
}
void StateManager::updateStateList(){
QString saveDirPath = settings->value("resourceDirectory", "").toString() + "/saveStates";
QDir saveDir(saveDirPath);
QDir saveDir(emu->getStatePath());
QStringList saveStateNames;
QStringList filter;
@@ -60,7 +59,7 @@ void StateManager::updateStateList(){
void StateManager::updateStatePreview(){
if(ui->states->currentItem()){
QString statePath = settings->value("resourceDirectory", "").toString() + "/saveStates/" + ui->states->currentItem()->text();
QString statePath = emu->getStatePath() + "/" + ui->states->currentItem()->text();
ui->statePreview->setPixmap(QPixmap(statePath + ".png").scaled(ui->statePreview->width() * 0.98, ui->statePreview->height() * 0.98, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
@@ -83,9 +82,9 @@ int StateManager::getStateIndexRowByName(const QString& name){
void StateManager::on_saveState_clicked(){
if(ui->newStateName->text() != ""){
MainWindow* parent = (MainWindow*)parentWidget();
QString statePath = settings->value("resourceDirectory", "").toString() + "/saveStates/" + ui->newStateName->text();
QString statePath = emu->getStatePath() + "/" + ui->newStateName->text();
parent->emu.saveState(statePath + ".state");
parent->emu.saveState(ui->newStateName->text());
parent->emu.getFramebuffer().save(statePath + ".png");
updateStateList();
@@ -96,15 +95,15 @@ void StateManager::on_saveState_clicked(){
void StateManager::on_loadState_clicked(){
if(ui->states->currentItem()){
MainWindow* parent = (MainWindow*)parentWidget();
QString statePath = settings->value("resourceDirectory", "").toString() + "/saveStates/" + ui->states->currentItem()->text();
QString statePath = emu->getStatePath() + "/" + ui->states->currentItem()->text();
parent->emu.loadState(statePath + ".state");
parent->emu.loadState(ui->states->currentItem()->text());
}
}
void StateManager::on_deleteState_clicked(){
if(ui->states->currentItem()){
QString statePath = settings->value("resourceDirectory", "").toString() + "/saveStates/" + ui->states->currentItem()->text();
QString statePath = emu->getStatePath() + "/" + ui->states->currentItem()->text();
QFile(statePath + ".state").remove();
QFile(statePath + ".png").remove();

View File

@@ -4,7 +4,9 @@
#include <QObject>
#include <QEvent>
#include <QListWidgetItem>
#include <QSettings>
#include <QString>
#include "emuwrapper.h"
namespace Ui{
class StateManager;
@@ -32,5 +34,5 @@ private slots:
private:
Ui::StateManager* ui;
QSettings* settings;
EmuWrapper* emu;
};

View File

@@ -101,7 +101,7 @@ uint32_t emulatorInit(uint8_t* palmRomData, uint32_t palmRomSize, uint8_t* palmB
bool dynarecInited = false;
dynarecInited = pxa255Init(&palmRom, &palmRam);
palmFramebuffer = malloc(320 * 320 * sizeof(uint16_t));
palmFramebuffer = malloc(320 * 480 * sizeof(uint16_t));
palmAudio = malloc(AUDIO_SAMPLES_PER_FRAME * 2 * sizeof(int16_t));
palmAudioResampler = blip_new(AUDIO_SAMPLE_RATE);//have 1 second of samples
if(!palmFramebuffer || !palmAudio || !palmAudioResampler || !dynarecInited){
@@ -115,14 +115,14 @@ uint32_t emulatorInit(uint8_t* palmRomData, uint32_t palmRomSize, uint8_t* palmB
if(palmRomSize < TUNGSTEN_T3_ROM_SIZE)
memset(palmRom + palmRomSize, 0x00, TUNGSTEN_T3_ROM_SIZE - palmRomSize);
memset(palmRam, 0x00, TUNGSTEN_T3_RAM_SIZE);
memset(palmFramebuffer, 0x00, 320 * 320 * sizeof(uint16_t));//TODO:PXA255 code doesnt always output a picture like my SED1376 code, so clear the buffer to prevent garbage from being displayed before the first render
memset(palmFramebuffer, 0x00, 320 * 480 * sizeof(uint16_t));//TODO:PXA255 code doesnt always output a picture like my SED1376 code, so clear the buffer to prevent garbage from being displayed before the first render
memset(palmAudio, 0x00, AUDIO_SAMPLES_PER_FRAME * 2/*channels*/ * sizeof(int16_t));
memset(&palmInput, 0x00, sizeof(palmInput));
memset(&palmMisc, 0x00, sizeof(palmMisc));
memset(&palmSdCard, 0x00, sizeof(palmSdCard));
memset(&palmEmuFeatures, 0x00, sizeof(palmEmuFeatures));
palmFramebufferWidth = 320;
palmFramebufferHeight = 320;
palmFramebufferHeight = 480;
palmMisc.batteryLevel = 100;
palmCycleCounter = 0.0;
palmEmuFeatures.info = enabledEmuFeatures;

View File

@@ -7,7 +7,6 @@
#define DEV_RAM 0
#define PALM_SD_CARD_SECTOR_SIZE 512
static bool cardInitalized = false;
@@ -38,7 +37,6 @@ DSTATUS disk_initialize (
)
{
if(pdrv == DEV_RAM){
memset(palmSdCard.flashChipData, 0x00, palmSdCard.flashChipSize);
cardInitalized = true;
return 0x00;
}
@@ -60,10 +58,10 @@ DRESULT disk_read (
)
{
if(pdrv == DEV_RAM){
if(!(sector * PALM_SD_CARD_SECTOR_SIZE + PALM_SD_CARD_SECTOR_SIZE < palmSdCard.flashChipSize))
if(!(sector * SD_CARD_BLOCK_SIZE + SD_CARD_BLOCK_SIZE <= palmSdCard.flashChipSize))
return RES_ERROR;
memcpy(buff, palmSdCard.flashChipData + sector * PALM_SD_CARD_SECTOR_SIZE, count * PALM_SD_CARD_SECTOR_SIZE);
memcpy(buff, palmSdCard.flashChipData + sector * SD_CARD_BLOCK_SIZE, count * SD_CARD_BLOCK_SIZE);
return RES_OK;
}
@@ -86,10 +84,10 @@ DRESULT disk_write (
)
{
if(pdrv == DEV_RAM){
if(!(sector * PALM_SD_CARD_SECTOR_SIZE + PALM_SD_CARD_SECTOR_SIZE < palmSdCard.flashChipSize))
if(!(sector * SD_CARD_BLOCK_SIZE + SD_CARD_BLOCK_SIZE <= palmSdCard.flashChipSize))
return RES_ERROR;
memcpy(palmSdCard.flashChipData + sector * PALM_SD_CARD_SECTOR_SIZE, buff, count * PALM_SD_CARD_SECTOR_SIZE);
memcpy(palmSdCard.flashChipData + sector * SD_CARD_BLOCK_SIZE, buff, count * SD_CARD_BLOCK_SIZE);
return RES_OK;
}
@@ -112,7 +110,16 @@ DRESULT disk_ioctl (
if(pdrv == DEV_RAM){
switch(cmd){
case GET_BLOCK_SIZE:
*((uint32_t*)buff) = PALM_SD_CARD_SECTOR_SIZE;
case GET_SECTOR_SIZE:
*((uint32_t*)buff) = SD_CARD_BLOCK_SIZE;
return RES_OK;
case GET_SECTOR_COUNT:
*((uint32_t*)buff) = palmSdCard.flashChipSize / SD_CARD_BLOCK_SIZE;
return RES_OK;
case CTRL_SYNC:
//do nothing
return RES_OK;
default:

View File

@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "../emulator.h"
#include "../portability.h"
@@ -7,7 +8,7 @@
#include "fatFs/ff.h"
#define LAUNCHER_SD_CARD_SIZE (32 * 0x100000) //SD card size for the default boot configuration
#define LAUNCHER_SD_CARD_SIZE (16 * 0x100000) //SD card size for the default boot configuration
#define LAUNCHER_BOOT_TIMEOUT 10 //in seconds
bool launcherSaveSdCardImage;
@@ -46,7 +47,7 @@ static uint32_t launcherMakeBootRecord(const char* appName){
FRESULT result;
uint32_t written;
result = f_open(&record, "0/PASSME/BOOT.TXT", FA_WRITE | FA_CREATE_ALWAYS);
result = f_open(&record, "0:/PASSME/BOOT.TXT", FA_WRITE | FA_CREATE_ALWAYS);
if(result != FR_OK)
return EMU_ERROR_UNKNOWN;
@@ -67,7 +68,7 @@ static uint32_t launcherCopyPrcPdbPqaToSdCard(launcher_file_t* file, uint32_t* f
FRESULT result;
uint32_t written;
sprintf(name, "0/PASSME/%d.%s", *fileId, launcherGetFileExtension(file->type));
sprintf(name, "0:/PASSME/%d.%s", *fileId, launcherGetFileExtension(file->type));
result = f_open(&application, name, FA_WRITE | FA_CREATE_ALWAYS);
if(result != FR_OK)
@@ -101,17 +102,26 @@ static uint32_t launcherCopyPrcPdbPqaToSdCard(launcher_file_t* file, uint32_t* f
static uint32_t launcherSetupSdCardImageFromApps(launcher_file_t* files, uint32_t fileCount){
uint32_t fileId = 0;//first file is named 0.p**, next is 1.p**, and the name continues going up with the file count
FATFS* fsData;
FRESULT result;
uint32_t error;
uint32_t index;
//setup filesystem
result = f_mkfs("0", FM_FAT, 4096, NULL, 0);
result = f_mkfs("0:/", FM_FAT, SD_CARD_BLOCK_SIZE, NULL, 0);
if(result != FR_OK)
return EMU_ERROR_UNKNOWN;
fsData = malloc(sizeof(FATFS));
if(!fsData)
return EMU_ERROR_OUT_OF_MEMORY;
result = f_mount(fsData, "0:/", 1);
if(result != FR_OK)
return EMU_ERROR_UNKNOWN;
//setup directory
result = f_mkdir("0/PASSME");
result = f_mkdir("0:/PASSME");
if(result != FR_OK)
return EMU_ERROR_UNKNOWN;
@@ -134,6 +144,9 @@ static uint32_t launcherSetupSdCardImageFromApps(launcher_file_t* files, uint32_
return error;
}
f_unmount("0:/");
free(fsData);
return EMU_ERROR_NONE;
}
@@ -287,6 +300,8 @@ uint32_t launcherLaunch(launcher_file_t* files, uint32_t fileCount, uint8_t* sra
emulatorSoftReset();
//leave this off until I make the PassMe program
/*
//execute frames until launch is completed(or failed with a time out)
success = false;
palmEmuFeatures.value = cardImageHasBeenLoaded ? 'RUNC' : 'RUNA';
@@ -301,6 +316,7 @@ uint32_t launcherLaunch(launcher_file_t* files, uint32_t fileCount, uint8_t* sra
//timed out
if(!success)
return EMU_ERROR_RESOURCE_LOCKED;
*/
//worked
return EMU_ERROR_NONE;

View File

@@ -1,13 +1,13 @@
#ifndef TUNGSTEN_C_BUS_H
#define TUNGSTEN_C_BUS_H
#ifndef TUNGSTEN_T3_BUS_H
#define TUNGSTEN_T3_BUS_H
#define PXA255_ROM_START_ADDRESS 0x00000000
#define PXA255_RAM_START_ADDRESS 0xA0000000
#define PXA255_PCMCIA0_START_ADDRESS 0x20000000
#define PXA255_PCMCIA1_START_ADDRESS 0x30000000
#define PXA255_REG_START_ADDRESS 0x40000000
#define TUNGSTEN_C_ROM_SIZE (10 * 0x100000)//10mb ROM
#define TUNGSTEN_C_RAM_SIZE (64 * 0x100000)//64mb RAM
#define TUNGSTEN_T3_ROM_SIZE (10 * 0x100000)//10mb ROM
#define TUNGSTEN_T3_RAM_SIZE (64 * 0x100000)//64mb RAM
#define PXA255_PCMCIA0_SIZE 0x10000000
#define PXA255_PCMCIA1_SIZE 0x10000000
#define PXA255_REG_SIZE 0x0C000000