diff --git a/CppOutRun.layout b/CppOutRun.layout
index a5dd53e..5b7ccbb 100644
--- a/CppOutRun.layout
+++ b/CppOutRun.layout
@@ -2,6 +2,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -15,64 +55,14 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -80,51 +70,71 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
@@ -154,19 +164,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/src/clock.cc b/src/clock.cc
index bec007c..79224a1 100644
--- a/src/clock.cc
+++ b/src/clock.cc
@@ -44,10 +44,141 @@
#define SDMR3_CL2 *(volatile uint8_t *)0xFEC15040 // SDMR2 Address
#define SDMR3_CL3 *(volatile uint8_t *)0xFEC15060 // SDMR2 Address
+
+#include
+#include
+/* Arrays of standard and extra timers */
+static tmu_t *TMU = SH7305_TMU.TMU;
+static etmu_t *ETMU = SH7305_ETMU;
+/* TSTR register for standard timers */
+static volatile uint8_t *TSTR = &SH7305_TMU.TSTR;
+
+bool runningTimers[3]; // 9 timers : 3 TMUs + 6 ETMUs
+uint32_t initTimersTCNT[3];
+uint32_t initTimersTCOR[3];
+uint32_t newTimersTCNT[3];
+uint32_t newTimersTCOR[3];
+int initPphi;
+int newPphi;
+
+static int getPphi_sh7305(void)
+{
+ /* The meaning of the PLL setting on SH7305 differs from the
+ documentation of SH7224; the value must not be doubled. */
+ int pll = CPG.FRQCR.STC + 1;
+
+
+ /* The FLL ratio is the value of the setting, halved if SELXM=1 */
+ int fll = CPG.FLLFRQ.FLF;
+ if(CPG.FLLFRQ.SELXM == 1) fll >>= 1;
+
+ /* On SH7724, the divider ratio is given by 1 / (setting + 1), but on
+ the SH7305 it is 1 / (2^setting + 1). */
+
+ int divb = CPG.FRQCR.BFC;
+ int divi = CPG.FRQCR.IFC;
+ int divp = CPG.FRQCR.P1FC;
+
+ /* Deduce the input frequency of divider 1 */
+ int base = 32768;
+ if(CPG.PLLCR.FLLE) base *= fll;
+ if(CPG.PLLCR.PLLE) base *= pll;
+ return (base >> (divp + 1));
+}
+
+//We list all running timers and store this in a table (true/false)
+void listTimerStatus( void )
+{
+ for(int k=0;k<3; k++)
+ {
+ if(k < 3)
+ {
+ tmu_t *T = &TMU[k];
+ runningTimers[k]= (!T->TCR.UNIE && !(*TSTR & (1 << k)));
+ }
+// else
+// {
+// etmu_t *T = &ETMU[k-3];
+// runningTimers[k]= (!T->TCR.UNIE && !T->TSTR);
+// }
+ }
+}
+
+// We get all TCNT and TCOR of currently used timers
+// And store these value into the
+void getInitialTimersParameters( void )
+{
+ for(int k=0;k<3; k++)
+ {
+ if (runningTimers[k]==true)
+ {
+ if(k < 3)
+ {
+ tmu_t *T = &TMU[k];
+ initTimersTCNT[k]= T->TCNT;
+ initTimersTCOR[k]= T->TCOR;
+ }
+// else
+// {
+// etmu_t *T = &ETMU[k-3];
+// initTimersTCNT[k]= T->TCNT;
+// initTimersTCOR[k]= T->TCOR;
+// }
+ }
+ }
+}
+
+static int callback(void)
+{
+ return TIMER_CONTINUE;
+}
+
+
+//We update the timers with the new TCNT and new TCOR
+void updateNewTimersParameters( void )
+{
+ for(int k=0;k<3; k++)
+ {
+ if (runningTimers[k]==true)
+ {
+ timer_stop( k );
+ if(k < 3)
+ {
+ tmu_t *T = &TMU[k];
+ T->TCNT = newTimersTCNT[k];
+ T->TCOR = newTimersTCOR[k];
+ }
+// else
+// {
+// etmu_t *T = &ETMU[k-3];
+// T->TCNT = newTimersTCNT[k];
+// T->TCOR = newTimersTCOR[k];
+// }
+ timer_start(k);
+ }
+ }
+}
+
+//We compute the new TCNT and new TCOR
+void computeNewTimersParameters( int initPphi_f, int newPphi_f )
+{
+ for(int k=0;k<3; k++)
+ {
+ if (runningTimers[k]==true)
+ {
+ newTimersTCNT[k] = (uint32_t) ((uint64_t) initTimersTCNT[k] * (uint64_t) newPphi_f / (uint64_t) initPphi_f);
+ newTimersTCOR[k] = (uint32_t) ((uint64_t) initTimersTCOR[k] * (uint64_t) newPphi_f / (uint64_t) initPphi_f);
+ }
+ }
+}
+
+
static overclock_level current_clock_state = OC_Default;
bool overclock_config_changed = false;
+
+
void SetOCDefault( void )
{
BSC.CS0WCR.WR = WAIT18;
@@ -174,25 +305,23 @@ int clock_overclock( overclock_level level )
{
cpu_atomic_start();
+ listTimerStatus(); // we list the running timers
+ initPphi = getPphi_sh7305(); // we get the current P_Phi_f
+ getInitialTimersParameters(); // we collect the current TCNT and TCOR
+
if (level == OC_Default && current_clock_state!=OC_Default) SetOCDefault(), current_clock_state= OC_Default, overclock_config_changed=true;
if (level == OC_PtuneF2 && current_clock_state!=OC_PtuneF2) SetOCPtuneF2(), current_clock_state= OC_PtuneF2, overclock_config_changed=true;
if (level == OC_PtuneF3 && current_clock_state!=OC_PtuneF3) SetOCPtuneF3(), current_clock_state= OC_PtuneF3, overclock_config_changed=true;
if (level == OC_PtuneF4 && current_clock_state!=OC_PtuneF4) SetOCPtuneF4(), current_clock_state= OC_PtuneF4, overclock_config_changed=true;
if (level == OC_PtuneF5 && current_clock_state!=OC_PtuneF5) SetOCPtuneF5(), current_clock_state= OC_PtuneF5, overclock_config_changed=true;
-/*
- if (overclock_config_changed==true)
- {
- CPG.FRQCR.KICK = 1 ;
- while((CPG.LSTATS & 1)!=0 && count<=1000)
- { count++; }
- }
-*/
+
+ newPphi = getPphi_sh7305(); // we get the new P_Phi_f after OC
+ computeNewTimersParameters( initPphi, newPphi ); // we compute the new TCNT and TCOR as per the new frequency
+ updateNewTimersParameters(); // we adjust the timers accordingly
+
cpu_atomic_end();
-// if (count >= 1000) return -1;
-// else return 1;
return 1;
}
else return 0;
}
-
diff --git a/src/clock.h b/src/clock.h
index fcebe12..e0459b4 100644
--- a/src/clock.h
+++ b/src/clock.h
@@ -5,6 +5,7 @@
extern "C" {
#endif
+
typedef enum
{
OC_Default = 0, // Default (118MHz)
@@ -22,10 +23,9 @@ typedef enum
int clock_overclock( overclock_level level );
-
-
#ifdef __cplusplus
}
#endif
#endif /* OVERCLOCK_H */
+
diff --git a/src/main.cc b/src/main.cc
index 4a5b859..b3262b1 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -34,9 +34,9 @@
#include "clock.h"
#define DEBUGXXX 0
-#define OVERCLCK_ACTIVABLE 0
+#define OVERCLCK_ACTIVABLE 1
-char version[5] = {'V','1','.','0','4'};
+char version[5] = {'V','1','.','0','5'};
extern bopti_image_t player;
@@ -225,7 +225,7 @@ static void get_inputs( float dt, int index )
else cam->decX( CC*dt*speed/100 ); // more easy on normal roads
}
- if(keydown(KEY_LEFT))
+ if(keydown(KEY_LEFT) || keydown(KEY_F5))
{
cam->decX(5.0*speed*direction);
@@ -234,7 +234,7 @@ static void get_inputs( float dt, int index )
if (CC>0) viewside=0;
}
- if(keydown(KEY_RIGHT))
+ if(keydown(KEY_RIGHT) || keydown(KEY_F6))
{
cam->incX(5.0*speed*direction);
@@ -243,7 +243,7 @@ static void get_inputs( float dt, int index )
if (CC<0) viewside=0;
}
- if(keydown(KEY_SHIFT)) // Accelerates
+ if(keydown(KEY_SHIFT) || keydown(KEY_XOT) || keydown(KEY_F1)) // Accelerates
{
if (direction==-1 && speed > 0)
{
@@ -263,7 +263,7 @@ static void get_inputs( float dt, int index )
speedcontrol = true;
}
- if(keydown(KEY_ALPHA)) // breaks or rear if speed <0
+ if(keydown(KEY_ALPHA) || keydown(KEY_FRAC) || keydown(KEY_F2)) // breaks or rear if speed <0
{
if (direction==1 && speed > 0)
{
@@ -288,12 +288,6 @@ static void get_inputs( float dt, int index )
if(keydown(KEY_OPTN)) drawOptions();
#if IS_FXLIB==1
- if(keydown(KEY_F1)) BDrawDeco = !BDrawDeco;
- if(keydown(KEY_F2)) BDrawClds = !BDrawClds;
- if(keydown(KEY_F3)) BDrawCars = !BDrawCars;
- if(keydown(KEY_F4)) BDrawBack = !BDrawBack;
- if(keydown(KEY_F5)) BDrawFPS = !BDrawFPS;
-
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
@@ -349,12 +343,6 @@ static void get_minimum_inputs( void )
if(keydown(KEY_OPTN)) drawOptions();
#if IS_FXLIB==1
- if(keydown(KEY_F1)) BDrawDeco = !BDrawDeco;
- if(keydown(KEY_F2)) BDrawClds = !BDrawClds;
- if(keydown(KEY_F3)) BDrawCars = !BDrawCars;
- if(keydown(KEY_F4)) BDrawBack = !BDrawBack;
- if(keydown(KEY_F5)) BDrawFPS = !BDrawFPS;
-
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
@@ -727,6 +715,7 @@ int main(void)
if (BDrawCars && mode==0)
{
+
updateTraffic( dt, maxDistance );
for (unsigned int k=0; k