#define EVENT_CASSETTE 0
#define EVENT_STRIG 1
+namespace PC6001 {
+
/* normal (small alphabet) */
-byte Keys1[256][2] =
+uint8_t Keys1[256][2] =
{
/* 0 1 2 3 4 5 6 7 */
/* 00 */
};
/* normal (small alphabet) + shift */
-byte Keys2[256][2] =
+uint8_t Keys2[256][2] =
{
/* 00 */
{0,0x35},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
};
/* hiragana */
-byte Keys3[256][2] =
+uint8_t Keys3[256][2] =
{
/* 00 */
{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
};
/* hiragana + shift */
-byte Keys4[256][2] =
+uint8_t Keys4[256][2] =
{
/* 00 */
{0,0x35},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
};
/* katakana */
-byte Keys5[256][2] =
+uint8_t Keys5[256][2] =
{
/* 00 */
{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
};
/* katakana + shift */
-byte Keys6[256][2] =
+uint8_t Keys6[256][2] =
{
/* 00 */
{0,0x35},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
};
/* with graph key */
-byte Keys7[256][2] =
+uint8_t Keys7[256][2] =
{
/* 00 */
{0,0x35},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},{0,0x00},
if (code == 0x76) {katakana = -1 * (katakana-1);continue;} // VK_F7
if (code == 0x77) {kbFlagGraph = -1 * (kbFlagGraph-1);continue;} // VK_F8
p6key=code;
- byte *Keys;
- byte ascii=0;
+ uint8_t *Keys;
+ uint8_t ascii=0;
if (kbFlagGraph) {
Keys = Keys7[code];
} else if (kanaMode) {
fio->Fseek(length, FILEIO_SEEK_SET);
char id_p = fio->Fgetc();
char id_6 = fio->Fgetc();
- uint8 ver = fio->FgetUint8();
+ uint8_t ver = fio->FgetUint8();
if(id_p == 'P' && id_6 == '6' && ver == 2) {
- uint8 blocks = fio->FgetUint8();
+ uint8_t blocks = fio->FgetUint8();
if(blocks >= 1) {
fio->FgetUint8();
fio->FgetUint8();
fio->FgetUint8();
- uint16 cmd = fio->FgetUint16();
+ uint16_t cmd = fio->FgetUint16();
fio->Fseek(cmd, FILEIO_SEEK_CUR);
- uint16 exp = fio->FgetUint16();
+ uint16_t exp = fio->FgetUint16();
fio->Fseek(exp, FILEIO_SEEK_CUR);
// check 1st data block
char id_t = fio->Fgetc();
return rec;
}
-static const uint8 pulse_1200hz[40] = {
+static const uint8_t pulse_1200hz[40] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
-static const uint8 pulse_2400hz[20] = {
+static const uint8_t pulse_2400hz[20] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
-static const uint8 pulse_2400hz_x2[40] = {
+static const uint8_t pulse_2400hz_x2[40] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
fio->Fwrite((void *)pulse_2400hz_x2, sizeof(pulse_2400hz_x2), 1);
}
#endif
- uint32 length = fio->Ftell();
-
+ uint32_t length = fio->Ftell();
+#if 0
+ pair_t __riff_chunk_size;
+ pair_t __fmt_chunk_size;
+ pair_t __wav_chunk_size;
+ pair16_t __fmt_id;
+ pair16_t __channels;
+ pair_t __sample_rate;
+ pair16_t __block_size;
+ pair16_t __sample_bits;
+
+ __riff_chunk_size.d = length - 8;
+ __fmt_chunk_size.d = 16;
+ __fmt_id.w = 1;
+ __channels.w = 1;
+ __sample_rate.d = sample_rate;
+ __block_size.w = 1;
+ __sample_bits.w = 8;
+
memcpy(wav_header.riff_chunk.id, "RIFF", 4);
- wav_header.riff_chunk.size = length - 8;
+ wav_header.riff_chunk.size = __riff_chunk_size.get_4bytes_le_to();
+
memcpy(wav_header.wave, "WAVE", 4);
memcpy(wav_header.fmt_chunk.id, "fmt ", 4);
- wav_header.fmt_chunk.size = 16;
- wav_header.format_id = 1;
- wav_header.channels = 1;
- wav_header.sample_rate = sample_rate;
- wav_header.data_speed = sample_rate;
- wav_header.block_size = 1;
- wav_header.sample_bits = 8;
-
+ wav_header.fmt_chunk.size = __riff_chunk_size.get_4bytes_le_to();
+ wav_header.format_id = __fmt_id.get_2bytes_le_to();
+ wav_header.channels = __channels.get_2byte_le_to();
+ wav_header.sample_rate = __sample_rate.get_4bytes_le_to();
+ wav_header.data_speed = __sample_rate.get_4bytes_le_to();
+ wav_header.block_size = __block_size.get_2bytes_le_to();
+ wav_header.sample_bits = __sample_bits_get_2bytes_le_to();
+
memcpy(wav_chunk.id, "data", 4);
- wav_chunk.size = length - sizeof(wav_header) - sizeof(wav_chunk);
-
+ __wav_chunk_size.d = length - sizeof(wav_header) - sizeof(wav_chunk);
+ wav_chunk.size = __wav_chunk_size.get_4bytes_le_to();
+
fio->Fseek(0, FILEIO_SEEK_SET);
fio->Fwrite(&wav_header, sizeof(wav_header), 1);
fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
+#else
+ if(set_wav_header(&wav_header, &wav_chunk, 1, sample_rate, 8, length)) {
+ fio->Fseek(0, FILEIO_SEEK_SET);
+ fio->Fwrite(&wav_header, sizeof(wav_header), 1);
+ fio->Fwrite(&wav_chunk, sizeof(wav_chunk), 1);
+ }
+#endif
} else {
fio->Fwrite(CasData, CasIndex, 1);
if(is_p6t) {
}
}
-uint32 PSUB::get_intr_ack()
+uint32_t PSUB::get_intr_ack()
{
if (CasMode != CAS_NONE && p6key == 0xFA && kbFlagGraph) {
return(INTADDR_CMTSTOP); /* Press STOP while CMT Load or Save */
return(INTADDR_TIMER);
}
-void PSUB::write_io8(uint32 addr, uint32 data)
+void PSUB::write_io8(uint32_t addr, uint32_t data)
{
- uint16 port=(addr & 0x00ff);
+ uint16_t port=(addr & 0x00ff);
if (port == 0x90) {
if (CasMode == CAS_SAVEBYTE) { /* CMT SAVE */
if (CasIndex<0x10000) {
d_pio->write_io8(addr, data);
}
-uint32 PSUB::read_io8(uint32 addr)
+uint32_t PSUB::read_io8(uint32_t addr)
{
- uint16 port=(addr & 0x00ff);
- byte Value=0xff;
+ uint16_t port=(addr & 0x00ff);
+ uint8_t Value=0xff;
if (port == 0x90) {
if (CasMode == CAS_LOADING) {
Value=CasRecv;
#define STATE_VERSION 1
-void PSUB::save_state(FILEIO* state_fio)
-{
- state_fio->FputUint32(STATE_VERSION);
- state_fio->FputInt32(this_device_id);
-
- state_fio->FputBool(play);
- state_fio->FputBool(rec);
- state_fio->FputBool(is_wav);
- state_fio->FputBool(is_p6t);
- state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
- if(rec && fio->IsOpened()) {
- int length_tmp = (int)fio->Ftell();
- fio->Fseek(0, FILEIO_SEEK_SET);
- state_fio->FputInt32(length_tmp);
- while(length_tmp != 0) {
- uint8 buffer_tmp[1024];
- int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
- fio->Fread(buffer_tmp, length_rw, 1);
- state_fio->Fwrite(buffer_tmp, length_rw, 1);
- length_tmp -= length_rw;
- }
- } else {
- state_fio->FputInt32(0);
- }
- state_fio->FputInt32(CasIntFlag);
- state_fio->FputInt32(CasIndex);
- state_fio->FputInt32(CasRecv);
- state_fio->FputInt32(CasMode);
- state_fio->FputInt32(CasBaud);
- state_fio->FputInt32(FileBaud);
- state_fio->Fwrite(CasData, sizeof(CasData), 1);
- state_fio->FputInt32(CasLength);
- state_fio->FputInt32(CasSkipFlag);
- state_fio->FputInt32(kbFlagFunc);
- state_fio->FputInt32(kbFlagGraph);
- state_fio->FputInt32(kbFlagCtrl);
- state_fio->FputInt32(kanaMode);
- state_fio->FputInt32(katakana);
- state_fio->FputInt32(p6key);
- state_fio->FputInt32(stick0);
- state_fio->FputInt32(StrigIntFlag);
- state_fio->FputInt32(StrigEventID);
-}
-
-bool PSUB::load_state(FILEIO* state_fio)
+bool PSUB::process_state(FILEIO* state_fio, bool loading)
{
- close_tape();
-
- if(state_fio->FgetUint32() != STATE_VERSION) {
+ if(!state_fio->StateCheckUint32(STATE_VERSION)) {
return false;
}
- if(state_fio->FgetInt32() != this_device_id) {
+ if(!state_fio->StateCheckInt32(this_device_id)) {
return false;
}
- play = state_fio->FgetBool();
- rec = state_fio->FgetBool();
- is_wav = state_fio->FgetBool();
- is_p6t = state_fio->FgetBool();
- state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
- int length_tmp = state_fio->FgetInt32();
- if(rec) {
- fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
- while(length_tmp != 0) {
- uint8 buffer_tmp[1024];
- int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
- state_fio->Fread(buffer_tmp, length_rw, 1);
- if(fio->IsOpened()) {
- fio->Fwrite(buffer_tmp, length_rw, 1);
+ // pre process
+ if(loading) {
+ close_tape();
+ }
+ state_fio->StateBool(play);
+ state_fio->StateBool(rec);
+ state_fio->StateBool(is_wav);
+ state_fio->StateBool(is_p6t);
+ state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+ if(loading) {
+ int length_tmp = state_fio->FgetInt32_LE();
+ if(rec) {
+ fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
+ while(length_tmp != 0) {
+ uint8_t buffer_tmp[1024];
+ int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+ state_fio->Fread(buffer_tmp, length_rw, 1);
+ if(fio->IsOpened()) {
+ fio->Fwrite(buffer_tmp, length_rw, 1);
+ }
+ length_tmp -= length_rw;
}
- length_tmp -= length_rw;
+ }
+ } else {
+ if(rec && fio->IsOpened()) {
+ int length_tmp = (int)fio->Ftell();
+ fio->Fseek(0, FILEIO_SEEK_SET);
+ state_fio->FputInt32_LE(length_tmp);
+ while(length_tmp != 0) {
+ uint8_t buffer_tmp[1024];
+ int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
+ fio->Fread(buffer_tmp, length_rw, 1);
+ state_fio->Fwrite(buffer_tmp, length_rw, 1);
+ length_tmp -= length_rw;
+ }
+ } else {
+ state_fio->FputInt32_LE(0);
}
}
- CasIntFlag = state_fio->FgetInt32();
- CasIndex = state_fio->FgetInt32();
- CasRecv = state_fio->FgetInt32();
- CasMode = state_fio->FgetInt32();
- CasBaud = state_fio->FgetInt32();
- FileBaud = state_fio->FgetInt32();
- state_fio->Fread(CasData, sizeof(CasData), 1);
- CasLength = state_fio->FgetInt32();
- CasSkipFlag = state_fio->FgetInt32();
- kbFlagFunc = state_fio->FgetInt32();
- kbFlagGraph = state_fio->FgetInt32();
- kbFlagCtrl = state_fio->FgetInt32();
- kanaMode = state_fio->FgetInt32();
- katakana = state_fio->FgetInt32();
- p6key = state_fio->FgetInt32();
- stick0 = state_fio->FgetInt32();
- StrigIntFlag = state_fio->FgetInt32();
- StrigEventID = state_fio->FgetInt32();
+ state_fio->StateInt32(CasIntFlag);
+ state_fio->StateInt32(CasIndex);
+ state_fio->StateInt32(CasRecv);
+ state_fio->StateInt32(CasMode);
+ state_fio->StateInt32(CasBaud);
+ state_fio->StateInt32(FileBaud);
+ state_fio->StateBuffer(CasData, sizeof(CasData), 1);
+ state_fio->StateInt32(CasLength);
+ state_fio->StateInt32(CasSkipFlag);
+ state_fio->StateInt32(kbFlagFunc);
+ state_fio->StateInt32(kbFlagGraph);
+ state_fio->StateInt32(kbFlagCtrl);
+ state_fio->StateInt32(kanaMode);
+ state_fio->StateInt32(katakana);
+ state_fio->StateInt32(p6key);
+ state_fio->StateInt32(stick0);
+ state_fio->StateInt32(StrigIntFlag);
+ state_fio->StateInt32(StrigEventID);
return true;
}
+}