OSDN Git Service

[VM] .
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmr30 / timer.cpp
1 /*
2         FUJITSU FMR-30 Emulator 'eFMR-30'
3
4         Author : Takeda.Toshiya
5         Date   : 2008.12.31 -
6
7         [ timer ]
8 */
9
10 #include "./timer.h"
11 #include "../i8259.h"
12
13 namespace FMR30 {
14         
15 void TIMER::initialize()
16 {
17         ctrl = status = 0;
18 }
19
20 void TIMER::write_io8(uint32_t addr, uint32_t data)
21 {
22         switch(addr) {
23         case 0x42:
24                 ctrl = data;
25                 update_intr();
26                 break;
27         }
28 }
29
30 uint32_t TIMER::read_io8(uint32_t addr)
31 {
32         switch(addr) {
33         case 0x42:
34                 return ctrl;
35         case 0x43:
36                 return status;
37         }
38         return 0xff;
39 }
40
41 void TIMER::write_signal(int id, uint32_t data, uint32_t mask)
42 {
43         if(id == SIG_TIMER_CH0) {
44                 if(data & mask) {
45                         status |= 1;
46                 } else {
47                         status &= ~1;
48                 }
49                 update_intr();
50         } else if(id == SIG_TIMER_CH1) {
51                 if(data & mask) {
52                         status |= 2;
53                 } else {
54                         status &= ~2;
55                 }
56                 update_intr();
57         }
58 }
59
60 void TIMER::update_intr()
61 {
62         d_pic->write_signal(SIG_I8259_CHIP0 | SIG_I8259_IR0, (ctrl & status & 3) ? 1 : 0, 1);
63 }
64
65 #define STATE_VERSION   1
66
67
68 bool TIMER::process_state(FILEIO* state_fio, bool loading)
69 {
70         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
71                 return false;
72         }
73         if(!state_fio->StateCheckInt32(this_device_id)) {
74                 return false;
75         }
76         state_fio->StateUint8(ctrl);
77         state_fio->StateUint8(status);
78         return true;
79 }
80
81 }