Skip to content

Commit

Permalink
Bugfix for Format 2 support (half-waves)
Browse files Browse the repository at this point in the history
Work around for TAPs with bizarre length values in the header
Clean-up of cycle handling for different machines
  • Loading branch information
sweetlilmre committed Apr 20, 2015
1 parent 5580a46 commit 4f1543b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
7 changes: 7 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions memstrings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
1 change: 1 addition & 0 deletions memstrings.c-it
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
1 change: 1 addition & 0 deletions memstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
32 changes: 24 additions & 8 deletions tapuino.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4f1543b

Please sign in to comment.