#include "../fileio.h"
#include "../common.h"
-#define EVENT_SIGNAL 0
-#define EVENT_SOUND 1
-#define EVENT_FFREW 2
+#define EVENT_SIGNAL 0
+#define EVENT_SOUND 1
#ifndef DATAREC_FF_REW_SPEED
#define DATAREC_FF_REW_SPEED 10
pcm_changed = 0;
pcm_last_vol = 0;
- percentage = -1;
// skip frames
signal_changed = 0;
register_frame_event(this);
{
if(event_id == EVENT_SIGNAL) {
if(play) {
- if(buffer_ptr <= 0) buffer_ptr = 0;
- int tmpp = (int)(((float)buffer_ptr / (float)buffer_length) * 100.0f);
- if(percentage != tmpp) {
- //printf("Percentage: %d, buffer_length = %d, buffer_ptr = %d\n", percentage, buffer_ptr, buffer_length);
- if(ff_rew > 0) {
- emu->out_message(_T("CMT: Fast Forward (%d %%)"), tape_position());
- } else if(ff_rew < 0) {
- emu->out_message(_T("CMT: Fast Rewind (%d %%)"), tape_position());
- } else {
- emu->out_message(_T("CMT: Play (%d %%)"), tape_position());
- }
+ if(ff_rew > 0) {
+ emu->out_message(_T("CMT: Fast Forward (%d %%)"), tape_position());
+ } else if(ff_rew < 0) {
+ emu->out_message(_T("CMT: Fast Rewind (%d %%)"), tape_position());
+ } else {
+ emu->out_message(_T("CMT: Play (%d %%)"), tape_position());
}
- percentage = tmpp;
bool signal = in_signal;
if(is_wav) {
- if(internal_count < 0) internal_count = buffer[buffer_ptr] & 0x7f;
+ //if(internal_count < 0) internal_count = buffer[buffer_ptr] & 0x7f;
if(buffer_ptr >= 0 && buffer_ptr < buffer_length) {
signal = ((buffer[buffer_ptr] & 0x80) != 0);
#ifdef DATAREC_SOUND
#endif
}
if(ff_rew < 0) {
- buffer_ptr--;
- if(buffer_ptr <= 0) {
- buffer_ptr = 0;
- internal_count = -1;
+ if((buffer_ptr = max(buffer_ptr - 1, 0)) == 0) {
set_remote(false); // top of tape
signal = false;
}
} else {
buffer_ptr++;
- if(buffer_ptr >= buffer_length) {
- buffer_ptr = buffer_length;
- internal_count = 0;
+ if((buffer_ptr = min(buffer_ptr + 1, buffer_length)) == buffer_length) {
set_remote(false); // end of tape
signal = false;
}
positive_clocks = negative_clocks = 0;
}
}
-
}
void DATAREC::set_remote(bool value)
void DATAREC::set_ff_rew(int value)
{
- set_ff_rew_apss(value);
-}
-
-void DATAREC::set_ff_rew_apss(int value)
-{
if(ff_rew != value) {
if(register_id != -1) {
cancel_event(this, register_id);
bool DATAREC::do_apss(int value)
{
bool result = false;
- percentage = (int)(((float)buffer_ptr / (float)buffer_length) * 100.0f);
-
if(play) {
- set_ff_rew_apss(0);
+ set_ff_rew(0);
set_remote(true);
- set_ff_rew_apss(value > 0 ? 1 : -1);
+ set_ff_rew(value > 0 ? 1 : -1);
apss_remain = value;
while(apss_remain != 0 && remote) {
// stop cmt
set_remote(false);
- set_ff_rew_apss(0);
- percentage = (int)(((float)buffer_ptr / (float)buffer_length) * 100.0f);
+ set_ff_rew(0);
if(value > 0) {
if(play) {
{
if(remote && (play || rec)) {
if(register_id == -1) {
- //percentage = -1;
if(ff_rew != 0) {
register_event(this, EVENT_SIGNAL, sample_usec / DATAREC_FF_REW_SPEED, true, ®ister_id);
} else {
emu->out_message(_T("CMT: Stop (%d %%)"), tape_position());
}
}
- prev_clock = 0;
+ prev_clock = 0;
}
}
// update signals
bool DATAREC::play_tape(const _TCHAR* file_path)
{
close_tape();
- percentage = -1;
if(play_fio->Fopen(file_path, FILEIO_READ_BINARY)) {
if(check_file_extension(file_path, _T(".wav")) || check_file_extension(file_path, _T(".mti"))) {
// standard PCM wave file
if((buffer_length = load_wav_image(0)) != 0) {
play = is_wav = true;
}
+ } else if(check_file_extension(file_path, _T(".t77"))) {
+ // FUJITSU FM-8/7 series T77 image for my emulator
+ if((buffer_length = load_t77_image()) != 0) {
+ buffer = (uint8 *)malloc(buffer_length);
+ load_t77_image();
+ play = is_wav = true;
+ }
} else if(check_file_extension(file_path, _T(".tap"))) {
// SHARP X1 series tape image
if((buffer_length = load_tap_image()) != 0) {
load_cas_image();
play = is_wav = true;
}
- } else if(check_file_extension(file_path, _T(".t77"))) {
- // standard cas image for my emulator
- if((buffer_length = load_t77_image()) != 0) {
- buffer = (uint8 *)malloc(buffer_length);
- load_t77_image();
- play = is_wav = true;
- }
}
play_fio->Fclose();
}
write_signals(&outputs_ear, signal ? 0xffffffff : 0);
in_signal = signal;
}
+
// initialize apss
apss_buffer_length = sample_rate * 2;
apss_buffer = (bool *)calloc(apss_buffer_length, 1);
bool DATAREC::rec_tape(const _TCHAR* file_path)
{
close_tape();
- percentage = -1;
if(rec_fio->Fopen(file_path, FILEIO_READ_WRITE_NEW_BINARY)) {
my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
sample_rate = 48000;
// initialize buffer
buffer[0] = out_signal ? 0x80 : 0;
}
- //is_t77 = false;
rec = true;
update_event();
}
void DATAREC::close_tape()
{
close_file();
- internal_count = -1;
+ //internal_count = -1;
play = rec = is_wav = is_tap = false;
- //is_t77 = false;
buffer_ptr = buffer_length = 0;
update_event();
}
// standard cas image for my emulator
+
static const uint8 msx_cas_header[8] = {0x1f, 0xa6, 0xde, 0xba, 0xcc, 0x13, 0x7d, 0x74};
int DATAREC::load_cas_image()
play_fio->Fread(tmp_header, sizeof(tmp_header), 1);
if(memcmp(tmp_header, "SORDM5", 6) == 0) {
- //is_t77 = false;
return load_m5_cas_image();
} else if(memcmp(tmp_header, msx_cas_header, 8) == 0) {
return load_msx_cas_image();
} else if(memcmp(tmp_header, momomomomomo, 6) == 0) {
- //is_t77 = false;
return load_p6_image(false);
}
ptr++;
}
}
- //is_t77 = false;
return ptr;
}
play_fio->Fseek(offset, FILEIO_SEEK_SET);
play_fio->Fread(&header, sizeof(header), 1);
if(header.format_id != 1 || !(header.sample_bits == 8 || header.sample_bits == 16)) {
- //is_t77 = false;
return 0;
}
play_fio->Fseek(header.fmt_chunk.size - 16, FILEIO_SEEK_CUR);
// load samples
if(samples > 0) {
-#define TMP_LENGTH (0x10000 * header.channels)
+ #define TMP_LENGTH (0x10000 * header.channels)
uint8 *tmp_buffer = (uint8 *)malloc(TMP_LENGTH);
play_fio->Fread(tmp_buffer, TMP_LENGTH, 1);
#define GET_SAMPLE { \
for(int ch = 0; ch < header.channels; ch++) { \
- if(header.sample_bits == 16) { \
- union { \
- int16 s16; \
- struct { \
- uint8 l, h; \
- } b; \
- } pair; \
- pair.b.l = tmp_buffer[tmp_ptr++]; \
- pair.b.h = tmp_buffer[tmp_ptr++]; \
- sample[ch] = pair.s16; \
- } else { \
+ if(header.sample_bits == 16) { \
+ union { \
+ int16 s16; \
+ struct { \
+ uint8 l, h; \
+ } b; \
+ } pair; \
+ pair.b.l = tmp_buffer[tmp_ptr++]; \
+ pair.b.h = tmp_buffer[tmp_ptr++]; \
+ sample[ch] = pair.s16; \
+ } else { \
sample[ch] = (tmp_buffer[tmp_ptr++] - 128) * 256; \
- } \
- } \
- if(tmp_ptr == TMP_LENGTH) { \
- play_fio->Fread(tmp_buffer, TMP_LENGTH, 1); \
- tmp_ptr = 0; \
- } \
- } \
+ } \
+ } \
+ if(tmp_ptr == TMP_LENGTH) { \
+ play_fio->Fread(tmp_buffer, TMP_LENGTH, 1); \
+ tmp_ptr = 0; \
+ } \
+ }
#ifdef DATAREC_SOUND
// t=0 : get thresholds
// t=1 : get number of samples
// t=2 : load samples
-#define FREQ_SCALE 16
+ #define FREQ_SCALE 16
int min_threshold = (int)(header.sample_rate * FREQ_SCALE / 2400.0 / 2.0 / 3.0 + 0.5);
int max_threshold = (int)(header.sample_rate * FREQ_SCALE / 1200.0 / 2.0 * 3.0 + 0.5);
int half_threshold, hi_count, lo_count;
rec_fio->Fwrite(buffer, buffer_ptr, 1);
}
uint32 length = rec_fio->Ftell();
- //is_t77 = false;
wav_header_t wav_header;
wav_chunk_t wav_chunk;
rec_fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
}
-
// SORD M5 tape image
#define M5_PUT_BIT(val, len) { \
}
// FUJITSU FM-7 series tape image
-#define T77_PUT_SIGNAL(signal, len) { \
+#define T77_PUT_SIGNAL(signal, len) { \
int remain = len; \
while(remain > 0) { \
if(buffer != NULL) { \
} else { \
ptr++; \
} \
- remain -= 1; \
+ remain--; \
} \
}
// load t77 file
uint8 tmpbuf[17];
int ptr = 0;
+
+ // I wish to save file size feature, sometimes causes segfault without this. / 20151218 Ohta.
int file_size = (int)play_fio->FileLength();
if(file_size <= 0) return 0; // Over 2GB.
+ play_fio->Fseek(0, FILEIO_SEEK_SET);
play_fio->Fread(tmpbuf, 16, 1);
tmpbuf[16] = '\0';
if(strcmp((char *)tmpbuf, "XM7 TAPE IMAGE 0") != 0) {
#define MZT_PUT_BLOCK(buf, len) { \
int count = 0; \
- for(int i = 0; i < (int)len; i++) { \
+ for(int i = 0; i < len; i++) { \
MZT_PUT_BYTE((buf)[i]); \
} \
uint8 hi = (count >> 8) & 0xff; \
play_fio->Fseek(0, FILEIO_SEEK_END);
int file_size = play_fio->Ftell();
play_fio->Fseek(0, FILEIO_SEEK_SET);
- //is_t77 = false;
// load mzt file
int ptr = 0;
play_fio->Fread(header, sizeof(header), 1);
file_size -= sizeof(header);
- pair size;
- pair offs;
- size.d = 0;
- size.b.h = header[0x13];
- size.b.l = header[0x12];
- offs.d = 0;
- offs.b.h = header[0x15];
- offs.b.l = header[0x14];
-
+ uint16 size = header[0x12] | (header[0x13] << 8);
+ uint16 offs = header[0x14] | (header[0x15] << 8);
memset(ram, 0, sizeof(ram));
- play_fio->Fread(ram + offs.d, size.d, 1);
- file_size -= size.d;
-#if defined(_MZ80K) || defined(_MZ700) || defined(_MZ1200) || defined(_MZ1500)
-#if 1
+ play_fio->Fread(ram + offs, size, 1);
+ file_size -= size;
+//#if defined(_MZ80K) || defined(_MZ700) || defined(_MZ1200) || defined(_MZ1500)
+#if 0
// apply mz700win patch
if(header[0x40] == 'P' && header[0x41] == 'A' && header[0x42] == 'T' && header[0x43] == ':') {
int patch_ofs = 0x44;
}
}
#endif
-#endif
// output to buffer
MZT_PUT_SIGNAL(0, sample_rate);
#if defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200)
MZT_PUT_BIT(0, 11000);
MZT_PUT_BIT(1, 20);
MZT_PUT_BIT(0, 21);
- MZT_PUT_BLOCK(ram + offs.d, size.d);
+ MZT_PUT_BLOCK(ram + offs, size);
MZT_PUT_BIT(1, 1);
#else
// format info written in \8e\8e\8c±\82É\8fo\82éX1
MZT_PUT_BIT(1, 20);
MZT_PUT_BIT(0, 20);
MZT_PUT_BIT(1, 1);
- MZT_PUT_BLOCK(ram + offs.d, size.d);
+ MZT_PUT_BLOCK(ram + offs, size);
MZT_PUT_BIT(1, 1);
#endif
}
#endif
}
-
-void DATAREC::update_config(void)
-{
-}
-#define STATE_VERSION 7
+#define STATE_VERSION 6
void DATAREC::save_state(FILEIO* state_fio)
{
state_fio->FputInt32(length_tmp);
while(length_tmp != 0) {
uint8 buffer_tmp[1024];
- int length_rw = min((uint) length_tmp, sizeof(buffer_tmp));
+ int length_rw = min(length_tmp, sizeof(buffer_tmp));
rec_fio->Fread(buffer_tmp, length_rw, 1);
state_fio->Fwrite(buffer_tmp, length_rw, 1);
length_tmp -= length_rw;
state_fio->FputInt32(0);
}
state_fio->FputInt32(ff_rew);
- state_fio->FputInt32(percentage);
state_fio->FputBool(in_signal);
state_fio->FputBool(out_signal);
state_fio->FputUint32(prev_clock);
rec_fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
while(length_tmp != 0) {
uint8 buffer_tmp[1024];
- int length_rw = min((uint)length_tmp, sizeof(buffer_tmp));
+ int length_rw = min(length_tmp, sizeof(buffer_tmp));
state_fio->Fread(buffer_tmp, length_rw, 1);
if(rec_fio->IsOpened()) {
rec_fio->Fwrite(buffer_tmp, length_rw, 1);
}
}
ff_rew = state_fio->FgetInt32();
- percentage = state_fio->FgetInt32();
in_signal = state_fio->FgetBool();
out_signal = state_fio->FgetBool();
prev_clock = state_fio->FgetUint32();