Skip to content

Commit

Permalink
awa
Browse files Browse the repository at this point in the history
  • Loading branch information
telecomadm1145 committed Aug 18, 2024
1 parent c3ef1e2 commit c59900c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CasioEmuMsvc/Chipset/MMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace casioemu {
MMURegion* region = byte.region;
if (!region || !region->write) {
#ifdef DBG
// std::cout << std::hex << offset << "<-" << (int)data << std::oct << "\n";
std::cout << std::hex << offset << "<-" << (int)data << std::oct << "\n";
#endif
return;
}
Expand Down
10 changes: 9 additions & 1 deletion CasioEmuMsvc/Peripheral/BatteryBackedRAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#include <cstring>
#include <fstream>

inline void fillRandomData(unsigned char* buf, size_t size) {
std::srand(static_cast<unsigned int>(SDL_GetPerformanceCounter())); // 使用当前时间作为随机种子
std::generate(buf, buf + size, []() {
return static_cast<unsigned char>(std::rand() % 256); // 生成0到255之间的随机数
});
}

namespace casioemu {
class BatteryBackedRAM : public Peripheral {
MMURegion region, region_2, region_3, region_4, region_5;
Expand All @@ -33,7 +40,7 @@ namespace casioemu {
ram_size += 0x100;

ram_buffer = new uint8_t[ram_size];
memset(ram_buffer, 0, ram_size);
fillRandomData(ram_buffer, ram_size);

ram_file_requested = false;
if (emulator.argv_map.find("ram") != emulator.argv_map.end()) {
Expand All @@ -49,6 +56,7 @@ namespace casioemu {
"BatteryBackedRAM", ram_buffer, [](MMURegion* region, size_t offset) { return ((uint8_t*)region->userdata)[offset - region->base]; }, [](MMURegion* region, size_t offset, uint8_t data) { ((uint8_t*)region->userdata)[offset - region->base] = data; }, emulator);
if (emulator.hardware_id == HW_FX_5800P) {
pram_buffer = new uint8_t[0x8000];
fillRandomData(pram_buffer, 0x8000);
region_5.Setup(
0x40000,
0x8000,
Expand Down
6 changes: 3 additions & 3 deletions CasioEmuMsvc/Peripheral/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <ctime> // for std::time
#include <vector>

constexpr uint8_t reverse_bits(uint8_t n) {
inline constexpr uint8_t reverse_bits(uint8_t n) {
uint8_t reversed = 0;
for (int i = 0; i < 8; ++i) {
reversed |= ((n >> i) & 1) << (7 - i);
Expand All @@ -42,7 +42,7 @@ constexpr uint8_t reverse_bits(uint8_t n) {
}

// constexpr 生成查找表
constexpr std::array<uint8_t, 256> generate_lookup_table() {
inline constexpr std::array<uint8_t, 256> generate_lookup_table() {
std::array<uint8_t, 256> table = {};
for (int i = 0; i < 256; ++i) {
table[i] = reverse_bits(static_cast<uint8_t>(i));
Expand All @@ -53,7 +53,7 @@ constexpr std::array<uint8_t, 256> generate_lookup_table() {
// 定义查找表
constexpr auto bit_lookup_table = generate_lookup_table();

void fillRandomData(unsigned char* buf, size_t size) {
inline void fillRandomData(unsigned char* buf, size_t size) {
std::srand(static_cast<unsigned int>(SDL_GetPerformanceCounter())); // 使用当前时间作为随机种子
std::generate(buf, buf + size, []() {
return static_cast<unsigned char>(std::rand() % 256); // 生成0到255之间的随机数
Expand Down

0 comments on commit c59900c

Please sign in to comment.