From 8647a252c49b940ce0d5068079cd4947895bb82f Mon Sep 17 00:00:00 2001 From: Maximilian Rehkopf Date: Wed, 17 Aug 2011 00:08:40 +0200 Subject: [PATCH] Firmware: SuperCIC detection support --- src/cic.c | 17 +++++++++-------- src/cic.h | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cic.c b/src/cic.c index c6528ec..9d6a75f 100644 --- a/src/cic.c +++ b/src/cic.c @@ -4,7 +4,7 @@ #include "uart.h" #include "cic.h" -char *cicstatenames[3] = { "CIC_OK", "CIC_FAIL", "CIC_PAIR" }; +char *cicstatenames[4] = { "CIC_OK", "CIC_FAIL", "CIC_PAIR", "CIC_SCIC" }; void print_cic_state() { printf("CIC state: %s\n", get_cic_statename(get_cic_state())); @@ -21,21 +21,22 @@ enum cicstates get_cic_state() { state_old = BITBAND(SNES_CIC_STATUS_REG->FIOPIN, SNES_CIC_STATUS_BIT); /* this loop samples at ~10MHz */ - for(count=0; count<1000; count++) { + for(count=0; countFIOPIN, SNES_CIC_STATUS_BIT); if(state != state_old) { togglecount++; } state_old = state; } - if(togglecount > 20) { - printf("%ld\n", togglecount); + printf("%ld\n", togglecount); +/* CIC_TOGGLE_THRESH_PAIR > CIC_TOGGLE_THRESH_SCIC */ + if(togglecount > CIC_TOGGLE_THRESH_PAIR) { return CIC_PAIR; - } - if(state) { + } else if(togglecount > CIC_TOGGLE_THRESH_SCIC) { + return CIC_SCIC; + } else if(state) { return CIC_OK; - } - return CIC_FAIL; + } else return CIC_FAIL; } void cic_init(int allow_pairmode) { diff --git a/src/cic.h b/src/cic.h index 9a384b6..03e0648 100644 --- a/src/cic.h +++ b/src/cic.h @@ -1,10 +1,14 @@ #ifndef _CIC_H #define _CIC_H +#define CIC_SAMPLECOUNT (100000) +#define CIC_TOGGLE_THRESH_PAIR (2500) +#define CIC_TOGGLE_THRESH_SCIC (10) + #include #include "bits.h" -enum cicstates { CIC_OK = 0, CIC_FAIL, CIC_PAIR }; +enum cicstates { CIC_OK = 0, CIC_FAIL, CIC_PAIR, CIC_SCIC }; enum cic_region { CIC_NTSC = 0, CIC_PAL }; void print_cic_state(void);