Merge pull request #82 from Kreeblah/snes_clockgen_file

Load SNES clock generator offset from SD card
This commit is contained in:
sanni 2021-01-27 08:20:24 +01:00 committed by GitHub
commit bfcf20142e
4 changed files with 3901 additions and 3854 deletions

View File

@ -4,6 +4,7 @@
#include "options.h"
#ifdef enable_NP
#include "snes_clk.h"
/******************************************
SF Memory Clock Source
@ -605,7 +606,12 @@ void setup_SFM() {
//PORTH &= ~(1 << 1);
// Adafruit Clock Generator
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, -16000);
}
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
clockgen.set_pll(SI5351_PLL_FIXED, SI5351_PLLB);
clockgen.set_freq(2147727200ULL, SI5351_CLK0);

View File

@ -4,6 +4,7 @@
#include "options.h"
#ifdef enable_SNES
#include "snes_clk.h"
/******************************************
Defines
@ -382,7 +383,12 @@ void setup_Snes() {
// Adafruit Clock Generator
// last number is the clock correction factor which is custom for each clock generator
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else {
clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, -16000);
}
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU

27
Cart_Reader/snes_clk.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "snes_clk.h"
#include <SdFat.h>
int32_t readClockOffset() {
File clock_file;
unsigned char* clock_buf;
int16_t i;
int32_t clock_offset;
if(!clock_file.open("/snes_clk.txt", FILE_READ)) {
return INT32_MIN;
}
clock_buf = malloc(16 * sizeof(char));
i = clock_file.read(clock_buf, 16);
clock_file.close();
if(i == -1) {
free(clock_buf);
return INT32_MIN;
} else if(i < 16) {
clock_buf[i] = 0;
}
clock_offset = (int32_t)atoi(clock_buf);
free(clock_buf);
return clock_offset;
}

8
Cart_Reader/snes_clk.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _SNES_CLK_H
#define _SNES_CLK_H
#include <SdFat.h>
int32_t readClockOffset();
#endif