#include "memory.h"
#include "../datarec.h"
+namespace BMJR {
#define SET_BANK(s, e, w, r) { \
int sb = (s) >> 11, eb = (e) >> 11; \
for(int i = sb; i <= eb; i++) { \
void MEMORY::reset()
{
+ touch_sound();
memory_bank = 0;
update_bank();
screen_mode = 0;
screen_reversed = false;
- drec_in = false;
+ drec_bit = drec_in = false;
key_column = 0;
nmi_enb = break_pressed = false;
break;
case 0xee80:
if(sound_sample != ((data >> 1) & 0x1f)) {
+ touch_sound();
sound_accum += (double)sound_sample * get_passed_usec(sound_clock);
sound_clock = get_current_clock();
sound_sample = (data >> 1) & 0x1f;
return;
}
if((addr & 0xf800) == 0xe800 && !(memory_bank & 2)) {
- // E800h - EDFFh
+ // E800h - EFFFh
switch(addr & 0xffff) {
case 0xe800:
case 0xe801:
d_drec->write_signal(SIG_DATAREC_REMOTE, addr, 0x20);
return 0x01;
case 0xee80:
- return drec_in ? 0x80 : 0;
+ return drec_bit ? 0x80 : 0;
case 0xeec0:
return key_data;
case 0xef00:
return 0xff;
}
if((addr & 0xf800) == 0xe800 && !(memory_bank & 2)) {
- // E800h - EDFFh
+ // E800h - EFFFh
switch(addr & 0xffff) {
case 0xe800:
case 0xe801:
void MEMORY::write_signal(int id, uint32_t data, uint32_t mask)
{
if(id == SIG_MEMORY_DATAREC_EAR) {
- drec_in = ((data & mask) != 0);
+ bool new_in = ((data & mask) != 0);
+ if(!drec_in && new_in) {
+ // L -> H
+ drec_clock = get_current_clock();
+ } else if(drec_in && !new_in) {
+ // H -> L
+ int usec = (int)get_passed_usec(drec_clock);
+ if(usec > 417 - 42 && usec < 417 + 42) {
+ drec_bit = false; // 1200Hz
+ } else if(usec > 208 - 21 && usec < 208 + 21) {
+ drec_bit = true; // 2400Hz
+ }
+ }
+ drec_in = new_in;
}
}
if(key_stat[key_table[key_column][2]]) key_data &= ~0x04;
if(key_stat[key_table[key_column][3]]) key_data &= ~0x08;
}
- // this is same as "\93ú\97§\83x\81[\83V\83b\83N\83}\83X\83^\81[Jr.(MB-6885)\83G\83~\83\85\83\8c\81[\83^ bm2"
- if(key_stat[0xa2]) key_data &= ~0x10; // \89p\90\94 -> L-CTRL
- if(key_stat[0xa0]) key_data &= ~0x20; // \89p\8bL\8d\86 -> L-SHIFT
- if(key_stat[0xa1]) key_data &= ~0x40; // \83J\83i\8bL\8d\86 -> R-SHIFT
- if(key_stat[0xa3]) key_data &= ~0x80; // \83J\83i -> R-CTRL
+
+#if defined(_USE_QT)
+ // If same as bm2, not effect below keys at Qt version.
+ if(key_stat[VK_LCONTROL]) key_data &= ~0x10; // 英数 -> LCTRL
+ if(key_stat[VK_LSHIFT ]) key_data &= ~0x20; // 英記号 -> L-SHIFT
+ if(key_stat[VK_RWIN ]) key_data &= ~0x40; // カナ記号 -> R-Win
+ if(key_stat[VK_KANA ]) key_data &= ~0x80; // カナ -> カタカナひらがな
+#else
+ // this is same as "日立ベーシックマスターJr.(MB-6885)エミュレータ bm2"
+ if(key_stat[0xa2]) key_data &= ~0x10; // 英数 -> L-CTRL
+ if(key_stat[0xa0]) key_data &= ~0x20; // 英記号 -> L-SHIFT
+ if(key_stat[0xa1]) key_data &= ~0x40; // カナ記号 -> R-SHIFT
+ if(key_stat[0xa3]) key_data &= ~0x80; // カナ -> R-CTRL
+#endif
}
void MEMORY::key_down(int code)
sound_accum = 0;
sound_clock = sound_mix_clock = get_current_clock();
+ int32_t vol_l = apply_volume(volume, volume_l);
+ int32_t vol_r = apply_volume(volume, volume_r);
+
for(int i = 0; i < cnt; i++) {
- *buffer++ = apply_volume(volume, volume_l); // L
- *buffer++ = apply_volume(volume, volume_r); // R
+ *buffer++ += vol_l; // L
+ *buffer++ += vol_r; // R
}
}
// emu->screen_skip_line(false);
}
-#define STATE_VERSION 1
-
-void MEMORY::save_state(FILEIO* state_fio)
-{
- state_fio->FputUint32(STATE_VERSION);
- state_fio->FputInt32(this_device_id);
-
- state_fio->Fwrite(ram, sizeof(ram), 1);
- state_fio->FputUint8(memory_bank);
- state_fio->Fwrite(color_table, sizeof(color_table), 1);
- state_fio->FputUint8(char_color);
- state_fio->FputUint8(back_color);
- state_fio->FputUint8(mp1710_enb);
- state_fio->FputUint8(screen_mode);
- state_fio->FputBool(screen_reversed);
- state_fio->FputBool(drec_in);
- state_fio->FputUint8(key_column);
- state_fio->FputUint8(key_data);
- state_fio->FputBool(nmi_enb);
- state_fio->FputBool(break_pressed);
- state_fio->FputUint8(sound_sample);
- state_fio->FputDouble(sound_accum);
- state_fio->FputUint32(sound_clock);
- state_fio->FputUint32(sound_mix_clock);
-}
+#define STATE_VERSION 2
-bool MEMORY::load_state(FILEIO* state_fio)
+bool MEMORY::process_state(FILEIO* state_fio, bool loading)
{
- 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;
}
- state_fio->Fread(ram, sizeof(ram), 1);
- memory_bank = state_fio->FgetUint8();
- state_fio->Fread(color_table, sizeof(color_table), 1);
- char_color = state_fio->FgetUint8();
- back_color = state_fio->FgetUint8();
- mp1710_enb = state_fio->FgetUint8();
- screen_mode = state_fio->FgetUint8();
- screen_reversed = state_fio->FgetBool();
- drec_in = state_fio->FgetBool();
- key_column = state_fio->FgetUint8();
- key_data = state_fio->FgetUint8();
- nmi_enb = state_fio->FgetBool();
- break_pressed = state_fio->FgetBool();
- sound_sample = state_fio->FgetUint8();
- sound_accum = state_fio->FgetDouble();
- sound_clock = state_fio->FgetUint32();
- sound_mix_clock = state_fio->FgetUint32();
+ state_fio->StateBuffer(ram, sizeof(ram), 1);
+ state_fio->StateUint8(memory_bank);
+ state_fio->StateBuffer(color_table, sizeof(color_table), 1);
+ state_fio->StateUint8(char_color);
+ state_fio->StateUint8(back_color);
+ state_fio->StateUint8(mp1710_enb);
+ state_fio->StateUint8(screen_mode);
+ state_fio->StateBool(screen_reversed);
+ state_fio->StateBool(drec_bit);
+ state_fio->StateBool(drec_in);
+ state_fio->StateUint32(drec_clock);
+ state_fio->StateUint8(key_column);
+ state_fio->StateUint8(key_data);
+ state_fio->StateBool(nmi_enb);
+ state_fio->StateBool(break_pressed);
+ state_fio->StateUint8(sound_sample);
+ state_fio->StateDouble(sound_accum);
+ state_fio->StateUint32(sound_clock);
+ state_fio->StateUint32(sound_mix_clock);
// post process
- update_bank();
+ if(loading) {
+ update_bank();
+ }
return true;
}
-
+}