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 / qc10 / mfont.cpp
1 /*
2         EPSON QC-10 Emulator 'eQC-10'
3
4         Author : Takeda.Toshiya
5         Date   : 2008.03.24 -
6
7         [ multifont rom card ]
8 */
9
10 #include "mfont.h"
11 #include "../i8259.h"
12 #include "../../fifo.h"
13
14 #define BIT_IBF 0x80
15 #define BIT_ERR 2
16 #define BIT_OBF 1
17
18 void MFONT::initialize()
19 {
20         memset(mfont, 0xff, sizeof(mfont));
21         
22         // load multifont rom image
23         FILEIO* fio = new FILEIO();
24         if(fio->Fopen(create_local_path(_T("MFONT.ROM")), FILEIO_READ_BINARY)) {
25                 fio->Fread(mfont, sizeof(mfont), 1);
26                 fio->Fclose();
27         }
28         delete fio;
29         
30         cmd = new FIFO(4);
31         res = new FIFO(38);
32         
33         status = 0;
34 }
35
36 void MFONT::release()
37 {
38         cmd->release();
39         delete cmd;
40         res->release();
41         delete res;
42 }
43
44 void MFONT::write_io8(uint32_t addr, uint32_t data)
45 {
46         switch(addr & 0xff) {
47         case 0xfc:
48                 cmd->write(data);
49                 if(cmd->count() == 3) {
50                         int mode = cmd->read();
51                         int code = cmd->read();
52                         code |= cmd->read() << 8;
53                         
54                         if(0x200 <= code && code < 0xc00) {
55                                 int ofs = (code - 0x200) * 36;
56                                 res->clear();
57                                 res->write(0x40);
58                                 for(int i = 0; i < 36; i++) {
59                                         res->write(mfont[ofs + i]);
60                                 }
61                                 status = BIT_IBF | BIT_OBF;
62                                 d_pic->write_signal(SIG_I8259_IR7 | SIG_I8259_CHIP1, 1, 1);
63                         } else {
64                                 // error
65                                 status = BIT_ERR;
66                         }
67                 }
68                 break;
69         case 0xfd:
70                 // set irq
71                 d_pic->write_signal(SIG_I8259_IR7 | SIG_I8259_CHIP1, 1, 1);
72                 break;
73         }
74 }
75
76 uint32_t MFONT::read_io8(uint32_t addr)
77 {
78         uint32_t val;
79         
80         switch(addr & 0xff) {
81         case 0xfc:
82                 val = res->read();
83                 if(res->empty()) {
84                         status = 0;
85                 }
86                 return val;
87         case 0xfd:
88                 // reset irq
89                 d_pic->write_signal(SIG_I8259_IR7 | SIG_I8259_CHIP1, 0, 1);
90                 return status;
91         }
92         return 0xff;
93 }
94
95 #define STATE_VERSION   1
96
97 #include "../../statesub.h"
98
99 void MFONT::decl_state()
100 {
101         enter_decl_state(STATE_VERSION);
102
103         DECL_STATE_ENTRY_UINT8(status);
104         DECL_STATE_ENTRY_FIFO(cmd);
105         DECL_STATE_ENTRY_FIFO(res);
106         
107         leave_decl_state();
108 }
109
110 void MFONT::save_state(FILEIO* state_fio)
111 {
112         if(state_entry != NULL) {
113                 state_entry->save_state(state_fio);
114         }
115 //      state_fio->FputUint32(STATE_VERSION);
116 //      state_fio->FputInt32(this_device_id);
117         
118 //      state_fio->FputUint8(status);
119 //      cmd->save_state((void *)state_fio);
120 //      res->save_state((void *)state_fio);
121 }
122
123 bool MFONT::load_state(FILEIO* state_fio)
124 {
125         bool mb = false;
126         if(state_entry != NULL) {
127                 mb = state_entry->load_state(state_fio);
128         }
129         if(!mb) {
130                 return false;
131         }
132 //      if(state_fio->FgetUint32() != STATE_VERSION) {
133 //              return false;
134 //      }
135 //      if(state_fio->FgetInt32() != this_device_id) {
136 //              return false;
137 //      }
138 //      status = state_fio->FgetUint8();
139 //      if(!cmd->load_state((void *)state_fio)) {
140 //              return false;
141 //      }
142 //      if(!res->load_state((void *)state_fio)) {
143 //              return false;
144 //      }
145         return true;
146 }
147
148 bool MFONT::process_state(FILEIO* state_fio, bool loading)
149 {
150         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
151                 return false;
152         }
153         if(!state_fio->StateCheckInt32(this_device_id)) {
154                 return false;
155         }
156         state_fio->StateUint8(status);
157         if(!cmd->process_state((void *)state_fio, loading)) {
158                 return false;
159         }
160         if(!res->process_state((void *)state_fio, loading)) {
161                 return false;
162         }
163         return true;
164 }