trunk/src/emu/machine/msm6242.c
| r19444 | r19445 | |
| 80 | 80 | |
| 81 | 81 | if(m_irq_flag == 1 && m_irq_type == 0 && ((m_tick % 0x200) == 0)) // 1/64 of second |
| 82 | 82 | { |
| 83 | | if ( !m_out_int_func.isnull() ) |
| 84 | | m_out_int_func( ASSERT_LINE ); |
| 83 | if ( !m_res_out_int_func.isnull() ) |
| 84 | m_res_out_int_func( ASSERT_LINE ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | if(m_tick & 0x8000) // 32,768 KHz == 0x8000 ticks |
| r19444 | r19445 | |
| 90 | 90 | m_rtc.sec++; |
| 91 | 91 | |
| 92 | 92 | if(m_irq_flag == 1 && m_irq_type == 1) // 1 second clock |
| 93 | | if ( !m_out_int_func.isnull() ) |
| 94 | | m_out_int_func(ASSERT_LINE); |
| 93 | if ( !m_res_out_int_func.isnull() ) |
| 94 | m_res_out_int_func(ASSERT_LINE); |
| 95 | 95 | |
| 96 | 96 | if(m_rtc.sec >= 60) |
| 97 | 97 | { |
| 98 | 98 | m_rtc.min++; m_rtc.sec = 0; |
| 99 | 99 | if(m_irq_flag == 1 && m_irq_type == 2) // 1 minute clock |
| 100 | | if ( !m_out_int_func.isnull() ) |
| 101 | | m_out_int_func(ASSERT_LINE); |
| 100 | if ( !m_res_out_int_func.isnull() ) |
| 101 | m_res_out_int_func(ASSERT_LINE); |
| 102 | 102 | } |
| 103 | 103 | if(m_rtc.min >= 60) |
| 104 | 104 | { |
| 105 | 105 | m_rtc.hour++; m_rtc.min = 0; |
| 106 | 106 | if(m_irq_flag == 1 && m_irq_type == 3) // 1 hour clock |
| 107 | | if ( !m_out_int_func.isnull() ) |
| 108 | | m_out_int_func(ASSERT_LINE); |
| 107 | if ( !m_res_out_int_func.isnull() ) |
| 108 | m_res_out_int_func(ASSERT_LINE); |
| 109 | 109 | } |
| 110 | 110 | if(m_rtc.hour >= 24) { m_rtc.day++; m_rtc.wday++; m_rtc.hour = 0; } |
| 111 | 111 | if(m_rtc.wday >= 6) { m_rtc.wday = 1; } |
| r19444 | r19445 | |
| 143 | 143 | |
| 144 | 144 | |
| 145 | 145 | //------------------------------------------------- |
| 146 | | // device_validity_check - perform validity checks |
| 147 | | // on this device |
| 148 | | //------------------------------------------------- |
| 149 | | |
| 150 | | void msm6242_device::device_validity_check(validity_checker &valid) const |
| 151 | | { |
| 152 | | } |
| 153 | | |
| 154 | | |
| 155 | | |
| 156 | | //------------------------------------------------- |
| 157 | 146 | // device_start - device-specific startup |
| 158 | 147 | //------------------------------------------------- |
| 159 | 148 | |
| 160 | 149 | void msm6242_device::device_start() |
| 161 | 150 | { |
| 162 | | m_out_int_func.resolve( m_out_int_cb, *this ); |
| 151 | const msm6242_interface *intf = reinterpret_cast<const msm6242_interface *>(static_config()); |
| 152 | if (intf != NULL) |
| 153 | m_res_out_int_func.resolve(intf->m_out_int_func, *this); |
| 163 | 154 | |
| 164 | 155 | // let's call the timer callback every tick |
| 165 | 156 | m_timer = timer_alloc(TIMER_RTC_CALLBACK); |
| r19444 | r19445 | |
| 185 | 176 | m_reg[0] = 0; |
| 186 | 177 | m_reg[1] = 0x6; |
| 187 | 178 | m_reg[2] = 0x4; |
| 179 | |
| 180 | // save states |
| 181 | save_item(NAME(m_reg)); |
| 182 | save_item(NAME(m_irq_flag)); |
| 183 | save_item(NAME(m_irq_type)); |
| 184 | save_item(NAME(m_tick)); |
| 185 | save_item(NAME(m_rtc.sec)); |
| 186 | save_item(NAME(m_rtc.min)); |
| 187 | save_item(NAME(m_rtc.hour)); |
| 188 | save_item(NAME(m_rtc.wday)); |
| 189 | save_item(NAME(m_rtc.day)); |
| 190 | save_item(NAME(m_rtc.month)); |
| 191 | save_item(NAME(m_rtc.year)); |
| 188 | 192 | } |
| 189 | 193 | |
| 190 | 194 | |
| r19444 | r19445 | |
| 195 | 199 | |
| 196 | 200 | void msm6242_device::device_reset() |
| 197 | 201 | { |
| 198 | | if ( !m_out_int_func.isnull() ) |
| 199 | | m_out_int_func( CLEAR_LINE ); |
| 202 | if ( !m_res_out_int_func.isnull() ) |
| 203 | m_res_out_int_func( CLEAR_LINE ); |
| 200 | 204 | } |
| 201 | 205 | |
| 202 | 206 | |
| 203 | 207 | |
| 204 | | //------------------------------------------------- |
| 205 | | // device_config_complete - perform any |
| 206 | | // operations now that the configuration is |
| 207 | | // complete |
| 208 | | //------------------------------------------------- |
| 209 | | |
| 210 | | void msm6242_device::device_config_complete() |
| 211 | | { |
| 212 | | const msm6242_interface *intf = reinterpret_cast<const msm6242_interface *>(static_config()); |
| 213 | | |
| 214 | | if ( intf != NULL ) |
| 215 | | { |
| 216 | | m_out_int_cb = intf->m_out_int_cb; |
| 217 | | } |
| 218 | | else |
| 219 | | { |
| 220 | | memset(&m_out_int_cb, 0, sizeof(m_out_int_cb)); |
| 221 | | } |
| 222 | | } |
| 223 | | |
| 224 | | |
| 225 | | |
| 226 | 208 | //************************************************************************** |
| 227 | 209 | // READ/WRITE HANDLERS |
| 228 | 210 | //************************************************************************** |
| r19444 | r19445 | |
| 320 | 302 | else |
| 321 | 303 | { |
| 322 | 304 | m_irq_flag = 0; |
| 323 | | if ( !m_out_int_func.isnull() ) |
| 324 | | m_out_int_func( CLEAR_LINE ); |
| 305 | if ( !m_res_out_int_func.isnull() ) |
| 306 | m_res_out_int_func( CLEAR_LINE ); |
| 325 | 307 | } |
| 326 | 308 | |
| 327 | 309 | return; |
trunk/src/emu/machine/msm6242.h
| r19444 | r19445 | |
| 26 | 26 | |
| 27 | 27 | struct msm6242_interface |
| 28 | 28 | { |
| 29 | | devcb_write_line m_out_int_cb; |
| 29 | devcb_write_line m_out_int_func; |
| 30 | 30 | }; |
| 31 | 31 | |
| 32 | 32 | struct rtc_regs_t |
| r19444 | r19445 | |
| 38 | 38 | |
| 39 | 39 | // ======================> msm6242_device |
| 40 | 40 | |
| 41 | | class msm6242_device : public device_t, |
| 42 | | public msm6242_interface |
| 41 | class msm6242_device : public device_t |
| 43 | 42 | { |
| 44 | 43 | public: |
| 45 | 44 | // construction/destruction |
| r19444 | r19445 | |
| 51 | 50 | |
| 52 | 51 | protected: |
| 53 | 52 | // device-level overrides |
| 54 | | virtual void device_config_complete(); |
| 55 | | virtual void device_validity_check(validity_checker &valid) const; |
| 56 | 53 | virtual void device_start(); |
| 57 | 54 | virtual void device_reset(); |
| 58 | 55 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 59 | 56 | |
| 60 | 57 | private: |
| 58 | // state |
| 61 | 59 | UINT8 m_reg[3]; |
| 62 | 60 | UINT8 m_irq_flag; |
| 63 | 61 | UINT8 m_irq_type; |
| 64 | 62 | UINT16 m_tick; |
| 65 | | |
| 66 | 63 | rtc_regs_t m_rtc; |
| 67 | | rtc_regs_t m_hold; |
| 68 | | devcb_resolved_write_line m_out_int_func; |
| 64 | |
| 65 | // incidentals |
| 66 | devcb_resolved_write_line m_res_out_int_func; |
| 69 | 67 | emu_timer * m_timer; |
| 70 | 68 | |
| 69 | // callbacks |
| 71 | 70 | void rtc_timer_callback(); |
| 72 | 71 | }; |
| 73 | 72 | |