OSDN Git Service

78082d61f0bafea032d9c049c2154ad921dc7065
[csp-qt/common_source_project-fm7.git] / source / src / vm / pasopia / pac2.cpp
1 /*
2         TOSHIBA PASOPIA Emulator 'EmuPIA'
3
4         Author : Takeda.Toshiya
5         Date   : 2006.12.28 -
6
7         [ pac slot 2 ]
8 */
9
10 #include "pac2.h"
11 #include "pac2dev.h"
12 #include "rampac2.h"
13 #include "kanjipac2.h"
14 #include "joypac2.h"
15
16 void PAC2::initialize()
17 {
18         rampac2 = new RAMPAC2(static_cast<VM *>(vm), emu);
19         kanji = new KANJIPAC2(static_cast<VM *>(vm), emu);
20         joy = new JOYPAC2(static_cast<VM *>(vm), emu);
21         dummy = new PAC2DEV(static_cast<VM *>(vm), emu);
22         rampac2->initialize(1);
23         kanji->initialize(1);
24         joy->initialize(1);
25         dummy->initialize(1);
26 }
27
28 void PAC2::release()
29 {
30         rampac2->release();
31         delete rampac2;
32         delete kanji;
33         delete joy;
34         delete dummy;
35 }
36
37 void PAC2::reset()
38 {
39         device_type = config.device_type;
40         get_device()->reset();
41 }
42
43 void PAC2::write_io8(uint32_t addr, uint32_t data)
44 {
45         switch(addr & 0xff) {
46         case 0x18:
47         case 0x19:
48         case 0x1a:
49         case 0x1b:
50                 get_device()->write_io8(addr, data);
51                 break;
52         }
53 }
54
55 uint32_t PAC2::read_io8(uint32_t addr)
56 {
57         return get_device()->read_io8(addr);
58 }
59
60 PAC2DEV* PAC2::get_device()
61 {
62         switch(device_type) {
63         case DEVICE_RAM_PAC:
64                 return rampac2;
65         case DEVICE_KANJI_ROM:
66                 return kanji;
67         case DEVICE_JOYSTICK:
68                 return joy;
69         }
70         return dummy;
71 }
72
73 void PAC2::open_rampac2(const _TCHAR* file_path)
74 {
75         rampac2->open_file(file_path);
76 }
77
78 #define STATE_VERSION   1
79
80 #include "../../statesub.h"
81
82 void PAC2::decl_state()
83 {
84         enter_decl_state(STATE_VERSION);
85         
86         DECL_STATE_ENTRY_INT32(device_type);
87
88         if(rampac2 != NULL) {
89                 rampac2->decl_state();
90         }
91         if(kanji != NULL) {
92                 kanji->decl_state();
93         }
94         if(joy != NULL) {
95                 joy->decl_state();
96         }
97         if(dummy != NULL) {
98                 dummy->decl_state();
99         }
100
101         
102         leave_decl_state();
103 }
104
105 void PAC2::save_state(FILEIO* state_fio)
106 {
107         if(state_entry != NULL) {
108                 state_entry->save_state(state_fio);
109         }
110 //      state_fio->FputUint32(STATE_VERSION);
111 //      state_fio->FputInt32(this_device_id);
112 //      
113 //      state_fio->FputInt32(device_type);
114         get_device()->save_state(state_fio);
115 }
116
117 bool PAC2::load_state(FILEIO* state_fio)
118 {
119         bool mb = false;
120         if(state_entry != NULL) {
121                 mb = state_entry->load_state(state_fio);
122         }
123         if(!mb) return false;
124 //      if(state_fio->FgetUint32() != STATE_VERSION) {
125 //              return false;
126 //      }
127 //      if(state_fio->FgetInt32() != this_device_id) {
128 //              return false;
129 //      }
130 //      device_type = state_fio->FgetInt32();
131         if(!get_device()->load_state(state_fio)) {
132                 return false;
133         }
134         return true;
135 }
136
137 bool PAC2::process_state(FILEIO* state_fio, bool loading)
138 {
139         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
140                 return false;
141         }
142         if(!state_fio->StateCheckInt32(this_device_id)) {
143                 return false;
144         }
145         state_fio->StateInt32(device_type);
146         return get_device()->process_state(state_fio, loading);
147 }