OSDN Git Service

[VM][FM7] FM7_MAINMEM:: Add state save.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fm7 / kanjirom.cpp
1 /*
2  * Common source code project -> FM-7/77/AV -> Kanji rom
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License: GPLv2
5  * History:
6  *  Feb 11, 2015 : Initial
7  */
8
9 #include "../../fileio.h"
10 #include "kanjirom.h"
11
12 KANJIROM::KANJIROM(VM *parent_vm, EMU* parent_emu, bool type_2std): DEVICE(parent_vm, parent_emu)
13 {
14         FILEIO *fio;
15         read_ok = false;
16         
17         fio = new FILEIO();
18         memset(data_table, 0xff, 0x20000); 
19         //      read_table[0].memory = data_table;
20         
21         if(type_2std) {
22                 class2 = true;
23                 if(fio->Fopen(emu->bios_path("KANJI2.ROM"), FILEIO_READ_BINARY)) {
24                   fio->Fread(data_table, 0x20000, 1);
25                         fio->Fclose();
26                         read_ok = true;
27                 }
28         } else {
29                 class2 = false;
30                 if(fio->Fopen(emu->bios_path("KANJI1.ROM"), FILEIO_READ_BINARY)) {
31                   fio->Fread(data_table, 0x20000, 1);
32                         fio->Fclose();
33                         read_ok = true;
34                 } else if(fio->Fopen(emu->bios_path("KANJI.ROM"), FILEIO_READ_BINARY)) {
35                   fio->Fread(data_table, 0x20000, 1);
36                         fio->Fclose();
37                         read_ok = true;
38                 } 
39         }
40         delete fio;
41         return;
42 }
43
44 void KANJIROM::write_data8(uint32 addr, uint32 data)
45 {
46         return;
47 }
48
49 uint32 KANJIROM::read_data8(uint32 addr)
50 {
51         return data_table[addr & 0x1ffff];
52 }
53
54 bool KANJIROM::get_readstat(void)
55 {
56         return read_ok;
57 }
58
59 void KANJIROM::release()
60 {
61 }
62
63 #define STATE_VERSION 1
64 void KANJIROM::save_state(FILEIO *state_fio)
65 {
66         state_fio->FputUint32(STATE_VERSION);
67         state_fio->FputInt32(this_device_id);
68
69         state_fio->FputBool(class2);
70         state_fio->FputBool(read_ok);
71         state_fio->Fwrite(data_table, sizeof(data_table), 1);
72 }
73
74 bool KANJIROM::load_state(FILEIO *state_fio)
75 {
76         uint32 version;
77         version = state_fio->FgetUint32();
78         if(this_device_id != state_fio->FgetInt32()) return false;
79
80         if(version >= 1) {
81                 class2 = state_fio->FgetBool();
82                 read_ok = state_fio->FgetBool();
83                 state_fio->Fread(data_table, sizeof(data_table), 1);
84                 if(version == 1) return true;
85         }
86         return false;
87 }
88