Skip to content

Commit

Permalink
naomi: improve performance of M1 and M4 carts dma
Browse files Browse the repository at this point in the history
Limit buffer size to 1 or 2 KB instead of 32 KB.
Only decrypt right before dma transfer.
Fixes frame drops and audio underruns in vf4evoct attract mode.
Issue #1717
  • Loading branch information
flyinghead committed Nov 2, 2024
1 parent 4d5ced1 commit 96aac66
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/hw/naomi/m1cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void M1Cartridge::AdvancePtr(u32 size)
has_history = true;
buffer_actual_size = 0;
}
enc_fill();
}
else
NaomiCartridge::AdvancePtr(size);
Expand Down Expand Up @@ -147,11 +146,13 @@ void M1Cartridge::Serialize(Serializer& ser) const
void M1Cartridge::Deserialize(Deserializer& deser)
{
deser >> buffer;
deser.skip(32768 - sizeof(buffer), Deserializer::V52);
deser >> dict;
deser >> hist;
deser >> avail_val;
deser >> rom_cur_address;
deser >> buffer_actual_size;
buffer_actual_size = std::min<u32>(buffer_actual_size, sizeof(buffer));
deser >> avail_bits;
deser >> stream_ended;
deser >> has_history;
Expand Down
4 changes: 2 additions & 2 deletions core/hw/naomi/m1cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class M1Cartridge : public NaomiCartridge
{
if (encryption)
{
enc_fill();
size = std::min(size, (u32)sizeof(buffer));
return buffer;
}
Expand All @@ -48,7 +49,6 @@ class M1Cartridge : public NaomiCartridge
//printf("M1 ENCRYPTION ON @ %08x\n", dma_offset);
encryption = true;
enc_reset();
enc_fill();
}
else
encryption = false;
Expand Down Expand Up @@ -100,7 +100,7 @@ class M1Cartridge : public NaomiCartridge

u16 actel_id;

u8 buffer[32768];
u8 buffer[1024];
u8 dict[111], hist[2];
u64 avail_val;
u32 rom_cur_address, buffer_actual_size, avail_bits;
Expand Down
2 changes: 2 additions & 0 deletions core/hw/naomi/m4cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,10 @@ void M4Cartridge::Serialize(Serializer& ser) const
void M4Cartridge::Deserialize(Deserializer& deser)
{
deser >> buffer;
deser.skip(32768 - sizeof(buffer), Deserializer::V52);
deser >> rom_cur_address;
deser >> buffer_actual_size;
buffer_actual_size = std::min<u32>(buffer_actual_size, sizeof(buffer));
deser >> iv;
deser >> counter;
deser >> encryption;
Expand Down
4 changes: 3 additions & 1 deletion core/hw/naomi/m4cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class M4Cartridge: public NaomiCartridge {
u16 subkey2 = 0;
u16 one_round[0x10000];

u8 buffer[32768];
u8 buffer[2048];
u32 rom_cur_address, buffer_actual_size;
u16 iv;
u8 counter;
Expand All @@ -80,6 +80,8 @@ class M4Cartridge: public NaomiCartridge {
void enc_init();
void enc_fill();
u16 decrypt_one_round(u16 word, u16 subkey);

static_assert(sizeof(RomBootID) <= sizeof(buffer));
};

#endif /* CORE_HW_NAOMI_M4CARTRIDGE_H_ */

0 comments on commit 96aac66

Please sign in to comment.