Skip to content

Commit

Permalink
Add ability to skip BIOS date/time setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cepawiel committed Mar 9, 2023
1 parent 501e9ae commit 68eede6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 15 deletions.
5 changes: 5 additions & 0 deletions legacy/wrappers/cpp/include/evmu-core-cpp/evmu_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class VmuDevice {
bool isHalted(void) const;
void setHalted(bool value);
bool isBiosLoaded(void) const;
void skipBiosSetup(bool enable);
//VMU_BIOS_MODE getCurrentBiosMode(void) const;
void reset(void) const;
uint16_t getProgramCounter(void) const;
Expand Down Expand Up @@ -265,6 +266,10 @@ inline bool VmuDevice::isBiosLoaded(void) const {
return EvmuRom_biosLoaded(EVMU_DEVICE_PRISTINE_PUBLIC(_dev)->pRom);
}

inline void VmuDevice::skipBiosSetup(bool enable) {
EvmuRom_skipBiosSetup(EVMU_DEVICE_PRISTINE_PUBLIC(_dev)->pRom, enable);
}

inline uint16_t VmuDevice::getProgramCounter(void) const {
return EvmuCpu_pc(EVMU_DEVICE_PRISTINE_PUBLIC(_dev)->pCpu);
}
Expand Down
24 changes: 13 additions & 11 deletions lib/api/evmu/hw/evmu_rom.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ GBL_DECLARE_ENUM(EVMU_BIOS_SUBROUTINE) {

GBL_DECLARE_ENUM(EVMU_BIOS_TYPE) {
EVMU_BIOS_TYPE_EMULATED,
EVMU_BIOS_TYPE_AMERICAN_IMAGE,
EVMU_BIOS_TYPE_JAPANESE_IMAGE,
EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05 = 0xC825003A,
EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04 = 0x8E0F867A,
EVMU_BIOS_TYPE_UNKNOWN_IMAGE
};

Expand All @@ -75,19 +75,21 @@ GBL_PROPERTIES(EvmuRom,
(biosMode, GBL_GENERIC, (READ, WRITE), GBL_ENUM_TYPE)
)

EVMU_EXPORT GblType EvmuRom_type (void) GBL_NOEXCEPT;
EVMU_EXPORT GblType EvmuRom_type (void) GBL_NOEXCEPT;

EVMU_EXPORT GblBool EvmuRom_biosLoaded (GBL_CSELF) GBL_NOEXCEPT;
EVMU_EXPORT GblBool EvmuRom_biosActive (GBL_CSELF) GBL_NOEXCEPT;
EVMU_EXPORT GblBool EvmuRom_biosLoaded (GBL_CSELF) GBL_NOEXCEPT;
EVMU_EXPORT GblBool EvmuRom_biosActive (GBL_CSELF) GBL_NOEXCEPT;

EVMU_EXPORT EVMU_RESULT EvmuRom_loadBios (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
EVMU_EXPORT EvmuAddress EvmuRom_callBios (GBL_SELF) GBL_NOEXCEPT;
EVMU_EXPORT EVMU_RESULT EvmuRom_loadBios (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
EVMU_EXPORT EvmuAddress EvmuRom_callBios (GBL_SELF) GBL_NOEXCEPT;

EVMU_EXPORT EVMU_RESULT EvmuRom_dateTime (GBL_CSELF,
GblDateTime* pDateTime) GBL_NOEXCEPT;
EVMU_EXPORT EVMU_RESULT EvmuRom_skipBiosSetup (GBL_SELF, GblBool enableSkip) GBL_NOEXCEPT;

EVMU_EXPORT EVMU_RESULT EvmuRom_setDateTime (GBL_SELF,
const GblDateTime* pDTime) GBL_NOEXCEPT;
EVMU_EXPORT EVMU_RESULT EvmuRom_dateTime (GBL_CSELF,
GblDateTime* pDateTime) GBL_NOEXCEPT;

EVMU_EXPORT EVMU_RESULT EvmuRom_setDateTime (GBL_SELF,
const GblDateTime* pDTime) GBL_NOEXCEPT;


GBL_DECLS_END
Expand Down
3 changes: 1 addition & 2 deletions lib/source/hw/evmu_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,8 @@ static GBL_RESULT EvmuCpu_IBehavior_reset_(EvmuIBehavior* pSelf) {
GBL_CTX_BEGIN(pSelf);
GBL_INSTANCE_VCALL_DEFAULT(EvmuIBehavior, pFnReset, pSelf);

EVMU_LOG_INFO("Resetting VMU CPU.");
GBL_CTX_INFO("Resetting VMU CPU.");

EVMU_CPU_(pSelf)->pc = 0x0;
memset(&EVMU_CPU_(pSelf)->curInstr.encoded, 0, sizeof(EvmuInstruction));
memset(&EVMU_CPU_(pSelf)->curInstr.decoded, 0, sizeof(EvmuInstruction));
EVMU_CPU_(pSelf)->curInstr.pFormat = EvmuIsa_format(EVMU_OPCODE_NOP);
Expand Down
32 changes: 30 additions & 2 deletions lib/source/hw/evmu_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "evmu_buzzer_.h"
#include "evmu_timers_.h"
#include "evmu_gamepad_.h"
#include "evmu_rom_.h"

EVMU_EXPORT EvmuAddress EvmuMemory_indirectAddress(const EvmuMemory* pSelf, uint8_t mode) {
EvmuAddress value = 0;
Expand Down Expand Up @@ -502,7 +503,7 @@ static GBL_RESULT EvmuMemory_destructor_(GblBox* pSelf) {
static GBL_RESULT EvmuMemory_reset_(EvmuIBehavior* pSelf) {
GBL_CTX_BEGIN(NULL);

GBL_CTX_VERBOSE("Resetting Memory.");
EVMU_LOG_VERBOSE("Resetting Memory.");

EvmuMemory* pMemory = EVMU_MEMORY(pSelf);
EvmuDevice* pDevice = EvmuPeripheral_device(EVMU_PERIPHERAL(pSelf));
Expand All @@ -512,6 +513,22 @@ static GBL_RESULT EvmuMemory_reset_(EvmuIBehavior* pSelf) {
time_t t = time(NULL);
struct tm *tm = localtime(&t);

GblBool skipSetup = pDevice_->pRom->bSetupSkipEnabled;

unsigned char sfr_bin[] = {
0x00, 0x00, 0xff, 0x00, 0x66, 0x19, 0x7f, 0x00, 0x83, 0x02, 0x00, 0x00,
0x00, 0x08, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x05,
0x20, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0xbf, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x06, 0x00, 0x00, 0x20, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xc0,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79
};

memset(pDevice_->pMemory->ram, 0, EVMU_ADDRESS_SEGMENT_RAM_SIZE*EVMU_ADDRESS_SEGMENT_RAM_BANKS);
memset(pDevice_->pMemory->sfr, 0, EVMU_ADDRESS_SEGMENT_SFR_SIZE);
memset(pDevice_->pMemory->wram, 0, EVMU_WRAM_SIZE);
Expand All @@ -534,7 +551,12 @@ static GBL_RESULT EvmuMemory_reset_(EvmuIBehavior* pSelf) {
//EvmuMemory_writeInt(pMemory, EVMU_ADDRESS_SFR_BTCR, 0x41);

pDevice_->pTimers->timer0.tscale = 256;
EvmuCpu_setPc(pDevice->pCpu, 0x0);
GBL_CTX_INFO("Resetting PC.");
if(skipSetup) {
EvmuCpu_setPc(pDevice->pCpu, 0x02E1);
} else {
EvmuCpu_setPc(pDevice->pCpu, 0x0);
}

if(EvmuRom_biosLoaded(pDevice->pRom)) {
// pDevice_->pMemory->sfr[EVMU_SFR_OFFSET(EVMU_ADDRESS_SFR_P7)] |= SFR_P7_P71_MASK;
Expand Down Expand Up @@ -593,6 +615,12 @@ static GBL_RESULT EvmuMemory_reset_(EvmuIBehavior* pSelf) {
EvmuMemory_writeInt(pMemory, EVMU_ADDRESS_SFR_MCR, EVMU_SFR_MCR_MCR3_MASK); //enable LCD update
EvmuMemory_writeInt(pMemory, EVMU_ADDRESS_SFR_PCON, 0); //Disable HALT/HOLD modes, run CPU normally.

if (skipSetup) {
for (int i = 0; i < EVMU_ADDRESS_SEGMENT_SFR_SIZE; i++) {
EvmuMemory_writeInt(pMemory, 0x100 + i, sfr_bin[i]);
}
}

GBL_CTX_END();
}

Expand Down
44 changes: 44 additions & 0 deletions lib/source/hw/evmu_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

EVMU_EXPORT GblBool EvmuRom_biosLoaded(const EvmuRom* pSelf) {
EvmuRom_* pSelf_ = EVMU_ROM_(pSelf);
// VMU Reset Vector is at 0x0 so must be non-zero if loaded
return pSelf_->pMemory->rom[0]? GBL_TRUE : GBL_FALSE;
}

Expand Down Expand Up @@ -63,11 +64,48 @@ EVMU_EXPORT EVMU_RESULT EvmuRom_loadBios(EvmuRom* pSelf, const char* path) {
//assert(bytesRead <= 0); //Didn't read shit
assert(bytesTotal >= 0);

GblHash biosHash = gblHashCrc(pSelf_->pMemory->rom, EVMU_ROM_SIZE);
switch (biosHash) {
case EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05:
EVMU_LOG_VERBOSE("Detected American V1.05 BIOS");
pSelf_->eBiosType = EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05;
break;
case EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04:
EVMU_LOG_VERBOSE("Detected Japanese V1.04 BIOS");
pSelf_->eBiosType = EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04;
break;
default:
EVMU_LOG_WARNING("Unknown BIOS CRC: 0x%X", biosHash);
pSelf_->eBiosType = EVMU_BIOS_TYPE_UNKNOWN_IMAGE;
break;
}

EVMU_LOG_POP(0);
return 1;

}

EVMU_EXPORT EVMU_RESULT EvmuRom_skipBiosSetup(EvmuRom* pSelf, GblBool enabled) {
EVMU_LOG_PUSH();
EVMU_LOG_VERBOSE("%s BIOS Setup Skip", enabled ? "Enabling" : "Disabling");

EvmuRom_* pSelf_ = EVMU_ROM_(pSelf);

switch(pSelf_->eBiosType){
case EVMU_BIOS_TYPE_AMERICAN_IMAGE_V1_05:
case EVMU_BIOS_TYPE_JAPANESE_IMAGE_V1_04:
pSelf_->bSetupSkipEnabled = enabled;
break;
case EVMU_BIOS_TYPE_EMULATED:
case EVMU_BIOS_TYPE_UNKNOWN_IMAGE:
EVMU_LOG_WARNING("Setup Skip Unavailable due to Unknown/Emulated BIOS");
break;
}

EVMU_LOG_POP(0);
return 1;
}


static void biosWriteFlashRom_(EvmuRom_* pSelf_) {
EvmuDevice* pDevice = EvmuPeripheral_device(EVMU_PERIPHERAL(EVMU_ROM_PUBLIC_(pSelf_)));
Expand Down Expand Up @@ -169,6 +207,11 @@ static GBL_RESULT EvmuRom_GblObject_constructed_(GblObject* pSelf) {
GBL_INSTANCE_VCALL_DEFAULT(EvmuPeripheral, base.pFnConstructed, pSelf);
GblObject_setName(pSelf, EVMU_ROM_NAME);

EvmuRom* pRom = EVMU_ROM(pSelf);
EvmuRom_* pRom_ = EVMU_ROM_(pRom);
pRom_->eBiosType = EVMU_BIOS_TYPE_EMULATED;
pRom_->bSetupSkipEnabled = GBL_FALSE;

GBL_CTX_END();
}

Expand Down Expand Up @@ -219,3 +262,4 @@ EVMU_EXPORT GblType EvmuRom_type(void) {




4 changes: 4 additions & 0 deletions lib/source/hw/evmu_rom_.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ GBL_FORWARD_DECLARE_STRUCT(EvmuMemory_);

typedef struct EvmuRom_ {
EvmuMemory_* pMemory;

EVMU_BIOS_TYPE eBiosType;

GblBool bSetupSkipEnabled;
} EvmuRom_;

GBL_DECLS_END
Expand Down

0 comments on commit 68eede6

Please sign in to comment.