summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/orao_cas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/formats/orao_cas.cpp')
-rw-r--r--src/lib/formats/orao_cas.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/lib/formats/orao_cas.cpp b/src/lib/formats/orao_cas.cpp
index 2d0f96b2a14..8cc77e3bf6f 100644
--- a/src/lib/formats/orao_cas.cpp
+++ b/src/lib/formats/orao_cas.cpp
@@ -5,22 +5,23 @@
Tape support for Orao TAP format
*/
-#include <assert.h>
#include "orao_cas.h"
#define ORAO_WAV_FREQUENCY 44100
-#define WAVE_HIGH -32768
-#define WAVE_LOW 0
+#define WAVE_HIGH -24576
+#define WAVE_LOW 24576
-#define ORAO_WAVE_ONE 24
-#define ORAO_WAVE_ZERO 11
+#define ORAO_WAVE_ONE 17
+#define ORAO_WAVE_ZERO 9
#define ORAO_HEADER_SIZE 360
-static int16_t wave_data;
-static int len;
+static int16_t wave_data; // FIXME: global variables prevent multiple instances
+static int len;
+static int startpos;
+static bool newformat;
static void orao_output_wave( int16_t **buffer, int length ) {
if ( buffer == nullptr ) {
@@ -41,7 +42,13 @@ static int orao_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
return -1;
}
size = 0;
- for (i=ORAO_HEADER_SIZE;i<caslen-ORAO_HEADER_SIZE;i++) {
+ startpos = 0;
+ newformat = true;
+ if (casdata[0]==0x68 && casdata[1]==0x01 && casdata[2]==0x00) {
+ startpos = ORAO_HEADER_SIZE;
+ newformat = false;
+ }
+ for (i=startpos;i<caslen-startpos;i++) {
for (j=0;j<8;j++) {
b = (casdata[i] >> j) & 1;
if (b==0) {
@@ -55,14 +62,15 @@ static int orao_cas_to_wav_size( const uint8_t *casdata, int caslen ) {
return size;
}
-static int orao_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
- int i,j,size;
+static int orao_cas_fill_wave( int16_t *buffer, int length, const uint8_t *bytes, int ) {
+ int i,j,size,k;
uint8_t b;
size = 0;
if (bytes == nullptr) return -1;
- for (i=ORAO_HEADER_SIZE;i<len-ORAO_HEADER_SIZE;i++) {
+ for (i=startpos;i<len-startpos;i++) {
for (j=0;j<8;j++) {
- b = (bytes[i] >> j) & 1;
+ k = newformat ? (7-j) : j;
+ b = (bytes[i] >> k) & 1;
if (b==0) {
wave_data = WAVE_LOW;
orao_output_wave(&buffer,ORAO_WAVE_ZERO);
@@ -85,7 +93,7 @@ static int orao_cas_fill_wave( int16_t *buffer, int length, uint8_t *bytes ) {
-static const struct CassetteLegacyWaveFiller orao_legacy_fill_wave = {
+static const cassette_image::LegacyWaveFiller orao_legacy_fill_wave = {
orao_cas_fill_wave, /* fill_wave */
-1, /* chunk_size */
0, /* chunk_samples */
@@ -97,19 +105,19 @@ static const struct CassetteLegacyWaveFiller orao_legacy_fill_wave = {
-static cassette_image::error orao_cassette_identify( cassette_image *cassette, struct CassetteOptions *opts ) {
- return cassette_legacy_identify( cassette, opts, &orao_legacy_fill_wave );
+static cassette_image::error orao_cassette_identify( cassette_image *cassette, cassette_image::Options *opts ) {
+ return cassette->legacy_identify( opts, &orao_legacy_fill_wave );
}
static cassette_image::error orao_cassette_load( cassette_image *cassette ) {
- return cassette_legacy_construct( cassette, &orao_legacy_fill_wave );
+ return cassette->legacy_construct( &orao_legacy_fill_wave );
}
-static const struct CassetteFormat orao_cassette_format = {
+static const cassette_image::Format orao_cassette_format = {
"tap",
orao_cassette_identify,
orao_cassette_load,