2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
19 DLL_PREFIX_I struct cur_time_s cur_time;
22 MSM5832::MSM5832(VM* parent_vm, EMU* parent_emu) : MSM58321_BASE(parent_vm, parent_emu)
24 set_device_name(_T("MSM5832 RTC"));
27 void MSM5832::initialize()
31 memset(regs, 0, sizeof(regs));
36 rd = wr = addr_wr = busy = hold = false;
37 count_1024hz = count_1s = count_1m = count_1h = 0;
39 get_host_time(&cur_time);
43 #ifdef MSM58321_START_DAY
44 start_day = MSM58321_START_DAY;
46 #ifdef MSM58321_START_YEAR
47 start_year = MSM58321_START_YEAR;
49 register_event(this, EVENT_INC, 1000000.0, true, ®ister_id);
50 register_event(this, EVENT_PULSE, 1000000.0 / 8192.0, true, NULL); // 122.1 usec
54 void MSM5832::read_from_cur_time()
57 int hour = (regs[5] & 8) ? cur_time.hour : (cur_time.hour % 12);
58 int ampm = (cur_time.hour > 11) ? 4 : 0;
60 regs[ 0] = TO_BCD_LO(cur_time.second);
61 regs[ 1] = TO_BCD_HI(cur_time.second);
62 regs[ 2] = TO_BCD_LO(cur_time.minute);
63 regs[ 3] = TO_BCD_HI(cur_time.minute);
64 regs[ 4] = TO_BCD_LO(hour);
65 regs[ 5] = TO_BCD_HI(hour) | ampm | (regs[5] & 8);
66 regs[ 6] = cur_time.day_of_week;
67 regs[ 7] = TO_BCD_LO(cur_time.day - start_day);
68 regs[ 8] = TO_BCD_HI(cur_time.day - start_day) | (regs[8] & 0x0c);
69 regs[ 9] = TO_BCD_LO(cur_time.month);
70 regs[10] = TO_BCD_HI(cur_time.month);
71 regs[11] = TO_BCD_LO(cur_time.year - start_year);
72 regs[12] = TO_BCD_HI(cur_time.year - start_year);
75 void MSM5832::write_to_cur_time()
77 cur_time.second = regs[0] + (regs[1] & 7) * 10;
78 cur_time.minute = regs[2] + (regs[3] & 7) * 10;
79 cur_time.hour = regs[4] + (regs[5] & 3) * 10;
86 // cur_time.day_of_week = regs[6] & 7;
87 cur_time.day = regs[7] + (regs[8] & 3) * 10;
88 cur_time.day += start_day;
89 cur_time.month = regs[9] + (regs[10] & 1) * 10;
90 cur_time.year = regs[11] + regs[12] * 10;
91 cur_time.year += start_year;
92 cur_time.update_year();
93 cur_time.update_day_of_week();
96 cancel_event(this, register_id);
97 register_event(this, EVENT_INC, 1000000.0, true, ®ister_id);
100 void MSM5832::set_busy(bool val)