OSDN Git Service

[VM] MEMORY:: class within some VM will change Foo_MEMORY:: to reduce misundestanding...
[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 void TIMER::initialize()
14 {
15         ctrl = status = 0;
16 }
17
18 void TIMER::write_io8(uint32_t addr, uint32_t data)
19 {
20         switch(addr) {
21         case 0x42:
22                 ctrl = data;
23                 update_intr();
24                 break;
25         }
26 }
27
28 uint32_t TIMER::read_io8(uint32_t addr)
29 {
30         switch(addr) {
31         case 0x42:
32                 return ctrl;
33         case 0x43:
34                 return status;
35         }
36         return 0xff;
37 }
38
39 void TIMER::write_signal(int id, uint32_t data, uint32_t mask)
40 {
41         if(id == SIG_TIMER_CH0) {
42                 if(data & mask) {
43                         status |= 1;
44                 } else {
45                         status &= ~1;
46                 }
47                 update_intr();
48         } else if(id == SIG_TIMER_CH1) {
49                 if(data & mask) {
50                         status |= 2;
51                 } else {
52                         status &= ~2;
53                 }
54                 update_intr();
55         }
56 }
57
58 void TIMER::update_intr()
59 {
60         d_pic->write_signal(SIG_I8259_CHIP0 | SIG_I8259_IR0, (ctrl & status & 3) ? 1 : 0, 1);
61 }
62
63 #define STATE_VERSION   1
64
65
66 bool TIMER::process_state(FILEIO* state_fio, bool loading)
67 {
68         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
69                 return false;
70         }
71         if(!state_fio->StateCheckInt32(this_device_id)) {
72                 return false;
73         }
74         state_fio->StateUint8(ctrl);
75         state_fio->StateUint8(status);
76         return true;
77 }