OSDN Git Service

Merge branch 'master' of github.com:Artanejp/common_source_project-fm7
[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 "vm.h"
10 #include "../../fileio.h"
11 #include "emu.h"
12 #include "fm7_common.h"
13 #include "kanjirom.h"
14
15 KANJIROM::KANJIROM(VM *parent_vm, EMU* parent_emu, bool type_2std): DEVICE(parent_vm, parent_emu)
16 {
17         FILEIO *fio;
18         read_ok = false;
19         
20         fio = new FILEIO();
21         memset(data_table, 0xff, 0x20000); 
22         //      read_table[0].memory = data_table;
23         p_emu = parent_emu;
24
25         if(type_2std) {
26                 class2 = true;
27                 if(fio->Fopen(create_local_path(_T(ROM_KANJI_CLASS2)), FILEIO_READ_BINARY)) {
28                   fio->Fread(data_table, 0x20000, 1);
29                         fio->Fclose();
30                         read_ok = true;
31                 }
32         } else {
33                 class2 = false;
34                 if(fio->Fopen(create_local_path(_T(ROM_KANJI_CLASS1)), FILEIO_READ_BINARY)) {
35                   fio->Fread(data_table, 0x20000, 1);
36                         fio->Fclose();
37                         read_ok = true;
38                 } else if(fio->Fopen(create_local_path(_T(ROM_KANJI_CLASS1_FALLBACK)), FILEIO_READ_BINARY)) {
39                   fio->Fread(data_table, 0x20000, 1);
40                         fio->Fclose();
41                         read_ok = true;
42                 }
43                 
44         }
45         if(class2) {
46                 set_device_name(_T("FM7_KANJI_CLASS2"));
47         } else {
48                 set_device_name(_T("FM7_KANJI_CLASS1"));
49         }
50         if(class2) {
51                 set_device_name(_T("FM7_KANJI_CLASS2"));
52         } else {
53                 set_device_name(_T("FM7_KANJI_CLASS1"));
54         }
55         this->out_debug_log(_T("KANJIROM READ %s."), read_ok ? "OK" : "FAILED");
56         
57         kanjiaddr.d = 0;
58         delete fio;
59         return;
60 }
61
62 KANJIROM::~KANJIROM()
63 {
64 }
65
66 void KANJIROM::reset(void)
67 {
68         kanjiaddr.d = 0;
69 }
70
71
72 void KANJIROM::write_data8(uint32_t addr, uint32_t data)
73 {
74         switch(addr) {
75         case KANJIROM_ADDR_HI:
76                 kanjiaddr.b.h = data & 0xff;
77                 break;
78         case KANJIROM_ADDR_LO:
79                 kanjiaddr.b.l = data & 0xff;
80                 break;
81         }               
82         return;
83 }
84
85 uint32_t KANJIROM::read_data8(uint32_t addr)
86 {
87         if(addr == KANJIROM_DATA_HI) {
88                 return data_table[(kanjiaddr.d << 1) & 0x1ffff];
89         } else if(addr == KANJIROM_DATA_LO) {
90                 return data_table[((kanjiaddr.d << 1) & 0x1ffff) + 1];
91         } else if(addr == KANJIROM_READSTAT) {
92                 return (read_ok) ? 0xffffffff : 0x00000000;
93         } else if((addr >= KANJIROM_DIRECTADDR) && (addr < (KANJIROM_DIRECTADDR + 0x20000))) {
94                 return data_table[addr - KANJIROM_DIRECTADDR];
95         }
96         return 0x00000000;
97 }
98
99 bool KANJIROM::get_readstat(void)
100 {
101         return read_ok;
102 }
103
104 void KANJIROM::release()
105 {
106 }
107
108 #define STATE_VERSION 4
109
110 #include "../../statesub.h"
111
112 void KANJIROM::decl_state()
113 {
114         state_entry = new csp_state_utils(STATE_VERSION, this_device_id, _T("KANJI_ROM"));
115         DECL_STATE_ENTRY_BOOL(class2);
116         DECL_STATE_ENTRY_BOOL(read_ok);
117         DECL_STATE_ENTRY_1D_ARRAY(data_table, sizeof(data_table));
118         DECL_STATE_ENTRY_PAIR(kanjiaddr);
119 }
120 void KANJIROM::save_state(FILEIO *state_fio)
121 {
122         if(state_entry != NULL) {
123                 state_entry->save_state(state_fio);
124         }
125 }
126
127 bool KANJIROM::load_state(FILEIO *state_fio)
128 {
129         bool mb = false;
130         if(state_entry != NULL) {
131                 mb = state_entry->load_state(state_fio);
132         }
133         if(!mb) return false;
134         kanjiaddr.w.h = 0;
135         return true;
136 }
137