mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 05:29:43 +00:00
Simplified PRAM emulation
This commit is contained in:
parent
1cff216e82
commit
5b8a787e9a
@ -18,9 +18,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** the signature for PRAM backing file identification. */
|
||||
static char PRAM_FILE_ID[] = "DINGUSPPCP-RAM";
|
||||
|
||||
ViaCuda::ViaCuda(std::string pram_file, uint32_t pram_size)
|
||||
{
|
||||
/* FIXME: is this the correct
|
||||
@ -33,10 +30,7 @@ ViaCuda::ViaCuda(std::string pram_file, uint32_t pram_size)
|
||||
this->via_regs[VIA_IER] = 0x7F;
|
||||
|
||||
//PRAM Pre-Initialization
|
||||
this->pram_file = pram_file;
|
||||
this->pram_size = pram_size;
|
||||
|
||||
this->pram_storage = new uint8_t[pram_size];
|
||||
this->pram_obj = NVram("pram.bin", 256);
|
||||
|
||||
this->cuda_init();
|
||||
}
|
||||
@ -49,30 +43,6 @@ void ViaCuda::cuda_init()
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
|
||||
//PRAM Initialization
|
||||
char sig[sizeof(PRAM_FILE_ID)];
|
||||
uint16_t data_size;
|
||||
|
||||
ifstream f(this->pram_file, ios::in | ios::binary);
|
||||
|
||||
if (f.fail() || !f.read(sig, sizeof(PRAM_FILE_ID)) ||
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, PRAM_FILE_ID, sizeof(PRAM_FILE_ID)) ||
|
||||
data_size != this->pram_size ||
|
||||
!f.read((char*)this->pram_storage, this->pram_size))
|
||||
{
|
||||
cout << "WARN: Could not restore PRAM content from the given file." << endl;
|
||||
memset(this->pram_storage, 0, sizeof(this->pram_size));
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
ViaCuda::~ViaCuda()
|
||||
{
|
||||
this->cuda_pram_save();
|
||||
if (this->pram_storage)
|
||||
delete this->pram_storage;
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::read(int reg)
|
||||
@ -275,11 +245,11 @@ void ViaCuda::cuda_pseudo_command(int cmd, int data_count)
|
||||
switch(cmd) {
|
||||
case CUDA_READ_PRAM:
|
||||
cuda_response_header(CUDA_PKT_PSEUDO, 0);
|
||||
pram_read_value(this->in_buf[2]);
|
||||
this->pram_obj.read_byte(this->in_buf[2]);
|
||||
break;
|
||||
case CUDA_WRITE_PRAM:
|
||||
cuda_response_header(CUDA_PKT_PSEUDO, 0);
|
||||
pram_write_value(this->in_buf[2], this->in_buf[3]);
|
||||
this->pram_obj.write_byte(this->in_buf[2], this->in_buf[3]);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
cuda_response_header(CUDA_PKT_PSEUDO, 0);
|
||||
@ -313,14 +283,6 @@ void ViaCuda::cuda_pseudo_command(int cmd, int data_count)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ViaCuda::pram_read_value(uint8_t offset) {
|
||||
return pram_storage[offset];
|
||||
}
|
||||
|
||||
void ViaCuda::pram_write_value(uint8_t offset, uint8_t new_state) {
|
||||
pram_storage[offset] = new_state;
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t *in_buf,
|
||||
int in_bytes)
|
||||
{
|
||||
@ -373,18 +335,4 @@ void ViaCuda::i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr,
|
||||
cout << "Unsupported I2C device 0x" << hex << (int)dev_addr1 << endl;
|
||||
cuda_error_response(CUDA_ERR_I2C);
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::cuda_pram_save()
|
||||
{
|
||||
ofstream f(this->pram_file, ios::out | ios::binary);
|
||||
|
||||
/* write file identification */
|
||||
f.write(PRAM_FILE_ID, sizeof(PRAM_FILE_ID));
|
||||
f.write((char*)&this->pram_size, sizeof(this->pram_size));
|
||||
|
||||
/* write PRAM content */
|
||||
f.write((char*)this->pram_storage, this->pram_size);
|
||||
|
||||
f.close();
|
||||
}
|
@ -28,6 +28,8 @@
|
||||
firmware using bit banging (https://en.wikipedia.org/wiki/Bit_banging).
|
||||
*/
|
||||
|
||||
#include "nvram.h"
|
||||
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
@ -87,7 +89,7 @@ class ViaCuda
|
||||
{
|
||||
public:
|
||||
ViaCuda(std::string pram_file = "pram.bin", uint32_t pram_size = 256);
|
||||
~ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
uint8_t read(int reg);
|
||||
void write(int reg, uint8_t value);
|
||||
@ -105,9 +107,7 @@ private:
|
||||
int32_t out_count;
|
||||
int32_t out_pos;
|
||||
|
||||
std::string pram_file; /* file name for the PRAM file. */
|
||||
uint8_t pram_size; /* PRAM size. */
|
||||
uint8_t* pram_storage;
|
||||
NVram pram_obj;
|
||||
|
||||
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
|
||||
|
||||
@ -122,8 +122,6 @@ private:
|
||||
void cuda_pram_save();
|
||||
|
||||
/* I2C related methods */
|
||||
uint8_t pram_read_value(uint8_t offset);
|
||||
void pram_write_value(uint8_t offset, uint8_t new_state);
|
||||
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t *in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1,
|
||||
const uint8_t *in_buf, int in_bytes);
|
||||
|
Loading…
x
Reference in New Issue
Block a user