2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
17 DLL_PREFIX_I struct cur_time_s cur_time;
20 void MSM58321_BASE::initialize()
24 memset(regs, 0, sizeof(regs));
29 rd = wr = addr_wr = busy = hold = false;
30 count_1024hz = count_1s = count_1m = count_1h = 0;
32 get_host_time(&cur_time);
37 // register_event(this, EVENT_INC, 1000000.0, true, ®ister_id);
39 // register_event(this, EVENT_BUSY, 1000000.0, true, ®ister_id);
41 register_event(this, EVENT_PULSE, 1000000.0 / 8192.0, true, NULL); // 122.1 usec
44 void MSM58321_BASE::event_callback(int event_id, int err)
46 if(event_id == EVENT_BUSY) {
48 register_event(this, EVENT_INC, 430, false, NULL);
49 } else if(event_id == EVENT_INC) {
50 if(cur_time.initialized) {
53 get_host_time(&cur_time); // resync
54 cur_time.initialized = true;
63 } else if(event_id == EVENT_PULSE) {
64 if(++count_1024hz == 4) {
68 if(++count_1s == 8192) {
74 if(++count_1m == (60 * 8192)) {
80 if(++count_1h == (3600 * 8192)) {
87 if(regnum == 14 || regnum == 15) {
93 void MSM58321_BASE::read_from_cur_time()
96 int hour = (regs[5] & 8) ? cur_time.hour : (cur_time.hour % 12);
97 int ampm = (cur_time.hour > 11) ? 4 : 0;
99 regs[ 0] = TO_BCD_LO(cur_time.second);
100 regs[ 1] = TO_BCD_HI(cur_time.second);
101 regs[ 2] = TO_BCD_LO(cur_time.minute);
102 regs[ 3] = TO_BCD_HI(cur_time.minute);
103 regs[ 4] = TO_BCD_LO(hour);
104 regs[ 5] = TO_BCD_HI(hour) | ampm | (regs[5] & 8);
105 regs[ 6] = cur_time.day_of_week;
106 regs[ 7] = TO_BCD_LO(cur_time.day - start_day);
107 regs[ 8] = TO_BCD_HI(cur_time.day - start_day) | (regs[8] & 0x0c);
108 regs[ 9] = TO_BCD_LO(cur_time.month);
109 regs[10] = TO_BCD_HI(cur_time.month);
110 regs[11] = TO_BCD_LO(cur_time.year - start_year);
111 regs[12] = TO_BCD_HI(cur_time.year - start_year);
114 void MSM58321_BASE::write_to_cur_time()
116 cur_time.second = regs[0] + (regs[1] & 7) * 10;
117 cur_time.minute = regs[2] + (regs[3] & 7) * 10;
118 cur_time.hour = regs[4] + (regs[5] & 3) * 10;
125 // cur_time.day_of_week = regs[6] & 7;
126 cur_time.day = regs[7] + (regs[8] & 3) * 10;
127 cur_time.day += start_day;
128 cur_time.month = regs[9] + (regs[10] & 1) * 10;
129 cur_time.year = regs[11] + regs[12] * 10;
130 cur_time.year += start_year;
131 cur_time.update_year();
132 cur_time.update_day_of_week();
135 cancel_event(this, register_id);
137 // register_event(this, EVENT_INC, 1000000.0, true, ®ister_id);
139 // register_event(this, EVENT_BUSY, 1000000.0, true, ®ister_id);
143 void MSM58321_BASE::write_signal(int id, uint32_t data, uint32_t mask)
145 if(id == SIG_MSM58321_DATA) {
146 wreg = (data & mask) | (wreg & ~mask);
147 } else if(id == SIG_MSM58321_CS) {
148 bool next = ((data & mask) != 0);
151 // regs[regnum] = wreg & 0x0f;
152 // if(regnum <= 12) {
153 // write_to_cur_time();
157 // regnum = wreg & 0x0f;
162 } else if(id == SIG_MSM58321_READ) {
163 rd = ((data & mask) != 0);
165 } else if(id == SIG_MSM58321_WRITE) {
166 bool next = ((data & mask) != 0);
167 if(!wr && next && cs) {
168 regs[regnum] = wreg & 0x0f;
174 } else if(id == SIG_MSM58321_ADDR_WRITE) {
175 bool next = ((data & mask) != 0);
176 if(addr_wr && !next && cs) {
177 regnum = wreg & 0x0f;
181 } else if(id == SIG_MSM5832_ADDR) {
182 regnum = (data & mask) | (regnum & ~mask);
184 } else if(id == SIG_MSM5832_HOLD) {
185 hold = ((data & mask) != 0);
189 uint32_t MSM58321_BASE::read_signal(int ch)
191 if(ch == SIG_MSM58321_DATA) {
198 void MSM58321_BASE::output_data()
201 write_signals(&outputs_data, regs[regnum]);
205 void MSM58321_BASE::set_busy(bool val)
207 //#ifndef HAS_MSM5832
209 // write_signals(&outputs_busy, busy ? 0 : 0xffffffff); // negative
215 #define STATE_VERSION 1
217 bool MSM58321_BASE::process_state(FILEIO* state_fio, bool loading)
219 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
222 if(!state_fio->StateCheckInt32(this_device_id)) {
225 if(!cur_time.process_state((void *)state_fio, loading)) {
228 state_fio->StateValue(register_id);
229 state_fio->StateArray(regs, sizeof(regs), 1);
230 state_fio->StateValue(wreg);
231 state_fio->StateValue(regnum);
232 state_fio->StateValue(cs);
233 state_fio->StateValue(rd);
234 state_fio->StateValue(wr);
235 state_fio->StateValue(addr_wr);
236 state_fio->StateValue(busy);
237 state_fio->StateValue(hold);
238 state_fio->StateValue(count_1024hz);
239 state_fio->StateValue(count_1s);
240 state_fio->StateValue(count_1m);
241 state_fio->StateValue(count_1h);