OSDN Git Service

[VM][WIP] Pre-process to apply new state framework.Still not buildable.
[csp-qt/common_source_project-fm7.git] / source / src / vm / x07 / io.cpp
index 28d9bc7..4ee5ad7 100644 (file)
@@ -1441,3 +1441,91 @@ bool IO::load_state(FILEIO* state_fio)
        return true;
 }
 
+bool IO::process_state(FILEIO* state_fio, bool loading)
+{
+       if(!state_fio->StateCheckUint32(STATE_VERSION)) {
+               return false;
+       }
+       if(!state_fio->StateCheckInt32(this_device_id)) {
+               return false;
+       }
+       state_fio->StateBuffer(rregs, sizeof(rregs), 1);
+       state_fio->StateBuffer(wregs, sizeof(wregs), 1);
+       if(!cur_time.process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateInt32(register_id_1sec);
+       if(!cmd_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       if(!rsp_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateUint8(sub_int);
+       state_fio->StateBuffer(wram, sizeof(wram), 1);
+       state_fio->StateBuffer(alarm, sizeof(alarm), 1);
+       if(!key_buf->process_state((void *)state_fio, loading)) {
+               return false;
+       }
+       state_fio->StateBool(ctrl);
+       state_fio->StateBool(shift);
+       state_fio->StateBool(kana);
+       state_fio->StateBool(graph);
+       state_fio->StateBool(brk);
+       state_fio->StateUint8(stick);
+       state_fio->StateUint8(strig);
+       state_fio->StateUint8(strig1);
+       state_fio->StateBool(cmt_play);
+       state_fio->StateBool(cmt_rec);
+       state_fio->StateBool(cmt_mode);
+       state_fio->StateBuffer(rec_file_path, sizeof(rec_file_path), 1);
+       if(loading) {
+               int length_tmp = state_fio->FgetInt32_LE();
+               if(cmt_rec) {
+                       cmt_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(cmt_fio->IsOpened()) {
+                                       cmt_fio->Fwrite(buffer_tmp, length_rw, 1);
+                               }
+                               length_tmp -= length_rw;
+                       }
+               }
+       } else {
+               if(cmt_rec && cmt_fio->IsOpened()) {
+                       int length_tmp = (int)cmt_fio->Ftell();
+                       cmt_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));
+                               cmt_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);
+               }
+       }
+       state_fio->StateInt32(cmt_len);
+       state_fio->StateInt32(cmt_ptr);
+       state_fio->StateBuffer(cmt_buf, sizeof(cmt_buf), 1);
+       state_fio->StateBool(vblank);
+       state_fio->StateUint8(font_code);
+       state_fio->StateBuffer(udc, sizeof(udc), 1);
+       state_fio->StateBuffer(lcd, sizeof(lcd), 1);
+       state_fio->StateBool(locate_on);
+       state_fio->StateBool(cursor_on);
+       state_fio->StateBool(udk_on);
+       state_fio->StateInt32(locate_x);
+       state_fio->StateInt32(locate_y);
+       state_fio->StateInt32(cursor_x);
+       state_fio->StateInt32(cursor_y);
+       state_fio->StateInt32(cursor_blink);
+       state_fio->StateInt32(scroll_min);
+       state_fio->StateInt32(scroll_max);
+       state_fio->StateInt32(register_id_beep);
+       return true;
+}