mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 05:29:43 +00:00
Generic I2C PROM emulation.
This commit is contained in:
parent
eecb5a0f42
commit
8cdbd9f81f
76
devices/common/i2c/i2cprom.cpp
Normal file
76
devices/common/i2c/i2cprom.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Generic PROM device programmable over I2C. */
|
||||
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
I2CProm::I2CProm(uint8_t dev_addr, int size)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
this->rom_size = size;
|
||||
|
||||
// allocate storage for ROM data
|
||||
this->data = std::unique_ptr<uint8_t[]> (new uint8_t[this->rom_size]);
|
||||
}
|
||||
|
||||
void I2CProm::fill_memory(int start, int size, uint8_t c)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memset(&this->data[start], c, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memcpy(&this->data[start], in_data, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool I2CProm::send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::send_byte(uint8_t data) {
|
||||
LOG_F(9, "I2CRom: 0x%X received", data);
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::receive_byte(uint8_t* p_data) {
|
||||
if (this->pos >= this->rom_size) {
|
||||
this->pos = 0; // attempt to read past last byte should wrap around
|
||||
}
|
||||
*p_data = this->data[this->pos++];
|
||||
return true;
|
||||
};
|
57
devices/common/i2c/i2cprom.h
Normal file
57
devices/common/i2c/i2cprom.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file Generic PROM device programmable over I2C. */
|
||||
|
||||
#ifndef I2C_PROM_H
|
||||
#define I2C_PROM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class I2CProm : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
I2CProm(uint8_t dev_addr, int size);
|
||||
~I2CProm() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
// data management methods
|
||||
void fill_memory(int start, int size, uint8_t c);
|
||||
void set_memory(int start, const uint8_t* in_data, int size);
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
|
||||
int rom_size = 0;
|
||||
int pos = 0;
|
||||
uint8_t my_addr = 0xA0;
|
||||
};
|
||||
|
||||
#endif // I2C_PROM_H
|
Loading…
x
Reference in New Issue
Block a user