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 / multi8 / kanji.cpp
1 /*
2         MITSUBISHI Electric MULTI8 Emulator 'EmuLTI8'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.09.15 -
6
7         [ kanji rom ]
8 */
9
10 #include "kanji.h"
11 #include "../i8255.h"
12
13 void KANJI::initialize()
14 {
15         // load rom image
16         FILEIO* fio = new FILEIO();
17         if(fio->Fopen(create_local_path(_T("KANJI.ROM")), FILEIO_READ_BINARY)) {
18                 fio->Fread(rom, sizeof(rom), 1);
19                 fio->Fclose();
20                 
21                 // 8255 Port A, bit6 = 0 (kanji rom exists)
22                 d_pio->write_signal(SIG_I8255_PORT_A, 0, 0x40);
23         } else {
24                 // 8255 Port A, bit6 = 1 (kanji rom does not exist)
25                 d_pio->write_signal(SIG_I8255_PORT_A, 0x40, 0x40);
26         }
27         delete fio;
28 }
29
30 void KANJI::reset()
31 {
32         ptr = 0;
33 }
34
35 void KANJI::write_io8(uint32_t addr, uint32_t data)
36 {
37         switch(addr & 0xff) {
38         case 0x40:
39                 ptr = (ptr & 0xff00) | data;
40                 break;
41         case 0x41:
42                 ptr = (ptr & 0x00ff) | (data << 8);
43                 break;
44         }
45 }
46
47 uint32_t KANJI::read_io8(uint32_t addr)
48 {
49         switch(addr & 0xff) {
50         case 0x40:
51                 return rom[(ptr << 1) | 0];
52         case 0x41:
53                 return rom[(ptr << 1) | 1];
54         }
55         return 0xff;
56 }
57
58 #define STATE_VERSION   1
59
60 #include "../../statesub.h"
61
62 void KANJI::decl_state()
63 {
64         enter_decl_state(STATE_VERSION);
65
66         DECL_STATE_ENTRY_UINT32(ptr);
67
68         leave_decl_state();
69 }
70
71 void KANJI::save_state(FILEIO* state_fio)
72 {
73         if(state_entry != NULL) {
74                 state_entry->save_state(state_fio);
75         }
76 //      state_fio->FputUint32(STATE_VERSION);
77         
78 //      state_fio->FputUint32(ptr);
79 }
80
81 bool KANJI::load_state(FILEIO* state_fio)
82 {
83         bool mb = false;
84         if(state_entry != NULL) {
85                 mb = state_entry->load_state(state_fio);
86         }
87         if(!mb) {
88                 return false;
89         }
90 //      if(state_fio->FgetUint32() != STATE_VERSION) {
91 //              return false;
92 //      }
93 //      ptr = state_fio->FgetUint32();
94         return true;
95 }
96
97 bool KANJI::process_state(FILEIO* state_fio, bool loading)
98 {
99         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
100                 return false;
101         }
102         if(!state_fio->StateCheckInt32(this_device_id)) {
103                 return false;
104         }
105         state_fio->StateUint32(ptr);
106         return true;
107 }