diff --git a/config.h b/config.h index da1562a..db2621f 100644 --- a/config.h +++ b/config.h @@ -2,6 +2,13 @@ #ifndef _CONFIG_H #define _CONFIG_H +// What machine do you want to use the Tapuino with. Currently this is a build-time only option +// The C64 and Vic 20 machines seem to be close enough that the C64 timing will work for the Vic 20 +// The C16 seems to be very much more particular, support for this machine is still in pre-alpha +#define MACHINE_C64 1 +//#define MACHINE_VIC 1 +//#define MACHINE_C16 1 + // LCD Definitions // I2C config and expander data lines #define LCD_USE_1602_LCD_MODULE diff --git a/memstrings.c b/memstrings.c index 36071ab..f40897f 100644 --- a/memstrings.c +++ b/memstrings.c @@ -34,6 +34,7 @@ const char S_CHDIR_FAILED[] PROGMEM = "CHDIR fail!"; const char S_READ_FAILED[] PROGMEM = "READ fail!"; const char S_OPEN_FAILED[] PROGMEM = "OPEN fail!"; const char S_INVALID_TAP[] PROGMEM = "Invalid TAP!"; +const char S_INVALID_SIZE[] PROGMEM = "Invalid size!"; const char S_LOADING[] PROGMEM = "Loading:"; const char S_OPERATION_COMPLETE[] PROGMEM = "Complete!"; diff --git a/memstrings.c-it b/memstrings.c-it index 190b8dd..cf5f6c1 100644 --- a/memstrings.c-it +++ b/memstrings.c-it @@ -34,6 +34,7 @@ const char S_CHDIR_FAILED[] PROGMEM = "Errore CHDIR!"; const char S_READ_FAILED[] PROGMEM = "READ fallito!"; const char S_OPEN_FAILED[] PROGMEM = "OPEN fallito!"; const char S_INVALID_TAP[] PROGMEM = "TAP Invalido!"; +const char S_INVALID_SIZE[] PROGMEM = "Formato non valido!"; const char S_LOADING[] PROGMEM = "Loading:"; const char S_OPERATION_COMPLETE[] PROGMEM = "Completato!"; diff --git a/memstrings.h b/memstrings.h index 29289d5..389fb8a 100644 --- a/memstrings.h +++ b/memstrings.h @@ -37,6 +37,7 @@ extern const char S_CHDIR_FAILED[]; extern const char S_READ_FAILED[]; extern const char S_OPEN_FAILED[]; extern const char S_INVALID_TAP[]; +extern const char S_INVALID_SIZE[]; extern const char S_LOADING[]; extern const char S_OPERATION_COMPLETE[]; extern const char S_OPERATION_ABORTED[]; diff --git a/tapuino.c b/tapuino.c index 82c3ace..7947e43 100644 --- a/tapuino.c +++ b/tapuino.c @@ -22,14 +22,29 @@ #include "fileutils.h" #include "menu.h" +// thanks stack overflow +#if defined(MACHINE_C64) + defined(MACHINE_VIC) + defined(MACHINE_C16) != 1 + #error Define exactly one of MACHINE_C64, MACHINE_VIC, MACHINE_C16 +#endif + +#ifdef MACHINE_C64 + #define NTSC_CYCLES_PER_SECOND 1022272 + #define PAL_CYCLES_PER_SECOND 985248 +#elif MACHINE_VIC + #define NTSC_CYCLES_PER_SECOND 1022727 + #define PAL_CYCLES_PER_SECOND 1108404 +#elif MACHINE_C16 + #define NTSC_CYCLES_PER_SECOND 894886 + #define PAL_CYCLES_PER_SECOND 886724 +#else + #error Define exactly one of MACHINE_C64, MACHINE_VIC, MACHINE_C16 +#endif #ifdef USE_NTSC_TIMING - #define CYCLES_PER_SECOND 1022730 - #define CYCLE_MULT_RAW (1000000.0 / CYCLES_PER_SECOND) + #define CYCLE_MULT_RAW (1000000.0 / NTSC_CYCLES_PER_SECOND) #define CYCLE_MULT_8 (CYCLE_MULT_RAW * 8) #else - #define CYCLES_PER_SECOND 985248 - #define CYCLE_MULT_RAW (1000000.0 / CYCLES_PER_SECOND) + #define CYCLE_MULT_RAW (1000000.0 / PAL_CYCLES_PER_SECOND) #define CYCLE_MULT_8 (CYCLE_MULT_RAW * 8.0) #endif @@ -203,9 +218,9 @@ ISR(TIMER1_COMPA_vect) { g_pulse_length_save |= ((unsigned long) g_fat_buffer[g_read_index++]) << 16; g_pulse_length_save *= CYCLE_MULT_RAW; g_tap_file_pos += 3; - // format 2 is half-wave and timer is running at 2Mhz so double - g_pulse_length_save <<= 1; } + // format 2 is half-wave and timer is running at 2Mhz so double + g_pulse_length_save <<= 1; } if (g_pulse_length > 0xFFFF) { // check to see if its bigger than 16 bits @@ -293,8 +308,9 @@ int verify_tap(FILINFO* pfile_info) { // check size first if (g_tap_info.length != (pfile_info->fsize - 20)) { - lcd_title_P(S_INVALID_TAP); - return 0; + lcd_title_P(S_INVALID_SIZE); + g_tap_info.length = pfile_info->fsize - 20; + lcd_busy_spinner(); } uint32_t* tap_magic = (uint32_t*) g_fat_buffer;