From 62d841c2703286b34983eb8dae174ecbf2c82c5f Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 6 May 2011 19:42:26 +0000 Subject: Moved format handling and all formats to separate library [Miodrag Milanovic] --- src/lib/formats/gtp_cas.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 src/lib/formats/gtp_cas.c (limited to 'src/lib/formats/gtp_cas.c') diff --git a/src/lib/formats/gtp_cas.c b/src/lib/formats/gtp_cas.c new file mode 100644 index 00000000000..e3756c4dcf7 --- /dev/null +++ b/src/lib/formats/gtp_cas.c @@ -0,0 +1,200 @@ +/* + + Tape support for Glaksija GTP format + + Miodrag Milanovic +*/ +#include "gtp_cas.h" + + +#define GTP_WAV_FREQUENCY 44100 +#define WAVE_LOW -0x5a9e +#define WAVE_HIGH 0x5a9e +#define WAVE_NULL 0 + +#define GTP_BLOCK_STANDARD 0x00 +#define GTP_BLOCK_TURBO 0x01 +#define GTP_BLOCK_NAME 0x10 + +static INT16 wave_data; +static INT16 len; + +#define PULSE_WIDTH 30 +#define PERIOD_BASE 150 +#define PERIOD_1 75 +#define PERIOD_0 150 + +#define INTERBYTE_PAUSE 225 +#define INTERBLOCK_PAUSE 100000 + + +static void gtp_output_wave( INT16 **buffer, int length ) { + if ( buffer == NULL ) { + return; + } + + for( ; length > 0; length-- ) { + **buffer = wave_data; + *buffer = *buffer + 1; + } +} + + + +static int gtp_mod_1( INT16 **buffer ) +{ + wave_data = WAVE_LOW; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_HIGH; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_NULL; + gtp_output_wave(buffer,PERIOD_1 - 2 * PULSE_WIDTH); + wave_data = WAVE_LOW; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_HIGH; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_NULL; + gtp_output_wave(buffer,PERIOD_1 - 2 * PULSE_WIDTH); + + return PERIOD_1 * 2; +} + +static int gtp_mod_0( INT16 **buffer ) +{ + wave_data = WAVE_LOW; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_HIGH; + gtp_output_wave(buffer,PULSE_WIDTH); + wave_data = WAVE_NULL; + gtp_output_wave(buffer,PERIOD_0 - 2 * PULSE_WIDTH); + + return PERIOD_0; +} + +static int gtp_byte( INT16 **buffer, UINT8 val ) +{ + UINT8 b; + int j,size = 0; + for (j=0;j<8;j++) { + b = (val >> j) & 1; + if (b==0) { + size += gtp_mod_0(buffer); + } else { + size += gtp_mod_1(buffer); + } + } + return size; +} + +static int gtp_sync( INT16 **buffer ) +{ + int i; + int size = 0; + + for(i=0;i<100;i++) { + if (i!=0) { + // Interbyte pause + wave_data = WAVE_NULL; + gtp_output_wave(buffer,INTERBYTE_PAUSE); + size += INTERBYTE_PAUSE; + } + size += gtp_byte(buffer,0); + } + return size; +} + +static int gtp_cas_to_wav_size( const UINT8 *casdata, int caslen ) { + int size,n; + size = 0; + n = 0; + if (casdata == NULL) return -1; + while(n