OSDN Git Service

[VM][COMMON_VM] Include IO:: class to common_vm.
[csp-qt/common_source_project-fm7.git] / source / src / vm / i8259.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2005.06.10-
6
7         [ i8259 ]
8 */
9
10 #ifndef _I8259_H_
11 #define _I8259_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16
17 /*
18         NOTE: I8259_MAX_CHIPS shoud be 1 or 2
19 */
20
21 #define SIG_I8259_IR0   0
22 #define SIG_I8259_IR1   1
23 #define SIG_I8259_IR2   2
24 #define SIG_I8259_IR3   3
25 #define SIG_I8259_IR4   4
26 #define SIG_I8259_IR5   5
27 #define SIG_I8259_IR6   6
28 #define SIG_I8259_IR7   7
29 #define SIG_I8259_CHIP0 0
30 #define SIG_I8259_CHIP1 8
31 //#define SIG_I8259_CHIP2       16
32 //#define SIG_I8259_CHIP3       24
33
34 #define I8259_ADDR_CHIP0        0
35 #define I8259_ADDR_CHIP1        2
36 //#define I8259_ADDR_CHIP2      4
37 //#define I8259_ADDR_CHIP3      6
38
39 struct  i8259_pic_t {
40         uint8_t imr, isr, irr, irr_tmp, prio;
41         uint8_t icw1, icw2, icw3, icw4, ocw3;
42         uint8_t icw2_r, icw3_r, icw4_r;
43         int irr_tmp_id;
44 };
45
46 class I8259 : public DEVICE
47 {
48 private:
49         DEVICE* d_cpu;
50
51         struct i8259_pic_t pic[2];
52         int req_chip, req_level;
53         uint8_t req_bit;
54         uint32_t __I8259_MAX_CHIPS;
55         uint32_t __CHIP_MASK;
56         bool __I8259_PC98_HACK;
57         void __FASTCALL update_intr();
58         
59 public:
60         I8259(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
61         {
62                 d_cpu = NULL;
63                 __I8259_MAX_CHIPS = 0;
64                 __CHIP_MASK = 0xffffffff;
65                 __I8259_PC98_HACK = false;
66                 for(int c = 0; c < 2; c++) {
67                         memset(&(pic[c]), 0x00, sizeof(struct i8259_pic_t));
68                         pic[c].irr_tmp_id = -1;
69                 }
70                 set_device_name(_T("i8259 PIC"));
71         }
72         ~I8259() {}
73         
74         // common functions
75         void initialize();
76         void reset();
77         void __FASTCALL write_io8(uint32_t addr, uint32_t data);
78         uint32_t __FASTCALL read_io8(uint32_t addr);
79         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
80         uint32_t __FASTCALL read_signal(int id);
81         void event_callback(int event_id, int err);
82         bool process_state(FILEIO* state_fio, bool loading);
83         // interrupt common functions
84         void set_intr_line(bool line, bool pending, uint32_t bit)
85         {
86                 // request from Z80 familly
87                 write_signal(bit, line ? 1 : 0, 1);
88         }
89         uint32_t get_intr_ack();
90         
91         // unique functions
92         void set_context_cpu(DEVICE* device)
93         {
94                 d_cpu = device;
95         }
96 };
97
98 #endif
99