2 TOSHIBA EX-80 Emulator 'eEX-80'
4 Author : Takeda.Toshiya
13 void CMT::initialize()
31 void CMT::write_signal(int id, uint32_t data, uint32_t mask)
35 buffer[bufcnt++] = data & mask;
36 if(bufcnt >= BUFFER_SIZE) {
37 fio->Fwrite(buffer, bufcnt, 1);
43 void CMT::play_tape(const _TCHAR* file_path)
47 if(fio->Fopen(file_path, FILEIO_READ_BINARY)) {
48 fio->Fseek(0, FILEIO_SEEK_END);
49 int size = (fio->Ftell() + 9) & (BUFFER_SIZE - 1);
50 fio->Fseek(0, FILEIO_SEEK_SET);
51 memset(buffer, 0, sizeof(buffer));
52 fio->Fread(buffer, sizeof(buffer), 1);
56 // this implement does not care the sio buffer size... :-(
57 for(int i = 0; i < size; i++) {
58 d_sio->write_signal(SIG_I8251_RECV, buffer[i], 0xff);
64 void CMT::rec_tape(const _TCHAR* file_path)
68 if(fio->Fopen(file_path, FILEIO_WRITE_BINARY)) {
69 my_tcscpy_s(rec_file_path, _MAX_PATH, file_path);
75 void CMT::close_tape()
81 d_sio->write_signal(SIG_I8251_CLEAR, 0, 0);
84 void CMT::release_tape()
89 fio->Fwrite(buffer, bufcnt, 1);
96 #define STATE_VERSION 1
98 void CMT::save_state(FILEIO* state_fio)
100 state_fio->FputUint32(STATE_VERSION);
101 state_fio->FputInt32(this_device_id);
103 state_fio->FputBool(play);
104 state_fio->FputBool(rec);
105 state_fio->Fwrite(rec_file_path, sizeof(rec_file_path), 1);
106 if(rec && fio->IsOpened()) {
107 int length_tmp = (int)fio->Ftell();
108 fio->Fseek(0, FILEIO_SEEK_SET);
109 state_fio->FputInt32(length_tmp);
110 while(length_tmp != 0) {
111 uint8_t buffer_tmp[1024];
112 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
113 fio->Fread(buffer_tmp, length_rw, 1);
114 state_fio->Fwrite(buffer_tmp, length_rw, 1);
115 length_tmp -= length_rw;
118 state_fio->FputInt32(0);
120 state_fio->FputInt32(bufcnt);
121 state_fio->Fwrite(buffer, sizeof(buffer), 1);
124 bool CMT::load_state(FILEIO* state_fio)
128 if(state_fio->FgetUint32() != STATE_VERSION) {
131 if(state_fio->FgetInt32() != this_device_id) {
134 play = state_fio->FgetBool();
135 rec = state_fio->FgetBool();
136 state_fio->Fread(rec_file_path, sizeof(rec_file_path), 1);
137 int length_tmp = state_fio->FgetInt32();
139 fio->Fopen(rec_file_path, FILEIO_READ_WRITE_NEW_BINARY);
140 while(length_tmp != 0) {
141 uint8_t buffer_tmp[1024];
142 int length_rw = min(length_tmp, (int)sizeof(buffer_tmp));
143 state_fio->Fread(buffer_tmp, length_rw, 1);
144 if(fio->IsOpened()) {
145 fio->Fwrite(buffer_tmp, length_rw, 1);
147 length_tmp -= length_rw;
150 bufcnt = state_fio->FgetInt32();
151 state_fio->Fread(buffer, sizeof(buffer), 1);