From f0f93ce074f6936f65142c15e77ee6dca5468902 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Thu, 12 Apr 2018 11:13:11 -0700 Subject: [PATCH] Uses spaces in Qt code for consistancy, fix PDDATA being set as PADATA Also remove tabs qt put in emulator sources. --- libretroBuildSystem/libretro.c | 2 +- qtBuildSystem/Mu/Mu.pro.user | 2 +- qtBuildSystem/Mu/mainwindow.cpp | 284 ++++++++++++++++---------------- qtBuildSystem/Mu/mainwindow.h | 66 ++++---- src/emulator.c | 7 +- src/emulator.h | 4 +- src/hardwareRegisters.c | 14 +- src/sed1376.c | 2 +- 8 files changed, 191 insertions(+), 190 deletions(-) diff --git a/libretroBuildSystem/libretro.c b/libretroBuildSystem/libretro.c index ddd5d52..b2189db 100644 --- a/libretroBuildSystem/libretro.c +++ b/libretroBuildSystem/libretro.c @@ -202,7 +202,7 @@ bool retro_load_game(const struct retro_game_info *info) fclose(romFile); if(bytesRead == ROM_SIZE) - emulatorInit(palmRom, ACCURATE); + emulatorInit(palmRom, NULL/*bootloader*/, ACCURATE); else return false; diff --git a/qtBuildSystem/Mu/Mu.pro.user b/qtBuildSystem/Mu/Mu.pro.user index a854def..2cecaba 100644 --- a/qtBuildSystem/Mu/Mu.pro.user +++ b/qtBuildSystem/Mu/Mu.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/qtBuildSystem/Mu/mainwindow.cpp b/qtBuildSystem/Mu/mainwindow.cpp index a21eb6d..5153310 100644 --- a/qtBuildSystem/Mu/mainwindow.cpp +++ b/qtBuildSystem/Mu/mainwindow.cpp @@ -31,242 +31,244 @@ static uint8_t romBuffer[ROM_SIZE]; void popupErrorDialog(std::string error){ - //add error dialog code + //add error dialog code } uint8_t* getFileBuffer(std::string filePath, size_t& size, uint32_t& error){ - uint8_t* rawData = NULL; - if(filePath != ""){ - struct stat st; - int doesntExist = stat(filePath.c_str(), &st); - if(doesntExist == 0 && st.st_size){ - FILE* dataFile = fopen(filePath.c_str(), "rb"); - if(dataFile != NULL){ - rawData = new (std::nothrow) uint8_t[st.st_size]; - if(rawData){ - size_t bytesRead = fread(rawData, 1, st.st_size, dataFile); - if(bytesRead == st.st_size){ - size = bytesRead; - error = FRONTEND_ERR_NONE; - } - else{ - error = FRONTEND_FILE_UNFINISHED; - } - } - else{ - error = FRONTEND_OUT_OF_MEMORY; - } - fclose(dataFile); - } - else{ - error = FRONTEND_FILE_PROTECTED; - } - } - else{ - error = FRONTEND_FILE_DOESNT_EXIST; - } - } - else{ - error = FRONTEND_FILE_EMPTY_PATH; - } + uint8_t* rawData = NULL; + if(filePath != ""){ + struct stat st; + int doesntExist = stat(filePath.c_str(), &st); + if(doesntExist == 0 && st.st_size){ + FILE* dataFile = fopen(filePath.c_str(), "rb"); + if(dataFile != NULL){ + rawData = new (std::nothrow) uint8_t[st.st_size]; + if(rawData){ + size_t bytesRead = fread(rawData, 1, st.st_size, dataFile); + if(bytesRead == st.st_size){ + size = bytesRead; + error = FRONTEND_ERR_NONE; + } + else{ + error = FRONTEND_FILE_UNFINISHED; + } + } + else{ + error = FRONTEND_OUT_OF_MEMORY; + } + fclose(dataFile); + } + else{ + error = FRONTEND_FILE_PROTECTED; + } + } + else{ + error = FRONTEND_FILE_DOESNT_EXIST; + } + } + else{ + error = FRONTEND_FILE_EMPTY_PATH; + } - if(error != FRONTEND_ERR_NONE){ - if(rawData) - delete[] rawData; - rawData = NULL; - size = 0; - } + if(error != FRONTEND_ERR_NONE){ + if(rawData) + delete[] rawData; + rawData = NULL; + size = 0; + } - return rawData; + return rawData; } MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow){ - ui->setupUi(this); - emuOn = false; - emuInited = false; - screenWidth = 160; - screenHeight = 160 + 60; + ui->setupUi(this); + emuOn = false; + emuInited = false; + screenWidth = 160; + screenHeight = 160 + 60; - loadRom(); + loadRom(); - ui->ctrlBtn->setText("Start"); + ui->ctrlBtn->setText("Start"); - refreshDisplay = new QTimer(this); - connect(refreshDisplay, SIGNAL(timeout()), this, SLOT(updateDisplay())); - //update display every 16.67 miliseconds = 60*second - refreshDisplay->start(16); + refreshDisplay = new QTimer(this); + connect(refreshDisplay, SIGNAL(timeout()), this, SLOT(updateDisplay())); + //update display every 16.67 miliseconds = 60*second + refreshDisplay->start(16); } MainWindow::~MainWindow(){ - emuMutex.lock(); - emulatorExit(); - emuMutex.unlock(); - delete ui; + emuMutex.lock(); + emulatorExit(); + emuMutex.unlock(); + delete ui; } void MainWindow::loadRom(){ - std::string rom = settings.value("romPath", "").toString().toStdString(); - if(rom == ""){ - //keep the selector open until a valid file is picked - while(settings.value("romPath", "").toString().toStdString() == "") - selectRom(); - } + std::string rom = settings.value("romPath", "").toString().toStdString(); + if(rom == ""){ + //keep the selector open until a valid file is picked + while(settings.value("romPath", "").toString().toStdString() == "") + selectRom(); + } - uint32_t error; - size_t size; - uint8_t* romData = getFileBuffer(rom, size, error); - if(romData){ - size_t romSize = size < ROM_SIZE ? size : ROM_SIZE; - memcpy(romBuffer, romData, romSize); - delete[] romData; - } + uint32_t error; + size_t size; + uint8_t* romData = getFileBuffer(rom, size, error); + if(romData){ + size_t romSize = size < ROM_SIZE ? size : ROM_SIZE; + memcpy(romBuffer, romData, romSize); + if(romSize < ROM_SIZE) + memset(romBuffer + romSize, 0x00, ROM_SIZE - romSize); + delete[] romData; + } - if(error != FRONTEND_ERR_NONE){ - popupErrorDialog("Could not open ROM file"); - } + if(error != FRONTEND_ERR_NONE){ + popupErrorDialog("Could not open ROM file"); + } } void MainWindow::selectRom(){ - std::string rom = QFileDialog::getOpenFileName(this, "Palm OS ROM (palmos41-en-m515.rom)", QDir::root().path(), 0).toStdString(); - uint32_t error; - size_t size; - uint8_t* romData = getFileBuffer(rom, size, error); - if(romData){ - //valid file - settings.setValue("romPath", QString::fromStdString(rom)); - delete[] romData; - } + std::string rom = QFileDialog::getOpenFileName(this, "Palm OS ROM (palmos41-en-m515.rom)", QDir::root().path(), 0).toStdString(); + uint32_t error; + size_t size; + uint8_t* romData = getFileBuffer(rom, size, error); + if(romData){ + //valid file + settings.setValue("romPath", QString::fromStdString(rom)); + delete[] romData; + } - if(error != FRONTEND_ERR_NONE){ - popupErrorDialog("Could not open ROM file"); - } + if(error != FRONTEND_ERR_NONE){ + popupErrorDialog("Could not open ROM file"); + } } void MainWindow::on_install_pressed(){ - std::string app = QFileDialog::getOpenFileName(this, "Open Prc/Pdb/Pqa", QDir::root().path(), 0).toStdString(); - uint32_t error; - size_t size; - uint8_t* appData = getFileBuffer(app, size, error); - if(appData){ - error = emulatorInstallPrcPdb(appData, size); - delete[] appData; - } + std::string app = QFileDialog::getOpenFileName(this, "Open Prc/Pdb/Pqa", QDir::root().path(), 0).toStdString(); + uint32_t error; + size_t size; + uint8_t* appData = getFileBuffer(app, size, error); + if(appData){ + error = emulatorInstallPrcPdb(appData, size); + delete[] appData; + } - if(error != FRONTEND_ERR_NONE){ - popupErrorDialog("Could not install app"); - } + if(error != FRONTEND_ERR_NONE){ + popupErrorDialog("Could not install app"); + } } //display void MainWindow::updateDisplay(){ - if(emuOn){ - if(emuMutex.try_lock()){ - emulateFrame(); - video = QImage((unsigned char*)palmFramebuffer, screenWidth, screenHeight, QImage::Format_RGB16);//16 bit - ui->display->setPixmap(QPixmap::fromImage(video).scaled(ui->display->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - ui->display->update(); - emuMutex.unlock(); - } - } + if(emuOn){ + if(emuMutex.try_lock()){ + emulateFrame(); + video = QImage((unsigned char*)palmFramebuffer, screenWidth, screenHeight, QImage::Format_RGB16);//16 bit + ui->display->setPixmap(QPixmap::fromImage(video).scaled(ui->display->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + ui->display->update(); + emuMutex.unlock(); + } + } } void MainWindow::on_display_destroyed(){ - //do nothing + //do nothing } //palm buttons void MainWindow::on_power_pressed(){ - palmInput.buttonPower = true; + palmInput.buttonPower = true; } void MainWindow::on_power_released(){ - palmInput.buttonPower = false; + palmInput.buttonPower = false; } void MainWindow::on_calender_pressed(){ - palmInput.buttonCalender = true; + palmInput.buttonCalender = true; } void MainWindow::on_calender_released(){ - palmInput.buttonCalender = false; + palmInput.buttonCalender = false; } void MainWindow::on_addressBook_pressed(){ - palmInput.buttonAddress = true; + palmInput.buttonAddress = true; } void MainWindow::on_addressBook_released(){ - palmInput.buttonAddress = false; + palmInput.buttonAddress = false; } void MainWindow::on_todo_pressed(){ - palmInput.buttonTodo = true; + palmInput.buttonTodo = true; } void MainWindow::on_todo_released(){ - palmInput.buttonTodo = false; + palmInput.buttonTodo = false; } void MainWindow::on_notes_pressed(){ - palmInput.buttonNotes = true; + palmInput.buttonNotes = true; } void MainWindow::on_notes_released(){ - palmInput.buttonNotes = false; + palmInput.buttonNotes = false; } //ui buttons void MainWindow::on_mainLeft_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(2)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(2)); } void MainWindow::on_mainRight_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(1)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(1)); } void MainWindow::on_settingsLeft_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(0)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(0)); } void MainWindow::on_settingsRight_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(2)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(2)); } void MainWindow::on_joyLeft_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(1)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(1)); } void MainWindow::on_joyRight_clicked(){ - ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(0)); + ui->controlPanel->setCurrentWidget(ui->controlPanel->widget(0)); } void MainWindow::on_settings_clicked(){ - //setprocess(SETUP); + //setprocess(SETUP); } //emu control void MainWindow::on_ctrlBtn_clicked() { - emuMutex.lock(); - if(!emuOn && !emuInited){ - //start emu - emulatorInit(romBuffer, ACCURATE); - emuInited = true; - emuOn = true; - ui->ctrlBtn->setText("Pause"); - } - else if(emuOn){ - emuOn = false; - ui->ctrlBtn->setText("Resume"); - } - else if(!emuOn){ - emuOn = true; - ui->ctrlBtn->setText("Pause"); - } - emuMutex.unlock(); + emuMutex.lock(); + if(!emuOn && !emuInited){ + //start emu + emulatorInit(romBuffer, NULL/*bootloader*/, ACCURATE); + emuInited = true; + emuOn = true; + ui->ctrlBtn->setText("Pause"); + } + else if(emuOn){ + emuOn = false; + ui->ctrlBtn->setText("Resume"); + } + else if(!emuOn){ + emuOn = true; + ui->ctrlBtn->setText("Pause"); + } + emuMutex.unlock(); } diff --git a/qtBuildSystem/Mu/mainwindow.h b/qtBuildSystem/Mu/mainwindow.h index 957618f..69960ac 100644 --- a/qtBuildSystem/Mu/mainwindow.h +++ b/qtBuildSystem/Mu/mainwindow.h @@ -8,14 +8,14 @@ extern uint32_t screenWidth; extern uint32_t screenHeight; enum{ - FRONTEND_ERR_NONE, - FRONTEND_FILE_DOESNT_EXIST, - FRONTEND_FILE_EMPTY_PATH, - FRONTEND_FILE_UNFINISHED, - FRONTEND_FILE_MODIFYED, - FRONTEND_FILE_INVALID_TYPE, - FRONTEND_FILE_PROTECTED, - FRONTEND_OUT_OF_MEMORY + FRONTEND_ERR_NONE, + FRONTEND_FILE_DOESNT_EXIST, + FRONTEND_FILE_EMPTY_PATH, + FRONTEND_FILE_UNFINISHED, + FRONTEND_FILE_MODIFYED, + FRONTEND_FILE_INVALID_TYPE, + FRONTEND_FILE_PROTECTED, + FRONTEND_OUT_OF_MEMORY }; namespace Ui { @@ -31,36 +31,36 @@ public: ~MainWindow(); private slots: - void loadRom(); - void selectRom(); + void loadRom(); + void selectRom(); void on_install_pressed(); - //display - void updateDisplay(); - void on_display_destroyed(); + //display + void updateDisplay(); + void on_display_destroyed(); - //palm buttons - void on_power_pressed(); - void on_power_released(); - void on_calender_pressed(); - void on_calender_released(); - void on_addressBook_pressed(); - void on_addressBook_released(); - void on_todo_pressed(); - void on_todo_released(); - void on_notes_pressed(); - void on_notes_released(); + //palm buttons + void on_power_pressed(); + void on_power_released(); + void on_calender_pressed(); + void on_calender_released(); + void on_addressBook_pressed(); + void on_addressBook_released(); + void on_todo_pressed(); + void on_todo_released(); + void on_notes_pressed(); + void on_notes_released(); - //ui buttons - void on_mainLeft_clicked(); - void on_mainRight_clicked(); - void on_settingsLeft_clicked(); - void on_settingsRight_clicked(); - void on_joyLeft_clicked(); - void on_joyRight_clicked(); - void on_settings_clicked(); + //ui buttons + void on_mainLeft_clicked(); + void on_mainRight_clicked(); + void on_settingsLeft_clicked(); + void on_settingsRight_clicked(); + void on_joyLeft_clicked(); + void on_joyRight_clicked(); + void on_settings_clicked(); - void on_ctrlBtn_clicked(); + void on_ctrlBtn_clicked(); private: Ui::MainWindow *ui; diff --git a/src/emulator.c b/src/emulator.c index 2aed4dd..e2c7442 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -29,6 +29,7 @@ uint8_t palmRam[RAM_SIZE + 3];//+ 3 to prevent 32 bit writes on last byte from corrupting memory uint8_t palmRom[ROM_SIZE + 3];//+ 3 to prevent 32 bit writes on last byte from corrupting memory uint8_t palmReg[REG_SIZE + 3];//+ 3 to prevent 32 bit writes on last byte from corrupting memory +uint8_t palmBootloader[BOOTLOADER_SIZE + 3];//+ 3 to prevent 32 bit writes on last byte from corrupting memory input_t palmInput; sdcard_t palmSdCard; misc_hw_t palmMisc; @@ -52,7 +53,7 @@ static inline bool allSdCardCallbacksPresent(){ } -void emulatorInit(uint8_t* palmRomDump, uint32_t specialFeatures){ +void emulatorInit(uint8_t* palmRomDump, uint8_t* palmBootDump, uint32_t specialFeatures){ //cpu m68k_init(); m68k_set_cpu_type(M68K_CPU_TYPE_68020); @@ -67,6 +68,10 @@ void emulatorInit(uint8_t* palmRomDump, uint32_t specialFeatures){ //memory memset(palmRam, 0x00, RAM_SIZE); memcpy(palmRom, palmRomDump, ROM_SIZE); + if(palmBootloader) + memcpy(palmBootloader, palmBootDump, BOOTLOADER_SIZE); + else + memset(palmBootloader, 0x00, BOOTLOADER_SIZE); memcpy(palmRam, palmRom, 256);//copy ROM header memcpy(&palmFramebuffer[160 * 160], silkscreenData, SILKSCREEN_WIDTH * SILKSCREEN_HEIGHT * (SILKSCREEN_BPP / 8)); resetAddressSpace(); diff --git a/src/emulator.h b/src/emulator.h index 42d61f2..755dc0b 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -99,6 +99,7 @@ typedef struct{ #define RAM_SIZE (16 * 0x100000)//16mb ram #define ROM_SIZE (4 * 0x100000)//4mb rom #define REG_SIZE 0xE00 +#define BOOTLOADER_SIZE 0x200 //display chip addresses #define SED1376_REG_START_ADDRESS 0x1FF80000 @@ -114,6 +115,7 @@ typedef struct{ extern uint8_t palmRam[]; extern uint8_t palmRom[]; extern uint8_t palmReg[]; +extern uint8_t palmBootloader[]; extern input_t palmInput; extern sdcard_t palmSdCard; extern misc_hw_t palmMisc; @@ -130,7 +132,7 @@ extern uint8_t* (*emulatorGetSdCardChunk)(uint64_t sessionId, uint64_t chunkId); extern void (*emulatorSetSdCardChunk)(uint64_t sessionId, uint64_t chunkId, uint8_t* data, uint64_t size); //functions -void emulatorInit(uint8_t* palmRomDump, uint32_t specialFeatures); +void emulatorInit(uint8_t* palmRomDump, uint8_t* palmBootDump, uint32_t specialFeatures); void emulatorExit(); void emulatorReset(); void emulatorSetRtc(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds); diff --git a/src/hardwareRegisters.c b/src/hardwareRegisters.c index 9424db2..92208d1 100644 --- a/src/hardwareRegisters.c +++ b/src/hardwareRegisters.c @@ -196,7 +196,7 @@ static inline void setPllfsr16(uint16_t value){ double q = (value & 0x0F00) >> 8; palmCrystalCycles = 2.0 * (14.0 * (p + 1.0) + q + 1.0) / prescaler1; printf("New CPU frequency of:%f cycles per second.\n", CPU_FREQUENCY); - printf("New clk32 cycle count of:%f.\n", palmCrystalCycles); + printf("New clk32 cycle count of:%f.\n", palmCrystalCycles); } } @@ -478,14 +478,6 @@ void checkInterrupts(){ if(intLevel < 4) intLevel = 4; } - - /* - if(lowPowerStopActive){ - uint32_t intMask = (m68k_get_reg(NULL, M68K_REG_SR) >> 8) & 0x0007; - if(intLevel == 7 || intLevel > intMask) - lowPowerStopActive = false; - } - */ m68k_set_irq(intLevel);//should be called even if intLevel is 0, that is how the interrupt state gets cleared } @@ -594,7 +586,7 @@ int interruptAcknowledge(int intLevel){ //If an interrupt occurs before the IVR has been programmed, the interrupt vector number 0x0F is returned to the CPU as an uninitialized interrupt. if(!vectorOffset) - vector = 15/*EXCEPTION_UNINITIALIZED_INTERRUPT*/; + vector = 15/*EXCEPTION_UNINITIALIZED_INTERRUPT*/; else vector = vectorOffset | intLevel; @@ -617,7 +609,7 @@ unsigned int getHwRegister8(unsigned int address){ address &= 0x00000FFF; switch(address){ - case PADATA: + case PDDATA: return getPortDValue(); //select between gpio or special function diff --git a/src/sed1376.c b/src/sed1376.c index 433535e..b09be81 100644 --- a/src/sed1376.c +++ b/src/sed1376.c @@ -49,6 +49,6 @@ void sed1376Render(){ } else{ - //black screen + //black screen } }