Merge pull request #32 from ramapcsx2/snes_speedup

Faster Snes dumping
This commit is contained in:
sanni 2019-08-27 08:38:54 +02:00 committed by GitHub
commit 3da22b39b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,8 @@
#define HI 1 #define HI 1
#define LO 0 #define LO 0
// optimization-safe nop delay
#define NOP __asm__ __volatile__ ("nop\n\t")
/****************************************** /******************************************
Variables Variables
*****************************************/ *****************************************/
@ -400,8 +402,11 @@ byte readBank_SNES(byte myBank, word myAddress) {
PORTF = myAddress & 0xFF; PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF; PORTK = (myAddress >> 8) & 0xFF;
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total // Wait for the Byte to appear on the data bus
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); // Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
NOP; NOP; NOP; NOP; NOP; NOP;
// Read // Read
byte tempByte = PINC; byte tempByte = PINC;
@ -410,29 +415,68 @@ byte readBank_SNES(byte myBank, word myAddress) {
void readLoRomBanks( unsigned int start, unsigned int total, SdFile *file) void readLoRomBanks( unsigned int start, unsigned int total, SdFile *file)
{ {
byte buffer[512]; byte buffer[1024];
uint16_t c = 0;
uint16_t currByte = 32768;
for (int currBank = start; currBank < total; currBank++) { for (int currBank = start; currBank < total; currBank++) {
// Dump the bytes to SD 512B at a time PORTL = currBank;
for (long currByte = 32768; currByte < 65536; currByte += 512) { currByte = 32768;
for (int c = 0; c < 512; c++) { while (1) {
buffer[c] = readBank_SNES(currBank, currByte + c); c = 0;
while (c < 1024) {
PORTF = (currByte & 0xFF);
PORTK = ((currByte >> 8) & 0xFF);
// Wait for the Byte to appear on the data bus
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
NOP; NOP; NOP; NOP; NOP; NOP;
buffer[c] = PINC;
c++;
currByte++;
} }
file->write(buffer, 512); file->write(buffer, 1024);
// exit while(1) loop once the uint16_t currByte overflows from 0xffff to 0 (current bank is done)
if (currByte == 0) break;
} }
} }
} }
void readHiRomBanks( unsigned int start, unsigned int total, SdFile *file) void readHiRomBanks( unsigned int start, unsigned int total, SdFile *file)
{ {
byte buffer[512]; byte buffer[1024];
uint16_t c = 0;
uint16_t currByte = 0;
for (int currBank = start; currBank < total; currBank++) { for (int currBank = start; currBank < total; currBank++) {
for (long currByte = 0; currByte < 65536; currByte += 512) { PORTL = currBank;
for (int c = 0; c < 512; c++) { currByte = 0;
buffer[c] = readBank_SNES(currBank, currByte + c); while (1) {
c = 0;
while (c < 1024) {
PORTF = (currByte & 0xFF);
PORTK = ((currByte >> 8) & 0xFF);
// Wait for the Byte to appear on the data bus
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
NOP; NOP; NOP; NOP; NOP; NOP;
buffer[c] = PINC;
c++;
currByte++;
} }
file->write(buffer, 512); file->write(buffer, 1024);
// exit while(1) loop once the uint16_t currByte overflows from 0xffff to 0 (current bank is done)
if (currByte == 0) break;
} }
} }
} }
@ -933,6 +977,9 @@ boolean compare_checksum() {
// Read rom to SD card // Read rom to SD card
void readROM_SNES() { void readROM_SNES() {
// get current time
unsigned long startTime = millis();
// Set control // Set control
dataIn(); dataIn();
controlIn_SNES(); controlIn_SNES();
@ -1120,6 +1167,12 @@ void readROM_SNES() {
// Close the file: // Close the file:
myFile.close(); myFile.close();
// print elapsed time
print_Msg(F("Time elapsed: "));
print_Msg((millis() - startTime) / 1000);
println_Msg(F("s"));
display_Update();
} }
/****************************************** /******************************************